1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef __ESP_SEC_API_H__ 16 #define __ESP_SEC_API_H__ 17 18 #include "stack/bt_types.h" 19 20 #define APP_SEC_IRK_FLAG (0) 21 #define RAND_NB_LEN 0x08 22 #define SEC_KEY_LEN 0x10 23 24 /* 25 * STRUCTURES DEFINITIONS 26 **************************************************************************************** 27 */ 28 29 30 /// Generic Security key structure 31 typedef struct { 32 /// Key value MSB -> LSB 33 UINT8 key[SEC_KEY_LEN]; 34 } smp_sec_key; 35 36 ///Random number structure 37 typedef struct { 38 ///8-byte array for random number 39 UINT8 nb[RAND_NB_LEN]; 40 } rand_nb; 41 42 typedef struct { 43 // LTK 44 smp_sec_key ltk; 45 // Random Number 46 rand_nb rand_nb; 47 // EDIV 48 UINT16 ediv; 49 // LTK key size 50 UINT8 key_size; 51 52 // Last paired peer address type 53 UINT8 peer_addr_type; 54 // Last paired peer address 55 BD_ADDR peer_addr; 56 57 // authentication level 58 UINT8 auth; 59 60 } tAPP_SEC_ENV; 61 62 extern tAPP_SEC_ENV app_sec_env; 63 64 /* 65 * GLOBAL FUNCTIONS DECLARATIONS 66 **************************************************************************************** 67 */ 68 69 void app_ble_sec_init(void); 70 71 void app_ble_sec_pairing_cmp_evt_send(UINT8); 72 73 UINT32 app_ble_sec_gen_tk(void); 74 75 void app_ble_sec_gen_ltk(UINT8 key_size); 76 77 void app_ble_security_start(void); 78 79 #endif /* __ESP_SEC_API_H__ */ 80