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 SOCIAL_CHAN_CNT 3
47 #define AF_PEER_SEARCH_CNT 2
49 #define BRCMF_SCB_TIMEOUT_VALUE 20
51 #define P2P_VER 9 /* P2P version: 9=WiFi P2P v1.0 */
52 #define P2P_PUB_AF_CATEGORY 0x04
53 #define P2P_PUB_AF_ACTION 0x09
54 #define P2P_AF_CATEGORY 0x7f
55 #define P2P_OUI "\x50\x6F\x9A" /* P2P OUI */
56 #define P2P_OUI_LEN 3 /* P2P OUI length */
58 /* Action Frame Constants */
59 #define DOT11_ACTION_HDR_LEN 2 /* action frame category + action */
60 #define DOT11_ACTION_CAT_OFF 0 /* category offset */
61 #define DOT11_ACTION_ACT_OFF 1 /* action offset */
63 #define P2P_AF_DWELL_TIME 200
64 #define P2P_AF_MIN_DWELL_TIME 100
65 #define P2P_AF_MED_DWELL_TIME 400
66 #define P2P_AF_LONG_DWELL_TIME 1000
67 #define P2P_AF_TX_MAX_RETRY 5
68 #define P2P_AF_MAX_WAIT_TIME 2000
69 #define P2P_INVALID_CHANNEL -1
70 #define P2P_CHANNEL_SYNC_RETRY 5
71 #define P2P_AF_FRM_SCAN_MAX_WAIT 1500
73 /* WiFi P2P Public Action Frame OUI Subtypes */
74 #define P2P_PAF_GON_REQ 0 /* Group Owner Negotiation Req */
75 #define P2P_PAF_GON_RSP 1 /* Group Owner Negotiation Rsp */
76 #define P2P_PAF_GON_CONF 2 /* Group Owner Negotiation Confirm */
77 #define P2P_PAF_INVITE_REQ 3 /* P2P Invitation Request */
78 #define P2P_PAF_INVITE_RSP 4 /* P2P Invitation Response */
79 #define P2P_PAF_DEVDIS_REQ 5 /* Device Discoverability Request */
80 #define P2P_PAF_DEVDIS_RSP 6 /* Device Discoverability Response */
81 #define P2P_PAF_PROVDIS_REQ 7 /* Provision Discovery Request */
82 #define P2P_PAF_PROVDIS_RSP 8 /* Provision Discovery Response */
83 #define P2P_PAF_SUBTYPE_INVALID 255 /* Invalid Subtype */
85 /* WiFi P2P Action Frame OUI Subtypes */
86 #define P2P_AF_NOTICE_OF_ABSENCE 0 /* Notice of Absence */
87 #define P2P_AF_PRESENCE_REQ 1 /* P2P Presence Request */
88 #define P2P_AF_PRESENCE_RSP 2 /* P2P Presence Response */
89 #define P2P_AF_GO_DISC_REQ 3 /* GO Discoverability Request */
91 /* P2P Service Discovery related */
92 #define P2PSD_ACTION_CATEGORY 0x04 /* Public action frame */
93 #define P2PSD_ACTION_ID_GAS_IREQ 0x0a /* GAS Initial Request AF */
94 #define P2PSD_ACTION_ID_GAS_IRESP 0x0b /* GAS Initial Response AF */
95 #define P2PSD_ACTION_ID_GAS_CREQ 0x0c /* GAS Comback Request AF */
96 #define P2PSD_ACTION_ID_GAS_CRESP 0x0d /* GAS Comback Response AF */
99 * struct brcmf_p2p_disc_st_le - set discovery state in firmware.
101 * @state: requested discovery state (see enum brcmf_p2p_disc_state).
102 * @chspec: channel parameter for %WL_P2P_DISC_ST_LISTEN state.
103 * @dwell: dwell time in ms for %WL_P2P_DISC_ST_LISTEN state.
105 struct brcmf_p2p_disc_st_le
{
112 * enum brcmf_p2p_disc_state - P2P discovery state values
114 * @WL_P2P_DISC_ST_SCAN: P2P discovery with wildcard SSID and P2P IE.
115 * @WL_P2P_DISC_ST_LISTEN: P2P discovery off-channel for specified time.
116 * @WL_P2P_DISC_ST_SEARCH: P2P discovery with P2P wildcard SSID and P2P IE.
118 enum brcmf_p2p_disc_state
{
120 WL_P2P_DISC_ST_LISTEN
,
121 WL_P2P_DISC_ST_SEARCH
125 * struct brcmf_p2p_scan_le - P2P specific scan request.
127 * @type: type of scan method requested (values: 'E' or 'S').
128 * @reserved: reserved (ignored).
129 * @eparams: parameters used for type 'E'.
130 * @sparams: parameters used for type 'S'.
132 struct brcmf_p2p_scan_le
{
136 struct brcmf_escan_params_le eparams
;
137 struct brcmf_scan_params_le sparams
;
142 * struct brcmf_p2p_pub_act_frame - WiFi P2P Public Action Frame
144 * @category: P2P_PUB_AF_CATEGORY
145 * @action: P2P_PUB_AF_ACTION
147 * @oui_type: OUI type - P2P_VER
148 * @subtype: OUI subtype - P2P_TYPE_*
149 * @dialog_token: nonzero, identifies req/rsp transaction
150 * @elts[1]: Variable length information elements.
152 struct brcmf_p2p_pub_act_frame
{
163 * struct brcmf_p2p_action_frame - WiFi P2P Action Frame
165 * @category: P2P_AF_CATEGORY
166 * @OUI[3]: OUI - P2P_OUI
167 * @type: OUI Type - P2P_VER
168 * @subtype: OUI Subtype - P2P_AF_*
169 * @dialog_token: nonzero, identifies req/resp tranaction
170 * @elts[1]: Variable length information elements.
172 struct brcmf_p2p_action_frame
{
182 * struct brcmf_p2psd_gas_pub_act_frame - Wi-Fi GAS Public Action Frame
184 * @category: 0x04 Public Action Frame
185 * @action: 0x6c Advertisement Protocol
186 * @dialog_token: nonzero, identifies req/rsp transaction
187 * @query_data[1]: Query Data. SD gas ireq SD gas iresp
189 struct brcmf_p2psd_gas_pub_act_frame
{
197 * struct brcmf_config_af_params - Action Frame Parameters for tx.
199 * @max_tx_retry: max tx retry count if tx no ack.
200 * @mpc_onoff: To make sure to send successfully action frame, we have to
201 * turn off mpc 0: off, 1: on, (-1): do nothing
203 struct brcmf_config_af_params
{
209 * brcmf_p2p_is_pub_action() - true if p2p public type frame.
211 * @frame: action frame data.
212 * @frame_len: length of action frame data.
214 * Determine if action frame is p2p public action type
216 static bool brcmf_p2p_is_pub_action(void *frame
, u32 frame_len
)
218 struct brcmf_p2p_pub_act_frame
*pact_frm
;
223 pact_frm
= (struct brcmf_p2p_pub_act_frame
*)frame
;
224 if (frame_len
< sizeof(struct brcmf_p2p_pub_act_frame
) - 1)
227 if (pact_frm
->category
== P2P_PUB_AF_CATEGORY
&&
228 pact_frm
->action
== P2P_PUB_AF_ACTION
&&
229 pact_frm
->oui_type
== P2P_VER
&&
230 memcmp(pact_frm
->oui
, P2P_OUI
, P2P_OUI_LEN
) == 0)
237 * brcmf_p2p_is_p2p_action() - true if p2p action type frame.
239 * @frame: action frame data.
240 * @frame_len: length of action frame data.
242 * Determine if action frame is p2p action type
244 static bool brcmf_p2p_is_p2p_action(void *frame
, u32 frame_len
)
246 struct brcmf_p2p_action_frame
*act_frm
;
251 act_frm
= (struct brcmf_p2p_action_frame
*)frame
;
252 if (frame_len
< sizeof(struct brcmf_p2p_action_frame
) - 1)
255 if (act_frm
->category
== P2P_AF_CATEGORY
&&
256 act_frm
->type
== P2P_VER
&&
257 memcmp(act_frm
->oui
, P2P_OUI
, P2P_OUI_LEN
) == 0)
264 * brcmf_p2p_is_gas_action() - true if p2p gas action type frame.
266 * @frame: action frame data.
267 * @frame_len: length of action frame data.
269 * Determine if action frame is p2p gas action type
271 static bool brcmf_p2p_is_gas_action(void *frame
, u32 frame_len
)
273 struct brcmf_p2psd_gas_pub_act_frame
*sd_act_frm
;
278 sd_act_frm
= (struct brcmf_p2psd_gas_pub_act_frame
*)frame
;
279 if (frame_len
< sizeof(struct brcmf_p2psd_gas_pub_act_frame
) - 1)
282 if (sd_act_frm
->category
!= P2PSD_ACTION_CATEGORY
)
285 if (sd_act_frm
->action
== P2PSD_ACTION_ID_GAS_IREQ
||
286 sd_act_frm
->action
== P2PSD_ACTION_ID_GAS_IRESP
||
287 sd_act_frm
->action
== P2PSD_ACTION_ID_GAS_CREQ
||
288 sd_act_frm
->action
== P2PSD_ACTION_ID_GAS_CRESP
)
295 * brcmf_p2p_print_actframe() - debug print routine.
297 * @tx: Received or to be transmitted
298 * @frame: action frame data.
299 * @frame_len: length of action frame data.
301 * Print information about the p2p action frame
303 static void brcmf_p2p_print_actframe(bool tx
, void *frame
, u32 frame_len
)
305 struct brcmf_p2p_pub_act_frame
*pact_frm
;
306 struct brcmf_p2p_action_frame
*act_frm
;
307 struct brcmf_p2psd_gas_pub_act_frame
*sd_act_frm
;
309 if (!frame
|| frame_len
<= 2)
312 if (brcmf_p2p_is_pub_action(frame
, frame_len
)) {
313 pact_frm
= (struct brcmf_p2p_pub_act_frame
*)frame
;
314 switch (pact_frm
->subtype
) {
315 case P2P_PAF_GON_REQ
:
316 brcmf_dbg(TRACE
, "%s P2P Group Owner Negotiation Req Frame\n",
319 case P2P_PAF_GON_RSP
:
320 brcmf_dbg(TRACE
, "%s P2P Group Owner Negotiation Rsp Frame\n",
323 case P2P_PAF_GON_CONF
:
324 brcmf_dbg(TRACE
, "%s P2P Group Owner Negotiation Confirm Frame\n",
327 case P2P_PAF_INVITE_REQ
:
328 brcmf_dbg(TRACE
, "%s P2P Invitation Request Frame\n",
331 case P2P_PAF_INVITE_RSP
:
332 brcmf_dbg(TRACE
, "%s P2P Invitation Response Frame\n",
335 case P2P_PAF_DEVDIS_REQ
:
336 brcmf_dbg(TRACE
, "%s P2P Device Discoverability Request Frame\n",
339 case P2P_PAF_DEVDIS_RSP
:
340 brcmf_dbg(TRACE
, "%s P2P Device Discoverability Response Frame\n",
343 case P2P_PAF_PROVDIS_REQ
:
344 brcmf_dbg(TRACE
, "%s P2P Provision Discovery Request Frame\n",
347 case P2P_PAF_PROVDIS_RSP
:
348 brcmf_dbg(TRACE
, "%s P2P Provision Discovery Response Frame\n",
352 brcmf_dbg(TRACE
, "%s Unknown P2P Public Action Frame\n",
356 } else if (brcmf_p2p_is_p2p_action(frame
, frame_len
)) {
357 act_frm
= (struct brcmf_p2p_action_frame
*)frame
;
358 switch (act_frm
->subtype
) {
359 case P2P_AF_NOTICE_OF_ABSENCE
:
360 brcmf_dbg(TRACE
, "%s P2P Notice of Absence Frame\n",
363 case P2P_AF_PRESENCE_REQ
:
364 brcmf_dbg(TRACE
, "%s P2P Presence Request Frame\n",
367 case P2P_AF_PRESENCE_RSP
:
368 brcmf_dbg(TRACE
, "%s P2P Presence Response Frame\n",
371 case P2P_AF_GO_DISC_REQ
:
372 brcmf_dbg(TRACE
, "%s P2P Discoverability Request Frame\n",
376 brcmf_dbg(TRACE
, "%s Unknown P2P Action Frame\n",
380 } else if (brcmf_p2p_is_gas_action(frame
, frame_len
)) {
381 sd_act_frm
= (struct brcmf_p2psd_gas_pub_act_frame
*)frame
;
382 switch (sd_act_frm
->action
) {
383 case P2PSD_ACTION_ID_GAS_IREQ
:
384 brcmf_dbg(TRACE
, "%s P2P GAS Initial Request\n",
387 case P2PSD_ACTION_ID_GAS_IRESP
:
388 brcmf_dbg(TRACE
, "%s P2P GAS Initial Response\n",
391 case P2PSD_ACTION_ID_GAS_CREQ
:
392 brcmf_dbg(TRACE
, "%s P2P GAS Comback Request\n",
395 case P2PSD_ACTION_ID_GAS_CRESP
:
396 brcmf_dbg(TRACE
, "%s P2P GAS Comback Response\n",
400 brcmf_dbg(TRACE
, "%s Unknown P2P GAS Frame\n",
408 * brcmf_p2p_set_firmware() - prepare firmware for peer-to-peer operation.
410 * @p2p: P2P specific data.
412 static int brcmf_p2p_set_firmware(struct brcmf_p2p_info
*p2p
)
414 struct net_device
*ndev
= cfg_to_ndev(p2p
->cfg
);
415 u8 null_eth_addr
[] = { 0, 0, 0, 0, 0, 0 };
418 brcmf_fil_iovar_int_set(netdev_priv(ndev
), "apsta", 1);
420 /* In case of COB type, firmware has default mac address
421 * After Initializing firmware, we have to set current mac address to
422 * firmware for P2P device address
424 ret
= brcmf_fil_iovar_data_set(netdev_priv(ndev
), "p2p_da_override",
425 null_eth_addr
, sizeof(null_eth_addr
));
427 brcmf_err("failed to update device address ret %d\n", ret
);
433 * brcmf_p2p_generate_bss_mac() - derive mac addresses for P2P.
435 * @p2p: P2P specific data.
437 * P2P needs mac addresses for P2P device and interface. These are
438 * derived from the primary net device, ie. the permanent ethernet
439 * address of the device.
441 static void brcmf_p2p_generate_bss_mac(struct brcmf_p2p_info
*p2p
)
443 /* Generate the P2P Device Address. This consists of the device's
444 * primary MAC address with the locally administered bit set.
446 memcpy(p2p
->dev_addr
, p2p
->cfg
->pub
->mac
, ETH_ALEN
);
447 p2p
->dev_addr
[0] |= 0x02;
449 /* Generate the P2P Interface Address. If the discovery and connection
450 * BSSCFGs need to simultaneously co-exist, then this address must be
451 * different from the P2P Device Address, but also locally administered.
453 memcpy(p2p
->int_addr
, p2p
->dev_addr
, ETH_ALEN
);
454 p2p
->int_addr
[4] ^= 0x80;
458 * brcmf_p2p_scan_is_p2p_request() - is cfg80211 scan request a P2P scan.
460 * @request: the scan request as received from cfg80211.
462 * returns true if one of the ssids in the request matches the
463 * P2P wildcard ssid; otherwise returns false.
465 static bool brcmf_p2p_scan_is_p2p_request(struct cfg80211_scan_request
*request
)
467 struct cfg80211_ssid
*ssids
= request
->ssids
;
470 for (i
= 0; i
< request
->n_ssids
; i
++) {
471 if (ssids
[i
].ssid_len
!= BRCMF_P2P_WILDCARD_SSID_LEN
)
474 brcmf_dbg(INFO
, "comparing ssid \"%s\"", ssids
[i
].ssid
);
475 if (!memcmp(BRCMF_P2P_WILDCARD_SSID
, ssids
[i
].ssid
,
476 BRCMF_P2P_WILDCARD_SSID_LEN
))
483 * brcmf_p2p_set_discover_state - set discover state in firmware.
485 * @ifp: low-level interface object.
486 * @state: discover state to set.
487 * @chanspec: channel parameters (for state @WL_P2P_DISC_ST_LISTEN only).
488 * @listen_ms: duration to listen (for state @WL_P2P_DISC_ST_LISTEN only).
490 static s32
brcmf_p2p_set_discover_state(struct brcmf_if
*ifp
, u8 state
,
491 u16 chanspec
, u16 listen_ms
)
493 struct brcmf_p2p_disc_st_le discover_state
;
495 brcmf_dbg(TRACE
, "enter\n");
497 discover_state
.state
= state
;
498 discover_state
.chspec
= cpu_to_le16(chanspec
);
499 discover_state
.dwell
= cpu_to_le16(listen_ms
);
500 ret
= brcmf_fil_bsscfg_data_set(ifp
, "p2p_state", &discover_state
,
501 sizeof(discover_state
));
506 * brcmf_p2p_init_discovery() - enable discovery in the firmware.
508 * @p2p: P2P specific data.
510 * Configures the firmware to allow P2P peer discovery. Creates the
511 * virtual interface and consequently the P2P device for it.
513 static s32
brcmf_p2p_init_discovery(struct brcmf_p2p_info
*p2p
)
515 struct net_device
*ndev
= cfg_to_ndev(p2p
->cfg
);
516 struct brcmf_cfg80211_vif
*vif
;
517 struct brcmf_if
*ifp
;
518 struct p2p_bss
*bss_dev
;
522 brcmf_dbg(TRACE
, "enter\n");
524 bss_dev
= &p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
];
525 if (bss_dev
->vif
!= NULL
) {
526 brcmf_dbg(INFO
, "do nothing, already initialized\n");
530 /* Enable P2P Discovery in the firmware */
531 ret
= brcmf_fil_iovar_int_set(netdev_priv(ndev
), "p2p_disc", 1);
533 brcmf_err("set discover error\n");
537 /* obtain bsscfg index for P2P discovery */
538 ret
= brcmf_fil_iovar_int_get(netdev_priv(ndev
), "p2p_dev", &index
);
540 brcmf_err("retrieving discover bsscfg index failed\n");
545 * need brcmf_if for setting the discovery state.
547 ifp
= kzalloc(sizeof(*vif
->ifp
), GFP_KERNEL
);
549 brcmf_err("could not create discovery if\n");
553 /* set required fields */
554 ifp
->drvr
= p2p
->cfg
->pub
;
558 /* Set the initial discovery state to SCAN */
559 ret
= brcmf_p2p_set_discover_state(ifp
, WL_P2P_DISC_ST_SCAN
, 0, 0);
562 brcmf_err("unable to set WL_P2P_DISC_ST_SCAN\n");
563 (void)brcmf_fil_iovar_int_set(netdev_priv(ndev
), "p2p_disc", 0);
568 /* create a vif for it */
569 vif
= brcmf_alloc_vif(p2p
->cfg
, NL80211_IFTYPE_P2P_DEVICE
, false);
571 brcmf_err("could not create discovery vif\n");
584 * brcmf_p2p_deinit_discovery() - disable P2P device discovery.
586 * @p2p: P2P specific data.
588 * Resets the discovery state and disables it in firmware. The virtual
589 * interface and P2P device are freed.
591 static s32
brcmf_p2p_deinit_discovery(struct brcmf_p2p_info
*p2p
)
593 struct net_device
*ndev
= cfg_to_ndev(p2p
->cfg
);
594 struct brcmf_if
*ifp
;
595 struct p2p_bss
*bss_dev
;
596 brcmf_dbg(TRACE
, "enter\n");
598 bss_dev
= &p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
];
599 ifp
= bss_dev
->vif
->ifp
;
601 /* Set the discovery state to SCAN */
602 (void)brcmf_p2p_set_discover_state(ifp
, WL_P2P_DISC_ST_SCAN
, 0, 0);
604 /* Disable P2P discovery in the firmware */
605 (void)brcmf_fil_iovar_int_set(netdev_priv(ndev
), "p2p_disc", 0);
607 /* remove discovery interface */
608 brcmf_free_vif(bss_dev
->vif
);
616 * brcmf_p2p_enable_discovery() - initialize and configure discovery.
618 * @p2p: P2P specific data.
620 * Initializes the discovery device and configure the virtual interface.
622 static int brcmf_p2p_enable_discovery(struct brcmf_p2p_info
*p2p
)
624 struct brcmf_cfg80211_vif
*vif
;
627 brcmf_dbg(TRACE
, "enter\n");
628 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
630 brcmf_dbg(INFO
, "DISCOVERY init already done\n");
634 ret
= brcmf_p2p_init_discovery(p2p
);
636 brcmf_err("init discovery error %d\n", ret
);
640 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
643 * Set wsec to any non-zero value in the discovery bsscfg
644 * to ensure our P2P probe responses have the privacy bit
645 * set in the 802.11 WPA IE. Some peer devices may not
646 * initiate WPS with us if this bit is not set.
648 ret
= brcmf_fil_bsscfg_int_set(vif
->ifp
, "wsec", AES_ENABLED
);
650 brcmf_err("wsec error %d\n", ret
);
657 * brcmf_p2p_escan() - initiate a P2P scan.
659 * @p2p: P2P specific data.
660 * @num_chans: number of channels to scan.
661 * @chanspecs: channel parameters for @num_chans channels.
662 * @search_state: P2P discover state to use.
663 * @action: scan action to pass to firmware.
664 * @bss_type: type of P2P bss.
666 static s32
brcmf_p2p_escan(struct brcmf_p2p_info
*p2p
, u32 num_chans
,
667 u16 chanspecs
[], s32 search_state
, u16 action
,
668 enum p2p_bss_type bss_type
)
671 s32 memsize
= offsetof(struct brcmf_p2p_scan_le
,
672 eparams
.params_le
.channel_list
);
677 struct brcmf_cfg80211_vif
*vif
;
678 struct brcmf_p2p_scan_le
*p2p_params
;
679 struct brcmf_scan_params_le
*sparams
;
680 struct brcmf_ssid ssid
;
682 memsize
+= num_chans
* sizeof(__le16
);
683 memblk
= kzalloc(memsize
, GFP_KERNEL
);
687 vif
= p2p
->bss_idx
[bss_type
].vif
;
689 brcmf_err("no vif for bss type %d\n", bss_type
);
694 switch (search_state
) {
695 case WL_P2P_DISC_ST_SEARCH
:
697 * If we in SEARCH STATE, we don't need to set SSID explictly
698 * because dongle use P2P WILDCARD internally by default
702 memset(ssid
.SSID
, 0, sizeof(ssid
.SSID
));
704 case WL_P2P_DISC_ST_SCAN
:
706 * wpa_supplicant has p2p_find command with type social or
707 * progressive. For progressive, we need to set the ssid to
708 * P2P WILDCARD because we just do broadcast scan unless
711 ssid
.SSID_len
= BRCMF_P2P_WILDCARD_SSID_LEN
;
712 memcpy(ssid
.SSID
, BRCMF_P2P_WILDCARD_SSID
, ssid
.SSID_len
);
715 brcmf_err(" invalid search state %d\n", search_state
);
720 brcmf_p2p_set_discover_state(vif
->ifp
, search_state
, 0, 0);
723 * set p2p scan parameters.
725 p2p_params
= (struct brcmf_p2p_scan_le
*)memblk
;
726 p2p_params
->type
= 'E';
728 /* determine the scan engine parameters */
729 sparams
= &p2p_params
->eparams
.params_le
;
730 sparams
->bss_type
= DOT11_BSSTYPE_ANY
;
731 if (p2p
->cfg
->active_scan
)
732 sparams
->scan_type
= 0;
734 sparams
->scan_type
= 1;
736 memset(&sparams
->bssid
, 0xFF, ETH_ALEN
);
738 memcpy(sparams
->ssid_le
.SSID
, ssid
.SSID
, ssid
.SSID_len
);
739 sparams
->ssid_le
.SSID_len
= cpu_to_le32(ssid
.SSID_len
);
740 sparams
->home_time
= cpu_to_le32(P2PAPI_SCAN_HOME_TIME_MS
);
743 * SOCIAL_CHAN_CNT + 1 takes care of the Progressive scan
744 * supported by the supplicant.
746 if (num_chans
== SOCIAL_CHAN_CNT
|| num_chans
== (SOCIAL_CHAN_CNT
+ 1))
747 active
= P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS
;
748 else if (num_chans
== AF_PEER_SEARCH_CNT
)
749 active
= P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS
;
750 else if (wl_get_vif_state_all(p2p
->cfg
, BRCMF_VIF_STATUS_CONNECTED
))
753 active
= P2PAPI_SCAN_DWELL_TIME_MS
;
755 /* Override scan params to find a peer for a connection */
756 if (num_chans
== 1) {
757 active
= WL_SCAN_CONNECT_DWELL_TIME_MS
;
758 /* WAR to sync with presence period of VSDB GO.
759 * send probe request more frequently
761 nprobes
= active
/ WL_SCAN_JOIN_PROBE_INTERVAL_MS
;
763 nprobes
= active
/ P2PAPI_SCAN_NPROBS_TIME_MS
;
769 brcmf_dbg(INFO
, "nprobes # %d, active_time %d\n", nprobes
, active
);
770 sparams
->active_time
= cpu_to_le32(active
);
771 sparams
->nprobes
= cpu_to_le32(nprobes
);
772 sparams
->passive_time
= cpu_to_le32(-1);
773 sparams
->channel_num
= cpu_to_le32(num_chans
&
774 BRCMF_SCAN_PARAMS_COUNT_MASK
);
775 for (i
= 0; i
< num_chans
; i
++)
776 sparams
->channel_list
[i
] = cpu_to_le16(chanspecs
[i
]);
778 /* set the escan specific parameters */
779 p2p_params
->eparams
.version
= cpu_to_le32(BRCMF_ESCAN_REQ_VERSION
);
780 p2p_params
->eparams
.action
= cpu_to_le16(action
);
781 p2p_params
->eparams
.sync_id
= cpu_to_le16(0x1234);
782 /* perform p2p scan on primary device */
783 ret
= brcmf_fil_bsscfg_data_set(vif
->ifp
, "p2p_scan", memblk
, memsize
);
785 set_bit(BRCMF_SCAN_STATUS_BUSY
, &p2p
->cfg
->scan_status
);
792 * brcmf_p2p_run_escan() - escan callback for peer-to-peer.
794 * @cfg: driver private data for cfg80211 interface.
795 * @ndev: net device for which scan is requested.
796 * @request: scan request from cfg80211.
797 * @action: scan action.
799 * Determines the P2P discovery state based to scan request parameters and
800 * validates the channels in the request.
802 static s32
brcmf_p2p_run_escan(struct brcmf_cfg80211_info
*cfg
,
803 struct net_device
*ndev
,
804 struct cfg80211_scan_request
*request
,
807 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
809 s32 search_state
= WL_P2P_DISC_ST_SCAN
;
810 struct brcmf_cfg80211_vif
*vif
;
811 struct net_device
*dev
= NULL
;
812 int i
, num_nodfs
= 0;
815 brcmf_dbg(TRACE
, "enter\n");
822 if (request
->n_channels
) {
823 chanspecs
= kcalloc(request
->n_channels
, sizeof(*chanspecs
),
829 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_CONNECTION
].vif
;
831 dev
= vif
->wdev
.netdev
;
832 if (request
->n_channels
== 3 &&
833 request
->channels
[0]->hw_value
== SOCIAL_CHAN_1
&&
834 request
->channels
[1]->hw_value
== SOCIAL_CHAN_2
&&
835 request
->channels
[2]->hw_value
== SOCIAL_CHAN_3
) {
836 /* SOCIAL CHANNELS 1, 6, 11 */
837 search_state
= WL_P2P_DISC_ST_SEARCH
;
838 brcmf_dbg(INFO
, "P2P SEARCH PHASE START\n");
839 } else if (dev
!= NULL
&& vif
->mode
== WL_MODE_AP
) {
840 /* If you are already a GO, then do SEARCH only */
841 brcmf_dbg(INFO
, "Already a GO. Do SEARCH Only\n");
842 search_state
= WL_P2P_DISC_ST_SEARCH
;
844 brcmf_dbg(INFO
, "P2P SCAN STATE START\n");
848 * no P2P scanning on passive or DFS channels.
850 for (i
= 0; i
< request
->n_channels
; i
++) {
851 struct ieee80211_channel
*chan
= request
->channels
[i
];
853 if (chan
->flags
& (IEEE80211_CHAN_RADAR
|
854 IEEE80211_CHAN_PASSIVE_SCAN
))
857 chanspecs
[i
] = channel_to_chanspec(chan
);
858 brcmf_dbg(INFO
, "%d: chan=%d, channel spec=%x\n",
859 num_nodfs
, chan
->hw_value
, chanspecs
[i
]);
862 err
= brcmf_p2p_escan(p2p
, num_nodfs
, chanspecs
, search_state
,
863 action
, P2PAPI_BSSCFG_DEVICE
);
867 brcmf_err("error (%d)\n", err
);
872 * brcmf_p2p_scan_prep() - prepare scan based on request.
874 * @wiphy: wiphy device.
875 * @request: scan request from cfg80211.
876 * @vif: vif on which scan request is to be executed.
878 * Prepare the scan appropriately for type of scan requested. Overrides the
879 * escan .run() callback for peer-to-peer scanning.
881 int brcmf_p2p_scan_prep(struct wiphy
*wiphy
,
882 struct cfg80211_scan_request
*request
,
883 struct brcmf_cfg80211_vif
*vif
)
885 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
886 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
889 if (brcmf_p2p_scan_is_p2p_request(request
)) {
890 /* find my listen channel */
891 err
= cfg80211_get_p2p_attr(request
->ie
, request
->ie_len
,
892 IEEE80211_P2P_ATTR_LISTEN_CHANNEL
,
893 &p2p
->listen_channel
, 1);
897 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE
, &p2p
->status
);
898 brcmf_dbg(INFO
, "P2P: GO_NEG_PHASE status cleared\n");
900 err
= brcmf_p2p_enable_discovery(p2p
);
904 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
906 /* override .run_escan() callback. */
907 cfg
->escan_info
.run
= brcmf_p2p_run_escan
;
909 err
= brcmf_vif_set_mgmt_ie(vif
, BRCMF_VNDR_IE_PRBREQ_FLAG
,
910 request
->ie
, request
->ie_len
);
916 * brcmf_p2p_remain_on_channel() - put device on channel and stay there.
918 * @wiphy: wiphy device.
919 * @channel: channel to stay on.
920 * @duration: time in ms to remain on channel.
923 int brcmf_p2p_remain_on_channel(struct wiphy
*wiphy
, struct wireless_dev
*wdev
,
924 struct ieee80211_channel
*channel
,
925 unsigned int duration
, u64
*cookie
)
927 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
928 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
929 struct brcmf_cfg80211_vif
*vif
;
933 brcmf_dbg(TRACE
, "Enter, channel: %d, duration ms (%d)\n",
934 ieee80211_frequency_to_channel(channel
->center_freq
),
938 err
= brcmf_p2p_enable_discovery(p2p
);
942 chanspec
= channel_to_chanspec(channel
);
943 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
944 err
= brcmf_p2p_set_discover_state(vif
->ifp
, WL_P2P_DISC_ST_LISTEN
,
945 chanspec
, (u16
)duration
);
949 memcpy(&p2p
->remain_on_channel
, channel
,
950 sizeof(p2p
->remain_on_channel
));
952 set_bit(BRCMF_P2P_STATUS_REMAIN_ON_CHANNEL
, &p2p
->status
);
955 cfg80211_ready_on_channel(wdev
, *cookie
, channel
, duration
, GFP_KERNEL
);
961 * brcmf_p2p_notify_listen_complete() - p2p listen has completed.
963 * @ifp: interfac control.
964 * @e: event message. Not used, to make it usable for fweh event dispatcher.
965 * @data: payload of message. Not used.
968 int brcmf_p2p_notify_listen_complete(struct brcmf_if
*ifp
,
969 const struct brcmf_event_msg
*e
,
972 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
973 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
975 brcmf_dbg(TRACE
, "Enter\n");
976 if (test_and_clear_bit(BRCMF_P2P_STATUS_REMAIN_ON_CHANNEL
,
978 cfg80211_remain_on_channel_expired(&ifp
->vif
->wdev
, 0,
979 &p2p
->remain_on_channel
,
986 * brcmf_p2p_cancel_remain_on_channel() - cancel p2p listen state.
988 * @ifp: interfac control.
991 void brcmf_p2p_cancel_remain_on_channel(struct brcmf_if
*ifp
)
995 brcmf_p2p_set_discover_state(ifp
, WL_P2P_DISC_ST_SCAN
, 0, 0);
996 brcmf_p2p_notify_listen_complete(ifp
, NULL
, NULL
);
1001 * brcmf_p2p_notify_action_frame_rx() - received action frame.
1003 * @ifp: interfac control.
1004 * @e: event message. Not used, to make it usable for fweh event dispatcher.
1005 * @data: payload of message, containing action frame data.
1008 int brcmf_p2p_notify_action_frame_rx(struct brcmf_if
*ifp
,
1009 const struct brcmf_event_msg
*e
,
1012 struct wireless_dev
*wdev
;
1013 u32 mgmt_frame_len
= e
->datalen
- sizeof(struct brcmf_rx_mgmt_data
);
1014 struct brcmf_rx_mgmt_data
*rxframe
= (struct brcmf_rx_mgmt_data
*)data
;
1015 u16 chanspec
= be16_to_cpu(rxframe
->chanspec
);
1016 struct ieee80211_mgmt
*mgmt_frame
;
1021 /* Check if wpa_supplicant has registered for this frame */
1022 brcmf_dbg(INFO
, "ifp->vif->mgmt_rx_reg %04x\n", ifp
->vif
->mgmt_rx_reg
);
1023 mgmt_type
= (IEEE80211_STYPE_ACTION
& IEEE80211_FCTL_STYPE
) >> 4;
1024 if ((ifp
->vif
->mgmt_rx_reg
& BIT(mgmt_type
)) == 0)
1027 brcmf_p2p_print_actframe(false, (u8
*)(rxframe
+ 1), mgmt_frame_len
);
1029 mgmt_frame
= kzalloc(offsetof(struct ieee80211_mgmt
, u
) +
1030 mgmt_frame_len
, GFP_KERNEL
);
1032 brcmf_err("No memory available for action frame\n");
1035 memcpy(mgmt_frame
->da
, ifp
->mac_addr
, ETH_ALEN
);
1036 err
= brcmf_fil_cmd_data_get(ifp
, BRCMF_C_GET_BSSID
, mgmt_frame
->bssid
,
1039 brcmf_err("BRCMF_C_GET_BSSID error %d\n", err
);
1040 memcpy(mgmt_frame
->sa
, e
->addr
, ETH_ALEN
);
1041 mgmt_frame
->frame_control
= cpu_to_le16(IEEE80211_STYPE_ACTION
);
1042 memcpy(&mgmt_frame
->u
, (u8
*)(rxframe
+ 1), mgmt_frame_len
);
1043 mgmt_frame_len
+= offsetof(struct ieee80211_mgmt
, u
);
1045 freq
= ieee80211_channel_to_frequency(CHSPEC_CHANNEL(chanspec
),
1046 CHSPEC_IS2G(chanspec
) ?
1047 IEEE80211_BAND_2GHZ
:
1048 IEEE80211_BAND_5GHZ
);
1049 wdev
= ifp
->ndev
->ieee80211_ptr
;
1050 cfg80211_rx_mgmt(wdev
, freq
, 0, (u8
*)mgmt_frame
, mgmt_frame_len
,
1059 * brcmf_p2p_notify_action_tx_complete() - transmit action frame complete
1061 * @ifp: interfac control.
1062 * @e: event message. Not used, to make it usable for fweh event dispatcher.
1066 int brcmf_p2p_notify_action_tx_complete(struct brcmf_if
*ifp
,
1067 const struct brcmf_event_msg
*e
,
1070 struct brcmf_cfg80211_info
*cfg
= ifp
->drvr
->config
;
1071 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1073 brcmf_dbg(INFO
, "Enter: status %d\n", e
->status
);
1075 if (e
->status
== BRCMF_E_STATUS_SUCCESS
)
1076 set_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED
, &p2p
->status
);
1078 set_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK
, &p2p
->status
);
1079 /* for now complete the receiver process here !! */
1080 complete(&p2p
->send_af_done
);
1087 * brcmf_p2p_tx_action_frame() - send action frame over fil.
1089 * @p2p: p2p info struct for vif.
1090 * @af_params: action frame data/info.
1092 * Send an action frame immediately without doing channel synchronization.
1094 * This function waits for a completion event before returning.
1095 * The WLC_E_ACTION_FRAME_COMPLETE event will be received when the action
1096 * frame is transmitted.
1098 static s32
brcmf_p2p_tx_action_frame(struct brcmf_p2p_info
*p2p
,
1099 struct brcmf_fil_af_params_le
*af_params
)
1101 struct brcmf_cfg80211_vif
*vif
;
1105 brcmf_dbg(TRACE
, "Enter\n");
1107 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED
, &p2p
->status
);
1108 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK
, &p2p
->status
);
1110 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
;
1111 err
= brcmf_fil_bsscfg_data_set(vif
->ifp
, "actframe", af_params
,
1112 sizeof(*af_params
));
1114 brcmf_err(" sending action frame has failed\n");
1118 timeout
= wait_for_completion_timeout(&p2p
->send_af_done
,
1119 msecs_to_jiffies(P2P_AF_MAX_WAIT_TIME
));
1121 if (test_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED
, &p2p
->status
)) {
1122 brcmf_dbg(TRACE
, "TX action frame operation is success\n");
1125 brcmf_dbg(TRACE
, "TX action frame operation has failed\n");
1127 /* clear status bit for action tx */
1128 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED
, &p2p
->status
);
1129 clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK
, &p2p
->status
);
1137 * brcmf_p2p_pub_af_tx() - public action frame tx routine.
1139 * @cfg: driver private data for cfg80211 interface.
1140 * @af_params: action frame data/info.
1141 * @config_af_params: configuration data for action frame.
1143 * routine which transmits ation frame public type.
1145 static s32
brcmf_p2p_pub_af_tx(struct brcmf_cfg80211_info
*cfg
,
1146 struct brcmf_fil_af_params_le
*af_params
,
1147 struct brcmf_config_af_params
*config_af_params
)
1149 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1150 struct brcmf_fil_action_frame_le
*action_frame
;
1151 struct brcmf_p2p_pub_act_frame
*act_frm
;
1154 action_frame
= &af_params
->action_frame
;
1155 act_frm
= (struct brcmf_p2p_pub_act_frame
*)(action_frame
->data
);
1157 switch (act_frm
->subtype
) {
1158 case P2P_PAF_GON_REQ
:
1159 brcmf_dbg(TRACE
, "P2P: GO_NEG_PHASE status set\n");
1160 set_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE
, &p2p
->status
);
1161 config_af_params
->mpc_onoff
= 0;
1162 p2p
->next_af_subtype
= act_frm
->subtype
+ 1;
1163 /* increase dwell time to wait for RESP frame */
1164 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MED_DWELL_TIME
);
1166 case P2P_PAF_GON_RSP
:
1167 p2p
->next_af_subtype
= act_frm
->subtype
+ 1;
1168 /* increase dwell time to wait for CONF frame */
1169 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MED_DWELL_TIME
);
1171 case P2P_PAF_GON_CONF
:
1172 /* If we reached till GO Neg confirmation reset the filter */
1173 brcmf_dbg(TRACE
, "P2P: GO_NEG_PHASE status cleared\n");
1174 clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE
, &p2p
->status
);
1175 /* turn on mpc again if go nego is done */
1176 config_af_params
->mpc_onoff
= 1;
1177 /* minimize dwell time */
1178 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MIN_DWELL_TIME
);
1180 case P2P_PAF_INVITE_REQ
:
1181 p2p
->next_af_subtype
= act_frm
->subtype
+ 1;
1182 /* increase dwell time */
1183 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MED_DWELL_TIME
);
1185 case P2P_PAF_INVITE_RSP
:
1186 /* minimize dwell time */
1187 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MIN_DWELL_TIME
);
1189 case P2P_PAF_DEVDIS_REQ
:
1190 p2p
->next_af_subtype
= act_frm
->subtype
+ 1;
1191 /* maximize dwell time to wait for RESP frame */
1192 af_params
->dwell_time
= cpu_to_le32(P2P_AF_LONG_DWELL_TIME
);
1194 case P2P_PAF_DEVDIS_RSP
:
1195 /* minimize dwell time */
1196 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MIN_DWELL_TIME
);
1198 case P2P_PAF_PROVDIS_REQ
:
1199 config_af_params
->mpc_onoff
= 0;
1200 p2p
->next_af_subtype
= act_frm
->subtype
+ 1;
1201 /* increase dwell time to wait for RESP frame */
1202 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MED_DWELL_TIME
);
1204 case P2P_PAF_PROVDIS_RSP
:
1205 /* wpa_supplicant send go nego req right after prov disc */
1206 p2p
->next_af_subtype
= P2P_PAF_GON_REQ
;
1207 /* increase dwell time to MED level */
1208 af_params
->dwell_time
= cpu_to_le32(P2P_AF_MED_DWELL_TIME
);
1211 brcmf_err("Unknown p2p pub act frame subtype: %d\n",
1219 * brcmf_p2p_send_action_frame() - send action frame .
1221 * @cfg: driver private data for cfg80211 interface.
1222 * @ndev: net device to transmit on.
1223 * @af_params: configuration data for action frame.
1225 bool brcmf_p2p_send_action_frame(struct brcmf_cfg80211_info
*cfg
,
1226 struct net_device
*ndev
,
1227 struct brcmf_fil_af_params_le
*af_params
)
1229 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1230 struct brcmf_fil_action_frame_le
*action_frame
;
1231 struct brcmf_config_af_params config_af_params
;
1232 u16 action_frame_len
;
1238 action_frame
= &af_params
->action_frame
;
1239 action_frame_len
= le16_to_cpu(action_frame
->len
);
1241 brcmf_p2p_print_actframe(true, action_frame
->data
, action_frame_len
);
1243 /* Add the default dwell time. Dwell time to stay off-channel */
1244 /* to wait for a response action frame after transmitting an */
1245 /* GO Negotiation action frame */
1246 af_params
->dwell_time
= cpu_to_le32(P2P_AF_DWELL_TIME
);
1248 category
= action_frame
->data
[DOT11_ACTION_CAT_OFF
];
1249 action
= action_frame
->data
[DOT11_ACTION_ACT_OFF
];
1251 /* initialize variables */
1252 p2p
->next_af_subtype
= P2P_PAF_SUBTYPE_INVALID
;
1254 /* config parameters */
1255 config_af_params
.max_tx_retry
= P2P_AF_TX_MAX_RETRY
;
1256 config_af_params
.mpc_onoff
= -1;
1258 if (brcmf_p2p_is_pub_action(action_frame
->data
, action_frame_len
)) {
1259 /* p2p public action frame process */
1260 if (brcmf_p2p_pub_af_tx(cfg
, af_params
, &config_af_params
)) {
1261 /* Just send unknown subtype frame with */
1262 /* default parameters. */
1263 brcmf_err("P2P Public action frame, unknown subtype.\n");
1265 } else if (brcmf_p2p_is_gas_action(action_frame
->data
,
1266 action_frame_len
)) {
1267 /* service discovery process */
1268 if (action
== P2PSD_ACTION_ID_GAS_IREQ
||
1269 action
== P2PSD_ACTION_ID_GAS_CREQ
) {
1270 /* save next af suptype to cancel */
1271 /* remaining dwell time */
1272 p2p
->next_af_subtype
= action
+ 1;
1274 af_params
->dwell_time
=
1275 cpu_to_le32(P2P_AF_MED_DWELL_TIME
);
1276 } else if (action
== P2PSD_ACTION_ID_GAS_IRESP
||
1277 action
== P2PSD_ACTION_ID_GAS_CRESP
) {
1278 /* configure service discovery response frame */
1279 af_params
->dwell_time
=
1280 cpu_to_le32(P2P_AF_MIN_DWELL_TIME
);
1282 brcmf_err("Unknown action type: %d\n", action
);
1285 } else if (brcmf_p2p_is_p2p_action(action_frame
->data
,
1286 action_frame_len
)) {
1287 /* do not configure anything. it will be */
1288 /* sent with a default configuration */
1290 brcmf_err("Unknown Frame: category 0x%x, action 0x%x\n",
1295 /* if scan is ongoing, abort current scan. */
1296 if (test_bit(BRCMF_SCAN_STATUS_BUSY
, &cfg
->scan_status
))
1297 brcmf_abort_scanning(cfg
);
1299 /* To make sure to send successfully action frame, turn off mpc */
1300 if (config_af_params
.mpc_onoff
== 0)
1301 brcmf_set_mpc(ndev
, 0);
1303 /* if failed, retry it. tx_retry_max value is configure by .... */
1305 while ((ack
== false) && (tx_retry
< config_af_params
.max_tx_retry
)) {
1306 ack
= !brcmf_p2p_tx_action_frame(p2p
, af_params
);
1310 brcmf_err("Failed to send Action Frame(retry %d)\n", tx_retry
);
1313 /* if all done, turn mpc on again */
1314 if (config_af_params
.mpc_onoff
== 1)
1315 brcmf_set_mpc(ndev
, 1);
1322 * brcmf_p2p_attach() - attach for P2P.
1324 * @cfg: driver private data for cfg80211 interface.
1326 void brcmf_p2p_attach(struct brcmf_cfg80211_info
*cfg
,
1327 struct brcmf_cfg80211_vif
*vif
)
1329 struct brcmf_p2p_info
*p2p
;
1334 p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
= vif
;
1335 brcmf_p2p_generate_bss_mac(p2p
);
1336 brcmf_p2p_set_firmware(p2p
);
1337 init_completion(&p2p
->send_af_done
);
1341 * brcmf_p2p_detach() - detach P2P.
1343 * @p2p: P2P specific data.
1345 void brcmf_p2p_detach(struct brcmf_p2p_info
*p2p
)
1347 if (p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
!= NULL
) {
1348 brcmf_p2p_cancel_remain_on_channel(
1349 p2p
->bss_idx
[P2PAPI_BSSCFG_DEVICE
].vif
->ifp
);
1350 brcmf_p2p_deinit_discovery(p2p
);
1352 /* just set it all to zero */
1353 memset(p2p
, 0, sizeof(*p2p
));
1357 * brcmf_p2p_get_current_chanspec() - Get current operation channel.
1359 * @p2p: P2P specific data.
1360 * @chanspec: chanspec to be returned.
1362 static void brcmf_p2p_get_current_chanspec(struct brcmf_p2p_info
*p2p
,
1365 struct brcmf_if
*ifp
;
1366 struct brcmf_fil_chan_info_le ci
;
1369 ifp
= p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
->ifp
;
1371 *chanspec
= 11 & WL_CHANSPEC_CHAN_MASK
;
1373 err
= brcmf_fil_cmd_data_get(ifp
, BRCMF_C_GET_CHANNEL
, &ci
, sizeof(ci
));
1375 *chanspec
= le32_to_cpu(ci
.hw_channel
) & WL_CHANSPEC_CHAN_MASK
;
1376 if (*chanspec
< CH_MAX_2G_CHANNEL
)
1377 *chanspec
|= WL_CHANSPEC_BAND_2G
;
1379 *chanspec
|= WL_CHANSPEC_BAND_5G
;
1381 *chanspec
|= WL_CHANSPEC_BW_20
| WL_CHANSPEC_CTL_SB_NONE
;
1385 * Change a P2P Role.
1387 * @mac: MAC address of the BSS to change a role
1388 * Returns 0 if success.
1390 int brcmf_p2p_ifchange(struct brcmf_cfg80211_info
*cfg
,
1391 enum brcmf_fil_p2p_if_types if_type
)
1393 struct brcmf_p2p_info
*p2p
= &cfg
->p2p
;
1394 struct brcmf_cfg80211_vif
*vif
;
1395 struct brcmf_fil_p2p_if_le if_request
;
1399 brcmf_dbg(TRACE
, "Enter\n");
1401 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_PRIMARY
].vif
;
1403 brcmf_err("vif for P2PAPI_BSSCFG_PRIMARY does not exist\n");
1406 brcmf_notify_escan_complete(cfg
, vif
->ifp
->ndev
, true, true);
1407 vif
= p2p
->bss_idx
[P2PAPI_BSSCFG_CONNECTION
].vif
;
1409 brcmf_err("vif for P2PAPI_BSSCFG_CONNECTION does not exist\n");
1412 brcmf_set_mpc(vif
->ifp
->ndev
, 0);
1414 /* In concurrency case, STA may be already associated in a particular */
1415 /* channel. so retrieve the current channel of primary interface and */
1416 /* then start the virtual interface on that. */
1417 brcmf_p2p_get_current_chanspec(p2p
, &chanspec
);
1419 if_request
.type
= cpu_to_le16((u16
)if_type
);
1420 if_request
.chspec
= cpu_to_le16(chanspec
);
1421 memcpy(if_request
.addr
, p2p
->int_addr
, sizeof(if_request
.addr
));
1423 brcmf_cfg80211_arm_vif_event(cfg
, vif
);
1424 err
= brcmf_fil_iovar_data_set(vif
->ifp
, "p2p_ifupd", &if_request
,
1425 sizeof(if_request
));
1427 brcmf_err("p2p_ifupd FAILED, err=%d\n", err
);
1428 brcmf_cfg80211_arm_vif_event(cfg
, NULL
);
1431 err
= brcmf_cfg80211_wait_vif_event_timeout(cfg
, BRCMF_E_IF_CHANGE
,
1432 msecs_to_jiffies(1500));
1433 brcmf_cfg80211_arm_vif_event(cfg
, NULL
);
1435 brcmf_err("No BRCMF_E_IF_CHANGE event received\n");
1439 err
= brcmf_fil_cmd_int_set(vif
->ifp
, BRCMF_C_SET_SCB_TIMEOUT
,
1440 BRCMF_SCB_TIMEOUT_VALUE
);
1445 static int brcmf_p2p_request_p2p_if(struct brcmf_p2p_info
*p2p
,
1446 struct brcmf_if
*ifp
, u8 ea
[ETH_ALEN
],
1447 enum brcmf_fil_p2p_if_types iftype
)
1449 struct brcmf_fil_p2p_if_le if_request
;
1453 /* we need a default channel */
1454 brcmf_p2p_get_current_chanspec(p2p
, &chanspec
);
1456 /* fill the firmware request */
1457 memcpy(if_request
.addr
, ea
, ETH_ALEN
);
1458 if_request
.type
= cpu_to_le16((u16
)iftype
);
1459 if_request
.chspec
= cpu_to_le16(chanspec
);
1461 err
= brcmf_fil_iovar_data_set(ifp
, "p2p_ifadd", &if_request
,
1462 sizeof(if_request
));
1469 static int brcmf_p2p_disable_p2p_if(struct brcmf_cfg80211_vif
*vif
)
1471 struct brcmf_cfg80211_info
*cfg
= wdev_to_cfg(&vif
->wdev
);
1472 struct net_device
*pri_ndev
= cfg_to_ndev(cfg
);
1473 struct brcmf_if
*ifp
= netdev_priv(pri_ndev
);
1474 u8
*addr
= vif
->wdev
.netdev
->dev_addr
;
1476 return brcmf_fil_iovar_data_set(ifp
, "p2p_ifdis", addr
, ETH_ALEN
);
1479 static int brcmf_p2p_release_p2p_if(struct brcmf_cfg80211_vif
*vif
)
1481 struct brcmf_cfg80211_info
*cfg
= wdev_to_cfg(&vif
->wdev
);
1482 struct net_device
*pri_ndev
= cfg_to_ndev(cfg
);
1483 struct brcmf_if
*ifp
= netdev_priv(pri_ndev
);
1484 u8
*addr
= vif
->wdev
.netdev
->dev_addr
;
1486 return brcmf_fil_iovar_data_set(ifp
, "p2p_ifdel", addr
, ETH_ALEN
);
1490 * brcmf_p2p_add_vif() - create a new P2P virtual interface.
1492 * @wiphy: wiphy device of new interface.
1493 * @name: name of the new interface.
1494 * @type: nl80211 interface type.
1498 struct wireless_dev
*brcmf_p2p_add_vif(struct wiphy
*wiphy
, const char *name
,
1499 enum nl80211_iftype type
, u32
*flags
,
1500 struct vif_params
*params
)
1502 struct brcmf_cfg80211_info
*cfg
= wiphy_to_cfg(wiphy
);
1503 struct brcmf_if
*ifp
= netdev_priv(cfg_to_ndev(cfg
));
1504 struct brcmf_cfg80211_vif
*vif
;
1505 enum brcmf_fil_p2p_if_types iftype
;
1509 if (brcmf_cfg80211_vif_event_armed(cfg
))
1510 return ERR_PTR(-EBUSY
);
1512 brcmf_dbg(INFO
, "adding vif \"%s\" (type=%d)\n", name
, type
);
1515 case NL80211_IFTYPE_P2P_CLIENT
:
1516 iftype
= BRCMF_FIL_P2P_IF_CLIENT
;
1519 case NL80211_IFTYPE_P2P_GO
:
1520 iftype
= BRCMF_FIL_P2P_IF_GO
;
1524 return ERR_PTR(-EOPNOTSUPP
);
1527 vif
= brcmf_alloc_vif(cfg
, type
, false);
1529 return (struct wireless_dev
*)vif
;
1530 brcmf_cfg80211_arm_vif_event(cfg
, vif
);
1532 err
= brcmf_p2p_request_p2p_if(&cfg
->p2p
, ifp
, cfg
->p2p
.int_addr
,
1535 brcmf_cfg80211_arm_vif_event(cfg
, NULL
);
1539 /* wait for firmware event */
1540 err
= brcmf_cfg80211_wait_vif_event_timeout(cfg
, BRCMF_E_IF_ADD
,
1541 msecs_to_jiffies(1500));
1542 brcmf_cfg80211_arm_vif_event(cfg
, NULL
);
1544 brcmf_err("timeout occurred\n");
1549 /* interface created in firmware */
1552 brcmf_err("no if pointer provided\n");
1557 strncpy(ifp
->ndev
->name
, name
, sizeof(ifp
->ndev
->name
) - 1);
1558 brcmf_cfg80211_vif_complete(cfg
);
1559 cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_CONNECTION
].vif
= vif
;
1560 /* Disable firmware roaming for P2P interface */
1561 brcmf_fil_iovar_int_set(ifp
, "roam_off", 1);
1562 if (iftype
== BRCMF_FIL_P2P_IF_GO
) {
1563 /* set station timeout for p2p */
1564 brcmf_fil_cmd_int_set(ifp
, BRCMF_C_SET_SCB_TIMEOUT
,
1565 BRCMF_SCB_TIMEOUT_VALUE
);
1567 return &ifp
->vif
->wdev
;
1570 brcmf_free_vif(vif
);
1571 return ERR_PTR(err
);
1575 * brcmf_p2p_del_vif() - delete a P2P virtual interface.
1577 * @wiphy: wiphy device of interface.
1578 * @wdev: wireless device of interface.
1580 * TODO: not yet supported.
1582 int brcmf_p2p_del_vif(struct wiphy
*wiphy
, struct wireless_dev
*wdev
)
1584 struct brcmf_cfg80211_info
*cfg
= wiphy_priv(wiphy
);
1585 struct brcmf_cfg80211_vif
*vif
;
1586 unsigned long jiffie_timeout
= msecs_to_jiffies(1500);
1587 bool wait_for_disable
= false;
1590 brcmf_dbg(TRACE
, "delete P2P vif\n");
1591 vif
= container_of(wdev
, struct brcmf_cfg80211_vif
, wdev
);
1593 switch (vif
->wdev
.iftype
) {
1594 case NL80211_IFTYPE_P2P_CLIENT
:
1595 if (test_bit(BRCMF_VIF_STATUS_DISCONNECTING
, &vif
->sme_state
))
1596 wait_for_disable
= true;
1599 case NL80211_IFTYPE_P2P_GO
:
1600 if (!brcmf_p2p_disable_p2p_if(vif
))
1601 wait_for_disable
= true;
1604 case NL80211_IFTYPE_P2P_DEVICE
:
1610 if (wait_for_disable
)
1611 wait_for_completion_timeout(&cfg
->vif_disabled
,
1612 msecs_to_jiffies(500));
1614 brcmf_vif_clear_mgmt_ies(vif
);
1616 brcmf_cfg80211_arm_vif_event(cfg
, vif
);
1617 err
= brcmf_p2p_release_p2p_if(vif
);
1619 /* wait for firmware event */
1620 err
= brcmf_cfg80211_wait_vif_event_timeout(cfg
, BRCMF_E_IF_DEL
,
1627 brcmf_cfg80211_arm_vif_event(cfg
, NULL
);
1628 brcmf_free_vif(vif
);
1629 cfg
->p2p
.bss_idx
[P2PAPI_BSSCFG_CONNECTION
].vif
= NULL
;