dfu.h revision 1514cc3fbace6793f002737b08f9cfcb140bed70
1/* 2 * 3 * BlueZ - Bluetooth protocol stack for Linux 4 * 5 * Copyright (C) 2003-2005 Marcel Holtmann <marcel@holtmann.org> 6 * 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License version 2 as 10 * published by the Free Software Foundation; 11 * 12 * Software distributed under the License is distributed on an "AS 13 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 14 * implied. See the License for the specific language governing 15 * rights and limitations under the License. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 * 21 * 22 * $Id$ 23 */ 24 25#include <stdint.h> 26 27/* CRC interface */ 28uint32_t crc32_init(void); 29uint32_t crc32_byte(uint32_t accum, uint8_t delta); 30 31/* DFU descriptor */ 32struct usb_dfu_descriptor { 33 u_int8_t bLength; 34 u_int8_t bDescriptorType; 35 u_int8_t bmAttributes; 36 u_int16_t wDetachTimeout; 37 u_int16_t wTransferSize; 38}; 39 40/* DFU commands */ 41#define DFU_DETACH 0 42#define DFU_DNLOAD 1 43#define DFU_UPLOAD 2 44#define DFU_GETSTATUS 3 45#define DFU_CLRSTATUS 4 46#define DFU_GETSTATE 5 47#define DFU_ABORT 6 48 49/* DFU status */ 50struct dfu_status { 51 uint8_t bStatus; 52 uint8_t bwPollTimeout[3]; 53 uint8_t bState; 54 uint8_t iString; 55} __attribute__ ((packed)); 56#define DFU_STATUS_SIZE 6 57 58/* DFU status */ 59#define DFU_OK 0x00 60#define DFU_ERR_TARGET 0x01 61#define DFU_ERR_FILE 0x02 62#define DFU_ERR_WRITE 0x03 63#define DFU_ERR_ERASE 0x04 64#define DFU_ERR_CHECK_ERASED 0x05 65#define DFU_ERR_PROG 0x06 66#define DFU_ERR_VERIFY 0x07 67#define DFU_ERR_ADDRESS 0x08 68#define DFU_ERR_NOTDONE 0x09 69#define DFU_ERR_FIRMWARE 0x0a 70#define DFU_ERR_VENDOR 0x0b 71#define DFU_ERR_USBR 0x0c 72#define DFU_ERR_POR 0x0d 73#define DFU_ERR_UNKNOWN 0x0e 74#define DFU_ERR_STALLEDPKT 0x0f 75 76/* DFU state */ 77#define DFU_STATE_APP_IDLE 0 78#define DFU_STATE_APP_DETACH 1 79#define DFU_STATE_DFU_IDLE 2 80#define DFU_STATE_DFU_DNLOAD_SYNC 3 81#define DFU_STATE_DFU_DNLOAD_BUSY 4 82#define DFU_STATE_DFU_DNLOAD_IDLE 5 83#define DFU_STATE_DFU_MANIFEST_SYNC 6 84#define DFU_STATE_DFU_MANIFEST 7 85#define DFU_STATE_MANIFEST_WAIT_RESET 8 86#define DFU_STATE_UPLOAD_IDLE 9 87#define DFU_STATE_ERROR 10 88 89/* DFU suffix */ 90struct dfu_suffix { 91 uint16_t bcdDevice; 92 uint16_t idProduct; 93 uint16_t idVendor; 94 uint16_t bcdDFU; 95 uint8_t ucDfuSignature[3]; 96 uint8_t bLength; 97 uint32_t dwCRC; 98} __attribute__ ((packed)); 99#define DFU_SUFFIX_SIZE 16 100 101/* DFU interface */ 102int dfu_detach(struct usb_dev_handle *udev, int intf); 103int dfu_upload(struct usb_dev_handle *udev, int intf, int block, unsigned char *buffer, int size); 104int dfu_download(struct usb_dev_handle *udev, int intf, int block, unsigned char *buffer, int size); 105int dfu_get_status(struct usb_dev_handle *udev, int intf, struct dfu_status *status); 106int dfu_clear_status(struct usb_dev_handle *udev, int intf); 107int dfu_get_state(struct usb_dev_handle *udev, int intf, uint8_t *state); 108int dfu_abort(struct usb_dev_handle *udev, int intf); 109