wl_cfg80211.h 14.2 KB
Newer Older
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
/*
 * Copyright (c) 2010 Broadcom Corporation
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef _wl_cfg80211_h_
#define _wl_cfg80211_h_

#define WL_DBG_NONE		0
#define WL_DBG_CONN		(1 << 5)
#define WL_DBG_SCAN		(1 << 4)
#define WL_DBG_TRACE		(1 << 3)
#define WL_DBG_INFO		(1 << 1)
#define WL_DBG_ERR		(1 << 0)
#define WL_DBG_MASK		((WL_DBG_INFO | WL_DBG_ERR | WL_DBG_TRACE) | \
				(WL_DBG_SCAN) | (WL_DBG_CONN))

29
#define	WL_ERR(fmt, ...)					\
30
31
32
do {								\
	if (brcmf_dbg_level & WL_DBG_ERR) {			\
		if (net_ratelimit()) {				\
33
34
			pr_err("ERROR @%s : " fmt,		\
			       __func__, ##__VA_ARGS__);	\
35
36
37
38
		}						\
	}							\
} while (0)

39
#if (defined DEBUG)
40
#define	WL_INFO(fmt, ...)					\
41
42
43
do {								\
	if (brcmf_dbg_level & WL_DBG_INFO) {			\
		if (net_ratelimit()) {				\
44
45
			pr_err("INFO @%s : " fmt,		\
			       __func__, ##__VA_ARGS__);	\
46
47
48
49
		}						\
	}							\
} while (0)

50
#define	WL_TRACE(fmt, ...)					\
51
52
53
do {								\
	if (brcmf_dbg_level & WL_DBG_TRACE) {			\
		if (net_ratelimit()) {				\
54
55
			pr_err("TRACE @%s : " fmt,		\
			       __func__, ##__VA_ARGS__);	\
56
57
58
59
		}						\
	}							\
} while (0)

60
#define	WL_SCAN(fmt, ...)					\
61
62
63
do {								\
	if (brcmf_dbg_level & WL_DBG_SCAN) {			\
		if (net_ratelimit()) {				\
64
65
			pr_err("SCAN @%s : " fmt,		\
			       __func__, ##__VA_ARGS__);	\
66
67
68
69
		}						\
	}							\
} while (0)

70
#define	WL_CONN(fmt, ...)					\
71
72
73
do {								\
	if (brcmf_dbg_level & WL_DBG_CONN) {			\
		if (net_ratelimit()) {				\
74
75
			pr_err("CONN @%s : " fmt,		\
			       __func__, ##__VA_ARGS__);	\
76
77
78
79
		}						\
	}							\
} while (0)

80
#else /* (defined DEBUG) */
81
82
83
84
#define	WL_INFO(fmt, args...)
#define	WL_TRACE(fmt, args...)
#define	WL_SCAN(fmt, args...)
#define	WL_CONN(fmt, args...)
85
#endif /* (defined DEBUG) */
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

#define WL_NUM_SCAN_MAX		1
#define WL_NUM_PMKIDS_MAX	MAXPMKID	/* will be used
						 * for 2.6.33 kernel
						 * or later
						 */
#define WL_SCAN_BUF_MAX			(1024 * 8)
#define WL_TLV_INFO_MAX			1024
#define WL_BSS_INFO_MAX			2048
#define WL_ASSOC_INFO_MAX	512	/*
				 * needs to grab assoc info from dongle to
				 * report it to cfg80211 through "connect"
				 * event
				 */
#define WL_DCMD_LEN_MAX	1024
#define WL_EXTRA_BUF_MAX	2048
#define WL_ISCAN_BUF_MAX	2048	/*
				 * the buf length can be BRCMF_DCMD_MAXLEN
				 * to reduce iteration
				 */
#define WL_ISCAN_TIMER_INTERVAL_MS	3000
#define WL_SCAN_ERSULTS_LAST	(BRCMF_SCAN_RESULTS_NO_MEM+1)
#define WL_AP_MAX	256	/* virtually unlimitted as long
				 * as kernel memory allows
				 */

#define WL_ROAM_TRIGGER_LEVEL		-75
#define WL_ROAM_DELTA			20
#define WL_BEACON_TIMEOUT		3

