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