1 /* 2 * Copyright 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at: 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 18 #pragma once 19 20 #include <bluetooth/log.h> 21 22 #include <cstdint> 23 24 #include "stack/include/bt_octets.h" 25 #include "stack/include/btm_api_types.h" // tBTM_CMPL_CB 26 #include "stack/include/btm_ble_sec_api_types.h" 27 #include "stack/include/btm_sec_api_types.h" 28 #include "types/raw_address.h" 29 30 /* 31 * Local device configuration 32 */ 33 typedef struct { 34 BD_NAME bd_name; /* local Bluetooth device name */ 35 bool pin_type; /* true if PIN type is fixed */ 36 uint8_t pin_code_len; /* Bonding information */ 37 PIN_CODE pin_code; /* PIN CODE if pin type is fixed */ 38 } tBTM_CFG; 39 40 /* Pairing State */ 41 enum tBTM_PAIRING_STATE : uint8_t { 42 BTM_PAIR_STATE_IDLE, /* Idle */ 43 BTM_PAIR_STATE_GET_REM_NAME, /* Getting the remote name (to check for SM4) */ 44 BTM_PAIR_STATE_WAIT_PIN_REQ, /* Started authentication, waiting for PIN req 45 (PIN is pre-fetched) */ 46 BTM_PAIR_STATE_WAIT_LOCAL_PIN, /* Waiting for local PIN code */ 47 BTM_PAIR_STATE_WAIT_NUMERIC_CONFIRM, /* Waiting user 'yes' to numeric 48 confirmation */ 49 BTM_PAIR_STATE_KEY_ENTRY, /* Key entry state (we are a keyboard) */ 50 BTM_PAIR_STATE_WAIT_LOCAL_OOB_RSP, /* Waiting for local response to peer OOB 51 data */ 52 BTM_PAIR_STATE_WAIT_LOCAL_IOCAPS, /* Waiting for local IO capabilities and OOB 53 data */ 54 BTM_PAIR_STATE_INCOMING_SSP, /* Incoming SSP (got peer IO caps when idle) */ 55 BTM_PAIR_STATE_WAIT_AUTH_COMPLETE, /* All done, waiting authentication 56 complete */ 57 BTM_PAIR_STATE_WAIT_DISCONNECT /* Waiting to disconnect the ACL */ 58 }; 59 60 #define BTM_PAIR_FLAGS_WE_STARTED_DD 0x01 /* We want to do dedicated bonding */ 61 #define BTM_PAIR_FLAGS_PEER_STARTED_DD 0x02 /* Peer initiated dedicated bonding */ 62 #define BTM_PAIR_FLAGS_DISC_WHEN_DONE 0x04 /* Disconnect when done */ 63 #define BTM_PAIR_FLAGS_PIN_REQD 0x08 /* set this bit when pin_callback is called */ 64 #define BTM_PAIR_FLAGS_PRE_FETCH_PIN 0x10 /* set this bit when pre-fetch pin */ 65 #define BTM_PAIR_FLAGS_REJECTED_CONNECT 0x20 /* set this bit when rejected incoming connection */ 66 #define BTM_PAIR_FLAGS_WE_CANCEL_DD 0x40 /* set this bit when cancelling a bonding procedure */ 67 #define BTM_PAIR_FLAGS_LE_ACTIVE 0x80 /* use this bit when SMP pairing is active */ 68 69 typedef struct { 70 bool is_mux; 71 RawAddress bd_addr; 72 uint16_t psm; 73 bool is_orig; 74 tBTM_SEC_CALLBACK* p_callback; 75 tSMP_SIRK_CALLBACK* p_sirk_callback; 76 void* p_ref_data; 77 uint16_t rfcomm_security_requirement; 78 tBT_TRANSPORT transport; 79 tBTM_BLE_SEC_ACT sec_act; 80 } tBTM_SEC_QUEUE_ENTRY; 81 82 /* Define the Device Management control structure 83 */ 84 typedef struct tBTM_SEC_DEVCB { 85 tBTM_CMPL_CB* p_stored_link_key_cmpl_cb; /* Read/Write/Delete stored link key */ 86 87 tBTM_BLE_LOCAL_ID_KEYS id_keys; /* local BLE ID keys */ 88 Octet16 ble_encryption_key_value; /* BLE encryption key */ 89 90 tBTM_IO_CAP loc_io_caps; /* IO capability of the local device */ 91 tBTM_AUTH_REQ loc_auth_req; /* the auth_req flag */ 92 } tBTM_SEC_DEVCB; 93 94 /* security action for L2CAP COC channels */ 95 #define BTM_SEC_OK 1 96 #define BTM_SEC_ENCRYPT 2 /* encrypt the link with current key */ 97 #define BTM_SEC_ENCRYPT_NO_MITM 3 /* unauthenticated encryption or better */ 98 #define BTM_SEC_ENCRYPT_MITM 4 /* authenticated encryption */ 99 #define BTM_SEC_ENC_PENDING 5 /* wait for link encryption pending */ 100 101 typedef uint8_t tBTM_SEC_ACTION; 102 103 namespace std { 104 template <> 105 struct formatter<tBTM_PAIRING_STATE> : enum_formatter<tBTM_PAIRING_STATE> {}; 106 } // namespace std 107