smp_int.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. /******************************************************************************
  2. *
  3. * Copyright 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. * This file contains internally used SMP definitions
  21. *
  22. ******************************************************************************/
  23. #ifndef SMP_INT_H
  24. #define SMP_INT_H
  25. #include "btm_api.h"
  26. #include "btm_ble_api.h"
  27. #include "btu.h"
  28. #include "smp_api.h"
  29. #include "stack/crypto_toolbox/crypto_toolbox.h"
  30. /* Legacy mode */
  31. #define SMP_MODEL_ENCRYPTION_ONLY 0 /* Just Works model */
  32. #define SMP_MODEL_PASSKEY 1 /* Passkey Entry model, input the key */
  33. #define SMP_MODEL_OOB 2 /* OOB model */
  34. #define SMP_MODEL_KEY_NOTIF 3 /* Passkey Entry model, display the key */
  35. /* Secure connections mode */
  36. #define SMP_MODEL_SEC_CONN_JUSTWORKS 4 /* Just Works model */
  37. #define SMP_MODEL_SEC_CONN_NUM_COMP 5 /* Numeric Comparison model */
  38. #define SMP_MODEL_SEC_CONN_PASSKEY_ENT 6 /* Passkey Entry model, */
  39. /* this side inputs the key */
  40. #define SMP_MODEL_SEC_CONN_PASSKEY_DISP 7 /* Passkey Entry model, */
  41. /* this side displays the key */
  42. #define SMP_MODEL_SEC_CONN_OOB 8 /* Secure Connections mode, OOB model */
  43. #define SMP_MODEL_OUT_OF_RANGE 9
  44. typedef uint8_t tSMP_ASSO_MODEL;
  45. #ifndef SMP_MAX_CONN
  46. #define SMP_MAX_CONN 2
  47. #endif
  48. #define SMP_WAIT_FOR_RSP_TIMEOUT_MS (30 * 1000)
  49. #define SMP_DELAYED_AUTH_TIMEOUT_MS 500
  50. #define SMP_OPCODE_INIT 0x04
  51. /* SMP events */
  52. #define SMP_PAIRING_REQ_EVT SMP_OPCODE_PAIRING_REQ
  53. #define SMP_PAIRING_RSP_EVT SMP_OPCODE_PAIRING_RSP
  54. #define SMP_CONFIRM_EVT SMP_OPCODE_CONFIRM
  55. #define SMP_RAND_EVT SMP_OPCODE_RAND
  56. #define SMP_PAIRING_FAILED_EVT SMP_OPCODE_PAIRING_FAILED
  57. #define SMP_ENCRPTION_INFO_EVT SMP_OPCODE_ENCRYPT_INFO
  58. #define SMP_MASTER_ID_EVT SMP_OPCODE_MASTER_ID
  59. #define SMP_ID_INFO_EVT SMP_OPCODE_IDENTITY_INFO
  60. #define SMP_ID_ADDR_EVT SMP_OPCODE_ID_ADDR
  61. #define SMP_SIGN_INFO_EVT SMP_OPCODE_SIGN_INFO
  62. #define SMP_SECURITY_REQ_EVT SMP_OPCODE_SEC_REQ
  63. #define SMP_PAIR_PUBLIC_KEY_EVT SMP_OPCODE_PAIR_PUBLIC_KEY
  64. #define SMP_PAIR_KEYPRESS_NOTIFICATION_EVT SMP_OPCODE_PAIR_KEYPR_NOTIF
  65. #define SMP_PAIR_COMMITM_EVT SMP_OPCODE_PAIR_COMMITM
  66. #define SMP_SELF_DEF_EVT (SMP_PAIR_COMMITM_EVT + 1)
  67. #define SMP_KEY_READY_EVT (SMP_SELF_DEF_EVT)
  68. #define SMP_ENCRYPTED_EVT (SMP_SELF_DEF_EVT + 1)
  69. #define SMP_L2CAP_CONN_EVT (SMP_SELF_DEF_EVT + 2)
  70. #define SMP_L2CAP_DISCONN_EVT (SMP_SELF_DEF_EVT + 3)
  71. #define SMP_IO_RSP_EVT (SMP_SELF_DEF_EVT + 4)
  72. #define SMP_API_SEC_GRANT_EVT (SMP_SELF_DEF_EVT + 5)
  73. #define SMP_TK_REQ_EVT (SMP_SELF_DEF_EVT + 6)
  74. #define SMP_AUTH_CMPL_EVT (SMP_SELF_DEF_EVT + 7)
  75. #define SMP_ENC_REQ_EVT (SMP_SELF_DEF_EVT + 8)
  76. #define SMP_BOND_REQ_EVT (SMP_SELF_DEF_EVT + 9)
  77. #define SMP_DISCARD_SEC_REQ_EVT (SMP_SELF_DEF_EVT + 10)
  78. #define SMP_PAIR_DHKEY_CHCK_EVT SMP_OPCODE_PAIR_DHKEY_CHECK
  79. /* request to start public key exchange */
  80. #define SMP_PUBL_KEY_EXCH_REQ_EVT (SMP_SELF_DEF_EVT + 11)
  81. /* local public key created */
  82. #define SMP_LOC_PUBL_KEY_CRTD_EVT (SMP_SELF_DEF_EVT + 12)
  83. /* both local and peer public keys are saved in cb */
  84. #define SMP_BOTH_PUBL_KEYS_RCVD_EVT (SMP_SELF_DEF_EVT + 13)
  85. /* DHKey computation is completed, time to start SC phase1 */
  86. #define SMP_SC_DHKEY_CMPLT_EVT (SMP_SELF_DEF_EVT + 14)
  87. /* new local nonce is generated and saved in p_cb->rand */
  88. #define SMP_HAVE_LOC_NONCE_EVT (SMP_SELF_DEF_EVT + 15)
  89. /* time to start SC phase2 */
  90. #define SMP_SC_PHASE1_CMPLT_EVT (SMP_SELF_DEF_EVT + 16)
  91. /* request to calculate number for user check. Used only in the numeric compare
  92. * protocol */
  93. #define SMP_SC_CALC_NC_EVT (SMP_SELF_DEF_EVT + 17)
  94. /* Request to display the number for user check to the user.*/
  95. /* Used only in the numeric compare protocol */
  96. #define SMP_SC_DSPL_NC_EVT (SMP_SELF_DEF_EVT + 18)
  97. /* user confirms 'OK' numeric comparison request */
  98. #define SMP_SC_NC_OK_EVT (SMP_SELF_DEF_EVT + 19)
  99. /* both local and peer DHKey Checks are already present - it is used on slave to
  100. * prevent a race condition */
  101. #define SMP_SC_2_DHCK_CHKS_PRES_EVT (SMP_SELF_DEF_EVT + 20)
  102. /* same meaning as SMP_KEY_READY_EVT to separate between SC and legacy actions
  103. */
  104. #define SMP_SC_KEY_READY_EVT (SMP_SELF_DEF_EVT + 21)
  105. #define SMP_KEYPRESS_NOTIFICATION_EVENT (SMP_SELF_DEF_EVT + 22)
  106. /* SC OOB data from some repository is provided */
  107. #define SMP_SC_OOB_DATA_EVT (SMP_SELF_DEF_EVT + 23)
  108. #define SMP_CR_LOC_SC_OOB_DATA_EVT (SMP_SELF_DEF_EVT + 24)
  109. #define SMP_MAX_EVT SMP_CR_LOC_SC_OOB_DATA_EVT
  110. typedef uint8_t tSMP_EVENT;
  111. /* Assumption it's only using the low 8 bits, if bigger than that, need to
  112. * expand it to 16 bits */
  113. #define SMP_SEC_KEY_MASK 0x00ff
  114. /* SMP pairing state */
  115. enum {
  116. SMP_STATE_IDLE,
  117. SMP_STATE_WAIT_APP_RSP,
  118. SMP_STATE_SEC_REQ_PENDING,
  119. SMP_STATE_PAIR_REQ_RSP,
  120. SMP_STATE_WAIT_CONFIRM,
  121. SMP_STATE_CONFIRM,
  122. SMP_STATE_RAND,
  123. SMP_STATE_PUBLIC_KEY_EXCH,
  124. SMP_STATE_SEC_CONN_PHS1_START,
  125. SMP_STATE_WAIT_COMMITMENT,
  126. SMP_STATE_WAIT_NONCE,
  127. SMP_STATE_SEC_CONN_PHS2_START,
  128. SMP_STATE_WAIT_DHK_CHECK,
  129. SMP_STATE_DHK_CHECK,
  130. SMP_STATE_ENCRYPTION_PENDING,
  131. SMP_STATE_BOND_PENDING,
  132. SMP_STATE_CREATE_LOCAL_SEC_CONN_OOB_DATA,
  133. SMP_STATE_MAX
  134. };
  135. typedef uint8_t tSMP_STATE;
  136. /* SMP over BR/EDR events */
  137. #define SMP_BR_PAIRING_REQ_EVT SMP_OPCODE_PAIRING_REQ
  138. #define SMP_BR_PAIRING_RSP_EVT SMP_OPCODE_PAIRING_RSP
  139. #define SMP_BR_CONFIRM_EVT SMP_OPCODE_CONFIRM /* not over BR/EDR */
  140. #define SMP_BR_RAND_EVT SMP_OPCODE_RAND /* not over BR/EDR */
  141. #define SMP_BR_PAIRING_FAILED_EVT SMP_OPCODE_PAIRING_FAILED
  142. #define SMP_BR_ENCRPTION_INFO_EVT \
  143. SMP_OPCODE_ENCRYPT_INFO /* not over BR/EDR \
  144. */
  145. #define SMP_BR_MASTER_ID_EVT SMP_OPCODE_MASTER_ID /* not over BR/EDR */
  146. #define SMP_BR_ID_INFO_EVT SMP_OPCODE_IDENTITY_INFO
  147. #define SMP_BR_ID_ADDR_EVT SMP_OPCODE_ID_ADDR
  148. #define SMP_BR_SIGN_INFO_EVT SMP_OPCODE_SIGN_INFO
  149. #define SMP_BR_SECURITY_REQ_EVT SMP_OPCODE_SEC_REQ /* not over BR/EDR */
  150. #define SMP_BR_PAIR_PUBLIC_KEY_EVT \
  151. SMP_OPCODE_PAIR_PUBLIC_KEY /* not over BR/EDR */
  152. #define SMP_BR_PAIR_DHKEY_CHCK_EVT \
  153. SMP_OPCODE_PAIR_DHKEY_CHECK /* not over BR/EDR */
  154. #define SMP_BR_PAIR_KEYPR_NOTIF_EVT \
  155. SMP_OPCODE_PAIR_KEYPR_NOTIF /* not over BR/EDR */
  156. #define SMP_BR_SELF_DEF_EVT SMP_BR_PAIR_KEYPR_NOTIF_EVT
  157. #define SMP_BR_KEY_READY_EVT (SMP_BR_SELF_DEF_EVT + 1)
  158. #define SMP_BR_ENCRYPTED_EVT (SMP_BR_SELF_DEF_EVT + 2)
  159. #define SMP_BR_L2CAP_CONN_EVT (SMP_BR_SELF_DEF_EVT + 3)
  160. #define SMP_BR_L2CAP_DISCONN_EVT (SMP_BR_SELF_DEF_EVT + 4)
  161. #define SMP_BR_KEYS_RSP_EVT (SMP_BR_SELF_DEF_EVT + 5)
  162. #define SMP_BR_API_SEC_GRANT_EVT (SMP_BR_SELF_DEF_EVT + 6)
  163. #define SMP_BR_TK_REQ_EVT (SMP_BR_SELF_DEF_EVT + 7)
  164. #define SMP_BR_AUTH_CMPL_EVT (SMP_BR_SELF_DEF_EVT + 8)
  165. #define SMP_BR_ENC_REQ_EVT (SMP_BR_SELF_DEF_EVT + 9)
  166. #define SMP_BR_BOND_REQ_EVT (SMP_BR_SELF_DEF_EVT + 10)
  167. #define SMP_BR_DISCARD_SEC_REQ_EVT (SMP_BR_SELF_DEF_EVT + 11)
  168. #define SMP_BR_MAX_EVT (SMP_BR_SELF_DEF_EVT + 12)
  169. typedef uint8_t tSMP_BR_EVENT;
  170. /* SMP over BR/EDR pairing states */
  171. enum {
  172. SMP_BR_STATE_IDLE = SMP_STATE_IDLE,
  173. SMP_BR_STATE_WAIT_APP_RSP,
  174. SMP_BR_STATE_PAIR_REQ_RSP,
  175. SMP_BR_STATE_BOND_PENDING,
  176. SMP_BR_STATE_MAX
  177. };
  178. typedef uint8_t tSMP_BR_STATE;
  179. enum {
  180. SMP_KEY_TYPE_TK,
  181. SMP_KEY_TYPE_CFM,
  182. SMP_KEY_TYPE_CMP,
  183. SMP_KEY_TYPE_PEER_DHK_CHCK,
  184. SMP_KEY_TYPE_STK,
  185. SMP_KEY_TYPE_LTK
  186. };
  187. typedef struct {
  188. uint8_t key_type;
  189. uint8_t* p_data;
  190. } tSMP_KEY;
  191. typedef union {
  192. uint8_t* p_data; /* uint8_t type data pointer */
  193. tSMP_KEY key;
  194. uint8_t status;
  195. uint16_t reason;
  196. uint32_t passkey;
  197. tSMP_OOB_DATA_TYPE req_oob_type;
  198. } tSMP_INT_DATA;
  199. /* internal status mask */
  200. #define SMP_PAIR_FLAGS_WE_STARTED_DD (1)
  201. #define SMP_PAIR_FLAGS_PEER_STARTED_DD (1 << 1)
  202. #define SMP_PAIR_FLAGS_CMD_CONFIRM (1 << SMP_OPCODE_CONFIRM) /* 1 << 3 */
  203. #define SMP_PAIR_FLAG_ENC_AFTER_PAIR (1 << 4)
  204. #define SMP_PAIR_FLAG_HAVE_PEER_DHK_CHK \
  205. (1 << 5) /* used on slave to resolve race condition */
  206. #define SMP_PAIR_FLAG_HAVE_PEER_PUBL_KEY \
  207. (1 << 6) /* used on slave to resolve race condition */
  208. #define SMP_PAIR_FLAG_HAVE_PEER_COMM \
  209. (1 << 7) /* used to resolve race condition */
  210. #define SMP_PAIR_FLAG_HAVE_LOCAL_PUBL_KEY \
  211. (1 << 8) /* used on slave to resolve race condition */
  212. /* check if authentication requirement need MITM protection */
  213. #define SMP_NO_MITM_REQUIRED(x) (((x)&SMP_AUTH_YN_BIT) == 0)
  214. typedef struct {
  215. RawAddress bd_addr;
  216. BT_HDR* p_copy;
  217. } tSMP_REQ_Q_ENTRY;
  218. /* SMP control block */
  219. typedef struct {
  220. tSMP_CALLBACK* p_callback;
  221. alarm_t* smp_rsp_timer_ent;
  222. uint8_t trace_level;
  223. RawAddress pairing_bda;
  224. tSMP_STATE state;
  225. bool derive_lk;
  226. bool id_addr_rcvd;
  227. tBLE_ADDR_TYPE id_addr_type;
  228. RawAddress id_addr;
  229. bool smp_over_br;
  230. tSMP_BR_STATE br_state; /* if SMP over BR/ERD has priority over SMP */
  231. uint8_t failure;
  232. uint8_t status;
  233. uint8_t role;
  234. uint16_t flags;
  235. uint8_t cb_evt;
  236. tSMP_SEC_LEVEL sec_level;
  237. bool connect_initialized;
  238. Octet16 confirm;
  239. Octet16 rconfirm;
  240. Octet16 rrand; /* for SC this is peer nonce */
  241. Octet16 rand; /* for SC this is local nonce */
  242. BT_OCTET32 private_key;
  243. BT_OCTET32 dhkey;
  244. Octet16 commitment;
  245. Octet16 remote_commitment;
  246. Octet16 local_random; /* local randomizer - passkey or OOB randomizer */
  247. Octet16 peer_random; /* peer randomizer - passkey or OOB randomizer */
  248. Octet16 dhkey_check;
  249. Octet16 remote_dhkey_check;
  250. tSMP_PUBLIC_KEY loc_publ_key;
  251. tSMP_PUBLIC_KEY peer_publ_key;
  252. tSMP_OOB_DATA_TYPE req_oob_type;
  253. tSMP_SC_OOB_DATA sc_oob_data;
  254. tSMP_IO_CAP peer_io_caps;
  255. tSMP_IO_CAP local_io_capability;
  256. tSMP_OOB_FLAG peer_oob_flag;
  257. tSMP_OOB_FLAG loc_oob_flag;
  258. tSMP_AUTH_REQ peer_auth_req;
  259. tSMP_AUTH_REQ loc_auth_req;
  260. bool secure_connections_only_mode_required; /* true if locally SM is required
  261. to operate */
  262. /* either in Secure Connections mode or not at all */
  263. tSMP_ASSO_MODEL selected_association_model;
  264. bool le_secure_connections_mode_is_used;
  265. bool key_derivation_h7_used;
  266. bool le_sc_kp_notif_is_used;
  267. tSMP_SC_KEY_TYPE local_keypress_notification;
  268. tSMP_SC_KEY_TYPE peer_keypress_notification;
  269. uint8_t
  270. round; /* authentication stage 1 round for passkey association model */
  271. uint32_t number_to_display;
  272. Octet16 mac_key;
  273. uint8_t peer_enc_size;
  274. uint8_t loc_enc_size;
  275. uint8_t peer_i_key;
  276. uint8_t peer_r_key;
  277. uint8_t local_i_key;
  278. uint8_t local_r_key;
  279. Octet16 tk;
  280. Octet16 ltk;
  281. uint16_t div;
  282. Octet16 csrk; /* storage for local CSRK */
  283. uint16_t ediv;
  284. BT_OCTET8 enc_rand;
  285. uint8_t addr_type;
  286. RawAddress local_bda;
  287. bool is_pair_cancel;
  288. bool discard_sec_req;
  289. uint8_t rcvd_cmd_code;
  290. uint8_t rcvd_cmd_len;
  291. uint16_t total_tx_unacked;
  292. bool wait_for_authorization_complete;
  293. uint8_t cert_failure; /*failure case for certification */
  294. alarm_t* delayed_auth_timer_ent;
  295. } tSMP_CB;
  296. /* Server Action functions are of this type */
  297. typedef void (*tSMP_ACT)(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  298. extern tSMP_CB smp_cb;
  299. /* Functions provided by att_main.cc */
  300. extern void smp_init(void);
  301. /* smp main */
  302. extern void smp_sm_event(tSMP_CB* p_cb, tSMP_EVENT event,
  303. tSMP_INT_DATA* p_data);
  304. extern tSMP_STATE smp_get_state(void);
  305. extern void smp_set_state(tSMP_STATE state);
  306. /* smp_br_main */
  307. extern void smp_br_state_machine_event(tSMP_CB* p_cb, tSMP_BR_EVENT event,
  308. tSMP_INT_DATA* p_data);
  309. extern tSMP_BR_STATE smp_get_br_state(void);
  310. extern void smp_set_br_state(tSMP_BR_STATE state);
  311. /* smp_act.cc */
  312. extern void smp_send_pair_req(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  313. extern void smp_send_confirm(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  314. extern void smp_send_pair_fail(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  315. extern void smp_send_rand(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  316. extern void smp_send_pair_public_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  317. extern void smp_send_commitment(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  318. extern void smp_send_dhkey_check(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  319. extern void smp_send_keypress_notification(tSMP_CB* p_cb,
  320. tSMP_INT_DATA* p_data);
  321. extern void smp_proc_pair_fail(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  322. extern void smp_proc_confirm(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  323. extern void smp_proc_rand(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  324. extern void smp_process_pairing_public_key(tSMP_CB* p_cb,
  325. tSMP_INT_DATA* p_data);
  326. extern void smp_proc_enc_info(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  327. extern void smp_proc_master_id(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  328. extern void smp_proc_id_info(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  329. extern void smp_proc_id_addr(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  330. extern void smp_proc_sec_grant(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  331. extern void smp_proc_sec_req(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  332. extern void smp_proc_sl_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  333. extern void smp_start_enc(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  334. extern void smp_enc_cmpl(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  335. extern void smp_proc_discard(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  336. extern void smp_pairing_cmpl(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  337. extern void smp_decide_association_model(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  338. extern void smp_send_app_cback(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  339. extern void smp_proc_compare(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  340. extern void smp_check_auth_req(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  341. extern void smp_process_io_response(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  342. extern void smp_send_id_info(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  343. extern void smp_send_enc_info(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  344. extern void smp_send_csrk_info(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  345. extern void smp_send_ltk_reply(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  346. extern void smp_proc_pair_cmd(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  347. extern void smp_pair_terminate(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  348. extern void smp_idle_terminate(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  349. extern void smp_send_pair_rsp(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  350. extern void smp_key_distribution(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  351. extern void smp_proc_srk_info(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  352. extern void smp_generate_csrk(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  353. extern void smp_key_pick_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  354. extern void smp_both_have_public_keys(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  355. extern void smp_start_secure_connection_phase1(tSMP_CB* p_cb,
  356. tSMP_INT_DATA* p_data);
  357. extern void smp_process_local_nonce(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  358. extern void smp_process_pairing_commitment(tSMP_CB* p_cb,
  359. tSMP_INT_DATA* p_data);
  360. extern void smp_process_peer_nonce(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  361. extern void smp_process_dhkey_check(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  362. extern void smp_match_dhkey_checks(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  363. extern void smp_process_keypress_notification(tSMP_CB* p_cb,
  364. tSMP_INT_DATA* p_data);
  365. extern void smp_move_to_secure_connections_phase2(tSMP_CB* p_cb,
  366. tSMP_INT_DATA* p_data);
  367. extern void smp_phase_2_dhkey_checks_are_present(tSMP_CB* p_cb,
  368. tSMP_INT_DATA* p_data);
  369. extern void smp_wait_for_both_public_keys(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  370. extern void smp_start_passkey_verification(tSMP_CB* p_cb,
  371. tSMP_INT_DATA* p_data);
  372. extern void smp_process_secure_connection_oob_data(tSMP_CB* p_cb,
  373. tSMP_INT_DATA* p_data);
  374. extern void smp_process_secure_connection_long_term_key(void);
  375. extern void smp_set_local_oob_keys(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  376. extern void smp_set_local_oob_random_commitment(tSMP_CB* p_cb,
  377. tSMP_INT_DATA* p_data);
  378. extern void smp_set_derive_link_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  379. extern void smp_derive_link_key_from_long_term_key(tSMP_CB* p_cb,
  380. tSMP_INT_DATA* p_data);
  381. extern void smp_br_process_pairing_command(tSMP_CB* p_cb,
  382. tSMP_INT_DATA* p_data);
  383. extern void smp_br_process_security_grant(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  384. extern void smp_br_process_slave_keys_response(tSMP_CB* p_cb,
  385. tSMP_INT_DATA* p_data);
  386. extern void smp_br_send_pair_response(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  387. extern void smp_br_check_authorization_request(tSMP_CB* p_cb,
  388. tSMP_INT_DATA* p_data);
  389. extern void smp_br_select_next_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  390. extern void smp_br_process_link_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  391. extern void smp_key_distribution_by_transport(tSMP_CB* p_cb,
  392. tSMP_INT_DATA* p_data);
  393. extern void smp_br_pairing_complete(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  394. /* smp_l2c */
  395. extern void smp_l2cap_if_init(void);
  396. extern void smp_data_ind(const RawAddress& bd_addr, BT_HDR* p_buf);
  397. /* smp_util.cc */
  398. extern void smp_log_metrics(const RawAddress& bd_addr, bool is_outgoing,
  399. const uint8_t* p_buf, size_t buf_len);
  400. extern bool smp_send_cmd(uint8_t cmd_code, tSMP_CB* p_cb);
  401. extern void smp_cb_cleanup(tSMP_CB* p_cb);
  402. extern void smp_reset_control_value(tSMP_CB* p_cb);
  403. extern void smp_proc_pairing_cmpl(tSMP_CB* p_cb);
  404. extern void smp_convert_string_to_tk(Octet16* tk, uint32_t passkey);
  405. extern void smp_mask_enc_key(uint8_t loc_enc_size, Octet16* p_data);
  406. extern void smp_rsp_timeout(void* data);
  407. extern void smp_delayed_auth_complete_timeout(void* data);
  408. extern bool smp_command_has_invalid_length(tSMP_CB* p_cb);
  409. extern bool smp_command_has_invalid_parameters(tSMP_CB* p_cb);
  410. extern void smp_reject_unexpected_pairing_command(const RawAddress& bd_addr);
  411. extern tSMP_ASSO_MODEL smp_select_association_model(tSMP_CB* p_cb);
  412. extern void smp_reverse_array(uint8_t* arr, uint8_t len);
  413. extern uint8_t smp_calculate_random_input(uint8_t* random, uint8_t round);
  414. extern void smp_collect_local_io_capabilities(uint8_t* iocap, tSMP_CB* p_cb);
  415. extern void smp_collect_peer_io_capabilities(uint8_t* iocap, tSMP_CB* p_cb);
  416. extern void smp_collect_local_ble_address(uint8_t* le_addr, tSMP_CB* p_cb);
  417. extern void smp_collect_peer_ble_address(uint8_t* le_addr, tSMP_CB* p_cb);
  418. extern bool smp_check_commitment(tSMP_CB* p_cb);
  419. extern void smp_save_secure_connections_long_term_key(tSMP_CB* p_cb);
  420. extern void smp_calculate_f5_mackey_and_long_term_key(tSMP_CB* p_cb);
  421. extern void smp_remove_fixed_channel(tSMP_CB* p_cb);
  422. extern bool smp_request_oob_data(tSMP_CB* p_cb);
  423. /* smp_keys.cc */
  424. extern void smp_generate_srand_mrand_confirm(tSMP_CB* p_cb,
  425. tSMP_INT_DATA* p_data);
  426. extern void smp_generate_compare(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  427. extern void smp_generate_stk(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  428. extern void smp_generate_ltk(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  429. extern void smp_generate_passkey(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  430. extern void smp_generate_rand_cont(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  431. extern void smp_create_private_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  432. extern void smp_use_oob_private_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  433. extern void smp_compute_dhkey(tSMP_CB* p_cb);
  434. extern void smp_calculate_local_commitment(tSMP_CB* p_cb);
  435. extern Octet16 smp_calculate_peer_commitment(tSMP_CB* p_cb);
  436. extern void smp_calculate_numeric_comparison_display_number(
  437. tSMP_CB* p_cb, tSMP_INT_DATA* p_data);
  438. extern void smp_calculate_local_dhkey_check(tSMP_CB* p_cb,
  439. tSMP_INT_DATA* p_data);
  440. extern void smp_calculate_peer_dhkey_check(tSMP_CB* p_cb,
  441. tSMP_INT_DATA* p_data);
  442. extern void smp_start_nonce_generation(tSMP_CB* p_cb);
  443. extern bool smp_calculate_link_key_from_long_term_key(tSMP_CB* p_cb);
  444. extern bool smp_calculate_long_term_key_from_link_key(tSMP_CB* p_cb);
  445. #if (SMP_DEBUG == TRUE)
  446. extern void smp_debug_print_nbyte_little_endian(uint8_t* p,
  447. const char* key_name,
  448. uint8_t len);
  449. inline void smp_debug_print_nbyte_little_endian(const Octet16& p,
  450. const char* key_name,
  451. uint8_t len) {
  452. smp_debug_print_nbyte_little_endian(const_cast<uint8_t*>(p.data()), key_name,
  453. len);
  454. }
  455. #endif
  456. extern void print128(const Octet16& x, const uint8_t* key_name);
  457. extern void smp_xor_128(Octet16* a, const Octet16& b);
  458. #endif /* SMP_INT_H */