1 /**@file
2  Linux Packet Filter implementation of the EMU_SNP_PROTOCOL that allows the
3  emulator to get on real networks.
4 
5  Currently only the Berkeley Packet Filter is fully implemented and this file
6  is just a template that needs to get filled in.
7 
8 Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>
9 Portitions copyright (c) 2011, Apple Inc. All rights reserved.
10 
11 SPDX-License-Identifier: BSD-2-Clause-Patent
12 
13 **/
14 
15 
16 #include "Host.h"
17 
18 #ifndef __APPLE__
19 
20 #define EMU_SNP_PRIVATE_SIGNATURE SIGNATURE_32('E', 'M', 's', 'n')
21 typedef struct {
22   UINTN                       Signature;
23 
24   EMU_IO_THUNK_PROTOCOL       *Thunk;
25 
26 
27   EMU_SNP_PROTOCOL            EmuSnp;
28   EFI_SIMPLE_NETWORK_MODE     *Mode;
29 
30 } EMU_SNP_PRIVATE;
31 
32 #define EMU_SNP_PRIVATE_DATA_FROM_THIS(a) \
33          CR(a, EMU_SNP_PRIVATE, EmuSnp, EMU_SNP_PRIVATE_SIGNATURE)
34 
35 /**
36   Register storage for SNP Mode.
37 
38   @param  This Protocol instance pointer.
39   @param  Mode SimpleNetworkProtocol Mode structure passed into driver.
40 
41   @retval EFI_SUCCESS           The network interface was started.
42   @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
43 
44 **/
45 EFI_STATUS
EmuSnpCreateMapping(IN EMU_SNP_PROTOCOL * This,IN EFI_SIMPLE_NETWORK_MODE * Mode)46 EmuSnpCreateMapping (
47   IN     EMU_SNP_PROTOCOL         *This,
48   IN     EFI_SIMPLE_NETWORK_MODE  *Mode
49   )
50 {
51   EMU_SNP_PRIVATE    *Private;
52 
53   Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
54 
55   Private->Mode = Mode;
56 
57   return EFI_SUCCESS;
58 }
59 
60 /**
61   Changes the state of a network interface from "stopped" to "started".
62 
63   @param  This Protocol instance pointer.
64 
65   @retval EFI_SUCCESS           The network interface was started.
66   @retval EFI_ALREADY_STARTED   The network interface is already in the started state.
67   @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
68   @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.
69   @retval EFI_UNSUPPORTED       This function is not supported by the network interface.
70 
71 **/
72 EFI_STATUS
EmuSnpStart(IN EMU_SNP_PROTOCOL * This)73 EmuSnpStart (
74   IN EMU_SNP_PROTOCOL  *This
75   )
76 {
77   EMU_SNP_PRIVATE    *Private;
78 
79   Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
80 
81   return EFI_UNSUPPORTED;
82 }
83 
84 /**
85   Changes the state of a network interface from "started" to "stopped".
86 
87   @param  This Protocol instance pointer.
88 
89   @retval EFI_SUCCESS           The network interface was stopped.
90   @retval EFI_ALREADY_STARTED   The network interface is already in the stopped state.
91   @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
92   @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.
93   @retval EFI_UNSUPPORTED       This function is not supported by the network interface.
94 
95 **/
96 EFI_STATUS
EmuSnpStop(IN EMU_SNP_PROTOCOL * This)97 EmuSnpStop (
98   IN EMU_SNP_PROTOCOL  *This
99   )
100 {
101   EMU_SNP_PRIVATE    *Private;
102 
103   Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
104 
105   return EFI_UNSUPPORTED;
106 }
107 
108 /**
109   Resets a network adapter and allocates the transmit and receive buffers
110   required by the network interface; optionally, also requests allocation
111   of additional transmit and receive buffers.
112 
113   @param  This              The protocol instance pointer.
114   @param  ExtraRxBufferSize The size, in bytes, of the extra receive buffer space
115                             that the driver should allocate for the network interface.
116                             Some network interfaces will not be able to use the extra
117                             buffer, and the caller will not know if it is actually
118                             being used.
119   @param  ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space
120                             that the driver should allocate for the network interface.
121                             Some network interfaces will not be able to use the extra
122                             buffer, and the caller will not know if it is actually
123                             being used.
124 
125   @retval EFI_SUCCESS           The network interface was initialized.
126   @retval EFI_NOT_STARTED       The network interface has not been started.
127   @retval EFI_OUT_OF_RESOURCES  There was not enough memory for the transmit and
128                                 receive buffers.
129   @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
130   @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.
131   @retval EFI_UNSUPPORTED       This function is not supported by the network interface.
132 
133 **/
134 EFI_STATUS
EmuSnpInitialize(IN EMU_SNP_PROTOCOL * This,IN UINTN ExtraRxBufferSize OPTIONAL,IN UINTN ExtraTxBufferSize OPTIONAL)135 EmuSnpInitialize (
136   IN EMU_SNP_PROTOCOL                    *This,
137   IN UINTN                               ExtraRxBufferSize  OPTIONAL,
138   IN UINTN                               ExtraTxBufferSize  OPTIONAL
139   )
140 {
141   EMU_SNP_PRIVATE    *Private;
142 
143   Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
144 
145   return EFI_UNSUPPORTED;
146 }
147 
148 /**
149   Resets a network adapter and re-initializes it with the parameters that were
150   provided in the previous call to Initialize().
151 
152   @param  This                 The protocol instance pointer.
153   @param  ExtendedVerification Indicates that the driver may perform a more
154                                exhaustive verification operation of the device
155                                during reset.
156 
157   @retval EFI_SUCCESS           The network interface was reset.
158   @retval EFI_NOT_STARTED       The network interface has not been started.
159   @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
160   @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.
161   @retval EFI_UNSUPPORTED       This function is not supported by the network interface.
162 
163 **/
164 EFI_STATUS
EmuSnpReset(IN EMU_SNP_PROTOCOL * This,IN BOOLEAN ExtendedVerification)165 EmuSnpReset (
166   IN EMU_SNP_PROTOCOL   *This,
167   IN BOOLEAN            ExtendedVerification
168   )
169 {
170   EMU_SNP_PRIVATE    *Private;
171 
172   Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
173 
174   return EFI_UNSUPPORTED;
175 }
176 
177 /**
178   Resets a network adapter and leaves it in a state that is safe for
179   another driver to initialize.
180 
181   @param  This Protocol instance pointer.
182 
183   @retval EFI_SUCCESS           The network interface was shutdown.
184   @retval EFI_NOT_STARTED       The network interface has not been started.
185   @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
186   @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.
187   @retval EFI_UNSUPPORTED       This function is not supported by the network interface.
188 
189 **/
190 EFI_STATUS
EmuSnpShutdown(IN EMU_SNP_PROTOCOL * This)191 EmuSnpShutdown (
192   IN EMU_SNP_PROTOCOL  *This
193   )
194 {
195   EMU_SNP_PRIVATE    *Private;
196 
197   Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
198 
199   return EFI_UNSUPPORTED;
200 }
201 
202 /**
203   Manages the multicast receive filters of a network interface.
204 
205   @param  This             The protocol instance pointer.
206   @param  Enable           A bit mask of receive filters to enable on the network interface.
207   @param  Disable          A bit mask of receive filters to disable on the network interface.
208   @param  ResetMCastFilter Set to TRUE to reset the contents of the multicast receive
209                            filters on the network interface to their default values.
210   @param  McastFilterCnt   Number of multicast HW MAC addresses in the new
211                            MCastFilter list. This value must be less than or equal to
212                            the MCastFilterCnt field of EMU_SNP_MODE. This
213                            field is optional if ResetMCastFilter is TRUE.
214   @param  MCastFilter      A pointer to a list of new multicast receive filter HW MAC
215                            addresses. This list will replace any existing multicast
216                            HW MAC address list. This field is optional if
217                            ResetMCastFilter is TRUE.
218 
219   @retval EFI_SUCCESS           The multicast receive filter list was updated.
220   @retval EFI_NOT_STARTED       The network interface has not been started.
221   @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
222   @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.
223   @retval EFI_UNSUPPORTED       This function is not supported by the network interface.
224 
225 **/
226 EFI_STATUS
EmuSnpReceiveFilters(IN EMU_SNP_PROTOCOL * This,IN UINT32 Enable,IN UINT32 Disable,IN BOOLEAN ResetMCastFilter,IN UINTN MCastFilterCnt OPTIONAL,IN EFI_MAC_ADDRESS * MCastFilter OPTIONAL)227 EmuSnpReceiveFilters (
228   IN EMU_SNP_PROTOCOL                             *This,
229   IN UINT32                                       Enable,
230   IN UINT32                                       Disable,
231   IN BOOLEAN                                      ResetMCastFilter,
232   IN UINTN                                        MCastFilterCnt     OPTIONAL,
233   IN EFI_MAC_ADDRESS                              *MCastFilter OPTIONAL
234   )
235 {
236   EMU_SNP_PRIVATE    *Private;
237 
238   Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
239 
240   return EFI_UNSUPPORTED;
241 }
242 
243 /**
244   Modifies or resets the current station address, if supported.
245 
246   @param  This  The protocol instance pointer.
247   @param  Reset Flag used to reset the station address to the network interfaces
248                 permanent address.
249   @param  New   The new station address to be used for the network interface.
250 
251   @retval EFI_SUCCESS           The network interfaces station address was updated.
252   @retval EFI_NOT_STARTED       The network interface has not been started.
253   @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
254   @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.
255   @retval EFI_UNSUPPORTED       This function is not supported by the network interface.
256 
257 **/
258 EFI_STATUS
EmuSnpStationAddress(IN EMU_SNP_PROTOCOL * This,IN BOOLEAN Reset,IN EFI_MAC_ADDRESS * New OPTIONAL)259 EmuSnpStationAddress (
260   IN EMU_SNP_PROTOCOL            *This,
261   IN BOOLEAN                     Reset,
262   IN EFI_MAC_ADDRESS             *New OPTIONAL
263   )
264 {
265   EMU_SNP_PRIVATE    *Private;
266 
267   Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
268 
269   return EFI_UNSUPPORTED;
270 }
271 
272 /**
273   Resets or collects the statistics on a network interface.
274 
275   @param  This            Protocol instance pointer.
276   @param  Reset           Set to TRUE to reset the statistics for the network interface.
277   @param  StatisticsSize  On input the size, in bytes, of StatisticsTable. On
278                           output the size, in bytes, of the resulting table of
279                           statistics.
280   @param  StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
281                           contains the statistics.
282 
283   @retval EFI_SUCCESS           The statistics were collected from the network interface.
284   @retval EFI_NOT_STARTED       The network interface has not been started.
285   @retval EFI_BUFFER_TOO_SMALL  The Statistics buffer was too small. The current buffer
286                                 size needed to hold the statistics is returned in
287                                 StatisticsSize.
288   @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
289   @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.
290   @retval EFI_UNSUPPORTED       This function is not supported by the network interface.
291 
292 **/
293 EFI_STATUS
EmuSnpStatistics(IN EMU_SNP_PROTOCOL * This,IN BOOLEAN Reset,IN OUT UINTN * StatisticsSize OPTIONAL,OUT EFI_NETWORK_STATISTICS * StatisticsTable OPTIONAL)294 EmuSnpStatistics (
295   IN EMU_SNP_PROTOCOL                     *This,
296   IN BOOLEAN                              Reset,
297   IN OUT UINTN                            *StatisticsSize   OPTIONAL,
298   OUT EFI_NETWORK_STATISTICS              *StatisticsTable  OPTIONAL
299   )
300 {
301   EMU_SNP_PRIVATE    *Private;
302 
303   Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
304 
305   return EFI_UNSUPPORTED;
306 }
307 
308 /**
309   Converts a multicast IP address to a multicast HW MAC address.
310 
311   @param  This The protocol instance pointer.
312   @param  IPv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set
313                to FALSE if the multicast IP address is IPv4 [RFC 791].
314   @param  IP   The multicast IP address that is to be converted to a multicast
315                HW MAC address.
316   @param  MAC  The multicast HW MAC address that is to be generated from IP.
317 
318   @retval EFI_SUCCESS           The multicast IP address was mapped to the multicast
319                                 HW MAC address.
320   @retval EFI_NOT_STARTED       The network interface has not been started.
321   @retval EFI_BUFFER_TOO_SMALL  The Statistics buffer was too small. The current buffer
322                                 size needed to hold the statistics is returned in
323                                 StatisticsSize.
324   @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
325   @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.
326   @retval EFI_UNSUPPORTED       This function is not supported by the network interface.
327 
328 **/
329 EFI_STATUS
EmuSnpMCastIpToMac(IN EMU_SNP_PROTOCOL * This,IN BOOLEAN IPv6,IN EFI_IP_ADDRESS * IP,OUT EFI_MAC_ADDRESS * MAC)330 EmuSnpMCastIpToMac (
331   IN EMU_SNP_PROTOCOL                     *This,
332   IN BOOLEAN                              IPv6,
333   IN EFI_IP_ADDRESS                       *IP,
334   OUT EFI_MAC_ADDRESS                     *MAC
335   )
336 {
337   EMU_SNP_PRIVATE    *Private;
338 
339   Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
340 
341   return EFI_UNSUPPORTED;
342 }
343 
344 /**
345   Performs read and write operations on the NVRAM device attached to a
346   network interface.
347 
348   @param  This       The protocol instance pointer.
349   @param  ReadWrite  TRUE for read operations, FALSE for write operations.
350   @param  Offset     Byte offset in the NVRAM device at which to start the read or
351                      write operation. This must be a multiple of NvRamAccessSize and
352                      less than NvRamSize.
353   @param  BufferSize The number of bytes to read or write from the NVRAM device.
354                      This must also be a multiple of NvramAccessSize.
355   @param  Buffer     A pointer to the data buffer.
356 
357   @retval EFI_SUCCESS           The NVRAM access was performed.
358   @retval EFI_NOT_STARTED       The network interface has not been started.
359   @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
360   @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.
361   @retval EFI_UNSUPPORTED       This function is not supported by the network interface.
362 
363 **/
364 EFI_STATUS
EmuSnpNvData(IN EMU_SNP_PROTOCOL * This,IN BOOLEAN ReadWrite,IN UINTN Offset,IN UINTN BufferSize,IN OUT VOID * Buffer)365 EmuSnpNvData (
366   IN EMU_SNP_PROTOCOL                     *This,
367   IN BOOLEAN                              ReadWrite,
368   IN UINTN                                Offset,
369   IN UINTN                                BufferSize,
370   IN OUT VOID                             *Buffer
371   )
372 {
373   EMU_SNP_PRIVATE    *Private;
374 
375   Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
376 
377   return EFI_UNSUPPORTED;
378 }
379 
380 /**
381   Reads the current interrupt status and recycled transmit buffer status from
382   a network interface.
383 
384   @param  This            The protocol instance pointer.
385   @param  InterruptStatus A pointer to the bit mask of the currently active interrupts
386                           If this is NULL, the interrupt status will not be read from
387                           the device. If this is not NULL, the interrupt status will
388                           be read from the device. When the  interrupt status is read,
389                           it will also be cleared. Clearing the transmit  interrupt
390                           does not empty the recycled transmit buffer array.
391   @param  TxBuf           Recycled transmit buffer address. The network interface will
392                           not transmit if its internal recycled transmit buffer array
393                           is full. Reading the transmit buffer does not clear the
394                           transmit interrupt. If this is NULL, then the transmit buffer
395                           status will not be read. If there are no transmit buffers to
396                           recycle and TxBuf is not NULL, * TxBuf will be set to NULL.
397 
398   @retval EFI_SUCCESS           The status of the network interface was retrieved.
399   @retval EFI_NOT_STARTED       The network interface has not been started.
400   @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
401   @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.
402   @retval EFI_UNSUPPORTED       This function is not supported by the network interface.
403 
404 **/
405 EFI_STATUS
EmuSnpGetStatus(IN EMU_SNP_PROTOCOL * This,OUT UINT32 * InterruptStatus OPTIONAL,OUT VOID ** TxBuf OPTIONAL)406 EmuSnpGetStatus (
407   IN EMU_SNP_PROTOCOL                     *This,
408   OUT UINT32                              *InterruptStatus OPTIONAL,
409   OUT VOID                                **TxBuf OPTIONAL
410   )
411 {
412   EMU_SNP_PRIVATE    *Private;
413 
414   Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
415 
416   return EFI_UNSUPPORTED;
417 }
418 
419 /**
420   Places a packet in the transmit queue of a network interface.
421 
422   @param  This       The protocol instance pointer.
423   @param  HeaderSize The size, in bytes, of the media header to be filled in by
424                      the Transmit() function. If HeaderSize is non-zero, then it
425                      must be equal to This->Mode->MediaHeaderSize and the DestAddr
426                      and Protocol parameters must not be NULL.
427   @param  BufferSize The size, in bytes, of the entire packet (media header and
428                      data) to be transmitted through the network interface.
429   @param  Buffer     A pointer to the packet (media header followed by data) to be
430                      transmitted. This parameter cannot be NULL. If HeaderSize is zero,
431                      then the media header in Buffer must already be filled in by the
432                      caller. If HeaderSize is non-zero, then the media header will be
433                      filled in by the Transmit() function.
434   @param  SrcAddr    The source HW MAC address. If HeaderSize is zero, then this parameter
435                      is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then
436                      This->Mode->CurrentAddress is used for the source HW MAC address.
437   @param  DestAddr   The destination HW MAC address. If HeaderSize is zero, then this
438                      parameter is ignored.
439   @param  Protocol   The type of header to build. If HeaderSize is zero, then this
440                      parameter is ignored. See RFC 1700, section "Ether Types", for
441                      examples.
442 
443   @retval EFI_SUCCESS           The packet was placed on the transmit queue.
444   @retval EFI_NOT_STARTED       The network interface has not been started.
445   @retval EFI_NOT_READY         The network interface is too busy to accept this transmit request.
446   @retval EFI_BUFFER_TOO_SMALL  The BufferSize parameter is too small.
447   @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
448   @retval EFI_DEVICE_ERROR      The command could not be sent to the network interface.
449   @retval EFI_UNSUPPORTED       This function is not supported by the network interface.
450 
451 **/
452 EFI_STATUS
EmuSnpTransmit(IN EMU_SNP_PROTOCOL * This,IN UINTN HeaderSize,IN UINTN BufferSize,IN VOID * Buffer,IN EFI_MAC_ADDRESS * SrcAddr OPTIONAL,IN EFI_MAC_ADDRESS * DestAddr OPTIONAL,IN UINT16 * Protocol OPTIONAL)453 EmuSnpTransmit (
454   IN EMU_SNP_PROTOCOL                     *This,
455   IN UINTN                                HeaderSize,
456   IN UINTN                                BufferSize,
457   IN VOID                                 *Buffer,
458   IN EFI_MAC_ADDRESS                      *SrcAddr  OPTIONAL,
459   IN EFI_MAC_ADDRESS                      *DestAddr OPTIONAL,
460   IN UINT16                               *Protocol OPTIONAL
461   )
462 {
463   EMU_SNP_PRIVATE    *Private;
464 
465   Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
466 
467   return EFI_UNSUPPORTED;
468 }
469 
470 /**
471   Receives a packet from a network interface.
472 
473   @param  This       The protocol instance pointer.
474   @param  HeaderSize The size, in bytes, of the media header received on the network
475                      interface. If this parameter is NULL, then the media header size
476                      will not be returned.
477   @param  BufferSize On entry, the size, in bytes, of Buffer. On exit, the size, in
478                      bytes, of the packet that was received on the network interface.
479   @param  Buffer     A pointer to the data buffer to receive both the media header and
480                      the data.
481   @param  SrcAddr    The source HW MAC address. If this parameter is NULL, the
482                      HW MAC source address will not be extracted from the media
483                      header.
484   @param  DestAddr   The destination HW MAC address. If this parameter is NULL,
485                      the HW MAC destination address will not be extracted from the
486                      media header.
487   @param  Protocol   The media header type. If this parameter is NULL, then the
488                      protocol will not be extracted from the media header. See
489                      RFC 1700 section "Ether Types" for examples.
490 
491   @retval  EFI_SUCCESS           The received data was stored in Buffer, and BufferSize has
492                                  been updated to the number of bytes received.
493   @retval  EFI_NOT_STARTED       The network interface has not been started.
494   @retval  EFI_NOT_READY         The network interface is too busy to accept this transmit
495                                  request.
496   @retval  EFI_BUFFER_TOO_SMALL  The BufferSize parameter is too small.
497   @retval  EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
498   @retval  EFI_DEVICE_ERROR      The command could not be sent to the network interface.
499   @retval  EFI_UNSUPPORTED       This function is not supported by the network interface.
500 
501 **/
502 EFI_STATUS
EmuSnpReceive(IN EMU_SNP_PROTOCOL * This,OUT UINTN * HeaderSize OPTIONAL,IN OUT UINTN * BufferSize,OUT VOID * Buffer,OUT EFI_MAC_ADDRESS * SrcAddr OPTIONAL,OUT EFI_MAC_ADDRESS * DestAddr OPTIONAL,OUT UINT16 * Protocol OPTIONAL)503 EmuSnpReceive (
504   IN EMU_SNP_PROTOCOL                     *This,
505   OUT UINTN                               *HeaderSize OPTIONAL,
506   IN OUT UINTN                            *BufferSize,
507   OUT VOID                                *Buffer,
508   OUT EFI_MAC_ADDRESS                     *SrcAddr    OPTIONAL,
509   OUT EFI_MAC_ADDRESS                     *DestAddr   OPTIONAL,
510   OUT UINT16                              *Protocol   OPTIONAL
511   )
512 {
513   EMU_SNP_PRIVATE    *Private;
514 
515   Private = EMU_SNP_PRIVATE_DATA_FROM_THIS (This);
516 
517   return EFI_UNSUPPORTED;
518 }
519 
520 
521 EMU_SNP_PROTOCOL gEmuSnpProtocol = {
522   GasketSnpCreateMapping,
523   GasketSnpStart,
524   GasketSnpStop,
525   GasketSnpInitialize,
526   GasketSnpReset,
527   GasketSnpShutdown,
528   GasketSnpReceiveFilters,
529   GasketSnpStationAddress,
530   GasketSnpStatistics,
531   GasketSnpMCastIpToMac,
532   GasketSnpNvData,
533   GasketSnpGetStatus,
534   GasketSnpTransmit,
535   GasketSnpReceive
536 };
537 
538 EFI_STATUS
EmuSnpThunkOpen(IN EMU_IO_THUNK_PROTOCOL * This)539 EmuSnpThunkOpen (
540   IN  EMU_IO_THUNK_PROTOCOL   *This
541   )
542 {
543   EMU_SNP_PRIVATE  *Private;
544 
545   if (This->Private != NULL) {
546     return EFI_ALREADY_STARTED;
547   }
548 
549   if (!CompareGuid (This->Protocol, &gEmuSnpProtocolGuid)) {
550     return EFI_UNSUPPORTED;
551   }
552 
553   Private = malloc (sizeof (EMU_SNP_PRIVATE));
554   if (Private == NULL) {
555     return EFI_OUT_OF_RESOURCES;
556   }
557 
558 
559   Private->Signature = EMU_SNP_PRIVATE_SIGNATURE;
560   Private->Thunk     = This;
561   CopyMem (&Private->EmuSnp, &gEmuSnpProtocol, sizeof (gEmuSnpProtocol));
562 
563   This->Interface = &Private->EmuSnp;
564   This->Private   = Private;
565   return EFI_SUCCESS;
566 }
567 
568 
569 EFI_STATUS
EmuSnpThunkClose(IN EMU_IO_THUNK_PROTOCOL * This)570 EmuSnpThunkClose (
571   IN  EMU_IO_THUNK_PROTOCOL   *This
572   )
573 {
574   EMU_SNP_PRIVATE  *Private;
575 
576   if (!CompareGuid (This->Protocol, &gEmuSnpProtocolGuid)) {
577     return EFI_UNSUPPORTED;
578   }
579 
580   Private = This->Private;
581   free (Private);
582 
583   return EFI_SUCCESS;
584 }
585 
586 
587 
588 EMU_IO_THUNK_PROTOCOL gSnpThunkIo = {
589   &gEmuSnpProtocolGuid,
590   NULL,
591   NULL,
592   0,
593   GasketSnpThunkOpen,
594   GasketSnpThunkClose,
595   NULL
596 };
597 
598 #endif
599