3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2004-2009 Marcel Holtmann <marcel@holtmann.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program 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
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <private/android_filesystem_config.h>
25 #include <sys/prctl.h>
26 #include <linux/capability.h>
28 /* Set UID to bluetooth w/ CAP_NET_RAW, CAP_NET_ADMIN and CAP_NET_BIND_SERVICE
29 * (Android's init.rc does not yet support applying linux capabilities) */
30 void android_set_aid_and_cap() {
31 prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
32 setuid(AID_BLUETOOTH);
34 struct __user_cap_header_struct header;
35 struct __user_cap_data_struct cap;
36 header.version = _LINUX_CAPABILITY_VERSION;
38 cap.effective = cap.permitted = 1 << CAP_NET_RAW |
40 1 << CAP_NET_BIND_SERVICE;
42 capset(&header, &cap);