Commit message: None
CVE: CVE-2017-0823
CWE: CWE-200
Vulnerability description: An information disclosure vulnerability in the Android system (rild). Product: Android. Versions: 4.4.4, 5.0.2, 5.1.1, 6.0, 6.0.1, 7.0, 7.1.1, 7.1.2. Android ID: A-37896655.

Project: Android

static char * RIL_getRilSocketName() {
 return rild;
}

Project: Android

RIL_onRequestAck(RIL_Token t) {
 RequestInfo *pRI;
 int ret, fd;

 size_t errorOffset;
    RIL_SOCKET_ID socket_id = RIL_SOCKET_1;

    pRI = (RequestInfo *)t;

 if (!checkAndDequeueRequestInfoIfAck(pRI, true)) {
        RLOGE ("RIL_onRequestAck: invalid RIL_Token");
 return;
 }

    socket_id = pRI->socket_id;
    fd = findFd(socket_id);

#if VDBG
    RLOGD("Request Ack, %s", rilSocketIdToString(socket_id));
#endif

    appendPrintBuf("Ack [%04d]< %s", pRI->token, requestToString(pRI->pCI->requestNumber));

 if (pRI->cancelled == 0) {
 Parcel p;

        p.writeInt32 (RESPONSE_SOLICITED_ACK);
        p.writeInt32 (pRI->token);

 if (fd < 0) {
            RLOGD ("RIL onRequestComplete: Command channel closed");
 }

        sendResponse(p, socket_id);
 }
}

Project: Android

RIL_onRequestComplete(RIL_Token t, RIL_Errno e, void *response, size_t responselen) {
 RequestInfo *pRI;
 int ret;
 int fd;
 size_t errorOffset;
    RIL_SOCKET_ID socket_id = RIL_SOCKET_1;

    pRI = (RequestInfo *)t;

 if (!checkAndDequeueRequestInfoIfAck(pRI, false)) {
        RLOGE ("RIL_onRequestComplete: invalid RIL_Token");
 return;
 }

    socket_id = pRI->socket_id;
    fd = findFd(socket_id);

#if VDBG
    RLOGD("RequestComplete, %s", rilSocketIdToString(socket_id));
#endif

 if (pRI->local > 0) {
        RLOGD("C[locl]< %s", requestToString(pRI->pCI->requestNumber));

 goto done;
 }

    appendPrintBuf("[%04d]< %s",
        pRI->token, requestToString(pRI->pCI->requestNumber));

 if (pRI->cancelled == 0) {
 Parcel p;

 if (s_callbacks.version >= 13 && pRI->wasAckSent == 1) {
            p.writeInt32 (RESPONSE_SOLICITED_ACK_EXP);
            grabPartialWakeLock();
 } else {
            p.writeInt32 (RESPONSE_SOLICITED);
 }
        p.writeInt32 (pRI->token);
        errorOffset = p.dataPosition();

        p.writeInt32 (e);

 if (response != NULL) {
            ret = pRI->pCI->responseFunction(p, response, responselen);

 /* if an error occurred, rewind and mark it */
 if (ret != 0) {
                RLOGE ("responseFunction error, ret %d", ret);
                p.setDataPosition(errorOffset);
                p.writeInt32 (ret);
 }
 }

 if (e != RIL_E_SUCCESS) {
            appendPrintBuf("%s fails by %s", printBuf, failCauseToString(e));
 }

 if (fd < 0) {
            RLOGD ("RIL onRequestComplete: Command channel closed");
 }
        sendResponse(p, socket_id);
 }

done:
    free(pRI);
}

Project: Android

void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
 size_t datalen, RIL_SOCKET_ID socket_id)
#else
extern "C"
void RIL_onUnsolicitedResponse(int unsolResponse, const void *data,
 size_t datalen)
