1 // SPDX-License-Identifier: GPL-2.0
2 /* ////////////////////////////////////////////////////////////////////////// */
4 /* Copyright (c) Atmel Corporation. All rights reserved. */
6 /* Module Name: wilc_wlan_cfg.c */
9 /* ///////////////////////////////////////////////////////////////////////// */
11 #include <linux/string.h>
12 #include "wilc_wlan_if.h"
13 #include "wilc_wlan.h"
14 #include "wilc_wlan_cfg.h"
15 #include "coreconfigurator.h"
17 /********************************************
21 ********************************************/
36 u8 firmware_version[129];
40 u8 hw_product_version[33];
51 static struct wilc_mac_cfg g_mac;
53 static struct wilc_cfg_byte g_cfg_byte[] = {
55 {WID_CURRENT_TX_RATE, 0},
56 {WID_CURRENT_CHANNEL, 0},
58 {WID_11G_OPERATING_MODE, 0},
63 {WID_POWER_MANAGEMENT, 0},
67 {WID_LISTEN_INTERVAL, 0},
71 {WID_REKEY_POLICY, 0},
72 {WID_SHORT_SLOT_ALLOWED, 0},
73 {WID_START_SCAN_REQ, 0},
76 {WID_AUTO_RX_SENSITIVITY, 0},
77 {WID_DATAFLOW_CONTROL, 0},
79 {WID_11N_PROT_MECH, 0},
80 {WID_11N_ERP_PROT_TYPE, 0},
82 {WID_11N_OPERATING_MODE, 0},
83 {WID_11N_OBSS_NONHT_DETECTION, 0},
84 {WID_11N_HT_PROT_TYPE, 0},
85 {WID_11N_RIFS_PROT_ENABLE, 0},
86 {WID_11N_SMPS_MODE, 0},
87 {WID_11N_CURRENT_TX_MCS, 0},
88 {WID_11N_SHORT_GI_ENABLE, 0},
90 {WID_TX_ABORT_CONFIG, 0},
91 {WID_11N_IMMEDIATE_BA_ENABLED, 0},
92 {WID_11N_TXOP_PROT_DISABLE, 0},
96 static struct wilc_cfg_hword g_cfg_hword[] = {
97 {WID_LINK_LOSS_THRESHOLD, 0},
98 {WID_RTS_THRESHOLD, 0},
99 {WID_FRAG_THRESHOLD, 0},
100 {WID_SHORT_RETRY_LIMIT, 0},
101 {WID_LONG_RETRY_LIMIT, 0},
102 {WID_BEACON_INTERVAL, 0},
104 {WID_ACTIVE_SCAN_TIME, 0},
105 {WID_PASSIVE_SCAN_TIME, 0},
106 {WID_SITE_SURVEY_SCAN_TIME, 0},
107 {WID_JOIN_START_TIMEOUT, 0},
108 {WID_AUTH_TIMEOUT, 0},
109 {WID_ASOC_TIMEOUT, 0},
110 {WID_11I_PROTOCOL_TIMEOUT, 0},
111 {WID_EAPOL_RESPONSE_TIMEOUT, 0},
112 {WID_11N_SIG_QUAL_VAL, 0},
113 {WID_CCA_THRESHOLD, 0},
117 static struct wilc_cfg_word g_cfg_word[] = {
118 {WID_FAILED_COUNT, 0},
119 {WID_RETRY_COUNT, 0},
120 {WID_MULTIPLE_RETRY_COUNT, 0},
121 {WID_FRAME_DUPLICATE_COUNT, 0},
122 {WID_ACK_FAILURE_COUNT, 0},
123 {WID_RECEIVED_FRAGMENT_COUNT, 0},
124 {WID_MCAST_RECEIVED_FRAME_COUNT, 0},
125 {WID_FCS_ERROR_COUNT, 0},
126 {WID_SUCCESS_FRAME_COUNT, 0},
127 {WID_TX_FRAGMENT_COUNT, 0},
128 {WID_TX_MULTICAST_FRAME_COUNT, 0},
129 {WID_RTS_SUCCESS_COUNT, 0},
130 {WID_RTS_FAILURE_COUNT, 0},
131 {WID_WEP_UNDECRYPTABLE_COUNT, 0},
132 {WID_REKEY_PERIOD, 0},
133 {WID_REKEY_PACKET_COUNT, 0},
134 {WID_HW_RX_COUNT, 0},
135 {WID_GET_INACTIVE_TIME, 0},
140 static struct wilc_cfg_str g_cfg_str[] = {
141 {WID_SSID, g_mac.ssid}, /* 33 + 1 bytes */
142 {WID_FIRMWARE_VERSION, g_mac.firmware_version},
143 {WID_OPERATIONAL_RATE_SET, g_mac.supp_rate},
144 {WID_BSSID, g_mac.bssid}, /* 6 bytes */
145 {WID_WEP_KEY_VALUE, g_mac.wep_key}, /* 27 bytes */
146 {WID_11I_PSK, g_mac.i_psk}, /* 65 bytes */
147 {WID_HARDWARE_VERSION, g_mac.hw_product_version},
148 {WID_MAC_ADDR, g_mac.mac_address},
149 {WID_PHY_VERSION, g_mac.phyversion},
150 {WID_SUPP_USERNAME, g_mac.supp_username},
151 {WID_SUPP_PASSWORD, g_mac.supp_password},
152 {WID_SITE_SURVEY_RESULTS, g_mac.scan_result},
153 {WID_SITE_SURVEY_RESULTS, g_mac.scan_result1},
154 {WID_ASSOC_REQ_INFO, g_mac.assoc_req},
155 {WID_ASSOC_RES_INFO, g_mac.assoc_rsp},
156 {WID_FIRMWARE_INFO, g_mac.firmware_version},
157 {WID_IP_ADDRESS, g_mac.ip_address},
161 /********************************************
163 * Configuration Functions
165 ********************************************/
167 static int wilc_wlan_cfg_set_byte(u8 *frame, u32 offset, u16 id, u8 val8)
171 if ((offset + 4) >= MAX_CFG_FRAME_SIZE)
174 buf = &frame[offset];
177 buf[1] = (u8)(id >> 8);
184 static int wilc_wlan_cfg_set_hword(u8 *frame, u32 offset, u16 id, u16 val16)
188 if ((offset + 5) >= MAX_CFG_FRAME_SIZE)
191 buf = &frame[offset];
194 buf[1] = (u8)(id >> 8);
198 buf[5] = (u8)(val16 >> 8);
203 static int wilc_wlan_cfg_set_word(u8 *frame, u32 offset, u16 id, u32 val32)
207 if ((offset + 7) >= MAX_CFG_FRAME_SIZE)
210 buf = &frame[offset];
213 buf[1] = (u8)(id >> 8);
217 buf[5] = (u8)(val32 >> 8);
218 buf[6] = (u8)(val32 >> 16);
219 buf[7] = (u8)(val32 >> 24);
224 static int wilc_wlan_cfg_set_str(u8 *frame, u32 offset, u16 id, u8 *str, u32 size)
228 if ((offset + size + 4) >= MAX_CFG_FRAME_SIZE)
231 buf = &frame[offset];
234 buf[1] = (u8)(id >> 8);
236 buf[3] = (u8)(size >> 8);
238 if ((str) && (size != 0))
239 memcpy(&buf[4], str, size);
244 static int wilc_wlan_cfg_set_bin(u8 *frame, u32 offset, u16 id, u8 *b, u32 size)
250 if ((offset + size + 5) >= MAX_CFG_FRAME_SIZE)
253 buf = &frame[offset];
255 buf[1] = (u8)(id >> 8);
257 buf[3] = (u8)(size >> 8);
259 if ((b) && (size != 0)) {
260 memcpy(&buf[4], b, size);
261 for (i = 0; i < size; i++)
262 checksum += buf[i + 4];
265 buf[size + 4] = checksum;
270 /********************************************
272 * Configuration Response Functions
274 ********************************************/
276 static void wilc_wlan_parse_response_frame(u8 *info, int size)
278 u32 wid, len = 0, i = 0;
282 wid = info[0] | (info[1] << 8);
283 wid = cpu_to_le32(wid);
285 switch ((wid >> 12) & 0x7) {
288 if (g_cfg_byte[i].id == WID_NIL)
291 if (g_cfg_byte[i].id == wid) {
292 g_cfg_byte[i].val = info[4];
302 if (g_cfg_hword[i].id == WID_NIL)
305 if (g_cfg_hword[i].id == wid) {
307 cpu_to_le16(info[4] |
318 if (g_cfg_word[i].id == WID_NIL)
321 if (g_cfg_word[i].id == wid) {
323 cpu_to_le32(info[4] |
336 if (g_cfg_str[i].id == WID_NIL)
339 if (g_cfg_str[i].id == wid) {
340 if (wid == WID_SITE_SURVEY_RESULTS) {
346 memcpy(g_cfg_str[i].str, &info[2],
363 static int wilc_wlan_parse_info_frame(u8 *info, int size)
365 struct wilc_mac_cfg *pd = &g_mac;
367 int type = WILC_CFG_RSP_STATUS;
369 wid = info[0] | (info[1] << 8);
373 if ((len == 1) && (wid == WID_STATUS)) {
374 pd->mac_status = info[3];
375 type = WILC_CFG_RSP_STATUS;
381 /********************************************
383 * Configuration Exported Functions
385 ********************************************/
387 int wilc_wlan_cfg_set_wid(u8 *frame, u32 offset, u16 id, u8 *buf, int size)
389 u8 type = (id >> 12) & 0xf;
395 ret = wilc_wlan_cfg_set_byte(frame, offset, id, *buf);
400 ret = wilc_wlan_cfg_set_hword(frame, offset, id,
406 ret = wilc_wlan_cfg_set_word(frame, offset, id,
411 ret = wilc_wlan_cfg_set_str(frame, offset, id, buf, size);
415 ret = wilc_wlan_cfg_set_bin(frame, offset, id, buf, size);
422 int wilc_wlan_cfg_get_wid(u8 *frame, u32 offset, u16 id)
426 if ((offset + 2) >= MAX_CFG_FRAME_SIZE)
429 buf = &frame[offset];
432 buf[1] = (u8)(id >> 8);
437 int wilc_wlan_cfg_get_wid_value(u16 wid, u8 *buffer, u32 buffer_size)
439 u32 type = (wid >> 12) & 0xf;
442 if (wid == WID_STATUS) {
443 *((u32 *)buffer) = g_mac.mac_status;
448 if (type == CFG_BYTE_CMD) {
450 if (g_cfg_byte[i].id == WID_NIL)
453 if (g_cfg_byte[i].id == wid) {
454 memcpy(buffer, &g_cfg_byte[i].val, 1);
460 } else if (type == CFG_HWORD_CMD) {
462 if (g_cfg_hword[i].id == WID_NIL)
465 if (g_cfg_hword[i].id == wid) {
466 memcpy(buffer, &g_cfg_hword[i].val, 2);
472 } else if (type == CFG_WORD_CMD) {
474 if (g_cfg_word[i].id == WID_NIL)
477 if (g_cfg_word[i].id == wid) {
478 memcpy(buffer, &g_cfg_word[i].val, 4);
484 } else if (type == CFG_STR_CMD) {
486 if (g_cfg_str[i].id == WID_NIL)
489 if (g_cfg_str[i].id == wid) {
490 u32 size = g_cfg_str[i].str[0] |
491 (g_cfg_str[i].str[1] << 8);
493 if (buffer_size >= size) {
494 if (g_cfg_str[i].id == WID_SITE_SURVEY_RESULTS) {
501 memcpy(buffer, &g_cfg_str[i].str[2],
514 int wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size,
515 struct wilc_cfg_rsp *rsp)
522 msg_id = frame[1]; /* seq no */
527 * The valid types of response messages are 'R' (Response), 'I' (Information), and 'N' (Network Information)
532 wilc_wlan_parse_response_frame(frame, size);
533 rsp->type = WILC_CFG_RSP;
534 rsp->seq_no = msg_id;
538 rsp->type = wilc_wlan_parse_info_frame(frame, size);
539 rsp->seq_no = msg_id;
540 /*call host interface info parse as well*/
541 wilc_gnrl_async_info_received(wilc, frame - 4, size + 4);
545 wilc_network_info_received(wilc, frame - 4, size + 4);
550 wilc_scan_complete_received(wilc, frame - 4, size + 4);
555 rsp->seq_no = msg_id;
563 int wilc_wlan_cfg_init(void)
565 memset((void *)&g_mac, 0, sizeof(struct wilc_mac_cfg));