• 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 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 
30 /*****************************************************************************
31  *  External Function Declarations
32  ****************************************************************************/
33 /* API of SMP */
34 
35 /*******************************************************************************
36  *
37  * Function         SMP_Init
38  *
39  * Description      This function initializes the SMP unit.
40  *
41  * Returns          void
42  *
43  ******************************************************************************/
44 extern void SMP_Init(void);
45 
46 /*******************************************************************************
47  *
48  * Function         SMP_SetTraceLevel
49  *
50  * Description      This function sets the trace level for SMP.  If called with
51  *                  a value of 0xFF, it simply returns the current trace level.
52  *
53  * Returns          The new or current trace level
54  *
55  ******************************************************************************/
56 extern uint8_t SMP_SetTraceLevel(uint8_t new_level);
57 
58 /*******************************************************************************
59  *
60  * Function         SMP_Register
61  *
62  * Description      This function register for the SMP service callback.
63  *
64  * Returns          void
65  *
66  ******************************************************************************/
67 extern bool SMP_Register(tSMP_CALLBACK* p_cback);
68 
69 /*******************************************************************************
70  *
71  * Function         SMP_Pair
72  *
73  * Description      This function is called to start a SMP pairing.
74  *
75  * Returns          SMP_STARTED if bond started, else otherwise exception.
76  *
77  ******************************************************************************/
78 extern tSMP_STATUS SMP_Pair(const RawAddress& bd_addr);
79 
80 /*******************************************************************************
81  *
82  * Function         SMP_BR_PairWith
83  *
84  * Description      This function is called to start a SMP pairing over BR/EDR.
85  *
86  * Returns          SMP_STARTED if pairing started, otherwise the reason for the
87  *                  failure.
88  *
89  ******************************************************************************/
90 extern tSMP_STATUS SMP_BR_PairWith(const RawAddress& bd_addr);
91 
92 /*******************************************************************************
93  *
94  * Function         SMP_PairCancel
95  *
96  * Description      This function is called to cancel a SMP pairing.
97  *
98  * Returns          true - pairing cancelled
99  *
100  ******************************************************************************/
101 extern bool SMP_PairCancel(const RawAddress& bd_addr);
102 
103 /*******************************************************************************
104  *
105  * Function         SMP_SecurityGrant
106  *
107  * Description      This function is called to grant security process.
108  *
109  * Parameters       bd_addr - peer device bd address.
110  *                  res     - result of the operation SMP_SUCCESS if success.
111  *                            Otherwise, SMP_REPEATED_ATTEMPTS is too many
112  *                            attempts.
113  *
114  * Returns          None
115  *
116  ******************************************************************************/
117 extern void SMP_SecurityGrant(const RawAddress& bd_addr, uint8_t res);
118 
119 /*******************************************************************************
120  *
121  * Function         SMP_PasskeyReply
122  *
123  * Description      This function is called after Security Manager submitted
124  *                  Passkey request to the application.
125  *
126  * Parameters:      bd_addr  - Address of the device for which PIN was requested
127  *                  res      - result of the operation SMP_SUCCESS if success
128  *                  passkey  - numeric value in the range of
129  *                             BTM_MIN_PASSKEY_VAL(0) -
130  *                             BTM_MAX_PASSKEY_VAL(999999(0xF423F)).
131  *
132  ******************************************************************************/
133 extern void SMP_PasskeyReply(const RawAddress& bd_addr, uint8_t res,
134                              uint32_t passkey);
135 
136 /*******************************************************************************
137  *
138  * Function         SMP_ConfirmReply
139  *
140  * Description      This function is called after Security Manager submitted
141  *                  numeric comparison request to the application.
142  *
143  * Parameters:      bd_addr      - Address of the device with which numeric
144  *                                 comparison was requested
145  *                  res          - comparison result SMP_SUCCESS if success
146  *
147  ******************************************************************************/
148 extern void SMP_ConfirmReply(const RawAddress& bd_addr, uint8_t res);
149 
150 /*******************************************************************************
151  *
152  * Function         SMP_OobDataReply
153  *
154  * Description      This function is called to provide the OOB data for
155  *                  SMP in response to SMP_OOB_REQ_EVT
156  *
157  * Parameters:      bd_addr     - Address of the peer device
158  *                  res         - result of the operation SMP_SUCCESS if success
159  *                  p_data      - SM Randomizer  C.
160  *
161  ******************************************************************************/
162 extern void SMP_OobDataReply(const RawAddress& bd_addr, tSMP_STATUS res,
163                              uint8_t len, uint8_t* p_data);
164 
165 /*******************************************************************************
166  *
167  * Function         SMP_SecureConnectionOobDataReply
168  *
169  * Description      This function is called to provide the SC OOB data for
170  *                  SMP in response to SMP_SC_OOB_REQ_EVT
171  *
172  * Parameters:      p_data      - pointer to the data
173  *
174  ******************************************************************************/
175 extern void SMP_SecureConnectionOobDataReply(uint8_t* p_data);
176 
177 /*******************************************************************************
178  *
179  * Function         SMP_Encrypt
180  *
181  * Description      Encrypt the data with the specified key.
182  *
183  * Parameters:      key                 - Pointer to key key[0] conatins the MSB
184  *                  key_len             - key length
185  *                  plain_text          - Pointer to data to be encrypted
186  *                                        plain_text[0] conatins the MSB
187  *                  pt_len              - plain text length
188  *                  p_out               - pointer to the encrypted outputs
189  *
190  *  Returns         Boolean - true: encryption is successful
191  ******************************************************************************/
192 extern bool SMP_Encrypt(uint8_t* key, uint8_t key_len, uint8_t* plain_text,
193                         uint8_t pt_len, tSMP_ENC* p_out);
194 
195 /*******************************************************************************
196  *
197  * Function         SMP_KeypressNotification
198  *
199  * Description      Notify SM about Keypress Notification.
200  *
201  * Parameters:      bd_addr      - Address of the device to send keypress
202  *                                 notification to
203  *                  value        - keypress notification parameter value
204  *
205  ******************************************************************************/
206 extern void SMP_KeypressNotification(const RawAddress& bd_addr, uint8_t value);
207 
208 /*******************************************************************************
209  *
210  * Function         SMP_CreateLocalSecureConnectionsOobData
211  *
212  * Description      This function is called to start creation of local SC OOB
213  *                  data set (tSMP_LOC_OOB_DATA).
214  *
215  * Parameters:      bd_addr      - Address of the device to send OOB data block
216  *                                 to.
217  *
218  *  Returns         Boolean - true: creation of local SC OOB data set started.
219  ******************************************************************************/
220 extern bool SMP_CreateLocalSecureConnectionsOobData(
221     tBLE_BD_ADDR* addr_to_send_to);
222 
223 // Called when LTK request is received from controller.
224 extern bool smp_proc_ltk_request(const RawAddress& bda);
225 
226 // Called when link is encrypted and notified to slave device.
227 // Proceed to send LTK, DIV and ER to master if bonding the devices.
228 extern void smp_link_encrypted(const RawAddress& bda, uint8_t encr_enable);
229 
230 //
231 // The AES-CMAC Generation Function with tlen implemented.
232 // |key| - CMAC key in little endian order, expect SRK when used by SMP.
233 // |input| - text to be signed in little endian byte order.
234 // |length| - length of the input in byte.
235 // |tlen| - lenth of mac desired
236 // |p_signature| - data pointer to where signed data to be stored, tlen long.
237 // Returns false if out of resources, true in other cases.
238 //
239 bool aes_cipher_msg_auth_code(BT_OCTET16 key, uint8_t* input, uint16_t length,
240                               uint16_t tlen, uint8_t* p_signature);
241 
242 #endif /* SMP_API_H */
243