Merge branch 'master' into feature/esp32s2beta_merge

This commit is contained in:
Angus Gratton
2019-10-15 14:59:27 +11:00
committed by Angus Gratton
122 changed files with 2683 additions and 1553 deletions

View File

@@ -16,17 +16,26 @@
#include "utils/common.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;
char *pos = buf, *end = buf + buf_size;
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)
return 0;
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) {
end[-1] = '\0';
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)
{
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)
{
return _wpa_snprintf_hex(buf, buf_size, data, len, 0);
return _wpa_snprintf_hex(buf, buf_size, data, len, 0, 0);
}
#ifdef DEBUG_PRINT
void wpa_dump_mem(char* desc, uint8_t *addr, uint16_t len)
{
char output[50];
wpa_printf(MSG_DEBUG, "%s\n", desc);
if (addr){
uint16_t i=0;
for (i=0; i<len; i++){
if (i%16==0) wpa_printf(MSG_DEBUG, "\n");
wpa_printf(MSG_DEBUG, "%02x ", addr[i]);
for (i = 0; i < len / 16; i++) {
_wpa_snprintf_hex(output, 50, addr + i * 16, 16, 0, 1);
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
size_t i;
char output[50];
if (level < MSG_MSGDUMP)
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) {
wpa_printf(MSG_DEBUG, " [NULL]\n");
wpa_printf(MSG_DEBUG, " [NULL]");
} else {
for (i = 0; i < len; i++) {
wpa_printf(MSG_DEBUG, " %02x", buf[i]);
if((i+1) % 16 == 0)
wpa_printf(MSG_DEBUG, "\n");
}
for (i = 0; i < len / 16; i++) {
_wpa_snprintf_hex(output, 50, buf + i * 16, 16, 0, 1);
wpa_printf(MSG_DEBUG, "%s", output);
}
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
}