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