Skip to content

Refactored AUTH_MODE and WIFI_MODE definitions and usage #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/include/wifi.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#ifndef WIFI_ST_PASSWORD
#define WIFI_ST_PASSWORD "0123456789"
#endif
#ifndef WIFI_MODE
#define WIFI_MODE STATIONAP_MODE // SOFTAP_MODE // STATION_MODE
#ifndef DEFAULT_WIFI_MODE
#define DEFAULT_WIFI_MODE STATIONAP_MODE // SOFTAP_MODE // STATION_MODE
#endif
#ifndef WIFI_ST_AUTOCONNECT
#define WIFI_ST_AUTOCONNECT 0
Expand Down
34 changes: 17 additions & 17 deletions app/sdklib/system/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,7 @@ void ICACHE_FLASH_ATTR tst_cfg_wifi(void)
struct s_wifi_store * wifi_config = &g_ic.g.wifi_store;
wifi_softap_set_default_ssid();
wifi_station_set_default_hostname(info.st_mac);
if(wifi_config->wfmode[0] == 0xff) wifi_config->wfmode[0] = SOFTAP_MODE;
else wifi_config->wfmode[0] &= 3;
if( WIFI_UNKNOWN_MODE <= wifi_config->wfmode[0]) wifi_config->wfmode[0] = SOFTAP_MODE;
wifi_config->wfmode[1] = 0;
if(wifi_config->wfchl >= 14 || wifi_config->wfchl == 0) {
wifi_config->wfchl = 1;
Expand All @@ -363,24 +362,25 @@ void ICACHE_FLASH_ATTR tst_cfg_wifi(void)
wifi_config->beacon = 100;
}
wDev_Set_Beacon_Int((wifi_config->beacon/100)*102400);
if(wifi_config->field_310 >= 5 || wifi_config->field_310 == 1){
wifi_config->field_310 = 0;
ets_bzero(wifi_config->ap_passw, 64);
if(wifi_config->authmode >= AUTH_MAX || wifi_config->authmode == AUTH_WEP){
wifi_config->authmode = AUTH_OPEN;
ets_bzero(wifi_config->ap_passw, sizeof(wifi_config->ap_passw));
}
if(wifi_config->field_311 > 2) wifi_config->field_311 = 0;
if(wifi_config->field_312 > 8) wifi_config->field_312 = 4;
if(wifi_config->st_ssid_len == 0xffffffff) {
ets_bzero(&wifi_config->st_ssid_len, 36);
ets_bzero(&wifi_config->st_passw, 64);
if(wifi_config->st_ssid_len > 32) {
ets_bzero(&wifi_config->st_ssid_len, sizeof(wifi_config->st_ssid_len));
ets_bzero(&wifi_config->st_ssid, sizeof(wifi_config->st_ssid));
ets_bzero(&wifi_config->st_passw, sizeof(wifi_config->st_passw));
}
wifi_config->field_880 = 0;
wifi_config->field_884 = 0;
g_ic.c[257] = 0; // ?

if(wifi_config->field_316 > 6) wifi_config->field_316 = 1;
if(wifi_config->field_169 > 2) wifi_config->field_169 = 0; // +169
wifi_config->phy_mode &= 3;
if(wifi_config->phy_mode == 0 ) wifi_config->phy_mode = 3; // phy_mode
wifi_config->phy_mode &= PHY_MODE_11N;
if(wifi_config->phy_mode < PHY_MODE_11B ) wifi_config->phy_mode = PHY_MODE_11N; // phy_mode
}
//=============================================================================
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -591,31 +591,31 @@ void ICACHE_FLASH_ATTR startup(void)
#endif
WDT_FEED = WDT_FEED_MAGIC; // WDT
//
int wfmode = g_ic.g.wifi_store.wfmode[0]; // g_ic.c[0x214] (+532) SDK 1.2.0 // SDK 1.3.0 g_ic.c[472]
WIFI_MODE wfmode = g_ic.g.wifi_store.wfmode[0]; // g_ic.c[0x214] (+532) SDK 1.2.0 // SDK 1.3.0 g_ic.c[472]
wifi_mode_set(wfmode);
if(wfmode & 1) wifi_station_start();
if(wfmode & SOFTAP_MODE) wifi_station_start();
#if DEF_SDK_VERSION >= 1200
if(wfmode == 2) {
if(SOFTAP_MODE == wfmode) {
#if DEF_SDK_VERSION >= 1400
if(g_ic.c[470] != 2) wifi_softap_start(0);
#else
if(g_ic.c[446] != 2) wifi_softap_start(0);
#endif
else wifi_softap_start(1);
}
else if(wfmode == 3) {
else if(STATIONAP_MODE == wfmode) {
wifi_softap_start(0);
}
#else
if(wfmode & 2) wifi_softap_start();
if(wfmode & SOFTAP_MODE) wifi_softap_start();
#endif

#if DEF_SDK_VERSION >= 1110
if(wfmode == 1) netif_set_default(*g_ic.g.netif1); // struct netif *
if(STATION_MODE == wfmode) netif_set_default(*g_ic.g.netif1); // struct netif *
#else
if(wfmode) {
struct netif * * p;
if(wfmode == 1) p = g_ic.g.netif1; // g_ic+0x10;
if(wfmode == STATION_MODE) p = g_ic.g.netif1; // g_ic+0x10;
else p = g_ic.g.netif2; // g_ic+0x14;
netif_set_default(*p); // struct netif *
}
Expand Down
2 changes: 1 addition & 1 deletion app/web/netbios.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ netbios_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, ip_addr_t *addr, u
uint32 ip = 0;
{
struct ip_info wifi_info;
uint8 opmode = wifi_get_opmode();
WIFI_MODE opmode = wifi_get_opmode();
if((opmode & STATION_MODE)
&& wifi_get_ip_info(STATION_IF, &wifi_info)
&& wifi_info.ip.addr == ip_current_netif()->ip_addr.addr) {
Expand Down
9 changes: 4 additions & 5 deletions app/web/web_int_callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,8 @@ void ICACHE_FLASH_ATTR get_new_url(TCP_SERV_CONN *ts_conn)
uint32 ip = 0;
uint32 ip_ap = 0;
uint32 ip_st = 0;
// int z = NULL_MODE;
struct ip_info wifi_info;
uint8 opmode = wifi_get_opmode();
WIFI_MODE opmode = wifi_get_opmode();
if(opmode == STATIONAP_MODE) {
if((opmode & STATION_MODE) && wifi_get_ip_info(STATION_IF, &wifi_info)) {
ip_st = wifi_info.ip.addr;
Expand All @@ -444,7 +443,7 @@ void ICACHE_FLASH_ATTR get_new_url(TCP_SERV_CONN *ts_conn)
};
};
opmode &= wificonfig.b.mode;
if(opmode == 0) opmode = wificonfig.b.mode;
if(WIFI_DISABLED == opmode) opmode = wificonfig.b.mode;
if(wificonfig.ap.ipinfo.ip.addr == 0 || (opmode & SOFTAP_MODE)) {
ip = wificonfig.ap.ipinfo.ip.addr;
#ifdef USE_NETBIOS
Expand Down Expand Up @@ -782,7 +781,7 @@ void ICACHE_FLASH_ATTR web_int_callback(TCP_SERV_CONN *ts_conn, uint8 *cstr)
cstr+=3;
struct ip_info wifi_info;
if(if_index == SOFTAP_IF) {
// SOFTAP
// SOFTAP_MODE
ifcmp("dhcp") tcp_puts("%d", (dhcps_flag==0)? 0 : 1);
else ifcmp("mac") {
uint8 macaddr[6];
Expand Down Expand Up @@ -825,7 +824,7 @@ void ICACHE_FLASH_ATTR web_int_callback(TCP_SERV_CONN *ts_conn, uint8 *cstr)
};
}
else {
// STATION
// STATION_MODE
ifcmp("dhcp") tcp_puts("%d", (dhcpc_flag==0)? 0 : 1);
else ifcmp("rssi") tcp_puts("%d", wifi_station_get_rssi());
else ifcmp("aucn") tcp_puts("%d", wifi_station_get_auto_connect());
Expand Down
10 changes: 5 additions & 5 deletions app/web/wifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void ICACHE_FLASH_ATTR read_macaddr_from_otp(uint8 *mac)
******************************************************************************/
void ICACHE_FLASH_ATTR WiFi_go_to_sleep(enum sleep_type mode, uint32 time_us)
{
wifi_set_opmode_current(NULL_MODE);
wifi_set_opmode_current(WIFI_DISABLED);
wifi_fpm_set_sleep_type(mode); // wifi_fpm_set_sleep_type(LIGHT_SLEEP_T);
wifi_fpm_open();
wifi_fpm_do_sleep(time_us);
Expand Down Expand Up @@ -349,7 +349,7 @@ void ICACHE_FLASH_ATTR Set_default_wificfg(struct wifi_config *wcfg,
os_memset(wcfg, 0, sizeof(wificonfig));
uwifi_chg wset;
wset.ui = wifi_set_mask;
if (wset.b.mode) wcfg->b.mode = WIFI_MODE;
if (wset.b.mode) wcfg->b.mode = DEFAULT_WIFI_MODE;
if (wset.b.phy) wcfg->b.phy = PHY_MODE;
// if (wset.b.chl)
wcfg->b.chl = 1; // for sniffer
Expand Down Expand Up @@ -585,10 +585,10 @@ void ICACHE_FLASH_ATTR wifi_start_scan(void)
#if DEBUGSOO > 1
os_printf("\nStart Wifi Scan...");
#endif
int x = wifi_get_opmode();
if(!(x&1)) {
WIFI_MODE curr_mode = wifi_get_opmode();
if(!(curr_mode & STATION_MODE)) {
wifi_station_set_auto_connect(0);
wifi_set_opmode_current(x|STATION_MODE);
wifi_set_opmode_current(curr_mode | STATION_MODE);
}
if(! wifi_station_scan(NULL, wifi_scan_cb)) {
#if DEBUGSOO > 1
Expand Down
9 changes: 5 additions & 4 deletions include/sdk/libmain.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "sdk/sdk_config.h"
#include "c_types.h"
#include "user_interface.h"

//=============================================================================
// extern data
Expand Down Expand Up @@ -44,9 +45,9 @@ struct s_wifi_store { // WiFi config flash addr: flashchip->chip_size - 0x3000 o
#if DEF_SDK_VERSION >= 1400 // SDK >= 1.4.0
uint8 boot_info[8]; //+000 g_ic+? 504 boot_version SDK 1.5.2 // 0x3FFEF164
uint8 wfmode[4]; //+008 g_ic.c[0x1D8] (+472) SDK 1.3.0 // 3FFF083C
uint32 st_ssid_len; //+012 g_ic+?
uint8 st_ssid[32]; //+016
uint8 field_048[7]; //+048
uint32 st_ssid_len; //+012 g_ic.c +004
uint8 st_ssid[32]; //+016 g_ic.c +008
uint8 field_048[7]; //+048 g_ic.c +
uint8 st_passw[64]; //+055
uint8 field_119; //+119
uint8 data_120[32]; //+120
Expand All @@ -59,7 +60,7 @@ struct s_wifi_store { // WiFi config flash addr: flashchip->chip_size - 0x3000 o
uint8 field_276[32]; //+276
uint8 field_308; //+308
uint8 wfchl; //+309
uint8 field_310; //+310
AUTH_MODE authmode; //+310
uint8 field_311; //+311
uint8 field_312; //+312
uint8 field_313; //+313
Expand Down
11 changes: 7 additions & 4 deletions include/user_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,13 @@ void system_soft_wdt_feed(void);

void system_show_malloc(void);

#define NULL_MODE 0x00
#define STATION_MODE 0x01
#define SOFTAP_MODE 0x02
#define STATIONAP_MODE 0x03
typedef enum _wifi_mode {
WIFI_DISABLED = 0,
STATION_MODE,
SOFTAP_MODE,
STATIONAP_MODE = (STATION_MODE | SOFTAP_MODE),
WIFI_UNKNOWN_MODE
} WIFI_MODE;

typedef enum _auth_mode {
AUTH_OPEN = 0,
Expand Down