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.

1017 lines
31 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation Copyright
  3. (c) 1991 Nokia Data Systems AB
  4. Module Name:
  5. dlcrcv.c
  6. Abstract:
  7. This module implements the DLC receive and read commands
  8. Contents:
  9. DlcReceiveRequest
  10. ReceiveCompletion
  11. DlcReadRequest
  12. ReadCompletion
  13. CompleteCompletionPacket
  14. CreateBufferChain
  15. DlcReceiveCancel
  16. Author:
  17. Antti Saarenheimo 22-Jul-1991
  18. Environment:
  19. Kernel mode
  20. Revision History:
  21. --*/
  22. #ifndef i386
  23. #define LLC_PRIVATE_PROTOTYPES
  24. #endif
  25. #include <dlc.h>
  26. #include "dlcdebug.h"
  27. #include "llc.h" // SwapMemCpy
  28. //
  29. // Option indicator defines how we will use the command and event queues:
  30. // 0 => only this station id
  31. // 1 => all events for the sap number in station id
  32. // 2 => all events to any station id
  33. // This table maps the option indicators to station id masks:
  34. //
  35. static USHORT StationIdMasks[3] = {
  36. (USHORT)(-1),
  37. 0xff00,
  38. 0
  39. };
  40. //
  41. // receive station id of a direct station defines
  42. // the received frame types. This table swaps around
  43. // the bits used by IBM.
  44. //
  45. static UCHAR DirectReceiveTypes[LLC_DIR_RCV_ALL_ETHERNET_TYPES + 1] = {
  46. DLC_RCV_MAC_FRAMES | DLC_RCV_8022_FRAMES,
  47. DLC_RCV_MAC_FRAMES,
  48. DLC_RCV_8022_FRAMES,
  49. 0, // DLC_RCV_SPECIFIC_DIX,
  50. DLC_RCV_MAC_FRAMES | DLC_RCV_8022_FRAMES | DLC_RCV_DIX_FRAMES,
  51. DLC_RCV_DIX_FRAMES
  52. };
  53. NTSTATUS
  54. DlcReceiveRequest(
  55. IN PIRP pIrp,
  56. IN PDLC_FILE_CONTEXT pFileContext,
  57. IN PNT_DLC_PARMS pDlcParms,
  58. IN ULONG ParameterLength,
  59. IN ULONG OutputBufferLength
  60. )
  61. /*++
  62. Routine Description:
  63. DLC RECEIVE implements two different commands:
  64. 1. It may receive a frame asynchronously when receive flag is zero
  65. 2. It may enable data permanent receiving. The received frames
  66. are save to event queue from which they read with READ command.
  67. The case 1 is not very much used, because there can be only
  68. one simultaneusly receive command on a dlc station and the frames
  69. are lost very easily before the next command can be be issued.
  70. Arguments:
  71. pIrp - current io request packet
  72. pFileContext - DLC process specific adapter context
  73. pDlcParms - the current parameter block
  74. ParameterLength - not used
  75. OutputBufferLength - not used
  76. Return Value:
  77. NTSTATUS:
  78. DLC_STATUS_DUPLICATE_COMMAND
  79. STATUS_PENDING
  80. --*/
  81. {
  82. NTSTATUS Status;
  83. PDLC_OBJECT pRcvObject;
  84. ULONG Event;
  85. USHORT OpenOptions;
  86. UNREFERENCED_PARAMETER(OutputBufferLength);
  87. UNREFERENCED_PARAMETER(ParameterLength);
  88. ASSUME_IRQL(DISPATCH_LEVEL);
  89. DIAG_FUNCTION("DlcReceiveRequest");
  90. Status = GetStation(pFileContext,
  91. pDlcParms->Async.Parms.Receive.usStationId,
  92. &pRcvObject
  93. );
  94. if (Status != STATUS_SUCCESS) {
  95. return Status;
  96. }
  97. if (pFileContext->hBufferPool == NULL) {
  98. return DLC_STATUS_INADEQUATE_BUFFERS;
  99. }
  100. //
  101. // There can be only one simultaneous receive command
  102. //
  103. if (pRcvObject->pRcvParms != NULL) {
  104. return DLC_STATUS_DUPLICATE_COMMAND;
  105. }
  106. if (pDlcParms->Async.Parms.Receive.usUserLength > MAX_USER_DATA_LENGTH) {
  107. return DLC_STATUS_USER_LENGTH_TOO_LARGE;
  108. }
  109. if (pDlcParms->Async.Parms.Receive.ulReceiveFlag != 0) {
  110. if (pDlcParms->Async.Parms.Receive.uchRcvReadOption >= INVALID_RCV_READ_OPTION) {
  111. return DLC_STATUS_INVALID_OPTION;
  112. }
  113. //
  114. // Everything is ready for the receive, we will now use buffer pool
  115. // to receive frames sent to this object, but applications must
  116. // make READ command to get the data from the buffer pool.
  117. //
  118. Event = LLC_RECEIVE_COMMAND_FLAG;
  119. } else {
  120. //
  121. // Receive read option flag is set also for the normal receive
  122. // to make its handling the same as the data receiving with READ
  123. //
  124. Event = LLC_RECEIVE_DATA; // we do only a normal receive
  125. }
  126. //
  127. // The receive command for a direct station defines the
  128. // type of the receive frames => we must set the
  129. // receive flags every time the receive command is issued
  130. // and remove them, when it is completed or canceled.
  131. //
  132. if (pRcvObject->Type == DLC_DIRECT_OBJECT) {
  133. if (pDlcParms->Async.Parms.Receive.usStationId > LLC_DIR_RCV_ALL_ETHERNET_TYPES) {
  134. return DLC_STATUS_INVALID_STATION_ID;
  135. }
  136. //
  137. // The two lowest bits the receive mask are inverted =>
  138. // They must be changed, when the llc driver is called.
  139. // ---
  140. // The MAC frames must have been enabled by the open options
  141. // of the direct station.
  142. //
  143. OpenOptions = (USHORT)(DirectReceiveTypes[pDlcParms->Async.Parms.Receive.usStationId]
  144. & pRcvObject->u.Direct.OpenOptions);
  145. //
  146. // We create an appropriate LLC object only when the direct station
  147. // has an active receive. The LLC object is deleted when the receive
  148. // terminates. This feature is implemented to support two different
  149. // kinds of LLC objects: (i) DLC Direct stations receiving MAC and
  150. // IEEE 802.2 frames and (ii) DIX ethernet type stations receiving
  151. // all frames having the selected ethernet type
  152. //
  153. if (OpenOptions & LLC_VALID_RCV_MASK) {
  154. LlcSetDirectOpenOptions(pRcvObject->hLlcObject, OpenOptions);
  155. }
  156. }
  157. pRcvObject->pRcvParms = pDlcParms;
  158. //
  159. // this IRP is cancellable
  160. //
  161. // RELEASE_DRIVER_LOCK();
  162. SetIrpCancelRoutine(pIrp, TRUE);
  163. // ACQUIRE_DRIVER_LOCK();
  164. //
  165. // We must queue both receive command types, the other can receive
  166. // data normally, but the second is in the queue only be cancelled
  167. // with its CCB address.
  168. //
  169. Status = QueueDlcCommand(pFileContext,
  170. Event,
  171. pRcvObject->StationId,
  172. (USHORT)(-1), // only this station id
  173. pIrp, // IRP
  174. pDlcParms->Async.Ccb.pCcbAddress,
  175. ReceiveCompletion // completion handler
  176. );
  177. //
  178. // Reset receive parameter link if this receive
  179. // command was not pending for some reason (eg. an error)
  180. //
  181. if (Status != STATUS_PENDING) {
  182. pRcvObject->pRcvParms = NULL;
  183. } else if (pRcvObject->Type != DLC_DIRECT_OBJECT) {
  184. //
  185. // The link station may be in a local busy state, if they
  186. // do not have a pending receive. That's why we must
  187. // clear the local busy states for a single link station
  188. // or all link stations of a sap station, if the receive
  189. // is made for the whole sap. This will clear simultaneously
  190. // also the "out of receive buffers" states, but
  191. // it does nto matter, because they can be set again.
  192. // This command does not change the local busy state, if
  193. // it has been set by user.
  194. //
  195. ReferenceLlcObject(pRcvObject);
  196. LEAVE_DLC(pFileContext);
  197. LlcFlowControl(pRcvObject->hLlcObject, LLC_RESET_LOCAL_BUSY_BUFFER);
  198. ENTER_DLC(pFileContext);
  199. DereferenceLlcObject(pRcvObject);
  200. }
  201. return Status;
  202. }
  203. BOOLEAN
  204. ReceiveCompletion(
  205. IN PDLC_FILE_CONTEXT pFileContext,
  206. IN PDLC_OBJECT pDlcObject,
  207. IN PIRP pIrp,
  208. IN ULONG Event,
  209. IN PVOID pEventInformation,
  210. IN ULONG SecondaryInfo
  211. )
  212. /*++
  213. Routine Description:
  214. The function handles the data receive event and completes
  215. the pending receive command.
  216. Arguments:
  217. pFileContext
  218. pDlcObject - the DLC object (sap, link or direct station) of the
  219. current event (or/and the read command)
  220. pIrp - interrupt request packet of this READ command
  221. Event - event code
  222. pEventInformation - event specific information
  223. SecondaryInfo - used as a miscellaneous secondary parameter
  224. at least the ReadFlag of the received frame, as a
  225. command completion flag in transmit completion
  226. Return Value:
  227. BOOLEAN
  228. --*/
  229. {
  230. PNT_DLC_PARMS pDlcParms;
  231. USHORT ReceivedFrameCount;
  232. UNREFERENCED_PARAMETER(Event);
  233. UNREFERENCED_PARAMETER(SecondaryInfo);
  234. DIAG_FUNCTION("ReceiveCompletion");
  235. pDlcParms = (PNT_DLC_PARMS)pIrp->AssociatedIrp.SystemBuffer;
  236. CreateBufferChain((PDLC_BUFFER_HEADER)pEventInformation,
  237. (PVOID *)&pDlcParms->Async.Parms.Receive.pFirstBuffer,
  238. &ReceivedFrameCount // this should be always 1
  239. );
  240. //
  241. // IBM DLC API defines, that there can be only one receive command
  242. // pending for an object. The receive parameter table pointer
  243. // disables the further receive commands while one is pending.
  244. //
  245. pDlcObject->pRcvParms = NULL;
  246. //
  247. // Queue a command completion event, if the command completion
  248. // flag has been defined in the CCB
  249. //
  250. if (pDlcParms->Async.Ccb.CommandCompletionFlag != 0) {
  251. MakeDlcEvent(pFileContext,
  252. DLC_COMMAND_COMPLETION,
  253. pDlcObject->StationId,
  254. NULL,
  255. pDlcParms->Async.Ccb.pCcbAddress,
  256. pDlcParms->Async.Ccb.CommandCompletionFlag,
  257. FALSE
  258. );
  259. }
  260. //
  261. // If this is RECEIVE2 (CCB and its parameter block catenated
  262. // together), then we copy back the whole buffer).
  263. // => change the size of the parameter block copied back to user.
  264. // The default output buffer size is defined for the receive commands
  265. // with a read flag.
  266. //
  267. if (IoGetCurrentIrpStackLocation(pIrp)->Parameters.DeviceIoControl.IoControlCode == IOCTL_DLC_RECEIVE2) {
  268. pIrp->IoStatus.Information = sizeof(LLC_RECEIVE_PARMS) + sizeof(NT_DLC_CCB);
  269. } else {
  270. //
  271. // MODMOD RLF 01/23/93
  272. //
  273. // Performance (slight). The following is a single-dword write
  274. //
  275. //LlcMemCpy(MmGetSystemAddressForMdl((PMDL)pDlcParms->Async.Ccb.u.pMdl),
  276. // &pDlcParms->Async.Parms.Receive.pFirstBuffer,
  277. // aSpecialOutputBuffers[IOCTL_DLC_RECEIVE_INDEX]
  278. // );
  279. PVOID* pChain;
  280. pChain = (PVOID*)MmGetSystemAddressForMdl((PMDL)pDlcParms->Async.Ccb.u.pMdl);
  281. *pChain = pDlcParms->Async.Parms.Receive.pFirstBuffer;
  282. //
  283. // MODMOD ends
  284. //
  285. UnlockAndFreeMdl(pDlcParms->Async.Ccb.u.pMdl);
  286. //
  287. // RLF 02/23/94
  288. //
  289. // zap the pMdl field to avoid trying to unlock and free the MDL again
  290. //
  291. pDlcParms->Async.Ccb.u.pMdl = NULL;
  292. }
  293. CompleteAsyncCommand(pFileContext, STATUS_SUCCESS, pIrp, NULL, FALSE);
  294. return TRUE;
  295. }
  296. NTSTATUS
  297. DlcReadRequest(
  298. IN PIRP pIrp,
  299. IN PDLC_FILE_CONTEXT pFileContext,
  300. IN PNT_DLC_PARMS pDlcParms,
  301. IN ULONG ParameterLength,
  302. IN ULONG OutputBufferLength
  303. )
  304. /*++
  305. Routine Description:
  306. The READ command emulates all posting features provided in DOS DLC API.
  307. The command can be used:
  308. 1. To receive data
  309. 2. To read DLC status indications (connect and disconnect indications)
  310. 3. To complele other asynchronous commands (transmit, receive,
  311. close, reset, connect)
  312. 4. To handle exceptions on NDIS (or on DLC) driver
  313. See IBM documentation for more information about DLC READ.
  314. Arguments:
  315. pIrp - current io request packet
  316. pFileContext - DLC process specific adapter context
  317. pDlcParms - the current parameter block
  318. ParameterLength - the length of input parameters
  319. Return Value:
  320. DLC_STATUS:
  321. --*/
  322. {
  323. NTSTATUS Status;
  324. PDLC_OBJECT pReadObject;
  325. PVOID AbortHandle;
  326. UNREFERENCED_PARAMETER(OutputBufferLength);
  327. UNREFERENCED_PARAMETER(ParameterLength);
  328. ASSUME_IRQL(DISPATCH_LEVEL);
  329. DIAG_FUNCTION("DlcReadRequest");
  330. //
  331. // Receive request alread checks, that buffer pool has been defined,
  332. // and we may complete commands or read dlc events before
  333. // the buffer pool has been created.
  334. //
  335. // if (pFileContext->hBufferPool == NULL)
  336. // {
  337. // return DLC_STATUS_INADEQUATE_BUFFERS;
  338. // }
  339. //
  340. // RLF 04/09/93
  341. //
  342. // It should not be possible to have the same READ CCB queued more than once.
  343. // It could get the app into all sorts of difficulty
  344. //
  345. if (IsCommandOnList((PVOID)pDlcParms->Async.Ccb.pCcbAddress, &pFileContext->CommandQueue)) {
  346. #if DBG
  347. DbgPrint("DLC.DlcReadRequest: Error: CCB %08X already on list\n",
  348. pDlcParms->Async.Ccb.pCcbAddress
  349. );
  350. DbgBreakPoint();
  351. #endif
  352. return DLC_STATUS_DUPLICATE_COMMAND;
  353. }
  354. //
  355. // Check the input parameters of DLC READ
  356. //
  357. if (pDlcParms->Async.Parms.ReadInput.OptionIndicator >= DLC_INVALID_OPTION_INDICATOR) {
  358. return DLC_STATUS_INVALID_OPTION;
  359. }
  360. //
  361. // If the read is destined for a specific station then we check that the
  362. // station really exists
  363. //
  364. if ((UCHAR)pDlcParms->Async.Parms.ReadInput.OptionIndicator < LLC_OPTION_READ_ALL) {
  365. Status = GetStation(pFileContext,
  366. (USHORT)(pDlcParms->Async.Parms.ReadInput.StationId
  367. & StationIdMasks[pDlcParms->Async.Parms.ReadInput.OptionIndicator]),
  368. &pReadObject
  369. );
  370. if (Status != STATUS_SUCCESS) {
  371. return Status;
  372. }
  373. }
  374. //
  375. // Read commands can be linked to another command by CCB pointer,
  376. // command completion flag and read flag are a special case. They
  377. // can be used only for the completion of a the given command.
  378. // We use the commands CCB address as a search handle and
  379. // save it as an abort handle instead of the read command's
  380. // own CCB address.
  381. //
  382. if (pDlcParms->Async.Parms.ReadInput.CommandCompletionCcbLink != NULL) {
  383. AbortHandle = pDlcParms->Async.Parms.ReadInput.CommandCompletionCcbLink;
  384. pDlcParms->Async.Parms.ReadInput.EventSet = LLC_RECEIVE_COMMAND_FLAG;
  385. } else {
  386. AbortHandle = pDlcParms->Async.Ccb.pCcbAddress;
  387. pDlcParms->Async.Parms.ReadInput.EventSet &= LLC_READ_ALL_EVENTS;
  388. if (pDlcParms->Async.Parms.ReadInput.EventSet == 0) {
  389. return DLC_STATUS_PARAMETER_MISSING;
  390. }
  391. }
  392. //
  393. // this IRP is cancellable
  394. //
  395. // RELEASE_DRIVER_LOCK();
  396. SetIrpCancelRoutine(pIrp, TRUE);
  397. // ACQUIRE_DRIVER_LOCK();
  398. return QueueDlcCommand(pFileContext,
  399. (ULONG)pDlcParms->Async.Parms.ReadInput.EventSet,
  400. pDlcParms->Async.Parms.ReadInput.StationId,
  401. StationIdMasks[pDlcParms->Async.Parms.ReadInput.OptionIndicator],
  402. pIrp,
  403. AbortHandle,
  404. ReadCompletion
  405. );
  406. }
  407. BOOLEAN
  408. ReadCompletion(
  409. IN PDLC_FILE_CONTEXT pFileContext,
  410. IN PDLC_OBJECT pDlcObject,
  411. IN PIRP pIrp,
  412. IN ULONG Event,
  413. IN PVOID pEventInformation,
  414. IN ULONG SecondaryInfo
  415. )
  416. /*++
  417. Routine Description:
  418. The command reads a DLC event and saves its information to
  419. the returned parameter block of the read command.
  420. Arguments:
  421. pFileContext - process specific open context
  422. pDlcObject - the DLC object (sap, link or direct station) of the
  423. current event (or/and the read command)
  424. pIrp - interrupt request packet of this READ command
  425. Event - event code
  426. pEventInformation - event specific information
  427. SecondaryInfo - a miscallaneous secondary parameter, eg. the ReadFlag
  428. of the received frame or the command completion flag
  429. in transmit completion.
  430. Return Value:
  431. BOOLEAN
  432. TRUE - The packet containing the event information can be returned
  433. to its pool
  434. FALSE - Do not deallocate the event packet
  435. --*/
  436. {
  437. BOOLEAN boolDeallocatePacket;
  438. PNT_DLC_PARMS pParms;
  439. ASSUME_IRQL(DISPATCH_LEVEL);
  440. DIAG_FUNCTION("ReadCompletion");
  441. pParms = (PNT_DLC_PARMS)pIrp->AssociatedIrp.SystemBuffer;
  442. boolDeallocatePacket = TRUE;
  443. //
  444. // Reset always all unrefernced variables
  445. // (otherwise they may be garbage)
  446. //
  447. LlcZeroMem((PVOID)&pParms->Async.Parms.Read.Event, sizeof(NT_DLC_READ_PARMS) - 4);
  448. pParms->Async.Parms.Read.Event = (UCHAR)Event;
  449. switch (Event) {
  450. case LLC_RECEIVE_DATA:
  451. //
  452. // The caller checks always if the DLC object is ready to receive data
  453. // with read and to selects the correct receive buffer pool
  454. //
  455. pParms->Async.Parms.Read.NotificationFlag = SecondaryInfo;
  456. //
  457. // The read always resets the receive event
  458. //
  459. if (pDlcObject != NULL) {
  460. pDlcObject->pReceiveEvent = NULL;
  461. }
  462. CreateBufferChain(pEventInformation,
  463. (PVOID*)&pParms->Async.Parms.Read.u.Event.pReceivedFrame,
  464. &pParms->Async.Parms.Read.u.Event.ReceivedFrameCount
  465. );
  466. break;
  467. case LLC_TRANSMIT_COMPLETION:
  468. if (SecondaryInfo == 0) {
  469. //
  470. // We have created a special completion packet for those chained
  471. // transmit command completions, whose DLC object have been deleted
  472. //
  473. CompleteCompletionPacket(pFileContext,
  474. (PDLC_COMPLETION_EVENT_INFO)pEventInformation,
  475. pParms
  476. );
  477. } else {
  478. //
  479. // Transmit commands do not use any command completion packets,
  480. // because the LLC module takes care of the command queueing
  481. // and completion routine. The previous transmit command
  482. // completion has left its CCB pointer to current object.
  483. // The sequential non null transmit CCBs create a CCB link
  484. // list, that is terminated in every READ call.
  485. //
  486. // Unlink the command completion event having the xmit
  487. // commands chained (the next xmit command with the
  488. // chaining option will setup the link again).
  489. //
  490. if (pDlcObject != NULL) {
  491. pEventInformation = pDlcObject->pPrevXmitCcbAddress;
  492. pDlcObject->pPrevXmitCcbAddress = NULL;
  493. pParms->Async.Parms.Read.u.Event.CcbCount = pDlcObject->ChainedTransmitCount;
  494. pDlcObject->ChainedTransmitCount = 0;
  495. } else {
  496. //
  497. // This is only an lonely unchained xmit completion
  498. // event. The CCB counter must be always one.
  499. //
  500. pParms->Async.Parms.Read.u.Event.CcbCount = 1;
  501. }
  502. pParms->Async.Parms.Read.NotificationFlag = SecondaryInfo;
  503. pParms->Async.Parms.Read.u.Event.pCcbCompletionList = pEventInformation;
  504. }
  505. break;
  506. case DLC_COMMAND_COMPLETION:
  507. //
  508. // Close command completions needs a special command completion
  509. // packet, the other command completions consists only of
  510. // the ccb address and command completion flag (secondary data).
  511. // The close command completions have reset the secondary data
  512. //
  513. if (SecondaryInfo != 0) {
  514. //
  515. // This is the command completion of a normal DLC command.
  516. //
  517. pParms->Async.Parms.Read.u.Event.CcbCount = 1;
  518. pParms->Async.Parms.Read.NotificationFlag = SecondaryInfo;
  519. pParms->Async.Parms.Read.u.Event.pCcbCompletionList = pEventInformation;
  520. } else {
  521. CompleteCompletionPacket(pFileContext,
  522. (PDLC_COMPLETION_EVENT_INFO)pEventInformation,
  523. pParms
  524. );
  525. }
  526. break;
  527. case LLC_CRITICAL_EXCEPTION:
  528. // THIS DEPENDS ON NDIS 3.0
  529. // Talk with Johnson about this case:
  530. // Dos NDIS first return RING_STATUS and then CLOSING status
  531. // LLC should put them together to CRITICAL_EXCEPTION.
  532. //
  533. // This event is not handled (?)
  534. //
  535. break;
  536. case LLC_NETWORK_STATUS:
  537. //
  538. // The network status change is not a fatal event.
  539. //
  540. pParms->Async.Parms.Read.NotificationFlag = pFileContext->NetworkStatusFlag;
  541. pParms->Async.Parms.Read.u.Event.EventErrorCode = (USHORT)SecondaryInfo;
  542. break;
  543. case LLC_STATUS_CHANGE:
  544. //
  545. // This is a DLC status change, WE MAY COPY SOME GRABAGE
  546. // IF THE LINK STATION HAS BEEN DELETED MEANWHILE, But
  547. // it does not matter, because the non-paged memory
  548. // alaways exists, and the status table can only be
  549. // owned by another link station (because the
  550. // link stations are allocated from a packet pool)
  551. //
  552. LlcMemCpy(&pParms->Async.Parms.Read.u.Status.DlcStatusCode,
  553. pEventInformation,
  554. sizeof(DLC_STATUS_TABLE) - sizeof(PVOID)
  555. );
  556. //
  557. // RLF 02/23/93 If this is a CONNECT_REQUEST and the medium is Ethernet
  558. // or FDDI then swap the bits in the reported net address
  559. //
  560. if ((pParms->Async.Parms.Read.u.Status.DlcStatusCode == LLC_INDICATE_CONNECT_REQUEST)
  561. && ((pFileContext->ActualNdisMedium == NdisMedium802_3)
  562. || (pFileContext->ActualNdisMedium == NdisMediumFddi))) {
  563. //
  564. // swap bytes in situ
  565. //
  566. SwapMemCpy(TRUE,
  567. &pParms->Async.Parms.Read.u.Status.RemoteNodeAddress[0],
  568. &pParms->Async.Parms.Read.u.Status.RemoteNodeAddress[0],
  569. 6
  570. );
  571. }
  572. pParms->Async.Parms.Read.u.Status.StationId = pDlcObject->StationId;
  573. pParms->Async.Parms.Read.u.Status.UserStatusValue = pDlcObject->u.Link.pSap->u.Sap.UserStatusValue;
  574. pParms->Async.Parms.Read.NotificationFlag = pDlcObject->u.Link.pSap->u.Sap.DlcStatusFlag;
  575. pParms->Async.Parms.Read.u.Status.DlcStatusCode = (USHORT)SecondaryInfo;
  576. //
  577. // Each link stations has a DLC status event packet.
  578. // Those packets must not be deallocated back to the
  579. // packet pool as the other event packets.
  580. //
  581. pDlcObject->u.Link.pStatusEvent->LlcPacket.pNext = NULL;
  582. pDlcObject->u.Link.pStatusEvent->SecondaryInfo = 0;
  583. boolDeallocatePacket = FALSE;
  584. break;
  585. //
  586. // System actions are based on the fact, that all apps share the
  587. // DLC same dlc and physical network adapter.
  588. // NT NDIS and DLC architectures provide full DLC for each
  589. // application separately => The system action indications are
  590. // not needed in NT DLC.
  591. //
  592. // case LLC_SYSTEM_ACTION:
  593. // break;
  594. #if LLC_DBG
  595. default:
  596. LlcInvalidObjectType();
  597. break;
  598. #endif
  599. };
  600. //
  601. // Copy the optional second output buffer to user memory.
  602. //
  603. if (IoGetCurrentIrpStackLocation(pIrp)->Parameters.DeviceIoControl.IoControlCode == IOCTL_DLC_READ) {
  604. LlcMemCpy(MmGetSystemAddressForMdl((PMDL)pParms->Async.Ccb.u.pMdl),
  605. &pParms->Async.Parms.Read.Event,
  606. aSpecialOutputBuffers[IOCTL_DLC_READ_INDEX] -
  607. ( (PCHAR)&pParms->Async.Parms.Read.Event -
  608. (PCHAR)&pParms->Async.Parms.Read )
  609. );
  610. UnlockAndFreeMdl(pParms->Async.Ccb.u.pMdl);
  611. }
  612. pParms->Async.Ccb.uchDlcStatus = (UCHAR)STATUS_SUCCESS;
  613. pParms->Async.Ccb.pCcbAddress = NULL;
  614. //
  615. // we are about to complete this IRP - remove the cancel routine
  616. //
  617. // RELEASE_DRIVER_LOCK();
  618. SetIrpCancelRoutine(pIrp, FALSE);
  619. IoCompleteRequest(pIrp, (CCHAR)IO_NETWORK_INCREMENT);
  620. // ACQUIRE_DRIVER_LOCK();
  621. DereferenceFileContext(pFileContext);
  622. return boolDeallocatePacket;
  623. }
  624. VOID
  625. CompleteCompletionPacket(
  626. IN PDLC_FILE_CONTEXT pFileContext,
  627. IN PDLC_COMPLETION_EVENT_INFO pCompletionInfo,
  628. IN OUT PNT_DLC_PARMS pParms
  629. )
  630. /*++
  631. Routine Description:
  632. Procedure reads the completion information from
  633. the command completion packet and saves it to the
  634. read parameter table.
  635. Arguments:
  636. pFileContext - process specific open context
  637. pCompletionInfo - dlc completion packet
  638. pParms - pointer to DLC parameter table
  639. Return Value:
  640. None
  641. --*/
  642. {
  643. pParms->Async.Parms.Read.u.Event.CcbCount = pCompletionInfo->CcbCount;
  644. pParms->Async.Parms.Read.NotificationFlag = pCompletionInfo->CommandCompletionFlag;
  645. pParms->Async.Parms.Read.u.Event.pCcbCompletionList = pCompletionInfo->pCcbAddress;
  646. CreateBufferChain(pCompletionInfo->pReceiveBuffers,
  647. (PVOID*)&pParms->Async.Parms.Read.u.Event.pReceivedFrame,
  648. &pParms->Async.Parms.Read.u.Event.ReceivedFrameCount
  649. );
  650. DEALLOCATE_PACKET_DLC_PKT(pFileContext->hPacketPool, pCompletionInfo);
  651. }
  652. VOID
  653. CreateBufferChain(
  654. IN PDLC_BUFFER_HEADER pBufferHeaders,
  655. OUT PVOID *pFirstBuffer,
  656. OUT PUSHORT pReceivedFrameCount
  657. )
  658. /*++
  659. Routine Description:
  660. The procudedure links the received frames in user's address space
  661. to the same order as they were received.
  662. We will take all frames linked to the queue.
  663. We must count the received frames to get
  664. the exact number of them. We cound count the frames
  665. also in the fly, but this is probably fastest and
  666. simplest way to do it (usually there is only one frame).
  667. The received frames are always in a circular link list.
  668. and in a reverse order. The newest
  669. frame is pointed by the list header and the oldes one
  670. is the next from it.
  671. Arguments:
  672. pBufferHeaders - circular DLC buffer list, the head point to the
  673. newest frame.
  674. pFirstBuffer - returned user's address space address of the
  675. first received frame
  676. pReceivedFrameCount - returned number of the received frame
  677. Return Value:
  678. None
  679. --*/
  680. {
  681. PDLC_BUFFER_HEADER pBuffer;
  682. if (pBufferHeaders != NULL) {
  683. pBuffer = pBufferHeaders->FrameBuffer.pNextFrame;
  684. pBufferHeaders->FrameBuffer.pNextFrame = NULL;
  685. do {
  686. *pFirstBuffer = (PVOID)((PCHAR)pBuffer->FrameBuffer.pParent->Header.pLocalVa
  687. + MIN_DLC_BUFFER_SEGMENT * pBuffer->FrameBuffer.Index);
  688. pFirstBuffer = (PVOID*)&((PFIRST_DLC_SEGMENT)
  689. ((PUCHAR)pBuffer->FrameBuffer.pParent->Header.pGlobalVa
  690. + MIN_DLC_BUFFER_SEGMENT * pBuffer->FrameBuffer.Index))->Cont.pNextFrame;
  691. (*pReceivedFrameCount)++;
  692. #if LLC_DBG
  693. cFramesIndicated++;
  694. #endif
  695. //
  696. // The new state makes it possible to free the
  697. // buffer immediately (should this be interlocked???)
  698. //
  699. {
  700. PDLC_BUFFER_HEADER pNextBuffer;
  701. pNextBuffer = pBuffer->FrameBuffer.pNextFrame;
  702. pBuffer->FrameBuffer.BufferState = BUF_USER;
  703. pBuffer = pNextBuffer;
  704. }
  705. } while (pBuffer != NULL);
  706. #if LLC_DBG
  707. if (*pFirstBuffer != NULL) {
  708. DbgPrint("Improperly formed frame link list!!!\n");
  709. DbgBreakPoint();
  710. }
  711. #endif
  712. }
  713. }
  714. NTSTATUS
  715. DlcReceiveCancel(
  716. IN PIRP pIrp,
  717. IN PDLC_FILE_CONTEXT pFileContext,
  718. IN PNT_DLC_PARMS pDlcParms,
  719. IN ULONG ParameterLength,
  720. IN ULONG OutputBufferLength
  721. )
  722. /*++
  723. Routine Description:
  724. This primitive cancels a pending receive command. This is different
  725. from the general cancel command used for READ and DirTimerSet,
  726. because we must find the object having the active receive and
  727. disable it.
  728. Arguments:
  729. pIrp - current io request packet
  730. pFileContext - DLC process specific adapter context
  731. pDlcParms - the current parameter block
  732. ParameterLength - the length of input parameters
  733. OutputBufferLength -
  734. Return Value:
  735. DLC_STATUS:
  736. Success - STATUS_SUCCESS
  737. Failure - DLC_INVALID_CCB_PARAMETER1
  738. --*/
  739. {
  740. PDLC_OBJECT pRcvObject;
  741. PDLC_COMMAND pDlcCommand;
  742. PVOID pCcbLink = NULL;
  743. PNT_DLC_PARMS pCanceledParms;
  744. UNREFERENCED_PARAMETER(pIrp);
  745. UNREFERENCED_PARAMETER(OutputBufferLength);
  746. UNREFERENCED_PARAMETER(ParameterLength);
  747. pDlcCommand = SearchAndRemoveAnyCommand(pFileContext,
  748. (ULONG)(LLC_RECEIVE_DATA | LLC_RECEIVE_COMMAND_FLAG),
  749. (USHORT)DLC_IGNORE_STATION_ID,
  750. (USHORT)DLC_STATION_MASK_SPECIFIC,
  751. pDlcParms->ReceiveCancel.pCcb
  752. );
  753. if (pDlcCommand != NULL) {
  754. pCanceledParms = (PNT_DLC_PARMS)pDlcCommand->pIrp->AssociatedIrp.SystemBuffer;
  755. GetStation(pFileContext,
  756. pCanceledParms->Async.Parms.Receive.usStationId,
  757. &pRcvObject
  758. );
  759. //
  760. // I can't see any reason why the station id should be missing
  761. // => we don't check the error code.
  762. //
  763. pRcvObject->pRcvParms = NULL;
  764. //
  765. // We return the canceled CCB pointer
  766. //
  767. CancelDlcCommand(pFileContext,
  768. pDlcCommand,
  769. &pCcbLink,
  770. DLC_STATUS_CANCELLED_BY_USER,
  771. TRUE // SuppressCommandCompletion !!!
  772. );
  773. }
  774. //
  775. // IBM LAN Tech Ref didn't define any possible error code for the
  776. // case, if the receive command could not be found => we
  777. // must return a successful status.
  778. //
  779. return STATUS_SUCCESS;
  780. }