|
|
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 |
|
|
|
9b8e64 |
static int32_t ptyc_ptm_open(struct ptyc_common_ctx * cctx)
|
|
|
538c8a |
{
|
|
|
538c8a |
nt_guid pty_guid = TTY_PTM_GUID;
|
|
|
9b8e64 |
|
|
|
538c8a |
return ptyc_pty_open(
|
|
|
538c8a |
0,&pty_guid,
|
|
|
9b8e64 |
&cctx->hptm);
|
|
|
538c8a |
}
|
|
|
538c8a |
|
|
|
9b8e64 |
static int32_t ptyc_pts_open(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,
|
|
|
9b8e64 |
&cctx->hpts);
|
|
|
538c8a |
}
|
|
|
538c8a |
|
|
|
538c8a |
int ptyc_alloc_pty(struct ptyc_driver_ctx * dctx)
|
|
|
538c8a |
{
|
|
|
9b8e64 |
int32_t status;
|
|
|
9b8e64 |
struct ptyc_driver_ctx_impl * ictx;
|
|
|
9b8e64 |
struct ptyc_common_ctx * cctx;
|
|
|
9b8e64 |
|
|
|
9b8e64 |
if (!(ictx = ptyc_get_driver_ictx(dctx)))
|
|
|
9b8e64 |
return NT_STATUS_INVALID_HANDLE;
|
|
|
9b8e64 |
|
|
|
9b8e64 |
cctx = &ictx->cctx;
|
|
|
538c8a |
|
|
|
9b8e64 |
if (cctx->hpts || cctx->hptm)
|
|
|
538c8a |
return ptyc_set_status(
|
|
|
538c8a |
dctx,NT_STATUS_DEVICE_ALREADY_ATTACHED);
|
|
|
538c8a |
|
|
|
9b8e64 |
if ((status = ptyc_ptm_open(cctx)))
|
|
|
538c8a |
return ptyc_set_status(
|
|
|
538c8a |
dctx,status);
|
|
|
538c8a |
|
|
|
2de078 |
if (!dctx->units[0]
|
|
|
2de078 |
&& !(cctx->drvflags & PTYC_DRIVER_DBG_OVEN)
|
|
|
9b8e64 |
&& !(cctx->drvflags & PTYC_DRIVER_DBG_RAW))
|
|
|
538c8a |
return ptyc_set_status(
|
|
|
538c8a |
dctx,NT_STATUS_SUCCESS);
|
|
|
538c8a |
|
|
|
9b8e64 |
if ((status = ptyc_pts_open(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 |
{
|
|
|
9b8e64 |
struct ptyc_driver_ctx_impl * ictx;
|
|
|
538c8a |
|
|
|
9b8e64 |
if (!(ictx = ptyc_get_driver_ictx(dctx)))
|
|
|
9b8e64 |
return;
|
|
|
538c8a |
|
|
|
9b8e64 |
if (ictx->cctx.hpts) {
|
|
|
9b8e64 |
ntapi->pty_close(ictx->cctx.hpts);
|
|
|
9b8e64 |
ictx->cctx.hpts = 0;
|
|
|
538c8a |
}
|
|
|
538c8a |
|
|
|
9b8e64 |
if (ictx->cctx.hptm) {
|
|
|
9b8e64 |
ntapi->pty_close(ictx->cctx.hptm);
|
|
|
9b8e64 |
ictx->cctx.hptm = 0;
|
|
|
538c8a |
}
|
|
|
538c8a |
}
|