1 /* ////////////////////////////////////////////////////////////////////////// */
3 /* Copyright (c) Atmel Corporation. All rights reserved. */
5 /* Module Name: wilc_wlan_cfg.c */
8 /* ///////////////////////////////////////////////////////////////////////// */
10 #include <linux/string.h>
11 #include "wilc_wlan_if.h"
12 #include "wilc_wlan.h"
13 #include "wilc_wlan_cfg.h"
14 #include "coreconfigurator.h"
16 /********************************************
20 ********************************************/
35 u8 firmware_version[129];
39 u8 hw_product_version[33];
50 static struct wilc_mac_cfg g_mac;
52 static struct wilc_cfg_byte g_cfg_byte[] = {
54 {WID_CURRENT_TX_RATE, 0},
55 {WID_CURRENT_CHANNEL, 0},
57 {WID_11G_OPERATING_MODE, 0},
62 {WID_POWER_MANAGEMENT, 0},
66 {WID_LISTEN_INTERVAL, 0},
70 {WID_REKEY_POLICY, 0},
71 {WID_SHORT_SLOT_ALLOWED, 0},
72 {WID_START_SCAN_REQ, 0},
75 {WID_AUTO_RX_SENSITIVITY, 0},
76 {WID_DATAFLOW_CONTROL, 0},
78 {WID_11N_PROT_MECH, 0},
79 {WID_11N_ERP_PROT_TYPE, 0},
81 {WID_11N_OPERATING_MODE, 0},
82 {WID_11N_OBSS_NONHT_DETECTION, 0},
83 {WID_11N_HT_PROT_TYPE, 0},
84 {WID_11N_RIFS_PROT_ENABLE, 0},
85 {WID_11N_SMPS_MODE, 0},
86 {WID_11N_CURRENT_TX_MCS, 0},
87 {WID_11N_SHORT_GI_ENABLE, 0},
89 {WID_TX_ABORT_CONFIG, 0},
90 {WID_11N_IMMEDIATE_BA_ENABLED, 0},
91 {WID_11N_TXOP_PROT_DISABLE, 0},
95 static struct wilc_cfg_hword g_cfg_hword[] = {
96 {WID_LINK_LOSS_THRESHOLD, 0},
97 {WID_RTS_THRESHOLD, 0},
98 {WID_FRAG_THRESHOLD, 0},
99 {WID_SHORT_RETRY_LIMIT, 0},
100 {WID_LONG_RETRY_LIMIT, 0},
101 {WID_BEACON_INTERVAL, 0},
103 {WID_ACTIVE_SCAN_TIME, 0},
104 {WID_PASSIVE_SCAN_TIME, 0},
105 {WID_SITE_SURVEY_SCAN_TIME, 0},
106 {WID_JOIN_START_TIMEOUT, 0},
107 {WID_AUTH_TIMEOUT, 0},
108 {WID_ASOC_TIMEOUT, 0},
109 {WID_11I_PROTOCOL_TIMEOUT, 0},
110 {WID_EAPOL_RESPONSE_TIMEOUT, 0},
111 {WID_11N_SIG_QUAL_VAL, 0},
112 {WID_CCA_THRESHOLD, 0},
116 static struct wilc_cfg_word g_cfg_word[] = {
117 {WID_FAILED_COUNT, 0},
118 {WID_RETRY_COUNT, 0},
119 {WID_MULTIPLE_RETRY_COUNT, 0},
120 {WID_FRAME_DUPLICATE_COUNT, 0},
121 {WID_ACK_FAILURE_COUNT, 0},
122 {WID_RECEIVED_FRAGMENT_COUNT, 0},
123 {WID_MCAST_RECEIVED_FRAME_COUNT, 0},
124 {WID_FCS_ERROR_COUNT, 0},
125 {WID_SUCCESS_FRAME_COUNT, 0},
126 {WID_TX_FRAGMENT_COUNT, 0},
127 {WID_TX_MULTICAST_FRAME_COUNT, 0},
128 {WID_RTS_SUCCESS_COUNT, 0},
129 {WID_RTS_FAILURE_COUNT, 0},
130 {WID_WEP_UNDECRYPTABLE_COUNT, 0},
131 {WID_REKEY_PERIOD, 0},
132 {WID_REKEY_PACKET_COUNT, 0},
133 {WID_HW_RX_COUNT, 0},
134 {WID_GET_INACTIVE_TIME, 0},
139 static struct wilc_cfg_str g_cfg_str[] = {
140 {WID_SSID, g_mac.ssid}, /* 33 + 1 bytes */
141 {WID_FIRMWARE_VERSION, g_mac.firmware_version},
142 {WID_OPERATIONAL_RATE_SET, g_mac.supp_rate},
143 {WID_BSSID, g_mac.bssid}, /* 6 bytes */
144 {WID_WEP_KEY_VALUE, g_mac.wep_key}, /* 27 bytes */
145 {WID_11I_PSK, g_mac.i_psk}, /* 65 bytes */
146 {WID_HARDWARE_VERSION, g_mac.hw_product_version},
147 {WID_MAC_ADDR, g_mac.mac_address},
148 {WID_PHY_VERSION, g_mac.phyversion},
149 {WID_SUPP_USERNAME, g_mac.supp_username},
150 {WID_SUPP_PASSWORD, g_mac.supp_password},
151 {WID_SITE_SURVEY_RESULTS, g_mac.scan_result},
152 {WID_SITE_SURVEY_RESULTS, g_mac.scan_result1},
153 {WID_ASSOC_REQ_INFO, g_mac.assoc_req},
154 {WID_ASSOC_RES_INFO, g_mac.assoc_rsp},
155 {WID_FIRMWARE_INFO, g_mac.firmware_version},
156 {WID_IP_ADDRESS, g_mac.ip_address},
160 /********************************************
162 * Configuration Functions
164 ********************************************/
166 static int wilc_wlan_cfg_set_byte(u8 *frame, u32 offset, u16 id, u8 val8)
170 if ((offset + 4) >= MAX_CFG_FRAME_SIZE)
173 buf = &frame[offset];
176 buf[1] = (u8)(id >> 8);
182 static int wilc_wlan_cfg_set_hword(u8 *frame, u32 offset, u16 id, u16 val16)
186 if ((offset + 5) >= MAX_CFG_FRAME_SIZE)
189 buf = &frame[offset];
192 buf[1] = (u8)(id >> 8);
195 buf[4] = (u8)(val16 >> 8);
200 static int wilc_wlan_cfg_set_word(u8 *frame, u32 offset, u16 id, u32 val32)
204 if ((offset + 7) >= MAX_CFG_FRAME_SIZE)
207 buf = &frame[offset];
210 buf[1] = (u8)(id >> 8);
213 buf[4] = (u8)(val32 >> 8);
214 buf[5] = (u8)(val32 >> 16);
215 buf[6] = (u8)(val32 >> 24);
220 static int wilc_wlan_cfg_set_str(u8 *frame, u32 offset, u16 id, u8 *str, u32 size)
224 if ((offset + size + 3) >= MAX_CFG_FRAME_SIZE)
227 buf = &frame[offset];
230 buf[1] = (u8)(id >> 8);
233 if ((str) && (size != 0))
234 memcpy(&buf[3], str, size);
239 static int wilc_wlan_cfg_set_bin(u8 *frame, u32 offset, u16 id, u8 *b, u32 size)
245 if ((offset + size + 5) >= MAX_CFG_FRAME_SIZE)
248 buf = &frame[offset];
250 buf[1] = (u8)(id >> 8);
252 buf[3] = (u8)(size >> 8);
254 if ((b) && (size != 0)) {
255 memcpy(&buf[4], b, size);
256 for (i = 0; i < size; i++)
257 checksum += buf[i + 4];
260 buf[size + 4] = checksum;
265 /********************************************
267 * Configuration Response Functions
269 ********************************************/
271 static void wilc_wlan_parse_response_frame(u8 *info, int size)
273 u32 wid, len = 0, i = 0;
277 wid = info[0] | (info[1] << 8);
278 wid = cpu_to_le32(wid);
280 switch ((wid >> 12) & 0x7) {
283 if (g_cfg_byte[i].id == WID_NIL)
286 if (g_cfg_byte[i].id == wid) {
287 g_cfg_byte[i].val = info[3];
297 if (g_cfg_hword[i].id == WID_NIL)
300 if (g_cfg_hword[i].id == wid) {
301 g_cfg_hword[i].val = cpu_to_le16(info[3] | (info[4] << 8));
311 if (g_cfg_word[i].id == WID_NIL)
314 if (g_cfg_word[i].id == wid) {
315 g_cfg_word[i].val = cpu_to_le32(info[3] | (info[4] << 8) | (info[5] << 16) | (info[6] << 24));
325 if (g_cfg_str[i].id == WID_NIL)
328 if (g_cfg_str[i].id == wid) {
329 if (wid == WID_SITE_SURVEY_RESULTS) {
335 memcpy(g_cfg_str[i].str, &info[2], (info[2] + 1));
351 static int wilc_wlan_parse_info_frame(u8 *info, int size)
353 struct wilc_mac_cfg *pd = &g_mac;
355 int type = WILC_CFG_RSP_STATUS;
357 wid = info[0] | (info[1] << 8);
361 if ((len == 1) && (wid == WID_STATUS)) {
362 pd->mac_status = info[3];
363 type = WILC_CFG_RSP_STATUS;
369 /********************************************
371 * Configuration Exported Functions
373 ********************************************/
375 int wilc_wlan_cfg_set_wid(u8 *frame, u32 offset, u16 id, u8 *buf, int size)
377 u8 type = (id >> 12) & 0xf;
383 ret = wilc_wlan_cfg_set_byte(frame, offset, id, *buf);
388 ret = wilc_wlan_cfg_set_hword(frame, offset, id,
394 ret = wilc_wlan_cfg_set_word(frame, offset, id,
399 ret = wilc_wlan_cfg_set_str(frame, offset, id, buf, size);
403 ret = wilc_wlan_cfg_set_bin(frame, offset, id, buf, size);
410 int wilc_wlan_cfg_get_wid(u8 *frame, u32 offset, u16 id)
414 if ((offset + 2) >= MAX_CFG_FRAME_SIZE)
417 buf = &frame[offset];
420 buf[1] = (u8)(id >> 8);
425 int wilc_wlan_cfg_get_wid_value(u16 wid, u8 *buffer, u32 buffer_size)
427 u32 type = (wid >> 12) & 0xf;
430 if (wid == WID_STATUS) {
431 *((u32 *)buffer) = g_mac.mac_status;
436 if (type == CFG_BYTE_CMD) {
438 if (g_cfg_byte[i].id == WID_NIL)
441 if (g_cfg_byte[i].id == wid) {
442 memcpy(buffer, &g_cfg_byte[i].val, 1);
448 } else if (type == CFG_HWORD_CMD) {
450 if (g_cfg_hword[i].id == WID_NIL)
453 if (g_cfg_hword[i].id == wid) {
454 memcpy(buffer, &g_cfg_hword[i].val, 2);
460 } else if (type == CFG_WORD_CMD) {
462 if (g_cfg_word[i].id == WID_NIL)
465 if (g_cfg_word[i].id == wid) {
466 memcpy(buffer, &g_cfg_word[i].val, 4);
472 } else if (type == CFG_STR_CMD) {
474 if (g_cfg_str[i].id == WID_NIL)
477 if (g_cfg_str[i].id == wid) {
478 u32 size = g_cfg_str[i].str[0];
480 if (buffer_size >= size) {
481 if (g_cfg_str[i].id == WID_SITE_SURVEY_RESULTS) {
488 memcpy(buffer, &g_cfg_str[i].str[1], size);
500 int wilc_wlan_cfg_indicate_rx(struct wilc *wilc, u8 *frame, int size,
501 struct wilc_cfg_rsp *rsp)
508 msg_id = frame[1]; /* seq no */
513 * The valid types of response messages are 'R' (Response), 'I' (Information), and 'N' (Network Information)
518 wilc_wlan_parse_response_frame(frame, size);
519 rsp->type = WILC_CFG_RSP;
520 rsp->seq_no = msg_id;
524 rsp->type = wilc_wlan_parse_info_frame(frame, size);
525 rsp->seq_no = msg_id;
526 /*call host interface info parse as well*/
527 wilc_gnrl_async_info_received(wilc, frame - 4, size + 4);
531 wilc_network_info_received(wilc, frame - 4, size + 4);
536 wilc_scan_complete_received(wilc, frame - 4, size + 4);
541 rsp->seq_no = msg_id;
549 int wilc_wlan_cfg_init(void)
551 memset((void *)&g_mac, 0, sizeof(struct wilc_mac_cfg));