#define WL_SCAN_CHANNEL_TIME		40
#define WL_SCAN_UNASSOC_TIME		40
#define WL_SCAN_PASSIVE_TIME		120

Hante Meuleman's avatar
Hante Meuleman committed
120
121
122
123
124
125
126
#define WL_ESCAN_BUF_SIZE		(1024 * 64)
#define WL_ESCAN_TIMER_INTERVAL_MS	8000 /* E-Scan timeout */

#define WL_ESCAN_ACTION_START		1
#define WL_ESCAN_ACTION_CONTINUE	2
#define WL_ESCAN_ACTION_ABORT		3

127
#define WL_AUTH_SHARED_KEY		1	/* d11 shared authentication */
Hante Meuleman's avatar
Hante Meuleman committed
128
#define IE_MAX_LEN			512
129

130
131
132
133
134
135
136
137
138
/**
 * enum brcmf_scan_status - dongle scan status
 *
 * @BRCMF_SCAN_STATUS_BUSY: scanning in progress on dongle.
 * @BRCMF_SCAN_STATUS_ABORT: scan being aborted on dongle.
 */
enum brcmf_scan_status {
	BRCMF_SCAN_STATUS_BUSY,
	BRCMF_SCAN_STATUS_ABORT,
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
};

/* wi-fi mode */
enum wl_mode {
	WL_MODE_BSS,
	WL_MODE_IBSS,
	WL_MODE_AP
};

/* dongle profile list */
enum wl_prof_list {
	WL_PROF_MODE,
	WL_PROF_SSID,
	WL_PROF_SEC,
	WL_PROF_IBSS,
	WL_PROF_BAND,
	WL_PROF_BSSID,
	WL_PROF_ACT,
	WL_PROF_BEACONINT,
	WL_PROF_DTIMPERIOD
};

/* dongle iscan state */
enum wl_iscan_state {
	WL_ISCAN_STATE_IDLE,
	WL_ISCAN_STATE_SCANING
};

/* dongle configuration */
struct brcmf_cfg80211_conf {
	u32 mode;		/* adhoc , infrastructure or ap */
	u32 frag_threshold;
	u32 rts_threshold;
	u32 retry_short;
	u32 retry_long;
	s32 tx_power;
	struct ieee80211_channel channel;
};

178
/* forward declaration */
179
struct brcmf_cfg80211_info;
180

181
182
/* cfg80211 main event loop */
struct brcmf_cfg80211_event_loop {
183
	s32(*handler[BRCMF_E_LAST]) (struct brcmf_cfg80211_info *cfg,
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
				     struct net_device *ndev,
				     const struct brcmf_event_msg *e,
				     void *data);
};

/* basic structure of scan request */
struct brcmf_cfg80211_scan_req {
	struct brcmf_ssid_le ssid_le;
};

/* basic structure of information element */
struct brcmf_cfg80211_ie {
	u16 offset;
	u8 buf[WL_TLV_INFO_MAX];
};

/* event queue for cfg80211 main event */
struct brcmf_cfg80211_event_q {
	struct list_head evt_q_list;
	u32 etype;
	struct brcmf_event_msg emsg;
	s8 edata[1];
};

/* security information with currently associated ap */
struct brcmf_cfg80211_security {
	u32 wpa_versions;
	u32 auth_type;
	u32 cipher_pairwise;
	u32 cipher_group;
	u32 wpa_auth;
};

217
218
219
220
221
222
223
/**
 * struct brcmf_cfg80211_profile - profile information.
 *
 * @ssid: ssid of associated/associating ap.
 * @bssid: bssid of joined/joining ibss.
 * @sec: security information.
 */
224
225
226
227
228
229
struct brcmf_cfg80211_profile {
	struct brcmf_ssid ssid;
	u8 bssid[ETH_ALEN];
	struct brcmf_cfg80211_security sec;
};

