• 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 
29 #define SMP_PIN_CODE_LEN_MAX    PIN_CODE_LEN
30 #define SMP_PIN_CODE_LEN_MIN    6
31 
32 /* SMP event type */
33 #define SMP_IO_CAP_REQ_EVT      1       /* IO capability request event */
34 #define SMP_SEC_REQUEST_EVT     2       /* SMP pairing request */
35 #define SMP_PASSKEY_NOTIF_EVT   3       /* passkey notification event */
36 #define SMP_PASSKEY_REQ_EVT     4       /* passkey request event */
37 #define SMP_OOB_REQ_EVT         5       /* OOB request event */
38 #define SMP_COMPLT_EVT          6       /* SMP complete event */
39 typedef UINT8   tSMP_EVT;
40 
41 
42 /* pairing failure reason code */
43 #define SMP_PASSKEY_ENTRY_FAIL      0x01
44 #define SMP_OOB_FAIL                0x02
45 #define SMP_PAIR_AUTH_FAIL          0x03
46 #define SMP_CONFIRM_VALUE_ERR       0x04
47 #define SMP_PAIR_NOT_SUPPORT        0x05
48 #define SMP_ENC_KEY_SIZE            0x06
49 #define SMP_INVALID_CMD             0x07
50 #define SMP_PAIR_FAIL_UNKNOWN       0x08
51 #define SMP_REPEATED_ATTEMPTS       0x09
52 #define SMP_PAIR_FAILURE_MAX        SMP_REPEATED_ATTEMPTS
53 /* self defined error code */
54 #define SMP_PAIR_INTERNAL_ERR       0x0A
55 #define SMP_UNKNOWN_IO_CAP          0x0B    /* unknown IO capability, unable to decide associatino model */
56 #define SMP_INIT_FAIL               0x0C
57 #define SMP_CONFIRM_FAIL            0x0D
58 #define SMP_BUSY                    0x0E
59 #define SMP_ENC_FAIL                0x0F
60 #define SMP_STARTED                 0x10
61 #define SMP_RSP_TIMEOUT             0x11
62 #define SMP_DIV_NOT_AVAIL           0x12
63 #define SMP_FAIL                    0x13 /* unspecified failed reason */
64 #define SMP_SUCCESS                 0
65 
66 typedef UINT8 tSMP_STATUS;
67 
68 
69 /* Device IO capability */
70 #define SMP_IO_CAP_OUT      BTM_IO_CAP_OUT   /* DisplayOnly */
71 #define SMP_IO_CAP_IO       BTM_IO_CAP_IO   /* DisplayYesNo */
72 #define SMP_IO_CAP_IN       BTM_IO_CAP_IN   /* KeyboardOnly */
73 #define SMP_IO_CAP_NONE     BTM_IO_CAP_NONE   /* NoInputNoOutput */
74 #define SMP_IO_CAP_KBDISP   BTM_IO_CAP_KBDISP   /* Keyboard Display */
75 #define SMP_IO_CAP_MAX      BTM_IO_CAP_MAX
76 typedef UINT8  tSMP_IO_CAP;
77 
78 #ifndef SMP_DEFAULT_IO_CAPS
79     #define SMP_DEFAULT_IO_CAPS     SMP_IO_CAP_KBDISP
80 #endif
81 
82 /* OOB data present or not */
83 enum
84 {
85     SMP_OOB_NONE,
86     SMP_OOB_PRESENT,
87     SMP_OOB_UNKNOWN
88 };
89 typedef UINT8  tSMP_OOB_FLAG;
90 
91 #define SMP_AUTH_NO_BOND        0x00
92 #define SMP_AUTH_GEN_BOND       0x01 //todo sdh change GEN_BOND to BOND
93 
94 /* SMP Authentication requirement */
95 #define SMP_AUTH_YN_BIT           (1 << 2)
96 #define SMP_AUTH_MASK           (SMP_AUTH_GEN_BOND|SMP_AUTH_YN_BIT)
97 
98 
99 #define SMP_AUTH_BOND           SMP_AUTH_GEN_BOND
100 
101 #define SMP_AUTH_NB_ENC_ONLY    0x00 //(SMP_AUTH_MASK | BTM_AUTH_SP_NO)   /* no MITM, No Bonding, Encryptino only */
102 #define SMP_AUTH_NB_IOCAP       (SMP_AUTH_NO_BOND | SMP_AUTH_YN_BIT)   /* MITM, No Bonding, Use IO Capability
103                                         to detrermine authenticaion procedure */
104 #define SMP_AUTH_GB_ENC_ONLY    (SMP_AUTH_GEN_BOND )   /* no MITM, General Bonding, Encryptino only */
105 #define SMP_AUTH_GB_IOCAP       (SMP_AUTH_GEN_BOND | SMP_AUTH_YN_BIT)  /* MITM, General Bonding, Use IO Capability
106                                         to detrermine authenticaion procedure   */
107 typedef UINT8 tSMP_AUTH_REQ;
108 
109 #define SMP_SEC_NONE                 0
110 #define SMP_SEC_UNAUTHENTICATE      (1 << 0)
111 #define SMP_SEC_AUTHENTICATED       (1 << 2)
112 typedef UINT8 tSMP_SEC_LEVEL;
113 
114 /* SMP key types */
115 #define SMP_SEC_KEY_TYPE_ENC                (1 << 0)    /* encryption key */
116 #define SMP_SEC_KEY_TYPE_ID                 (1 << 1)    /* identity key */
117 #define SMP_SEC_KEY_TYPE_CSRK               (1 << 2)    /* slave CSRK */
118 typedef UINT8 tSMP_KEYS;
119 
120 /* default security key distribution value */
121 #define SMP_SEC_DEFAULT_KEY                  (SMP_SEC_KEY_TYPE_ENC | SMP_SEC_KEY_TYPE_ID | SMP_SEC_KEY_TYPE_CSRK)
122 
123 /* data type for BTM_SP_IO_REQ_EVT */
124 typedef struct
125 {
126     tSMP_IO_CAP     io_cap;         /* local IO capabilities */
127     tSMP_OOB_FLAG   oob_data;       /* OOB data present (locally) for the peer device */
128     tSMP_AUTH_REQ   auth_req;       /* Authentication required (for local device) */
129     UINT8           max_key_size;   /* max encryption key size */
130     tSMP_KEYS       init_keys;      /* initiator keys to be distributed */
131     tSMP_KEYS       resp_keys;      /* responder keys */
132 } tSMP_IO_REQ;
133 
134 typedef struct
135 {
136     UINT8       reason;
137     UINT8       sec_level;
138     BOOLEAN     is_pair_cancel;
139 } tSMP_CMPL;
140 
141 typedef union
142 {
143     UINT32          passkey;
144     tSMP_IO_REQ     io_req;     /* IO request */
145     tSMP_CMPL       cmplt;
146 
147 }tSMP_EVT_DATA;
148 
149 
150 /* AES Encryption output */
151 typedef struct
152 {
153     UINT8   status;
154     UINT8   param_len;
155     UINT16  opcode;
156     UINT8   param_buf[BT_OCTET16_LEN];
157 } tSMP_ENC;
158 
159 /* Simple Pairing Events.  Called by the stack when Simple Pairing related
160 ** events occur.
161 */
162 typedef UINT8 (tSMP_CALLBACK) (tSMP_EVT event, BD_ADDR bd_addr, tSMP_EVT_DATA *p_data);
163 
164 /* callback function for CMAC algorithm
165 */
166 typedef void (tCMAC_CMPL_CBACK)(UINT8 *p_mac, UINT16 tlen, UINT32 sign_counter);
167 
168 /*****************************************************************************
169 **  External Function Declarations
170 *****************************************************************************/
171 #ifdef __cplusplus
172 extern "C"
173 {
174 #endif
175 /* API of SMP */
176 
177 /*******************************************************************************
178 **
179 ** Function         SMP_Init
180 **
181 ** Description      This function initializes the SMP unit.
182 **
183 ** Returns          void
184 **
185 *******************************************************************************/
186     SMP_API extern void SMP_Init(void);
187 
188 /*******************************************************************************
189 **
190 ** Function         SMP_SetTraceLevel
191 **
192 ** Description      This function sets the trace level for SMP.  If called with
193 **                  a value of 0xFF, it simply returns the current trace level.
194 **
195 ** Returns          The new or current trace level
196 **
197 *******************************************************************************/
198     SMP_API extern UINT8 SMP_SetTraceLevel (UINT8 new_level);
199 
200 /*******************************************************************************
201 **
202 ** Function         SMP_Register
203 **
204 ** Description      This function register for the SMP service callback.
205 **
206 ** Returns          void
207 **
208 *******************************************************************************/
209     SMP_API extern BOOLEAN SMP_Register (tSMP_CALLBACK *p_cback);
210 
211 /*******************************************************************************
212 **
213 ** Function         SMP_Pair
214 **
215 ** Description      This function is called to start a SMP pairing.
216 **
217 ** Returns          SMP_STARTED if bond started, else otherwise exception.
218 **
219 *******************************************************************************/
220     SMP_API extern tSMP_STATUS SMP_Pair (BD_ADDR bd_addr);
221 /*******************************************************************************
222 **
223 ** Function         SMP_PairCancel
224 **
225 ** Description      This function is called to cancel a SMP pairing.
226 **
227 ** Returns          TRUE - pairing cancelled
228 **
229 *******************************************************************************/
230     SMP_API extern  BOOLEAN SMP_PairCancel (BD_ADDR bd_addr);
231 
232 /*******************************************************************************
233 **
234 ** Function         SMP_SecurityGrant
235 **
236 ** Description      This function is called to grant security process.
237 **
238 ** Parameters       bd_addr - peer device bd address.
239 **                  res     - result of the operation SMP_SUCCESS if success.
240 **                            Otherwise, SMP_REPEATED_ATTEMPTS is too many attempts.
241 **
242 ** Returns          None
243 **
244 *******************************************************************************/
245     SMP_API extern void SMP_SecurityGrant(BD_ADDR bd_addr, UINT8 res);
246 
247 /*******************************************************************************
248 **
249 ** Function         SMP_PasskeyReply
250 **
251 ** Description      This function is called after Security Manager submitted
252 **                  Passkey request to the application.
253 **
254 ** Parameters:      bd_addr      - Address of the device for which PIN was requested
255 **                  res          - result of the operation BTM_SUCCESS if success
256 **                  passkey      - numeric value in the range of
257 **                  BTM_MIN_PASSKEY_VAL(0) - BTM_MAX_PASSKEY_VAL(999999(0xF423F)).
258 **
259 *******************************************************************************/
260     SMP_API extern void SMP_PasskeyReply (BD_ADDR bd_addr, UINT8 res, UINT32 passkey);
261 
262 /*******************************************************************************
263 **
264 ** Function         SMP_OobDataReply
265 **
266 ** Description      This function is called to provide the OOB data for
267 **                  Simple Pairing in response to BTM_SP_RMT_OOB_EVT
268 **
269 ** Parameters:      bd_addr     - Address of the peer device
270 **                  res         - result of the operation SMP_SUCCESS if success
271 **                  p_data      - simple pairing Randomizer  C.
272 **
273 *******************************************************************************/
274     SMP_API extern void SMP_OobDataReply(BD_ADDR bd_addr, tSMP_STATUS res, UINT8 len,
275                                          UINT8 *p_data);
276 
277 /*******************************************************************************
278 **
279 ** Function         SMP_Encrypt
280 **
281 ** Description      This function is called to encrypt the data with the specified
282 **                  key
283 **
284 ** Parameters:      key                 - Pointer to key key[0] conatins the MSB
285 **                  key_len             - key length
286 **                  plain_text          - Pointer to data to be encrypted
287 **                                        plain_text[0] conatins the MSB
288 **                  pt_len              - plain text length
289 **                  p_out               - pointer to the encrypted outputs
290 **
291 **  Returns         Boolean - TRUE: encryption is successful
292 *******************************************************************************/
293     SMP_API extern BOOLEAN SMP_Encrypt (UINT8 *key, UINT8 key_len,
294                                         UINT8 *plain_text, UINT8 pt_len,
295                                         tSMP_ENC *p_out);
296 
297 #ifdef __cplusplus
298 }
299 #endif
300 #endif /* SMP_API_H */
301