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