add ability to filter on direction and data contents
pub type U16Cmp = fn(x: u16) -> bool;
pub type CIntCmp = fn(x: libc::c_int) -> bool;
pub type CUintCmp = fn(x: libc::c_uint) -> bool;
+pub type SliceCmp = fn(x: &[u8]) -> bool;
+pub type BoolCmp = fn(x: bool) -> bool;
#[derive(Default, Copy, Clone)]
pub struct DeviceFilter {
pub flag_data: Option<U8Cmp>,
pub status: Option<CIntCmp>,
pub data_len: Option<CUintCmp>,
+ pub dir_out: Option<BoolCmp>,
+
+ // USB data
+ pub data: Option<SliceCmp>,
// Setup packet
pub setup_request_type: Option<U8Cmp>,
self.pkt_type != b'S' && self.status != 0
}
- fn match_filter(&self, f: Option<&UsbmonFilter>) -> bool {
+ fn match_filter(&self, f: Option<&UsbmonFilter>, data: &[u8]) -> bool {
let mut matched = true;
if f.is_none() {
return true;
matched &= f.epnum.map(|x| x(self.epnum())).unwrap_or(true);
matched &= f.devnum.map(|x| x(self.devnum())).unwrap_or(true);
matched &= f.busnum.map(|x| x(self.busnum())).unwrap_or(true);
+ matched &= f.dir_out.map(|x| x(self.dir_out())).unwrap_or(true);
matched &= f.flag_setup.map(|x| x(self.flag_setup())).unwrap_or(true);
matched &= f.flag_data.map(|x| x(self.flag_data())).unwrap_or(true);
matched &= f.status.map(|x| x(self.status())).unwrap_or(true);
matched &= f.data_len.map(|x| x(self.length())).unwrap_or(true);
+ matched &= f.data.map(|x| x(data)).unwrap_or(true);
+
matched &= f.setup_request_type
.map(|x| x(self.setup_packet()
.map(|s| s.request_type()).unwrap_or(0))).unwrap_or(true);
}
}
- if !capturing && (*hdr).match_filter(start_filter) {
+ if !capturing && (*hdr).match_filter(start_filter, &pkt_data) {
// If the start filter matches, begin capturing packets
capturing = true;
start_time = (*hdr).usec_since(0);
}
}
else if capturing {
- if end_filter.is_some() && (*hdr).match_filter(end_filter) {
+ if end_filter.is_some() && (*hdr).match_filter(end_filter, &pkt_data) {
if !cli_args.quiet {
(*hdr).print(start_time, &pkt_data);
}
stop_capturing_count = Some(f.pkts_after);
}
}
- else if (*hdr).match_filter(active_filter) {
+ else if (*hdr).match_filter(active_filter, &pkt_data) {
if !cli_args.quiet {
(*hdr).print(start_time, &pkt_data);
}