Home | History | Annotate | Download | only in include
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2009-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 BTIF_STORAGE_H
     20 #define BTIF_STORAGE_H
     21 
     22 #include <hardware/bluetooth.h>
     23 
     24 #include "bt_target.h"
     25 #include "bt_types.h"
     26 
     27 /*******************************************************************************
     28 **  Constants & Macros
     29 ********************************************************************************/
     30 #define BTIF_STORAGE_FILL_PROPERTY(p_prop, t, l, p_v) \
     31          (p_prop)->type = t;(p_prop)->len = l; (p_prop)->val = (p_v);
     32 
     33 /*******************************************************************************
     34 **  Functions
     35 ********************************************************************************/
     36 
     37 /*******************************************************************************
     38 **
     39 ** Function         btif_storage_get_adapter_property
     40 **
     41 ** Description      BTIF storage API - Fetches the adapter property->type
     42 **                  from NVRAM and fills property->val.
     43 **                  Caller should provide memory for property->val and
     44 **                  set the property->val
     45 **
     46 ** Returns          BT_STATUS_SUCCESS if the fetch was successful,
     47 **                  BT_STATUS_FAIL otherwise
     48 **
     49 *******************************************************************************/
     50 bt_status_t btif_storage_get_adapter_property(bt_property_t *property);
     51 
     52 /*******************************************************************************
     53 **
     54 ** Function         btif_storage_set_adapter_property
     55 **
     56 ** Description      BTIF storage API - Stores the adapter property
     57 **                  to NVRAM
     58 **
     59 ** Returns          BT_STATUS_SUCCESS if the store was successful,
     60 **                  BT_STATUS_FAIL otherwise
     61 **
     62 *******************************************************************************/
     63 bt_status_t btif_storage_set_adapter_property(bt_property_t *property);
     64 
     65 /*******************************************************************************
     66 **
     67 ** Function         btif_storage_get_remote_device_property
     68 **
     69 ** Description      BTIF storage API - Fetches the remote device property->type
     70 **                  from NVRAM and fills property->val.
     71 **                  Caller should provide memory for property->val and
     72 **                  set the property->val
     73 **
     74 ** Returns          BT_STATUS_SUCCESS if the fetch was successful,
     75 **                  BT_STATUS_FAIL otherwise
     76 **
     77 *******************************************************************************/
     78 bt_status_t btif_storage_get_remote_device_property(bt_bdaddr_t *remote_bd_addr,
     79                                                     bt_property_t *property);
     80 
     81 /*******************************************************************************
     82 **
     83 ** Function         btif_storage_set_remote_device_property
     84 **
     85 ** Description      BTIF storage API - Stores the remote device property
     86 **                  to NVRAM
     87 **
     88 ** Returns          BT_STATUS_SUCCESS if the store was successful,
     89 **                  BT_STATUS_FAIL otherwise
     90 **
     91 *******************************************************************************/
     92 bt_status_t btif_storage_set_remote_device_property(bt_bdaddr_t *remote_bd_addr,
     93                                                     bt_property_t *property);
     94 
     95 /*******************************************************************************
     96 **
     97 ** Function         btif_storage_add_remote_device
     98 **
     99 ** Description      BTIF storage API - Adds a newly discovered device to
    100 **                  track along with the timestamp. Also, stores the various
    101 **                  properties - RSSI, BDADDR, NAME (if found in EIR)
    102 **
    103 ** Returns          BT_STATUS_SUCCESS if successful,
    104 **                  BT_STATUS_FAIL otherwise
    105 **
    106 *******************************************************************************/
    107 bt_status_t btif_storage_add_remote_device(bt_bdaddr_t *remote_bd_addr,
    108                                            uint32_t num_properties,
    109                                            bt_property_t *properties);
    110 
    111 /*******************************************************************************
    112 **
    113 ** Function         btif_storage_add_bonded_device
    114 **
    115 ** Description      BTIF storage API - Adds the newly bonded device to NVRAM
    116 **                  along with the link-key, Key type and Pin key length
    117 **
    118 ** Returns          BT_STATUS_SUCCESS if the store was successful,
    119 **                  BT_STATUS_FAIL otherwise
    120 **
    121 *******************************************************************************/
    122 bt_status_t btif_storage_add_bonded_device(bt_bdaddr_t *remote_bd_addr,
    123                                            LINK_KEY link_key,
    124                                            uint8_t key_type,
    125                                            uint8_t pin_length);
    126 
    127 /*******************************************************************************
    128 **
    129 ** Function         btif_storage_remove_bonded_device
    130 **
    131 ** Description      BTIF storage API - Deletes the bonded device from NVRAM
    132 **
    133 ** Returns          BT_STATUS_SUCCESS if the deletion was successful,
    134 **                  BT_STATUS_FAIL otherwise
    135 **
    136 *******************************************************************************/
    137 bt_status_t btif_storage_remove_bonded_device(bt_bdaddr_t *remote_bd_addr);
    138 
    139 /*******************************************************************************
    140 **
    141 ** Function         btif_storage_remove_bonded_device
    142 **
    143 ** Description      BTIF storage API - Deletes the bonded device from NVRAM
    144 **
    145 ** Returns          BT_STATUS_SUCCESS if the deletion was successful,
    146 **                  BT_STATUS_FAIL otherwise
    147 **
    148 *******************************************************************************/
    149 bt_status_t btif_storage_load_bonded_devices(void);
    150 
    151 /*******************************************************************************
    152 **
    153 ** Function         btif_storage_read_hl_apps_cb
    154 **
    155 ** Description      BTIF storage API - Read HL application control block from NVRAM
    156 **
    157 ** Returns          BT_STATUS_SUCCESS if the operation was successful,
    158 **                  BT_STATUS_FAIL otherwise
    159 **
    160 *******************************************************************************/
    161 bt_status_t btif_storage_read_hl_apps_cb(char *value, int value_size);
    162 
    163 /*******************************************************************************
    164 **
    165 ** Function         btif_storage_write_hl_apps_cb
    166 **
    167 ** Description      BTIF storage API - Write HL application control block to NVRAM
    168 **
    169 ** Returns          BT_STATUS_SUCCESS if the operation was successful,
    170 **                  BT_STATUS_FAIL otherwise
    171 **
    172 *******************************************************************************/
    173 bt_status_t btif_storage_write_hl_apps_cb(char *value, int value_size);
    174 
    175 /*******************************************************************************
    176 **
    177 ** Function         btif_storage_read_hl_apps_cb
    178 **
    179 ** Description      BTIF storage API - Read HL application configuration from NVRAM
    180 **
    181 ** Returns          BT_STATUS_SUCCESS if the operation was successful,
    182 **                  BT_STATUS_FAIL otherwise
    183 **
    184 *******************************************************************************/
    185 bt_status_t btif_storage_read_hl_app_data(UINT8 app_idx, char *value, int value_size);
    186 
    187 /*******************************************************************************
    188 **
    189 ** Function         btif_storage_write_hl_app_data
    190 **
    191 ** Description      BTIF storage API - Write HL application configuration to NVRAM
    192 **
    193 ** Returns          BT_STATUS_SUCCESS if the operation was successful,
    194 **                  BT_STATUS_FAIL otherwise
    195 **
    196 *******************************************************************************/
    197 bt_status_t btif_storage_write_hl_app_data(UINT8 app_idx, char *value, int value_size);
    198 
    199 /*******************************************************************************
    200 **
    201 ** Function         btif_storage_read_hl_mdl_data
    202 **
    203 ** Description      BTIF storage API - Read HL application MDL configuration from NVRAM
    204 **
    205 ** Returns          BT_STATUS_SUCCESS if the operation was successful,
    206 **                  BT_STATUS_FAIL otherwise
    207 **
    208 *******************************************************************************/
    209 bt_status_t btif_storage_read_hl_mdl_data(UINT8 app_idx, char *value, int value_size);
    210 
    211 /*******************************************************************************
    212 **
    213 ** Function         btif_storage_write_hl_mdl_data
    214 **
    215 ** Description      BTIF storage API - Write HL application MDL configuration from NVRAM
    216 **
    217 ** Returns          BT_STATUS_SUCCESS if the operation was successful,
    218 **                  BT_STATUS_FAIL otherwise
    219 **
    220 *******************************************************************************/
    221 bt_status_t btif_storage_write_hl_mdl_data(UINT8 app_idx, char *value, int value_size);
    222 
    223 /*******************************************************************************
    224 **
    225 ** Function         btif_storage_add_hid_device_info
    226 **
    227 ** Description      BTIF storage API - Adds the hid information of bonded hid devices-to NVRAM
    228 **
    229 ** Returns          BT_STATUS_SUCCESS if the store was successful,
    230 **                  BT_STATUS_FAIL otherwise
    231 **
    232 *******************************************************************************/
    233 
    234 bt_status_t btif_storage_add_hid_device_info(bt_bdaddr_t *remote_bd_addr,
    235                                                     UINT16 attr_mask, UINT8 sub_class,
    236                                                     UINT8 app_id, UINT16 vendor_id,
    237                                                     UINT16 product_id, UINT16 version,
    238                                                     UINT8 ctry_code, UINT16 ssr_max_latency,
    239                                                     UINT16 ssr_min_tout, UINT16 dl_len, UINT8 *dsc_list);
    240 
    241 /*******************************************************************************
    242 **
    243 ** Function         btif_storage_load_bonded_hid_info
    244 **
    245 ** Description      BTIF storage API - Loads hid info for all the bonded devices from NVRAM
    246 **                  and adds those devices  to the BTA_HH.
    247 **
    248 ** Returns          BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise
    249 **
    250 *******************************************************************************/
    251 bt_status_t btif_storage_load_bonded_hid_info(void);
    252 
    253 /*******************************************************************************
    254 **
    255 ** Function         btif_storage_remove_hid_info
    256 **
    257 ** Description      BTIF storage API - Deletes the bonded hid device info from NVRAM
    258 **
    259 ** Returns          BT_STATUS_SUCCESS if the deletion was successful,
    260 **                  BT_STATUS_FAIL otherwise
    261 **
    262 *******************************************************************************/
    263 bt_status_t btif_storage_remove_hid_info(bt_bdaddr_t *remote_bd_addr);
    264 
    265 /*******************************************************************************
    266 **
    267 ** Function         btif_storage_is_retricted_device
    268 **
    269 ** Description      BTIF storage API - checks if this device is a restricted device
    270 **
    271 ** Returns          TRUE  if the device is labled as restricted
    272 **                  FALSE otherwise
    273 **
    274 *******************************************************************************/
    275 BOOLEAN btif_storage_is_restricted_device(const bt_bdaddr_t *remote_bd_addr);
    276 
    277 #if (BLE_INCLUDED == TRUE)
    278 bt_status_t btif_storage_add_ble_bonding_key( bt_bdaddr_t *remote_bd_addr,
    279                                               char *key,
    280                                               uint8_t key_type,
    281                                               uint8_t key_length);
    282 bt_status_t btif_storage_get_ble_bonding_key(bt_bdaddr_t *remote_bd_addr,
    283                                              UINT8 key_type,
    284                                              char *key_value,
    285                                              int key_length);
    286 
    287 bt_status_t btif_storage_add_ble_local_key(char *key,
    288                                            uint8_t key_type,
    289                                            uint8_t key_length);
    290 bt_status_t btif_storage_remove_ble_bonding_keys(bt_bdaddr_t *remote_bd_addr);
    291 bt_status_t btif_storage_remove_ble_local_keys(void);
    292 bt_status_t btif_storage_get_ble_local_key(UINT8 key_type,
    293                                            char *key_value,
    294                                            int key_len);
    295 
    296 bt_status_t btif_storage_get_remote_addr_type(bt_bdaddr_t *remote_bd_addr,
    297                                               int *addr_type);
    298 
    299 bt_status_t btif_storage_set_remote_addr_type(bt_bdaddr_t *remote_bd_addr,
    300                                               UINT8 addr_type);
    301 
    302 #endif
    303 /*******************************************************************************
    304 **
    305 ** Function         btif_storage_get_remote_version
    306 **
    307 ** Description      Fetch remote version info on cached remote device
    308 **
    309 ** Returns          BT_STATUS_SUCCESS if found
    310 **                  BT_STATUS_FAIL otherwise
    311 **
    312 *******************************************************************************/
    313 
    314 bt_status_t btif_storage_get_remote_version(const bt_bdaddr_t *remote_bd_addr,
    315                                   bt_remote_version_t *p_ver);
    316 
    317 /******************************************************************************
    318  * Exported for unit tests
    319  *****************************************************************************/
    320 size_t btif_split_uuids_string(const char *str, bt_uuid_t *p_uuid, size_t max_uuids);
    321 
    322 #endif /* BTIF_STORAGE_H */
    323