1a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton/******************************************************************************
2a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton *
3a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton *  Copyright (C) 2014 Google, Inc.
4a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton *
5a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton *  Licensed under the Apache License, Version 2.0 (the "License");
6a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton *  you may not use this file except in compliance with the License.
7a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton *  You may obtain a copy of the License at:
8a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton *
9a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton *  http://www.apache.org/licenses/LICENSE-2.0
10a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton *
11a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton *  Unless required by applicable law or agreed to in writing, software
12a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton *  distributed under the License is distributed on an "AS IS" BASIS,
13a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton *  See the License for the specific language governing permissions and
15a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton *  limitations under the License.
16a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton *
17a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton ******************************************************************************/
18a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
19a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton#include "base.h"
20a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton#include "btcore/include/bdaddr.h"
21a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton#include "btcore/include/property.h"
22a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton#include "support/adapter.h"
23a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton#include "support/callbacks.h"
24a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
25a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Mantonstatic bt_state_t state;
26a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Mantonstatic int property_count = 0;
27a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Mantonstatic bt_property_t *properties = NULL;
28a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Mantonstatic bt_discovery_state_t discovery_state;
29a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Mantonstatic bt_acl_state_t acl_state;
30a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Mantonstatic bt_bond_state_t bond_state;
31a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
32a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Mantonstatic void parse_properties(int num_properties, bt_property_t *property);
33a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
34a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton// Returns the current adapter state.
35a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Mantonbt_state_t adapter_get_state() {
36a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  return state;
37a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton}
38a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
39a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton// Returns the number of adapter properties.
40a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Mantonint adapter_get_property_count() {
41a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  return property_count;
42a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton}
43a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
44a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton// Returns the specified property.
45a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Mantonbt_property_t *adapter_get_property(bt_property_type_t type) {
46a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  for (int i = 0; i < property_count; ++i) {
47a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    if (properties[i].type == type) {
48a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      return &properties[i];
49a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    }
50a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  }
51a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
52a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  return NULL;
53a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton}
54a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
55a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton// Returns the device discovery state.
56a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Mantonbt_discovery_state_t adapter_get_discovery_state() {
57a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  return discovery_state;
58a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton}
59a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
60a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton// Returns the device acl state.
61a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Mantonbt_acl_state_t adapter_get_acl_state() {
62a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  return acl_state;
63a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton}
64a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
65a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton// Returns the device bond state.
66a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Mantonbt_bond_state_t adapter_get_bond_state() {
67a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  return bond_state;
68a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton}
69a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
70a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton// callback
71a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Mantonvoid acl_state_changed(bt_status_t status, bt_bdaddr_t *remote_bd_addr, bt_acl_state_t state) {
72a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  acl_state = state;
73a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  CALLBACK_RET();
74a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton}
75a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
76a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton// callback
77a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Mantonvoid adapter_properties(bt_status_t status,
78a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    int num_properties,
79a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    bt_property_t *new_properties) {
80a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  property_free_array(properties, property_count);
81a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  properties = property_copy_array(new_properties, num_properties);
82a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  property_count = num_properties;
83a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
84a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  CALLBACK_RET();
85a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton}
86a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
87a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton// callback
88a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Mantonvoid adapter_state_changed(bt_state_t new_state) {
89a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  state = new_state;
90a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  CALLBACK_RET();
91a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton}
92a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
93a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton// callback
94a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Mantonvoid bond_state_changed(bt_status_t status,
95a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    bt_bdaddr_t *bdaddr,
96a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    bt_bond_state_t state) {
97a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  char buf[18];
98a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  bond_state = state;
99a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
100a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  const char *state_name = "Bond state unknown";
101a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  switch (bond_state) {
102a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    case BT_BOND_STATE_NONE:
103a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      state_name = "Bond state none";
104a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      break;
105a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
106a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    case BT_BOND_STATE_BONDING:
107a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      state_name = "Bond state bonding";
108a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      break;
109a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
110a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    case BT_BOND_STATE_BONDED:
111a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      state_name = "Bond state bonded";
112a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      break;
113a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
114a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      // default none
115a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  }
116a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  fprintf(stdout, "Bond state changed callback addr:%s state:%s\n", bdaddr_to_string(bdaddr, buf, sizeof(buf)), state_name);
117a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
118a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  CALLBACK_RET();
119a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton}
120a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
121a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton// callback
122a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Mantonvoid device_found(int num_properties, bt_property_t *property) {
123a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  fprintf(stdout, "Device found num_properties:%d\n", num_properties);
124a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  parse_properties(num_properties, property);
125a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
126a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  CALLBACK_RET();
127a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton}
128a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
129a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton// callback
130a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Mantonvoid discovery_state_changed(bt_discovery_state_t state) {
131a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  const char *state_name = "Unknown";
132a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  discovery_state = state;
133a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
134a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  switch (discovery_state) {
135a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    case BT_DISCOVERY_STOPPED:
136a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      state_name = "Discovery stopped";
137a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      break;
138a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
139a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    case BT_DISCOVERY_STARTED:
140a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      state_name = "Discovery started";
141a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      break;
142a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
143a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      // default omitted
144a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  }
145a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  fprintf(stdout, "Discover state %s\n", state_name);
146a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
147a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  CALLBACK_RET();
148a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton}
149a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
150a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton// callback
151a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Mantonvoid remote_device_properties(bt_status_t status,
152a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    bt_bdaddr_t *bdaddr,
153a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    int num_properties,
154a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    bt_property_t *properties) {
155a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  char buf[18];
156a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  fprintf(stdout, "Device found bdaddr:%s num_properties:%d\n",
157a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      bdaddr_to_string(bdaddr, buf, sizeof(buf)), num_properties);
158a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
159a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  parse_properties(num_properties, properties);
160a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
161a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  CALLBACK_RET();
162a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton}
163a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
164a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton// callback
165a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Mantonvoid ssp_request(
166a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    bt_bdaddr_t *remote_bd_addr,
167a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    bt_bdname_t *bd_name,
168a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    uint32_t cod,
169a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    bt_ssp_variant_t pairing_variant,
170a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    uint32_t pass_key) {
171a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  char *pairing_variant_name = "Unknown";
172a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
173a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  switch (pairing_variant) {
174a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    case BT_SSP_VARIANT_PASSKEY_CONFIRMATION:
175a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      pairing_variant_name = "Passkey confirmation";
176a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      break;
177a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    case BT_SSP_VARIANT_PASSKEY_ENTRY:
178a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      pairing_variant_name = "Passkey entry";
179a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      break;
180a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
181a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    case BT_SSP_VARIANT_CONSENT:
182a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      pairing_variant_name = "Passkey consent";
183a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      break;
184a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
185a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    case BT_SSP_VARIANT_PASSKEY_NOTIFICATION:
186a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      pairing_variant_name = "Passkey notification";
187a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      break;
188a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  }
189a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
190a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  fprintf(stdout, "Got ssp request device_class:%u passkey:%x pairing_variant:%s\n", cod, pass_key, pairing_variant_name);
191a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  char buf[18];
192a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  fprintf(stdout, "Device found:%s %s\n", bdaddr_to_string(remote_bd_addr, buf, sizeof(buf)), bd_name->name);
193a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
194a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
195a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  fprintf(stdout, "auto-accepting bond\n");
196a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  bool accept = true;
197a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  int rc = bt_interface->ssp_reply(remote_bd_addr, pairing_variant,
198a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      (uint8_t)accept, pass_key);
199a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  CALLBACK_RET();
200a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton}
201a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
202a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton// callback
203a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Mantonvoid thread_evt(bt_cb_thread_evt evt) {
204a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  CALLBACK_RET();
205a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton}
206a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
207a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Mantonstatic void parse_properties(int num_properties, bt_property_t *property) {
208a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  while (num_properties-- > 0) {
209a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    switch(property->type) {
210a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      case BT_PROPERTY_BDNAME:
211a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton        {
2123252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton          const bt_bdname_t *name = property_as_name(property);
2133252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton          if (name)
2143252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton            fprintf(stdout, " name:%s\n", name->name);
215a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton        }
216a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton        break;
217a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
218a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      case BT_PROPERTY_BDADDR:
219a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton        {
220a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton          char buf[18];
2213252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton          const bt_bdaddr_t *addr = property_as_addr(property);
2223252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton          if (addr)
2233252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton            fprintf(stdout, " addr:%s\n", bdaddr_to_string(addr, buf, sizeof(buf)));
224a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton        }
225a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton        break;
226a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
227a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      case BT_PROPERTY_UUIDS:
228a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton        {
2293252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton          size_t num_uuid;
2303252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton          const bt_uuid_t *uuid = property_as_uuids(property, &num_uuid);
231a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton          if (uuid) {
2323252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton            for (size_t i = 0; i < num_uuid; i++) {
233a74fcdfe46726cf629ba6887cb6971bb2c4b8675Nitin Arora              fprintf(stdout, " uuid:%zd: ", i);
2343252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton              for (size_t j = 0; j < sizeof(uuid); j++) {
2353252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton                fprintf(stdout, "%02x", uuid->uu[j]);
2363252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton              }
2373252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton              fprintf(stdout, "\n");
238a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton            }
239a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton          }
240a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton        }
241a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton        break;
242a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
243a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      case BT_PROPERTY_TYPE_OF_DEVICE:
244a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton        {
2453252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton          bt_device_type_t device_type = property_as_device_type(property);
246a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton          if (device_type) {
247a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton            const struct {
248a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton              const char * device_type;
249a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton            } device_type_lookup[] = {
250a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton              { "Unknown" },
251a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton              { "Classic Only" },
252a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton              { "BLE Only" },
253a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton              { "Both Classic and BLE" },
254a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton            };
2553252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton            int idx = (int)device_type;
256a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton            if (idx > BT_DEVICE_DEVTYPE_DUAL)
257a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton              idx = 0;
258a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton            fprintf(stdout, " device_type:%s\n", device_type_lookup[idx].device_type);
259a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton          }
260a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton        }
261a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton        break;
262a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
263a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      case BT_PROPERTY_CLASS_OF_DEVICE:
264a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton        {
2653252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton          const bt_device_class_t *dc = property_as_device_class(property);
26697c544445c8b0d9d67de3652d7249a151e199ad7Chris Manton          int dc_int = device_class_to_int(dc);
26797c544445c8b0d9d67de3652d7249a151e199ad7Chris Manton          fprintf(stdout, " device_class:0x%x\n", dc_int);
268a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton        }
269a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton        break;
270a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
271a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      case BT_PROPERTY_REMOTE_RSSI:
272a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton        {
2733252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton          int8_t rssi = property_as_rssi(property);
274a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton          fprintf(stdout, " rssi:%d\n", rssi);
275a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton        }
276a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton        break;
277a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
278a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      case BT_PROPERTY_REMOTE_FRIENDLY_NAME:
279a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton        {
2803252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton          const bt_bdname_t *name = property_as_name(property);
2813252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton          if (name)
2823252cf07f3ba14201d30269f6ddb1ead765bdde4Chris Manton            fprintf(stdout, " remote_name:%s\n", name->name);
283a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton        }
284a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton        break;
285a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton
286a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      case BT_PROPERTY_SERVICE_RECORD:
287a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      case BT_PROPERTY_ADAPTER_SCAN_MODE:
288a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      case BT_PROPERTY_ADAPTER_BONDED_DEVICES:
289a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
290a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      case BT_PROPERTY_REMOTE_VERSION_INFO:
291a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      case BT_PROPERTY_LOCAL_LE_FEATURES:
292a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      case BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP:
293a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton      default:
294a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton        {
295a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton          fprintf(stderr, "Unhandled property type:%d len:%d\n", property->type, property->len);
296a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton          uint8_t *p = (uint8_t *)property->val;
297a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton          for (int i = 0; i < property->len; ++i, p++) {
298a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton            fprintf(stderr, " %02x", *p);
299a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton          }
300a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton          if (property->len != 0)
301a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton            fprintf(stderr, "\n");
302a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton        }
303a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    }
304a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton    property++;
305a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton  }
306a6cee15a4757c1bdda99fa9491a2eec5421de722Chris Manton}
307