230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/**
 * enum brcmf_vif_status - bit indices for vif status.
 *
 * @BRCMF_VIF_STATUS_READY: ready for operation.
 * @BRCMF_VIF_STATUS_CONNECTING: connect/join in progress.
 * @BRCMF_VIF_STATUS_CONNECTED: connected/joined succesfully.
 * @BRCMF_VIF_STATUS_AP_CREATING: interface configured for AP operation.
 * @BRCMF_VIF_STATUS_AP_CREATED: AP operation started.
 */
enum brcmf_vif_status {
	BRCMF_VIF_STATUS_READY,
	BRCMF_VIF_STATUS_CONNECTING,
	BRCMF_VIF_STATUS_CONNECTED,
	BRCMF_VIF_STATUS_AP_CREATING,
	BRCMF_VIF_STATUS_AP_CREATED
};

247
248
249
250
251
/**
 * struct brcmf_cfg80211_vif - virtual interface specific information.
 *
 * @ifp: lower layer interface pointer
 * @wdev: wireless device.
252
 * @profile: profile information.
253
254
 * @mode: operating mode.
 * @roam_off: roaming state.
255
 * @sme_state: SME state using enum brcmf_vif_status bits.
256
257
258
259
260
261
 * @pm_block: power-management blocked.
 * @list: linked list.
 */
struct brcmf_cfg80211_vif {
	struct brcmf_if *ifp;
	struct wireless_dev wdev;
262
	struct brcmf_cfg80211_profile profile;
263
264
	s32 mode;
	s32 roam_off;
265
	unsigned long sme_state;
266
267
268
269
	bool pm_block;
	struct list_head list;
};

270
271
272
/* dongle iscan event loop */
struct brcmf_cfg80211_iscan_eloop {
	s32 (*handler[WL_SCAN_ERSULTS_LAST])
273
		(struct brcmf_cfg80211_info *cfg);
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
};

/* dongle iscan controller */
struct brcmf_cfg80211_iscan_ctrl {
	struct net_device *ndev;
	struct timer_list timer;
	u32 timer_ms;
	u32 timer_on;
	s32 state;
	struct work_struct work;
	struct brcmf_cfg80211_iscan_eloop el;
	void *data;
	s8 dcmd_buf[BRCMF_DCMD_SMLEN];
	s8 scan_buf[WL_ISCAN_BUF_MAX];
};

/* association inform */
struct brcmf_cfg80211_connect_info {
	u8 *req_ie;
	s32 req_ie_len;
	u8 *resp_ie;
	s32 resp_ie_len;
};

/* assoc ie length */
299
300
301
struct brcmf_cfg80211_assoc_ielen_le {
	__le32 req_len;
	__le32 resp_len;
302
303
304
305
306
307
308
309
};

/* wpa2 pmk list */
struct brcmf_cfg80211_pmk_list {
	struct pmkid_list pmkids;
	struct pmkid foo[MAXPMKID - 1];
};

Hante Meuleman's avatar
Hante Meuleman committed
310
311
312
313
314
315
316
317
318
319
320
321
322
/* dongle escan state */
enum wl_escan_state {
	WL_ESCAN_STATE_IDLE,
	WL_ESCAN_STATE_SCANNING
};

struct escan_info {
	u32 escan_state;
	u8 escan_buf[WL_ESCAN_BUF_SIZE];
	struct wiphy *wiphy;
	struct net_device *ndev;
};

Hante Meuleman's avatar
Hante Meuleman committed
323
324
325
326
327
328
329
330
331
332
333
/* Structure to hold WPS, WPA IEs for a AP */
struct ap_info {
	u8 probe_res_ie[IE_MAX_LEN];
	u8 beacon_ie[IE_MAX_LEN];
	u32 probe_res_ie_len;
	u32 beacon_ie_len;
	u8 *wpa_ie;
	u8 *rsn_ie;
	bool security_mode;
};

334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
/**
 * struct brcmf_pno_param_le - PNO scan configuration parameters
 *
 * @version: PNO parameters version.
 * @scan_freq: scan frequency.
 * @lost_network_timeout: #sec. to declare discovered network as lost.
 * @flags: Bit field to control features of PFN such as sort criteria auto
 *	enable switch and background scan.
 * @rssi_margin: Margin to avoid jitter for choosing a PFN based on RSSI sort
 *	criteria.
 * @bestn: number of best networks in each scan.
 * @mscan: number of scans recorded.
 * @repeat: minimum number of scan intervals before scan frequency changes
 *	in adaptive scan.
 * @exp: exponent of 2 for maximum scan interval.
 * @slow_freq: slow scan period.
 */
