Change in simtrace2[master]: simtrace2-remsim: Better semi-automatic interface matching

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

laforge gerrit-no-reply at lists.osmocom.org
Thu Dec 26 07:10:31 UTC 2019


laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/simtrace2/+/16681 )


Change subject: simtrace2-remsim: Better semi-automatic interface matching
......................................................................

simtrace2-remsim: Better semi-automatic interface matching

Now it's sufficient to specify only the minimum required parameters
to uniquely identify the USB device and/or interface to use

* the program knows which VendorId/ProductId is supported
* if more than one device are found, you need to specify
  the USB path like '-H 1-2.1' to disambiguate
* if more than one matching interface are found in the device,
  you need to specify if like '-I 1'

Change-Id: Icbcb5e8a00d189859310117880a763864b72b6c3
---
M host/src/simtrace2-remsim.c
1 file changed, 58 insertions(+), 14 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/simtrace2 refs/changes/81/16681/1

diff --git a/host/src/simtrace2-remsim.c b/host/src/simtrace2-remsim.c
index 7d5ecd3..7abaa79 100644
--- a/host/src/simtrace2-remsim.c
+++ b/host/src/simtrace2-remsim.c
@@ -43,7 +43,11 @@
 #include <osmocom/simtrace2/simtrace_prot.h>
 #include <osmocom/simtrace2/apdu_dispatch.h>
 #include <osmocom/simtrace2/gsmtap.h>
+#include <osmocom/simtrace2/usb_util.h>
+#include <osmocom/simtrace2/simtrace_usb.h>
 
+#include <osmocom/core/logging.h>
+#include <osmocom/core/application.h>
 #include <osmocom/core/utils.h>
 #include <osmocom/core/socket.h>
 #include <osmocom/core/msgb.h>
@@ -274,6 +278,14 @@
 	}
 }
 
+static const struct log_info_cat log_categories[] = {
+};
+
+static const struct log_info log_info = {
+	.cat = log_categories,
+	.num_cat = ARRAY_SIZE(log_categories),
+};
+
 int main(int argc, char **argv)
 {
 	struct osmo_st2_transport *transp = ci->slot->transp;
@@ -291,6 +303,7 @@
 	struct osim_card_hdl *card;
 
 	print_welcome();
+	osmo_init_logging2(NULL, &log_info);
 
 	while (1) {
 		int option_index = 0;
@@ -342,11 +355,6 @@
 		}
 	}
 
-	if (!remote_udp_host && (vendor_id < 0 || product_id < 0)) {
-		fprintf(stderr, "You have to specify the vendor and product ID\n");
-		goto do_exit;
-	}
-
 	transp->udp_fd = -1;
 
 	ci->card_prof = &osim_uicc_sim_cic_profile;
@@ -395,15 +403,51 @@
 
 	do {
 		if (transp->udp_fd < 0) {
-			struct usb_interface_match _ifm, *ifm = &_ifm;
-			ifm->vendor = vendor_id;
-			ifm->product = product_id;
-			ifm->configuration = config_id;
-			ifm->interface = if_num;
-			ifm->altsetting = altsetting;
-			ifm->addr = addr;
-			if (path)
-				osmo_strlcpy(ifm->path, path, sizeof(ifm->path));
+			struct usb_interface_match if_matches[16];
+			struct usb_interface_match *ifm = NULL;
+			struct dev_id user_dev_ids[2] = {
+				{ vendor_id, product_id },
+				{ 0, 0 }
+			};
+			const struct dev_id *dev_ids = osmo_st2_compatible_dev_ids;
+			libusb_device *dev;
+			int i;
+
+			if (vendor_id != -1 || product_id != -1)
+				dev_ids = user_dev_ids;
+			dev = osmo_libusb_find_matching_dev_path(NULL, dev_ids, path);
+			if (!dev)
+				goto close_exit;
+
+			rc = osmo_libusb_dev_find_matching_interfaces(dev, USB_CLASS_PROPRIETARY,
+								      SIMTRACE_CARDEM_USB_SUBCLASS, -1,
+								      if_matches, sizeof(if_matches));
+			if (rc < 1) {
+				fprintf(stderr, "can't find matching USB interface at device\n");
+				goto close_exit;
+			} else if (rc == 1) {
+				ifm = if_matches;
+			} else if (rc > 1) {
+				if (if_num == -1) {
+					fprintf(stderr, "found %d matching USB interfaces, you "
+						"have to specify the interface number (try "
+						"simtrace2-list)\n", rc);
+					goto close_exit;
+				}
+				for (i = 0; i < rc; i++) {
+					if (if_matches[i].interface == if_num) {
+						ifm = &if_matches[i];
+						break;
+					}
+					/* FIXME: match altsetting */
+				}
+			}
+			if (!ifm) {
+				fprintf(stderr, "Couldn't find matching interface\n");
+				goto close_exit;
+			}
+			/* FIXME: we may need to switch configuration, if found interface has different config */
+
 			transp->usb_devh = osmo_libusb_open_claim_interface(NULL, NULL, ifm);
 			if (!transp->usb_devh) {
 				fprintf(stderr, "can't open USB device\n");

-- 
To view, visit https://gerrit.osmocom.org/c/simtrace2/+/16681
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: simtrace2
Gerrit-Branch: master
Gerrit-Change-Id: Icbcb5e8a00d189859310117880a763864b72b6c3
Gerrit-Change-Number: 16681
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20191226/9783c0b7/attachment.htm>


More information about the gerrit-log mailing list