mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-26 12:35:25 +00:00
track att connection encryption state
This commit is contained in:
parent
3f0d86542c
commit
f7fb899f3b
@ -60,7 +60,8 @@
|
||||
#include "att_server.h"
|
||||
#include "gap_le.h"
|
||||
#include "central_device_db.h"
|
||||
static att_connection_t att_connection;
|
||||
|
||||
static void att_run(void);
|
||||
|
||||
typedef enum {
|
||||
ATT_SERVER_IDLE,
|
||||
@ -68,8 +69,7 @@ typedef enum {
|
||||
ATT_SERVER_W4_SIGNED_WRITE_VALIDATION,
|
||||
} att_server_state_t;
|
||||
|
||||
static void att_run(void);
|
||||
|
||||
static att_connection_t att_connection;
|
||||
static att_server_state_t att_server_state;
|
||||
|
||||
static uint16_t att_request_handle = 0;
|
||||
@ -79,6 +79,8 @@ static uint8_t att_request_buffer[28];
|
||||
static int att_ir_central_device_db_index = -1;
|
||||
static int att_ir_lookup_active = 0;
|
||||
|
||||
static int att_connection_encrypted;
|
||||
|
||||
static btstack_packet_handler_t att_client_packet_handler = NULL;
|
||||
|
||||
static void att_event_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||
@ -97,6 +99,7 @@ static void att_event_packet_handler (uint8_t packet_type, uint16_t channel, uin
|
||||
case HCI_SUBEVENT_LE_CONNECTION_COMPLETE:
|
||||
// reset connection MTU
|
||||
att_connection.mtu = 23;
|
||||
att_connection_encrypted = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -104,11 +107,18 @@ static void att_event_packet_handler (uint8_t packet_type, uint16_t channel, uin
|
||||
}
|
||||
break;
|
||||
|
||||
case HCI_EVENT_ENCRYPTION_CHANGE:
|
||||
// check handle
|
||||
if (att_request_handle != READ_BT_16(packet, 3)) break;
|
||||
att_connection_encrypted = packet[5];
|
||||
break;
|
||||
|
||||
case HCI_EVENT_DISCONNECTION_COMPLETE:
|
||||
// restart advertising if we have been connected before
|
||||
// -> avoid sending advertise enable a second time before command complete was received
|
||||
att_server_state = ATT_SERVER_IDLE;
|
||||
att_request_handle = 0;
|
||||
att_connection_encrypted = 0;
|
||||
break;
|
||||
|
||||
case SM_IDENTITY_RESOLVING_STARTED:
|
||||
|
9
ble/sm.c
9
ble/sm.c
@ -215,7 +215,7 @@ static timer_source_t sm_timeout;
|
||||
// data to send to aes128 crypto engine, see sm_aes128_set_key and sm_aes128_set_plaintext
|
||||
static sm_key_t sm_aes128_key;
|
||||
static sm_key_t sm_aes128_plaintext;
|
||||
static uint8_t sm_aes128_active;
|
||||
static uint8_t sm_aes128_active;
|
||||
|
||||
// generation method and temporary key for STK - STK is stored in sm_s_ltk
|
||||
static stk_generation_method_t sm_stk_generation_method;
|
||||
@ -683,14 +683,13 @@ static void sm_cmac_handle_encryption_result(sm_key_t data){
|
||||
print_key("k2", k2);
|
||||
|
||||
// step 4: set m_last
|
||||
int i;
|
||||
if (sm_cmac_last_block_complete()){
|
||||
int i;
|
||||
for (i=0;i<16;i++){
|
||||
sm_cmac_m_last[i] = sm_cmac_message[sm_cmac_message_len - 16 + i] ^ k1[i];
|
||||
}
|
||||
} else {
|
||||
int valid_octets_in_last_block = sm_cmac_message_len & 0x0f;
|
||||
int i;
|
||||
for (i=0;i<16;i++){
|
||||
if (i < valid_octets_in_last_block){
|
||||
sm_cmac_m_last[i] = sm_cmac_message[(sm_cmac_message_len & 0xfff0) + i] ^ k2[i];
|
||||
@ -1659,6 +1658,10 @@ void sm_init(){
|
||||
l2cap_register_packet_handler(sm_event_packet_handler);
|
||||
}
|
||||
|
||||
void sm_encrypted(uint8_t addr_type, bd_addr_t address){
|
||||
|
||||
}
|
||||
|
||||
// GAP Bonding API
|
||||
static int sm_get_connection(uint8_t addr_type, bd_addr_t address){
|
||||
// TODO compare to current connection
|
||||
|
2
ble/sm.h
2
ble/sm.h
@ -135,6 +135,8 @@ void sm_set_authentication_requirements(uint8_t auth_req);
|
||||
void sm_set_io_capabilities(io_capability_t io_capability);
|
||||
void sm_set_request_security(int enable);
|
||||
|
||||
void sm_encrypted(uint8_t addr_type, bd_addr_t address);
|
||||
|
||||
void sm_bonding_decline(uint8_t addr_type, bd_addr_t address);
|
||||
void sm_just_works_confirm(uint8_t addr_type, bd_addr_t address);
|
||||
void sm_passkey_input(uint8_t addr_type, bd_addr_t address, uint32_t passkey);
|
||||
|
Loading…
x
Reference in New Issue
Block a user