2015-09-19 21:06:56 +02:00
/*
* Copyright 2015 Robert Foss . All rights reserved .
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions
* are met :
*
* - Redistributions of source code must retain the above copyright
* notice , this list of conditions and the following disclaimer .
* - Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the
* distribution .
* - Neither the name of the copyright holders nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission .
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* " AS IS " AND ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT
* LIMITED TO , THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED . IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT ,
* INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES
* ( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES ; LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION )
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT ,
* STRICT LIABILITY , OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE )
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE , EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE .
*
* @ author Robert Foss < dev @ robertfoss . se >
2016-01-28 06:52:09 +01:00
*
* Additions & fixes : Johny Mattsson < jmattsson @ dius . com . au >
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
* Jason Follas < jfollas @ gmail . com >
2015-09-19 21:06:56 +02:00
*/
2015-12-16 06:04:58 +01:00
# include "module.h"
2015-09-02 14:41:27 +02:00
# include "lauxlib.h"
2016-03-08 22:55:53 +01:00
# include "lmem.h"
2015-09-02 14:41:27 +02:00
# include "platform.h"
2019-07-21 23:58:21 +02:00
# include <stdlib.h>
# include <stdio.h>
# include <string.h>
2016-01-20 09:37:03 +01:00
# include "ctype.h"
2015-09-02 14:41:27 +02:00
# include "user_interface.h"
# include "espconn.h"
2016-03-24 09:25:49 +01:00
# include "lwip/tcp.h"
# include "lwip/pbuf.h"
2016-09-05 20:17:13 +02:00
# include "vfs.h"
2016-03-01 07:54:10 +01:00
# include "task/task.h"
2015-09-02 14:41:27 +02:00
2019-02-17 19:26:29 +01:00
/* Set this to 1 to generate debug messages. Uses debug callback provided by Lua. Example: enduser_setup.start(successFn, print, print) */
2016-12-01 22:12:47 +01:00
# define ENDUSER_SETUP_DEBUG_ENABLE 0
/* Set this to 1 to output the contents of HTTP requests when debugging. Useful if you need it, but can get pretty noisy */
# define ENDUSER_SETUP_DEBUG_SHOW_HTTP_REQUEST 0
2015-09-02 14:41:27 +02:00
# define MIN(x, y) (((x) < (y)) ? (x) : (y))
2016-01-28 06:52:09 +01:00
# define LITLEN(strliteral) (sizeof (strliteral) -1)
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
# define STRINGIFY(x) #x
# define NUMLEN(x) (sizeof(STRINGIFY(x)) - 1)
2015-09-02 14:41:27 +02:00
2015-09-19 21:06:56 +02:00
# define ENDUSER_SETUP_ERR_FATAL (1 << 0)
# define ENDUSER_SETUP_ERR_NONFATAL (1 << 1)
# define ENDUSER_SETUP_ERR_NO_RETURN (1 << 2)
# define ENDUSER_SETUP_ERR_OUT_OF_MEMORY 1
# define ENDUSER_SETUP_ERR_CONNECTION_NOT_FOUND 2
# define ENDUSER_SETUP_ERR_UNKOWN_ERROR 3
# define ENDUSER_SETUP_ERR_SOCKET_ALREADY_OPEN 4
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
# define ENDUSER_SETUP_ERR_MAX_NUMBER 5
2016-12-01 22:12:47 +01:00
# define ENDUSER_SETUP_ERR_ALREADY_INITIALIZED 6
2015-09-02 14:41:27 +02:00
/**
* DNS Response Packet :
*
* | DNS ID - 16 bits |
* | dns_header |
* | QNAME |
* | dns_body |
* | ip - 32 bits |
*
2015-09-16 14:56:44 +02:00
* DNS Header Part | FLAGS | | Q COUNT | | A CNT | | AUTH CNT | | ADD CNT | */
static const char dns_header [ ] = { 0x80 , 0x00 , 0x00 , 0x01 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 , 0x00 } ;
/* DNS Query Part | Q TYPE | | Q CLASS| */
static const char dns_body [ ] = { 0x00 , 0x01 , 0x00 , 0x01 ,
/* DNS Answer Part |LBL OFFS| | TYPE | | CLASS | | TTL | | RD LEN | */
0xC0 , 0x0C , 0x00 , 0x01 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 , 0x78 , 0x00 , 0x04 } ;
2016-12-01 22:12:47 +01:00
static const char http_html_gz_filename [ ] = " enduser_setup.html.gz " ;
2016-03-29 17:25:05 +02:00
static const char http_html_filename [ ] = " enduser_setup.html " ;
2020-09-15 14:06:38 +02:00
static const char http_header_200 [ ] = " HTTP/1.1 200 OK \r \n Cache-control:no-cache \r \n Connection:close \r \n Content-Type:text/html; charset=utf-8 \r \n " ; /* Note single \r\n here! */
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
static const char http_header_204 [ ] = " HTTP/1.1 204 No Content \r \n Content-Length:0 \r \n Connection:close \r \n \r \n " ;
2020-09-18 23:47:52 +02:00
static const char http_header_302 [ ] = " HTTP/1.1 302 Moved \r \n Location: http://nodemcu.portal/ \r \n Content-Length:0 \r \n Connection:close \r \n \r \n " ;
2019-07-08 21:48:16 +02:00
static const char http_header_302_trying [ ] = " HTTP/1.1 302 Moved \r \n Location: /?trying=true \r \n Content-Length:0 \r \n Connection:close \r \n \r \n " ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
static const char http_header_400 [ ] = " HTTP/1.1 400 Bad request \r \n Content-Length:0 \r \n Connection:close \r \n \r \n " ;
2020-09-15 14:06:38 +02:00
static const char http_header_404 [ ] = " HTTP/1.1 404 Not found \r \n Content-Length:10 \r \n Connection:close \r \n \r \n Not found \n " ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
static const char http_header_405 [ ] = " HTTP/1.1 405 Method Not Allowed \r \n Content-Length:0 \r \n Connection:close \r \n \r \n " ;
2020-09-15 14:06:38 +02:00
static const char http_header_500 [ ] = " HTTP/1.1 500 Internal Error \r \n Content-Length:6 \r \n Connection:close \r \n \r \n Error \n " ;
2015-09-02 14:41:27 +02:00
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
static const char http_header_content_len_fmt [ ] = " Content-length:%5d \r \n \r \n " ;
static const char http_html_gzip_contentencoding [ ] = " Content-Encoding: gzip \r \n " ;
2016-01-28 06:52:09 +01:00
2019-07-08 21:48:16 +02:00
/* Externally defined: static const char enduser_setup_html_default[] = ... */
# include "enduser_setup/enduser_setup.html.gz.def.h"
2016-03-24 09:25:49 +01:00
2020-09-15 14:06:38 +02:00
// The tcp_arg can be either a pointer to the scan_listener_t or http_request_buffer_t.
// The enum defines which one it is.
typedef enum {
SCAN_LISTENER_STRUCT_TYPE = 1 ,
HTTP_REQUEST_BUFFER_STRUCT_TYPE = 2
} struct_type_t ;
typedef struct {
struct_type_t struct_type ;
} tcp_arg_t ;
2016-01-28 06:52:09 +01:00
typedef struct scan_listener
{
2020-09-15 14:06:38 +02:00
struct_type_t struct_type ;
2016-03-24 09:25:49 +01:00
struct tcp_pcb * conn ;
2016-01-28 06:52:09 +01:00
struct scan_listener * next ;
} scan_listener_t ;
2015-09-19 21:06:56 +02:00
2020-09-15 14:06:38 +02:00
typedef struct {
struct_type_t struct_type ;
size_t length ;
char data [ 0 ] ;
} http_request_buffer_t ;
2015-09-19 21:06:56 +02:00
typedef struct
{
struct espconn * espconn_dns_udp ;
2016-03-24 09:25:49 +01:00
struct tcp_pcb * http_pcb ;
2015-09-19 21:06:56 +02:00
char * http_payload_data ;
uint32_t http_payload_len ;
2020-09-18 23:47:52 +02:00
char * ap_ssid ;
2015-09-19 21:06:56 +02:00
os_timer_t check_station_timer ;
2016-03-08 22:55:53 +01:00
os_timer_t shutdown_timer ;
2015-09-19 21:06:56 +02:00
int lua_connected_cb_ref ;
int lua_err_cb_ref ;
int lua_dbg_cb_ref ;
2016-01-28 06:52:09 +01:00
scan_listener_t * scan_listeners ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
uint8_t softAPchannel ;
uint8_t success ;
uint8_t callbackDone ;
uint8_t lastStationStatus ;
uint8_t connecting ;
2015-09-19 21:06:56 +02:00
} enduser_setup_state_t ;
static enduser_setup_state_t * state ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
2016-01-28 06:52:09 +01:00
static bool manual = false ;
2016-03-01 07:54:10 +01:00
static task_handle_t do_station_cfg_handle ;
2015-09-02 14:41:27 +02:00
2016-03-08 22:55:53 +01:00
static int enduser_setup_manual ( lua_State * L ) ;
2015-09-12 18:07:53 +02:00
static int enduser_setup_start ( lua_State * L ) ;
static int enduser_setup_stop ( lua_State * L ) ;
2016-03-08 22:55:53 +01:00
static void enduser_setup_stop_callback ( void * ptr ) ;
2015-09-19 21:06:56 +02:00
static void enduser_setup_station_start ( void ) ;
2015-09-12 18:07:53 +02:00
static void enduser_setup_ap_start ( void ) ;
static void enduser_setup_ap_stop ( void ) ;
2016-01-20 09:37:03 +01:00
static void enduser_setup_check_station ( void * p ) ;
2016-03-08 22:55:53 +01:00
static void enduser_setup_debug ( int line , const char * str ) ;
2015-09-19 21:06:56 +02:00
2017-03-18 09:45:26 +01:00
static char ipaddr [ 16 ] ;
2015-09-19 21:06:56 +02:00
# if ENDUSER_SETUP_DEBUG_ENABLE
2016-03-08 22:55:53 +01:00
# define ENDUSER_SETUP_DEBUG(str) enduser_setup_debug(__LINE__, str)
2015-09-19 21:06:56 +02:00
# else
2016-03-08 22:55:53 +01:00
# define ENDUSER_SETUP_DEBUG(str) do {} while(0)
2015-09-19 21:06:56 +02:00
# endif
2016-01-28 06:52:09 +01:00
# define ENDUSER_SETUP_ERROR(str, err, err_severity) \
do { \
2016-03-08 22:55:53 +01:00
ENDUSER_SETUP_DEBUG ( str ) ; \
2016-01-28 06:52:09 +01:00
if ( err_severity & ENDUSER_SETUP_ERR_FATAL ) enduser_setup_stop ( lua_getstate ( ) ) ; \
2016-03-08 22:55:53 +01:00
enduser_setup_error ( __LINE__ , str , err ) ; \
2016-01-28 06:52:09 +01:00
if ( ! ( err_severity & ENDUSER_SETUP_ERR_NO_RETURN ) ) \
return err ; \
} while ( 0 )
2015-09-19 21:06:56 +02:00
2016-03-08 22:55:53 +01:00
2016-01-28 06:52:09 +01:00
# define ENDUSER_SETUP_ERROR_VOID(str, err, err_severity) \
do { \
2016-03-08 22:55:53 +01:00
ENDUSER_SETUP_DEBUG ( str ) ; \
2016-01-28 06:52:09 +01:00
if ( err_severity & ENDUSER_SETUP_ERR_FATAL ) enduser_setup_stop ( lua_getstate ( ) ) ; \
2016-03-08 22:55:53 +01:00
enduser_setup_error ( __LINE__ , str , err ) ; \
2016-01-28 06:52:09 +01:00
if ( ! ( err_severity & ENDUSER_SETUP_ERR_NO_RETURN ) ) \
return ; \
} while ( 0 )
2015-09-19 21:06:56 +02:00
2016-03-08 22:55:53 +01:00
static void enduser_setup_debug ( int line , const char * str )
2015-09-19 21:06:56 +02:00
{
2016-03-08 22:55:53 +01:00
lua_State * L = lua_getstate ( ) ;
if ( state ! = NULL & & state - > lua_dbg_cb_ref ! = LUA_NOREF )
{
lua_rawgeti ( L , LUA_REGISTRYINDEX , state - > lua_dbg_cb_ref ) ;
lua_pushfstring ( L , " %d: \t %s " , line , str ) ;
2020-06-16 09:19:55 +02:00
luaL_pcallx ( L , 1 , 0 ) ;
2016-03-08 22:55:53 +01:00
}
}
static void enduser_setup_error ( int line , const char * str , int err )
{
ENDUSER_SETUP_DEBUG ( " enduser_setup_error " ) ;
2015-09-19 21:06:56 +02:00
2016-03-08 22:55:53 +01:00
lua_State * L = lua_getstate ( ) ;
if ( state ! = NULL & & state - > lua_err_cb_ref ! = LUA_NOREF )
2015-09-19 21:06:56 +02:00
{
lua_rawgeti ( L , LUA_REGISTRYINDEX , state - > lua_err_cb_ref ) ;
2020-08-29 18:48:24 +02:00
lua_pushinteger ( L , err ) ;
2016-03-08 22:55:53 +01:00
lua_pushfstring ( L , " %d: \t %s " , line , str ) ;
2020-06-16 09:19:55 +02:00
luaL_pcallx ( L , 2 , 0 ) ;
2015-09-19 21:06:56 +02:00
}
}
2016-03-08 22:55:53 +01:00
static void enduser_setup_connected_callback ( )
2015-09-19 21:06:56 +02:00
{
2016-03-08 22:55:53 +01:00
ENDUSER_SETUP_DEBUG ( " enduser_setup_connected_callback " ) ;
2015-09-19 21:06:56 +02:00
2016-03-08 22:55:53 +01:00
lua_State * L = lua_getstate ( ) ;
if ( state ! = NULL & & state - > lua_connected_cb_ref ! = LUA_NOREF )
2015-09-19 21:06:56 +02:00
{
lua_rawgeti ( L , LUA_REGISTRYINDEX , state - > lua_connected_cb_ref ) ;
2020-06-16 09:19:55 +02:00
luaL_pcallx ( L , 0 , 0 ) ;
2015-09-19 21:06:56 +02:00
}
}
2015-09-02 14:41:27 +02:00
2018-04-13 21:41:14 +02:00
# include "pm/swtimer.h"
2015-09-12 18:07:53 +02:00
static void enduser_setup_check_station_start ( void )
2015-09-02 14:41:27 +02:00
{
2016-03-08 22:55:53 +01:00
ENDUSER_SETUP_DEBUG ( " enduser_setup_check_station_start " ) ;
2015-09-19 21:06:56 +02:00
os_timer_setfn ( & ( state - > check_station_timer ) , enduser_setup_check_station , NULL ) ;
2018-04-13 21:41:14 +02:00
SWTIMER_REG_CB ( enduser_setup_check_station , SWTIMER_RESUME ) ;
//The function enduser_setup_check_station checks for a successful connection to the configured AP
//My guess: I'm not sure about whether or not user feedback is given via the web interface, but I don't see a problem with letting this timer resume.
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
os_timer_arm ( & ( state - > check_station_timer ) , 3 * 1000 , TRUE ) ;
2015-09-02 14:41:27 +02:00
}
2015-09-12 18:07:53 +02:00
static void enduser_setup_check_station_stop ( void )
2015-09-02 14:41:27 +02:00
{
2016-03-08 22:55:53 +01:00
ENDUSER_SETUP_DEBUG ( " enduser_setup_check_station_stop " ) ;
2015-09-02 14:41:27 +02:00
2016-03-01 08:33:11 +01:00
if ( state ! = NULL )
2016-03-08 22:55:53 +01:00
{
2016-03-01 08:33:11 +01:00
os_timer_disarm ( & ( state - > check_station_timer ) ) ;
2016-03-08 22:55:53 +01:00
}
2015-09-02 14:41:27 +02:00
}
/**
* Check Station
*
* Check that we ' ve successfully entered station mode .
*/
2016-01-20 09:37:03 +01:00
static void enduser_setup_check_station ( void * p )
2015-09-02 14:41:27 +02:00
{
2016-03-08 22:55:53 +01:00
ENDUSER_SETUP_DEBUG ( " enduser_setup_check_station " ) ;
2016-01-20 09:37:03 +01:00
( void ) p ;
2015-09-02 14:41:27 +02:00
struct ip_info ip ;
2019-07-21 23:58:21 +02:00
memset ( & ip , 0 , sizeof ( struct ip_info ) ) ;
2015-09-02 14:41:27 +02:00
wifi_get_ip_info ( STATION_IF , & ip ) ;
int i ;
char has_ip = 0 ;
for ( i = 0 ; i < sizeof ( struct ip_info ) ; + + i )
{
has_ip | = ( ( char * ) & ip ) [ i ] ;
}
2015-09-16 14:56:44 +02:00
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
uint8_t currChan = wifi_get_channel ( ) ;
2019-02-17 19:26:29 +01:00
2015-09-02 14:41:27 +02:00
if ( has_ip = = 0 )
{
2019-02-17 19:26:29 +01:00
/* No IP Address yet, so check the reported status */
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
uint8_t curr_status = wifi_station_get_connect_status ( ) ;
char buf [ 20 ] ;
2019-07-21 23:58:21 +02:00
sprintf ( buf , " status=%d,chan=%d " , curr_status , currChan ) ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
ENDUSER_SETUP_DEBUG ( buf ) ;
2015-09-16 14:56:44 +02:00
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
if ( curr_status = = 2 | | curr_status = = 3 | | curr_status = = 4 )
{
state - > connecting = 0 ;
2019-02-17 19:26:29 +01:00
/* If the status is an error status and the channel changed, then cache the
2016-12-01 22:12:47 +01:00
* status to state since the Station won ' t be able to report the same status
* after switching the channel back to the SoftAP ' s
*/
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
if ( currChan ! = state - > softAPchannel ) {
state - > lastStationStatus = curr_status ;
2019-02-17 19:26:29 +01:00
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
ENDUSER_SETUP_DEBUG ( " Turning off Station due to different channel than AP " ) ;
2019-02-17 19:26:29 +01:00
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
wifi_station_disconnect ( ) ;
wifi_set_opmode ( SOFTAP_MODE ) ;
enduser_setup_ap_start ( ) ;
}
}
return ;
}
2019-07-21 23:58:21 +02:00
sprintf ( ipaddr , " %d.%d.%d.%d " , IP2STR ( & ip . ip . addr ) ) ;
2017-03-18 09:45:26 +01:00
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
state - > success = 1 ;
2016-12-01 22:12:47 +01:00
state - > lastStationStatus = 5 ; /* We have an IP Address, so the status is 5 (as of SDK 1.5.1) */
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
state - > connecting = 0 ;
2019-02-17 19:26:29 +01:00
# if ENDUSER_SETUP_DEBUG_ENABLE
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
char debuginfo [ 100 ] ;
2019-07-21 23:58:21 +02:00
sprintf ( debuginfo , " AP_CHAN: %d, STA_CHAN: %d " , state - > softAPchannel , currChan ) ;
2019-02-17 19:26:29 +01:00
ENDUSER_SETUP_DEBUG ( debuginfo ) ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
# endif
if ( currChan = = state - > softAPchannel )
{
enduser_setup_connected_callback ( ) ;
state - > callbackDone = 1 ;
}
else
{
ENDUSER_SETUP_DEBUG ( " Turning off Station due to different channel than AP " ) ;
wifi_station_disconnect ( ) ;
wifi_set_opmode ( SOFTAP_MODE ) ;
enduser_setup_ap_start ( ) ;
}
2019-02-17 19:26:29 +01:00
2016-03-08 22:55:53 +01:00
enduser_setup_check_station_stop ( ) ;
/* Trigger shutdown, but allow time for HTTP client to fetch last status. */
if ( ! manual )
{
os_timer_setfn ( & ( state - > shutdown_timer ) , enduser_setup_stop_callback , NULL ) ;
2018-04-13 21:41:14 +02:00
SWTIMER_REG_CB ( enduser_setup_stop_callback , SWTIMER_RESUME ) ;
//The function enduser_setup_stop_callback frees services and resources used by enduser setup.
//My guess: Since it would lead to a memory leak, it's probably best to resume this timer.
2016-03-08 22:55:53 +01:00
os_timer_arm ( & ( state - > shutdown_timer ) , 10 * 1000 , FALSE ) ;
}
2015-09-02 14:41:27 +02:00
}
2016-03-29 08:27:55 +02:00
/* --- Connection closing handling ----------------------------------------- */
/* It is far more memory efficient to let the other end close the connection
* first and respond to that , than us initiating the closing . The latter
* seems to leave the pcb in a fin_wait state for a long time , which can
* starve us of memory over time .
*
* By instead using the poll function to schedule a hard abort a few seconds
* from now we achieve a deadline close . The downside is a ( very ) slight
* risk of dropping the connection early , but in this application that ' s
* hidden by the retries on the JavaScript side anyway .
*/
/* Callback on timeout to hard-close a connection */
static err_t force_abort ( void * arg , struct tcp_pcb * pcb )
{
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
ENDUSER_SETUP_DEBUG ( " force_abort " ) ;
2019-02-17 19:26:29 +01:00
2016-03-29 08:27:55 +02:00
( void ) arg ;
tcp_poll ( pcb , 0 , 0 ) ;
tcp_abort ( pcb ) ;
return ERR_ABRT ;
}
/* Callback to detect a remote-close of a connection */
static err_t handle_remote_close ( void * arg , struct tcp_pcb * pcb , struct pbuf * p , err_t err )
{
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
ENDUSER_SETUP_DEBUG ( " handle_remote_close " ) ;
2019-02-17 19:26:29 +01:00
2016-03-29 08:27:55 +02:00
( void ) arg ; ( void ) err ;
if ( p ) /* server sent us data, just ACK and move on */
{
tcp_recved ( pcb , p - > tot_len ) ;
pbuf_free ( p ) ;
}
else /* hey, remote end closed, we can do a soft close safely, yay! */
{
tcp_recv ( pcb , 0 ) ;
tcp_poll ( pcb , 0 , 0 ) ;
tcp_close ( pcb ) ;
}
return ERR_OK ;
}
/* Set up a deferred close of a connection, as discussed above. */
static inline void deferred_close ( struct tcp_pcb * pcb )
{
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
ENDUSER_SETUP_DEBUG ( " deferred_close " ) ;
2019-02-17 19:26:29 +01:00
2016-03-29 08:27:55 +02:00
tcp_poll ( pcb , force_abort , 15 ) ; /* ~3sec from now */
tcp_recv ( pcb , handle_remote_close ) ;
tcp_sent ( pcb , 0 ) ;
}
/* Convenience function to queue up a close-after-send. */
static err_t close_once_sent ( void * arg , struct tcp_pcb * pcb , u16_t len )
{
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
ENDUSER_SETUP_DEBUG ( " close_once_sent " ) ;
2016-03-29 08:27:55 +02:00
( void ) arg ; ( void ) len ;
deferred_close ( pcb ) ;
return ERR_OK ;
}
/* ------------------------------------------------------------------------- */
2015-09-02 14:41:27 +02:00
/**
2019-08-01 21:31:18 +02:00
* Get length of param value
2020-09-15 14:06:38 +02:00
*
* This is being called with a fragment of the parameters passed in the
2019-08-01 21:31:18 +02:00
* URL for GET requests or part of the body of a POST request .
* The string will look like one of these
* " SecretPassword HTTP/1.1 "
* " SecretPassword&wifi_ssid=... "
* " SecretPassword "
* The string is searched for the first occurence of deliemiter ' & ' or ' ' .
* If found return the length up to that position .
* If not found return the length of the string .
2015-09-02 14:41:27 +02:00
*
*/
2019-08-01 21:31:18 +02:00
static int enduser_setup_get_lenth_of_param_value ( const char * str )
2015-09-02 14:41:27 +02:00
{
2019-08-01 21:31:18 +02:00
char * found = strpbrk ( str , " & " ) ;
2016-01-28 06:52:09 +01:00
if ( ! found )
2016-03-08 22:55:53 +01:00
{
2019-08-01 21:31:18 +02:00
return strlen ( str ) ;
2016-03-08 22:55:53 +01:00
}
2016-01-28 06:52:09 +01:00
else
2016-03-08 22:55:53 +01:00
{
2016-01-28 06:52:09 +01:00
return found - str ;
2016-03-08 22:55:53 +01:00
}
2015-09-02 14:41:27 +02:00
}
/**
* Load HTTP Payload
*
2019-07-08 21:48:16 +02:00
* @ return - 0 if payload loaded successfully
* 1 if default html was loaded
* 2 if out of memory
2015-09-02 14:41:27 +02:00
*/
2015-09-12 18:07:53 +02:00
static int enduser_setup_http_load_payload ( void )
2015-09-02 14:41:27 +02:00
{
2016-03-08 22:55:53 +01:00
ENDUSER_SETUP_DEBUG ( " enduser_setup_http_load_payload " ) ;
2015-09-02 14:41:27 +02:00
2016-09-05 20:17:13 +02:00
int err = VFS_RES_ERR ;
int err2 = VFS_RES_ERR ;
2016-06-28 22:50:23 +02:00
int file_len = 0 ;
2016-12-01 22:12:47 +01:00
/* Try to open enduser_setup.html.gz from SPIFFS first */
int f = vfs_open ( http_html_gz_filename , " r " ) ;
2019-02-17 19:26:29 +01:00
if ( f )
2016-12-01 22:12:47 +01:00
{
2016-09-05 20:17:13 +02:00
err = vfs_lseek ( f , 0 , VFS_SEEK_END ) ;
file_len = ( int ) vfs_tell ( f ) ;
err2 = vfs_lseek ( f , 0 , VFS_SEEK_SET ) ;
2016-06-28 22:50:23 +02:00
}
2015-09-19 21:06:56 +02:00
2016-12-01 22:12:47 +01:00
if ( ! f | | err = = VFS_RES_ERR | | err2 = = VFS_RES_ERR )
{
2019-02-17 19:26:29 +01:00
if ( f )
2016-12-01 22:12:47 +01:00
{
vfs_close ( f ) ;
}
/* If that didn't work, try to open enduser_setup.html from SPIFFS */
f = vfs_open ( http_html_filename , " r " ) ;
2019-02-17 19:26:29 +01:00
if ( f )
2016-12-01 22:12:47 +01:00
{
err = vfs_lseek ( f , 0 , VFS_SEEK_END ) ;
file_len = ( int ) vfs_tell ( f ) ;
err2 = vfs_lseek ( f , 0 , VFS_SEEK_SET ) ;
}
}
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
char cl_hdr [ 30 ] ;
size_t ce_len = 0 ;
2019-02-17 19:26:29 +01:00
2019-07-21 23:58:21 +02:00
sprintf ( cl_hdr , http_header_content_len_fmt , file_len ) ;
size_t cl_len = strlen ( cl_hdr ) ;
2016-01-28 06:52:09 +01:00
2016-11-08 22:27:12 +01:00
if ( ! f | | err = = VFS_RES_ERR | | err2 = = VFS_RES_ERR )
2015-09-02 14:41:27 +02:00
{
2019-07-08 21:48:16 +02:00
ENDUSER_SETUP_DEBUG ( " Unable to load file enduser_setup.html, loading default HTML... " ) ;
2015-09-02 14:41:27 +02:00
2019-08-01 21:31:18 +02:00
if ( f )
{
vfs_close ( f ) ;
}
2019-07-21 23:58:21 +02:00
sprintf ( cl_hdr , http_header_content_len_fmt , sizeof ( enduser_setup_html_default ) ) ;
cl_len = strlen ( cl_hdr ) ;
2019-07-08 21:48:16 +02:00
int html_len = LITLEN ( enduser_setup_html_default ) ;
2016-12-01 22:12:47 +01:00
2019-07-08 21:48:16 +02:00
if ( enduser_setup_html_default [ 0 ] = = 0x1f & & enduser_setup_html_default [ 1 ] = = 0x8b )
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
{
2019-07-21 23:58:21 +02:00
ce_len = strlen ( http_html_gzip_contentencoding ) ;
2019-07-08 21:48:16 +02:00
html_len = enduser_setup_html_default_len ; /* Defined in enduser_setup/enduser_setup.html.gz.def.h by xxd -i */
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
ENDUSER_SETUP_DEBUG ( " Content is gzipped " ) ;
2019-02-17 19:26:29 +01:00
}
int payload_len = LITLEN ( http_header_200 ) + cl_len + ce_len + html_len ;
2015-09-19 21:06:56 +02:00
state - > http_payload_len = payload_len ;
2019-07-21 23:58:21 +02:00
state - > http_payload_data = ( char * ) malloc ( payload_len ) ;
2016-12-01 22:12:47 +01:00
2015-09-19 21:06:56 +02:00
if ( state - > http_payload_data = = NULL )
2015-09-02 14:41:27 +02:00
{
return 2 ;
}
2015-09-19 21:06:56 +02:00
2015-09-02 14:41:27 +02:00
int offset = 0 ;
2019-07-21 23:58:21 +02:00
memcpy ( & ( state - > http_payload_data [ offset ] ) , & ( http_header_200 ) , LITLEN ( http_header_200 ) ) ;
2016-01-28 06:52:09 +01:00
offset + = LITLEN ( http_header_200 ) ;
2016-12-01 22:12:47 +01:00
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
if ( ce_len > 0 )
2016-12-01 22:12:47 +01:00
{
2019-07-21 23:58:21 +02:00
offset + = sprintf ( state - > http_payload_data + offset , http_html_gzip_contentencoding , ce_len ) ;
2016-12-01 22:12:47 +01:00
}
2019-02-17 19:26:29 +01:00
2019-07-21 23:58:21 +02:00
memcpy ( & ( state - > http_payload_data [ offset ] ) , & ( cl_hdr ) , cl_len ) ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
offset + = cl_len ;
2019-07-21 23:58:21 +02:00
memcpy ( & ( state - > http_payload_data [ offset ] ) , & ( enduser_setup_html_default ) , sizeof ( enduser_setup_html_default ) ) ;
2019-02-17 19:26:29 +01:00
return 1 ;
2015-09-02 14:41:27 +02:00
}
2015-09-19 21:06:56 +02:00
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
char magic [ 2 ] ;
vfs_read ( f , magic , 2 ) ;
2019-02-17 19:26:29 +01:00
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
if ( magic [ 0 ] = = 0x1f & & magic [ 1 ] = = 0x8b )
{
2019-07-21 23:58:21 +02:00
ce_len = strlen ( http_html_gzip_contentencoding ) ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
ENDUSER_SETUP_DEBUG ( " Content is gzipped " ) ;
}
2019-02-17 19:26:29 +01:00
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
int payload_len = LITLEN ( http_header_200 ) + cl_len + ce_len + file_len ;
2015-09-19 21:06:56 +02:00
state - > http_payload_len = payload_len ;
2019-07-21 23:58:21 +02:00
state - > http_payload_data = ( char * ) malloc ( payload_len ) ;
2016-12-01 22:12:47 +01:00
2015-09-19 21:06:56 +02:00
if ( state - > http_payload_data = = NULL )
2015-09-02 14:41:27 +02:00
{
return 2 ;
}
2015-09-19 21:06:56 +02:00
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
vfs_lseek ( f , 0 , VFS_SEEK_SET ) ;
2019-02-17 19:26:29 +01:00
2015-09-02 14:41:27 +02:00
int offset = 0 ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
2019-07-21 23:58:21 +02:00
memcpy ( & ( state - > http_payload_data [ offset ] ) , & ( http_header_200 ) , LITLEN ( http_header_200 ) ) ;
2016-01-28 06:52:09 +01:00
offset + = LITLEN ( http_header_200 ) ;
2016-12-01 22:12:47 +01:00
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
if ( ce_len > 0 )
2016-12-01 22:12:47 +01:00
{
2019-07-21 23:58:21 +02:00
offset + = sprintf ( state - > http_payload_data + offset , http_html_gzip_contentencoding , ce_len ) ;
2016-12-01 22:12:47 +01:00
}
2019-02-17 19:26:29 +01:00
2019-07-21 23:58:21 +02:00
memcpy ( & ( state - > http_payload_data [ offset ] ) , & ( cl_hdr ) , cl_len ) ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
offset + = cl_len ;
2016-09-05 20:17:13 +02:00
vfs_read ( f , & ( state - > http_payload_data [ offset ] ) , file_len ) ;
2019-02-17 19:26:29 +01:00
vfs_close ( f ) ;
2015-09-02 14:41:27 +02:00
return 0 ;
}
/**
* De - escape URL data
*
* Parse escaped and form encoded data of request .
2016-03-08 22:55:53 +01:00
*
2019-07-08 21:48:16 +02:00
* @ return - return 0 if the HTTP parameter is decoded into a valid string .
2015-09-02 14:41:27 +02:00
*/
2016-03-08 22:55:53 +01:00
static int enduser_setup_http_urldecode ( char * dst , const char * src , int src_len , int dst_len )
2015-09-02 14:41:27 +02:00
{
2016-03-08 22:55:53 +01:00
ENDUSER_SETUP_DEBUG ( " enduser_setup_http_urldecode " ) ;
char * dst_start = dst ;
2016-03-31 08:46:03 +02:00
char * dst_last = dst + dst_len - 1 ; /* -1 to reserve space for last \0 */
2015-09-02 14:41:27 +02:00
char a , b ;
int i ;
2016-03-31 08:46:03 +02:00
for ( i = 0 ; i < src_len & & * src & & dst < dst_last ; + + i )
2015-09-02 14:41:27 +02:00
{
if ( ( * src = = ' % ' ) & & ( ( a = src [ 1 ] ) & & ( b = src [ 2 ] ) ) & & ( isxdigit ( a ) & & isxdigit ( b ) ) )
{
if ( a > = ' a ' )
{
a - = ' a ' - ' A ' ;
}
if ( a > = ' A ' )
{
a - = ( ' A ' - 10 ) ;
}
else
{
a - = ' 0 ' ;
}
if ( b > = ' a ' )
{
b - = ' a ' - ' A ' ;
}
if ( b > = ' A ' )
{
b - = ( ' A ' - 10 ) ;
}
else
{
b - = ' 0 ' ;
}
* dst + + = 16 * a + b ;
src + = 3 ;
i + = 2 ;
} else {
char c = * src + + ;
if ( c = = ' + ' )
{
c = ' ' ;
}
* dst + + = c ;
}
}
* dst + + = ' \0 ' ;
2016-03-31 08:46:03 +02:00
return ( i < src_len ) ; /* did we fail to process all the input? */
2015-09-02 14:41:27 +02:00
}
2016-03-01 07:54:10 +01:00
/**
* Task to do the actual station configuration .
* This config * cannot * be done in the network receive callback or serious
* issues like memory corruption occur .
*/
static void do_station_cfg ( task_param_t param , uint8_t prio )
{
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
ENDUSER_SETUP_DEBUG ( " do_station_cfg " ) ;
2019-02-17 19:26:29 +01:00
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
state - > connecting = 1 ;
2016-03-01 07:54:10 +01:00
struct station_config * cnf = ( struct station_config * ) param ;
( void ) prio ;
/* Best-effort disconnect-reconfig-reconnect. If the device is currently
* connected , the disconnect will work but the connect will report failure
* ( though it will actually start connecting ) . If the devices is not
* connected , the disconnect may fail but the connect will succeed . A
* solid head - in - the - sand approach seems to be the best tradeoff on
* functionality - vs - code - size .
* TODO : maybe use an error callback to at least report if the set config
* call fails .
*/
wifi_station_disconnect ( ) ;
wifi_station_set_config ( cnf ) ;
wifi_station_connect ( ) ;
2016-03-08 22:55:53 +01:00
luaM_free ( lua_getstate ( ) , cnf ) ;
2016-03-01 07:54:10 +01:00
}
2019-07-08 21:48:16 +02:00
/**
* Count the number of occurences of a character in a string
2020-04-27 02:13:38 +02:00
*
2019-07-08 21:48:16 +02:00
* return the number of times the character was encountered in the string
*/
static int count_char_occurence ( const char * input , const char char_to_count ) {
const char * current = input ;
int occur = 0 ;
while ( * current ! = 0 ) {
if ( * current = = char_to_count ) occur + + ;
current + + ;
}
return occur ;
}
/* structure used to store the key/value pairs that we find in a HTTP POST body */
struct keypairs_t {
char * * keypairs ;
int keypairs_nb ;
} ;
static void enduser_setup_free_keypairs ( struct keypairs_t * kp ) {
if ( kp = = NULL ) return ;
2020-04-27 02:13:38 +02:00
2019-07-08 21:48:16 +02:00
if ( kp - > keypairs ! = NULL ) {
for ( int i = 0 ; i < kp - > keypairs_nb * 2 ; i + + ) {
2019-07-21 23:58:21 +02:00
free ( kp - > keypairs [ i ] ) ;
2019-07-08 21:48:16 +02:00
}
}
2019-07-21 23:58:21 +02:00
free ( kp - > keypairs ) ;
free ( kp ) ;
2019-07-08 21:48:16 +02:00
}
static struct keypairs_t * enduser_setup_alloc_keypairs ( int kp_number ) {
2019-07-21 23:58:21 +02:00
struct keypairs_t * kp = malloc ( sizeof ( struct keypairs_t ) ) ;
2019-07-08 21:48:16 +02:00
os_memset ( kp , 0 , sizeof ( struct keypairs_t ) ) ;
2019-07-21 23:58:21 +02:00
kp - > keypairs = malloc ( kp_number * 2 * sizeof ( char * ) ) ;
2019-07-08 21:48:16 +02:00
kp - > keypairs_nb = kp_number ;
return kp ;
}
/**
* Parses a form - urlencoded body into a struct keypairs_t , which contains an array of key , values strings and the size of the array .
*/
static struct keypairs_t * enduser_setup_get_keypairs_from_form ( char * form_body , int form_length ) {
int keypair_nb = count_char_occurence ( form_body , ' & ' ) + 1 ;
int equal_nb = count_char_occurence ( form_body , ' = ' ) ;
2020-04-27 02:13:38 +02:00
2019-07-08 21:48:16 +02:00
if ( keypair_nb = = 1 & & equal_nb = = 0 ) {
ENDUSER_SETUP_DEBUG ( " No keypair in form body " ) ;
return NULL ;
}
struct keypairs_t * kp = enduser_setup_alloc_keypairs ( keypair_nb ) ;
int current_idx = 0 ;
int err ;
2019-07-21 23:58:21 +02:00
char * body_copy = malloc ( form_length + 1 ) ;
2019-07-08 21:48:16 +02:00
os_bzero ( body_copy , form_length + 1 ) ;
os_memcpy ( body_copy , form_body , form_length ) ;
char * tok = strtok ( body_copy , " = " ) ;
2020-04-27 02:13:38 +02:00
2019-07-08 21:48:16 +02:00
char last_tok = ' = ' ;
while ( tok ) {
size_t len = strlen ( tok ) ;
2019-07-21 23:58:21 +02:00
kp - > keypairs [ current_idx ] = malloc ( len + 1 ) ;
2019-07-08 21:48:16 +02:00
err = enduser_setup_http_urldecode ( kp - > keypairs [ current_idx ] , tok , len , len + 1 ) ;
if ( err ) {
ENDUSER_SETUP_DEBUG ( " Unable to decode parameter " ) ;
enduser_setup_free_keypairs ( kp ) ;
2019-07-21 23:58:21 +02:00
free ( body_copy ) ;
2019-07-08 21:48:16 +02:00
return NULL ;
}
current_idx + + ;
if ( current_idx > keypair_nb * 2 ) {
ENDUSER_SETUP_DEBUG ( " Too many keypairs! " ) ;
enduser_setup_free_keypairs ( kp ) ;
2019-07-21 23:58:21 +02:00
free ( body_copy ) ;
2019-07-08 21:48:16 +02:00
return NULL ;
}
if ( last_tok = = ' = ' ) {
tok = strtok ( NULL , " & " ) ; // now search for the '&'
last_tok = ' & ' ;
} else {
tok = strtok ( NULL , " = " ) ; // search for the next '='
last_tok = ' = ' ;
}
}
2019-07-21 23:58:21 +02:00
free ( body_copy ) ;
2019-07-08 21:48:16 +02:00
return kp ;
}
/**
* This function saves the form data received when the configuration is sent to the ESP into a eus_params . lua file
*/
static int enduser_setup_write_file_with_extra_configuration_data ( char * form_body , int form_length ) {
ENDUSER_SETUP_DEBUG ( " enduser: write data from posted form " ) ;
ENDUSER_SETUP_DEBUG ( form_body ) ;
// We will save the form data into a file in the LUA format: KEY="VALUE", so that configuration data is available for load in the lua code.
// As input, we have a string as such: "key1=value1&key2=value2&key3=value%203" (urlencoded), the number of '&' tells us how many keypairs there are (the count + 1)
2020-04-27 02:13:38 +02:00
2019-07-08 21:48:16 +02:00
struct keypairs_t * kp = enduser_setup_get_keypairs_from_form ( form_body , form_length ) ;
if ( kp = = NULL | | kp - > keypairs_nb = = 0 ) {
ENDUSER_SETUP_DEBUG ( " enduser: No extra configuration. " ) ;
if ( kp ! = NULL ) enduser_setup_free_keypairs ( kp ) ;
return 1 ;
}
// Now that we have the keys and the values, let's save them in a lua file
int p_file = vfs_open ( " eus_params.lua " , " w " ) ;
if ( p_file = = 0 )
{
ENDUSER_SETUP_DEBUG ( " Can't open file in write mode! " ) ;
enduser_setup_free_keypairs ( kp ) ;
return 1 ;
}
// write all key pairs as KEY="VALUE"\n into a Lua table, example:
// local p = {}
// p.wifi_ssid="ssid"
// p.wifi_password="password"
// p.device_name="foo-node"
// return p
vfs_write ( p_file , " local p={} \n " , 11 ) ;
int idx = 0 ;
for ( idx = 0 ; idx < kp - > keypairs_nb * 2 ; idx = idx + 2 ) {
char * to_write = kp - > keypairs [ idx ] ;
2019-07-21 23:58:21 +02:00
size_t length = strlen ( to_write ) ;
2020-04-27 02:13:38 +02:00
2019-07-08 21:48:16 +02:00
vfs_write ( p_file , " p. " , 2 ) ;
vfs_write ( p_file , to_write , length ) ;
vfs_write ( p_file , " = \" " , 2 ) ;
2020-04-27 02:13:38 +02:00
2019-07-08 21:48:16 +02:00
to_write = kp - > keypairs [ idx + 1 ] ;
2019-07-21 23:58:21 +02:00
length = strlen ( to_write ) ;
2019-07-08 21:48:16 +02:00
vfs_write ( p_file , to_write , length ) ;
vfs_write ( p_file , " \" \n " , 2 ) ;
}
vfs_write ( p_file , " return p \n " , 9 ) ;
vfs_close ( p_file ) ;
enduser_setup_free_keypairs ( kp ) ;
// TODO: we could call back in the LUA with an associative table setup, but this is MVP2...
return 0 ;
}
2016-03-01 07:54:10 +01:00
2015-09-02 14:41:27 +02:00
/**
* Handle HTTP Credentials
*
2019-07-08 21:48:16 +02:00
* @ return - return 0 if credentials are found and handled successfully
* return 1 if credentials aren ' t found
* return 2 if an error occured
2015-09-02 14:41:27 +02:00
*/
2015-09-12 18:07:53 +02:00
static int enduser_setup_http_handle_credentials ( char * data , unsigned short data_len )
2015-09-02 14:41:27 +02:00
{
2016-03-08 22:55:53 +01:00
ENDUSER_SETUP_DEBUG ( " enduser_setup_http_handle_credentials " ) ;
2015-09-02 14:41:27 +02:00
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
state - > success = 0 ;
state - > lastStationStatus = 0 ;
2019-02-17 19:26:29 +01:00
2019-08-01 21:31:18 +02:00
char * name_str = strstr ( data , " wifi_ssid= " ) ;
char * pwd_str = strstr ( data , " wifi_password= " ) ;
2015-09-02 14:41:27 +02:00
if ( name_str = = NULL | | pwd_str = = NULL )
{
2016-03-08 22:55:53 +01:00
ENDUSER_SETUP_DEBUG ( " Password or SSID string not found " ) ;
2015-09-02 14:41:27 +02:00
return 1 ;
}
2016-01-28 06:52:09 +01:00
int name_field_len = LITLEN ( " wifi_ssid= " ) ;
int pwd_field_len = LITLEN ( " wifi_password= " ) ;
2015-09-02 14:41:27 +02:00
char * name_str_start = name_str + name_field_len ;
char * pwd_str_start = pwd_str + pwd_field_len ;
2019-08-01 21:31:18 +02:00
int name_str_len = enduser_setup_get_lenth_of_param_value ( name_str_start ) ;
int pwd_str_len = enduser_setup_get_lenth_of_param_value ( pwd_str_start ) ;
2015-09-19 21:06:56 +02:00
2015-09-02 14:41:27 +02:00
2016-03-08 22:55:53 +01:00
struct station_config * cnf = luaM_malloc ( lua_getstate ( ) , sizeof ( struct station_config ) ) ;
2019-07-21 23:58:21 +02:00
memset ( cnf , 0 , sizeof ( struct station_config ) ) ;
2018-03-23 07:27:31 +01:00
cnf - > threshold . rssi = - 127 ;
cnf - > threshold . authmode = AUTH_OPEN ;
2015-09-02 14:41:27 +02:00
2016-03-08 22:55:53 +01:00
int err ;
2016-03-31 08:46:03 +02:00
err = enduser_setup_http_urldecode ( cnf - > ssid , name_str_start , name_str_len , sizeof ( cnf - > ssid ) ) ;
err | = enduser_setup_http_urldecode ( cnf - > password , pwd_str_start , pwd_str_len , sizeof ( cnf - > password ) ) ;
2019-07-21 23:58:21 +02:00
if ( err ! = 0 | | strlen ( cnf - > ssid ) = = 0 )
2016-03-08 22:55:53 +01:00
{
ENDUSER_SETUP_DEBUG ( " Unable to decode HTTP parameter to valid password or SSID " ) ;
return 1 ;
}
ENDUSER_SETUP_DEBUG ( " " ) ;
ENDUSER_SETUP_DEBUG ( " WiFi Credentials Stored " ) ;
ENDUSER_SETUP_DEBUG ( " ----------------------- " ) ;
ENDUSER_SETUP_DEBUG ( " name: " ) ;
ENDUSER_SETUP_DEBUG ( cnf - > ssid ) ;
ENDUSER_SETUP_DEBUG ( " pass: " ) ;
ENDUSER_SETUP_DEBUG ( cnf - > password ) ;
ENDUSER_SETUP_DEBUG ( " ----------------------- " ) ;
ENDUSER_SETUP_DEBUG ( " " ) ;
task_post_medium ( do_station_cfg_handle , ( task_param_t ) cnf ) ;
2015-09-02 14:41:27 +02:00
return 0 ;
}
/**
* Serve HTML
2015-09-19 21:06:56 +02:00
*
2019-07-08 21:48:16 +02:00
* @ return - return 0 if html was served successfully
2015-09-02 14:41:27 +02:00
*/
2016-03-24 09:25:49 +01:00
static int enduser_setup_http_serve_header ( struct tcp_pcb * http_client , const char * header , uint32_t header_len )
2015-09-02 14:41:27 +02:00
{
2016-03-08 22:55:53 +01:00
ENDUSER_SETUP_DEBUG ( " enduser_setup_http_serve_header " ) ;
2019-02-17 19:26:29 +01:00
2016-03-24 09:25:49 +01:00
err_t err = tcp_write ( http_client , header , header_len , TCP_WRITE_FLAG_COPY ) ;
if ( err ! = ERR_OK )
2015-09-02 14:41:27 +02:00
{
2016-03-29 08:27:55 +02:00
deferred_close ( http_client ) ;
2016-03-24 09:25:49 +01:00
ENDUSER_SETUP_ERROR ( " http_serve_header failed on tcp_write " , ENDUSER_SETUP_ERR_UNKOWN_ERROR , ENDUSER_SETUP_ERR_NONFATAL ) ;
2015-09-02 14:41:27 +02:00
}
2016-03-24 09:25:49 +01:00
return 0 ;
}
static err_t streamout_sent ( void * arg , struct tcp_pcb * pcb , u16_t len )
{
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
ENDUSER_SETUP_DEBUG ( " streamout_sent " ) ;
2016-03-24 09:25:49 +01:00
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
( void ) len ;
2016-03-24 09:25:49 +01:00
unsigned offs = ( unsigned ) arg ;
if ( ! state | | ! state - > http_payload_data )
2015-09-02 14:41:27 +02:00
{
2016-03-24 09:25:49 +01:00
tcp_abort ( pcb ) ;
return ERR_ABRT ;
2015-09-02 14:41:27 +02:00
}
2016-03-24 09:25:49 +01:00
unsigned wanted_len = state - > http_payload_len - offs ;
unsigned buf_free = tcp_sndbuf ( pcb ) ;
if ( buf_free < wanted_len )
wanted_len = buf_free ;
/* no-copy write */
err_t err = tcp_write ( pcb , state - > http_payload_data + offs , wanted_len , 0 ) ;
if ( err ! = ERR_OK )
2015-09-02 14:41:27 +02:00
{
2016-03-24 09:25:49 +01:00
ENDUSER_SETUP_DEBUG ( " streaming out html failed " ) ;
tcp_abort ( pcb ) ;
return ERR_ABRT ;
2015-09-02 14:41:27 +02:00
}
2015-09-19 21:06:56 +02:00
2016-03-24 09:25:49 +01:00
offs + = wanted_len ;
if ( offs > = state - > http_payload_len )
{
tcp_sent ( pcb , 0 ) ;
2016-03-29 08:27:55 +02:00
deferred_close ( pcb ) ;
2020-09-18 23:47:52 +02:00
free ( state - > http_payload_data ) ;
state - > http_payload_data = NULL ;
2016-03-24 09:25:49 +01:00
}
else
tcp_arg ( pcb , ( void * ) offs ) ;
return ERR_OK ;
2015-09-02 14:41:27 +02:00
}
/**
* Serve HTML
2015-09-16 14:56:44 +02:00
*
2019-07-08 21:48:16 +02:00
* @ return - return 0 if html was served successfully
2015-09-02 14:41:27 +02:00
*/
2016-03-24 09:25:49 +01:00
static int enduser_setup_http_serve_html ( struct tcp_pcb * http_client )
2015-09-02 14:41:27 +02:00
{
2016-03-08 22:55:53 +01:00
ENDUSER_SETUP_DEBUG ( " enduser_setup_http_serve_html " ) ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
2015-09-19 21:06:56 +02:00
if ( state - > http_payload_data = = NULL )
2015-09-02 14:41:27 +02:00
{
enduser_setup_http_load_payload ( ) ;
}
2015-09-16 14:56:44 +02:00
2016-03-24 09:25:49 +01:00
unsigned chunklen = tcp_sndbuf ( http_client ) ;
tcp_arg ( http_client , ( void * ) chunklen ) ;
tcp_recv ( http_client , 0 ) ; /* avoid confusion about the tcp_arg */
tcp_sent ( http_client , streamout_sent ) ;
/* Begin the no-copy stream-out here */
err_t err = tcp_write ( http_client , state - > http_payload_data , chunklen , 0 ) ;
if ( err ! = 0 )
2015-09-02 14:41:27 +02:00
{
2016-03-24 09:25:49 +01:00
ENDUSER_SETUP_ERROR ( " http_serve_html failed. tcp_write failed " , ENDUSER_SETUP_ERR_UNKOWN_ERROR , ENDUSER_SETUP_ERR_NONFATAL ) ;
2015-09-02 14:41:27 +02:00
}
2015-09-16 14:56:44 +02:00
2015-09-02 14:41:27 +02:00
return 0 ;
}
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
static void enduser_setup_serve_status ( struct tcp_pcb * conn )
2016-01-28 06:52:09 +01:00
{
2016-03-08 22:55:53 +01:00
ENDUSER_SETUP_DEBUG ( " enduser_setup_serve_status " ) ;
2016-01-28 06:52:09 +01:00
const char fmt [ ] =
" HTTP/1.1 200 OK \r \n "
2016-03-29 08:27:55 +02:00
" Cache-control:no-cache \r \n "
" Connection:close \r \n "
2019-02-17 19:26:29 +01:00
" Access-Control-Allow-Origin: * \r \n "
2016-03-29 08:27:55 +02:00
" Content-type:text/plain \r \n "
2016-01-28 06:52:09 +01:00
" Content-length: %d \r \n "
" \r \n "
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
" %s " ;
const char * states [ ] =
2016-01-28 06:52:09 +01:00
{
2016-03-08 22:55:53 +01:00
" Idle. " ,
" Connecting to \" %s \" . " ,
" Failed to connect to \" %s \" - Wrong password. " ,
" Failed to connect to \" %s \" - Network not found. " ,
" Failed to connect. " ,
2016-06-04 00:21:18 +02:00
" Connected to \" %s \" (%s). "
2016-01-28 06:52:09 +01:00
} ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
const size_t num_states = sizeof ( states ) / sizeof ( states [ 0 ] ) ;
2019-02-17 19:26:29 +01:00
uint8_t curr_state = state - > lastStationStatus > 0 ? state - > lastStationStatus : wifi_station_get_connect_status ( ) ;
2016-03-08 22:55:53 +01:00
if ( curr_state < num_states )
2016-01-28 06:52:09 +01:00
{
2016-03-08 22:55:53 +01:00
switch ( curr_state )
{
case STATION_CONNECTING :
case STATION_WRONG_PASSWORD :
case STATION_NO_AP_FOUND :
case STATION_GOT_IP :
{
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
const char * s = states [ curr_state ] ;
2016-03-08 22:55:53 +01:00
struct station_config config ;
wifi_station_get_config ( & config ) ;
config . ssid [ 31 ] = ' \0 ' ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
struct ip_info ip_info ;
2016-06-04 00:21:18 +02:00
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
wifi_get_ip_info ( STATION_IF , & ip_info ) ;
2016-06-04 00:21:18 +02:00
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
char ip_addr [ 16 ] ;
ip_addr [ 0 ] = ' \0 ' ;
if ( curr_state = = STATION_GOT_IP )
{
2019-07-21 23:58:21 +02:00
sprintf ( ip_addr , " %d.%d.%d.%d " , IP2STR ( & ip_info . ip . addr ) ) ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
}
2016-06-04 00:21:18 +02:00
2019-07-21 23:58:21 +02:00
int state_len = strlen ( s ) ;
int ip_len = strlen ( ip_addr ) ;
int ssid_len = strlen ( config . ssid ) ;
2016-06-04 00:21:18 +02:00
int status_len = state_len + ssid_len + ip_len + 1 ;
2016-03-08 22:55:53 +01:00
char status_buf [ status_len ] ;
memset ( status_buf , 0 , status_len ) ;
2019-07-21 23:58:21 +02:00
status_len = sprintf ( status_buf , s , config . ssid , ip_addr ) ;
2016-03-08 22:55:53 +01:00
2016-12-01 22:12:47 +01:00
int buf_len = sizeof ( fmt ) + status_len + 10 ; /* 10 = (9+1), 1 byte is '\0' and 9 are reserved for length field */
2016-03-08 22:55:53 +01:00
char buf [ buf_len ] ;
memset ( buf , 0 , buf_len ) ;
2019-07-21 23:58:21 +02:00
int output_len = sprintf ( buf , fmt , status_len , status_buf ) ;
2016-03-08 22:55:53 +01:00
enduser_setup_http_serve_header ( conn , buf , output_len ) ;
}
break ;
/* Handle non-formatted strings */
default :
{
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
const char * s = states [ curr_state ] ;
2019-07-21 23:58:21 +02:00
int status_len = strlen ( s ) ;
2016-12-01 22:12:47 +01:00
int buf_len = sizeof ( fmt ) + status_len + 10 ; /* 10 = (9+1), 1 byte is '\0' and 9 are reserved for length field */
2016-03-08 22:55:53 +01:00
char buf [ buf_len ] ;
memset ( buf , 0 , buf_len ) ;
2019-07-21 23:58:21 +02:00
int output_len = sprintf ( buf , fmt , status_len , s ) ;
2016-03-08 22:55:53 +01:00
enduser_setup_http_serve_header ( conn , buf , output_len ) ;
}
break ;
}
2016-03-01 07:55:45 +01:00
}
2016-03-08 22:55:53 +01:00
else
2016-03-01 07:55:45 +01:00
{
2016-03-08 22:55:53 +01:00
enduser_setup_http_serve_header ( conn , http_header_500 , LITLEN ( http_header_500 ) ) ;
2016-01-28 06:52:09 +01:00
}
}
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
static void enduser_setup_serve_status_as_json ( struct tcp_pcb * http_client )
{
ENDUSER_SETUP_DEBUG ( " enduser_setup_serve_status_as_json " ) ;
2019-02-17 19:26:29 +01:00
2016-12-01 22:12:47 +01:00
/* If the station is currently shut down because of wi-fi channel issue, use the cached status */
2019-02-17 19:26:29 +01:00
uint8_t curr_status = state - > lastStationStatus > 0 ? state - > lastStationStatus : wifi_station_get_connect_status ( ) ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
char json_payload [ 64 ] ;
2017-03-18 09:45:26 +01:00
struct ip_info ip_info ;
if ( curr_status = = 5 )
{
wifi_get_ip_info ( STATION_IF , & ip_info ) ;
/* If IP address not yet available, get now */
if ( strlen ( ipaddr ) = = 0 )
{
2019-07-21 23:58:21 +02:00
sprintf ( ipaddr , " %d.%d.%d.%d " , IP2STR ( & ip_info . ip . addr ) ) ;
2017-03-18 09:45:26 +01:00
}
2019-07-21 23:58:21 +02:00
sprintf ( json_payload , " { \" deviceid \" : \" %s \" , \" status \" :%d} " , ipaddr , curr_status ) ;
2017-03-18 09:45:26 +01:00
}
else
{
2019-07-21 23:58:21 +02:00
sprintf ( json_payload , " { \" deviceid \" : \" %06X \" , \" status \" :%d} " , system_get_chip_id ( ) , curr_status ) ;
2017-03-18 09:45:26 +01:00
}
2019-02-17 19:26:29 +01:00
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
const char fmt [ ] =
" HTTP/1.1 200 OK \r \n "
" Cache-Control: no-cache \r \n "
" Connection: close \r \n "
" Access-Control-Allow-Origin: * \r \n "
" Content-Type: application/json \r \n "
" Content-Length: %d \r \n "
" \r \n "
" %s " ;
2019-07-21 23:58:21 +02:00
int len = strlen ( json_payload ) ;
char buf [ strlen ( fmt ) + NUMLEN ( len ) + len - 4 ] ;
len = sprintf ( buf , fmt , len , json_payload ) ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
enduser_setup_http_serve_header ( http_client , buf , len ) ;
}
static void enduser_setup_handle_OPTIONS ( struct tcp_pcb * http_client , char * data , unsigned short data_len )
{
ENDUSER_SETUP_DEBUG ( " enduser_setup_handle_OPTIONS " ) ;
2019-02-17 19:26:29 +01:00
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
const char json [ ] =
" HTTP/1.1 200 OK \r \n "
" Cache-Control: no-cache \r \n "
" Connection: close \r \n "
" Content-Type: application/json \r \n "
" Content-Length: 0 \r \n "
" Access-Control-Allow-Origin: * \r \n "
" Access-Control-Allow-Methods: GET \r \n "
" Access-Control-Allow-Age: 300 \r \n "
" \r \n " ;
const char others [ ] =
" HTTP/1.1 200 OK \r \n "
" Cache-Control: no-cache \r \n "
" Connection: close \r \n "
2019-02-17 19:26:29 +01:00
" Content-Length: 0 \r \n "
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
" \r \n " ;
2019-02-17 19:26:29 +01:00
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
int type = 0 ;
2019-02-17 19:26:29 +01:00
2020-09-18 23:47:52 +02:00
if ( strncmp ( data , " OPTIONS " , 8 ) = = 0 )
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
{
2020-09-18 23:47:52 +02:00
if ( strncmp ( data + 8 , " /aplist " , 7 ) = = 0 | | strncmp ( data + 8 , " /setwifi? " , 9 ) = = 0 | | strncmp ( data + 8 , " /status.json " , 12 ) = = 0 )
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
{
2019-07-21 23:58:21 +02:00
enduser_setup_http_serve_header ( http_client , json , strlen ( json ) ) ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
return ;
}
}
2019-07-21 23:58:21 +02:00
enduser_setup_http_serve_header ( http_client , others , strlen ( others ) ) ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
return ;
}
2016-01-28 06:52:09 +01:00
2015-09-02 14:41:27 +02:00
2019-08-01 21:31:18 +02:00
static void enduser_setup_handle_POST ( struct tcp_pcb * http_client , char * data , size_t data_len )
2019-07-08 21:48:16 +02:00
{
ENDUSER_SETUP_DEBUG ( " Handling POST " ) ;
2019-07-21 23:58:21 +02:00
if ( strncmp ( data + 5 , " /setwifi " , 9 ) = = 0 ) // User clicked the submit button
2019-07-08 21:48:16 +02:00
{
2019-08-01 21:31:18 +02:00
char * body = strstr ( data , " \r \n \r \n " ) ;
2020-09-15 14:06:38 +02:00
if ( body = = NULL )
2019-08-01 21:31:18 +02:00
{
enduser_setup_http_serve_header ( http_client , http_header_400 , LITLEN ( http_header_400 ) ) ;
return ;
}
body + = 4 ; // length of the double CRLF found above
2020-09-15 14:06:38 +02:00
int bodylength = ( data + data_len ) - body ;
2019-08-01 21:31:18 +02:00
switch ( enduser_setup_http_handle_credentials ( body , bodylength ) )
2019-07-08 21:48:16 +02:00
{
case 0 : {
// all went fine, extract all the form data into a file
2020-09-18 23:47:52 +02:00
enduser_setup_write_file_with_extra_configuration_data ( body , bodylength ) ;
2019-07-08 21:48:16 +02:00
// redirect user to the base page with the trying flag
enduser_setup_http_serve_header ( http_client , http_header_302_trying , LITLEN ( http_header_302_trying ) ) ;
break ;
}
case 1 :
enduser_setup_http_serve_header ( http_client , http_header_400 , LITLEN ( http_header_400 ) ) ;
break ;
default :
2019-08-01 21:31:18 +02:00
ENDUSER_SETUP_ERROR_VOID ( " http_recvcb failed. Failed to handle wifi credentials. " , ENDUSER_SETUP_ERR_UNKOWN_ERROR , ENDUSER_SETUP_ERR_NONFATAL ) ;
2019-07-08 21:48:16 +02:00
break ;
}
2020-09-15 14:06:38 +02:00
} else {
enduser_setup_http_serve_header ( http_client , http_header_404 , LITLEN ( http_header_404 ) ) ;
2019-08-01 21:31:18 +02:00
}
2019-07-08 21:48:16 +02:00
}
2016-01-28 06:52:09 +01:00
/* --- WiFi AP scanning support -------------------------------------------- */
static void free_scan_listeners ( void )
2015-09-02 14:41:27 +02:00
{
2019-02-17 19:26:29 +01:00
ENDUSER_SETUP_DEBUG ( " free_scan_listeners " ) ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
2016-01-28 06:52:09 +01:00
if ( ! state | | ! state - > scan_listeners )
2016-03-08 22:55:53 +01:00
{
2016-01-28 06:52:09 +01:00
return ;
2016-03-08 22:55:53 +01:00
}
2015-09-02 14:41:27 +02:00
2016-01-28 06:52:09 +01:00
scan_listener_t * l = state - > scan_listeners , * next = 0 ;
while ( l )
2015-09-02 14:41:27 +02:00
{
2016-01-28 06:52:09 +01:00
next = l - > next ;
2019-07-21 23:58:21 +02:00
free ( l ) ;
2016-01-28 06:52:09 +01:00
l = next ;
}
state - > scan_listeners = 0 ;
}
2016-03-24 09:25:49 +01:00
static void remove_scan_listener ( scan_listener_t * l )
2016-01-28 06:52:09 +01:00
{
2019-02-17 19:26:29 +01:00
ENDUSER_SETUP_DEBUG ( " remove_scan_listener " ) ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
2016-03-24 09:25:49 +01:00
if ( state )
2016-01-28 06:52:09 +01:00
{
scan_listener_t * * sl = & state - > scan_listeners ;
while ( * sl )
2015-10-01 20:22:45 +02:00
{
2016-01-28 06:52:09 +01:00
/* Remove any and all references to the closed conn from the scan list */
2016-03-24 09:25:49 +01:00
if ( * sl = = l )
2016-01-28 06:52:09 +01:00
{
* sl = l - > next ;
2019-07-21 23:58:21 +02:00
free ( l ) ;
2016-01-28 06:52:09 +01:00
/* No early exit to guard against multi-entry on list */
}
else
sl = & ( * sl ) - > next ;
2015-10-01 20:22:45 +02:00
}
2016-01-28 06:52:09 +01:00
}
}
2016-03-08 22:55:53 +01:00
2016-01-28 06:52:09 +01:00
static char * escape_ssid ( char * dst , const char * src )
{
for ( int i = 0 ; i < 32 & & src [ i ] ; + + i )
{
if ( src [ i ] = = ' \\ ' | | src [ i ] = = ' " ' )
2016-03-08 22:55:53 +01:00
{
2016-01-28 06:52:09 +01:00
* dst + + = ' \\ ' ;
2016-03-08 22:55:53 +01:00
}
2016-01-28 06:52:09 +01:00
* dst + + = src [ i ] ;
}
return dst ;
}
static void notify_scan_listeners ( const char * payload , size_t sz )
{
2019-02-17 19:26:29 +01:00
ENDUSER_SETUP_DEBUG ( " notify_scan_listeners " ) ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
2016-01-28 06:52:09 +01:00
if ( ! state )
2016-03-08 22:55:53 +01:00
{
2016-01-28 06:52:09 +01:00
return ;
2016-03-08 22:55:53 +01:00
}
2016-01-28 06:52:09 +01:00
for ( scan_listener_t * l = state - > scan_listeners ; l ; l = l - > next )
{
2016-03-24 09:25:49 +01:00
if ( tcp_write ( l - > conn , payload , sz , TCP_WRITE_FLAG_COPY ) ! = ERR_OK )
2016-03-08 22:55:53 +01:00
{
ENDUSER_SETUP_DEBUG ( " failed to send wifi list " ) ;
2016-03-29 08:27:55 +02:00
tcp_abort ( l - > conn ) ;
2016-03-08 22:55:53 +01:00
}
2016-03-29 08:27:55 +02:00
else
tcp_sent ( l - > conn , close_once_sent ) ; /* TODO: time-out sends? */
2016-03-24 09:25:49 +01:00
l - > conn = 0 ;
2016-01-28 06:52:09 +01:00
}
free_scan_listeners ( ) ;
}
2015-09-16 14:56:44 +02:00
2016-01-28 06:52:09 +01:00
static void on_scan_done ( void * arg , STATUS status )
{
2019-02-17 19:26:29 +01:00
ENDUSER_SETUP_DEBUG ( " on_scan_done " ) ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
2016-01-28 06:52:09 +01:00
if ( ! state | | ! state - > scan_listeners )
2016-03-08 22:55:53 +01:00
{
2016-01-28 06:52:09 +01:00
return ;
2016-03-08 22:55:53 +01:00
}
2016-01-28 06:52:09 +01:00
if ( status = = OK )
{
unsigned num_nets = 0 ;
for ( struct bss_info * wn = arg ; wn ; wn = wn - > next . stqe_next )
2016-03-08 22:55:53 +01:00
{
2016-01-28 06:52:09 +01:00
+ + num_nets ;
2016-03-08 22:55:53 +01:00
}
2016-01-28 06:52:09 +01:00
const char header_fmt [ ] =
" HTTP/1.1 200 OK \r \n "
" Connection:close \r \n "
2016-03-29 08:27:55 +02:00
" Cache-control:no-cache \r \n "
2019-02-17 19:26:29 +01:00
" Access-Control-Allow-Origin: * \r \n "
2016-01-28 06:52:09 +01:00
" Content-type:application/json \r \n "
" Content-length:%4d \r \n "
" \r \n " ;
const size_t hdr_sz = sizeof ( header_fmt ) + 1 - 1 ; /* +expand %4d, -\0 */
/* To be able to safely escape a pathological SSID, we need 2*32 bytes */
2020-09-18 23:47:52 +02:00
const size_t max_entry_sz = 35 + 2 * 32 + 9 ; /* {"ssid":"","rssi":,"chan":,"auth":} */
2016-01-28 06:52:09 +01:00
const size_t alloc_sz = hdr_sz + num_nets * max_entry_sz + 3 ;
2019-07-21 23:58:21 +02:00
char * http = calloc ( 1 , alloc_sz ) ;
2016-01-28 06:52:09 +01:00
if ( ! http )
2016-03-08 22:55:53 +01:00
{
2016-01-28 06:52:09 +01:00
goto serve_500 ;
2016-03-08 22:55:53 +01:00
}
2016-01-28 06:52:09 +01:00
char * p = http + hdr_sz ; /* start body where we know it will be */
/* p[0] will be clobbered when we print the header, so fill it in last */
+ + p ;
for ( struct bss_info * wn = arg ; wn ; wn = wn - > next . stqe_next )
2015-10-01 20:22:45 +02:00
{
2016-01-28 06:52:09 +01:00
if ( wn ! = arg )
2016-03-08 22:55:53 +01:00
{
2016-01-28 06:52:09 +01:00
* p + + = ' , ' ;
2016-03-08 22:55:53 +01:00
}
2016-01-28 06:52:09 +01:00
const char entry_start [ ] = " { \" ssid \" : \" " ;
strcpy ( p , entry_start ) ;
p + = sizeof ( entry_start ) - 1 ;
p = escape_ssid ( p , wn - > ssid ) ;
const char entry_mid [ ] = " \" , \" rssi \" : " ;
strcpy ( p , entry_mid ) ;
p + = sizeof ( entry_mid ) - 1 ;
2019-07-21 23:58:21 +02:00
p + = sprintf ( p , " %d " , wn - > rssi ) ;
2019-02-17 19:26:29 +01:00
const char entry_chan [ ] = " , \" chan \" : " ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
strcpy ( p , entry_chan ) ;
p + = sizeof ( entry_chan ) - 1 ;
2019-07-21 23:58:21 +02:00
p + = sprintf ( p , " %d " , wn - > channel ) ;
2016-01-28 06:52:09 +01:00
2020-09-18 23:47:52 +02:00
const char entry_auth [ ] = " , \" auth \" : " ;
strcpy ( p , entry_auth ) ;
p + = sizeof ( entry_auth ) - 1 ;
p + = sprintf ( p , " %d " , wn - > authmode ) ;
2016-01-28 06:52:09 +01:00
* p + + = ' } ' ;
2015-10-01 20:22:45 +02:00
}
2016-01-28 06:52:09 +01:00
* p + + = ' ] ' ;
size_t body_sz = ( p - http ) - hdr_sz ;
2019-07-21 23:58:21 +02:00
sprintf ( http , header_fmt , body_sz ) ;
2016-01-28 06:52:09 +01:00
http [ hdr_sz ] = ' [ ' ; /* Rewrite the \0 with the correct start of body */
notify_scan_listeners ( http , hdr_sz + body_sz ) ;
2019-02-17 19:26:29 +01:00
ENDUSER_SETUP_DEBUG ( http + hdr_sz ) ;
2019-07-21 23:58:21 +02:00
free ( http ) ;
2016-01-28 06:52:09 +01:00
return ;
}
serve_500 :
notify_scan_listeners ( http_header_500 , LITLEN ( http_header_500 ) ) ;
}
/* ---- end WiFi AP scan support ------------------------------------------- */
2016-03-24 09:25:49 +01:00
static err_t enduser_setup_http_recvcb ( void * arg , struct tcp_pcb * http_client , struct pbuf * p , err_t err )
2016-01-28 06:52:09 +01:00
{
2016-03-08 22:55:53 +01:00
ENDUSER_SETUP_DEBUG ( " enduser_setup_http_recvcb " ) ;
2016-03-29 08:27:55 +02:00
2016-03-24 09:25:49 +01:00
if ( ! state | | err ! = ERR_OK )
2016-01-28 06:52:09 +01:00
{
2016-03-24 09:25:49 +01:00
if ( ! state )
ENDUSER_SETUP_DEBUG ( " ignoring received data while stopped " ) ;
tcp_abort ( http_client ) ;
return ERR_ABRT ;
}
2020-09-15 14:06:38 +02:00
tcp_arg_t * tcp_arg_ptr = arg ;
2016-03-24 09:25:49 +01:00
if ( ! p ) /* remote side closed, close our end too */
{
ENDUSER_SETUP_DEBUG ( " connection closed " ) ;
2020-09-15 14:06:38 +02:00
if ( tcp_arg_ptr ) {
if ( tcp_arg_ptr - > struct_type = = SCAN_LISTENER_STRUCT_TYPE ) {
remove_scan_listener ( ( scan_listener_t * ) tcp_arg_ptr ) ;
} else if ( tcp_arg_ptr - > struct_type = = HTTP_REQUEST_BUFFER_STRUCT_TYPE ) {
free ( tcp_arg_ptr ) ;
}
}
2016-03-24 09:25:49 +01:00
2016-03-29 08:27:55 +02:00
deferred_close ( http_client ) ;
2016-03-24 09:25:49 +01:00
return ERR_OK ;
2015-09-02 14:41:27 +02:00
}
2016-01-28 06:52:09 +01:00
2020-09-15 14:06:38 +02:00
http_request_buffer_t * hrb ;
if ( ! tcp_arg_ptr ) {
hrb = calloc ( 1 , sizeof ( * hrb ) ) ;
if ( ! hrb ) {
goto general_fail ;
}
hrb - > struct_type = HTTP_REQUEST_BUFFER_STRUCT_TYPE ;
tcp_arg ( http_client , hrb ) ;
} else if ( tcp_arg_ptr - > struct_type = = HTTP_REQUEST_BUFFER_STRUCT_TYPE ) {
hrb = ( http_request_buffer_t * ) tcp_arg_ptr ;
} else {
goto general_fail ;
}
// Append the new data
size_t newlen = hrb - > length + p - > tot_len ;
void * old_hrb = hrb ;
hrb = realloc ( hrb , sizeof ( * hrb ) + newlen + 1 ) ;
tcp_arg ( http_client , hrb ) ;
if ( ! hrb ) {
free ( old_hrb ) ;
goto general_fail ;
}
pbuf_copy_partial ( p , hrb - > data + hrb - > length , p - > tot_len , 0 ) ;
hrb - > data [ newlen ] = 0 ;
hrb - > length = newlen ;
2016-03-24 09:25:49 +01:00
tcp_recved ( http_client , p - > tot_len ) ;
pbuf_free ( p ) ;
2020-09-15 14:06:38 +02:00
// see if we have the whole request.
// Rely on the fact that the header should not contain a null character
char * end_of_header = strstr ( hrb - > data , " \r \n \r \n " ) ;
if ( end_of_header = = 0 ) {
return ERR_OK ;
}
end_of_header + = 4 ;
// We have the entire header, now see if there is any content. If we don't find the
// content-length header, then there is no content and we can process immediately.
// The content-length header can also be missing if the browser is using chunked
// encoding.
bool is_chunked = FALSE ;
for ( const char * hdr = hrb - > data ; hdr & & hdr < end_of_header ; hdr = strchr ( hdr , ' \n ' ) ) {
hdr + = 1 ; // Skip the \n
if ( strncasecmp ( hdr , " transfer-encoding: " , 18 ) = = 0 ) {
const char * field = hdr + 18 ;
while ( * field ! = ' \n ' ) {
if ( memcmp ( field , " chunked " , 7 ) = = 0 ) {
is_chunked = TRUE ;
break ;
}
field + + ;
}
}
if ( strncasecmp ( hdr , " Content-length: " , 15 ) = = 0 ) {
// There is a content-length header
const char * field = hdr + 15 ;
size_t extra = strtol ( field + 1 , 0 , 10 ) ;
if ( extra + ( end_of_header - hrb - > data ) > hrb - > length ) {
return ERR_OK ;
}
}
}
if ( is_chunked ) {
// More complex to determine if the whole body has arrived
// Format is one or more chunks each preceded by their length (in hex)
// A zero length chunk ends the body
const char * ptr = end_of_header ;
bool seen_end = FALSE ;
while ( ptr < hrb - > data + hrb - > length & & ptr > hrb - > data ) {
size_t chunk_len = strtol ( ptr , 0 , 16 ) ;
// Skip to end of chunk length (note that there can be parameters after the length)
ptr = strchr ( ptr , ' \n ' ) ;
if ( ! ptr ) {
// Don't have the entire chunk header
return ERR_OK ;
}
ptr + + ;
ptr + = chunk_len ;
if ( chunk_len = = 0 ) {
seen_end = TRUE ;
break ;
}
if ( ptr + 2 > hrb - > data + hrb - > length ) {
// We don't have the CRLF yet
return ERR_OK ;
}
if ( memcmp ( ptr , " \r \n " , 2 ) ) {
// Bail out here -- something bad happened
goto general_fail ;
}
ptr + = 2 ;
}
if ( ! seen_end ) {
// Still waiting for the end chunk
return ERR_OK ;
}
// Now rewrite the buffer to eliminate all the chunk headers
const char * src = end_of_header ;
char * dst = end_of_header ;
while ( src < hrb - > data + hrb - > length & & src > hrb - > data ) {
size_t chunk_len = strtol ( src , 0 , 16 ) ;
src = strchr ( src , ' \n ' ) ;
src + + ;
if ( chunk_len = = 0 ) {
break ;
}
memmove ( dst , src , chunk_len ) ;
dst + = chunk_len ;
src + = chunk_len + 2 ;
}
* dst = ' \0 ' ; // Move the null termination down
hrb - > length = dst - hrb - > data ; // Adjust the length down
}
2016-03-29 08:27:55 +02:00
err_t ret = ERR_OK ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
2020-09-15 14:06:38 +02:00
char * data = hrb - > data ;
size_t data_len = hrb - > length ;
tcp_arg ( http_client , 0 ) ; // Forget the data pointer.
2016-12-01 22:12:47 +01:00
# if ENDUSER_SETUP_DEBUG_SHOW_HTTP_REQUEST
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
ENDUSER_SETUP_DEBUG ( data ) ;
2016-12-01 22:12:47 +01:00
# endif
2019-07-21 23:58:21 +02:00
if ( strncmp ( data , " GET " , 4 ) = = 0 )
2015-09-02 14:41:27 +02:00
{
2019-07-21 23:58:21 +02:00
if ( strncmp ( data + 4 , " / " , 2 ) = = 0 | | strncmp ( data + 4 , " /? " , 2 ) = = 0 )
2015-10-01 20:22:45 +02:00
{
2016-01-28 06:52:09 +01:00
if ( enduser_setup_http_serve_html ( http_client ) ! = 0 )
2016-03-08 22:55:53 +01:00
{
2020-09-15 14:06:38 +02:00
goto general_fail ;
2016-03-24 09:25:49 +01:00
}
else
{
2016-03-29 08:27:55 +02:00
goto free_out ; /* streaming now in progress */
2016-03-08 22:55:53 +01:00
}
2015-10-01 20:22:45 +02:00
}
2019-07-21 23:58:21 +02:00
else if ( strncmp ( data + 4 , " /aplist " , 7 ) = = 0 )
2016-01-28 06:52:09 +01:00
{
2016-12-01 22:12:47 +01:00
/* Don't do an AP Scan while station is trying to connect to Wi-Fi */
2019-02-17 19:26:29 +01:00
if ( state - > connecting = = 0 )
2016-03-08 22:55:53 +01:00
{
2020-09-15 14:06:38 +02:00
scan_listener_t * sl = malloc ( sizeof ( scan_listener_t ) ) ;
if ( ! sl )
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
{
ENDUSER_SETUP_ERROR ( " out of memory " , ENDUSER_SETUP_ERR_OUT_OF_MEMORY , ENDUSER_SETUP_ERR_NONFATAL ) ;
}
2016-01-28 06:52:09 +01:00
2020-09-15 14:06:38 +02:00
sl - > struct_type = SCAN_LISTENER_STRUCT_TYPE ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
bool already = ( state - > scan_listeners ! = NULL ) ;
2016-01-28 06:52:09 +01:00
2020-09-15 14:06:38 +02:00
tcp_arg ( http_client , sl ) ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
/* TODO: check if also need a tcp_err() cb, or if recv() is enough */
2020-09-15 14:06:38 +02:00
sl - > conn = http_client ;
sl - > next = state - > scan_listeners ;
state - > scan_listeners = sl ;
2015-09-16 14:56:44 +02:00
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
if ( ! already )
2016-01-28 06:52:09 +01:00
{
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
if ( ! wifi_station_scan ( NULL , on_scan_done ) )
{
enduser_setup_http_serve_header ( http_client , http_header_500 , LITLEN ( http_header_500 ) ) ;
2020-09-15 14:06:38 +02:00
deferred_close ( sl - > conn ) ;
sl - > conn = 0 ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
free_scan_listeners ( ) ;
}
2016-01-28 06:52:09 +01:00
}
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
goto free_out ; /* request queued */
}
else
{
2016-12-01 22:12:47 +01:00
/* Return No Content status to the caller */
2019-02-17 19:26:29 +01:00
enduser_setup_http_serve_header ( http_client , http_header_204 , LITLEN ( http_header_204 ) ) ;
2016-01-28 06:52:09 +01:00
}
}
2019-07-21 23:58:21 +02:00
else if ( strncmp ( data + 4 , " /status.json " , 12 ) = = 0 )
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
{
2020-09-15 14:06:38 +02:00
enduser_setup_serve_status_as_json ( http_client ) ;
2019-02-17 19:26:29 +01:00
}
2019-07-21 23:58:21 +02:00
else if ( strncmp ( data + 4 , " /status " , 7 ) = = 0 )
2016-01-28 06:52:09 +01:00
{
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
enduser_setup_serve_status ( http_client ) ;
2016-01-28 06:52:09 +01:00
}
2019-07-21 23:58:21 +02:00
else if ( strncmp ( data + 4 , " /update? " , 8 ) = = 0 )
2016-01-28 06:52:09 +01:00
{
switch ( enduser_setup_http_handle_credentials ( data , data_len ) )
{
case 0 :
enduser_setup_http_serve_header ( http_client , http_header_302 , LITLEN ( http_header_302 ) ) ;
break ;
case 1 :
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
enduser_setup_http_serve_header ( http_client , http_header_400 , LITLEN ( http_header_400 ) ) ;
2016-01-28 06:52:09 +01:00
break ;
default :
2016-03-24 09:25:49 +01:00
ENDUSER_SETUP_ERROR ( " http_recvcb failed. Failed to handle wifi credentials. " , ENDUSER_SETUP_ERR_UNKOWN_ERROR , ENDUSER_SETUP_ERR_NONFATAL ) ;
2016-01-28 06:52:09 +01:00
break ;
}
}
else
2015-10-01 20:22:45 +02:00
{
2020-09-18 23:47:52 +02:00
// All other URLs redirect to http://nodemcu.portal/ -- this triggers captive portal.
enduser_setup_http_serve_header ( http_client , http_header_302 , LITLEN ( http_header_302 ) ) ;
2015-10-01 20:22:45 +02:00
}
2015-09-02 14:41:27 +02:00
}
2019-07-21 23:58:21 +02:00
else if ( strncmp ( data , " OPTIONS " , 8 ) = = 0 )
2015-09-02 14:41:27 +02:00
{
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
enduser_setup_handle_OPTIONS ( http_client , data , data_len ) ;
2019-02-17 19:26:29 +01:00
}
2019-07-21 23:58:21 +02:00
else if ( strncmp ( data , " POST " , 5 ) = = 0 )
2019-07-08 21:48:16 +02:00
{
enduser_setup_handle_POST ( http_client , data , data_len ) ;
}
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
else /* not GET or OPTIONS */
{
enduser_setup_http_serve_header ( http_client , http_header_405 , LITLEN ( http_header_405 ) ) ;
2015-09-02 14:41:27 +02:00
}
2016-01-28 06:52:09 +01:00
2016-03-29 08:27:55 +02:00
deferred_close ( http_client ) ;
free_out :
2020-09-15 14:06:38 +02:00
free ( hrb ) ;
2016-03-29 08:27:55 +02:00
return ret ;
2020-09-15 14:06:38 +02:00
general_fail :
ENDUSER_SETUP_ERROR ( " http_recvcb failed. Unable to send HTML. " , ENDUSER_SETUP_ERR_UNKOWN_ERROR , ENDUSER_SETUP_ERR_NONFATAL ) ;
2015-09-02 14:41:27 +02:00
}
2019-07-08 21:48:16 +02:00
2016-03-24 09:25:49 +01:00
static err_t enduser_setup_http_connectcb ( void * arg , struct tcp_pcb * pcb , err_t err )
2015-09-02 14:41:27 +02:00
{
2016-03-08 22:55:53 +01:00
ENDUSER_SETUP_DEBUG ( " enduser_setup_http_connectcb " ) ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
2016-03-24 09:25:49 +01:00
if ( ! state )
2015-09-02 14:41:27 +02:00
{
2016-03-24 09:25:49 +01:00
ENDUSER_SETUP_DEBUG ( " connect callback but no state?! " ) ;
tcp_abort ( pcb ) ;
return ERR_ABRT ;
2015-09-02 14:41:27 +02:00
}
2016-03-24 09:25:49 +01:00
tcp_accepted ( state - > http_pcb ) ;
2020-09-15 14:06:38 +02:00
tcp_arg ( pcb , 0 ) ; // Initialize to known value
2016-03-24 09:25:49 +01:00
tcp_recv ( pcb , enduser_setup_http_recvcb ) ;
2016-03-29 08:27:55 +02:00
tcp_nagle_disable ( pcb ) ;
2016-03-24 09:25:49 +01:00
return ERR_OK ;
2015-09-02 14:41:27 +02:00
}
2015-09-19 21:06:56 +02:00
static int enduser_setup_http_start ( void )
2015-09-02 14:41:27 +02:00
{
2016-03-08 22:55:53 +01:00
ENDUSER_SETUP_DEBUG ( " enduser_setup_http_start " ) ;
2016-03-24 09:25:49 +01:00
struct tcp_pcb * pcb = tcp_new ( ) ;
if ( pcb = = NULL )
2015-09-02 14:41:27 +02:00
{
2016-03-24 09:25:49 +01:00
ENDUSER_SETUP_ERROR ( " http_start failed. Memory allocation failed (http_pcb == NULL). " , ENDUSER_SETUP_ERR_OUT_OF_MEMORY , ENDUSER_SETUP_ERR_FATAL ) ;
2015-09-02 14:41:27 +02:00
}
2016-03-24 09:25:49 +01:00
if ( tcp_bind ( pcb , IP_ADDR_ANY , 80 ) ! = ERR_OK )
2015-09-02 14:41:27 +02:00
{
2016-03-24 09:25:49 +01:00
ENDUSER_SETUP_ERROR ( " http_start bind failed " , ENDUSER_SETUP_ERR_SOCKET_ALREADY_OPEN , ENDUSER_SETUP_ERR_FATAL ) ;
2015-09-02 14:41:27 +02:00
}
2016-03-24 09:25:49 +01:00
state - > http_pcb = tcp_listen ( pcb ) ;
if ( ! state - > http_pcb )
2015-09-02 14:41:27 +02:00
{
2016-03-24 09:25:49 +01:00
tcp_abort ( pcb ) ; /* original wasn't freed for us */
ENDUSER_SETUP_ERROR ( " http_start listen failed " , ENDUSER_SETUP_ERR_SOCKET_ALREADY_OPEN , ENDUSER_SETUP_ERR_FATAL ) ;
2015-09-02 14:41:27 +02:00
}
2015-09-16 14:56:44 +02:00
2016-03-24 09:25:49 +01:00
tcp_accept ( state - > http_pcb , enduser_setup_http_connectcb ) ;
/* TODO: check lwip tcp timeouts */
#if 0
2015-09-19 21:06:56 +02:00
err = espconn_regist_time ( state - > espconn_http_tcp , 2 , 0 ) ;
2015-09-02 14:41:27 +02:00
if ( err = = ESPCONN_ARG )
{
2016-01-28 06:52:09 +01:00
ENDUSER_SETUP_ERROR ( " http_start failed. Unable to set TCP timeout. " , ENDUSER_SETUP_ERR_CONNECTION_NOT_FOUND , ENDUSER_SETUP_ERR_NONFATAL | ENDUSER_SETUP_ERR_NO_RETURN ) ;
2015-09-02 14:41:27 +02:00
}
2016-03-24 09:25:49 +01:00
# endif
2015-09-02 14:41:27 +02:00
2016-03-24 09:25:49 +01:00
int err = enduser_setup_http_load_payload ( ) ;
2015-09-02 14:41:27 +02:00
if ( err = = 1 )
{
2019-07-08 21:48:16 +02:00
ENDUSER_SETUP_DEBUG ( " enduser_setup_http_start info. Loaded default HTML. " ) ;
2015-09-02 14:41:27 +02:00
}
else if ( err = = 2 )
{
2016-01-28 06:52:09 +01:00
ENDUSER_SETUP_ERROR ( " http_start failed. Unable to allocate memory for HTTP payload. " , ENDUSER_SETUP_ERR_OUT_OF_MEMORY , ENDUSER_SETUP_ERR_FATAL ) ;
2015-09-02 14:41:27 +02:00
}
2015-09-19 21:06:56 +02:00
return 0 ;
2015-09-02 14:41:27 +02:00
}
2015-09-12 18:07:53 +02:00
static void enduser_setup_http_stop ( void )
2015-09-02 14:41:27 +02:00
{
2016-03-08 22:55:53 +01:00
ENDUSER_SETUP_DEBUG ( " enduser_setup_http_stop " ) ;
2015-09-02 14:41:27 +02:00
2016-03-24 09:25:49 +01:00
if ( state & & state - > http_pcb )
2015-09-02 14:41:27 +02:00
{
2016-03-24 09:25:49 +01:00
tcp_close ( state - > http_pcb ) ; /* cannot fail for listening sockets */
state - > http_pcb = 0 ;
2015-09-02 14:41:27 +02:00
}
}
2015-09-12 18:07:53 +02:00
static void enduser_setup_ap_stop ( void )
2015-09-02 14:41:27 +02:00
{
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
ENDUSER_SETUP_DEBUG ( " enduser_setup_ap_stop " ) ;
2015-09-02 14:41:27 +02:00
wifi_set_opmode ( ~ SOFTAP_MODE & wifi_get_opmode ( ) ) ;
}
2015-09-12 18:07:53 +02:00
static void enduser_setup_ap_start ( void )
2015-09-02 14:41:27 +02:00
{
2016-03-08 22:55:53 +01:00
ENDUSER_SETUP_DEBUG ( " enduser_setup_ap_start " ) ;
2015-09-02 14:41:27 +02:00
struct softap_config cnf ;
2019-07-21 23:58:21 +02:00
memset ( & ( cnf ) , 0 , sizeof ( struct softap_config ) ) ;
2015-09-27 20:02:25 +02:00
2015-12-21 04:50:36 +01:00
# ifndef ENDUSER_SETUP_AP_SSID
2020-09-18 23:47:52 +02:00
# define ENDUSER_SETUP_AP_SSID "NodeMCU"
2015-12-21 04:50:36 +01:00
# endif
2020-09-18 23:47:52 +02:00
if ( state - > ap_ssid ) {
strncpy ( cnf . ssid , state - > ap_ssid , sizeof ( cnf . ssid ) ) ;
cnf . ssid_len = strlen ( cnf . ssid ) ;
} else {
char ssid [ ] = ENDUSER_SETUP_AP_SSID ;
int ssid_name_len = strlen ( ssid ) ;
memcpy ( & ( cnf . ssid ) , ssid , ssid_name_len ) ;
2015-09-27 20:02:25 +02:00
2020-09-18 23:47:52 +02:00
uint8_t mac [ 6 ] ;
wifi_get_macaddr ( SOFTAP_IF , mac ) ;
cnf . ssid [ ssid_name_len ] = ' _ ' ;
sprintf ( cnf . ssid + ssid_name_len + 1 , " %02X%02X%02X " , mac [ 3 ] , mac [ 4 ] , mac [ 5 ] ) ;
cnf . ssid_len = ssid_name_len + 7 ;
}
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
cnf . channel = state = = NULL ? 1 : state - > softAPchannel ;
2015-09-02 14:41:27 +02:00
cnf . authmode = AUTH_OPEN ;
cnf . ssid_hidden = 0 ;
cnf . max_connection = 5 ;
cnf . beacon_interval = 100 ;
2016-01-28 06:52:09 +01:00
wifi_set_opmode ( STATIONAP_MODE ) ;
2015-09-02 14:41:27 +02:00
wifi_softap_set_config ( & cnf ) ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
2019-02-17 19:26:29 +01:00
# if ENDUSER_SETUP_DEBUG_ENABLE
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
char debuginfo [ 100 ] ;
2019-07-21 23:58:21 +02:00
sprintf ( debuginfo , " SSID: %s, CHAN: %d " , cnf . ssid , cnf . channel ) ;
2019-02-17 19:26:29 +01:00
ENDUSER_SETUP_DEBUG ( debuginfo ) ;
# endif
2015-09-02 14:41:27 +02:00
}
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
static void on_initial_scan_done ( void * arg , STATUS status )
{
ENDUSER_SETUP_DEBUG ( " on_initial_scan_done " ) ;
2016-12-01 22:12:47 +01:00
if ( state = = NULL )
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
{
return ;
}
int8_t rssi = - 100 ;
2019-02-17 19:26:29 +01:00
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
if ( status = = OK )
{
2019-02-17 19:26:29 +01:00
/* Find the strongest signal and use the same wi-fi channel for the SoftAP. This is based on an assumption that end-user
* will likely be choosing that AP to connect to . Since ESP only has one radio , STA and AP must share same channel . This
* algorithm tries to minimize the SoftAP unavailability when the STA is connecting to verify . If the STA must switch to
* another wi - fi channel , then the SoftAP will follow it , but the end - user ' s device will not know that the SoftAP is no
2016-12-01 22:12:47 +01:00
* longer there until it times out . To mitigate , we try to prevent the need to switch channels , and if a switch does occur ,
2019-02-17 19:26:29 +01:00
* be quick about returning to this channel so that status info can be delivered to the end - user ' s device before shutting
* down EUS .
2016-12-01 22:12:47 +01:00
*/
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
for ( struct bss_info * wn = arg ; wn ; wn = wn - > next . stqe_next )
{
if ( wn - > rssi > rssi )
{
state - > softAPchannel = wn - > channel ;
rssi = wn - > rssi ;
}
}
}
2019-02-17 19:26:29 +01:00
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
enduser_setup_ap_start ( ) ;
enduser_setup_check_station_start ( ) ;
}
2015-09-02 14:41:27 +02:00
2015-09-12 18:07:53 +02:00
static void enduser_setup_dns_recv_callback ( void * arg , char * recv_data , unsigned short recv_len )
2015-09-02 14:41:27 +02:00
{
2016-03-08 22:55:53 +01:00
ENDUSER_SETUP_DEBUG ( " enduser_setup_dns_recv_callback. " ) ;
2015-09-02 14:41:27 +02:00
struct espconn * callback_espconn = arg ;
struct ip_info ip_info ;
2019-07-21 23:58:21 +02:00
uint32_t qname_len = strlen ( & ( recv_data [ 12 ] ) ) + 1 ; /* \0=1byte */
2016-12-01 22:12:47 +01:00
uint32_t dns_reply_static_len = ( uint32_t ) sizeof ( dns_header ) + ( uint32_t ) sizeof ( dns_body ) + 2 + 4 ; /* dns_id=2bytes, ip=4bytes */
2015-09-19 21:06:56 +02:00
uint32_t dns_reply_len = dns_reply_static_len + qname_len ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
# if ENDUSER_SETUP_DEBUG_ENABLE
2019-07-21 23:58:21 +02:00
char * qname = malloc ( qname_len + 12 ) ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
if ( qname ! = NULL )
{
2019-07-21 23:58:21 +02:00
sprintf ( qname , " DNS QUERY = %s " , & ( recv_data [ 12 ] ) ) ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
uint32_t p ;
int i , j ;
2019-02-17 19:26:29 +01:00
for ( i = 12 ; i < ( int ) strlen ( qname ) ; i + + )
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
{
p = qname [ i ] ;
2019-02-17 19:26:29 +01:00
for ( j = 0 ; j < ( int ) p ; j + + )
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
{
qname [ i ] = qname [ i + 1 ] ;
i = i + 1 ;
}
qname [ i ] = ' . ' ;
}
qname [ i - 1 ] = ' \0 ' ;
2019-02-17 19:26:29 +01:00
ENDUSER_SETUP_DEBUG ( qname ) ;
2019-07-21 23:58:21 +02:00
free ( qname ) ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
}
# endif
2015-09-02 14:41:27 +02:00
uint8_t if_mode = wifi_get_opmode ( ) ;
if ( ( if_mode & SOFTAP_MODE ) = = 0 )
{
2016-01-28 06:52:09 +01:00
ENDUSER_SETUP_ERROR_VOID ( " dns_recv_callback failed. Interface mode not supported. " , ENDUSER_SETUP_ERR_UNKOWN_ERROR , ENDUSER_SETUP_ERR_FATAL ) ;
2015-09-02 14:41:27 +02:00
}
2015-09-19 21:06:56 +02:00
2015-09-02 14:41:27 +02:00
uint8_t if_index = ( if_mode = = STATION_MODE ? STATION_IF : SOFTAP_IF ) ;
if ( wifi_get_ip_info ( if_index , & ip_info ) = = false )
{
2016-01-28 06:52:09 +01:00
ENDUSER_SETUP_ERROR_VOID ( " dns_recv_callback failed. Unable to get interface IP. " , ENDUSER_SETUP_ERR_UNKOWN_ERROR , ENDUSER_SETUP_ERR_FATAL ) ;
2015-09-02 14:41:27 +02:00
}
2015-09-19 21:06:56 +02:00
2019-07-21 23:58:21 +02:00
char * dns_reply = ( char * ) malloc ( dns_reply_len ) ;
2015-09-02 14:41:27 +02:00
if ( dns_reply = = NULL )
{
2016-01-28 06:52:09 +01:00
ENDUSER_SETUP_ERROR_VOID ( " dns_recv_callback failed. Failed to allocate memory. " , ENDUSER_SETUP_ERR_OUT_OF_MEMORY , ENDUSER_SETUP_ERR_NONFATAL ) ;
2015-09-02 14:41:27 +02:00
}
uint32_t insert_byte = 0 ;
2019-07-21 23:58:21 +02:00
memcpy ( & ( dns_reply [ insert_byte ] ) , recv_data , 2 ) ;
2015-09-02 14:41:27 +02:00
insert_byte + = 2 ;
2019-07-21 23:58:21 +02:00
memcpy ( & ( dns_reply [ insert_byte ] ) , dns_header , sizeof ( dns_header ) ) ;
2015-09-02 14:41:27 +02:00
insert_byte + = ( uint32_t ) sizeof ( dns_header ) ;
2019-07-21 23:58:21 +02:00
memcpy ( & ( dns_reply [ insert_byte ] ) , & ( recv_data [ 12 ] ) , qname_len ) ;
2015-09-02 14:41:27 +02:00
insert_byte + = qname_len ;
2019-07-21 23:58:21 +02:00
memcpy ( & ( dns_reply [ insert_byte ] ) , dns_body , sizeof ( dns_body ) ) ;
2015-09-02 14:41:27 +02:00
insert_byte + = ( uint32_t ) sizeof ( dns_body ) ;
2019-07-21 23:58:21 +02:00
memcpy ( & ( dns_reply [ insert_byte ] ) , & ( ip_info . ip ) , 4 ) ;
2015-09-19 21:06:56 +02:00
2016-12-01 22:12:47 +01:00
/* SDK 1.4.0 changed behaviour, for UDP server need to look up remote ip/port */
2015-11-12 05:46:26 +01:00
remot_info * pr = 0 ;
if ( espconn_get_connection_info ( callback_espconn , & pr , 0 ) ! = ESPCONN_OK )
{
2016-01-28 06:52:09 +01:00
ENDUSER_SETUP_ERROR_VOID ( " dns_recv_callback failed. Unable to get IP of UDP sender. " , ENDUSER_SETUP_ERR_CONNECTION_NOT_FOUND , ENDUSER_SETUP_ERR_FATAL ) ;
2015-11-12 05:46:26 +01:00
}
callback_espconn - > proto . udp - > remote_port = pr - > remote_port ;
os_memmove ( callback_espconn - > proto . udp - > remote_ip , pr - > remote_ip , 4 ) ;
2015-09-02 14:41:27 +02:00
int8_t err ;
2016-01-28 06:52:09 +01:00
err = espconn_send ( callback_espconn , dns_reply , dns_reply_len ) ;
2019-07-21 23:58:21 +02:00
free ( dns_reply ) ;
2015-09-02 14:41:27 +02:00
if ( err = = ESPCONN_MEM )
{
2016-01-28 06:52:09 +01:00
ENDUSER_SETUP_ERROR_VOID ( " dns_recv_callback failed. Failed to allocate memory for send. " , ENDUSER_SETUP_ERR_OUT_OF_MEMORY , ENDUSER_SETUP_ERR_FATAL ) ;
2015-09-02 14:41:27 +02:00
}
else if ( err = = ESPCONN_ARG )
{
2016-01-28 06:52:09 +01:00
ENDUSER_SETUP_ERROR_VOID ( " dns_recv_callback failed. Can't execute transmission. " , ENDUSER_SETUP_ERR_CONNECTION_NOT_FOUND , ENDUSER_SETUP_ERR_FATAL ) ;
2015-09-02 14:41:27 +02:00
}
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
else if ( err = = ESPCONN_MAXNUM )
{
ENDUSER_SETUP_ERROR_VOID ( " dns_recv_callback failed. Buffer full. Discarding... " , ENDUSER_SETUP_ERR_MAX_NUMBER , ENDUSER_SETUP_ERR_NONFATAL ) ;
2019-02-17 19:26:29 +01:00
}
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
else if ( err = = ESPCONN_IF )
{
ENDUSER_SETUP_ERROR_VOID ( " dns_recv_callback failed. Send UDP data failed " , ENDUSER_SETUP_ERR_UNKOWN_ERROR , ENDUSER_SETUP_ERR_NONFATAL ) ;
2019-02-17 19:26:29 +01:00
}
2015-09-02 14:41:27 +02:00
else if ( err ! = 0 )
{
2016-01-28 06:52:09 +01:00
ENDUSER_SETUP_ERROR_VOID ( " dns_recv_callback failed. espconn_send failed " , ENDUSER_SETUP_ERR_UNKOWN_ERROR , ENDUSER_SETUP_ERR_FATAL ) ;
2015-09-02 14:41:27 +02:00
}
}
2015-09-19 21:06:56 +02:00
static void enduser_setup_free ( void )
2015-09-02 14:41:27 +02:00
{
2016-03-08 22:55:53 +01:00
ENDUSER_SETUP_DEBUG ( " enduser_setup_free " ) ;
2015-09-19 21:06:56 +02:00
if ( state = = NULL )
{
return ;
}
2016-03-08 22:55:53 +01:00
/* Make sure no running timers are left. */
os_timer_disarm ( & ( state - > check_station_timer ) ) ;
os_timer_disarm ( & ( state - > shutdown_timer ) ) ;
2015-09-19 21:06:56 +02:00
if ( state - > espconn_dns_udp ! = NULL )
{
if ( state - > espconn_dns_udp - > proto . udp ! = NULL )
{
2019-07-21 23:58:21 +02:00
free ( state - > espconn_dns_udp - > proto . udp ) ;
2015-09-19 21:06:56 +02:00
}
2019-07-21 23:58:21 +02:00
free ( state - > espconn_dns_udp ) ;
2015-09-19 21:06:56 +02:00
}
2015-09-02 14:41:27 +02:00
2019-07-21 23:58:21 +02:00
free ( state - > http_payload_data ) ;
2016-01-28 06:52:09 +01:00
free_scan_listeners ( ) ;
2020-09-18 23:47:52 +02:00
free ( state - > ap_ssid ) ;
2019-07-21 23:58:21 +02:00
free ( state ) ;
2015-09-19 21:06:56 +02:00
state = NULL ;
2015-09-02 14:41:27 +02:00
}
2015-09-19 21:06:56 +02:00
static int enduser_setup_dns_start ( void )
2015-09-02 14:41:27 +02:00
{
2016-03-08 22:55:53 +01:00
ENDUSER_SETUP_DEBUG ( " enduser_setup_dns_start " ) ;
2015-09-02 14:41:27 +02:00
2015-09-19 21:06:56 +02:00
if ( state - > espconn_dns_udp ! = NULL )
2015-09-02 14:41:27 +02:00
{
2016-12-01 22:12:47 +01:00
ENDUSER_SETUP_ERROR ( " dns_start failed. Appears to already be started (espconn_dns_udp != NULL). " , ENDUSER_SETUP_ERR_ALREADY_INITIALIZED , ENDUSER_SETUP_ERR_FATAL ) ;
2015-09-02 14:41:27 +02:00
}
2019-07-21 23:58:21 +02:00
state - > espconn_dns_udp = ( struct espconn * ) malloc ( sizeof ( struct espconn ) ) ;
2015-09-19 21:06:56 +02:00
if ( state - > espconn_dns_udp = = NULL )
2015-09-02 14:41:27 +02:00
{
2016-01-28 06:52:09 +01:00
ENDUSER_SETUP_ERROR ( " dns_start failed. Memory allocation failed (espconn_dns_udp == NULL). " , ENDUSER_SETUP_ERR_OUT_OF_MEMORY , ENDUSER_SETUP_ERR_FATAL ) ;
2015-09-02 14:41:27 +02:00
}
2019-07-21 23:58:21 +02:00
esp_udp * esp_udp_data = ( esp_udp * ) malloc ( sizeof ( esp_udp ) ) ;
2015-09-02 14:41:27 +02:00
if ( esp_udp_data = = NULL )
{
2016-01-28 06:52:09 +01:00
ENDUSER_SETUP_ERROR ( " dns_start failed. Memory allocation failed (esp_udp == NULL). " , ENDUSER_SETUP_ERR_OUT_OF_MEMORY , ENDUSER_SETUP_ERR_FATAL ) ;
2015-09-02 14:41:27 +02:00
}
2019-07-21 23:58:21 +02:00
memset ( state - > espconn_dns_udp , 0 , sizeof ( struct espconn ) ) ;
memset ( esp_udp_data , 0 , sizeof ( esp_udp ) ) ;
2015-09-19 21:06:56 +02:00
state - > espconn_dns_udp - > proto . udp = esp_udp_data ;
state - > espconn_dns_udp - > type = ESPCONN_UDP ;
state - > espconn_dns_udp - > state = ESPCONN_NONE ;
2015-09-02 14:41:27 +02:00
esp_udp_data - > local_port = 53 ;
int8_t err ;
2015-09-19 21:06:56 +02:00
err = espconn_regist_recvcb ( state - > espconn_dns_udp , enduser_setup_dns_recv_callback ) ;
2015-09-02 14:41:27 +02:00
if ( err ! = 0 )
{
2016-01-28 06:52:09 +01:00
ENDUSER_SETUP_ERROR ( " dns_start failed. Couldn't add receive callback, unknown error. " , ENDUSER_SETUP_ERR_UNKOWN_ERROR , ENDUSER_SETUP_ERR_FATAL ) ;
2015-09-02 14:41:27 +02:00
}
2015-09-19 21:06:56 +02:00
err = espconn_create ( state - > espconn_dns_udp ) ;
2015-09-02 14:41:27 +02:00
if ( err = = ESPCONN_ISCONN )
{
2016-01-28 06:52:09 +01:00
ENDUSER_SETUP_ERROR ( " dns_start failed. Couldn't create connection, already listening for that connection. " , ENDUSER_SETUP_ERR_SOCKET_ALREADY_OPEN , ENDUSER_SETUP_ERR_FATAL ) ;
2015-09-02 14:41:27 +02:00
}
else if ( err = = ESPCONN_MEM )
{
2016-01-28 06:52:09 +01:00
ENDUSER_SETUP_ERROR ( " dns_start failed. Couldn't create connection, out of memory. " , ENDUSER_SETUP_ERR_OUT_OF_MEMORY , ENDUSER_SETUP_ERR_FATAL ) ;
2015-09-02 14:41:27 +02:00
}
else if ( err ! = 0 )
{
2016-01-28 06:52:09 +01:00
ENDUSER_SETUP_ERROR ( " dns_start failed. Couldn't create connection, unknown error. " , ENDUSER_SETUP_ERR_UNKOWN_ERROR , ENDUSER_SETUP_ERR_FATAL ) ;
2015-09-02 14:41:27 +02:00
}
2015-09-19 21:06:56 +02:00
return 0 ;
2015-09-02 14:41:27 +02:00
}
2015-09-12 18:07:53 +02:00
static void enduser_setup_dns_stop ( void )
2015-09-02 14:41:27 +02:00
{
2016-03-08 22:55:53 +01:00
ENDUSER_SETUP_DEBUG ( " enduser_setup_dns_stop " ) ;
2015-09-02 14:41:27 +02:00
2016-03-01 08:33:11 +01:00
if ( state ! = NULL & & state - > espconn_dns_udp ! = NULL )
2015-09-02 14:41:27 +02:00
{
2015-09-19 21:06:56 +02:00
espconn_delete ( state - > espconn_dns_udp ) ;
2015-09-02 14:41:27 +02:00
}
2015-09-19 21:06:56 +02:00
}
2015-09-02 14:41:27 +02:00
2015-09-19 21:06:56 +02:00
static int enduser_setup_init ( lua_State * L )
{
2016-12-01 22:12:47 +01:00
/* Note: Normal to not see this debug message on first invocation because debug callback is set below */
2016-03-08 22:55:53 +01:00
ENDUSER_SETUP_DEBUG ( " enduser_setup_init " ) ;
2015-09-19 21:06:56 +02:00
2016-12-01 22:12:47 +01:00
/* Defer errors until the bottom, so that callbacks can be set, if applicable, to handle debug and error messages */
int ret = 0 ;
2015-09-19 21:06:56 +02:00
if ( state ! = NULL )
2015-09-02 14:41:27 +02:00
{
2016-12-01 22:12:47 +01:00
ret = ENDUSER_SETUP_ERR_ALREADY_INITIALIZED ;
2015-09-02 14:41:27 +02:00
}
2016-12-01 22:12:47 +01:00
else
2015-09-19 21:06:56 +02:00
{
2019-07-21 23:58:21 +02:00
state = ( enduser_setup_state_t * ) calloc ( 1 , sizeof ( enduser_setup_state_t ) ) ;
2015-09-19 21:06:56 +02:00
2016-12-01 22:12:47 +01:00
if ( state = = NULL )
{
ret = ENDUSER_SETUP_ERR_OUT_OF_MEMORY ;
}
else
{
2019-07-21 23:58:21 +02:00
memset ( state , 0 , sizeof ( enduser_setup_state_t ) ) ;
2016-12-01 22:12:47 +01:00
state - > lua_connected_cb_ref = LUA_NOREF ;
state - > lua_err_cb_ref = LUA_NOREF ;
2019-02-17 19:26:29 +01:00
state - > lua_dbg_cb_ref = LUA_NOREF ;
2016-12-01 22:12:47 +01:00
state - > softAPchannel = 1 ;
state - > success = 0 ;
state - > callbackDone = 0 ;
state - > lastStationStatus = 0 ;
2019-02-17 19:26:29 +01:00
state - > connecting = 0 ;
2016-12-01 22:12:47 +01:00
}
}
2015-09-19 21:06:56 +02:00
2020-09-18 23:47:52 +02:00
int argno = 1 ;
if ( lua_isstring ( L , argno ) ) {
/* Get the SSID */
state - > ap_ssid = strdup ( lua_tostring ( L , argno ) ) ;
argno + + ;
}
if ( ! lua_isnoneornil ( L , argno ) )
2015-09-19 21:06:56 +02:00
{
2020-09-18 23:47:52 +02:00
lua_pushvalue ( L , argno ) ;
2015-09-19 21:06:56 +02:00
state - > lua_connected_cb_ref = luaL_ref ( L , LUA_REGISTRYINDEX ) ;
}
2020-09-18 23:47:52 +02:00
argno + + ;
if ( ! lua_isnoneornil ( L , argno ) )
2015-09-19 21:06:56 +02:00
{
2020-09-18 23:47:52 +02:00
lua_pushvalue ( L , argno ) ;
2015-09-19 21:06:56 +02:00
state - > lua_err_cb_ref = luaL_ref ( L , LUA_REGISTRYINDEX ) ;
}
2020-09-18 23:47:52 +02:00
argno + + ;
if ( ! lua_isnoneornil ( L , argno ) )
2015-09-02 14:41:27 +02:00
{
2020-09-18 23:47:52 +02:00
lua_pushvalue ( L , argno ) ;
2015-09-19 21:06:56 +02:00
state - > lua_dbg_cb_ref = luaL_ref ( L , LUA_REGISTRYINDEX ) ;
2019-02-17 19:26:29 +01:00
ENDUSER_SETUP_DEBUG ( " enduser_setup_init: Debug callback has been set " ) ;
2015-09-19 21:06:56 +02:00
}
2016-12-01 22:12:47 +01:00
2019-02-17 19:26:29 +01:00
if ( ret = = ENDUSER_SETUP_ERR_ALREADY_INITIALIZED )
2016-12-01 22:12:47 +01:00
{
ENDUSER_SETUP_ERROR ( " init failed. Appears to already be started. EUS will shut down now. " , ENDUSER_SETUP_ERR_ALREADY_INITIALIZED , ENDUSER_SETUP_ERR_FATAL ) ;
}
2019-02-17 19:26:29 +01:00
else if ( ret = = ENDUSER_SETUP_ERR_OUT_OF_MEMORY )
2015-09-19 21:06:56 +02:00
{
2016-12-01 22:12:47 +01:00
ENDUSER_SETUP_ERROR ( " init failed. Unable to allocate memory. " , ENDUSER_SETUP_ERR_OUT_OF_MEMORY , ENDUSER_SETUP_ERR_FATAL ) ;
2015-09-02 14:41:27 +02:00
}
2016-12-01 22:12:47 +01:00
return ret ;
2015-09-02 14:41:27 +02:00
}
2016-03-08 22:55:53 +01:00
static int enduser_setup_manual ( lua_State * L )
2016-01-28 06:52:09 +01:00
{
if ( ! lua_isnoneornil ( L , 1 ) )
2016-03-08 22:55:53 +01:00
{
2016-01-28 06:52:09 +01:00
manual = lua_toboolean ( L , 1 ) ;
2016-03-08 22:55:53 +01:00
}
2016-01-28 06:52:09 +01:00
lua_pushboolean ( L , manual ) ;
return 1 ;
}
2015-09-19 21:06:56 +02:00
static int enduser_setup_start ( lua_State * L )
2015-09-02 14:41:27 +02:00
{
2016-12-01 22:12:47 +01:00
/* Note: The debug callback is set in enduser_setup_init. It's normal to not see this debug message on first invocation. */
2016-03-08 22:55:53 +01:00
ENDUSER_SETUP_DEBUG ( " enduser_setup_start " ) ;
2015-09-19 21:06:56 +02:00
2017-03-18 09:45:26 +01:00
ipaddr [ 0 ] = ' \0 ' ;
2016-03-01 07:54:10 +01:00
if ( ! do_station_cfg_handle )
2016-03-08 22:55:53 +01:00
{
2016-03-01 07:54:10 +01:00
do_station_cfg_handle = task_get_id ( do_station_cfg ) ;
2016-03-08 22:55:53 +01:00
}
2016-03-01 07:54:10 +01:00
2015-09-19 21:06:56 +02:00
if ( enduser_setup_init ( L ) )
2016-03-08 22:55:53 +01:00
{
2016-01-28 06:52:09 +01:00
goto failed ;
2016-03-08 22:55:53 +01:00
}
2016-01-28 06:52:09 +01:00
if ( ! manual )
2015-09-19 21:06:56 +02:00
{
2019-02-17 19:26:29 +01:00
ENDUSER_SETUP_DEBUG ( " Performing AP Scan to identify likely AP's channel. Enabling Station if it wasn't already. " ) ;
2016-12-01 22:12:47 +01:00
wifi_set_opmode ( STATION_MODE | wifi_get_opmode ( ) ) ;
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
wifi_station_scan ( NULL , on_initial_scan_done ) ;
}
else
{
enduser_setup_check_station_start ( ) ;
2015-09-19 21:06:56 +02:00
}
if ( enduser_setup_dns_start ( ) )
2016-03-08 22:55:53 +01:00
{
2016-01-28 06:52:09 +01:00
goto failed ;
2016-03-08 22:55:53 +01:00
}
2015-09-19 21:06:56 +02:00
if ( enduser_setup_http_start ( ) )
2016-03-08 22:55:53 +01:00
{
2016-01-28 06:52:09 +01:00
goto failed ;
2016-03-08 22:55:53 +01:00
}
2016-01-28 06:52:09 +01:00
goto out ;
2015-09-16 14:56:44 +02:00
2016-01-28 06:52:09 +01:00
failed :
2016-03-08 22:55:53 +01:00
enduser_setup_stop ( lua_getstate ( ) ) ;
2016-01-28 06:52:09 +01:00
out :
2015-09-02 14:41:27 +02:00
return 0 ;
}
2016-03-08 22:55:53 +01:00
/**
* A wrapper needed for type - reasons strictness reasons .
*/
static void enduser_setup_stop_callback ( void * ptr )
{
enduser_setup_stop ( lua_getstate ( ) ) ;
}
2015-09-12 18:07:53 +02:00
static int enduser_setup_stop ( lua_State * L )
2015-09-02 14:41:27 +02:00
{
2016-03-08 22:55:53 +01:00
ENDUSER_SETUP_DEBUG ( " enduser_setup_stop " ) ;
2016-01-28 06:52:09 +01:00
if ( ! manual )
{
enduser_setup_ap_stop ( ) ;
}
2016-12-01 22:12:47 +01:00
if ( state ! = NULL & & state - > success & & ! state - > callbackDone )
Eus channelfix (#1583)
Squashed commits included:
Bug fixes and final implementation
- Added Content-Length: 0 to all headers
- Endpoint name checks not using trailing space so cache-busting techniques can be used (i.e., append a nonce to the URL)
- Track when connecting so APList scan doesn't take place during (which changes the channel)
- More debugging output added to assist in tracking down some issues
Added /status.json endpoint for phone apps/XHR to get JSON response
Station Status caching for wifi channel workaround + AJAX/CORS
- During checkstation poll, cache the last station status
- Shut down the station if status = 2,3,4 and channel is different than SoftAP
- Add Access-Control-Allow-Origin: * to endpoint responses used by a service
- Add a /setwifi GET endpoint for phone apps/XHR to use (same parameters as /update endpoint). Returns a JSON response containing chip id and status code.
- Add handler for OPTIONS verb (needed for CORS support)
Wi-Fi Channel Issue Workaround
- Do a site survey upon startup, set SoftAP channel to the strongest rssi's channel
- Compare successful station connect channel to SoftAP's. If different, then defer the Lua success callback to the end. Shut down Station and start the SoftAP back up with original channel.
- After the 10 second shutdown timer fires, check to see if success callback was already called. If not, then call it while starting the Station back up.
HTTP Response and DNS enhancements
- If DNS's UDP buffer fills up, keep going as non-fatal. It's UDP and not guaranteed anyways. I've seen this occur when connecting a PC to the SoftAP and every open program tries to phone home at the same time, overwhelming the EUS DNS server.
- Support for detecting/handling pre-gzipped `enduser_setup.html` (and `http_html_backup`) payload. Nice for keeping the size of the `state->http_payload_data` as small as possible (also makes minimization not as critical)
- Corrected misuse of HTTP 401 response status (changed one occurrence to 400/Bad Request, and changed another to 405/Method Not Allowed)
* Normalized formatting (tabs-to-spaces)
* Added documentation
* Corrected misuse of strlen for binary (gzip) data.
* Added NULL check after malloc
2016-11-08 21:58:33 +01:00
{
wifi_set_opmode ( STATION_MODE | wifi_get_opmode ( ) ) ;
wifi_station_connect ( ) ;
enduser_setup_connected_callback ( ) ;
2019-02-17 19:26:29 +01:00
}
2015-09-02 14:41:27 +02:00
enduser_setup_dns_stop ( ) ;
enduser_setup_http_stop ( ) ;
2015-09-19 21:06:56 +02:00
enduser_setup_free ( ) ;
2015-09-02 14:41:27 +02:00
return 0 ;
}
2020-04-27 02:13:38 +02:00
LROT_BEGIN ( enduser_setup , NULL , 0 )
2019-05-08 13:08:20 +02:00
LROT_FUNCENTRY ( manual , enduser_setup_manual )
LROT_FUNCENTRY ( start , enduser_setup_start )
LROT_FUNCENTRY ( stop , enduser_setup_stop )
2020-04-27 02:13:38 +02:00
LROT_END ( enduser_setup , NULL , 0 )
2019-05-08 13:08:20 +02:00
NODEMCU_MODULE ( ENDUSER_SETUP , " enduser_setup " , enduser_setup , NULL ) ;