Blob Blame History Raw
/*********************************************************/
/*  toksvc: a framework-native token broker service      */
/*  Copyright (C) 2020  SysDeer Technologies, LLC        */
/*  Released under GPLv2 and GPLv3; see COPYING.TOKSVC.  */
/*********************************************************/

#include <psxtypes/psxtypes.h>
#include <ntapi/ntapi.h>

#include <toksvc/toksvc.h>
#include "toksvc_driver_impl.h"
#include "toksvc_daemon_impl.h"

int32_t toks_client_query_service(
	struct toks_driver_ctx *    dctx,
	struct toks_service_info *  svcinfo)
{
	int32_t			status;
	void *			hport;
	struct _nt_tty_port_msg	msg;

	hport  = toks_get_driver_hservice(dctx);

	ntapi->tt_aligned_block_memset(
		&msg,0,sizeof(msg));

	msg.header.msg_type  = NT_LPC_NEW_MESSAGE;
	msg.header.data_size = sizeof(msg.ttyinfo) + sizeof(msg.svcdata);
	msg.header.msg_size  = sizeof(msg);
	msg.ttyinfo.opcode   = TOKS_DAEMON_IOCTL;
	msg.ttyinfo.opdata   = TOKS_IOCTL_GET_SERVICE_INFO;

	if ((status = ntapi->zw_request_wait_reply_port(hport,&msg,&msg)))
		return status;

	else if (msg.ttyinfo.status)
		return msg.ttyinfo.status;

	/* uuid */
	svcinfo->uuid.data1    = (msg.svcdata.meta[0]);

	svcinfo->uuid.data2    = (msg.svcdata.meta[1]  & 0xffff);
	svcinfo->uuid.data3    = (msg.svcdata.meta[1] >> 16);

	svcinfo->uuid.data4[0] = (msg.svcdata.meta[2] & 0xff);
	svcinfo->uuid.data4[1] = (msg.svcdata.meta[2] & 0xff00) >> 8;
	svcinfo->uuid.data4[2] = (msg.svcdata.meta[2] & 0xff0000) >> 16;
	svcinfo->uuid.data4[3] = (msg.svcdata.meta[2] & 0xff000000) >> 24;

	svcinfo->uuid.data4[4] = (msg.svcdata.meta[3] & 0xff);
	svcinfo->uuid.data4[5] = (msg.svcdata.meta[3] & 0xff00) >> 8;
	svcinfo->uuid.data4[6] = (msg.svcdata.meta[3] & 0xff0000) >> 16;
	svcinfo->uuid.data4[7] = (msg.svcdata.meta[3] & 0xff000000) >> 24;

	/* syspid, systid */
	svcinfo->syspid        = msg.svcdata.data[0];
	svcinfo->systid        = msg.svcdata.data[1];

	/* ctrlpid, csyspid */
	svcinfo->ctrlpid       = msg.svcdata.data[2];
	svcinfo->csyspid       = msg.svcdata.data[3];

	/* allocated, available, pending */
	svcinfo->allocated     = msg.svcdata.data[4];
	svcinfo->available     = msg.svcdata.data[5];
	svcinfo->pending       = msg.svcdata.data[6];

	/* used, free */
	svcinfo->tused         = msg.svcdata.data[7];
	svcinfo->tfree         = msg.svcdata.data[8];

	return NT_STATUS_SUCCESS;
}