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