Code clean up
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / bluez_hal / src / bt-hal-bluetooth.c
index 1f8a36d..1cba249 100644 (file)
@@ -33,6 +33,7 @@
 #include <bt-hal-adapter-dbus-handler.h>
 #include <bt-hal-device-dbus-handler.h>
 #include <bt-hal-hidhost.h>
+#include <bt-hal-hiddevice.h>
 #include <bt-hal-socket.h>
 #include <bt-hal-av.h>
 #include <bt-hal-hf.h>
@@ -45,6 +46,7 @@
 #include <bt-hal-adapter-le.h>
 #include <bt-hal-agent.h>
 #endif
+#include <bt-hal-hf-client.h>
 
 #define enum_prop_to_hal(prop, hal_prop, type) do { \
        static type e; \
@@ -113,6 +115,14 @@ static int disable(void)
 }
 
 #ifdef  TIZEN_BT_HAL
+/* Tizen Specific Recover Adapter */
+static int recover(void)
+{
+       return _bt_hal_dbus_recover_adapter();
+}
+#endif
+
+#ifdef  TIZEN_BT_HAL
 /* Tizen Specific Reset Adapter */
 static int reset(void)
 {
@@ -213,7 +223,6 @@ static int cancel_discovery(void)
 
 static int create_bond(const bt_bdaddr_t *bd_addr, int transport)
 {
-       DBG("+");
        return _bt_hal_device_create_bond(bd_addr, transport);
 }
 
@@ -224,7 +233,6 @@ static int cancel_bond(const bt_bdaddr_t *bd_addr)
 
 static int remove_bond(const bt_bdaddr_t *bd_addr)
 {
-       DBG("+");
        return _bt_hal_device_remove_bond(bd_addr);
 }
 
@@ -251,6 +259,9 @@ static const void *get_profile_interface(const char *profile_id)
        if (!strncmp(profile_id, BT_PROFILE_HIDHOST_ID, strlen(profile_id)))
                return bt_get_hidhost_interface();
 
+       if (!strcmp(profile_id, BT_PROFILE_HIDDEVICE_ID))
+               return bt_get_hiddevice_interface();
+
        if (!strcmp(profile_id, BT_PROFILE_SOCKETS_ID))
                return bt_get_socket_interface();
 
@@ -266,6 +277,9 @@ static const void *get_profile_interface(const char *profile_id)
        if (!strcmp(profile_id, BT_PROFILE_HANDSFREE_ID))
                return bt_get_hf_interface();
 
+       if (!strcmp(profile_id, BT_PROFILE_HANDSFREE_CLIENT_ID))
+               return bt_get_hf_client_interface();
+
        if (!strcmp(profile_id, BT_PROFILE_GATT_ID))
                return bt_get_gatt_interface();
 
@@ -330,13 +344,11 @@ static int read_energy_info(void)
 static int authorize_response(const bt_bdaddr_t *bd_addr, bt_service_id_t service_id,
                uint8_t authorize, uint8_t save_settings)
 {
-       DBG("+");
        return _bt_hal_device_authorize_response(bd_addr, service_id, authorize, save_settings);
 }
 
 int set_authorization(bt_bdaddr_t *bd_addr, uint8_t auth)
 {
-       DBG("+");
        return _bt_hal_device_set_trust(bd_addr, auth);
 }
 
@@ -347,10 +359,16 @@ static int get_service_connection_state(const bt_bdaddr_t *bd_addr, bt_service_i
        return _bt_hal_device_get_service_connection_state(bd_addr, rem_svc_id);
 }
 
-static int set_agent_osp_server(uint32_t type, uint8_t enable)
+static int register_agent_osp_server(uint32_t type, char *uuid, char *path, int fd)
+{
+       DBG("");
+       return _bt_hal_device_register_osp_server(type, uuid, path, fd);
+}
+
+static int unregister_agent_osp_server(uint32_t type, char *uuid)
 {
        DBG("");
-       return _bt_hal_device_set_osp_server(type, enable);
+       return _bt_hal_device_unregister_osp_server(type, uuid);
 }
 
 static int set_trusted_profile(bt_bdaddr_t *bd_addr, bt_trusted_profile_t profile, uint8_t trust)
@@ -399,6 +417,11 @@ static int set_hal_le_request_state(int enable)
        _bt_hal_set_le_request_state(enable);
        return BT_STATUS_SUCCESS;
 }
