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