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