3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2013 Intel Corporation. All rights reserved.
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
28 #include <sys/socket.h>
31 #define PROPERTY_VALUE_MAX 32
32 #define PROPERTY_KEY_MAX 32
34 #define BLUETOOTH_MODE_PROPERTY_NAME "persist.sys.bluetooth.mode"
35 #define BLUETOOTH_MODE_PROPERTY_HANDSFREE "persist.sys.bluetooth.handsfree"
37 static inline int property_get(const char *key, char *value,
38 const char *default_value)
40 const char *prop = NULL;
42 if (!strcmp(key, BLUETOOTH_MODE_PROPERTY_NAME))
43 prop = getenv("BLUETOOTH_MODE");
45 if (!strcmp(key, BLUETOOTH_MODE_PROPERTY_HANDSFREE))
46 prop = getenv("BLUETOOTH_HANDSFREE_MODE");
52 strncpy(value, prop, PROPERTY_VALUE_MAX);
54 value[PROPERTY_VALUE_MAX - 1] = '\0';
62 /* property_set: returns 0 on success, < 0 on failure
64 static inline int property_set(const char *key, const char *value)
66 static const char SYSTEM_SOCKET_PATH[] = "\0android_system";
68 struct sockaddr_un addr;
72 fd = socket(PF_LOCAL, SOCK_DGRAM, 0);
76 memset(&addr, 0, sizeof(addr));
77 addr.sun_family = AF_UNIX;
78 memcpy(addr.sun_path, SYSTEM_SOCKET_PATH, sizeof(SYSTEM_SOCKET_PATH));
80 if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
85 len = snprintf(msg, sizeof(msg), "%s=%s", key, value);
87 if (send(fd, msg, len + 1, 0) < 0) {