~ubuntu-branches/ubuntu/intrepid/bluez/intrepid

« back to all changes in this revision

Viewing changes to tools/dfu.h

  • Committer: Bazaar Package Importer
  • Author(s): Mario Limonciello
  • Date: 2008-10-07 12:10:29 UTC
  • Revision ID: james.westby@ubuntu.com-20081007121029-4gup4fmmh2vfo5nh
Tags: upstream-4.12
ImportĀ upstreamĀ versionĀ 4.12

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 *  BlueZ - Bluetooth protocol stack for Linux
 
4
 *
 
5
 *  Copyright (C) 2003-2008  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 as published by
 
10
 *  the Free Software Foundation; either version 2 of the License, or
 
11
 *  (at your option) any later version.
 
12
 *
 
13
 *  This program is distributed in the hope that it will be useful,
 
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 *  GNU General Public License for more details.
 
17
 *
 
18
 *  You should have received a copy of the GNU General Public License
 
19
 *  along with this program; if not, write to the Free Software
 
20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
21
 *
 
22
 */
 
23
 
 
24
#include <stdint.h>
 
25
 
 
26
/* CRC interface */
 
27
uint32_t crc32_init(void);
 
28
uint32_t crc32_byte(uint32_t accum, uint8_t delta);
 
29
 
 
30
/* DFU descriptor */
 
31
struct usb_dfu_descriptor {
 
32
        u_int8_t  bLength;
 
33
        u_int8_t  bDescriptorType;
 
34
        u_int8_t  bmAttributes;
 
35
        u_int16_t wDetachTimeout;
 
36
        u_int16_t wTransferSize;
 
37
};
 
38
 
 
39
/* DFU commands */
 
40
#define DFU_DETACH              0
 
41
#define DFU_DNLOAD              1
 
42
#define DFU_UPLOAD              2
 
43
#define DFU_GETSTATUS           3
 
44
#define DFU_CLRSTATUS           4
 
45
#define DFU_GETSTATE            5
 
46
#define DFU_ABORT               6
 
47
 
 
48
/* DFU status */
 
49
struct dfu_status {
 
50
        uint8_t bStatus;
 
51
        uint8_t bwPollTimeout[3];
 
52
        uint8_t bState;
 
53
        uint8_t iString;
 
54
} __attribute__ ((packed));
 
55
#define DFU_STATUS_SIZE 6
 
56
 
 
57
/* DFU status */
 
58
#define DFU_OK                  0x00
 
59
#define DFU_ERR_TARGET          0x01
 
60
#define DFU_ERR_FILE            0x02
 
61
#define DFU_ERR_WRITE           0x03
 
62
#define DFU_ERR_ERASE           0x04
 
63
#define DFU_ERR_CHECK_ERASED    0x05
 
64
#define DFU_ERR_PROG            0x06
 
65
#define DFU_ERR_VERIFY          0x07
 
66
#define DFU_ERR_ADDRESS         0x08
 
67
#define DFU_ERR_NOTDONE         0x09
 
68
#define DFU_ERR_FIRMWARE        0x0a
 
69
#define DFU_ERR_VENDOR          0x0b
 
70
#define DFU_ERR_USBR            0x0c
 
71
#define DFU_ERR_POR             0x0d
 
72
#define DFU_ERR_UNKNOWN         0x0e
 
73
#define DFU_ERR_STALLEDPKT      0x0f
 
74
 
 
75
/* DFU state */
 
76
#define DFU_STATE_APP_IDLE              0
 
77
#define DFU_STATE_APP_DETACH            1
 
78
#define DFU_STATE_DFU_IDLE              2
 
79
#define DFU_STATE_DFU_DNLOAD_SYNC       3
 
80
#define DFU_STATE_DFU_DNLOAD_BUSY       4
 
81
#define DFU_STATE_DFU_DNLOAD_IDLE       5
 
82
#define DFU_STATE_DFU_MANIFEST_SYNC     6
 
83
#define DFU_STATE_DFU_MANIFEST          7
 
84
#define DFU_STATE_MANIFEST_WAIT_RESET   8
 
85
#define DFU_STATE_UPLOAD_IDLE           9
 
86
#define DFU_STATE_ERROR                 10
 
87
 
 
88
/* DFU suffix */
 
89
struct dfu_suffix {
 
90
        uint16_t bcdDevice;
 
91
        uint16_t idProduct;
 
92
        uint16_t idVendor;
 
93
        uint16_t bcdDFU;
 
94
        uint8_t  ucDfuSignature[3];
 
95
        uint8_t  bLength;
 
96
        uint32_t dwCRC;
 
97
} __attribute__ ((packed));
 
98
#define DFU_SUFFIX_SIZE 16
 
99
 
 
100
/* DFU interface */
 
101
int dfu_detach(struct usb_dev_handle *udev, int intf);
 
102
int dfu_upload(struct usb_dev_handle *udev, int intf, int block, char *buffer, int size);
 
103
int dfu_download(struct usb_dev_handle *udev, int intf, int block, char *buffer, int size);
 
104
int dfu_get_status(struct usb_dev_handle *udev, int intf, struct dfu_status *status);
 
105
int dfu_clear_status(struct usb_dev_handle *udev, int intf);
 
106
int dfu_get_state(struct usb_dev_handle *udev, int intf, uint8_t *state);
 
107
int dfu_abort(struct usb_dev_handle *udev, int intf);