mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-20 18:40:31 +00:00
introduce log_info_key and log_info_hexdump, move prototypes to btstack_debug.h
This commit is contained in:
parent
9c80e4cce8
commit
8314c363bc
@ -225,7 +225,6 @@ int socket_connection_hci_process(struct btstack_data_source *ds) {
|
||||
}
|
||||
conn->bytes_read += bytes_read;
|
||||
conn->bytes_to_read -= bytes_read;
|
||||
// hexdump( conn->buffer, conn->bytes_read);
|
||||
if (conn->bytes_to_read > 0) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -190,8 +190,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// hexdump(packet, size);
|
||||
|
||||
|
||||
// get name from deviceInfo
|
||||
if (deviceInfo) {
|
||||
NSMutableDictionary * deviceDict = [deviceInfo objectForKey:[dev addressString]];
|
||||
|
@ -214,7 +214,7 @@ void att_dump_attributes(void){
|
||||
log_info("%04x", little_endian_read_16(it.uuid, 0));
|
||||
}
|
||||
log_info(", value_len: %u, value: ", it.value_len);
|
||||
hexdump(it.value, it.value_len);
|
||||
log_info_hexdump(it.value, it.value_len);
|
||||
}
|
||||
}
|
||||
|
||||
@ -393,7 +393,7 @@ static uint16_t handle_find_by_type_value_request2(att_connection_t * att_connec
|
||||
uint16_t attribute_type, uint16_t attribute_len, uint8_t* attribute_value){
|
||||
|
||||
log_info("ATT_FIND_BY_TYPE_VALUE_REQUEST: from %04X to %04X, type %04X, value: ", start_handle, end_handle, attribute_type);
|
||||
hexdump(attribute_value, attribute_len);
|
||||
log_info_hexdump(attribute_value, attribute_len);
|
||||
uint8_t request_type = ATT_FIND_BY_TYPE_VALUE_REQUEST;
|
||||
|
||||
if (start_handle > end_handle || start_handle == 0){
|
||||
@ -462,7 +462,7 @@ static uint16_t handle_read_by_type_request2(att_connection_t * att_connection,
|
||||
uint16_t attribute_type_len, uint8_t * attribute_type){
|
||||
|
||||
log_info("ATT_READ_BY_TYPE_REQUEST: from %04X to %04X, type: ", start_handle, end_handle);
|
||||
hexdump(attribute_type, attribute_type_len);
|
||||
log_info_hexdump(attribute_type, attribute_type_len);
|
||||
uint8_t request_type = ATT_READ_BY_TYPE_REQUEST;
|
||||
|
||||
if (start_handle > end_handle || start_handle == 0){
|
||||
@ -743,7 +743,7 @@ static uint16_t handle_read_by_group_type_request2(att_connection_t * att_connec
|
||||
uint16_t attribute_type_len, uint8_t * attribute_type){
|
||||
|
||||
log_info("ATT_READ_BY_GROUP_TYPE_REQUEST: from %04X to %04X, buffer size %u, type: ", start_handle, end_handle, response_buffer_size);
|
||||
hexdump(attribute_type, attribute_type_len);
|
||||
log_info_hexdump(attribute_type, attribute_type_len);
|
||||
uint8_t request_type = ATT_READ_BY_GROUP_TYPE_REQUEST;
|
||||
|
||||
if (start_handle > end_handle || start_handle == 0){
|
||||
@ -1061,7 +1061,7 @@ uint16_t att_handle_request(att_connection_t * att_connection,
|
||||
break;
|
||||
default:
|
||||
log_info("Unhandled ATT Command: %02X, DATA: ", request_buffer[0]);
|
||||
hexdump(&request_buffer[9], request_len-9);
|
||||
log_info_hexdump(&request_buffer[9], request_len-9);
|
||||
break;
|
||||
}
|
||||
return response_len;
|
||||
@ -1080,28 +1080,28 @@ int main(void){
|
||||
|
||||
uint8_t uuid_1[] = { 0x00, 0x18};
|
||||
acl_buffer_size = handle_find_by_type_value_request2(acl_buffer, 19, 0, 0xffff, 0x2800, 2, (uint8_t *) &uuid_1);
|
||||
hexdump(acl_buffer, acl_buffer_size);
|
||||
log_info_hexdump(acl_buffer, acl_buffer_size);
|
||||
|
||||
uint8_t uuid_3[] = { 0x00, 0x2a};
|
||||
acl_buffer_size = handle_read_by_type_request2(acl_buffer, 19, 0, 0xffff, 2, (uint8_t *) &uuid_3);
|
||||
hexdump(acl_buffer, acl_buffer_size);
|
||||
log_info_hexdump(acl_buffer, acl_buffer_size);
|
||||
|
||||
acl_buffer_size = handle_find_by_type_value_request2(acl_buffer, 19, 0, 0xffff, 0x2800, 2, (uint8_t *) &uuid_1);
|
||||
hexdump(acl_buffer, acl_buffer_size);
|
||||
log_info_hexdump(acl_buffer, acl_buffer_size);
|
||||
|
||||
uint8_t uuid_4[] = { 0x00, 0x28};
|
||||
acl_buffer_size = handle_read_by_group_type_request2(acl_buffer, 20, 0, 0xffff, 2, (uint8_t *) &uuid_4);
|
||||
hexdump(acl_buffer, acl_buffer_size);
|
||||
log_info_hexdump(acl_buffer, acl_buffer_size);
|
||||
|
||||
acl_buffer_size = handle_find_information_request2(acl_buffer, 20, 0, 0xffff);
|
||||
hexdump(acl_buffer, acl_buffer_size);
|
||||
log_info_hexdump(acl_buffer, acl_buffer_size);
|
||||
acl_buffer_size = handle_find_information_request2(acl_buffer, 20, 3, 0xffff);
|
||||
hexdump(acl_buffer, acl_buffer_size);
|
||||
log_info_hexdump(acl_buffer, acl_buffer_size);
|
||||
acl_buffer_size = handle_find_information_request2(acl_buffer, 20, 5, 0xffff);
|
||||
hexdump(acl_buffer, acl_buffer_size);
|
||||
log_info_hexdump(acl_buffer, acl_buffer_size);
|
||||
|
||||
acl_buffer_size = handle_read_request2(acl_buffer, 19, 0x0003);
|
||||
hexdump(acl_buffer, acl_buffer_size);
|
||||
log_info_hexdump(acl_buffer, acl_buffer_size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -278,7 +278,7 @@ static void att_run(void){
|
||||
le_device_db_remote_csrk_get(att_ir_le_device_db_index, csrk);
|
||||
att_server_state = ATT_SERVER_W4_SIGNED_WRITE_VALIDATION;
|
||||
log_info("Orig Signature: ");
|
||||
hexdump( &att_request_buffer[att_request_size-8], 8);
|
||||
log_info_hexdump( &att_request_buffer[att_request_size-8], 8);
|
||||
uint16_t attribute_handle = little_endian_read_16(att_request_buffer, 1);
|
||||
sm_cmac_start(csrk, att_request_buffer[0], attribute_handle, att_request_size - 15, &att_request_buffer[3], counter_packet, att_signed_write_handle_cmac_result);
|
||||
return;
|
||||
|
@ -108,7 +108,7 @@ int le_device_db_add(int addr_type, bd_addr_t addr, sm_key_t irk){
|
||||
if (index < 0) return -1;
|
||||
|
||||
log_info("Central Device DB adding type %u - %s", addr_type, bd_addr_to_str(addr));
|
||||
log_key("irk", irk);
|
||||
log_info_key("irk", irk);
|
||||
|
||||
le_devices[index].addr_type = addr_type;
|
||||
memcpy(le_devices[index].addr, addr, 6);
|
||||
@ -209,8 +209,8 @@ void le_device_db_dump(void){
|
||||
for (i=0;i<LE_DEVICE_MEMORY_SIZE;i++){
|
||||
if (le_devices[i].addr_type == INVALID_ENTRY_ADDR_TYPE) continue;
|
||||
log_info("%u: %u %s", i, le_devices[i].addr_type, bd_addr_to_str(le_devices[i].addr));
|
||||
log_key("irk", le_devices[i].irk);
|
||||
log_key("local csrk", le_devices[i].local_csrk);
|
||||
log_key("remote csrk", le_devices[i].remote_csrk);
|
||||
log_info_key("irk", le_devices[i].irk);
|
||||
log_info_key("local csrk", le_devices[i].local_csrk);
|
||||
log_info_key("remote csrk", le_devices[i].remote_csrk);
|
||||
}
|
||||
}
|
||||
|
44
src/ble/sm.c
44
src/ble/sm.c
@ -429,15 +429,15 @@ static void sm_c1_t1(sm_key_t r, uint8_t preq[7], uint8_t pres[7], uint8_t iat,
|
||||
reverse_56(preq, &p1[7]);
|
||||
p1[14] = rat;
|
||||
p1[15] = iat;
|
||||
log_key("p1", p1);
|
||||
log_key("r", r);
|
||||
log_info_key("p1", p1);
|
||||
log_info_key("r", r);
|
||||
|
||||
// t1 = r xor p1
|
||||
int i;
|
||||
for (i=0;i<16;i++){
|
||||
t1[i] = r[i] ^ p1[i];
|
||||
}
|
||||
log_key("t1", t1);
|
||||
log_info_key("t1", t1);
|
||||
}
|
||||
|
||||
// calculate arguments for second AES128 operation in C1 function
|
||||
@ -452,19 +452,19 @@ static void sm_c1_t3(sm_key_t t2, bd_addr_t ia, bd_addr_t ra, sm_key_t t3){
|
||||
memset(p2, 0, 16);
|
||||
memcpy(&p2[4], ia, 6);
|
||||
memcpy(&p2[10], ra, 6);
|
||||
log_key("p2", p2);
|
||||
log_info_key("p2", p2);
|
||||
|
||||
// c1 = e(k, t2_xor_p2)
|
||||
int i;
|
||||
for (i=0;i<16;i++){
|
||||
t3[i] = t2[i] ^ p2[i];
|
||||
}
|
||||
log_key("t3", t3);
|
||||
log_info_key("t3", t3);
|
||||
}
|
||||
|
||||
static void sm_s1_r_prime(sm_key_t r1, sm_key_t r2, sm_key_t r_prime){
|
||||
log_key("r1", r1);
|
||||
log_key("r2", r2);
|
||||
log_info_key("r1", r1);
|
||||
log_info_key("r2", r2);
|
||||
memcpy(&r_prime[8], &r2[8], 8);
|
||||
memcpy(&r_prime[0], &r1[8], 8);
|
||||
}
|
||||
@ -532,7 +532,7 @@ static void sm_setup_tk(void){
|
||||
// Out of Band pairing method shall be used.
|
||||
if (setup->sm_m_preq.oob_data_flag && setup->sm_s_pres.oob_data_flag){
|
||||
log_info("SM: have OOB data");
|
||||
log_key("OOB", setup->sm_tk);
|
||||
log_info_key("OOB", setup->sm_tk);
|
||||
setup->sm_stk_generation_method = OOB;
|
||||
return;
|
||||
}
|
||||
@ -722,7 +722,7 @@ static void sm_cmac_handle_aes_engine_ready(void){
|
||||
for (i=0;i<16;i++){
|
||||
y[i] = sm_cmac_x[i] ^ sm_cmac_m_last[i];
|
||||
}
|
||||
log_key("Y", y);
|
||||
log_info_key("Y", y);
|
||||
sm_cmac_block_current++;
|
||||
sm_cmac_next_state();
|
||||
sm_aes128_start(sm_cmac_k, y, NULL);
|
||||
@ -750,9 +750,9 @@ static void sm_cmac_handle_encryption_result(sm_key_t data){
|
||||
k2[15] ^= 0x87;
|
||||
}
|
||||
|
||||
log_key("k", sm_cmac_k);
|
||||
log_key("k1", k1);
|
||||
log_key("k2", k2);
|
||||
log_info_key("k", sm_cmac_k);
|
||||
log_info_key("k1", k1);
|
||||
log_info_key("k2", k2);
|
||||
|
||||
// step 4: set m_last
|
||||
int i;
|
||||
@ -785,7 +785,7 @@ static void sm_cmac_handle_encryption_result(sm_key_t data){
|
||||
break;
|
||||
case CMAC_W4_MLAST:
|
||||
// done
|
||||
log_key("CMAC", data);
|
||||
log_info_key("CMAC", data);
|
||||
sm_cmac_done_handler(data);
|
||||
sm_cmac_state = CMAC_IDLE;
|
||||
break;
|
||||
@ -1193,7 +1193,7 @@ static void sm_run(void){
|
||||
if (sm_aes128_state == SM_AES128_ACTIVE) break;
|
||||
|
||||
log_info("LE Device Lookup: calculate AH");
|
||||
log_key("IRK", irk);
|
||||
log_info_key("IRK", irk);
|
||||
|
||||
sm_key_t r_prime;
|
||||
sm_ah_r_prime(sm_address_resolution_address, r_prime);
|
||||
@ -1603,12 +1603,12 @@ static void sm_handle_encryption_result(uint8_t * data){
|
||||
switch (dkg_state){
|
||||
case DKG_W4_IRK:
|
||||
reverse_128(data, sm_persistent_irk);
|
||||
log_key("irk", sm_persistent_irk);
|
||||
log_info_key("irk", sm_persistent_irk);
|
||||
dkg_next_state();
|
||||
return;
|
||||
case DKG_W4_DHK:
|
||||
reverse_128(data, sm_persistent_dhk);
|
||||
log_key("dhk", sm_persistent_dhk);
|
||||
log_info_key("dhk", sm_persistent_dhk);
|
||||
dkg_next_state();
|
||||
// SM Init Finished
|
||||
return;
|
||||
@ -1654,14 +1654,14 @@ static void sm_handle_encryption_result(uint8_t * data){
|
||||
return;
|
||||
case SM_PH2_C1_W4_ENC_B:
|
||||
reverse_128(data, setup->sm_local_confirm);
|
||||
log_key("c1!", setup->sm_local_confirm);
|
||||
log_info_key("c1!", setup->sm_local_confirm);
|
||||
connection->sm_engine_state = SM_PH2_C1_SEND_PAIRING_CONFIRM;
|
||||
return;
|
||||
case SM_PH2_C1_W4_ENC_D:
|
||||
{
|
||||
sm_key_t peer_confirm_test;
|
||||
reverse_128(data, peer_confirm_test);
|
||||
log_key("c1!", peer_confirm_test);
|
||||
log_info_key("c1!", peer_confirm_test);
|
||||
if (memcmp(setup->sm_peer_confirm, peer_confirm_test, 16) != 0){
|
||||
setup->sm_pairing_failed_reason = SM_REASON_CONFIRM_VALUE_FAILED;
|
||||
connection->sm_engine_state = SM_GENERAL_SEND_PAIRING_FAILED;
|
||||
@ -1677,7 +1677,7 @@ static void sm_handle_encryption_result(uint8_t * data){
|
||||
case SM_PH2_W4_STK:
|
||||
reverse_128(data, setup->sm_ltk);
|
||||
sm_truncate_key(setup->sm_ltk, connection->sm_actual_encryption_key_size);
|
||||
log_key("stk", setup->sm_ltk);
|
||||
log_info_key("stk", setup->sm_ltk);
|
||||
if (connection->sm_role){
|
||||
connection->sm_engine_state = SM_RESPONDER_PH2_SEND_LTK_REPLY;
|
||||
} else {
|
||||
@ -1713,13 +1713,13 @@ static void sm_handle_encryption_result(uint8_t * data){
|
||||
}
|
||||
case SM_PH3_LTK_W4_ENC:
|
||||
reverse_128(data, setup->sm_ltk);
|
||||
log_key("ltk", setup->sm_ltk);
|
||||
log_info_key("ltk", setup->sm_ltk);
|
||||
// calc CSRK next
|
||||
connection->sm_engine_state = SM_PH3_CSRK_GET_ENC;
|
||||
return;
|
||||
case SM_PH3_CSRK_W4_ENC:
|
||||
reverse_128(data, setup->sm_local_csrk);
|
||||
log_key("csrk", setup->sm_local_csrk);
|
||||
log_info_key("csrk", setup->sm_local_csrk);
|
||||
if (setup->sm_key_distribution_send_set){
|
||||
connection->sm_engine_state = SM_PH3_DISTRIBUTE_KEYS;
|
||||
} else {
|
||||
@ -1737,7 +1737,7 @@ static void sm_handle_encryption_result(uint8_t * data){
|
||||
case SM_RESPONDER_PH4_LTK_W4_ENC:
|
||||
reverse_128(data, setup->sm_ltk);
|
||||
sm_truncate_key(setup->sm_ltk, connection->sm_actual_encryption_key_size);
|
||||
log_key("ltk", setup->sm_ltk);
|
||||
log_info_key("ltk", setup->sm_ltk);
|
||||
connection->sm_engine_state = SM_RESPONDER_PH4_SEND_LTK;
|
||||
return;
|
||||
default:
|
||||
|
@ -45,6 +45,7 @@
|
||||
#define __DEBUG_H
|
||||
|
||||
#include "btstack_config.h"
|
||||
#include "btstack_defines.h"
|
||||
#include "hci_dump.h"
|
||||
|
||||
#include <stdio.h>
|
||||
@ -94,4 +95,17 @@ static inline void __log_unused(const char *format, ...) {}
|
||||
#define log_error(...) __log_unused(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Log Security Manager key via log_info
|
||||
* @param key to log
|
||||
*/
|
||||
void log_info_key(const char * name, sm_key_t key);
|
||||
|
||||
/**
|
||||
* @brief Hexdump via log_info
|
||||
* @param data
|
||||
* @param size
|
||||
*/
|
||||
void log_info_hexdump(const void *data, int size);
|
||||
|
||||
#endif // __DEBUG_H
|
||||
|
@ -163,7 +163,7 @@ void printf_hexdump(const void *data, int size){
|
||||
//
|
||||
// }
|
||||
|
||||
void hexdump(const void *data, int size){
|
||||
void log_info_hexdump(const void *data, int size){
|
||||
#ifdef ENABLE_LOG_INFO
|
||||
char buffer[6*16+1];
|
||||
int i, j;
|
||||
@ -189,12 +189,12 @@ void hexdump(const void *data, int size){
|
||||
buffer[j] = 0;
|
||||
log_info("%s", buffer);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void log_key(const char * name, sm_key_t key){
|
||||
log_info("%-6s ", name);
|
||||
hexdump(key, 16);
|
||||
void log_info_key(const char * name, sm_key_t key){
|
||||
// log_info("%-6s ", name);
|
||||
// hexdump(key, 16);
|
||||
}
|
||||
|
||||
// Bluetooth Base UUID: 00000000-0000-1000-8000- 00805F9B34FB
|
||||
|
@ -157,13 +157,6 @@ void bd_addr_copy(bd_addr_t dest, bd_addr_t src);
|
||||
*/
|
||||
void printf_hexdump(const void *data, int size);
|
||||
|
||||
// move to btstack_debug.h
|
||||
// void log_info_hexdump(..) either log or hci_dump or off
|
||||
void log_key(const char * name, sm_key_t key);
|
||||
|
||||
//
|
||||
void hexdump(const void *data, int size);
|
||||
|
||||
/**
|
||||
* @brief Create human readable representation for UUID128
|
||||
* @note uses fixed global buffer
|
||||
|
Loading…
x
Reference in New Issue
Block a user