Change in osmo-ccid-firmware[master]: import ccid-control - small hack to send CCID USB control requests

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 Sep 3 08:12:59 UTC 2020


laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-ccid-firmware/+/19960 )


Change subject: import ccid-control - small hack to send CCID USB control requests
......................................................................

import ccid-control - small hack to send CCID USB control requests

Change-Id: I7d6cf32e91dfd9974d2e28f13a2b062e07d17d6c
---
M .gitignore
A contrib/Makefile
A contrib/ccid-control.c
3 files changed, 97 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-ccid-firmware refs/changes/60/19960/1

diff --git a/.gitignore b/.gitignore
index 67d3a67..929436b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@
 ccid_host/ccid_functionfs
 ccid_host/cuart_test
 ccid_host/hub_functionfs
+contrib/ccid-control
diff --git a/contrib/Makefile b/contrib/Makefile
new file mode 100644
index 0000000..54d6e77
--- /dev/null
+++ b/contrib/Makefile
@@ -0,0 +1,12 @@
+CFLAGS=-Wall -g `pkg-config --cflags libusb-1.0`
+
+LDFLAGS=-lasan `pkg-config --libs libusb-1.0`
+
+ccid-control: ccid-control.o
+	$(CC) $(LDFLAGS) -o $@ $^
+
+%.o: %.c
+	$(CC) $(CFLAGS) -o $@ -c $^
+
+clean:
+	rm ccid-control *.o
diff --git a/contrib/ccid-control.c b/contrib/ccid-control.c
new file mode 100644
index 0000000..378828a
--- /dev/null
+++ b/contrib/ccid-control.c
@@ -0,0 +1,84 @@
+/* CCID Control program
+ * - quick hack used to send CCID control transfers to a CCID device
+ *
+ * (C) 2019-2020 by Harald Welte <laforge at gnumonks.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA
+ */
+
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <libusb-1.0/libusb.h>
+
+static libusb_context *g_uctx;
+static uint16_t g_vendor_id = 0x2342;
+static uint16_t g_product_id = 0x2342;
+static uint8_t g_interface = 0;
+
+#define GET_CLOCK_FREQS	0x02
+#define GET_DATA_RATES	0x03
+
+static int usb_ctrl_get_dwords(libusb_device_handle *devh, uint8_t req_t, uint8_t rq,
+				uint16_t val, uint16_t index, unsigned int num_dword)
+{
+	uint32_t buf[num_dword];
+	unsigned int i;
+	int rc;
+
+	rc = libusb_control_transfer(devh, req_t, rq, val, index, (uint8_t *)buf, sizeof(buf), 1000);
+	if (rc < 0) {
+		printf("control_transfer: %s\n", libusb_strerror(rc));
+		return rc;
+	}
+
+	for (i = 0; i < num_dword; i++)
+		printf("\t%u\n", buf[i]);
+
+	return 0;
+}
+
+
+int main(int argc, char **argv)
+{
+	libusb_device_handle *devh;
+	int rc;
+
+	rc = libusb_init(&g_uctx);
+	if (rc < 0) {
+		fprintf(stderr, "Cannot init libusb\n");
+		exit(1);
+	}
+
+	devh = libusb_open_device_with_vid_pid(g_uctx, g_vendor_id, g_product_id);
+	if (!devh) {
+		fprintf(stderr, "Cannot open usb device %04x:%04x\n", g_vendor_id, g_product_id);
+		exit(1);
+	}
+
+	printf("Clock Frequencies:\n");
+	usb_ctrl_get_dwords(devh, 0xA1, GET_CLOCK_FREQS, 0, g_interface, 1);
+	printf("\n");
+
+	printf("Data Rates\n");
+	usb_ctrl_get_dwords(devh, 0xA1, GET_DATA_RATES, 0, g_interface, 1);
+	printf("\n");
+
+	libusb_close(devh);
+	exit(0);
+}
+

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-ccid-firmware/+/19960
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-ccid-firmware
Gerrit-Branch: master
Gerrit-Change-Id: I7d6cf32e91dfd9974d2e28f13a2b062e07d17d6c
Gerrit-Change-Number: 19960
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/20200903/d2b3f2f2/attachment.htm>


More information about the gerrit-log mailing list