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 <bluetooth/log.h>
22
23 #include "btif/include/btif_storage.h"
24 #include "btm_ble_api.h"
25 #include "device/include/device_iot_config.h"
26 #include "internal_include/bt_target.h"
27 #include "os/log.h"
28 #include "stack/acl/acl.h"
29
30 using namespace bluetooth;
31
32 /*******************************************************************************
33 *
34 * Function btm_iot_save_remote_properties
35 *
36 * Description Store remote basic properties to iot conf file
37 *
38 * Returns void
39 *
40 *******************************************************************************/
btm_iot_save_remote_properties(tACL_CONN * p_acl_cb)41 void btm_iot_save_remote_properties(tACL_CONN* p_acl_cb) {
42 BD_NAME bd_name;
43 bt_property_t prop_name;
44 uint32_t cod = 0;
45 tBT_DEVICE_TYPE dev_type;
46 tBLE_ADDR_TYPE addr_type;
47
48 // save remote name to iot conf file
49 if (BTM_GetRemoteDeviceName(p_acl_cb->remote_addr, bd_name)) {
50 std::string name_str{(char*)bd_name};
51 DEVICE_IOT_CONFIG_ADDR_SET_STR(p_acl_cb->remote_addr,
52 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,
57 sizeof(cod), &cod);
58 if (btif_storage_get_remote_device_property(&p_acl_cb->remote_addr,
59 &prop_name) == BT_STATUS_SUCCESS)
60 log::verbose("cod retrieved from storage is 0x{:06x}", cod);
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,
67 (int)cod);
68
69 BTM_ReadDevInfo(p_acl_cb->remote_addr, &dev_type, &addr_type);
70
71 // save remote dev type to iot conf file
72 DEVICE_IOT_CONFIG_ADDR_SET_INT(p_acl_cb->remote_addr, IOT_CONF_KEY_DEVTYPE,
73 (int)dev_type);
74
75 // save remote addr type to iot conf file
76 DEVICE_IOT_CONFIG_ADDR_SET_INT(p_acl_cb->remote_addr, IOT_CONF_KEY_ADDRTYPE,
77 (int)addr_type);
78
79 // save default recorded value to iot conf file
80 DEVICE_IOT_CONFIG_ADDR_SET_INT(p_acl_cb->remote_addr, IOT_CONF_KEY_RECORDED,
81 IOT_CONF_VAL_RECORDED_DEFAULT);
82 }
83
84 /*******************************************************************************
85 *
86 * Function btm_iot_save_remote_versions
87 *
88 * Description Store remote versions to iot conf file
89 *
90 * Returns void
91 *
92 *******************************************************************************/
btm_iot_save_remote_versions(tACL_CONN * p_acl_cb)93 void btm_iot_save_remote_versions(tACL_CONN* p_acl_cb) {
94 DEVICE_IOT_CONFIG_ADDR_SET_INT(p_acl_cb->remote_addr,
95 IOT_CONF_KEY_MANUFACTURER,
96 p_acl_cb->remote_version_info.manufacturer);
97 DEVICE_IOT_CONFIG_ADDR_SET_INT(p_acl_cb->remote_addr, IOT_CONF_KEY_LMPVER,
98 p_acl_cb->remote_version_info.lmp_version);
99 DEVICE_IOT_CONFIG_ADDR_SET_INT(p_acl_cb->remote_addr, IOT_CONF_KEY_LMPSUBVER,
100 p_acl_cb->remote_version_info.lmp_subversion);
101 }
102