Blame src/service/toks_service_ioctl.c

073a98
/*********************************************************/
073a98
/*  toksvc: a framework-native token broker service      */
073a98
/*  Copyright (C) 2020  Z. Gilboa                        */
073a98
/*  Released under GPLv2 and GPLv3; see COPYING.TOKSVC.  */
073a98
/*********************************************************/
073a98
073a98
#include <psxtypes/psxtypes.h>
073a98
#include <ntapi/ntapi.h>
073a98
073a98
#include <toksvc/toksvc.h>
073a98
#include "toksvc_driver_impl.h"
073a98
#include "toksvc_daemon_impl.h"
073a98
073a98
int32_t toks_service_ioctl(
073a98
	struct toks_driver_ctx *  dctx,
073a98
	uint32_t                  ctlcode,
073a98
	uintptr_t *               data,
073a98
	void *                    any)
073a98
{
073a98
	int32_t			status;
073a98
	void *			hport;
073a98
	struct _nt_tty_sync_msg	msg;
073a98
073a98
	hport = toks_get_driver_hservice(dctx);
073a98
073a98
	ntapi->tt_aligned_block_memset(
073a98
		&msg,0,sizeof(msg));
073a98
073a98
	msg.header.msg_type	= NT_LPC_NEW_MESSAGE;
073a98
	msg.header.data_size	= sizeof(msg.data);
073a98
	msg.header.msg_size	= sizeof(msg);
073a98
	msg.data.ttyinfo.opcode	= TOKS_DAEMON_IOCTL;
073a98
	msg.data.ttyinfo.opdata	= ctlcode;
073a98
073a98
	switch (ctlcode) {
073a98
		case TOKS_IOCTL_SET_TOKEN_COUNT:
073a98
			msg.data.ttyinfo.exarg = (void *)(intptr_t)*data;
073a98
			break;
073a98
073a98
		default:
073a98
			(void)any;
073a98
			break;
073a98
	}
073a98
073a98
	if ((status = ntapi->zw_request_wait_reply_port(hport,&msg,&msg)))
073a98
		return status;
073a98
073a98
	else if (msg.data.ttyinfo.status)
073a98
		return msg.data.ttyinfo.status;
073a98
073a98
	switch (ctlcode) {
073a98
		case TOKS_IOCTL_GET_TOKEN_COUNT:
073a98
			*data = (int)(intptr_t)msg.data.ttyinfo.exarg;
073a98
			break;
073a98
073a98
		default:
073a98
			(void)any;
073a98
			break;
073a98
	}
073a98
073a98
	return NT_STATUS_SUCCESS;
073a98
}