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