Fix indentation

pull/84/head
KatAst 9 years ago
parent 8351fb4599
commit 9dd3eac804
  1. 49
      esp-link/cgiwifi.c

@ -1,3 +1,7 @@
/*
Cgi/template routines for the /wifi url.
*/
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
@ -7,8 +11,6 @@
* ----------------------------------------------------------------------------
* Heavily modified and enhanced by Thorsten von Eicken in 2015
* ----------------------------------------------------------------------------
* Once again heavily modified to add soft-ap settings by KatAst in 2015
* ----------------------------------------------------------------------------
*/
#include <esp8266.h>
@ -39,7 +41,6 @@ struct station_config stconf;
struct softap_config apconf;
uint8_t wifiState = wifiIsDisconnected;
// reasons for which a connection failed
uint8_t wifiReason = 0;
static char *wifiReasons[] = {
@ -273,11 +274,9 @@ static int ICACHE_FLASH_ATTR cgiWiFiGetScan(HttpdConnData *connData) {
}
int ICACHE_FLASH_ATTR cgiWiFiScan(HttpdConnData *connData) {
if (connData->requestType == HTTPD_METHOD_GET) {
return cgiWiFiGetScan(connData);
}else if(connData->requestType == HTTPD_METHOD_POST)
{
}else if(connData->requestType == HTTPD_METHOD_POST) {
// DO NOT start APs scan in AP mode
int mode = wifi_get_opmode();
if(mode==2){
@ -298,13 +297,10 @@ int ICACHE_FLASH_ATTR cgiWiFiScan(HttpdConnData *connData) {
#define RESET_TIMEOUT (15000) // 15 seconds
static ETSTimer resetTimer;
/*
* This routine is ran some time after a connection attempt to an access point.
* If the connection succeeds and Makefile hard-coded CHANGE_TO_STA is set to yes, this gets the module in STA-only mode.
* If it fails and only STA mode is set, it ensures that the module is in STA+AP mode so the user has a chance to recover.
*/
// This routine is ran some time after a connection attempt to an access point. If
// the connect succeeds, this gets the module in STA-only mode. If it fails, it ensures
// that the module is in STA+AP mode so the user has a chance to recover.
static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) {
int x = wifi_station_get_connect_status();
int m = wifi_get_opmode() & 0x3;
DBG("Wifi check: mode=%s status=%d\n", wifiMode[m], x);
@ -349,14 +345,12 @@ static void ICACHE_FLASH_ATTR reassTimerCb(void *arg) {
// This cgi uses the routines above to connect to a specific access point with the
// given ESSID using the given password.
int ICACHE_FLASH_ATTR cgiWiFiConnect(HttpdConnData *connData) {
int mode = wifi_get_opmode();
if(mode == 2){
jsonHeader(connData, 400);
httpdSend(connData, "Can't associate to an AP en SoftAP mode", -1);
return HTTPD_CGI_DONE;
}
char essid[128];
char passwd[128];
@ -380,8 +374,6 @@ int ICACHE_FLASH_ATTR cgiWiFiConnect(HttpdConnData *connData) {
jsonHeader(connData, 400);
httpdSend(connData, "Cannot parse ssid or password", -1);
}
jsonHeader(connData, 400);
httpdSend(connData, "Invalid ssid or password", -1);
return HTTPD_CGI_DONE;
}
@ -528,7 +520,7 @@ int ICACHE_FLASH_ATTR cgiApSettingsChange(HttpdConnData *connData) {
// Do we need a password?
bool pass_need=true;
// Check extra security measure
// Check extra security measure, this must be 1
len=httpdFindArg(connData->getArgs, "100", buff, sizeof(buff));
if(len>0){
if(atoi(buff)!=1){
@ -543,9 +535,9 @@ int ICACHE_FLASH_ATTR cgiApSettingsChange(HttpdConnData *connData) {
os_memset(apconf.ssid, 0, 32);
os_memcpy(apconf.ssid, buff, len);
apconf.ssid_len = len;
pass_need = true;
pass_need = true; // ssid ok, look for a valid password
}else{
pass_need = false;
pass_need = false; // ssid wrong, neither pass not auth mode are needed
jsonHeader(connData, 400);
httpdSend(connData, "SSID not valid or out of range", -1);
return HTTPD_CGI_DONE;
@ -553,13 +545,13 @@ int ICACHE_FLASH_ATTR cgiApSettingsChange(HttpdConnData *connData) {
// Set new PASSWORD
if( pass_need ){
len=httpdFindArg(connData->getArgs, "ap_password", buff, sizeof(buff));
if(checkString(buff) && len>7 && len<62){
if(checkString(buff) && len>7 && len<64){
// STRING PREPROCESSING DONE IN CLIENT SIDE
os_memset(apconf.password, 0, 64);
os_memcpy(apconf.password, buff, len);
pass_need = true;
pass_need = true; // pass ok, look for auth mode
}else if (len == 0){
pass_need = false;
pass_need = false; // pass wrong, no need to look for an auth mode
os_memset(apconf.password, 0, 64);
}else{
jsonHeader(connData, 400);
@ -654,19 +646,14 @@ int ICACHE_FLASH_ATTR cgiApSettingsInfo(HttpdConnData *connData) {
return HTTPD_CGI_DONE;
}
// ===== Wifi set mode end info functions
//This cgi changes the operating mode: STA / AP / STA+AP
int ICACHE_FLASH_ATTR cgiWiFiSetMode(HttpdConnData *connData) {
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
int len;
char buff[1024];
int previous_mode = wifi_get_opmode();
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
len=httpdFindArg(connData->getArgs, "mode", buff, sizeof(buff));
int next_mode = atoi(buff);
if (len!=0) {
@ -698,8 +685,6 @@ int ICACHE_FLASH_ATTR cgiWiFiSetMode(HttpdConnData *connData) {
return HTTPD_CGI_DONE;
}
// Collection of wifi info variables
static char *connStatuses[] = { "idle", "connecting", "wrong password", "AP not found",
"failed", "got IP address" };
@ -725,7 +710,6 @@ static char *apAuthMode[] = { "OPEN",
// print various Wifi information into json buffer
int ICACHE_FLASH_ATTR printWifiInfo(char *buff) {
int len;
//struct station_config stconf;
wifi_station_get_config(&stconf);
@ -803,7 +787,7 @@ int ICACHE_FLASH_ATTR cgiWiFiConnStatus(HttpdConnData *connData) {
#endif
len += os_sprintf(buff+len, "\"x\":0}\n");
DBG(" -> %s\n", buff);
//DBG(" -> %s\n", buff);
httpdSend(connData, buff, len);
return HTTPD_CGI_DONE;
}
@ -948,4 +932,3 @@ void ICACHE_FLASH_ATTR wifiInit() {
os_timer_setfn(&resetTimer, resetTimerCb, NULL);
os_timer_arm(&resetTimer, RESET_TIMEOUT, 0);
}

Loading…
Cancel
Save