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