Merge tag 'pm+acpi-4.6-rc1-3' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael...
[cascardo/linux.git] / drivers / net / wireless / broadcom / 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_TLV_INFO_MAX                 1024
25 #define WL_BSS_INFO_MAX                 2048
26 #define WL_ASSOC_INFO_MAX               512     /* assoc related fil max buf */
27 #define WL_EXTRA_BUF_MAX                2048
28 #define WL_ROAM_TRIGGER_LEVEL           -75
29 #define WL_ROAM_DELTA                   20
30
31 /* Keep BRCMF_ESCAN_BUF_SIZE below 64K (65536). Allocing over 64K can be
32  * problematic on some systems and should be avoided.
33  */
34 #define BRCMF_ESCAN_BUF_SIZE            65000
35 #define BRCMF_ESCAN_TIMER_INTERVAL_MS   10000   /* E-Scan timeout */
36
37 #define WL_ESCAN_ACTION_START           1
38 #define WL_ESCAN_ACTION_CONTINUE        2
39 #define WL_ESCAN_ACTION_ABORT           3
40
41 #define WL_AUTH_SHARED_KEY              1       /* d11 shared authentication */
42 #define IE_MAX_LEN                      512
43
44 /* IE TLV processing */
45 #define TLV_LEN_OFF                     1       /* length offset */
46 #define TLV_HDR_LEN                     2       /* header length */
47 #define TLV_BODY_OFF                    2       /* body offset */
48 #define TLV_OUI_LEN                     3       /* oui id length */
49
50 /* 802.11 Mgmt Packet flags */
51 #define BRCMF_VNDR_IE_BEACON_FLAG       0x1
52 #define BRCMF_VNDR_IE_PRBRSP_FLAG       0x2
53 #define BRCMF_VNDR_IE_ASSOCRSP_FLAG     0x4
54 #define BRCMF_VNDR_IE_AUTHRSP_FLAG      0x8
55 #define BRCMF_VNDR_IE_PRBREQ_FLAG       0x10
56 #define BRCMF_VNDR_IE_ASSOCREQ_FLAG     0x20
57 /* vendor IE in IW advertisement protocol ID field */
58 #define BRCMF_VNDR_IE_IWAPID_FLAG       0x40
59 /* allow custom IE id */
60 #define BRCMF_VNDR_IE_CUSTOM_FLAG       0x100
61
62 /* P2P Action Frames flags (spec ordered) */
63 #define BRCMF_VNDR_IE_GONREQ_FLAG     0x001000
64 #define BRCMF_VNDR_IE_GONRSP_FLAG     0x002000
65 #define BRCMF_VNDR_IE_GONCFM_FLAG     0x004000
66 #define BRCMF_VNDR_IE_INVREQ_FLAG     0x008000
67 #define BRCMF_VNDR_IE_INVRSP_FLAG     0x010000
68 #define BRCMF_VNDR_IE_DISREQ_FLAG     0x020000
69 #define BRCMF_VNDR_IE_DISRSP_FLAG     0x040000
70 #define BRCMF_VNDR_IE_PRDREQ_FLAG     0x080000
71 #define BRCMF_VNDR_IE_PRDRSP_FLAG     0x100000
72
73 #define BRCMF_VNDR_IE_P2PAF_SHIFT       12
74
75 #define BRCMF_MAX_DEFAULT_KEYS          6
76
77 /* beacon loss timeout defaults */
78 #define BRCMF_DEFAULT_BCN_TIMEOUT_ROAM_ON       2
79 #define BRCMF_DEFAULT_BCN_TIMEOUT_ROAM_OFF      4
80
81 #define BRCMF_VIF_EVENT_TIMEOUT         msecs_to_jiffies(1500)
82
83 /**
84  * enum brcmf_scan_status - scan engine status
85  *
86  * @BRCMF_SCAN_STATUS_BUSY: scanning in progress on dongle.
87  * @BRCMF_SCAN_STATUS_ABORT: scan being aborted on dongle.
88  * @BRCMF_SCAN_STATUS_SUPPRESS: scanning is suppressed in driver.
89  */
90 enum brcmf_scan_status {
91         BRCMF_SCAN_STATUS_BUSY,
92         BRCMF_SCAN_STATUS_ABORT,
93         BRCMF_SCAN_STATUS_SUPPRESS,
94 };
95
96 /* dongle configuration */
97 struct brcmf_cfg80211_conf {
98         u32 frag_threshold;
99         u32 rts_threshold;
100         u32 retry_short;
101         u32 retry_long;
102 };
103
104 /* security information with currently associated ap */
105 struct brcmf_cfg80211_security {
106         u32 wpa_versions;
107         u32 auth_type;
108         u32 cipher_pairwise;
109         u32 cipher_group;
110 };
111
112 /**
113  * struct brcmf_cfg80211_profile - profile information.
114  *
115  * @bssid: bssid of joined/joining ibss.
116  * @sec: security information.
117  * @key: key information
118  */
119 struct brcmf_cfg80211_profile {
120         u8 bssid[ETH_ALEN];
121         struct brcmf_cfg80211_security sec;
122         struct brcmf_wsec_key key[BRCMF_MAX_DEFAULT_KEYS];
123 };
124
125 /**
126  * enum brcmf_vif_status - bit indices for vif status.
127  *
128  * @BRCMF_VIF_STATUS_READY: ready for operation.
129  * @BRCMF_VIF_STATUS_CONNECTING: connect/join in progress.
130  * @BRCMF_VIF_STATUS_CONNECTED: connected/joined succesfully.
131  * @BRCMF_VIF_STATUS_DISCONNECTING: disconnect/disable in progress.
132  * @BRCMF_VIF_STATUS_AP_CREATED: AP operation started.
133  */
134 enum brcmf_vif_status {
135         BRCMF_VIF_STATUS_READY,
136         BRCMF_VIF_STATUS_CONNECTING,
137         BRCMF_VIF_STATUS_CONNECTED,
138         BRCMF_VIF_STATUS_DISCONNECTING,
139         BRCMF_VIF_STATUS_AP_CREATED
140 };
141
142 /**
143  * struct vif_saved_ie - holds saved IEs for a virtual interface.
144  *
145  * @probe_req_ie: IE info for probe request.
146  * @probe_res_ie: IE info for probe response.
147  * @beacon_ie: IE info for beacon frame.
148  * @probe_req_ie_len: IE info length for probe request.
149  * @probe_res_ie_len: IE info length for probe response.
150  * @beacon_ie_len: IE info length for beacon frame.
151  */
152 struct vif_saved_ie {
153         u8  probe_req_ie[IE_MAX_LEN];
154         u8  probe_res_ie[IE_MAX_LEN];
155         u8  beacon_ie[IE_MAX_LEN];
156         u8  assoc_req_ie[IE_MAX_LEN];
157         u32 probe_req_ie_len;
158         u32 probe_res_ie_len;
159         u32 beacon_ie_len;
160         u32 assoc_req_ie_len;
161 };
162
163 /**
164  * struct brcmf_cfg80211_vif - virtual interface specific information.
165  *
166  * @ifp: lower layer interface pointer
167  * @wdev: wireless device.
168  * @profile: profile information.
169  * @sme_state: SME state using enum brcmf_vif_status bits.
170  * @pm_block: power-management blocked.
171  * @list: linked list.
172  * @mgmt_rx_reg: registered rx mgmt frame types.
173  * @mbss: Multiple BSS type, set if not first AP (not relevant for P2P).
174  */
175 struct brcmf_cfg80211_vif {
176         struct brcmf_if *ifp;
177         struct wireless_dev wdev;
178         struct brcmf_cfg80211_profile profile;
179         unsigned long sme_state;
180         bool pm_block;
181         struct vif_saved_ie saved_ie;
182         struct list_head list;
183         u16 mgmt_rx_reg;
184         bool mbss;
185         int is_11d;
186 };
187
188 /* association inform */
189 struct brcmf_cfg80211_connect_info {
190         u8 *req_ie;
191         s32 req_ie_len;
192         u8 *resp_ie;
193         s32 resp_ie_len;
194 };
195
196 /* assoc ie length */
197 struct brcmf_cfg80211_assoc_ielen_le {
198         __le32 req_len;
199         __le32 resp_len;
200 };
201
202 /* dongle escan state */
203 enum wl_escan_state {
204         WL_ESCAN_STATE_IDLE,
205         WL_ESCAN_STATE_SCANNING
206 };
207
208 struct escan_info {
209         u32 escan_state;
210         u8 *escan_buf;
211         struct wiphy *wiphy;
212         struct brcmf_if *ifp;
213         s32 (*run)(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp,
214                    struct cfg80211_scan_request *request);
215 };
216
217 /**
218  * struct brcmf_cfg80211_vif_event - virtual interface event information.
219  *
220  * @vif_wq: waitqueue awaiting interface event from firmware.
221  * @vif_event_lock: protects other members in this structure.
222  * @vif_complete: completion for net attach.
223  * @action: either add, change, or delete.
224  * @vif: virtual interface object related to the event.
225  */
226 struct brcmf_cfg80211_vif_event {
227         wait_queue_head_t vif_wq;
228         struct mutex vif_event_lock;
229         u8 action;
230         struct brcmf_cfg80211_vif *vif;
231 };
232
233 /**
234  * struct brcmf_cfg80211_wowl - wowl related information.
235  *
236  * @active: set on suspend, cleared on resume.
237  * @pre_pmmode: firmware PM mode at entering suspend.
238  * @nd: net dectect data.
239  * @nd_info: helper struct to pass to cfg80211.
240  * @nd_data_wait: wait queue to sync net detect data.
241  * @nd_data_completed: completion for net detect data.
242  * @nd_enabled: net detect enabled.
243  */
244 struct brcmf_cfg80211_wowl {
245         bool active;
246         u32 pre_pmmode;
247         struct cfg80211_wowlan_nd_match *nd;
248         struct cfg80211_wowlan_nd_info *nd_info;
249         wait_queue_head_t nd_data_wait;
250         bool nd_data_completed;
251         bool nd_enabled;
252 };
253
254 /**
255  * struct brcmf_cfg80211_info - dongle private data of cfg80211 interface
256  *
257  * @wiphy: wiphy object for cfg80211 interface.
258  * @ops: pointer to copy of ops as registered with wiphy object.
259  * @conf: dongle configuration.
260  * @p2p: peer-to-peer specific information.
261  * @btcoex: Bluetooth coexistence information.
262  * @scan_request: cfg80211 scan request object.
263  * @usr_sync: mainly for dongle up/down synchronization.
264  * @bss_list: bss_list holding scanned ap information.
265  * @bss_info: bss information for cfg80211 layer.
266  * @conn_info: association info.
267  * @pmk_list: wpa2 pmk list.
268  * @scan_status: scan activity on the dongle.
269  * @pub: common driver information.
270  * @channel: current channel.
271  * @active_scan: current scan mode.
272  * @sched_escan: e-scan for scheduled scan support running.
273  * @ibss_starter: indicates this sta is ibss starter.
274  * @pwr_save: indicate whether dongle to support power save mode.
275  * @dongle_up: indicate whether dongle up or not.
276  * @roam_on: on/off switch for dongle self-roaming.
277  * @scan_tried: indicates if first scan attempted.
278  * @dcmd_buf: dcmd buffer.
279  * @extra_buf: mainly to grab assoc information.
280  * @debugfsdir: debugfs folder for this device.
281  * @escan_info: escan information.
282  * @escan_timeout: Timer for catch scan timeout.
283  * @escan_timeout_work: scan timeout worker.
284  * @vif_list: linked list of vif instances.
285  * @vif_cnt: number of vif instances.
286  * @vif_event: vif event signalling.
287  * @wowl: wowl related information.
288  */
289 struct brcmf_cfg80211_info {
290         struct wiphy *wiphy;
291         struct cfg80211_ops *ops;
292         struct brcmf_cfg80211_conf *conf;
293         struct brcmf_p2p_info p2p;
294         struct brcmf_btcoex_info *btcoex;
295         struct cfg80211_scan_request *scan_request;
296         struct mutex usr_sync;
297         struct wl_cfg80211_bss_info *bss_info;
298         struct brcmf_cfg80211_connect_info conn_info;
299         struct brcmf_pmk_list_le pmk_list;
300         unsigned long scan_status;
301         struct brcmf_pub *pub;
302         u32 channel;
303         bool active_scan;
304         bool sched_escan;
305         bool ibss_starter;
306         bool pwr_save;
307         bool dongle_up;
308         bool scan_tried;
309         u8 *dcmd_buf;
310         u8 *extra_buf;
311         struct dentry *debugfsdir;
312         struct escan_info escan_info;
313         struct timer_list escan_timeout;
314         struct work_struct escan_timeout_work;
315         struct list_head vif_list;
316         struct brcmf_cfg80211_vif_event vif_event;
317         struct completion vif_disabled;
318         struct brcmu_d11inf d11inf;
319         struct brcmf_assoclist_le assoclist;
320         struct brcmf_cfg80211_wowl wowl;
321 };
322
323 /**
324  * struct brcmf_tlv - tag_ID/length/value_buffer tuple.
325  *
326  * @id: tag identifier.
327  * @len: number of bytes in value buffer.
328  * @data: value buffer.
329  */
330 struct brcmf_tlv {
331         u8 id;
332         u8 len;
333         u8 data[1];
334 };
335
336 static inline struct wiphy *cfg_to_wiphy(struct brcmf_cfg80211_info *cfg)
337 {
338         return cfg->wiphy;
339 }
340
341 static inline struct brcmf_cfg80211_info *wiphy_to_cfg(struct wiphy *w)
342 {
343         return (struct brcmf_cfg80211_info *)(wiphy_priv(w));
344 }
345
346 static inline struct brcmf_cfg80211_info *wdev_to_cfg(struct wireless_dev *wd)
347 {
348         return (struct brcmf_cfg80211_info *)(wdev_priv(wd));
349 }
350
351 static inline
352 struct net_device *cfg_to_ndev(struct brcmf_cfg80211_info *cfg)
353 {
354         struct brcmf_cfg80211_vif *vif;
355         vif = list_first_entry(&cfg->vif_list, struct brcmf_cfg80211_vif, list);
356         return vif->wdev.netdev;
357 }
358
359 static inline struct brcmf_cfg80211_info *ndev_to_cfg(struct net_device *ndev)
360 {
361         return wdev_to_cfg(ndev->ieee80211_ptr);
362 }
363
364 static inline struct brcmf_cfg80211_profile *ndev_to_prof(struct net_device *nd)
365 {
366         struct brcmf_if *ifp = netdev_priv(nd);
367         return &ifp->vif->profile;
368 }
369
370 static inline struct brcmf_cfg80211_vif *ndev_to_vif(struct net_device *ndev)
371 {
372         struct brcmf_if *ifp = netdev_priv(ndev);
373         return ifp->vif;
374 }
375
376 static inline struct
377 brcmf_cfg80211_connect_info *cfg_to_conn(struct brcmf_cfg80211_info *cfg)
378 {
379         return &cfg->conn_info;
380 }
381
382 struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
383                                                   struct device *busdev,
384                                                   bool p2pdev_forced);
385 void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg);
386 s32 brcmf_cfg80211_up(struct net_device *ndev);
387 s32 brcmf_cfg80211_down(struct net_device *ndev);
388 enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp);
389
390 struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg,
391                                            enum nl80211_iftype type,
392                                            bool pm_block);
393 void brcmf_free_vif(struct brcmf_cfg80211_vif *vif);
394
395 s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag,
396                           const u8 *vndr_ie_buf, u32 vndr_ie_len);
397 s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif);
398 const struct brcmf_tlv *
399 brcmf_parse_tlvs(const void *buf, int buflen, uint key);
400 u16 channel_to_chanspec(struct brcmu_d11inf *d11inf,
401                         struct ieee80211_channel *ch);
402 bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg,
403                              unsigned long state);
404 void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg,
405                                   struct brcmf_cfg80211_vif *vif);
406 bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg);
407 int brcmf_cfg80211_wait_vif_event(struct brcmf_cfg80211_info *cfg,
408                                   u8 action, ulong timeout);
409 s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg,
410                                 struct brcmf_if *ifp, bool aborted,
411                                 bool fw_abort);
412 void brcmf_set_mpc(struct brcmf_if *ndev, int mpc);
413 void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg);
414 void brcmf_cfg80211_free_netdev(struct net_device *ndev);
415
416 #endif /* BRCMFMAC_CFG80211_H */