/* Subroutine for splitpdu() for messages type 0 (SMS-Deliver) Returns the length of the ascii string In binary mode ascii contains the binary SMS */ static int split_type_0( char* Pointer,struct incame_sms *sms) { int Length; int padding; int is_binary; Length=octet2bin(Pointer); padding=Length%2; Pointer+=4; memcpy(sms->sender,Pointer,Length+padding); swapchars(sms->sender,Length+padding); /* remove Padding characters after swapping */ sms->sender[Length]=0; Pointer=Pointer+Length+padding+3; is_binary = ((Pointer[0] & 4)==4); Pointer++; set_date(sms->date,Pointer); Pointer=Pointer+6; set_time(sms->time,Pointer); Pointer=Pointer+8; if (is_binary) sms->userdatalength = pdu2binary(Pointer,sms->ascii); else sms->userdatalength = pdu2ascii(Pointer,sms->ascii); return 1; }
/* Subroutine for splitpdu() for messages type 2 (Staus Report) Returns the length of the ascii string. In binary mode ascii contains the binary SMS */ static int split_type_2( char* position, struct incame_sms *sms) { int length; int padding; char *p; /* get from report the sms id */ sms->sms_id = octet2bin(position); position+=2; /* get recipient address */ length=octet2bin(position); padding=length%2; position+=4; memcpy(sms->sender,position,length+padding); sms->sender[length]=0; swapchars(sms->sender,length); // get SMSC timestamp position+=length+padding; set_date(sms->date,position); set_time(sms->time,position+6); // get Discharge timestamp position+=14; p = sms->ascii + 2; set_date(p,position); *(p+DATE_LEN) = ' '; set_time(p+DATE_LEN+1,position+6); // get Status position+=14; sms->ascii[0] = (unsigned char)octet2bin(position); sms->ascii[1] = ' '; sms->ascii[2+DATE_LEN+1+TIME_LEN] = 0; sms->userdatalength=2+DATE_LEN+1+TIME_LEN; return 1; }
/* Returns the length of the ascii string. In binary mode ascii contains the binary SMS */ static int splitpdu(struct modem *mdm, char* pdu, struct incame_sms *sms) { int Length; int Type; char* Pointer; char* start; char* end; /* Get the senders Name if given. Depends on the modem. */ start=strstr(pdu,"\",\""); if (start!=0) { start+=3; end=strstr(start,"\","); if (end!=0) { memcpy(sms->name,start,end-start); sms->name[end-start]=0; } } else end=pdu; /* the pdu is after the first \r */ for( start=end+1 ; *start && *start!='\r' ; start++ ); if (!*start) return 0; pdu=++start; /* removes unwanted ctrl chars at the beginning */ while ( *pdu && (*pdu<=' ')) pdu++; Pointer=pdu; if (mdm->mode!=MODE_OLD) { /* get senders smsc */ Length=octet2bin(pdu)*2-2; if (Length>0) { Pointer=pdu+4; memcpy(sms->smsc,Pointer,Length); swapchars(sms->smsc,Length); /* remove Padding characters after swapping */ if (sms->smsc[Length-1]=='F') sms->smsc[Length-1]=0; else sms->smsc[Length] = 0; } Pointer=pdu+Length+4; } /* is UDH bit set? udh=(octet2bin(Pointer)&4) */ Type=octet2bin(Pointer) & 3; Pointer+=2; if (Type==0) { sms->is_statusreport = 0; /*SMS Deliver*/ return split_type_0( Pointer, sms); } else if (Type==2) { sms->is_statusreport = 1; /*Status Report*/ return split_type_2( Pointer, sms); } /*Unsupported type*/ return -1; }
/* make the PDU string. The destination variable pdu has to be big enough. */ int make_pdu(struct sms_msg *msg, struct modem *mdm, char* pdu) { int coding; int flags; char tmp[500]; int pdu_len=0; int foo; memcpy(tmp,msg->to.s,msg->to.len); foo = msg->to.len; tmp[foo] = 0; // terminate the number with F if the length is odd if ( foo%2 ) { tmp[foo]='F'; tmp[++foo] = 0; } // Swap every second character swapchars(tmp,foo); flags = 0x01; /* SMS-Sumbit MS to SMSC */ if (sms_report_type!=NO_REPORT) flags |= 0x20 ; /* status report request */ coding=240+1; // Dummy + Class 1 if (mdm->mode!=MODE_OLD) flags+=16; // Validity field /* concatenate the first part of the PDU string */ if (mdm->mode==MODE_OLD) pdu_len += sprintf(pdu,"%02X00%02X91%s00%02X%02X",flags, msg->to.len,tmp,coding,msg->text.len); else pdu_len += sprintf(pdu,"00%02X00%02X91%s00%02XA7%02X",flags, msg->to.len,tmp,coding,msg->text.len); /* Create the PDU string of the message */ /* pdu_len += binary2pdu(msg->text.s,msg->text.len,pdu+pdu_len); */ pdu_len += ascii2pdu(msg->text.s,msg->text.len,pdu+pdu_len,1/*convert*/); /* concatenate the text to the PDU string */ return pdu_len; }