1 /* 2 * 3 * Copyright 2023 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 19 #pragma once 20 21 #include <cstdint> 22 23 #include "stack/include/bt_octets.h" 24 #include "stack/include/btm_sec_api_types.h" 25 #include "stack/include/btm_status.h" 26 27 ////////////////////////////////////////////////////////// 28 ////// from btm_ble_api_types.h 29 ///////////////////////////////////////////////////////// 30 /* BLE encryption keys */ 31 typedef struct { 32 Octet16 ltk; 33 BT_OCTET8 rand; 34 uint16_t ediv; 35 uint8_t sec_level; 36 uint8_t key_size; 37 } tBTM_LE_PENC_KEYS; 38 39 /* BLE CSRK keys */ 40 typedef struct { 41 uint32_t counter; 42 Octet16 csrk; 43 uint8_t sec_level; 44 } tBTM_LE_PCSRK_KEYS; 45 46 /* BLE Encryption reproduction keys */ 47 typedef struct { 48 Octet16 ltk; 49 uint16_t div; 50 uint8_t key_size; 51 uint8_t sec_level; 52 } tBTM_LE_LENC_KEYS; 53 54 /* BLE SRK keys */ 55 typedef struct { 56 uint32_t counter; 57 uint16_t div; 58 uint8_t sec_level; 59 Octet16 csrk; 60 } tBTM_LE_LCSRK_KEYS; 61 62 typedef struct { 63 Octet16 irk; 64 tBLE_ADDR_TYPE identity_addr_type; 65 RawAddress identity_addr; 66 } tBTM_LE_PID_KEYS; 67 68 typedef union { 69 tBTM_LE_PENC_KEYS penc_key; /* received peer encryption key */ 70 tBTM_LE_PCSRK_KEYS pcsrk_key; /* received peer device SRK */ 71 tBTM_LE_PID_KEYS pid_key; /* peer device ID key */ 72 tBTM_LE_LENC_KEYS lenc_key; /* local encryption reproduction keys LTK = = d1(ER, DIV, 0) */ 73 tBTM_LE_LCSRK_KEYS lcsrk_key; /* local device CSRK = d1(ER,DIV,1)*/ 74 } tBTM_LE_KEY_VALUE; 75 76 typedef struct { 77 tBTM_LE_KEY_TYPE key_type; 78 tBTM_LE_KEY_VALUE* p_key_value; 79 } tBTM_LE_KEY; 80 81 typedef union { 82 tBTM_LE_IO_REQ io_req; /* BTM_LE_IO_REQ_EVT */ 83 uint32_t key_notif; /* BTM_LE_KEY_NOTIF_EVT */ 84 /* BTM_LE_NC_REQ_EVT */ 85 /* no callback data for BTM_LE_KEY_REQ_EVT and BTM_LE_OOB_REQ_EVT */ 86 tBTM_LE_COMPLT complt; /* BTM_LE_COMPLT_EVT */ 87 tSMP_OOB_DATA_TYPE req_oob_type; 88 tBTM_LE_KEY key; 89 tSMP_LOC_OOB_DATA local_oob_data; 90 tBLE_BD_ADDR id_addr_with_type; 91 } tBTM_LE_EVT_DATA; 92 93 /* Simple Pairing Events. Called by the stack when Simple Pairing related 94 * events occur. 95 */ 96 typedef tBTM_STATUS(tBTM_LE_CALLBACK)(tBTM_LE_EVT event, const RawAddress& bda, 97 tBTM_LE_EVT_DATA* p_data); 98 99 #define BTM_BLE_KEY_TYPE_ID 1 100 #define BTM_BLE_KEY_TYPE_ER 2 101 #define BTM_BLE_KEY_TYPE_COUNTER 3 // tobe obsolete 102 103 typedef struct { 104 Octet16 ir; 105 Octet16 irk; 106 Octet16 dhk; 107 } tBTM_BLE_LOCAL_ID_KEYS; 108 109 typedef union { 110 tBTM_BLE_LOCAL_ID_KEYS id_keys; 111 Octet16 er; 112 } tBTM_BLE_LOCAL_KEYS; 113 114 /* New LE identity key for local device. 115 */ 116 typedef void(tBTM_LE_KEY_CALLBACK)(uint8_t key_type, tBTM_BLE_LOCAL_KEYS* p_key); 117