Home | History | Annotate | Download | only in include
      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 #ifndef SMP_DEFAULT_IO_CAPS
    113 #define SMP_DEFAULT_IO_CAPS SMP_IO_CAP_KBDISP
    114 #endif
    115 
    116 /* OOB data present or not */
    117 enum { SMP_OOB_NONE, SMP_OOB_PRESENT, SMP_OOB_UNKNOWN };
    118 typedef uint8_t tSMP_OOB_FLAG;
    119 
    120 /* type of OOB data required from application */
    121 enum { SMP_OOB_INVALID_TYPE, SMP_OOB_PEER, SMP_OOB_LOCAL, SMP_OOB_BOTH };
    122 typedef uint8_t tSMP_OOB_DATA_TYPE;
    123 
    124 #define SMP_AUTH_NO_BOND 0x00
    125 #define SMP_AUTH_BOND 0x01
    126 
    127 /* SMP Authentication requirement */
    128 #define SMP_AUTH_YN_BIT (1 << 2)
    129 #define SMP_SC_SUPPORT_BIT (1 << 3)
    130 #define SMP_KP_SUPPORT_BIT (1 << 4)
    131 #define SMP_H7_SUPPORT_BIT (1 << 5)
    132 
    133 #define SMP_AUTH_MASK                                                          \
    134   (SMP_AUTH_BOND | SMP_AUTH_YN_BIT | SMP_SC_SUPPORT_BIT | SMP_KP_SUPPORT_BIT | \
    135    SMP_H7_SUPPORT_BIT)
    136 
    137 /* no MITM, No Bonding, encryption only */
    138 #define SMP_AUTH_NB_ENC_ONLY 0x00  //(SMP_AUTH_MASK | BTM_AUTH_SP_NO)
    139 
    140 /* MITM, No Bonding, Use IO Capability to determine authentication procedure */
    141 #define SMP_AUTH_NB_IOCAP (SMP_AUTH_NO_BOND | SMP_AUTH_YN_BIT)
    142 
    143 /* No MITM, General Bonding, Encryption only */
    144 #define SMP_AUTH_GB_ENC_ONLY SMP_AUTH_BOND
    145 
    146 /* MITM, General Bonding, Use IO Capability to determine authentication
    147  * procedure */
    148 #define SMP_AUTH_GB_IOCAP (SMP_AUTH_BOND | SMP_AUTH_YN_BIT)
    149 
    150 /* Secure Connections, no MITM, no Bonding */
    151 #define SMP_AUTH_SC_ENC_ONLY (SMP_H7_SUPPORT_BIT | SMP_SC_SUPPORT_BIT)
    152 
    153 /* Secure Connections, no MITM, Bonding */
    154 #define SMP_AUTH_SC_GB (SMP_H7_SUPPORT_BIT | SMP_SC_SUPPORT_BIT | SMP_AUTH_BOND)
    155 
    156 /* Secure Connections, MITM, no Bonding */
    157 #define SMP_AUTH_SC_MITM_NB \
    158   (SMP_H7_SUPPORT_BIT | SMP_SC_SUPPORT_BIT | SMP_AUTH_YN_BIT | SMP_AUTH_NO_BOND)
    159 
    160 /* Secure Connections, MITM, Bonding */
    161 #define SMP_AUTH_SC_MITM_GB \
    162   (SMP_H7_SUPPORT_BIT | SMP_SC_SUPPORT_BIT | SMP_AUTH_YN_BIT | SMP_AUTH_BOND)
    163 
    164 /* All AuthReq RFU bits are set to 1 - NOTE: reserved bit in Bonding_Flags is
    165  * not set */
    166 #define SMP_AUTH_ALL_RFU_SET 0xF8
    167 
    168 typedef uint8_t tSMP_AUTH_REQ;
    169 
    170 #define SMP_SEC_NONE 0
    171 #define SMP_SEC_UNAUTHENTICATE (1 << 0)
    172 #define SMP_SEC_AUTHENTICATED (1 << 2)
    173 typedef uint8_t tSMP_SEC_LEVEL;
    174 
    175 /* Maximum Encryption Key Size range */
    176 #define SMP_ENCR_KEY_SIZE_MIN 7
    177 #define SMP_ENCR_KEY_SIZE_MAX 16
    178 
    179 /* SMP key types */
    180 #define SMP_SEC_KEY_TYPE_ENC (1 << 0)  /* encryption key */
    181 #define SMP_SEC_KEY_TYPE_ID (1 << 1)   /* identity key */
    182 #define SMP_SEC_KEY_TYPE_CSRK (1 << 2) /* slave CSRK */
    183 #define SMP_SEC_KEY_TYPE_LK (1 << 3)   /* BR/EDR link key */
    184 typedef uint8_t tSMP_KEYS;
    185 
    186 #define SMP_BR_SEC_DEFAULT_KEY \
    187   (SMP_SEC_KEY_TYPE_ENC | SMP_SEC_KEY_TYPE_ID | SMP_SEC_KEY_TYPE_CSRK)
    188 
    189 /* default security key distribution value */
    190 #define SMP_SEC_DEFAULT_KEY                                             \
    191   (SMP_SEC_KEY_TYPE_ENC | SMP_SEC_KEY_TYPE_ID | SMP_SEC_KEY_TYPE_CSRK | \
    192    SMP_SEC_KEY_TYPE_LK)
    193 
    194 #define SMP_SC_KEY_STARTED 0      /* passkey entry started */
    195 #define SMP_SC_KEY_ENTERED 1      /* passkey digit entered */
    196 #define SMP_SC_KEY_ERASED 2       /* passkey digit erased */
    197 #define SMP_SC_KEY_CLEARED 3      /* passkey cleared */
    198 #define SMP_SC_KEY_COMPLT 4       /* passkey entry completed */
    199 #define SMP_SC_KEY_OUT_OF_RANGE 5 /* out of range */
    200 typedef uint8_t tSMP_SC_KEY_TYPE;
    201 
    202 /* data type for BTM_SP_IO_REQ_EVT */
    203 typedef struct {
    204   tSMP_IO_CAP io_cap;     /* local IO capabilities */
    205   tSMP_OOB_FLAG oob_data; /* OOB data present (locally) for the peer device */
    206   tSMP_AUTH_REQ auth_req; /* Authentication required (for local device) */
    207   uint8_t max_key_size;   /* max encryption key size */
    208   tSMP_KEYS init_keys;    /* initiator keys to be distributed */
    209   tSMP_KEYS resp_keys;    /* responder keys */
    210 } tSMP_IO_REQ;
    211 
    212 typedef struct {
    213   tSMP_STATUS reason;
    214   tSMP_SEC_LEVEL sec_level;
    215   bool is_pair_cancel;
    216   bool smp_over_br;
    217 } tSMP_CMPL;
    218 
    219 typedef struct {
    220   BT_OCTET32 x;
    221   BT_OCTET32 y;
    222 } tSMP_PUBLIC_KEY;
    223 
    224 /* the data associated with the info sent to the peer via OOB interface */
    225 typedef struct {
    226   bool present;
    227   BT_OCTET16 randomizer;
    228   BT_OCTET16 commitment;
    229 
    230   tBLE_BD_ADDR addr_sent_to;
    231   BT_OCTET32 private_key_used; /* is used to calculate: */
    232   /* publ_key_used = P-256(private_key_used, curve_p256.G) - send it to the */
    233   /* other side */
    234   /* dhkey = P-256(private_key_used, publ key rcvd from the other side) */
    235   tSMP_PUBLIC_KEY publ_key_used; /* P-256(private_key_used, curve_p256.G) */
    236 } tSMP_LOC_OOB_DATA;
    237 
    238 /* the data associated with the info received from the peer via OOB interface */
    239 typedef struct {
    240   bool present;
    241   BT_OCTET16 randomizer;
    242   BT_OCTET16 commitment;
    243   tBLE_BD_ADDR addr_rcvd_from;
    244 } tSMP_PEER_OOB_DATA;
    245 
    246 typedef struct {
    247   tSMP_LOC_OOB_DATA loc_oob_data;
    248   tSMP_PEER_OOB_DATA peer_oob_data;
    249 } tSMP_SC_OOB_DATA;
    250 
    251 typedef union {
    252   uint32_t passkey;
    253   tSMP_IO_REQ io_req; /* IO request */
    254   tSMP_CMPL cmplt;
    255   tSMP_OOB_DATA_TYPE req_oob_type;
    256   tSMP_LOC_OOB_DATA loc_oob_data;
    257 } tSMP_EVT_DATA;
    258 
    259 /* AES Encryption output */
    260 typedef struct {
    261   uint8_t status;
    262   uint8_t param_len;
    263   uint16_t opcode;
    264   uint8_t param_buf[BT_OCTET16_LEN];
    265 } tSMP_ENC;
    266 
    267 /* Security Manager events - Called by the stack when Security Manager related
    268  * events occur.*/
    269 typedef uint8_t(tSMP_CALLBACK)(tSMP_EVT event, const RawAddress& bd_addr,
    270                                tSMP_EVT_DATA* p_data);
    271 
    272 /* callback function for CMAC algorithm
    273 */
    274 typedef void(tCMAC_CMPL_CBACK)(uint8_t* p_mac, uint16_t tlen,
    275                                uint32_t sign_counter);
    276 
    277 #endif  // SMP_API_TYPES_H
    278