1 /* 2 * Copyright (c) 2004-2011 Atheros Communications Inc. 3 * Copyright (c) 2011-2012 Qualcomm Atheros, Inc. 4 * 5 * Permission to use, copy, modify, and/or distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #include <linux/ip.h> 19 #include "core.h" 20 #include "debug.h" 21 #include "testmode.h" 22 #include "../regd.h" 23 #include "../regd_common.h" 24 25 static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx); 26 27 static const s32 wmi_rate_tbl[][2] = { 28 /* {W/O SGI, with SGI} */ 29 {1000, 1000}, 30 {2000, 2000}, 31 {5500, 5500}, 32 {11000, 11000}, 33 {6000, 6000}, 34 {9000, 9000}, 35 {12000, 12000}, 36 {18000, 18000}, 37 {24000, 24000}, 38 {36000, 36000}, 39 {48000, 48000}, 40 {54000, 54000}, 41 {6500, 7200}, 42 {13000, 14400}, 43 {19500, 21700}, 44 {26000, 28900}, 45 {39000, 43300}, 46 {52000, 57800}, 47 {58500, 65000}, 48 {65000, 72200}, 49 {13500, 15000}, 50 {27000, 30000}, 51 {40500, 45000}, 52 {54000, 60000}, 53 {81000, 90000}, 54 {108000, 120000}, 55 {121500, 135000}, 56 {135000, 150000}, 57 {0, 0} 58 }; 59 60 /* 802.1d to AC mapping. Refer pg 57 of WMM-test-plan-v1.2 */ 61 static const u8 up_to_ac[] = { 62 WMM_AC_BE, 63 WMM_AC_BK, 64 WMM_AC_BK, 65 WMM_AC_BE, 66 WMM_AC_VI, 67 WMM_AC_VI, 68 WMM_AC_VO, 69 WMM_AC_VO, 70 }; 71 72 void ath6kl_wmi_set_control_ep(struct wmi *wmi, enum htc_endpoint_id ep_id) 73 { 74 if (WARN_ON(ep_id == ENDPOINT_UNUSED || ep_id >= ENDPOINT_MAX)) 75 return; 76 77 wmi->ep_id = ep_id; 78 } 79 80 enum htc_endpoint_id ath6kl_wmi_get_control_ep(struct wmi *wmi) 81 { 82 return wmi->ep_id; 83 } 84 85 struct ath6kl_vif *ath6kl_get_vif_by_index(struct ath6kl *ar, u8 if_idx) 86 { 87 struct ath6kl_vif *vif, *found = NULL; 88 89 if (WARN_ON(if_idx > (ar->vif_max - 1))) 90 return NULL; 91 92 /* FIXME: Locking */ 93 spin_lock_bh(&ar->list_lock); 94 list_for_each_entry(vif, &ar->vif_list, list) { 95 if (vif->fw_vif_idx == if_idx) { 96 found = vif; 97 break; 98 } 99 } 100 spin_unlock_bh(&ar->list_lock); 101 102 return found; 103 } 104 105 /* Performs DIX to 802.3 encapsulation for transmit packets. 106 * Assumes the entire DIX header is contigous and that there is 107 * enough room in the buffer for a 802.3 mac header and LLC+SNAP headers. 108 */ 109 int ath6kl_wmi_dix_2_dot3(struct wmi *wmi, struct sk_buff *skb) 110 { 111 struct ath6kl_llc_snap_hdr *llc_hdr; 112 struct ethhdr *eth_hdr; 113 size_t new_len; 114 __be16 type; 115 u8 *datap; 116 u16 size; 117 118 if (WARN_ON(skb == NULL)) 119 return -EINVAL; 120 121 size = sizeof(struct ath6kl_llc_snap_hdr) + sizeof(struct wmi_data_hdr); 122 if (skb_headroom(skb) < size) 123 return -ENOMEM; 124 125 eth_hdr = (struct ethhdr *) skb->data; 126 type = eth_hdr->h_proto; 127 128 if (!is_ethertype(be16_to_cpu(type))) { 129 ath6kl_dbg(ATH6KL_DBG_WMI, 130 "%s: pkt is already in 802.3 format\n", __func__); 131 return 0; 132 } 133 134 new_len = skb->len - sizeof(*eth_hdr) + sizeof(*llc_hdr); 135 136 skb_push(skb, sizeof(struct ath6kl_llc_snap_hdr)); 137 datap = skb->data; 138 139 eth_hdr->h_proto = cpu_to_be16(new_len); 140 141 memcpy(datap, eth_hdr, sizeof(*eth_hdr)); 142 143 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap + sizeof(*eth_hdr)); 144 llc_hdr->dsap = 0xAA; 145 llc_hdr->ssap = 0xAA; 146 llc_hdr->cntl = 0x03; 147 llc_hdr->org_code[0] = 0x0; 148 llc_hdr->org_code[1] = 0x0; 149 llc_hdr->org_code[2] = 0x0; 150 llc_hdr->eth_type = type; 151 152 return 0; 153 } 154 155 static int ath6kl_wmi_meta_add(struct wmi *wmi, struct sk_buff *skb, 156 u8 *version, void *tx_meta_info) 157 { 158 struct wmi_tx_meta_v1 *v1; 159 struct wmi_tx_meta_v2 *v2; 160 161 if (WARN_ON(skb == NULL || version == NULL)) 162 return -EINVAL; 163 164 switch (*version) { 165 case WMI_META_VERSION_1: 166 skb_push(skb, WMI_MAX_TX_META_SZ); 167 v1 = (struct wmi_tx_meta_v1 *) skb->data; 168 v1->pkt_id = 0; 169 v1->rate_plcy_id = 0; 170 *version = WMI_META_VERSION_1; 171 break; 172 case WMI_META_VERSION_2: 173 skb_push(skb, WMI_MAX_TX_META_SZ); 174 v2 = (struct wmi_tx_meta_v2 *) skb->data; 175 memcpy(v2, (struct wmi_tx_meta_v2 *) tx_meta_info, 176 sizeof(struct wmi_tx_meta_v2)); 177 break; 178 } 179 180 return 0; 181 } 182 183 int ath6kl_wmi_data_hdr_add(struct wmi *wmi, struct sk_buff *skb, 184 u8 msg_type, u32 flags, 185 enum wmi_data_hdr_data_type data_type, 186 u8 meta_ver, void *tx_meta_info, u8 if_idx) 187 { 188 struct wmi_data_hdr *data_hdr; 189 int ret; 190 191 if (WARN_ON(skb == NULL || (if_idx > wmi->parent_dev->vif_max - 1))) 192 return -EINVAL; 193 194 if (tx_meta_info) { 195 ret = ath6kl_wmi_meta_add(wmi, skb, &meta_ver, tx_meta_info); 196 if (ret) 197 return ret; 198 } 199 200 skb_push(skb, sizeof(struct wmi_data_hdr)); 201 202 data_hdr = (struct wmi_data_hdr *)skb->data; 203 memset(data_hdr, 0, sizeof(struct wmi_data_hdr)); 204 205 data_hdr->info = msg_type << WMI_DATA_HDR_MSG_TYPE_SHIFT; 206 data_hdr->info |= data_type << WMI_DATA_HDR_DATA_TYPE_SHIFT; 207 208 if (flags & WMI_DATA_HDR_FLAGS_MORE) 209 data_hdr->info |= WMI_DATA_HDR_MORE; 210 211 if (flags & WMI_DATA_HDR_FLAGS_EOSP) 212 data_hdr->info3 |= cpu_to_le16(WMI_DATA_HDR_EOSP); 213 214 data_hdr->info2 |= cpu_to_le16(meta_ver << WMI_DATA_HDR_META_SHIFT); 215 data_hdr->info3 |= cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK); 216 217 return 0; 218 } 219 220 u8 ath6kl_wmi_determine_user_priority(u8 *pkt, u32 layer2_pri) 221 { 222 struct iphdr *ip_hdr = (struct iphdr *) pkt; 223 u8 ip_pri; 224 225 /* 226 * Determine IPTOS priority 227 * 228 * IP-TOS - 8bits 229 * : DSCP(6-bits) ECN(2-bits) 230 * : DSCP - P2 P1 P0 X X X 231 * where (P2 P1 P0) form 802.1D 232 */ 233 ip_pri = ip_hdr->tos >> 5; 234 ip_pri &= 0x7; 235 236 if ((layer2_pri & 0x7) > ip_pri) 237 return (u8) layer2_pri & 0x7; 238 else 239 return ip_pri; 240 } 241 242 u8 ath6kl_wmi_get_traffic_class(u8 user_priority) 243 { 244 return up_to_ac[user_priority & 0x7]; 245 } 246 247 int ath6kl_wmi_implicit_create_pstream(struct wmi *wmi, u8 if_idx, 248 struct sk_buff *skb, 249 u32 layer2_priority, bool wmm_enabled, 250 u8 *ac) 251 { 252 struct wmi_data_hdr *data_hdr; 253 struct ath6kl_llc_snap_hdr *llc_hdr; 254 struct wmi_create_pstream_cmd cmd; 255 u32 meta_size, hdr_size; 256 u16 ip_type = IP_ETHERTYPE; 257 u8 stream_exist, usr_pri; 258 u8 traffic_class = WMM_AC_BE; 259 u8 *datap; 260 261 if (WARN_ON(skb == NULL)) 262 return -EINVAL; 263 264 datap = skb->data; 265 data_hdr = (struct wmi_data_hdr *) datap; 266 267 meta_size = ((le16_to_cpu(data_hdr->info2) >> WMI_DATA_HDR_META_SHIFT) & 268 WMI_DATA_HDR_META_MASK) ? WMI_MAX_TX_META_SZ : 0; 269 270 if (!wmm_enabled) { 271 /* If WMM is disabled all traffic goes as BE traffic */ 272 usr_pri = 0; 273 } else { 274 hdr_size = sizeof(struct ethhdr); 275 276 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap + 277 sizeof(struct 278 wmi_data_hdr) + 279 meta_size + hdr_size); 280 281 if (llc_hdr->eth_type == htons(ip_type)) { 282 /* 283 * Extract the endpoint info from the TOS field 284 * in the IP header. 285 */ 286 usr_pri = 287 ath6kl_wmi_determine_user_priority(((u8 *) llc_hdr) + 288 sizeof(struct ath6kl_llc_snap_hdr), 289 layer2_priority); 290 } else 291 usr_pri = layer2_priority & 0x7; 292 } 293 294 /* 295 * workaround for WMM S5 296 * 297 * FIXME: wmi->traffic_class is always 100 so this test doesn't 298 * make sense 299 */ 300 if ((wmi->traffic_class == WMM_AC_VI) && 301 ((usr_pri == 5) || (usr_pri == 4))) 302 usr_pri = 1; 303 304 /* Convert user priority to traffic class */ 305 traffic_class = up_to_ac[usr_pri & 0x7]; 306 307 wmi_data_hdr_set_up(data_hdr, usr_pri); 308 309 spin_lock_bh(&wmi->lock); 310 stream_exist = wmi->fat_pipe_exist; 311 spin_unlock_bh(&wmi->lock); 312 313 if (!(stream_exist & (1 << traffic_class))) { 314 memset(&cmd, 0, sizeof(cmd)); 315 cmd.traffic_class = traffic_class; 316 cmd.user_pri = usr_pri; 317 cmd.inactivity_int = 318 cpu_to_le32(WMI_IMPLICIT_PSTREAM_INACTIVITY_INT); 319 /* Implicit streams are created with TSID 0xFF */ 320 cmd.tsid = WMI_IMPLICIT_PSTREAM; 321 ath6kl_wmi_create_pstream_cmd(wmi, if_idx, &cmd); 322 } 323 324 *ac = traffic_class; 325 326 return 0; 327 } 328 329 int ath6kl_wmi_dot11_hdr_remove(struct wmi *wmi, struct sk_buff *skb) 330 { 331 struct ieee80211_hdr_3addr *pwh, wh; 332 struct ath6kl_llc_snap_hdr *llc_hdr; 333 struct ethhdr eth_hdr; 334 u32 hdr_size; 335 u8 *datap; 336 __le16 sub_type; 337 338 if (WARN_ON(skb == NULL)) 339 return -EINVAL; 340 341 datap = skb->data; 342 pwh = (struct ieee80211_hdr_3addr *) datap; 343 344 sub_type = pwh->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE); 345 346 memcpy((u8 *) &wh, datap, sizeof(struct ieee80211_hdr_3addr)); 347 348 /* Strip off the 802.11 header */ 349 if (sub_type == cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) { 350 hdr_size = roundup(sizeof(struct ieee80211_qos_hdr), 351 sizeof(u32)); 352 skb_pull(skb, hdr_size); 353 } else if (sub_type == cpu_to_le16(IEEE80211_STYPE_DATA)) 354 skb_pull(skb, sizeof(struct ieee80211_hdr_3addr)); 355 356 datap = skb->data; 357 llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap); 358 359 memset(ð_hdr, 0, sizeof(eth_hdr)); 360 eth_hdr.h_proto = llc_hdr->eth_type; 361 362 switch ((le16_to_cpu(wh.frame_control)) & 363 (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) { 364 case 0: 365 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN); 366 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN); 367 break; 368 case IEEE80211_FCTL_TODS: 369 memcpy(eth_hdr.h_dest, wh.addr3, ETH_ALEN); 370 memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN); 371 break; 372 case IEEE80211_FCTL_FROMDS: 373 memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN); 374 memcpy(eth_hdr.h_source, wh.addr3, ETH_ALEN); 375 break; 376 case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS: 377 break; 378 } 379 380 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr)); 381 skb_push(skb, sizeof(eth_hdr)); 382 383 datap = skb->data; 384 385 memcpy(datap, ð_hdr, sizeof(eth_hdr)); 386 387 return 0; 388 } 389 390 /* 391 * Performs 802.3 to DIX encapsulation for received packets. 392 * Assumes the entire 802.3 header is contigous. 393 */ 394 int ath6kl_wmi_dot3_2_dix(struct sk_buff *skb) 395 { 396 struct ath6kl_llc_snap_hdr *llc_hdr; 397 struct ethhdr eth_hdr; 398 u8 *datap; 399 400 if (WARN_ON(skb == NULL)) 401 return -EINVAL; 402 403 datap = skb->data; 404 405 memcpy(ð_hdr, datap, sizeof(eth_hdr)); 406 407 llc_hdr = (struct ath6kl_llc_snap_hdr *) (datap + sizeof(eth_hdr)); 408 eth_hdr.h_proto = llc_hdr->eth_type; 409 410 skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr)); 411 datap = skb->data; 412 413 memcpy(datap, ð_hdr, sizeof(eth_hdr)); 414 415 return 0; 416 } 417 418 static int ath6kl_wmi_tx_complete_event_rx(u8 *datap, int len) 419 { 420 struct tx_complete_msg_v1 *msg_v1; 421 struct wmi_tx_complete_event *evt; 422 int index; 423 u16 size; 424 425 evt = (struct wmi_tx_complete_event *) datap; 426 427 ath6kl_dbg(ATH6KL_DBG_WMI, "comp: %d %d %d\n", 428 evt->num_msg, evt->msg_len, evt->msg_type); 429 430 for (index = 0; index < evt->num_msg; index++) { 431 size = sizeof(struct wmi_tx_complete_event) + 432 (index * sizeof(struct tx_complete_msg_v1)); 433 msg_v1 = (struct tx_complete_msg_v1 *)(datap + size); 434 435 ath6kl_dbg(ATH6KL_DBG_WMI, "msg: %d %d %d %d\n", 436 msg_v1->status, msg_v1->pkt_id, 437 msg_v1->rate_idx, msg_v1->ack_failures); 438 } 439 440 return 0; 441 } 442 443 static int ath6kl_wmi_remain_on_chnl_event_rx(struct wmi *wmi, u8 *datap, 444 int len, struct ath6kl_vif *vif) 445 { 446 struct wmi_remain_on_chnl_event *ev; 447 u32 freq; 448 u32 dur; 449 struct ieee80211_channel *chan; 450 struct ath6kl *ar = wmi->parent_dev; 451 u32 id; 452 453 if (len < sizeof(*ev)) 454 return -EINVAL; 455 456 ev = (struct wmi_remain_on_chnl_event *) datap; 457 freq = le32_to_cpu(ev->freq); 458 dur = le32_to_cpu(ev->duration); 459 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: freq=%u dur=%u\n", 460 freq, dur); 461 chan = ieee80211_get_channel(ar->wiphy, freq); 462 if (!chan) { 463 ath6kl_dbg(ATH6KL_DBG_WMI, 464 "remain_on_chnl: Unknown channel (freq=%u)\n", 465 freq); 466 return -EINVAL; 467 } 468 id = vif->last_roc_id; 469 cfg80211_ready_on_channel(vif->ndev, id, chan, NL80211_CHAN_NO_HT, 470 dur, GFP_ATOMIC); 471 472 return 0; 473 } 474 475 static int ath6kl_wmi_cancel_remain_on_chnl_event_rx(struct wmi *wmi, 476 u8 *datap, int len, 477 struct ath6kl_vif *vif) 478 { 479 struct wmi_cancel_remain_on_chnl_event *ev; 480 u32 freq; 481 u32 dur; 482 struct ieee80211_channel *chan; 483 struct ath6kl *ar = wmi->parent_dev; 484 u32 id; 485 486 if (len < sizeof(*ev)) 487 return -EINVAL; 488 489 ev = (struct wmi_cancel_remain_on_chnl_event *) datap; 490 freq = le32_to_cpu(ev->freq); 491 dur = le32_to_cpu(ev->duration); 492 ath6kl_dbg(ATH6KL_DBG_WMI, 493 "cancel_remain_on_chnl: freq=%u dur=%u status=%u\n", 494 freq, dur, ev->status); 495 chan = ieee80211_get_channel(ar->wiphy, freq); 496 if (!chan) { 497 ath6kl_dbg(ATH6KL_DBG_WMI, 498 "cancel_remain_on_chnl: Unknown channel (freq=%u)\n", 499 freq); 500 return -EINVAL; 501 } 502 if (vif->last_cancel_roc_id && 503 vif->last_cancel_roc_id + 1 == vif->last_roc_id) 504 id = vif->last_cancel_roc_id; /* event for cancel command */ 505 else 506 id = vif->last_roc_id; /* timeout on uncanceled r-o-c */ 507 vif->last_cancel_roc_id = 0; 508 cfg80211_remain_on_channel_expired(vif->ndev, id, chan, 509 NL80211_CHAN_NO_HT, GFP_ATOMIC); 510 511 return 0; 512 } 513 514 static int ath6kl_wmi_tx_status_event_rx(struct wmi *wmi, u8 *datap, int len, 515 struct ath6kl_vif *vif) 516 { 517 struct wmi_tx_status_event *ev; 518 u32 id; 519 520 if (len < sizeof(*ev)) 521 return -EINVAL; 522 523 ev = (struct wmi_tx_status_event *) datap; 524 id = le32_to_cpu(ev->id); 525 ath6kl_dbg(ATH6KL_DBG_WMI, "tx_status: id=%x ack_status=%u\n", 526 id, ev->ack_status); 527 if (wmi->last_mgmt_tx_frame) { 528 cfg80211_mgmt_tx_status(vif->ndev, id, 529 wmi->last_mgmt_tx_frame, 530 wmi->last_mgmt_tx_frame_len, 531 !!ev->ack_status, GFP_ATOMIC); 532 kfree(wmi->last_mgmt_tx_frame); 533 wmi->last_mgmt_tx_frame = NULL; 534 wmi->last_mgmt_tx_frame_len = 0; 535 } 536 537 return 0; 538 } 539 540 static int ath6kl_wmi_rx_probe_req_event_rx(struct wmi *wmi, u8 *datap, int len, 541 struct ath6kl_vif *vif) 542 { 543 struct wmi_p2p_rx_probe_req_event *ev; 544 u32 freq; 545 u16 dlen; 546 547 if (len < sizeof(*ev)) 548 return -EINVAL; 549 550 ev = (struct wmi_p2p_rx_probe_req_event *) datap; 551 freq = le32_to_cpu(ev->freq); 552 dlen = le16_to_cpu(ev->len); 553 if (datap + len < ev->data + dlen) { 554 ath6kl_err("invalid wmi_p2p_rx_probe_req_event: len=%d dlen=%u\n", 555 len, dlen); 556 return -EINVAL; 557 } 558 ath6kl_dbg(ATH6KL_DBG_WMI, 559 "rx_probe_req: len=%u freq=%u probe_req_report=%d\n", 560 dlen, freq, vif->probe_req_report); 561 562 if (vif->probe_req_report || vif->nw_type == AP_NETWORK) 563 cfg80211_rx_mgmt(vif->ndev, freq, 0, 564 ev->data, dlen, GFP_ATOMIC); 565 566 return 0; 567 } 568 569 static int ath6kl_wmi_p2p_capabilities_event_rx(u8 *datap, int len) 570 { 571 struct wmi_p2p_capabilities_event *ev; 572 u16 dlen; 573 574 if (len < sizeof(*ev)) 575 return -EINVAL; 576 577 ev = (struct wmi_p2p_capabilities_event *) datap; 578 dlen = le16_to_cpu(ev->len); 579 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_capab: len=%u\n", dlen); 580 581 return 0; 582 } 583 584 static int ath6kl_wmi_rx_action_event_rx(struct wmi *wmi, u8 *datap, int len, 585 struct ath6kl_vif *vif) 586 { 587 struct wmi_rx_action_event *ev; 588 u32 freq; 589 u16 dlen; 590 591 if (len < sizeof(*ev)) 592 return -EINVAL; 593 594 ev = (struct wmi_rx_action_event *) datap; 595 freq = le32_to_cpu(ev->freq); 596 dlen = le16_to_cpu(ev->len); 597 if (datap + len < ev->data + dlen) { 598 ath6kl_err("invalid wmi_rx_action_event: len=%d dlen=%u\n", 599 len, dlen); 600 return -EINVAL; 601 } 602 ath6kl_dbg(ATH6KL_DBG_WMI, "rx_action: len=%u freq=%u\n", dlen, freq); 603 cfg80211_rx_mgmt(vif->ndev, freq, 0, 604 ev->data, dlen, GFP_ATOMIC); 605 606 return 0; 607 } 608 609 static int ath6kl_wmi_p2p_info_event_rx(u8 *datap, int len) 610 { 611 struct wmi_p2p_info_event *ev; 612 u32 flags; 613 u16 dlen; 614 615 if (len < sizeof(*ev)) 616 return -EINVAL; 617 618 ev = (struct wmi_p2p_info_event *) datap; 619 flags = le32_to_cpu(ev->info_req_flags); 620 dlen = le16_to_cpu(ev->len); 621 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: flags=%x len=%d\n", flags, dlen); 622 623 if (flags & P2P_FLAG_CAPABILITIES_REQ) { 624 struct wmi_p2p_capabilities *cap; 625 if (dlen < sizeof(*cap)) 626 return -EINVAL; 627 cap = (struct wmi_p2p_capabilities *) ev->data; 628 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: GO Power Save = %d\n", 629 cap->go_power_save); 630 } 631 632 if (flags & P2P_FLAG_MACADDR_REQ) { 633 struct wmi_p2p_macaddr *mac; 634 if (dlen < sizeof(*mac)) 635 return -EINVAL; 636 mac = (struct wmi_p2p_macaddr *) ev->data; 637 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: MAC Address = %pM\n", 638 mac->mac_addr); 639 } 640 641 if (flags & P2P_FLAG_HMODEL_REQ) { 642 struct wmi_p2p_hmodel *mod; 643 if (dlen < sizeof(*mod)) 644 return -EINVAL; 645 mod = (struct wmi_p2p_hmodel *) ev->data; 646 ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: P2P Model = %d (%s)\n", 647 mod->p2p_model, 648 mod->p2p_model ? "host" : "firmware"); 649 } 650 return 0; 651 } 652 653 static inline struct sk_buff *ath6kl_wmi_get_new_buf(u32 size) 654 { 655 struct sk_buff *skb; 656 657 skb = ath6kl_buf_alloc(size); 658 if (!skb) 659 return NULL; 660 661 skb_put(skb, size); 662 if (size) 663 memset(skb->data, 0, size); 664 665 return skb; 666 } 667 668 /* Send a "simple" wmi command -- one with no arguments */ 669 static int ath6kl_wmi_simple_cmd(struct wmi *wmi, u8 if_idx, 670 enum wmi_cmd_id cmd_id) 671 { 672 struct sk_buff *skb; 673 int ret; 674 675 skb = ath6kl_wmi_get_new_buf(0); 676 if (!skb) 677 return -ENOMEM; 678 679 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, cmd_id, NO_SYNC_WMIFLAG); 680 681 return ret; 682 } 683 684 static int ath6kl_wmi_ready_event_rx(struct wmi *wmi, u8 *datap, int len) 685 { 686 struct wmi_ready_event_2 *ev = (struct wmi_ready_event_2 *) datap; 687 688 if (len < sizeof(struct wmi_ready_event_2)) 689 return -EINVAL; 690 691 ath6kl_ready_event(wmi->parent_dev, ev->mac_addr, 692 le32_to_cpu(ev->sw_version), 693 le32_to_cpu(ev->abi_version), ev->phy_cap); 694 695 return 0; 696 } 697 698 /* 699 * Mechanism to modify the roaming behavior in the firmware. The lower rssi 700 * at which the station has to roam can be passed with 701 * WMI_SET_LRSSI_SCAN_PARAMS. Subtract 96 from RSSI to get the signal level 702 * in dBm. 703 */ 704 int ath6kl_wmi_set_roam_lrssi_cmd(struct wmi *wmi, u8 lrssi) 705 { 706 struct sk_buff *skb; 707 struct roam_ctrl_cmd *cmd; 708 709 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 710 if (!skb) 711 return -ENOMEM; 712 713 cmd = (struct roam_ctrl_cmd *) skb->data; 714 715 cmd->info.params.lrssi_scan_period = cpu_to_le16(DEF_LRSSI_SCAN_PERIOD); 716 cmd->info.params.lrssi_scan_threshold = a_cpu_to_sle16(lrssi + 717 DEF_SCAN_FOR_ROAM_INTVL); 718 cmd->info.params.lrssi_roam_threshold = a_cpu_to_sle16(lrssi); 719 cmd->info.params.roam_rssi_floor = DEF_LRSSI_ROAM_FLOOR; 720 cmd->roam_ctrl = WMI_SET_LRSSI_SCAN_PARAMS; 721 722 ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID, 723 NO_SYNC_WMIFLAG); 724 725 return 0; 726 } 727 728 int ath6kl_wmi_force_roam_cmd(struct wmi *wmi, const u8 *bssid) 729 { 730 struct sk_buff *skb; 731 struct roam_ctrl_cmd *cmd; 732 733 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 734 if (!skb) 735 return -ENOMEM; 736 737 cmd = (struct roam_ctrl_cmd *) skb->data; 738 memset(cmd, 0, sizeof(*cmd)); 739 740 memcpy(cmd->info.bssid, bssid, ETH_ALEN); 741 cmd->roam_ctrl = WMI_FORCE_ROAM; 742 743 ath6kl_dbg(ATH6KL_DBG_WMI, "force roam to %pM\n", bssid); 744 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID, 745 NO_SYNC_WMIFLAG); 746 } 747 748 int ath6kl_wmi_set_roam_mode_cmd(struct wmi *wmi, enum wmi_roam_mode mode) 749 { 750 struct sk_buff *skb; 751 struct roam_ctrl_cmd *cmd; 752 753 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 754 if (!skb) 755 return -ENOMEM; 756 757 cmd = (struct roam_ctrl_cmd *) skb->data; 758 memset(cmd, 0, sizeof(*cmd)); 759 760 cmd->info.roam_mode = mode; 761 cmd->roam_ctrl = WMI_SET_ROAM_MODE; 762 763 ath6kl_dbg(ATH6KL_DBG_WMI, "set roam mode %d\n", mode); 764 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID, 765 NO_SYNC_WMIFLAG); 766 } 767 768 static int ath6kl_wmi_connect_event_rx(struct wmi *wmi, u8 *datap, int len, 769 struct ath6kl_vif *vif) 770 { 771 struct wmi_connect_event *ev; 772 u8 *pie, *peie; 773 774 if (len < sizeof(struct wmi_connect_event)) 775 return -EINVAL; 776 777 ev = (struct wmi_connect_event *) datap; 778 779 if (vif->nw_type == AP_NETWORK) { 780 /* AP mode start/STA connected event */ 781 struct net_device *dev = vif->ndev; 782 if (memcmp(dev->dev_addr, ev->u.ap_bss.bssid, ETH_ALEN) == 0) { 783 ath6kl_dbg(ATH6KL_DBG_WMI, 784 "%s: freq %d bssid %pM (AP started)\n", 785 __func__, le16_to_cpu(ev->u.ap_bss.ch), 786 ev->u.ap_bss.bssid); 787 ath6kl_connect_ap_mode_bss( 788 vif, le16_to_cpu(ev->u.ap_bss.ch)); 789 } else { 790 ath6kl_dbg(ATH6KL_DBG_WMI, 791 "%s: aid %u mac_addr %pM auth=%u keymgmt=%u cipher=%u apsd_info=%u (STA connected)\n", 792 __func__, ev->u.ap_sta.aid, 793 ev->u.ap_sta.mac_addr, 794 ev->u.ap_sta.auth, 795 ev->u.ap_sta.keymgmt, 796 le16_to_cpu(ev->u.ap_sta.cipher), 797 ev->u.ap_sta.apsd_info); 798 799 ath6kl_connect_ap_mode_sta( 800 vif, ev->u.ap_sta.aid, ev->u.ap_sta.mac_addr, 801 ev->u.ap_sta.keymgmt, 802 le16_to_cpu(ev->u.ap_sta.cipher), 803 ev->u.ap_sta.auth, ev->assoc_req_len, 804 ev->assoc_info + ev->beacon_ie_len, 805 ev->u.ap_sta.apsd_info); 806 } 807 return 0; 808 } 809 810 /* STA/IBSS mode connection event */ 811 812 ath6kl_dbg(ATH6KL_DBG_WMI, 813 "wmi event connect freq %d bssid %pM listen_intvl %d beacon_intvl %d type %d\n", 814 le16_to_cpu(ev->u.sta.ch), ev->u.sta.bssid, 815 le16_to_cpu(ev->u.sta.listen_intvl), 816 le16_to_cpu(ev->u.sta.beacon_intvl), 817 le32_to_cpu(ev->u.sta.nw_type)); 818 819 /* Start of assoc rsp IEs */ 820 pie = ev->assoc_info + ev->beacon_ie_len + 821 ev->assoc_req_len + (sizeof(u16) * 3); /* capinfo, status, aid */ 822 823 /* End of assoc rsp IEs */ 824 peie = ev->assoc_info + ev->beacon_ie_len + ev->assoc_req_len + 825 ev->assoc_resp_len; 826 827 while (pie < peie) { 828 switch (*pie) { 829 case WLAN_EID_VENDOR_SPECIFIC: 830 if (pie[1] > 3 && pie[2] == 0x00 && pie[3] == 0x50 && 831 pie[4] == 0xf2 && pie[5] == WMM_OUI_TYPE) { 832 /* WMM OUT (00:50:F2) */ 833 if (pie[1] > 5 && 834 pie[6] == WMM_PARAM_OUI_SUBTYPE) 835 wmi->is_wmm_enabled = true; 836 } 837 break; 838 } 839 840 if (wmi->is_wmm_enabled) 841 break; 842 843 pie += pie[1] + 2; 844 } 845 846 ath6kl_connect_event(vif, le16_to_cpu(ev->u.sta.ch), 847 ev->u.sta.bssid, 848 le16_to_cpu(ev->u.sta.listen_intvl), 849 le16_to_cpu(ev->u.sta.beacon_intvl), 850 le32_to_cpu(ev->u.sta.nw_type), 851 ev->beacon_ie_len, ev->assoc_req_len, 852 ev->assoc_resp_len, ev->assoc_info); 853 854 return 0; 855 } 856 857 static struct country_code_to_enum_rd * 858 ath6kl_regd_find_country(u16 countryCode) 859 { 860 int i; 861 862 for (i = 0; i < ARRAY_SIZE(allCountries); i++) { 863 if (allCountries[i].countryCode == countryCode) 864 return &allCountries[i]; 865 } 866 867 return NULL; 868 } 869 870 static struct reg_dmn_pair_mapping * 871 ath6kl_get_regpair(u16 regdmn) 872 { 873 int i; 874 875 if (regdmn == NO_ENUMRD) 876 return NULL; 877 878 for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) { 879 if (regDomainPairs[i].regDmnEnum == regdmn) 880 return ®DomainPairs[i]; 881 } 882 883 return NULL; 884 } 885 886 static struct country_code_to_enum_rd * 887 ath6kl_regd_find_country_by_rd(u16 regdmn) 888 { 889 int i; 890 891 for (i = 0; i < ARRAY_SIZE(allCountries); i++) { 892 if (allCountries[i].regDmnEnum == regdmn) 893 return &allCountries[i]; 894 } 895 896 return NULL; 897 } 898 899 static void ath6kl_wmi_regdomain_event(struct wmi *wmi, u8 *datap, int len) 900 { 901 902 struct ath6kl_wmi_regdomain *ev; 903 struct country_code_to_enum_rd *country = NULL; 904 struct reg_dmn_pair_mapping *regpair = NULL; 905 char alpha2[2]; 906 u32 reg_code; 907 908 ev = (struct ath6kl_wmi_regdomain *) datap; 909 reg_code = le32_to_cpu(ev->reg_code); 910 911 if ((reg_code >> ATH6KL_COUNTRY_RD_SHIFT) & COUNTRY_ERD_FLAG) 912 country = ath6kl_regd_find_country((u16) reg_code); 913 else if (!(((u16) reg_code & WORLD_SKU_MASK) == WORLD_SKU_PREFIX)) { 914 915 regpair = ath6kl_get_regpair((u16) reg_code); 916 country = ath6kl_regd_find_country_by_rd((u16) reg_code); 917 ath6kl_dbg(ATH6KL_DBG_WMI, "Regpair used: 0x%0x\n", 918 regpair->regDmnEnum); 919 } 920 921 if (country && wmi->parent_dev->wiphy_registered) { 922 alpha2[0] = country->isoName[0]; 923 alpha2[1] = country->isoName[1]; 924 925 regulatory_hint(wmi->parent_dev->wiphy, alpha2); 926 927 ath6kl_dbg(ATH6KL_DBG_WMI, "Country alpha2 being used: %c%c\n", 928 alpha2[0], alpha2[1]); 929 } 930 } 931 932 static int ath6kl_wmi_disconnect_event_rx(struct wmi *wmi, u8 *datap, int len, 933 struct ath6kl_vif *vif) 934 { 935 struct wmi_disconnect_event *ev; 936 wmi->traffic_class = 100; 937 938 if (len < sizeof(struct wmi_disconnect_event)) 939 return -EINVAL; 940 941 ev = (struct wmi_disconnect_event *) datap; 942 943 ath6kl_dbg(ATH6KL_DBG_WMI, 944 "wmi event disconnect proto_reason %d bssid %pM wmi_reason %d assoc_resp_len %d\n", 945 le16_to_cpu(ev->proto_reason_status), ev->bssid, 946 ev->disconn_reason, ev->assoc_resp_len); 947 948 wmi->is_wmm_enabled = false; 949 950 ath6kl_disconnect_event(vif, ev->disconn_reason, 951 ev->bssid, ev->assoc_resp_len, ev->assoc_info, 952 le16_to_cpu(ev->proto_reason_status)); 953 954 return 0; 955 } 956 957 static int ath6kl_wmi_peer_node_event_rx(struct wmi *wmi, u8 *datap, int len) 958 { 959 struct wmi_peer_node_event *ev; 960 961 if (len < sizeof(struct wmi_peer_node_event)) 962 return -EINVAL; 963 964 ev = (struct wmi_peer_node_event *) datap; 965 966 if (ev->event_code == PEER_NODE_JOIN_EVENT) 967 ath6kl_dbg(ATH6KL_DBG_WMI, "joined node with mac addr: %pM\n", 968 ev->peer_mac_addr); 969 else if (ev->event_code == PEER_NODE_LEAVE_EVENT) 970 ath6kl_dbg(ATH6KL_DBG_WMI, "left node with mac addr: %pM\n", 971 ev->peer_mac_addr); 972 973 return 0; 974 } 975 976 static int ath6kl_wmi_tkip_micerr_event_rx(struct wmi *wmi, u8 *datap, int len, 977 struct ath6kl_vif *vif) 978 { 979 struct wmi_tkip_micerr_event *ev; 980 981 if (len < sizeof(struct wmi_tkip_micerr_event)) 982 return -EINVAL; 983 984 ev = (struct wmi_tkip_micerr_event *) datap; 985 986 ath6kl_tkip_micerr_event(vif, ev->key_id, ev->is_mcast); 987 988 return 0; 989 } 990 991 void ath6kl_wmi_sscan_timer(unsigned long ptr) 992 { 993 struct ath6kl_vif *vif = (struct ath6kl_vif *) ptr; 994 995 cfg80211_sched_scan_results(vif->ar->wiphy); 996 } 997 998 static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len, 999 struct ath6kl_vif *vif) 1000 { 1001 struct wmi_bss_info_hdr2 *bih; 1002 u8 *buf; 1003 struct ieee80211_channel *channel; 1004 struct ath6kl *ar = wmi->parent_dev; 1005 struct ieee80211_mgmt *mgmt; 1006 struct cfg80211_bss *bss; 1007 1008 if (len <= sizeof(struct wmi_bss_info_hdr2)) 1009 return -EINVAL; 1010 1011 bih = (struct wmi_bss_info_hdr2 *) datap; 1012 buf = datap + sizeof(struct wmi_bss_info_hdr2); 1013 len -= sizeof(struct wmi_bss_info_hdr2); 1014 1015 ath6kl_dbg(ATH6KL_DBG_WMI, 1016 "bss info evt - ch %u, snr %d, rssi %d, bssid \"%pM\" " 1017 "frame_type=%d\n", 1018 bih->ch, bih->snr, bih->snr - 95, bih->bssid, 1019 bih->frame_type); 1020 1021 if (bih->frame_type != BEACON_FTYPE && 1022 bih->frame_type != PROBERESP_FTYPE) 1023 return 0; /* Only update BSS table for now */ 1024 1025 if (bih->frame_type == BEACON_FTYPE && 1026 test_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags)) { 1027 clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags); 1028 ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx, 1029 NONE_BSS_FILTER, 0); 1030 } 1031 1032 channel = ieee80211_get_channel(ar->wiphy, le16_to_cpu(bih->ch)); 1033 if (channel == NULL) 1034 return -EINVAL; 1035 1036 if (len < 8 + 2 + 2) 1037 return -EINVAL; 1038 1039 if (bih->frame_type == BEACON_FTYPE && 1040 test_bit(CONNECTED, &vif->flags) && 1041 memcmp(bih->bssid, vif->bssid, ETH_ALEN) == 0) { 1042 const u8 *tim; 1043 tim = cfg80211_find_ie(WLAN_EID_TIM, buf + 8 + 2 + 2, 1044 len - 8 - 2 - 2); 1045 if (tim && tim[1] >= 2) { 1046 vif->assoc_bss_dtim_period = tim[3]; 1047 set_bit(DTIM_PERIOD_AVAIL, &vif->flags); 1048 } 1049 } 1050 1051 /* 1052 * In theory, use of cfg80211_inform_bss() would be more natural here 1053 * since we do not have the full frame. However, at least for now, 1054 * cfg80211 can only distinguish Beacon and Probe Response frames from 1055 * each other when using cfg80211_inform_bss_frame(), so let's build a 1056 * fake IEEE 802.11 header to be able to take benefit of this. 1057 */ 1058 mgmt = kmalloc(24 + len, GFP_ATOMIC); 1059 if (mgmt == NULL) 1060 return -EINVAL; 1061 1062 if (bih->frame_type == BEACON_FTYPE) { 1063 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 1064 IEEE80211_STYPE_BEACON); 1065 memset(mgmt->da, 0xff, ETH_ALEN); 1066 } else { 1067 struct net_device *dev = vif->ndev; 1068 1069 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 1070 IEEE80211_STYPE_PROBE_RESP); 1071 memcpy(mgmt->da, dev->dev_addr, ETH_ALEN); 1072 } 1073 mgmt->duration = cpu_to_le16(0); 1074 memcpy(mgmt->sa, bih->bssid, ETH_ALEN); 1075 memcpy(mgmt->bssid, bih->bssid, ETH_ALEN); 1076 mgmt->seq_ctrl = cpu_to_le16(0); 1077 1078 memcpy(&mgmt->u.beacon, buf, len); 1079 1080 bss = cfg80211_inform_bss_frame(ar->wiphy, channel, mgmt, 1081 24 + len, (bih->snr - 95) * 100, 1082 GFP_ATOMIC); 1083 kfree(mgmt); 1084 if (bss == NULL) 1085 return -ENOMEM; 1086 cfg80211_put_bss(bss); 1087 1088 /* 1089 * Firmware doesn't return any event when scheduled scan has 1090 * finished, so we need to use a timer to find out when there are 1091 * no more results. 1092 * 1093 * The timer is started from the first bss info received, otherwise 1094 * the timer would not ever fire if the scan interval is short 1095 * enough. 1096 */ 1097 if (ar->state == ATH6KL_STATE_SCHED_SCAN && 1098 !timer_pending(&vif->sched_scan_timer)) { 1099 mod_timer(&vif->sched_scan_timer, jiffies + 1100 msecs_to_jiffies(ATH6KL_SCHED_SCAN_RESULT_DELAY)); 1101 } 1102 1103 return 0; 1104 } 1105 1106 /* Inactivity timeout of a fatpipe(pstream) at the target */ 1107 static int ath6kl_wmi_pstream_timeout_event_rx(struct wmi *wmi, u8 *datap, 1108 int len) 1109 { 1110 struct wmi_pstream_timeout_event *ev; 1111 1112 if (len < sizeof(struct wmi_pstream_timeout_event)) 1113 return -EINVAL; 1114 1115 ev = (struct wmi_pstream_timeout_event *) datap; 1116 1117 /* 1118 * When the pstream (fat pipe == AC) timesout, it means there were 1119 * no thinStreams within this pstream & it got implicitly created 1120 * due to data flow on this AC. We start the inactivity timer only 1121 * for implicitly created pstream. Just reset the host state. 1122 */ 1123 spin_lock_bh(&wmi->lock); 1124 wmi->stream_exist_for_ac[ev->traffic_class] = 0; 1125 wmi->fat_pipe_exist &= ~(1 << ev->traffic_class); 1126 spin_unlock_bh(&wmi->lock); 1127 1128 /* Indicate inactivity to driver layer for this fatpipe (pstream) */ 1129 ath6kl_indicate_tx_activity(wmi->parent_dev, ev->traffic_class, false); 1130 1131 return 0; 1132 } 1133 1134 static int ath6kl_wmi_bitrate_reply_rx(struct wmi *wmi, u8 *datap, int len) 1135 { 1136 struct wmi_bit_rate_reply *reply; 1137 s32 rate; 1138 u32 sgi, index; 1139 1140 if (len < sizeof(struct wmi_bit_rate_reply)) 1141 return -EINVAL; 1142 1143 reply = (struct wmi_bit_rate_reply *) datap; 1144 1145 ath6kl_dbg(ATH6KL_DBG_WMI, "rateindex %d\n", reply->rate_index); 1146 1147 if (reply->rate_index == (s8) RATE_AUTO) { 1148 rate = RATE_AUTO; 1149 } else { 1150 index = reply->rate_index & 0x7f; 1151 sgi = (reply->rate_index & 0x80) ? 1 : 0; 1152 rate = wmi_rate_tbl[index][sgi]; 1153 } 1154 1155 ath6kl_wakeup_event(wmi->parent_dev); 1156 1157 return 0; 1158 } 1159 1160 static int ath6kl_wmi_test_rx(struct wmi *wmi, u8 *datap, int len) 1161 { 1162 ath6kl_tm_rx_event(wmi->parent_dev, datap, len); 1163 1164 return 0; 1165 } 1166 1167 static int ath6kl_wmi_ratemask_reply_rx(struct wmi *wmi, u8 *datap, int len) 1168 { 1169 if (len < sizeof(struct wmi_fix_rates_reply)) 1170 return -EINVAL; 1171 1172 ath6kl_wakeup_event(wmi->parent_dev); 1173 1174 return 0; 1175 } 1176 1177 static int ath6kl_wmi_ch_list_reply_rx(struct wmi *wmi, u8 *datap, int len) 1178 { 1179 if (len < sizeof(struct wmi_channel_list_reply)) 1180 return -EINVAL; 1181 1182 ath6kl_wakeup_event(wmi->parent_dev); 1183 1184 return 0; 1185 } 1186 1187 static int ath6kl_wmi_tx_pwr_reply_rx(struct wmi *wmi, u8 *datap, int len) 1188 { 1189 struct wmi_tx_pwr_reply *reply; 1190 1191 if (len < sizeof(struct wmi_tx_pwr_reply)) 1192 return -EINVAL; 1193 1194 reply = (struct wmi_tx_pwr_reply *) datap; 1195 ath6kl_txpwr_rx_evt(wmi->parent_dev, reply->dbM); 1196 1197 return 0; 1198 } 1199 1200 static int ath6kl_wmi_keepalive_reply_rx(struct wmi *wmi, u8 *datap, int len) 1201 { 1202 if (len < sizeof(struct wmi_get_keepalive_cmd)) 1203 return -EINVAL; 1204 1205 ath6kl_wakeup_event(wmi->parent_dev); 1206 1207 return 0; 1208 } 1209 1210 static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len, 1211 struct ath6kl_vif *vif) 1212 { 1213 struct wmi_scan_complete_event *ev; 1214 1215 ev = (struct wmi_scan_complete_event *) datap; 1216 1217 ath6kl_scan_complete_evt(vif, a_sle32_to_cpu(ev->status)); 1218 wmi->is_probe_ssid = false; 1219 1220 return 0; 1221 } 1222 1223 static int ath6kl_wmi_neighbor_report_event_rx(struct wmi *wmi, u8 *datap, 1224 int len, struct ath6kl_vif *vif) 1225 { 1226 struct wmi_neighbor_report_event *ev; 1227 u8 i; 1228 1229 if (len < sizeof(*ev)) 1230 return -EINVAL; 1231 ev = (struct wmi_neighbor_report_event *) datap; 1232 if (sizeof(*ev) + ev->num_neighbors * sizeof(struct wmi_neighbor_info) 1233 > len) { 1234 ath6kl_dbg(ATH6KL_DBG_WMI, 1235 "truncated neighbor event (num=%d len=%d)\n", 1236 ev->num_neighbors, len); 1237 return -EINVAL; 1238 } 1239 for (i = 0; i < ev->num_neighbors; i++) { 1240 ath6kl_dbg(ATH6KL_DBG_WMI, "neighbor %d/%d - %pM 0x%x\n", 1241 i + 1, ev->num_neighbors, ev->neighbor[i].bssid, 1242 ev->neighbor[i].bss_flags); 1243 cfg80211_pmksa_candidate_notify(vif->ndev, i, 1244 ev->neighbor[i].bssid, 1245 !!(ev->neighbor[i].bss_flags & 1246 WMI_PREAUTH_CAPABLE_BSS), 1247 GFP_ATOMIC); 1248 } 1249 1250 return 0; 1251 } 1252 1253 /* 1254 * Target is reporting a programming error. This is for 1255 * developer aid only. Target only checks a few common violations 1256 * and it is responsibility of host to do all error checking. 1257 * Behavior of target after wmi error event is undefined. 1258 * A reset is recommended. 1259 */ 1260 static int ath6kl_wmi_error_event_rx(struct wmi *wmi, u8 *datap, int len) 1261 { 1262 const char *type = "unknown error"; 1263 struct wmi_cmd_error_event *ev; 1264 ev = (struct wmi_cmd_error_event *) datap; 1265 1266 switch (ev->err_code) { 1267 case INVALID_PARAM: 1268 type = "invalid parameter"; 1269 break; 1270 case ILLEGAL_STATE: 1271 type = "invalid state"; 1272 break; 1273 case INTERNAL_ERROR: 1274 type = "internal error"; 1275 break; 1276 } 1277 1278 ath6kl_dbg(ATH6KL_DBG_WMI, "programming error, cmd=%d %s\n", 1279 ev->cmd_id, type); 1280 1281 return 0; 1282 } 1283 1284 static int ath6kl_wmi_stats_event_rx(struct wmi *wmi, u8 *datap, int len, 1285 struct ath6kl_vif *vif) 1286 { 1287 ath6kl_tgt_stats_event(vif, datap, len); 1288 1289 return 0; 1290 } 1291 1292 static u8 ath6kl_wmi_get_upper_threshold(s16 rssi, 1293 struct sq_threshold_params *sq_thresh, 1294 u32 size) 1295 { 1296 u32 index; 1297 u8 threshold = (u8) sq_thresh->upper_threshold[size - 1]; 1298 1299 /* The list is already in sorted order. Get the next lower value */ 1300 for (index = 0; index < size; index++) { 1301 if (rssi < sq_thresh->upper_threshold[index]) { 1302 threshold = (u8) sq_thresh->upper_threshold[index]; 1303 break; 1304 } 1305 } 1306 1307 return threshold; 1308 } 1309 1310 static u8 ath6kl_wmi_get_lower_threshold(s16 rssi, 1311 struct sq_threshold_params *sq_thresh, 1312 u32 size) 1313 { 1314 u32 index; 1315 u8 threshold = (u8) sq_thresh->lower_threshold[size - 1]; 1316 1317 /* The list is already in sorted order. Get the next lower value */ 1318 for (index = 0; index < size; index++) { 1319 if (rssi > sq_thresh->lower_threshold[index]) { 1320 threshold = (u8) sq_thresh->lower_threshold[index]; 1321 break; 1322 } 1323 } 1324 1325 return threshold; 1326 } 1327 1328 static int ath6kl_wmi_send_rssi_threshold_params(struct wmi *wmi, 1329 struct wmi_rssi_threshold_params_cmd *rssi_cmd) 1330 { 1331 struct sk_buff *skb; 1332 struct wmi_rssi_threshold_params_cmd *cmd; 1333 1334 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 1335 if (!skb) 1336 return -ENOMEM; 1337 1338 cmd = (struct wmi_rssi_threshold_params_cmd *) skb->data; 1339 memcpy(cmd, rssi_cmd, sizeof(struct wmi_rssi_threshold_params_cmd)); 1340 1341 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_RSSI_THRESHOLD_PARAMS_CMDID, 1342 NO_SYNC_WMIFLAG); 1343 } 1344 1345 static int ath6kl_wmi_rssi_threshold_event_rx(struct wmi *wmi, u8 *datap, 1346 int len) 1347 { 1348 struct wmi_rssi_threshold_event *reply; 1349 struct wmi_rssi_threshold_params_cmd cmd; 1350 struct sq_threshold_params *sq_thresh; 1351 enum wmi_rssi_threshold_val new_threshold; 1352 u8 upper_rssi_threshold, lower_rssi_threshold; 1353 s16 rssi; 1354 int ret; 1355 1356 if (len < sizeof(struct wmi_rssi_threshold_event)) 1357 return -EINVAL; 1358 1359 reply = (struct wmi_rssi_threshold_event *) datap; 1360 new_threshold = (enum wmi_rssi_threshold_val) reply->range; 1361 rssi = a_sle16_to_cpu(reply->rssi); 1362 1363 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_RSSI]; 1364 1365 /* 1366 * Identify the threshold breached and communicate that to the app. 1367 * After that install a new set of thresholds based on the signal 1368 * quality reported by the target 1369 */ 1370 if (new_threshold) { 1371 /* Upper threshold breached */ 1372 if (rssi < sq_thresh->upper_threshold[0]) { 1373 ath6kl_dbg(ATH6KL_DBG_WMI, 1374 "spurious upper rssi threshold event: %d\n", 1375 rssi); 1376 } else if ((rssi < sq_thresh->upper_threshold[1]) && 1377 (rssi >= sq_thresh->upper_threshold[0])) { 1378 new_threshold = WMI_RSSI_THRESHOLD1_ABOVE; 1379 } else if ((rssi < sq_thresh->upper_threshold[2]) && 1380 (rssi >= sq_thresh->upper_threshold[1])) { 1381 new_threshold = WMI_RSSI_THRESHOLD2_ABOVE; 1382 } else if ((rssi < sq_thresh->upper_threshold[3]) && 1383 (rssi >= sq_thresh->upper_threshold[2])) { 1384 new_threshold = WMI_RSSI_THRESHOLD3_ABOVE; 1385 } else if ((rssi < sq_thresh->upper_threshold[4]) && 1386 (rssi >= sq_thresh->upper_threshold[3])) { 1387 new_threshold = WMI_RSSI_THRESHOLD4_ABOVE; 1388 } else if ((rssi < sq_thresh->upper_threshold[5]) && 1389 (rssi >= sq_thresh->upper_threshold[4])) { 1390 new_threshold = WMI_RSSI_THRESHOLD5_ABOVE; 1391 } else if (rssi >= sq_thresh->upper_threshold[5]) { 1392 new_threshold = WMI_RSSI_THRESHOLD6_ABOVE; 1393 } 1394 } else { 1395 /* Lower threshold breached */ 1396 if (rssi > sq_thresh->lower_threshold[0]) { 1397 ath6kl_dbg(ATH6KL_DBG_WMI, 1398 "spurious lower rssi threshold event: %d %d\n", 1399 rssi, sq_thresh->lower_threshold[0]); 1400 } else if ((rssi > sq_thresh->lower_threshold[1]) && 1401 (rssi <= sq_thresh->lower_threshold[0])) { 1402 new_threshold = WMI_RSSI_THRESHOLD6_BELOW; 1403 } else if ((rssi > sq_thresh->lower_threshold[2]) && 1404 (rssi <= sq_thresh->lower_threshold[1])) { 1405 new_threshold = WMI_RSSI_THRESHOLD5_BELOW; 1406 } else if ((rssi > sq_thresh->lower_threshold[3]) && 1407 (rssi <= sq_thresh->lower_threshold[2])) { 1408 new_threshold = WMI_RSSI_THRESHOLD4_BELOW; 1409 } else if ((rssi > sq_thresh->lower_threshold[4]) && 1410 (rssi <= sq_thresh->lower_threshold[3])) { 1411 new_threshold = WMI_RSSI_THRESHOLD3_BELOW; 1412 } else if ((rssi > sq_thresh->lower_threshold[5]) && 1413 (rssi <= sq_thresh->lower_threshold[4])) { 1414 new_threshold = WMI_RSSI_THRESHOLD2_BELOW; 1415 } else if (rssi <= sq_thresh->lower_threshold[5]) { 1416 new_threshold = WMI_RSSI_THRESHOLD1_BELOW; 1417 } 1418 } 1419 1420 /* Calculate and install the next set of thresholds */ 1421 lower_rssi_threshold = ath6kl_wmi_get_lower_threshold(rssi, sq_thresh, 1422 sq_thresh->lower_threshold_valid_count); 1423 upper_rssi_threshold = ath6kl_wmi_get_upper_threshold(rssi, sq_thresh, 1424 sq_thresh->upper_threshold_valid_count); 1425 1426 /* Issue a wmi command to install the thresholds */ 1427 cmd.thresh_above1_val = a_cpu_to_sle16(upper_rssi_threshold); 1428 cmd.thresh_below1_val = a_cpu_to_sle16(lower_rssi_threshold); 1429 cmd.weight = sq_thresh->weight; 1430 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval); 1431 1432 ret = ath6kl_wmi_send_rssi_threshold_params(wmi, &cmd); 1433 if (ret) { 1434 ath6kl_err("unable to configure rssi thresholds\n"); 1435 return -EIO; 1436 } 1437 1438 return 0; 1439 } 1440 1441 static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len, 1442 struct ath6kl_vif *vif) 1443 { 1444 struct wmi_cac_event *reply; 1445 struct ieee80211_tspec_ie *ts; 1446 u16 active_tsids, tsinfo; 1447 u8 tsid, index; 1448 u8 ts_id; 1449 1450 if (len < sizeof(struct wmi_cac_event)) 1451 return -EINVAL; 1452 1453 reply = (struct wmi_cac_event *) datap; 1454 1455 if ((reply->cac_indication == CAC_INDICATION_ADMISSION_RESP) && 1456 (reply->status_code != IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED)) { 1457 1458 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion); 1459 tsinfo = le16_to_cpu(ts->tsinfo); 1460 tsid = (tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) & 1461 IEEE80211_WMM_IE_TSPEC_TID_MASK; 1462 1463 ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx, 1464 reply->ac, tsid); 1465 } else if (reply->cac_indication == CAC_INDICATION_NO_RESP) { 1466 /* 1467 * Following assumes that there is only one outstanding 1468 * ADDTS request when this event is received 1469 */ 1470 spin_lock_bh(&wmi->lock); 1471 active_tsids = wmi->stream_exist_for_ac[reply->ac]; 1472 spin_unlock_bh(&wmi->lock); 1473 1474 for (index = 0; index < sizeof(active_tsids) * 8; index++) { 1475 if ((active_tsids >> index) & 1) 1476 break; 1477 } 1478 if (index < (sizeof(active_tsids) * 8)) 1479 ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx, 1480 reply->ac, index); 1481 } 1482 1483 /* 1484 * Clear active tsids and Add missing handling 1485 * for delete qos stream from AP 1486 */ 1487 else if (reply->cac_indication == CAC_INDICATION_DELETE) { 1488 1489 ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion); 1490 tsinfo = le16_to_cpu(ts->tsinfo); 1491 ts_id = ((tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) & 1492 IEEE80211_WMM_IE_TSPEC_TID_MASK); 1493 1494 spin_lock_bh(&wmi->lock); 1495 wmi->stream_exist_for_ac[reply->ac] &= ~(1 << ts_id); 1496 active_tsids = wmi->stream_exist_for_ac[reply->ac]; 1497 spin_unlock_bh(&wmi->lock); 1498 1499 /* Indicate stream inactivity to driver layer only if all tsids 1500 * within this AC are deleted. 1501 */ 1502 if (!active_tsids) { 1503 ath6kl_indicate_tx_activity(wmi->parent_dev, reply->ac, 1504 false); 1505 wmi->fat_pipe_exist &= ~(1 << reply->ac); 1506 } 1507 } 1508 1509 return 0; 1510 } 1511 1512 static int ath6kl_wmi_send_snr_threshold_params(struct wmi *wmi, 1513 struct wmi_snr_threshold_params_cmd *snr_cmd) 1514 { 1515 struct sk_buff *skb; 1516 struct wmi_snr_threshold_params_cmd *cmd; 1517 1518 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 1519 if (!skb) 1520 return -ENOMEM; 1521 1522 cmd = (struct wmi_snr_threshold_params_cmd *) skb->data; 1523 memcpy(cmd, snr_cmd, sizeof(struct wmi_snr_threshold_params_cmd)); 1524 1525 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SNR_THRESHOLD_PARAMS_CMDID, 1526 NO_SYNC_WMIFLAG); 1527 } 1528 1529 static int ath6kl_wmi_snr_threshold_event_rx(struct wmi *wmi, u8 *datap, 1530 int len) 1531 { 1532 struct wmi_snr_threshold_event *reply; 1533 struct sq_threshold_params *sq_thresh; 1534 struct wmi_snr_threshold_params_cmd cmd; 1535 enum wmi_snr_threshold_val new_threshold; 1536 u8 upper_snr_threshold, lower_snr_threshold; 1537 s16 snr; 1538 int ret; 1539 1540 if (len < sizeof(struct wmi_snr_threshold_event)) 1541 return -EINVAL; 1542 1543 reply = (struct wmi_snr_threshold_event *) datap; 1544 1545 new_threshold = (enum wmi_snr_threshold_val) reply->range; 1546 snr = reply->snr; 1547 1548 sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_SNR]; 1549 1550 /* 1551 * Identify the threshold breached and communicate that to the app. 1552 * After that install a new set of thresholds based on the signal 1553 * quality reported by the target. 1554 */ 1555 if (new_threshold) { 1556 /* Upper threshold breached */ 1557 if (snr < sq_thresh->upper_threshold[0]) { 1558 ath6kl_dbg(ATH6KL_DBG_WMI, 1559 "spurious upper snr threshold event: %d\n", 1560 snr); 1561 } else if ((snr < sq_thresh->upper_threshold[1]) && 1562 (snr >= sq_thresh->upper_threshold[0])) { 1563 new_threshold = WMI_SNR_THRESHOLD1_ABOVE; 1564 } else if ((snr < sq_thresh->upper_threshold[2]) && 1565 (snr >= sq_thresh->upper_threshold[1])) { 1566 new_threshold = WMI_SNR_THRESHOLD2_ABOVE; 1567 } else if ((snr < sq_thresh->upper_threshold[3]) && 1568 (snr >= sq_thresh->upper_threshold[2])) { 1569 new_threshold = WMI_SNR_THRESHOLD3_ABOVE; 1570 } else if (snr >= sq_thresh->upper_threshold[3]) { 1571 new_threshold = WMI_SNR_THRESHOLD4_ABOVE; 1572 } 1573 } else { 1574 /* Lower threshold breached */ 1575 if (snr > sq_thresh->lower_threshold[0]) { 1576 ath6kl_dbg(ATH6KL_DBG_WMI, 1577 "spurious lower snr threshold event: %d\n", 1578 sq_thresh->lower_threshold[0]); 1579 } else if ((snr > sq_thresh->lower_threshold[1]) && 1580 (snr <= sq_thresh->lower_threshold[0])) { 1581 new_threshold = WMI_SNR_THRESHOLD4_BELOW; 1582 } else if ((snr > sq_thresh->lower_threshold[2]) && 1583 (snr <= sq_thresh->lower_threshold[1])) { 1584 new_threshold = WMI_SNR_THRESHOLD3_BELOW; 1585 } else if ((snr > sq_thresh->lower_threshold[3]) && 1586 (snr <= sq_thresh->lower_threshold[2])) { 1587 new_threshold = WMI_SNR_THRESHOLD2_BELOW; 1588 } else if (snr <= sq_thresh->lower_threshold[3]) { 1589 new_threshold = WMI_SNR_THRESHOLD1_BELOW; 1590 } 1591 } 1592 1593 /* Calculate and install the next set of thresholds */ 1594 lower_snr_threshold = ath6kl_wmi_get_lower_threshold(snr, sq_thresh, 1595 sq_thresh->lower_threshold_valid_count); 1596 upper_snr_threshold = ath6kl_wmi_get_upper_threshold(snr, sq_thresh, 1597 sq_thresh->upper_threshold_valid_count); 1598 1599 /* Issue a wmi command to install the thresholds */ 1600 cmd.thresh_above1_val = upper_snr_threshold; 1601 cmd.thresh_below1_val = lower_snr_threshold; 1602 cmd.weight = sq_thresh->weight; 1603 cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval); 1604 1605 ath6kl_dbg(ATH6KL_DBG_WMI, 1606 "snr: %d, threshold: %d, lower: %d, upper: %d\n", 1607 snr, new_threshold, 1608 lower_snr_threshold, upper_snr_threshold); 1609 1610 ret = ath6kl_wmi_send_snr_threshold_params(wmi, &cmd); 1611 if (ret) { 1612 ath6kl_err("unable to configure snr threshold\n"); 1613 return -EIO; 1614 } 1615 1616 return 0; 1617 } 1618 1619 static int ath6kl_wmi_aplist_event_rx(struct wmi *wmi, u8 *datap, int len) 1620 { 1621 u16 ap_info_entry_size; 1622 struct wmi_aplist_event *ev = (struct wmi_aplist_event *) datap; 1623 struct wmi_ap_info_v1 *ap_info_v1; 1624 u8 index; 1625 1626 if (len < sizeof(struct wmi_aplist_event) || 1627 ev->ap_list_ver != APLIST_VER1) 1628 return -EINVAL; 1629 1630 ap_info_entry_size = sizeof(struct wmi_ap_info_v1); 1631 ap_info_v1 = (struct wmi_ap_info_v1 *) ev->ap_list; 1632 1633 ath6kl_dbg(ATH6KL_DBG_WMI, 1634 "number of APs in aplist event: %d\n", ev->num_ap); 1635 1636 if (len < (int) (sizeof(struct wmi_aplist_event) + 1637 (ev->num_ap - 1) * ap_info_entry_size)) 1638 return -EINVAL; 1639 1640 /* AP list version 1 contents */ 1641 for (index = 0; index < ev->num_ap; index++) { 1642 ath6kl_dbg(ATH6KL_DBG_WMI, "AP#%d BSSID %pM Channel %d\n", 1643 index, ap_info_v1->bssid, ap_info_v1->channel); 1644 ap_info_v1++; 1645 } 1646 1647 return 0; 1648 } 1649 1650 int ath6kl_wmi_cmd_send(struct wmi *wmi, u8 if_idx, struct sk_buff *skb, 1651 enum wmi_cmd_id cmd_id, enum wmi_sync_flag sync_flag) 1652 { 1653 struct wmi_cmd_hdr *cmd_hdr; 1654 enum htc_endpoint_id ep_id = wmi->ep_id; 1655 int ret; 1656 u16 info1; 1657 1658 if (WARN_ON(skb == NULL || (if_idx > (wmi->parent_dev->vif_max - 1)))) 1659 return -EINVAL; 1660 1661 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi tx id %d len %d flag %d\n", 1662 cmd_id, skb->len, sync_flag); 1663 ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi tx ", 1664 skb->data, skb->len); 1665 1666 if (sync_flag >= END_WMIFLAG) { 1667 dev_kfree_skb(skb); 1668 return -EINVAL; 1669 } 1670 1671 if ((sync_flag == SYNC_BEFORE_WMIFLAG) || 1672 (sync_flag == SYNC_BOTH_WMIFLAG)) { 1673 /* 1674 * Make sure all data currently queued is transmitted before 1675 * the cmd execution. Establish a new sync point. 1676 */ 1677 ath6kl_wmi_sync_point(wmi, if_idx); 1678 } 1679 1680 skb_push(skb, sizeof(struct wmi_cmd_hdr)); 1681 1682 cmd_hdr = (struct wmi_cmd_hdr *) skb->data; 1683 cmd_hdr->cmd_id = cpu_to_le16(cmd_id); 1684 info1 = if_idx & WMI_CMD_HDR_IF_ID_MASK; 1685 cmd_hdr->info1 = cpu_to_le16(info1); 1686 1687 /* Only for OPT_TX_CMD, use BE endpoint. */ 1688 if (cmd_id == WMI_OPT_TX_FRAME_CMDID) { 1689 ret = ath6kl_wmi_data_hdr_add(wmi, skb, OPT_MSGTYPE, 1690 false, false, 0, NULL, if_idx); 1691 if (ret) { 1692 dev_kfree_skb(skb); 1693 return ret; 1694 } 1695 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev, WMM_AC_BE); 1696 } 1697 1698 ath6kl_control_tx(wmi->parent_dev, skb, ep_id); 1699 1700 if ((sync_flag == SYNC_AFTER_WMIFLAG) || 1701 (sync_flag == SYNC_BOTH_WMIFLAG)) { 1702 /* 1703 * Make sure all new data queued waits for the command to 1704 * execute. Establish a new sync point. 1705 */ 1706 ath6kl_wmi_sync_point(wmi, if_idx); 1707 } 1708 1709 return 0; 1710 } 1711 1712 int ath6kl_wmi_connect_cmd(struct wmi *wmi, u8 if_idx, 1713 enum network_type nw_type, 1714 enum dot11_auth_mode dot11_auth_mode, 1715 enum auth_mode auth_mode, 1716 enum crypto_type pairwise_crypto, 1717 u8 pairwise_crypto_len, 1718 enum crypto_type group_crypto, 1719 u8 group_crypto_len, int ssid_len, u8 *ssid, 1720 u8 *bssid, u16 channel, u32 ctrl_flags, 1721 u8 nw_subtype) 1722 { 1723 struct sk_buff *skb; 1724 struct wmi_connect_cmd *cc; 1725 int ret; 1726 1727 ath6kl_dbg(ATH6KL_DBG_WMI, 1728 "wmi connect bssid %pM freq %d flags 0x%x ssid_len %d " 1729 "type %d dot11_auth %d auth %d pairwise %d group %d\n", 1730 bssid, channel, ctrl_flags, ssid_len, nw_type, 1731 dot11_auth_mode, auth_mode, pairwise_crypto, group_crypto); 1732 ath6kl_dbg_dump(ATH6KL_DBG_WMI, NULL, "ssid ", ssid, ssid_len); 1733 1734 wmi->traffic_class = 100; 1735 1736 if ((pairwise_crypto == NONE_CRYPT) && (group_crypto != NONE_CRYPT)) 1737 return -EINVAL; 1738 1739 if ((pairwise_crypto != NONE_CRYPT) && (group_crypto == NONE_CRYPT)) 1740 return -EINVAL; 1741 1742 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_connect_cmd)); 1743 if (!skb) 1744 return -ENOMEM; 1745 1746 cc = (struct wmi_connect_cmd *) skb->data; 1747 1748 if (ssid_len) 1749 memcpy(cc->ssid, ssid, ssid_len); 1750 1751 cc->ssid_len = ssid_len; 1752 cc->nw_type = nw_type; 1753 cc->dot11_auth_mode = dot11_auth_mode; 1754 cc->auth_mode = auth_mode; 1755 cc->prwise_crypto_type = pairwise_crypto; 1756 cc->prwise_crypto_len = pairwise_crypto_len; 1757 cc->grp_crypto_type = group_crypto; 1758 cc->grp_crypto_len = group_crypto_len; 1759 cc->ch = cpu_to_le16(channel); 1760 cc->ctrl_flags = cpu_to_le32(ctrl_flags); 1761 cc->nw_subtype = nw_subtype; 1762 1763 if (bssid != NULL) 1764 memcpy(cc->bssid, bssid, ETH_ALEN); 1765 1766 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CONNECT_CMDID, 1767 NO_SYNC_WMIFLAG); 1768 1769 return ret; 1770 } 1771 1772 int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 if_idx, u8 *bssid, 1773 u16 channel) 1774 { 1775 struct sk_buff *skb; 1776 struct wmi_reconnect_cmd *cc; 1777 int ret; 1778 1779 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi reconnect bssid %pM freq %d\n", 1780 bssid, channel); 1781 1782 wmi->traffic_class = 100; 1783 1784 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_reconnect_cmd)); 1785 if (!skb) 1786 return -ENOMEM; 1787 1788 cc = (struct wmi_reconnect_cmd *) skb->data; 1789 cc->channel = cpu_to_le16(channel); 1790 1791 if (bssid != NULL) 1792 memcpy(cc->bssid, bssid, ETH_ALEN); 1793 1794 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RECONNECT_CMDID, 1795 NO_SYNC_WMIFLAG); 1796 1797 return ret; 1798 } 1799 1800 int ath6kl_wmi_disconnect_cmd(struct wmi *wmi, u8 if_idx) 1801 { 1802 int ret; 1803 1804 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi disconnect\n"); 1805 1806 wmi->traffic_class = 100; 1807 1808 /* Disconnect command does not need to do a SYNC before. */ 1809 ret = ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_DISCONNECT_CMDID); 1810 1811 return ret; 1812 } 1813 1814 int ath6kl_wmi_beginscan_cmd(struct wmi *wmi, u8 if_idx, 1815 enum wmi_scan_type scan_type, 1816 u32 force_fgscan, u32 is_legacy, 1817 u32 home_dwell_time, u32 force_scan_interval, 1818 s8 num_chan, u16 *ch_list, u32 no_cck, u32 *rates) 1819 { 1820 struct sk_buff *skb; 1821 struct wmi_begin_scan_cmd *sc; 1822 s8 size; 1823 int i, band, ret; 1824 struct ath6kl *ar = wmi->parent_dev; 1825 int num_rates; 1826 1827 size = sizeof(struct wmi_begin_scan_cmd); 1828 1829 if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN)) 1830 return -EINVAL; 1831 1832 if (num_chan > WMI_MAX_CHANNELS) 1833 return -EINVAL; 1834 1835 if (num_chan) 1836 size += sizeof(u16) * (num_chan - 1); 1837 1838 skb = ath6kl_wmi_get_new_buf(size); 1839 if (!skb) 1840 return -ENOMEM; 1841 1842 sc = (struct wmi_begin_scan_cmd *) skb->data; 1843 sc->scan_type = scan_type; 1844 sc->force_fg_scan = cpu_to_le32(force_fgscan); 1845 sc->is_legacy = cpu_to_le32(is_legacy); 1846 sc->home_dwell_time = cpu_to_le32(home_dwell_time); 1847 sc->force_scan_intvl = cpu_to_le32(force_scan_interval); 1848 sc->no_cck = cpu_to_le32(no_cck); 1849 sc->num_ch = num_chan; 1850 1851 for (band = 0; band < IEEE80211_NUM_BANDS; band++) { 1852 struct ieee80211_supported_band *sband = 1853 ar->wiphy->bands[band]; 1854 u32 ratemask = rates[band]; 1855 u8 *supp_rates = sc->supp_rates[band].rates; 1856 num_rates = 0; 1857 1858 for (i = 0; i < sband->n_bitrates; i++) { 1859 if ((BIT(i) & ratemask) == 0) 1860 continue; /* skip rate */ 1861 supp_rates[num_rates++] = 1862 (u8) (sband->bitrates[i].bitrate / 5); 1863 } 1864 sc->supp_rates[band].nrates = num_rates; 1865 } 1866 1867 for (i = 0; i < num_chan; i++) 1868 sc->ch_list[i] = cpu_to_le16(ch_list[i]); 1869 1870 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_BEGIN_SCAN_CMDID, 1871 NO_SYNC_WMIFLAG); 1872 1873 return ret; 1874 } 1875 1876 /* ath6kl_wmi_start_scan_cmd is to be deprecated. Use 1877 * ath6kl_wmi_begin_scan_cmd instead. The new function supports P2P 1878 * mgmt operations using station interface. 1879 */ 1880 int ath6kl_wmi_startscan_cmd(struct wmi *wmi, u8 if_idx, 1881 enum wmi_scan_type scan_type, 1882 u32 force_fgscan, u32 is_legacy, 1883 u32 home_dwell_time, u32 force_scan_interval, 1884 s8 num_chan, u16 *ch_list) 1885 { 1886 struct sk_buff *skb; 1887 struct wmi_start_scan_cmd *sc; 1888 s8 size; 1889 int i, ret; 1890 1891 size = sizeof(struct wmi_start_scan_cmd); 1892 1893 if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN)) 1894 return -EINVAL; 1895 1896 if (num_chan > WMI_MAX_CHANNELS) 1897 return -EINVAL; 1898 1899 if (num_chan) 1900 size += sizeof(u16) * (num_chan - 1); 1901 1902 skb = ath6kl_wmi_get_new_buf(size); 1903 if (!skb) 1904 return -ENOMEM; 1905 1906 sc = (struct wmi_start_scan_cmd *) skb->data; 1907 sc->scan_type = scan_type; 1908 sc->force_fg_scan = cpu_to_le32(force_fgscan); 1909 sc->is_legacy = cpu_to_le32(is_legacy); 1910 sc->home_dwell_time = cpu_to_le32(home_dwell_time); 1911 sc->force_scan_intvl = cpu_to_le32(force_scan_interval); 1912 sc->num_ch = num_chan; 1913 1914 for (i = 0; i < num_chan; i++) 1915 sc->ch_list[i] = cpu_to_le16(ch_list[i]); 1916 1917 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_START_SCAN_CMDID, 1918 NO_SYNC_WMIFLAG); 1919 1920 return ret; 1921 } 1922 1923 int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u8 if_idx, 1924 u16 fg_start_sec, 1925 u16 fg_end_sec, u16 bg_sec, 1926 u16 minact_chdw_msec, u16 maxact_chdw_msec, 1927 u16 pas_chdw_msec, u8 short_scan_ratio, 1928 u8 scan_ctrl_flag, u32 max_dfsch_act_time, 1929 u16 maxact_scan_per_ssid) 1930 { 1931 struct sk_buff *skb; 1932 struct wmi_scan_params_cmd *sc; 1933 int ret; 1934 1935 skb = ath6kl_wmi_get_new_buf(sizeof(*sc)); 1936 if (!skb) 1937 return -ENOMEM; 1938 1939 sc = (struct wmi_scan_params_cmd *) skb->data; 1940 sc->fg_start_period = cpu_to_le16(fg_start_sec); 1941 sc->fg_end_period = cpu_to_le16(fg_end_sec); 1942 sc->bg_period = cpu_to_le16(bg_sec); 1943 sc->minact_chdwell_time = cpu_to_le16(minact_chdw_msec); 1944 sc->maxact_chdwell_time = cpu_to_le16(maxact_chdw_msec); 1945 sc->pas_chdwell_time = cpu_to_le16(pas_chdw_msec); 1946 sc->short_scan_ratio = short_scan_ratio; 1947 sc->scan_ctrl_flags = scan_ctrl_flag; 1948 sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time); 1949 sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid); 1950 1951 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_SCAN_PARAMS_CMDID, 1952 NO_SYNC_WMIFLAG); 1953 return ret; 1954 } 1955 1956 int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 if_idx, u8 filter, u32 ie_mask) 1957 { 1958 struct sk_buff *skb; 1959 struct wmi_bss_filter_cmd *cmd; 1960 int ret; 1961 1962 if (filter >= LAST_BSS_FILTER) 1963 return -EINVAL; 1964 1965 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 1966 if (!skb) 1967 return -ENOMEM; 1968 1969 cmd = (struct wmi_bss_filter_cmd *) skb->data; 1970 cmd->bss_filter = filter; 1971 cmd->ie_mask = cpu_to_le32(ie_mask); 1972 1973 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BSS_FILTER_CMDID, 1974 NO_SYNC_WMIFLAG); 1975 return ret; 1976 } 1977 1978 int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 if_idx, u8 index, u8 flag, 1979 u8 ssid_len, u8 *ssid) 1980 { 1981 struct sk_buff *skb; 1982 struct wmi_probed_ssid_cmd *cmd; 1983 int ret; 1984 1985 if (index > MAX_PROBED_SSID_INDEX) 1986 return -EINVAL; 1987 1988 if (ssid_len > sizeof(cmd->ssid)) 1989 return -EINVAL; 1990 1991 if ((flag & (DISABLE_SSID_FLAG | ANY_SSID_FLAG)) && (ssid_len > 0)) 1992 return -EINVAL; 1993 1994 if ((flag & SPECIFIC_SSID_FLAG) && !ssid_len) 1995 return -EINVAL; 1996 1997 if (flag & SPECIFIC_SSID_FLAG) 1998 wmi->is_probe_ssid = true; 1999 2000 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 2001 if (!skb) 2002 return -ENOMEM; 2003 2004 cmd = (struct wmi_probed_ssid_cmd *) skb->data; 2005 cmd->entry_index = index; 2006 cmd->flag = flag; 2007 cmd->ssid_len = ssid_len; 2008 memcpy(cmd->ssid, ssid, ssid_len); 2009 2010 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PROBED_SSID_CMDID, 2011 NO_SYNC_WMIFLAG); 2012 return ret; 2013 } 2014 2015 int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u8 if_idx, 2016 u16 listen_interval, 2017 u16 listen_beacons) 2018 { 2019 struct sk_buff *skb; 2020 struct wmi_listen_int_cmd *cmd; 2021 int ret; 2022 2023 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 2024 if (!skb) 2025 return -ENOMEM; 2026 2027 cmd = (struct wmi_listen_int_cmd *) skb->data; 2028 cmd->listen_intvl = cpu_to_le16(listen_interval); 2029 cmd->num_beacons = cpu_to_le16(listen_beacons); 2030 2031 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LISTEN_INT_CMDID, 2032 NO_SYNC_WMIFLAG); 2033 return ret; 2034 } 2035 2036 int ath6kl_wmi_bmisstime_cmd(struct wmi *wmi, u8 if_idx, 2037 u16 bmiss_time, u16 num_beacons) 2038 { 2039 struct sk_buff *skb; 2040 struct wmi_bmiss_time_cmd *cmd; 2041 int ret; 2042 2043 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 2044 if (!skb) 2045 return -ENOMEM; 2046 2047 cmd = (struct wmi_bmiss_time_cmd *) skb->data; 2048 cmd->bmiss_time = cpu_to_le16(bmiss_time); 2049 cmd->num_beacons = cpu_to_le16(num_beacons); 2050 2051 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BMISS_TIME_CMDID, 2052 NO_SYNC_WMIFLAG); 2053 return ret; 2054 } 2055 2056 int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 if_idx, u8 pwr_mode) 2057 { 2058 struct sk_buff *skb; 2059 struct wmi_power_mode_cmd *cmd; 2060 int ret; 2061 2062 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 2063 if (!skb) 2064 return -ENOMEM; 2065 2066 cmd = (struct wmi_power_mode_cmd *) skb->data; 2067 cmd->pwr_mode = pwr_mode; 2068 wmi->pwr_mode = pwr_mode; 2069 2070 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_MODE_CMDID, 2071 NO_SYNC_WMIFLAG); 2072 return ret; 2073 } 2074 2075 int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u8 if_idx, u16 idle_period, 2076 u16 ps_poll_num, u16 dtim_policy, 2077 u16 tx_wakeup_policy, u16 num_tx_to_wakeup, 2078 u16 ps_fail_event_policy) 2079 { 2080 struct sk_buff *skb; 2081 struct wmi_power_params_cmd *pm; 2082 int ret; 2083 2084 skb = ath6kl_wmi_get_new_buf(sizeof(*pm)); 2085 if (!skb) 2086 return -ENOMEM; 2087 2088 pm = (struct wmi_power_params_cmd *)skb->data; 2089 pm->idle_period = cpu_to_le16(idle_period); 2090 pm->pspoll_number = cpu_to_le16(ps_poll_num); 2091 pm->dtim_policy = cpu_to_le16(dtim_policy); 2092 pm->tx_wakeup_policy = cpu_to_le16(tx_wakeup_policy); 2093 pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup); 2094 pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy); 2095 2096 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_PARAMS_CMDID, 2097 NO_SYNC_WMIFLAG); 2098 return ret; 2099 } 2100 2101 int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 if_idx, u8 timeout) 2102 { 2103 struct sk_buff *skb; 2104 struct wmi_disc_timeout_cmd *cmd; 2105 int ret; 2106 2107 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 2108 if (!skb) 2109 return -ENOMEM; 2110 2111 cmd = (struct wmi_disc_timeout_cmd *) skb->data; 2112 cmd->discon_timeout = timeout; 2113 2114 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_DISC_TIMEOUT_CMDID, 2115 NO_SYNC_WMIFLAG); 2116 2117 if (ret == 0) 2118 ath6kl_debug_set_disconnect_timeout(wmi->parent_dev, timeout); 2119 2120 return ret; 2121 } 2122 2123 int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index, 2124 enum crypto_type key_type, 2125 u8 key_usage, u8 key_len, 2126 u8 *key_rsc, unsigned int key_rsc_len, 2127 u8 *key_material, 2128 u8 key_op_ctrl, u8 *mac_addr, 2129 enum wmi_sync_flag sync_flag) 2130 { 2131 struct sk_buff *skb; 2132 struct wmi_add_cipher_key_cmd *cmd; 2133 int ret; 2134 2135 ath6kl_dbg(ATH6KL_DBG_WMI, 2136 "addkey cmd: key_index=%u key_type=%d key_usage=%d key_len=%d key_op_ctrl=%d\n", 2137 key_index, key_type, key_usage, key_len, key_op_ctrl); 2138 2139 if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) || 2140 (key_material == NULL) || key_rsc_len > 8) 2141 return -EINVAL; 2142 2143 if ((WEP_CRYPT != key_type) && (NULL == key_rsc)) 2144 return -EINVAL; 2145 2146 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 2147 if (!skb) 2148 return -ENOMEM; 2149 2150 cmd = (struct wmi_add_cipher_key_cmd *) skb->data; 2151 cmd->key_index = key_index; 2152 cmd->key_type = key_type; 2153 cmd->key_usage = key_usage; 2154 cmd->key_len = key_len; 2155 memcpy(cmd->key, key_material, key_len); 2156 2157 if (key_rsc != NULL) 2158 memcpy(cmd->key_rsc, key_rsc, key_rsc_len); 2159 2160 cmd->key_op_ctrl = key_op_ctrl; 2161 2162 if (mac_addr) 2163 memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN); 2164 2165 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_CIPHER_KEY_CMDID, 2166 sync_flag); 2167 2168 return ret; 2169 } 2170 2171 int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 if_idx, u8 *krk) 2172 { 2173 struct sk_buff *skb; 2174 struct wmi_add_krk_cmd *cmd; 2175 int ret; 2176 2177 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 2178 if (!skb) 2179 return -ENOMEM; 2180 2181 cmd = (struct wmi_add_krk_cmd *) skb->data; 2182 memcpy(cmd->krk, krk, WMI_KRK_LEN); 2183 2184 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_KRK_CMDID, 2185 NO_SYNC_WMIFLAG); 2186 2187 return ret; 2188 } 2189 2190 int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index) 2191 { 2192 struct sk_buff *skb; 2193 struct wmi_delete_cipher_key_cmd *cmd; 2194 int ret; 2195 2196 if (key_index > WMI_MAX_KEY_INDEX) 2197 return -EINVAL; 2198 2199 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 2200 if (!skb) 2201 return -ENOMEM; 2202 2203 cmd = (struct wmi_delete_cipher_key_cmd *) skb->data; 2204 cmd->key_index = key_index; 2205 2206 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_CIPHER_KEY_CMDID, 2207 NO_SYNC_WMIFLAG); 2208 2209 return ret; 2210 } 2211 2212 int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, u8 if_idx, const u8 *bssid, 2213 const u8 *pmkid, bool set) 2214 { 2215 struct sk_buff *skb; 2216 struct wmi_setpmkid_cmd *cmd; 2217 int ret; 2218 2219 if (bssid == NULL) 2220 return -EINVAL; 2221 2222 if (set && pmkid == NULL) 2223 return -EINVAL; 2224 2225 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 2226 if (!skb) 2227 return -ENOMEM; 2228 2229 cmd = (struct wmi_setpmkid_cmd *) skb->data; 2230 memcpy(cmd->bssid, bssid, ETH_ALEN); 2231 if (set) { 2232 memcpy(cmd->pmkid, pmkid, sizeof(cmd->pmkid)); 2233 cmd->enable = PMKID_ENABLE; 2234 } else { 2235 memset(cmd->pmkid, 0, sizeof(cmd->pmkid)); 2236 cmd->enable = PMKID_DISABLE; 2237 } 2238 2239 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PMKID_CMDID, 2240 NO_SYNC_WMIFLAG); 2241 2242 return ret; 2243 } 2244 2245 static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb, 2246 enum htc_endpoint_id ep_id, u8 if_idx) 2247 { 2248 struct wmi_data_hdr *data_hdr; 2249 int ret; 2250 2251 if (WARN_ON(skb == NULL || ep_id == wmi->ep_id)) 2252 return -EINVAL; 2253 2254 skb_push(skb, sizeof(struct wmi_data_hdr)); 2255 2256 data_hdr = (struct wmi_data_hdr *) skb->data; 2257 data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT; 2258 data_hdr->info3 = cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK); 2259 2260 ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id); 2261 2262 return ret; 2263 } 2264 2265 static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx) 2266 { 2267 struct sk_buff *skb; 2268 struct wmi_sync_cmd *cmd; 2269 struct wmi_data_sync_bufs data_sync_bufs[WMM_NUM_AC]; 2270 enum htc_endpoint_id ep_id; 2271 u8 index, num_pri_streams = 0; 2272 int ret = 0; 2273 2274 memset(data_sync_bufs, 0, sizeof(data_sync_bufs)); 2275 2276 spin_lock_bh(&wmi->lock); 2277 2278 for (index = 0; index < WMM_NUM_AC; index++) { 2279 if (wmi->fat_pipe_exist & (1 << index)) { 2280 num_pri_streams++; 2281 data_sync_bufs[num_pri_streams - 1].traffic_class = 2282 index; 2283 } 2284 } 2285 2286 spin_unlock_bh(&wmi->lock); 2287 2288 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 2289 if (!skb) { 2290 ret = -ENOMEM; 2291 goto free_skb; 2292 } 2293 2294 cmd = (struct wmi_sync_cmd *) skb->data; 2295 2296 /* 2297 * In the SYNC cmd sent on the control Ep, send a bitmap 2298 * of the data eps on which the Data Sync will be sent 2299 */ 2300 cmd->data_sync_map = wmi->fat_pipe_exist; 2301 2302 for (index = 0; index < num_pri_streams; index++) { 2303 data_sync_bufs[index].skb = ath6kl_buf_alloc(0); 2304 if (data_sync_bufs[index].skb == NULL) { 2305 ret = -ENOMEM; 2306 break; 2307 } 2308 } 2309 2310 /* 2311 * If buffer allocation for any of the dataSync fails, 2312 * then do not send the Synchronize cmd on the control ep 2313 */ 2314 if (ret) 2315 goto free_skb; 2316 2317 /* 2318 * Send sync cmd followed by sync data messages on all 2319 * endpoints being used 2320 */ 2321 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SYNCHRONIZE_CMDID, 2322 NO_SYNC_WMIFLAG); 2323 2324 if (ret) 2325 goto free_skb; 2326 2327 /* cmd buffer sent, we no longer own it */ 2328 skb = NULL; 2329 2330 for (index = 0; index < num_pri_streams; index++) { 2331 2332 if (WARN_ON(!data_sync_bufs[index].skb)) 2333 break; 2334 2335 ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev, 2336 data_sync_bufs[index]. 2337 traffic_class); 2338 ret = 2339 ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb, 2340 ep_id, if_idx); 2341 2342 if (ret) 2343 break; 2344 2345 data_sync_bufs[index].skb = NULL; 2346 } 2347 2348 free_skb: 2349 /* free up any resources left over (possibly due to an error) */ 2350 if (skb) 2351 dev_kfree_skb(skb); 2352 2353 for (index = 0; index < num_pri_streams; index++) { 2354 if (data_sync_bufs[index].skb != NULL) { 2355 dev_kfree_skb((struct sk_buff *)data_sync_bufs[index]. 2356 skb); 2357 } 2358 } 2359 2360 return ret; 2361 } 2362 2363 int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi, u8 if_idx, 2364 struct wmi_create_pstream_cmd *params) 2365 { 2366 struct sk_buff *skb; 2367 struct wmi_create_pstream_cmd *cmd; 2368 u8 fatpipe_exist_for_ac = 0; 2369 s32 min_phy = 0; 2370 s32 nominal_phy = 0; 2371 int ret; 2372 2373 if (!((params->user_pri < 8) && 2374 (params->user_pri <= 0x7) && 2375 (up_to_ac[params->user_pri & 0x7] == params->traffic_class) && 2376 (params->traffic_direc == UPLINK_TRAFFIC || 2377 params->traffic_direc == DNLINK_TRAFFIC || 2378 params->traffic_direc == BIDIR_TRAFFIC) && 2379 (params->traffic_type == TRAFFIC_TYPE_APERIODIC || 2380 params->traffic_type == TRAFFIC_TYPE_PERIODIC) && 2381 (params->voice_psc_cap == DISABLE_FOR_THIS_AC || 2382 params->voice_psc_cap == ENABLE_FOR_THIS_AC || 2383 params->voice_psc_cap == ENABLE_FOR_ALL_AC) && 2384 (params->tsid == WMI_IMPLICIT_PSTREAM || 2385 params->tsid <= WMI_MAX_THINSTREAM))) { 2386 return -EINVAL; 2387 } 2388 2389 /* 2390 * Check nominal PHY rate is >= minimalPHY, 2391 * so that DUT can allow TSRS IE 2392 */ 2393 2394 /* Get the physical rate (units of bps) */ 2395 min_phy = ((le32_to_cpu(params->min_phy_rate) / 1000) / 1000); 2396 2397 /* Check minimal phy < nominal phy rate */ 2398 if (params->nominal_phy >= min_phy) { 2399 /* unit of 500 kbps */ 2400 nominal_phy = (params->nominal_phy * 1000) / 500; 2401 ath6kl_dbg(ATH6KL_DBG_WMI, 2402 "TSRS IE enabled::MinPhy %x->NominalPhy ===> %x\n", 2403 min_phy, nominal_phy); 2404 2405 params->nominal_phy = nominal_phy; 2406 } else { 2407 params->nominal_phy = 0; 2408 } 2409 2410 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 2411 if (!skb) 2412 return -ENOMEM; 2413 2414 ath6kl_dbg(ATH6KL_DBG_WMI, 2415 "sending create_pstream_cmd: ac=%d tsid:%d\n", 2416 params->traffic_class, params->tsid); 2417 2418 cmd = (struct wmi_create_pstream_cmd *) skb->data; 2419 memcpy(cmd, params, sizeof(*cmd)); 2420 2421 /* This is an implicitly created Fat pipe */ 2422 if ((u32) params->tsid == (u32) WMI_IMPLICIT_PSTREAM) { 2423 spin_lock_bh(&wmi->lock); 2424 fatpipe_exist_for_ac = (wmi->fat_pipe_exist & 2425 (1 << params->traffic_class)); 2426 wmi->fat_pipe_exist |= (1 << params->traffic_class); 2427 spin_unlock_bh(&wmi->lock); 2428 } else { 2429 /* explicitly created thin stream within a fat pipe */ 2430 spin_lock_bh(&wmi->lock); 2431 fatpipe_exist_for_ac = (wmi->fat_pipe_exist & 2432 (1 << params->traffic_class)); 2433 wmi->stream_exist_for_ac[params->traffic_class] |= 2434 (1 << params->tsid); 2435 /* 2436 * If a thinstream becomes active, the fat pipe automatically 2437 * becomes active 2438 */ 2439 wmi->fat_pipe_exist |= (1 << params->traffic_class); 2440 spin_unlock_bh(&wmi->lock); 2441 } 2442 2443 /* 2444 * Indicate activty change to driver layer only if this is the 2445 * first TSID to get created in this AC explicitly or an implicit 2446 * fat pipe is getting created. 2447 */ 2448 if (!fatpipe_exist_for_ac) 2449 ath6kl_indicate_tx_activity(wmi->parent_dev, 2450 params->traffic_class, true); 2451 2452 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CREATE_PSTREAM_CMDID, 2453 NO_SYNC_WMIFLAG); 2454 return ret; 2455 } 2456 2457 int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 if_idx, u8 traffic_class, 2458 u8 tsid) 2459 { 2460 struct sk_buff *skb; 2461 struct wmi_delete_pstream_cmd *cmd; 2462 u16 active_tsids = 0; 2463 int ret; 2464 2465 if (traffic_class > 3) { 2466 ath6kl_err("invalid traffic class: %d\n", traffic_class); 2467 return -EINVAL; 2468 } 2469 2470 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 2471 if (!skb) 2472 return -ENOMEM; 2473 2474 cmd = (struct wmi_delete_pstream_cmd *) skb->data; 2475 cmd->traffic_class = traffic_class; 2476 cmd->tsid = tsid; 2477 2478 spin_lock_bh(&wmi->lock); 2479 active_tsids = wmi->stream_exist_for_ac[traffic_class]; 2480 spin_unlock_bh(&wmi->lock); 2481 2482 if (!(active_tsids & (1 << tsid))) { 2483 dev_kfree_skb(skb); 2484 ath6kl_dbg(ATH6KL_DBG_WMI, 2485 "TSID %d doesn't exist for traffic class: %d\n", 2486 tsid, traffic_class); 2487 return -ENODATA; 2488 } 2489 2490 ath6kl_dbg(ATH6KL_DBG_WMI, 2491 "sending delete_pstream_cmd: traffic class: %d tsid=%d\n", 2492 traffic_class, tsid); 2493 2494 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_PSTREAM_CMDID, 2495 SYNC_BEFORE_WMIFLAG); 2496 2497 spin_lock_bh(&wmi->lock); 2498 wmi->stream_exist_for_ac[traffic_class] &= ~(1 << tsid); 2499 active_tsids = wmi->stream_exist_for_ac[traffic_class]; 2500 spin_unlock_bh(&wmi->lock); 2501 2502 /* 2503 * Indicate stream inactivity to driver layer only if all tsids 2504 * within this AC are deleted. 2505 */ 2506 if (!active_tsids) { 2507 ath6kl_indicate_tx_activity(wmi->parent_dev, 2508 traffic_class, false); 2509 wmi->fat_pipe_exist &= ~(1 << traffic_class); 2510 } 2511 2512 return ret; 2513 } 2514 2515 int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, u8 if_idx, 2516 __be32 ips0, __be32 ips1) 2517 { 2518 struct sk_buff *skb; 2519 struct wmi_set_ip_cmd *cmd; 2520 int ret; 2521 2522 /* Multicast address are not valid */ 2523 if (ipv4_is_multicast(ips0) || 2524 ipv4_is_multicast(ips1)) 2525 return -EINVAL; 2526 2527 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_ip_cmd)); 2528 if (!skb) 2529 return -ENOMEM; 2530 2531 cmd = (struct wmi_set_ip_cmd *) skb->data; 2532 cmd->ips[0] = ips0; 2533 cmd->ips[1] = ips1; 2534 2535 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IP_CMDID, 2536 NO_SYNC_WMIFLAG); 2537 return ret; 2538 } 2539 2540 static void ath6kl_wmi_relinquish_implicit_pstream_credits(struct wmi *wmi) 2541 { 2542 u16 active_tsids; 2543 u8 stream_exist; 2544 int i; 2545 2546 /* 2547 * Relinquish credits from all implicitly created pstreams 2548 * since when we go to sleep. If user created explicit 2549 * thinstreams exists with in a fatpipe leave them intact 2550 * for the user to delete. 2551 */ 2552 spin_lock_bh(&wmi->lock); 2553 stream_exist = wmi->fat_pipe_exist; 2554 spin_unlock_bh(&wmi->lock); 2555 2556 for (i = 0; i < WMM_NUM_AC; i++) { 2557 if (stream_exist & (1 << i)) { 2558 2559 /* 2560 * FIXME: Is this lock & unlock inside 2561 * for loop correct? may need rework. 2562 */ 2563 spin_lock_bh(&wmi->lock); 2564 active_tsids = wmi->stream_exist_for_ac[i]; 2565 spin_unlock_bh(&wmi->lock); 2566 2567 /* 2568 * If there are no user created thin streams 2569 * delete the fatpipe 2570 */ 2571 if (!active_tsids) { 2572 stream_exist &= ~(1 << i); 2573 /* 2574 * Indicate inactivity to driver layer for 2575 * this fatpipe (pstream) 2576 */ 2577 ath6kl_indicate_tx_activity(wmi->parent_dev, 2578 i, false); 2579 } 2580 } 2581 } 2582 2583 /* FIXME: Can we do this assignment without locking ? */ 2584 spin_lock_bh(&wmi->lock); 2585 wmi->fat_pipe_exist = stream_exist; 2586 spin_unlock_bh(&wmi->lock); 2587 } 2588 2589 int ath6kl_wmi_set_host_sleep_mode_cmd(struct wmi *wmi, u8 if_idx, 2590 enum ath6kl_host_mode host_mode) 2591 { 2592 struct sk_buff *skb; 2593 struct wmi_set_host_sleep_mode_cmd *cmd; 2594 int ret; 2595 2596 if ((host_mode != ATH6KL_HOST_MODE_ASLEEP) && 2597 (host_mode != ATH6KL_HOST_MODE_AWAKE)) { 2598 ath6kl_err("invalid host sleep mode: %d\n", host_mode); 2599 return -EINVAL; 2600 } 2601 2602 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 2603 if (!skb) 2604 return -ENOMEM; 2605 2606 cmd = (struct wmi_set_host_sleep_mode_cmd *) skb->data; 2607 2608 if (host_mode == ATH6KL_HOST_MODE_ASLEEP) { 2609 ath6kl_wmi_relinquish_implicit_pstream_credits(wmi); 2610 cmd->asleep = cpu_to_le32(1); 2611 } else 2612 cmd->awake = cpu_to_le32(1); 2613 2614 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, 2615 WMI_SET_HOST_SLEEP_MODE_CMDID, 2616 NO_SYNC_WMIFLAG); 2617 return ret; 2618 } 2619 2620 /* This command has zero length payload */ 2621 static int ath6kl_wmi_host_sleep_mode_cmd_prcd_evt_rx(struct wmi *wmi, 2622 struct ath6kl_vif *vif) 2623 { 2624 struct ath6kl *ar = wmi->parent_dev; 2625 2626 set_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags); 2627 wake_up(&ar->event_wq); 2628 2629 return 0; 2630 } 2631 2632 int ath6kl_wmi_set_wow_mode_cmd(struct wmi *wmi, u8 if_idx, 2633 enum ath6kl_wow_mode wow_mode, 2634 u32 filter, u16 host_req_delay) 2635 { 2636 struct sk_buff *skb; 2637 struct wmi_set_wow_mode_cmd *cmd; 2638 int ret; 2639 2640 if ((wow_mode != ATH6KL_WOW_MODE_ENABLE) && 2641 wow_mode != ATH6KL_WOW_MODE_DISABLE) { 2642 ath6kl_err("invalid wow mode: %d\n", wow_mode); 2643 return -EINVAL; 2644 } 2645 2646 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 2647 if (!skb) 2648 return -ENOMEM; 2649 2650 cmd = (struct wmi_set_wow_mode_cmd *) skb->data; 2651 cmd->enable_wow = cpu_to_le32(wow_mode); 2652 cmd->filter = cpu_to_le32(filter); 2653 cmd->host_req_delay = cpu_to_le16(host_req_delay); 2654 2655 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WOW_MODE_CMDID, 2656 NO_SYNC_WMIFLAG); 2657 return ret; 2658 } 2659 2660 int ath6kl_wmi_add_wow_pattern_cmd(struct wmi *wmi, u8 if_idx, 2661 u8 list_id, u8 filter_size, 2662 u8 filter_offset, const u8 *filter, 2663 const u8 *mask) 2664 { 2665 struct sk_buff *skb; 2666 struct wmi_add_wow_pattern_cmd *cmd; 2667 u16 size; 2668 u8 *filter_mask; 2669 int ret; 2670 2671 /* 2672 * Allocate additional memory in the buffer to hold 2673 * filter and mask value, which is twice of filter_size. 2674 */ 2675 size = sizeof(*cmd) + (2 * filter_size); 2676 2677 skb = ath6kl_wmi_get_new_buf(size); 2678 if (!skb) 2679 return -ENOMEM; 2680 2681 cmd = (struct wmi_add_wow_pattern_cmd *) skb->data; 2682 cmd->filter_list_id = list_id; 2683 cmd->filter_size = filter_size; 2684 cmd->filter_offset = filter_offset; 2685 2686 memcpy(cmd->filter, filter, filter_size); 2687 2688 filter_mask = (u8 *) (cmd->filter + filter_size); 2689 memcpy(filter_mask, mask, filter_size); 2690 2691 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_WOW_PATTERN_CMDID, 2692 NO_SYNC_WMIFLAG); 2693 2694 return ret; 2695 } 2696 2697 int ath6kl_wmi_del_wow_pattern_cmd(struct wmi *wmi, u8 if_idx, 2698 u16 list_id, u16 filter_id) 2699 { 2700 struct sk_buff *skb; 2701 struct wmi_del_wow_pattern_cmd *cmd; 2702 int ret; 2703 2704 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 2705 if (!skb) 2706 return -ENOMEM; 2707 2708 cmd = (struct wmi_del_wow_pattern_cmd *) skb->data; 2709 cmd->filter_list_id = cpu_to_le16(list_id); 2710 cmd->filter_id = cpu_to_le16(filter_id); 2711 2712 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DEL_WOW_PATTERN_CMDID, 2713 NO_SYNC_WMIFLAG); 2714 return ret; 2715 } 2716 2717 static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb, 2718 enum wmix_command_id cmd_id, 2719 enum wmi_sync_flag sync_flag) 2720 { 2721 struct wmix_cmd_hdr *cmd_hdr; 2722 int ret; 2723 2724 skb_push(skb, sizeof(struct wmix_cmd_hdr)); 2725 2726 cmd_hdr = (struct wmix_cmd_hdr *) skb->data; 2727 cmd_hdr->cmd_id = cpu_to_le32(cmd_id); 2728 2729 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_EXTENSION_CMDID, sync_flag); 2730 2731 return ret; 2732 } 2733 2734 int ath6kl_wmi_get_challenge_resp_cmd(struct wmi *wmi, u32 cookie, u32 source) 2735 { 2736 struct sk_buff *skb; 2737 struct wmix_hb_challenge_resp_cmd *cmd; 2738 int ret; 2739 2740 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 2741 if (!skb) 2742 return -ENOMEM; 2743 2744 cmd = (struct wmix_hb_challenge_resp_cmd *) skb->data; 2745 cmd->cookie = cpu_to_le32(cookie); 2746 cmd->source = cpu_to_le32(source); 2747 2748 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_HB_CHALLENGE_RESP_CMDID, 2749 NO_SYNC_WMIFLAG); 2750 return ret; 2751 } 2752 2753 int ath6kl_wmi_config_debug_module_cmd(struct wmi *wmi, u32 valid, u32 config) 2754 { 2755 struct ath6kl_wmix_dbglog_cfg_module_cmd *cmd; 2756 struct sk_buff *skb; 2757 int ret; 2758 2759 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 2760 if (!skb) 2761 return -ENOMEM; 2762 2763 cmd = (struct ath6kl_wmix_dbglog_cfg_module_cmd *) skb->data; 2764 cmd->valid = cpu_to_le32(valid); 2765 cmd->config = cpu_to_le32(config); 2766 2767 ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_DBGLOG_CFG_MODULE_CMDID, 2768 NO_SYNC_WMIFLAG); 2769 return ret; 2770 } 2771 2772 int ath6kl_wmi_get_stats_cmd(struct wmi *wmi, u8 if_idx) 2773 { 2774 return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_STATISTICS_CMDID); 2775 } 2776 2777 int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 if_idx, u8 dbM) 2778 { 2779 struct sk_buff *skb; 2780 struct wmi_set_tx_pwr_cmd *cmd; 2781 int ret; 2782 2783 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_tx_pwr_cmd)); 2784 if (!skb) 2785 return -ENOMEM; 2786 2787 cmd = (struct wmi_set_tx_pwr_cmd *) skb->data; 2788 cmd->dbM = dbM; 2789 2790 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_TX_PWR_CMDID, 2791 NO_SYNC_WMIFLAG); 2792 2793 return ret; 2794 } 2795 2796 int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi, u8 if_idx) 2797 { 2798 return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_TX_PWR_CMDID); 2799 } 2800 2801 int ath6kl_wmi_get_roam_tbl_cmd(struct wmi *wmi) 2802 { 2803 return ath6kl_wmi_simple_cmd(wmi, 0, WMI_GET_ROAM_TBL_CMDID); 2804 } 2805 2806 int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 if_idx, u8 status, 2807 u8 preamble_policy) 2808 { 2809 struct sk_buff *skb; 2810 struct wmi_set_lpreamble_cmd *cmd; 2811 int ret; 2812 2813 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_lpreamble_cmd)); 2814 if (!skb) 2815 return -ENOMEM; 2816 2817 cmd = (struct wmi_set_lpreamble_cmd *) skb->data; 2818 cmd->status = status; 2819 cmd->preamble_policy = preamble_policy; 2820 2821 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LPREAMBLE_CMDID, 2822 NO_SYNC_WMIFLAG); 2823 return ret; 2824 } 2825 2826 int ath6kl_wmi_set_rts_cmd(struct wmi *wmi, u16 threshold) 2827 { 2828 struct sk_buff *skb; 2829 struct wmi_set_rts_cmd *cmd; 2830 int ret; 2831 2832 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_rts_cmd)); 2833 if (!skb) 2834 return -ENOMEM; 2835 2836 cmd = (struct wmi_set_rts_cmd *) skb->data; 2837 cmd->threshold = cpu_to_le16(threshold); 2838 2839 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_RTS_CMDID, 2840 NO_SYNC_WMIFLAG); 2841 return ret; 2842 } 2843 2844 int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, u8 if_idx, enum wmi_txop_cfg cfg) 2845 { 2846 struct sk_buff *skb; 2847 struct wmi_set_wmm_txop_cmd *cmd; 2848 int ret; 2849 2850 if (!((cfg == WMI_TXOP_DISABLED) || (cfg == WMI_TXOP_ENABLED))) 2851 return -EINVAL; 2852 2853 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_wmm_txop_cmd)); 2854 if (!skb) 2855 return -ENOMEM; 2856 2857 cmd = (struct wmi_set_wmm_txop_cmd *) skb->data; 2858 cmd->txop_enable = cfg; 2859 2860 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WMM_TXOP_CMDID, 2861 NO_SYNC_WMIFLAG); 2862 return ret; 2863 } 2864 2865 int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 if_idx, 2866 u8 keep_alive_intvl) 2867 { 2868 struct sk_buff *skb; 2869 struct wmi_set_keepalive_cmd *cmd; 2870 int ret; 2871 2872 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 2873 if (!skb) 2874 return -ENOMEM; 2875 2876 cmd = (struct wmi_set_keepalive_cmd *) skb->data; 2877 cmd->keep_alive_intvl = keep_alive_intvl; 2878 2879 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_KEEPALIVE_CMDID, 2880 NO_SYNC_WMIFLAG); 2881 2882 if (ret == 0) 2883 ath6kl_debug_set_keepalive(wmi->parent_dev, keep_alive_intvl); 2884 2885 return ret; 2886 } 2887 2888 int ath6kl_wmi_set_htcap_cmd(struct wmi *wmi, u8 if_idx, 2889 enum ieee80211_band band, 2890 struct ath6kl_htcap *htcap) 2891 { 2892 struct sk_buff *skb; 2893 struct wmi_set_htcap_cmd *cmd; 2894 2895 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 2896 if (!skb) 2897 return -ENOMEM; 2898 2899 cmd = (struct wmi_set_htcap_cmd *) skb->data; 2900 2901 /* 2902 * NOTE: Band in firmware matches enum ieee80211_band, it is unlikely 2903 * this will be changed in firmware. If at all there is any change in 2904 * band value, the host needs to be fixed. 2905 */ 2906 cmd->band = band; 2907 cmd->ht_enable = !!htcap->ht_enable; 2908 cmd->ht20_sgi = !!(htcap->cap_info & IEEE80211_HT_CAP_SGI_20); 2909 cmd->ht40_supported = 2910 !!(htcap->cap_info & IEEE80211_HT_CAP_SUP_WIDTH_20_40); 2911 cmd->ht40_sgi = !!(htcap->cap_info & IEEE80211_HT_CAP_SGI_40); 2912 cmd->intolerant_40mhz = 2913 !!(htcap->cap_info & IEEE80211_HT_CAP_40MHZ_INTOLERANT); 2914 cmd->max_ampdu_len_exp = htcap->ampdu_factor; 2915 2916 ath6kl_dbg(ATH6KL_DBG_WMI, 2917 "Set htcap: band:%d ht_enable:%d 40mhz:%d sgi_20mhz:%d sgi_40mhz:%d 40mhz_intolerant:%d ampdu_len_exp:%d\n", 2918 cmd->band, cmd->ht_enable, cmd->ht40_supported, 2919 cmd->ht20_sgi, cmd->ht40_sgi, cmd->intolerant_40mhz, 2920 cmd->max_ampdu_len_exp); 2921 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_HT_CAP_CMDID, 2922 NO_SYNC_WMIFLAG); 2923 } 2924 2925 int ath6kl_wmi_test_cmd(struct wmi *wmi, void *buf, size_t len) 2926 { 2927 struct sk_buff *skb; 2928 int ret; 2929 2930 skb = ath6kl_wmi_get_new_buf(len); 2931 if (!skb) 2932 return -ENOMEM; 2933 2934 memcpy(skb->data, buf, len); 2935 2936 ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_TEST_CMDID, NO_SYNC_WMIFLAG); 2937 2938 return ret; 2939 } 2940 2941 int ath6kl_wmi_mcast_filter_cmd(struct wmi *wmi, u8 if_idx, bool mc_all_on) 2942 { 2943 struct sk_buff *skb; 2944 struct wmi_mcast_filter_cmd *cmd; 2945 int ret; 2946 2947 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 2948 if (!skb) 2949 return -ENOMEM; 2950 2951 cmd = (struct wmi_mcast_filter_cmd *) skb->data; 2952 cmd->mcast_all_enable = mc_all_on; 2953 2954 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_MCAST_FILTER_CMDID, 2955 NO_SYNC_WMIFLAG); 2956 return ret; 2957 } 2958 2959 int ath6kl_wmi_add_del_mcast_filter_cmd(struct wmi *wmi, u8 if_idx, 2960 u8 *filter, bool add_filter) 2961 { 2962 struct sk_buff *skb; 2963 struct wmi_mcast_filter_add_del_cmd *cmd; 2964 int ret; 2965 2966 if ((filter[0] != 0x33 || filter[1] != 0x33) && 2967 (filter[0] != 0x01 || filter[1] != 0x00 || 2968 filter[2] != 0x5e || filter[3] > 0x7f)) { 2969 ath6kl_warn("invalid multicast filter address\n"); 2970 return -EINVAL; 2971 } 2972 2973 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 2974 if (!skb) 2975 return -ENOMEM; 2976 2977 cmd = (struct wmi_mcast_filter_add_del_cmd *) skb->data; 2978 memcpy(cmd->mcast_mac, filter, ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE); 2979 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, 2980 add_filter ? WMI_SET_MCAST_FILTER_CMDID : 2981 WMI_DEL_MCAST_FILTER_CMDID, 2982 NO_SYNC_WMIFLAG); 2983 2984 return ret; 2985 } 2986 2987 s32 ath6kl_wmi_get_rate(s8 rate_index) 2988 { 2989 if (rate_index == RATE_AUTO) 2990 return 0; 2991 2992 return wmi_rate_tbl[(u32) rate_index][0]; 2993 } 2994 2995 static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap, 2996 u32 len) 2997 { 2998 struct wmi_pmkid_list_reply *reply; 2999 u32 expected_len; 3000 3001 if (len < sizeof(struct wmi_pmkid_list_reply)) 3002 return -EINVAL; 3003 3004 reply = (struct wmi_pmkid_list_reply *)datap; 3005 expected_len = sizeof(reply->num_pmkid) + 3006 le32_to_cpu(reply->num_pmkid) * WMI_PMKID_LEN; 3007 3008 if (len < expected_len) 3009 return -EINVAL; 3010 3011 return 0; 3012 } 3013 3014 static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len, 3015 struct ath6kl_vif *vif) 3016 { 3017 struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap; 3018 3019 aggr_recv_addba_req_evt(vif, cmd->tid, 3020 le16_to_cpu(cmd->st_seq_no), cmd->win_sz); 3021 3022 return 0; 3023 } 3024 3025 static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len, 3026 struct ath6kl_vif *vif) 3027 { 3028 struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap; 3029 3030 aggr_recv_delba_req_evt(vif, cmd->tid); 3031 3032 return 0; 3033 } 3034 3035 /* AP mode functions */ 3036 3037 int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, u8 if_idx, 3038 struct wmi_connect_cmd *p) 3039 { 3040 struct sk_buff *skb; 3041 struct wmi_connect_cmd *cm; 3042 int res; 3043 3044 skb = ath6kl_wmi_get_new_buf(sizeof(*cm)); 3045 if (!skb) 3046 return -ENOMEM; 3047 3048 cm = (struct wmi_connect_cmd *) skb->data; 3049 memcpy(cm, p, sizeof(*cm)); 3050 3051 res = ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_CONFIG_COMMIT_CMDID, 3052 NO_SYNC_WMIFLAG); 3053 ath6kl_dbg(ATH6KL_DBG_WMI, 3054 "%s: nw_type=%u auth_mode=%u ch=%u ctrl_flags=0x%x-> res=%d\n", 3055 __func__, p->nw_type, p->auth_mode, le16_to_cpu(p->ch), 3056 le32_to_cpu(p->ctrl_flags), res); 3057 return res; 3058 } 3059 3060 int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 if_idx, u8 cmd, const u8 *mac, 3061 u16 reason) 3062 { 3063 struct sk_buff *skb; 3064 struct wmi_ap_set_mlme_cmd *cm; 3065 3066 skb = ath6kl_wmi_get_new_buf(sizeof(*cm)); 3067 if (!skb) 3068 return -ENOMEM; 3069 3070 cm = (struct wmi_ap_set_mlme_cmd *) skb->data; 3071 memcpy(cm->mac, mac, ETH_ALEN); 3072 cm->reason = cpu_to_le16(reason); 3073 cm->cmd = cmd; 3074 3075 ath6kl_dbg(ATH6KL_DBG_WMI, "ap_set_mlme: cmd=%d reason=%d\n", cm->cmd, 3076 cm->reason); 3077 3078 return ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_SET_MLME_CMDID, 3079 NO_SYNC_WMIFLAG); 3080 } 3081 3082 int ath6kl_wmi_ap_hidden_ssid(struct wmi *wmi, u8 if_idx, bool enable) 3083 { 3084 struct sk_buff *skb; 3085 struct wmi_ap_hidden_ssid_cmd *cmd; 3086 3087 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 3088 if (!skb) 3089 return -ENOMEM; 3090 3091 cmd = (struct wmi_ap_hidden_ssid_cmd *) skb->data; 3092 cmd->hidden_ssid = enable ? 1 : 0; 3093 3094 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_HIDDEN_SSID_CMDID, 3095 NO_SYNC_WMIFLAG); 3096 } 3097 3098 /* This command will be used to enable/disable AP uAPSD feature */ 3099 int ath6kl_wmi_ap_set_apsd(struct wmi *wmi, u8 if_idx, u8 enable) 3100 { 3101 struct wmi_ap_set_apsd_cmd *cmd; 3102 struct sk_buff *skb; 3103 3104 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 3105 if (!skb) 3106 return -ENOMEM; 3107 3108 cmd = (struct wmi_ap_set_apsd_cmd *)skb->data; 3109 cmd->enable = enable; 3110 3111 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_APSD_CMDID, 3112 NO_SYNC_WMIFLAG); 3113 } 3114 3115 int ath6kl_wmi_set_apsd_bfrd_traf(struct wmi *wmi, u8 if_idx, 3116 u16 aid, u16 bitmap, u32 flags) 3117 { 3118 struct wmi_ap_apsd_buffered_traffic_cmd *cmd; 3119 struct sk_buff *skb; 3120 3121 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 3122 if (!skb) 3123 return -ENOMEM; 3124 3125 cmd = (struct wmi_ap_apsd_buffered_traffic_cmd *)skb->data; 3126 cmd->aid = cpu_to_le16(aid); 3127 cmd->bitmap = cpu_to_le16(bitmap); 3128 cmd->flags = cpu_to_le32(flags); 3129 3130 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, 3131 WMI_AP_APSD_BUFFERED_TRAFFIC_CMDID, 3132 NO_SYNC_WMIFLAG); 3133 } 3134 3135 static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len, 3136 struct ath6kl_vif *vif) 3137 { 3138 struct wmi_pspoll_event *ev; 3139 3140 if (len < sizeof(struct wmi_pspoll_event)) 3141 return -EINVAL; 3142 3143 ev = (struct wmi_pspoll_event *) datap; 3144 3145 ath6kl_pspoll_event(vif, le16_to_cpu(ev->aid)); 3146 3147 return 0; 3148 } 3149 3150 static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len, 3151 struct ath6kl_vif *vif) 3152 { 3153 ath6kl_dtimexpiry_event(vif); 3154 3155 return 0; 3156 } 3157 3158 int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u8 if_idx, u16 aid, 3159 bool flag) 3160 { 3161 struct sk_buff *skb; 3162 struct wmi_ap_set_pvb_cmd *cmd; 3163 int ret; 3164 3165 skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_ap_set_pvb_cmd)); 3166 if (!skb) 3167 return -ENOMEM; 3168 3169 cmd = (struct wmi_ap_set_pvb_cmd *) skb->data; 3170 cmd->aid = cpu_to_le16(aid); 3171 cmd->rsvd = cpu_to_le16(0); 3172 cmd->flag = cpu_to_le32(flag); 3173 3174 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_PVB_CMDID, 3175 NO_SYNC_WMIFLAG); 3176 3177 return 0; 3178 } 3179 3180 int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 if_idx, 3181 u8 rx_meta_ver, 3182 bool rx_dot11_hdr, bool defrag_on_host) 3183 { 3184 struct sk_buff *skb; 3185 struct wmi_rx_frame_format_cmd *cmd; 3186 int ret; 3187 3188 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 3189 if (!skb) 3190 return -ENOMEM; 3191 3192 cmd = (struct wmi_rx_frame_format_cmd *) skb->data; 3193 cmd->dot11_hdr = rx_dot11_hdr ? 1 : 0; 3194 cmd->defrag_on_host = defrag_on_host ? 1 : 0; 3195 cmd->meta_ver = rx_meta_ver; 3196 3197 /* Delete the local aggr state, on host */ 3198 ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RX_FRAME_FORMAT_CMDID, 3199 NO_SYNC_WMIFLAG); 3200 3201 return ret; 3202 } 3203 3204 int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 if_idx, u8 mgmt_frm_type, 3205 const u8 *ie, u8 ie_len) 3206 { 3207 struct sk_buff *skb; 3208 struct wmi_set_appie_cmd *p; 3209 3210 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len); 3211 if (!skb) 3212 return -ENOMEM; 3213 3214 ath6kl_dbg(ATH6KL_DBG_WMI, 3215 "set_appie_cmd: mgmt_frm_type=%u ie_len=%u\n", 3216 mgmt_frm_type, ie_len); 3217 p = (struct wmi_set_appie_cmd *) skb->data; 3218 p->mgmt_frm_type = mgmt_frm_type; 3219 p->ie_len = ie_len; 3220 3221 if (ie != NULL && ie_len > 0) 3222 memcpy(p->ie_info, ie, ie_len); 3223 3224 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_APPIE_CMDID, 3225 NO_SYNC_WMIFLAG); 3226 } 3227 3228 int ath6kl_wmi_set_ie_cmd(struct wmi *wmi, u8 if_idx, u8 ie_id, u8 ie_field, 3229 const u8 *ie_info, u8 ie_len) 3230 { 3231 struct sk_buff *skb; 3232 struct wmi_set_ie_cmd *p; 3233 3234 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len); 3235 if (!skb) 3236 return -ENOMEM; 3237 3238 ath6kl_dbg(ATH6KL_DBG_WMI, "set_ie_cmd: ie_id=%u ie_ie_field=%u ie_len=%u\n", 3239 ie_id, ie_field, ie_len); 3240 p = (struct wmi_set_ie_cmd *) skb->data; 3241 p->ie_id = ie_id; 3242 p->ie_field = ie_field; 3243 p->ie_len = ie_len; 3244 if (ie_info && ie_len > 0) 3245 memcpy(p->ie_info, ie_info, ie_len); 3246 3247 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IE_CMDID, 3248 NO_SYNC_WMIFLAG); 3249 } 3250 3251 int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable) 3252 { 3253 struct sk_buff *skb; 3254 struct wmi_disable_11b_rates_cmd *cmd; 3255 3256 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 3257 if (!skb) 3258 return -ENOMEM; 3259 3260 ath6kl_dbg(ATH6KL_DBG_WMI, "disable_11b_rates_cmd: disable=%u\n", 3261 disable); 3262 cmd = (struct wmi_disable_11b_rates_cmd *) skb->data; 3263 cmd->disable = disable ? 1 : 0; 3264 3265 return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_DISABLE_11B_RATES_CMDID, 3266 NO_SYNC_WMIFLAG); 3267 } 3268 3269 int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx, u32 freq, u32 dur) 3270 { 3271 struct sk_buff *skb; 3272 struct wmi_remain_on_chnl_cmd *p; 3273 3274 skb = ath6kl_wmi_get_new_buf(sizeof(*p)); 3275 if (!skb) 3276 return -ENOMEM; 3277 3278 ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl_cmd: freq=%u dur=%u\n", 3279 freq, dur); 3280 p = (struct wmi_remain_on_chnl_cmd *) skb->data; 3281 p->freq = cpu_to_le32(freq); 3282 p->duration = cpu_to_le32(dur); 3283 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_REMAIN_ON_CHNL_CMDID, 3284 NO_SYNC_WMIFLAG); 3285 } 3286 3287 /* ath6kl_wmi_send_action_cmd is to be deprecated. Use 3288 * ath6kl_wmi_send_mgmt_cmd instead. The new function supports P2P 3289 * mgmt operations using station interface. 3290 */ 3291 static int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u8 if_idx, u32 id, 3292 u32 freq, u32 wait, const u8 *data, 3293 u16 data_len) 3294 { 3295 struct sk_buff *skb; 3296 struct wmi_send_action_cmd *p; 3297 u8 *buf; 3298 3299 if (wait) 3300 return -EINVAL; /* Offload for wait not supported */ 3301 3302 buf = kmalloc(data_len, GFP_KERNEL); 3303 if (!buf) 3304 return -ENOMEM; 3305 3306 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len); 3307 if (!skb) { 3308 kfree(buf); 3309 return -ENOMEM; 3310 } 3311 3312 kfree(wmi->last_mgmt_tx_frame); 3313 memcpy(buf, data, data_len); 3314 wmi->last_mgmt_tx_frame = buf; 3315 wmi->last_mgmt_tx_frame_len = data_len; 3316 3317 ath6kl_dbg(ATH6KL_DBG_WMI, 3318 "send_action_cmd: id=%u freq=%u wait=%u len=%u\n", 3319 id, freq, wait, data_len); 3320 p = (struct wmi_send_action_cmd *) skb->data; 3321 p->id = cpu_to_le32(id); 3322 p->freq = cpu_to_le32(freq); 3323 p->wait = cpu_to_le32(wait); 3324 p->len = cpu_to_le16(data_len); 3325 memcpy(p->data, data, data_len); 3326 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_ACTION_CMDID, 3327 NO_SYNC_WMIFLAG); 3328 } 3329 3330 static int __ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id, 3331 u32 freq, u32 wait, const u8 *data, 3332 u16 data_len, u32 no_cck) 3333 { 3334 struct sk_buff *skb; 3335 struct wmi_send_mgmt_cmd *p; 3336 u8 *buf; 3337 3338 if (wait) 3339 return -EINVAL; /* Offload for wait not supported */ 3340 3341 buf = kmalloc(data_len, GFP_KERNEL); 3342 if (!buf) 3343 return -ENOMEM; 3344 3345 skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len); 3346 if (!skb) { 3347 kfree(buf); 3348 return -ENOMEM; 3349 } 3350 3351 kfree(wmi->last_mgmt_tx_frame); 3352 memcpy(buf, data, data_len); 3353 wmi->last_mgmt_tx_frame = buf; 3354 wmi->last_mgmt_tx_frame_len = data_len; 3355 3356 ath6kl_dbg(ATH6KL_DBG_WMI, 3357 "send_action_cmd: id=%u freq=%u wait=%u len=%u\n", 3358 id, freq, wait, data_len); 3359 p = (struct wmi_send_mgmt_cmd *) skb->data; 3360 p->id = cpu_to_le32(id); 3361 p->freq = cpu_to_le32(freq); 3362 p->wait = cpu_to_le32(wait); 3363 p->no_cck = cpu_to_le32(no_cck); 3364 p->len = cpu_to_le16(data_len); 3365 memcpy(p->data, data, data_len); 3366 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_MGMT_CMDID, 3367 NO_SYNC_WMIFLAG); 3368 } 3369 3370 int ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id, u32 freq, 3371 u32 wait, const u8 *data, u16 data_len, 3372 u32 no_cck) 3373 { 3374 int status; 3375 struct ath6kl *ar = wmi->parent_dev; 3376 3377 if (test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX, 3378 ar->fw_capabilities)) { 3379 /* 3380 * If capable of doing P2P mgmt operations using 3381 * station interface, send additional information like 3382 * supported rates to advertise and xmit rates for 3383 * probe requests 3384 */ 3385 status = __ath6kl_wmi_send_mgmt_cmd(ar->wmi, if_idx, id, freq, 3386 wait, data, data_len, 3387 no_cck); 3388 } else { 3389 status = ath6kl_wmi_send_action_cmd(ar->wmi, if_idx, id, freq, 3390 wait, data, data_len); 3391 } 3392 3393 return status; 3394 } 3395 3396 int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u8 if_idx, u32 freq, 3397 const u8 *dst, const u8 *data, 3398 u16 data_len) 3399 { 3400 struct sk_buff *skb; 3401 struct wmi_p2p_probe_response_cmd *p; 3402 size_t cmd_len = sizeof(*p) + data_len; 3403 3404 if (data_len == 0) 3405 cmd_len++; /* work around target minimum length requirement */ 3406 3407 skb = ath6kl_wmi_get_new_buf(cmd_len); 3408 if (!skb) 3409 return -ENOMEM; 3410 3411 ath6kl_dbg(ATH6KL_DBG_WMI, 3412 "send_probe_response_cmd: freq=%u dst=%pM len=%u\n", 3413 freq, dst, data_len); 3414 p = (struct wmi_p2p_probe_response_cmd *) skb->data; 3415 p->freq = cpu_to_le32(freq); 3416 memcpy(p->destination_addr, dst, ETH_ALEN); 3417 p->len = cpu_to_le16(data_len); 3418 memcpy(p->data, data, data_len); 3419 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, 3420 WMI_SEND_PROBE_RESPONSE_CMDID, 3421 NO_SYNC_WMIFLAG); 3422 } 3423 3424 int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, u8 if_idx, bool enable) 3425 { 3426 struct sk_buff *skb; 3427 struct wmi_probe_req_report_cmd *p; 3428 3429 skb = ath6kl_wmi_get_new_buf(sizeof(*p)); 3430 if (!skb) 3431 return -ENOMEM; 3432 3433 ath6kl_dbg(ATH6KL_DBG_WMI, "probe_report_req_cmd: enable=%u\n", 3434 enable); 3435 p = (struct wmi_probe_req_report_cmd *) skb->data; 3436 p->enable = enable ? 1 : 0; 3437 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_PROBE_REQ_REPORT_CMDID, 3438 NO_SYNC_WMIFLAG); 3439 } 3440 3441 int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u8 if_idx, u32 info_req_flags) 3442 { 3443 struct sk_buff *skb; 3444 struct wmi_get_p2p_info *p; 3445 3446 skb = ath6kl_wmi_get_new_buf(sizeof(*p)); 3447 if (!skb) 3448 return -ENOMEM; 3449 3450 ath6kl_dbg(ATH6KL_DBG_WMI, "info_req_cmd: flags=%x\n", 3451 info_req_flags); 3452 p = (struct wmi_get_p2p_info *) skb->data; 3453 p->info_req_flags = cpu_to_le32(info_req_flags); 3454 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_GET_P2P_INFO_CMDID, 3455 NO_SYNC_WMIFLAG); 3456 } 3457 3458 int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx) 3459 { 3460 ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl_cmd\n"); 3461 return ath6kl_wmi_simple_cmd(wmi, if_idx, 3462 WMI_CANCEL_REMAIN_ON_CHNL_CMDID); 3463 } 3464 3465 int ath6kl_wmi_set_inact_period(struct wmi *wmi, u8 if_idx, int inact_timeout) 3466 { 3467 struct sk_buff *skb; 3468 struct wmi_set_inact_period_cmd *cmd; 3469 3470 skb = ath6kl_wmi_get_new_buf(sizeof(*cmd)); 3471 if (!skb) 3472 return -ENOMEM; 3473 3474 cmd = (struct wmi_set_inact_period_cmd *) skb->data; 3475 cmd->inact_period = cpu_to_le32(inact_timeout); 3476 cmd->num_null_func = 0; 3477 3478 return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_CONN_INACT_CMDID, 3479 NO_SYNC_WMIFLAG); 3480 } 3481 3482 static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb) 3483 { 3484 struct wmix_cmd_hdr *cmd; 3485 u32 len; 3486 u16 id; 3487 u8 *datap; 3488 int ret = 0; 3489 3490 if (skb->len < sizeof(struct wmix_cmd_hdr)) { 3491 ath6kl_err("bad packet 1\n"); 3492 return -EINVAL; 3493 } 3494 3495 cmd = (struct wmix_cmd_hdr *) skb->data; 3496 id = le32_to_cpu(cmd->cmd_id); 3497 3498 skb_pull(skb, sizeof(struct wmix_cmd_hdr)); 3499 3500 datap = skb->data; 3501 len = skb->len; 3502 3503 switch (id) { 3504 case WMIX_HB_CHALLENGE_RESP_EVENTID: 3505 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event hb challenge resp\n"); 3506 break; 3507 case WMIX_DBGLOG_EVENTID: 3508 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event dbglog len %d\n", len); 3509 ath6kl_debug_fwlog_event(wmi->parent_dev, datap, len); 3510 break; 3511 default: 3512 ath6kl_warn("unknown cmd id 0x%x\n", id); 3513 ret = -EINVAL; 3514 break; 3515 } 3516 3517 return ret; 3518 } 3519 3520 static int ath6kl_wmi_roam_tbl_event_rx(struct wmi *wmi, u8 *datap, int len) 3521 { 3522 return ath6kl_debug_roam_tbl_event(wmi->parent_dev, datap, len); 3523 } 3524 3525 /* Process interface specific wmi events, caller would free the datap */ 3526 static int ath6kl_wmi_proc_events_vif(struct wmi *wmi, u16 if_idx, u16 cmd_id, 3527 u8 *datap, u32 len) 3528 { 3529 struct ath6kl_vif *vif; 3530 3531 vif = ath6kl_get_vif_by_index(wmi->parent_dev, if_idx); 3532 if (!vif) { 3533 ath6kl_dbg(ATH6KL_DBG_WMI, 3534 "Wmi event for unavailable vif, vif_index:%d\n", 3535 if_idx); 3536 return -EINVAL; 3537 } 3538 3539 switch (cmd_id) { 3540 case WMI_CONNECT_EVENTID: 3541 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n"); 3542 return ath6kl_wmi_connect_event_rx(wmi, datap, len, vif); 3543 case WMI_DISCONNECT_EVENTID: 3544 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n"); 3545 return ath6kl_wmi_disconnect_event_rx(wmi, datap, len, vif); 3546 case WMI_TKIP_MICERR_EVENTID: 3547 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n"); 3548 return ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len, vif); 3549 case WMI_BSSINFO_EVENTID: 3550 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n"); 3551 return ath6kl_wmi_bssinfo_event_rx(wmi, datap, len, vif); 3552 case WMI_NEIGHBOR_REPORT_EVENTID: 3553 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n"); 3554 return ath6kl_wmi_neighbor_report_event_rx(wmi, datap, len, 3555 vif); 3556 case WMI_SCAN_COMPLETE_EVENTID: 3557 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n"); 3558 return ath6kl_wmi_scan_complete_rx(wmi, datap, len, vif); 3559 case WMI_REPORT_STATISTICS_EVENTID: 3560 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n"); 3561 return ath6kl_wmi_stats_event_rx(wmi, datap, len, vif); 3562 case WMI_CAC_EVENTID: 3563 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n"); 3564 return ath6kl_wmi_cac_event_rx(wmi, datap, len, vif); 3565 case WMI_PSPOLL_EVENTID: 3566 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n"); 3567 return ath6kl_wmi_pspoll_event_rx(wmi, datap, len, vif); 3568 case WMI_DTIMEXPIRY_EVENTID: 3569 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n"); 3570 return ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len, vif); 3571 case WMI_ADDBA_REQ_EVENTID: 3572 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n"); 3573 return ath6kl_wmi_addba_req_event_rx(wmi, datap, len, vif); 3574 case WMI_DELBA_REQ_EVENTID: 3575 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n"); 3576 return ath6kl_wmi_delba_req_event_rx(wmi, datap, len, vif); 3577 case WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID: 3578 ath6kl_dbg(ATH6KL_DBG_WMI, 3579 "WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID"); 3580 return ath6kl_wmi_host_sleep_mode_cmd_prcd_evt_rx(wmi, vif); 3581 case WMI_REMAIN_ON_CHNL_EVENTID: 3582 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REMAIN_ON_CHNL_EVENTID\n"); 3583 return ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len, vif); 3584 case WMI_CANCEL_REMAIN_ON_CHNL_EVENTID: 3585 ath6kl_dbg(ATH6KL_DBG_WMI, 3586 "WMI_CANCEL_REMAIN_ON_CHNL_EVENTID\n"); 3587 return ath6kl_wmi_cancel_remain_on_chnl_event_rx(wmi, datap, 3588 len, vif); 3589 case WMI_TX_STATUS_EVENTID: 3590 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_STATUS_EVENTID\n"); 3591 return ath6kl_wmi_tx_status_event_rx(wmi, datap, len, vif); 3592 case WMI_RX_PROBE_REQ_EVENTID: 3593 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_PROBE_REQ_EVENTID\n"); 3594 return ath6kl_wmi_rx_probe_req_event_rx(wmi, datap, len, vif); 3595 case WMI_RX_ACTION_EVENTID: 3596 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_ACTION_EVENTID\n"); 3597 return ath6kl_wmi_rx_action_event_rx(wmi, datap, len, vif); 3598 default: 3599 ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", cmd_id); 3600 return -EINVAL; 3601 } 3602 3603 return 0; 3604 } 3605 3606 static int ath6kl_wmi_proc_events(struct wmi *wmi, struct sk_buff *skb) 3607 { 3608 struct wmi_cmd_hdr *cmd; 3609 int ret = 0; 3610 u32 len; 3611 u16 id; 3612 u8 if_idx; 3613 u8 *datap; 3614 3615 cmd = (struct wmi_cmd_hdr *) skb->data; 3616 id = le16_to_cpu(cmd->cmd_id); 3617 if_idx = le16_to_cpu(cmd->info1) & WMI_CMD_HDR_IF_ID_MASK; 3618 3619 skb_pull(skb, sizeof(struct wmi_cmd_hdr)); 3620 datap = skb->data; 3621 len = skb->len; 3622 3623 ath6kl_dbg(ATH6KL_DBG_WMI, "wmi rx id %d len %d\n", id, len); 3624 ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi rx ", 3625 datap, len); 3626 3627 switch (id) { 3628 case WMI_GET_BITRATE_CMDID: 3629 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_BITRATE_CMDID\n"); 3630 ret = ath6kl_wmi_bitrate_reply_rx(wmi, datap, len); 3631 break; 3632 case WMI_GET_CHANNEL_LIST_CMDID: 3633 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_CHANNEL_LIST_CMDID\n"); 3634 ret = ath6kl_wmi_ch_list_reply_rx(wmi, datap, len); 3635 break; 3636 case WMI_GET_TX_PWR_CMDID: 3637 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_TX_PWR_CMDID\n"); 3638 ret = ath6kl_wmi_tx_pwr_reply_rx(wmi, datap, len); 3639 break; 3640 case WMI_READY_EVENTID: 3641 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_READY_EVENTID\n"); 3642 ret = ath6kl_wmi_ready_event_rx(wmi, datap, len); 3643 break; 3644 case WMI_PEER_NODE_EVENTID: 3645 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n"); 3646 ret = ath6kl_wmi_peer_node_event_rx(wmi, datap, len); 3647 break; 3648 case WMI_REGDOMAIN_EVENTID: 3649 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n"); 3650 ath6kl_wmi_regdomain_event(wmi, datap, len); 3651 break; 3652 case WMI_PSTREAM_TIMEOUT_EVENTID: 3653 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n"); 3654 ret = ath6kl_wmi_pstream_timeout_event_rx(wmi, datap, len); 3655 break; 3656 case WMI_CMDERROR_EVENTID: 3657 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n"); 3658 ret = ath6kl_wmi_error_event_rx(wmi, datap, len); 3659 break; 3660 case WMI_RSSI_THRESHOLD_EVENTID: 3661 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n"); 3662 ret = ath6kl_wmi_rssi_threshold_event_rx(wmi, datap, len); 3663 break; 3664 case WMI_ERROR_REPORT_EVENTID: 3665 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ERROR_REPORT_EVENTID\n"); 3666 break; 3667 case WMI_OPT_RX_FRAME_EVENTID: 3668 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n"); 3669 /* this event has been deprecated */ 3670 break; 3671 case WMI_REPORT_ROAM_TBL_EVENTID: 3672 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n"); 3673 ret = ath6kl_wmi_roam_tbl_event_rx(wmi, datap, len); 3674 break; 3675 case WMI_EXTENSION_EVENTID: 3676 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n"); 3677 ret = ath6kl_wmi_control_rx_xtnd(wmi, skb); 3678 break; 3679 case WMI_CHANNEL_CHANGE_EVENTID: 3680 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n"); 3681 break; 3682 case WMI_REPORT_ROAM_DATA_EVENTID: 3683 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n"); 3684 break; 3685 case WMI_TEST_EVENTID: 3686 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TEST_EVENTID\n"); 3687 ret = ath6kl_wmi_test_rx(wmi, datap, len); 3688 break; 3689 case WMI_GET_FIXRATES_CMDID: 3690 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n"); 3691 ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len); 3692 break; 3693 case WMI_TX_RETRY_ERR_EVENTID: 3694 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_RETRY_ERR_EVENTID\n"); 3695 break; 3696 case WMI_SNR_THRESHOLD_EVENTID: 3697 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SNR_THRESHOLD_EVENTID\n"); 3698 ret = ath6kl_wmi_snr_threshold_event_rx(wmi, datap, len); 3699 break; 3700 case WMI_LQ_THRESHOLD_EVENTID: 3701 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_LQ_THRESHOLD_EVENTID\n"); 3702 break; 3703 case WMI_APLIST_EVENTID: 3704 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_APLIST_EVENTID\n"); 3705 ret = ath6kl_wmi_aplist_event_rx(wmi, datap, len); 3706 break; 3707 case WMI_GET_KEEPALIVE_CMDID: 3708 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_KEEPALIVE_CMDID\n"); 3709 ret = ath6kl_wmi_keepalive_reply_rx(wmi, datap, len); 3710 break; 3711 case WMI_GET_WOW_LIST_EVENTID: 3712 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n"); 3713 break; 3714 case WMI_GET_PMKID_LIST_EVENTID: 3715 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n"); 3716 ret = ath6kl_wmi_get_pmkid_list_event_rx(wmi, datap, len); 3717 break; 3718 case WMI_SET_PARAMS_REPLY_EVENTID: 3719 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n"); 3720 break; 3721 case WMI_ADDBA_RESP_EVENTID: 3722 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n"); 3723 break; 3724 case WMI_REPORT_BTCOEX_CONFIG_EVENTID: 3725 ath6kl_dbg(ATH6KL_DBG_WMI, 3726 "WMI_REPORT_BTCOEX_CONFIG_EVENTID\n"); 3727 break; 3728 case WMI_REPORT_BTCOEX_STATS_EVENTID: 3729 ath6kl_dbg(ATH6KL_DBG_WMI, 3730 "WMI_REPORT_BTCOEX_STATS_EVENTID\n"); 3731 break; 3732 case WMI_TX_COMPLETE_EVENTID: 3733 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_COMPLETE_EVENTID\n"); 3734 ret = ath6kl_wmi_tx_complete_event_rx(datap, len); 3735 break; 3736 case WMI_P2P_CAPABILITIES_EVENTID: 3737 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_CAPABILITIES_EVENTID\n"); 3738 ret = ath6kl_wmi_p2p_capabilities_event_rx(datap, len); 3739 break; 3740 case WMI_P2P_INFO_EVENTID: 3741 ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_INFO_EVENTID\n"); 3742 ret = ath6kl_wmi_p2p_info_event_rx(datap, len); 3743 break; 3744 default: 3745 /* may be the event is interface specific */ 3746 ret = ath6kl_wmi_proc_events_vif(wmi, if_idx, id, datap, len); 3747 break; 3748 } 3749 3750 dev_kfree_skb(skb); 3751 return ret; 3752 } 3753 3754 /* Control Path */ 3755 int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb) 3756 { 3757 if (WARN_ON(skb == NULL)) 3758 return -EINVAL; 3759 3760 if (skb->len < sizeof(struct wmi_cmd_hdr)) { 3761 ath6kl_err("bad packet 1\n"); 3762 dev_kfree_skb(skb); 3763 return -EINVAL; 3764 } 3765 3766 return ath6kl_wmi_proc_events(wmi, skb); 3767 } 3768 3769 void ath6kl_wmi_reset(struct wmi *wmi) 3770 { 3771 spin_lock_bh(&wmi->lock); 3772 3773 wmi->fat_pipe_exist = 0; 3774 memset(wmi->stream_exist_for_ac, 0, sizeof(wmi->stream_exist_for_ac)); 3775 3776 spin_unlock_bh(&wmi->lock); 3777 } 3778 3779 void *ath6kl_wmi_init(struct ath6kl *dev) 3780 { 3781 struct wmi *wmi; 3782 3783 wmi = kzalloc(sizeof(struct wmi), GFP_KERNEL); 3784 if (!wmi) 3785 return NULL; 3786 3787 spin_lock_init(&wmi->lock); 3788 3789 wmi->parent_dev = dev; 3790 3791 wmi->pwr_mode = REC_POWER; 3792 3793 ath6kl_wmi_reset(wmi); 3794 3795 return wmi; 3796 } 3797 3798 void ath6kl_wmi_shutdown(struct wmi *wmi) 3799 { 3800 if (!wmi) 3801 return; 3802 3803 kfree(wmi->last_mgmt_tx_frame); 3804 kfree(wmi); 3805 } 3806