2 * Copyright (c) 2010 Broadcom Corporation
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #ifndef _wl_cfg80211_h_
18 #define _wl_cfg80211_h_
21 #define WL_DBG_CONN (1 << 5)
22 #define WL_DBG_SCAN (1 << 4)
23 #define WL_DBG_TRACE (1 << 3)
24 #define WL_DBG_INFO (1 << 1)
25 #define WL_DBG_ERR (1 << 0)
26 #define WL_DBG_MASK ((WL_DBG_INFO | WL_DBG_ERR | WL_DBG_TRACE) | \
27 (WL_DBG_SCAN) | (WL_DBG_CONN))
29 #define WL_ERR(fmt, ...) \
31 if (brcmf_dbg_level & WL_DBG_ERR) { \
32 if (net_ratelimit()) { \
33 pr_err("ERROR @%s : " fmt, \
34 __func__, ##__VA_ARGS__); \
40 #define WL_INFO(fmt, ...) \
42 if (brcmf_dbg_level & WL_DBG_INFO) { \
43 if (net_ratelimit()) { \
44 pr_err("INFO @%s : " fmt, \
45 __func__, ##__VA_ARGS__); \
50 #define WL_TRACE(fmt, ...) \
52 if (brcmf_dbg_level & WL_DBG_TRACE) { \
53 if (net_ratelimit()) { \
54 pr_err("TRACE @%s : " fmt, \
55 __func__, ##__VA_ARGS__); \
60 #define WL_SCAN(fmt, ...) \
62 if (brcmf_dbg_level & WL_DBG_SCAN) { \
63 if (net_ratelimit()) { \
64 pr_err("SCAN @%s : " fmt, \
65 __func__, ##__VA_ARGS__); \
70 #define WL_CONN(fmt, ...) \
72 if (brcmf_dbg_level & WL_DBG_CONN) { \
73 if (net_ratelimit()) { \
74 pr_err("CONN @%s : " fmt, \
75 __func__, ##__VA_ARGS__); \
80 #else /* (defined DEBUG) */
81 #define WL_INFO(fmt, args...)
82 #define WL_TRACE(fmt, args...)
83 #define WL_SCAN(fmt, args...)
84 #define WL_CONN(fmt, args...)
85 #endif /* (defined DEBUG) */
87 #define WL_NUM_SCAN_MAX 1
88 #define WL_NUM_PMKIDS_MAX MAXPMKID /* will be used
92 #define WL_SCAN_BUF_MAX (1024 * 8)
93 #define WL_TLV_INFO_MAX 1024
94 #define WL_BSS_INFO_MAX 2048
95 #define WL_ASSOC_INFO_MAX 512 /*
96 * needs to grab assoc info from dongle to
97 * report it to cfg80211 through "connect"
100 #define WL_DCMD_LEN_MAX 1024
101 #define WL_EXTRA_BUF_MAX 2048
102 #define WL_ISCAN_BUF_MAX 2048 /*
103 * the buf length can be BRCMF_DCMD_MAXLEN
104 * to reduce iteration
106 #define WL_ISCAN_TIMER_INTERVAL_MS 3000
107 #define WL_SCAN_ERSULTS_LAST (BRCMF_SCAN_RESULTS_NO_MEM+1)
108 #define WL_AP_MAX 256 /* virtually unlimitted as long
109 * as kernel memory allows
112 #define WL_ROAM_TRIGGER_LEVEL -75
113 #define WL_ROAM_DELTA 20
114 #define WL_BEACON_TIMEOUT 3
116 #define WL_SCAN_CHANNEL_TIME 40
117 #define WL_SCAN_UNASSOC_TIME 40
118 #define WL_SCAN_PASSIVE_TIME 120
120 #define WL_ESCAN_BUF_SIZE (1024 * 64)
121 #define WL_ESCAN_TIMER_INTERVAL_MS 8000 /* E-Scan timeout */
123 #define WL_ESCAN_ACTION_START 1
124 #define WL_ESCAN_ACTION_CONTINUE 2
125 #define WL_ESCAN_ACTION_ABORT 3
127 #define WL_AUTH_SHARED_KEY 1 /* d11 shared authentication */
128 #define IE_MAX_LEN 512
131 * enum brcmf_scan_status - dongle scan status
133 * @BRCMF_SCAN_STATUS_BUSY: scanning in progress on dongle.
134 * @BRCMF_SCAN_STATUS_ABORT: scan being aborted on dongle.
136 enum brcmf_scan_status
{
137 BRCMF_SCAN_STATUS_BUSY
,
138 BRCMF_SCAN_STATUS_ABORT
,
148 /* dongle profile list */
161 /* dongle iscan state */
162 enum wl_iscan_state
{
164 WL_ISCAN_STATE_SCANING
167 /* dongle configuration */
168 struct brcmf_cfg80211_conf
{
169 u32 mode
; /* adhoc , infrastructure or ap */
175 struct ieee80211_channel channel
;
178 /* forward declaration */
179 struct brcmf_cfg80211_info
;
181 /* cfg80211 main event loop */
182 struct brcmf_cfg80211_event_loop
{
183 s32(*handler
[BRCMF_E_LAST
]) (struct brcmf_cfg80211_info
*cfg
,
184 struct net_device
*ndev
,
185 const struct brcmf_event_msg
*e
,
189 /* basic structure of scan request */
190 struct brcmf_cfg80211_scan_req
{
191 struct brcmf_ssid_le ssid_le
;
194 /* basic structure of information element */
195 struct brcmf_cfg80211_ie
{
197 u8 buf
[WL_TLV_INFO_MAX
];
200 /* event queue for cfg80211 main event */
201 struct brcmf_cfg80211_event_q
{
202 struct list_head evt_q_list
;
204 struct brcmf_event_msg emsg
;
208 /* security information with currently associated ap */
209 struct brcmf_cfg80211_security
{
217 /* ibss information for currently joined ibss network */
218 struct brcmf_cfg80211_ibss
{
219 u8 beacon_interval
; /* in millisecond */
220 u8 atim
; /* in millisecond */
227 struct brcmf_cfg80211_profile
{
229 struct brcmf_ssid ssid
;
233 struct brcmf_cfg80211_security sec
;
234 struct brcmf_cfg80211_ibss ibss
;
239 * enum brcmf_vif_status - bit indices for vif status.
241 * @BRCMF_VIF_STATUS_READY: ready for operation.
242 * @BRCMF_VIF_STATUS_CONNECTING: connect/join in progress.
243 * @BRCMF_VIF_STATUS_CONNECTED: connected/joined succesfully.
244 * @BRCMF_VIF_STATUS_AP_CREATING: interface configured for AP operation.
245 * @BRCMF_VIF_STATUS_AP_CREATED: AP operation started.
247 enum brcmf_vif_status
{
248 BRCMF_VIF_STATUS_READY
,
249 BRCMF_VIF_STATUS_CONNECTING
,
250 BRCMF_VIF_STATUS_CONNECTED
,
251 BRCMF_VIF_STATUS_AP_CREATING
,
252 BRCMF_VIF_STATUS_AP_CREATED
256 * struct brcmf_cfg80211_vif - virtual interface specific information.
258 * @ifp: lower layer interface pointer
259 * @wdev: wireless device.
260 * @profile: profile information.
261 * @mode: operating mode.
262 * @roam_off: roaming state.
263 * @sme_state: SME state using enum brcmf_vif_status bits.
264 * @pm_block: power-management blocked.
265 * @list: linked list.
267 struct brcmf_cfg80211_vif
{
268 struct brcmf_if
*ifp
;
269 struct wireless_dev wdev
;
270 struct brcmf_cfg80211_profile profile
;
273 unsigned long sme_state
;
275 struct list_head list
;
278 /* dongle iscan event loop */
279 struct brcmf_cfg80211_iscan_eloop
{
280 s32 (*handler
[WL_SCAN_ERSULTS_LAST
])
281 (struct brcmf_cfg80211_info
*cfg
);
284 /* dongle iscan controller */
285 struct brcmf_cfg80211_iscan_ctrl
{
286 struct net_device
*ndev
;
287 struct timer_list timer
;
291 struct work_struct work
;
292 struct brcmf_cfg80211_iscan_eloop el
;
294 s8 dcmd_buf
[BRCMF_DCMD_SMLEN
];
295 s8 scan_buf
[WL_ISCAN_BUF_MAX
];
298 /* association inform */
299 struct brcmf_cfg80211_connect_info
{
306 /* assoc ie length */
307 struct brcmf_cfg80211_assoc_ielen_le
{
313 struct brcmf_cfg80211_pmk_list
{
314 struct pmkid_list pmkids
;
315 struct pmkid foo
[MAXPMKID
- 1];
318 /* dongle escan state */
319 enum wl_escan_state
{
321 WL_ESCAN_STATE_SCANNING
326 u8 escan_buf
[WL_ESCAN_BUF_SIZE
];
328 struct net_device
*ndev
;
331 /* Structure to hold WPS, WPA IEs for a AP */
333 u8 probe_res_ie
[IE_MAX_LEN
];
334 u8 beacon_ie
[IE_MAX_LEN
];
335 u32 probe_res_ie_len
;
343 * struct brcmf_pno_param_le - PNO scan configuration parameters
345 * @version: PNO parameters version.
346 * @scan_freq: scan frequency.
347 * @lost_network_timeout: #sec. to declare discovered network as lost.
348 * @flags: Bit field to control features of PFN such as sort criteria auto
349 * enable switch and background scan.
350 * @rssi_margin: Margin to avoid jitter for choosing a PFN based on RSSI sort
352 * @bestn: number of best networks in each scan.
353 * @mscan: number of scans recorded.
354 * @repeat: minimum number of scan intervals before scan frequency changes
356 * @exp: exponent of 2 for maximum scan interval.
357 * @slow_freq: slow scan period.
359 struct brcmf_pno_param_le
{
362 __le32 lost_network_timeout
;
373 * struct brcmf_pno_net_param_le - scan parameters per preferred network.
375 * @ssid: ssid name and its length.
376 * @flags: bit2: hidden.
377 * @infra: BSS vs IBSS.
378 * @auth: Open vs Closed.
379 * @wpa_auth: WPA type.
382 struct brcmf_pno_net_param_le
{
383 struct brcmf_ssid_le ssid
;
392 * struct brcmf_pno_net_info_le - information per found network.
394 * @bssid: BSS network identifier.
395 * @channel: channel number only.
396 * @SSID_len: length of ssid.
397 * @SSID: ssid characters.
398 * @RSSI: receive signal strength (in dBm).
399 * @timestamp: age in seconds.
401 struct brcmf_pno_net_info_le
{
411 * struct brcmf_pno_scanresults_le - result returned in PNO NET FOUND event.
413 * @version: PNO version identifier.
414 * @status: indicates completion status of PNO scan.
415 * @count: amount of brcmf_pno_net_info_le entries appended.
417 struct brcmf_pno_scanresults_le
{
424 * struct brcmf_cfg80211_info - dongle private data of cfg80211 interface
426 * @wiphy: wiphy object for cfg80211 interface.
427 * @conf: dongle configuration.
428 * @scan_request: cfg80211 scan request object.
429 * @el: main event loop.
430 * @evt_q_list: used for event queue.
431 * @evt_q_lock: for event queue synchronization.
432 * @usr_sync: mainly for dongle up/down synchronization.
433 * @bss_list: bss_list holding scanned ap information.
434 * @scan_results: results of the last scan.
435 * @scan_req_int: internal scan request object.
436 * @bss_info: bss information for cfg80211 layer.
437 * @ie: information element object for internal purpose.
438 * @iscan: iscan controller information.
439 * @conn_info: association info.
440 * @pmk_list: wpa2 pmk list.
441 * @event_work: event handler work struct.
442 * @scan_status: scan activity on the dongle.
443 * @pub: common driver information.
444 * @channel: current channel.
445 * @iscan_on: iscan on/off switch.
446 * @iscan_kickstart: indicate iscan already started.
447 * @active_scan: current scan mode.
448 * @sched_escan: e-scan for scheduled scan support running.
449 * @ibss_starter: indicates this sta is ibss starter.
450 * @link_up: link/connection up flag.
451 * @pwr_save: indicate whether dongle to support power save mode.
452 * @dongle_up: indicate whether dongle up or not.
453 * @roam_on: on/off switch for dongle self-roaming.
454 * @scan_tried: indicates if first scan attempted.
455 * @dcmd_buf: dcmd buffer.
456 * @extra_buf: mainly to grab assoc information.
457 * @debugfsdir: debugfs folder for this device.
458 * @escan_on: escan on/off switch.
459 * @escan_info: escan information.
460 * @escan_timeout: Timer for catch scan timeout.
461 * @escan_timeout_work: scan timeout worker.
462 * @escan_ioctl_buf: dongle command buffer for escan commands.
463 * @ap_info: host ap information.
464 * @vif_list: linked list of vif instances.
465 * @vif_cnt: number of vif instances.
467 struct brcmf_cfg80211_info
{
469 struct brcmf_cfg80211_conf
*conf
;
470 struct cfg80211_scan_request
*scan_request
;
471 struct brcmf_cfg80211_event_loop el
;
472 struct list_head evt_q_list
;
473 spinlock_t evt_q_lock
;
474 struct mutex usr_sync
;
475 struct brcmf_scan_results
*bss_list
;
476 struct brcmf_scan_results
*scan_results
;
477 struct brcmf_cfg80211_scan_req
*scan_req_int
;
478 struct wl_cfg80211_bss_info
*bss_info
;
479 struct brcmf_cfg80211_ie ie
;
480 struct brcmf_cfg80211_iscan_ctrl
*iscan
;
481 struct brcmf_cfg80211_connect_info conn_info
;
482 struct brcmf_cfg80211_pmk_list
*pmk_list
;
483 struct work_struct event_work
;
484 unsigned long scan_status
;
485 struct brcmf_pub
*pub
;
488 bool iscan_kickstart
;
499 struct dentry
*debugfsdir
;
501 struct escan_info escan_info
;
502 struct timer_list escan_timeout
;
503 struct work_struct escan_timeout_work
;
505 struct ap_info
*ap_info
;
506 struct list_head vif_list
;
510 static inline struct wiphy
*cfg_to_wiphy(struct brcmf_cfg80211_info
*cfg
)
515 static inline struct brcmf_cfg80211_info
*wiphy_to_cfg(struct wiphy
*w
)
517 return (struct brcmf_cfg80211_info
*)(wiphy_priv(w
));
520 static inline struct brcmf_cfg80211_info
*wdev_to_cfg(struct wireless_dev
*wd
)
522 return (struct brcmf_cfg80211_info
*)(wdev_priv(wd
));
526 struct net_device
*cfg_to_ndev(struct brcmf_cfg80211_info
*cfg
)
528 struct brcmf_cfg80211_vif
*vif
;
529 vif
= list_first_entry(&cfg
->vif_list
, struct brcmf_cfg80211_vif
, list
);
530 return vif
->wdev
.netdev
;
533 static inline struct brcmf_cfg80211_info
*ndev_to_cfg(struct net_device
*ndev
)
535 return wdev_to_cfg(ndev
->ieee80211_ptr
);
538 static inline struct brcmf_cfg80211_profile
*ndev_to_prof(struct net_device
*nd
)
540 struct brcmf_if
*ifp
= netdev_priv(nd
);
541 return &ifp
->vif
->profile
;
544 #define iscan_to_cfg(i) ((struct brcmf_cfg80211_info *)(i->data))
545 #define cfg_to_iscan(w) (w->iscan)
548 brcmf_cfg80211_connect_info
*cfg_to_conn(struct brcmf_cfg80211_info
*cfg
)
550 return &cfg
->conn_info
;
553 struct brcmf_cfg80211_info
*brcmf_cfg80211_attach(struct brcmf_pub
*drvr
);
554 void brcmf_cfg80211_detach(struct brcmf_cfg80211_info
*cfg
);
556 /* event handler from dongle */
557 void brcmf_cfg80211_event(struct net_device
*ndev
,
558 const struct brcmf_event_msg
*e
, void *data
);
559 s32
brcmf_cfg80211_up(struct brcmf_cfg80211_info
*cfg
);
560 s32
brcmf_cfg80211_down(struct brcmf_cfg80211_info
*cfg
);
562 #endif /* _wl_cfg80211_h_ */