#endif
{
 int unsolResponseIndex;
 int ret;
 int64_t timeReceived = 0;
 bool shouldScheduleTimeout = false;
    RIL_RadioState newState;
    RIL_SOCKET_ID soc_id = RIL_SOCKET_1;

#if defined(ANDROID_MULTI_SIM)
    soc_id = socket_id;
#endif


 if (s_registerCalled == 0) {
        RLOGW("RIL_onUnsolicitedResponse called before RIL_register");
 return;
 }

    unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE;

 if ((unsolResponseIndex < 0)
 || (unsolResponseIndex >= (int32_t)NUM_ELEMS(s_unsolResponses))) {
        RLOGE("unsupported unsolicited response code %d", unsolResponse);
 return;
 }

 switch (s_unsolResponses[unsolResponseIndex].wakeType) {
 case WAKE_PARTIAL:
            grabPartialWakeLock();
            shouldScheduleTimeout = true;
 break;

 case DONT_WAKE:
 default:
            shouldScheduleTimeout = false;
 break;
 }

 if (unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {
        timeReceived = elapsedRealtime();
 }

    appendPrintBuf("[UNSL]< %s", requestToString(unsolResponse));

 Parcel p;
 if (s_callbacks.version >= 13
 && s_unsolResponses[unsolResponseIndex].wakeType == WAKE_PARTIAL) {
        p.writeInt32 (RESPONSE_UNSOLICITED_ACK_EXP);
 } else {
        p.writeInt32 (RESPONSE_UNSOLICITED);
 }
    p.writeInt32 (unsolResponse);

    ret = s_unsolResponses[unsolResponseIndex]
 .responseFunction(p, const_cast<void*>(data), datalen);
 if (ret != 0) {
 goto error_exit;
 }

 switch(unsolResponse) {
 case RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED:
            newState = processRadioState(CALL_ONSTATEREQUEST(soc_id), soc_id);
            p.writeInt32(newState);
            appendPrintBuf("%s {%s}", printBuf,
                radioStateToString(CALL_ONSTATEREQUEST(soc_id)));
 break;


 case RIL_UNSOL_NITZ_TIME_RECEIVED:
            p.writeInt64(timeReceived);
 break;
 }

 if (s_callbacks.version < 13) {
 if (shouldScheduleTimeout) {
 UserCallbackInfo *p_info = internalRequestTimedCallback(wakeTimeoutCallback, NULL,
 &TIMEVAL_WAKE_TIMEOUT);

 if (p_info == NULL) {
 goto error_exit;
 } else {
 if (s_last_wake_timeout_info != NULL) {
                    s_last_wake_timeout_info->userParam = (void *)1;
 }
                s_last_wake_timeout_info = p_info;
 }
 }
 }

#if VDBG
    RLOGI("%s UNSOLICITED: %s length:%d", rilSocketIdToString(soc_id), requestToString(unsolResponse), p.dataSize());
#endif
    ret = sendResponse(p, soc_id);
 if (ret != 0 && unsolResponse == RIL_UNSOL_NITZ_TIME_RECEIVED) {


 if (s_lastNITZTimeData != NULL) {
            free (s_lastNITZTimeData);
            s_lastNITZTimeData = NULL;
 }

        s_lastNITZTimeData = calloc(p.dataSize(), 1);
 if (s_lastNITZTimeData == NULL) {
             RLOGE("Memory allocation failed in RIL_onUnsolicitedResponse");
 goto error_exit;
 }
        s_lastNITZTimeDataSize = p.dataSize();
        memcpy(s_lastNITZTimeData, p.data(), p.dataSize());
 }

 return;

error_exit:
 if (shouldScheduleTimeout) {
        releaseWakeLock();
 }
}

Project: Android

RIL_register (const RIL_RadioFunctions *callbacks) {
 int ret;
 int flags;

    RLOGI("SIM_COUNT: %d", SIM_COUNT);

 if (callbacks == NULL) {
        RLOGE("RIL_register: RIL_RadioFunctions * null");
 return;
 }
 if (callbacks->version < RIL_VERSION_MIN) {
        RLOGE("RIL_register: version %d is to old, min version is %d",
             callbacks->version, RIL_VERSION_MIN);
 return;
 }

    RLOGE("RIL_register: RIL version %d", callbacks->version);

 if (s_registerCalled > 0) {
        RLOGE("RIL_register has been called more than once. "
 "Subsequent call ignored");
 return;
 }

    memcpy(&s_callbacks, callbacks, sizeof (RIL_RadioFunctions));

 /* Initialize socket1 parameters */
    s_ril_param_socket = {
                        RIL_SOCKET_1, /* socket_id */
 -1, /* fdListen */
 -1, /* fdCommand */
                        PHONE_PROCESS, /* processName */
 &s_commands_event, /* commands_event */
 &s_listen_event, /* listen_event */
                        processCommandsCallback, /* processCommandsCallback */
                        NULL, /* p_rs */
                        RIL_TELEPHONY_SOCKET      /* type */
 };

#if (SIM_COUNT >= 2)
    s_ril_param_socket2 = {
                        RIL_SOCKET_2, /* socket_id */
 -1, /* fdListen */
 -1, /* fdCommand */
                        PHONE_PROCESS, /* processName */
 &s_commands_event_socket2, /* commands_event */
 &s_listen_event_socket2, /* listen_event */
                        processCommandsCallback, /* processCommandsCallback */
                        NULL, /* p_rs */
                        RIL_TELEPHONY_SOCKET        /* type */
 };
#endif

#if (SIM_COUNT >= 3)
    s_ril_param_socket3 = {
                        RIL_SOCKET_3, /* socket_id */
 -1, /* fdListen */
 -1, /* fdCommand */
                        PHONE_PROCESS, /* processName */
 &s_commands_event_socket3, /* commands_event */
 &s_listen_event_socket3, /* listen_event */
                        processCommandsCallback, /* processCommandsCallback */
                        NULL, /* p_rs */
                        RIL_TELEPHONY_SOCKET        /* type */
 };
#endif

#if (SIM_COUNT >= 4)
    s_ril_param_socket4 = {
                        RIL_SOCKET_4, /* socket_id */
 -1, /* fdListen */
 -1, /* fdCommand */
                        PHONE_PROCESS, /* processName */
 &s_commands_event_socket4, /* commands_event */
 &s_listen_event_socket4, /* listen_event */
                        processCommandsCallback, /* processCommandsCallback */
                        NULL, /* p_rs */
                        RIL_TELEPHONY_SOCKET        /* type */
 };
#endif


    s_registerCalled = 1;

    RLOGI("s_registerCalled flag set, %d", s_started);

 for (int i = 0; i < (int)NUM_ELEMS(s_commands); i++) {
        assert(i == s_commands[i].requestNumber);
 }

 for (int i = 0; i < (int)NUM_ELEMS(s_unsolResponses); i++) {
        assert(i + RIL_UNSOL_RESPONSE_BASE
 == s_unsolResponses[i].requestNumber);
 }


 if (s_started == 0) {
        RIL_startEventLoop();
 }

    startListen(RIL_SOCKET_1, &s_ril_param_socket);

#if (SIM_COUNT >= 2)
    startListen(RIL_SOCKET_2, &s_ril_param_socket2);
#endif /* (SIM_COUNT == 2) */

#if (SIM_COUNT >= 3)
    startListen(RIL_SOCKET_3, &s_ril_param_socket3);
#endif /* (SIM_COUNT == 3) */

#if (SIM_COUNT >= 4)
    startListen(RIL_SOCKET_4, &s_ril_param_socket4);
#endif /* (SIM_COUNT == 4) */


#if 1

 char *inst = NULL;
 if (strlen(RIL_getRilSocketName()) >= strlen(SOCKET_NAME_RIL)) {
        inst = RIL_getRilSocketName() + strlen(SOCKET_NAME_RIL);
 }

 char rildebug[MAX_DEBUG_SOCKET_NAME_LENGTH] = SOCKET_NAME_RIL_DEBUG;
 if (inst != NULL) {
        strlcat(rildebug, inst, MAX_DEBUG_SOCKET_NAME_LENGTH);
 }

    s_fdDebug = android_get_control_socket(rildebug);
 if (s_fdDebug < 0) {
        RLOGE("Failed to get socket : %s errno:%d", rildebug, errno);
        exit(-1);
 }

    ret = listen(s_fdDebug, 4);

 if (ret < 0) {
        RLOGE("Failed to listen on ril debug socket '%d': %s",
             s_fdDebug, strerror(errno));
        exit(-1);
 }

    ril_event_set (&s_debug_event, s_fdDebug, true,
                debugCallback, NULL);

    rilEventAddWakeup (&s_debug_event);
#endif

}

Project: Android

RIL_requestTimedCallback (RIL_TimedCallback callback, void *param,
 const struct timeval *relativeTime) {
    internalRequestTimedCallback (callback, param, relativeTime);
}

Project: Android

void RIL_setRilSocketName(const char * s) {
    strncpy(rild, s, MAX_SOCKET_NAME_LENGTH);
}

Project: Android

blockingWrite(int fd, const void *buffer, size_t len) {
 size_t writeOffset = 0;
 const uint8_t *toWrite;

    toWrite = (const uint8_t *)buffer;

 while (writeOffset < len) {
 ssize_t written;
 do {
            written = write (fd, toWrite + writeOffset,
                                len - writeOffset);
 } while (written < 0 && ((errno == EINTR) || (errno == EAGAIN)));

 if (written >= 0) {
            writeOffset += written;
 } else { // written < 0
            RLOGE ("RIL Response: unexpected error on write errno:%d", errno);
            close(fd);
 return -1;
 }
 }
#if VDBG
    RLOGE("RIL Response bytes written:%d", writeOffset);
#endif
 return 0;
}

Project: Android

int blockingWrite_helper(int fd, void *buffer, size_t len) {
 return android::blockingWrite(fd, buffer, len);
}

Project: Android

callStateToString(RIL_CallState s) {
 switch(s) {
 case RIL_CALL_ACTIVE : return "ACTIVE";
 case RIL_CALL_HOLDING: return "HOLDING";
 case RIL_CALL_DIALING: return "DIALING";
 case RIL_CALL_ALERTING: return "ALERTING";
 case RIL_CALL_INCOMING: return "INCOMING";
 case RIL_CALL_WAITING: return "WAITING";
 default: return "<unknown state>";
 }
}

Project: Android

checkAndDequeueRequestInfoIfAck(struct RequestInfo *pRI, bool isAck) {
 int ret = 0;
 /* Hook for current context
       pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
 /* pendingRequestsHook refer to &s_pendingRequests */
 RequestInfo ** pendingRequestsHook = &s_pendingRequests;

 if (pRI == NULL) {
 return 0;
 }

#if (SIM_COUNT >= 2)
 if (pRI->socket_id == RIL_SOCKET_2) {
        pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
        pendingRequestsHook = &s_pendingRequests_socket2;
 }
#if (SIM_COUNT >= 3)
 if (pRI->socket_id == RIL_SOCKET_3) {
            pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
            pendingRequestsHook = &s_pendingRequests_socket3;
 }
#endif
#if (SIM_COUNT >= 4)
 if (pRI->socket_id == RIL_SOCKET_4) {
        pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
        pendingRequestsHook = &s_pendingRequests_socket4;
 }
#endif
#endif
    pthread_mutex_lock(pendingRequestsMutexHook);

 for(RequestInfo **ppCur = pendingRequestsHook
 ; *ppCur != NULL
 ; ppCur = &((*ppCur)->p_next)
 ) {
 if (pRI == *ppCur) {
            ret = 1;
 if (isAck) { // Async ack
 if (pRI->wasAckSent == 1) {
                    RLOGD("Ack was already sent for %s", requestToString(pRI->pCI->requestNumber));
 } else {
                    pRI->wasAckSent = 1;
 }
 } else {
 *ppCur = (*ppCur)->p_next;
 }
 break;
 }
 }

    pthread_mutex_unlock(pendingRequestsMutexHook);

 return ret;
}

Project: Android

constructCdmaSms(Parcel &p, RequestInfo *pRI, RIL_CDMA_SMS_Message& rcsm) {
 int32_t  t;
 uint8_t ut;
 status_t status;
 int32_t digitCount;
 int digitLimit;

    memset(&rcsm, 0, sizeof(rcsm));

    status = p.readInt32(&t);
    rcsm.uTeleserviceID = (int) t;

    status = p.read(&ut,sizeof(ut));
    rcsm.bIsServicePresent = (uint8_t) ut;

    status = p.readInt32(&t);
    rcsm.uServicecategory = (int) t;

    status = p.readInt32(&t);
    rcsm.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;

    status = p.readInt32(&t);
    rcsm.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;

    status = p.readInt32(&t);
    rcsm.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;

    status = p.readInt32(&t);
    rcsm.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;

    status = p.read(&ut,sizeof(ut));
    rcsm.sAddress.number_of_digits= (uint8_t) ut;

    digitLimit= MIN((rcsm.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);
 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
        status = p.read(&ut,sizeof(ut));
        rcsm.sAddress.digits[digitCount] = (uint8_t) ut;
 }

    status = p.readInt32(&t);
    rcsm.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;

    status = p.read(&ut,sizeof(ut));
    rcsm.sSubAddress.odd = (uint8_t) ut;

    status = p.read(&ut,sizeof(ut));
    rcsm.sSubAddress.number_of_digits = (uint8_t) ut;

    digitLimit= MIN((rcsm.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);
 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
        status = p.read(&ut,sizeof(ut));
        rcsm.sSubAddress.digits[digitCount] = (uint8_t) ut;
 }

    status = p.readInt32(&t);
    rcsm.uBearerDataLen = (int) t;

    digitLimit= MIN((rcsm.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);
 for(digitCount =0 ; digitCount < digitLimit; digitCount ++) {
        status = p.read(&ut, sizeof(ut));
        rcsm.aBearerData[digitCount] = (uint8_t) ut;
 }

 if (status != NO_ERROR) {
 return status;
 }

    startRequest;
    appendPrintBuf("%suTeleserviceID=%d, bIsServicePresent=%d, uServicecategory=%d, \
            sAddress.digit_mode=%d, sAddress.Number_mode=%d, sAddress.number_type=%d, ",
            printBuf, rcsm.uTeleserviceID,rcsm.bIsServicePresent,rcsm.uServicecategory,
            rcsm.sAddress.digit_mode, rcsm.sAddress.number_mode,rcsm.sAddress.number_type);
    closeRequest;

    printRequest(pRI->token, pRI->pCI->requestNumber);

 return status;
}

Project: Android

decodeCdmaSubscriptionSource (RIL_RadioState radioState) {
 switch (radioState) {
 case RADIO_STATE_SIM_NOT_READY:
 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
 case RADIO_STATE_SIM_READY:
 case RADIO_STATE_RUIM_NOT_READY:
 case RADIO_STATE_RUIM_READY:
 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
 return CDMA_SUBSCRIPTION_SOURCE_RUIM_SIM;

 case RADIO_STATE_NV_NOT_READY:
 case RADIO_STATE_NV_READY:
 return CDMA_SUBSCRIPTION_SOURCE_NV;

 default:
            RLOGD("decodeCdmaSubscriptionSource: Invoked with incorrect RadioState");
 return -1;
 }
}

Project: Android

decodeSimStatus (RIL_RadioState radioState) {
 switch (radioState) {
 case RADIO_STATE_SIM_NOT_READY:
 case RADIO_STATE_RUIM_NOT_READY:
 case RADIO_STATE_NV_NOT_READY:
 case RADIO_STATE_NV_READY:
 return -1;
 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
 case RADIO_STATE_SIM_READY:
 case RADIO_STATE_RUIM_READY:
 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
 return radioState;
 default:
           RLOGD("decodeSimStatus: Invoked with incorrect RadioState");
 return -1;
 }
}

Project: Android

decodeVoiceRadioTechnology (RIL_RadioState radioState) {
 switch (radioState) {
 case RADIO_STATE_SIM_NOT_READY:
 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
 case RADIO_STATE_SIM_READY:
 return RADIO_TECH_UMTS;

 case RADIO_STATE_RUIM_NOT_READY:
 case RADIO_STATE_RUIM_READY:
 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
 case RADIO_STATE_NV_NOT_READY:
 case RADIO_STATE_NV_READY:
 return RADIO_TECH_1xRTT;

 default:
            RLOGD("decodeVoiceRadioTechnology: Invoked with incorrect RadioState");
 return -1;
 }
}

Project: Android

dispatchCallForward(Parcel &p, RequestInfo *pRI) {
    RIL_CallForwardInfo cff;
 int32_t t;
 status_t status;

    RLOGD("dispatchCallForward");
    memset (&cff, 0, sizeof(cff));


    status = p.readInt32(&t);
    cff.status = (int)t;

    status = p.readInt32(&t);
    cff.reason = (int)t;

    status = p.readInt32(&t);
    cff.serviceClass = (int)t;

    status = p.readInt32(&t);
    cff.toa = (int)t;

    cff.number = strdupReadString(p);

    status = p.readInt32(&t);
    cff.timeSeconds = (int)t;

 if (status != NO_ERROR) {
 goto invalid;
 }


 if (cff.number != NULL && strlen (cff.number) == 0) {
        cff.number = NULL;
 }

    startRequest;
    appendPrintBuf("%sstat=%d,reason=%d,serv=%d,toa=%d,%s,tout=%d", printBuf,
        cff.status, cff.reason, cff.serviceClass, cff.toa,
 (char*)cff.number, cff.timeSeconds);
    closeRequest;
    printRequest(pRI->token, pRI->pCI->requestNumber);

    CALL_ONREQUEST(pRI->pCI->requestNumber, &cff, sizeof(cff), pRI, pRI->socket_id);

#ifdef MEMSET_FREED
    memsetString(cff.number);
#endif

    free (cff.number);

#ifdef MEMSET_FREED
    memset(&cff, 0, sizeof(cff));
#endif

 return;
invalid:
    invalidCommandBlock(pRI);
 return;
}

Project: Android

static void dispatchCarrierRestrictions(Parcel &p, RequestInfo *pRI) {
    RIL_CarrierRestrictions cr;
    RIL_Carrier * allowed_carriers = NULL;
    RIL_Carrier * excluded_carriers = NULL;
 int32_t t;
 status_t status;

    memset(&cr, 0, sizeof(RIL_CarrierRestrictions));

 if (s_callbacks.version < 14) {
        RLOGE("Unsuppoted RIL version %d, min version expected %d",
              s_callbacks.version, 14);
        RIL_onRequestComplete(pRI, RIL_E_REQUEST_NOT_SUPPORTED, NULL, 0);
 return;
 }

    status = p.readInt32(&t);
 if (status != NO_ERROR) {
 goto invalid;
 }
    allowed_carriers = (RIL_Carrier *)calloc(t, sizeof(RIL_Carrier));
 if (allowed_carriers == NULL) {
        RLOGE("Memory allocation failed for request %s", requestToString(pRI->pCI->requestNumber));
 goto exit;
 }
    cr.len_allowed_carriers = t;
    cr.allowed_carriers = allowed_carriers;

    status = p.readInt32(&t);
 if (status != NO_ERROR) {
 goto invalid;
 }
    excluded_carriers = (RIL_Carrier *)calloc(t, sizeof(RIL_Carrier));
 if (excluded_carriers == NULL) {
        RLOGE("Memory allocation failed for request %s", requestToString(pRI->pCI->requestNumber));
 goto exit;
 }
    cr.len_excluded_carriers = t;
    cr.excluded_carriers = excluded_carriers;

    startRequest;
    appendPrintBuf("%s len_allowed_carriers:%d, len_excluded_carriers:%d,",
                   printBuf, cr.len_allowed_carriers, cr.len_excluded_carriers);

    appendPrintBuf("%s allowed_carriers:", printBuf);
 for (int32_t i = 0; i < cr.len_allowed_carriers; i++) {
        RIL_Carrier *p_cr = allowed_carriers + i;
        p_cr->mcc = strdupReadString(p);
        p_cr->mnc = strdupReadString(p);
        status = p.readInt32(&t);
        p_cr->match_type = static_cast<RIL_CarrierMatchType>(t);
 if (status != NO_ERROR) {
 goto invalid;
 }
        p_cr->match_data = strdupReadString(p);
        appendPrintBuf("%s [%d mcc:%s, mnc:%s, match_type:%d, match_data:%s],",
                       printBuf, i, p_cr->mcc, p_cr->mnc, p_cr->match_type, p_cr->match_data);
 }

 for (int32_t i = 0; i < cr.len_excluded_carriers; i++) {
        RIL_Carrier *p_cr = excluded_carriers + i;
        p_cr->mcc = strdupReadString(p);
        p_cr->mnc = strdupReadString(p);
        status = p.readInt32(&t);
        p_cr->match_type = static_cast<RIL_CarrierMatchType>(t);
 if (status != NO_ERROR) {
 goto invalid;
 }
        p_cr->match_data = strdupReadString(p);
        appendPrintBuf("%s [%d mcc:%s, mnc:%s, match_type:%d, match_data:%s],",
                       printBuf, i, p_cr->mcc, p_cr->mnc, p_cr->match_type, p_cr->match_data);
 }

    closeRequest;
    printRequest(pRI->token, pRI->pCI->requestNumber);

    CALL_ONREQUEST(pRI->pCI->requestNumber,
 &cr,
 sizeof(RIL_CarrierRestrictions),
                pRI, pRI->socket_id);

 goto exit;

invalid:
    invalidCommandBlock(pRI);
    RIL_onRequestComplete(pRI, RIL_E_INVALID_ARGUMENTS, NULL, 0);
exit:
 if (allowed_carriers != NULL) {
        free(allowed_carriers);
 }
 if (excluded_carriers != NULL) {
        free(excluded_carriers);
 }
 return;
}

Project: Android

dispatchCdmaBrSmsCnf(Parcel &p, RequestInfo *pRI) {
 int32_t t;
 status_t status;
 int32_t num;

    status = p.readInt32(&num);
 if (status != NO_ERROR) {
 goto invalid;
 }

 {
        RIL_CDMA_BroadcastSmsConfigInfo cdmaBci[num];
        RIL_CDMA_BroadcastSmsConfigInfo *cdmaBciPtrs[num];

        startRequest;
 for (int i = 0 ; i < num ; i++ ) {
            cdmaBciPtrs[i] = &cdmaBci[i];

            status = p.readInt32(&t);
            cdmaBci[i].service_category = (int) t;

            status = p.readInt32(&t);
            cdmaBci[i].language = (int) t;

            status = p.readInt32(&t);
            cdmaBci[i].selected = (uint8_t) t;

            appendPrintBuf("%s [%d: service_category=%d, language =%d, \
                  entries.bSelected =%d]", printBuf, i, cdmaBci[i].service_category,
                  cdmaBci[i].language, cdmaBci[i].selected);
 }
        closeRequest;

 if (status != NO_ERROR) {
 goto invalid;
 }

        CALL_ONREQUEST(pRI->pCI->requestNumber,
                              cdmaBciPtrs,
                              num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *),
                              pRI, pRI->socket_id);

#ifdef MEMSET_FREED
        memset(cdmaBci, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo));
        memset(cdmaBciPtrs, 0, num * sizeof(RIL_CDMA_BroadcastSmsConfigInfo *));
#endif
 }

 return;

invalid:
    invalidCommandBlock(pRI);
 return;
}

