Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 Broadcom Corporation |
| 3 | * |
| 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. |
| 7 | * |
| 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. |
| 15 | */ |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/netdevice.h> |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 18 | #include <linux/etherdevice.h> |
Arend van Spriel | f7a4087 | 2015-06-11 00:12:23 +0200 | [diff] [blame] | 19 | #include <linux/rtnetlink.h> |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 20 | #include <net/cfg80211.h> |
| 21 | |
| 22 | #include <brcmu_wifi.h> |
| 23 | #include <brcmu_utils.h> |
| 24 | #include <defs.h> |
Hante Meuleman | 122d3d0 | 2014-10-28 14:56:18 +0100 | [diff] [blame] | 25 | #include "core.h" |
Hante Meuleman | a8e8ed3 | 2014-10-28 14:56:13 +0100 | [diff] [blame] | 26 | #include "debug.h" |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 27 | #include "fwil.h" |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 28 | #include "fwil_types.h" |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 29 | #include "p2p.h" |
Hante Meuleman | bfe8197 | 2014-10-28 14:56:16 +0100 | [diff] [blame] | 30 | #include "cfg80211.h" |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 31 | |
| 32 | /* parameters used for p2p escan */ |
| 33 | #define P2PAPI_SCAN_NPROBES 1 |
| 34 | #define P2PAPI_SCAN_DWELL_TIME_MS 80 |
| 35 | #define P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS 40 |
| 36 | #define P2PAPI_SCAN_HOME_TIME_MS 60 |
| 37 | #define P2PAPI_SCAN_NPROBS_TIME_MS 30 |
| 38 | #define P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS 100 |
| 39 | #define WL_SCAN_CONNECT_DWELL_TIME_MS 200 |
| 40 | #define WL_SCAN_JOIN_PROBE_INTERVAL_MS 20 |
| 41 | |
| 42 | #define BRCMF_P2P_WILDCARD_SSID "DIRECT-" |
| 43 | #define BRCMF_P2P_WILDCARD_SSID_LEN (sizeof(BRCMF_P2P_WILDCARD_SSID) - 1) |
| 44 | |
| 45 | #define SOCIAL_CHAN_1 1 |
| 46 | #define SOCIAL_CHAN_2 6 |
| 47 | #define SOCIAL_CHAN_3 11 |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 48 | #define IS_P2P_SOCIAL_CHANNEL(channel) ((channel == SOCIAL_CHAN_1) || \ |
| 49 | (channel == SOCIAL_CHAN_2) || \ |
| 50 | (channel == SOCIAL_CHAN_3)) |
Hante Meuleman | 15a953d | 2013-05-27 21:09:54 +0200 | [diff] [blame] | 51 | #define BRCMF_P2P_TEMP_CHAN SOCIAL_CHAN_3 |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 52 | #define SOCIAL_CHAN_CNT 3 |
| 53 | #define AF_PEER_SEARCH_CNT 2 |
| 54 | |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 55 | #define BRCMF_SCB_TIMEOUT_VALUE 20 |
| 56 | |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 57 | #define P2P_VER 9 /* P2P version: 9=WiFi P2P v1.0 */ |
| 58 | #define P2P_PUB_AF_CATEGORY 0x04 |
| 59 | #define P2P_PUB_AF_ACTION 0x09 |
| 60 | #define P2P_AF_CATEGORY 0x7f |
| 61 | #define P2P_OUI "\x50\x6F\x9A" /* P2P OUI */ |
| 62 | #define P2P_OUI_LEN 3 /* P2P OUI length */ |
| 63 | |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 64 | /* Action Frame Constants */ |
| 65 | #define DOT11_ACTION_HDR_LEN 2 /* action frame category + action */ |
| 66 | #define DOT11_ACTION_CAT_OFF 0 /* category offset */ |
| 67 | #define DOT11_ACTION_ACT_OFF 1 /* action offset */ |
| 68 | |
| 69 | #define P2P_AF_DWELL_TIME 200 |
| 70 | #define P2P_AF_MIN_DWELL_TIME 100 |
| 71 | #define P2P_AF_MED_DWELL_TIME 400 |
| 72 | #define P2P_AF_LONG_DWELL_TIME 1000 |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 73 | #define P2P_AF_TX_MAX_RETRY 1 |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 74 | #define P2P_AF_MAX_WAIT_TIME 2000 |
| 75 | #define P2P_INVALID_CHANNEL -1 |
| 76 | #define P2P_CHANNEL_SYNC_RETRY 5 |
| 77 | #define P2P_AF_FRM_SCAN_MAX_WAIT 1500 |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 78 | #define P2P_DEFAULT_SLEEP_TIME_VSDB 200 |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 79 | |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 80 | /* WiFi P2P Public Action Frame OUI Subtypes */ |
| 81 | #define P2P_PAF_GON_REQ 0 /* Group Owner Negotiation Req */ |
| 82 | #define P2P_PAF_GON_RSP 1 /* Group Owner Negotiation Rsp */ |
| 83 | #define P2P_PAF_GON_CONF 2 /* Group Owner Negotiation Confirm */ |
| 84 | #define P2P_PAF_INVITE_REQ 3 /* P2P Invitation Request */ |
| 85 | #define P2P_PAF_INVITE_RSP 4 /* P2P Invitation Response */ |
| 86 | #define P2P_PAF_DEVDIS_REQ 5 /* Device Discoverability Request */ |
| 87 | #define P2P_PAF_DEVDIS_RSP 6 /* Device Discoverability Response */ |
| 88 | #define P2P_PAF_PROVDIS_REQ 7 /* Provision Discovery Request */ |
| 89 | #define P2P_PAF_PROVDIS_RSP 8 /* Provision Discovery Response */ |
| 90 | #define P2P_PAF_SUBTYPE_INVALID 255 /* Invalid Subtype */ |
| 91 | |
| 92 | /* WiFi P2P Action Frame OUI Subtypes */ |
| 93 | #define P2P_AF_NOTICE_OF_ABSENCE 0 /* Notice of Absence */ |
| 94 | #define P2P_AF_PRESENCE_REQ 1 /* P2P Presence Request */ |
| 95 | #define P2P_AF_PRESENCE_RSP 2 /* P2P Presence Response */ |
| 96 | #define P2P_AF_GO_DISC_REQ 3 /* GO Discoverability Request */ |
| 97 | |
| 98 | /* P2P Service Discovery related */ |
| 99 | #define P2PSD_ACTION_CATEGORY 0x04 /* Public action frame */ |
| 100 | #define P2PSD_ACTION_ID_GAS_IREQ 0x0a /* GAS Initial Request AF */ |
| 101 | #define P2PSD_ACTION_ID_GAS_IRESP 0x0b /* GAS Initial Response AF */ |
| 102 | #define P2PSD_ACTION_ID_GAS_CREQ 0x0c /* GAS Comback Request AF */ |
| 103 | #define P2PSD_ACTION_ID_GAS_CRESP 0x0d /* GAS Comback Response AF */ |
| 104 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 105 | /** |
| 106 | * struct brcmf_p2p_disc_st_le - set discovery state in firmware. |
| 107 | * |
| 108 | * @state: requested discovery state (see enum brcmf_p2p_disc_state). |
| 109 | * @chspec: channel parameter for %WL_P2P_DISC_ST_LISTEN state. |
| 110 | * @dwell: dwell time in ms for %WL_P2P_DISC_ST_LISTEN state. |
| 111 | */ |
| 112 | struct brcmf_p2p_disc_st_le { |
| 113 | u8 state; |
| 114 | __le16 chspec; |
| 115 | __le16 dwell; |
| 116 | }; |
| 117 | |
| 118 | /** |
| 119 | * enum brcmf_p2p_disc_state - P2P discovery state values |
| 120 | * |
| 121 | * @WL_P2P_DISC_ST_SCAN: P2P discovery with wildcard SSID and P2P IE. |
| 122 | * @WL_P2P_DISC_ST_LISTEN: P2P discovery off-channel for specified time. |
| 123 | * @WL_P2P_DISC_ST_SEARCH: P2P discovery with P2P wildcard SSID and P2P IE. |
| 124 | */ |
| 125 | enum brcmf_p2p_disc_state { |
| 126 | WL_P2P_DISC_ST_SCAN, |
| 127 | WL_P2P_DISC_ST_LISTEN, |
| 128 | WL_P2P_DISC_ST_SEARCH |
| 129 | }; |
| 130 | |
| 131 | /** |
| 132 | * struct brcmf_p2p_scan_le - P2P specific scan request. |
| 133 | * |
| 134 | * @type: type of scan method requested (values: 'E' or 'S'). |
| 135 | * @reserved: reserved (ignored). |
| 136 | * @eparams: parameters used for type 'E'. |
| 137 | * @sparams: parameters used for type 'S'. |
| 138 | */ |
| 139 | struct brcmf_p2p_scan_le { |
| 140 | u8 type; |
| 141 | u8 reserved[3]; |
| 142 | union { |
| 143 | struct brcmf_escan_params_le eparams; |
| 144 | struct brcmf_scan_params_le sparams; |
| 145 | }; |
| 146 | }; |
| 147 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 148 | /** |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 149 | * struct brcmf_p2p_pub_act_frame - WiFi P2P Public Action Frame |
| 150 | * |
| 151 | * @category: P2P_PUB_AF_CATEGORY |
| 152 | * @action: P2P_PUB_AF_ACTION |
| 153 | * @oui[3]: P2P_OUI |
| 154 | * @oui_type: OUI type - P2P_VER |
| 155 | * @subtype: OUI subtype - P2P_TYPE_* |
| 156 | * @dialog_token: nonzero, identifies req/rsp transaction |
| 157 | * @elts[1]: Variable length information elements. |
| 158 | */ |
| 159 | struct brcmf_p2p_pub_act_frame { |
| 160 | u8 category; |
| 161 | u8 action; |
| 162 | u8 oui[3]; |
| 163 | u8 oui_type; |
| 164 | u8 subtype; |
| 165 | u8 dialog_token; |
| 166 | u8 elts[1]; |
| 167 | }; |
| 168 | |
| 169 | /** |
| 170 | * struct brcmf_p2p_action_frame - WiFi P2P Action Frame |
| 171 | * |
| 172 | * @category: P2P_AF_CATEGORY |
| 173 | * @OUI[3]: OUI - P2P_OUI |
| 174 | * @type: OUI Type - P2P_VER |
| 175 | * @subtype: OUI Subtype - P2P_AF_* |
| 176 | * @dialog_token: nonzero, identifies req/resp tranaction |
| 177 | * @elts[1]: Variable length information elements. |
| 178 | */ |
| 179 | struct brcmf_p2p_action_frame { |
| 180 | u8 category; |
| 181 | u8 oui[3]; |
| 182 | u8 type; |
| 183 | u8 subtype; |
| 184 | u8 dialog_token; |
| 185 | u8 elts[1]; |
| 186 | }; |
| 187 | |
| 188 | /** |
| 189 | * struct brcmf_p2psd_gas_pub_act_frame - Wi-Fi GAS Public Action Frame |
| 190 | * |
| 191 | * @category: 0x04 Public Action Frame |
| 192 | * @action: 0x6c Advertisement Protocol |
| 193 | * @dialog_token: nonzero, identifies req/rsp transaction |
| 194 | * @query_data[1]: Query Data. SD gas ireq SD gas iresp |
| 195 | */ |
| 196 | struct brcmf_p2psd_gas_pub_act_frame { |
| 197 | u8 category; |
| 198 | u8 action; |
| 199 | u8 dialog_token; |
| 200 | u8 query_data[1]; |
| 201 | }; |
| 202 | |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 203 | /** |
| 204 | * struct brcmf_config_af_params - Action Frame Parameters for tx. |
| 205 | * |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 206 | * @mpc_onoff: To make sure to send successfully action frame, we have to |
| 207 | * turn off mpc 0: off, 1: on, (-1): do nothing |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 208 | * @search_channel: 1: search peer's channel to send af |
| 209 | * extra_listen: keep the dwell time to get af response frame. |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 210 | */ |
| 211 | struct brcmf_config_af_params { |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 212 | s32 mpc_onoff; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 213 | bool search_channel; |
| 214 | bool extra_listen; |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 215 | }; |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 216 | |
| 217 | /** |
| 218 | * brcmf_p2p_is_pub_action() - true if p2p public type frame. |
| 219 | * |
| 220 | * @frame: action frame data. |
| 221 | * @frame_len: length of action frame data. |
| 222 | * |
| 223 | * Determine if action frame is p2p public action type |
| 224 | */ |
| 225 | static bool brcmf_p2p_is_pub_action(void *frame, u32 frame_len) |
| 226 | { |
| 227 | struct brcmf_p2p_pub_act_frame *pact_frm; |
| 228 | |
| 229 | if (frame == NULL) |
| 230 | return false; |
| 231 | |
| 232 | pact_frm = (struct brcmf_p2p_pub_act_frame *)frame; |
| 233 | if (frame_len < sizeof(struct brcmf_p2p_pub_act_frame) - 1) |
| 234 | return false; |
| 235 | |
| 236 | if (pact_frm->category == P2P_PUB_AF_CATEGORY && |
| 237 | pact_frm->action == P2P_PUB_AF_ACTION && |
| 238 | pact_frm->oui_type == P2P_VER && |
| 239 | memcmp(pact_frm->oui, P2P_OUI, P2P_OUI_LEN) == 0) |
| 240 | return true; |
| 241 | |
| 242 | return false; |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * brcmf_p2p_is_p2p_action() - true if p2p action type frame. |
| 247 | * |
| 248 | * @frame: action frame data. |
| 249 | * @frame_len: length of action frame data. |
| 250 | * |
| 251 | * Determine if action frame is p2p action type |
| 252 | */ |
| 253 | static bool brcmf_p2p_is_p2p_action(void *frame, u32 frame_len) |
| 254 | { |
| 255 | struct brcmf_p2p_action_frame *act_frm; |
| 256 | |
| 257 | if (frame == NULL) |
| 258 | return false; |
| 259 | |
| 260 | act_frm = (struct brcmf_p2p_action_frame *)frame; |
| 261 | if (frame_len < sizeof(struct brcmf_p2p_action_frame) - 1) |
| 262 | return false; |
| 263 | |
| 264 | if (act_frm->category == P2P_AF_CATEGORY && |
| 265 | act_frm->type == P2P_VER && |
| 266 | memcmp(act_frm->oui, P2P_OUI, P2P_OUI_LEN) == 0) |
| 267 | return true; |
| 268 | |
| 269 | return false; |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * brcmf_p2p_is_gas_action() - true if p2p gas action type frame. |
| 274 | * |
| 275 | * @frame: action frame data. |
| 276 | * @frame_len: length of action frame data. |
| 277 | * |
| 278 | * Determine if action frame is p2p gas action type |
| 279 | */ |
| 280 | static bool brcmf_p2p_is_gas_action(void *frame, u32 frame_len) |
| 281 | { |
| 282 | struct brcmf_p2psd_gas_pub_act_frame *sd_act_frm; |
| 283 | |
| 284 | if (frame == NULL) |
| 285 | return false; |
| 286 | |
| 287 | sd_act_frm = (struct brcmf_p2psd_gas_pub_act_frame *)frame; |
| 288 | if (frame_len < sizeof(struct brcmf_p2psd_gas_pub_act_frame) - 1) |
| 289 | return false; |
| 290 | |
| 291 | if (sd_act_frm->category != P2PSD_ACTION_CATEGORY) |
| 292 | return false; |
| 293 | |
| 294 | if (sd_act_frm->action == P2PSD_ACTION_ID_GAS_IREQ || |
| 295 | sd_act_frm->action == P2PSD_ACTION_ID_GAS_IRESP || |
| 296 | sd_act_frm->action == P2PSD_ACTION_ID_GAS_CREQ || |
| 297 | sd_act_frm->action == P2PSD_ACTION_ID_GAS_CRESP) |
| 298 | return true; |
| 299 | |
| 300 | return false; |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * brcmf_p2p_print_actframe() - debug print routine. |
| 305 | * |
| 306 | * @tx: Received or to be transmitted |
| 307 | * @frame: action frame data. |
| 308 | * @frame_len: length of action frame data. |
| 309 | * |
| 310 | * Print information about the p2p action frame |
| 311 | */ |
Hante Meuleman | 0a4cf48 | 2013-02-08 15:53:54 +0100 | [diff] [blame] | 312 | |
| 313 | #ifdef DEBUG |
| 314 | |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 315 | static void brcmf_p2p_print_actframe(bool tx, void *frame, u32 frame_len) |
| 316 | { |
| 317 | struct brcmf_p2p_pub_act_frame *pact_frm; |
| 318 | struct brcmf_p2p_action_frame *act_frm; |
| 319 | struct brcmf_p2psd_gas_pub_act_frame *sd_act_frm; |
| 320 | |
| 321 | if (!frame || frame_len <= 2) |
| 322 | return; |
| 323 | |
| 324 | if (brcmf_p2p_is_pub_action(frame, frame_len)) { |
| 325 | pact_frm = (struct brcmf_p2p_pub_act_frame *)frame; |
| 326 | switch (pact_frm->subtype) { |
| 327 | case P2P_PAF_GON_REQ: |
| 328 | brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Req Frame\n", |
| 329 | (tx) ? "TX" : "RX"); |
| 330 | break; |
| 331 | case P2P_PAF_GON_RSP: |
| 332 | brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Rsp Frame\n", |
| 333 | (tx) ? "TX" : "RX"); |
| 334 | break; |
| 335 | case P2P_PAF_GON_CONF: |
| 336 | brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Confirm Frame\n", |
| 337 | (tx) ? "TX" : "RX"); |
| 338 | break; |
| 339 | case P2P_PAF_INVITE_REQ: |
| 340 | brcmf_dbg(TRACE, "%s P2P Invitation Request Frame\n", |
| 341 | (tx) ? "TX" : "RX"); |
| 342 | break; |
| 343 | case P2P_PAF_INVITE_RSP: |
| 344 | brcmf_dbg(TRACE, "%s P2P Invitation Response Frame\n", |
| 345 | (tx) ? "TX" : "RX"); |
| 346 | break; |
| 347 | case P2P_PAF_DEVDIS_REQ: |
| 348 | brcmf_dbg(TRACE, "%s P2P Device Discoverability Request Frame\n", |
| 349 | (tx) ? "TX" : "RX"); |
| 350 | break; |
| 351 | case P2P_PAF_DEVDIS_RSP: |
| 352 | brcmf_dbg(TRACE, "%s P2P Device Discoverability Response Frame\n", |
| 353 | (tx) ? "TX" : "RX"); |
| 354 | break; |
| 355 | case P2P_PAF_PROVDIS_REQ: |
| 356 | brcmf_dbg(TRACE, "%s P2P Provision Discovery Request Frame\n", |
| 357 | (tx) ? "TX" : "RX"); |
| 358 | break; |
| 359 | case P2P_PAF_PROVDIS_RSP: |
| 360 | brcmf_dbg(TRACE, "%s P2P Provision Discovery Response Frame\n", |
| 361 | (tx) ? "TX" : "RX"); |
| 362 | break; |
| 363 | default: |
| 364 | brcmf_dbg(TRACE, "%s Unknown P2P Public Action Frame\n", |
| 365 | (tx) ? "TX" : "RX"); |
| 366 | break; |
| 367 | } |
| 368 | } else if (brcmf_p2p_is_p2p_action(frame, frame_len)) { |
| 369 | act_frm = (struct brcmf_p2p_action_frame *)frame; |
| 370 | switch (act_frm->subtype) { |
| 371 | case P2P_AF_NOTICE_OF_ABSENCE: |
| 372 | brcmf_dbg(TRACE, "%s P2P Notice of Absence Frame\n", |
| 373 | (tx) ? "TX" : "RX"); |
| 374 | break; |
| 375 | case P2P_AF_PRESENCE_REQ: |
| 376 | brcmf_dbg(TRACE, "%s P2P Presence Request Frame\n", |
| 377 | (tx) ? "TX" : "RX"); |
| 378 | break; |
| 379 | case P2P_AF_PRESENCE_RSP: |
| 380 | brcmf_dbg(TRACE, "%s P2P Presence Response Frame\n", |
| 381 | (tx) ? "TX" : "RX"); |
| 382 | break; |
| 383 | case P2P_AF_GO_DISC_REQ: |
| 384 | brcmf_dbg(TRACE, "%s P2P Discoverability Request Frame\n", |
| 385 | (tx) ? "TX" : "RX"); |
| 386 | break; |
| 387 | default: |
| 388 | brcmf_dbg(TRACE, "%s Unknown P2P Action Frame\n", |
| 389 | (tx) ? "TX" : "RX"); |
| 390 | } |
| 391 | |
| 392 | } else if (brcmf_p2p_is_gas_action(frame, frame_len)) { |
| 393 | sd_act_frm = (struct brcmf_p2psd_gas_pub_act_frame *)frame; |
| 394 | switch (sd_act_frm->action) { |
| 395 | case P2PSD_ACTION_ID_GAS_IREQ: |
| 396 | brcmf_dbg(TRACE, "%s P2P GAS Initial Request\n", |
| 397 | (tx) ? "TX" : "RX"); |
| 398 | break; |
| 399 | case P2PSD_ACTION_ID_GAS_IRESP: |
| 400 | brcmf_dbg(TRACE, "%s P2P GAS Initial Response\n", |
| 401 | (tx) ? "TX" : "RX"); |
| 402 | break; |
| 403 | case P2PSD_ACTION_ID_GAS_CREQ: |
| 404 | brcmf_dbg(TRACE, "%s P2P GAS Comback Request\n", |
| 405 | (tx) ? "TX" : "RX"); |
| 406 | break; |
| 407 | case P2PSD_ACTION_ID_GAS_CRESP: |
| 408 | brcmf_dbg(TRACE, "%s P2P GAS Comback Response\n", |
| 409 | (tx) ? "TX" : "RX"); |
| 410 | break; |
| 411 | default: |
| 412 | brcmf_dbg(TRACE, "%s Unknown P2P GAS Frame\n", |
| 413 | (tx) ? "TX" : "RX"); |
| 414 | break; |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | |
Hante Meuleman | 0a4cf48 | 2013-02-08 15:53:54 +0100 | [diff] [blame] | 419 | #else |
| 420 | |
| 421 | static void brcmf_p2p_print_actframe(bool tx, void *frame, u32 frame_len) |
| 422 | { |
| 423 | } |
| 424 | |
| 425 | #endif |
| 426 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 427 | |
| 428 | /** |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 429 | * brcmf_p2p_set_firmware() - prepare firmware for peer-to-peer operation. |
| 430 | * |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 431 | * @ifp: ifp to use for iovars (primary). |
| 432 | * @p2p_mac: mac address to configure for p2p_da_override |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 433 | */ |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 434 | static int brcmf_p2p_set_firmware(struct brcmf_if *ifp, u8 *p2p_mac) |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 435 | { |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 436 | s32 ret = 0; |
| 437 | |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 438 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1); |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 439 | brcmf_fil_iovar_int_set(ifp, "apsta", 1); |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 440 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 441 | |
| 442 | /* In case of COB type, firmware has default mac address |
| 443 | * After Initializing firmware, we have to set current mac address to |
Arend van Spriel | f48556e | 2014-09-30 10:23:16 +0200 | [diff] [blame] | 444 | * firmware for P2P device address. This must be done with discovery |
| 445 | * disabled. |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 446 | */ |
Arend van Spriel | f48556e | 2014-09-30 10:23:16 +0200 | [diff] [blame] | 447 | brcmf_fil_iovar_int_set(ifp, "p2p_disc", 0); |
| 448 | |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 449 | ret = brcmf_fil_iovar_data_set(ifp, "p2p_da_override", p2p_mac, |
| 450 | ETH_ALEN); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 451 | if (ret) |
| 452 | brcmf_err("failed to update device address ret %d\n", ret); |
| 453 | |
| 454 | return ret; |
| 455 | } |
| 456 | |
| 457 | /** |
| 458 | * brcmf_p2p_generate_bss_mac() - derive mac addresses for P2P. |
| 459 | * |
| 460 | * @p2p: P2P specific data. |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 461 | * @dev_addr: optional device address. |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 462 | * |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 463 | * P2P needs mac addresses for P2P device and interface. If no device |
| 464 | * address it specified, these are derived from the primary net device, ie. |
| 465 | * the permanent ethernet address of the device. |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 466 | */ |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 467 | static void brcmf_p2p_generate_bss_mac(struct brcmf_p2p_info *p2p, u8 *dev_addr) |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 468 | { |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 469 | struct brcmf_if *pri_ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp; |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 470 | bool local_admin = false; |
| 471 | |
| 472 | if (!dev_addr || is_zero_ether_addr(dev_addr)) { |
| 473 | dev_addr = pri_ifp->mac_addr; |
| 474 | local_admin = true; |
| 475 | } |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 476 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 477 | /* Generate the P2P Device Address. This consists of the device's |
| 478 | * primary MAC address with the locally administered bit set. |
| 479 | */ |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 480 | memcpy(p2p->dev_addr, dev_addr, ETH_ALEN); |
| 481 | if (local_admin) |
| 482 | p2p->dev_addr[0] |= 0x02; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 483 | |
| 484 | /* Generate the P2P Interface Address. If the discovery and connection |
| 485 | * BSSCFGs need to simultaneously co-exist, then this address must be |
| 486 | * different from the P2P Device Address, but also locally administered. |
| 487 | */ |
| 488 | memcpy(p2p->int_addr, p2p->dev_addr, ETH_ALEN); |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 489 | p2p->int_addr[0] |= 0x02; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 490 | p2p->int_addr[4] ^= 0x80; |
| 491 | } |
| 492 | |
| 493 | /** |
| 494 | * brcmf_p2p_scan_is_p2p_request() - is cfg80211 scan request a P2P scan. |
| 495 | * |
| 496 | * @request: the scan request as received from cfg80211. |
| 497 | * |
| 498 | * returns true if one of the ssids in the request matches the |
| 499 | * P2P wildcard ssid; otherwise returns false. |
| 500 | */ |
| 501 | static bool brcmf_p2p_scan_is_p2p_request(struct cfg80211_scan_request *request) |
| 502 | { |
| 503 | struct cfg80211_ssid *ssids = request->ssids; |
| 504 | int i; |
| 505 | |
| 506 | for (i = 0; i < request->n_ssids; i++) { |
| 507 | if (ssids[i].ssid_len != BRCMF_P2P_WILDCARD_SSID_LEN) |
| 508 | continue; |
| 509 | |
| 510 | brcmf_dbg(INFO, "comparing ssid \"%s\"", ssids[i].ssid); |
| 511 | if (!memcmp(BRCMF_P2P_WILDCARD_SSID, ssids[i].ssid, |
| 512 | BRCMF_P2P_WILDCARD_SSID_LEN)) |
| 513 | return true; |
| 514 | } |
| 515 | return false; |
| 516 | } |
| 517 | |
| 518 | /** |
| 519 | * brcmf_p2p_set_discover_state - set discover state in firmware. |
| 520 | * |
| 521 | * @ifp: low-level interface object. |
| 522 | * @state: discover state to set. |
| 523 | * @chanspec: channel parameters (for state @WL_P2P_DISC_ST_LISTEN only). |
| 524 | * @listen_ms: duration to listen (for state @WL_P2P_DISC_ST_LISTEN only). |
| 525 | */ |
| 526 | static s32 brcmf_p2p_set_discover_state(struct brcmf_if *ifp, u8 state, |
| 527 | u16 chanspec, u16 listen_ms) |
| 528 | { |
| 529 | struct brcmf_p2p_disc_st_le discover_state; |
| 530 | s32 ret = 0; |
| 531 | brcmf_dbg(TRACE, "enter\n"); |
| 532 | |
| 533 | discover_state.state = state; |
| 534 | discover_state.chspec = cpu_to_le16(chanspec); |
| 535 | discover_state.dwell = cpu_to_le16(listen_ms); |
| 536 | ret = brcmf_fil_bsscfg_data_set(ifp, "p2p_state", &discover_state, |
| 537 | sizeof(discover_state)); |
| 538 | return ret; |
| 539 | } |
| 540 | |
| 541 | /** |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 542 | * brcmf_p2p_deinit_discovery() - disable P2P device discovery. |
| 543 | * |
| 544 | * @p2p: P2P specific data. |
| 545 | * |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 546 | * Resets the discovery state and disables it in firmware. |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 547 | */ |
| 548 | static s32 brcmf_p2p_deinit_discovery(struct brcmf_p2p_info *p2p) |
| 549 | { |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 550 | struct brcmf_cfg80211_vif *vif; |
| 551 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 552 | brcmf_dbg(TRACE, "enter\n"); |
| 553 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 554 | /* Set the discovery state to SCAN */ |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 555 | vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif; |
| 556 | (void)brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_SCAN, 0, 0); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 557 | |
| 558 | /* Disable P2P discovery in the firmware */ |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 559 | vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif; |
| 560 | (void)brcmf_fil_iovar_int_set(vif->ifp, "p2p_disc", 0); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 561 | |
| 562 | return 0; |
| 563 | } |
| 564 | |
| 565 | /** |
| 566 | * brcmf_p2p_enable_discovery() - initialize and configure discovery. |
| 567 | * |
| 568 | * @p2p: P2P specific data. |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 569 | * |
| 570 | * Initializes the discovery device and configure the virtual interface. |
| 571 | */ |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 572 | static int brcmf_p2p_enable_discovery(struct brcmf_p2p_info *p2p) |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 573 | { |
| 574 | struct brcmf_cfg80211_vif *vif; |
| 575 | s32 ret = 0; |
| 576 | |
| 577 | brcmf_dbg(TRACE, "enter\n"); |
| 578 | vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif; |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 579 | if (!vif) { |
| 580 | brcmf_err("P2P config device not available\n"); |
| 581 | ret = -EPERM; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 582 | goto exit; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 583 | } |
| 584 | |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 585 | if (test_bit(BRCMF_P2P_STATUS_ENABLED, &p2p->status)) { |
| 586 | brcmf_dbg(INFO, "P2P config device already configured\n"); |
| 587 | goto exit; |
| 588 | } |
| 589 | |
| 590 | /* Re-initialize P2P Discovery in the firmware */ |
| 591 | vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif; |
| 592 | ret = brcmf_fil_iovar_int_set(vif->ifp, "p2p_disc", 1); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 593 | if (ret < 0) { |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 594 | brcmf_err("set p2p_disc error\n"); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 595 | goto exit; |
| 596 | } |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 597 | vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif; |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 598 | ret = brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_SCAN, 0, 0); |
| 599 | if (ret < 0) { |
| 600 | brcmf_err("unable to set WL_P2P_DISC_ST_SCAN\n"); |
| 601 | goto exit; |
| 602 | } |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 603 | |
| 604 | /* |
| 605 | * Set wsec to any non-zero value in the discovery bsscfg |
| 606 | * to ensure our P2P probe responses have the privacy bit |
| 607 | * set in the 802.11 WPA IE. Some peer devices may not |
| 608 | * initiate WPS with us if this bit is not set. |
| 609 | */ |
| 610 | ret = brcmf_fil_bsscfg_int_set(vif->ifp, "wsec", AES_ENABLED); |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 611 | if (ret < 0) { |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 612 | brcmf_err("wsec error %d\n", ret); |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 613 | goto exit; |
| 614 | } |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 615 | |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 616 | set_bit(BRCMF_P2P_STATUS_ENABLED, &p2p->status); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 617 | exit: |
| 618 | return ret; |
| 619 | } |
| 620 | |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 621 | /** |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 622 | * brcmf_p2p_escan() - initiate a P2P scan. |
| 623 | * |
| 624 | * @p2p: P2P specific data. |
| 625 | * @num_chans: number of channels to scan. |
| 626 | * @chanspecs: channel parameters for @num_chans channels. |
| 627 | * @search_state: P2P discover state to use. |
| 628 | * @action: scan action to pass to firmware. |
| 629 | * @bss_type: type of P2P bss. |
| 630 | */ |
| 631 | static s32 brcmf_p2p_escan(struct brcmf_p2p_info *p2p, u32 num_chans, |
| 632 | u16 chanspecs[], s32 search_state, u16 action, |
| 633 | enum p2p_bss_type bss_type) |
| 634 | { |
| 635 | s32 ret = 0; |
| 636 | s32 memsize = offsetof(struct brcmf_p2p_scan_le, |
| 637 | eparams.params_le.channel_list); |
| 638 | s32 nprobes; |
| 639 | s32 active; |
| 640 | u32 i; |
| 641 | u8 *memblk; |
| 642 | struct brcmf_cfg80211_vif *vif; |
| 643 | struct brcmf_p2p_scan_le *p2p_params; |
| 644 | struct brcmf_scan_params_le *sparams; |
| 645 | struct brcmf_ssid ssid; |
| 646 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 647 | memsize += num_chans * sizeof(__le16); |
| 648 | memblk = kzalloc(memsize, GFP_KERNEL); |
| 649 | if (!memblk) |
| 650 | return -ENOMEM; |
| 651 | |
| 652 | vif = p2p->bss_idx[bss_type].vif; |
| 653 | if (vif == NULL) { |
| 654 | brcmf_err("no vif for bss type %d\n", bss_type); |
| 655 | ret = -EINVAL; |
| 656 | goto exit; |
| 657 | } |
| 658 | |
| 659 | switch (search_state) { |
| 660 | case WL_P2P_DISC_ST_SEARCH: |
| 661 | /* |
| 662 | * If we in SEARCH STATE, we don't need to set SSID explictly |
| 663 | * because dongle use P2P WILDCARD internally by default |
| 664 | */ |
| 665 | /* use null ssid */ |
| 666 | ssid.SSID_len = 0; |
| 667 | memset(ssid.SSID, 0, sizeof(ssid.SSID)); |
| 668 | break; |
| 669 | case WL_P2P_DISC_ST_SCAN: |
| 670 | /* |
| 671 | * wpa_supplicant has p2p_find command with type social or |
| 672 | * progressive. For progressive, we need to set the ssid to |
| 673 | * P2P WILDCARD because we just do broadcast scan unless |
| 674 | * setting SSID. |
| 675 | */ |
| 676 | ssid.SSID_len = BRCMF_P2P_WILDCARD_SSID_LEN; |
| 677 | memcpy(ssid.SSID, BRCMF_P2P_WILDCARD_SSID, ssid.SSID_len); |
| 678 | break; |
| 679 | default: |
| 680 | brcmf_err(" invalid search state %d\n", search_state); |
| 681 | ret = -EINVAL; |
| 682 | goto exit; |
| 683 | } |
| 684 | |
| 685 | brcmf_p2p_set_discover_state(vif->ifp, search_state, 0, 0); |
| 686 | |
| 687 | /* |
| 688 | * set p2p scan parameters. |
| 689 | */ |
| 690 | p2p_params = (struct brcmf_p2p_scan_le *)memblk; |
| 691 | p2p_params->type = 'E'; |
| 692 | |
| 693 | /* determine the scan engine parameters */ |
| 694 | sparams = &p2p_params->eparams.params_le; |
| 695 | sparams->bss_type = DOT11_BSSTYPE_ANY; |
| 696 | if (p2p->cfg->active_scan) |
| 697 | sparams->scan_type = 0; |
| 698 | else |
| 699 | sparams->scan_type = 1; |
| 700 | |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 701 | eth_broadcast_addr(sparams->bssid); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 702 | if (ssid.SSID_len) |
| 703 | memcpy(sparams->ssid_le.SSID, ssid.SSID, ssid.SSID_len); |
| 704 | sparams->ssid_le.SSID_len = cpu_to_le32(ssid.SSID_len); |
| 705 | sparams->home_time = cpu_to_le32(P2PAPI_SCAN_HOME_TIME_MS); |
| 706 | |
| 707 | /* |
| 708 | * SOCIAL_CHAN_CNT + 1 takes care of the Progressive scan |
| 709 | * supported by the supplicant. |
| 710 | */ |
| 711 | if (num_chans == SOCIAL_CHAN_CNT || num_chans == (SOCIAL_CHAN_CNT + 1)) |
| 712 | active = P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS; |
| 713 | else if (num_chans == AF_PEER_SEARCH_CNT) |
| 714 | active = P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS; |
Rasmus Villemoes | e843bb1 | 2014-06-22 20:50:40 +0200 | [diff] [blame] | 715 | else if (brcmf_get_vif_state_any(p2p->cfg, BRCMF_VIF_STATUS_CONNECTED)) |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 716 | active = -1; |
| 717 | else |
| 718 | active = P2PAPI_SCAN_DWELL_TIME_MS; |
| 719 | |
| 720 | /* Override scan params to find a peer for a connection */ |
| 721 | if (num_chans == 1) { |
| 722 | active = WL_SCAN_CONNECT_DWELL_TIME_MS; |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 723 | /* WAR to sync with presence period of VSDB GO. |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 724 | * send probe request more frequently |
| 725 | */ |
| 726 | nprobes = active / WL_SCAN_JOIN_PROBE_INTERVAL_MS; |
| 727 | } else { |
| 728 | nprobes = active / P2PAPI_SCAN_NPROBS_TIME_MS; |
| 729 | } |
| 730 | |
| 731 | if (nprobes <= 0) |
| 732 | nprobes = 1; |
| 733 | |
| 734 | brcmf_dbg(INFO, "nprobes # %d, active_time %d\n", nprobes, active); |
| 735 | sparams->active_time = cpu_to_le32(active); |
| 736 | sparams->nprobes = cpu_to_le32(nprobes); |
| 737 | sparams->passive_time = cpu_to_le32(-1); |
| 738 | sparams->channel_num = cpu_to_le32(num_chans & |
| 739 | BRCMF_SCAN_PARAMS_COUNT_MASK); |
| 740 | for (i = 0; i < num_chans; i++) |
| 741 | sparams->channel_list[i] = cpu_to_le16(chanspecs[i]); |
| 742 | |
| 743 | /* set the escan specific parameters */ |
| 744 | p2p_params->eparams.version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION); |
| 745 | p2p_params->eparams.action = cpu_to_le16(action); |
| 746 | p2p_params->eparams.sync_id = cpu_to_le16(0x1234); |
| 747 | /* perform p2p scan on primary device */ |
| 748 | ret = brcmf_fil_bsscfg_data_set(vif->ifp, "p2p_scan", memblk, memsize); |
| 749 | if (!ret) |
| 750 | set_bit(BRCMF_SCAN_STATUS_BUSY, &p2p->cfg->scan_status); |
| 751 | exit: |
| 752 | kfree(memblk); |
| 753 | return ret; |
| 754 | } |
| 755 | |
| 756 | /** |
| 757 | * brcmf_p2p_run_escan() - escan callback for peer-to-peer. |
| 758 | * |
| 759 | * @cfg: driver private data for cfg80211 interface. |
| 760 | * @ndev: net device for which scan is requested. |
| 761 | * @request: scan request from cfg80211. |
| 762 | * @action: scan action. |
| 763 | * |
| 764 | * Determines the P2P discovery state based to scan request parameters and |
| 765 | * validates the channels in the request. |
| 766 | */ |
| 767 | static s32 brcmf_p2p_run_escan(struct brcmf_cfg80211_info *cfg, |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 768 | struct brcmf_if *ifp, |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 769 | struct cfg80211_scan_request *request, |
| 770 | u16 action) |
| 771 | { |
| 772 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
| 773 | s32 err = 0; |
| 774 | s32 search_state = WL_P2P_DISC_ST_SCAN; |
| 775 | struct brcmf_cfg80211_vif *vif; |
| 776 | struct net_device *dev = NULL; |
| 777 | int i, num_nodfs = 0; |
| 778 | u16 *chanspecs; |
| 779 | |
| 780 | brcmf_dbg(TRACE, "enter\n"); |
| 781 | |
| 782 | if (!request) { |
| 783 | err = -EINVAL; |
| 784 | goto exit; |
| 785 | } |
| 786 | |
| 787 | if (request->n_channels) { |
| 788 | chanspecs = kcalloc(request->n_channels, sizeof(*chanspecs), |
| 789 | GFP_KERNEL); |
| 790 | if (!chanspecs) { |
| 791 | err = -ENOMEM; |
| 792 | goto exit; |
| 793 | } |
| 794 | vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif; |
| 795 | if (vif) |
| 796 | dev = vif->wdev.netdev; |
| 797 | if (request->n_channels == 3 && |
| 798 | request->channels[0]->hw_value == SOCIAL_CHAN_1 && |
| 799 | request->channels[1]->hw_value == SOCIAL_CHAN_2 && |
| 800 | request->channels[2]->hw_value == SOCIAL_CHAN_3) { |
| 801 | /* SOCIAL CHANNELS 1, 6, 11 */ |
| 802 | search_state = WL_P2P_DISC_ST_SEARCH; |
| 803 | brcmf_dbg(INFO, "P2P SEARCH PHASE START\n"); |
Arend van Spriel | 967fe2c | 2014-03-15 17:18:21 +0100 | [diff] [blame] | 804 | } else if (dev != NULL && |
| 805 | vif->wdev.iftype == NL80211_IFTYPE_P2P_GO) { |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 806 | /* If you are already a GO, then do SEARCH only */ |
| 807 | brcmf_dbg(INFO, "Already a GO. Do SEARCH Only\n"); |
| 808 | search_state = WL_P2P_DISC_ST_SEARCH; |
| 809 | } else { |
| 810 | brcmf_dbg(INFO, "P2P SCAN STATE START\n"); |
| 811 | } |
| 812 | |
| 813 | /* |
| 814 | * no P2P scanning on passive or DFS channels. |
| 815 | */ |
| 816 | for (i = 0; i < request->n_channels; i++) { |
| 817 | struct ieee80211_channel *chan = request->channels[i]; |
| 818 | |
| 819 | if (chan->flags & (IEEE80211_CHAN_RADAR | |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 820 | IEEE80211_CHAN_NO_IR)) |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 821 | continue; |
| 822 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 823 | chanspecs[i] = channel_to_chanspec(&p2p->cfg->d11inf, |
| 824 | chan); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 825 | brcmf_dbg(INFO, "%d: chan=%d, channel spec=%x\n", |
| 826 | num_nodfs, chan->hw_value, chanspecs[i]); |
| 827 | num_nodfs++; |
| 828 | } |
| 829 | err = brcmf_p2p_escan(p2p, num_nodfs, chanspecs, search_state, |
| 830 | action, P2PAPI_BSSCFG_DEVICE); |
Geyslan G. Bem | 3b1bace | 2013-11-15 09:21:47 -0300 | [diff] [blame] | 831 | kfree(chanspecs); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 832 | } |
| 833 | exit: |
| 834 | if (err) |
| 835 | brcmf_err("error (%d)\n", err); |
| 836 | return err; |
| 837 | } |
| 838 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 839 | |
| 840 | /** |
| 841 | * brcmf_p2p_find_listen_channel() - find listen channel in ie string. |
| 842 | * |
| 843 | * @ie: string of information elements. |
| 844 | * @ie_len: length of string. |
| 845 | * |
| 846 | * Scan ie for p2p ie and look for attribute 6 channel. If available determine |
| 847 | * channel and return it. |
| 848 | */ |
| 849 | static s32 brcmf_p2p_find_listen_channel(const u8 *ie, u32 ie_len) |
| 850 | { |
| 851 | u8 channel_ie[5]; |
| 852 | s32 listen_channel; |
| 853 | s32 err; |
| 854 | |
| 855 | err = cfg80211_get_p2p_attr(ie, ie_len, |
| 856 | IEEE80211_P2P_ATTR_LISTEN_CHANNEL, |
| 857 | channel_ie, sizeof(channel_ie)); |
| 858 | if (err < 0) |
| 859 | return err; |
| 860 | |
| 861 | /* listen channel subel length format: */ |
| 862 | /* 3(country) + 1(op. class) + 1(chan num) */ |
| 863 | listen_channel = (s32)channel_ie[3 + 1]; |
| 864 | |
| 865 | if (listen_channel == SOCIAL_CHAN_1 || |
| 866 | listen_channel == SOCIAL_CHAN_2 || |
| 867 | listen_channel == SOCIAL_CHAN_3) { |
| 868 | brcmf_dbg(INFO, "Found my Listen Channel %d\n", listen_channel); |
| 869 | return listen_channel; |
| 870 | } |
| 871 | |
| 872 | return -EPERM; |
| 873 | } |
| 874 | |
| 875 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 876 | /** |
| 877 | * brcmf_p2p_scan_prep() - prepare scan based on request. |
| 878 | * |
| 879 | * @wiphy: wiphy device. |
| 880 | * @request: scan request from cfg80211. |
Hante Meuleman | 0f8ffe1 | 2013-02-08 15:53:42 +0100 | [diff] [blame] | 881 | * @vif: vif on which scan request is to be executed. |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 882 | * |
| 883 | * Prepare the scan appropriately for type of scan requested. Overrides the |
| 884 | * escan .run() callback for peer-to-peer scanning. |
| 885 | */ |
| 886 | int brcmf_p2p_scan_prep(struct wiphy *wiphy, |
Hante Meuleman | 0f8ffe1 | 2013-02-08 15:53:42 +0100 | [diff] [blame] | 887 | struct cfg80211_scan_request *request, |
| 888 | struct brcmf_cfg80211_vif *vif) |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 889 | { |
| 890 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 891 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
| 892 | int err = 0; |
| 893 | |
| 894 | if (brcmf_p2p_scan_is_p2p_request(request)) { |
| 895 | /* find my listen channel */ |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 896 | err = brcmf_p2p_find_listen_channel(request->ie, |
| 897 | request->ie_len); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 898 | if (err < 0) |
| 899 | return err; |
| 900 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 901 | p2p->afx_hdl.my_listen_chan = err; |
| 902 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 903 | clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status); |
| 904 | brcmf_dbg(INFO, "P2P: GO_NEG_PHASE status cleared\n"); |
| 905 | |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 906 | err = brcmf_p2p_enable_discovery(p2p); |
Hante Meuleman | 0f8ffe1 | 2013-02-08 15:53:42 +0100 | [diff] [blame] | 907 | if (err) |
| 908 | return err; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 909 | |
Hante Meuleman | 0f8ffe1 | 2013-02-08 15:53:42 +0100 | [diff] [blame] | 910 | vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif; |
| 911 | |
| 912 | /* override .run_escan() callback. */ |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 913 | cfg->escan_info.run = brcmf_p2p_run_escan; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 914 | } |
Hante Meuleman | 0f8ffe1 | 2013-02-08 15:53:42 +0100 | [diff] [blame] | 915 | err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBREQ_FLAG, |
| 916 | request->ie, request->ie_len); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 917 | return err; |
| 918 | } |
| 919 | |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 920 | |
| 921 | /** |
Hante Meuleman | f2058dd | 2013-02-08 15:53:50 +0100 | [diff] [blame] | 922 | * brcmf_p2p_discover_listen() - set firmware to discover listen state. |
| 923 | * |
| 924 | * @p2p: p2p device. |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 925 | * @channel: channel nr for discover listen. |
| 926 | * @duration: time in ms to stay on channel. |
Hante Meuleman | f2058dd | 2013-02-08 15:53:50 +0100 | [diff] [blame] | 927 | * |
| 928 | */ |
| 929 | static s32 |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 930 | brcmf_p2p_discover_listen(struct brcmf_p2p_info *p2p, u16 channel, u32 duration) |
Hante Meuleman | f2058dd | 2013-02-08 15:53:50 +0100 | [diff] [blame] | 931 | { |
| 932 | struct brcmf_cfg80211_vif *vif; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 933 | struct brcmu_chan ch; |
Hante Meuleman | f2058dd | 2013-02-08 15:53:50 +0100 | [diff] [blame] | 934 | s32 err = 0; |
Hante Meuleman | f2058dd | 2013-02-08 15:53:50 +0100 | [diff] [blame] | 935 | |
| 936 | vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif; |
| 937 | if (!vif) { |
| 938 | brcmf_err("Discovery is not set, so we have nothing to do\n"); |
| 939 | err = -EPERM; |
| 940 | goto exit; |
| 941 | } |
| 942 | |
| 943 | if (test_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, &p2p->status)) { |
| 944 | brcmf_err("Previous LISTEN is not completed yet\n"); |
| 945 | /* WAR: prevent cookie mismatch in wpa_supplicant return OK */ |
| 946 | goto exit; |
| 947 | } |
| 948 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 949 | ch.chnum = channel; |
| 950 | ch.bw = BRCMU_CHAN_BW_20; |
| 951 | p2p->cfg->d11inf.encchspec(&ch); |
Hante Meuleman | f2058dd | 2013-02-08 15:53:50 +0100 | [diff] [blame] | 952 | err = brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_LISTEN, |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 953 | ch.chspec, (u16)duration); |
Hante Meuleman | f2058dd | 2013-02-08 15:53:50 +0100 | [diff] [blame] | 954 | if (!err) { |
| 955 | set_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, &p2p->status); |
| 956 | p2p->remain_on_channel_cookie++; |
| 957 | } |
| 958 | exit: |
| 959 | return err; |
| 960 | } |
| 961 | |
| 962 | |
| 963 | /** |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 964 | * brcmf_p2p_remain_on_channel() - put device on channel and stay there. |
| 965 | * |
| 966 | * @wiphy: wiphy device. |
| 967 | * @channel: channel to stay on. |
| 968 | * @duration: time in ms to remain on channel. |
| 969 | * |
| 970 | */ |
| 971 | int brcmf_p2p_remain_on_channel(struct wiphy *wiphy, struct wireless_dev *wdev, |
| 972 | struct ieee80211_channel *channel, |
| 973 | unsigned int duration, u64 *cookie) |
| 974 | { |
| 975 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 976 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 977 | s32 err; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 978 | u16 channel_nr; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 979 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 980 | channel_nr = ieee80211_frequency_to_channel(channel->center_freq); |
| 981 | brcmf_dbg(TRACE, "Enter, channel: %d, duration ms (%d)\n", channel_nr, |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 982 | duration); |
| 983 | |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 984 | err = brcmf_p2p_enable_discovery(p2p); |
| 985 | if (err) |
| 986 | goto exit; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 987 | err = brcmf_p2p_discover_listen(p2p, channel_nr, duration); |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 988 | if (err) |
| 989 | goto exit; |
| 990 | |
Hante Meuleman | f2058dd | 2013-02-08 15:53:50 +0100 | [diff] [blame] | 991 | memcpy(&p2p->remain_on_channel, channel, sizeof(*channel)); |
| 992 | *cookie = p2p->remain_on_channel_cookie; |
Arend van Spriel | 1ce3086 | 2013-02-08 15:53:51 +0100 | [diff] [blame] | 993 | cfg80211_ready_on_channel(wdev, *cookie, channel, duration, GFP_KERNEL); |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 994 | |
| 995 | exit: |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 996 | return err; |
| 997 | } |
| 998 | |
| 999 | |
| 1000 | /** |
| 1001 | * brcmf_p2p_notify_listen_complete() - p2p listen has completed. |
| 1002 | * |
| 1003 | * @ifp: interfac control. |
| 1004 | * @e: event message. Not used, to make it usable for fweh event dispatcher. |
| 1005 | * @data: payload of message. Not used. |
| 1006 | * |
| 1007 | */ |
| 1008 | int brcmf_p2p_notify_listen_complete(struct brcmf_if *ifp, |
| 1009 | const struct brcmf_event_msg *e, |
| 1010 | void *data) |
| 1011 | { |
| 1012 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
| 1013 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
| 1014 | |
| 1015 | brcmf_dbg(TRACE, "Enter\n"); |
Hante Meuleman | f2058dd | 2013-02-08 15:53:50 +0100 | [diff] [blame] | 1016 | if (test_and_clear_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1017 | &p2p->status)) { |
| 1018 | if (test_and_clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN, |
| 1019 | &p2p->status)) { |
| 1020 | clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, |
| 1021 | &p2p->status); |
| 1022 | brcmf_dbg(INFO, "Listen DONE, wake up wait_next_af\n"); |
| 1023 | complete(&p2p->wait_next_af); |
| 1024 | } |
| 1025 | |
Hante Meuleman | f2058dd | 2013-02-08 15:53:50 +0100 | [diff] [blame] | 1026 | cfg80211_remain_on_channel_expired(&ifp->vif->wdev, |
| 1027 | p2p->remain_on_channel_cookie, |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 1028 | &p2p->remain_on_channel, |
| 1029 | GFP_KERNEL); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1030 | } |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 1031 | return 0; |
| 1032 | } |
| 1033 | |
| 1034 | |
| 1035 | /** |
| 1036 | * brcmf_p2p_cancel_remain_on_channel() - cancel p2p listen state. |
| 1037 | * |
| 1038 | * @ifp: interfac control. |
| 1039 | * |
| 1040 | */ |
| 1041 | void brcmf_p2p_cancel_remain_on_channel(struct brcmf_if *ifp) |
| 1042 | { |
| 1043 | if (!ifp) |
| 1044 | return; |
| 1045 | brcmf_p2p_set_discover_state(ifp, WL_P2P_DISC_ST_SCAN, 0, 0); |
| 1046 | brcmf_p2p_notify_listen_complete(ifp, NULL, NULL); |
| 1047 | } |
| 1048 | |
| 1049 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1050 | /** |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1051 | * brcmf_p2p_act_frm_search() - search function for action frame. |
| 1052 | * |
| 1053 | * @p2p: p2p device. |
| 1054 | * channel: channel on which action frame is to be trasmitted. |
| 1055 | * |
| 1056 | * search function to reach at common channel to send action frame. When |
| 1057 | * channel is 0 then all social channels will be used to send af |
| 1058 | */ |
| 1059 | static s32 brcmf_p2p_act_frm_search(struct brcmf_p2p_info *p2p, u16 channel) |
| 1060 | { |
| 1061 | s32 err; |
| 1062 | u32 channel_cnt; |
| 1063 | u16 *default_chan_list; |
| 1064 | u32 i; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 1065 | struct brcmu_chan ch; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1066 | |
| 1067 | brcmf_dbg(TRACE, "Enter\n"); |
| 1068 | |
| 1069 | if (channel) |
| 1070 | channel_cnt = AF_PEER_SEARCH_CNT; |
| 1071 | else |
| 1072 | channel_cnt = SOCIAL_CHAN_CNT; |
| 1073 | default_chan_list = kzalloc(channel_cnt * sizeof(*default_chan_list), |
| 1074 | GFP_KERNEL); |
| 1075 | if (default_chan_list == NULL) { |
| 1076 | brcmf_err("channel list allocation failed\n"); |
| 1077 | err = -ENOMEM; |
| 1078 | goto exit; |
| 1079 | } |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 1080 | ch.bw = BRCMU_CHAN_BW_20; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1081 | if (channel) { |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 1082 | ch.chnum = channel; |
| 1083 | p2p->cfg->d11inf.encchspec(&ch); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1084 | /* insert same channel to the chan_list */ |
| 1085 | for (i = 0; i < channel_cnt; i++) |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 1086 | default_chan_list[i] = ch.chspec; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1087 | } else { |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 1088 | ch.chnum = SOCIAL_CHAN_1; |
| 1089 | p2p->cfg->d11inf.encchspec(&ch); |
| 1090 | default_chan_list[0] = ch.chspec; |
| 1091 | ch.chnum = SOCIAL_CHAN_2; |
| 1092 | p2p->cfg->d11inf.encchspec(&ch); |
| 1093 | default_chan_list[1] = ch.chspec; |
| 1094 | ch.chnum = SOCIAL_CHAN_3; |
| 1095 | p2p->cfg->d11inf.encchspec(&ch); |
| 1096 | default_chan_list[2] = ch.chspec; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1097 | } |
| 1098 | err = brcmf_p2p_escan(p2p, channel_cnt, default_chan_list, |
| 1099 | WL_P2P_DISC_ST_SEARCH, WL_ESCAN_ACTION_START, |
| 1100 | P2PAPI_BSSCFG_DEVICE); |
| 1101 | kfree(default_chan_list); |
| 1102 | exit: |
| 1103 | return err; |
| 1104 | } |
| 1105 | |
| 1106 | |
| 1107 | /** |
| 1108 | * brcmf_p2p_afx_handler() - afx worker thread. |
| 1109 | * |
| 1110 | * @work: |
| 1111 | * |
| 1112 | */ |
| 1113 | static void brcmf_p2p_afx_handler(struct work_struct *work) |
| 1114 | { |
| 1115 | struct afx_hdl *afx_hdl = container_of(work, struct afx_hdl, afx_work); |
| 1116 | struct brcmf_p2p_info *p2p = container_of(afx_hdl, |
| 1117 | struct brcmf_p2p_info, |
| 1118 | afx_hdl); |
| 1119 | s32 err; |
| 1120 | |
| 1121 | if (!afx_hdl->is_active) |
| 1122 | return; |
| 1123 | |
| 1124 | if (afx_hdl->is_listen && afx_hdl->my_listen_chan) |
| 1125 | /* 100ms ~ 300ms */ |
| 1126 | err = brcmf_p2p_discover_listen(p2p, afx_hdl->my_listen_chan, |
Akinobu Mita | e00adf3 | 2013-05-07 16:18:15 -0700 | [diff] [blame] | 1127 | 100 * (1 + prandom_u32() % 3)); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1128 | else |
| 1129 | err = brcmf_p2p_act_frm_search(p2p, afx_hdl->peer_listen_chan); |
| 1130 | |
| 1131 | if (err) { |
| 1132 | brcmf_err("ERROR occurred! value is (%d)\n", err); |
| 1133 | if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, |
| 1134 | &p2p->status)) |
| 1135 | complete(&afx_hdl->act_frm_scan); |
| 1136 | } |
| 1137 | } |
| 1138 | |
| 1139 | |
| 1140 | /** |
| 1141 | * brcmf_p2p_af_searching_channel() - search channel. |
| 1142 | * |
| 1143 | * @p2p: p2p device info struct. |
| 1144 | * |
| 1145 | */ |
| 1146 | static s32 brcmf_p2p_af_searching_channel(struct brcmf_p2p_info *p2p) |
| 1147 | { |
| 1148 | struct afx_hdl *afx_hdl = &p2p->afx_hdl; |
| 1149 | struct brcmf_cfg80211_vif *pri_vif; |
| 1150 | unsigned long duration; |
| 1151 | s32 retry; |
| 1152 | |
| 1153 | brcmf_dbg(TRACE, "Enter\n"); |
| 1154 | |
| 1155 | pri_vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif; |
| 1156 | |
Wolfram Sang | 16735d0 | 2013-11-14 14:32:02 -0800 | [diff] [blame] | 1157 | reinit_completion(&afx_hdl->act_frm_scan); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1158 | set_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, &p2p->status); |
| 1159 | afx_hdl->is_active = true; |
| 1160 | afx_hdl->peer_chan = P2P_INVALID_CHANNEL; |
| 1161 | |
| 1162 | /* Loop to wait until we find a peer's channel or the |
| 1163 | * pending action frame tx is cancelled. |
| 1164 | */ |
| 1165 | retry = 0; |
| 1166 | duration = msecs_to_jiffies(P2P_AF_FRM_SCAN_MAX_WAIT); |
| 1167 | while ((retry < P2P_CHANNEL_SYNC_RETRY) && |
| 1168 | (afx_hdl->peer_chan == P2P_INVALID_CHANNEL)) { |
| 1169 | afx_hdl->is_listen = false; |
| 1170 | brcmf_dbg(TRACE, "Scheduling action frame for sending.. (%d)\n", |
| 1171 | retry); |
| 1172 | /* search peer on peer's listen channel */ |
| 1173 | schedule_work(&afx_hdl->afx_work); |
| 1174 | wait_for_completion_timeout(&afx_hdl->act_frm_scan, duration); |
| 1175 | if ((afx_hdl->peer_chan != P2P_INVALID_CHANNEL) || |
| 1176 | (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, |
| 1177 | &p2p->status))) |
| 1178 | break; |
| 1179 | |
| 1180 | if (afx_hdl->my_listen_chan) { |
| 1181 | brcmf_dbg(TRACE, "Scheduling listen peer, channel=%d\n", |
| 1182 | afx_hdl->my_listen_chan); |
| 1183 | /* listen on my listen channel */ |
| 1184 | afx_hdl->is_listen = true; |
| 1185 | schedule_work(&afx_hdl->afx_work); |
| 1186 | wait_for_completion_timeout(&afx_hdl->act_frm_scan, |
| 1187 | duration); |
| 1188 | } |
| 1189 | if ((afx_hdl->peer_chan != P2P_INVALID_CHANNEL) || |
| 1190 | (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, |
| 1191 | &p2p->status))) |
| 1192 | break; |
| 1193 | retry++; |
| 1194 | |
| 1195 | /* if sta is connected or connecting, sleep for a while before |
| 1196 | * retry af tx or finding a peer |
| 1197 | */ |
| 1198 | if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &pri_vif->sme_state) || |
| 1199 | test_bit(BRCMF_VIF_STATUS_CONNECTING, &pri_vif->sme_state)) |
| 1200 | msleep(P2P_DEFAULT_SLEEP_TIME_VSDB); |
| 1201 | } |
| 1202 | |
| 1203 | brcmf_dbg(TRACE, "Completed search/listen peer_chan=%d\n", |
| 1204 | afx_hdl->peer_chan); |
| 1205 | afx_hdl->is_active = false; |
| 1206 | |
| 1207 | clear_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, &p2p->status); |
| 1208 | |
| 1209 | return afx_hdl->peer_chan; |
| 1210 | } |
| 1211 | |
| 1212 | |
| 1213 | /** |
| 1214 | * brcmf_p2p_scan_finding_common_channel() - was escan used for finding channel |
| 1215 | * |
| 1216 | * @cfg: common configuration struct. |
| 1217 | * @bi: bss info struct, result from scan. |
| 1218 | * |
| 1219 | */ |
| 1220 | bool brcmf_p2p_scan_finding_common_channel(struct brcmf_cfg80211_info *cfg, |
| 1221 | struct brcmf_bss_info_le *bi) |
| 1222 | |
| 1223 | { |
| 1224 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
| 1225 | struct afx_hdl *afx_hdl = &p2p->afx_hdl; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 1226 | struct brcmu_chan ch; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1227 | u8 *ie; |
| 1228 | s32 err; |
| 1229 | u8 p2p_dev_addr[ETH_ALEN]; |
| 1230 | |
| 1231 | if (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, &p2p->status)) |
| 1232 | return false; |
| 1233 | |
| 1234 | if (bi == NULL) { |
| 1235 | brcmf_dbg(TRACE, "ACTION FRAME SCAN Done\n"); |
| 1236 | if (afx_hdl->peer_chan == P2P_INVALID_CHANNEL) |
| 1237 | complete(&afx_hdl->act_frm_scan); |
| 1238 | return true; |
| 1239 | } |
| 1240 | |
| 1241 | ie = ((u8 *)bi) + le16_to_cpu(bi->ie_offset); |
| 1242 | memset(p2p_dev_addr, 0, sizeof(p2p_dev_addr)); |
| 1243 | err = cfg80211_get_p2p_attr(ie, le32_to_cpu(bi->ie_length), |
| 1244 | IEEE80211_P2P_ATTR_DEVICE_INFO, |
| 1245 | p2p_dev_addr, sizeof(p2p_dev_addr)); |
| 1246 | if (err < 0) |
| 1247 | err = cfg80211_get_p2p_attr(ie, le32_to_cpu(bi->ie_length), |
| 1248 | IEEE80211_P2P_ATTR_DEVICE_ID, |
| 1249 | p2p_dev_addr, sizeof(p2p_dev_addr)); |
| 1250 | if ((err >= 0) && |
dingtianhong | 692e516 | 2013-12-26 19:41:34 +0800 | [diff] [blame] | 1251 | (ether_addr_equal(p2p_dev_addr, afx_hdl->tx_dst_addr))) { |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 1252 | if (!bi->ctl_ch) { |
| 1253 | ch.chspec = le16_to_cpu(bi->chanspec); |
| 1254 | cfg->d11inf.decchspec(&ch); |
| 1255 | bi->ctl_ch = ch.chnum; |
| 1256 | } |
| 1257 | afx_hdl->peer_chan = bi->ctl_ch; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1258 | brcmf_dbg(TRACE, "ACTION FRAME SCAN : Peer %pM found, channel : %d\n", |
| 1259 | afx_hdl->tx_dst_addr, afx_hdl->peer_chan); |
| 1260 | complete(&afx_hdl->act_frm_scan); |
| 1261 | } |
| 1262 | return true; |
| 1263 | } |
| 1264 | |
| 1265 | /** |
| 1266 | * brcmf_p2p_stop_wait_next_action_frame() - finish scan if af tx complete. |
| 1267 | * |
| 1268 | * @cfg: common configuration struct. |
| 1269 | * |
| 1270 | */ |
| 1271 | static void |
| 1272 | brcmf_p2p_stop_wait_next_action_frame(struct brcmf_cfg80211_info *cfg) |
| 1273 | { |
| 1274 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1275 | struct brcmf_if *ifp = cfg->escan_info.ifp; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1276 | |
| 1277 | if (test_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME, &p2p->status) && |
| 1278 | (test_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status) || |
| 1279 | test_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status))) { |
| 1280 | brcmf_dbg(TRACE, "*** Wake UP ** abort actframe iovar\n"); |
| 1281 | /* if channel is not zero, "actfame" uses off channel scan. |
| 1282 | * So abort scan for off channel completion. |
| 1283 | */ |
| 1284 | if (p2p->af_sent_channel) |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1285 | brcmf_notify_escan_complete(cfg, ifp, true, true); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1286 | } else if (test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN, |
| 1287 | &p2p->status)) { |
| 1288 | brcmf_dbg(TRACE, "*** Wake UP ** abort listen for next af frame\n"); |
| 1289 | /* So abort scan to cancel listen */ |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1290 | brcmf_notify_escan_complete(cfg, ifp, true, true); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | |
| 1295 | /** |
| 1296 | * brcmf_p2p_gon_req_collision() - Check if go negotiaton collission |
| 1297 | * |
| 1298 | * @p2p: p2p device info struct. |
| 1299 | * |
| 1300 | * return true if recevied action frame is to be dropped. |
| 1301 | */ |
| 1302 | static bool |
| 1303 | brcmf_p2p_gon_req_collision(struct brcmf_p2p_info *p2p, u8 *mac) |
| 1304 | { |
| 1305 | struct brcmf_cfg80211_info *cfg = p2p->cfg; |
| 1306 | struct brcmf_if *ifp; |
| 1307 | |
| 1308 | brcmf_dbg(TRACE, "Enter\n"); |
| 1309 | |
| 1310 | if (!test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, &p2p->status) || |
| 1311 | !p2p->gon_req_action) |
| 1312 | return false; |
| 1313 | |
| 1314 | brcmf_dbg(TRACE, "GO Negotiation Request COLLISION !!!\n"); |
| 1315 | /* if sa(peer) addr is less than da(my) addr, then this device |
| 1316 | * process peer's gon request and block to send gon req. |
| 1317 | * if not (sa addr > da addr), |
| 1318 | * this device will process gon request and drop gon req of peer. |
| 1319 | */ |
| 1320 | ifp = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif->ifp; |
| 1321 | if (memcmp(mac, ifp->mac_addr, ETH_ALEN) < 0) { |
| 1322 | brcmf_dbg(INFO, "Block transmit gon req !!!\n"); |
| 1323 | p2p->block_gon_req_tx = true; |
| 1324 | /* if we are finding a common channel for sending af, |
| 1325 | * do not scan more to block to send current gon req |
| 1326 | */ |
| 1327 | if (test_and_clear_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, |
| 1328 | &p2p->status)) |
| 1329 | complete(&p2p->afx_hdl.act_frm_scan); |
| 1330 | if (test_and_clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, |
| 1331 | &p2p->status)) |
| 1332 | brcmf_p2p_stop_wait_next_action_frame(cfg); |
| 1333 | return false; |
| 1334 | } |
| 1335 | |
| 1336 | /* drop gon request of peer to process gon request by this device. */ |
| 1337 | brcmf_dbg(INFO, "Drop received gon req !!!\n"); |
| 1338 | |
| 1339 | return true; |
| 1340 | } |
| 1341 | |
| 1342 | |
| 1343 | /** |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 1344 | * brcmf_p2p_notify_action_frame_rx() - received action frame. |
| 1345 | * |
| 1346 | * @ifp: interfac control. |
| 1347 | * @e: event message. Not used, to make it usable for fweh event dispatcher. |
| 1348 | * @data: payload of message, containing action frame data. |
| 1349 | * |
| 1350 | */ |
| 1351 | int brcmf_p2p_notify_action_frame_rx(struct brcmf_if *ifp, |
| 1352 | const struct brcmf_event_msg *e, |
| 1353 | void *data) |
| 1354 | { |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1355 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
| 1356 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
| 1357 | struct afx_hdl *afx_hdl = &p2p->afx_hdl; |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 1358 | struct wireless_dev *wdev; |
| 1359 | u32 mgmt_frame_len = e->datalen - sizeof(struct brcmf_rx_mgmt_data); |
| 1360 | struct brcmf_rx_mgmt_data *rxframe = (struct brcmf_rx_mgmt_data *)data; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1361 | u8 *frame = (u8 *)(rxframe + 1); |
| 1362 | struct brcmf_p2p_pub_act_frame *act_frm; |
| 1363 | struct brcmf_p2psd_gas_pub_act_frame *sd_act_frm; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 1364 | struct brcmu_chan ch; |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 1365 | struct ieee80211_mgmt *mgmt_frame; |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 1366 | s32 freq; |
| 1367 | u16 mgmt_type; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1368 | u8 action; |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 1369 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 1370 | ch.chspec = be16_to_cpu(rxframe->chanspec); |
| 1371 | cfg->d11inf.decchspec(&ch); |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 1372 | /* Check if wpa_supplicant has registered for this frame */ |
| 1373 | brcmf_dbg(INFO, "ifp->vif->mgmt_rx_reg %04x\n", ifp->vif->mgmt_rx_reg); |
| 1374 | mgmt_type = (IEEE80211_STYPE_ACTION & IEEE80211_FCTL_STYPE) >> 4; |
| 1375 | if ((ifp->vif->mgmt_rx_reg & BIT(mgmt_type)) == 0) |
| 1376 | return 0; |
| 1377 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1378 | brcmf_p2p_print_actframe(false, frame, mgmt_frame_len); |
| 1379 | |
| 1380 | action = P2P_PAF_SUBTYPE_INVALID; |
| 1381 | if (brcmf_p2p_is_pub_action(frame, mgmt_frame_len)) { |
| 1382 | act_frm = (struct brcmf_p2p_pub_act_frame *)frame; |
| 1383 | action = act_frm->subtype; |
| 1384 | if ((action == P2P_PAF_GON_REQ) && |
| 1385 | (brcmf_p2p_gon_req_collision(p2p, (u8 *)e->addr))) { |
| 1386 | if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, |
| 1387 | &p2p->status) && |
dingtianhong | 692e516 | 2013-12-26 19:41:34 +0800 | [diff] [blame] | 1388 | (ether_addr_equal(afx_hdl->tx_dst_addr, e->addr))) { |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 1389 | afx_hdl->peer_chan = ch.chnum; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1390 | brcmf_dbg(INFO, "GON request: Peer found, channel=%d\n", |
| 1391 | afx_hdl->peer_chan); |
| 1392 | complete(&afx_hdl->act_frm_scan); |
| 1393 | } |
| 1394 | return 0; |
| 1395 | } |
| 1396 | /* After complete GO Negotiation, roll back to mpc mode */ |
| 1397 | if ((action == P2P_PAF_GON_CONF) || |
| 1398 | (action == P2P_PAF_PROVDIS_RSP)) |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 1399 | brcmf_set_mpc(ifp, 1); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1400 | if (action == P2P_PAF_GON_CONF) { |
| 1401 | brcmf_dbg(TRACE, "P2P: GO_NEG_PHASE status cleared\n"); |
| 1402 | clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status); |
| 1403 | } |
| 1404 | } else if (brcmf_p2p_is_gas_action(frame, mgmt_frame_len)) { |
| 1405 | sd_act_frm = (struct brcmf_p2psd_gas_pub_act_frame *)frame; |
| 1406 | action = sd_act_frm->action; |
| 1407 | } |
| 1408 | |
| 1409 | if (test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, &p2p->status) && |
| 1410 | (p2p->next_af_subtype == action)) { |
| 1411 | brcmf_dbg(TRACE, "We got a right next frame! (%d)\n", action); |
| 1412 | clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, |
| 1413 | &p2p->status); |
| 1414 | /* Stop waiting for next AF. */ |
| 1415 | brcmf_p2p_stop_wait_next_action_frame(cfg); |
| 1416 | } |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 1417 | |
| 1418 | mgmt_frame = kzalloc(offsetof(struct ieee80211_mgmt, u) + |
| 1419 | mgmt_frame_len, GFP_KERNEL); |
| 1420 | if (!mgmt_frame) { |
| 1421 | brcmf_err("No memory available for action frame\n"); |
| 1422 | return -ENOMEM; |
| 1423 | } |
| 1424 | memcpy(mgmt_frame->da, ifp->mac_addr, ETH_ALEN); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1425 | brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSSID, mgmt_frame->bssid, |
| 1426 | ETH_ALEN); |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 1427 | memcpy(mgmt_frame->sa, e->addr, ETH_ALEN); |
| 1428 | mgmt_frame->frame_control = cpu_to_le16(IEEE80211_STYPE_ACTION); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1429 | memcpy(&mgmt_frame->u, frame, mgmt_frame_len); |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 1430 | mgmt_frame_len += offsetof(struct ieee80211_mgmt, u); |
| 1431 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 1432 | freq = ieee80211_channel_to_frequency(ch.chnum, |
| 1433 | ch.band == BRCMU_CHAN_BAND_2G ? |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 1434 | IEEE80211_BAND_2GHZ : |
| 1435 | IEEE80211_BAND_5GHZ); |
Arend van Spriel | 5b57af6 | 2013-04-05 10:57:53 +0200 | [diff] [blame] | 1436 | |
| 1437 | wdev = &ifp->vif->wdev; |
Vladimir Kondratiev | 970fdfa | 2014-08-11 03:29:57 -0700 | [diff] [blame] | 1438 | cfg80211_rx_mgmt(wdev, freq, 0, (u8 *)mgmt_frame, mgmt_frame_len, 0); |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 1439 | |
| 1440 | kfree(mgmt_frame); |
| 1441 | return 0; |
| 1442 | } |
| 1443 | |
| 1444 | |
| 1445 | /** |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1446 | * brcmf_p2p_notify_action_tx_complete() - transmit action frame complete |
| 1447 | * |
| 1448 | * @ifp: interfac control. |
| 1449 | * @e: event message. Not used, to make it usable for fweh event dispatcher. |
| 1450 | * @data: not used. |
| 1451 | * |
| 1452 | */ |
| 1453 | int brcmf_p2p_notify_action_tx_complete(struct brcmf_if *ifp, |
| 1454 | const struct brcmf_event_msg *e, |
| 1455 | void *data) |
| 1456 | { |
| 1457 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
| 1458 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
| 1459 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1460 | brcmf_dbg(INFO, "Enter: event %s, status=%d\n", |
| 1461 | e->event_code == BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE ? |
| 1462 | "ACTION_FRAME_OFF_CHAN_COMPLETE" : "ACTION_FRAME_COMPLETE", |
| 1463 | e->status); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1464 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1465 | if (!test_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME, &p2p->status)) |
| 1466 | return 0; |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1467 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1468 | if (e->event_code == BRCMF_E_ACTION_FRAME_COMPLETE) { |
| 1469 | if (e->status == BRCMF_E_STATUS_SUCCESS) |
| 1470 | set_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, |
| 1471 | &p2p->status); |
| 1472 | else { |
| 1473 | set_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status); |
| 1474 | /* If there is no ack, we don't need to wait for |
| 1475 | * WLC_E_ACTION_FRAME_OFFCHAN_COMPLETE event |
| 1476 | */ |
| 1477 | brcmf_p2p_stop_wait_next_action_frame(cfg); |
| 1478 | } |
| 1479 | |
| 1480 | } else { |
| 1481 | complete(&p2p->send_af_done); |
| 1482 | } |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1483 | return 0; |
| 1484 | } |
| 1485 | |
| 1486 | |
| 1487 | /** |
| 1488 | * brcmf_p2p_tx_action_frame() - send action frame over fil. |
| 1489 | * |
| 1490 | * @p2p: p2p info struct for vif. |
| 1491 | * @af_params: action frame data/info. |
| 1492 | * |
| 1493 | * Send an action frame immediately without doing channel synchronization. |
| 1494 | * |
| 1495 | * This function waits for a completion event before returning. |
| 1496 | * The WLC_E_ACTION_FRAME_COMPLETE event will be received when the action |
| 1497 | * frame is transmitted. |
| 1498 | */ |
| 1499 | static s32 brcmf_p2p_tx_action_frame(struct brcmf_p2p_info *p2p, |
| 1500 | struct brcmf_fil_af_params_le *af_params) |
| 1501 | { |
| 1502 | struct brcmf_cfg80211_vif *vif; |
| 1503 | s32 err = 0; |
| 1504 | s32 timeout = 0; |
| 1505 | |
| 1506 | brcmf_dbg(TRACE, "Enter\n"); |
| 1507 | |
Wolfram Sang | 16735d0 | 2013-11-14 14:32:02 -0800 | [diff] [blame] | 1508 | reinit_completion(&p2p->send_af_done); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1509 | clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status); |
| 1510 | clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status); |
| 1511 | |
| 1512 | vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif; |
| 1513 | err = brcmf_fil_bsscfg_data_set(vif->ifp, "actframe", af_params, |
| 1514 | sizeof(*af_params)); |
| 1515 | if (err) { |
| 1516 | brcmf_err(" sending action frame has failed\n"); |
| 1517 | goto exit; |
| 1518 | } |
| 1519 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1520 | p2p->af_sent_channel = le32_to_cpu(af_params->channel); |
| 1521 | p2p->af_tx_sent_jiffies = jiffies; |
| 1522 | |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1523 | timeout = wait_for_completion_timeout(&p2p->send_af_done, |
| 1524 | msecs_to_jiffies(P2P_AF_MAX_WAIT_TIME)); |
| 1525 | |
| 1526 | if (test_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status)) { |
| 1527 | brcmf_dbg(TRACE, "TX action frame operation is success\n"); |
| 1528 | } else { |
| 1529 | err = -EIO; |
| 1530 | brcmf_dbg(TRACE, "TX action frame operation has failed\n"); |
| 1531 | } |
| 1532 | /* clear status bit for action tx */ |
| 1533 | clear_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status); |
| 1534 | clear_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status); |
| 1535 | |
| 1536 | exit: |
| 1537 | return err; |
| 1538 | } |
| 1539 | |
| 1540 | |
| 1541 | /** |
| 1542 | * brcmf_p2p_pub_af_tx() - public action frame tx routine. |
| 1543 | * |
| 1544 | * @cfg: driver private data for cfg80211 interface. |
| 1545 | * @af_params: action frame data/info. |
| 1546 | * @config_af_params: configuration data for action frame. |
| 1547 | * |
| 1548 | * routine which transmits ation frame public type. |
| 1549 | */ |
| 1550 | static s32 brcmf_p2p_pub_af_tx(struct brcmf_cfg80211_info *cfg, |
| 1551 | struct brcmf_fil_af_params_le *af_params, |
| 1552 | struct brcmf_config_af_params *config_af_params) |
| 1553 | { |
| 1554 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
| 1555 | struct brcmf_fil_action_frame_le *action_frame; |
| 1556 | struct brcmf_p2p_pub_act_frame *act_frm; |
| 1557 | s32 err = 0; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1558 | u16 ie_len; |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1559 | |
| 1560 | action_frame = &af_params->action_frame; |
| 1561 | act_frm = (struct brcmf_p2p_pub_act_frame *)(action_frame->data); |
| 1562 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1563 | config_af_params->extra_listen = true; |
| 1564 | |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1565 | switch (act_frm->subtype) { |
| 1566 | case P2P_PAF_GON_REQ: |
| 1567 | brcmf_dbg(TRACE, "P2P: GO_NEG_PHASE status set\n"); |
| 1568 | set_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status); |
| 1569 | config_af_params->mpc_onoff = 0; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1570 | config_af_params->search_channel = true; |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1571 | p2p->next_af_subtype = act_frm->subtype + 1; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1572 | p2p->gon_req_action = true; |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1573 | /* increase dwell time to wait for RESP frame */ |
| 1574 | af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME); |
| 1575 | break; |
| 1576 | case P2P_PAF_GON_RSP: |
| 1577 | p2p->next_af_subtype = act_frm->subtype + 1; |
| 1578 | /* increase dwell time to wait for CONF frame */ |
| 1579 | af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME); |
| 1580 | break; |
| 1581 | case P2P_PAF_GON_CONF: |
| 1582 | /* If we reached till GO Neg confirmation reset the filter */ |
| 1583 | brcmf_dbg(TRACE, "P2P: GO_NEG_PHASE status cleared\n"); |
| 1584 | clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status); |
| 1585 | /* turn on mpc again if go nego is done */ |
| 1586 | config_af_params->mpc_onoff = 1; |
| 1587 | /* minimize dwell time */ |
| 1588 | af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1589 | config_af_params->extra_listen = false; |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1590 | break; |
| 1591 | case P2P_PAF_INVITE_REQ: |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1592 | config_af_params->search_channel = true; |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1593 | p2p->next_af_subtype = act_frm->subtype + 1; |
| 1594 | /* increase dwell time */ |
| 1595 | af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME); |
| 1596 | break; |
| 1597 | case P2P_PAF_INVITE_RSP: |
| 1598 | /* minimize dwell time */ |
| 1599 | af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1600 | config_af_params->extra_listen = false; |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1601 | break; |
| 1602 | case P2P_PAF_DEVDIS_REQ: |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1603 | config_af_params->search_channel = true; |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1604 | p2p->next_af_subtype = act_frm->subtype + 1; |
| 1605 | /* maximize dwell time to wait for RESP frame */ |
| 1606 | af_params->dwell_time = cpu_to_le32(P2P_AF_LONG_DWELL_TIME); |
| 1607 | break; |
| 1608 | case P2P_PAF_DEVDIS_RSP: |
| 1609 | /* minimize dwell time */ |
| 1610 | af_params->dwell_time = cpu_to_le32(P2P_AF_MIN_DWELL_TIME); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1611 | config_af_params->extra_listen = false; |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1612 | break; |
| 1613 | case P2P_PAF_PROVDIS_REQ: |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1614 | ie_len = le16_to_cpu(action_frame->len) - |
| 1615 | offsetof(struct brcmf_p2p_pub_act_frame, elts); |
| 1616 | if (cfg80211_get_p2p_attr(&act_frm->elts[0], ie_len, |
| 1617 | IEEE80211_P2P_ATTR_GROUP_ID, |
| 1618 | NULL, 0) < 0) |
| 1619 | config_af_params->search_channel = true; |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1620 | config_af_params->mpc_onoff = 0; |
| 1621 | p2p->next_af_subtype = act_frm->subtype + 1; |
| 1622 | /* increase dwell time to wait for RESP frame */ |
| 1623 | af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME); |
| 1624 | break; |
| 1625 | case P2P_PAF_PROVDIS_RSP: |
| 1626 | /* wpa_supplicant send go nego req right after prov disc */ |
| 1627 | p2p->next_af_subtype = P2P_PAF_GON_REQ; |
| 1628 | /* increase dwell time to MED level */ |
| 1629 | af_params->dwell_time = cpu_to_le32(P2P_AF_MED_DWELL_TIME); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1630 | config_af_params->extra_listen = false; |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1631 | break; |
| 1632 | default: |
| 1633 | brcmf_err("Unknown p2p pub act frame subtype: %d\n", |
| 1634 | act_frm->subtype); |
| 1635 | err = -EINVAL; |
| 1636 | } |
| 1637 | return err; |
| 1638 | } |
| 1639 | |
| 1640 | /** |
| 1641 | * brcmf_p2p_send_action_frame() - send action frame . |
| 1642 | * |
| 1643 | * @cfg: driver private data for cfg80211 interface. |
| 1644 | * @ndev: net device to transmit on. |
| 1645 | * @af_params: configuration data for action frame. |
| 1646 | */ |
| 1647 | bool brcmf_p2p_send_action_frame(struct brcmf_cfg80211_info *cfg, |
| 1648 | struct net_device *ndev, |
| 1649 | struct brcmf_fil_af_params_le *af_params) |
| 1650 | { |
| 1651 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1652 | struct brcmf_if *ifp = netdev_priv(ndev); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1653 | struct brcmf_fil_action_frame_le *action_frame; |
| 1654 | struct brcmf_config_af_params config_af_params; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1655 | struct afx_hdl *afx_hdl = &p2p->afx_hdl; |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1656 | u16 action_frame_len; |
| 1657 | bool ack = false; |
| 1658 | u8 category; |
| 1659 | u8 action; |
| 1660 | s32 tx_retry; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1661 | s32 extra_listen_time; |
| 1662 | uint delta_ms; |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1663 | |
| 1664 | action_frame = &af_params->action_frame; |
| 1665 | action_frame_len = le16_to_cpu(action_frame->len); |
| 1666 | |
| 1667 | brcmf_p2p_print_actframe(true, action_frame->data, action_frame_len); |
| 1668 | |
| 1669 | /* Add the default dwell time. Dwell time to stay off-channel */ |
| 1670 | /* to wait for a response action frame after transmitting an */ |
| 1671 | /* GO Negotiation action frame */ |
| 1672 | af_params->dwell_time = cpu_to_le32(P2P_AF_DWELL_TIME); |
| 1673 | |
| 1674 | category = action_frame->data[DOT11_ACTION_CAT_OFF]; |
| 1675 | action = action_frame->data[DOT11_ACTION_ACT_OFF]; |
| 1676 | |
| 1677 | /* initialize variables */ |
| 1678 | p2p->next_af_subtype = P2P_PAF_SUBTYPE_INVALID; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1679 | p2p->gon_req_action = false; |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1680 | |
| 1681 | /* config parameters */ |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1682 | config_af_params.mpc_onoff = -1; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1683 | config_af_params.search_channel = false; |
| 1684 | config_af_params.extra_listen = false; |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1685 | |
| 1686 | if (brcmf_p2p_is_pub_action(action_frame->data, action_frame_len)) { |
| 1687 | /* p2p public action frame process */ |
| 1688 | if (brcmf_p2p_pub_af_tx(cfg, af_params, &config_af_params)) { |
| 1689 | /* Just send unknown subtype frame with */ |
| 1690 | /* default parameters. */ |
| 1691 | brcmf_err("P2P Public action frame, unknown subtype.\n"); |
| 1692 | } |
| 1693 | } else if (brcmf_p2p_is_gas_action(action_frame->data, |
| 1694 | action_frame_len)) { |
| 1695 | /* service discovery process */ |
| 1696 | if (action == P2PSD_ACTION_ID_GAS_IREQ || |
| 1697 | action == P2PSD_ACTION_ID_GAS_CREQ) { |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1698 | /* configure service discovery query frame */ |
| 1699 | config_af_params.search_channel = true; |
| 1700 | |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1701 | /* save next af suptype to cancel */ |
| 1702 | /* remaining dwell time */ |
| 1703 | p2p->next_af_subtype = action + 1; |
| 1704 | |
| 1705 | af_params->dwell_time = |
| 1706 | cpu_to_le32(P2P_AF_MED_DWELL_TIME); |
| 1707 | } else if (action == P2PSD_ACTION_ID_GAS_IRESP || |
| 1708 | action == P2PSD_ACTION_ID_GAS_CRESP) { |
| 1709 | /* configure service discovery response frame */ |
| 1710 | af_params->dwell_time = |
| 1711 | cpu_to_le32(P2P_AF_MIN_DWELL_TIME); |
| 1712 | } else { |
| 1713 | brcmf_err("Unknown action type: %d\n", action); |
| 1714 | goto exit; |
| 1715 | } |
| 1716 | } else if (brcmf_p2p_is_p2p_action(action_frame->data, |
| 1717 | action_frame_len)) { |
| 1718 | /* do not configure anything. it will be */ |
| 1719 | /* sent with a default configuration */ |
| 1720 | } else { |
| 1721 | brcmf_err("Unknown Frame: category 0x%x, action 0x%x\n", |
| 1722 | category, action); |
| 1723 | return false; |
| 1724 | } |
| 1725 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1726 | /* if connecting on primary iface, sleep for a while before sending |
| 1727 | * af tx for VSDB |
| 1728 | */ |
| 1729 | if (test_bit(BRCMF_VIF_STATUS_CONNECTING, |
| 1730 | &p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->sme_state)) |
| 1731 | msleep(50); |
| 1732 | |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1733 | /* if scan is ongoing, abort current scan. */ |
| 1734 | if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) |
| 1735 | brcmf_abort_scanning(cfg); |
| 1736 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1737 | memcpy(afx_hdl->tx_dst_addr, action_frame->da, ETH_ALEN); |
| 1738 | |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1739 | /* To make sure to send successfully action frame, turn off mpc */ |
| 1740 | if (config_af_params.mpc_onoff == 0) |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1741 | brcmf_set_mpc(ifp, 0); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1742 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1743 | /* set status and destination address before sending af */ |
| 1744 | if (p2p->next_af_subtype != P2P_PAF_SUBTYPE_INVALID) { |
| 1745 | /* set status to cancel the remained dwell time in rx process */ |
| 1746 | set_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, &p2p->status); |
| 1747 | } |
| 1748 | |
| 1749 | p2p->af_sent_channel = 0; |
| 1750 | set_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME, &p2p->status); |
| 1751 | /* validate channel and p2p ies */ |
| 1752 | if (config_af_params.search_channel && |
| 1753 | IS_P2P_SOCIAL_CHANNEL(le32_to_cpu(af_params->channel)) && |
| 1754 | p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif->saved_ie.probe_req_ie_len) { |
| 1755 | afx_hdl = &p2p->afx_hdl; |
| 1756 | afx_hdl->peer_listen_chan = le32_to_cpu(af_params->channel); |
| 1757 | |
| 1758 | if (brcmf_p2p_af_searching_channel(p2p) == |
| 1759 | P2P_INVALID_CHANNEL) { |
| 1760 | brcmf_err("Couldn't find peer's channel.\n"); |
| 1761 | goto exit; |
| 1762 | } |
| 1763 | |
| 1764 | /* Abort scan even for VSDB scenarios. Scan gets aborted in |
| 1765 | * firmware but after the check of piggyback algorithm. To take |
| 1766 | * care of current piggback algo, lets abort the scan here |
| 1767 | * itself. |
| 1768 | */ |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1769 | brcmf_notify_escan_complete(cfg, ifp, true, true); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1770 | |
| 1771 | /* update channel */ |
| 1772 | af_params->channel = cpu_to_le32(afx_hdl->peer_chan); |
| 1773 | } |
| 1774 | |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1775 | tx_retry = 0; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1776 | while (!p2p->block_gon_req_tx && |
| 1777 | (ack == false) && (tx_retry < P2P_AF_TX_MAX_RETRY)) { |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1778 | ack = !brcmf_p2p_tx_action_frame(p2p, af_params); |
| 1779 | tx_retry++; |
| 1780 | } |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1781 | if (ack == false) { |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1782 | brcmf_err("Failed to send Action Frame(retry %d)\n", tx_retry); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1783 | clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status); |
| 1784 | } |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1785 | |
| 1786 | exit: |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1787 | clear_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME, &p2p->status); |
| 1788 | |
| 1789 | /* WAR: sometimes dongle does not keep the dwell time of 'actframe'. |
| 1790 | * if we coundn't get the next action response frame and dongle does |
| 1791 | * not keep the dwell time, go to listen state again to get next action |
| 1792 | * response frame. |
| 1793 | */ |
| 1794 | if (ack && config_af_params.extra_listen && !p2p->block_gon_req_tx && |
| 1795 | test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, &p2p->status) && |
| 1796 | p2p->af_sent_channel == afx_hdl->my_listen_chan) { |
| 1797 | delta_ms = jiffies_to_msecs(jiffies - p2p->af_tx_sent_jiffies); |
| 1798 | if (le32_to_cpu(af_params->dwell_time) > delta_ms) |
| 1799 | extra_listen_time = le32_to_cpu(af_params->dwell_time) - |
| 1800 | delta_ms; |
| 1801 | else |
| 1802 | extra_listen_time = 0; |
| 1803 | if (extra_listen_time > 50) { |
| 1804 | set_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN, |
| 1805 | &p2p->status); |
| 1806 | brcmf_dbg(INFO, "Wait more time! actual af time:%d, calculated extra listen:%d\n", |
| 1807 | le32_to_cpu(af_params->dwell_time), |
| 1808 | extra_listen_time); |
| 1809 | extra_listen_time += 100; |
| 1810 | if (!brcmf_p2p_discover_listen(p2p, |
| 1811 | p2p->af_sent_channel, |
| 1812 | extra_listen_time)) { |
| 1813 | unsigned long duration; |
| 1814 | |
| 1815 | extra_listen_time += 100; |
| 1816 | duration = msecs_to_jiffies(extra_listen_time); |
| 1817 | wait_for_completion_timeout(&p2p->wait_next_af, |
| 1818 | duration); |
| 1819 | } |
| 1820 | clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN, |
| 1821 | &p2p->status); |
| 1822 | } |
| 1823 | } |
| 1824 | |
| 1825 | if (p2p->block_gon_req_tx) { |
| 1826 | /* if ack is true, supplicant will wait more time(100ms). |
| 1827 | * so we will return it as a success to get more time . |
| 1828 | */ |
| 1829 | p2p->block_gon_req_tx = false; |
| 1830 | ack = true; |
| 1831 | } |
| 1832 | |
| 1833 | clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, &p2p->status); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1834 | /* if all done, turn mpc on again */ |
| 1835 | if (config_af_params.mpc_onoff == 1) |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1836 | brcmf_set_mpc(ifp, 1); |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1837 | |
| 1838 | return ack; |
| 1839 | } |
| 1840 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1841 | /** |
| 1842 | * brcmf_p2p_notify_rx_mgmt_p2p_probereq() - Event handler for p2p probe req. |
| 1843 | * |
| 1844 | * @ifp: interface pointer for which event was received. |
| 1845 | * @e: even message. |
| 1846 | * @data: payload of event message (probe request). |
| 1847 | */ |
| 1848 | s32 brcmf_p2p_notify_rx_mgmt_p2p_probereq(struct brcmf_if *ifp, |
| 1849 | const struct brcmf_event_msg *e, |
| 1850 | void *data) |
| 1851 | { |
| 1852 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
| 1853 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
| 1854 | struct afx_hdl *afx_hdl = &p2p->afx_hdl; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1855 | struct brcmf_cfg80211_vif *vif = ifp->vif; |
| 1856 | struct brcmf_rx_mgmt_data *rxframe = (struct brcmf_rx_mgmt_data *)data; |
| 1857 | u16 chanspec = be16_to_cpu(rxframe->chanspec); |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 1858 | struct brcmu_chan ch; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1859 | u8 *mgmt_frame; |
| 1860 | u32 mgmt_frame_len; |
| 1861 | s32 freq; |
| 1862 | u16 mgmt_type; |
| 1863 | |
| 1864 | brcmf_dbg(INFO, "Enter: event %d reason %d\n", e->event_code, |
| 1865 | e->reason); |
| 1866 | |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 1867 | ch.chspec = be16_to_cpu(rxframe->chanspec); |
| 1868 | cfg->d11inf.decchspec(&ch); |
| 1869 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1870 | if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, &p2p->status) && |
dingtianhong | 692e516 | 2013-12-26 19:41:34 +0800 | [diff] [blame] | 1871 | (ether_addr_equal(afx_hdl->tx_dst_addr, e->addr))) { |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 1872 | afx_hdl->peer_chan = ch.chnum; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1873 | brcmf_dbg(INFO, "PROBE REQUEST: Peer found, channel=%d\n", |
| 1874 | afx_hdl->peer_chan); |
| 1875 | complete(&afx_hdl->act_frm_scan); |
| 1876 | } |
| 1877 | |
| 1878 | /* Firmware sends us two proberesponses for each idx one. At the */ |
| 1879 | /* moment anything but bsscfgidx 0 is passed up to supplicant */ |
| 1880 | if (e->bsscfgidx == 0) |
| 1881 | return 0; |
| 1882 | |
| 1883 | /* Filter any P2P probe reqs arriving during the GO-NEG Phase */ |
| 1884 | if (test_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status)) { |
| 1885 | brcmf_dbg(INFO, "Filtering P2P probe_req in GO-NEG phase\n"); |
| 1886 | return 0; |
| 1887 | } |
| 1888 | |
| 1889 | /* Check if wpa_supplicant has registered for this frame */ |
| 1890 | brcmf_dbg(INFO, "vif->mgmt_rx_reg %04x\n", vif->mgmt_rx_reg); |
| 1891 | mgmt_type = (IEEE80211_STYPE_PROBE_REQ & IEEE80211_FCTL_STYPE) >> 4; |
| 1892 | if ((vif->mgmt_rx_reg & BIT(mgmt_type)) == 0) |
| 1893 | return 0; |
| 1894 | |
| 1895 | mgmt_frame = (u8 *)(rxframe + 1); |
| 1896 | mgmt_frame_len = e->datalen - sizeof(*rxframe); |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 1897 | freq = ieee80211_channel_to_frequency(ch.chnum, |
| 1898 | ch.band == BRCMU_CHAN_BAND_2G ? |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1899 | IEEE80211_BAND_2GHZ : |
| 1900 | IEEE80211_BAND_5GHZ); |
Arend van Spriel | bffc61c | 2013-04-05 10:57:52 +0200 | [diff] [blame] | 1901 | |
Vladimir Kondratiev | 970fdfa | 2014-08-11 03:29:57 -0700 | [diff] [blame] | 1902 | cfg80211_rx_mgmt(&vif->wdev, freq, 0, mgmt_frame, mgmt_frame_len, 0); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1903 | |
| 1904 | brcmf_dbg(INFO, "mgmt_frame_len (%d) , e->datalen (%d), chanspec (%04x), freq (%d)\n", |
| 1905 | mgmt_frame_len, e->datalen, chanspec, freq); |
| 1906 | |
| 1907 | return 0; |
| 1908 | } |
| 1909 | |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1910 | |
| 1911 | /** |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 1912 | * brcmf_p2p_get_current_chanspec() - Get current operation channel. |
| 1913 | * |
| 1914 | * @p2p: P2P specific data. |
| 1915 | * @chanspec: chanspec to be returned. |
| 1916 | */ |
| 1917 | static void brcmf_p2p_get_current_chanspec(struct brcmf_p2p_info *p2p, |
| 1918 | u16 *chanspec) |
| 1919 | { |
| 1920 | struct brcmf_if *ifp; |
Hante Meuleman | 15a953d | 2013-05-27 21:09:54 +0200 | [diff] [blame] | 1921 | u8 mac_addr[ETH_ALEN]; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 1922 | struct brcmu_chan ch; |
Hante Meuleman | 15a953d | 2013-05-27 21:09:54 +0200 | [diff] [blame] | 1923 | struct brcmf_bss_info_le *bi; |
| 1924 | u8 *buf; |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 1925 | |
| 1926 | ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp; |
| 1927 | |
Hante Meuleman | 15a953d | 2013-05-27 21:09:54 +0200 | [diff] [blame] | 1928 | if (brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSSID, mac_addr, |
| 1929 | ETH_ALEN) == 0) { |
| 1930 | buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL); |
| 1931 | if (buf != NULL) { |
| 1932 | *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX); |
| 1933 | if (brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO, |
| 1934 | buf, WL_BSS_INFO_MAX) == 0) { |
| 1935 | bi = (struct brcmf_bss_info_le *)(buf + 4); |
| 1936 | *chanspec = le16_to_cpu(bi->chanspec); |
| 1937 | kfree(buf); |
| 1938 | return; |
| 1939 | } |
| 1940 | kfree(buf); |
| 1941 | } |
| 1942 | } |
| 1943 | /* Use default channel for P2P */ |
| 1944 | ch.chnum = BRCMF_P2P_TEMP_CHAN; |
Franky Lin | 83cf17a | 2013-04-11 13:28:50 +0200 | [diff] [blame] | 1945 | ch.bw = BRCMU_CHAN_BW_20; |
| 1946 | p2p->cfg->d11inf.encchspec(&ch); |
| 1947 | *chanspec = ch.chspec; |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | /** |
| 1951 | * Change a P2P Role. |
| 1952 | * Parameters: |
| 1953 | * @mac: MAC address of the BSS to change a role |
| 1954 | * Returns 0 if success. |
| 1955 | */ |
| 1956 | int brcmf_p2p_ifchange(struct brcmf_cfg80211_info *cfg, |
| 1957 | enum brcmf_fil_p2p_if_types if_type) |
| 1958 | { |
| 1959 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
| 1960 | struct brcmf_cfg80211_vif *vif; |
| 1961 | struct brcmf_fil_p2p_if_le if_request; |
| 1962 | s32 err; |
| 1963 | u16 chanspec; |
| 1964 | |
| 1965 | brcmf_dbg(TRACE, "Enter\n"); |
| 1966 | |
| 1967 | vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif; |
| 1968 | if (!vif) { |
| 1969 | brcmf_err("vif for P2PAPI_BSSCFG_PRIMARY does not exist\n"); |
| 1970 | return -EPERM; |
| 1971 | } |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1972 | brcmf_notify_escan_complete(cfg, vif->ifp, true, true); |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 1973 | vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif; |
| 1974 | if (!vif) { |
| 1975 | brcmf_err("vif for P2PAPI_BSSCFG_CONNECTION does not exist\n"); |
| 1976 | return -EPERM; |
| 1977 | } |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 1978 | brcmf_set_mpc(vif->ifp, 0); |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 1979 | |
| 1980 | /* In concurrency case, STA may be already associated in a particular */ |
| 1981 | /* channel. so retrieve the current channel of primary interface and */ |
| 1982 | /* then start the virtual interface on that. */ |
| 1983 | brcmf_p2p_get_current_chanspec(p2p, &chanspec); |
| 1984 | |
| 1985 | if_request.type = cpu_to_le16((u16)if_type); |
| 1986 | if_request.chspec = cpu_to_le16(chanspec); |
| 1987 | memcpy(if_request.addr, p2p->int_addr, sizeof(if_request.addr)); |
| 1988 | |
| 1989 | brcmf_cfg80211_arm_vif_event(cfg, vif); |
| 1990 | err = brcmf_fil_iovar_data_set(vif->ifp, "p2p_ifupd", &if_request, |
| 1991 | sizeof(if_request)); |
| 1992 | if (err) { |
| 1993 | brcmf_err("p2p_ifupd FAILED, err=%d\n", err); |
| 1994 | brcmf_cfg80211_arm_vif_event(cfg, NULL); |
| 1995 | return err; |
| 1996 | } |
| 1997 | err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_CHANGE, |
| 1998 | msecs_to_jiffies(1500)); |
| 1999 | brcmf_cfg80211_arm_vif_event(cfg, NULL); |
| 2000 | if (!err) { |
| 2001 | brcmf_err("No BRCMF_E_IF_CHANGE event received\n"); |
| 2002 | return -EIO; |
| 2003 | } |
| 2004 | |
| 2005 | err = brcmf_fil_cmd_int_set(vif->ifp, BRCMF_C_SET_SCB_TIMEOUT, |
| 2006 | BRCMF_SCB_TIMEOUT_VALUE); |
| 2007 | |
| 2008 | return err; |
| 2009 | } |
| 2010 | |
| 2011 | static int brcmf_p2p_request_p2p_if(struct brcmf_p2p_info *p2p, |
| 2012 | struct brcmf_if *ifp, u8 ea[ETH_ALEN], |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2013 | enum brcmf_fil_p2p_if_types iftype) |
| 2014 | { |
| 2015 | struct brcmf_fil_p2p_if_le if_request; |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2016 | int err; |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 2017 | u16 chanspec; |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2018 | |
| 2019 | /* we need a default channel */ |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 2020 | brcmf_p2p_get_current_chanspec(p2p, &chanspec); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2021 | |
| 2022 | /* fill the firmware request */ |
| 2023 | memcpy(if_request.addr, ea, ETH_ALEN); |
Hante Meuleman | 7ee2d92 | 2013-02-08 15:53:43 +0100 | [diff] [blame] | 2024 | if_request.type = cpu_to_le16((u16)iftype); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2025 | if_request.chspec = cpu_to_le16(chanspec); |
| 2026 | |
| 2027 | err = brcmf_fil_iovar_data_set(ifp, "p2p_ifadd", &if_request, |
| 2028 | sizeof(if_request)); |
| 2029 | if (err) |
| 2030 | return err; |
| 2031 | |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2032 | return err; |
| 2033 | } |
| 2034 | |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 2035 | static int brcmf_p2p_disable_p2p_if(struct brcmf_cfg80211_vif *vif) |
| 2036 | { |
| 2037 | struct brcmf_cfg80211_info *cfg = wdev_to_cfg(&vif->wdev); |
| 2038 | struct net_device *pri_ndev = cfg_to_ndev(cfg); |
| 2039 | struct brcmf_if *ifp = netdev_priv(pri_ndev); |
| 2040 | u8 *addr = vif->wdev.netdev->dev_addr; |
| 2041 | |
| 2042 | return brcmf_fil_iovar_data_set(ifp, "p2p_ifdis", addr, ETH_ALEN); |
| 2043 | } |
| 2044 | |
| 2045 | static int brcmf_p2p_release_p2p_if(struct brcmf_cfg80211_vif *vif) |
| 2046 | { |
| 2047 | struct brcmf_cfg80211_info *cfg = wdev_to_cfg(&vif->wdev); |
| 2048 | struct net_device *pri_ndev = cfg_to_ndev(cfg); |
| 2049 | struct brcmf_if *ifp = netdev_priv(pri_ndev); |
| 2050 | u8 *addr = vif->wdev.netdev->dev_addr; |
| 2051 | |
| 2052 | return brcmf_fil_iovar_data_set(ifp, "p2p_ifdel", addr, ETH_ALEN); |
| 2053 | } |
| 2054 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 2055 | /** |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 2056 | * brcmf_p2p_create_p2pdev() - create a P2P_DEVICE virtual interface. |
| 2057 | * |
| 2058 | * @p2p: P2P specific data. |
| 2059 | * @wiphy: wiphy device of new interface. |
| 2060 | * @addr: mac address for this new interface. |
| 2061 | */ |
| 2062 | static struct wireless_dev *brcmf_p2p_create_p2pdev(struct brcmf_p2p_info *p2p, |
| 2063 | struct wiphy *wiphy, |
| 2064 | u8 *addr) |
| 2065 | { |
| 2066 | struct brcmf_cfg80211_vif *p2p_vif; |
| 2067 | struct brcmf_if *p2p_ifp; |
| 2068 | struct brcmf_if *pri_ifp; |
| 2069 | int err; |
| 2070 | u32 bssidx; |
| 2071 | |
| 2072 | if (p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif) |
| 2073 | return ERR_PTR(-ENOSPC); |
| 2074 | |
| 2075 | p2p_vif = brcmf_alloc_vif(p2p->cfg, NL80211_IFTYPE_P2P_DEVICE, |
| 2076 | false); |
| 2077 | if (IS_ERR(p2p_vif)) { |
| 2078 | brcmf_err("could not create discovery vif\n"); |
| 2079 | return (struct wireless_dev *)p2p_vif; |
| 2080 | } |
| 2081 | |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 2082 | pri_ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp; |
Arend van Spriel | 01b8e7d | 2013-04-05 10:57:51 +0200 | [diff] [blame] | 2083 | brcmf_p2p_generate_bss_mac(p2p, addr); |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 2084 | brcmf_p2p_set_firmware(pri_ifp, p2p->dev_addr); |
| 2085 | |
Arend van Spriel | 01b8e7d | 2013-04-05 10:57:51 +0200 | [diff] [blame] | 2086 | brcmf_cfg80211_arm_vif_event(p2p->cfg, p2p_vif); |
| 2087 | |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 2088 | /* Initialize P2P Discovery in the firmware */ |
| 2089 | err = brcmf_fil_iovar_int_set(pri_ifp, "p2p_disc", 1); |
| 2090 | if (err < 0) { |
| 2091 | brcmf_err("set p2p_disc error\n"); |
Arend van Spriel | 01b8e7d | 2013-04-05 10:57:51 +0200 | [diff] [blame] | 2092 | brcmf_cfg80211_arm_vif_event(p2p->cfg, NULL); |
| 2093 | goto fail; |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 2094 | } |
Arend van Spriel | 01b8e7d | 2013-04-05 10:57:51 +0200 | [diff] [blame] | 2095 | |
| 2096 | /* wait for firmware event */ |
| 2097 | err = brcmf_cfg80211_wait_vif_event_timeout(p2p->cfg, BRCMF_E_IF_ADD, |
| 2098 | msecs_to_jiffies(1500)); |
| 2099 | brcmf_cfg80211_arm_vif_event(p2p->cfg, NULL); |
| 2100 | if (!err) { |
| 2101 | brcmf_err("timeout occurred\n"); |
| 2102 | err = -EIO; |
| 2103 | goto fail; |
| 2104 | } |
| 2105 | |
| 2106 | /* discovery interface created */ |
| 2107 | p2p_ifp = p2p_vif->ifp; |
| 2108 | p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif = p2p_vif; |
| 2109 | memcpy(p2p_ifp->mac_addr, p2p->dev_addr, ETH_ALEN); |
| 2110 | memcpy(&p2p_vif->wdev.address, p2p->dev_addr, sizeof(p2p->dev_addr)); |
| 2111 | |
| 2112 | /* verify bsscfg index for P2P discovery */ |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 2113 | err = brcmf_fil_iovar_int_get(pri_ifp, "p2p_dev", &bssidx); |
| 2114 | if (err < 0) { |
| 2115 | brcmf_err("retrieving discover bsscfg index failed\n"); |
Arend van Spriel | 01b8e7d | 2013-04-05 10:57:51 +0200 | [diff] [blame] | 2116 | goto fail; |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 2117 | } |
| 2118 | |
Arend van Spriel | 01b8e7d | 2013-04-05 10:57:51 +0200 | [diff] [blame] | 2119 | WARN_ON(p2p_ifp->bssidx != bssidx); |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 2120 | |
| 2121 | init_completion(&p2p->send_af_done); |
| 2122 | INIT_WORK(&p2p->afx_hdl.afx_work, brcmf_p2p_afx_handler); |
| 2123 | init_completion(&p2p->afx_hdl.act_frm_scan); |
| 2124 | init_completion(&p2p->wait_next_af); |
| 2125 | |
| 2126 | return &p2p_vif->wdev; |
Arend van Spriel | 01b8e7d | 2013-04-05 10:57:51 +0200 | [diff] [blame] | 2127 | |
| 2128 | fail: |
Arend van Spriel | 427dec5 | 2014-01-06 12:40:47 +0100 | [diff] [blame] | 2129 | brcmf_free_vif(p2p_vif); |
Arend van Spriel | 01b8e7d | 2013-04-05 10:57:51 +0200 | [diff] [blame] | 2130 | return ERR_PTR(err); |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | /** |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 2134 | * brcmf_p2p_add_vif() - create a new P2P virtual interface. |
| 2135 | * |
| 2136 | * @wiphy: wiphy device of new interface. |
| 2137 | * @name: name of the new interface. |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 2138 | * @name_assign_type: origin of the interface name |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 2139 | * @type: nl80211 interface type. |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 2140 | * @flags: not used. |
| 2141 | * @params: contains mac address for P2P device. |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 2142 | */ |
| 2143 | struct wireless_dev *brcmf_p2p_add_vif(struct wiphy *wiphy, const char *name, |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 2144 | unsigned char name_assign_type, |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 2145 | enum nl80211_iftype type, u32 *flags, |
| 2146 | struct vif_params *params) |
| 2147 | { |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2148 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 2149 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
| 2150 | struct brcmf_cfg80211_vif *vif; |
| 2151 | enum brcmf_fil_p2p_if_types iftype; |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2152 | int err; |
| 2153 | |
| 2154 | if (brcmf_cfg80211_vif_event_armed(cfg)) |
| 2155 | return ERR_PTR(-EBUSY); |
| 2156 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 2157 | brcmf_dbg(INFO, "adding vif \"%s\" (type=%d)\n", name, type); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2158 | |
| 2159 | switch (type) { |
| 2160 | case NL80211_IFTYPE_P2P_CLIENT: |
| 2161 | iftype = BRCMF_FIL_P2P_IF_CLIENT; |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2162 | break; |
| 2163 | case NL80211_IFTYPE_P2P_GO: |
| 2164 | iftype = BRCMF_FIL_P2P_IF_GO; |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2165 | break; |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 2166 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2167 | return brcmf_p2p_create_p2pdev(&cfg->p2p, wiphy, |
| 2168 | params->macaddr); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2169 | default: |
| 2170 | return ERR_PTR(-EOPNOTSUPP); |
| 2171 | } |
| 2172 | |
| 2173 | vif = brcmf_alloc_vif(cfg, type, false); |
Hante Meuleman | 7ee2d92 | 2013-02-08 15:53:43 +0100 | [diff] [blame] | 2174 | if (IS_ERR(vif)) |
| 2175 | return (struct wireless_dev *)vif; |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2176 | brcmf_cfg80211_arm_vif_event(cfg, vif); |
| 2177 | |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 2178 | err = brcmf_p2p_request_p2p_if(&cfg->p2p, ifp, cfg->p2p.int_addr, |
| 2179 | iftype); |
Hante Meuleman | 7ee2d92 | 2013-02-08 15:53:43 +0100 | [diff] [blame] | 2180 | if (err) { |
| 2181 | brcmf_cfg80211_arm_vif_event(cfg, NULL); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2182 | goto fail; |
Hante Meuleman | 7ee2d92 | 2013-02-08 15:53:43 +0100 | [diff] [blame] | 2183 | } |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2184 | |
| 2185 | /* wait for firmware event */ |
| 2186 | err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_ADD, |
| 2187 | msecs_to_jiffies(1500)); |
| 2188 | brcmf_cfg80211_arm_vif_event(cfg, NULL); |
| 2189 | if (!err) { |
| 2190 | brcmf_err("timeout occurred\n"); |
| 2191 | err = -EIO; |
| 2192 | goto fail; |
| 2193 | } |
| 2194 | |
| 2195 | /* interface created in firmware */ |
| 2196 | ifp = vif->ifp; |
| 2197 | if (!ifp) { |
| 2198 | brcmf_err("no if pointer provided\n"); |
| 2199 | err = -ENOENT; |
Hante Meuleman | 7ee2d92 | 2013-02-08 15:53:43 +0100 | [diff] [blame] | 2200 | goto fail; |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2201 | } |
| 2202 | |
| 2203 | strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1); |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 2204 | ifp->ndev->name_assign_type = name_assign_type; |
Hante Meuleman | 4b3a89d | 2013-02-08 15:54:01 +0100 | [diff] [blame] | 2205 | err = brcmf_net_attach(ifp, true); |
| 2206 | if (err) { |
| 2207 | brcmf_err("Registering netdevice failed\n"); |
| 2208 | goto fail; |
| 2209 | } |
Arend van Spriel | cbb371d | 2013-05-27 21:09:57 +0200 | [diff] [blame] | 2210 | |
Hante Meuleman | 7ee2d92 | 2013-02-08 15:53:43 +0100 | [diff] [blame] | 2211 | cfg->p2p.bss_idx[P2PAPI_BSSCFG_CONNECTION].vif = vif; |
| 2212 | /* Disable firmware roaming for P2P interface */ |
| 2213 | brcmf_fil_iovar_int_set(ifp, "roam_off", 1); |
| 2214 | if (iftype == BRCMF_FIL_P2P_IF_GO) { |
| 2215 | /* set station timeout for p2p */ |
| 2216 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCB_TIMEOUT, |
| 2217 | BRCMF_SCB_TIMEOUT_VALUE); |
| 2218 | } |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2219 | return &ifp->vif->wdev; |
| 2220 | |
| 2221 | fail: |
Arend van Spriel | 427dec5 | 2014-01-06 12:40:47 +0100 | [diff] [blame] | 2222 | brcmf_free_vif(vif); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2223 | return ERR_PTR(err); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 2224 | } |
| 2225 | |
| 2226 | /** |
| 2227 | * brcmf_p2p_del_vif() - delete a P2P virtual interface. |
| 2228 | * |
| 2229 | * @wiphy: wiphy device of interface. |
| 2230 | * @wdev: wireless device of interface. |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 2231 | */ |
| 2232 | int brcmf_p2p_del_vif(struct wiphy *wiphy, struct wireless_dev *wdev) |
| 2233 | { |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2234 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 2235 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 2236 | struct brcmf_cfg80211_vif *vif; |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 2237 | unsigned long jiffie_timeout = msecs_to_jiffies(1500); |
| 2238 | bool wait_for_disable = false; |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2239 | int err; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 2240 | |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 2241 | brcmf_dbg(TRACE, "delete P2P vif\n"); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 2242 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2243 | |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 2244 | switch (vif->wdev.iftype) { |
| 2245 | case NL80211_IFTYPE_P2P_CLIENT: |
| 2246 | if (test_bit(BRCMF_VIF_STATUS_DISCONNECTING, &vif->sme_state)) |
| 2247 | wait_for_disable = true; |
| 2248 | break; |
| 2249 | |
| 2250 | case NL80211_IFTYPE_P2P_GO: |
| 2251 | if (!brcmf_p2p_disable_p2p_if(vif)) |
| 2252 | wait_for_disable = true; |
| 2253 | break; |
| 2254 | |
| 2255 | case NL80211_IFTYPE_P2P_DEVICE: |
Hante Meuleman | 9831bcb | 2015-09-18 22:08:12 +0200 | [diff] [blame] | 2256 | if (!p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif) |
| 2257 | return 0; |
Arend van Spriel | f37d69a | 2015-06-11 00:12:21 +0200 | [diff] [blame] | 2258 | brcmf_p2p_cancel_remain_on_channel(vif->ifp); |
| 2259 | brcmf_p2p_deinit_discovery(p2p); |
Hante Meuleman | 9831bcb | 2015-09-18 22:08:12 +0200 | [diff] [blame] | 2260 | brcmf_remove_interface(vif->ifp); |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 2261 | return 0; |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 2262 | default: |
| 2263 | return -ENOTSUPP; |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 2264 | } |
| 2265 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 2266 | clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status); |
| 2267 | brcmf_dbg(INFO, "P2P: GO_NEG_PHASE status cleared\n"); |
| 2268 | |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 2269 | if (wait_for_disable) |
Hante Meuleman | 7ee2d92 | 2013-02-08 15:53:43 +0100 | [diff] [blame] | 2270 | wait_for_completion_timeout(&cfg->vif_disabled, |
| 2271 | msecs_to_jiffies(500)); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 2272 | |
| 2273 | brcmf_vif_clear_mgmt_ies(vif); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2274 | |
| 2275 | brcmf_cfg80211_arm_vif_event(cfg, vif); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 2276 | err = brcmf_p2p_release_p2p_if(vif); |
Hante Meuleman | 7ee2d92 | 2013-02-08 15:53:43 +0100 | [diff] [blame] | 2277 | if (!err) { |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 2278 | /* wait for firmware event */ |
| 2279 | err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_DEL, |
| 2280 | jiffie_timeout); |
Hante Meuleman | 7ee2d92 | 2013-02-08 15:53:43 +0100 | [diff] [blame] | 2281 | if (!err) |
| 2282 | err = -EIO; |
| 2283 | else |
| 2284 | err = 0; |
| 2285 | } |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2286 | brcmf_cfg80211_arm_vif_event(cfg, NULL); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 2287 | p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif = NULL; |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 2288 | |
| 2289 | return err; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 2290 | } |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 2291 | |
Hante Meuleman | 9831bcb | 2015-09-18 22:08:12 +0200 | [diff] [blame] | 2292 | void brcmf_p2p_ifp_removed(struct brcmf_if *ifp) |
| 2293 | { |
| 2294 | struct brcmf_cfg80211_info *cfg; |
| 2295 | struct brcmf_cfg80211_vif *vif; |
| 2296 | |
| 2297 | brcmf_dbg(INFO, "P2P: device interface removed\n"); |
| 2298 | vif = ifp->vif; |
| 2299 | cfg = wdev_to_cfg(&vif->wdev); |
| 2300 | cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif = NULL; |
| 2301 | rtnl_lock(); |
| 2302 | cfg80211_unregister_wdev(&vif->wdev); |
| 2303 | rtnl_unlock(); |
| 2304 | brcmf_free_vif(vif); |
| 2305 | } |
| 2306 | |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 2307 | int brcmf_p2p_start_device(struct wiphy *wiphy, struct wireless_dev *wdev) |
| 2308 | { |
| 2309 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 2310 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
| 2311 | struct brcmf_cfg80211_vif *vif; |
| 2312 | int err; |
| 2313 | |
| 2314 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
| 2315 | mutex_lock(&cfg->usr_sync); |
| 2316 | err = brcmf_p2p_enable_discovery(p2p); |
| 2317 | if (!err) |
| 2318 | set_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state); |
| 2319 | mutex_unlock(&cfg->usr_sync); |
| 2320 | return err; |
| 2321 | } |
| 2322 | |
| 2323 | void brcmf_p2p_stop_device(struct wiphy *wiphy, struct wireless_dev *wdev) |
| 2324 | { |
| 2325 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 2326 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
| 2327 | struct brcmf_cfg80211_vif *vif; |
| 2328 | |
| 2329 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
Hante Meuleman | d1bb34c | 2015-09-18 22:08:13 +0200 | [diff] [blame^] | 2330 | /* This call can be result of the unregister_wdev call. In that case |
| 2331 | * we dont want to do anything anymore. Just return. The config vif |
| 2332 | * will have been cleared at this point. |
| 2333 | */ |
| 2334 | if (p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif == vif) { |
| 2335 | mutex_lock(&cfg->usr_sync); |
| 2336 | (void)brcmf_p2p_deinit_discovery(p2p); |
| 2337 | brcmf_abort_scanning(cfg); |
| 2338 | clear_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state); |
| 2339 | mutex_unlock(&cfg->usr_sync); |
| 2340 | } |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame] | 2341 | } |
Arend van Spriel | 55479df | 2015-06-11 00:12:22 +0200 | [diff] [blame] | 2342 | |
| 2343 | /** |
| 2344 | * brcmf_p2p_attach() - attach for P2P. |
| 2345 | * |
| 2346 | * @cfg: driver private data for cfg80211 interface. |
| 2347 | */ |
Hante Meuleman | ae7c03f | 2015-09-18 22:08:08 +0200 | [diff] [blame] | 2348 | s32 brcmf_p2p_attach(struct brcmf_cfg80211_info *cfg, bool p2pdev_forced) |
Arend van Spriel | 55479df | 2015-06-11 00:12:22 +0200 | [diff] [blame] | 2349 | { |
| 2350 | struct brcmf_if *pri_ifp; |
| 2351 | struct brcmf_if *p2p_ifp; |
| 2352 | struct brcmf_cfg80211_vif *p2p_vif; |
| 2353 | struct brcmf_p2p_info *p2p; |
| 2354 | struct brcmf_pub *drvr; |
| 2355 | s32 bssidx; |
| 2356 | s32 err = 0; |
| 2357 | |
| 2358 | p2p = &cfg->p2p; |
| 2359 | p2p->cfg = cfg; |
| 2360 | |
| 2361 | drvr = cfg->pub; |
| 2362 | |
Hante Meuleman | ae7c03f | 2015-09-18 22:08:08 +0200 | [diff] [blame] | 2363 | pri_ifp = brcmf_get_ifp(drvr, 0); |
Arend van Spriel | 55479df | 2015-06-11 00:12:22 +0200 | [diff] [blame] | 2364 | p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif = pri_ifp->vif; |
| 2365 | |
Hante Meuleman | ae7c03f | 2015-09-18 22:08:08 +0200 | [diff] [blame] | 2366 | if (p2pdev_forced) { |
| 2367 | p2p_ifp = drvr->iflist[1]; |
| 2368 | } else { |
| 2369 | p2p_ifp = NULL; |
| 2370 | p2p->p2pdev_dynamically = true; |
| 2371 | } |
Arend van Spriel | 55479df | 2015-06-11 00:12:22 +0200 | [diff] [blame] | 2372 | if (p2p_ifp) { |
| 2373 | p2p_vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_P2P_DEVICE, |
| 2374 | false); |
| 2375 | if (IS_ERR(p2p_vif)) { |
| 2376 | brcmf_err("could not create discovery vif\n"); |
| 2377 | err = -ENOMEM; |
| 2378 | goto exit; |
| 2379 | } |
| 2380 | |
| 2381 | p2p_vif->ifp = p2p_ifp; |
| 2382 | p2p_ifp->vif = p2p_vif; |
| 2383 | p2p_vif->wdev.netdev = p2p_ifp->ndev; |
| 2384 | p2p_ifp->ndev->ieee80211_ptr = &p2p_vif->wdev; |
| 2385 | SET_NETDEV_DEV(p2p_ifp->ndev, wiphy_dev(cfg->wiphy)); |
| 2386 | |
| 2387 | p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif = p2p_vif; |
| 2388 | |
| 2389 | brcmf_p2p_generate_bss_mac(p2p, NULL); |
| 2390 | memcpy(p2p_ifp->mac_addr, p2p->dev_addr, ETH_ALEN); |
| 2391 | brcmf_p2p_set_firmware(pri_ifp, p2p->dev_addr); |
| 2392 | |
| 2393 | /* Initialize P2P Discovery in the firmware */ |
| 2394 | err = brcmf_fil_iovar_int_set(pri_ifp, "p2p_disc", 1); |
| 2395 | if (err < 0) { |
| 2396 | brcmf_err("set p2p_disc error\n"); |
| 2397 | brcmf_free_vif(p2p_vif); |
| 2398 | goto exit; |
| 2399 | } |
| 2400 | /* obtain bsscfg index for P2P discovery */ |
| 2401 | err = brcmf_fil_iovar_int_get(pri_ifp, "p2p_dev", &bssidx); |
| 2402 | if (err < 0) { |
| 2403 | brcmf_err("retrieving discover bsscfg index failed\n"); |
| 2404 | brcmf_free_vif(p2p_vif); |
| 2405 | goto exit; |
| 2406 | } |
| 2407 | /* Verify that firmware uses same bssidx as driver !! */ |
| 2408 | if (p2p_ifp->bssidx != bssidx) { |
| 2409 | brcmf_err("Incorrect bssidx=%d, compared to p2p_ifp->bssidx=%d\n", |
| 2410 | bssidx, p2p_ifp->bssidx); |
| 2411 | brcmf_free_vif(p2p_vif); |
| 2412 | goto exit; |
| 2413 | } |
| 2414 | |
| 2415 | init_completion(&p2p->send_af_done); |
| 2416 | INIT_WORK(&p2p->afx_hdl.afx_work, brcmf_p2p_afx_handler); |
| 2417 | init_completion(&p2p->afx_hdl.act_frm_scan); |
| 2418 | init_completion(&p2p->wait_next_af); |
| 2419 | } |
| 2420 | exit: |
| 2421 | return err; |
| 2422 | } |
| 2423 | |
| 2424 | /** |
| 2425 | * brcmf_p2p_detach() - detach P2P. |
| 2426 | * |
| 2427 | * @p2p: P2P specific data. |
| 2428 | */ |
| 2429 | void brcmf_p2p_detach(struct brcmf_p2p_info *p2p) |
| 2430 | { |
| 2431 | struct brcmf_cfg80211_vif *vif; |
| 2432 | |
| 2433 | vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif; |
| 2434 | if (vif != NULL) { |
| 2435 | brcmf_p2p_cancel_remain_on_channel(vif->ifp); |
| 2436 | brcmf_p2p_deinit_discovery(p2p); |
Hante Meuleman | 9831bcb | 2015-09-18 22:08:12 +0200 | [diff] [blame] | 2437 | brcmf_remove_interface(vif->ifp); |
Arend van Spriel | 55479df | 2015-06-11 00:12:22 +0200 | [diff] [blame] | 2438 | } |
| 2439 | /* just set it all to zero */ |
| 2440 | memset(p2p, 0, sizeof(*p2p)); |
| 2441 | } |
| 2442 | |