UKEY虚拟通道方式流程分析

 

UKEY虚拟通道方式流程分析

 

最后更新 05-08-19

 

UKEY-虚拟通道整体架构

 

TermRWVC 虚拟通道client

TSSysInfclient

E:/Program Files/Microsoft SDK/samples/winbase/WtsApi/TSSysInf/Client/SysInf_C.c)程序改写。

1 服务器端程序TermRWVC运行在PC上,提供5个接口函数供UKEY厂商调用。

 

 

1). 打开设备

TERMRWVC_API HANDLE CreateFileCenterm(char          * lpFileName);

2). 关闭设备

TERMRWVC_API BOOL CloseHandleCenterm(HANDLE                   hFile);

3). 读取文件

TERMRWVC_API BOOL ReadFileCenterm(         HANDLE               hFile,

                                                                                      LPVOID                lpBuffer,

                                                                                      DWORD                nNumberOfBytesToRead,

                                                                                      LPDWORD                          lpNumberOfBytesRead,

                                                                                      LPOVERLAPPED                 lpOverlapped);

4). 写入文件

TERMRWVC_API BOOL WriteFileCenterm(        HANDLE               hFile,

                                                                                      LPCVOID                            lpBuffer,

                                                                                      DWORD                nNumberOfBytesToWrite,

                                                                                      LPDWORD                          lpNumberOfBytesWritten,

                                                                                      LPOVERLAPPED   lpOverlapped);

5) .设置波特率(与串口扩展兼容)

TERMRWVC_API BOOL ComSetCenterm(                        HANDLE               hFile,

                                                                                   unsigned long         ulBaudRate);

#define TAXUSBNAME                       TEXT("TAX1:")

//提供Usb接口,设备名为TAX1:

 

2  TermRWVC.cpp中主要完成以下操作:

1)  DllMainDLL的入口

2)   打开虚拟通道操作OpenTaxVc,调用WTSVirtualChannelOpen函数打开虚拟通道,该函数在2003SDKWtsapi32.h中定义。

3)  关闭虚拟通道操作CloseTaxVc

4)  读写虚拟通道操作DoTaxVc

5)  实现打开设备CreateFileCenterm,以TSUSBHSOPEN状态为参数调用DoTaxVc函数。

6)  实现关闭设备CloseHandleCenterm,以TSUSBHSCLOSE状态为参数调用DoTaxVc函数。

7)  实现读取文件ReadFileCenterm,以TSUSBHSREAD状态为参数调用DoTaxVc函数。

8)  实现写入文件WriteFileCenterm,以TSUSBHSWRITE状态为参数调用DoTaxVc函数。

9)  设置波特率ComSetCenterm没有实现。

 

3  DoTaxVc函数分析

涉及到的类结构TS_USB_DATA *p_usbdata,在StdAfx.h E:/project/UKEY/天安信源代码/TermRWVC050201/TermRWVC/StdAfx.h)中有定义。

根据dwOPtype的类型判断是以下哪种状态,执行相应的操作

1TSUSBHSOPEN ,

2TSUSBHSCLOSE           

3 TSUSBHSREAD            ,调用WTSVirtualChannelRead          

4) TSUSBHSWRITE            

5) TSUSBHSSMASK             0x0ce37    //SERVER data

6) TSUSBHSCMASK            0x0ce25    //CLIENT data

7) TSUSBHSTIMEOUT  40000;//INFINITE;

 

  usbVTC 虚拟通道Server

TSSysInfserver

E:/Program Files/Microsoft SDK/samples/winbase/WtsApi/TSSysInf/Server)程序改写。

1 SysInfo.hE:/Program Files/Microsoft SDK/samples/winbase/WtsApi/TSSysInf/Inc/SysInfo.h针对USBKEY做了部分修改:

1)  增加了虚拟通道USB操作类型的声明

2)  增加了类结构TS_USB_DATA 的声明

3)  增加了BOOL ReadUsbData(void)函数声明

4)  增加了BOOL WriteUsbData(DWORD dwlen,char * pszdata) 函数声明

2

VirtualChannelInitEventProc函数(SysInf_C.cpp

 

1Event事件定义

Value

Meaning

CHANNEL_EVENT_CONNECTED

A connection has been established with a terminal server that supports virtual channels. The pData parameter is a pointer to a null-terminated string with the name of the server.

CHANNEL_EVENT_DISCONNECTED

The connection to the terminal server has been disconnected. The pData parameter is NULL.

CHANNEL_EVENT_INITIALIZED

The Terminal Services client initialization has been completed. The pData parameter is NULL.

CHANNEL_EVENT_TERMINATED

The client has been terminated. The pData parameter is NULL.

CHANNEL_EVENT_V1_CONNECTED

A connection has been established with a terminal server that does not support virtual channels. The pData parameter is NULL.

CHANNEL_EVENT_REMOTE_CONTROL_START

A remote control operation has been started. The pData parameter is NULL.

CHANNEL_EVENT_REMOTE_CONTROL_STOP

A remote control operation has been terminated. The pData parameter is a pointer to a null-terminated string containing the name of the server.

 

2) PCHANNEL_ENTRY_POINTS pEntryPoints类结构体定义

typedef struct tagCHANNEL_ENTRY_POINTS {
  DWORD
cbSize;
  DWORD
protocolVersion;
  PVIRTUALCHANNELINIT
pVirtualChannelInit;
  PVIRTUALCHANNELOPEN
pVirtualChannelOpen;
  PVIRTUALCHANNELCLOSE
pVirtualChannelClose;
  PVIRTUALCHANNELWRITE
pVirtualChannelWrite;

} CHANNEL_ENTRY_POINTS, *PCHANNEL_ENTRY_POINTS;

 

3)  CHANNEL_EVENT_CONNECTED事件处理流程:

 

 

3 VirtualChannelOpenEvent  函数

1event 事件定义

[in] Indicates the event that caused the notification. This parameter can be one of the following values.

Value

Meaning

CHANNEL_EVENT_DATA_RECEIVED

The virtual channel received data from the server end. pData is a pointer to a chunk of the data. dataLength indicates the size of this chunk. totalLength indicates the total size of the data written by the server.

CHANNEL_EVENT_WRITE_CANCELLED

A write operation started by a VirtualChannelWrite call has been canceled. pData is the value specified in the pUserData parameter of VirtualChannelWrite.

A write operation is canceled when the client session is disconnected. This notification enables you to free any memory associated with the write operation.

CHANNEL_EVENT_WRITE_COMPLETE

A write operation started by a VirtualChannelWrite call has been completed. pData is the value specified in the pUserData parameter of VirtualChannelWrite.

 

 

4         WorkerThread线程函数

监听由客户端发来的指令

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值