3 * Copyright (c) 2021 Project CHIP Authors
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * Copyright (c) 2016-2019, The OpenThread Authors.
20 * All rights reserved.
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions are met:
24 * 1. Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * 2. Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in the
28 * documentation and/or other materials provided with the distribution.
29 * 3. Neither the name of the copyright holder nor the
30 * names of its contributors may be used to endorse or promote products
31 * derived from this software without specific prior written permission.
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
34 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
37 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
38 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
39 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
40 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
41 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
42 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
43 * POSSIBILITY OF SUCH DAMAGE.
48 #include <platform/CHIPDeviceConfig.h>
50 #if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
52 #include <ble/CHIPBleServiceData.h>
53 #include <platform/Linux/dbus/bluez/DbusBluez.h>
59 namespace DeviceLayer {
64 BLUEZ_ADV_TYPE_CONNECTABLE = 0x01,
65 BLUEZ_ADV_TYPE_SCANNABLE = 0x02,
66 BLUEZ_ADV_TYPE_DIRECTED = 0x04,
68 BLUEZ_ADV_TYPE_UNDIRECTED_NONCONNECTABLE_NONSCANNABLE = 0,
69 BLUEZ_ADV_TYPE_UNDIRECTED_CONNECTABLE_NONSCANNABLE = BLUEZ_ADV_TYPE_CONNECTABLE,
70 BLUEZ_ADV_TYPE_UNDIRECTED_NONCONNECTABLE_SCANNABLE = BLUEZ_ADV_TYPE_SCANNABLE,
71 BLUEZ_ADV_TYPE_UNDIRECTED_CONNECTABLE_SCANNABLE = BLUEZ_ADV_TYPE_CONNECTABLE | BLUEZ_ADV_TYPE_SCANNABLE,
73 BLUEZ_ADV_TYPE_DIRECTED_NONCONNECTABLE_NONSCANNABLE = BLUEZ_ADV_TYPE_DIRECTED,
74 BLUEZ_ADV_TYPE_DIRECTED_CONNECTABLE_NONSCANNABLE = BLUEZ_ADV_TYPE_DIRECTED | BLUEZ_ADV_TYPE_CONNECTABLE,
75 BLUEZ_ADV_TYPE_DIRECTED_NONCONNECTABLE_SCANNABLE = BLUEZ_ADV_TYPE_DIRECTED | BLUEZ_ADV_TYPE_SCANNABLE,
76 BLUEZ_ADV_TYPE_DIRECTED_CONNECTABLE_SCANNABLE = BLUEZ_ADV_TYPE_DIRECTED | BLUEZ_ADV_TYPE_CONNECTABLE | BLUEZ_ADV_TYPE_SCANNABLE,
79 #define BLUEZ_ADDRESS_SIZE 6 ///< BLE address size (in bytes)
80 #define BLUEZ_PATH "/org/bluez"
81 #define BLUEZ_INTERFACE "org.bluez"
82 #define ADAPTER_INTERFACE BLUEZ_INTERFACE ".Adapter1"
83 #define PROFILE_INTERFACE BLUEZ_INTERFACE ".GattManager1"
84 #define ADVERTISING_MANAGER_INTERFACE BLUEZ_INTERFACE ".LEAdvertisingManager1"
85 #define SERVICE_INTERFACE BLUEZ_INTERFACE ".GattService1"
86 #define CHARACTERISTIC_INTERFACE BLUEZ_INTERFACE ".GattCharacteristic1"
87 #define ADVERTISING_INTERFACE BLUEZ_INTERFACE ".LEAdvertisement1"
88 #define DEVICE_INTERFACE BLUEZ_INTERFACE ".Device1"
90 #define CHIP_PLAT_BLE_UUID_C1_STRING "18ee2ef5-263d-4559-959f-4f9c429f9d11"
91 #define CHIP_PLAT_BLE_UUID_C2_STRING "18ee2ef5-263d-4559-959f-4f9c429f9d12"
92 #define CHIP_PLAT_BLE_UUID_C3_STRING "64630238-8772-45F2-B87D-748A83218F04"
94 #define CHIP_BLE_BASE_SERVICE_UUID_STRING "-0000-1000-8000-00805f9b34fb"
95 #define CHIP_BLE_SERVICE_PREFIX_LENGTH 8
96 #define CHIP_BLE_BASE_SERVICE_PREFIX "0000"
97 #define CHIP_BLE_UUID_SERVICE_SHORT_STRING "feaf"
99 #define CHIP_BLE_UUID_SERVICE_STRING \
100 CHIP_BLE_BASE_SERVICE_PREFIX CHIP_BLE_UUID_SERVICE_SHORT_STRING CHIP_BLE_BASE_SERVICE_UUID_STRING
102 #define BLUEZ_ADV_TYPE_FLAGS 0x01
103 #define BLUEZ_ADV_TYPE_SERVICE_DATA 0x16
105 #define BLUEZ_ADV_FLAGS_LE_LIMITED (1 << 0)
106 #define BLUEZ_ADV_FLAGS_LE_DISCOVERABLE (1 << 1)
107 #define BLUEZ_ADV_FLAGS_EDR_UNSUPPORTED (1 << 2)
108 #define BLUEZ_ADV_FLAGS_LE_EDR_CONTROLLER (1 << 3)
109 #define BLUEZ_ADV_FLAGS_LE_EDR_HOST (1 << 4)
111 enum BluezAddressType
113 BLUEZ_ADDRESS_TYPE_PUBLIC = 0, ///< Bluetooth public device address.
114 BLUEZ_ADDRESS_TYPE_RANDOM_STATIC = 1, ///< Bluetooth random static address.
115 BLUEZ_ADDRESS_TYPE_RANDOM_PRIVATE_RESOLVABLE = 2, ///< Bluetooth random private resolvable address.
116 BLUEZ_ADDRESS_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE = 3, ///< Bluetooth random private non-resolvable address.
121 BluezAddressType mType; ///< Bluetooth device address type.
122 uint8_t mAddress[BLUEZ_ADDRESS_SIZE]; ///< A 48-bit address of Bluetooth device in LSB format.
127 GIOChannel * mpChannel;
133 char * mpOwningName; // Bus owning name
135 // Adapter properties
136 char * mpAdapterName;
137 char * mpAdapterAddr;
139 // Paths for objects published by this service
142 char * mpServicePath;
144 // Objects (interfaces) subscibed to by this service
145 GDBusObjectManager * mpObjMgr = nullptr;
146 BluezAdapter1 * mpAdapter = nullptr;
147 BluezDevice1 * mpDevice = nullptr;
149 // Objects (interfaces) published by this service
150 GDBusObjectManagerServer * mpRoot;
151 BluezGattService1 * mpService;
152 BluezGattCharacteristic1 * mpC1;
153 BluezGattCharacteristic1 * mpC2;
154 // additional data characteristics
155 BluezGattCharacteristic1 * mpC3;
157 // map device path to the connection
158 GHashTable * mpConnMap;
161 char * mpAdvertisingUUID;
162 chip::Ble::ChipBLEDeviceIdentificationInfo mDeviceIdInfo;
163 ChipAdvType mType; ///< Advertisement type.
164 uint16_t mDuration; ///< Advertisement interval (in ms).
166 char * mpPeerDevicePath;
167 GCancellable * mpConnectCancellable = nullptr;
170 struct BluezConnection
172 char * mpPeerAddress;
173 BluezDevice1 * mpDevice;
174 BluezGattService1 * mpService;
175 BluezGattCharacteristic1 * mpC1;
176 BluezGattCharacteristic1 * mpC2;
177 // additional data characteristics
178 BluezGattCharacteristic1 * mpC3;
182 struct IOChannel mC1Channel;
183 struct IOChannel mC2Channel;
184 BluezEndpoint * mpEndpoint;
187 struct ConnectionDataBundle
189 BluezConnection * mpConn;
193 } // namespace Internal
194 } // namespace DeviceLayer
197 #endif // CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE