diff options
author | Marc Petit-Huguenin <petithug@gmail.com> | 2010-07-14 12:33:15 -0700 |
---|---|---|
committer | Marc Petit-Huguenin <petithug@gmail.com> | 2010-07-27 17:23:41 -0700 |
commit | a1b379c65f787fc85bd9c6f4a6d14d8a2bebc9d5 (patch) | |
tree | 7b3e7fb07704a507f0914e8e6290546b59045934 /telephony | |
parent | 657a3521a1f4d354b57f0e524b1cd57bed177bb0 (diff) | |
download | external_qemu-a1b379c65f787fc85bd9c6f4a6d14d8a2bebc9d5.zip external_qemu-a1b379c65f787fc85bd9c6f4a6d14d8a2bebc9d5.tar.gz external_qemu-a1b379c65f787fc85bd9c6f4a6d14d8a2bebc9d5.tar.bz2 |
Make the GSM simulator more realistic
- The phone number of the phone is now built by concatenating "1555521"
to the console port.
- Convert number in remote call by concatenating "1555521" to the port
number.
- Convert called number to a number starting with "1555521".
- Fixed a bug in sms_address_to_str where the length returned is
incorrect is the length of the phone number to convert is odd.
Change-Id: Iefbdd866b6e41f6086c6e0cc33026551e3d5ae8f
Diffstat (limited to 'telephony')
-rw-r--r-- | telephony/android_modem.c | 50 | ||||
-rw-r--r-- | telephony/gsm.h | 2 | ||||
-rw-r--r-- | telephony/remote_call.c | 21 | ||||
-rw-r--r-- | telephony/sim_card.c | 10 | ||||
-rw-r--r-- | telephony/sim_card.h | 2 | ||||
-rw-r--r-- | telephony/sms.c | 3 |
6 files changed, 71 insertions, 17 deletions
diff --git a/telephony/android_modem.c b/telephony/android_modem.c index 6e73411..1e060dd 100644 --- a/telephony/android_modem.c +++ b/telephony/android_modem.c @@ -357,7 +357,7 @@ amodem_create( int base_port, AModemUnsolFunc unsol_func, void* unsol_opaque modem->unsol_func = unsol_func; modem->unsol_opaque = unsol_opaque; - modem->sim = asimcard_create(); + modem->sim = asimcard_create(base_port); return modem; } @@ -1084,6 +1084,7 @@ handleSendSMSText( const char* cmd, AModem modem ) { #if 1 SmsAddressRec address; + char temp[16]; char number[16]; int numlen; int len = strlen(cmd); @@ -1107,11 +1108,29 @@ handleSendSMSText( const char* cmd, AModem modem ) do { int index; - numlen = sms_address_to_str( &address, number, sizeof(number) ); - if (numlen > sizeof(number)-1) + numlen = sms_address_to_str( &address, temp, sizeof(temp) ); + if (numlen > sizeof(temp)-1) break; + temp[numlen] = 0; + + /* Converts 4, 7, and 10 digits number to 11 digits */ + if (numlen == 10 && !strncmp(temp, PHONE_PREFIX+1, 6)) { + memcpy( number, PHONE_PREFIX, 1 ); + memcpy( number+1, temp, numlen ); + number[numlen+1] = 0; + } else if (numlen == 7 && !strncmp(temp, PHONE_PREFIX+4, 3)) { + memcpy( number, PHONE_PREFIX, 4 ); + memcpy( number+4, temp, numlen ); + number[numlen+4] = 0; + } else if (numlen == 4) { + memcpy( number, PHONE_PREFIX, 7 ); + memcpy( number+7, temp, numlen ); + number[numlen+7] = 0; + } else { + memcpy( number, temp, numlen ); + number[numlen] = 0; + } - number[numlen] = 0; if ( remote_number_string_to_port( number ) < 0 ) break; @@ -1133,11 +1152,11 @@ handleSendSMSText( const char* cmd, AModem modem ) if (index > 0) { SmsAddressRec from[1]; - char temp[10]; + char temp[12]; SmsPDU* deliver; int nn; - sprintf( temp, "%d", modem->base_port ); + snprintf( temp, sizeof(temp), PHONE_PREFIX "%d", modem->base_port ); sms_address_from_str( from, temp, strlen(temp) ); deliver = sms_receiver_create_deliver( modem->sms_receiver, index, from ); @@ -1533,8 +1552,23 @@ handleDial( const char* cmd, AModem modem ) if (len >= sizeof(call->number)) len = sizeof(call->number)-1; - memcpy( call->number, cmd, len ); - call->number[len] = 0; + /* Converts 4, 7, and 10 digits number to 11 digits */ + if (len == 10 && !strncmp(cmd, PHONE_PREFIX+1, 6)) { + memcpy( call->number, PHONE_PREFIX, 1 ); + memcpy( call->number+1, cmd, len ); + call->number[len+1] = 0; + } else if (len == 7 && !strncmp(cmd, PHONE_PREFIX+4, 3)) { + memcpy( call->number, PHONE_PREFIX, 4 ); + memcpy( call->number+4, cmd, len ); + call->number[len+4] = 0; + } else if (len == 4) { + memcpy( call->number, PHONE_PREFIX, 7 ); + memcpy( call->number+7, cmd, len ); + call->number[len+7] = 0; + } else { + memcpy( call->number, cmd, len ); + call->number[len] = 0; + } vcall->is_remote = (remote_number_string_to_port(call->number) > 0); diff --git a/telephony/gsm.h b/telephony/gsm.h index f799dea..ec52a38 100644 --- a/telephony/gsm.h +++ b/telephony/gsm.h @@ -193,4 +193,6 @@ extern void gsm_rope_add_c( GsmRope rope, char c ); extern void gsm_rope_add( GsmRope rope, const void* str, int len ); extern void* gsm_rope_reserve( GsmRope rope, int len ); +#define PHONE_PREFIX "1555521" + #endif /* _android_gsm_h */ diff --git a/telephony/remote_call.c b/telephony/remote_call.c index 927e11d..43c9099 100644 --- a/telephony/remote_call.c +++ b/telephony/remote_call.c @@ -78,7 +78,16 @@ int remote_number_string_to_port( const char* number ) { char* end; - long num = strtol( number, &end, 10 ); + long num; + char* temp = number; + int len; + + len = strlen(number); + if (len > 0 && number[len-1] == ';') + len--; + if (len == 11 && !memcmp(number, PHONE_PREFIX, 7)) + temp += 7; + num = strtol( temp, &end, 10 ); if (end == NULL || *end || (int)num != num ) return -1; @@ -167,23 +176,23 @@ remote_call_alloc( RemoteCallType type, int to_port, int from_port ) switch (type) { case REMOTE_CALL_DIAL: - p = bufprint(p, end, "gsm call %d\n", from_num ); + p = bufprint(p, end, "gsm call " PHONE_PREFIX "%d\n", from_num ); break; case REMOTE_CALL_BUSY: - p = bufprint(p, end, "gsm busy %d\n", from_num); + p = bufprint(p, end, "gsm busy " PHONE_PREFIX "%d\n", from_num); break; case REMOTE_CALL_HOLD: - p = bufprint(p, end, "gsm hold %d\n", from_num); + p = bufprint(p, end, "gsm hold " PHONE_PREFIX "%d\n", from_num); break; case REMOTE_CALL_ACCEPT: - p = bufprint(p, end, "gsm accept %d\n", from_num); + p = bufprint(p, end, "gsm accept " PHONE_PREFIX "%d\n", from_num); break; case REMOTE_CALL_HANGUP: - p = bufprint(p, end, "gsm cancel %d\n", from_num ); + p = bufprint(p, end, "gsm cancel " PHONE_PREFIX "%d\n", from_num ); break; default: diff --git a/telephony/sim_card.c b/telephony/sim_card.c index a5a3249..b172deb 100644 --- a/telephony/sim_card.c +++ b/telephony/sim_card.c @@ -12,6 +12,7 @@ #include "sim_card.h" #include <string.h> #include <assert.h> +#include <stdio.h> /* set ENABLE_DYNAMIC_RECORDS to 1 to enable dynamic records * for now, this is an experimental feature that needs more testing @@ -26,6 +27,7 @@ typedef struct ASimCardRec_ { char pin[ A_SIM_PIN_SIZE+1 ]; char puk[ A_SIM_PUK_SIZE+1 ]; int pin_retries; + int port; char out_buff[ 256 ]; int out_size; @@ -35,13 +37,14 @@ typedef struct ASimCardRec_ { static ASimCardRec _s_card[1]; ASimCard -asimcard_create( void ) +asimcard_create(int port) { ASimCard card = _s_card; card->status = A_SIM_STATUS_READY; card->pin_retries = 0; strncpy( card->pin, "0000", sizeof(card->pin) ); strncpy( card->puk, "12345678", sizeof(card->puk) ); + card->port = port; return card; } @@ -429,6 +432,11 @@ asimcard_io( ASimCard sim, const char* cmd ) } #endif + if (!strcmp("+CRSM=178,28480,1,4,32", cmd)) { + snprintf( sim->out_buff, sizeof(sim->out_buff), "+CRSM: 144,0,ffffffffffffffffffffffffffffffffffff0781515525%d1%d%df%dffffffffffff", (sim->port / 1000) % 10, (sim->port / 10) % 10, (sim->port / 100) % 10, sim->port % 10); + return sim->out_buff; + } + for (nn = 0; answers[nn].cmd != NULL; nn++) { if ( !strcmp( answers[nn].cmd, cmd ) ) { return answers[nn].answer; diff --git a/telephony/sim_card.h b/telephony/sim_card.h index af78237..1bab1ba 100644 --- a/telephony/sim_card.h +++ b/telephony/sim_card.h @@ -16,7 +16,7 @@ typedef struct ASimCardRec_* ASimCard; -extern ASimCard asimcard_create( void ); +extern ASimCard asimcard_create( int from_port ); extern void asimcard_destroy( ASimCard sim ); typedef enum { diff --git a/telephony/sms.c b/telephony/sms.c index 448eab4..50ef715 100644 --- a/telephony/sms.c +++ b/telephony/sms.c @@ -353,7 +353,8 @@ sms_address_to_str( SmsAddress address, char* str, int strlen ) if (count < strlen) str[count] = dialdigits[(c >> 4) & 0xf]; - count += 1; + if (str[count]) + count += 1; } return count; } |