system/core
Revision | adbd6c30a6e37938e5c0f3b0699f4a5990209f13 (tree) |
---|---|
Zeit | 2010-02-27 16:12:49 |
Autor | Chih-Wei Huang <cwhuang@linu...> |
Commiter | Chih-Wei Huang |
hotplug.c: handle add bluetooth rfkill events
Change the permission and owner of state to be bluetooth service accessible.
@@ -1,7 +1,7 @@ | ||
1 | 1 | /* |
2 | 2 | * Simple hotplug tool |
3 | 3 | * |
4 | - * by Chih-Wei Huang <cwhuang@linux.org.tw> 2009/08/03 | |
4 | + * by Chih-Wei Huang <cwhuang@linux.org.tw> 2009/11/06 | |
5 | 5 | * |
6 | 6 | */ |
7 | 7 |
@@ -12,6 +12,8 @@ | ||
12 | 12 | #include <sys/stat.h> |
13 | 13 | #include <unistd.h> |
14 | 14 | |
15 | +#include "private/android_filesystem_config.h" | |
16 | + | |
15 | 17 | #define HOTPLUG_LOG "/tmp/hotplug.log" |
16 | 18 | #define FIRMWARE_PATH "/system/lib/firmware" |
17 | 19 |
@@ -46,8 +48,7 @@ static int load_firmware() | ||
46 | 48 | goto clean3; |
47 | 49 | } |
48 | 50 | } |
49 | - if (write(loading_fd, "0", 1) == 1) | |
50 | - ret = 0; | |
51 | + ret = !(write(loading_fd, "0", 1) == 1); | |
51 | 52 | |
52 | 53 | clean3: |
53 | 54 | close(data_fd); |
@@ -59,6 +60,25 @@ static int load_firmware() | ||
59 | 60 | return ret; |
60 | 61 | } |
61 | 62 | |
63 | +static int set_rfkill() | |
64 | +{ | |
65 | + int ret = -1; | |
66 | + if (strcmp(getenv("RFKILL_TYPE"), "bluetooth") == 0) { | |
67 | + chdir("/sys"); | |
68 | + chdir(getenv("DEVPATH") + 1); | |
69 | + ret = chown("state", AID_BLUETOOTH, AID_BLUETOOTH); | |
70 | + ret |= chmod("state", S_IRUSR|S_IRGRP|S_IWUSR|S_IWGRP); | |
71 | +#if 0 /* we may not need the hack */ | |
72 | + if (!strncmp(getenv("RFKILL_NAME"), "hci", 3) && !strcmp(getenv("RFKILL_STATE"), "0")) { | |
73 | + int fd = open("state", O_WRONLY); | |
74 | + if (fd >= 0) | |
75 | + ret |= !(write(fd, "1", 1) == 1); | |
76 | + } | |
77 | +#endif | |
78 | + } | |
79 | + return ret; | |
80 | +} | |
81 | + | |
62 | 82 | int hotplug_main(int argc, char **argv) |
63 | 83 | { |
64 | 84 | int ret = -1; |
@@ -88,6 +108,8 @@ int hotplug_main(int argc, char **argv) | ||
88 | 108 | if (strcmp(action, "add") == 0) { |
89 | 109 | if (strcmp(argv[1], "firmware") == 0) |
90 | 110 | ret = load_firmware(); |
111 | + else if (strcmp(argv[1], "rfkill") == 0) | |
112 | + ret = set_rfkill(); | |
91 | 113 | } |
92 | 114 | } |
93 | 115 | return ret; |