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