Project: Android

dispatchCdmaSms(Parcel &p, RequestInfo *pRI) {
    RIL_CDMA_SMS_Message rcsm;

    RLOGD("dispatchCdmaSms");
 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
 goto invalid;
 }

    CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsm, sizeof(rcsm),pRI, pRI->socket_id);

#ifdef MEMSET_FREED
    memset(&rcsm, 0, sizeof(rcsm));
#endif

 return;

invalid:
    invalidCommandBlock(pRI);
 return;
}

Project: Android

dispatchCdmaSmsAck(Parcel &p, RequestInfo *pRI) {
    RIL_CDMA_SMS_Ack rcsa;
 int32_t  t;
 status_t status;
 int32_t digitCount;

    RLOGD("dispatchCdmaSmsAck");
    memset(&rcsa, 0, sizeof(rcsa));

    status = p.readInt32(&t);
    rcsa.uErrorClass = (RIL_CDMA_SMS_ErrorClass) t;

    status = p.readInt32(&t);
    rcsa.uSMSCauseCode = (int) t;

 if (status != NO_ERROR) {
 goto invalid;
 }

    startRequest;
    appendPrintBuf("%suErrorClass=%d, uTLStatus=%d, ",
            printBuf, rcsa.uErrorClass, rcsa.uSMSCauseCode);
    closeRequest;

    printRequest(pRI->token, pRI->pCI->requestNumber);

    CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsa, sizeof(rcsa),pRI, pRI->socket_id);

#ifdef MEMSET_FREED
    memset(&rcsa, 0, sizeof(rcsa));
#endif

 return;

invalid:
    invalidCommandBlock(pRI);
 return;
}

Project: Android

static void dispatchDataCall(Parcel& p, RequestInfo *pRI) {
 const int numParamsRilV3 = 6;

 int pos = p.dataPosition();

 int numParams = p.readInt32();
 if (s_callbacks.version < 4 && numParams > numParamsRilV3) {
 Parcel p2;
      p2.appendFrom(&p, 0, pos);
      p2.writeInt32(numParamsRilV3);
 for(int i = 0; i < numParamsRilV3; i++) {
        p2.writeString16(p.readString16());
 }
      p2.setDataPosition(pos);
      dispatchStrings(p2, pRI);
 } else {
      p.setDataPosition(pos);
      dispatchStrings(p, pRI);
 }
}

Project: Android

dispatchDial (Parcel &p, RequestInfo *pRI) {
    RIL_Dial dial;
    RIL_UUS_Info uusInfo;
 int32_t sizeOfDial;
 int32_t t;
 int32_t uusPresent;
 status_t status;

    RLOGD("dispatchDial");
    memset (&dial, 0, sizeof(dial));

    dial.address = strdupReadString(p);

    status = p.readInt32(&t);
    dial.clir = (int)t;

 if (status != NO_ERROR || dial.address == NULL) {
 goto invalid;
 }

 if (s_callbacks.version < 3) { // Remove when partners upgrade to version 3
        uusPresent = 0;
        sizeOfDial = sizeof(dial) - sizeof(RIL_UUS_Info *);
 } else {
        status = p.readInt32(&uusPresent);

 if (status != NO_ERROR) {
 goto invalid;
 }

 if (uusPresent == 0) {
            dial.uusInfo = NULL;
 } else {
 int32_t len;

            memset(&uusInfo, 0, sizeof(RIL_UUS_Info));

            status = p.readInt32(&t);
            uusInfo.uusType = (RIL_UUS_Type) t;

            status = p.readInt32(&t);
            uusInfo.uusDcs = (RIL_UUS_DCS) t;

            status = p.readInt32(&len);
 if (status != NO_ERROR) {
 goto invalid;
 }

 if (((int) len) == -1) {
                uusInfo.uusData = NULL;
                len = 0;
 } else {
                uusInfo.uusData = (char*) p.readInplace(len);
 }

            uusInfo.uusLength = len;
            dial.uusInfo = &uusInfo;
 }
        sizeOfDial = sizeof(dial);
 }

    startRequest;
    appendPrintBuf("%snum=%s,clir=%d", printBuf, dial.address, dial.clir);
 if (uusPresent) {
        appendPrintBuf("%s,uusType=%d,uusDcs=%d,uusLen=%d", printBuf,
                dial.uusInfo->uusType, dial.uusInfo->uusDcs,
                dial.uusInfo->uusLength);
 }
    closeRequest;
    printRequest(pRI->token, pRI->pCI->requestNumber);

    CALL_ONREQUEST(pRI->pCI->requestNumber, &dial, sizeOfDial, pRI, pRI->socket_id);

#ifdef MEMSET_FREED
    memsetString (dial.address);
#endif

    free (dial.address);

#ifdef MEMSET_FREED
    memset(&uusInfo, 0, sizeof(RIL_UUS_Info));
    memset(&dial, 0, sizeof(dial));
#endif

 return;
invalid:
    invalidCommandBlock(pRI);
 return;
}

Project: Android

dispatchGsmBrSmsCnf(Parcel &p, RequestInfo *pRI) {
 int32_t t;
 status_t status;
 int32_t num;

    status = p.readInt32(&num);
 if (status != NO_ERROR) {
 goto invalid;
 }

 {
        RIL_GSM_BroadcastSmsConfigInfo gsmBci[num];
        RIL_GSM_BroadcastSmsConfigInfo *gsmBciPtrs[num];

        startRequest;
 for (int i = 0 ; i < num ; i++ ) {
            gsmBciPtrs[i] = &gsmBci[i];

            status = p.readInt32(&t);
            gsmBci[i].fromServiceId = (int) t;

            status = p.readInt32(&t);
            gsmBci[i].toServiceId = (int) t;

            status = p.readInt32(&t);
            gsmBci[i].fromCodeScheme = (int) t;

            status = p.readInt32(&t);
            gsmBci[i].toCodeScheme = (int) t;

            status = p.readInt32(&t);
            gsmBci[i].selected = (uint8_t) t;

            appendPrintBuf("%s [%d: fromServiceId=%d, toServiceId =%d, \
                  fromCodeScheme=%d, toCodeScheme=%d, selected =%d]", printBuf, i,
                  gsmBci[i].fromServiceId, gsmBci[i].toServiceId,
                  gsmBci[i].fromCodeScheme, gsmBci[i].toCodeScheme,
                  gsmBci[i].selected);
 }
        closeRequest;

 if (status != NO_ERROR) {
 goto invalid;
 }

        CALL_ONREQUEST(pRI->pCI->requestNumber,
                              gsmBciPtrs,
                              num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *),
                              pRI, pRI->socket_id);

#ifdef MEMSET_FREED
        memset(gsmBci, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo));
        memset(gsmBciPtrs, 0, num * sizeof(RIL_GSM_BroadcastSmsConfigInfo *));
