1 /* ****************************************************************
3 * Copyright 2015 Intel Corporation All Rights Reserved.
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.
17 ******************************************************************/
19 #include "advertisement.h"
20 #include "gatt_dbus.h"
22 #include "cagattservice.h"
29 static char const TAG[] = "BLE_ADVERTISEMENT";
31 bool CALEAdvertisementInitialize(CALEAdvertisement * a,
32 GDBusConnection * connection,
36 assert(connection != NULL);
39 D-Bus object path for the LEAdvertisement1 object of the form
40 /org/iotivity/gatt/advertisement0.
42 The same object path is registered with all
43 org.bluez.LEAdvertisingManager1 objects since the advertisement
44 data is same for all Bluetooth hardware adapters.
46 static char const object_path[] =
47 CA_GATT_SERVICE_ROOT_PATH "/" CA_LE_ADVERTISEMENT_PATH;
49 assert(g_variant_is_object_path(object_path));
51 a->advertisement = leadvertisement1_skeleton_new();
54 Setting the BlueZ advertisement type to "peripheral" causes the
55 Bluetooth adapter to go into LE connectable and general
56 discoverable modes upon successful registration of the
57 advertisement with BlueZ.
59 leadvertisement1_set_type_(a->advertisement, "peripheral");
61 static char const * service_uuids[] = {
62 CA_GATT_SERVICE_UUID, // Advertise OIC Transport Profile
66 leadvertisement1_set_service_uuids(a->advertisement, service_uuids);
67 leadvertisement1_set_manufacturer_data(a->advertisement, NULL);
68 leadvertisement1_set_solicit_uuids(a->advertisement, NULL);
69 leadvertisement1_set_service_data(a->advertisement, NULL);
70 leadvertisement1_set_include_tx_power(a->advertisement, FALSE);
72 a->managers = managers;
74 // Export the LEAdvertisement1 interface skeleton.
75 GError * error = NULL;
76 if (!g_dbus_interface_skeleton_export(
77 G_DBUS_INTERFACE_SKELETON(a->advertisement),
84 "Unable to export LE advertisement interface: %s\n",
93 void CALEAdvertisementDestroy(CALEAdvertisement * a)
95 if (a->advertisement != NULL)
97 char const * const advertisement_path =
98 g_dbus_interface_skeleton_get_object_path(
99 G_DBUS_INTERFACE_SKELETON(
102 if (advertisement_path != NULL)
104 for (GList * l = a->managers; l != NULL; l = l->next)
106 GDBusProxy * const manager = G_DBUS_PROXY(l->data);
108 GVariant * const parameters =
109 g_variant_new("(o)", advertisement_path, NULL);
112 Unregister our LE advertisement from the BlueZ LE
117 "UnregisterAdvertisement",
119 G_DBUS_CALL_FLAGS_NONE,
120 -1, // timeout (default == -1),
127 g_clear_object(&a->advertisement);
130 g_list_free_full(a->managers, g_object_unref);