mirror of
https://github.com/espressif/esp-idf
synced 2025-03-10 01:29:21 -04:00
Merge branch 'bugfix/debug_logs_cleanup' into 'master'
Bugfix/debug logs cleanup See merge request espressif/esp-idf!6209
This commit is contained in:
commit
7e3676f307
@ -16,17 +16,26 @@
|
|||||||
#include "utils/common.h"
|
#include "utils/common.h"
|
||||||
#include "utils/wpa_debug.h"
|
#include "utils/wpa_debug.h"
|
||||||
|
|
||||||
static inline int _wpa_snprintf_hex(char *buf, size_t buf_size, const u8 *data, size_t len, int uppercase)
|
static inline int
|
||||||
|
_wpa_snprintf_hex(char *buf, size_t buf_size, const u8 *data, size_t len,
|
||||||
|
int uppercase, int whitespace)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
char *pos = buf, *end = buf + buf_size;
|
char *pos = buf, *end = buf + buf_size;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
static const char *fmt_upper = "%02X";
|
||||||
|
static const char *fmt_lower = "%02x";
|
||||||
|
static const char *fmt_upper_ws = "%02X ";
|
||||||
|
static const char *fmt_lower_ws = "%02x ";
|
||||||
|
const char *fmt = uppercase ? (whitespace ? fmt_upper_ws : fmt_upper) :
|
||||||
|
(whitespace ? fmt_lower_ws : fmt_lower);
|
||||||
|
|
||||||
if (buf_size == 0)
|
if (buf_size == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
ret = snprintf(pos, end - pos, uppercase? "%02X":"%02x", data[i]);
|
ret = snprintf(pos, end - pos, fmt, data[i]);
|
||||||
if (ret < 0 || ret >= end - pos) {
|
if (ret < 0 || ret >= end - pos) {
|
||||||
end[-1] = '\0';
|
end[-1] = '\0';
|
||||||
return pos - buf;
|
return pos - buf;
|
||||||
@ -39,25 +48,31 @@ static inline int _wpa_snprintf_hex(char *buf, size_t buf_size, const u8 *data,
|
|||||||
|
|
||||||
int wpa_snprintf_hex_uppercase(char *buf, size_t buf_size, const u8 *data, size_t len)
|
int wpa_snprintf_hex_uppercase(char *buf, size_t buf_size, const u8 *data, size_t len)
|
||||||
{
|
{
|
||||||
return _wpa_snprintf_hex(buf, buf_size, data, len, 1);
|
return _wpa_snprintf_hex(buf, buf_size, data, len, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int wpa_snprintf_hex(char *buf, size_t buf_size, const u8 *data, size_t len)
|
int wpa_snprintf_hex(char *buf, size_t buf_size, const u8 *data, size_t len)
|
||||||
{
|
{
|
||||||
return _wpa_snprintf_hex(buf, buf_size, data, len, 0);
|
return _wpa_snprintf_hex(buf, buf_size, data, len, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_PRINT
|
#ifdef DEBUG_PRINT
|
||||||
void wpa_dump_mem(char* desc, uint8_t *addr, uint16_t len)
|
void wpa_dump_mem(char* desc, uint8_t *addr, uint16_t len)
|
||||||
{
|
{
|
||||||
|
char output[50];
|
||||||
wpa_printf(MSG_DEBUG, "%s\n", desc);
|
wpa_printf(MSG_DEBUG, "%s\n", desc);
|
||||||
if (addr){
|
if (addr){
|
||||||
uint16_t i=0;
|
uint16_t i=0;
|
||||||
for (i=0; i<len; i++){
|
for (i = 0; i < len / 16; i++) {
|
||||||
if (i%16==0) wpa_printf(MSG_DEBUG, "\n");
|
_wpa_snprintf_hex(output, 50, addr + i * 16, 16, 0, 1);
|
||||||
wpa_printf(MSG_DEBUG, "%02x ", addr[i]);
|
wpa_printf(MSG_DEBUG, "%s", output);
|
||||||
|
}
|
||||||
|
if (len % 16) {
|
||||||
|
int bytes_printed = (len / 16) * 16;
|
||||||
|
_wpa_snprintf_hex(output, 50, addr + bytes_printed,
|
||||||
|
len - bytes_printed, 0, 1);
|
||||||
|
wpa_printf(MSG_DEBUG, "%s", output);
|
||||||
}
|
}
|
||||||
wpa_printf(MSG_DEBUG, "\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,21 +89,26 @@ void wpa_hexdump(int level, const char *title, const u8 *buf, size_t len)
|
|||||||
{
|
{
|
||||||
#ifdef DEBUG_PRINT
|
#ifdef DEBUG_PRINT
|
||||||
size_t i;
|
size_t i;
|
||||||
|
char output[50];
|
||||||
|
|
||||||
if (level < MSG_MSGDUMP)
|
if (level < MSG_MSGDUMP)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wpa_printf(MSG_DEBUG, "%s - hexdump(len=%lu):\n", title, (unsigned long) len);
|
wpa_printf(MSG_DEBUG, "%s - hexdump(len=%lu):", title, (unsigned long) len);
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
wpa_printf(MSG_DEBUG, " [NULL]\n");
|
wpa_printf(MSG_DEBUG, " [NULL]");
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len / 16; i++) {
|
||||||
wpa_printf(MSG_DEBUG, " %02x", buf[i]);
|
_wpa_snprintf_hex(output, 50, buf + i * 16, 16, 0, 1);
|
||||||
if((i+1) % 16 == 0)
|
wpa_printf(MSG_DEBUG, "%s", output);
|
||||||
wpa_printf(MSG_DEBUG, "\n");
|
}
|
||||||
|
if (len % 16) {
|
||||||
|
int bytes_printed = (len / 16) * 16;
|
||||||
|
_wpa_snprintf_hex(output, 50, buf + bytes_printed,
|
||||||
|
len - bytes_printed, 0, 1);
|
||||||
|
wpa_printf(MSG_DEBUG, "%s", output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wpa_printf(MSG_DEBUG, "\n");
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,12 +6,28 @@ menu "Example Configuration"
|
|||||||
help
|
help
|
||||||
SSID (network name) for the example to connect to.
|
SSID (network name) for the example to connect to.
|
||||||
|
|
||||||
config EXAMPLE_EAP_METHOD
|
config EXAMPLE_VALIDATE_SERVER_CERT
|
||||||
int "EAP METHOD"
|
bool "Validate server"
|
||||||
default 1
|
default y
|
||||||
help
|
help
|
||||||
EAP method (TLS, PEAP or TTLS) for the example to use.
|
Validate the servers' certificate using CA cert.
|
||||||
TLS: 0, PEAP: 1, TTLS: 2
|
|
||||||
|
choice
|
||||||
|
prompt "EAP method for the example to use"
|
||||||
|
default EXAMPLE_EAP_METHOD_PEAP
|
||||||
|
config EXAMPLE_EAP_METHOD_TLS
|
||||||
|
bool "TLS"
|
||||||
|
config EXAMPLE_EAP_METHOD_PEAP
|
||||||
|
bool "PEAP"
|
||||||
|
config EXAMPLE_EAP_METHOD_TTLS
|
||||||
|
bool "TTLS"
|
||||||
|
endchoice
|
||||||
|
|
||||||
|
config EXAMPLE_EAP_METHOD
|
||||||
|
int
|
||||||
|
default 0 if EXAMPLE_EAP_METHOD_TLS
|
||||||
|
default 1 if EXAMPLE_EAP_METHOD_PEAP
|
||||||
|
default 2 if EXAMPLE_EAP_METHOD_TTLS
|
||||||
|
|
||||||
config EXAMPLE_EAP_ID
|
config EXAMPLE_EAP_ID
|
||||||
string "EAP ID"
|
string "EAP ID"
|
||||||
@ -21,12 +37,14 @@ menu "Example Configuration"
|
|||||||
|
|
||||||
config EXAMPLE_EAP_USERNAME
|
config EXAMPLE_EAP_USERNAME
|
||||||
string "EAP USERNAME"
|
string "EAP USERNAME"
|
||||||
|
depends on EXAMPLE_EAP_METHOD_PEAP || EXAMPLE_EAP_METHOD_TTLS
|
||||||
default "espressif"
|
default "espressif"
|
||||||
help
|
help
|
||||||
Username for EAP method (PEAP and TTLS).
|
Username for EAP method (PEAP and TTLS).
|
||||||
|
|
||||||
config EXAMPLE_EAP_PASSWORD
|
config EXAMPLE_EAP_PASSWORD
|
||||||
string "EAP PASSWORD"
|
string "EAP PASSWORD"
|
||||||
|
depends on EXAMPLE_EAP_METHOD_PEAP || EXAMPLE_EAP_METHOD_TTLS
|
||||||
default "test11"
|
default "test11"
|
||||||
help
|
help
|
||||||
Password for EAP method (PEAP and TTLS).
|
Password for EAP method (PEAP and TTLS).
|
||||||
|
@ -53,10 +53,6 @@ static EventGroupHandle_t wifi_event_group;
|
|||||||
to the AP with an IP? */
|
to the AP with an IP? */
|
||||||
const int CONNECTED_BIT = BIT0;
|
const int CONNECTED_BIT = BIT0;
|
||||||
|
|
||||||
/* Constants that aren't configurable in menuconfig */
|
|
||||||
#define EAP_PEAP 1
|
|
||||||
#define EAP_TTLS 2
|
|
||||||
|
|
||||||
static const char *TAG = "example";
|
static const char *TAG = "example";
|
||||||
|
|
||||||
/* CA cert, taken from wpa2_ca.pem
|
/* CA cert, taken from wpa2_ca.pem
|
||||||
@ -69,12 +65,17 @@ static const char *TAG = "example";
|
|||||||
To embed it in the app binary, the PEM, CRT and KEY file is named
|
To embed it in the app binary, the PEM, CRT and KEY file is named
|
||||||
in the component.mk COMPONENT_EMBED_TXTFILES variable.
|
in the component.mk COMPONENT_EMBED_TXTFILES variable.
|
||||||
*/
|
*/
|
||||||
|
#ifdef CONFIG_EXAMPLE_VALIDATE_SERVER_CERT
|
||||||
extern uint8_t ca_pem_start[] asm("_binary_wpa2_ca_pem_start");
|
extern uint8_t ca_pem_start[] asm("_binary_wpa2_ca_pem_start");
|
||||||
extern uint8_t ca_pem_end[] asm("_binary_wpa2_ca_pem_end");
|
extern uint8_t ca_pem_end[] asm("_binary_wpa2_ca_pem_end");
|
||||||
|
#endif /* CONFIG_EXAMPLE_VALIDATE_SERVER_CERT */
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLE_EAP_METHOD_TLS
|
||||||
extern uint8_t client_crt_start[] asm("_binary_wpa2_client_crt_start");
|
extern uint8_t client_crt_start[] asm("_binary_wpa2_client_crt_start");
|
||||||
extern uint8_t client_crt_end[] asm("_binary_wpa2_client_crt_end");
|
extern uint8_t client_crt_end[] asm("_binary_wpa2_client_crt_end");
|
||||||
extern uint8_t client_key_start[] asm("_binary_wpa2_client_key_start");
|
extern uint8_t client_key_start[] asm("_binary_wpa2_client_key_start");
|
||||||
extern uint8_t client_key_end[] asm("_binary_wpa2_client_key_end");
|
extern uint8_t client_key_end[] asm("_binary_wpa2_client_key_end");
|
||||||
|
#endif /* CONFIG_EXAMPLE_EAP_METHOD_TLS */
|
||||||
|
|
||||||
static void event_handler(void* arg, esp_event_base_t event_base,
|
static void event_handler(void* arg, esp_event_base_t event_base,
|
||||||
int32_t event_id, void* event_data)
|
int32_t event_id, void* event_data)
|
||||||
@ -91,9 +92,14 @@ static void event_handler(void* arg, esp_event_base_t event_base,
|
|||||||
|
|
||||||
static void initialise_wifi(void)
|
static void initialise_wifi(void)
|
||||||
{
|
{
|
||||||
|
#ifdef CONFIG_EXAMPLE_VALIDATE_SERVER_CERT
|
||||||
unsigned int ca_pem_bytes = ca_pem_end - ca_pem_start;
|
unsigned int ca_pem_bytes = ca_pem_end - ca_pem_start;
|
||||||
|
#endif /* CONFIG_EXAMPLE_VALIDATE_SERVER_CERT */
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLE_EAP_METHOD_TLS
|
||||||
unsigned int client_crt_bytes = client_crt_end - client_crt_start;
|
unsigned int client_crt_bytes = client_crt_end - client_crt_start;
|
||||||
unsigned int client_key_bytes = client_key_end - client_key_start;
|
unsigned int client_key_bytes = client_key_end - client_key_start;
|
||||||
|
#endif /* CONFIG_EXAMPLE_EAP_METHOD_TLS */
|
||||||
|
|
||||||
tcpip_adapter_init();
|
tcpip_adapter_init();
|
||||||
wifi_event_group = xEventGroupCreate();
|
wifi_event_group = xEventGroupCreate();
|
||||||
@ -111,14 +117,21 @@ static void initialise_wifi(void)
|
|||||||
ESP_LOGI(TAG, "Setting WiFi configuration SSID %s...", wifi_config.sta.ssid);
|
ESP_LOGI(TAG, "Setting WiFi configuration SSID %s...", wifi_config.sta.ssid);
|
||||||
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
|
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
|
||||||
ESP_ERROR_CHECK( esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) );
|
ESP_ERROR_CHECK( esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) );
|
||||||
|
ESP_ERROR_CHECK( esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)EXAMPLE_EAP_ID, strlen(EXAMPLE_EAP_ID)) );
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLE_VALIDATE_SERVER_CERT
|
||||||
ESP_ERROR_CHECK( esp_wifi_sta_wpa2_ent_set_ca_cert(ca_pem_start, ca_pem_bytes) );
|
ESP_ERROR_CHECK( esp_wifi_sta_wpa2_ent_set_ca_cert(ca_pem_start, ca_pem_bytes) );
|
||||||
|
#endif /* CONFIG_EXAMPLE_VALIDATE_SERVER_CERT */
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLE_EAP_METHOD_TLS
|
||||||
ESP_ERROR_CHECK( esp_wifi_sta_wpa2_ent_set_cert_key(client_crt_start, client_crt_bytes,\
|
ESP_ERROR_CHECK( esp_wifi_sta_wpa2_ent_set_cert_key(client_crt_start, client_crt_bytes,\
|
||||||
client_key_start, client_key_bytes, NULL, 0) );
|
client_key_start, client_key_bytes, NULL, 0) );
|
||||||
ESP_ERROR_CHECK( esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)EXAMPLE_EAP_ID, strlen(EXAMPLE_EAP_ID)) );
|
#endif /* CONFIG_EXAMPLE_EAP_METHOD_TLS */
|
||||||
if (EXAMPLE_EAP_METHOD == EAP_PEAP || EXAMPLE_EAP_METHOD == EAP_TTLS) {
|
|
||||||
|
#if defined CONFIG_EXAMPLE_EAP_METHOD_PEAP || CONFIG_EXAMPLE_EAP_METHOD_TTLS
|
||||||
ESP_ERROR_CHECK( esp_wifi_sta_wpa2_ent_set_username((uint8_t *)EXAMPLE_EAP_USERNAME, strlen(EXAMPLE_EAP_USERNAME)) );
|
ESP_ERROR_CHECK( esp_wifi_sta_wpa2_ent_set_username((uint8_t *)EXAMPLE_EAP_USERNAME, strlen(EXAMPLE_EAP_USERNAME)) );
|
||||||
ESP_ERROR_CHECK( esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EXAMPLE_EAP_PASSWORD, strlen(EXAMPLE_EAP_PASSWORD)) );
|
ESP_ERROR_CHECK( esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EXAMPLE_EAP_PASSWORD, strlen(EXAMPLE_EAP_PASSWORD)) );
|
||||||
}
|
#endif /* CONFIG_EXAMPLE_EAP_METHOD_PEAP || CONFIG_EXAMPLE_EAP_METHOD_TTLS */
|
||||||
|
|
||||||
ESP_ERROR_CHECK( esp_wifi_sta_wpa2_ent_enable() );
|
ESP_ERROR_CHECK( esp_wifi_sta_wpa2_ent_enable() );
|
||||||
ESP_ERROR_CHECK( esp_wifi_start() );
|
ESP_ERROR_CHECK( esp_wifi_start() );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user