Change in osmo-ccid-firmware[master]: Implement serial number string descriptor in CTRL EP callback

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 Feb 6 16:22:32 UTC 2020


laforge has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ccid-firmware/+/17055 )

Change subject: Implement serial number string descriptor in CTRL EP callback
......................................................................

Implement serial number string descriptor in CTRL EP callback

Change-Id: I910eca1db4baa375bf604110301a0bde25ffcb26
---
M sysmoOCTSIM/main.c
M sysmoOCTSIM/usb_descriptors.h
M sysmoOCTSIM/usb_start.c
3 files changed, 77 insertions(+), 3 deletions(-)

Approvals:
  laforge: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/sysmoOCTSIM/main.c b/sysmoOCTSIM/main.c
index 07c5af8..3db67d9 100644
--- a/sysmoOCTSIM/main.c
+++ b/sysmoOCTSIM/main.c
@@ -436,11 +436,15 @@
 //#######################
 
 #define NUM_OUT_BUF 16
+char sernr_buf[16*2+1];
+//unicode for descriptor
+uint8_t sernr_buf_descr[1+1+16*2*2];
+
+
+char rstcause_buf[RSTCAUSE_STR_SIZE];
 
 int main(void)
 {
-	char sernr_buf[16*2+1];
-	char rstcause_buf[RSTCAUSE_STR_SIZE];
 
 #if 0
 CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk ; //| /* tracing*/
@@ -469,6 +473,11 @@
 	get_chip_unique_serial_str(sernr_buf, sizeof(sernr_buf));
 	get_rstcause_str(rstcause_buf);
 
+	sernr_buf_descr[0] = sizeof(sernr_buf_descr);
+	sernr_buf_descr[1] = 0x3;
+	for(int i= 2; i < sizeof(sernr_buf_descr); i+=2)
+		sernr_buf_descr[i] = sernr_buf[i >> 1];
+
 	usb_start();
 
 	board_init();
diff --git a/sysmoOCTSIM/usb_descriptors.h b/sysmoOCTSIM/usb_descriptors.h
index adf6405..df072c2 100644
--- a/sysmoOCTSIM/usb_descriptors.h
+++ b/sysmoOCTSIM/usb_descriptors.h
@@ -19,6 +19,8 @@
 #ifndef USB_DESCRIPTORS_H_
 #define USB_DESCRIPTORS_H_
 
+#include "ccid_device.h"
+
 #define CCID_NUM_CLK_SUPPORTED 4
 
 /* aggregate descriptors for the combined CDC-ACM + CCID device that we expose
diff --git a/sysmoOCTSIM/usb_start.c b/sysmoOCTSIM/usb_start.c
index c6d9fe9..08201cb 100644
--- a/sysmoOCTSIM/usb_start.c
+++ b/sysmoOCTSIM/usb_start.c
@@ -7,6 +7,7 @@
  */
 #include "atmel_start.h"
 #include "usb_start.h"
+#include "usb_descriptors.h"
 
 #define CDCD_ECHO_BUF_SIZ CONF_USB_CDCD_ACM_DATA_BULKIN_MAXPKSZ
 
@@ -58,6 +59,67 @@
 
 extern const struct usbd_descriptors usb_descs[];
 
+/* transmit given string descriptor */
+static bool send_str_desc(uint8_t ep, const struct usb_req *req, enum usb_ctrl_stage stage,
+			  const uint8_t *desc)
+{
+	uint16_t len_req = LE16(req->wLength);
+	uint16_t len_desc = desc[0];
+	uint16_t len_tx;
+	bool need_zlp = !(len_req & (CONF_USB_CDCD_ACM_BMAXPKSZ0 - 1));
+
+	if (len_req <= len_desc) {
+		need_zlp = false;
+		len_tx = len_req;
+	} else {
+		len_tx = len_desc;
+	}
+
+	if (ERR_NONE != usbdc_xfer(ep, (uint8_t *)desc, len_tx, need_zlp)) {
+		return true;
+	}
+
+	return false;
+}
+
+extern uint8_t sernr_buf_descr[];
+/* call-back for every control EP request */
+static int32_t string_req_cb(uint8_t ep, struct usb_req *req, enum usb_ctrl_stage stage)
+{
+	uint8_t index, type;
+
+	if (stage != USB_SETUP_STAGE)
+		return ERR_NOT_FOUND;
+
+	if ((req->bmRequestType & (USB_REQT_TYPE_MASK | USB_REQT_DIR_IN)) !=
+	    (USB_REQT_TYPE_STANDARD | USB_REQT_DIR_IN))
+		return ERR_NOT_FOUND;
+
+	/* abort if it's not a GET DESCRIPTOR request */
+	if (req->bRequest != USB_REQ_GET_DESC)
+		return ERR_NOT_FOUND;
+
+	/* abort if it's not about a string descriptor */
+	type = req->wValue >> 8;
+	if (type != USB_DT_STRING)
+		return ERR_NOT_FOUND;
+#if 0
+	printf("ep=%02x, bmReqT=%04x, bReq=%02x, wValue=%04x, stage=%d\r\n",
+		ep, req->bmRequestType, req->bRequest, req->wValue, stage);
+#endif
+	/* abort if it's not a standard GET request */
+	index = req->wValue & 0x00FF;
+	switch (index) {
+	case STR_DESC_SERIAL:
+		return send_str_desc(ep, req, stage, sernr_buf_descr);
+	default:
+		return ERR_NOT_FOUND;
+	}
+}
+
+
+static struct usbdc_handler string_req_h = {NULL, (FUNC_PTR)string_req_cb};
+
 /**
  * \brief CDC ACM Init
  */
@@ -65,10 +127,12 @@
 {
 	/* usb stack init */
 	usbdc_init(ctrl_buffer);
+	usbdc_register_handler(USBDC_HDL_REQ, &string_req_h);
 
 	/* usbdc_register_funcion inside */
 	cdcdf_acm_init();
 
+	printf("usb_descs_size=%u\r\n", usb_descs[0].eod - usb_descs[0].sod);
 	usbdc_start((struct usbd_descriptors *) usb_descs);
 	usbdc_attach();
 }
@@ -87,7 +151,6 @@
 
 void usb_init(void)
 {
-
 	cdc_device_acm_init();
 	ccid_df_init();
 }

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-ccid-firmware/+/17055
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: I910eca1db4baa375bf604110301a0bde25ffcb26
Gerrit-Change-Number: 17055
Gerrit-PatchSet: 2
Gerrit-Owner: Hoernchen <ewild at sysmocom.de>
Gerrit-Reviewer: Hoernchen <ewild at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200206/a3bf124f/attachment.htm>


More information about the gerrit-log mailing list