Separate command for provisioning using HWEUI

This commit is contained in:
Manuel Bleichenbacher 2018-09-30 13:56:04 +02:00
parent 276fc0bac9
commit 467fdb8890

View File

@ -194,10 +194,15 @@ top:
void provisioning_process_line() void provisioning_process_line()
{ {
bool is_ok = true; bool is_ok = true;
bool reset_needed = false;
// Expected format: // Expected format:
// AT+PROV? // AT+PROV?
// AT+PROV=hex16-hex16-hex32 // AT+PROV=hex16-hex16-hex32
// AT+PROVM=hex16-hex32
// AT+MAC? // AT+MAC?
// AT+HWEUI?
if (strcmp(line_buf, "AT+PROV?") == 0) if (strcmp(line_buf, "AT+PROV?") == 0)
{ {
uint8_t binbuf[8]; uint8_t binbuf[8];
@ -218,34 +223,23 @@ void provisioning_process_line()
} }
else if (strncmp(line_buf, "AT+PROV=", 8) == 0) else if (strncmp(line_buf, "AT+PROV=", 8) == 0)
{ {
if (strlen(line_buf) == 74 && line_buf[24] == '-' && line_buf[41] == '-') is_ok = strlen(line_buf) == 74 && line_buf[24] == '-' && line_buf[41] == '-';
if (is_ok)
{ {
line_buf[24] = 0; line_buf[24] = 0;
line_buf[41] = 0; line_buf[41] = 0;
is_ok = provisioning_decode_keys(line_buf + 8, line_buf + 25, line_buf + 42); is_ok = provisioning_decode_keys(line_buf + 8, line_buf + 25, line_buf + 42);
reset_needed = is_ok;
}
}
else if (strncmp(line_buf, "AT+PROVM=", 8) == 0)
{
is_ok = strlen(line_buf) == 58 && line_buf[25] == '-';
if (is_ok) if (is_ok)
{ {
hal_enterCriticalSection(); line_buf[25] = 0;
LMIC_reset(); is_ok = provisioning_from_mac(line_buf + 9, line_buf + 26);
hal_leaveCriticalSection(); reset_needed = is_ok;
onEvent(EV_RESET);
}
}
else if(strlen(line_buf) == 57 && line_buf[24] == '-')
{
line_buf[24] = 0;
is_ok = provisioning_from_mac(line_buf + 8, line_buf + 25);
if (is_ok)
{
hal_enterCriticalSection();
LMIC_reset();
hal_leaveCriticalSection();
onEvent(EV_RESET);
}
}
else
{
is_ok = false;
} }
} }
else if (strcmp(line_buf, "AT+MAC?") == 0) else if (strcmp(line_buf, "AT+MAC?") == 0)
@ -275,10 +269,8 @@ void provisioning_process_line()
bin_to_hex_str(mac, 6, hexbuf); bin_to_hex_str(mac, 6, hexbuf);
for (int i = 0; i < 12; i += 2) { for (int i = 0; i < 12; i += 2) {
uart_write_bytes(UART_NUM, hexbuf + i, 2); uart_write_bytes(UART_NUM, hexbuf + i, 2);
if (i == 4) { if (i == 4)
uart_write_bytes(UART_NUM, "FF", 2); uart_write_bytes(UART_NUM, "FFFE", 4);
uart_write_bytes(UART_NUM, "FE", 2);
}
} }
uart_write_bytes(UART_NUM, "\r\n", 2); uart_write_bytes(UART_NUM, "\r\n", 2);
} }
@ -291,6 +283,14 @@ void provisioning_process_line()
is_ok = false; is_ok = false;
} }
if (reset_needed)
{
hal_enterCriticalSection();
LMIC_reset();
hal_leaveCriticalSection();
onEvent(EV_RESET);
}
uart_write_bytes(UART_NUM, is_ok ? "OK\r\n" : "ERROR\r\n", is_ok ? 4 : 7); uart_write_bytes(UART_NUM, is_ok ? "OK\r\n" : "ERROR\r\n", is_ok ? 4 : 7);
} }