• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #define LOG_TAG "bt_headless_property"
18 
19 #include "test/headless/bt_property.h"
20 
21 #include "base/logging.h"  // LOG() stdout and android log
22 #include "btif/include/btif_api.h"
23 #include "osi/include/log.h"  // android log only
24 #include "stack/include/sdp_api.h"
25 #include "test/headless/get_options.h"
26 #include "test/headless/headless.h"
27 #include "test/headless/interface.h"
28 #include "test/headless/log.h"
29 #include "test/headless/sdp/sdp.h"
30 #include "test/headless/stopwatch.h"
31 #include "types/bluetooth/uuid.h"
32 #include "types/raw_address.h"
33 
34 using namespace bluetooth::test::headless;
35 using namespace std::chrono_literals;
36 
37 namespace bluetooth {
38 namespace test {
39 namespace headless {
40 
process_property(const RawAddress & bd_addr,const bt_property_t * prop)41 void process_property(const RawAddress& bd_addr, const bt_property_t* prop) {
42   LOG_INFO("%s bt_property type:%d len:%d val:%p",
43            ADDRESS_TO_LOGGABLE_CSTR(bd_addr), prop->type,
44            prop->len, prop->val);
45   switch (prop->type) {
46     case BT_PROPERTY_BDNAME: {
47       ASSERT(prop->len >= 0);
48       std::string name(static_cast<const char*>(prop->val),
49                        static_cast<size_t>(prop->len));
50       LOG_CONSOLE("BT_PROPERTY_BDNAME  NAME:%s", name.c_str());
51     } break;
52     case BT_PROPERTY_BDADDR:
53       LOG_CONSOLE("BT_PROPERTY_BDADDR");
54       break;
55     case BT_PROPERTY_UUIDS: {
56       const size_t remainder = prop->len % sizeof(bluetooth::Uuid);
57       ASSERT(remainder == 0);
58       bluetooth::Uuid* uuid = reinterpret_cast<bluetooth::Uuid*>(prop->val);
59       for (int len = prop->len; len > 0; len -= sizeof(*uuid)) {
60         LOG_CONSOLE("BT_PROPERTY_UUIDS  UUID:%s", uuid->ToString().c_str());
61         uuid++;
62       }
63     } break;
64     case BT_PROPERTY_CLASS_OF_DEVICE: {
65       ASSERT(prop->len == 4);
66       uint32_t cod = *(reinterpret_cast<uint32_t*>(prop->val));
67       LOG_CONSOLE("BT_PROPERTY_CLASS_OF_DEVICE  0x%04x", cod);
68     } break;
69     case BT_PROPERTY_TYPE_OF_DEVICE: {
70       ASSERT(prop->len == 4);
71       uint32_t devtype = *(reinterpret_cast<uint32_t*>(prop->val));
72       LOG_CONSOLE("BT_PROPERTY_TYPE_OF_DEVICE  0x%04x", devtype);
73     } break;
74     case BT_PROPERTY_SERVICE_RECORD:
75       LOG_CONSOLE("BT_PROPERTY_SERVICE_RECORD");
76       break;
77     case BT_PROPERTY_ADAPTER_SCAN_MODE:
78       LOG_CONSOLE("BT_PROPERTY_ADAPTER_SCAN_MODE");
79       break;
80     case BT_PROPERTY_ADAPTER_BONDED_DEVICES:
81       LOG_CONSOLE("BT_PROPERTY_ADAPTER_BONDED_DEVICES");
82       break;
83     case BT_PROPERTY_ADAPTER_DISCOVERABLE_TIMEOUT:
84       LOG_CONSOLE("BT_PROPERTY_ADAPTER_DISCOVERABLE_TIMEOUT");
85       break;
86     case BT_PROPERTY_REMOTE_FRIENDLY_NAME:
87       LOG_CONSOLE("BT_PROPERTY_REMOTE_FRIENDLY_NAME");
88       break;
89     case BT_PROPERTY_REMOTE_RSSI:
90       LOG_CONSOLE("BT_PROPERTY_REMOTE_RSSI");
91       break;
92     case BT_PROPERTY_REMOTE_VERSION_INFO:
93       LOG_CONSOLE("BT_PROPERTY_REMOTE_VERSION_INFO");
94       break;
95     case BT_PROPERTY_LOCAL_LE_FEATURES:
96       LOG_CONSOLE("BT_PROPERTY_LOCAL_LE_FEATURES");
97       break;
98     case BT_PROPERTY_LOCAL_IO_CAPS:
99       LOG_CONSOLE("BT_PROPERTY_LOCAL_IO_CAPS");
100       break;
101     case BT_PROPERTY_DYNAMIC_AUDIO_BUFFER:
102       LOG_CONSOLE("BT_PROPERTY_DYNAMIC_AUDIO_BUFFER");
103       break;
104     case BT_PROPERTY_REMOTE_IS_COORDINATED_SET_MEMBER:
105       LOG_CONSOLE("BT_PROPERTY_REMOTE_IS_COORDINATED_SET_MEMBER");
106       break;
107     case BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP:
108       LOG_CONSOLE("BT_PROPERTY_REMOTE_IS_COORDINATED_SET_MEMBER");
109       break;
110     default: {
111       LOG_CONSOLE("Unable to find BT property bd_addr:%s type:%d ptr:%p",
112                   ADDRESS_TO_LOGGABLE_CSTR(bd_addr), prop->type, prop);
113       const uint8_t* p = reinterpret_cast<const uint8_t*>(prop);
114       for (size_t i = 0; i < sizeof(bt_property_t); i++, p++) {
115         LOG_CONSOLE("  %p:0x%02x", p, *p);
116       }
117     } break;
118   }
119 }
120 
121 }  // namespace headless
122 }  // namespace test
123 }  // namespace bluetooth
124