1 /* ////////////////////////////////////////////////////////////////////////// */
3 /* Copyright (c) Atmel Corporation. All rights reserved. */
5 /* Module Name: wilc_wlan_cfg.c */
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
);
20 /********************************************
24 ********************************************/
27 wilc_debug_func dPrint
;
30 uint8_t mac_address
[7];
31 uint8_t ip_address
[5];
34 uint8_t firmware_version
[129];
35 uint8_t supp_rate
[24];
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];
49 static wilc_mac_cfg_t g_mac
;
51 static wilc_cfg_byte_t g_cfg_byte
[] = {
53 {WID_CURRENT_TX_RATE
, 0},
54 {WID_CURRENT_CHANNEL
, 0},
56 {WID_11G_OPERATING_MODE
, 0},
61 {WID_POWER_MANAGEMENT
, 0},
65 {WID_LISTEN_INTERVAL
, 0},
69 {WID_REKEY_POLICY
, 0},
70 {WID_SHORT_SLOT_ALLOWED
, 0},
71 {WID_START_SCAN_REQ
, 0},
74 {WID_AUTO_RX_SENSITIVITY
, 0},
75 {WID_DATAFLOW_CONTROL
, 0},
77 {WID_11N_PROT_MECH
, 0},
78 {WID_11N_ERP_PROT_TYPE
, 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},
88 {WID_TX_ABORT_CONFIG
, 0},
89 {WID_11N_IMMEDIATE_BA_ENABLED
, 0},
90 {WID_11N_TXOP_PROT_DISABLE
, 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},
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},
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},
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
},
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
)
172 if ((offset
+ 4) >= MAX_CFG_FRAME_SIZE
)
175 buf
= &frame
[offset
];
177 buf
[0] = (uint8_t)id
;
178 buf
[1] = (uint8_t)(id
>> 8);
184 static int wilc_wlan_cfg_set_hword(uint8_t *frame
, uint32_t offset
, uint16_t id
, uint16_t val16
)
188 if ((offset
+ 5) >= MAX_CFG_FRAME_SIZE
)
191 buf
= &frame
[offset
];
193 buf
[0] = (uint8_t)id
;
194 buf
[1] = (uint8_t)(id
>> 8);
196 buf
[3] = (uint8_t)val16
;
197 buf
[4] = (uint8_t)(val16
>> 8);
202 static int wilc_wlan_cfg_set_word(uint8_t *frame
, uint32_t offset
, uint16_t id
, uint32_t val32
)
206 if ((offset
+ 7) >= MAX_CFG_FRAME_SIZE
)
209 buf
= &frame
[offset
];
211 buf
[0] = (uint8_t)id
;
212 buf
[1] = (uint8_t)(id
>> 8);
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);
222 static int wilc_wlan_cfg_set_str(uint8_t *frame
, uint32_t offset
, uint16_t id
, uint8_t *str
, uint32_t size
)
226 if ((offset
+ size
+ 3) >= MAX_CFG_FRAME_SIZE
)
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
);
241 static int wilc_wlan_cfg_set_bin(uint8_t *frame
, uint32_t offset
, uint16_t id
, uint8_t *b
, uint32_t size
)
245 uint8_t checksum
= 0;
247 if ((offset
+ size
+ 5) >= MAX_CFG_FRAME_SIZE
)
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
;
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;
281 wid
= info
[0] | (info
[1] << 8);
283 wid
= BYTE_SWAP(wid
);
285 PRINT_INFO(GENERIC_DBG
, "Processing response for %d seq %d\n", wid
, seq
++);
286 switch ((wid
>> 12) & 0x7) {
289 if (g_cfg_byte
[i
].id
== WID_NIL
)
292 if (g_cfg_byte
[i
].id
== wid
) {
293 g_cfg_byte
[i
].val
= info
[3];
303 if (g_cfg_hword
[i
].id
== WID_NIL
)
306 if (g_cfg_hword
[i
].id
== wid
) {
308 g_cfg_hword
[i
].val
= (info
[3] << 8) | (info
[4]);
310 g_cfg_hword
[i
].val
= info
[3] | (info
[4] << 8);
321 if (g_cfg_word
[i
].id
== WID_NIL
)
324 if (g_cfg_word
[i
].id
== wid
) {
326 g_cfg_word
[i
].val
= (info
[3] << 24) | (info
[4] << 16) | (info
[5] << 8) | (info
[6]);
328 g_cfg_word
[i
].val
= info
[3] | (info
[4] << 8) | (info
[5] << 16) | (info
[6] << 24);
339 if (g_cfg_str
[i
].id
== WID_NIL
)
342 if (g_cfg_str
[i
].id
== wid
) {
343 if (wid
== WID_SITE_SURVEY_RESULTS
) {
345 PRINT_INFO(GENERIC_DBG
, "Site survey results received[%d]\n",
348 PRINT_INFO(GENERIC_DBG
, "Site survey results value[%d]toggle[%d]\n", size
, toggle
);
352 memcpy(g_cfg_str
[i
].str
, &info
[2], (info
[2] + 1));
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
;
374 int type
= WILC_CFG_RSP_STATUS
;
376 wid
= info
[0] | (info
[1] << 8);
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
;
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;
399 if (type
== 0) { /* byte command */
401 ret
= wilc_wlan_cfg_set_byte(frame
, offset
, id
, *buf
);
402 } else if (type
== 1) { /* half word command */
404 ret
= wilc_wlan_cfg_set_hword(frame
, offset
, id
, *((uint16_t *)buf
));
405 } else if (type
== 2) { /* word command */
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
);
413 g_mac
.dPrint(N_ERR
, "illegal id\n");
419 static int wilc_wlan_cfg_get_wid(uint8_t *frame
, uint32_t offset
, uint16_t id
)
423 if ((offset
+ 2) >= MAX_CFG_FRAME_SIZE
)
426 buf
= &frame
[offset
];
428 buf
[0] = (uint8_t)id
;
429 buf
[1] = (uint8_t)(id
>> 8);
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;
439 if (wid
== WID_STATUS
) {
440 *((uint32_t *)buffer
) = g_mac
.mac_status
;
445 if (type
== 0) { /* byte command */
447 if (g_cfg_byte
[i
].id
== WID_NIL
)
450 if (g_cfg_byte
[i
].id
== wid
) {
451 memcpy(buffer
, &g_cfg_byte
[i
].val
, 1);
457 } else if (type
== 1) { /* half word command */
459 if (g_cfg_hword
[i
].id
== WID_NIL
)
462 if (g_cfg_hword
[i
].id
== wid
) {
463 memcpy(buffer
, &g_cfg_hword
[i
].val
, 2);
469 } else if (type
== 2) { /* word command */
471 if (g_cfg_word
[i
].id
== WID_NIL
)
474 if (g_cfg_word
[i
].id
== wid
) {
475 memcpy(buffer
, &g_cfg_word
[i
].val
, 4);
481 } else if (type
== 3) { /* string command */
483 if (g_cfg_str
[i
].id
== WID_NIL
)
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
) {
491 PRINT_INFO(GENERIC_DBG
, "Site survey results value[%d]\n",
497 memcpy(buffer
, &g_cfg_str
[i
].str
[1], size
);
505 g_mac
.dPrint(N_ERR
, "[CFG]: illegal type (%08x)\n", wid
);
511 static int wilc_wlan_cfg_indicate_rx(uint8_t *frame
, int size
, wilc_cfg_rsp_t
*rsp
)
517 #ifdef WILC_FULLY_HOSTING_AP
519 bool bStatus
= frame
[2];
522 ptru32Frame
= (frame
[4] << 24) | (frame
[5] << 16) | (frame
[6] << 8) | frame
[7];
524 ptru32Frame
= (frame
[7] << 24) | (frame
[6] << 16) | (frame
[5] << 8) | frame
[4];
525 #endif /* BIG_ENDIAN */
527 #endif /* WILC_FULLY_HOSTING_AP */
530 msg_id
= frame
[1]; /* seq no */
532 msg_len
= (frame
[2] << 8) | frame
[3];
534 msg_len
= (frame
[3] << 8) | frame
[2];
540 * The valid types of response messages are 'R' (Response), 'I' (Information), and 'N' (Network Information)
545 wilc_wlan_parse_response_frame(frame
, size
);
546 rsp
->type
= WILC_CFG_RSP
;
547 rsp
->seq_no
= msg_id
;
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);
559 #ifndef SWITCH_LOG_TERMINAL
560 PRINT_ER("Unexpected firmware log message received \n");
562 PRINT_D(FIRM_DBG
, "\nFIRMWARE LOGS :\n<<\n%s\n>>\n", frame
);
568 NetworkInfoReceived(frame
- 4, size
+ 4);
575 PRINT_INFO(RX_DBG
, "Scan Notification Received \n");
576 host_int_ScanCompleteReceived(frame
- 4, size
+ 4);
579 #ifdef WILC_FULLY_HOSTING_AP
581 PRINT_INFO(RX_DBG
, "TBTT Notification Received \n");
586 PRINT_INFO(RX_DBG
, "HOSTAPD ACK Notification Received \n");
587 WILC_mgm_HOSTAPD_ACK(ptru32Frame
, bStatus
);
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]);
596 rsp
->seq_no
= msg_id
;
604 static int wilc_wlan_cfg_init(wilc_debug_func func
)
606 memset((void *)&g_mac
, 0, sizeof(wilc_mac_cfg_t
));
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
,