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