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