Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 1 | /* ////////////////////////////////////////////////////////////////////////// */ |
| 2 | /* */ |
| 3 | /* Copyright (c) Atmel Corporation. All rights reserved. */ |
| 4 | /* */ |
| 5 | /* Module Name: wilc_wlan_cfg.c */ |
| 6 | /* */ |
| 7 | /* */ |
| 8 | /* ///////////////////////////////////////////////////////////////////////// */ |
| 9 | |
| 10 | #include "wilc_wlan_if.h" |
| 11 | #include "wilc_wlan.h" |
| 12 | #include "wilc_wlan_cfg.h" |
| 13 | #include "coreconfigurator.h" |
| 14 | |
| 15 | #ifdef WILC_FULLY_HOSTING_AP |
| 16 | #include "wilc_host_ap.h" |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 17 | void WILC_mgm_HOSTAPD_ACK(void *priv, bool bStatus); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 18 | #endif |
| 19 | |
| 20 | /******************************************** |
| 21 | * |
| 22 | * Global Data |
| 23 | * |
| 24 | ********************************************/ |
| 25 | |
| 26 | typedef struct { |
| 27 | wilc_debug_func dPrint; |
| 28 | |
| 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; |
| 48 | |
| 49 | static wilc_mac_cfg_t g_mac; |
| 50 | |
| 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} |
| 92 | }; |
| 93 | |
| 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} |
| 113 | }; |
| 114 | |
| 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} |
| 135 | |
| 136 | }; |
| 137 | |
| 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} |
| 160 | }; |
| 161 | |
| 162 | /******************************************** |
| 163 | * |
| 164 | * Configuration Functions |
| 165 | * |
| 166 | ********************************************/ |
| 167 | |
| 168 | static int wilc_wlan_cfg_set_byte(uint8_t *frame, uint32_t offset, uint16_t id, uint8_t val8) |
| 169 | { |
| 170 | uint8_t *buf; |
| 171 | |
| 172 | if ((offset + 4) >= MAX_CFG_FRAME_SIZE) |
| 173 | return 0; |
| 174 | |
| 175 | buf = &frame[offset]; |
| 176 | |
| 177 | buf[0] = (uint8_t)id; |
| 178 | buf[1] = (uint8_t)(id >> 8); |
| 179 | buf[2] = 1; |
| 180 | buf[3] = val8; |
| 181 | return 4; |
| 182 | } |
| 183 | |
| 184 | static int wilc_wlan_cfg_set_hword(uint8_t *frame, uint32_t offset, uint16_t id, uint16_t val16) |
| 185 | { |
| 186 | uint8_t *buf; |
| 187 | |
| 188 | if ((offset + 5) >= MAX_CFG_FRAME_SIZE) |
| 189 | return 0; |
| 190 | |
| 191 | buf = &frame[offset]; |
| 192 | |
| 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); |
| 198 | |
| 199 | return 5; |
| 200 | } |
| 201 | |
| 202 | static int wilc_wlan_cfg_set_word(uint8_t *frame, uint32_t offset, uint16_t id, uint32_t val32) |
| 203 | { |
| 204 | uint8_t *buf; |
| 205 | |
| 206 | if ((offset + 7) >= MAX_CFG_FRAME_SIZE) |
| 207 | return 0; |
| 208 | |
| 209 | buf = &frame[offset]; |
| 210 | |
| 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); |
| 218 | |
| 219 | return 7; |
| 220 | } |
| 221 | |
| 222 | static int wilc_wlan_cfg_set_str(uint8_t *frame, uint32_t offset, uint16_t id, uint8_t *str, uint32_t size) |
| 223 | { |
| 224 | uint8_t *buf; |
| 225 | |
| 226 | if ((offset + size + 3) >= MAX_CFG_FRAME_SIZE) |
| 227 | return 0; |
| 228 | |
| 229 | buf = &frame[offset]; |
| 230 | |
| 231 | buf[0] = (uint8_t)id; |
| 232 | buf[1] = (uint8_t)(id >> 8); |
| 233 | buf[2] = (uint8_t)size; |
| 234 | |
| 235 | if ((str != NULL) && (size != 0)) |
| 236 | memcpy(&buf[3], str, size); |
| 237 | |
| 238 | return (size + 3); |
| 239 | } |
| 240 | |
| 241 | static int wilc_wlan_cfg_set_bin(uint8_t *frame, uint32_t offset, uint16_t id, uint8_t *b, uint32_t size) |
| 242 | { |
| 243 | uint8_t *buf; |
| 244 | uint32_t i; |
| 245 | uint8_t checksum = 0; |
| 246 | |
| 247 | if ((offset + size + 5) >= MAX_CFG_FRAME_SIZE) |
| 248 | return 0; |
| 249 | |
| 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); |
| 255 | |
| 256 | if ((b != NULL) && (size != 0)) { |
| 257 | memcpy(&buf[4], b, size); |
| 258 | for (i = 0; i < size; i++) { |
| 259 | checksum += buf[i + 4]; |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | buf[size + 4] = checksum; |
| 264 | |
| 265 | return (size + 5); |
| 266 | } |
| 267 | |
| 268 | /******************************************** |
| 269 | * |
| 270 | * Configuration Response Functions |
| 271 | * |
| 272 | ********************************************/ |
| 273 | |
| 274 | static void wilc_wlan_parse_response_frame(uint8_t *info, int size) |
| 275 | { |
| 276 | uint32_t wid, len = 0, i = 0; |
| 277 | static int seq; |
| 278 | |
| 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; |
| 291 | |
| 292 | if (g_cfg_byte[i].id == wid) { |
| 293 | g_cfg_byte[i].val = info[3]; |
| 294 | break; |
| 295 | } |
| 296 | i++; |
| 297 | } while (1); |
| 298 | len = 2; |
| 299 | break; |
| 300 | |
| 301 | case WID_SHORT: |
| 302 | do { |
| 303 | if (g_cfg_hword[i].id == WID_NIL) |
| 304 | break; |
| 305 | |
| 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; |
| 313 | } |
| 314 | i++; |
| 315 | } while (1); |
| 316 | len = 3; |
| 317 | break; |
| 318 | |
| 319 | case WID_INT: |
| 320 | do { |
| 321 | if (g_cfg_word[i].id == WID_NIL) |
| 322 | break; |
| 323 | |
| 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; |
| 331 | } |
| 332 | i++; |
| 333 | } while (1); |
| 334 | len = 5; |
| 335 | break; |
| 336 | |
| 337 | case WID_STR: |
| 338 | do { |
| 339 | if (g_cfg_str[i].id == WID_NIL) |
| 340 | break; |
| 341 | |
| 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); |
| 347 | |
| 348 | PRINT_INFO(GENERIC_DBG, "Site survey results value[%d]toggle[%d]\n", size, toggle); |
| 349 | i += toggle; |
| 350 | toggle ^= 1; |
| 351 | } |
| 352 | memcpy(g_cfg_str[i].str, &info[2], (info[2] + 1)); |
| 353 | break; |
| 354 | } |
| 355 | i++; |
| 356 | } while (1); |
| 357 | len = 1 + info[2]; |
| 358 | break; |
| 359 | |
| 360 | default: |
| 361 | break; |
| 362 | } |
| 363 | size -= (2 + len); |
| 364 | info += (2 + len); |
| 365 | } |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | static int wilc_wlan_parse_info_frame(uint8_t *info, int size) |
| 369 | { |
| 370 | wilc_mac_cfg_t *pd = (wilc_mac_cfg_t *)&g_mac; |
| 371 | uint32_t wid, len; |
| 372 | int type = WILC_CFG_RSP_STATUS; |
| 373 | |
| 374 | wid = info[0] | (info[1] << 8); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 375 | |
| 376 | len = info[2]; |
| 377 | PRINT_INFO(GENERIC_DBG, "Status Len = %d Id= %d\n", len, wid); |
| 378 | if ((len == 1) && (wid == WID_STATUS)) { |
| 379 | pd->mac_status = info[3]; |
| 380 | type = WILC_CFG_RSP_STATUS; |
| 381 | } |
| 382 | |
| 383 | return type; |
| 384 | } |
| 385 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 386 | /******************************************** |
| 387 | * |
| 388 | * Configuration Exported Functions |
| 389 | * |
| 390 | ********************************************/ |
| 391 | |
| 392 | static int wilc_wlan_cfg_set_wid(uint8_t *frame, uint32_t offset, uint16_t id, uint8_t *buf, int size) |
| 393 | { |
| 394 | uint8_t type = (id >> 12) & 0xf; |
| 395 | int ret = 0; |
| 396 | |
| 397 | if (type == 0) { /* byte command */ |
| 398 | if (size >= 1) |
| 399 | ret = wilc_wlan_cfg_set_byte(frame, offset, id, *buf); |
| 400 | } else if (type == 1) { /* half word command */ |
| 401 | if (size >= 2) |
| 402 | ret = wilc_wlan_cfg_set_hword(frame, offset, id, *((uint16_t *)buf)); |
| 403 | } else if (type == 2) { /* word command */ |
| 404 | if (size >= 4) |
| 405 | ret = wilc_wlan_cfg_set_word(frame, offset, id, *((uint32_t *)buf)); |
| 406 | } else if (type == 3) { /* string command */ |
| 407 | ret = wilc_wlan_cfg_set_str(frame, offset, id, buf, size); |
| 408 | } else if (type == 4) { /* binary command */ |
| 409 | ret = wilc_wlan_cfg_set_bin(frame, offset, id, buf, size); |
| 410 | } else { |
| 411 | g_mac.dPrint(N_ERR, "illegal id\n"); |
| 412 | } |
| 413 | |
| 414 | return ret; |
| 415 | } |
| 416 | |
| 417 | static int wilc_wlan_cfg_get_wid(uint8_t *frame, uint32_t offset, uint16_t id) |
| 418 | { |
| 419 | uint8_t *buf; |
| 420 | |
| 421 | if ((offset + 2) >= MAX_CFG_FRAME_SIZE) |
| 422 | return 0; |
| 423 | |
| 424 | buf = &frame[offset]; |
| 425 | |
| 426 | buf[0] = (uint8_t)id; |
| 427 | buf[1] = (uint8_t)(id >> 8); |
| 428 | |
| 429 | return 2; |
| 430 | } |
| 431 | |
| 432 | static int wilc_wlan_cfg_get_wid_value(uint16_t wid, uint8_t *buffer, uint32_t buffer_size) |
| 433 | { |
| 434 | uint32_t type = (wid >> 12) & 0xf; |
| 435 | int i, ret = 0; |
| 436 | |
| 437 | if (wid == WID_STATUS) { |
| 438 | *((uint32_t *)buffer) = g_mac.mac_status; |
| 439 | return 4; |
| 440 | } |
| 441 | |
| 442 | i = 0; |
| 443 | if (type == 0) { /* byte command */ |
| 444 | do { |
| 445 | if (g_cfg_byte[i].id == WID_NIL) |
| 446 | break; |
| 447 | |
| 448 | if (g_cfg_byte[i].id == wid) { |
| 449 | memcpy(buffer, &g_cfg_byte[i].val, 1); |
| 450 | ret = 1; |
| 451 | break; |
| 452 | } |
| 453 | i++; |
| 454 | } while (1); |
| 455 | } else if (type == 1) { /* half word command */ |
| 456 | do { |
| 457 | if (g_cfg_hword[i].id == WID_NIL) |
| 458 | break; |
| 459 | |
| 460 | if (g_cfg_hword[i].id == wid) { |
| 461 | memcpy(buffer, &g_cfg_hword[i].val, 2); |
| 462 | ret = 2; |
| 463 | break; |
| 464 | } |
| 465 | i++; |
| 466 | } while (1); |
| 467 | } else if (type == 2) { /* word command */ |
| 468 | do { |
| 469 | if (g_cfg_word[i].id == WID_NIL) |
| 470 | break; |
| 471 | |
| 472 | if (g_cfg_word[i].id == wid) { |
| 473 | memcpy(buffer, &g_cfg_word[i].val, 4); |
| 474 | ret = 4; |
| 475 | break; |
| 476 | } |
| 477 | i++; |
| 478 | } while (1); |
| 479 | } else if (type == 3) { /* string command */ |
| 480 | do { |
| 481 | if (g_cfg_str[i].id == WID_NIL) |
| 482 | break; |
| 483 | |
| 484 | if (g_cfg_str[i].id == wid) { |
| 485 | uint32_t size = g_cfg_str[i].str[0]; |
| 486 | if (buffer_size >= size) { |
| 487 | if (g_cfg_str[i].id == WID_SITE_SURVEY_RESULTS) { |
| 488 | static int toggle; |
| 489 | PRINT_INFO(GENERIC_DBG, "Site survey results value[%d]\n", |
| 490 | size); |
| 491 | i += toggle; |
| 492 | toggle ^= 1; |
| 493 | |
| 494 | } |
| 495 | memcpy(buffer, &g_cfg_str[i].str[1], size); |
| 496 | ret = size; |
| 497 | } |
| 498 | break; |
| 499 | } |
| 500 | i++; |
| 501 | } while (1); |
| 502 | } else { |
| 503 | g_mac.dPrint(N_ERR, "[CFG]: illegal type (%08x)\n", wid); |
| 504 | } |
| 505 | |
| 506 | return ret; |
| 507 | } |
| 508 | |
| 509 | static int wilc_wlan_cfg_indicate_rx(uint8_t *frame, int size, wilc_cfg_rsp_t *rsp) |
| 510 | { |
| 511 | int ret = 1; |
| 512 | uint8_t msg_type; |
| 513 | uint8_t msg_id; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 514 | #ifdef WILC_FULLY_HOSTING_AP |
Chaehyun Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 515 | u32 *ptru32Frame; |
Dean Lee | 72ed4dc | 2015-06-12 14:11:44 +0900 | [diff] [blame] | 516 | bool bStatus = frame[2]; |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 517 | |
| 518 | #ifdef BIG_ENDIAN |
| 519 | ptru32Frame = (frame[4] << 24) | (frame[5] << 16) | (frame[6] << 8) | frame[7]; |
| 520 | #else |
| 521 | ptru32Frame = (frame[7] << 24) | (frame[6] << 16) | (frame[5] << 8) | frame[4]; |
| 522 | #endif /* BIG_ENDIAN */ |
| 523 | |
| 524 | #endif /* WILC_FULLY_HOSTING_AP */ |
| 525 | |
| 526 | msg_type = frame[0]; |
| 527 | msg_id = frame[1]; /* seq no */ |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 528 | frame += 4; |
| 529 | size -= 4; |
| 530 | |
| 531 | /** |
| 532 | * The valid types of response messages are 'R' (Response), 'I' (Information), and 'N' (Network Information) |
| 533 | **/ |
| 534 | |
| 535 | switch (msg_type) { |
| 536 | case 'R': |
| 537 | wilc_wlan_parse_response_frame(frame, size); |
| 538 | rsp->type = WILC_CFG_RSP; |
| 539 | rsp->seq_no = msg_id; |
| 540 | break; |
| 541 | |
| 542 | case 'I': |
| 543 | rsp->type = wilc_wlan_parse_info_frame(frame, size); |
| 544 | rsp->seq_no = msg_id; |
| 545 | /*call host interface info parse as well*/ |
| 546 | PRINT_INFO(RX_DBG, "Info message received\n"); |
| 547 | GnrlAsyncInfoReceived(frame - 4, size + 4); |
| 548 | break; |
| 549 | |
| 550 | case 'L': |
| 551 | #ifndef SWITCH_LOG_TERMINAL |
Chandra S Gorentla | 17aacd4 | 2015-08-08 17:41:35 +0530 | [diff] [blame] | 552 | PRINT_ER("Unexpected firmware log message received\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 553 | #else |
| 554 | PRINT_D(FIRM_DBG, "\nFIRMWARE LOGS :\n<<\n%s\n>>\n", frame); |
| 555 | break; |
| 556 | |
| 557 | #endif |
| 558 | #if 1 |
| 559 | case 'N': |
| 560 | NetworkInfoReceived(frame - 4, size + 4); |
| 561 | rsp->type = 0; |
| 562 | break; |
| 563 | |
| 564 | #endif |
| 565 | /*bug3819:*/ |
| 566 | case 'S': |
Chandra S Gorentla | 17aacd4 | 2015-08-08 17:41:35 +0530 | [diff] [blame] | 567 | PRINT_INFO(RX_DBG, "Scan Notification Received\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 568 | host_int_ScanCompleteReceived(frame - 4, size + 4); |
| 569 | break; |
| 570 | |
| 571 | #ifdef WILC_FULLY_HOSTING_AP |
| 572 | case 'T': |
Chandra S Gorentla | 17aacd4 | 2015-08-08 17:41:35 +0530 | [diff] [blame] | 573 | PRINT_INFO(RX_DBG, "TBTT Notification Received\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 574 | process_tbtt_isr(); |
| 575 | break; |
| 576 | |
| 577 | case 'A': |
Chandra S Gorentla | 17aacd4 | 2015-08-08 17:41:35 +0530 | [diff] [blame] | 578 | PRINT_INFO(RX_DBG, "HOSTAPD ACK Notification Received\n"); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 579 | WILC_mgm_HOSTAPD_ACK(ptru32Frame, bStatus); |
| 580 | break; |
| 581 | #endif |
| 582 | |
| 583 | default: |
| 584 | PRINT_INFO(RX_DBG, "Receive unknown message type[%d-%d-%d-%d-%d-%d-%d-%d]\n", |
| 585 | frame[0], frame[1], frame[2], frame[3], frame[4], |
| 586 | frame[5], frame[6], frame[7]); |
| 587 | rsp->type = 0; |
| 588 | rsp->seq_no = msg_id; |
| 589 | ret = 0; |
| 590 | break; |
| 591 | } |
| 592 | |
| 593 | return ret; |
| 594 | } |
| 595 | |
| 596 | static int wilc_wlan_cfg_init(wilc_debug_func func) |
| 597 | { |
| 598 | memset((void *)&g_mac, 0, sizeof(wilc_mac_cfg_t)); |
| 599 | g_mac.dPrint = func; |
| 600 | return 1; |
| 601 | } |
| 602 | |
| 603 | wilc_cfg_func_t mac_cfg = { |
| 604 | wilc_wlan_cfg_set_wid, |
| 605 | wilc_wlan_cfg_get_wid, |
| 606 | wilc_wlan_cfg_get_wid_value, |
| 607 | wilc_wlan_cfg_indicate_rx, |
| 608 | wilc_wlan_cfg_init, |
| 609 | }; |