From 04bc2c17768a169df742c22f3820ac006766fa93 Mon Sep 17 00:00:00 2001 From: "matthias.ringwald@gmail.com" Date: Mon, 6 Jan 2014 15:53:46 +0000 Subject: [PATCH] get security properties on encryption change --- ble/att_server.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/ble/att_server.c b/ble/att_server.c index 786f1eb07..3f2bf13d4 100644 --- a/ble/att_server.c +++ b/ble/att_server.c @@ -72,6 +72,8 @@ typedef enum { static att_connection_t att_connection; static att_server_state_t att_server_state; +static uint8_t att_client_addr_type; +static bd_addr_t att_client_address; static uint16_t att_request_handle = 0; static uint16_t att_request_size = 0; static uint8_t att_request_buffer[28]; @@ -79,8 +81,6 @@ 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,9 +97,15 @@ static void att_event_packet_handler (uint8_t packet_type, uint16_t channel, uin case HCI_EVENT_LE_META: switch (packet[2]) { case HCI_SUBEVENT_LE_CONNECTION_COMPLETE: - // reset connection MTU + // store address + att_client_addr_type = packet[7]; + bt_flip_addr(att_client_address, &packet[8]); + + // reset connection properties att_connection.mtu = 23; - att_connection_encrypted = 0; + att_connection.encryption_key_size = 0; + att_connection.authenticated = 0; + att_connection.authorized = 0; break; default: @@ -110,7 +116,9 @@ static void att_event_packet_handler (uint8_t packet_type, uint16_t channel, uin case HCI_EVENT_ENCRYPTION_CHANGE: // check handle if (att_request_handle != READ_BT_16(packet, 3)) break; - att_connection_encrypted = packet[5]; + att_connection.encryption_key_size = sm_encryption_key_size(att_client_addr_type, att_client_address); + att_connection.authenticated = sm_authenticated(att_client_addr_type, att_client_address); + att_connection.authorized = 0; break; case HCI_EVENT_DISCONNECTION_COMPLETE: @@ -118,7 +126,6 @@ static void att_event_packet_handler (uint8_t packet_type, uint16_t channel, uin // -> 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: