diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 86a9a2a..1666cdb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,7 +29,7 @@ Please ensure to specify the following: Arduino IDE version: 1.8.19 Arduino AmebaD core v3.1.1 OS: Ubuntu 20.04 LTS -Linux xy-Inspiron-3593 5.4.0-91-generic #102-Ubuntu SMP Fri Nov 5 16:31:28 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux +Linux xy-Inspiron-3593 5.4.0-94-generic #106-Ubuntu SMP Thu Jan 6 23:58:14 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux Context: I encountered an endless loop while trying to connect to Local WiFi. diff --git a/README.md b/README.md index a3aa6cf..43038ae 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ This [**WiFiWebServer_RTL8720 library**](https://github.com/khoih-prog/WiFiWebSe ## Prerequisites - 1. [`Arduino IDE 1.8.19+` for Arduino](https://www.arduino.cc/en/Main/Software) + 1. [`Arduino IDE 1.8.19+` for Arduino](https://github.com/arduino/Arduino). [![GitHub release](https://img.shields.io/github/release/arduino/Arduino.svg)](https://github.com/arduino/Arduino/releases/latest) 2. [`Arduino AmebaD core 3.1.1+`](https://github.com/ambiot/ambd_arduino) for Realtek RTL8720DN, RTL8722DM and RTL8722CSM. [![GitHub release](https://img.shields.io/github/release/ambiot/ambd_arduino.svg)](https://github.com/ambiot/ambd_arduino/releases/latest) 3. [`Functional-VLPP library v1.0.2+`](https://github.com/khoih-prog/functional-vlpp) to use server's lambda function. To install. check [![arduino-library-badge](https://www.ardu-badge.com/badge/Functional-Vlpp.svg?)](https://www.ardu-badge.com/Functional-Vlpp) @@ -620,7 +620,7 @@ The following are debug terminal output and screen shot when running example [** ``` Starting AdvancedServer on Rtlduino RTL8720DN with RTL8720DN -WiFiWebServer_RTL8720 v1.1.0 +WiFiWebServer_RTL8720 v1.1.1 Current Firmware Version = 1.0.0 Attempting to connect to SSID: HueNet_5G HTTP server started @ 192.168.2.152 @@ -636,7 +636,7 @@ The following are debug terminal output and screen shot when running example [** ``` Starting WebClient on Rtlduino RTL8720DN with RTL8720DN -WiFiWebServer_RTL8720 v1.1.0 +WiFiWebServer_RTL8720 v1.1.1 Current Firmware Version = 1.0.0 Attempting to connect to SSID: HueNet_5G You're connected to the network, IP = 192.168.2.152 @@ -707,7 +707,7 @@ The following are debug terminal output and screen shot when running example [** ``` Starting ScanNetworks on Rtlduino RTL8720DN with RTL8720DN -WiFiWebServer_RTL8720 v1.1.0 +WiFiWebServer_RTL8720 v1.1.1 Current Firmware Version = 1.0.0 Attempting to connect to SSID: HueNet_5G You're connected to the network, IP = 192.168.2.152 @@ -737,7 +737,7 @@ The following are debug terminal output and screen shot when running example [** ``` Starting MQTTClient_Auth on Rtlduino RTL8720DN with RTL8720DN -WiFiWebServer_RTL8720 v1.1.0 +WiFiWebServer_RTL8720 v1.1.1 Current Firmware Version = 1.0.0 Attempting to connect to SSID: HueNet_5G Connected! IP address: 192.168.2.152 @@ -757,7 +757,7 @@ The following are debug terminal output and screen shot when running example [** ``` Start MQTT_ThingStream on Rtlduino RTL8720DN with RTL8720DN -WiFiWebServer_RTL8720 v1.1.0 +WiFiWebServer_RTL8720 v1.1.1 Current Firmware Version = 1.0.0 Attempting to connect to SSID: HueNet_5G Connected! IP address: 192.168.2.152 @@ -787,7 +787,7 @@ The following are debug terminal output and screen shot when running example [** ``` Starting WiFiUdpNTPClient on Rtlduino RTL8720DN with RTL8720DN -WiFiWebServer_RTL8720 v1.1.0 +WiFiWebServer_RTL8720 v1.1.1 Current Firmware Version = 1.0.0 Attempting to connect to SSID: HueNet_5G Connected! IP address: 192.168.2.152 diff --git a/changelog.md b/changelog.md index e5741a3..ed4161e 100644 --- a/changelog.md +++ b/changelog.md @@ -12,6 +12,7 @@ ## Table of Contents * [Changelog](#changelog) + * [Releases v1.1.1](#releases-v111) * [Major Releases v1.1.0](#major-releases-v110) * [Releases v1.0.1](#releases-v101) * [Initial Releases v1.0.0](#initial-releases-v100) @@ -22,6 +23,10 @@ ## Changelog +#### Releases v1.1.1 + +1. Fix authenticate issue caused by libb64 + ### Major Releases v1.1.0 1. Fix bug related to usage of Arduino String diff --git a/library.json b/library.json index 2215cd1..04b51ea 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "WiFiWebServer_RTL8720", - "version": "1.1.0", + "version": "1.1.1", "keywords": "wifi, wi-fi, WebServer, RTL8720DN, RTL8722DM, RTM8722CSM, realtek, amebad-core, HTTP-Client, WebSocket-Client, server, client, websocket, mqtt, mqtt-client, thingstream, 5-GHz-WiFi, 5GHz-WiFi", "description": "Simple WiFiWebServer, HTTP Client, MQTT and WebSocket Client library for Realtek RTL8720DN, RTL8722DM, RTM8722CSM boards using WiFi. Supporting WiFi at 2.4GHz and 5GHz", "authors": @@ -31,6 +31,7 @@ "platforms": ["*"] } ], + "license": "MIT", "frameworks": "*", "platforms": "AmebaD", "examples": "examples/*/*/*.ino", diff --git a/library.properties b/library.properties index adc87e7..3744532 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=WiFiWebServer_RTL8720 -version=1.1.0 +version=1.1.1 author=Khoi Hoang license=MIT maintainer=Khoi Hoang diff --git a/src/Parsing_RTL8720-impl.h b/src/Parsing_RTL8720-impl.h index d31c8df..f0b474d 100644 --- a/src/Parsing_RTL8720-impl.h +++ b/src/Parsing_RTL8720-impl.h @@ -7,13 +7,14 @@ Built by Khoi Hoang https://github.com/khoih-prog/WiFiWebServer_RTL8720 Licensed under MIT license - Version: 1.1.0 + Version: 1.1.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 14/07/2021 Initial coding for Realtek RTL8720DN, RTL8722DM and RTL8722CSM 1.0.1 K Hoang 07/08/2021 Fix version typo 1.1.0 K Hoang 26/12/2021 Fix bug related to usage of Arduino String. Optimize code + 1.1.1 K Hoang 26/12/2021 Fix authenticate issue caused by libb64 ***************************************************************************************************************************************/ #pragma once diff --git a/src/RTL8720HttpClient.h b/src/RTL8720HttpClient.h index 6ab2404..50de79e 100644 --- a/src/RTL8720HttpClient.h +++ b/src/RTL8720HttpClient.h @@ -7,13 +7,14 @@ Built by Khoi Hoang https://github.com/khoih-prog/WiFiWebServer_RTL8720 Licensed under MIT license - Version: 1.1.0 + Version: 1.1.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 14/07/2021 Initial coding for Realtek RTL8720DN, RTL8722DM and RTL8722CSM 1.0.1 K Hoang 07/08/2021 Fix version typo 1.1.0 K Hoang 26/12/2021 Fix bug related to usage of Arduino String. Optimize code + 1.1.1 K Hoang 26/12/2021 Fix authenticate issue caused by libb64 *****************************************************************************************************************************/ // Library to simplify HTTP fetching on Arduino diff --git a/src/RTL8720_HTTPClient/RTL8720_HttpClient.cpp b/src/RTL8720_HTTPClient/RTL8720_HttpClient.cpp index c759187..ec8c42a 100644 --- a/src/RTL8720_HTTPClient/RTL8720_HttpClient.cpp +++ b/src/RTL8720_HTTPClient/RTL8720_HttpClient.cpp @@ -7,13 +7,14 @@ Built by Khoi Hoang https://github.com/khoih-prog/WiFiWebServer_RTL8720 Licensed under MIT license - Version: 1.1.0 + Version: 1.1.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 14/07/2021 Initial coding for Realtek RTL8720DN, RTL8722DM and RTL8722CSM 1.0.1 K Hoang 07/08/2021 Fix version typo 1.1.0 K Hoang 26/12/2021 Fix bug related to usage of Arduino String. Optimize code + 1.1.1 K Hoang 26/12/2021 Fix authenticate issue caused by libb64 *****************************************************************************************************************************/ // Class to simplify HTTP fetching on Arduino diff --git a/src/RTL8720_HTTPClient/RTL8720_HttpClient.h b/src/RTL8720_HTTPClient/RTL8720_HttpClient.h index d06be22..f6e41ee 100644 --- a/src/RTL8720_HTTPClient/RTL8720_HttpClient.h +++ b/src/RTL8720_HTTPClient/RTL8720_HttpClient.h @@ -7,13 +7,14 @@ Built by Khoi Hoang https://github.com/khoih-prog/WiFiWebServer_RTL8720 Licensed under MIT license - Version: 1.1.0 + Version: 1.1.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 14/07/2021 Initial coding for Realtek RTL8720DN, RTL8722DM and RTL8722CSM 1.0.1 K Hoang 07/08/2021 Fix version typo 1.1.0 K Hoang 26/12/2021 Fix bug related to usage of Arduino String. Optimize code + 1.1.1 K Hoang 26/12/2021 Fix authenticate issue caused by libb64 *****************************************************************************************************************************/ // Class to simplify HTTP fetching on Arduino diff --git a/src/RTL8720_HTTPClient/RTL8720_URLEncoder.cpp b/src/RTL8720_HTTPClient/RTL8720_URLEncoder.cpp index 36f2508..25dc5f3 100644 --- a/src/RTL8720_HTTPClient/RTL8720_URLEncoder.cpp +++ b/src/RTL8720_HTTPClient/RTL8720_URLEncoder.cpp @@ -7,13 +7,14 @@ Built by Khoi Hoang https://github.com/khoih-prog/WiFiWebServer_RTL8720 Licensed under MIT license - Version: 1.1.0 + Version: 1.1.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 14/07/2021 Initial coding for Realtek RTL8720DN, RTL8722DM and RTL8722CSM 1.0.1 K Hoang 07/08/2021 Fix version typo 1.1.0 K Hoang 26/12/2021 Fix bug related to usage of Arduino String. Optimize code + 1.1.1 K Hoang 26/12/2021 Fix authenticate issue caused by libb64 *****************************************************************************************************************************/ // Library to simplify HTTP fetching on Arduino diff --git a/src/RTL8720_HTTPClient/RTL8720_URLEncoder.h b/src/RTL8720_HTTPClient/RTL8720_URLEncoder.h index 7993fd2..5b097f1 100644 --- a/src/RTL8720_HTTPClient/RTL8720_URLEncoder.h +++ b/src/RTL8720_HTTPClient/RTL8720_URLEncoder.h @@ -7,13 +7,14 @@ Built by Khoi Hoang https://github.com/khoih-prog/WiFiWebServer_RTL8720 Licensed under MIT license - Version: 1.1.0 + Version: 1.1.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 14/07/2021 Initial coding for Realtek RTL8720DN, RTL8722DM and RTL8722CSM 1.0.1 K Hoang 07/08/2021 Fix version typo 1.1.0 K Hoang 26/12/2021 Fix bug related to usage of Arduino String. Optimize code + 1.1.1 K Hoang 26/12/2021 Fix authenticate issue caused by libb64 *****************************************************************************************************************************/ // Library to simplify HTTP fetching on Arduino diff --git a/src/RTL8720_HTTPClient/RTL8720_WebSocketClient.cpp b/src/RTL8720_HTTPClient/RTL8720_WebSocketClient.cpp index 19dfc71..28a07f2 100644 --- a/src/RTL8720_HTTPClient/RTL8720_WebSocketClient.cpp +++ b/src/RTL8720_HTTPClient/RTL8720_WebSocketClient.cpp @@ -7,13 +7,14 @@ Built by Khoi Hoang https://github.com/khoih-prog/WiFiWebServer_RTL8720 Licensed under MIT license - Version: 1.1.0 + Version: 1.1.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 14/07/2021 Initial coding for Realtek RTL8720DN, RTL8722DM and RTL8722CSM 1.0.1 K Hoang 07/08/2021 Fix version typo 1.1.0 K Hoang 26/12/2021 Fix bug related to usage of Arduino String. Optimize code + 1.1.1 K Hoang 26/12/2021 Fix authenticate issue caused by libb64 *****************************************************************************************************************************/ // (c) Copyright Arduino. 2016 diff --git a/src/RTL8720_HTTPClient/RTL8720_WebSocketClient.h b/src/RTL8720_HTTPClient/RTL8720_WebSocketClient.h index 5bbb85d..21c6558 100644 --- a/src/RTL8720_HTTPClient/RTL8720_WebSocketClient.h +++ b/src/RTL8720_HTTPClient/RTL8720_WebSocketClient.h @@ -7,13 +7,14 @@ Built by Khoi Hoang https://github.com/khoih-prog/WiFiWebServer_RTL8720 Licensed under MIT license - Version: 1.1.0 + Version: 1.1.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 14/07/2021 Initial coding for Realtek RTL8720DN, RTL8722DM and RTL8722CSM 1.0.1 K Hoang 07/08/2021 Fix version typo 1.1.0 K Hoang 26/12/2021 Fix bug related to usage of Arduino String. Optimize code + 1.1.1 K Hoang 26/12/2021 Fix authenticate issue caused by libb64 *****************************************************************************************************************************/ // (c) Copyright Arduino. 2016 diff --git a/src/WiFiWebServer_RTL8720-impl.h b/src/WiFiWebServer_RTL8720-impl.h index 97698a7..a8aa5f7 100644 --- a/src/WiFiWebServer_RTL8720-impl.h +++ b/src/WiFiWebServer_RTL8720-impl.h @@ -7,13 +7,14 @@ Built by Khoi Hoang https://github.com/khoih-prog/WiFiWebServer_RTL8720 Licensed under MIT license - Version: 1.1.0 + Version: 1.1.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 14/07/2021 Initial coding for Realtek RTL8720DN, RTL8722DM and RTL8722CSM 1.0.1 K Hoang 07/08/2021 Fix version typo 1.1.0 K Hoang 26/12/2021 Fix bug related to usage of Arduino String. Optimize code + 1.1.1 K Hoang 26/12/2021 Fix authenticate issue caused by libb64 ***************************************************************************************************************************************/ #pragma once @@ -252,7 +253,7 @@ void WiFiWebServer::handleClient() delay(1); } - // KH, fix bug. Have to close the connection + // KH, fix bug. Have to close the connection. _currentClient.stop(); WS_LOGDEBUG(F("handleClient: Client disconnected")); } @@ -368,7 +369,7 @@ void WiFiWebServer::handleClient() stopClient: - // KH, fix bug. Have to close the connection + // KH, fix bug. Have to close the connection. _currentClient.stop(); WS_LOGDEBUG(F("handleClient: Client disconnected")); } diff --git a/src/WiFiWebServer_RTL8720.h b/src/WiFiWebServer_RTL8720.h index da4d876..f765caa 100644 --- a/src/WiFiWebServer_RTL8720.h +++ b/src/WiFiWebServer_RTL8720.h @@ -7,13 +7,14 @@ Built by Khoi Hoang https://github.com/khoih-prog/WiFiWebServer_RTL8720 Licensed under MIT license - Version: 1.1.0 + Version: 1.1.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 14/07/2021 Initial coding for Realtek RTL8720DN, RTL8722DM and RTL8722CSM 1.0.1 K Hoang 07/08/2021 Fix version typo 1.1.0 K Hoang 26/12/2021 Fix bug related to usage of Arduino String. Optimize code + 1.1.1 K Hoang 26/12/2021 Fix authenticate issue caused by libb64 ***************************************************************************************************************************************/ #pragma once @@ -21,13 +22,13 @@ #ifndef WiFiWebServer_RTL8720_h #define WiFiWebServer_RTL8720_h -#define WIFI_WEBSERVER_RTL8720_VERSION "WiFiWebServer_RTL8720 v1.1.0" +#define WIFI_WEBSERVER_RTL8720_VERSION "WiFiWebServer_RTL8720 v1.1.1" #define WIFI_WEBSERVER_RTL8720_VERSION_MAJOR 1 #define WIFI_WEBSERVER_RTL8720_VERSION_MINOR 1 -#define WIFI_WEBSERVER_RTL8720_VERSION_PATCH 0 +#define WIFI_WEBSERVER_RTL8720_VERSION_PATCH 1 -#define WIFI_WEBSERVER_RTL8720_VERSION_IN 1001000 +#define WIFI_WEBSERVER_RTL8720_VERSION_IN 1001001 #define USE_NEW_WEBSERVER_VERSION true diff --git a/src/libb64/base64.cpp b/src/libb64/base64.cpp index 0afd4e2..05c75a5 100644 --- a/src/libb64/base64.cpp +++ b/src/libb64/base64.cpp @@ -8,13 +8,14 @@ Built by Khoi Hoang https://github.com/khoih-prog/WiFiWebServer_RTL8720 Licensed under MIT license - Version: 1.1.0 + Version: 1.1.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 14/07/2021 Initial coding for Realtek RTL8720DN, RTL8722DM and RTL8722CSM 1.0.1 K Hoang 07/08/2021 Fix version typo 1.1.0 K Hoang 26/12/2021 Fix bug related to usage of Arduino String. Optimize code + 1.1.1 K Hoang 26/12/2021 Fix authenticate issue caused by libb64 *****************************************************************************************************************************/ #include "base64.h" diff --git a/src/libb64/base64.h b/src/libb64/base64.h index 9437a14..3bd49d5 100644 --- a/src/libb64/base64.h +++ b/src/libb64/base64.h @@ -8,13 +8,14 @@ Built by Khoi Hoang https://github.com/khoih-prog/WiFiWebServer_RTL8720 Licensed under MIT license - Version: 1.1.0 + Version: 1.1.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 14/07/2021 Initial coding for Realtek RTL8720DN, RTL8722DM and RTL8722CSM 1.0.1 K Hoang 07/08/2021 Fix version typo 1.1.0 K Hoang 26/12/2021 Fix bug related to usage of Arduino String. Optimize code + 1.1.1 K Hoang 26/12/2021 Fix authenticate issue caused by libb64 *****************************************************************************************************************************/ #pragma once diff --git a/src/libb64/cdecode.c b/src/libb64/cdecode.c index fe1d224..14adaf8 100644 --- a/src/libb64/cdecode.c +++ b/src/libb64/cdecode.c @@ -7,36 +7,35 @@ Built by Khoi Hoang https://github.com/khoih-prog/WiFiWebServer_RTL8720 Licensed under MIT license - Version: 1.1.0 + Version: 1.1.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 14/07/2021 Initial coding for Realtek RTL8720DN, RTL8722DM and RTL8722CSM 1.0.1 K Hoang 07/08/2021 Fix version typo 1.1.0 K Hoang 26/12/2021 Fix bug related to usage of Arduino String. Optimize code + 1.1.1 K Hoang 26/12/2021 Fix authenticate issue caused by libb64 ***************************************************************************************************************************************/ #include #include "cdecode.h" - -static int base64_decode_value_signed(int8_t value_in) +int base64_decode_value(int value_in) { static const char decoding[] = - { 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, - -1, -1, -1, -2, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, - -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, - 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 + { 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -2, -1, -1, -1, 0, 1, 2, + 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, + -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, + 47, 48, 49, 50, 51 }; - static const int8_t decoding_size = sizeof(decoding); + static const char decoding_size = sizeof(decoding); value_in -= 43; if (value_in < 0 || value_in > decoding_size) return -1; - return (int) ( &decoding[(int)value_in] ); + return decoding[(int)value_in]; } void base64_init_decodestate(base64_decodestate* state_in) @@ -45,11 +44,11 @@ void base64_init_decodestate(base64_decodestate* state_in) state_in->plainchar = 0; } -static int base64_decode_block_signed(const int8_t* code_in, const int length_in, int8_t* plaintext_out, base64_decodestate* state_in) +int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in) { - const int8_t* codechar = code_in; - int8_t* plainchar = plaintext_out; - int8_t fragment; + const char* codechar = code_in; + char* plainchar = plaintext_out; + int fragment; *plainchar = state_in->plainchar; @@ -67,11 +66,13 @@ static int base64_decode_block_signed(const int8_t* code_in, const int length_in return plainchar - plaintext_out; } - fragment = (int8_t)base64_decode_value_signed(*codechar++); + fragment = base64_decode_value(*codechar++); } while (fragment < 0); *plainchar = (fragment & 0x03f) << 2; - // falls through + + // fall through + case step_b: do { @@ -82,12 +83,14 @@ static int base64_decode_block_signed(const int8_t* code_in, const int length_in return plainchar - plaintext_out; } - fragment = (int8_t)base64_decode_value_signed(*codechar++); + fragment = base64_decode_value(*codechar++); } while (fragment < 0); *plainchar++ |= (fragment & 0x030) >> 4; *plainchar = (fragment & 0x00f) << 4; - // falls through + + // fall through + case step_c: do { @@ -98,12 +101,14 @@ static int base64_decode_block_signed(const int8_t* code_in, const int length_in return plainchar - plaintext_out; } - fragment = (int8_t)base64_decode_value_signed(*codechar++); + fragment = base64_decode_value(*codechar++); } while (fragment < 0); *plainchar++ |= (fragment & 0x03c) >> 2; *plainchar = (fragment & 0x003) << 6; - // falls through + + // fall through + case step_d: do { @@ -113,22 +118,25 @@ static int base64_decode_block_signed(const int8_t* code_in, const int length_in state_in->plainchar = *plainchar; return plainchar - plaintext_out; } - fragment = (int8_t)base64_decode_value_signed(*codechar++); + + fragment = base64_decode_value(*codechar++); } while (fragment < 0); *plainchar++ |= (fragment & 0x03f); + + // fall through } } + /* control should not reach here */ return plainchar - plaintext_out; } -static int base64_decode_chars_signed(const int8_t* code_in, const int length_in, int8_t* plaintext_out) -{ +int base64_decode_chars(const char* code_in, const int length_in, char* plaintext_out) { + base64_decodestate _state; base64_init_decodestate(&_state); - - int len = base64_decode_block_signed(code_in, length_in, plaintext_out, &_state); + int len = base64_decode_block(code_in, length_in, plaintext_out, &_state); if (len > 0) plaintext_out[len] = 0; @@ -136,18 +144,3 @@ static int base64_decode_chars_signed(const int8_t* code_in, const int length_in return len; } -int base64_decode_value(char value_in) -{ - return base64_decode_value_signed(*((int8_t *) &value_in)); -} - -int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in) -{ - return base64_decode_block_signed((int8_t *) code_in, length_in, (int8_t *) plaintext_out, state_in); -} - -int base64_decode_chars(const char* code_in, const int length_in, char* plaintext_out) -{ - return base64_decode_chars_signed((int8_t *) code_in, length_in, (int8_t *) plaintext_out); -} - diff --git a/src/libb64/cdecode.h b/src/libb64/cdecode.h index 1a3e776..91d6ed2 100644 --- a/src/libb64/cdecode.h +++ b/src/libb64/cdecode.h @@ -7,13 +7,14 @@ Built by Khoi Hoang https://github.com/khoih-prog/WiFiWebServer_RTL8720 Licensed under MIT license - Version: 1.1.0 + Version: 1.1.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 14/07/2021 Initial coding for Realtek RTL8720DN, RTL8722DM and RTL8722CSM 1.0.1 K Hoang 07/08/2021 Fix version typo 1.1.0 K Hoang 26/12/2021 Fix bug related to usage of Arduino String. Optimize code + 1.1.1 K Hoang 26/12/2021 Fix authenticate issue caused by libb64 ***************************************************************************************************************************************/ #pragma once @@ -26,15 +27,12 @@ #define base64_decode_expected_len(n) ((n * 3) / 4) #ifdef __cplusplus - extern "C" { +extern "C" { #endif typedef enum { - step_a, - step_b, - step_c, - step_d + step_a, step_b, step_c, step_d } base64_decodestep; typedef struct @@ -45,14 +43,14 @@ typedef struct void base64_init_decodestate(base64_decodestate* state_in); -int base64_decode_value(char value_in); +int base64_decode_value(int value_in); int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in); int base64_decode_chars(const char* code_in, const int length_in, char* plaintext_out); #ifdef __cplusplus - } // extern "C" +} // extern "C" #endif #endif /* BASE64_CDECODE_H */ diff --git a/src/libb64/cencode.c b/src/libb64/cencode.c index a8384d9..499b09c 100644 --- a/src/libb64/cencode.c +++ b/src/libb64/cencode.c @@ -7,47 +7,35 @@ Built by Khoi Hoang https://github.com/khoih-prog/WiFiWebServer_RTL8720 Licensed under MIT license - Version: 1.1.0 + Version: 1.1.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 14/07/2021 Initial coding for Realtek RTL8720DN, RTL8722DM and RTL8722CSM 1.0.1 K Hoang 07/08/2021 Fix version typo 1.1.0 K Hoang 26/12/2021 Fix bug related to usage of Arduino String. Optimize code + 1.1.1 K Hoang 26/12/2021 Fix authenticate issue caused by libb64 ***************************************************************************************************************************************/ #include "cencode.h" +const int CHARS_PER_LINE = 72; + void base64_init_encodestate(base64_encodestate* state_in) { state_in->step = step_A; state_in->result = 0; state_in->stepcount = 0; - state_in->stepsnewline = BASE64_CHARS_PER_LINE; } - -void base64_init_encodestate_nonewlines(base64_encodestate* state_in) +char base64_encode_value(char value_in) { - base64_init_encodestate(state_in); - state_in->stepsnewline = -1; -} + static const char* encoding = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -char base64_encode_value(const char n) -{ - char r; - - if (n < 26) - r = n + 'A'; - else if (n < 26 + 26) - r = n - 26 + 'a'; - else if (n < 26 + 26 + 10 ) - r = n - 26 - 26 + '0'; - else if (n == 62 ) - r = '+'; - else - r = '/'; - return r; + if (value_in > 63) + return '='; + + return encoding[(unsigned int)value_in]; } int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in) @@ -76,7 +64,9 @@ int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, result = (fragment & 0x0fc) >> 2; *codechar++ = base64_encode_value(result); result = (fragment & 0x003) << 4; - // falls through + + // fall through + case step_B: if (plainchar == plaintextend) { @@ -89,7 +79,9 @@ int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, result |= (fragment & 0x0f0) >> 4; *codechar++ = base64_encode_value(result); result = (fragment & 0x00f) << 2; - // falls through + + // fall through + case step_C: if (plainchar == plaintextend) { @@ -106,11 +98,13 @@ int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, ++(state_in->stepcount); - if ((state_in->stepcount == BASE64_CHARS_PER_LINE / 4) && (state_in->stepsnewline > 0)) + if (state_in->stepcount == CHARS_PER_LINE / 4) { *codechar++ = '\n'; state_in->stepcount = 0; } + + // fall through } } @@ -146,7 +140,6 @@ int base64_encode_chars(const char* plaintext_in, int length_in, char* code_out) { base64_encodestate _state; base64_init_encodestate(&_state); - int len = base64_encode_block(plaintext_in, length_in, code_out, &_state); return len + base64_encode_blockend((code_out + len), &_state); diff --git a/src/libb64/cencode.h b/src/libb64/cencode.h index 98a12e8..8b9e3d5 100644 --- a/src/libb64/cencode.h +++ b/src/libb64/cencode.h @@ -7,13 +7,14 @@ Built by Khoi Hoang https://github.com/khoih-prog/WiFiWebServer_RTL8720 Licensed under MIT license - Version: 1.1.0 + Version: 1.1.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 14/07/2021 Initial coding for Realtek RTL8720DN, RTL8722DM and RTL8722CSM 1.0.1 K Hoang 07/08/2021 Fix version typo 1.1.0 K Hoang 26/12/2021 Fix bug related to usage of Arduino String. Optimize code + 1.1.1 K Hoang 26/12/2021 Fix authenticate issue caused by libb64 ***************************************************************************************************************************************/ #pragma once @@ -23,22 +24,15 @@ #ifndef BASE64_CENCODE_H #define BASE64_CENCODE_H -#define BASE64_CHARS_PER_LINE 72 - -#define base64_encode_expected_len_nonewlines(n) ((((4 * (n)) / 3) + 3) & ~3) -#define base64_encode_expected_len(n) \ - (base64_encode_expected_len_nonewlines(n) + ((n / ((BASE64_CHARS_PER_LINE * 3) / 4)) + 1)) - +#define base64_encode_expected_len(n) ((((4 * n) / 3) + 3) & ~3) #ifdef __cplusplus - extern "C" { +extern "C" { #endif typedef enum { - step_A, - step_B, - step_C + step_A, step_B, step_C } base64_encodestep; typedef struct @@ -46,11 +40,9 @@ typedef struct base64_encodestep step; char result; int stepcount; - int stepsnewline; } base64_encodestate; void base64_init_encodestate(base64_encodestate* state_in); -void base64_init_encodestate_nonewlines(base64_encodestate* state_in); char base64_encode_value(char value_in); @@ -61,7 +53,7 @@ int base64_encode_blockend(char* code_out, base64_encodestate* state_in); int base64_encode_chars(const char* plaintext_in, int length_in, char* code_out); #ifdef __cplusplus - } // extern "C" +} // extern "C" #endif #endif /* BASE64_CENCODE_H */ diff --git a/src/utility/RequestHandler.h b/src/utility/RequestHandler.h index a7b41d3..d7587ff 100644 --- a/src/utility/RequestHandler.h +++ b/src/utility/RequestHandler.h @@ -7,13 +7,14 @@ Built by Khoi Hoang https://github.com/khoih-prog/WiFiWebServer_RTL8720 Licensed under MIT license - Version: 1.1.0 + Version: 1.1.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 14/07/2021 Initial coding for Realtek RTL8720DN, RTL8722DM and RTL8722CSM 1.0.1 K Hoang 07/08/2021 Fix version typo 1.1.0 K Hoang 26/12/2021 Fix bug related to usage of Arduino String. Optimize code + 1.1.1 K Hoang 26/12/2021 Fix authenticate issue caused by libb64 ***************************************************************************************************************************************/ #pragma once diff --git a/src/utility/RequestHandlersImpl.h b/src/utility/RequestHandlersImpl.h index 0e14604..67b701a 100644 --- a/src/utility/RequestHandlersImpl.h +++ b/src/utility/RequestHandlersImpl.h @@ -7,13 +7,14 @@ Built by Khoi Hoang https://github.com/khoih-prog/WiFiWebServer_RTL8720 Licensed under MIT license - Version: 1.1.0 + Version: 1.1.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 14/07/2021 Initial coding for Realtek RTL8720DN, RTL8722DM and RTL8722CSM 1.0.1 K Hoang 07/08/2021 Fix version typo 1.1.0 K Hoang 26/12/2021 Fix bug related to usage of Arduino String. Optimize code + 1.1.1 K Hoang 26/12/2021 Fix authenticate issue caused by libb64 ***************************************************************************************************************************************/ #pragma once diff --git a/src/utility/RingBuffer.cpp b/src/utility/RingBuffer.cpp index f817852..2679779 100644 --- a/src/utility/RingBuffer.cpp +++ b/src/utility/RingBuffer.cpp @@ -7,13 +7,14 @@ Built by Khoi Hoang https://github.com/khoih-prog/WiFiWebServer_RTL8720 Licensed under MIT license - Version: 1.1.0 + Version: 1.1.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 14/07/2021 Initial coding for Realtek RTL8720DN, RTL8722DM and RTL8722CSM 1.0.1 K Hoang 07/08/2021 Fix version typo 1.1.0 K Hoang 26/12/2021 Fix bug related to usage of Arduino String. Optimize code + 1.1.1 K Hoang 26/12/2021 Fix authenticate issue caused by libb64 ***************************************************************************************************************************************/ #include "RingBuffer.h" diff --git a/src/utility/RingBuffer.h b/src/utility/RingBuffer.h index 1d1abb5..9649572 100644 --- a/src/utility/RingBuffer.h +++ b/src/utility/RingBuffer.h @@ -7,13 +7,14 @@ Built by Khoi Hoang https://github.com/khoih-prog/WiFiWebServer_RTL8720 Licensed under MIT license - Version: 1.1.0 + Version: 1.1.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 14/07/2021 Initial coding for Realtek RTL8720DN, RTL8722DM and RTL8722CSM 1.0.1 K Hoang 07/08/2021 Fix version typo 1.1.0 K Hoang 26/12/2021 Fix bug related to usage of Arduino String. Optimize code + 1.1.1 K Hoang 26/12/2021 Fix authenticate issue caused by libb64 ***************************************************************************************************************************************/ #pragma once diff --git a/src/utility/WiFiDebug.h b/src/utility/WiFiDebug.h index 14c4aac..ea6b523 100644 --- a/src/utility/WiFiDebug.h +++ b/src/utility/WiFiDebug.h @@ -7,13 +7,14 @@ Built by Khoi Hoang https://github.com/khoih-prog/WiFiWebServer_RTL8720 Licensed under MIT license - Version: 1.1.0 + Version: 1.1.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 14/07/2021 Initial coding for Realtek RTL8720DN, RTL8722DM and RTL8722CSM 1.0.1 K Hoang 07/08/2021 Fix version typo 1.1.0 K Hoang 26/12/2021 Fix bug related to usage of Arduino String. Optimize code + 1.1.1 K Hoang 26/12/2021 Fix authenticate issue caused by libb64 ***************************************************************************************************************************************/ #pragma once diff --git a/src/utility/mimetable.h b/src/utility/mimetable.h index be3bf1f..aef9944 100644 --- a/src/utility/mimetable.h +++ b/src/utility/mimetable.h @@ -7,13 +7,14 @@ Built by Khoi Hoang https://github.com/khoih-prog/WiFiWebServer_RTL8720 Licensed under MIT license - Version: 1.1.0 + Version: 1.1.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K Hoang 14/07/2021 Initial coding for Realtek RTL8720DN, RTL8722DM and RTL8722CSM 1.0.1 K Hoang 07/08/2021 Fix version typo 1.1.0 K Hoang 26/12/2021 Fix bug related to usage of Arduino String. Optimize code + 1.1.1 K Hoang 26/12/2021 Fix authenticate issue caused by libb64 ***************************************************************************************************************************************/ #pragma once