Skip to content

Commit 17a8931

Browse files
authored
Merge pull request #1021 from nicholasbishop/bishop-network-proto-raw
uefi-raw: Add HttpProtocol, Ip4Config2Protocol, and TlsConfigurationProtocol
2 parents 5de89dd + ba3f7b7 commit 17a8931

File tree

6 files changed

+306
-1
lines changed

6 files changed

+306
-1
lines changed

Diff for: uefi-raw/CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
## Added
44
- Added `Ipv4Address`, `Ipv6Address`, and `MacAddress` types.
5-
- Added `ServiceBindingProtocol` and `Dhcp4Protocol`.
5+
- Added `ServiceBindingProtocol`, `Dhcp4Protocol`, `HttpProtocol`,
6+
`Ip4Config2Protocol`, `TlsConfigurationProtocol`, and related types.
67

78
# uefi-raw - 0.5.0 (2023-11-12)
89

Diff for: uefi-raw/src/protocol/network/http.rs

+180
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
use crate::{guid, Char16, Char8, Event, Guid, Ipv4Address, Ipv6Address, Status};
2+
use core::ffi::c_void;
3+
use core::fmt::{self, Debug, Formatter};
4+
5+
#[derive(Debug)]
6+
#[repr(C)]
7+
pub struct HttpConfigData {
8+
pub http_version: HttpVersion,
9+
pub time_out_millisec: u32,
10+
pub local_addr_is_ipv6: bool,
11+
pub access_point: HttpAccessPoint,
12+
}
13+
14+
newtype_enum! {
15+
pub enum HttpVersion: i32 => {
16+
HTTP_VERSION_10 = 0,
17+
HTTP_VERSION_11 = 1,
18+
HTTP_VERSION_UNSUPPORTED = 2,
19+
}
20+
}
21+
22+
#[derive(Debug)]
23+
#[repr(C)]
24+
pub struct HttpV4AccessPoint {
25+
pub use_default_addr: bool,
26+
pub local_address: Ipv4Address,
27+
pub local_subnet: Ipv4Address,
28+
pub local_port: u16,
29+
}
30+
31+
#[derive(Debug)]
32+
#[repr(C)]
33+
pub struct HttpV6AccessPoint {
34+
pub local_address: Ipv6Address,
35+
pub local_port: u16,
36+
}
37+
38+
#[repr(C)]
39+
pub union HttpAccessPoint {
40+
pub ipv4_node: *const HttpV4AccessPoint,
41+
pub ipv6_node: *const HttpV6AccessPoint,
42+
}
43+
44+
impl Debug for HttpAccessPoint {
45+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
46+
// This is a union type, so we can't access the internal data.
47+
f.debug_struct("HttpAccessPoint").finish()
48+
}
49+
}
50+
51+
#[derive(Debug)]
52+
#[repr(C)]
53+
pub struct HttpToken {
54+
pub event: Event,
55+
pub status: Status,
56+
pub message: *mut HttpMessage,
57+
}
58+
59+
#[derive(Debug)]
60+
#[repr(C)]
61+
pub struct HttpMessage {
62+
pub data: HttpRequestOrResponse,
63+
pub header_count: usize,
64+
pub header: *mut HttpHeader,
65+
pub body_length: usize,
66+
pub body: *mut c_void,
67+
}
68+
69+
#[derive(Debug)]
70+
#[repr(C)]
71+
pub struct HttpRequestData {
72+
pub method: HttpMethod,
73+
pub url: *const Char16,
74+
}
75+
76+
newtype_enum! {
77+
pub enum HttpMethod: i32 => {
78+
GET = 0,
79+
POST = 1,
80+
PATCH = 2,
81+
OPTIONS = 3,
82+
CONNECT = 4,
83+
HEAD = 5,
84+
PUT = 6,
85+
DELETE = 7,
86+
TRACE = 8,
87+
MAX = 9,
88+
}
89+
}
90+
91+
#[derive(Debug)]
92+
#[repr(C)]
93+
pub struct HttpResponseData {
94+
pub status_code: HttpStatusCode,
95+
}
96+
97+
#[repr(C)]
98+
pub union HttpRequestOrResponse {
99+
pub request: *const HttpRequestData,
100+
pub response: *const HttpResponseData,
101+
}
102+
103+
impl Debug for HttpRequestOrResponse {
104+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
105+
// This is a union type, so we can't access the internal data.
106+
f.debug_struct("RequestOrResponse").finish()
107+
}
108+
}
109+
110+
#[derive(Clone, Debug)]
111+
#[repr(C)]
112+
pub struct HttpHeader {
113+
pub field_name: *const Char8,
114+
pub field_value: *const Char8,
115+
}
116+
117+
newtype_enum! {
118+
pub enum HttpStatusCode: i32 => {
119+
STATUS_UNSUPPORTED = 0,
120+
STATUS_100_CONTINUE = 1,
121+
STATUS_101_SWITCHING_PROTOCOLS = 2,
122+
STATUS_200_OK = 3,
123+
STATUS_201_CREATED = 4,
124+
STATUS_202_ACCEPTED = 5,
125+
STATUS_203_NON_AUTHORITATIVE_INFORMATION = 6,
126+
STATUS_204_NO_CONTENT = 7,
127+
STATUS_205_RESET_CONTENT = 8,
128+
STATUS_206_PARTIAL_CONTENT = 9,
129+
STATUS_300_MULTIPLE_CHOICES = 10,
130+
STATUS_301_MOVED_PERMANENTLY = 11,
131+
STATUS_302_FOUND = 12,
132+
STATUS_303_SEE_OTHER = 13,
133+
STATUS_304_NOT_MODIFIED = 14,
134+
STATUS_305_USE_PROXY = 15,
135+
STATUS_307_TEMPORARY_REDIRECT = 16,
136+
STATUS_400_BAD_REQUEST = 17,
137+
STATUS_401_UNAUTHORIZED = 18,
138+
STATUS_402_PAYMENT_REQUIRED = 19,
139+
STATUS_403_FORBIDDEN = 20,
140+
STATUS_404_NOT_FOUND = 21,
141+
STATUS_405_METHOD_NOT_ALLOWED = 22,
142+
STATUS_406_NOT_ACCEPTABLE = 23,
143+
STATUS_407_PROXY_AUTHENTICATION_REQUIRED = 24,
144+
STATUS_408_REQUEST_TIME_OUT = 25,
145+
STATUS_409_CONFLICT = 26,
146+
STATUS_410_GONE = 27,
147+
STATUS_411_LENGTH_REQUIRED = 28,
148+
STATUS_412_PRECONDITION_FAILED = 29,
149+
STATUS_413_REQUEST_ENTITY_TOO_LARGE = 30,
150+
STATUS_414_REQUEST_URI_TOO_LARGE = 31,
151+
STATUS_415_UNSUPPORTED_MEDIA_TYPE = 32,
152+
STATUS_416_REQUESTED_RANGE_NOT_SATISFIED = 33,
153+
STATUS_417_EXPECTATION_FAILED = 34,
154+
STATUS_500_INTERNAL_SERVER_ERROR = 35,
155+
STATUS_501_NOT_IMPLEMENTED = 36,
156+
STATUS_502_BAD_GATEWAY = 37,
157+
STATUS_503_SERVICE_UNAVAILABLE = 38,
158+
STATUS_504_GATEWAY_TIME_OUT = 39,
159+
STATUS_505_VERSION_NOT_SUPPORTED = 40,
160+
STATUS_308_PERMANENT_REDIRECT = 41,
161+
}
162+
}
163+
164+
#[derive(Debug)]
165+
#[repr(C)]
166+
pub struct HttpProtocol {
167+
pub get_mode_data:
168+
unsafe extern "efiapi" fn(this: *const Self, config_data: *mut HttpConfigData) -> Status,
169+
pub configure:
170+
unsafe extern "efiapi" fn(this: *mut Self, config_data: *const HttpConfigData) -> Status,
171+
pub request: unsafe extern "efiapi" fn(this: *mut Self, token: *mut HttpToken) -> Status,
172+
pub cancel: unsafe extern "efiapi" fn(this: *mut Self, token: *mut HttpToken) -> Status,
173+
pub response: unsafe extern "efiapi" fn(this: *mut Self, token: *mut HttpToken) -> Status,
174+
pub poll: unsafe extern "efiapi" fn(this: *mut Self) -> Status,
175+
}
176+
177+
impl HttpProtocol {
178+
pub const GUID: Guid = guid!("7a59b29b-910b-4171-8242-a85a0df25b5b");
179+
pub const SERVICE_BINDING_GUID: Guid = guid!("bdc8e6af-d9bc-4379-a72a-e0c4e75dae1c");
180+
}

