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 Portions copyright (c) 2011, Apple Inc. All rights reserved.
11 SPDX-License-Identifier: BSD-2-Clause-Patent
20 #define EMU_SNP_PRIVATE_SIGNATURE SIGNATURE_32('E', 'M', 's', 'n')
24 EMU_IO_THUNK_PROTOCOL
*Thunk
;
27 EMU_SNP_PROTOCOL EmuSnp
;
28 EFI_SIMPLE_NETWORK_MODE
*Mode
;
32 #define EMU_SNP_PRIVATE_DATA_FROM_THIS(a) \
33 CR(a, EMU_SNP_PRIVATE, EmuSnp, EMU_SNP_PRIVATE_SIGNATURE)
36 Register storage for SNP Mode.
38 @param This Protocol instance pointer.
39 @param Mode SimpleNetworkProtocol Mode structure passed into driver.
41 @retval EFI_SUCCESS The network interface was started.
42 @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.
47 IN EMU_SNP_PROTOCOL
*This
,
48 IN EFI_SIMPLE_NETWORK_MODE
*Mode
51 EMU_SNP_PRIVATE
*Private
;
53 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
61 Changes the state of a network interface from "stopped" to "started".
63 @param This Protocol instance pointer.
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.
74 IN EMU_SNP_PROTOCOL
*This
77 EMU_SNP_PRIVATE
*Private
;
79 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
81 return EFI_UNSUPPORTED
;
85 Changes the state of a network interface from "started" to "stopped".
87 @param This Protocol instance pointer.
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.
98 IN EMU_SNP_PROTOCOL
*This
101 EMU_SNP_PRIVATE
*Private
;
103 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
105 return EFI_UNSUPPORTED
;
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.
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
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
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
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.
136 IN EMU_SNP_PROTOCOL
*This
,
137 IN UINTN ExtraRxBufferSize OPTIONAL
,
138 IN UINTN ExtraTxBufferSize OPTIONAL
141 EMU_SNP_PRIVATE
*Private
;
143 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
145 return EFI_UNSUPPORTED
;
149 Resets a network adapter and re-initializes it with the parameters that were
150 provided in the previous call to Initialize().
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
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.
166 IN EMU_SNP_PROTOCOL
*This
,
167 IN BOOLEAN ExtendedVerification
170 EMU_SNP_PRIVATE
*Private
;
172 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
174 return EFI_UNSUPPORTED
;
178 Resets a network adapter and leaves it in a state that is safe for
179 another driver to initialize.
181 @param This Protocol instance pointer.
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.
192 IN EMU_SNP_PROTOCOL
*This
195 EMU_SNP_PRIVATE
*Private
;
197 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
199 return EFI_UNSUPPORTED
;
203 Manages the multicast receive filters of a network interface.
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.
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.
227 EmuSnpReceiveFilters (
228 IN EMU_SNP_PROTOCOL
*This
,
231 IN BOOLEAN ResetMCastFilter
,
232 IN UINTN MCastFilterCnt OPTIONAL
,
233 IN EFI_MAC_ADDRESS
*MCastFilter OPTIONAL
236 EMU_SNP_PRIVATE
*Private
;
238 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
240 return EFI_UNSUPPORTED
;
244 Modifies or resets the current station address, if supported.
246 @param This The protocol instance pointer.
247 @param Reset Flag used to reset the station address to the network interfaces
249 @param New The new station address to be used for the network interface.
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.
259 EmuSnpStationAddress (
260 IN EMU_SNP_PROTOCOL
*This
,
262 IN EFI_MAC_ADDRESS
*New OPTIONAL
265 EMU_SNP_PRIVATE
*Private
;
267 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
269 return EFI_UNSUPPORTED
;
273 Resets or collects the statistics on a network interface.
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
280 @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that
281 contains the statistics.
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
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.
295 IN EMU_SNP_PROTOCOL
*This
,
297 IN OUT UINTN
*StatisticsSize OPTIONAL
,
298 OUT EFI_NETWORK_STATISTICS
*StatisticsTable OPTIONAL
301 EMU_SNP_PRIVATE
*Private
;
303 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
305 return EFI_UNSUPPORTED
;
309 Converts a multicast IP address to a multicast HW MAC address.
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
316 @param MAC The multicast HW MAC address that is to be generated from IP.
318 @retval EFI_SUCCESS The multicast IP address was mapped to the multicast
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
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.
331 IN EMU_SNP_PROTOCOL
*This
,
333 IN EFI_IP_ADDRESS
*IP
,
334 OUT EFI_MAC_ADDRESS
*MAC
337 EMU_SNP_PRIVATE
*Private
;
339 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
341 return EFI_UNSUPPORTED
;
345 Performs read and write operations on the NVRAM device attached to a
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
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.
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.
366 IN EMU_SNP_PROTOCOL
*This
,
367 IN BOOLEAN ReadWrite
,
373 EMU_SNP_PRIVATE
*Private
;
375 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
377 return EFI_UNSUPPORTED
;
381 Reads the current interrupt status and recycled transmit buffer status from
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.
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.
407 IN EMU_SNP_PROTOCOL
*This
,
408 OUT UINT32
*InterruptStatus OPTIONAL
,
409 OUT VOID
**TxBuf OPTIONAL
412 EMU_SNP_PRIVATE
*Private
;
414 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
416 return EFI_UNSUPPORTED
;
420 Places a packet in the transmit queue of a network interface.
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
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.
454 IN EMU_SNP_PROTOCOL
*This
,
458 IN EFI_MAC_ADDRESS
*SrcAddr OPTIONAL
,
459 IN EFI_MAC_ADDRESS
*DestAddr OPTIONAL
,
460 IN UINT16
*Protocol OPTIONAL
463 EMU_SNP_PRIVATE
*Private
;
465 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
467 return EFI_UNSUPPORTED
;
471 Receives a packet from a network interface.
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
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
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
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.
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
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.
504 IN EMU_SNP_PROTOCOL
*This
,
505 OUT UINTN
*HeaderSize OPTIONAL
,
506 IN OUT UINTN
*BufferSize
,
508 OUT EFI_MAC_ADDRESS
*SrcAddr OPTIONAL
,
509 OUT EFI_MAC_ADDRESS
*DestAddr OPTIONAL
,
510 OUT UINT16
*Protocol OPTIONAL
513 EMU_SNP_PRIVATE
*Private
;
515 Private
= EMU_SNP_PRIVATE_DATA_FROM_THIS (This
);
517 return EFI_UNSUPPORTED
;
521 EMU_SNP_PROTOCOL gEmuSnpProtocol
= {
522 GasketSnpCreateMapping
,
528 GasketSnpReceiveFilters
,
529 GasketSnpStationAddress
,
531 GasketSnpMCastIpToMac
,
540 IN EMU_IO_THUNK_PROTOCOL
*This
543 EMU_SNP_PRIVATE
*Private
;
545 if (This
->Private
!= NULL
) {
546 return EFI_ALREADY_STARTED
;
549 if (!CompareGuid (This
->Protocol
, &gEmuSnpProtocolGuid
)) {
550 return EFI_UNSUPPORTED
;
553 Private
= malloc (sizeof (EMU_SNP_PRIVATE
));
554 if (Private
== NULL
) {
555 return EFI_OUT_OF_RESOURCES
;
559 Private
->Signature
= EMU_SNP_PRIVATE_SIGNATURE
;
560 Private
->Thunk
= This
;
561 CopyMem (&Private
->EmuSnp
, &gEmuSnpProtocol
, sizeof (gEmuSnpProtocol
));
563 This
->Interface
= &Private
->EmuSnp
;
564 This
->Private
= Private
;
571 IN EMU_IO_THUNK_PROTOCOL
*This
574 EMU_SNP_PRIVATE
*Private
;
576 if (!CompareGuid (This
->Protocol
, &gEmuSnpProtocolGuid
)) {
577 return EFI_UNSUPPORTED
;
580 Private
= This
->Private
;
588 EMU_IO_THUNK_PROTOCOL gSnpThunkIo
= {
589 &gEmuSnpProtocolGuid
,