1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 18 // Reference: 19 // https://uefi.org/specs/UEFI/2.10/24_Network_Protocols_SNP_PXE_BIS.html#simple-network-protocol 20 21 #ifndef __SIMPLE_NETWORK_PROTOCOL_H__ 22 #define __SIMPLE_NETWORK_PROTOCOL_H__ 23 24 #include <stddef.h> 25 26 #include "types.h" 27 28 #define EFI_SIMPLE_NETWORK_PROTOCOL_REVISION 0x00010000 29 #define EFI_SIMPLE_NETWORK_RECEIVE_UNICAST 0x01 30 #define EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST 0x02 31 #define EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST 0x04 32 #define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS 0x08 33 #define EFI_SIMPLE_NETWORK_RECEIVE_PROMISCUOUS_MULTICAST 0x10 34 35 #define MAX_MCAST_FILTER_CNT 16 36 37 typedef struct { 38 uint8_t addr[32]; 39 } EfiMacAddress; 40 41 typedef struct { 42 uint8_t addr[4]; 43 } EfiIpV4Address; 44 45 typedef struct { 46 uint8_t addr[16]; 47 } EfiIpV6Address; 48 49 typedef union { 50 EfiIpV4Address v4; 51 EfiIpV6Address v6; 52 uint32_t addr[4]; 53 } EfiIpAddr; 54 55 typedef struct { 56 uint32_t state; 57 uint32_t hw_address_size; 58 uint32_t media_header_size; 59 uint32_t max_packet_size; 60 uint32_t nv_ram_size; 61 uint32_t nv_ram_access_size; 62 uint32_t receive_filter_mask; 63 uint32_t receive_filter_setting; 64 uint32_t max_m_cast_filter_count; 65 uint32_t m_cast_filter_count; 66 EfiMacAddress m_cast_filter[MAX_MCAST_FILTER_CNT]; 67 EfiMacAddress current_address; 68 EfiMacAddress broadcast_address; 69 EfiMacAddress permanent_address; 70 uint8_t if_type; 71 bool mac_address_changeable; 72 bool multiple_tx_supported; 73 bool media_present_supported; 74 bool media_present; 75 } EfiSimpleNetworkMode; 76 77 typedef struct { 78 uint64_t rx_total_frames; 79 uint64_t rx_good_frames; 80 uint64_t rx_undersize_frames; 81 uint64_t rx_oversize_frames; 82 uint64_t rx_dropped_frames; 83 uint64_t rx_unicast_frames; 84 uint64_t rx_broadcast_frames; 85 uint64_t rx_multicast_frames; 86 uint64_t rx_crc_error_frames; 87 uint64_t rx_total_bytes; 88 uint64_t tx_total_frames; 89 uint64_t tx_good_frames; 90 uint64_t tx_undersize_frames; 91 uint64_t tx_oversize_frames; 92 uint64_t tx_dropped_frames; 93 uint64_t tx_unicast_frames; 94 uint64_t tx_broadcast_frames; 95 uint64_t tx_multicast_frames; 96 uint64_t tx_crc_error_frames; 97 uint64_t tx_total_bytes; 98 uint64_t collisions; 99 uint64_t unsupported_protocol; 100 uint64_t rx_duplicated_frames; 101 uint64_t rx_decrypt_error_frames; 102 uint64_t tx_error_frames; 103 uint64_t tx_retry_frames; 104 } EfiNetworkStatistics; 105 106 typedef struct EfiSimpleNetworkProtocol { 107 uint64_t revision; 108 EfiStatus (*start)(struct EfiSimpleNetworkProtocol* self); 109 EfiStatus (*stop)(struct EfiSimpleNetworkProtocol* self); 110 EfiStatus (*initialize)(struct EfiSimpleNetworkProtocol* self, size_t extra_rx_buffer_size, 111 size_t extra_tx_buffer_size); 112 EfiStatus (*reset)(struct EfiSimpleNetworkProtocol* self, bool extended_verification); 113 EfiStatus (*shutdown)(struct EfiSimpleNetworkProtocol* self); 114 EfiStatus (*receive_filters)(struct EfiSimpleNetworkProtocol* self, uint32_t enable, 115 uint32_t disable, bool reset_mcast_filter, size_t mcast_filter_count, 116 EfiMacAddress* mcast_filter); 117 EfiStatus (*station_address)(struct EfiSimpleNetworkProtocol* self, bool reset, 118 EfiMacAddress* new_addr); 119 EfiStatus (*statistics)(struct EfiSimpleNetworkProtocol* self, bool reset, size_t* stats_size, 120 EfiNetworkStatistics* stats_table); 121 EfiStatus (*m_cast_ip_to_mac)(struct EfiSimpleNetworkProtocol* self, bool ipv6, EfiIpAddr* ip, 122 EfiMacAddress* mac); 123 EfiStatus (*nv_data)(struct EfiSimpleNetworkProtocol* self, bool read_write, size_t offset, 124 size_t buf_size, void* buf); 125 EfiStatus (*get_status)(struct EfiSimpleNetworkProtocol* self, uint32_t* interrupt_status, 126 void** tx_buf); 127 EfiStatus (*transmit)(struct EfiSimpleNetworkProtocol* self, size_t header_size, size_t buf_size, 128 void* buf, EfiMacAddress* src, EfiMacAddress* dest, uint16_t* protocol); 129 EfiStatus (*receive)(struct EfiSimpleNetworkProtocol* self, size_t* header_size, size_t* buf_size, 130 void* buf, EfiMacAddress* src, EfiMacAddress* dest, uint16_t* protocol); 131 132 EfiEvent wait_for_packet; 133 EfiSimpleNetworkMode* mode; 134 } EfiSimpleNetworkProtocol; 135 136 #endif // __SIMPLE_NETWORK_PROTOCOL_H__ 137