#include "bt-hal-gatt-client.h"
#include "bt-hal-adapter-dbus-handler.h"
+#include "bt-internal-types.h"
+
#define BASELEN_PROP_CHANGED (sizeof(struct hal_ev_adapter_props_changed) \
+ sizeof(struct hal_property))
struct hal_ev_discovery_state_changed ev;
ev.state = HAL_DISCOVERY_STATE_STOPPED;
event_cb(HAL_EV_DISCOVERY_STATE_CHANGED, &ev, sizeof(ev));
- DBG("-");
return FALSE;
}
ev->num_props = 0;
ev->status = BT_STATUS_SUCCESS;
- DBG("+");
-
while (g_variant_iter_loop(&value_iter, "{sv}", &key, &value)) {
if (!g_strcmp0(key, "Address")) {
uint8_t bdaddr[6];
/* TODO: Need to check this operation!! */
if (powered == FALSE) {
DBG("###### Adapter Powered Down ######");
- DBG("Pending disalbed event after bluetoothd is terminated");
-#if 0
- /* We should send the disable event for USB dongle type's target in here. So remain thie code */
- struct hal_ev_adapter_state_changed ev;
- ev.state = HAL_POWER_OFF;
- event_cb(HAL_EV_ADAPTER_STATE_CHANGED, &ev, sizeof(ev));
+ if (TIZEN_FEATURE_BT_USB_DONGLE) {
+ struct hal_ev_adapter_state_changed ev;
+ ev.state = HAL_POWER_OFF;
+ event_cb(HAL_EV_ADAPTER_STATE_CHANGED, &ev, sizeof(ev));
#ifdef TIZEN_BT_HAL
- struct hal_ev_le_state_changed le_ev;
- le_ev.state = HAL_POWER_OFF;
- event_cb(HAL_EV_LE_STATE_CHANGED, &le_ev, sizeof(le_ev));
-#endif
- /* Destroy Agent */
- _bt_hal_destroy_adapter_agent();
+ struct hal_ev_le_state_changed le_ev;
+ le_ev.state = HAL_POWER_OFF;
+ event_cb(HAL_EV_LE_STATE_CHANGED, &le_ev, sizeof(le_ev));
#endif
+ /* Destroy Agent */
+ _bt_hal_destroy_adapter_agent();
+ } else {
+ DBG("Pending disalbed event after bluetoothd is terminated");
+ }
} else {
DBG("###### Adapter Powered Up ######");
if (_bt_hal_get_adapter_request_state()) {
DBG("##Discovering = [%d]", is_discovering);
if (is_discovering == FALSE) {
- DBG("###### Adapter Has stopped Discovering ######");
/* In Tizen Bluez, this actually does not mean Discovery is stopped
in Bluez. Tizen Bluez sends this event after a certain timeout,
Therefore, we must forecefully call StopDiscovery to stop discovery in BlueZ */
DBUS_TIMEOUT, NULL,
&err);
if (err) {
+ struct hal_ev_discovery_state_changed ev;
+
ERR("Dbus Error : %s", err->message);
+ if (g_strrstr(err->message, "No discovery started"))
+ continue;
+
/* This error is thrown by Bluez, as Discovery is already stopped.
Discovery is stopped if user cancels on going discovery.
In order to maintain correct state of Bluetooth Discovery state,
simply send Discovery stopped event to HAL user */
- struct hal_ev_discovery_state_changed ev;
ev.state = HAL_DISCOVERY_STATE_STOPPED;
event_cb(HAL_EV_DISCOVERY_STATE_CHANGED, &ev, sizeof(ev));
g_clear_error(&err);
}
} else {
- DBG("###### Adapter Has started Discovering ######");
struct hal_ev_discovery_state_changed ev;
ev.state = HAL_DISCOVERY_STATE_STARTED;
event_cb(HAL_EV_DISCOVERY_STATE_CHANGED, &ev, sizeof(ev));
ev->num_props++;
} else if (!g_strcmp0(key, "Modalias")) {
char *modalias = NULL;
- g_variant_get(value, "s", &modalias);
+ g_variant_get(value, "&s", &modalias);
DBG("##Adapter ModAlias [%s]", modalias);
} else if (!g_strcmp0(key, "SupportedLEFeatures")) {
DBG("##LE Supported features");
DBG("Send Adapter properties changed event to HAL user, Num Prop [%d] total size [%zd]", ev->num_props, size);
event_cb(HAL_EV_ADAPTER_PROPS_CHANGED, buf, size);
}
-
- DBG("-");
-}
-
-static void __bt_hal_flight_ps_mode_cb(keynode_t *node, void *data)
-{
- gboolean flight_mode = FALSE;
- int type;
- DBG_SECURE("HAL callback hit");
- DBG_SECURE("key=%s", vconf_keynode_get_name(node));
- type = vconf_keynode_get_type(node);
- if (type == VCONF_TYPE_BOOL) {
- flight_mode = vconf_keynode_get_bool(node);
- if (flight_mode != TRUE) {
- ERR("Ignore the event");
- return;
- } else {
- ERR("Flight Mode == TRUE");
- }
- } else {
- ERR("Invaild vconf key type : %d", type);
- return;
- }
- DBG("Enabling core now");
- _bt_hal_enable_core();
-}
-
-static void _bt_hal_register_vconf_handler(void)
-{
- DBG("+");
-
- if (vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
- (vconf_callback_fn)__bt_hal_flight_ps_mode_cb, NULL) < 0)
- ERR("Unable to register key handler");
- DBG("Telephony is disabled");
- if (vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE,
- (vconf_callback_fn)__bt_hal_flight_ps_mode_cb, NULL) < 0)
- ERR("Unable to register key handler");
}
void _bt_hal_handle_adapter_event(GVariant *msg, const char *member)
{
- DBG("+");
-
if (member == NULL)
return;
if (strcasecmp(member, "DeviceCreated") == 0) {
DBG("DeviceCreated: Unhandled");
} else if (strcasecmp(member, "AdvertisingEnabled") == 0) {
- DBG("AdvertisingEnabled");
- DBG("Advertising Enabled");
int slot_id;
gboolean status = FALSE;
g_variant_get(msg, "(ib)", &slot_id, &status);
- DBG("Advertising Enabled : server_slot_id [%d] status [%d]", slot_id, status);
+
/* Send event to application */
_bt_hal_set_advertising_status(slot_id, status);
} else if (strcasecmp(member, "RssiEnabled") == 0) {
g_free(address);
} else if (strcasecmp(member, BT_HAL_HARDWARE_ERROR) == 0) {
+#ifndef TIZEN_BT_HAL
DBG("BT Hardware Error: Unhandled");
+#else
+ struct hal_ev_controller_error_recieved info;
+
+ INFO("### BT Hardware Error");
+ info.code = HAL_CONTROLLER_ERROR_HW_ERROR;
+ event_cb(HAL_EV_CONTROLLER_ERROR_RECIEVED, &info, sizeof(info));
+#endif
} else if (strcasecmp(member, BT_HAL_TX_TIMEOUT_ERROR) == 0) {
- DBG("BT TX Timeout Error: Unhandled");
+#ifndef TIZEN_BT_HAL
+ DBG("BT Hardware Error: Unhandled");
+#else
+ struct hal_ev_controller_error_recieved info;
+
+ INFO("### BT TX Timeout Error");
+ info.code = HAL_CONTROLLER_ERROR_TX_TIMEOUT;
+ event_cb(HAL_EV_CONTROLLER_ERROR_RECIEVED, &info, sizeof(info));
+#endif
} else if (strcasecmp(member, BT_HAL_DBFW_PLUS_INFO) == 0) {
#ifdef TIZEN_BT_HAL
DBG("### DBFW+ info received from BLUEZ");
}
#endif
}
-
- DBG("-");
}
static gboolean __bt_hal_parse_device_properties(GVariant *item)
if (!item)
return FALSE;
- DBG("+");
/* Buffer and propety count management */
uint8_t buf[BT_HAL_MAX_PROPERTY_BUF_SIZE];
} else if (strcasecmp(key, "LegacyManufacturerData") == 0) {
/* TODO: To be handled later*/
} else {
- ERR("Unhandled Property:[%s]", key);
+ DBG("Unhandled Property:[%s]", key);
}
}
- DBG("-");
if (size > 1 && is_bredr_dev) {
DBG("Send Device found event to HAL user, Num Prop [%d] total size [%zd]", ev->num_props, size);
g_variant_unref(value);
return;
}
-
- DBG("-");
}
static void __bt_hal_send_hid_connection_state_event(
g_variant_unref(val);
g_variant_unref(child);
}
-
- DBG("-");
}
static gboolean __bt_hal_parse_interface(GVariant *msg)
} else {
bt_event = __bt_hal_parse_event(value);
if (bt_event == BT_HAL_DEVICE_EVENT) {
+ DBG("InterfacesAdded %s ", obj_path);
__bt_hal_handle_device_event(value, param->parameters);
} else if (bt_event == BT_HAL_AVRCP_CONTROL_EVENT) {
+ DBG("InterfacesAdded %s ", obj_path);
_bt_hal_set_control_device_path(obj_path);
}
}
/*TODO: Handle Interfaces Removed Signal from stack */
g_variant_get(param->parameters, "(&oas)", &obj_path, &iter);
-
+ DBG("InterfacesRemoved %s ", obj_path);
while (g_variant_iter_loop(iter, "s", &str)) {
if (g_strcmp0(str, BT_HAL_PLAYER_CONTROL_INTERFACE) == 0)
_bt_hal_remove_control_device_path(obj_path);
} else if (g_strcmp0(param->interface_name, BT_HAL_PROPERTIES_INTERFACE) == 0) {
__bt_hal_handle_property_changed_event(param->parameters, param->object_path);
} else if (g_strcmp0(param->interface_name, BT_HAL_ADAPTER_INTERFACE) == 0) {
+ DBG("Manager Event: Interface Name: BT_HAL_ADAPTER_INTERFACE");
_bt_hal_handle_adapter_event(param->parameters, param->signal_name);
} else if (g_strcmp0(param->interface_name, BT_HAL_INPUT_INTERFACE) == 0) {
+ DBG("Manager Event: Interface Name: BT_HAL_INPUT_INTERFACE");
__bt_hal_handle_input_event(param->parameters, param->object_path);
} else if (g_strcmp0(param->interface_name, BT_HAL_NETWORK_SERVER_INTERFACE) == 0) {
/* TODO: Handle Network Server events from stack */
DBG("Manager Event: Interface Name: BT_HAL_NETWORK_SERVER_INTERFACE");
} else if (g_strcmp0(param->interface_name, BT_HAL_HEADSET_INTERFACE) == 0) {
+ DBG("Manager Event: Interface Name: BT_HAL_HEADSET_INTERFACE");
__bt_hal_handle_headset_events(param->parameters, param->signal_name, param->object_path);
} else if (g_strcmp0(param->interface_name, BT_HAL_SINK_INTERFACE) == 0) {
/* TODO: Handle Sink interface events from stack */
/* TODO: Handle Agent events from stack */
DBG("Manager Event: Interface Name:BT_HAL_AGENT_INTERFACE");
} else if (g_strcmp0(param->interface_name, BT_HAL_DEVICE_INTERFACE) == 0) {
+ DBG("Manager Event: Interface Name:BT_HAL_DEVICE_INTERFACE");
__bt_hal_handle_device_specific_events(param->parameters, param->signal_name, param->object_path);
} else if (g_strcmp0(param->interface_name, BT_HAL_PLAYER_CONTROL_INTERFACE) == 0) {
+ DBG("Manager Event: Interface Name: BT_HAL_PLAYER_CONTROL_INTERFACE");
__bt_hal_handle_avrcp_ctrl_events(param->parameters, param->signal_name, param->object_path);
} else if (g_strcmp0(param->interface_name, BT_HAL_MEDIATRANSPORT_INTERFACE) == 0) {
+ DBG("Manager Event: Interface Name: BT_HAL_MEDIATRANSPORT_INTERFACE");
__bt_hal_handle_avrcp_transport_events(param->parameters, param->signal_name, param->object_path);
} else if (g_strcmp0(param->interface_name, BT_HAL_GATT_CHAR_INTERFACE) == 0) {
+ DBG("Manager Event: Interface Name: BT_HAL_GATT_CHAR_INTERFACE");
__bt_hal_handle_gatt_char_event(param->parameters, param->signal_name);
} else if (g_strcmp0(param->interface_name, BT_HAL_GATT_SERVICE_INTERFACE) == 0) {
DBG("Manager Event: Interface Name: BT_HAL_GATT_SERVICE_INTERFACE");
static int subs_property_id = -1;
static int subs_adapter_id = -1;
- INFO_C("+");
-
if (subscribe) {
if (subs_interface_added_id == -1) {
subs_interface_added_id = g_dbus_connection_signal_subscribe(conn,
}
}
- INFO_C("-");
return 0;
}
{
static int subs_device_id = -1;
- DBG("+");
if (conn == NULL)
return -1;
}
}
- DBG("-");
return 0;
}
{
static int subs_input_id = -1;
- DBG("+");
-
if (conn == NULL)
return -1;
}
}
- DBG("-");
-
return 0;
}
static int __bt_hal_register_service_event(GDBusConnection *g_conn, int event_type)
{
- DBG("+");
-
if (g_conn == NULL)
return BT_HAL_ERROR_INTERNAL;
manager_conn = NULL;
}
- DBG("-");
-
return BT_HAL_ERROR_INTERNAL;
}
/*TODO: Initialize Obexd Event receiver */
- /* Initialize event receiver for flight mode */
- _bt_hal_register_vconf_handler();
-
event_cb = cb;
- DBG("-");
return BT_HAL_ERROR_NONE;
}
GVariant *value = NULL;
char *key = NULL;
g_variant_iter_init(&value_iter, msg);
- DBG("+");
while (g_variant_iter_loop(&value_iter, "{sv}", &key, &value)) {
if (!g_strcmp0(key, "Connected")) {
guint connected = 0;
g_variant_get(value, "i", &connected);
- DBG("Device property changed : Connected [%d]", connected);
+ INFO("Device property changed : Connected [%d]", connected);
} else if (!g_strcmp0(key, "RSSI")) {
DBG("Device property changed : RSSI");
__bt_hal_dbus_device_found_properties(path);
} else if (!g_strcmp0(key, "GattConnected")) {
- DBG("Device property changed : GattConnected");
gboolean gatt_connected = FALSE;
g_variant_get(value, "b", &gatt_connected);
+ INFO_C("Device property changed : GattConnected [%d]", gatt_connected);
+
char *address = g_malloc0(BT_HAL_ADDRESS_STRING_SIZE);
_bt_hal_convert_device_path_to_address(path, address);
- DBG("@@gatt_connected: %d", gatt_connected);
- DBG("@@address: %s", address);
_bt_hal_gatt_connected_state_event(gatt_connected, address);
_bt_hal_handle_gattc_connected_event(address, gatt_connected);
g_free(address);
if (!event_cb) {
ERR("Bluetooth HAL event handler not registered");
- } else {
- DBG("Sending HAL_EV_BOND_STATE_CHANGED event");
+ } else
event_cb(HAL_EV_BOND_STATE_CHANGED, (void*)&ev, sizeof(ev));
- }
} else if (!g_strcmp0(key, "LegacyPaired")) {
DBG("Device property changed : LegacyPaired");
} else if (!g_strcmp0(key, "Trusted")) {
DBG("Address: %s, TrustedProfiles: 0x%X", address, trust_val);
__bt_hal_send_device_trusted_profile_changed_event(trust_val, address);
} else {
- ERR("Unhandled Property:[%s]", key);
+ DBG("Unhandled Property:[%s]", key);
}
}
- DBG("-");
}
static void __bt_hal_dbus_device_found_properties(const char *device_path)
GDBusProxy *device_proxy;
GDBusConnection *conn;
GVariant *result;
- DBG("+");
if (!device_path) {
ERR("Invalid device path");
g_object_unref(device_proxy);
g_free(address);
-
- DBG("-");
}
static void __bt_hal_device_properties_lookup(GVariant *result, char *address)
(BT_HAL_STACK_UUID_SIZE * uuid_count),
uuids);
ev->num_props = num_props_tmp + 1;
- g_free(uuid_value);
+ g_strfreev(uuid_value);
}
g_variant_unref(tmp_value);
DBG("Send Device found event to HAL user, Num Prop [%d] total size [%zd]", ev->num_props, size);
event_cb(HAL_EV_DEVICE_FOUND, (void*) buf, size);
}
- DBG("-");
}
static void __bt_hal_send_device_acl_connection_state_event(int status, gboolean connected, const char *address)
{
- DBG("+");
struct hal_ev_acl_state_changed ev;
ev.status = status;
ERR("Bluetooth HAL event handler not registered");
else
event_cb(HAL_EV_ACL_STATE_CHANGED, &ev, sizeof(ev));
- DBG("-");
}
static void __bt_hal_send_device_le_connection_state_event(int status, gboolean connected, const char *address)
{
- DBG("+");
struct hal_ev_le_conn_state_changed ev;
ev.status = status;
ERR("Bluetooth HAL event handler not registered");
else
event_cb(HAL_EV_LE_CONN_STATE_CHANGED, &ev, sizeof(ev));
- DBG("-");
}
static void __bt_hal_send_device_trust_state_event(gboolean is_trusted,
const char *address)
{
struct hal_ev_device_trust_state_changed ev;
- DBG("+");
ev.trust = (is_trusted == TRUE) ?
HAL_DEVICE_TRUSTED :
ERR("Bluetooth HAL event handler not registered");
else
event_cb(HAL_EV_DEVICE_TRUST_CHANGED, &ev, sizeof(ev));
- DBG("-");
}
static void __bt_hal_send_device_trusted_profile_changed_event(
uint32_t trust_val, const char *address)
{
struct hal_ev_device_trusted_profiles_changed ev;
- DBG("+");
_bt_hal_convert_addr_string_to_type(ev.bdaddr, address);
ev.trust_val = trust_val;
ERR("Bluetooth HAL event handler not registered");
else
event_cb(HAL_EV_DEVICE_TRUSTED_PROFILES_CHANGED, &ev, sizeof(ev));
- DBG("-");
}
static void __bt_hal_handle_device_specific_events(GVariant *msg, const char *member,
disc_reason, _bt_hal_convert_disc_reason_to_string(disc_reason), address, name);
if (!addr_type)
- __bt_hal_send_device_acl_connection_state_event(_bt_hal_convert_disc_reason_to_status(disc_reason), FALSE, address);
+ __bt_hal_send_device_acl_connection_state_event(disc_reason, FALSE, address);
else
- __bt_hal_send_device_le_connection_state_event(_bt_hal_convert_disc_reason_to_status(disc_reason), FALSE, address);
+ __bt_hal_send_device_le_connection_state_event(disc_reason, FALSE, address);
g_free(address);
} else if (strcasecmp(member, "ProfileStateChanged") == 0) {
int state = 0;
address = g_malloc0(BT_HAL_ADDRESS_STRING_SIZE);
_bt_hal_convert_device_path_to_address(path, address);
- DBG("[%s] %s, state %d", address, profile_uuid, state);
if (strncmp(profile_uuid, HID_UUID, strlen(HID_UUID)) == 0) {
DBG("HID Host Profile state: %d", state);
if (state == BT_HAL_PROFILE_STATE_CONNECTED)
DBG("AVRCP Controller Profile state changed: BT_HAL_PROFILE_STATE_CONNECTING");
}
} else {
- DBG("Profile[%s] State changed status [%d] ", profile_uuid, state);
+ DBG("Profile [%s] State changed [%d] [%s] ", profile_uuid, state, address);
}
g_free(address);
g_free(profile_uuid);
address = g_malloc0(BT_HAL_ADDRESS_STRING_SIZE);
- DBG("Member: [%s]", member);
-
_bt_hal_convert_device_path_to_address(path, address);
g_variant_get(msg, "(q)", &mtu);
memset(buf, 0, sizeof(buf));
size = sizeof(*ev);
- DBG("Address: %s, mtu: %d", address, mtu);
-
ev->conn_id = _bt_get_remote_gatt_client_conn_id(address);
ev->mtu = mtu;
- DBG("Send GATT server mtu changed event to HAL, size: [%zd]", size);
gatt_event_cb(HAL_EV_GATT_SERVER_MTU_CHANGED, buf, size);
}
}
ev->num_attr = i;
- g_variant_iter_free(&iter);
return;
}
DBG("Property not handled");
}
}
-
- g_free((char *)property);
- g_variant_unref(value);
}
static void __bt_hal_handle_avrcp_transport_events(GVariant *msg, const char *member,
/* Send event to application */
avrcp_tg_event_cb(HAL_EV_AVRCP_TG_DELAY_CHANGE, &ev, sizeof(ev));
+ } else if ((strcasecmp(property, "Volume") == 0)) {
+ struct hal_ev_avrcp_tg_volume_changed ev;
+ uint16_t val;
+
+ memset(&ev, 0, sizeof(ev));
+ _bt_hal_convert_addr_string_to_type(ev.bdaddr, address);
+
+ val = g_variant_get_uint16(value);
+ DBG("Value : %d", val);
+ ev.volume = val;
+
+ /* Send event to application */
+ avrcp_tg_event_cb(HAL_EV_AVRCP_TG_VOLUME_CHANGE, &ev, sizeof(ev));
} else {
DBG("Property not handled");
}
}
-
- DBG("-");
- g_free((char *)property);
- g_variant_unref(value);
}
/* A2DP Src Role(Remote:Sink) Events */
static void __bt_hal_send_av_connection_state_event(gboolean connected, const char *address)
{
- DBG("+");
struct hal_ev_a2dp_conn_state ev;
if (connected == TRUE)
/* A2DP Sink Role(Remote:Source) Events */
static void __bt_hal_send_a2dp_sink_connection_state_event(gboolean connected, const char *address)
{
- DBG("+");
struct hal_ev_a2dp_conn_state ev;
if (connected == TRUE)
static void __bt_hal_send_hf_audio_connection_state_event(gboolean connected,
const char *address)
{
- DBG("+");
struct hal_ev_handsfree_audio_state ev;
if (connected == TRUE)
static void __bt_hal_send_hf_connection_state_event(gboolean connected,
const char *address)
{
- DBG("+");
struct hal_ev_handsfree_conn_state ev;
if (connected == TRUE)