<p>laforge <strong>submitted</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/osmo-remsim/+/16609">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">remsim-client: Port from local copy to libosmousb + libosmo-simtrace2<br><br>We originally imported a copy of [most of] the code of<br>simtrace2.git/host into this repository.  That was a quick hack to get<br>things going, but now that simtrace2.git is providing a shared library<br>of simtrace2 utility functions, let's migrate over to it.<br><br>At the same time, some functions (libusb_util) have been migrated to<br>libosmousb (a new library in libosmocore.git), so we must add that<br>as new dependency, too.<br><br>This performs the minimally required changes and is *not* a proper<br>port to the libosmousb osmocore select loop integration, whcih will<br>follow in a separate patch.<br><br>Change-Id: Idf5a861f4dacbec3c664f4ced6e03d8662c73112<br>Closes: OS#4298<br>Related: OS#4299<br>Depends: libosmocore.git I656a1a38cbb5b1f3a9145d2869d3b4d0adefcae3<br>---<br>M configure.ac<br>M contrib/jenkins.sh<br>M src/Makefile.am<br>M src/simtrace2-remsim_client.c<br>D src/simtrace2/apdu_dispatch.c<br>D src/simtrace2/apdu_dispatch.h<br>D src/simtrace2/libusb_util.c<br>D src/simtrace2/libusb_util.h<br>D src/simtrace2/simtrace2-discovery.c<br>D src/simtrace2/simtrace2-discovery.h<br>D src/simtrace2/simtrace_prot.h<br>D src/simtrace2/simtrace_usb.h<br>12 files changed, 17 insertions(+), 1,119 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/configure.ac b/configure.ac</span><br><span>index 2fc603d..d041c1a 100644</span><br><span>--- a/configure.ac</span><br><span>+++ b/configure.ac</span><br><span>@@ -39,6 +39,8 @@</span><br><span> PKG_CHECK_MODULES(OSMOGSM, libosmogsm >= 0.11.0)</span><br><span> PKG_CHECK_MODULES(OSMOABIS, libosmoabis)</span><br><span> PKG_CHECK_MODULES(OSMOSIM, libosmosim)</span><br><span style="color: hsl(120, 100%, 40%);">+PKG_CHECK_MODULES(OSMOUSB, libosmousb)</span><br><span style="color: hsl(120, 100%, 40%);">+PKG_CHECK_MODULES(OSMOSIMTRACE2, libosmo-simtrace2)</span><br><span> PKG_CHECK_MODULES(USB, libusb-1.0)</span><br><span> </span><br><span> AC_ARG_ENABLE([remsim-server],[AS_HELP_STRING([--disable-remsim-server], [Build osmo-remsim-server])],</span><br><span>diff --git a/contrib/jenkins.sh b/contrib/jenkins.sh</span><br><span>index 249df64..c36626e 100755</span><br><span>--- a/contrib/jenkins.sh</span><br><span>+++ b/contrib/jenkins.sh</span><br><span>@@ -25,6 +25,7 @@</span><br><span> osmo-build-dep.sh libosmocore "" --disable-doxygen</span><br><span> osmo-build-dep.sh libosmo-abis</span><br><span> osmo-build-dep.sh libosmo-netif</span><br><span style="color: hsl(120, 100%, 40%);">+osmo-build-dep.sh simtrace2</span><br><span> </span><br><span> set +x</span><br><span> echo</span><br><span>diff --git a/src/Makefile.am b/src/Makefile.am</span><br><span>index 35da621..58f02e8 100644</span><br><span>--- a/src/Makefile.am</span><br><span>+++ b/src/Makefile.am</span><br><span>@@ -9,6 +9,7 @@</span><br><span> AM_CFLAGS = -Wall -I$(top_srcdir)/include -I$(top_builddir)/include \</span><br><span>            $(OSMOCORE_CFLAGS) $(OSMOGSM_CFLAGS) $(OSMOABIS_CFLAGS) \</span><br><span>            $(PCSC_CFLAGS) $(USB_CFLAGS) $(OSMOSIM_CFLAGS) \</span><br><span style="color: hsl(120, 100%, 40%);">+      $(OSMOSIMTRACE2_CFLAGS) \</span><br><span>            -I$(top_srcdir)/include/osmocom/rspro</span><br><span> </span><br><span> RSPRO_LIBVERSION=1:0:0</span><br><span>@@ -19,12 +20,7 @@</span><br><span> libosmo_rspro_la_SOURCES = rspro_util.c asn1c_helpers.c</span><br><span> </span><br><span> noinst_HEADERS = debug.h client.h rspro_util.h slotmap.h rspro_client_fsm.h \</span><br><span style="color: hsl(0, 100%, 40%);">-             asn1c_helpers.h \</span><br><span style="color: hsl(0, 100%, 40%);">-               simtrace2/apdu_dispatch.h \</span><br><span style="color: hsl(0, 100%, 40%);">-             simtrace2/libusb_util.h \</span><br><span style="color: hsl(0, 100%, 40%);">-               simtrace2/simtrace2-discovery.h \</span><br><span style="color: hsl(0, 100%, 40%);">-               simtrace2/simtrace_prot.h \</span><br><span style="color: hsl(0, 100%, 40%);">-             simtrace2/simtrace_usb.h</span><br><span style="color: hsl(120, 100%, 40%);">+              asn1c_helpers.h</span><br><span> </span><br><span> bin_PROGRAMS = osmo-remsim-client-st2</span><br><span> </span><br><span>@@ -33,9 +29,7 @@</span><br><span>                     libosmo-rspro.la</span><br><span> </span><br><span> osmo_remsim_client_st2_SOURCES = simtrace2-remsim_client.c \</span><br><span style="color: hsl(0, 100%, 40%);">-                                rspro_client_fsm.c debug.c \</span><br><span style="color: hsl(0, 100%, 40%);">-                            simtrace2/apdu_dispatch.c \</span><br><span style="color: hsl(0, 100%, 40%);">-                             simtrace2/simtrace2-discovery.c \</span><br><span style="color: hsl(0, 100%, 40%);">-                               simtrace2/libusb_util.c</span><br><span style="color: hsl(120, 100%, 40%);">+                               rspro_client_fsm.c debug.c</span><br><span> osmo_remsim_client_st2_LDADD = $(OSMOCORE_LIBS) $(OSMOGSM_LIBS) $(OSMOABIS_LIBS) \</span><br><span style="color: hsl(120, 100%, 40%);">+                            $(OSMOUSB_LIBS) $(OSMOSIMTRACE2_LIBS) \</span><br><span>                              $(USB_LIBS) $(OSMOSIM_LIBS) libosmo-rspro.la</span><br><span>diff --git a/src/simtrace2-remsim_client.c b/src/simtrace2-remsim_client.c</span><br><span>index fc5ac55..30a9c5b 100644</span><br><span>--- a/src/simtrace2-remsim_client.c</span><br><span>+++ b/src/simtrace2-remsim_client.c</span><br><span>@@ -50,11 +50,10 @@</span><br><span> </span><br><span> #include <libusb.h></span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#include "simtrace2/libusb_util.h"</span><br><span style="color: hsl(0, 100%, 40%);">-#include "simtrace2/simtrace_prot.h"</span><br><span style="color: hsl(0, 100%, 40%);">-#include "simtrace2/simtrace_usb.h"</span><br><span style="color: hsl(0, 100%, 40%);">-#include "simtrace2/apdu_dispatch.h"</span><br><span style="color: hsl(0, 100%, 40%);">-#include "simtrace2/simtrace2-discovery.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/usb/libusb.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/simtrace2/simtrace_prot.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/simtrace2/simtrace_usb.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/simtrace2/apdu_dispatch.h></span><br><span> </span><br><span> #include <osmocom/core/gsmtap.h></span><br><span> #include <osmocom/core/gsmtap_util.h></span><br><span>@@ -406,7 +405,7 @@</span><br><span>        return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static struct apdu_context ac; // this will hold the complete APDU (across calls)</span><br><span style="color: hsl(120, 100%, 40%);">+static struct osmo_apdu_context ac; // this will hold the complete APDU (across calls)</span><br><span> </span><br><span> /*! \brief Process a RX-DATA indication message from the SIMtrace2 */</span><br><span> static int process_do_rx_da(struct cardem_inst *ci, uint8_t *buf, int len)</span><br><span>@@ -417,8 +416,8 @@</span><br><span>         printf("SIMtrace => DATA: flags=%x, %s: ", data->flags,</span><br><span>              osmo_hexdump(data->data, data->data_len));</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-    rc = apdu_segment_in(&ac, data->data, data->data_len,</span><br><span style="color: hsl(0, 100%, 40%);">-                      data->flags & CEMU_DATA_F_TPDU_HDR); // parse the APDU data in the USB message</span><br><span style="color: hsl(120, 100%, 40%);">+    rc = osmo_apdu_segment_in(&ac, data->data, data->data_len,</span><br><span style="color: hsl(120, 100%, 40%);">+                            data->flags & CEMU_DATA_F_TPDU_HDR); // parse the APDU data in the USB message</span><br><span> </span><br><span>  if (rc & APDU_ACT_TX_CAPDU_TO_CARD) { // there is no pending data coming from the modem</span><br><span>          uint8_t apdu_command[sizeof(ac.hdr) + ac.lc.tot]; // to store the APDU command to send</span><br><span>@@ -864,7 +863,7 @@</span><br><span>                 ifm->addr = addr;</span><br><span>                 if (path)</span><br><span>                    osmo_strlcpy(ifm->path, path, sizeof(ifm->path));</span><br><span style="color: hsl(0, 100%, 40%);">-         transp->usb_devh = usb_open_claim_interface(NULL, ifm);</span><br><span style="color: hsl(120, 100%, 40%);">+            transp->usb_devh = osmo_libusb_open_claim_interface(NULL, NULL, ifm);</span><br><span>             if (!transp->usb_devh) {</span><br><span>                  fprintf(stderr, "can't open USB device\n");</span><br><span>                    goto close_exit;</span><br><span>@@ -876,8 +875,8 @@</span><br><span>                       goto close_exit;</span><br><span>             }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-           rc = get_usb_ep_addrs(transp->usb_devh, if_num, &transp->usb_ep.out,</span><br><span style="color: hsl(0, 100%, 40%);">-                                &transp->usb_ep.in, &transp->usb_ep.irq_in);</span><br><span style="color: hsl(120, 100%, 40%);">+              rc = osmo_libusb_get_ep_addrs(transp->usb_devh, if_num, &transp->usb_ep.out,</span><br><span style="color: hsl(120, 100%, 40%);">+                                                &transp->usb_ep.in, &transp->usb_ep.irq_in);</span><br><span>           if (rc < 0) {</span><br><span>                     fprintf(stderr, "can't obtain EP addrs; rc=%d\n", rc);</span><br><span>                         goto close_exit;</span><br><span>diff --git a/src/simtrace2/apdu_dispatch.c b/src/simtrace2/apdu_dispatch.c</span><br><span>deleted file mode 100644</span><br><span>index b9dc3b7..0000000</span><br><span>--- a/src/simtrace2/apdu_dispatch.c</span><br><span>+++ /dev/null</span><br><span>@@ -1,173 +0,0 @@</span><br><span style="color: hsl(0, 100%, 40%);">-/* apdu_dispatch - State machine to determine Rx/Tx phases of APDU</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * (C) 2016 by Harald Welte <hwelte@hmw-consulting.de></span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * This program is free software; you can redistribute it and/or</span><br><span style="color: hsl(0, 100%, 40%);">- * modify it under the terms of the GNU General Public License</span><br><span style="color: hsl(0, 100%, 40%);">- * as published by the Free Software Foundation; either version 2</span><br><span style="color: hsl(0, 100%, 40%);">- * of the License, or (at your option) any later version.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(0, 100%, 40%);">- * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(0, 100%, 40%);">- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(0, 100%, 40%);">- * GNU General Public License for more details.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * You should have received a copy of the GNU General Public License</span><br><span style="color: hsl(0, 100%, 40%);">- * along with this program; if not, write to the Free Software</span><br><span style="color: hsl(0, 100%, 40%);">- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-#include <stdint.h></span><br><span style="color: hsl(0, 100%, 40%);">-#include <stdlib.h></span><br><span style="color: hsl(0, 100%, 40%);">-#include <string.h></span><br><span style="color: hsl(0, 100%, 40%);">-#include <stdbool.h></span><br><span style="color: hsl(0, 100%, 40%);">-#include <stdio.h></span><br><span style="color: hsl(0, 100%, 40%);">-#include <errno.h></span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#include <osmocom/core/utils.h></span><br><span style="color: hsl(0, 100%, 40%);">-#include <osmocom/sim/sim.h></span><br><span style="color: hsl(0, 100%, 40%);">-#include <osmocom/sim/class_tables.h></span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#include "apdu_dispatch.h"</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/*! \brief Has the command-data phase been completed yet? */</span><br><span style="color: hsl(0, 100%, 40%);">-static inline bool is_dc_complete(struct apdu_context *ac)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">-    return (ac->lc.tot == ac->lc.cur);</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/*! \brief Has the expected-data phase been completed yet? */</span><br><span style="color: hsl(0, 100%, 40%);">-static inline bool is_de_complete(struct apdu_context *ac)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">-       return (ac->le.tot == ac->le.cur);</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static const char *dump_apdu_hdr(const struct osim_apdu_cmd_hdr *h)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">-   static char buf[256];</span><br><span style="color: hsl(0, 100%, 40%);">-   sprintf(buf, "CLA=%02x INS=%02x P1=%02x P2=%02x P3=%02x",</span><br><span style="color: hsl(0, 100%, 40%);">-             h->cla, h->ins, h->p1, h->p2, h->p3);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-    return buf;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static void dump_apdu_ctx(const struct apdu_context *ac)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">-   printf("%s; case=%d, lc=%d(%d), le=%d(%d)\n",</span><br><span style="color: hsl(0, 100%, 40%);">-         dump_apdu_hdr(&ac->hdr), ac->apdu_case,</span><br><span style="color: hsl(0, 100%, 40%);">-               ac->lc.tot, ac->lc.cur,</span><br><span style="color: hsl(0, 100%, 40%);">-           ac->le.tot, ac->le.cur);</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/*! \brief input function for APDU segmentation</span><br><span style="color: hsl(0, 100%, 40%);">- *  \param ac APDU context across successive calls</span><br><span style="color: hsl(0, 100%, 40%);">- *  \param[in] apdu_buf APDU inpud data buffer</span><br><span style="color: hsl(0, 100%, 40%);">- *  \param[in] apdu_len Length of apdu_buf</span><br><span style="color: hsl(0, 100%, 40%);">- *  \param[in] new_apdu Is this the beginning of a new APDU?</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- *  The function returns APDU_ACT_TX_CAPDU_TO_CARD once there is</span><br><span style="color: hsl(0, 100%, 40%);">- *  sufficient data of the APDU received to transmit the command-APDU to</span><br><span style="color: hsl(0, 100%, 40%);">- *  the actual card.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- *  The function retunrs APDU_ACT_RX_MORE_CAPDU_FROM_READER when there</span><br><span style="color: hsl(0, 100%, 40%);">- *  is more data to be received from the card reader (GSM Phone).</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-int apdu_segment_in(struct apdu_context *ac, const uint8_t *apdu_buf,</span><br><span style="color: hsl(0, 100%, 40%);">-                 unsigned int apdu_len, bool new_apdu)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">-      int rc = 0;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-     if (new_apdu) {</span><br><span style="color: hsl(0, 100%, 40%);">-         /* initialize the apdu context structure */</span><br><span style="color: hsl(0, 100%, 40%);">-             memset(ac, 0, sizeof(*ac));</span><br><span style="color: hsl(0, 100%, 40%);">-             /* copy APDU header over */</span><br><span style="color: hsl(0, 100%, 40%);">-             memcpy(&ac->hdr, apdu_buf, sizeof(ac->hdr));</span><br><span style="color: hsl(0, 100%, 40%);">-          ac->apdu_case = osim_determine_apdu_case(&osim_uicc_sim_cic_profile, apdu_buf);</span><br><span style="color: hsl(0, 100%, 40%);">-          switch (ac->apdu_case) {</span><br><span style="color: hsl(0, 100%, 40%);">-             case 1: /* P3 == 0, No Lc/Le */</span><br><span style="color: hsl(0, 100%, 40%);">-                 ac->le.tot = ac->lc.tot = 0;</span><br><span style="color: hsl(0, 100%, 40%);">-                      break;</span><br><span style="color: hsl(0, 100%, 40%);">-          case 2: /* P3 == Le */</span><br><span style="color: hsl(0, 100%, 40%);">-                  ac->le.tot = ac->hdr.p3;</span><br><span style="color: hsl(0, 100%, 40%);">-                  break;</span><br><span style="color: hsl(0, 100%, 40%);">-          case 3: /* P3 = Lc */</span><br><span style="color: hsl(0, 100%, 40%);">-                   ac->lc.tot = ac->hdr.p3;</span><br><span style="color: hsl(0, 100%, 40%);">-                  /* copy Dc */</span><br><span style="color: hsl(0, 100%, 40%);">-                   ac->lc.cur = apdu_len - sizeof(ac->hdr);</span><br><span style="color: hsl(0, 100%, 40%);">-                  memcpy(ac->dc, apdu_buf + sizeof(ac->hdr),</span><br><span style="color: hsl(0, 100%, 40%);">-                                ac->lc.cur);</span><br><span style="color: hsl(0, 100%, 40%);">-                 break;</span><br><span style="color: hsl(0, 100%, 40%);">-          case 4: /* P3 = Lc; SW with Le */</span><br><span style="color: hsl(0, 100%, 40%);">-                       ac->lc.tot = ac->hdr.p3;</span><br><span style="color: hsl(0, 100%, 40%);">-                  /* copy Dc */</span><br><span style="color: hsl(0, 100%, 40%);">-                   ac->lc.cur = apdu_len - sizeof(ac->hdr);</span><br><span style="color: hsl(0, 100%, 40%);">-                  memcpy(ac->dc, apdu_buf + sizeof(ac->hdr),</span><br><span style="color: hsl(0, 100%, 40%);">-                                ac->lc.cur);</span><br><span style="color: hsl(0, 100%, 40%);">-                 break;</span><br><span style="color: hsl(0, 100%, 40%);">-          case 0:</span><br><span style="color: hsl(0, 100%, 40%);">-         default:</span><br><span style="color: hsl(0, 100%, 40%);">-                        fprintf(stderr, "Unknown APDU case %d\n", ac->apdu_case);</span><br><span style="color: hsl(0, 100%, 40%);">-                  return -1;</span><br><span style="color: hsl(0, 100%, 40%);">-              }</span><br><span style="color: hsl(0, 100%, 40%);">-       } else {</span><br><span style="color: hsl(0, 100%, 40%);">-                /* copy more data, if available */</span><br><span style="color: hsl(0, 100%, 40%);">-              int cpy_len;</span><br><span style="color: hsl(0, 100%, 40%);">-            switch (ac->apdu_case) {</span><br><span style="color: hsl(0, 100%, 40%);">-             case 1:</span><br><span style="color: hsl(0, 100%, 40%);">-         case 2:</span><br><span style="color: hsl(0, 100%, 40%);">-                 break;</span><br><span style="color: hsl(0, 100%, 40%);">-          case 3:</span><br><span style="color: hsl(0, 100%, 40%);">-         case 4:</span><br><span style="color: hsl(0, 100%, 40%);">-                 cpy_len = ac->lc.tot - ac->lc.cur;</span><br><span style="color: hsl(0, 100%, 40%);">-                        if (cpy_len > apdu_len)</span><br><span style="color: hsl(0, 100%, 40%);">-                              cpy_len = apdu_len;</span><br><span style="color: hsl(0, 100%, 40%);">-                     memcpy(ac->dc+ac->lc.cur, apdu_buf, cpy_len);</span><br><span style="color: hsl(0, 100%, 40%);">-                     ac->lc.cur += cpy_len;</span><br><span style="color: hsl(0, 100%, 40%);">-                       break;</span><br><span style="color: hsl(0, 100%, 40%);">-          default:</span><br><span style="color: hsl(0, 100%, 40%);">-                        fprintf(stderr, "Unknown APDU case %d\n", ac->apdu_case);</span><br><span style="color: hsl(0, 100%, 40%);">-                  break;</span><br><span style="color: hsl(0, 100%, 40%);">-          }</span><br><span style="color: hsl(0, 100%, 40%);">-       }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-       /* take some decisions... */</span><br><span style="color: hsl(0, 100%, 40%);">-    switch (ac->apdu_case) {</span><br><span style="color: hsl(0, 100%, 40%);">-     case 1: /* P3 == 0, No Lc/Le */</span><br><span style="color: hsl(0, 100%, 40%);">-         /* send C-APDU to card */</span><br><span style="color: hsl(0, 100%, 40%);">-               /* receive SW from card, forward to reader */</span><br><span style="color: hsl(0, 100%, 40%);">-           rc |= APDU_ACT_TX_CAPDU_TO_CARD;</span><br><span style="color: hsl(0, 100%, 40%);">-                break;</span><br><span style="color: hsl(0, 100%, 40%);">-  case 2: /* P3 == Le */</span><br><span style="color: hsl(0, 100%, 40%);">-          /* send C-APDU to card */</span><br><span style="color: hsl(0, 100%, 40%);">-               /* receive Le bytes + SW from card, forward to reader */</span><br><span style="color: hsl(0, 100%, 40%);">-                rc |= APDU_ACT_TX_CAPDU_TO_CARD;</span><br><span style="color: hsl(0, 100%, 40%);">-                break;</span><br><span style="color: hsl(0, 100%, 40%);">-  case 3: /* P3 = Lc */</span><br><span style="color: hsl(0, 100%, 40%);">-           if (!is_dc_complete(ac)) {</span><br><span style="color: hsl(0, 100%, 40%);">-                      /* send PB + read further Lc bytes from reader */</span><br><span style="color: hsl(0, 100%, 40%);">-                       rc |= APDU_ACT_RX_MORE_CAPDU_FROM_READER;</span><br><span style="color: hsl(0, 100%, 40%);">-               } else {</span><br><span style="color: hsl(0, 100%, 40%);">-                        /* send C-APDU to card */</span><br><span style="color: hsl(0, 100%, 40%);">-                       /* receive SW from card, forward to reader */</span><br><span style="color: hsl(0, 100%, 40%);">-                   rc |= APDU_ACT_TX_CAPDU_TO_CARD;</span><br><span style="color: hsl(0, 100%, 40%);">-                }</span><br><span style="color: hsl(0, 100%, 40%);">-               break;</span><br><span style="color: hsl(0, 100%, 40%);">-  case 4: /* P3 = Lc; SW with Le */</span><br><span style="color: hsl(0, 100%, 40%);">-               if (!is_dc_complete(ac)) {</span><br><span style="color: hsl(0, 100%, 40%);">-                      /* send PB + read further Lc bytes from reader */</span><br><span style="color: hsl(0, 100%, 40%);">-                       rc |= APDU_ACT_RX_MORE_CAPDU_FROM_READER;</span><br><span style="color: hsl(0, 100%, 40%);">-               } else {</span><br><span style="color: hsl(0, 100%, 40%);">-                        /* send C-APDU to card */</span><br><span style="color: hsl(0, 100%, 40%);">-                       /* receive SW from card, forward to reader */</span><br><span style="color: hsl(0, 100%, 40%);">-                   rc |= APDU_ACT_TX_CAPDU_TO_CARD;</span><br><span style="color: hsl(0, 100%, 40%);">-                }</span><br><span style="color: hsl(0, 100%, 40%);">-               break;</span><br><span style="color: hsl(0, 100%, 40%);">-  case 0:</span><br><span style="color: hsl(0, 100%, 40%);">- default:</span><br><span style="color: hsl(0, 100%, 40%);">-                fprintf(stderr, "Unknown APDU case %d\n", ac->apdu_case);</span><br><span style="color: hsl(0, 100%, 40%);">-          break;</span><br><span style="color: hsl(0, 100%, 40%);">-  }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-       dump_apdu_ctx(ac);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-      return rc;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span>diff --git a/src/simtrace2/apdu_dispatch.h b/src/simtrace2/apdu_dispatch.h</span><br><span>deleted file mode 100644</span><br><span>index 2c99858..0000000</span><br><span>--- a/src/simtrace2/apdu_dispatch.h</span><br><span>+++ /dev/null</span><br><span>@@ -1,49 +0,0 @@</span><br><span style="color: hsl(0, 100%, 40%);">-/* apdu_dispatch - State machine to determine Rx/Tx phases of APDU</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * (C) 2016 by Harald Welte <hwelte@hmw-consulting.de></span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * This program is free software; you can redistribute it and/or</span><br><span style="color: hsl(0, 100%, 40%);">- * modify it under the terms of the GNU General Public License</span><br><span style="color: hsl(0, 100%, 40%);">- * as published by the Free Software Foundation; either version 2</span><br><span style="color: hsl(0, 100%, 40%);">- * of the License, or (at your option) any later version.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(0, 100%, 40%);">- * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(0, 100%, 40%);">- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(0, 100%, 40%);">- * GNU General Public License for more details.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * You should have received a copy of the GNU General Public License</span><br><span style="color: hsl(0, 100%, 40%);">- * along with this program; if not, write to the Free Software</span><br><span style="color: hsl(0, 100%, 40%);">- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-#pragma once</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#include <stdint.h></span><br><span style="color: hsl(0, 100%, 40%);">-#include <stdbool.h></span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#include <osmocom/sim/sim.h></span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-struct apdu_context {</span><br><span style="color: hsl(0, 100%, 40%);">-      struct osim_apdu_cmd_hdr hdr;</span><br><span style="color: hsl(0, 100%, 40%);">-   uint8_t dc[256];</span><br><span style="color: hsl(0, 100%, 40%);">-        uint8_t de[256];</span><br><span style="color: hsl(0, 100%, 40%);">-        uint8_t sw[2];</span><br><span style="color: hsl(0, 100%, 40%);">-  uint8_t apdu_case;</span><br><span style="color: hsl(0, 100%, 40%);">-      struct {</span><br><span style="color: hsl(0, 100%, 40%);">-                uint8_t tot;</span><br><span style="color: hsl(0, 100%, 40%);">-            uint8_t cur;</span><br><span style="color: hsl(0, 100%, 40%);">-    } lc;</span><br><span style="color: hsl(0, 100%, 40%);">-   struct {</span><br><span style="color: hsl(0, 100%, 40%);">-                uint8_t tot;</span><br><span style="color: hsl(0, 100%, 40%);">-            uint8_t cur;</span><br><span style="color: hsl(0, 100%, 40%);">-    } le;</span><br><span style="color: hsl(0, 100%, 40%);">-};</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-enum apdu_action {</span><br><span style="color: hsl(0, 100%, 40%);">-       APDU_ACT_TX_CAPDU_TO_CARD               = 0x0001,</span><br><span style="color: hsl(0, 100%, 40%);">-       APDU_ACT_RX_MORE_CAPDU_FROM_READER      = 0x0002,</span><br><span style="color: hsl(0, 100%, 40%);">-};</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-int apdu_segment_in(struct apdu_context *ac, const uint8_t *apdu_buf,</span><br><span style="color: hsl(0, 100%, 40%);">-                    unsigned int apdu_len, bool new_apdu);</span><br><span>diff --git a/src/simtrace2/libusb_util.c b/src/simtrace2/libusb_util.c</span><br><span>deleted file mode 100644</span><br><span>index 45e3f50..0000000</span><br><span>--- a/src/simtrace2/libusb_util.c</span><br><span>+++ /dev/null</span><br><span>@@ -1,297 +0,0 @@</span><br><span style="color: hsl(0, 100%, 40%);">-/* libisb utilities</span><br><span style="color: hsl(0, 100%, 40%);">- * </span><br><span style="color: hsl(0, 100%, 40%);">- * (C) 2010-2016 by Harald Welte <hwelte@hmw-consulting.de></span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * This program is free software; you can redistribute it and/or</span><br><span style="color: hsl(0, 100%, 40%);">- * modify it under the terms of the GNU General Public License</span><br><span style="color: hsl(0, 100%, 40%);">- * as published by the Free Software Foundation; either version 2</span><br><span style="color: hsl(0, 100%, 40%);">- * of the License, or (at your option) any later version.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(0, 100%, 40%);">- * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(0, 100%, 40%);">- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(0, 100%, 40%);">- * GNU General Public License for more details.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * You should have received a copy of the GNU General Public License</span><br><span style="color: hsl(0, 100%, 40%);">- * along with this program; if not, write to the Free Software</span><br><span style="color: hsl(0, 100%, 40%);">- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-#include <errno.h></span><br><span style="color: hsl(0, 100%, 40%);">-#include <unistd.h></span><br><span style="color: hsl(0, 100%, 40%);">-#include <stdio.h></span><br><span style="color: hsl(0, 100%, 40%);">-#include <stdlib.h></span><br><span style="color: hsl(0, 100%, 40%);">-#include <stdint.h></span><br><span style="color: hsl(0, 100%, 40%);">-#include <string.h></span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#include <libusb.h></span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#include "libusb_util.h"</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static char path_buf[USB_MAX_PATH_LEN];</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static char *get_path(libusb_device *dev)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">-#if (defined(LIBUSB_API_VERSION) && LIBUSB_API_VERSION >= 0x01000102) || (defined(LIBUSBX_API_VERSION) && LIBUSBX_API_VERSION >= 0x01000102)</span><br><span style="color: hsl(0, 100%, 40%);">- uint8_t path[8];</span><br><span style="color: hsl(0, 100%, 40%);">-        int r,j;</span><br><span style="color: hsl(0, 100%, 40%);">-        r = libusb_get_port_numbers(dev, path, sizeof(path));</span><br><span style="color: hsl(0, 100%, 40%);">-   if (r > 0) {</span><br><span style="color: hsl(0, 100%, 40%);">-         sprintf(path_buf,"%d-%d",libusb_get_bus_number(dev),path[0]);</span><br><span style="color: hsl(0, 100%, 40%);">-         for (j = 1; j < r; j++){</span><br><span style="color: hsl(0, 100%, 40%);">-                     sprintf(path_buf+strlen(path_buf),".%d",path[j]);</span><br><span style="color: hsl(0, 100%, 40%);">-             };</span><br><span style="color: hsl(0, 100%, 40%);">-      }</span><br><span style="color: hsl(0, 100%, 40%);">-       return path_buf;</span><br><span style="color: hsl(0, 100%, 40%);">-#else</span><br><span style="color: hsl(0, 100%, 40%);">-# warning "libusb too old - building without USB path support!"</span><br><span style="color: hsl(0, 100%, 40%);">-  return NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static int match_dev_id(const struct libusb_device_descriptor *desc, const struct dev_id *id)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">-       if ((desc->idVendor == id->vendor_id) && (desc->idProduct == id->product_id))</span><br><span style="color: hsl(0, 100%, 40%);">-               return 1;</span><br><span style="color: hsl(0, 100%, 40%);">-       return 0;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static int match_dev_ids(const struct libusb_device_descriptor *desc, const struct dev_id *ids)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">-      const struct dev_id *id;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-        for (id = ids; id->vendor_id || id->product_id; id++) {</span><br><span style="color: hsl(0, 100%, 40%);">-           if (match_dev_id(desc, id))</span><br><span style="color: hsl(0, 100%, 40%);">-                     return 1;</span><br><span style="color: hsl(0, 100%, 40%);">-       }</span><br><span style="color: hsl(0, 100%, 40%);">-       return 0;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-libusb_device **find_matching_usb_devs(const struct dev_id *dev_ids)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">- libusb_device **list;</span><br><span style="color: hsl(0, 100%, 40%);">-   libusb_device **out = calloc(256, sizeof(libusb_device *));</span><br><span style="color: hsl(0, 100%, 40%);">-     libusb_device **cur = out;</span><br><span style="color: hsl(0, 100%, 40%);">-      unsigned int i;</span><br><span style="color: hsl(0, 100%, 40%);">- int rc;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (!out)</span><br><span style="color: hsl(0, 100%, 40%);">-               return NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-    rc = libusb_get_device_list(NULL, &list);</span><br><span style="color: hsl(0, 100%, 40%);">-   if (rc <= 0) {</span><br><span style="color: hsl(0, 100%, 40%);">-               perror("No USB devices found");</span><br><span style="color: hsl(0, 100%, 40%);">-               free(out);</span><br><span style="color: hsl(0, 100%, 40%);">-              return NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-    }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-       for (i = 0; list[i] != NULL; i++) {</span><br><span style="color: hsl(0, 100%, 40%);">-             struct libusb_device_descriptor dev_desc;</span><br><span style="color: hsl(0, 100%, 40%);">-               libusb_device *dev = list[i];</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-           rc = libusb_get_device_descriptor(dev, &dev_desc);</span><br><span style="color: hsl(0, 100%, 40%);">-          if (rc < 0) {</span><br><span style="color: hsl(0, 100%, 40%);">-                        perror("Couldn't get device descriptor\n");</span><br><span style="color: hsl(0, 100%, 40%);">-                       libusb_unref_device(dev);</span><br><span style="color: hsl(0, 100%, 40%);">-                       continue;</span><br><span style="color: hsl(0, 100%, 40%);">-               }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-               if (match_dev_ids(&dev_desc, dev_ids)) {</span><br><span style="color: hsl(0, 100%, 40%);">-                    *cur = dev;</span><br><span style="color: hsl(0, 100%, 40%);">-                     cur++;</span><br><span style="color: hsl(0, 100%, 40%);">-                  /* FIXME: overflow check */</span><br><span style="color: hsl(0, 100%, 40%);">-             } else</span><br><span style="color: hsl(0, 100%, 40%);">-                  libusb_unref_device(dev);</span><br><span style="color: hsl(0, 100%, 40%);">-       }</span><br><span style="color: hsl(0, 100%, 40%);">-       if (cur == out) {</span><br><span style="color: hsl(0, 100%, 40%);">-               libusb_free_device_list(list, 1);</span><br><span style="color: hsl(0, 100%, 40%);">-               free(out);</span><br><span style="color: hsl(0, 100%, 40%);">-              return NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-    }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-       libusb_free_device_list(list, 0);</span><br><span style="color: hsl(0, 100%, 40%);">-       return out;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-int dev_find_matching_interfaces(libusb_device *dev, int class, int sub_class, int protocol,</span><br><span style="color: hsl(0, 100%, 40%);">-                                 struct usb_interface_match *out, unsigned int out_len)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">-        struct libusb_device_descriptor dev_desc;</span><br><span style="color: hsl(0, 100%, 40%);">-       int rc, i, out_idx = 0;</span><br><span style="color: hsl(0, 100%, 40%);">- uint8_t addr;</span><br><span style="color: hsl(0, 100%, 40%);">-   char *path;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-     rc = libusb_get_device_descriptor(dev, &dev_desc);</span><br><span style="color: hsl(0, 100%, 40%);">-  if (rc < 0) {</span><br><span style="color: hsl(0, 100%, 40%);">-                perror("Couldn't get device descriptor\n");</span><br><span style="color: hsl(0, 100%, 40%);">-               return -EIO;</span><br><span style="color: hsl(0, 100%, 40%);">-    }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-       addr = libusb_get_device_address(dev);</span><br><span style="color: hsl(0, 100%, 40%);">-  path = get_path(dev);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-   /* iterate over all configurations */</span><br><span style="color: hsl(0, 100%, 40%);">-   for (i = 0; i < dev_desc.bNumConfigurations; i++) {</span><br><span style="color: hsl(0, 100%, 40%);">-          struct libusb_config_descriptor *conf_desc;</span><br><span style="color: hsl(0, 100%, 40%);">-             int j;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-          rc = libusb_get_config_descriptor(dev, i, &conf_desc);</span><br><span style="color: hsl(0, 100%, 40%);">-              if (rc < 0) {</span><br><span style="color: hsl(0, 100%, 40%);">-                        fprintf(stderr, "Couldn't get config descriptor %u\n", i);</span><br><span style="color: hsl(0, 100%, 40%);">-                        continue;</span><br><span style="color: hsl(0, 100%, 40%);">-               }</span><br><span style="color: hsl(0, 100%, 40%);">-               /* iterate over all interfaces */</span><br><span style="color: hsl(0, 100%, 40%);">-               for (j = 0; j < conf_desc->bNumInterfaces; j++) {</span><br><span style="color: hsl(0, 100%, 40%);">-                 const struct libusb_interface *intf = &conf_desc->interface[j];</span><br><span style="color: hsl(0, 100%, 40%);">-                  int k;</span><br><span style="color: hsl(0, 100%, 40%);">-                  /* iterate over all alternate settings */</span><br><span style="color: hsl(0, 100%, 40%);">-                       for (k = 0; k < intf->num_altsetting; k++) {</span><br><span style="color: hsl(0, 100%, 40%);">-                              const struct libusb_interface_descriptor *if_desc;</span><br><span style="color: hsl(0, 100%, 40%);">-                              if_desc = &intf->altsetting[k];</span><br><span style="color: hsl(0, 100%, 40%);">-                          if (class >= 0 && if_desc->bInterfaceClass != class)</span><br><span style="color: hsl(0, 100%, 40%);">-                                      continue;</span><br><span style="color: hsl(0, 100%, 40%);">-                               if (sub_class >= 0 && if_desc->bInterfaceSubClass != sub_class)</span><br><span style="color: hsl(0, 100%, 40%);">-                                   continue;</span><br><span style="color: hsl(0, 100%, 40%);">-                               if (protocol >= 0 && if_desc->bInterfaceProtocol != protocol)</span><br><span style="color: hsl(0, 100%, 40%);">-                                     continue;</span><br><span style="color: hsl(0, 100%, 40%);">-                               /* MATCH! */</span><br><span style="color: hsl(0, 100%, 40%);">-                            out[out_idx].usb_dev = dev;</span><br><span style="color: hsl(0, 100%, 40%);">-                             out[out_idx].vendor = dev_desc.idVendor;</span><br><span style="color: hsl(0, 100%, 40%);">-                                out[out_idx].product = dev_desc.idProduct;</span><br><span style="color: hsl(0, 100%, 40%);">-                              out[out_idx].addr = addr;</span><br><span style="color: hsl(0, 100%, 40%);">-                               strncpy(out[out_idx].path, path, sizeof(out[out_idx].path)-1);</span><br><span style="color: hsl(0, 100%, 40%);">-                          out[out_idx].path[sizeof(out[out_idx].path)-1] = '\0';</span><br><span style="color: hsl(0, 100%, 40%);">-                          out[out_idx].configuration = conf_desc->bConfigurationValue;</span><br><span style="color: hsl(0, 100%, 40%);">-                         out[out_idx].interface = if_desc->bInterfaceNumber;</span><br><span style="color: hsl(0, 100%, 40%);">-                          out[out_idx].altsetting = if_desc->bAlternateSetting;</span><br><span style="color: hsl(0, 100%, 40%);">-                                out[out_idx].class = if_desc->bInterfaceClass;</span><br><span style="color: hsl(0, 100%, 40%);">-                               out[out_idx].sub_class = if_desc->bInterfaceSubClass;</span><br><span style="color: hsl(0, 100%, 40%);">-                                out[out_idx].protocol = if_desc->bInterfaceProtocol;</span><br><span style="color: hsl(0, 100%, 40%);">-                         out[out_idx].string_idx = if_desc->iInterface;</span><br><span style="color: hsl(0, 100%, 40%);">-                               out_idx++;</span><br><span style="color: hsl(0, 100%, 40%);">-                              if (out_idx >= out_len)</span><br><span style="color: hsl(0, 100%, 40%);">-                                      return out_idx;</span><br><span style="color: hsl(0, 100%, 40%);">-                 }</span><br><span style="color: hsl(0, 100%, 40%);">-               }</span><br><span style="color: hsl(0, 100%, 40%);">-       }</span><br><span style="color: hsl(0, 100%, 40%);">-       return out_idx;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-int usb_match_interfaces(libusb_context *ctx, const struct dev_id *dev_ids,</span><br><span style="color: hsl(0, 100%, 40%);">-                      int class, int sub_class, int protocol,</span><br><span style="color: hsl(0, 100%, 40%);">-                         struct usb_interface_match *out, unsigned int out_len)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">-        struct usb_interface_match *out_cur = out;</span><br><span style="color: hsl(0, 100%, 40%);">-      unsigned int out_len_remain = out_len;</span><br><span style="color: hsl(0, 100%, 40%);">-  libusb_device **list;</span><br><span style="color: hsl(0, 100%, 40%);">-   libusb_device **dev;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-    list = find_matching_usb_devs(dev_ids);</span><br><span style="color: hsl(0, 100%, 40%);">- if (!list)</span><br><span style="color: hsl(0, 100%, 40%);">-              return 0;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-       for (dev = list; *dev; dev++) {</span><br><span style="color: hsl(0, 100%, 40%);">-         int rc;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#if 0</span><br><span style="color: hsl(0, 100%, 40%);">-            struct libusb_device_descriptor dev_desc;</span><br><span style="color: hsl(0, 100%, 40%);">-               uint8_t ports[8];</span><br><span style="color: hsl(0, 100%, 40%);">-               uint8_t addr;</span><br><span style="color: hsl(0, 100%, 40%);">-           rc = libusb_get_device_descriptor(*dev, &dev_desc);</span><br><span style="color: hsl(0, 100%, 40%);">-         if (rc < 0) {</span><br><span style="color: hsl(0, 100%, 40%);">-                        perror("Cannot get device descriptor");</span><br><span style="color: hsl(0, 100%, 40%);">-                       continue;</span><br><span style="color: hsl(0, 100%, 40%);">-               }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-               addr = libusb_get_device_address(*dev);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-         rc = libusb_get_port_numbers(*dev, ports, sizeof(ports));</span><br><span style="color: hsl(0, 100%, 40%);">-               if (rc < 0) {</span><br><span style="color: hsl(0, 100%, 40%);">-                        perror("Cannot get device path");</span><br><span style="color: hsl(0, 100%, 40%);">-                     continue;</span><br><span style="color: hsl(0, 100%, 40%);">-               }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-               printf("Found USB Device %04x:%04x at address %d\n",</span><br><span style="color: hsl(0, 100%, 40%);">-                  dev_desc.idVendor, dev_desc.idProduct, addr);</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-             rc = dev_find_matching_interfaces(*dev, class, sub_class, protocol, out_cur, out_len_remain);</span><br><span style="color: hsl(0, 100%, 40%);">-           if (rc < 0)</span><br><span style="color: hsl(0, 100%, 40%);">-                  continue;</span><br><span style="color: hsl(0, 100%, 40%);">-               out_cur += rc;</span><br><span style="color: hsl(0, 100%, 40%);">-          out_len_remain -= rc;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-   }</span><br><span style="color: hsl(0, 100%, 40%);">-       return out_len - out_len_remain;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-libusb_device_handle *usb_open_claim_interface(libusb_context *ctx,</span><br><span style="color: hsl(0, 100%, 40%);">-                                           const struct usb_interface_match *ifm)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">-  int rc, config;</span><br><span style="color: hsl(0, 100%, 40%);">- struct dev_id dev_ids[] = { { ifm->vendor, ifm->product }, { 0, 0 } };</span><br><span style="color: hsl(0, 100%, 40%);">-    libusb_device **list;</span><br><span style="color: hsl(0, 100%, 40%);">-   libusb_device **dev;</span><br><span style="color: hsl(0, 100%, 40%);">-    libusb_device_handle *usb_devh = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-  list = find_matching_usb_devs(dev_ids);</span><br><span style="color: hsl(0, 100%, 40%);">- if (!list) {</span><br><span style="color: hsl(0, 100%, 40%);">-            perror("No USB device with matching VID/PID");</span><br><span style="color: hsl(0, 100%, 40%);">-                return NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-    }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-       for (dev = list; *dev; dev++) {</span><br><span style="color: hsl(0, 100%, 40%);">-         int addr;</span><br><span style="color: hsl(0, 100%, 40%);">-               char *path;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-             addr = libusb_get_device_address(*dev);</span><br><span style="color: hsl(0, 100%, 40%);">-         path = get_path(*dev);</span><br><span style="color: hsl(0, 100%, 40%);">-          if ((ifm->addr && addr == ifm->addr) ||</span><br><span style="color: hsl(0, 100%, 40%);">-               (strlen(ifm->path) && !strcmp(path, ifm->path))) {</span><br><span style="color: hsl(0, 100%, 40%);">-                    rc = libusb_open(*dev, &usb_devh);</span><br><span style="color: hsl(0, 100%, 40%);">-                  if (rc < 0) {</span><br><span style="color: hsl(0, 100%, 40%);">-                                fprintf(stderr, "Cannot open device: %s\n", libusb_error_name(rc));</span><br><span style="color: hsl(0, 100%, 40%);">-                           usb_devh = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-                                break;</span><br><span style="color: hsl(0, 100%, 40%);">-                  }</span><br><span style="color: hsl(0, 100%, 40%);">-                       rc = libusb_get_configuration(usb_devh, &config);</span><br><span style="color: hsl(0, 100%, 40%);">-                   if (rc < 0) {</span><br><span style="color: hsl(0, 100%, 40%);">-                                fprintf(stderr, "Cannot get current configuration: %s\n", libusb_error_name(rc));</span><br><span style="color: hsl(0, 100%, 40%);">-                             libusb_close(usb_devh);</span><br><span style="color: hsl(0, 100%, 40%);">-                         usb_devh = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-                                break;</span><br><span style="color: hsl(0, 100%, 40%);">-                  }</span><br><span style="color: hsl(0, 100%, 40%);">-                       if (config != ifm->configuration) {</span><br><span style="color: hsl(0, 100%, 40%);">-                          rc = libusb_set_configuration(usb_devh, ifm->configuration);</span><br><span style="color: hsl(0, 100%, 40%);">-                         if (rc < 0) {</span><br><span style="color: hsl(0, 100%, 40%);">-                                        fprintf(stderr, "Cannot set configuration: %s\n", libusb_error_name(rc));</span><br><span style="color: hsl(0, 100%, 40%);">-                                     libusb_close(usb_devh);</span><br><span style="color: hsl(0, 100%, 40%);">-                                 usb_devh = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-                                        break;</span><br><span style="color: hsl(0, 100%, 40%);">-                          }</span><br><span style="color: hsl(0, 100%, 40%);">-                       }</span><br><span style="color: hsl(0, 100%, 40%);">-                       rc = libusb_claim_interface(usb_devh, ifm->interface);</span><br><span style="color: hsl(0, 100%, 40%);">-                       if (rc < 0) {</span><br><span style="color: hsl(0, 100%, 40%);">-                                fprintf(stderr, "Cannot claim interface: %s\n", libusb_error_name(rc));</span><br><span style="color: hsl(0, 100%, 40%);">-                               libusb_close(usb_devh);</span><br><span style="color: hsl(0, 100%, 40%);">-                         usb_devh = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-                                break;</span><br><span style="color: hsl(0, 100%, 40%);">-                  }</span><br><span style="color: hsl(0, 100%, 40%);">-                       rc = libusb_set_interface_alt_setting(usb_devh, ifm->interface, ifm->altsetting);</span><br><span style="color: hsl(0, 100%, 40%);">-                 if (rc < 0) {</span><br><span style="color: hsl(0, 100%, 40%);">-                                fprintf(stderr, "Cannot set interface altsetting: %s\n", libusb_error_name(rc));</span><br><span style="color: hsl(0, 100%, 40%);">-                              libusb_release_interface(usb_devh, ifm->interface);</span><br><span style="color: hsl(0, 100%, 40%);">-                          libusb_close(usb_devh);</span><br><span style="color: hsl(0, 100%, 40%);">-                         usb_devh = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-                                break;</span><br><span style="color: hsl(0, 100%, 40%);">-                  }</span><br><span style="color: hsl(0, 100%, 40%);">-               }</span><br><span style="color: hsl(0, 100%, 40%);">-       }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-       /* unref / free list */</span><br><span style="color: hsl(0, 100%, 40%);">- for (dev = list; *dev; dev++)</span><br><span style="color: hsl(0, 100%, 40%);">-           libusb_unref_device(*dev);</span><br><span style="color: hsl(0, 100%, 40%);">-      free(list);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-     return usb_devh;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span>diff --git a/src/simtrace2/libusb_util.h b/src/simtrace2/libusb_util.h</span><br><span>deleted file mode 100644</span><br><span>index 2b2d92e..0000000</span><br><span>--- a/src/simtrace2/libusb_util.h</span><br><span>+++ /dev/null</span><br><span>@@ -1,70 +0,0 @@</span><br><span style="color: hsl(0, 100%, 40%);">-/* libisb utilities</span><br><span style="color: hsl(0, 100%, 40%);">- * </span><br><span style="color: hsl(0, 100%, 40%);">- * (C) 2010-2016 by Harald Welte <hwelte@hmw-consulting.de></span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * This program is free software; you can redistribute it and/or</span><br><span style="color: hsl(0, 100%, 40%);">- * modify it under the terms of the GNU General Public License</span><br><span style="color: hsl(0, 100%, 40%);">- * as published by the Free Software Foundation; either version 2</span><br><span style="color: hsl(0, 100%, 40%);">- * of the License, or (at your option) any later version.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(0, 100%, 40%);">- * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(0, 100%, 40%);">- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(0, 100%, 40%);">- * GNU General Public License for more details.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * You should have received a copy of the GNU General Public License</span><br><span style="color: hsl(0, 100%, 40%);">- * along with this program; if not, write to the Free Software</span><br><span style="color: hsl(0, 100%, 40%);">- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-#pragma once</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#include <libusb.h></span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#define USB_MAX_PATH_LEN 20</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-struct dev_id {</span><br><span style="color: hsl(0, 100%, 40%);">-      uint16_t vendor_id;</span><br><span style="color: hsl(0, 100%, 40%);">-     uint16_t product_id;</span><br><span style="color: hsl(0, 100%, 40%);">-};</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* Find any USB devices in the system matching the given Vendor and</span><br><span style="color: hsl(0, 100%, 40%);">- * Product ID */</span><br><span style="color: hsl(0, 100%, 40%);">-libusb_device **find_matching_usb_devs(const struct dev_id *dev_ids);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* structure describing a single matching interface found */</span><br><span style="color: hsl(0, 100%, 40%);">-struct usb_interface_match {</span><br><span style="color: hsl(0, 100%, 40%);">-  /* libusb device E*/</span><br><span style="color: hsl(0, 100%, 40%);">-    libusb_device *usb_dev;</span><br><span style="color: hsl(0, 100%, 40%);">- /* Vendor ID of the device running matching interface */</span><br><span style="color: hsl(0, 100%, 40%);">-        uint16_t vendor;</span><br><span style="color: hsl(0, 100%, 40%);">-        /* Product ID of the device running matching interface */</span><br><span style="color: hsl(0, 100%, 40%);">-       uint16_t product;</span><br><span style="color: hsl(0, 100%, 40%);">-       /* USB Bus Address */</span><br><span style="color: hsl(0, 100%, 40%);">-   uint8_t addr;</span><br><span style="color: hsl(0, 100%, 40%);">-   /* physical path */</span><br><span style="color: hsl(0, 100%, 40%);">-     char path[USB_MAX_PATH_LEN];</span><br><span style="color: hsl(0, 100%, 40%);">-    /* configuration of matching interface */</span><br><span style="color: hsl(0, 100%, 40%);">-       uint8_t configuration;</span><br><span style="color: hsl(0, 100%, 40%);">-  /* interface number of matching interface */</span><br><span style="color: hsl(0, 100%, 40%);">-    uint8_t interface;</span><br><span style="color: hsl(0, 100%, 40%);">-      /* altsetting of matching interface */</span><br><span style="color: hsl(0, 100%, 40%);">-  uint8_t altsetting;</span><br><span style="color: hsl(0, 100%, 40%);">-     /* bInterfaceClass of matching interface */</span><br><span style="color: hsl(0, 100%, 40%);">-     uint8_t class;</span><br><span style="color: hsl(0, 100%, 40%);">-  /* bInterfaceSubClass of matching interface */</span><br><span style="color: hsl(0, 100%, 40%);">-  uint8_t sub_class;</span><br><span style="color: hsl(0, 100%, 40%);">-      /* bInterfaceProtocol of matching interface */</span><br><span style="color: hsl(0, 100%, 40%);">-  uint8_t protocol;</span><br><span style="color: hsl(0, 100%, 40%);">-       /* index of string descriptor of matching interface */</span><br><span style="color: hsl(0, 100%, 40%);">-  uint8_t string_idx;</span><br><span style="color: hsl(0, 100%, 40%);">-};</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-int dev_find_matching_interfaces(libusb_device *dev, int class, int sub_class, int protocol,</span><br><span style="color: hsl(0, 100%, 40%);">-                                struct usb_interface_match *out, unsigned int out_len);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-int usb_match_interfaces(libusb_context *ctx, const struct dev_id *dev_ids,</span><br><span style="color: hsl(0, 100%, 40%);">-                      int class, int sub_class, int protocol,</span><br><span style="color: hsl(0, 100%, 40%);">-                         struct usb_interface_match *out, unsigned int out_len);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-libusb_device_handle *usb_open_claim_interface(libusb_context *ctx,</span><br><span style="color: hsl(0, 100%, 40%);">-                                            const struct usb_interface_match *ifm);</span><br><span>diff --git a/src/simtrace2/simtrace2-discovery.c b/src/simtrace2/simtrace2-discovery.c</span><br><span>deleted file mode 100644</span><br><span>index a7306ce..0000000</span><br><span>--- a/src/simtrace2/simtrace2-discovery.c</span><br><span>+++ /dev/null</span><br><span>@@ -1,94 +0,0 @@</span><br><span style="color: hsl(0, 100%, 40%);">-/* simtrace2-discovery - host PC library to scan for matching USB</span><br><span style="color: hsl(0, 100%, 40%);">- * devices</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * (C) 2016 by Harald Welte <hwelte@hmw-consulting.de></span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * This program is free software; you can redistribute it and/or</span><br><span style="color: hsl(0, 100%, 40%);">- * modify it under the terms of the GNU General Public License</span><br><span style="color: hsl(0, 100%, 40%);">- * as published by the Free Software Foundation; either version 2</span><br><span style="color: hsl(0, 100%, 40%);">- * of the License, or (at your option) any later version.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(0, 100%, 40%);">- * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(0, 100%, 40%);">- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(0, 100%, 40%);">- * GNU General Public License for more details.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * You should have received a copy of the GNU General Public License</span><br><span style="color: hsl(0, 100%, 40%);">- * along with this program; if not, write to the Free Software</span><br><span style="color: hsl(0, 100%, 40%);">- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-#include <stdint.h></span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#include <libusb.h></span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/*! \brief obtain the endpoint addresses for a given USB interface */</span><br><span style="color: hsl(0, 100%, 40%);">-int get_usb_ep_addrs(libusb_device_handle *devh, unsigned int if_num,</span><br><span style="color: hsl(0, 100%, 40%);">-               uint8_t *out, uint8_t *in, uint8_t *irq)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">-  libusb_device *dev = libusb_get_device(devh);</span><br><span style="color: hsl(0, 100%, 40%);">-   struct libusb_config_descriptor *cdesc;</span><br><span style="color: hsl(0, 100%, 40%);">- const struct libusb_interface_descriptor *idesc;</span><br><span style="color: hsl(0, 100%, 40%);">-        const struct libusb_interface *iface;</span><br><span style="color: hsl(0, 100%, 40%);">-   int rc, l;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-      rc = libusb_get_active_config_descriptor(dev, &cdesc);</span><br><span style="color: hsl(0, 100%, 40%);">-      if (rc < 0)</span><br><span style="color: hsl(0, 100%, 40%);">-          return rc;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-      iface = &cdesc->interface[if_num];</span><br><span style="color: hsl(0, 100%, 40%);">-       /* FIXME: we assume there's no altsetting */</span><br><span style="color: hsl(0, 100%, 40%);">-        idesc = &iface->altsetting[0];</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-   for (l = 0; l < idesc->bNumEndpoints; l++) {</span><br><span style="color: hsl(0, 100%, 40%);">-              const struct libusb_endpoint_descriptor *edesc = &idesc->endpoint[l];</span><br><span style="color: hsl(0, 100%, 40%);">-            switch (edesc->bmAttributes & 3) {</span><br><span style="color: hsl(0, 100%, 40%);">-               case LIBUSB_TRANSFER_TYPE_BULK:</span><br><span style="color: hsl(0, 100%, 40%);">-                 if (edesc->bEndpointAddress & 0x80) {</span><br><span style="color: hsl(0, 100%, 40%);">-                            if (in)</span><br><span style="color: hsl(0, 100%, 40%);">-                                 *in = edesc->bEndpointAddress;</span><br><span style="color: hsl(0, 100%, 40%);">-                       } else {</span><br><span style="color: hsl(0, 100%, 40%);">-                                if (out)</span><br><span style="color: hsl(0, 100%, 40%);">-                                        *out = edesc->bEndpointAddress;</span><br><span style="color: hsl(0, 100%, 40%);">-                      }</span><br><span style="color: hsl(0, 100%, 40%);">-                       break;</span><br><span style="color: hsl(0, 100%, 40%);">-          case LIBUSB_TRANSFER_TYPE_INTERRUPT:</span><br><span style="color: hsl(0, 100%, 40%);">-                    if (irq)</span><br><span style="color: hsl(0, 100%, 40%);">-                                *irq = edesc->bEndpointAddress;</span><br><span style="color: hsl(0, 100%, 40%);">-                      break;</span><br><span style="color: hsl(0, 100%, 40%);">-          default:</span><br><span style="color: hsl(0, 100%, 40%);">-                        break;</span><br><span style="color: hsl(0, 100%, 40%);">-          }</span><br><span style="color: hsl(0, 100%, 40%);">-       }</span><br><span style="color: hsl(0, 100%, 40%);">-       return 0;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#if 0</span><br><span style="color: hsl(0, 100%, 40%);">- struct libusb_device_descriptor ddesc;</span><br><span style="color: hsl(0, 100%, 40%);">-  int rc, i, j, k;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-        rc = libusb_get_device_descriptor(devh, &ddesc);</span><br><span style="color: hsl(0, 100%, 40%);">-    if (rc < 0)</span><br><span style="color: hsl(0, 100%, 40%);">-          return;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- for (i = 0; i < ddesc.bNumConfigurations; i++) {</span><br><span style="color: hsl(0, 100%, 40%);">-             struct libusb_config_descriptor *cdesc;</span><br><span style="color: hsl(0, 100%, 40%);">-         rc = libusb_get_config_descriptor(devh, i, &cdesc);</span><br><span style="color: hsl(0, 100%, 40%);">-         if (rc < 0)</span><br><span style="color: hsl(0, 100%, 40%);">-                  return;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-         for (j = 0; j < cdesc->bNumInterfaces; j++) {</span><br><span style="color: hsl(0, 100%, 40%);">-                     const struct libusb_interface *iface = cdesc->interface[j];</span><br><span style="color: hsl(0, 100%, 40%);">-                  for (k = 0; k < iface->num_altsetting; k++) {</span><br><span style="color: hsl(0, 100%, 40%);">-                             const struct libusb_interface_descriptor *idesc = iface->altsetting[k];</span><br><span style="color: hsl(0, 100%, 40%);">-                              /* make sure this is the interface we're looking for */</span><br><span style="color: hsl(0, 100%, 40%);">-                             if (idesc->bInterfaceClass != 0xFF ||</span><br><span style="color: hsl(0, 100%, 40%);">-                                    idesc->bInterfaceSubClass != if_class ||</span><br><span style="color: hsl(0, 100%, 40%);">-                             idsec->bInterfaceProtocol != if_proto)</span><br><span style="color: hsl(0, 100%, 40%);">-                                   continue;</span><br><span style="color: hsl(0, 100%, 40%);">-                               /* FIXME */</span><br><span style="color: hsl(0, 100%, 40%);">-                     }</span><br><span style="color: hsl(0, 100%, 40%);">-               }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-               libusb_free_config_descriptor(cdesc);</span><br><span style="color: hsl(0, 100%, 40%);">-   }</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span>diff --git a/src/simtrace2/simtrace2-discovery.h b/src/simtrace2/simtrace2-discovery.h</span><br><span>deleted file mode 100644</span><br><span>index cfba956..0000000</span><br><span>--- a/src/simtrace2/simtrace2-discovery.h</span><br><span>+++ /dev/null</span><br><span>@@ -1,26 +0,0 @@</span><br><span style="color: hsl(0, 100%, 40%);">-/* simtrace2-discovery - host PC library to scan for matching USB</span><br><span style="color: hsl(0, 100%, 40%);">- * devices</span><br><span style="color: hsl(0, 100%, 40%);">- * </span><br><span style="color: hsl(0, 100%, 40%);">- * (C) 2016 by Harald Welte <hwelte@hmw-consulting.de></span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * This program is free software; you can redistribute it and/or</span><br><span style="color: hsl(0, 100%, 40%);">- * modify it under the terms of the GNU General Public License</span><br><span style="color: hsl(0, 100%, 40%);">- * as published by the Free Software Foundation; either version 2</span><br><span style="color: hsl(0, 100%, 40%);">- * of the License, or (at your option) any later version.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(0, 100%, 40%);">- * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(0, 100%, 40%);">- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(0, 100%, 40%);">- * GNU General Public License for more details.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * You should have received a copy of the GNU General Public License</span><br><span style="color: hsl(0, 100%, 40%);">- * along with this program; if not, write to the Free Software</span><br><span style="color: hsl(0, 100%, 40%);">- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-#pragma once</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#include <stdint.h></span><br><span style="color: hsl(0, 100%, 40%);">-#include <libusb.h></span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-int get_usb_ep_addrs(libusb_device_handle *devh, unsigned int if_num,</span><br><span style="color: hsl(0, 100%, 40%);">-              uint8_t *out, uint8_t *in, uint8_t *irq);</span><br><span>diff --git a/src/simtrace2/simtrace_prot.h b/src/simtrace2/simtrace_prot.h</span><br><span>deleted file mode 100644</span><br><span>index 878bc34..0000000</span><br><span>--- a/src/simtrace2/simtrace_prot.h</span><br><span>+++ /dev/null</span><br><span>@@ -1,322 +0,0 @@</span><br><span style="color: hsl(0, 100%, 40%);">-/* SIMtrace2 USB protocol</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * (C) 2015-2017 by Harald Welte <hwelte@hmw-consulting.de></span><br><span style="color: hsl(0, 100%, 40%);">- * (C) 2018 by sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de></span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(0, 100%, 40%);">- * it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(0, 100%, 40%);">- * the Free Software Foundation; either version 2 of the License, or</span><br><span style="color: hsl(0, 100%, 40%);">- * (at your option) any later version.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(0, 100%, 40%);">- * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(0, 100%, 40%);">- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(0, 100%, 40%);">- * GNU General Public License for more details.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * You should have received a copy of the GNU General Public License</span><br><span style="color: hsl(0, 100%, 40%);">- * along with this program; if not, write to the Free Software</span><br><span style="color: hsl(0, 100%, 40%);">- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-#pragma once</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#include <stdint.h></span><br><span style="color: hsl(0, 100%, 40%);">-#include <stdbool.h></span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/***********************************************************************</span><br><span style="color: hsl(0, 100%, 40%);">- * COMMON HEADER</span><br><span style="color: hsl(0, 100%, 40%);">- ***********************************************************************/</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-enum simtrace_msg_class {</span><br><span style="color: hsl(0, 100%, 40%);">-   SIMTRACE_MSGC_GENERIC = 0,</span><br><span style="color: hsl(0, 100%, 40%);">-      /* Card Emulation / Forwarding */</span><br><span style="color: hsl(0, 100%, 40%);">-       SIMTRACE_MSGC_CARDEM,</span><br><span style="color: hsl(0, 100%, 40%);">-   /* Modem Control (if modem is attached next to device) */</span><br><span style="color: hsl(0, 100%, 40%);">-       SIMTRACE_MSGC_MODEM,</span><br><span style="color: hsl(0, 100%, 40%);">-    /* Reader/phone-car/SIM communication sniff */</span><br><span style="color: hsl(0, 100%, 40%);">-  SIMTRACE_MSGC_SNIFF,</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-    /* first vendor-specific request */</span><br><span style="color: hsl(0, 100%, 40%);">-     _SIMTRACE_MGSC_VENDOR_FIRST = 127,</span><br><span style="color: hsl(0, 100%, 40%);">-};</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-enum simtrace_msg_type_generic {</span><br><span style="color: hsl(0, 100%, 40%);">-    /* Generic Error Message */</span><br><span style="color: hsl(0, 100%, 40%);">-     SIMTRACE_CMD_DO_ERROR   = 0,</span><br><span style="color: hsl(0, 100%, 40%);">-    /* Request/Response for simtrace_board_info */</span><br><span style="color: hsl(0, 100%, 40%);">-  SIMTRACE_CMD_BD_BOARD_INFO,</span><br><span style="color: hsl(0, 100%, 40%);">-};</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* SIMTRACE_MSGC_CARDEM */</span><br><span style="color: hsl(0, 100%, 40%);">-enum simtrace_msg_type_cardem {</span><br><span style="color: hsl(0, 100%, 40%);">-  /* TPDU Data to be transmitted to phone */</span><br><span style="color: hsl(0, 100%, 40%);">-      SIMTRACE_MSGT_DT_CEMU_TX_DATA = 1,</span><br><span style="color: hsl(0, 100%, 40%);">-      /* Set the ATR to be returned at phone-SIM reset */</span><br><span style="color: hsl(0, 100%, 40%);">-     SIMTRACE_MSGT_DT_CEMU_SET_ATR,</span><br><span style="color: hsl(0, 100%, 40%);">-  /* Get Statistics Request / Response */</span><br><span style="color: hsl(0, 100%, 40%);">- SIMTRACE_MSGT_BD_CEMU_STATS,</span><br><span style="color: hsl(0, 100%, 40%);">-    /* Get Status Request / Response */</span><br><span style="color: hsl(0, 100%, 40%);">-     SIMTRACE_MSGT_BD_CEMU_STATUS,</span><br><span style="color: hsl(0, 100%, 40%);">-   /* Request / Confirm emulated card insert */</span><br><span style="color: hsl(0, 100%, 40%);">-    SIMTRACE_MSGT_DT_CEMU_CARDINSERT,</span><br><span style="color: hsl(0, 100%, 40%);">-       /* TPDU Data received from phomne */</span><br><span style="color: hsl(0, 100%, 40%);">-    SIMTRACE_MSGT_DO_CEMU_RX_DATA,</span><br><span style="color: hsl(0, 100%, 40%);">-  /* Indicate PTS request from phone */</span><br><span style="color: hsl(0, 100%, 40%);">-   SIMTRACE_MSGT_DO_CEMU_PTS,</span><br><span style="color: hsl(0, 100%, 40%);">-};</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* SIMTRACE_MSGC_MODEM */</span><br><span style="color: hsl(0, 100%, 40%);">-enum simtrace_msg_type_modem {</span><br><span style="color: hsl(0, 100%, 40%);">-     /* Modem Control: Reset an attached modem */</span><br><span style="color: hsl(0, 100%, 40%);">-    SIMTRACE_MSGT_DT_MODEM_RESET = 1,</span><br><span style="color: hsl(0, 100%, 40%);">-       /* Modem Control: Select local / remote SIM */</span><br><span style="color: hsl(0, 100%, 40%);">-  SIMTRACE_MSGT_DT_MODEM_SIM_SELECT,</span><br><span style="color: hsl(0, 100%, 40%);">-      /* Modem Control: Status (WWAN LED, SIM Presence) */</span><br><span style="color: hsl(0, 100%, 40%);">-    SIMTRACE_MSGT_BD_MODEM_STATUS,</span><br><span style="color: hsl(0, 100%, 40%);">-};</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* SIMTRACE_MSGC_SNIFF */</span><br><span style="color: hsl(0, 100%, 40%);">-enum simtrace_msg_type_sniff {</span><br><span style="color: hsl(0, 100%, 40%);">- /* Status change (card inserted, reset, ...) */</span><br><span style="color: hsl(0, 100%, 40%);">- SIMTRACE_MSGT_SNIFF_CHANGE = 0,</span><br><span style="color: hsl(0, 100%, 40%);">- /* Fi/Di baudrate change */</span><br><span style="color: hsl(0, 100%, 40%);">-     SIMTRACE_MSGT_SNIFF_FIDI,</span><br><span style="color: hsl(0, 100%, 40%);">-       /* ATR data */</span><br><span style="color: hsl(0, 100%, 40%);">-  SIMTRACE_MSGT_SNIFF_ATR,</span><br><span style="color: hsl(0, 100%, 40%);">-        /* PPS (request or response) data */</span><br><span style="color: hsl(0, 100%, 40%);">-    SIMTRACE_MSGT_SNIFF_PPS,</span><br><span style="color: hsl(0, 100%, 40%);">-        /* TPDU data */</span><br><span style="color: hsl(0, 100%, 40%);">- SIMTRACE_MSGT_SNIFF_TPDU,</span><br><span style="color: hsl(0, 100%, 40%);">-};</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* common message header */</span><br><span style="color: hsl(0, 100%, 40%);">-struct simtrace_msg_hdr {</span><br><span style="color: hsl(0, 100%, 40%);">- uint8_t msg_class;      /* simtrace_msg_class */</span><br><span style="color: hsl(0, 100%, 40%);">-        uint8_t msg_type;       /* simtrace_msg_type_xxx */</span><br><span style="color: hsl(0, 100%, 40%);">-     uint8_t seq_nr;</span><br><span style="color: hsl(0, 100%, 40%);">- uint8_t slot_nr;        /* SIM slot number */</span><br><span style="color: hsl(0, 100%, 40%);">-   uint16_t _reserved;</span><br><span style="color: hsl(0, 100%, 40%);">-     uint16_t msg_len;       /* length including header */</span><br><span style="color: hsl(0, 100%, 40%);">-   uint8_t payload[0];</span><br><span style="color: hsl(0, 100%, 40%);">-} __attribute__ ((packed));</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/***********************************************************************</span><br><span style="color: hsl(0, 100%, 40%);">- * Capabilities</span><br><span style="color: hsl(0, 100%, 40%);">- ***********************************************************************/</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* generic capabilities */</span><br><span style="color: hsl(0, 100%, 40%);">-enum simtrace_capability_generic {</span><br><span style="color: hsl(0, 100%, 40%);">-      /* compatible with 5V SIM card interface */</span><br><span style="color: hsl(0, 100%, 40%);">-     SIMTRACE_CAP_VOLT_5V,</span><br><span style="color: hsl(0, 100%, 40%);">-   /* compatible with 3.3V SIM card interface */</span><br><span style="color: hsl(0, 100%, 40%);">-   SIMTRACE_CAP_VOLT_3V3,</span><br><span style="color: hsl(0, 100%, 40%);">-  /* compatible with 1.8V SIM card interface */</span><br><span style="color: hsl(0, 100%, 40%);">-   SIMTRACE_CAP_VOLT_1V8,</span><br><span style="color: hsl(0, 100%, 40%);">-  /* Has LED1 */</span><br><span style="color: hsl(0, 100%, 40%);">-  SIMTRACE_CAP_LED_1,</span><br><span style="color: hsl(0, 100%, 40%);">-     /* Has LED2 */</span><br><span style="color: hsl(0, 100%, 40%);">-  SIMTRACE_CAP_LED_2,</span><br><span style="color: hsl(0, 100%, 40%);">-     /* Has Single-Pole Dual-Throw (local/remote SIM) */</span><br><span style="color: hsl(0, 100%, 40%);">-     SIMTRACE_CAP_SPDT,</span><br><span style="color: hsl(0, 100%, 40%);">-      /* Has Bus-Switch (trace / MITM) */</span><br><span style="color: hsl(0, 100%, 40%);">-     SIMTRACE_CAP_BUS_SWITCH,</span><br><span style="color: hsl(0, 100%, 40%);">-        /* Can read VSIM via ADC */</span><br><span style="color: hsl(0, 100%, 40%);">-     SIMTRACE_CAP_VSIM_ADC,</span><br><span style="color: hsl(0, 100%, 40%);">-  /* Can read temperature via ADC */</span><br><span style="color: hsl(0, 100%, 40%);">-      SIMTRACE_CAP_TEMP_ADC,</span><br><span style="color: hsl(0, 100%, 40%);">-  /* Supports DFU for firmware update */</span><br><span style="color: hsl(0, 100%, 40%);">-  SIMTRACE_CAP_DFU,</span><br><span style="color: hsl(0, 100%, 40%);">-       /* Supports Ctrl EP command for erasing flash / return to SAM-BA */</span><br><span style="color: hsl(0, 100%, 40%);">-     SIMTRACE_CAP_ERASE_FLASH,</span><br><span style="color: hsl(0, 100%, 40%);">-       /* Can read the status of card insert contact */</span><br><span style="color: hsl(0, 100%, 40%);">-        SIMTRACE_CAP_READ_CARD_DET,</span><br><span style="color: hsl(0, 100%, 40%);">-     /* Can control the status of a simulated card insert */</span><br><span style="color: hsl(0, 100%, 40%);">- SIMTRACE_CAP_ASSERT_CARD_DET,</span><br><span style="color: hsl(0, 100%, 40%);">-   /* Can toggle the hardware reset of an attached modem */</span><br><span style="color: hsl(0, 100%, 40%);">-        SIMTRACE_CAP_ASSERT_MODEM_RST,</span><br><span style="color: hsl(0, 100%, 40%);">-};</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* vendor-specific capabilities of sysmocom devices */</span><br><span style="color: hsl(0, 100%, 40%);">-enum simtrace_capability_vendor {</span><br><span style="color: hsl(0, 100%, 40%);">- /* Can erase a peer SAM3 controller */</span><br><span style="color: hsl(0, 100%, 40%);">-  SIMTRACE_CAP_SYSMO_QMOD_ERASE_PEER,</span><br><span style="color: hsl(0, 100%, 40%);">-     /* Can read/write an attached EEPROM */</span><br><span style="color: hsl(0, 100%, 40%);">- SIMTRACE_CAP_SYSMO_QMOD_RW_EEPROM,</span><br><span style="color: hsl(0, 100%, 40%);">-      /* can reset an attached USB hub */</span><br><span style="color: hsl(0, 100%, 40%);">-     SIMTRACE_CAP_SYSMO_QMOD_RESET_HUB,</span><br><span style="color: hsl(0, 100%, 40%);">-};</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* SIMTRACE_CMD_BD_BOARD_INFO */</span><br><span style="color: hsl(0, 100%, 40%);">-struct simtrace_board_info {</span><br><span style="color: hsl(0, 100%, 40%);">-        struct {</span><br><span style="color: hsl(0, 100%, 40%);">-                char manufacturer[32];</span><br><span style="color: hsl(0, 100%, 40%);">-          char model[32];</span><br><span style="color: hsl(0, 100%, 40%);">-         char version[32];</span><br><span style="color: hsl(0, 100%, 40%);">-       } hardware;</span><br><span style="color: hsl(0, 100%, 40%);">-     struct {</span><br><span style="color: hsl(0, 100%, 40%);">-                /* who provided this software? */</span><br><span style="color: hsl(0, 100%, 40%);">-               char provider[32];</span><br><span style="color: hsl(0, 100%, 40%);">-              /* name of software image */</span><br><span style="color: hsl(0, 100%, 40%);">-            char name[32];</span><br><span style="color: hsl(0, 100%, 40%);">-          /* (git) version at build time */</span><br><span style="color: hsl(0, 100%, 40%);">-               char version[32];</span><br><span style="color: hsl(0, 100%, 40%);">-               /* built on which machine? */</span><br><span style="color: hsl(0, 100%, 40%);">-           char buildhost[32];</span><br><span style="color: hsl(0, 100%, 40%);">-             /* CRC-32 over software image */</span><br><span style="color: hsl(0, 100%, 40%);">-                uint32_t crc;</span><br><span style="color: hsl(0, 100%, 40%);">-   } software;</span><br><span style="color: hsl(0, 100%, 40%);">-     struct {</span><br><span style="color: hsl(0, 100%, 40%);">-                /* Maximum baud rate supported */</span><br><span style="color: hsl(0, 100%, 40%);">-               uint32_t max_baud_rate;</span><br><span style="color: hsl(0, 100%, 40%);">- } speed;</span><br><span style="color: hsl(0, 100%, 40%);">-        /* number of bytes of generic capability bit-mask */</span><br><span style="color: hsl(0, 100%, 40%);">-    uint8_t cap_generic_bytes;</span><br><span style="color: hsl(0, 100%, 40%);">-      /* number of bytes of vendor capability bit-mask */</span><br><span style="color: hsl(0, 100%, 40%);">-     uint8_t cap_vendor_bytes;</span><br><span style="color: hsl(0, 100%, 40%);">-       uint8_t data[0];</span><br><span style="color: hsl(0, 100%, 40%);">-        /* cap_generic + cap_vendor */</span><br><span style="color: hsl(0, 100%, 40%);">-} __attribute__ ((packed));</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/***********************************************************************</span><br><span style="color: hsl(0, 100%, 40%);">- * CARD EMULATOR / FORWARDER</span><br><span style="color: hsl(0, 100%, 40%);">- ***********************************************************************/</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* indicates a TPDU header is present in this message */</span><br><span style="color: hsl(0, 100%, 40%);">-#define CEMU_DATA_F_TPDU_HDR      0x00000001</span><br><span style="color: hsl(0, 100%, 40%);">-/* indicates last part of transmission in this direction */</span><br><span style="color: hsl(0, 100%, 40%);">-#define CEMU_DATA_F_FINAL  0x00000002</span><br><span style="color: hsl(0, 100%, 40%);">-/* incdicates a PB is present and we should continue with TX */</span><br><span style="color: hsl(0, 100%, 40%);">-#define CEMU_DATA_F_PB_AND_TX  0x00000004</span><br><span style="color: hsl(0, 100%, 40%);">-/* incdicates a PB is present and we should continue with RX */</span><br><span style="color: hsl(0, 100%, 40%);">-#define CEMU_DATA_F_PB_AND_RX  0x00000008</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* CEMU_USB_MSGT_DT_CARDINSERT */</span><br><span style="color: hsl(0, 100%, 40%);">-struct cardemu_usb_msg_cardinsert {</span><br><span style="color: hsl(0, 100%, 40%);">-  uint8_t card_insert;</span><br><span style="color: hsl(0, 100%, 40%);">-} __attribute__ ((packed));</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* CEMU_USB_MSGT_DT_SET_ATR */</span><br><span style="color: hsl(0, 100%, 40%);">-struct cardemu_usb_msg_set_atr {</span><br><span style="color: hsl(0, 100%, 40%);">-   uint8_t atr_len;</span><br><span style="color: hsl(0, 100%, 40%);">-        /* variable-length ATR data */</span><br><span style="color: hsl(0, 100%, 40%);">-  uint8_t atr[0];</span><br><span style="color: hsl(0, 100%, 40%);">-} __attribute__ ((packed));</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* CEMU_USB_MSGT_DT_TX_DATA */</span><br><span style="color: hsl(0, 100%, 40%);">-struct cardemu_usb_msg_tx_data {</span><br><span style="color: hsl(0, 100%, 40%);">-        uint32_t flags;</span><br><span style="color: hsl(0, 100%, 40%);">- uint16_t data_len;</span><br><span style="color: hsl(0, 100%, 40%);">-      /* variable-length TPDU data */</span><br><span style="color: hsl(0, 100%, 40%);">- uint8_t data[0];</span><br><span style="color: hsl(0, 100%, 40%);">-} __attribute__ ((packed));</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* CEMU_USB_MSGT_DO_RX_DATA */</span><br><span style="color: hsl(0, 100%, 40%);">-struct cardemu_usb_msg_rx_data {</span><br><span style="color: hsl(0, 100%, 40%);">-       uint32_t flags;</span><br><span style="color: hsl(0, 100%, 40%);">- uint16_t data_len;</span><br><span style="color: hsl(0, 100%, 40%);">-      /* variable-length TPDU data */</span><br><span style="color: hsl(0, 100%, 40%);">- uint8_t data[0];</span><br><span style="color: hsl(0, 100%, 40%);">-} __attribute__ ((packed));</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-#define CEMU_STATUS_F_VCC_PRESENT    0x00000001</span><br><span style="color: hsl(0, 100%, 40%);">-#define CEMU_STATUS_F_CLK_ACTIVE      0x00000002</span><br><span style="color: hsl(0, 100%, 40%);">-#define CEMU_STATUS_F_RCEMU_ACTIVE    0x00000004</span><br><span style="color: hsl(0, 100%, 40%);">-#define CEMU_STATUS_F_CARD_INSERT     0x00000008</span><br><span style="color: hsl(0, 100%, 40%);">-#define CEMU_STATUS_F_RESET_ACTIVE    0x00000010</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* CEMU_USB_MSGT_DO_STATUS */</span><br><span style="color: hsl(0, 100%, 40%);">-struct cardemu_usb_msg_status {</span><br><span style="color: hsl(0, 100%, 40%);">-  uint32_t flags;</span><br><span style="color: hsl(0, 100%, 40%);">- /* phone-applied target voltage in mV */</span><br><span style="color: hsl(0, 100%, 40%);">-        uint16_t voltage_mv;</span><br><span style="color: hsl(0, 100%, 40%);">-    /* Fi/Di related information */</span><br><span style="color: hsl(0, 100%, 40%);">- uint8_t fi;</span><br><span style="color: hsl(0, 100%, 40%);">-     uint8_t di;</span><br><span style="color: hsl(0, 100%, 40%);">-     uint8_t wi;</span><br><span style="color: hsl(0, 100%, 40%);">-     uint32_t waiting_time;</span><br><span style="color: hsl(0, 100%, 40%);">-} __attribute__ ((packed));</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* CEMU_USB_MSGT_DO_PTS */</span><br><span style="color: hsl(0, 100%, 40%);">-struct cardemu_usb_msg_pts_info {</span><br><span style="color: hsl(0, 100%, 40%);">-    uint8_t pts_len;</span><br><span style="color: hsl(0, 100%, 40%);">-        /* PTS request as sent from reader */</span><br><span style="color: hsl(0, 100%, 40%);">-   uint8_t req[6];</span><br><span style="color: hsl(0, 100%, 40%);">- /* PTS response as sent by card */</span><br><span style="color: hsl(0, 100%, 40%);">-      uint8_t resp[6];</span><br><span style="color: hsl(0, 100%, 40%);">-} __attribute__ ((packed));</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* CEMU_USB_MSGT_DO_ERROR */</span><br><span style="color: hsl(0, 100%, 40%);">-struct cardemu_usb_msg_error {</span><br><span style="color: hsl(0, 100%, 40%);">-   uint8_t severity;</span><br><span style="color: hsl(0, 100%, 40%);">-       uint8_t subsystem;</span><br><span style="color: hsl(0, 100%, 40%);">-      uint16_t code;</span><br><span style="color: hsl(0, 100%, 40%);">-  uint8_t msg_len;</span><br><span style="color: hsl(0, 100%, 40%);">-        /* human-readable error message */</span><br><span style="color: hsl(0, 100%, 40%);">-      uint8_t msg[0];</span><br><span style="color: hsl(0, 100%, 40%);">-} __attribute__ ((packed));</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/***********************************************************************</span><br><span style="color: hsl(0, 100%, 40%);">- * MODEM CONTROL</span><br><span style="color: hsl(0, 100%, 40%);">- ***********************************************************************/</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* SIMTRACE_MSGT_DT_MODEM_RESET */</span><br><span style="color: hsl(0, 100%, 40%);">-struct st_modem_reset {</span><br><span style="color: hsl(0, 100%, 40%);">-    /* 0: de-assert reset, 1: assert reset, 2: pulse reset */</span><br><span style="color: hsl(0, 100%, 40%);">-       uint8_t asserted;</span><br><span style="color: hsl(0, 100%, 40%);">-       /* if above is '2', duration of pulse in ms */</span><br><span style="color: hsl(0, 100%, 40%);">-  uint16_t pulse_duration_msec;</span><br><span style="color: hsl(0, 100%, 40%);">-} __attribute__((packed));</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* SIMTRACE_MSGT_DT_MODEM_SIM_SELECT */</span><br><span style="color: hsl(0, 100%, 40%);">-struct st_modem_sim_select {</span><br><span style="color: hsl(0, 100%, 40%);">-      /* remote (1), local (0) */</span><br><span style="color: hsl(0, 100%, 40%);">-     uint8_t remote_sim;</span><br><span style="color: hsl(0, 100%, 40%);">-} __attribute__((packed));</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* SIMTRACE_MSGT_BD_MODEM_STATUS */</span><br><span style="color: hsl(0, 100%, 40%);">-#define ST_MDM_STS_BIT_WWAN_LED         (1 << 0)</span><br><span style="color: hsl(0, 100%, 40%);">-#define ST_MDM_STS_BIT_CARD_INSERTED      (1 << 1)</span><br><span style="color: hsl(0, 100%, 40%);">-struct st_modem_status {</span><br><span style="color: hsl(0, 100%, 40%);">-  /* bit-field of supported status bits */</span><br><span style="color: hsl(0, 100%, 40%);">-        uint8_t supported_mask;</span><br><span style="color: hsl(0, 100%, 40%);">- /* bit-field of current status bits */</span><br><span style="color: hsl(0, 100%, 40%);">-  uint8_t status_mask;</span><br><span style="color: hsl(0, 100%, 40%);">-    /* bit-field of changed status bits */</span><br><span style="color: hsl(0, 100%, 40%);">-  uint8_t changed_mask;</span><br><span style="color: hsl(0, 100%, 40%);">-} __attribute__((packed));</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/***********************************************************************</span><br><span style="color: hsl(0, 100%, 40%);">- * SNIFF</span><br><span style="color: hsl(0, 100%, 40%);">- ***********************************************************************/</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* SIMTRACE_MSGT_SNIFF_CHANGE flags */</span><br><span style="color: hsl(0, 100%, 40%);">-#define SNIFF_CHANGE_FLAG_CARD_INSERT (1<<0)</span><br><span style="color: hsl(0, 100%, 40%);">-#define SNIFF_CHANGE_FLAG_CARD_EJECT (1<<1)</span><br><span style="color: hsl(0, 100%, 40%);">-#define SNIFF_CHANGE_FLAG_RESET_ASSERT (1<<2)</span><br><span style="color: hsl(0, 100%, 40%);">-#define SNIFF_CHANGE_FLAG_RESET_DEASSERT (1<<3)</span><br><span style="color: hsl(0, 100%, 40%);">-#define SNIFF_CHANGE_FLAG_TIMEOUT_WT (1<<4)</span><br><span style="color: hsl(0, 100%, 40%);">-/* SIMTRACE_MSGT_SNIFF_ATR, SIMTRACE_MSGT_SNIFF_PPS, SIMTRACE_MSGT_SNIFF_TPDU flags */</span><br><span style="color: hsl(0, 100%, 40%);">-#define SNIFF_DATA_FLAG_ERROR_INCOMPLETE (1<<5)</span><br><span style="color: hsl(0, 100%, 40%);">-#define SNIFF_DATA_FLAG_ERROR_MALFORMED (1<<6)</span><br><span style="color: hsl(0, 100%, 40%);">-#define SNIFF_DATA_FLAG_ERROR_CHECKSUM (1<<7)</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* SIMTRACE_MSGT_SNIFF_CHANGE */</span><br><span style="color: hsl(0, 100%, 40%);">-struct sniff_change {</span><br><span style="color: hsl(0, 100%, 40%);">-       /* SIMTRACE_MSGT_SNIFF_CHANGE flags */</span><br><span style="color: hsl(0, 100%, 40%);">-  uint32_t flags;</span><br><span style="color: hsl(0, 100%, 40%);">-} __attribute__ ((packed));</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* SIMTRACE_MSGT_SNIFF_FIDI */</span><br><span style="color: hsl(0, 100%, 40%);">-struct sniff_fidi {</span><br><span style="color: hsl(0, 100%, 40%);">-     /* Fi/Di values as encoded in TA1 */</span><br><span style="color: hsl(0, 100%, 40%);">-    uint8_t fidi;</span><br><span style="color: hsl(0, 100%, 40%);">-} __attribute__ ((packed));</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* SIMTRACE_MSGT_SNIFF_ATR, SIMTRACE_MSGT_SNIFF_PPS, SIMTRACE_MSGT_SNIFF_TPDU */</span><br><span style="color: hsl(0, 100%, 40%);">-struct sniff_data {</span><br><span style="color: hsl(0, 100%, 40%);">-     /* data flags */</span><br><span style="color: hsl(0, 100%, 40%);">-        uint32_t flags;</span><br><span style="color: hsl(0, 100%, 40%);">- /* data length */</span><br><span style="color: hsl(0, 100%, 40%);">-       uint16_t length;</span><br><span style="color: hsl(0, 100%, 40%);">-        /* data */</span><br><span style="color: hsl(0, 100%, 40%);">-      uint8_t data[0];</span><br><span style="color: hsl(0, 100%, 40%);">-} __attribute__ ((packed));</span><br><span>diff --git a/src/simtrace2/simtrace_usb.h b/src/simtrace2/simtrace_usb.h</span><br><span>deleted file mode 100644</span><br><span>index c0da9c5..0000000</span><br><span>--- a/src/simtrace2/simtrace_usb.h</span><br><span>+++ /dev/null</span><br><span>@@ -1,67 +0,0 @@</span><br><span style="color: hsl(0, 100%, 40%);">-/* SIMtrace 2 USB definitions</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * (C) 2018 by sysmocom -s.f.m.c. GmbH, Author: Kevin Redon <kredon@sysmocom.de></span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(0, 100%, 40%);">- * it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(0, 100%, 40%);">- * the Free Software Foundation; either version 2 of the License, or</span><br><span style="color: hsl(0, 100%, 40%);">- * (at your option) any later version.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(0, 100%, 40%);">- * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(0, 100%, 40%);">- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(0, 100%, 40%);">- * GNU General Public License for more details.</span><br><span style="color: hsl(0, 100%, 40%);">- *</span><br><span style="color: hsl(0, 100%, 40%);">- * You should have received a copy of the GNU General Public License</span><br><span style="color: hsl(0, 100%, 40%);">- * along with this program; if not, write to the Free Software</span><br><span style="color: hsl(0, 100%, 40%);">- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-/* SIMtrace USB IDs */</span><br><span style="color: hsl(0, 100%, 40%);">-#define USB_VENDOR_OPENMOKO                       0x1d50</span><br><span style="color: hsl(0, 100%, 40%);">-#define USB_PRODUCT_OWHW_SAM3_DFU 0x4001  /* was 0x4000 */</span><br><span style="color: hsl(0, 100%, 40%);">-#define USB_PRODUCT_OWHW_SAM3           0x4001</span><br><span style="color: hsl(0, 100%, 40%);">-#define USB_PRODUCT_QMOD_HUB              0x4002</span><br><span style="color: hsl(0, 100%, 40%);">-#define USB_PRODUCT_QMOD_SAM3_DFU 0x4004  /* was 0x4003 */</span><br><span style="color: hsl(0, 100%, 40%);">-#define USB_PRODUCT_QMOD_SAM3           0x4004</span><br><span style="color: hsl(0, 100%, 40%);">-#define USB_PRODUCT_SIMTRACE2_DFU 0x60e3  /* was 0x60e2 */</span><br><span style="color: hsl(0, 100%, 40%);">-#define USB_PRODUCT_SIMTRACE2           0x60e3</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* USB proprietary class */</span><br><span style="color: hsl(0, 100%, 40%);">-#define USB_CLASS_PROPRIETARY                  0xff</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* SIMtrace USB sub-classes */</span><br><span style="color: hsl(0, 100%, 40%);">-/*! Sniffer USB sub-class */</span><br><span style="color: hsl(0, 100%, 40%);">-#define SIMTRACE_SNIFFER_USB_SUBCLASS     1</span><br><span style="color: hsl(0, 100%, 40%);">-/*! Card-emulation USB sub-class */</span><br><span style="color: hsl(0, 100%, 40%);">-#define SIMTRACE_CARDEM_USB_SUBCLASS        2</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* Generic USB endpoint numbers */</span><br><span style="color: hsl(0, 100%, 40%);">-/*! Card-side USB data out (host to device) endpoint number */</span><br><span style="color: hsl(0, 100%, 40%);">-#define SIMTRACE_USB_EP_CARD_DATAOUT   1</span><br><span style="color: hsl(0, 100%, 40%);">-/*! Card-side USB data in (device to host) endpoint number */</span><br><span style="color: hsl(0, 100%, 40%);">-#define SIMTRACE_USB_EP_CARD_DATAIN               2</span><br><span style="color: hsl(0, 100%, 40%);">-/*! Card-side USB interrupt endpoint number */</span><br><span style="color: hsl(0, 100%, 40%);">-#define SIMTRACE_USB_EP_CARD_INT         3</span><br><span style="color: hsl(0, 100%, 40%);">-/*! Phone-side USB data out (host to device) endpoint number */</span><br><span style="color: hsl(0, 100%, 40%);">-#define SIMTRACE_USB_EP_PHONE_DATAOUT   4</span><br><span style="color: hsl(0, 100%, 40%);">-/*! Phone-side USB data in (device to host) endpoint number */</span><br><span style="color: hsl(0, 100%, 40%);">-#define SIMTRACE_USB_EP_PHONE_DATAIN     5</span><br><span style="color: hsl(0, 100%, 40%);">-/*! Phone-side USB interrupt endpoint number */</span><br><span style="color: hsl(0, 100%, 40%);">-#define SIMTRACE_USB_EP_PHONE_INT               6</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* Card-emulation USB endpoint numbers */</span><br><span style="color: hsl(0, 100%, 40%);">-/*! USIM1 USB data out (host to device) endpoint number */</span><br><span style="color: hsl(0, 100%, 40%);">-#define SIMTRACE_CARDEM_USB_EP_USIM1_DATAOUT        4</span><br><span style="color: hsl(0, 100%, 40%);">-/*! USIM1 USB data in (device to host) endpoint number */</span><br><span style="color: hsl(0, 100%, 40%);">-#define SIMTRACE_CARDEM_USB_EP_USIM1_DATAIN           5</span><br><span style="color: hsl(0, 100%, 40%);">-/*! USIM1 USB interrupt endpoint number */</span><br><span style="color: hsl(0, 100%, 40%);">-#define SIMTRACE_CARDEM_USB_EP_USIM1_INT             6</span><br><span style="color: hsl(0, 100%, 40%);">-/*! USIM2 USB data out (host to device) endpoint number */</span><br><span style="color: hsl(0, 100%, 40%);">-#define SIMTRACE_CARDEM_USB_EP_USIM2_DATAOUT 1</span><br><span style="color: hsl(0, 100%, 40%);">-/*! USIM2 USB data in (device to host) endpoint number */</span><br><span style="color: hsl(0, 100%, 40%);">-#define SIMTRACE_CARDEM_USB_EP_USIM2_DATAIN           2</span><br><span style="color: hsl(0, 100%, 40%);">-/*! USIM2 USB interrupt endpoint number */</span><br><span style="color: hsl(0, 100%, 40%);">-#define SIMTRACE_CARDEM_USB_EP_USIM2_INT             3</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/*! Maximum number of endpoints */</span><br><span style="color: hsl(0, 100%, 40%);">-#define BOARD_USB_NUMENDPOINTS               6</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-remsim/+/16609">change 16609</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/osmo-remsim/+/16609"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-remsim </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Idf5a861f4dacbec3c664f4ced6e03d8662c73112 </div>
<div style="display:none"> Gerrit-Change-Number: 16609 </div>
<div style="display:none"> Gerrit-PatchSet: 4 </div>
<div style="display:none"> Gerrit-Owner: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>