1
1
use uefi:: prelude:: BootServices ;
2
2
use uefi:: proto:: network:: snp:: SimpleNetwork ;
3
+ use uefi:: proto:: network:: snp:: EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST ;
4
+ use uefi:: proto:: network:: snp:: EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST ;
5
+ use uefi:: proto:: network:: snp:: EFI_SIMPLE_NETWORK_RECEIVE_UNICAST ;
3
6
use uefi:: proto:: network:: MacAddress ;
4
-
7
+ use uefi :: Status ;
5
8
6
9
pub fn test ( bt : & BootServices ) {
7
10
info ! ( "Testing the simple network protocol" ) ;
8
11
9
- let handles = bt
10
- . find_handles :: < SimpleNetwork > ( )
11
- . expect ( "Failed to get handles for `SimpleNetwork` protocol" ) ;
12
+ let handles = bt. find_handles :: < SimpleNetwork > ( ) . unwrap_or_default ( ) ;
12
13
13
14
for handle in handles {
14
-
15
15
let simple_network = bt. open_protocol_exclusive :: < SimpleNetwork > ( handle) ;
16
- if simple_network. is_err ( ) { continue ; }
16
+ if simple_network. is_err ( ) {
17
+ continue ;
18
+ }
17
19
let simple_network = simple_network. unwrap ( ) ;
18
20
19
21
// Check shutdown
20
- simple_network. shutdown ( ) . expect ( "Failed to shutdown Simple Network" ) ;
22
+ simple_network
23
+ . shutdown ( )
24
+ . expect ( "Failed to shutdown Simple Network" ) ;
21
25
22
26
// Check stop
23
- simple_network. stop ( ) . expect ( "Failed to stop Simple Network" ) ;
27
+ simple_network
28
+ . stop ( )
29
+ . expect ( "Failed to stop Simple Network" ) ;
24
30
25
31
// Check start
26
- simple_network. start ( ) . expect ( "Failed to start Simple Network" ) ;
32
+ simple_network
33
+ . start ( )
34
+ . expect ( "Failed to start Simple Network" ) ;
27
35
28
36
// Check initialize
29
- simple_network. initialize ( None , None )
37
+ simple_network
38
+ . initialize ( 0 , 0 )
30
39
. expect ( "Failed to initialize Simple Network" ) ;
31
40
32
41
simple_network. reset_statistics ( ) . unwrap ( ) ;
@@ -35,51 +44,81 @@ pub fn test(bt: &BootServices) {
35
44
simple_network. get_interrupt_status ( ) . unwrap ( ) ;
36
45
37
46
// Set receive filters
38
- simple_network. receive_filters ( 0x01 | 0x02 | 0x04 | 0x08 | 0x10 , 0 , false , None , None )
47
+ simple_network
48
+ . receive_filters (
49
+ EFI_SIMPLE_NETWORK_RECEIVE_UNICAST
50
+ | EFI_SIMPLE_NETWORK_RECEIVE_MULTICAST
51
+ | EFI_SIMPLE_NETWORK_RECEIVE_BROADCAST ,
52
+ 0 ,
53
+ false ,
54
+ None ,
55
+ )
39
56
. expect ( "Failed to set receive filters" ) ;
40
57
41
58
// Check media
42
59
if !simple_network. mode ( ) . media_present_supported || !simple_network. mode ( ) . media_present {
43
60
continue ;
44
61
}
45
62
46
- let payload = & [ 0u8 ; 46 ] ;
47
-
48
- let dest_addr = MacAddress ( [ 0xffu8 ; 32 ] ) ;
49
- assert ! ( !simple_network. get_interrupt_status( ) . unwrap( ) . transmit_interrupt( ) ) ;
63
+ let payload = b"\0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \
64
+ \x45 \x00 \
65
+ \x00 \x21 \
66
+ \x00 \x01 \
67
+ \x00 \x00 \
68
+ \x10 \
69
+ \x11 \
70
+ \x07 \x6a \
71
+ \xc0 \xa8 \x11 \x0f \
72
+ \xc0 \xa8 \x11 \x02 \
73
+ \x54 \x45 \
74
+ \x54 \x44 \
75
+ \x00 \x0d \
76
+ \xa9 \xe4 \
77
+ \x04 \x01 \x02 \x03 \x04 ";
78
+
79
+ let dest_addr = MacAddress ( [ 0xffu8 ; 32 ] ) ;
80
+ assert ! ( !simple_network
81
+ . get_interrupt_status( )
82
+ . unwrap( )
83
+ . transmit_interrupt( ) ) ;
50
84
// Send the frame
51
- simple_network. transmit (
52
- simple_network. mode ( ) . media_header_size as usize ,
53
- payload,
54
- None ,
55
- Some ( & dest_addr) ,
56
- Some ( & 0x0800 ) ,
57
- )
58
- . expect ( "Failed to transmit frame" ) ;
85
+ simple_network
86
+ . transmit (
87
+ simple_network. mode ( ) . media_header_size as usize ,
88
+ payload,
89
+ None ,
90
+ Some ( & dest_addr) ,
91
+ Some ( & 0x0800 ) ,
92
+ )
93
+ . expect ( "Failed to transmit frame" ) ;
59
94
60
95
info ! ( "Waiting for the transmit" ) ;
61
- while !simple_network. get_interrupt_status ( ) . unwrap ( ) . transmit_interrupt ( ) { }
96
+ while !simple_network
97
+ . get_interrupt_status ( )
98
+ . unwrap ( )
99
+ . transmit_interrupt ( )
100
+ { }
62
101
63
102
// Attempt to receive a frame
64
103
let mut buffer = [ 0u8 ; 1500 ] ;
65
-
66
- let mut count = 0 ;
67
-
104
+
68
105
info ! ( "Waiting for the reception" ) ;
69
- while count < 1_000 {
70
- let result = simple_network. receive (
71
- & mut buffer,
72
- None ,
73
- None ,
74
- None ,
75
- None
76
- ) ;
77
- if result. is_ok ( ) { break ; }
78
- count += 1 ;
106
+ if simple_network. receive ( & mut buffer, None , None , None , None )
107
+ == Err ( Status :: NOT_READY . into ( ) )
108
+ {
109
+ bt. stall ( 1_000_000 ) ;
110
+
111
+ simple_network
112
+ . receive ( & mut buffer, None , None , None , None )
113
+ . unwrap ( ) ;
79
114
}
80
115
116
+ assert_eq ! ( buffer[ 42 ..47 ] , [ 4 , 4 , 3 , 2 , 1 ] ) ;
117
+
81
118
// Get stats
82
- let stats = simple_network. collect_statistics ( ) . expect ( "Failed to collect statistics" ) ;
119
+ let stats = simple_network
120
+ . collect_statistics ( )
121
+ . expect ( "Failed to collect statistics" ) ;
83
122
info ! ( "Stats: {:?}" , stats) ;
84
123
85
124
// One frame should have been transmitted and one received
0 commit comments