• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (C) 2018 The Linux Foundation
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 #define LOG_TAG "btm_iot"
20 
21 #include "stack/include/btm_iot_config.h"
22 
23 #include <bluetooth/log.h>
24 
25 #include "btif/include/btif_storage.h"
26 #include "btm_ble_api.h"
27 #include "device/include/device_iot_config.h"
28 #include "stack/acl/acl.h"
29 #include "stack/include/btm_client_interface.h"
30 
31 using namespace bluetooth;
32 
33 /*******************************************************************************
34  *
35  * Function         btm_iot_save_remote_properties
36  *
37  * Description      Store remote basic properties to iot conf file
38  *
39  * Returns          void
40  *
41  *******************************************************************************/
btm_iot_save_remote_properties(tACL_CONN * p_acl_cb)42 void btm_iot_save_remote_properties(tACL_CONN* p_acl_cb) {
43   BD_NAME bd_name;
44   bt_property_t prop_name;
45   uint32_t cod = 0;
46   tBT_DEVICE_TYPE dev_type;
47   tBLE_ADDR_TYPE addr_type;
48 
49   // save remote name to iot conf file
50   if (BTM_GetRemoteDeviceName(p_acl_cb->remote_addr, bd_name)) {
51     std::string name_str{(char*)bd_name};
52     DEVICE_IOT_CONFIG_ADDR_SET_STR(p_acl_cb->remote_addr, IOT_CONF_KEY_REMOTE_NAME, name_str);
53   }
54 
55   /* Try to retrieve cod from storage */
56   BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod);
57   if (btif_storage_get_remote_device_property(&p_acl_cb->remote_addr, &prop_name) ==
58       BT_STATUS_SUCCESS) {
59     log::verbose("cod retrieved from storage is 0x{:06x}", cod);
60   }
61   if (cod == 0) {
62     log::verbose("cod is 0, set as unclassified");
63     cod = (0x1F) << 8;
64   }
65 
66   DEVICE_IOT_CONFIG_ADDR_SET_INT(p_acl_cb->remote_addr, IOT_CONF_KEY_DEVCLASS, (int)cod);
67 
68   get_btm_client_interface().peer.BTM_ReadDevInfo(p_acl_cb->remote_addr, &dev_type, &addr_type);
69 
70   // save remote dev type to iot conf file
71   DEVICE_IOT_CONFIG_ADDR_SET_INT(p_acl_cb->remote_addr, IOT_CONF_KEY_DEVTYPE, (int)dev_type);
72 
73   // save remote addr type to iot conf file
74   DEVICE_IOT_CONFIG_ADDR_SET_INT(p_acl_cb->remote_addr, IOT_CONF_KEY_ADDRTYPE, (int)addr_type);
75 
76   // save default recorded value to iot conf file
77   DEVICE_IOT_CONFIG_ADDR_SET_INT(p_acl_cb->remote_addr, IOT_CONF_KEY_RECORDED,
78                                  IOT_CONF_VAL_RECORDED_DEFAULT);
79 }
80 
81 /*******************************************************************************
82  *
83  * Function         btm_iot_save_remote_versions
84  *
85  * Description      Store remote versions to iot conf file
86  *
87  * Returns          void
88  *
89  *******************************************************************************/
btm_iot_save_remote_versions(tACL_CONN * p_acl_cb)90 void btm_iot_save_remote_versions(tACL_CONN* p_acl_cb) {
91   DEVICE_IOT_CONFIG_ADDR_SET_INT(p_acl_cb->remote_addr, IOT_CONF_KEY_MANUFACTURER,
92                                  p_acl_cb->remote_version_info.manufacturer);
93   DEVICE_IOT_CONFIG_ADDR_SET_INT(p_acl_cb->remote_addr, IOT_CONF_KEY_LMPVER,
94                                  p_acl_cb->remote_version_info.lmp_version);
95   DEVICE_IOT_CONFIG_ADDR_SET_INT(p_acl_cb->remote_addr, IOT_CONF_KEY_LMPSUBVER,
96                                  p_acl_cb->remote_version_info.lmp_subversion);
97 }
98