├── .classpath
├── .project
├── .settings
└── org.eclipse.jdt.core.prefs
├── AndroidManifest.xml
├── GPLV3.TXT
├── README.TXT
├── jni
├── Android.mk
├── com_googlecode_android_wifi_tether_system_NativeTask.c
└── com_googlecode_android_wifi_tether_system_NativeTask.h
├── libs
├── android-support-v4.jar
└── armeabi
│ └── libwtnativetask.so
├── lint.xml
├── native
├── ifconfig
│ ├── Android.mk
│ └── ifconfig.c
├── rfkill
│ ├── Android.mk
│ ├── COPYING
│ ├── README
│ ├── core.h
│ ├── rfkill.c
│ └── rfkill.h
└── tether
│ ├── Android.mk
│ ├── edify
│ ├── Android.mk
│ ├── README
│ ├── expr.c
│ ├── expr.h
│ ├── lexer.l
│ ├── main.c
│ ├── parser.y
│ └── yydefs.h
│ ├── install.c
│ ├── install.h
│ ├── sha1.c
│ ├── sha1.h
│ ├── tether.c
│ └── tether.h
├── project.properties
├── res
├── drawable-hdpi
│ ├── appwidget_bg.9.png
│ ├── appwidget_divider.9.png
│ ├── appwidget_ind_mid_c.9.png
│ ├── appwidget_ind_off_c.9.png
│ ├── appwidget_ind_on_c.9.png
│ ├── appwidget_inner_focus_c.9.png
│ ├── appwidget_inner_press_c.9.png
│ ├── icon.png
│ ├── tether_wifi_off.png
│ └── tether_wifi_on.png
├── drawable-mdpi
│ ├── appwidget_bg.9.png
│ ├── appwidget_divider.9.png
│ ├── appwidget_ind_mid_c.9.png
│ ├── appwidget_ind_off_c.9.png
│ ├── appwidget_ind_on_c.9.png
│ ├── appwidget_inner_focus_c.9.png
│ ├── appwidget_inner_press_c.9.png
│ ├── icon.png
│ ├── tether_wifi_off.png
│ └── tether_wifi_on.png
├── drawable
│ ├── appwidget_button.xml
│ ├── background.9.png
│ ├── battery.png
│ ├── sechigh.png
│ ├── seclow.png
│ ├── secmedium.png
│ ├── start.png
│ ├── start_notification.png
│ ├── stop.png
│ ├── stop_notification.png
│ ├── tether_start_button.xml
│ └── tether_stop_button.xml
├── layout
│ ├── aboutview.xml
│ ├── accesscontrolview.xml
│ ├── clientrow.xml
│ ├── donateview.xml
│ ├── hidessidwarningview.xml
│ ├── logview.xml
│ ├── main.xml
│ ├── noaccesscontrolview.xml
│ ├── nonetfilterview.xml
│ ├── norootview.xml
│ ├── setupview.xml
│ ├── txpowerwarningview.xml
│ ├── updateview.xml
│ └── widget.xml
├── raw
│ ├── dnsmasq
│ ├── fixpersist_sh
│ ├── hostapd_conf_droi
│ ├── hostapd_conf_mini
│ ├── hostapd_conf_tiap
│ ├── ifconfig
│ ├── iptables
│ ├── iwconfig
│ ├── rfkill
│ ├── tether
│ ├── tether_edify
│ ├── tiwlan_ini
│ └── wpa_supplicant_conf
├── values-de
│ └── strings.xml
├── values-it
│ └── strings.xml
├── values-v11
│ └── themes.xml
├── values-zh-rCN
│ └── strings.xml
├── values
│ ├── colors.xml
│ ├── strings.xml
│ └── themes.xml
└── xml
│ └── appwidget_info.xml
└── src
└── com
└── googlecode
└── android
└── wifi
└── tether
├── AccessControlActivity.java
├── LogActivity.java
├── MainActivity.java
├── SetupActivity.java
├── TetherApplication.java
├── TetherService.java
├── TetherServiceReceiver.java
├── TetherWidget.java
├── WifiStateChangeReceiver.java
├── data
├── ClientAdapter.java
└── ClientData.java
├── system
├── Configuration.java
├── CoreTask.java
├── FallbackTether.java
├── NativeTask.java
├── ServiceHandler.java
├── UntetherHelper.java
├── WebserviceTask.java
└── WimaxHelper.java
└── ui
└── SeekBarPreference.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | andTether
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | #Wed Jan 18 21:54:36 CET 2012
2 | eclipse.preferences.version=1
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
4 | org.eclipse.jdt.core.compiler.compliance=1.5
5 | org.eclipse.jdt.core.compiler.source=1.5
6 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
28 |
29 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/README.TXT:
--------------------------------------------------------------------------------
1 | WiFi Tether for Root Users
2 | --------------------------
3 |
4 | WiFi Tether for Root Users
5 |
6 | *** Use this application at your own risk. It is possible that use of this program may violate your carrier's Terms of Use/Terms of Service. ***
7 |
8 | This program enables wifi-tethering for "rooted" handsets.
9 |
10 | Clients (your laptop for example) can connect via wifi and get access to the internet using the mobile connection (4G, 3G, 2G) of your phone.
11 |
12 | Wifi-tethering creates a so called adhoc (peer-to-peer) network on most devices.
13 | Infrastructure-mode is supported for a large set of devices.
14 |
15 | ** PREREQUISITE **
16 |
17 | 1) Root
18 | 2) Netfilter-enabled kernel (most stock-kernel nowadays come with such a kernel).
19 |
--------------------------------------------------------------------------------
/jni/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH := $(call my-dir)
2 | include $(CLEAR_VARS)
3 |
4 | LOCAL_MODULE := libwtnativetask
5 | LOCAL_SRC_FILES := com_googlecode_android_wifi_tether_system_NativeTask.c
6 | #LOCAL_SHARED_LIBRARIES := libcutils
7 |
8 | include $(BUILD_SHARED_LIBRARY)
9 |
--------------------------------------------------------------------------------
/jni/com_googlecode_android_wifi_tether_system_NativeTask.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | #include "com_googlecode_android_wifi_tether_system_NativeTask.h"
8 |
9 | #define PROPERTY_KEY_MAX 32
10 | #define PROPERTY_VALUE_MAX 92
11 |
12 | JNIEXPORT jstring JNICALL Java_com_googlecode_android_wifi_tether_system_NativeTask_getProp
13 | (JNIEnv *env, jclass class, jstring name)
14 | {
15 | const char *nameString;
16 | nameString = (*env)->GetStringUTFChars(env, name, 0);
17 |
18 | char value[PROPERTY_VALUE_MAX];
19 | char *default_value;
20 | jstring jstrOutput;
21 |
22 | default_value = "undefined";
23 | property_get(nameString, value, default_value);
24 |
25 | jstrOutput = (*env)->NewStringUTF(env, value);
26 |
27 | (*env)->ReleaseStringUTFChars(env, name, nameString);
28 |
29 | return jstrOutput;
30 | }
31 |
32 | JNIEXPORT jint JNICALL Java_com_googlecode_android_wifi_tether_system_NativeTask_runCommand
33 | (JNIEnv *env, jclass class, jstring command)
34 | {
35 | const char *commandString;
36 | commandString = (*env)->GetStringUTFChars(env, command, 0);
37 | int exitcode = system(commandString);
38 | (*env)->ReleaseStringUTFChars(env, command, commandString);
39 | return (jint)exitcode;
40 | }
41 |
42 | int property_get(const char *key, char *value, const char *default_value)
43 | {
44 | int len;
45 |
46 | len = __system_property_get(key, value);
47 | if(len > 0) {
48 | return len;
49 | }
50 |
51 | if(default_value) {
52 | len = strlen(default_value);
53 | memcpy(value, default_value, len + 1);
54 | }
55 | return len;
56 | }
57 |
--------------------------------------------------------------------------------
/jni/com_googlecode_android_wifi_tether_system_NativeTask.h:
--------------------------------------------------------------------------------
1 | /* DO NOT EDIT THIS FILE - it is machine generated */
2 | #include
3 | /* Header for class com_googlecode_android_wifi_tether_system_NativeTask */
4 |
5 | #ifndef _Included_com_googlecode_android_wifi_tether_system_NativeTask
6 | #define _Included_com_googlecode_android_wifi_tether_system_NativeTask
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 | /*
11 | * Class: com_googlecode_android_wifi_tether_system_NativeTask
12 | * Method: getProp
13 | * Signature: (Ljava/lang/String;)Ljava/lang/String;
14 | */
15 | JNIEXPORT jstring JNICALL Java_com_googlecode_android_wifi_tether_system_NativeTask_getProp
16 | (JNIEnv *, jclass, jstring);
17 |
18 | /*
19 | * Class: com_googlecode_android_wifi_tether_system_NativeTask
20 | * Method: runCommand
21 | * Signature: (Ljava/lang/String;)I
22 | */
23 | JNIEXPORT jint JNICALL Java_com_googlecode_android_wifi_tether_system_NativeTask_runCommand
24 | (JNIEnv *, jclass, jstring);
25 |
26 | #ifdef __cplusplus
27 | }
28 | #endif
29 | #endif
30 |
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/libs/armeabi/libwtnativetask.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/libs/armeabi/libwtnativetask.so
--------------------------------------------------------------------------------
/lint.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/native/ifconfig/Android.mk:
--------------------------------------------------------------------------------
1 | ifneq ($(TARGET_SIMULATOR),true)
2 |
3 | LOCAL_PATH:= $(call my-dir)
4 |
5 | include $(CLEAR_VARS)
6 | LOCAL_SRC_FILES:= ifconfig.c
7 | LOCAL_MODULE := ifconfig-tether
8 |
9 | #LOCAL_SHARED_LIBRARIES := libcutils
10 |
11 | include $(BUILD_EXECUTABLE)
12 |
13 | endif # TARGET_SIMULATOR != true
14 |
--------------------------------------------------------------------------------
/native/rfkill/Android.mk:
--------------------------------------------------------------------------------
1 | ifneq ($(TARGET_SIMULATOR),true)
2 |
3 | LOCAL_PATH:= $(call my-dir)
4 |
5 | include $(CLEAR_VARS)
6 | LOCAL_SRC_FILES:= rfkill.c
7 | LOCAL_MODULE := rfkill
8 |
9 | #LOCAL_SHARED_LIBRARIES := libcutils
10 |
11 | include $(BUILD_EXECUTABLE)
12 |
13 | LOCAL_MODULE_TAGS := optional
14 |
15 | endif # TARGET_SIMULATOR != true
16 |
--------------------------------------------------------------------------------
/native/rfkill/COPYING:
--------------------------------------------------------------------------------
1 | Copyright 2009 Johannes Berg
2 | Copyright 2009 Marcel Holtmann
3 | Copyright 2009 Tim Gardner
4 |
5 | Permission to use, copy, modify, and/or distribute this software for any
6 | purpose with or without fee is hereby granted, provided that the above
7 | copyright notice and this permission notice appear in all copies.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 |
--------------------------------------------------------------------------------
/native/rfkill/README:
--------------------------------------------------------------------------------
1 |
2 | This is 'rfkill', a tool to use /dev/rfkill.
3 |
4 |
5 | To build rfkill, just enter 'make'.
6 |
7 | 'rfkill' is currently maintained at http://git.sipsolutions.net/rfkill.git/,
8 | some more documentation is available at
9 | http://wireless.kernel.org/en/users/Documentation/rfkill.
10 |
11 | Please send all patches to Johannes Berg
12 | and CC linux-wireless@vger.kernel.org for community review.
13 |
--------------------------------------------------------------------------------
/native/rfkill/core.h:
--------------------------------------------------------------------------------
1 | #ifndef __CORE
2 | #define __CORE
3 |
4 | #include "rfkill.h"
5 |
6 | extern const char rfkill_version[];
7 |
8 | #endif
9 |
--------------------------------------------------------------------------------
/native/rfkill/rfkill.c:
--------------------------------------------------------------------------------
1 | /*
2 | * rfkill userspace tool
3 | */
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 |
17 | #include "rfkill.h"
18 | #include "core.h"
19 |
20 | static void rfkill_event(void)
21 | {
22 | struct rfkill_event event;
23 | struct timeval tv;
24 | struct pollfd p;
25 | ssize_t len;
26 | int fd, n;
27 |
28 | fd = open("/dev/rfkill", O_RDONLY);
29 | if (fd < 0) {
30 | perror("Can't open RFKILL control device");
31 | return;
32 | }
33 |
34 | memset(&p, 0, sizeof(p));
35 | p.fd = fd;
36 | p.events = POLLIN | POLLHUP;
37 |
38 | while (1) {
39 | n = poll(&p, 1, -1);
40 | if (n < 0) {
41 | perror("Failed to poll RFKILL control device");
42 | break;
43 | }
44 |
45 | if (n == 0)
46 | continue;
47 |
48 | len = read(fd, &event, sizeof(event));
49 | if (len < 0) {
50 | perror("Reading of RFKILL events failed");
51 | break;
52 | }
53 |
54 | if (len != RFKILL_EVENT_SIZE_V1) {
55 | fprintf(stderr, "Wrong size of RFKILL event\n");
56 | continue;
57 | }
58 |
59 | gettimeofday(&tv, NULL);
60 | printf("%ld.%06u: idx %u type %u op %u soft %u hard %u\n",
61 | (long) tv.tv_sec, (unsigned int) tv.tv_usec,
62 | event.idx, event.type, event.op, event.soft, event.hard);
63 | fflush(stdout);
64 | }
65 |
66 | close(fd);
67 | }
68 |
69 | static const char *get_name(__u32 idx)
70 | {
71 | static char name[128];
72 | ssize_t len;
73 | char *pos, filename[64];
74 | int fd;
75 |
76 | snprintf(filename, sizeof(filename) - 1,
77 | "/sys/class/rfkill/rfkill%u/name", idx);
78 |
79 | fd = open(filename, O_RDONLY);
80 | if (fd < 0)
81 | return NULL;
82 |
83 | memset(name, 0, sizeof(name));
84 | len = read(fd, name, sizeof(name) - 1);
85 |
86 | pos = strchr(name, '\n');
87 | if (pos)
88 | *pos = '\0';
89 |
90 | close(fd);
91 |
92 | return name;
93 | }
94 |
95 | static const char *type2string(enum rfkill_type type)
96 | {
97 | switch (type) {
98 | case RFKILL_TYPE_ALL:
99 | return "All";
100 | case RFKILL_TYPE_WLAN:
101 | return "Wireless LAN";
102 | case RFKILL_TYPE_BLUETOOTH:
103 | return "Bluetooth";
104 | case RFKILL_TYPE_UWB:
105 | return "Ultra-Wideband";
106 | case RFKILL_TYPE_WIMAX:
107 | return "WiMAX";
108 | case RFKILL_TYPE_WWAN:
109 | return "Wireless WAN";
110 | case RFKILL_TYPE_GPS:
111 | return "GPS";
112 | case RFKILL_TYPE_FM:
113 | return "FM";
114 | case NUM_RFKILL_TYPES:
115 | return NULL;
116 | }
117 |
118 | return NULL;
119 | }
120 |
121 | struct rfkill_type_str {
122 | enum rfkill_type type;
123 | const char *name;
124 | };
125 | static const struct rfkill_type_str rfkill_type_strings[] = {
126 | { .type = RFKILL_TYPE_ALL, .name = "all" },
127 | { .type = RFKILL_TYPE_WLAN, .name = "wifi" },
128 | { .type = RFKILL_TYPE_WLAN, .name = "wlan" }, /* alias */
129 | { .type = RFKILL_TYPE_BLUETOOTH, .name = "bluetooth" },
130 | { .type = RFKILL_TYPE_UWB, .name = "uwb" },
131 | { .type = RFKILL_TYPE_UWB, .name = "ultrawideband" }, /* alias */
132 | { .type = RFKILL_TYPE_WIMAX, .name = "wimax" },
133 | { .type = RFKILL_TYPE_WWAN, .name = "wwan" },
134 | { .type = RFKILL_TYPE_GPS, .name = "gps" },
135 | { .type = RFKILL_TYPE_FM, .name = "fm" },
136 | { .name = NULL }
137 | };
138 |
139 | struct rfkill_id {
140 | union {
141 | enum rfkill_type type;
142 | __u32 index;
143 | };
144 | enum {
145 | RFKILL_IS_INVALID,
146 | RFKILL_IS_TYPE,
147 | RFKILL_IS_INDEX,
148 | } result;
149 | };
150 |
151 | static struct rfkill_id rfkill_id_to_type(const char *s)
152 | {
153 | const struct rfkill_type_str *p;
154 | struct rfkill_id ret;
155 |
156 | if (islower(*s)) {
157 | for (p = rfkill_type_strings; p->name != NULL; p++) {
158 | if ((strlen(s) == strlen(p->name)) && (!strcmp(s,p->name))) {
159 | ret.type = p->type;
160 | ret.result = RFKILL_IS_TYPE;
161 | return ret;
162 | }
163 | }
164 | } else if (isdigit(*s)) {
165 | /* assume a numeric character implies an index. */
166 | ret.index = atoi(s);
167 | ret.result = RFKILL_IS_INDEX;
168 | return ret;
169 | }
170 |
171 | ret.result = RFKILL_IS_INVALID;
172 | return ret;
173 | }
174 |
175 | static int rfkill_list(const char *param)
176 | {
177 | struct rfkill_id id = { .result = RFKILL_IS_INVALID };
178 | struct rfkill_event event;
179 | const char *name;
180 | ssize_t len;
181 | int fd;
182 |
183 | if (param) {
184 | id = rfkill_id_to_type(param);
185 | if (id.result == RFKILL_IS_INVALID) {
186 | fprintf(stderr, "Bogus %s argument '%s'.\n", "list", param);
187 | return 2;
188 | }
189 | /* don't filter "all" */
190 | if (id.result == RFKILL_IS_TYPE && id.type == RFKILL_TYPE_ALL)
191 | id.result = RFKILL_IS_INVALID;
192 | }
193 |
194 | fd = open("/dev/rfkill", O_RDONLY);
195 | if (fd < 0) {
196 | perror("Can't open RFKILL control device");
197 | return 1;
198 | }
199 |
200 | if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
201 | perror("Can't set RFKILL control device to non-blocking");
202 | close(fd);
203 | return 1;
204 | }
205 |
206 | while (1) {
207 | len = read(fd, &event, sizeof(event));
208 | if (len < 0) {
209 | if (errno == EAGAIN)
210 | break;
211 | perror("Reading of RFKILL events failed");
212 | break;
213 | }
214 |
215 | if (len != RFKILL_EVENT_SIZE_V1) {
216 | fprintf(stderr, "Wrong size of RFKILL event\n");
217 | continue;
218 | }
219 |
220 | if (event.op != RFKILL_OP_ADD)
221 | continue;
222 |
223 | /* filter out unwanted results */
224 | switch (id.result)
225 | {
226 | case RFKILL_IS_TYPE:
227 | if (event.type != id.type)
228 | continue;
229 | break;
230 | case RFKILL_IS_INDEX:
231 | if (event.idx != id.index)
232 | continue;
233 | break;
234 | case RFKILL_IS_INVALID:; /* must be last */
235 | }
236 |
237 | name = get_name(event.idx);
238 |
239 | printf("%u: %s: %s\n", event.idx, name,
240 | type2string(event.type));
241 | printf("\tSoft blocked: %s\n", event.soft ? "yes" : "no");
242 | printf("\tHard blocked: %s\n", event.hard ? "yes" : "no");
243 | }
244 |
245 | close(fd);
246 | return 0;
247 | }
248 |
249 | static int rfkill_block(__u8 block, const char *param)
250 | {
251 | struct rfkill_id id;
252 | struct rfkill_event event;
253 | ssize_t len;
254 | int fd;
255 |
256 | id = rfkill_id_to_type(param);
257 | if (id.result == RFKILL_IS_INVALID) {
258 | fprintf(stderr, "Bogus %s argument '%s'.\n", block ? "block" : "unblock", param);
259 | return 2;
260 | }
261 |
262 | fd = open("/dev/rfkill", O_RDWR);
263 | if (fd < 0) {
264 | perror("Can't open RFKILL control device");
265 | return 1;
266 | }
267 |
268 | memset(&event, 0, sizeof(event));
269 | switch (id.result) {
270 | case RFKILL_IS_TYPE:
271 | event.op = RFKILL_OP_CHANGE_ALL;
272 | event.type = id.type;
273 | break;
274 | case RFKILL_IS_INDEX:
275 | event.op = RFKILL_OP_CHANGE;
276 | event.idx = id.index;
277 | break;
278 | case RFKILL_IS_INVALID:; /* must be last */
279 | }
280 | event.soft = block;
281 |
282 | len = write(fd, &event, sizeof(event));
283 | if (len < 0)
284 | perror("Failed to change RFKILL state");
285 |
286 | close(fd);
287 | return 0;
288 | }
289 |
290 | static const char *argv0;
291 |
292 | static void usage(void)
293 | {
294 | const struct rfkill_type_str *p;
295 |
296 | fprintf(stderr, "Usage:\t%s [options] command\n", argv0);
297 | fprintf(stderr, "Options:\n");
298 | fprintf(stderr, "Commands:\n");
299 | fprintf(stderr, "\thelp\n");
300 | fprintf(stderr, "\tevent\n");
301 | fprintf(stderr, "\tlist [IDENTIFIER]\n");
302 | fprintf(stderr, "\tblock IDENTIFIER\n");
303 | fprintf(stderr, "\tunblock IDENTIFIER\n");
304 | fprintf(stderr, "where IDENTIFIER is the index no. of an rfkill switch or one of:\n");
305 | fprintf(stderr, "\t");
306 | for (p = rfkill_type_strings; p->name != NULL; p++)
307 | fprintf(stderr, " %s", p->name);
308 | fprintf(stderr, "\n");
309 | }
310 |
311 | /*static void version(void)
312 | {
313 | printf("rfkill %s\n", rfkill_version);
314 | }*/
315 |
316 | int main(int argc, char **argv)
317 | {
318 | int ret = 0;
319 |
320 | /* strip off self */
321 | argc--;
322 | argv0 = *argv++;
323 |
324 | if (argc > 0 && strcmp(*argv, "--version") == 0) {
325 | //version();
326 | return 0;
327 | }
328 |
329 | if (argc == 0 || strcmp(*argv, "help") == 0) {
330 | usage();
331 | return 0;
332 | }
333 |
334 | if (strcmp(*argv, "event") == 0) {
335 | rfkill_event();
336 | } else if (strcmp(*argv, "list") == 0) {
337 | argc--;
338 | argv++;
339 | rfkill_list(*argv); /* NULL is acceptable */
340 | } else if (strcmp(*argv, "block") == 0 && argc > 1) {
341 | argc--;
342 | argv++;
343 | ret = rfkill_block(1,*argv);
344 | } else if (strcmp(*argv, "unblock") == 0 && argc > 1) {
345 | argc--;
346 | argv++;
347 | ret = rfkill_block(0,*argv);
348 | } else {
349 | usage();
350 | return 1;
351 | }
352 |
353 | return ret;
354 | }
355 |
--------------------------------------------------------------------------------
/native/rfkill/rfkill.h:
--------------------------------------------------------------------------------
1 | #ifndef __RFKILL_H
2 | #define __RFKILL_H
3 |
4 | /*
5 | * Copyright (C) 2006 - 2007 Ivo van Doorn
6 | * Copyright (C) 2007 Dmitry Torokhov
7 | * Copyright 2009 Johannes Berg
8 | *
9 | * Permission to use, copy, modify, and/or distribute this software for any
10 | * purpose with or without fee is hereby granted, provided that the above
11 | * copyright notice and this permission notice appear in all copies.
12 | *
13 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 | */
21 |
22 | #include
23 |
24 | /* define userspace visible states */
25 | #define RFKILL_STATE_SOFT_BLOCKED 0
26 | #define RFKILL_STATE_UNBLOCKED 1
27 | #define RFKILL_STATE_HARD_BLOCKED 2
28 |
29 | /**
30 | * enum rfkill_type - type of rfkill switch.
31 | *
32 | * @RFKILL_TYPE_ALL: toggles all switches (userspace only)
33 | * @RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device.
34 | * @RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device.
35 | * @RFKILL_TYPE_UWB: switch is on a ultra wideband device.
36 | * @RFKILL_TYPE_WIMAX: switch is on a WiMAX device.
37 | * @RFKILL_TYPE_WWAN: switch is on a wireless WAN device.
38 | * @RFKILL_TYPE_GPS: switch is on a GPS device.
39 | * @RFKILL_TYPE_FM: switch is on a FM radio device.
40 | * @NUM_RFKILL_TYPES: number of defined rfkill types
41 | */
42 | enum rfkill_type {
43 | RFKILL_TYPE_ALL = 0,
44 | RFKILL_TYPE_WLAN,
45 | RFKILL_TYPE_BLUETOOTH,
46 | RFKILL_TYPE_UWB,
47 | RFKILL_TYPE_WIMAX,
48 | RFKILL_TYPE_WWAN,
49 | RFKILL_TYPE_GPS,
50 | RFKILL_TYPE_FM,
51 | NUM_RFKILL_TYPES,
52 | };
53 |
54 | /**
55 | * enum rfkill_operation - operation types
56 | * @RFKILL_OP_ADD: a device was added
57 | * @RFKILL_OP_DEL: a device was removed
58 | * @RFKILL_OP_CHANGE: a device's state changed -- userspace changes one device
59 | * @RFKILL_OP_CHANGE_ALL: userspace changes all devices (of a type, or all)
60 | */
61 | enum rfkill_operation {
62 | RFKILL_OP_ADD = 0,
63 | RFKILL_OP_DEL,
64 | RFKILL_OP_CHANGE,
65 | RFKILL_OP_CHANGE_ALL,
66 | };
67 |
68 | /**
69 | * struct rfkill_event - events for userspace on /dev/rfkill
70 | * @idx: index of dev rfkill
71 | * @type: type of the rfkill struct
72 | * @op: operation code
73 | * @hard: hard state (0/1)
74 | * @soft: soft state (0/1)
75 | *
76 | * Structure used for userspace communication on /dev/rfkill,
77 | * used for events from the kernel and control to the kernel.
78 | */
79 | struct rfkill_event {
80 | __u32 idx;
81 | __u8 type;
82 | __u8 op;
83 | __u8 soft, hard;
84 | } __packed;
85 |
86 | /*
87 | * We are planning to be backward and forward compatible with changes
88 | * to the event struct, by adding new, optional, members at the end.
89 | * When reading an event (whether the kernel from userspace or vice
90 | * versa) we need to accept anything that's at least as large as the
91 | * version 1 event size, but might be able to accept other sizes in
92 | * the future.
93 | *
94 | * One exception is the kernel -- we already have two event sizes in
95 | * that we've made the 'hard' member optional since our only option
96 | * is to ignore it anyway.
97 | */
98 | #define RFKILL_EVENT_SIZE_V1 8
99 |
100 | /* ioctl for turning off rfkill-input (if present) */
101 | #define RFKILL_IOC_MAGIC 'R'
102 | #define RFKILL_IOC_NOINPUT 1
103 | #define RFKILL_IOCTL_NOINPUT _IO(RFKILL_IOC_MAGIC, RFKILL_IOC_NOINPUT)
104 |
105 | /* and that's all userspace gets */
106 | #ifdef __KERNEL__
107 | /* don't allow anyone to use these in the kernel */
108 | enum rfkill_user_states {
109 | RFKILL_USER_STATE_SOFT_BLOCKED = RFKILL_STATE_SOFT_BLOCKED,
110 | RFKILL_USER_STATE_UNBLOCKED = RFKILL_STATE_UNBLOCKED,
111 | RFKILL_USER_STATE_HARD_BLOCKED = RFKILL_STATE_HARD_BLOCKED,
112 | };
113 | #undef RFKILL_STATE_SOFT_BLOCKED
114 | #undef RFKILL_STATE_UNBLOCKED
115 | #undef RFKILL_STATE_HARD_BLOCKED
116 |
117 | #include
118 | #include
119 | #include
120 | #include
121 | #include
122 | #include
123 |
124 | /* this is opaque */
125 | struct rfkill;
126 |
127 | /**
128 | * struct rfkill_ops - rfkill driver methods
129 | *
130 | * @poll: poll the rfkill block state(s) -- only assign this method
131 | * when you need polling. When called, simply call one of the
132 | * rfkill_set{,_hw,_sw}_state family of functions. If the hw
133 | * is getting unblocked you need to take into account the return
134 | * value of those functions to make sure the software block is
135 | * properly used.
136 | * @query: query the rfkill block state(s) and call exactly one of the
137 | * rfkill_set{,_hw,_sw}_state family of functions. Assign this
138 | * method if input events can cause hardware state changes to make
139 | * the rfkill core query your driver before setting a requested
140 | * block.
141 | * @set_block: turn the transmitter on (blocked == false) or off
142 | * (blocked == true) -- ignore and return 0 when hard blocked.
143 | * This callback must be assigned.
144 | */
145 | struct rfkill_ops {
146 | void (*poll)(struct rfkill *rfkill, void *data);
147 | void (*query)(struct rfkill *rfkill, void *data);
148 | int (*set_block)(void *data, bool blocked);
149 | };
150 |
151 | #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
152 | /**
153 | * rfkill_alloc - allocate rfkill structure
154 | * @name: name of the struct -- the string is not copied internally
155 | * @parent: device that has rf switch on it
156 | * @type: type of the switch (RFKILL_TYPE_*)
157 | * @ops: rfkill methods
158 | * @ops_data: data passed to each method
159 | *
160 | * This function should be called by the transmitter driver to allocate an
161 | * rfkill structure. Returns %NULL on failure.
162 | */
163 | struct rfkill * __must_check rfkill_alloc(const char *name,
164 | struct device *parent,
165 | const enum rfkill_type type,
166 | const struct rfkill_ops *ops,
167 | void *ops_data);
168 |
169 | /**
170 | * rfkill_register - Register a rfkill structure.
171 | * @rfkill: rfkill structure to be registered
172 | *
173 | * This function should be called by the transmitter driver to register
174 | * the rfkill structure. Before calling this function the driver needs
175 | * to be ready to service method calls from rfkill.
176 | *
177 | * If rfkill_init_sw_state() is not called before registration,
178 | * set_block() will be called to initialize the software blocked state
179 | * to a default value.
180 | *
181 | * If the hardware blocked state is not set before registration,
182 | * it is assumed to be unblocked.
183 | */
184 | int __must_check rfkill_register(struct rfkill *rfkill);
185 |
186 | /**
187 | * rfkill_pause_polling(struct rfkill *rfkill)
188 | *
189 | * Pause polling -- say transmitter is off for other reasons.
190 | * NOTE: not necessary for suspend/resume -- in that case the
191 | * core stops polling anyway
192 | */
193 | void rfkill_pause_polling(struct rfkill *rfkill);
194 |
195 | /**
196 | * rfkill_resume_polling(struct rfkill *rfkill)
197 | *
198 | * Pause polling -- say transmitter is off for other reasons.
199 | * NOTE: not necessary for suspend/resume -- in that case the
200 | * core stops polling anyway
201 | */
202 | void rfkill_resume_polling(struct rfkill *rfkill);
203 |
204 |
205 | /**
206 | * rfkill_unregister - Unregister a rfkill structure.
207 | * @rfkill: rfkill structure to be unregistered
208 | *
209 | * This function should be called by the network driver during device
210 | * teardown to destroy rfkill structure. Until it returns, the driver
211 | * needs to be able to service method calls.
212 | */
213 | void rfkill_unregister(struct rfkill *rfkill);
214 |
215 | /**
216 | * rfkill_destroy - free rfkill structure
217 | * @rfkill: rfkill structure to be destroyed
218 | *
219 | * Destroys the rfkill structure.
220 | */
221 | void rfkill_destroy(struct rfkill *rfkill);
222 |
223 | /**
224 | * rfkill_set_hw_state - Set the internal rfkill hardware block state
225 | * @rfkill: pointer to the rfkill class to modify.
226 | * @state: the current hardware block state to set
227 | *
228 | * rfkill drivers that get events when the hard-blocked state changes
229 | * use this function to notify the rfkill core (and through that also
230 | * userspace) of the current state. They should also use this after
231 | * resume if the state could have changed.
232 | *
233 | * You need not (but may) call this function if poll_state is assigned.
234 | *
235 | * This function can be called in any context, even from within rfkill
236 | * callbacks.
237 | *
238 | * The function returns the combined block state (true if transmitter
239 | * should be blocked) so that drivers need not keep track of the soft
240 | * block state -- which they might not be able to.
241 | */
242 | bool rfkill_set_hw_state(struct rfkill *rfkill, bool blocked);
243 |
244 | /**
245 | * rfkill_set_sw_state - Set the internal rfkill software block state
246 | * @rfkill: pointer to the rfkill class to modify.
247 | * @state: the current software block state to set
248 | *
249 | * rfkill drivers that get events when the soft-blocked state changes
250 | * (yes, some platforms directly act on input but allow changing again)
251 | * use this function to notify the rfkill core (and through that also
252 | * userspace) of the current state.
253 | *
254 | * Drivers should also call this function after resume if the state has
255 | * been changed by the user. This only makes sense for "persistent"
256 | * devices (see rfkill_init_sw_state()).
257 | *
258 | * This function can be called in any context, even from within rfkill
259 | * callbacks.
260 | *
261 | * The function returns the combined block state (true if transmitter
262 | * should be blocked).
263 | */
264 | bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked);
265 |
266 | /**
267 | * rfkill_init_sw_state - Initialize persistent software block state
268 | * @rfkill: pointer to the rfkill class to modify.
269 | * @state: the current software block state to set
270 | *
271 | * rfkill drivers that preserve their software block state over power off
272 | * use this function to notify the rfkill core (and through that also
273 | * userspace) of their initial state. It should only be used before
274 | * registration.
275 | *
276 | * In addition, it marks the device as "persistent", an attribute which
277 | * can be read by userspace. Persistent devices are expected to preserve
278 | * their own state when suspended.
279 | */
280 | void rfkill_init_sw_state(struct rfkill *rfkill, bool blocked);
281 |
282 | /**
283 | * rfkill_set_states - Set the internal rfkill block states
284 | * @rfkill: pointer to the rfkill class to modify.
285 | * @sw: the current software block state to set
286 | * @hw: the current hardware block state to set
287 | *
288 | * This function can be called in any context, even from within rfkill
289 | * callbacks.
290 | */
291 | void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw);
292 |
293 | /**
294 | * rfkill_blocked - query rfkill block
295 | *
296 | * @rfkill: rfkill struct to query
297 | */
298 | bool rfkill_blocked(struct rfkill *rfkill);
299 | #else /* !RFKILL */
300 | static inline struct rfkill * __must_check
301 | rfkill_alloc(const char *name,
302 | struct device *parent,
303 | const enum rfkill_type type,
304 | const struct rfkill_ops *ops,
305 | void *ops_data)
306 | {
307 | return ERR_PTR(-ENODEV);
308 | }
309 |
310 | static inline int __must_check rfkill_register(struct rfkill *rfkill)
311 | {
312 | if (rfkill == ERR_PTR(-ENODEV))
313 | return 0;
314 | return -EINVAL;
315 | }
316 |
317 | static inline void rfkill_pause_polling(struct rfkill *rfkill)
318 | {
319 | }
320 |
321 | static inline void rfkill_resume_polling(struct rfkill *rfkill)
322 | {
323 | }
324 |
325 | static inline void rfkill_unregister(struct rfkill *rfkill)
326 | {
327 | }
328 |
329 | static inline void rfkill_destroy(struct rfkill *rfkill)
330 | {
331 | }
332 |
333 | static inline bool rfkill_set_hw_state(struct rfkill *rfkill, bool blocked)
334 | {
335 | return blocked;
336 | }
337 |
338 | static inline bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked)
339 | {
340 | return blocked;
341 | }
342 |
343 | static inline void rfkill_init_sw_state(struct rfkill *rfkill, bool blocked)
344 | {
345 | }
346 |
347 | static inline void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw)
348 | {
349 | }
350 |
351 | static inline bool rfkill_blocked(struct rfkill *rfkill)
352 | {
353 | return false;
354 | }
355 | #endif /* RFKILL || RFKILL_MODULE */
356 |
357 |
358 | #ifdef CONFIG_RFKILL_LEDS
359 | /**
360 | * rfkill_get_led_trigger_name - Get the LED trigger name for the button's LED.
361 | * This function might return a NULL pointer if registering of the
362 | * LED trigger failed. Use this as "default_trigger" for the LED.
363 | */
364 | const char *rfkill_get_led_trigger_name(struct rfkill *rfkill);
365 |
366 | /**
367 | * rfkill_set_led_trigger_name -- set the LED trigger name
368 | * @rfkill: rfkill struct
369 | * @name: LED trigger name
370 | *
371 | * This function sets the LED trigger name of the radio LED
372 | * trigger that rfkill creates. It is optional, but if called
373 | * must be called before rfkill_register() to be effective.
374 | */
375 | void rfkill_set_led_trigger_name(struct rfkill *rfkill, const char *name);
376 | #else
377 | static inline const char *rfkill_get_led_trigger_name(struct rfkill *rfkill)
378 | {
379 | return NULL;
380 | }
381 |
382 | static inline void
383 | rfkill_set_led_trigger_name(struct rfkill *rfkill, const char *name)
384 | {
385 | }
386 | #endif
387 |
388 | #endif /* __KERNEL__ */
389 |
390 | #endif /* RFKILL_H */
391 |
--------------------------------------------------------------------------------
/native/tether/Android.mk:
--------------------------------------------------------------------------------
1 | # Copyright 2009 The Android Open Source Project
2 |
3 | LOCAL_PATH := $(call my-dir)
4 |
5 | updater_src_files := \
6 | sha1.c\
7 | install.c\
8 | tether.c\
9 |
10 | include $(CLEAR_VARS)
11 |
12 | LOCAL_SRC_FILES := $(updater_src_files)
13 |
14 | LOCAL_C_INCLUDES += $(dir $(inc))
15 |
16 | LOCAL_CFLAGS := -DINTERNAL_SHA1 -DCONFIG_CRYPTO_INTERNAL -DCONFIG_NO_T_PRF -DCONFIG_NO_TLS_PRF
17 |
18 | LOCAL_STATIC_LIBRARIES := libedify
19 |
20 | LOCAL_SHARED_LIBRARIES := libcutils\
21 | libhardware_legacy\
22 | libc\
23 | libnetutils\
24 | libsysutils
25 |
26 | LOCAL_MODULE := tether
27 |
28 | include $(BUILD_EXECUTABLE)
29 |
30 | #####################
31 | #include $(CLEAR_VARS)
32 | #LOCAL_SRC_FILES := ultra_bcm_config.c\
33 | # wpa_supplicant/sha1.c\
34 | # wpa_supplicant/md5.c\
35 | # wpa_supplicant/os_unix.c\
36 | # wpa_supplicant/des.c\
37 | # wpa_supplicant/crypto_openssl.c
38 | #LOCAL_C_INCLUDES:= \
39 | # external/openssl/include
40 | #LOCAL_MODULE := ultra_bcm_config
41 | #LOCAL_STATIC_LIBRARIES := iwlib
42 | #LOCAL_SHARED_LIBRARIES := libc libcutils libcrypto libssl
43 | #LOCAL_CFLAGS := $(WT_INCS) $(WT_DEFS)
44 | #include $(BUILD_EXECUTABLE)
45 | #####################
46 |
47 |
48 |
--------------------------------------------------------------------------------
/native/tether/edify/Android.mk:
--------------------------------------------------------------------------------
1 | # Copyright 2009 The Android Open Source Project
2 |
3 | LOCAL_PATH := $(call my-dir)
4 |
5 | edify_src_files := \
6 | lexer.l \
7 | parser.y \
8 | expr.c
9 |
10 | # "-x c" forces the lex/yacc files to be compiled as c;
11 | # the build system otherwise forces them to be c++.
12 | edify_cflags := -x c
13 |
14 | #
15 | # Build the host-side command line tool
16 | #
17 | include $(CLEAR_VARS)
18 |
19 | LOCAL_SRC_FILES := \
20 | $(edify_src_files) \
21 | main.c
22 |
23 | LOCAL_CFLAGS := $(edify_cflags) -g -O0
24 | LOCAL_MODULE := edify
25 | LOCAL_YACCFLAGS := -v
26 |
27 | include $(BUILD_HOST_EXECUTABLE)
28 |
29 | #
30 | # Build the device-side library
31 | #
32 | include $(CLEAR_VARS)
33 |
34 | LOCAL_SRC_FILES := $(edify_src_files)
35 |
36 | LOCAL_CFLAGS := $(edify_cflags)
37 | LOCAL_MODULE := libedify
38 |
39 | include $(BUILD_STATIC_LIBRARY)
40 |
--------------------------------------------------------------------------------
/native/tether/edify/README:
--------------------------------------------------------------------------------
1 | Update scripts (from donut onwards) are written in a new little
2 | scripting language ("edify") that is superficially somewhat similar to
3 | the old one ("amend"). This is a brief overview of the new language.
4 |
5 | - The entire script is a single expression.
6 |
7 | - All expressions are string-valued.
8 |
9 | - String literals appear in double quotes. \n, \t, \", and \\ are
10 | understood, as are hexadecimal escapes like \x4a.
11 |
12 | - String literals consisting of only letters, numbers, colons,
13 | underscores, slashes, and periods don't need to be in double quotes.
14 |
15 | - The following words are reserved:
16 |
17 | if then else endif
18 |
19 | They have special meaning when unquoted. (In quotes, they are just
20 | string literals.)
21 |
22 | - When used as a boolean, the empty string is "false" and all other
23 | strings are "true".
24 |
25 | - All functions are actually macros (in the Lisp sense); the body of
26 | the function can control which (if any) of the arguments are
27 | evaluated. This means that functions can act as control
28 | structures.
29 |
30 | - Operators (like "&&" and "||") are just syntactic sugar for builtin
31 | functions, so they can act as control structures as well.
32 |
33 | - ";" is a binary operator; evaluating it just means to first evaluate
34 | the left side, then the right. It can also appear after any
35 | expression.
36 |
37 | - Comments start with "#" and run to the end of the line.
38 |
39 |
40 |
41 | Some examples:
42 |
43 | - There's no distinction between quoted and unquoted strings; the
44 | quotes are only needed if you want characters like whitespace to
45 | appear in the string. The following expressions all evaluate to the
46 | same string.
47 |
48 | "a b"
49 | a + " " + b
50 | "a" + " " + "b"
51 | "a\x20b"
52 | a + "\x20b"
53 | concat(a, " ", "b")
54 | "concat"(a, " ", "b")
55 |
56 | As shown in the last example, function names are just strings,
57 | too. They must be string *literals*, however. This is not legal:
58 |
59 | ("con" + "cat")(a, " ", b) # syntax error!
60 |
61 |
62 | - The ifelse() builtin takes three arguments: it evaluates exactly
63 | one of the second and third, depending on whether the first one is
64 | true. There is also some syntactic sugar to make expressions that
65 | look like if/else statements:
66 |
67 | # these are all equivalent
68 | ifelse(something(), "yes", "no")
69 | if something() then yes else no endif
70 | if something() then "yes" else "no" endif
71 |
72 | The else part is optional.
73 |
74 | if something() then "yes" endif # if something() is false,
75 | # evaluates to false
76 |
77 | ifelse(condition(), "", abort()) # abort() only called if
78 | # condition() is false
79 |
80 | The last example is equivalent to:
81 |
82 | assert(condition())
83 |
84 |
85 | - The && and || operators can be used similarly; they evaluate their
86 | second argument only if it's needed to determine the truth of the
87 | expression. Their value is the value of the last-evaluated
88 | argument:
89 |
90 | file_exists("/data/system/bad") && delete("/data/system/bad")
91 |
92 | file_exists("/data/system/missing") || create("/data/system/missing")
93 |
94 | get_it() || "xxx" # returns value of get_it() if that value is
95 | # true, otherwise returns "xxx"
96 |
97 |
98 | - The purpose of ";" is to simulate imperative statements, of course,
99 | but the operator can be used anywhere. Its value is the value of
100 | its right side:
101 |
102 | concat(a;b;c, d, e;f) # evaluates to "cdf"
103 |
104 | A more useful example might be something like:
105 |
106 | ifelse(condition(),
107 | (first_step(); second_step();), # second ; is optional
108 | alternative_procedure())
109 |
--------------------------------------------------------------------------------
/native/tether/edify/expr.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 |
24 | #include "expr.h"
25 |
26 | // Functions should:
27 | //
28 | // - return a malloc()'d string
29 | // - if Evaluate() on any argument returns NULL, return NULL.
30 |
31 | int BooleanString(const char* s) {
32 | return s[0] != '\0';
33 | }
34 |
35 | char* Evaluate(State* state, Expr* expr) {
36 | return expr->fn(expr->name, state, expr->argc, expr->argv);
37 | }
38 |
39 | char* ConcatFn(const char* name, State* state, int argc, Expr* argv[]) {
40 | if (argc == 0) {
41 | return strdup("");
42 | }
43 | char** strings = malloc(argc * sizeof(char*));
44 | int i;
45 | for (i = 0; i < argc; ++i) {
46 | strings[i] = NULL;
47 | }
48 | char* result = NULL;
49 | int length = 0;
50 | for (i = 0; i < argc; ++i) {
51 | strings[i] = Evaluate(state, argv[i]);
52 | if (strings[i] == NULL) {
53 | goto done;
54 | }
55 | length += strlen(strings[i]);
56 | }
57 |
58 | result = malloc(length+1);
59 | int p = 0;
60 | for (i = 0; i < argc; ++i) {
61 | strcpy(result+p, strings[i]);
62 | p += strlen(strings[i]);
63 | }
64 | result[p] = '\0';
65 |
66 | done:
67 | for (i = 0; i < argc; ++i) {
68 | free(strings[i]);
69 | }
70 | return result;
71 | }
72 |
73 | char* IfElseFn(const char* name, State* state, int argc, Expr* argv[]) {
74 | if (argc != 2 && argc != 3) {
75 | free(state->errmsg);
76 | state->errmsg = strdup("ifelse expects 2 or 3 arguments");
77 | return NULL;
78 | }
79 | char* cond = Evaluate(state, argv[0]);
80 | if (cond == NULL) {
81 | return NULL;
82 | }
83 |
84 | if (BooleanString(cond) == true) {
85 | free(cond);
86 | return Evaluate(state, argv[1]);
87 | } else {
88 | if (argc == 3) {
89 | free(cond);
90 | return Evaluate(state, argv[2]);
91 | } else {
92 | return cond;
93 | }
94 | }
95 | }
96 |
97 | char* AbortFn(const char* name, State* state, int argc, Expr* argv[]) {
98 | char* msg = NULL;
99 | if (argc > 0) {
100 | msg = Evaluate(state, argv[0]);
101 | }
102 | free(state->errmsg);
103 | if (msg) {
104 | state->errmsg = msg;
105 | } else {
106 | state->errmsg = strdup("called abort()");
107 | }
108 | return NULL;
109 | }
110 |
111 | char* AssertFn(const char* name, State* state, int argc, Expr* argv[]) {
112 | int i;
113 | for (i = 0; i < argc; ++i) {
114 | char* v = Evaluate(state, argv[i]);
115 | if (v == NULL) {
116 | return NULL;
117 | }
118 | int b = BooleanString(v);
119 | free(v);
120 | if (!b) {
121 | int prefix_len;
122 | int len = argv[i]->end - argv[i]->start;
123 | char* err_src = malloc(len + 20);
124 | strcpy(err_src, "assert failed: ");
125 | prefix_len = strlen(err_src);
126 | memcpy(err_src + prefix_len, state->script + argv[i]->start, len);
127 | err_src[prefix_len + len] = '\0';
128 | free(state->errmsg);
129 | state->errmsg = err_src;
130 | return NULL;
131 | }
132 | }
133 | return strdup("");
134 | }
135 |
136 | char* SleepFn(const char* name, State* state, int argc, Expr* argv[]) {
137 | char* val = Evaluate(state, argv[0]);
138 | if (val == NULL) {
139 | return NULL;
140 | }
141 | int v = strtol(val, NULL, 10);
142 | sleep(v);
143 | return val;
144 | }
145 |
146 | char* StdoutFn(const char* name, State* state, int argc, Expr* argv[]) {
147 | int i;
148 | for (i = 0; i < argc; ++i) {
149 | char* v = Evaluate(state, argv[i]);
150 | if (v == NULL) {
151 | return NULL;
152 | }
153 | fputs(v, stdout);
154 | free(v);
155 | }
156 | return strdup("");
157 | }
158 |
159 | char* LogicalAndFn(const char* name, State* state,
160 | int argc, Expr* argv[]) {
161 | char* left = Evaluate(state, argv[0]);
162 | if (left == NULL) return NULL;
163 | if (BooleanString(left) == true) {
164 | free(left);
165 | return Evaluate(state, argv[1]);
166 | } else {
167 | return left;
168 | }
169 | }
170 |
171 | char* LogicalOrFn(const char* name, State* state,
172 | int argc, Expr* argv[]) {
173 | char* left = Evaluate(state, argv[0]);
174 | if (left == NULL) return NULL;
175 | if (BooleanString(left) == false) {
176 | free(left);
177 | return Evaluate(state, argv[1]);
178 | } else {
179 | return left;
180 | }
181 | }
182 |
183 | char* LogicalNotFn(const char* name, State* state,
184 | int argc, Expr* argv[]) {
185 | char* val = Evaluate(state, argv[0]);
186 | if (val == NULL) return NULL;
187 | bool bv = BooleanString(val);
188 | free(val);
189 | if (bv) {
190 | return strdup("");
191 | } else {
192 | return strdup("t");
193 | }
194 | }
195 |
196 | char* SubstringFn(const char* name, State* state,
197 | int argc, Expr* argv[]) {
198 | char* needle = Evaluate(state, argv[0]);
199 | if (needle == NULL) return NULL;
200 | char* haystack = Evaluate(state, argv[1]);
201 | if (haystack == NULL) {
202 | free(needle);
203 | return NULL;
204 | }
205 |
206 | char* result = strdup(strstr(haystack, needle) ? "t" : "");
207 | free(needle);
208 | free(haystack);
209 | return result;
210 | }
211 |
212 | char* EqualityFn(const char* name, State* state, int argc, Expr* argv[]) {
213 | char* left = Evaluate(state, argv[0]);
214 | if (left == NULL) return NULL;
215 | char* right = Evaluate(state, argv[1]);
216 | if (right == NULL) {
217 | free(left);
218 | return NULL;
219 | }
220 |
221 | char* result = strdup(strcmp(left, right) == 0 ? "t" : "");
222 | free(left);
223 | free(right);
224 | return result;
225 | }
226 |
227 | char* InequalityFn(const char* name, State* state, int argc, Expr* argv[]) {
228 | char* left = Evaluate(state, argv[0]);
229 | if (left == NULL) return NULL;
230 | char* right = Evaluate(state, argv[1]);
231 | if (right == NULL) {
232 | free(left);
233 | return NULL;
234 | }
235 |
236 | char* result = strdup(strcmp(left, right) != 0 ? "t" : "");
237 | free(left);
238 | free(right);
239 | return result;
240 | }
241 |
242 | char* SequenceFn(const char* name, State* state, int argc, Expr* argv[]) {
243 | char* left = Evaluate(state, argv[0]);
244 | if (left == NULL) return NULL;
245 | free(left);
246 | return Evaluate(state, argv[1]);
247 | }
248 |
249 | char* LessThanIntFn(const char* name, State* state, int argc, Expr* argv[]) {
250 | if (argc != 2) {
251 | free(state->errmsg);
252 | state->errmsg = strdup("less_than_int expects 2 arguments");
253 | return NULL;
254 | }
255 |
256 | char* left;
257 | char* right;
258 | if (ReadArgs(state, argv, 2, &left, &right) < 0) return NULL;
259 |
260 | bool result = false;
261 | char* end;
262 |
263 | long l_int = strtol(left, &end, 10);
264 | if (left[0] == '\0' || *end != '\0') {
265 | fprintf(stderr, "[%s] is not an int\n", left);
266 | goto done;
267 | }
268 |
269 | long r_int = strtol(right, &end, 10);
270 | if (right[0] == '\0' || *end != '\0') {
271 | fprintf(stderr, "[%s] is not an int\n", right);
272 | goto done;
273 | }
274 |
275 | result = l_int < r_int;
276 |
277 | done:
278 | free(left);
279 | free(right);
280 | return strdup(result ? "t" : "");
281 | }
282 |
283 | char* GreaterThanIntFn(const char* name, State* state, int argc, Expr* argv[]) {
284 | if (argc != 2) {
285 | free(state->errmsg);
286 | state->errmsg = strdup("greater_than_int expects 2 arguments");
287 | return NULL;
288 | }
289 |
290 | Expr* temp[2];
291 | temp[0] = argv[1];
292 | temp[1] = argv[0];
293 |
294 | return LessThanIntFn(name, state, 2, temp);
295 | }
296 |
297 | char* Literal(const char* name, State* state, int argc, Expr* argv[]) {
298 | return strdup(name);
299 | }
300 |
301 | Expr* Build(Function fn, YYLTYPE loc, int count, ...) {
302 | va_list v;
303 | va_start(v, count);
304 | Expr* e = malloc(sizeof(Expr));
305 | e->fn = fn;
306 | e->name = "(operator)";
307 | e->argc = count;
308 | e->argv = malloc(count * sizeof(Expr*));
309 | int i;
310 | for (i = 0; i < count; ++i) {
311 | e->argv[i] = va_arg(v, Expr*);
312 | }
313 | va_end(v);
314 | e->start = loc.start;
315 | e->end = loc.end;
316 | return e;
317 | }
318 |
319 | // -----------------------------------------------------------------
320 | // the function table
321 | // -----------------------------------------------------------------
322 |
323 | static int fn_entries = 0;
324 | static int fn_size = 0;
325 | NamedFunction* fn_table = NULL;
326 |
327 | void RegisterFunction(const char* name, Function fn) {
328 | if (fn_entries >= fn_size) {
329 | fn_size = fn_size*2 + 1;
330 | fn_table = realloc(fn_table, fn_size * sizeof(NamedFunction));
331 | }
332 | fn_table[fn_entries].name = name;
333 | fn_table[fn_entries].fn = fn;
334 | ++fn_entries;
335 | }
336 |
337 | static int fn_entry_compare(const void* a, const void* b) {
338 | const char* na = ((const NamedFunction*)a)->name;
339 | const char* nb = ((const NamedFunction*)b)->name;
340 | return strcmp(na, nb);
341 | }
342 |
343 | void FinishRegistration() {
344 | qsort(fn_table, fn_entries, sizeof(NamedFunction), fn_entry_compare);
345 | }
346 |
347 | Function FindFunction(const char* name) {
348 | NamedFunction key;
349 | key.name = name;
350 | NamedFunction* nf = bsearch(&key, fn_table, fn_entries,
351 | sizeof(NamedFunction), fn_entry_compare);
352 | if (nf == NULL) {
353 | return NULL;
354 | }
355 | return nf->fn;
356 | }
357 |
358 | void RegisterBuiltins() {
359 | RegisterFunction("ifelse", IfElseFn);
360 | RegisterFunction("abort", AbortFn);
361 | RegisterFunction("assert", AssertFn);
362 | RegisterFunction("concat", ConcatFn);
363 | RegisterFunction("is_substring", SubstringFn);
364 | RegisterFunction("stdout", StdoutFn);
365 | RegisterFunction("sleep", SleepFn);
366 |
367 | RegisterFunction("less_than_int", LessThanIntFn);
368 | RegisterFunction("greater_than_int", GreaterThanIntFn);
369 | }
370 |
371 |
372 | // -----------------------------------------------------------------
373 | // convenience methods for functions
374 | // -----------------------------------------------------------------
375 |
376 | // Evaluate the expressions in argv, giving 'count' char* (the ... is
377 | // zero or more char** to put them in). If any expression evaluates
378 | // to NULL, free the rest and return -1. Return 0 on success.
379 | int ReadArgs(State* state, Expr* argv[], int count, ...) {
380 | char** args = malloc(count * sizeof(char*));
381 | va_list v;
382 | va_start(v, count);
383 | int i;
384 | for (i = 0; i < count; ++i) {
385 | args[i] = Evaluate(state, argv[i]);
386 | if (args[i] == NULL) {
387 | va_end(v);
388 | int j;
389 | for (j = 0; j < i; ++j) {
390 | free(args[j]);
391 | }
392 | return -1;
393 | }
394 | *(va_arg(v, char**)) = args[i];
395 | }
396 | va_end(v);
397 | return 0;
398 | }
399 |
400 | // Evaluate the expressions in argv, returning an array of char*
401 | // results. If any evaluate to NULL, free the rest and return NULL.
402 | // The caller is responsible for freeing the returned array and the
403 | // strings it contains.
404 | char** ReadVarArgs(State* state, int argc, Expr* argv[]) {
405 | char** args = (char**)malloc(argc * sizeof(char*));
406 | int i = 0;
407 | for (i = 0; i < argc; ++i) {
408 | args[i] = Evaluate(state, argv[i]);
409 | if (args[i] == NULL) {
410 | int j;
411 | for (j = 0; j < i; ++j) {
412 | free(args[j]);
413 | }
414 | free(args);
415 | return NULL;
416 | }
417 | }
418 | return args;
419 | }
420 |
421 | // Use printf-style arguments to compose an error message to put into
422 | // *state. Returns NULL.
423 | char* ErrorAbort(State* state, char* format, ...) {
424 | char* buffer = malloc(4096);
425 | va_list v;
426 | va_start(v, format);
427 | vsnprintf(buffer, 4096, format, v);
428 | va_end(v);
429 | free(state->errmsg);
430 | state->errmsg = buffer;
431 | return NULL;
432 | }
433 |
--------------------------------------------------------------------------------
/native/tether/edify/expr.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef _EXPRESSION_H
18 | #define _EXPRESSION_H
19 |
20 | #include "yydefs.h"
21 |
22 | #define MAX_STRING_LEN 1024
23 |
24 | typedef struct Expr Expr;
25 |
26 | typedef struct {
27 | // Optional pointer to app-specific data; the core of edify never
28 | // uses this value.
29 | void* cookie;
30 |
31 | // The source of the original script. Must be NULL-terminated,
32 | // and in writable memory (Evaluate may make temporary changes to
33 | // it but will restore it when done).
34 | char* script;
35 |
36 | // The error message (if any) returned if the evaluation aborts.
37 | // Should be NULL initially, will be either NULL or a malloc'd
38 | // pointer after Evaluate() returns.
39 | char* errmsg;
40 | } State;
41 |
42 | typedef char* (*Function)(const char* name, State* state,
43 | int argc, Expr* argv[]);
44 |
45 | struct Expr {
46 | Function fn;
47 | char* name;
48 | int argc;
49 | Expr** argv;
50 | int start, end;
51 | };
52 |
53 | char* Evaluate(State* state, Expr* expr);
54 |
55 | // Glue to make an Expr out of a literal.
56 | char* Literal(const char* name, State* state, int argc, Expr* argv[]);
57 |
58 | // Functions corresponding to various syntactic sugar operators.
59 | // ("concat" is also available as a builtin function, to concatenate
60 | // more than two strings.)
61 | char* ConcatFn(const char* name, State* state, int argc, Expr* argv[]);
62 | char* LogicalAndFn(const char* name, State* state, int argc, Expr* argv[]);
63 | char* LogicalOrFn(const char* name, State* state, int argc, Expr* argv[]);
64 | char* LogicalNotFn(const char* name, State* state, int argc, Expr* argv[]);
65 | char* SubstringFn(const char* name, State* state, int argc, Expr* argv[]);
66 | char* EqualityFn(const char* name, State* state, int argc, Expr* argv[]);
67 | char* InequalityFn(const char* name, State* state, int argc, Expr* argv[]);
68 | char* SequenceFn(const char* name, State* state, int argc, Expr* argv[]);
69 |
70 | // Convenience function for building expressions with a fixed number
71 | // of arguments.
72 | Expr* Build(Function fn, YYLTYPE loc, int count, ...);
73 |
74 | // Global builtins, registered by RegisterBuiltins().
75 | char* IfElseFn(const char* name, State* state, int argc, Expr* argv[]);
76 | char* AssertFn(const char* name, State* state, int argc, Expr* argv[]);
77 | char* AbortFn(const char* name, State* state, int argc, Expr* argv[]);
78 |
79 |
80 | // For setting and getting the global error string (when returning
81 | // NULL from a function).
82 | void SetError(const char* message); // makes a copy
83 | const char* GetError(); // retains ownership
84 | void ClearError();
85 |
86 |
87 | typedef struct {
88 | const char* name;
89 | Function fn;
90 | } NamedFunction;
91 |
92 | // Register a new function. The same Function may be registered under
93 | // multiple names, but a given name should only be used once.
94 | void RegisterFunction(const char* name, Function fn);
95 |
96 | // Register all the builtins.
97 | void RegisterBuiltins();
98 |
99 | // Call this after all calls to RegisterFunction() but before parsing
100 | // any scripts to finish building the function table.
101 | void FinishRegistration();
102 |
103 | // Find the Function for a given name; return NULL if no such function
104 | // exists.
105 | Function FindFunction(const char* name);
106 |
107 |
108 | // --- convenience functions for use in functions ---
109 |
110 | // Evaluate the expressions in argv, giving 'count' char* (the ... is
111 | // zero or more char** to put them in). If any expression evaluates
112 | // to NULL, free the rest and return -1. Return 0 on success.
113 | int ReadArgs(State* state, Expr* argv[], int count, ...);
114 |
115 | // Evaluate the expressions in argv, returning an array of char*
116 | // results. If any evaluate to NULL, free the rest and return NULL.
117 | // The caller is responsible for freeing the returned array and the
118 | // strings it contains.
119 | char** ReadVarArgs(State* state, int argc, Expr* argv[]);
120 |
121 | // Use printf-style arguments to compose an error message to put into
122 | // *state. Returns NULL.
123 | char* ErrorAbort(State* state, char* format, ...);
124 |
125 |
126 | #endif // _EXPRESSION_H
127 |
--------------------------------------------------------------------------------
/native/tether/edify/lexer.l:
--------------------------------------------------------------------------------
1 | %{
2 | /*
3 | * Copyright (C) 2009 The Android Open Source Project
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #include "expr.h"
19 | #include "yydefs.h"
20 | #include "parser.h"
21 |
22 | int gLine = 1;
23 | int gColumn = 1;
24 | int gPos = 0;
25 |
26 | // TODO: enforce MAX_STRING_LEN during lexing
27 | char string_buffer[MAX_STRING_LEN];
28 | char* string_pos;
29 |
30 | #define ADVANCE do {yylloc.start=gPos; yylloc.end=gPos+yyleng; \
31 | gColumn+=yyleng; gPos+=yyleng;} while(0)
32 |
33 | %}
34 |
35 | %x STR
36 |
37 | %option noyywrap
38 |
39 | %%
40 |
41 |
42 | \" {
43 | BEGIN(STR);
44 | string_pos = string_buffer;
45 | yylloc.start = gPos;
46 | ++gColumn;
47 | ++gPos;
48 | }
49 |
50 | {
51 | \" {
52 | ++gColumn;
53 | ++gPos;
54 | BEGIN(INITIAL);
55 | *string_pos = '\0';
56 | yylval.str = strdup(string_buffer);
57 | yylloc.end = gPos;
58 | return STRING;
59 | }
60 |
61 | \\n { gColumn += yyleng; gPos += yyleng; *string_pos++ = '\n'; }
62 | \\t { gColumn += yyleng; gPos += yyleng; *string_pos++ = '\t'; }
63 | \\\" { gColumn += yyleng; gPos += yyleng; *string_pos++ = '\"'; }
64 | \\\\ { gColumn += yyleng; gPos += yyleng; *string_pos++ = '\\'; }
65 |
66 | \\x[0-9a-fA-F]{2} {
67 | gColumn += yyleng;
68 | gPos += yyleng;
69 | int val;
70 | sscanf(yytext+2, "%x", &val);
71 | *string_pos++ = val;
72 | }
73 |
74 | \n {
75 | ++gLine;
76 | ++gPos;
77 | gColumn = 1;
78 | *string_pos++ = yytext[0];
79 | }
80 |
81 | . {
82 | ++gColumn;
83 | ++gPos;
84 | *string_pos++ = yytext[0];
85 | }
86 | }
87 |
88 | if ADVANCE; return IF;
89 | then ADVANCE; return THEN;
90 | else ADVANCE; return ELSE;
91 | endif ADVANCE; return ENDIF;
92 |
93 | [a-zA-Z0-9_:/.]+ {
94 | ADVANCE;
95 | yylval.str = strdup(yytext);
96 | return STRING;
97 | }
98 |
99 | \&\& ADVANCE; return AND;
100 | \|\| ADVANCE; return OR;
101 | == ADVANCE; return EQ;
102 | != ADVANCE; return NE;
103 |
104 | [+(),!;] ADVANCE; return yytext[0];
105 |
106 | [ \t]+ ADVANCE;
107 |
108 | (#.*)?\n gPos += yyleng; ++gLine; gColumn = 1;
109 |
110 | . return BAD;
111 |
--------------------------------------------------------------------------------
/native/tether/edify/main.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 | #include
19 | #include
20 |
21 | #include "expr.h"
22 | #include "parser.h"
23 |
24 | extern int yyparse(Expr** root, int* error_count);
25 |
26 | int expect(const char* expr_str, const char* expected, int* errors) {
27 | Expr* e;
28 | int error;
29 | char* result;
30 |
31 | printf(".");
32 |
33 | yy_scan_string(expr_str);
34 | int error_count = 0;
35 | error = yyparse(&e, &error_count);
36 | if (error > 0 || error_count > 0) {
37 | fprintf(stderr, "error parsing \"%s\" (%d errors)\n",
38 | expr_str, error_count);
39 | ++*errors;
40 | return 0;
41 | }
42 |
43 | State state;
44 | state.cookie = NULL;
45 | state.script = expr_str;
46 | state.errmsg = NULL;
47 |
48 | result = Evaluate(&state, e);
49 | free(state.errmsg);
50 | if (result == NULL && expected != NULL) {
51 | fprintf(stderr, "error evaluating \"%s\"\n", expr_str);
52 | ++*errors;
53 | return 0;
54 | }
55 |
56 | if (result == NULL && expected == NULL) {
57 | return 1;
58 | }
59 |
60 | if (strcmp(result, expected) != 0) {
61 | fprintf(stderr, "evaluating \"%s\": expected \"%s\", got \"%s\"\n",
62 | expr_str, expected, result);
63 | ++*errors;
64 | free(result);
65 | return 0;
66 | }
67 |
68 | free(result);
69 | return 1;
70 | }
71 |
72 | int test() {
73 | int errors = 0;
74 |
75 | expect("a", "a", &errors);
76 | expect("\"a\"", "a", &errors);
77 | expect("\"\\x61\"", "a", &errors);
78 | expect("# this is a comment\n"
79 | " a\n"
80 | " \n",
81 | "a", &errors);
82 |
83 |
84 | // sequence operator
85 | expect("a; b; c", "c", &errors);
86 |
87 | // string concat operator
88 | expect("a + b", "ab", &errors);
89 | expect("a + \n \"b\"", "ab", &errors);
90 | expect("a + b +\nc\n", "abc", &errors);
91 |
92 | // string concat function
93 | expect("concat(a, b)", "ab", &errors);
94 | expect("concat(a,\n \"b\")", "ab", &errors);
95 | expect("concat(a + b,\nc,\"d\")", "abcd", &errors);
96 | expect("\"concat\"(a + b,\nc,\"d\")", "abcd", &errors);
97 |
98 | // logical and
99 | expect("a && b", "b", &errors);
100 | expect("a && \"\"", "", &errors);
101 | expect("\"\" && b", "", &errors);
102 | expect("\"\" && \"\"", "", &errors);
103 | expect("\"\" && abort()", "", &errors); // test short-circuiting
104 | expect("t && abort()", NULL, &errors);
105 |
106 | // logical or
107 | expect("a || b", "a", &errors);
108 | expect("a || \"\"", "a", &errors);
109 | expect("\"\" || b", "b", &errors);
110 | expect("\"\" || \"\"", "", &errors);
111 | expect("a || abort()", "a", &errors); // test short-circuiting
112 | expect("\"\" || abort()", NULL, &errors);
113 |
114 | // logical not
115 | expect("!a", "", &errors);
116 | expect("! \"\"", "t", &errors);
117 | expect("!!a", "t", &errors);
118 |
119 | // precedence
120 | expect("\"\" == \"\" && b", "b", &errors);
121 | expect("a + b == ab", "t", &errors);
122 | expect("ab == a + b", "t", &errors);
123 | expect("a + (b == ab)", "a", &errors);
124 | expect("(ab == a) + b", "b", &errors);
125 |
126 | // substring function
127 | expect("is_substring(cad, abracadabra)", "t", &errors);
128 | expect("is_substring(abrac, abracadabra)", "t", &errors);
129 | expect("is_substring(dabra, abracadabra)", "t", &errors);
130 | expect("is_substring(cad, abracxadabra)", "", &errors);
131 | expect("is_substring(abrac, axbracadabra)", "", &errors);
132 | expect("is_substring(dabra, abracadabrxa)", "", &errors);
133 |
134 | // ifelse function
135 | expect("ifelse(t, yes, no)", "yes", &errors);
136 | expect("ifelse(!t, yes, no)", "no", &errors);
137 | expect("ifelse(t, yes, abort())", "yes", &errors);
138 | expect("ifelse(!t, abort(), no)", "no", &errors);
139 |
140 | // if "statements"
141 | expect("if t then yes else no endif", "yes", &errors);
142 | expect("if \"\" then yes else no endif", "no", &errors);
143 | expect("if \"\" then yes endif", "", &errors);
144 | expect("if \"\"; t then yes endif", "yes", &errors);
145 |
146 | // numeric comparisons
147 | expect("less_than_int(3, 14)", "t", &errors);
148 | expect("less_than_int(14, 3)", "", &errors);
149 | expect("less_than_int(x, 3)", "", &errors);
150 | expect("less_than_int(3, x)", "", &errors);
151 | expect("greater_than_int(3, 14)", "", &errors);
152 | expect("greater_than_int(14, 3)", "t", &errors);
153 | expect("greater_than_int(x, 3)", "", &errors);
154 | expect("greater_than_int(3, x)", "", &errors);
155 |
156 | printf("\n");
157 |
158 | return errors;
159 | }
160 |
161 | void ExprDump(int depth, Expr* n, char* script) {
162 | printf("%*s", depth*2, "");
163 | char temp = script[n->end];
164 | script[n->end] = '\0';
165 | printf("%s %p (%d-%d) \"%s\"\n",
166 | n->name == NULL ? "(NULL)" : n->name, n->fn, n->start, n->end,
167 | script+n->start);
168 | script[n->end] = temp;
169 | int i;
170 | for (i = 0; i < n->argc; ++i) {
171 | ExprDump(depth+1, n->argv[i], script);
172 | }
173 | }
174 |
175 | int main(int argc, char** argv) {
176 | RegisterBuiltins();
177 | FinishRegistration();
178 |
179 | if (argc == 1) {
180 | return test() != 0;
181 | }
182 |
183 | FILE* f = fopen(argv[1], "r");
184 | char buffer[8192];
185 | int size = fread(buffer, 1, 8191, f);
186 | fclose(f);
187 | buffer[size] = '\0';
188 |
189 | Expr* root;
190 | int error_count = 0;
191 | yy_scan_bytes(buffer, size);
192 | int error = yyparse(&root, &error_count);
193 | printf("parse returned %d; %d errors encountered\n", error, error_count);
194 | if (error == 0 || error_count > 0) {
195 |
196 | ExprDump(0, root, buffer);
197 |
198 | State state;
199 | state.cookie = NULL;
200 | state.script = buffer;
201 | state.errmsg = NULL;
202 |
203 | char* result = Evaluate(&state, root);
204 | if (result == NULL) {
205 | printf("result was NULL, message is: %s\n",
206 | (state.errmsg == NULL ? "(NULL)" : state.errmsg));
207 | free(state.errmsg);
208 | } else {
209 | printf("result is [%s]\n", result);
210 | }
211 | }
212 | return 0;
213 | }
214 |
--------------------------------------------------------------------------------
/native/tether/edify/parser.y:
--------------------------------------------------------------------------------
1 | %{
2 | /*
3 | * Copyright (C) 2009 The Android Open Source Project
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | #include
19 | #include
20 | #include
21 |
22 | #include "expr.h"
23 | #include "yydefs.h"
24 | #include "parser.h"
25 |
26 | extern int gLine;
27 | extern int gColumn;
28 |
29 | void yyerror(Expr** root, int* error_count, const char* s);
30 | int yyparse(Expr** root, int* error_count);
31 |
32 | %}
33 |
34 | %locations
35 |
36 | %union {
37 | char* str;
38 | Expr* expr;
39 | struct {
40 | int argc;
41 | Expr** argv;
42 | } args;
43 | }
44 |
45 | %token AND OR SUBSTR SUPERSTR EQ NE IF THEN ELSE ENDIF
46 | %token STRING BAD
47 | %type expr
48 | %type arglist
49 |
50 | %parse-param {Expr** root}
51 | %parse-param {int* error_count}
52 | %error-verbose
53 |
54 | /* declarations in increasing order of precedence */
55 | %left ';'
56 | %left ','
57 | %left OR
58 | %left AND
59 | %left EQ NE
60 | %left '+'
61 | %right '!'
62 |
63 | %%
64 |
65 | input: expr { *root = $1; }
66 | ;
67 |
68 | expr: STRING {
69 | $$ = malloc(sizeof(Expr));
70 | $$->fn = Literal;
71 | $$->name = $1;
72 | $$->argc = 0;
73 | $$->argv = NULL;
74 | $$->start = @$.start;
75 | $$->end = @$.end;
76 | }
77 | | '(' expr ')' { $$ = $2; $$->start=@$.start; $$->end=@$.end; }
78 | | expr ';' { $$ = $1; $$->start=@1.start; $$->end=@1.end; }
79 | | expr ';' expr { $$ = Build(SequenceFn, @$, 2, $1, $3); }
80 | | error ';' expr { $$ = $3; $$->start=@$.start; $$->end=@$.end; }
81 | | expr '+' expr { $$ = Build(ConcatFn, @$, 2, $1, $3); }
82 | | expr EQ expr { $$ = Build(EqualityFn, @$, 2, $1, $3); }
83 | | expr NE expr { $$ = Build(InequalityFn, @$, 2, $1, $3); }
84 | | expr AND expr { $$ = Build(LogicalAndFn, @$, 2, $1, $3); }
85 | | expr OR expr { $$ = Build(LogicalOrFn, @$, 2, $1, $3); }
86 | | '!' expr { $$ = Build(LogicalNotFn, @$, 1, $2); }
87 | | IF expr THEN expr ENDIF { $$ = Build(IfElseFn, @$, 2, $2, $4); }
88 | | IF expr THEN expr ELSE expr ENDIF { $$ = Build(IfElseFn, @$, 3, $2, $4, $6); }
89 | | STRING '(' arglist ')' {
90 | $$ = malloc(sizeof(Expr));
91 | $$->fn = FindFunction($1);
92 | if ($$->fn == NULL) {
93 | char buffer[256];
94 | snprintf(buffer, sizeof(buffer), "unknown function \"%s\"", $1);
95 | yyerror(root, error_count, buffer);
96 | YYERROR;
97 | }
98 | $$->name = $1;
99 | $$->argc = $3.argc;
100 | $$->argv = $3.argv;
101 | $$->start = @$.start;
102 | $$->end = @$.end;
103 | }
104 | ;
105 |
106 | arglist: /* empty */ {
107 | $$.argc = 0;
108 | $$.argv = NULL;
109 | }
110 | | expr {
111 | $$.argc = 1;
112 | $$.argv = malloc(sizeof(Expr*));
113 | $$.argv[0] = $1;
114 | }
115 | | arglist ',' expr {
116 | $$.argc = $1.argc + 1;
117 | $$.argv = realloc($$.argv, $$.argc * sizeof(Expr*));
118 | $$.argv[$$.argc-1] = $3;
119 | }
120 | ;
121 |
122 | %%
123 |
124 | void yyerror(Expr** root, int* error_count, const char* s) {
125 | if (strlen(s) == 0) {
126 | s = "syntax error";
127 | }
128 | printf("line %d col %d: %s\n", gLine, gColumn, s);
129 | ++*error_count;
130 | }
131 |
--------------------------------------------------------------------------------
/native/tether/edify/yydefs.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef _YYDEFS_H_
18 | #define _YYDEFS_H_
19 |
20 | #define YYLTYPE YYLTYPE
21 | typedef struct {
22 | int start, end;
23 | } YYLTYPE;
24 |
25 | #define YYLLOC_DEFAULT(Current, Rhs, N) \
26 | do { \
27 | if (N) { \
28 | (Current).start = YYRHSLOC(Rhs, 1).start; \
29 | (Current).end = YYRHSLOC(Rhs, N).end; \
30 | } else { \
31 | (Current).start = YYRHSLOC(Rhs, 0).start; \
32 | (Current).end = YYRHSLOC(Rhs, 0).end; \
33 | } \
34 | } while (0)
35 |
36 | #endif
37 |
--------------------------------------------------------------------------------
/native/tether/install.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef _UPDATER_INSTALL_H_
18 | #define _UPDATER_INSTALL_H_
19 |
20 | void RegisterInstallFunctions();
21 |
22 | #endif
23 |
--------------------------------------------------------------------------------
/native/tether/sha1.h:
--------------------------------------------------------------------------------
1 | /*
2 | * SHA1 hash implementation and interface functions
3 | * Copyright (c) 2003-2005, Jouni Malinen
4 | *
5 | * This program is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License version 2 as
7 | * published by the Free Software Foundation.
8 | *
9 | * Alternatively, this software may be distributed under the terms of BSD
10 | * license.
11 | *
12 | * See README and COPYING for more details.
13 | */
14 |
15 | #ifndef SHA1_H
16 | #define SHA1_H
17 |
18 | #include
19 | #include
20 | #include
21 |
22 | #define os_memcpy memcpy
23 | #define os_memset memset
24 | #define os_memcmp memcmp
25 | #define os_strlen strlen
26 |
27 | #define MAX_SHA1_LEN 32
28 | #define SHA1_MAC_LEN 20
29 |
30 | typedef __u8 u8;
31 | typedef __u32 u32;
32 |
33 | static inline unsigned int wpa_swap_32(unsigned int v)
34 | {
35 | return ((v & 0xff) << 24) | ((v & 0xff00) << 8) |
36 | ((v & 0xff0000) >> 8) | (v >> 24);
37 | }
38 |
39 | #define be_to_host32(n) wpa_swap_32(n)
40 | #define host_to_be32(n) wpa_swap_32(n)
41 |
42 | void sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len,
43 | u8 *mac);
44 | void hmac_sha1_vector(const u8 *key, size_t key_len, size_t num_elem,
45 | const u8 *addr[], const size_t *len, u8 *mac);
46 | void hmac_sha1(const u8 *key, size_t key_len, const u8 *data, size_t data_len,
47 | u8 *mac);
48 | void sha1_prf(const u8 *key, size_t key_len, const char *label,
49 | const u8 *data, size_t data_len, u8 *buf, size_t buf_len);
50 | void sha1_t_prf(const u8 *key, size_t key_len, const char *label,
51 | const u8 *seed, size_t seed_len, u8 *buf, size_t buf_len);
52 | int tls_prf(const u8 *secret, size_t secret_len,
53 | const char *label, const u8 *seed, size_t seed_len,
54 | u8 *out, size_t outlen);
55 | #ifdef __cplusplus
56 | extern "C"
57 | #endif
58 | void pbkdf2_sha1(const char *passphrase, const char *ssid, size_t ssid_len,
59 | int iterations, u8 *buf, size_t buflen);
60 |
61 | #ifdef CONFIG_CRYPTO_INTERNAL
62 | struct SHA1Context;
63 |
64 | void SHA1Init(struct SHA1Context *context);
65 | void SHA1Update(struct SHA1Context *context, const void *data, u32 len);
66 | void SHA1Final(unsigned char digest[20], struct SHA1Context *context);
67 | #endif /* CONFIG_CRYPTO_INTERNAL */
68 |
69 | #endif /* SHA1_H */
70 |
--------------------------------------------------------------------------------
/native/tether/tether.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 Ben Buxton
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 |
24 | #include "edify/expr.h"
25 | #include "tether.h"
26 | #include "install.h"
27 |
28 | // Where in the package we expect to find the edify script to execute.
29 | #define SCRIPT_NAME "/data/data/com.googlecode.android.wifi.tether/conf/tether.edify"
30 |
31 | int main(int argc, char** argv) {
32 | FILE *f;
33 | /*
34 | if (argc != 4) {
35 | fprintf(stderr, "unexpected number of arguments (%d)\n", argc);
36 | return 1;
37 | }
38 |
39 | */
40 | // Set up the pipe for sending commands back to the parent process.
41 | //int fd = atoi(argv[2]);
42 | int fd = 1;
43 | FILE* cmd_pipe = fdopen(fd, "wb");
44 | setlinebuf(cmd_pipe);
45 |
46 | struct stat st;
47 | if (stat(SCRIPT_NAME, &st) < 0) {
48 | fprintf(stderr, "Could not stat %s: %s", SCRIPT_NAME, strerror(errno));
49 | return 1;
50 | }
51 | if (st.st_size > 128000) {
52 | fprintf(stderr, "%s too large (max 128k)", SCRIPT_NAME);
53 | return 1;
54 | }
55 | char *script = malloc(st.st_size+1);
56 |
57 | f = fopen(SCRIPT_NAME, "rb");
58 | if (f == NULL) {
59 | fprintf(stderr, "Cannot read %s\n", SCRIPT_NAME);
60 | return 1;
61 | }
62 | if (fread(script, 1, st.st_size, f) != st.st_size) {
63 | fprintf(stderr, "Failed to read %d bytes from %s", st.st_size+1, SCRIPT_NAME);
64 | return 1;
65 | }
66 | script[st.st_size] = '\0';
67 | fclose(f);
68 |
69 | // Configure edify's functions.
70 |
71 | RegisterBuiltins();
72 | RegisterInstallFunctions();
73 | FinishRegistration();
74 |
75 | // Parse the script.
76 |
77 | Expr* root;
78 | int error_count = 0;
79 | yy_scan_string(script);
80 | int error = yyparse(&root, &error_count);
81 | if (error != 0 || error_count > 0) {
82 | fprintf(stderr, "%d parse errors\n", error_count);
83 | return 6;
84 | }
85 |
86 | // Evaluate the parsed script.
87 |
88 | UpdaterInfo updater_info;
89 | updater_info.cmd_pipe = cmd_pipe;
90 | updater_info.log_fd = fopen ("/data/data/com.googlecode.android.wifi.tether/var/tether.log","w");
91 |
92 | updater_info.action = strdup(argv[1]);
93 |
94 | State state;
95 | state.cookie = &updater_info;
96 | state.script = script;
97 | state.errmsg = NULL;
98 |
99 | char* result = Evaluate(&state, root);
100 | if (result == NULL) {
101 | if (state.errmsg == NULL) {
102 | fprintf(stderr, "script aborted (no error message)\n");
103 | fprintf(cmd_pipe, "ui_print script aborted (no error message)\n");
104 | } else {
105 | fprintf(stderr, "script aborted: %s\n", state.errmsg);
106 | char* line = strtok(state.errmsg, "\n");
107 | while (line) {
108 | fprintf(cmd_pipe, "ui_print %s\n", line);
109 | line = strtok(NULL, "\n");
110 | }
111 | fprintf(cmd_pipe, "ui_print\n");
112 | }
113 | free(state.errmsg);
114 | return 7;
115 | } else {
116 | fprintf(stderr, "script result was [%s]\n", result);
117 | free(result);
118 | }
119 |
120 | free(script);
121 |
122 | return 0;
123 | }
124 |
--------------------------------------------------------------------------------
/native/tether/tether.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2009 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef _UPDATER_UPDATER_H_
18 | #define _UPDATER_UPDATER_H_
19 |
20 | #include
21 |
22 | typedef struct {
23 | FILE* cmd_pipe;
24 | FILE* log_fd;
25 | char *action;
26 | } UpdaterInfo;
27 |
28 | #endif
29 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system use,
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 |
10 | # Indicates whether an apk should be generated for each density.
11 | split.density=false
12 | # Project target.
13 | target=android-11
14 | apk-configurations=
15 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/appwidget_bg.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable-hdpi/appwidget_bg.9.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/appwidget_divider.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable-hdpi/appwidget_divider.9.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/appwidget_ind_mid_c.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable-hdpi/appwidget_ind_mid_c.9.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/appwidget_ind_off_c.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable-hdpi/appwidget_ind_off_c.9.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/appwidget_ind_on_c.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable-hdpi/appwidget_ind_on_c.9.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/appwidget_inner_focus_c.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable-hdpi/appwidget_inner_focus_c.9.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/appwidget_inner_press_c.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable-hdpi/appwidget_inner_press_c.9.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable-hdpi/icon.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/tether_wifi_off.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable-hdpi/tether_wifi_off.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/tether_wifi_on.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable-hdpi/tether_wifi_on.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/appwidget_bg.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable-mdpi/appwidget_bg.9.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/appwidget_divider.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable-mdpi/appwidget_divider.9.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/appwidget_ind_mid_c.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable-mdpi/appwidget_ind_mid_c.9.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/appwidget_ind_off_c.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable-mdpi/appwidget_ind_off_c.9.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/appwidget_ind_on_c.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable-mdpi/appwidget_ind_on_c.9.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/appwidget_inner_focus_c.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable-mdpi/appwidget_inner_focus_c.9.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/appwidget_inner_press_c.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable-mdpi/appwidget_inner_press_c.9.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable-mdpi/icon.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/tether_wifi_off.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable-mdpi/tether_wifi_off.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/tether_wifi_on.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable-mdpi/tether_wifi_on.png
--------------------------------------------------------------------------------
/res/drawable/appwidget_button.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
18 |
19 |
21 |
22 |
25 |
26 |
28 |
29 |
--------------------------------------------------------------------------------
/res/drawable/background.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable/background.9.png
--------------------------------------------------------------------------------
/res/drawable/battery.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable/battery.png
--------------------------------------------------------------------------------
/res/drawable/sechigh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable/sechigh.png
--------------------------------------------------------------------------------
/res/drawable/seclow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable/seclow.png
--------------------------------------------------------------------------------
/res/drawable/secmedium.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable/secmedium.png
--------------------------------------------------------------------------------
/res/drawable/start.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable/start.png
--------------------------------------------------------------------------------
/res/drawable/start_notification.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable/start_notification.png
--------------------------------------------------------------------------------
/res/drawable/stop.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable/stop.png
--------------------------------------------------------------------------------
/res/drawable/stop_notification.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/drawable/stop_notification.png
--------------------------------------------------------------------------------
/res/drawable/tether_start_button.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
7 |
8 |
--------------------------------------------------------------------------------
/res/drawable/tether_stop_button.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
7 |
8 |
--------------------------------------------------------------------------------
/res/layout/aboutview.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
21 |
22 |
31 |
32 |
41 |
42 |
52 |
53 |
62 |
63 |
70 |
71 |
81 |
82 |
91 |
92 |
100 |
101 |
110 |
111 |
118 |
119 |
128 |
129 |
139 |
140 |
150 |
158 |
167 |
174 |
175 |
176 |
--------------------------------------------------------------------------------
/res/layout/accesscontrolview.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
13 |
23 |
33 |
34 |
43 |
49 |
54 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/res/layout/clientrow.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
13 |
14 |
20 |
21 |
26 |
27 |
31 |
36 |
37 |
38 |
42 |
48 |
49 |
50 |
54 |
60 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/res/layout/donateview.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
11 |
18 |
24 |
30 |
36 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/res/layout/hidessidwarningview.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
10 |
14 |
23 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/res/layout/logview.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
26 |
27 |
36 |
37 |
38 |
39 |
47 |
48 |
58 |
59 |
69 |
70 |
81 |
82 |
83 |
88 |
89 |
94 |
95 |
96 |
97 |
101 |
102 |
103 |
104 |
112 |
113 |
119 |
120 |
121 |
122 |
123 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
140 |
141 |
142 |
143 |
151 |
152 |
158 |
159 |
160 |
161 |
162 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
184 |
185 |
195 |
196 |
206 |
207 |
217 |
218 |
228 |
229 |
240 |
241 |
252 |
253 |
262 |
263 |
274 |
275 |
285 |
286 |
296 |
297 |
298 |
299 |
308 |
318 |
319 |
330 |
331 |
342 |
343 |
344 |
345 |
--------------------------------------------------------------------------------
/res/layout/noaccesscontrolview.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
10 |
14 |
23 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/res/layout/nonetfilterview.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
10 |
14 |
23 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/res/layout/norootview.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
10 |
14 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/res/layout/setupview.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
14 |
22 |
27 |
31 |
35 |
44 |
51 |
59 |
63 |
71 |
76 |
85 |
93 |
98 |
103 |
108 |
109 |
111 |
115 |
116 |
118 |
122 |
129 |
136 |
145 |
152 |
153 |
155 |
160 |
168 |
173 |
181 |
186 |
193 |
194 |
195 |
203 |
208 |
213 |
214 |
215 |
223 |
231 |
232 |
233 |
241 |
248 |
253 |
254 |
255 |
259 |
264 |
272 |
277 |
278 |
279 |
--------------------------------------------------------------------------------
/res/layout/txpowerwarningview.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
10 |
14 |
23 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/res/layout/updateview.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
10 |
14 |
23 |
34 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/res/layout/widget.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
26 |
27 |
33 |
34 |
35 |
40 |
41 |
164 |
165 |
166 |
--------------------------------------------------------------------------------
/res/raw/dnsmasq:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/raw/dnsmasq
--------------------------------------------------------------------------------
/res/raw/fixpersist_sh:
--------------------------------------------------------------------------------
1 | #!/system/bin/sh
2 | while true; do
3 | sleep 2
4 | /data/data/com.googlecode.android.wifi.tether/bin/iwconfig $1 | while read l; do
5 | case "$l" in *ESSID*)
6 | case "$l" in *\"$2\"*)
7 | break;
8 | esac;
9 | /data/data/com.googlecode.android.wifi.tether/bin/iwconfig $1 mode Ad-Hoc
10 | /data/data/com.googlecode.android.wifi.tether/bin/iwconfig $1 essid $2
11 | /data/data/com.googlecode.android.wifi.tether/bin/iwconfig $1 channel $3
12 | break;
13 | esac;
14 | break;
15 | done
16 | done
17 |
--------------------------------------------------------------------------------
/res/raw/hostapd_conf_droi:
--------------------------------------------------------------------------------
1 | interface=tiwlan0
2 | driver=wilink
3 | logger_syslog=-1
4 | logger_syslog_level=2
5 | logger_stdout=-1
6 | logger_stdout_level=2
7 | dump_file=/tmp/hostapd.dump
8 | hw_mode=g
9 | beacon_int=100
10 | dtim_period=2
11 | max_num_sta=5
12 | rts_threshold=2347
13 | fragm_threshold=2346
14 | supported_rates=10 20 55 110 60 90 120 180 240 360 480 540
15 | macaddr_acl=0
16 | auth_algs=1
17 | ignore_broadcast_ssid=0
18 | wme_enabled=0
19 | wme_ac_bk_cwmin=4
20 | wme_ac_bk_cwmax=10
21 | wme_ac_bk_aifs=7
22 | wme_ac_bk_txop_limit=0
23 | wme_ac_bk_acm=0
24 | wme_ac_be_aifs=3
25 | wme_ac_be_cwmin=4
26 | wme_ac_be_cwmax=10
27 | wme_ac_be_txop_limit=0
28 | wme_ac_be_acm=0
29 | wme_ac_vi_aifs=2
30 | wme_ac_vi_cwmin=3
31 | wme_ac_vi_cwmax=4
32 | wme_ac_vi_txop_limit=94
33 | wme_ac_vi_acm=0
34 | wme_ac_vo_aifs=2
35 | wme_ac_vo_cwmin=2
36 | wme_ac_vo_cwmax=3
37 | wme_ac_vo_txop_limit=47
38 | wme_ac_vo_acm=0
39 | ap_max_inactivity=30
40 | wep_rekey_period=0
41 | eap_server=0
42 | own_ip_addr=127.0.0.1
43 | wpa_group_rekey=0
44 | wpa_gmk_rekey=0
45 | wpa_ptk_rekey=0
--------------------------------------------------------------------------------
/res/raw/hostapd_conf_mini:
--------------------------------------------------------------------------------
1 | interface=wlan0
2 | ssid=AndroidTether
3 | auth_algs=1
4 | max_num_sta=8
5 | beacon_int=100
6 | dtim_period=1
7 | channel_num=1
8 | preamble=0
--------------------------------------------------------------------------------
/res/raw/hostapd_conf_tiap:
--------------------------------------------------------------------------------
1 | interface=tiap0
2 | driver=wilink
3 | logger_syslog=-1
4 | logger_syslog_level=2
5 | logger_stdout=-1
6 | logger_stdout_level=2
7 | dump_file=/data/misc/wifi/hostapd.dump
8 | ctrl_interface=/dev/socket
9 | ctrl_interface_group=wifi
10 | ssid=AndroidTether
11 | hw_mode=g
12 | channel=11
13 | beacon_int=100
14 | dtim_period=2
15 | max_num_sta=8
16 | supported_rates=10 20 55 110 60 90 120 180 240 360 480 540
17 | preamble=1
18 | macaddr_acl=0
19 | accept_mac_file=/data/misc/wifi/hostapd.accept
20 | deny_mac_file=/data/misc/wifi/hostapd.deny
21 | auth_algs=1
22 | ignore_broadcast_ssid=0
23 | wme_enabled=0
24 | ap_max_inactivity=60
25 | wep_rekey_period=0
26 | eap_server=0
27 | own_ip_addr=127.0.0.1
28 | wpa_group_rekey=0
29 | wpa_gmk_rekey=0
30 | wpa_ptk_rekey=0
31 | ap_table_max_size=255
32 | ap_table_expiration_time=60
--------------------------------------------------------------------------------
/res/raw/ifconfig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/raw/ifconfig
--------------------------------------------------------------------------------
/res/raw/iptables:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/raw/iptables
--------------------------------------------------------------------------------
/res/raw/iwconfig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/raw/iwconfig
--------------------------------------------------------------------------------
/res/raw/rfkill:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/raw/rfkill
--------------------------------------------------------------------------------
/res/raw/tether:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mmorciegov/android-wifi-tether/6231e1968be59c7a7499e45807121aad24c0579d/res/raw/tether
--------------------------------------------------------------------------------
/res/raw/tiwlan_ini:
--------------------------------------------------------------------------------
1 | EEPROMlessModeSupported = 1
2 | WME_Enable = 1
3 | dot11NetworkType = 3
4 | RecoveryEnable = 1
5 | TriggerFcs = 0
6 | dot11FragmentationThreshold = 4096
7 | dot11RTSThreshold = 4096
8 | WPAMixedMode = 1
9 | RSNPreAuthentication = 1
10 | CalibrationChannel24 = 1
11 | CalibrationChannel5 = 36
12 | AllowedChannelsTable24 = FFFFFFFFFFFFFFFFFFFFFFFFFFFF
13 | AllowedChannelsTable5 = FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF0000000000000000000000000000000000000000000000000000000000000000000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF0000000000000000FF000000FF000000FF000000FF00000000000000000000000000000000000000
14 | SpectrumManagement = 0
15 | RxBroadcastInPs = 1
16 | FirstConnScanEnabled = 1
17 | ArpIp_Addr = c0 a8 00 5e
18 | ArpIp_Filter_ena = 0
19 | Mac_Filter_Enabled = 0
20 | numGroupAddrs = 4
21 | Group_addr0 = 10 01 02 03 04 05
22 | Group_addr1 = 11 11 12 13 14 15
23 | Group_addr2 = 12 21 22 23 24 25
24 | Group_addr3 = 13 31 32 33 34 35
25 | Group_addr4 = 14 41 42 43 44 45
26 | Group_addr5 = 15 51 52 53 54 55
27 | Group_addr6 = 16 61 62 63 64 65
28 | Group_addr7 = 17 71 72 73 74 75
29 | Beacon_Filter_Desired_State = 1
30 | Beacon_Filter_Stored = 1
31 | Beacon_IE_Num_Of_Elem = 15
32 | Beacon_IE_Table_Size = 35
33 | Beacon_IE_Table = 00 01 01 01 32 01 2a 01 03 01 06 01 07 01 20 01 25 01 23 01 30 01 28 01 2e 01 85 01 dd 00 52 f2 02 00 01
34 | RateContThreshold = 10
35 | RateStepUpThreshold = 2
36 | FBShortInterval = 40
37 | FBLongInterval = 200
38 | RateAdaptationTimeout = 300
39 | RatePolicyUserShortRetryLimit = 10
40 | RatePolicyUserLongRetryLimit = 10
41 | RatePolicyUserRetriesPerRateCck = 1,1,1,1,1,1,1,1,1,1,1,1,1
42 | RatePolicyUserRetriesPerRatePbcc = 1,1,1,1,1,1,1,1,1,1,1,1,1
43 | RatePolicyUserRetriesPerRateOfdm = 0,0,0,1,0,0,0,1,0,0,1,1,1
44 | RatePolicyUserRetriesPerRateOfdmA = 0,0,0,1,0,0,1,0,0,1,0,0,0
45 | RatePolicySGRetriesPerRateCck = 1,1,1,1,1,1,1,5,1,1,1,1,1
46 | RatePolicySGRetriesPerRatePbcc = 1,1,1,1,1,1,1,5,1,1,1,1,1
47 | RatePolicySGRetriesPerRateOfdm = 1,1,1,1,1,1,1,5,1,1,1,1,1
48 | RatePolicySGRetriesPerRateOfdmA = 1,1,1,1,1,1,1,5,1,1,1,1,1
49 | BeaconListenInterval = 1
50 | DtimListenInterval = 1
51 | dot11PowerMode = 1
52 | PowerMgmtHangOverPeriod = 5
53 | AutoPowerModeDozeMode = 2
54 | AutoPowerModeActiveTh = 15
55 | AutoPowerModeDozeTh = 8
56 | defaultPowerLevel = 0
57 | PowerSavePowerLevel = 0
58 | OsDbgState = 0x01e9003c
59 | ReportSeverityTable = "00011010000"
60 | BeaconReceiveTime = 50
61 | FirstConnScanBandB_ChannelList = 1,2,3,4,5,6,7,8,9,10,11,12,13,14
62 | FirstConnScanBandB_MinDwellTime = 30000
63 | FirstConnScanBandB_MaxDwellTime = 60000
64 | FirstConnScanBandB_NumOfProbReqs = 3
65 | FirstConnScanBandB_ProbReqRate = 2
66 | FirstConnScanBandB_TxPowerLevel = 255
67 | FirstConnScanBandA_ChannelList = 36,40,44,48,52,56,60,64,100,104,108,112,149,153,157,161
68 | FirstConnScanBandA_MinDwellTime = 30000
69 | FirstConnScanBandA_MaxDwellTime = 60000
70 | FirstConnScanBandA_NumOfProbReqs = 3
71 | FirstConnScanBandA_ProbReqRate = 32
72 | FirstConnScanBandA_TxPowerLevel = 255
73 | desiredPsMode = 0
74 | QOS_wmePsModeBE = 0
75 | QOS_wmePsModeBK = 0
76 | QOS_wmePsModeVI = 0
77 | QOS_wmePsModeVO = 0
78 | Clsfr_Type = 1
79 | NumOfDstIPPortClassifiers = 3
80 | IPPortClassifier00_IPAddress = 0a 03 89 02
81 | IPPortClassifier00_Port = 5001
82 | IPPortClassifier00_DTag = 1
83 | IPPortClassifier01_IPAddress = 0a 03 89 02
84 | IPPortClassifier01_Port = 5002
85 | IPPortClassifier01_DTag = 4
86 | IPPortClassifier02_IPAddress = 0a 03 89 02
87 | IPPortClassifier02_Port = 5003
88 | IPPortClassifier02_DTag = 6
89 | NumOfCodePoints = 4
90 | DSCPClassifier00_CodePoint = 0
91 | DSCPClassifier00_DTag = 0
92 | DSCPClassifier01_CodePoint = 8
93 | DSCPClassifier01_DTag = 1
94 | DSCPClassifier02_CodePoint = 40
95 | DSCPClassifier02_DTag = 5
96 | DSCPClassifier03_CodePoint = 56
97 | DSCPClassifier03_DTag = 7
98 | dot11MaxReceiveLifetime=512000
99 | FracOfLifeTimeToDrop = 50
100 | WiFiAdhoc = 1
101 | dot11DesiredChannel = 6
102 | dot11DesiredSSID = AndroidTether
103 | dot11DesiredBSSType = 0
104 | WiFiWmmPS = 0
105 | EarlyWakeUp = 1
106 | TxEnergyDetection = 0
107 | TriggeredScanTimeOut = 50000
108 | PsPollDeliveryFailureRecoveryPeriod = 20
109 | ConsecutivePsPollDeliveryFailureThreshold = 4
110 | BThWlanCoexistEnable = 2
111 |
--------------------------------------------------------------------------------
/res/raw/wpa_supplicant_conf:
--------------------------------------------------------------------------------
1 | update_config=0
2 | ctrl_interface=/data/local/tmp/wpa_supplicant
3 | eapol_version=1
4 | ap_scan=2
5 | fast_reauth=0
6 | network={
7 | ssid="AndroidTether"
8 | scan_ssid=1
9 | mode=1
10 | key_mgmt=NONE
11 | group=WEP104
12 | auth_alg=SHARED
13 | wep_key0="abcdefghijklm"
14 | }
15 |
--------------------------------------------------------------------------------
/res/values-v11/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
--------------------------------------------------------------------------------
/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #00000000
4 | #FF000000
5 | #FFFFFFFF
6 | #A0909090
7 | #FFFF2211
8 | #FF00B627
9 |
10 |
--------------------------------------------------------------------------------
/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
--------------------------------------------------------------------------------
/res/xml/appwidget_info.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
23 |
24 |
--------------------------------------------------------------------------------
/src/com/googlecode/android/wifi/tether/AccessControlActivity.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This program is free software; you can redistribute it and/or modify it under
3 | * the terms of the GNU General Public License as published by the Free Software
4 | * Foundation; either version 3 of the License, or (at your option) any later
5 | * version.
6 | * You should have received a copy of the GNU General Public License along with
7 | * this program; if not, see .
8 | * Use this application at your own risk.
9 | *
10 | * Copyright (c) 2009 by Harald Mueller and Sofia Lemons.
11 | */
12 |
13 | package com.googlecode.android.wifi.tether;
14 |
15 | import java.io.IOException;
16 | import java.util.ArrayList;
17 | import java.util.Enumeration;
18 | import java.util.Hashtable;
19 |
20 | import com.googlecode.android.wifi.tether.data.ClientAdapter;
21 | import com.googlecode.android.wifi.tether.data.ClientData;
22 | import com.googlecode.android.wifi.tether.system.CoreTask;
23 |
24 | import android.R.drawable;
25 | import android.app.ListActivity;
26 | import android.os.Bundle;
27 | import android.os.Handler;
28 | import android.os.Looper;
29 | import android.os.Message;
30 | import android.util.Log;
31 | import android.view.Menu;
32 | import android.view.MenuItem;
33 | import android.view.SubMenu;
34 | import android.view.View;
35 | import android.view.View.OnClickListener;
36 | import android.widget.Button;
37 | import android.widget.RelativeLayout;
38 | import android.widget.TextView;
39 | import android.widget.ToggleButton;
40 |
41 | public class AccessControlActivity extends ListActivity {
42 |
43 | private TetherApplication application = null;
44 |
45 | private ToggleButton buttonAC = null;
46 | private Button buttonApply = null;
47 | private TextView statusAC = null;
48 | private RelativeLayout applyFooterAC = null;
49 |
50 | private ClientAdapter clientAdapter;
51 |
52 | public CoreTask.Whitelist whitelist;
53 |
54 | public static final String TAG = "TETHER -> AccessControlActivity";
55 | public static AccessControlActivity currentInstance = null;
56 |
57 | private static void setCurrent(AccessControlActivity current){
58 | AccessControlActivity.currentInstance = current;
59 | }
60 |
61 | @Override
62 | public void onCreate(Bundle savedInstanceState) {
63 | Log.d(TAG, "Calling onCreate()");
64 | super.onCreate(savedInstanceState);
65 | setContentView(R.layout.accesscontrolview);
66 |
67 | // Init Application
68 | this.application = (TetherApplication)this.getApplication();
69 | this.whitelist = this.application.whitelist;
70 |
71 | // Status-Text
72 | this.statusAC = (TextView)findViewById(R.id.statusAC);
73 |
74 | // Footer
75 | this.applyFooterAC = (RelativeLayout)findViewById(R.id.layoutFooterAC);
76 |
77 | // Buttons
78 | this.buttonAC = (ToggleButton)findViewById(R.id.buttonAC);
79 | this.buttonAC.setOnClickListener(new OnClickListener() {
80 | public void onClick(View v) {
81 | if (buttonAC.isChecked() == false) {
82 | Log.d(TAG, "Disable pressed ...");
83 | if (whitelist.remove()) {
84 | AccessControlActivity.this.application.displayToastMessage(getString(R.string.accesscontrol_activity_disabled));
85 | AccessControlActivity.this.clientAdapter.refreshData(AccessControlActivity.this.getCurrentClientData());
86 | if (TetherService.singleton != null && TetherService.singleton.getState() == TetherService.STATE_RUNNING) {
87 | TetherService.singleton.reloadACRules();
88 | }
89 | AccessControlActivity.this.application.preferenceEditor.putBoolean("acpref", false);
90 | AccessControlActivity.this.application.preferenceEditor.commit();
91 | AccessControlActivity.this.toggleACHeader();
92 | }
93 | }
94 | else {
95 | Log.d(TAG, "Enable pressed ...");
96 | try {
97 | whitelist.touch();
98 | AccessControlActivity.this.application.displayToastMessage(getString(R.string.accesscontrol_activity_enabled));
99 | AccessControlActivity.this.clientAdapter.refreshData(AccessControlActivity.this.getCurrentClientData());
100 | if (TetherService.singleton != null && TetherService.singleton.getState() == TetherService.STATE_RUNNING) {
101 | TetherService.singleton.reloadACRules();
102 | }
103 | AccessControlActivity.this.application.preferenceEditor.putBoolean("acpref", true);
104 | AccessControlActivity.this.application.preferenceEditor.commit();
105 | AccessControlActivity.this.toggleACHeader();
106 | } catch (IOException e) {
107 | // nothing
108 | }
109 | }
110 | }
111 | });
112 | this.buttonApply = (Button)findViewById(R.id.buttonApplyAC);
113 | this.buttonApply.setOnClickListener(new OnClickListener() {
114 | public void onClick(View v) {
115 | Log.d(TAG, "Apply pressed ...");
116 | AccessControlActivity.this.saveWhiteList();
117 | AccessControlActivity.this.clientAdapter.saveRequired = false;
118 | AccessControlActivity.this.toggleACFooter();
119 | if (TetherService.singleton != null && TetherService.singleton.getState() == TetherService.STATE_RUNNING) {
120 | TetherService.singleton.reloadACRules();
121 | }
122 | }
123 | });
124 |
125 | // Init Application
126 | this.application = (TetherApplication)this.getApplication();
127 |
128 | // Init Clientadapter
129 | AccessControlActivity.setCurrent(this);
130 | this.clientAdapter = new ClientAdapter(this, this.getCurrentClientData(), this.application);
131 | this.setListAdapter(this.clientAdapter);
132 |
133 | // "Toggle" header and footer
134 | this.toggleACHeader();
135 | this.toggleACFooter();
136 | }
137 |
138 |
139 | @Override
140 | protected void onStop() {
141 | Log.d(TAG, "Calling onStop()");
142 | if (this.clientAdapter.saveRequired) {
143 | this.saveWhiteList();
144 | this.clientAdapter.saveRequired = false;
145 | if (TetherService.singleton != null && TetherService.singleton.getState() == TetherService.STATE_RUNNING) {
146 | TetherService.singleton.reloadACRules();
147 | }
148 | }
149 | super.onStop();
150 | }
151 |
152 | @Override
153 | protected void onDestroy() {
154 | Log.d(TAG, "Calling onDestroy()");
155 | super.onDestroy();
156 | }
157 |
158 |
159 | @Override
160 | protected void onResume() {
161 | Log.d(TAG, "Calling onResume()");
162 | super.onResume();
163 | this.toggleACHeader();
164 | this.updateListView();
165 | }
166 |
167 |
168 | private void toggleACHeader() {
169 | if (whitelist.exists()) {
170 | this.statusAC.setText(getString(R.string.accesscontrol_activity_is_enabled));
171 | this.buttonAC.setChecked(true);
172 | }
173 | else {
174 | this.statusAC.setText(getString(R.string.accesscontrol_activity_is_disabled));
175 | this.buttonAC.setChecked(false);
176 | }
177 | }
178 |
179 | public void toggleACFooter() {
180 | if (this.clientAdapter.saveRequired)
181 | this.applyFooterAC.setVisibility(View.VISIBLE);
182 | else
183 | this.applyFooterAC.setVisibility(View.GONE);
184 | }
185 |
186 | // Handler
187 | Handler clientConnectHandler = new Handler() {
188 | public void handleMessage(Message msg) {
189 | AccessControlActivity.this.updateListView();
190 | }
191 | };
192 |
193 | private void saveWhiteList() {
194 | Log.d(TAG, "Saving whitelist ...");
195 | new Thread(new Runnable(){
196 | public void run(){
197 | Looper.prepare();
198 | if (whitelist.exists()) {
199 | whitelist.whitelist.clear();
200 | for (ClientData tmpClientData : AccessControlActivity.this.clientAdapter.getClientData()) {
201 | if (tmpClientData.isAccessAllowed()) {
202 | whitelist.whitelist.add(tmpClientData.getMacAddress());
203 | }
204 | }
205 | try {
206 | whitelist.save();
207 | if (TetherService.singleton != null && TetherService.singleton.getState() == TetherService.STATE_RUNNING) {
208 | TetherService.singleton.reloadACRules();
209 | }
210 | }
211 | catch (Exception ex) {
212 | application.displayToastMessage(getString(R.string.accesscontrol_activity_error_save_whitelistfile));
213 | }
214 | }
215 | else {
216 | if (whitelist.exists()) {
217 | if (!whitelist.remove()) {
218 | application.displayToastMessage(getString(R.string.accesscontrol_activity_error_remove_whitelistfile));
219 | }
220 | }
221 | }
222 | application.displayToastMessage(getString(R.string.accesscontrol_activity_config_saved));
223 | Looper.loop();
224 | }
225 | }).start();
226 | }
227 |
228 | private void updateListView() {
229 | ArrayList clientDataAddList = this.application.getClientDataAddList();
230 | ArrayList clientMacRemoveList = this.application.getClientMacRemoveList();
231 | for (ClientData tmpClientData : clientDataAddList) {
232 | this.clientAdapter.addClient(tmpClientData);
233 | }
234 | for (String tmpMac : clientMacRemoveList) {
235 | this.clientAdapter.removeClient(tmpMac);
236 | }
237 | }
238 |
239 | private ArrayList getCurrentClientData() {
240 | ArrayList clientDataList = new ArrayList();
241 | Hashtable leases = null;
242 | try {
243 | leases = application.coretask.getLeases();
244 | } catch (Exception e) {
245 | AccessControlActivity.this.application.displayToastMessage(getString(R.string.accesscontrol_activity_error_read_leasefile));
246 | }
247 | if (whitelist != null) {
248 | for (String macAddress : whitelist.get()) {
249 | ClientData clientData = new ClientData();
250 | clientData.setConnected(false);
251 | clientData.setIpAddress(getString(R.string.accesscontrol_activity_not_connected));
252 | if (leases.containsKey(macAddress)) {
253 | clientData = leases.get(macAddress);
254 | Log.d(TAG, clientData.isConnected()+" - "+clientData.getIpAddress());
255 | leases.remove(macAddress);
256 | }
257 | clientData.setAccessAllowed(true);
258 | clientData.setMacAddress(macAddress);
259 | clientDataList.add(clientData);
260 | }
261 | }
262 | if (leases != null) {
263 | Enumeration enumLeases = leases.keys();
264 | while (enumLeases.hasMoreElements()) {
265 | String macAddress = enumLeases.nextElement();
266 | clientDataList.add(leases.get(macAddress));
267 | }
268 | }
269 |
270 | // Reset client-mac-lists
271 | this.application.resetClientMacLists();
272 |
273 | return clientDataList;
274 | }
275 |
276 | private static final int MENU_RELOAD_CLIENTS = 0;
277 | private static final int MENU_APPLY = 1;
278 |
279 | @Override
280 | public boolean onCreateOptionsMenu(Menu menu) {
281 | boolean supRetVal = super.onCreateOptionsMenu(menu);
282 | SubMenu refreshClientList = menu.addSubMenu(0, MENU_RELOAD_CLIENTS, 0, getString(R.string.accesscontrol_activity_reloadclientlist));
283 | refreshClientList.setIcon(drawable.ic_menu_revert);
284 | SubMenu saveWhitelist = menu.addSubMenu(0, MENU_APPLY, 0, getString(R.string.accesscontrol_activity_applysettings));
285 | saveWhitelist.setIcon(drawable.ic_menu_save);
286 | return supRetVal;
287 | }
288 |
289 | @Override
290 | public boolean onOptionsItemSelected(MenuItem menuItem) {
291 | boolean supRetVal = super.onOptionsItemSelected(menuItem);
292 | Log.d(TAG, "Menuitem:getId - "+menuItem.getItemId());
293 | switch (menuItem.getItemId()) {
294 | case MENU_APPLY :
295 | this.saveWhiteList();
296 | this.clientAdapter.saveRequired = false;
297 | this.toggleACFooter();
298 | if (TetherService.singleton != null && TetherService.singleton.getState() == TetherService.STATE_RUNNING) {
299 | TetherService.singleton.reloadACRules();
300 | }
301 | break;
302 | case MENU_RELOAD_CLIENTS :
303 | this.clientAdapter.refreshData(AccessControlActivity.this.getCurrentClientData());
304 | }
305 | return supRetVal;
306 | }
307 | }
308 |
--------------------------------------------------------------------------------
/src/com/googlecode/android/wifi/tether/LogActivity.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This program is free software; you can redistribute it and/or modify it under
3 | * the terms of the GNU General Public License as published by the Free Software
4 | * Foundation; either version 3 of the License, or (at your option) any later
5 | * version.
6 | * You should have received a copy of the GNU General Public License along with
7 | * this program; if not, see .
8 | * Use this application at your own risk.
9 | *
10 | * Copyright (c) 2009 by Harald Mueller and Sofia Lemons.
11 | */
12 |
13 | package com.googlecode.android.wifi.tether;
14 |
15 | import java.io.File;
16 | import java.io.FileInputStream;
17 | import java.io.InputStreamReader;
18 |
19 | import com.googlecode.android.wifi.tether.system.CoreTask;
20 |
21 | import android.app.Activity;
22 | import android.os.Bundle;
23 | import android.webkit.WebSettings;
24 | import android.webkit.WebView;
25 |
26 | public class LogActivity extends Activity {
27 |
28 | public static final String MSG_TAG = "TETHER -> AccessControlActivity";
29 |
30 | private static final String HEADER = "background-color "+
31 | " "+
38 | "";
39 | private static final String FOOTER = "";
40 |
41 | private WebView webView = null;
42 |
43 | private TetherApplication application;
44 |
45 | @Override
46 | public void onCreate(Bundle savedInstanceState) {
47 | super.onCreate(savedInstanceState);
48 | setContentView(R.layout.logview);
49 |
50 | // Init Application
51 | this.application = (TetherApplication)this.getApplication();
52 |
53 | this.webView = (WebView) findViewById(R.id.webviewLog);
54 | this.webView.getSettings().setJavaScriptEnabled(false);
55 | this.webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
56 | this.webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
57 |
58 | // this.webView.getSettings().setPluginState(WebSettings.PluginState.OFF);
59 | // this.webView.getSettings().setPluginsEnabled(false);
60 | this.webView.getSettings().setSupportMultipleWindows(false);
61 | this.webView.getSettings().setSupportZoom(false);
62 | this.setWebViewContent();
63 | }
64 |
65 | private void setWebViewContent() {
66 | this.webView.loadDataWithBaseURL("fake://fakeme",HEADER+this.readLogfile()+FOOTER , "text/html", "UTF-8", "fake://fakeme");
67 | }
68 |
69 | private String readLogfile(){
70 | FileInputStream fis = null;
71 | InputStreamReader isr = null;
72 | String data = "";
73 | try{
74 | File file = new File(CoreTask.DATA_FILE_PATH+"/var/tether.log");
75 | fis = new FileInputStream(file);
76 | isr = new InputStreamReader(fis, "utf-8");
77 | char[] buff = new char[(int) file.length()];
78 | isr.read(buff);
79 | data = new String(buff);
80 | }
81 | catch (Exception e) {
82 | e.printStackTrace();
83 | this.application.displayToastMessage(getString(R.string.log_activity_nologfile));
84 | }
85 | finally {
86 | try {
87 | if (isr != null)
88 | isr.close();
89 | if (fis != null)
90 | fis.close();
91 | } catch (Exception e) {
92 | // nothing
93 | }
94 | }
95 | return data;
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/src/com/googlecode/android/wifi/tether/TetherServiceReceiver.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This program is free software; you can redistribute it and/or modify it under
3 | * the terms of the GNU General Public License as published by the Free Software
4 | * Foundation; either version 3 of the License, or (at your option) any later
5 | * version.
6 | * You should have received a copy of the GNU General Public License along with
7 | * this program; if not, see .
8 | * Use this application at your own risk.
9 | *
10 | * Copyright (c) 2011 by Harald Mueller
11 | */
12 |
13 | package com.googlecode.android.wifi.tether;
14 |
15 | import android.content.BroadcastReceiver;
16 | import android.content.ComponentName;
17 | import android.content.Context;
18 | import android.content.Intent;
19 | import android.util.Log;
20 |
21 | public class TetherServiceReceiver extends BroadcastReceiver {
22 | final static String TAG = "ServiceStartupReceiver";
23 | @Override
24 | public void onReceive(Context context, Intent intent) {
25 |
26 | Intent serviceIntent = new Intent();
27 | serviceIntent.setComponent(
28 | new ComponentName("com.googlecode.android.wifi.tether",
29 | "com.googlecode.android.wifi.tether.TetherService"));
30 |
31 | Log.d(TAG, "onReceive " + intent.getAction());
32 | if (intent.getAction().equals(TetherService.SERVICEMANAGE_INTENT)) {
33 | switch (intent.getIntExtra("state", TetherService.SERVICE_START)) {
34 | case TetherService.SERVICE_START :
35 | if (TetherService.singleton == null) {
36 | context.startService(serviceIntent);
37 | }
38 | else {
39 | sendServiceBroadcast(context, TetherService.SERVICE_STARTED);
40 | }
41 | break;
42 | case TetherService.SERVICE_STARTED :
43 | if (TetherService.singleton != null)
44 | TetherService.singleton.start();
45 | break;
46 | case TetherService.SERVICE_STOP :
47 | if (TetherService.singleton != null)
48 | TetherService.singleton.stop();
49 | break;
50 | case TetherService.SERVICE_STOPPED :
51 | if (TetherService.singleton != null)
52 | TetherService.singleton.stopSelf();
53 | break;
54 | }
55 | }
56 | }
57 |
58 | private void sendServiceBroadcast(Context context, int state) {
59 | Intent intent = new Intent(TetherService.SERVICEMANAGE_INTENT);
60 | intent.setAction(TetherService.SERVICEMANAGE_INTENT);
61 | intent.putExtra("state", state);
62 | context.sendBroadcast(intent);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/com/googlecode/android/wifi/tether/WifiStateChangeReceiver.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This program is free software; you can redistribute it and/or modify it under
3 | * the terms of the GNU General Public License as published by the Free Software
4 | * Foundation; either version 3 of the License, or (at your option) any later
5 | * version.
6 | * You should have received a copy of the GNU General Public License along with
7 | * this program; if not, see .
8 | * Use this application at your own risk.
9 | *
10 | * Copyright (c) 2011 by Harald Mueller
11 | */
12 |
13 | package com.googlecode.android.wifi.tether;
14 |
15 | import android.content.BroadcastReceiver;
16 | import android.content.Context;
17 | import android.content.Intent;
18 | import android.util.Log;
19 |
20 | public class WifiStateChangeReceiver extends BroadcastReceiver {
21 | final static String TAG = "WifiStateChangeReceiver";
22 | @Override
23 | public void onReceive(Context context, Intent intent) {
24 | if (TetherService.singleton != null
25 | && TetherService.singleton.getState() == TetherService.STATE_RUNNING) {
26 | Log.d(TAG, "Phone takes control back over the wifi-interface!");
27 | ((TetherApplication)TetherService.singleton.getApplication()).displayToastMessage("What the hell!\nYour phone takes back control over the wifi-interface.\nImmediate tethering-shutdown NOW!");
28 | TetherService.singleton.stop();
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/com/googlecode/android/wifi/tether/data/ClientAdapter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This program is free software; you can redistribute it and/or modify it under
3 | * the terms of the GNU General Public License as published by the Free Software
4 | * Foundation; either version 3 of the License, or (at your option) any later
5 | * version.
6 | * You should have received a copy of the GNU General Public License along with
7 | * this program; if not, see .
8 | * Use this application at your own risk.
9 | *
10 | * Copyright (c) 2009 by Harald Mueller and Sofia Lemons.
11 | */
12 |
13 | package com.googlecode.android.wifi.tether.data;
14 |
15 | import java.util.ArrayList;
16 |
17 | import com.googlecode.android.wifi.tether.AccessControlActivity;
18 | import com.googlecode.android.wifi.tether.R;
19 | import com.googlecode.android.wifi.tether.TetherApplication;
20 |
21 | import android.graphics.Color;
22 | import android.util.Log;
23 | import android.view.LayoutInflater;
24 | import android.view.View;
25 | import android.view.ViewGroup;
26 | import android.widget.BaseAdapter;
27 | import android.widget.CheckBox;
28 | import android.widget.CompoundButton;
29 | import android.widget.TextView;
30 | import android.widget.CompoundButton.OnCheckedChangeListener;
31 |
32 | public class ClientAdapter extends BaseAdapter {
33 |
34 | public static final String TAG = "TETHER -> ClientAdapter";
35 |
36 | private LayoutInflater inflater;
37 | private ArrayList rows = new ArrayList();
38 |
39 | public boolean saveRequired = false;
40 | public boolean accessControlActive = false;
41 |
42 | public TetherApplication application;
43 | public AccessControlActivity accessControlActivity;
44 |
45 | public ClientAdapter(AccessControlActivity accessControlActivity, ArrayList rows, TetherApplication app) {
46 | super();
47 | this.accessControlActivity = accessControlActivity;
48 | this.application = app;
49 | this.accessControlActive = application.whitelist.exists();
50 | this.rows = rows;
51 | this.inflater = LayoutInflater.from(accessControlActivity);
52 | }
53 |
54 | public ArrayList getClientData() {
55 | return this.rows;
56 | }
57 |
58 | public synchronized void refreshData(ArrayList rows) {
59 | this.accessControlActive = application.whitelist.exists();
60 | this.rows = rows;
61 | this.notifyDataSetChanged();
62 | }
63 |
64 | public synchronized void addClient(ClientData clientData) {
65 | Log.d(TAG, "addClient() called: = "+clientData.getClientName());
66 | this.rows.add(clientData);
67 | this.notifyDataSetChanged();
68 | }
69 |
70 | public synchronized void removeClient(String mac) {
71 | for (int i=0;i "+tmpClientData.getClientName()+"-"+tmpClientData.isAccessAllowed());
86 | this.rows.set(position, tmpClientData);
87 | this.saveRequired = true;
88 | this.accessControlActivity.toggleACFooter();
89 | }
90 | }
91 |
92 | public View getView(final int position, View returnView, ViewGroup parent) {
93 | Log.d(TAG, "getView() called: position = "+position);
94 | ClientData row = this.rows.get(position);
95 |
96 | returnView = inflater.inflate(R.layout.clientrow, null);
97 | TextView macaddress = (TextView) returnView.findViewById(R.id.macaddress);
98 | TextView clientname = (TextView) returnView.findViewById(R.id.clientname);
99 | TextView ipaddress = (TextView) returnView.findViewById(R.id.ipaddress);
100 | CheckBox checkBoxAllowed = (CheckBox) returnView.findViewById(R.id.checkBoxAllowed);
101 | if (this.accessControlActive == false) {
102 | checkBoxAllowed.setVisibility(View.GONE);
103 | }
104 | else {
105 | checkBoxAllowed.setOnCheckedChangeListener(new OnCheckedChangeListener() {
106 | public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
107 | toggleChecked(position, isChecked);
108 | }
109 | });
110 | }
111 | macaddress.setText(row.getMacAddress());
112 | if (row.isConnected()) {
113 | // Change textcolor to green
114 | macaddress.setTextColor(Color.rgb(0, 182, 39));
115 | clientname.setTextColor(Color.rgb(0, 182, 39));
116 | ipaddress.setTextColor(Color.rgb(0, 182, 39));
117 | if (row.getIpAddress() != null) {
118 | ipaddress.setText(row.getIpAddress());
119 | }
120 | if (row.getClientName() != null) {
121 | clientname.setText(row.getClientName());
122 | }
123 | }
124 | else {
125 | // Set connected-icon
126 | clientname.setText("- Unknown -");
127 | ipaddress.setText("- Not connected -");
128 | // Change textcolor to red
129 | macaddress.setTextColor(Color.rgb(255, 34, 17));
130 | clientname.setTextColor(Color.rgb(255, 34, 17));
131 | ipaddress.setTextColor(Color.rgb(255, 34, 17));
132 | }
133 | if (row.isAccessAllowed()) {
134 | checkBoxAllowed.setChecked(true);
135 |
136 | }
137 | return returnView;
138 | }
139 |
140 | public int getCount() {
141 | return rows.size();
142 | }
143 |
144 | public Object getItem(int position) {
145 | return rows.get(position);
146 | }
147 |
148 | public long getItemId(int position) {
149 | return position;
150 | }
151 | }
152 |
153 |
--------------------------------------------------------------------------------
/src/com/googlecode/android/wifi/tether/data/ClientData.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This program is free software; you can redistribute it and/or modify it under
3 | * the terms of the GNU General Public License as published by the Free Software
4 | * Foundation; either version 3 of the License, or (at your option) any later
5 | * version.
6 | * You should have received a copy of the GNU General Public License along with
7 | * this program; if not, see .
8 | * Use this application at your own risk.
9 | *
10 | * Copyright (c) 2009 by Harald Mueller and Sofia Lemons.
11 | */
12 |
13 | package com.googlecode.android.wifi.tether.data;
14 |
15 | import java.util.Date;
16 |
17 | public class ClientData {
18 | private boolean connected;
19 | private boolean accessAllowed;
20 | private String macAddress;
21 | private String clientName;
22 | private String ipAddress;
23 | private Date connectTime;
24 |
25 | public boolean isConnected() {
26 | return connected;
27 | }
28 | public void setConnected(boolean connected) {
29 | this.connected = connected;
30 | }
31 | public boolean isAccessAllowed() {
32 | return accessAllowed;
33 | }
34 | public void setAccessAllowed(boolean accessAllowed) {
35 | this.accessAllowed = accessAllowed;
36 | }
37 | public String getMacAddress() {
38 | return macAddress;
39 | }
40 | public void setMacAddress(String macAddress) {
41 | this.macAddress = macAddress;
42 | }
43 | public String getClientName() {
44 | return clientName;
45 | }
46 | public void setClientName(String clientName) {
47 | this.clientName = clientName;
48 | }
49 | public String getIpAddress() {
50 | return ipAddress;
51 | }
52 | public void setIpAddress(String ipAddress) {
53 | this.ipAddress = ipAddress;
54 | }
55 | public Date getConnectTime() {
56 | return connectTime;
57 | }
58 | public void setConnectTime(Date connectTime) {
59 | this.connectTime = connectTime;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/com/googlecode/android/wifi/tether/system/FallbackTether.java:
--------------------------------------------------------------------------------
1 | package com.googlecode.android.wifi.tether.system;
2 |
3 | import java.lang.reflect.Method;
4 | import android.app.Application;
5 | import android.net.wifi.WifiConfiguration;
6 | import android.net.wifi.WifiManager;
7 | import android.util.Log;
8 |
9 | public class FallbackTether extends Application {
10 | public static final String TAG = "TETHER -> FallbackTether";
11 |
12 | public static void controlStockTether(WifiManager wifimanager, boolean enabled, boolean encryptionEnabled, String passphrase) throws Exception {
13 |
14 | Log.d(TAG, "fallback tether mode starting: " + enabled);
15 | //Config setup
16 | WifiConfiguration config = new WifiConfiguration();
17 | config.SSID = "TetherFallback";
18 |
19 |
20 | if(!encryptionEnabled){
21 | Log.d(TAG, "open AP mode ");
22 | config.allowedKeyManagement.set(WifiConfiguration.AuthAlgorithm.OPEN);
23 | } else
24 | {
25 | Log.d(TAG, "Shared AP mode ");
26 | config.allowedKeyManagement.set(WifiConfiguration.AuthAlgorithm.SHARED);
27 | config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
28 | config.preSharedKey = passphrase;
29 | }
30 |
31 | //TODO: tkip
32 | //config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
33 | //config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
34 |
35 | //start AP
36 | Method method1 = wifimanager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
37 | method1.invoke(wifimanager, config, enabled);
38 |
39 | //checkstate
40 | Method getWifiApState = wifimanager.getClass().getMethod("getWifiApState");
41 | Integer state = (Integer) getWifiApState.invoke(wifimanager);
42 | Log.d(TAG, "fallback tether mode state is: " + state);
43 | }
44 |
45 | }
--------------------------------------------------------------------------------
/src/com/googlecode/android/wifi/tether/system/NativeTask.java:
--------------------------------------------------------------------------------
1 | package com.googlecode.android.wifi.tether.system;
2 |
3 | import android.util.Log;
4 |
5 | public class NativeTask {
6 |
7 | public static final String MSG_TAG = "TETHER -> NativeTask";
8 |
9 | static {
10 | try {
11 | Log.i(MSG_TAG, "Trying to load libwtnativetask.so");
12 | System.loadLibrary("wtnativetask");
13 | }
14 | catch (UnsatisfiedLinkError ule) {
15 | Log.e(MSG_TAG, "Could not load libwtnativetask.so");
16 | }
17 | }
18 | public static native String getProp(String name);
19 | public static native int runCommand(String command);
20 | }
21 |
--------------------------------------------------------------------------------
/src/com/googlecode/android/wifi/tether/system/ServiceHandler.java:
--------------------------------------------------------------------------------
1 | package com.googlecode.android.wifi.tether.system;
2 |
3 | import java.lang.reflect.Method;
4 | import android.app.Application;
5 | import android.os.IBinder;
6 | import android.util.Log;
7 |
8 | public class ServiceHandler extends Application {
9 | public static final String TAG = "TETHER -> ServiceHandler";
10 | /**
11 | private static IBinder getService(String service) throws Exception {
12 | Class> ServiceManager = Class.forName("android.os.ServiceManager");
13 | Method getService_method = ServiceManager.getMethod("getService", new Class[]{String.class});
14 | IBinder b = (IBinder)getService_method.invoke(null, new Object[]{service});
15 | return b;
16 | }**/
17 |
18 | public static void setMaxClients(IBinder binder, int clients) throws Exception {
19 |
20 | // IBinder binder = getService("network_management");
21 | Class> stub = Class.forName("android.os.INetworkManagementService$Stub");
22 | Method asInterface_method = stub.getMethod("asInterface", new Class[]{IBinder.class});
23 | Object asInterface = asInterface_method.invoke(null, new Object[] {binder});
24 |
25 | Log.d(TAG,"About to run SetMaxClient " + clients);
26 | Method setMaxClients_method = asInterface.getClass().getMethod("setMaxClient", new Class[]{int.class});
27 | setMaxClients_method.invoke(asInterface, new Object[]{clients});
28 | }
29 |
30 | public static void wifiFirmwareReload(IBinder binder, String Adaptor, String firmwaremode) throws Exception {
31 |
32 | //IBinder binder = getService("network_management");
33 | Class> stub = Class.forName("android.os.INetworkManagementService$Stub");
34 | Method asInterface_method = stub.getMethod("asInterface", new Class[]{IBinder.class});
35 | Object asInterface = asInterface_method.invoke(null, new Object[] {binder});
36 |
37 | //setInterfaceDown
38 | //setInterfaceUp
39 | Method setFirmwareMode_method = asInterface.getClass().getMethod("wifiFirmwareReload", new Class[]{String.class, String.class});
40 | setFirmwareMode_method.invoke(asInterface, new Object[]{Adaptor, firmwaremode});
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/com/googlecode/android/wifi/tether/system/UntetherHelper.java:
--------------------------------------------------------------------------------
1 | package com.googlecode.android.wifi.tether.system;
2 |
3 | import java.lang.reflect.Method;
4 |
5 | import android.content.Context;
6 |
7 | public class UntetherHelper {
8 |
9 | public static String[] getTetherableIfaces(Context context) {
10 | String[] tetherableIfaces = null;
11 | Object connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE);
12 | Method tetherableInterfaces = null;
13 | try {
14 | tetherableInterfaces = connectivityManager.getClass().getMethod("getTetherableIfaces", new Class[] { });
15 | } catch (Exception e) {
16 | e.printStackTrace();
17 | }
18 | try {
19 | tetherableIfaces = (String[])tetherableInterfaces.invoke(connectivityManager, new Object[] {});
20 |
21 | } catch (Exception e) {
22 | e.printStackTrace();
23 | }
24 | return tetherableIfaces;
25 | }
26 |
27 | public static int untetherIface(Context context, String iface) {
28 | int returnCode = -1;
29 | Object connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE);
30 | Method untether = null;
31 | try {
32 | untether = connectivityManager.getClass().getMethod("untether", new Class[] { String.class });
33 | } catch (Exception e) {
34 | e.printStackTrace();
35 | }
36 | try {
37 | returnCode = (Integer)untether.invoke(connectivityManager, new Object[] { iface });
38 |
39 | } catch (Exception e) {
40 | e.printStackTrace();
41 | }
42 | return returnCode;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/com/googlecode/android/wifi/tether/system/WebserviceTask.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This program is free software; you can redistribute it and/or modify it under
3 | * the terms of the GNU General Public License as published by the Free Software
4 | * Foundation; either version 3 of the License, or (at your option) any later
5 | * version.
6 | * You should have received a copy of the GNU General Public License along with
7 | * this program; if not, see .
8 | * Use this application at your own risk.
9 | *
10 | * Copyright (c) 2009 by Harald Mueller, Sofia Lemons and Ben Buxton.
11 | */
12 |
13 | package com.googlecode.android.wifi.tether.system;
14 |
15 | import java.io.BufferedInputStream;
16 | import java.io.File;
17 | import java.io.FileInputStream;
18 | import java.io.FileOutputStream;
19 | import java.io.IOException;
20 | import java.io.InputStream;
21 | import java.util.Properties;
22 | import java.util.zip.GZIPInputStream;
23 |
24 | import org.apache.http.HttpEntity;
25 | import org.apache.http.HttpResponse;
26 | import org.apache.http.StatusLine;
27 | import org.apache.http.client.HttpClient;
28 | import org.apache.http.client.methods.HttpGet;
29 | import org.apache.http.impl.client.DefaultHttpClient;
30 |
31 | import com.googlecode.android.wifi.tether.MainActivity;
32 |
33 | import android.os.Message;
34 | import android.util.Log;
35 |
36 | public class WebserviceTask {
37 |
38 | public static final String MSG_TAG = "TETHER -> WebserviceTask";
39 | public static final String DOWNLOAD_FILEPATH = "/sdcard/download";
40 | public static final String BLUETOOTH_FILEPATH = "/sdcard/android.tether";
41 |
42 | public MainActivity mainActivity;
43 |
44 | public Properties queryForProperty(String url) {
45 | Properties properties = null;
46 | HttpClient client = new DefaultHttpClient();
47 | HttpGet request = new HttpGet(String.format(url));
48 | try {
49 | HttpResponse response = client.execute(request);
50 |
51 | StatusLine status = response.getStatusLine();
52 | Log.d(MSG_TAG, "Request returned status " + status);
53 | if (status.getStatusCode() == 200) {
54 | HttpEntity entity = response.getEntity();
55 | properties = new Properties();
56 | properties.load(entity.getContent());
57 | }
58 | } catch (IOException e) {
59 | Log.d(MSG_TAG, "Can't get property '"+url+"'.");
60 | }
61 | return properties;
62 | }
63 |
64 | public boolean downloadUpdateFile(String downloadFileUrl, String destinationFilename) {
65 | if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED) == false) {
66 | return false;
67 | }
68 | File downloadDir = new File(DOWNLOAD_FILEPATH);
69 | if (downloadDir.exists() == false) {
70 | downloadDir.mkdirs();
71 | }
72 | else {
73 | File downloadFile = new File(DOWNLOAD_FILEPATH+"/"+destinationFilename);
74 | if (downloadFile.exists()) {
75 | downloadFile.delete();
76 | }
77 | }
78 | return this.downloadFile(downloadFileUrl, DOWNLOAD_FILEPATH, destinationFilename);
79 | }
80 |
81 | public boolean downloadBluetoothModule(String downloadFileUrl, String destinationFilename) {
82 | if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED) == false) {
83 | return false;
84 | }
85 | File bluetoothDir = new File(BLUETOOTH_FILEPATH);
86 | if (bluetoothDir.exists() == false) {
87 | bluetoothDir.mkdirs();
88 | }
89 | if (this.downloadFile(downloadFileUrl, "", destinationFilename) == true) {
90 | try {
91 | FileOutputStream out = new FileOutputStream(new File(destinationFilename.replace(".gz", "")));
92 | FileInputStream fis = new FileInputStream(destinationFilename);
93 | GZIPInputStream gzin = new GZIPInputStream(new BufferedInputStream(fis));
94 | int count;
95 | byte buf[] = new byte[8192];
96 | while ((count = gzin.read(buf, 0, 8192)) != -1) {
97 | //System.out.write(x);
98 | out.write(buf, 0, count);
99 | }
100 | out.flush();
101 | out.close();
102 | gzin.close();
103 | File inputFile = new File(destinationFilename);
104 | inputFile.delete();
105 | } catch (IOException e) {
106 | return false;
107 | }
108 | return true;
109 | } else
110 | return false;
111 | }
112 |
113 | public boolean downloadFile(String url, String destinationDirectory, String destinationFilename) {
114 | boolean filedownloaded = true;
115 | HttpClient client = new DefaultHttpClient();
116 | HttpGet request = new HttpGet(String.format(url));
117 | Message msg = Message.obtain();
118 | try {
119 | HttpResponse response = client.execute(request);
120 | StatusLine status = response.getStatusLine();
121 | Log.d(MSG_TAG, "Request returned status " + status);
122 | if (status.getStatusCode() == 200) {
123 | HttpEntity entity = response.getEntity();
124 | InputStream instream = entity.getContent();
125 | int fileSize = (int)entity.getContentLength();
126 | FileOutputStream out = new FileOutputStream(new File(destinationDirectory+"/"+destinationFilename));
127 | byte buf[] = new byte[8192];
128 | int len;
129 | int totalRead = 0;
130 | while((len = instream.read(buf)) > 0) {
131 | msg = Message.obtain();
132 | msg.what = MainActivity.MESSAGE_DOWNLOAD_PROGRESS;
133 | totalRead += len;
134 | msg.arg1 = totalRead / 1024;
135 | msg.arg2 = fileSize / 1024;
136 | MainActivity.currentInstance.viewUpdateHandler.sendMessage(msg);
137 | out.write(buf,0,len);
138 | }
139 | out.close();
140 | }
141 | else {
142 | throw new IOException();
143 | }
144 | } catch (IOException e) {
145 | Log.d(MSG_TAG, "Can't download file '"+url+"' to '" + destinationDirectory+"/"+destinationFilename + "'.");
146 | filedownloaded = false;
147 | }
148 | msg = Message.obtain();
149 | msg.what = MainActivity.MESSAGE_DOWNLOAD_COMPLETE;
150 | MainActivity.currentInstance.viewUpdateHandler.sendMessage(msg);
151 | return filedownloaded;
152 | }
153 | }
154 |
--------------------------------------------------------------------------------
/src/com/googlecode/android/wifi/tether/system/WimaxHelper.java:
--------------------------------------------------------------------------------
1 | package com.googlecode.android.wifi.tether.system;
2 |
3 | import java.lang.reflect.Method;
4 |
5 | import android.content.Context;
6 |
7 | public class WimaxHelper {
8 |
9 | public void htcWimax(Context context, boolean state) {
10 |
11 | //http://forum.xda-developers.com/archive/index.php/t-909206.html
12 | Object htcWimaxManager = context.getSystemService("wimax");
13 |
14 | Method setWimaxEnabled = null;
15 | try {
16 | setWimaxEnabled = htcWimaxManager.getClass().getMethod("setWimaxEnabled",
17 | new Class[] { Boolean.TYPE });
18 | } catch (Exception e) {
19 | e.printStackTrace();
20 | }
21 | try {
22 | if (state) {setWimaxEnabled.invoke(htcWimaxManager, new Object[] { Boolean.TRUE });}
23 | else {setWimaxEnabled.invoke(htcWimaxManager, new Object[] { Boolean.FALSE });}
24 | } catch (Exception e) {
25 | e.printStackTrace();
26 | }
27 | }
28 |
29 | public static void samsungWimax(Context context, boolean state) {
30 | //http://forum.xda-developers.com/archive/index.php/t-909206.html
31 | Object samsungWimaxManager = context.getSystemService("WiMax");
32 | Method setWimaxEnabled = null;
33 | try {
34 | setWimaxEnabled = samsungWimaxManager.getClass().getMethod("setWimaxEnabled",
35 | new Class[] { Boolean.TYPE });
36 | } catch (Exception e) {
37 | e.printStackTrace();
38 | }
39 | try {
40 | if (state) {setWimaxEnabled.invoke(samsungWimaxManager, new Object[] { Boolean.TRUE });}
41 | else {setWimaxEnabled.invoke(samsungWimaxManager, new Object[] { Boolean.FALSE });}
42 | } catch (Exception e) {
43 | e.printStackTrace();
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/com/googlecode/android/wifi/tether/ui/SeekBarPreference.java:
--------------------------------------------------------------------------------
1 | package com.googlecode.android.wifi.tether.ui;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.Gravity;
6 | import android.view.View;
7 | import android.preference.DialogPreference;
8 | import android.widget.SeekBar;
9 | import android.widget.TextView;
10 | import android.widget.LinearLayout;
11 |
12 |
13 | public class SeekBarPreference extends DialogPreference implements SeekBar.OnSeekBarChangeListener {
14 |
15 | private static final String androidns="http://schemas.android.com/apk/res/android";
16 |
17 | private SeekBar mSeekBar;
18 | private TextView mSplashText,mValueText;
19 | private Context mContext;
20 |
21 | private String mDialogMessage, mSuffix;
22 | private int mDefault, mMax, mValue = 0;
23 |
24 | public SeekBarPreference(Context context, AttributeSet attrs) {
25 | super(context,attrs);
26 | mContext = context;
27 |
28 | mDialogMessage = mContext.getString(attrs.getAttributeResourceValue(androidns,"dialogMessage", 0));
29 | mSuffix = " "+mContext.getString(attrs.getAttributeResourceValue(androidns,"text",0));
30 | mDefault = attrs.getAttributeIntValue(androidns,"defaultValue", 0);
31 | mMax = attrs.getAttributeIntValue(androidns,"max", 100);
32 | }
33 | @Override
34 | protected View onCreateDialogView() {
35 | LinearLayout.LayoutParams params;
36 | LinearLayout layout = new LinearLayout(mContext);
37 | layout.setOrientation(LinearLayout.VERTICAL);
38 | layout.setPadding(6,6,6,6);
39 |
40 | mSplashText = new TextView(mContext);
41 | if (mDialogMessage != null)
42 | mSplashText.setText(mDialogMessage);
43 | layout.addView(mSplashText);
44 |
45 | mValueText = new TextView(mContext);
46 | mValueText.setGravity(Gravity.CENTER_HORIZONTAL);
47 | mValueText.setTextSize(32);
48 | params = new LinearLayout.LayoutParams(
49 | LinearLayout.LayoutParams.MATCH_PARENT,
50 | LinearLayout.LayoutParams.WRAP_CONTENT);
51 | layout.addView(mValueText, params);
52 |
53 | mSeekBar = new SeekBar(mContext);
54 | mSeekBar.setOnSeekBarChangeListener(this);
55 | layout.addView(mSeekBar, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
56 |
57 | if (shouldPersist())
58 | mValue = getPersistedInt(mDefault);
59 |
60 | mSeekBar.setMax(mMax);
61 | mSeekBar.setProgress(mValue);
62 | return layout;
63 | }
64 | @Override
65 | protected void onBindDialogView(View v) {
66 | super.onBindDialogView(v);
67 | mSeekBar.setMax(mMax);
68 | mSeekBar.setProgress(mValue);
69 | }
70 | @Override
71 | protected void onSetInitialValue(boolean restore, Object defaultValue)
72 | {
73 | super.onSetInitialValue(restore, defaultValue);
74 | if (restore)
75 | mValue = shouldPersist() ? getPersistedInt(mDefault) : 0;
76 | else
77 | mValue = (Integer)defaultValue;
78 | }
79 |
80 | public void onProgressChanged(SeekBar seek, int value, boolean fromTouch)
81 | {
82 | if (value <= 0)
83 | value = 1;
84 | String t = String.valueOf(value);
85 | mValueText.setText(mSuffix == null ? t : t.concat(mSuffix));
86 | if (shouldPersist())
87 | persistInt(value);
88 | callChangeListener(Integer.valueOf(value));
89 | }
90 | public void onStartTrackingTouch(SeekBar seek) {}
91 | public void onStopTrackingTouch(SeekBar seek) {}
92 |
93 | public void setMax(int max) { mMax = max; }
94 | public int getMax() { return mMax; }
95 |
96 | public void setProgress(int progress) {
97 | mValue = progress;
98 | if (mSeekBar != null)
99 | mSeekBar.setProgress(progress);
100 | }
101 | public int getProgress() { return mValue; }
102 | }
103 |
--------------------------------------------------------------------------------