<p>tsaitgaist <strong>submitted</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/simtrace2/+/16196">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Jenkins Builder: Verified
  pespin: Looks good to me, but someone else must approve
  tsaitgaist: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">merge simtrace2-discovery.[ch] to libusb_util.[ch]<br><br>Change-Id: I4defbec70986a90c1f0cfb7587393265b73c0163<br>---<br>M host/include/osmocom/simtrace2/libusb_util.h<br>M host/lib/libusb_util.c<br>M host/src/Makefile.am<br>D host/src/simtrace2-discovery.c<br>D host/src/simtrace2-discovery.h<br>M host/src/simtrace2-remsim.c<br>M host/src/simtrace2-sniff.c<br>M host/src/usb2udp.c<br>8 files changed, 48 insertions(+), 129 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/host/include/osmocom/simtrace2/libusb_util.h b/host/include/osmocom/simtrace2/libusb_util.h</span><br><span>index 2b2d92e..3280b27 100644</span><br><span>--- a/host/include/osmocom/simtrace2/libusb_util.h</span><br><span>+++ b/host/include/osmocom/simtrace2/libusb_util.h</span><br><span>@@ -68,3 +68,6 @@</span><br><span> </span><br><span> libusb_device_handle *usb_open_claim_interface(libusb_context *ctx,</span><br><span>                                          const struct usb_interface_match *ifm);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+int get_usb_ep_addrs(libusb_device_handle *devh, unsigned int if_num,</span><br><span style="color: hsl(120, 100%, 40%);">+                    uint8_t *out, uint8_t *in, uint8_t *irq);</span><br><span>diff --git a/host/lib/libusb_util.c b/host/lib/libusb_util.c</span><br><span>index d88b043..50cd087 100644</span><br><span>--- a/host/lib/libusb_util.c</span><br><span>+++ b/host/lib/libusb_util.c</span><br><span>@@ -295,3 +295,44 @@</span><br><span> </span><br><span>       return usb_devh;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*! \brief obtain the endpoint addresses for a given USB interface */</span><br><span style="color: hsl(120, 100%, 40%);">+int get_usb_ep_addrs(libusb_device_handle *devh, unsigned int if_num,</span><br><span style="color: hsl(120, 100%, 40%);">+              uint8_t *out, uint8_t *in, uint8_t *irq)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+      libusb_device *dev = libusb_get_device(devh);</span><br><span style="color: hsl(120, 100%, 40%);">+ struct libusb_config_descriptor *cdesc;</span><br><span style="color: hsl(120, 100%, 40%);">+       const struct libusb_interface_descriptor *idesc;</span><br><span style="color: hsl(120, 100%, 40%);">+      const struct libusb_interface *iface;</span><br><span style="color: hsl(120, 100%, 40%);">+ int rc, l;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  rc = libusb_get_active_config_descriptor(dev, &cdesc);</span><br><span style="color: hsl(120, 100%, 40%);">+    if (rc < 0)</span><br><span style="color: hsl(120, 100%, 40%);">+                return rc;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  iface = &cdesc->interface[if_num];</span><br><span style="color: hsl(120, 100%, 40%);">+     /* FIXME: we assume there's no altsetting */</span><br><span style="color: hsl(120, 100%, 40%);">+      idesc = &iface->altsetting[0];</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+       for (l = 0; l < idesc->bNumEndpoints; l++) {</span><br><span style="color: hsl(120, 100%, 40%);">+            const struct libusb_endpoint_descriptor *edesc = &idesc->endpoint[l];</span><br><span style="color: hsl(120, 100%, 40%);">+          switch (edesc->bmAttributes & 3) {</span><br><span style="color: hsl(120, 100%, 40%);">+             case LIBUSB_TRANSFER_TYPE_BULK:</span><br><span style="color: hsl(120, 100%, 40%);">+                       if (edesc->bEndpointAddress & 0x80) {</span><br><span style="color: hsl(120, 100%, 40%);">+                          if (in)</span><br><span style="color: hsl(120, 100%, 40%);">+                                       *in = edesc->bEndpointAddress;</span><br><span style="color: hsl(120, 100%, 40%);">+                     } else {</span><br><span style="color: hsl(120, 100%, 40%);">+                              if (out)</span><br><span style="color: hsl(120, 100%, 40%);">+                                      *out = edesc->bEndpointAddress;</span><br><span style="color: hsl(120, 100%, 40%);">+                    }</span><br><span style="color: hsl(120, 100%, 40%);">+                     break;</span><br><span style="color: hsl(120, 100%, 40%);">+                case LIBUSB_TRANSFER_TYPE_INTERRUPT:</span><br><span style="color: hsl(120, 100%, 40%);">+                  if (irq)</span><br><span style="color: hsl(120, 100%, 40%);">+                              *irq = edesc->bEndpointAddress;</span><br><span style="color: hsl(120, 100%, 40%);">+                    break;</span><br><span style="color: hsl(120, 100%, 40%);">+                default:</span><br><span style="color: hsl(120, 100%, 40%);">+                      break;</span><br><span style="color: hsl(120, 100%, 40%);">+                }</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span style="color: hsl(120, 100%, 40%);">+     return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span>diff --git a/host/src/Makefile.am b/host/src/Makefile.am</span><br><span>index b0f1f91..29f2405 100644</span><br><span>--- a/host/src/Makefile.am</span><br><span>+++ b/host/src/Makefile.am</span><br><span>@@ -5,14 +5,12 @@</span><br><span> LDADD= $(top_builddir)/lib/libosmo-simtrace2.la \</span><br><span>        $(LIBOSMOCORE_LIBS) $(LIBOSMOSIM_LIBS) $(LIBUSB_LIBS)</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-noinst_HEADERS = simtrace2-discovery.h</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> bin_PROGRAMS = simtrace2-remsim simtrace2-remsim-usb2udp simtrace2-list simtrace2-sniff</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-simtrace2_remsim_SOURCES = simtrace2-remsim.c simtrace2-discovery.c</span><br><span style="color: hsl(120, 100%, 40%);">+simtrace2_remsim_SOURCES = simtrace2-remsim.c</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-simtrace2_remsim_usb2udp_SOURCES = usb2udp.c simtrace2-discovery.c</span><br><span style="color: hsl(120, 100%, 40%);">+simtrace2_remsim_usb2udp_SOURCES = usb2udp.c</span><br><span> </span><br><span> simtrace2_list_SOURCES = simtrace2_usb.c</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-simtrace2_sniff_SOURCES = simtrace2-sniff.c simtrace2-discovery.c</span><br><span style="color: hsl(120, 100%, 40%);">+simtrace2_sniff_SOURCES = simtrace2-sniff.c</span><br><span>diff --git a/host/src/simtrace2-discovery.c b/host/src/simtrace2-discovery.c</span><br><span>deleted file mode 100644</span><br><span>index a7306ce..0000000</span><br><span>--- a/host/src/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/host/src/simtrace2-discovery.h b/host/src/simtrace2-discovery.h</span><br><span>deleted file mode 100644</span><br><span>index cfba956..0000000</span><br><span>--- a/host/src/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/host/src/simtrace2-remsim.c b/host/src/simtrace2-remsim.c</span><br><span>index 5362733..03d11df 100644</span><br><span>--- a/host/src/simtrace2-remsim.c</span><br><span>+++ b/host/src/simtrace2-remsim.c</span><br><span>@@ -44,8 +44,6 @@</span><br><span> #include <osmocom/simtrace2/apdu_dispatch.h></span><br><span> #include <osmocom/simtrace2/gsmtap.h></span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-#include "simtrace2-discovery.h"</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> #include <osmocom/core/utils.h></span><br><span> #include <osmocom/core/socket.h></span><br><span> #include <osmocom/core/msgb.h></span><br><span>diff --git a/host/src/simtrace2-sniff.c b/host/src/simtrace2-sniff.c</span><br><span>index f3c37dc..7e8e5eb 100644</span><br><span>--- a/host/src/simtrace2-sniff.c</span><br><span>+++ b/host/src/simtrace2-sniff.c</span><br><span>@@ -40,7 +40,6 @@</span><br><span> #include <osmocom/simtrace2/libusb_util.h></span><br><span> #include <osmocom/simtrace2/simtrace_usb.h></span><br><span> #include <osmocom/simtrace2/simtrace_prot.h></span><br><span style="color: hsl(0, 100%, 40%);">-#include "simtrace2-discovery.h"</span><br><span> </span><br><span> #include <osmocom/simtrace2/gsmtap.h></span><br><span> </span><br><span>diff --git a/host/src/usb2udp.c b/host/src/usb2udp.c</span><br><span>index 9927594..23800fd 100644</span><br><span>--- a/host/src/usb2udp.c</span><br><span>+++ b/host/src/usb2udp.c</span><br><span>@@ -37,7 +37,7 @@</span><br><span> </span><br><span> #include <osmocom/simtrace2/simtrace_usb.h></span><br><span> #include <osmocom/simtrace2/simtrace_prot.h></span><br><span style="color: hsl(0, 100%, 40%);">-#include "simtrace2-discovery.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/simtrace2/libusb_util.h></span><br><span> </span><br><span> #include <osmocom/core/utils.h></span><br><span> #include <osmocom/core/socket.h></span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/simtrace2/+/16196">change 16196</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/simtrace2/+/16196"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: simtrace2 </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I4defbec70986a90c1f0cfb7587393265b73c0163 </div>
<div style="display:none"> Gerrit-Change-Number: 16196 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </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: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: tsaitgaist <kredon@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>