@@ -11,6 +11,7 @@ use bitflags::bitflags;
1111use core:: fmt:: { self , Debug , Display , Formatter } ;
1212use core:: iter:: from_fn;
1313use core:: mem:: MaybeUninit ;
14+ use core:: net:: IpAddr ;
1415use core:: ptr:: { self , null, null_mut} ;
1516use core:: slice;
1617use ptr_meta:: Pointee ;
@@ -65,9 +66,10 @@ impl BaseCode {
6566 }
6667
6768 /// Returns the size of a file located on a TFTP server.
68- pub fn tftp_get_file_size ( & mut self , server_ip : & EfiIpAddr , filename : & CStr8 ) -> Result < u64 > {
69+ pub fn tftp_get_file_size ( & mut self , server_ip : & IpAddr , filename : & CStr8 ) -> Result < u64 > {
6970 let mut buffer_size = 0 ;
7071
72+ let server_ip = EfiIpAddr :: from ( server_ip) ;
7173 let status = unsafe {
7274 ( self . 0 . mtftp ) (
7375 & mut self . 0 ,
@@ -88,7 +90,7 @@ impl BaseCode {
8890 /// Reads a file located on a TFTP server.
8991 pub fn tftp_read_file (
9092 & mut self ,
91- server_ip : & EfiIpAddr ,
93+ server_ip : & IpAddr ,
9294 filename : & CStr8 ,
9395 buffer : Option < & mut [ u8 ] > ,
9496 ) -> Result < u64 > {
@@ -98,7 +100,7 @@ impl BaseCode {
98100 } else {
99101 ( null_mut ( ) , 0 , Boolean :: TRUE )
100102 } ;
101-
103+ let server_ip = EfiIpAddr :: from ( server_ip ) ;
102104 let status = unsafe {
103105 ( self . 0 . mtftp ) (
104106 & mut self . 0 ,
@@ -119,7 +121,7 @@ impl BaseCode {
119121 /// Writes to a file located on a TFTP server.
120122 pub fn tftp_write_file (
121123 & mut self ,
122- server_ip : & EfiIpAddr ,
124+ server_ip : & IpAddr ,
123125 filename : & CStr8 ,
124126 overwrite : bool ,
125127 buffer : & [ u8 ] ,
@@ -135,7 +137,7 @@ impl BaseCode {
135137 overwrite. into ( ) ,
136138 & mut buffer_size,
137139 null ( ) ,
138- server_ip. as_ptr ( ) ,
140+ EfiIpAddr :: from ( server_ip) . as_ptr ( ) ,
139141 cstr8_to_ptr ( filename) ,
140142 null ( ) ,
141143 Boolean :: FALSE ,
@@ -147,7 +149,7 @@ impl BaseCode {
147149 /// Reads a directory listing of a directory on a TFTP server.
148150 pub fn tftp_read_dir < ' a > (
149151 & mut self ,
150- server_ip : & EfiIpAddr ,
152+ server_ip : & IpAddr ,
151153 directory_name : & CStr8 ,
152154 buffer : & ' a mut [ u8 ] ,
153155 ) -> Result < impl Iterator < Item = core:: result:: Result < TftpFileInfo < ' a > , ReadDirParseError > > + ' a >
@@ -163,7 +165,7 @@ impl BaseCode {
163165 Boolean :: FALSE ,
164166 & mut buffer_size,
165167 null ( ) ,
166- server_ip. as_ptr ( ) ,
168+ EfiIpAddr :: from ( server_ip) . as_ptr ( ) ,
167169 cstr8_to_ptr ( directory_name) ,
168170 null ( ) ,
169171 Boolean :: FALSE ,
@@ -222,7 +224,7 @@ impl BaseCode {
222224 /// Returns the size of a file located on a MTFTP server.
223225 pub fn mtftp_get_file_size (
224226 & mut self ,
225- server_ip : & EfiIpAddr ,
227+ server_ip : & IpAddr ,
226228 filename : & CStr8 ,
227229 info : & MtftpInfo ,
228230 ) -> Result < u64 > {
@@ -236,7 +238,7 @@ impl BaseCode {
236238 Boolean :: FALSE ,
237239 & mut buffer_size,
238240 null ( ) ,
239- server_ip. as_ptr ( ) ,
241+ EfiIpAddr :: from ( server_ip) . as_ptr ( ) ,
240242 cstr8_to_ptr ( filename) ,
241243 info. as_raw_ptr ( ) ,
242244 Boolean :: FALSE ,
@@ -248,7 +250,7 @@ impl BaseCode {
248250 /// Reads a file located on a MTFTP server.
249251 pub fn mtftp_read_file (
250252 & mut self ,
251- server_ip : & EfiIpAddr ,
253+ server_ip : & IpAddr ,
252254 filename : & CStr8 ,
253255 buffer : Option < & mut [ u8 ] > ,
254256 info : & MtftpInfo ,
@@ -268,7 +270,7 @@ impl BaseCode {
268270 Boolean :: FALSE ,
269271 & mut buffer_size,
270272 null ( ) ,
271- server_ip. as_ptr ( ) ,
273+ EfiIpAddr :: from ( server_ip) . as_ptr ( ) ,
272274 cstr8_to_ptr ( filename) ,
273275 info. as_raw_ptr ( ) ,
274276 dont_use_buffer,
@@ -280,7 +282,7 @@ impl BaseCode {
280282 /// Reads a directory listing of a directory on a MTFTP server.
281283 pub fn mtftp_read_dir < ' a > (
282284 & mut self ,
283- server_ip : & EfiIpAddr ,
285+ server_ip : & IpAddr ,
284286 buffer : & ' a mut [ u8 ] ,
285287 info : & MtftpInfo ,
286288 ) -> Result < impl Iterator < Item = core:: result:: Result < MtftpFileInfo < ' a > , ReadDirParseError > > + ' a >
@@ -296,7 +298,7 @@ impl BaseCode {
296298 Boolean :: FALSE ,
297299 & mut buffer_size,
298300 null ( ) ,
299- server_ip. as_ptr ( ) ,
301+ EfiIpAddr :: from ( server_ip) . as_ptr ( ) ,
300302 null_mut ( ) ,
301303 info. as_raw_ptr ( ) ,
302304 Boolean :: FALSE ,
@@ -374,10 +376,10 @@ impl BaseCode {
374376 pub fn udp_write (
375377 & mut self ,
376378 op_flags : UdpOpFlags ,
377- dest_ip : & EfiIpAddr ,
379+ dest_ip : & IpAddr ,
378380 dest_port : u16 ,
379- gateway_ip : Option < & EfiIpAddr > ,
380- src_ip : Option < & EfiIpAddr > ,
381+ gateway_ip : Option < & IpAddr > ,
382+ src_ip : Option < & IpAddr > ,
381383 src_port : Option < & mut u16 > ,
382384 header : Option < & [ u8 ] > ,
383385 buffer : & [ u8 ] ,
@@ -390,14 +392,18 @@ impl BaseCode {
390392 ( None , null ( ) )
391393 } ;
392394
395+ let gateway_ip = gateway_ip. map ( EfiIpAddr :: from) ;
396+ let src_ip = src_ip. map ( EfiIpAddr :: from) ;
397+ let dest_ip = EfiIpAddr :: from ( dest_ip) ;
398+
393399 unsafe {
394400 ( self . 0 . udp_write ) (
395401 & mut self . 0 ,
396402 op_flags,
397403 dest_ip. as_ptr ( ) ,
398404 & dest_port,
399- opt_ip_addr_to_ptr ( gateway_ip) ,
400- opt_ip_addr_to_ptr ( src_ip) ,
405+ opt_ip_addr_to_ptr ( gateway_ip. as_ref ( ) ) ,
406+ opt_ip_addr_to_ptr ( src_ip. as_ref ( ) ) ,
401407 opt_mut_to_ptr ( src_port) ,
402408 opt_ref_to_ptr ( header_size) ,
403409 header_ptr,
@@ -413,9 +419,9 @@ impl BaseCode {
413419 pub fn udp_read (
414420 & mut self ,
415421 op_flags : UdpOpFlags ,
416- dest_ip : Option < & mut EfiIpAddr > ,
422+ mut dest_ip : Option < & mut IpAddr > ,
417423 dest_port : Option < & mut u16 > ,
418- src_ip : Option < & mut EfiIpAddr > ,
424+ mut src_ip : Option < & mut IpAddr > ,
419425 src_port : Option < & mut u16 > ,
420426 header : Option < & mut [ u8 ] > ,
421427 buffer : & mut [ u8 ] ,
@@ -429,21 +435,40 @@ impl BaseCode {
429435 } ;
430436
431437 let mut buffer_size = buffer. len ( ) ;
432-
438+ let mut dest_ip_efi = dest_ip. as_ref ( ) . map ( |rf| * * rf) . map ( EfiIpAddr :: from) ;
439+ let mut src_ip_efi = src_ip. as_ref ( ) . map ( |rf| * * rf) . map ( EfiIpAddr :: from) ;
433440 let status = unsafe {
434441 ( self . 0 . udp_read ) (
435442 & mut self . 0 ,
436443 op_flags,
437- opt_ip_addr_to_ptr_mut ( dest_ip ) ,
444+ opt_ip_addr_to_ptr_mut ( dest_ip_efi . as_mut ( ) ) ,
438445 opt_mut_to_ptr ( dest_port) ,
439- opt_ip_addr_to_ptr_mut ( src_ip ) ,
446+ opt_ip_addr_to_ptr_mut ( src_ip_efi . as_mut ( ) ) ,
440447 opt_mut_to_ptr ( src_port) ,
441448 header_size,
442449 header_ptr,
443450 & mut buffer_size,
444451 buffer. as_mut_ptr ( ) . cast ( ) ,
445452 )
446453 } ;
454+ // Update input props
455+ if let Some ( ip) = & mut dest_ip {
456+ let ip_efi = dest_ip_efi. unwrap ( ) ;
457+ if ip. is_ipv4 ( ) {
458+ * * ip = IpAddr :: V4 ( unsafe { ip_efi. v4 } )
459+ } else {
460+ * * ip = IpAddr :: V6 ( unsafe { ip_efi. v6 } )
461+ }
462+ }
463+ if let Some ( ip) = & mut src_ip {
464+ let ip_efi = src_ip_efi. unwrap ( ) ;
465+ if ip. is_ipv4 ( ) {
466+ * * ip = IpAddr :: V4 ( unsafe { ip_efi. v4 } )
467+ } else {
468+ * * ip = IpAddr :: V6 ( unsafe { ip_efi. v6 } )
469+ }
470+ }
471+
447472 status. to_result_with_val ( || buffer_size)
448473 }
449474
@@ -455,7 +480,8 @@ impl BaseCode {
455480 }
456481
457482 /// Uses the ARP protocol to resolve a MAC address.
458- pub fn arp ( & mut self , ip_addr : & EfiIpAddr , mac_addr : Option < & mut EfiMacAddr > ) -> Result {
483+ pub fn arp ( & mut self , ip_addr : & IpAddr , mac_addr : Option < & mut EfiMacAddr > ) -> Result {
484+ let ip_addr = EfiIpAddr :: from ( ip_addr) ;
459485 unsafe { ( self . 0 . arp ) ( & mut self . 0 , ip_addr. as_ptr ( ) , opt_mut_to_ptr ( mac_addr) ) } . to_result ( )
460486 }
461487
@@ -486,14 +512,16 @@ impl BaseCode {
486512 /// device.
487513 pub fn set_station_ip (
488514 & mut self ,
489- new_station_ip : Option < & EfiIpAddr > ,
490- new_subnet_mask : Option < & EfiIpAddr > ,
515+ new_station_ip : Option < & IpAddr > ,
516+ new_subnet_mask : Option < & IpAddr > ,
491517 ) -> Result {
518+ let new_station_ip = new_station_ip. map ( EfiIpAddr :: from) ;
519+ let new_subnet_mask = new_subnet_mask. map ( EfiIpAddr :: from) ;
492520 unsafe {
493521 ( self . 0 . set_station_ip ) (
494522 & mut self . 0 ,
495- opt_ip_addr_to_ptr ( new_station_ip) ,
496- opt_ip_addr_to_ptr ( new_subnet_mask) ,
523+ opt_ip_addr_to_ptr ( new_station_ip. as_ref ( ) ) ,
524+ opt_ip_addr_to_ptr ( new_subnet_mask. as_ref ( ) ) ,
497525 )
498526 }
499527 . to_result ( )
@@ -711,16 +739,16 @@ impl Server {
711739 /// `None` only Boot Server replies with matching the IP address will be
712740 /// accepted.
713741 #[ must_use]
714- pub fn new ( ty : u16 , ip_addr : Option < EfiIpAddr > ) -> Self {
742+ pub fn new ( ty : u16 , ip_addr : Option < IpAddr > ) -> Self {
715743 Self {
716744 ty,
717745 accept_any_response : ip_addr. is_none ( ) ,
718746 _reserved : 0 ,
719- ip_addr : ip_addr. unwrap_or ( EfiIpAddr :: from ( [ 0 ; 16 ] ) ) ,
747+ ip_addr : ip_addr. map ( Into :: into ) . unwrap_or ( EfiIpAddr :: from ( [ 0 ; 16 ] ) ) ,
720748 }
721749 }
722750
723- /// Returns a `None` if the any response should be accepted or the IP
751+ /// Returns `None` if any response should be accepted, or otherwise the IP
724752 /// address of a Boot Server whose responses should be accepted.
725753 #[ must_use]
726754 pub const fn ip_addr ( & self ) -> Option < & EfiIpAddr > {
0 commit comments