<p>Hoernchen has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/osmo-ccid-firmware/+/16266">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">split usb descriptor code<br><br>Change-Id: I9eb3606cfbaecf81f7ae80a9ea3d061a39088760<br>---<br>M sysmoOCTSIM/main.c<br>M sysmoOCTSIM/usb/class/ccid/device/ccid_df.c<br>M sysmoOCTSIM/usb_descriptors.c<br>A sysmoOCTSIM/usb_descriptors.h<br>4 files changed, 105 insertions(+), 47 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/66/16266/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/sysmoOCTSIM/main.c b/sysmoOCTSIM/main.c</span><br><span>index 15e2004..fed562b 100644</span><br><span>--- a/sysmoOCTSIM/main.c</span><br><span>+++ b/sysmoOCTSIM/main.c</span><br><span>@@ -43,6 +43,8 @@</span><br><span> // TODO put declaration in more global file</span><br><span> // TODO for now SIM7 is not present because used for debug</span><br><span> static struct usart_async_descriptor* SIM_peripheral_descriptors[] = {&SIM0, &SIM1, &SIM2, &SIM3, &SIM4, &SIM5, &SIM6, NULL};</span><br><span style="color: hsl(120, 100%, 40%);">+#include "ccid_device.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "usb_descriptors.h"</span><br><span> </span><br><span> /** number of bytes transmitted on the SIM peripheral */</span><br><span> static volatile bool SIM_tx_count[8];</span><br><span>diff --git a/sysmoOCTSIM/usb/class/ccid/device/ccid_df.c b/sysmoOCTSIM/usb/class/ccid/device/ccid_df.c</span><br><span>index 65d3499..665f0fc 100644</span><br><span>--- a/sysmoOCTSIM/usb/class/ccid/device/ccid_df.c</span><br><span>+++ b/sysmoOCTSIM/usb/class/ccid/device/ccid_df.c</span><br><span>@@ -24,6 +24,9 @@</span><br><span> #include "ccid_proto.h"</span><br><span> #include "usb_includes.h"</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#include "cdcdf_acm_desc.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "usb_descriptors.h"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #ifndef USB_CLASS_CCID</span><br><span> #define  USB_CLASS_CCID  11</span><br><span> #endif</span><br><span>@@ -40,9 +43,11 @@</span><br><span> static struct usbdf_driver _ccid_df;</span><br><span> static struct ccid_df_func_data _ccid_df_funcd;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+extern const struct usb_desc_collection usb_fs_descs;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* FIXME: make those configurable, ensure they're sized according to</span><br><span>  * bNumClockSupported / bNumDataRatesSupported */</span><br><span style="color: hsl(0, 100%, 40%);">-static uint32_t ccid_clock_frequencies[] = { LE32(20000) };</span><br><span style="color: hsl(120, 100%, 40%);">+static uint32_t ccid_clock_frequencies[CCID_NUM_CLK_SUPPORTED] = { LE32(2500),LE32(5000),LE32(10000),LE32(20000) };</span><br><span> static uint32_t ccid_baud_rates[] = { LE32(9600) };</span><br><span> </span><br><span> static int32_t ccid_df_enable(struct usbdf_driver *drv, struct usbd_descriptors *desc)</span><br><span>diff --git a/sysmoOCTSIM/usb_descriptors.c b/sysmoOCTSIM/usb_descriptors.c</span><br><span>index 944e43b..63ace0c 100644</span><br><span>--- a/sysmoOCTSIM/usb_descriptors.c</span><br><span>+++ b/sysmoOCTSIM/usb_descriptors.c</span><br><span>@@ -1,54 +1,32 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright (C) 2019 sysmocom -s.f.m.c. GmbH, Author: Eric Wild <ewild@sysmocom.de></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</span><br><span style="color: hsl(120, 100%, 40%);">+ * modify it under the terms of the GNU General Public License</span><br><span style="color: hsl(120, 100%, 40%);">+ * as published by the Free Software Foundation; either version 2</span><br><span style="color: hsl(120, 100%, 40%);">+ * of the License, or (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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.</span><br><span style="color: hsl(120, 100%, 40%);">+*/</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #include "usbd_config.h"</span><br><span> #include "usbdc.h"</span><br><span> #include "usb_protocol.h"</span><br><span> #include "usb_protocol_cdc.h"</span><br><span> #include "ccid_proto.h"</span><br><span> #include "cdcdf_acm_desc.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "usb_descriptors.h"</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-/* aggregate descriptors for the combined CDC-ACM + CCID device that we expose</span><br><span style="color: hsl(0, 100%, 40%);">- * from sysmoQMOD */</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-enum str_desc_num {</span><br><span style="color: hsl(0, 100%, 40%);">-   STR_DESC_MANUF = 1,</span><br><span style="color: hsl(0, 100%, 40%);">-     STR_DESC_PRODUCT,</span><br><span style="color: hsl(0, 100%, 40%);">-       STR_DESC_CONFIG,</span><br><span style="color: hsl(0, 100%, 40%);">-        STR_DESC_INTF_ACM_COMM,</span><br><span style="color: hsl(0, 100%, 40%);">- STR_DESC_INTF_ACM_DATA,</span><br><span style="color: hsl(0, 100%, 40%);">- STR_DESC_INTF_CCID,</span><br><span style="color: hsl(0, 100%, 40%);">-     STR_DESC_SERIAL,</span><br><span style="color: hsl(0, 100%, 40%);">-};</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-/* a struct of structs representing the concatenated collection of USB descriptors */</span><br><span style="color: hsl(0, 100%, 40%);">-struct usb_desc_collection {</span><br><span style="color: hsl(0, 100%, 40%);">- struct usb_dev_desc dev;</span><br><span style="color: hsl(0, 100%, 40%);">-        struct usb_config_desc cfg;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-     /* CDC-ACM: Two interfaces, one with IRQ EP and one with BULK IN + OUT */</span><br><span style="color: hsl(0, 100%, 40%);">-       struct {</span><br><span style="color: hsl(0, 100%, 40%);">-                struct {</span><br><span style="color: hsl(0, 100%, 40%);">-                        struct usb_iface_desc iface;</span><br><span style="color: hsl(0, 100%, 40%);">-                    struct usb_cdc_hdr_desc cdc_hdr;</span><br><span style="color: hsl(0, 100%, 40%);">-                        struct usb_cdc_call_mgmt_desc cdc_call_mgmt;</span><br><span style="color: hsl(0, 100%, 40%);">-                    struct usb_cdc_acm_desc cdc_acm;</span><br><span style="color: hsl(0, 100%, 40%);">-                        struct usb_cdc_union_desc cdc_union;</span><br><span style="color: hsl(0, 100%, 40%);">-                    struct usb_ep_desc ep[1];</span><br><span style="color: hsl(0, 100%, 40%);">-               } comm;</span><br><span style="color: hsl(0, 100%, 40%);">-         struct {</span><br><span style="color: hsl(0, 100%, 40%);">-                        struct usb_iface_desc iface;</span><br><span style="color: hsl(0, 100%, 40%);">-                    struct usb_ep_desc ep[2];</span><br><span style="color: hsl(0, 100%, 40%);">-               } data;</span><br><span style="color: hsl(0, 100%, 40%);">- } cdc;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-  /* CCID: One interface with CCID class descriptor and three endpoints */</span><br><span style="color: hsl(0, 100%, 40%);">-        struct {</span><br><span style="color: hsl(0, 100%, 40%);">-                struct usb_iface_desc iface;</span><br><span style="color: hsl(0, 100%, 40%);">-            struct usb_ccid_class_descriptor class;</span><br><span style="color: hsl(0, 100%, 40%);">-         struct usb_ep_desc ep[3];</span><br><span style="color: hsl(0, 100%, 40%);">-       } ccid;</span><br><span style="color: hsl(0, 100%, 40%);">- uint8_t str[116];</span><br><span style="color: hsl(0, 100%, 40%);">-} __attribute__((packed));</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-static const struct usb_desc_collection usb_fs_descs = {</span><br><span style="color: hsl(120, 100%, 40%);">+const struct usb_desc_collection usb_fs_descs = {</span><br><span>       .dev = {</span><br><span>             .bLength = sizeof(struct usb_dev_desc),</span><br><span>              .bDescriptorType = USB_DT_DEVICE,</span><br><span>@@ -176,17 +154,23 @@</span><br><span>                    .bcdCCID = LE16(0x0110),</span><br><span>                     .bMaxSlotIndex = 7,</span><br><span>                  .bVoltageSupport = 0x07, /* 5/3/1.8V */</span><br><span style="color: hsl(0, 100%, 40%);">-                 .dwProtocols = 0x03,</span><br><span style="color: hsl(120, 100%, 40%);">+                  .dwProtocols = 0x01, /* only t0 */</span><br><span>                   .dwDefaultClock = LE32(2500),</span><br><span>                        .dwMaximumClock = LE32(20000),</span><br><span style="color: hsl(0, 100%, 40%);">-                  .bNumClockSupported = 4,</span><br><span style="color: hsl(0, 100%, 40%);">-                        .dwDataRate = LE32(9600),</span><br><span style="color: hsl(120, 100%, 40%);">+                     .bNumClockSupported = CCID_NUM_CLK_SUPPORTED,</span><br><span style="color: hsl(120, 100%, 40%);">+                 .dwDataRate = LE32(6720), /* default clock 2.5M/372 */</span><br><span>                       .dwMaxDataRate = LE32(921600),</span><br><span>                       .bNumDataRatesSupported = 0,</span><br><span>                         .dwMaxIFSD = LE32(0),</span><br><span>                        .dwSynchProtocols = LE32(0),</span><br><span>                         .dwMechanical = LE32(0),</span><br><span style="color: hsl(0, 100%, 40%);">-                        .dwFeatures = LE32(0x10 | 0x00010000),</span><br><span style="color: hsl(120, 100%, 40%);">+                        /* 0x10000 TPDU level exchanges with CCID</span><br><span style="color: hsl(120, 100%, 40%);">+                      * 0x80 Automatic PPS made by the CCID according to the active parameters</span><br><span style="color: hsl(120, 100%, 40%);">+                      * 0x20 Automatic baud rate change according to active parameters </span><br><span style="color: hsl(120, 100%, 40%);">+                     * provided by the Host or self determined</span><br><span style="color: hsl(120, 100%, 40%);">+                     * 0x10 Automatic ICC clock frequency change according to active parameters</span><br><span style="color: hsl(120, 100%, 40%);">+                    *  provided by the Host or self determined */</span><br><span style="color: hsl(120, 100%, 40%);">+                        .dwFeatures = LE32(0x10 | 0x20 | 0x80 | 0x00010000),</span><br><span>                         .dwMaxCCIDMessageLength = 272,</span><br><span>                       .bClassGetResponse = 0xff,</span><br><span>                   .bClassEnvelope = 0xff,</span><br><span>diff --git a/sysmoOCTSIM/usb_descriptors.h b/sysmoOCTSIM/usb_descriptors.h</span><br><span>new file mode 100644</span><br><span>index 0000000..94a4212</span><br><span>--- /dev/null</span><br><span>+++ b/sysmoOCTSIM/usb_descriptors.h</span><br><span>@@ -0,0 +1,67 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright (C) 2019 sysmocom -s.f.m.c. GmbH, Author: Eric Wild <ewild@sysmocom.de></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</span><br><span style="color: hsl(120, 100%, 40%);">+ * modify it under the terms of the GNU General Public License</span><br><span style="color: hsl(120, 100%, 40%);">+ * as published by the Free Software Foundation; either version 2</span><br><span style="color: hsl(120, 100%, 40%);">+ * of the License, or (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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 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%);">+#ifndef USB_DESCRIPTORS_H_</span><br><span style="color: hsl(120, 100%, 40%);">+#define USB_DESCRIPTORS_H_</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#define CCID_NUM_CLK_SUPPORTED 4</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* aggregate descriptors for the combined CDC-ACM + CCID device that we expose</span><br><span style="color: hsl(120, 100%, 40%);">+ * from sysmoQMOD */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+enum str_desc_num {</span><br><span style="color: hsl(120, 100%, 40%);">+        STR_DESC_MANUF = 1,</span><br><span style="color: hsl(120, 100%, 40%);">+   STR_DESC_PRODUCT,</span><br><span style="color: hsl(120, 100%, 40%);">+     STR_DESC_CONFIG,</span><br><span style="color: hsl(120, 100%, 40%);">+      STR_DESC_INTF_ACM_COMM,</span><br><span style="color: hsl(120, 100%, 40%);">+       STR_DESC_INTF_ACM_DATA,</span><br><span style="color: hsl(120, 100%, 40%);">+       STR_DESC_INTF_CCID,</span><br><span style="color: hsl(120, 100%, 40%);">+   STR_DESC_SERIAL,</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%);">+/* a struct of structs representing the concatenated collection of USB descriptors */</span><br><span style="color: hsl(120, 100%, 40%);">+struct usb_desc_collection {</span><br><span style="color: hsl(120, 100%, 40%);">+   struct usb_dev_desc dev;</span><br><span style="color: hsl(120, 100%, 40%);">+      struct usb_config_desc cfg;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* CDC-ACM: Two interfaces, one with IRQ EP and one with BULK IN + OUT */</span><br><span style="color: hsl(120, 100%, 40%);">+     struct {</span><br><span style="color: hsl(120, 100%, 40%);">+              struct {</span><br><span style="color: hsl(120, 100%, 40%);">+                      struct usb_iface_desc iface;</span><br><span style="color: hsl(120, 100%, 40%);">+                  struct usb_cdc_hdr_desc cdc_hdr;</span><br><span style="color: hsl(120, 100%, 40%);">+                      struct usb_cdc_call_mgmt_desc cdc_call_mgmt;</span><br><span style="color: hsl(120, 100%, 40%);">+                  struct usb_cdc_acm_desc cdc_acm;</span><br><span style="color: hsl(120, 100%, 40%);">+                      struct usb_cdc_union_desc cdc_union;</span><br><span style="color: hsl(120, 100%, 40%);">+                  struct usb_ep_desc ep[1];</span><br><span style="color: hsl(120, 100%, 40%);">+             } comm;</span><br><span style="color: hsl(120, 100%, 40%);">+               struct {</span><br><span style="color: hsl(120, 100%, 40%);">+                      struct usb_iface_desc iface;</span><br><span style="color: hsl(120, 100%, 40%);">+                  struct usb_ep_desc ep[2];</span><br><span style="color: hsl(120, 100%, 40%);">+             } data;</span><br><span style="color: hsl(120, 100%, 40%);">+       } cdc;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      /* CCID: One interface with CCID class descriptor and three endpoints */</span><br><span style="color: hsl(120, 100%, 40%);">+      struct {</span><br><span style="color: hsl(120, 100%, 40%);">+              struct usb_iface_desc iface;</span><br><span style="color: hsl(120, 100%, 40%);">+          struct usb_ccid_class_descriptor class;</span><br><span style="color: hsl(120, 100%, 40%);">+               struct usb_ep_desc ep[3];</span><br><span style="color: hsl(120, 100%, 40%);">+     } ccid;</span><br><span style="color: hsl(120, 100%, 40%);">+       uint8_t str[116];</span><br><span style="color: hsl(120, 100%, 40%);">+} __attribute__((packed));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#endif /* USB_DESCRIPTORS_H_ */</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-ccid-firmware/+/16266">change 16266</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/+/16266"/><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: I9eb3606cfbaecf81f7ae80a9ea3d061a39088760 </div>
<div style="display:none"> Gerrit-Change-Number: 16266 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Hoernchen <ewild@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>