Diff for: uefi-raw/src/protocol/network/ip4.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use crate::Ipv4Address;
2+
3+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
4+
#[repr(C)]
5+
pub struct Ip4RouteTable {
6+
pub subnet_addr: Ipv4Address,
7+
pub subnet_mask: Ipv4Address,
8+
pub gateway_addr: Ipv4Address,
9+
}

Diff for: uefi-raw/src/protocol/network/ip4_config2.rs

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
use crate::protocol::network::ip4::Ip4RouteTable;
2+
use crate::{guid, Char16, Event, Guid, Ipv4Address, MacAddress, Status};
3+
use core::ffi::c_void;
4+
5+
newtype_enum! {
6+
pub enum Ip4Config2DataType: i32 => {
7+
INTERFACE_INFO = 0,
8+
POLICY = 1,
9+
MANUAL_ADDRESS = 2,
10+
GATEWAY = 3,
11+
DNS_SERVER = 4,
12+
MAXIMUM = 5,
13+
}
14+
}
15+
16+
#[derive(Debug)]
17+
#[repr(C)]
18+
pub struct Ip4Config2InterfaceInfo {
19+
pub name: [Char16; 32],
20+
pub if_type: u8,
21+
pub hw_addr_size: u32,
22+
pub hw_addr: MacAddress,
23+
pub station_addr: Ipv4Address,
24+
pub subnet_mask: Ipv4Address,
25+
pub route_table_size: u32,
26+
pub route_table: *mut Ip4RouteTable,
27+
}
28+
29+
newtype_enum! {
30+
pub enum Ip4Config2Policy: i32 => {
31+
STATIC = 0,
32+
DHCP = 1,
33+
MAX = 2,
34+
}
35+
}
36+
37+
#[derive(Debug)]
38+
#[repr(C)]
39+
pub struct Ip4Config2ManualAddress {
40+
pub address: Ipv4Address,
41+
pub subnet_mask: Ipv4Address,
42+
}
43+
44+
#[derive(Debug)]
45+
#[repr(C)]
46+
pub struct Ip4Config2Protocol {
47+
pub set_data: unsafe extern "efiapi" fn(
48+
this: *mut Self,
49+
data_type: Ip4Config2DataType,
50+
data_size: usize,
51+
data: *const c_void,
52+
) -> Status,
53+
54+
pub get_data: unsafe extern "efiapi" fn(
55+
this: *mut Self,
56+
data_type: Ip4Config2DataType,
57+
data_size: *mut usize,
58+
data: *mut c_void,
59+
) -> Status,
60+
61+
pub register_data_notify: unsafe extern "efiapi" fn(
62+
this: *mut Self,
63+
data_type: Ip4Config2DataType,
64+
event: Event,
65+
) -> Status,
66+
67+
pub unregister_data_notify: unsafe extern "efiapi" fn(
68+
this: *mut Self,
69+
data_type: Ip4Config2DataType,
70+
event: Event,
71+
) -> Status,
72+
}
73+
74+
impl Ip4Config2Protocol {
75+
pub const GUID: Guid = guid!("5b446ed1-e30b-4faa-871a-3654eca36080");
76+
}

