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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53#ifndef __WUSBHC_H__
54#define __WUSBHC_H__
55
56#include <linux/usb.h>
57#include <linux/list.h>
58#include <linux/mutex.h>
59#include <linux/kref.h>
60#include <linux/workqueue.h>
61#include <linux/usb/hcd.h>
62#include <linux/uwb.h>
63#include <linux/usb/wusb.h>
64
65
66
67
68
69
70
71#define WUSB_CHANNEL_STOP_DELAY_MS 8
72#define WUSB_RETRY_COUNT_MAX 15
73#define WUSB_RETRY_COUNT_INFINITE 0
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96struct wusb_dev {
97 struct kref refcnt;
98 struct wusbhc *wusbhc;
99 struct list_head cack_node;
100 u8 port_idx;
101 u8 addr;
102 u8 beacon_type:4;
103 struct usb_encryption_descriptor ccm1_etd;
104 struct wusb_ckhdid cdid;
105 unsigned long entry_ts;
106 struct usb_bos_descriptor *bos;
107 struct usb_wireless_cap_descriptor *wusb_cap_descr;
108 struct uwb_mas_bm availability;
109 struct work_struct devconnect_acked_work;
110 struct urb *set_gtk_urb;
111 struct usb_ctrlrequest *set_gtk_req;
112 struct usb_device *usb_dev;
113};
114
115#define WUSB_DEV_ADDR_UNAUTH 0x80
116
117static inline void wusb_dev_init(struct wusb_dev *wusb_dev)
118{
119 kref_init(&wusb_dev->refcnt);
120
121}
122
123extern void wusb_dev_destroy(struct kref *_wusb_dev);
124
125static inline struct wusb_dev *wusb_dev_get(struct wusb_dev *wusb_dev)
126{
127 kref_get(&wusb_dev->refcnt);
128 return wusb_dev;
129}
130
131static inline void wusb_dev_put(struct wusb_dev *wusb_dev)
132{
133 kref_put(&wusb_dev->refcnt, wusb_dev_destroy);
134}
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153struct wusb_port {
154 u16 status;
155 u16 change;
156 struct wusb_dev *wusb_dev;
157 u32 ptk_tkid;
158};
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248struct wusbhc {
249 struct usb_hcd usb_hcd;
250 struct device *dev;
251 struct uwb_rc *uwb_rc;
252 struct uwb_pal pal;
253
254 unsigned trust_timeout;
255 struct wusb_ckhdid chid;
256 uint8_t phy_rate;
257 uint8_t dnts_num_slots;
258 uint8_t dnts_interval;
259 uint8_t retry_count;
260 struct wuie_host_info *wuie_host_info;
261
262 struct mutex mutex;
263 u16 cluster_id;
264 struct wusb_port *port;
265 struct wusb_dev_info *dev_info;
266 u8 ports_max;
267 unsigned active:1;
268 struct wuie_keep_alive keep_alive_ie;
269 struct delayed_work keep_alive_timer;
270 struct list_head cack_list;
271 size_t cack_count;
272 struct wuie_connect_ack cack_ie;
273 struct uwb_rsv *rsv;
274
275 struct mutex mmcie_mutex;
276 struct wuie_hdr **mmcie;
277 u8 mmcies_max;
278
279 int (*start)(struct wusbhc *wusbhc);
280 void (*stop)(struct wusbhc *wusbhc, int delay);
281 int (*mmcie_add)(struct wusbhc *wusbhc, u8 interval, u8 repeat_cnt,
282 u8 handle, struct wuie_hdr *wuie);
283 int (*mmcie_rm)(struct wusbhc *wusbhc, u8 handle);
284 int (*dev_info_set)(struct wusbhc *, struct wusb_dev *wusb_dev);
285 int (*bwa_set)(struct wusbhc *wusbhc, s8 stream_index,
286 const struct uwb_mas_bm *);
287 int (*set_ptk)(struct wusbhc *wusbhc, u8 port_idx,
288 u32 tkid, const void *key, size_t key_size);
289 int (*set_gtk)(struct wusbhc *wusbhc,
290 u32 tkid, const void *key, size_t key_size);
291 int (*set_num_dnts)(struct wusbhc *wusbhc, u8 interval, u8 slots);
292
293 struct {
294 struct usb_key_descriptor descr;
295 u8 data[16];
296 } __attribute__((packed)) gtk;
297 u8 gtk_index;
298 u32 gtk_tkid;
299 struct work_struct gtk_rekey_done_work;
300 int pending_set_gtks;
301
302 struct usb_encryption_descriptor *ccm1_etd;
303};
304
305#define usb_hcd_to_wusbhc(u) container_of((u), struct wusbhc, usb_hcd)
306
307
308extern int wusbhc_create(struct wusbhc *);
309extern int wusbhc_b_create(struct wusbhc *);
310extern void wusbhc_b_destroy(struct wusbhc *);
311extern void wusbhc_destroy(struct wusbhc *);
312extern int wusb_dev_sysfs_add(struct wusbhc *, struct usb_device *,
313 struct wusb_dev *);
314extern void wusb_dev_sysfs_rm(struct wusb_dev *);
315extern int wusbhc_sec_create(struct wusbhc *);
316extern int wusbhc_sec_start(struct wusbhc *);
317extern void wusbhc_sec_stop(struct wusbhc *);
318extern void wusbhc_sec_destroy(struct wusbhc *);
319extern void wusbhc_giveback_urb(struct wusbhc *wusbhc, struct urb *urb,
320 int status);
321void wusbhc_reset_all(struct wusbhc *wusbhc);
322
323int wusbhc_pal_register(struct wusbhc *wusbhc);
324void wusbhc_pal_unregister(struct wusbhc *wusbhc);
325
326
327
328
329
330
331
332
333
334static inline struct usb_hcd *usb_hcd_get_by_usb_dev(struct usb_device *usb_dev)
335{
336 struct usb_hcd *usb_hcd;
337 usb_hcd = container_of(usb_dev->bus, struct usb_hcd, self);
338 return usb_get_hcd(usb_hcd);
339}
340
341
342
343
344
345
346static inline struct wusbhc *wusbhc_get(struct wusbhc *wusbhc)
347{
348 return usb_get_hcd(&wusbhc->usb_hcd) ? wusbhc : NULL;
349}
350
351
352
353
354
355
356
357
358
359
360
361static inline struct wusbhc *wusbhc_get_by_usb_dev(struct usb_device *usb_dev)
362{
363 struct wusbhc *wusbhc = NULL;
364 struct usb_hcd *usb_hcd;
365 if (usb_dev->devnum > 1 && !usb_dev->wusb) {
366
367 dev_err(&usb_dev->dev, "devnum %d wusb %d\n", usb_dev->devnum,
368 usb_dev->wusb);
369 BUG_ON(usb_dev->devnum > 1 && !usb_dev->wusb);
370 }
371 usb_hcd = usb_hcd_get_by_usb_dev(usb_dev);
372 if (usb_hcd == NULL)
373 return NULL;
374 BUG_ON(usb_hcd->wireless == 0);
375 return wusbhc = usb_hcd_to_wusbhc(usb_hcd);
376}
377
378
379static inline void wusbhc_put(struct wusbhc *wusbhc)
380{
381 usb_put_hcd(&wusbhc->usb_hcd);
382}
383
384int wusbhc_start(struct wusbhc *wusbhc);
385void wusbhc_stop(struct wusbhc *wusbhc);
386extern int wusbhc_chid_set(struct wusbhc *, const struct wusb_ckhdid *);
387
388
389extern int wusbhc_devconnect_create(struct wusbhc *);
390extern void wusbhc_devconnect_destroy(struct wusbhc *);
391extern int wusbhc_devconnect_start(struct wusbhc *wusbhc);
392extern void wusbhc_devconnect_stop(struct wusbhc *wusbhc);
393extern void wusbhc_handle_dn(struct wusbhc *, u8 srcaddr,
394 struct wusb_dn_hdr *dn_hdr, size_t size);
395extern void __wusbhc_dev_disable(struct wusbhc *wusbhc, u8 port);
396extern int wusb_usb_ncb(struct notifier_block *nb, unsigned long val,
397 void *priv);
398extern int wusb_set_dev_addr(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev,
399 u8 addr);
400
401
402extern int wusbhc_rh_create(struct wusbhc *);
403extern void wusbhc_rh_destroy(struct wusbhc *);
404
405extern int wusbhc_rh_status_data(struct usb_hcd *, char *);
406extern int wusbhc_rh_control(struct usb_hcd *, u16, u16, u16, char *, u16);
407extern int wusbhc_rh_start_port_reset(struct usb_hcd *, unsigned);
408
409
410extern int wusbhc_mmcie_create(struct wusbhc *);
411extern void wusbhc_mmcie_destroy(struct wusbhc *);
412extern int wusbhc_mmcie_set(struct wusbhc *, u8 interval, u8 repeat_cnt,
413 struct wuie_hdr *);
414extern void wusbhc_mmcie_rm(struct wusbhc *, struct wuie_hdr *);
415
416
417int wusbhc_rsv_establish(struct wusbhc *wusbhc);
418void wusbhc_rsv_terminate(struct wusbhc *wusbhc);
419
420
421
422
423
424
425
426
427
428
429
430
431
432extern int wusb_dev_sec_add(struct wusbhc *, struct usb_device *,
433 struct wusb_dev *);
434extern void wusb_dev_sec_rm(struct wusb_dev *) ;
435extern int wusb_dev_4way_handshake(struct wusbhc *, struct wusb_dev *,
436 struct wusb_ckhdid *ck);
437void wusbhc_gtk_rekey(struct wusbhc *wusbhc);
438int wusb_dev_update_address(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev);
439
440
441
442extern u8 wusb_cluster_id_get(void);
443extern void wusb_cluster_id_put(u8);
444
445
446
447
448
449
450
451
452static inline struct wusb_port *wusb_port_by_idx(struct wusbhc *wusbhc,
453 u8 port_idx)
454{
455 return &wusbhc->port[port_idx];
456}
457
458
459
460
461
462
463
464
465
466static inline u8 wusb_port_no_to_idx(u8 port_no)
467{
468 return port_no - 1;
469}
470
471extern struct wusb_dev *__wusb_dev_get_by_usb_dev(struct wusbhc *,
472 struct usb_device *);
473
474
475
476
477
478
479
480
481static inline
482struct wusb_dev *wusb_dev_get_by_usb_dev(struct usb_device *usb_dev)
483{
484 struct wusbhc *wusbhc;
485 struct wusb_dev *wusb_dev;
486 wusbhc = wusbhc_get_by_usb_dev(usb_dev);
487 if (wusbhc == NULL)
488 return NULL;
489 mutex_lock(&wusbhc->mutex);
490 wusb_dev = __wusb_dev_get_by_usb_dev(wusbhc, usb_dev);
491 mutex_unlock(&wusbhc->mutex);
492 wusbhc_put(wusbhc);
493 return wusb_dev;
494}
495
496
497
498extern struct workqueue_struct *wusbd;
499#endif
500