aboutsummaryrefslogtreecommitdiffstats
path: root/net-android.c
diff options
context:
space:
mode:
authorVladimir Chtchetkine <vchtchetkine@google.com>2010-07-15 12:27:56 -0700
committerVladimir Chtchetkine <vchtchetkine@google.com>2010-07-15 12:27:56 -0700
commiteb8382507c6b802f378cf940fae4775633c1d84e (patch)
treed5974956e7487b2cb3af339abff2139d28e4b091 /net-android.c
parent7258f6b1539906849d02fa9f5e75360b0d01f48c (diff)
downloadexternal_qemu-eb8382507c6b802f378cf940fae4775633c1d84e.zip
external_qemu-eb8382507c6b802f378cf940fae4775633c1d84e.tar.gz
external_qemu-eb8382507c6b802f378cf940fae4775633c1d84e.tar.bz2
Move net-related routines from main.c to net-android.c
Change-Id: If102220e6db913f4a51bb1809ce60f4bf24bdd6a
Diffstat (limited to 'net-android.c')
-rw-r--r--net-android.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/net-android.c b/net-android.c
index 8649b82..cc1db96 100644
--- a/net-android.c
+++ b/net-android.c
@@ -130,8 +130,32 @@
#include "shaper.h"
#endif
+#include "android/android.h"
+#include "telephony/modem_driver.h"
+
static VLANState *first_vlan;
+/* see http://en.wikipedia.org/wiki/List_of_device_bandwidths or a complete list */
+const NetworkSpeed android_netspeeds[] = {
+ { "gsm", "GSM/CSD", 14400, 14400 },
+ { "hscsd", "HSCSD", 14400, 43200 },
+ { "gprs", "GPRS", 40000, 80000 },
+ { "edge", "EDGE/EGPRS", 118400, 236800 },
+ { "umts", "UMTS/3G", 128000, 1920000 },
+ { "hsdpa", "HSDPA", 348000, 14400000 },
+ { "full", "no limit", 0, 0 },
+ { NULL, NULL, 0, 0 }
+};
+
+const NetworkLatency android_netdelays[] = {
+ /* FIXME: these numbers are totally imaginary */
+ { "gprs", "GPRS", 150, 550 },
+ { "edge", "EDGE/EGPRS", 80, 400 },
+ { "umts", "UMTS/3G", 35, 200 },
+ { "none", "no latency", 0, 0 },
+ { NULL, NULL, 0, 0 }
+};
+
/***********************************************************/
/* network device redirectors */
@@ -2608,3 +2632,79 @@ void net_client_check(void)
vlan->id);
}
}
+
+int
+android_parse_network_speed(const char* speed)
+{
+ int n;
+ char* end;
+ double sp;
+
+ if (speed == NULL || speed[0] == 0) {
+ speed = DEFAULT_NETSPEED;
+ }
+
+ for (n = 0; android_netspeeds[n].name != NULL; n++) {
+ if (!strcmp(android_netspeeds[n].name, speed)) {
+ qemu_net_download_speed = android_netspeeds[n].download;
+ qemu_net_upload_speed = android_netspeeds[n].upload;
+ return 0;
+ }
+ }
+
+ /* is this a number ? */
+ sp = strtod(speed, &end);
+ if (end == speed) {
+ return -1;
+ }
+
+ qemu_net_download_speed = qemu_net_upload_speed = sp*1000.;
+ if (*end == ':') {
+ speed = end+1;
+ sp = strtod(speed, &end);
+ if (end > speed) {
+ qemu_net_download_speed = sp*1000.;
+ }
+ }
+
+ if (android_modem)
+ amodem_set_data_network_type( android_modem,
+ android_parse_network_type(speed) );
+ return 0;
+}
+
+
+int
+android_parse_network_latency(const char* delay)
+{
+ int n;
+ char* end;
+ double sp;
+
+ if (delay == NULL || delay[0] == 0)
+ delay = DEFAULT_NETDELAY;
+
+ for (n = 0; android_netdelays[n].name != NULL; n++) {
+ if ( !strcmp( android_netdelays[n].name, delay ) ) {
+ qemu_net_min_latency = android_netdelays[n].min_ms;
+ qemu_net_max_latency = android_netdelays[n].max_ms;
+ return 0;
+ }
+ }
+
+ /* is this a number ? */
+ sp = strtod(delay, &end);
+ if (end == delay) {
+ return -1;
+ }
+
+ qemu_net_min_latency = qemu_net_max_latency = (int)sp;
+ if (*end == ':') {
+ delay = (const char*)end+1;
+ sp = strtod(delay, &end);
+ if (end > delay) {
+ qemu_net_max_latency = (int)sp;
+ }
+ }
+ return 0;
+}