12
12
use super :: { IpAddress , MacAddress } ;
13
13
use crate :: data_types:: Event ;
14
14
use crate :: proto:: unsafe_protocol;
15
- use crate :: { Result , Status , StatusExt } ;
16
- use bitflags:: bitflags;
15
+ use crate :: { Result , StatusExt } ;
17
16
use core:: ffi:: c_void;
18
17
use core:: ptr;
19
18
use core:: ptr:: NonNull ;
19
+ use uefi_raw:: protocol:: network:: snp:: SimpleNetworkProtocol ;
20
+ use uefi_raw:: Boolean ;
21
+
22
+ pub use uefi_raw:: protocol:: network:: snp:: {
23
+ InterruptStatus , NetworkMode , NetworkState , NetworkStatistics , ReceiveFlags ,
24
+ } ;
20
25
21
26
/// The Simple Network Protocol
22
27
#[ derive( Debug ) ]
23
- #[ repr( C ) ]
24
- #[ unsafe_protocol( "a19832b9-ac25-11d3-9a2d-0090273fc14d" ) ]
25
- pub struct SimpleNetwork {
26
- revision : u64 ,
27
- start : extern "efiapi" fn ( this : & Self ) -> Status ,
28
- stop : extern "efiapi" fn ( this : & Self ) -> Status ,
29
- initialize : extern "efiapi" fn (
30
- this : & Self ,
31
- extra_recv_buffer_size : usize ,
32
- extra_transmit_buffer_size : usize ,
33
- ) -> Status ,
34
- reset : extern "efiapi" fn ( this : & Self , extended_verification : bool ) -> Status ,
35
- shutdown : extern "efiapi" fn ( this : & Self ) -> Status ,
36
- receive_filters : extern "efiapi" fn (
37
- this : & Self ,
38
- enable : u32 ,
39
- disable : u32 ,
40
- reset_mcast_filter : bool ,
41
- mcast_filter_count : usize ,
42
- mcast_filter : Option < NonNull < MacAddress > > ,
43
- ) -> Status ,
44
- station_address :
45
- extern "efiapi" fn ( this : & Self , reset : bool , new : Option < & MacAddress > ) -> Status ,
46
- statistics : extern "efiapi" fn (
47
- this : & Self ,
48
- reset : bool ,
49
- stats_size : Option < & mut usize > ,
50
- stats_table : Option < & mut NetworkStats > ,
51
- ) -> Status ,
52
- mcast_ip_to_mac :
53
- extern "efiapi" fn ( this : & Self , ipv6 : bool , ip : & IpAddress , mac : & mut MacAddress ) -> Status ,
54
- nv_data : extern "efiapi" fn (
55
- this : & Self ,
56
- read_write : bool ,
57
- offset : usize ,
58
- buffer_size : usize ,
59
- buffer : * mut c_void ,
60
- ) -> Status ,
61
- get_status : extern "efiapi" fn (
62
- this : & Self ,
63
- interrupt_status : Option < & mut InterruptStatus > ,
64
- tx_buf : Option < & mut * mut c_void > ,
65
- ) -> Status ,
66
- transmit : extern "efiapi" fn (
67
- this : & Self ,
68
- header_size : usize ,
69
- buffer_size : usize ,
70
- buffer : * const c_void ,
71
- src_addr : Option < & MacAddress > ,
72
- dest_addr : Option < & MacAddress > ,
73
- protocol : Option < & u16 > ,
74
- ) -> Status ,
75
- receive : extern "efiapi" fn (
76
- this : & Self ,
77
- header_size : Option < & mut usize > ,
78
- buffer_size : & mut usize ,
79
- buffer : * mut c_void ,
80
- src_addr : Option < & mut MacAddress > ,
81
- dest_addr : Option < & mut MacAddress > ,
82
- protocol : Option < & mut u16 > ,
83
- ) -> Status ,
84
- // On QEMU, this event seems to never fire.
85
- wait_for_packet : Event ,
86
- mode : * const NetworkMode ,
87
- }
28
+ #[ repr( transparent) ]
29
+ #[ unsafe_protocol( SimpleNetworkProtocol :: GUID ) ]
30
+ pub struct SimpleNetwork ( SimpleNetworkProtocol ) ;
88
31
89
32
impl SimpleNetwork {
90
33
/// Change the state of a network from "Stopped" to "Started".
91
34
pub fn start ( & self ) -> Result {
92
- ( self . start ) ( self ) . to_result ( )
35
+ unsafe { ( self . 0 . start ) ( & self . 0 ) } . to_result ( )
93
36
}
94
37
95
38
/// Change the state of a network interface from "Started" to "Stopped".
96
39
pub fn stop ( & self ) -> Result {
97
- ( self . stop ) ( self ) . to_result ( )
40
+ unsafe { ( self . 0 . stop ) ( & self . 0 ) } . to_result ( )
98
41
}
99
42
100
43
/// Reset a network adapter and allocate the transmit and receive buffers
101
44
/// required by the network interface; optionally, also request allocation of
102
45
/// additional transmit and receive buffers.
103
46
pub fn initialize ( & self , extra_rx_buffer_size : usize , extra_tx_buffer_size : usize ) -> Result {
104
- ( self . initialize ) ( self , extra_rx_buffer_size, extra_tx_buffer_size) . to_result ( )
47
+ unsafe { ( self . 0 . initialize ) ( & self . 0 , extra_rx_buffer_size, extra_tx_buffer_size) }
48
+ . to_result ( )
105
49
}
106
50
107
51
/// Reset a network adapter and reinitialize it with the parameters that were
108
52
/// provided in the previous call to `initialize`.
109
53
pub fn reset ( & self , extended_verification : bool ) -> Result {
110
- ( self . reset ) ( self , extended_verification) . to_result ( )
54
+ unsafe { ( self . 0 . reset ) ( & self . 0 , Boolean :: from ( extended_verification) ) } . to_result ( )
111
55
}
112
56
113
57
/// Reset a network adapter, leaving it in a state that is safe
114
58
/// for another driver to initialize
115
59
pub fn shutdown ( & self ) -> Result {
116
- ( self . shutdown ) ( self ) . to_result ( )
60
+ unsafe { ( self . 0 . shutdown ) ( & self . 0 ) } . to_result ( )
117
61
}
118
62
119
63
/// Manage the multicast receive filters of a network.
@@ -124,92 +68,121 @@ impl SimpleNetwork {
124
68
reset_mcast_filter : bool ,
125
69
mcast_filter : Option < & [ MacAddress ] > ,
126
70
) -> Result {
127
- if let Some ( mcast_filter) = mcast_filter {
128
- ( self . receive_filters ) (
129
- self ,
130
- enable. bits ( ) ,
131
- disable. bits ( ) ,
132
- reset_mcast_filter,
133
- mcast_filter. len ( ) ,
134
- NonNull :: new ( mcast_filter. as_ptr ( ) as * mut _ ) ,
135
- )
136
- . to_result ( )
137
- } else {
138
- ( self . receive_filters ) (
139
- self ,
140
- enable. bits ( ) ,
141
- disable. bits ( ) ,
142
- reset_mcast_filter,
143
- 0 ,
144
- None ,
71
+ let filter_count = mcast_filter. map ( |filters| filters. len ( ) ) . unwrap_or ( 0 ) ;
72
+ let filters = mcast_filter
73
+ . map ( |filters| filters. as_ptr ( ) )
74
+ . unwrap_or ( core:: ptr:: null_mut ( ) ) ;
75
+
76
+ unsafe {
77
+ ( self . 0 . receive_filters ) (
78
+ & self . 0 ,
79
+ enable,
80
+ disable,
81
+ Boolean :: from ( reset_mcast_filter) ,
82
+ filter_count,
83
+ filters,
145
84
)
146
- . to_result ( )
147
85
}
86
+ . to_result ( )
148
87
}
149
88
150
89
/// Modify or reset the current station address, if supported.
151
90
pub fn station_address ( & self , reset : bool , new : Option < & MacAddress > ) -> Result {
152
- ( self . station_address ) ( self , reset, new) . to_result ( )
91
+ unsafe {
92
+ ( self . 0 . station_address ) (
93
+ & self . 0 ,
94
+ Boolean :: from ( reset) ,
95
+ new. map ( ptr:: from_ref) . unwrap_or ( ptr:: null ( ) ) ,
96
+ )
97
+ }
98
+ . to_result ( )
153
99
}
154
100
155
101
/// Reset statistics on a network interface.
156
102
pub fn reset_statistics ( & self ) -> Result {
157
- ( self . statistics ) ( self , true , None , None ) . to_result ( )
103
+ unsafe {
104
+ ( self . 0 . statistics ) (
105
+ & self . 0 ,
106
+ Boolean :: from ( true ) ,
107
+ ptr:: null_mut ( ) ,
108
+ ptr:: null_mut ( ) ,
109
+ )
110
+ }
111
+ . to_result ( )
158
112
}
159
113
160
114
/// Collect statistics on a network interface.
161
- pub fn collect_statistics ( & self ) -> Result < NetworkStats > {
162
- let mut stats_table: NetworkStats = Default :: default ( ) ;
163
- let mut stats_size = size_of :: < NetworkStats > ( ) ;
164
- let status = ( self . statistics ) ( self , false , Some ( & mut stats_size) , Some ( & mut stats_table) ) ;
115
+ pub fn collect_statistics ( & self ) -> Result < NetworkStatistics > {
116
+ let mut stats_table: NetworkStatistics = Default :: default ( ) ;
117
+ let mut stats_size = size_of :: < NetworkStatistics > ( ) ;
118
+ let status = unsafe {
119
+ ( self . 0 . statistics ) (
120
+ & self . 0 ,
121
+ Boolean :: from ( false ) ,
122
+ & mut stats_size,
123
+ & mut stats_table,
124
+ )
125
+ } ;
165
126
status. to_result_with_val ( || stats_table)
166
127
}
167
128
168
129
/// Convert a multicast IP address to a multicast HW MAC Address.
169
130
pub fn mcast_ip_to_mac ( & self , ipv6 : bool , ip : IpAddress ) -> Result < MacAddress > {
170
131
let mut mac_address = MacAddress ( [ 0 ; 32 ] ) ;
171
- let status = ( self . mcast_ip_to_mac ) ( self , ipv6, & ip, & mut mac_address) ;
132
+ let status = unsafe {
133
+ ( self . 0 . multicast_ip_to_mac ) (
134
+ & self . 0 ,
135
+ Boolean :: from ( ipv6) ,
136
+ ip. as_raw_ptr ( ) ,
137
+ & mut mac_address,
138
+ )
139
+ } ;
172
140
status. to_result_with_val ( || mac_address)
173
141
}
174
142
175
143
/// Perform read operations on the NVRAM device attached to
176
144
/// a network interface.
177
145
pub fn read_nv_data ( & self , offset : usize , buffer : & [ u8 ] ) -> Result {
178
- ( self . nv_data ) (
179
- self ,
180
- true ,
181
- offset,
182
- buffer. len ( ) ,
183
- buffer. as_ptr ( ) as * mut c_void ,
184
- )
146
+ unsafe {
147
+ ( self . 0 . non_volatile_data ) (
148
+ & self . 0 ,
149
+ Boolean :: from ( true ) ,
150
+ offset,
151
+ buffer. len ( ) ,
152
+ buffer. as_ptr ( ) as * mut c_void ,
153
+ )
154
+ }
185
155
. to_result ( )
186
156
}
187
157
188
158
/// Perform write operations on the NVRAM device attached to a network interface.
189
159
pub fn write_nv_data ( & self , offset : usize , buffer : & mut [ u8 ] ) -> Result {
190
- ( self . nv_data ) (
191
- self ,
192
- false ,
193
- offset,
194
- buffer. len ( ) ,
195
- buffer. as_mut_ptr ( ) . cast ( ) ,
196
- )
160
+ unsafe {
161
+ ( self . 0 . non_volatile_data ) (
162
+ & self . 0 ,
163
+ Boolean :: from ( false ) ,
164
+ offset,
165
+ buffer. len ( ) ,
166
+ buffer. as_mut_ptr ( ) . cast ( ) ,
167
+ )
168
+ }
197
169
. to_result ( )
198
170
}
199
171
200
172
/// Read the current interrupt status and recycled transmit buffer
201
173
/// status from a network interface.
202
174
pub fn get_interrupt_status ( & self ) -> Result < InterruptStatus > {
203
175
let mut interrupt_status = InterruptStatus :: empty ( ) ;
204
- let status = ( self . get_status ) ( self , Some ( & mut interrupt_status) , None ) ;
176
+ let status =
177
+ unsafe { ( self . 0 . get_status ) ( & self . 0 , & mut interrupt_status, ptr:: null_mut ( ) ) } ;
205
178
status. to_result_with_val ( || interrupt_status)
206
179
}
207
180
208
181
/// Read the current recycled transmit buffer status from a
209
182
/// network interface.
210
183
pub fn get_recycled_transmit_buffer_status ( & self ) -> Result < Option < NonNull < u8 > > > {
211
184
let mut tx_buf: * mut c_void = ptr:: null_mut ( ) ;
212
- let status = ( self . get_status ) ( self , None , Some ( & mut tx_buf) ) ;
185
+ let status = unsafe { ( self . 0 . get_status ) ( & self . 0 , ptr :: null_mut ( ) , & mut tx_buf) } ;
213
186
status. to_result_with_val ( || NonNull :: new ( tx_buf. cast ( ) ) )
214
187
}
215
188
@@ -222,15 +195,17 @@ impl SimpleNetwork {
222
195
dest_addr : Option < MacAddress > ,
223
196
protocol : Option < u16 > ,
224
197
) -> Result {
225
- ( self . transmit ) (
226
- self ,
227
- header_size,
228
- buffer. len ( ) ,
229
- buffer. as_ptr ( ) . cast ( ) ,
230
- src_addr. as_ref ( ) ,
231
- dest_addr. as_ref ( ) ,
232
- protocol. as_ref ( ) ,
233
- )
198
+ unsafe {
199
+ ( self . 0 . transmit ) (
200
+ & self . 0 ,
201
+ header_size,
202
+ buffer. len ( ) ,
203
+ buffer. as_ptr ( ) . cast ( ) ,
204
+ src_addr. as_ref ( ) . map ( ptr:: from_ref) . unwrap_or ( ptr:: null ( ) ) ,
205
+ dest_addr. as_ref ( ) . map ( ptr:: from_ref) . unwrap_or ( ptr:: null ( ) ) ,
206
+ protocol. as_ref ( ) . map ( ptr:: from_ref) . unwrap_or ( ptr:: null ( ) ) ,
207
+ )
208
+ }
234
209
. to_result ( )
235
210
}
236
211
@@ -246,15 +221,17 @@ impl SimpleNetwork {
246
221
protocol : Option < & mut u16 > ,
247
222
) -> Result < usize > {
248
223
let mut buffer_size = buffer. len ( ) ;
249
- let status = ( self . receive ) (
250
- self ,
251
- header_size,
252
- & mut buffer_size,
253
- buffer. as_mut_ptr ( ) . cast ( ) ,
254
- src_addr,
255
- dest_addr,
256
- protocol,
257
- ) ;
224
+ let status = unsafe {
225
+ ( self . 0 . receive ) (
226
+ & self . 0 ,
227
+ header_size. map ( ptr:: from_mut) . unwrap_or ( ptr:: null_mut ( ) ) ,
228
+ & mut buffer_size,
229
+ buffer. as_mut_ptr ( ) . cast ( ) ,
230
+ src_addr. map ( ptr:: from_mut) . unwrap_or ( ptr:: null_mut ( ) ) ,
231
+ dest_addr. map ( ptr:: from_mut) . unwrap_or ( ptr:: null_mut ( ) ) ,
232
+ protocol. map ( ptr:: from_mut) . unwrap_or ( ptr:: null_mut ( ) ) ,
233
+ )
234
+ } ;
258
235
status. to_result_with_val ( || buffer_size)
259
236
}
260
237
@@ -264,335 +241,12 @@ impl SimpleNetwork {
264
241
/// of UEFI properly implements this event before using it.
265
242
#[ must_use]
266
243
pub const fn wait_for_packet ( & self ) -> & Event {
267
- & self . wait_for_packet
244
+ unsafe { & * ( ptr :: from_ref ( & self . 0 . wait_for_packet ) . cast :: < Event > ( ) ) }
268
245
}
269
246
270
247
/// Returns a reference to the Simple Network mode.
271
248
#[ must_use]
272
- pub const fn mode ( & self ) -> & NetworkMode {
273
- unsafe { & * self . mode }
274
- }
275
- }
276
-
277
- bitflags ! {
278
- /// Flags to pass to receive_filters to enable/disable reception of some kinds of packets.
279
- #[ repr( transparent) ]
280
- #[ derive( Clone , Copy , Debug , Default , PartialEq , Eq , PartialOrd , Ord ) ]
281
- pub struct ReceiveFlags : u32 {
282
- /// Receive unicast packets.
283
- const UNICAST = 0x01 ;
284
- /// Receive multicast packets.
285
- const MULTICAST = 0x02 ;
286
- /// Receive broadcast packets.
287
- const BROADCAST = 0x04 ;
288
- /// Receive packets in promiscuous mode.
289
- const PROMISCUOUS = 0x08 ;
290
- /// Receive packets in promiscuous multicast mode.
291
- const PROMISCUOUS_MULTICAST = 0x10 ;
292
- }
293
- }
294
-
295
- bitflags ! {
296
- /// Flags returned by get_interrupt_status to indicate which interrupts have fired on the
297
- /// interface since the last call.
298
- #[ repr( transparent) ]
299
- #[ derive( Clone , Copy , Debug , Default , PartialEq , Eq , PartialOrd , Ord ) ]
300
- pub struct InterruptStatus : u32 {
301
- /// Packet received.
302
- const RECEIVE = 0x01 ;
303
- /// Packet transmitted.
304
- const TRANSMIT = 0x02 ;
305
- /// Command interrupt fired.
306
- const COMMAND = 0x04 ;
307
- /// Software interrupt fired.
308
- const SOFTWARE = 0x08 ;
309
- }
310
- }
311
-
312
- /// Network Statistics
313
- ///
314
- /// The description of statistics on the network with the SNP's `statistics` function
315
- /// is returned in this structure
316
- ///
317
- /// Any of these statistics may or may not be available on the device. So, all the
318
- /// retriever functions of the statistics return `None` when a statistic is not supported
319
- #[ repr( C ) ]
320
- #[ derive( Default , Debug ) ]
321
- pub struct NetworkStats {
322
- rx_total_frames : u64 ,
323
- rx_good_frames : u64 ,
324
- rx_undersize_frames : u64 ,
325
- rx_oversize_frames : u64 ,
326
- rx_dropped_frames : u64 ,
327
- rx_unicast_frames : u64 ,
328
- rx_broadcast_frames : u64 ,
329
- rx_multicast_frames : u64 ,
330
- rx_crc_error_frames : u64 ,
331
- rx_total_bytes : u64 ,
332
- tx_total_frames : u64 ,
333
- tx_good_frames : u64 ,
334
- tx_undersize_frames : u64 ,
335
- tx_oversize_frames : u64 ,
336
- tx_dropped_frames : u64 ,
337
- tx_unicast_frames : u64 ,
338
- tx_broadcast_frames : u64 ,
339
- tx_multicast_frames : u64 ,
340
- tx_crc_error_frames : u64 ,
341
- tx_total_bytes : u64 ,
342
- collisions : u64 ,
343
- unsupported_protocol : u64 ,
344
- rx_duplicated_frames : u64 ,
345
- rx_decrypt_error_frames : u64 ,
346
- tx_error_frames : u64 ,
347
- tx_retry_frames : u64 ,
348
- }
349
-
350
- impl NetworkStats {
351
- /// Any statistic value of -1 is not available
352
- const fn available ( & self , stat : u64 ) -> bool {
353
- stat as i64 != -1
354
- }
355
-
356
- /// Takes a statistic and converts it to an option
357
- ///
358
- /// When the statistic is not available, `None` is returned
359
- const fn to_option ( & self , stat : u64 ) -> Option < u64 > {
360
- match self . available ( stat) {
361
- true => Some ( stat) ,
362
- false => None ,
363
- }
364
- }
365
-
366
- /// The total number of frames received, including error frames
367
- /// and dropped frames
368
- #[ must_use]
369
- pub const fn rx_total_frames ( & self ) -> Option < u64 > {
370
- self . to_option ( self . rx_total_frames )
371
- }
372
-
373
- /// The total number of good frames received and copied
374
- /// into receive buffers
375
- #[ must_use]
376
- pub const fn rx_good_frames ( & self ) -> Option < u64 > {
377
- self . to_option ( self . rx_good_frames )
378
- }
379
-
380
- /// The number of frames below the minimum length for the
381
- /// communications device
382
- #[ must_use]
383
- pub const fn rx_undersize_frames ( & self ) -> Option < u64 > {
384
- self . to_option ( self . rx_undersize_frames )
385
- }
386
-
387
- /// The number of frames longer than the maximum length for
388
- /// the communications length device
389
- #[ must_use]
390
- pub const fn rx_oversize_frames ( & self ) -> Option < u64 > {
391
- self . to_option ( self . rx_oversize_frames )
392
- }
393
-
394
- /// The number of valid frames that were dropped because
395
- /// the receive buffers were full
396
- #[ must_use]
397
- pub const fn rx_dropped_frames ( & self ) -> Option < u64 > {
398
- self . to_option ( self . rx_dropped_frames )
399
- }
400
-
401
- /// The number of valid unicast frames received and not dropped
402
- #[ must_use]
403
- pub const fn rx_unicast_frames ( & self ) -> Option < u64 > {
404
- self . to_option ( self . rx_unicast_frames )
405
- }
406
-
407
- /// The number of valid broadcast frames received and not dropped
408
- #[ must_use]
409
- pub const fn rx_broadcast_frames ( & self ) -> Option < u64 > {
410
- self . to_option ( self . rx_broadcast_frames )
411
- }
412
-
413
- /// The number of valid multicast frames received and not dropped
414
- #[ must_use]
415
- pub const fn rx_multicast_frames ( & self ) -> Option < u64 > {
416
- self . to_option ( self . rx_multicast_frames )
417
- }
418
-
419
- /// Number of frames with CRC or alignment errors
420
- #[ must_use]
421
- pub const fn rx_crc_error_frames ( & self ) -> Option < u64 > {
422
- self . to_option ( self . rx_crc_error_frames )
423
- }
424
-
425
- /// The total number of bytes received including frames with errors
426
- /// and dropped frames
427
- #[ must_use]
428
- pub const fn rx_total_bytes ( & self ) -> Option < u64 > {
429
- self . to_option ( self . rx_total_bytes )
430
- }
431
-
432
- /// The total number of frames transmitted including frames
433
- /// with errors and dropped frames
434
- #[ must_use]
435
- pub const fn tx_total_frames ( & self ) -> Option < u64 > {
436
- self . to_option ( self . tx_total_frames )
437
- }
438
-
439
- /// The total number of valid frames transmitted and copied
440
- /// into receive buffers
441
- #[ must_use]
442
- pub const fn tx_good_frames ( & self ) -> Option < u64 > {
443
- self . to_option ( self . tx_good_frames )
444
- }
445
-
446
- /// The number of frames below the minimum length for
447
- /// the media. This would be less than 64 for Ethernet
448
- #[ must_use]
449
- pub const fn tx_undersize_frames ( & self ) -> Option < u64 > {
450
- self . to_option ( self . tx_undersize_frames )
451
- }
452
-
453
- /// The number of frames longer than the maximum length for
454
- /// the media. This would be 1500 for Ethernet
455
- #[ must_use]
456
- pub const fn tx_oversize_frames ( & self ) -> Option < u64 > {
457
- self . to_option ( self . tx_oversize_frames )
458
- }
459
-
460
- /// The number of valid frames that were dropped because
461
- /// received buffers were full
462
- #[ must_use]
463
- pub const fn tx_dropped_frames ( & self ) -> Option < u64 > {
464
- self . to_option ( self . tx_dropped_frames )
465
- }
466
-
467
- /// The number of valid unicast frames transmitted and not
468
- /// dropped
469
- #[ must_use]
470
- pub const fn tx_unicast_frames ( & self ) -> Option < u64 > {
471
- self . to_option ( self . tx_unicast_frames )
472
- }
473
-
474
- /// The number of valid broadcast frames transmitted and
475
- /// not dropped
476
- #[ must_use]
477
- pub const fn tx_broadcast_frames ( & self ) -> Option < u64 > {
478
- self . to_option ( self . tx_broadcast_frames )
479
- }
480
-
481
- /// The number of valid multicast frames transmitted
482
- /// and not dropped
483
- #[ must_use]
484
- pub const fn tx_multicast_frames ( & self ) -> Option < u64 > {
485
- self . to_option ( self . tx_multicast_frames )
486
- }
487
-
488
- /// The number of transmitted frames with CRC or
489
- /// alignment errors
490
- #[ must_use]
491
- pub const fn tx_crc_error_frames ( & self ) -> Option < u64 > {
492
- self . to_option ( self . tx_crc_error_frames )
493
- }
494
-
495
- /// The total number of bytes transmitted including
496
- /// error frames and dropped frames
497
- #[ must_use]
498
- pub const fn tx_total_bytes ( & self ) -> Option < u64 > {
499
- self . to_option ( self . tx_total_bytes )
500
- }
501
-
502
- /// The number of collisions detected on this subnet
503
- #[ must_use]
504
- pub const fn collisions ( & self ) -> Option < u64 > {
505
- self . to_option ( self . collisions )
506
- }
507
-
508
- /// The number of frames destined for unsupported protocol
509
- #[ must_use]
510
- pub const fn unsupported_protocol ( & self ) -> Option < u64 > {
511
- self . to_option ( self . unsupported_protocol )
512
- }
513
-
514
- /// The number of valid frames received that were duplicated
515
- #[ must_use]
516
- pub const fn rx_duplicated_frames ( & self ) -> Option < u64 > {
517
- self . to_option ( self . rx_duplicated_frames )
518
- }
519
-
520
- /// The number of encrypted frames received that failed
521
- /// to decrypt
522
- #[ must_use]
523
- pub const fn rx_decrypt_error_frames ( & self ) -> Option < u64 > {
524
- self . to_option ( self . rx_decrypt_error_frames )
525
- }
526
-
527
- /// The number of frames that failed to transmit after
528
- /// exceeding the retry limit
529
- #[ must_use]
530
- pub const fn tx_error_frames ( & self ) -> Option < u64 > {
531
- self . to_option ( self . tx_error_frames )
532
- }
533
-
534
- /// The number of frames that transmitted successfully
535
- /// after more than one attempt
536
- #[ must_use]
537
- pub const fn tx_retry_frames ( & self ) -> Option < u64 > {
538
- self . to_option ( self . tx_retry_frames )
539
- }
540
- }
541
-
542
- /// The Simple Network Mode
543
- #[ repr( C ) ]
544
- #[ derive( Debug ) ]
545
- pub struct NetworkMode {
546
- /// Reports the current state of the network interface
547
- pub state : NetworkState ,
548
- /// The size of the network interface's hardware address in bytes
549
- pub hw_address_size : u32 ,
550
- /// The size of the network interface's media header in bytes
551
- pub media_header_size : u32 ,
552
- /// The maximum size of the packets supported by the network interface in bytes
553
- pub max_packet_size : u32 ,
554
- /// The size of the NVRAM device attached to the network interface in bytes
555
- pub nv_ram_size : u32 ,
556
- /// The size that must be used for all NVRAM reads and writes
557
- pub nv_ram_access_size : u32 ,
558
- /// The multicast receive filter settings supported by the network interface
559
- pub receive_filter_mask : u32 ,
560
- /// The current multicast receive filter settings
561
- pub receive_filter_setting : u32 ,
562
- /// The maximum number of multicast address receive filters supported by the driver
563
- pub max_mcast_filter_count : u32 ,
564
- /// The current number of multicast address receive filters
565
- pub mcast_filter_count : u32 ,
566
- /// The array containing the addresses of the current multicast address receive filters
567
- pub mcast_filter : [ MacAddress ; 16 ] ,
568
- /// The current hardware MAC address for the network interface
569
- pub current_address : MacAddress ,
570
- /// The current hardware MAC address for broadcast packets
571
- pub broadcast_address : MacAddress ,
572
- /// The permanent hardware MAC address for the network interface
573
- pub permanent_address : MacAddress ,
574
- /// The interface type of the network interface
575
- pub if_type : u8 ,
576
- /// Tells if the MAC address can be changed
577
- pub mac_address_changeable : bool ,
578
- /// Tells if the network interface can transmit more than one packet at a time
579
- pub multiple_tx_supported : bool ,
580
- /// Tells if the presence of the media can be determined
581
- pub media_present_supported : bool ,
582
- /// Tells if media are connected to the network interface
583
- pub media_present : bool ,
584
- }
585
-
586
- newtype_enum ! {
587
- /// The state of a network interface.
588
- pub enum NetworkState : u32 => {
589
- /// The interface has been stopped
590
- STOPPED = 0 ,
591
- /// The interface has been started
592
- STARTED = 1 ,
593
- /// The interface has been initialized
594
- INITIALIZED = 2 ,
595
- /// No state can have a number higher than this
596
- MAX_STATE = 4 ,
249
+ pub fn mode ( & self ) -> & NetworkMode {
250
+ unsafe { & * self . 0 . mode }
597
251
}
598
252
}
0 commit comments