#[repr(C)]pub struct PxeBaseCodeProtocol(/* private fields */);
Implementations§
Source§impl PxeBaseCodeProtocol
impl PxeBaseCodeProtocol
pub fn get_any<'a>() -> Result<Option<&'a PxeBaseCodeProtocol>>
pub fn get_all<'a>() -> Result<Vec<&'a PxeBaseCodeProtocol>>
Sourcepub fn get_all_mut<'a>() -> Result<Vec<&'a mut PxeBaseCodeProtocol>>
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}
Sourcepub fn cached_dhcp_config(&self) -> Result<Option<DhcpConfig>>
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}
Sourcepub fn run_dhcp(&self) -> Result<DhcpConfig>
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}
pub fn run_boot_server_discovery( &self, _dhcp_config: &DhcpConfig, ) -> Result<BootServerConfig>
pub fn set_proxy_offer(&mut self, pxe_reply_packet: &Dhcpv4Packet) -> Result<()>
pub fn mtftp_get_file_size( &self, server_ip: &IpAddr, filename: &NullTerminatedAsciiStr<'_>, ) -> Result<u64>
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
impl From<EFI_PXE_BASE_CODE_PROTOCOL> for PxeBaseCodeProtocol
Source§fn from(raw_protocol: EFI_PXE_BASE_CODE_PROTOCOL) -> Self
fn from(raw_protocol: EFI_PXE_BASE_CODE_PROTOCOL) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for PxeBaseCodeProtocol
impl RefUnwindSafe for PxeBaseCodeProtocol
impl !Send for PxeBaseCodeProtocol
impl !Sync for PxeBaseCodeProtocol
impl Unpin for PxeBaseCodeProtocol
impl UnwindSafe for PxeBaseCodeProtocol
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more