#endif
 }

 return;

invalid:
    invalidCommandBlock(pRI);
 return;
}

Project: Android

dispatchImsCdmaSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
    RIL_IMS_SMS_Message rism;
    RIL_CDMA_SMS_Message rcsm;

    RLOGD("dispatchImsCdmaSms: retry=%d, messageRef=%d", retry, messageRef);

 if (NO_ERROR != constructCdmaSms(p, pRI, rcsm)) {
 goto invalid;
 }
    memset(&rism, 0, sizeof(rism));
    rism.tech = RADIO_TECH_3GPP2;
    rism.retry = retry;
    rism.messageRef = messageRef;
    rism.message.cdmaMessage = &rcsm;

    CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
 +sizeof(rcsm),pRI, pRI->socket_id);

#ifdef MEMSET_FREED
    memset(&rcsm, 0, sizeof(rcsm));
    memset(&rism, 0, sizeof(rism));
#endif

 return;

invalid:
    invalidCommandBlock(pRI);
 return;
}

Project: Android

dispatchImsGsmSms(Parcel &p, RequestInfo *pRI, uint8_t retry, int32_t messageRef) {
    RIL_IMS_SMS_Message rism;
 int32_t countStrings;
 status_t status;
 size_t datalen;
 char **pStrings;
    RLOGD("dispatchImsGsmSms: retry=%d, messageRef=%d", retry, messageRef);

    status = p.readInt32 (&countStrings);

 if (status != NO_ERROR) {
 goto invalid;
 }

    memset(&rism, 0, sizeof(rism));
    rism.tech = RADIO_TECH_3GPP;
    rism.retry = retry;
    rism.messageRef = messageRef;

    startRequest;
    appendPrintBuf("%stech=%d, retry=%d, messageRef=%d, ", printBuf,
 (int)rism.tech, (int)rism.retry, rism.messageRef);
 if (countStrings == 0) {
        pStrings = (char **)calloc(1, sizeof(char *));
 if (pStrings == NULL) {
            RLOGE("Memory allocation failed for request %s",
                    requestToString(pRI->pCI->requestNumber));
            closeRequest;
 return;
 }

        datalen = 0;
 } else if (countStrings < 0) {
        pStrings = NULL;
        datalen = 0;
 } else {
 if ((size_t)countStrings > (INT_MAX/sizeof(char *))) {
            RLOGE("Invalid value of countStrings: \n");
            closeRequest;
 return;
 }
        datalen = sizeof(char *) * countStrings;

        pStrings = (char **)calloc(countStrings, sizeof(char *));
 if (pStrings == NULL) {
            RLOGE("Memory allocation failed for request %s",
                    requestToString(pRI->pCI->requestNumber));
            closeRequest;
 return;
 }

 for (int i = 0 ; i < countStrings ; i++) {
            pStrings[i] = strdupReadString(p);
            appendPrintBuf("%s%s,", printBuf, pStrings[i]);
 }
 }
    removeLastChar;
    closeRequest;
    printRequest(pRI->token, pRI->pCI->requestNumber);

    rism.message.gsmMessage = pStrings;
    CALL_ONREQUEST(pRI->pCI->requestNumber, &rism,
 sizeof(RIL_RadioTechnologyFamily)+sizeof(uint8_t)+sizeof(int32_t)
 +datalen, pRI, pRI->socket_id);

 if (pStrings != NULL) {
 for (int i = 0 ; i < countStrings ; i++) {
#ifdef MEMSET_FREED
            memsetString (pStrings[i]);
#endif
            free(pStrings[i]);
 }

#ifdef MEMSET_FREED
        memset(pStrings, 0, datalen);
#endif
        free(pStrings);
 }

#ifdef MEMSET_FREED
    memset(&rism, 0, sizeof(rism));
#endif
 return;
invalid:
    ALOGE("dispatchImsGsmSms invalid block");
    invalidCommandBlock(pRI);
 return;
}

Project: Android

dispatchImsSms(Parcel &p, RequestInfo *pRI) {
 int32_t  t;
 status_t status = p.readInt32(&t);
    RIL_RadioTechnologyFamily format;
 uint8_t retry;
 int32_t messageRef;

    RLOGD("dispatchImsSms");
 if (status != NO_ERROR) {
 goto invalid;
 }
    format = (RIL_RadioTechnologyFamily) t;

    status = p.read(&retry,sizeof(retry));
 if (status != NO_ERROR) {
 goto invalid;
 }
    status = p.read(&messageRef,sizeof(messageRef));
 if (status != NO_ERROR) {
 goto invalid;
 }

 if (RADIO_TECH_3GPP == format) {
        dispatchImsGsmSms(p, pRI, retry, messageRef);
 } else if (RADIO_TECH_3GPP2 == format) {
        dispatchImsCdmaSms(p, pRI, retry, messageRef);
 } else {
        ALOGE("requestImsSendSMS invalid format value =%d", format);
 }

 return;

invalid:
    invalidCommandBlock(pRI);
 return;
}

Project: Android

dispatchInts (Parcel &p, RequestInfo *pRI) {
 int32_t count;
 status_t status;
 size_t datalen;
 int *pInts;

    status = p.readInt32 (&count);

 if (status != NO_ERROR || count <= 0) {
 goto invalid;
 }

    datalen = sizeof(int) * count;
    pInts = (int *)calloc(count, sizeof(int));
 if (pInts == NULL) {
        RLOGE("Memory allocation failed for request %s", requestToString(pRI->pCI->requestNumber));
 return;
 }

    startRequest;
 for (int i = 0 ; i < count ; i++) {
 int32_t t;

        status = p.readInt32(&t);
        pInts[i] = (int)t;
        appendPrintBuf("%s%d,", printBuf, t);

 if (status != NO_ERROR) {
            free(pInts);
 goto invalid;
 }
 }
   removeLastChar;
   closeRequest;
   printRequest(pRI->token, pRI->pCI->requestNumber);

   CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<int *>(pInts),
                       datalen, pRI, pRI->socket_id);

#ifdef MEMSET_FREED
    memset(pInts, 0, datalen);
#endif
    free(pInts);
 return;
invalid:
    invalidCommandBlock(pRI);
 return;
}

Project: Android

static void dispatchNVWriteItem(Parcel &p, RequestInfo *pRI) {
    RIL_NV_WriteItem nvwi;
 int32_t  t;
 status_t status;

    memset(&nvwi, 0, sizeof(nvwi));

    status = p.readInt32(&t);
    nvwi.itemID = (RIL_NV_Item) t;

    nvwi.value = strdupReadString(p);

 if (status != NO_ERROR || nvwi.value == NULL) {
 goto invalid;
 }

    startRequest;
    appendPrintBuf("%snvwi.itemID=%d, value=%s, ", printBuf, nvwi.itemID,
            nvwi.value);
    closeRequest;

    printRequest(pRI->token, pRI->pCI->requestNumber);

    CALL_ONREQUEST(pRI->pCI->requestNumber, &nvwi, sizeof(nvwi), pRI, pRI->socket_id);

#ifdef MEMSET_FREED
    memsetString(nvwi.value);
#endif

    free(nvwi.value);

#ifdef MEMSET_FREED
    memset(&nvwi, 0, sizeof(nvwi));
#endif

 return;

invalid:
    invalidCommandBlock(pRI);
 return;
}

Project: Android

static void dispatchRadioCapability(Parcel &p, RequestInfo *pRI){
    RIL_RadioCapability rc;
 int32_t t;
 status_t status;

    memset (&rc, 0, sizeof(RIL_RadioCapability));

    status = p.readInt32(&t);
    rc.version = (int)t;
 if (status != NO_ERROR) {
 goto invalid;
 }

    status = p.readInt32(&t);
    rc.session= (int)t;
 if (status != NO_ERROR) {
 goto invalid;
 }

    status = p.readInt32(&t);
    rc.phase= (int)t;
 if (status != NO_ERROR) {
 goto invalid;
 }

    status = p.readInt32(&t);
    rc.rat = (int)t;
 if (status != NO_ERROR) {
 goto invalid;
 }

    status = readStringFromParcelInplace(p, rc.logicalModemUuid, sizeof(rc.logicalModemUuid));
 if (status != NO_ERROR) {
 goto invalid;
 }

    status = p.readInt32(&t);
    rc.status = (int)t;

 if (status != NO_ERROR) {
 goto invalid;
 }

    startRequest;
    appendPrintBuf("%s [version:%d, session:%d, phase:%d, rat:%d, \
            logicalModemUuid:%s, status:%d", printBuf, rc.version, rc.session,
            rc.phase, rc.rat, rc.logicalModemUuid, rc.session);

    closeRequest;
    printRequest(pRI->token, pRI->pCI->requestNumber);

    CALL_ONREQUEST(pRI->pCI->requestNumber,
 &rc,
 sizeof(RIL_RadioCapability),
                pRI, pRI->socket_id);
 return;
invalid:
    invalidCommandBlock(pRI);
 return;
}

Project: Android

dispatchRaw(Parcel &p, RequestInfo *pRI) {
 int32_t len;
 status_t status;
 const void *data;

    status = p.readInt32(&len);

 if (status != NO_ERROR) {
 goto invalid;
 }

 if (((int)len) == -1) {
        data = NULL;
        len = 0;
 }

    data = p.readInplace(len);

    startRequest;
    appendPrintBuf("%sraw_size=%d", printBuf, len);
    closeRequest;
    printRequest(pRI->token, pRI->pCI->requestNumber);

    CALL_ONREQUEST(pRI->pCI->requestNumber, const_cast<void *>(data), len, pRI, pRI->socket_id);

 return;
invalid:
    invalidCommandBlock(pRI);
 return;
}

Project: Android

