Fix CUSD unsoliceted message
Signed-off-by: Michael Trimarchi <mich...@panicking.kicks-ass.org> --- diff --git a/reference-ril/freerunner-ril.c b/reference-ril/freerunner-ril.c index 679e975..f082191 100644 --- a/reference-ril/freerunner-ril.c +++ b/reference-ril/freerunner-ril.c @@ -2823,8 +2823,8 @@ static void onUnsolicited (const char *s, const char *sms_pdu) } else if (strStartsWith(s, "+CUSD:")) { char *response[2] = { NULL, NULL }; - char **cur; char *tmp; + char *buf = NULL; line = strdup(s); tmp = line; @@ -2837,34 +2837,42 @@ static void onUnsolicited (const char *s, const char *sms_pdu) } err = at_tok_nextstr(&tmp, &(response[1])); - - // Convert the response, which is in the GSM 03.38 [25] default alphabet, to UTF-8 - - // Since the GSM alphabet characters contain a character above 2048 (the Euro symbol) - // the string can theoretically expand by 3/2 in length when converted to UTF-8, so we - // allocate a new buffer, twice the size of the one holding the hex string. - int len = strlen(response[1]); - char *buf = malloc(2 * len); - char extension = '\0'; - int i = 0; - while (i < len) { - char c = hex2char(response[1] + i); - buf[i] = '\0'; - if (extension) { - utf8cat(buf, extension_char(c)); - extension = '\0'; - } else if (c == 0x1B) { - extension = c; - } else { - utf8cat(buf, gsm_to_unicode[c]); + if (err == 0) { + // Convert the response, which is in the GSM 03.38 [25] + // default alphabet, to UTF-8 + // Since the GSM alphabet characters contain a character + // above 2048 (the Euro symbol) + // the string can theoretically expand by 3/2 in length + // when converted to UTF-8, so we allocate a new buffer, twice + // the size of the one holding the hex string. + int len = strlen(response[1]); + char extension = '\0'; + buf = malloc(2 * len); + + int i = 0; + while (i < len) { + char c = hex2char(response[1] + i); + buf[i] = '\0'; + if (extension) { + utf8cat(buf, extension_char(c)); + extension = '\0'; + } else if (c == 0x1B) { + extension = c; + } else { + utf8cat(buf, gsm_to_unicode[c]); + } + i += 2; } - i += 2; + response[1] = buf; + RIL_onUnsolicitedResponse( + RIL_UNSOL_ON_USSD, + &response, sizeof(response)); + free(buf); + } else { + RIL_onUnsolicitedResponse( + RIL_UNSOL_ON_USSD, + &response[0], sizeof(response[0])); } - response[1] = buf; - RIL_onUnsolicitedResponse( - RIL_UNSOL_ON_USSD, - &response, sizeof(response)); - free(buf); } #ifdef HAVE_TI_CALYPSO else if (strStartsWith(s, "%CSTAT:") && !isSMSInit()) {
_______________________________________________ android-freerunner mailing list android-freerunner@android.koolu.org http://android.koolu.org/listinfo.cgi/android-freerunner-koolu.org