1 /****************************************************************************** 2 * 3 * Copyright (C) 1999-2012 Broadcom Corporation 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 #ifndef SMP_API_TYPES_H 20 #define SMP_API_TYPES_H 21 22 #include "bt_target.h" 23 24 #define SMP_PIN_CODE_LEN_MAX PIN_CODE_LEN 25 #define SMP_PIN_CODE_LEN_MIN 6 26 27 /* SMP command code */ 28 #define SMP_OPCODE_PAIRING_REQ 0x01 29 #define SMP_OPCODE_PAIRING_RSP 0x02 30 #define SMP_OPCODE_CONFIRM 0x03 31 #define SMP_OPCODE_RAND 0x04 32 #define SMP_OPCODE_PAIRING_FAILED 0x05 33 #define SMP_OPCODE_ENCRYPT_INFO 0x06 34 #define SMP_OPCODE_MASTER_ID 0x07 35 #define SMP_OPCODE_IDENTITY_INFO 0x08 36 #define SMP_OPCODE_ID_ADDR 0x09 37 #define SMP_OPCODE_SIGN_INFO 0x0A 38 #define SMP_OPCODE_SEC_REQ 0x0B 39 #define SMP_OPCODE_PAIR_PUBLIC_KEY 0x0C 40 #define SMP_OPCODE_PAIR_DHKEY_CHECK 0x0D 41 #define SMP_OPCODE_PAIR_KEYPR_NOTIF 0x0E 42 #define SMP_OPCODE_MAX SMP_OPCODE_PAIR_KEYPR_NOTIF 43 #define SMP_OPCODE_MIN SMP_OPCODE_PAIRING_REQ 44 #define SMP_OPCODE_PAIR_COMMITM 0x0F 45 46 /* SMP event type */ 47 #define SMP_IO_CAP_REQ_EVT 1 /* IO capability request event */ 48 #define SMP_SEC_REQUEST_EVT 2 /* SMP pairing request */ 49 #define SMP_PASSKEY_NOTIF_EVT 3 /* passkey notification event */ 50 #define SMP_PASSKEY_REQ_EVT 4 /* passkey request event */ 51 #define SMP_OOB_REQ_EVT 5 /* OOB request event */ 52 #define SMP_NC_REQ_EVT 6 /* Numeric Comparison request event */ 53 #define SMP_COMPLT_EVT 7 /* SMP complete event */ 54 #define SMP_PEER_KEYPR_NOT_EVT 8 /* Peer keypress notification */ 55 56 /* SC OOB request event (both local and peer OOB data can be expected in 57 * response) */ 58 #define SMP_SC_OOB_REQ_EVT 9 59 /* SC OOB local data set is created (as result of SMP_CrLocScOobData(...)) */ 60 #define SMP_SC_LOC_OOB_DATA_UP_EVT 10 61 #define SMP_BR_KEYS_REQ_EVT 12 /* SMP over BR keys request event */ 62 typedef uint8_t tSMP_EVT; 63 64 /* pairing failure reason code */ 65 #define SMP_PASSKEY_ENTRY_FAIL 0x01 66 #define SMP_OOB_FAIL 0x02 67 #define SMP_PAIR_AUTH_FAIL 0x03 68 #define SMP_CONFIRM_VALUE_ERR 0x04 69 #define SMP_PAIR_NOT_SUPPORT 0x05 70 #define SMP_ENC_KEY_SIZE 0x06 71 #define SMP_INVALID_CMD 0x07 72 #define SMP_PAIR_FAIL_UNKNOWN 0x08 73 #define SMP_REPEATED_ATTEMPTS 0x09 74 #define SMP_INVALID_PARAMETERS 0x0A 75 #define SMP_DHKEY_CHK_FAIL 0x0B 76 #define SMP_NUMERIC_COMPAR_FAIL 0x0C 77 #define SMP_BR_PARING_IN_PROGR 0x0D 78 #define SMP_XTRANS_DERIVE_NOT_ALLOW 0x0E 79 #define SMP_MAX_FAIL_RSN_PER_SPEC SMP_XTRANS_DERIVE_NOT_ALLOW 80 81 /* self defined error code */ 82 #define SMP_PAIR_INTERNAL_ERR (SMP_MAX_FAIL_RSN_PER_SPEC + 0x01) /* 0x0F */ 83 84 /* Unknown IO capability, unable to decide association model */ 85 #define SMP_UNKNOWN_IO_CAP (SMP_MAX_FAIL_RSN_PER_SPEC + 0x02) /* 0x10 */ 86 87 #define SMP_INIT_FAIL (SMP_MAX_FAIL_RSN_PER_SPEC + 0x03) /* 0x11 */ 88 #define SMP_CONFIRM_FAIL (SMP_MAX_FAIL_RSN_PER_SPEC + 0x04) /* 0x12 */ 89 #define SMP_BUSY (SMP_MAX_FAIL_RSN_PER_SPEC + 0x05) /* 0x13 */ 90 #define SMP_ENC_FAIL (SMP_MAX_FAIL_RSN_PER_SPEC + 0x06) /* 0x14 */ 91 #define SMP_STARTED (SMP_MAX_FAIL_RSN_PER_SPEC + 0x07) /* 0x15 */ 92 #define SMP_RSP_TIMEOUT (SMP_MAX_FAIL_RSN_PER_SPEC + 0x08) /* 0x16 */ 93 #define SMP_DIV_NOT_AVAIL (SMP_MAX_FAIL_RSN_PER_SPEC + 0x09) /* 0x17 */ 94 95 /* Unspecified failure reason */ 96 #define SMP_FAIL (SMP_MAX_FAIL_RSN_PER_SPEC + 0x0A) /* 0x18 */ 97 98 #define SMP_CONN_TOUT (SMP_MAX_FAIL_RSN_PER_SPEC + 0x0B) /* 0x19 */ 99 #define SMP_SUCCESS 0 100 101 typedef uint8_t tSMP_STATUS; 102 103 /* Device IO capability */ 104 #define SMP_IO_CAP_OUT BTM_IO_CAP_OUT /* DisplayOnly */ 105 #define SMP_IO_CAP_IO BTM_IO_CAP_IO /* DisplayYesNo */ 106 #define SMP_IO_CAP_IN BTM_IO_CAP_IN /* KeyboardOnly */ 107 #define SMP_IO_CAP_NONE BTM_IO_CAP_NONE /* NoInputNoOutput */ 108 #define SMP_IO_CAP_KBDISP BTM_IO_CAP_KBDISP /* Keyboard Display */ 109 #define SMP_IO_CAP_MAX BTM_IO_CAP_MAX 110 typedef uint8_t tSMP_IO_CAP; 111 112 #ifndef SMP_DEFAULT_IO_CAPS 113 #define SMP_DEFAULT_IO_CAPS SMP_IO_CAP_KBDISP 114 #endif 115 116 /* OOB data present or not */ 117 enum { SMP_OOB_NONE, SMP_OOB_PRESENT, SMP_OOB_UNKNOWN }; 118 typedef uint8_t tSMP_OOB_FLAG; 119 120 /* type of OOB data required from application */ 121 enum { SMP_OOB_INVALID_TYPE, SMP_OOB_PEER, SMP_OOB_LOCAL, SMP_OOB_BOTH }; 122 typedef uint8_t tSMP_OOB_DATA_TYPE; 123 124 #define SMP_AUTH_NO_BOND 0x00 125 #define SMP_AUTH_GEN_BOND 0x01 // todo sdh change GEN_BOND to BOND 126 127 /* SMP Authentication requirement */ 128 #define SMP_AUTH_YN_BIT (1 << 2) 129 #define SMP_SC_SUPPORT_BIT (1 << 3) 130 #define SMP_KP_SUPPORT_BIT (1 << 4) 131 #define SMP_H7_SUPPORT_BIT (1 << 5) 132 133 #define SMP_AUTH_MASK \ 134 (SMP_AUTH_GEN_BOND | SMP_AUTH_YN_BIT | SMP_SC_SUPPORT_BIT | \ 135 SMP_KP_SUPPORT_BIT | SMP_H7_SUPPORT_BIT) 136 137 #define SMP_AUTH_BOND SMP_AUTH_GEN_BOND 138 139 /* no MITM, No Bonding, encryption only */ 140 #define SMP_AUTH_NB_ENC_ONLY 0x00 //(SMP_AUTH_MASK | BTM_AUTH_SP_NO) 141 142 /* MITM, No Bonding, Use IO Capability to determine authentication procedure */ 143 #define SMP_AUTH_NB_IOCAP (SMP_AUTH_NO_BOND | SMP_AUTH_YN_BIT) 144 145 /* No MITM, General Bonding, Encryption only */ 146 #define SMP_AUTH_GB_ENC_ONLY (SMP_AUTH_GEN_BOND) 147 148 /* MITM, General Bonding, Use IO Capability to determine authentication 149 * procedure */ 150 #define SMP_AUTH_GB_IOCAP (SMP_AUTH_GEN_BOND | SMP_AUTH_YN_BIT) 151 152 /* Secure Connections, no MITM, no Bonding */ 153 #define SMP_AUTH_SC_ENC_ONLY (SMP_H7_SUPPORT_BIT | SMP_SC_SUPPORT_BIT) 154 155 /* Secure Connections, no MITM, Bonding */ 156 #define SMP_AUTH_SC_GB \ 157 (SMP_H7_SUPPORT_BIT | SMP_SC_SUPPORT_BIT | SMP_AUTH_GEN_BOND) 158 159 /* Secure Connections, MITM, no Bonding */ 160 #define SMP_AUTH_SC_MITM_NB \ 161 (SMP_H7_SUPPORT_BIT | SMP_SC_SUPPORT_BIT | SMP_AUTH_YN_BIT | SMP_AUTH_NO_BOND) 162 163 /* Secure Connections, MITM, Bonding */ 164 #define SMP_AUTH_SC_MITM_GB \ 165 (SMP_H7_SUPPORT_BIT | SMP_SC_SUPPORT_BIT | SMP_AUTH_YN_BIT | \ 166 SMP_AUTH_GEN_BOND) 167 168 /* All AuthReq RFU bits are set to 1 - NOTE: reserved bit in Bonding_Flags is 169 * not set */ 170 #define SMP_AUTH_ALL_RFU_SET 0xF8 171 172 typedef uint8_t tSMP_AUTH_REQ; 173 174 #define SMP_SEC_NONE 0 175 #define SMP_SEC_UNAUTHENTICATE (1 << 0) 176 #define SMP_SEC_AUTHENTICATED (1 << 2) 177 typedef uint8_t tSMP_SEC_LEVEL; 178 179 /* Maximum Encryption Key Size range */ 180 #define SMP_ENCR_KEY_SIZE_MIN 7 181 #define SMP_ENCR_KEY_SIZE_MAX 16 182 183 /* SMP key types */ 184 #define SMP_SEC_KEY_TYPE_ENC (1 << 0) /* encryption key */ 185 #define SMP_SEC_KEY_TYPE_ID (1 << 1) /* identity key */ 186 #define SMP_SEC_KEY_TYPE_CSRK (1 << 2) /* slave CSRK */ 187 #define SMP_SEC_KEY_TYPE_LK (1 << 3) /* BR/EDR link key */ 188 typedef uint8_t tSMP_KEYS; 189 190 #define SMP_BR_SEC_DEFAULT_KEY \ 191 (SMP_SEC_KEY_TYPE_ENC | SMP_SEC_KEY_TYPE_ID | SMP_SEC_KEY_TYPE_CSRK) 192 193 /* default security key distribution value */ 194 #define SMP_SEC_DEFAULT_KEY \ 195 (SMP_SEC_KEY_TYPE_ENC | SMP_SEC_KEY_TYPE_ID | SMP_SEC_KEY_TYPE_CSRK | \ 196 SMP_SEC_KEY_TYPE_LK) 197 198 #define SMP_SC_KEY_STARTED 0 /* passkey entry started */ 199 #define SMP_SC_KEY_ENTERED 1 /* passkey digit entered */ 200 #define SMP_SC_KEY_ERASED 2 /* passkey digit erased */ 201 #define SMP_SC_KEY_CLEARED 3 /* passkey cleared */ 202 #define SMP_SC_KEY_COMPLT 4 /* passkey entry completed */ 203 #define SMP_SC_KEY_OUT_OF_RANGE 5 /* out of range */ 204 typedef uint8_t tSMP_SC_KEY_TYPE; 205 206 /* data type for BTM_SP_IO_REQ_EVT */ 207 typedef struct { 208 tSMP_IO_CAP io_cap; /* local IO capabilities */ 209 tSMP_OOB_FLAG oob_data; /* OOB data present (locally) for the peer device */ 210 tSMP_AUTH_REQ auth_req; /* Authentication required (for local device) */ 211 uint8_t max_key_size; /* max encryption key size */ 212 tSMP_KEYS init_keys; /* initiator keys to be distributed */ 213 tSMP_KEYS resp_keys; /* responder keys */ 214 } tSMP_IO_REQ; 215 216 typedef struct { 217 tSMP_STATUS reason; 218 tSMP_SEC_LEVEL sec_level; 219 bool is_pair_cancel; 220 bool smp_over_br; 221 } tSMP_CMPL; 222 223 typedef struct { 224 BT_OCTET32 x; 225 BT_OCTET32 y; 226 } tSMP_PUBLIC_KEY; 227 228 /* the data associated with the info sent to the peer via OOB interface */ 229 typedef struct { 230 bool present; 231 BT_OCTET16 randomizer; 232 BT_OCTET16 commitment; 233 234 tBLE_BD_ADDR addr_sent_to; 235 BT_OCTET32 private_key_used; /* is used to calculate: */ 236 /* publ_key_used = P-256(private_key_used, curve_p256.G) - send it to the */ 237 /* other side */ 238 /* dhkey = P-256(private_key_used, publ key rcvd from the other side) */ 239 tSMP_PUBLIC_KEY publ_key_used; /* P-256(private_key_used, curve_p256.G) */ 240 } tSMP_LOC_OOB_DATA; 241 242 /* the data associated with the info received from the peer via OOB interface */ 243 typedef struct { 244 bool present; 245 BT_OCTET16 randomizer; 246 BT_OCTET16 commitment; 247 tBLE_BD_ADDR addr_rcvd_from; 248 } tSMP_PEER_OOB_DATA; 249 250 typedef struct { 251 tSMP_LOC_OOB_DATA loc_oob_data; 252 tSMP_PEER_OOB_DATA peer_oob_data; 253 } tSMP_SC_OOB_DATA; 254 255 typedef union { 256 uint32_t passkey; 257 tSMP_IO_REQ io_req; /* IO request */ 258 tSMP_CMPL cmplt; 259 tSMP_OOB_DATA_TYPE req_oob_type; 260 tSMP_LOC_OOB_DATA loc_oob_data; 261 } tSMP_EVT_DATA; 262 263 /* AES Encryption output */ 264 typedef struct { 265 uint8_t status; 266 uint8_t param_len; 267 uint16_t opcode; 268 uint8_t param_buf[BT_OCTET16_LEN]; 269 } tSMP_ENC; 270 271 /* Security Manager events - Called by the stack when Security Manager related 272 * events occur.*/ 273 typedef uint8_t(tSMP_CALLBACK)(tSMP_EVT event, BD_ADDR bd_addr, 274 tSMP_EVT_DATA* p_data); 275 276 /* callback function for CMAC algorithm 277 */ 278 typedef void(tCMAC_CMPL_CBACK)(uint8_t* p_mac, uint16_t tlen, 279 uint32_t sign_counter); 280 281 #endif // SMP_API_TYPES_H 282