MCPcopy Index your code
hub / github.com/RizeCrime/linuxblaster_control / parse_packet_urb

Function parse_packet_urb

sniffer/src/main.rs:189–250  ·  view source on GitHub ↗
(packet: &EnhancedPacketBlock)

Source from the content-addressed store, hash-verified

187// ---------------------------------------------------------------------------
188
189fn parse_packet_urb(packet: &EnhancedPacketBlock) -> UrbHeader {
190 let urb_id = u64::from_le_bytes(packet.data[0..8].try_into().unwrap());
191
192 let typ = match packet.data[8] {
193 0x53 => UrbType::Submit,
194 0x43 => UrbType::Complete,
195 _ => UrbType::UrbError,
196 };
197
198 let transfer_type = match packet.data[9] {
199 0x00 => TransferType::Isochronous,
200 0x01 => TransferType::Interrupt,
201 0x02 => TransferType::Control,
202 0x03 => TransferType::Bulk,
203 _ => TransferType::Bulk,
204 };
205
206 let endpoint = UsbEndpoint {
207 raw: hb(packet.data[10]),
208 direction: if packet.data[10] & 0x80 != 0 {
209 CommDirection::HostIn
210 } else {
211 CommDirection::HostOut
212 },
213 };
214
215 let bus_number = u16::from_le_bytes(packet.data[12..14].try_into().unwrap());
216
217 let setup_fragment = match packet.data[14] {
218 0x00 => Some(SetupFragment {
219 bmRequestType: hb(packet.data[40]),
220 bRequest: hb(packet.data[41]),
221 wValue: hw(u16::from_le_bytes(packet.data[42..44].try_into().unwrap())),
222 wIndex: hw(u16::from_le_bytes(packet.data[44..46].try_into().unwrap())),
223 wLength: hw(u16::from_le_bytes(packet.data[46..48].try_into().unwrap())),
224 }),
225 _ => None,
226 };
227
228 let data_fragment = Some(parse_data_fragment(packet));
229
230 let urb_status_value = i32::from_le_bytes(packet.data[28..32].try_into().unwrap());
231 let urb_status = match urb_status_value {
232 0 => UrbStatus::Success,
233 e => UrbStatus::Err(hd(e as u32)),
234 };
235
236 let transfer_flags = u32::from_le_bytes(packet.data[56..60].try_into().unwrap());
237
238 UrbHeader {
239 id: hq(urb_id),
240 typ,
241 transfer_type,
242 endpoint,
243 device_address: hb(packet.data[11]),
244 bus_number: hw(bus_number),
245 urb_status,
246 transfer_flags: hd(transfer_flags),

Callers 1

parse_fileFunction · 0.85

Calls 5

hbFunction · 0.85
hwFunction · 0.85
parse_data_fragmentFunction · 0.85
hdFunction · 0.85
hqFunction · 0.85

Tested by

no test coverage detected