blob: 1e3104ad1d8284c6a6d99c0c24f6ba4f03f63466 [file] [log] [blame]
Kévin Redonefbcf382018-07-07 17:35:15 +02001/* simtrace2_usb - host PC application to list found SIMtrace 2 USB devices
2 *
3 * (C) 2016 by Harald Welte <hwelte@hmw-consulting.de>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
Harald Welte822d66e2017-03-06 20:58:03 +010019#include <stdio.h>
20#include <stdint.h>
21#include <stdlib.h>
22#include <errno.h>
23
24#include <osmocom/core/utils.h>
25
26#include "libusb_util.h"
Kévin Redone2f84f62018-07-01 18:19:36 +020027#include "simtrace_usb.h"
Harald Welte822d66e2017-03-06 20:58:03 +010028
29static const struct dev_id compatible_dev_ids[] = {
30 { USB_VENDOR_OPENMOKO, USB_PRODUCT_OWHW_SAM3 },
31 { USB_VENDOR_OPENMOKO, USB_PRODUCT_QMOD_SAM3 },
32 { USB_VENDOR_OPENMOKO, USB_PRODUCT_SIMTRACE2 },
33 { 0, 0 }
34};
35
Harald Welte822d66e2017-03-06 20:58:03 +010036static int find_devices(void)
37{
38 struct usb_interface_match ifm[16];
39 int rc, i, num_interfaces;
40
Kévin Redone2f84f62018-07-01 18:19:36 +020041 /* scan for USB devices matching SIMtrace USB ID with proprietary class */
Harald Welte822d66e2017-03-06 20:58:03 +010042 rc = usb_match_interfaces(NULL, compatible_dev_ids,
Kévin Redone2f84f62018-07-01 18:19:36 +020043 USB_CLASS_PROPRIETARY, -1, -1, ifm, ARRAY_SIZE(ifm));
44 printf("USB matches: %d\n", rc);
Harald Welte822d66e2017-03-06 20:58:03 +010045 if (rc < 0)
46 return rc;
47 num_interfaces = rc;
48
49 for (i = 0; i < num_interfaces; i++) {
50 struct usb_interface_match *m = &ifm[i];
51 libusb_device_handle *dev_handle;
52 char strbuf[256];
53
Harald Weltea6016352017-05-11 01:31:45 +020054 printf("\t%04x:%04x Addr=%u, Path=%s, Cfg=%u, Intf=%u, Alt=%u: %d/%d/%d ",
55 m->vendor, m->product, m->addr, m->path,
Harald Welte822d66e2017-03-06 20:58:03 +010056 m->configuration, m->interface, m->altsetting,
57 m->class, m->sub_class, m->protocol);
58
59 rc = libusb_open(m->usb_dev, &dev_handle);
60 if (rc < 0) {
61 printf("\n");
62 perror("Cannot open device");
63 continue;
64 }
Harald Welte9f38ddd2017-05-10 22:49:02 +020065 rc = libusb_get_string_descriptor_ascii(dev_handle, m->string_idx,
66 (unsigned char *)strbuf, sizeof(strbuf));
Harald Welte822d66e2017-03-06 20:58:03 +010067 libusb_close(dev_handle);
68 if (rc < 0) {
69 printf("\n");
70 perror("Cannot read string");
71 continue;
72 }
73 printf("(%s)\n", strbuf);
74#if 0
75 dev_handle = usb_open_claim_interface(NULL, m);
76 printf("dev_handle=%p\n", dev_handle);
77 libusb_close(dev_handle);
78#endif
79 }
80
81 return num_interfaces;
82}
83
84int main(int argc, char **argv)
85{
86 libusb_init(NULL);
87 find_devices();
Martin Hauke53b4e592018-10-13 20:40:22 +020088 return 0;
Harald Welte822d66e2017-03-06 20:58:03 +010089}