2016-11-12 18:54:24 +00:00
|
|
|
/* Recreated Espressif libwpa wpa_main.o contents.
|
|
|
|
|
|
|
|
Copyright (C) 2015 Espressif Systems. Derived from MIT Licensed SDK libraries.
|
|
|
|
BSD Licensed as described in the file LICENSE
|
|
|
|
*/
|
|
|
|
|
2017-06-06 02:47:21 +00:00
|
|
|
#include <strings.h>
|
|
|
|
#include <string.h>
|
2016-11-23 15:55:48 +00:00
|
|
|
#include "espressif/user_interface.h"
|
|
|
|
#include "etstimer.h"
|
|
|
|
#include "espressif/osapi.h"
|
2017-06-06 02:47:21 +00:00
|
|
|
#include "espressif/esp_sta.h"
|
2016-11-23 15:55:48 +00:00
|
|
|
#include "esplibs/libnet80211.h"
|
|
|
|
#include "esplibs/libmain.h"
|
|
|
|
#include "esplibs/libwpa.h"
|
|
|
|
#include "esplibs/libpp.h"
|
|
|
|
#include "lwip/dhcp.h"
|
2017-01-02 22:40:54 +00:00
|
|
|
#include "esp/rtcmem_regs.h"
|
2016-11-23 15:55:48 +00:00
|
|
|
|
|
|
|
static void wpa_callback1(struct pbuf* pb) {
|
|
|
|
struct netif *netif = sdk_g_ic.v.station_netif_info->netif;
|
|
|
|
sdk_ieee80211_output_pbuf(netif, pb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wpa_callback2(int arg0) {
|
|
|
|
struct sdk_g_ic_netif_info *netif_info = sdk_g_ic.v.station_netif_info;
|
|
|
|
sdk_ieee80211_send_mgmt(netif_info, 192, arg0);
|
|
|
|
sdk_ieee80211_sta_new_state(&sdk_g_ic, 2, (arg0 << 8) | 192);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sdk_wpa_config_profile(struct sdk_g_ic_st *g_ic) {
|
|
|
|
uint8_t v = g_ic->s._unknown209;
|
|
|
|
|
|
|
|
if (v == 2 || v == 3 || v == 6) {
|
|
|
|
sdk_wpa_set_profile(1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v == 4 || v == 5 || v == 7)
|
|
|
|
sdk_wpa_set_profile(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void sdk_wpa_config_bss(struct sdk_g_ic_st *g_ic, uint8_t (* hwaddr2)[6]) {
|
|
|
|
struct sdk_g_ic_netif_info *netif_info = g_ic->v.station_netif_info;
|
|
|
|
struct netif *netif = netif_info->netif;
|
|
|
|
sdk_wpa_set_bss(netif->hwaddr, hwaddr2, g_ic->s._unknown20a, g_ic->s._unknown20c,
|
2017-06-06 02:47:21 +00:00
|
|
|
g_ic->s.sta_password, g_ic->s.sta_ssid.ssid,
|
|
|
|
g_ic->s.sta_ssid.ssid_length);
|
2016-11-23 15:55:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void sdk_wpa_config_assoc_ie(int arg0, int16_t *arg1, int32_t arg2) {
|
|
|
|
if (arg0 != 1)
|
|
|
|
sdk_g_ic.v._unknown178 = arg1;
|
|
|
|
else
|
|
|
|
sdk_g_ic.v._unknown174 = arg1;
|
|
|
|
|
|
|
|
*arg1 = arg2;
|
|
|
|
}
|
|
|
|
|
2017-06-06 02:47:21 +00:00
|
|
|
void sdk_dhcp_bind_check(void *parg) {
|
2016-11-23 15:55:48 +00:00
|
|
|
struct sdk_g_ic_netif_info *netif_info = sdk_g_ic.v.station_netif_info;
|
|
|
|
uint8_t connect_status = netif_info->connect_status;
|
|
|
|
uint8_t unknown20a = sdk_g_ic.s._unknown20a;
|
|
|
|
|
2017-06-06 02:47:21 +00:00
|
|
|
if (connect_status != STATION_GOT_IP) {
|
2016-11-23 15:55:48 +00:00
|
|
|
if (unknown20a == 7 || unknown20a == 8) {
|
2017-06-06 02:47:21 +00:00
|
|
|
netif_info->connect_status = STATION_CONNECTING;
|
2016-11-23 15:55:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void sdk_eagle_auth_done() {
|
|
|
|
struct sdk_g_ic_netif_info *netif_info = sdk_g_ic.v.station_netif_info;
|
|
|
|
struct netif *netif = netif_info->netif;
|
2017-06-06 02:47:21 +00:00
|
|
|
struct sdk_cnx_node *cnx_node = netif_info->_unknown88;
|
2016-11-23 15:55:48 +00:00
|
|
|
|
2017-06-06 02:47:21 +00:00
|
|
|
if (cnx_node->_unknown08 & 1)
|
2016-11-23 15:55:48 +00:00
|
|
|
return;
|
|
|
|
|
2017-08-18 07:36:00 +00:00
|
|
|
uint32_t channel = cnx_node->channel->num;
|
2017-06-06 02:47:21 +00:00
|
|
|
char *ssid = (char *)sdk_g_ic.s.sta_ssid.ssid;
|
2016-11-23 15:55:48 +00:00
|
|
|
printf("\nconnected with %s, channel %d\n", ssid, channel);
|
|
|
|
|
|
|
|
RTCMEM_SYSTEM[61] = 0x00010000 | channel;
|
|
|
|
|
|
|
|
ETSTimer *timer = &netif_info->timer;
|
|
|
|
sdk_os_timer_disarm(timer);
|
|
|
|
sdk_os_timer_setfn(timer, sdk_dhcp_bind_check, 0);
|
|
|
|
sdk_os_timer_arm(timer, 15000, 0);
|
|
|
|
|
|
|
|
netif_info->statusb9 = 0;
|
2017-06-06 02:47:21 +00:00
|
|
|
cnx_node->_unknown18 = 0;
|
|
|
|
cnx_node->_unknown08 |= 1;
|
2016-11-23 15:55:48 +00:00
|
|
|
|
2017-06-06 02:47:21 +00:00
|
|
|
if (dhcp_supplied_address(netif))
|
2016-11-23 15:55:48 +00:00
|
|
|
return;
|
|
|
|
|
2017-06-06 02:47:21 +00:00
|
|
|
if (sdk_dhcpc_flag != DHCP_STOPPED) {
|
|
|
|
printf("dhcp client start...\n");
|
|
|
|
netif_set_up(netif);
|
|
|
|
dhcp_start(netif);
|
2016-11-23 15:55:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-06 02:47:21 +00:00
|
|
|
if (ip4_addr_isany_val(sdk_info.sta_ipaddr)) {
|
|
|
|
printf("expected a static ip address?\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
netif_set_addr(netif, &sdk_info.sta_ipaddr, &sdk_info.sta_netmask, &sdk_info.sta_gw);
|
2016-11-23 15:55:48 +00:00
|
|
|
netif_set_up(netif);
|
2017-06-06 02:47:21 +00:00
|
|
|
sdk_system_station_got_ip_set(ip_2_ip4(&netif->ip_addr),
|
|
|
|
ip_2_ip4(&netif->netmask),
|
|
|
|
ip_2_ip4(&netif->gw));
|
2016-11-23 15:55:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void sdk_wpa_neg_complete() {
|
|
|
|
sdk_eagle_auth_done();
|
|
|
|
}
|
|
|
|
|
|
|
|
void sdk_wpa_attach(struct sdk_g_ic_st *g_ic) {
|
|
|
|
g_ic->v._unknown180 = NULL;
|
|
|
|
g_ic->v._unknown184 = &(g_ic->v._unknown180);
|
|
|
|
sdk_wpa_register(0, wpa_callback1, sdk_wpa_config_assoc_ie, sdk_ppInstallKey,
|
|
|
|
wpa_callback2, sdk_wpa_neg_complete);
|
|
|
|
sdk_ppRegisterTxCallback(sdk_eapol_txcb, 3);
|
|
|
|
}
|