ioctl.c
上传用户:zanmei2
上传日期:2010-03-06
资源大小:775k
文件大小:21k
源码类别:

通讯编程文档

开发平台:

C/C++

  1. /*++
  2. Copyright (c) 2005  Changzhi Zhou All Rights Reserved
  3. Module Name:
  4.     ioctl.c
  5. Abstract:
  6.     This module handles Device I/O control requests.
  7. Environment:
  8.     Kernel mode
  9. Revision History:
  10. Changzhi Zhou Dec 20  2004
  11. --*/
  12. #include <ntddk.h>
  13. #include <initguid.h>
  14. #include "main.h"
  15. #include "..incwdmioctl.h"
  16. NTSTATUS SampleIoControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
  17. /*++
  18. Routine Description:
  19.     The evice I/O control handle.
  20. All handle relevant to Serial Port are deal with here.
  21. Arguments:
  22.    DeviceObject - pointer to a device object.
  23.    Irp - pointer to an I/O Request Packet.
  24. Return Value:
  25.       NT status code
  26. --*/
  27. {
  28. PIO_STACK_LOCATION IrpStack;
  29. ULONG ControlCode;
  30. ULONG InputLength,OutputLength;
  31. NTSTATUS status;
  32. ULONG info;
  33. PUCHAR Buffer;
  34. PDEVICE_EXTENSION deviceExtension;
  35. KIRQL oldIrql;
  36. PAGED_CODE();
  37. deviceExtension = DeviceObject->DeviceExtension;
  38. if ( deviceExtension->DevicePnPState != Working)
  39. {
  40. status = STATUS_INVALID_DEVICE_STATE;
  41. return CompleteRequest(Irp, status, 0);
  42.     }
  43. IrpStack = IoGetCurrentIrpStackLocation(Irp);
  44. DebugPrint(("SampleIoControl: IrpStack 0x%08xn", IrpStack ));
  45. ControlCode = IrpStack->Parameters.DeviceIoControl.IoControlCode;
  46. InputLength = IrpStack->Parameters.DeviceIoControl.InputBufferLength;
  47. OutputLength= IrpStack->Parameters.DeviceIoControl.OutputBufferLength;
  48. info = 0;
  49. status = STATUS_SUCCESS;
  50. SampleIoIncrement ( deviceExtension );
  51. switch(ControlCode)
  52. {
  53. case IOCTL_CREATE_DOS_NAME:
  54. // create DosName, such as COM5.
  55. //
  56. status = CreateDosName( DeviceObject, Irp );
  57. break;
  58. case IOCTL_DELETE_DOS_NAME:
  59. status = SerialUndoExternalNaming( deviceExtension );
  60. break;
  61. case IOCTL_SET_REMOTE_INFO:
  62. if ( InputLength < ( sizeof ( ULONG ) * 2 ) )
  63. {
  64. status = STATUS_BUFFER_TOO_SMALL;
  65. break;
  66. }
  67. deviceExtension->RemoteAddress = *((ULONG *)Irp->AssociatedIrp.SystemBuffer);
  68. deviceExtension->RemotePort = (USHORT)*( ((ULONG *)Irp->AssociatedIrp.SystemBuffer) + 1);
  69. break;
  70. case IOCTL_QUERY_NETWORK_INFORMATION:
  71. if ( ( InputLength < sizeof( ULONG ) ) || ( OutputLength < sizeof ( ULONG ) ) )
  72. {
  73. status = STATUS_BUFFER_TOO_SMALL;
  74. break;
  75. }
  76. status = TDIQueryNetworkInformation ( DeviceObject, Irp );
  77. info = Irp->IoStatus.Information;
  78. break;
  79. case IOCTL_SERIAL_SET_WAIT_MASK:
  80. {
  81. ULONG NewMask;
  82. if ( IrpStack->Parameters.DeviceIoControl.InputBufferLength < sizeof(ULONG)) {
  83. status = STATUS_BUFFER_TOO_SMALL;
  84. break;
  85. }else{
  86. NewMask = *((ULONG *)Irp->AssociatedIrp.SystemBuffer);
  87. }
  88. DebugPrint(("--  IOCTL_SERIAL_SET_WAIT_MASK   --n"));
  89. if (NewMask & ~(SERIAL_EV_RXCHAR   |
  90. SERIAL_EV_RXFLAG   |
  91. SERIAL_EV_TXEMPTY  |
  92. SERIAL_EV_CTS      |
  93. SERIAL_EV_DSR      |
  94. SERIAL_EV_RLSD     |
  95. SERIAL_EV_BREAK    |
  96. SERIAL_EV_ERR      |
  97. SERIAL_EV_RING     |
  98. SERIAL_EV_PERR     |
  99. SERIAL_EV_RX80FULL |
  100. SERIAL_EV_EVENT1   |
  101. SERIAL_EV_EVENT2)) {
  102. DebugPrint(("SERIAL: Unknown mask %xn",NewMask));
  103. status = STATUS_INVALID_PARAMETER;
  104. break;
  105. }
  106. DebugPrint(("Set wait mask:   0x%xn", NewMask ));
  107. KeAcquireSpinLock ( &deviceExtension->ThreadSpinLock, &oldIrql );
  108. //
  109. // Set wait mask means that we will wait NEW mask.
  110. // So we must complete WaitOnMaskIrp and PendingReadIrp
  111. //
  112. if( deviceExtension->WaitOnMaskIrp ){
  113. // 取消上一次的WAIT_ON_MASK Irp
  114. *((ULONG *)deviceExtension->WaitOnMaskIrp->AssociatedIrp.SystemBuffer) = 0;
  115. CompleteRequest( deviceExtension->WaitOnMaskIrp, STATUS_SUCCESS, sizeof( ULONG ));
  116. SampleIoDecrement( deviceExtension );
  117. deviceExtension->WaitOnMaskIrp = NULL;
  118. }
  119. deviceExtension->WaitMask = NewMask;
  120. KeReleaseSpinLock ( &deviceExtension->ThreadSpinLock, oldIrql );
  121. status = STATUS_SUCCESS;
  122. break;
  123. }
  124. case IOCTL_SERIAL_WAIT_ON_MASK:
  125. {
  126. ULONG RetMask;
  127. DebugPrint(("--  IOCTL_SERIAL_WAIT_ON_MASK   --n"));
  128. if ( IrpStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(ULONG)) {
  129. DebugPrint(("SERIAL: Invalid size for the buffer %dn",
  130. IrpStack->Parameters.DeviceIoControl.OutputBufferLength));
  131. status = STATUS_BUFFER_TOO_SMALL;
  132. break;
  133. }
  134. KeAcquireSpinLock ( &deviceExtension->ThreadSpinLock, &oldIrql );
  135. if( deviceExtension->WaitOnMaskIrp ){
  136. DebugPrint(("There is a wait-on-mask request already pendingn"));
  137. status = STATUS_INVALID_PARAMETER;
  138. KeReleaseSpinLock ( &deviceExtension->ThreadSpinLock, oldIrql );
  139. break;
  140. }
  141. // Mark the Irp here. Then we check COMMSTATUS at intervals in another thread
  142. // to determine whether or not to complete this Irp.
  143. //
  144. DebugPrint(("MarkIrpPendingn"));
  145. IoMarkIrpPending( Irp );
  146. ASSERT( deviceExtension->WaitOnMaskIrp == NULL );
  147. deviceExtension->WaitOnMaskIrp = Irp;
  148. KeReleaseSpinLock ( &deviceExtension->ThreadSpinLock, oldIrql );
  149. status = STATUS_PENDING;
  150. return status;
  151. }
  152. case IOCTL_SERIAL_PURGE:
  153. {
  154. ULONG PurgeMask;
  155. DebugPrint(("--   IOCTL_SERIAL_PURGE  --n"));
  156. if ( IrpStack->Parameters.DeviceIoControl.InputBufferLength <
  157. sizeof( ULONG )) {
  158. DebugPrint(("Serial purge output buffer too smalln"));
  159. status = STATUS_BUFFER_TOO_SMALL;
  160. break;
  161. }
  162. PurgeMask = *(PULONG)Irp->AssociatedIrp.SystemBuffer;
  163. DebugPrint(("IOCTL_SERIAL_PURGE:   0x%xn", PurgeMask));
  164. KeAcquireSpinLock( &deviceExtension->ThreadSpinLock, &oldIrql );
  165. if( ( PurgeMask & SERIAL_PURGE_RXABORT ) || ( PurgeMask & SERIAL_PURGE_RXCLEAR ) ){
  166. // purge Rx buffer and complete PendingReadIrp
  167. DebugPrint(( "SERIAL_PURGE_RXABORTn" ));
  168. deviceExtension->SerialStatus.AmountInInQueue = 0;
  169. deviceExtension->lpRx = deviceExtension->RxBuffer;
  170. deviceExtension->lpRead = deviceExtension->RxBuffer;
  171. }
  172. if ( ( PurgeMask & SERIAL_PURGE_TXABORT ) || ( PurgeMask & SERIAL_PURGE_TXCLEAR ) ){
  173. // purge Tx buffer
  174. DebugPrint(( "SERIAL_PURGE_TXABORTn" ));
  175. }
  176. KeReleaseSpinLock ( &deviceExtension->ThreadSpinLock, oldIrql );
  177. info = sizeof( ULONG );
  178. status = STATUS_SUCCESS;
  179. break;
  180. }
  181. case IOCTL_SERIAL_GET_COMMSTATUS:
  182. {
  183. DebugPrint(("--  IOCTL_SERIAL_GET_COMMSTATUS   --n"));
  184. if( IrpStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof( SERIAL_STATUS ) ){
  185. status = STATUS_BUFFER_TOO_SMALL;
  186. break;
  187. }
  188. KeAcquireSpinLock ( &deviceExtension->ThreadSpinLock, &oldIrql );
  189. RtlCopyMemory( Irp->AssociatedIrp.SystemBuffer, &deviceExtension->SerialStatus, sizeof ( SERIAL_STATUS ) );
  190. DebugPrint(("InQueue = %d  OutQueue = %dn", deviceExtension->SerialStatus.AmountInInQueue, deviceExtension->SerialStatus.AmountInOutQueue ));
  191. KeReleaseSpinLock ( &deviceExtension->ThreadSpinLock, oldIrql );
  192. info = sizeof ( SERIAL_STATUS );
  193. status = STATUS_SUCCESS;
  194. break;
  195. }
  196. case IOCTL_SERIAL_GET_WAIT_MASK:
  197. {
  198. DebugPrint(("--  IOCTL_SERIAL_GET_WAIT_MASK   --n"));
  199. if( IrpStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof( ULONG ) ){
  200. status = STATUS_BUFFER_TOO_SMALL;
  201. break;
  202. }
  203. *(PULONG)Irp->AssociatedIrp.SystemBuffer = deviceExtension->WaitMask;
  204. info = sizeof ( ULONG );
  205. status = STATUS_SUCCESS;
  206. break;
  207. }
  208. case IOCTL_SERIAL_GET_BAUD_RATE:
  209. {
  210. PSERIAL_BAUD_RATE Br = ( PSERIAL_BAUD_RATE )Irp->AssociatedIrp.SystemBuffer;
  211. DebugPrint(("--  IOCTL_SERIAL_GET_BAUD_RATE  ---n"));
  212. if( IrpStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof( SERIAL_BAUD_RATE ) ){
  213. status = STATUS_BUFFER_TOO_SMALL;
  214. break;
  215. }
  216. Br->BaudRate = deviceExtension->CurrentBaud;
  217. DebugPrint(("CurrentBaud:  %d    Br->BaudRate   %dn", deviceExtension->CurrentBaud, Br->BaudRate ));
  218. info = sizeof( SERIAL_BAUD_RATE );
  219. status = STATUS_SUCCESS;
  220. break;
  221. }
  222. case IOCTL_SERIAL_SET_BAUD_RATE:
  223. DebugPrint(("--  IOCTL_SERIAL_SET_BAUD_RATE  ---n"));
  224. if( IrpStack->Parameters.DeviceIoControl.InputBufferLength < sizeof( SERIAL_BAUD_RATE ) ){
  225. status = STATUS_BUFFER_TOO_SMALL;
  226. break;
  227. }
  228. DebugPrint(("CurrentBaud :  %d     SetBaudRate:   %dn", deviceExtension->CurrentBaud, ((PSERIAL_BAUD_RATE)(Irp->AssociatedIrp.SystemBuffer))->BaudRate));
  229. deviceExtension->CurrentBaud = ((PSERIAL_BAUD_RATE)(Irp->AssociatedIrp.SystemBuffer))->BaudRate;
  230. status = STATUS_SUCCESS;
  231. break;
  232. case IOCTL_SERIAL_SET_LINE_CONTROL:
  233. {
  234. PSERIAL_LINE_CONTROL Lc;
  235. UCHAR LData;
  236. UCHAR LStop;
  237. UCHAR LParity;
  238. UCHAR Mask = 0xff;
  239. DebugPrint(("--  IOCTL_SERIAL_SET_LINE_CONTROL   --n"));
  240. if( IrpStack->Parameters.DeviceIoControl.InputBufferLength < sizeof(SERIAL_LINE_CONTROL)) {
  241. status = STATUS_BUFFER_TOO_SMALL;
  242. break;
  243. }
  244. Lc = ((PSERIAL_LINE_CONTROL)(Irp->AssociatedIrp.SystemBuffer));
  245. deviceExtension->LineControl.WordLength = Lc->WordLength;
  246. deviceExtension->LineControl.Parity = Lc->Parity;
  247. deviceExtension->LineControl.StopBits = Lc->StopBits;
  248. DebugPrint(("IOCTL_SERIAL_SET_LINE_CONTROL:  WordLength:  %d  Parity:  %d  StopBits  %dn", Lc->WordLength, Lc->Parity, Lc->StopBits ));
  249. status = STATUS_SUCCESS;
  250. break;
  251. }
  252. case IOCTL_SERIAL_GET_LINE_CONTROL:
  253. {
  254. PSERIAL_LINE_CONTROL Lc = (PSERIAL_LINE_CONTROL)Irp->AssociatedIrp.SystemBuffer;
  255. DebugPrint(("--  IOCTL_SERIAL_GET_LINE_CONTROL   --n"));
  256. if (IrpStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(SERIAL_LINE_CONTROL)) {
  257. status = STATUS_BUFFER_TOO_SMALL;
  258. break;
  259. }
  260. Lc->WordLength = deviceExtension->LineControl.WordLength;
  261. Lc->Parity = deviceExtension->LineControl.Parity;
  262. Lc->StopBits = deviceExtension->LineControl.StopBits;
  263. DebugPrint(("IOCTL_SERIAL_GET_LINE_CONTROL:  WordLength:  %d  Parity:  %d  StopBits  %dn", Lc->WordLength, Lc->Parity, Lc->StopBits ));
  264. info = sizeof(SERIAL_LINE_CONTROL);
  265. status = STATUS_SUCCESS;
  266. break;
  267. }
  268. case IOCTL_SERIAL_SET_TIMEOUTS:
  269. {
  270. PSERIAL_TIMEOUTS NewTimeouts =
  271. ((PSERIAL_TIMEOUTS)(Irp->AssociatedIrp.SystemBuffer));
  272. DebugPrint(("--  IOCTL_SERIAL_SET_TIMEOUTS   --n"));
  273. if ( IrpStack->Parameters.DeviceIoControl.InputBufferLength <
  274. sizeof(SERIAL_TIMEOUTS)) {
  275. status = STATUS_BUFFER_TOO_SMALL;
  276. break;
  277. }
  278. if ((NewTimeouts->ReadIntervalTimeout == MAXULONG) &&
  279. (NewTimeouts->ReadTotalTimeoutMultiplier == MAXULONG) &&
  280. (NewTimeouts->ReadTotalTimeoutConstant == MAXULONG)) {
  281. status = STATUS_INVALID_PARAMETER;
  282. break;
  283. }
  284. deviceExtension->Timeouts.ReadIntervalTimeout = NewTimeouts->ReadIntervalTimeout;
  285. deviceExtension->Timeouts.ReadTotalTimeoutMultiplier =NewTimeouts->ReadTotalTimeoutMultiplier;
  286. deviceExtension->Timeouts.ReadTotalTimeoutConstant = NewTimeouts->ReadTotalTimeoutConstant;
  287. deviceExtension->Timeouts.WriteTotalTimeoutMultiplier = NewTimeouts->WriteTotalTimeoutMultiplier;
  288. deviceExtension->Timeouts.WriteTotalTimeoutConstant = NewTimeouts->WriteTotalTimeoutConstant;
  289. DebugPrint(("Set_Timeoutsn"));
  290. status = STATUS_SUCCESS;
  291. break;
  292. }
  293. case IOCTL_SERIAL_GET_TIMEOUTS:
  294. {
  295. if ( IrpStack->Parameters.DeviceIoControl.OutputBufferLength <
  296. sizeof(SERIAL_TIMEOUTS)) {
  297. status = STATUS_BUFFER_TOO_SMALL;
  298. break;
  299. }
  300. DebugPrint(("--  IOCTL_SERIAL_GET_TIMEOUTS   --n"));
  301. *((PSERIAL_TIMEOUTS)Irp->AssociatedIrp.SystemBuffer) = deviceExtension->Timeouts;
  302. info = sizeof( SERIAL_TIMEOUTS );
  303. status = STATUS_SUCCESS;
  304. break;
  305. }
  306. case IOCTL_SERIAL_SET_CHARS:
  307. {
  308. PSERIAL_CHARS NewChars =
  309. ((PSERIAL_CHARS)(Irp->AssociatedIrp.SystemBuffer));
  310. DebugPrint(("--  IOCTL_SERIAL_SET_CHARS   --n"));
  311. if ( IrpStack->Parameters.DeviceIoControl.InputBufferLength <
  312. ( sizeof( UCHAR ) * 6 ) ) {
  313. status = STATUS_BUFFER_TOO_SMALL;
  314. break;
  315. }else /*if( NewChars->XonChar == NewChars->XoffChar ){
  316. status = STATUS_INVALID_PARAMETER;
  317. break;
  318. }else */{
  319. deviceExtension->SpecialChars.EofChar = NewChars->EofChar;
  320. deviceExtension->SpecialChars.ErrorChar = NewChars->ErrorChar;
  321. deviceExtension->SpecialChars.BreakChar = NewChars->BreakChar;
  322. deviceExtension->SpecialChars.EventChar = NewChars->EventChar;
  323. deviceExtension->SpecialChars.XonChar = NewChars->XonChar;
  324. deviceExtension->SpecialChars.XoffChar = NewChars->XoffChar;
  325. DebugPrint(("SetChars:  %2x %2x %2x %2x %2x %2xn", NewChars->EofChar, NewChars->ErrorChar, NewChars->BreakChar, NewChars->EventChar, NewChars->XonChar, NewChars->XoffChar ));
  326. status = STATUS_SUCCESS;
  327. }
  328. break;
  329. }
  330. case IOCTL_SERIAL_GET_CHARS:
  331. {
  332. PSERIAL_CHARS NewChars = ((PSERIAL_CHARS)(Irp->AssociatedIrp.SystemBuffer));
  333. DebugPrint(("--  IOCTL_SERIAL_GET_CHARS   --n"));
  334. if( IrpStack->Parameters.DeviceIoControl.OutputBufferLength <
  335. sizeof(SERIAL_CHARS)) {
  336. status = STATUS_BUFFER_TOO_SMALL;
  337. break;
  338. }
  339. ((PSERIAL_CHARS)Irp->AssociatedIrp.SystemBuffer)->XonChar = deviceExtension->SpecialChars.XonChar;
  340. ((PSERIAL_CHARS)Irp->AssociatedIrp.SystemBuffer)->XoffChar = deviceExtension->SpecialChars.XoffChar;
  341. ((PSERIAL_CHARS)Irp->AssociatedIrp.SystemBuffer)->EofChar = deviceExtension->SpecialChars.EofChar;
  342. ((PSERIAL_CHARS)Irp->AssociatedIrp.SystemBuffer)->ErrorChar = deviceExtension->SpecialChars.ErrorChar;
  343. ((PSERIAL_CHARS)Irp->AssociatedIrp.SystemBuffer)->BreakChar = deviceExtension->SpecialChars.BreakChar;
  344. ((PSERIAL_CHARS)Irp->AssociatedIrp.SystemBuffer)->EventChar = deviceExtension->SpecialChars.EventChar;
  345. DebugPrint(("GetChars:  %2x %2x %2x %2x %2x %2xn", NewChars->EofChar, NewChars->ErrorChar, NewChars->BreakChar, NewChars->EventChar, NewChars->XonChar, NewChars->XoffChar ));
  346. info = sizeof( SERIAL_CHARS );
  347. status = STATUS_SUCCESS;
  348. break;
  349. }
  350. case IOCTL_SERIAL_SET_DTR:
  351. {
  352. DebugPrint(("--  IOCTL_SERIAL_SET_DTR   --n"));
  353. if (( deviceExtension->HandFlow.ControlHandShake & SERIAL_DTR_MASK) == SERIAL_DTR_HANDSHAKE){
  354. DebugPrint(("IOCTL_SERIAL_SET_DTR error: Current ControlHandShake 0x%xn", deviceExtension->HandFlow.ControlHandShake ));
  355. status = STATUS_INVALID_PARAMETER;
  356. }
  357. info = 0;
  358. //*(PULONG)Irp->AssociatedIrp.SystemBuffer = 0;
  359. status = STATUS_SUCCESS;
  360. break;
  361. }
  362.         case IOCTL_SERIAL_CLR_DTR:
  363. {
  364. DebugPrint(("--  IOCTL_SERIAL_CLR_DTR   --n"));
  365. if (( deviceExtension->HandFlow.ControlHandShake & SERIAL_DTR_MASK) == SERIAL_DTR_HANDSHAKE){
  366. DebugPrint(("IOCTL_SERIAL_CLR_DTR errorn"));
  367. status = STATUS_INVALID_PARAMETER;
  368. }
  369. //*(PULONG)Irp->AssociatedIrp.SystemBuffer = 0;
  370. status = STATUS_SUCCESS;
  371. break;
  372. }
  373. case IOCTL_SERIAL_SET_RTS:
  374. {
  375. DebugPrint(("--  IOCTL_SERIAL_SET_RTS   --n"));
  376. if (( deviceExtension->HandFlow.FlowReplace & SERIAL_RTS_MASK) == SERIAL_RTS_HANDSHAKE ){
  377. DebugPrint(("IOCTL_SERIAL_SET_RTS errorn"));
  378. status = STATUS_INVALID_PARAMETER;
  379. }
  380. status = STATUS_SUCCESS;
  381. break;
  382. }
  383. case IOCTL_SERIAL_SET_QUEUE_SIZE:
  384. {
  385. PSERIAL_QUEUE_SIZE Rs = ( PSERIAL_QUEUE_SIZE )Irp->AssociatedIrp.SystemBuffer;
  386. DebugPrint(("--  IOCTL_SERIAL_SET_QUEUE_SIZE   --n"));
  387. if( IrpStack->Parameters.DeviceIoControl.InputBufferLength < sizeof(SERIAL_QUEUE_SIZE)) {
  388. status = STATUS_BUFFER_TOO_SMALL;
  389. break;
  390. }
  391. if( Rs->InSize > deviceExtension->BufferSize ){
  392. deviceExtension->BufferSize = Rs->InSize;
  393. }
  394. DebugPrint(("Buffersize :  %dn", deviceExtension->BufferSize ));
  395. status = STATUS_SUCCESS;
  396. break;
  397. }
  398. case IOCTL_SERIAL_GET_HANDFLOW:
  399. {
  400. PSERIAL_HANDFLOW HandFlow;
  401. DebugPrint(("--  IOCTL_SERIAL_GET_HANDFLOW   --n"));
  402. if ( IrpStack->Parameters.DeviceIoControl.OutputBufferLength <
  403. sizeof(SERIAL_HANDFLOW)) {
  404. status = STATUS_BUFFER_TOO_SMALL;
  405. break;
  406. }
  407. HandFlow = (PSERIAL_HANDFLOW)Irp->AssociatedIrp.SystemBuffer;
  408. HandFlow->ControlHandShake = deviceExtension->HandFlow.ControlHandShake;
  409. HandFlow->FlowReplace = deviceExtension->HandFlow.FlowReplace;
  410. HandFlow->XonLimit = deviceExtension->HandFlow.XonLimit;
  411. HandFlow->XoffLimit = deviceExtension->HandFlow.XoffLimit;
  412. DebugPrint(("ControlHandShake:  %d  FlowReplace:  %d  XonLimit:  %d  XoffLimit:  %dn", HandFlow->ControlHandShake, HandFlow->FlowReplace, HandFlow->XonLimit, HandFlow->XoffLimit));
  413. info = sizeof(SERIAL_HANDFLOW);
  414. status = STATUS_SUCCESS;
  415. break;
  416. }
  417. case IOCTL_SERIAL_SET_HANDFLOW:
  418. {
  419.             PSERIAL_HANDFLOW HandFlow = Irp->AssociatedIrp.SystemBuffer;
  420. if ( IrpStack->Parameters.DeviceIoControl.InputBufferLength <
  421. sizeof(SERIAL_HANDFLOW)) {
  422. status = STATUS_BUFFER_TOO_SMALL;
  423. break;
  424. }
  425. DebugPrint(("--  IOCTL_SERIAL_SET_HANDFLOW   --n"));
  426. if (HandFlow->ControlHandShake & SERIAL_CONTROL_INVALID) {
  427. status = STATUS_INVALID_PARAMETER;
  428. break;
  429. }
  430. if (HandFlow->FlowReplace & SERIAL_FLOW_INVALID) {
  431. status = STATUS_INVALID_PARAMETER;
  432. break;
  433. }
  434. if ((HandFlow->ControlHandShake & SERIAL_DTR_MASK) ==
  435. SERIAL_DTR_MASK) {
  436. status = STATUS_INVALID_PARAMETER;
  437. break;
  438. }
  439. if ((HandFlow->XonLimit < 0) ||
  440. ((ULONG)HandFlow->XonLimit > deviceExtension->BufferSize)) {
  441. DebugPrint(("XonLimit( %d ) > BufferSizen", ((ULONG)HandFlow->XonLimit )));
  442. status = STATUS_INVALID_PARAMETER;
  443. break;
  444. }
  445. if ((HandFlow->XoffLimit < 0) ||
  446. ((ULONG)HandFlow->XoffLimit > deviceExtension->BufferSize)) {
  447. DebugPrint(("XoffLimit( %d ) > BufferSizen", ((ULONG)HandFlow->XoffLimit )));
  448. status = STATUS_INVALID_PARAMETER;
  449. break;
  450. }
  451. deviceExtension->HandFlow.ControlHandShake = HandFlow->ControlHandShake;
  452. deviceExtension->HandFlow.FlowReplace = HandFlow->FlowReplace;
  453. deviceExtension->HandFlow.XonLimit = HandFlow->XonLimit;
  454. deviceExtension->HandFlow.XoffLimit = HandFlow->XoffLimit;
  455. DebugPrint(("Set_HandFlow OKn"));
  456. status = STATUS_SUCCESS;
  457. break;
  458. }
  459. case IOCTL_SERIAL_CONFIG_SIZE:
  460. {
  461. DebugPrint(("--  IOCTL_SERIAL_CONFIG_SIZE   --n"));
  462. if( IrpStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof( ULONG ) ){
  463. status = STATUS_BUFFER_TOO_SMALL;
  464. break;
  465. }
  466. info = sizeof( ULONG );
  467. *(PULONG)Irp->AssociatedIrp.SystemBuffer = 0;
  468. status = STATUS_SUCCESS;
  469. break;
  470. }
  471. case IOCTL_SERIAL_IMMEDIATE_CHAR:
  472. DebugPrint(("--  IOCTL_SERIAL_IMMEDIATE_CHAR   --n"));
  473. break;
  474. case IOCTL_SERIAL_GET_STATS:
  475. DebugPrint(("--  IOCTL_SERIAL_GET_STATS   --n"));
  476. break;
  477. case IOCTL_SERIAL_CLEAR_STATS:
  478. DebugPrint(("--  IOCTL_SERIAL_CLEAR_STATS   --n"));
  479. break;
  480. case IOCTL_SERIAL_GET_PROPERTIES:
  481. DebugPrint(("--  IOCTL_SERIAL_GET_PROPERTIES   --n"));
  482. break;
  483. case IOCTL_SERIAL_XOFF_COUNTER:
  484. DebugPrint(("--  IOCTL_SERIAL_XOFF_COUNTER   --n"));
  485. break;
  486. case IOCTL_SERIAL_LSRMST_INSERT:
  487. DebugPrint(("--  IOCTL_SERIAL_LSRMST_INSERT   --n"));
  488. break;
  489. case IOCTL_SERIAL_GET_MODEMSTATUS:
  490. DebugPrint(("--  IOCTL_SERIAL_GET_MODEMSTATUS   --n"));
  491. break;
  492. case IOCTL_SERIAL_GET_DTRRTS:
  493. DebugPrint(("--  IOCTL_SERIAL_GET_DTRRTS   --n"));
  494. break;
  495. case IOCTL_SERIAL_CLR_RTS:
  496. DebugPrint(("--  IOCTL_SERIAL_CLR_RTS   --n"));
  497. break;
  498. case IOCTL_SERIAL_SET_XOFF:
  499. DebugPrint(("--  IOCTL_SERIAL_SET_XOFF   --n"));
  500. break;
  501. case IOCTL_SERIAL_SET_XON:
  502. DebugPrint(("--  IOCTL_SERIAL_SET_XON   --n"));
  503. break;
  504. case IOCTL_SERIAL_SET_BREAK_ON:
  505. DebugPrint(("--  IOCTL_SERIAL_SET_BREAK_ON   --n"));
  506. break;
  507. case IOCTL_SERIAL_SET_BREAK_OFF:
  508. DebugPrint(("--  IOCTL_SERIAL_SET_BREAK_OFF   --n"));
  509. break;
  510. case IOCTL_SERIAL_RESET_DEVICE:
  511. DebugPrint(("--  IOCTL_SERIAL_RESET_DEVICE   --n"));
  512. break;
  513. case IOCTL_SERIAL_GET_MODEM_CONTROL:
  514. DebugPrint(("--  IOCTL_SERIAL_GET_MODEM_CONTROL   --n"));
  515. break;
  516. case IOCTL_SERIAL_SET_MODEM_CONTROL:
  517. DebugPrint(("--  IOCTL_SERIAL_SET_MODEM_CONTROL   --n"));
  518. break;
  519. case IOCTL_SERIAL_SET_FIFO_CONTROL:
  520. DebugPrint(("--  IOCTL_SERIAL_SET_FIFO_CONTROL   --n"));
  521. break;
  522. default:
  523. status=STATUS_INVALID_DEVICE_REQUEST;
  524. break;
  525. }
  526. status = CompleteRequest( Irp, status, info );
  527.     SampleIoDecrement( deviceExtension );
  528. return status;
  529. }
  530. NTSTATUS CreateDosName( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
  531. /*++
  532. Routine Description:
  533. Create Dosname.
  534. Arguments:
  535.    DeviceObject - pointer to a device object.
  536.    Irp - pointer to an I/O Request Packet.
  537. Return Value:
  538.       NT status code
  539. --*/
  540. {
  541. LONG ComX;
  542. PIO_STACK_LOCATION IrpStack;
  543. NTSTATUS status;
  544. PDEVICE_EXTENSION deviceExtension;
  545. deviceExtension = DeviceObject->DeviceExtension;
  546. DebugPrint(("-----  IOCTL_INIT_SETTING   ----n"));
  547. IrpStack = IoGetCurrentIrpStackLocation(Irp);
  548. if( IrpStack->Parameters.DeviceIoControl.InputBufferLength < sizeof( LONG ) ){
  549. status = STATUS_BUFFER_TOO_SMALL;
  550. return status;
  551. }
  552. ComX = *((PLONG)Irp->AssociatedIrp.SystemBuffer);
  553. // 此处注意Dos名不要重复
  554. if( ( ComX > 255 ) || ( ComX < 1 ) ){
  555. status = STATUS_INVALID_PARAMETER;
  556. return status;
  557. }
  558. if( !deviceExtension->CreatedSymbolicLink ){
  559. status = SerialDoExternalNaming( deviceExtension, ComX);
  560. }
  561. return status;
  562. }