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 the SMP API function external definitions.
22  *
23  ******************************************************************************/
24 #ifndef SMP_API_H
25 #define SMP_API_H
26 
27 #include <cstdint>
28 
29 #include "smp_api_types.h"
30 #include "types/ble_address_with_type.h"
31 #include "types/raw_address.h"
32 
33 /*****************************************************************************
34  *  External Function Declarations
35  ****************************************************************************/
36 /* API of SMP */
37 
38 /*******************************************************************************
39  *
40  * Function         SMP_Init
41  *
42  * Description      This function initializes the SMP unit.
43  *
44  * Returns          void
45  *
46  ******************************************************************************/
47 void SMP_Init(uint8_t init_security_mode);
48 
49 /*******************************************************************************
50  *
51  * Function         SMP_Register
52  *
53  * Description      This function register for the SMP service callback.
54  *
55  * Returns          void
56  *
57  ******************************************************************************/
58 bool SMP_Register(tSMP_CALLBACK* p_cback);
59 
60 /*******************************************************************************
61  *
62  * Function         SMP_Pair
63  *
64  * Description      This function is called to start a SMP pairing.
65  *
66  * Returns          SMP_STARTED if bond started, else otherwise exception.
67  *
68  ******************************************************************************/
69 tSMP_STATUS SMP_Pair(const RawAddress& bd_addr);
70 tSMP_STATUS SMP_Pair(const RawAddress& bd_addr, tBLE_ADDR_TYPE addr_type);
71 
72 /*******************************************************************************
73  *
74  * Function         SMP_BR_PairWith
75  *
76  * Description      This function is called to start a SMP pairing over BR/EDR.
77  *
78  * Returns          SMP_STARTED if pairing started, otherwise the reason for the
79  *                  failure.
80  *
81  ******************************************************************************/
82 tSMP_STATUS SMP_BR_PairWith(const RawAddress& bd_addr);
83 
84 /*******************************************************************************
85  *
86  * Function         SMP_PairCancel
87  *
88  * Description      This function is called to cancel a SMP pairing.
89  *
90  * Returns          true - pairing cancelled
91  *
92  ******************************************************************************/
93 bool SMP_PairCancel(const RawAddress& bd_addr);
94 
95 /*******************************************************************************
96  *
97  * Function         SMP_SecurityGrant
98  *
99  * Description      This function is called to grant security process.
100  *
101  * Parameters       bd_addr - peer device bd address.
102  *                  res     - result of the operation SMP_SUCCESS if success.
103  *                            Otherwise, SMP_REPEATED_ATTEMPTS is too many
104  *                            attempts.
105  *
106  * Returns          None
107  *
108  ******************************************************************************/
109 void SMP_SecurityGrant(const RawAddress& bd_addr, tSMP_STATUS res);
110 
111 /*******************************************************************************
112  *
113  * Function         SMP_PasskeyReply
114  *
115  * Description      This function is called after Security Manager submitted
116  *                  Passkey request to the application.
117  *
118  * Parameters:      bd_addr  - Address of the device for which PIN was requested
119  *                  res      - result of the operation SMP_SUCCESS if success
120  *                  passkey  - numeric value in the range of
121  *                             BTM_MIN_PASSKEY_VAL(0) -
122  *                             BTM_MAX_PASSKEY_VAL(999999(0xF423F)).
123  *
124  ******************************************************************************/
125 void SMP_PasskeyReply(const RawAddress& bd_addr, uint8_t res, uint32_t passkey);
126 
127 /*******************************************************************************
128  *
129  * Function         SMP_ConfirmReply
130  *
131  * Description      This function is called after Security Manager submitted
132  *                  numeric comparison request to the application.
133  *
134  * Parameters:      bd_addr      - Address of the device with which numeric
135  *                                 comparison was requested
136  *                  res          - comparison result SMP_SUCCESS if success
137  *
138  ******************************************************************************/
139 void SMP_ConfirmReply(const RawAddress& bd_addr, uint8_t res);
140 
141 /*******************************************************************************
142  *
143  * Function         SMP_OobDataReply
144  *
145  * Description      This function is called to provide the OOB data for
146  *                  SMP in response to SMP_OOB_REQ_EVT
147  *
148  * Parameters:      bd_addr     - Address of the peer device
149  *                  res         - result of the operation SMP_SUCCESS if success
150  *                  p_data      - SM Randomizer  C.
151  *
152  ******************************************************************************/
153 void SMP_OobDataReply(const RawAddress& bd_addr, tSMP_STATUS res, uint8_t len, uint8_t* p_data);
154 
155 /*******************************************************************************
156  *
157  * Function         SMP_SecureConnectionOobDataReply
158  *
159  * Description      This function is called to provide the SC OOB data for
160  *                  SMP in response to SMP_SC_OOB_REQ_EVT
161  *
162  * Parameters:      p_data      - pointer to the data
163  *
164  ******************************************************************************/
165 void SMP_SecureConnectionOobDataReply(uint8_t* p_data);
166 
167 /*******************************************************************************
168  *
169  * Function         SMP_CrLocScOobData
170  *
171  * Description      This function is called to generate a public key to be
172  *                  passed to a remote device via an Out of Band transport
173  *
174  * Returns          true if the request is successfully sent and executed by the
175  *                  state machine, false otherwise
176  *
177  ******************************************************************************/
178 bool SMP_CrLocScOobData();
179 
180 /*******************************************************************************
181  *
182  * Function         SMP_ClearLocScOobData
183  *
184  * Description      This function is called to clear out the OOB stored locally.
185  *
186  ******************************************************************************/
187 void SMP_ClearLocScOobData();
188 
189 /*******************************************************************************
190  *
191  * Function         SMP_SirkConfirmDeviceReply
192  *
193  * Description      This function is called after Security Manager submitted
194  *                  verification of device with CSIP.
195  *
196  * Parameters:      bd_addr      - Address of the device with which verification
197  *                                 was requested
198  *                  res          - comparison result SMP_SUCCESS if success
199  *
200  ******************************************************************************/
201 void SMP_SirkConfirmDeviceReply(const RawAddress& bd_addr, uint8_t res);
202 
203 // Called when LTK request is received from controller.
204 bool smp_proc_ltk_request(const RawAddress& bda);
205 
206 // Called when link is encrypted and notified to peripheral device.
207 // Proceed to send LTK, DIV and ER to central if bonding the devices.
208 void smp_link_encrypted(const RawAddress& bda, uint8_t encr_enable);
209 
210 void smp_cancel_start_encryption_attempt();
211 
212 #endif /* SMP_API_H */
213