diff options
Diffstat (limited to 'libgammu/phone/at')
-rw-r--r-- | libgammu/phone/at/at-sms.c | 27 | ||||
-rw-r--r-- | libgammu/phone/at/atgen.c | 33 |
2 files changed, 35 insertions, 25 deletions
diff --git a/libgammu/phone/at/at-sms.c b/libgammu/phone/at/at-sms.c index 12d071b..0cd0d65 100644 --- a/libgammu/phone/at/at-sms.c +++ b/libgammu/phone/at/at-sms.c @@ -408,7 +408,7 @@ GSM_Error ATGEN_GetSMSLocation(GSM_StateMachine *s, GSM_SMSMessage *sms, unsigne (*location)--; } smprintf(s, "SMS folder %i & location %i -> ATGEN folder %i & location %i\n", - sms->Folder,sms->Location,*folderid,*location); + sms->Folder, sms->Location, *folderid, *location); /* Set the needed memory type */ if (Priv->SIMSMSMemory == AT_AVAILABLE && @@ -1534,7 +1534,6 @@ GSM_Error ATGEN_ReplyAddSMSMessage(GSM_Protocol_Message *msg, GSM_StateMachine * GSM_Error error; GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; size_t i = 0; - int folder = 0; switch (Priv->ReplyState) { case AT_Reply_SMSEdit: @@ -1564,11 +1563,13 @@ GSM_Error ATGEN_ReplyAddSMSMessage(GSM_Protocol_Message *msg, GSM_StateMachine * smprintf(s, "Saved at AT location %i\n", s->Phone.Data.SaveSMSMessage->Location); /* Adjust location */ - folder = s->Phone.Data.SaveSMSMessage->Folder; - ATGEN_SetSMSLocation(s, s->Phone.Data.SaveSMSMessage, - (folder / 2), /* We care only about SIM/Phone */ - s->Phone.Data.SaveSMSMessage->Location); - s->Phone.Data.SaveSMSMessage->Folder = folder; + ATGEN_SetSMSLocation( + s, + s->Phone.Data.SaveSMSMessage, + /* We care only about SIM/Phone */ + s->Phone.Data.SaveSMSMessage->Folder <= 2 ? 1 : 2, + s->Phone.Data.SaveSMSMessage->Location + ); return ERR_NONE; case AT_Reply_Error: smprintf(s, "Error\n"); @@ -1584,7 +1585,7 @@ GSM_Error ATGEN_ReplyAddSMSMessage(GSM_Protocol_Message *msg, GSM_StateMachine * return ERR_UNKNOWNRESPONSE; } -GSM_Error ATGEN_MakeSMSFrame(GSM_StateMachine *s, GSM_SMSMessage *message, unsigned char *hexreq, int *current, size_t *length2) +GSM_Error ATGEN_MakeSMSFrame(GSM_StateMachine *s, GSM_SMSMessage *message, unsigned char *hexreq, size_t hexlength, int *current, size_t *length2) { GSM_Error error; GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; @@ -1708,7 +1709,7 @@ GSM_Error ATGEN_MakeSMSFrame(GSM_StateMachine *s, GSM_SMSMessage *message, unsig /* If not SMS with UDH, it's as normal text */ if (message->UDH.Type == UDH_NoUDH) { error = ATGEN_EncodeText( - s, message->Text, UnicodeLength(message->Text), hexreq, sizeof(hexreq), length2 + s, message->Text, UnicodeLength(message->Text), hexreq, hexlength, length2 ); if (error != ERR_NONE) { return error; @@ -1783,7 +1784,7 @@ GSM_Error ATGEN_AddSMS(GSM_StateMachine *s, GSM_SMSMessage *sms) } /* Format SMS frame */ - error = ATGEN_MakeSMSFrame(s, sms, hexreq, ¤t, &length); + error = ATGEN_MakeSMSFrame(s, sms, hexreq, sizeof(hexreq), ¤t, &length); if (error != ERR_NONE) { return error; @@ -1803,7 +1804,7 @@ GSM_Error ATGEN_AddSMS(GSM_StateMachine *s, GSM_SMSMessage *sms) /* No (good and 100% working) support for alphanumeric numbers */ if (sms->Number[1]!='+' && (sms->Number[1]<'0' || sms->Number[1]>'9')) { EncodeUnicode(sms->Number,"123",3); - error = ATGEN_MakeSMSFrame(s, sms, hexreq, ¤t, &length); + error = ATGEN_MakeSMSFrame(s, sms, hexreq, sizeof(hexreq), ¤t, &length); if (error != ERR_NONE) return error; } } @@ -1960,7 +1961,7 @@ GSM_Error ATGEN_SendSMS(GSM_StateMachine *s, GSM_SMSMessage *sms) if (sms->PDU == SMS_Deliver) { sms->PDU = SMS_Submit; } - error = ATGEN_MakeSMSFrame(s, sms, hexreq, ¤t, &length); + error = ATGEN_MakeSMSFrame(s, sms, hexreq, sizeof(hexreq), ¤t, &length); if (error != ERR_NONE) { return error; @@ -2422,6 +2423,7 @@ int *GetRange(GSM_StateMachine *s, const char *buffer) /* Did we parse anything? */ if (endptr == chr) { smprintf(s, "Failed to find number in range!\n"); + free(result); return NULL; } /* Allocate more memory if needed */ @@ -2457,6 +2459,7 @@ int *GetRange(GSM_StateMachine *s, const char *buffer) break; } else if (*chr != ',') { smprintf(s, "Bad character in range: %c\n", *chr); + free(result); return NULL; } } diff --git a/libgammu/phone/at/atgen.c b/libgammu/phone/at/atgen.c index c1b65ca..067f5d4 100644 --- a/libgammu/phone/at/atgen.c +++ b/libgammu/phone/at/atgen.c @@ -437,7 +437,7 @@ GSM_Error ATGEN_WaitFor(GSM_StateMachine *s, const char * cmd, size_t len, * * \return True when text does not contain non hex chars. */ -INLINE gboolean ATGEN_HasOnlyHexChars(const char *text, const size_t length) +gboolean ATGEN_HasOnlyHexChars(const char *text, const size_t length) { size_t i = 0; @@ -456,7 +456,7 @@ INLINE gboolean ATGEN_HasOnlyHexChars(const char *text, const size_t length) * * \return True when text does not contain non digits chars. */ -INLINE gboolean ATGEN_HasOnlyDigits(const char *text, const size_t length) +gboolean ATGEN_HasOnlyDigits(const char *text, const size_t length) { size_t i = 0; @@ -476,7 +476,7 @@ INLINE gboolean ATGEN_HasOnlyDigits(const char *text, const size_t length) * \param text Text. * \return True when text can be UCS2. */ -INLINE gboolean ATGEN_IsUCS2(const char *text, const size_t length) +gboolean ATGEN_IsUCS2(const char *text, const size_t length) { return (length > 3) && (length % 4 == 0) && @@ -491,7 +491,7 @@ INLINE gboolean ATGEN_IsUCS2(const char *text, const size_t length) * \param text Text. * \return True when text can be HEX. */ -INLINE gboolean ATGEN_IsHex(const char *text, const size_t length) +gboolean ATGEN_IsHex(const char *text, const size_t length) { return (length > 4) && (length % 2 == 0) && @@ -506,7 +506,7 @@ INLINE gboolean ATGEN_IsHex(const char *text, const size_t length) * \param text Text. * \return True when text can be HEX. */ -INLINE gboolean ATGEN_IsNumber(const char *text, const size_t length) +gboolean ATGEN_IsNumber(const char *text, const size_t length) { return ATGEN_HasOnlyDigits(text, length); } @@ -759,7 +759,10 @@ GSM_Error ATGEN_DecodeText(GSM_StateMachine *s, return ERR_MOREMEMORY; } DecodeHexBin(buffer, input, length); - if (2 * strlen(buffer) >= outlength) return ERR_MOREMEMORY; + if (2 * strlen(buffer) >= outlength) { + free(buffer); + return ERR_MOREMEMORY; + } DecodeDefault(output, buffer, strlen(buffer), TRUE, NULL); free(buffer); buffer = NULL; @@ -1613,6 +1616,7 @@ GSM_Error ATGEN_SQWEReply(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s) GSM_Error ATGEN_ReplyGetUSSD(GSM_Protocol_Message *msg, GSM_StateMachine *s) { + GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; GSM_USSDMessage ussd; GSM_Error error; unsigned char *pos = NULL; @@ -1719,13 +1723,16 @@ GSM_Error ATGEN_ReplyGetUSSD(GSM_Protocol_Message *msg, GSM_StateMachine *s) coding = GSM_GetMessageCoding(&(s->di), dcs); } - smprintf(s, "coding %d -> %d\n", dcs, coding); + smprintf(s, "USSD coding DCS = %d -> Coding = %d\n", dcs, coding); if (coding == SMS_Coding_Default_No_Compression) { - DecodeHexBin(packed, hex_encoded, strlen(hex_encoded)); - GSM_UnpackEightBitsToSeven(0, strlen(hex_encoded), sizeof(decoded), packed, decoded); - DecodeDefault(ussd.Text, decoded, strlen(decoded), TRUE, NULL); - + if (Priv->Charset == AT_CHARSET_HEX || GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_ENCODED_USSD)) { + DecodeHexBin(packed, hex_encoded, strlen(hex_encoded)); + GSM_UnpackEightBitsToSeven(0, strlen(hex_encoded), sizeof(decoded), packed, decoded); + DecodeDefault(ussd.Text, decoded, strlen(decoded), TRUE, NULL); + } else { + DecodeDefault(ussd.Text, hex_encoded, strlen(hex_encoded), TRUE, NULL); + } } else if (coding == SMS_Coding_Unicode_No_Compression) { DecodeHexUnicode(ussd.Text, hex_encoded + offset, strlen(hex_encoded)); } else if (coding == SMS_Coding_8bit) { @@ -4766,7 +4773,7 @@ GSM_Error ATGEN_ReplyGetDivert(GSM_Protocol_Message *msg, GSM_StateMachine *s) if (error != ERR_NONE) { error = ATGEN_ParseReply(s, str, - "+CCFC: @i, @i, @p, @I, @s, @i, @i", + "+CCFC: @i, @i, @p, @I, @s, @I, @I", &status, &class, response->Entries[response->EntriesNum].Number, @@ -6146,7 +6153,6 @@ GSM_Reply_Function ATGENReplyFunctions[] = { {ATGEN_GenericReply, "AT+CLIP" ,0x00,0x00,ID_SetIncomingCall }, {ATGEN_GenericReply, "AT+CCWA" ,0x00,0x00,ID_SetIncomingCall }, {ATGEN_GenericReply, "AT+CUSD" ,0x00,0x00,ID_SetUSSD }, -{ATGEN_ReplyGetUSSD, "AT+CUSD" ,0x00,0x00,ID_GetUSSD }, {ATGEN_ReplyGetUSSD, "+CUSD" ,0x00,0x00,ID_IncomingFrame }, {ATGEN_GenericReply, "AT+CLIP=1" ,0x00,0x00,ID_IncomingFrame }, {ATGEN_ReplyIncomingCallInfo, "+CLIP" ,0x00,0x00,ID_IncomingFrame }, @@ -6205,6 +6211,7 @@ GSM_Reply_Function ATGENReplyFunctions[] = { {ATGEN_GenericReplyIgnore, "^HCSQ:" ,0x00,0x00,ID_IncomingFrame }, {ATGEN_GenericReplyIgnore, "^SRVST:" ,0x00,0x00,ID_IncomingFrame }, {ATGEN_GenericReplyIgnore, "^SIMST:" ,0x00,0x00,ID_IncomingFrame }, +{ATGEN_GenericReplyIgnore, "^STIN:" ,0x00,0x00,ID_IncomingFrame }, {ATGEN_GenericReplyIgnore, "+ZUSIMR:" ,0x00,0x00,ID_IncomingFrame }, {ATGEN_GenericReplyIgnore, "+ZEND" ,0x00,0x00,ID_IncomingFrame }, {ATGEN_GenericReplyIgnore, "+CDSI:" ,0x00,0x00,ID_IncomingFrame }, |