@@ -11,6 +11,7 @@ use bitflags::bitflags;
11
11
use core:: fmt:: { self , Debug , Display , Formatter } ;
12
12
use core:: iter:: from_fn;
13
13
use core:: mem:: MaybeUninit ;
14
+ use core:: net:: IpAddr ;
14
15
use core:: ptr:: { self , null, null_mut} ;
15
16
use core:: slice;
16
17
use ptr_meta:: Pointee ;
@@ -65,9 +66,10 @@ impl BaseCode {
65
66
}
66
67
67
68
/// 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 > {
69
70
let mut buffer_size = 0 ;
70
71
72
+ let server_ip = EfiIpAddr :: from ( server_ip) ;
71
73
let status = unsafe {
72
74
( self . 0 . mtftp ) (
73
75
& mut self . 0 ,
@@ -88,7 +90,7 @@ impl BaseCode {
88
90
/// Reads a file located on a TFTP server.
89
91
pub fn tftp_read_file (
90
92
& mut self ,
91
- server_ip : & EfiIpAddr ,
93
+ server_ip : & IpAddr ,
92
94
filename : & CStr8 ,
93
95
buffer : Option < & mut [ u8 ] > ,
94
96
) -> Result < u64 > {
@@ -98,7 +100,7 @@ impl BaseCode {
98
100
} else {
99
101
( null_mut ( ) , 0 , Boolean :: TRUE )
100
102
} ;
101
-
103
+ let server_ip = EfiIpAddr :: from ( server_ip ) ;
102
104
let status = unsafe {
103
105
( self . 0 . mtftp ) (
104
106
& mut self . 0 ,
@@ -119,7 +121,7 @@ impl BaseCode {
119
121
/// Writes to a file located on a TFTP server.
120
122
pub fn tftp_write_file (
121
123
& mut self ,
122
- server_ip : & EfiIpAddr ,
124
+ server_ip : & IpAddr ,
123
125
filename : & CStr8 ,
124
126
overwrite : bool ,
125
127
buffer : & [ u8 ] ,
@@ -135,7 +137,7 @@ impl BaseCode {
135
137
overwrite. into ( ) ,
136
138
& mut buffer_size,
137
139
null ( ) ,
138
- server_ip. as_ptr ( ) ,
140
+ EfiIpAddr :: from ( server_ip) . as_ptr ( ) ,
139
141
cstr8_to_ptr ( filename) ,
140
142
null ( ) ,
141
143
Boolean :: FALSE ,
@@ -147,7 +149,7 @@ impl BaseCode {
147
149
/// Reads a directory listing of a directory on a TFTP server.
148
150
pub fn tftp_read_dir < ' a > (
149
151
& mut self ,
150
- server_ip : & EfiIpAddr ,
152
+ server_ip : & IpAddr ,
151
153
directory_name : & CStr8 ,
152
154
buffer : & ' a mut [ u8 ] ,
153
155
) -> Result < impl Iterator < Item = core:: result:: Result < TftpFileInfo < ' a > , ReadDirParseError > > + ' a >
@@ -163,7 +165,7 @@ impl BaseCode {
163
165
Boolean :: FALSE ,
164
166
& mut buffer_size,
165
167
null ( ) ,
166
- server_ip. as_ptr ( ) ,
168
+ EfiIpAddr :: from ( server_ip) . as_ptr ( ) ,
167
169
cstr8_to_ptr ( directory_name) ,
168
170
null ( ) ,
169
171
Boolean :: FALSE ,
@@ -222,7 +224,7 @@ impl BaseCode {
222
224
/// Returns the size of a file located on a MTFTP server.
223
225
pub fn mtftp_get_file_size (
224
226
& mut self ,
225
- server_ip : & EfiIpAddr ,
227
+ server_ip : & IpAddr ,
226
228
filename : & CStr8 ,
227
229
info : & MtftpInfo ,
228
230
) -> Result < u64 > {
@@ -236,7 +238,7 @@ impl BaseCode {
236
238
Boolean :: FALSE ,
237
239
& mut buffer_size,
238
240
null ( ) ,
239
- server_ip. as_ptr ( ) ,
241
+ EfiIpAddr :: from ( server_ip) . as_ptr ( ) ,
240
242
cstr8_to_ptr ( filename) ,
241
243
info. as_raw_ptr ( ) ,
242
244
Boolean :: FALSE ,
@@ -248,7 +250,7 @@ impl BaseCode {
248
250
/// Reads a file located on a MTFTP server.
249
251
pub fn mtftp_read_file (
250
252
& mut self ,
251
- server_ip : & EfiIpAddr ,
253
+ server_ip : & IpAddr ,
252
254
filename : & CStr8 ,
253
255
buffer : Option < & mut [ u8 ] > ,
254
256
info : & MtftpInfo ,
@@ -268,7 +270,7 @@ impl BaseCode {
268
270
Boolean :: FALSE ,
269
271
& mut buffer_size,
270
272
null ( ) ,
271
- server_ip. as_ptr ( ) ,
273
+ EfiIpAddr :: from ( server_ip) . as_ptr ( ) ,
272
274
cstr8_to_ptr ( filename) ,
273
275
info. as_raw_ptr ( ) ,
274
276
dont_use_buffer,
@@ -280,7 +282,7 @@ impl BaseCode {
280
282
/// Reads a directory listing of a directory on a MTFTP server.
281
283
pub fn mtftp_read_dir < ' a > (
282
284
& mut self ,
283
- server_ip : & EfiIpAddr ,
285
+ server_ip : & IpAddr ,
284
286
buffer : & ' a mut [ u8 ] ,
285
287
info : & MtftpInfo ,
286
288
) -> Result < impl Iterator < Item = core:: result:: Result < MtftpFileInfo < ' a > , ReadDirParseError > > + ' a >
@@ -296,7 +298,7 @@ impl BaseCode {
296
298
Boolean :: FALSE ,
297
299
& mut buffer_size,
298
300
null ( ) ,
299
- server_ip. as_ptr ( ) ,
301
+ EfiIpAddr :: from ( server_ip) . as_ptr ( ) ,
300
302
null_mut ( ) ,
301
303
info. as_raw_ptr ( ) ,
302
304
Boolean :: FALSE ,
@@ -374,10 +376,10 @@ impl BaseCode {
374
376
pub fn udp_write (
375
377
& mut self ,
376
378
op_flags : UdpOpFlags ,
377
- dest_ip : & EfiIpAddr ,
379
+ dest_ip : & IpAddr ,
378
380
dest_port : u16 ,
379
- gateway_ip : Option < & EfiIpAddr > ,
380
- src_ip : Option < & EfiIpAddr > ,
381
+ gateway_ip : Option < & IpAddr > ,
382
+ src_ip : Option < & IpAddr > ,
381
383
src_port : Option < & mut u16 > ,
382
384
header : Option < & [ u8 ] > ,
383
385
buffer : & [ u8 ] ,
@@ -390,14 +392,18 @@ impl BaseCode {
390
392
( None , null ( ) )
391
393
} ;
392
394
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
+
393
399
unsafe {
394
400
( self . 0 . udp_write ) (
395
401
& mut self . 0 ,
396
402
op_flags,
397
403
dest_ip. as_ptr ( ) ,
398
404
& 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 ( ) ) ,
401
407
opt_mut_to_ptr ( src_port) ,
402
408
opt_ref_to_ptr ( header_size) ,
403
409
header_ptr,
@@ -413,9 +419,9 @@ impl BaseCode {
413
419
pub fn udp_read (
414
420
& mut self ,
415
421
op_flags : UdpOpFlags ,
416
- dest_ip : Option < & mut EfiIpAddr > ,
422
+ mut dest_ip : Option < & mut IpAddr > ,
417
423
dest_port : Option < & mut u16 > ,
418
- src_ip : Option < & mut EfiIpAddr > ,
424
+ mut src_ip : Option < & mut IpAddr > ,
419
425
src_port : Option < & mut u16 > ,
420
426
header : Option < & mut [ u8 ] > ,
421
427
buffer : & mut [ u8 ] ,
@@ -429,21 +435,40 @@ impl BaseCode {
429
435
} ;
430
436
431
437
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) ;
433
440
let status = unsafe {
434
441
( self . 0 . udp_read ) (
435
442
& mut self . 0 ,
436
443
op_flags,
437
- opt_ip_addr_to_ptr_mut ( dest_ip ) ,
444
+ opt_ip_addr_to_ptr_mut ( dest_ip_efi . as_mut ( ) ) ,
438
445
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 ( ) ) ,
440
447
opt_mut_to_ptr ( src_port) ,
441
448
header_size,
442
449
header_ptr,
443
450
& mut buffer_size,
444
451
buffer. as_mut_ptr ( ) . cast ( ) ,
445
452
)
446
453
} ;
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
+
447
472
status. to_result_with_val ( || buffer_size)
448
473
}
449
474
@@ -455,7 +480,8 @@ impl BaseCode {
455
480
}
456
481
457
482
/// 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) ;
459
485
unsafe { ( self . 0 . arp ) ( & mut self . 0 , ip_addr. as_ptr ( ) , opt_mut_to_ptr ( mac_addr) ) } . to_result ( )
460
486
}
461
487
@@ -486,14 +512,16 @@ impl BaseCode {
486
512
/// device.
487
513
pub fn set_station_ip (
488
514
& 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 > ,
491
517
) -> Result {
518
+ let new_station_ip = new_station_ip. map ( EfiIpAddr :: from) ;
519
+ let new_subnet_mask = new_subnet_mask. map ( EfiIpAddr :: from) ;
492
520
unsafe {
493
521
( self . 0 . set_station_ip ) (
494
522
& 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 ( ) ) ,
497
525
)
498
526
}
499
527
. to_result ( )
@@ -711,16 +739,16 @@ impl Server {
711
739
/// `None` only Boot Server replies with matching the IP address will be
712
740
/// accepted.
713
741
#[ must_use]
714
- pub fn new ( ty : u16 , ip_addr : Option < EfiIpAddr > ) -> Self {
742
+ pub fn new ( ty : u16 , ip_addr : Option < IpAddr > ) -> Self {
715
743
Self {
716
744
ty,
717
745
accept_any_response : ip_addr. is_none ( ) ,
718
746
_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 ] ) ) ,
720
748
}
721
749
}
722
750
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
724
752
/// address of a Boot Server whose responses should be accepted.
725
753
#[ must_use]
726
754
pub const fn ip_addr ( & self ) -> Option < & EfiIpAddr > {
0 commit comments