Merge commit 'goog/master' into merge_master
This commit is contained in:
commit
1edfd382ba
|
@ -0,0 +1 @@
|
|||
*~
|
36
adb/adb.c
36
adb/adb.c
|
@ -23,6 +23,7 @@
|
|||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "sysdeps.h"
|
||||
#include "adb.h"
|
||||
|
@ -657,10 +658,25 @@ void start_logging(void)
|
|||
void start_device_log(void)
|
||||
{
|
||||
int fd;
|
||||
char path[100];
|
||||
char path[PATH_MAX];
|
||||
struct tm now;
|
||||
time_t t;
|
||||
char value[PROPERTY_VALUE_MAX];
|
||||
|
||||
snprintf(path, sizeof path, "/data/adb_%ld.txt", (long)time(NULL));
|
||||
fd = unix_open(path, O_WRONLY | O_CREAT | O_APPEND, 0640);
|
||||
// read the trace mask from persistent property persist.adb.trace_mask
|
||||
// give up if the property is not set or cannot be parsed
|
||||
property_get("persist.adb.trace_mask", value, "");
|
||||
if (sscanf(value, "%x", &adb_trace_mask) != 1)
|
||||
return;
|
||||
|
||||
adb_mkdir("/data/adb", 0775);
|
||||
tzset();
|
||||
time(&t);
|
||||
localtime_r(&t, &now);
|
||||
strftime(path, sizeof(path),
|
||||
"/data/adb/adb-%Y-%m-%d-%H-%M-%S.txt",
|
||||
&now);
|
||||
fd = unix_open(path, O_WRONLY | O_CREAT | O_TRUNC, 0640);
|
||||
if (fd < 0)
|
||||
return;
|
||||
|
||||
|
@ -671,11 +687,6 @@ void start_device_log(void)
|
|||
|
||||
fd = unix_open("/dev/null", O_RDONLY);
|
||||
dup2(fd, 0);
|
||||
|
||||
// log everything
|
||||
adb_trace_mask = ~0;
|
||||
// except TRACE_RWX is a bit too verbose
|
||||
adb_trace_mask &= ~TRACE_RWX;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -875,9 +886,10 @@ int adb_main(int is_daemon)
|
|||
** AID_INET to diagnose network issues (netcfg, ping)
|
||||
** AID_GRAPHICS to access the frame buffer
|
||||
** AID_NET_BT and AID_NET_BT_ADMIN to diagnose bluetooth (hcidump)
|
||||
** AID_SDCARD_RW to allow writing to the SD card
|
||||
*/
|
||||
gid_t groups[] = { AID_ADB, AID_LOG, AID_INPUT, AID_INET, AID_GRAPHICS,
|
||||
AID_NET_BT, AID_NET_BT_ADMIN };
|
||||
AID_NET_BT, AID_NET_BT_ADMIN, AID_SDCARD_RW };
|
||||
setgroups(sizeof(groups)/sizeof(groups[0]), groups);
|
||||
|
||||
/* then switch user and group to "shell" */
|
||||
|
@ -919,9 +931,6 @@ int adb_main(int is_daemon)
|
|||
fdevent_loop();
|
||||
|
||||
usb_cleanup();
|
||||
#if ADB_HOST
|
||||
usb_vendors_cleanup();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1081,9 +1090,8 @@ int main(int argc, char **argv)
|
|||
adb_device_banner = "recovery";
|
||||
recovery_mode = 1;
|
||||
}
|
||||
#if ADB_DEVICE_LOG
|
||||
|
||||
start_device_log();
|
||||
#endif
|
||||
return adb_main(0);
|
||||
#endif
|
||||
}
|
||||
|
|
12
adb/adb.h
12
adb/adb.h
|
@ -345,11 +345,6 @@ typedef enum {
|
|||
#endif
|
||||
|
||||
|
||||
/* set this to log to /data/adb/adb_<time>.txt on the device.
|
||||
* has no effect if the /data/adb/ directory does not exist.
|
||||
*/
|
||||
#define ADB_DEVICE_LOG 0
|
||||
|
||||
#if !TRACE_PACKETS
|
||||
#define print_packet(tag,p) do {} while (0)
|
||||
#endif
|
||||
|
@ -357,11 +352,10 @@ typedef enum {
|
|||
#define ADB_PORT 5037
|
||||
#define ADB_LOCAL_TRANSPORT_PORT 5555
|
||||
|
||||
// Google's USB Vendor ID
|
||||
#define VENDOR_ID_GOOGLE 0x18d1
|
||||
#define ADB_CLASS 0xff
|
||||
#define ADB_SUBCLASS 0x42
|
||||
#define ADB_PROTOCOL 0x1
|
||||
|
||||
// HTC's USB Vendor ID
|
||||
#define VENDOR_ID_HTC 0x0bb4
|
||||
|
||||
void local_init();
|
||||
int local_connect(int port);
|
||||
|
|
|
@ -213,7 +213,7 @@ int adb_connect(const char *service)
|
|||
fprintf(stdout,"* daemon started successfully *\n");
|
||||
}
|
||||
/* give the server some time to start properly and detect devices */
|
||||
adb_sleep_ms(2000);
|
||||
adb_sleep_ms(3000);
|
||||
// fall through to _adb_connect
|
||||
} else {
|
||||
// if server was running, check its version to make sure it is not out of date
|
||||
|
|
|
@ -135,11 +135,9 @@ int is_adb_interface(int vid, int pid, int usb_class, int usb_subclass, int usb_
|
|||
unsigned i;
|
||||
for (i = 0; i < vendorIdCount; i++) {
|
||||
if (vid == vendorIds[i]) {
|
||||
/* class:vendor (0xff) subclass:android (0x42) proto:adb (0x01) */
|
||||
if(usb_class == 0xff) {
|
||||
if((usb_subclass == 0x42) && (usb_protocol == 0x01)) {
|
||||
return 1;
|
||||
}
|
||||
if (usb_class == ADB_CLASS && usb_subclass == ADB_SUBCLASS &&
|
||||
usb_protocol == ADB_PROTOCOL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -32,9 +32,6 @@
|
|||
|
||||
#define DBG D
|
||||
|
||||
#define ADB_SUBCLASS 0x42
|
||||
#define ADB_PROTOCOL 0x1
|
||||
|
||||
static IONotificationPortRef notificationPort = 0;
|
||||
static io_iterator_t* notificationIterators;
|
||||
|
||||
|
|
|
@ -16,25 +16,119 @@
|
|||
|
||||
#include "usb_vendors.h"
|
||||
|
||||
#include "sysdeps.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include "windows.h"
|
||||
# include "shlobj.h"
|
||||
#else
|
||||
# include <unistd.h>
|
||||
# include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#include "sysdeps.h"
|
||||
#include "adb.h"
|
||||
|
||||
int* vendorIds = NULL;
|
||||
#define ANDROID_PATH ".android"
|
||||
#define ANDROID_ADB_INI "adb_usb.ini"
|
||||
|
||||
#define TRACE_TAG TRACE_USB
|
||||
|
||||
// Google's USB Vendor ID
|
||||
#define VENDOR_ID_GOOGLE 0x18d1
|
||||
// HTC's USB Vendor ID
|
||||
#define VENDOR_ID_HTC 0x0bb4
|
||||
|
||||
/** built-in vendor list */
|
||||
int builtInVendorIds[] = {
|
||||
VENDOR_ID_GOOGLE,
|
||||
VENDOR_ID_HTC,
|
||||
};
|
||||
|
||||
#define BUILT_IN_VENDOR_COUNT (sizeof(builtInVendorIds)/sizeof(builtInVendorIds[0]))
|
||||
|
||||
/* max number of supported vendor ids (built-in + 3rd party). increase as needed */
|
||||
#define VENDOR_COUNT_MAX 128
|
||||
|
||||
int vendorIds[VENDOR_COUNT_MAX];
|
||||
unsigned vendorIdCount = 0;
|
||||
|
||||
void usb_vendors_init(void) {
|
||||
/* for now, only put the built-in VENDOR_ID_* */
|
||||
vendorIdCount = 2;
|
||||
vendorIds = (int*)malloc(vendorIdCount * sizeof(int));
|
||||
vendorIds[0] = VENDOR_ID_GOOGLE;
|
||||
vendorIds[1] = VENDOR_ID_HTC;
|
||||
}
|
||||
int get_adb_usb_ini(char* buff, size_t len);
|
||||
|
||||
void usb_vendors_cleanup(void) {
|
||||
if (vendorIds != NULL) {
|
||||
free(vendorIds);
|
||||
vendorIds = NULL;
|
||||
vendorIdCount = 0;
|
||||
void usb_vendors_init(void)
|
||||
{
|
||||
if (VENDOR_COUNT_MAX < BUILT_IN_VENDOR_COUNT) {
|
||||
fprintf(stderr, "VENDOR_COUNT_MAX not big enough for built-in vendor list.\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
/* add the built-in vendors at the beginning of the array */
|
||||
memcpy(vendorIds, builtInVendorIds, sizeof(builtInVendorIds));
|
||||
|
||||
/* default array size is the number of built-in vendors */
|
||||
vendorIdCount = BUILT_IN_VENDOR_COUNT;
|
||||
|
||||
if (VENDOR_COUNT_MAX == BUILT_IN_VENDOR_COUNT)
|
||||
return;
|
||||
|
||||
char temp[PATH_MAX];
|
||||
if (get_adb_usb_ini(temp, sizeof(temp)) == 0) {
|
||||
FILE * f = fopen(temp, "rt");
|
||||
|
||||
if (f != NULL) {
|
||||
/* The vendor id file is pretty basic. 1 vendor id per line.
|
||||
Lines starting with # are comments */
|
||||
while (fgets(temp, sizeof(temp), f) != NULL) {
|
||||
if (temp[0] == '#')
|
||||
continue;
|
||||
|
||||
long value = strtol(temp, NULL, 0);
|
||||
if (errno == EINVAL || errno == ERANGE || value > INT_MAX || value < 0) {
|
||||
fprintf(stderr, "Invalid content in %s. Quitting.\n", ANDROID_ADB_INI);
|
||||
exit(2);
|
||||
}
|
||||
|
||||
vendorIds[vendorIdCount++] = (int)value;
|
||||
|
||||
/* make sure we don't go beyond the array */
|
||||
if (vendorIdCount == VENDOR_COUNT_MAX) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Utils methods */
|
||||
|
||||
/* builds the path to the adb vendor id file. returns 0 if success */
|
||||
int build_path(char* buff, size_t len, const char* format, const char* home)
|
||||
{
|
||||
if (snprintf(buff, len, format, home, ANDROID_PATH, ANDROID_ADB_INI) >= len) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* fills buff with the path to the adb vendor id file. returns 0 if success */
|
||||
int get_adb_usb_ini(char* buff, size_t len)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
const char* home = getenv("ANDROID_SDK_HOME");
|
||||
if (home != NULL) {
|
||||
return build_path(buff, len, "%s\\%s\\%s", home);
|
||||
} else {
|
||||
char path[MAX_PATH];
|
||||
SHGetFolderPath( NULL, CSIDL_PROFILE, NULL, 0, path);
|
||||
return build_path(buff, len, "%s\\%s\\%s", path);
|
||||
}
|
||||
#else
|
||||
const char* home = getenv("HOME");
|
||||
if (home == NULL)
|
||||
home = "/tmp";
|
||||
|
||||
return build_path(buff, len, "%s/%s/%s", home);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -17,10 +17,9 @@
|
|||
#ifndef __USB_VENDORS_H
|
||||
#define __USB_VENDORS_H
|
||||
|
||||
extern int* vendorIds;
|
||||
extern int vendorIds[];
|
||||
extern unsigned vendorIdCount;
|
||||
|
||||
void usb_vendors_init(void);
|
||||
void usb_vendors_cleanup(void);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_ACC_ACC_H
|
||||
#define ANDROID_ACC_ACC_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
typedef char ACCchar;
|
||||
typedef int32_t ACCint;
|
||||
typedef uint32_t ACCuint;
|
||||
typedef ssize_t ACCsizei;
|
||||
typedef unsigned int ACCenum;
|
||||
typedef void ACCvoid;
|
||||
typedef struct ACCscript ACCscript;
|
||||
|
||||
#define ACC_NO_ERROR 0x0000
|
||||
#define ACC_INVALID_ENUM 0x0500
|
||||
#define ACC_INVALID_OPERATION 0x0502
|
||||
#define ACC_INVALID_VALUE 0x0501
|
||||
#define ACC_OUT_OF_MEMORY 0x0505
|
||||
|
||||
#define ACC_COMPILE_STATUS 0x8B81
|
||||
#define ACC_INFO_LOG_LENGTH 0x8B84
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
ACCscript* accCreateScript();
|
||||
|
||||
void accDeleteScript(ACCscript* script);
|
||||
|
||||
ACCenum accGetError( ACCscript* script );
|
||||
|
||||
void accScriptSource(ACCscript* script,
|
||||
ACCsizei count,
|
||||
const ACCchar** string,
|
||||
const ACCint* length);
|
||||
|
||||
void accCompileScript(ACCscript* script);
|
||||
|
||||
void accGetScriptiv(ACCscript* script,
|
||||
ACCenum pname,
|
||||
ACCint* params);
|
||||
|
||||
void accGetScriptInfoLog(ACCscript* script,
|
||||
ACCsizei maxLength,
|
||||
ACCsizei* length,
|
||||
ACCchar* infoLog);
|
||||
|
||||
void accGetScriptLabel(ACCscript* script, const ACCchar * name,
|
||||
ACCvoid** address);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#endif
|
|
@ -115,6 +115,7 @@ static struct perms_ devperms[] = {
|
|||
{ "/dev/oncrpc/", 0660, AID_ROOT, AID_SYSTEM, 1 },
|
||||
{ "/dev/adsp/", 0660, AID_SYSTEM, AID_AUDIO, 1 },
|
||||
{ "/dev/mt9t013", 0660, AID_SYSTEM, AID_SYSTEM, 0 },
|
||||
{ "/dev/msm_camera/", 0660, AID_SYSTEM, AID_SYSTEM, 1 },
|
||||
{ "/dev/akm8976_daemon",0640, AID_COMPASS, AID_SYSTEM, 0 },
|
||||
{ "/dev/akm8976_aot", 0640, AID_COMPASS, AID_SYSTEM, 0 },
|
||||
{ "/dev/akm8976_pffd", 0640, AID_COMPASS, AID_SYSTEM, 0 },
|
||||
|
@ -384,7 +385,10 @@ static void handle_device_event(struct uevent *uevent)
|
|||
} else if (!strncmp(uevent->subsystem, "adsp", 4)) {
|
||||
base = "/dev/adsp/";
|
||||
mkdir(base, 0755);
|
||||
} else if(!strncmp(uevent->subsystem, "input", 5)) {
|
||||
} else if (!strncmp(uevent->subsystem, "msm_camera", 10)) {
|
||||
base = "/dev/msm_camera/";
|
||||
mkdir(base, 0755);
|
||||
} else if(!strncmp(uevent->subsystem, "input", 5)) {
|
||||
base = "/dev/input/";
|
||||
mkdir(base, 0755);
|
||||
} else if(!strncmp(uevent->subsystem, "mtd", 3)) {
|
||||
|
|
|
@ -5,8 +5,15 @@ include $(CLEAR_VARS)
|
|||
# Shared library
|
||||
#
|
||||
|
||||
LOCAL_MODULE:= acc
|
||||
LOCAL_SRC_FILES := acc.cpp disassem.cpp
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
LOCAL_MODULE:= libacc
|
||||
LOCAL_SRC_FILES := acc.cpp
|
||||
|
||||
include $(BUILD_EXECUTABLE)
|
||||
ifeq ($(TARGET_ARCH),arm)
|
||||
LOCAL_SRC_FILES += disassem.cpp
|
||||
endif
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := libdl
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
include $(call all-makefiles-under,$(LOCAL_PATH))
|
|
@ -0,0 +1,21 @@
|
|||
Obfuscated Tiny C Compiler
|
||||
|
||||
Copyright (C) 2001-2003 Fabrice Bellard
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product and its documentation
|
||||
*is* required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
|
624
libacc/acc.cpp
624
libacc/acc.cpp
File diff suppressed because it is too large
Load Diff
13
libacc/test
13
libacc/test
|
@ -1,13 +0,0 @@
|
|||
#!/bin/sh
|
||||
rm -f tests/acc
|
||||
g++ acc.cpp disassem.cpp -g -ldl -o tests/acc && tests/acc tests/otcc.c -a x86 -d tests/otcc.out && diff tests/otcc.out tests/otcc.out-orig
|
||||
if [ -x "tests/acc" ]; then
|
||||
tests/acc -S tests/returnval.c
|
||||
|
||||
if [ "$(uname)" = "Linux" ]; then
|
||||
if [ "$(uname -m)" = "i686" ]; then
|
||||
echo "Linux i686. Testing otcc.c"
|
||||
tests/acc tests/otcc.c tests/otcc.c tests/returnval.c
|
||||
fi
|
||||
fi
|
||||
fi
|
|
@ -1,4 +0,0 @@
|
|||
#!/bin/sh
|
||||
adb remount
|
||||
adb push tests/returnval.c /system/bin/returnval.c
|
||||
mm -j8 && adb sync && adb shell /system/bin/acc -S /system/bin/returnval.c
|
|
@ -1,2 +1,2 @@
|
|||
acc
|
||||
test-acc
|
||||
*.out
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_SRC_FILES:= \
|
||||
main.cpp
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := \
|
||||
libacc
|
||||
|
||||
LOCAL_MODULE:= acc
|
||||
|
||||
LOCAL_MODULE_TAGS := tests
|
||||
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
Binary file not shown.
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* Android "Almost" C Compiler.
|
||||
* This is a compiler for a small subset of the C language, intended for use
|
||||
* in scripting environments where speed and memory footprint are important.
|
||||
*
|
||||
* This code is based upon the "unobfuscated" version of the
|
||||
* Obfuscated Tiny C compiler, see the file LICENSE for details.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <dlfcn.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(__arm__)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <acc/acc.h>
|
||||
|
||||
|
||||
typedef int (*MainPtr)(int, char**);
|
||||
// This is a separate function so it can easily be set by breakpoint in gdb.
|
||||
int run(MainPtr mainFunc, int argc, char** argv) {
|
||||
return mainFunc(argc, argv);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
const char* inFile = NULL;
|
||||
bool printListing;
|
||||
FILE* in = stdin;
|
||||
int i;
|
||||
for (i = 1; i < argc; i++) {
|
||||
char* arg = argv[i];
|
||||
if (arg[0] == '-') {
|
||||
switch (arg[1]) {
|
||||
case 'S':
|
||||
printListing = true;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Unrecognized flag %s\n", arg);
|
||||
return 3;
|
||||
}
|
||||
} else if (inFile == NULL) {
|
||||
inFile = arg;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (! inFile) {
|
||||
fprintf(stderr, "input file required\n");
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (inFile) {
|
||||
in = fopen(inFile, "r");
|
||||
if (!in) {
|
||||
fprintf(stderr, "Could not open input file %s\n", inFile);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
fseek(in, 0, SEEK_END);
|
||||
size_t fileSize = (size_t) ftell(in);
|
||||
rewind(in);
|
||||
ACCchar* text = new ACCchar[fileSize];
|
||||
size_t bytesRead = fread(text, 1, fileSize, in);
|
||||
if (bytesRead != fileSize) {
|
||||
fprintf(stderr, "Could not read all of file %s\n", inFile);
|
||||
}
|
||||
|
||||
ACCscript* script = accCreateScript();
|
||||
|
||||
const ACCchar* scriptSource[] = {text};
|
||||
accScriptSource(script, 1, scriptSource, NULL);
|
||||
delete[] text;
|
||||
|
||||
accCompileScript(script);
|
||||
|
||||
MainPtr mainPointer = 0;
|
||||
|
||||
accGetScriptLabel(script, "main", (ACCvoid**) & mainPointer);
|
||||
|
||||
int result = accGetError(script);
|
||||
if (result == ACC_NO_ERROR) {
|
||||
fprintf(stderr, "Executing compiled code:\n");
|
||||
int codeArgc = argc - i + 1;
|
||||
char** codeArgv = argv + i - 1;
|
||||
codeArgv[0] = (char*) (inFile ? inFile : "stdin");
|
||||
result = run(mainPointer, codeArgc, codeArgv);
|
||||
fprintf(stderr, "result: %d\n", result);
|
||||
}
|
||||
|
||||
accDeleteScript(script);
|
||||
|
||||
return result;
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,9 @@
|
|||
#!/bin/sh
|
||||
adb remount
|
||||
adb shell rm /system/bin/acc
|
||||
adb push data/returnval.c /system/bin/returnval.c
|
||||
cd ..
|
||||
mm -j8
|
||||
cd tests
|
||||
adb sync
|
||||
adb shell /system/bin/acc -S /system/bin/returnval.c
|
|
@ -0,0 +1,15 @@
|
|||
#!/bin/sh
|
||||
rm -f test-acc
|
||||
cd ..
|
||||
g++ -I../include acc.cpp disassem.cpp tests/main.cpp -g -ldl -o tests/test-acc
|
||||
cd tests
|
||||
if [ -x "test-acc" ]; then
|
||||
./test-acc -S data/returnval.c
|
||||
|
||||
if [ "$(uname)" = "Linux" ]; then
|
||||
if [ "$(uname -m)" = "i686" ]; then
|
||||
echo "Linux i686. Testing otcc.c"
|
||||
./test-acc data/otcc.c data/otcc.c data/returnval.c
|
||||
fi
|
||||
fi
|
||||
fi
|
|
@ -17,7 +17,6 @@ LOCAL_PATH := $(my-dir)
|
|||
include $(CLEAR_VARS)
|
||||
|
||||
commonSources := \
|
||||
abort_socket.c \
|
||||
array.c \
|
||||
hashmap.c \
|
||||
atomic.c \
|
||||
|
@ -45,22 +44,23 @@ commonHostSources := \
|
|||
# some files must not be compiled when building against Mingw
|
||||
# they correspond to features not used by our host development tools
|
||||
# which are also hard or even impossible to port to native Win32
|
||||
WITH_MINGW :=
|
||||
WINDOWS_HOST_ONLY :=
|
||||
ifeq ($(HOST_OS),windows)
|
||||
ifeq ($(strip $(USE_CYGWIN)),)
|
||||
WITH_MINGW := 1
|
||||
WINDOWS_HOST_ONLY := 1
|
||||
endif
|
||||
endif
|
||||
# USE_MINGW is defined when we build against Mingw on Linux
|
||||
ifneq ($(strip $(USE_MINGW)),)
|
||||
WITH_MINGW := 1
|
||||
WINDOWS_HOST_ONLY := 1
|
||||
endif
|
||||
|
||||
ifeq ($(WITH_MINGW),1)
|
||||
ifeq ($(WINDOWS_HOST_ONLY),1)
|
||||
commonSources += \
|
||||
uio.c
|
||||
else
|
||||
commonSources += \
|
||||
abort_socket.c \
|
||||
mspace.c \
|
||||
selector.c \
|
||||
tztime.c \
|
||||
|
|
|
@ -239,7 +239,7 @@ int asocket_write(struct asocket *s, const void *buf, size_t count,
|
|||
}
|
||||
|
||||
if (pfd[0].revents) {
|
||||
if (pfd[0].revents & POLLIN) {
|
||||
if (pfd[0].revents & POLLOUT) {
|
||||
/* ready to write() without blocking */
|
||||
do {
|
||||
ret = write(s->fd, buf, count);
|
||||
|
|
|
@ -33,54 +33,19 @@
|
|||
|
||||
CommandListener::CommandListener() :
|
||||
FrameworkListener("nexus") {
|
||||
registerCmd(new WifiEnableCmd());
|
||||
registerCmd(new WifiDisableCmd());
|
||||
registerCmd(new WifiScanCmd());
|
||||
registerCmd(new WifiScanResultsCmd());
|
||||
registerCmd(new WifiListNetworksCmd());
|
||||
registerCmd(new WifiAddNetworkCmd());
|
||||
registerCmd(new WifiRemoveNetworkCmd());
|
||||
registerCmd(new WifiSetVarCmd());
|
||||
registerCmd(new WifiGetVarCmd());
|
||||
|
||||
registerCmd(new VpnEnableCmd());
|
||||
registerCmd(new VpnSetVarCmd());
|
||||
registerCmd(new VpnGetVarCmd());
|
||||
registerCmd(new VpnDisableCmd());
|
||||
registerCmd(new GetCmd());
|
||||
registerCmd(new SetCmd());
|
||||
}
|
||||
|
||||
/* -------------
|
||||
* Wifi Commands
|
||||
* ------------ */
|
||||
|
||||
CommandListener::WifiEnableCmd::WifiEnableCmd() :
|
||||
NexusCommand("wifi_enable") {
|
||||
}
|
||||
|
||||
int CommandListener::WifiEnableCmd::runCommand(SocketClient *cli, char *data) {
|
||||
Controller *c = NetworkManager::Instance()->findController("WIFI");
|
||||
|
||||
if (c->enable())
|
||||
cli->sendMsg(ErrorCode::OperationFailed, "Failed to enable wifi", true);
|
||||
else
|
||||
cli->sendMsg(ErrorCode::CommandOkay, "Wifi Enabled", false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
CommandListener::WifiDisableCmd::WifiDisableCmd() :
|
||||
NexusCommand("wifi_disable") {
|
||||
}
|
||||
|
||||
int CommandListener::WifiDisableCmd::runCommand(SocketClient *cli, char *data) {
|
||||
Controller *c = NetworkManager::Instance()->findController("WIFI");
|
||||
|
||||
if (c->disable())
|
||||
cli->sendMsg(ErrorCode::OperationFailed, "Failed to disable wifi", true);
|
||||
else
|
||||
cli->sendMsg(ErrorCode::CommandOkay, "Wifi Disabled", false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
CommandListener::WifiAddNetworkCmd::WifiAddNetworkCmd() :
|
||||
NexusCommand("wifi_add_network") {
|
||||
}
|
||||
|
@ -116,21 +81,6 @@ int CommandListener::WifiRemoveNetworkCmd::runCommand(SocketClient *cli, char *d
|
|||
return 0;
|
||||
}
|
||||
|
||||
CommandListener::WifiScanCmd::WifiScanCmd() :
|
||||
NexusCommand("wifi_scan") {
|
||||
}
|
||||
|
||||
int CommandListener::WifiScanCmd::runCommand(SocketClient *cli, char *data) {
|
||||
WifiController *wc = (WifiController *) NetworkManager::Instance()->findController("WIFI");
|
||||
|
||||
if (wc->setScanMode(atoi(data)))
|
||||
cli->sendMsg(ErrorCode::OperationFailed, "Failed to set scan mode", true);
|
||||
else
|
||||
cli->sendMsg(ErrorCode::CommandOkay, "Scan mode set", false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
CommandListener::WifiScanResultsCmd::WifiScanResultsCmd() :
|
||||
NexusCommand("wifi_scan_results") {
|
||||
}
|
||||
|
@ -181,158 +131,39 @@ int CommandListener::WifiListNetworksCmd::runCommand(SocketClient *cli, char *da
|
|||
return 0;
|
||||
}
|
||||
|
||||
CommandListener::WifiSetVarCmd::WifiSetVarCmd() :
|
||||
NexusCommand("wifi_setvar") {
|
||||
}
|
||||
|
||||
int CommandListener::WifiSetVarCmd::runCommand(SocketClient *cli, char *data) {
|
||||
WifiController *wc = (WifiController *) NetworkManager::Instance()->findController("WIFI");
|
||||
|
||||
char *bword;
|
||||
char *last;
|
||||
char varname[32];
|
||||
char val[250];
|
||||
int networkId;
|
||||
|
||||
if (!(bword = strtok_r(data, ":", &last)))
|
||||
goto out_inval;
|
||||
|
||||
networkId = atoi(bword);
|
||||
|
||||
if (!(bword = strtok_r(NULL, ":", &last)))
|
||||
goto out_inval;
|
||||
|
||||
strncpy(varname, bword, sizeof(varname));
|
||||
|
||||
if (!(bword = strtok_r(NULL, ":", &last)))
|
||||
goto out_inval;
|
||||
|
||||
strncpy(val, bword, sizeof(val));
|
||||
|
||||
LOGD("Network id %d, varname '%s', value '%s'", networkId, varname, val);
|
||||
|
||||
return 0;
|
||||
|
||||
out_inval:
|
||||
errno = EINVAL;
|
||||
cli->sendMsg(ErrorCode::CommandParameterError, "Failed to set variable.", true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
CommandListener::WifiGetVarCmd::WifiGetVarCmd() :
|
||||
NexusCommand("wifi_getvar") {
|
||||
}
|
||||
|
||||
int CommandListener::WifiGetVarCmd::runCommand(SocketClient *cli, char *data) {
|
||||
WifiController *wc = (WifiController *) NetworkManager::Instance()->findController("WIFI");
|
||||
|
||||
char *bword;
|
||||
char *last;
|
||||
char varname[32];
|
||||
int networkId;
|
||||
|
||||
if (!(bword = strtok_r(data, ":", &last)))
|
||||
goto out_inval;
|
||||
|
||||
networkId = atoi(bword);
|
||||
|
||||
if (!(bword = strtok_r(NULL, ":", &last)))
|
||||
goto out_inval;
|
||||
|
||||
strncpy(varname, bword, sizeof(varname));
|
||||
|
||||
LOGD("networkId = %d, varname '%s'", networkId, varname);
|
||||
|
||||
return 0;
|
||||
out_inval:
|
||||
errno = EINVAL;
|
||||
cli->sendMsg(ErrorCode::CommandParameterError, "Failed to get variable.", true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------
|
||||
* Vpn Commands
|
||||
* ------------ */
|
||||
CommandListener::VpnEnableCmd::VpnEnableCmd() :
|
||||
NexusCommand("vpn_enable") {
|
||||
}
|
||||
|
||||
int CommandListener::VpnEnableCmd::runCommand(SocketClient *cli, char *data) {
|
||||
Controller *c = NetworkManager::Instance()->findController("VPN");
|
||||
|
||||
if (c->enable())
|
||||
cli->sendMsg(ErrorCode::OperationFailed, "Failed to enable VPN", true);
|
||||
else
|
||||
cli->sendMsg(ErrorCode::CommandOkay, "VPN enabled", false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
CommandListener::VpnSetVarCmd::VpnSetVarCmd() :
|
||||
NexusCommand("vpn_setvar") {
|
||||
/* ----------------
|
||||
* Generic Commands
|
||||
* ---------------- */
|
||||
CommandListener::GetCmd::GetCmd() :
|
||||
NexusCommand("get") {
|
||||
}
|
||||
|
||||
int CommandListener::VpnSetVarCmd::runCommand(SocketClient *cli, char *data) {
|
||||
VpnController *vc = (VpnController *) NetworkManager::Instance()->findController("VPN");
|
||||
|
||||
int CommandListener::GetCmd::runCommand(SocketClient *cli, char *data) {
|
||||
char *bword;
|
||||
char *last;
|
||||
char varname[32];
|
||||
char val[250];
|
||||
|
||||
if (!(bword = strtok_r(data, ":", &last)))
|
||||
goto out_inval;
|
||||
|
||||
strncpy(varname, bword, sizeof(varname));
|
||||
|
||||
if (!(bword = strtok_r(NULL, ":", &last)))
|
||||
goto out_inval;
|
||||
|
||||
strncpy(val, bword, sizeof(val));
|
||||
|
||||
if (!strcasecmp(varname, "vpn_gateway")) {
|
||||
if (vc->setVpnGateway(val))
|
||||
goto out_inval;
|
||||
} else {
|
||||
cli->sendMsg(ErrorCode::CommandParameterError, "Variable not found.", true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
cli->sendMsg(ErrorCode::CommandOkay, "Variable written.", false);
|
||||
return 0;
|
||||
|
||||
out_inval:
|
||||
errno = EINVAL;
|
||||
cli->sendMsg(ErrorCode::CommandParameterError, "Failed to set variable.", true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
CommandListener::VpnGetVarCmd::VpnGetVarCmd() :
|
||||
NexusCommand("vpn_getvar") {
|
||||
}
|
||||
|
||||
int CommandListener::VpnGetVarCmd::runCommand(SocketClient *cli, char *data) {
|
||||
VpnController *vc = (VpnController *) NetworkManager::Instance()->findController("VPN");
|
||||
|
||||
char *bword;
|
||||
char *last;
|
||||
char varname[32];
|
||||
char propname[32];
|
||||
|
||||
if (!(bword = strtok_r(data, ":", &last)))
|
||||
goto out_inval;
|
||||
|
||||
strncpy(varname, bword, sizeof(varname));
|
||||
strncpy(propname, bword, sizeof(propname));
|
||||
|
||||
if (!strcasecmp(varname, "vpn_gateway")) {
|
||||
char buffer[255];
|
||||
char pb[255];
|
||||
snprintf(pb, sizeof(pb), "%s:", propname);
|
||||
|
||||
sprintf(buffer, "%s:%s", varname, inet_ntoa(vc->getVpnGateway()));
|
||||
cli->sendMsg(ErrorCode::VariableRead, buffer, false);
|
||||
} else {
|
||||
cli->sendMsg(ErrorCode::CommandParameterError, "Variable not found.", true);
|
||||
return 0;
|
||||
if (!NetworkManager::Instance()->getProperty(propname,
|
||||
&pb[strlen(pb)],
|
||||
sizeof(pb) - strlen(pb))) {
|
||||
goto out_inval;
|
||||
}
|
||||
|
||||
cli->sendMsg(ErrorCode::CommandOkay, "Variable read.", false);
|
||||
cli->sendMsg(ErrorCode::VariableRead, pb, false);
|
||||
|
||||
cli->sendMsg(ErrorCode::CommandOkay, "Property read.", false);
|
||||
return 0;
|
||||
out_inval:
|
||||
errno = EINVAL;
|
||||
|
@ -340,16 +171,34 @@ out_inval:
|
|||
return 0;
|
||||
}
|
||||
|
||||
CommandListener::VpnDisableCmd::VpnDisableCmd() :
|
||||
NexusCommand("vpn_disable") {
|
||||
}
|
||||
|
||||
int CommandListener::VpnDisableCmd::runCommand(SocketClient *cli, char *data) {
|
||||
Controller *c = NetworkManager::Instance()->findController("VPN");
|
||||
CommandListener::SetCmd::SetCmd() :
|
||||
NexusCommand("set") {
|
||||
}
|
||||
|
||||
if (c->disable())
|
||||
cli->sendMsg(ErrorCode::OperationFailed, "Failed to disable VPN", true);
|
||||
else
|
||||
cli->sendMsg(ErrorCode::CommandOkay, "VPN disabled", false);
|
||||
int CommandListener::SetCmd::runCommand(SocketClient *cli, char *data) {
|
||||
char *bword;
|
||||
char *last;
|
||||
char propname[32];
|
||||
char propval[250];
|
||||
|
||||
if (!(bword = strtok_r(data, ":", &last)))
|
||||
goto out_inval;
|
||||
|
||||
strncpy(propname, bword, sizeof(propname));
|
||||
|
||||
if (!(bword = strtok_r(NULL, ":", &last)))
|
||||
goto out_inval;
|
||||
|
||||
strncpy(propval, bword, sizeof(propval));
|
||||
|
||||
if (NetworkManager::Instance()->setProperty(propname, propval))
|
||||
goto out_inval;
|
||||
|
||||
cli->sendMsg(ErrorCode::CommandOkay, "Property set.", false);
|
||||
return 0;
|
||||
|
||||
out_inval:
|
||||
errno = EINVAL;
|
||||
cli->sendMsg(ErrorCode::CommandParameterError, "Failed to set property.", true);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -25,19 +25,6 @@ public:
|
|||
virtual ~CommandListener() {}
|
||||
|
||||
private:
|
||||
class WifiEnableCmd : public NexusCommand {
|
||||
public:
|
||||
WifiEnableCmd();
|
||||
virtual ~WifiEnableCmd() {}
|
||||
int runCommand(SocketClient *c, char *data);
|
||||
};
|
||||
|
||||
class WifiDisableCmd : public NexusCommand {
|
||||
public:
|
||||
WifiDisableCmd();
|
||||
virtual ~WifiDisableCmd() {}
|
||||
int runCommand(SocketClient *c, char *data);
|
||||
};
|
||||
|
||||
class WifiScanCmd : public NexusCommand {
|
||||
public:
|
||||
|
@ -74,48 +61,19 @@ private:
|
|||
int runCommand(SocketClient *c, char *data);
|
||||
};
|
||||
|
||||
class WifiSetVarCmd : public NexusCommand {
|
||||
class SetCmd : public NexusCommand {
|
||||
public:
|
||||
WifiSetVarCmd();
|
||||
virtual ~WifiSetVarCmd() {}
|
||||
SetCmd();
|
||||
virtual ~SetCmd() {}
|
||||
int runCommand(SocketClient *c, char *data);
|
||||
};
|
||||
|
||||
class WifiGetVarCmd : public NexusCommand {
|
||||
class GetCmd : public NexusCommand {
|
||||
public:
|
||||
WifiGetVarCmd();
|
||||
virtual ~WifiGetVarCmd() {}
|
||||
GetCmd();
|
||||
virtual ~GetCmd() {}
|
||||
int runCommand(SocketClient *c, char *data);
|
||||
};
|
||||
|
||||
class VpnEnableCmd : public NexusCommand {
|
||||
public:
|
||||
VpnEnableCmd();
|
||||
virtual ~VpnEnableCmd() {}
|
||||
int runCommand(SocketClient *c, char *data);
|
||||
};
|
||||
|
||||
class VpnSetVarCmd : public NexusCommand {
|
||||
public:
|
||||
VpnSetVarCmd();
|
||||
virtual ~VpnSetVarCmd() {}
|
||||
int runCommand(SocketClient *c, char *data);
|
||||
};
|
||||
|
||||
class VpnGetVarCmd : public NexusCommand {
|
||||
public:
|
||||
VpnGetVarCmd();
|
||||
virtual ~VpnGetVarCmd() {}
|
||||
int runCommand(SocketClient *c, char *data);
|
||||
};
|
||||
|
||||
class VpnDisableCmd : public NexusCommand {
|
||||
public:
|
||||
VpnDisableCmd();
|
||||
virtual ~VpnDisableCmd() {}
|
||||
int runCommand(SocketClient *c, char *data);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
@ -32,8 +33,13 @@
|
|||
extern "C" int init_module(void *, unsigned int, const char *);
|
||||
extern "C" int delete_module(const char *, unsigned int);
|
||||
|
||||
Controller::Controller(const char *name) {
|
||||
Controller::Controller(const char *name, const char *prefix) {
|
||||
mName = name;
|
||||
mPropertyPrefix = prefix;
|
||||
mProperties = new PropertyCollection();
|
||||
|
||||
mEnabled = false;
|
||||
registerProperty("enable");
|
||||
}
|
||||
|
||||
int Controller::start() {
|
||||
|
@ -44,12 +50,69 @@ int Controller::stop() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
const PropertyCollection & Controller::getProperties() {
|
||||
return *mProperties;
|
||||
}
|
||||
|
||||
int Controller::setProperty(const char *name, char *value) {
|
||||
if (!strcmp(name, "enable")) {
|
||||
int en = atoi(value);
|
||||
int rc;
|
||||
|
||||
rc = (en ? enable() : disable());
|
||||
|
||||
if (!rc)
|
||||
mEnabled = en;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *Controller::getProperty(const char *name, char *buffer, size_t maxsize) {
|
||||
if (!strcmp(name, "enable")) {
|
||||
snprintf(buffer, maxsize, "%d", mEnabled);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
errno = ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int Controller::registerProperty(const char *name) {
|
||||
PropertyCollection::iterator it;
|
||||
|
||||
for (it = mProperties->begin(); it != mProperties->end(); ++it) {
|
||||
if (!strcmp(name, (*it))) {
|
||||
errno = EADDRINUSE;
|
||||
LOGE("Failed to register property (%s)", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
mProperties->push_back(name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Controller::unregisterProperty(const char *name) {
|
||||
PropertyCollection::iterator it;
|
||||
|
||||
for (it = mProperties->begin(); it != mProperties->end(); ++it) {
|
||||
if (!strcmp(name, (*it))) {
|
||||
mProperties->erase(it);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Controller::loadKernelModule(char *modpath, const char *args) {
|
||||
void *module;
|
||||
unsigned int size;
|
||||
|
||||
LOGD("loadKernelModule(%s, %s)", modpath, args);
|
||||
|
||||
module = loadFile(modpath, &size);
|
||||
if (!module) {
|
||||
errno = -EIO;
|
||||
|
@ -65,7 +128,6 @@ int Controller::unloadKernelModule(const char *modtag) {
|
|||
int rc = -1;
|
||||
int retries = 10;
|
||||
|
||||
LOGD("unloadKernelModule(%s)", modtag);
|
||||
while (retries--) {
|
||||
rc = delete_module(modtag, O_NONBLOCK | O_EXCL);
|
||||
if (rc < 0 && errno == EAGAIN)
|
||||
|
@ -107,7 +169,6 @@ bool Controller::isKernelModuleLoaded(const char *modtag) {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
void *Controller::loadFile(char *filename, unsigned int *_size)
|
||||
{
|
||||
int ret, fd;
|
||||
|
|
|
@ -16,31 +16,48 @@
|
|||
#ifndef _CONTROLLER_H
|
||||
#define _CONTROLLER_H
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "../../../frameworks/base/include/utils/List.h"
|
||||
|
||||
#include "PropertyCollection.h"
|
||||
|
||||
class Controller {
|
||||
private:
|
||||
const char *mName;
|
||||
const char *mPropertyPrefix;
|
||||
PropertyCollection *mProperties;
|
||||
bool mEnabled;
|
||||
|
||||
public:
|
||||
Controller(const char *name);
|
||||
Controller(const char *name, const char *prefix);
|
||||
virtual ~Controller() {}
|
||||
|
||||
virtual int start();
|
||||
virtual int stop();
|
||||
|
||||
virtual int enable() = 0;
|
||||
virtual int disable() = 0;
|
||||
virtual const PropertyCollection &getProperties();
|
||||
virtual int setProperty(const char *name, char *value);
|
||||
virtual const char *getProperty(const char *name, char *buffer, size_t maxsize);
|
||||
|
||||
virtual const char *getName() { return mName; }
|
||||
const char *getName() { return mName; }
|
||||
const char *getPropertyPrefix() { return mPropertyPrefix; }
|
||||
|
||||
protected:
|
||||
int loadKernelModule(char *modpath, const char *args);
|
||||
bool isKernelModuleLoaded(const char *modtag);
|
||||
int unloadKernelModule(const char *modtag);
|
||||
|
||||
int registerProperty(const char *name);
|
||||
int unregisterProperty(const char *name);
|
||||
|
||||
private:
|
||||
void *loadFile(char *filename, unsigned int *_size);
|
||||
|
||||
virtual int enable() = 0;
|
||||
virtual int disable() = 0;
|
||||
|
||||
};
|
||||
|
||||
typedef android::List<Controller *> ControllerCollection;
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include "LoopController.h"
|
||||
|
||||
LoopController::LoopController() :
|
||||
Controller("LOOP") {
|
||||
Controller("LOOP", "loop") {
|
||||
}
|
||||
|
||||
int LoopController::enable() {
|
||||
|
|
|
@ -23,6 +23,7 @@ public:
|
|||
LoopController();
|
||||
virtual ~LoopController() {}
|
||||
|
||||
private:
|
||||
int enable();
|
||||
int disable();
|
||||
};
|
||||
|
|
|
@ -83,6 +83,73 @@ Controller *NetworkManager::findController(const char *name) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int NetworkManager::setProperty(const char *name, char *value) {
|
||||
char *tmp = strdup(name);
|
||||
char *next = tmp;
|
||||
char *prefix;
|
||||
char *rest;
|
||||
ControllerCollection::iterator it;
|
||||
|
||||
if (!(prefix = strsep(&next, ".")))
|
||||
goto out_inval;
|
||||
|
||||
rest = next;
|
||||
|
||||
if (!strncasecmp(prefix, "netman", 6)) {
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (it = mControllers->begin(); it != mControllers->end(); ++it) {
|
||||
if (!strcasecmp(prefix, (*it)->getPropertyPrefix())) {
|
||||
return (*it)->setProperty(rest, value);
|
||||
}
|
||||
}
|
||||
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
|
||||
out_inval:
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *NetworkManager::getProperty(const char *name, char *buffer,
|
||||
size_t maxsize) {
|
||||
char *tmp = strdup(name);
|
||||
char *next = tmp;
|
||||
char *prefix;
|
||||
char *rest;
|
||||
ControllerCollection::iterator it;
|
||||
|
||||
if (!(prefix = strsep(&next, ".")))
|
||||
goto out_inval;
|
||||
|
||||
rest = next;
|
||||
|
||||
if (!strncasecmp(prefix, "netman", 6)) {
|
||||
errno = ENOSYS;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (it = mControllers->begin(); it != mControllers->end(); ++it) {
|
||||
if (!strcasecmp(prefix, (*it)->getPropertyPrefix())) {
|
||||
return (*it)->getProperty(rest, buffer, maxsize);
|
||||
}
|
||||
}
|
||||
|
||||
errno = ENOENT;
|
||||
return NULL;
|
||||
|
||||
out_inval:
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const PropertyCollection &NetworkManager::getProperties() {
|
||||
return *mProperties;
|
||||
}
|
||||
|
||||
int NetworkManager::onInterfaceCreated(Controller *c, char *name) {
|
||||
LOGD("Interface %s created by controller %s", name, c->getName());
|
||||
return 0;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <sysutils/SocketListener.h>
|
||||
|
||||
#include "Controller.h"
|
||||
#include "PropertyCollection.h"
|
||||
|
||||
class NetworkManager {
|
||||
private:
|
||||
|
@ -27,6 +28,7 @@ private:
|
|||
private:
|
||||
ControllerCollection *mControllers;
|
||||
SocketListener *mBroadcaster;
|
||||
PropertyCollection *mProperties;
|
||||
|
||||
public:
|
||||
virtual ~NetworkManager() {}
|
||||
|
@ -37,6 +39,10 @@ public:
|
|||
|
||||
Controller *findController(const char *name);
|
||||
|
||||
const PropertyCollection &getProperties();
|
||||
int setProperty(const char *name, char *value);
|
||||
const char *getProperty(const char *name, char *buffer, size_t maxsize);
|
||||
|
||||
void setBroadcaster(SocketListener *sl) { mBroadcaster = sl; }
|
||||
SocketListener *getBroadcaster() { return mBroadcaster; }
|
||||
|
||||
|
@ -45,6 +51,9 @@ public:
|
|||
private:
|
||||
int startControllers();
|
||||
int stopControllers();
|
||||
int registerProperty(const char *name);
|
||||
int unregisterProperty(const char *name);
|
||||
|
||||
NetworkManager();
|
||||
|
||||
public:
|
||||
|
|
|
@ -63,7 +63,6 @@ int OpenVpnController::enable() {
|
|||
}
|
||||
|
||||
int OpenVpnController::disable() {
|
||||
|
||||
if (mServiceManager->stop("openvpn"))
|
||||
return -1;
|
||||
return 0;
|
||||
|
|
|
@ -31,6 +31,8 @@ public:
|
|||
|
||||
int start();
|
||||
int stop();
|
||||
|
||||
private:
|
||||
int enable();
|
||||
int disable();
|
||||
};
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _PROPERTY_COLLECTION_H
|
||||
#define _PROPERTY_COLLECTION_H
|
||||
|
||||
#include "../../../frameworks/base/include/utils/List.h"
|
||||
|
||||
typedef android::List<const char *> PropertyCollection;
|
||||
|
||||
#endif
|
||||
|
|
@ -14,6 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/socket.h>
|
||||
|
@ -23,7 +24,8 @@
|
|||
#include "VpnController.h"
|
||||
|
||||
VpnController::VpnController() :
|
||||
Controller("VPN") {
|
||||
Controller("VPN", "vpn") {
|
||||
registerProperty("gateway");
|
||||
}
|
||||
|
||||
int VpnController::start() {
|
||||
|
@ -46,15 +48,23 @@ int VpnController::disable() {
|
|||
return -1;
|
||||
}
|
||||
|
||||
int VpnController::setVpnGateway(const char *vpnGw) {
|
||||
if (!inet_aton(vpnGw, &mVpnGateway)) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
int VpnController::setProperty(const char *name, char *value) {
|
||||
if (!strcmp(name, "gateway")) {
|
||||
if (!inet_aton(value, &mVpnGateway)) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Controller::setProperty(name, value);
|
||||
}
|
||||
|
||||
int VpnController::setVpnGateway(struct in_addr *vpnGw) {
|
||||
memcpy(&mVpnGateway, vpnGw, sizeof(struct in_addr));
|
||||
return 0;
|
||||
const char *VpnController::getProperty(const char *name, char *buffer, size_t maxsize) {
|
||||
if (!strcmp(name, "gateway")) {
|
||||
snprintf(buffer, maxsize, "%s", inet_ntoa(mVpnGateway));
|
||||
return buffer;
|
||||
}
|
||||
|
||||
return Controller::getProperty(name, buffer, maxsize);
|
||||
}
|
||||
|
|
|
@ -33,14 +33,14 @@ public:
|
|||
virtual int start();
|
||||
virtual int stop();
|
||||
|
||||
virtual int setProperty(const char *name, char *value);
|
||||
virtual const char *getProperty(const char *name, char *buffer,
|
||||
size_t maxlen);
|
||||
|
||||
private:
|
||||
virtual int enable();
|
||||
virtual int disable();
|
||||
|
||||
struct in_addr &getVpnGateway() { return mVpnGateway; }
|
||||
int setVpnGateway(const char *vpnGw);
|
||||
int setVpnGateway(struct in_addr *vpnGw);
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
@ -26,7 +28,7 @@
|
|||
#include "ErrorCode.h"
|
||||
|
||||
WifiController::WifiController(char *modpath, char *modname, char *modargs) :
|
||||
Controller("WIFI") {
|
||||
Controller("WIFI", "wifi") {
|
||||
strncpy(mModulePath, modpath, sizeof(mModulePath));
|
||||
strncpy(mModuleName, modname, sizeof(mModuleName));
|
||||
strncpy(mModuleArgs, modargs, sizeof(mModuleArgs));
|
||||
|
@ -34,6 +36,8 @@ WifiController::WifiController(char *modpath, char *modname, char *modargs) :
|
|||
mSupplicant = new Supplicant();
|
||||
mScanner = new WifiScanner(mSupplicant, 10);
|
||||
mCurrentScanMode = 0;
|
||||
|
||||
registerProperty("scanmode");
|
||||
}
|
||||
|
||||
int WifiController::start() {
|
||||
|
@ -94,7 +98,7 @@ out_powerdown:
|
|||
return -1;
|
||||
}
|
||||
|
||||
void WifiController::sendStatusBroadcast(char *msg) {
|
||||
void WifiController::sendStatusBroadcast(const char *msg) {
|
||||
NetworkManager::Instance()->
|
||||
getBroadcaster()->
|
||||
sendBroadcast(ErrorCode::UnsolicitedInformational, msg, false);
|
||||
|
@ -167,3 +171,20 @@ ScanResultCollection *WifiController::createScanResults() {
|
|||
WifiNetworkCollection *WifiController::createNetworkList() {
|
||||
return mSupplicant->createNetworkList();
|
||||
}
|
||||
|
||||
int WifiController::setProperty(const char *name, char *value) {
|
||||
if (!strcmp(name, "scanmode"))
|
||||
return setScanMode((uint32_t) strtoul(value, NULL, 0));
|
||||
|
||||
return Controller::setProperty(name, value);
|
||||
}
|
||||
|
||||
const char *WifiController::getProperty(const char *name, char *buffer, size_t maxsize) {
|
||||
if (!strcmp(name, "scanmode")) {
|
||||
snprintf(buffer, maxsize, "0x%.8x", mCurrentScanMode);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
return Controller::getProperty(name, buffer, maxsize);
|
||||
}
|
||||
|
||||
|
|
|
@ -54,15 +54,14 @@ public:
|
|||
int start();
|
||||
int stop();
|
||||
|
||||
int enable();
|
||||
int disable();
|
||||
|
||||
int addNetwork();
|
||||
int removeNetwork(int networkId);
|
||||
WifiNetworkCollection *createNetworkList();
|
||||
|
||||
int getScanMode() { return mCurrentScanMode; }
|
||||
int setScanMode(uint32_t mode);
|
||||
virtual int setProperty(const char *name, char *value);
|
||||
virtual const char *getProperty(const char *name, char *buffer,
|
||||
size_t maxlen);
|
||||
|
||||
ScanResultCollection *createScanResults();
|
||||
|
||||
char *getModulePath() { return mModulePath; }
|
||||
|
@ -79,7 +78,13 @@ protected:
|
|||
virtual bool isFirmwareLoaded() = 0;
|
||||
virtual bool isPoweredUp() = 0;
|
||||
|
||||
void sendStatusBroadcast(char *msg);
|
||||
void sendStatusBroadcast(const char *msg);
|
||||
|
||||
private:
|
||||
int setScanMode(uint32_t mode);
|
||||
int enable();
|
||||
int disable();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -65,7 +65,7 @@ void WifiScanner::run() {
|
|||
struct timeval to;
|
||||
int rc = 0;
|
||||
|
||||
to.tv_sec = 0;
|
||||
to.tv_usec = 0;
|
||||
to.tv_sec = mPeriod;
|
||||
|
||||
FD_ZERO(&read_fds);
|
||||
|
@ -83,4 +83,5 @@ void WifiScanner::run() {
|
|||
} else if (FD_ISSET(mCtrlPipe[0], &read_fds))
|
||||
break;
|
||||
} // while
|
||||
LOGD("Stopping wifi scanner");
|
||||
}
|
||||
|
|
|
@ -34,6 +34,10 @@ case "$boot_anim" in
|
|||
;;
|
||||
esac
|
||||
|
||||
# call 'qemu-props' to set system properties from the emulator.
|
||||
#
|
||||
/system/bin/qemu-props
|
||||
|
||||
# this line doesn't really do anything useful. however without it the
|
||||
# previous setprop doesn't seem to apply for some really odd reason
|
||||
setprop ro.qemu.init.completed 1
|
||||
|
|
Loading…
Reference in New Issue