3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2011-2012 Intel Corporation
6 * Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
33 #include <sys/socket.h>
36 #include "src/shared/mainloop.h"
37 #include "src/shared/hfp.h"
39 static void hfp_debug(const char *str, void *user_data)
41 const char *prefix = user_data;
43 printf("%s%s\n", prefix, str);
46 static void command_handler(const char *command, void *user_data)
48 struct hfp_gw *hfp = user_data;
50 printf("Command: %s\n", command);
52 hfp_gw_send_result(hfp, HFP_RESULT_ERROR);
55 static bool open_connection(void)
57 static const char SOCKET_PATH[] = "\0hfp-headset";
59 struct sockaddr_un addr;
62 fd = socket(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
64 perror("Failed to create Unix socket");
68 memset(&addr, 0, sizeof(addr));
69 addr.sun_family = AF_UNIX;
70 memcpy(addr.sun_path, SOCKET_PATH, sizeof(SOCKET_PATH));
72 if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
73 perror("Failed to connect Unix socket");
84 hfp_gw_set_close_on_unref(hfp, true);
86 hfp_gw_set_debug(hfp, hfp_debug, "HFP: ", NULL);
88 hfp_gw_set_command_handler(hfp, command_handler, hfp, NULL);
93 static void signal_callback(int signum, void *user_data)
103 int main(int argc, char *argv[])
110 sigaddset(&mask, SIGINT);
111 sigaddset(&mask, SIGTERM);
113 mainloop_set_signal(&mask, signal_callback, NULL, NULL);
115 if (!open_connection())
118 return mainloop_run();