128ab5bcf7792f95ad75854728f76466de91acd7
[GitHub/LineageOS/G12/android_hardware_amlogic_kernel-modules_dhd-driver.git] / bcmdhd.100.10.315.x / wl_cfgp2p.h
1 /*
2 * Linux cfgp2p driver
3 *
4 * Copyright (C) 1999-2019, Broadcom.
5 *
6 * Unless you and Broadcom execute a separate written software license
7 * agreement governing use of this software, this software is licensed to you
8 * under the terms of the GNU General Public License version 2 (the "GPL"),
9 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
10 * following added to such license:
11 *
12 * As a special exception, the copyright holders of this software give you
13 * permission to link this software with independent modules, and to copy and
14 * distribute the resulting executable under terms of your choice, provided that
15 * you also meet, for each linked independent module, the terms and conditions of
16 * the license of that module. An independent module is a module which is not
17 * derived from this software. The special exception does not apply to any
18 * modifications of the software.
19 *
20 * Notwithstanding the above, under no circumstances may you combine this
21 * software in any way with any other Broadcom software provided under a license
22 * other than the GPL, without Broadcom's express prior written consent.
23 *
24 *
25 * <<Broadcom-WL-IPTag/Open:>>
26 *
27 * $Id: wl_cfgp2p.h 794110 2018-12-12 05:03:21Z $
28 */
29 #ifndef _wl_cfgp2p_h_
30 #define _wl_cfgp2p_h_
31 #include <802.11.h>
32 #include <p2p.h>
33
34 struct bcm_cfg80211;
35 extern u32 wl_dbg_level;
36
37 typedef struct wifi_p2p_ie wifi_wfd_ie_t;
38 /* Enumeration of the usages of the BSSCFGs used by the P2P Library. Do not
39 * confuse this with a bsscfg index. This value is an index into the
40 * saved_ie[] array of structures which in turn contains a bsscfg index field.
41 */
42 typedef enum {
43 P2PAPI_BSSCFG_PRIMARY, /**< maps to driver's primary bsscfg */
44 P2PAPI_BSSCFG_DEVICE, /**< maps to driver's P2P device discovery bsscfg */
45 P2PAPI_BSSCFG_CONNECTION1, /**< maps to driver's P2P connection bsscfg */
46 P2PAPI_BSSCFG_CONNECTION2,
47 P2PAPI_BSSCFG_MAX
48 } p2p_bsscfg_type_t;
49
50 typedef enum {
51 P2P_SCAN_PURPOSE_MIN,
52 P2P_SCAN_SOCIAL_CHANNEL, /**< scan for social channel */
53 P2P_SCAN_AFX_PEER_NORMAL, /**< scan for action frame search */
54 P2P_SCAN_AFX_PEER_REDUCED, /**< scan for action frame search with short time */
55 P2P_SCAN_DURING_CONNECTED, /**< scan during connected status */
56 P2P_SCAN_CONNECT_TRY, /**< scan for connecting */
57 P2P_SCAN_NORMAL, /**< scan during not-connected status */
58 P2P_SCAN_PURPOSE_MAX
59 } p2p_scan_purpose_t;
60
61 /** vendor ies max buffer length for probe response or beacon */
62 #define VNDR_IES_MAX_BUF_LEN 1400
63 /** normal vendor ies buffer length */
64 #define VNDR_IES_BUF_LEN 512
65
66 struct p2p_bss {
67 s32 bssidx;
68 struct net_device *dev;
69 void *private_data;
70 struct ether_addr mac_addr;
71 };
72
73 struct p2p_info {
74 bool on; /**< p2p on/off switch */
75 bool scan;
76 int16 search_state;
77 s8 vir_ifname[IFNAMSIZ];
78 unsigned long status;
79 struct p2p_bss bss[P2PAPI_BSSCFG_MAX];
80 timer_list_compat_t listen_timer;
81 wl_p2p_sched_t noa;
82 wl_p2p_ops_t ops;
83 wlc_ssid_t ssid;
84 s8 p2p_go_count;
85 };
86
87 #define MAX_VNDR_IE_NUMBER 10
88
89 struct parsed_vndr_ie_info {
90 const char *ie_ptr;
91 u32 ie_len; /**< total length including id & length field */
92 vndr_ie_t vndrie;
93 };
94
95 struct parsed_vndr_ies {
96 u32 count;
97 struct parsed_vndr_ie_info ie_info[MAX_VNDR_IE_NUMBER];
98 };
99
100 /* dongle status */
101 enum wl_cfgp2p_status {
102 WLP2P_STATUS_DISCOVERY_ON = 0,
103 WLP2P_STATUS_SEARCH_ENABLED,
104 WLP2P_STATUS_IF_ADDING,
105 WLP2P_STATUS_IF_DELETING,
106 WLP2P_STATUS_IF_CHANGING,
107 WLP2P_STATUS_IF_CHANGED,
108 WLP2P_STATUS_LISTEN_EXPIRED,
109 WLP2P_STATUS_ACTION_TX_COMPLETED,
110 WLP2P_STATUS_ACTION_TX_NOACK,
111 WLP2P_STATUS_SCANNING,
112 WLP2P_STATUS_GO_NEG_PHASE,
113 WLP2P_STATUS_DISC_IN_PROGRESS
114 };
115
116 #define wl_to_p2p_bss_ndev(cfg, type) ((cfg)->p2p->bss[type].dev)
117 #define wl_to_p2p_bss_bssidx(cfg, type) ((cfg)->p2p->bss[type].bssidx)
118 #define wl_to_p2p_bss_macaddr(cfg, type) &((cfg)->p2p->bss[type].mac_addr)
119 #define wl_to_p2p_bss_saved_ie(cfg, type) ((cfg)->p2p->bss[type].saved_ie)
120 #define wl_to_p2p_bss_private(cfg, type) ((cfg)->p2p->bss[type].private_data)
121 #define wl_to_p2p_bss(cfg, type) ((cfg)->p2p->bss[type])
122 #define wl_get_p2p_status(cfg, stat) ((!(cfg)->p2p_supported) ? 0 : \
123 test_bit(WLP2P_STATUS_ ## stat, &(cfg)->p2p->status))
124 #define wl_set_p2p_status(cfg, stat) ((!(cfg)->p2p_supported) ? 0 : \
125 set_bit(WLP2P_STATUS_ ## stat, &(cfg)->p2p->status))
126 #define wl_clr_p2p_status(cfg, stat) ((!(cfg)->p2p_supported) ? 0 : \
127 clear_bit(WLP2P_STATUS_ ## stat, &(cfg)->p2p->status))
128 #define wl_chg_p2p_status(cfg, stat) ((!(cfg)->p2p_supported) ? 0 : \
129 change_bit(WLP2P_STATUS_ ## stat, &(cfg)->p2p->status))
130 #define p2p_on(cfg) ((cfg)->p2p->on)
131 #define p2p_scan(cfg) ((cfg)->p2p->scan)
132 #define p2p_is_on(cfg) ((cfg)->p2p && (cfg)->p2p->on)
133
134 /* dword align allocation */
135 #define WLC_IOCTL_MAXLEN 8192
136
137 #define CFGP2P_ERROR_TEXT "CFGP2P-ERROR) "
138
139 #ifdef DHD_LOG_DUMP
140 #define CFGP2P_ERR(args) \
141 do { \
142 if (wl_dbg_level & WL_DBG_ERR) { \
143 printk(KERN_INFO CFGP2P_ERROR_TEXT "%s : ", __func__); \
144 printk args; \
145 DHD_LOG_DUMP_WRITE("[%s] %s: ", \
146 dhd_log_dump_get_timestamp(), __func__); \
147 DHD_LOG_DUMP_WRITE args; \
148 } \
149 } while (0)
150 #define CFGP2P_INFO(args) \
151 do { \
152 if (wl_dbg_level & WL_DBG_INFO) { \
153 printk(KERN_INFO "CFGP2P-INFO) %s : ", __func__); \
154 printk args; \
155 DHD_LOG_DUMP_WRITE("[%s] %s: ", \
156 dhd_log_dump_get_timestamp(), __func__); \
157 DHD_LOG_DUMP_WRITE args; \
158 } \
159 } while (0)
160 #define CFGP2P_ACTION(args) \
161 do { \
162 if (wl_dbg_level & WL_DBG_P2P_ACTION) { \
163 printk(KERN_DEBUG "CFGP2P-ACTION) %s :", __func__); \
164 printk args; \
165 DHD_LOG_DUMP_WRITE("[%s] %s: ", \
166 dhd_log_dump_get_timestamp(), __func__); \
167 DHD_LOG_DUMP_WRITE args; \
168 } \
169 } while (0)
170 #else
171 #define CFGP2P_ERR(args) \
172 do { \
173 if (wl_dbg_level & WL_DBG_ERR) { \
174 printk(KERN_INFO CFGP2P_ERROR_TEXT "%s : ", __func__); \
175 printk args; \
176 } \
177 } while (0)
178 #define CFGP2P_INFO(args) \
179 do { \
180 if (wl_dbg_level & WL_DBG_INFO) { \
181 printk(KERN_INFO "CFGP2P-INFO) %s : ", __func__); \
182 printk args; \
183 } \
184 } while (0)
185 #define CFGP2P_ACTION(args) \
186 do { \
187 if (wl_dbg_level & WL_DBG_P2P_ACTION) { \
188 printk(KERN_INFO "CFGP2P-ACTION) %s :", __func__); \
189 printk args; \
190 } \
191 } while (0)
192 #endif /* DHD_LOG_DUMP */
193
194 #define CFGP2P_DBG(args) \
195 do { \
196 if (wl_dbg_level & WL_DBG_DBG) { \
197 printk(KERN_INFO "CFGP2P-DEBUG) %s :", __func__); \
198 printk args; \
199 } \
200 } while (0)
201
202 #define INIT_TIMER(timer, func, duration, extra_delay) \
203 do { \
204 init_timer_compat(timer, func, cfg); \
205 timer_expires(timer) = jiffies + msecs_to_jiffies(duration + extra_delay); \
206 add_timer(timer); \
207 } while (0);
208
209 #if (LINUX_VERSION_CODE <= KERNEL_VERSION(3, 0, 8))
210 #ifdef WL_SUPPORT_BACKPORTED_KPATCHES
211 #undef WL_SUPPORT_BACKPORTED_KPATCHES
212 #endif
213 #endif
214
215 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 2, 0))
216 #ifdef WL_CFG80211_STA_EVENT
217 #undef WL_CFG80211_STA_EVENT
218 #endif
219 #endif
220
221 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0)) && !defined(WL_CFG80211_P2P_DEV_IF)
222 #define WL_CFG80211_P2P_DEV_IF
223
224 #ifdef WL_SUPPORT_BACKPORTED_KPATCHES
225 #undef WL_SUPPORT_BACKPORTED_KPATCHES
226 #endif // endif
227 #else
228 #ifdef WLP2P
229 /* Enable P2P network Interface if P2P support is enabled */
230 #define WL_ENABLE_P2P_IF
231 #endif /* WLP2P */
232 #endif /* (LINUX_VERSION >= VERSION(3, 8, 0)) */
233
234 #ifndef WL_CFG80211_P2P_DEV_IF
235 #endif /* WL_CFG80211_P2P_DEV_IF */
236
237 #if defined(WL_ENABLE_P2P_IF) && (defined(WL_CFG80211_P2P_DEV_IF) || \
238 (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0)))
239 #error Disable 'WL_ENABLE_P2P_IF', if 'WL_CFG80211_P2P_DEV_IF' is enabled \
240 or kernel version is 3.8.0 or above
241 #endif /* WL_ENABLE_P2P_IF && (WL_CFG80211_P2P_DEV_IF || (LINUX_VERSION >= VERSION(3, 8, 0))) */
242
243 #if !defined(WLP2P) && (defined(WL_ENABLE_P2P_IF) || defined(WL_CFG80211_P2P_DEV_IF))
244 #error WLP2P not defined
245 #endif /* !WLP2P && (WL_ENABLE_P2P_IF || WL_CFG80211_P2P_DEV_IF) */
246
247 #if defined(WL_CFG80211_P2P_DEV_IF)
248 #define bcm_struct_cfgdev struct wireless_dev
249 #else
250 #define bcm_struct_cfgdev struct net_device
251 #endif /* WL_CFG80211_P2P_DEV_IF */
252
253 #define P2P_ECSA_CNT 50
254
255 extern void
256 wl_cfgp2p_listen_expired(unsigned long data);
257 extern bool
258 wl_cfgp2p_is_pub_action(void *frame, u32 frame_len);
259 extern bool
260 wl_cfgp2p_is_p2p_action(void *frame, u32 frame_len);
261 extern bool
262 wl_cfgp2p_is_gas_action(void *frame, u32 frame_len);
263 extern bool
264 wl_cfgp2p_find_gas_subtype(u8 subtype, u8* data, u32 len);
265 extern bool
266 wl_cfgp2p_is_p2p_gas_action(void *frame, u32 frame_len);
267 extern void
268 wl_cfgp2p_print_actframe(bool tx, void *frame, u32 frame_len, u32 channel);
269 extern s32
270 wl_cfgp2p_init_priv(struct bcm_cfg80211 *cfg);
271 extern void
272 wl_cfgp2p_deinit_priv(struct bcm_cfg80211 *cfg);
273 extern s32
274 wl_cfgp2p_set_firm_p2p(struct bcm_cfg80211 *cfg);
275 extern s32
276 wl_cfgp2p_set_p2p_mode(struct bcm_cfg80211 *cfg, u8 mode,
277 u32 channel, u16 listen_ms, int bssidx);
278 extern s32
279 wl_cfgp2p_ifadd(struct bcm_cfg80211 *cfg, struct ether_addr *mac, u8 if_type,
280 chanspec_t chspec);
281 extern s32
282 wl_cfgp2p_ifdisable(struct bcm_cfg80211 *cfg, struct ether_addr *mac);
283 extern s32
284 wl_cfgp2p_ifdel(struct bcm_cfg80211 *cfg, struct ether_addr *mac);
285 extern s32
286 wl_cfgp2p_ifchange(struct bcm_cfg80211 *cfg, struct ether_addr *mac, u8 if_type,
287 chanspec_t chspec, s32 conn_idx);
288
289 extern s32
290 wl_cfgp2p_ifidx(struct bcm_cfg80211 *cfg, struct ether_addr *mac, s32 *index);
291
292 extern s32
293 wl_cfgp2p_init_discovery(struct bcm_cfg80211 *cfg);
294 extern s32
295 wl_cfgp2p_enable_discovery(struct bcm_cfg80211 *cfg, struct net_device *dev, const u8 *ie,
296 u32 ie_len);
297 extern s32
298 wl_cfgp2p_disable_discovery(struct bcm_cfg80211 *cfg);
299 extern s32
300 wl_cfgp2p_escan(struct bcm_cfg80211 *cfg, struct net_device *dev, u16 active, u32 num_chans,
301 u16 *channels,
302 s32 search_state, u16 action, u32 bssidx, struct ether_addr *tx_dst_addr,
303 p2p_scan_purpose_t p2p_scan_purpose);
304
305 extern s32
306 wl_cfgp2p_act_frm_search(struct bcm_cfg80211 *cfg, struct net_device *ndev,
307 s32 bssidx, s32 channel, struct ether_addr *tx_dst_addr);
308
309 extern const wpa_ie_fixed_t *
310 wl_cfgp2p_find_wpaie(const u8 *parse, u32 len);
311
312 extern const wpa_ie_fixed_t *
313 wl_cfgp2p_find_wpsie(const u8 *parse, u32 len);
314
315 extern wifi_p2p_ie_t *
316 wl_cfgp2p_find_p2pie(const u8 *parse, u32 len);
317
318 extern const wifi_wfd_ie_t *
319 wl_cfgp2p_find_wfdie(const u8 *parse, u32 len);
320 extern s32
321 wl_cfgp2p_set_management_ie(struct bcm_cfg80211 *cfg, struct net_device *ndev, s32 bssidx,
322 s32 pktflag, const u8 *vndr_ie, u32 vndr_ie_len);
323 extern s32
324 wl_cfgp2p_clear_management_ie(struct bcm_cfg80211 *cfg, s32 bssidx);
325
326 extern struct net_device *
327 wl_cfgp2p_find_ndev(struct bcm_cfg80211 *cfg, s32 bssidx);
328 extern s32
329 wl_cfgp2p_find_type(struct bcm_cfg80211 *cfg, s32 bssidx, s32 *type);
330
331 extern s32
332 wl_cfgp2p_listen_complete(struct bcm_cfg80211 *cfg, bcm_struct_cfgdev *cfgdev,
333 const wl_event_msg_t *e, void *data);
334 extern s32
335 wl_cfgp2p_discover_listen(struct bcm_cfg80211 *cfg, s32 channel, u32 duration_ms);
336
337 extern s32
338 wl_cfgp2p_discover_enable_search(struct bcm_cfg80211 *cfg, u8 enable);
339
340 extern s32
341 wl_cfgp2p_action_tx_complete(struct bcm_cfg80211 *cfg, bcm_struct_cfgdev *cfgdev,
342 const wl_event_msg_t *e, void *data);
343
344 extern s32
345 wl_cfgp2p_tx_action_frame(struct bcm_cfg80211 *cfg, struct net_device *dev,
346 wl_af_params_t *af_params, s32 bssidx);
347
348 extern void
349 wl_cfgp2p_generate_bss_mac(struct bcm_cfg80211 *cfg, struct ether_addr *primary_addr);
350
351 extern void
352 wl_cfg80211_change_ifaddr(u8* buf, struct ether_addr *p2p_int_addr, u8 element_id);
353
354 extern s32
355 wl_cfgp2p_supported(struct bcm_cfg80211 *cfg, struct net_device *ndev);
356
357 extern s32
358 wl_cfgp2p_down(struct bcm_cfg80211 *cfg);
359
360 extern s32
361 wl_cfgp2p_set_p2p_noa(struct bcm_cfg80211 *cfg, struct net_device *ndev, char* buf, int len);
362
363 extern s32
364 wl_cfgp2p_get_p2p_noa(struct bcm_cfg80211 *cfg, struct net_device *ndev, char* buf, int len);
365
366 extern s32
367 wl_cfgp2p_set_p2p_ps(struct bcm_cfg80211 *cfg, struct net_device *ndev, char* buf, int len);
368
369 extern s32
370 wl_cfgp2p_set_p2p_ecsa(struct bcm_cfg80211 *cfg, struct net_device *ndev, char* buf, int len);
371
372 extern s32
373 wl_cfgp2p_increase_p2p_bw(struct bcm_cfg80211 *cfg, struct net_device *ndev, char* buf, int len);
374
375 extern const u8 *
376 wl_cfgp2p_retreive_p2pattrib(const void *buf, u8 element_id);
377
378 extern const u8*
379 wl_cfgp2p_find_attrib_in_all_p2p_Ies(const u8 *parse, u32 len, u32 attrib);
380
381 extern const u8 *
382 wl_cfgp2p_retreive_p2p_dev_addr(wl_bss_info_t *bi, u32 bi_length);
383
384 extern s32
385 wl_cfgp2p_register_ndev(struct bcm_cfg80211 *cfg);
386
387 extern s32
388 wl_cfgp2p_unregister_ndev(struct bcm_cfg80211 *cfg);
389
390 extern bool
391 wl_cfgp2p_is_ifops(const struct net_device_ops *if_ops);
392
393 extern u32
394 wl_cfgp2p_vndr_ie(struct bcm_cfg80211 *cfg, u8 *iebuf, s32 pktflag,
395 s8 *oui, s32 ie_id, const s8 *data, s32 datalen, const s8* add_del_cmd);
396
397 extern int wl_cfgp2p_get_conn_idx(struct bcm_cfg80211 *cfg);
398
399 extern
400 int wl_cfg_multip2p_operational(struct bcm_cfg80211 *cfg);
401
402 extern
403 int wl_cfgp2p_vif_created(struct bcm_cfg80211 *cfg);
404
405 #if defined(WL_CFG80211_P2P_DEV_IF)
406 extern struct wireless_dev *
407 wl_cfgp2p_add_p2p_disc_if(struct bcm_cfg80211 *cfg);
408
409 extern int
410 wl_cfgp2p_start_p2p_device(struct wiphy *wiphy, struct wireless_dev *wdev);
411
412 extern void
413 wl_cfgp2p_stop_p2p_device(struct wiphy *wiphy, struct wireless_dev *wdev);
414
415 extern int
416 wl_cfgp2p_del_p2p_disc_if(struct wireless_dev *wdev, struct bcm_cfg80211 *cfg);
417
418 #endif /* WL_CFG80211_P2P_DEV_IF */
419
420 extern void
421 wl_cfgp2p_need_wait_actfrmae(struct bcm_cfg80211 *cfg, void *frame, u32 frame_len, bool tx);
422
423 extern int
424 wl_cfgp2p_is_p2p_specific_scan(struct cfg80211_scan_request *request);
425
426 /* WiFi Direct */
427 #define SOCIAL_CHAN_1 1
428 #define SOCIAL_CHAN_2 6
429 #define SOCIAL_CHAN_3 11
430 #define IS_P2P_SOCIAL_CHANNEL(channel) ((channel == SOCIAL_CHAN_1) || \
431 (channel == SOCIAL_CHAN_2) || \
432 (channel == SOCIAL_CHAN_3))
433 #define SOCIAL_CHAN_CNT 3
434 #define AF_PEER_SEARCH_CNT 2
435 #define WL_P2P_WILDCARD_SSID "DIRECT-"
436 #define WL_P2P_WILDCARD_SSID_LEN 7
437 #define WL_P2P_INTERFACE_PREFIX "p2p"
438 #define WL_P2P_TEMP_CHAN 11
439 #define WL_P2P_TEMP_CHAN_5G 36
440 #define WL_P2P_AF_STATUS_OFFSET 9
441
442 /* If the provision discovery is for JOIN operations,
443 * or the device discoverablity frame is destined to GO
444 * then we need not do an internal scan to find GO.
445 */
446 #define IS_ACTPUB_WITHOUT_GROUP_ID(p2p_ie, len) \
447 (wl_cfgp2p_retreive_p2pattrib(p2p_ie, P2P_SEID_GROUP_ID) == NULL)
448
449 #define IS_GAS_REQ(frame, len) (wl_cfgp2p_is_gas_action(frame, len) && \
450 ((frame->action == P2PSD_ACTION_ID_GAS_IREQ) || \
451 (frame->action == P2PSD_ACTION_ID_GAS_CREQ)))
452
453 #define IS_P2P_PUB_ACT_RSP_SUBTYPE(subtype) ((subtype == P2P_PAF_GON_RSP) || \
454 ((subtype == P2P_PAF_GON_CONF) || \
455 (subtype == P2P_PAF_INVITE_RSP) || \
456 (subtype == P2P_PAF_PROVDIS_RSP)))
457 #define IS_P2P_SOCIAL(ch) ((ch == SOCIAL_CHAN_1) || (ch == SOCIAL_CHAN_2) || (ch == SOCIAL_CHAN_3))
458 #define IS_P2P_SSID(ssid, len) (!memcmp(ssid, WL_P2P_WILDCARD_SSID, WL_P2P_WILDCARD_SSID_LEN) && \
459 (len == WL_P2P_WILDCARD_SSID_LEN))
460 #endif /* _wl_cfgp2p_h_ */