int stringToBinary(/*in*/ const char *string, /*in*/ size_t len, /*out*/ unsigned char *binary) { int pos; const char *it; const char *end = &string[len]; if (end < string) return -EINVAL; if (len & 1) return -EINVAL; for (pos = 0, it = string; it != end; ++pos, it += 2) { binary[pos] = char2nib(it[0]) << 4 | char2nib(it[1]); } return 0; }
void onNewBroadcastSms(const char *pdu) { char *message = NULL; int i; if (strlen(pdu) != (2 * 88)) { LOGE("Broadcast Message length error! Discarding!"); goto error; } message = alloca(88); memset(message, 0, 88); for (i = 0; i < 88; i++) { message[i] |= (char2nib(pdu[i * 2]) << 4); message[i] |= char2nib(pdu[i * 2 + 1]); } RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS, message, sizeof(char *)); error: return; }