struct brcmf_pno_param_le {
	__le32 version;
	__le32 scan_freq;
	__le32 lost_network_timeout;
	__le16 flags;
	__le16 rssi_margin;
	u8 bestn;
	u8 mscan;
	u8 repeat;
	u8 exp;
	__le32 slow_freq;
};

/**
 * struct brcmf_pno_net_param_le - scan parameters per preferred network.
 *
 * @ssid: ssid name and its length.
 * @flags: bit2: hidden.
 * @infra: BSS vs IBSS.
 * @auth: Open vs Closed.
 * @wpa_auth: WPA type.
 * @wsec: wsec value.
 */
struct brcmf_pno_net_param_le {
	struct brcmf_ssid_le ssid;
	__le32 flags;
	__le32 infra;
	__le32 auth;
	__le32 wpa_auth;
	__le32 wsec;
};

/**
 * struct brcmf_pno_net_info_le - information per found network.
 *
 * @bssid: BSS network identifier.
 * @channel: channel number only.
 * @SSID_len: length of ssid.
 * @SSID: ssid characters.
 * @RSSI: receive signal strength (in dBm).
 * @timestamp: age in seconds.
 */
struct brcmf_pno_net_info_le {
	u8 bssid[ETH_ALEN];
	u8 channel;
	u8 SSID_len;
	u8 SSID[32];
	__le16	RSSI;
	__le16	timestamp;
};

/**
 * struct brcmf_pno_scanresults_le - result returned in PNO NET FOUND event.
 *
 * @version: PNO version identifier.
 * @status: indicates completion status of PNO scan.
 * @count: amount of brcmf_pno_net_info_le entries appended.
 */
struct brcmf_pno_scanresults_le {
	__le32 version;
	__le32 status;
	__le32 count;
};

415
/**
416
 * struct brcmf_cfg80211_info - dongle private data of cfg80211 interface
417
 *
418
 * @wiphy: wiphy object for cfg80211 interface.
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
 * @conf: dongle configuration.
 * @scan_request: cfg80211 scan request object.
 * @el: main event loop.
 * @evt_q_list: used for event queue.
 * @evt_q_lock: for event queue synchronization.
 * @usr_sync: mainly for dongle up/down synchronization.
 * @bss_list: bss_list holding scanned ap information.
 * @scan_results: results of the last scan.
 * @scan_req_int: internal scan request object.
 * @bss_info: bss information for cfg80211 layer.
 * @ie: information element object for internal purpose.
 * @iscan: iscan controller information.
 * @conn_info: association info.
 * @pmk_list: wpa2 pmk list.
 * @event_work: event handler work struct.
434
 * @scan_status: scan activity on the dongle.
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
 * @pub: common driver information.
 * @channel: current channel.
 * @iscan_on: iscan on/off switch.
 * @iscan_kickstart: indicate iscan already started.
 * @active_scan: current scan mode.
 * @sched_escan: e-scan for scheduled scan support running.
 * @ibss_starter: indicates this sta is ibss starter.
 * @link_up: link/connection up flag.
 * @pwr_save: indicate whether dongle to support power save mode.
 * @dongle_up: indicate whether dongle up or not.
 * @roam_on: on/off switch for dongle self-roaming.
 * @scan_tried: indicates if first scan attempted.
 * @dcmd_buf: dcmd buffer.
 * @extra_buf: mainly to grab assoc information.
 * @debugfsdir: debugfs folder for this device.
 * @escan_on: escan on/off switch.
 * @escan_info: escan information.
 * @escan_timeout: Timer for catch scan timeout.
 * @escan_timeout_work: scan timeout worker.
 * @escan_ioctl_buf: dongle command buffer for escan commands.
Hante Meuleman's avatar
Hante Meuleman committed
455
 * @ap_info: host ap information.
456
457
 * @vif_list: linked list of vif instances.
 * @vif_cnt: number of vif instances.
458
 */
