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