mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-16 08:42:28 +00:00
only send keys requested by initiator
This commit is contained in:
parent
966db7038e
commit
e666cc4e4b
@ -62,7 +62,9 @@ ble_server: ${CORE_OBJ} ${COMMON_OBJ} rijndael.c ble_server.c profile.h
|
|||||||
${CC} ${CORE_OBJ} ${COMMON_OBJ} rijndael.c ble_server.c ${CFLAGS} ${LDFLAGS} -o $@
|
${CC} ${CORE_OBJ} ${COMMON_OBJ} rijndael.c ble_server.c ${CFLAGS} ${LDFLAGS} -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f spp_counter sdp_rfcomm_query sdp_general_query spp_counter_ssp *.o *.out *.hex ../driver/*.o ${BTSTACK_ROOT}/src/*.o
|
rm -f spp_counter sdp_rfcomm_query sdp_general_query spp_counter_ssp *.o *.out *.hex
|
||||||
|
rm -f ${BTSTACK_ROOT}/src/*.o
|
||||||
|
rm -f ${BTSTACK_ROOT}/ble/*.o
|
||||||
rm -f ${BTSTACK_ROOT}/chipset-cc256x/*.o
|
rm -f ${BTSTACK_ROOT}/chipset-cc256x/*.o
|
||||||
rm -rf *.dSYM
|
rm -rf *.dSYM
|
||||||
|
|
@ -81,6 +81,11 @@ typedef enum {
|
|||||||
#define SM_AUTHREQ_BONDING 0x01
|
#define SM_AUTHREQ_BONDING 0x01
|
||||||
#define SM_AUTHREQ_MITM_PROTECTION 0x02
|
#define SM_AUTHREQ_MITM_PROTECTION 0x02
|
||||||
|
|
||||||
|
//Key distribution flags
|
||||||
|
#define SM_KEYDIST_ENC_KEY 0X01
|
||||||
|
#define SM_KEYDIST_ID_KEY 0x02
|
||||||
|
#define SM_KEYDIST_SIGN 0x04
|
||||||
|
|
||||||
typedef uint8_t key_t[16];
|
typedef uint8_t key_t[16];
|
||||||
|
|
||||||
static att_connection_t att_connection;
|
static att_connection_t att_connection;
|
||||||
@ -92,6 +97,9 @@ static uint16_t sm_response_handle = 0;
|
|||||||
static uint16_t sm_response_size = 0;
|
static uint16_t sm_response_size = 0;
|
||||||
static uint8_t sm_response_buffer[28];
|
static uint8_t sm_response_buffer[28];
|
||||||
|
|
||||||
|
// defines which keys will be send after connection is encrypted
|
||||||
|
static int sm_key_distribution_set = 0;
|
||||||
|
|
||||||
static int sm_send_security_request = 0;
|
static int sm_send_security_request = 0;
|
||||||
static int sm_send_encryption_information = 0;
|
static int sm_send_encryption_information = 0;
|
||||||
static int sm_send_master_identification = 0;
|
static int sm_send_master_identification = 0;
|
||||||
@ -120,7 +128,7 @@ static bd_addr_t sm_s_address;
|
|||||||
static key_t sm_s_csrk;
|
static key_t sm_s_csrk;
|
||||||
static key_t sm_s_irk;
|
static key_t sm_s_irk;
|
||||||
|
|
||||||
// key distribution, recevied from master
|
// key distribution, received from master
|
||||||
static key_t sm_m_ltk;
|
static key_t sm_m_ltk;
|
||||||
static uint16_t sm_m_ediv;
|
static uint16_t sm_m_ediv;
|
||||||
static uint8_t sm_m_rand[8];
|
static uint8_t sm_m_rand[8];
|
||||||
@ -260,6 +268,10 @@ static void sm_packet_handler(uint8_t packet_type, uint16_t handle, uint8_t *pac
|
|||||||
|
|
||||||
switch (packet[0]){
|
switch (packet[0]){
|
||||||
case SM_CODE_PAIRING_REQUEST:
|
case SM_CODE_PAIRING_REQUEST:
|
||||||
|
|
||||||
|
// store key distribtion request
|
||||||
|
sm_key_distribution_set = packet[6];
|
||||||
|
|
||||||
// for validate
|
// for validate
|
||||||
memcpy(sm_preq, packet, 7);
|
memcpy(sm_preq, packet, 7);
|
||||||
|
|
||||||
@ -277,6 +289,7 @@ static void sm_packet_handler(uint8_t packet_type, uint16_t handle, uint8_t *pac
|
|||||||
// for validate
|
// for validate
|
||||||
memcpy(sm_pres, sm_response_buffer, 7);
|
memcpy(sm_pres, sm_response_buffer, 7);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SM_CODE_PAIRING_CONFIRM:
|
case SM_CODE_PAIRING_CONFIRM:
|
||||||
// received confirm value
|
// received confirm value
|
||||||
memcpy(sm_m_confirm, &packet[1], 16);
|
memcpy(sm_m_confirm, &packet[1], 16);
|
||||||
@ -285,6 +298,7 @@ static void sm_packet_handler(uint8_t packet_type, uint16_t handle, uint8_t *pac
|
|||||||
// dummy
|
// dummy
|
||||||
memcpy(sm_response_buffer, packet, size);
|
memcpy(sm_response_buffer, packet, size);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SM_CODE_PAIRING_RANDOM:
|
case SM_CODE_PAIRING_RANDOM:
|
||||||
// received confirm value
|
// received confirm value
|
||||||
memcpy(sm_m_random, &packet[1], 16);
|
memcpy(sm_m_random, &packet[1], 16);
|
||||||
@ -360,7 +374,7 @@ static void packet_handler (void * connection, uint8_t packet_type, uint16_t cha
|
|||||||
sm_response_handle = READ_BT_16(packet, 4);
|
sm_response_handle = READ_BT_16(packet, 4);
|
||||||
|
|
||||||
// request security
|
// request security
|
||||||
// sm_send_security_request = 1;
|
sm_send_security_request = 1;
|
||||||
|
|
||||||
// reset connection MTU
|
// reset connection MTU
|
||||||
att_connection.mtu = 23;
|
att_connection.mtu = 23;
|
||||||
@ -377,16 +391,16 @@ static void packet_handler (void * connection, uint8_t packet_type, uint16_t cha
|
|||||||
break;
|
break;
|
||||||
case HCI_EVENT_ENCRYPTION_CHANGE:
|
case HCI_EVENT_ENCRYPTION_CHANGE:
|
||||||
|
|
||||||
// TODO: check state:
|
// distribute keys as requested by initiator
|
||||||
|
// TODO: handle initiator case here
|
||||||
// TODO: only send requested keys
|
if (sm_key_distribution_set & SM_KEYDIST_ENC_KEY)
|
||||||
|
sm_send_encryption_information = 1;
|
||||||
// distribute keys
|
|
||||||
sm_send_encryption_information = 1;
|
|
||||||
sm_send_master_identification = 1;
|
sm_send_master_identification = 1;
|
||||||
sm_send_identity_information = 1;
|
if (sm_key_distribution_set & SM_KEYDIST_ID_KEY)
|
||||||
|
sm_send_identity_information = 1;
|
||||||
sm_send_identity_address_information = 1;
|
sm_send_identity_address_information = 1;
|
||||||
sm_send_signing_identification = 1;
|
if (sm_key_distribution_set & SM_KEYDIST_SIGN)
|
||||||
|
sm_send_signing_identification = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HCI_EVENT_DISCONNECTION_COMPLETE:
|
case HCI_EVENT_DISCONNECTION_COMPLETE:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user