aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / vendor / uefi-raw / src / protocol / network / dhcp4.rs
| 1 | // SPDX-License-Identifier: MIT OR Apache-2.0 |
| 2 | |
| 3 | use crate::{Boolean, Char8, Event, Guid, Ipv4Address, MacAddress, Status, guid, newtype_enum}; |
| 4 | use core::ffi::c_void; |
| 5 | |
| 6 | newtype_enum! { |
| 7 | pub enum Dhcp4Event: i32 => { |
| 8 | SEND_DISCOVER = 0x01, |
| 9 | RCVD_OFFER = 0x02, |
| 10 | SELECT_OFFER = 0x03, |
| 11 | SEND_REQUEST = 0x04, |
| 12 | RCVD_ACK = 0x05, |
| 13 | RCVD_NAK = 0x06, |
| 14 | SEND_DECLINE = 0x07, |
| 15 | BOUND_COMPLETED = 0x08, |
| 16 | ENTER_RENEWING = 0x09, |
| 17 | ENTER_REBINDING = 0x0a, |
| 18 | ADDRESS_LOST = 0x0b, |
| 19 | FAIL = 0x0c, |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | newtype_enum! { |
| 24 | pub enum Dhcp4State: i32 => { |
| 25 | STOPPED = 0x0, |
| 26 | INIT = 0x1, |
| 27 | SELECTING = 0x2, |
| 28 | REQUESTING = 0x3, |
| 29 | BOUND = 0x4, |
| 30 | RENEWING = 0x5, |
| 31 | REBINDING = 0x6, |
| 32 | INIT_REBOOT = 0x7, |
| 33 | REBOOTING = 0x8, |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | #[derive(Debug)] |
| 38 | #[repr(C, packed)] |
| 39 | pub struct Dhcp4Packet { |
| 40 | pub size: u32, |
| 41 | pub length: u32, |
| 42 | pub header: Dhcp4Header, |
| 43 | pub magik: u32, |
| 44 | |
| 45 | /// Start of the DHCP packed option data. |
| 46 | /// |
| 47 | /// Note that this field is actually a variable-length array. |
| 48 | pub option: [u8; 0], |
| 49 | } |
| 50 | |
| 51 | #[derive(Clone, Copy, Debug)] |
| 52 | #[repr(C, packed)] |
| 53 | pub struct Dhcp4Header { |
| 54 | pub op_code: u8, |
| 55 | pub hw_type: u8, |
| 56 | pub hw_addr_len: u8, |
| 57 | pub hops: u8, |
| 58 | pub xid: u32, |
| 59 | pub seconds: u16, |
| 60 | pub reserved: u16, |
| 61 | pub client_addr: Ipv4Address, |
| 62 | pub your_addr: Ipv4Address, |
| 63 | pub server_addr: Ipv4Address, |
| 64 | pub gateway_addr: Ipv4Address, |
| 65 | pub client_hw_addr: [u8; 16], |
| 66 | pub server_name: [Char8; 64], |
| 67 | pub boot_file_name: [Char8; 128], |
| 68 | } |
| 69 | |
| 70 | #[derive(Debug)] |
| 71 | #[repr(C, packed)] |
| 72 | pub struct Dhcp4PacketOption { |
| 73 | pub op_code: u8, |
| 74 | pub length: u8, |
| 75 | |
| 76 | /// Start of the DHCP option data. |
| 77 | /// |
| 78 | /// Note that this field is actually a variable-length array. |
| 79 | pub data: [u8; 0], |
| 80 | } |
| 81 | |
| 82 | #[derive(Debug)] |
| 83 | #[repr(C)] |
| 84 | pub struct Dhcp4ConfigData { |
| 85 | pub discover_try_count: u32, |
| 86 | pub discover_timeout: *mut u32, |
| 87 | pub request_try_count: u32, |
| 88 | pub request_timeout: *mut u32, |
| 89 | pub client_address: Ipv4Address, |
| 90 | pub callback: Option< |
| 91 | unsafe extern "efiapi" fn( |
| 92 | this: *mut Dhcp4Protocol, |
| 93 | context: *const c_void, |
| 94 | current_state: Dhcp4State, |
| 95 | dhcp4_event: Dhcp4Event, |
| 96 | packet: *const Dhcp4Packet, |
| 97 | new_packet: *mut *mut Dhcp4Packet, |
| 98 | ) -> Status, |
| 99 | >, |
| 100 | pub callback_context: *mut c_void, |
| 101 | pub option_count: u32, |
| 102 | pub option_list: *mut *const Dhcp4PacketOption, |
| 103 | } |
| 104 | |
| 105 | #[derive(Debug)] |
| 106 | #[repr(C)] |
| 107 | pub struct Dhcp4ModeData { |
| 108 | pub state: Dhcp4State, |
| 109 | pub config_data: Dhcp4ConfigData, |
| 110 | pub client_address: Ipv4Address, |
| 111 | pub client_mac_address: MacAddress, |
| 112 | pub server_address: Ipv4Address, |
| 113 | pub router_address: Ipv4Address, |
| 114 | pub subnet_mask: Ipv4Address, |
| 115 | pub lease_time: u32, |
| 116 | pub reply_packet: *const Dhcp4Packet, |
| 117 | } |
| 118 | |
| 119 | #[derive(Debug)] |
| 120 | #[repr(C)] |
| 121 | pub struct Dhcp4ListenPoint { |
| 122 | pub listen_address: Ipv4Address, |
| 123 | pub subnet_mask: Ipv4Address, |
| 124 | pub listen_port: u16, |
| 125 | } |
| 126 | |
| 127 | #[derive(Debug)] |
| 128 | #[repr(C)] |
| 129 | pub struct Dhcp4TransmitReceiveToken { |
| 130 | pub status: Status, |
| 131 | pub completion_event: Event, |
| 132 | pub remote_address: Ipv4Address, |
| 133 | pub remote_port: u16, |
| 134 | pub gateway_address: Ipv4Address, |
| 135 | pub listen_point_count: u32, |
| 136 | pub listen_points: *mut Dhcp4ListenPoint, |
| 137 | pub timeout_value: u32, |
| 138 | pub packet: *mut Dhcp4Packet, |
| 139 | pub response_count: u32, |
| 140 | pub response_list: *mut Dhcp4Packet, |
| 141 | } |
| 142 | |
| 143 | #[derive(Debug)] |
| 144 | #[repr(C)] |
| 145 | pub struct Dhcp4Protocol { |
| 146 | pub get_mode_data: |
| 147 | unsafe extern "efiapi" fn(this: *const Self, mode_data: *mut Dhcp4ModeData) -> Status, |
| 148 | pub configure: |
| 149 | unsafe extern "efiapi" fn(this: *mut Self, cfg_data: *const Dhcp4ConfigData) -> Status, |
| 150 | pub start: unsafe extern "efiapi" fn(this: *mut Self, completion_event: Event) -> Status, |
| 151 | pub renew_rebind: unsafe extern "efiapi" fn( |
| 152 | this: *mut Self, |
| 153 | rebind_request: Boolean, |
| 154 | completion_event: Event, |
| 155 | ) -> Status, |
| 156 | pub release: unsafe extern "efiapi" fn(this: *mut Self) -> Status, |
| 157 | pub stop: unsafe extern "efiapi" fn(this: *mut Self) -> Status, |
| 158 | pub build: unsafe extern "efiapi" fn( |
| 159 | this: *mut Self, |
| 160 | seed_packet: *const Dhcp4Packet, |
| 161 | delete_count: u32, |
| 162 | delete_list: *const u8, |
| 163 | append_count: u32, |
| 164 | append_list: *const *const Dhcp4PacketOption, |
| 165 | new_packet: *mut *mut Dhcp4Packet, |
| 166 | ) -> Status, |
| 167 | pub transmit_receive: |
| 168 | unsafe extern "efiapi" fn(this: *mut Self, token: *mut Dhcp4TransmitReceiveToken) -> Status, |
| 169 | pub parse: unsafe extern "efiapi" fn( |
| 170 | this: *mut Self, |
| 171 | packet: *const Dhcp4Packet, |
| 172 | option_count: *mut u32, |
| 173 | packet_option_list: *mut *mut Dhcp4PacketOption, |
| 174 | ) -> Status, |
| 175 | } |
| 176 | |
| 177 | impl Dhcp4Protocol { |
| 178 | pub const GUID: Guid = guid!("8a219718-4ef5-4761-91c8-c0f04bda9e56"); |
| 179 | pub const SERVICE_BINDING_GUID: Guid = guid!("9d9a39d8-bd42-4a73-a4d5-8ee94be11380"); |
| 180 | } |