mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-24 13:43:38 +00:00
util.h: rename swapX into reverse_x
This commit is contained in:
parent
0ca398bf08
commit
9c80e4cce8
@ -67,7 +67,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
switch (packet[2]) {
|
||||
case HCI_SUBEVENT_LE_ADVERTISING_REPORT:
|
||||
printf("\n- ADV: ");
|
||||
hexdumpf(packet, size);
|
||||
printf_hexdump(packet, size);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -142,7 +142,7 @@ static void extract_service(le_service_t * service, uint8_t * packet){
|
||||
service->start_group_handle = little_endian_read_16(packet, 4);
|
||||
service->end_group_handle = little_endian_read_16(packet, 6);
|
||||
service->uuid16 = 0;
|
||||
swap128(&packet[8], service->uuid128);
|
||||
reverse_128(&packet[8], service->uuid128);
|
||||
if (uuid_has_bluetooth_prefix(service->uuid128)){
|
||||
service->uuid16 = big_endian_read_32(service->uuid128, 0);
|
||||
}
|
||||
@ -154,7 +154,7 @@ static void extract_characteristic(le_characteristic_t * characteristic, uint8_t
|
||||
characteristic->end_handle = little_endian_read_16(packet, 8);
|
||||
characteristic->properties = little_endian_read_16(packet, 10);
|
||||
characteristic->uuid16 = 0;
|
||||
swap128(&packet[12], characteristic->uuid128);
|
||||
reverse_128(&packet[12], characteristic->uuid128);
|
||||
if (uuid_has_bluetooth_prefix(characteristic->uuid128)){
|
||||
characteristic->uuid16 = big_endian_read_32(characteristic->uuid128, 0);
|
||||
}
|
||||
|
@ -244,7 +244,7 @@ static void extract_service(le_service_t * service, uint8_t * packet){
|
||||
service->start_group_handle = little_endian_read_16(packet, 4);
|
||||
service->end_group_handle = little_endian_read_16(packet, 6);
|
||||
service->uuid16 = 0;
|
||||
swap128(&packet[8], service->uuid128);
|
||||
reverse_128(&packet[8], service->uuid128);
|
||||
if (uuid_has_bluetooth_prefix(service->uuid128)){
|
||||
service->uuid16 = big_endian_read_32(service->uuid128, 0);
|
||||
}
|
||||
@ -256,7 +256,7 @@ static void extract_characteristic(le_characteristic_t * characteristic, uint8_t
|
||||
characteristic->end_handle = little_endian_read_16(packet, 8);
|
||||
characteristic->properties = little_endian_read_16(packet, 10);
|
||||
characteristic->uuid16 = 0;
|
||||
swap128(&packet[12], characteristic->uuid128);
|
||||
reverse_128(&packet[12], characteristic->uuid128);
|
||||
if (uuid_has_bluetooth_prefix(characteristic->uuid128)){
|
||||
characteristic->uuid16 = big_endian_read_32(characteristic->uuid128, 0);
|
||||
}
|
||||
|
@ -151,7 +151,6 @@ static void sco_packet_handler(uint8_t packet_type, uint8_t * packet, uint16_t s
|
||||
count++;
|
||||
if ((count & 15)) return;
|
||||
printf("SCO packets %u\n", count);
|
||||
// hexdumpf(packet, size);
|
||||
}
|
||||
|
||||
static void packet_handler(uint8_t * event, uint16_t event_size){
|
||||
|
@ -846,13 +846,13 @@ btstack_linked_list_gatt_client_helper_t * daemon_setup_gatt_client_request(conn
|
||||
void daemon_gatt_deserialize_service(uint8_t *packet, int offset, le_service_t *service){
|
||||
service->start_group_handle = little_endian_read_16(packet, offset);
|
||||
service->end_group_handle = little_endian_read_16(packet, offset + 2);
|
||||
swap128(&packet[offset + 4], service->uuid128);
|
||||
reverse_128(&packet[offset + 4], service->uuid128);
|
||||
}
|
||||
|
||||
void daemon_gatt_serialize_service(le_service_t * service, uint8_t * event, int offset){
|
||||
little_endian_store_16(event, offset, service->start_group_handle);
|
||||
little_endian_store_16(event, offset+2, service->end_group_handle);
|
||||
swap128(service->uuid128, &event[offset + 4]);
|
||||
reverse_128(service->uuid128, &event[offset + 4]);
|
||||
}
|
||||
|
||||
void daemon_gatt_deserialize_characteristic(uint8_t * packet, int offset, le_characteristic_t * characteristic){
|
||||
@ -861,7 +861,7 @@ void daemon_gatt_deserialize_characteristic(uint8_t * packet, int offset, le_cha
|
||||
characteristic->end_handle = little_endian_read_16(packet, offset + 4);
|
||||
characteristic->properties = little_endian_read_16(packet, offset + 6);
|
||||
characteristic->uuid16 = little_endian_read_16(packet, offset + 8);
|
||||
swap128(&packet[offset+10], characteristic->uuid128);
|
||||
reverse_128(&packet[offset+10], characteristic->uuid128);
|
||||
}
|
||||
|
||||
void daemon_gatt_serialize_characteristic(le_characteristic_t * characteristic, uint8_t * event, int offset){
|
||||
@ -869,17 +869,17 @@ void daemon_gatt_serialize_characteristic(le_characteristic_t * characteristic,
|
||||
little_endian_store_16(event, offset+2, characteristic->value_handle);
|
||||
little_endian_store_16(event, offset+4, characteristic->end_handle);
|
||||
little_endian_store_16(event, offset+6, characteristic->properties);
|
||||
swap128(characteristic->uuid128, &event[offset+8]);
|
||||
reverse_128(characteristic->uuid128, &event[offset+8]);
|
||||
}
|
||||
|
||||
void daemon_gatt_deserialize_characteristic_descriptor(uint8_t * packet, int offset, le_characteristic_descriptor_t * descriptor){
|
||||
descriptor->handle = little_endian_read_16(packet, offset);
|
||||
swap128(&packet[offset+2], descriptor->uuid128);
|
||||
reverse_128(&packet[offset+2], descriptor->uuid128);
|
||||
}
|
||||
|
||||
void daemon_gatt_serialize_characteristic_descriptor(le_characteristic_descriptor_t * characteristic_descriptor, uint8_t * event, int offset){
|
||||
little_endian_store_16(event, offset, characteristic_descriptor->handle);
|
||||
swap128(characteristic_descriptor->uuid128, &event[offset+2]);
|
||||
reverse_128(characteristic_descriptor->uuid128, &event[offset+2]);
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -1179,7 +1179,7 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui
|
||||
case GATT_DISCOVER_PRIMARY_SERVICES_BY_UUID128:
|
||||
gatt_helper = daemon_setup_gatt_client_request(connection, packet, 1);
|
||||
if (!gatt_helper) break;
|
||||
swap128(&packet[5], uuid128);
|
||||
reverse_128(&packet[5], uuid128);
|
||||
gatt_client_discover_primary_services_by_uuid128(gatt_client_id, gatt_helper->con_handle, uuid128);
|
||||
break;
|
||||
case GATT_FIND_INCLUDED_SERVICES_FOR_SERVICE:
|
||||
@ -1199,7 +1199,7 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui
|
||||
gatt_helper = daemon_setup_gatt_client_request(connection, packet, 1);
|
||||
if (!gatt_helper) break;
|
||||
daemon_gatt_deserialize_service(packet, 5, &service);
|
||||
swap128(&packet[5 + SERVICE_LENGTH], uuid128);
|
||||
reverse_128(&packet[5 + SERVICE_LENGTH], uuid128);
|
||||
gatt_client_discover_characteristics_for_service_by_uuid128(gatt_client_id, gatt_helper->con_handle, &service, uuid128);
|
||||
break;
|
||||
case GATT_DISCOVER_CHARACTERISTIC_DESCRIPTORS:
|
||||
|
@ -109,7 +109,7 @@ int ad_data_contains_uuid16(uint8_t ad_len, uint8_t * ad_data, uint16_t uuid16){
|
||||
case IncompleteList128:
|
||||
case CompleteList128:
|
||||
uuid_add_bluetooth_prefix(ad_uuid128, uuid16);
|
||||
swap128(ad_uuid128, uuid128_bt);
|
||||
reverse_128(ad_uuid128, uuid128_bt);
|
||||
|
||||
for (i=0; i<data_len; i+=16){
|
||||
if (memcmp(uuid128_bt, &data[i], 16) == 0) return 1;
|
||||
@ -126,7 +126,7 @@ int ad_data_contains_uuid128(uint8_t ad_len, uint8_t * ad_data, uint8_t * uuid12
|
||||
ad_context_t context;
|
||||
// input in big endian/network order, bluetooth data in little endian
|
||||
uint8_t uuid128_le[16];
|
||||
swap128(uuid128, uuid128_le);
|
||||
reverse_128(uuid128, uuid128_le);
|
||||
for (ad_iterator_init(&context, ad_len, ad_data) ; ad_iterator_has_more(&context) ; ad_iterator_next(&context)){
|
||||
uint8_t data_type = ad_iterator_get_data_type(&context);
|
||||
uint8_t data_len = ad_iterator_get_data_len(&context);
|
||||
|
@ -178,7 +178,7 @@ static void extract_service(le_service_t * service, uint8_t * packet){
|
||||
service->start_group_handle = little_endian_read_16(packet, 4);
|
||||
service->end_group_handle = little_endian_read_16(packet, 6);
|
||||
service->uuid16 = 0;
|
||||
swap128(&packet[8], service->uuid128);
|
||||
reverse_128(&packet[8], service->uuid128);
|
||||
if (uuid_has_bluetooth_prefix(service->uuid128)){
|
||||
service->uuid16 = big_endian_read_32(service->uuid128, 0);
|
||||
}
|
||||
@ -190,7 +190,7 @@ static void extract_characteristic(le_characteristic_t * characteristic, uint8_t
|
||||
characteristic->end_handle = little_endian_read_16(packet, 8);
|
||||
characteristic->properties = little_endian_read_16(packet, 10);
|
||||
characteristic->uuid16 = 0;
|
||||
swap128(&packet[12], characteristic->uuid128);
|
||||
reverse_128(&packet[12], characteristic->uuid128);
|
||||
if (uuid_has_bluetooth_prefix(characteristic->uuid128)){
|
||||
characteristic->uuid16 = big_endian_read_32(characteristic->uuid128, 0);
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ void att_dump_attributes(void){
|
||||
}
|
||||
log_info("Handle: 0x%04x, flags: 0x%04x, uuid: ", it.handle, it.flags);
|
||||
if (it.flags & ATT_PROPERTY_UUID128){
|
||||
swap128(it.uuid, uuid128);
|
||||
reverse_128(it.uuid, uuid128);
|
||||
log_info("%s", uuid128_to_str(uuid128));
|
||||
} else {
|
||||
log_info("%04x", little_endian_read_16(it.uuid, 0));
|
||||
|
@ -131,7 +131,7 @@ static void att_db_util_add_attribute_uuid128(uint8_t * uuid128, uint16_t flags,
|
||||
little_endian_store_16(att_db, att_db_size, att_db_next_handle);
|
||||
att_db_size += 2;
|
||||
att_db_next_handle++;
|
||||
swap128(uuid128, &att_db[att_db_size]);
|
||||
reverse_128(uuid128, &att_db[att_db_size]);
|
||||
att_db_size += 16;
|
||||
memcpy(&att_db[att_db_size], data, data_len);
|
||||
att_db_size += data_len;
|
||||
@ -146,7 +146,7 @@ void att_db_util_add_service_uuid16(uint16_t uuid16){
|
||||
|
||||
void att_db_util_add_service_uuid128(uint8_t * uuid128){
|
||||
uint8_t buffer[16];
|
||||
swap128(uuid128, buffer);
|
||||
reverse_128(uuid128, buffer);
|
||||
att_db_util_add_attribute_uuid16(GATT_PRIMARY_SERVICE_UUID, ATT_PROPERTY_READ, buffer, 16);
|
||||
}
|
||||
|
||||
@ -170,7 +170,7 @@ uint16_t att_db_util_add_characteristic_uuid128(uint8_t * uuid128, uint16_t prop
|
||||
uint8_t buffer[19];
|
||||
buffer[0] = properties;
|
||||
little_endian_store_16(buffer, 1, att_db_next_handle + 1);
|
||||
swap128(uuid128, &buffer[3]);
|
||||
reverse_128(uuid128, &buffer[3]);
|
||||
att_db_util_add_attribute_uuid16(GATT_CHARACTERISTICS_UUID, ATT_PROPERTY_READ, buffer, sizeof(buffer));
|
||||
uint16_t value_handle = att_db_next_handle;
|
||||
att_db_util_add_attribute_uuid128(uuid128, properties, data, data_len);
|
||||
|
@ -221,7 +221,7 @@ static void att_signed_write_handle_cmac_result(uint8_t hash[8]){
|
||||
if (att_server_state != ATT_SERVER_W4_SIGNED_WRITE_VALIDATION) return;
|
||||
|
||||
uint8_t hash_flipped[8];
|
||||
swap64(hash, hash_flipped);
|
||||
reverse_64(hash, hash_flipped);
|
||||
if (memcmp(hash_flipped, &att_request_buffer[att_request_size-8], 8)){
|
||||
log_info("ATT Signed Write, invalid signature");
|
||||
att_server_state = ATT_SERVER_IDLE;
|
||||
|
@ -287,7 +287,7 @@ static void att_read_by_type_or_group_request_for_uuid128(uint16_t request_type,
|
||||
request[0] = request_type;
|
||||
little_endian_store_16(request, 1, start_handle);
|
||||
little_endian_store_16(request, 3, end_handle);
|
||||
swap128(uuid128, &request[5]);
|
||||
reverse_128(uuid128, &request[5]);
|
||||
|
||||
l2cap_send_prepared_connectionless(peripheral_handle, L2CAP_CID_ATTRIBUTE_PROTOCOL, 21);
|
||||
}
|
||||
@ -334,7 +334,7 @@ static void att_signed_write_request(uint16_t request_type, uint16_t peripheral_
|
||||
little_endian_store_16(request, 1, attribute_handle);
|
||||
memcpy(&request[3], value, value_length);
|
||||
little_endian_store_32(request, 3 + value_length, sign_counter);
|
||||
swap64(sgn, &request[3 + value_length + 4]);
|
||||
reverse_64(sgn, &request[3 + value_length + 4]);
|
||||
l2cap_send_prepared_connectionless(peripheral_handle, L2CAP_CID_ATTRIBUTE_PROTOCOL, 3 + value_length + 12);
|
||||
}
|
||||
|
||||
@ -403,7 +403,7 @@ static void send_gatt_by_uuid_request(gatt_client_t *peripheral, uint16_t attrib
|
||||
return;
|
||||
}
|
||||
uint8_t uuid128[16];
|
||||
swap128(peripheral->uuid128, uuid128);
|
||||
reverse_128(peripheral->uuid128, uuid128);
|
||||
att_find_by_type_value_request(ATT_FIND_BY_TYPE_VALUE_REQUEST, attribute_group_type, peripheral->handle, peripheral->start_group_handle, peripheral->end_group_handle, uuid128, 16);
|
||||
}
|
||||
|
||||
@ -533,7 +533,7 @@ static void emit_gatt_service_query_result_event(gatt_client_t * peripheral, uin
|
||||
///
|
||||
little_endian_store_16(packet, 4, start_group_handle);
|
||||
little_endian_store_16(packet, 6, end_group_handle);
|
||||
swap128(uuid128, &packet[8]);
|
||||
reverse_128(uuid128, &packet[8]);
|
||||
emit_event_new(peripheral->subclient_id, packet, sizeof(packet));
|
||||
}
|
||||
|
||||
@ -548,7 +548,7 @@ static void emit_gatt_included_service_query_result_event(gatt_client_t * periph
|
||||
//
|
||||
little_endian_store_16(packet, 6, start_group_handle);
|
||||
little_endian_store_16(packet, 8, end_group_handle);
|
||||
swap128(uuid128, &packet[10]);
|
||||
reverse_128(uuid128, &packet[10]);
|
||||
emit_event_new(peripheral->subclient_id, packet, sizeof(packet));
|
||||
}
|
||||
|
||||
@ -564,7 +564,7 @@ static void emit_gatt_characteristic_query_result_event(gatt_client_t * peripher
|
||||
little_endian_store_16(packet, 6, value_handle);
|
||||
little_endian_store_16(packet, 8, end_handle);
|
||||
little_endian_store_16(packet, 10, properties);
|
||||
swap128(uuid128, &packet[12]);
|
||||
reverse_128(uuid128, &packet[12]);
|
||||
emit_event_new(peripheral->subclient_id, packet, sizeof(packet));
|
||||
}
|
||||
|
||||
@ -577,7 +577,7 @@ static void emit_gatt_all_characteristic_descriptors_result_event(
|
||||
little_endian_store_16(packet, 2, peripheral->handle);
|
||||
///
|
||||
little_endian_store_16(packet, 4, descriptor_handle);
|
||||
swap128(uuid128, &packet[6]);
|
||||
reverse_128(uuid128, &packet[6]);
|
||||
emit_event_new(peripheral->subclient_id, packet, sizeof(packet));
|
||||
}
|
||||
///
|
||||
@ -597,7 +597,7 @@ static void report_gatt_services(gatt_client_t * peripheral, uint8_t * packet,
|
||||
uuid16 = little_endian_read_16(packet, i+4);
|
||||
uuid_add_bluetooth_prefix((uint8_t*) &uuid128, uuid16);
|
||||
} else {
|
||||
swap128(&packet[i+4], uuid128);
|
||||
reverse_128(&packet[i+4], uuid128);
|
||||
}
|
||||
emit_gatt_service_query_result_event(peripheral, start_group_handle, end_group_handle, uuid128);
|
||||
}
|
||||
@ -612,7 +612,7 @@ static void characteristic_start_found(gatt_client_t * peripheral, uint16_t star
|
||||
uuid16 = little_endian_read_16(uuid, 0);
|
||||
uuid_add_bluetooth_prefix((uint8_t*) uuid128, uuid16);
|
||||
} else {
|
||||
swap128(uuid, uuid128);
|
||||
reverse_128(uuid, uuid128);
|
||||
}
|
||||
|
||||
if (peripheral->filter_with_uuid && memcmp(peripheral->uuid128, uuid128, 16) != 0) return;
|
||||
@ -744,7 +744,7 @@ static void report_gatt_all_characteristic_descriptors(gatt_client_t * periphera
|
||||
uuid16 = little_endian_read_16(packet,i+2);
|
||||
uuid_add_bluetooth_prefix(uuid128, uuid16);
|
||||
} else {
|
||||
swap128(&packet[i+2], uuid128);
|
||||
reverse_128(&packet[i+2], uuid128);
|
||||
}
|
||||
emit_gatt_all_characteristic_descriptors_result_event(peripheral, descriptor_handle, uuid128);
|
||||
}
|
||||
@ -1166,7 +1166,7 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle,
|
||||
switch (peripheral->gatt_client_state){
|
||||
case P_W4_INCLUDED_SERVICE_UUID_WITH_QUERY_RESULT: {
|
||||
uint8_t uuid128[16];
|
||||
swap128(&packet[1], uuid128);
|
||||
reverse_128(&packet[1], uuid128);
|
||||
report_gatt_included_service_uuid128(peripheral, peripheral->start_group_handle, uuid128);
|
||||
trigger_next_included_service_query(peripheral, peripheral->start_group_handle);
|
||||
// GATT_EVENT_QUERY_COMPLETE is emitted by trigger_next_xxx when done
|
||||
@ -1385,7 +1385,7 @@ static void att_signed_write_handle_cmac_result(uint8_t hash[8]){
|
||||
if (peripheral->gatt_client_state == P_W4_CMAC_RESULT){
|
||||
// store result
|
||||
memcpy(peripheral->cmac, hash, 8);
|
||||
// swap64(hash, peripheral->cmac);
|
||||
// reverse_64(hash, peripheral->cmac);
|
||||
peripheral->gatt_client_state = P_W2_SEND_SIGNED_WRITE;
|
||||
gatt_client_run();
|
||||
return;
|
||||
|
76
src/ble/sm.c
76
src/ble/sm.c
@ -381,8 +381,8 @@ static void sm_random_start(void * context){
|
||||
static void sm_aes128_start(sm_key_t key, sm_key_t plaintext, void * context){
|
||||
sm_aes128_state = SM_AES128_ACTIVE;
|
||||
sm_key_t key_flipped, plaintext_flipped;
|
||||
swap128(key, key_flipped);
|
||||
swap128(plaintext, plaintext_flipped);
|
||||
reverse_128(key, key_flipped);
|
||||
reverse_128(plaintext, plaintext_flipped);
|
||||
sm_aes128_context = context;
|
||||
hci_send_cmd(&hci_le_encrypt, key_flipped, plaintext_flipped);
|
||||
}
|
||||
@ -425,8 +425,8 @@ static void sm_c1_t1(sm_key_t r, uint8_t preq[7], uint8_t pres[7], uint8_t iat,
|
||||
// p1 is 0x05000800000302070710000001010001."
|
||||
|
||||
sm_key_t p1;
|
||||
swap56(pres, &p1[0]);
|
||||
swap56(preq, &p1[7]);
|
||||
reverse_56(pres, &p1[0]);
|
||||
reverse_56(preq, &p1[7]);
|
||||
p1[14] = rat;
|
||||
p1[15] = iat;
|
||||
log_key("p1", p1);
|
||||
@ -1329,7 +1329,7 @@ static void sm_run(void){
|
||||
// initiator side
|
||||
case SM_INITIATOR_PH0_SEND_START_ENCRYPTION: {
|
||||
sm_key_t peer_ltk_flipped;
|
||||
swap128(setup->sm_peer_ltk, peer_ltk_flipped);
|
||||
reverse_128(setup->sm_peer_ltk, peer_ltk_flipped);
|
||||
connection->sm_engine_state = SM_INITIATOR_PH0_W4_CONNECTION_ENCRYPTED;
|
||||
log_info("sm: hci_le_start_encryption ediv 0x%04x", setup->sm_peer_ediv);
|
||||
uint32_t rand_high = big_endian_read_32(setup->sm_peer_rand, 0);
|
||||
@ -1366,7 +1366,7 @@ static void sm_run(void){
|
||||
case SM_PH2_SEND_PAIRING_RANDOM: {
|
||||
uint8_t buffer[17];
|
||||
buffer[0] = SM_CODE_PAIRING_RANDOM;
|
||||
swap128(setup->sm_local_random, &buffer[1]);
|
||||
reverse_128(setup->sm_local_random, &buffer[1]);
|
||||
if (connection->sm_role){
|
||||
connection->sm_engine_state = SM_RESPONDER_PH2_W4_LTK_REQUEST;
|
||||
} else {
|
||||
@ -1457,7 +1457,7 @@ static void sm_run(void){
|
||||
case SM_PH2_C1_SEND_PAIRING_CONFIRM: {
|
||||
uint8_t buffer[17];
|
||||
buffer[0] = SM_CODE_PAIRING_CONFIRM;
|
||||
swap128(setup->sm_local_confirm, &buffer[1]);
|
||||
reverse_128(setup->sm_local_confirm, &buffer[1]);
|
||||
if (connection->sm_role){
|
||||
connection->sm_engine_state = SM_RESPONDER_PH2_W4_PAIRING_RANDOM;
|
||||
} else {
|
||||
@ -1469,21 +1469,21 @@ static void sm_run(void){
|
||||
}
|
||||
case SM_RESPONDER_PH2_SEND_LTK_REPLY: {
|
||||
sm_key_t stk_flipped;
|
||||
swap128(setup->sm_ltk, stk_flipped);
|
||||
reverse_128(setup->sm_ltk, stk_flipped);
|
||||
connection->sm_engine_state = SM_PH2_W4_CONNECTION_ENCRYPTED;
|
||||
hci_send_cmd(&hci_le_long_term_key_request_reply, connection->sm_handle, stk_flipped);
|
||||
return;
|
||||
}
|
||||
case SM_INITIATOR_PH3_SEND_START_ENCRYPTION: {
|
||||
sm_key_t stk_flipped;
|
||||
swap128(setup->sm_ltk, stk_flipped);
|
||||
reverse_128(setup->sm_ltk, stk_flipped);
|
||||
connection->sm_engine_state = SM_PH2_W4_CONNECTION_ENCRYPTED;
|
||||
hci_send_cmd(&hci_le_start_encryption, connection->sm_handle, 0, 0, 0, stk_flipped);
|
||||
return;
|
||||
}
|
||||
case SM_RESPONDER_PH4_SEND_LTK: {
|
||||
sm_key_t ltk_flipped;
|
||||
swap128(setup->sm_ltk, ltk_flipped);
|
||||
reverse_128(setup->sm_ltk, ltk_flipped);
|
||||
connection->sm_engine_state = SM_RESPONDER_IDLE;
|
||||
hci_send_cmd(&hci_le_long_term_key_request_reply, connection->sm_handle, ltk_flipped);
|
||||
return;
|
||||
@ -1503,7 +1503,7 @@ static void sm_run(void){
|
||||
setup->sm_key_distribution_send_set &= ~SM_KEYDIST_FLAG_ENCRYPTION_INFORMATION;
|
||||
uint8_t buffer[17];
|
||||
buffer[0] = SM_CODE_ENCRYPTION_INFORMATION;
|
||||
swap128(setup->sm_ltk, &buffer[1]);
|
||||
reverse_128(setup->sm_ltk, &buffer[1]);
|
||||
l2cap_send_connectionless(connection->sm_handle, L2CAP_CID_SECURITY_MANAGER_PROTOCOL, (uint8_t*) buffer, sizeof(buffer));
|
||||
sm_timeout_reset(connection);
|
||||
return;
|
||||
@ -1513,7 +1513,7 @@ static void sm_run(void){
|
||||
uint8_t buffer[11];
|
||||
buffer[0] = SM_CODE_MASTER_IDENTIFICATION;
|
||||
little_endian_store_16(buffer, 1, setup->sm_local_ediv);
|
||||
swap64(setup->sm_local_rand, &buffer[3]);
|
||||
reverse_64(setup->sm_local_rand, &buffer[3]);
|
||||
l2cap_send_connectionless(connection->sm_handle, L2CAP_CID_SECURITY_MANAGER_PROTOCOL, (uint8_t*) buffer, sizeof(buffer));
|
||||
sm_timeout_reset(connection);
|
||||
return;
|
||||
@ -1522,7 +1522,7 @@ static void sm_run(void){
|
||||
setup->sm_key_distribution_send_set &= ~SM_KEYDIST_FLAG_IDENTITY_INFORMATION;
|
||||
uint8_t buffer[17];
|
||||
buffer[0] = SM_CODE_IDENTITY_INFORMATION;
|
||||
swap128(sm_persistent_irk, &buffer[1]);
|
||||
reverse_128(sm_persistent_irk, &buffer[1]);
|
||||
l2cap_send_connectionless(connection->sm_handle, L2CAP_CID_SECURITY_MANAGER_PROTOCOL, (uint8_t*) buffer, sizeof(buffer));
|
||||
sm_timeout_reset(connection);
|
||||
return;
|
||||
@ -1548,7 +1548,7 @@ static void sm_run(void){
|
||||
|
||||
uint8_t buffer[17];
|
||||
buffer[0] = SM_CODE_SIGNING_INFORMATION;
|
||||
swap128(setup->sm_local_csrk, &buffer[1]);
|
||||
reverse_128(setup->sm_local_csrk, &buffer[1]);
|
||||
l2cap_send_connectionless(connection->sm_handle, L2CAP_CID_SECURITY_MANAGER_PROTOCOL, (uint8_t*) buffer, sizeof(buffer));
|
||||
sm_timeout_reset(connection);
|
||||
return;
|
||||
@ -1589,7 +1589,7 @@ static void sm_handle_encryption_result(uint8_t * data){
|
||||
sm_address_resolution_ah_calculation_active = 0;
|
||||
// compare calulated address against connecting device
|
||||
uint8_t hash[3];
|
||||
swap24(data, hash);
|
||||
reverse_24(data, hash);
|
||||
if (memcmp(&sm_address_resolution_address[3], hash, 3) == 0){
|
||||
log_info("LE Device Lookup: matched resolvable private address");
|
||||
sm_address_resolution_handle_event(ADDRESS_RESOLUTION_SUCEEDED);
|
||||
@ -1602,12 +1602,12 @@ static void sm_handle_encryption_result(uint8_t * data){
|
||||
|
||||
switch (dkg_state){
|
||||
case DKG_W4_IRK:
|
||||
swap128(data, sm_persistent_irk);
|
||||
reverse_128(data, sm_persistent_irk);
|
||||
log_key("irk", sm_persistent_irk);
|
||||
dkg_next_state();
|
||||
return;
|
||||
case DKG_W4_DHK:
|
||||
swap128(data, sm_persistent_dhk);
|
||||
reverse_128(data, sm_persistent_dhk);
|
||||
log_key("dhk", sm_persistent_dhk);
|
||||
dkg_next_state();
|
||||
// SM Init Finished
|
||||
@ -1618,7 +1618,7 @@ static void sm_handle_encryption_result(uint8_t * data){
|
||||
|
||||
switch (rau_state){
|
||||
case RAU_W4_ENC:
|
||||
swap24(data, &sm_random_address[3]);
|
||||
reverse_24(data, &sm_random_address[3]);
|
||||
rau_next_state();
|
||||
return;
|
||||
default:
|
||||
@ -1631,7 +1631,7 @@ static void sm_handle_encryption_result(uint8_t * data){
|
||||
case CMAC_W4_MLAST:
|
||||
{
|
||||
sm_key_t t;
|
||||
swap128(data, t);
|
||||
reverse_128(data, t);
|
||||
sm_cmac_handle_encryption_result(t);
|
||||
}
|
||||
return;
|
||||
@ -1647,20 +1647,20 @@ static void sm_handle_encryption_result(uint8_t * data){
|
||||
case SM_PH2_C1_W4_ENC_C:
|
||||
{
|
||||
sm_key_t t2;
|
||||
swap128(data, t2);
|
||||
reverse_128(data, t2);
|
||||
sm_c1_t3(t2, setup->sm_m_address, setup->sm_s_address, setup->sm_c1_t3_value);
|
||||
}
|
||||
sm_next_responding_state(connection);
|
||||
return;
|
||||
case SM_PH2_C1_W4_ENC_B:
|
||||
swap128(data, setup->sm_local_confirm);
|
||||
reverse_128(data, setup->sm_local_confirm);
|
||||
log_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;
|
||||
swap128(data, peer_confirm_test);
|
||||
reverse_128(data, peer_confirm_test);
|
||||
log_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;
|
||||
@ -1675,7 +1675,7 @@ static void sm_handle_encryption_result(uint8_t * data){
|
||||
}
|
||||
return;
|
||||
case SM_PH2_W4_STK:
|
||||
swap128(data, setup->sm_ltk);
|
||||
reverse_128(data, setup->sm_ltk);
|
||||
sm_truncate_key(setup->sm_ltk, connection->sm_actual_encryption_key_size);
|
||||
log_key("stk", setup->sm_ltk);
|
||||
if (connection->sm_role){
|
||||
@ -1686,7 +1686,7 @@ static void sm_handle_encryption_result(uint8_t * data){
|
||||
return;
|
||||
case SM_PH3_Y_W4_ENC:{
|
||||
sm_key_t y128;
|
||||
swap128(data, y128);
|
||||
reverse_128(data, y128);
|
||||
setup->sm_local_y = big_endian_read_16(y128, 14);
|
||||
log_info_hex16("y", setup->sm_local_y);
|
||||
// PH3B3 - calculate EDIV
|
||||
@ -1699,7 +1699,7 @@ static void sm_handle_encryption_result(uint8_t * data){
|
||||
}
|
||||
case SM_RESPONDER_PH4_Y_W4_ENC:{
|
||||
sm_key_t y128;
|
||||
swap128(data, y128);
|
||||
reverse_128(data, y128);
|
||||
setup->sm_local_y = big_endian_read_16(y128, 14);
|
||||
log_info_hex16("y", setup->sm_local_y);
|
||||
|
||||
@ -1712,13 +1712,13 @@ static void sm_handle_encryption_result(uint8_t * data){
|
||||
return;
|
||||
}
|
||||
case SM_PH3_LTK_W4_ENC:
|
||||
swap128(data, setup->sm_ltk);
|
||||
reverse_128(data, setup->sm_ltk);
|
||||
log_key("ltk", setup->sm_ltk);
|
||||
// calc CSRK next
|
||||
connection->sm_engine_state = SM_PH3_CSRK_GET_ENC;
|
||||
return;
|
||||
case SM_PH3_CSRK_W4_ENC:
|
||||
swap128(data, setup->sm_local_csrk);
|
||||
reverse_128(data, setup->sm_local_csrk);
|
||||
log_key("csrk", setup->sm_local_csrk);
|
||||
if (setup->sm_key_distribution_send_set){
|
||||
connection->sm_engine_state = SM_PH3_DISTRIBUTE_KEYS;
|
||||
@ -1735,7 +1735,7 @@ static void sm_handle_encryption_result(uint8_t * data){
|
||||
}
|
||||
return;
|
||||
case SM_RESPONDER_PH4_LTK_W4_ENC:
|
||||
swap128(data, setup->sm_ltk);
|
||||
reverse_128(data, setup->sm_ltk);
|
||||
sm_truncate_key(setup->sm_ltk, connection->sm_actual_encryption_key_size);
|
||||
log_key("ltk", setup->sm_ltk);
|
||||
connection->sm_engine_state = SM_RESPONDER_PH4_SEND_LTK;
|
||||
@ -1808,7 +1808,7 @@ static void sm_handle_random_result(uint8_t * data){
|
||||
connection->sm_engine_state = SM_PH2_C1_GET_ENC_A;
|
||||
return;
|
||||
case SM_PH3_W4_RANDOM:
|
||||
swap64(data, setup->sm_local_rand);
|
||||
reverse_64(data, setup->sm_local_rand);
|
||||
// no db for encryption size hack: encryption size is stored in lowest nibble of setup->sm_local_rand
|
||||
setup->sm_local_rand[7] = (setup->sm_local_rand[7] & 0xf0) + (connection->sm_actual_encryption_key_size - 1);
|
||||
// no db for authenticated flag hack: store flag in bit 4 of LSB
|
||||
@ -1912,7 +1912,7 @@ static void sm_event_packet_handler (uint8_t packet_type, uint16_t channel, uint
|
||||
}
|
||||
|
||||
// store rand and ediv
|
||||
swap64(&packet[5], sm_conn->sm_local_rand);
|
||||
reverse_64(&packet[5], sm_conn->sm_local_rand);
|
||||
sm_conn->sm_local_ediv = little_endian_read_16(packet, 13);
|
||||
sm_conn->sm_engine_state = SM_RESPONDER_PH0_RECEIVED_LTK;
|
||||
break;
|
||||
@ -2136,7 +2136,7 @@ static void sm_pdu_handler(uint8_t packet_type, uint16_t handle, uint8_t *packet
|
||||
}
|
||||
|
||||
// store s_confirm
|
||||
swap128(&packet[1], setup->sm_peer_confirm);
|
||||
reverse_128(&packet[1], setup->sm_peer_confirm);
|
||||
sm_conn->sm_engine_state = SM_PH2_SEND_PAIRING_RANDOM;
|
||||
break;
|
||||
|
||||
@ -2147,7 +2147,7 @@ static void sm_pdu_handler(uint8_t packet_type, uint16_t handle, uint8_t *packet
|
||||
}
|
||||
|
||||
// received random value
|
||||
swap128(&packet[1], setup->sm_peer_random);
|
||||
reverse_128(&packet[1], setup->sm_peer_random);
|
||||
sm_conn->sm_engine_state = SM_PH2_C1_GET_ENC_C;
|
||||
break;
|
||||
|
||||
@ -2172,7 +2172,7 @@ static void sm_pdu_handler(uint8_t packet_type, uint16_t handle, uint8_t *packet
|
||||
}
|
||||
|
||||
// received confirm value
|
||||
swap128(&packet[1], setup->sm_peer_confirm);
|
||||
reverse_128(&packet[1], setup->sm_peer_confirm);
|
||||
|
||||
// notify client to hide shown passkey
|
||||
if (setup->sm_stk_generation_method == PK_INIT_INPUT){
|
||||
@ -2203,7 +2203,7 @@ static void sm_pdu_handler(uint8_t packet_type, uint16_t handle, uint8_t *packet
|
||||
}
|
||||
|
||||
// received random value
|
||||
swap128(&packet[1], setup->sm_peer_random);
|
||||
reverse_128(&packet[1], setup->sm_peer_random);
|
||||
sm_conn->sm_engine_state = SM_PH2_C1_GET_ENC_C;
|
||||
break;
|
||||
|
||||
@ -2211,18 +2211,18 @@ static void sm_pdu_handler(uint8_t packet_type, uint16_t handle, uint8_t *packet
|
||||
switch(packet[0]){
|
||||
case SM_CODE_ENCRYPTION_INFORMATION:
|
||||
setup->sm_key_distribution_received_set |= SM_KEYDIST_FLAG_ENCRYPTION_INFORMATION;
|
||||
swap128(&packet[1], setup->sm_peer_ltk);
|
||||
reverse_128(&packet[1], setup->sm_peer_ltk);
|
||||
break;
|
||||
|
||||
case SM_CODE_MASTER_IDENTIFICATION:
|
||||
setup->sm_key_distribution_received_set |= SM_KEYDIST_FLAG_MASTER_IDENTIFICATION;
|
||||
setup->sm_peer_ediv = little_endian_read_16(packet, 1);
|
||||
swap64(&packet[3], setup->sm_peer_rand);
|
||||
reverse_64(&packet[3], setup->sm_peer_rand);
|
||||
break;
|
||||
|
||||
case SM_CODE_IDENTITY_INFORMATION:
|
||||
setup->sm_key_distribution_received_set |= SM_KEYDIST_FLAG_IDENTITY_INFORMATION;
|
||||
swap128(&packet[1], setup->sm_peer_irk);
|
||||
reverse_128(&packet[1], setup->sm_peer_irk);
|
||||
break;
|
||||
|
||||
case SM_CODE_IDENTITY_ADDRESS_INFORMATION:
|
||||
@ -2233,7 +2233,7 @@ static void sm_pdu_handler(uint8_t packet_type, uint16_t handle, uint8_t *packet
|
||||
|
||||
case SM_CODE_SIGNING_INFORMATION:
|
||||
setup->sm_key_distribution_received_set |= SM_KEYDIST_FLAG_SIGNING_IDENTIFICATION;
|
||||
swap128(&packet[1], setup->sm_peer_csrk);
|
||||
reverse_128(&packet[1], setup->sm_peer_csrk);
|
||||
break;
|
||||
default:
|
||||
// Unexpected PDU
|
||||
|
@ -74,7 +74,7 @@ static inline uint8_t l2cap_event_channel_opened_get_status(const uint8_t * even
|
||||
* @note: btstack_type B
|
||||
*/
|
||||
static inline void l2cap_event_channel_opened_get_address(const uint8_t * event, bd_addr_t address){
|
||||
swap48(&event[3], address);
|
||||
reverse_48(&event[3], address);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -174,7 +174,7 @@ static inline uint8_t l2cap_event_incoming_connection_get_status(const uint8_t *
|
||||
* @note: btstack_type B
|
||||
*/
|
||||
static inline void l2cap_event_incoming_connection_get_address(const uint8_t * event, bd_addr_t address){
|
||||
swap48(&event[3], address);
|
||||
reverse_48(&event[3], address);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -324,7 +324,7 @@ static inline uint8_t rfcomm_event_open_channel_complete_get_status(const uint8_
|
||||
* @note: btstack_type B
|
||||
*/
|
||||
static inline void rfcomm_event_open_channel_complete_get_bd_addr(const uint8_t * event, bd_addr_t bd_addr){
|
||||
swap48(&event[3], bd_addr);
|
||||
reverse_48(&event[3], bd_addr);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -384,7 +384,7 @@ static inline uint16_t rfcomm_event_channel_closed_get_rfcomm_cid(const uint8_t
|
||||
* @note: btstack_type B
|
||||
*/
|
||||
static inline void rfcomm_event_incoming_connection_get_bd_addr(const uint8_t * event, bd_addr_t bd_addr){
|
||||
swap48(&event[2], bd_addr);
|
||||
reverse_48(&event[2], bd_addr);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -714,7 +714,7 @@ static inline uint8_t sm_event_just_works_request_get_addr_type(const uint8_t *
|
||||
* @note: btstack_type B
|
||||
*/
|
||||
static inline void sm_event_just_works_request_get_address(const uint8_t * event, bd_addr_t address){
|
||||
swap48(&event[5], address);
|
||||
reverse_48(&event[5], address);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -744,7 +744,7 @@ static inline uint8_t sm_event_just_works_cancel_get_addr_type(const uint8_t * e
|
||||
* @note: btstack_type B
|
||||
*/
|
||||
static inline void sm_event_just_works_cancel_get_address(const uint8_t * event, bd_addr_t address){
|
||||
swap48(&event[5], address);
|
||||
reverse_48(&event[5], address);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -774,7 +774,7 @@ static inline uint8_t sm_event_passkey_display_number_get_addr_type(const uint8_
|
||||
* @note: btstack_type B
|
||||
*/
|
||||
static inline void sm_event_passkey_display_number_get_address(const uint8_t * event, bd_addr_t address){
|
||||
swap48(&event[5], address);
|
||||
reverse_48(&event[5], address);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -814,7 +814,7 @@ static inline uint8_t sm_event_passkey_display_cancel_get_addr_type(const uint8_
|
||||
* @note: btstack_type B
|
||||
*/
|
||||
static inline void sm_event_passkey_display_cancel_get_address(const uint8_t * event, bd_addr_t address){
|
||||
swap48(&event[5], address);
|
||||
reverse_48(&event[5], address);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -844,7 +844,7 @@ static inline uint8_t sm_event_passkey_input_number_get_addr_type(const uint8_t
|
||||
* @note: btstack_type B
|
||||
*/
|
||||
static inline void sm_event_passkey_input_number_get_address(const uint8_t * event, bd_addr_t address){
|
||||
swap48(&event[5], address);
|
||||
reverse_48(&event[5], address);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -874,7 +874,7 @@ static inline uint8_t sm_event_passkey_input_cancel_get_addr_type(const uint8_t
|
||||
* @note: btstack_type B
|
||||
*/
|
||||
static inline void sm_event_passkey_input_cancel_get_address(const uint8_t * event, bd_addr_t address){
|
||||
swap48(&event[5], address);
|
||||
reverse_48(&event[5], address);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -904,7 +904,7 @@ static inline uint8_t sm_event_identity_resolving_started_get_addr_type(const ui
|
||||
* @note: btstack_type B
|
||||
*/
|
||||
static inline void sm_event_identity_resolving_started_get_address(const uint8_t * event, bd_addr_t address){
|
||||
swap48(&event[5], address);
|
||||
reverse_48(&event[5], address);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -934,7 +934,7 @@ static inline uint8_t sm_event_identity_resolving_failed_get_addr_type(const uin
|
||||
* @note: btstack_type B
|
||||
*/
|
||||
static inline void sm_event_identity_resolving_failed_get_address(const uint8_t * event, bd_addr_t address){
|
||||
swap48(&event[5], address);
|
||||
reverse_48(&event[5], address);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -964,7 +964,7 @@ static inline uint8_t sm_event_identity_resolving_succeeded_get_addr_type(const
|
||||
* @note: btstack_type B
|
||||
*/
|
||||
static inline void sm_event_identity_resolving_succeeded_get_address(const uint8_t * event, bd_addr_t address){
|
||||
swap48(&event[5], address);
|
||||
reverse_48(&event[5], address);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1004,7 +1004,7 @@ static inline uint8_t sm_event_authorization_request_get_addr_type(const uint8_t
|
||||
* @note: btstack_type B
|
||||
*/
|
||||
static inline void sm_event_authorization_request_get_address(const uint8_t * event, bd_addr_t address){
|
||||
swap48(&event[5], address);
|
||||
reverse_48(&event[5], address);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1034,7 +1034,7 @@ static inline uint8_t sm_event_authorization_result_get_addr_type(const uint8_t
|
||||
* @note: btstack_type B
|
||||
*/
|
||||
static inline void sm_event_authorization_result_get_address(const uint8_t * event, bd_addr_t address){
|
||||
swap48(&event[5], address);
|
||||
reverse_48(&event[5], address);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -122,25 +122,25 @@ void bt_flip_addr(bd_addr_t dest, bd_addr_t src){
|
||||
}
|
||||
|
||||
// general swap/endianess utils
|
||||
void swapX(const uint8_t *src, uint8_t *dst, int len){
|
||||
void reverse_bytes(const uint8_t *src, uint8_t *dst, int len){
|
||||
int i;
|
||||
for (i = 0; i < len; i++)
|
||||
dst[len - 1 - i] = src[i];
|
||||
}
|
||||
void swap24(const uint8_t * src, uint8_t * dst){
|
||||
swapX(src, dst, 3);
|
||||
void reverse_24(const uint8_t * src, uint8_t * dst){
|
||||
reverse_bytes(src, dst, 3);
|
||||
}
|
||||
void swap48(const uint8_t * src, uint8_t * dst){
|
||||
swapX(src, dst, 6);
|
||||
void reverse_48(const uint8_t * src, uint8_t * dst){
|
||||
reverse_bytes(src, dst, 6);
|
||||
}
|
||||
void swap56(const uint8_t * src, uint8_t * dst){
|
||||
swapX(src, dst, 7);
|
||||
void reverse_56(const uint8_t * src, uint8_t * dst){
|
||||
reverse_bytes(src, dst, 7);
|
||||
}
|
||||
void swap64(const uint8_t * src, uint8_t * dst){
|
||||
swapX(src, dst, 8);
|
||||
void reverse_64(const uint8_t * src, uint8_t * dst){
|
||||
reverse_bytes(src, dst, 8);
|
||||
}
|
||||
void swap128(const uint8_t * src, uint8_t * dst){
|
||||
swapX(src, dst, 16);
|
||||
void reverse_128(const uint8_t * src, uint8_t * dst){
|
||||
reverse_bytes(src, dst, 16);
|
||||
}
|
||||
|
||||
char char_for_nibble(int nibble){
|
||||
@ -159,33 +159,6 @@ void printf_hexdump(const void *data, int size){
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void hexdumpf(const void *data, int size){
|
||||
char buffer[6*16+1];
|
||||
int i, j;
|
||||
|
||||
uint8_t low = 0x0F;
|
||||
uint8_t high = 0xF0;
|
||||
j = 0;
|
||||
for (i=0; i<size;i++){
|
||||
uint8_t byte = ((uint8_t *)data)[i];
|
||||
buffer[j++] = '0';
|
||||
buffer[j++] = 'x';
|
||||
buffer[j++] = char_for_nibble((byte & high) >> 4);
|
||||
buffer[j++] = char_for_nibble(byte & low);
|
||||
buffer[j++] = ',';
|
||||
buffer[j++] = ' ';
|
||||
if (j >= 6*16 ){
|
||||
buffer[j] = 0;
|
||||
printf("%s\n", buffer);
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
if (j != 0){
|
||||
buffer[j] = 0;
|
||||
printf("%s\n", buffer);
|
||||
}
|
||||
}
|
||||
|
||||
// void log_info_hexdump(..){
|
||||
//
|
||||
// }
|
||||
|
@ -58,9 +58,9 @@ extern "C" {
|
||||
#include "btstack_defines.h"
|
||||
#include "btstack_linked_list.h"
|
||||
|
||||
// hack: compilation with the android ndk causes an error as there's a swap64 macro
|
||||
#ifdef swap64
|
||||
#undef swap64
|
||||
// hack: compilation with the android ndk causes an error as there's a reverse_64 macro
|
||||
#ifdef reverse_64
|
||||
#undef reverse_64
|
||||
#endif
|
||||
|
||||
// will be moved to daemon/btstack_device_name_db.h
|
||||
@ -112,13 +112,23 @@ void big_endian_store_32(uint8_t *buffer, uint16_t pos, uint32_t value);
|
||||
|
||||
/**
|
||||
* @brief Copy from source to destination and reverse byte order
|
||||
* @param src
|
||||
* @param dest
|
||||
* @param len
|
||||
*/
|
||||
void swapX (const uint8_t *src, uint8_t * dst, int len);
|
||||
void swap24 (const uint8_t *src, uint8_t * dst);
|
||||
void swap48 (const uint8_t *src, uint8_t * dst);
|
||||
void swap56 (const uint8_t *src, uint8_t * dst);
|
||||
void swap64 (const uint8_t *src, uint8_t * dst);
|
||||
void swap128(const uint8_t *src, uint8_t * dst);
|
||||
void reverse_bytes (const uint8_t *src, uint8_t * dest, int len);
|
||||
|
||||
/**
|
||||
* @brief Wrapper around reverse_bytes for common buffer sizes
|
||||
* @param src
|
||||
* @param dest
|
||||
*/
|
||||
void reverse_24 (const uint8_t *src, uint8_t * dest);
|
||||
void reverse_48 (const uint8_t *src, uint8_t * dest);
|
||||
void reverse_56 (const uint8_t *src, uint8_t * dest);
|
||||
void reverse_64 (const uint8_t *src, uint8_t * dest);
|
||||
void reverse_128(const uint8_t *src, uint8_t * dest);
|
||||
|
||||
void bt_flip_addr(bd_addr_t dest, bd_addr_t src);
|
||||
|
||||
/**
|
||||
@ -153,7 +163,6 @@ void log_key(const char * name, sm_key_t key);
|
||||
|
||||
//
|
||||
void hexdump(const void *data, int size);
|
||||
void hexdumpf(const void *data, int size);
|
||||
|
||||
/**
|
||||
* @brief Create human readable representation for UUID128
|
||||
|
@ -102,7 +102,6 @@ TEST(AttDbUtil, LeCounterDb){
|
||||
uint8_t * addr = att_db_util_get_address();
|
||||
uint16_t size = att_db_util_get_size();
|
||||
|
||||
// hexdumpf(addr, size);
|
||||
CHECK_EQUAL(size, (uint16_t)sizeof(profile_data));
|
||||
CHECK_EQUAL_ARRAY(profile_data, addr, size);
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ static void handle_ble_client_event(uint8_t packet_type, uint16_t channel, uint8
|
||||
service.start_group_handle = little_endian_read_16(packet, 4);
|
||||
service.end_group_handle = little_endian_read_16(packet, 6);
|
||||
service.uuid16 = 0;
|
||||
swap128(&packet[8], service.uuid128);
|
||||
reverse_128(&packet[8], service.uuid128);
|
||||
if (uuid_has_bluetooth_prefix(service.uuid128)){
|
||||
service.uuid16 = big_endian_read_32(service.uuid128, 0);
|
||||
}
|
||||
@ -172,7 +172,7 @@ static void handle_ble_client_event(uint8_t packet_type, uint16_t channel, uint8
|
||||
service.start_group_handle = little_endian_read_16(packet, 6);
|
||||
service.end_group_handle = little_endian_read_16(packet, 8);
|
||||
service.uuid16 = 0;
|
||||
swap128(&packet[10], service.uuid128);
|
||||
reverse_128(&packet[10], service.uuid128);
|
||||
if (uuid_has_bluetooth_prefix(service.uuid128)){
|
||||
service.uuid16 = big_endian_read_32(service.uuid128, 0);
|
||||
}
|
||||
@ -185,7 +185,7 @@ static void handle_ble_client_event(uint8_t packet_type, uint16_t channel, uint8
|
||||
characteristic.end_handle = little_endian_read_16(packet, 8);
|
||||
characteristic.properties = little_endian_read_16(packet, 10);
|
||||
characteristic.uuid16 = 0;
|
||||
swap128(&packet[12], characteristic.uuid128);
|
||||
reverse_128(&packet[12], characteristic.uuid128);
|
||||
if (uuid_has_bluetooth_prefix(characteristic.uuid128)){
|
||||
characteristic.uuid16 = big_endian_read_32(characteristic.uuid128, 0);
|
||||
}
|
||||
@ -194,7 +194,7 @@ static void handle_ble_client_event(uint8_t packet_type, uint16_t channel, uint8
|
||||
break;
|
||||
case GATT_EVENT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT:
|
||||
descriptor.handle = little_endian_read_16(packet, 4);
|
||||
swap128(&packet[6], descriptor.uuid128);
|
||||
reverse_128(&packet[6], descriptor.uuid128);
|
||||
if (uuid_has_bluetooth_prefix(descriptor.uuid128)){
|
||||
descriptor.uuid16 = big_endian_read_32(descriptor.uuid128, 0);
|
||||
}
|
||||
|
@ -413,7 +413,7 @@ static void extract_service(le_service_t * aService, uint8_t * data){
|
||||
aService->start_group_handle = little_endian_read_16(data, 0);
|
||||
aService->end_group_handle = little_endian_read_16(data, 2);
|
||||
aService->uuid16 = 0;
|
||||
swap128(&data[4], aService->uuid128);
|
||||
reverse_128(&data[4], aService->uuid128);
|
||||
if (uuid_has_bluetooth_prefix(aService->uuid128)){
|
||||
aService->uuid16 = big_endian_read_32(aService->uuid128, 0);
|
||||
}
|
||||
@ -425,7 +425,7 @@ static void extract_characteristic(le_characteristic_t * characteristic, uint8_t
|
||||
characteristic->end_handle = little_endian_read_16(packet, 8);
|
||||
characteristic->properties = little_endian_read_16(packet, 10);
|
||||
characteristic->uuid16 = 0;
|
||||
swap128(&packet[12], characteristic->uuid128);
|
||||
reverse_128(&packet[12], characteristic->uuid128);
|
||||
if (uuid_has_bluetooth_prefix(characteristic->uuid128)){
|
||||
characteristic->uuid16 = big_endian_read_32(characteristic->uuid128, 0);
|
||||
}
|
||||
@ -515,7 +515,7 @@ static void handle_gatt_client_event(uint8_t packet_type, uint8_t *packet, uint1
|
||||
case GATT_EVENT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT: {
|
||||
uint16_t descriptor_handle = little_endian_read_16(packet, 4);
|
||||
uint8_t uuid128[16];
|
||||
swap128(&packet[6], uuid128);
|
||||
reverse_128(&packet[6], uuid128);
|
||||
if (uuid_has_bluetooth_prefix(uuid128)){
|
||||
printf("Characteristic descriptor at 0x%04x with UUID %04x\n", descriptor_handle, big_endian_read_32(uuid128, 0));
|
||||
} else {
|
||||
@ -557,7 +557,7 @@ static void handle_gatt_client_event(uint8_t packet_type, uint8_t *packet, uint1
|
||||
printf("%04x\n", little_endian_read_16(value, 3));
|
||||
} else {
|
||||
uint8_t uuid128[16];
|
||||
swap128(&value[3], uuid128);
|
||||
reverse_128(&value[3], uuid128);
|
||||
printUUID128(uuid128);
|
||||
printf("\n");
|
||||
}
|
||||
@ -953,7 +953,7 @@ static void att_signed_write_handle_cmac_result(uint8_t hash[8]){
|
||||
little_endian_store_16(request, 1, pts_signed_write_characteristic_handle);
|
||||
memcpy(&request[3], signed_write_value, value_length);
|
||||
little_endian_store_32(request, 3 + value_length, 0);
|
||||
swap64(hash, &request[3 + value_length + 4]);
|
||||
reverse_64(hash, &request[3 + value_length + 4]);
|
||||
l2cap_send_prepared_connectionless(handle, L2CAP_CID_ATTRIBUTE_PROTOCOL, 3 + value_length + 12);
|
||||
}
|
||||
|
||||
|
@ -137,6 +137,33 @@ static uint8_t panu_sdp_record[200];
|
||||
|
||||
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||
|
||||
static void hexdumpf(const void *data, int size){
|
||||
char buffer[6*16+1];
|
||||
int i, j;
|
||||
|
||||
uint8_t low = 0x0F;
|
||||
uint8_t high = 0xF0;
|
||||
j = 0;
|
||||
for (i=0; i<size;i++){
|
||||
uint8_t byte = ((uint8_t *)data)[i];
|
||||
buffer[j++] = '0';
|
||||
buffer[j++] = 'x';
|
||||
buffer[j++] = char_for_nibble((byte & high) >> 4);
|
||||
buffer[j++] = char_for_nibble(byte & low);
|
||||
buffer[j++] = ',';
|
||||
buffer[j++] = ' ';
|
||||
if (j >= 6*16 ){
|
||||
buffer[j] = 0;
|
||||
printf("%s\n", buffer);
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
if (j != 0){
|
||||
buffer[j] = 0;
|
||||
printf("%s\n", buffer);
|
||||
}
|
||||
}
|
||||
|
||||
static uint16_t setup_ethernet_header(int src_compressed, int dst_compressed, int broadcast, uint16_t network_protocol_type){
|
||||
// setup packet
|
||||
int pos = 0;
|
||||
|
@ -70,7 +70,7 @@ void aes128_report_result(void){
|
||||
uint8_t le_enc_result[22];
|
||||
uint8_t enc1_data[] = { 0x0e, 0x14, 0x01, 0x17, 0x20, 0x00 };
|
||||
memcpy (le_enc_result, enc1_data, 6);
|
||||
swap128(aes128_cyphertext, &le_enc_result[6]);
|
||||
reverse_128(aes128_cyphertext, &le_enc_result[6]);
|
||||
mock_simulate_hci_event(&le_enc_result[0], sizeof(le_enc_result));
|
||||
}
|
||||
|
||||
@ -168,12 +168,12 @@ int hci_send_cmd(const hci_cmd_t *cmd, ...){
|
||||
if (cmd->opcode == hci_le_encrypt.opcode){
|
||||
uint8_t * key_flipped = &packet_buffer[3];
|
||||
uint8_t key[16];
|
||||
swap128(key_flipped, key);
|
||||
reverse_128(key_flipped, key);
|
||||
// printf("le_encrypt key ");
|
||||
// hexdump(key, 16);
|
||||
uint8_t * plaintext_flipped = &packet_buffer[19];
|
||||
uint8_t plaintext[16];
|
||||
swap128(plaintext_flipped, plaintext);
|
||||
reverse_128(plaintext_flipped, plaintext);
|
||||
// printf("le_encrypt txt ");
|
||||
// hexdump(plaintext, 16);
|
||||
aes128_calc_cyphertext(key, plaintext, aes128_cyphertext);
|
||||
|
@ -136,7 +136,7 @@ param_read = {
|
||||
'3' : 'return little_endian_read_24(event, {offset});',
|
||||
'4' : 'return little_endian_read_32(event, {offset});',
|
||||
'H' : 'return little_endian_read_16(event, {offset});',
|
||||
'B' : 'swap48(&event[{offset}], {result_name});',
|
||||
'B' : 'reverse_48(&event[{offset}], {result_name});',
|
||||
'R' : 'return &event[{offset}];',
|
||||
'T' : 'return (const char *) &event[{offset}];',
|
||||
'V' : 'return &event[{offset}];',
|
||||
|
Loading…
x
Reference in New Issue
Block a user