net: Add inet_addr lookup by table
[linux-2.6/btrfs-unstable.git] / drivers / staging / wilc1000 / wilc_wlan_cfg.c
blob3cffe55b3a93915c02e84540ba5eec3af769f822
1 /* ////////////////////////////////////////////////////////////////////////// */
2 /* */
3 /* Copyright (c) Atmel Corporation. All rights reserved. */
4 /* */
5 /* Module Name: wilc_wlan_cfg.c */
6 /* */
7 /* */
8 /* ///////////////////////////////////////////////////////////////////////// */
10 #include "wilc_wlan_if.h"
11 #include "wilc_wlan.h"
12 #include "wilc_wlan_cfg.h"
13 #include "coreconfigurator.h"
15 #ifdef WILC_FULLY_HOSTING_AP
16 #include "wilc_host_ap.h"
17 void WILC_mgm_HOSTAPD_ACK(void *priv, bool bStatus);
18 #endif
20 /********************************************
22 * Global Data
24 ********************************************/
26 typedef struct {
27 wilc_debug_func dPrint;
29 int mac_status;
30 uint8_t mac_address[7];
31 uint8_t ip_address[5];
32 uint8_t bssid[7];
33 uint8_t ssid[34];
34 uint8_t firmware_version[129];
35 uint8_t supp_rate[24];
36 uint8_t wep_key[28];
37 uint8_t i_psk[66];
38 uint8_t hardwareProductVersion[33];
39 uint8_t phyversion[17];
40 uint8_t supp_username[21];
41 uint8_t supp_password[64];
42 uint8_t assoc_req[256];
43 uint8_t assoc_rsp[256];
44 uint8_t firmware_info[8];
45 uint8_t scan_result[256];
46 uint8_t scan_result1[256];
47 } wilc_mac_cfg_t;
49 static wilc_mac_cfg_t g_mac;
51 static wilc_cfg_byte_t g_cfg_byte[] = {
52 {WID_BSS_TYPE, 0},
53 {WID_CURRENT_TX_RATE, 0},
54 {WID_CURRENT_CHANNEL, 0},
55 {WID_PREAMBLE, 0},
56 {WID_11G_OPERATING_MODE, 0},
57 {WID_STATUS, 0},
58 {WID_SCAN_TYPE, 0},
59 {WID_KEY_ID, 0},
60 {WID_QOS_ENABLE, 0},
61 {WID_POWER_MANAGEMENT, 0},
62 {WID_11I_MODE, 0},
63 {WID_AUTH_TYPE, 0},
64 {WID_SITE_SURVEY, 0},
65 {WID_LISTEN_INTERVAL, 0},
66 {WID_DTIM_PERIOD, 0},
67 {WID_ACK_POLICY, 0},
68 {WID_BCAST_SSID, 0},
69 {WID_REKEY_POLICY, 0},
70 {WID_SHORT_SLOT_ALLOWED, 0},
71 {WID_START_SCAN_REQ, 0},
72 {WID_RSSI, 0},
73 {WID_LINKSPEED, 0},
74 {WID_AUTO_RX_SENSITIVITY, 0},
75 {WID_DATAFLOW_CONTROL, 0},
76 {WID_SCAN_FILTER, 0},
77 {WID_11N_PROT_MECH, 0},
78 {WID_11N_ERP_PROT_TYPE, 0},
79 {WID_11N_ENABLE, 0},
80 {WID_11N_OPERATING_MODE, 0},
81 {WID_11N_OBSS_NONHT_DETECTION, 0},
82 {WID_11N_HT_PROT_TYPE, 0},
83 {WID_11N_RIFS_PROT_ENABLE, 0},
84 {WID_11N_SMPS_MODE, 0},
85 {WID_11N_CURRENT_TX_MCS, 0},
86 {WID_11N_SHORT_GI_ENABLE, 0},
87 {WID_RIFS_MODE, 0},
88 {WID_TX_ABORT_CONFIG, 0},
89 {WID_11N_IMMEDIATE_BA_ENABLED, 0},
90 {WID_11N_TXOP_PROT_DISABLE, 0},
91 {WID_NIL, 0}
94 static wilc_cfg_hword_t g_cfg_hword[] = {
95 {WID_LINK_LOSS_THRESHOLD, 0},
96 {WID_RTS_THRESHOLD, 0},
97 {WID_FRAG_THRESHOLD, 0},
98 {WID_SHORT_RETRY_LIMIT, 0},
99 {WID_LONG_RETRY_LIMIT, 0},
100 {WID_BEACON_INTERVAL, 0},
101 {WID_RX_SENSE, 0},
102 {WID_ACTIVE_SCAN_TIME, 0},
103 {WID_PASSIVE_SCAN_TIME, 0},
104 {WID_SITE_SURVEY_SCAN_TIME, 0},
105 {WID_JOIN_START_TIMEOUT, 0},
106 {WID_AUTH_TIMEOUT, 0},
107 {WID_ASOC_TIMEOUT, 0},
108 {WID_11I_PROTOCOL_TIMEOUT, 0},
109 {WID_EAPOL_RESPONSE_TIMEOUT, 0},
110 {WID_11N_SIG_QUAL_VAL, 0},
111 {WID_CCA_THRESHOLD, 0},
112 {WID_NIL, 0}
115 static wilc_cfg_word_t g_cfg_word[] = {
116 {WID_FAILED_COUNT, 0},
117 {WID_RETRY_COUNT, 0},
118 {WID_MULTIPLE_RETRY_COUNT, 0},
119 {WID_FRAME_DUPLICATE_COUNT, 0},
120 {WID_ACK_FAILURE_COUNT, 0},
121 {WID_RECEIVED_FRAGMENT_COUNT, 0},
122 {WID_MCAST_RECEIVED_FRAME_COUNT, 0},
123 {WID_FCS_ERROR_COUNT, 0},
124 {WID_SUCCESS_FRAME_COUNT, 0},
125 {WID_TX_FRAGMENT_COUNT, 0},
126 {WID_TX_MULTICAST_FRAME_COUNT, 0},
127 {WID_RTS_SUCCESS_COUNT, 0},
128 {WID_RTS_FAILURE_COUNT, 0},
129 {WID_WEP_UNDECRYPTABLE_COUNT, 0},
130 {WID_REKEY_PERIOD, 0},
131 {WID_REKEY_PACKET_COUNT, 0},
132 {WID_HW_RX_COUNT, 0},
133 {WID_GET_INACTIVE_TIME, 0},
134 {WID_NIL, 0}
138 static wilc_cfg_str_t g_cfg_str[] = {
139 {WID_SSID, g_mac.ssid}, /* 33 + 1 bytes */
140 {WID_FIRMWARE_VERSION, g_mac.firmware_version},
141 {WID_OPERATIONAL_RATE_SET, g_mac.supp_rate},
142 {WID_BSSID, g_mac.bssid}, /* 6 bytes */
143 {WID_WEP_KEY_VALUE, g_mac.wep_key}, /* 27 bytes */
144 {WID_11I_PSK, g_mac.i_psk}, /* 65 bytes */
145 /* {WID_11E_P_ACTION_REQ, g_mac.action_req}, */
146 {WID_HARDWARE_VERSION, g_mac.hardwareProductVersion},
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_RX_POWER_LEVEL, g_mac.channel_rssi}, */
154 {WID_ASSOC_REQ_INFO, g_mac.assoc_req},
155 {WID_ASSOC_RES_INFO, g_mac.assoc_rsp},
156 /* {WID_11N_P_ACTION_REQ, g_mac.action_req}, */
157 {WID_FIRMWARE_INFO, g_mac.firmware_version},
158 {WID_IP_ADDRESS, g_mac.ip_address},
159 {WID_NIL, NULL}
162 /********************************************
164 * Configuration Functions
166 ********************************************/
168 static int wilc_wlan_cfg_set_byte(uint8_t *frame, uint32_t offset, uint16_t id, uint8_t val8)
170 uint8_t *buf;
172 if ((offset + 4) >= MAX_CFG_FRAME_SIZE)
173 return 0;
175 buf = &frame[offset];
177 buf[0] = (uint8_t)id;
178 buf[1] = (uint8_t)(id >> 8);
179 buf[2] = 1;
180 buf[3] = val8;
181 return 4;
184 static int wilc_wlan_cfg_set_hword(uint8_t *frame, uint32_t offset, uint16_t id, uint16_t val16)
186 uint8_t *buf;
188 if ((offset + 5) >= MAX_CFG_FRAME_SIZE)
189 return 0;
191 buf = &frame[offset];
193 buf[0] = (uint8_t)id;
194 buf[1] = (uint8_t)(id >> 8);
195 buf[2] = 2;
196 buf[3] = (uint8_t)val16;
197 buf[4] = (uint8_t)(val16 >> 8);
199 return 5;
202 static int wilc_wlan_cfg_set_word(uint8_t *frame, uint32_t offset, uint16_t id, uint32_t val32)
204 uint8_t *buf;
206 if ((offset + 7) >= MAX_CFG_FRAME_SIZE)
207 return 0;
209 buf = &frame[offset];
211 buf[0] = (uint8_t)id;
212 buf[1] = (uint8_t)(id >> 8);
213 buf[2] = 4;
214 buf[3] = (uint8_t)val32;
215 buf[4] = (uint8_t)(val32 >> 8);
216 buf[5] = (uint8_t)(val32 >> 16);
217 buf[6] = (uint8_t)(val32 >> 24);
219 return 7;
222 static int wilc_wlan_cfg_set_str(uint8_t *frame, uint32_t offset, uint16_t id, uint8_t *str, uint32_t size)
224 uint8_t *buf;
226 if ((offset + size + 3) >= MAX_CFG_FRAME_SIZE)
227 return 0;
229 buf = &frame[offset];
231 buf[0] = (uint8_t)id;
232 buf[1] = (uint8_t)(id >> 8);
233 buf[2] = (uint8_t)size;
235 if ((str != NULL) && (size != 0))
236 memcpy(&buf[3], str, size);
238 return (size + 3);
241 static int wilc_wlan_cfg_set_bin(uint8_t *frame, uint32_t offset, uint16_t id, uint8_t *b, uint32_t size)
243 uint8_t *buf;
244 uint32_t i;
245 uint8_t checksum = 0;
247 if ((offset + size + 5) >= MAX_CFG_FRAME_SIZE)
248 return 0;
250 buf = &frame[offset];
251 buf[0] = (uint8_t)id;
252 buf[1] = (uint8_t)(id >> 8);
253 buf[2] = (uint8_t)size;
254 buf[3] = (uint8_t)(size >> 8);
256 if ((b != NULL) && (size != 0)) {
257 memcpy(&buf[4], b, size);
258 for (i = 0; i < size; i++) {
259 checksum += buf[i + 4];
263 buf[size + 4] = checksum;
265 return (size + 5);
268 /********************************************
270 * Configuration Response Functions
272 ********************************************/
274 static void wilc_wlan_parse_response_frame(uint8_t *info, int size)
276 uint32_t wid, len = 0, i = 0;
277 static int seq;
279 while (size > 0) {
280 i = 0;
281 wid = info[0] | (info[1] << 8);
282 #ifdef BIG_ENDIAN
283 wid = BYTE_SWAP(wid);
284 #endif
285 PRINT_INFO(GENERIC_DBG, "Processing response for %d seq %d\n", wid, seq++);
286 switch ((wid >> 12) & 0x7) {
287 case WID_CHAR:
288 do {
289 if (g_cfg_byte[i].id == WID_NIL)
290 break;
292 if (g_cfg_byte[i].id == wid) {
293 g_cfg_byte[i].val = info[3];
294 break;
296 i++;
297 } while (1);
298 len = 2;
299 break;
301 case WID_SHORT:
302 do {
303 if (g_cfg_hword[i].id == WID_NIL)
304 break;
306 if (g_cfg_hword[i].id == wid) {
307 #ifdef BIG_ENDIAN
308 g_cfg_hword[i].val = (info[3] << 8) | (info[4]);
309 #else
310 g_cfg_hword[i].val = info[3] | (info[4] << 8);
311 #endif
312 break;
314 i++;
315 } while (1);
316 len = 3;
317 break;
319 case WID_INT:
320 do {
321 if (g_cfg_word[i].id == WID_NIL)
322 break;
324 if (g_cfg_word[i].id == wid) {
325 #ifdef BIG_ENDIAN
326 g_cfg_word[i].val = (info[3] << 24) | (info[4] << 16) | (info[5] << 8) | (info[6]);
327 #else
328 g_cfg_word[i].val = info[3] | (info[4] << 8) | (info[5] << 16) | (info[6] << 24);
329 #endif
330 break;
332 i++;
333 } while (1);
334 len = 5;
335 break;
337 case WID_STR:
338 do {
339 if (g_cfg_str[i].id == WID_NIL)
340 break;
342 if (g_cfg_str[i].id == wid) {
343 if (wid == WID_SITE_SURVEY_RESULTS) {
344 static int toggle;
345 PRINT_INFO(GENERIC_DBG, "Site survey results received[%d]\n",
346 size);
348 PRINT_INFO(GENERIC_DBG, "Site survey results value[%d]toggle[%d]\n", size, toggle);
349 i += toggle;
350 toggle ^= 1;
352 memcpy(g_cfg_str[i].str, &info[2], (info[2] + 1));
353 break;
355 i++;
356 } while (1);
357 len = 1 + info[2];
358 break;
360 default:
361 break;
363 size -= (2 + len);
364 info += (2 + len);
367 return;
370 static int wilc_wlan_parse_info_frame(uint8_t *info, int size)
372 wilc_mac_cfg_t *pd = (wilc_mac_cfg_t *)&g_mac;
373 uint32_t wid, len;
374 int type = WILC_CFG_RSP_STATUS;
376 wid = info[0] | (info[1] << 8);
378 len = info[2];
379 PRINT_INFO(GENERIC_DBG, "Status Len = %d Id= %d\n", len, wid);
380 if ((len == 1) && (wid == WID_STATUS)) {
381 pd->mac_status = info[3];
382 type = WILC_CFG_RSP_STATUS;
385 return type;
388 /********************************************
390 * Configuration Exported Functions
392 ********************************************/
394 static int wilc_wlan_cfg_set_wid(uint8_t *frame, uint32_t offset, uint16_t id, uint8_t *buf, int size)
396 uint8_t type = (id >> 12) & 0xf;
397 int ret = 0;
399 if (type == 0) { /* byte command */
400 if (size >= 1)
401 ret = wilc_wlan_cfg_set_byte(frame, offset, id, *buf);
402 } else if (type == 1) { /* half word command */
403 if (size >= 2)
404 ret = wilc_wlan_cfg_set_hword(frame, offset, id, *((uint16_t *)buf));
405 } else if (type == 2) { /* word command */
406 if (size >= 4)
407 ret = wilc_wlan_cfg_set_word(frame, offset, id, *((uint32_t *)buf));
408 } else if (type == 3) { /* string command */
409 ret = wilc_wlan_cfg_set_str(frame, offset, id, buf, size);
410 } else if (type == 4) { /* binary command */
411 ret = wilc_wlan_cfg_set_bin(frame, offset, id, buf, size);
412 } else {
413 g_mac.dPrint(N_ERR, "illegal id\n");
416 return ret;
419 static int wilc_wlan_cfg_get_wid(uint8_t *frame, uint32_t offset, uint16_t id)
421 uint8_t *buf;
423 if ((offset + 2) >= MAX_CFG_FRAME_SIZE)
424 return 0;
426 buf = &frame[offset];
428 buf[0] = (uint8_t)id;
429 buf[1] = (uint8_t)(id >> 8);
431 return 2;
434 static int wilc_wlan_cfg_get_wid_value(uint16_t wid, uint8_t *buffer, uint32_t buffer_size)
436 uint32_t type = (wid >> 12) & 0xf;
437 int i, ret = 0;
439 if (wid == WID_STATUS) {
440 *((uint32_t *)buffer) = g_mac.mac_status;
441 return 4;
444 i = 0;
445 if (type == 0) { /* byte command */
446 do {
447 if (g_cfg_byte[i].id == WID_NIL)
448 break;
450 if (g_cfg_byte[i].id == wid) {
451 memcpy(buffer, &g_cfg_byte[i].val, 1);
452 ret = 1;
453 break;
455 i++;
456 } while (1);
457 } else if (type == 1) { /* half word command */
458 do {
459 if (g_cfg_hword[i].id == WID_NIL)
460 break;
462 if (g_cfg_hword[i].id == wid) {
463 memcpy(buffer, &g_cfg_hword[i].val, 2);
464 ret = 2;
465 break;
467 i++;
468 } while (1);
469 } else if (type == 2) { /* word command */
470 do {
471 if (g_cfg_word[i].id == WID_NIL)
472 break;
474 if (g_cfg_word[i].id == wid) {
475 memcpy(buffer, &g_cfg_word[i].val, 4);
476 ret = 4;
477 break;
479 i++;
480 } while (1);
481 } else if (type == 3) { /* string command */
482 do {
483 if (g_cfg_str[i].id == WID_NIL)
484 break;
486 if (g_cfg_str[i].id == wid) {
487 uint32_t size = g_cfg_str[i].str[0];
488 if (buffer_size >= size) {
489 if (g_cfg_str[i].id == WID_SITE_SURVEY_RESULTS) {
490 static int toggle;
491 PRINT_INFO(GENERIC_DBG, "Site survey results value[%d]\n",
492 size);
493 i += toggle;
494 toggle ^= 1;
497 memcpy(buffer, &g_cfg_str[i].str[1], size);
498 ret = size;
500 break;
502 i++;
503 } while (1);
504 } else {
505 g_mac.dPrint(N_ERR, "[CFG]: illegal type (%08x)\n", wid);
508 return ret;
511 static int wilc_wlan_cfg_indicate_rx(uint8_t *frame, int size, wilc_cfg_rsp_t *rsp)
513 int ret = 1;
514 uint8_t msg_type;
515 uint8_t msg_id;
516 uint16_t msg_len;
517 #ifdef WILC_FULLY_HOSTING_AP
518 u32 *ptru32Frame;
519 bool bStatus = frame[2];
521 #ifdef BIG_ENDIAN
522 ptru32Frame = (frame[4] << 24) | (frame[5] << 16) | (frame[6] << 8) | frame[7];
523 #else
524 ptru32Frame = (frame[7] << 24) | (frame[6] << 16) | (frame[5] << 8) | frame[4];
525 #endif /* BIG_ENDIAN */
527 #endif /* WILC_FULLY_HOSTING_AP */
529 msg_type = frame[0];
530 msg_id = frame[1]; /* seq no */
531 #ifdef BIG_ENDIAN
532 msg_len = (frame[2] << 8) | frame[3];
533 #else
534 msg_len = (frame[3] << 8) | frame[2];
535 #endif
536 frame += 4;
537 size -= 4;
540 * The valid types of response messages are 'R' (Response), 'I' (Information), and 'N' (Network Information)
543 switch (msg_type) {
544 case 'R':
545 wilc_wlan_parse_response_frame(frame, size);
546 rsp->type = WILC_CFG_RSP;
547 rsp->seq_no = msg_id;
548 break;
550 case 'I':
551 rsp->type = wilc_wlan_parse_info_frame(frame, size);
552 rsp->seq_no = msg_id;
553 /*call host interface info parse as well*/
554 PRINT_INFO(RX_DBG, "Info message received\n");
555 GnrlAsyncInfoReceived(frame - 4, size + 4);
556 break;
558 case 'L':
559 #ifndef SWITCH_LOG_TERMINAL
560 PRINT_ER("Unexpected firmware log message received \n");
561 #else
562 PRINT_D(FIRM_DBG, "\nFIRMWARE LOGS :\n<<\n%s\n>>\n", frame);
563 break;
565 #endif
566 #if 1
567 case 'N':
568 NetworkInfoReceived(frame - 4, size + 4);
569 rsp->type = 0;
570 break;
572 #endif
573 /*bug3819:*/
574 case 'S':
575 PRINT_INFO(RX_DBG, "Scan Notification Received \n");
576 host_int_ScanCompleteReceived(frame - 4, size + 4);
577 break;
579 #ifdef WILC_FULLY_HOSTING_AP
580 case 'T':
581 PRINT_INFO(RX_DBG, "TBTT Notification Received \n");
582 process_tbtt_isr();
583 break;
585 case 'A':
586 PRINT_INFO(RX_DBG, "HOSTAPD ACK Notification Received \n");
587 WILC_mgm_HOSTAPD_ACK(ptru32Frame, bStatus);
588 break;
589 #endif
591 default:
592 PRINT_INFO(RX_DBG, "Receive unknown message type[%d-%d-%d-%d-%d-%d-%d-%d]\n",
593 frame[0], frame[1], frame[2], frame[3], frame[4],
594 frame[5], frame[6], frame[7]);
595 rsp->type = 0;
596 rsp->seq_no = msg_id;
597 ret = 0;
598 break;
601 return ret;
604 static int wilc_wlan_cfg_init(wilc_debug_func func)
606 memset((void *)&g_mac, 0, sizeof(wilc_mac_cfg_t));
607 g_mac.dPrint = func;
608 return 1;
611 wilc_cfg_func_t mac_cfg = {
612 wilc_wlan_cfg_set_wid,
613 wilc_wlan_cfg_get_wid,
614 wilc_wlan_cfg_get_wid_value,
615 wilc_wlan_cfg_indicate_rx,
616 wilc_wlan_cfg_init,