1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

bluetil/addr: fix byte ordering in addr_from_str()

This commit is contained in:
Hauke Petersen 2019-08-19 18:07:53 +02:00
parent b7b5791930
commit 7f7993f1d6
2 changed files with 5 additions and 2 deletions

View File

@ -73,6 +73,9 @@ void bluetil_addr_print(const uint8_t *addr);
/**
* @brief Parse a BLE address from the given string
*
* @note The address is expected most significant byte first and is written
* to @p addr in network byte order
*
* @param[out] addr buffer to write the BLE address, *must* be able to hold
* @ref BLE_ADDR_LEN bytes
* @param[in] addr_str address string, must be at least of length

View File

@ -78,12 +78,12 @@ uint8_t *bluetil_addr_from_str(uint8_t *addr, const char *addr_str)
}
}
unsigned pos = BLE_ADDR_LEN;
unsigned pos = 0;
for (unsigned i = 0; i < (BLUETIL_ADDR_STRLEN - 1); i += 3) {
if (!_is_hex_char(addr_str[i]) || !_is_hex_char(addr_str[i + 1])) {
return NULL;
}
addr[--pos] = fmt_hex_byte(addr_str + i);
addr[pos++] = fmt_hex_byte(addr_str + i);
}
return addr;
}