Skip to content

Commit

Permalink
Pulled CLI tools into a single crate.
Browse files Browse the repository at this point in the history
  • Loading branch information
SirVer committed Dec 7, 2023
1 parent 5664021 commit 4f6fe9c
Show file tree
Hide file tree
Showing 11 changed files with 709 additions and 317 deletions.
254 changes: 124 additions & 130 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resolver = "2"
members = [
"zvt",
"zvt_builder",
"zvt_cli",
"zvt_derive",
]

Expand Down
18 changes: 6 additions & 12 deletions zvt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,12 @@ A crate to interact with payment terminals (ECRs) that use the ZVT protocol, inc

[dependencies]
anyhow = "1.0.70"
chrono = "0.4.24"
clap = { version = "4.2.4", features = ["derive"] }
hex = "0.4.3"
yore = "1.0.2"
zvt_derive = { version = "0.1.0", path = "../zvt_derive" }
zvt_builder = { version = "0.1.0", path = "../zvt_builder" }
log = "0.4.19"
env_logger = "0.10.0"
tokio-stream = "0.1.14"
tokio = { version = "1.29.1", features = ["net", "io-util", "rt-multi-thread", "macros"] }
async-stream = "0.3.5"
serde = { version = "1.0.185", features = ["derive"] }
serde_json = "1.0.105"
chrono = "0.4.24"
futures = "0.3.28"
log = "0.4.19"
pretty-hex = "0.4.0"
tokio = { version = "1.29.1", features = ["net", "io-util", "rt-multi-thread", "macros"] }
tokio-stream = "0.1.14"
zvt_builder = { version = "0.1.0", path = "../zvt_builder" }
zvt_derive = { version = "0.1.0", path = "../zvt_derive" }
157 changes: 0 additions & 157 deletions zvt/src/bin/status/main.rs

This file was deleted.