+
+static int dev_disconnect(const bt_bdaddr_t *bd_addr)
+{
+       return _bt_hal_device_disconnect(bd_addr);
+}
 #endif
 
 static const bt_interface_t bluetooth_if = {
@@ -406,7 +429,9 @@ static const bt_interface_t bluetooth_if = {
        .init = init,
        .enable = enable,
        .disable = disable,
+
 #ifdef TIZEN_BT_HAL
+       .recover = recover,
        .reset = reset,
 #endif
 
@@ -452,7 +477,8 @@ static const bt_interface_t bluetooth_if = {
        .set_authorization = set_authorization,
 #ifdef TIZEN_BT_HAL
        .get_service_connection_state = get_service_connection_state,
-       .set_agent_osp_server = set_agent_osp_server,
+       .register_agent_osp_server = register_agent_osp_server,
+       .unregister_agent_osp_server = unregister_agent_osp_server,
        .set_trusted_profile = set_trusted_profile,
        .get_trusted_profile = get_trusted_profile,
        .enable_rssi_monitoring = enable_rssi_monitoring,
@@ -461,7 +487,10 @@ static const bt_interface_t bluetooth_if = {
        .set_le_static_random_address = _bt_hal_set_le_static_random_address,
        .set_hal_adapter_request_state = set_hal_adapter_request_state,
        .set_hal_le_request_state = set_hal_le_request_state,
+       .adapter_le_set_manufacturer_data = _bt_hal_adapter_le_set_manufacturer_data,
        .adapter_le_set_white_list = _bt_hal_adapter_le_set_white_list,
+       .adapter_le_set_privacy = _bt_hal_adapter_le_set_privacy,
+       .device_disconnect = dev_disconnect,
 #endif
 };
 
@@ -507,7 +536,7 @@ struct hw_module_t HAL_MODULE_INFO_SYM = {
        .version_major = 1,
        .version_minor = 0,
        .id = BT_HARDWARE_MODULE_ID,
-       .name = "Bluetooth stack",
+       .name = "bluez",
        .author = "Intel Corporation",
        .methods = &bluetooth_module_methods
 };
@@ -575,10 +604,7 @@ static void __bt_device_props_to_hal(bt_property_t *send_props,
        void *buf = prop;
        uint8_t i;
 
-       DBG("+");
-
        for (i = 0; i < num_props; i++) {
-
                if (sizeof(*prop) + prop->len > len) {
                        ERR("invalid device properties (%zu > %u), cant process further properties!!!",
                                        sizeof(*prop) + prop->len, len);
@@ -587,8 +613,6 @@ static void __bt_device_props_to_hal(bt_property_t *send_props,
 
                send_props[i].type = prop->type;
 
-               DBG("HAL prop Type [%d]", prop->type);
-
                switch (prop->type) {
                case HAL_PROP_DEVICE_TYPE:
                {
@@ -638,7 +662,6 @@ static void __bt_device_props_to_hal(bt_property_t *send_props,
        }
 
        if (!len) {
-               DBG("-");
                return;
        }
 
@@ -649,7 +672,6 @@ static void __bt_hal_handle_adapter_property_changed(void *buf, uint16_t len)
 {
        struct hal_ev_adapter_props_changed *ev = (struct hal_ev_adapter_props_changed *)buf;
        bt_property_t props[ev->num_props];
-       DBG("+");
 
        if (!bt_hal_cbacks->adapter_properties_cb)
                return;
@@ -665,8 +687,6 @@ static void __bt_hal_handle_adapter_discovery_state_changed(void *buf, uint16_t
 {
        struct hal_ev_discovery_state_changed *ev = (struct hal_ev_discovery_state_changed *)buf;
 
-       DBG("+");
-
        if (bt_hal_cbacks->discovery_state_changed_cb)
                bt_hal_cbacks->discovery_state_changed_cb(ev->state);
 }
@@ -675,7 +695,6 @@ static void __bt_hal_handle_device_found_event(void *buf, uint16_t len)
 {
        struct hal_ev_device_found *ev =  (struct hal_ev_device_found *) buf;
        bt_property_t props[ev->num_props];
-       DBG("+");
 
        if (!bt_hal_cbacks->device_found_cb)
                return;
@@ -692,8 +711,6 @@ static void __bt_hal_handle_remote_device_properties_event(void *buf, uint16_t l
        bt_bdaddr_t bd_addr;
        bt_property_t props[ev->num_props];
 
-       DBG("+");
-
        if (!bt_hal_cbacks->remote_device_properties_cb)
                return;
 
@@ -702,7 +719,6 @@ static void __bt_hal_handle_remote_device_properties_event(void *buf, uint16_t l
        memcpy(bd_addr.address, ev->bdaddr, 6);
        bt_hal_cbacks->remote_device_properties_cb(
                        ev->status, &bd_addr, ev->num_props, props);
-       DBG("-");
 }
 
 static void __bt_hal_handle_bond_state_changed_event(void *buf, uint16_t len)
@@ -710,16 +726,8 @@ static void __bt_hal_handle_bond_state_changed_event(void *buf, uint16_t len)
 
        struct hal_ev_bond_state_changed *ev = (struct hal_ev_bond_state_changed *)buf;
        bt_bdaddr_t bd_addr;
-       DBG("+");
 
        memcpy(bd_addr.address, ev->bdaddr, 6);
-       /* BD address*/
-       DBG("[0x%x]", bd_addr.address[0]);
-       DBG("[0x%x]", bd_addr.address[1]);
-       DBG("[0x%x]", bd_addr.address[2]);
-       DBG("[0x%x]", bd_addr.address[3]);
-       DBG("[0x%x]", bd_addr.address[4]);
-       DBG("[0x%x]", bd_addr.address[5]);
 
        DBG("Bonding  State changed Status [0x%x]", ev->status);
        DBG("Bonding  State [0x%x]", ev->state);
@@ -730,26 +738,15 @@ static void __bt_hal_handle_bond_state_changed_event(void *buf, uint16_t len)
        }
 
        bt_hal_cbacks->bond_state_changed_cb(ev->status, &bd_addr, ev->state);
-       DBG("-");
 }
 
 static void __bt_hal_handle_device_acl_state_changed_event(void *buf, uint16_t len)
 {
        struct hal_ev_acl_state_changed *ev = (struct hal_ev_acl_state_changed*)buf;
        bt_bdaddr_t bd_addr;
-       DBG("+");
 
        memcpy(bd_addr.address, ev->bdaddr, 6);
-       /* BD address*/
-       DBG("[0x%x]", bd_addr.address[0]);
-       DBG("[0x%x]", bd_addr.address[1]);
-       DBG("[0x%x]", bd_addr.address[2]);
-       DBG("[0x%x]", bd_addr.address[3]);
-       DBG("[0x%x]", bd_addr.address[4]);
-       DBG("[0x%x]", bd_addr.address[5]);
-
-       DBG("ACL Status [0x%x]", ev->status);
-       DBG("ACL State  [0x%x]", ev->state);
+       INFO("ACL status[0x%x], state[0x%x]: XX:XX:XX:XX:XX:%02X", ev->status, ev->state, bd_addr.address[5]);
 
        if (!bt_hal_cbacks->acl_state_changed_cb) {
                ERR("HAL User acl_state_changed_cb is not set!!");
@@ -757,14 +754,12 @@ static void __bt_hal_handle_device_acl_state_changed_event(void *buf, uint16_t l
        }
 
        bt_hal_cbacks->acl_state_changed_cb(ev->status, &bd_addr, ev->state);
-       DBG("-");
 }
 
 static void __bt_hal_handle_device_le_conn_state_changed_event(void *buf, uint16_t len)
 {
        struct hal_ev_acl_state_changed *ev = (struct hal_ev_acl_state_changed*)buf;
        bt_bdaddr_t bd_addr;
-       DBG("+");
 
        memcpy(bd_addr.address, ev->bdaddr, 6);
        /* BD address */
@@ -782,7 +777,6 @@ static void __bt_hal_handle_device_le_conn_state_changed_event(void *buf, uint16
 
        bt_hal_cbacks->le_conn_state_changed_cb(ev->status, &bd_addr, ev->state);
 #endif
-       DBG("-");
 }
 
 static void __bt_hal_handle_authorize_request_event(void *buf, uint16_t len)
@@ -790,8 +784,6 @@ static void __bt_hal_handle_authorize_request_event(void *buf, uint16_t len)
        struct hal_ev_authorize_request *ev = (struct hal_ev_authorize_request *)buf;
        bt_bdaddr_t bd_addr;
 
-       DBG("+");
-
        memcpy(bd_addr.address, ev->bdaddr, 6);
 
        /* BD address*/
@@ -810,7 +802,6 @@ static void __bt_hal_handle_authorize_request_event(void *buf, uint16_t len)
        }
 
        bt_hal_cbacks->authorize_request_cb(&bd_addr, ev->service_id);
-       DBG("-");
 }
 
 #ifdef TIZEN_BT_HAL
@@ -819,19 +810,22 @@ static void __bt_hal_handle_socket_authorize_request_event(void *buf, uint16_t l
        struct hal_ev_sock_conn_auth *ev = buf;
        bt_bdaddr_t bd_addr;
        bt_uuid_t uuid;
-
-       DBG("+");
+       uint8_t name[249] = {0, };
+       uint8_t path[249] = {0, };
+       uint32_t fd;
 
        memcpy(bd_addr.address, ev->bdaddr, 6);
        memcpy(uuid.uu, ev->uuid, 16);
+       memcpy(name, ev->name, sizeof(name) - 1);
+       memcpy(path, ev->path, sizeof(name) - 1);
+       fd = ev->fd;
 
        if (!bt_hal_cbacks->socket_authorize_request_cb) {
                ERR("HAL User socket_authorize_request_cb is not set!!");
                return;
        }
 
-       bt_hal_cbacks->socket_authorize_request_cb(&bd_addr, &uuid);
-       DBG("-");
+       bt_hal_cbacks->socket_authorize_request_cb(&bd_addr, &uuid, name, path, fd);
 }
 #endif
 
@@ -840,7 +834,6 @@ static void __bt_hal_handle_ssp_request_event(void *buf, uint16_t len)
        struct hal_ev_ssp_request *ev = (struct hal_ev_ssp_request *)buf;
        bt_bdaddr_t bd_addr;
        bt_bdname_t bd_name;
-       DBG("+");
 
        memcpy(bd_addr.address, ev->bdaddr, 6);
        memcpy(bd_name.name, ev->name, 248);
@@ -865,7 +858,6 @@ static void __bt_hal_handle_ssp_request_event(void *buf, uint16_t len)
        bt_hal_cbacks->ssp_request_cb(&bd_addr, &bd_name,
                        ev->class_of_dev,
                        ev->pairing_variant, ev->passkey);
-       DBG("-");
 }
 
 static void __bt_hal_handle_pin_request_event(void *buf, uint16_t len)
@@ -873,7 +865,6 @@ static void __bt_hal_handle_pin_request_event(void *buf, uint16_t len)
        struct hal_ev_pin_request *ev = (struct hal_ev_pin_request *)buf;
        bt_bdaddr_t bd_addr;
        bt_bdname_t bd_name;
-       DBG("+");
 
        memcpy(bd_addr.address, ev->bdaddr, 6);
        memcpy(bd_name.name, ev->name, 248);
@@ -895,14 +886,12 @@ static void __bt_hal_handle_pin_request_event(void *buf, uint16_t len)
 
        bt_hal_cbacks->pin_request_cb(&bd_addr, &bd_name,
                        ev->class_of_dev);
-       DBG("-");
 }
 
 static void __bt_hal_handle_device_trust_state_changed_event(void *buf, uint16_t len)
 {
        struct hal_ev_device_trust_state_changed *ev = (struct hal_ev_device_trust_state_changed*)buf;
        bt_bdaddr_t bd_addr;
-       DBG("+");
 
        memcpy(bd_addr.address, ev->bdaddr, 6);
        /* BD address*/
@@ -921,7 +910,6 @@ static void __bt_hal_handle_device_trust_state_changed_event(void *buf, uint16_t
        }
 
        bt_hal_cbacks->device_trust_state_changed_cb(&bd_addr, ev->trust);
-       DBG("-");
 }
 
 static void __bt_hal_handle_device_trusted_profiles_changed_event(void *buf, uint16_t len)
@@ -929,7 +917,6 @@ static void __bt_hal_handle_device_trusted_profiles_changed_event(void *buf, uin
        struct hal_ev_device_trusted_profiles_changed *ev = buf;
        bt_bdaddr_t bd_addr;
 
-       DBG("+");
 #ifdef TIZEN_BT_HAL
        memcpy(bd_addr.address, ev->bdaddr, 6);
        DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
@@ -944,7 +931,6 @@ static void __bt_hal_handle_device_trusted_profiles_changed_event(void *buf, uin
 
        bt_hal_cbacks->device_trusted_profiles_changed_cb(&bd_addr, ev->trust_val);
 #endif
-       DBG("-");
 }
 
 static void __bt_handle_rssi_monitor_state_changed(void *buf, uint16_t len)
@@ -952,7 +938,6 @@ static void __bt_handle_rssi_monitor_state_changed(void *buf, uint16_t len)
        struct hal_ev_rssi_monitor_state_changed *ev = buf;
        bt_bdaddr_t bd_addr;
 
-       DBG("+");
 #ifdef TIZEN_BT_HAL
        memcpy(bd_addr.address, ev->bdaddr, 6);
        DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
@@ -964,7 +949,6 @@ static void __bt_handle_rssi_monitor_state_changed(void *buf, uint16_t len)
                bt_hal_cbacks->rssi_monitor_state_changed_cb(
                                &bd_addr, ev->link_type, ev->state);
 #endif
-       DBG("-");
 }
 
 static void __bt_handle_rssi_alert_recieved(void *buf, uint16_t len)
@@ -972,7 +956,6 @@ static void __bt_handle_rssi_alert_recieved(void *buf, uint16_t len)
        struct hal_ev_rssi_alert_recieved *ev = buf;
        bt_bdaddr_t bd_addr;
 
-       DBG("+");
 #ifdef TIZEN_BT_HAL
        memcpy(bd_addr.address, ev->bdaddr, 6);
        DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
@@ -984,7 +967,6 @@ static void __bt_handle_rssi_alert_recieved(void *buf, uint16_t len)
                bt_hal_cbacks->rssi_alert_cb(
                                &bd_addr, ev->link_type, ev->alert_type, ev->rssi);
 #endif
-       DBG("-");
 }
 
 static void __bt_handle_raw_rssi_recieved(void *buf, uint16_t len)
@@ -992,7 +974,6 @@ static void __bt_handle_raw_rssi_recieved(void *buf, uint16_t len)
        struct hal_ev_raw_rssi_recieved *ev = buf;
        bt_bdaddr_t bd_addr;
 
-       DBG("+");
 #ifdef TIZEN_BT_HAL
        memcpy(bd_addr.address, ev->bdaddr, 6);
        DBG("[0x%02X:%02X:%02X:%02X:%02X:%02X]",
@@ -1004,12 +985,21 @@ static void __bt_handle_raw_rssi_recieved(void *buf, uint16_t len)
                bt_hal_cbacks->raw_rssi_received_cb(
                                &bd_addr, ev->link_type, ev->rssi);
 #endif
-       DBG("-");
+}
+
+static void __bt_handle_dbfw_plus_info_recieved(void *buf, uint16_t len)
+{
+       struct hal_ev_dbfw_plus_info_recieved *info = buf;
+
+#ifdef TIZEN_BT_HAL
+       if (bt_hal_cbacks->dbfw_plus_info_received_cb)
+               bt_hal_cbacks->dbfw_plus_info_received_cb(
+                               info->data, info->data_len, info->event_code);
+#endif
 }
 
 static void __bt_hal_handle_stack_messages(int message, void *buf, uint16_t len)
 {
-       DBG("+");
        switch (message) {
        case HAL_EV_ADAPTER_STATE_CHANGED:
                DBG("Event: HAL_EV_ADAPTER_STATE_CHANGED");
@@ -1085,9 +1075,12 @@ static void __bt_hal_handle_stack_messages(int message, void *buf, uint16_t len)
                DBG("Event: HAL_EV_RAW_RSSI_RECIEVED");
                __bt_handle_raw_rssi_recieved(buf, len);
                break;
+       case HAL_EV_DBFW_PLUS_INFO_RECIEVED:
+               DBG("Event: HAL_EV_DBFW_PLUS_INFO_RECIEVED");
+               __bt_handle_dbfw_plus_info_recieved(buf, len);
+               break;
        default:
                DBG("Event Currently not handled!!");
                break;
        }
-       DBG("-");
 }