1 // SPDX-License-Identifier: ISC
3 * Copyright (c) 2012 Broadcom Corporation
5 #include <linux/slab.h>
6 #include <linux/netdevice.h>
7 #include <linux/etherdevice.h>
8 #include <linux/rtnetlink.h>
9 #include <net/cfg80211.h>
11 #include <brcmu_wifi.h>
12 #include <brcmu_utils.h>
17 #include "fwil_types.h"
22 /* parameters used for p2p escan */
23 #define P2PAPI_SCAN_NPROBES 1
24 #define P2PAPI_SCAN_DWELL_TIME_MS 80
25 #define P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS 40
26 #define P2PAPI_SCAN_HOME_TIME_MS 60
27 #define P2PAPI_SCAN_NPROBS_TIME_MS 30
28 #define P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS 100
29 #define WL_SCAN_CONNECT_DWELL_TIME_MS 200
30 #define WL_SCAN_JOIN_PROBE_INTERVAL_MS 20
32 #define BRCMF_P2P_WILDCARD_SSID "DIRECT-"
33 #define BRCMF_P2P_WILDCARD_SSID_LEN (sizeof(BRCMF_P2P_WILDCARD_SSID) - 1)
35 #define SOCIAL_CHAN_1 1
36 #define SOCIAL_CHAN_2 6
37 #define SOCIAL_CHAN_3 11
38 #define IS_P2P_SOCIAL_CHANNEL(channel) ((channel == SOCIAL_CHAN_1) || \
39 (channel == SOCIAL_CHAN_2) || \
40 (channel == SOCIAL_CHAN_3))
41 #define BRCMF_P2P_TEMP_CHAN SOCIAL_CHAN_3
42 #define SOCIAL_CHAN_CNT 3
43 #define AF_PEER_SEARCH_CNT 2
45 #define BRCMF_SCB_TIMEOUT_VALUE 20
47 #define P2P_VER 9 /* P2P version: 9=WiFi P2P v1.0 */
48 #define P2P_PUB_AF_CATEGORY 0x04
49 #define P2P_PUB_AF_ACTION 0x09
50 #define P2P_AF_CATEGORY 0x7f
51 #define P2P_OUI "\x50\x6F\x9A" /* P2P OUI */
52 #define P2P_OUI_LEN 3 /* P2P OUI length */
54 /* Action Frame Constants */
55 #define DOT11_ACTION_HDR_LEN 2 /* action frame category + action */
56 #define DOT11_ACTION_CAT_OFF 0 /* category offset */
57 #define DOT11_ACTION_ACT_OFF 1 /* action offset */
59 #define P2P_AF_DWELL_TIME 200
60 #define P2P_AF_MIN_DWELL_TIME 100
61 #define P2P_AF_MED_DWELL_TIME 400
62 #define P2P_AF_LONG_DWELL_TIME 1000
63 #define P2P_AF_TX_MAX_RETRY 5
64 #define P2P_AF_MAX_WAIT_TIME msecs_to_jiffies(2000)
65 #define P2P_INVALID_CHANNEL -1
66 #define P2P_CHANNEL_SYNC_RETRY 5
67 #define P2P_AF_FRM_SCAN_MAX_WAIT msecs_to_jiffies(450)
68 #define P2P_DEFAULT_SLEEP_TIME_VSDB 200
69 #define P2P_AF_RETRY_DELAY_TIME 40
71 /* WiFi P2P Public Action Frame OUI Subtypes */
72 #define P2P_PAF_GON_REQ 0 /* Group Owner Negotiation Req */
73 #define P2P_PAF_GON_RSP 1 /* Group Owner Negotiation Rsp */
74 #define P2P_PAF_GON_CONF 2 /* Group Owner Negotiation Confirm */
75 #define P2P_PAF_INVITE_REQ 3 /* P2P Invitation Request */
76 #define P2P_PAF_INVITE_RSP 4 /* P2P Invitation Response */
77 #define P2P_PAF_DEVDIS_REQ 5 /* Device Discoverability Request */
78 #define P2P_PAF_DEVDIS_RSP 6 /* Device Discoverability Response */
79 #define P2P_PAF_PROVDIS_REQ 7 /* Provision Discovery Request */
80 #define P2P_PAF_PROVDIS_RSP 8 /* Provision Discovery Response */
81 #define P2P_PAF_SUBTYPE_INVALID 255 /* Invalid Subtype */
83 /* WiFi P2P Action Frame OUI Subtypes */
84 #define P2P_AF_NOTICE_OF_ABSENCE 0 /* Notice of Absence */
85 #define P2P_AF_PRESENCE_REQ 1 /* P2P Presence Request */
86 #define P2P_AF_PRESENCE_RSP 2 /* P2P Presence Response */
87 #define P2P_AF_GO_DISC_REQ 3 /* GO Discoverability Request */
89 /* P2P Service Discovery related */
90 #define P2PSD_ACTION_CATEGORY 0x04 /* Public action frame */
91 #define P2PSD_ACTION_ID_GAS_IREQ 0x0a /* GAS Initial Request AF */
92 #define P2PSD_ACTION_ID_GAS_IRESP 0x0b /* GAS Initial Response AF */
93 #define P2PSD_ACTION_ID_GAS_CREQ 0x0c /* GAS Comback Request AF */
94 #define P2PSD_ACTION_ID_GAS_CRESP 0x0d /* GAS Comback Response AF */
96 #define BRCMF_P2P_DISABLE_TIMEOUT msecs_to_jiffies(500)
98 /* Mask for retry counter of custom dwell time */
99 #define CUSTOM_RETRY_MASK 0xff000000
101 * struct brcmf_p2p_disc_st_le - set discovery state in firmware.
103 * @state: requested discovery state (see enum brcmf_p2p_disc_state).
104 * @chspec: channel parameter for %WL_P2P_DISC_ST_LISTEN state.
105 * @dwell: dwell time in ms for %WL_P2P_DISC_ST_LISTEN state.
107 struct brcmf_p2p_disc_st_le {
114 * enum brcmf_p2p_disc_state - P2P discovery state values
116 * @WL_P2P_DISC_ST_SCAN: P2P discovery with wildcard SSID and P2P IE.
117 * @WL_P2P_DISC_ST_LISTEN: P2P discovery off-channel for specified time.
118 * @WL_P2P_DISC_ST_SEARCH: P2P discovery with P2P wildcard SSID and P2P IE.
120 enum brcmf_p2p_disc_state {
122 WL_P2P_DISC_ST_LISTEN,
123 WL_P2P_DISC_ST_SEARCH
127 * struct brcmf_p2p_scan_le - P2P specific scan request.
129 * @type: type of scan method requested (values: 'E' or 'S').
130 * @reserved: reserved (ignored).
131 * @eparams: parameters used for type 'E'.
132 * @sparams: parameters used for type 'S'.
134 struct brcmf_p2p_scan_le {
138 struct brcmf_escan_params_le eparams;
139 struct brcmf_scan_params_le sparams;
144 * struct brcmf_p2p_pub_act_frame - WiFi P2P Public Action Frame
146 * @category: P2P_PUB_AF_CATEGORY
147 * @action: P2P_PUB_AF_ACTION
149 * @oui_type: OUI type - P2P_VER
150 * @subtype: OUI subtype - P2P_TYPE_*
151 * @dialog_token: nonzero, identifies req/rsp transaction
152 * @elts: Variable length information elements.
154 struct brcmf_p2p_pub_act_frame {
165 * struct brcmf_p2p_action_frame - WiFi P2P Action Frame
167 * @category: P2P_AF_CATEGORY
168 * @oui: OUI - P2P_OUI
169 * @type: OUI Type - P2P_VER
170 * @subtype: OUI Subtype - P2P_AF_*
171 * @dialog_token: nonzero, identifies req/resp tranaction
172 * @elts: Variable length information elements.
174 struct brcmf_p2p_action_frame {
184 * struct brcmf_p2psd_gas_pub_act_frame - Wi-Fi GAS Public Action Frame
186 * @category: 0x04 Public Action Frame
187 * @action: 0x6c Advertisement Protocol
188 * @dialog_token: nonzero, identifies req/rsp transaction
189 * @query_data: Query Data. SD gas ireq SD gas iresp
191 struct brcmf_p2psd_gas_pub_act_frame {
199 * struct brcmf_config_af_params - Action Frame Parameters for tx.
201 * @mpc_onoff: To make sure to send successfully action frame, we have to
202 * turn off mpc 0: off, 1: on, (-1): do nothing
203 * @search_channel: 1: search peer's channel to send af
204 * @extra_listen: keep the dwell time to get af response frame.
206 struct brcmf_config_af_params {
213 * brcmf_p2p_is_pub_action() - true if p2p public type frame.
215 * @frame: action frame data.
216 * @frame_len: length of action frame data.
218 * Determine if action frame is p2p public action type
220 static bool brcmf_p2p_is_pub_action(void *frame, u32 frame_len)
222 struct brcmf_p2p_pub_act_frame *pact_frm;
227 pact_frm = (struct brcmf_p2p_pub_act_frame *)frame;
228 if (frame_len < sizeof(struct brcmf_p2p_pub_act_frame) - 1)
231 if (pact_frm->category == P2P_PUB_AF_CATEGORY &&
232 pact_frm->action == P2P_PUB_AF_ACTION &&
233 pact_frm->oui_type == P2P_VER &&
234 memcmp(pact_frm->oui, P2P_OUI, P2P_OUI_LEN) == 0)
241 * brcmf_p2p_is_p2p_action() - true if p2p action type frame.
243 * @frame: action frame data.
244 * @frame_len: length of action frame data.
246 * Determine if action frame is p2p action type
248 static bool brcmf_p2p_is_p2p_action(void *frame, u32 frame_len)
250 struct brcmf_p2p_action_frame *act_frm;
255 act_frm = (struct brcmf_p2p_action_frame *)frame;
256 if (frame_len < sizeof(struct brcmf_p2p_action_frame) - 1)
259 if (act_frm->category == P2P_AF_CATEGORY &&
260 act_frm->type == P2P_VER &&
261 memcmp(act_frm->oui, P2P_OUI, P2P_OUI_LEN) == 0)
268 * brcmf_p2p_is_gas_action() - true if p2p gas action type frame.
270 * @frame: action frame data.
271 * @frame_len: length of action frame data.
273 * Determine if action frame is p2p gas action type
275 static bool brcmf_p2p_is_gas_action(void *frame, u32 frame_len)
277 struct brcmf_p2psd_gas_pub_act_frame *sd_act_frm;
282 sd_act_frm = (struct brcmf_p2psd_gas_pub_act_frame *)frame;
283 if (frame_len < sizeof(struct brcmf_p2psd_gas_pub_act_frame) - 1)
286 if (sd_act_frm->category != P2PSD_ACTION_CATEGORY)
289 if (sd_act_frm->action == P2PSD_ACTION_ID_GAS_IREQ ||
290 sd_act_frm->action == P2PSD_ACTION_ID_GAS_IRESP ||
291 sd_act_frm->action == P2PSD_ACTION_ID_GAS_CREQ ||
292 sd_act_frm->action == P2PSD_ACTION_ID_GAS_CRESP)
299 * brcmf_p2p_print_actframe() - debug print routine.
301 * @tx: Received or to be transmitted
302 * @frame: action frame data.
303 * @frame_len: length of action frame data.
305 * Print information about the p2p action frame
310 static void brcmf_p2p_print_actframe(bool tx, void *frame, u32 frame_len)
312 struct brcmf_p2p_pub_act_frame *pact_frm;
313 struct brcmf_p2p_action_frame *act_frm;
314 struct brcmf_p2psd_gas_pub_act_frame *sd_act_frm;
316 if (!frame || frame_len <= 2)
319 if (brcmf_p2p_is_pub_action(frame, frame_len)) {
320 pact_frm = (struct brcmf_p2p_pub_act_frame *)frame;
321 switch (pact_frm->subtype) {
322 case P2P_PAF_GON_REQ:
323 brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Req Frame\n",
326 case P2P_PAF_GON_RSP:
327 brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Rsp Frame\n",
330 case P2P_PAF_GON_CONF:
331 brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Confirm Frame\n",
334 case P2P_PAF_INVITE_REQ:
335 brcmf_dbg(TRACE, "%s P2P Invitation Request Frame\n",
338 case P2P_PAF_INVITE_RSP:
339 brcmf_dbg(TRACE, "%s P2P Invitation Response Frame\n",
342 case P2P_PAF_DEVDIS_REQ:
343 brcmf_dbg(TRACE, "%s P2P Device Discoverability Request Frame\n",
346 case P2P_PAF_DEVDIS_RSP:
347 brcmf_dbg(TRACE, "%s P2P Device Discoverability Response Frame\n",
350 case P2P_PAF_PROVDIS_REQ:
351 brcmf_dbg(TRACE, "%s P2P Provision Discovery Request Frame\n",
354 case P2P_PAF_PROVDIS_RSP:
355 brcmf_dbg(TRACE, "%s P2P Provision Discovery Response Frame\n",
359 brcmf_dbg(TRACE, "%s Unknown P2P Public Action Frame\n",
363 } else if (brcmf_p2p_is_p2p_action(frame, frame_len)) {
364 act_frm = (struct brcmf_p2p_action_frame *)frame;
365 switch (act_frm->subtype) {
366 case P2P_AF_NOTICE_OF_ABSENCE:
367 brcmf_dbg(TRACE, "%s P2P Notice of Absence Frame\n",
370 case P2P_AF_PRESENCE_REQ:
371 brcmf_dbg(TRACE, "%s P2P Presence Request Frame\n",
374 case P2P_AF_PRESENCE_RSP:
375 brcmf_dbg(TRACE, "%s P2P Presence Response Frame\n",
378 case P2P_AF_GO_DISC_REQ:
379 brcmf_dbg(TRACE, "%s P2P Discoverability Request Frame\n",
383 brcmf_dbg(TRACE, "%s Unknown P2P Action Frame\n",
387 } else if (brcmf_p2p_is_gas_action(frame, frame_len)) {
388 sd_act_frm = (struct brcmf_p2psd_gas_pub_act_frame *)frame;
389 switch (sd_act_frm->action) {
390 case P2PSD_ACTION_ID_GAS_IREQ:
391 brcmf_dbg(TRACE, "%s P2P GAS Initial Request\n",
394 case P2PSD_ACTION_ID_GAS_IRESP:
395 brcmf_dbg(TRACE, "%s P2P GAS Initial Response\n",
398 case P2PSD_ACTION_ID_GAS_CREQ:
399 brcmf_dbg(TRACE, "%s P2P GAS Comback Request\n",
402 case P2PSD_ACTION_ID_GAS_CRESP:
403 brcmf_dbg(TRACE, "%s P2P GAS Comback Response\n",
407 brcmf_dbg(TRACE, "%s Unknown P2P GAS Frame\n",
416 static void brcmf_p2p_print_actframe(bool tx, void *frame, u32 frame_len)
424 * brcmf_p2p_set_firmware() - prepare firmware for peer-to-peer operation.
426 * @ifp: ifp to use for iovars (primary).
427 * @p2p_mac: mac address to configure for p2p_da_override
429 static int brcmf_p2p_set_firmware(struct brcmf_if *ifp, u8 *p2p_mac)
431 struct brcmf_pub *drvr = ifp->drvr;
434 brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
435 brcmf_fil_iovar_int_set(ifp, "apsta", 1);
436 brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
438 /* In case of COB type, firmware has default mac address
439 * After Initializing firmware, we have to set current mac address to
440 * firmware for P2P device address. This must be done with discovery
443 brcmf_fil_iovar_int_set(ifp, "p2p_disc", 0);
445 ret = brcmf_fil_iovar_data_set(ifp, "p2p_da_override", p2p_mac,
448 bphy_err(drvr, "failed to update device address ret %d\n", ret);
454 * brcmf_p2p_generate_bss_mac() - derive mac addresses for P2P.
456 * @p2p: P2P specific data.
457 * @dev_addr: optional device address.
459 * P2P needs mac addresses for P2P device and interface. If no device
460 * address it specified, these are derived from a random ethernet
463 static void brcmf_p2p_generate_bss_mac(struct brcmf_p2p_info *p2p, u8 *dev_addr)
465 struct brcmf_if *pri_ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
466 bool random_addr = false;
467 bool local_admin = false;
469 if (!dev_addr || is_zero_ether_addr(dev_addr)) {
470 /* If the primary interface address is already locally
471 * administered, create a new random address.
473 if (pri_ifp->mac_addr[0] & 0x02) {
476 dev_addr = pri_ifp->mac_addr;
481 /* Generate the P2P Device Address obtaining a random ethernet
482 * address with the locally administered bit set.
485 eth_random_addr(p2p->dev_addr);
487 memcpy(p2p->dev_addr, dev_addr, ETH_ALEN);
490 p2p->dev_addr[0] |= 0x02;
492 /* Generate the P2P Interface Address. If the discovery and connection
493 * BSSCFGs need to simultaneously co-exist, then this address must be
494 * different from the P2P Device Address, but also locally administered.
496 memcpy(p2p->conn_int_addr, p2p->dev_addr, ETH_ALEN);
497 p2p->conn_int_addr[0] |= 0x02;
498 p2p->conn_int_addr[4] ^= 0x80;
500 memcpy(p2p->conn2_int_addr, p2p->dev_addr, ETH_ALEN);
501 p2p->conn2_int_addr[0] |= 0x02;
502 p2p->conn2_int_addr[4] ^= 0x90;
506 * brcmf_p2p_scan_is_p2p_request() - is cfg80211 scan request a P2P scan.
508 * @request: the scan request as received from cfg80211.
510 * returns true if one of the ssids in the request matches the
511 * P2P wildcard ssid; otherwise returns false.
513 static bool brcmf_p2p_scan_is_p2p_request(struct cfg80211_scan_request *request)
515 struct cfg80211_ssid *ssids = request->ssids;
518 for (i = 0; i < request->n_ssids; i++) {
519 if (ssids[i].ssid_len != BRCMF_P2P_WILDCARD_SSID_LEN)
522 brcmf_dbg(INFO, "comparing ssid \"%s\"", ssids[i].ssid);
523 if (!memcmp(BRCMF_P2P_WILDCARD_SSID, ssids[i].ssid,
524 BRCMF_P2P_WILDCARD_SSID_LEN))
531 * brcmf_p2p_set_discover_state - set discover state in firmware.
533 * @ifp: low-level interface object.
534 * @state: discover state to set.
535 * @chanspec: channel parameters (for state @WL_P2P_DISC_ST_LISTEN only).
536 * @listen_ms: duration to listen (for state @WL_P2P_DISC_ST_LISTEN only).
538 static s32 brcmf_p2p_set_discover_state(struct brcmf_if *ifp, u8 state,
539 u16 chanspec, u16 listen_ms)
541 struct brcmf_p2p_disc_st_le discover_state;
543 brcmf_dbg(TRACE, "enter\n");
545 discover_state.state = state;
546 discover_state.chspec = cpu_to_le16(chanspec);
547 discover_state.dwell = cpu_to_le16(listen_ms);
548 ret = brcmf_fil_bsscfg_data_set(ifp, "p2p_state", &discover_state,
549 sizeof(discover_state));
554 * brcmf_p2p_deinit_discovery() - disable P2P device discovery.
556 * @p2p: P2P specific data.
558 * Resets the discovery state and disables it in firmware.
560 static s32 brcmf_p2p_deinit_discovery(struct brcmf_p2p_info *p2p)
562 struct brcmf_cfg80211_vif *vif;
564 brcmf_dbg(TRACE, "enter\n");
566 /* Set the discovery state to SCAN */
567 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
568 (void)brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
570 /* Disable P2P discovery in the firmware */
571 vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
572 (void)brcmf_fil_iovar_int_set(vif->ifp, "p2p_disc", 0);
578 * brcmf_p2p_enable_discovery() - initialize and configure discovery.
580 * @p2p: P2P specific data.
582 * Initializes the discovery device and configure the virtual interface.
584 static int brcmf_p2p_enable_discovery(struct brcmf_p2p_info *p2p)
586 struct brcmf_pub *drvr = p2p->cfg->pub;
587 struct brcmf_cfg80211_vif *vif;
590 brcmf_dbg(TRACE, "enter\n");
591 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
593 bphy_err(drvr, "P2P config device not available\n");
598 if (test_bit(BRCMF_P2P_STATUS_ENABLED, &p2p->status)) {
599 brcmf_dbg(INFO, "P2P config device already configured\n");
603 /* Re-initialize P2P Discovery in the firmware */
604 vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
605 ret = brcmf_fil_iovar_int_set(vif->ifp, "p2p_disc", 1);
607 bphy_err(drvr, "set p2p_disc error\n");
610 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
611 ret = brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
613 bphy_err(drvr, "unable to set WL_P2P_DISC_ST_SCAN\n");
618 * Set wsec to any non-zero value in the discovery bsscfg
619 * to ensure our P2P probe responses have the privacy bit
620 * set in the 802.11 WPA IE. Some peer devices may not
621 * initiate WPS with us if this bit is not set.
623 ret = brcmf_fil_bsscfg_int_set(vif->ifp, "wsec", AES_ENABLED);
625 bphy_err(drvr, "wsec error %d\n", ret);
629 set_bit(BRCMF_P2P_STATUS_ENABLED, &p2p->status);
635 * brcmf_p2p_escan() - initiate a P2P scan.
637 * @p2p: P2P specific data.
638 * @num_chans: number of channels to scan.
639 * @chanspecs: channel parameters for @num_chans channels.
640 * @search_state: P2P discover state to use.
641 * @bss_type: type of P2P bss.
643 static s32 brcmf_p2p_escan(struct brcmf_p2p_info *p2p, u32 num_chans,
644 u16 chanspecs[], s32 search_state,
645 enum p2p_bss_type bss_type)
647 struct brcmf_pub *drvr = p2p->cfg->pub;
649 s32 memsize = offsetof(struct brcmf_p2p_scan_le,
650 eparams.params_le.channel_list);
655 struct brcmf_cfg80211_vif *vif;
656 struct brcmf_p2p_scan_le *p2p_params;
657 struct brcmf_scan_params_le *sparams;
659 memsize += num_chans * sizeof(__le16);
660 memblk = kzalloc(memsize, GFP_KERNEL);
664 vif = p2p->bss_idx[bss_type].vif;
666 bphy_err(drvr, "no vif for bss type %d\n", bss_type);
670 p2p_params = (struct brcmf_p2p_scan_le *)memblk;
671 sparams = &p2p_params->eparams.params_le;
673 switch (search_state) {
674 case WL_P2P_DISC_ST_SEARCH:
676 * If we in SEARCH STATE, we don't need to set SSID explictly
677 * because dongle use P2P WILDCARD internally by default, use
678 * null ssid, which it is already due to kzalloc.
681 case WL_P2P_DISC_ST_SCAN:
683 * wpa_supplicant has p2p_find command with type social or
684 * progressive. For progressive, we need to set the ssid to
685 * P2P WILDCARD because we just do broadcast scan unless
688 sparams->ssid_le.SSID_len =
689 cpu_to_le32(BRCMF_P2P_WILDCARD_SSID_LEN);
690 memcpy(sparams->ssid_le.SSID, BRCMF_P2P_WILDCARD_SSID,
691 BRCMF_P2P_WILDCARD_SSID_LEN);
694 bphy_err(drvr, " invalid search state %d\n", search_state);
699 brcmf_p2p_set_discover_state(vif->ifp, search_state, 0, 0);
702 * set p2p scan parameters.
704 p2p_params->type = 'E';
706 /* determine the scan engine parameters */
707 sparams->bss_type = DOT11_BSSTYPE_ANY;
708 sparams->scan_type = BRCMF_SCANTYPE_ACTIVE;
710 eth_broadcast_addr(sparams->bssid);
711 sparams->home_time = cpu_to_le32(P2PAPI_SCAN_HOME_TIME_MS);
714 * SOCIAL_CHAN_CNT + 1 takes care of the Progressive scan
715 * supported by the supplicant.
717 if (num_chans == SOCIAL_CHAN_CNT || num_chans == (SOCIAL_CHAN_CNT + 1))
718 active = P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS;
719 else if (num_chans == AF_PEER_SEARCH_CNT)
720 active = P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS;
721 else if (brcmf_get_vif_state_any(p2p->cfg, BRCMF_VIF_STATUS_CONNECTED))
724 active = P2PAPI_SCAN_DWELL_TIME_MS;
726 /* Override scan params to find a peer for a connection */
727 if (num_chans == 1) {
728 active = WL_SCAN_CONNECT_DWELL_TIME_MS;
729 /* WAR to sync with presence period of VSDB GO.
730 * send probe request more frequently
732 nprobes = active / WL_SCAN_JOIN_PROBE_INTERVAL_MS;
734 nprobes = active / P2PAPI_SCAN_NPROBS_TIME_MS;
740 brcmf_dbg(INFO, "nprobes # %d, active_time %d\n", nprobes, active);
741 sparams->active_time = cpu_to_le32(active);
742 sparams->nprobes = cpu_to_le32(nprobes);
743 sparams->passive_time = cpu_to_le32(-1);
744 sparams->channel_num = cpu_to_le32(num_chans &
745 BRCMF_SCAN_PARAMS_COUNT_MASK);
746 for (i = 0; i < num_chans; i++)
747 sparams->channel_list[i] = cpu_to_le16(chanspecs[i]);
749 /* set the escan specific parameters */
750 p2p_params->eparams.version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION);
751 p2p_params->eparams.action = cpu_to_le16(WL_ESCAN_ACTION_START);
752 p2p_params->eparams.sync_id = cpu_to_le16(0x1234);
753 /* perform p2p scan on primary device */
754 ret = brcmf_fil_bsscfg_data_set(vif->ifp, "p2p_scan", memblk, memsize);
756 set_bit(BRCMF_SCAN_STATUS_BUSY, &p2p->cfg->scan_status);
763 * brcmf_p2p_run_escan() - escan callback for peer-to-peer.
765 * @cfg: driver private data for cfg80211 interface.
766 * @ifp: interface control.
767 * @request: scan request from cfg80211.
769 * Determines the P2P discovery state based to scan request parameters and
770 * validates the channels in the request.
772 static s32 brcmf_p2p_run_escan(struct brcmf_cfg80211_info *cfg,
773 struct brcmf_if *ifp,
774 struct cfg80211_scan_request *request)
776 struct brcmf_p2p_info *p2p = &cfg->p2p;
777 struct brcmf_pub *drvr = cfg->pub;
779 s32 search_state = WL_P2P_DISC_ST_SCAN;
780 struct brcmf_cfg80211_vif *vif;
781 struct net_device *dev = NULL;
782 int i, num_nodfs = 0;
785 brcmf_dbg(TRACE, "enter\n");
792 if (request->n_channels) {
793 chanspecs = kcalloc(request->n_channels, sizeof(*chanspecs),
799 vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif;
801 dev = vif->wdev.netdev;
802 if (request->n_channels == 3 &&
803 request->channels[0]->hw_value == SOCIAL_CHAN_1 &&
804 request->channels[1]->hw_value == SOCIAL_CHAN_2 &&
805 request->channels[2]->hw_value == SOCIAL_CHAN_3) {
806 /* SOCIAL CHANNELS 1, 6, 11 */
807 search_state = WL_P2P_DISC_ST_SEARCH;
808 brcmf_dbg(INFO, "P2P SEARCH PHASE START\n");
809 } else if (dev != NULL &&
810 vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) {
811 /* If you are already a GO, then do SEARCH only */
812 brcmf_dbg(INFO, "Already a GO. Do SEARCH Only\n");
813 search_state = WL_P2P_DISC_ST_SEARCH;
815 brcmf_dbg(INFO, "P2P SCAN STATE START\n");
819 * no P2P scanning on passive or DFS channels.
821 for (i = 0; i < request->n_channels; i++) {
822 struct ieee80211_channel *chan = request->channels[i];
824 if (chan->flags & (IEEE80211_CHAN_RADAR |
825 IEEE80211_CHAN_NO_IR))
828 chanspecs[i] = channel_to_chanspec(&p2p->cfg->d11inf,
830 brcmf_dbg(INFO, "%d: chan=%d, channel spec=%x\n",
831 num_nodfs, chan->hw_value, chanspecs[i]);
834 err = brcmf_p2p_escan(p2p, num_nodfs, chanspecs, search_state,
835 P2PAPI_BSSCFG_DEVICE);
840 bphy_err(drvr, "error (%d)\n", err);
846 * brcmf_p2p_find_listen_channel() - find listen channel in ie string.
848 * @ie: string of information elements.
849 * @ie_len: length of string.
851 * Scan ie for p2p ie and look for attribute 6 channel. If available determine
852 * channel and return it.
854 static s32 brcmf_p2p_find_listen_channel(const u8 *ie, u32 ie_len)
860 err = cfg80211_get_p2p_attr(ie, ie_len,
861 IEEE80211_P2P_ATTR_LISTEN_CHANNEL,
862 channel_ie, sizeof(channel_ie));
866 /* listen channel subel length format: */
867 /* 3(country) + 1(op. class) + 1(chan num) */
868 listen_channel = (s32)channel_ie[3 + 1];
870 if (listen_channel == SOCIAL_CHAN_1 ||
871 listen_channel == SOCIAL_CHAN_2 ||
872 listen_channel == SOCIAL_CHAN_3) {
873 brcmf_dbg(INFO, "Found my Listen Channel %d\n", listen_channel);
874 return listen_channel;
882 * brcmf_p2p_scan_prep() - prepare scan based on request.
884 * @wiphy: wiphy device.
885 * @request: scan request from cfg80211.
886 * @vif: vif on which scan request is to be executed.
888 * Prepare the scan appropriately for type of scan requested. Overrides the
889 * escan .run() callback for peer-to-peer scanning.
891 int brcmf_p2p_scan_prep(struct wiphy *wiphy,
892 struct cfg80211_scan_request *request,
893 struct brcmf_cfg80211_vif *vif)
895 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
896 struct brcmf_p2p_info *p2p = &cfg->p2p;
899 if (brcmf_p2p_scan_is_p2p_request(request)) {
900 /* find my listen channel */
901 err = brcmf_p2p_find_listen_channel(request->ie,
906 p2p->afx_hdl.my_listen_chan = err;
908 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
909 brcmf_dbg(INFO, "P2P: GO_NEG_PHASE status cleared\n");
911 err = brcmf_p2p_enable_discovery(p2p);
915 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
917 /* override .run_escan() callback. */
918 cfg->escan_info.run = brcmf_p2p_run_escan;
920 err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBREQ_FLAG,
921 request->ie, request->ie_len);
927 * brcmf_p2p_discover_listen() - set firmware to discover listen state.
930 * @channel: channel nr for discover listen.
931 * @duration: time in ms to stay on channel.
935 brcmf_p2p_discover_listen(struct brcmf_p2p_info *p2p, u16 channel, u32 duration)
937 struct brcmf_pub *drvr = p2p->cfg->pub;
938 struct brcmf_cfg80211_vif *vif;
939 struct brcmu_chan ch;
942 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
944 bphy_err(drvr, "Discovery is not set, so we have nothing to do\n");
949 if (test_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, &p2p->status)) {
950 bphy_err(drvr, "Previous LISTEN is not completed yet\n");
951 /* WAR: prevent cookie mismatch in wpa_supplicant return OK */
956 ch.bw = BRCMU_CHAN_BW_20;
957 p2p->cfg->d11inf.encchspec(&ch);
958 err = brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_LISTEN,
959 ch.chspec, (u16)duration);
961 set_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, &p2p->status);
962 p2p->remain_on_channel_cookie++;
970 * brcmf_p2p_remain_on_channel() - put device on channel and stay there.
972 * @wiphy: wiphy device.
973 * @wdev: wireless device.
974 * @channel: channel to stay on.
975 * @duration: time in ms to remain on channel.
978 int brcmf_p2p_remain_on_channel(struct wiphy *wiphy, struct wireless_dev *wdev,
979 struct ieee80211_channel *channel,
980 unsigned int duration, u64 *cookie)
982 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
983 struct brcmf_p2p_info *p2p = &cfg->p2p;
987 channel_nr = ieee80211_frequency_to_channel(channel->center_freq);
988 brcmf_dbg(TRACE, "Enter, channel: %d, duration ms (%d)\n", channel_nr,
991 err = brcmf_p2p_enable_discovery(p2p);
994 err = brcmf_p2p_discover_listen(p2p, channel_nr, duration);
998 memcpy(&p2p->remain_on_channel, channel, sizeof(*channel));
999 *cookie = p2p->remain_on_channel_cookie;
1000 cfg80211_ready_on_channel(wdev, *cookie, channel, duration, GFP_KERNEL);
1008 * brcmf_p2p_notify_listen_complete() - p2p listen has completed.
1010 * @ifp: interfac control.
1011 * @e: event message. Not used, to make it usable for fweh event dispatcher.
1012 * @data: payload of message. Not used.
1015 int brcmf_p2p_notify_listen_complete(struct brcmf_if *ifp,
1016 const struct brcmf_event_msg *e,
1019 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
1020 struct brcmf_p2p_info *p2p = &cfg->p2p;
1022 brcmf_dbg(TRACE, "Enter\n");
1023 if (test_and_clear_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN,
1025 if (test_and_clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN,
1027 clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME,
1029 brcmf_dbg(INFO, "Listen DONE, wake up wait_next_af\n");
1030 complete(&p2p->wait_next_af);
1033 cfg80211_remain_on_channel_expired(&ifp->vif->wdev,
1034 p2p->remain_on_channel_cookie,
1035 &p2p->remain_on_channel,
1043 * brcmf_p2p_cancel_remain_on_channel() - cancel p2p listen state.
1045 * @ifp: interfac control.
1048 void brcmf_p2p_cancel_remain_on_channel(struct brcmf_if *ifp)
1052 brcmf_p2p_set_discover_state(ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
1053 brcmf_p2p_notify_listen_complete(ifp, NULL, NULL);
1058 * brcmf_p2p_act_frm_search() - search function for action frame.
1061 * @channel: channel on which action frame is to be trasmitted.
1063 * search function to reach at common channel to send action frame. When
1064 * channel is 0 then all social channels will be used to send af
1066 static s32 brcmf_p2p_act_frm_search(struct brcmf_p2p_info *p2p, u16 channel)
1068 struct brcmf_pub *drvr = p2p->cfg->pub;
1071 u16 *default_chan_list;
1073 struct brcmu_chan ch;
1075 brcmf_dbg(TRACE, "Enter\n");
1078 channel_cnt = AF_PEER_SEARCH_CNT;
1080 channel_cnt = SOCIAL_CHAN_CNT;
1081 default_chan_list = kcalloc(channel_cnt, sizeof(*default_chan_list),
1083 if (default_chan_list == NULL) {
1084 bphy_err(drvr, "channel list allocation failed\n");
1088 ch.bw = BRCMU_CHAN_BW_20;
1091 p2p->cfg->d11inf.encchspec(&ch);
1092 /* insert same channel to the chan_list */
1093 for (i = 0; i < channel_cnt; i++)
1094 default_chan_list[i] = ch.chspec;
1096 ch.chnum = SOCIAL_CHAN_1;
1097 p2p->cfg->d11inf.encchspec(&ch);
1098 default_chan_list[0] = ch.chspec;
1099 ch.chnum = SOCIAL_CHAN_2;
1100 p2p->cfg->d11inf.encchspec(&ch);
1101 default_chan_list[1] = ch.chspec;
1102 ch.chnum = SOCIAL_CHAN_3;
1103 p2p->cfg->d11inf.encchspec(&ch);
1104 default_chan_list[2] = ch.chspec;
1106 err = brcmf_p2p_escan(p2p, channel_cnt, default_chan_list,
1107 WL_P2P_DISC_ST_SEARCH, P2PAPI_BSSCFG_DEVICE);
1108 kfree(default_chan_list);
1115 * brcmf_p2p_afx_handler() - afx worker thread.
1120 static void brcmf_p2p_afx_handler(struct work_struct *work)
1122 struct afx_hdl *afx_hdl = container_of(work, struct afx_hdl, afx_work);
1123 struct brcmf_p2p_info *p2p = container_of(afx_hdl,
1124 struct brcmf_p2p_info,
1126 struct brcmf_pub *drvr = p2p->cfg->pub;
1129 if (!afx_hdl->is_active)
1132 if (afx_hdl->is_listen && afx_hdl->my_listen_chan)
1134 err = brcmf_p2p_discover_listen(p2p, afx_hdl->my_listen_chan,
1135 100 * (1 + prandom_u32() % 3));
1137 err = brcmf_p2p_act_frm_search(p2p, afx_hdl->peer_listen_chan);
1140 bphy_err(drvr, "ERROR occurred! value is (%d)\n", err);
1141 if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL,
1143 complete(&afx_hdl->act_frm_scan);
1149 * brcmf_p2p_af_searching_channel() - search channel.
1151 * @p2p: p2p device info struct.
1154 static s32 brcmf_p2p_af_searching_channel(struct brcmf_p2p_info *p2p)
1156 struct afx_hdl *afx_hdl = &p2p->afx_hdl;
1157 struct brcmf_cfg80211_vif *pri_vif;
1160 brcmf_dbg(TRACE, "Enter\n");
1162 pri_vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
1164 reinit_completion(&afx_hdl->act_frm_scan);
1165 set_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, &p2p->status);
1166 afx_hdl->is_active = true;
1167 afx_hdl->peer_chan = P2P_INVALID_CHANNEL;
1169 /* Loop to wait until we find a peer's channel or the
1170 * pending action frame tx is cancelled.
1173 while ((retry < P2P_CHANNEL_SYNC_RETRY) &&
1174 (afx_hdl->peer_chan == P2P_INVALID_CHANNEL)) {
1175 afx_hdl->is_listen = false;
1176 brcmf_dbg(TRACE, "Scheduling action frame for sending.. (%d)\n",
1178 /* search peer on peer's listen channel */
1179 schedule_work(&afx_hdl->afx_work);
1180 wait_for_completion_timeout(&afx_hdl->act_frm_scan,
1181 P2P_AF_FRM_SCAN_MAX_WAIT);
1182 if ((afx_hdl->peer_chan != P2P_INVALID_CHANNEL) ||
1183 (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL,
1187 if (afx_hdl->my_listen_chan) {
1188 brcmf_dbg(TRACE, "Scheduling listen peer, channel=%d\n",
1189 afx_hdl->my_listen_chan);
1190 /* listen on my listen channel */
1191 afx_hdl->is_listen = true;
1192 schedule_work(&afx_hdl->afx_work);
1193 wait_for_completion_timeout(&afx_hdl->act_frm_scan,
1194 P2P_AF_FRM_SCAN_MAX_WAIT);
1196 if ((afx_hdl->peer_chan != P2P_INVALID_CHANNEL) ||
1197 (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL,
1202 /* if sta is connected or connecting, sleep for a while before
1203 * retry af tx or finding a peer
1205 if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &pri_vif->sme_state) ||
1206 test_bit(BRCMF_VIF_STATUS_CONNECTING, &pri_vif->sme_state))
1207 msleep(P2P_DEFAULT_SLEEP_TIME_VSDB);
1210 brcmf_dbg(TRACE, "Completed search/listen peer_chan=%d\n",
1211 afx_hdl->peer_chan);
1212 afx_hdl->is_active = false;
1214 clear_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, &p2p->status);
1216 return afx_hdl->peer_chan;
1221 * brcmf_p2p_scan_finding_common_channel() - was escan used for finding channel
1223 * @cfg: common configuration struct.
1224 * @bi: bss info struct, result from scan.
1227 bool brcmf_p2p_scan_finding_common_channel(struct brcmf_cfg80211_info *cfg,
1228 struct brcmf_bss_info_le *bi)
1231 struct brcmf_p2p_info *p2p = &cfg->p2p;
1232 struct afx_hdl *afx_hdl = &p2p->afx_hdl;
1233 struct brcmu_chan ch;
1236 u8 p2p_dev_addr[ETH_ALEN];
1238 if (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, &p2p->status))
1242 brcmf_dbg(TRACE, "ACTION FRAME SCAN Done\n");
1243 if (afx_hdl->peer_chan == P2P_INVALID_CHANNEL)
1244 complete(&afx_hdl->act_frm_scan);
1248 ie = ((u8 *)bi) + le16_to_cpu(bi->ie_offset);
1249 memset(p2p_dev_addr, 0, sizeof(p2p_dev_addr));
1250 err = cfg80211_get_p2p_attr(ie, le32_to_cpu(bi->ie_length),
1251 IEEE80211_P2P_ATTR_DEVICE_INFO,
1252 p2p_dev_addr, sizeof(p2p_dev_addr));
1254 err = cfg80211_get_p2p_attr(ie, le32_to_cpu(bi->ie_length),
1255 IEEE80211_P2P_ATTR_DEVICE_ID,
1256 p2p_dev_addr, sizeof(p2p_dev_addr));
1258 (ether_addr_equal(p2p_dev_addr, afx_hdl->tx_dst_addr))) {
1260 ch.chspec = le16_to_cpu(bi->chanspec);
1261 cfg->d11inf.decchspec(&ch);
1262 bi->ctl_ch = ch.control_ch_num;
1264 afx_hdl->peer_chan = bi->ctl_ch;
1265 brcmf_dbg(TRACE, "ACTION FRAME SCAN : Peer %pM found, channel : %d\n",
1266 afx_hdl->tx_dst_addr, afx_hdl->peer_chan);
1267 complete(&afx_hdl->act_frm_scan);
1273 * brcmf_p2p_abort_action_frame() - abort action frame.
1275 * @cfg: common configuration struct.
1278 static s32 brcmf_p2p_abort_action_frame(struct brcmf_cfg80211_info *cfg)
1280 struct brcmf_p2p_info *p2p = &cfg->p2p;
1281 struct brcmf_cfg80211_vif *vif;
1285 brcmf_dbg(TRACE, "Enter\n");
1287 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
1288 err = brcmf_fil_bsscfg_data_set(vif->ifp, "actframe_abort", &int_val,
1291 brcmf_err(" aborting action frame has failed (%d)\n", err);
1297 * brcmf_p2p_stop_wait_next_action_frame() - finish scan if af tx complete.
1299 * @cfg: common configuration struct.
1303 brcmf_p2p_stop_wait_next_action_frame(struct brcmf_cfg80211_info *cfg)
1305 struct brcmf_p2p_info *p2p = &cfg->p2p;
1306 struct brcmf_if *ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
1309 if (test_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME, &p2p->status) &&
1310 (test_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status) ||
1311 test_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status))) {
1312 brcmf_dbg(TRACE, "*** Wake UP ** abort actframe iovar\n");
1313 /* if channel is not zero, "actfame" uses off channel scan.
1314 * So abort scan for off channel completion.
1316 if (p2p->af_sent_channel) {
1317 /* abort actframe using actframe_abort or abort scan */
1318 err = brcmf_p2p_abort_action_frame(cfg);
1320 brcmf_notify_escan_complete(cfg, ifp, true,
1323 } else if (test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN,
1325 brcmf_dbg(TRACE, "*** Wake UP ** abort listen for next af frame\n");
1326 /* So abort scan to cancel listen */
1327 brcmf_notify_escan_complete(cfg, ifp, true, true);
1333 * brcmf_p2p_gon_req_collision() - Check if go negotiaton collission
1335 * @p2p: p2p device info struct.
1336 * @mac: MAC address.
1338 * return true if recevied action frame is to be dropped.
1341 brcmf_p2p_gon_req_collision(struct brcmf_p2p_info *p2p, u8 *mac)
1343 struct brcmf_cfg80211_info *cfg = p2p->cfg;
1344 struct brcmf_if *ifp;
1346 brcmf_dbg(TRACE, "Enter\n");
1348 if (!test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, &p2p->status) ||
1349 !p2p->gon_req_action)
1352 brcmf_dbg(TRACE, "GO Negotiation Request COLLISION !!!\n");
1353 /* if sa(peer) addr is less than da(my) addr, then this device
1354 * process peer's gon request and block to send gon req.
1355 * if not (sa addr > da addr),
1356 * this device will process gon request and drop gon req of peer.
1358 ifp = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif->ifp;
1359 if (memcmp(mac, ifp->mac_addr, ETH_ALEN) < 0) {
1360 brcmf_dbg(INFO, "Block transmit gon req !!!\n");
1361 p2p->block_gon_req_tx = true;
1362 /* if we are finding a common channel for sending af,
1363 * do not scan more to block to send current gon req
1365 if (test_and_clear_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL,
1367 complete(&p2p->afx_hdl.act_frm_scan);
1368 if (test_and_clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME,
1370 brcmf_p2p_stop_wait_next_action_frame(cfg);
1374 /* drop gon request of peer to process gon request by this device. */
1375 brcmf_dbg(INFO, "Drop received gon req !!!\n");
1382 * brcmf_p2p_notify_action_frame_rx() - received action frame.
1384 * @ifp: interfac control.
1385 * @e: event message. Not used, to make it usable for fweh event dispatcher.
1386 * @data: payload of message, containing action frame data.
1389 int brcmf_p2p_notify_action_frame_rx(struct brcmf_if *ifp,
1390 const struct brcmf_event_msg *e,
1393 struct brcmf_pub *drvr = ifp->drvr;
1394 struct brcmf_cfg80211_info *cfg = drvr->config;
1395 struct brcmf_p2p_info *p2p = &cfg->p2p;
1396 struct afx_hdl *afx_hdl = &p2p->afx_hdl;
1397 struct wireless_dev *wdev;
1398 u32 mgmt_frame_len = e->datalen - sizeof(struct brcmf_rx_mgmt_data);
1399 struct brcmf_rx_mgmt_data *rxframe = (struct brcmf_rx_mgmt_data *)data;
1400 u8 *frame = (u8 *)(rxframe + 1);
1401 struct brcmf_p2p_pub_act_frame *act_frm;
1402 struct brcmf_p2psd_gas_pub_act_frame *sd_act_frm;
1403 struct brcmu_chan ch;
1404 struct ieee80211_mgmt *mgmt_frame;
1409 if (e->datalen < sizeof(*rxframe)) {
1410 brcmf_dbg(SCAN, "Event data to small. Ignore\n");
1414 ch.chspec = be16_to_cpu(rxframe->chanspec);
1415 cfg->d11inf.decchspec(&ch);
1416 /* Check if wpa_supplicant has registered for this frame */
1417 brcmf_dbg(INFO, "ifp->vif->mgmt_rx_reg %04x\n", ifp->vif->mgmt_rx_reg);
1418 mgmt_type = (IEEE80211_STYPE_ACTION & IEEE80211_FCTL_STYPE) >> 4;
1419 if ((ifp->vif->mgmt_rx_reg & BIT(mgmt_type)) == 0)
1422 brcmf_p2p_print_actframe(false, frame, mgmt_frame_len);
1424 action = P2P_PAF_SUBTYPE_INVALID;
1425 if (brcmf_p2p_is_pub_action(frame, mgmt_frame_len)) {
1426 act_frm = (struct brcmf_p2p_pub_act_frame *)frame;
1427 action = act_frm->subtype;
1428 if ((action == P2P_PAF_GON_REQ) &&
1429 (brcmf_p2p_gon_req_collision(p2p, (u8 *)e->addr))) {
1430 if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL,
1432 (ether_addr_equal(afx_hdl->tx_dst_addr, e->addr))) {
1433 afx_hdl->peer_chan = ch.control_ch_num;
1434 brcmf_dbg(INFO, "GON request: Peer found, channel=%d\n",
1435 afx_hdl->peer_chan);
1436 complete(&afx_hdl->act_frm_scan);
1440 /* After complete GO Negotiation, roll back to mpc mode */
1441 if ((action == P2P_PAF_GON_CONF) ||
1442 (action == P2P_PAF_PROVDIS_RSP))
1443 brcmf_set_mpc(ifp, 1);
1444 if (action == P2P_PAF_GON_CONF) {
1445 brcmf_dbg(TRACE, "P2P: GO_NEG_PHASE status cleared\n");
1446 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
1448 } else if (brcmf_p2p_is_gas_action(frame, mgmt_frame_len)) {
1449 sd_act_frm = (struct brcmf_p2psd_gas_pub_act_frame *)frame;
1450 action = sd_act_frm->action;
1453 if (test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, &p2p->status) &&
1454 (p2p->next_af_subtype == action)) {
1455 brcmf_dbg(TRACE, "We got a right next frame! (%d)\n", action);
1456 clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME,
1458 /* Stop waiting for next AF. */
1459 brcmf_p2p_stop_wait_next_action_frame(cfg);
1462 mgmt_frame = kzalloc(offsetof(struct ieee80211_mgmt, u) +
1463 mgmt_frame_len, GFP_KERNEL);
1465 bphy_err(drvr, "No memory available for action frame\n");
1468 memcpy(mgmt_frame->da, ifp->mac_addr, ETH_ALEN);
1469 brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSSID, mgmt_frame->bssid,
1471 memcpy(mgmt_frame->sa, e->addr, ETH_ALEN);
1472 mgmt_frame->frame_control = cpu_to_le16(IEEE80211_STYPE_ACTION);
1473 memcpy(&mgmt_frame->u, frame, mgmt_frame_len);
1474 mgmt_frame_len += offsetof(struct ieee80211_mgmt, u);
1476 freq = ieee80211_channel_to_frequency(ch.control_ch_num,
1477 ch.band == BRCMU_CHAN_BAND_2G ?
1481 wdev = &ifp->vif->wdev;
1482 cfg80211_rx_mgmt(wdev, freq, 0, (u8 *)mgmt_frame, mgmt_frame_len, 0);
1490 * brcmf_p2p_notify_action_tx_complete() - transmit action frame complete
1492 * @ifp: interfac control.
1493 * @e: event message. Not used, to make it usable for fweh event dispatcher.
1497 int brcmf_p2p_notify_action_tx_complete(struct brcmf_if *ifp,
1498 const struct brcmf_event_msg *e,
1501 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
1502 struct brcmf_p2p_info *p2p = &cfg->p2p;
1504 brcmf_dbg(INFO, "Enter: event %s, status=%d\n",
1505 e->event_code == BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE ?
1506 "ACTION_FRAME_OFF_CHAN_COMPLETE" : "ACTION_FRAME_COMPLETE",
1509 if (!test_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME, &p2p->status))
1512 if (e->event_code == BRCMF_E_ACTION_FRAME_COMPLETE) {
1513 if (e->status == BRCMF_E_STATUS_SUCCESS) {
1514 set_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED,
1516 if (!p2p->wait_for_offchan_complete)
1517 complete(&p2p->send_af_done);
1519 set_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
1520 /* If there is no ack, we don't need to wait for
1521 * WLC_E_ACTION_FRAME_OFFCHAN_COMPLETE event
1523 brcmf_p2p_stop_wait_next_action_frame(cfg);
1527 complete(&p2p->send_af_done);
1534 * brcmf_p2p_tx_action_frame() - send action frame over fil.
1536 * @p2p: p2p info struct for vif.
1537 * @af_params: action frame data/info.
1539 * Send an action frame immediately without doing channel synchronization.
1541 * This function waits for a completion event before returning.
1542 * The WLC_E_ACTION_FRAME_COMPLETE event will be received when the action
1543 * frame is transmitted.
1545 static s32 brcmf_p2p_tx_action_frame(struct brcmf_p2p_info *p2p,
1546 struct brcmf_fil_af_params_le *af_params)
1548 struct brcmf_pub *drvr = p2p->cfg->pub;
1549 struct brcmf_cfg80211_vif *vif;
1550 struct brcmf_p2p_action_frame *p2p_af;
1553 brcmf_dbg(TRACE, "Enter\n");
1555 reinit_completion(&p2p->send_af_done);
1556 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
1557 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
1559 /* check if it is a p2p_presence response */
1560 p2p_af = (struct brcmf_p2p_action_frame *)af_params->action_frame.data;
1561 if (p2p_af->subtype == P2P_AF_PRESENCE_RSP)
1562 vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif;
1564 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
1566 err = brcmf_fil_bsscfg_data_set(vif->ifp, "actframe", af_params,
1567 sizeof(*af_params));
1569 bphy_err(drvr, " sending action frame has failed\n");
1573 p2p->af_sent_channel = le32_to_cpu(af_params->channel);
1574 p2p->af_tx_sent_jiffies = jiffies;
1576 if (test_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, &p2p->status) &&
1577 p2p->af_sent_channel ==
1578 ieee80211_frequency_to_channel(p2p->remain_on_channel.center_freq))
1579 p2p->wait_for_offchan_complete = false;
1581 p2p->wait_for_offchan_complete = true;
1583 brcmf_dbg(TRACE, "Waiting for %s tx completion event\n",
1584 (p2p->wait_for_offchan_complete) ?
1585 "off-channel" : "on-channel");
1587 wait_for_completion_timeout(&p2p->send_af_done, P2P_AF_MAX_WAIT_TIME);
1589 if (test_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status)) {
1590 brcmf_dbg(TRACE, "TX action frame operation is success\n");
1593 brcmf_dbg(TRACE, "TX action frame operation has failed\n");
1595 /* clear status bit for action tx */
1596 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
1597 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
1605 * brcmf_p2p_pub_af_tx() - public action frame tx routine.
1607 * @cfg: driver private data for cfg80211 interface.
1608 * @af_params: action frame data/info.
1609 * @config_af_params: configuration data for action frame.
1611 * routine which transmits ation frame public type.
1613 static s32 brcmf_p2p_pub_af_tx(struct brcmf_cfg80211_info *cfg,
1614 struct brcmf_fil_af_params_le *af_params,
1615 struct brcmf_config_af_params *config_af_params)
1617 struct brcmf_p2p_info *p2p = &cfg->p2p;
1618 struct brcmf_pub *drvr = cfg->pub;
1619 struct brcmf_fil_action_frame_le *action_frame;
1620 struct brcmf_p2p_pub_act_frame *act_frm;
1624 action_frame = &af_params->action_frame;
1625 act_frm = (struct brcmf_p2p_pub_act_frame *)(action_frame->data);
1627 config_af_params->extra_listen = true;
1629 switch (act_frm->subtype) {
1630 case P2P_PAF_GON_REQ:
1631 brcmf_dbg(TRACE, "P2P: GO_NEG_PHASE status set\n");
1632 set_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
1633 config_af_params->mpc_onoff = 0;
1634 config_af_params->search_channel = true;
1635 p2p->next_af_subtype = act_frm->subtype + 1;
1636 p2p->gon_req_action = true;
1637 /* increase dwell time to wait for RESP frame */
1638 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1640 case P2P_PAF_GON_RSP:
1641 p2p->next_af_subtype = act_frm->subtype + 1;
1642 /* increase dwell time to wait for CONF frame */
1643 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1645 case P2P_PAF_GON_CONF:
1646 /* If we reached till GO Neg confirmation reset the filter */
1647 brcmf_dbg(TRACE, "P2P: GO_NEG_PHASE status cleared\n");
1648 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
1649 /* turn on mpc again if go nego is done */
1650 config_af_params->mpc_onoff = 1;
1651 /* minimize dwell time */
1652 af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
1653 config_af_params->extra_listen = false;
1655 case P2P_PAF_INVITE_REQ:
1656 config_af_params->search_channel = true;
1657 p2p->next_af_subtype = act_frm->subtype + 1;
1658 /* increase dwell time */
1659 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1661 case P2P_PAF_INVITE_RSP:
1662 /* minimize dwell time */
1663 af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
1664 config_af_params->extra_listen = false;
1666 case P2P_PAF_DEVDIS_REQ:
1667 config_af_params->search_channel = true;
1668 p2p->next_af_subtype = act_frm->subtype + 1;
1669 /* maximize dwell time to wait for RESP frame */
1670 af_params->dwell_time = cpu_to_le32(P2P_AF_LONG_DWELL_TIME);
1672 case P2P_PAF_DEVDIS_RSP:
1673 /* minimize dwell time */
1674 af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
1675 config_af_params->extra_listen = false;
1677 case P2P_PAF_PROVDIS_REQ:
1678 ie_len = le16_to_cpu(action_frame->len) -
1679 offsetof(struct brcmf_p2p_pub_act_frame, elts);
1680 if (cfg80211_get_p2p_attr(&act_frm->elts[0], ie_len,
1681 IEEE80211_P2P_ATTR_GROUP_ID,
1683 config_af_params->search_channel = true;
1684 config_af_params->mpc_onoff = 0;
1685 p2p->next_af_subtype = act_frm->subtype + 1;
1686 /* increase dwell time to wait for RESP frame */
1687 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1689 case P2P_PAF_PROVDIS_RSP:
1690 /* wpa_supplicant send go nego req right after prov disc */
1691 p2p->next_af_subtype = P2P_PAF_GON_REQ;
1692 /* increase dwell time to MED level */
1693 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1694 config_af_params->extra_listen = false;
1697 bphy_err(drvr, "Unknown p2p pub act frame subtype: %d\n",
1704 static bool brcmf_p2p_check_dwell_overflow(u32 requested_dwell,
1705 unsigned long dwell_jiffies)
1707 if ((requested_dwell & CUSTOM_RETRY_MASK) &&
1708 (jiffies_to_msecs(jiffies - dwell_jiffies) >
1709 (requested_dwell & ~CUSTOM_RETRY_MASK))) {
1710 brcmf_err("Action frame TX retry time over dwell time!\n");
1716 * brcmf_p2p_send_action_frame() - send action frame .
1718 * @cfg: driver private data for cfg80211 interface.
1719 * @ndev: net device to transmit on.
1720 * @af_params: configuration data for action frame.
1722 bool brcmf_p2p_send_action_frame(struct brcmf_cfg80211_info *cfg,
1723 struct net_device *ndev,
1724 struct brcmf_fil_af_params_le *af_params)
1726 struct brcmf_p2p_info *p2p = &cfg->p2p;
1727 struct brcmf_if *ifp = netdev_priv(ndev);
1728 struct brcmf_fil_action_frame_le *action_frame;
1729 struct brcmf_config_af_params config_af_params;
1730 struct afx_hdl *afx_hdl = &p2p->afx_hdl;
1731 struct brcmf_pub *drvr = cfg->pub;
1732 u16 action_frame_len;
1737 s32 extra_listen_time;
1739 unsigned long dwell_jiffies = 0;
1740 bool dwell_overflow = false;
1742 u32 requested_dwell = le32_to_cpu(af_params->dwell_time);
1743 action_frame = &af_params->action_frame;
1744 action_frame_len = le16_to_cpu(action_frame->len);
1746 brcmf_p2p_print_actframe(true, action_frame->data, action_frame_len);
1748 /* Add the default dwell time. Dwell time to stay off-channel */
1749 /* to wait for a response action frame after transmitting an */
1750 /* GO Negotiation action frame */
1751 af_params->dwell_time = cpu_to_le32(P2P_AF_DWELL_TIME);
1753 category = action_frame->data[DOT11_ACTION_CAT_OFF];
1754 action = action_frame->data[DOT11_ACTION_ACT_OFF];
1756 /* initialize variables */
1757 p2p->next_af_subtype = P2P_PAF_SUBTYPE_INVALID;
1758 p2p->gon_req_action = false;
1760 /* config parameters */
1761 config_af_params.mpc_onoff = -1;
1762 config_af_params.search_channel = false;
1763 config_af_params.extra_listen = false;
1765 if (brcmf_p2p_is_pub_action(action_frame->data, action_frame_len)) {
1766 /* p2p public action frame process */
1767 if (brcmf_p2p_pub_af_tx(cfg, af_params, &config_af_params)) {
1768 /* Just send unknown subtype frame with */
1769 /* default parameters. */
1770 bphy_err(drvr, "P2P Public action frame, unknown subtype.\n");
1772 } else if (brcmf_p2p_is_gas_action(action_frame->data,
1773 action_frame_len)) {
1774 /* service discovery process */
1775 if (action == P2PSD_ACTION_ID_GAS_IREQ ||
1776 action == P2PSD_ACTION_ID_GAS_CREQ) {
1777 /* configure service discovery query frame */
1778 config_af_params.search_channel = true;
1780 /* save next af suptype to cancel */
1781 /* remaining dwell time */
1782 p2p->next_af_subtype = action + 1;
1784 af_params->dwell_time =
1785 cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1786 } else if (action == P2PSD_ACTION_ID_GAS_IRESP ||
1787 action == P2PSD_ACTION_ID_GAS_CRESP) {
1788 /* configure service discovery response frame */
1789 af_params->dwell_time =
1790 cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
1792 bphy_err(drvr, "Unknown action type: %d\n", action);
1795 } else if (brcmf_p2p_is_p2p_action(action_frame->data,
1796 action_frame_len)) {
1797 /* do not configure anything. it will be */
1798 /* sent with a default configuration */
1800 bphy_err(drvr, "Unknown Frame: category 0x%x, action 0x%x\n",
1805 /* if connecting on primary iface, sleep for a while before sending
1808 if (test_bit(BRCMF_VIF_STATUS_CONNECTING,
1809 &p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->sme_state))
1812 /* if scan is ongoing, abort current scan. */
1813 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
1814 brcmf_abort_scanning(cfg);
1816 memcpy(afx_hdl->tx_dst_addr, action_frame->da, ETH_ALEN);
1818 /* To make sure to send successfully action frame, turn off mpc */
1819 if (config_af_params.mpc_onoff == 0)
1820 brcmf_set_mpc(ifp, 0);
1822 /* set status and destination address before sending af */
1823 if (p2p->next_af_subtype != P2P_PAF_SUBTYPE_INVALID) {
1824 /* set status to cancel the remained dwell time in rx process */
1825 set_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, &p2p->status);
1828 p2p->af_sent_channel = 0;
1829 set_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME, &p2p->status);
1830 /* validate channel and p2p ies */
1831 if (config_af_params.search_channel &&
1832 IS_P2P_SOCIAL_CHANNEL(le32_to_cpu(af_params->channel)) &&
1833 p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif->saved_ie.probe_req_ie_len) {
1834 afx_hdl = &p2p->afx_hdl;
1835 afx_hdl->peer_listen_chan = le32_to_cpu(af_params->channel);
1837 if (brcmf_p2p_af_searching_channel(p2p) ==
1838 P2P_INVALID_CHANNEL) {
1839 bphy_err(drvr, "Couldn't find peer's channel.\n");
1843 /* Abort scan even for VSDB scenarios. Scan gets aborted in
1844 * firmware but after the check of piggyback algorithm. To take
1845 * care of current piggback algo, lets abort the scan here
1848 brcmf_notify_escan_complete(cfg, ifp, true, true);
1850 /* update channel */
1851 af_params->channel = cpu_to_le32(afx_hdl->peer_chan);
1853 dwell_jiffies = jiffies;
1854 dwell_overflow = brcmf_p2p_check_dwell_overflow(requested_dwell,
1858 while (!p2p->block_gon_req_tx &&
1859 (!ack) && (tx_retry < P2P_AF_TX_MAX_RETRY) &&
1861 if (af_params->channel)
1862 msleep(P2P_AF_RETRY_DELAY_TIME);
1864 ack = !brcmf_p2p_tx_action_frame(p2p, af_params);
1866 dwell_overflow = brcmf_p2p_check_dwell_overflow(requested_dwell,
1870 bphy_err(drvr, "Failed to send Action Frame(retry %d)\n",
1872 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
1876 clear_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME, &p2p->status);
1878 /* WAR: sometimes dongle does not keep the dwell time of 'actframe'.
1879 * if we coundn't get the next action response frame and dongle does
1880 * not keep the dwell time, go to listen state again to get next action
1883 if (ack && config_af_params.extra_listen && !p2p->block_gon_req_tx &&
1884 test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, &p2p->status) &&
1885 p2p->af_sent_channel == afx_hdl->my_listen_chan) {
1886 delta_ms = jiffies_to_msecs(jiffies - p2p->af_tx_sent_jiffies);
1887 if (le32_to_cpu(af_params->dwell_time) > delta_ms)
1888 extra_listen_time = le32_to_cpu(af_params->dwell_time) -
1891 extra_listen_time = 0;
1892 if (extra_listen_time > 50) {
1893 set_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN,
1895 brcmf_dbg(INFO, "Wait more time! actual af time:%d, calculated extra listen:%d\n",
1896 le32_to_cpu(af_params->dwell_time),
1898 extra_listen_time += 100;
1899 if (!brcmf_p2p_discover_listen(p2p,
1900 p2p->af_sent_channel,
1901 extra_listen_time)) {
1902 unsigned long duration;
1904 extra_listen_time += 100;
1905 duration = msecs_to_jiffies(extra_listen_time);
1906 wait_for_completion_timeout(&p2p->wait_next_af,
1909 clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN,
1914 if (p2p->block_gon_req_tx) {
1915 /* if ack is true, supplicant will wait more time(100ms).
1916 * so we will return it as a success to get more time .
1918 p2p->block_gon_req_tx = false;
1922 clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, &p2p->status);
1923 /* if all done, turn mpc on again */
1924 if (config_af_params.mpc_onoff == 1)
1925 brcmf_set_mpc(ifp, 1);
1931 * brcmf_p2p_notify_rx_mgmt_p2p_probereq() - Event handler for p2p probe req.
1933 * @ifp: interface pointer for which event was received.
1935 * @data: payload of event message (probe request).
1937 s32 brcmf_p2p_notify_rx_mgmt_p2p_probereq(struct brcmf_if *ifp,
1938 const struct brcmf_event_msg *e,
1941 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
1942 struct brcmf_p2p_info *p2p = &cfg->p2p;
1943 struct afx_hdl *afx_hdl = &p2p->afx_hdl;
1944 struct brcmf_cfg80211_vif *vif = ifp->vif;
1945 struct brcmf_rx_mgmt_data *rxframe = (struct brcmf_rx_mgmt_data *)data;
1946 struct brcmu_chan ch;
1952 brcmf_dbg(INFO, "Enter: event %d reason %d\n", e->event_code,
1955 if (e->datalen < sizeof(*rxframe)) {
1956 brcmf_dbg(SCAN, "Event data to small. Ignore\n");
1960 ch.chspec = be16_to_cpu(rxframe->chanspec);
1961 cfg->d11inf.decchspec(&ch);
1963 if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, &p2p->status) &&
1964 (ether_addr_equal(afx_hdl->tx_dst_addr, e->addr))) {
1965 afx_hdl->peer_chan = ch.control_ch_num;
1966 brcmf_dbg(INFO, "PROBE REQUEST: Peer found, channel=%d\n",
1967 afx_hdl->peer_chan);
1968 complete(&afx_hdl->act_frm_scan);
1971 /* Firmware sends us two proberesponses for each idx one. At the */
1972 /* moment anything but bsscfgidx 0 is passed up to supplicant */
1973 if (e->bsscfgidx == 0)
1976 /* Filter any P2P probe reqs arriving during the GO-NEG Phase */
1977 if (test_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status)) {
1978 brcmf_dbg(INFO, "Filtering P2P probe_req in GO-NEG phase\n");
1982 /* Check if wpa_supplicant has registered for this frame */
1983 brcmf_dbg(INFO, "vif->mgmt_rx_reg %04x\n", vif->mgmt_rx_reg);
1984 mgmt_type = (IEEE80211_STYPE_PROBE_REQ & IEEE80211_FCTL_STYPE) >> 4;
1985 if ((vif->mgmt_rx_reg & BIT(mgmt_type)) == 0)
1988 mgmt_frame = (u8 *)(rxframe + 1);
1989 mgmt_frame_len = e->datalen - sizeof(*rxframe);
1990 freq = ieee80211_channel_to_frequency(ch.control_ch_num,
1991 ch.band == BRCMU_CHAN_BAND_2G ?
1995 cfg80211_rx_mgmt(&vif->wdev, freq, 0, mgmt_frame, mgmt_frame_len, 0);
1997 brcmf_dbg(INFO, "mgmt_frame_len (%d) , e->datalen (%d), chanspec (%04x), freq (%d)\n",
1998 mgmt_frame_len, e->datalen, ch.chspec, freq);
2005 * brcmf_p2p_get_current_chanspec() - Get current operation channel.
2007 * @p2p: P2P specific data.
2008 * @chanspec: chanspec to be returned.
2010 static void brcmf_p2p_get_current_chanspec(struct brcmf_p2p_info *p2p,
2013 struct brcmf_if *ifp;
2014 u8 mac_addr[ETH_ALEN];
2015 struct brcmu_chan ch;
2016 struct brcmf_bss_info_le *bi;
2019 ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
2021 if (brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSSID, mac_addr,
2023 buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
2025 *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
2026 if (brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
2027 buf, WL_BSS_INFO_MAX) == 0) {
2028 bi = (struct brcmf_bss_info_le *)(buf + 4);
2029 *chanspec = le16_to_cpu(bi->chanspec);
2036 /* Use default channel for P2P */
2037 ch.chnum = BRCMF_P2P_TEMP_CHAN;
2038 ch.bw = BRCMU_CHAN_BW_20;
2039 p2p->cfg->d11inf.encchspec(&ch);
2040 *chanspec = ch.chspec;
2044 * Change a P2P Role.
2045 * @cfg: driver private data for cfg80211 interface.
2046 * @if_type: interface type.
2047 * Returns 0 if success.
2049 int brcmf_p2p_ifchange(struct brcmf_cfg80211_info *cfg,
2050 enum brcmf_fil_p2p_if_types if_type)
2052 struct brcmf_p2p_info *p2p = &cfg->p2p;
2053 struct brcmf_pub *drvr = cfg->pub;
2054 struct brcmf_cfg80211_vif *vif;
2055 struct brcmf_fil_p2p_if_le if_request;
2059 brcmf_dbg(TRACE, "Enter\n");
2061 vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
2063 bphy_err(drvr, "vif for P2PAPI_BSSCFG_PRIMARY does not exist\n");
2066 brcmf_notify_escan_complete(cfg, vif->ifp, true, true);
2067 vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif;
2069 bphy_err(drvr, "vif for P2PAPI_BSSCFG_CONNECTION does not exist\n");
2072 brcmf_set_mpc(vif->ifp, 0);
2074 /* In concurrency case, STA may be already associated in a particular */
2075 /* channel. so retrieve the current channel of primary interface and */
2076 /* then start the virtual interface on that. */
2077 brcmf_p2p_get_current_chanspec(p2p, &chanspec);
2079 if_request.type = cpu_to_le16((u16)if_type);
2080 if_request.chspec = cpu_to_le16(chanspec);
2081 memcpy(if_request.addr, p2p->conn_int_addr, sizeof(if_request.addr));
2083 brcmf_cfg80211_arm_vif_event(cfg, vif);
2084 err = brcmf_fil_iovar_data_set(vif->ifp, "p2p_ifupd", &if_request,
2085 sizeof(if_request));
2087 bphy_err(drvr, "p2p_ifupd FAILED, err=%d\n", err);
2088 brcmf_cfg80211_arm_vif_event(cfg, NULL);
2091 err = brcmf_cfg80211_wait_vif_event(cfg, BRCMF_E_IF_CHANGE,
2092 BRCMF_VIF_EVENT_TIMEOUT);
2093 brcmf_cfg80211_arm_vif_event(cfg, NULL);
2095 bphy_err(drvr, "No BRCMF_E_IF_CHANGE event received\n");
2099 err = brcmf_fil_cmd_int_set(vif->ifp, BRCMF_C_SET_SCB_TIMEOUT,
2100 BRCMF_SCB_TIMEOUT_VALUE);
2105 static int brcmf_p2p_request_p2p_if(struct brcmf_p2p_info *p2p,
2106 struct brcmf_if *ifp, u8 ea[ETH_ALEN],
2107 enum brcmf_fil_p2p_if_types iftype)
2109 struct brcmf_fil_p2p_if_le if_request;
2113 /* we need a default channel */
2114 brcmf_p2p_get_current_chanspec(p2p, &chanspec);
2116 /* fill the firmware request */
2117 memcpy(if_request.addr, ea, ETH_ALEN);
2118 if_request.type = cpu_to_le16((u16)iftype);
2119 if_request.chspec = cpu_to_le16(chanspec);
2121 err = brcmf_fil_iovar_data_set(ifp, "p2p_ifadd", &if_request,
2122 sizeof(if_request));
2127 static int brcmf_p2p_disable_p2p_if(struct brcmf_cfg80211_vif *vif)
2129 struct brcmf_cfg80211_info *cfg = wdev_to_cfg(&vif->wdev);
2130 struct net_device *pri_ndev = cfg_to_ndev(cfg);
2131 struct brcmf_if *ifp = netdev_priv(pri_ndev);
2132 u8 *addr = vif->wdev.netdev->dev_addr;
2134 return brcmf_fil_iovar_data_set(ifp, "p2p_ifdis", addr, ETH_ALEN);
2137 static int brcmf_p2p_release_p2p_if(struct brcmf_cfg80211_vif *vif)
2139 struct brcmf_cfg80211_info *cfg = wdev_to_cfg(&vif->wdev);
2140 struct net_device *pri_ndev = cfg_to_ndev(cfg);
2141 struct brcmf_if *ifp = netdev_priv(pri_ndev);
2142 u8 *addr = vif->wdev.netdev->dev_addr;
2144 return brcmf_fil_iovar_data_set(ifp, "p2p_ifdel", addr, ETH_ALEN);
2148 * brcmf_p2p_create_p2pdev() - create a P2P_DEVICE virtual interface.
2150 * @p2p: P2P specific data.
2151 * @wiphy: wiphy device of new interface.
2152 * @addr: mac address for this new interface.
2154 static struct wireless_dev *brcmf_p2p_create_p2pdev(struct brcmf_p2p_info *p2p,
2155 struct wiphy *wiphy,
2158 struct brcmf_pub *drvr = p2p->cfg->pub;
2159 struct brcmf_cfg80211_vif *p2p_vif;
2160 struct brcmf_if *p2p_ifp;
2161 struct brcmf_if *pri_ifp;
2165 if (p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
2166 return ERR_PTR(-ENOSPC);
2168 p2p_vif = brcmf_alloc_vif(p2p->cfg, NL80211_IFTYPE_P2P_DEVICE);
2169 if (IS_ERR(p2p_vif)) {
2170 bphy_err(drvr, "could not create discovery vif\n");
2171 return (struct wireless_dev *)p2p_vif;
2174 pri_ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
2176 /* firmware requires unique mac address for p2pdev interface */
2177 if (addr && ether_addr_equal(addr, pri_ifp->mac_addr)) {
2178 bphy_err(drvr, "discovery vif must be different from primary interface\n");
2183 brcmf_p2p_generate_bss_mac(p2p, addr);
2184 brcmf_p2p_set_firmware(pri_ifp, p2p->dev_addr);
2186 brcmf_cfg80211_arm_vif_event(p2p->cfg, p2p_vif);
2187 brcmf_fweh_p2pdev_setup(pri_ifp, true);
2189 /* Initialize P2P Discovery in the firmware */
2190 err = brcmf_fil_iovar_int_set(pri_ifp, "p2p_disc", 1);
2192 bphy_err(drvr, "set p2p_disc error\n");
2193 brcmf_fweh_p2pdev_setup(pri_ifp, false);
2194 brcmf_cfg80211_arm_vif_event(p2p->cfg, NULL);
2198 /* wait for firmware event */
2199 err = brcmf_cfg80211_wait_vif_event(p2p->cfg, BRCMF_E_IF_ADD,
2200 BRCMF_VIF_EVENT_TIMEOUT);
2201 brcmf_cfg80211_arm_vif_event(p2p->cfg, NULL);
2202 brcmf_fweh_p2pdev_setup(pri_ifp, false);
2204 bphy_err(drvr, "timeout occurred\n");
2209 /* discovery interface created */
2210 p2p_ifp = p2p_vif->ifp;
2211 p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif = p2p_vif;
2212 memcpy(p2p_ifp->mac_addr, p2p->dev_addr, ETH_ALEN);
2213 memcpy(&p2p_vif->wdev.address, p2p->dev_addr, sizeof(p2p->dev_addr));
2215 /* verify bsscfg index for P2P discovery */
2216 err = brcmf_fil_iovar_int_get(pri_ifp, "p2p_dev", &bsscfgidx);
2218 bphy_err(drvr, "retrieving discover bsscfg index failed\n");
2222 WARN_ON(p2p_ifp->bsscfgidx != bsscfgidx);
2224 init_completion(&p2p->send_af_done);
2225 INIT_WORK(&p2p->afx_hdl.afx_work, brcmf_p2p_afx_handler);
2226 init_completion(&p2p->afx_hdl.act_frm_scan);
2227 init_completion(&p2p->wait_next_af);
2229 return &p2p_vif->wdev;
2232 brcmf_free_vif(p2p_vif);
2233 return ERR_PTR(err);
2236 static int brcmf_p2p_get_conn_idx(struct brcmf_cfg80211_info *cfg)
2239 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
2244 for (i = P2PAPI_BSSCFG_CONNECTION; i < P2PAPI_BSSCFG_MAX; i++) {
2245 if (!cfg->p2p.bss_idx[i].vif) {
2246 if (i == P2PAPI_BSSCFG_CONNECTION2 &&
2247 !(brcmf_feat_is_enabled(ifp, BRCMF_FEAT_RSDB))) {
2248 brcmf_err("Multi p2p not supported");
2258 * brcmf_p2p_add_vif() - create a new P2P virtual interface.
2260 * @wiphy: wiphy device of new interface.
2261 * @name: name of the new interface.
2262 * @name_assign_type: origin of the interface name
2263 * @type: nl80211 interface type.
2264 * @params: contains mac address for P2P device.
2266 struct wireless_dev *brcmf_p2p_add_vif(struct wiphy *wiphy, const char *name,
2267 unsigned char name_assign_type,
2268 enum nl80211_iftype type,
2269 struct vif_params *params)
2271 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2272 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
2273 struct brcmf_pub *drvr = cfg->pub;
2274 struct brcmf_cfg80211_vif *vif;
2275 enum brcmf_fil_p2p_if_types iftype;
2280 if (brcmf_cfg80211_vif_event_armed(cfg))
2281 return ERR_PTR(-EBUSY);
2283 brcmf_dbg(INFO, "adding vif \"%s\" (type=%d)\n", name, type);
2286 case NL80211_IFTYPE_P2P_CLIENT:
2287 iftype = BRCMF_FIL_P2P_IF_CLIENT;
2289 case NL80211_IFTYPE_P2P_GO:
2290 iftype = BRCMF_FIL_P2P_IF_GO;
2292 case NL80211_IFTYPE_P2P_DEVICE:
2293 return brcmf_p2p_create_p2pdev(&cfg->p2p, wiphy,
2296 return ERR_PTR(-EOPNOTSUPP);
2299 vif = brcmf_alloc_vif(cfg, type);
2301 return (struct wireless_dev *)vif;
2302 brcmf_cfg80211_arm_vif_event(cfg, vif);
2304 connidx = brcmf_p2p_get_conn_idx(cfg);
2306 if (connidx == P2PAPI_BSSCFG_CONNECTION)
2307 p2p_intf_addr = cfg->p2p.conn_int_addr;
2308 else if (connidx == P2PAPI_BSSCFG_CONNECTION2)
2309 p2p_intf_addr = cfg->p2p.conn2_int_addr;
2314 err = brcmf_p2p_request_p2p_if(&cfg->p2p, ifp,
2315 p2p_intf_addr, iftype);
2318 brcmf_err("request p2p interface failed\n");
2319 brcmf_cfg80211_arm_vif_event(cfg, NULL);
2323 /* wait for firmware event */
2324 err = brcmf_cfg80211_wait_vif_event(cfg, BRCMF_E_IF_ADD,
2325 BRCMF_VIF_EVENT_TIMEOUT);
2326 brcmf_cfg80211_arm_vif_event(cfg, NULL);
2328 bphy_err(drvr, "timeout occurred\n");
2333 /* interface created in firmware */
2336 bphy_err(drvr, "no if pointer provided\n");
2341 strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1);
2342 ifp->ndev->name_assign_type = name_assign_type;
2343 err = brcmf_net_attach(ifp, true);
2345 bphy_err(drvr, "Registering netdevice failed\n");
2346 free_netdev(ifp->ndev);
2350 cfg->p2p.bss_idx[connidx].vif = vif;
2351 /* Disable firmware roaming for P2P interface */
2352 brcmf_fil_iovar_int_set(ifp, "roam_off", 1);
2353 if (iftype == BRCMF_FIL_P2P_IF_GO) {
2354 /* set station timeout for p2p */
2355 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCB_TIMEOUT,
2356 BRCMF_SCB_TIMEOUT_VALUE);
2358 return &ifp->vif->wdev;
2361 brcmf_free_vif(vif);
2362 return ERR_PTR(err);
2366 * brcmf_p2p_del_vif() - delete a P2P virtual interface.
2368 * @wiphy: wiphy device of interface.
2369 * @wdev: wireless device of interface.
2371 int brcmf_p2p_del_vif(struct wiphy *wiphy, struct wireless_dev *wdev)
2373 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2374 struct brcmf_p2p_info *p2p = &cfg->p2p;
2375 struct brcmf_cfg80211_vif *vif;
2376 enum nl80211_iftype iftype;
2377 bool wait_for_disable = false;
2380 brcmf_dbg(TRACE, "delete P2P vif\n");
2381 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
2383 iftype = vif->wdev.iftype;
2384 brcmf_cfg80211_arm_vif_event(cfg, vif);
2386 case NL80211_IFTYPE_P2P_CLIENT:
2387 if (test_bit(BRCMF_VIF_STATUS_DISCONNECTING, &vif->sme_state))
2388 wait_for_disable = true;
2391 case NL80211_IFTYPE_P2P_GO:
2392 if (!brcmf_p2p_disable_p2p_if(vif))
2393 wait_for_disable = true;
2396 case NL80211_IFTYPE_P2P_DEVICE:
2397 if (!p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
2399 brcmf_p2p_cancel_remain_on_channel(vif->ifp);
2400 brcmf_p2p_deinit_discovery(p2p);
2407 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
2408 brcmf_dbg(INFO, "P2P: GO_NEG_PHASE status cleared\n");
2410 if (wait_for_disable)
2411 wait_for_completion_timeout(&cfg->vif_disabled,
2412 BRCMF_P2P_DISABLE_TIMEOUT);
2415 if (iftype != NL80211_IFTYPE_P2P_DEVICE) {
2416 brcmf_vif_clear_mgmt_ies(vif);
2417 err = brcmf_p2p_release_p2p_if(vif);
2420 /* wait for firmware event */
2421 err = brcmf_cfg80211_wait_vif_event(cfg, BRCMF_E_IF_DEL,
2422 BRCMF_VIF_EVENT_TIMEOUT);
2428 brcmf_remove_interface(vif->ifp, true);
2430 brcmf_cfg80211_arm_vif_event(cfg, NULL);
2431 if (iftype != NL80211_IFTYPE_P2P_DEVICE)
2432 p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif = NULL;
2437 void brcmf_p2p_ifp_removed(struct brcmf_if *ifp, bool rtnl_locked)
2439 struct brcmf_cfg80211_info *cfg;
2440 struct brcmf_cfg80211_vif *vif;
2442 brcmf_dbg(INFO, "P2P: device interface removed\n");
2444 cfg = wdev_to_cfg(&vif->wdev);
2445 cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif = NULL;
2448 cfg80211_unregister_wdev(&vif->wdev);
2451 brcmf_free_vif(vif);
2454 int brcmf_p2p_start_device(struct wiphy *wiphy, struct wireless_dev *wdev)
2456 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2457 struct brcmf_p2p_info *p2p = &cfg->p2p;
2458 struct brcmf_cfg80211_vif *vif;
2461 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
2462 mutex_lock(&cfg->usr_sync);
2463 err = brcmf_p2p_enable_discovery(p2p);
2465 set_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state);
2466 mutex_unlock(&cfg->usr_sync);
2470 void brcmf_p2p_stop_device(struct wiphy *wiphy, struct wireless_dev *wdev)
2472 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2473 struct brcmf_p2p_info *p2p = &cfg->p2p;
2474 struct brcmf_cfg80211_vif *vif;
2476 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
2477 /* This call can be result of the unregister_wdev call. In that case
2478 * we dont want to do anything anymore. Just return. The config vif
2479 * will have been cleared at this point.
2481 if (p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif == vif) {
2482 mutex_lock(&cfg->usr_sync);
2483 /* Set the discovery state to SCAN */
2484 (void)brcmf_p2p_set_discover_state(vif->ifp,
2485 WL_P2P_DISC_ST_SCAN, 0, 0);
2486 brcmf_abort_scanning(cfg);
2487 clear_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state);
2488 mutex_unlock(&cfg->usr_sync);
2493 * brcmf_p2p_attach() - attach for P2P.
2495 * @cfg: driver private data for cfg80211 interface.
2496 * @p2pdev_forced: create p2p device interface at attach.
2498 s32 brcmf_p2p_attach(struct brcmf_cfg80211_info *cfg, bool p2pdev_forced)
2500 struct brcmf_pub *drvr = cfg->pub;
2501 struct brcmf_p2p_info *p2p;
2502 struct brcmf_if *pri_ifp;
2509 pri_ifp = brcmf_get_ifp(cfg->pub, 0);
2510 p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif = pri_ifp->vif;
2512 if (p2pdev_forced) {
2513 err_ptr = brcmf_p2p_create_p2pdev(p2p, NULL, NULL);
2514 if (IS_ERR(err_ptr)) {
2515 bphy_err(drvr, "P2P device creation failed.\n");
2516 err = PTR_ERR(err_ptr);
2519 p2p->p2pdev_dynamically = true;
2525 * brcmf_p2p_detach() - detach P2P.
2527 * @p2p: P2P specific data.
2529 void brcmf_p2p_detach(struct brcmf_p2p_info *p2p)
2531 struct brcmf_cfg80211_vif *vif;
2533 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
2535 brcmf_p2p_cancel_remain_on_channel(vif->ifp);
2536 brcmf_p2p_deinit_discovery(p2p);
2537 brcmf_remove_interface(vif->ifp, false);
2539 /* just set it all to zero */
2540 memset(p2p, 0, sizeof(*p2p));