Diff for: uefi-raw/src/protocol/network/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
pub mod dhcp4;
2+
pub mod http;
3+
pub mod ip4;
4+
pub mod ip4_config2;
5+
pub mod tls;

Diff for: uefi-raw/src/protocol/network/tls.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use crate::{guid, Guid, Status};
2+
use core::ffi::c_void;
3+
4+
newtype_enum! {
5+
pub enum TlsConfigDataType: i32 => {
6+
HOST_PUBLIC_CERT = 0,
7+
HOST_PRIVATE_KEY = 1,
8+
CA_CERTIFICATE = 2,
9+
CERT_REVOCATION_LIST = 3,
10+
MAXIMUM = 4,
11+
}
12+
}
13+
14+
#[derive(Debug)]
15+
#[repr(C)]
16+
pub struct TlsConfigurationProtocol {
17+
pub set_data: unsafe extern "efiapi" fn(
18+
this: *mut Self,
19+
typ: TlsConfigDataType,
20+
data: *const c_void,
21+
size: usize,
22+
) -> Status,
23+
24+
pub get_data: unsafe extern "efiapi" fn(
25+
this: *const Self,
26+
typ: TlsConfigDataType,
27+
data: *mut c_void,
28+
size: *mut usize,
29+
) -> Status,
30+
}
31+
32+
impl TlsConfigurationProtocol {
33+
pub const GUID: Guid = guid!("1682fe44-bd7a-4407-b7c7-dca37ca3922d");
34+
pub const SERVICE_BINDING_GUID: Guid = guid!("952cb795-ff36-48cf-a249-4df486d6ab8d");
35+
}

0 commit comments

Comments
 (0)