From 9f9b1721e11470e7d01a3673ec902fdf325c8da2 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Wed, 19 Aug 2015 14:43:41 +0200 Subject: [PATCH] sm: manage global signing counter --- ble/sm.c | 10 ++++++++++ ble/sm.h | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/ble/sm.c b/ble/sm.c index b33d1fed3..88f90eaaf 100644 --- a/ble/sm.c +++ b/ble/sm.c @@ -137,6 +137,8 @@ static derived_key_generation_t dkg_state; // derived from sm_persistent_er // .. +static uint32_t sm_signing_counter = 0; + // random address update static random_address_update_t rau_state; static bd_addr_t sm_random_address; @@ -2225,6 +2227,14 @@ void sm_set_ir(sm_key_t ir){ memcpy(sm_persistent_ir, ir, 16); } +void sm_set_signing_counter(uint32_t signing_counter){ + sm_signing_counter = signing_counter; +} + +uint32_t sm_signing_counter_next(void){ + return sm_signing_counter++; +} + // Testing support only void sm_test_set_irk(sm_key_t irk){ memcpy(sm_persistent_irk, irk, 16); diff --git a/ble/sm.h b/ble/sm.h index 41c973a56..80b8ca0da 100644 --- a/ble/sm.h +++ b/ble/sm.h @@ -147,6 +147,14 @@ void sm_set_er(sm_key_t er); */ void sm_set_ir(sm_key_t ir); +/** + * @brief Set signning counnter used with Connection Signature Resolving Key (CSRK) + * @note Needs to be stored in persistent memory as a signed writes are invalid if a higher counter was + * recevied before + * @param signing counter + */ +void sm_set_signing_counter(uint32_t signing_counter); + /** * * @brief Registers OOB Data Callback. The callback should set the oob_data and return 1 if OOB data is availble @@ -263,6 +271,11 @@ void sm_authorization_grant(uint8_t addr_type, bd_addr_t address); int sm_cmac_ready(void); void sm_cmac_start(sm_key_t k, uint16_t message_len, uint8_t * message, uint32_t sign_counter, void (*done_handler)(uint8_t hash[8])); +/** + * @brief Get global signing counter and increment it + */ +uint32_t sm_signing_counter_next(void); + /* * @brief Match address against bonded devices * @return 0 if successfully added to lookup queue