static void dispatchRilCdmaSmsWriteArgs(Parcel &p, RequestInfo *pRI) {
    RIL_CDMA_SMS_WriteArgs rcsw;
 int32_t  t;
 uint32_t ut;
 uint8_t  uct;
 status_t status;
 int32_t  digitCount;
 int32_t  digitLimit;

    memset(&rcsw, 0, sizeof(rcsw));

    status = p.readInt32(&t);
    rcsw.status = t;

    status = p.readInt32(&t);
    rcsw.message.uTeleserviceID = (int) t;

    status = p.read(&uct,sizeof(uct));
    rcsw.message.bIsServicePresent = (uint8_t) uct;

    status = p.readInt32(&t);
    rcsw.message.uServicecategory = (int) t;

    status = p.readInt32(&t);
    rcsw.message.sAddress.digit_mode = (RIL_CDMA_SMS_DigitMode) t;

    status = p.readInt32(&t);
    rcsw.message.sAddress.number_mode = (RIL_CDMA_SMS_NumberMode) t;

    status = p.readInt32(&t);
    rcsw.message.sAddress.number_type = (RIL_CDMA_SMS_NumberType) t;

    status = p.readInt32(&t);
    rcsw.message.sAddress.number_plan = (RIL_CDMA_SMS_NumberPlan) t;

    status = p.read(&uct,sizeof(uct));
    rcsw.message.sAddress.number_of_digits = (uint8_t) uct;

    digitLimit = MIN((rcsw.message.sAddress.number_of_digits), RIL_CDMA_SMS_ADDRESS_MAX);

 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
        status = p.read(&uct,sizeof(uct));
        rcsw.message.sAddress.digits[digitCount] = (uint8_t) uct;
 }

    status = p.readInt32(&t);
    rcsw.message.sSubAddress.subaddressType = (RIL_CDMA_SMS_SubaddressType) t;

    status = p.read(&uct,sizeof(uct));
    rcsw.message.sSubAddress.odd = (uint8_t) uct;

    status = p.read(&uct,sizeof(uct));
    rcsw.message.sSubAddress.number_of_digits = (uint8_t) uct;

    digitLimit = MIN((rcsw.message.sSubAddress.number_of_digits), RIL_CDMA_SMS_SUBADDRESS_MAX);

 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
        status = p.read(&uct,sizeof(uct));
        rcsw.message.sSubAddress.digits[digitCount] = (uint8_t) uct;
 }

    status = p.readInt32(&t);
    rcsw.message.uBearerDataLen = (int) t;

    digitLimit = MIN((rcsw.message.uBearerDataLen), RIL_CDMA_SMS_BEARER_DATA_MAX);

 for(digitCount = 0 ; digitCount < digitLimit; digitCount ++) {
        status = p.read(&uct, sizeof(uct));
        rcsw.message.aBearerData[digitCount] = (uint8_t) uct;
 }

 if (status != NO_ERROR) {
 goto invalid;
 }

    startRequest;
    appendPrintBuf("%sstatus=%d, message.uTeleserviceID=%d, message.bIsServicePresent=%d, \
            message.uServicecategory=%d, message.sAddress.digit_mode=%d, \
            message.sAddress.number_mode=%d, \
            message.sAddress.number_type=%d, ",
            printBuf, rcsw.status, rcsw.message.uTeleserviceID, rcsw.message.bIsServicePresent,
            rcsw.message.uServicecategory, rcsw.message.sAddress.digit_mode,
            rcsw.message.sAddress.number_mode,
            rcsw.message.sAddress.number_type);
    closeRequest;

    printRequest(pRI->token, pRI->pCI->requestNumber);

    CALL_ONREQUEST(pRI->pCI->requestNumber, &rcsw, sizeof(rcsw),pRI, pRI->socket_id);

#ifdef MEMSET_FREED
    memset(&rcsw, 0, sizeof(rcsw));
#endif

 return;

invalid:
    invalidCommandBlock(pRI);
 return;

}

Project: Android

dispatchSIM_APDU (Parcel &p, RequestInfo *pRI) {
 int32_t t;
 status_t status;
    RIL_SIM_APDU apdu;

#if VDBG
    RLOGD("dispatchSIM_APDU");
#endif
    memset (&apdu, 0, sizeof(RIL_SIM_APDU));

    status = p.readInt32(&t);
    apdu.sessionid = (int)t;

    status = p.readInt32(&t);
    apdu.cla = (int)t;

    status = p.readInt32(&t);
    apdu.instruction = (int)t;

    status = p.readInt32(&t);
    apdu.p1 = (int)t;

    status = p.readInt32(&t);
    apdu.p2 = (int)t;

    status = p.readInt32(&t);
    apdu.p3 = (int)t;

    apdu.data = strdupReadString(p);

    startRequest;
    appendPrintBuf("%ssessionid=%d,cla=%d,ins=%d,p1=%d,p2=%d,p3=%d,data=%s",
        printBuf, apdu.sessionid, apdu.cla, apdu.instruction, apdu.p1, apdu.p2,
        apdu.p3, (char*)apdu.data);
    closeRequest;
    printRequest(pRI->token, pRI->pCI->requestNumber);

 if (status != NO_ERROR) {
 goto invalid;
 }

    CALL_ONREQUEST(pRI->pCI->requestNumber, &apdu, sizeof(RIL_SIM_APDU), pRI, pRI->socket_id);

#ifdef MEMSET_FREED
    memsetString(apdu.data);
#endif
    free(apdu.data);

#ifdef MEMSET_FREED
    memset(&apdu, 0, sizeof(RIL_SIM_APDU));
#endif

 return;
invalid:
    invalidCommandBlock(pRI);
 return;
}

Project: Android

dispatchSIM_IO (Parcel &p, RequestInfo *pRI) {
 union RIL_SIM_IO {
        RIL_SIM_IO_v6 v6;
        RIL_SIM_IO_v5 v5;
 } simIO;

 int32_t t;
 int size;
 status_t status;

#if VDBG
    RLOGD("dispatchSIM_IO");
#endif
    memset (&simIO, 0, sizeof(simIO));


    status = p.readInt32(&t);
    simIO.v6.command = (int)t;

    status = p.readInt32(&t);
    simIO.v6.fileid = (int)t;

    simIO.v6.path = strdupReadString(p);

    status = p.readInt32(&t);
    simIO.v6.p1 = (int)t;

    status = p.readInt32(&t);
    simIO.v6.p2 = (int)t;

    status = p.readInt32(&t);
    simIO.v6.p3 = (int)t;

    simIO.v6.data = strdupReadString(p);
    simIO.v6.pin2 = strdupReadString(p);
    simIO.v6.aidPtr = strdupReadString(p);

    startRequest;
    appendPrintBuf("%scmd=0x%X,efid=0x%X,path=%s,%d,%d,%d,%s,pin2=%s,aid=%s", printBuf,
        simIO.v6.command, simIO.v6.fileid, (char*)simIO.v6.path,
        simIO.v6.p1, simIO.v6.p2, simIO.v6.p3,
 (char*)simIO.v6.data, (char*)simIO.v6.pin2, simIO.v6.aidPtr);
    closeRequest;
    printRequest(pRI->token, pRI->pCI->requestNumber);

 if (status != NO_ERROR) {
 goto invalid;
 }

    size = (s_callbacks.version < 6) ? sizeof(simIO.v5) : sizeof(simIO.v6);
    CALL_ONREQUEST(pRI->pCI->requestNumber, &simIO, size, pRI, pRI->socket_id);

#ifdef MEMSET_FREED
    memsetString (simIO.v6.path);
    memsetString (simIO.v6.data);
    memsetString (simIO.v6.pin2);
    memsetString (simIO.v6.aidPtr);
#endif

    free (simIO.v6.path);
    free (simIO.v6.data);
    free (simIO.v6.pin2);
    free (simIO.v6.aidPtr);

#ifdef MEMSET_FREED
    memset(&simIO, 0, sizeof(simIO));
#endif

 return;
invalid:
    invalidCommandBlock(pRI);
 return;
}

Project: Android

static void dispatchSetInitialAttachApn(Parcel &p, RequestInfo *pRI)
{
    RIL_InitialAttachApn pf;
 int32_t  t;
 status_t status;

    memset(&pf, 0, sizeof(pf));

    pf.apn = strdupReadString(p);
    pf.protocol = strdupReadString(p);

    status = p.readInt32(&t);
    pf.authtype = (int) t;

    pf.username = strdupReadString(p);
    pf.password = strdupReadString(p);

    startRequest;
    appendPrintBuf("%sapn=%s, protocol=%s, authtype=%d, username=%s, password=%s",
            printBuf, pf.apn, pf.protocol, pf.authtype, pf.username, pf.password);
    closeRequest;
    printRequest(pRI->token, pRI->pCI->requestNumber);

 if (status != NO_ERROR) {
 goto invalid;
 }
    CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);

#ifdef MEMSET_FREED
    memsetString(pf.apn);
    memsetString(pf.protocol);
    memsetString(pf.username);
    memsetString(pf.password);
#endif

    free(pf.apn);
    free(pf.protocol);
    free(pf.username);
    free(pf.password);

#ifdef MEMSET_FREED
    memset(&pf, 0, sizeof(pf));
#endif

 return;
invalid:
    invalidCommandBlock(pRI);
 return;
}

Project: Android

static void dispatchSimAuthentication(Parcel &p, RequestInfo *pRI)
{
    RIL_SimAuthentication pf;
 int32_t  t;
 status_t status;

    memset(&pf, 0, sizeof(pf));

    status = p.readInt32(&t);
    pf.authContext = (int) t;
    pf.authData = strdupReadString(p);
    pf.aid = strdupReadString(p);

    startRequest;
    appendPrintBuf("authContext=%s, authData=%s, aid=%s", pf.authContext, pf.authData, pf.aid);
    closeRequest;
    printRequest(pRI->token, pRI->pCI->requestNumber);

 if (status != NO_ERROR) {
 goto invalid;
 }
    CALL_ONREQUEST(pRI->pCI->requestNumber, &pf, sizeof(pf), pRI, pRI->socket_id);

#ifdef MEMSET_FREED
    memsetString(pf.authData);
    memsetString(pf.aid);
#endif

    free(pf.authData);
    free(pf.aid);

#ifdef MEMSET_FREED
    memset(&pf, 0, sizeof(pf));
#endif

 return;
invalid:
    invalidCommandBlock(pRI);
 return;
}

Project: Android

dispatchSmsWrite (Parcel &p, RequestInfo *pRI) {
    RIL_SMS_WriteArgs args;
 int32_t t;
 status_t status;

    RLOGD("dispatchSmsWrite");
    memset (&args, 0, sizeof(args));

    status = p.readInt32(&t);
    args.status = (int)t;

    args.pdu = strdupReadString(p);

 if (status != NO_ERROR || args.pdu == NULL) {
 goto invalid;
 }

    args.smsc = strdupReadString(p);

    startRequest;
    appendPrintBuf("%s%d,%s,smsc=%s", printBuf, args.status,
 (char*)args.pdu, (char*)args.smsc);
    closeRequest;
    printRequest(pRI->token, pRI->pCI->requestNumber);

    CALL_ONREQUEST(pRI->pCI->requestNumber, &args, sizeof(args), pRI, pRI->socket_id);

#ifdef MEMSET_FREED
    memsetString (args.pdu);
#endif

    free (args.pdu);

#ifdef MEMSET_FREED
    memset(&args, 0, sizeof(args));
#endif

 return;
invalid:
    invalidCommandBlock(pRI);
 return;
}

Project: Android

dispatchString (Parcel& p, RequestInfo *pRI) {
 status_t status;
 size_t datalen;
 size_t stringlen;
 char *string8 = NULL;

    string8 = strdupReadString(p);

    startRequest;
    appendPrintBuf("%s%s", printBuf, string8);
    closeRequest;
    printRequest(pRI->token, pRI->pCI->requestNumber);

    CALL_ONREQUEST(pRI->pCI->requestNumber, string8,
 sizeof(char *), pRI, pRI->socket_id);

#ifdef MEMSET_FREED
    memsetString(string8);
#endif

    free(string8);
 return;
invalid:
    invalidCommandBlock(pRI);
 return;
}

Project: Android

