Leaked source code of windows server 2003
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.

148 lines
4.5 KiB

  1. #include "precomp.h" // Precompiled header
  2. /************************************************************************/
  3. /* */
  4. /* Title : Dispatch Entry for INTERNAL IOCTLs */
  5. /* */
  6. /* Author : N.P.Vassallo */
  7. /* */
  8. /* Creation : 14th October 1998 */
  9. /* */
  10. /* Version : 1.0.0 */
  11. /* */
  12. /* Description : Internal IOCTLs support the SERENUM */
  13. /* attached serial device enumerator: */
  14. /* IOCTL_SERIAL_INTERNAL_BASIC_SETTINGS */
  15. /* IOCTL_SERIAL_INTERNAL_RESTORE_SETTINGS */
  16. /* */
  17. /************************************************************************/
  18. /* History...
  19. 1.0.0 14/20/98 NPV Creation.
  20. */
  21. #define FILE_ID SPX_IIOC_C // File ID for Event Logging see SPX_DEFS.H for values.
  22. /*****************************************************************************
  23. ********************** ***********************
  24. ********************** Spx_SerialInternalIoControl ***********************
  25. ********************** ***********************
  26. ******************************************************************************
  27. prototype: NTSTATUS Spx_SerialInternalIoControl(IN PDEVICE_OBJECT pDevObj, IN PIRP pIrp)
  28. description: Internal IOCTL dipatch routine.
  29. These IOCTLs are only issued from know trusted system components such as
  30. the SERENUM.SYS attached serial device enumerator and the mouse driver:
  31. parameters: pDevObj points to the device object structure
  32. pIrp points to the IOCTL Irp packet
  33. returns: STATUS_SUCCESS
  34. */
  35. NTSTATUS Spx_SerialInternalIoControl(IN PDEVICE_OBJECT pDevObj, IN PIRP pIrp)
  36. {
  37. NTSTATUS status;
  38. PIO_STACK_LOCATION pIrpStack;
  39. PPORT_DEVICE_EXTENSION pPort = pDevObj->DeviceExtension;
  40. KIRQL OldIrql;
  41. SpxDbgMsg(SPX_TRACE_IRP_PATH,("%s[card=%d,port=%d]: Internal IOCTL Dispatch Entry\n",
  42. PRODUCT_NAME, pPort->pParentCardExt->CardNumber, pPort->PortNumber));
  43. if(SerialCompleteIfError(pDevObj, pIrp) != STATUS_SUCCESS)
  44. return(STATUS_CANCELLED);
  45. pIrpStack = IoGetCurrentIrpStackLocation(pIrp);
  46. pIrp->IoStatus.Information = 0L;
  47. status = STATUS_SUCCESS;
  48. switch(pIrpStack->Parameters.DeviceIoControl.IoControlCode)
  49. {
  50. case IOCTL_SERIAL_INTERNAL_BASIC_SETTINGS:
  51. case IOCTL_SERIAL_INTERNAL_RESTORE_SETTINGS:
  52. {
  53. SERIAL_BASIC_SETTINGS Basic;
  54. PSERIAL_BASIC_SETTINGS pBasic;
  55. SERIAL_IOCTL_SYNC S;
  56. if (pIrpStack->Parameters.DeviceIoControl.IoControlCode
  57. == IOCTL_SERIAL_INTERNAL_BASIC_SETTINGS)
  58. {
  59. /* Check the buffer size... */
  60. if(pIrpStack->Parameters.DeviceIoControl.OutputBufferLength
  61. < sizeof(SERIAL_BASIC_SETTINGS))
  62. {
  63. status = STATUS_BUFFER_TOO_SMALL;
  64. break;
  65. }
  66. /* Everything is 0 -- timeouts and flow control. */
  67. /* If we add additional features, this zero memory method may not work. */
  68. RtlZeroMemory(&Basic,sizeof(SERIAL_BASIC_SETTINGS));
  69. pIrp->IoStatus.Information = sizeof(SERIAL_BASIC_SETTINGS);
  70. pBasic = (PSERIAL_BASIC_SETTINGS)pIrp->AssociatedIrp.SystemBuffer;
  71. /* Save off the old settings... */
  72. RtlCopyMemory(&pBasic->Timeouts, &pPort->Timeouts, sizeof(SERIAL_TIMEOUTS));
  73. RtlCopyMemory(&pBasic->HandFlow, &pPort->HandFlow, sizeof(SERIAL_HANDFLOW));
  74. /* Point to our new settings... */
  75. pBasic = &Basic;
  76. }
  77. else
  78. {
  79. if(pIrpStack->Parameters.DeviceIoControl.InputBufferLength < sizeof(SERIAL_BASIC_SETTINGS))
  80. {
  81. status = STATUS_BUFFER_TOO_SMALL;
  82. break;
  83. }
  84. pBasic = (PSERIAL_BASIC_SETTINGS)pIrp->AssociatedIrp.SystemBuffer;
  85. }
  86. KeAcquireSpinLock(&pPort->ControlLock,&OldIrql);
  87. /* Set the timeouts... */
  88. RtlCopyMemory(&pPort->Timeouts, &pBasic->Timeouts, sizeof(SERIAL_TIMEOUTS));
  89. /* Set flowcontrol... */
  90. S.pPort = pPort;
  91. S.Data = &pBasic->HandFlow;
  92. XXX_SetHandFlow(pPort, &S); /* Set the handflow for specific hardware */
  93. KeReleaseSpinLock(&pPort->ControlLock, OldIrql);
  94. break;
  95. }
  96. default:
  97. status = STATUS_INVALID_PARAMETER;
  98. break;
  99. }
  100. pIrp->IoStatus.Status = status;
  101. SpxDbgMsg(SPX_TRACE_IRP_PATH,("%s[card=%d,port=%d]: Internal IOCTL Dispatch Complete\n",
  102. PRODUCT_NAME, pPort->pParentCardExt->CardNumber, pPort->PortNumber));
  103. IoCompleteRequest(pIrp,0);
  104. return(status);
  105. } /* Spx_SerialInternalIoControl */
  106. /* End of SPX_IIOC.C */