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