dispatchStrings (Parcel &p, RequestInfo *pRI) {
 int32_t countStrings;
 status_t status;
 size_t datalen;
 char **pStrings;

    status = p.readInt32 (&countStrings);

 if (status != NO_ERROR) {
 goto invalid;
 }

    startRequest;
 if (countStrings == 0) {
        pStrings = (char **)calloc(1, sizeof(char *));
 if (pStrings == NULL) {
            RLOGE("Memory allocation failed for request %s",
                    requestToString(pRI->pCI->requestNumber));
            closeRequest;
 return;
 }

        datalen = 0;
 } else if (countStrings < 0) {
        pStrings = NULL;
        datalen = 0;
 } else {
        datalen = sizeof(char *) * countStrings;

        pStrings = (char **)calloc(countStrings, sizeof(char *));
 if (pStrings == NULL) {
            RLOGE("Memory allocation failed for request %s",
                    requestToString(pRI->pCI->requestNumber));
            closeRequest;
 return;
 }

 for (int i = 0 ; i < countStrings ; i++) {
            pStrings[i] = strdupReadString(p);
            appendPrintBuf("%s%s,", printBuf, pStrings[i]);
 }
 }
    removeLastChar;
    closeRequest;
    printRequest(pRI->token, pRI->pCI->requestNumber);

    CALL_ONREQUEST(pRI->pCI->requestNumber, pStrings, datalen, pRI, pRI->socket_id);

 if (pStrings != NULL) {
 for (int i = 0 ; i < countStrings ; i++) {
#ifdef MEMSET_FREED
            memsetString (pStrings[i]);
#endif
            free(pStrings[i]);
 }

#ifdef MEMSET_FREED
        memset(pStrings, 0, datalen);
#endif
        free(pStrings);
 }

 return;
invalid:
    invalidCommandBlock(pRI);
 return;
}

Project: Android

static void dispatchUiccSubscripton(Parcel &p, RequestInfo *pRI) {
    RIL_SelectUiccSub uicc_sub;
 status_t status;
 int32_t  t;
    memset(&uicc_sub, 0, sizeof(uicc_sub));

    status = p.readInt32(&t);
 if (status != NO_ERROR) {
 goto invalid;
 }
    uicc_sub.slot = (int) t;

    status = p.readInt32(&t);
 if (status != NO_ERROR) {
 goto invalid;
 }
    uicc_sub.app_index = (int) t;

    status = p.readInt32(&t);
 if (status != NO_ERROR) {
 goto invalid;
 }
    uicc_sub.sub_type = (RIL_SubscriptionType) t;

    status = p.readInt32(&t);
 if (status != NO_ERROR) {
 goto invalid;
 }
    uicc_sub.act_status = (RIL_UiccSubActStatus) t;

    startRequest;
    appendPrintBuf("slot=%d, app_index=%d, act_status = %d", uicc_sub.slot, uicc_sub.app_index,
            uicc_sub.act_status);
    RLOGD("dispatchUiccSubscription, slot=%d, app_index=%d, act_status = %d", uicc_sub.slot,
            uicc_sub.app_index, uicc_sub.act_status);
    closeRequest;
    printRequest(pRI->token, pRI->pCI->requestNumber);

    CALL_ONREQUEST(pRI->pCI->requestNumber, &uicc_sub, sizeof(uicc_sub), pRI, pRI->socket_id);

#ifdef MEMSET_FREED
    memset(&uicc_sub, 0, sizeof(uicc_sub));
#endif
 return;

invalid:
    invalidCommandBlock(pRI);
 return;
}

Project: Android

static void dispatchVoiceRadioTech(Parcel& p, RequestInfo *pRI) {
    RIL_RadioState state = CALL_ONSTATEREQUEST((RIL_SOCKET_ID)pRI->socket_id);

 if ((RADIO_STATE_UNAVAILABLE == state) || (RADIO_STATE_OFF == state)) {
        RIL_onRequestComplete(pRI, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0);
 }

 if (RADIO_STATE_ON == state) {
        dispatchVoid(p, pRI);
 return;
 }

    voiceRadioTech = decodeVoiceRadioTechnology(state);

 if (voiceRadioTech < 0)
        RIL_onRequestComplete(pRI, RIL_E_GENERIC_FAILURE, NULL, 0);
 else
        RIL_onRequestComplete(pRI, RIL_E_SUCCESS, &voiceRadioTech, sizeof(int));
}

Project: Android

dispatchVoid (Parcel& p, RequestInfo *pRI) {
    clearPrintBuf;
    printRequest(pRI->token, pRI->pCI->requestNumber);
    CALL_ONREQUEST(pRI->pCI->requestNumber, NULL, 0, pRI, pRI->socket_id);
}

Project: Android

eventLoop(void *param) {
 int ret;
 int filedes[2];

    ril_event_init();

    pthread_mutex_lock(&s_startupMutex);

    s_started = 1;
    pthread_cond_broadcast(&s_startupCond);

    pthread_mutex_unlock(&s_startupMutex);

    ret = pipe(filedes);

 if (ret < 0) {
        RLOGE("Error in pipe() errno:%d", errno);
 return NULL;
 }

    s_fdWakeupRead = filedes[0];
    s_fdWakeupWrite = filedes[1];

    fcntl(s_fdWakeupRead, F_SETFL, O_NONBLOCK);

    ril_event_set (&s_wakeupfd_event, s_fdWakeupRead, true,
                processWakeupCallback, NULL);

    rilEventAddWakeup (&s_wakeupfd_event);

    ril_event_loop();
    RLOGE ("error in event_loop_base errno:%d", errno);
    kill(0, SIGKILL);

 return NULL;
}

Project: Android

failCauseToString(RIL_Errno e) {
 switch(e) {
 case RIL_E_SUCCESS: return "E_SUCCESS";
 case RIL_E_RADIO_NOT_AVAILABLE: return "E_RADIO_NOT_AVAILABLE";
 case RIL_E_GENERIC_FAILURE: return "E_GENERIC_FAILURE";
 case RIL_E_PASSWORD_INCORRECT: return "E_PASSWORD_INCORRECT";
 case RIL_E_SIM_PIN2: return "E_SIM_PIN2";
 case RIL_E_SIM_PUK2: return "E_SIM_PUK2";
 case RIL_E_REQUEST_NOT_SUPPORTED: return "E_REQUEST_NOT_SUPPORTED";
 case RIL_E_CANCELLED: return "E_CANCELLED";
 case RIL_E_OP_NOT_ALLOWED_DURING_VOICE_CALL: return "E_OP_NOT_ALLOWED_DURING_VOICE_CALL";
 case RIL_E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW: return "E_OP_NOT_ALLOWED_BEFORE_REG_TO_NW";
 case RIL_E_SMS_SEND_FAIL_RETRY: return "E_SMS_SEND_FAIL_RETRY";
 case RIL_E_SIM_ABSENT:return "E_SIM_ABSENT";
 case RIL_E_ILLEGAL_SIM_OR_ME:return "E_ILLEGAL_SIM_OR_ME";
#ifdef FEATURE_MULTIMODE_ANDROID
 case RIL_E_SUBSCRIPTION_NOT_AVAILABLE:return "E_SUBSCRIPTION_NOT_AVAILABLE";
 case RIL_E_MODE_NOT_SUPPORTED:return "E_MODE_NOT_SUPPORTED";
#endif
 case RIL_E_FDN_CHECK_FAILURE: return "E_FDN_CHECK_FAILURE";
 case RIL_E_MISSING_RESOURCE: return "E_MISSING_RESOURCE";
 case RIL_E_NO_SUCH_ELEMENT: return "E_NO_SUCH_ELEMENT";
 case RIL_E_DIAL_MODIFIED_TO_USSD: return "E_DIAL_MODIFIED_TO_USSD";
 case RIL_E_DIAL_MODIFIED_TO_SS: return "E_DIAL_MODIFIED_TO_SS";
 case RIL_E_DIAL_MODIFIED_TO_DIAL: return "E_DIAL_MODIFIED_TO_DIAL";
 case RIL_E_USSD_MODIFIED_TO_DIAL: return "E_USSD_MODIFIED_TO_DIAL";
 case RIL_E_USSD_MODIFIED_TO_SS: return "E_USSD_MODIFIED_TO_SS";
 case RIL_E_USSD_MODIFIED_TO_USSD: return "E_USSD_MODIFIED_TO_USSD";
 case RIL_E_SS_MODIFIED_TO_DIAL: return "E_SS_MODIFIED_TO_DIAL";
 case RIL_E_SS_MODIFIED_TO_USSD: return "E_SS_MODIFIED_TO_USSD";
 case RIL_E_SUBSCRIPTION_NOT_SUPPORTED: return "E_SUBSCRIPTION_NOT_SUPPORTED";
 case RIL_E_SS_MODIFIED_TO_SS: return "E_SS_MODIFIED_TO_SS";
 case RIL_E_LCE_NOT_SUPPORTED: return "E_LCE_NOT_SUPPORTED";
 case RIL_E_NO_MEMORY: return "E_NO_MEMORY";
 case RIL_E_INTERNAL_ERR: return "E_INTERNAL_ERR";
 case RIL_E_SYSTEM_ERR: return "E_SYSTEM_ERR";
 case RIL_E_MODEM_ERR: return "E_MODEM_ERR";
 case RIL_E_INVALID_STATE: return "E_INVALID_STATE";
 case RIL_E_NO_RESOURCES: return "E_NO_RESOURCES";
 case RIL_E_SIM_ERR: return "E_SIM_ERR";
 case RIL_E_INVALID_ARGUMENTS: return "E_INVALID_ARGUMENTS";
 case RIL_E_INVALID_SIM_STATE: return "E_INVALID_SIM_STATE";
 case RIL_E_INVALID_MODEM_STATE: return "E_INVALID_MODEM_STATE";
 case RIL_E_INVALID_CALL_ID: return "E_INVALID_CALL_ID";
 case RIL_E_NO_SMS_TO_ACK: return "E_NO_SMS_TO_ACK";
 case RIL_E_NETWORK_ERR: return "E_NETWORK_ERR";
 case RIL_E_REQUEST_RATE_LIMITED: return "E_REQUEST_RATE_LIMITED";
 case RIL_E_SIM_BUSY: return "E_SIM_BUSY";
 case RIL_E_SIM_FULL: return "E_SIM_FULL";
 case RIL_E_NETWORK_REJECT: return "E_NETWORK_REJECT";
 case RIL_E_OPERATION_NOT_ALLOWED: return "E_OPERATION_NOT_ALLOWED";
 case RIL_E_EMPTY_RECORD: "E_EMPTY_RECORD";
 case RIL_E_INVALID_SMS_FORMAT: return "E_INVALID_SMS_FORMAT";
 case RIL_E_ENCODING_ERR: return "E_ENCODING_ERR";
 case RIL_E_INVALID_SMSC_ADDRESS: return "E_INVALID_SMSC_ADDRESS";
 case RIL_E_NO_SUCH_ENTRY: return "E_NO_SUCH_ENTRY";
 case RIL_E_NETWORK_NOT_READY: return "E_NETWORK_NOT_READY";
 case RIL_E_NOT_PROVISIONED: return "E_NOT_PROVISIONED";
 case RIL_E_NO_SUBSCRIPTION: return "E_NO_SUBSCRIPTION";
 case RIL_E_NO_NETWORK_FOUND: return "E_NO_NETWORK_FOUND";
 case RIL_E_DEVICE_IN_USE: return "E_DEVICE_IN_USE";
 case RIL_E_ABORTED: return "E_ABORTED";
 case RIL_E_OEM_ERROR_1: return "E_OEM_ERROR_1";
 case RIL_E_OEM_ERROR_2: return "E_OEM_ERROR_2";
 case RIL_E_OEM_ERROR_3: return "E_OEM_ERROR_3";
 case RIL_E_OEM_ERROR_4: return "E_OEM_ERROR_4";
 case RIL_E_OEM_ERROR_5: return "E_OEM_ERROR_5";
 case RIL_E_OEM_ERROR_6: return "E_OEM_ERROR_6";
 case RIL_E_OEM_ERROR_7: return "E_OEM_ERROR_7";
 case RIL_E_OEM_ERROR_8: return "E_OEM_ERROR_8";
 case RIL_E_OEM_ERROR_9: return "E_OEM_ERROR_9";
 case RIL_E_OEM_ERROR_10: return "E_OEM_ERROR_10";
 case RIL_E_OEM_ERROR_11: return "E_OEM_ERROR_11";
 case RIL_E_OEM_ERROR_12: return "E_OEM_ERROR_12";
 case RIL_E_OEM_ERROR_13: return "E_OEM_ERROR_13";
 case RIL_E_OEM_ERROR_14: return "E_OEM_ERROR_14";
 case RIL_E_OEM_ERROR_15: return "E_OEM_ERROR_15";
 case RIL_E_OEM_ERROR_16: return "E_OEM_ERROR_16";
 case RIL_E_OEM_ERROR_17: return "E_OEM_ERROR_17";
 case RIL_E_OEM_ERROR_18: return "E_OEM_ERROR_18";
 case RIL_E_OEM_ERROR_19: return "E_OEM_ERROR_19";
 case RIL_E_OEM_ERROR_20: return "E_OEM_ERROR_20";
 case RIL_E_OEM_ERROR_21: return "E_OEM_ERROR_21";
 case RIL_E_OEM_ERROR_22: return "E_OEM_ERROR_22";
 case RIL_E_OEM_ERROR_23: return "E_OEM_ERROR_23";
 case RIL_E_OEM_ERROR_24: return "E_OEM_ERROR_24";
 case RIL_E_OEM_ERROR_25: return "E_OEM_ERROR_25";
 default: return "<unknown error>";
 }
}

