Thomas' modifications to recieve DT SMS and escalate to Java via an intent.

This commit is contained in:
Jeremy Lakeman 2011-05-23 21:05:15 +09:30
parent ba758f71ca
commit 83f88a6d08
2 changed files with 23 additions and 37 deletions

3
mphlr.h Executable file → Normal file
View File

@ -241,7 +241,7 @@ extern struct mphlr_variable vars[];
#define ACTION_SET 0x01 #define ACTION_SET 0x01
#define ACTION_DEL 0x02 #define ACTION_DEL 0x02
#define ACTION_INSERT 0x03 #define ACTION_INSERT 0x03
#define ACTION_SENDSMS 0x04 #define ACTION_DIGITALTELEGRAM 0x04
#define ACTION_CREATEHLR 0x0f #define ACTION_CREATEHLR 0x0f
#define ACTION_STATS 0x40 #define ACTION_STATS 0x40
@ -253,7 +253,6 @@ extern struct mphlr_variable vars[];
#define ACTION_OKAY 0x81 #define ACTION_OKAY 0x81
#define ACTION_DATA 0x82 #define ACTION_DATA 0x82
#define ACTION_WROTE 0x83 #define ACTION_WROTE 0x83
#define ACTION_SMSRECEIVED 0x84
#define ACTION_XFER 0xf0 #define ACTION_XFER 0xf0
#define ACTION_PAD 0xfe #define ACTION_PAD 0xfe

57
server.c Executable file → Normal file
View File

@ -195,43 +195,30 @@ int processRequest(unsigned char *packet,int len,
} }
} }
break; break;
case ACTION_SENDSMS: /* Send an SMS to the specified SID. */ case ACTION_DIGITALTELEGRAM:
/* You cannot use a DID */ // Unpack SMS message.
if (did[0]) return respondSimple(NULL,ACTION_DECLINED,NULL,0,transaction_id,CRYPT_CIPHERED|CRYPT_SIGNED); {
char emitterPhoneNumber[256];
char message[256];
pofs++;
char messageType = packet[pofs];
pofs++;
char emitterPhoneNumberLen = packet[pofs];
pofs++;
char messageLen = packet[pofs];
pofs++;
strncpy(emitterPhoneNumber, (const char*)packet+pofs, emitterPhoneNumberLen);
pofs+=emitterPhoneNumberLen;
strncpy(message, (const char*)packet+pofs, messageLen);
pofs+=messageLen;
/* XXX Thomas to complete and make sure it works: // Check if I'm the recipient
1. Unpack SMS message.
2. Make sure it hasn't already been delivered.
3. Make sure there is space to deliver it .
4. Deliver it to the next free message slot
*/
{
// extractSMS(...); -- don't forget to check maximum message length
int instance=-1; /* use first free slot */
unsigned char oldvalue[65536];
int oldl=65536;
int oldr=hlrGetVariable(hlr,ofs,VAR_SMESSAGES,instance,oldvalue,&oldl);
if (oldr) { // Send SMS to android
/* Already exists, so no need to deliver it again */ char amCommand[576]; // 64 char + 2*256(max) char = 576
respondSimple(sid,ACTION_SMSRECEIVED,NULL,0,transaction_id,CRYPT_CIPHERED|CRYPT_SIGNED); sprintf(amCommand, "am broadcast -a org.servalproject.DT -e number \"%s\" -e content \"%s\"", emitterPhoneNumber, message);
} int exitcode = printf(amCommand);
else //int exitcode = system(amCommand);
{
/* Write new value back */
if (hlrSetVariable(hlr,ofs,VAR_SMESSAGES,instance,oldvalue,oldl))
{
setReason("Failed to write variable");
return
respondSimple(NULL,ACTION_ERROR,(unsigned char *)"No space for message",0,transaction_id,
CRYPT_CIPHERED|CRYPT_SIGNED);
}
if (debug>2) { fprintf(stderr,"HLR after writing:\n"); hlrDump(hlr,ofs); }
/* Reply that we wrote the fragment */
respondSimple(sid,ACTION_WROTE,&packet[rofs],6,
transaction_id,CRYPT_CIPHERED|CRYPT_SIGNED);
}
} }
break; break;
case ACTION_SET: case ACTION_SET: