<p>laforge <strong>submitted</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/osmo-ccid-firmware/+/17033">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  laforge: Looks good to me, approved
  Jenkins Builder: Verified

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">Add DFU runtime descriptor<br><br>Change-Id: I031c2353248873735698c845f591537779eee995<br>---<br>A sysmoOCTSIM/dfu_descriptors.h<br>M sysmoOCTSIM/usb_descriptors.c<br>M sysmoOCTSIM/usb_descriptors.h<br>A sysmoOCTSIM/usb_dfu.h<br>4 files changed, 133 insertions(+), 4 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/sysmoOCTSIM/dfu_descriptors.h b/sysmoOCTSIM/dfu_descriptors.h</span><br><span>new file mode 100644</span><br><span>index 0000000..8cbaf23</span><br><span>--- /dev/null</span><br><span>+++ b/sysmoOCTSIM/dfu_descriptors.h</span><br><span>@@ -0,0 +1,44 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#ifndef _USB_DEV_DFU_H</span><br><span style="color: hsl(120, 100%, 40%);">+#define _USB_DEV_DFU_H</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include "usb_protocol.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "usb_dfu.h"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* USB DFU functional descriptor */</span><br><span style="color: hsl(120, 100%, 40%);">+#define DFU_FUNC_DESC  {                                             \</span><br><span style="color: hsl(120, 100%, 40%);">+     .bLength                = USB_DT_DFU_SIZE,                      \</span><br><span style="color: hsl(120, 100%, 40%);">+     .bDescriptorType        = USB_DT_DFU,                           \</span><br><span style="color: hsl(120, 100%, 40%);">+     .bmAttributes           = USB_DFU_CAN_UPLOAD | USB_DFU_CAN_DOWNLOAD, \</span><br><span style="color: hsl(120, 100%, 40%);">+        .wDetachTimeOut         = 5000,                                 \</span><br><span style="color: hsl(120, 100%, 40%);">+     .wTransferSize          = FLASH_PAGE_SIZE,                      \</span><br><span style="color: hsl(120, 100%, 40%);">+     .bcdDFUVersion          = 0x0100,                               \</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%);">+/* Number of DFU interface during runtime mode */</span><br><span style="color: hsl(120, 100%, 40%);">+#define DFURT_NUM_IF         1</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* to be used by the runtime as part of its USB descriptor structure</span><br><span style="color: hsl(120, 100%, 40%);">+ * declaration */</span><br><span style="color: hsl(120, 100%, 40%);">+#define DFURT_IF_DESCRIPTOR_STRUCT                \</span><br><span style="color: hsl(120, 100%, 40%);">+     struct usb_iface_desc           dfu_rt;         \</span><br><span style="color: hsl(120, 100%, 40%);">+     struct usb_dfu_func_descriptor  func_dfu;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* to be used by the runtime as part of its USB Dsecriptor structure</span><br><span style="color: hsl(120, 100%, 40%);">+ * definition */</span><br><span style="color: hsl(120, 100%, 40%);">+#define DFURT_IF_DESCRIPTOR(dfuIF, dfuSTR)                                 \</span><br><span style="color: hsl(120, 100%, 40%);">+     .dfu_rt = {                                                             \</span><br><span style="color: hsl(120, 100%, 40%);">+             .bLength                = sizeof(struct usb_iface_desc),        \</span><br><span style="color: hsl(120, 100%, 40%);">+             .bDescriptorType        = USB_DT_INTERFACE,                     \</span><br><span style="color: hsl(120, 100%, 40%);">+             .bInterfaceNumber       = dfuIF,                                \</span><br><span style="color: hsl(120, 100%, 40%);">+             .bAlternateSetting      = 0,                                    \</span><br><span style="color: hsl(120, 100%, 40%);">+             .bNumEndpoints          = 0,                                    \</span><br><span style="color: hsl(120, 100%, 40%);">+             .bInterfaceClass        = 0xFE,                                 \</span><br><span style="color: hsl(120, 100%, 40%);">+             .bInterfaceSubClass     = 0x01,                                 \</span><br><span style="color: hsl(120, 100%, 40%);">+             .bInterfaceProtocol     = 0x01,                                 \</span><br><span style="color: hsl(120, 100%, 40%);">+             .iInterface             = dfuSTR,                               \</span><br><span style="color: hsl(120, 100%, 40%);">+     },                                                                      \</span><br><span style="color: hsl(120, 100%, 40%);">+     .func_dfu = DFU_FUNC_DESC                                               \</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span>diff --git a/sysmoOCTSIM/usb_descriptors.c b/sysmoOCTSIM/usb_descriptors.c</span><br><span>index 2b41390..00d2007 100644</span><br><span>--- a/sysmoOCTSIM/usb_descriptors.c</span><br><span>+++ b/sysmoOCTSIM/usb_descriptors.c</span><br><span>@@ -47,8 +47,10 @@</span><br><span>            .bDescriptorType = USB_DT_CONFIG,</span><br><span>            .wTotalLength = sizeof(usb_fs_descs.cfg) +</span><br><span>                           sizeof(usb_fs_descs.cdc) +</span><br><span style="color: hsl(0, 100%, 40%);">-                              sizeof(usb_fs_descs.ccid),</span><br><span style="color: hsl(0, 100%, 40%);">-              .bNumInterfaces = 3,</span><br><span style="color: hsl(120, 100%, 40%);">+                          sizeof(usb_fs_descs.ccid) +</span><br><span style="color: hsl(120, 100%, 40%);">+                           sizeof(usb_fs_descs.dfu_rt) +</span><br><span style="color: hsl(120, 100%, 40%);">+                         sizeof(usb_fs_descs.func_dfu),</span><br><span style="color: hsl(120, 100%, 40%);">+                .bNumInterfaces = 4,</span><br><span>                 .bConfigurationValue = CONF_USB_CDCD_ACM_BCONFIGVAL,</span><br><span>                 .iConfiguration = STR_DESC_CONFIG,</span><br><span>           .bmAttributes = CONF_USB_CDCD_ACM_BMATTRI,</span><br><span>@@ -206,7 +208,7 @@</span><br><span>                     },</span><br><span>           },</span><br><span>   },</span><br><span style="color: hsl(0, 100%, 40%);">-      //DFURT_IF_DESCRIPTOR,</span><br><span style="color: hsl(120, 100%, 40%);">+        DFURT_IF_DESCRIPTOR(3, STR_DESC_INTF_DFURT),</span><br><span>         .str = {</span><br><span> #if 0</span><br><span>            CDCD_ACM_STR_DESCES</span><br><span>@@ -219,6 +221,7 @@</span><br><span>            22,  3, 'd',0, 'e',0, 'b',0, 'u',0, 'g',0, ' ',0, 'U',0, 'A',0, 'R',0, 'T',0,</span><br><span>                10,  3, 'C',0, 'C',0, 'I',0, 'D',0,</span><br><span>          12,  3, 'F',0, 'I',0, 'X',0, 'M',0, 'E',0,</span><br><span style="color: hsl(120, 100%, 40%);">+            28,  3, 'D',0, 'F',0, 'U',0, ' ',0, '(',0, 'R',0, 'u',0, 'n',0, 't',0, 'i',0, 'm',0, 'e',0 ,')',0,</span><br><span> #endif</span><br><span>         }</span><br><span> };</span><br><span>diff --git a/sysmoOCTSIM/usb_descriptors.h b/sysmoOCTSIM/usb_descriptors.h</span><br><span>index df072c2..ea47d07 100644</span><br><span>--- a/sysmoOCTSIM/usb_descriptors.h</span><br><span>+++ b/sysmoOCTSIM/usb_descriptors.h</span><br><span>@@ -20,6 +20,7 @@</span><br><span> #define USB_DESCRIPTORS_H_</span><br><span> </span><br><span> #include "ccid_device.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "dfu_descriptors.h"</span><br><span> </span><br><span> #define CCID_NUM_CLK_SUPPORTED 4</span><br><span> </span><br><span>@@ -34,6 +35,7 @@</span><br><span>         STR_DESC_INTF_ACM_DATA,</span><br><span>      STR_DESC_INTF_CCID,</span><br><span>  STR_DESC_SERIAL,</span><br><span style="color: hsl(120, 100%, 40%);">+      STR_DESC_INTF_DFURT,</span><br><span> };</span><br><span> </span><br><span> /* a struct of structs representing the concatenated collection of USB descriptors */</span><br><span>@@ -63,7 +65,8 @@</span><br><span>          struct usb_ccid_class_descriptor class;</span><br><span>              struct usb_ep_desc ep[3];</span><br><span>    } ccid;</span><br><span style="color: hsl(0, 100%, 40%);">- uint8_t str[148];</span><br><span style="color: hsl(120, 100%, 40%);">+     DFURT_IF_DESCRIPTOR_STRUCT</span><br><span style="color: hsl(120, 100%, 40%);">+    uint8_t str[176];</span><br><span> } __attribute__((packed));</span><br><span> </span><br><span> #endif /* USB_DESCRIPTORS_H_ */</span><br><span>diff --git a/sysmoOCTSIM/usb_dfu.h b/sysmoOCTSIM/usb_dfu.h</span><br><span>new file mode 100644</span><br><span>index 0000000..b447c7c</span><br><span>--- /dev/null</span><br><span>+++ b/sysmoOCTSIM/usb_dfu.h</span><br><span>@@ -0,0 +1,79 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#ifndef _USB_DFU_H</span><br><span style="color: hsl(120, 100%, 40%);">+#define _USB_DFU_H</span><br><span style="color: hsl(120, 100%, 40%);">+/* USB Device Firmware Update Implementation for OpenPCD</span><br><span style="color: hsl(120, 100%, 40%);">+ * (C) 2006 by Harald Welte <hwelte@hmw-consulting.de></span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Protocol definitions for USB DFU</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This ought to be compliant to the USB DFU Spec 1.0 as available from</span><br><span style="color: hsl(120, 100%, 40%);">+ * http://www.usb.org/developers/devclass_docs/usbdfu10.pdf</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%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#define USB_DT_DFU                     0x21</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct usb_dfu_func_descriptor {</span><br><span style="color: hsl(120, 100%, 40%);">+      uint8_t         bLength;</span><br><span style="color: hsl(120, 100%, 40%);">+      uint8_t         bDescriptorType;</span><br><span style="color: hsl(120, 100%, 40%);">+      uint8_t         bmAttributes;</span><br><span style="color: hsl(120, 100%, 40%);">+#define USB_DFU_CAN_DOWNLOAD     (1 << 0)</span><br><span style="color: hsl(120, 100%, 40%);">+#define USB_DFU_CAN_UPLOAD      (1 << 1)</span><br><span style="color: hsl(120, 100%, 40%);">+#define USB_DFU_MANIFEST_TOL    (1 << 2)</span><br><span style="color: hsl(120, 100%, 40%);">+#define USB_DFU_WILL_DETACH     (1 << 3)</span><br><span style="color: hsl(120, 100%, 40%);">+        uint16_t                wDetachTimeOut;</span><br><span style="color: hsl(120, 100%, 40%);">+       uint16_t                wTransferSize;</span><br><span style="color: hsl(120, 100%, 40%);">+        uint16_t                bcdDFUVersion;</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%);">+#define USB_DT_DFU_SIZE                  9</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* DFU class-specific requests (Section 3, DFU Rev 1.1) */</span><br><span style="color: hsl(120, 100%, 40%);">+#define USB_REQ_DFU_DETACH     0x00</span><br><span style="color: hsl(120, 100%, 40%);">+#define USB_REQ_DFU_DNLOAD        0x01</span><br><span style="color: hsl(120, 100%, 40%);">+#define USB_REQ_DFU_UPLOAD        0x02</span><br><span style="color: hsl(120, 100%, 40%);">+#define USB_REQ_DFU_GETSTATUS     0x03</span><br><span style="color: hsl(120, 100%, 40%);">+#define USB_REQ_DFU_CLRSTATUS     0x04</span><br><span style="color: hsl(120, 100%, 40%);">+#define USB_REQ_DFU_GETSTATE      0x05</span><br><span style="color: hsl(120, 100%, 40%);">+#define USB_REQ_DFU_ABORT 0x06</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct dfu_status {</span><br><span style="color: hsl(120, 100%, 40%);">+   uint8_t bStatus;</span><br><span style="color: hsl(120, 100%, 40%);">+      uint8_t bwPollTimeout[3];</span><br><span style="color: hsl(120, 100%, 40%);">+     uint8_t bState;</span><br><span style="color: hsl(120, 100%, 40%);">+       uint8_t iString;</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%);">+#define DFU_STATUS_OK                   0x00</span><br><span style="color: hsl(120, 100%, 40%);">+#define DFU_STATUS_errTARGET              0x01</span><br><span style="color: hsl(120, 100%, 40%);">+#define DFU_STATUS_errFILE                0x02</span><br><span style="color: hsl(120, 100%, 40%);">+#define DFU_STATUS_errWRITE               0x03</span><br><span style="color: hsl(120, 100%, 40%);">+#define DFU_STATUS_errERASE               0x04</span><br><span style="color: hsl(120, 100%, 40%);">+#define DFU_STATUS_errCHECK_ERASED        0x05</span><br><span style="color: hsl(120, 100%, 40%);">+#define DFU_STATUS_errPROG                0x06</span><br><span style="color: hsl(120, 100%, 40%);">+#define DFU_STATUS_errVERIFY              0x07</span><br><span style="color: hsl(120, 100%, 40%);">+#define DFU_STATUS_errADDRESS             0x08</span><br><span style="color: hsl(120, 100%, 40%);">+#define DFU_STATUS_errNOTDONE             0x09</span><br><span style="color: hsl(120, 100%, 40%);">+#define DFU_STATUS_errFIRMWARE            0x0a</span><br><span style="color: hsl(120, 100%, 40%);">+#define DFU_STATUS_errVENDOR              0x0b</span><br><span style="color: hsl(120, 100%, 40%);">+#define DFU_STATUS_errUSBR                0x0c</span><br><span style="color: hsl(120, 100%, 40%);">+#define DFU_STATUS_errPOR         0x0d</span><br><span style="color: hsl(120, 100%, 40%);">+#define DFU_STATUS_errUNKNOWN             0x0e</span><br><span style="color: hsl(120, 100%, 40%);">+#define DFU_STATUS_errSTALLEDPKT  0x0f</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+enum dfu_state {</span><br><span style="color: hsl(120, 100%, 40%);">+      DFU_STATE_appIDLE               = 0,</span><br><span style="color: hsl(120, 100%, 40%);">+  DFU_STATE_appDETACH             = 1,</span><br><span style="color: hsl(120, 100%, 40%);">+  DFU_STATE_dfuIDLE               = 2,</span><br><span style="color: hsl(120, 100%, 40%);">+  DFU_STATE_dfuDNLOAD_SYNC        = 3,</span><br><span style="color: hsl(120, 100%, 40%);">+  DFU_STATE_dfuDNBUSY             = 4,</span><br><span style="color: hsl(120, 100%, 40%);">+  DFU_STATE_dfuDNLOAD_IDLE        = 5,</span><br><span style="color: hsl(120, 100%, 40%);">+  DFU_STATE_dfuMANIFEST_SYNC      = 6,</span><br><span style="color: hsl(120, 100%, 40%);">+  DFU_STATE_dfuMANIFEST           = 7,</span><br><span style="color: hsl(120, 100%, 40%);">+  DFU_STATE_dfuMANIFEST_WAIT_RST  = 8,</span><br><span style="color: hsl(120, 100%, 40%);">+  DFU_STATE_dfuUPLOAD_IDLE        = 9,</span><br><span style="color: hsl(120, 100%, 40%);">+  DFU_STATE_dfuERROR              = 10,</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%);">+#endif /* _USB_DFU_H */</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-ccid-firmware/+/17033">change 17033</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/+/17033"/><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: I031c2353248873735698c845f591537779eee995 </div>
<div style="display:none"> Gerrit-Change-Number: 17033 </div>
<div style="display:none"> Gerrit-PatchSet: 4 </div>
<div style="display:none"> Gerrit-Owner: Hoernchen <ewild@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>