1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
7 #include "wilc_wlan_if.h"
9 #include "wilc_wlan_cfg.h"
10 #include "coreconfigurator.h"
26 u8 firmware_version[129];
30 u8 hw_product_version[33];
41 static struct wilc_mac_cfg g_mac;
43 static struct wilc_cfg_byte g_cfg_byte[] = {
45 {WID_CURRENT_TX_RATE, 0},
46 {WID_CURRENT_CHANNEL, 0},
48 {WID_11G_OPERATING_MODE, 0},
53 {WID_POWER_MANAGEMENT, 0},
57 {WID_LISTEN_INTERVAL, 0},
61 {WID_REKEY_POLICY, 0},
62 {WID_SHORT_SLOT_ALLOWED, 0},
63 {WID_START_SCAN_REQ, 0},
66 {WID_AUTO_RX_SENSITIVITY, 0},
67 {WID_DATAFLOW_CONTROL, 0},
69 {WID_11N_PROT_MECH, 0},
70 {WID_11N_ERP_PROT_TYPE, 0},
72 {WID_11N_OPERATING_MODE, 0},
73 {WID_11N_OBSS_NONHT_DETECTION, 0},
74 {WID_11N_HT_PROT_TYPE, 0},
75 {WID_11N_RIFS_PROT_ENABLE, 0},
76 {WID_11N_SMPS_MODE, 0},
77 {WID_11N_CURRENT_TX_MCS, 0},
78 {WID_11N_SHORT_GI_ENABLE, 0},
80 {WID_TX_ABORT_CONFIG, 0},
81 {WID_11N_IMMEDIATE_BA_ENABLED, 0},
82 {WID_11N_TXOP_PROT_DISABLE, 0},
86 static struct wilc_cfg_hword g_cfg_hword[] = {
87 {WID_LINK_LOSS_THRESHOLD, 0},
88 {WID_RTS_THRESHOLD, 0},
89 {WID_FRAG_THRESHOLD, 0},
90 {WID_SHORT_RETRY_LIMIT, 0},
91 {WID_LONG_RETRY_LIMIT, 0},
92 {WID_BEACON_INTERVAL, 0},
94 {WID_ACTIVE_SCAN_TIME, 0},
95 {WID_PASSIVE_SCAN_TIME, 0},
96 {WID_SITE_SURVEY_SCAN_TIME, 0},
97 {WID_JOIN_START_TIMEOUT, 0},
98 {WID_AUTH_TIMEOUT, 0},
99 {WID_ASOC_TIMEOUT, 0},
100 {WID_11I_PROTOCOL_TIMEOUT, 0},
101 {WID_EAPOL_RESPONSE_TIMEOUT, 0},
102 {WID_11N_SIG_QUAL_VAL, 0},
103 {WID_CCA_THRESHOLD, 0},
107 static struct wilc_cfg_word g_cfg_word[] = {
108 {WID_FAILED_COUNT, 0},
109 {WID_RETRY_COUNT, 0},
110 {WID_MULTIPLE_RETRY_COUNT, 0},
111 {WID_FRAME_DUPLICATE_COUNT, 0},
112 {WID_ACK_FAILURE_COUNT, 0},
113 {WID_RECEIVED_FRAGMENT_COUNT, 0},
114 {WID_MCAST_RECEIVED_FRAME_COUNT, 0},
115 {WID_FCS_ERROR_COUNT, 0},
116 {WID_SUCCESS_FRAME_COUNT, 0},
117 {WID_TX_FRAGMENT_COUNT, 0},
118 {WID_TX_MULTICAST_FRAME_COUNT, 0},
119 {WID_RTS_SUCCESS_COUNT, 0},
120 {WID_RTS_FAILURE_COUNT, 0},
121 {WID_WEP_UNDECRYPTABLE_COUNT, 0},
122 {WID_REKEY_PERIOD, 0},
123 {WID_REKEY_PACKET_COUNT, 0},
124 {WID_HW_RX_COUNT, 0},
125 {WID_GET_INACTIVE_TIME, 0},
130 static struct wilc_cfg_str g_cfg_str[] = {
131 {WID_SSID, g_mac.ssid}, /* 33 + 1 bytes */
132 {WID_FIRMWARE_VERSION, g_mac.firmware_version},
133 {WID_OPERATIONAL_RATE_SET, g_mac.supp_rate},
134 {WID_BSSID, g_mac.bssid}, /* 6 bytes */
135 {WID_WEP_KEY_VALUE, g_mac.wep_key}, /* 27 bytes */
136 {WID_11I_PSK, g_mac.i_psk}, /* 65 bytes */
137 {WID_HARDWARE_VERSION, g_mac.hw_product_version},
138 {WID_MAC_ADDR, g_mac.mac_address},
139 {WID_PHY_VERSION, g_mac.phyversion},
140 {WID_SUPP_USERNAME, g_mac.supp_username},
141 {WID_SUPP_PASSWORD, g_mac.supp_password},
142 {WID_SITE_SURVEY_RESULTS, g_mac.scan_result},
143 {WID_SITE_SURVEY_RESULTS, g_mac.scan_result1},
144 {WID_ASSOC_REQ_INFO, g_mac.assoc_req},
145 {WID_ASSOC_RES_INFO, g_mac.assoc_rsp},
146 {WID_FIRMWARE_INFO, g_mac.firmware_version},
147 {WID_IP_ADDRESS, g_mac.ip_address},
151 /********************************************
153 * Configuration Functions
155 ********************************************/
157 static int wilc_wlan_cfg_set_byte(u8 *frame, u32 offset, u16 id, u8 val8)
161 if ((offset + 4) >= MAX_CFG_FRAME_SIZE)
164 buf = &frame[offset];
167 buf[1] = (u8)(id >> 8);
174 static int wilc_wlan_cfg_set_hword(u8 *frame, u32 offset, u16 id, u16 val16)
178 if ((offset + 5) >= MAX_CFG_FRAME_SIZE)
181 buf = &frame[offset];
184 buf[1] = (u8)(id >> 8);
188 buf[5] = (u8)(val16 >> 8);
193 static int wilc_wlan_cfg_set_word(u8 *frame, u32 offset, u16 id, u32 val32)
197 if ((offset + 7) >= MAX_CFG_FRAME_SIZE)
200 buf = &frame[offset];
203 buf[1] = (u8)(id >> 8);
207 buf[5] = (u8)(val32 >> 8);
208 buf[6] = (u8)(val32 >> 16);
209 buf[7] = (u8)(val32 >> 24);
214 static int wilc_wlan_cfg_set_str(u8 *frame, u32 offset, u16 id, u8 *str,
219 if ((offset + size + 4) >= MAX_CFG_FRAME_SIZE)
222 buf = &frame[offset];
225 buf[1] = (u8)(id >> 8);
227 buf[3] = (u8)(size >> 8);
229 if (str && size != 0)
230 memcpy(&buf[4], str, size);
235 static int wilc_wlan_cfg_set_bin(u8 *frame, u32 offset, u16 id, u8 *b, u32 size)
241 if ((offset + size + 5) >= MAX_CFG_FRAME_SIZE)
244 buf = &frame[offset];
246 buf[1] = (u8)(id >> 8);
248 buf[3] = (u8)(size >> 8);
250 if ((b) && size != 0) {
251 memcpy(&buf[4], b, size);
252 for (i = 0; i < size; i++)
253 checksum += buf[i + 4];
256 buf[size + 4] = checksum;
261 /********************************************
263 * Configuration Response Functions
265 ********************************************/
267 #define GET_WID_TYPE(wid) (((wid) >> 12) & 0x7)
268 static void wilc_wlan_parse_response_frame(u8 *info, int size)
275 wid = info[0] | (info[1] << 8);
277 switch (GET_WID_TYPE(wid)) {
280 if (g_cfg_byte[i].id == WID_NIL)
283 if (g_cfg_byte[i].id == wid) {
284 g_cfg_byte[i].val = info[4];
294 if (g_cfg_hword[i].id == WID_NIL)
297 if (g_cfg_hword[i].id == wid) {
298 g_cfg_hword[i].val = (info[4] |
309 if (g_cfg_word[i].id == WID_NIL)
312 if (g_cfg_word[i].id == wid) {
313 g_cfg_word[i].val = (info[4] |
326 if (g_cfg_str[i].id == WID_NIL)
329 if (g_cfg_str[i].id == wid) {
330 if (wid == WID_SITE_SURVEY_RESULTS) {
336 memcpy(g_cfg_str[i].str, &info[2],
353 static int wilc_wlan_parse_info_frame(u8 *info, int size)
355 struct wilc_mac_cfg *pd = &g_mac;
357 int type = WILC_CFG_RSP_STATUS;
359 wid = info[0] | (info[1] << 8);
363 if (len == 1 && wid == WID_STATUS) {
364 pd->mac_status = info[3];
365 type = WILC_CFG_RSP_STATUS;
371 /********************************************
373 * Configuration Exported Functions
375 ********************************************/
377 int wilc_wlan_cfg_set_wid(u8 *frame, u32 offset, u16 id, u8 *buf, int size)
379 u8 type = (id >> 12) & 0xf;
385 ret = wilc_wlan_cfg_set_byte(frame, offset, id, *buf);
390 ret = wilc_wlan_cfg_set_hword(frame, offset, id,
396 ret = wilc_wlan_cfg_set_word(frame, offset, id,
401 ret = wilc_wlan_cfg_set_str(frame, offset, id, buf, size);
405 ret = wilc_wlan_cfg_set_bin(frame, offset, id, buf, size);
412 int wilc_wlan_cfg_get_wid(u8 *frame, u32 offset, u16 id)
416 if ((offset + 2) >= MAX_CFG_FRAME_SIZE)
419 buf = &frame[offset];
422 buf[1] = (u8)(id >> 8);
427 int wilc_wlan_cfg_get_wid_value(u16 wid, u8 *buffer, u32 buffer_size)
429 u32 type = (wid >> 12) & 0xf;
432 if (wid == WID_STATUS) {
433 *((u32 *)buffer) = g_mac.mac_status;
438 if (type == CFG_BYTE_CMD) {
440 if (g_cfg_byte[i].id == WID_NIL)
443 if (g_cfg_byte[i].id == wid) {
444 memcpy(buffer, &g_cfg_byte[i].val, 1);
450 } else if (type == CFG_HWORD_CMD) {
452 if (g_cfg_hword[i].id == WID_NIL)
455 if (g_cfg_hword[i].id == wid) {
456 memcpy(buffer, &g_cfg_hword[i].val, 2);
462 } else if (type == CFG_WORD_CMD) {
464 if (g_cfg_word[i].id == WID_NIL)
467 if (g_cfg_word[i].id == wid) {
468 memcpy(buffer, &g_cfg_word[i].val, 4);
474 } else if (type == CFG_STR_CMD) {
476 u32 id = g_cfg_str[i].id;
482 u32 size = g_cfg_str[i].str[0] |
483 (g_cfg_str[i].str[1] << 8);
485 if (buffer_size >= size) {
486 if (id == WID_SITE_SURVEY_RESULTS) {
492 memcpy(buffer, &g_cfg_str[i].str[2],
505 int wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size,
506 struct wilc_cfg_rsp *rsp)
513 msg_id = frame[1]; /* seq no */
518 * The valid types of response messages are
520 * 'I' (Information), and
521 * 'N' (Network Information)
526 wilc_wlan_parse_response_frame(frame, size);
527 rsp->type = WILC_CFG_RSP;
528 rsp->seq_no = msg_id;
532 rsp->type = wilc_wlan_parse_info_frame(frame, size);
533 rsp->seq_no = msg_id;
534 /*call host interface info parse as well*/
535 wilc_gnrl_async_info_received(wilc, frame - 4, size + 4);
539 wilc_network_info_received(wilc, frame - 4, size + 4);
544 wilc_scan_complete_received(wilc, frame - 4, size + 4);
549 rsp->seq_no = msg_id;
557 int wilc_wlan_cfg_init(void)
559 memset((void *)&g_mac, 0, sizeof(struct wilc_mac_cfg));