Project: Android

static int findFd(int socket_id) {
 int fd = s_ril_param_socket.fdCommand;
#if (SIM_COUNT >= 2)
 if (socket_id == RIL_SOCKET_2) {
        fd = s_ril_param_socket2.fdCommand;
 }
#if (SIM_COUNT >= 3)
 if (socket_id == RIL_SOCKET_3) {
        fd = s_ril_param_socket3.fdCommand;
 }
#endif
#if (SIM_COUNT >= 4)
 if (socket_id == RIL_SOCKET_4) {
        fd = s_ril_param_socket4.fdCommand;
 }
#endif
#endif
 return fd;
}

Project: Android

static void freeDebugCallbackArgs(int number, char **args) {
 for (int i = 0; i < number; i++) {
 if (args[i] != NULL) {
            free(args[i]);
 }
 }
    free(args);
}

Project: Android

grabPartialWakeLock() {
 if (s_callbacks.version >= 13) {
 int ret;
        ret = pthread_mutex_lock(&s_wakeLockCountMutex);
        assert(ret == 0);
        acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);

 UserCallbackInfo *p_info =
                internalRequestTimedCallback(wakeTimeoutCallback, NULL, &TIMEVAL_WAKE_TIMEOUT);
 if (p_info == NULL) {
            release_wake_lock(ANDROID_WAKE_LOCK_NAME);
 } else {
            s_wakelock_count++;
 if (s_last_wake_timeout_info != NULL) {
                s_last_wake_timeout_info->userParam = (void *)1;
 }
            s_last_wake_timeout_info = p_info;
 }
        ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
        assert(ret == 0);
 } else {
        acquire_wake_lock(PARTIAL_WAKE_LOCK, ANDROID_WAKE_LOCK_NAME);
 }
}

Project: Android

internalRequestTimedCallback (RIL_TimedCallback callback, void *param,
 const struct timeval *relativeTime)
{
 struct timeval myRelativeTime;
 UserCallbackInfo *p_info;

    p_info = (UserCallbackInfo *) calloc(1, sizeof(UserCallbackInfo));
 if (p_info == NULL) {
        RLOGE("Memory allocation failed in internalRequestTimedCallback");
 return p_info;

 }

    p_info->p_callback = callback;
    p_info->userParam = param;

 if (relativeTime == NULL) {
 /* treat null parameter as a 0 relative time */
        memset (&myRelativeTime, 0, sizeof(myRelativeTime));
 } else {
 /* FIXME I think event_add's tv param is really const anyway */
        memcpy (&myRelativeTime, relativeTime, sizeof(myRelativeTime));
 }

    ril_event_set(&(p_info->event), -1, false, userTimerCallback, p_info);

    ril_timer_add(&(p_info->event), &myRelativeTime);

    triggerEvLoop();
 return p_info;
}

Project: Android

invalidCommandBlock (RequestInfo *pRI) {
    RLOGE("invalid command block for token %d request %s",
                pRI->token, requestToString(pRI->pCI->requestNumber));
}

Project: Android

static bool is3gpp2(int radioTech) {
 switch (radioTech) {
 case RADIO_TECH_IS95A:
 case RADIO_TECH_IS95B:
 case RADIO_TECH_1xRTT:
 case RADIO_TECH_EVDO_0:
 case RADIO_TECH_EVDO_A:
 case RADIO_TECH_EVDO_B:
 case RADIO_TECH_EHRPD:
 return true;
 default:
 return false;
 }
}

Project: Android

static bool isServiceTypeCfQuery(RIL_SsServiceType serType, RIL_SsRequestType reqType) {
 if ((reqType == SS_INTERROGATION) &&
 (serType == SS_CFU ||
         serType == SS_CF_BUSY ||
         serType == SS_CF_NO_REPLY ||
         serType == SS_CF_NOT_REACHABLE ||
         serType == SS_CF_ALL ||
         serType == SS_CF_ALL_CONDITIONAL)) {
 return true;
 }
 return false;
}

Project: Android

issueLocalRequest(int request, void *data, int len, RIL_SOCKET_ID socket_id) {
 RequestInfo *pRI;
 int ret;
 /* Hook for current context */
 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
 /* pendingRequestsHook refer to &s_pendingRequests */
 RequestInfo**    pendingRequestsHook = &s_pendingRequests;

#if (SIM_COUNT == 2)
 if (socket_id == RIL_SOCKET_2) {
        pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
        pendingRequestsHook = &s_pendingRequests_socket2;
 }
#endif

    pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
 if (pRI == NULL) {
        RLOGE("Memory allocation failed for request %s", requestToString(request));
 return;
 }

    pRI->local = 1;
    pRI->token = 0xffffffff; // token is not used in this context
    pRI->pCI = &(s_commands[request]);
    pRI->socket_id = socket_id;

    ret = pthread_mutex_lock(pendingRequestsMutexHook);
    assert (ret == 0);

    pRI->p_next = *pendingRequestsHook;
 *pendingRequestsHook = pRI;

    ret = pthread_mutex_unlock(pendingRequestsMutexHook);
    assert (ret == 0);

    RLOGD("C[locl]> %s", requestToString(request));

    CALL_ONREQUEST(request, data, len, pRI, pRI->socket_id);
}

Project: Android

static void listenCallback (int fd, short flags, void *param) {
 int ret;
 int err;
 int is_phone_socket;
 int fdCommand = -1;
 const char* processName;
 RecordStream *p_rs;
 MySocketListenParam* listenParam;
 RilSocket *sapSocket = NULL;
    socketClient *sClient = NULL;

 SocketListenParam *p_info = (SocketListenParam *)param;

 if(RIL_SAP_SOCKET == p_info->type) {
        listenParam = (MySocketListenParam *)param;
        sapSocket = listenParam->socket;
 }

 struct sockaddr_un peeraddr;
 socklen_t socklen = sizeof (peeraddr);

 struct ucred creds;
 socklen_t szCreds = sizeof(creds);

 struct passwd *pwd = NULL;

 if(NULL == sapSocket) {
        assert (*p_info->fdCommand < 0);
        assert (fd == *p_info->fdListen);
        processName = PHONE_PROCESS;
 } else {
        assert (sapSocket->commandFd < 0);
        assert (fd == sapSocket->listenFd);
        processName = BLUETOOTH_PROCESS;
 }


    fdCommand = accept(fd, (sockaddr *) &peeraddr, &socklen);

 if (fdCommand < 0 ) {
        RLOGE("Error on accept() errno:%d", errno);
 /* start listening for new connections again */
 if(NULL == sapSocket) {
            rilEventAddWakeup(p_info->listen_event);
 } else {
            rilEventAddWakeup(sapSocket->getListenEvent());
 }
 return;
 }

 /* check the credential of the other side and only accept socket from
     * phone process
     */
    errno = 0;
    is_phone_socket = 0;

    err = getsockopt(fdCommand, SOL_SOCKET, SO_PEERCRED, &creds, &szCreds);

 if (err == 0 && szCreds > 0) {
        errno = 0;
        pwd = getpwuid(creds.uid);
 if (pwd != NULL) {
 if (strcmp(pwd->pw_name, processName) == 0) {
                is_phone_socket = 1;
 } else {
                RLOGE("RILD can't accept socket from process %s", pwd->pw_name);
 }
 } else {
            RLOGE("Error on getpwuid() errno: %d", errno);
 }
 } else {
        RLOGD("Error on getsockopt() errno: %d", errno);
 }

 if (!is_phone_socket) {
        RLOGE("RILD must accept socket from %s", processName);

        close(fdCommand);
        fdCommand = -1;

 if(NULL == sapSocket) {
            onCommandsSocketClosed(p_info->socket_id);

 /* start listening for new connections again */
            rilEventAddWakeup(p_info->listen_event);
 } else {
            sapSocket->onCommandsSocketClosed();

 /* start listening for new connections again */
            rilEventAddWakeup(sapSocket->getListenEvent());
 }

 return;
 }

    ret = fcntl(fdCommand, F_SETFL, O_NONBLOCK);

 if (ret < 0) {
        RLOGE ("Error setting O_NONBLOCK errno:%d", errno);
 }

 if(NULL == sapSocket) {
        RLOGI("libril: new connection to %s", rilSocketIdToString(p_info->socket_id));

        p_info->fdCommand = fdCommand;
        p_rs = record_stream_new(p_info->fdCommand, MAX_COMMAND_BYTES);
        p_info->p_rs = p_rs;

        ril_event_set (p_info->commands_event, p_info->fdCommand, 1,
        p_info->processCommandsCallback, p_info);
        rilEventAddWakeup (p_info->commands_event);

        onNewCommandConnect(p_info->socket_id);
 } else {
        RLOGI("libril: new connection");

        sapSocket->setCommandFd(fdCommand);
        p_rs = record_stream_new(sapSocket->getCommandFd(), MAX_COMMAND_BYTES);
        sClient = new socketClient(sapSocket,p_rs);
        ril_event_set (sapSocket->getCallbackEvent(), sapSocket->getCommandFd(), 1,
        sapSocket->getCommandCb(), sClient);

        rilEventAddWakeup(sapSocket->getCallbackEvent());
        sapSocket->onNewCommandConnect();
 }
}

Project: Android

void listenCallback_helper(int fd, short flags, void *param) {
    android::listenCallback(fd, flags, param);
}

Project: Android

static void marshallSignalInfoRecord(Parcel &p,
            RIL_CDMA_SignalInfoRecord &p_signalInfoRecord) {
    p.writeInt32(p_signalInfoRecord.isPresent);
    p.writeInt32(p_signalInfoRecord.signalType);
    p.writeInt32(p_signalInfoRecord.alertPitch);
    p.writeInt32(p_signalInfoRecord.signal);
}

