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.

1696 lines
59 KiB

  1. /*++
  2. Copyright(c) 1998,99 Microsoft Corporation
  3. Module Name:
  4. nic.c
  5. Abstract:
  6. Windows Load Balancing Service (WLBS)
  7. Driver - upper-level (NIC) layer of intermediate miniport
  8. Author:
  9. kyrilf
  10. --*/
  11. #define NDIS_MINIPORT_DRIVER 1
  12. //#define NDIS50_MINIPORT 1
  13. #define NDIS51_MINIPORT 1
  14. #include <ndis.h>
  15. #include "nic.h"
  16. #include "prot.h"
  17. #include "main.h"
  18. #include "util.h"
  19. #include "wlbsparm.h"
  20. #include "univ.h"
  21. #include "log.h"
  22. #include "nic.tmh"
  23. /* define this routine here since the necessary portion of ndis.h was not
  24. imported due to NDIS_... flags */
  25. extern NTKERNELAPI VOID KeBugCheckEx (ULONG code, ULONG_PTR p1, ULONG_PTR p2, ULONG_PTR p3, ULONG_PTR p4);
  26. NTHALAPI KIRQL KeGetCurrentIrql();
  27. /* GLOBALS */
  28. static ULONG log_module_id = LOG_MODULE_NIC;
  29. /* PROCEDURES */
  30. /* miniport handlers */
  31. NDIS_STATUS Nic_init ( /* PASSIVE_IRQL */
  32. PNDIS_STATUS open_status,
  33. PUINT medium_index,
  34. PNDIS_MEDIUM medium_array,
  35. UINT medium_size,
  36. NDIS_HANDLE adapter_handle,
  37. NDIS_HANDLE wrapper_handle)
  38. {
  39. PMAIN_CTXT ctxtp;
  40. UINT i;
  41. NDIS_STATUS status;
  42. PMAIN_ADAPTER adapterp;
  43. /* verify that we have the context setup (Prot_bind was called) */
  44. UNIV_PRINT_INFO(("Nic_init: Initializing, adapter_handle=0x%p", adapter_handle));
  45. ctxtp = (PMAIN_CTXT) NdisIMGetDeviceContext (adapter_handle);
  46. if (ctxtp == NULL)
  47. {
  48. UNIV_PRINT_INFO(("Nic_init: return=NDIS_STATUS_ADAPTER_NOT_FOUND"));
  49. TRACE_INFO("%!FUNC! return=NDIS_STATUS_ADAPTER_NOT_FOUND");
  50. return NDIS_STATUS_ADAPTER_NOT_FOUND;
  51. }
  52. UNIV_ASSERT (ctxtp -> code == MAIN_CTXT_CODE);
  53. adapterp = & (univ_adapters [ctxtp -> adapter_id]);
  54. UNIV_ASSERT (adapterp -> ctxtp == ctxtp);
  55. /* return supported mediums */
  56. for (i = 0; i < medium_size; i ++)
  57. {
  58. if (medium_array [i] == ctxtp -> medium)
  59. {
  60. * medium_index = i;
  61. break;
  62. }
  63. }
  64. if (i >= medium_size)
  65. {
  66. UNIV_PRINT_CRIT(("Nic_init: Unsupported media requested %d, %d, %x", i, medium_size, ctxtp -> medium));
  67. UNIV_PRINT_INFO(("Nic_init: return=NDIS_STATUS_UNSUPPORTED_MEDIA"));
  68. LOG_MSG2 (MSG_ERROR_MEDIA, MSG_NONE, i, ctxtp -> medium);
  69. TRACE_CRIT("%!FUNC! Unsupported media requested i=%d, size=%d, medium=0x%x", i, medium_size, ctxtp -> medium);
  70. TRACE_INFO("<-%!FUNC! return=NDIS_STATUS_UNSUPPORTED_MEDIA");
  71. return NDIS_STATUS_UNSUPPORTED_MEDIA;
  72. }
  73. ctxtp -> prot_handle = adapter_handle;
  74. NdisMSetAttributesEx (adapter_handle, ctxtp, 0,
  75. NDIS_ATTRIBUTE_INTERMEDIATE_DRIVER | /* V1.1.2 */ /* v2.07 */
  76. NDIS_ATTRIBUTE_DESERIALIZE |
  77. NDIS_ATTRIBUTE_IGNORE_PACKET_TIMEOUT |
  78. NDIS_ATTRIBUTE_IGNORE_REQUEST_TIMEOUT |
  79. NDIS_ATTRIBUTE_NO_HALT_ON_SUSPEND, 0);
  80. /* Setting up the default value for the Device State Flag as PM capable
  81. initialize the PM Variable, (for both NIC and the PROT)
  82. Device is ON by default. */
  83. ctxtp->prot_pnp_state = NdisDeviceStateD0;
  84. ctxtp->nic_pnp_state = NdisDeviceStateD0;
  85. /* Allocate memory for our pseudo-periodic NDIS timer. */
  86. status = NdisAllocateMemoryWithTag(&ctxtp->timer, sizeof(NDIS_MINIPORT_TIMER), UNIV_POOL_TAG);
  87. if (status != NDIS_STATUS_SUCCESS) {
  88. UNIV_PRINT_CRIT(("Nic_init: Error allocating timer; status=0x%x", status));
  89. UNIV_PRINT_INFO(("Nic_init: return=NDIS_STATUS_RESOURCES"));
  90. LOG_MSG2(MSG_ERROR_MEMORY, MSG_NONE, sizeof(NDIS_MINIPORT_TIMER), status);
  91. TRACE_CRIT("%!FUNC! Error allocating timer; status=0x%x", status);
  92. TRACE_INFO("<-%!FUNC! return=NDIS_STATUS_RESOURCES");
  93. return NDIS_STATUS_RESOURCES;
  94. }
  95. /* Initialize the timer structure; here we set the timer routine (Nic_timer) and the
  96. context that will be a parameter to that function, the adapter MAIN_CTXT. */
  97. NdisMInitializeTimer((PNDIS_MINIPORT_TIMER)ctxtp->timer, ctxtp->prot_handle, Nic_timer, ctxtp);
  98. /* Set the initial timeout value to the default heartbeat period from the registry. */
  99. ctxtp->curr_tout = ctxtp->params.alive_period;
  100. {
  101. PNDIS_REQUEST request;
  102. MAIN_ACTION act;
  103. ULONG xferred;
  104. ULONG needed;
  105. ULONG result;
  106. act.code = MAIN_ACTION_CODE;
  107. act.ctxtp = ctxtp;
  108. act.op.request.xferred = &xferred;
  109. act.op.request.needed = &needed;
  110. act.op.request.external = FALSE;
  111. act.op.request.buffer_len = 0;
  112. act.op.request.buffer = NULL;
  113. NdisInitializeEvent(&act.op.request.event);
  114. NdisResetEvent(&act.op.request.event);
  115. NdisZeroMemory(&act.op.request.req, sizeof(NDIS_REQUEST));
  116. request = &act.op.request.req;
  117. /* Check to see if the media is connected. Some cards do not register disconnection, so use this as a hint. */
  118. request->RequestType = NdisRequestQueryInformation;
  119. request->DATA.QUERY_INFORMATION.Oid = OID_GEN_MEDIA_CONNECT_STATUS;
  120. request->DATA.QUERY_INFORMATION.InformationBuffer = &result;
  121. request->DATA.QUERY_INFORMATION.InformationBufferLength = sizeof(ULONG);
  122. act.status = NDIS_STATUS_FAILURE;
  123. status = Prot_request(ctxtp, &act, FALSE);
  124. if (status != NDIS_STATUS_SUCCESS)
  125. {
  126. UNIV_PRINT_CRIT(("Prot_bind: Error %x requesting media connection status %d %d", status, xferred, needed));
  127. TRACE_CRIT("%!FUNC! Error 0x%x requesting media connection status %d %d", status, xferred, needed);
  128. ctxtp->media_connected = TRUE;
  129. }
  130. else
  131. {
  132. UNIV_PRINT_INFO(("Prot_bind: Media state - %s", result == NdisMediaStateConnected ? "CONNECTED" : "DISCONNECTED"));
  133. TRACE_INFO("%!FUNC! Media state - %s", result == NdisMediaStateConnected ? "CONNECTED" : "DISCONNECTED");
  134. ctxtp->media_connected = (result == NdisMediaStateConnected);
  135. }
  136. }
  137. NdisAcquireSpinLock(& univ_bind_lock);
  138. UNIV_ASSERT (adapterp -> code == MAIN_ADAPTER_CODE);
  139. adapterp -> announced = TRUE;
  140. NdisReleaseSpinLock(& univ_bind_lock);
  141. /* Set the first heartbeat timeout. */
  142. NdisMSetTimer((PNDIS_MINIPORT_TIMER)ctxtp->timer, ctxtp->curr_tout);
  143. UNIV_PRINT_INFO(("Nic_init: return=NDIS_STATUS_SUCCESS"));
  144. TRACE_INFO("<-%!FUNC! return=NDIS_STATUS_SUCCESS");
  145. return NDIS_STATUS_SUCCESS;
  146. } /* end Nic_init */
  147. VOID Nic_halt ( /* PASSIVE_IRQL */
  148. NDIS_HANDLE adapter_handle)
  149. {
  150. PMAIN_CTXT ctxtp = (PMAIN_CTXT) adapter_handle;
  151. BOOLEAN done;
  152. NDIS_STATUS status;
  153. PMAIN_ADAPTER adapterp;
  154. UNIV_PRINT_INFO(("Nic_halt: Halting, adapter_id=0x%x", ctxtp -> adapter_id));
  155. TRACE_INFO("->%!FUNC! Halting, adapter_id=0x%x", ctxtp -> adapter_id);
  156. UNIV_ASSERT (ctxtp -> code == MAIN_CTXT_CODE);
  157. adapterp = & (univ_adapters [ctxtp -> adapter_id]);
  158. UNIV_ASSERT (adapterp -> code == MAIN_ADAPTER_CODE);
  159. UNIV_ASSERT (adapterp -> ctxtp == ctxtp);
  160. NdisAcquireSpinLock(& univ_bind_lock);
  161. if (! adapterp -> announced)
  162. {
  163. NdisReleaseSpinLock(& univ_bind_lock);
  164. UNIV_PRINT_CRIT(("Nic_halt: Adapter not announced, adapter id = 0x%x", ctxtp -> adapter_id));
  165. UNIV_PRINT_INFO(("Nic_halt: return"));
  166. TRACE_CRIT("%!FUNC! Adapter not announced, adapter id = 0x%x", ctxtp -> adapter_id);
  167. TRACE_INFO("<-%!FUNC! return");
  168. return;
  169. }
  170. adapterp -> announced = FALSE;
  171. NdisReleaseSpinLock(& univ_bind_lock);
  172. /* Cancel the heartbeat timer. */
  173. NdisMCancelTimer((PNDIS_MINIPORT_TIMER)ctxtp->timer, &done);
  174. /* If canceling the timer fails, this means that the timer was not in the timer queue.
  175. This indicates that either the timer function is currently running, or was about to
  176. be run when we canceled it. However, we can't be SURE whether or not the timer
  177. routine will run, so we can't count on it - the DPC may or may not have been canceled
  178. if NdisMCancelTimer returns false. Since we have set adapterp->announced to FALSE,
  179. this will prevent the timer routine from re-setting the timer before it exits.
  180. To make sure that we don't free any memory that may be used by the timer routine,
  181. we'll just wait here for at least one heartbeat period before we delete the timer
  182. memory and move on to delete the adapter context, just in case. */
  183. if (!done) Nic_sleep(ctxtp->curr_tout);
  184. /* Free the timer memory. */
  185. NdisFreeMemory(ctxtp->timer, sizeof(NDIS_MINIPORT_TIMER), 0);
  186. /* ctxtp->prot_handle = NULL;
  187. This is commented out to resolve a timing issue.
  188. During unbind, a packet could go through but the flags
  189. announced and bound are reset and prot_handle is set to NULL
  190. So, this should be set after CloseAdapter. */
  191. status = Prot_close (adapterp);
  192. if (status != NDIS_STATUS_SUCCESS)
  193. {
  194. /* Don't do an early exit. This check was added for tracing only */
  195. TRACE_CRIT("%!FUNC! Prot_close failed with 0x%x", status);
  196. }
  197. /* ctxtp might be gone at this point! */
  198. UNIV_PRINT_INFO(("Nic_halt: return"));
  199. TRACE_INFO("<-%!FUNC! return");
  200. } /* end Nic_halt */
  201. //#define TRACE_OID
  202. NDIS_STATUS Nic_info_query (
  203. NDIS_HANDLE adapter_handle,
  204. NDIS_OID oid,
  205. PVOID info_buf,
  206. ULONG info_len,
  207. PULONG written,
  208. PULONG needed)
  209. {
  210. PMAIN_CTXT ctxtp = (PMAIN_CTXT) adapter_handle;
  211. NDIS_STATUS status;
  212. PMAIN_ACTION actp;
  213. PNDIS_REQUEST request;
  214. ULONG size;
  215. PMAIN_ADAPTER adapterp;
  216. UNIV_ASSERT (ctxtp -> code == MAIN_CTXT_CODE);
  217. #if defined(TRACE_OID)
  218. DbgPrint("Nic_info_query: called for %x, %x %d\n", oid, info_buf, info_len);
  219. #endif
  220. adapterp = & (univ_adapters [ctxtp -> adapter_id]);
  221. UNIV_ASSERT (adapterp -> code == MAIN_ADAPTER_CODE);
  222. UNIV_ASSERT (adapterp -> ctxtp == ctxtp);
  223. // reference counting in unbinding
  224. if (! adapterp -> inited)
  225. {
  226. TRACE_CRIT("%!FUNC! adapter not initialized, adapter_id = 0x%x", ctxtp -> adapter_id);
  227. TRACE_VERB("<-%!FUNC! return=NDIS_STATUS_FAILURE");
  228. return NDIS_STATUS_FAILURE;
  229. }
  230. if (oid == OID_PNP_QUERY_POWER)
  231. {
  232. #if defined(TRACE_OID)
  233. DbgPrint("Nic_info_query: OID_PNP_QUERY_POWER\n");
  234. #endif
  235. TRACE_VERB("<-%!FUNC! return=NDIS_STATUS_SUCCESS for oid=OID_PNP_QUERY_POWER");
  236. return NDIS_STATUS_SUCCESS;
  237. }
  238. if (ctxtp -> reset_state != MAIN_RESET_NONE ||
  239. ctxtp->nic_pnp_state > NdisDeviceStateD0 ||
  240. ctxtp->standby_state)
  241. {
  242. TRACE_CRIT("%!FUNC! adapter reset or in standby, adapter id = 0x%x", ctxtp -> adapter_id);
  243. TRACE_VERB("<-%!FUNC! return=NDIS_STATUS_FAILURE");
  244. return NDIS_STATUS_FAILURE;
  245. }
  246. switch (oid)
  247. {
  248. case OID_GEN_SUPPORTED_LIST:
  249. #if defined(TRACE_OID)
  250. DbgPrint("Nic_info_query: OID_GEN_SUPPORTED_LIST\n");
  251. #endif
  252. TRACE_VERB("%!FUNC! case: OID_GEN_SUPPORTED_LIST");
  253. break;
  254. #if 0
  255. size = sizeof(univ_oids);
  256. if (size > info_len)
  257. {
  258. * needed = size;
  259. return NDIS_STATUS_INVALID_LENGTH;
  260. }
  261. NdisMoveMemory (info_buf, univ_oids, size);
  262. * written = size;
  263. return NDIS_STATUS_SUCCESS;
  264. #endif
  265. case OID_GEN_XMIT_OK:
  266. if (info_len < sizeof (ULONG))
  267. {
  268. * needed = sizeof (ULONG);
  269. TRACE_CRIT("%!FUNC! case: OID_GEN_XMIT_OK adapter id = 0x%x, info_buf too small", ctxtp -> adapter_id);
  270. TRACE_VERB("<-%!FUNC! return=NDIS_STATUS_INVALID_LENGTH");
  271. return NDIS_STATUS_INVALID_LENGTH;
  272. }
  273. * ((PULONG) info_buf) = ctxtp -> cntr_xmit_ok;
  274. * written = sizeof (ULONG);
  275. #if defined(TRACE_OID)
  276. DbgPrint("Nic_info_query: OID_GEN_XMIT_OK %d\n", *(PULONG) info_buf);
  277. #endif
  278. return NDIS_STATUS_SUCCESS;
  279. case OID_GEN_RCV_OK:
  280. if (info_len < sizeof (ULONG))
  281. {
  282. * needed = sizeof (ULONG);
  283. TRACE_CRIT("%!FUNC! case: OID_GEN_RCV_OK adapter id = 0x%x, info_buf too small", ctxtp -> adapter_id);
  284. TRACE_VERB("<-%!FUNC! return=NDIS_STATUS_INVALID_LENGTH");
  285. return NDIS_STATUS_INVALID_LENGTH;
  286. }
  287. * ((PULONG) info_buf) = ctxtp -> cntr_recv_ok;
  288. * written = sizeof (ULONG);
  289. #if defined(TRACE_OID)
  290. DbgPrint("Nic_info_query: OID_GEN_RCV_OK %d\n", *(PULONG) info_buf);
  291. #endif
  292. return NDIS_STATUS_SUCCESS;
  293. case OID_GEN_XMIT_ERROR:
  294. if (info_len < sizeof (ULONG))
  295. {
  296. * needed = sizeof (ULONG);
  297. TRACE_CRIT("%!FUNC! case: OID_GEN_XMIT_ERROR adapter id = 0x%x, info_buf too small", ctxtp -> adapter_id);
  298. TRACE_VERB("<-%!FUNC! return=NDIS_STATUS_INVALID_LENGTH");
  299. return NDIS_STATUS_INVALID_LENGTH;
  300. }
  301. * ((PULONG) info_buf) = ctxtp -> cntr_xmit_err;
  302. * written = sizeof (ULONG);
  303. #if defined(TRACE_OID)
  304. DbgPrint("Nic_info_query: OID_GEN_XMIT_ERROR %d\n", *(PULONG) info_buf);
  305. #endif
  306. return NDIS_STATUS_SUCCESS;
  307. case OID_GEN_RCV_ERROR:
  308. if (info_len < sizeof (ULONG))
  309. {
  310. * needed = sizeof (ULONG);
  311. TRACE_CRIT("%!FUNC! case: OID_GEN_RCV_ERROR adapter id = 0x%x, info_buf too small", ctxtp -> adapter_id);
  312. TRACE_VERB("<-%!FUNC! return=NDIS_STATUS_INVALID_LENGTH");
  313. return NDIS_STATUS_INVALID_LENGTH;
  314. }
  315. * ((PULONG) info_buf) = ctxtp -> cntr_recv_err;
  316. * written = sizeof (ULONG);
  317. #if defined(TRACE_OID)
  318. DbgPrint("Nic_info_query: OID_GEN_RCV_ERROR %d\n", *(PULONG) info_buf);
  319. #endif
  320. return NDIS_STATUS_SUCCESS;
  321. case OID_GEN_RCV_NO_BUFFER:
  322. if (info_len < sizeof (ULONG))
  323. {
  324. * needed = sizeof (ULONG);
  325. TRACE_CRIT("%!FUNC! case: OID_GEN_RCV_NO_BUFFER adapter id = 0x%x, info_buf too small", ctxtp -> adapter_id);
  326. TRACE_VERB("<-%!FUNC! return=NDIS_STATUS_INVALID_LENGTH");
  327. return NDIS_STATUS_INVALID_LENGTH;
  328. }
  329. * ((PULONG) info_buf) = ctxtp -> cntr_recv_no_buf;
  330. * written = sizeof (ULONG);
  331. #if defined(TRACE_OID)
  332. DbgPrint("Nic_info_query: OID_GEN_RCV_NO_BUFFER %d\n", *(PULONG) info_buf);
  333. #endif
  334. return NDIS_STATUS_SUCCESS;
  335. case OID_GEN_DIRECTED_BYTES_XMIT:
  336. if (info_len < sizeof (ULONGLONG))
  337. {
  338. * needed = sizeof (ULONGLONG);
  339. TRACE_CRIT("%!FUNC! case: OID_GEN_DIRECTED_BYTES_XMIT adapter id = 0x%x, info_buf too small", ctxtp -> adapter_id);
  340. TRACE_VERB("<-%!FUNC! return=NDIS_STATUS_INVALID_LENGTH");
  341. return NDIS_STATUS_INVALID_LENGTH;
  342. }
  343. * ((PULONGLONG) info_buf) = ctxtp -> cntr_xmit_bytes_dir;
  344. * written = sizeof (ULONGLONG);
  345. #if defined(TRACE_OID)
  346. DbgPrint("Nic_info_query: OID_GEN_DIRECTED_BYTES_XMIT %.0f\n", *(PULONGLONG) info_buf);
  347. #endif
  348. return NDIS_STATUS_SUCCESS;
  349. case OID_GEN_DIRECTED_FRAMES_XMIT:
  350. if (info_len < sizeof (ULONG))
  351. {
  352. * needed = sizeof (ULONG);
  353. TRACE_CRIT("%!FUNC! case: OID_GEN_DIRECTED_FRAMES_XMIT adapter id = 0x%x, info_buf too small", ctxtp -> adapter_id);
  354. TRACE_VERB("<-%!FUNC! return=NDIS_STATUS_INVALID_LENGTH");
  355. return NDIS_STATUS_INVALID_LENGTH;
  356. }
  357. * ((PULONG) info_buf) = ctxtp -> cntr_xmit_frames_dir;
  358. * written = sizeof (ULONG);
  359. #if defined(TRACE_OID)
  360. DbgPrint("Nic_info_query: OID_GEN_DIRECTED_FRAMES_XMIT %d\n", *(PULONG) info_buf);
  361. #endif
  362. return NDIS_STATUS_SUCCESS;
  363. case OID_GEN_MULTICAST_BYTES_XMIT:
  364. if (info_len < sizeof (ULONGLONG))
  365. {
  366. * needed = sizeof (ULONGLONG);
  367. TRACE_CRIT("%!FUNC! case: OID_GEN_MULTICAST_BYTES_XMIT adapter id = 0x%x, info_buf too small", ctxtp -> adapter_id);
  368. TRACE_VERB("<-%!FUNC! return=NDIS_STATUS_INVALID_LENGTH");
  369. return NDIS_STATUS_INVALID_LENGTH;
  370. }
  371. * ((PULONGLONG) info_buf) = ctxtp -> cntr_xmit_bytes_mcast;
  372. * written = sizeof (ULONGLONG);
  373. #if defined(TRACE_OID)
  374. DbgPrint("Nic_info_query: OID_GEN_MULTICAST_BYTES_XMIT %.0f\n", *(PULONGLONG) info_buf);
  375. #endif
  376. return NDIS_STATUS_SUCCESS;
  377. case OID_GEN_MULTICAST_FRAMES_XMIT:
  378. if (info_len < sizeof (ULONG))
  379. {
  380. * needed = sizeof (ULONG);
  381. TRACE_CRIT("%!FUNC! case: OID_GEN_MULTICAST_FRAMES_XMIT adapter id = 0x%x, info_buf too small", ctxtp -> adapter_id);
  382. TRACE_VERB("<-%!FUNC! return=NDIS_STATUS_INVALID_LENGTH");
  383. return NDIS_STATUS_INVALID_LENGTH;
  384. }
  385. * ((PULONG) info_buf) = ctxtp -> cntr_xmit_frames_mcast;
  386. * written = sizeof (ULONG);
  387. #if defined(TRACE_OID)
  388. DbgPrint("Nic_info_query: OID_GEN_MULTICAST_FRAMES_XMIT %d\n", *(PULONG) info_buf);
  389. #endif
  390. return NDIS_STATUS_SUCCESS;
  391. case OID_GEN_BROADCAST_BYTES_XMIT:
  392. if (info_len < sizeof (ULONGLONG))
  393. {
  394. * needed = sizeof (ULONGLONG);
  395. TRACE_CRIT("%!FUNC! case: OID_GEN_BROADCAST_BYTES_XMIT adapter id = 0x%x, info_buf too small", ctxtp -> adapter_id);
  396. TRACE_VERB("<-%!FUNC! return=NDIS_STATUS_INVALID_LENGTH");
  397. return NDIS_STATUS_INVALID_LENGTH;
  398. }
  399. * ((PULONGLONG) info_buf) = ctxtp -> cntr_xmit_bytes_bcast;
  400. * written = sizeof (ULONGLONG);
  401. #if defined(TRACE_OID)
  402. DbgPrint("Nic_info_query: OID_GEN_BROADCAST_BYTES_XMIT %.0f\n", *(PULONGLONG) info_buf);
  403. #endif
  404. return NDIS_STATUS_SUCCESS;
  405. case OID_GEN_BROADCAST_FRAMES_XMIT:
  406. if (info_len < sizeof (ULONG))
  407. {
  408. * needed = sizeof (ULONG);
  409. TRACE_CRIT("%!FUNC! case: OID_GEN_BROADCAST_FRAMES_XMIT adapter id = 0x%x, info_buf too small", ctxtp -> adapter_id);
  410. TRACE_VERB("<-%!FUNC! return=NDIS_STATUS_INVALID_LENGTH");
  411. return NDIS_STATUS_INVALID_LENGTH;
  412. }
  413. * ((PULONG) info_buf) = ctxtp -> cntr_xmit_frames_bcast;
  414. * written = sizeof (ULONG);
  415. #if defined(TRACE_OID)
  416. DbgPrint("Nic_info_query: OID_GEN_BROADCAST_FRAMES_XMIT %d\n", *(PULONG) info_buf);
  417. #endif
  418. return NDIS_STATUS_SUCCESS;
  419. case OID_GEN_DIRECTED_BYTES_RCV:
  420. if (info_len < sizeof (ULONGLONG))
  421. {
  422. * needed = sizeof (ULONGLONG);
  423. TRACE_CRIT("%!FUNC! case: OID_GEN_DIRECTED_BYTES_RCV adapter id = 0x%x, info_buf too small", ctxtp -> adapter_id);
  424. TRACE_VERB("<-%!FUNC! return=NDIS_STATUS_INVALID_LENGTH");
  425. return NDIS_STATUS_INVALID_LENGTH;
  426. }
  427. * ((PULONGLONG) info_buf) = ctxtp -> cntr_recv_bytes_dir;
  428. * written = sizeof (ULONGLONG);
  429. #if defined(TRACE_OID)
  430. DbgPrint("Nic_info_query: OID_GEN_DIRECTED_BYTES_RCV %.0f\n", *(PULONGLONG) info_buf);
  431. #endif
  432. return NDIS_STATUS_SUCCESS;
  433. case OID_GEN_DIRECTED_FRAMES_RCV:
  434. if (info_len < sizeof (ULONG))
  435. {
  436. * needed = sizeof (ULONG);
  437. TRACE_CRIT("%!FUNC! case: OID_GEN_DIRECTED_FRAMES_RCV adapter id = 0x%x, info_buf too small", ctxtp -> adapter_id);
  438. TRACE_VERB("<-%!FUNC! return=NDIS_STATUS_INVALID_LENGTH");
  439. return NDIS_STATUS_INVALID_LENGTH;
  440. }
  441. * ((PULONG) info_buf) = ctxtp -> cntr_recv_frames_dir;
  442. * written = sizeof (ULONG);
  443. #if defined(TRACE_OID)
  444. DbgPrint("Nic_info_query: OID_GEN_DIRECTED_FRAMES_RCV %d\n", *(PULONG) info_buf);
  445. #endif
  446. return NDIS_STATUS_SUCCESS;
  447. case OID_GEN_MULTICAST_BYTES_RCV:
  448. if (info_len < sizeof (ULONGLONG))
  449. {
  450. * needed = sizeof (ULONGLONG);
  451. TRACE_CRIT("%!FUNC! case: OID_GEN_MULTICAST_BYTES_RCV adapter id = 0x%x, info_buf too small", ctxtp -> adapter_id);
  452. TRACE_VERB("<-%!FUNC! return=NDIS_STATUS_INVALID_LENGTH");
  453. return NDIS_STATUS_INVALID_LENGTH;
  454. }
  455. * ((PULONGLONG) info_buf) = ctxtp -> cntr_recv_bytes_mcast;
  456. * written = sizeof (ULONGLONG);
  457. #if defined(TRACE_OID)
  458. DbgPrint("Nic_info_query: OID_GEN_MULTICAST_BYTES_RCV %.0f\n", *(PULONGLONG) info_buf);
  459. #endif
  460. return NDIS_STATUS_SUCCESS;
  461. case OID_GEN_MULTICAST_FRAMES_RCV:
  462. if (info_len < sizeof (ULONG))
  463. {
  464. * needed = sizeof (ULONG);
  465. TRACE_CRIT("%!FUNC! case: OID_GEN_MULTICAST_FRAMES_RCV adapter id = 0x%x, info_buf too small", ctxtp -> adapter_id);
  466. TRACE_VERB("<-%!FUNC! return=NDIS_STATUS_INVALID_LENGTH");
  467. return NDIS_STATUS_INVALID_LENGTH;
  468. }
  469. * ((PULONG) info_buf) = ctxtp -> cntr_recv_frames_mcast;
  470. * written = sizeof (ULONG);
  471. #if defined(TRACE_OID)
  472. DbgPrint("Nic_info_query: OID_GEN_MULTICAST_FRAMES_RCV %d\n", *(PULONG) info_buf);
  473. #endif
  474. return NDIS_STATUS_SUCCESS;
  475. case OID_GEN_BROADCAST_BYTES_RCV:
  476. if (info_len < sizeof (ULONGLONG))
  477. {
  478. * needed = sizeof (ULONGLONG);
  479. TRACE_CRIT("%!FUNC! case: OID_GEN_BROADCAST_BYTES_RCV adapter id = 0x%x, info_buf too small", ctxtp -> adapter_id);
  480. TRACE_VERB("<-%!FUNC! return=NDIS_STATUS_INVALID_LENGTH");
  481. return NDIS_STATUS_INVALID_LENGTH;
  482. }
  483. * ((PULONGLONG) info_buf) = ctxtp -> cntr_recv_bytes_bcast;
  484. * written = sizeof (ULONGLONG);
  485. #if defined(TRACE_OID)
  486. DbgPrint("Nic_info_query: OID_GEN_DIRECTED_BROADCAST_RCV %.0f\n", *(PULONGLONG) info_buf);
  487. #endif
  488. return NDIS_STATUS_SUCCESS;
  489. case OID_GEN_BROADCAST_FRAMES_RCV:
  490. if (info_len < sizeof (ULONG))
  491. {
  492. * needed = sizeof (ULONG);
  493. TRACE_CRIT("%!FUNC! case: OID_GEN_BROADCAST_FRAMES_RCV adapter id = 0x%x, info_buf too small", ctxtp -> adapter_id);
  494. TRACE_VERB("<-%!FUNC! return=NDIS_STATUS_INVALID_LENGTH");
  495. return NDIS_STATUS_INVALID_LENGTH;
  496. }
  497. * ((PULONG) info_buf) = ctxtp -> cntr_recv_frames_bcast;
  498. * written = sizeof (ULONG);
  499. #if defined(TRACE_OID)
  500. DbgPrint("Nic_info_query: OID_GEN_BROADCAST_FRAMES_RCV %d\n", *(PULONG) info_buf);
  501. #endif
  502. return NDIS_STATUS_SUCCESS;
  503. case OID_GEN_RCV_CRC_ERROR:
  504. if (info_len < sizeof (ULONG))
  505. {
  506. * needed = sizeof (ULONG);
  507. TRACE_CRIT("%!FUNC! case: OID_GEN_RCV_CRC_ERROR adapter id = 0x%x, info_buf too small", ctxtp -> adapter_id);
  508. TRACE_VERB("<-%!FUNC! return=NDIS_STATUS_INVALID_LENGTH");
  509. return NDIS_STATUS_INVALID_LENGTH;
  510. }
  511. * ((PULONG) info_buf) = ctxtp -> cntr_recv_crc_err;
  512. * written = sizeof (ULONG);
  513. #if defined(TRACE_OID)
  514. DbgPrint("Nic_info_query: OID_GEN_RCV_CRC_ERROR %d\n", *(PULONG) info_buf);
  515. #endif
  516. return NDIS_STATUS_SUCCESS;
  517. case OID_GEN_TRANSMIT_QUEUE_LENGTH:
  518. if (info_len < sizeof (ULONG))
  519. {
  520. * needed = sizeof (ULONG);
  521. TRACE_CRIT("%!FUNC! case: OID_GEN_TRANSMIT_QUEUE_LENGTH adapter id = 0x%x, info_buf too small", ctxtp -> adapter_id);
  522. TRACE_VERB("<-%!FUNC! return=NDIS_STATUS_INVALID_LENGTH");
  523. return NDIS_STATUS_INVALID_LENGTH;
  524. }
  525. * ((PULONG) info_buf) = ctxtp -> cntr_xmit_queue_len;
  526. * written = sizeof (ULONG);
  527. #if defined(TRACE_OID)
  528. DbgPrint("Nic_info_query: OID_GEN_TRANSMIT_QUEUE_LENGTH %d\n", *(PULONG) info_buf);
  529. #endif
  530. return NDIS_STATUS_SUCCESS;
  531. default:
  532. break;
  533. }
  534. actp = Main_action_get (ctxtp);
  535. if (actp == NULL)
  536. {
  537. UNIV_PRINT_CRIT(("Nic_info_query: Error allocating action"));
  538. TRACE_CRIT("%!FUNC! Error allocating action");
  539. TRACE_VERB("<-%!FUNC! return=NDIS_STATUS_FAILURE");
  540. return NDIS_STATUS_FAILURE;
  541. }
  542. request = & actp -> op . request . req;
  543. request -> RequestType = NdisRequestQueryInformation;
  544. request -> DATA . QUERY_INFORMATION . Oid = oid;
  545. request -> DATA . QUERY_INFORMATION . InformationBuffer = info_buf;
  546. request -> DATA . QUERY_INFORMATION . InformationBufferLength = info_len;
  547. actp -> op . request . xferred = written;
  548. actp -> op . request . needed = needed;
  549. /* pass request down */
  550. status = Prot_request (ctxtp, actp, TRUE);
  551. if (status != NDIS_STATUS_PENDING)
  552. {
  553. * written = request -> DATA . QUERY_INFORMATION . BytesWritten;
  554. * needed = request -> DATA . QUERY_INFORMATION . BytesNeeded;
  555. #if defined(TRACE_OID)
  556. DbgPrint("Nic_info_query: done %x, %d %d, %x\n", status, * written, * needed, * ((PULONG) (request -> DATA . QUERY_INFORMATION . InformationBuffer)));
  557. #endif
  558. /* override return values of some oids */
  559. if (oid == OID_GEN_MAXIMUM_SEND_PACKETS && info_len >= sizeof (ULONG))
  560. {
  561. * ((PULONG) info_buf) = CVY_MAX_SEND_PACKETS;
  562. * written = sizeof (ULONG);
  563. status = NDIS_STATUS_SUCCESS;
  564. }
  565. else if (oid == OID_802_3_CURRENT_ADDRESS && status == NDIS_STATUS_SUCCESS)
  566. {
  567. if (info_len >= sizeof(CVY_MAC_ADR)) {
  568. if (!ctxtp->params.mcast_support && ctxtp->cl_ip_addr != 0)
  569. NdisMoveMemory(info_buf, &ctxtp->cl_mac_addr, sizeof(CVY_MAC_ADR));
  570. else
  571. NdisMoveMemory(info_buf, &ctxtp->ded_mac_addr, sizeof(CVY_MAC_ADR));
  572. *written = sizeof(CVY_MAC_ADR);
  573. } else {
  574. UNIV_PRINT_CRIT(("Nic_info_query: MAC address buffer too small (%u) - not spoofing", info_len));
  575. }
  576. }
  577. else if (oid == OID_GEN_MAC_OPTIONS && status == NDIS_STATUS_SUCCESS)
  578. {
  579. * ((PULONG) info_buf) |= NDIS_MAC_OPTION_TRANSFERS_NOT_PEND |
  580. NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA;
  581. * ((PULONG) info_buf) &= ~NDIS_MAC_OPTION_NO_LOOPBACK;
  582. }
  583. else if (oid == OID_PNP_CAPABILITIES && status == NDIS_STATUS_SUCCESS)
  584. {
  585. PNDIS_PNP_CAPABILITIES pnp_capabilities;
  586. PNDIS_PM_WAKE_UP_CAPABILITIES pm_struct;
  587. if (info_len >= sizeof (NDIS_PNP_CAPABILITIES))
  588. {
  589. pnp_capabilities = (PNDIS_PNP_CAPABILITIES) info_buf;
  590. pm_struct = & pnp_capabilities -> WakeUpCapabilities;
  591. pm_struct -> MinMagicPacketWakeUp = NdisDeviceStateUnspecified;
  592. pm_struct -> MinPatternWakeUp = NdisDeviceStateUnspecified;
  593. pm_struct -> MinLinkChangeWakeUp = NdisDeviceStateUnspecified;
  594. ctxtp -> prot_pnp_state = NdisDeviceStateD0;
  595. ctxtp -> nic_pnp_state = NdisDeviceStateD0;
  596. * written = sizeof (NDIS_PNP_CAPABILITIES);
  597. * needed = 0;
  598. status = NDIS_STATUS_SUCCESS;
  599. }
  600. else
  601. {
  602. * needed = sizeof (NDIS_PNP_CAPABILITIES);
  603. status = NDIS_STATUS_RESOURCES;
  604. }
  605. }
  606. Main_action_put (ctxtp, actp);
  607. }
  608. return status;
  609. } /* end Nic_info_query */
  610. NDIS_STATUS Nic_info_set (
  611. NDIS_HANDLE adapter_handle,
  612. NDIS_OID oid,
  613. PVOID info_buf,
  614. ULONG info_len,
  615. PULONG read,
  616. PULONG needed)
  617. {
  618. PMAIN_CTXT ctxtp = (PMAIN_CTXT) adapter_handle;
  619. NDIS_STATUS status;
  620. PMAIN_ACTION actp;
  621. PNDIS_REQUEST request;
  622. PMAIN_ADAPTER adapterp;
  623. UNIV_ASSERT (ctxtp -> code == MAIN_CTXT_CODE);
  624. adapterp = & (univ_adapters [ctxtp -> adapter_id]);
  625. UNIV_ASSERT (adapterp -> code == MAIN_ADAPTER_CODE);
  626. UNIV_ASSERT (adapterp -> ctxtp == ctxtp);
  627. #if defined(TRACE_OID)
  628. DbgPrint("Nic_info_set: called for %x, %x %d\n", oid, info_buf, info_len);
  629. #endif
  630. if (! adapterp -> inited)
  631. {
  632. TRACE_CRIT("%!FUNC! adapter not initialized, adapter id = 0x%x", ctxtp -> adapter_id);
  633. TRACE_INFO("<-%!FUNC! return=NDIS_STATUS_FAILURE");
  634. return NDIS_STATUS_FAILURE;
  635. }
  636. /* the Set Power should not be sent to the miniport below the Passthru,
  637. but is handled internally */
  638. if (oid == OID_PNP_SET_POWER)
  639. {
  640. NDIS_DEVICE_POWER_STATE new_pnp_state;
  641. #if defined(TRACE_OID)
  642. DbgPrint("Nic_info_set: OID_PNP_SET_POWER\n");
  643. #endif
  644. TRACE_VERB("%!FUNC! OID_PNP_SET_POWER");
  645. if (info_len >= sizeof (NDIS_DEVICE_POWER_STATE))
  646. {
  647. new_pnp_state = (* (PNDIS_DEVICE_POWER_STATE) info_buf);
  648. /* If WLBS is transitioning from an Off to On state, it must wait
  649. for all underlying miniports to be turned On */
  650. if (ctxtp->nic_pnp_state > NdisDeviceStateD0 &&
  651. new_pnp_state != NdisDeviceStateD0)
  652. {
  653. // If the miniport is in a non-D0 state, the miniport can only
  654. // receive a Set Power to D0
  655. TRACE_CRIT("%!FUNC! miniport is in a non-D0 state");
  656. TRACE_INFO("<-%!FUNC! return=NDIS_STATUS_FAILURE");
  657. return NDIS_STATUS_FAILURE;
  658. }
  659. //
  660. // Is the miniport transitioning from an On (D0) state to an Low Power State (>D0)
  661. // If so, then set the standby_state Flag - (Block all incoming requests)
  662. //
  663. if (ctxtp->nic_pnp_state == NdisDeviceStateD0 &&
  664. new_pnp_state > NdisDeviceStateD0)
  665. {
  666. ctxtp->standby_state = TRUE;
  667. }
  668. // Note: lock these *_pnp_state variables
  669. //
  670. // If the miniport is transitioning from a low power state to ON (D0), then clear the standby_state flag
  671. // All incoming requests will be pended until the physical miniport turns ON.
  672. //
  673. if (ctxtp->nic_pnp_state > NdisDeviceStateD0 &&
  674. new_pnp_state == NdisDeviceStateD0)
  675. {
  676. ctxtp->standby_state = FALSE;
  677. }
  678. ctxtp->nic_pnp_state = new_pnp_state;
  679. // Note: We should be waiting here, as we do in prot_pnp_handle
  680. // Note: Also wait for indicated packets to "return"
  681. * read = sizeof (NDIS_DEVICE_POWER_STATE);
  682. * needed = 0;
  683. TRACE_INFO("<-%!FUNC! return=NDIS_STATUS_SUCCESS");
  684. return NDIS_STATUS_SUCCESS;
  685. }
  686. else
  687. {
  688. * read = 0;
  689. * needed = sizeof (NDIS_DEVICE_POWER_STATE);
  690. TRACE_CRIT("%!FUNC! info_buf too small");
  691. TRACE_INFO("<-%!FUNC! return=NDIS_STATUS_INVALID_LENGTH");
  692. return NDIS_STATUS_INVALID_LENGTH;
  693. }
  694. }
  695. if (ctxtp -> reset_state != MAIN_RESET_NONE ||
  696. ctxtp->nic_pnp_state > NdisDeviceStateD0 ||
  697. ctxtp->standby_state)
  698. {
  699. TRACE_CRIT("%!FUNC! adapter reset or in standby, adapter id = 0x%x", ctxtp -> adapter_id);
  700. TRACE_INFO("<-%!FUNC! return=NDIS_STATUS_FAILURE");
  701. return NDIS_STATUS_FAILURE;
  702. }
  703. actp = Main_action_get (ctxtp);
  704. if (actp == NULL)
  705. {
  706. UNIV_PRINT_CRIT(("Nic_info_set: Error allocating action"));
  707. TRACE_CRIT("%!FUNC! Error allocating action");
  708. TRACE_INFO("<-%!FUNC! return=NDIS_STATUS_FAILURE");
  709. return NDIS_STATUS_FAILURE;
  710. }
  711. request = & actp -> op . request . req;
  712. request -> RequestType = NdisRequestSetInformation;
  713. request -> DATA . SET_INFORMATION . Oid = oid;
  714. /* V1.3.0b Multicast support. If protocol is setting multicast list, make sure we always
  715. add our multicast address on at the end. If the cluster IP address 0.0.0.0, then we don't
  716. want to add the multicast MAC address to the NIC - we retain the current MAC address. */
  717. if (oid == OID_802_3_MULTICAST_LIST && ctxtp -> params . mcast_support && ctxtp -> params . cl_ip_addr != 0)
  718. {
  719. ULONG size, i, len;
  720. PUCHAR ptr;
  721. UNIV_PRINT_VERB(("Nic_info_set: OID_802_3_MULTICAST_LIST"));
  722. /* search and see if our multicast address is alrady in the list */
  723. len = CVY_MAC_ADDR_LEN (ctxtp -> medium);
  724. for (i = 0; i < info_len; i += len)
  725. {
  726. if (CVY_MAC_ADDR_COMP (ctxtp -> medium, (PUCHAR) info_buf + i, & ctxtp -> cl_mac_addr))
  727. {
  728. UNIV_PRINT_VERB(("Nic_info_set: Cluster MAC matched - no need to add it"));
  729. CVY_MAC_ADDR_PRINT (ctxtp -> medium, "", & ctxtp -> cl_mac_addr);
  730. break;
  731. }
  732. else
  733. CVY_MAC_ADDR_PRINT (ctxtp -> medium, "", (PUCHAR) info_buf + i);
  734. }
  735. /* if cluster mac not found, add it to the list */
  736. if (i >= info_len)
  737. {
  738. UNIV_PRINT_VERB(("Nic_info_set: Cluster MAC not found - adding it"));
  739. CVY_MAC_ADDR_PRINT (ctxtp -> medium, "", & ctxtp -> cl_mac_addr);
  740. size = info_len + len;
  741. status = NdisAllocateMemoryWithTag (& ptr, size, UNIV_POOL_TAG);
  742. if (status != NDIS_STATUS_SUCCESS)
  743. {
  744. UNIV_PRINT_CRIT(("Nic_info_set: Error allocating space %d %x", size, status));
  745. LOG_MSG2 (MSG_ERROR_MEMORY, MSG_NONE, size, status);
  746. Main_action_put (ctxtp, actp);
  747. TRACE_CRIT("%!FUNC! Error allocating size=%d, status=0x%x", size, status);
  748. TRACE_INFO("<-%!FUNC! return=NDIS_STATUS_FAILURE");
  749. return NDIS_STATUS_FAILURE;
  750. }
  751. /* If we have allocated a new buffer to hold the multicast MAC list,
  752. note that we need to free it later when the request completes.
  753. Main_action_get initializes the buffer to NULL, so a buffer will
  754. only be freed if we explicitly store its address here. */
  755. actp->op.request.buffer = ptr;
  756. actp->op.request.buffer_len = size;
  757. CVY_MAC_ADDR_COPY (ctxtp -> medium, ptr, & ctxtp -> cl_mac_addr);
  758. NdisMoveMemory (ptr + len, info_buf, info_len);
  759. request -> DATA . SET_INFORMATION . InformationBuffer = ptr;
  760. request -> DATA . SET_INFORMATION . InformationBufferLength = size;
  761. }
  762. else
  763. {
  764. request -> DATA . SET_INFORMATION . InformationBuffer = info_buf;
  765. request -> DATA . SET_INFORMATION . InformationBufferLength = info_len;
  766. }
  767. }
  768. else
  769. {
  770. request -> DATA . SET_INFORMATION . InformationBuffer = info_buf;
  771. request -> DATA . SET_INFORMATION . InformationBufferLength = info_len;
  772. }
  773. actp -> op . request . xferred = read;
  774. actp -> op . request . needed = needed;
  775. status = Prot_request (ctxtp, actp, TRUE);
  776. if (status != NDIS_STATUS_PENDING)
  777. {
  778. /* V1.3.0b multicast support - clean up array used for storing list
  779. of multicast addresses */
  780. * read = request -> DATA . SET_INFORMATION . BytesRead;
  781. * needed = request -> DATA . SET_INFORMATION . BytesNeeded;
  782. if (request -> DATA . SET_INFORMATION . Oid == OID_802_3_MULTICAST_LIST)
  783. {
  784. /* If the request buffer is non-NULL, then we were forced to allocate a new buffer
  785. large enough to hold the entire multicast MAC address list, plus our multicast
  786. MAC address, which was missing from the list sent down by the protocol. To mask
  787. this from the protocol, free the buffer and decrease the number of bytes read
  788. by the miniport by the length of a MAC address before returning the request to
  789. the protocol. */
  790. if (actp->op.request.buffer != NULL) {
  791. NdisFreeMemory(actp->op.request.buffer, actp->op.request.buffer_len, 0);
  792. * read -= CVY_MAC_ADDR_LEN (ctxtp -> medium);
  793. }
  794. }
  795. #if defined (NLB_TCP_NOTIFICATION)
  796. else if (request->DATA.SET_INFORMATION.Oid == OID_GEN_NETWORK_LAYER_ADDRESSES)
  797. {
  798. /* Schedule an NDIS work item to get the interface index of this NLB
  799. instance from TCP/IP by querying the IP address table. */
  800. (VOID)Main_schedule_work_item(ctxtp, Main_set_interface_index);
  801. /* Overwrite the status from the request. We will ALWAYS succeed this OID,
  802. lest the protocol decide to stop sending it down to us. See the DDK. */
  803. status = NDIS_STATUS_SUCCESS;
  804. }
  805. #endif
  806. #if defined(TRACE_OID)
  807. DbgPrint("Nic_info_set: done %x, %d %d\n", status, * read, * needed);
  808. #endif
  809. Main_action_put (ctxtp, actp);
  810. }
  811. TRACE_INFO("<-%!FUNC! return=0x%x", status);
  812. return status;
  813. } /* end Nic_info_set */
  814. NDIS_STATUS Nic_reset (
  815. PBOOLEAN addr_reset,
  816. NDIS_HANDLE adapter_handle)
  817. {
  818. PMAIN_CTXT ctxtp = (PMAIN_CTXT) adapter_handle;
  819. NDIS_STATUS status;
  820. PMAIN_ADAPTER adapterp;
  821. UNIV_ASSERT (ctxtp -> code == MAIN_CTXT_CODE);
  822. adapterp = & (univ_adapters [ctxtp -> adapter_id]);
  823. UNIV_ASSERT (adapterp -> code == MAIN_ADAPTER_CODE);
  824. if (! adapterp -> inited)
  825. {
  826. TRACE_CRIT("%!FUNC! adapter not initialized");
  827. TRACE_INFO("<-%!FUNC! return=NDIS_STATUS_FAILURE");
  828. return NDIS_STATUS_FAILURE;
  829. }
  830. UNIV_PRINT_VERB(("Nic_reset: Called"));
  831. /* since no information needs to be passed to Prot_reset,
  832. action is not allocated. Prot_reset_complete will get
  833. one and pass it to Nic_reset_complete */
  834. status = Prot_reset (ctxtp);
  835. if (status != NDIS_STATUS_SUCCESS && status != NDIS_STATUS_PENDING)
  836. {
  837. UNIV_PRINT_CRIT(("Nic_reset: Error resetting adapter, status=0x%x", status));
  838. TRACE_CRIT("%!FUNC! Error resetting adapter, status=0x%x", status);
  839. }
  840. TRACE_INFO("<-%!FUNC! return=0x%x", status);
  841. return status;
  842. } /* end Nic_reset */
  843. VOID Nic_cancel_send_packets (
  844. NDIS_HANDLE adapter_handle,
  845. PVOID cancel_id)
  846. {
  847. PMAIN_CTXT ctxtp = (PMAIN_CTXT) adapter_handle;
  848. PMAIN_ADAPTER adapterp;
  849. UNIV_ASSERT (ctxtp -> code == MAIN_CTXT_CODE);
  850. adapterp = & (univ_adapters [ctxtp -> adapter_id]);
  851. UNIV_ASSERT (adapterp -> code == MAIN_ADAPTER_CODE);
  852. /* Since no internal queues are maintained,
  853. * can simply pass the cancel call to the miniport
  854. */
  855. Prot_cancel_send_packets (ctxtp, cancel_id);
  856. TRACE_INFO("<-%!FUNC! return");
  857. return;
  858. } /* Nic_cancel_send_packets */
  859. VOID Nic_pnpevent_notify (
  860. NDIS_HANDLE adapter_handle,
  861. NDIS_DEVICE_PNP_EVENT pnp_event,
  862. PVOID info_buf,
  863. ULONG info_len)
  864. {
  865. PMAIN_CTXT ctxtp = (PMAIN_CTXT) adapter_handle;
  866. UNIV_ASSERT (ctxtp -> code == MAIN_CTXT_CODE);
  867. return;
  868. } /* Nic_pnpevent_notify */
  869. VOID Nic_adapter_shutdown (
  870. NDIS_HANDLE adapter_handle)
  871. {
  872. PMAIN_CTXT ctxtp = (PMAIN_CTXT) adapter_handle;
  873. UNIV_ASSERT (ctxtp -> code == MAIN_CTXT_CODE);
  874. return;
  875. } /* Nic_adapter_shutdown */
  876. /* helpers for protocol layer */
  877. NDIS_STATUS Nic_announce (
  878. PMAIN_CTXT ctxtp)
  879. {
  880. NDIS_STATUS status;
  881. NDIS_STRING nic_name;
  882. UNIV_ASSERT (ctxtp -> code == MAIN_CTXT_CODE);
  883. /* create the name to expose to TCP/IP protocol and call NDIS to force
  884. TCP/IP to bind to us */
  885. NdisInitUnicodeString (& nic_name, ctxtp -> virtual_nic_name);
  886. /* Called from Prot_bind at PASSIVE_LEVEL - %ls is OK. */
  887. UNIV_PRINT_INFO(("Nic_announce: Exposing %ls, %ls", nic_name . Buffer, ctxtp -> virtual_nic_name));
  888. status = NdisIMInitializeDeviceInstanceEx (univ_driver_handle, & nic_name, (NDIS_HANDLE) ctxtp);
  889. if (status != NDIS_STATUS_SUCCESS)
  890. {
  891. UNIV_PRINT_CRIT(("Nic_announce: Error announcing driver %x", status));
  892. __LOG_MSG1 (MSG_ERROR_ANNOUNCE, nic_name . Buffer + (wcslen(L"\\DEVICE\\") * sizeof(WCHAR)), status);
  893. }
  894. UNIV_PRINT_INFO(("Nic_announce: return=0x%x", status));
  895. return status;
  896. } /* end Nic_announce */
  897. NDIS_STATUS Nic_unannounce (
  898. PMAIN_CTXT ctxtp)
  899. {
  900. NDIS_STATUS status;
  901. NDIS_STRING nic_name;
  902. PMAIN_ADAPTER adapterp;
  903. UNIV_ASSERT (ctxtp -> code == MAIN_CTXT_CODE);
  904. adapterp = & (univ_adapters [ctxtp -> adapter_id]);
  905. UNIV_ASSERT (adapterp -> code == MAIN_ADAPTER_CODE);
  906. UNIV_ASSERT (adapterp -> ctxtp == ctxtp);
  907. NdisAcquireSpinLock(& univ_bind_lock);
  908. if (! adapterp -> announced || ctxtp -> prot_handle == NULL)
  909. {
  910. adapterp -> announced = FALSE;
  911. ctxtp->prot_handle = NULL;
  912. NdisReleaseSpinLock(& univ_bind_lock);
  913. NdisInitUnicodeString (& nic_name, ctxtp -> virtual_nic_name);
  914. /* Called from Prot_unbind at PASSIVE_LEVEL - %ls is OK. */
  915. UNIV_PRINT_INFO(("Nic_unannounce: Cancelling %ls, %ls", nic_name . Buffer, ctxtp -> virtual_nic_name));
  916. status = NdisIMCancelInitializeDeviceInstance (univ_driver_handle, & nic_name);
  917. if (status != NDIS_STATUS_SUCCESS)
  918. {
  919. UNIV_PRINT_CRIT(("Nic_unannounce: Error cancelling driver %x", status));
  920. __LOG_MSG1 (MSG_ERROR_ANNOUNCE, nic_name . Buffer + (wcslen(L"\\DEVICE\\") * sizeof(WCHAR)), status);
  921. TRACE_CRIT("%!FUNC! Error cancelling driver status=0x%x", status);
  922. }
  923. UNIV_PRINT_INFO(("Nic_unannounce: return=NDIS_STATUS_SUCCESS"));
  924. TRACE_INFO("<-%!FUNC! return=NDIS_STATUS_SUCCESS");
  925. return NDIS_STATUS_SUCCESS;
  926. }
  927. NdisReleaseSpinLock(& univ_bind_lock);
  928. UNIV_PRINT_INFO(("Nic_unannounce: Calling DeinitializeDeviceInstance"));
  929. TRACE_INFO("%!FUNC! Calling DeinitializeDeviceInstance");
  930. status = NdisIMDeInitializeDeviceInstance (ctxtp -> prot_handle);
  931. UNIV_PRINT_INFO(("Nic_unannounce: return=0x%x", status));
  932. TRACE_INFO("<-%!FUNC! return=0x%x", status);
  933. return status;
  934. } /* end Nic_unannounce */
  935. /* routines that can be used with Nic_sync */
  936. VOID Nic_request_complete (
  937. NDIS_HANDLE handle,
  938. PVOID cookie)
  939. {
  940. PMAIN_ACTION actp = (PMAIN_ACTION) cookie;
  941. PMAIN_CTXT ctxtp = actp -> ctxtp;
  942. NDIS_STATUS status = actp -> status;
  943. PNDIS_REQUEST request = & actp -> op . request . req;
  944. PULONG ptr;
  945. ULONG oid;
  946. UNIV_ASSERT (ctxtp -> code == MAIN_CTXT_CODE);
  947. if (request -> RequestType == NdisRequestSetInformation)
  948. {
  949. UNIV_ASSERT (request -> DATA . SET_INFORMATION . Oid != OID_PNP_SET_POWER);
  950. * actp -> op . request . xferred =
  951. request -> DATA . SET_INFORMATION . BytesRead;
  952. * actp -> op . request . needed =
  953. request -> DATA . SET_INFORMATION . BytesNeeded;
  954. #if defined(TRACE_OID)
  955. DbgPrint("Nic_request_complete: set done %x, %d %d\n", status, * actp -> op . request . xferred, * actp -> op . request . needed);
  956. #endif
  957. TRACE_VERB("%!FUNC! set done status=0x%x, xferred=%d, needed=%d", status, * actp -> op . request . xferred, * actp -> op . request . needed);
  958. /* V1.3.0b multicast support - free multicast list array */
  959. if (request -> DATA . SET_INFORMATION . Oid == OID_802_3_MULTICAST_LIST)
  960. {
  961. /* If the request buffer is non-NULL, then we were forced to allocate a new buffer
  962. large enough to hold the entire multicast MAC address list, plus our multicast
  963. MAC address, which was missing from the list sent down by the protocol. To mask
  964. this from the protocol, free the buffer and decrease the number of bytes read
  965. by the miniport by the length of a MAC address before returning the request to
  966. the protocol. */
  967. if (actp->op.request.buffer != NULL) {
  968. if (status != NDIS_STATUS_SUCCESS)
  969. {
  970. UNIV_PRINT_CRIT(("Nic_request_complete: Error setting multicast list, status=0x%x", status));
  971. TRACE_CRIT("%!FUNC! Error setting multicast list, status=0x%x", status);
  972. }
  973. NdisFreeMemory(actp->op.request.buffer, actp->op.request.buffer_len, 0);
  974. * actp -> op . request . xferred -= CVY_MAC_ADDR_LEN (ctxtp -> medium);
  975. }
  976. }
  977. #if defined (NLB_TCP_NOTIFICATION)
  978. else if (request->DATA.SET_INFORMATION.Oid == OID_GEN_NETWORK_LAYER_ADDRESSES)
  979. {
  980. /* Schedule an NDIS work item to get the interface index of this NLB
  981. instance from TCP/IP by querying the IP address table. */
  982. (VOID)Main_schedule_work_item(ctxtp, Main_set_interface_index);
  983. /* Overwrite the status from the request. We will ALWAYS succeed this OID,
  984. lest the protocol decide to stop sending it down to us. See the DDK. */
  985. status = NDIS_STATUS_SUCCESS;
  986. }
  987. #endif
  988. NdisMSetInformationComplete (ctxtp -> prot_handle, status);
  989. }
  990. else if (request -> RequestType == NdisRequestQueryInformation)
  991. {
  992. * actp -> op . request . xferred =
  993. request -> DATA . QUERY_INFORMATION . BytesWritten;
  994. * actp -> op . request . needed =
  995. request -> DATA . QUERY_INFORMATION . BytesNeeded;
  996. #if defined(TRACE_OID)
  997. DbgPrint("Nic_request_complete: query done %x, %d %d\n", status, * actp -> op . request . xferred, * actp -> op . request . needed);
  998. #endif
  999. oid = request -> DATA . QUERY_INFORMATION . Oid;
  1000. ptr = ((PULONG) request -> DATA . QUERY_INFORMATION . InformationBuffer);
  1001. /* override certain oid values with our own */
  1002. if (oid == OID_GEN_MAXIMUM_SEND_PACKETS &&
  1003. request -> DATA . QUERY_INFORMATION . InformationBufferLength >=
  1004. sizeof (ULONG))
  1005. {
  1006. * ptr = CVY_MAX_SEND_PACKETS;
  1007. * actp -> op . request . xferred = sizeof (ULONG);
  1008. status = NDIS_STATUS_SUCCESS;
  1009. }
  1010. else if (oid == OID_802_3_CURRENT_ADDRESS && status == NDIS_STATUS_SUCCESS)
  1011. {
  1012. if (request->DATA.QUERY_INFORMATION.InformationBufferLength >= sizeof(CVY_MAC_ADR)) {
  1013. if (!ctxtp->params.mcast_support && ctxtp->cl_ip_addr != 0)
  1014. NdisMoveMemory(ptr, &ctxtp->cl_mac_addr, sizeof(CVY_MAC_ADR));
  1015. else
  1016. NdisMoveMemory(ptr, &ctxtp->ded_mac_addr, sizeof(CVY_MAC_ADR));
  1017. *actp->op.request.xferred = sizeof(CVY_MAC_ADR);
  1018. } else {
  1019. UNIV_PRINT_CRIT(("Nic_request_complete: MAC address buffer too small (%u) - not spoofing", request->DATA.QUERY_INFORMATION.InformationBufferLength));
  1020. }
  1021. }
  1022. else if (oid == OID_GEN_MAC_OPTIONS && status == NDIS_STATUS_SUCCESS)
  1023. {
  1024. * ptr |= NDIS_MAC_OPTION_TRANSFERS_NOT_PEND |
  1025. NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA;
  1026. * ptr &= ~NDIS_MAC_OPTION_NO_LOOPBACK;
  1027. }
  1028. else if (oid == OID_PNP_CAPABILITIES && status == NDIS_STATUS_SUCCESS)
  1029. {
  1030. PNDIS_PNP_CAPABILITIES pnp_capabilities;
  1031. PNDIS_PM_WAKE_UP_CAPABILITIES pm_struct;
  1032. if (request -> DATA . QUERY_INFORMATION . InformationBufferLength >=
  1033. sizeof (NDIS_PNP_CAPABILITIES))
  1034. {
  1035. pnp_capabilities = (PNDIS_PNP_CAPABILITIES) ptr;
  1036. pm_struct = & pnp_capabilities -> WakeUpCapabilities;
  1037. pm_struct -> MinMagicPacketWakeUp = NdisDeviceStateUnspecified;
  1038. pm_struct -> MinPatternWakeUp = NdisDeviceStateUnspecified;
  1039. pm_struct -> MinLinkChangeWakeUp = NdisDeviceStateUnspecified;
  1040. ctxtp -> prot_pnp_state = NdisDeviceStateD0;
  1041. ctxtp -> nic_pnp_state = NdisDeviceStateD0;
  1042. * actp -> op . request . xferred = sizeof (NDIS_PNP_CAPABILITIES);
  1043. * actp -> op . request . needed = 0;
  1044. status = NDIS_STATUS_SUCCESS;
  1045. }
  1046. else
  1047. {
  1048. * actp -> op . request . needed = sizeof (NDIS_PNP_CAPABILITIES);
  1049. status = NDIS_STATUS_RESOURCES;
  1050. }
  1051. }
  1052. NdisMQueryInformationComplete (ctxtp -> prot_handle, status);
  1053. }
  1054. else
  1055. {
  1056. UNIV_PRINT_CRIT(("Nic_request_complete: Strange request completion %x\n", request -> RequestType));
  1057. TRACE_CRIT("%!FUNC! Strange request completion 0x%x", request -> RequestType);
  1058. }
  1059. Main_action_put (ctxtp, actp);
  1060. } /* end Nic_request_complete */
  1061. VOID Nic_reset_complete (
  1062. PMAIN_CTXT ctxtp,
  1063. NDIS_STATUS status)
  1064. {
  1065. TRACE_INFO("->%!FUNC!");
  1066. if (status != NDIS_STATUS_SUCCESS)
  1067. {
  1068. UNIV_PRINT_CRIT(("Nic_reset_complete: Error resetting adapter %x", status));
  1069. TRACE_CRIT("%!FUNC! Error resetting adapter 0x%x", status);
  1070. }
  1071. NdisMResetComplete (ctxtp -> prot_handle, status, TRUE);
  1072. TRACE_INFO("<-%!FUNC! return");
  1073. } /* end Nic_reset_complete */
  1074. VOID Nic_send_complete (
  1075. PMAIN_CTXT ctxtp,
  1076. NDIS_STATUS status,
  1077. PNDIS_PACKET packet)
  1078. {
  1079. UNIV_ASSERT (ctxtp -> code == MAIN_CTXT_CODE);
  1080. if (status != NDIS_STATUS_SUCCESS)
  1081. {
  1082. UNIV_PRINT_CRIT(("Nic_send_complete: Error sending to adapter %x", status));
  1083. TRACE_CRIT("%!FUNC! Error sending to adapter 0x%x", status);
  1084. }
  1085. // ctxtp -> sends_completed ++;
  1086. NdisMSendComplete (ctxtp -> prot_handle, packet, status);
  1087. } /* end Nic_send_complete */
  1088. VOID Nic_recv_complete ( /* PASSIVE_IRQL */
  1089. PMAIN_CTXT ctxtp)
  1090. {
  1091. UNIV_ASSERT (ctxtp -> code == MAIN_CTXT_CODE);
  1092. UNIV_ASSERT (ctxtp -> medium == NdisMedium802_3);
  1093. NdisMEthIndicateReceiveComplete (ctxtp -> prot_handle);
  1094. } /* end Nic_recv_complete */
  1095. VOID Nic_send_resources_signal (
  1096. PMAIN_CTXT ctxtp)
  1097. {
  1098. UNIV_ASSERT (ctxtp -> code == MAIN_CTXT_CODE);
  1099. UNIV_PRINT_VERB(("Nic_send_resources_signal: Signalling send resources available"));
  1100. NdisMSendResourcesAvailable (ctxtp -> prot_handle);
  1101. } /* end Nic_send_resources_signal */
  1102. NDIS_STATUS Nic_PNP_handle (
  1103. PMAIN_CTXT ctxtp,
  1104. PNET_PNP_EVENT pnp_event)
  1105. {
  1106. NDIS_STATUS status;
  1107. TRACE_INFO("->%!FUNC!");
  1108. UNIV_ASSERT (ctxtp -> code == MAIN_CTXT_CODE);
  1109. if (ctxtp -> prot_handle != NULL)
  1110. {
  1111. status = NdisIMNotifyPnPEvent (ctxtp -> prot_handle, pnp_event);
  1112. }
  1113. else
  1114. {
  1115. status = NDIS_STATUS_SUCCESS;
  1116. }
  1117. UNIV_PRINT_VERB(("Nic_PNP_handle: status 0x%x", status));
  1118. TRACE_INFO("<-%!FUNC! return=0x%x", status);
  1119. return status;
  1120. }
  1121. VOID Nic_status (
  1122. PMAIN_CTXT ctxtp,
  1123. NDIS_STATUS status,
  1124. PVOID buf,
  1125. UINT len)
  1126. {
  1127. UNIV_ASSERT (ctxtp -> code == MAIN_CTXT_CODE);
  1128. UNIV_PRINT_VERB(("Nic_status: Status indicated %x", status));
  1129. NdisMIndicateStatus (ctxtp -> prot_handle, status, buf, len);
  1130. } /* end Nic_status */
  1131. VOID Nic_status_complete (
  1132. PMAIN_CTXT ctxtp)
  1133. {
  1134. UNIV_ASSERT (ctxtp -> code == MAIN_CTXT_CODE);
  1135. NdisMIndicateStatusComplete (ctxtp -> prot_handle);
  1136. } /* end Nic_status_complete */
  1137. VOID Nic_packets_send (
  1138. NDIS_HANDLE adapter_handle,
  1139. PPNDIS_PACKET packets,
  1140. UINT num_packets)
  1141. {
  1142. PMAIN_CTXT ctxtp = (PMAIN_CTXT) adapter_handle;
  1143. NDIS_STATUS status;
  1144. PMAIN_ADAPTER adapterp;
  1145. /* V1.1.4 */
  1146. UNIV_ASSERT (ctxtp -> code == MAIN_CTXT_CODE);
  1147. adapterp = & (univ_adapters [ctxtp -> adapter_id]);
  1148. UNIV_ASSERT (adapterp -> code == MAIN_ADAPTER_CODE);
  1149. UNIV_ASSERT (adapterp -> ctxtp == ctxtp);
  1150. if (! adapterp -> inited)
  1151. {
  1152. // ctxtp -> uninited_return += num_packets;
  1153. TRACE_CRIT("%!FUNC! adapter not initialized");
  1154. return;
  1155. }
  1156. // ctxtp -> sends_in ++;
  1157. Prot_packets_send (ctxtp, packets, num_packets);
  1158. } /* end Nic_packets_send */
  1159. VOID Nic_return (
  1160. NDIS_HANDLE adapter_handle,
  1161. PNDIS_PACKET packet)
  1162. {
  1163. PMAIN_CTXT ctxtp = (PMAIN_CTXT) adapter_handle;
  1164. PMAIN_ADAPTER adapterp;
  1165. UNIV_ASSERT (ctxtp -> code == MAIN_CTXT_CODE);
  1166. adapterp = & (univ_adapters [ctxtp -> adapter_id]);
  1167. UNIV_ASSERT (adapterp -> code == MAIN_ADAPTER_CODE);
  1168. UNIV_ASSERT (adapterp -> ctxtp == ctxtp);
  1169. Prot_return (ctxtp, packet);
  1170. } /* end Nic_return */
  1171. /* would be called by Prot_packet_recv */
  1172. VOID Nic_recv_packet (
  1173. PMAIN_CTXT ctxtp,
  1174. PNDIS_PACKET packet)
  1175. {
  1176. NDIS_STATUS status;
  1177. UNIV_ASSERT (ctxtp -> code == MAIN_CTXT_CODE);
  1178. status = NDIS_GET_PACKET_STATUS (packet);
  1179. NdisMIndicateReceivePacket (ctxtp -> prot_handle, & packet, 1);
  1180. if (status == NDIS_STATUS_RESOURCES)
  1181. Prot_return (ctxtp, packet);
  1182. } /* end Nic_recv_packet */
  1183. VOID Nic_timer (
  1184. PVOID dpc,
  1185. PVOID cp,
  1186. PVOID arg1,
  1187. PVOID arg2)
  1188. {
  1189. PMAIN_CTXT ctxtp = cp;
  1190. PMAIN_ADAPTER adapterp;
  1191. ULONG tout;
  1192. UNIV_ASSERT(ctxtp->code == MAIN_CTXT_CODE);
  1193. adapterp = &(univ_adapters[ctxtp->adapter_id]);
  1194. UNIV_ASSERT(adapterp->code == MAIN_ADAPTER_CODE);
  1195. UNIV_ASSERT(adapterp->ctxtp == ctxtp);
  1196. /* If the adapter is not initialized at this point, then we can't process
  1197. the timeout, so just reset the timer and bail out. Note: this should
  1198. NEVER happen, as the context is always initialized BEFORE the timer is
  1199. set and the timer is always cancelled BEFORE the context is de-initialized. */
  1200. if (!adapterp->inited) {
  1201. UNIV_PRINT_CRIT(("Nic_timer: Adapter not initialized. Bailing out without resetting the heartbeat timer."));
  1202. TRACE_CRIT("%!FUNC! Adapter not initialized. Bailing out without resetting the heartbeat timer.");
  1203. return;
  1204. }
  1205. /* Initialize tout to the current heartbeat timeout. */
  1206. tout = ctxtp->curr_tout;
  1207. /* Handle the heartbeat timer. */
  1208. Main_ping(ctxtp, &tout);
  1209. NdisAcquireSpinLock(&univ_bind_lock);
  1210. /* If the adapter is not announced anymore, then we don't want to reset the timer. */
  1211. if (!adapterp->announced) {
  1212. UNIV_PRINT_CRIT(("Nic_timer: Adapter not announced. Bailing out without resetting the heartbeat timer."));
  1213. TRACE_CRIT("%!FUNC! Adapter not announced. Bailing out without resetting the heartbeat timer.");
  1214. NdisReleaseSpinLock(&univ_bind_lock);
  1215. return;
  1216. }
  1217. /* Cache the next timeout value specified by the load module and use it to
  1218. reset the timer for the next heartbeat timeout. */
  1219. ctxtp->curr_tout = tout;
  1220. NdisMSetTimer((PNDIS_MINIPORT_TIMER)ctxtp->timer, tout);
  1221. NdisReleaseSpinLock(&univ_bind_lock);
  1222. }
  1223. VOID Nic_sleep (
  1224. ULONG msecs)
  1225. {
  1226. NdisMSleep(msecs);
  1227. } /* end Nic_sleep */
  1228. /* Added from old code for NT 5.1 - ramkrish */
  1229. VOID Nic_recv_indicate (
  1230. PMAIN_CTXT ctxtp,
  1231. NDIS_HANDLE recv_handle,
  1232. PVOID head_buf,
  1233. UINT head_len,
  1234. PVOID look_buf,
  1235. UINT look_len,
  1236. UINT packet_len)
  1237. {
  1238. UNIV_ASSERT (ctxtp -> code == MAIN_CTXT_CODE);
  1239. /* V1.1.2 do not accept frames if the card below is resetting */
  1240. if (ctxtp -> reset_state != MAIN_RESET_NONE)
  1241. {
  1242. TRACE_CRIT("%!FUNC! adapter was reset");
  1243. return;
  1244. }
  1245. UNIV_ASSERT (ctxtp -> medium == NdisMedium802_3);
  1246. NdisMEthIndicateReceive (ctxtp -> prot_handle,
  1247. recv_handle,
  1248. head_buf,
  1249. head_len,
  1250. look_buf,
  1251. look_len,
  1252. packet_len);
  1253. } /* end Nic_recv_indicate */
  1254. NDIS_STATUS Nic_transfer (
  1255. PNDIS_PACKET packet,
  1256. PUINT xferred,
  1257. NDIS_HANDLE adapter_handle,
  1258. NDIS_HANDLE receive_handle,
  1259. UINT offset,
  1260. UINT len)
  1261. {
  1262. PMAIN_CTXT ctxtp = (PMAIN_CTXT) adapter_handle;
  1263. NDIS_STATUS status;
  1264. UNIV_ASSERT (ctxtp -> code == MAIN_CTXT_CODE);
  1265. status = Prot_transfer (ctxtp, receive_handle, packet, offset, len, xferred);
  1266. if (status != NDIS_STATUS_PENDING && status != NDIS_STATUS_SUCCESS)
  1267. {
  1268. UNIV_PRINT_CRIT(("Nic_transfer: Error transferring from adapter %x", status));
  1269. TRACE_CRIT("%!FUNC! error transferring from adapter 0x%x", status);
  1270. }
  1271. return status;
  1272. } /* end Nic_transfer */
  1273. VOID Nic_transfer_complete (
  1274. PMAIN_CTXT ctxtp,
  1275. NDIS_STATUS status,
  1276. PNDIS_PACKET packet,
  1277. UINT xferred)
  1278. {
  1279. UNIV_ASSERT (ctxtp -> code == MAIN_CTXT_CODE);
  1280. if (status != NDIS_STATUS_SUCCESS)
  1281. {
  1282. UNIV_PRINT_CRIT(("Nic_transfer: Error transferring from adapter %x", status));
  1283. TRACE_CRIT("%!FUNC! error transferring from adapter 0x%x", status);
  1284. }
  1285. NdisMTransferDataComplete (ctxtp -> prot_handle, packet, status, xferred);
  1286. } /* end Nic_transfer_complete */