Struct PxeBaseCodeProtocol

Source
#[repr(C)]
pub struct PxeBaseCodeProtocol(/* private fields */);

Implementations§

Source§

impl PxeBaseCodeProtocol

Source

pub fn get_any<'a>() -> Result<Option<&'a PxeBaseCodeProtocol>>

Source

pub fn get_all<'a>() -> Result<Vec<&'a PxeBaseCodeProtocol>>

Source

pub fn get_all_mut<'a>() -> Result<Vec<&'a mut PxeBaseCodeProtocol>>

Examples found in repository?
examples/sample_efi_app.rs (line 38)
34fn run(_sys_table: &mut SystemTable) -> Result<(), String> {
35    println!("Hello from UEFI");
36    println!("");
37
38    let pxe_protocols = net::pxebc::PxeBaseCodeProtocol::get_all_mut()
39            .map_err(|_| "error while locating PXE protocols")?;
40
41    if pxe_protocols.len() == 0 {
42        return Err(String::from("No PXE protocols found"));
43    }
44
45    println!("Found {0} PXE protocols", pxe_protocols.len());
46
47    let pxe_protocol = &pxe_protocols[0];
48    
49    if pxe_protocol.cached_dhcp_config().unwrap_or(None).is_none() { // If there's cached config then DHCP has already happend. Otherwise we start it.
50        println!("Performing DHCP...");
51        let dhcp_config = pxe_protocol.run_dhcp().map_err(|e| format!("Dhcp failed - {}", e))?;
52
53        println!("    Your IP: {}, Subnet mask: {}", dhcp_config.ip(), dhcp_config.subnet_mask());
54        if let Some(server_ip) =  dhcp_config.dhcp_server_addr() {
55            println!("    Server IP: {}", server_ip);
56        }
57    }
58
59    println!("");
60    println!("Testing TCP by sending HTTP request to the given addr");
61
62    print!("Enter addr to connect to (<host>:<port>): ");
63    let stdin = efi::stdin();
64    let addr = stdin.lines().next().unwrap().unwrap();
65
66    println!("Connecting to {}...", addr);
67
68    net::TcpStream::connect(addr)
69        .and_then(|mut stream| {
70            println!("Connected!");
71            let buf = "GET / HTTP/1.1".as_bytes();
72            use io::Write;
73
74            stream.write(&buf).unwrap();
75            stream.write("\r\n".as_bytes()).unwrap();
76            stream.write("Content-Length: 0\r\n".as_bytes()).unwrap();
77            stream.write("\r\n".as_bytes()).unwrap();
78
79            println!("Req sent");
80
81            println!("");
82            println!("Received resp: ");
83            let mut rbuf = [0_u8; 2048];
84
85            let read = stream.read(&mut rbuf).unwrap();
86
87            if read == 0 {
88                return Err(EfiErrorKind::NoResponse.into())
89            }
90
91            let resp = String::from_utf8_lossy(&rbuf[..read]).into_owned();
92
93            println!("{}", resp);
94
95            println!("");
96
97            Ok(())
98        })
99        .or_else(|e| {
100            Err(format!("Failed to connect. Status code: {:?}", e))
101        })?;
102
103    Ok(())
104}
Source

pub fn cached_dhcp_config(&self) -> Result<Option<DhcpConfig>>

Examples found in repository?
examples/sample_efi_app.rs (line 49)
34fn run(_sys_table: &mut SystemTable) -> Result<(), String> {
35    println!("Hello from UEFI");
36    println!("");
37
38    let pxe_protocols = net::pxebc::PxeBaseCodeProtocol::get_all_mut()
39            .map_err(|_| "error while locating PXE protocols")?;
40
41    if pxe_protocols.len() == 0 {
42        return Err(String::from("No PXE protocols found"));
43    }
44
45    println!("Found {0} PXE protocols", pxe_protocols.len());
46
47    let pxe_protocol = &pxe_protocols[0];
48    
49    if pxe_protocol.cached_dhcp_config().unwrap_or(None).is_none() { // If there's cached config then DHCP has already happend. Otherwise we start it.
50        println!("Performing DHCP...");
51        let dhcp_config = pxe_protocol.run_dhcp().map_err(|e| format!("Dhcp failed - {}", e))?;
52
53        println!("    Your IP: {}, Subnet mask: {}", dhcp_config.ip(), dhcp_config.subnet_mask());
54        if let Some(server_ip) =  dhcp_config.dhcp_server_addr() {
55            println!("    Server IP: {}", server_ip);
56        }
57    }
58
59    println!("");
60    println!("Testing TCP by sending HTTP request to the given addr");
61
62    print!("Enter addr to connect to (<host>:<port>): ");
63    let stdin = efi::stdin();
64    let addr = stdin.lines().next().unwrap().unwrap();
65
66    println!("Connecting to {}...", addr);
67
68    net::TcpStream::connect(addr)
69        .and_then(|mut stream| {
70            println!("Connected!");
71            let buf = "GET / HTTP/1.1".as_bytes();
72            use io::Write;
73
74            stream.write(&buf).unwrap();
75            stream.write("\r\n".as_bytes()).unwrap();
76            stream.write("Content-Length: 0\r\n".as_bytes()).unwrap();
77            stream.write("\r\n".as_bytes()).unwrap();
78
79            println!("Req sent");
80
81            println!("");
82            println!("Received resp: ");
83            let mut rbuf = [0_u8; 2048];
84
85            let read = stream.read(&mut rbuf).unwrap();
86
87            if read == 0 {
88                return Err(EfiErrorKind::NoResponse.into())
89            }
90
91            let resp = String::from_utf8_lossy(&rbuf[..read]).into_owned();
92
93            println!("{}", resp);
94
95            println!("");
96
97            Ok(())
98        })
99        .or_else(|e| {
100            Err(format!("Failed to connect. Status code: {:?}", e))
101        })?;
102
103    Ok(())
104}
Source

