Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

235 lines
6.2 KiB

  1. /*************************************************************************
  2. * CHANNEL.C
  3. *
  4. * Copyright 1996, Citrix Systems Inc.
  5. * Copyright (C) 1997-1999 Microsoft Corp.
  6. *
  7. * Author: Marc Bloomfield
  8. * Terry Treder
  9. * Brad Pedersen
  10. *************************************************************************/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. /*=============================================================================
  14. == External procedures defined
  15. =============================================================================*/
  16. NTSTATUS IcaChannelOpen( HANDLE hIca, CHANNELCLASS, PVIRTUALCHANNELNAME, HANDLE * phChannel );
  17. NTSTATUS IcaChannelClose( HANDLE hChannel );
  18. NTSTATUS IcaChannelIoControl( HANDLE hChannel, ULONG, PVOID, ULONG, PVOID, ULONG, PULONG );
  19. VOID cdecl IcaChannelTrace( IN HANDLE hChannel, ULONG, ULONG, char *, ... );
  20. /*=============================================================================
  21. == Internal procedures defined
  22. =============================================================================*/
  23. /*=============================================================================
  24. == Procedures used
  25. =============================================================================*/
  26. NTSTATUS _IcaStackOpen( HANDLE hIca, HANDLE * phStack, ICA_OPEN_TYPE, PICA_TYPE_INFO );
  27. /****************************************************************************
  28. *
  29. * IcaChannelOpen
  30. *
  31. * Open an ICA channel
  32. *
  33. * ENTRY:
  34. * hIca (input)
  35. * ICA instance handle
  36. *
  37. * Channel (input)
  38. * ICA channel
  39. *
  40. * pVirtualName (input)
  41. * pointer to virtual channel name
  42. * phChannel (output)
  43. * Pointer to ICA channel handle
  44. *
  45. * EXIT:
  46. * STATUS_SUCCESS - Success
  47. * other - Error return code
  48. *
  49. ****************************************************************************/
  50. NTSTATUS
  51. IcaChannelOpen( IN HANDLE hIca,
  52. IN CHANNELCLASS Channel,
  53. IN PVIRTUALCHANNELNAME pVirtualName,
  54. OUT HANDLE * phChannel )
  55. {
  56. ICA_TYPE_INFO TypeInfo;
  57. NTSTATUS Status;
  58. RtlZeroMemory( &TypeInfo, sizeof(TypeInfo) );
  59. TypeInfo.ChannelClass = Channel;
  60. if ( pVirtualName )
  61. strncpy( TypeInfo.VirtualName, pVirtualName, sizeof(TypeInfo.VirtualName) );
  62. Status = _IcaStackOpen( hIca, phChannel, IcaOpen_Channel, &TypeInfo );
  63. if ( !NT_SUCCESS(Status) )
  64. goto badopen;
  65. TRACE(( hIca, TC_ICAAPI, TT_API1, "TSAPI: IcaChannelOpen, %u/%s, %u, success\n",
  66. Channel, TypeInfo.VirtualName, *phChannel ));
  67. return( STATUS_SUCCESS );
  68. /*=============================================================================
  69. == Error returns
  70. =============================================================================*/
  71. badopen:
  72. TRACE(( hIca, TC_ICAAPI, TT_ERROR, "TSAPI: IcaChannelOpen, %u/%s, 0x%x\n",
  73. Channel, TypeInfo.VirtualName, Status ));
  74. return( Status );
  75. }
  76. /****************************************************************************
  77. *
  78. * IcaChannelClose
  79. *
  80. * Close an ICA channel
  81. *
  82. * ENTRY:
  83. * hChannel (input)
  84. * ICA channel handle
  85. *
  86. * EXIT:
  87. * STATUS_SUCCESS - Success
  88. * other - Error return code
  89. *
  90. ****************************************************************************/
  91. NTSTATUS
  92. IcaChannelClose( IN HANDLE hChannel )
  93. {
  94. NTSTATUS Status;
  95. TRACECHANNEL(( hChannel, TC_ICAAPI, TT_API1, "TSAPI: IcaChannelClose[%u]\n", hChannel ));
  96. /*
  97. * Close the ICA device driver channel instance
  98. */
  99. Status = NtClose( hChannel );
  100. ASSERT( NT_SUCCESS(Status) );
  101. return( Status );
  102. }
  103. /****************************************************************************
  104. *
  105. * IcaChannelIoControl
  106. *
  107. * Generic interface to an ICA channel
  108. *
  109. * ENTRY:
  110. * hChannel (input)
  111. * ICA channel handle
  112. *
  113. * IoControlCode (input)
  114. * I/O control code
  115. *
  116. * pInBuffer (input)
  117. * Pointer to input parameters
  118. *
  119. * InBufferSize (input)
  120. * Size of pInBuffer
  121. *
  122. * pOutBuffer (output)
  123. * Pointer to output buffer
  124. *
  125. * OutBufferSize (input)
  126. * Size of pOutBuffer
  127. *
  128. * pBytesReturned (output)
  129. * Pointer to number of bytes returned
  130. *
  131. * EXIT:
  132. * STATUS_SUCCESS - Success
  133. * other - Error return code
  134. *
  135. ****************************************************************************/
  136. NTSTATUS
  137. IcaChannelIoControl( IN HANDLE hChannel,
  138. IN ULONG IoControlCode,
  139. IN PVOID pInBuffer,
  140. IN ULONG InBufferSize,
  141. OUT PVOID pOutBuffer,
  142. IN ULONG OutBufferSize,
  143. OUT PULONG pBytesReturned )
  144. {
  145. NTSTATUS Status;
  146. Status = IcaIoControl( hChannel,
  147. IoControlCode,
  148. pInBuffer,
  149. InBufferSize,
  150. pOutBuffer,
  151. OutBufferSize,
  152. pBytesReturned );
  153. return( Status );
  154. }
  155. /*******************************************************************************
  156. *
  157. * IcaChannelTrace
  158. *
  159. * Write a trace record to the winstation trace file
  160. *
  161. * ENTRY:
  162. * hChannel (input)
  163. * ICA channel handle
  164. * TraceClass (input)
  165. * trace class bit mask
  166. * TraceEnable (input)
  167. * trace type bit mask
  168. * Format (input)
  169. * format string
  170. * ... (input)
  171. * enough arguments to satisfy format string
  172. *
  173. * EXIT:
  174. * nothing
  175. *
  176. ******************************************************************************/
  177. VOID cdecl
  178. IcaChannelTrace( IN HANDLE hChannel,
  179. IN ULONG TraceClass,
  180. IN ULONG TraceEnable,
  181. IN char * Format,
  182. IN ... )
  183. {
  184. ICA_TRACE_BUFFER Buffer;
  185. va_list arg_marker;
  186. ULONG Length;
  187. va_start( arg_marker, Format );
  188. Length = (ULONG) _vsnprintf( Buffer.Data, sizeof(Buffer.Data), Format, arg_marker );
  189. Buffer.TraceClass = TraceClass;
  190. Buffer.TraceEnable = TraceEnable;
  191. Buffer.DataLength = Length;
  192. (void) IcaIoControl( hChannel,
  193. IOCTL_ICA_CHANNEL_TRACE,
  194. &Buffer,
  195. sizeof(Buffer) - sizeof(Buffer.Data) + Length,
  196. NULL,
  197. 0,
  198. NULL );
  199. }