struct hal_property props[0];
} __attribute__((packed));
+#define HAL_EV_ADAPTER_PROFILE_CONNECTED_DEVICES 0x02
+struct hal_ev_adapter_profile_connected_devices {
+ uint8_t count;
+ uint8_t bdaddr_list[10][6];
+} __attribute__((packed));
#define HAL_DISCOVERY_STATE_STOPPED 0x00
#define HAL_DISCOVERY_STATE_STARTED 0x01
return BT_STATUS_SUCCESS;
}
+int _bt_hal_dbus_get_profile_connected_devices(const char *profile_uuid)
+{
+ GDBusConnection *conn;
+ GDBusProxy *manager_proxy;
+ GVariant *result = NULL;
+ GVariant *result1 = NULL;
+ GVariantIter *iter = NULL;
+ GError *error = NULL;
+ char *object_path = NULL;
+ GVariantIter *interface_iter;
+ char *interface_str = NULL;
+ GDBusProxy *device_proxy = NULL;
+ gboolean is_connected = FALSE;
+ struct hal_ev_adapter_profile_connected_devices ev;
+
+ DBG("Get Profile Connected Devices. UUID: %s", profile_uuid);
+ memset(&ev, 0, sizeof(ev));
+
+ conn = __bt_hal_get_system_gconn();
+ if (conn == NULL)
+ return BT_STATUS_FAIL;
+
+ manager_proxy = _bt_hal_get_manager_proxy();
+ if (manager_proxy == NULL)
+ return BT_STATUS_FAIL;
+
+ result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (!result) {
+ if (error != NULL) {
+ ERR("GetManagedObjects failed (Error: %s)", error->message);
+ g_clear_error(&error);
+ error = NULL;
+ } else
+ ERR("GetManagedObjects failed");
+ return BT_STATUS_FAIL;
+ }
+
+ /* signature of GetManagedObjects: a{oa{sa{sv}}} */
+ g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
+
+ /* Parse the signature: oa{sa{sv}}} */
+ while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path, &interface_iter)) {
+ if (object_path == NULL)
+ continue;
+
+ while (g_variant_iter_loop(interface_iter, "{sa{sv}}",
+ &interface_str, NULL)) {
+ if (g_strcmp0(interface_str, "org.bluez.Device1") == 0) {
+ DBG("Found a device: %s", object_path);
+ g_free(interface_str);
+
+ device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_HAL_BLUEZ_NAME,
+ object_path, BT_HAL_DEVICE_INTERFACE, NULL, NULL);
+
+ if (device_proxy == NULL) {
+ DBG("Device don't have this service");
+ break;
+ }
+
+ result1 = g_dbus_proxy_call_sync(device_proxy, "IsConnectedProfile",
+ g_variant_new("(s)", profile_uuid),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (result1 == NULL) {
+ if (error) {
+ ERR("Error occured in Proxy call [%s]", error->message);
+ g_error_free(error);
+ error = NULL;
+ }
+ g_object_unref(device_proxy);
+ break;
+ }
+ g_variant_get(result1, "(b)", &is_connected);
+
+ if (is_connected == TRUE) {
+ char address[BT_HAL_ADDRESS_STRING_SIZE];
+ _bt_hal_convert_device_path_to_address(object_path, address);
+ DBG("Address: %s", address);
+ if (ev.count >= 10) {
+ INFO("Too many address");
+ break;
+ }
+ _bt_hal_convert_addr_string_to_type(ev.bdaddr_list[ev.count], address);
+ ev.count++;
+ }
+
+ g_variant_unref(result1);
+ g_object_unref(device_proxy);
+ break;
+ }
+ }
+ }
+
+ if (!event_cb)
+ event_cb = _bt_hal_get_stack_message_handler();
+ if (event_cb) {
+ DBG("Sending HAL_EV_ADAPTER_PROFILE_CONNECTED_DEVICES event");
+ event_cb(HAL_EV_ADAPTER_PROFILE_CONNECTED_DEVICES, (void *)&ev, sizeof(ev));
+ }
+
+ g_variant_unref(result);
+ g_variant_iter_free(iter);
+
+ DBG("-");
+ return BT_STATUS_SUCCESS;
+}
+
static gboolean __bt_adapter_all_properties_cb(gpointer user_data)
{
GVariant *result = user_data;
int _bt_hal_dbus_get_energy_info(uint32_t *tx_time, uint32_t *rx_time,
uint32_t *idle_time, uint32_t *energy_used);
+int _bt_hal_dbus_get_profile_connected_devices(const char *profile_uuid);
+
int _bt_hal_enable_core(void);
#ifdef __cplusplus
{
return _bt_hal_dbus_get_energy_info(tx_time, rx_time, idle_time, energy_used);
}
+
+static int get_profile_connected_devices(const char *profile_uuid)
+{
+ return _bt_hal_dbus_get_profile_connected_devices(profile_uuid);
+}
#endif
static int get_adapter_properties(void)
#ifdef TIZEN_BT_HAL
.get_adapter_powered_status = get_adapter_powered_status,
.get_adapter_energy_info = get_adapter_energy_info,
+ .get_profile_connected_devices = get_profile_connected_devices,
#endif
.get_adapter_properties = get_adapter_properties,
.get_adapter_property = get_adapter_property,
bt_hal_cbacks->adapter_properties_cb(ev->status, ev->num_props, props);
}
+static void __bt_hal_handle_profile_connected_devices(void *buf, uint16_t len)
+{
+ struct hal_ev_adapter_profile_connected_devices *ev = (struct hal_ev_adapter_profile_connected_devices *)buf;
+
+ if (!bt_hal_cbacks->adapter_profile_connected_devices_cb)
+ return;
+
+ if (bt_hal_cbacks->adapter_profile_connected_devices_cb)
+ bt_hal_cbacks->adapter_profile_connected_devices_cb(ev->count, ev->bdaddr_list);
+}
+
static void __bt_hal_handle_adapter_discovery_state_changed(void *buf, uint16_t len)
{
struct hal_ev_discovery_state_changed *ev = (struct hal_ev_discovery_state_changed *)buf;
DBG("Event: HAL_EV_ADAPTER_PROPS_CHANGED");
__bt_hal_handle_adapter_property_changed(buf, len);
break;
+ case HAL_EV_ADAPTER_PROFILE_CONNECTED_DEVICES:
+ DBG("Event: HAL_EV_ADAPTER_PROFILE_CONNECTED_DEVICES");
+ __bt_hal_handle_profile_connected_devices(buf, len);
+ break;
case HAL_EV_DISCOVERY_STATE_CHANGED:
DBG("Event: HAL_EV_DISCOVERY_STATE_CHANGED");
__bt_hal_handle_adapter_discovery_state_changed(buf, len);
int num_properties,
bt_property_t *properties);
+typedef void (*adapter_profile_connected_devices_callback)(uint8_t count,
+ uint8_t bdaddr_list[][6]);
+
/** GET/SET Remote Device Properties callback */
/** TODO: For remote device properties, do not see a need to get/set
* multiple properties - num_properties shall be 1
size_t size;
adapter_state_changed_callback adapter_state_changed_cb;
adapter_properties_callback adapter_properties_cb;
+ adapter_profile_connected_devices_callback adapter_profile_connected_devices_cb;
remote_device_properties_callback remote_device_properties_cb;
device_found_callback device_found_cb;
discovery_state_changed_callback discovery_state_changed_cb;
/** Get Bluetooth Adapter Energy Information */
int (*get_adapter_energy_info)(uint32_t *tx_time, uint32_t *rx_time,
uint32_t *idle_time, uint32_t *energy_used);
+
+ /** Get Profile Connected Devices */
+ int (*get_profile_connected_devices)(const char *profile_uuid);
#endif
/** Get all Bluetooth Adapter properties at init */
*/
oal_status_t adapter_get_bonded_devices(void);
+/**
+ * @brief Get list of profile connected devices
+ *
+ * @remarks A list of bt_address_t is provided in the event data.
+ *
+ * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
+ * @retval #OAL_STATUS_SUCCESS Successful
+ *
+ * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
+ */
+oal_status_t adapter_get_profile_connected_devices(const char *profile_uuid);
+
/*
* @brief Set connectability of adapter
*
EVENT(OAL_EVENT_ADAPTER_INQUIRY_RESULT_BREDR_ONLY) /* event_dev_found_t */\
EVENT(OAL_EVENT_ADAPTER_INQUIRY_RESULT_BLE) /* event_ble_dev_found_t */\
EVENT(OAL_EVENT_ADAPTER_INQUIRY_FINISHED) \
+ EVENT(OAL_EVENT_ADAPTER_PROFILE_CONNECTED_DEVICES) \
EVENT(OAL_EVENT_CONTROLLER_ERROR_RECEIVED) /* */\
EVENT(OAL_EVENT_DEVICE_PROPERTIES) /* remote_device_t */\
EVENT(OAL_EVENT_DEVICE_NAME) /* remote_device_t */\
service_uuid_t service_list[0];
} event_adapter_services_t;
+typedef struct {
+ uint8_t count;
+ bt_address_t addr_list[10];
+} event_adapter_profile_connected_devices;
+
typedef struct {
/* TODO Add more features */
uint8_t max_adv_instance;
static void cb_adapter_device_found(int num_properties, bt_property_t *properties);
static void cb_adapter_properties(bt_status_t status,
int num_properties, bt_property_t *properties);
+static void cb_adapter_profile_connected_devices(uint8_t count, uint8_t bdaddr_list[][6]);
extern void cb_device_properties(bt_status_t status, bt_bdaddr_t *bd_addr,
int num_properties, bt_property_t *properties);
extern void cb_device_bond_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr,
.size = sizeof(callbacks),
.adapter_state_changed_cb = cb_adapter_state_change,
.adapter_properties_cb = cb_adapter_properties,
+ .adapter_profile_connected_devices_cb = cb_adapter_profile_connected_devices,
.remote_device_properties_cb = cb_device_properties,
.device_found_cb = cb_adapter_device_found,
.discovery_state_changed_cb = cb_adapter_discovery_state_changed,
return OAL_STATUS_SUCCESS;
}
+oal_status_t adapter_get_profile_connected_devices(const char *profile_uuid)
+{
+ int ret;
+
+ CHECK_OAL_INITIALIZED();
+
+ API_TRACE();
+
+ ret = blued_api->get_profile_connected_devices(profile_uuid);
+ if (ret != BT_STATUS_SUCCESS) {
+ BT_ERR("get_profile_connected_devices failed: [%s]", status2string(ret));
+ return convert_to_oal_status(ret);
+ }
+
+ return OAL_STATUS_SUCCESS;
+}
+
static oal_status_t set_scan_mode(bt_scan_mode_t mode)
{
bt_property_t prop;
}
}
+static void cb_adapter_profile_connected_devices(uint8_t count, uint8_t addr_list[][6])
+{
+ event_adapter_profile_connected_devices *event_data;
+ int i;
+
+ event_data = g_malloc0(sizeof(event_adapter_profile_connected_devices));
+ event_data->count = count;
+ for (i = 0; i < count; i++) {
+ memcpy(event_data->addr_list[i].addr, addr_list[i], BT_ADDRESS_BYTES_NUM);
+ }
+ send_event(OAL_EVENT_ADAPTER_PROFILE_CONNECTED_DEVICES, event_data, sizeof(event_adapter_profile_connected_devices));
+}
+
static void cb_adapter_discovery_state_changed(bt_discovery_state_t state)
{
oal_event_t event;
return result;
}
-int _bt_get_profile_connected_devices(char *profile_uuid, GArray **addr_list)
+int _bt_get_profile_connected_devices(const char *profile_uuid)
{
- BT_DBG("+");
- GDBusConnection *conn;
- GDBusProxy *manager_proxy;
- GVariant *result = NULL;
- GVariant *result1 = NULL;
- GVariantIter *iter = NULL;
- GError *error = NULL;
- char *object_path = NULL;
- GVariantIter *interface_iter;
- char *interface_str = NULL;
- GDBusProxy *device_proxy = NULL;
- gboolean is_connected = FALSE;
-
- conn = _bt_gdbus_get_system_gconn();
- retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- manager_proxy = _bt_get_manager_proxy();
- retv_if(manager_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
-
- result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- NULL);
-
- if (!result) {
- if (error != NULL) {
- BT_ERR("Failed to GetManagedObjects (Error: %s)", error->message);
- g_clear_error(&error);
- error = NULL;
- } else
- BT_ERR("Failed to Failed to GetManagedObjects");
- return BLUETOOTH_ERROR_INTERNAL;
- }
-
- /* signature of GetManagedObjects: a{oa{sa{sv}}} */
- g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
-
- /* Parse the signature: oa{sa{sv}}} */
- while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path, &interface_iter)) {
- if (object_path == NULL)
- continue;
-
- while (g_variant_iter_loop(interface_iter, "{sa{sv}}",
- &interface_str, NULL)) {
- if (g_strcmp0(interface_str, "org.bluez.Device1") == 0) {
- BT_DBG("Found a device: %s", object_path);
- g_free(interface_str);
-
- device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
- NULL, BT_BLUEZ_NAME,
- object_path, BT_DEVICE_INTERFACE, NULL, NULL);
-
- if (device_proxy == NULL) {
- BT_DBG("Device don't have this service");
- break;
- }
-
- result1 = g_dbus_proxy_call_sync(device_proxy, "IsConnectedProfile",
- g_variant_new("(s)", profile_uuid),
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- &error);
-
- if (result1 == NULL) {
- BT_ERR("Error occured in Proxy call");
- if (error) {
- BT_ERR("Error occured in Proxy call [%s]\n", error->message);
- g_error_free(error);
- error = NULL;
- }
- g_object_unref(device_proxy);
- break;
- }
- g_variant_get(result1, "(b)", &is_connected);
-
- if (is_connected == TRUE) {
- char address[BT_ADDRESS_STRING_SIZE];
- bluetooth_device_address_t *addr = NULL;
-
- _bt_convert_device_path_to_address(object_path, address);
-
- addr = g_malloc0(sizeof(bluetooth_device_address_t));
- _bt_convert_addr_string_to_type(addr->addr, address);
-
- g_array_append_vals(*addr_list, addr,
- sizeof(bluetooth_device_address_t));
- }
-
- g_variant_unref(result1);
- g_object_unref(device_proxy);
-
- break;
- }
- }
- }
+ int result = BLUETOOTH_ERROR_NONE;
- g_variant_unref(result);
- g_variant_iter_free(iter);
+ BT_DBG("+");
+ result = adapter_get_profile_connected_devices(profile_uuid);
+ if (result != OAL_STATUS_SUCCESS) {
+ BT_ERR("adapter_get_profile_connected_devices failed: %d", result);
+ result = BLUETOOTH_ERROR_INTERNAL;
+ } else
+ result = BLUETOOTH_ERROR_NONE;
BT_DBG("-");
- return BLUETOOTH_ERROR_NONE;
+ return result;
}
static gboolean __bt_disconnect_all(void)
#endif
break;
}
+ case OAL_EVENT_ADAPTER_PROFILE_CONNECTED_DEVICES:
+ BT_DBG("OAL_EVENT_ADAPTER_PROFILE_CONNECTED_DEVICES");
+ __bt_adapter_handle_pending_requests(BT_GET_PROFILE_CONNECTED_DEVICES,
+ event_data, sizeof(event_adapter_profile_connected_devices));
+ break;
default:
BT_ERR("Unhandled event..");
break;
g_array_append_vals(out_param, &used, sizeof(gboolean));
break;
}
+ case BT_GET_PROFILE_CONNECTED_DEVICES: {
+ event_adapter_profile_connected_devices *event_data = user_data;
+ bluetooth_device_address_t addr;
+ int i;
+ for (i = 0; i < event_data->count; i++) {
+ memcpy(&addr, &event_data->addr_list[i], sizeof(bluetooth_device_address_t));
+ g_array_append_vals(out_param, &addr, sizeof(bluetooth_device_address_t));
+ }
+ break;
+ }
default:
BT_ERR("Unknown service function[%d]", service_function);
}
|| service_function == BT_GET_LOCAL_VERSION
|| service_function == BT_GET_BONDED_DEVICES
|| service_function == BT_GET_BONDED_DEVICE
+ || service_function == BT_GET_PROFILE_CONNECTED_DEVICES
|| service_function == BT_GET_IS_ALIAS_SET
|| service_function == BT_GET_CONNECTED_LINK_TYPE
|| service_function == BT_IS_SERVICE_USED
case BT_GET_PROFILE_CONNECTED_DEVICES: {
char *uuid;
uuid = (char *)g_variant_get_data(in_param1);
- result = _bt_get_profile_connected_devices(uuid, out_param1);
+ result = _bt_get_profile_connected_devices(uuid);
+
+ /* Save invocation */
+ if (result == BLUETOOTH_ERROR_NONE) {
+ sender = (char *)g_dbus_method_invocation_get_sender(context);
+ _bt_save_invocation_context(context, result, sender,
+ function_name, NULL);
+ }
break;
}
case BT_SET_ALIAS: {
{
char *l_uuid;
int allow_bt = DPM_BT_ERROR;
- GArray *addr_list = NULL;
- int i = 0;
+ //GArray *addr_list = NULL;
+ //int i = 0;
BT_INFO("_bt_dpm_add_bluetooth_uuids_to_blacklist");
policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list = g_slist_append(policy_table[DPM_POLICY_BLUETOOTH_UUIDS_BLACKLIST].list, l_uuid);
+#if 0 /* Use device functions if this logic required in later */
/* Disconnect if connected blacklist uuid is existing */
addr_list = g_array_new(FALSE, FALSE, sizeof(gchar));
_bt_get_profile_connected_devices((char *)uuid, &addr_list);
// TODO: need to implement disconnect logic
}
g_array_free(addr_list, TRUE);
+#endif
return BLUETOOTH_ERROR_NONE;
}
dpm_profile_state[profile].value = value;
+
+#if 0 /* Use other functions if this logic required in later */
/* In case of restriction, disconnect if connected profile is existing */
if (value == DPM_RESTRICTED) {
char *uuid = NULL;
}
g_array_free(addr_list, TRUE);
}
+#endif
return BLUETOOTH_ERROR_NONE;
}
case OAL_EVENT_ADAPTER_INQUIRY_STARTED:
case OAL_EVENT_ADAPTER_INQUIRY_FINISHED:
case OAL_EVENT_CONTROLLER_ERROR_RECEIVED:
+ case OAL_EVENT_ADAPTER_PROFILE_CONNECTED_DEVICES:
if (adapter_cb)
adapter_cb(event_type, event_data);
break;
int _bt_adapter_get_bonded_devices(void);
-int _bt_get_profile_connected_devices(char *profile_uuid, GArray **addr_list);
+int _bt_get_profile_connected_devices(const char *profile_uuid);
int _bt_init_profiles();