aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2021-04-02 16:21:56 +0200
committerAndreas Eversberg <jolly@eversberg.eu>2021-04-03 23:00:01 +0200
commit2d1b5fb437a2035db06f994997c8afdb995d54b2 (patch)
treeda54aac0007976e592d5188ac3ba55381909ed01
parente671b2181224c666a5065b829e4a2fac65bb4e44 (diff)
SIM: Option to write sniffed PDU to file
-rw-r--r--src/sim/main.c7
-rw-r--r--src/sim/sniffer.c15
2 files changed, 20 insertions, 2 deletions
diff --git a/src/sim/main.c b/src/sim/main.c
index 91cae4b..17ebb32 100644
--- a/src/sim/main.c
+++ b/src/sim/main.c
@@ -41,6 +41,7 @@
int num_kanal = 1;
sim_sniffer_t sim_sniffer;
sim_sim_t sim_sim;
+const char *write_pdu_file = NULL;
static int quit = 0;
static const char *serialdev = "/dev/ttyUSB0";
static int baudrate = 9600;
@@ -80,6 +81,8 @@ void print_help(const char *arg0)
printf(" Serial device (default = '%s')\n", serialdev);
printf(" -b --baud-rate <baud>\n");
printf(" Serial baud rate (default = %d)\n", baudrate);
+ printf(" -w --write-pdu <filename>\n");
+ printf(" Write PDU to file (sniffer only)\n");
printf("\nSIM card simulator options:\n");
printf(" -E --eeprom <name>\n");
printf(" Stores and reads EEPROM data to/from file. The file is stored at\n");
@@ -120,6 +123,7 @@ void add_options(void)
option_add('v', "debug", 1);
option_add('s', "serial-device", 1);
option_add('b', "baud-rate", 1);
+ option_add('w', "write-pdu", 1);
option_add('E', "eeprom", 1);
option_add('F', "futln", 1);
option_add(OPT_SICHERUNG, "sicherung", 1);
@@ -156,6 +160,9 @@ int handle_options(int short_option, int argi, char **argv)
case 'b':
baudrate = atoi(argv[argi]);
break;
+ case 'w':
+ write_pdu_file = options_strdup(argv[argi]);
+ break;
case 'E':
eeprom_name = options_strdup(argv[argi]);
break;
diff --git a/src/sim/sniffer.c b/src/sim/sniffer.c
index 728af53..f635246 100644
--- a/src/sim/sniffer.c
+++ b/src/sim/sniffer.c
@@ -26,6 +26,8 @@
#include "sim.h"
#include "sniffer.h"
+extern const char *write_pdu_file;
+
/* Layer 7 */
static void rx_icl_sdu(uint8_t *data, int length)
@@ -742,9 +744,18 @@ static void rx_char(sim_sniffer_t *sim, uint8_t c)
else
PDEBUG(DSIM2, DEBUG_INFO, " control unknown 0x%02x\n", sim->block_control);
PDEBUG(DSIM2, DEBUG_INFO, " length %d\n", sim->block_length);
- if (sim->block_checksum == 0)
+ if (sim->block_checksum == 0) {
+ FILE *fp;
+ if (write_pdu_file && (fp = fopen(write_pdu_file, "a"))) {
+ int i;
+ fprintf(fp, "PDU: addr=0x%02x ctrl=0x%02x len=0x%02x data:", sim->block_address, sim->block_control, sim->block_length);
+ for (i = 0; i < sim->block_length; i++)
+ fprintf(fp, " 0x%02x", sim->block_data[i]);
+ fprintf(fp, "\n");
+ fclose (fp);
+ }
rx_icl_pdu(sim->block_data, sim->block_length);
- else
+ } else
PDEBUG(DSIM2, DEBUG_NOTICE, "Received message with checksum error!\n");
sim->block_state = BLOCK_STATE_ADDRESS;
}