• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (C) 2016 Google, Inc.
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 "rfcomm/rfcomm_test.h"
20 #include "adapter/bluetooth_test.h"
21 
22 #include "btcore/include/bdaddr.h"
23 #include "btcore/include/uuid.h"
24 
25 namespace bttest {
26 
27 const bt_uuid_t RFCommTest::HFP_UUID = {{0x00, 0x00, 0x11, 0x1E, 0x00, 0x00,
28                                          0x10, 0x00, 0x80, 0x00, 0x00, 0x80,
29                                          0x5F, 0x9B, 0x34, 0xFB}};
30 
SetUp()31 void RFCommTest::SetUp() {
32   BluetoothTest::SetUp();
33 
34   ASSERT_EQ(bt_interface()->enable(false), BT_STATUS_SUCCESS);
35   semaphore_wait(adapter_state_changed_callback_sem_);
36   ASSERT_TRUE(GetState() == BT_STATE_ON);
37   socket_interface_ =
38       (const btsock_interface_t*)bt_interface()->get_profile_interface(
39           BT_PROFILE_SOCKETS_ID);
40   ASSERT_NE(socket_interface_, nullptr);
41 
42   // Find a bonded device that supports HFP
43   string_to_bdaddr("00:00:00:00:00:00", &bt_remote_bdaddr_);
44   char value[1280];
45 
46   bt_property_t* bonded_devices_prop =
47       GetProperty(BT_PROPERTY_ADAPTER_BONDED_DEVICES);
48   bt_bdaddr_t* devices = (bt_bdaddr_t*)bonded_devices_prop->val;
49   int num_bonded_devices = bonded_devices_prop->len / sizeof(bt_bdaddr_t);
50 
51   for (int i = 0; i < num_bonded_devices && bdaddr_is_empty(&bt_remote_bdaddr_);
52        i++) {
53     ClearSemaphore(remote_device_properties_callback_sem_);
54     bt_interface()->get_remote_device_property(&devices[i], BT_PROPERTY_UUIDS);
55     semaphore_wait(remote_device_properties_callback_sem_);
56 
57     bt_property_t* uuid_prop =
58         GetRemoteDeviceProperty(&devices[i], BT_PROPERTY_UUIDS);
59     if (uuid_prop == nullptr) continue;
60     bt_uuid_t* uuids = (bt_uuid_t*)uuid_prop->val;
61     int num_uuids = uuid_prop->len / sizeof(bt_uuid_t);
62 
63     for (int j = 0; j < num_uuids; j++) {
64       uuid_to_string(&uuids[j], (uuid_string_t*)value);
65       if (!memcmp(uuids + j, &HFP_UUID, sizeof(bt_uuid_t))) {
66         bdaddr_copy(&bt_remote_bdaddr_, devices + i);
67         break;
68       }
69     }
70   }
71 
72   ASSERT_FALSE(bdaddr_is_empty(&bt_remote_bdaddr_))
73       << "Could not find paired device that supports HFP";
74 }
75 
TearDown()76 void RFCommTest::TearDown() {
77   socket_interface_ = NULL;
78 
79   ASSERT_EQ(bt_interface()->disable(), BT_STATUS_SUCCESS);
80   semaphore_wait(adapter_state_changed_callback_sem_);
81 
82   BluetoothTest::TearDown();
83 }
84 
85 }  // bttest
86