blob: d28ddfcbbf1e9a096e9a6716192148026dbfced9 [file] [log] [blame]
Harald Welte8dd67e32020-09-03 10:10:09 +02001/* CCID Control program
2 * - quick hack used to send CCID control transfers to a CCID device
3 *
4 * (C) 2019-2020 by Harald Welte <laforge@gnumonks.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
19 */
20
21
22#include <stdint.h>
23#include <stdio.h>
24#include <stdlib.h>
25#include <errno.h>
26#include <libusb-1.0/libusb.h>
27
28static libusb_context *g_uctx;
Harald Welte6b2ff3b2020-09-03 10:16:42 +020029static uint16_t g_vendor_id = 0x1d50;
30static uint16_t g_product_id = 0x615f;
Harald Welte8dd67e32020-09-03 10:10:09 +020031static uint8_t g_interface = 0;
32
33#define GET_CLOCK_FREQS 0x02
34#define GET_DATA_RATES 0x03
35
36static int usb_ctrl_get_dwords(libusb_device_handle *devh, uint8_t req_t, uint8_t rq,
37 uint16_t val, uint16_t index, unsigned int num_dword)
38{
39 uint32_t buf[num_dword];
40 unsigned int i;
41 int rc;
42
43 rc = libusb_control_transfer(devh, req_t, rq, val, index, (uint8_t *)buf, sizeof(buf), 1000);
44 if (rc < 0) {
45 printf("control_transfer: %s\n", libusb_strerror(rc));
46 return rc;
47 }
48
49 for (i = 0; i < num_dword; i++)
50 printf("\t%u\n", buf[i]);
51
52 return 0;
53}
54
55
56int main(int argc, char **argv)
57{
58 libusb_device_handle *devh;
59 int rc;
60
61 rc = libusb_init(&g_uctx);
62 if (rc < 0) {
63 fprintf(stderr, "Cannot init libusb\n");
64 exit(1);
65 }
66
67 devh = libusb_open_device_with_vid_pid(g_uctx, g_vendor_id, g_product_id);
68 if (!devh) {
69 fprintf(stderr, "Cannot open usb device %04x:%04x\n", g_vendor_id, g_product_id);
70 exit(1);
71 }
72
73 printf("Clock Frequencies:\n");
74 usb_ctrl_get_dwords(devh, 0xA1, GET_CLOCK_FREQS, 0, g_interface, 1);
75 printf("\n");
76
77 printf("Data Rates\n");
78 usb_ctrl_get_dwords(devh, 0xA1, GET_DATA_RATES, 0, g_interface, 1);
79 printf("\n");
80
81 libusb_close(devh);
82 exit(0);
83}
84