Merge remote-tracking branches 'asoc/topic/txx9', 'asoc/topic/wm8750', 'asoc/topic...
[linux-2.6-block.git] / drivers / net / wireless / brcm80211 / brcmfmac / cfg80211.h
1 /*
2  * Copyright (c) 2010 Broadcom Corporation
3  *
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.
7  *
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.
15  */
16
17 #ifndef BRCMFMAC_CFG80211_H
18 #define BRCMFMAC_CFG80211_H
19
20 /* for brcmu_d11inf */
21 #include <brcmu_d11.h>
22
23 #define WL_NUM_SCAN_MAX                 10
24 #define WL_NUM_PMKIDS_MAX               MAXPMKID
25 #define WL_TLV_INFO_MAX                 1024
26 #define WL_BSS_INFO_MAX                 2048
27 #define WL_ASSOC_INFO_MAX               512     /* assoc related fil max buf */
28 #define WL_EXTRA_BUF_MAX                2048
29 #define WL_ROAM_TRIGGER_LEVEL           -75
30 #define WL_ROAM_DELTA                   20
31 #define WL_BEACON_TIMEOUT               3
32
33 #define WL_SCAN_CHANNEL_TIME            40
34 #define WL_SCAN_UNASSOC_TIME            40
35 #define WL_SCAN_PASSIVE_TIME            120
36
37 #define WL_ESCAN_BUF_SIZE               (1024 * 64)
38 #define WL_ESCAN_TIMER_INTERVAL_MS      10000 /* E-Scan timeout */
39
40 #define WL_ESCAN_ACTION_START           1
41 #define WL_ESCAN_ACTION_CONTINUE        2
42 #define WL_ESCAN_ACTION_ABORT           3
43
44 #define WL_AUTH_SHARED_KEY              1       /* d11 shared authentication */
45 #define IE_MAX_LEN                      512
46
47 /* IE TLV processing */
48 #define TLV_LEN_OFF                     1       /* length offset */
49 #define TLV_HDR_LEN                     2       /* header length */
50 #define TLV_BODY_OFF                    2       /* body offset */
51 #define TLV_OUI_LEN                     3       /* oui id length */
52
53 /* 802.11 Mgmt Packet flags */
54 #define BRCMF_VNDR_IE_BEACON_FLAG       0x1
55 #define BRCMF_VNDR_IE_PRBRSP_FLAG       0x2
56 #define BRCMF_VNDR_IE_ASSOCRSP_FLAG     0x4
57 #define BRCMF_VNDR_IE_AUTHRSP_FLAG      0x8
58 #define BRCMF_VNDR_IE_PRBREQ_FLAG       0x10
59 #define BRCMF_VNDR_IE_ASSOCREQ_FLAG     0x20
60 /* vendor IE in IW advertisement protocol ID field */
61 #define BRCMF_VNDR_IE_IWAPID_FLAG       0x40
62 /* allow custom IE id */
63 #define BRCMF_VNDR_IE_CUSTOM_FLAG       0x100
64
65 /* P2P Action Frames flags (spec ordered) */
66 #define BRCMF_VNDR_IE_GONREQ_FLAG     0x001000
67 #define BRCMF_VNDR_IE_GONRSP_FLAG     0x002000
68 #define BRCMF_VNDR_IE_GONCFM_FLAG     0x004000
69 #define BRCMF_VNDR_IE_INVREQ_FLAG     0x008000
70 #define BRCMF_VNDR_IE_INVRSP_FLAG     0x010000
71 #define BRCMF_VNDR_IE_DISREQ_FLAG     0x020000
72 #define BRCMF_VNDR_IE_DISRSP_FLAG     0x040000
73 #define BRCMF_VNDR_IE_PRDREQ_FLAG     0x080000
74 #define BRCMF_VNDR_IE_PRDRSP_FLAG     0x100000
75
76 #define BRCMF_VNDR_IE_P2PAF_SHIFT       12
77
78
79 /**
80  * enum brcmf_scan_status - scan engine status
81  *
82  * @BRCMF_SCAN_STATUS_BUSY: scanning in progress on dongle.
83  * @BRCMF_SCAN_STATUS_ABORT: scan being aborted on dongle.
84  * @BRCMF_SCAN_STATUS_SUPPRESS: scanning is suppressed in driver.
85  */
86 enum brcmf_scan_status {
87         BRCMF_SCAN_STATUS_BUSY,
88         BRCMF_SCAN_STATUS_ABORT,
89         BRCMF_SCAN_STATUS_SUPPRESS,
90 };
91
92 /* dongle configuration */
93 struct brcmf_cfg80211_conf {
94         u32 frag_threshold;
95         u32 rts_threshold;
96         u32 retry_short;
97         u32 retry_long;
98         s32 tx_power;
99         struct ieee80211_channel channel;
100 };
101
102 /* basic structure of scan request */
103 struct brcmf_cfg80211_scan_req {
104         struct brcmf_ssid_le ssid_le;
105 };
106
107 /* basic structure of information element */
108 struct brcmf_cfg80211_ie {
109         u16 offset;
110         u8 buf[WL_TLV_INFO_MAX];
111 };
112
113 /* security information with currently associated ap */
114 struct brcmf_cfg80211_security {
115         u32 wpa_versions;
116         u32 auth_type;
117         u32 cipher_pairwise;
118         u32 cipher_group;
119         u32 wpa_auth;
120 };
121
122 /**
123  * struct brcmf_cfg80211_profile - profile information.
124  *
125  * @ssid: ssid of associated/associating ap.
126  * @bssid: bssid of joined/joining ibss.
127  * @sec: security information.
128  */
129 struct brcmf_cfg80211_profile {
130         struct brcmf_ssid ssid;
131         u8 bssid[ETH_ALEN];
132         struct brcmf_cfg80211_security sec;
133 };
134
135 /**
136  * enum brcmf_vif_status - bit indices for vif status.
137  *
138  * @BRCMF_VIF_STATUS_READY: ready for operation.
139  * @BRCMF_VIF_STATUS_CONNECTING: connect/join in progress.
140  * @BRCMF_VIF_STATUS_CONNECTED: connected/joined succesfully.
141  * @BRCMF_VIF_STATUS_DISCONNECTING: disconnect/disable in progress.
142  * @BRCMF_VIF_STATUS_AP_CREATING: interface configured for AP operation.
143  * @BRCMF_VIF_STATUS_AP_CREATED: AP operation started.
144  */
145 enum brcmf_vif_status {
146         BRCMF_VIF_STATUS_READY,
147         BRCMF_VIF_STATUS_CONNECTING,
148         BRCMF_VIF_STATUS_CONNECTED,
149         BRCMF_VIF_STATUS_DISCONNECTING,
150         BRCMF_VIF_STATUS_AP_CREATING,
151         BRCMF_VIF_STATUS_AP_CREATED
152 };
153
154 /**
155  * struct vif_saved_ie - holds saved IEs for a virtual interface.
156  *
157  * @probe_req_ie: IE info for probe request.
158  * @probe_res_ie: IE info for probe response.
159  * @beacon_ie: IE info for beacon frame.
160  * @probe_req_ie_len: IE info length for probe request.
161  * @probe_res_ie_len: IE info length for probe response.
162  * @beacon_ie_len: IE info length for beacon frame.
163  */
164 struct vif_saved_ie {
165         u8  probe_req_ie[IE_MAX_LEN];
166         u8  probe_res_ie[IE_MAX_LEN];
167         u8  beacon_ie[IE_MAX_LEN];
168         u8  assoc_req_ie[IE_MAX_LEN];
169         u32 probe_req_ie_len;
170         u32 probe_res_ie_len;
171         u32 beacon_ie_len;
172         u32 assoc_req_ie_len;
173 };
174
175 /**
176  * struct brcmf_cfg80211_vif - virtual interface specific information.
177  *
178  * @ifp: lower layer interface pointer
179  * @wdev: wireless device.
180  * @profile: profile information.
181  * @roam_off: roaming state.
182  * @sme_state: SME state using enum brcmf_vif_status bits.
183  * @pm_block: power-management blocked.
184  * @list: linked list.
185  * @mgmt_rx_reg: registered rx mgmt frame types.
186  * @mbss: Multiple BSS type, set if not first AP (not relevant for P2P).
187  */
188 struct brcmf_cfg80211_vif {
189         struct brcmf_if *ifp;
190         struct wireless_dev wdev;
191         struct brcmf_cfg80211_profile profile;
192         s32 roam_off;
193         unsigned long sme_state;
194         bool pm_block;
195         struct vif_saved_ie saved_ie;
196         struct list_head list;
197         u16 mgmt_rx_reg;
198         bool mbss;
199 };
200
201 /* association inform */
202 struct brcmf_cfg80211_connect_info {
203         u8 *req_ie;
204         s32 req_ie_len;
205         u8 *resp_ie;
206         s32 resp_ie_len;
207 };
208
209 /* assoc ie length */
210 struct brcmf_cfg80211_assoc_ielen_le {
211         __le32 req_len;
212         __le32 resp_len;
213 };
214
215 /* wpa2 pmk list */
216 struct brcmf_cfg80211_pmk_list {
217         struct pmkid_list pmkids;
218         struct pmkid foo[MAXPMKID - 1];
219 };
220
221 /* dongle escan state */
222 enum wl_escan_state {
223         WL_ESCAN_STATE_IDLE,
224         WL_ESCAN_STATE_SCANNING
225 };
226
227 struct escan_info {
228         u32 escan_state;
229         u8 escan_buf[WL_ESCAN_BUF_SIZE];
230         struct wiphy *wiphy;
231         struct brcmf_if *ifp;
232         s32 (*run)(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp,
233                    struct cfg80211_scan_request *request, u16 action);
234 };
235
236 /**
237  * struct brcmf_pno_param_le - PNO scan configuration parameters
238  *
239  * @version: PNO parameters version.
240  * @scan_freq: scan frequency.
241  * @lost_network_timeout: #sec. to declare discovered network as lost.
242  * @flags: Bit field to control features of PFN such as sort criteria auto
243  *      enable switch and background scan.
244  * @rssi_margin: Margin to avoid jitter for choosing a PFN based on RSSI sort
245  *      criteria.
246  * @bestn: number of best networks in each scan.
247  * @mscan: number of scans recorded.
248  * @repeat: minimum number of scan intervals before scan frequency changes
249  *      in adaptive scan.
250  * @exp: exponent of 2 for maximum scan interval.
251  * @slow_freq: slow scan period.
252  */
253 struct brcmf_pno_param_le {
254         __le32 version;
255         __le32 scan_freq;
256         __le32 lost_network_timeout;
257         __le16 flags;
258         __le16 rssi_margin;
259         u8 bestn;
260         u8 mscan;
261         u8 repeat;
262         u8 exp;
263         __le32 slow_freq;
264 };
265
266 /**
267  * struct brcmf_pno_net_param_le - scan parameters per preferred network.
268  *
269  * @ssid: ssid name and its length.
270  * @flags: bit2: hidden.
271  * @infra: BSS vs IBSS.
272  * @auth: Open vs Closed.
273  * @wpa_auth: WPA type.
274  * @wsec: wsec value.
275  */
276 struct brcmf_pno_net_param_le {
277         struct brcmf_ssid_le ssid;
278         __le32 flags;
279         __le32 infra;
280         __le32 auth;
281         __le32 wpa_auth;
282         __le32 wsec;
283 };
284
285 /**
286  * struct brcmf_pno_net_info_le - information per found network.
287  *
288  * @bssid: BSS network identifier.
289  * @channel: channel number only.
290  * @SSID_len: length of ssid.
291  * @SSID: ssid characters.
292  * @RSSI: receive signal strength (in dBm).
293  * @timestamp: age in seconds.
294  */
295 struct brcmf_pno_net_info_le {
296         u8 bssid[ETH_ALEN];
297         u8 channel;
298         u8 SSID_len;
299         u8 SSID[32];
300         __le16  RSSI;
301         __le16  timestamp;
302 };
303
304 /**
305  * struct brcmf_pno_scanresults_le - result returned in PNO NET FOUND event.
306  *
307  * @version: PNO version identifier.
308  * @status: indicates completion status of PNO scan.
309  * @count: amount of brcmf_pno_net_info_le entries appended.
310  */
311 struct brcmf_pno_scanresults_le {
312         __le32 version;
313         __le32 status;
314         __le32 count;
315 };
316
317 /**
318  * struct brcmf_cfg80211_vif_event - virtual interface event information.
319  *
320  * @vif_wq: waitqueue awaiting interface event from firmware.
321  * @vif_event_lock: protects other members in this structure.
322  * @vif_complete: completion for net attach.
323  * @action: either add, change, or delete.
324  * @vif: virtual interface object related to the event.
325  */
326 struct brcmf_cfg80211_vif_event {
327         wait_queue_head_t vif_wq;
328         struct mutex vif_event_lock;
329         u8 action;
330         struct brcmf_cfg80211_vif *vif;
331 };
332
333 /**
334  * struct brcmf_cfg80211_info - dongle private data of cfg80211 interface
335  *
336  * @wiphy: wiphy object for cfg80211 interface.
337  * @conf: dongle configuration.
338  * @p2p: peer-to-peer specific information.
339  * @btcoex: Bluetooth coexistence information.
340  * @scan_request: cfg80211 scan request object.
341  * @usr_sync: mainly for dongle up/down synchronization.
342  * @bss_list: bss_list holding scanned ap information.
343  * @scan_req_int: internal scan request object.
344  * @bss_info: bss information for cfg80211 layer.
345  * @ie: information element object for internal purpose.
346  * @conn_info: association info.
347  * @pmk_list: wpa2 pmk list.
348  * @scan_status: scan activity on the dongle.
349  * @pub: common driver information.
350  * @channel: current channel.
351  * @active_scan: current scan mode.
352  * @sched_escan: e-scan for scheduled scan support running.
353  * @ibss_starter: indicates this sta is ibss starter.
354  * @pwr_save: indicate whether dongle to support power save mode.
355  * @dongle_up: indicate whether dongle up or not.
356  * @roam_on: on/off switch for dongle self-roaming.
357  * @scan_tried: indicates if first scan attempted.
358  * @dcmd_buf: dcmd buffer.
359  * @extra_buf: mainly to grab assoc information.
360  * @debugfsdir: debugfs folder for this device.
361  * @escan_info: escan information.
362  * @escan_timeout: Timer for catch scan timeout.
363  * @escan_timeout_work: scan timeout worker.
364  * @escan_ioctl_buf: dongle command buffer for escan commands.
365  * @vif_list: linked list of vif instances.
366  * @vif_cnt: number of vif instances.
367  * @vif_event: vif event signalling.
368  * @wowl_enabled; set during suspend, is wowl used.
369  * @pre_wowl_pmmode: intermediate storage of pm mode during wowl.
370  */
371 struct brcmf_cfg80211_info {
372         struct wiphy *wiphy;
373         struct brcmf_cfg80211_conf *conf;
374         struct brcmf_p2p_info p2p;
375         struct brcmf_btcoex_info *btcoex;
376         struct cfg80211_scan_request *scan_request;
377         struct mutex usr_sync;
378         struct brcmf_cfg80211_scan_req scan_req_int;
379         struct wl_cfg80211_bss_info *bss_info;
380         struct brcmf_cfg80211_ie ie;
381         struct brcmf_cfg80211_connect_info conn_info;
382         struct brcmf_cfg80211_pmk_list *pmk_list;
383         unsigned long scan_status;
384         struct brcmf_pub *pub;
385         u32 channel;
386         bool active_scan;
387         bool sched_escan;
388         bool ibss_starter;
389         bool pwr_save;
390         bool dongle_up;
391         bool scan_tried;
392         u8 *dcmd_buf;
393         u8 *extra_buf;
394         struct dentry *debugfsdir;
395         struct escan_info escan_info;
396         struct timer_list escan_timeout;
397         struct work_struct escan_timeout_work;
398         u8 *escan_ioctl_buf;
399         struct list_head vif_list;
400         struct brcmf_cfg80211_vif_event vif_event;
401         struct completion vif_disabled;
402         struct brcmu_d11inf d11inf;
403         bool wowl_enabled;
404         u32 pre_wowl_pmmode;
405 };
406
407 /**
408  * struct brcmf_tlv - tag_ID/length/value_buffer tuple.
409  *
410  * @id: tag identifier.
411  * @len: number of bytes in value buffer.
412  * @data: value buffer.
413  */
414 struct brcmf_tlv {
415         u8 id;
416         u8 len;
417         u8 data[1];
418 };
419
420 static inline struct wiphy *cfg_to_wiphy(struct brcmf_cfg80211_info *cfg)
421 {
422         return cfg->wiphy;
423 }
424
425 static inline struct brcmf_cfg80211_info *wiphy_to_cfg(struct wiphy *w)
426 {
427         return (struct brcmf_cfg80211_info *)(wiphy_priv(w));
428 }
429
430 static inline struct brcmf_cfg80211_info *wdev_to_cfg(struct wireless_dev *wd)
431 {
432         return (struct brcmf_cfg80211_info *)(wdev_priv(wd));
433 }
434
435 static inline
436 struct net_device *cfg_to_ndev(struct brcmf_cfg80211_info *cfg)
437 {
438         struct brcmf_cfg80211_vif *vif;
439         vif = list_first_entry(&cfg->vif_list, struct brcmf_cfg80211_vif, list);
440         return vif->wdev.netdev;
441 }
442
443 static inline struct brcmf_cfg80211_info *ndev_to_cfg(struct net_device *ndev)
444 {
445         return wdev_to_cfg(ndev->ieee80211_ptr);
446 }
447
448 static inline struct brcmf_cfg80211_profile *ndev_to_prof(struct net_device *nd)
449 {
450         struct brcmf_if *ifp = netdev_priv(nd);
451         return &ifp->vif->profile;
452 }
453
454 static inline struct brcmf_cfg80211_vif *ndev_to_vif(struct net_device *ndev)
455 {
456         struct brcmf_if *ifp = netdev_priv(ndev);
457         return ifp->vif;
458 }
459
460 static inline struct
461 brcmf_cfg80211_connect_info *cfg_to_conn(struct brcmf_cfg80211_info *cfg)
462 {
463         return &cfg->conn_info;
464 }
465
466 struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
467                                                   struct device *busdev);
468 void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg);
469 s32 brcmf_cfg80211_up(struct net_device *ndev);
470 s32 brcmf_cfg80211_down(struct net_device *ndev);
471 enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp);
472
473 struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg,
474                                            enum nl80211_iftype type,
475                                            bool pm_block);
476 void brcmf_free_vif(struct brcmf_cfg80211_vif *vif);
477
478 s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag,
479                           const u8 *vndr_ie_buf, u32 vndr_ie_len);
480 s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif);
481 const struct brcmf_tlv *
482 brcmf_parse_tlvs(const void *buf, int buflen, uint key);
483 u16 channel_to_chanspec(struct brcmu_d11inf *d11inf,
484                         struct ieee80211_channel *ch);
485 bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg,
486                              unsigned long state);
487 void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg,
488                                   struct brcmf_cfg80211_vif *vif);
489 bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg);
490 int brcmf_cfg80211_wait_vif_event_timeout(struct brcmf_cfg80211_info *cfg,
491                                           u8 action, ulong timeout);
492 s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg,
493                                 struct brcmf_if *ifp, bool aborted,
494                                 bool fw_abort);
495 void brcmf_set_mpc(struct brcmf_if *ndev, int mpc);
496 void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg);
497 void brcmf_cfg80211_free_netdev(struct net_device *ndev);
498
499 #endif /* BRCMFMAC_CFG80211_H */