./src/bt-hal-tds.c
./src/bt-hal-tds-dbus-handler.c
./src/bt-hal-l2cap-le-dbus-handler.c
+./src/bt-hal-socket-common.c
)
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
#include "bt-hal-l2cap-le-dbus-handler.h"
#include "bt-hal-dbus-common-utils.h"
+#include "bt-hal-socket-common.h"
#define BT_HAL_L2CAP_LE_ID_MAX 245
#define BT_HAL_L2CAP_LE_MAX_BUFFER_SIZE 1024
return NULL;
}
-static int __send_sock_fd(int sock_fd, const void *buf, int size, int send_fd)
-{
- ssize_t ret;
- struct msghdr msg;
- struct cmsghdr *cmsg;
- struct iovec iov;
- char cmsg_buf[CMSG_SPACE(sizeof(int))];
- char err_msg[256] = {0, };
-
- if (sock_fd == -1 || send_fd == -1)
- return -1;
-
- memset(&msg, 0, sizeof(msg));
- memset(cmsg_buf, 0, sizeof(cmsg_buf));
-
- msg.msg_control = cmsg_buf;
- msg.msg_controllen = sizeof(cmsg_buf);
-
- cmsg = CMSG_FIRSTHDR(&msg);
- cmsg->cmsg_level = SOL_SOCKET;
- cmsg->cmsg_type = SCM_RIGHTS;
- cmsg->cmsg_len = CMSG_LEN(sizeof(send_fd));
-
- memcpy(CMSG_DATA(cmsg), &send_fd, sizeof(send_fd));
-
- iov.iov_base = (unsigned char *) buf;
- iov.iov_len = size;
-
- msg.msg_iov = &iov;
- msg.msg_iovlen = 1;
-
- ret = sendmsg(sock_fd, &msg, MSG_NOSIGNAL);
- if (ret < 0) {
- strerror_r(errno, err_msg, sizeof(err_msg));
- ERR("sendmsg(): sock_fd %d send_fd %d: %s",
- sock_fd, send_fd, err_msg);
- }
-
- return ret;
-}
static int __new_server_connection(const char *path, int fd, bt_bdaddr_t *addr)
{
ev.size = sizeof(ev);
memcpy(ev.bdaddr, addr->address, 6);
ev.status = BT_STATUS_SUCCESS;
- ret = __send_sock_fd(info->server_fd, (void *)&ev, sizeof(ev), fd);
+ ret = _bt_hal_send_sock_fd(info->server_fd, (void *)&ev, sizeof(ev), fd);
if (ret < 0) {
ERR("Error sending connect event");
close(fd);
#include "bt-hal-rfcomm-dbus-handler.h"
#include "bt-hal-dbus-common-utils.h"
+#include "bt-hal-socket-common.h"
#define BT_HAL_RFCOMM_ID_MAX 245
#define BT_HAL_RFCOMM_MAX_BUFFER_SIZE 1024
return NULL;
}
-static int __send_sock_fd(int sock_fd, const void *buf, int size, int send_fd)
-{
- ssize_t ret;
- struct msghdr msg;
- struct cmsghdr *cmsg;
- struct iovec iov;
- char cmsg_buf[CMSG_SPACE(sizeof(int))];
- char err_msg[256] = {0, };
-
- if (sock_fd == -1 || send_fd == -1)
- return -1;
-
- memset(&msg, 0, sizeof(msg));
- memset(cmsg_buf, 0, sizeof(cmsg_buf));
-
- msg.msg_control = cmsg_buf;
- msg.msg_controllen = sizeof(cmsg_buf);
-
- cmsg = CMSG_FIRSTHDR(&msg);
- cmsg->cmsg_level = SOL_SOCKET;
- cmsg->cmsg_type = SCM_RIGHTS;
- cmsg->cmsg_len = CMSG_LEN(sizeof(send_fd));
-
- memcpy(CMSG_DATA(cmsg), &send_fd, sizeof(send_fd));
-
- iov.iov_base = (unsigned char *) buf;
- iov.iov_len = size;
-
- msg.msg_iov = &iov;
- msg.msg_iovlen = 1;
-
- ret = sendmsg(sock_fd, &msg, MSG_NOSIGNAL);
- if (ret < 0) {
- strerror_r(errno, err_msg, sizeof(err_msg));
- ERR("sendmsg(): sock_fd %d send_fd %d: %s",
- sock_fd, send_fd, err_msg);
- }
-
- return ret;
-}
-
int __new_server_connection(const char *path, int fd, bt_bdaddr_t *addr)
{
int ret;
ev.size = sizeof(ev);
memcpy(ev.bdaddr, addr->address, 6);
ev.status = BT_STATUS_SUCCESS;
- ret = __send_sock_fd(info->server_fd, (void *)&ev, sizeof(ev), fd);
+ ret = _bt_hal_send_sock_fd(info->server_fd, (void *)&ev, sizeof(ev), fd);
if (ret < 0) {
ERR("Error sending connect event");
close(fd);
--- /dev/null
+/*
+ * Bluetooth-frwk
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <sys/socket.h>
+
+#include <dlog.h>
+
+#include "bt-hal-socket-common.h"
+
+int _bt_hal_send_sock_fd(int sock_fd, const void *buf, int size, int send_fd)
+{
+ ssize_t ret;
+ struct msghdr msg;
+ struct cmsghdr *cmsg;
+ struct iovec iov;
+ char cmsg_buf[CMSG_SPACE(sizeof(int))];
+ char err_msg[256] = {0, };
+
+ if (sock_fd == -1 || send_fd == -1)
+ return -1;
+
+ memset(&msg, 0, sizeof(msg));
+ memset(cmsg_buf, 0, sizeof(cmsg_buf));
+
+ msg.msg_control = cmsg_buf;
+ msg.msg_controllen = sizeof(cmsg_buf);
+
+ cmsg = CMSG_FIRSTHDR(&msg);
+ cmsg->cmsg_level = SOL_SOCKET;
+ cmsg->cmsg_type = SCM_RIGHTS;
+ cmsg->cmsg_len = CMSG_LEN(sizeof(send_fd));
+
+ memcpy(CMSG_DATA(cmsg), &send_fd, sizeof(send_fd));
+
+ iov.iov_base = (unsigned char *) buf;
+ iov.iov_len = size;
+
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+
+ ret = sendmsg(sock_fd, &msg, MSG_NOSIGNAL);
+ if (ret < 0) {
+ strerror_r(errno, err_msg, sizeof(err_msg));
+ ERR("sendmsg(): sock_fd %d send_fd %d: %s",
+ sock_fd, send_fd, err_msg);
+ }
+
+ return ret;
+}
--- /dev/null
+/* Bluetooth-frwk
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+#ifndef _BT_HAL_SOCKET_COMMON_H_
+#define _BT_HAL_SOCKET_COMMON_H_
+
+#include <glib.h>
+#include <sys/types.h>
+
+#include "bt-hal.h"
+#include "bt-hal-log.h"
+#include "bt-hal-msg.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int _bt_hal_send_sock_fd(int sock_fd, const void *buf, int size, int send_fd);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* _BT_HAL_SOCKET_COMMON_H_ */