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