]> git.proxmox.com Git - mirror_edk2.git/blame - Nt32Pkg/SnpNt32Dxe/SnpNt32.c
We enabled X64 native version NT32, and made it works on Windows 7 X64 OS.
[mirror_edk2.git] / Nt32Pkg / SnpNt32Dxe / SnpNt32.c
CommitLineData
593a8308 1/** @file\r
2\r
f66a43b2 3Copyright (c) 2006 - 2013, 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
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
7ee525b2 443 TRUE, // MediaPresentSupported\r
531237a5 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
f66a43b2 707 (UINT32)McastFilterCount,\r
593a8308 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
f66a43b2 866 *((UINT8 **) TxBuffer) = (UINT8 *)(UINTN) 1;\r
593a8308 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
f66a43b2
JM
936 (UINT32)HeaderSize,\r
937 (UINT32)BufferSize,\r
593a8308 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
aaf779a7 998 UINTN BufSize;\r
999 \r
1000 BufSize = *BuffSize;\r
593a8308 1001\r
1002 Instance = SNP_NT32_INSTANCE_DATA_FROM_SNP_THIS (This);\r
1003\r
1004 GlobalData = Instance->GlobalData;\r
1005\r
1006 ASSERT (GlobalData->NtNetUtilityTable.Receive != NULL);\r
1007\r
e90e8777 1008 if (EFI_ERROR (EfiAcquireLockOrFail (&GlobalData->Lock))) {\r
593a8308 1009 return EFI_ACCESS_DENIED;\r
1010 }\r
1011\r
1012 ReturnValue = GlobalData->NtNetUtilityTable.Receive (\r
1013 Instance->InterfaceInfo.InterfaceIndex,\r
1014 BuffSize,\r
1015 Buffer\r
1016 );\r
1017\r
e90e8777 1018 EfiReleaseLock (&GlobalData->Lock);\r
593a8308 1019\r
1020 if (ReturnValue < 0) {\r
1021 if (ReturnValue == -100) {\r
1022 return EFI_BUFFER_TOO_SMALL;\r
1023 }\r
1024\r
1025 return EFI_DEVICE_ERROR;\r
1026 } else if (ReturnValue == 0) {\r
1027 return EFI_NOT_READY;\r
1028 }\r
1029\r
1030 if (HeaderSize != NULL) {\r
1031 *HeaderSize = 14;\r
1032 }\r
1033\r
1034 if (SourceAddr != NULL) {\r
e90e8777 1035 ZeroMem (SourceAddr, sizeof (EFI_MAC_ADDRESS));\r
1036 CopyMem (SourceAddr, ((UINT8 *) Buffer) + 6, 6);\r
593a8308 1037 }\r
1038\r
1039 if (DestinationAddr != NULL) {\r
e90e8777 1040 ZeroMem (DestinationAddr, sizeof (EFI_MAC_ADDRESS));\r
1041 CopyMem (DestinationAddr, ((UINT8 *) Buffer), 6);\r
593a8308 1042 }\r
1043\r
1044 if (Protocol != NULL) {\r
1045 *Protocol = NTOHS (*((UINT16 *) (((UINT8 *) Buffer) + 12)));\r
1046 }\r
1047\r
aaf779a7 1048 return (*BuffSize <= BufSize) ? EFI_SUCCESS : EFI_BUFFER_TOO_SMALL; \r
593a8308 1049}\r
1050\r
593a8308 1051/**\r
1052 Initialize the driver's global data.\r
1053\r
1054 @param This Pointer to the global context data.\r
1055\r
1056 @retval EFI_SUCCESS The global data is initialized.\r
1057 @retval EFI_NOT_FOUND The required DLL is not found.\r
531237a5 1058 @retval EFI_DEVICE_ERROR Error initialize network utility library.\r
1059 @retval EFI_OUT_OF_RESOURCES Out of resource.\r
1060 @retval other Other errors.\r
593a8308 1061\r
1062**/\r
1063EFI_STATUS\r
1064SnpNt32InitializeGlobalData (\r
531237a5 1065 IN OUT SNPNT32_GLOBAL_DATA *This\r
593a8308 1066 )\r
1067{\r
1068 EFI_STATUS Status;\r
1069 CHAR16 *DllFileNameU;\r
1070 UINT32 Index;\r
1071 INT32 ReturnValue;\r
1072 BOOLEAN NetUtilityLibInitDone;\r
1073 NT_NET_INTERFACE_INFO NetInterfaceInfoBuffer[MAX_INTERFACE_INFO_NUMBER];\r
1074 SNPNT32_INSTANCE_DATA *Instance;\r
e90e8777 1075 LIST_ENTRY *Entry;\r
593a8308 1076 UINT32 InterfaceCount;\r
1077\r
1078 ASSERT (This != NULL);\r
1079\r
1080 NetUtilityLibInitDone = FALSE;\r
1081 InterfaceCount = MAX_INTERFACE_INFO_NUMBER;\r
1082\r
e90e8777 1083 InitializeListHead (&This->InstanceList);\r
1084 EfiInitializeLock (&This->Lock, TPL_CALLBACK);\r
593a8308 1085\r
1086 //\r
1087 // Get the WinNT thunk\r
1088 //\r
a00ec39b 1089 Status = gBS->LocateProtocol (&gEfiWinNtThunkProtocolGuid, NULL, (VOID **)&This->WinNtThunk);\r
593a8308 1090\r
1091 if (EFI_ERROR (Status)) {\r
1092 return Status;\r
1093 }\r
1094\r
1095 ASSERT (This->WinNtThunk != NULL);\r
1096\r
1097 DllFileNameU = NETWORK_LIBRARY_NAME_U;\r
1098\r
1099 //\r
1100 // Load network utility library\r
1101 //\r
1102 This->NetworkLibraryHandle = This->WinNtThunk->LoadLibraryEx (DllFileNameU, NULL, 0);\r
1103\r
1104 if (NULL == This->NetworkLibraryHandle) {\r
1105 return EFI_NOT_FOUND;\r
1106 }\r
1107\r
1108 This->NtNetUtilityTable.Initialize = (NT_NET_INITIALIZE) This->WinNtThunk->GetProcAddress (\r
531237a5 1109 This->NetworkLibraryHandle,\r
1110 NETWORK_LIBRARY_INITIALIZE\r
1111 );\r
593a8308 1112\r
1113 if (NULL == This->NtNetUtilityTable.Initialize) {\r
1114 Status = EFI_NOT_FOUND;\r
1115 goto ErrorReturn;\r
1116 }\r
1117\r
1118 This->NtNetUtilityTable.Finalize = (NT_NET_FINALIZE) This->WinNtThunk->GetProcAddress (\r
531237a5 1119 This->NetworkLibraryHandle,\r
1120 NETWORK_LIBRARY_FINALIZE\r
1121 );\r
593a8308 1122\r
1123 if (NULL == This->NtNetUtilityTable.Finalize) {\r
1124 Status = EFI_NOT_FOUND;\r
1125 goto ErrorReturn;\r
1126 }\r
1127\r
1128 This->NtNetUtilityTable.SetReceiveFilter = (NT_NET_SET_RECEIVE_FILTER) This->WinNtThunk->GetProcAddress (\r
531237a5 1129 This->NetworkLibraryHandle,\r
1130 NETWORK_LIBRARY_SET_RCV_FILTER\r
1131 );\r
593a8308 1132\r
1133 if (NULL == This->NtNetUtilityTable.SetReceiveFilter) {\r
1134 Status = EFI_NOT_FOUND;\r
1135 goto ErrorReturn;\r
1136 }\r
1137\r
1138 This->NtNetUtilityTable.Receive = (NT_NET_RECEIVE) This->WinNtThunk->GetProcAddress (\r
531237a5 1139 This->NetworkLibraryHandle,\r
1140 NETWORK_LIBRARY_RECEIVE\r
1141 );\r
593a8308 1142\r
1143 if (NULL == This->NtNetUtilityTable.Receive) {\r
1144 Status = EFI_NOT_FOUND;\r
1145 goto ErrorReturn;\r
1146 }\r
1147\r
1148 This->NtNetUtilityTable.Transmit = (NT_NET_TRANSMIT) This->WinNtThunk->GetProcAddress (\r
531237a5 1149 This->NetworkLibraryHandle,\r
1150 NETWORK_LIBRARY_TRANSMIT\r
1151 );\r
593a8308 1152\r
1153 if (NULL == This->NtNetUtilityTable.Transmit) {\r
1154 Status = EFI_NOT_FOUND;\r
1155 goto ErrorReturn;\r
1156 }\r
1157 //\r
1158 // Initialize the network utility library\r
1159 // And enumerate the interfaces in NT32 host\r
1160 //\r
1161 ReturnValue = This->NtNetUtilityTable.Initialize (&InterfaceCount, &NetInterfaceInfoBuffer[0]);\r
1162 if (ReturnValue <= 0) {\r
1163 Status = EFI_DEVICE_ERROR;\r
1164 goto ErrorReturn;\r
1165 }\r
1166\r
1167 NetUtilityLibInitDone = TRUE;\r
1168\r
1169 if (InterfaceCount == 0) {\r
1170 Status = EFI_NOT_FOUND;\r
1171 goto ErrorReturn;\r
1172 }\r
1173 //\r
1174 // Create fake SNP instances\r
1175 //\r
1176 for (Index = 0; Index < InterfaceCount; Index++) {\r
1177\r
e90e8777 1178 Instance = AllocatePool (sizeof (SNPNT32_INSTANCE_DATA));\r
593a8308 1179\r
1180 if (NULL == Instance) {\r
1181 Status = EFI_OUT_OF_RESOURCES;\r
1182 goto ErrorReturn;\r
1183 }\r
1184 //\r
1185 // Copy the content from a template\r
1186 //\r
e90e8777 1187 CopyMem (Instance, &gSnpNt32InstanceTemplate, sizeof (SNPNT32_INSTANCE_DATA));\r
593a8308 1188\r
1189 //\r
1190 // Set the interface information.\r
1191 //\r
f66a43b2 1192 CopyMem (&Instance->InterfaceInfo, &NetInterfaceInfoBuffer[Index], sizeof(Instance->InterfaceInfo));\r
593a8308 1193 //\r
1194 // Initialize this instance\r
1195 //\r
1196 Status = This->InitializeInstanceData (This, Instance);\r
1197 if (EFI_ERROR (Status)) {\r
1198\r
e90e8777 1199 gBS->FreePool (Instance);\r
593a8308 1200 goto ErrorReturn;\r
1201 }\r
1202 //\r
1203 // Insert this instance into the instance list\r
1204 //\r
e90e8777 1205 InsertTailList (&This->InstanceList, &Instance->Entry);\r
593a8308 1206 }\r
1207\r
1208 return EFI_SUCCESS;\r
1209\r
1210ErrorReturn:\r
1211\r
e90e8777 1212 while (!IsListEmpty (&This->InstanceList)) {\r
593a8308 1213\r
1214 Entry = This->InstanceList.ForwardLink;\r
1215\r
1216 Instance = NET_LIST_USER_STRUCT_S (Entry, SNPNT32_INSTANCE_DATA, Entry, SNP_NT32_INSTANCE_SIGNATURE);\r
1217\r
e90e8777 1218 RemoveEntryList (Entry);\r
593a8308 1219\r
1220 This->CloseInstance (This, Instance);\r
e90e8777 1221 gBS->FreePool (Instance);\r
593a8308 1222 }\r
1223\r
1224 if (NetUtilityLibInitDone) {\r
1225\r
1226 ASSERT (This->WinNtThunk != NULL);\r
1227\r
1228 if (This->NtNetUtilityTable.Finalize != NULL) {\r
1229 This->NtNetUtilityTable.Finalize ();\r
1230 This->NtNetUtilityTable.Finalize = NULL;\r
1231 }\r
1232 }\r
1233\r
1234 return Status;\r
1235}\r
1236\r
1237\r
1238/**\r
1239 Initialize the snpnt32 driver instance.\r
1240\r
1241 @param This Pointer to the SnpNt32 global data.\r
1242 @param Instance Pointer to the instance context data.\r
1243\r
1244 @retval EFI_SUCCESS The driver instance is initialized.\r
531237a5 1245 @retval other Initialization errors.\r
593a8308 1246\r
1247**/\r
1248EFI_STATUS\r
1249SnpNt32InitializeInstanceData (\r
531237a5 1250 IN SNPNT32_GLOBAL_DATA *This,\r
1251 IN OUT SNPNT32_INSTANCE_DATA *Instance\r
593a8308 1252 )\r
1253{\r
1254 EFI_STATUS Status;\r
1255 EFI_DEV_PATH EndNode;\r
1256 EFI_DEV_PATH Node;\r
1257\r
1258 Instance->GlobalData = This;\r
1259 Instance->Snp.Mode = &Instance->Mode;\r
1260 //\r
1261 // Set broadcast address\r
1262 //\r
1263 SetMem (&Instance->Mode.BroadcastAddress, sizeof (EFI_MAC_ADDRESS), 0xFF);\r
1264\r
1265 //\r
1266 // Copy Current/PermanentAddress MAC address\r
1267 //\r
f66a43b2
JM
1268 CopyMem (&Instance->Mode.CurrentAddress, &Instance->InterfaceInfo.MacAddr, sizeof(Instance->Mode.CurrentAddress));\r
1269 CopyMem (&Instance->Mode.PermanentAddress, &Instance->InterfaceInfo.MacAddr, sizeof(Instance->Mode.PermanentAddress));\r
593a8308 1270\r
1271 //\r
1272 // Since the fake SNP is based on a real NIC, to avoid conflict with the host\r
1273 // NIC network stack, we use a different MAC address.\r
1274 // So just change the last byte of the MAC address for the real NIC.\r
1275 //\r
1276 Instance->Mode.CurrentAddress.Addr[NET_ETHER_ADDR_LEN - 1]++;\r
1277\r
1278 //\r
1279 // Create a fake device path for the instance\r
1280 //\r
e90e8777 1281 ZeroMem (&Node, sizeof (Node));\r
593a8308 1282\r
1283 Node.DevPath.Type = MESSAGING_DEVICE_PATH;\r
1284 Node.DevPath.SubType = MSG_MAC_ADDR_DP;\r
1285 SetDevicePathNodeLength (&Node.DevPath, sizeof (MAC_ADDR_DEVICE_PATH));\r
1286\r
e90e8777 1287 CopyMem (\r
593a8308 1288 &Node.MacAddr.MacAddress,\r
1289 &Instance->Mode.CurrentAddress,\r
4324075f 1290 NET_ETHER_ADDR_LEN\r
593a8308 1291 );\r
1292\r
1293 Node.MacAddr.IfType = Instance->Mode.IfType;\r
1294\r
1295 SetDevicePathEndNode (&EndNode.DevPath);\r
1296\r
1297 Instance->DevicePath = AppendDevicePathNode (\r
531237a5 1298 &EndNode.DevPath,\r
1299 &Node.DevPath\r
1300 );\r
593a8308 1301\r
1302 //\r
1303 // Create a fake device handle for the fake SNP\r
1304 //\r
1305 Status = gBS->InstallMultipleProtocolInterfaces (\r
1306 &Instance->DeviceHandle,\r
1307 &gEfiSimpleNetworkProtocolGuid,\r
1308 &Instance->Snp,\r
1309 &gEfiDevicePathProtocolGuid,\r
1310 Instance->DevicePath,\r
1311 NULL\r
1312 );\r
593a8308 1313 return Status;\r
1314}\r
1315\r
1316\r
1317/**\r
1318 Close the SnpNt32 driver instance.\r
1319\r
1320 @param This Pointer to the SnpNt32 global data.\r
1321 @param Instance Pointer to the instance context data.\r
1322\r
1323 @retval EFI_SUCCESS The instance is closed.\r
1324\r
1325**/\r
1326EFI_STATUS\r
1327SnpNt32CloseInstance (\r
531237a5 1328 IN SNPNT32_GLOBAL_DATA *This,\r
1329 IN OUT SNPNT32_INSTANCE_DATA *Instance\r
593a8308 1330 )\r
1331{\r
1332 ASSERT (This != NULL);\r
1333 ASSERT (Instance != NULL);\r
1334\r
1335 gBS->UninstallMultipleProtocolInterfaces (\r
531237a5 1336 Instance->DeviceHandle,\r
1337 &gEfiSimpleNetworkProtocolGuid,\r
1338 &Instance->Snp,\r
1339 &gEfiDevicePathProtocolGuid,\r
1340 Instance->DevicePath,\r
1341 NULL\r
1342 );\r
593a8308 1343\r
1344 if (Instance->DevicePath != NULL) {\r
1345 gBS->FreePool (Instance->DevicePath);\r
1346 }\r
1347\r
1348 return EFI_SUCCESS;\r
1349}\r
1350\r
593a8308 1351/**\r
531237a5 1352 Unloads an image.\r
593a8308 1353\r
531237a5 1354 @param ImageHandle Handle that identifies the image to be unloaded.\r
593a8308 1355\r
531237a5 1356 @retval EFI_SUCCESS The image has been unloaded.\r
1357 @return Exit code from the image's unload handler\r
593a8308 1358\r
1359**/\r
1360EFI_STATUS\r
1361EFIAPI\r
1362SnpNt32Unload (\r
1363 IN EFI_HANDLE ImageHandle\r
1364 )\r
1365{\r
1366 EFI_STATUS Status;\r
1367 SNPNT32_GLOBAL_DATA *This;\r
e90e8777 1368 LIST_ENTRY *Entry;\r
593a8308 1369 SNPNT32_INSTANCE_DATA *Instance;\r
1370\r
1371 This = &gSnpNt32GlobalData;\r
1372\r
1373 Status = NetLibDefaultUnload (ImageHandle);\r
1374\r
1375 if (EFI_ERROR (Status)) {\r
1376 return Status;\r
1377 }\r
1378\r
e90e8777 1379 while (!IsListEmpty (&This->InstanceList)) {\r
593a8308 1380 //\r
1381 // Walkthrough the interfaces and remove all the SNP instance\r
1382 //\r
1383 Entry = This->InstanceList.ForwardLink;\r
1384\r
1385 Instance = NET_LIST_USER_STRUCT_S (Entry, SNPNT32_INSTANCE_DATA, Entry, SNP_NT32_INSTANCE_SIGNATURE);\r
1386\r
e90e8777 1387 RemoveEntryList (Entry);\r
593a8308 1388\r
1389 This->CloseInstance (This, Instance);\r
e90e8777 1390 gBS->FreePool (Instance);\r
593a8308 1391 }\r
1392\r
1393 if (This->NtNetUtilityTable.Finalize != NULL) {\r
1394 This->NtNetUtilityTable.Finalize ();\r
1395 }\r
1396\r
1397 This->WinNtThunk->FreeLibrary (This->NetworkLibraryHandle);\r
1398\r
1399 return EFI_SUCCESS;\r
1400}\r
1401\r
531237a5 1402/**\r
1403 This is the declaration of an EFI image entry point. This entry point is\r
1404 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including\r
1405 both device drivers and bus drivers.\r
1406\r
1407 @param ImageHandle The firmware allocated handle for the UEFI image.\r
1408 @param SystemTable A pointer to the EFI System Table.\r
1409\r
1410 @retval EFI_SUCCESS The operation completed successfully.\r
1411 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
593a8308 1412\r
531237a5 1413**/\r
593a8308 1414EFI_STATUS\r
6c76a5da 1415InitializeSnpNt32Driver (\r
593a8308 1416 IN EFI_HANDLE ImageHandle,\r
1417 IN EFI_SYSTEM_TABLE *SystemTable\r
1418 )\r
593a8308 1419{\r
1420\r
1421 EFI_STATUS Status;\r
1422\r
1423 //\r
1424 // Install the Driver Protocols\r
1425 //\r
1426\r
057d744e 1427 Status = EfiLibInstallDriverBindingComponentName2 (\r
1428 ImageHandle,\r
1429 SystemTable,\r
1430 &gSnpNt32DriverBinding,\r
1431 ImageHandle,\r
1432 &gSnpNt32DriverComponentName,\r
1433 &gSnpNt32DriverComponentName2\r
1434 );\r
593a8308 1435 if (EFI_ERROR (Status)) {\r
1436 return Status;\r
1437 }\r
1438\r
1439 //\r
1440 // Initialize the global data\r
1441 //\r
1442 Status = SnpNt32InitializeGlobalData (&gSnpNt32GlobalData);\r
1443 if (EFI_ERROR (Status)) {\r
1444 SnpNt32Unload (ImageHandle);\r
1445 }\r
1446\r
1447 return Status;\r
1448}\r