Skip to content

Commit

Permalink
[esp-wifishark] Remove lazy_static in favor of normal initialisation
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev committed Sep 2, 2024
1 parent f40fd21 commit 4b0ba1f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 33 deletions.
1 change: 0 additions & 1 deletion extras/esp-wifishark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ r-extcap = "0.2.4"
pcap-file = "2.0.0"
serialport = "4.2.1"
clap = { version = "4.3.5", features = ["derive"] }
lazy_static = "1.4.0"
66 changes: 34 additions & 32 deletions extras/esp-wifishark/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::{
};

use clap::Parser;
use lazy_static::lazy_static;
use pcap_file::{
pcap::{PcapHeader, PcapPacket, PcapWriter},
DataLink,
Expand All @@ -25,13 +24,16 @@ pub struct AppArgs {
serialport: String,
}

lazy_static! {
static ref METADATA: Metadata = Metadata {
help_url: "http://github.com/esp-rs/esp-wifi".into(),
display_description: "esp-wifi".into(),
..r_extcap::cargo_metadata!()
};
static ref WIFI_CAPTURE_INTERFACE: Interface = Interface {
fn main() {
let args = AppArgs::parse();

if !args.extcap.capture {
if let Some(_filter) = args.extcap.extcap_capture_filter {
std::process::exit(0);
}
}

let wifi_capture_interface = Interface {
value: "wifi".into(),
display: "esp-wifi Ethernet capture".into(),
dlt: Dlt {
Expand All @@ -40,7 +42,8 @@ lazy_static! {
display: "Ethernet".into(),
},
};
static ref BT_CAPTURE_INTERFACE: Interface = Interface {

let bt_capture_interface = Interface {
value: "bt".into(),
display: "esp-wifi HCI capture".into(),
dlt: Dlt {
Expand All @@ -49,44 +52,43 @@ lazy_static! {
display: "HCI".into(),
},
};
static ref CONFIG_SERIALPORT: StringConfig = StringConfig::builder()
.config_number(1)
.call("serialport")
.display("Serialport")
.tooltip("Serialport to connect to")
.required(false)
.placeholder("")
.build();
}

fn main() {
let args = AppArgs::parse();

if !args.extcap.capture {
if let Some(_filter) = args.extcap.extcap_capture_filter {
std::process::exit(0);
}
}

match args.extcap.run().unwrap() {
ExtcapStep::Interfaces(interfaces_step) => {
let metadata = Metadata {
help_url: "http://github.com/esp-rs/esp-wifi".into(),
display_description: "esp-wifi".into(),
..r_extcap::cargo_metadata!()
};

interfaces_step.list_interfaces(
&METADATA,
&[&*WIFI_CAPTURE_INTERFACE, &*BT_CAPTURE_INTERFACE],
&metadata,
&[&wifi_capture_interface, &bt_capture_interface],
&[],
);
}
ExtcapStep::Dlts(dlts_step) => {
dlts_step
.print_from_interfaces(&[&*WIFI_CAPTURE_INTERFACE, &*BT_CAPTURE_INTERFACE])
.print_from_interfaces(&[&wifi_capture_interface, &bt_capture_interface])
.unwrap();
}
ExtcapStep::Config(config_step) => config_step.list_configs(&[&*CONFIG_SERIALPORT]),
ExtcapStep::Config(config_step) => {
let config_serialport = StringConfig::builder()
.config_number(1)
.call("serialport")
.display("Serialport")
.tooltip("Serialport to connect to")
.required(false)
.placeholder("")
.build();

config_step.list_configs(&[&config_serialport])
}
ExtcapStep::ReloadConfig(_reload_config_step) => {
panic!("Unsupported operation");
}
ExtcapStep::Capture(capture_step) => {
let (data_link, prefix) = if capture_step.interface == WIFI_CAPTURE_INTERFACE.value {
let (data_link, prefix) = if capture_step.interface == wifi_capture_interface.value {
(DataLink::ETHERNET, "@WIFIFRAME [")
} else {
(DataLink::BLUETOOTH_HCI_H4, "@HCIFRAME [")
Expand Down

0 comments on commit 4b0ba1f

Please sign in to comment.