fwcutter/make: Avoid _DEFAULT_SOURCE warning
[b43-tools.git] / fwcutter / fwcutter.h
1 #ifndef _FWCUTTER_H_
2 #define _FWCUTTER_H_
3
4 #define FW_FLAG_LE              0x01    /* little endian? convert */
5 #define FW_FLAG_V4              0x02    /* b43 vs. b43legacy */
6 #define FW_FLAG_UNSUPPORTED     0x04    /* not supported/working */
7
8 #define fwcutter_stringify_1(x) #x
9 #define fwcutter_stringify(x)   fwcutter_stringify_1(x)
10 #define FWCUTTER_VERSION        fwcutter_stringify(FWCUTTER_VERSION_)
11
12 #undef ARRAY_SIZE
13 #define ARRAY_SIZE(array)       (sizeof(array) / sizeof((array)[0]))
14
15 typedef uint16_t be16_t; /* Big-endian 16bit */
16 typedef uint32_t be32_t; /* Big-endian 32bit */
17
18 typedef uint32_t le32_t; /* Little-endian 32bit */
19
20 #if defined(__DragonFly__) || defined(__FreeBSD__)
21 #define bswap_16        bswap16
22 #define bswap_32        bswap32
23 #elif defined(__APPLE__)
24 #define bswap_16        OSSwapInt16
25 #define bswap_32        OSSwapInt32
26 #endif
27
28 #define ARG_MATCH       0
29 #define ARG_NOMATCH     1
30 #define ARG_ERROR       -1
31
32 enum fwcutter_mode {
33         FWCM_EXTRACT_B43 = 0,   /* default */
34         FWCM_LIST,
35         FWCM_IDENTIFY,
36         FWCM_EXTRACT_BRCMSMAC,
37 };
38
39 struct cmdline_args {
40         const char *infile;
41         const char *target_dir;
42         enum fwcutter_mode mode;
43         int unsupported;
44 };
45
46 struct insn {
47         uint32_t opcode;
48         uint16_t op1, op2, op3;
49 };
50
51 /* The IV how it's done in the binary driver files. */
52 struct iv {
53         be16_t reg, size;
54         be32_t val;
55 } __attribute__((__packed__));
56
57 enum extract_type {
58         EXT_UNDEFINED, /* error catcher  */
59         EXT_UCODE_1,   /* rev  <= 4 ucode */
60         EXT_UCODE_2,   /* rev 5..14 ucode */
61         EXT_UCODE_3,   /* rev >= 15 ucode */
62         EXT_PCM,       /* "pcm" values   */
63         EXT_IV,        /* initial values */
64 };
65
66 struct extract {
67         const char *name;
68         const uint32_t offset;
69         const uint32_t length;
70         const enum extract_type type;
71 };
72
73 #define EXTRACT_LIST_END { .name = NULL, }
74
75 struct file {
76         const char *name;
77         const char *ucode_version;
78         const char *md5;
79         const struct extract *extract;
80         const uint32_t flags;
81 };
82
83 /* The header that's put in to every .fw file */
84 struct fw_header {
85         /* Type of the firmware data */
86         uint8_t type;
87         /* Version number of the firmware data format */
88         uint8_t ver;
89         uint8_t __padding[2];
90         /* Size of the data. For ucode and PCM this is in bytes.
91          * For IV this is in number-of-ivs. */
92         be32_t size;
93 } __attribute__((__packed__));
94
95 #define FW_TYPE_UCODE   'u'
96 #define FW_TYPE_PCM     'p'
97 #define FW_TYPE_IV      'i'
98
99 #define FW_HDR_VER      0x01
100
101 /* The IV in the .fw file */
102 struct b43_iv {
103         be16_t offset_size;
104         union {
105                 be16_t d16;
106                 be32_t d32;
107         } data __attribute__((__packed__));
108 } __attribute__((__packed__));
109
110 #define FW_IV_OFFSET_MASK       0x7FFF
111 #define FW_IV_32BIT             0x8000
112
113 /* header format for brcmsmac firmware */
114 struct firmware_hdr {
115         le32_t offset;
116         le32_t len;
117         le32_t idx;
118 };
119
120 /* numbers of firmware types for brcmsmac firmware */
121 enum firmware_brcmsmac {
122         D11UCODE_NAMETAG_START = 0,
123         D11LCN0BSINITVALS24,
124         D11LCN0INITVALS24,
125         D11LCN1BSINITVALS24,
126         D11LCN1INITVALS24,
127         D11LCN2BSINITVALS24,
128         D11LCN2INITVALS24,
129         D11N0ABSINITVALS16,
130         D11N0BSINITVALS16,
131         D11N0INITVALS16,
132         D11UCODE_OVERSIGHT16_MIMO,
133         D11UCODE_OVERSIGHT16_MIMOSZ,
134         D11UCODE_OVERSIGHT24_LCN,
135         D11UCODE_OVERSIGHT24_LCNSZ,
136         D11UCODE_OVERSIGHT_BOMMAJOR,
137         D11UCODE_OVERSIGHT_BOMMINOR
138 };
139
140 #endif /* _FWCUTTER_H_ */