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