b8b3d86844f8330089b229f346ac0ad9c26ea7d6
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / bluez_hal / src / bt-hal-socket.c
1 /*
2  * Bluetooth-frwk
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:  Atul Rai <a.rai@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *              http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #include <stdbool.h>
23 #include <stddef.h>
24 #include <string.h>
25 #include <stdlib.h>
26 #include <dlog.h>
27
28 #include "bt-hal.h"
29 #include "bt-hal-log.h"
30 #include "bt-hal-msg.h"
31 #include "bt-hal-utils.h"
32 #include "bt-hal-rfcomm-dbus-handler.h"
33
34 static bt_status_t listen(btsock_type_t type, const char *service_name,
35                 const uint8_t *uuid, int channel, int *sock_fd, int flags)
36 {
37         DBG("");
38         return BT_STATUS_UNSUPPORTED;
39 }
40
41 static bt_status_t connect(const bt_bdaddr_t *bd_addr, btsock_type_t type,
42                 const uint8_t *uuid, int channel, int *sock_fd, int flags)
43 {
44         bt_status_t status;
45
46         DBG("+");
47
48         if (bd_addr == NULL || sock_fd == NULL) {
49                 ERR("invalid parameters, bd_addr:%p, uuid:%p, channel:%d, sock_fd:%p",
50                                 bd_addr, uuid, channel, sock_fd);
51                 return BT_STATUS_PARM_INVALID;
52         }
53
54         if (!uuid) {
55                 ERR("Currently we only support to connect using UUID");
56                 return BT_STATUS_UNSUPPORTED;
57         }
58
59         INFO("channel: %d, sock_fd: %d, type: %d", channel, sock_fd, type);
60
61         switch (type) {
62         case BTSOCK_RFCOMM:
63                 /* Call rfcomm dbus handler to connect rfcomm client */
64                 status = _bt_hal_dbus_handler_rfcomm_connect(
65                                 (unsigned char *)bd_addr->address,
66                                 (unsigned char *)uuid, sock_fd);
67                 break;
68         case BTSOCK_L2CAP:
69                 ERR("bt l2cap socket type not supported");
70                 status = BT_STATUS_UNSUPPORTED;
71                 goto failed;
72         case BTSOCK_SCO:
73                 ERR("bt sco socket not supported");
74                 status = BT_STATUS_UNSUPPORTED;
75                 goto failed;
76         default:
77                 ERR("unknown bt socket type:%d", type);
78                 status = BT_STATUS_UNSUPPORTED;
79                 goto failed;
80         }
81
82         DBG("-");
83         return status;
84
85 failed:
86         *sock_fd = -1;
87         return status;
88 }
89
90 static btsock_interface_t socket_if = {
91         .size = sizeof(socket_if),
92         .listen = listen,
93         .connect = connect
94 };
95
96 btsock_interface_t *bt_get_socket_interface(void)
97 {
98         return &socket_if;
99 }