Skip to content

Commit

Permalink
Merge pull request #92 from martinling/rename-backend
Browse files Browse the repository at this point in the history
Rename LUNA backend to Cynthion and update docs
  • Loading branch information
miek authored May 14, 2024
2 parents fcf553a + 0651089 commit 68cb2b1
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 43 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Packetry

A fast, intuitive USB 2.0 protocol analysis application for use with [LUNA](https://github.com/greatscottgadgets/luna).
A fast, intuitive USB 2.0 protocol analysis application for use with [Cynthion](https://greatscottgadgets.com/cynthion/).

Packetry is currently in active development and not yet ready for initial release.

Expand All @@ -20,8 +20,6 @@ To build, run `cargo build` after installing the necessary prerequisites (see be

If you pass a capture filename as an argument, Packetry will attempt to load it. The current supported file format is a `.pcap` file with the `LINKTYPE_USB_2_0` link layer header type.

If no filename is provided, Packetry will attempt to start live capture from an attached device running the [LUNA](https://github.com/greatscottgadgets/luna) USB analyzer applet.

### Installing prerequisites

#### Linux
Expand Down
2 changes: 1 addition & 1 deletion docs/source/introToPacketry.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Packetry
========

A fast, intuitive USB 2.0 protocol analysis application for use with LUNA.
A fast, intuitive USB 2.0 protocol analysis application for use with Cynthion.
42 changes: 21 additions & 21 deletions src/backend/luna.rs → src/backend/cynthion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,30 +80,30 @@ impl State {
}
}

/// A Luna device attached to the system.
pub struct LunaDevice {
/// A Cynthion device attached to the system.
pub struct CynthionDevice {
device_info: DeviceInfo,
pub description: String,
pub speeds: Vec<Speed>,
}

/// A handle to an open Luna device.
pub struct LunaHandle {
/// A handle to an open Cynthion device.
pub struct CynthionHandle {
interface: Interface,
}

pub struct LunaStream {
pub struct CynthionStream {
receiver: mpsc::Receiver<Vec<u8>>,
buffer: VecDeque<u8>,
}

pub struct LunaStop {
pub struct CynthionStop {
stop_request: oneshot::Sender<()>,
worker: JoinHandle::<()>,
}

impl LunaDevice {
pub fn scan() -> Result<Vec<LunaDevice>, Error> {
impl CynthionDevice {
pub fn scan() -> Result<Vec<CynthionDevice>, Error> {
let mut result = Vec::new();
for device_info in nusb::list_devices()? {
if device_info.vendor_id() == VID &&
Expand All @@ -120,9 +120,9 @@ impl LunaDevice {
.product_string()
.unwrap_or("Device");
let description = format!("{} {}", manufacturer, product);
let handle = LunaHandle::new(&device_info)?;
let handle = CynthionHandle::new(&device_info)?;
let speeds = handle.speeds()?;
result.push(LunaDevice{
result.push(CynthionDevice{
device_info,
description,
speeds,
Expand All @@ -132,16 +132,16 @@ impl LunaDevice {
Ok(result)
}

pub fn open(&self) -> Result<LunaHandle, Error> {
LunaHandle::new(&self.device_info)
pub fn open(&self) -> Result<CynthionHandle, Error> {
CynthionHandle::new(&self.device_info)
}
}

impl LunaHandle {
fn new(device_info: &DeviceInfo) -> Result<LunaHandle, Error> {
impl CynthionHandle {
fn new(device_info: &DeviceInfo) -> Result<CynthionHandle, Error> {
let device = device_info.open()?;
let interface = device.claim_interface(0)?;
Ok(LunaHandle { interface })
Ok(CynthionHandle { interface })
}

pub fn speeds(&self) -> Result<Vec<Speed>, Error> {
Expand Down Expand Up @@ -171,7 +171,7 @@ impl LunaHandle {
}

pub fn start<F>(mut self, speed: Speed, result_handler: F)
-> Result<(LunaStream, LunaStop), Error>
-> Result<(CynthionStream, CynthionStop), Error>
where F: FnOnce(Result<(), Error>) + Send + 'static
{
// Channel to pass captured data to the decoder thread.
Expand Down Expand Up @@ -241,11 +241,11 @@ impl LunaHandle {
};
let worker = spawn(move || result_handler(run_capture()));
Ok((
LunaStream {
CynthionStream {
receiver: rx,
buffer: VecDeque::new(),
},
LunaStop {
CynthionStop {
stop_request: stop_tx,
worker,
}
Expand All @@ -269,7 +269,7 @@ impl LunaHandle {
}
}

impl Iterator for LunaStream {
impl Iterator for CynthionStream {
type Item = Vec<u8>;

fn next(&mut self) -> Option<Vec<u8>> {
Expand All @@ -290,7 +290,7 @@ impl Iterator for LunaStream {
}
}

impl LunaStream {
impl CynthionStream {
fn next_buffered_packet(&mut self) -> Option<Vec<u8>> {
// Do we have the length header for the next packet?
let buffer_len = self.buffer.len();
Expand All @@ -313,7 +313,7 @@ impl LunaStream {
}
}

impl LunaStop {
impl CynthionStop {
pub fn stop(self) -> Result<(), Error> {
println!("Requesting capture stop");
self.stop_request.send(())
Expand Down
2 changes: 1 addition & 1 deletion src/backend/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod luna;
pub mod cynthion;
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use gtk::gio::ApplicationFlags;
use packetry::ui::{
activate,
display_error,
stop_luna
stop_cynthion
};

fn main() {
Expand All @@ -14,5 +14,5 @@ fn main() {
);
application.connect_activate(|app| display_error(activate(app)));
application.run_with_args::<&str>(&[]);
display_error(stop_luna());
display_error(stop_cynthion());
}
30 changes: 15 additions & 15 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use pcap_file::{
pcap::{PcapReader, PcapWriter, PcapHeader, RawPcapPacket},
};

use crate::backend::luna::{LunaDevice, LunaHandle, LunaStop, Speed};
use crate::backend::cynthion::{CynthionDevice, CynthionHandle, CynthionStop, Speed};
use crate::capture::{
create_capture,
CaptureReader,
Expand Down Expand Up @@ -93,7 +93,7 @@ enum FileAction {
}

struct DeviceSelector {
devices: Vec<LunaDevice>,
devices: Vec<CynthionDevice>,
dev_strings: Vec<String>,
dev_speeds: Vec<Vec<&'static str>>,
dev_dropdown: DropDown,
Expand Down Expand Up @@ -140,7 +140,7 @@ impl DeviceSelector {
}

fn scan(&mut self) -> Result<bool, Error> {
self.devices = LunaDevice::scan()?;
self.devices = CynthionDevice::scan()?;
self.dev_strings = Vec::with_capacity(self.devices.len());
self.dev_speeds = Vec::with_capacity(self.devices.len());
for device in self.devices.iter() {
Expand All @@ -158,13 +158,13 @@ impl DeviceSelector {
Ok(available)
}

fn open(&self) -> Result<(LunaHandle, Speed), Error> {
fn open(&self) -> Result<(CynthionHandle, Speed), Error> {
let device_id = self.dev_dropdown.selected();
let device = &self.devices[device_id as usize];
let speed_id = self.speed_dropdown.selected() as usize;
let speed = device.speeds[speed_id];
let luna = device.open()?;
Ok((luna, speed))
let cynthion = device.open()?;
Ok((cynthion, speed))
}

fn replace_dropdown<T: AsRef<str>>(
Expand All @@ -187,7 +187,7 @@ pub struct UserInterface {
pub capture: CaptureReader,
selector: DeviceSelector,
file_name: Option<String>,
stop_handle: Option<LunaStop>,
stop_handle: Option<CynthionStop>,
traffic_window: ScrolledWindow,
device_window: ScrolledWindow,
pub traffic_model: Option<TrafficModel>,
Expand Down Expand Up @@ -328,7 +328,7 @@ pub fn activate(application: &Application) -> Result<(), Error> {
window.set_child(Some(&vbox));

scan_button.connect_clicked(|_| display_error(detect_hardware()));
capture_button.connect_clicked(|_| display_error(start_luna()));
capture_button.connect_clicked(|_| display_error(start_cynthion()));
open_button.connect_clicked(|_| display_error(choose_file(Load)));
save_button.connect_clicked(|_| display_error(choose_file(Save)));

Expand Down Expand Up @@ -779,21 +779,21 @@ fn detect_hardware() -> Result<(), Error> {
})
}

pub fn start_luna() -> Result<(), Error> {
pub fn start_cynthion() -> Result<(), Error> {
let writer = reset_capture()?;
with_ui(|ui| {
let (luna, speed) = ui.selector.open()?;
let (cynthion, speed) = ui.selector.open()?;
let (stream_handle, stop_handle) =
luna.start(speed, display_error)?;
cynthion.start(speed, display_error)?;
ui.stop_handle.replace(stop_handle);
ui.open_button.set_sensitive(false);
ui.scan_button.set_sensitive(false);
ui.selector.set_sensitive(false);
ui.capture_button.set_sensitive(false);
ui.stop_button.set_sensitive(true);
let signal_id = ui.stop_button.connect_clicked(|_|
display_error(stop_luna()));
let read_luna = move || {
display_error(stop_cynthion()));
let read_cynthion = move || {
let mut decoder = Decoder::new(writer)?;
for packet in stream_handle {
decoder.handle_raw_packet(&packet)?;
Expand All @@ -802,7 +802,7 @@ pub fn start_luna() -> Result<(), Error> {
Ok(())
};
std::thread::spawn(move || {
display_error(read_luna());
display_error(read_cynthion());
gtk::glib::idle_add_once(|| {
display_error(
with_ui(|ui| {
Expand All @@ -824,7 +824,7 @@ pub fn start_luna() -> Result<(), Error> {
})
}

pub fn stop_luna() -> Result<(), Error> {
pub fn stop_cynthion() -> Result<(), Error> {
with_ui(|ui| {
if let Some(stop_handle) = ui.stop_handle.take() {
stop_handle.stop()?;
Expand Down

0 comments on commit 68cb2b1

Please sign in to comment.