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 /****************************************************************************** 20 * 21 * This file contains internally used SMP definitions 22 * 23 ******************************************************************************/ 24 25 #ifndef SMP_INT_H 26 #define SMP_INT_H 27 28 #include "btu.h" 29 #include "smp_api.h" 30 31 #define SMP_MODEL_ENC_ONLY 0 32 #define SMP_MODEL_PASSKEY 1 33 #define SMP_MODEL_OOB 2 34 #define SMP_MODEL_KEY_NOTIF 3 35 #define SMP_MODEL_MAX 4 36 typedef UINT8 tSMP_ASSO_MODEL; 37 38 39 #ifndef SMP_MAX_CONN 40 #define SMP_MAX_CONN 2 41 #endif 42 43 #define SMP_WAIT_FOR_RSP_TOUT 30 44 #define SMP_WAIT_FOR_REL_DELAY_TOUT 5 45 /* SMP L2CAP command code */ 46 #define SMP_OPCODE_PAIRING_REQ 0x01 47 #define SMP_OPCODE_PAIRING_RSP 0x02 48 #define SMP_OPCODE_CONFIRM 0x03 49 #define SMP_OPCODE_INIT 0x04 50 #define SMP_OPCODE_PAIRING_FAILED 0x05 51 #define SMP_OPCODE_ENCRYPT_INFO 0x06 52 #define SMP_OPCODE_MASTER_ID 0x07 53 #define SMP_OPCODE_IDENTITY_INFO 0x08 54 #define SMP_OPCODE_ID_ADDR 0x09 55 #define SMP_OPCODE_SIGN_INFO 0x0A 56 #define SMP_OPCODE_SEC_REQ 0x0B 57 #define SMP_OPCODE_MAX (SMP_OPCODE_SEC_REQ + 1) 58 59 /* SMP events */ 60 #define SMP_PAIRING_REQ_EVT SMP_OPCODE_PAIRING_REQ 61 #define SMP_PAIRING_RSP_EVT SMP_OPCODE_PAIRING_RSP 62 #define SMP_CONFIRM_EVT SMP_OPCODE_CONFIRM 63 #define SMP_RAND_EVT SMP_OPCODE_INIT 64 #define SMP_PAIRING_FAILED_EVT SMP_OPCODE_PAIRING_FAILED 65 #define SMP_ENCRPTION_INFO_EVT SMP_OPCODE_ENCRYPT_INFO 66 #define SMP_MASTER_ID_EVT SMP_OPCODE_MASTER_ID 67 #define SMP_ID_INFO_EVT SMP_OPCODE_IDENTITY_INFO 68 #define SMP_ID_ADDR_EVT SMP_OPCODE_ID_ADDR 69 #define SMP_SIGN_INFO_EVT SMP_OPCODE_SIGN_INFO 70 #define SMP_SECURITY_REQ_EVT SMP_OPCODE_SEC_REQ 71 72 #define SMP_SELF_DEF_EVT SMP_SECURITY_REQ_EVT 73 #define SMP_KEY_READY_EVT (SMP_SELF_DEF_EVT + 1) 74 #define SMP_ENCRYPTED_EVT (SMP_SELF_DEF_EVT + 2) 75 #define SMP_L2CAP_CONN_EVT (SMP_SELF_DEF_EVT + 3) 76 #define SMP_L2CAP_DISCONN_EVT (SMP_SELF_DEF_EVT + 4) 77 #define SMP_IO_RSP_EVT (SMP_SELF_DEF_EVT + 5) 78 #define SMP_API_SEC_GRANT_EVT (SMP_SELF_DEF_EVT + 6) 79 #define SMP_TK_REQ_EVT (SMP_SELF_DEF_EVT + 7) 80 #define SMP_AUTH_CMPL_EVT (SMP_SELF_DEF_EVT + 8) 81 #define SMP_ENC_REQ_EVT (SMP_SELF_DEF_EVT + 9) 82 #define SMP_BOND_REQ_EVT (SMP_SELF_DEF_EVT + 10) 83 #define SMP_DISCARD_SEC_REQ_EVT (SMP_SELF_DEF_EVT + 11) 84 #define SMP_RELEASE_DELAY_EVT (SMP_SELF_DEF_EVT + 12) 85 #define SMP_RELEASE_DELAY_TOUT_EVT (SMP_SELF_DEF_EVT + 13) 86 typedef UINT8 tSMP_EVENT; 87 #define SMP_MAX_EVT SMP_RELEASE_DELAY_TOUT_EVT + 1 88 89 /* auumption it's only using the low 8 bits, if bigger than that, need to expand it to be 16 bits */ 90 #define SMP_SEC_KEY_MASK 0x00ff 91 92 /* SMP pairing state */ 93 enum 94 { 95 SMP_ST_IDLE, 96 SMP_ST_WAIT_APP_RSP, 97 SMP_ST_SEC_REQ_PENDING, 98 SMP_ST_PAIR_REQ_RSP, 99 SMP_ST_WAIT_CONFIRM, 100 SMP_ST_CONFIRM, 101 SMP_ST_RAND, 102 SMP_ST_ENC_PENDING, 103 SMP_ST_BOND_PENDING, 104 SMP_ST_RELEASE_DELAY, 105 SMP_ST_MAX 106 }; 107 typedef UINT8 tSMP_STATE; 108 109 /* random and encrption activity state */ 110 enum 111 { 112 SMP_GEN_COMPARE = 1, 113 SMP_GEN_CONFIRM, 114 115 SMP_GEN_DIV_LTK, 116 SMP_GEN_DIV_CSRK, 117 SMP_GEN_RAND_V, 118 SMP_GEN_TK, 119 SMP_GEN_SRAND_MRAND, 120 SMP_GEN_SRAND_MRAND_CONT 121 }; 122 123 enum 124 { 125 SMP_KEY_TYPE_TK, 126 SMP_KEY_TYPE_CFM, 127 SMP_KEY_TYPE_CMP, 128 SMP_KEY_TYPE_STK, 129 SMP_KEY_TYPE_LTK 130 }; 131 typedef struct 132 { 133 UINT8 key_type; 134 UINT8* p_data; 135 }tSMP_KEY; 136 137 typedef union 138 { 139 UINT8 *p_data; /* UINT8 type data pointer */ 140 tSMP_KEY key; 141 UINT16 reason; 142 }tSMP_INT_DATA; 143 144 /* internal status mask */ 145 #define SMP_PAIR_FLAGS_WE_STARTED_DD (1) 146 #define SMP_PAIR_FLAGS_PEER_STARTED_DD (1 << 1) 147 #define SMP_PAIR_FLAGS_CMD_CONFIRM (1 << SMP_OPCODE_CONFIRM) /* 1 << 3 */ 148 #define SMP_PAIR_FLAG_ENC_AFTER_PAIR (1 << 4) 149 150 /* check if authentication requirement need MITM protection */ 151 #define SMP_NO_MITM_REQUIRED(x) (((x) & SMP_AUTH_YN_BIT) == 0) 152 153 #define SMP_ENCRYT_KEY_SIZE 16 154 #define SMP_ENCRYT_DATA_SIZE 16 155 #define SMP_ECNCRPYT_STATUS HCI_SUCCESS 156 157 /* SMP control block */ 158 typedef struct 159 { 160 tSMP_CALLBACK *p_callback; 161 TIMER_LIST_ENT rsp_timer_ent; 162 UINT8 trace_level; 163 164 BD_ADDR pairing_bda; 165 166 tSMP_STATE state; 167 UINT8 failure; 168 UINT8 status; 169 UINT8 role; 170 UINT8 flags; 171 UINT8 cb_evt; 172 173 tSMP_SEC_LEVEL sec_level; 174 BOOLEAN connect_initialized; 175 BT_OCTET16 confirm; 176 BT_OCTET16 rconfirm; 177 BT_OCTET16 rrand; 178 BT_OCTET16 rand; 179 tSMP_IO_CAP peer_io_caps; 180 tSMP_IO_CAP loc_io_caps; 181 tSMP_OOB_FLAG peer_oob_flag; 182 tSMP_OOB_FLAG loc_oob_flag; 183 tSMP_AUTH_REQ peer_auth_req; 184 tSMP_AUTH_REQ loc_auth_req; 185 UINT8 peer_enc_size; 186 UINT8 loc_enc_size; 187 UINT8 peer_i_key; 188 UINT8 peer_r_key; 189 UINT8 loc_i_key; 190 UINT8 loc_r_key; 191 192 BT_OCTET16 tk; 193 BT_OCTET16 ltk; 194 UINT16 div; 195 BT_OCTET16 csrk; /* storage for local CSRK */ 196 UINT16 ediv; 197 BT_OCTET8 enc_rand; 198 199 UINT8 rand_enc_proc; 200 BOOLEAN last_cmd; 201 UINT8 addr_type; 202 BD_ADDR local_bda; 203 BOOLEAN is_pair_cancel; 204 BOOLEAN discard_sec_req; 205 #if SMP_CONFORMANCE_TESTING == TRUE 206 BOOLEAN enable_test_confirm_val; 207 BT_OCTET16 test_confirm; 208 BOOLEAN enable_test_rand_val; 209 BT_OCTET16 test_rand; 210 BOOLEAN enable_test_pair_fail; 211 UINT8 pair_fail_status; 212 BOOLEAN remove_fixed_channel_disable; 213 BOOLEAN skip_test_compare_check; 214 #endif 215 216 }tSMP_CB; 217 218 /* Server Action functions are of this type */ 219 typedef void (*tSMP_ACT)(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 220 221 222 #ifdef __cplusplus 223 extern "C" 224 { 225 #endif 226 227 #if SMP_DYNAMIC_MEMORY == FALSE 228 SMP_API extern tSMP_CB smp_cb; 229 #else 230 SMP_API extern tSMP_CB *smp_cb_ptr; 231 #define smp_cb (*smp_cb_ptr) 232 #endif 233 234 #ifdef __cplusplus 235 } 236 #endif 237 238 /* Functions provided by att_main.c */ 239 SMP_API extern void smp_init (void); 240 241 #if SMP_CONFORMANCE_TESTING == TRUE 242 /* Used only for conformance testing */ 243 SMP_API extern void smp_set_test_confirm_value (BOOLEAN enable, UINT8 *p_c_value); 244 SMP_API extern void smp_set_test_rand_value (BOOLEAN enable, UINT8 *p_c_value); 245 SMP_API extern void smp_set_test_pair_fail_status (BOOLEAN enable, UINT8 status); 246 SMP_API extern void smp_remove_fixed_channel_disable (BOOLEAN disable); 247 SMP_API extern void smp_skip_compare_check (BOOLEAN enable); 248 #endif 249 /* smp main */ 250 extern void smp_sm_event(tSMP_CB *p_cb, tSMP_EVENT event, void *p_data); 251 252 extern void smp_proc_sec_request(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 253 extern void smp_send_pair_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 254 extern void smp_send_confirm(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 255 extern void smp_send_pair_fail(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 256 extern void smp_send_init(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 257 extern void smp_proc_sec_request(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 258 extern void smp_proc_pair_fail(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 259 extern void smp_proc_confirm(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 260 extern void smp_proc_init(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 261 extern void smp_proc_enc_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 262 extern void smp_proc_master_id(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 263 extern void smp_proc_id_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 264 extern void smp_proc_id_addr(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 265 extern void smp_proc_sec_grant(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 266 extern void smp_proc_sec_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 267 extern void smp_proc_sl_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 268 extern void smp_start_enc(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 269 extern void smp_enc_cmpl(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 270 extern void smp_proc_discard(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 271 extern void smp_proc_release_delay(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 272 extern void smp_proc_release_delay_tout(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 273 extern void smp_pairing_cmpl(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 274 extern void smp_decide_asso_model(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 275 extern void smp_send_app_cback(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 276 extern void smp_proc_compare(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 277 extern void smp_check_auth_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 278 extern void smp_proc_io_rsp(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 279 extern void smp_send_id_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 280 extern void smp_send_enc_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 281 extern void smp_send_csrk_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 282 extern void smp_send_ltk_reply(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 283 extern void smp_proc_pair_cmd(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 284 extern void smp_pair_terminate(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 285 extern void smp_idle_terminate(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 286 extern void smp_send_pair_rsp(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 287 extern void smp_key_distribution(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 288 extern void smp_proc_srk_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 289 extern void smp_generate_csrk(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 290 extern void smp_delay_terminate(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 291 /* smp_l2c */ 292 extern void smp_l2cap_if_init (void); 293 294 /* smp utility */ 295 extern BOOLEAN smp_send_cmd(UINT8 cmd_code, tSMP_CB *p_cb); 296 extern void smp_cb_cleanup(tSMP_CB *p_cb); 297 extern void smp_reset_control_value(tSMP_CB *p_cb); 298 extern void smp_proc_pairing_cmpl(tSMP_CB *p_cb); 299 extern void smp_convert_string_to_tk(BT_OCTET16 tk, UINT32 passkey); 300 extern void smp_mask_enc_key(UINT8 loc_enc_size, UINT8 * p_data); 301 extern void smp_rsp_timeout(TIMER_LIST_ENT *p_tle); 302 extern void smp_xor_128(BT_OCTET16 a, BT_OCTET16 b); 303 extern BOOLEAN smp_encrypt_data (UINT8 *key, UINT8 key_len, 304 UINT8 *plain_text, UINT8 pt_len, 305 tSMP_ENC *p_out); 306 /* smp key */ 307 extern void smp_generate_confirm (tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 308 extern void smp_generate_compare (tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 309 extern void smp_generate_stk (tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 310 extern void smp_generate_ltk(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 311 extern void smp_generate_passkey (tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 312 extern void smp_genenrate_rand_cont(tSMP_CB *p_cb, tSMP_INT_DATA *p_data); 313 314 /* smp main util */ 315 extern void smp_set_state(tSMP_STATE state); 316 extern tSMP_STATE smp_get_state(void); 317 318 #endif /* SMP_INT_H */ 319 320