Skip to content

Commit

Permalink
successful request
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasbishop committed Nov 12, 2024
1 parent 058ea25 commit b3f4671
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 24 deletions.
29 changes: 15 additions & 14 deletions uefi-test-runner/src/proto/network/http.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
use core::time::Duration;
use log::info;
use uefi::proto::network::http::{
Http, HttpConfiguration, HttpMethod, HttpRequest, HttpServiceBinding, HttpVersion,
Http, HttpConfiguration, HttpHeader, HttpMethod, HttpRequest, HttpServiceBinding, HttpVersion,
};
use uefi::{boot, cstr16};

// TODO: uefi wrappers
use uefi_raw::protocol::network::ip4_config2::Ip4Config2Protocol;
use uefi::proto::network::ip4_config2::{Ip4Config2, Ip4Config2Policy};
use uefi::{boot, cstr16, cstr8};

// TODO: unwraps
pub fn test() {
info!("Testing HTTP protocol");

let handle = boot::get_handle_for_protocol::<HttpServiceBinding>().unwrap();
// TODO
let handle = boot::get_handle_for_protocol::<Ip4Config2>().unwrap();
let mut ipconfig = boot::open_protocol_exclusive::<Ip4Config2>(handle).unwrap();
ipconfig.set_policy(Ip4Config2Policy::DHCP).unwrap();
info!("Ip4Config2 policy: {:?}", ipconfig.get_policy().unwrap());

Ip4Config2Protocol::pub get_data: unsafe extern "efiapi" fn(
this: *mut Self,
data_type: Ip4Config2DataType,
data_size: *mut usize,
data: *mut c_void,
) -> Status,
boot::stall(4_000_000);

let handle = boot::get_handle_for_protocol::<HttpServiceBinding>().unwrap();
let mut http_sb = boot::open_protocol_exclusive::<HttpServiceBinding>(handle).unwrap();
Expand All @@ -28,7 +25,8 @@ pub fn test() {

let config = HttpConfiguration {
http_version: HttpVersion::HTTP_VERSION_11,
timeout: Duration::from_secs(1),
// TODO
timeout: Duration::from_secs(10),
access_point: Default::default(),
};
http.configure(&config).unwrap();
Expand All @@ -39,7 +37,10 @@ pub fn test() {
http.send_request_sync(HttpRequest {
method: HttpMethod::GET,
url: cstr16!("http://example.com"),
headers: &[],
headers: &[HttpHeader::new(
cstr8!("Host"),
cstr8!("http://example.com"),
)],
body: &[],
})
.unwrap();
Expand Down
13 changes: 12 additions & 1 deletion uefi/src/proto/network/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ impl Http {
header_count: request.headers.len(),
headers,
body_length: request.body.len(),
body: request.body.as_ptr().cast(),
// TODO: body: request.body.as_ptr().cast(),
body: ptr::null(),
};

let mut is_done = false;
Expand All @@ -134,6 +135,9 @@ impl Http {
status: Status::SUCCESS,
message: &message,
};
// TODO
log::info!("token: {token:?}");
log::info!("message: {:?}", unsafe { &*token.message });

unsafe { (self.0.request)(&mut self.0, &mut token) }.to_result()
}
Expand Down Expand Up @@ -178,6 +182,13 @@ pub struct HttpHeader<'a> {
pub value: &'a CStr8,
}

impl<'a> HttpHeader<'a> {
#[must_use]
pub const fn new(name: &'a CStr8, value: &'a CStr8) -> Self {
Self { name, value }
}
}

#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct HttpRequest<'a> {
pub method: HttpMethod,
Expand Down
45 changes: 45 additions & 0 deletions uefi/src/proto/network/ip4_config2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//! TODO

use core::ptr;
use uefi::{Result, StatusExt};
use uefi_macros::unsafe_protocol;
use uefi_raw::protocol::network::ip4_config2::{Ip4Config2DataType, Ip4Config2Protocol};

pub use uefi_raw::protocol::network::ip4_config2::Ip4Config2Policy;

/// TODO
#[derive(Debug)]
#[repr(transparent)]
#[unsafe_protocol(Ip4Config2Protocol::GUID)]
pub struct Ip4Config2(Ip4Config2Protocol);

impl Ip4Config2 {
/// TODO
pub fn get_policy(&self) -> Result<Ip4Config2Policy> {
let mut policy = Ip4Config2Policy(-1);
let mut size = size_of_val(&policy);

unsafe {
(self.0.get_data)(
ptr::from_ref(&self.0).cast_mut(),
Ip4Config2DataType::POLICY,
&mut size,
ptr::from_mut(&mut policy).cast(),
)
}
.to_result_with_val(|| policy)
}

/// TODO
pub fn set_policy(&mut self, policy: Ip4Config2Policy) -> Result {
unsafe {
(self.0.set_data)(
&mut self.0,
Ip4Config2DataType::POLICY,
size_of::<Ip4Config2Policy>(),
ptr::from_ref(&policy).cast(),
)
}
.to_result()
}
}
1 change: 1 addition & 0 deletions uefi/src/proto/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! These protocols can be used to interact with network resources.

pub mod http;
pub mod ip4_config2;
pub mod pxe;
pub mod snp;

Expand Down
18 changes: 9 additions & 9 deletions xtask/src/qemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ pub fn run_qemu(arch: UefiArch, opt: &QemuOpt) -> Result<()> {

cmd.args(["-device", "virtio-rng-pci"]);

if arch == UefiArch::IA32 || arch == UefiArch::X86_64 {
cmd.args(["-debugcon", "file:./integration-test-debugcon.log"]);
}
// if arch == UefiArch::IA32 || arch == UefiArch::X86_64 {
// cmd.args(["-debugcon", "file:./integration-test-debugcon.log"]);
// }

// Set the boot menu timeout to zero. On aarch64 in particular this speeds
// up the boot a lot. Note that we have to enable the menu here even though
Expand Down Expand Up @@ -426,12 +426,12 @@ pub fn run_qemu(arch: UefiArch, opt: &QemuOpt) -> Result<()> {

// OVMF debug builds can output information to a serial `debugcon`.
// Only enable when debugging UEFI boot.
// cmd.args([
// "-debugcon",
// "file:debug.log",
// "-global",
// "isa-debugcon.iobase=0x402",
// ]);
cmd.args([
"-debugcon",
"file:debug.log",
"-global",
"isa-debugcon.iobase=0x402",
]);
}
}

Expand Down

0 comments on commit b3f4671

Please sign in to comment.