459
struct brcmf_cfg80211_info {
460
	struct wiphy *wiphy;
461
462
463
464
465
466
467
	struct brcmf_cfg80211_conf *conf;
	struct cfg80211_scan_request *scan_request;
	struct brcmf_cfg80211_event_loop el;
	struct list_head evt_q_list;
	spinlock_t	 evt_q_lock;
	struct mutex usr_sync;
	struct brcmf_scan_results *bss_list;
468
	struct brcmf_scan_results *scan_results;
469
470
471
472
473
474
475
	struct brcmf_cfg80211_scan_req *scan_req_int;
	struct wl_cfg80211_bss_info *bss_info;
	struct brcmf_cfg80211_ie ie;
	struct brcmf_cfg80211_iscan_ctrl *iscan;
	struct brcmf_cfg80211_connect_info conn_info;
	struct brcmf_cfg80211_pmk_list *pmk_list;
	struct work_struct event_work;
476
	unsigned long scan_status;
477
	struct brcmf_pub *pub;
478
479
480
481
482
483
484
485
486
487
488
489
490
	u32 channel;
	bool iscan_on;
	bool iscan_kickstart;
	bool active_scan;
	bool sched_escan;
	bool ibss_starter;
	bool link_up;
	bool pwr_save;
	bool dongle_up;
	bool roam_on;
	bool scan_tried;
	u8 *dcmd_buf;
	u8 *extra_buf;
491
	struct dentry *debugfsdir;
492
493
494
495
	bool escan_on;
	struct escan_info escan_info;
	struct timer_list escan_timeout;
	struct work_struct escan_timeout_work;
Hante Meuleman's avatar
Hante Meuleman committed
496
	u8 *escan_ioctl_buf;
Hante Meuleman's avatar
Hante Meuleman committed
497
	struct ap_info *ap_info;
498
499
	struct list_head vif_list;
	u8 vif_cnt;
500
501
};

502
static inline struct wiphy *cfg_to_wiphy(struct brcmf_cfg80211_info *cfg)
503
{
504
	return cfg->wiphy;
505
506
}

507
static inline struct brcmf_cfg80211_info *wiphy_to_cfg(struct wiphy *w)
508
{
509
	return (struct brcmf_cfg80211_info *)(wiphy_priv(w));
510
511
}

512
static inline struct brcmf_cfg80211_info *wdev_to_cfg(struct wireless_dev *wd)
513
{
514
	return (struct brcmf_cfg80211_info *)(wdev_priv(wd));
515
516
}

517
518
static inline
struct net_device *cfg_to_ndev(struct brcmf_cfg80211_info *cfg)
519
{
520
521
522
	struct brcmf_cfg80211_vif *vif;
	vif = list_first_entry(&cfg->vif_list, struct brcmf_cfg80211_vif, list);
	return vif->wdev.netdev;
523
524
}

525
static inline struct brcmf_cfg80211_info *ndev_to_cfg(struct net_device *ndev)
526
527
528
529
{
	return wdev_to_cfg(ndev->ieee80211_ptr);
}

530
531
532
533
534
535
static inline struct brcmf_cfg80211_profile *ndev_to_prof(struct net_device *nd)
{
	struct brcmf_if *ifp = netdev_priv(nd);
	return &ifp->vif->profile;
}

536
#define iscan_to_cfg(i) ((struct brcmf_cfg80211_info *)(i->data))
537
538
539
#define cfg_to_iscan(w) (w->iscan)

static inline struct
540
brcmf_cfg80211_connect_info *cfg_to_conn(struct brcmf_cfg80211_info *cfg)
541
542
543
544
{
	return &cfg->conn_info;
}

545
struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr);
546
void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg);
547
548

/* event handler from dongle */
549
550
void brcmf_cfg80211_event(struct net_device *ndev,
			  const struct brcmf_event_msg *e, void *data);
551
552
s32 brcmf_cfg80211_up(struct brcmf_cfg80211_info *cfg);
s32 brcmf_cfg80211_down(struct brcmf_cfg80211_info *cfg);
553
554

#endif				/* _wl_cfg80211_h_ */