From 318f17a0050e729bce8545463b657c1d62835b5e Mon Sep 17 00:00:00 2001 From: Vladimir Chtchetkine Date: Fri, 27 Aug 2010 09:09:45 -0700 Subject: Fixed dependency ob core data in android/help.c Also moved along -tcpdump option Change-Id: I9fc53e0dc6a86e9a880d6127bf2da3ac1d7ec58a --- android/android.h | 2 ++ android/help.c | 36 +++++++++++--------- android/main.c | 12 +++---- android/ui-core-protocol.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++ android/ui-core-protocol.h | 34 +++++++++++++++++++ net-android.c | 8 +++-- qemu-options.hx | 3 ++ vl-android.c | 14 ++++++++ 8 files changed, 167 insertions(+), 24 deletions(-) diff --git a/android/android.h b/android/android.h index 62ef789..189b5c2 100644 --- a/android/android.h +++ b/android/android.h @@ -40,6 +40,7 @@ typedef struct { } NetworkSpeed; extern const NetworkSpeed android_netspeeds[]; +extern const size_t android_netspeeds_count; /* list of supported network latency names and min-max values in ms */ typedef struct { @@ -50,6 +51,7 @@ typedef struct { } NetworkLatency; extern const NetworkLatency android_netdelays[]; +extern const size_t android_netdelays_count; /* default network settings for emulator */ #define DEFAULT_NETSPEED "full" diff --git a/android/help.c b/android/help.c index 3527c34..ea419f3 100644 --- a/android/help.c +++ b/android/help.c @@ -10,6 +10,7 @@ #include "audio/audio.h" #include #include +#include "android/ui-core-protocol.h" /* XXX: TODO: put most of the help stuff in auto-generated files */ @@ -653,7 +654,8 @@ static void help_shaper(stralloc_t* out) { int n; - + NetworkSpeed android_netspeed; + NetworkLatency android_netdelay; PRINTF( " the Android emulator supports network throttling, i.e. slower network\n" " bandwidth as well as higher connection latencies. this is done either through\n" @@ -661,22 +663,22 @@ help_shaper(stralloc_t* out) " the format of -netspeed is one of the following (numbers are kbits/s):\n\n" ); - for (n = 0; android_netspeeds[n].name != NULL; n++) { + for (n = 0; !android_core_get_android_netspeed(n, &android_netspeed); n++) { PRINTF( " -netspeed %-12s %-15s (up: %.1f, down: %.1f)\n", - android_netspeeds[n].name, - android_netspeeds[n].display, - android_netspeeds[n].upload/1000., - android_netspeeds[n].download/1000. ); + android_netspeed.name, + android_netspeed.display, + android_netspeed.upload/1000., + android_netspeed.download/1000. ); } PRINTF( "\n" ); PRINTF( " -netspeed %-12s %s", "", "select both upload and download speed\n"); PRINTF( " -netspeed %-12s %s", ":", "select individual up and down speed\n"); PRINTF( "\n The format of -netdelay is one of the following (numbers are msec):\n\n" ); - for (n = 0; android_netdelays[n].name != NULL; n++) { + for (n = 0; !android_core_get_android_netdelay(n, &android_netdelay); n++) { PRINTF( " -netdelay %-10s %-15s (min %d, max %d)\n", - android_netdelays[n].name, android_netdelays[n].display, - android_netdelays[n].min_ms, android_netdelays[n].max_ms ); + android_netdelay.name, android_netdelay.display, + android_netdelay.min_ms, android_netdelay.max_ms ); } PRINTF( " -netdelay %-10s %s", "", "select exact latency\n"); PRINTF( " -netdelay %-10s %s", ":", "select min and max latencies\n\n"); @@ -781,10 +783,12 @@ help_audio_out(stralloc_t* out) " on this system, output can be one of the following:\n\n" ); for ( nn = 0; ; nn++ ) { - const char* descr; - const char* name = audio_get_backend_name( 0, nn, &descr ); - if (name == NULL) + char name[512]; + char descr[4096]; + if (android_core_audio_get_backend_name(0, nn, name, sizeof(name), + descr, sizeof(descr))) { break; + } PRINTF( " %-10s %s\n", name, descr ); } PRINTF( "\n" ); @@ -809,10 +813,12 @@ help_audio_in(stralloc_t* out) " on this system, input can be one of:\n\n" ); for ( nn = 0; ; nn++ ) { - const char* descr; - const char* name = audio_get_backend_name( 1, nn, &descr ); - if (name == NULL) + char name[512]; + char descr[4096]; + if (android_core_audio_get_backend_name(1, nn, name, sizeof(name), + descr, sizeof(descr))) { break; + } PRINTF( " %-10s %s\n", name, descr ); } PRINTF( "\n" ); diff --git a/android/main.c b/android/main.c index 03d0ffd..c03280d 100644 --- a/android/main.c +++ b/android/main.c @@ -61,7 +61,6 @@ #include "hw/goldfish_nand.h" #include "android/globals.h" -#include "tcpdump.h" #include "android/qemulator.h" #include "android/display.h" @@ -1153,12 +1152,6 @@ int main(int argc, char **argv) opts->trace = tracePath; } - if (opts->tcpdump) { - if (qemu_tcpdump_start(opts->tcpdump) < 0) { - dwarning( "could not start packet capture: %s", strerror(errno)); - } - } - if (opts->no_cache) opts->cache = 0; @@ -1190,6 +1183,11 @@ int main(int argc, char **argv) } } + if (opts->tcpdump) { + args[n++] = "-tcpdump"; + args[n++] = opts->tcpdump; + } + #ifdef CONFIG_NAND_LIMITS if (opts->nand_limits) { args[n++] = "-nand-limits"; diff --git a/android/ui-core-protocol.c b/android/ui-core-protocol.c index a5caba0..7442c73 100644 --- a/android/ui-core-protocol.c +++ b/android/ui-core-protocol.c @@ -23,8 +23,11 @@ #include "android/globals.h" #include "android/hw-control.h" #include "android/ui-core-protocol.h" +#if !defined(CONFIG_STANDALONE_UI) #include "telephony/modem_driver.h" #include "trace.h" +#include "audio/audio.h" +#endif // CONFIG_STANDALONE_UI int android_core_get_hw_lcd_density(void) @@ -39,38 +42,117 @@ android_core_set_brightness_change_callback(AndroidHwLightBrightnessCallback cal AndroidHwControlFuncs funcs; funcs.light_brightness = callback; +#if !defined(CONFIG_STANDALONE_UI) android_hw_control_init( opaque, &funcs ); +#endif // CONFIG_STANDALONE_UI } int android_core_get_base_port(void) { +#if !defined(CONFIG_STANDALONE_UI) return android_base_port; +#else + return 5554; +#endif // CONFIG_STANDALONE_UI } void android_core_sensors_set_coarse_orientation( AndroidCoarseOrientation orient ) { +#if !defined(CONFIG_STANDALONE_UI) android_sensors_set_coarse_orientation(orient); +#endif // CONFIG_STANDALONE_UI } void android_core_set_network_enabled(int enabled) { +#if !defined(CONFIG_STANDALONE_UI) if (android_modem) { amodem_set_data_registration( android_modem, qemu_net_disable ? A_REGISTRATION_UNREGISTERED : A_REGISTRATION_HOME); } +#endif // CONFIG_STANDALONE_UI } void android_core_tracing_start(void) { +#if !defined(CONFIG_STANDALONE_UI) start_tracing(); +#endif // CONFIG_STANDALONE_UI } void android_core_tracing_stop(void) { +#if !defined(CONFIG_STANDALONE_UI) stop_tracing(); +#endif // CONFIG_STANDALONE_UI +} + +int +android_core_get_android_netspeed(int index, NetworkSpeed* netspeed) { + /* This is a temporary code used to support current behavior of the + *monolitic (core + ui in one executable) emulator executed with + * -help-netspeed option. In the future, when ui and core get separated, + * behavior of help may change, and this code should be reviewed. */ +#if !defined(CONFIG_STANDALONE_UI) + if (index >= android_netspeeds_count || + android_netspeeds[index].name == NULL) { + return -1; + } + *netspeed = android_netspeeds[index]; + return 0; +#else + return -1; +#endif // !CONFIG_STANDALONE_UI +} + +int +android_core_get_android_netdelay(int index, NetworkLatency* delay) { + /* This is a temporary code used to support current behavior of the + * monolitic (core + ui in one executable) emulator executed with + * -help-netdelays option. In the future, when ui and core get separated, + * behavior of help may change, and this code should be reviewed. */ +#if !defined(CONFIG_STANDALONE_UI) + if (index >= android_netdelays_count || + android_netdelays[index].name == NULL) { + return -1; + } + *delay = android_netdelays[index]; + return 0; +#else + return -1; +#endif // !CONFIG_STANDALONE_UI +} + +int +android_core_audio_get_backend_name(int is_input, int index, + char* name, size_t name_buf_size, + char* descr, size_t descr_buf_size) { + /* This is a temporary code used to support current behavior of the + * monolitic (core + ui in one executable) emulator executed with + * -help-audio-in, and -help-audio-in options. In the future, when ui and + * core get separated, behavior of help may change, and this code should + * be reviewed. */ +#if !defined(CONFIG_STANDALONE_UI) + const char* descr_ptr = NULL; + const char* name_ptr = audio_get_backend_name(is_input, index, &descr_ptr); + if (name_ptr == NULL) { + return -1; + } + if (name != NULL && name_buf_size) { + strncpy(name, name_ptr, name_buf_size); + name[name_buf_size - 1] = '\0'; + } + if (descr != NULL && descr_buf_size && descr_ptr != NULL) { + strncpy(descr, descr_ptr, descr_buf_size); + descr[descr_buf_size - 1] = '\0'; + } + return 0; +#else + return -1; +#endif // !CONFIG_STANDALONE_UI } diff --git a/android/ui-core-protocol.h b/android/ui-core-protocol.h index f461d21..16f49df 100644 --- a/android/ui-core-protocol.h +++ b/android/ui-core-protocol.h @@ -52,4 +52,38 @@ void android_core_set_network_enabled(int enabled); void android_core_tracing_start(void); void android_core_tracing_stop(void); +/* Gets an entry in android_netspeeds array defined in net-android.c + * Parameters: + * index - Index of the entry to get from the array. + * netspeed - Upon successful return contains copy of the requested entry. + * Return: + * 0 on success, or -1 if requested entry index is too large. + */ +int android_core_get_android_netspeed(int index, NetworkSpeed* netspeed); + +/* Gets an entry in android_netdelays array defined in net-android.c + * Parameters: + * index - Index of the entry to get from the array. + * netspeed - Upon successful return contains copy of the requested entry. + * Return: + * 0 on success, or -1 if requested entry index is too large. + */ +int android_core_get_android_netdelay(int index, NetworkLatency* delay); + +/* Get name of a given audio backend. + * Parameters + * is_input - If 1, routine should lookup for input audio backend, if zero, + * routine should lookup for output audio backend. + * index - Index of the registered audio backend to lookup. + * name - Upon successful return contains backend name. + * name_buf_size - name buffer size (in characters). + * descr - Upon successful return contains backend description. + * descr_buf_size - descre buffer size (in characters). + * Return: + * 0 on success, or -1 if requested backend has not been found. + */ +int android_core_audio_get_backend_name(int is_input, int index, + char* name, size_t name_buf_size, + char* descr, size_t descr_buf_size); + #endif // QEMU_ANDROID_UI_CORE_PROTOCOL_H diff --git a/net-android.c b/net-android.c index cc1db96..234235b 100644 --- a/net-android.c +++ b/net-android.c @@ -146,6 +146,8 @@ const NetworkSpeed android_netspeeds[] = { { "full", "no limit", 0, 0 }, { NULL, NULL, 0, 0 } }; +const size_t android_netspeeds_count = + sizeof(android_netspeeds) / sizeof(android_netspeeds[0]); const NetworkLatency android_netdelays[] = { /* FIXME: these numbers are totally imaginary */ @@ -155,6 +157,8 @@ const NetworkLatency android_netdelays[] = { { "none", "no latency", 0, 0 }, { NULL, NULL, 0, 0 } }; +const size_t android_netdelays_count = + sizeof(android_netdelays) / sizeof(android_netdelays[0]); /***********************************************************/ /* network device redirectors */ @@ -194,7 +198,7 @@ static int parse_macaddr(uint8_t *macaddr, const char *p) long int offset; errno = 0; - offset = strtol(p, &last_char, 0); + offset = strtol(p, &last_char, 0); if (0 == errno && '\0' == *last_char && offset >= 0 && offset <= 0xFFFFFF) { macaddr[3] = (offset & 0xFF0000) >> 16; @@ -213,7 +217,7 @@ static int parse_macaddr(uint8_t *macaddr, const char *p) p++; } } - return 0; + return 0; } return -1; diff --git a/qemu-options.hx b/qemu-options.hx index d2d32c8..4f6f122 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -1671,4 +1671,7 @@ DEF("netdelay", HAS_ARG, QEMU_OPTION_netdelay, \ DEF("netfast", 0, QEMU_OPTION_netfast, \ "-netfast disable network shaping\n") +DEF("tcpdump", HAS_ARG, QEMU_OPTION_tcpdump, \ + "-tcpdump capture network packets to file\n") + #endif diff --git a/vl-android.c b/vl-android.c index cdaeb64..07ef4e2 100644 --- a/vl-android.c +++ b/vl-android.c @@ -57,6 +57,7 @@ #include "android/globals.h" #include "android/utils/bufprint.h" #include "targphys.h" +#include "tcpdump.h" #ifdef CONFIG_MEMCHECK #include "memcheck/memcheck.h" @@ -387,6 +388,9 @@ char* android_op_netdelay = NULL; /* -netfast option value. */ int android_op_netfast = 0; +/* -tcpdump option value. */ +char* android_op_tcpdump = NULL; + extern int android_display_width; extern int android_display_height; extern int android_display_bpp; @@ -5958,6 +5962,9 @@ int main(int argc, char **argv, char **envp) android_op_netfast = 1; break; + case QEMU_OPTION_tcpdump: + android_op_tcpdump = (char*)optarg; + break; #ifdef CONFIG_MEMCHECK case QEMU_OPTION_android_memcheck: @@ -6040,6 +6047,13 @@ int main(int argc, char **argv, char **envp) qemu_net_max_latency = 0; } + /* Initialize TCP dump */ + if (android_op_tcpdump) { + if (qemu_tcpdump_start(android_op_tcpdump) < 0) { + fprintf(stdout, "could not start packet capture: %s\n", strerror(errno)); + } + } + /* Initialize modem */ if (android_op_radio) { CharDriverState* cs = qemu_chr_open("radio", android_op_radio, NULL); -- cgit v1.1