pub fn run_dhcp(&self) -> Result<DhcpConfig>

Examples found in repository?
examples/sample_efi_app.rs (line 51)
34fn run(_sys_table: &mut SystemTable) -> Result<(), String> {
35    println!("Hello from UEFI");
36    println!("");
37
38    let pxe_protocols = net::pxebc::PxeBaseCodeProtocol::get_all_mut()
39            .map_err(|_| "error while locating PXE protocols")?;
40
41    if pxe_protocols.len() == 0 {
42        return Err(String::from("No PXE protocols found"));
43    }
44
45    println!("Found {0} PXE protocols", pxe_protocols.len());
46
47    let pxe_protocol = &pxe_protocols[0];
48    
49    if pxe_protocol.cached_dhcp_config().unwrap_or(None).is_none() { // If there's cached config then DHCP has already happend. Otherwise we start it.
50        println!("Performing DHCP...");
51        let dhcp_config = pxe_protocol.run_dhcp().map_err(|e| format!("Dhcp failed - {}", e))?;
52
53        println!("    Your IP: {}, Subnet mask: {}", dhcp_config.ip(), dhcp_config.subnet_mask());
54        if let Some(server_ip) =  dhcp_config.dhcp_server_addr() {
55            println!("    Server IP: {}", server_ip);
56        }
57    }
58
59    println!("");
60    println!("Testing TCP by sending HTTP request to the given addr");
61
62    print!("Enter addr to connect to (<host>:<port>): ");
63    let stdin = efi::stdin();
64    let addr = stdin.lines().next().unwrap().unwrap();
65
66    println!("Connecting to {}...", addr);
67
68    net::TcpStream::connect(addr)
69        .and_then(|mut stream| {
70            println!("Connected!");
71            let buf = "GET / HTTP/1.1".as_bytes();
72            use io::Write;
73
74            stream.write(&buf).unwrap();
75            stream.write("\r\n".as_bytes()).unwrap();
76            stream.write("Content-Length: 0\r\n".as_bytes()).unwrap();
77            stream.write("\r\n".as_bytes()).unwrap();
78
79            println!("Req sent");
80
81            println!("");
82            println!("Received resp: ");
83            let mut rbuf = [0_u8; 2048];
84
85            let read = stream.read(&mut rbuf).unwrap();
86
87            if read == 0 {
88                return Err(EfiErrorKind::NoResponse.into())
89            }
90
91            let resp = String::from_utf8_lossy(&rbuf[..read]).into_owned();
92
93            println!("{}", resp);
94
95            println!("");
96
97            Ok(())
98        })
99        .or_else(|e| {
100            Err(format!("Failed to connect. Status code: {:?}", e))
101        })?;
102
103    Ok(())
104}
Source

pub fn run_boot_server_discovery( &self, _dhcp_config: &DhcpConfig, ) -> Result<BootServerConfig>

Source

pub fn set_proxy_offer(&mut self, pxe_reply_packet: &Dhcpv4Packet) -> Result<()>

Source

pub fn mtftp_get_file_size( &self, server_ip: &IpAddr, filename: &NullTerminatedAsciiStr<'_>, ) -> Result<u64>

Source

pub fn mtftp_get_file( &self, server_ip: &IpAddr, filename: &NullTerminatedAsciiStr<'_>, ) -> Result<Vec<u8>>

Trait Implementations§

Source§

impl From<EFI_PXE_BASE_CODE_PROTOCOL> for PxeBaseCodeProtocol

Source§

fn from(raw_protocol: EFI_PXE_BASE_CODE_PROTOCOL) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.