]> git.proxmox.com Git - mirror_edk2.git/blame - Nt32Pkg/SnpNt32Dxe/SnpNt32.c
IntelFrameworkModulePkg: Refine casting expression result to bigger size
[mirror_edk2.git] / Nt32Pkg / SnpNt32Dxe / SnpNt32.c
CommitLineData
593a8308 1/** @file\r
2\r
a2cc5fea 3Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
8f2a5f80 4This program and the accompanying materials\r
593a8308 5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 SnpNt32.c\r
15\r
16Abstract:\r
17\r
18-**/\r
19\r
20#include "SnpNt32.h"\r
21\r
22EFI_DRIVER_BINDING_PROTOCOL gSnpNt32DriverBinding = {\r
23 SnpNt32DriverBindingSupported,\r
24 SnpNt32DriverBindingStart,\r
25 SnpNt32DriverBindingStop,\r
26 0xa,\r
27 NULL,\r
28 NULL\r
29};\r
30\r
31SNPNT32_GLOBAL_DATA gSnpNt32GlobalData = {\r
32 SNP_NT32_DRIVER_SIGNATURE, // Signature\r
33 {\r
34 NULL,\r
35 NULL\r
36 }, // InstanceList\r
37 NULL, // WinNtThunk\r
38 NULL, // NetworkLibraryHandle\r
39 {\r
40 0\r
41 }, // NtNetUtilityTable\r
42 {\r
43 0,\r
44 0,\r
a00ec39b 45 EfiLockUninitialized\r
593a8308 46 }, // Lock\r
a2cc5fea
ZL
47 NULL, // RecycledTxBuf\r
48 0, // RecycledTxBufCount\r
49 32, // MaxRecycledTxBuf\r
593a8308 50 //\r
51 // Private functions\r
52 //\r
53 SnpNt32InitializeGlobalData, // InitializeGlobalData\r
54 SnpNt32InitializeInstanceData, // InitializeInstanceData\r
55 SnpNt32CloseInstance // CloseInstance\r
56};\r
57\r
531237a5 58/**\r
59 Changes the state of a network interface from "stopped" to "started".\r
60\r
61 @param This Protocol instance pointer.\r
62\r
63 @retval EFI_SUCCESS Always succeeds.\r
64\r
65**/\r
66EFI_STATUS\r
67EFIAPI\r
68SnpNt32Start (\r
69 IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r
70 );\r
71 \r
72/**\r
73 Changes the state of a network interface from "started" to "stopped".\r
74\r
75 @param This Protocol instance pointer.\r
76\r
77 @retval EFI_SUCCESS Always succeeds.\r
78\r
79**/\r
80EFI_STATUS\r
81EFIAPI\r
82SnpNt32Stop (\r
83 IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r
84 );\r
85 \r
86/**\r
87 Resets a network adapter and allocates the transmit and receive buffers \r
88 required by the network interface; optionally, also requests allocation \r
89 of additional transmit and receive buffers.\r
90\r
91 @param This Protocol instance pointer.\r
92 @param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space\r
93 that the driver should allocate for the network interface.\r
94 Some network interfaces will not be able to use the extra\r
95 buffer, and the caller will not know if it is actually\r
96 being used.\r
97 @param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space\r
98 that the driver should allocate for the network interface.\r
99 Some network interfaces will not be able to use the extra\r
100 buffer, and the caller will not know if it is actually\r
101 being used.\r
102\r
103 @retval EFI_SUCCESS Always succeeds.\r
104\r
105**/\r
106EFI_STATUS\r
107EFIAPI\r
108SnpNt32Initialize (\r
109 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
110 IN UINTN ExtraRxBufferSize OPTIONAL,\r
111 IN UINTN ExtraTxBufferSize OPTIONAL\r
112 );\r
113 \r
114/**\r
115 Resets a network adapter and re-initializes it with the parameters that were \r
116 provided in the previous call to Initialize(). \r
117\r
118 @param This Protocol instance pointer.\r
119 @param ExtendedVerification Indicates that the driver may perform a more\r
120 exhaustive verification operation of the device\r
121 during reset.\r
122\r
123 @retval EFI_SUCCESS Always succeeds.\r
124\r
125**/\r
126EFI_STATUS\r
127EFIAPI\r
128SnpNt32Reset (\r
129 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
130 IN BOOLEAN ExtendedVerification\r
131 );\r
132\r
133/**\r
134 Resets a network adapter and leaves it in a state that is safe for \r
135 another driver to initialize.\r
136\r
137 @param This Protocol instance pointer.\r
138\r
139 @retval EFI_SUCCESS Always succeeds.\r
140\r
141**/\r
142EFI_STATUS\r
143EFIAPI\r
144SnpNt32Shutdown (\r
145 IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r
146 );\r
147\r
148/**\r
149 Manages the multicast receive filters of a network interface.\r
150\r
151 @param This Protocol instance pointer.\r
152 @param EnableBits A bit mask of receive filters to enable on the network interface.\r
153 @param DisableBits A bit mask of receive filters to disable on the network interface.\r
154 @param ResetMcastFilter Set to TRUE to reset the contents of the multicast receive\r
155 filters on the network interface to their default values.\r
156 @param McastFilterCount Number of multicast HW MAC addresses in the new\r
157 MCastFilter list. This value must be less than or equal to\r
158 the MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE. This\r
159 field is optional if ResetMCastFilter is TRUE.\r
160 @param McastFilter A pointer to a list of new multicast receive filter HW MAC\r
161 addresses. This list will replace any existing multicast\r
162 HW MAC address list. This field is optional if\r
163 ResetMCastFilter is TRUE.\r
164\r
165 @retval EFI_SUCCESS The multicast receive filter list was updated.\r
166 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r
167\r
168**/\r
169EFI_STATUS\r
170EFIAPI\r
171SnpNt32ReceiveFilters (\r
172 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
173 IN UINT32 EnableBits,\r
174 IN UINT32 DisableBits,\r
175 IN BOOLEAN ResetMcastFilter,\r
176 IN UINTN McastFilterCount OPTIONAL,\r
177 IN EFI_MAC_ADDRESS *McastFilter OPTIONAL\r
178 );\r
179\r
180/**\r
181 Modifies or resets the current station address, if supported.\r
182\r
183 @param This Protocol instance pointer.\r
184 @param Reset Flag used to reset the station address to the network interfaces\r
185 permanent address.\r
186 @param NewMacAddr New station address to be used for the network interface.\r
187\r
188 @retval EFI_UNSUPPORTED Not supported yet.\r
189\r
190**/\r
191EFI_STATUS\r
192EFIAPI\r
193SnpNt32StationAddress (\r
194 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
195 IN BOOLEAN Reset,\r
196 IN EFI_MAC_ADDRESS *NewMacAddr OPTIONAL\r
197 );\r
198\r
199/**\r
200 Resets or collects the statistics on a network interface.\r
201\r
202 @param This Protocol instance pointer.\r
203 @param Reset Set to TRUE to reset the statistics for the network interface.\r
204 @param StatisticsSize On input the size, in bytes, of StatisticsTable. On\r
205 output the size, in bytes, of the resulting table of\r
206 statistics.\r
207 @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that\r
208 contains the statistics.\r
209\r
210 @retval EFI_SUCCESS The statistics were collected from the network interface.\r
211 @retval EFI_NOT_STARTED The network interface has not been started.\r
212 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer\r
213 size needed to hold the statistics is returned in\r
214 StatisticsSize.\r
215 @retval EFI_UNSUPPORTED Not supported yet.\r
216\r
217**/\r
218EFI_STATUS\r
219EFIAPI\r
220SnpNt32Statistics (\r
221 IN EFI_SIMPLE_NETWORK_PROTOCOL * This,\r
222 IN BOOLEAN Reset,\r
223 IN OUT UINTN *StatisticsSize OPTIONAL,\r
224 OUT EFI_NETWORK_STATISTICS *StatisticsTable OPTIONAL\r
225 );\r
226 \r
227/**\r
228 Converts a multicast IP address to a multicast HW MAC address.\r
229 \r
230 @param This Protocol instance pointer.\r
231 @param Ipv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set\r
232 to FALSE if the multicast IP address is IPv4 [RFC 791].\r
233 @param Ip The multicast IP address that is to be converted to a multicast\r
234 HW MAC address.\r
235 @param Mac The multicast HW MAC address that is to be generated from IP.\r
236\r
237 @retval EFI_SUCCESS The multicast IP address was mapped to the multicast\r
238 HW MAC address.\r
239 @retval EFI_NOT_STARTED The network interface has not been started.\r
240 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer\r
241 size needed to hold the statistics is returned in\r
242 StatisticsSize.\r
243 @retval EFI_UNSUPPORTED Not supported yet.\r
244\r
245**/\r
246EFI_STATUS\r
247EFIAPI\r
248SnpNt32McastIptoMac (\r
249 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
250 IN BOOLEAN Ipv6,\r
251 IN EFI_IP_ADDRESS *Ip,\r
252 OUT EFI_MAC_ADDRESS *Mac\r
253 );\r
254\r
255/**\r
256 Performs read and write operations on the NVRAM device attached to a \r
257 network interface.\r
258\r
259 @param This Protocol instance pointer.\r
260 @param ReadOrWrite TRUE for read operations, FALSE for write operations.\r
261 @param Offset Byte offset in the NVRAM device at which to start the read or\r
262 write operation. This must be a multiple of NvRamAccessSize and\r
263 less than NvRamSize.\r
264 @param BufferSize The number of bytes to read or write from the NVRAM device.\r
265 This must also be a multiple of NvramAccessSize.\r
266 @param Buffer A pointer to the data buffer.\r
267\r
268 @retval EFI_UNSUPPORTED Not supported yet.\r
269\r
270**/\r
271EFI_STATUS\r
272EFIAPI\r
273SnpNt32Nvdata (\r
274 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
275 IN BOOLEAN ReadOrWrite,\r
276 IN UINTN Offset,\r
277 IN UINTN BufferSize,\r
278 IN OUT VOID *Buffer\r
279 );\r
280\r
281/**\r
282 Reads the current interrupt status and recycled transmit buffer status from \r
283 a network interface.\r
284\r
285 @param This Protocol instance pointer.\r
286 @param InterruptStatus A pointer to the bit mask of the currently active interrupts\r
287 If this is NULL, the interrupt status will not be read from\r
288 the device. If this is not NULL, the interrupt status will\r
289 be read from the device. When the interrupt status is read,\r
290 it will also be cleared. Clearing the transmit interrupt\r
291 does not empty the recycled transmit buffer array.\r
292 @param TxBuffer Recycled transmit buffer address. The network interface will\r
293 not transmit if its internal recycled transmit buffer array\r
294 is full. Reading the transmit buffer does not clear the\r
295 transmit interrupt. If this is NULL, then the transmit buffer\r
296 status will not be read. If there are no transmit buffers to\r
297 recycle and TxBuf is not NULL, * TxBuf will be set to NULL.\r
298\r
299 @retval EFI_SUCCESS Always succeeds.\r
300\r
301**/\r
302EFI_STATUS\r
303EFIAPI\r
304SnpNt32GetStatus (\r
305 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
306 OUT UINT32 *InterruptStatus,\r
307 OUT VOID **TxBuffer\r
308 );\r
309\r
310/**\r
311 Places a packet in the transmit queue of a network interface.\r
312\r
313 @param This Protocol instance pointer.\r
314 @param HeaderSize The size, in bytes, of the media header to be filled in by\r
315 the Transmit() function. If HeaderSize is non-zero, then it\r
316 must be equal to This->Mode->MediaHeaderSize and the DestAddr\r
317 and Protocol parameters must not be NULL.\r
318 @param BufferSize The size, in bytes, of the entire packet (media header and\r
319 data) to be transmitted through the network interface.\r
320 @param Buffer A pointer to the packet (media header followed by data) to be\r
321 transmitted. This parameter cannot be NULL. If HeaderSize is zero,\r
322 then the media header in Buffer must already be filled in by the\r
323 caller. If HeaderSize is non-zero, then the media header will be\r
324 filled in by the Transmit() function.\r
325 @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this parameter\r
326 is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then\r
327 This->Mode->CurrentAddress is used for the source HW MAC address.\r
328 @param DestAddr The destination HW MAC address. If HeaderSize is zero, then this\r
329 parameter is ignored.\r
330 @param Protocol The type of header to build. If HeaderSize is zero, then this\r
331 parameter is ignored. See RFC 1700, section "Ether Types", for\r
332 examples.\r
333\r
334 @retval EFI_SUCCESS The packet was placed on the transmit queue.\r
335 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r
336 @retval EFI_ACCESS_DENIED Error acquire global lock for operation.\r
337\r
338**/\r
339EFI_STATUS\r
340EFIAPI\r
341SnpNt32Transmit (\r
342 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
343 IN UINTN HeaderSize,\r
344 IN UINTN BufferSize,\r
345 IN VOID *Buffer,\r
346 IN EFI_MAC_ADDRESS *SrcAddr OPTIONAL,\r
347 IN EFI_MAC_ADDRESS *DestAddr OPTIONAL,\r
348 IN UINT16 *Protocol OPTIONAL\r
349 );\r
350\r
351/**\r
352 Receives a packet from a network interface.\r
353\r
354 @param This Protocol instance pointer.\r
355 @param HeaderSize The size, in bytes, of the media header received on the network\r
356 interface. If this parameter is NULL, then the media header size\r
357 will not be returned.\r
358 @param BuffSize On entry, the size, in bytes, of Buffer. On exit, the size, in\r
359 bytes, of the packet that was received on the network interface.\r
360 @param Buffer A pointer to the data buffer to receive both the media header and\r
361 the data.\r
362 @param SourceAddr The source HW MAC address. If this parameter is NULL, the\r
363 HW MAC source address will not be extracted from the media\r
364 header.\r
365 @param DestinationAddr The destination HW MAC address. If this parameter is NULL,\r
366 the HW MAC destination address will not be extracted from the\r
367 media header.\r
368 @param Protocol The media header type. If this parameter is NULL, then the\r
369 protocol will not be extracted from the media header. See\r
370 RFC 1700 section "Ether Types" for examples.\r
371\r
372 @retval EFI_SUCCESS The received data was stored in Buffer, and BufferSize has\r
373 been updated to the number of bytes received.\r
374 @retval EFI_NOT_READY The network interface is too busy to accept this transmit\r
375 request.\r
376 @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.\r
377 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r
378 @retval EFI_ACCESS_DENIED Error acquire global lock for operation.\r
379\r
380**/\r
381EFI_STATUS\r
382EFIAPI\r
383SnpNt32Receive (\r
384 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
385 OUT UINTN *HeaderSize,\r
386 IN OUT UINTN *BuffSize,\r
387 OUT VOID *Buffer,\r
388 OUT EFI_MAC_ADDRESS *SourceAddr,\r
389 OUT EFI_MAC_ADDRESS *DestinationAddr,\r
390 OUT UINT16 *Protocol\r
391 );\r
392\r
393SNPNT32_INSTANCE_DATA gSnpNt32InstanceTemplate = {\r
394 SNP_NT32_INSTANCE_SIGNATURE, // Signature\r
395 {\r
396 NULL,\r
397 NULL\r
398 }, // Entry\r
399 NULL, // GlobalData\r
400 NULL, // DeviceHandle\r
401 NULL, // DevicePath\r
402 { // Snp\r
403 EFI_SIMPLE_NETWORK_PROTOCOL_REVISION, // Revision\r
404 SnpNt32Start, // Start\r
405 SnpNt32Stop, // Stop\r
406 SnpNt32Initialize, // Initialize\r
407 SnpNt32Reset, // Reset\r
408 SnpNt32Shutdown, // Shutdown\r
409 SnpNt32ReceiveFilters, // ReceiveFilters\r
410 SnpNt32StationAddress, // StationAddress\r
411 SnpNt32Statistics, // Statistics\r
412 SnpNt32McastIptoMac, // MCastIpToMac\r
413 SnpNt32Nvdata, // NvData\r
414 SnpNt32GetStatus, // GetStatus\r
415 SnpNt32Transmit, // Transmit\r
416 SnpNt32Receive, // Receive\r
417 NULL, // WaitForPacket\r
418 NULL // Mode\r
419 },\r
420 { // Mode\r
421 EfiSimpleNetworkInitialized, // State\r
422 NET_ETHER_ADDR_LEN, // HwAddressSize\r
423 NET_ETHER_HEADER_SIZE, // MediaHeaderSize\r
424 1500, // MaxPacketSize\r
425 0, // NvRamSize\r
426 0, // NvRamAccessSize\r
427 0, // ReceiveFilterMask\r
428 0, // ReceiveFilterSetting\r
429 MAX_MCAST_FILTER_CNT, // MaxMCastFilterCount\r
430 0, // MCastFilterCount\r
431 {\r
432 0\r
433 }, // MCastFilter\r
434 {\r
435 0\r
436 }, // CurrentAddress\r
437 {\r
438 0\r
439 }, // BroadcastAddress\r
440 {\r
441 0\r
442 }, // PermanentAddress\r
443 NET_IFTYPE_ETHERNET, // IfType\r
444 FALSE, // MacAddressChangeable\r
445 FALSE, // MultipleTxSupported\r
7ee525b2 446 TRUE, // MediaPresentSupported\r
531237a5 447 TRUE // MediaPresent\r
448 },\r
449 {\r
450 0\r
451 } // InterfaceInfo\r
452};\r
593a8308 453\r
454/**\r
531237a5 455 Test to see if this driver supports ControllerHandle. This service\r
456 is called by the EFI boot service ConnectController(). In\r
457 order to make drivers as small as possible, there are a few calling\r
458 restrictions for this service. ConnectController() must\r
459 follow these calling restrictions. If any other agent wishes to call\r
460 Supported() it must also follow these calling restrictions.\r
593a8308 461\r
531237a5 462 @param This Protocol instance pointer.\r
463 @param ControllerHandle Handle of device to test\r
464 @param RemainingDevicePath Optional parameter use to pick a specific child\r
465 device to start.\r
593a8308 466\r
531237a5 467 @retval EFI_SUCCESS This driver supports this device\r
468 @retval EFI_UNSUPPORTED This driver does not support this device\r
593a8308 469\r
470**/\r
471EFI_STATUS\r
472EFIAPI\r
473SnpNt32DriverBindingSupported (\r
474 IN EFI_DRIVER_BINDING_PROTOCOL * This,\r
475 IN EFI_HANDLE ControllerHandle,\r
476 IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL\r
477 )\r
478{\r
479\r
480 SNPNT32_GLOBAL_DATA *GlobalData;\r
e90e8777 481 LIST_ENTRY *Entry;\r
593a8308 482 SNPNT32_INSTANCE_DATA *Instance;\r
483\r
484 GlobalData = &gSnpNt32GlobalData;\r
485\r
486 NET_LIST_FOR_EACH (Entry, &GlobalData->InstanceList) {\r
487\r
488 Instance = NET_LIST_USER_STRUCT_S (Entry, SNPNT32_INSTANCE_DATA, Entry, SNP_NT32_INSTANCE_SIGNATURE);\r
489\r
490 if (Instance->DeviceHandle == ControllerHandle) {\r
491 return EFI_SUCCESS;\r
492 }\r
493\r
494 }\r
495\r
496 return EFI_UNSUPPORTED;\r
497}\r
498\r
499\r
500/**\r
531237a5 501 Start this driver on ControllerHandle. This service is called by the\r
502 EFI boot service ConnectController(). In order to make\r
503 drivers as small as possible, there are a few calling restrictions for\r
504 this service. ConnectController() must follow these\r
505 calling restrictions. If any other agent wishes to call Start() it\r
506 must also follow these calling restrictions.\r
593a8308 507\r
531237a5 508 @param This Protocol instance pointer.\r
509 @param ControllerHandle Handle of device to bind driver to\r
510 @param RemainingDevicePath Optional parameter use to pick a specific child\r
511 device to start.\r
593a8308 512\r
531237a5 513 @retval EFI_SUCCESS Always succeeds.\r
593a8308 514\r
515**/\r
516EFI_STATUS\r
517EFIAPI\r
518SnpNt32DriverBindingStart (\r
519 IN EFI_DRIVER_BINDING_PROTOCOL * This,\r
520 IN EFI_HANDLE ControllerHandle,\r
521 IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL\r
522 )\r
523{\r
524 return EFI_SUCCESS;\r
525}\r
526\r
593a8308 527/**\r
531237a5 528 Stop this driver on ControllerHandle. This service is called by the\r
529 EFI boot service DisconnectController(). In order to\r
530 make drivers as small as possible, there are a few calling\r
531 restrictions for this service. DisconnectController()\r
532 must follow these calling restrictions. If any other agent wishes\r
533 to call Stop() it must also follow these calling restrictions.\r
534 \r
535 @param This Protocol instance pointer.\r
536 @param ControllerHandle Handle of device to stop driver on\r
537 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
538 children is zero stop the entire bus driver.\r
539 @param ChildHandleBuffer List of Child Handles to Stop.\r
540\r
541 @retval EFI_SUCCESS Always succeeds.\r
593a8308 542\r
543**/\r
544EFI_STATUS\r
545EFIAPI\r
546SnpNt32DriverBindingStop (\r
547 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
548 IN EFI_HANDLE ControllerHandle,\r
549 IN UINTN NumberOfChildren,\r
550 IN EFI_HANDLE *ChildHandleBuffer\r
551 )\r
552{\r
593a8308 553 return EFI_SUCCESS;\r
554}\r
555\r
556\r
557/**\r
531237a5 558 Changes the state of a network interface from "stopped" to "started".\r
593a8308 559\r
531237a5 560 @param This Protocol instance pointer.\r
593a8308 561\r
531237a5 562 @retval EFI_SUCCESS Always succeeds.\r
593a8308 563\r
564**/\r
565EFI_STATUS\r
531237a5 566EFIAPI\r
593a8308 567SnpNt32Start (\r
568 IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r
569 )\r
570{\r
571 return EFI_SUCCESS;\r
572}\r
573\r
574\r
575/**\r
531237a5 576 Changes the state of a network interface from "started" to "stopped".\r
593a8308 577\r
531237a5 578 @param This Protocol instance pointer.\r
593a8308 579\r
531237a5 580 @retval EFI_SUCCESS Always succeeds.\r
593a8308 581\r
582**/\r
583EFI_STATUS\r
531237a5 584EFIAPI\r
593a8308 585SnpNt32Stop (\r
586 IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r
587 )\r
588{\r
589 return EFI_SUCCESS;\r
590}\r
591\r
593a8308 592/**\r
531237a5 593 Resets a network adapter and allocates the transmit and receive buffers \r
594 required by the network interface; optionally, also requests allocation \r
595 of additional transmit and receive buffers.\r
596\r
597 @param This Protocol instance pointer.\r
598 @param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space\r
599 that the driver should allocate for the network interface.\r
600 Some network interfaces will not be able to use the extra\r
601 buffer, and the caller will not know if it is actually\r
602 being used.\r
603 @param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space\r
604 that the driver should allocate for the network interface.\r
605 Some network interfaces will not be able to use the extra\r
606 buffer, and the caller will not know if it is actually\r
607 being used.\r
608\r
609 @retval EFI_SUCCESS Always succeeds.\r
593a8308 610\r
611**/\r
612EFI_STATUS\r
531237a5 613EFIAPI\r
593a8308 614SnpNt32Initialize (\r
615 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
616 IN UINTN ExtraRxBufferSize OPTIONAL,\r
617 IN UINTN ExtraTxBufferSize OPTIONAL\r
618 )\r
619{\r
620 return EFI_SUCCESS;\r
621}\r
622\r
593a8308 623/**\r
531237a5 624 Resets a network adapter and re-initializes it with the parameters that were \r
625 provided in the previous call to Initialize(). \r
593a8308 626\r
531237a5 627 @param This Protocol instance pointer.\r
628 @param ExtendedVerification Indicates that the driver may perform a more\r
629 exhaustive verification operation of the device\r
630 during reset.\r
593a8308 631\r
531237a5 632 @retval EFI_SUCCESS Always succeeds.\r
593a8308 633\r
634**/\r
635EFI_STATUS\r
531237a5 636EFIAPI\r
593a8308 637SnpNt32Reset (\r
638 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
639 IN BOOLEAN ExtendedVerification\r
640 )\r
641{\r
642 return EFI_SUCCESS;\r
643}\r
644\r
593a8308 645/**\r
531237a5 646 Resets a network adapter and leaves it in a state that is safe for \r
647 another driver to initialize.\r
593a8308 648\r
531237a5 649 @param This Protocol instance pointer.\r
593a8308 650\r
531237a5 651 @retval EFI_SUCCESS Always succeeds.\r
593a8308 652\r
653**/\r
654EFI_STATUS\r
531237a5 655EFIAPI\r
593a8308 656SnpNt32Shutdown (\r
657 IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r
658 )\r
659{\r
660 return EFI_SUCCESS;\r
661}\r
662\r
593a8308 663/**\r
531237a5 664 Manages the multicast receive filters of a network interface.\r
665\r
666 @param This Protocol instance pointer.\r
667 @param EnableBits A bit mask of receive filters to enable on the network interface.\r
668 @param DisableBits A bit mask of receive filters to disable on the network interface.\r
669 @param ResetMcastFilter Set to TRUE to reset the contents of the multicast receive\r
670 filters on the network interface to their default values.\r
671 @param McastFilterCount Number of multicast HW MAC addresses in the new\r
672 MCastFilter list. This value must be less than or equal to\r
673 the MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE. This\r
674 field is optional if ResetMCastFilter is TRUE.\r
675 @param McastFilter A pointer to a list of new multicast receive filter HW MAC\r
676 addresses. This list will replace any existing multicast\r
677 HW MAC address list. This field is optional if\r
678 ResetMCastFilter is TRUE.\r
679\r
680 @retval EFI_SUCCESS The multicast receive filter list was updated.\r
681 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r
593a8308 682\r
683**/\r
684EFI_STATUS\r
531237a5 685EFIAPI\r
593a8308 686SnpNt32ReceiveFilters (\r
687 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
688 IN UINT32 EnableBits,\r
689 IN UINT32 DisableBits,\r
690 IN BOOLEAN ResetMcastFilter,\r
691 IN UINTN McastFilterCount OPTIONAL,\r
531237a5 692 IN EFI_MAC_ADDRESS *McastFilter OPTIONAL\r
593a8308 693 )\r
694{\r
695 SNPNT32_INSTANCE_DATA *Instance;\r
696 SNPNT32_GLOBAL_DATA *GlobalData;\r
697 INT32 ReturnValue;\r
698\r
699 Instance = SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This);\r
700\r
701 GlobalData = Instance->GlobalData;\r
702\r
e90e8777 703 if (EFI_ERROR (EfiAcquireLockOrFail (&GlobalData->Lock))) {\r
593a8308 704 return EFI_ACCESS_DENIED;\r
705 }\r
706\r
707 ReturnValue = GlobalData->NtNetUtilityTable.SetReceiveFilter (\r
708 Instance->InterfaceInfo.InterfaceIndex,\r
709 EnableBits,\r
f66a43b2 710 (UINT32)McastFilterCount,\r
593a8308 711 McastFilter\r
712 );\r
713\r
e90e8777 714 EfiReleaseLock (&GlobalData->Lock);\r
593a8308 715\r
716 if (ReturnValue <= 0) {\r
717 return EFI_DEVICE_ERROR;\r
718 }\r
719\r
720 return EFI_SUCCESS;\r
721}\r
722\r
593a8308 723/**\r
531237a5 724 Modifies or resets the current station address, if supported.\r
593a8308 725\r
531237a5 726 @param This Protocol instance pointer.\r
727 @param Reset Flag used to reset the station address to the network interfaces\r
728 permanent address.\r
729 @param NewMacAddr New station address to be used for the network interface.\r
593a8308 730\r
731 @retval EFI_UNSUPPORTED Not supported yet.\r
732\r
733**/\r
734EFI_STATUS\r
531237a5 735EFIAPI\r
593a8308 736SnpNt32StationAddress (\r
737 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
738 IN BOOLEAN Reset,\r
739 IN EFI_MAC_ADDRESS *NewMacAddr OPTIONAL\r
740 )\r
741{\r
742 return EFI_UNSUPPORTED;\r
743}\r
744\r
593a8308 745/**\r
531237a5 746 Resets or collects the statistics on a network interface.\r
747\r
748 @param This Protocol instance pointer.\r
749 @param Reset Set to TRUE to reset the statistics for the network interface.\r
750 @param StatisticsSize On input the size, in bytes, of StatisticsTable. On\r
751 output the size, in bytes, of the resulting table of\r
752 statistics.\r
753 @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that\r
754 contains the statistics.\r
755\r
756 @retval EFI_SUCCESS The statistics were collected from the network interface.\r
757 @retval EFI_NOT_STARTED The network interface has not been started.\r
758 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer\r
759 size needed to hold the statistics is returned in\r
760 StatisticsSize.\r
593a8308 761 @retval EFI_UNSUPPORTED Not supported yet.\r
762\r
763**/\r
764EFI_STATUS\r
531237a5 765EFIAPI\r
593a8308 766SnpNt32Statistics (\r
767 IN EFI_SIMPLE_NETWORK_PROTOCOL * This,\r
768 IN BOOLEAN Reset,\r
769 IN OUT UINTN *StatisticsSize OPTIONAL,\r
531237a5 770 OUT EFI_NETWORK_STATISTICS *StatisticsTable OPTIONAL\r
593a8308 771 )\r
772{\r
773 return EFI_UNSUPPORTED;\r
774}\r
775\r
593a8308 776/**\r
531237a5 777 Converts a multicast IP address to a multicast HW MAC address.\r
778\r
779 @param This Protocol instance pointer.\r
780 @param Ipv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set\r
781 to FALSE if the multicast IP address is IPv4 [RFC 791].\r
782 @param Ip The multicast IP address that is to be converted to a multicast\r
783 HW MAC address.\r
784 @param Mac The multicast HW MAC address that is to be generated from IP.\r
785\r
786 @retval EFI_SUCCESS The multicast IP address was mapped to the multicast\r
787 HW MAC address.\r
788 @retval EFI_NOT_STARTED The network interface has not been started.\r
789 @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer\r
790 size needed to hold the statistics is returned in\r
791 StatisticsSize.\r
593a8308 792 @retval EFI_UNSUPPORTED Not supported yet.\r
793\r
794**/\r
795EFI_STATUS\r
531237a5 796EFIAPI\r
593a8308 797SnpNt32McastIptoMac (\r
798 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
799 IN BOOLEAN Ipv6,\r
800 IN EFI_IP_ADDRESS *Ip,\r
801 OUT EFI_MAC_ADDRESS *Mac\r
802 )\r
803{\r
804 return EFI_UNSUPPORTED;\r
805}\r
806\r
807\r
808/**\r
531237a5 809 Performs read and write operations on the NVRAM device attached to a \r
810 network interface.\r
811\r
812 @param This Protocol instance pointer.\r
813 @param ReadOrWrite TRUE for read operations, FALSE for write operations.\r
814 @param Offset Byte offset in the NVRAM device at which to start the read or\r
815 write operation. This must be a multiple of NvRamAccessSize and\r
816 less than NvRamSize.\r
817 @param BufferSize The number of bytes to read or write from the NVRAM device.\r
818 This must also be a multiple of NvramAccessSize.\r
819 @param Buffer A pointer to the data buffer.\r
593a8308 820\r
821 @retval EFI_UNSUPPORTED Not supported yet.\r
822\r
823**/\r
824EFI_STATUS\r
531237a5 825EFIAPI\r
593a8308 826SnpNt32Nvdata (\r
827 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
828 IN BOOLEAN ReadOrWrite,\r
829 IN UINTN Offset,\r
830 IN UINTN BufferSize,\r
831 IN OUT VOID *Buffer\r
832 )\r
833{\r
834 return EFI_UNSUPPORTED;\r
835}\r
836\r
837\r
838/**\r
531237a5 839 Reads the current interrupt status and recycled transmit buffer status from \r
840 a network interface.\r
841\r
842 @param This Protocol instance pointer.\r
843 @param InterruptStatus A pointer to the bit mask of the currently active interrupts\r
844 If this is NULL, the interrupt status will not be read from\r
845 the device. If this is not NULL, the interrupt status will\r
846 be read from the device. When the interrupt status is read,\r
847 it will also be cleared. Clearing the transmit interrupt\r
848 does not empty the recycled transmit buffer array.\r
849 @param TxBuffer Recycled transmit buffer address. The network interface will\r
850 not transmit if its internal recycled transmit buffer array\r
851 is full. Reading the transmit buffer does not clear the\r
852 transmit interrupt. If this is NULL, then the transmit buffer\r
853 status will not be read. If there are no transmit buffers to\r
854 recycle and TxBuf is not NULL, * TxBuf will be set to NULL.\r
855\r
856 @retval EFI_SUCCESS Always succeeds.\r
593a8308 857\r
858**/\r
859EFI_STATUS\r
531237a5 860EFIAPI\r
593a8308 861SnpNt32GetStatus (\r
862 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
863 OUT UINT32 *InterruptStatus,\r
864 OUT VOID **TxBuffer\r
865 )\r
866{\r
a2cc5fea
ZL
867 SNPNT32_INSTANCE_DATA *Instance;\r
868 SNPNT32_GLOBAL_DATA *GlobalData;\r
869\r
870 Instance = SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This);\r
871\r
872 GlobalData = Instance->GlobalData;\r
593a8308 873\r
874 if (TxBuffer != NULL) {\r
a2cc5fea
ZL
875 if (GlobalData->RecycledTxBufCount != 0) {\r
876 GlobalData->RecycledTxBufCount --;\r
877 *((UINT8 **) TxBuffer) = (UINT8 *) (UINTN)GlobalData->RecycledTxBuf[GlobalData->RecycledTxBufCount];\r
878 } else {\r
879 *((UINT8 **) TxBuffer) = NULL;\r
880 }\r
593a8308 881 }\r
882\r
883 if (InterruptStatus != NULL) {\r
884 *InterruptStatus = EFI_SIMPLE_NETWORK_TRANSMIT_INTERRUPT;\r
885 }\r
886\r
887 return EFI_SUCCESS;\r
888}\r
889\r
890\r
891/**\r
531237a5 892 Places a packet in the transmit queue of a network interface.\r
893\r
894 @param This Protocol instance pointer.\r
895 @param HeaderSize The size, in bytes, of the media header to be filled in by\r
896 the Transmit() function. If HeaderSize is non-zero, then it\r
897 must be equal to This->Mode->MediaHeaderSize and the DestAddr\r
898 and Protocol parameters must not be NULL.\r
899 @param BufferSize The size, in bytes, of the entire packet (media header and\r
900 data) to be transmitted through the network interface.\r
901 @param Buffer A pointer to the packet (media header followed by data) to be\r
902 transmitted. This parameter cannot be NULL. If HeaderSize is zero,\r
903 then the media header in Buffer must already be filled in by the\r
904 caller. If HeaderSize is non-zero, then the media header will be\r
905 filled in by the Transmit() function.\r
906 @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this parameter\r
907 is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then\r
908 This->Mode->CurrentAddress is used for the source HW MAC address.\r
909 @param DestAddr The destination HW MAC address. If HeaderSize is zero, then this\r
910 parameter is ignored.\r
911 @param Protocol The type of header to build. If HeaderSize is zero, then this\r
912 parameter is ignored. See RFC 1700, section "Ether Types", for\r
913 examples.\r
914\r
915 @retval EFI_SUCCESS The packet was placed on the transmit queue.\r
916 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r
917 @retval EFI_ACCESS_DENIED Error acquire global lock for operation.\r
593a8308 918\r
919**/\r
920EFI_STATUS\r
531237a5 921EFIAPI\r
593a8308 922SnpNt32Transmit (\r
923 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
924 IN UINTN HeaderSize,\r
925 IN UINTN BufferSize,\r
926 IN VOID *Buffer,\r
927 IN EFI_MAC_ADDRESS *SrcAddr OPTIONAL,\r
928 IN EFI_MAC_ADDRESS *DestAddr OPTIONAL,\r
929 IN UINT16 *Protocol OPTIONAL\r
930 )\r
931{\r
932 SNPNT32_INSTANCE_DATA *Instance;\r
933 SNPNT32_GLOBAL_DATA *GlobalData;\r
934 INT32 ReturnValue;\r
a2cc5fea 935 UINT64 *Tmp;\r
593a8308 936\r
937 Instance = SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This);\r
938\r
939 GlobalData = Instance->GlobalData;\r
940\r
941 if ((HeaderSize != 0) && (SrcAddr == NULL)) {\r
942 SrcAddr = &Instance->Mode.CurrentAddress;\r
943 }\r
944\r
e90e8777 945 if (EFI_ERROR (EfiAcquireLockOrFail (&GlobalData->Lock))) {\r
593a8308 946 return EFI_ACCESS_DENIED;\r
947 }\r
948\r
949 ReturnValue = GlobalData->NtNetUtilityTable.Transmit (\r
950 Instance->InterfaceInfo.InterfaceIndex,\r
f66a43b2
JM
951 (UINT32)HeaderSize,\r
952 (UINT32)BufferSize,\r
593a8308 953 Buffer,\r
954 SrcAddr,\r
955 DestAddr,\r
956 Protocol\r
957 );\r
958\r
e90e8777 959 EfiReleaseLock (&GlobalData->Lock);\r
593a8308 960\r
961 if (ReturnValue < 0) {\r
962 return EFI_DEVICE_ERROR;\r
a2cc5fea
ZL
963 } else {\r
964 if ((GlobalData->MaxRecycledTxBuf + SNP_TX_BUFFER_INCREASEMENT) >= SNP_MAX_TX_BUFFER_NUM) {\r
965 return EFI_NOT_READY;\r
966 }\r
967\r
968 if (GlobalData->RecycledTxBufCount < GlobalData->MaxRecycledTxBuf) {\r
969 GlobalData->RecycledTxBuf[GlobalData->RecycledTxBufCount] = (UINT64) Buffer;\r
970 GlobalData->RecycledTxBufCount ++;\r
971 } else {\r
972 Tmp = AllocatePool (sizeof (UINT64) * (GlobalData->MaxRecycledTxBuf + SNP_TX_BUFFER_INCREASEMENT));\r
973 if (Tmp == NULL) {\r
974 return EFI_DEVICE_ERROR;\r
975 }\r
976 CopyMem (Tmp, GlobalData->RecycledTxBuf, sizeof (UINT64) * GlobalData->RecycledTxBufCount);\r
977 FreePool (GlobalData->RecycledTxBuf);\r
978 GlobalData->RecycledTxBuf = Tmp;\r
979 GlobalData->MaxRecycledTxBuf += SNP_TX_BUFFER_INCREASEMENT;\r
980 }\r
593a8308 981 }\r
982\r
983 return EFI_SUCCESS;\r
984}\r
985\r
593a8308 986/**\r
531237a5 987 Receives a packet from a network interface.\r
988\r
989 @param This Protocol instance pointer.\r
990 @param HeaderSize The size, in bytes, of the media header received on the network\r
991 interface. If this parameter is NULL, then the media header size\r
992 will not be returned.\r
993 @param BuffSize On entry, the size, in bytes, of Buffer. On exit, the size, in\r
994 bytes, of the packet that was received on the network interface.\r
995 @param Buffer A pointer to the data buffer to receive both the media header and\r
996 the data.\r
997 @param SourceAddr The source HW MAC address. If this parameter is NULL, the\r
998 HW MAC source address will not be extracted from the media\r
999 header.\r
1000 @param DestinationAddr The destination HW MAC address. If this parameter is NULL,\r
1001 the HW MAC destination address will not be extracted from the\r
1002 media header.\r
1003 @param Protocol The media header type. If this parameter is NULL, then the\r
1004 protocol will not be extracted from the media header. See\r
1005 RFC 1700 section "Ether Types" for examples.\r
1006\r
1007 @retval EFI_SUCCESS The received data was stored in Buffer, and BufferSize has\r
1008 been updated to the number of bytes received.\r
1009 @retval EFI_NOT_READY The network interface is too busy to accept this transmit\r
1010 request.\r
1011 @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.\r
1012 @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r
1013 @retval EFI_ACCESS_DENIED Error acquire global lock for operation.\r
593a8308 1014\r
1015**/\r
1016EFI_STATUS\r
531237a5 1017EFIAPI\r
593a8308 1018SnpNt32Receive (\r
1019 IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r
1020 OUT UINTN *HeaderSize,\r
1021 IN OUT UINTN *BuffSize,\r
1022 OUT VOID *Buffer,\r
1023 OUT EFI_MAC_ADDRESS *SourceAddr,\r
1024 OUT EFI_MAC_ADDRESS *DestinationAddr,\r
1025 OUT UINT16 *Protocol\r
1026 )\r
1027{\r
1028 SNPNT32_INSTANCE_DATA *Instance;\r
1029 SNPNT32_GLOBAL_DATA *GlobalData;\r
1030 INT32 ReturnValue;\r
aaf779a7 1031 UINTN BufSize;\r
1032 \r
1033 BufSize = *BuffSize;\r
593a8308 1034\r
1035 Instance = SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This);\r
1036\r
1037 GlobalData = Instance->GlobalData;\r
1038\r
1039 ASSERT (GlobalData->NtNetUtilityTable.Receive != NULL);\r
1040\r
e90e8777 1041 if (EFI_ERROR (EfiAcquireLockOrFail (&GlobalData->Lock))) {\r
593a8308 1042 return EFI_ACCESS_DENIED;\r
1043 }\r
1044\r
1045 ReturnValue = GlobalData->NtNetUtilityTable.Receive (\r
1046 Instance->InterfaceInfo.InterfaceIndex,\r
1047 BuffSize,\r
1048 Buffer\r
1049 );\r
1050\r
e90e8777 1051 EfiReleaseLock (&GlobalData->Lock);\r
593a8308 1052\r
1053 if (ReturnValue < 0) {\r
1054 if (ReturnValue == -100) {\r
1055 return EFI_BUFFER_TOO_SMALL;\r
1056 }\r
1057\r
1058 return EFI_DEVICE_ERROR;\r
1059 } else if (ReturnValue == 0) {\r
1060 return EFI_NOT_READY;\r
1061 }\r
1062\r
1063 if (HeaderSize != NULL) {\r
1064 *HeaderSize = 14;\r
1065 }\r
1066\r
1067 if (SourceAddr != NULL) {\r
e90e8777 1068 ZeroMem (SourceAddr, sizeof (EFI_MAC_ADDRESS));\r
1069 CopyMem (SourceAddr, ((UINT8 *) Buffer) + 6, 6);\r
593a8308 1070 }\r
1071\r
1072 if (DestinationAddr != NULL) {\r
e90e8777 1073 ZeroMem (DestinationAddr, sizeof (EFI_MAC_ADDRESS));\r
1074 CopyMem (DestinationAddr, ((UINT8 *) Buffer), 6);\r
593a8308 1075 }\r
1076\r
1077 if (Protocol != NULL) {\r
1078 *Protocol = NTOHS (*((UINT16 *) (((UINT8 *) Buffer) + 12)));\r
1079 }\r
1080\r
aaf779a7 1081 return (*BuffSize <= BufSize) ? EFI_SUCCESS : EFI_BUFFER_TOO_SMALL; \r
593a8308 1082}\r
1083\r
593a8308 1084/**\r
1085 Initialize the driver's global data.\r
1086\r
1087 @param This Pointer to the global context data.\r
1088\r
1089 @retval EFI_SUCCESS The global data is initialized.\r
1090 @retval EFI_NOT_FOUND The required DLL is not found.\r
531237a5 1091 @retval EFI_DEVICE_ERROR Error initialize network utility library.\r
1092 @retval EFI_OUT_OF_RESOURCES Out of resource.\r
1093 @retval other Other errors.\r
593a8308 1094\r
1095**/\r
1096EFI_STATUS\r
1097SnpNt32InitializeGlobalData (\r
531237a5 1098 IN OUT SNPNT32_GLOBAL_DATA *This\r
593a8308 1099 )\r
1100{\r
1101 EFI_STATUS Status;\r
1102 CHAR16 *DllFileNameU;\r
1103 UINT32 Index;\r
1104 INT32 ReturnValue;\r
1105 BOOLEAN NetUtilityLibInitDone;\r
1106 NT_NET_INTERFACE_INFO NetInterfaceInfoBuffer[MAX_INTERFACE_INFO_NUMBER];\r
1107 SNPNT32_INSTANCE_DATA *Instance;\r
e90e8777 1108 LIST_ENTRY *Entry;\r
593a8308 1109 UINT32 InterfaceCount;\r
1110\r
1111 ASSERT (This != NULL);\r
1112\r
1113 NetUtilityLibInitDone = FALSE;\r
1114 InterfaceCount = MAX_INTERFACE_INFO_NUMBER;\r
1115\r
e90e8777 1116 InitializeListHead (&This->InstanceList);\r
1117 EfiInitializeLock (&This->Lock, TPL_CALLBACK);\r
593a8308 1118\r
a2cc5fea
ZL
1119 This->RecycledTxBuf = AllocatePool (sizeof (UINT64) * This->MaxRecycledTxBuf);\r
1120 if (This->RecycledTxBuf == NULL) {\r
1121 return EFI_OUT_OF_RESOURCES;\r
1122 }\r
1123\r
593a8308 1124 //\r
1125 // Get the WinNT thunk\r
1126 //\r
a00ec39b 1127 Status = gBS->LocateProtocol (&gEfiWinNtThunkProtocolGuid, NULL, (VOID **)&This->WinNtThunk);\r
593a8308 1128\r
1129 if (EFI_ERROR (Status)) {\r
1130 return Status;\r
1131 }\r
1132\r
1133 ASSERT (This->WinNtThunk != NULL);\r
1134\r
1135 DllFileNameU = NETWORK_LIBRARY_NAME_U;\r
1136\r
1137 //\r
1138 // Load network utility library\r
1139 //\r
1140 This->NetworkLibraryHandle = This->WinNtThunk->LoadLibraryEx (DllFileNameU, NULL, 0);\r
1141\r
1142 if (NULL == This->NetworkLibraryHandle) {\r
1143 return EFI_NOT_FOUND;\r
1144 }\r
1145\r
1146 This->NtNetUtilityTable.Initialize = (NT_NET_INITIALIZE) This->WinNtThunk->GetProcAddress (\r
531237a5 1147 This->NetworkLibraryHandle,\r
1148 NETWORK_LIBRARY_INITIALIZE\r
1149 );\r
593a8308 1150\r
1151 if (NULL == This->NtNetUtilityTable.Initialize) {\r
1152 Status = EFI_NOT_FOUND;\r
1153 goto ErrorReturn;\r
1154 }\r
1155\r
1156 This->NtNetUtilityTable.Finalize = (NT_NET_FINALIZE) This->WinNtThunk->GetProcAddress (\r
531237a5 1157 This->NetworkLibraryHandle,\r
1158 NETWORK_LIBRARY_FINALIZE\r
1159 );\r
593a8308 1160\r
1161 if (NULL == This->NtNetUtilityTable.Finalize) {\r
1162 Status = EFI_NOT_FOUND;\r
1163 goto ErrorReturn;\r
1164 }\r
1165\r
1166 This->NtNetUtilityTable.SetReceiveFilter = (NT_NET_SET_RECEIVE_FILTER) This->WinNtThunk->GetProcAddress (\r
531237a5 1167 This->NetworkLibraryHandle,\r
1168 NETWORK_LIBRARY_SET_RCV_FILTER\r
1169 );\r
593a8308 1170\r
1171 if (NULL == This->NtNetUtilityTable.SetReceiveFilter) {\r
1172 Status = EFI_NOT_FOUND;\r
1173 goto ErrorReturn;\r
1174 }\r
1175\r
1176 This->NtNetUtilityTable.Receive = (NT_NET_RECEIVE) This->WinNtThunk->GetProcAddress (\r
531237a5 1177 This->NetworkLibraryHandle,\r
1178 NETWORK_LIBRARY_RECEIVE\r
1179 );\r
593a8308 1180\r
1181 if (NULL == This->NtNetUtilityTable.Receive) {\r
1182 Status = EFI_NOT_FOUND;\r
1183 goto ErrorReturn;\r
1184 }\r
1185\r
1186 This->NtNetUtilityTable.Transmit = (NT_NET_TRANSMIT) This->WinNtThunk->GetProcAddress (\r
531237a5 1187 This->NetworkLibraryHandle,\r
1188 NETWORK_LIBRARY_TRANSMIT\r
1189 );\r
593a8308 1190\r
1191 if (NULL == This->NtNetUtilityTable.Transmit) {\r
1192 Status = EFI_NOT_FOUND;\r
1193 goto ErrorReturn;\r
1194 }\r
1195 //\r
1196 // Initialize the network utility library\r
1197 // And enumerate the interfaces in NT32 host\r
1198 //\r
1199 ReturnValue = This->NtNetUtilityTable.Initialize (&InterfaceCount, &NetInterfaceInfoBuffer[0]);\r
1200 if (ReturnValue <= 0) {\r
1201 Status = EFI_DEVICE_ERROR;\r
1202 goto ErrorReturn;\r
1203 }\r
1204\r
1205 NetUtilityLibInitDone = TRUE;\r
1206\r
1207 if (InterfaceCount == 0) {\r
1208 Status = EFI_NOT_FOUND;\r
1209 goto ErrorReturn;\r
1210 }\r
1211 //\r
1212 // Create fake SNP instances\r
1213 //\r
1214 for (Index = 0; Index < InterfaceCount; Index++) {\r
1215\r
e90e8777 1216 Instance = AllocatePool (sizeof (SNPNT32_INSTANCE_DATA));\r
593a8308 1217\r
1218 if (NULL == Instance) {\r
1219 Status = EFI_OUT_OF_RESOURCES;\r
1220 goto ErrorReturn;\r
1221 }\r
1222 //\r
1223 // Copy the content from a template\r
1224 //\r
e90e8777 1225 CopyMem (Instance, &gSnpNt32InstanceTemplate, sizeof (SNPNT32_INSTANCE_DATA));\r
593a8308 1226\r
1227 //\r
1228 // Set the interface information.\r
1229 //\r
f66a43b2 1230 CopyMem (&Instance->InterfaceInfo, &NetInterfaceInfoBuffer[Index], sizeof(Instance->InterfaceInfo));\r
593a8308 1231 //\r
1232 // Initialize this instance\r
1233 //\r
1234 Status = This->InitializeInstanceData (This, Instance);\r
1235 if (EFI_ERROR (Status)) {\r
1236\r
e90e8777 1237 gBS->FreePool (Instance);\r
593a8308 1238 goto ErrorReturn;\r
1239 }\r
1240 //\r
1241 // Insert this instance into the instance list\r
1242 //\r
e90e8777 1243 InsertTailList (&This->InstanceList, &Instance->Entry);\r
593a8308 1244 }\r
1245\r
1246 return EFI_SUCCESS;\r
1247\r
1248ErrorReturn:\r
1249\r
e90e8777 1250 while (!IsListEmpty (&This->InstanceList)) {\r
593a8308 1251\r
1252 Entry = This->InstanceList.ForwardLink;\r
1253\r
1254 Instance = NET_LIST_USER_STRUCT_S (Entry, SNPNT32_INSTANCE_DATA, Entry, SNP_NT32_INSTANCE_SIGNATURE);\r
1255\r
e90e8777 1256 RemoveEntryList (Entry);\r
593a8308 1257\r
1258 This->CloseInstance (This, Instance);\r
e90e8777 1259 gBS->FreePool (Instance);\r
593a8308 1260 }\r
1261\r
1262 if (NetUtilityLibInitDone) {\r
1263\r
1264 ASSERT (This->WinNtThunk != NULL);\r
1265\r
1266 if (This->NtNetUtilityTable.Finalize != NULL) {\r
1267 This->NtNetUtilityTable.Finalize ();\r
1268 This->NtNetUtilityTable.Finalize = NULL;\r
1269 }\r
1270 }\r
1271\r
1272 return Status;\r
1273}\r
1274\r
1275\r
1276/**\r
1277 Initialize the snpnt32 driver instance.\r
1278\r
1279 @param This Pointer to the SnpNt32 global data.\r
1280 @param Instance Pointer to the instance context data.\r
1281\r
1282 @retval EFI_SUCCESS The driver instance is initialized.\r
531237a5 1283 @retval other Initialization errors.\r
593a8308 1284\r
1285**/\r
1286EFI_STATUS\r
1287SnpNt32InitializeInstanceData (\r
531237a5 1288 IN SNPNT32_GLOBAL_DATA *This,\r
1289 IN OUT SNPNT32_INSTANCE_DATA *Instance\r
593a8308 1290 )\r
1291{\r
1292 EFI_STATUS Status;\r
1293 EFI_DEV_PATH EndNode;\r
1294 EFI_DEV_PATH Node;\r
1295\r
1296 Instance->GlobalData = This;\r
1297 Instance->Snp.Mode = &Instance->Mode;\r
1298 //\r
1299 // Set broadcast address\r
1300 //\r
1301 SetMem (&Instance->Mode.BroadcastAddress, sizeof (EFI_MAC_ADDRESS), 0xFF);\r
1302\r
1303 //\r
1304 // Copy Current/PermanentAddress MAC address\r
1305 //\r
f66a43b2
JM
1306 CopyMem (&Instance->Mode.CurrentAddress, &Instance->InterfaceInfo.MacAddr, sizeof(Instance->Mode.CurrentAddress));\r
1307 CopyMem (&Instance->Mode.PermanentAddress, &Instance->InterfaceInfo.MacAddr, sizeof(Instance->Mode.PermanentAddress));\r
593a8308 1308\r
1309 //\r
1310 // Since the fake SNP is based on a real NIC, to avoid conflict with the host\r
1311 // NIC network stack, we use a different MAC address.\r
1312 // So just change the last byte of the MAC address for the real NIC.\r
1313 //\r
1314 Instance->Mode.CurrentAddress.Addr[NET_ETHER_ADDR_LEN - 1]++;\r
1315\r
1316 //\r
1317 // Create a fake device path for the instance\r
1318 //\r
e90e8777 1319 ZeroMem (&Node, sizeof (Node));\r
593a8308 1320\r
1321 Node.DevPath.Type = MESSAGING_DEVICE_PATH;\r
1322 Node.DevPath.SubType = MSG_MAC_ADDR_DP;\r
1323 SetDevicePathNodeLength (&Node.DevPath, sizeof (MAC_ADDR_DEVICE_PATH));\r
1324\r
e90e8777 1325 CopyMem (\r
593a8308 1326 &Node.MacAddr.MacAddress,\r
1327 &Instance->Mode.CurrentAddress,\r
4324075f 1328 NET_ETHER_ADDR_LEN\r
593a8308 1329 );\r
1330\r
1331 Node.MacAddr.IfType = Instance->Mode.IfType;\r
1332\r
1333 SetDevicePathEndNode (&EndNode.DevPath);\r
1334\r
1335 Instance->DevicePath = AppendDevicePathNode (\r
531237a5 1336 &EndNode.DevPath,\r
1337 &Node.DevPath\r
1338 );\r
593a8308 1339\r
1340 //\r
1341 // Create a fake device handle for the fake SNP\r
1342 //\r
1343 Status = gBS->InstallMultipleProtocolInterfaces (\r
1344 &Instance->DeviceHandle,\r
1345 &gEfiSimpleNetworkProtocolGuid,\r
1346 &Instance->Snp,\r
1347 &gEfiDevicePathProtocolGuid,\r
1348 Instance->DevicePath,\r
1349 NULL\r
1350 );\r
593a8308 1351 return Status;\r
1352}\r
1353\r
1354\r
1355/**\r
1356 Close the SnpNt32 driver instance.\r
1357\r
1358 @param This Pointer to the SnpNt32 global data.\r
1359 @param Instance Pointer to the instance context data.\r
1360\r
1361 @retval EFI_SUCCESS The instance is closed.\r
1362\r
1363**/\r
1364EFI_STATUS\r
1365SnpNt32CloseInstance (\r
531237a5 1366 IN SNPNT32_GLOBAL_DATA *This,\r
1367 IN OUT SNPNT32_INSTANCE_DATA *Instance\r
593a8308 1368 )\r
1369{\r
1370 ASSERT (This != NULL);\r
1371 ASSERT (Instance != NULL);\r
1372\r
1373 gBS->UninstallMultipleProtocolInterfaces (\r
531237a5 1374 Instance->DeviceHandle,\r
1375 &gEfiSimpleNetworkProtocolGuid,\r
1376 &Instance->Snp,\r
1377 &gEfiDevicePathProtocolGuid,\r
1378 Instance->DevicePath,\r
1379 NULL\r
1380 );\r
593a8308 1381\r
1382 if (Instance->DevicePath != NULL) {\r
1383 gBS->FreePool (Instance->DevicePath);\r
1384 }\r
1385\r
1386 return EFI_SUCCESS;\r
1387}\r
1388\r
593a8308 1389/**\r
531237a5 1390 Unloads an image.\r
593a8308 1391\r
531237a5 1392 @param ImageHandle Handle that identifies the image to be unloaded.\r
593a8308 1393\r
531237a5 1394 @retval EFI_SUCCESS The image has been unloaded.\r
1395 @return Exit code from the image's unload handler\r
593a8308 1396\r
1397**/\r
1398EFI_STATUS\r
1399EFIAPI\r
1400SnpNt32Unload (\r
1401 IN EFI_HANDLE ImageHandle\r
1402 )\r
1403{\r
1404 EFI_STATUS Status;\r
1405 SNPNT32_GLOBAL_DATA *This;\r
e90e8777 1406 LIST_ENTRY *Entry;\r
593a8308 1407 SNPNT32_INSTANCE_DATA *Instance;\r
1408\r
1409 This = &gSnpNt32GlobalData;\r
1410\r
1411 Status = NetLibDefaultUnload (ImageHandle);\r
1412\r
1413 if (EFI_ERROR (Status)) {\r
1414 return Status;\r
1415 }\r
1416\r
e90e8777 1417 while (!IsListEmpty (&This->InstanceList)) {\r
593a8308 1418 //\r
1419 // Walkthrough the interfaces and remove all the SNP instance\r
1420 //\r
1421 Entry = This->InstanceList.ForwardLink;\r
1422\r
1423 Instance = NET_LIST_USER_STRUCT_S (Entry, SNPNT32_INSTANCE_DATA, Entry, SNP_NT32_INSTANCE_SIGNATURE);\r
1424\r
e90e8777 1425 RemoveEntryList (Entry);\r
593a8308 1426\r
1427 This->CloseInstance (This, Instance);\r
e90e8777 1428 gBS->FreePool (Instance);\r
593a8308 1429 }\r
1430\r
1431 if (This->NtNetUtilityTable.Finalize != NULL) {\r
1432 This->NtNetUtilityTable.Finalize ();\r
1433 }\r
1434\r
1435 This->WinNtThunk->FreeLibrary (This->NetworkLibraryHandle);\r
1436\r
1437 return EFI_SUCCESS;\r
1438}\r
1439\r
531237a5 1440/**\r
1441 This is the declaration of an EFI image entry point. This entry point is\r
1442 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including\r
1443 both device drivers and bus drivers.\r
1444\r
1445 @param ImageHandle The firmware allocated handle for the UEFI image.\r
1446 @param SystemTable A pointer to the EFI System Table.\r
1447\r
1448 @retval EFI_SUCCESS The operation completed successfully.\r
1449 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
593a8308 1450\r
531237a5 1451**/\r
593a8308 1452EFI_STATUS\r
6c76a5da 1453InitializeSnpNt32Driver (\r
593a8308 1454 IN EFI_HANDLE ImageHandle,\r
1455 IN EFI_SYSTEM_TABLE *SystemTable\r
1456 )\r
593a8308 1457{\r
1458\r
1459 EFI_STATUS Status;\r
1460\r
1461 //\r
1462 // Install the Driver Protocols\r
1463 //\r
1464\r
057d744e 1465 Status = EfiLibInstallDriverBindingComponentName2 (\r
1466 ImageHandle,\r
1467 SystemTable,\r
1468 &gSnpNt32DriverBinding,\r
1469 ImageHandle,\r
1470 &gSnpNt32DriverComponentName,\r
1471 &gSnpNt32DriverComponentName2\r
1472 );\r
593a8308 1473 if (EFI_ERROR (Status)) {\r
1474 return Status;\r
1475 }\r
1476\r
1477 //\r
1478 // Initialize the global data\r
1479 //\r
1480 Status = SnpNt32InitializeGlobalData (&gSnpNt32GlobalData);\r
1481 if (EFI_ERROR (Status)) {\r
1482 SnpNt32Unload (ImageHandle);\r
1483 }\r
1484\r
1485 return Status;\r
1486}\r