<p>laforge has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/osmo-ccid-firmware/+/19960">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">import ccid-control - small hack to send CCID USB control requests<br><br>Change-Id: I7d6cf32e91dfd9974d2e28f13a2b062e07d17d6c<br>---<br>M .gitignore<br>A contrib/Makefile<br>A contrib/ccid-control.c<br>3 files changed, 97 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-ccid-firmware refs/changes/60/19960/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/.gitignore b/.gitignore</span><br><span>index 67d3a67..929436b 100644</span><br><span>--- a/.gitignore</span><br><span>+++ b/.gitignore</span><br><span>@@ -2,3 +2,4 @@</span><br><span> ccid_host/ccid_functionfs</span><br><span> ccid_host/cuart_test</span><br><span> ccid_host/hub_functionfs</span><br><span style="color: hsl(120, 100%, 40%);">+contrib/ccid-control</span><br><span>diff --git a/contrib/Makefile b/contrib/Makefile</span><br><span>new file mode 100644</span><br><span>index 0000000..54d6e77</span><br><span>--- /dev/null</span><br><span>+++ b/contrib/Makefile</span><br><span>@@ -0,0 +1,12 @@</span><br><span style="color: hsl(120, 100%, 40%);">+CFLAGS=-Wall -g `pkg-config --cflags libusb-1.0`</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+LDFLAGS=-lasan `pkg-config --libs libusb-1.0`</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ccid-control: ccid-control.o</span><br><span style="color: hsl(120, 100%, 40%);">+ $(CC) $(LDFLAGS) -o $@ $^</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+%.o: %.c</span><br><span style="color: hsl(120, 100%, 40%);">+ $(CC) $(CFLAGS) -o $@ -c $^</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+clean:</span><br><span style="color: hsl(120, 100%, 40%);">+ rm ccid-control *.o</span><br><span>diff --git a/contrib/ccid-control.c b/contrib/ccid-control.c</span><br><span>new file mode 100644</span><br><span>index 0000000..378828a</span><br><span>--- /dev/null</span><br><span>+++ b/contrib/ccid-control.c</span><br><span>@@ -0,0 +1,84 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/* CCID Control program</span><br><span style="color: hsl(120, 100%, 40%);">+ * - quick hack used to send CCID control transfers to a CCID device</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * (C) 2019-2020 by Harald Welte <laforge@gnumonks.org></span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; either version 2 of the License, or</span><br><span style="color: hsl(120, 100%, 40%);">+ * (at your option) any later version.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * You should have received a copy of the GNU General Public License</span><br><span style="color: hsl(120, 100%, 40%);">+ * along with this program; if not, write to the Free Software</span><br><span style="color: hsl(120, 100%, 40%);">+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <stdint.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <stdio.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <stdlib.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <errno.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <libusb-1.0/libusb.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static libusb_context *g_uctx;</span><br><span style="color: hsl(120, 100%, 40%);">+static uint16_t g_vendor_id = 0x2342;</span><br><span style="color: hsl(120, 100%, 40%);">+static uint16_t g_product_id = 0x2342;</span><br><span style="color: hsl(120, 100%, 40%);">+static uint8_t g_interface = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#define GET_CLOCK_FREQS  0x02</span><br><span style="color: hsl(120, 100%, 40%);">+#define GET_DATA_RATES    0x03</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static int usb_ctrl_get_dwords(libusb_device_handle *devh, uint8_t req_t, uint8_t rq,</span><br><span style="color: hsl(120, 100%, 40%);">+                         uint16_t val, uint16_t index, unsigned int num_dword)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+      uint32_t buf[num_dword];</span><br><span style="color: hsl(120, 100%, 40%);">+      unsigned int i;</span><br><span style="color: hsl(120, 100%, 40%);">+       int rc;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     rc = libusb_control_transfer(devh, req_t, rq, val, index, (uint8_t *)buf, sizeof(buf), 1000);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (rc < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+              printf("control_transfer: %s\n", libusb_strerror(rc));</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   for (i = 0; i < num_dword; i++)</span><br><span style="color: hsl(120, 100%, 40%);">+            printf("\t%u\n", buf[i]);</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 style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+int main(int argc, char **argv)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  libusb_device_handle *devh;</span><br><span style="color: hsl(120, 100%, 40%);">+   int rc;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     rc = libusb_init(&g_uctx);</span><br><span style="color: hsl(120, 100%, 40%);">+        if (rc < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+              fprintf(stderr, "Cannot init libusb\n");</span><br><span style="color: hsl(120, 100%, 40%);">+            exit(1);</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%);">+   devh = libusb_open_device_with_vid_pid(g_uctx, g_vendor_id, g_product_id);</span><br><span style="color: hsl(120, 100%, 40%);">+    if (!devh) {</span><br><span style="color: hsl(120, 100%, 40%);">+          fprintf(stderr, "Cannot open usb device %04x:%04x\n", g_vendor_id, g_product_id);</span><br><span style="color: hsl(120, 100%, 40%);">+           exit(1);</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%);">+   printf("Clock Frequencies:\n");</span><br><span style="color: hsl(120, 100%, 40%);">+     usb_ctrl_get_dwords(devh, 0xA1, GET_CLOCK_FREQS, 0, g_interface, 1);</span><br><span style="color: hsl(120, 100%, 40%);">+  printf("\n");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     printf("Data Rates\n");</span><br><span style="color: hsl(120, 100%, 40%);">+     usb_ctrl_get_dwords(devh, 0xA1, GET_DATA_RATES, 0, g_interface, 1);</span><br><span style="color: hsl(120, 100%, 40%);">+   printf("\n");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     libusb_close(devh);</span><br><span style="color: hsl(120, 100%, 40%);">+   exit(0);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-ccid-firmware/+/19960">change 19960</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/osmo-ccid-firmware/+/19960"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-ccid-firmware </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I7d6cf32e91dfd9974d2e28f13a2b062e07d17d6c </div>
<div style="display:none"> Gerrit-Change-Number: 19960 </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-MessageType: newchange </div>