1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries. 4 * All rights reserved. 5 */ 6 7 #include "netdev.h" 8 9 #define WILC_HIF_SCAN_TIMEOUT_MS 5000 10 #define WILC_HIF_CONNECT_TIMEOUT_MS 9500 11 12 #define WILC_FALSE_FRMWR_CHANNEL 100 13 14 #define WILC_SCAN_WID_LIST_SIZE 6 15 16 struct wilc_rcvd_mac_info { 17 u8 status; 18 }; 19 20 struct wilc_set_multicast { 21 u32 enabled; 22 u32 cnt; 23 u8 *mc_list; 24 }; 25 26 struct host_if_wowlan_trigger { 27 u8 wowlan_trigger; 28 }; 29 30 struct wilc_del_all_sta { 31 u8 assoc_sta; 32 u8 mac[WILC_MAX_NUM_STA][ETH_ALEN]; 33 }; 34 35 union wilc_message_body { 36 struct wilc_rcvd_net_info net_info; 37 struct wilc_rcvd_mac_info mac_info; 38 struct wilc_set_multicast mc_info; 39 struct wilc_remain_ch remain_on_ch; 40 char *data; 41 struct host_if_wowlan_trigger wow_trigger; 42 }; 43 44 struct host_if_msg { 45 union wilc_message_body body; 46 struct wilc_vif *vif; 47 struct work_struct work; 48 void (*fn)(struct work_struct *ws); 49 struct completion work_comp; 50 bool is_sync; 51 }; 52 53 /* 'msg' should be free by the caller for syc */ 54 static struct host_if_msg* 55 wilc_alloc_work(struct wilc_vif *vif, void (*work_fun)(struct work_struct *), 56 bool is_sync) 57 { 58 struct host_if_msg *msg; 59 60 if (!work_fun) 61 return ERR_PTR(-EINVAL); 62 63 msg = kzalloc(sizeof(*msg), GFP_ATOMIC); 64 if (!msg) 65 return ERR_PTR(-ENOMEM); 66 msg->fn = work_fun; 67 msg->vif = vif; 68 msg->is_sync = is_sync; 69 if (is_sync) 70 init_completion(&msg->work_comp); 71 72 return msg; 73 } 74 75 static int wilc_enqueue_work(struct host_if_msg *msg) 76 { 77 INIT_WORK(&msg->work, msg->fn); 78 79 if (!msg->vif || !msg->vif->wilc || !msg->vif->wilc->hif_workqueue) 80 return -EINVAL; 81 82 if (!queue_work(msg->vif->wilc->hif_workqueue, &msg->work)) 83 return -EINVAL; 84 85 return 0; 86 } 87 88 /* The idx starts from 0 to (NUM_CONCURRENT_IFC - 1), but 0 index used as 89 * special purpose in wilc device, so we add 1 to the index to starts from 1. 90 * As a result, the returned index will be 1 to NUM_CONCURRENT_IFC. 91 */ 92 int wilc_get_vif_idx(struct wilc_vif *vif) 93 { 94 return vif->idx + 1; 95 } 96 97 /* We need to minus 1 from idx which is from wilc device to get real index 98 * of wilc->vif[], because we add 1 when pass to wilc device in the function 99 * wilc_get_vif_idx. 100 * As a result, the index should be between 0 and (NUM_CONCURRENT_IFC - 1). 101 */ 102 static struct wilc_vif *wilc_get_vif_from_idx(struct wilc *wilc, int idx) 103 { 104 int index = idx - 1; 105 struct wilc_vif *vif; 106 107 if (index < 0 || index >= WILC_NUM_CONCURRENT_IFC) 108 return NULL; 109 110 list_for_each_entry_rcu(vif, &wilc->vif_list, list) { 111 if (vif->idx == index) 112 return vif; 113 } 114 115 return NULL; 116 } 117 118 static int handle_scan_done(struct wilc_vif *vif, enum scan_event evt) 119 { 120 int result = 0; 121 u8 abort_running_scan; 122 struct wid wid; 123 struct host_if_drv *hif_drv = vif->hif_drv; 124 struct wilc_user_scan_req *scan_req; 125 126 if (evt == SCAN_EVENT_ABORTED) { 127 abort_running_scan = 1; 128 wid.id = WID_ABORT_RUNNING_SCAN; 129 wid.type = WID_CHAR; 130 wid.val = (s8 *)&abort_running_scan; 131 wid.size = sizeof(char); 132 133 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 134 if (result) { 135 netdev_err(vif->ndev, "Failed to set abort running\n"); 136 result = -EFAULT; 137 } 138 } 139 140 if (!hif_drv) { 141 netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__); 142 return result; 143 } 144 145 scan_req = &hif_drv->usr_scan_req; 146 if (scan_req->scan_result) { 147 scan_req->scan_result(evt, NULL, scan_req->arg); 148 scan_req->scan_result = NULL; 149 } 150 151 return result; 152 } 153 154 int wilc_scan(struct wilc_vif *vif, u8 scan_source, u8 scan_type, 155 u8 *ch_freq_list, u8 ch_list_len, 156 void (*scan_result_fn)(enum scan_event, 157 struct wilc_rcvd_net_info *, void *), 158 void *user_arg, struct cfg80211_scan_request *request) 159 { 160 int result = 0; 161 struct wid wid_list[WILC_SCAN_WID_LIST_SIZE]; 162 u32 index = 0; 163 u32 i, scan_timeout; 164 u8 *buffer; 165 u8 valuesize = 0; 166 u8 *search_ssid_vals = NULL; 167 struct host_if_drv *hif_drv = vif->hif_drv; 168 169 if (hif_drv->hif_state >= HOST_IF_SCANNING && 170 hif_drv->hif_state < HOST_IF_CONNECTED) { 171 netdev_err(vif->ndev, "Already scan\n"); 172 result = -EBUSY; 173 goto error; 174 } 175 176 if (vif->connecting) { 177 netdev_err(vif->ndev, "Don't do obss scan\n"); 178 result = -EBUSY; 179 goto error; 180 } 181 182 hif_drv->usr_scan_req.ch_cnt = 0; 183 184 if (request->n_ssids) { 185 for (i = 0; i < request->n_ssids; i++) 186 valuesize += ((request->ssids[i].ssid_len) + 1); 187 search_ssid_vals = kmalloc(valuesize + 1, GFP_KERNEL); 188 if (search_ssid_vals) { 189 wid_list[index].id = WID_SSID_PROBE_REQ; 190 wid_list[index].type = WID_STR; 191 wid_list[index].val = search_ssid_vals; 192 buffer = wid_list[index].val; 193 194 *buffer++ = request->n_ssids; 195 196 for (i = 0; i < request->n_ssids; i++) { 197 *buffer++ = request->ssids[i].ssid_len; 198 memcpy(buffer, request->ssids[i].ssid, 199 request->ssids[i].ssid_len); 200 buffer += request->ssids[i].ssid_len; 201 } 202 wid_list[index].size = (s32)(valuesize + 1); 203 index++; 204 } 205 } 206 207 wid_list[index].id = WID_INFO_ELEMENT_PROBE; 208 wid_list[index].type = WID_BIN_DATA; 209 wid_list[index].val = (s8 *)request->ie; 210 wid_list[index].size = request->ie_len; 211 index++; 212 213 wid_list[index].id = WID_SCAN_TYPE; 214 wid_list[index].type = WID_CHAR; 215 wid_list[index].size = sizeof(char); 216 wid_list[index].val = (s8 *)&scan_type; 217 index++; 218 219 if (scan_type == WILC_FW_PASSIVE_SCAN && request->duration) { 220 wid_list[index].id = WID_PASSIVE_SCAN_TIME; 221 wid_list[index].type = WID_SHORT; 222 wid_list[index].size = sizeof(u16); 223 wid_list[index].val = (s8 *)&request->duration; 224 index++; 225 226 scan_timeout = (request->duration * ch_list_len) + 500; 227 } else { 228 scan_timeout = WILC_HIF_SCAN_TIMEOUT_MS; 229 } 230 231 wid_list[index].id = WID_SCAN_CHANNEL_LIST; 232 wid_list[index].type = WID_BIN_DATA; 233 234 if (ch_freq_list && ch_list_len > 0) { 235 for (i = 0; i < ch_list_len; i++) { 236 if (ch_freq_list[i] > 0) 237 ch_freq_list[i] -= 1; 238 } 239 } 240 241 wid_list[index].val = ch_freq_list; 242 wid_list[index].size = ch_list_len; 243 index++; 244 245 wid_list[index].id = WID_START_SCAN_REQ; 246 wid_list[index].type = WID_CHAR; 247 wid_list[index].size = sizeof(char); 248 wid_list[index].val = (s8 *)&scan_source; 249 index++; 250 251 hif_drv->usr_scan_req.scan_result = scan_result_fn; 252 hif_drv->usr_scan_req.arg = user_arg; 253 254 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, index); 255 if (result) { 256 netdev_err(vif->ndev, "Failed to send scan parameters\n"); 257 goto error; 258 } 259 260 hif_drv->scan_timer_vif = vif; 261 mod_timer(&hif_drv->scan_timer, 262 jiffies + msecs_to_jiffies(scan_timeout)); 263 264 error: 265 266 kfree(search_ssid_vals); 267 268 return result; 269 } 270 271 static int wilc_send_connect_wid(struct wilc_vif *vif) 272 { 273 int result = 0; 274 struct wid wid_list[5]; 275 u32 wid_cnt = 0; 276 struct host_if_drv *hif_drv = vif->hif_drv; 277 struct wilc_conn_info *conn_attr = &hif_drv->conn_info; 278 struct wilc_join_bss_param *bss_param = conn_attr->param; 279 280 281 wid_list[wid_cnt].id = WID_SET_MFP; 282 wid_list[wid_cnt].type = WID_CHAR; 283 wid_list[wid_cnt].size = sizeof(char); 284 wid_list[wid_cnt].val = (s8 *)&conn_attr->mfp_type; 285 wid_cnt++; 286 287 wid_list[wid_cnt].id = WID_INFO_ELEMENT_ASSOCIATE; 288 wid_list[wid_cnt].type = WID_BIN_DATA; 289 wid_list[wid_cnt].val = conn_attr->req_ies; 290 wid_list[wid_cnt].size = conn_attr->req_ies_len; 291 wid_cnt++; 292 293 wid_list[wid_cnt].id = WID_11I_MODE; 294 wid_list[wid_cnt].type = WID_CHAR; 295 wid_list[wid_cnt].size = sizeof(char); 296 wid_list[wid_cnt].val = (s8 *)&conn_attr->security; 297 wid_cnt++; 298 299 wid_list[wid_cnt].id = WID_AUTH_TYPE; 300 wid_list[wid_cnt].type = WID_CHAR; 301 wid_list[wid_cnt].size = sizeof(char); 302 wid_list[wid_cnt].val = (s8 *)&conn_attr->auth_type; 303 wid_cnt++; 304 305 wid_list[wid_cnt].id = WID_JOIN_REQ_EXTENDED; 306 wid_list[wid_cnt].type = WID_STR; 307 wid_list[wid_cnt].size = sizeof(*bss_param); 308 wid_list[wid_cnt].val = (u8 *)bss_param; 309 wid_cnt++; 310 311 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, wid_cnt); 312 if (result) { 313 netdev_err(vif->ndev, "failed to send config packet\n"); 314 goto error; 315 } else { 316 if (conn_attr->auth_type == WILC_FW_AUTH_SAE) 317 hif_drv->hif_state = HOST_IF_EXTERNAL_AUTH; 318 else 319 hif_drv->hif_state = HOST_IF_WAITING_CONN_RESP; 320 } 321 322 return 0; 323 324 error: 325 326 kfree(conn_attr->req_ies); 327 conn_attr->req_ies = NULL; 328 329 return result; 330 } 331 332 static void handle_connect_timeout(struct work_struct *work) 333 { 334 struct host_if_msg *msg = container_of(work, struct host_if_msg, work); 335 struct wilc_vif *vif = msg->vif; 336 int result; 337 struct wid wid; 338 u16 dummy_reason_code = 0; 339 struct host_if_drv *hif_drv = vif->hif_drv; 340 341 if (!hif_drv) { 342 netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__); 343 goto out; 344 } 345 346 hif_drv->hif_state = HOST_IF_IDLE; 347 348 if (hif_drv->conn_info.conn_result) { 349 hif_drv->conn_info.conn_result(CONN_DISCONN_EVENT_CONN_RESP, 350 WILC_MAC_STATUS_DISCONNECTED, 351 hif_drv->conn_info.arg); 352 353 } else { 354 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__); 355 } 356 357 wid.id = WID_DISCONNECT; 358 wid.type = WID_CHAR; 359 wid.val = (s8 *)&dummy_reason_code; 360 wid.size = sizeof(char); 361 362 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 363 if (result) 364 netdev_err(vif->ndev, "Failed to send disconnect\n"); 365 366 hif_drv->conn_info.req_ies_len = 0; 367 kfree(hif_drv->conn_info.req_ies); 368 hif_drv->conn_info.req_ies = NULL; 369 370 out: 371 kfree(msg); 372 } 373 374 void *wilc_parse_join_bss_param(struct cfg80211_bss *bss, 375 struct cfg80211_crypto_settings *crypto) 376 { 377 const u8 *ies_data, *tim_elm, *ssid_elm, *rates_ie, *supp_rates_ie; 378 const u8 *ht_ie, *wpa_ie, *wmm_ie, *rsn_ie; 379 struct ieee80211_p2p_noa_attr noa_attr; 380 const struct cfg80211_bss_ies *ies; 381 struct wilc_join_bss_param *param; 382 u8 rates_len = 0; 383 int ies_len; 384 u64 ies_tsf; 385 int ret; 386 387 param = kzalloc(sizeof(*param), GFP_KERNEL); 388 if (!param) 389 return NULL; 390 391 rcu_read_lock(); 392 ies = rcu_dereference(bss->ies); 393 ies_data = kmemdup(ies->data, ies->len, GFP_ATOMIC); 394 if (!ies_data) { 395 rcu_read_unlock(); 396 kfree(param); 397 return NULL; 398 } 399 ies_len = ies->len; 400 ies_tsf = ies->tsf; 401 rcu_read_unlock(); 402 403 param->beacon_period = cpu_to_le16(bss->beacon_interval); 404 param->cap_info = cpu_to_le16(bss->capability); 405 param->bss_type = WILC_FW_BSS_TYPE_INFRA; 406 param->ch = ieee80211_frequency_to_channel(bss->channel->center_freq); 407 ether_addr_copy(param->bssid, bss->bssid); 408 409 ssid_elm = cfg80211_find_ie(WLAN_EID_SSID, ies_data, ies_len); 410 if (ssid_elm) { 411 if (ssid_elm[1] <= IEEE80211_MAX_SSID_LEN) 412 memcpy(param->ssid, ssid_elm + 2, ssid_elm[1]); 413 } 414 415 tim_elm = cfg80211_find_ie(WLAN_EID_TIM, ies_data, ies_len); 416 if (tim_elm && tim_elm[1] >= 2) 417 param->dtim_period = tim_elm[3]; 418 419 memset(param->p_suites, 0xFF, 3); 420 memset(param->akm_suites, 0xFF, 3); 421 422 rates_ie = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies_data, ies_len); 423 if (rates_ie) { 424 rates_len = rates_ie[1]; 425 if (rates_len > WILC_MAX_RATES_SUPPORTED) 426 rates_len = WILC_MAX_RATES_SUPPORTED; 427 param->supp_rates[0] = rates_len; 428 memcpy(¶m->supp_rates[1], rates_ie + 2, rates_len); 429 } 430 431 if (rates_len < WILC_MAX_RATES_SUPPORTED) { 432 supp_rates_ie = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, 433 ies_data, ies_len); 434 if (supp_rates_ie) { 435 u8 ext_rates = supp_rates_ie[1]; 436 437 if (ext_rates > (WILC_MAX_RATES_SUPPORTED - rates_len)) 438 param->supp_rates[0] = WILC_MAX_RATES_SUPPORTED; 439 else 440 param->supp_rates[0] += ext_rates; 441 442 memcpy(¶m->supp_rates[rates_len + 1], 443 supp_rates_ie + 2, 444 (param->supp_rates[0] - rates_len)); 445 } 446 } 447 448 ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies_data, ies_len); 449 if (ht_ie) 450 param->ht_capable = true; 451 452 ret = cfg80211_get_p2p_attr(ies_data, ies_len, 453 IEEE80211_P2P_ATTR_ABSENCE_NOTICE, 454 (u8 *)&noa_attr, sizeof(noa_attr)); 455 if (ret > 0) { 456 param->tsf_lo = cpu_to_le32(ies_tsf); 457 param->noa_enabled = 1; 458 param->idx = noa_attr.index; 459 if (noa_attr.oppps_ctwindow & IEEE80211_P2P_OPPPS_ENABLE_BIT) { 460 param->opp_enabled = 1; 461 param->opp_en.ct_window = noa_attr.oppps_ctwindow; 462 param->opp_en.cnt = noa_attr.desc[0].count; 463 param->opp_en.duration = noa_attr.desc[0].duration; 464 param->opp_en.interval = noa_attr.desc[0].interval; 465 param->opp_en.start_time = noa_attr.desc[0].start_time; 466 } else { 467 param->opp_enabled = 0; 468 param->opp_dis.cnt = noa_attr.desc[0].count; 469 param->opp_dis.duration = noa_attr.desc[0].duration; 470 param->opp_dis.interval = noa_attr.desc[0].interval; 471 param->opp_dis.start_time = noa_attr.desc[0].start_time; 472 } 473 } 474 wmm_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT, 475 WLAN_OUI_TYPE_MICROSOFT_WMM, 476 ies_data, ies_len); 477 if (wmm_ie) { 478 struct ieee80211_wmm_param_ie *ie; 479 480 ie = (struct ieee80211_wmm_param_ie *)wmm_ie; 481 if ((ie->oui_subtype == 0 || ie->oui_subtype == 1) && 482 ie->version == 1) { 483 param->wmm_cap = true; 484 if (ie->qos_info & BIT(7)) 485 param->uapsd_cap = true; 486 } 487 } 488 489 wpa_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT, 490 WLAN_OUI_TYPE_MICROSOFT_WPA, 491 ies_data, ies_len); 492 if (wpa_ie) { 493 param->mode_802_11i = 1; 494 param->rsn_found = true; 495 } 496 497 rsn_ie = cfg80211_find_ie(WLAN_EID_RSN, ies_data, ies_len); 498 if (rsn_ie) { 499 int rsn_ie_len = sizeof(struct element) + rsn_ie[1]; 500 int offset = 8; 501 502 param->mode_802_11i = 2; 503 param->rsn_found = true; 504 505 /* extract RSN capabilities */ 506 if (offset < rsn_ie_len) { 507 /* skip over pairwise suites */ 508 offset += (rsn_ie[offset] * 4) + 2; 509 510 if (offset < rsn_ie_len) { 511 /* skip over authentication suites */ 512 offset += (rsn_ie[offset] * 4) + 2; 513 514 if (offset + 1 < rsn_ie_len) 515 memcpy(param->rsn_cap, &rsn_ie[offset], 2); 516 } 517 } 518 } 519 520 if (param->rsn_found) { 521 int i; 522 523 param->rsn_grp_policy = crypto->cipher_group & 0xFF; 524 for (i = 0; i < crypto->n_ciphers_pairwise && i < 3; i++) 525 param->p_suites[i] = crypto->ciphers_pairwise[i] & 0xFF; 526 527 for (i = 0; i < crypto->n_akm_suites && i < 3; i++) 528 param->akm_suites[i] = crypto->akm_suites[i] & 0xFF; 529 } 530 531 kfree(ies_data); 532 return (void *)param; 533 } 534 535 static void handle_rcvd_ntwrk_info(struct work_struct *work) 536 { 537 struct host_if_msg *msg = container_of(work, struct host_if_msg, work); 538 struct wilc_rcvd_net_info *rcvd_info = &msg->body.net_info; 539 struct wilc_user_scan_req *scan_req = &msg->vif->hif_drv->usr_scan_req; 540 const u8 *ch_elm; 541 u8 *ies; 542 int ies_len; 543 size_t offset; 544 545 if (ieee80211_is_probe_resp(rcvd_info->mgmt->frame_control)) 546 offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable); 547 else if (ieee80211_is_beacon(rcvd_info->mgmt->frame_control)) 548 offset = offsetof(struct ieee80211_mgmt, u.beacon.variable); 549 else 550 goto done; 551 552 ies = rcvd_info->mgmt->u.beacon.variable; 553 ies_len = rcvd_info->frame_len - offset; 554 if (ies_len <= 0) 555 goto done; 556 557 ch_elm = cfg80211_find_ie(WLAN_EID_DS_PARAMS, ies, ies_len); 558 if (ch_elm && ch_elm[1] > 0) 559 rcvd_info->ch = ch_elm[2]; 560 561 if (scan_req->scan_result) 562 scan_req->scan_result(SCAN_EVENT_NETWORK_FOUND, rcvd_info, 563 scan_req->arg); 564 565 done: 566 kfree(rcvd_info->mgmt); 567 kfree(msg); 568 } 569 570 static void host_int_get_assoc_res_info(struct wilc_vif *vif, 571 u8 *assoc_resp_info, 572 u32 max_assoc_resp_info_len, 573 u32 *rcvd_assoc_resp_info_len) 574 { 575 int result; 576 struct wid wid; 577 578 wid.id = WID_ASSOC_RES_INFO; 579 wid.type = WID_STR; 580 wid.val = assoc_resp_info; 581 wid.size = max_assoc_resp_info_len; 582 583 result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1); 584 if (result) { 585 *rcvd_assoc_resp_info_len = 0; 586 netdev_err(vif->ndev, "Failed to send association response\n"); 587 return; 588 } 589 590 *rcvd_assoc_resp_info_len = wid.size; 591 } 592 593 static s32 wilc_parse_assoc_resp_info(u8 *buffer, u32 buffer_len, 594 struct wilc_conn_info *ret_conn_info) 595 { 596 u8 *ies; 597 u16 ies_len; 598 struct wilc_assoc_resp *res = (struct wilc_assoc_resp *)buffer; 599 600 ret_conn_info->status = le16_to_cpu(res->status_code); 601 if (ret_conn_info->status == WLAN_STATUS_SUCCESS) { 602 ies = &buffer[sizeof(*res)]; 603 ies_len = buffer_len - sizeof(*res); 604 605 ret_conn_info->resp_ies = kmemdup(ies, ies_len, GFP_KERNEL); 606 if (!ret_conn_info->resp_ies) 607 return -ENOMEM; 608 609 ret_conn_info->resp_ies_len = ies_len; 610 } 611 612 return 0; 613 } 614 615 static inline void host_int_parse_assoc_resp_info(struct wilc_vif *vif, 616 u8 mac_status) 617 { 618 struct host_if_drv *hif_drv = vif->hif_drv; 619 struct wilc_conn_info *conn_info = &hif_drv->conn_info; 620 621 if (mac_status == WILC_MAC_STATUS_CONNECTED) { 622 u32 assoc_resp_info_len; 623 624 memset(hif_drv->assoc_resp, 0, WILC_MAX_ASSOC_RESP_FRAME_SIZE); 625 626 host_int_get_assoc_res_info(vif, hif_drv->assoc_resp, 627 WILC_MAX_ASSOC_RESP_FRAME_SIZE, 628 &assoc_resp_info_len); 629 630 if (assoc_resp_info_len != 0) { 631 s32 err = 0; 632 633 err = wilc_parse_assoc_resp_info(hif_drv->assoc_resp, 634 assoc_resp_info_len, 635 conn_info); 636 if (err) 637 netdev_err(vif->ndev, 638 "wilc_parse_assoc_resp_info() returned error %d\n", 639 err); 640 } 641 } 642 643 del_timer(&hif_drv->connect_timer); 644 conn_info->conn_result(CONN_DISCONN_EVENT_CONN_RESP, mac_status, 645 hif_drv->conn_info.arg); 646 647 if (mac_status == WILC_MAC_STATUS_CONNECTED && 648 conn_info->status == WLAN_STATUS_SUCCESS) { 649 ether_addr_copy(hif_drv->assoc_bssid, conn_info->bssid); 650 hif_drv->hif_state = HOST_IF_CONNECTED; 651 } else { 652 hif_drv->hif_state = HOST_IF_IDLE; 653 } 654 655 kfree(conn_info->resp_ies); 656 conn_info->resp_ies = NULL; 657 conn_info->resp_ies_len = 0; 658 659 kfree(conn_info->req_ies); 660 conn_info->req_ies = NULL; 661 conn_info->req_ies_len = 0; 662 } 663 664 void wilc_handle_disconnect(struct wilc_vif *vif) 665 { 666 struct host_if_drv *hif_drv = vif->hif_drv; 667 668 if (hif_drv->usr_scan_req.scan_result) { 669 del_timer(&hif_drv->scan_timer); 670 handle_scan_done(vif, SCAN_EVENT_ABORTED); 671 } 672 673 if (hif_drv->conn_info.conn_result) 674 hif_drv->conn_info.conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF, 675 0, hif_drv->conn_info.arg); 676 677 eth_zero_addr(hif_drv->assoc_bssid); 678 679 hif_drv->conn_info.req_ies_len = 0; 680 kfree(hif_drv->conn_info.req_ies); 681 hif_drv->conn_info.req_ies = NULL; 682 hif_drv->hif_state = HOST_IF_IDLE; 683 } 684 685 static void handle_rcvd_gnrl_async_info(struct work_struct *work) 686 { 687 struct host_if_msg *msg = container_of(work, struct host_if_msg, work); 688 struct wilc_vif *vif = msg->vif; 689 struct wilc_rcvd_mac_info *mac_info = &msg->body.mac_info; 690 struct host_if_drv *hif_drv = vif->hif_drv; 691 692 if (!hif_drv) { 693 netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__); 694 goto free_msg; 695 } 696 697 if (!hif_drv->conn_info.conn_result) { 698 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__); 699 goto free_msg; 700 } 701 702 703 if (hif_drv->hif_state == HOST_IF_EXTERNAL_AUTH) { 704 cfg80211_external_auth_request(vif->ndev, &vif->auth, 705 GFP_KERNEL); 706 hif_drv->hif_state = HOST_IF_WAITING_CONN_RESP; 707 } else if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) { 708 host_int_parse_assoc_resp_info(vif, mac_info->status); 709 } else if (mac_info->status == WILC_MAC_STATUS_DISCONNECTED) { 710 if (hif_drv->hif_state == HOST_IF_CONNECTED) { 711 wilc_handle_disconnect(vif); 712 } else if (hif_drv->usr_scan_req.scan_result) { 713 del_timer(&hif_drv->scan_timer); 714 handle_scan_done(vif, SCAN_EVENT_ABORTED); 715 } 716 } 717 718 free_msg: 719 kfree(msg); 720 } 721 722 int wilc_disconnect(struct wilc_vif *vif) 723 { 724 struct wid wid; 725 struct host_if_drv *hif_drv = vif->hif_drv; 726 struct wilc_user_scan_req *scan_req; 727 struct wilc_conn_info *conn_info; 728 int result; 729 u16 dummy_reason_code = 0; 730 731 wid.id = WID_DISCONNECT; 732 wid.type = WID_CHAR; 733 wid.val = (s8 *)&dummy_reason_code; 734 wid.size = sizeof(char); 735 736 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 737 if (result) { 738 netdev_err(vif->ndev, "Failed to send disconnect\n"); 739 return result; 740 } 741 742 scan_req = &hif_drv->usr_scan_req; 743 conn_info = &hif_drv->conn_info; 744 745 if (scan_req->scan_result) { 746 del_timer(&hif_drv->scan_timer); 747 scan_req->scan_result(SCAN_EVENT_ABORTED, NULL, scan_req->arg); 748 scan_req->scan_result = NULL; 749 } 750 751 if (conn_info->conn_result) { 752 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP || 753 hif_drv->hif_state == HOST_IF_EXTERNAL_AUTH) 754 del_timer(&hif_drv->connect_timer); 755 756 conn_info->conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF, 0, 757 conn_info->arg); 758 } else { 759 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__); 760 } 761 762 hif_drv->hif_state = HOST_IF_IDLE; 763 764 eth_zero_addr(hif_drv->assoc_bssid); 765 766 conn_info->req_ies_len = 0; 767 kfree(conn_info->req_ies); 768 conn_info->req_ies = NULL; 769 770 return 0; 771 } 772 773 int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats) 774 { 775 struct wid wid_list[5]; 776 u32 wid_cnt = 0, result; 777 778 wid_list[wid_cnt].id = WID_LINKSPEED; 779 wid_list[wid_cnt].type = WID_CHAR; 780 wid_list[wid_cnt].size = sizeof(char); 781 wid_list[wid_cnt].val = (s8 *)&stats->link_speed; 782 wid_cnt++; 783 784 wid_list[wid_cnt].id = WID_RSSI; 785 wid_list[wid_cnt].type = WID_CHAR; 786 wid_list[wid_cnt].size = sizeof(char); 787 wid_list[wid_cnt].val = (s8 *)&stats->rssi; 788 wid_cnt++; 789 790 wid_list[wid_cnt].id = WID_SUCCESS_FRAME_COUNT; 791 wid_list[wid_cnt].type = WID_INT; 792 wid_list[wid_cnt].size = sizeof(u32); 793 wid_list[wid_cnt].val = (s8 *)&stats->tx_cnt; 794 wid_cnt++; 795 796 wid_list[wid_cnt].id = WID_RECEIVED_FRAGMENT_COUNT; 797 wid_list[wid_cnt].type = WID_INT; 798 wid_list[wid_cnt].size = sizeof(u32); 799 wid_list[wid_cnt].val = (s8 *)&stats->rx_cnt; 800 wid_cnt++; 801 802 wid_list[wid_cnt].id = WID_FAILED_COUNT; 803 wid_list[wid_cnt].type = WID_INT; 804 wid_list[wid_cnt].size = sizeof(u32); 805 wid_list[wid_cnt].val = (s8 *)&stats->tx_fail_cnt; 806 wid_cnt++; 807 808 result = wilc_send_config_pkt(vif, WILC_GET_CFG, wid_list, wid_cnt); 809 if (result) { 810 netdev_err(vif->ndev, "Failed to send scan parameters\n"); 811 return result; 812 } 813 814 if (stats->link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH && 815 stats->link_speed != DEFAULT_LINK_SPEED) 816 wilc_enable_tcp_ack_filter(vif, true); 817 else if (stats->link_speed != DEFAULT_LINK_SPEED) 818 wilc_enable_tcp_ack_filter(vif, false); 819 820 return result; 821 } 822 823 static void handle_get_statistics(struct work_struct *work) 824 { 825 struct host_if_msg *msg = container_of(work, struct host_if_msg, work); 826 struct wilc_vif *vif = msg->vif; 827 struct rf_info *stats = (struct rf_info *)msg->body.data; 828 829 wilc_get_statistics(vif, stats); 830 831 kfree(msg); 832 } 833 834 static void wilc_hif_pack_sta_param(u8 *cur_byte, const u8 *mac, 835 struct station_parameters *params) 836 { 837 ether_addr_copy(cur_byte, mac); 838 cur_byte += ETH_ALEN; 839 840 put_unaligned_le16(params->aid, cur_byte); 841 cur_byte += 2; 842 843 *cur_byte++ = params->link_sta_params.supported_rates_len; 844 if (params->link_sta_params.supported_rates_len > 0) 845 memcpy(cur_byte, params->link_sta_params.supported_rates, 846 params->link_sta_params.supported_rates_len); 847 cur_byte += params->link_sta_params.supported_rates_len; 848 849 if (params->link_sta_params.ht_capa) { 850 *cur_byte++ = true; 851 memcpy(cur_byte, params->link_sta_params.ht_capa, 852 sizeof(struct ieee80211_ht_cap)); 853 } else { 854 *cur_byte++ = false; 855 } 856 cur_byte += sizeof(struct ieee80211_ht_cap); 857 858 put_unaligned_le16(params->sta_flags_mask, cur_byte); 859 cur_byte += 2; 860 put_unaligned_le16(params->sta_flags_set, cur_byte); 861 } 862 863 static int handle_remain_on_chan(struct wilc_vif *vif, 864 struct wilc_remain_ch *hif_remain_ch) 865 { 866 int result; 867 u8 remain_on_chan_flag; 868 struct wid wid; 869 struct host_if_drv *hif_drv = vif->hif_drv; 870 871 if (hif_drv->usr_scan_req.scan_result) 872 return -EBUSY; 873 874 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) 875 return -EBUSY; 876 877 if (vif->connecting) 878 return -EBUSY; 879 880 remain_on_chan_flag = true; 881 wid.id = WID_REMAIN_ON_CHAN; 882 wid.type = WID_STR; 883 wid.size = 2; 884 wid.val = kmalloc(wid.size, GFP_KERNEL); 885 if (!wid.val) 886 return -ENOMEM; 887 888 wid.val[0] = remain_on_chan_flag; 889 wid.val[1] = (s8)hif_remain_ch->ch; 890 891 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 892 kfree(wid.val); 893 if (result) 894 return -EBUSY; 895 896 hif_drv->remain_on_ch.arg = hif_remain_ch->arg; 897 hif_drv->remain_on_ch.expired = hif_remain_ch->expired; 898 hif_drv->remain_on_ch.ch = hif_remain_ch->ch; 899 hif_drv->remain_on_ch.cookie = hif_remain_ch->cookie; 900 hif_drv->remain_on_ch_timer_vif = vif; 901 902 return 0; 903 } 904 905 static int wilc_handle_roc_expired(struct wilc_vif *vif, u64 cookie) 906 { 907 u8 remain_on_chan_flag; 908 struct wid wid; 909 int result; 910 struct host_if_drv *hif_drv = vif->hif_drv; 911 912 if (vif->priv.p2p_listen_state) { 913 remain_on_chan_flag = false; 914 wid.id = WID_REMAIN_ON_CHAN; 915 wid.type = WID_STR; 916 wid.size = 2; 917 918 wid.val = kmalloc(wid.size, GFP_KERNEL); 919 if (!wid.val) 920 return -ENOMEM; 921 922 wid.val[0] = remain_on_chan_flag; 923 wid.val[1] = WILC_FALSE_FRMWR_CHANNEL; 924 925 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 926 kfree(wid.val); 927 if (result != 0) { 928 netdev_err(vif->ndev, "Failed to set remain channel\n"); 929 return -EINVAL; 930 } 931 932 if (hif_drv->remain_on_ch.expired) { 933 hif_drv->remain_on_ch.expired(hif_drv->remain_on_ch.arg, 934 cookie); 935 } 936 } else { 937 netdev_dbg(vif->ndev, "Not in listen state\n"); 938 } 939 940 return 0; 941 } 942 943 static void wilc_handle_listen_state_expired(struct work_struct *work) 944 { 945 struct host_if_msg *msg = container_of(work, struct host_if_msg, work); 946 947 wilc_handle_roc_expired(msg->vif, msg->body.remain_on_ch.cookie); 948 kfree(msg); 949 } 950 951 static void listen_timer_cb(struct timer_list *t) 952 { 953 struct host_if_drv *hif_drv = from_timer(hif_drv, t, 954 remain_on_ch_timer); 955 struct wilc_vif *vif = hif_drv->remain_on_ch_timer_vif; 956 int result; 957 struct host_if_msg *msg; 958 959 del_timer(&vif->hif_drv->remain_on_ch_timer); 960 961 msg = wilc_alloc_work(vif, wilc_handle_listen_state_expired, false); 962 if (IS_ERR(msg)) 963 return; 964 965 msg->body.remain_on_ch.cookie = vif->hif_drv->remain_on_ch.cookie; 966 967 result = wilc_enqueue_work(msg); 968 if (result) { 969 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__); 970 kfree(msg); 971 } 972 } 973 974 static void handle_set_mcast_filter(struct work_struct *work) 975 { 976 struct host_if_msg *msg = container_of(work, struct host_if_msg, work); 977 struct wilc_vif *vif = msg->vif; 978 struct wilc_set_multicast *set_mc = &msg->body.mc_info; 979 int result; 980 struct wid wid; 981 u8 *cur_byte; 982 983 wid.id = WID_SETUP_MULTICAST_FILTER; 984 wid.type = WID_BIN; 985 wid.size = sizeof(struct wilc_set_multicast) + (set_mc->cnt * ETH_ALEN); 986 wid.val = kmalloc(wid.size, GFP_KERNEL); 987 if (!wid.val) 988 goto error; 989 990 cur_byte = wid.val; 991 put_unaligned_le32(set_mc->enabled, cur_byte); 992 cur_byte += 4; 993 994 put_unaligned_le32(set_mc->cnt, cur_byte); 995 cur_byte += 4; 996 997 if (set_mc->cnt > 0 && set_mc->mc_list) 998 memcpy(cur_byte, set_mc->mc_list, set_mc->cnt * ETH_ALEN); 999 1000 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 1001 if (result) 1002 netdev_err(vif->ndev, "Failed to send setup multicast\n"); 1003 1004 error: 1005 kfree(set_mc->mc_list); 1006 kfree(wid.val); 1007 kfree(msg); 1008 } 1009 1010 void wilc_set_wowlan_trigger(struct wilc_vif *vif, bool enabled) 1011 { 1012 int ret; 1013 struct wid wid; 1014 u8 wowlan_trigger = 0; 1015 1016 if (enabled) 1017 wowlan_trigger = 1; 1018 1019 wid.id = WID_WOWLAN_TRIGGER; 1020 wid.type = WID_CHAR; 1021 wid.val = &wowlan_trigger; 1022 wid.size = sizeof(char); 1023 1024 ret = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 1025 if (ret) 1026 pr_err("Failed to send wowlan trigger config packet\n"); 1027 } 1028 1029 int wilc_set_external_auth_param(struct wilc_vif *vif, 1030 struct cfg80211_external_auth_params *auth) 1031 { 1032 int ret; 1033 struct wid wid; 1034 struct wilc_external_auth_param *param; 1035 1036 wid.id = WID_EXTERNAL_AUTH_PARAM; 1037 wid.type = WID_BIN_DATA; 1038 wid.size = sizeof(*param); 1039 param = kzalloc(sizeof(*param), GFP_KERNEL); 1040 if (!param) 1041 return -EINVAL; 1042 1043 wid.val = (u8 *)param; 1044 param->action = auth->action; 1045 ether_addr_copy(param->bssid, auth->bssid); 1046 memcpy(param->ssid, auth->ssid.ssid, auth->ssid.ssid_len); 1047 param->ssid_len = auth->ssid.ssid_len; 1048 ret = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 1049 1050 kfree(param); 1051 return ret; 1052 } 1053 1054 static void handle_scan_timer(struct work_struct *work) 1055 { 1056 struct host_if_msg *msg = container_of(work, struct host_if_msg, work); 1057 1058 handle_scan_done(msg->vif, SCAN_EVENT_ABORTED); 1059 kfree(msg); 1060 } 1061 1062 static void handle_scan_complete(struct work_struct *work) 1063 { 1064 struct host_if_msg *msg = container_of(work, struct host_if_msg, work); 1065 1066 del_timer(&msg->vif->hif_drv->scan_timer); 1067 1068 handle_scan_done(msg->vif, SCAN_EVENT_DONE); 1069 1070 kfree(msg); 1071 } 1072 1073 static void timer_scan_cb(struct timer_list *t) 1074 { 1075 struct host_if_drv *hif_drv = from_timer(hif_drv, t, scan_timer); 1076 struct wilc_vif *vif = hif_drv->scan_timer_vif; 1077 struct host_if_msg *msg; 1078 int result; 1079 1080 msg = wilc_alloc_work(vif, handle_scan_timer, false); 1081 if (IS_ERR(msg)) 1082 return; 1083 1084 result = wilc_enqueue_work(msg); 1085 if (result) 1086 kfree(msg); 1087 } 1088 1089 static void timer_connect_cb(struct timer_list *t) 1090 { 1091 struct host_if_drv *hif_drv = from_timer(hif_drv, t, 1092 connect_timer); 1093 struct wilc_vif *vif = hif_drv->connect_timer_vif; 1094 struct host_if_msg *msg; 1095 int result; 1096 1097 msg = wilc_alloc_work(vif, handle_connect_timeout, false); 1098 if (IS_ERR(msg)) 1099 return; 1100 1101 result = wilc_enqueue_work(msg); 1102 if (result) 1103 kfree(msg); 1104 } 1105 1106 int wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len, 1107 const u8 *mac_addr, const u8 *rx_mic, const u8 *tx_mic, 1108 u8 mode, u8 cipher_mode, u8 index) 1109 { 1110 int result = 0; 1111 u8 t_key_len = ptk_key_len + WILC_RX_MIC_KEY_LEN + WILC_TX_MIC_KEY_LEN; 1112 1113 if (mode == WILC_AP_MODE) { 1114 struct wid wid_list[2]; 1115 struct wilc_ap_wpa_ptk *key_buf; 1116 1117 wid_list[0].id = WID_11I_MODE; 1118 wid_list[0].type = WID_CHAR; 1119 wid_list[0].size = sizeof(char); 1120 wid_list[0].val = (s8 *)&cipher_mode; 1121 1122 key_buf = kzalloc(sizeof(*key_buf) + t_key_len, GFP_KERNEL); 1123 if (!key_buf) 1124 return -ENOMEM; 1125 1126 ether_addr_copy(key_buf->mac_addr, mac_addr); 1127 key_buf->index = index; 1128 key_buf->key_len = t_key_len; 1129 memcpy(&key_buf->key[0], ptk, ptk_key_len); 1130 1131 if (rx_mic) 1132 memcpy(&key_buf->key[ptk_key_len], rx_mic, 1133 WILC_RX_MIC_KEY_LEN); 1134 1135 if (tx_mic) 1136 memcpy(&key_buf->key[ptk_key_len + WILC_RX_MIC_KEY_LEN], 1137 tx_mic, WILC_TX_MIC_KEY_LEN); 1138 1139 wid_list[1].id = WID_ADD_PTK; 1140 wid_list[1].type = WID_STR; 1141 wid_list[1].size = sizeof(*key_buf) + t_key_len; 1142 wid_list[1].val = (u8 *)key_buf; 1143 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, 1144 ARRAY_SIZE(wid_list)); 1145 kfree(key_buf); 1146 } else if (mode == WILC_STATION_MODE) { 1147 struct wid wid; 1148 struct wilc_sta_wpa_ptk *key_buf; 1149 1150 key_buf = kzalloc(sizeof(*key_buf) + t_key_len, GFP_KERNEL); 1151 if (!key_buf) 1152 return -ENOMEM; 1153 1154 ether_addr_copy(key_buf->mac_addr, mac_addr); 1155 key_buf->key_len = t_key_len; 1156 memcpy(&key_buf->key[0], ptk, ptk_key_len); 1157 1158 if (rx_mic) 1159 memcpy(&key_buf->key[ptk_key_len], rx_mic, 1160 WILC_RX_MIC_KEY_LEN); 1161 1162 if (tx_mic) 1163 memcpy(&key_buf->key[ptk_key_len + WILC_RX_MIC_KEY_LEN], 1164 tx_mic, WILC_TX_MIC_KEY_LEN); 1165 1166 wid.id = WID_ADD_PTK; 1167 wid.type = WID_STR; 1168 wid.size = sizeof(*key_buf) + t_key_len; 1169 wid.val = (s8 *)key_buf; 1170 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 1171 kfree(key_buf); 1172 } 1173 1174 return result; 1175 } 1176 1177 int wilc_add_igtk(struct wilc_vif *vif, const u8 *igtk, u8 igtk_key_len, 1178 const u8 *pn, u8 pn_len, const u8 *mac_addr, u8 mode, u8 index) 1179 { 1180 int result = 0; 1181 u8 t_key_len = igtk_key_len; 1182 struct wid wid; 1183 struct wilc_wpa_igtk *key_buf; 1184 1185 key_buf = kzalloc(sizeof(*key_buf) + t_key_len, GFP_KERNEL); 1186 if (!key_buf) 1187 return -ENOMEM; 1188 1189 key_buf->index = index; 1190 1191 memcpy(&key_buf->pn[0], pn, pn_len); 1192 key_buf->pn_len = pn_len; 1193 1194 memcpy(&key_buf->key[0], igtk, igtk_key_len); 1195 key_buf->key_len = t_key_len; 1196 1197 wid.id = WID_ADD_IGTK; 1198 wid.type = WID_STR; 1199 wid.size = sizeof(*key_buf) + t_key_len; 1200 wid.val = (s8 *)key_buf; 1201 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 1202 kfree(key_buf); 1203 1204 return result; 1205 } 1206 1207 int wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len, 1208 u8 index, u32 key_rsc_len, const u8 *key_rsc, 1209 const u8 *rx_mic, const u8 *tx_mic, u8 mode, 1210 u8 cipher_mode) 1211 { 1212 int result = 0; 1213 struct wilc_gtk_key *gtk_key; 1214 int t_key_len = gtk_key_len + WILC_RX_MIC_KEY_LEN + WILC_TX_MIC_KEY_LEN; 1215 1216 gtk_key = kzalloc(sizeof(*gtk_key) + t_key_len, GFP_KERNEL); 1217 if (!gtk_key) 1218 return -ENOMEM; 1219 1220 /* fill bssid value only in station mode */ 1221 if (mode == WILC_STATION_MODE && 1222 vif->hif_drv->hif_state == HOST_IF_CONNECTED) 1223 memcpy(gtk_key->mac_addr, vif->hif_drv->assoc_bssid, ETH_ALEN); 1224 1225 if (key_rsc) 1226 memcpy(gtk_key->rsc, key_rsc, 8); 1227 gtk_key->index = index; 1228 gtk_key->key_len = t_key_len; 1229 memcpy(>k_key->key[0], rx_gtk, gtk_key_len); 1230 1231 if (rx_mic) 1232 memcpy(>k_key->key[gtk_key_len], rx_mic, WILC_RX_MIC_KEY_LEN); 1233 1234 if (tx_mic) 1235 memcpy(>k_key->key[gtk_key_len + WILC_RX_MIC_KEY_LEN], 1236 tx_mic, WILC_TX_MIC_KEY_LEN); 1237 1238 if (mode == WILC_AP_MODE) { 1239 struct wid wid_list[2]; 1240 1241 wid_list[0].id = WID_11I_MODE; 1242 wid_list[0].type = WID_CHAR; 1243 wid_list[0].size = sizeof(char); 1244 wid_list[0].val = (s8 *)&cipher_mode; 1245 1246 wid_list[1].id = WID_ADD_RX_GTK; 1247 wid_list[1].type = WID_STR; 1248 wid_list[1].size = sizeof(*gtk_key) + t_key_len; 1249 wid_list[1].val = (u8 *)gtk_key; 1250 1251 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, 1252 ARRAY_SIZE(wid_list)); 1253 } else if (mode == WILC_STATION_MODE) { 1254 struct wid wid; 1255 1256 wid.id = WID_ADD_RX_GTK; 1257 wid.type = WID_STR; 1258 wid.size = sizeof(*gtk_key) + t_key_len; 1259 wid.val = (u8 *)gtk_key; 1260 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 1261 } 1262 1263 kfree(gtk_key); 1264 return result; 1265 } 1266 1267 int wilc_set_pmkid_info(struct wilc_vif *vif, struct wilc_pmkid_attr *pmkid) 1268 { 1269 struct wid wid; 1270 1271 wid.id = WID_PMKID_INFO; 1272 wid.type = WID_STR; 1273 wid.size = (pmkid->numpmkid * sizeof(struct wilc_pmkid)) + 1; 1274 wid.val = (u8 *)pmkid; 1275 1276 return wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 1277 } 1278 1279 int wilc_get_mac_address(struct wilc_vif *vif, u8 *mac_addr) 1280 { 1281 int result; 1282 struct wid wid; 1283 1284 wid.id = WID_MAC_ADDR; 1285 wid.type = WID_STR; 1286 wid.size = ETH_ALEN; 1287 wid.val = mac_addr; 1288 1289 result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1); 1290 if (result) 1291 netdev_err(vif->ndev, "Failed to get mac address\n"); 1292 1293 return result; 1294 } 1295 1296 int wilc_set_mac_address(struct wilc_vif *vif, u8 *mac_addr) 1297 { 1298 struct wid wid; 1299 int result; 1300 1301 wid.id = WID_MAC_ADDR; 1302 wid.type = WID_STR; 1303 wid.size = ETH_ALEN; 1304 wid.val = mac_addr; 1305 1306 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 1307 if (result) 1308 netdev_err(vif->ndev, "Failed to set mac address\n"); 1309 1310 return result; 1311 } 1312 1313 int wilc_set_join_req(struct wilc_vif *vif, u8 *bssid, const u8 *ies, 1314 size_t ies_len) 1315 { 1316 int result; 1317 struct host_if_drv *hif_drv = vif->hif_drv; 1318 struct wilc_conn_info *conn_info = &hif_drv->conn_info; 1319 1320 if (bssid) 1321 ether_addr_copy(conn_info->bssid, bssid); 1322 1323 if (ies) { 1324 conn_info->req_ies_len = ies_len; 1325 conn_info->req_ies = kmemdup(ies, ies_len, GFP_KERNEL); 1326 if (!conn_info->req_ies) 1327 return -ENOMEM; 1328 } 1329 1330 result = wilc_send_connect_wid(vif); 1331 if (result) 1332 goto free_ies; 1333 1334 hif_drv->connect_timer_vif = vif; 1335 mod_timer(&hif_drv->connect_timer, 1336 jiffies + msecs_to_jiffies(WILC_HIF_CONNECT_TIMEOUT_MS)); 1337 1338 return 0; 1339 1340 free_ies: 1341 kfree(conn_info->req_ies); 1342 1343 return result; 1344 } 1345 1346 int wilc_set_mac_chnl_num(struct wilc_vif *vif, u8 channel) 1347 { 1348 struct wid wid; 1349 int result; 1350 1351 wid.id = WID_CURRENT_CHANNEL; 1352 wid.type = WID_CHAR; 1353 wid.size = sizeof(char); 1354 wid.val = &channel; 1355 1356 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 1357 if (result) 1358 netdev_err(vif->ndev, "Failed to set channel\n"); 1359 1360 return result; 1361 } 1362 1363 int wilc_set_operation_mode(struct wilc_vif *vif, int index, u8 mode, 1364 u8 ifc_id) 1365 { 1366 struct wid wid; 1367 int result; 1368 struct wilc_drv_handler drv; 1369 1370 wid.id = WID_SET_OPERATION_MODE; 1371 wid.type = WID_STR; 1372 wid.size = sizeof(drv); 1373 wid.val = (u8 *)&drv; 1374 1375 drv.handler = cpu_to_le32(index); 1376 drv.mode = (ifc_id | (mode << 1)); 1377 1378 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 1379 if (result) 1380 netdev_err(vif->ndev, "Failed to set driver handler\n"); 1381 1382 return result; 1383 } 1384 1385 s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac, u32 *out_val) 1386 { 1387 struct wid wid; 1388 s32 result; 1389 1390 wid.id = WID_SET_STA_MAC_INACTIVE_TIME; 1391 wid.type = WID_STR; 1392 wid.size = ETH_ALEN; 1393 wid.val = kzalloc(wid.size, GFP_KERNEL); 1394 if (!wid.val) 1395 return -ENOMEM; 1396 1397 ether_addr_copy(wid.val, mac); 1398 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 1399 kfree(wid.val); 1400 if (result) { 1401 netdev_err(vif->ndev, "Failed to set inactive mac\n"); 1402 return result; 1403 } 1404 1405 wid.id = WID_GET_INACTIVE_TIME; 1406 wid.type = WID_INT; 1407 wid.val = (s8 *)out_val; 1408 wid.size = sizeof(u32); 1409 result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1); 1410 if (result) 1411 netdev_err(vif->ndev, "Failed to get inactive time\n"); 1412 1413 return result; 1414 } 1415 1416 int wilc_get_rssi(struct wilc_vif *vif, s8 *rssi_level) 1417 { 1418 struct wid wid; 1419 int result; 1420 1421 if (!rssi_level) { 1422 netdev_err(vif->ndev, "%s: RSSI level is NULL\n", __func__); 1423 return -EFAULT; 1424 } 1425 1426 wid.id = WID_RSSI; 1427 wid.type = WID_CHAR; 1428 wid.size = sizeof(char); 1429 wid.val = rssi_level; 1430 result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1); 1431 if (result) 1432 netdev_err(vif->ndev, "Failed to get RSSI value\n"); 1433 1434 return result; 1435 } 1436 1437 static int wilc_get_stats_async(struct wilc_vif *vif, struct rf_info *stats) 1438 { 1439 int result; 1440 struct host_if_msg *msg; 1441 1442 msg = wilc_alloc_work(vif, handle_get_statistics, false); 1443 if (IS_ERR(msg)) 1444 return PTR_ERR(msg); 1445 1446 msg->body.data = (char *)stats; 1447 1448 result = wilc_enqueue_work(msg); 1449 if (result) { 1450 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__); 1451 kfree(msg); 1452 return result; 1453 } 1454 1455 return result; 1456 } 1457 1458 int wilc_hif_set_cfg(struct wilc_vif *vif, struct cfg_param_attr *param) 1459 { 1460 struct wid wid_list[4]; 1461 int i = 0; 1462 1463 if (param->flag & WILC_CFG_PARAM_RETRY_SHORT) { 1464 wid_list[i].id = WID_SHORT_RETRY_LIMIT; 1465 wid_list[i].val = (s8 *)¶m->short_retry_limit; 1466 wid_list[i].type = WID_SHORT; 1467 wid_list[i].size = sizeof(u16); 1468 i++; 1469 } 1470 if (param->flag & WILC_CFG_PARAM_RETRY_LONG) { 1471 wid_list[i].id = WID_LONG_RETRY_LIMIT; 1472 wid_list[i].val = (s8 *)¶m->long_retry_limit; 1473 wid_list[i].type = WID_SHORT; 1474 wid_list[i].size = sizeof(u16); 1475 i++; 1476 } 1477 if (param->flag & WILC_CFG_PARAM_FRAG_THRESHOLD) { 1478 wid_list[i].id = WID_FRAG_THRESHOLD; 1479 wid_list[i].val = (s8 *)¶m->frag_threshold; 1480 wid_list[i].type = WID_SHORT; 1481 wid_list[i].size = sizeof(u16); 1482 i++; 1483 } 1484 if (param->flag & WILC_CFG_PARAM_RTS_THRESHOLD) { 1485 wid_list[i].id = WID_RTS_THRESHOLD; 1486 wid_list[i].val = (s8 *)¶m->rts_threshold; 1487 wid_list[i].type = WID_SHORT; 1488 wid_list[i].size = sizeof(u16); 1489 i++; 1490 } 1491 1492 return wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, i); 1493 } 1494 1495 static void get_periodic_rssi(struct timer_list *t) 1496 { 1497 struct wilc_vif *vif = from_timer(vif, t, periodic_rssi); 1498 1499 if (!vif->hif_drv) { 1500 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__); 1501 return; 1502 } 1503 1504 if (vif->hif_drv->hif_state == HOST_IF_CONNECTED) 1505 wilc_get_stats_async(vif, &vif->periodic_stat); 1506 1507 mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000)); 1508 } 1509 1510 int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler) 1511 { 1512 struct host_if_drv *hif_drv; 1513 struct wilc_vif *vif = netdev_priv(dev); 1514 1515 hif_drv = kzalloc(sizeof(*hif_drv), GFP_KERNEL); 1516 if (!hif_drv) 1517 return -ENOMEM; 1518 1519 *hif_drv_handler = hif_drv; 1520 1521 vif->hif_drv = hif_drv; 1522 1523 timer_setup(&vif->periodic_rssi, get_periodic_rssi, 0); 1524 mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000)); 1525 1526 timer_setup(&hif_drv->scan_timer, timer_scan_cb, 0); 1527 timer_setup(&hif_drv->connect_timer, timer_connect_cb, 0); 1528 timer_setup(&hif_drv->remain_on_ch_timer, listen_timer_cb, 0); 1529 1530 hif_drv->hif_state = HOST_IF_IDLE; 1531 1532 hif_drv->p2p_timeout = 0; 1533 1534 return 0; 1535 } 1536 1537 int wilc_deinit(struct wilc_vif *vif) 1538 { 1539 int result = 0; 1540 struct host_if_drv *hif_drv = vif->hif_drv; 1541 1542 if (!hif_drv) { 1543 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__); 1544 return -EFAULT; 1545 } 1546 1547 mutex_lock(&vif->wilc->deinit_lock); 1548 1549 timer_shutdown_sync(&hif_drv->scan_timer); 1550 timer_shutdown_sync(&hif_drv->connect_timer); 1551 del_timer_sync(&vif->periodic_rssi); 1552 timer_shutdown_sync(&hif_drv->remain_on_ch_timer); 1553 1554 if (hif_drv->usr_scan_req.scan_result) { 1555 hif_drv->usr_scan_req.scan_result(SCAN_EVENT_ABORTED, NULL, 1556 hif_drv->usr_scan_req.arg); 1557 hif_drv->usr_scan_req.scan_result = NULL; 1558 } 1559 1560 hif_drv->hif_state = HOST_IF_IDLE; 1561 1562 kfree(hif_drv); 1563 vif->hif_drv = NULL; 1564 mutex_unlock(&vif->wilc->deinit_lock); 1565 return result; 1566 } 1567 1568 void wilc_network_info_received(struct wilc *wilc, u8 *buffer, u32 length) 1569 { 1570 int result; 1571 struct host_if_msg *msg; 1572 int id; 1573 struct host_if_drv *hif_drv; 1574 struct wilc_vif *vif; 1575 1576 id = get_unaligned_le32(&buffer[length - 4]); 1577 vif = wilc_get_vif_from_idx(wilc, id); 1578 if (!vif) 1579 return; 1580 hif_drv = vif->hif_drv; 1581 1582 if (!hif_drv) { 1583 netdev_err(vif->ndev, "driver not init[%p]\n", hif_drv); 1584 return; 1585 } 1586 1587 msg = wilc_alloc_work(vif, handle_rcvd_ntwrk_info, false); 1588 if (IS_ERR(msg)) 1589 return; 1590 1591 msg->body.net_info.frame_len = get_unaligned_le16(&buffer[6]) - 1; 1592 msg->body.net_info.rssi = buffer[8]; 1593 msg->body.net_info.mgmt = kmemdup(&buffer[9], 1594 msg->body.net_info.frame_len, 1595 GFP_KERNEL); 1596 if (!msg->body.net_info.mgmt) { 1597 kfree(msg); 1598 return; 1599 } 1600 1601 result = wilc_enqueue_work(msg); 1602 if (result) { 1603 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__); 1604 kfree(msg->body.net_info.mgmt); 1605 kfree(msg); 1606 } 1607 } 1608 1609 void wilc_gnrl_async_info_received(struct wilc *wilc, u8 *buffer, u32 length) 1610 { 1611 int result; 1612 struct host_if_msg *msg; 1613 int id; 1614 struct host_if_drv *hif_drv; 1615 struct wilc_vif *vif; 1616 1617 mutex_lock(&wilc->deinit_lock); 1618 1619 id = get_unaligned_le32(&buffer[length - 4]); 1620 vif = wilc_get_vif_from_idx(wilc, id); 1621 if (!vif) { 1622 mutex_unlock(&wilc->deinit_lock); 1623 return; 1624 } 1625 1626 hif_drv = vif->hif_drv; 1627 1628 if (!hif_drv) { 1629 mutex_unlock(&wilc->deinit_lock); 1630 return; 1631 } 1632 1633 if (!hif_drv->conn_info.conn_result) { 1634 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__); 1635 mutex_unlock(&wilc->deinit_lock); 1636 return; 1637 } 1638 1639 msg = wilc_alloc_work(vif, handle_rcvd_gnrl_async_info, false); 1640 if (IS_ERR(msg)) { 1641 mutex_unlock(&wilc->deinit_lock); 1642 return; 1643 } 1644 1645 msg->body.mac_info.status = buffer[7]; 1646 result = wilc_enqueue_work(msg); 1647 if (result) { 1648 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__); 1649 kfree(msg); 1650 } 1651 1652 mutex_unlock(&wilc->deinit_lock); 1653 } 1654 1655 void wilc_scan_complete_received(struct wilc *wilc, u8 *buffer, u32 length) 1656 { 1657 int result; 1658 int id; 1659 struct host_if_drv *hif_drv; 1660 struct wilc_vif *vif; 1661 1662 id = get_unaligned_le32(&buffer[length - 4]); 1663 vif = wilc_get_vif_from_idx(wilc, id); 1664 if (!vif) 1665 return; 1666 hif_drv = vif->hif_drv; 1667 1668 if (!hif_drv) 1669 return; 1670 1671 if (hif_drv->usr_scan_req.scan_result) { 1672 struct host_if_msg *msg; 1673 1674 msg = wilc_alloc_work(vif, handle_scan_complete, false); 1675 if (IS_ERR(msg)) 1676 return; 1677 1678 result = wilc_enqueue_work(msg); 1679 if (result) { 1680 netdev_err(vif->ndev, "%s: enqueue work failed\n", 1681 __func__); 1682 kfree(msg); 1683 } 1684 } 1685 } 1686 1687 int wilc_remain_on_channel(struct wilc_vif *vif, u64 cookie, 1688 u32 duration, u16 chan, 1689 void (*expired)(void *, u64), 1690 void *user_arg) 1691 { 1692 struct wilc_remain_ch roc; 1693 int result; 1694 1695 roc.ch = chan; 1696 roc.expired = expired; 1697 roc.arg = user_arg; 1698 roc.duration = duration; 1699 roc.cookie = cookie; 1700 result = handle_remain_on_chan(vif, &roc); 1701 if (result) 1702 netdev_err(vif->ndev, "%s: failed to set remain on channel\n", 1703 __func__); 1704 1705 return result; 1706 } 1707 1708 int wilc_listen_state_expired(struct wilc_vif *vif, u64 cookie) 1709 { 1710 if (!vif->hif_drv) { 1711 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__); 1712 return -EFAULT; 1713 } 1714 1715 del_timer(&vif->hif_drv->remain_on_ch_timer); 1716 1717 return wilc_handle_roc_expired(vif, cookie); 1718 } 1719 1720 void wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg) 1721 { 1722 struct wid wid; 1723 int result; 1724 struct wilc_reg_frame reg_frame; 1725 1726 wid.id = WID_REGISTER_FRAME; 1727 wid.type = WID_STR; 1728 wid.size = sizeof(reg_frame); 1729 wid.val = (u8 *)®_frame; 1730 1731 memset(®_frame, 0x0, sizeof(reg_frame)); 1732 1733 if (reg) 1734 reg_frame.reg = 1; 1735 1736 switch (frame_type) { 1737 case IEEE80211_STYPE_ACTION: 1738 reg_frame.reg_id = WILC_FW_ACTION_FRM_IDX; 1739 break; 1740 1741 case IEEE80211_STYPE_PROBE_REQ: 1742 reg_frame.reg_id = WILC_FW_PROBE_REQ_IDX; 1743 break; 1744 1745 case IEEE80211_STYPE_AUTH: 1746 reg_frame.reg_id = WILC_FW_AUTH_REQ_IDX; 1747 break; 1748 1749 default: 1750 break; 1751 } 1752 reg_frame.frame_type = cpu_to_le16(frame_type); 1753 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 1754 if (result) 1755 netdev_err(vif->ndev, "Failed to frame register\n"); 1756 } 1757 1758 int wilc_add_beacon(struct wilc_vif *vif, u32 interval, u32 dtim_period, 1759 struct cfg80211_beacon_data *params) 1760 { 1761 struct wid wid; 1762 int result; 1763 u8 *cur_byte; 1764 1765 wid.id = WID_ADD_BEACON; 1766 wid.type = WID_BIN; 1767 wid.size = params->head_len + params->tail_len + 16; 1768 wid.val = kzalloc(wid.size, GFP_KERNEL); 1769 if (!wid.val) 1770 return -ENOMEM; 1771 1772 cur_byte = wid.val; 1773 put_unaligned_le32(interval, cur_byte); 1774 cur_byte += 4; 1775 put_unaligned_le32(dtim_period, cur_byte); 1776 cur_byte += 4; 1777 put_unaligned_le32(params->head_len, cur_byte); 1778 cur_byte += 4; 1779 1780 if (params->head_len > 0) 1781 memcpy(cur_byte, params->head, params->head_len); 1782 cur_byte += params->head_len; 1783 1784 put_unaligned_le32(params->tail_len, cur_byte); 1785 cur_byte += 4; 1786 1787 if (params->tail_len > 0) 1788 memcpy(cur_byte, params->tail, params->tail_len); 1789 1790 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 1791 if (result) 1792 netdev_err(vif->ndev, "Failed to send add beacon\n"); 1793 1794 kfree(wid.val); 1795 1796 return result; 1797 } 1798 1799 int wilc_del_beacon(struct wilc_vif *vif) 1800 { 1801 int result; 1802 struct wid wid; 1803 u8 del_beacon = 0; 1804 1805 wid.id = WID_DEL_BEACON; 1806 wid.type = WID_CHAR; 1807 wid.size = sizeof(char); 1808 wid.val = &del_beacon; 1809 1810 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 1811 if (result) 1812 netdev_err(vif->ndev, "Failed to send delete beacon\n"); 1813 1814 return result; 1815 } 1816 1817 int wilc_add_station(struct wilc_vif *vif, const u8 *mac, 1818 struct station_parameters *params) 1819 { 1820 struct wid wid; 1821 int result; 1822 u8 *cur_byte; 1823 1824 wid.id = WID_ADD_STA; 1825 wid.type = WID_BIN; 1826 wid.size = WILC_ADD_STA_LENGTH + 1827 params->link_sta_params.supported_rates_len; 1828 wid.val = kmalloc(wid.size, GFP_KERNEL); 1829 if (!wid.val) 1830 return -ENOMEM; 1831 1832 cur_byte = wid.val; 1833 wilc_hif_pack_sta_param(cur_byte, mac, params); 1834 1835 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 1836 if (result != 0) 1837 netdev_err(vif->ndev, "Failed to send add station\n"); 1838 1839 kfree(wid.val); 1840 1841 return result; 1842 } 1843 1844 int wilc_del_station(struct wilc_vif *vif, const u8 *mac_addr) 1845 { 1846 struct wid wid; 1847 int result; 1848 1849 wid.id = WID_REMOVE_STA; 1850 wid.type = WID_BIN; 1851 wid.size = ETH_ALEN; 1852 wid.val = kzalloc(wid.size, GFP_KERNEL); 1853 if (!wid.val) 1854 return -ENOMEM; 1855 1856 if (!mac_addr) 1857 eth_broadcast_addr(wid.val); 1858 else 1859 ether_addr_copy(wid.val, mac_addr); 1860 1861 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 1862 if (result) 1863 netdev_err(vif->ndev, "Failed to del station\n"); 1864 1865 kfree(wid.val); 1866 1867 return result; 1868 } 1869 1870 int wilc_del_allstation(struct wilc_vif *vif, u8 mac_addr[][ETH_ALEN]) 1871 { 1872 struct wid wid; 1873 int result; 1874 int i; 1875 u8 assoc_sta = 0; 1876 struct wilc_del_all_sta del_sta; 1877 1878 memset(&del_sta, 0x0, sizeof(del_sta)); 1879 for (i = 0; i < WILC_MAX_NUM_STA; i++) { 1880 if (!is_zero_ether_addr(mac_addr[i])) { 1881 assoc_sta++; 1882 ether_addr_copy(del_sta.mac[i], mac_addr[i]); 1883 } 1884 } 1885 1886 if (!assoc_sta) 1887 return 0; 1888 1889 del_sta.assoc_sta = assoc_sta; 1890 1891 wid.id = WID_DEL_ALL_STA; 1892 wid.type = WID_STR; 1893 wid.size = (assoc_sta * ETH_ALEN) + 1; 1894 wid.val = (u8 *)&del_sta; 1895 1896 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 1897 if (result) 1898 netdev_err(vif->ndev, "Failed to send delete all station\n"); 1899 1900 return result; 1901 } 1902 1903 int wilc_edit_station(struct wilc_vif *vif, const u8 *mac, 1904 struct station_parameters *params) 1905 { 1906 struct wid wid; 1907 int result; 1908 u8 *cur_byte; 1909 1910 wid.id = WID_EDIT_STA; 1911 wid.type = WID_BIN; 1912 wid.size = WILC_ADD_STA_LENGTH + 1913 params->link_sta_params.supported_rates_len; 1914 wid.val = kmalloc(wid.size, GFP_KERNEL); 1915 if (!wid.val) 1916 return -ENOMEM; 1917 1918 cur_byte = wid.val; 1919 wilc_hif_pack_sta_param(cur_byte, mac, params); 1920 1921 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 1922 if (result) 1923 netdev_err(vif->ndev, "Failed to send edit station\n"); 1924 1925 kfree(wid.val); 1926 return result; 1927 } 1928 1929 int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout) 1930 { 1931 struct wilc *wilc = vif->wilc; 1932 struct wid wid; 1933 int result; 1934 s8 power_mode; 1935 1936 if (enabled) 1937 power_mode = WILC_FW_MIN_FAST_PS; 1938 else 1939 power_mode = WILC_FW_NO_POWERSAVE; 1940 1941 wid.id = WID_POWER_MANAGEMENT; 1942 wid.val = &power_mode; 1943 wid.size = sizeof(char); 1944 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 1945 if (result) 1946 netdev_err(vif->ndev, "Failed to send power management\n"); 1947 else 1948 wilc->power_save_mode = enabled; 1949 1950 return result; 1951 } 1952 1953 int wilc_setup_multicast_filter(struct wilc_vif *vif, u32 enabled, u32 count, 1954 u8 *mc_list) 1955 { 1956 int result; 1957 struct host_if_msg *msg; 1958 1959 msg = wilc_alloc_work(vif, handle_set_mcast_filter, false); 1960 if (IS_ERR(msg)) 1961 return PTR_ERR(msg); 1962 1963 msg->body.mc_info.enabled = enabled; 1964 msg->body.mc_info.cnt = count; 1965 msg->body.mc_info.mc_list = mc_list; 1966 1967 result = wilc_enqueue_work(msg); 1968 if (result) { 1969 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__); 1970 kfree(msg); 1971 } 1972 return result; 1973 } 1974 1975 int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power) 1976 { 1977 struct wid wid; 1978 1979 wid.id = WID_TX_POWER; 1980 wid.type = WID_CHAR; 1981 wid.val = &tx_power; 1982 wid.size = sizeof(char); 1983 1984 return wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 1985 } 1986 1987 int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power) 1988 { 1989 struct wid wid; 1990 1991 wid.id = WID_TX_POWER; 1992 wid.type = WID_CHAR; 1993 wid.val = tx_power; 1994 wid.size = sizeof(char); 1995 1996 return wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1); 1997 } 1998 1999 int wilc_set_default_mgmt_key_index(struct wilc_vif *vif, u8 index) 2000 { 2001 struct wid wid; 2002 int result; 2003 2004 wid.id = WID_DEFAULT_MGMT_KEY_ID; 2005 wid.type = WID_CHAR; 2006 wid.size = sizeof(char); 2007 wid.val = &index; 2008 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1); 2009 if (result) 2010 netdev_err(vif->ndev, 2011 "Failed to send default mgmt key index\n"); 2012 2013 return result; 2014 } 2015