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