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 30 #define MAX_MCAST_FILTER_CNT 16 31 32 typedef struct { 33 uint8_t addr[32]; 34 } EfiMacAddress; 35 36 typedef struct { 37 uint8_t addr[4]; 38 } EfiIpV4Address; 39 40 typedef struct { 41 uint8_t addr[16]; 42 } EfiIpV6Address; 43 44 typedef union { 45 EfiIpV4Address v4; 46 EfiIpV6Address v6; 47 uint32_t addr[4]; 48 } EfiIpAddr; 49 50 typedef struct { 51 uint32_t state; 52 uint32_t hw_address_size; 53 uint32_t media_header_size; 54 uint32_t max_packet_size; 55 uint32_t nv_ram_size; 56 uint32_t nv_ram_access_size; 57 uint32_t receive_filter_mask; 58 uint32_t receive_filter_setting; 59 uint32_t max_m_cast_filter_count; 60 uint32_t m_cast_filter_count; 61 EfiMacAddress m_cast_filter[MAX_MCAST_FILTER_CNT]; 62 EfiMacAddress current_address; 63 EfiMacAddress broadcast_address; 64 EfiMacAddress permanent_address; 65 uint8_t if_type; 66 bool mac_address_changeable; 67 bool multiple_tx_supported; 68 bool media_present_supported; 69 bool media_present; 70 } EfiSimpleNetworkMode; 71 72 typedef struct { 73 uint64_t rx_total_frames; 74 uint64_t rx_good_frames; 75 uint64_t rx_undersize_frames; 76 uint64_t rx_oversize_frames; 77 uint64_t rx_dropped_frames; 78 uint64_t rx_unicast_frames; 79 uint64_t rx_broadcast_frames; 80 uint64_t rx_multicast_frames; 81 uint64_t rx_crc_error_frames; 82 uint64_t rx_total_bytes; 83 uint64_t tx_total_frames; 84 uint64_t tx_good_frames; 85 uint64_t tx_undersize_frames; 86 uint64_t tx_oversize_frames; 87 uint64_t tx_dropped_frames; 88 uint64_t tx_unicast_frames; 89 uint64_t tx_broadcast_frames; 90 uint64_t tx_multicast_frames; 91 uint64_t tx_crc_error_frames; 92 uint64_t tx_total_bytes; 93 uint64_t collisions; 94 uint64_t unsupported_protocol; 95 uint64_t rx_duplicated_frames; 96 uint64_t rx_decrypt_error_frames; 97 uint64_t tx_error_frames; 98 uint64_t tx_retry_frames; 99 } EfiNetworkStatistics; 100 101 typedef struct EfiSimpleNetworkProtocol { 102 uint64_t revision; 103 EfiStatus (*start)(struct EfiSimpleNetworkProtocol* self); 104 EfiStatus (*stop)(struct EfiSimpleNetworkProtocol* self); 105 EfiStatus (*initialize)(struct EfiSimpleNetworkProtocol* self, size_t extra_rx_buffer_size, 106 size_t extra_tx_buffer_size); 107 EfiStatus (*reset)(struct EfiSimpleNetworkProtocol* self, bool extended_verification); 108 EfiStatus (*shutdown)(struct EfiSimpleNetworkProtocol* self); 109 EfiStatus (*receive_filters)(struct EfiSimpleNetworkProtocol* self, uint32_t enable, 110 uint32_t disable, bool reset_mcast_filter, size_t mcast_filter_count, 111 EfiMacAddress* mcast_filter); 112 EfiStatus (*station_address)(struct EfiSimpleNetworkProtocol* self, bool reset, 113 EfiMacAddress* new_addr); 114 EfiStatus (*statistics)(struct EfiSimpleNetworkProtocol* self, bool reset, size_t* stats_size, 115 EfiNetworkStatistics* stats_table); 116 EfiStatus (*m_cast_ip_to_mac)(struct EfiSimpleNetworkProtocol* self, bool ipv6, EfiIpAddr* ip, 117 EfiMacAddress* mac); 118 EfiStatus (*nv_data)(struct EfiSimpleNetworkProtocol* self, bool read_write, size_t offset, 119 size_t buf_size, void* buf); 120 EfiStatus (*get_status)(struct EfiSimpleNetworkProtocol* self, uint32_t* interrupt_status, 121 void** tx_buf); 122 EfiStatus (*transmit)(struct EfiSimpleNetworkProtocol* self, size_t header_size, size_t buf_size, 123 void* buf, EfiMacAddress* src, EfiMacAddress* dest, uint16_t* protocol); 124 EfiStatus (*receive)(struct EfiSimpleNetworkProtocol* self, size_t* header_size, size_t* buf_size, 125 void* buf, EfiMacAddress* src, EfiMacAddress* dest, uint16_t* protocol); 126 127 EfiEvent wait_for_packet; 128 EfiSimpleNetworkMode* mode; 129 } EfiSimpleNetworkProtocol; 130 131 #endif // __SIMPLE_NETWORK_PROTOCOL_H__ 132