8 changes: 7 additions & 1 deletion zvt/src/feig/packets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,16 @@ pub struct WriteFile {
#[derive(Debug, PartialEq, Zvt)]
#[zvt_control_field(class = 0x0f, instr = 0xa1)]
pub struct CVendFunctions {
#[zvt_bmp(length = length::Fixed<3>, encoding = encoding::Bcd)]
pub password: Option<usize>,

#[zvt_bmp( encoding = encoding::BigEndian)]
pub instr: u16,
}

pub const CVEND_FUNCTIONS_ENHANCED_SYSTEMS_INFO: u16 = 1;
pub const CVEND_FUNCTIONS_ENHANCED_FACTORY_RESET: u16 = 0x0255;

#[derive(Debug, PartialEq, Zvt)]
#[zvt_control_field(class = 0x80, instr = 0x00)]
pub struct WriteData {
Expand Down Expand Up @@ -192,7 +198,7 @@ mod test {
#[test]
fn test_cvend_functions() {
let bytes = get_bytes("1680761818.690979000_ecr_pt.blob");
let expected = CVendFunctions { instr: 0x01 };
let expected = CVendFunctions { password: None, instr: 0x01 };
assert_eq!(CVendFunctions::zvt_deserialize(&bytes).unwrap().0, expected);
assert_eq!(bytes, expected.zvt_serialize());
}
Expand Down
12 changes: 12 additions & 0 deletions zvt/src/feig/sequences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,15 @@ impl WriteFile {
Box::pin(s)
}
}

pub struct FactoryReset;

#[derive(Debug, ZvtEnum)]
pub enum FactoryResetResponse {
CompletionData(packets::CompletionData),
}

impl Sequence for FactoryReset {
type Input = super::packets::CVendFunctions;
type Output = FactoryResetResponse;
}
10 changes: 10 additions & 0 deletions zvt/src/packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,16 @@ pub struct Diagnosis {
pub tlv: Option<tlv::Diagnosis>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum DiagnosisType {
Line = 1,
Extended = 2,
Configuration = 3,
EmvConfiguration = 4,
Ep2Configuration = 5,
}

#[derive(Debug, PartialEq, Zvt)]
#[zvt_control_field(class = 0x06, instr = 0x93)]
pub struct Initialization {
Expand Down
2 changes: 1 addition & 1 deletion zvt/src/sequences.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{encoding, ZvtEnum, ZvtParser, ZvtSerializer};
use anyhow::Result;
use async_stream::try_stream;
use futures::Stream;
use log::{log_enabled, debug, Level::Debug};
use log::{debug, log_enabled, Level::Debug};
use std::boxed::Box;
use std::marker::Unpin;
use std::pin::Pin;
Expand Down
23 changes: 23 additions & 0 deletions zvt_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "zvt_cli"
edition = "2021"
authors.workspace = true
categories.workspace = true
keywords.workspace = true
license.workspace = true
repository.workspace = true
version.workspace = true
description = """
A crate to interact with payment terminals (ECRs) that use the ZVT protocol, including stand alone commandline tools to interact with the devices.
"""

[dependencies]
anyhow = "1.0.70"
argh = "0.1.12"
env_logger = "0.10.0"
log = "0.4.19"
serde = { version = "1.0.185", features = ["derive"] }
serde_json = "1.0.105"
tokio = { version = "1.29.1", features = ["net", "io-util", "rt-multi-thread", "macros"] }
tokio-stream = "0.1.14"
zvt = { version = "0.1.0", path = "../zvt" }
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
use anyhow::Result;
use clap::Parser;
use argh::FromArgs;
use serde::Deserialize;
use std::fs::read_to_string;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use tokio::net::TcpStream;
use tokio_stream::StreamExt;
use zvt::{feig, packets, sequences, sequences::Sequence};

#[derive(FromArgs, Debug)]
/// Updates a feig terminal.
#[derive(Parser)]
struct Args {
/// The ip and port of the payment terminal.
#[clap(long, default_value = "localhost:22000")]
/// ip and port of the payment terminal.
#[argh(option, default = "\"localhost:22000\".to_string()")]
ip_address: String,

/// The password of the payment terminal. The password is a 6-digits code,
/// password of the payment terminal. The password is a 6-digits code,
/// e.x. 123456.
#[clap(long)]
#[argh(option)]
password: usize,

/// The config byte for the registration.
#[clap(long, default_value = "222")]
/// config byte for the registration.
#[argh(option, default = "222")]
config_byte: u8,

/// Force the update. The update will otherwise be skipped if the returned
/// forces the update. The update will otherwise be skipped if the returned
/// software version corresponds to the version stored in app1/update.spec.
#[clap(long, default_value = "false")]
#[argh(switch)]
force: bool,

/// The folder containing the payload, e.x. firmware and app1 folders.
/// folder containing the payload, e.x. firmware and app1 folders.
#[argh(positional)]
payload_dir: PathBuf,
}

Expand All @@ -41,16 +42,16 @@ struct UpdateSpec {
///
/// We're using the app1/update.spec as a proxy for the version of the entire
/// firmware update. Returns an error if the desired version cannot be read.
fn get_desired_version(payload_dir: &std::path::PathBuf) -> Result<String> {
fn get_desired_version(payload_dir: &Path) -> Result<String> {
let path = payload_dir.join("app1/update.spec");
let update_spec_str = read_to_string(&path)?;
let update_spec_str = read_to_string(path)?;
let update_spec: UpdateSpec = serde_json::from_str(&update_spec_str)?;
Ok(update_spec.version)
}

#[tokio::main]
async fn main() -> Result<()> {
let args = Args::parse();
let args: Args = argh::from_env();

// Connect to the payment terminal.
let mut socket = TcpStream::connect(&args.ip_address).await?;
Expand All @@ -77,7 +78,10 @@ async fn main() -> Result<()> {

{
// Check the current version of the software
let request = feig::packets::CVendFunctions { instr: 1 };
let request = feig::packets::CVendFunctions {
password: None,
instr: 1,
};
let mut stream = feig::sequences::GetSystemInfo::into_stream(&request, &mut socket);
let mut current_version = "unknown".to_string();
while let Some(response) = stream.next().await {
Expand Down
Loading

0 comments on commit 4f6fe9c

Please sign in to comment.