Preparatory work for Thomas to implement sending/receiving SMS over the mesh.

This commit is contained in:
gardners 2011-03-22 17:03:14 +10:30
parent af2ec8dc51
commit f537141b13
3 changed files with 40 additions and 2 deletions

View File

@ -77,7 +77,7 @@ int packetSendRequest(int method,unsigned char *packet,int packet_len,int batchP
return 0;
}
getPeerList();
if (!peer_count) getPeerList();
gettimeofday(&time_in,NULL);

View File

@ -227,6 +227,7 @@ extern struct mphlr_variable vars[];
#define ACTION_SET 0x01
#define ACTION_DEL 0x02
#define ACTION_INSERT 0x03
#define ACTION_SENDSMS 0x04
#define ACTION_CREATEHLR 0x0f
#define ACTION_DONE 0x7e
@ -236,6 +237,7 @@ extern struct mphlr_variable vars[];
#define ACTION_OKAY 0x81
#define ACTION_DATA 0x82
#define ACTION_WROTE 0x83
#define ACTION_SMSRECEIVED 0x84
#define ACTION_XFER 0xf0
#define ACTION_PAD 0xfe

View File

@ -129,7 +129,7 @@ int processRequest(unsigned char *packet,int len,
unsigned char *transaction_id,char *did,char *sid)
{
/* Find HLR entry by DID or SID, unless creating */
int ofs,rofs;
int ofs,rofs=0;
int records_searched=0;
int prev_pofs=0;
@ -173,6 +173,42 @@ int processRequest(unsigned char *packet,int len,
case ACTION_EOT: /* EOT */
pofs=len;
break;
case ACTION_SENDSMS: /* Send an SMS to the specified SID. */
/* You cannot use a DID */
if (did[0]) return respondSimple(NULL,ACTION_DECLINED,NULL,0,transaction_id);
/* XXX Thomas to complete and make sure it works:
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) {
/* Already exists, so no need to deliver it again */
respondSimple(sid,ACTION_SMSRECEIVED,NULL,0,transaction_id);
}
else
{
/* 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);
}
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);
}
}
break;
case ACTION_SET:
ofs=0;
if (debug>1) fprintf(stderr,"Looking for hlr entries with sid='%s' / did='%s'\n",sid,did);