diff options
author | Michal Čihař <michal@cihar.com> | 2010-10-04 17:19:03 +0200 |
---|---|---|
committer | Michal Čihař <michal@cihar.com> | 2010-10-04 17:19:03 +0200 |
commit | d91a0635ba6086e8d6a09ac0290b39e6d62fda37 (patch) | |
tree | c9e6685cbe1b9487e7c4affdcc05ec4b7bed2e22 /libgammu | |
parent | 468ee374ccf16a5e86fae6a911067112999b2a44 (diff) |
Imported Upstream version 1.28.92
Diffstat (limited to 'libgammu')
-rw-r--r-- | libgammu/gsmphones.c | 1 | ||||
-rw-r--r-- | libgammu/gsmstate.c | 36 | ||||
-rw-r--r-- | libgammu/misc/coding/coding.c | 22 | ||||
-rw-r--r-- | libgammu/phone/at/at-sms.c | 4 | ||||
-rw-r--r-- | libgammu/phone/at/atgen.c | 4 | ||||
-rw-r--r-- | libgammu/phone/nokia/dct4s40/6510/n6510.c | 108 | ||||
-rw-r--r-- | libgammu/phone/nokia/ncommon.h | 3 | ||||
-rw-r--r-- | libgammu/phone/nokia/nfunc.c | 129 | ||||
-rw-r--r-- | libgammu/service/sms/gsmsms.c | 36 |
9 files changed, 184 insertions, 159 deletions
diff --git a/libgammu/gsmphones.c b/libgammu/gsmphones.c index 51fa75c..53e734f 100644 --- a/libgammu/gsmphones.c +++ b/libgammu/gsmphones.c @@ -270,6 +270,7 @@ GSM_PhoneModel allmodels[] = { {"2660", "RM-292","Nokia 2660", {F_SERIES40_30,F_FILES2,F_TODO66,F_RADIO,F_NOTES,F_SMS_FILES,0}},/* guess */ {"2680", "RM-392","Nokia 2680", {F_SERIES40_30,F_FILES2,F_TODO66,F_RADIO,F_NOTES,F_SMS_FILES,0}},/* guess */ {"2700", "RM-561","Nokia 2700",{F_SERIES40_30,F_FILES2,F_TODO66,F_RADIO,F_NOTES,F_SMS_FILES,0}},/* guess */ + {"2730c", "RM-578","Nokia 2730c",{F_SERIES40_30,F_FILES2,F_TODO66,F_RADIO,F_NOTES,F_SMS_FILES,0}},/* guess */ {"2760", "RM-258","Nokia 2760",{F_SERIES40_30,F_FILES2,F_TODO66,F_RADIO,F_NOTES,F_SMS_FILES,0}},/* guess */ {"3109c","RM-274","Nokia 3109c",{F_SERIES40_30,F_FILES2,F_TODO66,F_PBKUSER,F_PBKTONEGAL,F_NOTES,F_SMS_FILES,F_CHAT,F_SYNCML,F_6230iCALLER,0}},/* guess */ {"3110c","RM-237","Nokia 3110c",{F_SERIES40_30,F_PBKTONEGAL,F_TODO66,F_PBKSMSLIST,F_PBKUSER,F_NOTES,F_CHAT,F_SYNCML,F_FILES2,F_SMS_FILES,0}},/* guess */ diff --git a/libgammu/gsmstate.c b/libgammu/gsmstate.c index 5d59e32..8143533 100644 --- a/libgammu/gsmstate.c +++ b/libgammu/gsmstate.c @@ -40,6 +40,7 @@ #define FALLBACK_GAMMURC "/etc/gammurc" #define GAMMURC_NAME "/.gammurc" #endif +#define XDG_GAMMURC_NAME "/gammu/config" /* Win32 compatibility */ #ifndef PATH_MAX @@ -93,13 +94,20 @@ static const GSM_ConnectionInfo GSM_Connections[] = { /* cables */ {"mbus", GCT_MBUS2, FALSE}, + {"fbus", GCT_FBUS2, FALSE}, + {"fbususb", GCT_FBUS2USB, FALSE}, + {"fbuspl2303", GCT_FBUS2PL2303, FALSE}, + {"dlr3", GCT_FBUS2DLR3, FALSE}, {"fbusdlr3", GCT_FBUS2DLR3, FALSE}, + {"dku5", GCT_DKU5FBUS2, FALSE}, + {"fbusdku5", GCT_DKU5FBUS2, FALSE}, {"dku5fbus", GCT_DKU5FBUS2, FALSE}, + {"ark3116fbus", GCT_DKU5FBUS2, TRUE}, #ifdef WIN32 {"dku2", GCT_DKU2PHONET, FALSE}, @@ -1098,13 +1106,30 @@ GSM_Error GSM_FindGammuRC (INI_Section **result, const char *force_config) } #endif - /* Reset as we're using strcat */ - configfile[0] = 0; + /* XDG paths */ + envpath = getenv("XDG_CONFIG_HOME"); + if (envpath) { + strcpy(configfile, envpath); + strcat(configfile, XDG_GAMMURC_NAME); + + error = GSM_TryReadGammuRC(configfile, result); + if (error == ERR_NONE) return ERR_NONE; + } else { + envpath = getenv("HOME"); + if (envpath) { + strcpy(configfile, envpath); + strcat(configfile, "/.config"); + strcat(configfile, XDG_GAMMURC_NAME); + + error = GSM_TryReadGammuRC(configfile, result); + if (error == ERR_NONE) return ERR_NONE; + } + } - /* Try user home */ + /* Try home from environment */ envpath = getenv("HOME"); if (envpath) { - strcat(configfile, envpath); + strcpy(configfile, envpath); strcat(configfile, GAMMURC_NAME); error = GSM_TryReadGammuRC(configfile, result); @@ -1112,9 +1137,10 @@ GSM_Error GSM_FindGammuRC (INI_Section **result, const char *force_config) } #if defined(HAVE_GETPWUID) && defined(HAVE_GETUID) + /* Tru home from passwd */ pwent = getpwuid(getuid()); if (pwent != NULL) { - strcat(configfile, pwent->pw_dir); + strcpy(configfile, pwent->pw_dir); strcat(configfile, GAMMURC_NAME); error = GSM_TryReadGammuRC(configfile, result); diff --git a/libgammu/misc/coding/coding.c b/libgammu/misc/coding/coding.c index d02815b..e7c77f5 100644 --- a/libgammu/misc/coding/coding.c +++ b/libgammu/misc/coding/coding.c @@ -367,7 +367,7 @@ int DecodeWithHexBinAlphabet (unsigned char mychar) return -1; } -unsigned char EncodeWithHexBinAlphabet (int digit) +char EncodeWithHexBinAlphabet (int digit) { if (digit >= 0 && digit <= 9) return '0'+(digit); if (digit >=10 && digit <=15) return 'A'+(digit-10); @@ -392,15 +392,7 @@ void DecodeHexUnicode (unsigned char *dest, const char *src, size_t len) void EncodeHexUnicode (char *dest, const unsigned char *src, size_t len) { - size_t i, current = 0; - - for (i = 0; i < len; i++) { - dest[current++] = EncodeWithHexBinAlphabet(src[2*i] >> 4); - dest[current++] = EncodeWithHexBinAlphabet(src[2*i] & 0x0f); - dest[current++] = EncodeWithHexBinAlphabet(src[2*i+1] >> 4); - dest[current++] = EncodeWithHexBinAlphabet(src[2*i+1] & 0x0f); - } - dest[current++] = 0; + EncodeHexBin(dest, src, len * 2); } gboolean DecodeHexBin (unsigned char *dest, const unsigned char *src, int len) @@ -417,15 +409,15 @@ gboolean DecodeHexBin (unsigned char *dest, const unsigned char *src, int len) return TRUE; } -void EncodeHexBin (unsigned char *dest, const unsigned char *src, int len) +void EncodeHexBin (char *dest, const unsigned char *src, size_t len) { - int i,current=0; + size_t i, outpos = 0; for (i = 0; i < len; i++) { - dest[current++] = EncodeWithHexBinAlphabet(src[i] >> 0x04); - dest[current++] = EncodeWithHexBinAlphabet(src[i] & 0x0f); + dest[outpos++] = EncodeWithHexBinAlphabet(src[i] >> 4); + dest[outpos++] = EncodeWithHexBinAlphabet(src[i] & 0xF); } - dest[current++] = 0; + dest[outpos++] = 0; } /* ETSI GSM 03.38, section 6.2.1: Default alphabet for SMS messages */ diff --git a/libgammu/phone/at/at-sms.c b/libgammu/phone/at/at-sms.c index 4ef6996..5812ff9 100644 --- a/libgammu/phone/at/at-sms.c +++ b/libgammu/phone/at/at-sms.c @@ -1088,10 +1088,10 @@ GSM_Error ATGEN_GetSMSList(GSM_StateMachine *s, gboolean first) if (Priv->SMSMode == SMS_AT_TXT) { ATGEN_WaitForAutoLen(s, "AT+CMGL=\"ALL\"\r", 0x00, 500, ID_GetSMSMessage); } else { - ATGEN_WaitForAutoLen(s, "AT+CMGL=4\r", 0x00, 20, ID_GetSMSMessage); + ATGEN_WaitForAutoLen(s, "AT+CMGL=4\r", 0x00, 500, ID_GetSMSMessage); } if (error == ERR_NOTSUPPORTED) { - ATGEN_WaitForAutoLen(s, "AT+CMGL\r", 0x00, 5, ID_GetSMSMessage); + ATGEN_WaitForAutoLen(s, "AT+CMGL\r", 0x00, 500, ID_GetSMSMessage); } /* * We did not read anything, but it is correct, indicate that diff --git a/libgammu/phone/at/atgen.c b/libgammu/phone/at/atgen.c index 074b362..d51131e 100644 --- a/libgammu/phone/at/atgen.c +++ b/libgammu/phone/at/atgen.c @@ -4095,12 +4095,12 @@ GSM_Error ATGEN_DialVoice(GSM_StateMachine *s, char *number, GSM_CallShowNumber } smprintf(s, "Making voice call\n"); length = sprintf(buffer, "ATDT%s;\r", number); - ATGEN_WaitFor(s, buffer, length, 0x00, 20, ID_DialVoice); + ATGEN_WaitFor(s, buffer, length, 0x00, 100, ID_DialVoice); if (error == ERR_INVALIDLOCATION || error == ERR_UNKNOWN) { smprintf(s, "Making voice call without forcing to tone dial\n"); length = sprintf(buffer, "ATD%s;\r", number); - ATGEN_WaitFor(s, buffer, length, 0x00, 20, ID_DialVoice); + ATGEN_WaitFor(s, buffer, length, 0x00, 100, ID_DialVoice); } return error; } diff --git a/libgammu/phone/nokia/dct4s40/6510/n6510.c b/libgammu/phone/nokia/dct4s40/6510/n6510.c index 1fb3dcd..17128e9 100644 --- a/libgammu/phone/nokia/dct4s40/6510/n6510.c +++ b/libgammu/phone/nokia/dct4s40/6510/n6510.c @@ -324,59 +324,59 @@ static GSM_Error N6510_SetSMSC(GSM_StateMachine *s, GSM_SMSC *smsc) static GSM_Error N6510_ReplyGetNetworkInfo(GSM_Protocol_Message msg, GSM_StateMachine *s) { - int current = msg.Buffer[7]+7, tmp; + int current = msg.Buffer[7]+7, pos; GSM_Phone_Data *Data = &s->Phone.Data; -#ifdef DEBUG - char name[100]; - GSM_NetworkInfo NetInfo; + GSM_NetworkInfo network_info_local, *network_info; - if (msg.Buffer[3] == 0xf0) return ERR_NOTSUPPORTED; + if (msg.Buffer[3] == 0xf0) { + return ERR_NOTSUPPORTED; + } - smprintf(s, "Network status : "); - switch (msg.Buffer[8]) { - case 0x00 : smprintf(s, "home network\n"); break; - case 0x01 : smprintf(s, "roaming network\n"); break; - case 0x04 : smprintf(s, "not logged"); break; - case 0x06 : smprintf(s, "SIM card rejected\n"); break; - case 0x09 : smprintf(s, "not logged"); break; - default : smprintf(s, "unknown %i!\n",msg.Buffer[8]); break; + if (Data->RequestID == ID_GetNetworkInfo) { + network_info = Data->NetworkInfo; + } else { + network_info = &network_info_local; } - if (msg.Buffer[8]==0x00 || msg.Buffer[8] == 0x01) { - NOKIA_DecodeNetworkCode(msg.Buffer + (current + 7),NetInfo.NetworkCode); - smprintf(s, "Network code : %s\n", NetInfo.NetworkCode); - smprintf(s, "Network name for Gammu : %s ", - DecodeUnicodeString(GSM_GetNetworkName(NetInfo.NetworkCode))); - smprintf(s, "(%s)\n",DecodeUnicodeString(GSM_GetCountryName(NetInfo.NetworkCode))); - - sprintf(NetInfo.LAC, "%02X%02X", msg.Buffer[current+1], msg.Buffer[current+2]); - smprintf(s, "LAC : %s\n", NetInfo.LAC); - - sprintf(NetInfo.CID, "%02X%02X", msg.Buffer[current+5], msg.Buffer[current+6]); - smprintf(s, "CID : %s\n", NetInfo.CID); - - tmp = 10; - NOKIA_GetUnicodeString(s, &tmp, msg.Buffer,name,TRUE); - smprintf(s, "Network name for phone : %s\n",DecodeUnicodeString(name)); + + network_info->NetworkName[0] = 0x00; + network_info->NetworkName[1] = 0x00; + + switch (msg.Buffer[8]) { + case 0x00: + smprintf(s, "home network\n"); + network_info->State = GSM_HomeNetwork; + break; + case 0x01: + smprintf(s, "roaming network\n"); + network_info->State = GSM_RoamingNetwork; + break; + case 0x04: + smprintf(s, "not logged"); + network_info->State = GSM_NoNetwork; + break; + case 0x06: + smprintf(s, "SIM card rejected\n"); + network_info->State = GSM_RegistrationDenied; + break; + case 0x09: + smprintf(s, "not logged"); + network_info->State = GSM_NoNetwork; + break; + default: + smprintf(s, "unknown %i!\n",msg.Buffer[8]); + network_info->State = GSM_NetworkStatusUnknown; } -#endif - if (Data->RequestID==ID_GetNetworkInfo) { - Data->NetworkInfo->NetworkName[0] = 0x00; - Data->NetworkInfo->NetworkName[1] = 0x00; - Data->NetworkInfo->State = 0; - switch (msg.Buffer[8]) { - case 0x00: Data->NetworkInfo->State = GSM_HomeNetwork; break; - case 0x01: Data->NetworkInfo->State = GSM_RoamingNetwork; break; - case 0x04: - case 0x06: - case 0x09: Data->NetworkInfo->State = GSM_NoNetwork; break; - } - if (Data->NetworkInfo->State == GSM_HomeNetwork || Data->NetworkInfo->State == GSM_RoamingNetwork) { - tmp = 10; - NOKIA_GetUnicodeString(s, &tmp, msg.Buffer,Data->NetworkInfo->NetworkName,TRUE); - sprintf(Data->NetworkInfo->LAC, "%02X%02X", msg.Buffer[current+1], msg.Buffer[current+2]); - sprintf(Data->NetworkInfo->CID, "%02X%02X", msg.Buffer[current+5], msg.Buffer[current+6]); - NOKIA_DecodeNetworkCode(msg.Buffer + (current+7),Data->NetworkInfo->NetworkCode); - } + if (network_info->State == GSM_HomeNetwork || network_info->State == GSM_RoamingNetwork) { + pos = 10; + NOKIA_GetUnicodeString(s, &pos, msg.Buffer, network_info->NetworkName, TRUE); + smprintf(s, "Network name: %s ", DecodeUnicodeString(network_info->NetworkName)); + NOKIA_DecodeNetworkCode(msg.Buffer + (current + 7), network_info->NetworkCode); + smprintf(s, "Network code: %s\n", network_info->NetworkCode); + smprintf(s, "Network name in libGammu: %s ", DecodeUnicodeString(GSM_GetNetworkName(network_info->NetworkCode))); + sprintf(network_info->LAC, "%02X%02X", msg.Buffer[current+1], msg.Buffer[current+2]); + smprintf(s, "LAC: %s\n", network_info->LAC); + sprintf(network_info->CID, "%02X%02X", msg.Buffer[current+5], msg.Buffer[current+6]); + smprintf(s, "CID: %s\n", network_info->CID); } return ERR_NONE; } @@ -4168,16 +4168,18 @@ static GSM_Reply_Function N6510ReplyFunctions[] = { {N6510_ReplyGetSecurityStatus, "\x08",0x03,0x12,ID_GetSecurityStatus }, {N6510_ReplyGetNetworkInfo, "\x0A",0x03,0x01,ID_GetNetworkInfo }, + {N6510_ReplyGetNetworkInfo, "\x0A",0x03,0xf0,ID_GetNetworkInfo }, + {N6510_ReplyGetSignalQuality, "\x0A",0x03,0x0C,ID_GetSignalQuality }, + {N6510_ReplyGetOperatorLogo, "\x0A",0x03,0x24,ID_GetBitmap }, + {N6510_ReplyGetOperatorLogo, "\x0A",0x03,0xf0,ID_GetBitmap }, + {N6510_ReplySetOperatorLogo, "\x0A",0x03,0x26,ID_SetBitmap }, + /* This needs to be last of type */ {N6510_ReplyGetNetworkInfo, "\x0A",0x03,0x01,ID_IncomingFrame }, - {N6510_ReplyGetNetworkInfo, "\x0A",0x03,0xf0,ID_IncomingFrame }, {N6510_ReplyLogIntoNetwork, "\x0A",0x03,0x02,ID_IncomingFrame }, - {N6510_ReplyGetSignalQuality, "\x0A",0x03,0x0C,ID_GetSignalQuality }, {NoneReply, "\x0A",0x03,0x16,ID_IncomingFrame }, {N6510_ReplyGetIncSignalQuality, "\x0A",0x03,0x1E,ID_IncomingFrame }, {NoneReply, "\x0A",0x03,0x20,ID_IncomingFrame }, - {N6510_ReplyGetOperatorLogo, "\x0A",0x03,0x24,ID_GetBitmap }, - {N6510_ReplyGetOperatorLogo, "\x0A",0x03,0xf0,ID_GetBitmap }, - {N6510_ReplySetOperatorLogo, "\x0A",0x03,0x26,ID_SetBitmap }, + {N6510_ReplyGetNetworkInfo, "\x0A",0x03,0xf0,ID_IncomingFrame }, {NoneReply, "\x0B",0x03,0x01,ID_PlayTone }, {NoneReply, "\x0B",0x03,0x15,ID_PlayTone }, diff --git a/libgammu/phone/nokia/ncommon.h b/libgammu/phone/nokia/ncommon.h index 10fe23f..5f6d185 100644 --- a/libgammu/phone/nokia/ncommon.h +++ b/libgammu/phone/nokia/ncommon.h @@ -59,8 +59,9 @@ typedef enum { S4030_PBK_NICKNAME = 0x56, S4030_PBK_BIRTHDAY = 0x57, - /* Unknown series */ + /* Unknown/Other series */ N2630_PBK_FAVMESSAGING = 0x65, + N6303_PBK_UNKNOWN1 = 0x8b, } GSM_71_65_Phonebook_Entries_Types; typedef enum { diff --git a/libgammu/phone/nokia/nfunc.c b/libgammu/phone/nokia/nfunc.c index 32f88ba..7f6ab41 100644 --- a/libgammu/phone/nokia/nfunc.c +++ b/libgammu/phone/nokia/nfunc.c @@ -329,6 +329,34 @@ size_t N71_65_EncodePhonebookFrame(GSM_StateMachine *s, unsigned char *req, GSM_ } /** + * Copy string to GSM_MemoryEntry + * + * Return false on failure + */ +static gboolean N71_65_PB_CopyString(GSM_StateMachine *s, + GSM_MemoryEntry *entry, + const unsigned char *src, + unsigned char length) +{ + if ((length & 1) != 0) { + smprintf(s, "String length not even\n"); + return FALSE; + } + if (length/2 > GSM_PHONEBOOK_TEXT_LENGTH) { + smprintf(s, "Too long text\n"); + return FALSE; + } + memcpy(entry->Entries[entry->EntriesNum].Text, src, length); + /* Zero terminate the string */ + entry->Entries[entry->EntriesNum].Text[length] = 0; + entry->Entries[entry->EntriesNum].Text[length + 1] = 0; + + smprintf(s, " \"%s\"\n",DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text)); + + return TRUE; +} + +/** * Decodes nokia phonebook. * * \bug Type casting MemoryType to int is ugly. @@ -379,7 +407,8 @@ GSM_Error N71_65_DecodePhonebook(GSM_StateMachine *s, bs = 256*Block[2]+Block[3]; if (bs == 0) break; #ifdef DEBUG - smprintf(s, "Phonebook entry block - length %i\n", bs-6); + smprintf(s, "Phonebook entry block 0x%02x - length %i\n", + Block[0], bs-6); if (GSM_GetDI(s)->dl == DL_TEXTALL || GSM_GetDI(s)->dl == DL_TEXTALLDATE) DumpMessage(&s->di, Block+0, bs-1); #endif @@ -397,19 +426,9 @@ GSM_Error N71_65_DecodePhonebook(GSM_StateMachine *s, } if (Type != 0) { found=TRUE; - if (Block[5]/2>GSM_PHONEBOOK_TEXT_LENGTH) { - smprintf(s, "Too long text\n"); + if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5])) return ERR_UNKNOWNRESPONSE; - } - /* No text? */ - if (Block[5] < 2) { - entry->Entries[entry->EntriesNum].Text[0] = 0; - entry->Entries[entry->EntriesNum].Text[1] = 0; - } else { - memcpy(entry->Entries[entry->EntriesNum].Text,Block+6,Block[5]); - } entry->Entries[entry->EntriesNum].EntryType=Type; - smprintf(s, " \"%s\"\n",DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text)); entry->EntriesNum ++; } } @@ -428,7 +447,8 @@ GSM_Error N71_65_DecodePhonebook(GSM_StateMachine *s, } bs = 256*Block[2]+Block[3]; #ifdef DEBUG - smprintf(s, "Phonebook entry block - length %i\n", bs-6); + smprintf(s, "Phonebook entry block 0x%02x - length %i\n", + Block[0], bs-6); if (s->di.dl == DL_TEXTALL || s->di.dl == DL_TEXTALLDATE) DumpMessage(&s->di, Block+0, bs-1); #endif if (entry->EntriesNum >= GSM_PHONEBOOK_ENTRIES) { @@ -554,12 +574,8 @@ GSM_Error N71_65_DecodePhonebook(GSM_StateMachine *s, return ERR_UNKNOWNRESPONSE; } entry->Entries[entry->EntriesNum].EntryType=Type; - if (Block[9]/2>GSM_PHONEBOOK_TEXT_LENGTH) { - smprintf(s, "Too long text\n"); + if (! N71_65_PB_CopyString(s, entry, Block+10, Block[9])) return ERR_UNKNOWNRESPONSE; - } - memcpy(entry->Entries[entry->EntriesNum].Text,Block+10,Block[9]); - smprintf(s, " \"%s\"\n",DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text)); /* DCT3 phones like 6210 */ entry->Entries[entry->EntriesNum].VoiceTag = Block[7]; #ifdef DEBUG @@ -605,12 +621,8 @@ GSM_Error N71_65_DecodePhonebook(GSM_StateMachine *s, return ERR_UNKNOWNRESPONSE; } entry->Entries[entry->EntriesNum].EntryType=Type; - if (Block[9]/2>GSM_PHONEBOOK_TEXT_LENGTH) { - smprintf(s, "Too long text\n"); + if (! N71_65_PB_CopyString(s, entry, Block+10, Block[9])) return ERR_UNKNOWNRESPONSE; - } - memcpy(entry->Entries[entry->EntriesNum].Text,Block+10,Block[9]); - smprintf(s, " \"%s\"\n",DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text)); entry->EntriesNum ++; continue; } @@ -618,121 +630,81 @@ GSM_Error N71_65_DecodePhonebook(GSM_StateMachine *s, if ((Block[0] == S4030_PBK_POSTAL_EXTADDRESS) && (foundbb5add==TRUE)) { Type = PBK_Text_Custom1; smprintf(s,"Address extension ? "); - if (Block[5]/2>GSM_PHONEBOOK_TEXT_LENGTH) { - smprintf(s, "Too long text\n"); + if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5])) return ERR_UNKNOWNRESPONSE; - } - memcpy(entry->Entries[entry->EntriesNum].Text,Block+6,Block[5]); entry->Entries[entry->EntriesNum].EntryType=Type; - smprintf(s, " \"%s\"\n",DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text)); entry->EntriesNum ++; continue; } if ((Block[0] == S4030_PBK_POSTAL_STREET) && (foundbb5add==TRUE)) { Type = PBK_Text_StreetAddress; smprintf(s,"Street "); - if (Block[5]/2>GSM_PHONEBOOK_TEXT_LENGTH) { - smprintf(s, "Too long text\n"); + if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5])) return ERR_UNKNOWNRESPONSE; - } - memcpy(entry->Entries[entry->EntriesNum].Text,Block+6,Block[5]); entry->Entries[entry->EntriesNum].EntryType=Type; - smprintf(s, " \"%s\"\n",DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text)); entry->EntriesNum ++; continue; } if ((Block[0] == S4030_PBK_POSTAL_CITY) && (foundbb5add==TRUE)) { Type = PBK_Text_City; smprintf(s,"City "); - if (Block[5]/2>GSM_PHONEBOOK_TEXT_LENGTH) { - smprintf(s, "Too long text\n"); + if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5])) return ERR_UNKNOWNRESPONSE; - } - memcpy(entry->Entries[entry->EntriesNum].Text,Block+6,Block[5]); entry->Entries[entry->EntriesNum].EntryType=Type; - smprintf(s, " \"%s\"\n",DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text)); entry->EntriesNum ++; continue; } if ((Block[0] == S4030_PBK_POSTAL_STATE) && (foundbb5add==TRUE)) { Type = PBK_Text_State; smprintf(s,"State "); - if (Block[5]/2>GSM_PHONEBOOK_TEXT_LENGTH) { - smprintf(s, "Too long text\n"); + if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5])) return ERR_UNKNOWNRESPONSE; - } - memcpy(entry->Entries[entry->EntriesNum].Text,Block+6,Block[5]); entry->Entries[entry->EntriesNum].EntryType=Type; - smprintf(s, " \"%s\"\n",DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text)); entry->EntriesNum ++; continue; } if ((Block[0] == S4030_PBK_POSTAL_POSTAL) && (foundbb5add==TRUE)) { Type = PBK_Text_Postal; smprintf(s,"Postal "); - if (Block[5]/2>GSM_PHONEBOOK_TEXT_LENGTH) { - smprintf(s, "Too long text\n"); + if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5])) return ERR_UNKNOWNRESPONSE; - } - memcpy(entry->Entries[entry->EntriesNum].Text,Block+6,Block[5]); entry->Entries[entry->EntriesNum].EntryType=Type; - smprintf(s, " \"%s\"\n",DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text)); entry->EntriesNum ++; continue; } if ((Block[0] == S4030_PBK_POSTAL_COUNTRY) && (foundbb5add==TRUE)) { Type = PBK_Text_Country; smprintf(s,"Country "); - if (Block[5]/2>GSM_PHONEBOOK_TEXT_LENGTH) { - smprintf(s, "Too long text\n"); + if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5])) return ERR_UNKNOWNRESPONSE; - } - memcpy(entry->Entries[entry->EntriesNum].Text,Block+6,Block[5]); entry->Entries[entry->EntriesNum].EntryType=Type; - smprintf(s, " \"%s\"\n",DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text)); entry->EntriesNum ++; continue; } if (Block[0] == S4030_PBK_FORMALNAME) { Type = PBK_Text_FormalName; smprintf(s,"FormalName "); - if (Block[5]/2>GSM_PHONEBOOK_TEXT_LENGTH) { - smprintf(s, "Too long text\n"); + if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5])) return ERR_UNKNOWNRESPONSE; - } - memcpy(entry->Entries[entry->EntriesNum].Text,Block+6,Block[5]); entry->Entries[entry->EntriesNum].EntryType=Type; - smprintf(s, " \"%s\"\n",DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text)); entry->EntriesNum ++; continue; } if (Block[0] == S4030_PBK_JOBTITLE) { Type = PBK_Text_JobTitle; smprintf(s,"JobTitle "); - if (Block[5]/2>GSM_PHONEBOOK_TEXT_LENGTH) { - smprintf(s, "Too long text\n"); + if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5])) return ERR_UNKNOWNRESPONSE; - } - memcpy(entry->Entries[entry->EntriesNum].Text,Block+6,Block[5]); entry->Entries[entry->EntriesNum].EntryType=Type; - smprintf(s, " \"%s\"\n",DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text)); entry->EntriesNum ++; continue; } if (Block[0] == S4030_PBK_COMPANY) { Type = PBK_Text_Company; smprintf(s,"Company "); - if (Block[5]/2>GSM_PHONEBOOK_TEXT_LENGTH) { - smprintf(s, "Too long text\n"); + if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5])) return ERR_UNKNOWNRESPONSE; - } - memcpy(entry->Entries[entry->EntriesNum].Text,Block+6,Block[5]); entry->Entries[entry->EntriesNum].EntryType=Type; - smprintf(s, " \"%s\"\n",DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text)); entry->EntriesNum ++; continue; } if (Block[0] == S4030_PBK_NICKNAME) { Type = PBK_Text_NickName; smprintf(s,"NickName "); - if (Block[5]/2>GSM_PHONEBOOK_TEXT_LENGTH) { - smprintf(s, "Too long text\n"); + if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5])) return ERR_UNKNOWNRESPONSE; - } - memcpy(entry->Entries[entry->EntriesNum].Text,Block+6,Block[5]); entry->Entries[entry->EntriesNum].EntryType=Type; - smprintf(s, " \"%s\"\n",DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text)); entry->EntriesNum ++; continue; } @@ -864,7 +836,10 @@ GSM_Error N71_65_DecodePhonebook(GSM_StateMachine *s, entry->Entries[Block[5]-1].SMSList[i] = Block[9]; continue; } - if (Block[0] == N7110_PBK_UNKNOWN1 || Block[0] == N7110_PBK_UNKNOWN2 || Block[0] == N7110_PBK_UNKNOWN3) { + if (Block[0] == N7110_PBK_UNKNOWN1 + || Block[0] == N7110_PBK_UNKNOWN2 + || Block[0] == N7110_PBK_UNKNOWN3 + || Block[0] == N6303_PBK_UNKNOWN1) { smprintf(s,"Unknown entry type 0x%02x data length %d\n", Block[0], bs-6); continue; } @@ -882,13 +857,9 @@ GSM_Error N71_65_DecodePhonebook(GSM_StateMachine *s, } if (Block[0] == N6510_PBK_PUSHTOTALK_ID) { smprintf(s,"SIP Address (Push to Talk address)\n"); - if (Block[5]/2>GSM_PHONEBOOK_TEXT_LENGTH) { - smprintf(s, "Too long text\n"); + if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5])) return ERR_UNKNOWNRESPONSE; - } - memcpy(entry->Entries[entry->EntriesNum].Text,Block+6,Block[5]); entry->Entries[entry->EntriesNum].EntryType=PBK_PushToTalkID; - smprintf(s, " \"%s\"\n",DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text)); entry->EntriesNum ++; continue; } diff --git a/libgammu/service/sms/gsmsms.c b/libgammu/service/sms/gsmsms.c index 39e2fc9..c78e5e7 100644 --- a/libgammu/service/sms/gsmsms.c +++ b/libgammu/service/sms/gsmsms.c @@ -365,12 +365,13 @@ GSM_Error GSM_DecodeSMSFrameStatusReportData(GSM_Debug_Info *di, GSM_SMSMessage GSM_Error GSM_DecodePDUFrame(GSM_Debug_Info *di, GSM_SMSMessage *SMS, const unsigned char *buffer, size_t length, size_t *final_pos, gboolean SMSC) { size_t pos = 0; - int type; + int type, tp_pi; int vpf = 0; int udh = 0; int i,w; unsigned char output[161]; int datalength; + gboolean have_data = FALSE; /* Set some sane data */ GSM_SetDefaultReceivedSMSData(SMS); @@ -503,6 +504,37 @@ GSM_Error GSM_DecodePDUFrame(GSM_Debug_Info *di, GSM_SMSMessage *SMS, const unsi /* Status */ GSM_DecodeSMSStatusReportData(di, SMS, buffer[pos]); pos++; + + /* Optional part coming from ETSI 123 040, section 9.2.2.3 */ + /* We ignore 0xff, because some buggy phones pad SMS with it */ + if (pos < length && buffer[pos] != 0xff) { + /* TP-Parameter-Indicator */ + tp_pi = buffer[pos]; + pos++; + + /* We have TP-PID */ + if (tp_pi & 1) { + smfprintf(di, "SMS PID: 0x%02X\n", buffer[pos]); + if (buffer[pos] > 0x40 && buffer[pos] < 0x48) { + SMS->ReplaceMessage = buffer[pos] - 0x40; + } + pos++; + } + + /* We have TP-DCS */ + if (tp_pi & 2) { + smfprintf(di, "SMS DCS: 0x%02X\n", buffer[pos]); + SMS->Coding = GSM_GetMessageCoding(di, buffer[pos]); + pos++; + } else { + SMS->Coding = GSM_GetMessageCoding(di, 0); + } + + /* We have TP-UDL */ + if (tp_pi & 4) { + have_data = TRUE; + } + } } /* Validity period */ @@ -528,7 +560,7 @@ GSM_Error GSM_DecodePDUFrame(GSM_Debug_Info *di, GSM_SMSMessage *SMS, const unsi } /* Data */ - if (SMS->PDU == SMS_Submit || SMS->PDU == SMS_Deliver) { + if (SMS->PDU == SMS_Submit || SMS->PDU == SMS_Deliver || have_data) { datalength = buffer[pos]; if (SMS->Coding == SMS_Coding_Default_No_Compression) { datalength = (datalength * 7) / 8; |