2 * Copyright (c) 2012 Broadcom Corporation
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 #include <linux/slab.h>
17 #include <linux/netdevice.h>
18 #include <net/cfg80211.h>
20 #include <brcmu_wifi.h>
21 #include <brcmu_utils.h>
26 #include "fwil_types.h"
28 #include "wl_cfg80211.h"
30 /* parameters used for p2p escan */
31 #define P2PAPI_SCAN_NPROBES 1
32 #define P2PAPI_SCAN_DWELL_TIME_MS 80
33 #define P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS 40
34 #define P2PAPI_SCAN_HOME_TIME_MS 60
35 #define P2PAPI_SCAN_NPROBS_TIME_MS 30
36 #define P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS 100
37 #define WL_SCAN_CONNECT_DWELL_TIME_MS 200
38 #define WL_SCAN_JOIN_PROBE_INTERVAL_MS 20
40 #define BRCMF_P2P_WILDCARD_SSID "DIRECT-"
41 #define BRCMF_P2P_WILDCARD_SSID_LEN (sizeof(BRCMF_P2P_WILDCARD_SSID) - 1)
43 #define SOCIAL_CHAN_1 1
44 #define SOCIAL_CHAN_2 6
45 #define SOCIAL_CHAN_3 11
46 #define IS_P2P_SOCIAL_CHANNEL(channel) ((channel == SOCIAL_CHAN_1) || \
47 (channel == SOCIAL_CHAN_2) || \
48 (channel == SOCIAL_CHAN_3))
49 #define SOCIAL_CHAN_CNT 3
50 #define AF_PEER_SEARCH_CNT 2
52 #define BRCMF_SCB_TIMEOUT_VALUE 20
54 #define P2P_VER 9 /* P2P version: 9=WiFi P2P v1.0 */
55 #define P2P_PUB_AF_CATEGORY 0x04
56 #define P2P_PUB_AF_ACTION 0x09
57 #define P2P_AF_CATEGORY 0x7f
58 #define P2P_OUI "\x50\x6F\x9A" /* P2P OUI */
59 #define P2P_OUI_LEN 3 /* P2P OUI length */
61 /* Action Frame Constants */
62 #define DOT11_ACTION_HDR_LEN 2 /* action frame category + action */
63 #define DOT11_ACTION_CAT_OFF 0 /* category offset */
64 #define DOT11_ACTION_ACT_OFF 1 /* action offset */
66 #define P2P_AF_DWELL_TIME 200
67 #define P2P_AF_MIN_DWELL_TIME 100
68 #define P2P_AF_MED_DWELL_TIME 400
69 #define P2P_AF_LONG_DWELL_TIME 1000
70 #define P2P_AF_TX_MAX_RETRY 1
71 #define P2P_AF_MAX_WAIT_TIME 2000
72 #define P2P_INVALID_CHANNEL -1
73 #define P2P_CHANNEL_SYNC_RETRY 5
74 #define P2P_AF_FRM_SCAN_MAX_WAIT 1500
75 #define P2P_DEFAULT_SLEEP_TIME_VSDB 200
77 /* WiFi P2P Public Action Frame OUI Subtypes */
78 #define P2P_PAF_GON_REQ 0 /* Group Owner Negotiation Req */
79 #define P2P_PAF_GON_RSP 1 /* Group Owner Negotiation Rsp */
80 #define P2P_PAF_GON_CONF 2 /* Group Owner Negotiation Confirm */
81 #define P2P_PAF_INVITE_REQ 3 /* P2P Invitation Request */
82 #define P2P_PAF_INVITE_RSP 4 /* P2P Invitation Response */
83 #define P2P_PAF_DEVDIS_REQ 5 /* Device Discoverability Request */
84 #define P2P_PAF_DEVDIS_RSP 6 /* Device Discoverability Response */
85 #define P2P_PAF_PROVDIS_REQ 7 /* Provision Discovery Request */
86 #define P2P_PAF_PROVDIS_RSP 8 /* Provision Discovery Response */
87 #define P2P_PAF_SUBTYPE_INVALID 255 /* Invalid Subtype */
89 /* WiFi P2P Action Frame OUI Subtypes */
90 #define P2P_AF_NOTICE_OF_ABSENCE 0 /* Notice of Absence */
91 #define P2P_AF_PRESENCE_REQ 1 /* P2P Presence Request */
92 #define P2P_AF_PRESENCE_RSP 2 /* P2P Presence Response */
93 #define P2P_AF_GO_DISC_REQ 3 /* GO Discoverability Request */
95 /* P2P Service Discovery related */
96 #define P2PSD_ACTION_CATEGORY 0x04 /* Public action frame */
97 #define P2PSD_ACTION_ID_GAS_IREQ 0x0a /* GAS Initial Request AF */
98 #define P2PSD_ACTION_ID_GAS_IRESP 0x0b /* GAS Initial Response AF */
99 #define P2PSD_ACTION_ID_GAS_CREQ 0x0c /* GAS Comback Request AF */
100 #define P2PSD_ACTION_ID_GAS_CRESP 0x0d /* GAS Comback Response AF */
103 * struct brcmf_p2p_disc_st_le - set discovery state in firmware.
105 * @state: requested discovery state (see enum brcmf_p2p_disc_state).
106 * @chspec: channel parameter for %WL_P2P_DISC_ST_LISTEN state.
107 * @dwell: dwell time in ms for %WL_P2P_DISC_ST_LISTEN state.
109 struct brcmf_p2p_disc_st_le {
116 * enum brcmf_p2p_disc_state - P2P discovery state values
118 * @WL_P2P_DISC_ST_SCAN: P2P discovery with wildcard SSID and P2P IE.
119 * @WL_P2P_DISC_ST_LISTEN: P2P discovery off-channel for specified time.
120 * @WL_P2P_DISC_ST_SEARCH: P2P discovery with P2P wildcard SSID and P2P IE.
122 enum brcmf_p2p_disc_state {
124 WL_P2P_DISC_ST_LISTEN,
125 WL_P2P_DISC_ST_SEARCH
129 * struct brcmf_p2p_scan_le - P2P specific scan request.
131 * @type: type of scan method requested (values: 'E' or 'S').
132 * @reserved: reserved (ignored).
133 * @eparams: parameters used for type 'E'.
134 * @sparams: parameters used for type 'S'.
136 struct brcmf_p2p_scan_le {
140 struct brcmf_escan_params_le eparams;
141 struct brcmf_scan_params_le sparams;
146 * struct brcmf_p2p_pub_act_frame - WiFi P2P Public Action Frame
148 * @category: P2P_PUB_AF_CATEGORY
149 * @action: P2P_PUB_AF_ACTION
151 * @oui_type: OUI type - P2P_VER
152 * @subtype: OUI subtype - P2P_TYPE_*
153 * @dialog_token: nonzero, identifies req/rsp transaction
154 * @elts[1]: Variable length information elements.
156 struct brcmf_p2p_pub_act_frame {
167 * struct brcmf_p2p_action_frame - WiFi P2P Action Frame
169 * @category: P2P_AF_CATEGORY
170 * @OUI[3]: OUI - P2P_OUI
171 * @type: OUI Type - P2P_VER
172 * @subtype: OUI Subtype - P2P_AF_*
173 * @dialog_token: nonzero, identifies req/resp tranaction
174 * @elts[1]: Variable length information elements.
176 struct brcmf_p2p_action_frame {
186 * struct brcmf_p2psd_gas_pub_act_frame - Wi-Fi GAS Public Action Frame
188 * @category: 0x04 Public Action Frame
189 * @action: 0x6c Advertisement Protocol
190 * @dialog_token: nonzero, identifies req/rsp transaction
191 * @query_data[1]: Query Data. SD gas ireq SD gas iresp
193 struct brcmf_p2psd_gas_pub_act_frame {
201 * struct brcmf_config_af_params - Action Frame Parameters for tx.
203 * @mpc_onoff: To make sure to send successfully action frame, we have to
204 * turn off mpc 0: off, 1: on, (-1): do nothing
205 * @search_channel: 1: search peer's channel to send af
206 * extra_listen: keep the dwell time to get af response frame.
208 struct brcmf_config_af_params {
215 * brcmf_p2p_is_pub_action() - true if p2p public type frame.
217 * @frame: action frame data.
218 * @frame_len: length of action frame data.
220 * Determine if action frame is p2p public action type
222 static bool brcmf_p2p_is_pub_action(void *frame, u32 frame_len)
224 struct brcmf_p2p_pub_act_frame *pact_frm;
229 pact_frm = (struct brcmf_p2p_pub_act_frame *)frame;
230 if (frame_len < sizeof(struct brcmf_p2p_pub_act_frame) - 1)
233 if (pact_frm->category == P2P_PUB_AF_CATEGORY &&
234 pact_frm->action == P2P_PUB_AF_ACTION &&
235 pact_frm->oui_type == P2P_VER &&
236 memcmp(pact_frm->oui, P2P_OUI, P2P_OUI_LEN) == 0)
243 * brcmf_p2p_is_p2p_action() - true if p2p action type frame.
245 * @frame: action frame data.
246 * @frame_len: length of action frame data.
248 * Determine if action frame is p2p action type
250 static bool brcmf_p2p_is_p2p_action(void *frame, u32 frame_len)
252 struct brcmf_p2p_action_frame *act_frm;
257 act_frm = (struct brcmf_p2p_action_frame *)frame;
258 if (frame_len < sizeof(struct brcmf_p2p_action_frame) - 1)
261 if (act_frm->category == P2P_AF_CATEGORY &&
262 act_frm->type == P2P_VER &&
263 memcmp(act_frm->oui, P2P_OUI, P2P_OUI_LEN) == 0)
270 * brcmf_p2p_is_gas_action() - true if p2p gas action type frame.
272 * @frame: action frame data.
273 * @frame_len: length of action frame data.
275 * Determine if action frame is p2p gas action type
277 static bool brcmf_p2p_is_gas_action(void *frame, u32 frame_len)
279 struct brcmf_p2psd_gas_pub_act_frame *sd_act_frm;
284 sd_act_frm = (struct brcmf_p2psd_gas_pub_act_frame *)frame;
285 if (frame_len < sizeof(struct brcmf_p2psd_gas_pub_act_frame) - 1)
288 if (sd_act_frm->category != P2PSD_ACTION_CATEGORY)
291 if (sd_act_frm->action == P2PSD_ACTION_ID_GAS_IREQ ||
292 sd_act_frm->action == P2PSD_ACTION_ID_GAS_IRESP ||
293 sd_act_frm->action == P2PSD_ACTION_ID_GAS_CREQ ||
294 sd_act_frm->action == P2PSD_ACTION_ID_GAS_CRESP)
301 * brcmf_p2p_print_actframe() - debug print routine.
303 * @tx: Received or to be transmitted
304 * @frame: action frame data.
305 * @frame_len: length of action frame data.
307 * Print information about the p2p action frame
312 static void brcmf_p2p_print_actframe(bool tx, void *frame, u32 frame_len)
314 struct brcmf_p2p_pub_act_frame *pact_frm;
315 struct brcmf_p2p_action_frame *act_frm;
316 struct brcmf_p2psd_gas_pub_act_frame *sd_act_frm;
318 if (!frame || frame_len <= 2)
321 if (brcmf_p2p_is_pub_action(frame, frame_len)) {
322 pact_frm = (struct brcmf_p2p_pub_act_frame *)frame;
323 switch (pact_frm->subtype) {
324 case P2P_PAF_GON_REQ:
325 brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Req Frame\n",
328 case P2P_PAF_GON_RSP:
329 brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Rsp Frame\n",
332 case P2P_PAF_GON_CONF:
333 brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Confirm Frame\n",
336 case P2P_PAF_INVITE_REQ:
337 brcmf_dbg(TRACE, "%s P2P Invitation Request Frame\n",
340 case P2P_PAF_INVITE_RSP:
341 brcmf_dbg(TRACE, "%s P2P Invitation Response Frame\n",
344 case P2P_PAF_DEVDIS_REQ:
345 brcmf_dbg(TRACE, "%s P2P Device Discoverability Request Frame\n",
348 case P2P_PAF_DEVDIS_RSP:
349 brcmf_dbg(TRACE, "%s P2P Device Discoverability Response Frame\n",
352 case P2P_PAF_PROVDIS_REQ:
353 brcmf_dbg(TRACE, "%s P2P Provision Discovery Request Frame\n",
356 case P2P_PAF_PROVDIS_RSP:
357 brcmf_dbg(TRACE, "%s P2P Provision Discovery Response Frame\n",
361 brcmf_dbg(TRACE, "%s Unknown P2P Public Action Frame\n",
365 } else if (brcmf_p2p_is_p2p_action(frame, frame_len)) {
366 act_frm = (struct brcmf_p2p_action_frame *)frame;
367 switch (act_frm->subtype) {
368 case P2P_AF_NOTICE_OF_ABSENCE:
369 brcmf_dbg(TRACE, "%s P2P Notice of Absence Frame\n",
372 case P2P_AF_PRESENCE_REQ:
373 brcmf_dbg(TRACE, "%s P2P Presence Request Frame\n",
376 case P2P_AF_PRESENCE_RSP:
377 brcmf_dbg(TRACE, "%s P2P Presence Response Frame\n",
380 case P2P_AF_GO_DISC_REQ:
381 brcmf_dbg(TRACE, "%s P2P Discoverability Request Frame\n",
385 brcmf_dbg(TRACE, "%s Unknown P2P Action Frame\n",
389 } else if (brcmf_p2p_is_gas_action(frame, frame_len)) {
390 sd_act_frm = (struct brcmf_p2psd_gas_pub_act_frame *)frame;
391 switch (sd_act_frm->action) {
392 case P2PSD_ACTION_ID_GAS_IREQ:
393 brcmf_dbg(TRACE, "%s P2P GAS Initial Request\n",
396 case P2PSD_ACTION_ID_GAS_IRESP:
397 brcmf_dbg(TRACE, "%s P2P GAS Initial Response\n",
400 case P2PSD_ACTION_ID_GAS_CREQ:
401 brcmf_dbg(TRACE, "%s P2P GAS Comback Request\n",
404 case P2PSD_ACTION_ID_GAS_CRESP:
405 brcmf_dbg(TRACE, "%s P2P GAS Comback Response\n",
409 brcmf_dbg(TRACE, "%s Unknown P2P GAS Frame\n",
418 static void brcmf_p2p_print_actframe(bool tx, void *frame, u32 frame_len)
426 * brcmf_p2p_chnr_to_chspec() - convert channel number to chanspec.
428 * @channel: channel number
430 static u16 brcmf_p2p_chnr_to_chspec(u16 channel)
434 chanspec = channel & WL_CHANSPEC_CHAN_MASK;
436 if (channel <= CH_MAX_2G_CHANNEL)
437 chanspec |= WL_CHANSPEC_BAND_2G;
439 chanspec |= WL_CHANSPEC_BAND_5G;
441 chanspec |= WL_CHANSPEC_BW_20;
442 chanspec |= WL_CHANSPEC_CTL_SB_NONE;
449 * brcmf_p2p_set_firmware() - prepare firmware for peer-to-peer operation.
451 * @ifp: ifp to use for iovars (primary).
452 * @p2p_mac: mac address to configure for p2p_da_override
454 static int brcmf_p2p_set_firmware(struct brcmf_if *ifp, u8 *p2p_mac)
458 brcmf_fil_iovar_int_set(ifp, "apsta", 1);
460 /* In case of COB type, firmware has default mac address
461 * After Initializing firmware, we have to set current mac address to
462 * firmware for P2P device address
464 ret = brcmf_fil_iovar_data_set(ifp, "p2p_da_override", p2p_mac,
467 brcmf_err("failed to update device address ret %d\n", ret);
473 * brcmf_p2p_generate_bss_mac() - derive mac addresses for P2P.
475 * @p2p: P2P specific data.
477 * P2P needs mac addresses for P2P device and interface. These are
478 * derived from the primary net device, ie. the permanent ethernet
479 * address of the device.
481 static void brcmf_p2p_generate_bss_mac(struct brcmf_p2p_info *p2p)
483 struct brcmf_if *pri_ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
484 struct brcmf_if *p2p_ifp = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif->ifp;
486 /* Generate the P2P Device Address. This consists of the device's
487 * primary MAC address with the locally administered bit set.
489 memcpy(p2p->dev_addr, pri_ifp->mac_addr, ETH_ALEN);
490 p2p->dev_addr[0] |= 0x02;
491 memcpy(p2p_ifp->mac_addr, p2p->dev_addr, ETH_ALEN);
493 /* Generate the P2P Interface Address. If the discovery and connection
494 * BSSCFGs need to simultaneously co-exist, then this address must be
495 * different from the P2P Device Address, but also locally administered.
497 memcpy(p2p->int_addr, p2p->dev_addr, ETH_ALEN);
498 p2p->int_addr[4] ^= 0x80;
502 * brcmf_p2p_scan_is_p2p_request() - is cfg80211 scan request a P2P scan.
504 * @request: the scan request as received from cfg80211.
506 * returns true if one of the ssids in the request matches the
507 * P2P wildcard ssid; otherwise returns false.
509 static bool brcmf_p2p_scan_is_p2p_request(struct cfg80211_scan_request *request)
511 struct cfg80211_ssid *ssids = request->ssids;
514 for (i = 0; i < request->n_ssids; i++) {
515 if (ssids[i].ssid_len != BRCMF_P2P_WILDCARD_SSID_LEN)
518 brcmf_dbg(INFO, "comparing ssid \"%s\"", ssids[i].ssid);
519 if (!memcmp(BRCMF_P2P_WILDCARD_SSID, ssids[i].ssid,
520 BRCMF_P2P_WILDCARD_SSID_LEN))
527 * brcmf_p2p_set_discover_state - set discover state in firmware.
529 * @ifp: low-level interface object.
530 * @state: discover state to set.
531 * @chanspec: channel parameters (for state @WL_P2P_DISC_ST_LISTEN only).
532 * @listen_ms: duration to listen (for state @WL_P2P_DISC_ST_LISTEN only).
534 static s32 brcmf_p2p_set_discover_state(struct brcmf_if *ifp, u8 state,
535 u16 chanspec, u16 listen_ms)
537 struct brcmf_p2p_disc_st_le discover_state;
539 brcmf_dbg(TRACE, "enter\n");
541 discover_state.state = state;
542 discover_state.chspec = cpu_to_le16(chanspec);
543 discover_state.dwell = cpu_to_le16(listen_ms);
544 ret = brcmf_fil_bsscfg_data_set(ifp, "p2p_state", &discover_state,
545 sizeof(discover_state));
550 * brcmf_p2p_deinit_discovery() - disable P2P device discovery.
552 * @p2p: P2P specific data.
554 * Resets the discovery state and disables it in firmware.
556 static s32 brcmf_p2p_deinit_discovery(struct brcmf_p2p_info *p2p)
558 struct brcmf_cfg80211_vif *vif;
560 brcmf_dbg(TRACE, "enter\n");
562 /* Set the discovery state to SCAN */
563 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
564 (void)brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
566 /* Disable P2P discovery in the firmware */
567 vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
568 (void)brcmf_fil_iovar_int_set(vif->ifp, "p2p_disc", 0);
574 * brcmf_p2p_enable_discovery() - initialize and configure discovery.
576 * @p2p: P2P specific data.
578 * Initializes the discovery device and configure the virtual interface.
580 static int brcmf_p2p_enable_discovery(struct brcmf_p2p_info *p2p)
582 struct brcmf_cfg80211_vif *vif;
585 brcmf_dbg(TRACE, "enter\n");
586 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
588 brcmf_err("P2P config device not available\n");
593 if (test_bit(BRCMF_P2P_STATUS_ENABLED, &p2p->status)) {
594 brcmf_dbg(INFO, "P2P config device already configured\n");
598 /* Re-initialize P2P Discovery in the firmware */
599 vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
600 ret = brcmf_fil_iovar_int_set(vif->ifp, "p2p_disc", 1);
602 brcmf_err("set p2p_disc error\n");
605 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
606 ret = brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
608 brcmf_err("unable to set WL_P2P_DISC_ST_SCAN\n");
613 * Set wsec to any non-zero value in the discovery bsscfg
614 * to ensure our P2P probe responses have the privacy bit
615 * set in the 802.11 WPA IE. Some peer devices may not
616 * initiate WPS with us if this bit is not set.
618 ret = brcmf_fil_bsscfg_int_set(vif->ifp, "wsec", AES_ENABLED);
620 brcmf_err("wsec error %d\n", ret);
624 set_bit(BRCMF_P2P_STATUS_ENABLED, &p2p->status);
630 * brcmf_p2p_escan() - initiate a P2P scan.
632 * @p2p: P2P specific data.
633 * @num_chans: number of channels to scan.
634 * @chanspecs: channel parameters for @num_chans channels.
635 * @search_state: P2P discover state to use.
636 * @action: scan action to pass to firmware.
637 * @bss_type: type of P2P bss.
639 static s32 brcmf_p2p_escan(struct brcmf_p2p_info *p2p, u32 num_chans,
640 u16 chanspecs[], s32 search_state, u16 action,
641 enum p2p_bss_type bss_type)
644 s32 memsize = offsetof(struct brcmf_p2p_scan_le,
645 eparams.params_le.channel_list);
650 struct brcmf_cfg80211_vif *vif;
651 struct brcmf_p2p_scan_le *p2p_params;
652 struct brcmf_scan_params_le *sparams;
653 struct brcmf_ssid ssid;
655 memsize += num_chans * sizeof(__le16);
656 memblk = kzalloc(memsize, GFP_KERNEL);
660 vif = p2p->bss_idx[bss_type].vif;
662 brcmf_err("no vif for bss type %d\n", bss_type);
667 switch (search_state) {
668 case WL_P2P_DISC_ST_SEARCH:
670 * If we in SEARCH STATE, we don't need to set SSID explictly
671 * because dongle use P2P WILDCARD internally by default
675 memset(ssid.SSID, 0, sizeof(ssid.SSID));
677 case WL_P2P_DISC_ST_SCAN:
679 * wpa_supplicant has p2p_find command with type social or
680 * progressive. For progressive, we need to set the ssid to
681 * P2P WILDCARD because we just do broadcast scan unless
684 ssid.SSID_len = BRCMF_P2P_WILDCARD_SSID_LEN;
685 memcpy(ssid.SSID, BRCMF_P2P_WILDCARD_SSID, ssid.SSID_len);
688 brcmf_err(" invalid search state %d\n", search_state);
693 brcmf_p2p_set_discover_state(vif->ifp, search_state, 0, 0);
696 * set p2p scan parameters.
698 p2p_params = (struct brcmf_p2p_scan_le *)memblk;
699 p2p_params->type = 'E';
701 /* determine the scan engine parameters */
702 sparams = &p2p_params->eparams.params_le;
703 sparams->bss_type = DOT11_BSSTYPE_ANY;
704 if (p2p->cfg->active_scan)
705 sparams->scan_type = 0;
707 sparams->scan_type = 1;
709 memset(&sparams->bssid, 0xFF, ETH_ALEN);
711 memcpy(sparams->ssid_le.SSID, ssid.SSID, ssid.SSID_len);
712 sparams->ssid_le.SSID_len = cpu_to_le32(ssid.SSID_len);
713 sparams->home_time = cpu_to_le32(P2PAPI_SCAN_HOME_TIME_MS);
716 * SOCIAL_CHAN_CNT + 1 takes care of the Progressive scan
717 * supported by the supplicant.
719 if (num_chans == SOCIAL_CHAN_CNT || num_chans == (SOCIAL_CHAN_CNT + 1))
720 active = P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS;
721 else if (num_chans == AF_PEER_SEARCH_CNT)
722 active = P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS;
723 else if (wl_get_vif_state_all(p2p->cfg, BRCMF_VIF_STATUS_CONNECTED))
726 active = P2PAPI_SCAN_DWELL_TIME_MS;
728 /* Override scan params to find a peer for a connection */
729 if (num_chans == 1) {
730 active = WL_SCAN_CONNECT_DWELL_TIME_MS;
731 /* WAR to sync with presence period of VSDB GO.
732 * send probe request more frequently
734 nprobes = active / WL_SCAN_JOIN_PROBE_INTERVAL_MS;
736 nprobes = active / P2PAPI_SCAN_NPROBS_TIME_MS;
742 brcmf_dbg(INFO, "nprobes # %d, active_time %d\n", nprobes, active);
743 sparams->active_time = cpu_to_le32(active);
744 sparams->nprobes = cpu_to_le32(nprobes);
745 sparams->passive_time = cpu_to_le32(-1);
746 sparams->channel_num = cpu_to_le32(num_chans &
747 BRCMF_SCAN_PARAMS_COUNT_MASK);
748 for (i = 0; i < num_chans; i++)
749 sparams->channel_list[i] = cpu_to_le16(chanspecs[i]);
751 /* set the escan specific parameters */
752 p2p_params->eparams.version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION);
753 p2p_params->eparams.action = cpu_to_le16(action);
754 p2p_params->eparams.sync_id = cpu_to_le16(0x1234);
755 /* perform p2p scan on primary device */
756 ret = brcmf_fil_bsscfg_data_set(vif->ifp, "p2p_scan", memblk, memsize);
758 set_bit(BRCMF_SCAN_STATUS_BUSY, &p2p->cfg->scan_status);
765 * brcmf_p2p_run_escan() - escan callback for peer-to-peer.
767 * @cfg: driver private data for cfg80211 interface.
768 * @ndev: net device for which scan is requested.
769 * @request: scan request from cfg80211.
770 * @action: scan action.
772 * Determines the P2P discovery state based to scan request parameters and
773 * validates the channels in the request.
775 static s32 brcmf_p2p_run_escan(struct brcmf_cfg80211_info *cfg,
776 struct net_device *ndev,
777 struct cfg80211_scan_request *request,
780 struct brcmf_p2p_info *p2p = &cfg->p2p;
782 s32 search_state = WL_P2P_DISC_ST_SCAN;
783 struct brcmf_cfg80211_vif *vif;
784 struct net_device *dev = NULL;
785 int i, num_nodfs = 0;
788 brcmf_dbg(TRACE, "enter\n");
795 if (request->n_channels) {
796 chanspecs = kcalloc(request->n_channels, sizeof(*chanspecs),
802 vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif;
804 dev = vif->wdev.netdev;
805 if (request->n_channels == 3 &&
806 request->channels[0]->hw_value == SOCIAL_CHAN_1 &&
807 request->channels[1]->hw_value == SOCIAL_CHAN_2 &&
808 request->channels[2]->hw_value == SOCIAL_CHAN_3) {
809 /* SOCIAL CHANNELS 1, 6, 11 */
810 search_state = WL_P2P_DISC_ST_SEARCH;
811 brcmf_dbg(INFO, "P2P SEARCH PHASE START\n");
812 } else if (dev != NULL && vif->mode == WL_MODE_AP) {
813 /* If you are already a GO, then do SEARCH only */
814 brcmf_dbg(INFO, "Already a GO. Do SEARCH Only\n");
815 search_state = WL_P2P_DISC_ST_SEARCH;
817 brcmf_dbg(INFO, "P2P SCAN STATE START\n");
821 * no P2P scanning on passive or DFS channels.
823 for (i = 0; i < request->n_channels; i++) {
824 struct ieee80211_channel *chan = request->channels[i];
826 if (chan->flags & (IEEE80211_CHAN_RADAR |
827 IEEE80211_CHAN_PASSIVE_SCAN))
830 chanspecs[i] = channel_to_chanspec(chan);
831 brcmf_dbg(INFO, "%d: chan=%d, channel spec=%x\n",
832 num_nodfs, chan->hw_value, chanspecs[i]);
835 err = brcmf_p2p_escan(p2p, num_nodfs, chanspecs, search_state,
836 action, P2PAPI_BSSCFG_DEVICE);
840 brcmf_err("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_cfg80211_vif *vif;
941 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
943 brcmf_err("Discovery is not set, so we have nothing to do\n");
948 if (test_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, &p2p->status)) {
949 brcmf_err("Previous LISTEN is not completed yet\n");
950 /* WAR: prevent cookie mismatch in wpa_supplicant return OK */
954 chanspec = brcmf_p2p_chnr_to_chspec(channel);
955 err = brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_LISTEN,
956 chanspec, (u16)duration);
958 set_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, &p2p->status);
959 p2p->remain_on_channel_cookie++;
967 * brcmf_p2p_remain_on_channel() - put device on channel and stay there.
969 * @wiphy: wiphy device.
970 * @channel: channel to stay on.
971 * @duration: time in ms to remain on channel.
974 int brcmf_p2p_remain_on_channel(struct wiphy *wiphy, struct wireless_dev *wdev,
975 struct ieee80211_channel *channel,
976 unsigned int duration, u64 *cookie)
978 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
979 struct brcmf_p2p_info *p2p = &cfg->p2p;
983 channel_nr = ieee80211_frequency_to_channel(channel->center_freq);
984 brcmf_dbg(TRACE, "Enter, channel: %d, duration ms (%d)\n", channel_nr,
987 err = brcmf_p2p_enable_discovery(p2p);
990 err = brcmf_p2p_discover_listen(p2p, channel_nr, duration);
994 memcpy(&p2p->remain_on_channel, channel, sizeof(*channel));
995 *cookie = p2p->remain_on_channel_cookie;
996 cfg80211_ready_on_channel(wdev, *cookie, channel, duration, GFP_KERNEL);
1004 * brcmf_p2p_notify_listen_complete() - p2p listen has completed.
1006 * @ifp: interfac control.
1007 * @e: event message. Not used, to make it usable for fweh event dispatcher.
1008 * @data: payload of message. Not used.
1011 int brcmf_p2p_notify_listen_complete(struct brcmf_if *ifp,
1012 const struct brcmf_event_msg *e,
1015 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
1016 struct brcmf_p2p_info *p2p = &cfg->p2p;
1018 brcmf_dbg(TRACE, "Enter\n");
1019 if (test_and_clear_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN,
1021 if (test_and_clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN,
1023 clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME,
1025 brcmf_dbg(INFO, "Listen DONE, wake up wait_next_af\n");
1026 complete(&p2p->wait_next_af);
1029 cfg80211_remain_on_channel_expired(&ifp->vif->wdev,
1030 p2p->remain_on_channel_cookie,
1031 &p2p->remain_on_channel,
1039 * brcmf_p2p_cancel_remain_on_channel() - cancel p2p listen state.
1041 * @ifp: interfac control.
1044 void brcmf_p2p_cancel_remain_on_channel(struct brcmf_if *ifp)
1048 brcmf_p2p_set_discover_state(ifp, WL_P2P_DISC_ST_SCAN, 0, 0);
1049 brcmf_p2p_notify_listen_complete(ifp, NULL, NULL);
1054 * brcmf_p2p_act_frm_search() - search function for action frame.
1057 * channel: channel on which action frame is to be trasmitted.
1059 * search function to reach at common channel to send action frame. When
1060 * channel is 0 then all social channels will be used to send af
1062 static s32 brcmf_p2p_act_frm_search(struct brcmf_p2p_info *p2p, u16 channel)
1066 u16 *default_chan_list;
1069 brcmf_dbg(TRACE, "Enter\n");
1072 channel_cnt = AF_PEER_SEARCH_CNT;
1074 channel_cnt = SOCIAL_CHAN_CNT;
1075 default_chan_list = kzalloc(channel_cnt * sizeof(*default_chan_list),
1077 if (default_chan_list == NULL) {
1078 brcmf_err("channel list allocation failed\n");
1083 /* insert same channel to the chan_list */
1084 for (i = 0; i < channel_cnt; i++)
1085 default_chan_list[i] =
1086 brcmf_p2p_chnr_to_chspec(channel);
1088 default_chan_list[0] = brcmf_p2p_chnr_to_chspec(SOCIAL_CHAN_1);
1089 default_chan_list[1] = brcmf_p2p_chnr_to_chspec(SOCIAL_CHAN_2);
1090 default_chan_list[2] = brcmf_p2p_chnr_to_chspec(SOCIAL_CHAN_3);
1092 err = brcmf_p2p_escan(p2p, channel_cnt, default_chan_list,
1093 WL_P2P_DISC_ST_SEARCH, WL_ESCAN_ACTION_START,
1094 P2PAPI_BSSCFG_DEVICE);
1095 kfree(default_chan_list);
1102 * brcmf_p2p_afx_handler() - afx worker thread.
1107 static void brcmf_p2p_afx_handler(struct work_struct *work)
1109 struct afx_hdl *afx_hdl = container_of(work, struct afx_hdl, afx_work);
1110 struct brcmf_p2p_info *p2p = container_of(afx_hdl,
1111 struct brcmf_p2p_info,
1115 if (!afx_hdl->is_active)
1118 if (afx_hdl->is_listen && afx_hdl->my_listen_chan)
1120 err = brcmf_p2p_discover_listen(p2p, afx_hdl->my_listen_chan,
1121 100 * (1 + (random32() % 3)));
1123 err = brcmf_p2p_act_frm_search(p2p, afx_hdl->peer_listen_chan);
1126 brcmf_err("ERROR occurred! value is (%d)\n", err);
1127 if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL,
1129 complete(&afx_hdl->act_frm_scan);
1135 * brcmf_p2p_af_searching_channel() - search channel.
1137 * @p2p: p2p device info struct.
1140 static s32 brcmf_p2p_af_searching_channel(struct brcmf_p2p_info *p2p)
1142 struct afx_hdl *afx_hdl = &p2p->afx_hdl;
1143 struct brcmf_cfg80211_vif *pri_vif;
1144 unsigned long duration;
1147 brcmf_dbg(TRACE, "Enter\n");
1149 pri_vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
1151 INIT_COMPLETION(afx_hdl->act_frm_scan);
1152 set_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, &p2p->status);
1153 afx_hdl->is_active = true;
1154 afx_hdl->peer_chan = P2P_INVALID_CHANNEL;
1156 /* Loop to wait until we find a peer's channel or the
1157 * pending action frame tx is cancelled.
1160 duration = msecs_to_jiffies(P2P_AF_FRM_SCAN_MAX_WAIT);
1161 while ((retry < P2P_CHANNEL_SYNC_RETRY) &&
1162 (afx_hdl->peer_chan == P2P_INVALID_CHANNEL)) {
1163 afx_hdl->is_listen = false;
1164 brcmf_dbg(TRACE, "Scheduling action frame for sending.. (%d)\n",
1166 /* search peer on peer's listen channel */
1167 schedule_work(&afx_hdl->afx_work);
1168 wait_for_completion_timeout(&afx_hdl->act_frm_scan, duration);
1169 if ((afx_hdl->peer_chan != P2P_INVALID_CHANNEL) ||
1170 (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL,
1174 if (afx_hdl->my_listen_chan) {
1175 brcmf_dbg(TRACE, "Scheduling listen peer, channel=%d\n",
1176 afx_hdl->my_listen_chan);
1177 /* listen on my listen channel */
1178 afx_hdl->is_listen = true;
1179 schedule_work(&afx_hdl->afx_work);
1180 wait_for_completion_timeout(&afx_hdl->act_frm_scan,
1183 if ((afx_hdl->peer_chan != P2P_INVALID_CHANNEL) ||
1184 (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL,
1189 /* if sta is connected or connecting, sleep for a while before
1190 * retry af tx or finding a peer
1192 if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &pri_vif->sme_state) ||
1193 test_bit(BRCMF_VIF_STATUS_CONNECTING, &pri_vif->sme_state))
1194 msleep(P2P_DEFAULT_SLEEP_TIME_VSDB);
1197 brcmf_dbg(TRACE, "Completed search/listen peer_chan=%d\n",
1198 afx_hdl->peer_chan);
1199 afx_hdl->is_active = false;
1201 clear_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, &p2p->status);
1203 return afx_hdl->peer_chan;
1208 * brcmf_p2p_scan_finding_common_channel() - was escan used for finding channel
1210 * @cfg: common configuration struct.
1211 * @bi: bss info struct, result from scan.
1214 bool brcmf_p2p_scan_finding_common_channel(struct brcmf_cfg80211_info *cfg,
1215 struct brcmf_bss_info_le *bi)
1218 struct brcmf_p2p_info *p2p = &cfg->p2p;
1219 struct afx_hdl *afx_hdl = &p2p->afx_hdl;
1222 u8 p2p_dev_addr[ETH_ALEN];
1224 if (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, &p2p->status))
1228 brcmf_dbg(TRACE, "ACTION FRAME SCAN Done\n");
1229 if (afx_hdl->peer_chan == P2P_INVALID_CHANNEL)
1230 complete(&afx_hdl->act_frm_scan);
1234 ie = ((u8 *)bi) + le16_to_cpu(bi->ie_offset);
1235 memset(p2p_dev_addr, 0, sizeof(p2p_dev_addr));
1236 err = cfg80211_get_p2p_attr(ie, le32_to_cpu(bi->ie_length),
1237 IEEE80211_P2P_ATTR_DEVICE_INFO,
1238 p2p_dev_addr, sizeof(p2p_dev_addr));
1240 err = cfg80211_get_p2p_attr(ie, le32_to_cpu(bi->ie_length),
1241 IEEE80211_P2P_ATTR_DEVICE_ID,
1242 p2p_dev_addr, sizeof(p2p_dev_addr));
1244 (!memcmp(p2p_dev_addr, afx_hdl->tx_dst_addr, ETH_ALEN))) {
1245 afx_hdl->peer_chan = bi->ctl_ch ? bi->ctl_ch :
1246 CHSPEC_CHANNEL(le16_to_cpu(bi->chanspec));
1247 brcmf_dbg(TRACE, "ACTION FRAME SCAN : Peer %pM found, channel : %d\n",
1248 afx_hdl->tx_dst_addr, afx_hdl->peer_chan);
1249 complete(&afx_hdl->act_frm_scan);
1255 * brcmf_p2p_stop_wait_next_action_frame() - finish scan if af tx complete.
1257 * @cfg: common configuration struct.
1261 brcmf_p2p_stop_wait_next_action_frame(struct brcmf_cfg80211_info *cfg)
1263 struct brcmf_p2p_info *p2p = &cfg->p2p;
1264 struct net_device *ndev = cfg->escan_info.ndev;
1266 if (test_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME, &p2p->status) &&
1267 (test_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status) ||
1268 test_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status))) {
1269 brcmf_dbg(TRACE, "*** Wake UP ** abort actframe iovar\n");
1270 /* if channel is not zero, "actfame" uses off channel scan.
1271 * So abort scan for off channel completion.
1273 if (p2p->af_sent_channel)
1274 brcmf_notify_escan_complete(cfg, ndev, true, true);
1275 } else if (test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN,
1277 brcmf_dbg(TRACE, "*** Wake UP ** abort listen for next af frame\n");
1278 /* So abort scan to cancel listen */
1279 brcmf_notify_escan_complete(cfg, ndev, true, true);
1285 * brcmf_p2p_gon_req_collision() - Check if go negotiaton collission
1287 * @p2p: p2p device info struct.
1289 * return true if recevied action frame is to be dropped.
1292 brcmf_p2p_gon_req_collision(struct brcmf_p2p_info *p2p, u8 *mac)
1294 struct brcmf_cfg80211_info *cfg = p2p->cfg;
1295 struct brcmf_if *ifp;
1297 brcmf_dbg(TRACE, "Enter\n");
1299 if (!test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, &p2p->status) ||
1300 !p2p->gon_req_action)
1303 brcmf_dbg(TRACE, "GO Negotiation Request COLLISION !!!\n");
1304 /* if sa(peer) addr is less than da(my) addr, then this device
1305 * process peer's gon request and block to send gon req.
1306 * if not (sa addr > da addr),
1307 * this device will process gon request and drop gon req of peer.
1309 ifp = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif->ifp;
1310 if (memcmp(mac, ifp->mac_addr, ETH_ALEN) < 0) {
1311 brcmf_dbg(INFO, "Block transmit gon req !!!\n");
1312 p2p->block_gon_req_tx = true;
1313 /* if we are finding a common channel for sending af,
1314 * do not scan more to block to send current gon req
1316 if (test_and_clear_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL,
1318 complete(&p2p->afx_hdl.act_frm_scan);
1319 if (test_and_clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME,
1321 brcmf_p2p_stop_wait_next_action_frame(cfg);
1325 /* drop gon request of peer to process gon request by this device. */
1326 brcmf_dbg(INFO, "Drop received gon req !!!\n");
1333 * brcmf_p2p_notify_action_frame_rx() - received action frame.
1335 * @ifp: interfac control.
1336 * @e: event message. Not used, to make it usable for fweh event dispatcher.
1337 * @data: payload of message, containing action frame data.
1340 int brcmf_p2p_notify_action_frame_rx(struct brcmf_if *ifp,
1341 const struct brcmf_event_msg *e,
1344 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
1345 struct brcmf_p2p_info *p2p = &cfg->p2p;
1346 struct afx_hdl *afx_hdl = &p2p->afx_hdl;
1347 struct wireless_dev *wdev;
1348 u32 mgmt_frame_len = e->datalen - sizeof(struct brcmf_rx_mgmt_data);
1349 struct brcmf_rx_mgmt_data *rxframe = (struct brcmf_rx_mgmt_data *)data;
1350 u8 *frame = (u8 *)(rxframe + 1);
1351 struct brcmf_p2p_pub_act_frame *act_frm;
1352 struct brcmf_p2psd_gas_pub_act_frame *sd_act_frm;
1353 u16 chanspec = be16_to_cpu(rxframe->chanspec);
1354 struct ieee80211_mgmt *mgmt_frame;
1359 /* Check if wpa_supplicant has registered for this frame */
1360 brcmf_dbg(INFO, "ifp->vif->mgmt_rx_reg %04x\n", ifp->vif->mgmt_rx_reg);
1361 mgmt_type = (IEEE80211_STYPE_ACTION & IEEE80211_FCTL_STYPE) >> 4;
1362 if ((ifp->vif->mgmt_rx_reg & BIT(mgmt_type)) == 0)
1365 brcmf_p2p_print_actframe(false, frame, mgmt_frame_len);
1367 action = P2P_PAF_SUBTYPE_INVALID;
1368 if (brcmf_p2p_is_pub_action(frame, mgmt_frame_len)) {
1369 act_frm = (struct brcmf_p2p_pub_act_frame *)frame;
1370 action = act_frm->subtype;
1371 if ((action == P2P_PAF_GON_REQ) &&
1372 (brcmf_p2p_gon_req_collision(p2p, (u8 *)e->addr))) {
1373 if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL,
1375 (memcmp(afx_hdl->tx_dst_addr, e->addr,
1377 afx_hdl->peer_chan = CHSPEC_CHANNEL(chanspec);
1378 brcmf_dbg(INFO, "GON request: Peer found, channel=%d\n",
1379 afx_hdl->peer_chan);
1380 complete(&afx_hdl->act_frm_scan);
1384 /* After complete GO Negotiation, roll back to mpc mode */
1385 if ((action == P2P_PAF_GON_CONF) ||
1386 (action == P2P_PAF_PROVDIS_RSP))
1387 brcmf_set_mpc(ifp->ndev, 1);
1388 if (action == P2P_PAF_GON_CONF) {
1389 brcmf_dbg(TRACE, "P2P: GO_NEG_PHASE status cleared\n");
1390 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
1392 } else if (brcmf_p2p_is_gas_action(frame, mgmt_frame_len)) {
1393 sd_act_frm = (struct brcmf_p2psd_gas_pub_act_frame *)frame;
1394 action = sd_act_frm->action;
1397 if (test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, &p2p->status) &&
1398 (p2p->next_af_subtype == action)) {
1399 brcmf_dbg(TRACE, "We got a right next frame! (%d)\n", action);
1400 clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME,
1402 /* Stop waiting for next AF. */
1403 brcmf_p2p_stop_wait_next_action_frame(cfg);
1406 mgmt_frame = kzalloc(offsetof(struct ieee80211_mgmt, u) +
1407 mgmt_frame_len, GFP_KERNEL);
1409 brcmf_err("No memory available for action frame\n");
1412 memcpy(mgmt_frame->da, ifp->mac_addr, ETH_ALEN);
1413 brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSSID, mgmt_frame->bssid,
1415 memcpy(mgmt_frame->sa, e->addr, ETH_ALEN);
1416 mgmt_frame->frame_control = cpu_to_le16(IEEE80211_STYPE_ACTION);
1417 memcpy(&mgmt_frame->u, frame, mgmt_frame_len);
1418 mgmt_frame_len += offsetof(struct ieee80211_mgmt, u);
1420 freq = ieee80211_channel_to_frequency(CHSPEC_CHANNEL(chanspec),
1421 CHSPEC_IS2G(chanspec) ?
1422 IEEE80211_BAND_2GHZ :
1423 IEEE80211_BAND_5GHZ);
1424 wdev = ifp->ndev->ieee80211_ptr;
1425 cfg80211_rx_mgmt(wdev, freq, 0, (u8 *)mgmt_frame, mgmt_frame_len,
1434 * brcmf_p2p_notify_action_tx_complete() - transmit action frame complete
1436 * @ifp: interfac control.
1437 * @e: event message. Not used, to make it usable for fweh event dispatcher.
1441 int brcmf_p2p_notify_action_tx_complete(struct brcmf_if *ifp,
1442 const struct brcmf_event_msg *e,
1445 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
1446 struct brcmf_p2p_info *p2p = &cfg->p2p;
1448 brcmf_dbg(INFO, "Enter: event %s, status=%d\n",
1449 e->event_code == BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE ?
1450 "ACTION_FRAME_OFF_CHAN_COMPLETE" : "ACTION_FRAME_COMPLETE",
1453 if (!test_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME, &p2p->status))
1456 if (e->event_code == BRCMF_E_ACTION_FRAME_COMPLETE) {
1457 if (e->status == BRCMF_E_STATUS_SUCCESS)
1458 set_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED,
1461 set_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
1462 /* If there is no ack, we don't need to wait for
1463 * WLC_E_ACTION_FRAME_OFFCHAN_COMPLETE event
1465 brcmf_p2p_stop_wait_next_action_frame(cfg);
1469 complete(&p2p->send_af_done);
1476 * brcmf_p2p_tx_action_frame() - send action frame over fil.
1478 * @p2p: p2p info struct for vif.
1479 * @af_params: action frame data/info.
1481 * Send an action frame immediately without doing channel synchronization.
1483 * This function waits for a completion event before returning.
1484 * The WLC_E_ACTION_FRAME_COMPLETE event will be received when the action
1485 * frame is transmitted.
1487 static s32 brcmf_p2p_tx_action_frame(struct brcmf_p2p_info *p2p,
1488 struct brcmf_fil_af_params_le *af_params)
1490 struct brcmf_cfg80211_vif *vif;
1494 brcmf_dbg(TRACE, "Enter\n");
1496 INIT_COMPLETION(p2p->send_af_done);
1497 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
1498 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
1500 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
1501 err = brcmf_fil_bsscfg_data_set(vif->ifp, "actframe", af_params,
1502 sizeof(*af_params));
1504 brcmf_err(" sending action frame has failed\n");
1508 p2p->af_sent_channel = le32_to_cpu(af_params->channel);
1509 p2p->af_tx_sent_jiffies = jiffies;
1511 timeout = wait_for_completion_timeout(&p2p->send_af_done,
1512 msecs_to_jiffies(P2P_AF_MAX_WAIT_TIME));
1514 if (test_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status)) {
1515 brcmf_dbg(TRACE, "TX action frame operation is success\n");
1518 brcmf_dbg(TRACE, "TX action frame operation has failed\n");
1520 /* clear status bit for action tx */
1521 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status);
1522 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status);
1530 * brcmf_p2p_pub_af_tx() - public action frame tx routine.
1532 * @cfg: driver private data for cfg80211 interface.
1533 * @af_params: action frame data/info.
1534 * @config_af_params: configuration data for action frame.
1536 * routine which transmits ation frame public type.
1538 static s32 brcmf_p2p_pub_af_tx(struct brcmf_cfg80211_info *cfg,
1539 struct brcmf_fil_af_params_le *af_params,
1540 struct brcmf_config_af_params *config_af_params)
1542 struct brcmf_p2p_info *p2p = &cfg->p2p;
1543 struct brcmf_fil_action_frame_le *action_frame;
1544 struct brcmf_p2p_pub_act_frame *act_frm;
1548 action_frame = &af_params->action_frame;
1549 act_frm = (struct brcmf_p2p_pub_act_frame *)(action_frame->data);
1551 config_af_params->extra_listen = true;
1553 switch (act_frm->subtype) {
1554 case P2P_PAF_GON_REQ:
1555 brcmf_dbg(TRACE, "P2P: GO_NEG_PHASE status set\n");
1556 set_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
1557 config_af_params->mpc_onoff = 0;
1558 config_af_params->search_channel = true;
1559 p2p->next_af_subtype = act_frm->subtype + 1;
1560 p2p->gon_req_action = true;
1561 /* increase dwell time to wait for RESP frame */
1562 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1564 case P2P_PAF_GON_RSP:
1565 p2p->next_af_subtype = act_frm->subtype + 1;
1566 /* increase dwell time to wait for CONF frame */
1567 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1569 case P2P_PAF_GON_CONF:
1570 /* If we reached till GO Neg confirmation reset the filter */
1571 brcmf_dbg(TRACE, "P2P: GO_NEG_PHASE status cleared\n");
1572 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
1573 /* turn on mpc again if go nego is done */
1574 config_af_params->mpc_onoff = 1;
1575 /* minimize dwell time */
1576 af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
1577 config_af_params->extra_listen = false;
1579 case P2P_PAF_INVITE_REQ:
1580 config_af_params->search_channel = true;
1581 p2p->next_af_subtype = act_frm->subtype + 1;
1582 /* increase dwell time */
1583 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1585 case P2P_PAF_INVITE_RSP:
1586 /* minimize dwell time */
1587 af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
1588 config_af_params->extra_listen = false;
1590 case P2P_PAF_DEVDIS_REQ:
1591 config_af_params->search_channel = true;
1592 p2p->next_af_subtype = act_frm->subtype + 1;
1593 /* maximize dwell time to wait for RESP frame */
1594 af_params->dwell_time = cpu_to_le32(P2P_AF_LONG_DWELL_TIME);
1596 case P2P_PAF_DEVDIS_RSP:
1597 /* minimize dwell time */
1598 af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
1599 config_af_params->extra_listen = false;
1601 case P2P_PAF_PROVDIS_REQ:
1602 ie_len = le16_to_cpu(action_frame->len) -
1603 offsetof(struct brcmf_p2p_pub_act_frame, elts);
1604 if (cfg80211_get_p2p_attr(&act_frm->elts[0], ie_len,
1605 IEEE80211_P2P_ATTR_GROUP_ID,
1607 config_af_params->search_channel = true;
1608 config_af_params->mpc_onoff = 0;
1609 p2p->next_af_subtype = act_frm->subtype + 1;
1610 /* increase dwell time to wait for RESP frame */
1611 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1613 case P2P_PAF_PROVDIS_RSP:
1614 /* wpa_supplicant send go nego req right after prov disc */
1615 p2p->next_af_subtype = P2P_PAF_GON_REQ;
1616 /* increase dwell time to MED level */
1617 af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1618 config_af_params->extra_listen = false;
1621 brcmf_err("Unknown p2p pub act frame subtype: %d\n",
1629 * brcmf_p2p_send_action_frame() - send action frame .
1631 * @cfg: driver private data for cfg80211 interface.
1632 * @ndev: net device to transmit on.
1633 * @af_params: configuration data for action frame.
1635 bool brcmf_p2p_send_action_frame(struct brcmf_cfg80211_info *cfg,
1636 struct net_device *ndev,
1637 struct brcmf_fil_af_params_le *af_params)
1639 struct brcmf_p2p_info *p2p = &cfg->p2p;
1640 struct brcmf_fil_action_frame_le *action_frame;
1641 struct brcmf_config_af_params config_af_params;
1642 struct afx_hdl *afx_hdl = &p2p->afx_hdl;
1643 u16 action_frame_len;
1648 s32 extra_listen_time;
1651 action_frame = &af_params->action_frame;
1652 action_frame_len = le16_to_cpu(action_frame->len);
1654 brcmf_p2p_print_actframe(true, action_frame->data, action_frame_len);
1656 /* Add the default dwell time. Dwell time to stay off-channel */
1657 /* to wait for a response action frame after transmitting an */
1658 /* GO Negotiation action frame */
1659 af_params->dwell_time = cpu_to_le32(P2P_AF_DWELL_TIME);
1661 category = action_frame->data[DOT11_ACTION_CAT_OFF];
1662 action = action_frame->data[DOT11_ACTION_ACT_OFF];
1664 /* initialize variables */
1665 p2p->next_af_subtype = P2P_PAF_SUBTYPE_INVALID;
1666 p2p->gon_req_action = false;
1668 /* config parameters */
1669 config_af_params.mpc_onoff = -1;
1670 config_af_params.search_channel = false;
1671 config_af_params.extra_listen = false;
1673 if (brcmf_p2p_is_pub_action(action_frame->data, action_frame_len)) {
1674 /* p2p public action frame process */
1675 if (brcmf_p2p_pub_af_tx(cfg, af_params, &config_af_params)) {
1676 /* Just send unknown subtype frame with */
1677 /* default parameters. */
1678 brcmf_err("P2P Public action frame, unknown subtype.\n");
1680 } else if (brcmf_p2p_is_gas_action(action_frame->data,
1681 action_frame_len)) {
1682 /* service discovery process */
1683 if (action == P2PSD_ACTION_ID_GAS_IREQ ||
1684 action == P2PSD_ACTION_ID_GAS_CREQ) {
1685 /* configure service discovery query frame */
1686 config_af_params.search_channel = true;
1688 /* save next af suptype to cancel */
1689 /* remaining dwell time */
1690 p2p->next_af_subtype = action + 1;
1692 af_params->dwell_time =
1693 cpu_to_le32(P2P_AF_MED_DWELL_TIME);
1694 } else if (action == P2PSD_ACTION_ID_GAS_IRESP ||
1695 action == P2PSD_ACTION_ID_GAS_CRESP) {
1696 /* configure service discovery response frame */
1697 af_params->dwell_time =
1698 cpu_to_le32(P2P_AF_MIN_DWELL_TIME);
1700 brcmf_err("Unknown action type: %d\n", action);
1703 } else if (brcmf_p2p_is_p2p_action(action_frame->data,
1704 action_frame_len)) {
1705 /* do not configure anything. it will be */
1706 /* sent with a default configuration */
1708 brcmf_err("Unknown Frame: category 0x%x, action 0x%x\n",
1713 /* if connecting on primary iface, sleep for a while before sending
1716 if (test_bit(BRCMF_VIF_STATUS_CONNECTING,
1717 &p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->sme_state))
1720 /* if scan is ongoing, abort current scan. */
1721 if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
1722 brcmf_abort_scanning(cfg);
1724 memcpy(afx_hdl->tx_dst_addr, action_frame->da, ETH_ALEN);
1726 /* To make sure to send successfully action frame, turn off mpc */
1727 if (config_af_params.mpc_onoff == 0)
1728 brcmf_set_mpc(ndev, 0);
1730 /* set status and destination address before sending af */
1731 if (p2p->next_af_subtype != P2P_PAF_SUBTYPE_INVALID) {
1732 /* set status to cancel the remained dwell time in rx process */
1733 set_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, &p2p->status);
1736 p2p->af_sent_channel = 0;
1737 set_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME, &p2p->status);
1738 /* validate channel and p2p ies */
1739 if (config_af_params.search_channel &&
1740 IS_P2P_SOCIAL_CHANNEL(le32_to_cpu(af_params->channel)) &&
1741 p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif->saved_ie.probe_req_ie_len) {
1742 afx_hdl = &p2p->afx_hdl;
1743 afx_hdl->peer_listen_chan = le32_to_cpu(af_params->channel);
1745 if (brcmf_p2p_af_searching_channel(p2p) ==
1746 P2P_INVALID_CHANNEL) {
1747 brcmf_err("Couldn't find peer's channel.\n");
1751 /* Abort scan even for VSDB scenarios. Scan gets aborted in
1752 * firmware but after the check of piggyback algorithm. To take
1753 * care of current piggback algo, lets abort the scan here
1756 brcmf_notify_escan_complete(cfg, ndev, true, true);
1758 /* update channel */
1759 af_params->channel = cpu_to_le32(afx_hdl->peer_chan);
1763 while (!p2p->block_gon_req_tx &&
1764 (ack == false) && (tx_retry < P2P_AF_TX_MAX_RETRY)) {
1765 ack = !brcmf_p2p_tx_action_frame(p2p, af_params);
1769 brcmf_err("Failed to send Action Frame(retry %d)\n", tx_retry);
1770 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
1774 clear_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME, &p2p->status);
1776 /* WAR: sometimes dongle does not keep the dwell time of 'actframe'.
1777 * if we coundn't get the next action response frame and dongle does
1778 * not keep the dwell time, go to listen state again to get next action
1781 if (ack && config_af_params.extra_listen && !p2p->block_gon_req_tx &&
1782 test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, &p2p->status) &&
1783 p2p->af_sent_channel == afx_hdl->my_listen_chan) {
1784 delta_ms = jiffies_to_msecs(jiffies - p2p->af_tx_sent_jiffies);
1785 if (le32_to_cpu(af_params->dwell_time) > delta_ms)
1786 extra_listen_time = le32_to_cpu(af_params->dwell_time) -
1789 extra_listen_time = 0;
1790 if (extra_listen_time > 50) {
1791 set_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN,
1793 brcmf_dbg(INFO, "Wait more time! actual af time:%d, calculated extra listen:%d\n",
1794 le32_to_cpu(af_params->dwell_time),
1796 extra_listen_time += 100;
1797 if (!brcmf_p2p_discover_listen(p2p,
1798 p2p->af_sent_channel,
1799 extra_listen_time)) {
1800 unsigned long duration;
1802 extra_listen_time += 100;
1803 duration = msecs_to_jiffies(extra_listen_time);
1804 wait_for_completion_timeout(&p2p->wait_next_af,
1807 clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN,
1812 if (p2p->block_gon_req_tx) {
1813 /* if ack is true, supplicant will wait more time(100ms).
1814 * so we will return it as a success to get more time .
1816 p2p->block_gon_req_tx = false;
1820 clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, &p2p->status);
1821 /* if all done, turn mpc on again */
1822 if (config_af_params.mpc_onoff == 1)
1823 brcmf_set_mpc(ndev, 1);
1829 * brcmf_p2p_notify_rx_mgmt_p2p_probereq() - Event handler for p2p probe req.
1831 * @ifp: interface pointer for which event was received.
1833 * @data: payload of event message (probe request).
1835 s32 brcmf_p2p_notify_rx_mgmt_p2p_probereq(struct brcmf_if *ifp,
1836 const struct brcmf_event_msg *e,
1839 struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
1840 struct brcmf_p2p_info *p2p = &cfg->p2p;
1841 struct afx_hdl *afx_hdl = &p2p->afx_hdl;
1842 struct wireless_dev *wdev;
1843 struct brcmf_cfg80211_vif *vif = ifp->vif;
1844 struct brcmf_rx_mgmt_data *rxframe = (struct brcmf_rx_mgmt_data *)data;
1845 u16 chanspec = be16_to_cpu(rxframe->chanspec);
1851 brcmf_dbg(INFO, "Enter: event %d reason %d\n", e->event_code,
1854 if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, &p2p->status) &&
1855 (memcmp(afx_hdl->tx_dst_addr, e->addr, ETH_ALEN) == 0)) {
1856 afx_hdl->peer_chan = CHSPEC_CHANNEL(chanspec);
1857 brcmf_dbg(INFO, "PROBE REQUEST: Peer found, channel=%d\n",
1858 afx_hdl->peer_chan);
1859 complete(&afx_hdl->act_frm_scan);
1862 /* Firmware sends us two proberesponses for each idx one. At the */
1863 /* moment anything but bsscfgidx 0 is passed up to supplicant */
1864 if (e->bsscfgidx == 0)
1867 /* Filter any P2P probe reqs arriving during the GO-NEG Phase */
1868 if (test_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status)) {
1869 brcmf_dbg(INFO, "Filtering P2P probe_req in GO-NEG phase\n");
1873 /* Check if wpa_supplicant has registered for this frame */
1874 brcmf_dbg(INFO, "vif->mgmt_rx_reg %04x\n", vif->mgmt_rx_reg);
1875 mgmt_type = (IEEE80211_STYPE_PROBE_REQ & IEEE80211_FCTL_STYPE) >> 4;
1876 if ((vif->mgmt_rx_reg & BIT(mgmt_type)) == 0)
1879 mgmt_frame = (u8 *)(rxframe + 1);
1880 mgmt_frame_len = e->datalen - sizeof(*rxframe);
1881 freq = ieee80211_channel_to_frequency(CHSPEC_CHANNEL(chanspec),
1882 CHSPEC_IS2G(chanspec) ?
1883 IEEE80211_BAND_2GHZ :
1884 IEEE80211_BAND_5GHZ);
1885 wdev = ifp->ndev->ieee80211_ptr;
1886 cfg80211_rx_mgmt(wdev, freq, 0, mgmt_frame, mgmt_frame_len, GFP_ATOMIC);
1888 brcmf_dbg(INFO, "mgmt_frame_len (%d) , e->datalen (%d), chanspec (%04x), freq (%d)\n",
1889 mgmt_frame_len, e->datalen, chanspec, freq);
1896 * brcmf_p2p_attach() - attach for P2P.
1898 * @cfg: driver private data for cfg80211 interface.
1900 s32 brcmf_p2p_attach(struct brcmf_cfg80211_info *cfg)
1902 struct brcmf_if *pri_ifp;
1903 struct brcmf_if *p2p_ifp;
1904 struct brcmf_cfg80211_vif *p2p_vif;
1905 struct brcmf_p2p_info *p2p;
1906 struct brcmf_pub *drvr;
1915 pri_ifp = drvr->iflist[0];
1916 p2p_ifp = drvr->iflist[1];
1918 p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif = pri_ifp->vif;
1921 p2p_vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_P2P_DEVICE,
1923 if (IS_ERR(p2p_vif)) {
1924 brcmf_err("could not create discovery vif\n");
1929 p2p_vif->ifp = p2p_ifp;
1930 p2p_ifp->vif = p2p_vif;
1931 p2p_vif->wdev.netdev = p2p_ifp->ndev;
1932 p2p_ifp->ndev->ieee80211_ptr = &p2p_vif->wdev;
1933 SET_NETDEV_DEV(p2p_ifp->ndev, wiphy_dev(cfg->wiphy));
1935 p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif = p2p_vif;
1937 brcmf_p2p_generate_bss_mac(p2p);
1938 brcmf_p2p_set_firmware(pri_ifp, p2p->dev_addr);
1940 /* Initialize P2P Discovery in the firmware */
1941 err = brcmf_fil_iovar_int_set(pri_ifp, "p2p_disc", 1);
1943 brcmf_err("set p2p_disc error\n");
1944 brcmf_free_vif(p2p_vif);
1947 /* obtain bsscfg index for P2P discovery */
1948 err = brcmf_fil_iovar_int_get(pri_ifp, "p2p_dev", &bssidx);
1950 brcmf_err("retrieving discover bsscfg index failed\n");
1951 brcmf_free_vif(p2p_vif);
1954 /* Verify that firmware uses same bssidx as driver !! */
1955 if (p2p_ifp->bssidx != bssidx) {
1956 brcmf_err("Incorrect bssidx=%d, compared to p2p_ifp->bssidx=%d\n",
1957 bssidx, p2p_ifp->bssidx);
1958 brcmf_free_vif(p2p_vif);
1962 init_completion(&p2p->send_af_done);
1963 INIT_WORK(&p2p->afx_hdl.afx_work, brcmf_p2p_afx_handler);
1964 init_completion(&p2p->afx_hdl.act_frm_scan);
1965 init_completion(&p2p->wait_next_af);
1973 * brcmf_p2p_detach() - detach P2P.
1975 * @p2p: P2P specific data.
1977 void brcmf_p2p_detach(struct brcmf_p2p_info *p2p)
1979 struct brcmf_cfg80211_vif *vif;
1981 vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
1983 brcmf_p2p_cancel_remain_on_channel(vif->ifp);
1984 brcmf_p2p_deinit_discovery(p2p);
1985 /* remove discovery interface */
1986 brcmf_free_vif(vif);
1987 p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif = NULL;
1989 /* just set it all to zero */
1990 memset(p2p, 0, sizeof(*p2p));
1994 * brcmf_p2p_get_current_chanspec() - Get current operation channel.
1996 * @p2p: P2P specific data.
1997 * @chanspec: chanspec to be returned.
1999 static void brcmf_p2p_get_current_chanspec(struct brcmf_p2p_info *p2p,
2002 struct brcmf_if *ifp;
2003 struct brcmf_fil_chan_info_le ci;
2006 ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
2008 *chanspec = 11 & WL_CHANSPEC_CHAN_MASK;
2010 err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_CHANNEL, &ci, sizeof(ci));
2012 *chanspec = le32_to_cpu(ci.hw_channel) & WL_CHANSPEC_CHAN_MASK;
2013 if (*chanspec < CH_MAX_2G_CHANNEL)
2014 *chanspec |= WL_CHANSPEC_BAND_2G;
2016 *chanspec |= WL_CHANSPEC_BAND_5G;
2018 *chanspec |= WL_CHANSPEC_BW_20 | WL_CHANSPEC_CTL_SB_NONE;
2022 * Change a P2P Role.
2024 * @mac: MAC address of the BSS to change a role
2025 * Returns 0 if success.
2027 int brcmf_p2p_ifchange(struct brcmf_cfg80211_info *cfg,
2028 enum brcmf_fil_p2p_if_types if_type)
2030 struct brcmf_p2p_info *p2p = &cfg->p2p;
2031 struct brcmf_cfg80211_vif *vif;
2032 struct brcmf_fil_p2p_if_le if_request;
2036 brcmf_dbg(TRACE, "Enter\n");
2038 vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
2040 brcmf_err("vif for P2PAPI_BSSCFG_PRIMARY does not exist\n");
2043 brcmf_notify_escan_complete(cfg, vif->ifp->ndev, true, true);
2044 vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif;
2046 brcmf_err("vif for P2PAPI_BSSCFG_CONNECTION does not exist\n");
2049 brcmf_set_mpc(vif->ifp->ndev, 0);
2051 /* In concurrency case, STA may be already associated in a particular */
2052 /* channel. so retrieve the current channel of primary interface and */
2053 /* then start the virtual interface on that. */
2054 brcmf_p2p_get_current_chanspec(p2p, &chanspec);
2056 if_request.type = cpu_to_le16((u16)if_type);
2057 if_request.chspec = cpu_to_le16(chanspec);
2058 memcpy(if_request.addr, p2p->int_addr, sizeof(if_request.addr));
2060 brcmf_cfg80211_arm_vif_event(cfg, vif);
2061 err = brcmf_fil_iovar_data_set(vif->ifp, "p2p_ifupd", &if_request,
2062 sizeof(if_request));
2064 brcmf_err("p2p_ifupd FAILED, err=%d\n", err);
2065 brcmf_cfg80211_arm_vif_event(cfg, NULL);
2068 err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_CHANGE,
2069 msecs_to_jiffies(1500));
2070 brcmf_cfg80211_arm_vif_event(cfg, NULL);
2072 brcmf_err("No BRCMF_E_IF_CHANGE event received\n");
2076 err = brcmf_fil_cmd_int_set(vif->ifp, BRCMF_C_SET_SCB_TIMEOUT,
2077 BRCMF_SCB_TIMEOUT_VALUE);
2082 static int brcmf_p2p_request_p2p_if(struct brcmf_p2p_info *p2p,
2083 struct brcmf_if *ifp, u8 ea[ETH_ALEN],
2084 enum brcmf_fil_p2p_if_types iftype)
2086 struct brcmf_fil_p2p_if_le if_request;
2090 /* we need a default channel */
2091 brcmf_p2p_get_current_chanspec(p2p, &chanspec);
2093 /* fill the firmware request */
2094 memcpy(if_request.addr, ea, ETH_ALEN);
2095 if_request.type = cpu_to_le16((u16)iftype);
2096 if_request.chspec = cpu_to_le16(chanspec);
2098 err = brcmf_fil_iovar_data_set(ifp, "p2p_ifadd", &if_request,
2099 sizeof(if_request));
2106 static int brcmf_p2p_disable_p2p_if(struct brcmf_cfg80211_vif *vif)
2108 struct brcmf_cfg80211_info *cfg = wdev_to_cfg(&vif->wdev);
2109 struct net_device *pri_ndev = cfg_to_ndev(cfg);
2110 struct brcmf_if *ifp = netdev_priv(pri_ndev);
2111 u8 *addr = vif->wdev.netdev->dev_addr;
2113 return brcmf_fil_iovar_data_set(ifp, "p2p_ifdis", addr, ETH_ALEN);
2116 static int brcmf_p2p_release_p2p_if(struct brcmf_cfg80211_vif *vif)
2118 struct brcmf_cfg80211_info *cfg = wdev_to_cfg(&vif->wdev);
2119 struct net_device *pri_ndev = cfg_to_ndev(cfg);
2120 struct brcmf_if *ifp = netdev_priv(pri_ndev);
2121 u8 *addr = vif->wdev.netdev->dev_addr;
2123 return brcmf_fil_iovar_data_set(ifp, "p2p_ifdel", addr, ETH_ALEN);
2127 * brcmf_p2p_add_vif() - create a new P2P virtual interface.
2129 * @wiphy: wiphy device of new interface.
2130 * @name: name of the new interface.
2131 * @type: nl80211 interface type.
2135 struct wireless_dev *brcmf_p2p_add_vif(struct wiphy *wiphy, const char *name,
2136 enum nl80211_iftype type, u32 *flags,
2137 struct vif_params *params)
2139 struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
2140 struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
2141 struct brcmf_cfg80211_vif *vif;
2142 enum brcmf_fil_p2p_if_types iftype;
2146 if (brcmf_cfg80211_vif_event_armed(cfg))
2147 return ERR_PTR(-EBUSY);
2149 brcmf_dbg(INFO, "adding vif \"%s\" (type=%d)\n", name, type);
2152 case NL80211_IFTYPE_P2P_CLIENT:
2153 iftype = BRCMF_FIL_P2P_IF_CLIENT;
2156 case NL80211_IFTYPE_P2P_GO:
2157 iftype = BRCMF_FIL_P2P_IF_GO;
2161 return ERR_PTR(-EOPNOTSUPP);
2164 vif = brcmf_alloc_vif(cfg, type, false);
2166 return (struct wireless_dev *)vif;
2167 brcmf_cfg80211_arm_vif_event(cfg, vif);
2169 err = brcmf_p2p_request_p2p_if(&cfg->p2p, ifp, cfg->p2p.int_addr,
2172 brcmf_cfg80211_arm_vif_event(cfg, NULL);
2176 /* wait for firmware event */
2177 err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_ADD,
2178 msecs_to_jiffies(1500));
2179 brcmf_cfg80211_arm_vif_event(cfg, NULL);
2181 brcmf_err("timeout occurred\n");
2186 /* interface created in firmware */
2189 brcmf_err("no if pointer provided\n");
2194 strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1);
2195 err = brcmf_net_attach(ifp, true);
2197 brcmf_err("Registering netdevice failed\n");
2200 cfg->p2p.bss_idx[P2PAPI_BSSCFG_CONNECTION].vif = vif;
2201 /* Disable firmware roaming for P2P interface */
2202 brcmf_fil_iovar_int_set(ifp, "roam_off", 1);
2203 if (iftype == BRCMF_FIL_P2P_IF_GO) {
2204 /* set station timeout for p2p */
2205 brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCB_TIMEOUT,
2206 BRCMF_SCB_TIMEOUT_VALUE);
2208 return &ifp->vif->wdev;
2211 brcmf_free_vif(vif);
2212 return ERR_PTR(err);
2216 * brcmf_p2p_del_vif() - delete a P2P virtual interface.
2218 * @wiphy: wiphy device of interface.
2219 * @wdev: wireless device of interface.
2221 * TODO: not yet supported.
2223 int brcmf_p2p_del_vif(struct wiphy *wiphy, struct wireless_dev *wdev)
2225 struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
2226 struct brcmf_p2p_info *p2p = &cfg->p2p;
2227 struct brcmf_cfg80211_vif *vif;
2228 unsigned long jiffie_timeout = msecs_to_jiffies(1500);
2229 bool wait_for_disable = false;
2232 brcmf_dbg(TRACE, "delete P2P vif\n");
2233 vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
2235 switch (vif->wdev.iftype) {
2236 case NL80211_IFTYPE_P2P_CLIENT:
2237 if (test_bit(BRCMF_VIF_STATUS_DISCONNECTING, &vif->sme_state))
2238 wait_for_disable = true;
2241 case NL80211_IFTYPE_P2P_GO:
2242 if (!brcmf_p2p_disable_p2p_if(vif))
2243 wait_for_disable = true;
2246 case NL80211_IFTYPE_P2P_DEVICE:
2252 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status);
2253 brcmf_dbg(INFO, "P2P: GO_NEG_PHASE status cleared\n");
2255 if (wait_for_disable)
2256 wait_for_completion_timeout(&cfg->vif_disabled,
2257 msecs_to_jiffies(500));
2259 brcmf_vif_clear_mgmt_ies(vif);
2261 brcmf_cfg80211_arm_vif_event(cfg, vif);
2262 err = brcmf_p2p_release_p2p_if(vif);
2264 /* wait for firmware event */
2265 err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_DEL,
2272 brcmf_cfg80211_arm_vif_event(cfg, NULL);
2273 brcmf_free_vif(vif);
2274 p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif = NULL;