18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
48c2ecf20Sopenharmony_ci * All rights reserved.
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include "netdev.h"
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#define WILC_HIF_SCAN_TIMEOUT_MS                5000
108c2ecf20Sopenharmony_ci#define WILC_HIF_CONNECT_TIMEOUT_MS             9500
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#define WILC_FALSE_FRMWR_CHANNEL		100
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#define WILC_SCAN_WID_LIST_SIZE		6
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_cistruct wilc_rcvd_mac_info {
178c2ecf20Sopenharmony_ci	u8 status;
188c2ecf20Sopenharmony_ci};
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_cistruct wilc_set_multicast {
218c2ecf20Sopenharmony_ci	u32 enabled;
228c2ecf20Sopenharmony_ci	u32 cnt;
238c2ecf20Sopenharmony_ci	u8 *mc_list;
248c2ecf20Sopenharmony_ci};
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cistruct wilc_del_all_sta {
278c2ecf20Sopenharmony_ci	u8 assoc_sta;
288c2ecf20Sopenharmony_ci	u8 mac[WILC_MAX_NUM_STA][ETH_ALEN];
298c2ecf20Sopenharmony_ci};
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ciunion wilc_message_body {
328c2ecf20Sopenharmony_ci	struct wilc_rcvd_net_info net_info;
338c2ecf20Sopenharmony_ci	struct wilc_rcvd_mac_info mac_info;
348c2ecf20Sopenharmony_ci	struct wilc_set_multicast mc_info;
358c2ecf20Sopenharmony_ci	struct wilc_remain_ch remain_on_ch;
368c2ecf20Sopenharmony_ci	char *data;
378c2ecf20Sopenharmony_ci};
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_cistruct host_if_msg {
408c2ecf20Sopenharmony_ci	union wilc_message_body body;
418c2ecf20Sopenharmony_ci	struct wilc_vif *vif;
428c2ecf20Sopenharmony_ci	struct work_struct work;
438c2ecf20Sopenharmony_ci	void (*fn)(struct work_struct *ws);
448c2ecf20Sopenharmony_ci	struct completion work_comp;
458c2ecf20Sopenharmony_ci	bool is_sync;
468c2ecf20Sopenharmony_ci};
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci/* 'msg' should be free by the caller for syc */
498c2ecf20Sopenharmony_cistatic struct host_if_msg*
508c2ecf20Sopenharmony_ciwilc_alloc_work(struct wilc_vif *vif, void (*work_fun)(struct work_struct *),
518c2ecf20Sopenharmony_ci		bool is_sync)
528c2ecf20Sopenharmony_ci{
538c2ecf20Sopenharmony_ci	struct host_if_msg *msg;
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci	if (!work_fun)
568c2ecf20Sopenharmony_ci		return ERR_PTR(-EINVAL);
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci	msg = kzalloc(sizeof(*msg), GFP_ATOMIC);
598c2ecf20Sopenharmony_ci	if (!msg)
608c2ecf20Sopenharmony_ci		return ERR_PTR(-ENOMEM);
618c2ecf20Sopenharmony_ci	msg->fn = work_fun;
628c2ecf20Sopenharmony_ci	msg->vif = vif;
638c2ecf20Sopenharmony_ci	msg->is_sync = is_sync;
648c2ecf20Sopenharmony_ci	if (is_sync)
658c2ecf20Sopenharmony_ci		init_completion(&msg->work_comp);
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci	return msg;
688c2ecf20Sopenharmony_ci}
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_cistatic int wilc_enqueue_work(struct host_if_msg *msg)
718c2ecf20Sopenharmony_ci{
728c2ecf20Sopenharmony_ci	INIT_WORK(&msg->work, msg->fn);
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	if (!msg->vif || !msg->vif->wilc || !msg->vif->wilc->hif_workqueue)
758c2ecf20Sopenharmony_ci		return -EINVAL;
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci	if (!queue_work(msg->vif->wilc->hif_workqueue, &msg->work))
788c2ecf20Sopenharmony_ci		return -EINVAL;
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci	return 0;
818c2ecf20Sopenharmony_ci}
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci/* The idx starts from 0 to (NUM_CONCURRENT_IFC - 1), but 0 index used as
848c2ecf20Sopenharmony_ci * special purpose in wilc device, so we add 1 to the index to starts from 1.
858c2ecf20Sopenharmony_ci * As a result, the returned index will be 1 to NUM_CONCURRENT_IFC.
868c2ecf20Sopenharmony_ci */
878c2ecf20Sopenharmony_ciint wilc_get_vif_idx(struct wilc_vif *vif)
888c2ecf20Sopenharmony_ci{
898c2ecf20Sopenharmony_ci	return vif->idx + 1;
908c2ecf20Sopenharmony_ci}
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci/* We need to minus 1 from idx which is from wilc device to get real index
938c2ecf20Sopenharmony_ci * of wilc->vif[], because we add 1 when pass to wilc device in the function
948c2ecf20Sopenharmony_ci * wilc_get_vif_idx.
958c2ecf20Sopenharmony_ci * As a result, the index should be between 0 and (NUM_CONCURRENT_IFC - 1).
968c2ecf20Sopenharmony_ci */
978c2ecf20Sopenharmony_cistatic struct wilc_vif *wilc_get_vif_from_idx(struct wilc *wilc, int idx)
988c2ecf20Sopenharmony_ci{
998c2ecf20Sopenharmony_ci	int index = idx - 1;
1008c2ecf20Sopenharmony_ci	struct wilc_vif *vif;
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci	if (index < 0 || index >= WILC_NUM_CONCURRENT_IFC)
1038c2ecf20Sopenharmony_ci		return NULL;
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci	list_for_each_entry_rcu(vif, &wilc->vif_list, list) {
1068c2ecf20Sopenharmony_ci		if (vif->idx == index)
1078c2ecf20Sopenharmony_ci			return vif;
1088c2ecf20Sopenharmony_ci	}
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	return NULL;
1118c2ecf20Sopenharmony_ci}
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_cistatic int handle_scan_done(struct wilc_vif *vif, enum scan_event evt)
1148c2ecf20Sopenharmony_ci{
1158c2ecf20Sopenharmony_ci	int result = 0;
1168c2ecf20Sopenharmony_ci	u8 abort_running_scan;
1178c2ecf20Sopenharmony_ci	struct wid wid;
1188c2ecf20Sopenharmony_ci	struct host_if_drv *hif_drv = vif->hif_drv;
1198c2ecf20Sopenharmony_ci	struct wilc_user_scan_req *scan_req;
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci	if (evt == SCAN_EVENT_ABORTED) {
1228c2ecf20Sopenharmony_ci		abort_running_scan = 1;
1238c2ecf20Sopenharmony_ci		wid.id = WID_ABORT_RUNNING_SCAN;
1248c2ecf20Sopenharmony_ci		wid.type = WID_CHAR;
1258c2ecf20Sopenharmony_ci		wid.val = (s8 *)&abort_running_scan;
1268c2ecf20Sopenharmony_ci		wid.size = sizeof(char);
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci		result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
1298c2ecf20Sopenharmony_ci		if (result) {
1308c2ecf20Sopenharmony_ci			netdev_err(vif->ndev, "Failed to set abort running\n");
1318c2ecf20Sopenharmony_ci			result = -EFAULT;
1328c2ecf20Sopenharmony_ci		}
1338c2ecf20Sopenharmony_ci	}
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci	if (!hif_drv) {
1368c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
1378c2ecf20Sopenharmony_ci		return result;
1388c2ecf20Sopenharmony_ci	}
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci	scan_req = &hif_drv->usr_scan_req;
1418c2ecf20Sopenharmony_ci	if (scan_req->scan_result) {
1428c2ecf20Sopenharmony_ci		scan_req->scan_result(evt, NULL, scan_req->arg);
1438c2ecf20Sopenharmony_ci		scan_req->scan_result = NULL;
1448c2ecf20Sopenharmony_ci	}
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci	return result;
1478c2ecf20Sopenharmony_ci}
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ciint wilc_scan(struct wilc_vif *vif, u8 scan_source, u8 scan_type,
1508c2ecf20Sopenharmony_ci	      u8 *ch_freq_list, u8 ch_list_len,
1518c2ecf20Sopenharmony_ci	      void (*scan_result_fn)(enum scan_event,
1528c2ecf20Sopenharmony_ci				     struct wilc_rcvd_net_info *, void *),
1538c2ecf20Sopenharmony_ci	      void *user_arg, struct cfg80211_scan_request *request)
1548c2ecf20Sopenharmony_ci{
1558c2ecf20Sopenharmony_ci	int result = 0;
1568c2ecf20Sopenharmony_ci	struct wid wid_list[WILC_SCAN_WID_LIST_SIZE];
1578c2ecf20Sopenharmony_ci	u32 index = 0;
1588c2ecf20Sopenharmony_ci	u32 i, scan_timeout;
1598c2ecf20Sopenharmony_ci	u8 *buffer;
1608c2ecf20Sopenharmony_ci	u8 valuesize = 0;
1618c2ecf20Sopenharmony_ci	u8 *search_ssid_vals = NULL;
1628c2ecf20Sopenharmony_ci	struct host_if_drv *hif_drv = vif->hif_drv;
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci	if (hif_drv->hif_state >= HOST_IF_SCANNING &&
1658c2ecf20Sopenharmony_ci	    hif_drv->hif_state < HOST_IF_CONNECTED) {
1668c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "Already scan\n");
1678c2ecf20Sopenharmony_ci		result = -EBUSY;
1688c2ecf20Sopenharmony_ci		goto error;
1698c2ecf20Sopenharmony_ci	}
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci	if (vif->connecting) {
1728c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "Don't do obss scan\n");
1738c2ecf20Sopenharmony_ci		result = -EBUSY;
1748c2ecf20Sopenharmony_ci		goto error;
1758c2ecf20Sopenharmony_ci	}
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci	hif_drv->usr_scan_req.ch_cnt = 0;
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci	if (request->n_ssids) {
1808c2ecf20Sopenharmony_ci		for (i = 0; i < request->n_ssids; i++)
1818c2ecf20Sopenharmony_ci			valuesize += ((request->ssids[i].ssid_len) + 1);
1828c2ecf20Sopenharmony_ci		search_ssid_vals = kmalloc(valuesize + 1, GFP_KERNEL);
1838c2ecf20Sopenharmony_ci		if (search_ssid_vals) {
1848c2ecf20Sopenharmony_ci			wid_list[index].id = WID_SSID_PROBE_REQ;
1858c2ecf20Sopenharmony_ci			wid_list[index].type = WID_STR;
1868c2ecf20Sopenharmony_ci			wid_list[index].val = search_ssid_vals;
1878c2ecf20Sopenharmony_ci			buffer = wid_list[index].val;
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci			*buffer++ = request->n_ssids;
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci			for (i = 0; i < request->n_ssids; i++) {
1928c2ecf20Sopenharmony_ci				*buffer++ = request->ssids[i].ssid_len;
1938c2ecf20Sopenharmony_ci				memcpy(buffer, request->ssids[i].ssid,
1948c2ecf20Sopenharmony_ci				       request->ssids[i].ssid_len);
1958c2ecf20Sopenharmony_ci				buffer += request->ssids[i].ssid_len;
1968c2ecf20Sopenharmony_ci			}
1978c2ecf20Sopenharmony_ci			wid_list[index].size = (s32)(valuesize + 1);
1988c2ecf20Sopenharmony_ci			index++;
1998c2ecf20Sopenharmony_ci		}
2008c2ecf20Sopenharmony_ci	}
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ci	wid_list[index].id = WID_INFO_ELEMENT_PROBE;
2038c2ecf20Sopenharmony_ci	wid_list[index].type = WID_BIN_DATA;
2048c2ecf20Sopenharmony_ci	wid_list[index].val = (s8 *)request->ie;
2058c2ecf20Sopenharmony_ci	wid_list[index].size = request->ie_len;
2068c2ecf20Sopenharmony_ci	index++;
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci	wid_list[index].id = WID_SCAN_TYPE;
2098c2ecf20Sopenharmony_ci	wid_list[index].type = WID_CHAR;
2108c2ecf20Sopenharmony_ci	wid_list[index].size = sizeof(char);
2118c2ecf20Sopenharmony_ci	wid_list[index].val = (s8 *)&scan_type;
2128c2ecf20Sopenharmony_ci	index++;
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci	if (scan_type == WILC_FW_PASSIVE_SCAN && request->duration) {
2158c2ecf20Sopenharmony_ci		wid_list[index].id = WID_PASSIVE_SCAN_TIME;
2168c2ecf20Sopenharmony_ci		wid_list[index].type = WID_SHORT;
2178c2ecf20Sopenharmony_ci		wid_list[index].size = sizeof(u16);
2188c2ecf20Sopenharmony_ci		wid_list[index].val = (s8 *)&request->duration;
2198c2ecf20Sopenharmony_ci		index++;
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci		scan_timeout = (request->duration * ch_list_len) + 500;
2228c2ecf20Sopenharmony_ci	} else {
2238c2ecf20Sopenharmony_ci		scan_timeout = WILC_HIF_SCAN_TIMEOUT_MS;
2248c2ecf20Sopenharmony_ci	}
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci	wid_list[index].id = WID_SCAN_CHANNEL_LIST;
2278c2ecf20Sopenharmony_ci	wid_list[index].type = WID_BIN_DATA;
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci	if (ch_freq_list && ch_list_len > 0) {
2308c2ecf20Sopenharmony_ci		for (i = 0; i < ch_list_len; i++) {
2318c2ecf20Sopenharmony_ci			if (ch_freq_list[i] > 0)
2328c2ecf20Sopenharmony_ci				ch_freq_list[i] -= 1;
2338c2ecf20Sopenharmony_ci		}
2348c2ecf20Sopenharmony_ci	}
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci	wid_list[index].val = ch_freq_list;
2378c2ecf20Sopenharmony_ci	wid_list[index].size = ch_list_len;
2388c2ecf20Sopenharmony_ci	index++;
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci	wid_list[index].id = WID_START_SCAN_REQ;
2418c2ecf20Sopenharmony_ci	wid_list[index].type = WID_CHAR;
2428c2ecf20Sopenharmony_ci	wid_list[index].size = sizeof(char);
2438c2ecf20Sopenharmony_ci	wid_list[index].val = (s8 *)&scan_source;
2448c2ecf20Sopenharmony_ci	index++;
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_ci	hif_drv->usr_scan_req.scan_result = scan_result_fn;
2478c2ecf20Sopenharmony_ci	hif_drv->usr_scan_req.arg = user_arg;
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, index);
2508c2ecf20Sopenharmony_ci	if (result) {
2518c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "Failed to send scan parameters\n");
2528c2ecf20Sopenharmony_ci		goto error;
2538c2ecf20Sopenharmony_ci	}
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci	hif_drv->scan_timer_vif = vif;
2568c2ecf20Sopenharmony_ci	mod_timer(&hif_drv->scan_timer,
2578c2ecf20Sopenharmony_ci		  jiffies + msecs_to_jiffies(scan_timeout));
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_cierror:
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ci	kfree(search_ssid_vals);
2628c2ecf20Sopenharmony_ci
2638c2ecf20Sopenharmony_ci	return result;
2648c2ecf20Sopenharmony_ci}
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_cistatic int wilc_send_connect_wid(struct wilc_vif *vif)
2678c2ecf20Sopenharmony_ci{
2688c2ecf20Sopenharmony_ci	int result = 0;
2698c2ecf20Sopenharmony_ci	struct wid wid_list[4];
2708c2ecf20Sopenharmony_ci	u32 wid_cnt = 0;
2718c2ecf20Sopenharmony_ci	struct host_if_drv *hif_drv = vif->hif_drv;
2728c2ecf20Sopenharmony_ci	struct wilc_conn_info *conn_attr = &hif_drv->conn_info;
2738c2ecf20Sopenharmony_ci	struct wilc_join_bss_param *bss_param = conn_attr->param;
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci	wid_list[wid_cnt].id = WID_INFO_ELEMENT_ASSOCIATE;
2768c2ecf20Sopenharmony_ci	wid_list[wid_cnt].type = WID_BIN_DATA;
2778c2ecf20Sopenharmony_ci	wid_list[wid_cnt].val = conn_attr->req_ies;
2788c2ecf20Sopenharmony_ci	wid_list[wid_cnt].size = conn_attr->req_ies_len;
2798c2ecf20Sopenharmony_ci	wid_cnt++;
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci	wid_list[wid_cnt].id = WID_11I_MODE;
2828c2ecf20Sopenharmony_ci	wid_list[wid_cnt].type = WID_CHAR;
2838c2ecf20Sopenharmony_ci	wid_list[wid_cnt].size = sizeof(char);
2848c2ecf20Sopenharmony_ci	wid_list[wid_cnt].val = (s8 *)&conn_attr->security;
2858c2ecf20Sopenharmony_ci	wid_cnt++;
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci	wid_list[wid_cnt].id = WID_AUTH_TYPE;
2888c2ecf20Sopenharmony_ci	wid_list[wid_cnt].type = WID_CHAR;
2898c2ecf20Sopenharmony_ci	wid_list[wid_cnt].size = sizeof(char);
2908c2ecf20Sopenharmony_ci	wid_list[wid_cnt].val = (s8 *)&conn_attr->auth_type;
2918c2ecf20Sopenharmony_ci	wid_cnt++;
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_ci	wid_list[wid_cnt].id = WID_JOIN_REQ_EXTENDED;
2948c2ecf20Sopenharmony_ci	wid_list[wid_cnt].type = WID_STR;
2958c2ecf20Sopenharmony_ci	wid_list[wid_cnt].size = sizeof(*bss_param);
2968c2ecf20Sopenharmony_ci	wid_list[wid_cnt].val = (u8 *)bss_param;
2978c2ecf20Sopenharmony_ci	wid_cnt++;
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, wid_cnt);
3008c2ecf20Sopenharmony_ci	if (result) {
3018c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "failed to send config packet\n");
3028c2ecf20Sopenharmony_ci		goto error;
3038c2ecf20Sopenharmony_ci	} else {
3048c2ecf20Sopenharmony_ci		hif_drv->hif_state = HOST_IF_WAITING_CONN_RESP;
3058c2ecf20Sopenharmony_ci	}
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_ci	return 0;
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_cierror:
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_ci	kfree(conn_attr->req_ies);
3128c2ecf20Sopenharmony_ci	conn_attr->req_ies = NULL;
3138c2ecf20Sopenharmony_ci
3148c2ecf20Sopenharmony_ci	return result;
3158c2ecf20Sopenharmony_ci}
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_cistatic void handle_connect_timeout(struct work_struct *work)
3188c2ecf20Sopenharmony_ci{
3198c2ecf20Sopenharmony_ci	struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
3208c2ecf20Sopenharmony_ci	struct wilc_vif *vif = msg->vif;
3218c2ecf20Sopenharmony_ci	int result;
3228c2ecf20Sopenharmony_ci	struct wid wid;
3238c2ecf20Sopenharmony_ci	u16 dummy_reason_code = 0;
3248c2ecf20Sopenharmony_ci	struct host_if_drv *hif_drv = vif->hif_drv;
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_ci	if (!hif_drv) {
3278c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
3288c2ecf20Sopenharmony_ci		goto out;
3298c2ecf20Sopenharmony_ci	}
3308c2ecf20Sopenharmony_ci
3318c2ecf20Sopenharmony_ci	hif_drv->hif_state = HOST_IF_IDLE;
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci	if (hif_drv->conn_info.conn_result) {
3348c2ecf20Sopenharmony_ci		hif_drv->conn_info.conn_result(CONN_DISCONN_EVENT_CONN_RESP,
3358c2ecf20Sopenharmony_ci					       WILC_MAC_STATUS_DISCONNECTED,
3368c2ecf20Sopenharmony_ci					       hif_drv->conn_info.arg);
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_ci	} else {
3398c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
3408c2ecf20Sopenharmony_ci	}
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_ci	wid.id = WID_DISCONNECT;
3438c2ecf20Sopenharmony_ci	wid.type = WID_CHAR;
3448c2ecf20Sopenharmony_ci	wid.val = (s8 *)&dummy_reason_code;
3458c2ecf20Sopenharmony_ci	wid.size = sizeof(char);
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
3488c2ecf20Sopenharmony_ci	if (result)
3498c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "Failed to send disconnect\n");
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci	hif_drv->conn_info.req_ies_len = 0;
3528c2ecf20Sopenharmony_ci	kfree(hif_drv->conn_info.req_ies);
3538c2ecf20Sopenharmony_ci	hif_drv->conn_info.req_ies = NULL;
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_ciout:
3568c2ecf20Sopenharmony_ci	kfree(msg);
3578c2ecf20Sopenharmony_ci}
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_civoid *wilc_parse_join_bss_param(struct cfg80211_bss *bss,
3608c2ecf20Sopenharmony_ci				struct cfg80211_crypto_settings *crypto)
3618c2ecf20Sopenharmony_ci{
3628c2ecf20Sopenharmony_ci	struct wilc_join_bss_param *param;
3638c2ecf20Sopenharmony_ci	struct ieee80211_p2p_noa_attr noa_attr;
3648c2ecf20Sopenharmony_ci	u8 rates_len = 0;
3658c2ecf20Sopenharmony_ci	const u8 *tim_elm, *ssid_elm, *rates_ie, *supp_rates_ie;
3668c2ecf20Sopenharmony_ci	const u8 *ht_ie, *wpa_ie, *wmm_ie, *rsn_ie;
3678c2ecf20Sopenharmony_ci	int ret;
3688c2ecf20Sopenharmony_ci	const struct cfg80211_bss_ies *ies = rcu_dereference(bss->ies);
3698c2ecf20Sopenharmony_ci
3708c2ecf20Sopenharmony_ci	param = kzalloc(sizeof(*param), GFP_KERNEL);
3718c2ecf20Sopenharmony_ci	if (!param)
3728c2ecf20Sopenharmony_ci		return NULL;
3738c2ecf20Sopenharmony_ci
3748c2ecf20Sopenharmony_ci	param->beacon_period = cpu_to_le16(bss->beacon_interval);
3758c2ecf20Sopenharmony_ci	param->cap_info = cpu_to_le16(bss->capability);
3768c2ecf20Sopenharmony_ci	param->bss_type = WILC_FW_BSS_TYPE_INFRA;
3778c2ecf20Sopenharmony_ci	param->ch = ieee80211_frequency_to_channel(bss->channel->center_freq);
3788c2ecf20Sopenharmony_ci	ether_addr_copy(param->bssid, bss->bssid);
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ci	ssid_elm = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len);
3818c2ecf20Sopenharmony_ci	if (ssid_elm) {
3828c2ecf20Sopenharmony_ci		if (ssid_elm[1] <= IEEE80211_MAX_SSID_LEN)
3838c2ecf20Sopenharmony_ci			memcpy(param->ssid, ssid_elm + 2, ssid_elm[1]);
3848c2ecf20Sopenharmony_ci	}
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci	tim_elm = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
3878c2ecf20Sopenharmony_ci	if (tim_elm && tim_elm[1] >= 2)
3888c2ecf20Sopenharmony_ci		param->dtim_period = tim_elm[3];
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ci	memset(param->p_suites, 0xFF, 3);
3918c2ecf20Sopenharmony_ci	memset(param->akm_suites, 0xFF, 3);
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ci	rates_ie = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies->data, ies->len);
3948c2ecf20Sopenharmony_ci	if (rates_ie) {
3958c2ecf20Sopenharmony_ci		rates_len = rates_ie[1];
3968c2ecf20Sopenharmony_ci		if (rates_len > WILC_MAX_RATES_SUPPORTED)
3978c2ecf20Sopenharmony_ci			rates_len = WILC_MAX_RATES_SUPPORTED;
3988c2ecf20Sopenharmony_ci		param->supp_rates[0] = rates_len;
3998c2ecf20Sopenharmony_ci		memcpy(&param->supp_rates[1], rates_ie + 2, rates_len);
4008c2ecf20Sopenharmony_ci	}
4018c2ecf20Sopenharmony_ci
4028c2ecf20Sopenharmony_ci	if (rates_len < WILC_MAX_RATES_SUPPORTED) {
4038c2ecf20Sopenharmony_ci		supp_rates_ie = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES,
4048c2ecf20Sopenharmony_ci						 ies->data, ies->len);
4058c2ecf20Sopenharmony_ci		if (supp_rates_ie) {
4068c2ecf20Sopenharmony_ci			u8 ext_rates = supp_rates_ie[1];
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_ci			if (ext_rates > (WILC_MAX_RATES_SUPPORTED - rates_len))
4098c2ecf20Sopenharmony_ci				param->supp_rates[0] = WILC_MAX_RATES_SUPPORTED;
4108c2ecf20Sopenharmony_ci			else
4118c2ecf20Sopenharmony_ci				param->supp_rates[0] += ext_rates;
4128c2ecf20Sopenharmony_ci
4138c2ecf20Sopenharmony_ci			memcpy(&param->supp_rates[rates_len + 1],
4148c2ecf20Sopenharmony_ci			       supp_rates_ie + 2,
4158c2ecf20Sopenharmony_ci			       (param->supp_rates[0] - rates_len));
4168c2ecf20Sopenharmony_ci		}
4178c2ecf20Sopenharmony_ci	}
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ci	ht_ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies->data, ies->len);
4208c2ecf20Sopenharmony_ci	if (ht_ie)
4218c2ecf20Sopenharmony_ci		param->ht_capable = true;
4228c2ecf20Sopenharmony_ci
4238c2ecf20Sopenharmony_ci	ret = cfg80211_get_p2p_attr(ies->data, ies->len,
4248c2ecf20Sopenharmony_ci				    IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
4258c2ecf20Sopenharmony_ci				    (u8 *)&noa_attr, sizeof(noa_attr));
4268c2ecf20Sopenharmony_ci	if (ret > 0) {
4278c2ecf20Sopenharmony_ci		param->tsf_lo = cpu_to_le32(ies->tsf);
4288c2ecf20Sopenharmony_ci		param->noa_enabled = 1;
4298c2ecf20Sopenharmony_ci		param->idx = noa_attr.index;
4308c2ecf20Sopenharmony_ci		if (noa_attr.oppps_ctwindow & IEEE80211_P2P_OPPPS_ENABLE_BIT) {
4318c2ecf20Sopenharmony_ci			param->opp_enabled = 1;
4328c2ecf20Sopenharmony_ci			param->opp_en.ct_window = noa_attr.oppps_ctwindow;
4338c2ecf20Sopenharmony_ci			param->opp_en.cnt = noa_attr.desc[0].count;
4348c2ecf20Sopenharmony_ci			param->opp_en.duration = noa_attr.desc[0].duration;
4358c2ecf20Sopenharmony_ci			param->opp_en.interval = noa_attr.desc[0].interval;
4368c2ecf20Sopenharmony_ci			param->opp_en.start_time = noa_attr.desc[0].start_time;
4378c2ecf20Sopenharmony_ci		} else {
4388c2ecf20Sopenharmony_ci			param->opp_enabled = 0;
4398c2ecf20Sopenharmony_ci			param->opp_dis.cnt = noa_attr.desc[0].count;
4408c2ecf20Sopenharmony_ci			param->opp_dis.duration = noa_attr.desc[0].duration;
4418c2ecf20Sopenharmony_ci			param->opp_dis.interval = noa_attr.desc[0].interval;
4428c2ecf20Sopenharmony_ci			param->opp_dis.start_time = noa_attr.desc[0].start_time;
4438c2ecf20Sopenharmony_ci		}
4448c2ecf20Sopenharmony_ci	}
4458c2ecf20Sopenharmony_ci	wmm_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
4468c2ecf20Sopenharmony_ci					 WLAN_OUI_TYPE_MICROSOFT_WMM,
4478c2ecf20Sopenharmony_ci					 ies->data, ies->len);
4488c2ecf20Sopenharmony_ci	if (wmm_ie) {
4498c2ecf20Sopenharmony_ci		struct ieee80211_wmm_param_ie *ie;
4508c2ecf20Sopenharmony_ci
4518c2ecf20Sopenharmony_ci		ie = (struct ieee80211_wmm_param_ie *)wmm_ie;
4528c2ecf20Sopenharmony_ci		if ((ie->oui_subtype == 0 || ie->oui_subtype == 1) &&
4538c2ecf20Sopenharmony_ci		    ie->version == 1) {
4548c2ecf20Sopenharmony_ci			param->wmm_cap = true;
4558c2ecf20Sopenharmony_ci			if (ie->qos_info & BIT(7))
4568c2ecf20Sopenharmony_ci				param->uapsd_cap = true;
4578c2ecf20Sopenharmony_ci		}
4588c2ecf20Sopenharmony_ci	}
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_ci	wpa_ie = cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT,
4618c2ecf20Sopenharmony_ci					 WLAN_OUI_TYPE_MICROSOFT_WPA,
4628c2ecf20Sopenharmony_ci					 ies->data, ies->len);
4638c2ecf20Sopenharmony_ci	if (wpa_ie) {
4648c2ecf20Sopenharmony_ci		param->mode_802_11i = 1;
4658c2ecf20Sopenharmony_ci		param->rsn_found = true;
4668c2ecf20Sopenharmony_ci	}
4678c2ecf20Sopenharmony_ci
4688c2ecf20Sopenharmony_ci	rsn_ie = cfg80211_find_ie(WLAN_EID_RSN, ies->data, ies->len);
4698c2ecf20Sopenharmony_ci	if (rsn_ie) {
4708c2ecf20Sopenharmony_ci		int rsn_ie_len = sizeof(struct element) + rsn_ie[1];
4718c2ecf20Sopenharmony_ci		int offset = 8;
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_ci		param->mode_802_11i = 2;
4748c2ecf20Sopenharmony_ci		param->rsn_found = true;
4758c2ecf20Sopenharmony_ci
4768c2ecf20Sopenharmony_ci		/* extract RSN capabilities */
4778c2ecf20Sopenharmony_ci		if (offset < rsn_ie_len) {
4788c2ecf20Sopenharmony_ci			/* skip over pairwise suites */
4798c2ecf20Sopenharmony_ci			offset += (rsn_ie[offset] * 4) + 2;
4808c2ecf20Sopenharmony_ci
4818c2ecf20Sopenharmony_ci			if (offset < rsn_ie_len) {
4828c2ecf20Sopenharmony_ci				/* skip over authentication suites */
4838c2ecf20Sopenharmony_ci				offset += (rsn_ie[offset] * 4) + 2;
4848c2ecf20Sopenharmony_ci
4858c2ecf20Sopenharmony_ci				if (offset + 1 < rsn_ie_len)
4868c2ecf20Sopenharmony_ci					memcpy(param->rsn_cap, &rsn_ie[offset], 2);
4878c2ecf20Sopenharmony_ci			}
4888c2ecf20Sopenharmony_ci		}
4898c2ecf20Sopenharmony_ci	}
4908c2ecf20Sopenharmony_ci
4918c2ecf20Sopenharmony_ci	if (param->rsn_found) {
4928c2ecf20Sopenharmony_ci		int i;
4938c2ecf20Sopenharmony_ci
4948c2ecf20Sopenharmony_ci		param->rsn_grp_policy = crypto->cipher_group & 0xFF;
4958c2ecf20Sopenharmony_ci		for (i = 0; i < crypto->n_ciphers_pairwise && i < 3; i++)
4968c2ecf20Sopenharmony_ci			param->p_suites[i] = crypto->ciphers_pairwise[i] & 0xFF;
4978c2ecf20Sopenharmony_ci
4988c2ecf20Sopenharmony_ci		for (i = 0; i < crypto->n_akm_suites && i < 3; i++)
4998c2ecf20Sopenharmony_ci			param->akm_suites[i] = crypto->akm_suites[i] & 0xFF;
5008c2ecf20Sopenharmony_ci	}
5018c2ecf20Sopenharmony_ci
5028c2ecf20Sopenharmony_ci	return (void *)param;
5038c2ecf20Sopenharmony_ci}
5048c2ecf20Sopenharmony_ci
5058c2ecf20Sopenharmony_cistatic void handle_rcvd_ntwrk_info(struct work_struct *work)
5068c2ecf20Sopenharmony_ci{
5078c2ecf20Sopenharmony_ci	struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
5088c2ecf20Sopenharmony_ci	struct wilc_rcvd_net_info *rcvd_info = &msg->body.net_info;
5098c2ecf20Sopenharmony_ci	struct wilc_user_scan_req *scan_req = &msg->vif->hif_drv->usr_scan_req;
5108c2ecf20Sopenharmony_ci	const u8 *ch_elm;
5118c2ecf20Sopenharmony_ci	u8 *ies;
5128c2ecf20Sopenharmony_ci	int ies_len;
5138c2ecf20Sopenharmony_ci	size_t offset;
5148c2ecf20Sopenharmony_ci
5158c2ecf20Sopenharmony_ci	if (ieee80211_is_probe_resp(rcvd_info->mgmt->frame_control))
5168c2ecf20Sopenharmony_ci		offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
5178c2ecf20Sopenharmony_ci	else if (ieee80211_is_beacon(rcvd_info->mgmt->frame_control))
5188c2ecf20Sopenharmony_ci		offset = offsetof(struct ieee80211_mgmt, u.beacon.variable);
5198c2ecf20Sopenharmony_ci	else
5208c2ecf20Sopenharmony_ci		goto done;
5218c2ecf20Sopenharmony_ci
5228c2ecf20Sopenharmony_ci	ies = rcvd_info->mgmt->u.beacon.variable;
5238c2ecf20Sopenharmony_ci	ies_len = rcvd_info->frame_len - offset;
5248c2ecf20Sopenharmony_ci	if (ies_len <= 0)
5258c2ecf20Sopenharmony_ci		goto done;
5268c2ecf20Sopenharmony_ci
5278c2ecf20Sopenharmony_ci	ch_elm = cfg80211_find_ie(WLAN_EID_DS_PARAMS, ies, ies_len);
5288c2ecf20Sopenharmony_ci	if (ch_elm && ch_elm[1] > 0)
5298c2ecf20Sopenharmony_ci		rcvd_info->ch = ch_elm[2];
5308c2ecf20Sopenharmony_ci
5318c2ecf20Sopenharmony_ci	if (scan_req->scan_result)
5328c2ecf20Sopenharmony_ci		scan_req->scan_result(SCAN_EVENT_NETWORK_FOUND, rcvd_info,
5338c2ecf20Sopenharmony_ci				      scan_req->arg);
5348c2ecf20Sopenharmony_ci
5358c2ecf20Sopenharmony_cidone:
5368c2ecf20Sopenharmony_ci	kfree(rcvd_info->mgmt);
5378c2ecf20Sopenharmony_ci	kfree(msg);
5388c2ecf20Sopenharmony_ci}
5398c2ecf20Sopenharmony_ci
5408c2ecf20Sopenharmony_cistatic void host_int_get_assoc_res_info(struct wilc_vif *vif,
5418c2ecf20Sopenharmony_ci					u8 *assoc_resp_info,
5428c2ecf20Sopenharmony_ci					u32 max_assoc_resp_info_len,
5438c2ecf20Sopenharmony_ci					u32 *rcvd_assoc_resp_info_len)
5448c2ecf20Sopenharmony_ci{
5458c2ecf20Sopenharmony_ci	int result;
5468c2ecf20Sopenharmony_ci	struct wid wid;
5478c2ecf20Sopenharmony_ci
5488c2ecf20Sopenharmony_ci	wid.id = WID_ASSOC_RES_INFO;
5498c2ecf20Sopenharmony_ci	wid.type = WID_STR;
5508c2ecf20Sopenharmony_ci	wid.val = assoc_resp_info;
5518c2ecf20Sopenharmony_ci	wid.size = max_assoc_resp_info_len;
5528c2ecf20Sopenharmony_ci
5538c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
5548c2ecf20Sopenharmony_ci	if (result) {
5558c2ecf20Sopenharmony_ci		*rcvd_assoc_resp_info_len = 0;
5568c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "Failed to send association response\n");
5578c2ecf20Sopenharmony_ci		return;
5588c2ecf20Sopenharmony_ci	}
5598c2ecf20Sopenharmony_ci
5608c2ecf20Sopenharmony_ci	*rcvd_assoc_resp_info_len = wid.size;
5618c2ecf20Sopenharmony_ci}
5628c2ecf20Sopenharmony_ci
5638c2ecf20Sopenharmony_cistatic s32 wilc_parse_assoc_resp_info(u8 *buffer, u32 buffer_len,
5648c2ecf20Sopenharmony_ci				      struct wilc_conn_info *ret_conn_info)
5658c2ecf20Sopenharmony_ci{
5668c2ecf20Sopenharmony_ci	u8 *ies;
5678c2ecf20Sopenharmony_ci	u16 ies_len;
5688c2ecf20Sopenharmony_ci	struct wilc_assoc_resp *res = (struct wilc_assoc_resp *)buffer;
5698c2ecf20Sopenharmony_ci
5708c2ecf20Sopenharmony_ci	ret_conn_info->status = le16_to_cpu(res->status_code);
5718c2ecf20Sopenharmony_ci	if (ret_conn_info->status == WLAN_STATUS_SUCCESS) {
5728c2ecf20Sopenharmony_ci		ies = &buffer[sizeof(*res)];
5738c2ecf20Sopenharmony_ci		ies_len = buffer_len - sizeof(*res);
5748c2ecf20Sopenharmony_ci
5758c2ecf20Sopenharmony_ci		ret_conn_info->resp_ies = kmemdup(ies, ies_len, GFP_KERNEL);
5768c2ecf20Sopenharmony_ci		if (!ret_conn_info->resp_ies)
5778c2ecf20Sopenharmony_ci			return -ENOMEM;
5788c2ecf20Sopenharmony_ci
5798c2ecf20Sopenharmony_ci		ret_conn_info->resp_ies_len = ies_len;
5808c2ecf20Sopenharmony_ci	}
5818c2ecf20Sopenharmony_ci
5828c2ecf20Sopenharmony_ci	return 0;
5838c2ecf20Sopenharmony_ci}
5848c2ecf20Sopenharmony_ci
5858c2ecf20Sopenharmony_cistatic inline void host_int_parse_assoc_resp_info(struct wilc_vif *vif,
5868c2ecf20Sopenharmony_ci						  u8 mac_status)
5878c2ecf20Sopenharmony_ci{
5888c2ecf20Sopenharmony_ci	struct host_if_drv *hif_drv = vif->hif_drv;
5898c2ecf20Sopenharmony_ci	struct wilc_conn_info *conn_info = &hif_drv->conn_info;
5908c2ecf20Sopenharmony_ci
5918c2ecf20Sopenharmony_ci	if (mac_status == WILC_MAC_STATUS_CONNECTED) {
5928c2ecf20Sopenharmony_ci		u32 assoc_resp_info_len;
5938c2ecf20Sopenharmony_ci
5948c2ecf20Sopenharmony_ci		memset(hif_drv->assoc_resp, 0, WILC_MAX_ASSOC_RESP_FRAME_SIZE);
5958c2ecf20Sopenharmony_ci
5968c2ecf20Sopenharmony_ci		host_int_get_assoc_res_info(vif, hif_drv->assoc_resp,
5978c2ecf20Sopenharmony_ci					    WILC_MAX_ASSOC_RESP_FRAME_SIZE,
5988c2ecf20Sopenharmony_ci					    &assoc_resp_info_len);
5998c2ecf20Sopenharmony_ci
6008c2ecf20Sopenharmony_ci		if (assoc_resp_info_len != 0) {
6018c2ecf20Sopenharmony_ci			s32 err = 0;
6028c2ecf20Sopenharmony_ci
6038c2ecf20Sopenharmony_ci			err = wilc_parse_assoc_resp_info(hif_drv->assoc_resp,
6048c2ecf20Sopenharmony_ci							 assoc_resp_info_len,
6058c2ecf20Sopenharmony_ci							 conn_info);
6068c2ecf20Sopenharmony_ci			if (err)
6078c2ecf20Sopenharmony_ci				netdev_err(vif->ndev,
6088c2ecf20Sopenharmony_ci					   "wilc_parse_assoc_resp_info() returned error %d\n",
6098c2ecf20Sopenharmony_ci					   err);
6108c2ecf20Sopenharmony_ci		}
6118c2ecf20Sopenharmony_ci	}
6128c2ecf20Sopenharmony_ci
6138c2ecf20Sopenharmony_ci	del_timer(&hif_drv->connect_timer);
6148c2ecf20Sopenharmony_ci	conn_info->conn_result(CONN_DISCONN_EVENT_CONN_RESP, mac_status,
6158c2ecf20Sopenharmony_ci			       hif_drv->conn_info.arg);
6168c2ecf20Sopenharmony_ci
6178c2ecf20Sopenharmony_ci	if (mac_status == WILC_MAC_STATUS_CONNECTED &&
6188c2ecf20Sopenharmony_ci	    conn_info->status == WLAN_STATUS_SUCCESS) {
6198c2ecf20Sopenharmony_ci		ether_addr_copy(hif_drv->assoc_bssid, conn_info->bssid);
6208c2ecf20Sopenharmony_ci		hif_drv->hif_state = HOST_IF_CONNECTED;
6218c2ecf20Sopenharmony_ci	} else {
6228c2ecf20Sopenharmony_ci		hif_drv->hif_state = HOST_IF_IDLE;
6238c2ecf20Sopenharmony_ci	}
6248c2ecf20Sopenharmony_ci
6258c2ecf20Sopenharmony_ci	kfree(conn_info->resp_ies);
6268c2ecf20Sopenharmony_ci	conn_info->resp_ies = NULL;
6278c2ecf20Sopenharmony_ci	conn_info->resp_ies_len = 0;
6288c2ecf20Sopenharmony_ci
6298c2ecf20Sopenharmony_ci	kfree(conn_info->req_ies);
6308c2ecf20Sopenharmony_ci	conn_info->req_ies = NULL;
6318c2ecf20Sopenharmony_ci	conn_info->req_ies_len = 0;
6328c2ecf20Sopenharmony_ci}
6338c2ecf20Sopenharmony_ci
6348c2ecf20Sopenharmony_cistatic inline void host_int_handle_disconnect(struct wilc_vif *vif)
6358c2ecf20Sopenharmony_ci{
6368c2ecf20Sopenharmony_ci	struct host_if_drv *hif_drv = vif->hif_drv;
6378c2ecf20Sopenharmony_ci
6388c2ecf20Sopenharmony_ci	if (hif_drv->usr_scan_req.scan_result) {
6398c2ecf20Sopenharmony_ci		del_timer(&hif_drv->scan_timer);
6408c2ecf20Sopenharmony_ci		handle_scan_done(vif, SCAN_EVENT_ABORTED);
6418c2ecf20Sopenharmony_ci	}
6428c2ecf20Sopenharmony_ci
6438c2ecf20Sopenharmony_ci	if (hif_drv->conn_info.conn_result)
6448c2ecf20Sopenharmony_ci		hif_drv->conn_info.conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF,
6458c2ecf20Sopenharmony_ci					       0, hif_drv->conn_info.arg);
6468c2ecf20Sopenharmony_ci	else
6478c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
6488c2ecf20Sopenharmony_ci
6498c2ecf20Sopenharmony_ci	eth_zero_addr(hif_drv->assoc_bssid);
6508c2ecf20Sopenharmony_ci
6518c2ecf20Sopenharmony_ci	hif_drv->conn_info.req_ies_len = 0;
6528c2ecf20Sopenharmony_ci	kfree(hif_drv->conn_info.req_ies);
6538c2ecf20Sopenharmony_ci	hif_drv->conn_info.req_ies = NULL;
6548c2ecf20Sopenharmony_ci	hif_drv->hif_state = HOST_IF_IDLE;
6558c2ecf20Sopenharmony_ci}
6568c2ecf20Sopenharmony_ci
6578c2ecf20Sopenharmony_cistatic void handle_rcvd_gnrl_async_info(struct work_struct *work)
6588c2ecf20Sopenharmony_ci{
6598c2ecf20Sopenharmony_ci	struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
6608c2ecf20Sopenharmony_ci	struct wilc_vif *vif = msg->vif;
6618c2ecf20Sopenharmony_ci	struct wilc_rcvd_mac_info *mac_info = &msg->body.mac_info;
6628c2ecf20Sopenharmony_ci	struct host_if_drv *hif_drv = vif->hif_drv;
6638c2ecf20Sopenharmony_ci
6648c2ecf20Sopenharmony_ci	if (!hif_drv) {
6658c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "%s: hif driver is NULL\n", __func__);
6668c2ecf20Sopenharmony_ci		goto free_msg;
6678c2ecf20Sopenharmony_ci	}
6688c2ecf20Sopenharmony_ci
6698c2ecf20Sopenharmony_ci	if (!hif_drv->conn_info.conn_result) {
6708c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
6718c2ecf20Sopenharmony_ci		goto free_msg;
6728c2ecf20Sopenharmony_ci	}
6738c2ecf20Sopenharmony_ci
6748c2ecf20Sopenharmony_ci	if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP) {
6758c2ecf20Sopenharmony_ci		host_int_parse_assoc_resp_info(vif, mac_info->status);
6768c2ecf20Sopenharmony_ci	} else if (mac_info->status == WILC_MAC_STATUS_DISCONNECTED) {
6778c2ecf20Sopenharmony_ci		if (hif_drv->hif_state == HOST_IF_CONNECTED) {
6788c2ecf20Sopenharmony_ci			host_int_handle_disconnect(vif);
6798c2ecf20Sopenharmony_ci		} else if (hif_drv->usr_scan_req.scan_result) {
6808c2ecf20Sopenharmony_ci			del_timer(&hif_drv->scan_timer);
6818c2ecf20Sopenharmony_ci			handle_scan_done(vif, SCAN_EVENT_ABORTED);
6828c2ecf20Sopenharmony_ci		}
6838c2ecf20Sopenharmony_ci	}
6848c2ecf20Sopenharmony_ci
6858c2ecf20Sopenharmony_cifree_msg:
6868c2ecf20Sopenharmony_ci	kfree(msg);
6878c2ecf20Sopenharmony_ci}
6888c2ecf20Sopenharmony_ci
6898c2ecf20Sopenharmony_ciint wilc_disconnect(struct wilc_vif *vif)
6908c2ecf20Sopenharmony_ci{
6918c2ecf20Sopenharmony_ci	struct wid wid;
6928c2ecf20Sopenharmony_ci	struct host_if_drv *hif_drv = vif->hif_drv;
6938c2ecf20Sopenharmony_ci	struct wilc_user_scan_req *scan_req;
6948c2ecf20Sopenharmony_ci	struct wilc_conn_info *conn_info;
6958c2ecf20Sopenharmony_ci	int result;
6968c2ecf20Sopenharmony_ci	u16 dummy_reason_code = 0;
6978c2ecf20Sopenharmony_ci
6988c2ecf20Sopenharmony_ci	wid.id = WID_DISCONNECT;
6998c2ecf20Sopenharmony_ci	wid.type = WID_CHAR;
7008c2ecf20Sopenharmony_ci	wid.val = (s8 *)&dummy_reason_code;
7018c2ecf20Sopenharmony_ci	wid.size = sizeof(char);
7028c2ecf20Sopenharmony_ci
7038c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
7048c2ecf20Sopenharmony_ci	if (result) {
7058c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "Failed to send disconnect\n");
7068c2ecf20Sopenharmony_ci		return result;
7078c2ecf20Sopenharmony_ci	}
7088c2ecf20Sopenharmony_ci
7098c2ecf20Sopenharmony_ci	scan_req = &hif_drv->usr_scan_req;
7108c2ecf20Sopenharmony_ci	conn_info = &hif_drv->conn_info;
7118c2ecf20Sopenharmony_ci
7128c2ecf20Sopenharmony_ci	if (scan_req->scan_result) {
7138c2ecf20Sopenharmony_ci		del_timer(&hif_drv->scan_timer);
7148c2ecf20Sopenharmony_ci		scan_req->scan_result(SCAN_EVENT_ABORTED, NULL, scan_req->arg);
7158c2ecf20Sopenharmony_ci		scan_req->scan_result = NULL;
7168c2ecf20Sopenharmony_ci	}
7178c2ecf20Sopenharmony_ci
7188c2ecf20Sopenharmony_ci	if (conn_info->conn_result) {
7198c2ecf20Sopenharmony_ci		if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP)
7208c2ecf20Sopenharmony_ci			del_timer(&hif_drv->connect_timer);
7218c2ecf20Sopenharmony_ci
7228c2ecf20Sopenharmony_ci		conn_info->conn_result(CONN_DISCONN_EVENT_DISCONN_NOTIF, 0,
7238c2ecf20Sopenharmony_ci				       conn_info->arg);
7248c2ecf20Sopenharmony_ci	} else {
7258c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
7268c2ecf20Sopenharmony_ci	}
7278c2ecf20Sopenharmony_ci
7288c2ecf20Sopenharmony_ci	hif_drv->hif_state = HOST_IF_IDLE;
7298c2ecf20Sopenharmony_ci
7308c2ecf20Sopenharmony_ci	eth_zero_addr(hif_drv->assoc_bssid);
7318c2ecf20Sopenharmony_ci
7328c2ecf20Sopenharmony_ci	conn_info->req_ies_len = 0;
7338c2ecf20Sopenharmony_ci	kfree(conn_info->req_ies);
7348c2ecf20Sopenharmony_ci	conn_info->req_ies = NULL;
7358c2ecf20Sopenharmony_ci
7368c2ecf20Sopenharmony_ci	return 0;
7378c2ecf20Sopenharmony_ci}
7388c2ecf20Sopenharmony_ci
7398c2ecf20Sopenharmony_ciint wilc_get_statistics(struct wilc_vif *vif, struct rf_info *stats)
7408c2ecf20Sopenharmony_ci{
7418c2ecf20Sopenharmony_ci	struct wid wid_list[5];
7428c2ecf20Sopenharmony_ci	u32 wid_cnt = 0, result;
7438c2ecf20Sopenharmony_ci
7448c2ecf20Sopenharmony_ci	wid_list[wid_cnt].id = WID_LINKSPEED;
7458c2ecf20Sopenharmony_ci	wid_list[wid_cnt].type = WID_CHAR;
7468c2ecf20Sopenharmony_ci	wid_list[wid_cnt].size = sizeof(char);
7478c2ecf20Sopenharmony_ci	wid_list[wid_cnt].val = (s8 *)&stats->link_speed;
7488c2ecf20Sopenharmony_ci	wid_cnt++;
7498c2ecf20Sopenharmony_ci
7508c2ecf20Sopenharmony_ci	wid_list[wid_cnt].id = WID_RSSI;
7518c2ecf20Sopenharmony_ci	wid_list[wid_cnt].type = WID_CHAR;
7528c2ecf20Sopenharmony_ci	wid_list[wid_cnt].size = sizeof(char);
7538c2ecf20Sopenharmony_ci	wid_list[wid_cnt].val = (s8 *)&stats->rssi;
7548c2ecf20Sopenharmony_ci	wid_cnt++;
7558c2ecf20Sopenharmony_ci
7568c2ecf20Sopenharmony_ci	wid_list[wid_cnt].id = WID_SUCCESS_FRAME_COUNT;
7578c2ecf20Sopenharmony_ci	wid_list[wid_cnt].type = WID_INT;
7588c2ecf20Sopenharmony_ci	wid_list[wid_cnt].size = sizeof(u32);
7598c2ecf20Sopenharmony_ci	wid_list[wid_cnt].val = (s8 *)&stats->tx_cnt;
7608c2ecf20Sopenharmony_ci	wid_cnt++;
7618c2ecf20Sopenharmony_ci
7628c2ecf20Sopenharmony_ci	wid_list[wid_cnt].id = WID_RECEIVED_FRAGMENT_COUNT;
7638c2ecf20Sopenharmony_ci	wid_list[wid_cnt].type = WID_INT;
7648c2ecf20Sopenharmony_ci	wid_list[wid_cnt].size = sizeof(u32);
7658c2ecf20Sopenharmony_ci	wid_list[wid_cnt].val = (s8 *)&stats->rx_cnt;
7668c2ecf20Sopenharmony_ci	wid_cnt++;
7678c2ecf20Sopenharmony_ci
7688c2ecf20Sopenharmony_ci	wid_list[wid_cnt].id = WID_FAILED_COUNT;
7698c2ecf20Sopenharmony_ci	wid_list[wid_cnt].type = WID_INT;
7708c2ecf20Sopenharmony_ci	wid_list[wid_cnt].size = sizeof(u32);
7718c2ecf20Sopenharmony_ci	wid_list[wid_cnt].val = (s8 *)&stats->tx_fail_cnt;
7728c2ecf20Sopenharmony_ci	wid_cnt++;
7738c2ecf20Sopenharmony_ci
7748c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_GET_CFG, wid_list, wid_cnt);
7758c2ecf20Sopenharmony_ci	if (result) {
7768c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "Failed to send scan parameters\n");
7778c2ecf20Sopenharmony_ci		return result;
7788c2ecf20Sopenharmony_ci	}
7798c2ecf20Sopenharmony_ci
7808c2ecf20Sopenharmony_ci	if (stats->link_speed > TCP_ACK_FILTER_LINK_SPEED_THRESH &&
7818c2ecf20Sopenharmony_ci	    stats->link_speed != DEFAULT_LINK_SPEED)
7828c2ecf20Sopenharmony_ci		wilc_enable_tcp_ack_filter(vif, true);
7838c2ecf20Sopenharmony_ci	else if (stats->link_speed != DEFAULT_LINK_SPEED)
7848c2ecf20Sopenharmony_ci		wilc_enable_tcp_ack_filter(vif, false);
7858c2ecf20Sopenharmony_ci
7868c2ecf20Sopenharmony_ci	return result;
7878c2ecf20Sopenharmony_ci}
7888c2ecf20Sopenharmony_ci
7898c2ecf20Sopenharmony_cistatic void handle_get_statistics(struct work_struct *work)
7908c2ecf20Sopenharmony_ci{
7918c2ecf20Sopenharmony_ci	struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
7928c2ecf20Sopenharmony_ci	struct wilc_vif *vif = msg->vif;
7938c2ecf20Sopenharmony_ci	struct rf_info *stats = (struct rf_info *)msg->body.data;
7948c2ecf20Sopenharmony_ci
7958c2ecf20Sopenharmony_ci	wilc_get_statistics(vif, stats);
7968c2ecf20Sopenharmony_ci
7978c2ecf20Sopenharmony_ci	kfree(msg);
7988c2ecf20Sopenharmony_ci}
7998c2ecf20Sopenharmony_ci
8008c2ecf20Sopenharmony_cistatic void wilc_hif_pack_sta_param(u8 *cur_byte, const u8 *mac,
8018c2ecf20Sopenharmony_ci				    struct station_parameters *params)
8028c2ecf20Sopenharmony_ci{
8038c2ecf20Sopenharmony_ci	ether_addr_copy(cur_byte, mac);
8048c2ecf20Sopenharmony_ci	cur_byte += ETH_ALEN;
8058c2ecf20Sopenharmony_ci
8068c2ecf20Sopenharmony_ci	put_unaligned_le16(params->aid, cur_byte);
8078c2ecf20Sopenharmony_ci	cur_byte += 2;
8088c2ecf20Sopenharmony_ci
8098c2ecf20Sopenharmony_ci	*cur_byte++ = params->supported_rates_len;
8108c2ecf20Sopenharmony_ci	if (params->supported_rates_len > 0)
8118c2ecf20Sopenharmony_ci		memcpy(cur_byte, params->supported_rates,
8128c2ecf20Sopenharmony_ci		       params->supported_rates_len);
8138c2ecf20Sopenharmony_ci	cur_byte += params->supported_rates_len;
8148c2ecf20Sopenharmony_ci
8158c2ecf20Sopenharmony_ci	if (params->ht_capa) {
8168c2ecf20Sopenharmony_ci		*cur_byte++ = true;
8178c2ecf20Sopenharmony_ci		memcpy(cur_byte, params->ht_capa,
8188c2ecf20Sopenharmony_ci		       sizeof(struct ieee80211_ht_cap));
8198c2ecf20Sopenharmony_ci	} else {
8208c2ecf20Sopenharmony_ci		*cur_byte++ = false;
8218c2ecf20Sopenharmony_ci	}
8228c2ecf20Sopenharmony_ci	cur_byte += sizeof(struct ieee80211_ht_cap);
8238c2ecf20Sopenharmony_ci
8248c2ecf20Sopenharmony_ci	put_unaligned_le16(params->sta_flags_mask, cur_byte);
8258c2ecf20Sopenharmony_ci	cur_byte += 2;
8268c2ecf20Sopenharmony_ci	put_unaligned_le16(params->sta_flags_set, cur_byte);
8278c2ecf20Sopenharmony_ci}
8288c2ecf20Sopenharmony_ci
8298c2ecf20Sopenharmony_cistatic int handle_remain_on_chan(struct wilc_vif *vif,
8308c2ecf20Sopenharmony_ci				 struct wilc_remain_ch *hif_remain_ch)
8318c2ecf20Sopenharmony_ci{
8328c2ecf20Sopenharmony_ci	int result;
8338c2ecf20Sopenharmony_ci	u8 remain_on_chan_flag;
8348c2ecf20Sopenharmony_ci	struct wid wid;
8358c2ecf20Sopenharmony_ci	struct host_if_drv *hif_drv = vif->hif_drv;
8368c2ecf20Sopenharmony_ci
8378c2ecf20Sopenharmony_ci	if (hif_drv->usr_scan_req.scan_result)
8388c2ecf20Sopenharmony_ci		return -EBUSY;
8398c2ecf20Sopenharmony_ci
8408c2ecf20Sopenharmony_ci	if (hif_drv->hif_state == HOST_IF_WAITING_CONN_RESP)
8418c2ecf20Sopenharmony_ci		return -EBUSY;
8428c2ecf20Sopenharmony_ci
8438c2ecf20Sopenharmony_ci	if (vif->connecting)
8448c2ecf20Sopenharmony_ci		return -EBUSY;
8458c2ecf20Sopenharmony_ci
8468c2ecf20Sopenharmony_ci	remain_on_chan_flag = true;
8478c2ecf20Sopenharmony_ci	wid.id = WID_REMAIN_ON_CHAN;
8488c2ecf20Sopenharmony_ci	wid.type = WID_STR;
8498c2ecf20Sopenharmony_ci	wid.size = 2;
8508c2ecf20Sopenharmony_ci	wid.val = kmalloc(wid.size, GFP_KERNEL);
8518c2ecf20Sopenharmony_ci	if (!wid.val)
8528c2ecf20Sopenharmony_ci		return -ENOMEM;
8538c2ecf20Sopenharmony_ci
8548c2ecf20Sopenharmony_ci	wid.val[0] = remain_on_chan_flag;
8558c2ecf20Sopenharmony_ci	wid.val[1] = (s8)hif_remain_ch->ch;
8568c2ecf20Sopenharmony_ci
8578c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
8588c2ecf20Sopenharmony_ci	kfree(wid.val);
8598c2ecf20Sopenharmony_ci	if (result)
8608c2ecf20Sopenharmony_ci		return -EBUSY;
8618c2ecf20Sopenharmony_ci
8628c2ecf20Sopenharmony_ci	hif_drv->remain_on_ch.arg = hif_remain_ch->arg;
8638c2ecf20Sopenharmony_ci	hif_drv->remain_on_ch.expired = hif_remain_ch->expired;
8648c2ecf20Sopenharmony_ci	hif_drv->remain_on_ch.ch = hif_remain_ch->ch;
8658c2ecf20Sopenharmony_ci	hif_drv->remain_on_ch.cookie = hif_remain_ch->cookie;
8668c2ecf20Sopenharmony_ci	hif_drv->remain_on_ch_timer_vif = vif;
8678c2ecf20Sopenharmony_ci
8688c2ecf20Sopenharmony_ci	return 0;
8698c2ecf20Sopenharmony_ci}
8708c2ecf20Sopenharmony_ci
8718c2ecf20Sopenharmony_cistatic int wilc_handle_roc_expired(struct wilc_vif *vif, u64 cookie)
8728c2ecf20Sopenharmony_ci{
8738c2ecf20Sopenharmony_ci	u8 remain_on_chan_flag;
8748c2ecf20Sopenharmony_ci	struct wid wid;
8758c2ecf20Sopenharmony_ci	int result;
8768c2ecf20Sopenharmony_ci	struct host_if_drv *hif_drv = vif->hif_drv;
8778c2ecf20Sopenharmony_ci
8788c2ecf20Sopenharmony_ci	if (vif->priv.p2p_listen_state) {
8798c2ecf20Sopenharmony_ci		remain_on_chan_flag = false;
8808c2ecf20Sopenharmony_ci		wid.id = WID_REMAIN_ON_CHAN;
8818c2ecf20Sopenharmony_ci		wid.type = WID_STR;
8828c2ecf20Sopenharmony_ci		wid.size = 2;
8838c2ecf20Sopenharmony_ci
8848c2ecf20Sopenharmony_ci		wid.val = kmalloc(wid.size, GFP_KERNEL);
8858c2ecf20Sopenharmony_ci		if (!wid.val)
8868c2ecf20Sopenharmony_ci			return -ENOMEM;
8878c2ecf20Sopenharmony_ci
8888c2ecf20Sopenharmony_ci		wid.val[0] = remain_on_chan_flag;
8898c2ecf20Sopenharmony_ci		wid.val[1] = WILC_FALSE_FRMWR_CHANNEL;
8908c2ecf20Sopenharmony_ci
8918c2ecf20Sopenharmony_ci		result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
8928c2ecf20Sopenharmony_ci		kfree(wid.val);
8938c2ecf20Sopenharmony_ci		if (result != 0) {
8948c2ecf20Sopenharmony_ci			netdev_err(vif->ndev, "Failed to set remain channel\n");
8958c2ecf20Sopenharmony_ci			return -EINVAL;
8968c2ecf20Sopenharmony_ci		}
8978c2ecf20Sopenharmony_ci
8988c2ecf20Sopenharmony_ci		if (hif_drv->remain_on_ch.expired) {
8998c2ecf20Sopenharmony_ci			hif_drv->remain_on_ch.expired(hif_drv->remain_on_ch.arg,
9008c2ecf20Sopenharmony_ci						      cookie);
9018c2ecf20Sopenharmony_ci		}
9028c2ecf20Sopenharmony_ci	} else {
9038c2ecf20Sopenharmony_ci		netdev_dbg(vif->ndev, "Not in listen state\n");
9048c2ecf20Sopenharmony_ci	}
9058c2ecf20Sopenharmony_ci
9068c2ecf20Sopenharmony_ci	return 0;
9078c2ecf20Sopenharmony_ci}
9088c2ecf20Sopenharmony_ci
9098c2ecf20Sopenharmony_cistatic void wilc_handle_listen_state_expired(struct work_struct *work)
9108c2ecf20Sopenharmony_ci{
9118c2ecf20Sopenharmony_ci	struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
9128c2ecf20Sopenharmony_ci
9138c2ecf20Sopenharmony_ci	wilc_handle_roc_expired(msg->vif, msg->body.remain_on_ch.cookie);
9148c2ecf20Sopenharmony_ci	kfree(msg);
9158c2ecf20Sopenharmony_ci}
9168c2ecf20Sopenharmony_ci
9178c2ecf20Sopenharmony_cistatic void listen_timer_cb(struct timer_list *t)
9188c2ecf20Sopenharmony_ci{
9198c2ecf20Sopenharmony_ci	struct host_if_drv *hif_drv = from_timer(hif_drv, t,
9208c2ecf20Sopenharmony_ci						      remain_on_ch_timer);
9218c2ecf20Sopenharmony_ci	struct wilc_vif *vif = hif_drv->remain_on_ch_timer_vif;
9228c2ecf20Sopenharmony_ci	int result;
9238c2ecf20Sopenharmony_ci	struct host_if_msg *msg;
9248c2ecf20Sopenharmony_ci
9258c2ecf20Sopenharmony_ci	del_timer(&vif->hif_drv->remain_on_ch_timer);
9268c2ecf20Sopenharmony_ci
9278c2ecf20Sopenharmony_ci	msg = wilc_alloc_work(vif, wilc_handle_listen_state_expired, false);
9288c2ecf20Sopenharmony_ci	if (IS_ERR(msg))
9298c2ecf20Sopenharmony_ci		return;
9308c2ecf20Sopenharmony_ci
9318c2ecf20Sopenharmony_ci	msg->body.remain_on_ch.cookie = vif->hif_drv->remain_on_ch.cookie;
9328c2ecf20Sopenharmony_ci
9338c2ecf20Sopenharmony_ci	result = wilc_enqueue_work(msg);
9348c2ecf20Sopenharmony_ci	if (result) {
9358c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
9368c2ecf20Sopenharmony_ci		kfree(msg);
9378c2ecf20Sopenharmony_ci	}
9388c2ecf20Sopenharmony_ci}
9398c2ecf20Sopenharmony_ci
9408c2ecf20Sopenharmony_cistatic void handle_set_mcast_filter(struct work_struct *work)
9418c2ecf20Sopenharmony_ci{
9428c2ecf20Sopenharmony_ci	struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
9438c2ecf20Sopenharmony_ci	struct wilc_vif *vif = msg->vif;
9448c2ecf20Sopenharmony_ci	struct wilc_set_multicast *set_mc = &msg->body.mc_info;
9458c2ecf20Sopenharmony_ci	int result;
9468c2ecf20Sopenharmony_ci	struct wid wid;
9478c2ecf20Sopenharmony_ci	u8 *cur_byte;
9488c2ecf20Sopenharmony_ci
9498c2ecf20Sopenharmony_ci	wid.id = WID_SETUP_MULTICAST_FILTER;
9508c2ecf20Sopenharmony_ci	wid.type = WID_BIN;
9518c2ecf20Sopenharmony_ci	wid.size = sizeof(struct wilc_set_multicast) + (set_mc->cnt * ETH_ALEN);
9528c2ecf20Sopenharmony_ci	wid.val = kmalloc(wid.size, GFP_KERNEL);
9538c2ecf20Sopenharmony_ci	if (!wid.val)
9548c2ecf20Sopenharmony_ci		goto error;
9558c2ecf20Sopenharmony_ci
9568c2ecf20Sopenharmony_ci	cur_byte = wid.val;
9578c2ecf20Sopenharmony_ci	put_unaligned_le32(set_mc->enabled, cur_byte);
9588c2ecf20Sopenharmony_ci	cur_byte += 4;
9598c2ecf20Sopenharmony_ci
9608c2ecf20Sopenharmony_ci	put_unaligned_le32(set_mc->cnt, cur_byte);
9618c2ecf20Sopenharmony_ci	cur_byte += 4;
9628c2ecf20Sopenharmony_ci
9638c2ecf20Sopenharmony_ci	if (set_mc->cnt > 0 && set_mc->mc_list)
9648c2ecf20Sopenharmony_ci		memcpy(cur_byte, set_mc->mc_list, set_mc->cnt * ETH_ALEN);
9658c2ecf20Sopenharmony_ci
9668c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
9678c2ecf20Sopenharmony_ci	if (result)
9688c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "Failed to send setup multicast\n");
9698c2ecf20Sopenharmony_ci
9708c2ecf20Sopenharmony_cierror:
9718c2ecf20Sopenharmony_ci	kfree(set_mc->mc_list);
9728c2ecf20Sopenharmony_ci	kfree(wid.val);
9738c2ecf20Sopenharmony_ci	kfree(msg);
9748c2ecf20Sopenharmony_ci}
9758c2ecf20Sopenharmony_ci
9768c2ecf20Sopenharmony_cistatic void handle_scan_timer(struct work_struct *work)
9778c2ecf20Sopenharmony_ci{
9788c2ecf20Sopenharmony_ci	struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
9798c2ecf20Sopenharmony_ci
9808c2ecf20Sopenharmony_ci	handle_scan_done(msg->vif, SCAN_EVENT_ABORTED);
9818c2ecf20Sopenharmony_ci	kfree(msg);
9828c2ecf20Sopenharmony_ci}
9838c2ecf20Sopenharmony_ci
9848c2ecf20Sopenharmony_cistatic void handle_scan_complete(struct work_struct *work)
9858c2ecf20Sopenharmony_ci{
9868c2ecf20Sopenharmony_ci	struct host_if_msg *msg = container_of(work, struct host_if_msg, work);
9878c2ecf20Sopenharmony_ci
9888c2ecf20Sopenharmony_ci	del_timer(&msg->vif->hif_drv->scan_timer);
9898c2ecf20Sopenharmony_ci
9908c2ecf20Sopenharmony_ci	handle_scan_done(msg->vif, SCAN_EVENT_DONE);
9918c2ecf20Sopenharmony_ci
9928c2ecf20Sopenharmony_ci	kfree(msg);
9938c2ecf20Sopenharmony_ci}
9948c2ecf20Sopenharmony_ci
9958c2ecf20Sopenharmony_cistatic void timer_scan_cb(struct timer_list *t)
9968c2ecf20Sopenharmony_ci{
9978c2ecf20Sopenharmony_ci	struct host_if_drv *hif_drv = from_timer(hif_drv, t, scan_timer);
9988c2ecf20Sopenharmony_ci	struct wilc_vif *vif = hif_drv->scan_timer_vif;
9998c2ecf20Sopenharmony_ci	struct host_if_msg *msg;
10008c2ecf20Sopenharmony_ci	int result;
10018c2ecf20Sopenharmony_ci
10028c2ecf20Sopenharmony_ci	msg = wilc_alloc_work(vif, handle_scan_timer, false);
10038c2ecf20Sopenharmony_ci	if (IS_ERR(msg))
10048c2ecf20Sopenharmony_ci		return;
10058c2ecf20Sopenharmony_ci
10068c2ecf20Sopenharmony_ci	result = wilc_enqueue_work(msg);
10078c2ecf20Sopenharmony_ci	if (result)
10088c2ecf20Sopenharmony_ci		kfree(msg);
10098c2ecf20Sopenharmony_ci}
10108c2ecf20Sopenharmony_ci
10118c2ecf20Sopenharmony_cistatic void timer_connect_cb(struct timer_list *t)
10128c2ecf20Sopenharmony_ci{
10138c2ecf20Sopenharmony_ci	struct host_if_drv *hif_drv = from_timer(hif_drv, t,
10148c2ecf20Sopenharmony_ci						      connect_timer);
10158c2ecf20Sopenharmony_ci	struct wilc_vif *vif = hif_drv->connect_timer_vif;
10168c2ecf20Sopenharmony_ci	struct host_if_msg *msg;
10178c2ecf20Sopenharmony_ci	int result;
10188c2ecf20Sopenharmony_ci
10198c2ecf20Sopenharmony_ci	msg = wilc_alloc_work(vif, handle_connect_timeout, false);
10208c2ecf20Sopenharmony_ci	if (IS_ERR(msg))
10218c2ecf20Sopenharmony_ci		return;
10228c2ecf20Sopenharmony_ci
10238c2ecf20Sopenharmony_ci	result = wilc_enqueue_work(msg);
10248c2ecf20Sopenharmony_ci	if (result)
10258c2ecf20Sopenharmony_ci		kfree(msg);
10268c2ecf20Sopenharmony_ci}
10278c2ecf20Sopenharmony_ci
10288c2ecf20Sopenharmony_ciint wilc_remove_wep_key(struct wilc_vif *vif, u8 index)
10298c2ecf20Sopenharmony_ci{
10308c2ecf20Sopenharmony_ci	struct wid wid;
10318c2ecf20Sopenharmony_ci	int result;
10328c2ecf20Sopenharmony_ci
10338c2ecf20Sopenharmony_ci	wid.id = WID_REMOVE_WEP_KEY;
10348c2ecf20Sopenharmony_ci	wid.type = WID_STR;
10358c2ecf20Sopenharmony_ci	wid.size = sizeof(char);
10368c2ecf20Sopenharmony_ci	wid.val = &index;
10378c2ecf20Sopenharmony_ci
10388c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
10398c2ecf20Sopenharmony_ci	if (result)
10408c2ecf20Sopenharmony_ci		netdev_err(vif->ndev,
10418c2ecf20Sopenharmony_ci			   "Failed to send remove wep key config packet\n");
10428c2ecf20Sopenharmony_ci	return result;
10438c2ecf20Sopenharmony_ci}
10448c2ecf20Sopenharmony_ci
10458c2ecf20Sopenharmony_ciint wilc_set_wep_default_keyid(struct wilc_vif *vif, u8 index)
10468c2ecf20Sopenharmony_ci{
10478c2ecf20Sopenharmony_ci	struct wid wid;
10488c2ecf20Sopenharmony_ci	int result;
10498c2ecf20Sopenharmony_ci
10508c2ecf20Sopenharmony_ci	wid.id = WID_KEY_ID;
10518c2ecf20Sopenharmony_ci	wid.type = WID_CHAR;
10528c2ecf20Sopenharmony_ci	wid.size = sizeof(char);
10538c2ecf20Sopenharmony_ci	wid.val = &index;
10548c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
10558c2ecf20Sopenharmony_ci	if (result)
10568c2ecf20Sopenharmony_ci		netdev_err(vif->ndev,
10578c2ecf20Sopenharmony_ci			   "Failed to send wep default key config packet\n");
10588c2ecf20Sopenharmony_ci
10598c2ecf20Sopenharmony_ci	return result;
10608c2ecf20Sopenharmony_ci}
10618c2ecf20Sopenharmony_ci
10628c2ecf20Sopenharmony_ciint wilc_add_wep_key_bss_sta(struct wilc_vif *vif, const u8 *key, u8 len,
10638c2ecf20Sopenharmony_ci			     u8 index)
10648c2ecf20Sopenharmony_ci{
10658c2ecf20Sopenharmony_ci	struct wid wid;
10668c2ecf20Sopenharmony_ci	int result;
10678c2ecf20Sopenharmony_ci	struct wilc_wep_key *wep_key;
10688c2ecf20Sopenharmony_ci
10698c2ecf20Sopenharmony_ci	wid.id = WID_ADD_WEP_KEY;
10708c2ecf20Sopenharmony_ci	wid.type = WID_STR;
10718c2ecf20Sopenharmony_ci	wid.size = sizeof(*wep_key) + len;
10728c2ecf20Sopenharmony_ci	wep_key = kzalloc(wid.size, GFP_KERNEL);
10738c2ecf20Sopenharmony_ci	if (!wep_key)
10748c2ecf20Sopenharmony_ci		return -ENOMEM;
10758c2ecf20Sopenharmony_ci
10768c2ecf20Sopenharmony_ci	wid.val = (u8 *)wep_key;
10778c2ecf20Sopenharmony_ci
10788c2ecf20Sopenharmony_ci	wep_key->index = index;
10798c2ecf20Sopenharmony_ci	wep_key->key_len = len;
10808c2ecf20Sopenharmony_ci	memcpy(wep_key->key, key, len);
10818c2ecf20Sopenharmony_ci
10828c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
10838c2ecf20Sopenharmony_ci	if (result)
10848c2ecf20Sopenharmony_ci		netdev_err(vif->ndev,
10858c2ecf20Sopenharmony_ci			   "Failed to add wep key config packet\n");
10868c2ecf20Sopenharmony_ci
10878c2ecf20Sopenharmony_ci	kfree(wep_key);
10888c2ecf20Sopenharmony_ci	return result;
10898c2ecf20Sopenharmony_ci}
10908c2ecf20Sopenharmony_ci
10918c2ecf20Sopenharmony_ciint wilc_add_wep_key_bss_ap(struct wilc_vif *vif, const u8 *key, u8 len,
10928c2ecf20Sopenharmony_ci			    u8 index, u8 mode, enum authtype auth_type)
10938c2ecf20Sopenharmony_ci{
10948c2ecf20Sopenharmony_ci	struct wid wid_list[3];
10958c2ecf20Sopenharmony_ci	int result;
10968c2ecf20Sopenharmony_ci	struct wilc_wep_key *wep_key;
10978c2ecf20Sopenharmony_ci
10988c2ecf20Sopenharmony_ci	wid_list[0].id = WID_11I_MODE;
10998c2ecf20Sopenharmony_ci	wid_list[0].type = WID_CHAR;
11008c2ecf20Sopenharmony_ci	wid_list[0].size = sizeof(char);
11018c2ecf20Sopenharmony_ci	wid_list[0].val = &mode;
11028c2ecf20Sopenharmony_ci
11038c2ecf20Sopenharmony_ci	wid_list[1].id = WID_AUTH_TYPE;
11048c2ecf20Sopenharmony_ci	wid_list[1].type = WID_CHAR;
11058c2ecf20Sopenharmony_ci	wid_list[1].size = sizeof(char);
11068c2ecf20Sopenharmony_ci	wid_list[1].val = (s8 *)&auth_type;
11078c2ecf20Sopenharmony_ci
11088c2ecf20Sopenharmony_ci	wid_list[2].id = WID_WEP_KEY_VALUE;
11098c2ecf20Sopenharmony_ci	wid_list[2].type = WID_STR;
11108c2ecf20Sopenharmony_ci	wid_list[2].size = sizeof(*wep_key) + len;
11118c2ecf20Sopenharmony_ci	wep_key = kzalloc(wid_list[2].size, GFP_KERNEL);
11128c2ecf20Sopenharmony_ci	if (!wep_key)
11138c2ecf20Sopenharmony_ci		return -ENOMEM;
11148c2ecf20Sopenharmony_ci
11158c2ecf20Sopenharmony_ci	wid_list[2].val = (u8 *)wep_key;
11168c2ecf20Sopenharmony_ci
11178c2ecf20Sopenharmony_ci	wep_key->index = index;
11188c2ecf20Sopenharmony_ci	wep_key->key_len = len;
11198c2ecf20Sopenharmony_ci	memcpy(wep_key->key, key, len);
11208c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
11218c2ecf20Sopenharmony_ci				      ARRAY_SIZE(wid_list));
11228c2ecf20Sopenharmony_ci	if (result)
11238c2ecf20Sopenharmony_ci		netdev_err(vif->ndev,
11248c2ecf20Sopenharmony_ci			   "Failed to add wep ap key config packet\n");
11258c2ecf20Sopenharmony_ci
11268c2ecf20Sopenharmony_ci	kfree(wep_key);
11278c2ecf20Sopenharmony_ci	return result;
11288c2ecf20Sopenharmony_ci}
11298c2ecf20Sopenharmony_ci
11308c2ecf20Sopenharmony_ciint wilc_add_ptk(struct wilc_vif *vif, const u8 *ptk, u8 ptk_key_len,
11318c2ecf20Sopenharmony_ci		 const u8 *mac_addr, const u8 *rx_mic, const u8 *tx_mic,
11328c2ecf20Sopenharmony_ci		 u8 mode, u8 cipher_mode, u8 index)
11338c2ecf20Sopenharmony_ci{
11348c2ecf20Sopenharmony_ci	int result = 0;
11358c2ecf20Sopenharmony_ci	u8 t_key_len  = ptk_key_len + WILC_RX_MIC_KEY_LEN + WILC_TX_MIC_KEY_LEN;
11368c2ecf20Sopenharmony_ci
11378c2ecf20Sopenharmony_ci	if (mode == WILC_AP_MODE) {
11388c2ecf20Sopenharmony_ci		struct wid wid_list[2];
11398c2ecf20Sopenharmony_ci		struct wilc_ap_wpa_ptk *key_buf;
11408c2ecf20Sopenharmony_ci
11418c2ecf20Sopenharmony_ci		wid_list[0].id = WID_11I_MODE;
11428c2ecf20Sopenharmony_ci		wid_list[0].type = WID_CHAR;
11438c2ecf20Sopenharmony_ci		wid_list[0].size = sizeof(char);
11448c2ecf20Sopenharmony_ci		wid_list[0].val = (s8 *)&cipher_mode;
11458c2ecf20Sopenharmony_ci
11468c2ecf20Sopenharmony_ci		key_buf = kzalloc(sizeof(*key_buf) + t_key_len, GFP_KERNEL);
11478c2ecf20Sopenharmony_ci		if (!key_buf)
11488c2ecf20Sopenharmony_ci			return -ENOMEM;
11498c2ecf20Sopenharmony_ci
11508c2ecf20Sopenharmony_ci		ether_addr_copy(key_buf->mac_addr, mac_addr);
11518c2ecf20Sopenharmony_ci		key_buf->index = index;
11528c2ecf20Sopenharmony_ci		key_buf->key_len = t_key_len;
11538c2ecf20Sopenharmony_ci		memcpy(&key_buf->key[0], ptk, ptk_key_len);
11548c2ecf20Sopenharmony_ci
11558c2ecf20Sopenharmony_ci		if (rx_mic)
11568c2ecf20Sopenharmony_ci			memcpy(&key_buf->key[ptk_key_len], rx_mic,
11578c2ecf20Sopenharmony_ci			       WILC_RX_MIC_KEY_LEN);
11588c2ecf20Sopenharmony_ci
11598c2ecf20Sopenharmony_ci		if (tx_mic)
11608c2ecf20Sopenharmony_ci			memcpy(&key_buf->key[ptk_key_len + WILC_RX_MIC_KEY_LEN],
11618c2ecf20Sopenharmony_ci			       tx_mic, WILC_TX_MIC_KEY_LEN);
11628c2ecf20Sopenharmony_ci
11638c2ecf20Sopenharmony_ci		wid_list[1].id = WID_ADD_PTK;
11648c2ecf20Sopenharmony_ci		wid_list[1].type = WID_STR;
11658c2ecf20Sopenharmony_ci		wid_list[1].size = sizeof(*key_buf) + t_key_len;
11668c2ecf20Sopenharmony_ci		wid_list[1].val = (u8 *)key_buf;
11678c2ecf20Sopenharmony_ci		result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
11688c2ecf20Sopenharmony_ci					      ARRAY_SIZE(wid_list));
11698c2ecf20Sopenharmony_ci		kfree(key_buf);
11708c2ecf20Sopenharmony_ci	} else if (mode == WILC_STATION_MODE) {
11718c2ecf20Sopenharmony_ci		struct wid wid;
11728c2ecf20Sopenharmony_ci		struct wilc_sta_wpa_ptk *key_buf;
11738c2ecf20Sopenharmony_ci
11748c2ecf20Sopenharmony_ci		key_buf = kzalloc(sizeof(*key_buf) + t_key_len, GFP_KERNEL);
11758c2ecf20Sopenharmony_ci		if (!key_buf)
11768c2ecf20Sopenharmony_ci			return -ENOMEM;
11778c2ecf20Sopenharmony_ci
11788c2ecf20Sopenharmony_ci		ether_addr_copy(key_buf->mac_addr, mac_addr);
11798c2ecf20Sopenharmony_ci		key_buf->key_len = t_key_len;
11808c2ecf20Sopenharmony_ci		memcpy(&key_buf->key[0], ptk, ptk_key_len);
11818c2ecf20Sopenharmony_ci
11828c2ecf20Sopenharmony_ci		if (rx_mic)
11838c2ecf20Sopenharmony_ci			memcpy(&key_buf->key[ptk_key_len], rx_mic,
11848c2ecf20Sopenharmony_ci			       WILC_RX_MIC_KEY_LEN);
11858c2ecf20Sopenharmony_ci
11868c2ecf20Sopenharmony_ci		if (tx_mic)
11878c2ecf20Sopenharmony_ci			memcpy(&key_buf->key[ptk_key_len + WILC_RX_MIC_KEY_LEN],
11888c2ecf20Sopenharmony_ci			       tx_mic, WILC_TX_MIC_KEY_LEN);
11898c2ecf20Sopenharmony_ci
11908c2ecf20Sopenharmony_ci		wid.id = WID_ADD_PTK;
11918c2ecf20Sopenharmony_ci		wid.type = WID_STR;
11928c2ecf20Sopenharmony_ci		wid.size = sizeof(*key_buf) + t_key_len;
11938c2ecf20Sopenharmony_ci		wid.val = (s8 *)key_buf;
11948c2ecf20Sopenharmony_ci		result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
11958c2ecf20Sopenharmony_ci		kfree(key_buf);
11968c2ecf20Sopenharmony_ci	}
11978c2ecf20Sopenharmony_ci
11988c2ecf20Sopenharmony_ci	return result;
11998c2ecf20Sopenharmony_ci}
12008c2ecf20Sopenharmony_ci
12018c2ecf20Sopenharmony_ciint wilc_add_rx_gtk(struct wilc_vif *vif, const u8 *rx_gtk, u8 gtk_key_len,
12028c2ecf20Sopenharmony_ci		    u8 index, u32 key_rsc_len, const u8 *key_rsc,
12038c2ecf20Sopenharmony_ci		    const u8 *rx_mic, const u8 *tx_mic, u8 mode,
12048c2ecf20Sopenharmony_ci		    u8 cipher_mode)
12058c2ecf20Sopenharmony_ci{
12068c2ecf20Sopenharmony_ci	int result = 0;
12078c2ecf20Sopenharmony_ci	struct wilc_gtk_key *gtk_key;
12088c2ecf20Sopenharmony_ci	int t_key_len = gtk_key_len + WILC_RX_MIC_KEY_LEN + WILC_TX_MIC_KEY_LEN;
12098c2ecf20Sopenharmony_ci
12108c2ecf20Sopenharmony_ci	gtk_key = kzalloc(sizeof(*gtk_key) + t_key_len, GFP_KERNEL);
12118c2ecf20Sopenharmony_ci	if (!gtk_key)
12128c2ecf20Sopenharmony_ci		return -ENOMEM;
12138c2ecf20Sopenharmony_ci
12148c2ecf20Sopenharmony_ci	/* fill bssid value only in station mode */
12158c2ecf20Sopenharmony_ci	if (mode == WILC_STATION_MODE &&
12168c2ecf20Sopenharmony_ci	    vif->hif_drv->hif_state == HOST_IF_CONNECTED)
12178c2ecf20Sopenharmony_ci		memcpy(gtk_key->mac_addr, vif->hif_drv->assoc_bssid, ETH_ALEN);
12188c2ecf20Sopenharmony_ci
12198c2ecf20Sopenharmony_ci	if (key_rsc)
12208c2ecf20Sopenharmony_ci		memcpy(gtk_key->rsc, key_rsc, 8);
12218c2ecf20Sopenharmony_ci	gtk_key->index = index;
12228c2ecf20Sopenharmony_ci	gtk_key->key_len = t_key_len;
12238c2ecf20Sopenharmony_ci	memcpy(&gtk_key->key[0], rx_gtk, gtk_key_len);
12248c2ecf20Sopenharmony_ci
12258c2ecf20Sopenharmony_ci	if (rx_mic)
12268c2ecf20Sopenharmony_ci		memcpy(&gtk_key->key[gtk_key_len], rx_mic, WILC_RX_MIC_KEY_LEN);
12278c2ecf20Sopenharmony_ci
12288c2ecf20Sopenharmony_ci	if (tx_mic)
12298c2ecf20Sopenharmony_ci		memcpy(&gtk_key->key[gtk_key_len + WILC_RX_MIC_KEY_LEN],
12308c2ecf20Sopenharmony_ci		       tx_mic, WILC_TX_MIC_KEY_LEN);
12318c2ecf20Sopenharmony_ci
12328c2ecf20Sopenharmony_ci	if (mode == WILC_AP_MODE) {
12338c2ecf20Sopenharmony_ci		struct wid wid_list[2];
12348c2ecf20Sopenharmony_ci
12358c2ecf20Sopenharmony_ci		wid_list[0].id = WID_11I_MODE;
12368c2ecf20Sopenharmony_ci		wid_list[0].type = WID_CHAR;
12378c2ecf20Sopenharmony_ci		wid_list[0].size = sizeof(char);
12388c2ecf20Sopenharmony_ci		wid_list[0].val = (s8 *)&cipher_mode;
12398c2ecf20Sopenharmony_ci
12408c2ecf20Sopenharmony_ci		wid_list[1].id = WID_ADD_RX_GTK;
12418c2ecf20Sopenharmony_ci		wid_list[1].type = WID_STR;
12428c2ecf20Sopenharmony_ci		wid_list[1].size = sizeof(*gtk_key) + t_key_len;
12438c2ecf20Sopenharmony_ci		wid_list[1].val = (u8 *)gtk_key;
12448c2ecf20Sopenharmony_ci
12458c2ecf20Sopenharmony_ci		result = wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list,
12468c2ecf20Sopenharmony_ci					      ARRAY_SIZE(wid_list));
12478c2ecf20Sopenharmony_ci	} else if (mode == WILC_STATION_MODE) {
12488c2ecf20Sopenharmony_ci		struct wid wid;
12498c2ecf20Sopenharmony_ci
12508c2ecf20Sopenharmony_ci		wid.id = WID_ADD_RX_GTK;
12518c2ecf20Sopenharmony_ci		wid.type = WID_STR;
12528c2ecf20Sopenharmony_ci		wid.size = sizeof(*gtk_key) + t_key_len;
12538c2ecf20Sopenharmony_ci		wid.val = (u8 *)gtk_key;
12548c2ecf20Sopenharmony_ci		result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
12558c2ecf20Sopenharmony_ci	}
12568c2ecf20Sopenharmony_ci
12578c2ecf20Sopenharmony_ci	kfree(gtk_key);
12588c2ecf20Sopenharmony_ci	return result;
12598c2ecf20Sopenharmony_ci}
12608c2ecf20Sopenharmony_ci
12618c2ecf20Sopenharmony_ciint wilc_set_pmkid_info(struct wilc_vif *vif, struct wilc_pmkid_attr *pmkid)
12628c2ecf20Sopenharmony_ci{
12638c2ecf20Sopenharmony_ci	struct wid wid;
12648c2ecf20Sopenharmony_ci
12658c2ecf20Sopenharmony_ci	wid.id = WID_PMKID_INFO;
12668c2ecf20Sopenharmony_ci	wid.type = WID_STR;
12678c2ecf20Sopenharmony_ci	wid.size = (pmkid->numpmkid * sizeof(struct wilc_pmkid)) + 1;
12688c2ecf20Sopenharmony_ci	wid.val = (u8 *)pmkid;
12698c2ecf20Sopenharmony_ci
12708c2ecf20Sopenharmony_ci	return wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
12718c2ecf20Sopenharmony_ci}
12728c2ecf20Sopenharmony_ci
12738c2ecf20Sopenharmony_ciint wilc_get_mac_address(struct wilc_vif *vif, u8 *mac_addr)
12748c2ecf20Sopenharmony_ci{
12758c2ecf20Sopenharmony_ci	int result;
12768c2ecf20Sopenharmony_ci	struct wid wid;
12778c2ecf20Sopenharmony_ci
12788c2ecf20Sopenharmony_ci	wid.id = WID_MAC_ADDR;
12798c2ecf20Sopenharmony_ci	wid.type = WID_STR;
12808c2ecf20Sopenharmony_ci	wid.size = ETH_ALEN;
12818c2ecf20Sopenharmony_ci	wid.val = mac_addr;
12828c2ecf20Sopenharmony_ci
12838c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
12848c2ecf20Sopenharmony_ci	if (result)
12858c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "Failed to get mac address\n");
12868c2ecf20Sopenharmony_ci
12878c2ecf20Sopenharmony_ci	return result;
12888c2ecf20Sopenharmony_ci}
12898c2ecf20Sopenharmony_ci
12908c2ecf20Sopenharmony_ciint wilc_set_join_req(struct wilc_vif *vif, u8 *bssid, const u8 *ies,
12918c2ecf20Sopenharmony_ci		      size_t ies_len)
12928c2ecf20Sopenharmony_ci{
12938c2ecf20Sopenharmony_ci	int result;
12948c2ecf20Sopenharmony_ci	struct host_if_drv *hif_drv = vif->hif_drv;
12958c2ecf20Sopenharmony_ci	struct wilc_conn_info *conn_info = &hif_drv->conn_info;
12968c2ecf20Sopenharmony_ci
12978c2ecf20Sopenharmony_ci	if (bssid)
12988c2ecf20Sopenharmony_ci		ether_addr_copy(conn_info->bssid, bssid);
12998c2ecf20Sopenharmony_ci
13008c2ecf20Sopenharmony_ci	if (ies) {
13018c2ecf20Sopenharmony_ci		conn_info->req_ies_len = ies_len;
13028c2ecf20Sopenharmony_ci		conn_info->req_ies = kmemdup(ies, ies_len, GFP_KERNEL);
13038c2ecf20Sopenharmony_ci		if (!conn_info->req_ies)
13048c2ecf20Sopenharmony_ci			return -ENOMEM;
13058c2ecf20Sopenharmony_ci	}
13068c2ecf20Sopenharmony_ci
13078c2ecf20Sopenharmony_ci	result = wilc_send_connect_wid(vif);
13088c2ecf20Sopenharmony_ci	if (result)
13098c2ecf20Sopenharmony_ci		goto free_ies;
13108c2ecf20Sopenharmony_ci
13118c2ecf20Sopenharmony_ci	hif_drv->connect_timer_vif = vif;
13128c2ecf20Sopenharmony_ci	mod_timer(&hif_drv->connect_timer,
13138c2ecf20Sopenharmony_ci		  jiffies + msecs_to_jiffies(WILC_HIF_CONNECT_TIMEOUT_MS));
13148c2ecf20Sopenharmony_ci
13158c2ecf20Sopenharmony_ci	return 0;
13168c2ecf20Sopenharmony_ci
13178c2ecf20Sopenharmony_cifree_ies:
13188c2ecf20Sopenharmony_ci	kfree(conn_info->req_ies);
13198c2ecf20Sopenharmony_ci
13208c2ecf20Sopenharmony_ci	return result;
13218c2ecf20Sopenharmony_ci}
13228c2ecf20Sopenharmony_ci
13238c2ecf20Sopenharmony_ciint wilc_set_mac_chnl_num(struct wilc_vif *vif, u8 channel)
13248c2ecf20Sopenharmony_ci{
13258c2ecf20Sopenharmony_ci	struct wid wid;
13268c2ecf20Sopenharmony_ci	int result;
13278c2ecf20Sopenharmony_ci
13288c2ecf20Sopenharmony_ci	wid.id = WID_CURRENT_CHANNEL;
13298c2ecf20Sopenharmony_ci	wid.type = WID_CHAR;
13308c2ecf20Sopenharmony_ci	wid.size = sizeof(char);
13318c2ecf20Sopenharmony_ci	wid.val = &channel;
13328c2ecf20Sopenharmony_ci
13338c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
13348c2ecf20Sopenharmony_ci	if (result)
13358c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "Failed to set channel\n");
13368c2ecf20Sopenharmony_ci
13378c2ecf20Sopenharmony_ci	return result;
13388c2ecf20Sopenharmony_ci}
13398c2ecf20Sopenharmony_ci
13408c2ecf20Sopenharmony_ciint wilc_set_operation_mode(struct wilc_vif *vif, int index, u8 mode,
13418c2ecf20Sopenharmony_ci			    u8 ifc_id)
13428c2ecf20Sopenharmony_ci{
13438c2ecf20Sopenharmony_ci	struct wid wid;
13448c2ecf20Sopenharmony_ci	int result;
13458c2ecf20Sopenharmony_ci	struct wilc_drv_handler drv;
13468c2ecf20Sopenharmony_ci
13478c2ecf20Sopenharmony_ci	wid.id = WID_SET_OPERATION_MODE;
13488c2ecf20Sopenharmony_ci	wid.type = WID_STR;
13498c2ecf20Sopenharmony_ci	wid.size = sizeof(drv);
13508c2ecf20Sopenharmony_ci	wid.val = (u8 *)&drv;
13518c2ecf20Sopenharmony_ci
13528c2ecf20Sopenharmony_ci	drv.handler = cpu_to_le32(index);
13538c2ecf20Sopenharmony_ci	drv.mode = (ifc_id | (mode << 1));
13548c2ecf20Sopenharmony_ci
13558c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
13568c2ecf20Sopenharmony_ci	if (result)
13578c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "Failed to set driver handler\n");
13588c2ecf20Sopenharmony_ci
13598c2ecf20Sopenharmony_ci	return result;
13608c2ecf20Sopenharmony_ci}
13618c2ecf20Sopenharmony_ci
13628c2ecf20Sopenharmony_cis32 wilc_get_inactive_time(struct wilc_vif *vif, const u8 *mac, u32 *out_val)
13638c2ecf20Sopenharmony_ci{
13648c2ecf20Sopenharmony_ci	struct wid wid;
13658c2ecf20Sopenharmony_ci	s32 result;
13668c2ecf20Sopenharmony_ci
13678c2ecf20Sopenharmony_ci	wid.id = WID_SET_STA_MAC_INACTIVE_TIME;
13688c2ecf20Sopenharmony_ci	wid.type = WID_STR;
13698c2ecf20Sopenharmony_ci	wid.size = ETH_ALEN;
13708c2ecf20Sopenharmony_ci	wid.val = kzalloc(wid.size, GFP_KERNEL);
13718c2ecf20Sopenharmony_ci	if (!wid.val)
13728c2ecf20Sopenharmony_ci		return -ENOMEM;
13738c2ecf20Sopenharmony_ci
13748c2ecf20Sopenharmony_ci	ether_addr_copy(wid.val, mac);
13758c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
13768c2ecf20Sopenharmony_ci	kfree(wid.val);
13778c2ecf20Sopenharmony_ci	if (result) {
13788c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "Failed to set inactive mac\n");
13798c2ecf20Sopenharmony_ci		return result;
13808c2ecf20Sopenharmony_ci	}
13818c2ecf20Sopenharmony_ci
13828c2ecf20Sopenharmony_ci	wid.id = WID_GET_INACTIVE_TIME;
13838c2ecf20Sopenharmony_ci	wid.type = WID_INT;
13848c2ecf20Sopenharmony_ci	wid.val = (s8 *)out_val;
13858c2ecf20Sopenharmony_ci	wid.size = sizeof(u32);
13868c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
13878c2ecf20Sopenharmony_ci	if (result)
13888c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "Failed to get inactive time\n");
13898c2ecf20Sopenharmony_ci
13908c2ecf20Sopenharmony_ci	return result;
13918c2ecf20Sopenharmony_ci}
13928c2ecf20Sopenharmony_ci
13938c2ecf20Sopenharmony_ciint wilc_get_rssi(struct wilc_vif *vif, s8 *rssi_level)
13948c2ecf20Sopenharmony_ci{
13958c2ecf20Sopenharmony_ci	struct wid wid;
13968c2ecf20Sopenharmony_ci	int result;
13978c2ecf20Sopenharmony_ci
13988c2ecf20Sopenharmony_ci	if (!rssi_level) {
13998c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "%s: RSSI level is NULL\n", __func__);
14008c2ecf20Sopenharmony_ci		return -EFAULT;
14018c2ecf20Sopenharmony_ci	}
14028c2ecf20Sopenharmony_ci
14038c2ecf20Sopenharmony_ci	wid.id = WID_RSSI;
14048c2ecf20Sopenharmony_ci	wid.type = WID_CHAR;
14058c2ecf20Sopenharmony_ci	wid.size = sizeof(char);
14068c2ecf20Sopenharmony_ci	wid.val = rssi_level;
14078c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
14088c2ecf20Sopenharmony_ci	if (result)
14098c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "Failed to get RSSI value\n");
14108c2ecf20Sopenharmony_ci
14118c2ecf20Sopenharmony_ci	return result;
14128c2ecf20Sopenharmony_ci}
14138c2ecf20Sopenharmony_ci
14148c2ecf20Sopenharmony_cistatic int wilc_get_stats_async(struct wilc_vif *vif, struct rf_info *stats)
14158c2ecf20Sopenharmony_ci{
14168c2ecf20Sopenharmony_ci	int result;
14178c2ecf20Sopenharmony_ci	struct host_if_msg *msg;
14188c2ecf20Sopenharmony_ci
14198c2ecf20Sopenharmony_ci	msg = wilc_alloc_work(vif, handle_get_statistics, false);
14208c2ecf20Sopenharmony_ci	if (IS_ERR(msg))
14218c2ecf20Sopenharmony_ci		return PTR_ERR(msg);
14228c2ecf20Sopenharmony_ci
14238c2ecf20Sopenharmony_ci	msg->body.data = (char *)stats;
14248c2ecf20Sopenharmony_ci
14258c2ecf20Sopenharmony_ci	result = wilc_enqueue_work(msg);
14268c2ecf20Sopenharmony_ci	if (result) {
14278c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
14288c2ecf20Sopenharmony_ci		kfree(msg);
14298c2ecf20Sopenharmony_ci		return result;
14308c2ecf20Sopenharmony_ci	}
14318c2ecf20Sopenharmony_ci
14328c2ecf20Sopenharmony_ci	return result;
14338c2ecf20Sopenharmony_ci}
14348c2ecf20Sopenharmony_ci
14358c2ecf20Sopenharmony_ciint wilc_hif_set_cfg(struct wilc_vif *vif, struct cfg_param_attr *param)
14368c2ecf20Sopenharmony_ci{
14378c2ecf20Sopenharmony_ci	struct wid wid_list[4];
14388c2ecf20Sopenharmony_ci	int i = 0;
14398c2ecf20Sopenharmony_ci
14408c2ecf20Sopenharmony_ci	if (param->flag & WILC_CFG_PARAM_RETRY_SHORT) {
14418c2ecf20Sopenharmony_ci		wid_list[i].id = WID_SHORT_RETRY_LIMIT;
14428c2ecf20Sopenharmony_ci		wid_list[i].val = (s8 *)&param->short_retry_limit;
14438c2ecf20Sopenharmony_ci		wid_list[i].type = WID_SHORT;
14448c2ecf20Sopenharmony_ci		wid_list[i].size = sizeof(u16);
14458c2ecf20Sopenharmony_ci		i++;
14468c2ecf20Sopenharmony_ci	}
14478c2ecf20Sopenharmony_ci	if (param->flag & WILC_CFG_PARAM_RETRY_LONG) {
14488c2ecf20Sopenharmony_ci		wid_list[i].id = WID_LONG_RETRY_LIMIT;
14498c2ecf20Sopenharmony_ci		wid_list[i].val = (s8 *)&param->long_retry_limit;
14508c2ecf20Sopenharmony_ci		wid_list[i].type = WID_SHORT;
14518c2ecf20Sopenharmony_ci		wid_list[i].size = sizeof(u16);
14528c2ecf20Sopenharmony_ci		i++;
14538c2ecf20Sopenharmony_ci	}
14548c2ecf20Sopenharmony_ci	if (param->flag & WILC_CFG_PARAM_FRAG_THRESHOLD) {
14558c2ecf20Sopenharmony_ci		wid_list[i].id = WID_FRAG_THRESHOLD;
14568c2ecf20Sopenharmony_ci		wid_list[i].val = (s8 *)&param->frag_threshold;
14578c2ecf20Sopenharmony_ci		wid_list[i].type = WID_SHORT;
14588c2ecf20Sopenharmony_ci		wid_list[i].size = sizeof(u16);
14598c2ecf20Sopenharmony_ci		i++;
14608c2ecf20Sopenharmony_ci	}
14618c2ecf20Sopenharmony_ci	if (param->flag & WILC_CFG_PARAM_RTS_THRESHOLD) {
14628c2ecf20Sopenharmony_ci		wid_list[i].id = WID_RTS_THRESHOLD;
14638c2ecf20Sopenharmony_ci		wid_list[i].val = (s8 *)&param->rts_threshold;
14648c2ecf20Sopenharmony_ci		wid_list[i].type = WID_SHORT;
14658c2ecf20Sopenharmony_ci		wid_list[i].size = sizeof(u16);
14668c2ecf20Sopenharmony_ci		i++;
14678c2ecf20Sopenharmony_ci	}
14688c2ecf20Sopenharmony_ci
14698c2ecf20Sopenharmony_ci	return wilc_send_config_pkt(vif, WILC_SET_CFG, wid_list, i);
14708c2ecf20Sopenharmony_ci}
14718c2ecf20Sopenharmony_ci
14728c2ecf20Sopenharmony_cistatic void get_periodic_rssi(struct timer_list *t)
14738c2ecf20Sopenharmony_ci{
14748c2ecf20Sopenharmony_ci	struct wilc_vif *vif = from_timer(vif, t, periodic_rssi);
14758c2ecf20Sopenharmony_ci
14768c2ecf20Sopenharmony_ci	if (!vif->hif_drv) {
14778c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
14788c2ecf20Sopenharmony_ci		return;
14798c2ecf20Sopenharmony_ci	}
14808c2ecf20Sopenharmony_ci
14818c2ecf20Sopenharmony_ci	if (vif->hif_drv->hif_state == HOST_IF_CONNECTED)
14828c2ecf20Sopenharmony_ci		wilc_get_stats_async(vif, &vif->periodic_stat);
14838c2ecf20Sopenharmony_ci
14848c2ecf20Sopenharmony_ci	mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000));
14858c2ecf20Sopenharmony_ci}
14868c2ecf20Sopenharmony_ci
14878c2ecf20Sopenharmony_ciint wilc_init(struct net_device *dev, struct host_if_drv **hif_drv_handler)
14888c2ecf20Sopenharmony_ci{
14898c2ecf20Sopenharmony_ci	struct host_if_drv *hif_drv;
14908c2ecf20Sopenharmony_ci	struct wilc_vif *vif = netdev_priv(dev);
14918c2ecf20Sopenharmony_ci	struct wilc *wilc = vif->wilc;
14928c2ecf20Sopenharmony_ci
14938c2ecf20Sopenharmony_ci	hif_drv  = kzalloc(sizeof(*hif_drv), GFP_KERNEL);
14948c2ecf20Sopenharmony_ci	if (!hif_drv)
14958c2ecf20Sopenharmony_ci		return -ENOMEM;
14968c2ecf20Sopenharmony_ci
14978c2ecf20Sopenharmony_ci	*hif_drv_handler = hif_drv;
14988c2ecf20Sopenharmony_ci
14998c2ecf20Sopenharmony_ci	vif->hif_drv = hif_drv;
15008c2ecf20Sopenharmony_ci
15018c2ecf20Sopenharmony_ci	if (wilc->clients_count == 0)
15028c2ecf20Sopenharmony_ci		mutex_init(&wilc->deinit_lock);
15038c2ecf20Sopenharmony_ci
15048c2ecf20Sopenharmony_ci	timer_setup(&vif->periodic_rssi, get_periodic_rssi, 0);
15058c2ecf20Sopenharmony_ci	mod_timer(&vif->periodic_rssi, jiffies + msecs_to_jiffies(5000));
15068c2ecf20Sopenharmony_ci
15078c2ecf20Sopenharmony_ci	timer_setup(&hif_drv->scan_timer, timer_scan_cb, 0);
15088c2ecf20Sopenharmony_ci	timer_setup(&hif_drv->connect_timer, timer_connect_cb, 0);
15098c2ecf20Sopenharmony_ci	timer_setup(&hif_drv->remain_on_ch_timer, listen_timer_cb, 0);
15108c2ecf20Sopenharmony_ci
15118c2ecf20Sopenharmony_ci	hif_drv->hif_state = HOST_IF_IDLE;
15128c2ecf20Sopenharmony_ci
15138c2ecf20Sopenharmony_ci	hif_drv->p2p_timeout = 0;
15148c2ecf20Sopenharmony_ci
15158c2ecf20Sopenharmony_ci	wilc->clients_count++;
15168c2ecf20Sopenharmony_ci
15178c2ecf20Sopenharmony_ci	return 0;
15188c2ecf20Sopenharmony_ci}
15198c2ecf20Sopenharmony_ci
15208c2ecf20Sopenharmony_ciint wilc_deinit(struct wilc_vif *vif)
15218c2ecf20Sopenharmony_ci{
15228c2ecf20Sopenharmony_ci	int result = 0;
15238c2ecf20Sopenharmony_ci	struct host_if_drv *hif_drv = vif->hif_drv;
15248c2ecf20Sopenharmony_ci
15258c2ecf20Sopenharmony_ci	if (!hif_drv) {
15268c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
15278c2ecf20Sopenharmony_ci		return -EFAULT;
15288c2ecf20Sopenharmony_ci	}
15298c2ecf20Sopenharmony_ci
15308c2ecf20Sopenharmony_ci	mutex_lock(&vif->wilc->deinit_lock);
15318c2ecf20Sopenharmony_ci
15328c2ecf20Sopenharmony_ci	del_timer_sync(&hif_drv->scan_timer);
15338c2ecf20Sopenharmony_ci	del_timer_sync(&hif_drv->connect_timer);
15348c2ecf20Sopenharmony_ci	del_timer_sync(&vif->periodic_rssi);
15358c2ecf20Sopenharmony_ci	del_timer_sync(&hif_drv->remain_on_ch_timer);
15368c2ecf20Sopenharmony_ci
15378c2ecf20Sopenharmony_ci	if (hif_drv->usr_scan_req.scan_result) {
15388c2ecf20Sopenharmony_ci		hif_drv->usr_scan_req.scan_result(SCAN_EVENT_ABORTED, NULL,
15398c2ecf20Sopenharmony_ci						  hif_drv->usr_scan_req.arg);
15408c2ecf20Sopenharmony_ci		hif_drv->usr_scan_req.scan_result = NULL;
15418c2ecf20Sopenharmony_ci	}
15428c2ecf20Sopenharmony_ci
15438c2ecf20Sopenharmony_ci	hif_drv->hif_state = HOST_IF_IDLE;
15448c2ecf20Sopenharmony_ci
15458c2ecf20Sopenharmony_ci	kfree(hif_drv);
15468c2ecf20Sopenharmony_ci	vif->hif_drv = NULL;
15478c2ecf20Sopenharmony_ci	vif->wilc->clients_count--;
15488c2ecf20Sopenharmony_ci	mutex_unlock(&vif->wilc->deinit_lock);
15498c2ecf20Sopenharmony_ci	return result;
15508c2ecf20Sopenharmony_ci}
15518c2ecf20Sopenharmony_ci
15528c2ecf20Sopenharmony_civoid wilc_network_info_received(struct wilc *wilc, u8 *buffer, u32 length)
15538c2ecf20Sopenharmony_ci{
15548c2ecf20Sopenharmony_ci	int result;
15558c2ecf20Sopenharmony_ci	struct host_if_msg *msg;
15568c2ecf20Sopenharmony_ci	int id;
15578c2ecf20Sopenharmony_ci	struct host_if_drv *hif_drv;
15588c2ecf20Sopenharmony_ci	struct wilc_vif *vif;
15598c2ecf20Sopenharmony_ci
15608c2ecf20Sopenharmony_ci	id = get_unaligned_le32(&buffer[length - 4]);
15618c2ecf20Sopenharmony_ci	vif = wilc_get_vif_from_idx(wilc, id);
15628c2ecf20Sopenharmony_ci	if (!vif)
15638c2ecf20Sopenharmony_ci		return;
15648c2ecf20Sopenharmony_ci	hif_drv = vif->hif_drv;
15658c2ecf20Sopenharmony_ci
15668c2ecf20Sopenharmony_ci	if (!hif_drv) {
15678c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "driver not init[%p]\n", hif_drv);
15688c2ecf20Sopenharmony_ci		return;
15698c2ecf20Sopenharmony_ci	}
15708c2ecf20Sopenharmony_ci
15718c2ecf20Sopenharmony_ci	msg = wilc_alloc_work(vif, handle_rcvd_ntwrk_info, false);
15728c2ecf20Sopenharmony_ci	if (IS_ERR(msg))
15738c2ecf20Sopenharmony_ci		return;
15748c2ecf20Sopenharmony_ci
15758c2ecf20Sopenharmony_ci	msg->body.net_info.frame_len = get_unaligned_le16(&buffer[6]) - 1;
15768c2ecf20Sopenharmony_ci	msg->body.net_info.rssi = buffer[8];
15778c2ecf20Sopenharmony_ci	msg->body.net_info.mgmt = kmemdup(&buffer[9],
15788c2ecf20Sopenharmony_ci					  msg->body.net_info.frame_len,
15798c2ecf20Sopenharmony_ci					  GFP_KERNEL);
15808c2ecf20Sopenharmony_ci	if (!msg->body.net_info.mgmt) {
15818c2ecf20Sopenharmony_ci		kfree(msg);
15828c2ecf20Sopenharmony_ci		return;
15838c2ecf20Sopenharmony_ci	}
15848c2ecf20Sopenharmony_ci
15858c2ecf20Sopenharmony_ci	result = wilc_enqueue_work(msg);
15868c2ecf20Sopenharmony_ci	if (result) {
15878c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
15888c2ecf20Sopenharmony_ci		kfree(msg->body.net_info.mgmt);
15898c2ecf20Sopenharmony_ci		kfree(msg);
15908c2ecf20Sopenharmony_ci	}
15918c2ecf20Sopenharmony_ci}
15928c2ecf20Sopenharmony_ci
15938c2ecf20Sopenharmony_civoid wilc_gnrl_async_info_received(struct wilc *wilc, u8 *buffer, u32 length)
15948c2ecf20Sopenharmony_ci{
15958c2ecf20Sopenharmony_ci	int result;
15968c2ecf20Sopenharmony_ci	struct host_if_msg *msg;
15978c2ecf20Sopenharmony_ci	int id;
15988c2ecf20Sopenharmony_ci	struct host_if_drv *hif_drv;
15998c2ecf20Sopenharmony_ci	struct wilc_vif *vif;
16008c2ecf20Sopenharmony_ci
16018c2ecf20Sopenharmony_ci	mutex_lock(&wilc->deinit_lock);
16028c2ecf20Sopenharmony_ci
16038c2ecf20Sopenharmony_ci	id = get_unaligned_le32(&buffer[length - 4]);
16048c2ecf20Sopenharmony_ci	vif = wilc_get_vif_from_idx(wilc, id);
16058c2ecf20Sopenharmony_ci	if (!vif) {
16068c2ecf20Sopenharmony_ci		mutex_unlock(&wilc->deinit_lock);
16078c2ecf20Sopenharmony_ci		return;
16088c2ecf20Sopenharmony_ci	}
16098c2ecf20Sopenharmony_ci
16108c2ecf20Sopenharmony_ci	hif_drv = vif->hif_drv;
16118c2ecf20Sopenharmony_ci
16128c2ecf20Sopenharmony_ci	if (!hif_drv) {
16138c2ecf20Sopenharmony_ci		mutex_unlock(&wilc->deinit_lock);
16148c2ecf20Sopenharmony_ci		return;
16158c2ecf20Sopenharmony_ci	}
16168c2ecf20Sopenharmony_ci
16178c2ecf20Sopenharmony_ci	if (!hif_drv->conn_info.conn_result) {
16188c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "%s: conn_result is NULL\n", __func__);
16198c2ecf20Sopenharmony_ci		mutex_unlock(&wilc->deinit_lock);
16208c2ecf20Sopenharmony_ci		return;
16218c2ecf20Sopenharmony_ci	}
16228c2ecf20Sopenharmony_ci
16238c2ecf20Sopenharmony_ci	msg = wilc_alloc_work(vif, handle_rcvd_gnrl_async_info, false);
16248c2ecf20Sopenharmony_ci	if (IS_ERR(msg)) {
16258c2ecf20Sopenharmony_ci		mutex_unlock(&wilc->deinit_lock);
16268c2ecf20Sopenharmony_ci		return;
16278c2ecf20Sopenharmony_ci	}
16288c2ecf20Sopenharmony_ci
16298c2ecf20Sopenharmony_ci	msg->body.mac_info.status = buffer[7];
16308c2ecf20Sopenharmony_ci	result = wilc_enqueue_work(msg);
16318c2ecf20Sopenharmony_ci	if (result) {
16328c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
16338c2ecf20Sopenharmony_ci		kfree(msg);
16348c2ecf20Sopenharmony_ci	}
16358c2ecf20Sopenharmony_ci
16368c2ecf20Sopenharmony_ci	mutex_unlock(&wilc->deinit_lock);
16378c2ecf20Sopenharmony_ci}
16388c2ecf20Sopenharmony_ci
16398c2ecf20Sopenharmony_civoid wilc_scan_complete_received(struct wilc *wilc, u8 *buffer, u32 length)
16408c2ecf20Sopenharmony_ci{
16418c2ecf20Sopenharmony_ci	int result;
16428c2ecf20Sopenharmony_ci	int id;
16438c2ecf20Sopenharmony_ci	struct host_if_drv *hif_drv;
16448c2ecf20Sopenharmony_ci	struct wilc_vif *vif;
16458c2ecf20Sopenharmony_ci
16468c2ecf20Sopenharmony_ci	id = get_unaligned_le32(&buffer[length - 4]);
16478c2ecf20Sopenharmony_ci	vif = wilc_get_vif_from_idx(wilc, id);
16488c2ecf20Sopenharmony_ci	if (!vif)
16498c2ecf20Sopenharmony_ci		return;
16508c2ecf20Sopenharmony_ci	hif_drv = vif->hif_drv;
16518c2ecf20Sopenharmony_ci
16528c2ecf20Sopenharmony_ci	if (!hif_drv)
16538c2ecf20Sopenharmony_ci		return;
16548c2ecf20Sopenharmony_ci
16558c2ecf20Sopenharmony_ci	if (hif_drv->usr_scan_req.scan_result) {
16568c2ecf20Sopenharmony_ci		struct host_if_msg *msg;
16578c2ecf20Sopenharmony_ci
16588c2ecf20Sopenharmony_ci		msg = wilc_alloc_work(vif, handle_scan_complete, false);
16598c2ecf20Sopenharmony_ci		if (IS_ERR(msg))
16608c2ecf20Sopenharmony_ci			return;
16618c2ecf20Sopenharmony_ci
16628c2ecf20Sopenharmony_ci		result = wilc_enqueue_work(msg);
16638c2ecf20Sopenharmony_ci		if (result) {
16648c2ecf20Sopenharmony_ci			netdev_err(vif->ndev, "%s: enqueue work failed\n",
16658c2ecf20Sopenharmony_ci				   __func__);
16668c2ecf20Sopenharmony_ci			kfree(msg);
16678c2ecf20Sopenharmony_ci		}
16688c2ecf20Sopenharmony_ci	}
16698c2ecf20Sopenharmony_ci}
16708c2ecf20Sopenharmony_ci
16718c2ecf20Sopenharmony_ciint wilc_remain_on_channel(struct wilc_vif *vif, u64 cookie,
16728c2ecf20Sopenharmony_ci			   u32 duration, u16 chan,
16738c2ecf20Sopenharmony_ci			   void (*expired)(void *, u64),
16748c2ecf20Sopenharmony_ci			   void *user_arg)
16758c2ecf20Sopenharmony_ci{
16768c2ecf20Sopenharmony_ci	struct wilc_remain_ch roc;
16778c2ecf20Sopenharmony_ci	int result;
16788c2ecf20Sopenharmony_ci
16798c2ecf20Sopenharmony_ci	roc.ch = chan;
16808c2ecf20Sopenharmony_ci	roc.expired = expired;
16818c2ecf20Sopenharmony_ci	roc.arg = user_arg;
16828c2ecf20Sopenharmony_ci	roc.duration = duration;
16838c2ecf20Sopenharmony_ci	roc.cookie = cookie;
16848c2ecf20Sopenharmony_ci	result = handle_remain_on_chan(vif, &roc);
16858c2ecf20Sopenharmony_ci	if (result)
16868c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "%s: failed to set remain on channel\n",
16878c2ecf20Sopenharmony_ci			   __func__);
16888c2ecf20Sopenharmony_ci
16898c2ecf20Sopenharmony_ci	return result;
16908c2ecf20Sopenharmony_ci}
16918c2ecf20Sopenharmony_ci
16928c2ecf20Sopenharmony_ciint wilc_listen_state_expired(struct wilc_vif *vif, u64 cookie)
16938c2ecf20Sopenharmony_ci{
16948c2ecf20Sopenharmony_ci	if (!vif->hif_drv) {
16958c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "%s: hif driver is NULL", __func__);
16968c2ecf20Sopenharmony_ci		return -EFAULT;
16978c2ecf20Sopenharmony_ci	}
16988c2ecf20Sopenharmony_ci
16998c2ecf20Sopenharmony_ci	del_timer(&vif->hif_drv->remain_on_ch_timer);
17008c2ecf20Sopenharmony_ci
17018c2ecf20Sopenharmony_ci	return wilc_handle_roc_expired(vif, cookie);
17028c2ecf20Sopenharmony_ci}
17038c2ecf20Sopenharmony_ci
17048c2ecf20Sopenharmony_civoid wilc_frame_register(struct wilc_vif *vif, u16 frame_type, bool reg)
17058c2ecf20Sopenharmony_ci{
17068c2ecf20Sopenharmony_ci	struct wid wid;
17078c2ecf20Sopenharmony_ci	int result;
17088c2ecf20Sopenharmony_ci	struct wilc_reg_frame reg_frame;
17098c2ecf20Sopenharmony_ci
17108c2ecf20Sopenharmony_ci	wid.id = WID_REGISTER_FRAME;
17118c2ecf20Sopenharmony_ci	wid.type = WID_STR;
17128c2ecf20Sopenharmony_ci	wid.size = sizeof(reg_frame);
17138c2ecf20Sopenharmony_ci	wid.val = (u8 *)&reg_frame;
17148c2ecf20Sopenharmony_ci
17158c2ecf20Sopenharmony_ci	memset(&reg_frame, 0x0, sizeof(reg_frame));
17168c2ecf20Sopenharmony_ci
17178c2ecf20Sopenharmony_ci	if (reg)
17188c2ecf20Sopenharmony_ci		reg_frame.reg = 1;
17198c2ecf20Sopenharmony_ci
17208c2ecf20Sopenharmony_ci	switch (frame_type) {
17218c2ecf20Sopenharmony_ci	case IEEE80211_STYPE_ACTION:
17228c2ecf20Sopenharmony_ci		reg_frame.reg_id = WILC_FW_ACTION_FRM_IDX;
17238c2ecf20Sopenharmony_ci		break;
17248c2ecf20Sopenharmony_ci
17258c2ecf20Sopenharmony_ci	case IEEE80211_STYPE_PROBE_REQ:
17268c2ecf20Sopenharmony_ci		reg_frame.reg_id = WILC_FW_PROBE_REQ_IDX;
17278c2ecf20Sopenharmony_ci		break;
17288c2ecf20Sopenharmony_ci
17298c2ecf20Sopenharmony_ci	default:
17308c2ecf20Sopenharmony_ci		break;
17318c2ecf20Sopenharmony_ci	}
17328c2ecf20Sopenharmony_ci	reg_frame.frame_type = cpu_to_le16(frame_type);
17338c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
17348c2ecf20Sopenharmony_ci	if (result)
17358c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "Failed to frame register\n");
17368c2ecf20Sopenharmony_ci}
17378c2ecf20Sopenharmony_ci
17388c2ecf20Sopenharmony_ciint wilc_add_beacon(struct wilc_vif *vif, u32 interval, u32 dtim_period,
17398c2ecf20Sopenharmony_ci		    struct cfg80211_beacon_data *params)
17408c2ecf20Sopenharmony_ci{
17418c2ecf20Sopenharmony_ci	struct wid wid;
17428c2ecf20Sopenharmony_ci	int result;
17438c2ecf20Sopenharmony_ci	u8 *cur_byte;
17448c2ecf20Sopenharmony_ci
17458c2ecf20Sopenharmony_ci	wid.id = WID_ADD_BEACON;
17468c2ecf20Sopenharmony_ci	wid.type = WID_BIN;
17478c2ecf20Sopenharmony_ci	wid.size = params->head_len + params->tail_len + 16;
17488c2ecf20Sopenharmony_ci	wid.val = kzalloc(wid.size, GFP_KERNEL);
17498c2ecf20Sopenharmony_ci	if (!wid.val)
17508c2ecf20Sopenharmony_ci		return -ENOMEM;
17518c2ecf20Sopenharmony_ci
17528c2ecf20Sopenharmony_ci	cur_byte = wid.val;
17538c2ecf20Sopenharmony_ci	put_unaligned_le32(interval, cur_byte);
17548c2ecf20Sopenharmony_ci	cur_byte += 4;
17558c2ecf20Sopenharmony_ci	put_unaligned_le32(dtim_period, cur_byte);
17568c2ecf20Sopenharmony_ci	cur_byte += 4;
17578c2ecf20Sopenharmony_ci	put_unaligned_le32(params->head_len, cur_byte);
17588c2ecf20Sopenharmony_ci	cur_byte += 4;
17598c2ecf20Sopenharmony_ci
17608c2ecf20Sopenharmony_ci	if (params->head_len > 0)
17618c2ecf20Sopenharmony_ci		memcpy(cur_byte, params->head, params->head_len);
17628c2ecf20Sopenharmony_ci	cur_byte += params->head_len;
17638c2ecf20Sopenharmony_ci
17648c2ecf20Sopenharmony_ci	put_unaligned_le32(params->tail_len, cur_byte);
17658c2ecf20Sopenharmony_ci	cur_byte += 4;
17668c2ecf20Sopenharmony_ci
17678c2ecf20Sopenharmony_ci	if (params->tail_len > 0)
17688c2ecf20Sopenharmony_ci		memcpy(cur_byte, params->tail, params->tail_len);
17698c2ecf20Sopenharmony_ci
17708c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
17718c2ecf20Sopenharmony_ci	if (result)
17728c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "Failed to send add beacon\n");
17738c2ecf20Sopenharmony_ci
17748c2ecf20Sopenharmony_ci	kfree(wid.val);
17758c2ecf20Sopenharmony_ci
17768c2ecf20Sopenharmony_ci	return result;
17778c2ecf20Sopenharmony_ci}
17788c2ecf20Sopenharmony_ci
17798c2ecf20Sopenharmony_ciint wilc_del_beacon(struct wilc_vif *vif)
17808c2ecf20Sopenharmony_ci{
17818c2ecf20Sopenharmony_ci	int result;
17828c2ecf20Sopenharmony_ci	struct wid wid;
17838c2ecf20Sopenharmony_ci	u8 del_beacon = 0;
17848c2ecf20Sopenharmony_ci
17858c2ecf20Sopenharmony_ci	wid.id = WID_DEL_BEACON;
17868c2ecf20Sopenharmony_ci	wid.type = WID_CHAR;
17878c2ecf20Sopenharmony_ci	wid.size = sizeof(char);
17888c2ecf20Sopenharmony_ci	wid.val = &del_beacon;
17898c2ecf20Sopenharmony_ci
17908c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
17918c2ecf20Sopenharmony_ci	if (result)
17928c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "Failed to send delete beacon\n");
17938c2ecf20Sopenharmony_ci
17948c2ecf20Sopenharmony_ci	return result;
17958c2ecf20Sopenharmony_ci}
17968c2ecf20Sopenharmony_ci
17978c2ecf20Sopenharmony_ciint wilc_add_station(struct wilc_vif *vif, const u8 *mac,
17988c2ecf20Sopenharmony_ci		     struct station_parameters *params)
17998c2ecf20Sopenharmony_ci{
18008c2ecf20Sopenharmony_ci	struct wid wid;
18018c2ecf20Sopenharmony_ci	int result;
18028c2ecf20Sopenharmony_ci	u8 *cur_byte;
18038c2ecf20Sopenharmony_ci
18048c2ecf20Sopenharmony_ci	wid.id = WID_ADD_STA;
18058c2ecf20Sopenharmony_ci	wid.type = WID_BIN;
18068c2ecf20Sopenharmony_ci	wid.size = WILC_ADD_STA_LENGTH + params->supported_rates_len;
18078c2ecf20Sopenharmony_ci	wid.val = kmalloc(wid.size, GFP_KERNEL);
18088c2ecf20Sopenharmony_ci	if (!wid.val)
18098c2ecf20Sopenharmony_ci		return -ENOMEM;
18108c2ecf20Sopenharmony_ci
18118c2ecf20Sopenharmony_ci	cur_byte = wid.val;
18128c2ecf20Sopenharmony_ci	wilc_hif_pack_sta_param(cur_byte, mac, params);
18138c2ecf20Sopenharmony_ci
18148c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
18158c2ecf20Sopenharmony_ci	if (result != 0)
18168c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "Failed to send add station\n");
18178c2ecf20Sopenharmony_ci
18188c2ecf20Sopenharmony_ci	kfree(wid.val);
18198c2ecf20Sopenharmony_ci
18208c2ecf20Sopenharmony_ci	return result;
18218c2ecf20Sopenharmony_ci}
18228c2ecf20Sopenharmony_ci
18238c2ecf20Sopenharmony_ciint wilc_del_station(struct wilc_vif *vif, const u8 *mac_addr)
18248c2ecf20Sopenharmony_ci{
18258c2ecf20Sopenharmony_ci	struct wid wid;
18268c2ecf20Sopenharmony_ci	int result;
18278c2ecf20Sopenharmony_ci
18288c2ecf20Sopenharmony_ci	wid.id = WID_REMOVE_STA;
18298c2ecf20Sopenharmony_ci	wid.type = WID_BIN;
18308c2ecf20Sopenharmony_ci	wid.size = ETH_ALEN;
18318c2ecf20Sopenharmony_ci	wid.val = kzalloc(wid.size, GFP_KERNEL);
18328c2ecf20Sopenharmony_ci	if (!wid.val)
18338c2ecf20Sopenharmony_ci		return -ENOMEM;
18348c2ecf20Sopenharmony_ci
18358c2ecf20Sopenharmony_ci	if (!mac_addr)
18368c2ecf20Sopenharmony_ci		eth_broadcast_addr(wid.val);
18378c2ecf20Sopenharmony_ci	else
18388c2ecf20Sopenharmony_ci		ether_addr_copy(wid.val, mac_addr);
18398c2ecf20Sopenharmony_ci
18408c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
18418c2ecf20Sopenharmony_ci	if (result)
18428c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "Failed to del station\n");
18438c2ecf20Sopenharmony_ci
18448c2ecf20Sopenharmony_ci	kfree(wid.val);
18458c2ecf20Sopenharmony_ci
18468c2ecf20Sopenharmony_ci	return result;
18478c2ecf20Sopenharmony_ci}
18488c2ecf20Sopenharmony_ci
18498c2ecf20Sopenharmony_ciint wilc_del_allstation(struct wilc_vif *vif, u8 mac_addr[][ETH_ALEN])
18508c2ecf20Sopenharmony_ci{
18518c2ecf20Sopenharmony_ci	struct wid wid;
18528c2ecf20Sopenharmony_ci	int result;
18538c2ecf20Sopenharmony_ci	int i;
18548c2ecf20Sopenharmony_ci	u8 assoc_sta = 0;
18558c2ecf20Sopenharmony_ci	struct wilc_del_all_sta del_sta;
18568c2ecf20Sopenharmony_ci
18578c2ecf20Sopenharmony_ci	memset(&del_sta, 0x0, sizeof(del_sta));
18588c2ecf20Sopenharmony_ci	for (i = 0; i < WILC_MAX_NUM_STA; i++) {
18598c2ecf20Sopenharmony_ci		if (!is_zero_ether_addr(mac_addr[i])) {
18608c2ecf20Sopenharmony_ci			assoc_sta++;
18618c2ecf20Sopenharmony_ci			ether_addr_copy(del_sta.mac[i], mac_addr[i]);
18628c2ecf20Sopenharmony_ci		}
18638c2ecf20Sopenharmony_ci	}
18648c2ecf20Sopenharmony_ci
18658c2ecf20Sopenharmony_ci	if (!assoc_sta)
18668c2ecf20Sopenharmony_ci		return 0;
18678c2ecf20Sopenharmony_ci
18688c2ecf20Sopenharmony_ci	del_sta.assoc_sta = assoc_sta;
18698c2ecf20Sopenharmony_ci
18708c2ecf20Sopenharmony_ci	wid.id = WID_DEL_ALL_STA;
18718c2ecf20Sopenharmony_ci	wid.type = WID_STR;
18728c2ecf20Sopenharmony_ci	wid.size = (assoc_sta * ETH_ALEN) + 1;
18738c2ecf20Sopenharmony_ci	wid.val = (u8 *)&del_sta;
18748c2ecf20Sopenharmony_ci
18758c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
18768c2ecf20Sopenharmony_ci	if (result)
18778c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "Failed to send delete all station\n");
18788c2ecf20Sopenharmony_ci
18798c2ecf20Sopenharmony_ci	return result;
18808c2ecf20Sopenharmony_ci}
18818c2ecf20Sopenharmony_ci
18828c2ecf20Sopenharmony_ciint wilc_edit_station(struct wilc_vif *vif, const u8 *mac,
18838c2ecf20Sopenharmony_ci		      struct station_parameters *params)
18848c2ecf20Sopenharmony_ci{
18858c2ecf20Sopenharmony_ci	struct wid wid;
18868c2ecf20Sopenharmony_ci	int result;
18878c2ecf20Sopenharmony_ci	u8 *cur_byte;
18888c2ecf20Sopenharmony_ci
18898c2ecf20Sopenharmony_ci	wid.id = WID_EDIT_STA;
18908c2ecf20Sopenharmony_ci	wid.type = WID_BIN;
18918c2ecf20Sopenharmony_ci	wid.size = WILC_ADD_STA_LENGTH + params->supported_rates_len;
18928c2ecf20Sopenharmony_ci	wid.val = kmalloc(wid.size, GFP_KERNEL);
18938c2ecf20Sopenharmony_ci	if (!wid.val)
18948c2ecf20Sopenharmony_ci		return -ENOMEM;
18958c2ecf20Sopenharmony_ci
18968c2ecf20Sopenharmony_ci	cur_byte = wid.val;
18978c2ecf20Sopenharmony_ci	wilc_hif_pack_sta_param(cur_byte, mac, params);
18988c2ecf20Sopenharmony_ci
18998c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
19008c2ecf20Sopenharmony_ci	if (result)
19018c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "Failed to send edit station\n");
19028c2ecf20Sopenharmony_ci
19038c2ecf20Sopenharmony_ci	kfree(wid.val);
19048c2ecf20Sopenharmony_ci	return result;
19058c2ecf20Sopenharmony_ci}
19068c2ecf20Sopenharmony_ci
19078c2ecf20Sopenharmony_ciint wilc_set_power_mgmt(struct wilc_vif *vif, bool enabled, u32 timeout)
19088c2ecf20Sopenharmony_ci{
19098c2ecf20Sopenharmony_ci	struct wid wid;
19108c2ecf20Sopenharmony_ci	int result;
19118c2ecf20Sopenharmony_ci	s8 power_mode;
19128c2ecf20Sopenharmony_ci
19138c2ecf20Sopenharmony_ci	if (enabled)
19148c2ecf20Sopenharmony_ci		power_mode = WILC_FW_MIN_FAST_PS;
19158c2ecf20Sopenharmony_ci	else
19168c2ecf20Sopenharmony_ci		power_mode = WILC_FW_NO_POWERSAVE;
19178c2ecf20Sopenharmony_ci
19188c2ecf20Sopenharmony_ci	wid.id = WID_POWER_MANAGEMENT;
19198c2ecf20Sopenharmony_ci	wid.val = &power_mode;
19208c2ecf20Sopenharmony_ci	wid.size = sizeof(char);
19218c2ecf20Sopenharmony_ci	result = wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
19228c2ecf20Sopenharmony_ci	if (result)
19238c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "Failed to send power management\n");
19248c2ecf20Sopenharmony_ci
19258c2ecf20Sopenharmony_ci	return result;
19268c2ecf20Sopenharmony_ci}
19278c2ecf20Sopenharmony_ci
19288c2ecf20Sopenharmony_ciint wilc_setup_multicast_filter(struct wilc_vif *vif, u32 enabled, u32 count,
19298c2ecf20Sopenharmony_ci				u8 *mc_list)
19308c2ecf20Sopenharmony_ci{
19318c2ecf20Sopenharmony_ci	int result;
19328c2ecf20Sopenharmony_ci	struct host_if_msg *msg;
19338c2ecf20Sopenharmony_ci
19348c2ecf20Sopenharmony_ci	msg = wilc_alloc_work(vif, handle_set_mcast_filter, false);
19358c2ecf20Sopenharmony_ci	if (IS_ERR(msg))
19368c2ecf20Sopenharmony_ci		return PTR_ERR(msg);
19378c2ecf20Sopenharmony_ci
19388c2ecf20Sopenharmony_ci	msg->body.mc_info.enabled = enabled;
19398c2ecf20Sopenharmony_ci	msg->body.mc_info.cnt = count;
19408c2ecf20Sopenharmony_ci	msg->body.mc_info.mc_list = mc_list;
19418c2ecf20Sopenharmony_ci
19428c2ecf20Sopenharmony_ci	result = wilc_enqueue_work(msg);
19438c2ecf20Sopenharmony_ci	if (result) {
19448c2ecf20Sopenharmony_ci		netdev_err(vif->ndev, "%s: enqueue work failed\n", __func__);
19458c2ecf20Sopenharmony_ci		kfree(msg);
19468c2ecf20Sopenharmony_ci	}
19478c2ecf20Sopenharmony_ci	return result;
19488c2ecf20Sopenharmony_ci}
19498c2ecf20Sopenharmony_ci
19508c2ecf20Sopenharmony_ciint wilc_set_tx_power(struct wilc_vif *vif, u8 tx_power)
19518c2ecf20Sopenharmony_ci{
19528c2ecf20Sopenharmony_ci	struct wid wid;
19538c2ecf20Sopenharmony_ci
19548c2ecf20Sopenharmony_ci	wid.id = WID_TX_POWER;
19558c2ecf20Sopenharmony_ci	wid.type = WID_CHAR;
19568c2ecf20Sopenharmony_ci	wid.val = &tx_power;
19578c2ecf20Sopenharmony_ci	wid.size = sizeof(char);
19588c2ecf20Sopenharmony_ci
19598c2ecf20Sopenharmony_ci	return wilc_send_config_pkt(vif, WILC_SET_CFG, &wid, 1);
19608c2ecf20Sopenharmony_ci}
19618c2ecf20Sopenharmony_ci
19628c2ecf20Sopenharmony_ciint wilc_get_tx_power(struct wilc_vif *vif, u8 *tx_power)
19638c2ecf20Sopenharmony_ci{
19648c2ecf20Sopenharmony_ci	struct wid wid;
19658c2ecf20Sopenharmony_ci
19668c2ecf20Sopenharmony_ci	wid.id = WID_TX_POWER;
19678c2ecf20Sopenharmony_ci	wid.type = WID_CHAR;
19688c2ecf20Sopenharmony_ci	wid.val = tx_power;
19698c2ecf20Sopenharmony_ci	wid.size = sizeof(char);
19708c2ecf20Sopenharmony_ci
19718c2ecf20Sopenharmony_ci	return wilc_send_config_pkt(vif, WILC_GET_CFG, &wid, 1);
19728c2ecf20Sopenharmony_ci}
1973