From 538c8a5109b56d1d0a26631fa93913341214501d Mon Sep 17 00:00:00 2001 From: midipix Date: Tue, 5 Jul 2016 17:00:06 -0400 Subject: pty layer: added ptyc_alloc_pty(), ptyc_free_pty(). --- src/pty/ptyc_pty_ctx.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/pty/ptyc_pty_ctx.c (limited to 'src/pty') diff --git a/src/pty/ptyc_pty_ctx.c b/src/pty/ptyc_pty_ctx.c new file mode 100644 index 0000000..31a9c26 --- /dev/null +++ b/src/pty/ptyc_pty_ctx.c @@ -0,0 +1,92 @@ +/*********************************************************/ +/* ptycon: a pty-console bridge */ +/* Copyright (C) 2016 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.PTYCON. */ +/*********************************************************/ + +#include +#include +#include +#include "ptycon_driver_impl.h" +#include "ptycon_ioctl_impl.h" +#include "ptycon_status_impl.h" + +static int32_t ptyc_pty_open(nt_pty * hptm, nt_guid * pty_guid, nt_pty ** hpty) +{ + nt_vfd_dev_name pty_name; + nt_oa oa = {sizeof(oa),0,0,0,0,0}; + + ntapi->vfd_dev_name_init( + &pty_name,pty_guid); + + oa.obj_name = &pty_name.name; + oa.root_dir = hptm; + + return ntapi->pty_open( + 0,hpty, + NT_FILE_ALL_ACCESS, + &oa,0,0,0); +} + +static int32_t ptyc_ptm_open(const struct ptyc_common_ctx * cctx) +{ + nt_guid pty_guid = TTY_PTM_GUID; + return ptyc_pty_open( + 0,&pty_guid, + (nt_pty **)&cctx->hptm); +} + +static int32_t ptyc_pts_open(const struct ptyc_common_ctx * cctx) +{ + int32_t status; + nt_guid pty_guid = TTY_PTS_GUID; + + if ((status = ptyc_grant(cctx->hptm))) + return status; + + return ptyc_pty_open( + cctx->hptm,&pty_guid, + (nt_pty **)&cctx->hpts); +} + +int ptyc_alloc_pty(struct ptyc_driver_ctx * dctx) +{ + int32_t status; + + if (dctx->cctx->hpts || dctx->cctx->hptm) + return ptyc_set_status( + dctx,NT_STATUS_DEVICE_ALREADY_ATTACHED); + + if ((status = ptyc_ptm_open(dctx->cctx))) + return ptyc_set_status( + dctx,status); + + if (!(dctx->cctx->drvflags & PTYC_DRIVER_DBG_OVEN) + && !(dctx->cctx->drvflags & PTYC_DRIVER_DBG_RAW)) + return ptyc_set_status( + dctx,NT_STATUS_SUCCESS); + + if ((status = ptyc_pts_open(dctx->cctx))) + return ptyc_set_status( + dctx,status); + + return ptyc_set_status( + dctx,NT_STATUS_SUCCESS); +} + +void ptyc_free_pty(struct ptyc_driver_ctx * dctx) +{ + struct ptyc_common_ctx * cctx; + + cctx = (struct ptyc_common_ctx *)dctx->cctx; + + if (cctx->hpts) { + ntapi->pty_close(cctx->hpts); + cctx->hpts = 0; + } + + if (cctx->hptm) { + ntapi->pty_close(cctx->hptm); + cctx->hptm = 0; + } +} -- cgit v1.2.3