@@ -8,15 +8,14 @@ use crate::proto::unsafe_protocol;
8
8
use crate :: util:: ptr_write_unaligned_and_add;
9
9
use crate :: { CStr8 , Result , Status , StatusExt } ;
10
10
use bitflags:: bitflags;
11
- use core:: ffi:: c_void;
12
11
use core:: fmt:: { self , Debug , Display , Formatter } ;
13
12
use core:: iter:: from_fn;
14
13
use core:: mem:: MaybeUninit ;
15
14
use core:: ptr:: { self , null, null_mut} ;
16
15
use ptr_meta:: Pointee ;
17
16
use uefi_raw:: protocol:: network:: pxe:: {
18
17
PxeBaseCodeDiscoverInfo , PxeBaseCodeIpFilter , PxeBaseCodeMtftpInfo , PxeBaseCodePacket ,
19
- PxeBaseCodeTftpOpcode ,
18
+ PxeBaseCodeProtocol , PxeBaseCodeTftpOpcode ,
20
19
} ;
21
20
use uefi_raw:: { Boolean , Char8 } ;
22
21
@@ -27,111 +26,25 @@ pub use uefi_raw::protocol::network::pxe::{
27
26
28
27
/// PXE Base Code protocol
29
28
#[ derive( Debug ) ]
30
- #[ repr( C ) ]
31
- #[ unsafe_protocol( "03c4e603-ac28-11d3-9a2d-0090273fc14d" ) ]
32
- #[ allow( clippy:: type_complexity) ]
33
- pub struct BaseCode {
34
- revision : u64 ,
35
- start : unsafe extern "efiapi" fn ( this : & Self , use_ipv6 : Boolean ) -> Status ,
36
- stop : unsafe extern "efiapi" fn ( this : & Self ) -> Status ,
37
- dhcp : unsafe extern "efiapi" fn ( this : & Self , sort_offers : Boolean ) -> Status ,
38
- discover : unsafe extern "efiapi" fn (
39
- this : & Self ,
40
- ty : BootstrapType ,
41
- layer : & mut u16 ,
42
- use_bis : Boolean ,
43
- info : * const PxeBaseCodeDiscoverInfo ,
44
- ) -> Status ,
45
- mtftp : unsafe extern "efiapi" fn (
46
- this : & Self ,
47
- operation : PxeBaseCodeTftpOpcode ,
48
- buffer : * mut c_void ,
49
- overwrite : Boolean ,
50
- buffer_size : & mut u64 ,
51
- block_size : * const usize ,
52
- server_ip : * const uefi_raw:: IpAddress ,
53
- filename : * const Char8 ,
54
- info : * const PxeBaseCodeMtftpInfo ,
55
- dont_use_buffer : Boolean ,
56
- ) -> Status ,
57
- udp_write : unsafe extern "efiapi" fn (
58
- this : & Self ,
59
- op_flags : UdpOpFlags ,
60
- dest_ip : * const uefi_raw:: IpAddress ,
61
- dest_port : & u16 ,
62
- gateway_ip : * const uefi_raw:: IpAddress ,
63
- src_ip : * const uefi_raw:: IpAddress ,
64
- src_port : * mut u16 ,
65
- header_size : * const usize ,
66
- header_ptr : * const c_void ,
67
- buffer_size : & usize ,
68
- buffer_ptr : * const c_void ,
69
- ) -> Status ,
70
- udp_read : unsafe extern "efiapi" fn (
71
- this : & Self ,
72
- op_flags : UdpOpFlags ,
73
- dest_ip : * mut uefi_raw:: IpAddress ,
74
- dest_port : * mut u16 ,
75
- src_ip : * mut uefi_raw:: IpAddress ,
76
- src_port : * mut u16 ,
77
- header_size : * const usize ,
78
- header_ptr : * mut c_void ,
79
- buffer_size : & mut usize ,
80
- buffer_ptr : * mut c_void ,
81
- ) -> Status ,
82
- set_ip_filter :
83
- unsafe extern "efiapi" fn ( this : & Self , new_filter : * const PxeBaseCodeIpFilter ) -> Status ,
84
- arp : unsafe extern "efiapi" fn (
85
- this : & Self ,
86
- ip_addr : * const uefi_raw:: IpAddress ,
87
- mac_addr : * mut MacAddress ,
88
- ) -> Status ,
89
- set_parameters : unsafe extern "efiapi" fn (
90
- this : & Self ,
91
- new_auto_arp : * const Boolean ,
92
- new_send_guid : * const Boolean ,
93
- new_ttl : * const u8 ,
94
- new_tos : * const u8 ,
95
- new_make_callback : * const Boolean ,
96
- ) -> Status ,
97
- set_station_ip : unsafe extern "efiapi" fn (
98
- this : & Self ,
99
- new_station_ip : * const uefi_raw:: IpAddress ,
100
- new_subnet_mask : * const uefi_raw:: IpAddress ,
101
- ) -> Status ,
102
- set_packets : unsafe extern "efiapi" fn (
103
- this : & Self ,
104
- new_dhcp_discover_valid : * const Boolean ,
105
- new_dhcp_ack_received : * const Boolean ,
106
- new_proxy_offer_received : * const Boolean ,
107
- new_pxe_discover_valid : * const Boolean ,
108
- new_pxe_reply_received : * const Boolean ,
109
- new_pxe_bis_reply_received : * const Boolean ,
110
- new_dhcp_discover : * const PxeBaseCodePacket ,
111
- new_dhcp_ack : * const PxeBaseCodePacket ,
112
- new_proxy_offer : * const PxeBaseCodePacket ,
113
- new_pxe_discover : * const PxeBaseCodePacket ,
114
- new_pxe_reply : * const PxeBaseCodePacket ,
115
- new_pxe_bis_reply : * const PxeBaseCodePacket ,
116
- ) -> Status ,
117
- mode : * const Mode ,
118
- }
29
+ #[ repr( transparent) ]
30
+ #[ unsafe_protocol( PxeBaseCodeProtocol :: GUID ) ]
31
+ pub struct BaseCode ( PxeBaseCodeProtocol ) ;
119
32
120
33
impl BaseCode {
121
34
/// Enables the use of the PXE Base Code Protocol functions.
122
35
pub fn start ( & mut self , use_ipv6 : bool ) -> Result {
123
- unsafe { ( self . start ) ( self , use_ipv6. into ( ) ) } . to_result ( )
36
+ unsafe { ( self . 0 . start ) ( & mut self . 0 , use_ipv6. into ( ) ) } . to_result ( )
124
37
}
125
38
126
39
/// Disables the use of the PXE Base Code Protocol functions.
127
40
pub fn stop ( & mut self ) -> Result {
128
- unsafe { ( self . stop ) ( self ) } . to_result ( )
41
+ unsafe { ( self . 0 . stop ) ( & mut self . 0 ) } . to_result ( )
129
42
}
130
43
131
44
/// Attempts to complete a DHCPv4 D.O.R.A. (discover / offer / request /
132
45
/// acknowledge) or DHCPv6 S.A.R.R (solicit / advertise / request / reply) sequence.
133
46
pub fn dhcp ( & mut self , sort_offers : bool ) -> Result {
134
- unsafe { ( self . dhcp ) ( self , sort_offers. into ( ) ) } . to_result ( )
47
+ unsafe { ( self . 0 . dhcp ) ( & mut self . 0 , sort_offers. into ( ) ) } . to_result ( )
135
48
}
136
49
137
50
/// Attempts to complete the PXE Boot Server and/or boot image discovery
@@ -147,16 +60,16 @@ impl BaseCode {
147
60
. map ( |info| ptr:: from_ref ( info) . cast ( ) )
148
61
. unwrap_or ( null ( ) ) ;
149
62
150
- unsafe { ( self . discover ) ( self , ty, layer, use_bis. into ( ) , info) } . to_result ( )
63
+ unsafe { ( self . 0 . discover ) ( & mut self . 0 , ty, layer, use_bis. into ( ) , info) } . to_result ( )
151
64
}
152
65
153
66
/// Returns the size of a file located on a TFTP server.
154
67
pub fn tftp_get_file_size ( & mut self , server_ip : & IpAddress , filename : & CStr8 ) -> Result < u64 > {
155
68
let mut buffer_size = 0 ;
156
69
157
70
let status = unsafe {
158
- ( self . mtftp ) (
159
- self ,
71
+ ( self . 0 . mtftp ) (
72
+ & mut self . 0 ,
160
73
PxeBaseCodeTftpOpcode :: TFTP_GET_FILE_SIZE ,
161
74
null_mut ( ) ,
162
75
Boolean :: FALSE ,
@@ -186,8 +99,8 @@ impl BaseCode {
186
99
} ;
187
100
188
101
let status = unsafe {
189
- ( self . mtftp ) (
190
- self ,
102
+ ( self . 0 . mtftp ) (
103
+ & mut self . 0 ,
191
104
PxeBaseCodeTftpOpcode :: TFTP_READ_FILE ,
192
105
buffer_ptr,
193
106
Boolean :: FALSE ,
@@ -214,8 +127,8 @@ impl BaseCode {
214
127
let mut buffer_size = u64:: try_from ( buffer. len ( ) ) . expect ( "buffer length should fit in u64" ) ;
215
128
216
129
unsafe {
217
- ( self . mtftp ) (
218
- self ,
130
+ ( self . 0 . mtftp ) (
131
+ & mut self . 0 ,
219
132
PxeBaseCodeTftpOpcode :: TFTP_WRITE_FILE ,
220
133
buffer_ptr,
221
134
overwrite. into ( ) ,
@@ -242,8 +155,8 @@ impl BaseCode {
242
155
let mut buffer_size = u64:: try_from ( buffer. len ( ) ) . expect ( "buffer length should fit in u64" ) ;
243
156
244
157
let status = unsafe {
245
- ( self . mtftp ) (
246
- self ,
158
+ ( self . 0 . mtftp ) (
159
+ & mut self . 0 ,
247
160
PxeBaseCodeTftpOpcode :: TFTP_READ_DIRECTORY ,
248
161
buffer_ptr,
249
162
Boolean :: FALSE ,
@@ -315,8 +228,8 @@ impl BaseCode {
315
228
let mut buffer_size = 0 ;
316
229
317
230
let status = unsafe {
318
- ( self . mtftp ) (
319
- self ,
231
+ ( self . 0 . mtftp ) (
232
+ & mut self . 0 ,
320
233
PxeBaseCodeTftpOpcode :: MTFTP_GET_FILE_SIZE ,
321
234
null_mut ( ) ,
322
235
Boolean :: FALSE ,
@@ -347,8 +260,8 @@ impl BaseCode {
347
260
} ;
348
261
349
262
let status = unsafe {
350
- ( self . mtftp ) (
351
- self ,
263
+ ( self . 0 . mtftp ) (
264
+ & mut self . 0 ,
352
265
PxeBaseCodeTftpOpcode :: MTFTP_READ_FILE ,
353
266
buffer_ptr,
354
267
Boolean :: FALSE ,
@@ -375,8 +288,8 @@ impl BaseCode {
375
288
let mut buffer_size = u64:: try_from ( buffer. len ( ) ) . expect ( "buffer length should fit in u64" ) ;
376
289
377
290
let status = unsafe {
378
- ( self . mtftp ) (
379
- self ,
291
+ ( self . 0 . mtftp ) (
292
+ & mut self . 0 ,
380
293
PxeBaseCodeTftpOpcode :: MTFTP_READ_DIRECTORY ,
381
294
buffer_ptr,
382
295
Boolean :: FALSE ,
@@ -477,8 +390,8 @@ impl BaseCode {
477
390
} ;
478
391
479
392
unsafe {
480
- ( self . udp_write ) (
481
- self ,
393
+ ( self . 0 . udp_write ) (
394
+ & mut self . 0 ,
482
395
op_flags,
483
396
dest_ip. as_raw_ptr ( ) ,
484
397
& dest_port,
@@ -517,8 +430,8 @@ impl BaseCode {
517
430
let mut buffer_size = buffer. len ( ) ;
518
431
519
432
let status = unsafe {
520
- ( self . udp_read ) (
521
- self ,
433
+ ( self . 0 . udp_read ) (
434
+ & mut self . 0 ,
522
435
op_flags,
523
436
opt_ip_addr_to_ptr_mut ( dest_ip) ,
524
437
opt_mut_to_ptr ( dest_port) ,
@@ -537,12 +450,13 @@ impl BaseCode {
537
450
/// filtering.
538
451
pub fn set_ip_filter ( & mut self , new_filter : & IpFilter ) -> Result {
539
452
let new_filter: * const PxeBaseCodeIpFilter = ptr:: from_ref ( new_filter) . cast ( ) ;
540
- unsafe { ( self . set_ip_filter ) ( self , new_filter) } . to_result ( )
453
+ unsafe { ( self . 0 . set_ip_filter ) ( & mut self . 0 , new_filter) } . to_result ( )
541
454
}
542
455
543
456
/// Uses the ARP protocol to resolve a MAC address.
544
457
pub fn arp ( & mut self , ip_addr : & IpAddress , mac_addr : Option < & mut MacAddress > ) -> Result {
545
- unsafe { ( self . arp ) ( self , ip_addr. as_raw_ptr ( ) , opt_mut_to_ptr ( mac_addr) ) } . to_result ( )
458
+ unsafe { ( self . 0 . arp ) ( & mut self . 0 , ip_addr. as_raw_ptr ( ) , opt_mut_to_ptr ( mac_addr) ) }
459
+ . to_result ( )
546
460
}
547
461
548
462
/// Updates the parameters that affect the operation of the PXE Base Code
@@ -556,8 +470,8 @@ impl BaseCode {
556
470
new_make_callback : Option < bool > ,
557
471
) -> Result {
558
472
unsafe {
559
- ( self . set_parameters ) (
560
- self ,
473
+ ( self . 0 . set_parameters ) (
474
+ & mut self . 0 ,
561
475
opt_bool_to_ptr ( & new_auto_arp) ,
562
476
opt_bool_to_ptr ( & new_send_guid) ,
563
477
opt_ref_to_ptr ( new_ttl. as_ref ( ) ) ,
@@ -576,8 +490,8 @@ impl BaseCode {
576
490
new_subnet_mask : Option < & IpAddress > ,
577
491
) -> Result {
578
492
unsafe {
579
- ( self . set_station_ip ) (
580
- self ,
493
+ ( self . 0 . set_station_ip ) (
494
+ & mut self . 0 ,
581
495
opt_ip_addr_to_ptr ( new_station_ip) ,
582
496
opt_ip_addr_to_ptr ( new_subnet_mask) ,
583
497
)
@@ -603,8 +517,8 @@ impl BaseCode {
603
517
new_pxe_bis_reply : Option < & Packet > ,
604
518
) -> Result {
605
519
unsafe {
606
- ( self . set_packets ) (
607
- self ,
520
+ ( self . 0 . set_packets ) (
521
+ & mut self . 0 ,
608
522
opt_bool_to_ptr ( & new_dhcp_discover_valid) ,
609
523
opt_bool_to_ptr ( & new_dhcp_ack_received) ,
610
524
opt_bool_to_ptr ( & new_proxy_offer_received) ,
@@ -625,7 +539,7 @@ impl BaseCode {
625
539
/// Returns a reference to the `Mode` struct.
626
540
#[ must_use]
627
541
pub const fn mode ( & self ) -> & Mode {
628
- unsafe { & * self . mode }
542
+ unsafe { & * ( self . 0 . mode . cast ( ) ) }
629
543
}
630
544
}
631
545
0 commit comments