|
|
538c8a |
/*********************************************************/
|
|
|
538c8a |
/* ptycon: a pty-console bridge */
|
|
|
538c8a |
/* Copyright (C) 2016 Z. Gilboa */
|
|
|
538c8a |
/* Released under GPLv2 and GPLv3; see COPYING.PTYCON. */
|
|
|
538c8a |
/*********************************************************/
|
|
|
538c8a |
|
|
|
538c8a |
#include <psxtypes/psxtypes.h>
|
|
|
538c8a |
#include <ntapi/ntapi.h>
|
|
|
538c8a |
#include <ptycon/ptycon.h>
|
|
|
538c8a |
#include "ptycon_driver_impl.h"
|
|
|
538c8a |
#include "ptycon_ioctl_impl.h"
|
|
|
538c8a |
#include "ptycon_status_impl.h"
|
|
|
538c8a |
|
|
|
538c8a |
static int32_t ptyc_pty_open(nt_pty * hptm, nt_guid * pty_guid, nt_pty ** hpty)
|
|
|
538c8a |
{
|
|
|
538c8a |
nt_vfd_dev_name pty_name;
|
|
|
538c8a |
nt_oa oa = {sizeof(oa),0,0,0,0,0};
|
|
|
538c8a |
|
|
|
538c8a |
ntapi->vfd_dev_name_init(
|
|
|
538c8a |
&pty_name,pty_guid);
|
|
|
538c8a |
|
|
|
538c8a |
oa.obj_name = &pty_name.name;
|
|
|
538c8a |
oa.root_dir = hptm;
|
|
|
538c8a |
|
|
|
538c8a |
return ntapi->pty_open(
|
|
|
538c8a |
0,hpty,
|
|
|
538c8a |
NT_FILE_ALL_ACCESS,
|
|
|
538c8a |
&oa,0,0,0);
|
|
|
538c8a |
}
|
|
|
538c8a |
|
|
|
538c8a |
static int32_t ptyc_ptm_open(const struct ptyc_common_ctx * cctx)
|
|
|
538c8a |
{
|
|
|
538c8a |
nt_guid pty_guid = TTY_PTM_GUID;
|
|
|
538c8a |
return ptyc_pty_open(
|
|
|
538c8a |
0,&pty_guid,
|
|
|
538c8a |
(nt_pty **)&cctx->hptm);
|
|
|
538c8a |
}
|
|
|
538c8a |
|
|
|
538c8a |
static int32_t ptyc_pts_open(const struct ptyc_common_ctx * cctx)
|
|
|
538c8a |
{
|
|
|
538c8a |
int32_t status;
|
|
|
538c8a |
nt_guid pty_guid = TTY_PTS_GUID;
|
|
|
538c8a |
|
|
|
538c8a |
if ((status = ptyc_grant(cctx->hptm)))
|
|
|
538c8a |
return status;
|
|
|
538c8a |
|
|
|
538c8a |
return ptyc_pty_open(
|
|
|
538c8a |
cctx->hptm,&pty_guid,
|
|
|
538c8a |
(nt_pty **)&cctx->hpts);
|
|
|
538c8a |
}
|
|
|
538c8a |
|
|
|
538c8a |
int ptyc_alloc_pty(struct ptyc_driver_ctx * dctx)
|
|
|
538c8a |
{
|
|
|
538c8a |
int32_t status;
|
|
|
538c8a |
|
|
|
538c8a |
if (dctx->cctx->hpts || dctx->cctx->hptm)
|
|
|
538c8a |
return ptyc_set_status(
|
|
|
538c8a |
dctx,NT_STATUS_DEVICE_ALREADY_ATTACHED);
|
|
|
538c8a |
|
|
|
538c8a |
if ((status = ptyc_ptm_open(dctx->cctx)))
|
|
|
538c8a |
return ptyc_set_status(
|
|
|
538c8a |
dctx,status);
|
|
|
538c8a |
|
|
|
538c8a |
if (!(dctx->cctx->drvflags & PTYC_DRIVER_DBG_OVEN)
|
|
|
538c8a |
&& !(dctx->cctx->drvflags & PTYC_DRIVER_DBG_RAW))
|
|
|
538c8a |
return ptyc_set_status(
|
|
|
538c8a |
dctx,NT_STATUS_SUCCESS);
|
|
|
538c8a |
|
|
|
538c8a |
if ((status = ptyc_pts_open(dctx->cctx)))
|
|
|
538c8a |
return ptyc_set_status(
|
|
|
538c8a |
dctx,status);
|
|
|
538c8a |
|
|
|
538c8a |
return ptyc_set_status(
|
|
|
538c8a |
dctx,NT_STATUS_SUCCESS);
|
|
|
538c8a |
}
|
|
|
538c8a |
|
|
|
538c8a |
void ptyc_free_pty(struct ptyc_driver_ctx * dctx)
|
|
|
538c8a |
{
|
|
|
538c8a |
struct ptyc_common_ctx * cctx;
|
|
|
538c8a |
|
|
|
538c8a |
cctx = (struct ptyc_common_ctx *)dctx->cctx;
|
|
|
538c8a |
|
|
|
538c8a |
if (cctx->hpts) {
|
|
|
538c8a |
ntapi->pty_close(cctx->hpts);
|
|
|
538c8a |
cctx->hpts = 0;
|
|
|
538c8a |
}
|
|
|
538c8a |
|
|
|
538c8a |
if (cctx->hptm) {
|
|
|
538c8a |
ntapi->pty_close(cctx->hptm);
|
|
|
538c8a |
cctx->hptm = 0;
|
|
|
538c8a |
}
|
|
|
538c8a |
}
|