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 | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 19 | #include <net/cfg80211.h> |
| 20 | |
| 21 | #include <brcmu_wifi.h> |
| 22 | #include <brcmu_utils.h> |
| 23 | #include <defs.h> |
| 24 | #include <dhd.h> |
| 25 | #include <dhd_dbg.h> |
| 26 | #include "fwil.h" |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 27 | #include "fwil_types.h" |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 28 | #include "p2p.h" |
| 29 | #include "wl_cfg80211.h" |
| 30 | |
| 31 | /* parameters used for p2p escan */ |
| 32 | #define P2PAPI_SCAN_NPROBES 1 |
| 33 | #define P2PAPI_SCAN_DWELL_TIME_MS 80 |
| 34 | #define P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS 40 |
| 35 | #define P2PAPI_SCAN_HOME_TIME_MS 60 |
| 36 | #define P2PAPI_SCAN_NPROBS_TIME_MS 30 |
| 37 | #define P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS 100 |
| 38 | #define WL_SCAN_CONNECT_DWELL_TIME_MS 200 |
| 39 | #define WL_SCAN_JOIN_PROBE_INTERVAL_MS 20 |
| 40 | |
| 41 | #define BRCMF_P2P_WILDCARD_SSID "DIRECT-" |
| 42 | #define BRCMF_P2P_WILDCARD_SSID_LEN (sizeof(BRCMF_P2P_WILDCARD_SSID) - 1) |
| 43 | |
| 44 | #define SOCIAL_CHAN_1 1 |
| 45 | #define SOCIAL_CHAN_2 6 |
| 46 | #define SOCIAL_CHAN_3 11 |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 47 | #define IS_P2P_SOCIAL_CHANNEL(channel) ((channel == SOCIAL_CHAN_1) || \ |
| 48 | (channel == SOCIAL_CHAN_2) || \ |
| 49 | (channel == SOCIAL_CHAN_3)) |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 50 | #define SOCIAL_CHAN_CNT 3 |
| 51 | #define AF_PEER_SEARCH_CNT 2 |
| 52 | |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 53 | #define BRCMF_SCB_TIMEOUT_VALUE 20 |
| 54 | |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 55 | #define P2P_VER 9 /* P2P version: 9=WiFi P2P v1.0 */ |
| 56 | #define P2P_PUB_AF_CATEGORY 0x04 |
| 57 | #define P2P_PUB_AF_ACTION 0x09 |
| 58 | #define P2P_AF_CATEGORY 0x7f |
| 59 | #define P2P_OUI "\x50\x6F\x9A" /* P2P OUI */ |
| 60 | #define P2P_OUI_LEN 3 /* P2P OUI length */ |
| 61 | |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 62 | /* Action Frame Constants */ |
| 63 | #define DOT11_ACTION_HDR_LEN 2 /* action frame category + action */ |
| 64 | #define DOT11_ACTION_CAT_OFF 0 /* category offset */ |
| 65 | #define DOT11_ACTION_ACT_OFF 1 /* action offset */ |
| 66 | |
| 67 | #define P2P_AF_DWELL_TIME 200 |
| 68 | #define P2P_AF_MIN_DWELL_TIME 100 |
| 69 | #define P2P_AF_MED_DWELL_TIME 400 |
| 70 | #define P2P_AF_LONG_DWELL_TIME 1000 |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 71 | #define P2P_AF_TX_MAX_RETRY 1 |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 72 | #define P2P_AF_MAX_WAIT_TIME 2000 |
| 73 | #define P2P_INVALID_CHANNEL -1 |
| 74 | #define P2P_CHANNEL_SYNC_RETRY 5 |
| 75 | #define P2P_AF_FRM_SCAN_MAX_WAIT 1500 |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 76 | #define P2P_DEFAULT_SLEEP_TIME_VSDB 200 |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 77 | |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 78 | /* WiFi P2P Public Action Frame OUI Subtypes */ |
| 79 | #define P2P_PAF_GON_REQ 0 /* Group Owner Negotiation Req */ |
| 80 | #define P2P_PAF_GON_RSP 1 /* Group Owner Negotiation Rsp */ |
| 81 | #define P2P_PAF_GON_CONF 2 /* Group Owner Negotiation Confirm */ |
| 82 | #define P2P_PAF_INVITE_REQ 3 /* P2P Invitation Request */ |
| 83 | #define P2P_PAF_INVITE_RSP 4 /* P2P Invitation Response */ |
| 84 | #define P2P_PAF_DEVDIS_REQ 5 /* Device Discoverability Request */ |
| 85 | #define P2P_PAF_DEVDIS_RSP 6 /* Device Discoverability Response */ |
| 86 | #define P2P_PAF_PROVDIS_REQ 7 /* Provision Discovery Request */ |
| 87 | #define P2P_PAF_PROVDIS_RSP 8 /* Provision Discovery Response */ |
| 88 | #define P2P_PAF_SUBTYPE_INVALID 255 /* Invalid Subtype */ |
| 89 | |
| 90 | /* WiFi P2P Action Frame OUI Subtypes */ |
| 91 | #define P2P_AF_NOTICE_OF_ABSENCE 0 /* Notice of Absence */ |
| 92 | #define P2P_AF_PRESENCE_REQ 1 /* P2P Presence Request */ |
| 93 | #define P2P_AF_PRESENCE_RSP 2 /* P2P Presence Response */ |
| 94 | #define P2P_AF_GO_DISC_REQ 3 /* GO Discoverability Request */ |
| 95 | |
| 96 | /* P2P Service Discovery related */ |
| 97 | #define P2PSD_ACTION_CATEGORY 0x04 /* Public action frame */ |
| 98 | #define P2PSD_ACTION_ID_GAS_IREQ 0x0a /* GAS Initial Request AF */ |
| 99 | #define P2PSD_ACTION_ID_GAS_IRESP 0x0b /* GAS Initial Response AF */ |
| 100 | #define P2PSD_ACTION_ID_GAS_CREQ 0x0c /* GAS Comback Request AF */ |
| 101 | #define P2PSD_ACTION_ID_GAS_CRESP 0x0d /* GAS Comback Response AF */ |
| 102 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 103 | /** |
| 104 | * struct brcmf_p2p_disc_st_le - set discovery state in firmware. |
| 105 | * |
| 106 | * @state: requested discovery state (see enum brcmf_p2p_disc_state). |
| 107 | * @chspec: channel parameter for %WL_P2P_DISC_ST_LISTEN state. |
| 108 | * @dwell: dwell time in ms for %WL_P2P_DISC_ST_LISTEN state. |
| 109 | */ |
| 110 | struct brcmf_p2p_disc_st_le { |
| 111 | u8 state; |
| 112 | __le16 chspec; |
| 113 | __le16 dwell; |
| 114 | }; |
| 115 | |
| 116 | /** |
| 117 | * enum brcmf_p2p_disc_state - P2P discovery state values |
| 118 | * |
| 119 | * @WL_P2P_DISC_ST_SCAN: P2P discovery with wildcard SSID and P2P IE. |
| 120 | * @WL_P2P_DISC_ST_LISTEN: P2P discovery off-channel for specified time. |
| 121 | * @WL_P2P_DISC_ST_SEARCH: P2P discovery with P2P wildcard SSID and P2P IE. |
| 122 | */ |
| 123 | enum brcmf_p2p_disc_state { |
| 124 | WL_P2P_DISC_ST_SCAN, |
| 125 | WL_P2P_DISC_ST_LISTEN, |
| 126 | WL_P2P_DISC_ST_SEARCH |
| 127 | }; |
| 128 | |
| 129 | /** |
| 130 | * struct brcmf_p2p_scan_le - P2P specific scan request. |
| 131 | * |
| 132 | * @type: type of scan method requested (values: 'E' or 'S'). |
| 133 | * @reserved: reserved (ignored). |
| 134 | * @eparams: parameters used for type 'E'. |
| 135 | * @sparams: parameters used for type 'S'. |
| 136 | */ |
| 137 | struct brcmf_p2p_scan_le { |
| 138 | u8 type; |
| 139 | u8 reserved[3]; |
| 140 | union { |
| 141 | struct brcmf_escan_params_le eparams; |
| 142 | struct brcmf_scan_params_le sparams; |
| 143 | }; |
| 144 | }; |
| 145 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 146 | /** |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 147 | * struct brcmf_p2p_pub_act_frame - WiFi P2P Public Action Frame |
| 148 | * |
| 149 | * @category: P2P_PUB_AF_CATEGORY |
| 150 | * @action: P2P_PUB_AF_ACTION |
| 151 | * @oui[3]: P2P_OUI |
| 152 | * @oui_type: OUI type - P2P_VER |
| 153 | * @subtype: OUI subtype - P2P_TYPE_* |
| 154 | * @dialog_token: nonzero, identifies req/rsp transaction |
| 155 | * @elts[1]: Variable length information elements. |
| 156 | */ |
| 157 | struct brcmf_p2p_pub_act_frame { |
| 158 | u8 category; |
| 159 | u8 action; |
| 160 | u8 oui[3]; |
| 161 | u8 oui_type; |
| 162 | u8 subtype; |
| 163 | u8 dialog_token; |
| 164 | u8 elts[1]; |
| 165 | }; |
| 166 | |
| 167 | /** |
| 168 | * struct brcmf_p2p_action_frame - WiFi P2P Action Frame |
| 169 | * |
| 170 | * @category: P2P_AF_CATEGORY |
| 171 | * @OUI[3]: OUI - P2P_OUI |
| 172 | * @type: OUI Type - P2P_VER |
| 173 | * @subtype: OUI Subtype - P2P_AF_* |
| 174 | * @dialog_token: nonzero, identifies req/resp tranaction |
| 175 | * @elts[1]: Variable length information elements. |
| 176 | */ |
| 177 | struct brcmf_p2p_action_frame { |
| 178 | u8 category; |
| 179 | u8 oui[3]; |
| 180 | u8 type; |
| 181 | u8 subtype; |
| 182 | u8 dialog_token; |
| 183 | u8 elts[1]; |
| 184 | }; |
| 185 | |
| 186 | /** |
| 187 | * struct brcmf_p2psd_gas_pub_act_frame - Wi-Fi GAS Public Action Frame |
| 188 | * |
| 189 | * @category: 0x04 Public Action Frame |
| 190 | * @action: 0x6c Advertisement Protocol |
| 191 | * @dialog_token: nonzero, identifies req/rsp transaction |
| 192 | * @query_data[1]: Query Data. SD gas ireq SD gas iresp |
| 193 | */ |
| 194 | struct brcmf_p2psd_gas_pub_act_frame { |
| 195 | u8 category; |
| 196 | u8 action; |
| 197 | u8 dialog_token; |
| 198 | u8 query_data[1]; |
| 199 | }; |
| 200 | |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 201 | /** |
| 202 | * struct brcmf_config_af_params - Action Frame Parameters for tx. |
| 203 | * |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 204 | * @mpc_onoff: To make sure to send successfully action frame, we have to |
| 205 | * turn off mpc 0: off, 1: on, (-1): do nothing |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 206 | * @search_channel: 1: search peer's channel to send af |
| 207 | * extra_listen: keep the dwell time to get af response frame. |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 208 | */ |
| 209 | struct brcmf_config_af_params { |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 210 | s32 mpc_onoff; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 211 | bool search_channel; |
| 212 | bool extra_listen; |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 213 | }; |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 214 | |
| 215 | /** |
| 216 | * brcmf_p2p_is_pub_action() - true if p2p public type frame. |
| 217 | * |
| 218 | * @frame: action frame data. |
| 219 | * @frame_len: length of action frame data. |
| 220 | * |
| 221 | * Determine if action frame is p2p public action type |
| 222 | */ |
| 223 | static bool brcmf_p2p_is_pub_action(void *frame, u32 frame_len) |
| 224 | { |
| 225 | struct brcmf_p2p_pub_act_frame *pact_frm; |
| 226 | |
| 227 | if (frame == NULL) |
| 228 | return false; |
| 229 | |
| 230 | pact_frm = (struct brcmf_p2p_pub_act_frame *)frame; |
| 231 | if (frame_len < sizeof(struct brcmf_p2p_pub_act_frame) - 1) |
| 232 | return false; |
| 233 | |
| 234 | if (pact_frm->category == P2P_PUB_AF_CATEGORY && |
| 235 | pact_frm->action == P2P_PUB_AF_ACTION && |
| 236 | pact_frm->oui_type == P2P_VER && |
| 237 | memcmp(pact_frm->oui, P2P_OUI, P2P_OUI_LEN) == 0) |
| 238 | return true; |
| 239 | |
| 240 | return false; |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * brcmf_p2p_is_p2p_action() - true if p2p action type frame. |
| 245 | * |
| 246 | * @frame: action frame data. |
| 247 | * @frame_len: length of action frame data. |
| 248 | * |
| 249 | * Determine if action frame is p2p action type |
| 250 | */ |
| 251 | static bool brcmf_p2p_is_p2p_action(void *frame, u32 frame_len) |
| 252 | { |
| 253 | struct brcmf_p2p_action_frame *act_frm; |
| 254 | |
| 255 | if (frame == NULL) |
| 256 | return false; |
| 257 | |
| 258 | act_frm = (struct brcmf_p2p_action_frame *)frame; |
| 259 | if (frame_len < sizeof(struct brcmf_p2p_action_frame) - 1) |
| 260 | return false; |
| 261 | |
| 262 | if (act_frm->category == P2P_AF_CATEGORY && |
| 263 | act_frm->type == P2P_VER && |
| 264 | memcmp(act_frm->oui, P2P_OUI, P2P_OUI_LEN) == 0) |
| 265 | return true; |
| 266 | |
| 267 | return false; |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * brcmf_p2p_is_gas_action() - true if p2p gas action type frame. |
| 272 | * |
| 273 | * @frame: action frame data. |
| 274 | * @frame_len: length of action frame data. |
| 275 | * |
| 276 | * Determine if action frame is p2p gas action type |
| 277 | */ |
| 278 | static bool brcmf_p2p_is_gas_action(void *frame, u32 frame_len) |
| 279 | { |
| 280 | struct brcmf_p2psd_gas_pub_act_frame *sd_act_frm; |
| 281 | |
| 282 | if (frame == NULL) |
| 283 | return false; |
| 284 | |
| 285 | sd_act_frm = (struct brcmf_p2psd_gas_pub_act_frame *)frame; |
| 286 | if (frame_len < sizeof(struct brcmf_p2psd_gas_pub_act_frame) - 1) |
| 287 | return false; |
| 288 | |
| 289 | if (sd_act_frm->category != P2PSD_ACTION_CATEGORY) |
| 290 | return false; |
| 291 | |
| 292 | if (sd_act_frm->action == P2PSD_ACTION_ID_GAS_IREQ || |
| 293 | sd_act_frm->action == P2PSD_ACTION_ID_GAS_IRESP || |
| 294 | sd_act_frm->action == P2PSD_ACTION_ID_GAS_CREQ || |
| 295 | sd_act_frm->action == P2PSD_ACTION_ID_GAS_CRESP) |
| 296 | return true; |
| 297 | |
| 298 | return false; |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * brcmf_p2p_print_actframe() - debug print routine. |
| 303 | * |
| 304 | * @tx: Received or to be transmitted |
| 305 | * @frame: action frame data. |
| 306 | * @frame_len: length of action frame data. |
| 307 | * |
| 308 | * Print information about the p2p action frame |
| 309 | */ |
Hante Meuleman | 0a4cf48 | 2013-02-08 15:53:54 +0100 | [diff] [blame] | 310 | |
| 311 | #ifdef DEBUG |
| 312 | |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 313 | static void brcmf_p2p_print_actframe(bool tx, void *frame, u32 frame_len) |
| 314 | { |
| 315 | struct brcmf_p2p_pub_act_frame *pact_frm; |
| 316 | struct brcmf_p2p_action_frame *act_frm; |
| 317 | struct brcmf_p2psd_gas_pub_act_frame *sd_act_frm; |
| 318 | |
| 319 | if (!frame || frame_len <= 2) |
| 320 | return; |
| 321 | |
| 322 | if (brcmf_p2p_is_pub_action(frame, frame_len)) { |
| 323 | pact_frm = (struct brcmf_p2p_pub_act_frame *)frame; |
| 324 | switch (pact_frm->subtype) { |
| 325 | case P2P_PAF_GON_REQ: |
| 326 | brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Req Frame\n", |
| 327 | (tx) ? "TX" : "RX"); |
| 328 | break; |
| 329 | case P2P_PAF_GON_RSP: |
| 330 | brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Rsp Frame\n", |
| 331 | (tx) ? "TX" : "RX"); |
| 332 | break; |
| 333 | case P2P_PAF_GON_CONF: |
| 334 | brcmf_dbg(TRACE, "%s P2P Group Owner Negotiation Confirm Frame\n", |
| 335 | (tx) ? "TX" : "RX"); |
| 336 | break; |
| 337 | case P2P_PAF_INVITE_REQ: |
| 338 | brcmf_dbg(TRACE, "%s P2P Invitation Request Frame\n", |
| 339 | (tx) ? "TX" : "RX"); |
| 340 | break; |
| 341 | case P2P_PAF_INVITE_RSP: |
| 342 | brcmf_dbg(TRACE, "%s P2P Invitation Response Frame\n", |
| 343 | (tx) ? "TX" : "RX"); |
| 344 | break; |
| 345 | case P2P_PAF_DEVDIS_REQ: |
| 346 | brcmf_dbg(TRACE, "%s P2P Device Discoverability Request Frame\n", |
| 347 | (tx) ? "TX" : "RX"); |
| 348 | break; |
| 349 | case P2P_PAF_DEVDIS_RSP: |
| 350 | brcmf_dbg(TRACE, "%s P2P Device Discoverability Response Frame\n", |
| 351 | (tx) ? "TX" : "RX"); |
| 352 | break; |
| 353 | case P2P_PAF_PROVDIS_REQ: |
| 354 | brcmf_dbg(TRACE, "%s P2P Provision Discovery Request Frame\n", |
| 355 | (tx) ? "TX" : "RX"); |
| 356 | break; |
| 357 | case P2P_PAF_PROVDIS_RSP: |
| 358 | brcmf_dbg(TRACE, "%s P2P Provision Discovery Response Frame\n", |
| 359 | (tx) ? "TX" : "RX"); |
| 360 | break; |
| 361 | default: |
| 362 | brcmf_dbg(TRACE, "%s Unknown P2P Public Action Frame\n", |
| 363 | (tx) ? "TX" : "RX"); |
| 364 | break; |
| 365 | } |
| 366 | } else if (brcmf_p2p_is_p2p_action(frame, frame_len)) { |
| 367 | act_frm = (struct brcmf_p2p_action_frame *)frame; |
| 368 | switch (act_frm->subtype) { |
| 369 | case P2P_AF_NOTICE_OF_ABSENCE: |
| 370 | brcmf_dbg(TRACE, "%s P2P Notice of Absence Frame\n", |
| 371 | (tx) ? "TX" : "RX"); |
| 372 | break; |
| 373 | case P2P_AF_PRESENCE_REQ: |
| 374 | brcmf_dbg(TRACE, "%s P2P Presence Request Frame\n", |
| 375 | (tx) ? "TX" : "RX"); |
| 376 | break; |
| 377 | case P2P_AF_PRESENCE_RSP: |
| 378 | brcmf_dbg(TRACE, "%s P2P Presence Response Frame\n", |
| 379 | (tx) ? "TX" : "RX"); |
| 380 | break; |
| 381 | case P2P_AF_GO_DISC_REQ: |
| 382 | brcmf_dbg(TRACE, "%s P2P Discoverability Request Frame\n", |
| 383 | (tx) ? "TX" : "RX"); |
| 384 | break; |
| 385 | default: |
| 386 | brcmf_dbg(TRACE, "%s Unknown P2P Action Frame\n", |
| 387 | (tx) ? "TX" : "RX"); |
| 388 | } |
| 389 | |
| 390 | } else if (brcmf_p2p_is_gas_action(frame, frame_len)) { |
| 391 | sd_act_frm = (struct brcmf_p2psd_gas_pub_act_frame *)frame; |
| 392 | switch (sd_act_frm->action) { |
| 393 | case P2PSD_ACTION_ID_GAS_IREQ: |
| 394 | brcmf_dbg(TRACE, "%s P2P GAS Initial Request\n", |
| 395 | (tx) ? "TX" : "RX"); |
| 396 | break; |
| 397 | case P2PSD_ACTION_ID_GAS_IRESP: |
| 398 | brcmf_dbg(TRACE, "%s P2P GAS Initial Response\n", |
| 399 | (tx) ? "TX" : "RX"); |
| 400 | break; |
| 401 | case P2PSD_ACTION_ID_GAS_CREQ: |
| 402 | brcmf_dbg(TRACE, "%s P2P GAS Comback Request\n", |
| 403 | (tx) ? "TX" : "RX"); |
| 404 | break; |
| 405 | case P2PSD_ACTION_ID_GAS_CRESP: |
| 406 | brcmf_dbg(TRACE, "%s P2P GAS Comback Response\n", |
| 407 | (tx) ? "TX" : "RX"); |
| 408 | break; |
| 409 | default: |
| 410 | brcmf_dbg(TRACE, "%s Unknown P2P GAS Frame\n", |
| 411 | (tx) ? "TX" : "RX"); |
| 412 | break; |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | |
Hante Meuleman | 0a4cf48 | 2013-02-08 15:53:54 +0100 | [diff] [blame] | 417 | #else |
| 418 | |
| 419 | static void brcmf_p2p_print_actframe(bool tx, void *frame, u32 frame_len) |
| 420 | { |
| 421 | } |
| 422 | |
| 423 | #endif |
| 424 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 425 | |
| 426 | /** |
| 427 | * brcmf_p2p_chnr_to_chspec() - convert channel number to chanspec. |
| 428 | * |
| 429 | * @channel: channel number |
| 430 | */ |
| 431 | static u16 brcmf_p2p_chnr_to_chspec(u16 channel) |
| 432 | { |
| 433 | u16 chanspec; |
| 434 | |
| 435 | chanspec = channel & WL_CHANSPEC_CHAN_MASK; |
| 436 | |
| 437 | if (channel <= CH_MAX_2G_CHANNEL) |
| 438 | chanspec |= WL_CHANSPEC_BAND_2G; |
| 439 | else |
| 440 | chanspec |= WL_CHANSPEC_BAND_5G; |
| 441 | |
| 442 | chanspec |= WL_CHANSPEC_BW_20; |
| 443 | chanspec |= WL_CHANSPEC_CTL_SB_NONE; |
| 444 | |
| 445 | return chanspec; |
| 446 | } |
| 447 | |
| 448 | |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 449 | /** |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 450 | * brcmf_p2p_set_firmware() - prepare firmware for peer-to-peer operation. |
| 451 | * |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 452 | * @ifp: ifp to use for iovars (primary). |
| 453 | * @p2p_mac: mac address to configure for p2p_da_override |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 454 | */ |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 455 | 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] | 456 | { |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 457 | s32 ret = 0; |
| 458 | |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame^] | 459 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1); |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 460 | brcmf_fil_iovar_int_set(ifp, "apsta", 1); |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame^] | 461 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 462 | |
| 463 | /* In case of COB type, firmware has default mac address |
| 464 | * After Initializing firmware, we have to set current mac address to |
| 465 | * firmware for P2P device address |
| 466 | */ |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 467 | ret = brcmf_fil_iovar_data_set(ifp, "p2p_da_override", p2p_mac, |
| 468 | ETH_ALEN); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 469 | if (ret) |
| 470 | brcmf_err("failed to update device address ret %d\n", ret); |
| 471 | |
| 472 | return ret; |
| 473 | } |
| 474 | |
| 475 | /** |
| 476 | * brcmf_p2p_generate_bss_mac() - derive mac addresses for P2P. |
| 477 | * |
| 478 | * @p2p: P2P specific data. |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame^] | 479 | * @dev_addr: optional device address. |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 480 | * |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame^] | 481 | * P2P needs mac addresses for P2P device and interface. If no device |
| 482 | * address it specified, these are derived from the primary net device, ie. |
| 483 | * the permanent ethernet address of the device. |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 484 | */ |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame^] | 485 | 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] | 486 | { |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 487 | struct brcmf_if *pri_ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp; |
| 488 | struct brcmf_if *p2p_ifp = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif->ifp; |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame^] | 489 | bool local_admin = false; |
| 490 | |
| 491 | if (!dev_addr || is_zero_ether_addr(dev_addr)) { |
| 492 | dev_addr = pri_ifp->mac_addr; |
| 493 | local_admin = true; |
| 494 | } |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 495 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 496 | /* Generate the P2P Device Address. This consists of the device's |
| 497 | * primary MAC address with the locally administered bit set. |
| 498 | */ |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame^] | 499 | memcpy(p2p->dev_addr, dev_addr, ETH_ALEN); |
| 500 | if (local_admin) |
| 501 | p2p->dev_addr[0] |= 0x02; |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 502 | memcpy(p2p_ifp->mac_addr, p2p->dev_addr, ETH_ALEN); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 503 | |
| 504 | /* Generate the P2P Interface Address. If the discovery and connection |
| 505 | * BSSCFGs need to simultaneously co-exist, then this address must be |
| 506 | * different from the P2P Device Address, but also locally administered. |
| 507 | */ |
| 508 | memcpy(p2p->int_addr, p2p->dev_addr, ETH_ALEN); |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame^] | 509 | p2p->int_addr[0] |= 0x02; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 510 | p2p->int_addr[4] ^= 0x80; |
| 511 | } |
| 512 | |
| 513 | /** |
| 514 | * brcmf_p2p_scan_is_p2p_request() - is cfg80211 scan request a P2P scan. |
| 515 | * |
| 516 | * @request: the scan request as received from cfg80211. |
| 517 | * |
| 518 | * returns true if one of the ssids in the request matches the |
| 519 | * P2P wildcard ssid; otherwise returns false. |
| 520 | */ |
| 521 | static bool brcmf_p2p_scan_is_p2p_request(struct cfg80211_scan_request *request) |
| 522 | { |
| 523 | struct cfg80211_ssid *ssids = request->ssids; |
| 524 | int i; |
| 525 | |
| 526 | for (i = 0; i < request->n_ssids; i++) { |
| 527 | if (ssids[i].ssid_len != BRCMF_P2P_WILDCARD_SSID_LEN) |
| 528 | continue; |
| 529 | |
| 530 | brcmf_dbg(INFO, "comparing ssid \"%s\"", ssids[i].ssid); |
| 531 | if (!memcmp(BRCMF_P2P_WILDCARD_SSID, ssids[i].ssid, |
| 532 | BRCMF_P2P_WILDCARD_SSID_LEN)) |
| 533 | return true; |
| 534 | } |
| 535 | return false; |
| 536 | } |
| 537 | |
| 538 | /** |
| 539 | * brcmf_p2p_set_discover_state - set discover state in firmware. |
| 540 | * |
| 541 | * @ifp: low-level interface object. |
| 542 | * @state: discover state to set. |
| 543 | * @chanspec: channel parameters (for state @WL_P2P_DISC_ST_LISTEN only). |
| 544 | * @listen_ms: duration to listen (for state @WL_P2P_DISC_ST_LISTEN only). |
| 545 | */ |
| 546 | static s32 brcmf_p2p_set_discover_state(struct brcmf_if *ifp, u8 state, |
| 547 | u16 chanspec, u16 listen_ms) |
| 548 | { |
| 549 | struct brcmf_p2p_disc_st_le discover_state; |
| 550 | s32 ret = 0; |
| 551 | brcmf_dbg(TRACE, "enter\n"); |
| 552 | |
| 553 | discover_state.state = state; |
| 554 | discover_state.chspec = cpu_to_le16(chanspec); |
| 555 | discover_state.dwell = cpu_to_le16(listen_ms); |
| 556 | ret = brcmf_fil_bsscfg_data_set(ifp, "p2p_state", &discover_state, |
| 557 | sizeof(discover_state)); |
| 558 | return ret; |
| 559 | } |
| 560 | |
| 561 | /** |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 562 | * brcmf_p2p_deinit_discovery() - disable P2P device discovery. |
| 563 | * |
| 564 | * @p2p: P2P specific data. |
| 565 | * |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 566 | * Resets the discovery state and disables it in firmware. |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 567 | */ |
| 568 | static s32 brcmf_p2p_deinit_discovery(struct brcmf_p2p_info *p2p) |
| 569 | { |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 570 | struct brcmf_cfg80211_vif *vif; |
| 571 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 572 | brcmf_dbg(TRACE, "enter\n"); |
| 573 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 574 | /* Set the discovery state to SCAN */ |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 575 | vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif; |
| 576 | (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] | 577 | |
| 578 | /* Disable P2P discovery in the firmware */ |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 579 | vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif; |
| 580 | (void)brcmf_fil_iovar_int_set(vif->ifp, "p2p_disc", 0); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 581 | |
| 582 | return 0; |
| 583 | } |
| 584 | |
| 585 | /** |
| 586 | * brcmf_p2p_enable_discovery() - initialize and configure discovery. |
| 587 | * |
| 588 | * @p2p: P2P specific data. |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 589 | * |
| 590 | * Initializes the discovery device and configure the virtual interface. |
| 591 | */ |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 592 | static int brcmf_p2p_enable_discovery(struct brcmf_p2p_info *p2p) |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 593 | { |
| 594 | struct brcmf_cfg80211_vif *vif; |
| 595 | s32 ret = 0; |
| 596 | |
| 597 | brcmf_dbg(TRACE, "enter\n"); |
| 598 | vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif; |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 599 | if (!vif) { |
| 600 | brcmf_err("P2P config device not available\n"); |
| 601 | ret = -EPERM; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 602 | goto exit; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 603 | } |
| 604 | |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 605 | if (test_bit(BRCMF_P2P_STATUS_ENABLED, &p2p->status)) { |
| 606 | brcmf_dbg(INFO, "P2P config device already configured\n"); |
| 607 | goto exit; |
| 608 | } |
| 609 | |
| 610 | /* Re-initialize P2P Discovery in the firmware */ |
| 611 | vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif; |
| 612 | ret = brcmf_fil_iovar_int_set(vif->ifp, "p2p_disc", 1); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 613 | if (ret < 0) { |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 614 | brcmf_err("set p2p_disc error\n"); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 615 | goto exit; |
| 616 | } |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 617 | vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif; |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 618 | ret = brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_SCAN, 0, 0); |
| 619 | if (ret < 0) { |
| 620 | brcmf_err("unable to set WL_P2P_DISC_ST_SCAN\n"); |
| 621 | goto exit; |
| 622 | } |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 623 | |
| 624 | /* |
| 625 | * Set wsec to any non-zero value in the discovery bsscfg |
| 626 | * to ensure our P2P probe responses have the privacy bit |
| 627 | * set in the 802.11 WPA IE. Some peer devices may not |
| 628 | * initiate WPS with us if this bit is not set. |
| 629 | */ |
| 630 | ret = brcmf_fil_bsscfg_int_set(vif->ifp, "wsec", AES_ENABLED); |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 631 | if (ret < 0) { |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 632 | brcmf_err("wsec error %d\n", ret); |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 633 | goto exit; |
| 634 | } |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 635 | |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 636 | set_bit(BRCMF_P2P_STATUS_ENABLED, &p2p->status); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 637 | exit: |
| 638 | return ret; |
| 639 | } |
| 640 | |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 641 | /** |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 642 | * brcmf_p2p_escan() - initiate a P2P scan. |
| 643 | * |
| 644 | * @p2p: P2P specific data. |
| 645 | * @num_chans: number of channels to scan. |
| 646 | * @chanspecs: channel parameters for @num_chans channels. |
| 647 | * @search_state: P2P discover state to use. |
| 648 | * @action: scan action to pass to firmware. |
| 649 | * @bss_type: type of P2P bss. |
| 650 | */ |
| 651 | static s32 brcmf_p2p_escan(struct brcmf_p2p_info *p2p, u32 num_chans, |
| 652 | u16 chanspecs[], s32 search_state, u16 action, |
| 653 | enum p2p_bss_type bss_type) |
| 654 | { |
| 655 | s32 ret = 0; |
| 656 | s32 memsize = offsetof(struct brcmf_p2p_scan_le, |
| 657 | eparams.params_le.channel_list); |
| 658 | s32 nprobes; |
| 659 | s32 active; |
| 660 | u32 i; |
| 661 | u8 *memblk; |
| 662 | struct brcmf_cfg80211_vif *vif; |
| 663 | struct brcmf_p2p_scan_le *p2p_params; |
| 664 | struct brcmf_scan_params_le *sparams; |
| 665 | struct brcmf_ssid ssid; |
| 666 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 667 | memsize += num_chans * sizeof(__le16); |
| 668 | memblk = kzalloc(memsize, GFP_KERNEL); |
| 669 | if (!memblk) |
| 670 | return -ENOMEM; |
| 671 | |
| 672 | vif = p2p->bss_idx[bss_type].vif; |
| 673 | if (vif == NULL) { |
| 674 | brcmf_err("no vif for bss type %d\n", bss_type); |
| 675 | ret = -EINVAL; |
| 676 | goto exit; |
| 677 | } |
| 678 | |
| 679 | switch (search_state) { |
| 680 | case WL_P2P_DISC_ST_SEARCH: |
| 681 | /* |
| 682 | * If we in SEARCH STATE, we don't need to set SSID explictly |
| 683 | * because dongle use P2P WILDCARD internally by default |
| 684 | */ |
| 685 | /* use null ssid */ |
| 686 | ssid.SSID_len = 0; |
| 687 | memset(ssid.SSID, 0, sizeof(ssid.SSID)); |
| 688 | break; |
| 689 | case WL_P2P_DISC_ST_SCAN: |
| 690 | /* |
| 691 | * wpa_supplicant has p2p_find command with type social or |
| 692 | * progressive. For progressive, we need to set the ssid to |
| 693 | * P2P WILDCARD because we just do broadcast scan unless |
| 694 | * setting SSID. |
| 695 | */ |
| 696 | ssid.SSID_len = BRCMF_P2P_WILDCARD_SSID_LEN; |
| 697 | memcpy(ssid.SSID, BRCMF_P2P_WILDCARD_SSID, ssid.SSID_len); |
| 698 | break; |
| 699 | default: |
| 700 | brcmf_err(" invalid search state %d\n", search_state); |
| 701 | ret = -EINVAL; |
| 702 | goto exit; |
| 703 | } |
| 704 | |
| 705 | brcmf_p2p_set_discover_state(vif->ifp, search_state, 0, 0); |
| 706 | |
| 707 | /* |
| 708 | * set p2p scan parameters. |
| 709 | */ |
| 710 | p2p_params = (struct brcmf_p2p_scan_le *)memblk; |
| 711 | p2p_params->type = 'E'; |
| 712 | |
| 713 | /* determine the scan engine parameters */ |
| 714 | sparams = &p2p_params->eparams.params_le; |
| 715 | sparams->bss_type = DOT11_BSSTYPE_ANY; |
| 716 | if (p2p->cfg->active_scan) |
| 717 | sparams->scan_type = 0; |
| 718 | else |
| 719 | sparams->scan_type = 1; |
| 720 | |
| 721 | memset(&sparams->bssid, 0xFF, ETH_ALEN); |
| 722 | if (ssid.SSID_len) |
| 723 | memcpy(sparams->ssid_le.SSID, ssid.SSID, ssid.SSID_len); |
| 724 | sparams->ssid_le.SSID_len = cpu_to_le32(ssid.SSID_len); |
| 725 | sparams->home_time = cpu_to_le32(P2PAPI_SCAN_HOME_TIME_MS); |
| 726 | |
| 727 | /* |
| 728 | * SOCIAL_CHAN_CNT + 1 takes care of the Progressive scan |
| 729 | * supported by the supplicant. |
| 730 | */ |
| 731 | if (num_chans == SOCIAL_CHAN_CNT || num_chans == (SOCIAL_CHAN_CNT + 1)) |
| 732 | active = P2PAPI_SCAN_SOCIAL_DWELL_TIME_MS; |
| 733 | else if (num_chans == AF_PEER_SEARCH_CNT) |
| 734 | active = P2PAPI_SCAN_AF_SEARCH_DWELL_TIME_MS; |
| 735 | else if (wl_get_vif_state_all(p2p->cfg, BRCMF_VIF_STATUS_CONNECTED)) |
| 736 | active = -1; |
| 737 | else |
| 738 | active = P2PAPI_SCAN_DWELL_TIME_MS; |
| 739 | |
| 740 | /* Override scan params to find a peer for a connection */ |
| 741 | if (num_chans == 1) { |
| 742 | active = WL_SCAN_CONNECT_DWELL_TIME_MS; |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 743 | /* WAR to sync with presence period of VSDB GO. |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 744 | * send probe request more frequently |
| 745 | */ |
| 746 | nprobes = active / WL_SCAN_JOIN_PROBE_INTERVAL_MS; |
| 747 | } else { |
| 748 | nprobes = active / P2PAPI_SCAN_NPROBS_TIME_MS; |
| 749 | } |
| 750 | |
| 751 | if (nprobes <= 0) |
| 752 | nprobes = 1; |
| 753 | |
| 754 | brcmf_dbg(INFO, "nprobes # %d, active_time %d\n", nprobes, active); |
| 755 | sparams->active_time = cpu_to_le32(active); |
| 756 | sparams->nprobes = cpu_to_le32(nprobes); |
| 757 | sparams->passive_time = cpu_to_le32(-1); |
| 758 | sparams->channel_num = cpu_to_le32(num_chans & |
| 759 | BRCMF_SCAN_PARAMS_COUNT_MASK); |
| 760 | for (i = 0; i < num_chans; i++) |
| 761 | sparams->channel_list[i] = cpu_to_le16(chanspecs[i]); |
| 762 | |
| 763 | /* set the escan specific parameters */ |
| 764 | p2p_params->eparams.version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION); |
| 765 | p2p_params->eparams.action = cpu_to_le16(action); |
| 766 | p2p_params->eparams.sync_id = cpu_to_le16(0x1234); |
| 767 | /* perform p2p scan on primary device */ |
| 768 | ret = brcmf_fil_bsscfg_data_set(vif->ifp, "p2p_scan", memblk, memsize); |
| 769 | if (!ret) |
| 770 | set_bit(BRCMF_SCAN_STATUS_BUSY, &p2p->cfg->scan_status); |
| 771 | exit: |
| 772 | kfree(memblk); |
| 773 | return ret; |
| 774 | } |
| 775 | |
| 776 | /** |
| 777 | * brcmf_p2p_run_escan() - escan callback for peer-to-peer. |
| 778 | * |
| 779 | * @cfg: driver private data for cfg80211 interface. |
| 780 | * @ndev: net device for which scan is requested. |
| 781 | * @request: scan request from cfg80211. |
| 782 | * @action: scan action. |
| 783 | * |
| 784 | * Determines the P2P discovery state based to scan request parameters and |
| 785 | * validates the channels in the request. |
| 786 | */ |
| 787 | static s32 brcmf_p2p_run_escan(struct brcmf_cfg80211_info *cfg, |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 788 | struct brcmf_if *ifp, |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 789 | struct cfg80211_scan_request *request, |
| 790 | u16 action) |
| 791 | { |
| 792 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
| 793 | s32 err = 0; |
| 794 | s32 search_state = WL_P2P_DISC_ST_SCAN; |
| 795 | struct brcmf_cfg80211_vif *vif; |
| 796 | struct net_device *dev = NULL; |
| 797 | int i, num_nodfs = 0; |
| 798 | u16 *chanspecs; |
| 799 | |
| 800 | brcmf_dbg(TRACE, "enter\n"); |
| 801 | |
| 802 | if (!request) { |
| 803 | err = -EINVAL; |
| 804 | goto exit; |
| 805 | } |
| 806 | |
| 807 | if (request->n_channels) { |
| 808 | chanspecs = kcalloc(request->n_channels, sizeof(*chanspecs), |
| 809 | GFP_KERNEL); |
| 810 | if (!chanspecs) { |
| 811 | err = -ENOMEM; |
| 812 | goto exit; |
| 813 | } |
| 814 | vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif; |
| 815 | if (vif) |
| 816 | dev = vif->wdev.netdev; |
| 817 | if (request->n_channels == 3 && |
| 818 | request->channels[0]->hw_value == SOCIAL_CHAN_1 && |
| 819 | request->channels[1]->hw_value == SOCIAL_CHAN_2 && |
| 820 | request->channels[2]->hw_value == SOCIAL_CHAN_3) { |
| 821 | /* SOCIAL CHANNELS 1, 6, 11 */ |
| 822 | search_state = WL_P2P_DISC_ST_SEARCH; |
| 823 | brcmf_dbg(INFO, "P2P SEARCH PHASE START\n"); |
| 824 | } else if (dev != NULL && vif->mode == WL_MODE_AP) { |
| 825 | /* If you are already a GO, then do SEARCH only */ |
| 826 | brcmf_dbg(INFO, "Already a GO. Do SEARCH Only\n"); |
| 827 | search_state = WL_P2P_DISC_ST_SEARCH; |
| 828 | } else { |
| 829 | brcmf_dbg(INFO, "P2P SCAN STATE START\n"); |
| 830 | } |
| 831 | |
| 832 | /* |
| 833 | * no P2P scanning on passive or DFS channels. |
| 834 | */ |
| 835 | for (i = 0; i < request->n_channels; i++) { |
| 836 | struct ieee80211_channel *chan = request->channels[i]; |
| 837 | |
| 838 | if (chan->flags & (IEEE80211_CHAN_RADAR | |
| 839 | IEEE80211_CHAN_PASSIVE_SCAN)) |
| 840 | continue; |
| 841 | |
| 842 | chanspecs[i] = channel_to_chanspec(chan); |
| 843 | brcmf_dbg(INFO, "%d: chan=%d, channel spec=%x\n", |
| 844 | num_nodfs, chan->hw_value, chanspecs[i]); |
| 845 | num_nodfs++; |
| 846 | } |
| 847 | err = brcmf_p2p_escan(p2p, num_nodfs, chanspecs, search_state, |
| 848 | action, P2PAPI_BSSCFG_DEVICE); |
| 849 | } |
| 850 | exit: |
| 851 | if (err) |
| 852 | brcmf_err("error (%d)\n", err); |
| 853 | return err; |
| 854 | } |
| 855 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 856 | |
| 857 | /** |
| 858 | * brcmf_p2p_find_listen_channel() - find listen channel in ie string. |
| 859 | * |
| 860 | * @ie: string of information elements. |
| 861 | * @ie_len: length of string. |
| 862 | * |
| 863 | * Scan ie for p2p ie and look for attribute 6 channel. If available determine |
| 864 | * channel and return it. |
| 865 | */ |
| 866 | static s32 brcmf_p2p_find_listen_channel(const u8 *ie, u32 ie_len) |
| 867 | { |
| 868 | u8 channel_ie[5]; |
| 869 | s32 listen_channel; |
| 870 | s32 err; |
| 871 | |
| 872 | err = cfg80211_get_p2p_attr(ie, ie_len, |
| 873 | IEEE80211_P2P_ATTR_LISTEN_CHANNEL, |
| 874 | channel_ie, sizeof(channel_ie)); |
| 875 | if (err < 0) |
| 876 | return err; |
| 877 | |
| 878 | /* listen channel subel length format: */ |
| 879 | /* 3(country) + 1(op. class) + 1(chan num) */ |
| 880 | listen_channel = (s32)channel_ie[3 + 1]; |
| 881 | |
| 882 | if (listen_channel == SOCIAL_CHAN_1 || |
| 883 | listen_channel == SOCIAL_CHAN_2 || |
| 884 | listen_channel == SOCIAL_CHAN_3) { |
| 885 | brcmf_dbg(INFO, "Found my Listen Channel %d\n", listen_channel); |
| 886 | return listen_channel; |
| 887 | } |
| 888 | |
| 889 | return -EPERM; |
| 890 | } |
| 891 | |
| 892 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 893 | /** |
| 894 | * brcmf_p2p_scan_prep() - prepare scan based on request. |
| 895 | * |
| 896 | * @wiphy: wiphy device. |
| 897 | * @request: scan request from cfg80211. |
Hante Meuleman | 0f8ffe1 | 2013-02-08 15:53:42 +0100 | [diff] [blame] | 898 | * @vif: vif on which scan request is to be executed. |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 899 | * |
| 900 | * Prepare the scan appropriately for type of scan requested. Overrides the |
| 901 | * escan .run() callback for peer-to-peer scanning. |
| 902 | */ |
| 903 | int brcmf_p2p_scan_prep(struct wiphy *wiphy, |
Hante Meuleman | 0f8ffe1 | 2013-02-08 15:53:42 +0100 | [diff] [blame] | 904 | struct cfg80211_scan_request *request, |
| 905 | struct brcmf_cfg80211_vif *vif) |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 906 | { |
| 907 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 908 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
| 909 | int err = 0; |
| 910 | |
| 911 | if (brcmf_p2p_scan_is_p2p_request(request)) { |
| 912 | /* find my listen channel */ |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 913 | err = brcmf_p2p_find_listen_channel(request->ie, |
| 914 | request->ie_len); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 915 | if (err < 0) |
| 916 | return err; |
| 917 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 918 | p2p->afx_hdl.my_listen_chan = err; |
| 919 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 920 | clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status); |
| 921 | brcmf_dbg(INFO, "P2P: GO_NEG_PHASE status cleared\n"); |
| 922 | |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 923 | err = brcmf_p2p_enable_discovery(p2p); |
Hante Meuleman | 0f8ffe1 | 2013-02-08 15:53:42 +0100 | [diff] [blame] | 924 | if (err) |
| 925 | return err; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 926 | |
Hante Meuleman | 0f8ffe1 | 2013-02-08 15:53:42 +0100 | [diff] [blame] | 927 | vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif; |
| 928 | |
| 929 | /* override .run_escan() callback. */ |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 930 | cfg->escan_info.run = brcmf_p2p_run_escan; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 931 | } |
Hante Meuleman | 0f8ffe1 | 2013-02-08 15:53:42 +0100 | [diff] [blame] | 932 | err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBREQ_FLAG, |
| 933 | request->ie, request->ie_len); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 934 | return err; |
| 935 | } |
| 936 | |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 937 | |
| 938 | /** |
Hante Meuleman | f2058dd | 2013-02-08 15:53:50 +0100 | [diff] [blame] | 939 | * brcmf_p2p_discover_listen() - set firmware to discover listen state. |
| 940 | * |
| 941 | * @p2p: p2p device. |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 942 | * @channel: channel nr for discover listen. |
| 943 | * @duration: time in ms to stay on channel. |
Hante Meuleman | f2058dd | 2013-02-08 15:53:50 +0100 | [diff] [blame] | 944 | * |
| 945 | */ |
| 946 | static s32 |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 947 | 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] | 948 | { |
| 949 | struct brcmf_cfg80211_vif *vif; |
| 950 | s32 err = 0; |
| 951 | u16 chanspec; |
| 952 | |
| 953 | vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif; |
| 954 | if (!vif) { |
| 955 | brcmf_err("Discovery is not set, so we have nothing to do\n"); |
| 956 | err = -EPERM; |
| 957 | goto exit; |
| 958 | } |
| 959 | |
| 960 | if (test_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, &p2p->status)) { |
| 961 | brcmf_err("Previous LISTEN is not completed yet\n"); |
| 962 | /* WAR: prevent cookie mismatch in wpa_supplicant return OK */ |
| 963 | goto exit; |
| 964 | } |
| 965 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 966 | chanspec = brcmf_p2p_chnr_to_chspec(channel); |
Hante Meuleman | f2058dd | 2013-02-08 15:53:50 +0100 | [diff] [blame] | 967 | err = brcmf_p2p_set_discover_state(vif->ifp, WL_P2P_DISC_ST_LISTEN, |
| 968 | chanspec, (u16)duration); |
| 969 | if (!err) { |
| 970 | set_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, &p2p->status); |
| 971 | p2p->remain_on_channel_cookie++; |
| 972 | } |
| 973 | exit: |
| 974 | return err; |
| 975 | } |
| 976 | |
| 977 | |
| 978 | /** |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 979 | * brcmf_p2p_remain_on_channel() - put device on channel and stay there. |
| 980 | * |
| 981 | * @wiphy: wiphy device. |
| 982 | * @channel: channel to stay on. |
| 983 | * @duration: time in ms to remain on channel. |
| 984 | * |
| 985 | */ |
| 986 | int brcmf_p2p_remain_on_channel(struct wiphy *wiphy, struct wireless_dev *wdev, |
| 987 | struct ieee80211_channel *channel, |
| 988 | unsigned int duration, u64 *cookie) |
| 989 | { |
| 990 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 991 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 992 | s32 err; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 993 | u16 channel_nr; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 994 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 995 | channel_nr = ieee80211_frequency_to_channel(channel->center_freq); |
| 996 | brcmf_dbg(TRACE, "Enter, channel: %d, duration ms (%d)\n", channel_nr, |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 997 | duration); |
| 998 | |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 999 | err = brcmf_p2p_enable_discovery(p2p); |
| 1000 | if (err) |
| 1001 | goto exit; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1002 | err = brcmf_p2p_discover_listen(p2p, channel_nr, duration); |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 1003 | if (err) |
| 1004 | goto exit; |
| 1005 | |
Hante Meuleman | f2058dd | 2013-02-08 15:53:50 +0100 | [diff] [blame] | 1006 | memcpy(&p2p->remain_on_channel, channel, sizeof(*channel)); |
| 1007 | *cookie = p2p->remain_on_channel_cookie; |
Arend van Spriel | 1ce3086 | 2013-02-08 15:53:51 +0100 | [diff] [blame] | 1008 | cfg80211_ready_on_channel(wdev, *cookie, channel, duration, GFP_KERNEL); |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 1009 | |
| 1010 | exit: |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 1011 | return err; |
| 1012 | } |
| 1013 | |
| 1014 | |
| 1015 | /** |
| 1016 | * brcmf_p2p_notify_listen_complete() - p2p listen has completed. |
| 1017 | * |
| 1018 | * @ifp: interfac control. |
| 1019 | * @e: event message. Not used, to make it usable for fweh event dispatcher. |
| 1020 | * @data: payload of message. Not used. |
| 1021 | * |
| 1022 | */ |
| 1023 | int brcmf_p2p_notify_listen_complete(struct brcmf_if *ifp, |
| 1024 | const struct brcmf_event_msg *e, |
| 1025 | void *data) |
| 1026 | { |
| 1027 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
| 1028 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
| 1029 | |
| 1030 | brcmf_dbg(TRACE, "Enter\n"); |
Hante Meuleman | f2058dd | 2013-02-08 15:53:50 +0100 | [diff] [blame] | 1031 | if (test_and_clear_bit(BRCMF_P2P_STATUS_DISCOVER_LISTEN, |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1032 | &p2p->status)) { |
| 1033 | if (test_and_clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN, |
| 1034 | &p2p->status)) { |
| 1035 | clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, |
| 1036 | &p2p->status); |
| 1037 | brcmf_dbg(INFO, "Listen DONE, wake up wait_next_af\n"); |
| 1038 | complete(&p2p->wait_next_af); |
| 1039 | } |
| 1040 | |
Hante Meuleman | f2058dd | 2013-02-08 15:53:50 +0100 | [diff] [blame] | 1041 | cfg80211_remain_on_channel_expired(&ifp->vif->wdev, |
| 1042 | p2p->remain_on_channel_cookie, |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 1043 | &p2p->remain_on_channel, |
| 1044 | GFP_KERNEL); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1045 | } |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 1046 | return 0; |
| 1047 | } |
| 1048 | |
| 1049 | |
| 1050 | /** |
| 1051 | * brcmf_p2p_cancel_remain_on_channel() - cancel p2p listen state. |
| 1052 | * |
| 1053 | * @ifp: interfac control. |
| 1054 | * |
| 1055 | */ |
| 1056 | void brcmf_p2p_cancel_remain_on_channel(struct brcmf_if *ifp) |
| 1057 | { |
| 1058 | if (!ifp) |
| 1059 | return; |
| 1060 | brcmf_p2p_set_discover_state(ifp, WL_P2P_DISC_ST_SCAN, 0, 0); |
| 1061 | brcmf_p2p_notify_listen_complete(ifp, NULL, NULL); |
| 1062 | } |
| 1063 | |
| 1064 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1065 | /** |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1066 | * brcmf_p2p_act_frm_search() - search function for action frame. |
| 1067 | * |
| 1068 | * @p2p: p2p device. |
| 1069 | * channel: channel on which action frame is to be trasmitted. |
| 1070 | * |
| 1071 | * search function to reach at common channel to send action frame. When |
| 1072 | * channel is 0 then all social channels will be used to send af |
| 1073 | */ |
| 1074 | static s32 brcmf_p2p_act_frm_search(struct brcmf_p2p_info *p2p, u16 channel) |
| 1075 | { |
| 1076 | s32 err; |
| 1077 | u32 channel_cnt; |
| 1078 | u16 *default_chan_list; |
| 1079 | u32 i; |
| 1080 | |
| 1081 | brcmf_dbg(TRACE, "Enter\n"); |
| 1082 | |
| 1083 | if (channel) |
| 1084 | channel_cnt = AF_PEER_SEARCH_CNT; |
| 1085 | else |
| 1086 | channel_cnt = SOCIAL_CHAN_CNT; |
| 1087 | default_chan_list = kzalloc(channel_cnt * sizeof(*default_chan_list), |
| 1088 | GFP_KERNEL); |
| 1089 | if (default_chan_list == NULL) { |
| 1090 | brcmf_err("channel list allocation failed\n"); |
| 1091 | err = -ENOMEM; |
| 1092 | goto exit; |
| 1093 | } |
| 1094 | if (channel) { |
| 1095 | /* insert same channel to the chan_list */ |
| 1096 | for (i = 0; i < channel_cnt; i++) |
| 1097 | default_chan_list[i] = |
| 1098 | brcmf_p2p_chnr_to_chspec(channel); |
| 1099 | } else { |
| 1100 | default_chan_list[0] = brcmf_p2p_chnr_to_chspec(SOCIAL_CHAN_1); |
| 1101 | default_chan_list[1] = brcmf_p2p_chnr_to_chspec(SOCIAL_CHAN_2); |
| 1102 | default_chan_list[2] = brcmf_p2p_chnr_to_chspec(SOCIAL_CHAN_3); |
| 1103 | } |
| 1104 | err = brcmf_p2p_escan(p2p, channel_cnt, default_chan_list, |
| 1105 | WL_P2P_DISC_ST_SEARCH, WL_ESCAN_ACTION_START, |
| 1106 | P2PAPI_BSSCFG_DEVICE); |
| 1107 | kfree(default_chan_list); |
| 1108 | exit: |
| 1109 | return err; |
| 1110 | } |
| 1111 | |
| 1112 | |
| 1113 | /** |
| 1114 | * brcmf_p2p_afx_handler() - afx worker thread. |
| 1115 | * |
| 1116 | * @work: |
| 1117 | * |
| 1118 | */ |
| 1119 | static void brcmf_p2p_afx_handler(struct work_struct *work) |
| 1120 | { |
| 1121 | struct afx_hdl *afx_hdl = container_of(work, struct afx_hdl, afx_work); |
| 1122 | struct brcmf_p2p_info *p2p = container_of(afx_hdl, |
| 1123 | struct brcmf_p2p_info, |
| 1124 | afx_hdl); |
| 1125 | s32 err; |
| 1126 | |
| 1127 | if (!afx_hdl->is_active) |
| 1128 | return; |
| 1129 | |
| 1130 | if (afx_hdl->is_listen && afx_hdl->my_listen_chan) |
| 1131 | /* 100ms ~ 300ms */ |
| 1132 | err = brcmf_p2p_discover_listen(p2p, afx_hdl->my_listen_chan, |
| 1133 | 100 * (1 + (random32() % 3))); |
| 1134 | else |
| 1135 | err = brcmf_p2p_act_frm_search(p2p, afx_hdl->peer_listen_chan); |
| 1136 | |
| 1137 | if (err) { |
| 1138 | brcmf_err("ERROR occurred! value is (%d)\n", err); |
| 1139 | if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, |
| 1140 | &p2p->status)) |
| 1141 | complete(&afx_hdl->act_frm_scan); |
| 1142 | } |
| 1143 | } |
| 1144 | |
| 1145 | |
| 1146 | /** |
| 1147 | * brcmf_p2p_af_searching_channel() - search channel. |
| 1148 | * |
| 1149 | * @p2p: p2p device info struct. |
| 1150 | * |
| 1151 | */ |
| 1152 | static s32 brcmf_p2p_af_searching_channel(struct brcmf_p2p_info *p2p) |
| 1153 | { |
| 1154 | struct afx_hdl *afx_hdl = &p2p->afx_hdl; |
| 1155 | struct brcmf_cfg80211_vif *pri_vif; |
| 1156 | unsigned long duration; |
| 1157 | s32 retry; |
| 1158 | |
| 1159 | brcmf_dbg(TRACE, "Enter\n"); |
| 1160 | |
| 1161 | pri_vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif; |
| 1162 | |
| 1163 | INIT_COMPLETION(afx_hdl->act_frm_scan); |
| 1164 | set_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, &p2p->status); |
| 1165 | afx_hdl->is_active = true; |
| 1166 | afx_hdl->peer_chan = P2P_INVALID_CHANNEL; |
| 1167 | |
| 1168 | /* Loop to wait until we find a peer's channel or the |
| 1169 | * pending action frame tx is cancelled. |
| 1170 | */ |
| 1171 | retry = 0; |
| 1172 | duration = msecs_to_jiffies(P2P_AF_FRM_SCAN_MAX_WAIT); |
| 1173 | while ((retry < P2P_CHANNEL_SYNC_RETRY) && |
| 1174 | (afx_hdl->peer_chan == P2P_INVALID_CHANNEL)) { |
| 1175 | afx_hdl->is_listen = false; |
| 1176 | brcmf_dbg(TRACE, "Scheduling action frame for sending.. (%d)\n", |
| 1177 | retry); |
| 1178 | /* search peer on peer's listen channel */ |
| 1179 | schedule_work(&afx_hdl->afx_work); |
| 1180 | wait_for_completion_timeout(&afx_hdl->act_frm_scan, duration); |
| 1181 | if ((afx_hdl->peer_chan != P2P_INVALID_CHANNEL) || |
| 1182 | (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, |
| 1183 | &p2p->status))) |
| 1184 | break; |
| 1185 | |
| 1186 | if (afx_hdl->my_listen_chan) { |
| 1187 | brcmf_dbg(TRACE, "Scheduling listen peer, channel=%d\n", |
| 1188 | afx_hdl->my_listen_chan); |
| 1189 | /* listen on my listen channel */ |
| 1190 | afx_hdl->is_listen = true; |
| 1191 | schedule_work(&afx_hdl->afx_work); |
| 1192 | wait_for_completion_timeout(&afx_hdl->act_frm_scan, |
| 1193 | duration); |
| 1194 | } |
| 1195 | if ((afx_hdl->peer_chan != P2P_INVALID_CHANNEL) || |
| 1196 | (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, |
| 1197 | &p2p->status))) |
| 1198 | break; |
| 1199 | retry++; |
| 1200 | |
| 1201 | /* if sta is connected or connecting, sleep for a while before |
| 1202 | * retry af tx or finding a peer |
| 1203 | */ |
| 1204 | if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &pri_vif->sme_state) || |
| 1205 | test_bit(BRCMF_VIF_STATUS_CONNECTING, &pri_vif->sme_state)) |
| 1206 | msleep(P2P_DEFAULT_SLEEP_TIME_VSDB); |
| 1207 | } |
| 1208 | |
| 1209 | brcmf_dbg(TRACE, "Completed search/listen peer_chan=%d\n", |
| 1210 | afx_hdl->peer_chan); |
| 1211 | afx_hdl->is_active = false; |
| 1212 | |
| 1213 | clear_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, &p2p->status); |
| 1214 | |
| 1215 | return afx_hdl->peer_chan; |
| 1216 | } |
| 1217 | |
| 1218 | |
| 1219 | /** |
| 1220 | * brcmf_p2p_scan_finding_common_channel() - was escan used for finding channel |
| 1221 | * |
| 1222 | * @cfg: common configuration struct. |
| 1223 | * @bi: bss info struct, result from scan. |
| 1224 | * |
| 1225 | */ |
| 1226 | bool brcmf_p2p_scan_finding_common_channel(struct brcmf_cfg80211_info *cfg, |
| 1227 | struct brcmf_bss_info_le *bi) |
| 1228 | |
| 1229 | { |
| 1230 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
| 1231 | struct afx_hdl *afx_hdl = &p2p->afx_hdl; |
| 1232 | u8 *ie; |
| 1233 | s32 err; |
| 1234 | u8 p2p_dev_addr[ETH_ALEN]; |
| 1235 | |
| 1236 | if (!test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, &p2p->status)) |
| 1237 | return false; |
| 1238 | |
| 1239 | if (bi == NULL) { |
| 1240 | brcmf_dbg(TRACE, "ACTION FRAME SCAN Done\n"); |
| 1241 | if (afx_hdl->peer_chan == P2P_INVALID_CHANNEL) |
| 1242 | complete(&afx_hdl->act_frm_scan); |
| 1243 | return true; |
| 1244 | } |
| 1245 | |
| 1246 | ie = ((u8 *)bi) + le16_to_cpu(bi->ie_offset); |
| 1247 | memset(p2p_dev_addr, 0, sizeof(p2p_dev_addr)); |
| 1248 | err = cfg80211_get_p2p_attr(ie, le32_to_cpu(bi->ie_length), |
| 1249 | IEEE80211_P2P_ATTR_DEVICE_INFO, |
| 1250 | p2p_dev_addr, sizeof(p2p_dev_addr)); |
| 1251 | if (err < 0) |
| 1252 | err = cfg80211_get_p2p_attr(ie, le32_to_cpu(bi->ie_length), |
| 1253 | IEEE80211_P2P_ATTR_DEVICE_ID, |
| 1254 | p2p_dev_addr, sizeof(p2p_dev_addr)); |
| 1255 | if ((err >= 0) && |
| 1256 | (!memcmp(p2p_dev_addr, afx_hdl->tx_dst_addr, ETH_ALEN))) { |
| 1257 | afx_hdl->peer_chan = bi->ctl_ch ? bi->ctl_ch : |
| 1258 | CHSPEC_CHANNEL(le16_to_cpu(bi->chanspec)); |
| 1259 | brcmf_dbg(TRACE, "ACTION FRAME SCAN : Peer %pM found, channel : %d\n", |
| 1260 | afx_hdl->tx_dst_addr, afx_hdl->peer_chan); |
| 1261 | complete(&afx_hdl->act_frm_scan); |
| 1262 | } |
| 1263 | return true; |
| 1264 | } |
| 1265 | |
| 1266 | /** |
| 1267 | * brcmf_p2p_stop_wait_next_action_frame() - finish scan if af tx complete. |
| 1268 | * |
| 1269 | * @cfg: common configuration struct. |
| 1270 | * |
| 1271 | */ |
| 1272 | static void |
| 1273 | brcmf_p2p_stop_wait_next_action_frame(struct brcmf_cfg80211_info *cfg) |
| 1274 | { |
| 1275 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1276 | struct brcmf_if *ifp = cfg->escan_info.ifp; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1277 | |
| 1278 | if (test_bit(BRCMF_P2P_STATUS_SENDING_ACT_FRAME, &p2p->status) && |
| 1279 | (test_bit(BRCMF_P2P_STATUS_ACTION_TX_COMPLETED, &p2p->status) || |
| 1280 | test_bit(BRCMF_P2P_STATUS_ACTION_TX_NOACK, &p2p->status))) { |
| 1281 | brcmf_dbg(TRACE, "*** Wake UP ** abort actframe iovar\n"); |
| 1282 | /* if channel is not zero, "actfame" uses off channel scan. |
| 1283 | * So abort scan for off channel completion. |
| 1284 | */ |
| 1285 | if (p2p->af_sent_channel) |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1286 | brcmf_notify_escan_complete(cfg, ifp, true, true); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1287 | } else if (test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_AF_LISTEN, |
| 1288 | &p2p->status)) { |
| 1289 | brcmf_dbg(TRACE, "*** Wake UP ** abort listen for next af frame\n"); |
| 1290 | /* So abort scan to cancel listen */ |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 1291 | brcmf_notify_escan_complete(cfg, ifp, true, true); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1292 | } |
| 1293 | } |
| 1294 | |
| 1295 | |
| 1296 | /** |
| 1297 | * brcmf_p2p_gon_req_collision() - Check if go negotiaton collission |
| 1298 | * |
| 1299 | * @p2p: p2p device info struct. |
| 1300 | * |
| 1301 | * return true if recevied action frame is to be dropped. |
| 1302 | */ |
| 1303 | static bool |
| 1304 | brcmf_p2p_gon_req_collision(struct brcmf_p2p_info *p2p, u8 *mac) |
| 1305 | { |
| 1306 | struct brcmf_cfg80211_info *cfg = p2p->cfg; |
| 1307 | struct brcmf_if *ifp; |
| 1308 | |
| 1309 | brcmf_dbg(TRACE, "Enter\n"); |
| 1310 | |
| 1311 | if (!test_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, &p2p->status) || |
| 1312 | !p2p->gon_req_action) |
| 1313 | return false; |
| 1314 | |
| 1315 | brcmf_dbg(TRACE, "GO Negotiation Request COLLISION !!!\n"); |
| 1316 | /* if sa(peer) addr is less than da(my) addr, then this device |
| 1317 | * process peer's gon request and block to send gon req. |
| 1318 | * if not (sa addr > da addr), |
| 1319 | * this device will process gon request and drop gon req of peer. |
| 1320 | */ |
| 1321 | ifp = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif->ifp; |
| 1322 | if (memcmp(mac, ifp->mac_addr, ETH_ALEN) < 0) { |
| 1323 | brcmf_dbg(INFO, "Block transmit gon req !!!\n"); |
| 1324 | p2p->block_gon_req_tx = true; |
| 1325 | /* if we are finding a common channel for sending af, |
| 1326 | * do not scan more to block to send current gon req |
| 1327 | */ |
| 1328 | if (test_and_clear_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, |
| 1329 | &p2p->status)) |
| 1330 | complete(&p2p->afx_hdl.act_frm_scan); |
| 1331 | if (test_and_clear_bit(BRCMF_P2P_STATUS_WAITING_NEXT_ACT_FRAME, |
| 1332 | &p2p->status)) |
| 1333 | brcmf_p2p_stop_wait_next_action_frame(cfg); |
| 1334 | return false; |
| 1335 | } |
| 1336 | |
| 1337 | /* drop gon request of peer to process gon request by this device. */ |
| 1338 | brcmf_dbg(INFO, "Drop received gon req !!!\n"); |
| 1339 | |
| 1340 | return true; |
| 1341 | } |
| 1342 | |
| 1343 | |
| 1344 | /** |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 1345 | * brcmf_p2p_notify_action_frame_rx() - received action frame. |
| 1346 | * |
| 1347 | * @ifp: interfac control. |
| 1348 | * @e: event message. Not used, to make it usable for fweh event dispatcher. |
| 1349 | * @data: payload of message, containing action frame data. |
| 1350 | * |
| 1351 | */ |
| 1352 | int brcmf_p2p_notify_action_frame_rx(struct brcmf_if *ifp, |
| 1353 | const struct brcmf_event_msg *e, |
| 1354 | void *data) |
| 1355 | { |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1356 | struct brcmf_cfg80211_info *cfg = ifp->drvr->config; |
| 1357 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
| 1358 | struct afx_hdl *afx_hdl = &p2p->afx_hdl; |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 1359 | struct wireless_dev *wdev; |
| 1360 | u32 mgmt_frame_len = e->datalen - sizeof(struct brcmf_rx_mgmt_data); |
| 1361 | struct brcmf_rx_mgmt_data *rxframe = (struct brcmf_rx_mgmt_data *)data; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1362 | u8 *frame = (u8 *)(rxframe + 1); |
| 1363 | struct brcmf_p2p_pub_act_frame *act_frm; |
| 1364 | struct brcmf_p2psd_gas_pub_act_frame *sd_act_frm; |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 1365 | u16 chanspec = be16_to_cpu(rxframe->chanspec); |
| 1366 | struct ieee80211_mgmt *mgmt_frame; |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 1367 | s32 freq; |
| 1368 | u16 mgmt_type; |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1369 | u8 action; |
Hante Meuleman | e6da340 | 2013-02-08 15:53:48 +0100 | [diff] [blame] | 1370 | |
| 1371 | /* Check if wpa_supplicant has registered for this frame */ |
| 1372 | brcmf_dbg(INFO, "ifp->vif->mgmt_rx_reg %04x\n", ifp->vif->mgmt_rx_reg); |
| 1373 | mgmt_type = (IEEE80211_STYPE_ACTION & IEEE80211_FCTL_STYPE) >> 4; |
| 1374 | if ((ifp->vif->mgmt_rx_reg & BIT(mgmt_type)) == 0) |
| 1375 | return 0; |
| 1376 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1377 | brcmf_p2p_print_actframe(false, frame, mgmt_frame_len); |
| 1378 | |
| 1379 | action = P2P_PAF_SUBTYPE_INVALID; |
| 1380 | if (brcmf_p2p_is_pub_action(frame, mgmt_frame_len)) { |
| 1381 | act_frm = (struct brcmf_p2p_pub_act_frame *)frame; |
| 1382 | action = act_frm->subtype; |
| 1383 | if ((action == P2P_PAF_GON_REQ) && |
| 1384 | (brcmf_p2p_gon_req_collision(p2p, (u8 *)e->addr))) { |
| 1385 | if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, |
| 1386 | &p2p->status) && |
| 1387 | (memcmp(afx_hdl->tx_dst_addr, e->addr, |
| 1388 | ETH_ALEN) == 0)) { |
| 1389 | afx_hdl->peer_chan = CHSPEC_CHANNEL(chanspec); |
| 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 | |
| 1432 | freq = ieee80211_channel_to_frequency(CHSPEC_CHANNEL(chanspec), |
| 1433 | CHSPEC_IS2G(chanspec) ? |
| 1434 | IEEE80211_BAND_2GHZ : |
| 1435 | IEEE80211_BAND_5GHZ); |
| 1436 | wdev = ifp->ndev->ieee80211_ptr; |
| 1437 | cfg80211_rx_mgmt(wdev, freq, 0, (u8 *)mgmt_frame, mgmt_frame_len, |
| 1438 | GFP_ATOMIC); |
| 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 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1508 | INIT_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; |
| 1855 | struct wireless_dev *wdev; |
| 1856 | struct brcmf_cfg80211_vif *vif = ifp->vif; |
| 1857 | struct brcmf_rx_mgmt_data *rxframe = (struct brcmf_rx_mgmt_data *)data; |
| 1858 | u16 chanspec = be16_to_cpu(rxframe->chanspec); |
| 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 | |
| 1867 | if (test_bit(BRCMF_P2P_STATUS_FINDING_COMMON_CHANNEL, &p2p->status) && |
| 1868 | (memcmp(afx_hdl->tx_dst_addr, e->addr, ETH_ALEN) == 0)) { |
| 1869 | afx_hdl->peer_chan = CHSPEC_CHANNEL(chanspec); |
| 1870 | brcmf_dbg(INFO, "PROBE REQUEST: Peer found, channel=%d\n", |
| 1871 | afx_hdl->peer_chan); |
| 1872 | complete(&afx_hdl->act_frm_scan); |
| 1873 | } |
| 1874 | |
| 1875 | /* Firmware sends us two proberesponses for each idx one. At the */ |
| 1876 | /* moment anything but bsscfgidx 0 is passed up to supplicant */ |
| 1877 | if (e->bsscfgidx == 0) |
| 1878 | return 0; |
| 1879 | |
| 1880 | /* Filter any P2P probe reqs arriving during the GO-NEG Phase */ |
| 1881 | if (test_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status)) { |
| 1882 | brcmf_dbg(INFO, "Filtering P2P probe_req in GO-NEG phase\n"); |
| 1883 | return 0; |
| 1884 | } |
| 1885 | |
| 1886 | /* Check if wpa_supplicant has registered for this frame */ |
| 1887 | brcmf_dbg(INFO, "vif->mgmt_rx_reg %04x\n", vif->mgmt_rx_reg); |
| 1888 | mgmt_type = (IEEE80211_STYPE_PROBE_REQ & IEEE80211_FCTL_STYPE) >> 4; |
| 1889 | if ((vif->mgmt_rx_reg & BIT(mgmt_type)) == 0) |
| 1890 | return 0; |
| 1891 | |
| 1892 | mgmt_frame = (u8 *)(rxframe + 1); |
| 1893 | mgmt_frame_len = e->datalen - sizeof(*rxframe); |
| 1894 | freq = ieee80211_channel_to_frequency(CHSPEC_CHANNEL(chanspec), |
| 1895 | CHSPEC_IS2G(chanspec) ? |
| 1896 | IEEE80211_BAND_2GHZ : |
| 1897 | IEEE80211_BAND_5GHZ); |
| 1898 | wdev = ifp->ndev->ieee80211_ptr; |
| 1899 | cfg80211_rx_mgmt(wdev, freq, 0, mgmt_frame, mgmt_frame_len, GFP_ATOMIC); |
| 1900 | |
| 1901 | brcmf_dbg(INFO, "mgmt_frame_len (%d) , e->datalen (%d), chanspec (%04x), freq (%d)\n", |
| 1902 | mgmt_frame_len, e->datalen, chanspec, freq); |
| 1903 | |
| 1904 | return 0; |
| 1905 | } |
| 1906 | |
Hante Meuleman | 18e2f61 | 2013-02-08 15:53:49 +0100 | [diff] [blame] | 1907 | |
| 1908 | /** |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1909 | * brcmf_p2p_attach() - attach for P2P. |
| 1910 | * |
| 1911 | * @cfg: driver private data for cfg80211 interface. |
| 1912 | */ |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 1913 | s32 brcmf_p2p_attach(struct brcmf_cfg80211_info *cfg) |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1914 | { |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 1915 | struct brcmf_if *pri_ifp; |
| 1916 | struct brcmf_if *p2p_ifp; |
| 1917 | struct brcmf_cfg80211_vif *p2p_vif; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1918 | struct brcmf_p2p_info *p2p; |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 1919 | struct brcmf_pub *drvr; |
| 1920 | s32 bssidx; |
| 1921 | s32 err = 0; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1922 | |
| 1923 | p2p = &cfg->p2p; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1924 | p2p->cfg = cfg; |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 1925 | |
| 1926 | drvr = cfg->pub; |
| 1927 | |
| 1928 | pri_ifp = drvr->iflist[0]; |
| 1929 | p2p_ifp = drvr->iflist[1]; |
| 1930 | |
| 1931 | p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif = pri_ifp->vif; |
| 1932 | |
| 1933 | if (p2p_ifp) { |
Hante Meuleman | dded3d5 | 2013-02-08 15:53:57 +0100 | [diff] [blame] | 1934 | p2p_vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_P2P_DEVICE, |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 1935 | false); |
| 1936 | if (IS_ERR(p2p_vif)) { |
| 1937 | brcmf_err("could not create discovery vif\n"); |
| 1938 | err = -ENOMEM; |
| 1939 | goto exit; |
| 1940 | } |
| 1941 | |
| 1942 | p2p_vif->ifp = p2p_ifp; |
| 1943 | p2p_ifp->vif = p2p_vif; |
| 1944 | p2p_vif->wdev.netdev = p2p_ifp->ndev; |
| 1945 | p2p_ifp->ndev->ieee80211_ptr = &p2p_vif->wdev; |
| 1946 | SET_NETDEV_DEV(p2p_ifp->ndev, wiphy_dev(cfg->wiphy)); |
| 1947 | |
| 1948 | p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif = p2p_vif; |
| 1949 | |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame^] | 1950 | brcmf_p2p_generate_bss_mac(p2p, NULL); |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 1951 | brcmf_p2p_set_firmware(pri_ifp, p2p->dev_addr); |
| 1952 | |
| 1953 | /* Initialize P2P Discovery in the firmware */ |
| 1954 | err = brcmf_fil_iovar_int_set(pri_ifp, "p2p_disc", 1); |
| 1955 | if (err < 0) { |
| 1956 | brcmf_err("set p2p_disc error\n"); |
| 1957 | brcmf_free_vif(p2p_vif); |
| 1958 | goto exit; |
| 1959 | } |
| 1960 | /* obtain bsscfg index for P2P discovery */ |
| 1961 | err = brcmf_fil_iovar_int_get(pri_ifp, "p2p_dev", &bssidx); |
| 1962 | if (err < 0) { |
| 1963 | brcmf_err("retrieving discover bsscfg index failed\n"); |
| 1964 | brcmf_free_vif(p2p_vif); |
| 1965 | goto exit; |
| 1966 | } |
| 1967 | /* Verify that firmware uses same bssidx as driver !! */ |
| 1968 | if (p2p_ifp->bssidx != bssidx) { |
| 1969 | brcmf_err("Incorrect bssidx=%d, compared to p2p_ifp->bssidx=%d\n", |
| 1970 | bssidx, p2p_ifp->bssidx); |
| 1971 | brcmf_free_vif(p2p_vif); |
| 1972 | goto exit; |
| 1973 | } |
| 1974 | |
| 1975 | init_completion(&p2p->send_af_done); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 1976 | INIT_WORK(&p2p->afx_hdl.afx_work, brcmf_p2p_afx_handler); |
| 1977 | init_completion(&p2p->afx_hdl.act_frm_scan); |
| 1978 | init_completion(&p2p->wait_next_af); |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 1979 | } |
| 1980 | exit: |
| 1981 | return err; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1982 | } |
| 1983 | |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 1984 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 1985 | /** |
| 1986 | * brcmf_p2p_detach() - detach P2P. |
| 1987 | * |
| 1988 | * @p2p: P2P specific data. |
| 1989 | */ |
| 1990 | void brcmf_p2p_detach(struct brcmf_p2p_info *p2p) |
| 1991 | { |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 1992 | struct brcmf_cfg80211_vif *vif; |
| 1993 | |
| 1994 | vif = p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif; |
| 1995 | if (vif != NULL) { |
| 1996 | brcmf_p2p_cancel_remain_on_channel(vif->ifp); |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 1997 | brcmf_p2p_deinit_discovery(p2p); |
Hante Meuleman | 2fde59d | 2013-02-08 15:53:52 +0100 | [diff] [blame] | 1998 | /* remove discovery interface */ |
| 1999 | brcmf_free_vif(vif); |
| 2000 | p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif = NULL; |
Hante Meuleman | 0de8aac | 2013-02-08 15:53:38 +0100 | [diff] [blame] | 2001 | } |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 2002 | /* just set it all to zero */ |
| 2003 | memset(p2p, 0, sizeof(*p2p)); |
| 2004 | } |
| 2005 | |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 2006 | /** |
| 2007 | * brcmf_p2p_get_current_chanspec() - Get current operation channel. |
| 2008 | * |
| 2009 | * @p2p: P2P specific data. |
| 2010 | * @chanspec: chanspec to be returned. |
| 2011 | */ |
| 2012 | static void brcmf_p2p_get_current_chanspec(struct brcmf_p2p_info *p2p, |
| 2013 | u16 *chanspec) |
| 2014 | { |
| 2015 | struct brcmf_if *ifp; |
| 2016 | struct brcmf_fil_chan_info_le ci; |
| 2017 | s32 err; |
| 2018 | |
| 2019 | ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp; |
| 2020 | |
| 2021 | *chanspec = 11 & WL_CHANSPEC_CHAN_MASK; |
| 2022 | |
| 2023 | err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_CHANNEL, &ci, sizeof(ci)); |
| 2024 | if (!err) { |
| 2025 | *chanspec = le32_to_cpu(ci.hw_channel) & WL_CHANSPEC_CHAN_MASK; |
| 2026 | if (*chanspec < CH_MAX_2G_CHANNEL) |
| 2027 | *chanspec |= WL_CHANSPEC_BAND_2G; |
| 2028 | else |
| 2029 | *chanspec |= WL_CHANSPEC_BAND_5G; |
| 2030 | } |
| 2031 | *chanspec |= WL_CHANSPEC_BW_20 | WL_CHANSPEC_CTL_SB_NONE; |
| 2032 | } |
| 2033 | |
| 2034 | /** |
| 2035 | * Change a P2P Role. |
| 2036 | * Parameters: |
| 2037 | * @mac: MAC address of the BSS to change a role |
| 2038 | * Returns 0 if success. |
| 2039 | */ |
| 2040 | int brcmf_p2p_ifchange(struct brcmf_cfg80211_info *cfg, |
| 2041 | enum brcmf_fil_p2p_if_types if_type) |
| 2042 | { |
| 2043 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
| 2044 | struct brcmf_cfg80211_vif *vif; |
| 2045 | struct brcmf_fil_p2p_if_le if_request; |
| 2046 | s32 err; |
| 2047 | u16 chanspec; |
| 2048 | |
| 2049 | brcmf_dbg(TRACE, "Enter\n"); |
| 2050 | |
| 2051 | vif = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif; |
| 2052 | if (!vif) { |
| 2053 | brcmf_err("vif for P2PAPI_BSSCFG_PRIMARY does not exist\n"); |
| 2054 | return -EPERM; |
| 2055 | } |
Arend van Spriel | a0f472a | 2013-04-05 10:57:49 +0200 | [diff] [blame] | 2056 | brcmf_notify_escan_complete(cfg, vif->ifp, true, true); |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 2057 | vif = p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif; |
| 2058 | if (!vif) { |
| 2059 | brcmf_err("vif for P2PAPI_BSSCFG_CONNECTION does not exist\n"); |
| 2060 | return -EPERM; |
| 2061 | } |
Arend van Spriel | f96aa07 | 2013-04-05 10:57:48 +0200 | [diff] [blame] | 2062 | brcmf_set_mpc(vif->ifp, 0); |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 2063 | |
| 2064 | /* In concurrency case, STA may be already associated in a particular */ |
| 2065 | /* channel. so retrieve the current channel of primary interface and */ |
| 2066 | /* then start the virtual interface on that. */ |
| 2067 | brcmf_p2p_get_current_chanspec(p2p, &chanspec); |
| 2068 | |
| 2069 | if_request.type = cpu_to_le16((u16)if_type); |
| 2070 | if_request.chspec = cpu_to_le16(chanspec); |
| 2071 | memcpy(if_request.addr, p2p->int_addr, sizeof(if_request.addr)); |
| 2072 | |
| 2073 | brcmf_cfg80211_arm_vif_event(cfg, vif); |
| 2074 | err = brcmf_fil_iovar_data_set(vif->ifp, "p2p_ifupd", &if_request, |
| 2075 | sizeof(if_request)); |
| 2076 | if (err) { |
| 2077 | brcmf_err("p2p_ifupd FAILED, err=%d\n", err); |
| 2078 | brcmf_cfg80211_arm_vif_event(cfg, NULL); |
| 2079 | return err; |
| 2080 | } |
| 2081 | err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_CHANGE, |
| 2082 | msecs_to_jiffies(1500)); |
| 2083 | brcmf_cfg80211_arm_vif_event(cfg, NULL); |
| 2084 | if (!err) { |
| 2085 | brcmf_err("No BRCMF_E_IF_CHANGE event received\n"); |
| 2086 | return -EIO; |
| 2087 | } |
| 2088 | |
| 2089 | err = brcmf_fil_cmd_int_set(vif->ifp, BRCMF_C_SET_SCB_TIMEOUT, |
| 2090 | BRCMF_SCB_TIMEOUT_VALUE); |
| 2091 | |
| 2092 | return err; |
| 2093 | } |
| 2094 | |
| 2095 | static int brcmf_p2p_request_p2p_if(struct brcmf_p2p_info *p2p, |
| 2096 | struct brcmf_if *ifp, u8 ea[ETH_ALEN], |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2097 | enum brcmf_fil_p2p_if_types iftype) |
| 2098 | { |
| 2099 | struct brcmf_fil_p2p_if_le if_request; |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2100 | int err; |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 2101 | u16 chanspec; |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2102 | |
| 2103 | /* we need a default channel */ |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 2104 | brcmf_p2p_get_current_chanspec(p2p, &chanspec); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2105 | |
| 2106 | /* fill the firmware request */ |
| 2107 | memcpy(if_request.addr, ea, ETH_ALEN); |
Hante Meuleman | 7ee2d92 | 2013-02-08 15:53:43 +0100 | [diff] [blame] | 2108 | if_request.type = cpu_to_le16((u16)iftype); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2109 | if_request.chspec = cpu_to_le16(chanspec); |
| 2110 | |
| 2111 | err = brcmf_fil_iovar_data_set(ifp, "p2p_ifadd", &if_request, |
| 2112 | sizeof(if_request)); |
| 2113 | if (err) |
| 2114 | return err; |
| 2115 | |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2116 | return err; |
| 2117 | } |
| 2118 | |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 2119 | static int brcmf_p2p_disable_p2p_if(struct brcmf_cfg80211_vif *vif) |
| 2120 | { |
| 2121 | struct brcmf_cfg80211_info *cfg = wdev_to_cfg(&vif->wdev); |
| 2122 | struct net_device *pri_ndev = cfg_to_ndev(cfg); |
| 2123 | struct brcmf_if *ifp = netdev_priv(pri_ndev); |
| 2124 | u8 *addr = vif->wdev.netdev->dev_addr; |
| 2125 | |
| 2126 | return brcmf_fil_iovar_data_set(ifp, "p2p_ifdis", addr, ETH_ALEN); |
| 2127 | } |
| 2128 | |
| 2129 | static int brcmf_p2p_release_p2p_if(struct brcmf_cfg80211_vif *vif) |
| 2130 | { |
| 2131 | struct brcmf_cfg80211_info *cfg = wdev_to_cfg(&vif->wdev); |
| 2132 | struct net_device *pri_ndev = cfg_to_ndev(cfg); |
| 2133 | struct brcmf_if *ifp = netdev_priv(pri_ndev); |
| 2134 | u8 *addr = vif->wdev.netdev->dev_addr; |
| 2135 | |
| 2136 | return brcmf_fil_iovar_data_set(ifp, "p2p_ifdel", addr, ETH_ALEN); |
| 2137 | } |
| 2138 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 2139 | /** |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame^] | 2140 | * brcmf_p2p_create_p2pdev() - create a P2P_DEVICE virtual interface. |
| 2141 | * |
| 2142 | * @p2p: P2P specific data. |
| 2143 | * @wiphy: wiphy device of new interface. |
| 2144 | * @addr: mac address for this new interface. |
| 2145 | */ |
| 2146 | static struct wireless_dev *brcmf_p2p_create_p2pdev(struct brcmf_p2p_info *p2p, |
| 2147 | struct wiphy *wiphy, |
| 2148 | u8 *addr) |
| 2149 | { |
| 2150 | struct brcmf_cfg80211_vif *p2p_vif; |
| 2151 | struct brcmf_if *p2p_ifp; |
| 2152 | struct brcmf_if *pri_ifp; |
| 2153 | int err; |
| 2154 | u32 bssidx; |
| 2155 | |
| 2156 | if (p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif) |
| 2157 | return ERR_PTR(-ENOSPC); |
| 2158 | |
| 2159 | p2p_vif = brcmf_alloc_vif(p2p->cfg, NL80211_IFTYPE_P2P_DEVICE, |
| 2160 | false); |
| 2161 | if (IS_ERR(p2p_vif)) { |
| 2162 | brcmf_err("could not create discovery vif\n"); |
| 2163 | return (struct wireless_dev *)p2p_vif; |
| 2164 | } |
| 2165 | |
| 2166 | /* create ifp here */ |
| 2167 | p2p_ifp = kzalloc(sizeof(*p2p_ifp), GFP_KERNEL); |
| 2168 | if (!p2p_ifp) |
| 2169 | return ERR_PTR(-ENOMEM); |
| 2170 | |
| 2171 | p2p_vif->ifp = p2p_ifp; |
| 2172 | p2p_ifp->vif = p2p_vif; |
| 2173 | |
| 2174 | p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif = p2p_vif; |
| 2175 | brcmf_p2p_generate_bss_mac(p2p, addr); |
| 2176 | memcpy(&p2p_vif->wdev.address, p2p->dev_addr, sizeof(p2p->dev_addr)); |
| 2177 | |
| 2178 | pri_ifp = p2p->bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp; |
| 2179 | brcmf_p2p_set_firmware(pri_ifp, p2p->dev_addr); |
| 2180 | |
| 2181 | /* Initialize P2P Discovery in the firmware */ |
| 2182 | err = brcmf_fil_iovar_int_set(pri_ifp, "p2p_disc", 1); |
| 2183 | if (err < 0) { |
| 2184 | brcmf_err("set p2p_disc error\n"); |
| 2185 | brcmf_free_vif(p2p_vif); |
| 2186 | return ERR_PTR(err); |
| 2187 | } |
| 2188 | /* obtain bsscfg index for P2P discovery */ |
| 2189 | err = brcmf_fil_iovar_int_get(pri_ifp, "p2p_dev", &bssidx); |
| 2190 | if (err < 0) { |
| 2191 | brcmf_err("retrieving discover bsscfg index failed\n"); |
| 2192 | brcmf_free_vif(p2p_vif); |
| 2193 | return ERR_PTR(err); |
| 2194 | } |
| 2195 | |
| 2196 | p2p_ifp->drvr = p2p->cfg->pub; |
| 2197 | p2p_ifp->bssidx = bssidx; |
| 2198 | |
| 2199 | init_completion(&p2p->send_af_done); |
| 2200 | INIT_WORK(&p2p->afx_hdl.afx_work, brcmf_p2p_afx_handler); |
| 2201 | init_completion(&p2p->afx_hdl.act_frm_scan); |
| 2202 | init_completion(&p2p->wait_next_af); |
| 2203 | |
| 2204 | return &p2p_vif->wdev; |
| 2205 | } |
| 2206 | |
| 2207 | /** |
| 2208 | * brcmf_p2p_delete_p2pdev() - delete P2P_DEVICE virtual interface. |
| 2209 | * |
| 2210 | * @vif: virtual interface object to delete. |
| 2211 | */ |
| 2212 | static void brcmf_p2p_delete_p2pdev(struct brcmf_cfg80211_vif *vif) |
| 2213 | { |
| 2214 | struct brcmf_p2p_info *p2p = &vif->ifp->drvr->config->p2p; |
| 2215 | |
| 2216 | cfg80211_unregister_wdev(&vif->wdev); |
| 2217 | p2p->bss_idx[P2PAPI_BSSCFG_DEVICE].vif = NULL; |
| 2218 | kfree(vif->ifp); |
| 2219 | brcmf_free_vif(vif); |
| 2220 | } |
| 2221 | |
| 2222 | /** |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 2223 | * brcmf_p2p_add_vif() - create a new P2P virtual interface. |
| 2224 | * |
| 2225 | * @wiphy: wiphy device of new interface. |
| 2226 | * @name: name of the new interface. |
| 2227 | * @type: nl80211 interface type. |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame^] | 2228 | * @flags: not used. |
| 2229 | * @params: contains mac address for P2P device. |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 2230 | */ |
| 2231 | struct wireless_dev *brcmf_p2p_add_vif(struct wiphy *wiphy, const char *name, |
| 2232 | enum nl80211_iftype type, u32 *flags, |
| 2233 | struct vif_params *params) |
| 2234 | { |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2235 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 2236 | struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg)); |
| 2237 | struct brcmf_cfg80211_vif *vif; |
| 2238 | enum brcmf_fil_p2p_if_types iftype; |
| 2239 | enum wl_mode mode; |
| 2240 | int err; |
| 2241 | |
| 2242 | if (brcmf_cfg80211_vif_event_armed(cfg)) |
| 2243 | return ERR_PTR(-EBUSY); |
| 2244 | |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 2245 | brcmf_dbg(INFO, "adding vif \"%s\" (type=%d)\n", name, type); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2246 | |
| 2247 | switch (type) { |
| 2248 | case NL80211_IFTYPE_P2P_CLIENT: |
| 2249 | iftype = BRCMF_FIL_P2P_IF_CLIENT; |
| 2250 | mode = WL_MODE_BSS; |
| 2251 | break; |
| 2252 | case NL80211_IFTYPE_P2P_GO: |
| 2253 | iftype = BRCMF_FIL_P2P_IF_GO; |
| 2254 | mode = WL_MODE_AP; |
| 2255 | break; |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame^] | 2256 | case NL80211_IFTYPE_P2P_DEVICE: |
| 2257 | return brcmf_p2p_create_p2pdev(&cfg->p2p, wiphy, |
| 2258 | params->macaddr); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2259 | default: |
| 2260 | return ERR_PTR(-EOPNOTSUPP); |
| 2261 | } |
| 2262 | |
| 2263 | vif = brcmf_alloc_vif(cfg, type, false); |
Hante Meuleman | 7ee2d92 | 2013-02-08 15:53:43 +0100 | [diff] [blame] | 2264 | if (IS_ERR(vif)) |
| 2265 | return (struct wireless_dev *)vif; |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2266 | brcmf_cfg80211_arm_vif_event(cfg, vif); |
| 2267 | |
Hante Meuleman | 7a5c1f6 | 2013-02-08 15:53:44 +0100 | [diff] [blame] | 2268 | err = brcmf_p2p_request_p2p_if(&cfg->p2p, ifp, cfg->p2p.int_addr, |
| 2269 | iftype); |
Hante Meuleman | 7ee2d92 | 2013-02-08 15:53:43 +0100 | [diff] [blame] | 2270 | if (err) { |
| 2271 | brcmf_cfg80211_arm_vif_event(cfg, NULL); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2272 | goto fail; |
Hante Meuleman | 7ee2d92 | 2013-02-08 15:53:43 +0100 | [diff] [blame] | 2273 | } |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2274 | |
| 2275 | /* wait for firmware event */ |
| 2276 | err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_ADD, |
| 2277 | msecs_to_jiffies(1500)); |
| 2278 | brcmf_cfg80211_arm_vif_event(cfg, NULL); |
| 2279 | if (!err) { |
| 2280 | brcmf_err("timeout occurred\n"); |
| 2281 | err = -EIO; |
| 2282 | goto fail; |
| 2283 | } |
| 2284 | |
| 2285 | /* interface created in firmware */ |
| 2286 | ifp = vif->ifp; |
| 2287 | if (!ifp) { |
| 2288 | brcmf_err("no if pointer provided\n"); |
| 2289 | err = -ENOENT; |
Hante Meuleman | 7ee2d92 | 2013-02-08 15:53:43 +0100 | [diff] [blame] | 2290 | goto fail; |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2291 | } |
| 2292 | |
| 2293 | strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1); |
Hante Meuleman | 4b3a89d | 2013-02-08 15:54:01 +0100 | [diff] [blame] | 2294 | err = brcmf_net_attach(ifp, true); |
| 2295 | if (err) { |
| 2296 | brcmf_err("Registering netdevice failed\n"); |
| 2297 | goto fail; |
| 2298 | } |
Hante Meuleman | 7ee2d92 | 2013-02-08 15:53:43 +0100 | [diff] [blame] | 2299 | cfg->p2p.bss_idx[P2PAPI_BSSCFG_CONNECTION].vif = vif; |
| 2300 | /* Disable firmware roaming for P2P interface */ |
| 2301 | brcmf_fil_iovar_int_set(ifp, "roam_off", 1); |
| 2302 | if (iftype == BRCMF_FIL_P2P_IF_GO) { |
| 2303 | /* set station timeout for p2p */ |
| 2304 | brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCB_TIMEOUT, |
| 2305 | BRCMF_SCB_TIMEOUT_VALUE); |
| 2306 | } |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2307 | return &ifp->vif->wdev; |
| 2308 | |
| 2309 | fail: |
| 2310 | brcmf_free_vif(vif); |
| 2311 | return ERR_PTR(err); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | /** |
| 2315 | * brcmf_p2p_del_vif() - delete a P2P virtual interface. |
| 2316 | * |
| 2317 | * @wiphy: wiphy device of interface. |
| 2318 | * @wdev: wireless device of interface. |
| 2319 | * |
| 2320 | * TODO: not yet supported. |
| 2321 | */ |
| 2322 | int brcmf_p2p_del_vif(struct wiphy *wiphy, struct wireless_dev *wdev) |
| 2323 | { |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2324 | struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 2325 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 2326 | struct brcmf_cfg80211_vif *vif; |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 2327 | unsigned long jiffie_timeout = msecs_to_jiffies(1500); |
| 2328 | bool wait_for_disable = false; |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2329 | int err; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 2330 | |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 2331 | brcmf_dbg(TRACE, "delete P2P vif\n"); |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 2332 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2333 | |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 2334 | switch (vif->wdev.iftype) { |
| 2335 | case NL80211_IFTYPE_P2P_CLIENT: |
| 2336 | if (test_bit(BRCMF_VIF_STATUS_DISCONNECTING, &vif->sme_state)) |
| 2337 | wait_for_disable = true; |
| 2338 | break; |
| 2339 | |
| 2340 | case NL80211_IFTYPE_P2P_GO: |
| 2341 | if (!brcmf_p2p_disable_p2p_if(vif)) |
| 2342 | wait_for_disable = true; |
| 2343 | break; |
| 2344 | |
| 2345 | case NL80211_IFTYPE_P2P_DEVICE: |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame^] | 2346 | brcmf_p2p_delete_p2pdev(vif); |
| 2347 | return 0; |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 2348 | default: |
| 2349 | return -ENOTSUPP; |
| 2350 | break; |
| 2351 | } |
| 2352 | |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 2353 | clear_bit(BRCMF_P2P_STATUS_GO_NEG_PHASE, &p2p->status); |
| 2354 | brcmf_dbg(INFO, "P2P: GO_NEG_PHASE status cleared\n"); |
| 2355 | |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 2356 | if (wait_for_disable) |
Hante Meuleman | 7ee2d92 | 2013-02-08 15:53:43 +0100 | [diff] [blame] | 2357 | wait_for_completion_timeout(&cfg->vif_disabled, |
| 2358 | msecs_to_jiffies(500)); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 2359 | |
| 2360 | brcmf_vif_clear_mgmt_ies(vif); |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2361 | |
| 2362 | brcmf_cfg80211_arm_vif_event(cfg, vif); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 2363 | err = brcmf_p2p_release_p2p_if(vif); |
Hante Meuleman | 7ee2d92 | 2013-02-08 15:53:43 +0100 | [diff] [blame] | 2364 | if (!err) { |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 2365 | /* wait for firmware event */ |
| 2366 | err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_DEL, |
| 2367 | jiffie_timeout); |
Hante Meuleman | 7ee2d92 | 2013-02-08 15:53:43 +0100 | [diff] [blame] | 2368 | if (!err) |
| 2369 | err = -EIO; |
| 2370 | else |
| 2371 | err = 0; |
| 2372 | } |
Arend van Spriel | d3c0b63 | 2013-02-08 15:53:37 +0100 | [diff] [blame] | 2373 | brcmf_cfg80211_arm_vif_event(cfg, NULL); |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 2374 | brcmf_free_vif(vif); |
Hante Meuleman | 6eda4e2 | 2013-02-08 15:54:02 +0100 | [diff] [blame] | 2375 | p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif = NULL; |
Arend van Spriel | 5f4f9f1 | 2013-02-08 15:53:41 +0100 | [diff] [blame] | 2376 | |
| 2377 | return err; |
Arend van Spriel | 9f440b7 | 2013-02-08 15:53:36 +0100 | [diff] [blame] | 2378 | } |
Arend van Spriel | 27f10e3 | 2013-04-05 10:57:50 +0200 | [diff] [blame^] | 2379 | |
| 2380 | int brcmf_p2p_start_device(struct wiphy *wiphy, struct wireless_dev *wdev) |
| 2381 | { |
| 2382 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 2383 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
| 2384 | struct brcmf_cfg80211_vif *vif; |
| 2385 | int err; |
| 2386 | |
| 2387 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
| 2388 | mutex_lock(&cfg->usr_sync); |
| 2389 | err = brcmf_p2p_enable_discovery(p2p); |
| 2390 | if (!err) |
| 2391 | set_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state); |
| 2392 | mutex_unlock(&cfg->usr_sync); |
| 2393 | return err; |
| 2394 | } |
| 2395 | |
| 2396 | void brcmf_p2p_stop_device(struct wiphy *wiphy, struct wireless_dev *wdev) |
| 2397 | { |
| 2398 | struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy); |
| 2399 | struct brcmf_p2p_info *p2p = &cfg->p2p; |
| 2400 | struct brcmf_cfg80211_vif *vif; |
| 2401 | |
| 2402 | vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev); |
| 2403 | mutex_lock(&cfg->usr_sync); |
| 2404 | (void)brcmf_p2p_deinit_discovery(p2p); |
| 2405 | brcmf_abort_scanning(cfg); |
| 2406 | clear_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state); |
| 2407 | mutex_unlock(&cfg->usr_sync); |
| 2408 | } |