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