mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-25 09:35:42 +00:00
use HCI Event style packet instead of sm_event_t
This commit is contained in:
parent
0dbb2346df
commit
75e30611be
@ -127,6 +127,7 @@ static void att_handle_value_indication_timeout(timer_source_t *ts){
|
||||
|
||||
static void att_event_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||
|
||||
bd_addr_t event_address;
|
||||
switch (packet_type) {
|
||||
|
||||
case HCI_EVENT_PACKET:
|
||||
@ -179,7 +180,7 @@ static void att_event_packet_handler (uint8_t packet_type, uint16_t channel, uin
|
||||
break;
|
||||
case SM_IDENTITY_RESOLVING_SUCCEEDED:
|
||||
att_ir_lookup_active = 0;
|
||||
att_ir_le_device_db_index = ((sm_event_t*) packet)->le_device_db_index;
|
||||
att_ir_le_device_db_index = READ_BT_16(packet, 11);
|
||||
log_info("SM_IDENTITY_RESOLVING_SUCCEEDED id %u", att_ir_le_device_db_index);
|
||||
att_run();
|
||||
break;
|
||||
@ -191,10 +192,10 @@ static void att_event_packet_handler (uint8_t packet_type, uint16_t channel, uin
|
||||
break;
|
||||
|
||||
case SM_AUTHORIZATION_RESULT: {
|
||||
sm_event_t * event = (sm_event_t *) packet;
|
||||
if (event->addr_type != att_client_addr_type) break;
|
||||
if (memcmp(event->address, att_client_address, 6) != 0) break;
|
||||
att_connection.authorized = event->authorization_result;
|
||||
if (packet[4] != att_client_addr_type) break;
|
||||
bt_flip_addr(event_address, &packet[5]);
|
||||
if (memcmp(event_address, att_client_address, 6) != 0) break;
|
||||
att_connection.authorized = packet[11];
|
||||
att_run();
|
||||
break;
|
||||
}
|
||||
|
72
ble/sm.c
72
ble/sm.c
@ -263,7 +263,6 @@ static const stk_generation_method_t stk_generation_method[5][5] = {
|
||||
|
||||
static void sm_run(void);
|
||||
static void sm_done_for_handle(uint16_t handle);
|
||||
static void sm_notify_client(uint8_t type, uint16_t handle, uint8_t addr_type, bd_addr_t address, uint32_t passkey, uint16_t index);
|
||||
static sm_connection_t * sm_get_connection_for_handle(uint16_t handle);
|
||||
static inline int sm_calc_actual_encryption_key_size(int other);
|
||||
static int sm_validate_stk_generation_method(void);
|
||||
@ -464,32 +463,45 @@ static void sm_s1_r_prime(sm_key_t r1, sm_key_t r2, sm_key_t r_prime){
|
||||
memcpy(&r_prime[0], &r1[8], 8);
|
||||
}
|
||||
|
||||
static void sm_notify_client(uint8_t type, uint16_t handle, uint8_t addr_type, bd_addr_t address, uint32_t passkey, uint16_t index){
|
||||
static void sm_setup_event_base(uint8_t * event, int event_size, uint8_t type, uint16_t handle, uint8_t addr_type, bd_addr_t address){
|
||||
event[0] = type;
|
||||
event[1] = event_size - 2;
|
||||
bt_store_16(event, 2, handle);
|
||||
event[4] = addr_type;
|
||||
bt_flip_addr(&event[5], address);
|
||||
}
|
||||
|
||||
sm_event_t event;
|
||||
event.type = type;
|
||||
event.handle = handle;
|
||||
event.addr_type = addr_type;
|
||||
BD_ADDR_COPY(event.address, address);
|
||||
event.passkey = passkey;
|
||||
event.le_device_db_index = index;
|
||||
|
||||
log_info("sm_notify_client %02x, addres_type %u, address %s, num '%06"PRIu32"', index %u", event.type, event.addr_type, bd_addr_to_str(event.address), event.passkey, event.le_device_db_index);
|
||||
static void sm_notify_client_base(uint8_t type, uint16_t handle, uint8_t addr_type, bd_addr_t address){
|
||||
uint8_t event[11];
|
||||
sm_setup_event_base(event, sizeof(event), type, handle, addr_type, address);
|
||||
|
||||
if (!sm_client_packet_handler) return;
|
||||
sm_client_packet_handler(HCI_EVENT_PACKET, 0, (uint8_t*) &event, sizeof(event));
|
||||
sm_client_packet_handler(HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||
}
|
||||
|
||||
static void sm_notify_client_passkey(uint8_t type, uint16_t handle, uint8_t addr_type, bd_addr_t address, uint32_t passkey){
|
||||
uint8_t event[15];
|
||||
sm_setup_event_base(event, sizeof(event), type, handle, addr_type, address);
|
||||
bt_store_32(event, 11, passkey);
|
||||
|
||||
if (!sm_client_packet_handler) return;
|
||||
sm_client_packet_handler(HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||
}
|
||||
|
||||
static void sm_notify_client_index(uint8_t type, uint16_t handle, uint8_t addr_type, bd_addr_t address, uint16_t index){
|
||||
uint8_t event[13];
|
||||
sm_setup_event_base(event, sizeof(event), type, handle, addr_type, address);
|
||||
bt_store_16(event, 11, index);
|
||||
|
||||
if (!sm_client_packet_handler) return;
|
||||
sm_client_packet_handler(HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||
}
|
||||
|
||||
static void sm_notify_client_authorization(uint8_t type, uint16_t handle, uint8_t addr_type, bd_addr_t address, uint8_t result){
|
||||
|
||||
sm_event_t event;
|
||||
event.type = type;
|
||||
event.handle = handle;
|
||||
event.addr_type = addr_type;
|
||||
BD_ADDR_COPY(event.address, address);
|
||||
event.authorization_result = result;
|
||||
|
||||
log_info("sm_notify_client_authorization %02x, address_type %u, address %s, result %u", event.type, event.addr_type, bd_addr_to_str(event.address), event.authorization_result);
|
||||
uint8_t event[18];
|
||||
sm_setup_event_base(event, sizeof(event), type, handle, addr_type, address);
|
||||
event[11] = result;
|
||||
|
||||
if (!sm_client_packet_handler) return;
|
||||
sm_client_packet_handler(HCI_EVENT_PACKET, 0, (uint8_t*) &event, sizeof(event));
|
||||
@ -570,7 +582,7 @@ static void sm_address_resolution_start_lookup(uint8_t addr_type, uint16_t handl
|
||||
sm_address_resolution_test = 0;
|
||||
sm_address_resolution_mode = mode;
|
||||
sm_address_resolution_context = context;
|
||||
sm_notify_client(SM_IDENTITY_RESOLVING_STARTED, handle, addr_type, addr, 0, 0);
|
||||
sm_notify_client_base(SM_IDENTITY_RESOLVING_STARTED, handle, addr_type, addr);
|
||||
}
|
||||
|
||||
int sm_address_resolution_lookup(uint8_t address_type, bd_addr_t address){
|
||||
@ -779,26 +791,26 @@ static void sm_trigger_user_response(sm_connection_t * sm_conn){
|
||||
case PK_RESP_INPUT:
|
||||
if (sm_conn->sm_role){
|
||||
setup->sm_user_response = SM_USER_RESPONSE_PENDING;
|
||||
sm_notify_client(SM_PASSKEY_INPUT_NUMBER, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address, 0, 0);
|
||||
sm_notify_client_base(SM_PASSKEY_INPUT_NUMBER, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address);
|
||||
} else {
|
||||
sm_notify_client(SM_PASSKEY_DISPLAY_NUMBER, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address, READ_NET_32(setup->sm_tk, 12), 0);
|
||||
sm_notify_client_passkey(SM_PASSKEY_DISPLAY_NUMBER, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address, READ_NET_32(setup->sm_tk, 12));
|
||||
}
|
||||
break;
|
||||
case PK_INIT_INPUT:
|
||||
if (sm_conn->sm_role){
|
||||
sm_notify_client(SM_PASSKEY_DISPLAY_NUMBER, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address, READ_NET_32(setup->sm_tk, 12), 0);
|
||||
sm_notify_client_passkey(SM_PASSKEY_DISPLAY_NUMBER, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address, READ_NET_32(setup->sm_tk, 12));
|
||||
} else {
|
||||
setup->sm_user_response = SM_USER_RESPONSE_PENDING;
|
||||
sm_notify_client(SM_PASSKEY_INPUT_NUMBER, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address, 0, 0);
|
||||
sm_notify_client_base(SM_PASSKEY_INPUT_NUMBER, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address);
|
||||
}
|
||||
break;
|
||||
case OK_BOTH_INPUT:
|
||||
setup->sm_user_response = SM_USER_RESPONSE_PENDING;
|
||||
sm_notify_client(SM_PASSKEY_INPUT_NUMBER, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address, 0, 0);
|
||||
sm_notify_client_base(SM_PASSKEY_INPUT_NUMBER, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address);
|
||||
break;
|
||||
case JUST_WORKS:
|
||||
setup->sm_user_response = SM_USER_RESPONSE_PENDING;
|
||||
sm_notify_client(SM_JUST_WORKS_REQUEST, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address, READ_NET_32(setup->sm_tk, 12), 0);
|
||||
sm_notify_client_base(SM_JUST_WORKS_REQUEST, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address);
|
||||
break;
|
||||
case OOB:
|
||||
// client already provided OOB data, let's skip notification.
|
||||
@ -963,10 +975,10 @@ static void sm_address_resolution_handle_event(address_resolution_event_t event)
|
||||
|
||||
switch (event){
|
||||
case ADDRESS_RESOLUTION_SUCEEDED:
|
||||
sm_notify_client(SM_IDENTITY_RESOLVING_SUCCEEDED, handle, sm_address_resolution_addr_type, sm_address_resolution_address, 0, matched_device_id);
|
||||
sm_notify_client_index(SM_IDENTITY_RESOLVING_SUCCEEDED, handle, sm_address_resolution_addr_type, sm_address_resolution_address, matched_device_id);
|
||||
break;
|
||||
case ADDRESS_RESOLUTION_FAILED:
|
||||
sm_notify_client(SM_IDENTITY_RESOLVING_FAILED, handle, sm_address_resolution_addr_type, sm_address_resolution_address, 0, 0);
|
||||
sm_notify_client_base(SM_IDENTITY_RESOLVING_FAILED, handle, sm_address_resolution_addr_type, sm_address_resolution_address);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -2160,7 +2172,7 @@ static void sm_packet_handler(uint8_t packet_type, uint16_t handle, uint8_t *pac
|
||||
|
||||
// notify client to hide shown passkey
|
||||
if (setup->sm_stk_generation_method == PK_INIT_INPUT){
|
||||
sm_notify_client(SM_PASSKEY_DISPLAY_CANCEL, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address, 0, 0);
|
||||
sm_notify_client_base(SM_PASSKEY_DISPLAY_CANCEL, sm_conn->sm_handle, sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address);
|
||||
}
|
||||
|
||||
// handle user cancel pairing?
|
||||
|
13
ble/sm.h
13
ble/sm.h
@ -119,19 +119,6 @@ typedef struct {
|
||||
|
||||
/* API_START */
|
||||
|
||||
/**
|
||||
* @brief Security Manager event
|
||||
*/
|
||||
typedef struct sm_event {
|
||||
uint8_t type; ///< See <btstack/hci_cmds.h> SM_...
|
||||
uint16_t handle;
|
||||
uint8_t addr_type;
|
||||
bd_addr_t address;
|
||||
uint32_t passkey; ///< only used for SM_PASSKEY_DISPLAY_NUMBER
|
||||
uint16_t le_device_db_index; ///< only used for SM_IDENTITY_RESOLVING_..
|
||||
uint8_t authorization_result; ///< only use for SM_AUTHORIZATION_RESULT
|
||||
} sm_event_t;
|
||||
|
||||
/**
|
||||
* @brief Initializes the Security Manager, connects to L2CAP
|
||||
*/
|
||||
|
@ -575,115 +575,93 @@ extern "C" {
|
||||
// data: event(8), len(8)
|
||||
#define BNEP_EVENT_READY_TO_SEND 0xC4
|
||||
|
||||
/** @note same event structure is used for all SM events, unused fields are listed, too */
|
||||
/**
|
||||
* @format H1B
|
||||
* @param handle
|
||||
* @param addr_type
|
||||
* @param address
|
||||
*/
|
||||
#define SM_JUST_WORKS_REQUEST 0xD0
|
||||
|
||||
/**
|
||||
* @format H1B
|
||||
* @param handle
|
||||
* @param addr_type
|
||||
* @param address
|
||||
*/
|
||||
#define SM_JUST_WORKS_CANCEL 0xD1
|
||||
|
||||
/**
|
||||
* @format H1B4
|
||||
* @param handle
|
||||
* @param addr_type
|
||||
* @param address
|
||||
* @param passkey
|
||||
*/
|
||||
#define SM_PASSKEY_DISPLAY_NUMBER 0xD2
|
||||
|
||||
/**
|
||||
* @format H1B
|
||||
* @param handle
|
||||
* @param addr_type
|
||||
* @param address
|
||||
*/
|
||||
#define SM_PASSKEY_DISPLAY_CANCEL 0xD3
|
||||
|
||||
/**
|
||||
* @format H1B421
|
||||
* @param handle
|
||||
* @param addr_type
|
||||
* @param address
|
||||
* @param passkey
|
||||
* @param le_device_db_index
|
||||
* @param authorization_result
|
||||
*/
|
||||
#define SM_JUST_WORKS_REQUEST 0xD0
|
||||
/**
|
||||
* @format H1B421
|
||||
* @param handle
|
||||
* @param addr_type
|
||||
* @param address
|
||||
* @param passkey
|
||||
* @param le_device_db_index
|
||||
* @param authorization_result
|
||||
*/
|
||||
#define SM_JUST_WORKS_CANCEL 0xD1
|
||||
/**
|
||||
* @format H1B421
|
||||
* @param handle
|
||||
* @param addr_type
|
||||
* @param address
|
||||
* @param passkey
|
||||
* @param le_device_db_index
|
||||
* @param authorization_result
|
||||
*/
|
||||
#define SM_PASSKEY_DISPLAY_NUMBER 0xD2
|
||||
/**
|
||||
* @format H1B421
|
||||
* @param handle
|
||||
* @param addr_type
|
||||
* @param address
|
||||
* @param passkey
|
||||
* @param le_device_db_index
|
||||
* @param authorization_result
|
||||
*/
|
||||
#define SM_PASSKEY_DISPLAY_CANCEL 0xD3
|
||||
/**
|
||||
* @format H1B421
|
||||
* @param handle
|
||||
* @param addr_type
|
||||
* @param address
|
||||
* @param passkey
|
||||
* @param le_device_db_index
|
||||
* @param authorization_result
|
||||
*/
|
||||
#define SM_PASSKEY_INPUT_NUMBER 0xD4
|
||||
|
||||
/**
|
||||
* @format H1B421
|
||||
* @format H1B
|
||||
* @param handle
|
||||
* @param addr_type
|
||||
* @param address
|
||||
* @param passkey
|
||||
* @param le_device_db_index
|
||||
* @param authorization_result
|
||||
*/
|
||||
#define SM_PASSKEY_INPUT_CANCEL 0xD5
|
||||
|
||||
/**
|
||||
* @format H1B421
|
||||
* @format H1B
|
||||
* @param handle
|
||||
* @param addr_type
|
||||
* @param address
|
||||
* @param passkey
|
||||
* @param le_device_db_index
|
||||
* @param authorization_result
|
||||
*/
|
||||
#define SM_IDENTITY_RESOLVING_STARTED 0xD6
|
||||
|
||||
/**
|
||||
* @format H1B421
|
||||
* @format H1B
|
||||
* @param handle
|
||||
* @param addr_type
|
||||
* @param address
|
||||
* @param passkey
|
||||
* @param le_device_db_index
|
||||
* @param authorization_result
|
||||
*/
|
||||
#define SM_IDENTITY_RESOLVING_FAILED 0xD7
|
||||
|
||||
/**
|
||||
* @format H1B421
|
||||
* @format H1B2
|
||||
* @param handle
|
||||
* @param addr_type
|
||||
* @param address
|
||||
* @param passkey
|
||||
* @param le_device_db_index
|
||||
* @param authorization_result
|
||||
*/
|
||||
#define SM_IDENTITY_RESOLVING_SUCCEEDED 0xD8
|
||||
|
||||
/**
|
||||
* @format H1B421
|
||||
* @format H1B
|
||||
* @param handle
|
||||
* @param addr_type
|
||||
* @param address
|
||||
* @param passkey
|
||||
* @param le_device_db_index
|
||||
* @param authorization_result
|
||||
*/
|
||||
#define SM_AUTHORIZATION_REQUEST 0xD9
|
||||
|
||||
/**
|
||||
* @format H1B421
|
||||
* @format H1B1
|
||||
* @param handle
|
||||
* @param addr_type
|
||||
* @param address
|
||||
* @param passkey
|
||||
* @param le_device_db_index
|
||||
* @param authorization_result
|
||||
*/
|
||||
#define SM_AUTHORIZATION_RESULT 0xDA
|
||||
|
@ -147,8 +147,6 @@ static uint8_t * sm_oob_data_B = (uint8_t *) "3333333333333333"; // = { 0x30...0
|
||||
static int sm_min_key_size = 7;
|
||||
static uint8_t pts_privacy_flag;
|
||||
|
||||
static int peer_addr_type;
|
||||
static bd_addr_t peer_address;
|
||||
static int ui_passkey = 0;
|
||||
static int ui_digits_for_passkey = 0;
|
||||
static int ui_uint16_request = 0;
|
||||
@ -326,7 +324,7 @@ static void gap_run(void){
|
||||
|
||||
void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||
uint16_t aHandle;
|
||||
sm_event_t * sm_event;
|
||||
bd_addr_t event_address;
|
||||
|
||||
switch (packet_type) {
|
||||
|
||||
@ -361,36 +359,29 @@ void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet,
|
||||
|
||||
case SM_PASSKEY_INPUT_NUMBER:
|
||||
// store peer address for input
|
||||
sm_event = (sm_event_t *) packet;
|
||||
memcpy(peer_address, sm_event->address, 6);
|
||||
peer_addr_type = sm_event->addr_type;
|
||||
printf("\nGAP Bonding %s (%u): Enter 6 digit passkey: '", bd_addr_to_str(sm_event->address), sm_event->addr_type);
|
||||
printf("\nGAP Bonding: Enter 6 digit passkey: '");
|
||||
fflush(stdout);
|
||||
ui_passkey = 0;
|
||||
ui_digits_for_passkey = 6;
|
||||
break;
|
||||
|
||||
case SM_PASSKEY_DISPLAY_NUMBER:
|
||||
sm_event = (sm_event_t *) packet;
|
||||
printf("\nGAP Bonding %s (%u): Display Passkey '%06u\n", bd_addr_to_str(sm_event->address), sm_event->addr_type, sm_event->passkey);
|
||||
printf("\nGAP Bonding: Display Passkey '%06u\n", READ_BT_32(packet, 11));
|
||||
break;
|
||||
|
||||
case SM_PASSKEY_DISPLAY_CANCEL:
|
||||
sm_event = (sm_event_t *) packet;
|
||||
printf("\nGAP Bonding %s (%u): Display cancel\n", bd_addr_to_str(sm_event->address), sm_event->addr_type);
|
||||
printf("\nGAP Bonding: Display cancel\n");
|
||||
break;
|
||||
|
||||
case SM_JUST_WORKS_REQUEST:
|
||||
// auto-authorize connection if requested
|
||||
sm_event = (sm_event_t *) packet;
|
||||
sm_just_works_confirm(sm_event->handle);
|
||||
sm_just_works_confirm(READ_BT_16(packet, 2));
|
||||
printf("Just Works request confirmed\n");
|
||||
break;
|
||||
|
||||
case SM_AUTHORIZATION_REQUEST:
|
||||
// auto-authorize connection if requested
|
||||
sm_event = (sm_event_t *) packet;
|
||||
sm_authorization_grant(sm_event->handle);
|
||||
sm_authorization_grant(READ_BT_16(packet, 2));
|
||||
break;
|
||||
|
||||
case GAP_LE_ADVERTISING_REPORT:
|
||||
@ -398,11 +389,12 @@ void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet,
|
||||
break;
|
||||
|
||||
case SM_IDENTITY_RESOLVING_SUCCEEDED:
|
||||
memcpy(current_pts_address, ((sm_event_t*) packet)->address, 6);
|
||||
current_pts_address_type = ((sm_event_t*) packet)->addr_type;
|
||||
le_device_db_index = ((sm_event_t*) packet)->le_device_db_index;
|
||||
bt_flip_addr(event_address, &packet[5]);
|
||||
// skip already detected pts
|
||||
if (memcmp( ((sm_event_t*) packet)->address, current_pts_address, 6) == 0) break;
|
||||
if (memcmp(event_address, current_pts_address, 6) == 0) break;
|
||||
memcpy(current_pts_address, event_address, 6);
|
||||
current_pts_address_type = packet[4];
|
||||
le_device_db_index = READ_BT_16(packet, 11);
|
||||
printf("Address resolving succeeded: resolvable address %s, addr type %u\n",
|
||||
bd_addr_to_str(current_pts_address), current_pts_address_type);
|
||||
break;
|
||||
|
@ -528,7 +528,7 @@ static void gap_run(void){
|
||||
}
|
||||
|
||||
static void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||
|
||||
bd_addr_t event_address;
|
||||
switch (packet_type) {
|
||||
|
||||
case HCI_EVENT_PACKET:
|
||||
@ -567,42 +567,35 @@ static void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
|
||||
att_write_queue_init();
|
||||
break;
|
||||
|
||||
case SM_JUST_WORKS_REQUEST: {
|
||||
case SM_JUST_WORKS_REQUEST:
|
||||
printf("SM_JUST_WORKS_REQUEST\n");
|
||||
sm_event_t * event = (sm_event_t *) packet;
|
||||
sm_just_works_confirm(event->handle);
|
||||
sm_just_works_confirm(READ_BT_16(packet, 2));
|
||||
break;
|
||||
}
|
||||
|
||||
case SM_PASSKEY_INPUT_NUMBER: {
|
||||
case SM_PASSKEY_INPUT_NUMBER:
|
||||
// display number
|
||||
sm_event_t * event = (sm_event_t *) packet;
|
||||
memcpy(master_address, event->address, 6);
|
||||
master_addr_type = event->addr_type;
|
||||
master_addr_type = packet[4];
|
||||
bt_flip_addr(event_address, &packet[5]);
|
||||
printf("\nGAP Bonding %s (%u): Enter 6 digit passkey: '", bd_addr_to_str(master_address), master_addr_type);
|
||||
fflush(stdout);
|
||||
ui_passkey = 0;
|
||||
ui_digits_for_passkey = 6;
|
||||
break;
|
||||
}
|
||||
|
||||
case SM_PASSKEY_DISPLAY_NUMBER: {
|
||||
case SM_PASSKEY_DISPLAY_NUMBER:
|
||||
// display number
|
||||
sm_event_t * event = (sm_event_t *) packet;
|
||||
printf("\nGAP Bonding %s (%u): Display Passkey '%06u\n", bd_addr_to_str(master_address), master_addr_type, event->passkey);
|
||||
printf("\nGAP Bonding %s (%u): Display Passkey '%06u\n", bd_addr_to_str(master_address), master_addr_type, READ_BT_32(packet, 11));
|
||||
break;
|
||||
}
|
||||
|
||||
case SM_PASSKEY_DISPLAY_CANCEL:
|
||||
printf("\nGAP Bonding %s (%u): Display cancel\n", bd_addr_to_str(master_address), master_addr_type);
|
||||
break;
|
||||
|
||||
case SM_AUTHORIZATION_REQUEST: {
|
||||
case SM_AUTHORIZATION_REQUEST:
|
||||
// auto-authorize connection if requested
|
||||
sm_event_t * event = (sm_event_t *) packet;
|
||||
sm_authorization_grant(event->handle);
|
||||
sm_authorization_grant(READ_BT_16(packet, 2));
|
||||
break;
|
||||
}
|
||||
|
||||
case ATT_HANDLE_VALUE_INDICATION_COMPLETE:
|
||||
printf("ATT_HANDLE_VALUE_INDICATION_COMPLETE status %u\n", packet[2]);
|
||||
break;
|
||||
|
@ -120,38 +120,33 @@ void mock_clear_packet_buffer(void);
|
||||
|
||||
void app_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||
uint16_t aHandle;
|
||||
sm_event_t * sm_event;
|
||||
bd_addr_t event_address;
|
||||
switch (packet_type) {
|
||||
case HCI_EVENT_PACKET:
|
||||
switch (packet[0]) {
|
||||
case SM_PASSKEY_INPUT_NUMBER:
|
||||
// store peer address for input
|
||||
sm_event = (sm_event_t *) packet;
|
||||
printf("\nGAP Bonding %s (%u): Enter 6 digit passkey: '", bd_addr_to_str(sm_event->address), sm_event->addr_type);
|
||||
printf("\nGAP Bonding: Enter 6 digit passkey: '");
|
||||
fflush(stdout);
|
||||
break;
|
||||
|
||||
case SM_PASSKEY_DISPLAY_NUMBER:
|
||||
sm_event = (sm_event_t *) packet;
|
||||
printf("\nGAP Bonding %s (%u): Display Passkey '%06u\n", bd_addr_to_str(sm_event->address), sm_event->addr_type, sm_event->passkey);
|
||||
printf("\nGAP Bonding: Display Passkey '%06u\n", READ_BT_32(packet, 11));
|
||||
break;
|
||||
|
||||
case SM_PASSKEY_DISPLAY_CANCEL:
|
||||
sm_event = (sm_event_t *) packet;
|
||||
printf("\nGAP Bonding %s (%u): Display cancel\n", bd_addr_to_str(sm_event->address), sm_event->addr_type);
|
||||
printf("\nGAP Bonding: Display cancel\n");
|
||||
break;
|
||||
|
||||
case SM_JUST_WORKS_REQUEST:
|
||||
// auto-authorize connection if requested
|
||||
sm_event = (sm_event_t *) packet;
|
||||
sm_just_works_confirm(sm_event->handle);
|
||||
sm_just_works_confirm(READ_BT_16(packet, 2));
|
||||
printf("Just Works request confirmed\n");
|
||||
break;
|
||||
|
||||
case SM_AUTHORIZATION_REQUEST:
|
||||
// auto-authorize connection if requested
|
||||
sm_event = (sm_event_t *) packet;
|
||||
sm_authorization_grant(sm_event->handle);
|
||||
sm_authorization_grant(READ_BT_16(packet, 2));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
Loading…
x
Reference in New Issue
Block a user