2 Linux Packet Filter implementation of the EMU_SNP_PROTOCOL that allows the
3 emulator to get on real networks.
5 Currently only the Berkeley Packet Filter is fully implemented and this file
6 is just a template that needs to get filled in.
8 Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>
9 Portitions copyright (c) 2011, Apple Inc. All rights reserved.
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
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.
26 #define EMU_SNP_PRIVATE_SIGNATURE SIGNATURE_32('E', 'M', 's', 'n')
30 EMU_IO_THUNK_PROTOCOL
*Thunk
;
33 EMU_SNP_PROTOCOL EmuSnp
;
34 EFI_SIMPLE_NETWORK_MODE
*Mode
;
38 #define EMU_SNP_PRIVATE_DATA_FROM_THIS(a) \
39 CR(a, EMU_SNP_PRIVATE, EmuSnp, EMU_SNP_PRIVATE_SIGNATURE)
42 Register storage for SNP Mode.
44 @param This Protocol instance pointer.
45 @param Mode SimpleNetworkProtocol Mode structure passed into driver.
47 @retval EFI_SUCCESS The network interface was started.
48 @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
53 IN EMU_SNP_PROTOCOL
*This
,
54 IN EFI_SIMPLE_NETWORK_MODE
*Mode
57 EMU_SNP_PRIVATE
*Private
;
59 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
67 Changes the state of a network interface from "stopped" to "started".
69 @param This Protocol instance pointer.
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.
80 IN EMU_SNP_PROTOCOL
*This
83 EMU_SNP_PRIVATE
*Private
;
85 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
87 return EFI_UNSUPPORTED
;
91 Changes the state of a network interface from "started" to "stopped".
93 @param This Protocol instance pointer.
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.
104 IN EMU_SNP_PROTOCOL
*This
107 EMU_SNP_PRIVATE
*Private
;
109 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
111 return EFI_UNSUPPORTED
;
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.
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
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
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
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.
142 IN EMU_SNP_PROTOCOL
*This
,
143 IN UINTN ExtraRxBufferSize OPTIONAL
,
144 IN UINTN ExtraTxBufferSize OPTIONAL
147 EMU_SNP_PRIVATE
*Private
;
149 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
151 return EFI_UNSUPPORTED
;
155 Resets a network adapter and re-initializes it with the parameters that were
156 provided in the previous call to Initialize().
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
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.
172 IN EMU_SNP_PROTOCOL
*This
,
173 IN BOOLEAN ExtendedVerification
176 EMU_SNP_PRIVATE
*Private
;
178 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
180 return EFI_UNSUPPORTED
;
184 Resets a network adapter and leaves it in a state that is safe for
185 another driver to initialize.
187 @param This Protocol instance pointer.
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.
198 IN EMU_SNP_PROTOCOL
*This
201 EMU_SNP_PRIVATE
*Private
;
203 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
205 return EFI_UNSUPPORTED
;
209 Manages the multicast receive filters of a network interface.
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.
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.
233 EmuSnpReceiveFilters (
234 IN EMU_SNP_PROTOCOL
*This
,
237 IN BOOLEAN ResetMCastFilter
,
238 IN UINTN MCastFilterCnt OPTIONAL
,
239 IN EFI_MAC_ADDRESS
*MCastFilter OPTIONAL
242 EMU_SNP_PRIVATE
*Private
;
244 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
246 return EFI_UNSUPPORTED
;
250 Modifies or resets the current station address, if supported.
252 @param This The protocol instance pointer.
253 @param Reset Flag used to reset the station address to the network interfaces
255 @param New The new station address to be used for the network interface.
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.
265 EmuSnpStationAddress (
266 IN EMU_SNP_PROTOCOL
*This
,
268 IN EFI_MAC_ADDRESS
*New OPTIONAL
271 EMU_SNP_PRIVATE
*Private
;
273 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
275 return EFI_UNSUPPORTED
;
279 Resets or collects the statistics on a network interface.
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
286 @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
287 contains the statistics.
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
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.
301 IN EMU_SNP_PROTOCOL
*This
,
303 IN OUT UINTN
*StatisticsSize OPTIONAL
,
304 OUT EFI_NETWORK_STATISTICS
*StatisticsTable OPTIONAL
307 EMU_SNP_PRIVATE
*Private
;
309 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
311 return EFI_UNSUPPORTED
;
315 Converts a multicast IP address to a multicast HW MAC address.
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
322 @param MAC The multicast HW MAC address that is to be generated from IP.
324 @retval EFI_SUCCESS The multicast IP address was mapped to the multicast
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
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.
337 IN EMU_SNP_PROTOCOL
*This
,
339 IN EFI_IP_ADDRESS
*IP
,
340 OUT EFI_MAC_ADDRESS
*MAC
343 EMU_SNP_PRIVATE
*Private
;
345 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
347 return EFI_UNSUPPORTED
;
351 Performs read and write operations on the NVRAM device attached to a
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
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.
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.
372 IN EMU_SNP_PROTOCOL
*This
,
373 IN BOOLEAN ReadWrite
,
379 EMU_SNP_PRIVATE
*Private
;
381 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
383 return EFI_UNSUPPORTED
;
387 Reads the current interrupt status and recycled transmit buffer status from
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.
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.
413 IN EMU_SNP_PROTOCOL
*This
,
414 OUT UINT32
*InterruptStatus OPTIONAL
,
415 OUT VOID
**TxBuf OPTIONAL
418 EMU_SNP_PRIVATE
*Private
;
420 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
422 return EFI_UNSUPPORTED
;
426 Places a packet in the transmit queue of a network interface.
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
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.
460 IN EMU_SNP_PROTOCOL
*This
,
464 IN EFI_MAC_ADDRESS
*SrcAddr OPTIONAL
,
465 IN EFI_MAC_ADDRESS
*DestAddr OPTIONAL
,
466 IN UINT16
*Protocol OPTIONAL
469 EMU_SNP_PRIVATE
*Private
;
471 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
473 return EFI_UNSUPPORTED
;
477 Receives a packet from a network interface.
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
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
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
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.
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
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.
510 IN EMU_SNP_PROTOCOL
*This
,
511 OUT UINTN
*HeaderSize OPTIONAL
,
512 IN OUT UINTN
*BufferSize
,
514 OUT EFI_MAC_ADDRESS
*SrcAddr OPTIONAL
,
515 OUT EFI_MAC_ADDRESS
*DestAddr OPTIONAL
,
516 OUT UINT16
*Protocol OPTIONAL
519 EMU_SNP_PRIVATE
*Private
;
521 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
523 return EFI_UNSUPPORTED
;
527 EMU_SNP_PROTOCOL gEmuSnpProtocol
= {
528 GasketSnpCreateMapping
,
534 GasketSnpReceiveFilters
,
535 GasketSnpStationAddress
,
537 GasketSnpMCastIpToMac
,
546 IN EMU_IO_THUNK_PROTOCOL
*This
549 EMU_SNP_PRIVATE
*Private
;
551 if (This
->Private
!= NULL
) {
552 return EFI_ALREADY_STARTED
;
555 if (!CompareGuid (This
->Protocol
, &gEmuSnpProtocolGuid
)) {
556 return EFI_UNSUPPORTED
;
559 Private
= malloc (sizeof (EMU_SNP_PRIVATE
));
560 if (Private
== NULL
) {
561 return EFI_OUT_OF_RESOURCES
;
565 Private
->Signature
= EMU_SNP_PRIVATE_SIGNATURE
;
566 Private
->Thunk
= This
;
567 CopyMem (&Private
->EmuSnp
, &gEmuSnpProtocol
, sizeof (gEmuSnpProtocol
));
569 This
->Interface
= &Private
->EmuSnp
;
570 This
->Private
= Private
;
577 IN EMU_IO_THUNK_PROTOCOL
*This
580 EMU_SNP_PRIVATE
*Private
;
582 if (!CompareGuid (This
->Protocol
, &gEmuSnpProtocolGuid
)) {
583 return EFI_UNSUPPORTED
;
586 Private
= This
->Private
;
594 EMU_IO_THUNK_PROTOCOL gSnpThunkIo
= {
595 &gEmuSnpProtocolGuid
,