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