Merge branch 'tizen' into tizen_5.5
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / oal-device-mgr.c
index b738711..69ceaf3 100755 (executable)
@@ -119,7 +119,7 @@ oal_status_t device_set_alias(bt_address_t * addr, char * alias)
        return OAL_STATUS_SUCCESS;
 }
 
-oal_status_t device_create_bond(bt_address_t *addr, connection_type_e transport)
+oal_status_t device_create_bond(bt_address_t *addr, oal_conn_type_e transport)
 {
        int res;
        bdstr_t bdstr;
@@ -385,7 +385,7 @@ gboolean device_get_svc_conn_state(bt_address_t * addr, oal_service_t svc_id)
        return res;
 }
 
-oal_status_t device_set_osp_server(oal_osp_server_type_e type, int enable)
+oal_status_t device_register_osp_server(oal_osp_server_type_e type, char *uuid, char *path, int fd)
 {
        int res;
        uint32_t server_type;
@@ -399,14 +399,53 @@ oal_status_t device_set_osp_server(oal_osp_server_type_e type, int enable)
        case OAL_OSP_SERVER_OBEX:
                server_type = BT_OSP_SERVER_OBEX;
                break;
+       case OAL_OSP_SERVER_RFCOMM:
+               server_type = BT_OSP_SERVER_RFCOMM;
+               break;
+       default:
+               BT_ERR("unknown type: %d", type);
+               return OAL_STATUS_INVALID_PARAM;
+       }
+
+       res = blued_api->register_agent_osp_server(server_type, uuid, path, fd);
+       if (res != BT_STATUS_SUCCESS) {
+               BT_ERR("register_agent_osp_server error: [%s]", status2string(res));
+               return convert_to_oal_status(res);
+       }
+
+       return OAL_STATUS_SUCCESS;
+#else
+       BT_ERR("Not supported");
+       res = OAL_STATUS_NOT_SUPPORT;
+       return res;
+#endif
+}
+
+oal_status_t device_unregister_osp_server(oal_osp_server_type_e type, char *uuid)
+{
+       int res;
+       uint32_t server_type;
+
+       CHECK_OAL_INITIALIZED();
+
+       API_TRACE("type: %d", type);
+
+#ifdef TIZEN_BT_HAL
+       switch (type) {
+       case OAL_OSP_SERVER_OBEX:
+               server_type = BT_OSP_SERVER_OBEX;
+               break;
+       case OAL_OSP_SERVER_RFCOMM:
+               server_type = BT_OSP_SERVER_RFCOMM;
+               break;
        default:
                BT_ERR("unknown type: %d", type);
                return OAL_STATUS_INVALID_PARAM;
        }
 
-       res = blued_api->set_agent_osp_server(server_type, enable);
+       res = blued_api->unregister_agent_osp_server(server_type, uuid);
        if (res != BT_STATUS_SUCCESS) {
-               BT_ERR("set_agent_osp_server error: [%s]", status2string(res));
+               BT_ERR("unregister_agent_osp_server error: [%s]", status2string(res));
                return convert_to_oal_status(res);
        }
 
@@ -547,6 +586,26 @@ oal_status_t device_enable_gap_auth_notifications(oal_gap_auth_type_e type, gboo
 #endif
 }
 
+oal_status_t device_disconnect(bt_address_t * addr)
+{
+       int res;
+       bdstr_t bdstr;
+
+       CHECK_OAL_INITIALIZED();
+
+       OAL_CHECK_PARAMETER(addr, return);
+
+       API_TRACE("[%s]", bdt_bd2str(addr, &bdstr));
+
+       res = blued_api->device_disconnect((bt_bdaddr_t *)addr);
+       if (res != BT_STATUS_SUCCESS) {
+               BT_ERR("device_disconnect error: [%s]", status2string(res));
+               return convert_to_oal_status(res);
+       }
+
+       return OAL_STATUS_SUCCESS;
+}
+
 void cb_device_properties(bt_status_t status, bt_bdaddr_t *bd_addr,
                int num_properties, bt_property_t *properties)
 {
@@ -578,6 +637,7 @@ void cb_device_properties(bt_status_t status, bt_bdaddr_t *bd_addr,
                event_data = dev_props_event;
                event = OAL_EVENT_DEVICE_PROPERTIES;
                size = sizeof(event_dev_properties_t);
+               g_free(dev_info);
        } else if (num_properties == 1) {
                /* For one particular property a dedicated event to be sent */
                switch (properties[0].type) {
@@ -590,7 +650,7 @@ void cb_device_properties(bt_status_t status, bt_bdaddr_t *bd_addr,
                case BT_PROPERTY_UUIDS: {
                        event_dev_services_t *services_info;
                        bt_uuid_t *uuids = (bt_uuid_t *) properties[0].val;
-                       BT_INFO("Properties len [%d] event structure size [%d]", properties[0].len, sizeof(event_dev_services_t));
+                       BT_INFO("Properties len [%d] event structure size [%zu]", properties[0].len, sizeof(event_dev_services_t));
 
                        services_info = g_malloc(sizeof(event_dev_services_t) + properties[0].len);
                        services_info->address = dev_info->address;
@@ -634,6 +694,7 @@ void cb_device_properties(bt_status_t status, bt_bdaddr_t *bd_addr,
                event_data = dev_props_event;
                event = OAL_EVENT_DEVICE_PROPERTIES;
                size = sizeof(event_dev_properties_t);
+               g_free(dev_info);
        }
 
        send_event_bda_trace(event, event_data, size, (bt_address_t*)bd_addr);
@@ -690,6 +751,9 @@ void cb_device_acl_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr,
 
        memcpy(conn_status->address.addr, bd_addr->address, 6);
 
+#ifdef TIZEN_BT_HAL
+       conn_status->status = convert_to_oal_status(status);
+#else
        if (BT_STATUS_SUCCESS != status) {
                /* At present only timeout will cause non-success status, later we can add more */
                conn_status->status = OAL_STATUS_CONN_TIMEOUT;
@@ -698,6 +762,10 @@ void cb_device_acl_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr,
                conn_status->status = OAL_STATUS_SUCCESS;
 
        memcpy(conn_status->address.addr, bd_addr->address, 6);
+#endif
+
+       BT_INFO("ACL STATE :%d, conn_status->status :%d, BT_ACL_STATE: %d", status, conn_status->status, state);
+
        switch (state) {
        case BT_ACL_STATE_CONNECTED:
                event = OAL_EVENT_DEVICE_ACL_CONNECTED;
@@ -727,11 +795,7 @@ void cb_device_le_conn_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr,
 
        BT_DBG("LE conn status:%d, state: %d", status, state);
        memcpy(conn_status->address.addr, bd_addr->address, 6);
-       if (BT_STATUS_SUCCESS != status)
-               /* At present only timeout will cause non-success status, later we can add more */
-               conn_status->status = OAL_STATUS_CONN_TIMEOUT;
-       else
-               conn_status->status = OAL_STATUS_SUCCESS;
+       conn_status->status = convert_to_oal_status(status);
 
        switch (state) {
        case BT_LE_CONN_STATE_CONNECTED:
@@ -861,12 +925,15 @@ void cb_device_trust_state_changed(bt_bdaddr_t *bd_addr, bt_device_trust_state_t
 }
 
 #ifdef TIZEN_BT_HAL
-void cb_socket_conn_authorize_request(bt_bdaddr_t *bd_addr, bt_uuid_t *uuid)
+void cb_socket_conn_authorize_request(bt_bdaddr_t *bd_addr, bt_uuid_t *uuid, uint8_t *name, uint8_t *path, uint32_t fd)
 {
        event_socket_authorize_req_t *auth_req = g_new0(event_socket_authorize_req_t, 1);
 
        memcpy(auth_req->address.addr, bd_addr->address, 6);
        memcpy(auth_req->uuid.uuid, uuid->uu, 16);
+       memcpy(auth_req->name, name, sizeof(auth_req->name) - 1);
+       memcpy(auth_req->path, path, sizeof(auth_req->path) - 1);
+       auth_req->fd = fd;
 
        send_event_bda_trace(OAL_EVENT_SOCKET_AUTHORIZE_REQUEST, auth_req, sizeof(event_socket_authorize_req_t), (bt_address_t*)bd_addr);
 }
@@ -931,4 +998,5 @@ void cb_raw_rssi_received(bt_bdaddr_t *bd_addr, int32_t link_type, int32_t rssi)
                        ev, sizeof(event_dev_rssi_info_t), (bt_address_t*)bd_addr);
        BT_DBG("-");
 }
+
 #endif