3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2004-2008 Marcel Holtmann <marcel@holtmann.org>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
27 /* This table contains the string representation for messages types */
28 static const char *strtypes[] = {
35 /* This table contains the string representation for messages names */
36 static const char *strnames[] = {
37 "BT_GET_CAPABILITIES",
38 "BT_SET_CONFIGURATION",
47 int bt_audio_service_open(void)
51 struct sockaddr_un addr = {
52 AF_UNIX, BT_IPC_SOCKET_NAME
55 sk = socket(PF_LOCAL, SOCK_STREAM, 0);
58 fprintf(stderr, "%s: Cannot open socket: %s (%d)\n",
59 __FUNCTION__, strerror(err), err);
64 if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
66 fprintf(stderr, "%s: connect() failed: %s (%d)\n",
67 __FUNCTION__, strerror(err), err);
76 int bt_audio_service_close(int sk)
81 int bt_audio_service_get_data_fd(int sk)
83 char cmsg_b[CMSG_SPACE(sizeof(int))], m;
85 struct iovec iov = { &m, sizeof(m) };
89 memset(&msgh, 0, sizeof(msgh));
92 msgh.msg_control = &cmsg_b;
93 msgh.msg_controllen = CMSG_LEN(sizeof(int));
95 ret = recvmsg(sk, &msgh, 0);
98 fprintf(stderr, "%s: Unable to receive fd: %s (%d)\n",
99 __FUNCTION__, strerror(err), err);
104 /* Receive auxiliary data in msgh */
105 for (cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL;
106 cmsg = CMSG_NXTHDR(&msgh, cmsg)) {
107 if (cmsg->cmsg_level == SOL_SOCKET
108 && cmsg->cmsg_type == SCM_RIGHTS)
109 return (*(int *) CMSG_DATA(cmsg));
116 const char *bt_audio_strtype(uint8_t type)
118 if (type >= ARRAY_SIZE(strtypes))
121 return strtypes[type];
124 const char *bt_audio_strname(uint8_t name)
126 if (name >= ARRAY_SIZE(strnames))
129 return strnames[name];