0001
0002
0003
0004
0005
0006
0007 #include "netdev.h"
0008
0009 #define WILC_HIF_SCAN_TIMEOUT_MS 5000
0010 #define WILC_HIF_CONNECT_TIMEOUT_MS 9500
0011
0012 #define WILC_FALSE_FRMWR_CHANNEL 100
0013
0014 #define WILC_SCAN_WID_LIST_SIZE 6
0015
0016 struct wilc_rcvd_mac_info {
0017 u8 status;
0018 };
0019
0020 struct wilc_set_multicast {
0021 u32 enabled;
0022 u32 cnt;
0023 u8 *mc_list;
0024 };
0025
0026 struct host_if_wowlan_trigger {
0027 u8 wowlan_trigger;
0028 };
0029
0030 struct wilc_del_all_sta {
0031 u8 assoc_sta;
0032 u8 mac[WILC_MAX_NUM_STA][ETH_ALEN];
0033 };
0034
0035 union wilc_message_body {
0036 struct wilc_rcvd_net_info net_info;
0037 struct wilc_rcvd_mac_info mac_info;
0038 struct wilc_set_multicast mc_info;
0039 struct wilc_remain_ch remain_on_ch;
0040 char *data;
0041 struct host_if_wowlan_trigger wow_trigger;
0042 };
0043
0044 struct host_if_msg {
0045 union wilc_message_body body;
0046 struct wilc_vif *vif;
0047 struct work_struct work;
0048 void (*fn)(struct work_struct *ws);
0049 struct completion work_comp;
0050 bool is_sync;
0051 };
0052
0053
0054 static struct host_if_msg*
0055 wilc_alloc_work(struct wilc_vif *vif, void (*work_fun)(struct work_struct *),
0056 bool is_sync)
0057 {
0058 struct host_if_msg *msg;
0059
0060 if (!work_fun)
0061 return ERR_PTR(-EINVAL);
0062
0063 msg = kzalloc(sizeof(*msg), GFP_ATOMIC);
0064 if (!msg)
0065 return ERR_PTR(-ENOMEM);
0066 msg->fn = work_fun;
0067 msg->vif = vif;
0068 msg->is_sync = is_sync;
0069 if (is_sync)
0070 init_completion(&msg->work_comp);
0071
0072 return msg;
0073 }
0074
0075 static int wilc_enqueue_work(struct host_if_msg *msg)
0076 {
0077 INIT_WORK(&msg->work, msg->fn);
0078
0079 if (!msg->vif || !msg->vif->wilc || !msg->vif->wilc->hif_workqueue)
0080 return -EINVAL;
0081
0082 if (!queue_work(msg->vif->wilc->hif_workqueue, &msg->work))
0083 return -EINVAL;
0084
0085 return 0;
0086 }
0087
0088
0089
0090
0091
0092 int wilc_get_vif_idx(struct wilc_vif *vif)
0093 {
0094 return vif->idx + 1;
0095 }
0096
0097
0098
0099
0100
0101
0102 static struct wilc_vif *wilc_get_vif_from_idx(struct wilc *wilc, int idx)
0103 {
0104 int index = idx - 1;
0105 struct wilc_vif *vif;
0106
0107 if (index < 0 || index >= WILC_NUM_CONCURRENT_IFC)
0108 return NULL;
0109
0110 list_for_each_entry_rcu(vif, &wilc->vif_list, list) {
0111 if (vif->idx == index)
0112 return vif;
0113 }
0114
0115 return NULL;
0116 }
0117
0118 static int handle_scan_done(struct wilc_vif *vif, enum scan_event evt)
0119 {
0120 int result = 0;
0121 u8 abort_running_scan;
0122 struct wid wid;
0123 struct host_if_drv *hif_drv = vif->hif_drv;
0124 struct wilc_user_scan_req *scan_req;
0125
0126 if (evt == SCAN_EVENT_ABORTED) {
0127 abort_running_scan = 1;
0128 wid.id = WID_ABORT_RUNNING_SCAN;
0129 wid.type = WID_CHAR;
0130 wid.val = (s8 *)&abort_running_scan;
0131 wid.size = sizeof(char);
0132
0133 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
0134 if (result) {
0135 netdev_err(vif->ndev, "Failed to set abort running\n");
0136 result = -EFAULT;
0137 }
0138 }
0139
0140 if (!hif_drv) {
0141 netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
0142 return result;
0143 }
0144
0145 scan_req = &hif_drv->usr_scan_req;
0146 if (scan_req->scan_result) {
0147 scan_req->scan_result(evt, NULL, scan_req->arg);
0148 scan_req->scan_result = NULL;
0149 }
0150
0151 return result;
0152 }
0153
0154 int wilc_scan(struct wilc_vif *vif, u8 scan_source, u8 scan_type,
0155 u8 *ch_freq_list, u8 ch_list_len,
0156 void (*scan_result_fn)(enum scan_event,
0157 struct wilc_rcvd_net_info *, void *),
0158 void *user_arg, struct cfg80211_scan_request *request)
0159 {
0160 int result = 0;
0161 struct wid wid_list[WILC_SCAN_WID_LIST_SIZE];
0162 u32 index = 0;
0163 u32 i, scan_timeout;
0164 u8 *buffer;
0165 u8 valuesize = 0;
0166 u8 *search_ssid_vals = NULL;
0167 struct host_if_drv *hif_drv = vif->hif_drv;
0168
0169 if (hif_drv->hif_state >= HOST_IF_SCANNING &&
0170 hif_drv->hif_state < HOST_IF_CONNECTED) {
0171 netdev_err(vif->ndev, "Already scan\n");
0172 result = -EBUSY;
0173 goto error;
0174 }
0175
0176 if (vif->connecting) {
0177 netdev_err(vif->ndev, "Don't do obss scan\n");
0178 result = -EBUSY;
0179 goto error;
0180 }
0181
0182 hif_drv->usr_scan_req.ch_cnt = 0;
0183
0184 if (request->n_ssids) {
0185 for (i = 0; i < request->n_ssids; i++)
0186 valuesize += ((request->ssids[i].ssid_len) + 1);
0187 search_ssid_vals = kmalloc(valuesize + 1, GFP_KERNEL);
0188 if (search_ssid_vals) {
0189 wid_list[index].id = WID_SSID_PROBE_REQ;
0190 wid_list[index].type = WID_STR;
0191 wid_list[index].val = search_ssid_vals;
0192 buffer = wid_list[index].val;
0193
0194 *buffer++ = request->n_ssids;
0195
0196 for (i = 0; i < request->n_ssids; i++) {
0197 *buffer++ = request->ssids[i].ssid_len;
0198 memcpy(buffer, request->ssids[i].ssid,
0199 request->ssids[i].ssid_len);
0200 buffer += request->ssids[i].ssid_len;
0201 }
0202 wid_list[index].size = (s32)(valuesize + 1);
0203 index++;
0204 }
0205 }
0206
0207 wid_list[index].id = WID_INFO_ELEMENT_PROBE;
0208 wid_list[index].type = WID_BIN_DATA;
0209 wid_list[index].val = (s8 *)request->ie;
0210 wid_list[index].size = request->ie_len;
0211 index++;
0212
0213 wid_list[index].id = WID_SCAN_TYPE;
0214 wid_list[index].type = WID_CHAR;
0215 wid_list[index].size = sizeof(char);
0216 wid_list[index].val = (s8 *)&scan_type;
0217 index++;
0218
0219 if (scan_type == WILC_FW_PASSIVE_SCAN && request->duration) {
0220 wid_list[index].id = WID_PASSIVE_SCAN_TIME;
0221 wid_list[index].type = WID_SHORT;
0222 wid_list[index].size = sizeof(u16);
0223 wid_list[index].val = (s8 *)&request->duration;
0224 index++;
0225
0226 scan_timeout = (request->duration * ch_list_len) + 500;
0227 } else {
0228 scan_timeout = WILC_HIF_SCAN_TIMEOUT_MS;
0229 }
0230
0231 wid_list[index].id = WID_SCAN_CHANNEL_LIST;
0232 wid_list[index].type = WID_BIN_DATA;
0233
0234 if (ch_freq_list && ch_list_len > 0) {
0235 for (i = 0; i < ch_list_len; i++) {
0236 if (ch_freq_list[i] > 0)
0237 ch_freq_list[i] -= 1;
0238 }
0239 }
0240
0241 wid_list[index].val = ch_freq_list;
0242 wid_list[index].size = ch_list_len;
0243 index++;
0244
0245 wid_list[index].id = WID_START_SCAN_REQ;
0246 wid_list[index].type = WID_CHAR;
0247 wid_list[index].size = sizeof(char);
0248 wid_list[index].val = (s8 *)&scan_source;
0249 index++;
0250
0251 hif_drv->usr_scan_req.scan_result = scan_result_fn;
0252 hif_drv->usr_scan_req.arg = user_arg;
0253
0254 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, index);
0255 if (result) {
0256 netdev_err(vif->ndev, "Failed to send scan parameters\n");
0257 goto error;
0258 }
0259
0260 hif_drv->scan_timer_vif = vif;
0261 mod_timer(&hif_drv->scan_timer,
0262 jiffies + msecs_to_jiffies(scan_timeout));
0263
0264 error:
0265
0266 kfree(search_ssid_vals);
0267
0268 return result;
0269 }
0270
0271 static int wilc_send_connect_wid(struct wilc_vif *vif)
0272 {
0273 int result = 0;
0274 struct wid wid_list[5];
0275 u32 wid_cnt = 0;
0276 struct host_if_drv *hif_drv = vif->hif_drv;
0277 struct wilc_conn_info *conn_attr = &hif_drv->conn_info;
0278 struct wilc_join_bss_param *bss_param = conn_attr->param;
0279
0280
0281 wid_list[wid_cnt].id = WID_SET_MFP;
0282 wid_list[wid_cnt].type = WID_CHAR;
0283 wid_list[wid_cnt].size = sizeof(char);
0284 wid_list[wid_cnt].val = (s8 *)&conn_attr->mfp_type;
0285 wid_cnt++;
0286
0287 wid_list[wid_cnt].id = WID_INFO_ELEMENT_ASSOCIATE;
0288 wid_list[wid_cnt].type = WID_BIN_DATA;
0289 wid_list[wid_cnt].val = conn_attr->req_ies;
0290 wid_list[wid_cnt].size = conn_attr->req_ies_len;
0291 wid_cnt++;
0292
0293 wid_list[wid_cnt].id = WID_11I_MODE;
0294 wid_list[wid_cnt].type = WID_CHAR;
0295 wid_list[wid_cnt].size = sizeof(char);
0296 wid_list[wid_cnt].val = (s8 *)&conn_attr->security;
0297 wid_cnt++;
0298
0299 wid_list[wid_cnt].id = WID_AUTH_TYPE;
0300 wid_list[wid_cnt].type = WID_CHAR;
0301 wid_list[wid_cnt].size = sizeof(char);
0302 wid_list[wid_cnt].val = (s8 *)&conn_attr->auth_type;
0303 wid_cnt++;
0304
0305 wid_list[wid_cnt].id = WID_JOIN_REQ_EXTENDED;
0306 wid_list[wid_cnt].type = WID_STR;
0307 wid_list[wid_cnt].size = sizeof(*bss_param);
0308 wid_list[wid_cnt].val = (u8 *)bss_param;
0309 wid_cnt++;
0310
0311 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, wid_cnt);
0312 if (result) {
0313 netdev_err(vif->ndev, "failed to send config packet\n");
0314 goto error;
0315 } else {
0316 if (conn_attr->auth_type == WILC_FW_AUTH_SAE)
0317 hif_drv->hif_state = HOST_IF_EXTERNAL_AUTH;
0318 else
0319 hif_drv->hif_state = HOST_IF_WAITING_CONN_RESP;
0320 }
0321
0322 return 0;
0323
0324 error:
0325
0326 kfree(conn_attr->req_ies);
0327 conn_attr->req_ies = NULL;
0328
0329 return result;
0330 }
0331
0332 static void handle_connect_timeout(struct work_struct *work)
0333 {
0334 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
0335 struct wilc_vif *vif = msg->vif;
0336 int result;
0337 struct wid wid;
0338 u16 dummy_reason_code = 0;
0339 struct host_if_drv *hif_drv = vif->hif_drv;
0340
0341 if (!hif_drv) {
0342 netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
0343 goto out;
0344 }
0345
0346 hif_drv->hif_state = HOST_IF_IDLE;
0347
0348 if (hif_drv->conn_info.conn_result) {
0349 hif_drv->conn_info.conn_result(CONN_DISCONN_EVENT_CONN_RESP,
0350 WILC_MAC_STATUS_DISCONNECTED,
0351 hif_drv->conn_info.arg);
0352
0353 } else {
0354 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
0355 }
0356
0357 wid.id = WID_DISCONNECT;
0358 wid.type = WID_CHAR;
0359 wid.val = (s8 *)&dummy_reason_code;
0360 wid.size = sizeof(char);
0361
0362 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
0363 if (result)
0364 netdev_err(vif->ndev, "Failed to send disconnect\n");
0365
0366 hif_drv->conn_info.req_ies_len = 0;
0367 kfree(hif_drv->conn_info.req_ies);
0368 hif_drv->conn_info.req_ies = NULL;
0369
0370 out:
0371 kfree(msg);
0372 }
0373
0374 void *wilc_parse_join_bss_param(struct cfg80211_bss *bss,
0375 struct cfg80211_crypto_settings *crypto)
0376 {
0377 struct wilc_join_bss_param *param;
0378 struct ieee80211_p2p_noa_attr noa_attr;
0379 u8 rates_len = 0;
0380 const u8 *tim_elm, *ssid_elm, *rates_ie, *supp_rates_ie;
0381 const u8 *ht_ie, *wpa_ie, *wmm_ie, *rsn_ie;
0382 int ret;
0383 const struct cfg80211_bss_ies *ies = rcu_dereference(bss->ies);
0384
0385 param = kzalloc(sizeof(*param), GFP_KERNEL);
0386 if (!param)
0387 return NULL;
0388
0389 param->beacon_period = cpu_to_le16(bss->beacon_interval);
0390 param->cap_info = cpu_to_le16(bss->capability);
0391 param->bss_type = WILC_FW_BSS_TYPE_INFRA;
0392 param->ch = ieee80211_frequency_to_channel(bss->channel->center_freq);
0393 ether_addr_copy(param->bssid, bss->bssid);
0394
0395 ssid_elm = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len);
0396 if (ssid_elm) {
0397 if (ssid_elm[1] <= IEEE80211_MAX_SSID_LEN)
0398 memcpy(param->ssid, ssid_elm + 2, ssid_elm[1]);
0399 }
0400
0401 tim_elm = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
0402 if (tim_elm && tim_elm[1] >= 2)
0403 param->dtim_period = tim_elm[3];
0404
0405 memset(param->p_suites, 0xFF, 3);
0406 memset(param->akm_suites, 0xFF, 3);
0407
0408 rates_ie = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies->data, ies->len);
0409 if (rates_ie) {
0410 rates_len = rates_ie[1];
0411 if (rates_len > WILC_MAX_RATES_SUPPORTED)
0412 rates_len = WILC_MAX_RATES_SUPPORTED;
0413 param->supp_rates[0] = rates_len;
0414 memcpy(¶m->supp_rates[1], rates_ie + 2, rates_len);
0415 }
0416
0417 if (rates_len < WILC_MAX_RATES_SUPPORTED) {
0418 supp_rates_ie = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES,
0419 ies->data, ies->len);
0420 if (supp_rates_ie) {
0421 u8 ext_rates = supp_rates_ie[1];
0422
0423 if (ext_rates > (WILC_MAX_RATES_SUPPORTED - rates_len))
0424 param->supp_rates[0] = WILC_MAX_RATES_SUPPORTED;
0425 else
0426 param->supp_rates[0] += ext_rates;
0427
0428 memcpy(¶m->supp_rates[rates_len + 1],
0429 supp_rates_ie + 2,
0430 (param->supp_rates[0] - rates_len));
0431 }
0432 }
0433
0434 ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies->data, ies->len);
0435 if (ht_ie)
0436 param->ht_capable = true;
0437
0438 ret = cfg80211_get_p2p_attr(ies->data, ies->len,
0439 IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
0440 (u8 *)&noa_attr, sizeof(noa_attr));
0441 if (ret > 0) {
0442 param->tsf_lo = cpu_to_le32(ies->tsf);
0443 param->noa_enabled = 1;
0444 param->idx = noa_attr.index;
0445 if (noa_attr.oppps_ctwindow & IEEE80211_P2P_OPPPS_ENABLE_BIT) {
0446 param->opp_enabled = 1;
0447 param->opp_en.ct_window = noa_attr.oppps_ctwindow;
0448 param->opp_en.cnt = noa_attr.desc[0].count;
0449 param->opp_en.duration = noa_attr.desc[0].duration;
0450 param->opp_en.interval = noa_attr.desc[0].interval;
0451 param->opp_en.start_time = noa_attr.desc[0].start_time;
0452 } else {
0453 param->opp_enabled = 0;
0454 param->opp_dis.cnt = noa_attr.desc[0].count;
0455 param->opp_dis.duration = noa_attr.desc[0].duration;
0456 param->opp_dis.interval = noa_attr.desc[0].interval;
0457 param->opp_dis.start_time = noa_attr.desc[0].start_time;
0458 }
0459 }
0460 wmm_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
0461 WLAN_OUI_TYPE_MICROSOFT_WMM,
0462 ies->data, ies->len);
0463 if (wmm_ie) {
0464 struct ieee80211_wmm_param_ie *ie;
0465
0466 ie = (struct ieee80211_wmm_param_ie *)wmm_ie;
0467 if ((ie->oui_subtype == 0 || ie->oui_subtype == 1) &&
0468 ie->version == 1) {
0469 param->wmm_cap = true;
0470 if (ie->qos_info & BIT(7))
0471 param->uapsd_cap = true;
0472 }
0473 }
0474
0475 wpa_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
0476 WLAN_OUI_TYPE_MICROSOFT_WPA,
0477 ies->data, ies->len);
0478 if (wpa_ie) {
0479 param->mode_802_11i = 1;
0480 param->rsn_found = true;
0481 }
0482
0483 rsn_ie = cfg80211_find_ie(WLAN_EID_RSN, ies->data, ies->len);
0484 if (rsn_ie) {
0485 int offset = 8;
0486
0487 param->mode_802_11i = 2;
0488 param->rsn_found = true;
0489
0490 offset += (rsn_ie[offset] * 4) + 2;
0491 offset += (rsn_ie[offset] * 4) + 2;
0492 memcpy(param->rsn_cap, &rsn_ie[offset], 2);
0493 }
0494
0495 if (param->rsn_found) {
0496 int i;
0497
0498 param->rsn_grp_policy = crypto->cipher_group & 0xFF;
0499 for (i = 0; i < crypto->n_ciphers_pairwise && i < 3; i++)
0500 param->p_suites[i] = crypto->ciphers_pairwise[i] & 0xFF;
0501
0502 for (i = 0; i < crypto->n_akm_suites && i < 3; i++)
0503 param->akm_suites[i] = crypto->akm_suites[i] & 0xFF;
0504 }
0505
0506 return (void *)param;
0507 }
0508
0509 static void handle_rcvd_ntwrk_info(struct work_struct *work)
0510 {
0511 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
0512 struct wilc_rcvd_net_info *rcvd_info = &msg->body.net_info;
0513 struct wilc_user_scan_req *scan_req = &msg->vif->hif_drv->usr_scan_req;
0514 const u8 *ch_elm;
0515 u8 *ies;
0516 int ies_len;
0517 size_t offset;
0518
0519 if (ieee80211_is_probe_resp(rcvd_info->mgmt->frame_control))
0520 offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
0521 else if (ieee80211_is_beacon(rcvd_info->mgmt->frame_control))
0522 offset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
0523 else
0524 goto done;
0525
0526 ies = rcvd_info->mgmt->u.beacon.variable;
0527 ies_len = rcvd_info->frame_len - offset;
0528 if (ies_len <= 0)
0529 goto done;
0530
0531 ch_elm = cfg80211_find_ie(WLAN_EID_DS_PARAMS, ies, ies_len);
0532 if (ch_elm && ch_elm[1] > 0)
0533 rcvd_info->ch = ch_elm[2];
0534
0535 if (scan_req->scan_result)
0536 scan_req->scan_result(SCAN_EVENT_NETWORK_FOUND, rcvd_info,
0537 scan_req->arg);
0538
0539 done:
0540 kfree(rcvd_info->mgmt);
0541 kfree(msg);
0542 }
0543
0544 static void host_int_get_assoc_res_info(struct wilc_vif *vif,
0545 u8 *assoc_resp_info,
0546 u32 max_assoc_resp_info_len,
0547 u32 *rcvd_assoc_resp_info_len)
0548 {
0549 int result;
0550 struct wid wid;
0551
0552 wid.id = WID_ASSOC_RES_INFO;
0553 wid.type = WID_STR;
0554 wid.val = assoc_resp_info;
0555 wid.size = max_assoc_resp_info_len;
0556
0557 result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
0558 if (result) {
0559 *rcvd_assoc_resp_info_len = 0;
0560 netdev_err(vif->ndev, "Failed to send association response\n");
0561 return;
0562 }
0563
0564 *rcvd_assoc_resp_info_len = wid.size;
0565 }
0566
0567 static s32 wilc_parse_assoc_resp_info(u8 *buffer, u32 buffer_len,
0568 struct wilc_conn_info *ret_conn_info)
0569 {
0570 u8 *ies;
0571 u16 ies_len;
0572 struct wilc_assoc_resp *res = (struct wilc_assoc_resp *)buffer;
0573
0574 ret_conn_info->status = le16_to_cpu(res->status_code);
0575 if (ret_conn_info->status == WLAN_STATUS_SUCCESS) {
0576 ies = &buffer[sizeof(*res)];
0577 ies_len = buffer_len - sizeof(*res);
0578
0579 ret_conn_info->resp_ies = kmemdup(ies, ies_len, GFP_KERNEL);
0580 if (!ret_conn_info->resp_ies)
0581 return -ENOMEM;
0582
0583 ret_conn_info->resp_ies_len = ies_len;
0584 }
0585
0586 return 0;
0587 }
0588
0589 static inline void host_int_parse_assoc_resp_info(struct wilc_vif *vif,
0590 u8 mac_status)
0591 {
0592 struct host_if_drv *hif_drv = vif->hif_drv;
0593 struct wilc_conn_info *conn_info = &hif_drv->conn_info;
0594
0595 if (mac_status == WILC_MAC_STATUS_CONNECTED) {
0596 u32 assoc_resp_info_len;
0597
0598 memset(hif_drv->assoc_resp, 0, WILC_MAX_ASSOC_RESP_FRAME_SIZE);
0599
0600 host_int_get_assoc_res_info(vif, hif_drv->assoc_resp,
0601 WILC_MAX_ASSOC_RESP_FRAME_SIZE,
0602 &assoc_resp_info_len);
0603
0604 if (assoc_resp_info_len != 0) {
0605 s32 err = 0;
0606
0607 err = wilc_parse_assoc_resp_info(hif_drv->assoc_resp,
0608 assoc_resp_info_len,
0609 conn_info);
0610 if (err)
0611 netdev_err(vif->ndev,
0612 "wilc_parse_assoc_resp_info() returned error %d\n",
0613 err);
0614 }
0615 }
0616
0617 del_timer(&hif_drv->connect_timer);
0618 conn_info->conn_result(CONN_DISCONN_EVENT_CONN_RESP, mac_status,
0619 hif_drv->conn_info.arg);
0620
0621 if (mac_status == WILC_MAC_STATUS_CONNECTED &&
0622 conn_info->status == WLAN_STATUS_SUCCESS) {
0623 ether_addr_copy(hif_drv->assoc_bssid, conn_info->bssid);
0624 hif_drv->hif_state = HOST_IF_CONNECTED;
0625 } else {
0626 hif_drv->hif_state = HOST_IF_IDLE;
0627 }
0628
0629 kfree(conn_info->resp_ies);
0630 conn_info->resp_ies = NULL;
0631 conn_info->resp_ies_len = 0;
0632
0633 kfree(conn_info->req_ies);
0634 conn_info->req_ies = NULL;
0635 conn_info->req_ies_len = 0;
0636 }
0637
0638 void wilc_handle_disconnect(struct wilc_vif *vif)
0639 {
0640 struct host_if_drv *hif_drv = vif->hif_drv;
0641
0642 if (hif_drv->usr_scan_req.scan_result) {
0643 del_timer(&hif_drv->scan_timer);
0644 handle_scan_done(vif, SCAN_EVENT_ABORTED);
0645 }
0646
0647 if (hif_drv->conn_info.conn_result)
0648 hif_drv->conn_info.conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF,
0649 0, hif_drv->conn_info.arg);
0650
0651 eth_zero_addr(hif_drv->assoc_bssid);
0652
0653 hif_drv->conn_info.req_ies_len = 0;
0654 kfree(hif_drv->conn_info.req_ies);
0655 hif_drv->conn_info.req_ies = NULL;
0656 hif_drv->hif_state = HOST_IF_IDLE;
0657 }
0658
0659 static void handle_rcvd_gnrl_async_info(struct work_struct *work)
0660 {
0661 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
0662 struct wilc_vif *vif = msg->vif;
0663 struct wilc_rcvd_mac_info *mac_info = &msg->body.mac_info;
0664 struct host_if_drv *hif_drv = vif->hif_drv;
0665
0666 if (!hif_drv) {
0667 netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
0668 goto free_msg;
0669 }
0670
0671 if (!hif_drv->conn_info.conn_result) {
0672 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
0673 goto free_msg;
0674 }
0675
0676
0677 if (hif_drv->hif_state == HOST_IF_EXTERNAL_AUTH) {
0678 cfg80211_external_auth_request(vif->ndev, &vif->auth,
0679 GFP_KERNEL);
0680 hif_drv->hif_state = HOST_IF_WAITING_CONN_RESP;
0681 } else if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) {
0682 host_int_parse_assoc_resp_info(vif, mac_info->status);
0683 } else if (mac_info->status == WILC_MAC_STATUS_DISCONNECTED) {
0684 if (hif_drv->hif_state == HOST_IF_CONNECTED) {
0685 wilc_handle_disconnect(vif);
0686 } else if (hif_drv->usr_scan_req.scan_result) {
0687 del_timer(&hif_drv->scan_timer);
0688 handle_scan_done(vif, SCAN_EVENT_ABORTED);
0689 }
0690 }
0691
0692 free_msg:
0693 kfree(msg);
0694 }
0695
0696 int wilc_disconnect(struct wilc_vif *vif)
0697 {
0698 struct wid wid;
0699 struct host_if_drv *hif_drv = vif->hif_drv;
0700 struct wilc_user_scan_req *scan_req;
0701 struct wilc_conn_info *conn_info;
0702 int result;
0703 u16 dummy_reason_code = 0;
0704
0705 wid.id = WID_DISCONNECT;
0706 wid.type = WID_CHAR;
0707 wid.val = (s8 *)&dummy_reason_code;
0708 wid.size = sizeof(char);
0709
0710 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
0711 if (result) {
0712 netdev_err(vif->ndev, "Failed to send disconnect\n");
0713 return result;
0714 }
0715
0716 scan_req = &hif_drv->usr_scan_req;
0717 conn_info = &hif_drv->conn_info;
0718
0719 if (scan_req->scan_result) {
0720 del_timer(&hif_drv->scan_timer);
0721 scan_req->scan_result(SCAN_EVENT_ABORTED, NULL, scan_req->arg);
0722 scan_req->scan_result = NULL;
0723 }
0724
0725 if (conn_info->conn_result) {
0726 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP ||
0727 hif_drv->hif_state == HOST_IF_EXTERNAL_AUTH)
0728 del_timer(&hif_drv->connect_timer);
0729
0730 conn_info->conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF, 0,
0731 conn_info->arg);
0732 } else {
0733 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
0734 }
0735
0736 hif_drv->hif_state = HOST_IF_IDLE;
0737
0738 eth_zero_addr(hif_drv->assoc_bssid);
0739
0740 conn_info->req_ies_len = 0;
0741 kfree(conn_info->req_ies);
0742 conn_info->req_ies = NULL;
0743
0744 return 0;
0745 }
0746
0747 int wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats)
0748 {
0749 struct wid wid_list[5];
0750 u32 wid_cnt = 0, result;
0751
0752 wid_list[wid_cnt].id = WID_LINKSPEED;
0753 wid_list[wid_cnt].type = WID_CHAR;
0754 wid_list[wid_cnt].size = sizeof(char);
0755 wid_list[wid_cnt].val = (s8 *)&stats->link_speed;
0756 wid_cnt++;
0757
0758 wid_list[wid_cnt].id = WID_RSSI;
0759 wid_list[wid_cnt].type = WID_CHAR;
0760 wid_list[wid_cnt].size = sizeof(char);
0761 wid_list[wid_cnt].val = (s8 *)&stats->rssi;
0762 wid_cnt++;
0763
0764 wid_list[wid_cnt].id = WID_SUCCESS_FRAME_COUNT;
0765 wid_list[wid_cnt].type = WID_INT;
0766 wid_list[wid_cnt].size = sizeof(u32);
0767 wid_list[wid_cnt].val = (s8 *)&stats->tx_cnt;
0768 wid_cnt++;
0769
0770 wid_list[wid_cnt].id = WID_RECEIVED_FRAGMENT_COUNT;
0771 wid_list[wid_cnt].type = WID_INT;
0772 wid_list[wid_cnt].size = sizeof(u32);
0773 wid_list[wid_cnt].val = (s8 *)&stats->rx_cnt;
0774 wid_cnt++;
0775
0776 wid_list[wid_cnt].id = WID_FAILED_COUNT;
0777 wid_list[wid_cnt].type = WID_INT;
0778 wid_list[wid_cnt].size = sizeof(u32);
0779 wid_list[wid_cnt].val = (s8 *)&stats->tx_fail_cnt;
0780 wid_cnt++;
0781
0782 result = wilc_send_config_pkt(vif, WILC_GET_CFG, wid_list, wid_cnt);
0783 if (result) {
0784 netdev_err(vif->ndev, "Failed to send scan parameters\n");
0785 return result;
0786 }
0787
0788 if (stats->link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH &&
0789 stats->link_speed != DEFAULT_LINK_SPEED)
0790 wilc_enable_tcp_ack_filter(vif, true);
0791 else if (stats->link_speed != DEFAULT_LINK_SPEED)
0792 wilc_enable_tcp_ack_filter(vif, false);
0793
0794 return result;
0795 }
0796
0797 static void handle_get_statistics(struct work_struct *work)
0798 {
0799 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
0800 struct wilc_vif *vif = msg->vif;
0801 struct rf_info *stats = (struct rf_info *)msg->body.data;
0802
0803 wilc_get_statistics(vif, stats);
0804
0805 kfree(msg);
0806 }
0807
0808 static void wilc_hif_pack_sta_param(u8 *cur_byte, const u8 *mac,
0809 struct station_parameters *params)
0810 {
0811 ether_addr_copy(cur_byte, mac);
0812 cur_byte += ETH_ALEN;
0813
0814 put_unaligned_le16(params->aid, cur_byte);
0815 cur_byte += 2;
0816
0817 *cur_byte++ = params->link_sta_params.supported_rates_len;
0818 if (params->link_sta_params.supported_rates_len > 0)
0819 memcpy(cur_byte, params->link_sta_params.supported_rates,
0820 params->link_sta_params.supported_rates_len);
0821 cur_byte += params->link_sta_params.supported_rates_len;
0822
0823 if (params->link_sta_params.ht_capa) {
0824 *cur_byte++ = true;
0825 memcpy(cur_byte, params->link_sta_params.ht_capa,
0826 sizeof(struct ieee80211_ht_cap));
0827 } else {
0828 *cur_byte++ = false;
0829 }
0830 cur_byte += sizeof(struct ieee80211_ht_cap);
0831
0832 put_unaligned_le16(params->sta_flags_mask, cur_byte);
0833 cur_byte += 2;
0834 put_unaligned_le16(params->sta_flags_set, cur_byte);
0835 }
0836
0837 static int handle_remain_on_chan(struct wilc_vif *vif,
0838 struct wilc_remain_ch *hif_remain_ch)
0839 {
0840 int result;
0841 u8 remain_on_chan_flag;
0842 struct wid wid;
0843 struct host_if_drv *hif_drv = vif->hif_drv;
0844
0845 if (hif_drv->usr_scan_req.scan_result)
0846 return -EBUSY;
0847
0848 if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP)
0849 return -EBUSY;
0850
0851 if (vif->connecting)
0852 return -EBUSY;
0853
0854 remain_on_chan_flag = true;
0855 wid.id = WID_REMAIN_ON_CHAN;
0856 wid.type = WID_STR;
0857 wid.size = 2;
0858 wid.val = kmalloc(wid.size, GFP_KERNEL);
0859 if (!wid.val)
0860 return -ENOMEM;
0861
0862 wid.val[0] = remain_on_chan_flag;
0863 wid.val[1] = (s8)hif_remain_ch->ch;
0864
0865 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
0866 kfree(wid.val);
0867 if (result)
0868 return -EBUSY;
0869
0870 hif_drv->remain_on_ch.arg = hif_remain_ch->arg;
0871 hif_drv->remain_on_ch.expired = hif_remain_ch->expired;
0872 hif_drv->remain_on_ch.ch = hif_remain_ch->ch;
0873 hif_drv->remain_on_ch.cookie = hif_remain_ch->cookie;
0874 hif_drv->remain_on_ch_timer_vif = vif;
0875
0876 return 0;
0877 }
0878
0879 static int wilc_handle_roc_expired(struct wilc_vif *vif, u64 cookie)
0880 {
0881 u8 remain_on_chan_flag;
0882 struct wid wid;
0883 int result;
0884 struct host_if_drv *hif_drv = vif->hif_drv;
0885
0886 if (vif->priv.p2p_listen_state) {
0887 remain_on_chan_flag = false;
0888 wid.id = WID_REMAIN_ON_CHAN;
0889 wid.type = WID_STR;
0890 wid.size = 2;
0891
0892 wid.val = kmalloc(wid.size, GFP_KERNEL);
0893 if (!wid.val)
0894 return -ENOMEM;
0895
0896 wid.val[0] = remain_on_chan_flag;
0897 wid.val[1] = WILC_FALSE_FRMWR_CHANNEL;
0898
0899 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
0900 kfree(wid.val);
0901 if (result != 0) {
0902 netdev_err(vif->ndev, "Failed to set remain channel\n");
0903 return -EINVAL;
0904 }
0905
0906 if (hif_drv->remain_on_ch.expired) {
0907 hif_drv->remain_on_ch.expired(hif_drv->remain_on_ch.arg,
0908 cookie);
0909 }
0910 } else {
0911 netdev_dbg(vif->ndev, "Not in listen state\n");
0912 }
0913
0914 return 0;
0915 }
0916
0917 static void wilc_handle_listen_state_expired(struct work_struct *work)
0918 {
0919 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
0920
0921 wilc_handle_roc_expired(msg->vif, msg->body.remain_on_ch.cookie);
0922 kfree(msg);
0923 }
0924
0925 static void listen_timer_cb(struct timer_list *t)
0926 {
0927 struct host_if_drv *hif_drv = from_timer(hif_drv, t,
0928 remain_on_ch_timer);
0929 struct wilc_vif *vif = hif_drv->remain_on_ch_timer_vif;
0930 int result;
0931 struct host_if_msg *msg;
0932
0933 del_timer(&vif->hif_drv->remain_on_ch_timer);
0934
0935 msg = wilc_alloc_work(vif, wilc_handle_listen_state_expired, false);
0936 if (IS_ERR(msg))
0937 return;
0938
0939 msg->body.remain_on_ch.cookie = vif->hif_drv->remain_on_ch.cookie;
0940
0941 result = wilc_enqueue_work(msg);
0942 if (result) {
0943 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
0944 kfree(msg);
0945 }
0946 }
0947
0948 static void handle_set_mcast_filter(struct work_struct *work)
0949 {
0950 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
0951 struct wilc_vif *vif = msg->vif;
0952 struct wilc_set_multicast *set_mc = &msg->body.mc_info;
0953 int result;
0954 struct wid wid;
0955 u8 *cur_byte;
0956
0957 wid.id = WID_SETUP_MULTICAST_FILTER;
0958 wid.type = WID_BIN;
0959 wid.size = sizeof(struct wilc_set_multicast) + (set_mc->cnt * ETH_ALEN);
0960 wid.val = kmalloc(wid.size, GFP_KERNEL);
0961 if (!wid.val)
0962 goto error;
0963
0964 cur_byte = wid.val;
0965 put_unaligned_le32(set_mc->enabled, cur_byte);
0966 cur_byte += 4;
0967
0968 put_unaligned_le32(set_mc->cnt, cur_byte);
0969 cur_byte += 4;
0970
0971 if (set_mc->cnt > 0 && set_mc->mc_list)
0972 memcpy(cur_byte, set_mc->mc_list, set_mc->cnt * ETH_ALEN);
0973
0974 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
0975 if (result)
0976 netdev_err(vif->ndev, "Failed to send setup multicast\n");
0977
0978 error:
0979 kfree(set_mc->mc_list);
0980 kfree(wid.val);
0981 kfree(msg);
0982 }
0983
0984 void wilc_set_wowlan_trigger(struct wilc_vif *vif, bool enabled)
0985 {
0986 int ret;
0987 struct wid wid;
0988 u8 wowlan_trigger = 0;
0989
0990 if (enabled)
0991 wowlan_trigger = 1;
0992
0993 wid.id = WID_WOWLAN_TRIGGER;
0994 wid.type = WID_CHAR;
0995 wid.val = &wowlan_trigger;
0996 wid.size = sizeof(char);
0997
0998 ret = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
0999 if (ret)
1000 pr_err("Failed to send wowlan trigger config packet\n");
1001 }
1002
1003 int wilc_set_external_auth_param(struct wilc_vif *vif,
1004 struct cfg80211_external_auth_params *auth)
1005 {
1006 int ret;
1007 struct wid wid;
1008 struct wilc_external_auth_param *param;
1009
1010 wid.id = WID_EXTERNAL_AUTH_PARAM;
1011 wid.type = WID_BIN_DATA;
1012 wid.size = sizeof(*param);
1013 param = kzalloc(sizeof(*param), GFP_KERNEL);
1014 if (!param)
1015 return -EINVAL;
1016
1017 wid.val = (u8 *)param;
1018 param->action = auth->action;
1019 ether_addr_copy(param->bssid, auth->bssid);
1020 memcpy(param->ssid, auth->ssid.ssid, auth->ssid.ssid_len);
1021 param->ssid_len = auth->ssid.ssid_len;
1022 ret = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1023
1024 kfree(param);
1025 return ret;
1026 }
1027
1028 static void handle_scan_timer(struct work_struct *work)
1029 {
1030 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
1031
1032 handle_scan_done(msg->vif, SCAN_EVENT_ABORTED);
1033 kfree(msg);
1034 }
1035
1036 static void handle_scan_complete(struct work_struct *work)
1037 {
1038 struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
1039
1040 del_timer(&msg->vif->hif_drv->scan_timer);
1041
1042 handle_scan_done(msg->vif, SCAN_EVENT_DONE);
1043
1044 kfree(msg);
1045 }
1046
1047 static void timer_scan_cb(struct timer_list *t)
1048 {
1049 struct host_if_drv *hif_drv = from_timer(hif_drv, t, scan_timer);
1050 struct wilc_vif *vif = hif_drv->scan_timer_vif;
1051 struct host_if_msg *msg;
1052 int result;
1053
1054 msg = wilc_alloc_work(vif, handle_scan_timer, false);
1055 if (IS_ERR(msg))
1056 return;
1057
1058 result = wilc_enqueue_work(msg);
1059 if (result)
1060 kfree(msg);
1061 }
1062
1063 static void timer_connect_cb(struct timer_list *t)
1064 {
1065 struct host_if_drv *hif_drv = from_timer(hif_drv, t,
1066 connect_timer);
1067 struct wilc_vif *vif = hif_drv->connect_timer_vif;
1068 struct host_if_msg *msg;
1069 int result;
1070
1071 msg = wilc_alloc_work(vif, handle_connect_timeout, false);
1072 if (IS_ERR(msg))
1073 return;
1074
1075 result = wilc_enqueue_work(msg);
1076 if (result)
1077 kfree(msg);
1078 }
1079
1080 int wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len,
1081 const u8 *mac_addr, const u8 *rx_mic, const u8 *tx_mic,
1082 u8 mode, u8 cipher_mode, u8 index)
1083 {
1084 int result = 0;
1085 u8 t_key_len = ptk_key_len + WILC_RX_MIC_KEY_LEN + WILC_TX_MIC_KEY_LEN;
1086
1087 if (mode == WILC_AP_MODE) {
1088 struct wid wid_list[2];
1089 struct wilc_ap_wpa_ptk *key_buf;
1090
1091 wid_list[0].id = WID_11I_MODE;
1092 wid_list[0].type = WID_CHAR;
1093 wid_list[0].size = sizeof(char);
1094 wid_list[0].val = (s8 *)&cipher_mode;
1095
1096 key_buf = kzalloc(sizeof(*key_buf) + t_key_len, GFP_KERNEL);
1097 if (!key_buf)
1098 return -ENOMEM;
1099
1100 ether_addr_copy(key_buf->mac_addr, mac_addr);
1101 key_buf->index = index;
1102 key_buf->key_len = t_key_len;
1103 memcpy(&key_buf->key[0], ptk, ptk_key_len);
1104
1105 if (rx_mic)
1106 memcpy(&key_buf->key[ptk_key_len], rx_mic,
1107 WILC_RX_MIC_KEY_LEN);
1108
1109 if (tx_mic)
1110 memcpy(&key_buf->key[ptk_key_len + WILC_RX_MIC_KEY_LEN],
1111 tx_mic, WILC_TX_MIC_KEY_LEN);
1112
1113 wid_list[1].id = WID_ADD_PTK;
1114 wid_list[1].type = WID_STR;
1115 wid_list[1].size = sizeof(*key_buf) + t_key_len;
1116 wid_list[1].val = (u8 *)key_buf;
1117 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
1118 ARRAY_SIZE(wid_list));
1119 kfree(key_buf);
1120 } else if (mode == WILC_STATION_MODE) {
1121 struct wid wid;
1122 struct wilc_sta_wpa_ptk *key_buf;
1123
1124 key_buf = kzalloc(sizeof(*key_buf) + t_key_len, GFP_KERNEL);
1125 if (!key_buf)
1126 return -ENOMEM;
1127
1128 ether_addr_copy(key_buf->mac_addr, mac_addr);
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.id = WID_ADD_PTK;
1141 wid.type = WID_STR;
1142 wid.size = sizeof(*key_buf) + t_key_len;
1143 wid.val = (s8 *)key_buf;
1144 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1145 kfree(key_buf);
1146 }
1147
1148 return result;
1149 }
1150
1151 int wilc_add_igtk(struct wilc_vif *vif, const u8 *igtk, u8 igtk_key_len,
1152 const u8 *pn, u8 pn_len, const u8 *mac_addr, u8 mode, u8 index)
1153 {
1154 int result = 0;
1155 u8 t_key_len = igtk_key_len;
1156 struct wid wid;
1157 struct wilc_wpa_igtk *key_buf;
1158
1159 key_buf = kzalloc(sizeof(*key_buf) + t_key_len, GFP_KERNEL);
1160 if (!key_buf)
1161 return -ENOMEM;
1162
1163 key_buf->index = index;
1164
1165 memcpy(&key_buf->pn[0], pn, pn_len);
1166 key_buf->pn_len = pn_len;
1167
1168 memcpy(&key_buf->key[0], igtk, igtk_key_len);
1169 key_buf->key_len = t_key_len;
1170
1171 wid.id = WID_ADD_IGTK;
1172 wid.type = WID_STR;
1173 wid.size = sizeof(*key_buf) + t_key_len;
1174 wid.val = (s8 *)key_buf;
1175 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1176 kfree(key_buf);
1177
1178 return result;
1179 }
1180
1181 int wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len,
1182 u8 index, u32 key_rsc_len, const u8 *key_rsc,
1183 const u8 *rx_mic, const u8 *tx_mic, u8 mode,
1184 u8 cipher_mode)
1185 {
1186 int result = 0;
1187 struct wilc_gtk_key *gtk_key;
1188 int t_key_len = gtk_key_len + WILC_RX_MIC_KEY_LEN + WILC_TX_MIC_KEY_LEN;
1189
1190 gtk_key = kzalloc(sizeof(*gtk_key) + t_key_len, GFP_KERNEL);
1191 if (!gtk_key)
1192 return -ENOMEM;
1193
1194
1195 if (mode == WILC_STATION_MODE &&
1196 vif->hif_drv->hif_state == HOST_IF_CONNECTED)
1197 memcpy(gtk_key->mac_addr, vif->hif_drv->assoc_bssid, ETH_ALEN);
1198
1199 if (key_rsc)
1200 memcpy(gtk_key->rsc, key_rsc, 8);
1201 gtk_key->index = index;
1202 gtk_key->key_len = t_key_len;
1203 memcpy(>k_key->key[0], rx_gtk, gtk_key_len);
1204
1205 if (rx_mic)
1206 memcpy(>k_key->key[gtk_key_len], rx_mic, WILC_RX_MIC_KEY_LEN);
1207
1208 if (tx_mic)
1209 memcpy(>k_key->key[gtk_key_len + WILC_RX_MIC_KEY_LEN],
1210 tx_mic, WILC_TX_MIC_KEY_LEN);
1211
1212 if (mode == WILC_AP_MODE) {
1213 struct wid wid_list[2];
1214
1215 wid_list[0].id = WID_11I_MODE;
1216 wid_list[0].type = WID_CHAR;
1217 wid_list[0].size = sizeof(char);
1218 wid_list[0].val = (s8 *)&cipher_mode;
1219
1220 wid_list[1].id = WID_ADD_RX_GTK;
1221 wid_list[1].type = WID_STR;
1222 wid_list[1].size = sizeof(*gtk_key) + t_key_len;
1223 wid_list[1].val = (u8 *)gtk_key;
1224
1225 result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
1226 ARRAY_SIZE(wid_list));
1227 } else if (mode == WILC_STATION_MODE) {
1228 struct wid wid;
1229
1230 wid.id = WID_ADD_RX_GTK;
1231 wid.type = WID_STR;
1232 wid.size = sizeof(*gtk_key) + t_key_len;
1233 wid.val = (u8 *)gtk_key;
1234 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1235 }
1236
1237 kfree(gtk_key);
1238 return result;
1239 }
1240
1241 int wilc_set_pmkid_info(struct wilc_vif *vif, struct wilc_pmkid_attr *pmkid)
1242 {
1243 struct wid wid;
1244
1245 wid.id = WID_PMKID_INFO;
1246 wid.type = WID_STR;
1247 wid.size = (pmkid->numpmkid * sizeof(struct wilc_pmkid)) + 1;
1248 wid.val = (u8 *)pmkid;
1249
1250 return wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1251 }
1252
1253 int wilc_get_mac_address(struct wilc_vif *vif, u8 *mac_addr)
1254 {
1255 int result;
1256 struct wid wid;
1257
1258 wid.id = WID_MAC_ADDR;
1259 wid.type = WID_STR;
1260 wid.size = ETH_ALEN;
1261 wid.val = mac_addr;
1262
1263 result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
1264 if (result)
1265 netdev_err(vif->ndev, "Failed to get mac address\n");
1266
1267 return result;
1268 }
1269
1270 int wilc_set_mac_address(struct wilc_vif *vif, u8 *mac_addr)
1271 {
1272 struct wid wid;
1273 int result;
1274
1275 wid.id = WID_MAC_ADDR;
1276 wid.type = WID_STR;
1277 wid.size = ETH_ALEN;
1278 wid.val = mac_addr;
1279
1280 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1281 if (result)
1282 netdev_err(vif->ndev, "Failed to set mac address\n");
1283
1284 return result;
1285 }
1286
1287 int wilc_set_join_req(struct wilc_vif *vif, u8 *bssid, const u8 *ies,
1288 size_t ies_len)
1289 {
1290 int result;
1291 struct host_if_drv *hif_drv = vif->hif_drv;
1292 struct wilc_conn_info *conn_info = &hif_drv->conn_info;
1293
1294 if (bssid)
1295 ether_addr_copy(conn_info->bssid, bssid);
1296
1297 if (ies) {
1298 conn_info->req_ies_len = ies_len;
1299 conn_info->req_ies = kmemdup(ies, ies_len, GFP_KERNEL);
1300 if (!conn_info->req_ies)
1301 return -ENOMEM;
1302 }
1303
1304 result = wilc_send_connect_wid(vif);
1305 if (result)
1306 goto free_ies;
1307
1308 hif_drv->connect_timer_vif = vif;
1309 mod_timer(&hif_drv->connect_timer,
1310 jiffies + msecs_to_jiffies(WILC_HIF_CONNECT_TIMEOUT_MS));
1311
1312 return 0;
1313
1314 free_ies:
1315 kfree(conn_info->req_ies);
1316
1317 return result;
1318 }
1319
1320 int wilc_set_mac_chnl_num(struct wilc_vif *vif, u8 channel)
1321 {
1322 struct wid wid;
1323 int result;
1324
1325 wid.id = WID_CURRENT_CHANNEL;
1326 wid.type = WID_CHAR;
1327 wid.size = sizeof(char);
1328 wid.val = &channel;
1329
1330 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1331 if (result)
1332 netdev_err(vif->ndev, "Failed to set channel\n");
1333
1334 return result;
1335 }
1336
1337 int wilc_set_operation_mode(struct wilc_vif *vif, int index, u8 mode,
1338 u8 ifc_id)
1339 {
1340 struct wid wid;
1341 int result;
1342 struct wilc_drv_handler drv;
1343
1344 wid.id = WID_SET_OPERATION_MODE;
1345 wid.type = WID_STR;
1346 wid.size = sizeof(drv);
1347 wid.val = (u8 *)&drv;
1348
1349 drv.handler = cpu_to_le32(index);
1350 drv.mode = (ifc_id | (mode << 1));
1351
1352 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1353 if (result)
1354 netdev_err(vif->ndev, "Failed to set driver handler\n");
1355
1356 return result;
1357 }
1358
1359 s32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac, u32 *out_val)
1360 {
1361 struct wid wid;
1362 s32 result;
1363
1364 wid.id = WID_SET_STA_MAC_INACTIVE_TIME;
1365 wid.type = WID_STR;
1366 wid.size = ETH_ALEN;
1367 wid.val = kzalloc(wid.size, GFP_KERNEL);
1368 if (!wid.val)
1369 return -ENOMEM;
1370
1371 ether_addr_copy(wid.val, mac);
1372 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1373 kfree(wid.val);
1374 if (result) {
1375 netdev_err(vif->ndev, "Failed to set inactive mac\n");
1376 return result;
1377 }
1378
1379 wid.id = WID_GET_INACTIVE_TIME;
1380 wid.type = WID_INT;
1381 wid.val = (s8 *)out_val;
1382 wid.size = sizeof(u32);
1383 result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
1384 if (result)
1385 netdev_err(vif->ndev, "Failed to get inactive time\n");
1386
1387 return result;
1388 }
1389
1390 int wilc_get_rssi(struct wilc_vif *vif, s8 *rssi_level)
1391 {
1392 struct wid wid;
1393 int result;
1394
1395 if (!rssi_level) {
1396 netdev_err(vif->ndev, "%s: RSSI level is NULL\n", __func__);
1397 return -EFAULT;
1398 }
1399
1400 wid.id = WID_RSSI;
1401 wid.type = WID_CHAR;
1402 wid.size = sizeof(char);
1403 wid.val = rssi_level;
1404 result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
1405 if (result)
1406 netdev_err(vif->ndev, "Failed to get RSSI value\n");
1407
1408 return result;
1409 }
1410
1411 static int wilc_get_stats_async(struct wilc_vif *vif, struct rf_info *stats)
1412 {
1413 int result;
1414 struct host_if_msg *msg;
1415
1416 msg = wilc_alloc_work(vif, handle_get_statistics, false);
1417 if (IS_ERR(msg))
1418 return PTR_ERR(msg);
1419
1420 msg->body.data = (char *)stats;
1421
1422 result = wilc_enqueue_work(msg);
1423 if (result) {
1424 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
1425 kfree(msg);
1426 return result;
1427 }
1428
1429 return result;
1430 }
1431
1432 int wilc_hif_set_cfg(struct wilc_vif *vif, struct cfg_param_attr *param)
1433 {
1434 struct wid wid_list[4];
1435 int i = 0;
1436
1437 if (param->flag & WILC_CFG_PARAM_RETRY_SHORT) {
1438 wid_list[i].id = WID_SHORT_RETRY_LIMIT;
1439 wid_list[i].val = (s8 *)¶m->short_retry_limit;
1440 wid_list[i].type = WID_SHORT;
1441 wid_list[i].size = sizeof(u16);
1442 i++;
1443 }
1444 if (param->flag & WILC_CFG_PARAM_RETRY_LONG) {
1445 wid_list[i].id = WID_LONG_RETRY_LIMIT;
1446 wid_list[i].val = (s8 *)¶m->long_retry_limit;
1447 wid_list[i].type = WID_SHORT;
1448 wid_list[i].size = sizeof(u16);
1449 i++;
1450 }
1451 if (param->flag & WILC_CFG_PARAM_FRAG_THRESHOLD) {
1452 wid_list[i].id = WID_FRAG_THRESHOLD;
1453 wid_list[i].val = (s8 *)¶m->frag_threshold;
1454 wid_list[i].type = WID_SHORT;
1455 wid_list[i].size = sizeof(u16);
1456 i++;
1457 }
1458 if (param->flag & WILC_CFG_PARAM_RTS_THRESHOLD) {
1459 wid_list[i].id = WID_RTS_THRESHOLD;
1460 wid_list[i].val = (s8 *)¶m->rts_threshold;
1461 wid_list[i].type = WID_SHORT;
1462 wid_list[i].size = sizeof(u16);
1463 i++;
1464 }
1465
1466 return wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, i);
1467 }
1468
1469 static void get_periodic_rssi(struct timer_list *t)
1470 {
1471 struct wilc_vif *vif = from_timer(vif, t, periodic_rssi);
1472
1473 if (!vif->hif_drv) {
1474 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
1475 return;
1476 }
1477
1478 if (vif->hif_drv->hif_state == HOST_IF_CONNECTED)
1479 wilc_get_stats_async(vif, &vif->periodic_stat);
1480
1481 mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000));
1482 }
1483
1484 int wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
1485 {
1486 struct host_if_drv *hif_drv;
1487 struct wilc_vif *vif = netdev_priv(dev);
1488
1489 hif_drv = kzalloc(sizeof(*hif_drv), GFP_KERNEL);
1490 if (!hif_drv)
1491 return -ENOMEM;
1492
1493 *hif_drv_handler = hif_drv;
1494
1495 vif->hif_drv = hif_drv;
1496
1497 timer_setup(&vif->periodic_rssi, get_periodic_rssi, 0);
1498 mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000));
1499
1500 timer_setup(&hif_drv->scan_timer, timer_scan_cb, 0);
1501 timer_setup(&hif_drv->connect_timer, timer_connect_cb, 0);
1502 timer_setup(&hif_drv->remain_on_ch_timer, listen_timer_cb, 0);
1503
1504 hif_drv->hif_state = HOST_IF_IDLE;
1505
1506 hif_drv->p2p_timeout = 0;
1507
1508 return 0;
1509 }
1510
1511 int wilc_deinit(struct wilc_vif *vif)
1512 {
1513 int result = 0;
1514 struct host_if_drv *hif_drv = vif->hif_drv;
1515
1516 if (!hif_drv) {
1517 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
1518 return -EFAULT;
1519 }
1520
1521 mutex_lock(&vif->wilc->deinit_lock);
1522
1523 del_timer_sync(&hif_drv->scan_timer);
1524 del_timer_sync(&hif_drv->connect_timer);
1525 del_timer_sync(&vif->periodic_rssi);
1526 del_timer_sync(&hif_drv->remain_on_ch_timer);
1527
1528 if (hif_drv->usr_scan_req.scan_result) {
1529 hif_drv->usr_scan_req.scan_result(SCAN_EVENT_ABORTED, NULL,
1530 hif_drv->usr_scan_req.arg);
1531 hif_drv->usr_scan_req.scan_result = NULL;
1532 }
1533
1534 hif_drv->hif_state = HOST_IF_IDLE;
1535
1536 kfree(hif_drv);
1537 vif->hif_drv = NULL;
1538 mutex_unlock(&vif->wilc->deinit_lock);
1539 return result;
1540 }
1541
1542 void wilc_network_info_received(struct wilc *wilc, u8 *buffer, u32 length)
1543 {
1544 int result;
1545 struct host_if_msg *msg;
1546 int id;
1547 struct host_if_drv *hif_drv;
1548 struct wilc_vif *vif;
1549
1550 id = get_unaligned_le32(&buffer[length - 4]);
1551 vif = wilc_get_vif_from_idx(wilc, id);
1552 if (!vif)
1553 return;
1554 hif_drv = vif->hif_drv;
1555
1556 if (!hif_drv) {
1557 netdev_err(vif->ndev, "driver not init[%p]\n", hif_drv);
1558 return;
1559 }
1560
1561 msg = wilc_alloc_work(vif, handle_rcvd_ntwrk_info, false);
1562 if (IS_ERR(msg))
1563 return;
1564
1565 msg->body.net_info.frame_len = get_unaligned_le16(&buffer[6]) - 1;
1566 msg->body.net_info.rssi = buffer[8];
1567 msg->body.net_info.mgmt = kmemdup(&buffer[9],
1568 msg->body.net_info.frame_len,
1569 GFP_KERNEL);
1570 if (!msg->body.net_info.mgmt) {
1571 kfree(msg);
1572 return;
1573 }
1574
1575 result = wilc_enqueue_work(msg);
1576 if (result) {
1577 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
1578 kfree(msg->body.net_info.mgmt);
1579 kfree(msg);
1580 }
1581 }
1582
1583 void wilc_gnrl_async_info_received(struct wilc *wilc, u8 *buffer, u32 length)
1584 {
1585 int result;
1586 struct host_if_msg *msg;
1587 int id;
1588 struct host_if_drv *hif_drv;
1589 struct wilc_vif *vif;
1590
1591 mutex_lock(&wilc->deinit_lock);
1592
1593 id = get_unaligned_le32(&buffer[length - 4]);
1594 vif = wilc_get_vif_from_idx(wilc, id);
1595 if (!vif) {
1596 mutex_unlock(&wilc->deinit_lock);
1597 return;
1598 }
1599
1600 hif_drv = vif->hif_drv;
1601
1602 if (!hif_drv) {
1603 mutex_unlock(&wilc->deinit_lock);
1604 return;
1605 }
1606
1607 if (!hif_drv->conn_info.conn_result) {
1608 netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
1609 mutex_unlock(&wilc->deinit_lock);
1610 return;
1611 }
1612
1613 msg = wilc_alloc_work(vif, handle_rcvd_gnrl_async_info, false);
1614 if (IS_ERR(msg)) {
1615 mutex_unlock(&wilc->deinit_lock);
1616 return;
1617 }
1618
1619 msg->body.mac_info.status = buffer[7];
1620 result = wilc_enqueue_work(msg);
1621 if (result) {
1622 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
1623 kfree(msg);
1624 }
1625
1626 mutex_unlock(&wilc->deinit_lock);
1627 }
1628
1629 void wilc_scan_complete_received(struct wilc *wilc, u8 *buffer, u32 length)
1630 {
1631 int result;
1632 int id;
1633 struct host_if_drv *hif_drv;
1634 struct wilc_vif *vif;
1635
1636 id = get_unaligned_le32(&buffer[length - 4]);
1637 vif = wilc_get_vif_from_idx(wilc, id);
1638 if (!vif)
1639 return;
1640 hif_drv = vif->hif_drv;
1641
1642 if (!hif_drv)
1643 return;
1644
1645 if (hif_drv->usr_scan_req.scan_result) {
1646 struct host_if_msg *msg;
1647
1648 msg = wilc_alloc_work(vif, handle_scan_complete, false);
1649 if (IS_ERR(msg))
1650 return;
1651
1652 result = wilc_enqueue_work(msg);
1653 if (result) {
1654 netdev_err(vif->ndev, "%s: enqueue work failed\n",
1655 __func__);
1656 kfree(msg);
1657 }
1658 }
1659 }
1660
1661 int wilc_remain_on_channel(struct wilc_vif *vif, u64 cookie,
1662 u32 duration, u16 chan,
1663 void (*expired)(void *, u64),
1664 void *user_arg)
1665 {
1666 struct wilc_remain_ch roc;
1667 int result;
1668
1669 roc.ch = chan;
1670 roc.expired = expired;
1671 roc.arg = user_arg;
1672 roc.duration = duration;
1673 roc.cookie = cookie;
1674 result = handle_remain_on_chan(vif, &roc);
1675 if (result)
1676 netdev_err(vif->ndev, "%s: failed to set remain on channel\n",
1677 __func__);
1678
1679 return result;
1680 }
1681
1682 int wilc_listen_state_expired(struct wilc_vif *vif, u64 cookie)
1683 {
1684 if (!vif->hif_drv) {
1685 netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
1686 return -EFAULT;
1687 }
1688
1689 del_timer(&vif->hif_drv->remain_on_ch_timer);
1690
1691 return wilc_handle_roc_expired(vif, cookie);
1692 }
1693
1694 void wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg)
1695 {
1696 struct wid wid;
1697 int result;
1698 struct wilc_reg_frame reg_frame;
1699
1700 wid.id = WID_REGISTER_FRAME;
1701 wid.type = WID_STR;
1702 wid.size = sizeof(reg_frame);
1703 wid.val = (u8 *)®_frame;
1704
1705 memset(®_frame, 0x0, sizeof(reg_frame));
1706
1707 if (reg)
1708 reg_frame.reg = 1;
1709
1710 switch (frame_type) {
1711 case IEEE80211_STYPE_ACTION:
1712 reg_frame.reg_id = WILC_FW_ACTION_FRM_IDX;
1713 break;
1714
1715 case IEEE80211_STYPE_PROBE_REQ:
1716 reg_frame.reg_id = WILC_FW_PROBE_REQ_IDX;
1717 break;
1718
1719 case IEEE80211_STYPE_AUTH:
1720 reg_frame.reg_id = WILC_FW_AUTH_REQ_IDX;
1721 break;
1722
1723 default:
1724 break;
1725 }
1726 reg_frame.frame_type = cpu_to_le16(frame_type);
1727 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1728 if (result)
1729 netdev_err(vif->ndev, "Failed to frame register\n");
1730 }
1731
1732 int wilc_add_beacon(struct wilc_vif *vif, u32 interval, u32 dtim_period,
1733 struct cfg80211_beacon_data *params)
1734 {
1735 struct wid wid;
1736 int result;
1737 u8 *cur_byte;
1738
1739 wid.id = WID_ADD_BEACON;
1740 wid.type = WID_BIN;
1741 wid.size = params->head_len + params->tail_len + 16;
1742 wid.val = kzalloc(wid.size, GFP_KERNEL);
1743 if (!wid.val)
1744 return -ENOMEM;
1745
1746 cur_byte = wid.val;
1747 put_unaligned_le32(interval, cur_byte);
1748 cur_byte += 4;
1749 put_unaligned_le32(dtim_period, cur_byte);
1750 cur_byte += 4;
1751 put_unaligned_le32(params->head_len, cur_byte);
1752 cur_byte += 4;
1753
1754 if (params->head_len > 0)
1755 memcpy(cur_byte, params->head, params->head_len);
1756 cur_byte += params->head_len;
1757
1758 put_unaligned_le32(params->tail_len, cur_byte);
1759 cur_byte += 4;
1760
1761 if (params->tail_len > 0)
1762 memcpy(cur_byte, params->tail, params->tail_len);
1763
1764 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1765 if (result)
1766 netdev_err(vif->ndev, "Failed to send add beacon\n");
1767
1768 kfree(wid.val);
1769
1770 return result;
1771 }
1772
1773 int wilc_del_beacon(struct wilc_vif *vif)
1774 {
1775 int result;
1776 struct wid wid;
1777 u8 del_beacon = 0;
1778
1779 wid.id = WID_DEL_BEACON;
1780 wid.type = WID_CHAR;
1781 wid.size = sizeof(char);
1782 wid.val = &del_beacon;
1783
1784 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1785 if (result)
1786 netdev_err(vif->ndev, "Failed to send delete beacon\n");
1787
1788 return result;
1789 }
1790
1791 int wilc_add_station(struct wilc_vif *vif, const u8 *mac,
1792 struct station_parameters *params)
1793 {
1794 struct wid wid;
1795 int result;
1796 u8 *cur_byte;
1797
1798 wid.id = WID_ADD_STA;
1799 wid.type = WID_BIN;
1800 wid.size = WILC_ADD_STA_LENGTH +
1801 params->link_sta_params.supported_rates_len;
1802 wid.val = kmalloc(wid.size, GFP_KERNEL);
1803 if (!wid.val)
1804 return -ENOMEM;
1805
1806 cur_byte = wid.val;
1807 wilc_hif_pack_sta_param(cur_byte, mac, params);
1808
1809 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1810 if (result != 0)
1811 netdev_err(vif->ndev, "Failed to send add station\n");
1812
1813 kfree(wid.val);
1814
1815 return result;
1816 }
1817
1818 int wilc_del_station(struct wilc_vif *vif, const u8 *mac_addr)
1819 {
1820 struct wid wid;
1821 int result;
1822
1823 wid.id = WID_REMOVE_STA;
1824 wid.type = WID_BIN;
1825 wid.size = ETH_ALEN;
1826 wid.val = kzalloc(wid.size, GFP_KERNEL);
1827 if (!wid.val)
1828 return -ENOMEM;
1829
1830 if (!mac_addr)
1831 eth_broadcast_addr(wid.val);
1832 else
1833 ether_addr_copy(wid.val, mac_addr);
1834
1835 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1836 if (result)
1837 netdev_err(vif->ndev, "Failed to del station\n");
1838
1839 kfree(wid.val);
1840
1841 return result;
1842 }
1843
1844 int wilc_del_allstation(struct wilc_vif *vif, u8 mac_addr[][ETH_ALEN])
1845 {
1846 struct wid wid;
1847 int result;
1848 int i;
1849 u8 assoc_sta = 0;
1850 struct wilc_del_all_sta del_sta;
1851
1852 memset(&del_sta, 0x0, sizeof(del_sta));
1853 for (i = 0; i < WILC_MAX_NUM_STA; i++) {
1854 if (!is_zero_ether_addr(mac_addr[i])) {
1855 assoc_sta++;
1856 ether_addr_copy(del_sta.mac[i], mac_addr[i]);
1857 }
1858 }
1859
1860 if (!assoc_sta)
1861 return 0;
1862
1863 del_sta.assoc_sta = assoc_sta;
1864
1865 wid.id = WID_DEL_ALL_STA;
1866 wid.type = WID_STR;
1867 wid.size = (assoc_sta * ETH_ALEN) + 1;
1868 wid.val = (u8 *)&del_sta;
1869
1870 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1871 if (result)
1872 netdev_err(vif->ndev, "Failed to send delete all station\n");
1873
1874 return result;
1875 }
1876
1877 int wilc_edit_station(struct wilc_vif *vif, const u8 *mac,
1878 struct station_parameters *params)
1879 {
1880 struct wid wid;
1881 int result;
1882 u8 *cur_byte;
1883
1884 wid.id = WID_EDIT_STA;
1885 wid.type = WID_BIN;
1886 wid.size = WILC_ADD_STA_LENGTH +
1887 params->link_sta_params.supported_rates_len;
1888 wid.val = kmalloc(wid.size, GFP_KERNEL);
1889 if (!wid.val)
1890 return -ENOMEM;
1891
1892 cur_byte = wid.val;
1893 wilc_hif_pack_sta_param(cur_byte, mac, params);
1894
1895 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1896 if (result)
1897 netdev_err(vif->ndev, "Failed to send edit station\n");
1898
1899 kfree(wid.val);
1900 return result;
1901 }
1902
1903 int wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout)
1904 {
1905 struct wilc *wilc = vif->wilc;
1906 struct wid wid;
1907 int result;
1908 s8 power_mode;
1909
1910 if (enabled)
1911 power_mode = WILC_FW_MIN_FAST_PS;
1912 else
1913 power_mode = WILC_FW_NO_POWERSAVE;
1914
1915 wid.id = WID_POWER_MANAGEMENT;
1916 wid.val = &power_mode;
1917 wid.size = sizeof(char);
1918 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1919 if (result)
1920 netdev_err(vif->ndev, "Failed to send power management\n");
1921 else
1922 wilc->power_save_mode = enabled;
1923
1924 return result;
1925 }
1926
1927 int wilc_setup_multicast_filter(struct wilc_vif *vif, u32 enabled, u32 count,
1928 u8 *mc_list)
1929 {
1930 int result;
1931 struct host_if_msg *msg;
1932
1933 msg = wilc_alloc_work(vif, handle_set_mcast_filter, false);
1934 if (IS_ERR(msg))
1935 return PTR_ERR(msg);
1936
1937 msg->body.mc_info.enabled = enabled;
1938 msg->body.mc_info.cnt = count;
1939 msg->body.mc_info.mc_list = mc_list;
1940
1941 result = wilc_enqueue_work(msg);
1942 if (result) {
1943 netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
1944 kfree(msg);
1945 }
1946 return result;
1947 }
1948
1949 int wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power)
1950 {
1951 struct wid wid;
1952
1953 wid.id = WID_TX_POWER;
1954 wid.type = WID_CHAR;
1955 wid.val = &tx_power;
1956 wid.size = sizeof(char);
1957
1958 return wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1959 }
1960
1961 int wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power)
1962 {
1963 struct wid wid;
1964
1965 wid.id = WID_TX_POWER;
1966 wid.type = WID_CHAR;
1967 wid.val = tx_power;
1968 wid.size = sizeof(char);
1969
1970 return wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
1971 }
1972
1973 int wilc_set_default_mgmt_key_index(struct wilc_vif *vif, u8 index)
1974 {
1975 struct wid wid;
1976 int result;
1977
1978 wid.id = WID_DEFAULT_MGMT_KEY_ID;
1979 wid.type = WID_CHAR;
1980 wid.size = sizeof(char);
1981 wid.val = &index;
1982 result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1983 if (result)
1984 netdev_err(vif->ndev,
1985 "Failed to send default mgmt key index\n");
1986
1987 return result;
1988 }