Debian Codegraph @

src/usb_dfu.h

raw
1 #ifndef USB_DFU_H
2 #define USB_DFU_H
3 /* USB Device Firmware Update Implementation for OpenPCD
4 * (C) 2006 by Harald Welte <[email protected]>
5 *
6 * Protocol definitions for USB DFU
7 *
8 * This ought to be compliant to the USB DFU Spec 1.0 as available from
9 * http://www.usb.org/developers/devclass_docs/usbdfu10.pdf
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
26 #include <stdint.h>
27
28 #define USB_DT_DFU 0x21
29
30 #ifdef _MSC_VER
31 # pragma pack(push)
32 # pragma pack(1)
33 #endif /* _MSC_VER */
34 struct usb_dfu_func_descriptor {
35 uint8_t bLength;
36 uint8_t bDescriptorType;
37 uint8_t bmAttributes;
38 #define USB_DFU_CAN_DOWNLOAD (1 << 0)
39 #define USB_DFU_CAN_UPLOAD (1 << 1)
40 #define USB_DFU_MANIFEST_TOL (1 << 2)
41 #define USB_DFU_WILL_DETACH (1 << 3)
42 uint16_t wDetachTimeOut;
43 uint16_t wTransferSize;
44 uint16_t bcdDFUVersion;
45 #ifdef _MSC_VER
46 };
47 # pragma pack(pop)
48 #elif defined __GNUC__
49 # if defined __MINGW32__
50 } __attribute__ ((__packed__, __gcc_struct__));
51 # else
52 } __attribute__ ((__packed__));
53 # endif
54 #else
55 #warning "No way to pack struct on this compiler? This will break!"
56 #endif /* _MSC_VER */
57
58 #define USB_DT_DFU_SIZE 9
59
60 #define USB_TYPE_DFU (LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE)
61
62 /* DFU class-specific requests (Section 3, DFU Rev 1.1) */
63 #define USB_REQ_DFU_DETACH 0x00
64 #define USB_REQ_DFU_DNLOAD 0x01
65 #define USB_REQ_DFU_UPLOAD 0x02
66 #define USB_REQ_DFU_GETSTATUS 0x03
67 #define USB_REQ_DFU_CLRSTATUS 0x04
68 #define USB_REQ_DFU_GETSTATE 0x05
69 #define USB_REQ_DFU_ABORT 0x06
70
71 /* DFU_GETSTATUS bStatus values (Section 6.1.2, DFU Rev 1.1) */
72 #define DFU_STATUS_OK 0x00
73 #define DFU_STATUS_errTARGET 0x01
74 #define DFU_STATUS_errFILE 0x02
75 #define DFU_STATUS_errWRITE 0x03
76 #define DFU_STATUS_errERASE 0x04
77 #define DFU_STATUS_errCHECK_ERASED 0x05
78 #define DFU_STATUS_errPROG 0x06
79 #define DFU_STATUS_errVERIFY 0x07
80 #define DFU_STATUS_errADDRESS 0x08
81 #define DFU_STATUS_errNOTDONE 0x09
82 #define DFU_STATUS_errFIRMWARE 0x0a
83 #define DFU_STATUS_errVENDOR 0x0b
84 #define DFU_STATUS_errUSBR 0x0c
85 #define DFU_STATUS_errPOR 0x0d
86 #define DFU_STATUS_errUNKNOWN 0x0e
87 #define DFU_STATUS_errSTALLEDPKT 0x0f
88
89 enum dfu_state {
90 DFU_STATE_appIDLE = 0,
91 DFU_STATE_appDETACH = 1,
92 DFU_STATE_dfuIDLE = 2,
93 DFU_STATE_dfuDNLOAD_SYNC = 3,
94 DFU_STATE_dfuDNBUSY = 4,
95 DFU_STATE_dfuDNLOAD_IDLE = 5,
96 DFU_STATE_dfuMANIFEST_SYNC = 6,
97 DFU_STATE_dfuMANIFEST = 7,
98 DFU_STATE_dfuMANIFEST_WAIT_RST = 8,
99 DFU_STATE_dfuUPLOAD_IDLE = 9,
100 DFU_STATE_dfuERROR = 10
101 };
102
103 #endif /* USB_DFU_H */