Change in simtrace2[master]: Introduce simtrace2-tool
laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/simtrace2/+/24574 ) Change subject: Introduce simtrace2-tool .. Introduce simtrace2-tool The simtrace-tool isa command line tool which can be used to e.g. manually request a modem reset. Change-Id: I3a8896ac2b3caef7590b51118359e5caed820a40 --- M host/src/Makefile.am A host/src/simtrace2-tool.c 2 files changed, 341 insertions(+), 1 deletion(-) git pull ssh://gerrit.osmocom.org:29418/simtrace2 refs/changes/74/24574/1 diff --git a/host/src/Makefile.am b/host/src/Makefile.am index fa5be6e..17be9eb 100644 --- a/host/src/Makefile.am +++ b/host/src/Makefile.am @@ -5,10 +5,12 @@ LDADD= $(top_builddir)/lib/libosmo-simtrace2.la \ $(LIBOSMOCORE_LIBS) $(LIBOSMOSIM_LIBS) $(LIBOSMOUSB_LIBS) $(LIBUSB_LIBS) -bin_PROGRAMS = simtrace2-cardem-pcsc simtrace2-list simtrace2-sniff +bin_PROGRAMS = simtrace2-cardem-pcsc simtrace2-list simtrace2-sniff simtrace2-tool simtrace2_cardem_pcsc_SOURCES = simtrace2-cardem-pcsc.c simtrace2_list_SOURCES = simtrace2_usb.c simtrace2_sniff_SOURCES = simtrace2-sniff.c + +simtrace2_tool_SOURCES = simtrace2-tool.c diff --git a/host/src/simtrace2-tool.c b/host/src/simtrace2-tool.c new file mode 100644 index 000..56ec791 --- /dev/null +++ b/host/src/simtrace2-tool.c @@ -0,0 +1,338 @@ +/* simtrace2-tool - main program for the host PC to provide a remote SIM + * using the SIMtrace 2 firmware in card emulation mode + * + * (C) 2019 by Harald Welte + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#define _GNU_SOURCE +#include + +#include + +#include + +#include +#include +#include +#include + +#include +#include + +/*** + * Incoming Messages + ***/ + +static void print_welcome(void) +{ + printf("simtrace2-tool\n" + "(C) 2019 Harald Welte \n"); +} + +static void print_help(void) +{ + printf( "simtrace2-tool [OPTIONS] COMMAND\n\n"); + printf( "Options:\n" + "\t-h\t--help\n" + "\t-V\t--usb-vendor\tVENDOR_ID\n" + "\t-P\t--usb-product\tPRODUCT_ID\n" + "\t-C\t--usb-config\tCONFIG_ID\n" + "\t-I\t--usb-interface\tINTERFACE_ID\n" + "\t-S\t--usb-altsetting ALTSETTING_ID\n" + "\t-A\t--usb-address\tADDRESS\n" + "\t-H\t--usb-path\tPATH\n" + "\n" + ); + printf( "Commands:\n" + "\tmodem reset (enable|disable|cycle)\n" + "\tmodem sim-switch (local|remote)\n" + "\n"); +} + +static const struct option opts[] = { + { "help", 0, 0, 'h' }, + { "usb-vendor", 1, 0, 'V' }, + { "usb-product", 1, 0, 'P' }, + { "usb-config", 1, 0, 'C' }, + { "usb-interface", 1, 0, 'I' }, + { "usb-altsetting", 1, 0, 'S' }, + { "usb-address", 1, 0, 'A' }, + { "usb-path", 1, 0, 'H' }, + { NULL, 0, 0, 0 } +}; + +static void run_mainloop(struct osmo_st2_cardem_inst *ci) +{ + struct osmo_st2_transport *transp = ci->slot->transp; + uint8_t buf[16*265]; + int xfer_len; + int rc; + + while (1) { + /* read data from SIMtrace2 device */ + rc = libusb_bulk_transfer(transp->usb_devh, transp->usb_ep.in, + buf, sizeof(buf), &xfer_len, 100); + if (rc < 0 && rc != LIBUSB_ERROR_TIMEOUT && + rc != LIBUSB_ERROR_INTERRUPTED && + rc != LIBUSB_ERROR_IO) { + fprintf(stderr, "BULK IN transfer error; rc=%d\n", rc); + return; + } + /* break the loop if no new messages arrive within 100ms */ + if (rc == LIBUSB_ERROR_TIMEOUT) + return; + } +} + +static struct osmo_st2_transport _transp; + +static struct osmo_st2_slot _slot = { + .transp = &_transp, + .slot_nr = 0, +}; + +struct osmo_st2_cardem_inst _ci = { + .slot = &_slot, +}; + +struct
Change in simtrace2[master]: Introduce simtrace2-tool
osmith has posted comments on this change. ( https://gerrit.osmocom.org/c/simtrace2/+/24574 ) Change subject: Introduce simtrace2-tool .. Patch Set 1: (3 comments) https://gerrit.osmocom.org/c/simtrace2/+/24574/1/host/src/simtrace2-tool.c File host/src/simtrace2-tool.c: https://gerrit.osmocom.org/c/simtrace2/+/24574/1/host/src/simtrace2-tool.c@261 PS1, Line 261: if ((vendor_id < 0 || product_id < 0)) { why ((? https://gerrit.osmocom.org/c/simtrace2/+/24574/1/host/src/simtrace2-tool.c@293 PS1, Line 293: rc = libusb_claim_interface(transp->usb_devh, if_num); why is this needed? I would expect "osmo_libusb_open_claim_interface" to claim it already https://gerrit.osmocom.org/c/simtrace2/+/24574/1/host/src/simtrace2-tool.c@322 PS1, Line 322: 1 Doesn't make much difference, but I'm wondering: why not pass rc here? -- To view, visit https://gerrit.osmocom.org/c/simtrace2/+/24574 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: simtrace2 Gerrit-Branch: master Gerrit-Change-Id: I3a8896ac2b3caef7590b51118359e5caed820a40 Gerrit-Change-Number: 24574 Gerrit-PatchSet: 1 Gerrit-Owner: laforge Gerrit-Reviewer: Jenkins Builder Gerrit-CC: osmith Gerrit-Comment-Date: Tue, 08 Jun 2021 16:31:08 + Gerrit-HasComments: Yes Gerrit-Has-Labels: No Gerrit-MessageType: comment
Change in simtrace2[master]: Introduce simtrace2-tool
Hoernchen has uploaded a new patch set (#4) to the change originally created by laforge. ( https://gerrit.osmocom.org/c/simtrace2/+/24574 ) Change subject: Introduce simtrace2-tool .. Introduce simtrace2-tool The simtrace-tool is a command line tool which can be used to e.g. manually request a modem reset. Change-Id: I3a8896ac2b3caef7590b51118359e5caed820a40 --- M host/src/Makefile.am A host/src/simtrace2-tool.c 2 files changed, 335 insertions(+), 1 deletion(-) git pull ssh://gerrit.osmocom.org:29418/simtrace2 refs/changes/74/24574/4 -- To view, visit https://gerrit.osmocom.org/c/simtrace2/+/24574 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: simtrace2 Gerrit-Branch: master Gerrit-Change-Id: I3a8896ac2b3caef7590b51118359e5caed820a40 Gerrit-Change-Number: 24574 Gerrit-PatchSet: 4 Gerrit-Owner: laforge Gerrit-Reviewer: Hoernchen Gerrit-Reviewer: Jenkins Builder Gerrit-CC: osmith Gerrit-MessageType: newpatchset
Change in simtrace2[master]: Introduce simtrace2-tool
osmith has posted comments on this change. ( https://gerrit.osmocom.org/c/simtrace2/+/24574 ) Change subject: Introduce simtrace2-tool .. Patch Set 4: Code-Review+1 (1 comment) https://gerrit.osmocom.org/c/simtrace2/+/24574/1/host/src/simtrace2-tool.c File host/src/simtrace2-tool.c: https://gerrit.osmocom.org/c/simtrace2/+/24574/1/host/src/simtrace2-tool.c@293 PS1, Line 293: rc = libusb_claim_interface(transp->usb_devh, if_num); > why is this needed? I would expect "osmo_libusb_open_claim_interface" to > claim it already @Hoernchen: FYI I did not test this, just guessing by the name of the function. So I'm assuming you verified that it still works after removing this part. -- To view, visit https://gerrit.osmocom.org/c/simtrace2/+/24574 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: simtrace2 Gerrit-Branch: master Gerrit-Change-Id: I3a8896ac2b3caef7590b51118359e5caed820a40 Gerrit-Change-Number: 24574 Gerrit-PatchSet: 4 Gerrit-Owner: laforge Gerrit-Reviewer: Hoernchen Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: osmith Gerrit-Comment-Date: Fri, 30 Jul 2021 08:16:22 + Gerrit-HasComments: Yes Gerrit-Has-Labels: Yes Comment-In-Reply-To: osmith Gerrit-MessageType: comment
Change in simtrace2[master]: Introduce simtrace2-tool
Hoernchen has posted comments on this change. ( https://gerrit.osmocom.org/c/simtrace2/+/24574 ) Change subject: Introduce simtrace2-tool .. Patch Set 4: I didn't test it, but I've looked at the function, and it does claim the if, just like the duplicated extra claim. -- To view, visit https://gerrit.osmocom.org/c/simtrace2/+/24574 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: simtrace2 Gerrit-Branch: master Gerrit-Change-Id: I3a8896ac2b3caef7590b51118359e5caed820a40 Gerrit-Change-Number: 24574 Gerrit-PatchSet: 4 Gerrit-Owner: laforge Gerrit-Reviewer: Hoernchen Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: osmith Gerrit-Comment-Date: Fri, 30 Jul 2021 12:17:29 + Gerrit-HasComments: No Gerrit-Has-Labels: No Gerrit-MessageType: comment
Change in simtrace2[master]: Introduce simtrace2-tool
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/simtrace2/+/24574 ) Change subject: Introduce simtrace2-tool .. Patch Set 4: Code-Review+2 lets merge this as-is, i currently do not have the capability to address review issues. it will not break exitsing code as it is a self-contained new file. -- To view, visit https://gerrit.osmocom.org/c/simtrace2/+/24574 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: simtrace2 Gerrit-Branch: master Gerrit-Change-Id: I3a8896ac2b3caef7590b51118359e5caed820a40 Gerrit-Change-Number: 24574 Gerrit-PatchSet: 4 Gerrit-Owner: laforge Gerrit-Reviewer: Hoernchen Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge Gerrit-Reviewer: osmith Gerrit-Comment-Date: Mon, 02 Aug 2021 09:20:41 + Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
Change in simtrace2[master]: Introduce simtrace2-tool
laforge has submitted this change. ( https://gerrit.osmocom.org/c/simtrace2/+/24574 ) Change subject: Introduce simtrace2-tool .. Introduce simtrace2-tool The simtrace-tool is a command line tool which can be used to e.g. manually request a modem reset. Change-Id: I3a8896ac2b3caef7590b51118359e5caed820a40 --- M host/src/Makefile.am A host/src/simtrace2-tool.c 2 files changed, 335 insertions(+), 1 deletion(-) Approvals: laforge: Looks good to me, approved osmith: Looks good to me, but someone else must approve Jenkins Builder: Verified diff --git a/host/src/Makefile.am b/host/src/Makefile.am index fa5be6e..17be9eb 100644 --- a/host/src/Makefile.am +++ b/host/src/Makefile.am @@ -5,10 +5,12 @@ LDADD= $(top_builddir)/lib/libosmo-simtrace2.la \ $(LIBOSMOCORE_LIBS) $(LIBOSMOSIM_LIBS) $(LIBOSMOUSB_LIBS) $(LIBUSB_LIBS) -bin_PROGRAMS = simtrace2-cardem-pcsc simtrace2-list simtrace2-sniff +bin_PROGRAMS = simtrace2-cardem-pcsc simtrace2-list simtrace2-sniff simtrace2-tool simtrace2_cardem_pcsc_SOURCES = simtrace2-cardem-pcsc.c simtrace2_list_SOURCES = simtrace2_usb.c simtrace2_sniff_SOURCES = simtrace2-sniff.c + +simtrace2_tool_SOURCES = simtrace2-tool.c diff --git a/host/src/simtrace2-tool.c b/host/src/simtrace2-tool.c new file mode 100644 index 000..658f84a --- /dev/null +++ b/host/src/simtrace2-tool.c @@ -0,0 +1,332 @@ +/* simtrace2-tool - main program for the host PC to provide a remote SIM + * using the SIMtrace 2 firmware in card emulation mode + * + * (C) 2019 by Harald Welte + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#define _GNU_SOURCE +#include + +#include + +#include + +#include +#include +#include +#include + +#include +#include + +/*** + * Incoming Messages + ***/ + +static void print_welcome(void) +{ + printf("simtrace2-tool\n" + "(C) 2019 Harald Welte \n"); +} + +static void print_help(void) +{ + printf( "simtrace2-tool [OPTIONS] COMMAND\n\n"); + printf( "Options:\n" + "\t-h\t--help\n" + "\t-V\t--usb-vendor\tVENDOR_ID\n" + "\t-P\t--usb-product\tPRODUCT_ID\n" + "\t-C\t--usb-config\tCONFIG_ID\n" + "\t-I\t--usb-interface\tINTERFACE_ID\n" + "\t-S\t--usb-altsetting ALTSETTING_ID\n" + "\t-A\t--usb-address\tADDRESS\n" + "\t-H\t--usb-path\tPATH\n" + "\n" + ); + printf( "Commands:\n" + "\tmodem reset (enable|disable|cycle)\n" + "\tmodem sim-switch (local|remote)\n" + "\n"); +} + +static const struct option opts[] = { + { "help", 0, 0, 'h' }, + { "usb-vendor", 1, 0, 'V' }, + { "usb-product", 1, 0, 'P' }, + { "usb-config", 1, 0, 'C' }, + { "usb-interface", 1, 0, 'I' }, + { "usb-altsetting", 1, 0, 'S' }, + { "usb-address", 1, 0, 'A' }, + { "usb-path", 1, 0, 'H' }, + { NULL, 0, 0, 0 } +}; + +static void run_mainloop(struct osmo_st2_cardem_inst *ci) +{ + struct osmo_st2_transport *transp = ci->slot->transp; + uint8_t buf[16*265]; + int xfer_len; + int rc; + + while (1) { + /* read data from SIMtrace2 device */ + rc = libusb_bulk_transfer(transp->usb_devh, transp->usb_ep.in, + buf, sizeof(buf), &xfer_len, 100); + if (rc < 0 && rc != LIBUSB_ERROR_TIMEOUT && + rc != LIBUSB_ERROR_INTERRUPTED && + rc != LIBUSB_ERROR_IO) { + fprintf(stderr, "BULK IN transfer error; rc=%d\n", rc); + return; + } + /* break the loop if no new messages arrive within 100ms */ + if (rc == LIBUSB_ERROR_TIMEOUT) + return; + } +} + +static struct osmo_st2_transport _transp; + +static struct osmo_st2_slot _slot = { + .transp = &_transp, + .slot_nr = 0, +}; + +struct osmo_st2_cardem_i