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