Skip to content

Commit fc71bd7

Browse files
committed
Clean up implementation of SNP and fix test code.
1 parent 1975acf commit fc71bd7

File tree

2 files changed

+135
-98
lines changed
  • uefi/src/proto/network
  • uefi-test-runner/src/proto/network

2 files changed

+135
-98
lines changed

uefi-test-runner/src/proto/network/snp.rs

Lines changed: 77 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,43 @@
11
use uefi::prelude::BootServices;
22
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;
36
use uefi::proto::network::MacAddress;
4-
7+
use uefi::Status;
58

69
pub fn test(bt: &BootServices) {
710
info!("Testing the simple network protocol");
811

9-
let handles = bt
12+
let handles = bt
1013
.find_handles::<SimpleNetwork>()
1114
.expect("Failed to get handles for `SimpleNetwork` protocol");
1215

1316
for handle in handles {
14-
1517
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+
}
1721
let simple_network = simple_network.unwrap();
1822

1923
// Check shutdown
20-
simple_network.shutdown().expect("Failed to shutdown Simple Network");
24+
simple_network
25+
.shutdown()
26+
.expect("Failed to shutdown Simple Network");
2127

2228
// Check stop
23-
simple_network.stop().expect("Failed to stop Simple Network");
29+
simple_network
30+
.stop()
31+
.expect("Failed to stop Simple Network");
2432

2533
// Check start
26-
simple_network.start().expect("Failed to start Simple Network");
34+
simple_network
35+
.start()
36+
.expect("Failed to start Simple Network");
2737

2838
// Check initialize
29-
simple_network.initialize(None, None)
39+
simple_network
40+
.initialize(0, 0)
3041
.expect("Failed to initialize Simple Network");
3142

3243
simple_network.reset_statistics().unwrap();
@@ -35,51 +46,81 @@ pub fn test(bt: &BootServices) {
3546
simple_network.get_interrupt_status().unwrap();
3647

3748
// 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+
)
3958
.expect("Failed to set receive filters");
4059

4160
// Check media
4261
if !simple_network.mode().media_present_supported || !simple_network.mode().media_present {
4362
continue;
4463
}
4564

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());
5086
// 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");
5996

6097
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+
{}
62103

63104
// Attempt to receive a frame
64105
let mut buffer = [0u8; 1500];
65-
66-
let mut count = 0;
67-
106+
68107
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();
79116
}
80117

118+
assert_eq!(buffer[42..47], [4, 4, 3, 2, 1]);
119+
81120
// 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");
83124
info!("Stats: {:?}", stats);
84125

85126
// One frame should have been transmitted and one received

0 commit comments

Comments
 (0)