sm: add identity_addr and identiy_addr_type to SM_EVENT_IDENTITY_RESOLVING_SUCCEEDED. Also emit SM_EVENT_IDENTITY_CREATED during pairing

This commit is contained in:
Matthias Ringwald 2016-10-27 11:11:40 +02:00
parent 4231322a14
commit 13377825df
2 changed files with 76 additions and 9 deletions

View File

@ -48,6 +48,7 @@
#include "btstack_memory.h"
#include "gap.h"
#include "hci.h"
#include "hci_dump.h"
#include "l2cap.h"
#ifdef ENABLE_LE_SECURE_CONNECTIONS
@ -662,6 +663,8 @@ static void sm_setup_event_base(uint8_t * event, int event_size, uint8_t type, h
}
static void sm_dispatch_event(uint8_t packet_type, uint16_t channel, uint8_t * packet, uint16_t size){
// log event
hci_dump_packet(packet_type, 1, packet, size);
// dispatch to all event handlers
btstack_linked_list_iterator_t it;
btstack_linked_list_iterator_init(&it, &sm_event_handlers);
@ -685,9 +688,15 @@ static void sm_notify_client_passkey(uint8_t type, hci_con_handle_t con_handle,
}
static void sm_notify_client_index(uint8_t type, hci_con_handle_t con_handle, uint8_t addr_type, bd_addr_t address, uint16_t index){
uint8_t event[13];
// fetch addr and addr type from db
bd_addr_t identity_address;
int identity_address_type;
le_device_db_info(index, &identity_address_type, identity_address, NULL);
uint8_t event[18];
sm_setup_event_base(event, sizeof(event), type, con_handle, addr_type, address);
little_endian_store_16(event, 11, index);
event[11] = identity_address_type;
reverse_bd_addr(identity_address, &event[12]);
sm_dispatch_event(HCI_EVENT_PACKET, 0, event, sizeof(event));
}
@ -1267,6 +1276,8 @@ static void sm_key_distribution_handle_all_received(sm_connection_t * sm_conn){
le_db_index = le_device_db_add(setup->sm_peer_addr_type, setup->sm_peer_address, setup->sm_peer_irk);
}
sm_notify_client_index(SM_EVENT_IDENTITY_CREATED, sm_conn->sm_handle, setup->sm_peer_addr_type, setup->sm_peer_address, le_db_index);
if (le_db_index >= 0){
// store local CSRK
@ -2896,8 +2907,7 @@ static void sm_event_packet_handler (uint8_t packet_type, uint16_t channel, uint
sm_conn->sm_handle = con_handle;
sm_conn->sm_role = packet[6];
sm_conn->sm_peer_addr_type = packet[7];
reverse_bd_addr(&packet[8],
sm_conn->sm_peer_address);
reverse_bd_addr(&packet[8], sm_conn->sm_peer_address);
log_info("New sm_conn, role %s", sm_conn->sm_role ? "slave" : "master");

View File

@ -2599,13 +2599,22 @@ static inline void sm_event_identity_resolving_succeeded_get_address(const uint8
reverse_bd_addr(&event[5], address);
}
/**
* @brief Get field le_device_db_index from event SM_EVENT_IDENTITY_RESOLVING_SUCCEEDED
* @brief Get field identity_addr_type from event SM_EVENT_IDENTITY_RESOLVING_SUCCEEDED
* @param event packet
* @return le_device_db_index
* @note: btstack_type 2
* @return identity_addr_type
* @note: btstack_type 1
*/
static inline uint16_t sm_event_identity_resolving_succeeded_get_le_device_db_index(const uint8_t * event){
return little_endian_read_16(event, 11);
static inline uint8_t sm_event_identity_resolving_succeeded_get_identity_addr_type(const uint8_t * event){
return event[11];
}
/**
* @brief Get field identity_address from event SM_EVENT_IDENTITY_RESOLVING_SUCCEEDED
* @param event packet
* @param Pointer to storage for identity_address
* @note: btstack_type B
*/
static inline void sm_event_identity_resolving_succeeded_get_identity_address(const uint8_t * event, bd_addr_t identity_address){
reverse_bd_addr(&event[12], identity_address);
}
#endif
@ -2699,6 +2708,54 @@ static inline uint8_t sm_event_keypress_notification_get_action(const uint8_t *
}
#endif
#ifdef ENABLE_BLE
/**
* @brief Get field handle from event SM_EVENT_IDENTITY_CREATED
* @param event packet
* @return handle
* @note: btstack_type H
*/
static inline hci_con_handle_t sm_event_identity_created_get_handle(const uint8_t * event){
return little_endian_read_16(event, 2);
}
/**
* @brief Get field addr_type from event SM_EVENT_IDENTITY_CREATED
* @param event packet
* @return addr_type
* @note: btstack_type 1
*/
static inline uint8_t sm_event_identity_created_get_addr_type(const uint8_t * event){
return event[4];
}
/**
* @brief Get field address from event SM_EVENT_IDENTITY_CREATED
* @param event packet
* @param Pointer to storage for address
* @note: btstack_type B
*/
static inline void sm_event_identity_created_get_address(const uint8_t * event, bd_addr_t address){
reverse_bd_addr(&event[5], address);
}
/**
* @brief Get field identity_addr_type from event SM_EVENT_IDENTITY_CREATED
* @param event packet
* @return identity_addr_type
* @note: btstack_type 1
*/
static inline uint8_t sm_event_identity_created_get_identity_addr_type(const uint8_t * event){
return event[11];
}
/**
* @brief Get field identity_address from event SM_EVENT_IDENTITY_CREATED
* @param event packet
* @param Pointer to storage for identity_address
* @note: btstack_type B
*/
static inline void sm_event_identity_created_get_identity_address(const uint8_t * event, bd_addr_t identity_address){
reverse_bd_addr(&event[12], identity_address);
}
#endif
/**
* @brief Get field handle from event GAP_EVENT_SECURITY_LEVEL
* @param event packet