25 #include "../../misc/coding/coding.h" 26 #include "../../debug.h" 49 {
UDH_VoidSMS, 0x08,
"\x01\x02\x02\x01\x01\x02\x02\x00",-1,-1,-1,-1},
60 {
UDH_NokiaWAP, 0x06,
"\x05\x04\xc3\x4f\x00\x00",-1,-1,-1,-1},
79 {
UDH_NokiaWAPLong, 0x0b,
"\x05\x04\xc3\x4f\x00\x00\x00\x03\x7f\x00\x00",8,-1,10,9},
104 DT->
Timezone = (10 * (req[6] & 0x07) + (req[6] >> 4)) *3600 / 4;
133 while (UDHHeaders[++i].Type !=
UDH_NoUDH) {
137 if (tmp==UDH->
Text[0]) {
147 if (tmp == 0x06 && UDH->
Text[1] == 0x08) {
152 for (w = 0; w < tmp; w++) {
153 if (UDHHeaders[i].Text[w] != UDH->
Text[w + 1]) {
161 if (UDHHeaders[i].ID8bit !=-1) {
164 if (UDHHeaders[i].ID16bit !=-1) {
167 if (UDHHeaders[i].PartNumber !=-1) {
170 if (UDHHeaders[i].AllParts !=-1) {
182 smfprintf(di,
"Concatenated (linked) message");
185 smfprintf(di,
"Concatenated (linked) message");
188 smfprintf(di,
"Disables voice indicator");
191 smfprintf(di,
"Enables voice indicator");
200 smfprintf(di,
"Disables email indicator");
203 smfprintf(di,
"Enables email indicator");
215 smfprintf(di,
"Nokia WAP Bookmark or WAP/MMS Settings");
224 smfprintf(di,
"Nokia GSM operator logo");
264 if ((TPDCS & 0xC0) == 0 || (TPDCS & 0xC0) == 0x40) {
267 if ((TPDCS & 0xC) == 0xC) {
268 smfprintf(di,
"WARNING: reserved alphabet value in TPDCS\n");
273 if ((TPDCS & 0x2C) == 0x00) {
276 if ((TPDCS & 0x2C) == 0x20) {
279 if ((TPDCS & 0x2C) == 0x08) {
282 if ((TPDCS & 0x2C) == 0x28) {
286 }
else if ((TPDCS & 0xF0) >= 0x40 &&
287 (TPDCS & 0xF0) <= 0xB0) {
289 smfprintf(di,
"WARNING: reserved coding group in TPDCS\n");
290 }
else if (((TPDCS & 0xF0) == 0xC0) ||
291 ((TPDCS & 0xF0) == 0xD0)) {
293 if ((TPDCS & 4) == 4) {
294 smfprintf(di,
"WARNING: set reserved bit 2 in TPDCS\n");
298 }
else if ((TPDCS & 0xF0) == 0xE0) {
300 if ((TPDCS & 4) == 4) {
301 smfprintf(di,
"WARNING: set reserved bit 2 in TPDCS\n");
305 }
else if ((TPDCS & 0xF0) == 0xF0) {
307 if ((TPDCS & 8) == 8) {
308 smfprintf(di,
"WARNING: set reserved bit 3 in TPDCS\n");
320 unsigned char output[1024];
326 off = (buffer[Layout.
Text] + 1);
327 if (off > buffer[Layout.
TPUDL]) {
331 smfprintf(di,
"UDH header available (length %i)\n",off);
334 for (i = 0; i < off; i++) {
348 SMS->
Length=buffer[Layout.
TPUDL] - (off*8 + w) / 7;
392 }
else if (TP_ST & 0x40) {
395 }
else if (TP_ST & 0x20) {
408 smfprintf(di,
"Temporary error, SC is not making any more transfer attempts\n");
411 smfprintf(di,
"Permanent error, SC is not making any more transfer attempts\n");
413 }
else if (TP_ST & 0x20) {
415 smfprintf(di,
"Temporary error, SC still trying to transfer SM\n");
422 smfprintf(di,
"SM forwarded by the SC to the SME but the SC is unable to confirm delivery");
440 smfprintf(di,
"Quality of service not available");
449 smfprintf(di,
"Incompatible destination");
452 smfprintf(di,
"Connection rejected by SME");
458 smfprintf(di,
"Quality of service not available");
461 smfprintf(di,
"No internetworking available");
464 smfprintf(di,
"SM Validity Period Expired");
467 smfprintf(di,
"SM deleted by originating SME");
470 smfprintf(di,
"SM Deleted by SC Administration");
488 smfprintf(di,
"Quality of service not available");
494 smfprintf(di,
"Reserved/Specific to SC: %x",TP_ST);
515 unsigned char output[161];
535 switch (type & 0x3) {
545 smfprintf(di,
"SMS type: Status report");
549 smfprintf(di,
"SMS type: Reserved message type, aborting!\n");
554 if (type & (1 << 7)) {
557 if (type & (1 << 6)) {
561 if (type & (1 << 5)) {
562 smfprintf(di,
", Delivery report requested");
566 vpf = (type & (0x3 << 3)) >> 3;
590 smfprintf(di,
"Ran out of buffer when parsing PDU!\n");
602 smfprintf(di,
"Ran out of buffer when parsing PDU!\n");
609 smfprintf(di,
"SMS PID: 0x%02X\n", buffer[pos]);
610 if (buffer[pos] > 0x40 && buffer[pos] < 0x48) {
615 smfprintf(di,
"Ran out of buffer when parsing PDU!\n");
620 smfprintf(di,
"SMS DCS: 0x%02X\n", buffer[pos]);
626 if ((buffer[pos] & 0xD0) == 0x10 || (buffer[pos] & 0xF0) == 0xF0) {
627 SMS->
Class = buffer[pos] & 3;
633 smfprintf(di,
"Ran out of buffer when parsing PDU!\n");
640 if (pos + 7 >= length) {
641 smfprintf(di,
"Ran out of buffer when parsing PDU!\n");
650 if (pos + 7 >= length) {
651 smfprintf(di,
"Ran out of buffer when parsing PDU!\n");
663 if (pos < length && buffer[pos] != 0xff) {
670 smfprintf(di,
"SMS PID: 0x%02X\n", buffer[pos]);
671 if (buffer[pos] > 0x40 && buffer[pos] < 0x48) {
679 smfprintf(di,
"SMS DCS: 0x%02X\n", buffer[pos]);
698 smfprintf(di,
"Relative validity: 0x%02X\n", buffer[pos]);
701 smfprintf(di,
"Ran out of buffer when parsing PDU!\n");
704 }
else if (vpf == 3) {
706 smfprintf(di,
"Absolute validity not handled!\n");
709 smfprintf(di,
"Ran out of buffer when parsing PDU!\n");
717 datalength = buffer[pos];
719 datalength = (datalength * 7) / 8;
720 if ((buffer[pos] * 7) % 8 != 0) {
724 smfprintf(di,
"Compressed unicode messages not yet supported!\n");
727 smfprintf(di,
"Compressed 7-bit messages not yet supported!\n");
731 if (pos + datalength >= length) {
732 smfprintf(di,
"Ran out of buffer when parsing PDU!\n");
735 if (final_pos != NULL) {
736 *final_pos = pos + datalength + 1;
746 for (i = 0; i < SMS->
UDH.
Length; i++) SMS->
UDH.
Text[i] = buffer[pos + 1 + i];
772 smfprintf(di,
"Invalid message length!\n");
784 smfprintf(di,
"Invalid message length!\n");
799 if (final_pos != NULL) {
815 smfprintf(di,
"ERROR: firstbyte in SMS layout not set\n");
823 if (Layout.
Text != 255 && Layout.
TPUDL != 255 && buffer[Layout.
TPUDL] > 0) {
850 if (Layout.
TPDCS != 255) {
854 if (Layout.
Text != 255 && Layout.
TPDCS!=255 && Layout.
TPUDL!=255 && buffer[Layout.
TPUDL] > 0) {
871 if (Layout.
TPDCS != 255) {
873 if ((buffer[Layout.
TPDCS] & 0xD0) == 0x10) {
875 if ((buffer[Layout.
TPDCS] & 0xC) == 0xC) {
876 smfprintf(di,
"WARNING: reserved alphabet value in TPDCS\n");
880 }
else if ((buffer[Layout.
TPDCS] & 0xF0) == 0xF0) {
882 if ((buffer[Layout.
TPDCS] & 8) == 8) {
883 smfprintf(di,
"WARNING: set reserved bit 3 in TPDCS\n");
895 if (Layout.
TPPID != 255) {
896 if (buffer[Layout.
TPPID] > 0x40 && buffer[Layout.
TPPID] < 0x48) {
917 if (DT->
Year<2000) Year = DT->
Year-1900;
918 else Year = DT->
Year-2000;
919 }
else Year = DT->
Year;
937 int size = 0, size2 = 0, w;
946 smfprintf(di,
"UDL passed from API is 0, using UDHL+1 (%i)\n", off);
960 buffer[Layout.
TPDCS] |= (1 << 2);
962 size2 = size = SMS->
Length+off;
976 size2 = (off*8 + w) / 7 + p;
977 smfprintf(di,
"7 bit SMS, length %i, %i\n",size,size2);
986 buffer[Layout.
TPDCS] |= (1 << 3);
989 smfprintf(di,
"Unicode SMS, length %i\n",(size2-off)/2);
1004 buffer[Layout.
TPUDL] = size2;
1014 for (i=0;i<Layout.
Text;i++) buffer[i] = 0;
1037 if (Layout.
Number!=255) {
1048 if (Layout.
TPDCS != 255) {
1053 if (Layout.
TPVP != 255) {
1065 if (Layout.
TPMR != 255) {
1075 if (Layout.
TPPID != 255) {
1076 buffer[Layout.
TPPID] = 0;
1085 *length += Layout.
Text;
1165 smfprintf(di,
"Not supported UDH type\n");
1168 if (UDHHeaders[i].Type!=UDH->
Type) {
1177 if (UDHHeaders[i].ID8bit != -1) {
1182 if (UDHHeaders[i].ID16bit != -1) {
1188 if (UDHHeaders[i].PartNumber != -1) {
1193 if (UDHHeaders[i].AllParts != -1) {
1213 if (SMS->
Class != 1) {
1223 if (strncmp(SMS->
Text,
"//SEO",5) != 0) {
1226 if (SMS->
Text[5] != 1) {
1231 SMS->
Text[10]*256*256 + SMS->
Text[11]*256*256*256;
1236 SMS->
Text[18]*256*256 + SMS->
Text[19]*256*256*256;
1239 if (SMS->
Text[20] > 9) {
1246 current = 21+SMS->
Text[20];
1247 if (SMS->
Text[current] > 39) {
1254 current += SMS->
Text[current]+1;
1265 }
else if (strcmp(
"Unicode", s) == 0) {
1267 }
else if (strcmp(
"Unicode_No_Compression", s) == 0) {
1269 }
else if (strcmp(
"Unicode_Compression", s) == 0) {
1271 }
else if (strcmp(
"Default", s) == 0) {
1273 }
else if (strcmp(
"Default_No_Compression", s) == 0) {
1275 }
else if (strcmp(
"Default_Compression", s) == 0) {
1277 }
else if (strcmp(
"8bit", s) == 0) {
1288 return "Unicode_No_Compression";
1290 return "Unicode_Compression";
1292 return "Default_No_Compression";
1294 return "Default_Compression";
void GSM_SetDefaultReceivedSMSData(GSM_SMSMessage *SMS)
GSM_Error GSM_DecodeSMSStatusReportData(GSM_Debug_Info *di, GSM_SMSMessage *SMS, int TP_ST)
unsigned char Text[(GSM_MAX_SMS_LENGTH+1) *2]
char * DecodeUnicodeString(const unsigned char *src)
unsigned char Number[(GSM_MAX_NUMBER_LENGTH+1) *2]
static GSM_Error GSM_DecodeSMSDateTime(GSM_Debug_Info *di, GSM_DateTime *DT, const unsigned char *req)
void DecodeDefault(unsigned char *dest, const unsigned char *src, size_t len, gboolean UseExtensions, unsigned char *ExtraAlphabet)
char * OSDate(GSM_DateTime dt)
unsigned char ReplaceMessage
const char * GSM_SMSCodingToString(GSM_Coding_Type type)
int GSM_PackSemiOctetNumber(const unsigned char *Number, unsigned char *Output, gboolean semioctet)
void DumpMessageText(GSM_Debug_Info *d, const unsigned char *message, const size_t messagesize)
GSM_Error GSM_DecodeSMSFrame(GSM_Debug_Info *di, GSM_SMSMessage *SMS, unsigned char *buffer, GSM_SMSMessageLayout Layout)
int GSM_PackSevenBitsToEight(size_t offset, const unsigned char *input, unsigned char *output, size_t length)
gboolean RejectDuplicates
GSM_Error GSM_DecodePDUFrame(GSM_Debug_Info *di, GSM_SMSMessage *SMS, const unsigned char *buffer, size_t length, size_t *final_pos, gboolean SMSC)
static GSM_UDHHeader UDHHeaders[]
void GSM_SetDefaultSMSData(GSM_SMSMessage *SMS)
size_t UnicodeLength(const unsigned char *str)
static GSM_Error GSM_EncodeSMSDateTime(GSM_Debug_Info *di, GSM_DateTime *DT, unsigned char *req)
unsigned char DataName[40]
unsigned char DeliveryStatus
#define GSM_MAX_8BIT_SMS_LENGTH
unsigned char EncodeWithBCDAlphabet(int value)
gboolean GSM_DecodeSiemensOTASMS(GSM_Debug_Info *di, GSM_SiemensOTASMSInfo *Info, GSM_SMSMessage *SMS)
unsigned char DefaultNumber[(GSM_MAX_NUMBER_LENGTH+1) *2]
GSM_ValidityPeriodFormat Format
void EncodeUnicode(unsigned char *dest, const char *src, size_t len)
unsigned char Name[(GSM_MAX_SMS_NAME_LENGTH+1) *2]
GSM_Error GSM_DecodeSMSFrameText(GSM_Debug_Info *di, GSM_SMSMessage *SMS, unsigned char *buffer, GSM_SMSMessageLayout Layout)
GSM_Coding_Type GSM_StringToSMSCoding(const char *s)
GSM_Coding_Type GSM_GetMessageCoding(GSM_Debug_Info *di, const char TPDCS)
gboolean CheckTime(GSM_DateTime *date)
int DecodeWithBCDAlphabet(unsigned char value)
char * OSDateTime(GSM_DateTime dt, gboolean TimeZone)
unsigned char Number[(GSM_MAX_NUMBER_LENGTH+1) *2]
static int GSM_EncodeSMSFrameText(GSM_Debug_Info *di, GSM_SMSMessage *SMS, unsigned char *buffer, GSM_SMSMessageLayout Layout)
void DecodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, size_t len)
GSM_Error GSM_UnpackSemiOctetNumber(GSM_Debug_Info *di, unsigned char *retval, const unsigned char *Number, size_t *pos, size_t bufferlength, gboolean semioctet)
int GSM_UnpackEightBitsToSeven(size_t offset, size_t in_length, size_t out_length, const unsigned char *input, unsigned char *output)
void GSM_GetCurrentDateTime(GSM_DateTime *Date)
void EncodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, size_t len)
GSM_Error GSM_EncodeSMSFrame(GSM_Debug_Info *di, GSM_SMSMessage *SMS, unsigned char *buffer, GSM_SMSMessageLayout Layout, int *length, gboolean clear)
void GSM_DecodeUDHHeader(GSM_Debug_Info *di, GSM_UDHHeader *UDH)
int smfprintf(GSM_Debug_Info *d, const char *format,...)
void GSM_EncodeUDHHeader(GSM_Debug_Info *di, GSM_UDHHeader *UDH)
unsigned char MessageReference
gboolean ReplyViaSameSMSC
void EncodeDefault(unsigned char *dest, const unsigned char *src, size_t *len, gboolean UseExtensions, unsigned char *ExtraAlphabet)
GSM_ValidityPeriod Relative
gboolean CheckDate(GSM_DateTime *date)
GSM_Error GSM_DecodeSMSFrameStatusReportData(GSM_Debug_Info *di, GSM_SMSMessage *SMS, unsigned char *buffer, GSM_SMSMessageLayout Layout)
unsigned char DataType[10]
unsigned char Name[(GSM_MAX_SMSC_NAME_LENGTH+1) *2]