Fix dlog format error
[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         bt_status_t status;
38
39         DBG("+");
40
41         if (service_name == NULL || sock_fd == NULL) {
42                 ERR("invalid parameters, service_name:%p, uuid:%p, channel:%d, sock_fd:%p",
43                                 service_name, uuid, channel, sock_fd);
44                 return BT_STATUS_PARM_INVALID;
45         }
46
47         if (!uuid) {
48                 ERR("Currently we only support to listen using UUID");
49                 return BT_STATUS_UNSUPPORTED;
50         }
51
52         INFO("channel: %d, sock_fd: %d, type: %d", channel, *sock_fd, type);
53
54         switch (type) {
55         case BTSOCK_RFCOMM:
56                 /* Call rfcomm dbus handler to connect rfcomm client */
57                 status = _bt_hal_dbus_handler_rfcomm_listen(
58                                 service_name, (unsigned char *)uuid, sock_fd);
59                 break;
60         case BTSOCK_L2CAP:
61                 ERR("bt l2cap socket type not supported");
62                 status = BT_STATUS_UNSUPPORTED;
63                 goto failed;
64         case BTSOCK_SCO:
65                 ERR("bt sco socket not supported");
66                 status = BT_STATUS_UNSUPPORTED;
67                 goto failed;
68         default:
69                 ERR("unknown bt socket type:%d", type);
70                 status = BT_STATUS_UNSUPPORTED;
71                 goto failed;
72         }
73
74         DBG("-");
75         return status;
76
77 failed:
78         *sock_fd = -1;
79         return status;
80 }
81
82 static bt_status_t connect(const bt_bdaddr_t *bd_addr, btsock_type_t type,
83                 const uint8_t *uuid, int channel, int *sock_fd, int flags)
84 {
85         bt_status_t status;
86
87         DBG("+");
88
89         if (bd_addr == NULL || sock_fd == NULL) {
90                 ERR("invalid parameters, bd_addr:%p, uuid:%p, channel:%d, sock_fd:%p",
91                                 bd_addr, uuid, channel, sock_fd);
92                 return BT_STATUS_PARM_INVALID;
93         }
94
95         if (!uuid) {
96                 ERR("Currently we only support to connect using UUID");
97                 return BT_STATUS_UNSUPPORTED;
98         }
99
100         INFO("channel: %d, sock_fd: %d, type: %d", channel, *sock_fd, type);
101
102         switch (type) {
103         case BTSOCK_RFCOMM:
104                 /* Call rfcomm dbus handler to connect rfcomm client */
105                 status = _bt_hal_dbus_handler_rfcomm_connect(
106                                 (unsigned char *)bd_addr->address,
107                                 (unsigned char *)uuid, sock_fd);
108                 break;
109         case BTSOCK_L2CAP:
110                 ERR("bt l2cap socket type not supported");
111                 status = BT_STATUS_UNSUPPORTED;
112                 goto failed;
113         case BTSOCK_SCO:
114                 ERR("bt sco socket not supported");
115                 status = BT_STATUS_UNSUPPORTED;
116                 goto failed;
117         default:
118                 ERR("unknown bt socket type:%d", type);
119                 status = BT_STATUS_UNSUPPORTED;
120                 goto failed;
121         }
122
123         DBG("-");
124         return status;
125
126 failed:
127         *sock_fd = -1;
128         return status;
129 }
130
131 static btsock_interface_t socket_if = {
132         .size = sizeof(socket_if),
133         .listen = listen,
134         .connect = connect
135 };
136
137 btsock_interface_t *bt_get_socket_interface(void)
138 {
139         return &socket_if;
140 }