• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef SMP_API_TYPES_H
20 #define SMP_API_TYPES_H
21 
22 #include "bt_target.h"
23 
24 #define SMP_PIN_CODE_LEN_MAX PIN_CODE_LEN
25 #define SMP_PIN_CODE_LEN_MIN 6
26 
27 /* SMP command code */
28 #define SMP_OPCODE_PAIRING_REQ 0x01
29 #define SMP_OPCODE_PAIRING_RSP 0x02
30 #define SMP_OPCODE_CONFIRM 0x03
31 #define SMP_OPCODE_RAND 0x04
32 #define SMP_OPCODE_PAIRING_FAILED 0x05
33 #define SMP_OPCODE_ENCRYPT_INFO 0x06
34 #define SMP_OPCODE_MASTER_ID 0x07
35 #define SMP_OPCODE_IDENTITY_INFO 0x08
36 #define SMP_OPCODE_ID_ADDR 0x09
37 #define SMP_OPCODE_SIGN_INFO 0x0A
38 #define SMP_OPCODE_SEC_REQ 0x0B
39 #define SMP_OPCODE_PAIR_PUBLIC_KEY 0x0C
40 #define SMP_OPCODE_PAIR_DHKEY_CHECK 0x0D
41 #define SMP_OPCODE_PAIR_KEYPR_NOTIF 0x0E
42 #define SMP_OPCODE_MAX SMP_OPCODE_PAIR_KEYPR_NOTIF
43 #define SMP_OPCODE_MIN SMP_OPCODE_PAIRING_REQ
44 #define SMP_OPCODE_PAIR_COMMITM 0x0F
45 
46 /* SMP event type */
47 #define SMP_IO_CAP_REQ_EVT 1     /* IO capability request event */
48 #define SMP_SEC_REQUEST_EVT 2    /* SMP pairing request */
49 #define SMP_PASSKEY_NOTIF_EVT 3  /* passkey notification event */
50 #define SMP_PASSKEY_REQ_EVT 4    /* passkey request event */
51 #define SMP_OOB_REQ_EVT 5        /* OOB request event */
52 #define SMP_NC_REQ_EVT 6         /* Numeric Comparison request event */
53 #define SMP_COMPLT_EVT 7         /* SMP complete event */
54 #define SMP_PEER_KEYPR_NOT_EVT 8 /* Peer keypress notification */
55 
56 /* SC OOB request event (both local and peer OOB data can be expected in
57  * response) */
58 #define SMP_SC_OOB_REQ_EVT 9
59 /* SC OOB local data set is created (as result of SMP_CrLocScOobData(...)) */
60 #define SMP_SC_LOC_OOB_DATA_UP_EVT 10
61 #define SMP_BR_KEYS_REQ_EVT 12 /* SMP over BR keys request event */
62 #define SMP_CONSENT_REQ_EVT 14 /* Consent request event */
63 typedef uint8_t tSMP_EVT;
64 
65 /* pairing failure reason code */
66 #define SMP_PASSKEY_ENTRY_FAIL 0x01
67 #define SMP_OOB_FAIL 0x02
68 #define SMP_PAIR_AUTH_FAIL 0x03
69 #define SMP_CONFIRM_VALUE_ERR 0x04
70 #define SMP_PAIR_NOT_SUPPORT 0x05
71 #define SMP_ENC_KEY_SIZE 0x06
72 #define SMP_INVALID_CMD 0x07
73 #define SMP_PAIR_FAIL_UNKNOWN 0x08
74 #define SMP_REPEATED_ATTEMPTS 0x09
75 #define SMP_INVALID_PARAMETERS 0x0A
76 #define SMP_DHKEY_CHK_FAIL 0x0B
77 #define SMP_NUMERIC_COMPAR_FAIL 0x0C
78 #define SMP_BR_PARING_IN_PROGR 0x0D
79 #define SMP_XTRANS_DERIVE_NOT_ALLOW 0x0E
80 #define SMP_MAX_FAIL_RSN_PER_SPEC SMP_XTRANS_DERIVE_NOT_ALLOW
81 
82 /* self defined error code */
83 #define SMP_PAIR_INTERNAL_ERR (SMP_MAX_FAIL_RSN_PER_SPEC + 0x01) /* 0x0F */
84 
85 /* Unknown IO capability, unable to decide association model */
86 #define SMP_UNKNOWN_IO_CAP (SMP_MAX_FAIL_RSN_PER_SPEC + 0x02) /* 0x10 */
87 
88 #define SMP_INIT_FAIL (SMP_MAX_FAIL_RSN_PER_SPEC + 0x03)     /* 0x11 */
89 #define SMP_CONFIRM_FAIL (SMP_MAX_FAIL_RSN_PER_SPEC + 0x04)  /* 0x12 */
90 #define SMP_BUSY (SMP_MAX_FAIL_RSN_PER_SPEC + 0x05)          /* 0x13 */
91 #define SMP_ENC_FAIL (SMP_MAX_FAIL_RSN_PER_SPEC + 0x06)      /* 0x14 */
92 #define SMP_STARTED (SMP_MAX_FAIL_RSN_PER_SPEC + 0x07)       /* 0x15 */
93 #define SMP_RSP_TIMEOUT (SMP_MAX_FAIL_RSN_PER_SPEC + 0x08)   /* 0x16 */
94 #define SMP_DIV_NOT_AVAIL (SMP_MAX_FAIL_RSN_PER_SPEC + 0x09) /* 0x17 */
95 
96 /* Unspecified failure reason */
97 #define SMP_FAIL (SMP_MAX_FAIL_RSN_PER_SPEC + 0x0A) /* 0x18 */
98 
99 #define SMP_CONN_TOUT (SMP_MAX_FAIL_RSN_PER_SPEC + 0x0B) /* 0x19 */
100 #define SMP_SUCCESS 0
101 
102 typedef uint8_t tSMP_STATUS;
103 
104 /* Device IO capability */
105 #define SMP_IO_CAP_OUT BTM_IO_CAP_OUT       /* DisplayOnly */
106 #define SMP_IO_CAP_IO BTM_IO_CAP_IO         /* DisplayYesNo */
107 #define SMP_IO_CAP_IN BTM_IO_CAP_IN         /* KeyboardOnly */
108 #define SMP_IO_CAP_NONE BTM_IO_CAP_NONE     /* NoInputNoOutput */
109 #define SMP_IO_CAP_KBDISP BTM_IO_CAP_KBDISP /* Keyboard Display */
110 #define SMP_IO_CAP_MAX BTM_IO_CAP_MAX
111 typedef uint8_t tSMP_IO_CAP;
112 
113 /* OOB data present or not */
114 enum { SMP_OOB_NONE, SMP_OOB_PRESENT, SMP_OOB_UNKNOWN };
115 typedef uint8_t tSMP_OOB_FLAG;
116 
117 /* type of OOB data required from application */
118 enum { SMP_OOB_INVALID_TYPE, SMP_OOB_PEER, SMP_OOB_LOCAL, SMP_OOB_BOTH };
119 typedef uint8_t tSMP_OOB_DATA_TYPE;
120 
121 #define SMP_AUTH_NO_BOND 0x00
122 #define SMP_AUTH_BOND 0x01
123 
124 /* SMP Authentication requirement */
125 #define SMP_AUTH_YN_BIT (1 << 2)
126 #define SMP_SC_SUPPORT_BIT (1 << 3)
127 #define SMP_KP_SUPPORT_BIT (1 << 4)
128 #define SMP_H7_SUPPORT_BIT (1 << 5)
129 
130 #define SMP_AUTH_MASK                                                          \
131   (SMP_AUTH_BOND | SMP_AUTH_YN_BIT | SMP_SC_SUPPORT_BIT | SMP_KP_SUPPORT_BIT | \
132    SMP_H7_SUPPORT_BIT)
133 
134 /* no MITM, No Bonding, encryption only */
135 #define SMP_AUTH_NB_ENC_ONLY 0x00  //(SMP_AUTH_MASK | BTM_AUTH_SP_NO)
136 
137 /* MITM, No Bonding, Use IO Capability to determine authentication procedure */
138 #define SMP_AUTH_NB_IOCAP (SMP_AUTH_NO_BOND | SMP_AUTH_YN_BIT)
139 
140 /* No MITM, General Bonding, Encryption only */
141 #define SMP_AUTH_GB_ENC_ONLY SMP_AUTH_BOND
142 
143 /* MITM, General Bonding, Use IO Capability to determine authentication
144  * procedure */
145 #define SMP_AUTH_GB_IOCAP (SMP_AUTH_BOND | SMP_AUTH_YN_BIT)
146 
147 /* Secure Connections, no MITM, no Bonding */
148 #define SMP_AUTH_SC_ENC_ONLY (SMP_H7_SUPPORT_BIT | SMP_SC_SUPPORT_BIT)
149 
150 /* Secure Connections, no MITM, Bonding */
151 #define SMP_AUTH_SC_GB (SMP_H7_SUPPORT_BIT | SMP_SC_SUPPORT_BIT | SMP_AUTH_BOND)
152 
153 /* Secure Connections, MITM, no Bonding */
154 #define SMP_AUTH_SC_MITM_NB \
155   (SMP_H7_SUPPORT_BIT | SMP_SC_SUPPORT_BIT | SMP_AUTH_YN_BIT | SMP_AUTH_NO_BOND)
156 
157 /* Secure Connections, MITM, Bonding */
158 #define SMP_AUTH_SC_MITM_GB \
159   (SMP_H7_SUPPORT_BIT | SMP_SC_SUPPORT_BIT | SMP_AUTH_YN_BIT | SMP_AUTH_BOND)
160 
161 /* All AuthReq RFU bits are set to 1 - NOTE: reserved bit in Bonding_Flags is
162  * not set */
163 #define SMP_AUTH_ALL_RFU_SET 0xF8
164 
165 typedef uint8_t tSMP_AUTH_REQ;
166 
167 #define SMP_SEC_NONE 0
168 #define SMP_SEC_UNAUTHENTICATE (1 << 0)
169 #define SMP_SEC_AUTHENTICATED (1 << 2)
170 typedef uint8_t tSMP_SEC_LEVEL;
171 
172 /* Maximum Encryption Key Size range */
173 #define SMP_ENCR_KEY_SIZE_MIN 7
174 #define SMP_ENCR_KEY_SIZE_MAX 16
175 
176 /* SMP key types */
177 #define SMP_SEC_KEY_TYPE_ENC (1 << 0)  /* encryption key */
178 #define SMP_SEC_KEY_TYPE_ID (1 << 1)   /* identity key */
179 #define SMP_SEC_KEY_TYPE_CSRK (1 << 2) /* slave CSRK */
180 #define SMP_SEC_KEY_TYPE_LK (1 << 3)   /* BR/EDR link key */
181 typedef uint8_t tSMP_KEYS;
182 
183 #define SMP_BR_SEC_DEFAULT_KEY \
184   (SMP_SEC_KEY_TYPE_ENC | SMP_SEC_KEY_TYPE_ID | SMP_SEC_KEY_TYPE_CSRK)
185 
186 /* default security key distribution value */
187 #define SMP_SEC_DEFAULT_KEY                                             \
188   (SMP_SEC_KEY_TYPE_ENC | SMP_SEC_KEY_TYPE_ID | SMP_SEC_KEY_TYPE_CSRK | \
189    SMP_SEC_KEY_TYPE_LK)
190 
191 #define SMP_SC_KEY_STARTED 0      /* passkey entry started */
192 #define SMP_SC_KEY_ENTERED 1      /* passkey digit entered */
193 #define SMP_SC_KEY_ERASED 2       /* passkey digit erased */
194 #define SMP_SC_KEY_CLEARED 3      /* passkey cleared */
195 #define SMP_SC_KEY_COMPLT 4       /* passkey entry completed */
196 #define SMP_SC_KEY_OUT_OF_RANGE 5 /* out of range */
197 typedef uint8_t tSMP_SC_KEY_TYPE;
198 
199 /* data type for BTM_SP_IO_REQ_EVT */
200 typedef struct {
201   tSMP_IO_CAP io_cap;     /* local IO capabilities */
202   tSMP_OOB_FLAG oob_data; /* OOB data present (locally) for the peer device */
203   tSMP_AUTH_REQ auth_req; /* Authentication required (for local device) */
204   uint8_t max_key_size;   /* max encryption key size */
205   tSMP_KEYS init_keys;    /* initiator keys to be distributed */
206   tSMP_KEYS resp_keys;    /* responder keys */
207 } tSMP_IO_REQ;
208 
209 typedef struct {
210   tSMP_STATUS reason;
211   tSMP_SEC_LEVEL sec_level;
212   bool is_pair_cancel;
213   bool smp_over_br;
214 } tSMP_CMPL;
215 
216 typedef struct {
217   BT_OCTET32 x;
218   BT_OCTET32 y;
219 } tSMP_PUBLIC_KEY;
220 
221 /* the data associated with the info sent to the peer via OOB interface */
222 typedef struct {
223   bool present;
224   Octet16 randomizer;
225   Octet16 commitment;
226 
227   tBLE_BD_ADDR addr_sent_to;
228   BT_OCTET32 private_key_used; /* is used to calculate: */
229   /* publ_key_used = P-256(private_key_used, curve_p256.G) - send it to the */
230   /* other side */
231   /* dhkey = P-256(private_key_used, publ key rcvd from the other side) */
232   tSMP_PUBLIC_KEY publ_key_used; /* P-256(private_key_used, curve_p256.G) */
233 } tSMP_LOC_OOB_DATA;
234 
235 /* the data associated with the info received from the peer via OOB interface */
236 typedef struct {
237   bool present;
238   Octet16 randomizer;
239   Octet16 commitment;
240   tBLE_BD_ADDR addr_rcvd_from;
241 } tSMP_PEER_OOB_DATA;
242 
243 typedef struct {
244   tSMP_LOC_OOB_DATA loc_oob_data;
245   tSMP_PEER_OOB_DATA peer_oob_data;
246 } tSMP_SC_OOB_DATA;
247 
248 typedef union {
249   uint32_t passkey;
250   tSMP_IO_REQ io_req; /* IO request */
251   tSMP_CMPL cmplt;
252   tSMP_OOB_DATA_TYPE req_oob_type;
253   tSMP_LOC_OOB_DATA loc_oob_data;
254 } tSMP_EVT_DATA;
255 
256 /* AES Encryption output */
257 typedef struct {
258   uint8_t status;
259   uint8_t param_len;
260   uint16_t opcode;
261   uint8_t param_buf[OCTET16_LEN];
262 } tSMP_ENC;
263 
264 /* Security Manager events - Called by the stack when Security Manager related
265  * events occur.*/
266 typedef uint8_t(tSMP_CALLBACK)(tSMP_EVT event, const RawAddress& bd_addr,
267                                tSMP_EVT_DATA* p_data);
268 
269 /* callback function for CMAC algorithm
270 */
271 typedef void(tCMAC_CMPL_CBACK)(uint8_t* p_mac, uint16_t tlen,
272                                uint32_t sign_counter);
273 
274 #endif  // SMP_API_TYPES_H
275