This source file includes following definitions.
- wusb_dn_connect_prev_dev_addr
- wusb_dn_connect_new_connection
- wusb_dn_connect_beacon_behavior
- wusb_key_index
- wusb_prf_64
- wusb_prf_128
- wusb_prf_256
- wusb_key_derive
- wusb_oob_mic
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 #ifndef __WUSB_H__
32 #define __WUSB_H__
33
34 #include <linux/types.h>
35 #include <linux/kernel.h>
36 #include <linux/usb/ch9.h>
37 #include <linux/param.h>
38 #include "../../uwb/include/spec.h"
39
40
41
42
43
44
45
46 struct wuie_hdr {
47 u8 bLength;
48 u8 bIEIdentifier;
49 } __attribute__((packed));
50
51 enum {
52 WUIE_ID_WCTA = 0x80,
53 WUIE_ID_CONNECTACK,
54 WUIE_ID_HOST_INFO,
55 WUIE_ID_CHANGE_ANNOUNCE,
56 WUIE_ID_DEVICE_DISCONNECT,
57 WUIE_ID_HOST_DISCONNECT,
58 WUIE_ID_KEEP_ALIVE = 0x89,
59 WUIE_ID_ISOCH_DISCARD,
60 WUIE_ID_RESET_DEVICE,
61 };
62
63
64
65
66
67
68
69
70 #define WUIE_ELT_MAX 4
71
72
73
74
75
76
77
78
79
80 struct wusb_ckhdid {
81 u8 data[16];
82 } __attribute__((packed));
83
84 static const struct wusb_ckhdid wusb_ckhdid_zero = { .data = { 0 } };
85
86 #define WUSB_CKHDID_STRSIZE (3 * sizeof(struct wusb_ckhdid) + 1)
87
88
89
90
91
92
93
94 struct wuie_host_info {
95 struct wuie_hdr hdr;
96 __le16 attributes;
97 struct wusb_ckhdid CHID;
98 } __attribute__((packed));
99
100
101
102
103
104
105
106 struct wuie_connect_ack {
107 struct wuie_hdr hdr;
108 struct {
109 struct wusb_ckhdid CDID;
110 u8 bDeviceAddress;
111 u8 bReserved;
112 } blk[WUIE_ELT_MAX];
113 } __attribute__((packed));
114
115
116
117
118
119
120 enum {
121 WUIE_HI_CAP_RECONNECT = 0,
122 WUIE_HI_CAP_LIMITED,
123 WUIE_HI_CAP_RESERVED,
124 WUIE_HI_CAP_ALL,
125 };
126
127
128
129
130
131
132 struct wuie_channel_stop {
133 struct wuie_hdr hdr;
134 u8 attributes;
135 u8 timestamp[3];
136 } __attribute__((packed));
137
138
139
140
141
142
143 struct wuie_keep_alive {
144 struct wuie_hdr hdr;
145 u8 bDeviceAddress[WUIE_ELT_MAX];
146 } __attribute__((packed));
147
148
149
150
151
152
153
154
155
156
157 struct wuie_reset {
158 struct wuie_hdr hdr;
159 struct wusb_ckhdid CDID;
160 } __attribute__((packed));
161
162
163
164
165
166
167
168 struct wuie_disconnect {
169 struct wuie_hdr hdr;
170 u8 bDeviceAddress;
171 u8 padding;
172 } __attribute__((packed));
173
174
175
176
177
178
179 struct wuie_host_disconnect {
180 struct wuie_hdr hdr;
181 } __attribute__((packed));
182
183
184
185
186 struct wusb_dn_hdr {
187 u8 bType;
188 u8 notifdata[];
189 } __attribute__((packed));
190
191
192 enum WUSB_DN {
193 WUSB_DN_CONNECT = 0x01,
194 WUSB_DN_DISCONNECT = 0x02,
195 WUSB_DN_EPRDY = 0x03,
196 WUSB_DN_MASAVAILCHANGED = 0x04,
197 WUSB_DN_RWAKE = 0x05,
198 WUSB_DN_SLEEP = 0x06,
199 WUSB_DN_ALIVE = 0x07,
200 };
201
202
203 struct wusb_dn_connect {
204 struct wusb_dn_hdr hdr;
205 __le16 attributes;
206 struct wusb_ckhdid CDID;
207 } __attribute__((packed));
208
209 static inline int wusb_dn_connect_prev_dev_addr(const struct wusb_dn_connect *dn)
210 {
211 return le16_to_cpu(dn->attributes) & 0xff;
212 }
213
214 static inline int wusb_dn_connect_new_connection(const struct wusb_dn_connect *dn)
215 {
216 return (le16_to_cpu(dn->attributes) >> 8) & 0x1;
217 }
218
219 static inline int wusb_dn_connect_beacon_behavior(const struct wusb_dn_connect *dn)
220 {
221 return (le16_to_cpu(dn->attributes) >> 9) & 0x03;
222 }
223
224
225 struct wusb_dn_alive {
226 struct wusb_dn_hdr hdr;
227 } __attribute__((packed));
228
229
230 struct wusb_dn_disconnect {
231 struct wusb_dn_hdr hdr;
232 } __attribute__((packed));
233
234
235 enum {
236 WUSB_TRUST_TIMEOUT_MS = 4000,
237 };
238
239
240
241
242
243 extern const char *wusb_et_name(u8);
244
245
246
247
248
249 static inline u8 wusb_key_index(int index, int type, int originator)
250 {
251 return (originator << 6) | (type << 4) | index;
252 }
253
254 #define WUSB_KEY_INDEX_TYPE_PTK 0
255 #define WUSB_KEY_INDEX_TYPE_ASSOC 1
256 #define WUSB_KEY_INDEX_TYPE_GTK 2
257 #define WUSB_KEY_INDEX_ORIGINATOR_HOST 0
258 #define WUSB_KEY_INDEX_ORIGINATOR_DEVICE 1
259
260 #define WUSB_KEY_INDEX_MAX 15
261
262
263 struct aes_ccm_nonce {
264 u8 sfn[6];
265 u8 tkid[3];
266 struct uwb_dev_addr dest_addr;
267 struct uwb_dev_addr src_addr;
268 } __attribute__((packed));
269
270
271 struct aes_ccm_label {
272 u8 data[14];
273 } __attribute__((packed));
274
275
276
277
278
279
280 struct wusb_keydvt_in {
281 u8 hnonce[16];
282 u8 dnonce[16];
283 } __attribute__((packed));
284
285
286
287
288
289 struct wusb_keydvt_out {
290 u8 kck[16];
291 u8 ptk[16];
292 } __attribute__((packed));
293
294
295 extern int wusb_crypto_init(void);
296 extern void wusb_crypto_exit(void);
297 extern ssize_t wusb_prf(void *out, size_t out_size,
298 const u8 key[16], const struct aes_ccm_nonce *_n,
299 const struct aes_ccm_label *a,
300 const void *b, size_t blen, size_t len);
301
302 static inline int wusb_prf_64(void *out, size_t out_size, const u8 key[16],
303 const struct aes_ccm_nonce *n,
304 const struct aes_ccm_label *a,
305 const void *b, size_t blen)
306 {
307 return wusb_prf(out, out_size, key, n, a, b, blen, 64);
308 }
309
310 static inline int wusb_prf_128(void *out, size_t out_size, const u8 key[16],
311 const struct aes_ccm_nonce *n,
312 const struct aes_ccm_label *a,
313 const void *b, size_t blen)
314 {
315 return wusb_prf(out, out_size, key, n, a, b, blen, 128);
316 }
317
318 static inline int wusb_prf_256(void *out, size_t out_size, const u8 key[16],
319 const struct aes_ccm_nonce *n,
320 const struct aes_ccm_label *a,
321 const void *b, size_t blen)
322 {
323 return wusb_prf(out, out_size, key, n, a, b, blen, 256);
324 }
325
326
327 static inline int wusb_key_derive(struct wusb_keydvt_out *keydvt_out,
328 const u8 key[16],
329 const struct aes_ccm_nonce *n,
330 const struct wusb_keydvt_in *keydvt_in)
331 {
332 const struct aes_ccm_label a = { .data = "Pair-wise keys" };
333 return wusb_prf_256(keydvt_out, sizeof(*keydvt_out), key, n, &a,
334 keydvt_in, sizeof(*keydvt_in));
335 }
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353 static inline int wusb_oob_mic(u8 mic_out[8], const u8 key[16],
354 const struct aes_ccm_nonce *n,
355 const struct usb_handshake *hs)
356 {
357 const struct aes_ccm_label a = { .data = "out-of-bandMIC" };
358 return wusb_prf_64(mic_out, 8, key, n, &a,
359 hs, sizeof(*hs) - sizeof(hs->MIC));
360 }
361
362 #endif