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