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.

649 lines
14 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. asyncsft.h
  5. Abstract:
  6. Author:
  7. Environment:
  8. This driver is expected to work in DOS, OS2 and NT at the equivalent
  9. of kernal mode.
  10. Architecturally, there is an assumption in this driver that we are
  11. on a little endian machine.
  12. Notes:
  13. optional-notes
  14. Revision History:
  15. --*/
  16. #ifndef _ASYNCSFT_
  17. #define _ASYNCSFT_
  18. //
  19. // Memory tags
  20. //
  21. #define ASYNC_IOCTX_TAG '1ysA'
  22. #define ASYNC_INFO_TAG '2ysA'
  23. #define ASYNC_ADAPTER_TAG '3ysA'
  24. #define ASYNC_FRAME_TAG '4ysA'
  25. #define ASYNC_WORKITEM_TAG '5ysA'
  26. #define INLINE __inline
  27. //
  28. // UINT min(UINT a, UINT b)
  29. //
  30. #ifndef min
  31. #define min(a, b) ((a) <= (b) ? (a) : (b))
  32. #endif
  33. //
  34. // UINT max(UINT a, UINT b)
  35. //
  36. #ifndef max
  37. #define max(a, b) ((a) >= (b) ? (a) : (b))
  38. #endif
  39. #define MAKEWORD(l, h) ((USHORT) ((l) | ((h) << 8)))
  40. #define MAKELONG(l, h) ((ULONG) ((l) | ((h) << 16)))
  41. #define MAKE_SIGNATURE(a, b, c, d) MAKELONG(MAKEWORD(a, b), MAKEWORD(c, d))
  42. #define ASYNC_NDIS_MAJOR_VERSION 4
  43. #define ASYNC_NDIS_MINOR_VERSION 0
  44. // change these, just added these to compile.
  45. #define ETHERNET_HEADER_SIZE 14
  46. // what window size to request on the line-up indication
  47. #define ASYNC_WINDOW_SIZE 2
  48. //
  49. // PPP uses CIPX, and VJ TCP/IP header compression
  50. // the frame gets expanded inplace when decompressed.
  51. //
  52. #define PPP_PADDING 128
  53. #define MAC_NAME_SIZE 256
  54. //
  55. // ZZZ These macros are peculiar to NT.
  56. //
  57. #define ASYNC_MOVE_MEMORY(Destination,Source,Length) NdisMoveMemory(Destination,Source,Length)
  58. #define ASYNC_ZERO_MEMORY(Destination,Length) NdisZeroMemory(Destination,Length)
  59. /* Added this macro to eliminate problems caused by Tommy's redefinition and
  60. ** hard-coding of MaxFrameSize for PPP.
  61. */
  62. #define MaxFrameSizeWithPppExpansion(x) (((x)*2)+PPP_PADDING+100)
  63. typedef struct _OID_WORK_ITEM {
  64. WORK_QUEUE_ITEM WorkQueueItem;
  65. PVOID Context;
  66. } OID_WORK_ITEM, *POID_WORK_ITEM;
  67. //
  68. // Used to contain a queued operation.
  69. //
  70. typedef struct _ASYNC_PEND_DATA {
  71. PNDIS_REQUEST Next;
  72. struct _ASYNC_OPEN * Open;
  73. NDIS_REQUEST_TYPE RequestType;
  74. } ASYNC_PEND_DATA, * PASYNC_PEND_DATA;
  75. // o CRC errors are when the 16bit V.41 CRC check fails
  76. // o TimeoutErrors occur when inter-character delays within
  77. // a frame are exceeded
  78. // o AlignmentErrors occur when the SYN byte or ETX bytes which
  79. // mark the beginning and end of frames are not found.
  80. // o The other errors are standard UART errors returned by the serial driver
  81. typedef struct SERIAL_STATS SERIAL_STATS, *PSERIAL_STATS;
  82. struct SERIAL_STATS {
  83. ULONG CRCErrors; // Serial-like info only
  84. ULONG TimeoutErrors; // Serial-like info only
  85. ULONG AlignmentErrors; // Serial-like info only
  86. ULONG SerialOverrunErrors; // Serial-like info only
  87. ULONG FramingErrors; // Serial-like info only
  88. ULONG BufferOverrunErrors; // Serial-like info only
  89. };
  90. // The bytes transmitted, bytes received, frames received, frame transmitted
  91. // are monitored for frame and bytes going to the output device or
  92. // coming from the output device. If software compression used, it
  93. // is on top of this layer.
  94. typedef struct GENERIC_STATS GENERIC_STATS, *PGENERIC_STATS;
  95. struct GENERIC_STATS {
  96. ULONG BytesTransmitted; // Generic info
  97. ULONG BytesReceived; // Generic info
  98. ULONG FramesTransmitted; // Generic info
  99. ULONG FramesReceived; // Generic info
  100. };
  101. //
  102. // This macro will return a pointer to the reserved area of
  103. // a PNDIS_REQUEST.
  104. //
  105. #define PASYNC_PEND_DATA_FROM_PNDIS_REQUEST(Request) \
  106. ((PASYNC_PEND_DATA)((PVOID)((Request)->MacReserved)))
  107. //
  108. // This macros returns the enclosing NdisRequest.
  109. //
  110. #define PNDIS_REQUEST_FROM_PASYNC_PEND_DATA(PendOp)\
  111. ((PNDIS_REQUEST)((PVOID)(PendOp)))
  112. typedef struct ASYNC_CCB ASYNC_CCB, *PASYNC_CCB;
  113. // Every port will be atomically at some state. Typically states go into
  114. // intermediate states when they go from from closed to open and vice-versa.
  115. typedef enum _ASYNC_PORT_STATE {
  116. PORT_BOGUS, // PORT_BOGUS gets assigned the NULL value
  117. PORT_OPEN, // Port opened
  118. PORT_CLOSED, // Port closed
  119. PORT_CLOSING, // Port closing (cleaning up, deallocating)
  120. PORT_OPENING, // Port opening (checking arguments, allocating)
  121. PORT_FRAMING, // Port opened and sending/reading frames
  122. } ASYNC_PORT_STATE;
  123. //
  124. // The ASYNC_INFO structure is a per port field. The ASYNC_CONNECTION
  125. // field is embedded in it because it also a per port field.
  126. //
  127. struct ASYNC_INFO {
  128. LIST_ENTRY Linkage;
  129. ULONG RefCount;
  130. ULONG Flags;
  131. #define OID_WORK_SCHEDULED 0x00000001
  132. PASYNC_ADAPTER Adapter; // Back pointer to ADAPTER struct.
  133. PDEVICE_OBJECT DeviceObject; // Pointer to device object.
  134. ASYNC_PORT_STATE PortState; // OPEN, CLOSED, CLOSING, OPENING
  135. HANDLE Handle; // Port handle
  136. PFILE_OBJECT FileObject; // handle is dereferenced for IRPs
  137. KEVENT ClosingEvent; // we use this event to synch closing
  138. KEVENT DetectEvent; // sync the detect worker
  139. UINT QualOfConnect; // Defined by NDIS
  140. ULONG LinkSpeed; // in 100bps
  141. NDIS_HANDLE hNdisEndPoint;
  142. NDIS_HANDLE NdisLinkContext;
  143. LIST_ENTRY DDCDQueue;
  144. ULONG WaitMaskToUse ; // Wait mask used for reads.
  145. union {
  146. NDIS_WAN_GET_LINK_INFO GetLinkInfo; //... For OID requests.
  147. NDIS_WAN_SET_LINK_INFO SetLinkInfo;
  148. };
  149. // use for reading frames
  150. PASYNC_FRAME AsyncFrame; // allocated for READs (one frame only)
  151. WORK_QUEUE_ITEM WorkItem; // use to queue up first read thread
  152. UINT BytesWanted;
  153. UINT BytesRead;
  154. //... Statistics tracking
  155. SERIAL_STATS SerialStats; // Keep track of serial stats
  156. ULONG In;
  157. ULONG Out;
  158. UINT ReadStackCounter;
  159. NDIS_SPIN_LOCK Lock;
  160. };
  161. //
  162. // This structure, and it corresponding per port structures are
  163. // allocated when we get AddAdapter.
  164. //
  165. struct ASYNC_ADAPTER {
  166. //
  167. // WAN information. for OID_WAN_GET_INFO request.
  168. //
  169. NDIS_WAN_INFO WanInfo;
  170. //
  171. // Keeps a reference count on the current number of uses of
  172. // this adapter block. Uses is defined to be the number of
  173. // routines currently within the "external" interface.
  174. //
  175. LONG RefCount;
  176. //
  177. // List of active ports
  178. //
  179. LIST_ENTRY ActivePorts;
  180. //
  181. // Spinlock to protect fields in this structure..
  182. //
  183. NDIS_SPIN_LOCK Lock;
  184. //
  185. // Handle given by NDIS at MPInit
  186. //
  187. NDIS_HANDLE MiniportHandle;
  188. //
  189. // Flag that when enabled lets routines know that a reset
  190. // is in progress.
  191. //
  192. BOOLEAN ResetInProgress;
  193. /*
  194. LIST_ENTRY FramePoolHead;
  195. LIST_ENTRY AllocPoolHead;
  196. */
  197. // It will handle most file operations and transport
  198. // operations known today. You pay about 44 bytes
  199. // per stacksize. The registry parameter 'IrpStackSize'
  200. // will change this default if it exists.
  201. UCHAR IrpStackSize;
  202. // Here we default to the ethernet max frame size
  203. // The regsitry parameter 'MaxFrameSize' will change
  204. // this default if it exists.
  205. /* Note: This is meaningful only for non-PPP framing. For PPP framing the
  206. ** value is currently the hard-coded DEFAULT_PPP_MAX_FRAME_SIZE.
  207. ** See also DEFAULT_EXPANDED_PPP_MAX_FRAME_SIZE;
  208. */
  209. ULONG MaxFrameSize;
  210. //
  211. // Number of ports this adapter owns.
  212. //
  213. USHORT NumPorts;
  214. // How many frames to allocate per port.
  215. // The registry parameter 'FramesPerPort' can change this value
  216. USHORT FramesPerPort;
  217. // Minimum inter character timeout
  218. ULONG TimeoutBase;
  219. // Tacked on to TimeoutBase based on the baud rate
  220. ULONG TimeoutBaud;
  221. // Timeout to use to resync if a frame is dropped
  222. ULONG TimeoutReSync;
  223. //
  224. // Serial driver should only complete sends when the
  225. // data hits the wire
  226. //
  227. ULONG WriteBufferingEnabled;
  228. NPAGED_LOOKASIDE_LIST AsyncFrameList;
  229. };
  230. //
  231. // Define Maximum number of bytes a protocol can read during a
  232. // receive data indication.
  233. //
  234. #define ASYNC_MAX_LOOKAHEAD DEFAULT_MAX_FRAME_SIZE
  235. typedef struct _ASYNC_IO_CTX {
  236. BOOLEAN Sync;
  237. KEVENT Event; // use this event to signal completion
  238. IO_STATUS_BLOCK IoStatus; // use this to store Irp status
  239. PVOID Context;
  240. union {
  241. SERIAL_STATUS SerialStatus;
  242. SERIAL_QUEUE_SIZE SerialQueueSize;
  243. SERIAL_TIMEOUTS SerialTimeouts;
  244. SERIAL_CHARS SerialChars;
  245. SERIAL_COMMPROP CommProperties;
  246. UCHAR EscapeChar;
  247. UCHAR SerialPurge;
  248. ULONG WaitMask;
  249. ULONG WriteBufferingEnabled;
  250. };
  251. } ASYNC_IO_CTX, *PASYNC_IO_CTX;
  252. //
  253. // This macro will act a "epilogue" to every routine in the
  254. // *interface*. It will check whether any requests need
  255. // to defer their processing. It will also decrement the reference
  256. // count on the adapter.
  257. //
  258. // NOTE: This really does nothing now since there is no DPC for the AsyncMac.
  259. // --tommyd
  260. //
  261. // Note that we don't need to include checking for blocked receives
  262. // since blocked receives imply that there will eventually be an
  263. // interrupt.
  264. //
  265. // NOTE: This macro assumes that it is called with the lock acquired.
  266. //
  267. // ZZZ This routine is NT specific.
  268. //
  269. #define ASYNC_DO_DEFERRED(Adapter) \
  270. { \
  271. PASYNC_ADAPTER _A = (Adapter); \
  272. _A->References--; \
  273. NdisReleaseSpinLock(&_A->Lock); \
  274. }
  275. //
  276. // We define the external interfaces to the async driver.
  277. // These routines are only external to permit separate
  278. // compilation. Given a truely fast compiler they could
  279. // all reside in a single file and be static.
  280. //
  281. NTSTATUS
  282. AsyncSendPacket(
  283. IN PASYNC_INFO AsyncInfo,
  284. IN PNDIS_WAN_PACKET WanPacket);
  285. VOID
  286. AsyncIndicateFragment(
  287. IN PASYNC_INFO pInfo,
  288. IN ULONG Error);
  289. NTSTATUS
  290. AsyncStartReads(
  291. PASYNC_INFO pInfo);
  292. NTSTATUS
  293. AsyncSetupIrp(
  294. IN PASYNC_FRAME Frame,
  295. IN PIRP irp);
  296. VOID
  297. SetSerialStuff(
  298. PIRP irp,
  299. PASYNC_INFO pInfo,
  300. ULONG linkSpeed);
  301. VOID
  302. CancelSerialRequests(
  303. PASYNC_INFO pInfo);
  304. VOID
  305. SetSerialTimeouts(
  306. PASYNC_INFO pInfo,
  307. ULONG linkSpeed);
  308. VOID
  309. SerialSetEscapeChar(
  310. PASYNC_INFO pInfo,
  311. UCHAR EscapeChar);
  312. VOID
  313. SerialSetWaitMask(
  314. PASYNC_INFO pInfo,
  315. ULONG WaitMask);
  316. VOID
  317. SerialSetEventChar(
  318. PASYNC_INFO pInfo,
  319. UCHAR EventChar);
  320. VOID
  321. InitSerialIrp(
  322. PIRP irp,
  323. PASYNC_INFO pInfo,
  324. ULONG IoControlCode,
  325. ULONG InputBufferLength);
  326. NTSTATUS
  327. AsyncAllocateFrames(
  328. IN PASYNC_ADAPTER Adapter,
  329. IN UINT NumOfFrames);
  330. VOID
  331. AsyncSendLineUp(
  332. PASYNC_INFO pInfo);
  333. //
  334. // mp.c
  335. //
  336. VOID
  337. MpHalt(
  338. IN NDIS_HANDLE MiniportAdapterContext
  339. );
  340. NDIS_STATUS
  341. MpInit(
  342. OUT PNDIS_STATUS OpenErrorStatus,
  343. OUT PUINT SelectedMediumIndex,
  344. IN PNDIS_MEDIUM MediumArray,
  345. IN UINT MediumArraySize,
  346. IN NDIS_HANDLE MiniportAdapterContext,
  347. IN NDIS_HANDLE WrapperConfigurationContext
  348. );
  349. NDIS_STATUS
  350. MpQueryInfo(
  351. IN NDIS_HANDLE MiniportAdapterContext,
  352. IN NDIS_OID Oid,
  353. IN PVOID InformationBuffer,
  354. IN ULONG InformationBufferLength,
  355. OUT PULONG BytesWritten,
  356. OUT PULONG BytesNeeded
  357. );
  358. NDIS_STATUS
  359. MpReconfigure(
  360. OUT PNDIS_STATUS OpenErrorStatus,
  361. IN NDIS_HANDLE MiniportAdapterContext,
  362. IN NDIS_HANDLE WrapperConfigurationContext
  363. );
  364. NDIS_STATUS
  365. MpReset(
  366. OUT PBOOLEAN AddressingReset,
  367. IN NDIS_HANDLE MiniportAdapterContext
  368. );
  369. NDIS_STATUS
  370. MpSend(
  371. IN NDIS_HANDLE MiniportAdapterContext,
  372. IN NDIS_HANDLE NdisLinkHandle,
  373. IN PNDIS_WAN_PACKET Packet
  374. );
  375. NDIS_STATUS
  376. MpSetInfo(
  377. IN NDIS_HANDLE MiniportAdapterContext,
  378. IN NDIS_OID Oid,
  379. IN PVOID InformationBuffer,
  380. IN ULONG InformationBufferLength,
  381. OUT PULONG BytesRead,
  382. OUT PULONG BytesNeeded
  383. );
  384. //
  385. // crc.c
  386. //
  387. USHORT
  388. CalcCRC(
  389. PUCHAR Frame,
  390. UINT FrameSize);
  391. //
  392. // pppcrc.c
  393. //
  394. USHORT
  395. CalcCRCPPP(
  396. PUCHAR cp,
  397. UINT len);
  398. //
  399. // init.c
  400. //
  401. VOID
  402. AsyncSetupExternalNaming(
  403. PDRIVER_OBJECT DriverObject
  404. );
  405. VOID
  406. AsyncCleanupExternalNaming(VOID);
  407. //
  408. // io.c
  409. //
  410. PASYNC_IO_CTX
  411. AsyncAllocateIoCtx(
  412. BOOLEAN AllocateSync,
  413. PVOID Context
  414. );
  415. VOID
  416. AsyncFreeIoCtx(
  417. PASYNC_IO_CTX AsyncIoCtx
  418. );
  419. //
  420. // chkcomm.c
  421. //
  422. VOID
  423. AsyncCheckCommStatus(
  424. IN PASYNC_INFO pInfo);
  425. //
  426. // send.c
  427. //
  428. NDIS_STATUS
  429. AsyncTryToSendPacket(
  430. IN NDIS_HANDLE MacBindingHandle,
  431. IN PASYNC_INFO AsyncInfo,
  432. IN PASYNC_ADAPTER Adapter);
  433. //
  434. // pppread.c
  435. //
  436. NTSTATUS
  437. AsyncPPPWaitMask(
  438. IN PASYNC_INFO Info);
  439. NTSTATUS
  440. AsyncPPPRead(
  441. IN PASYNC_INFO Info);
  442. //
  443. // irps.c
  444. //
  445. VOID
  446. AsyncCancelQueued(
  447. PDEVICE_OBJECT DeviceObject,
  448. PIRP Irp);
  449. VOID
  450. AsyncCancelAllQueued(
  451. PLIST_ENTRY QueueToCancel);
  452. VOID
  453. AsyncQueueIrp(
  454. PLIST_ENTRY Queue,
  455. PIRP Irp);
  456. BOOLEAN
  457. TryToCompleteDDCDIrp(
  458. PASYNC_INFO pInfo);
  459. //
  460. // pppframe.c
  461. //
  462. VOID
  463. AssemblePPPFrame(
  464. PNDIS_WAN_PACKET Packet);
  465. //
  466. // slipframe.c
  467. //
  468. VOID
  469. AssembleSLIPFrame(
  470. PNDIS_WAN_PACKET Packet);
  471. VOID
  472. AssembleRASFrame(
  473. PNDIS_WAN_PACKET Packet);
  474. //
  475. // serial.c
  476. //
  477. NTSTATUS
  478. SerialIoSyncCompletionRoutine(
  479. IN PDEVICE_OBJECT DeviceObject,
  480. IN PIRP Irp,
  481. IN PVOID Context);
  482. NTSTATUS
  483. SerialIoAsyncCompletionRoutine(
  484. IN PDEVICE_OBJECT DeviceObject,
  485. IN PIRP Irp,
  486. IN PVOID Context);
  487. //
  488. // asyncmac.c
  489. //
  490. NTSTATUS
  491. AsyncDriverDispatch(
  492. IN PDEVICE_OBJECT DeviceObject,
  493. IN PIRP Irp);
  494. NTSTATUS
  495. AsyncDriverCreate(
  496. IN PDEVICE_OBJECT pDeviceObject,
  497. IN PIRP pIrp
  498. );
  499. NTSTATUS
  500. AsyncDriverCleanup(
  501. IN PDEVICE_OBJECT pDeviceObject,
  502. IN PIRP pIrp
  503. );
  504. #endif // _ASYNCSFT_