rxpath.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. /*
  2. * TAP-Windows -- A kernel driver to provide virtual tap
  3. * device functionality on Windows.
  4. *
  5. * This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
  6. *
  7. * This source code is Copyright (C) 2002-2014 OpenVPN Technologies, Inc.,
  8. * and is released under the GPL version 2 (see below).
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program (see the file COPYING included with this
  21. * distribution); if not, write to the Free Software Foundation, Inc.,
  22. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. //
  25. // Include files.
  26. //
  27. #include "tap.h"
  28. //======================================================================
  29. // TAP Receive Path Support
  30. //======================================================================
  31. #ifdef ALLOC_PRAGMA
  32. #pragma alloc_text( PAGE, TapDeviceWrite)
  33. #endif // ALLOC_PRAGMA
  34. //===============================================================
  35. // Used in cases where internally generated packets such as
  36. // ARP or DHCP replies must be returned to the kernel, to be
  37. // seen as an incoming packet "arriving" on the interface.
  38. //===============================================================
  39. VOID
  40. IndicateReceivePacket(
  41. __in PTAP_ADAPTER_CONTEXT Adapter,
  42. __in PUCHAR packetData,
  43. __in const unsigned int packetLength
  44. )
  45. {
  46. PUCHAR injectBuffer;
  47. //
  48. // Handle miniport Pause
  49. // ---------------------
  50. // NDIS 6 miniports implement a temporary "Pause" state normally followed
  51. // by the Restart. While in the Pause state it is forbidden for the miniport
  52. // to indicate receive NBLs.
  53. //
  54. // That is: The device interface may be "up", but the NDIS miniport send/receive
  55. // interface may be temporarily "down".
  56. //
  57. // BUGBUG!!! In the initial implementation of the NDIS 6 TapOas inject path
  58. // the code below will simply ignore inject packets passed to the driver while
  59. // the miniport is in the Paused state.
  60. //
  61. // The correct implementation is to go ahead and build the NBLs corresponding
  62. // to the inject packet - but queue them. When Restart is entered the
  63. // queued NBLs would be dequeued and indicated to the host.
  64. //
  65. if(tapAdapterSendAndReceiveReady(Adapter) != NDIS_STATUS_SUCCESS)
  66. {
  67. DEBUGP (("[%s] Lying send in IndicateReceivePacket while adapter paused\n",
  68. MINIPORT_INSTANCE_ID (Adapter)));
  69. return;
  70. }
  71. // Allocate flat buffer for packet data.
  72. injectBuffer = (PUCHAR )NdisAllocateMemoryWithTagPriority(
  73. Adapter->MiniportAdapterHandle,
  74. packetLength,
  75. TAP_RX_INJECT_BUFFER_TAG,
  76. NormalPoolPriority
  77. );
  78. if( injectBuffer)
  79. {
  80. PMDL mdl;
  81. // Copy packet data to flat buffer.
  82. NdisMoveMemory (injectBuffer, packetData, packetLength);
  83. // Allocate MDL for flat buffer.
  84. mdl = NdisAllocateMdl(
  85. Adapter->MiniportAdapterHandle,
  86. injectBuffer,
  87. packetLength
  88. );
  89. if( mdl )
  90. {
  91. PNET_BUFFER_LIST netBufferList;
  92. mdl->Next = NULL; // No next MDL
  93. // Allocate the NBL and NB. Link MDL chain to NB.
  94. netBufferList = NdisAllocateNetBufferAndNetBufferList(
  95. Adapter->ReceiveNblPool,
  96. 0, // ContextSize
  97. 0, // ContextBackFill
  98. mdl, // MDL chain
  99. 0,
  100. packetLength
  101. );
  102. if(netBufferList != NULL)
  103. {
  104. ULONG receiveFlags = 0;
  105. LONG nblCount;
  106. NET_BUFFER_LIST_NEXT_NBL(netBufferList) = NULL; // Only one NBL
  107. if(KeGetCurrentIrql() == DISPATCH_LEVEL)
  108. {
  109. receiveFlags |= NDIS_RECEIVE_FLAGS_DISPATCH_LEVEL;
  110. }
  111. // Set flag indicating that this is an injected packet
  112. TAP_RX_NBL_FLAGS_CLEAR_ALL(netBufferList);
  113. TAP_RX_NBL_FLAG_SET(netBufferList,TAP_RX_NBL_FLAGS_IS_INJECTED);
  114. netBufferList->MiniportReserved[0] = NULL;
  115. netBufferList->MiniportReserved[1] = NULL;
  116. // Increment in-flight receive NBL count.
  117. nblCount = NdisInterlockedIncrement(&Adapter->ReceiveNblInFlightCount);
  118. ASSERT(nblCount > 0 );
  119. netBufferList->SourceHandle = Adapter->MiniportAdapterHandle;
  120. //
  121. // Indicate the packet
  122. // -------------------
  123. // Irp->AssociatedIrp.SystemBuffer with length irpSp->Parameters.Write.Length
  124. // contains the complete packet including Ethernet header and payload.
  125. //
  126. NdisMIndicateReceiveNetBufferLists(
  127. Adapter->MiniportAdapterHandle,
  128. netBufferList,
  129. NDIS_DEFAULT_PORT_NUMBER,
  130. 1, // NumberOfNetBufferLists
  131. receiveFlags
  132. );
  133. return;
  134. }
  135. else
  136. {
  137. DEBUGP (("[%s] NdisAllocateNetBufferAndNetBufferList failed in IndicateReceivePacket\n",
  138. MINIPORT_INSTANCE_ID (Adapter)));
  139. NOTE_ERROR ();
  140. NdisFreeMdl(mdl);
  141. NdisFreeMemory(injectBuffer,0,0);
  142. }
  143. }
  144. else
  145. {
  146. DEBUGP (("[%s] NdisAllocateMdl failed in IndicateReceivePacket\n",
  147. MINIPORT_INSTANCE_ID (Adapter)));
  148. NOTE_ERROR ();
  149. NdisFreeMemory(injectBuffer,0,0);
  150. }
  151. }
  152. else
  153. {
  154. DEBUGP (("[%s] NdisAllocateMemoryWithTagPriority failed in IndicateReceivePacket\n",
  155. MINIPORT_INSTANCE_ID (Adapter)));
  156. NOTE_ERROR ();
  157. }
  158. }
  159. VOID
  160. tapCompleteIrpAndFreeReceiveNetBufferList(
  161. __in PTAP_ADAPTER_CONTEXT Adapter,
  162. __in PNET_BUFFER_LIST NetBufferList, // Only one NB here...
  163. __in NTSTATUS IoCompletionStatus
  164. )
  165. {
  166. PIRP irp;
  167. ULONG frameType, netBufferCount, byteCount;
  168. LONG nblCount;
  169. // Fetch NB frame type.
  170. frameType = tapGetNetBufferFrameType(NET_BUFFER_LIST_FIRST_NB(NetBufferList));
  171. // Fetch statistics for all NBs linked to the NB.
  172. netBufferCount = tapGetNetBufferCountsFromNetBufferList(
  173. NetBufferList,
  174. &byteCount
  175. );
  176. // Update statistics by frame type
  177. if(IoCompletionStatus == STATUS_SUCCESS)
  178. {
  179. switch(frameType)
  180. {
  181. case NDIS_PACKET_TYPE_DIRECTED:
  182. Adapter->FramesRxDirected += netBufferCount;
  183. Adapter->BytesRxDirected += byteCount;
  184. break;
  185. case NDIS_PACKET_TYPE_BROADCAST:
  186. Adapter->FramesRxBroadcast += netBufferCount;
  187. Adapter->BytesRxBroadcast += byteCount;
  188. break;
  189. case NDIS_PACKET_TYPE_MULTICAST:
  190. Adapter->FramesRxMulticast += netBufferCount;
  191. Adapter->BytesRxMulticast += byteCount;
  192. break;
  193. default:
  194. ASSERT(FALSE);
  195. break;
  196. }
  197. }
  198. //
  199. // Handle P2P Packet
  200. // -----------------
  201. // Free MDL allocated for P2P Ethernet header.
  202. //
  203. if(TAP_RX_NBL_FLAG_TEST(NetBufferList,TAP_RX_NBL_FLAGS_IS_P2P))
  204. {
  205. PNET_BUFFER netBuffer;
  206. PMDL mdl;
  207. netBuffer = NET_BUFFER_LIST_FIRST_NB(NetBufferList);
  208. mdl = NET_BUFFER_FIRST_MDL(netBuffer);
  209. mdl->Next = NULL;
  210. NdisFreeMdl(mdl);
  211. }
  212. //
  213. // Handle Injected Packet
  214. // -----------------------
  215. // Free MDL and data buffer allocated for injected packet.
  216. //
  217. if(TAP_RX_NBL_FLAG_TEST(NetBufferList,TAP_RX_NBL_FLAGS_IS_INJECTED))
  218. {
  219. PNET_BUFFER netBuffer;
  220. PMDL mdl;
  221. PUCHAR injectBuffer;
  222. netBuffer = NET_BUFFER_LIST_FIRST_NB(NetBufferList);
  223. mdl = NET_BUFFER_FIRST_MDL(netBuffer);
  224. injectBuffer = (PUCHAR )MmGetSystemAddressForMdlSafe(mdl,NormalPagePriority);
  225. if(injectBuffer)
  226. {
  227. NdisFreeMemory(injectBuffer,0,0);
  228. }
  229. NdisFreeMdl(mdl);
  230. }
  231. //
  232. // Complete the IRP
  233. //
  234. irp = (PIRP )NetBufferList->MiniportReserved[0];
  235. if(irp)
  236. {
  237. irp->IoStatus.Status = IoCompletionStatus;
  238. IoCompleteRequest(irp, IO_NO_INCREMENT);
  239. }
  240. // Decrement in-flight receive NBL count.
  241. nblCount = NdisInterlockedDecrement(&Adapter->ReceiveNblInFlightCount);
  242. ASSERT(nblCount >= 0 );
  243. if (0 == nblCount)
  244. {
  245. NdisSetEvent(&Adapter->ReceiveNblInFlightCountZeroEvent);
  246. }
  247. // Free the NBL
  248. NdisFreeNetBufferList(NetBufferList);
  249. }
  250. VOID
  251. AdapterReturnNetBufferLists(
  252. __in NDIS_HANDLE MiniportAdapterContext,
  253. __in PNET_BUFFER_LIST NetBufferLists,
  254. __in ULONG ReturnFlags
  255. )
  256. {
  257. PTAP_ADAPTER_CONTEXT adapter = (PTAP_ADAPTER_CONTEXT )MiniportAdapterContext;
  258. PNET_BUFFER_LIST currentNbl, nextNbl;
  259. UNREFERENCED_PARAMETER(ReturnFlags);
  260. //
  261. // Process each NBL individually
  262. //
  263. currentNbl = NetBufferLists;
  264. while (currentNbl)
  265. {
  266. PNET_BUFFER_LIST nextNbl;
  267. nextNbl = NET_BUFFER_LIST_NEXT_NBL(currentNbl);
  268. NET_BUFFER_LIST_NEXT_NBL(currentNbl) = NULL;
  269. // Complete write IRP and free NBL and associated resources.
  270. tapCompleteIrpAndFreeReceiveNetBufferList(
  271. adapter,
  272. currentNbl,
  273. STATUS_SUCCESS
  274. );
  275. // Move to next NBL
  276. currentNbl = nextNbl;
  277. }
  278. }
  279. // IRP_MJ_WRITE callback.
  280. NTSTATUS
  281. TapDeviceWrite(
  282. PDEVICE_OBJECT DeviceObject,
  283. PIRP Irp
  284. )
  285. {
  286. NTSTATUS ntStatus = STATUS_SUCCESS;// Assume success
  287. PIO_STACK_LOCATION irpSp;// Pointer to current stack location
  288. PTAP_ADAPTER_CONTEXT adapter = NULL;
  289. ULONG dataLength;
  290. PAGED_CODE();
  291. irpSp = IoGetCurrentIrpStackLocation( Irp );
  292. //
  293. // Fetch adapter context for this device.
  294. // --------------------------------------
  295. // Adapter pointer was stashed in FsContext when handle was opened.
  296. //
  297. adapter = (PTAP_ADAPTER_CONTEXT )(irpSp->FileObject)->FsContext;
  298. ASSERT(adapter);
  299. //
  300. // Sanity checks on state variables
  301. //
  302. if (!tapAdapterReadAndWriteReady(adapter))
  303. {
  304. //DEBUGP (("[%s] Interface is down in IRP_MJ_WRITE\n",
  305. // MINIPORT_INSTANCE_ID (adapter)));
  306. //NOTE_ERROR();
  307. Irp->IoStatus.Status = ntStatus = STATUS_CANCELLED;
  308. Irp->IoStatus.Information = 0;
  309. IoCompleteRequest (Irp, IO_NO_INCREMENT);
  310. return ntStatus;
  311. }
  312. // Save IRP-accessible copy of buffer length
  313. Irp->IoStatus.Information = irpSp->Parameters.Write.Length;
  314. if (Irp->MdlAddress == NULL)
  315. {
  316. DEBUGP (("[%s] MdlAddress is NULL for IRP_MJ_WRITE\n",
  317. MINIPORT_INSTANCE_ID (adapter)));
  318. NOTE_ERROR();
  319. Irp->IoStatus.Status = ntStatus = STATUS_INVALID_PARAMETER;
  320. Irp->IoStatus.Information = 0;
  321. IoCompleteRequest (Irp, IO_NO_INCREMENT);
  322. return ntStatus;
  323. }
  324. //
  325. // Try to get a virtual address for the MDL.
  326. //
  327. NdisQueryMdl(
  328. Irp->MdlAddress,
  329. &Irp->AssociatedIrp.SystemBuffer,
  330. &dataLength,
  331. NormalPagePriority
  332. );
  333. if (Irp->AssociatedIrp.SystemBuffer == NULL)
  334. {
  335. DEBUGP (("[%s] Could not map address in IRP_MJ_WRITE\n",
  336. MINIPORT_INSTANCE_ID (adapter)));
  337. NOTE_ERROR();
  338. Irp->IoStatus.Status = ntStatus = STATUS_INSUFFICIENT_RESOURCES;
  339. Irp->IoStatus.Information = 0;
  340. IoCompleteRequest (Irp, IO_NO_INCREMENT);
  341. return ntStatus;
  342. }
  343. ASSERT(dataLength == irpSp->Parameters.Write.Length);
  344. Irp->IoStatus.Information = irpSp->Parameters.Write.Length;
  345. //
  346. // Handle miniport Pause
  347. // ---------------------
  348. // NDIS 6 miniports implement a temporary "Pause" state normally followed
  349. // by the Restart. While in the Pause state it is forbidden for the miniport
  350. // to indicate receive NBLs.
  351. //
  352. // That is: The device interface may be "up", but the NDIS miniport send/receive
  353. // interface may be temporarily "down".
  354. //
  355. // BUGBUG!!! In the initial implementation of the NDIS 6 TapOas receive path
  356. // the code below will perform a "lying send" for write IRPs passed to the
  357. // driver while the miniport is in the Paused state.
  358. //
  359. // The correct implementation is to go ahead and build the NBLs corresponding
  360. // to the user-mode write - but queue them. When Restart is entered the
  361. // queued NBLs would be dequeued and indicated to the host.
  362. //
  363. if(tapAdapterSendAndReceiveReady(adapter) == NDIS_STATUS_SUCCESS)
  364. {
  365. if (/*!adapter->m_tun &&*/ ((irpSp->Parameters.Write.Length) >= ETHERNET_HEADER_SIZE))
  366. {
  367. PNET_BUFFER_LIST netBufferList;
  368. DUMP_PACKET ("IRP_MJ_WRITE ETH",
  369. (unsigned char *) Irp->AssociatedIrp.SystemBuffer,
  370. irpSp->Parameters.Write.Length);
  371. //=====================================================
  372. // If IPv4 packet, check whether or not packet
  373. // was truncated.
  374. //=====================================================
  375. #if PACKET_TRUNCATION_CHECK
  376. IPv4PacketSizeVerify (
  377. (unsigned char *) Irp->AssociatedIrp.SystemBuffer,
  378. irpSp->Parameters.Write.Length,
  379. FALSE,
  380. "RX",
  381. &adapter->m_RxTrunc
  382. );
  383. #endif
  384. (Irp->MdlAddress)->Next = NULL; // No next MDL
  385. // Allocate the NBL and NB. Link MDL chain to NB.
  386. netBufferList = NdisAllocateNetBufferAndNetBufferList(
  387. adapter->ReceiveNblPool,
  388. 0, // ContextSize
  389. 0, // ContextBackFill
  390. Irp->MdlAddress, // MDL chain
  391. 0,
  392. dataLength
  393. );
  394. if(netBufferList != NULL)
  395. {
  396. LONG nblCount;
  397. NET_BUFFER_LIST_NEXT_NBL(netBufferList) = NULL; // Only one NBL
  398. // Stash IRP pointer in NBL MiniportReserved[0] field.
  399. netBufferList->MiniportReserved[0] = Irp;
  400. netBufferList->MiniportReserved[1] = NULL;
  401. // This IRP is pended.
  402. IoMarkIrpPending(Irp);
  403. // This IRP cannot be cancelled while in-flight.
  404. IoSetCancelRoutine(Irp,NULL);
  405. TAP_RX_NBL_FLAGS_CLEAR_ALL(netBufferList);
  406. // Increment in-flight receive NBL count.
  407. nblCount = NdisInterlockedIncrement(&adapter->ReceiveNblInFlightCount);
  408. ASSERT(nblCount > 0 );
  409. //
  410. // Indicate the packet
  411. // -------------------
  412. // Irp->AssociatedIrp.SystemBuffer with length irpSp->Parameters.Write.Length
  413. // contains the complete packet including Ethernet header and payload.
  414. //
  415. NdisMIndicateReceiveNetBufferLists(
  416. adapter->MiniportAdapterHandle,
  417. netBufferList,
  418. NDIS_DEFAULT_PORT_NUMBER,
  419. 1, // NumberOfNetBufferLists
  420. 0 // ReceiveFlags
  421. );
  422. ntStatus = STATUS_PENDING;
  423. }
  424. else
  425. {
  426. DEBUGP (("[%s] NdisMIndicateReceiveNetBufferLists failed in IRP_MJ_WRITE\n",
  427. MINIPORT_INSTANCE_ID (adapter)));
  428. NOTE_ERROR ();
  429. // Fail the IRP
  430. Irp->IoStatus.Information = 0;
  431. ntStatus = STATUS_INSUFFICIENT_RESOURCES;
  432. }
  433. }
  434. /*
  435. else if (adapter->m_tun && ((irpSp->Parameters.Write.Length) >= IP_HEADER_SIZE))
  436. {
  437. PETH_HEADER p_UserToTap = &adapter->m_UserToTap;
  438. PMDL mdl; // Head of MDL chain.
  439. // For IPv6, need to use Ethernet header with IPv6 proto
  440. if ( IPH_GET_VER( ((IPHDR*) Irp->AssociatedIrp.SystemBuffer)->version_len) == 6 )
  441. {
  442. p_UserToTap = &adapter->m_UserToTap_IPv6;
  443. }
  444. DUMP_PACKET2 ("IRP_MJ_WRITE P2P",
  445. p_UserToTap,
  446. (unsigned char *) Irp->AssociatedIrp.SystemBuffer,
  447. irpSp->Parameters.Write.Length);
  448. //=====================================================
  449. // If IPv4 packet, check whether or not packet
  450. // was truncated.
  451. //=====================================================
  452. #if PACKET_TRUNCATION_CHECK
  453. IPv4PacketSizeVerify (
  454. (unsigned char *) Irp->AssociatedIrp.SystemBuffer,
  455. irpSp->Parameters.Write.Length,
  456. TRUE,
  457. "RX",
  458. &adapter->m_RxTrunc
  459. );
  460. #endif
  461. //
  462. // Allocate MDL for Ethernet header
  463. // --------------------------------
  464. // Irp->AssociatedIrp.SystemBuffer with length irpSp->Parameters.Write.Length
  465. // contains the only the Ethernet payload. Prepend the user-mode provided
  466. // payload with the Ethernet header pointed to by p_UserToTap.
  467. //
  468. mdl = NdisAllocateMdl(
  469. adapter->MiniportAdapterHandle,
  470. p_UserToTap,
  471. sizeof(ETH_HEADER)
  472. );
  473. if(mdl != NULL)
  474. {
  475. PNET_BUFFER_LIST netBufferList;
  476. // Chain user's Ethernet payload behind Ethernet header.
  477. mdl->Next = Irp->MdlAddress;
  478. (Irp->MdlAddress)->Next = NULL; // No next MDL
  479. // Allocate the NBL and NB. Link MDL chain to NB.
  480. netBufferList = NdisAllocateNetBufferAndNetBufferList(
  481. adapter->ReceiveNblPool,
  482. 0, // ContextSize
  483. 0, // ContextBackFill
  484. mdl, // MDL chain
  485. 0,
  486. sizeof(ETH_HEADER) + dataLength
  487. );
  488. if(netBufferList != NULL)
  489. {
  490. LONG nblCount;
  491. NET_BUFFER_LIST_NEXT_NBL(netBufferList) = NULL; // Only one NBL
  492. // This IRP is pended.
  493. IoMarkIrpPending(Irp);
  494. // This IRP cannot be cancelled while in-flight.
  495. IoSetCancelRoutine(Irp,NULL);
  496. // Stash IRP pointer in NBL MiniportReserved[0] field.
  497. netBufferList->MiniportReserved[0] = Irp;
  498. netBufferList->MiniportReserved[1] = NULL;
  499. // Set flag indicating that this is P2P packet
  500. TAP_RX_NBL_FLAGS_CLEAR_ALL(netBufferList);
  501. TAP_RX_NBL_FLAG_SET(netBufferList,TAP_RX_NBL_FLAGS_IS_P2P);
  502. // Increment in-flight receive NBL count.
  503. nblCount = NdisInterlockedIncrement(&adapter->ReceiveNblInFlightCount);
  504. ASSERT(nblCount > 0 );
  505. //
  506. // Indicate the packet
  507. //
  508. NdisMIndicateReceiveNetBufferLists(
  509. adapter->MiniportAdapterHandle,
  510. netBufferList,
  511. NDIS_DEFAULT_PORT_NUMBER,
  512. 1, // NumberOfNetBufferLists
  513. 0 // ReceiveFlags
  514. );
  515. ntStatus = STATUS_PENDING;
  516. }
  517. else
  518. {
  519. mdl->Next = NULL;
  520. NdisFreeMdl(mdl);
  521. DEBUGP (("[%s] NdisMIndicateReceiveNetBufferLists failed in IRP_MJ_WRITE\n",
  522. MINIPORT_INSTANCE_ID (adapter)));
  523. NOTE_ERROR ();
  524. // Fail the IRP
  525. Irp->IoStatus.Information = 0;
  526. ntStatus = STATUS_INSUFFICIENT_RESOURCES;
  527. }
  528. }
  529. else
  530. {
  531. DEBUGP (("[%s] NdisAllocateMdl failed in IRP_MJ_WRITE\n",
  532. MINIPORT_INSTANCE_ID (adapter)));
  533. NOTE_ERROR ();
  534. // Fail the IRP
  535. Irp->IoStatus.Information = 0;
  536. ntStatus = STATUS_INSUFFICIENT_RESOURCES;
  537. }
  538. }
  539. */
  540. else
  541. {
  542. DEBUGP (("[%s] Bad buffer size in IRP_MJ_WRITE, len=%d\n",
  543. MINIPORT_INSTANCE_ID (adapter),
  544. irpSp->Parameters.Write.Length));
  545. NOTE_ERROR ();
  546. Irp->IoStatus.Information = 0; // ETHERNET_HEADER_SIZE;
  547. Irp->IoStatus.Status = ntStatus = STATUS_BUFFER_TOO_SMALL;
  548. }
  549. }
  550. else
  551. {
  552. DEBUGP (("[%s] Lying send in IRP_MJ_WRITE while adapter paused\n",
  553. MINIPORT_INSTANCE_ID (adapter)));
  554. ntStatus = STATUS_SUCCESS;
  555. }
  556. if (ntStatus != STATUS_PENDING)
  557. {
  558. Irp->IoStatus.Status = ntStatus;
  559. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  560. }
  561. return ntStatus;
  562. }