Project: Android

memsetString (char *s) {
 if (s != NULL) {
        memset (s, 0, strlen(s));
 }
}

Project: Android

void   nullParcelReleaseFunction (const uint8_t* data, size_t dataSize,
 const size_t* objects, size_t objectsSize,
 void* cookie) {
}

Project: Android

static void onCommandsSocketClosed(RIL_SOCKET_ID socket_id) {
 int ret;
 RequestInfo *p_cur;
 /* Hook for current context
       pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
 pthread_mutex_t * pendingRequestsMutexHook = &s_pendingRequestsMutex;
 /* pendingRequestsHook refer to &s_pendingRequests */
 RequestInfo **    pendingRequestsHook = &s_pendingRequests;

#if (SIM_COUNT >= 2)
 if (socket_id == RIL_SOCKET_2) {
        pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
        pendingRequestsHook = &s_pendingRequests_socket2;
 }
#if (SIM_COUNT >= 3)
 else if (socket_id == RIL_SOCKET_3) {
        pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
        pendingRequestsHook = &s_pendingRequests_socket3;
 }
#endif
#if (SIM_COUNT >= 4)
 else if (socket_id == RIL_SOCKET_4) {
        pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
        pendingRequestsHook = &s_pendingRequests_socket4;
 }
#endif
#endif
 /* mark pending requests as "cancelled" so we dont report responses */
    ret = pthread_mutex_lock(pendingRequestsMutexHook);
    assert (ret == 0);

    p_cur = *pendingRequestsHook;

 for (p_cur = *pendingRequestsHook
 ; p_cur != NULL
 ; p_cur  = p_cur->p_next
 ) {
        p_cur->cancelled = 1;
 }

    ret = pthread_mutex_unlock(pendingRequestsMutexHook);
    assert (ret == 0);
}

Project: Android

static void onNewCommandConnect(RIL_SOCKET_ID socket_id) {
 int rilVer = s_callbacks.version;
    RIL_UNSOL_RESPONSE(RIL_UNSOL_RIL_CONNECTED,
 &rilVer, sizeof(rilVer), socket_id);

    RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED,
                                    NULL, 0, socket_id);

 if (s_lastNITZTimeData != NULL) {
        sendResponseRaw(s_lastNITZTimeData, s_lastNITZTimeDataSize, socket_id);

        free(s_lastNITZTimeData);
        s_lastNITZTimeData = NULL;
 }

 if (s_callbacks.getVersion != NULL) {
 const char *version;
        version = s_callbacks.getVersion();
        RLOGI("RIL Daemon version: %s\n", version);

        property_set(PROPERTY_RIL_IMPL, version);
 } else {
        RLOGI("RIL Daemon version: unavailable\n");
        property_set(PROPERTY_RIL_IMPL, "unavailable");
 }

}

Project: Android

processCommandBuffer(void *buffer, size_t buflen, RIL_SOCKET_ID socket_id) {
 Parcel p;
 status_t status;
 int32_t request;
 int32_t token;
 RequestInfo *pRI;
 int ret;
 /* Hook for current context */
 /* pendingRequestsMutextHook refer to &s_pendingRequestsMutex */
 pthread_mutex_t* pendingRequestsMutexHook = &s_pendingRequestsMutex;
 /* pendingRequestsHook refer to &s_pendingRequests */
 RequestInfo**    pendingRequestsHook = &s_pendingRequests;

    p.setData((uint8_t *) buffer, buflen);

    status = p.readInt32(&request);
    status = p.readInt32 (&token);

#if (SIM_COUNT >= 2)
 if (socket_id == RIL_SOCKET_2) {
        pendingRequestsMutexHook = &s_pendingRequestsMutex_socket2;
        pendingRequestsHook = &s_pendingRequests_socket2;
 }
#if (SIM_COUNT >= 3)
 else if (socket_id == RIL_SOCKET_3) {
        pendingRequestsMutexHook = &s_pendingRequestsMutex_socket3;
        pendingRequestsHook = &s_pendingRequests_socket3;
 }
#endif
#if (SIM_COUNT >= 4)
 else if (socket_id == RIL_SOCKET_4) {
        pendingRequestsMutexHook = &s_pendingRequestsMutex_socket4;
        pendingRequestsHook = &s_pendingRequests_socket4;
 }
#endif
#endif

 if (status != NO_ERROR) {
        RLOGE("invalid request block");
 return 0;
 }

 if (request == RIL_RESPONSE_ACKNOWLEDGEMENT) {
        releaseWakeLock();
 return 0;
 }

 if (request < 1 || request >= (int32_t)NUM_ELEMS(s_commands)) {
 Parcel pErr;
        RLOGE("unsupported request code %d token %d", request, token);
        pErr.writeInt32 (RESPONSE_SOLICITED);
        pErr.writeInt32 (token);
        pErr.writeInt32 (RIL_E_GENERIC_FAILURE);

        sendResponse(pErr, socket_id);
 return 0;
 }

    pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
 if (pRI == NULL) {
        RLOGE("Memory allocation failed for request %s", requestToString(request));
 return 0;
 }

    pRI->token = token;
    pRI->pCI = &(s_commands[request]);
    pRI->socket_id = socket_id;

    ret = pthread_mutex_lock(pendingRequestsMutexHook);
    assert (ret == 0);

    pRI->p_next = *pendingRequestsHook;
 *pendingRequestsHook = pRI;

    ret = pthread_mutex_unlock(pendingRequestsMutexHook);
    assert (ret == 0);

/*    sLastDispatchedToken = token; */

    pRI->pCI->dispatchFunction(p, pRI);

 return 0;
}

Project: Android

static void processCommandsCallback(int fd, short flags, void *param) {
 RecordStream *p_rs;
 void *p_record;
 size_t recordlen;
 int ret;
 SocketListenParam *p_info = (SocketListenParam *)param;

    assert(fd == p_info->fdCommand);

    p_rs = p_info->p_rs;

 for (;;) {
 /* loop until EAGAIN/EINTR, end of stream, or other error */
        ret = record_stream_get_next(p_rs, &p_record, &recordlen);

 if (ret == 0 && p_record == NULL) {
 /* end-of-stream */
 break;
 } else if (ret < 0) {
 break;
 } else if (ret == 0) { /* && p_record != NULL */
            processCommandBuffer(p_record, recordlen, p_info->socket_id);
 }
 }

 if (ret == 0 || !(errno == EAGAIN || errno == EINTR)) {
 /* fatal error or end-of-stream */
 if (ret != 0) {
            RLOGE("error on reading command socket errno:%d\n", errno);
 } else {
            RLOGW("EOS.  Closing command socket.");
 }

        close(fd);
        p_info->fdCommand = -1;

        ril_event_del(p_info->commands_event);

        record_stream_free(p_rs);

 /* start listening for new connections again */
        rilEventAddWakeup(&s_listen_event);

        onCommandsSocketClosed(p_info->socket_id);
 }
}

Project: Android

processRadioState(RIL_RadioState newRadioState, RIL_SOCKET_ID socket_id) {

 if((newRadioState > RADIO_STATE_UNAVAILABLE) && (newRadioState < RADIO_STATE_ON)) {
 int newVoiceRadioTech;
 int newCdmaSubscriptionSource;
 int newSimStatus;

 /* This is old RIL. Decode Subscription source and Voice Radio Technology
           from Radio State and send change notifications if there has been a change */
        newVoiceRadioTech = decodeVoiceRadioTechnology(newRadioState);
 if(newVoiceRadioTech != voiceRadioTech) {
            voiceRadioTech = newVoiceRadioTech;
            RIL_UNSOL_RESPONSE(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED,
 &voiceRadioTech, sizeof(voiceRadioTech), socket_id);
 }
 if(is3gpp2(newVoiceRadioTech)) {
            newCdmaSubscriptionSource = decodeCdmaSubscriptionSource(newRadioState);
 if(newCdmaSubscriptionSource != cdmaSubscriptionSource) {
                cdmaSubscriptionSource = newCdmaSubscriptionSource;
                RIL_UNSOL_RESPONSE(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED,
 &cdmaSubscriptionSource, sizeof(cdmaSubscriptionSource), socket_id);
 }
 }
        newSimStatus = decodeSimStatus(newRadioState);
 if(newSimStatus != simRuimStatus) {
            simRuimStatus = newSimStatus;
            RIL_UNSOL_RESPONSE(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0, socket_id);
 }

 /* Send RADIO_ON to telephony */
        newRadioState = RADIO_STATE_ON;
 }

 return newRadioState;
}

Project: Android

static void processWakeupCallback(int fd, short flags, void *param) {
 char buff[16];
 int ret;

    RLOGV("processWakeupCallback");

 /* empty our wakeup socket out */
 do {
        ret = read(s_fdWakeupRead, &buff, sizeof(buff));
 } while (ret > 0 || (ret < 0 && errno == EINTR));
}

Project: Android

radioStateToString(RIL_RadioState s) {
 switch(s) {
 case RADIO_STATE_OFF: return "RADIO_OFF";
 case RADIO_STATE_UNAVAILABLE: return "RADIO_UNAVAILABLE";
 case RADIO_STATE_SIM_NOT_READY: return "RADIO_SIM_NOT_READY";
 case RADIO_STATE_SIM_LOCKED_OR_ABSENT: return "RADIO_SIM_LOCKED_OR_ABSENT";
 case RADIO_STATE_SIM_READY: return "RADIO_SIM_READY";
 case RADIO_STATE_RUIM_NOT_READY:return"RADIO_RUIM_NOT_READY";
 case RADIO_STATE_RUIM_READY:return"RADIO_RUIM_READY";
 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:return"RADIO_RUIM_LOCKED_OR_ABSENT";
 case RADIO_STATE_NV_NOT_READY:return"RADIO_NV_NOT_READY";
 case RADIO_STATE_NV_READY:return"RADIO_NV_READY";
 case RADIO_STATE_ON:return"RADIO_ON";
 default: return "<unknown state>";
 }
}

Project: Android

readStringFromParcelInplace(Parcel &p, char *str, size_t maxLen) {
 size_t s16Len;
 const char16_t *s16;

    s16 = p.readString16Inplace(&s16Len);
 if (s16 == NULL) {
 return NO_MEMORY;
 }
 size_t strLen = strnlen16to8(s16, s16Len);
 if ((strLen + 1) > maxLen) {
 return NO_MEMORY;
 }
 if (strncpy16to8(str, s16, strLen) == NULL) {
 return NO_MEMORY;
 } else {
 return NO_ERROR;
 }
}

Project: Android

releaseWakeLock() {
 if (s_callbacks.version >= 13) {
 int ret;
        ret = pthread_mutex_lock(&s_wakeLockCountMutex);
        assert(ret == 0);

 if (s_wakelock_count > 1) {
            s_wakelock_count--;
 } else {
            s_wakelock_count = 0;
            release_wake_lock(ANDROID_WAKE_LOCK_NAME);
 if (s_last_wake_timeout_info != NULL) {
                s_last_wake_timeout_info->userParam = (void *)1;
 }
 }

        ret = pthread_mutex_unlock(&s_wakeLockCountMutex);
        assert(ret == 0);
 } else {
        release_wake_lock(ANDROID_WAKE_LOCK_NAME);
 }
}