+int jtag_get_speed_readable(int *khz)
+{
+ int jtag_speed_var = 0;
+ int retval = jtag_get_speed(&jtag_speed_var);
+ if (retval != ERROR_OK)
+ return retval;
+ if (!is_adapter_initialized())
+ return ERROR_OK;
+ if (!adapter_driver->speed_div) {
+ LOG_ERROR("Translation from jtag_speed to khz not implemented");
+ return ERROR_FAIL;
+ }
+ return adapter_driver->speed_div(jtag_speed_var, khz);
+}
+
+/*
+ * 1 char: bus
+ * 2 * 7 chars: max 7 ports
+ * 1 char: test for overflow
+ * ------
+ * 16 chars
+ */
+#define USB_MAX_LOCATION_LENGTH 16
+
+#ifdef HAVE_LIBUSB_GET_PORT_NUMBERS
+static void adapter_usb_set_location(const char *location)
+{
+ if (strnlen(location, USB_MAX_LOCATION_LENGTH) == USB_MAX_LOCATION_LENGTH)
+ LOG_WARNING("usb location string is too long!!");
+
+ free(adapter_config.usb_location);
+
+ adapter_config.usb_location = strndup(location, USB_MAX_LOCATION_LENGTH);
+}
+#endif /* HAVE_LIBUSB_GET_PORT_NUMBERS */
+
+const char *adapter_usb_get_location(void)
+{
+ return adapter_config.usb_location;
+}
+
+bool adapter_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, size_t path_len)
+{
+ size_t path_step, string_length;
+ char *ptr, *loc;
+ bool equal = false;
+
+ if (!adapter_usb_get_location())
+ return equal;
+
+ /* strtok need non const char */
+ loc = strndup(adapter_usb_get_location(), USB_MAX_LOCATION_LENGTH);
+ string_length = strnlen(loc, USB_MAX_LOCATION_LENGTH);
+
+ ptr = strtok(loc, "-");
+ if (!ptr) {
+ LOG_WARNING("no '-' in usb path\n");
+ goto done;
+ }
+
+ string_length -= strnlen(ptr, string_length);
+ /* check bus mismatch */
+ if (atoi(ptr) != dev_bus)
+ goto done;
+
+ path_step = 0;
+ while (path_step < path_len) {
+ ptr = strtok(NULL, ".");
+
+ /* no more tokens in path */
+ if (!ptr)
+ break;
+
+ /* path mismatch at some step */
+ if (path_step < path_len && atoi(ptr) != port_path[path_step])
+ break;
+
+ path_step++;
+ string_length -= strnlen(ptr, string_length) + 1;
+ };
+
+ /* walked the full path, all elements match */
+ if (path_step == path_len && !string_length)
+ equal = true;
+
+done:
+ free(loc);
+ return equal;
+}
+
+static int jim_adapter_name(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
+{
+ struct jim_getopt_info goi;
+ jim_getopt_setup(&goi, interp, argc-1, argv + 1);
+
+ /* return the name of the interface */
+ /* TCL code might need to know the exact type... */
+ /* FUTURE: we allow this as a means to "set" the interface. */
+ if (goi.argc != 0) {
+ Jim_WrongNumArgs(goi.interp, 1, goi.argv-1, "(no params)");
+ return JIM_ERR;
+ }
+ const char *name = adapter_driver ? adapter_driver->name : NULL;
+ Jim_SetResultString(goi.interp, name ? name : "undefined", -1);
+ return JIM_OK;
+}
+
+COMMAND_HANDLER(adapter_transports_command)