Blame src/daemon/toks_daemon_ioctl.c

e6c547
/*********************************************************/
e6c547
/*  toksvc: a framework-native token broker service      */
e6c547
/*  Copyright (C) 2020  Z. Gilboa                        */
e6c547
/*  Released under GPLv2 and GPLv3; see COPYING.TOKSVC.  */
e6c547
/*********************************************************/
e6c547
e6c547
#include <psxtypes/psxtypes.h>
e6c547
#include <ntapi/ntapi.h>
e6c547
#include <ntapi/nt_termios.h>
e6c547
e6c547
#include "toksvc_daemon_impl.h"
e6c547
#include "toksvc_driver_impl.h"
e6c547
e6c547
static int32_t toks_daemon_ioctl_get_token_count(struct toks_daemon_ctx * dctx)
e6c547
{
e6c547
	nt_tty_port_msg * msg = &dctx->reply;
e6c547
	msg->ttyinfo.exarg = (void *)(intptr_t)toks_get_driver_ntokens(dctx->driver_ctx);
e6c547
	return NT_STATUS_SUCCESS;
e6c547
}
e6c547
8f6a66
static int32_t toks_daemon_ioctl_set_token_count(struct toks_daemon_ctx * dctx)
8f6a66
{
8f6a66
	nt_tty_port_msg * msg;
8f6a66
	int               ntokens;
8f6a66
8f6a66
	msg     = &dctx->reply;
8f6a66
	ntokens = (int)(intptr_t)msg->ttyinfo.exarg;
8f6a66
8f6a66
	if (ntokens > toks_get_driver_atokens(dctx->driver_ctx))
8f6a66
		return NT_STATUS_BUFFER_TOO_SMALL;
8f6a66
8f6a66
	toks_set_driver_ntokens(dctx->driver_ctx,ntokens);
8f6a66
8f6a66
	return toks_daemon_release(dctx);
8f6a66
}
8f6a66
e6c547
int32_t __stdcall toks_daemon_ioctl(struct toks_daemon_ctx * dctx)
e6c547
{
e6c547
	nt_tty_port_msg * msg;
e6c547
	uint32_t          ctlcode;
e6c547
e6c547
	msg     = &dctx->reply;
e6c547
	ctlcode = msg->ttyinfo.opdata;
e6c547
e6c547
	switch (ctlcode) {
e6c547
		case TOKS_IOCTL_GET_TOKEN_COUNT:
e6c547
			return toks_daemon_ioctl_get_token_count(dctx);
e6c547
8f6a66
		case TOKS_IOCTL_SET_TOKEN_COUNT:
8f6a66
			return toks_daemon_ioctl_set_token_count(dctx);
8f6a66
e6c547
		default:
e6c547
			return NT_STATUS_NOT_IMPLEMENTED;
e6c547
	}
e6c547
}