|
| 1 | +// SPDX-License-Identifier: MIT OR Apache-2.0 |
| 2 | + |
| 3 | +use crate::{guid, Boolean, Char8, Guid, IpAddress, MacAddress, Status}; |
| 4 | +use bitflags::bitflags; |
| 5 | +use core::ffi::c_void; |
| 6 | +use core::fmt::{self, Debug, Formatter}; |
| 7 | + |
| 8 | +#[derive(Debug)] |
| 9 | +#[repr(C)] |
| 10 | +pub struct PxeBaseCodeProtocol { |
| 11 | + pub revision: u64, |
| 12 | + pub start: unsafe extern "efiapi" fn(this: *mut Self, use_ipv6: Boolean) -> Status, |
| 13 | + pub stop: unsafe extern "efiapi" fn(this: *mut Self) -> Status, |
| 14 | + pub dhcp: unsafe extern "efiapi" fn(this: *mut Self, sort_offers: Boolean) -> Status, |
| 15 | + pub discover: unsafe extern "efiapi" fn( |
| 16 | + this: *mut Self, |
| 17 | + ty: PxeBaseCodeBootType, |
| 18 | + layer: *mut u16, |
| 19 | + use_bis: Boolean, |
| 20 | + info: *const PxeBaseCodeDiscoverInfo, |
| 21 | + ) -> Status, |
| 22 | + pub mtftp: unsafe extern "efiapi" fn( |
| 23 | + this: *mut Self, |
| 24 | + operation: PxeBaseCodeTftpOpcode, |
| 25 | + buffer: *mut c_void, |
| 26 | + overwrite: Boolean, |
| 27 | + buffer_size: *mut u64, |
| 28 | + block_size: *const usize, |
| 29 | + server_ip: *const IpAddress, |
| 30 | + filename: *const Char8, |
| 31 | + info: *const PxeBaseCodeMtftpInfo, |
| 32 | + dont_use_buffer: Boolean, |
| 33 | + ) -> Status, |
| 34 | + pub udp_write: unsafe extern "efiapi" fn( |
| 35 | + this: *mut Self, |
| 36 | + op_flags: PxeBaseCodeUdpOpFlags, |
| 37 | + dest_ip: *const IpAddress, |
| 38 | + dest_port: *const PxeBaseCodeUdpPort, |
| 39 | + gateway_ip: *const IpAddress, |
| 40 | + src_ip: *const IpAddress, |
| 41 | + src_port: *mut PxeBaseCodeUdpPort, |
| 42 | + header_size: *const usize, |
| 43 | + header_ptr: *const c_void, |
| 44 | + buffer_size: *const usize, |
| 45 | + buffer_ptr: *const c_void, |
| 46 | + ) -> Status, |
| 47 | + pub udp_read: unsafe extern "efiapi" fn( |
| 48 | + this: *mut Self, |
| 49 | + op_flags: PxeBaseCodeUdpOpFlags, |
| 50 | + dest_ip: *mut IpAddress, |
| 51 | + dest_port: *mut PxeBaseCodeUdpPort, |
| 52 | + src_ip: *mut IpAddress, |
| 53 | + src_port: *mut PxeBaseCodeUdpPort, |
| 54 | + header_size: *const usize, |
| 55 | + header_ptr: *mut c_void, |
| 56 | + buffer_size: *mut usize, |
| 57 | + buffer_ptr: *mut c_void, |
| 58 | + ) -> Status, |
| 59 | + pub set_ip_filter: unsafe extern "efiapi" fn( |
| 60 | + this: *mut Self, |
| 61 | + new_filter: *const PxeBaseCodeIpFilter, |
| 62 | + ) -> Status, |
| 63 | + pub arp: unsafe extern "efiapi" fn( |
| 64 | + this: *mut Self, |
| 65 | + ip_addr: *const IpAddress, |
| 66 | + mac_addr: *mut MacAddress, |
| 67 | + ) -> Status, |
| 68 | + pub set_parameters: unsafe extern "efiapi" fn( |
| 69 | + this: *mut Self, |
| 70 | + new_auto_arp: *const Boolean, |
| 71 | + new_send_guid: *const Boolean, |
| 72 | + new_ttl: *const u8, |
| 73 | + new_tos: *const u8, |
| 74 | + new_make_callback: *const Boolean, |
| 75 | + ) -> Status, |
| 76 | + pub set_station_ip: unsafe extern "efiapi" fn( |
| 77 | + this: *mut Self, |
| 78 | + new_station_ip: *const IpAddress, |
| 79 | + new_subnet_mask: *const IpAddress, |
| 80 | + ) -> Status, |
| 81 | + pub set_packets: unsafe extern "efiapi" fn( |
| 82 | + this: *mut Self, |
| 83 | + new_dhcp_discover_valid: *const Boolean, |
| 84 | + new_dhcp_ack_received: *const Boolean, |
| 85 | + new_proxy_offer_received: *const Boolean, |
| 86 | + new_pxe_discover_valid: *const Boolean, |
| 87 | + new_pxe_reply_received: *const Boolean, |
| 88 | + new_pxe_bis_reply_received: *const Boolean, |
| 89 | + new_dhcp_discover: *const PxeBaseCodePacket, |
| 90 | + new_dhcp_ack: *const PxeBaseCodePacket, |
| 91 | + new_proxy_offer: *const PxeBaseCodePacket, |
| 92 | + new_pxe_discover: *const PxeBaseCodePacket, |
| 93 | + new_pxe_reply: *const PxeBaseCodePacket, |
| 94 | + new_pxe_bis_reply: *const PxeBaseCodePacket, |
| 95 | + ) -> Status, |
| 96 | + pub mode: *const PxeBaseCodeMode, |
| 97 | +} |
| 98 | + |
| 99 | +impl PxeBaseCodeProtocol { |
| 100 | + pub const GUID: Guid = guid!("03c4e603-ac28-11d3-9a2d-0090273fc14d"); |
| 101 | +} |
| 102 | + |
| 103 | +newtype_enum! { |
| 104 | + pub enum PxeBaseCodeBootType: u16 => { |
| 105 | + BOOTSTRAP = 0, |
| 106 | + MS_WINNT_RIS = 1, |
| 107 | + INTEL_LCM = 2, |
| 108 | + DOS_UNDI = 3, |
| 109 | + NEC_ESMPRO = 4, |
| 110 | + IBM_WSOD = 5, |
| 111 | + IBM_LCCM = 6, |
| 112 | + CA_UNICENTER_TNG = 7, |
| 113 | + HP_OPENVIEW = 8, |
| 114 | + ALTIRIS_9 = 9, |
| 115 | + ALTIRIS_10 = 10, |
| 116 | + ALTIRIS_11 = 11, |
| 117 | + NOT_USED_12 = 12, |
| 118 | + REDHAT_INSTALL = 13, |
| 119 | + REDHAT_BOOT = 14, |
| 120 | + REMBO = 15, |
| 121 | + BEOBOOT = 16, |
| 122 | + // 17..=32767: reserved. |
| 123 | + // 32768..=65279: reserved for vendor use. |
| 124 | + // 65280..=65534: reserved. |
| 125 | + PXETEST = 65535, |
| 126 | + } |
| 127 | +} |
| 128 | + |
| 129 | +newtype_enum! { |
| 130 | + pub enum PxeBaseCodeTftpOpcode: i32 => { |
| 131 | + TFTP_FIRST = 0, |
| 132 | + TFTP_GET_FILE_SIZE = 1, |
| 133 | + TFTP_READ_FILE = 2, |
| 134 | + TFTP_WRITE_FILE = 3, |
| 135 | + TFTP_READ_DIRECTORY = 4, |
| 136 | + MTFTP_GET_FILE_SIZE = 5, |
| 137 | + MTFTP_READ_FILE = 6, |
| 138 | + MTFTP_READ_DIRECTORY = 7, |
| 139 | + MTFTP_LAST = 8, |
| 140 | + } |
| 141 | +} |
| 142 | + |
| 143 | +#[derive(Debug)] |
| 144 | +#[repr(C)] |
| 145 | +pub struct PxeBaseCodeDiscoverInfo { |
| 146 | + pub use_m_cast: Boolean, |
| 147 | + pub use_b_cast: Boolean, |
| 148 | + pub use_u_cast: Boolean, |
| 149 | + pub must_use_list: Boolean, |
| 150 | + pub server_m_cast_ip: IpAddress, |
| 151 | + pub ip_cnt: u16, |
| 152 | + |
| 153 | + /// Note that this field is actually a variable-length array. |
| 154 | + pub srv_list: [PxeBaseCodeSrvlist; 0], |
| 155 | +} |
| 156 | + |
| 157 | +#[derive(Clone, Copy, Debug)] |
| 158 | +#[repr(C)] |
| 159 | +pub struct PxeBaseCodeSrvlist { |
| 160 | + pub server_type: u16, |
| 161 | + pub accept_any_response: Boolean, |
| 162 | + pub reserved: u8, |
| 163 | + pub ip_addr: IpAddress, |
| 164 | +} |
| 165 | + |
| 166 | +pub type PxeBaseCodeUdpPort = u16; |
| 167 | + |
| 168 | +#[derive(Clone, Copy, Debug)] |
| 169 | +#[repr(C)] |
| 170 | +pub struct PxeBaseCodeMtftpInfo { |
| 171 | + pub m_cast_ip: IpAddress, |
| 172 | + pub c_port: PxeBaseCodeUdpPort, |
| 173 | + pub s_port: PxeBaseCodeUdpPort, |
| 174 | + pub listen_timeout: u16, |
| 175 | + pub transmit_timeout: u16, |
| 176 | +} |
| 177 | + |
| 178 | +bitflags! { |
| 179 | + #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 180 | + #[repr(transparent)] |
| 181 | + pub struct PxeBaseCodeUdpOpFlags: u16 { |
| 182 | + const ANY_SRC_IP = 0x0001; |
| 183 | + const ANY_SRC_PORT = 0x0002; |
| 184 | + const ANY_DEST_IP = 0x0004; |
| 185 | + const ANY_DEST_PORT = 0x0008; |
| 186 | + const USE_FILTER = 0x0010; |
| 187 | + const MAY_FRAGMENT = 0x0020; |
| 188 | + } |
| 189 | +} |
| 190 | + |
| 191 | +#[derive(Clone, Debug)] |
| 192 | +#[repr(C)] |
| 193 | +pub struct PxeBaseCodeMode { |
| 194 | + pub started: Boolean, |
| 195 | + pub ipv6_available: Boolean, |
| 196 | + pub ipv6_supported: Boolean, |
| 197 | + pub using_ipv6: Boolean, |
| 198 | + pub bis_supported: Boolean, |
| 199 | + pub bis_detected: Boolean, |
| 200 | + pub auto_arp: Boolean, |
| 201 | + pub send_guid: Boolean, |
| 202 | + pub dhcp_discover_valid: Boolean, |
| 203 | + pub dhcp_ack_received: Boolean, |
| 204 | + pub proxy_offer_received: Boolean, |
| 205 | + pub pxe_discover_valid: Boolean, |
| 206 | + pub pxe_reply_received: Boolean, |
| 207 | + pub pxe_bis_reply_received: Boolean, |
| 208 | + pub icmp_error_received: Boolean, |
| 209 | + pub tftp_error_received: Boolean, |
| 210 | + pub make_callbacks: Boolean, |
| 211 | + pub ttl: u8, |
| 212 | + pub tos: u8, |
| 213 | + pub station_ip: IpAddress, |
| 214 | + pub subnet_mask: IpAddress, |
| 215 | + pub dhcp_discover: PxeBaseCodePacket, |
| 216 | + pub dhcp_ack: PxeBaseCodePacket, |
| 217 | + pub proxy_offer: PxeBaseCodePacket, |
| 218 | + pub pxe_discover: PxeBaseCodePacket, |
| 219 | + pub pxe_reply: PxeBaseCodePacket, |
| 220 | + pub pxe_bis_reply: PxeBaseCodePacket, |
| 221 | + pub ip_filter: PxeBaseCodeIpFilter, |
| 222 | + pub arp_cache_entries: u32, |
| 223 | + pub arp_cache: [PxeBaseCodeArpEntry; 8], |
| 224 | + pub route_table_entries: u32, |
| 225 | + pub route_table: [PxeBaseCodeRouteEntry; 8], |
| 226 | + pub icmp_error: PxeBaseCodeIcmpError, |
| 227 | + pub tftp_error: PxeBaseCodeTftpError, |
| 228 | +} |
| 229 | + |
| 230 | +#[derive(Clone, Copy)] |
| 231 | +#[repr(C)] |
| 232 | +pub union PxeBaseCodePacket { |
| 233 | + pub raw: [u8; 1472], |
| 234 | + pub dhcpv4: PxeBaseCodeDhcpV4Packet, |
| 235 | + pub dhcpv6: PxeBaseCodeDhcpV6Packet, |
| 236 | +} |
| 237 | + |
| 238 | +impl Debug for PxeBaseCodePacket { |
| 239 | + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
| 240 | + f.debug_struct("PxeBaseCodePacket").finish() |
| 241 | + } |
| 242 | +} |
| 243 | + |
| 244 | +#[derive(Clone, Copy, Debug)] |
| 245 | +#[repr(C)] |
| 246 | +pub struct PxeBaseCodeDhcpV4Packet { |
| 247 | + pub bootp_opcode: u8, |
| 248 | + pub bootp_hw_type: u8, |
| 249 | + pub bootp_hw_addr_len: u8, |
| 250 | + pub bootp_gate_hops: u8, |
| 251 | + pub bootp_ident: u32, |
| 252 | + pub bootp_seconds: u16, |
| 253 | + pub bootp_flags: u16, |
| 254 | + pub bootp_ci_addr: [u8; 4], |
| 255 | + pub bootp_yi_addr: [u8; 4], |
| 256 | + pub bootp_si_addr: [u8; 4], |
| 257 | + pub bootp_gi_addr: [u8; 4], |
| 258 | + pub bootp_hw_addr: [u8; 16], |
| 259 | + pub bootp_srv_name: [u8; 64], |
| 260 | + pub bootp_boot_file: [u8; 128], |
| 261 | + pub dhcp_magik: u32, |
| 262 | + pub dhcp_options: [u8; 56], |
| 263 | +} |
| 264 | + |
| 265 | +#[derive(Clone, Copy, Debug)] |
| 266 | +#[repr(C)] |
| 267 | +pub struct PxeBaseCodeDhcpV6Packet { |
| 268 | + pub message_type: u8, |
| 269 | + pub transaction_id: [u8; 3], |
| 270 | + pub dhcp_options: [u8; 1024], |
| 271 | +} |
| 272 | + |
| 273 | +#[derive(Clone, Copy, Debug)] |
| 274 | +#[repr(C)] |
| 275 | +pub struct PxeBaseCodeIpFilter { |
| 276 | + pub filters: PxeBaseCodeIpFilterFlags, |
| 277 | + pub ip_cnt: u8, |
| 278 | + pub reserved: u16, |
| 279 | + pub ip_list: [IpAddress; 8], |
| 280 | +} |
| 281 | + |
| 282 | +bitflags! { |
| 283 | + #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
| 284 | + #[repr(transparent)] |
| 285 | + pub struct PxeBaseCodeIpFilterFlags: u8 { |
| 286 | + const STATION_IP = 0x01; |
| 287 | + const BROADCAST = 0x02; |
| 288 | + const PROMISCUOUS = 0x04; |
| 289 | + const PROMISCUOUS_MULTICAST = 0x08; |
| 290 | + } |
| 291 | +} |
| 292 | + |
| 293 | +#[derive(Clone, Copy, Debug)] |
| 294 | +#[repr(C)] |
| 295 | +pub struct PxeBaseCodeArpEntry { |
| 296 | + pub ip_addr: IpAddress, |
| 297 | + pub mac_addr: MacAddress, |
| 298 | +} |
| 299 | + |
| 300 | +#[derive(Clone, Copy, Debug)] |
| 301 | +#[repr(C)] |
| 302 | +pub struct PxeBaseCodeRouteEntry { |
| 303 | + pub ip_addr: IpAddress, |
| 304 | + pub subnet_mask: IpAddress, |
| 305 | + pub gw_addr: IpAddress, |
| 306 | +} |
| 307 | + |
| 308 | +#[derive(Clone, Debug)] |
| 309 | +#[repr(C)] |
| 310 | +pub struct PxeBaseCodeIcmpError { |
| 311 | + pub ty: u8, |
| 312 | + pub code: u8, |
| 313 | + pub checksum: u16, |
| 314 | + pub u: PxeBaseCodeIcmpErrorUnion, |
| 315 | + pub data: [u8; 494], |
| 316 | +} |
| 317 | + |
| 318 | +/// In the C API, this is an anonymous union inside the definition of |
| 319 | +/// `EFI_PXE_BASE_CODE_ICMP_ERROR`. |
| 320 | +#[derive(Clone, Copy)] |
| 321 | +#[repr(C)] |
| 322 | +pub union PxeBaseCodeIcmpErrorUnion { |
| 323 | + pub reserved: u32, |
| 324 | + pub mtu: u32, |
| 325 | + pub pointer: u32, |
| 326 | + pub echo: PxeBaseCodeIcmpErrorEcho, |
| 327 | +} |
| 328 | + |
| 329 | +impl Debug for PxeBaseCodeIcmpErrorUnion { |
| 330 | + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
| 331 | + f.debug_struct("PxeBaseCodeIcmpErrorUnion").finish() |
| 332 | + } |
| 333 | +} |
| 334 | + |
| 335 | +/// In the C API, this is an anonymous struct inside the definition of |
| 336 | +/// `EFI_PXE_BASE_CODE_ICMP_ERROR`. |
| 337 | +#[derive(Clone, Copy, Debug)] |
| 338 | +#[repr(C)] |
| 339 | +pub struct PxeBaseCodeIcmpErrorEcho { |
| 340 | + pub identifier: u16, |
| 341 | + pub sequence: u16, |
| 342 | +} |
| 343 | + |
| 344 | +#[derive(Clone, Debug)] |
| 345 | +#[repr(C)] |
| 346 | +pub struct PxeBaseCodeTftpError { |
| 347 | + pub error_code: u8, |
| 348 | + pub error_string: [Char8; 127], |
| 349 | +} |
0 commit comments