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.

304 lines
7.7 KiB

  1. /*++
  2. Module Name:
  3. moxa.c
  4. Environment:
  5. Kernel mode
  6. Revision History :
  7. --*/
  8. #include "precomp.h"
  9. PMOXA_GLOBAL_DATA MoxaGlobalData;
  10. LONG MoxaTxLowWater = WRITE_LOW_WATER;
  11. BOOLEAN MoxaIRQok;
  12. ULONG MoxaLoopCnt;
  13. UCHAR MoxaFlagBit[MAX_PORT];
  14. ULONG MoxaTotalTx[MAX_PORT];
  15. ULONG MoxaTotalRx[MAX_PORT];
  16. PMOXA_DEVICE_EXTENSION MoxaExtension[MAX_COM+1];
  17. /************ USED BY MoxaStartWrite ***********/
  18. BOOLEAN WRcompFlag;
  19. /************ USED BY ImmediateChar ***********/
  20. PUCHAR ICbase, ICofs, ICbuff;
  21. PUSHORT ICrptr, ICwptr;
  22. USHORT ICtxMask, ICspage, ICepage, ICbufHead;
  23. USHORT ICtail, IChead, ICcount;
  24. USHORT ICpageNo, ICpageOfs;
  25. /************ USED BY MoxaPutData **************/
  26. PUCHAR PDbase, PDofs, PDbuff, PDwriteChar;
  27. PUSHORT PDrptr, PDwptr;
  28. USHORT PDtxMask, PDspage, PDepage, PDbufHead;
  29. USHORT PDtail, PDhead, PDcount, PDcount2;
  30. USHORT PDcnt, PDlen, PDpageNo, PDpageOfs;
  31. ULONG PDdataLen;
  32. /************ USED BY MoxaGetData **************/
  33. PUCHAR GDbase, GDofs, GDbuff, GDreadChar;
  34. PUSHORT GDrptr, GDwptr;
  35. USHORT GDrxMask, GDspage, GDepage, GDbufHead;
  36. USHORT GDtail, GDhead, GDcount, GDcount2;
  37. USHORT GDcnt, GDlen, GDpageNo, GDpageOfs;
  38. ULONG GDdataLen;
  39. /************ USED BY MoxaIntervalReadTimeout ***/
  40. PUCHAR IRTofs;
  41. PUSHORT IRTrptr, IRTwptr;
  42. USHORT IRTrxMask;
  43. /************ USED BY MoxaLineInput & MoxaView **********/
  44. UCHAR LIterminater;
  45. ULONG LIbufferSize, LIi;
  46. PUCHAR LIdataBuffer;
  47. PUCHAR LIbase, LIofs, LIbuff;
  48. PUSHORT LIrptr, LIwptr;
  49. USHORT LIrxMask, LIspage, LIepage, LIbufHead;
  50. USHORT LItail, LIhead, LIcount, LIcount2;
  51. USHORT LIcnt, LIlen, LIpageNo, LIpageOfs;
  52. /************ USED BY MoxaPutB **********/
  53. PUCHAR PBbase, PBofs, PBbuff, PBwriteChar;
  54. PUSHORT PBrptr, PBwptr;
  55. USHORT PBtxMask, PBspage, PBepage, PBbufHead;
  56. USHORT PBtail, PBhead, PBcount, PBcount2;
  57. USHORT PBcnt, PBpageNo, PBpageOfs;
  58. ULONG PBdataLen;
  59. const PHYSICAL_ADDRESS MoxaPhysicalZero = {0};
  60. NTSTATUS
  61. DriverEntry(
  62. IN PDRIVER_OBJECT DriverObject,
  63. IN PUNICODE_STRING RegistryPath
  64. )
  65. /*++
  66. Routine Description:
  67. The entry point that the system point calls to initialize
  68. any driver.
  69. This routine will gather the configuration information,
  70. report resource usage, attempt to initialize all serial
  71. devices, connect to interrupts for ports. If the above
  72. goes reasonably well it will fill in the dispatch points,
  73. reset the serial devices and then return to the system.
  74. Arguments:
  75. DriverObject - Just what it says, really of little use
  76. to the driver itself, it is something that the IO system
  77. cares more about.
  78. PathToRegistry - points to the entry for this driver
  79. in the current control set of the registry.
  80. Return Value:
  81. STATUS_SUCCESS if we could initialize a single device,
  82. otherwise STATUS_SERIAL_NO_DEVICE_INITED.
  83. --*/
  84. {
  85. NTSTATUS status;
  86. PDEVICE_OBJECT currentDevice;
  87. UNICODE_STRING deviceNameUnicodeString;
  88. UNICODE_STRING deviceLinkUnicodeString;
  89. PMOXA_DEVICE_EXTENSION extension;
  90. ULONG i;
  91. MoxaGlobalData = ExAllocatePool(
  92. NonPagedPool,
  93. sizeof(MOXA_GLOBAL_DATA)
  94. );
  95. if (!MoxaGlobalData) {
  96. return STATUS_INSUFFICIENT_RESOURCES;
  97. }
  98. RtlZeroMemory(
  99. MoxaGlobalData,
  100. sizeof(MOXA_GLOBAL_DATA)
  101. );
  102. MoxaGlobalData->DriverObject = DriverObject;
  103. MoxaGlobalData->RegistryPath.MaximumLength = RegistryPath->Length;
  104. MoxaGlobalData->RegistryPath.Length = RegistryPath->Length;
  105. MoxaGlobalData->RegistryPath.Buffer = ExAllocatePool(
  106. PagedPool,
  107. MoxaGlobalData->RegistryPath.MaximumLength
  108. );
  109. if (!MoxaGlobalData->RegistryPath.Buffer) {
  110. // MmUnlockPagableImageSection(lockPtr);
  111. ExFreePool(MoxaGlobalData);
  112. return STATUS_INSUFFICIENT_RESOURCES;
  113. }
  114. RtlZeroMemory(
  115. MoxaGlobalData->RegistryPath.Buffer,
  116. MoxaGlobalData->RegistryPath.MaximumLength
  117. );
  118. RtlMoveMemory(MoxaGlobalData->RegistryPath.Buffer,
  119. RegistryPath->Buffer, RegistryPath->Length);
  120. RtlInitUnicodeString (
  121. &deviceNameUnicodeString,
  122. CONTROL_DEVICE_NAME
  123. );
  124. //
  125. // Create MXCTL device object
  126. //
  127. status = IoCreateDevice(
  128. DriverObject,
  129. sizeof(MOXA_DEVICE_EXTENSION),
  130. &deviceNameUnicodeString,
  131. FILE_DEVICE_SERIAL_PORT,
  132. 0,
  133. TRUE,
  134. &currentDevice
  135. );
  136. if (!NT_SUCCESS(status)) {
  137. ExFreePool(MoxaGlobalData->RegistryPath.Buffer);
  138. ExFreePool(MoxaGlobalData);
  139. return STATUS_INSUFFICIENT_RESOURCES;
  140. }
  141. RtlInitUnicodeString (
  142. &deviceLinkUnicodeString,
  143. CONTROL_DEVICE_LINK
  144. );
  145. IoCreateSymbolicLink (
  146. &deviceLinkUnicodeString,
  147. &deviceNameUnicodeString
  148. );
  149. extension = currentDevice->DeviceExtension;
  150. RtlZeroMemory(
  151. extension,
  152. sizeof(MOXA_DEVICE_EXTENSION)
  153. );
  154. extension->GlobalData = MoxaGlobalData;
  155. //
  156. // This device is used for MOXA defined ioctl functions
  157. //
  158. extension->ControlDevice = TRUE;
  159. //
  160. // Initialize the Driver Object with driver's entry points
  161. //
  162. DriverObject->DriverUnload = MoxaUnload;
  163. DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = MoxaFlush;
  164. DriverObject->MajorFunction[IRP_MJ_WRITE] = MoxaWrite;
  165. DriverObject->MajorFunction[IRP_MJ_READ] = MoxaRead;
  166. DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = MoxaIoControl;
  167. DriverObject->MajorFunction[IRP_MJ_CREATE] =MoxaCreateOpen;
  168. DriverObject->MajorFunction[IRP_MJ_CLOSE] = MoxaClose;
  169. DriverObject->MajorFunction[IRP_MJ_CLEANUP] = MoxaCleanup;
  170. DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] =
  171. MoxaQueryInformationFile;
  172. DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] =
  173. MoxaSetInformationFile;
  174. DriverObject->MajorFunction[IRP_MJ_PNP] = MoxaPnpDispatch;
  175. DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL]
  176. = MoxaInternalIoControl;
  177. DriverObject->MajorFunction[IRP_MJ_POWER] = MoxaPowerDispatch;
  178. DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL]
  179. = MoxaSystemControlDispatch;
  180. DriverObject->DriverExtension->AddDevice = MoxaAddDevice;
  181. //
  182. // 9-03-01 by William
  183. //
  184. MoxaLoop();
  185. //
  186. // 7-20-01 by William
  187. //
  188. MoxaInitTimeOutProc();
  189. return STATUS_SUCCESS;
  190. }
  191. VOID
  192. MoxaInitializeDevices(
  193. IN PDRIVER_OBJECT DriverObject,
  194. IN PMOXA_GLOBAL_DATA GlobalData
  195. )
  196. /*++
  197. Routine Description:
  198. This routine will set up names, creates the device, creates symbolic link.
  199. Arguments:
  200. DriverObject - Just used to create the device object.
  201. GlobalData - Pointer to MOXA global data.
  202. Return Value:
  203. None.
  204. --*/
  205. {
  206. }
  207. VOID
  208. MoxaUnload(
  209. IN PDRIVER_OBJECT DriverObject
  210. )
  211. {
  212. MoxaKdPrint(MX_DBG_TRACE,("Enter MoxaUnload\n"));
  213. //
  214. // 7-20-01 by William
  215. //
  216. MoxaStopTimeOutProc();
  217. ExFreePool(MoxaGlobalData->RegistryPath.Buffer);
  218. ExFreePool(MoxaGlobalData);
  219. }
  220.