3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
28 /* This table contains the string representation for messages types */
29 static const char *strtypes[] = {
36 /* This table contains the string representation for messages names */
37 static const char *strnames[] = {
38 "BT_GET_CAPABILITIES",
40 "BT_SET_CONFIGURATION",
49 int bt_audio_service_open(void)
53 struct sockaddr_un addr = {
54 AF_UNIX, BT_IPC_SOCKET_NAME
57 sk = socket(PF_LOCAL, SOCK_STREAM, 0);
60 fprintf(stderr, "%s: Cannot open socket: %s (%d)\n",
61 __FUNCTION__, strerror(-err), -err);
66 if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
68 fprintf(stderr, "%s: connect() failed: %s (%d)\n",
69 __FUNCTION__, strerror(-err), -err);
78 int bt_audio_service_close(int sk)
83 int bt_audio_service_get_data_fd(int sk)
85 char cmsg_b[CMSG_SPACE(sizeof(int))], m;
87 struct iovec iov = { &m, sizeof(m) };
91 memset(&msgh, 0, sizeof(msgh));
94 msgh.msg_control = &cmsg_b;
95 msgh.msg_controllen = CMSG_LEN(sizeof(int));
97 ret = recvmsg(sk, &msgh, 0);
100 fprintf(stderr, "%s: Unable to receive fd: %s (%d)\n",
101 __FUNCTION__, strerror(-err), -err);
106 /* Receive auxiliary data in msgh */
107 for (cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL;
108 cmsg = CMSG_NXTHDR(&msgh, cmsg)) {
109 if (cmsg->cmsg_level == SOL_SOCKET
110 && cmsg->cmsg_type == SCM_RIGHTS) {
111 memcpy(&ret, CMSG_DATA(cmsg), sizeof(int));
120 const char *bt_audio_strtype(uint8_t type)
122 if (type >= ARRAY_SIZE(strtypes))
125 return strtypes[type];
128 const char *bt_audio_strname(uint8_t name)
130 if (name >= ARRAY_SIZE(strnames))
133 return strnames[name];