Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
wusb.h
Go to the documentation of this file.
1 /*
2  * Wireless USB Standard Definitions
3  * Event Size Tables
4  *
5  * Copyright (C) 2005-2006 Intel Corporation
6  * Inaky Perez-Gonzalez <[email protected]>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License version
10  * 2 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
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., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301, USA.
21  *
22  *
23  * FIXME: docs
24  * FIXME: organize properly, group logically
25  *
26  * All the event structures are defined in uwb/spec.h, as they are
27  * common to the WHCI and WUSB radio control interfaces.
28  */
29 
30 #ifndef __WUSB_H__
31 #define __WUSB_H__
32 
33 #include <linux/types.h>
34 #include <linux/kernel.h>
35 #include <linux/uwb/spec.h>
36 #include <linux/usb/ch9.h>
37 #include <linux/param.h>
38 
45 struct wuie_hdr {
48 } __attribute__((packed));
49 
50 enum {
51  WUIE_ID_WCTA = 0x80,
60 };
61 
69 #define WUIE_ELT_MAX 4
70 
79 struct wusb_ckhdid {
80  u8 data[16];
81 } __attribute__((packed));
82 
83 static const struct wusb_ckhdid wusb_ckhdid_zero = { .data = { 0 } };
84 
85 #define WUSB_CKHDID_STRSIZE (3 * sizeof(struct wusb_ckhdid) + 1)
86 
94  struct wuie_hdr hdr;
96  struct wusb_ckhdid CHID;
97 } __attribute__((packed));
98 
106  struct wuie_hdr hdr;
107  struct {
109  u8 bDeviceAddress; /* 0 means unused */
111  } blk[WUIE_ELT_MAX];
112 } __attribute__((packed));
113 
119 enum {
124 };
125 
132  struct wuie_hdr hdr;
135 } __attribute__((packed));
136 
143  struct wuie_hdr hdr;
145 } __attribute__((packed));
146 
156 struct wuie_reset {
157  struct wuie_hdr hdr;
159 } __attribute__((packed));
160 
168  struct wuie_hdr hdr;
171 } __attribute__((packed));
172 
179  struct wuie_hdr hdr;
180 } __attribute__((packed));
181 
185 struct wusb_dn_hdr {
188 } __attribute__((packed));
191 enum WUSB_DN {
199 };
200 
203  struct wusb_dn_hdr hdr;
206 } __attribute__((packed));
207 
208 static inline int wusb_dn_connect_prev_dev_addr(const struct wusb_dn_connect *dn)
209 {
210  return le16_to_cpu(dn->attributes) & 0xff;
211 }
212 
213 static inline int wusb_dn_connect_new_connection(const struct wusb_dn_connect *dn)
214 {
215  return (le16_to_cpu(dn->attributes) >> 8) & 0x1;
216 }
217 
218 static inline int wusb_dn_connect_beacon_behavior(const struct wusb_dn_connect *dn)
219 {
220  return (le16_to_cpu(dn->attributes) >> 9) & 0x03;
221 }
222 
225  struct wusb_dn_hdr hdr;
226 } __attribute__((packed));
227 
230  struct wusb_dn_hdr hdr;
231 } __attribute__((packed));
232 
233 /* General constants */
234 enum {
235  WUSB_TRUST_TIMEOUT_MS = 4000, /* [WUSB] section 4.15.1 */
236 };
237 
238 static inline size_t ckhdid_printf(char *pr_ckhdid, size_t size,
239  const struct wusb_ckhdid *ckhdid)
240 {
241  return scnprintf(pr_ckhdid, size,
242  "%02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx "
243  "%02hx %02hx %02hx %02hx %02hx %02hx %02hx %02hx",
244  ckhdid->data[0], ckhdid->data[1],
245  ckhdid->data[2], ckhdid->data[3],
246  ckhdid->data[4], ckhdid->data[5],
247  ckhdid->data[6], ckhdid->data[7],
248  ckhdid->data[8], ckhdid->data[9],
249  ckhdid->data[10], ckhdid->data[11],
250  ckhdid->data[12], ckhdid->data[13],
251  ckhdid->data[14], ckhdid->data[15]);
252 }
253 
254 /*
255  * WUSB Crypto stuff (WUSB1.0[6])
256  */
257 
258 extern const char *wusb_et_name(u8);
259 
264 static inline u8 wusb_key_index(int index, int type, int originator)
265 {
266  return (originator << 6) | (type << 4) | index;
267 }
268 
269 #define WUSB_KEY_INDEX_TYPE_PTK 0 /* for HWA only */
270 #define WUSB_KEY_INDEX_TYPE_ASSOC 1
271 #define WUSB_KEY_INDEX_TYPE_GTK 2
272 #define WUSB_KEY_INDEX_ORIGINATOR_HOST 0
273 #define WUSB_KEY_INDEX_ORIGINATOR_DEVICE 1
274 
275 /* A CCM Nonce, defined in WUSB1.0[6.4.1] */
277  u8 sfn[6]; /* Little Endian */
278  u8 tkid[3]; /* LE */
281 } __attribute__((packed));
283 /* A CCM operation label, defined on WUSB1.0[6.5.x] */
285  u8 data[14];
286 } __attribute__((packed));
287 
288 /*
289  * Input to the key derivation sequence defined in
290  * WUSB1.0[6.5.1]. Rest of the data is in the CCM Nonce passed to the
291  * PRF function.
292  */
294  u8 hnonce[16];
295  u8 dnonce[16];
296 } __attribute__((packed));
298 /*
299  * Output from the key derivation sequence defined in
300  * WUSB1.0[6.5.1].
301  */
303  u8 kck[16];
304  u8 ptk[16];
305 } __attribute__((packed));
307 /* Pseudo Random Function WUSB1.0[6.5] */
308 extern int wusb_crypto_init(void);
309 extern void wusb_crypto_exit(void);
310 extern ssize_t wusb_prf(void *out, size_t out_size,
311  const u8 key[16], const struct aes_ccm_nonce *_n,
312  const struct aes_ccm_label *a,
313  const void *b, size_t blen, size_t len);
314 
315 static inline int wusb_prf_64(void *out, size_t out_size, const u8 key[16],
316  const struct aes_ccm_nonce *n,
317  const struct aes_ccm_label *a,
318  const void *b, size_t blen)
319 {
320  return wusb_prf(out, out_size, key, n, a, b, blen, 64);
321 }
322 
323 static inline int wusb_prf_128(void *out, size_t out_size, const u8 key[16],
324  const struct aes_ccm_nonce *n,
325  const struct aes_ccm_label *a,
326  const void *b, size_t blen)
327 {
328  return wusb_prf(out, out_size, key, n, a, b, blen, 128);
329 }
330 
331 static inline int wusb_prf_256(void *out, size_t out_size, const u8 key[16],
332  const struct aes_ccm_nonce *n,
333  const struct aes_ccm_label *a,
334  const void *b, size_t blen)
335 {
336  return wusb_prf(out, out_size, key, n, a, b, blen, 256);
337 }
338 
339 /* Key derivation WUSB1.0[6.5.1] */
340 static inline int wusb_key_derive(struct wusb_keydvt_out *keydvt_out,
341  const u8 key[16],
342  const struct aes_ccm_nonce *n,
343  const struct wusb_keydvt_in *keydvt_in)
344 {
345  const struct aes_ccm_label a = { .data = "Pair-wise keys" };
346  return wusb_prf_256(keydvt_out, sizeof(*keydvt_out), key, n, &a,
347  keydvt_in, sizeof(*keydvt_in));
348 }
349 
350 /*
351  * Out-of-band MIC Generation WUSB1.0[6.5.2]
352  *
353  * Compute the MIC over @key, @n and @hs and place it in @mic_out.
354  *
355  * @mic_out: Where to place the 8 byte MIC tag
356  * @key: KCK from the derivation process
357  * @n: CCM nonce, n->sfn == 0, TKID as established in the
358  * process.
359  * @hs: Handshake struct for phase 2 of the 4-way.
360  * hs->bStatus and hs->bReserved are zero.
361  * hs->bMessageNumber is 2 (WUSB1.0[7.3.2.5.2]
362  * hs->dest_addr is the device's USB address padded with 0
363  * hs->src_addr is the hosts's UWB device address
364  * hs->mic is ignored (as we compute that value).
365  */
366 static inline int wusb_oob_mic(u8 mic_out[8], const u8 key[16],
367  const struct aes_ccm_nonce *n,
368  const struct usb_handshake *hs)
369 {
370  const struct aes_ccm_label a = { .data = "out-of-bandMIC" };
371  return wusb_prf_64(mic_out, 8, key, n, &a,
372  hs, sizeof(*hs) - sizeof(hs->MIC));
373 }
374 
375 #endif /* #ifndef __WUSB_H__ */