Ejemplo n.º 1
0
static int simIOGetLogicalChannel(void)
{
    ATResponse *atresponse = NULL;
    static int g_lc = 0;
    int err;

    if (g_lc == 0) {
        struct tlv tlvApp, tlvAppId;
        char *line;
        char *resp;

        err = at_send_command_singleline("AT+CUAD", "+CUAD:", &atresponse);
        if (err != AT_NOERROR)
            return g_lc;

        line = atresponse->p_intermediates->line;
        err = at_tok_start(&line);
        if (err < 0)
            goto finally;

        err = at_tok_nextstr(&line, &resp);
        if (err < 0)
            goto finally;

        err = parseTlv(resp, &resp[strlen(resp)], &tlvApp);
        if (err < 0)
            goto finally;
        if (tlvApp.tag != 0x61) { /* Application */
            err = -EINVAL;
            goto finally;
        }

        err = parseTlv(tlvApp.data, tlvApp.end, &tlvAppId);
        if (err < 0)
            goto finally;
        if (tlvAppId.tag != 0x4F) { /* Application ID */
            err = -EINVAL;
            goto finally;
        }

        at_response_free(atresponse);
        err = at_send_command_singleline("AT+CCHO=\"%.*s\"", "+CCHO:", &atresponse, tlvAppId.end - tlvAppId.data, tlvAppId.data);
        if (err != AT_NOERROR)
            return g_lc;
        line = atresponse->p_intermediates->line;
        err = at_tok_start(&line);
        if (err < 0)
            goto finally;

        err = at_tok_nextint(&line, &g_lc);
        if (err < 0)
            goto finally;
    }

finally:
    at_response_free(atresponse);
    return g_lc;
}
Ejemplo n.º 2
0
	/**
	 * RIL_REQUEST_QUERY_CALL_WAITING
	 *
	 * Query current call waiting state.
	 ok
	 */
void requestQueryCallWaiting(void *data, size_t datalen, RIL_Token t)
{
	ATResponse *p_response;
	p_response = NULL;
	int response[2] = {0, 0};
	int c = ((int *)data)[0];
	char *cmd;
	asprintf(&cmd, "AT+CCWA=1,2,1,%d", c);
	int err = at_send_command_singleline(cmd, "+CCWA: ",
			&p_response);
	free(cmd);

	if (err >= 0 && p_response->success) {
		char *line = p_response->p_intermediates->line;

		err = at_tok_start(&line);

		if (err >= 0) {
			err = at_tok_nextint(&line, &response[0]);

			if (err >= 0)
				err = at_tok_nextint(&line, &response[1]);
		}
	}

	RIL_onRequestComplete(t, RIL_E_SUCCESS, response, sizeof(response));
	at_response_free(p_response);
}
Ejemplo n.º 3
0
/**
 * Poll +COPS? and return a success, or if the loop counter reaches
 * REPOLL_OPERATOR_SELECTED, return generic failure.
 */
static void pollOperatorSelected(void *params)
{
    int err = 0;
    int response = 0;
    char *line = NULL;
    ATResponse *atresponse = NULL;
    struct operatorPollParams *poll_params;
    RIL_Token t;

    assert(params != NULL);

    poll_params = (struct operatorPollParams *) params;
    t = poll_params->t;

    if (poll_params->loopcount >= REPOLL_OPERATOR_SELECTED)
        goto error;

    err = at_send_command_singleline("AT+COPS?", "+COPS:", &atresponse);
    if (err != AT_NOERROR)
        goto error;

    line = atresponse->p_intermediates->line;

    err = at_tok_start(&line);
    if (err < 0)
        goto error;

    err = at_tok_nextint(&line, &response);
    if (err < 0)
        goto error;

    /* If we don't get more than the COPS: {0-4} we are not registered.
       Loop and try again. */
    if (!at_tok_hasmore(&line)) {
        switch (s_registrationDeniedReason) {
        case IMSI_UNKNOWN_IN_HLR: /* fall through */
        case ILLEGAL_ME:
            RIL_onRequestComplete(t, RIL_E_ILLEGAL_SIM_OR_ME, NULL, 0);
            free(poll_params);
            break;
        default:
            poll_params->loopcount++;
            enqueueRILEvent(RIL_EVENT_QUEUE_PRIO, pollOperatorSelected,
                            poll_params, &TIMEVAL_OPERATOR_SELECT_POLL);
        }
    } else {
        /* We got operator, throw a success! */
        RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0);
        free(poll_params);
    }

    at_response_free(atresponse);
    return;

error:
    RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
    free(poll_params);
    at_response_free(atresponse);
    return;
}
static char *getCharEncoding(void)
{
    int err;
    char *line, *chSet;
    ATResponse *p_response = NULL;
    err = at_send_command_singleline("AT+CSCS?", "+CSCS:", &p_response);
    if (err < 0) {
        LOGE("requestSetupDefaultPDP: Failed to read AT+CSCS?");
        return NULL;
    }

    line = p_response->p_intermediates->line;
    err = at_tok_start(&line);
    if (err < 0)
        return NULL;

    err = at_tok_nextstr(&line, &chSet);
    if (err < 0)
        return NULL;

    /* If not any of the listed below, assume UCS-2 */
    if (!strcmp(chSet, "GSM") || !strcmp(chSet, "IRA") ||
        !strncmp(chSet, "8859",4) || !strcmp(chSet, "UTF-8")) {
        return strdup(chSet);
    } else {
        return strdup("UCS-2");
    }
    at_response_free(p_response);
}
Ejemplo n.º 5
0
int getClvlValue()
{
	int err = 0;
	int clvl;
	char *line;
	ATResponse *atresponse=NULL;

	err = at_send_command_singleline("AT+CLVL?", "+CLVL:", &atresponse);

	if (err < 0 || !atresponse || !atresponse->p_intermediates)
		goto error;

	line = atresponse->p_intermediates->line;

	err = at_tok_start(&line);
	if (err < 0)
		goto error;

	err = at_tok_nextint(&line, &clvl);
	if (err < 0)
		goto error;
error:
	at_response_free(atresponse);
	return clvl;
}
Ejemplo n.º 6
0
void requestGetSMSCAddress(void *data, size_t datalen, RIL_Token t)
{
	ATResponse *atresponse = NULL;
	int err;
	char *line;
	char *response;

	err = at_send_command_singleline("AT+CSCA?", "+CSCA:", &atresponse);

	if (err < 0 || atresponse->success == 0)
		goto error;

	line = atresponse->p_intermediates->line;

	err = at_tok_start(&line);
	if (err < 0)
		goto error;

	err = at_tok_nextstr(&line, &response);
	if (err < 0)
		goto error;

	RIL_onRequestComplete(t, RIL_E_SUCCESS, response, sizeof(char *));

finally:
	at_response_free(atresponse);
	return;

error:
	RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
	goto finally;
}
Ejemplo n.º 7
0
/** returns 1 if on, 0 if off, and -1 on error */
int getRadioPower()
{
	ATResponse *p_response = NULL;
	int err;
	char *line;
	int ret;

	err = at_send_command_singleline("AT+CFUN?", "+CFUN:", &p_response);

	if (err < 0 || p_response->success == 0) {
		// assume radio is off
		goto error;
	}

	line = p_response->p_intermediates->line;

	err = at_tok_start(&line);
	if (err < 0) goto error;

	err = at_tok_nextint(&line, &ret);
	if (err < 0) goto error;

	at_response_free(p_response);

	return ret;

error:

	at_response_free(p_response);
	return -1;
}
Ejemplo n.º 8
0
int getZmdsValue()
{
	int err = 0;
	int type = 4;
	char *line;
	ATResponse *atresponse=NULL;

	err = at_send_command_singleline("AT+ZMDS?", "+ZMDS:", &atresponse);

	if (err < 0)
		goto error;

	if (!atresponse->p_intermediates || !atresponse->p_intermediates->line)
		goto error;

	line = atresponse->p_intermediates->line;

	err = at_tok_start(&line);
	if (err < 0)
		goto error;

	err = at_tok_nextint(&line, &type);
	if (err < 0)
		goto error;

error:
	at_response_free(atresponse);
	return type;
}
Ejemplo n.º 9
0
void reportSignalStrength(void *param)
{
	ATResponse *p_response = NULL;
	int err, tmp;
	char *line;
	RIL_SignalStrength_v6 resp;

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

	resp.GW_SignalStrength.signalStrength = -1;
	resp.GW_SignalStrength.bitErrorRate = -1;
	resp.LTE_SignalStrength.signalStrength = -1;
	resp.LTE_SignalStrength.rsrp = -1;
	resp.LTE_SignalStrength.rsrq = -1;
	resp.LTE_SignalStrength.rssnr = -1;
	resp.LTE_SignalStrength.cqi = -1;


	err = at_send_command_singleline("AT+CSQ", "+CSQ:", &p_response);

	if (err < 0 || p_response->success == 0) 
	{
		goto error;
	}
	line = p_response->p_intermediates->line;

	err = at_tok_start(&line);
	if (err < 0) goto error;

	err = at_tok_nextint(&line, &(resp.GW_SignalStrength.signalStrength));
	if (err < 0) goto error;

	err = at_tok_nextint(&line, &(resp.GW_SignalStrength.bitErrorRate));
	if (err < 0) goto error;

	at_response_free(p_response);
	p_response = NULL;

    if (param != NULL)
        resp.GW_SignalStrength.signalStrength = *(int*)param;

	resp.LTE_SignalStrength.signalStrength = -1;
	resp.LTE_SignalStrength.rsrp = -1;
	resp.LTE_SignalStrength.rsrq = -1;
	resp.LTE_SignalStrength.rssnr = -1;
	resp.LTE_SignalStrength.cqi = -1;

	RIL_onUnsolicitedResponse (
			RIL_UNSOL_SIGNAL_STRENGTH,
			& resp, sizeof(resp));
	return;

error:
	at_response_free(p_response);

}
Ejemplo n.º 10
0
int sendSimIOCmdICC(const RIL_SIM_IO_v6 *ioargs, ATResponse **atresponse, RIL_SIM_IO_Response *sr)
{
    int err;
    char *fmt;
    char *arg6;
    char *arg7;
    char *line;

    /* FIXME Handle pin2. */
    memset(sr, 0, sizeof(*sr));

    arg6 = ioargs->data;
    arg7 = ioargs->path;

    if (arg7 && arg6) {
        fmt = "AT+CRSM=%d,%d,%d,%d,%d,\"%s\",\"%s\"";
    } else if (arg7) {
        fmt = "AT+CRSM=%d,%d,%d,%d,%d,,\"%s\"";
        arg6 = arg7;
    } else if (arg6) {
        fmt = "AT+CRSM=%d,%d,%d,%d,%d,\"%s\"";
    } else {
        fmt = "AT+CRSM=%d,%d,%d,%d,%d";
    }

    err = at_send_command_singleline(fmt, "+CRSM:", atresponse,ioargs->command,
                 ioargs->fileid, ioargs->p1,
                 ioargs->p2, ioargs->p3,
                 arg6, arg7);

    if (err != AT_NOERROR)
        return err;

    line = (*atresponse)->p_intermediates->line;

    err = at_tok_start(&line);
    if (err < 0)
        goto finally;

    err = at_tok_nextint(&line, &(sr->sw1));
    if (err < 0)
        goto finally;

    err = at_tok_nextint(&line, &(sr->sw2));
    if (err < 0)
        goto finally;

    if (at_tok_hasmore(&line)) {
        err = at_tok_nextstr(&line, &(sr->simResponse));
        if (err < 0)
            goto finally;
    }

finally:
    return err;
}
Ejemplo n.º 11
0
/**
 * RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE
 *
 * Query the preferred network type (CS/PS domain, RAT, and operation mode)
 * for searching and registering.
 */
void requestGetPreferredNetworkType(void *data, size_t datalen,
                                    RIL_Token t)
{
    (void) data; (void) datalen;
    int err = 0;
    int response = 0;
    int cfun;
    char *line;
    ATResponse *atresponse;

    err = at_send_command_singleline("AT+CFUN?", "+CFUN:", &atresponse);
    if (err != AT_NOERROR)
        goto error;

    line = atresponse->p_intermediates->line;

    err = at_tok_start(&line);
    if (err < 0)
        goto error;

    err = at_tok_nextint(&line, &cfun);
    if (err < 0)
        goto error;

    if (cfun < 0 || cfun >= 7)
        goto error;

    switch (cfun) {
    case PREF_NET_TYPE_2G_ONLY:
        response = PREF_NET_TYPE_GSM_ONLY;
        break;
    case PREF_NET_TYPE_3G_ONLY:
        response = PREF_NET_TYPE_WCDMA;
        break;
    case PREF_NET_TYPE_3G:
        response = PREF_NET_TYPE_GSM_WCDMA_AUTO;
        break;
    default:
        response = PREF_NET_TYPE_GSM_WCDMA_AUTO;
        break;
    }

    RIL_onRequestComplete(t, RIL_E_SUCCESS, &response, sizeof(int));

finally:
    at_response_free(atresponse);
    return;

error:
    RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
    goto finally;
}
Ejemplo n.º 12
0
	/**
	 * RIL_REQUEST_QUERY_FACILITY_LOCK
	 *
	 * Query the status of a facility lock state.
	 */
void requestQueryFacilityLock(void *data, size_t datalen, RIL_Token t)
{
	int err, rat, response;
	ATResponse *atresponse = NULL;
	char *cmd = NULL;
	char *line = NULL;
	char *facility_string = NULL;
	char *facility_password = NULL;
	char *facility_class = NULL;

	assert(datalen >= (3 * sizeof(char **)));

	facility_string = ((char **) data)[0];
	facility_password = ((char **) data)[1];
	facility_class = ((char **) data)[2];

	/* do not support FD string, force copy string SC */
	if(strcmp(facility_string, "FD") == 0){
		strcpy(facility_string, "SC");
	}

	asprintf(&cmd, "AT+CLCK=\"%s\",2,\"%s\",%s", facility_string,
			facility_password, facility_class);

	err = at_send_command_singleline(cmd, "+CLCK:", &atresponse);
	free(cmd);
	if (err < 0 || atresponse->success == 0) {
		goto error;
	}

	line = atresponse->p_intermediates->line;

	err = at_tok_start(&line);
	if (err < 0)
		goto error;

	err = at_tok_nextint(&line, &response);
	if (err < 0)
		goto error;

	RIL_onRequestComplete(t, RIL_E_SUCCESS, &response, sizeof(int));

finally:
	at_response_free(atresponse);
	return;

error:
	RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
	goto finally;
}
Ejemplo n.º 13
0
static int get_phone_book(int index, phone_book_t* pb)
{
	int ret = -1, err;
	char* cmd = NULL;
	char* line = NULL;
    char* buffer = NULL;
    ATResponse *p_response = NULL;
	asprintf(&cmd,"AT+CPBR=%d", index);

	at_send_command("AT+CSCS=\"UCS2\"", NULL);
	err = at_send_command_singleline(cmd,"+CPBR:",&p_response);

	if (err < 0 || !p_response || p_response->success == 0)
		goto error;

    	if (p_response && p_response->p_intermediates) {
		line=p_response->p_intermediates->line;
		err=at_tok_start(&line);
		if (err < 0) 
			goto error;
		
		err=at_tok_nextint(&line,&(pb->index));
		if (err < 0)
			goto error;
		
		err=at_tok_nextstr(&line,&buffer);
		if (err < 0) 
			goto error;

        strcpy(pb->number, buffer);
		
		err=at_tok_nextint(&line,&(pb->code));
		if (err < 0)
			goto error;
		
		err=at_tok_nextstr(&line,&buffer);

		if (err < 0) 
			goto error;
        
        strcpy(pb->alpha, buffer);
	}
	
	ret = 0;
error:
	at_response_free(p_response);
	free(cmd);
	return ret;	
}
Ejemplo n.º 14
0
/**
 * RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE
 *
 * Query current network selectin mode.
 */
void requestQueryNetworkSelectionMode(void *data, size_t datalen,
                                      RIL_Token t)
{
    (void) data; (void) datalen;
    int err;
    ATResponse *atresponse = NULL;
    int response = 0;
    char *line;

    err = at_send_command_singleline("AT+COPS?", "+COPS:", &atresponse);

    if (err != AT_NOERROR)
        goto error;

    line = atresponse->p_intermediates->line;

    err = at_tok_start(&line);

    if (err < 0)
        goto error;

    err = at_tok_nextint(&line, &response);

    if (err < 0)
        goto error;

    /*
     * Android accepts 0(automatic) and 1(manual).
     * Modem may return mode 4(Manual/automatic).
     * Convert it to 1(Manual) as android expects.
     */
    if (response == 4)
        response = 1;

    RIL_onRequestComplete(t, RIL_E_SUCCESS, &response, sizeof(int));

finally:
    at_response_free(atresponse);
    return;

error:
    LOGE("%s() Must never return error when radio is on", __func__);
    RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
    goto finally;
}
Ejemplo n.º 15
0
/**
 * RIL_REQUEST_QUERY_FACILITY_LOCK
 *
 * Query the status of a facility lock state.
 */
void requestQueryFacilityLock(void *data, size_t datalen, RIL_Token t)
{
    int err, response;
    ATResponse *atresponse = NULL;
    char *line = NULL;
    char *facility_string = NULL;
    char *facility_password = NULL;
    char *facility_class = NULL;

    (void) datalen;

    if (datalen < 3 * sizeof(char **)) {
        ALOGE("%s() bad data length!", __func__);
        goto error;
    }

    facility_string = ((char **) data)[0];
    facility_password = ((char **) data)[1];
    facility_class = ((char **) data)[2];

    err = at_send_command_singleline("AT+CLCK=\"%s\",2,\"%s\",%s", "+CLCK:", &atresponse,
            facility_string, facility_password, facility_class);
    if (err != AT_NOERROR)
        goto error;

    line = atresponse->p_intermediates->line;

    err = at_tok_start(&line);

    if (err < 0)
        goto error;

    err = at_tok_nextint(&line, &response);

    if (err < 0)
        goto error;

    RIL_onRequestComplete(t, RIL_E_SUCCESS, &response, sizeof(int));
    at_response_free(atresponse);
    return;

error:
    RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
    at_response_free(atresponse);
}
Ejemplo n.º 16
0
void _requestSignalStrengthWCDMA(void *data, size_t datalen, RIL_Token t)
{
	ATResponse *p_response = NULL;
	int err;
	RIL_SignalStrength_v6 resp;
	char *line;

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

	err = at_send_command_singleline("AT+CSQ", "+CSQ:", &p_response);

	if (err < 0 || p_response->success == 0) {
		RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
		goto error;
	}

	line = p_response->p_intermediates->line;

	err = at_tok_start(&line);
	if (err < 0) goto error;

	err = at_tok_nextint(&line, &(resp.GW_SignalStrength.signalStrength));
	if (err < 0) goto error;

	err = at_tok_nextint(&line, &(resp.GW_SignalStrength.bitErrorRate));
	if (err < 0) goto error;

	resp.LTE_SignalStrength.signalStrength = -1;
	resp.LTE_SignalStrength.rsrp = -1;
	resp.LTE_SignalStrength.rsrq = -1;
	resp.LTE_SignalStrength.rssnr = -1;
	resp.LTE_SignalStrength.cqi = -1;

	RIL_onRequestComplete(t, RIL_E_SUCCESS, &resp, sizeof(resp));

	at_response_free(p_response);
	return;

error:
	LOGE("requestSignalStrength must never return an error when radio is on");
	RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
	at_response_free(p_response);
}
Ejemplo n.º 17
0
static void requestGetIMEI(void *data, size_t datalen, RIL_Token t)
{
	ATResponse *atresponse = NULL;
	int err;

	err = at_send_command_singleline("AT+CGSN", "+CGSN:",&atresponse);

	if (err < 0 || atresponse->success == 0) {
		RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
	} else {
		property_set("ril.imei",atresponse->p_intermediates->line+6);

		RIL_onRequestComplete(t, RIL_E_SUCCESS,
				atresponse->p_intermediates->line+6,
				sizeof(char *));
	}
	at_response_free(atresponse);
	return;
}
Ejemplo n.º 18
0
static int getNetworkType()
{
	int err;
	ATResponse *p_response = NULL;
	int type = 0;
	char *line;

	err = at_send_command_singleline("AT+COPS?", "+COPS:", &p_response);

	if (err < 0 || p_response->success == 0) {
		return type;
	}

	line = p_response->p_intermediates->line;

	err = at_tok_start(&line);

	if (err < 0) {
		goto out;
	}

	err = at_tok_nextint(&line, &type);
	err = at_tok_nextint(&line, &type);
	err = at_tok_nextint(&line, &type);
	err = at_tok_nextint(&line, &type);

	switch(type){
		case 0:
		case 1:
			type = 2;
			break;
		case 2:
			type = 3;
			break;
		default:
			type = 3;
			break;
	}
out:
	at_response_free(p_response);
	return type;	
}
Ejemplo n.º 19
0
static int simIOSelectFile(unsigned short fileid)
{
    int err = 0;
    unsigned short lc = simIOGetLogicalChannel();
    ATResponse *atresponse = NULL;
    char *line;
    char *resp;
    int resplen;

    if (lc == 0)
        return -EIO;

    err = at_send_command_singleline("AT+CGLA=%d,14,\"00A4000C02%.4X\"", "+CGLA:", &atresponse, lc, fileid);
    if (at_get_error_type(err) == AT_ERROR)
        return err;
    if (err != AT_NOERROR)
        return -EINVAL;

    line = atresponse->p_intermediates->line;
    err = at_tok_start(&line);
    if (err < 0)
        goto finally;

    err = at_tok_nextint(&line, &resplen);
    if (err < 0)
        goto finally;

    err = at_tok_nextstr(&line, &resp);
    if (err < 0)
        goto finally;

    /* Std resp code: "9000" */
    if (resplen != 4 || strcmp(resp, "9000") != 0) {
        err = -EIO;
        goto finally;
    }

finally:
    at_response_free(atresponse);
    return err;
}
Ejemplo n.º 20
0
/**
 * RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND
 *
 * Requests to send a SAT/USAT envelope command to SIM.
 * The SAT/USAT envelope command refers to 3GPP TS 11.14 and 3GPP TS 31.111.
 */
void requestStkSendEnvelopeCommand(void *data, size_t datalen, RIL_Token t)
{
    char *cmd;
    char *line;
    char *stkResponse;
    int err;
    ATResponse *atresponse = NULL;
    const char *ec = (const char *) data;

    asprintf(&cmd, "AT*STKE=\"%s\"", ec);
    err = at_send_command_singleline(cmd, "*STKE:", &atresponse);
    free(cmd);

    if (err < 0 || atresponse->success == 0)
        goto error;

    if (atresponse->p_intermediates) {
        line = atresponse->p_intermediates->line;

        err = at_tok_start(&line);
        if (err < 0)
            goto error;

        err = at_tok_nextstr(&line, &stkResponse);
        if (err < 0)
            goto error;

        RIL_onRequestComplete(t, RIL_E_SUCCESS, stkResponse,
                              sizeof(char *));
    } else
        RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0);

  finally:
    at_response_free(atresponse);

    return;

  error:
    RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
    goto finally;
}
Ejemplo n.º 21
0
/**
 * Fetch information about UICC card type (SIM/USIM)
 *
 * \return UICC_Type: type of UICC card.
 */
static UICC_Type getUICCType(void)
{
    ATResponse *atresponse = NULL;
    static UICC_Type UiccType = UICC_TYPE_UNKNOWN;
    int err;

    if (getRadioState() == RADIO_STATE_OFF ||
        getRadioState() == RADIO_STATE_UNAVAILABLE) {
        return UICC_TYPE_UNKNOWN;
    }

    if (UiccType == UICC_TYPE_UNKNOWN) {
        err = at_send_command_singleline("AT+CUAD", "+CUAD:", &atresponse);
        if (err == AT_NOERROR) {
            /* USIM */
            if(strstr(atresponse->p_intermediates->line, USIM_APPLICATION_ID)){
                UiccType = UICC_TYPE_USIM;
                ALOGI("Detected card type USIM - stored");
            } else {
                /* should maybe be unknown */
                UiccType = UICC_TYPE_SIM;
            }
        } else if (at_get_error_type(err) != AT_ERROR) {
            /* Command failed - unknown card */
            UiccType = UICC_TYPE_UNKNOWN;
            ALOGE("%s() Failed to detect card type - Retry at next request", __func__);
        } else {
            /* Legacy SIM */
            /* TODO: CUAD only responds OK if SIM is inserted.
             *       This is an inccorect AT response...
             */
            UiccType = UICC_TYPE_SIM;
            ALOGI("Detected card type Legacy SIM - stored");
        }
        at_response_free(atresponse);
    }

    return UiccType;
}
Ejemplo n.º 22
0
/**
 * Get the number of retries left for pin functions
 */
static int getNumRetries (int request) {
    ATResponse *atresponse = NULL;
    int err;
    int num_retries = -1;

    err = at_send_command_singleline("AT*EPIN?", "*EPIN:", &atresponse);
    if (err != AT_NOERROR) {
        ALOGE("%s() AT*EPIN error", __func__);
        return -1;
    }

    switch (request) {
    case RIL_REQUEST_ENTER_SIM_PIN:
    case RIL_REQUEST_CHANGE_SIM_PIN:
        sscanf(atresponse->p_intermediates->line, "*EPIN: %d",
               &num_retries);
        break;
    case RIL_REQUEST_ENTER_SIM_PUK:
        sscanf(atresponse->p_intermediates->line, "*EPIN: %*d,%d",
               &num_retries);
        break;
    case RIL_REQUEST_ENTER_SIM_PIN2:
    case RIL_REQUEST_CHANGE_SIM_PIN2:
        sscanf(atresponse->p_intermediates->line, "*EPIN: %*d,%*d,%d",
               &num_retries);
        break;
    case RIL_REQUEST_ENTER_SIM_PUK2:
        sscanf(atresponse->p_intermediates->line, "*EPIN: %*d,%*d,%*d,%d",
               &num_retries);
        break;
    default:
        num_retries = -1;
    break;
    }

    at_response_free(atresponse);
    return num_retries;
}
Ejemplo n.º 23
0
	/**
	 * RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE
	 *
	 * Query current network selectin mode.
	 ok
	 */
void requestQueryNetworkSelectionMode(
		void *data, size_t datalen, RIL_Token t)
{
	int err;
	ATResponse *p_response = NULL;
	int response = 0;
	char *line;


	err = at_send_command_singleline("AT+COPS?", "+COPS:", &p_response);

	if (err < 0 || p_response->success == 0) {
		goto error;
	}

	line = p_response->p_intermediates->line;

	err = at_tok_start(&line);

	if (err < 0) {
		goto error;
	}

	err = at_tok_nextint(&line, &response);

	if (err < 0) {
		goto error;
	}

	RIL_onRequestComplete(t, RIL_E_SUCCESS, &response, sizeof(int));
	at_response_free(p_response);
	return;
error:
	at_response_free(p_response);
	LOGE("requestQueryNetworkSelectionMode must never return error when radio is on");
	RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
}
Ejemplo n.º 24
0
/**  
 * RIL_REQUEST_GET_CLIR
 *
 * Gets current CLIR status.
 ok
 */
void requestGetCLIR(void *data, size_t datalen, RIL_Token t)
{
	ATResponse *p_response;
	p_response = NULL;
	int response[2] = {1, 1};

	int err = at_send_command_singleline("AT+CLIR?",
			"+CLIR: ", &p_response);
	if (err >= 0 && p_response->success) {
		char *line = p_response->p_intermediates->line;

		err = at_tok_start(&line);

		if (err >= 0) {
			err = at_tok_nextint(&line, &response[0]);

			if (err >= 0)
				err = at_tok_nextint(&line, &response[1]);
		}

	}
	RIL_onRequestComplete(t, RIL_E_SUCCESS, response, sizeof(response));
	at_response_free(p_response);
}
static char *getCharEncoding(void)
{
    int err;
    char *line, *chSet;
    char *result = NULL;
    ATResponse *p_response = NULL;
    err = at_send_command_singleline("AT+CSCS?", "+CSCS:", &p_response);

    if (err != AT_NOERROR) {
        LOGE("%s() Failed to read AT+CSCS?", __func__);
        return NULL;
    }

    line = p_response->p_intermediates->line;
    err = at_tok_start(&line);
    if (err < 0) {
        at_response_free(p_response);
        return NULL;
    }

    err = at_tok_nextstr(&line, &chSet);
    if (err < 0) {
        at_response_free(p_response);
        return NULL;
    }

    /* If not any of the listed below, assume UCS-2 */
    if (!strcmp(chSet, "GSM") || !strcmp(chSet, "IRA")
            || !strncmp(chSet, "8859", 4) || !strcmp(chSet, "UTF-8")) {
        result = strdup(chSet);
    } else
        result = strdup("UCS-2");

    at_response_free(p_response);
    return result;
}
Ejemplo n.º 26
0
void requestLastCallFailCause(void *data, size_t datalen, RIL_Token t)
{
	/* MTK proprietary start */
	int callFailCause;
	char *line;
	int ret;
	ATResponse *p_response = NULL;

	//Solve [ALPS00242104]Invalid number show but cannot call drop when dial VT call in 2G network
	//mtk04070, 2012.02.24
	if (bUseLocalCallFailCause == 1) {
	   callFailCause = dialLastError;
	   LOGD("Use local call fail cause = %d", callFailCause);
	}
	else {
 	   ret = at_send_command_singleline("AT+CEER", "+CEER:", &p_response, CC_CHANNEL_CTX);

	   if (ret < 0 || p_response->success == 0)
		   goto error;

	   line = p_response->p_intermediates->line;

	   ret = at_tok_start(&line);

	   if (ret < 0)
		   goto error;

	   ret = at_tok_nextint(&line, &callFailCause);

	   if (ret < 0)
		   goto error;

	   LOGD("MD fail cause = %d", callFailCause);
	}

	/*if there are more causes need to be translated in the future,
	 * discussing with APP owner to implement this in upper layer.
	 * For the hard coded value, please refer to modem code.*/

	if (callFailCause == 10 || callFailCause == 8)
		callFailCause = CALL_FAIL_CALL_BARRED;
	else if (callFailCause == 2600)
		callFailCause = CALL_FAIL_FDN_BLOCKED;
	else if (callFailCause == 2052)
		callFailCause = CALL_FAIL_IMSI_UNKNOWN_IN_VLR;
	else if (callFailCause == 2053)
		callFailCause = CALL_FAIL_IMEI_NOT_ACCEPTED;
	else if ((callFailCause > 127 && callFailCause != 2165) || callFailCause <= 0)
		callFailCause = CALL_FAIL_ERROR_UNSPECIFIED;

	LOGD("RIL fail cause = %d", callFailCause);
	RIL_onRequestComplete(t, RIL_E_SUCCESS, &callFailCause, sizeof(int));
	if (NULL != p_response) 
	{
		at_response_free(p_response);
	}
	return;

error:
	RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
	if (NULL != p_response) 
	{
	    at_response_free(p_response);
	}
	/* MTK proprietary end */
}
Ejemplo n.º 27
0
char *getNetworkType(int def){
    int network = def;
    int err;
    int gsm_rinfo, umts_rinfo, skip;
    int ul, dl;
    int networkType;
    char *line;
    ATResponse *p_response;

    err = at_send_command_singleline("AT*ERINFO?", "*ERINFO:",
                                     &p_response);

    if (err != AT_NOERROR)
        return NULL;

    line = p_response->p_intermediates->line;
    err = at_tok_start(&line);
    if (err < 0)
            goto finally;

    err = at_tok_nextint(&line, &skip);
    if (err < 0)
            goto finally;

    err = at_tok_nextint(&line, &gsm_rinfo);
    if (err < 0)
            goto finally;

    err = at_tok_nextint(&line, &umts_rinfo);
    if (err < 0)
            goto finally;

    at_response_free(p_response);

    if (umts_rinfo > ERINFO_UMTS_NO_UMTS_HSDPA && getE2napState() == E2NAP_ST_CONNECTED) {

        err = at_send_command_singleline("AT+CGEQNEG=%d", "+CGEQNEG:", &p_response, RIL_CID_IP);

        if (err != AT_NOERROR)
            LOGE("%s() Allocation for, or sending, CGEQNEG failed."
	         "Using default value specified by calling function", __func__);
        else {
            line = p_response->p_intermediates->line;
            err = at_tok_start(&line);
            if (err < 0)
                goto finally;

            err = at_tok_nextint(&line, &skip);
            if (err < 0)
                goto finally;

            err = at_tok_nextint(&line, &skip);
            if (err < 0)
                goto finally;

            err = at_tok_nextint(&line, &ul);
            if (err < 0)
                goto finally;

            err = at_tok_nextint(&line, &dl);
            if (err < 0)
                goto finally;

            at_response_free(p_response);
            LOGI("Max speed %i/%i, UL/DL", ul, dl);

            network = CGREG_ACT_UTRAN;
            if (dl > 384)
                network = CGREG_ACT_UTRAN_HSDPA;
            if (ul > 384)
                network = CGREG_ACT_UTRAN_HSUPA_HSDPA;
            if (dl > 14400)
                network = CGREG_ACT_UTRAN_HSPAP;
        }
    }
    else if (gsm_rinfo) {
        LOGD("%s() Using 2G info: %d", __func__, gsm_rinfo);
        if (gsm_rinfo == 1)
            network = CGREG_ACT_GSM;
        else
            network = CGREG_ACT_GSM_EGPRS;
    }

    switch (network) {
    case CGREG_ACT_GSM:
        networkType = RADIO_TECH_GPRS;
        break;
    case CGREG_ACT_UTRAN:
        networkType = RADIO_TECH_UMTS;
        break;
    case CGREG_ACT_GSM_EGPRS:
        networkType = RADIO_TECH_EDGE;
        break;
    case CGREG_ACT_UTRAN_HSDPA:
        networkType = RADIO_TECH_HSDPA;
        break;
    case CGREG_ACT_UTRAN_HSUPA:
        networkType = RADIO_TECH_HSUPA; /* Note: Not used */
        break;
    case CGREG_ACT_UTRAN_HSUPA_HSDPA:
        networkType = RADIO_TECH_HSPA;
        break;
    case CGREG_ACT_UTRAN_HSPAP:
        networkType = RADIO_TECH_HSPAP;
        break;
    default:
        networkType = RADIO_TECH_UNKNOWN;
        break;
    }
    char *resp;
    asprintf(&resp, "%d", networkType);
    return resp;

finally:
    at_response_free(p_response);
    return NULL;
}
Ejemplo n.º 28
0
/**
 * RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC
 *
 * Specify that the network should be selected automatically.
*/
void requestSetNetworkSelectionAutomatic(void *data, size_t datalen,
                                         RIL_Token t)
{
    (void) data; (void) datalen;
    int err = 0;
    ATResponse *atresponse = NULL;
    int mode = 0;
    int skip;
    char *line;
    char *operator = NULL;
    struct operatorPollParams *poll_params = NULL;

    poll_params = malloc(sizeof(struct operatorPollParams));
    if (NULL == poll_params)
        goto error;

    /* First check if we are already scanning or in manual mode */
    err = at_send_command_singleline("AT+COPS=3,2;+COPS?", "+COPS:", &atresponse);
    if (err != AT_NOERROR)
        goto error;

    line = atresponse->p_intermediates->line;

    err = at_tok_start(&line);
    if (err < 0)
        goto error;

    /* Read network selection mode */
    err = at_tok_nextint(&line, &mode);
    if (err < 0)
        goto error;

    /* If we're unregistered, we may just get
       a "+COPS: 0" response. */
    if (!at_tok_hasmore(&line)) {
        if (mode == 1) {
            LOGD("%s() Changing manual to automatic network mode", __func__);
            goto do_auto;
        } else
            goto check_reg;
    }

    err = at_tok_nextint(&line, &skip);
    if (err < 0)
        goto error;

    /* A "+COPS: 0, n" response is also possible. */
    if (!at_tok_hasmore(&line)) {
        if (mode == 1) {
            LOGD("%s() Changing manual to automatic network mode", __func__);
            goto do_auto;
        } else
            goto check_reg;
    }

    /* Read numeric operator */
    err = at_tok_nextstr(&line, &operator);
    if (err < 0)
        goto error;

    /* If operator is found then do a new scan,
       else let it continue the already pending scan */
    if (operator && strlen(operator) == 0) {
        if (mode == 1) {
            LOGD("%s() Changing manual to automatic network mode", __func__);
            goto do_auto;
        } else
            goto check_reg;
    }

    /* Operator found */
    if (mode == 1) {
        LOGD("%s() Changing manual to automatic network mode", __func__);
        goto do_auto;
    } else {
        LOGD("%s() Already in automatic mode with known operator, trigger a new network scan",
	    __func__);
        goto do_auto;
    }

    /* Check if module is scanning,
       if not then trigger a rescan */
check_reg:
    at_response_free(atresponse);
    atresponse = NULL;

    /* Check CS domain first */
    err = at_send_command_singleline("AT+CREG?", "+CREG:", &atresponse);
    if (err != AT_NOERROR)
        goto error;

    line = atresponse->p_intermediates->line;

    err = at_tok_start(&line);
    if (err < 0)
        goto error;

    /* Read registration unsolicited mode */
    err = at_tok_nextint(&line, &mode);
    if (err < 0)
        goto error;

    /* Read registration status */
    err = at_tok_nextint(&line, &mode);
    if (err < 0)
        goto error;

    /* If scanning has stopped, then perform a new scan */
    if (mode == 0) {
        LOGD("%s() Already in automatic mode, but not currently scanning on CS,"
	     "trigger a new network scan", __func__);
        goto do_auto;
    }

    /* Now check PS domain */
    at_response_free(atresponse);
    atresponse = NULL;
    err = at_send_command_singleline("AT+CGREG?", "+CGREG:", &atresponse);
    if (err != AT_NOERROR)
        goto error;

    line = atresponse->p_intermediates->line;

    err = at_tok_start(&line);
    if (err < 0)
        goto error;

    /* Read registration unsolicited mode */
    err = at_tok_nextint(&line, &mode);
    if (err < 0)
        goto error;

    /* Read registration status */
    err = at_tok_nextint(&line, &mode);
    if (err < 0)
        goto error;

    /* If scanning has stopped, then perform a new scan */
    if (mode == 0) {
        LOGD("%s() Already in automatic mode, but not currently scanning on PS,"
	     "trigger a new network scan", __func__);
        goto do_auto;
    }
    else
    {
        LOGD("%s() Already in automatic mode and scanning", __func__);
        goto finish_scan;
    }

do_auto:
    at_response_free(atresponse);
    atresponse = NULL;

    /* This command does two things, one it sets automatic mode,
       two it starts a new network scan! */
    err = at_send_command("AT+COPS=0");
    if (err != AT_NOERROR)
        goto error;

finish_scan:

    at_response_free(atresponse);
    atresponse = NULL;

    poll_params->loopcount = 0;
    poll_params->t = t;

    enqueueRILEvent(RIL_EVENT_QUEUE_NORMAL, pollOperatorSelected,
                    poll_params, &TIMEVAL_OPERATOR_SELECT_POLL);

    return;

error:
    free(poll_params);
    at_response_free(atresponse);
    RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
    return;
}
Ejemplo n.º 29
0
int getSignalStrength(RIL_SignalStrength_v6 *signalStrength){
    ATResponse *atresponse = NULL;
    int err;
    char *line;
    int ber;
    int rssi;

    memset(signalStrength, 0, sizeof(RIL_SignalStrength_v6));

    signalStrength->LTE_SignalStrength.signalStrength = -1;
    signalStrength->LTE_SignalStrength.rsrp = -1;
    signalStrength->LTE_SignalStrength.rsrq = -1;
    signalStrength->LTE_SignalStrength.rssnr = -1;
    signalStrength->LTE_SignalStrength.cqi = -1;

    err = at_send_command_singleline("AT+CSQ", "+CSQ:", &atresponse);

    if (err != AT_NOERROR)
        goto cind;
    
    line = atresponse->p_intermediates->line;

    err = at_tok_start(&line);
    if (err < 0)
        goto cind;

    err = at_tok_nextint(&line,&rssi);
    if (err < 0)
        goto cind;
    signalStrength->GW_SignalStrength.signalStrength = rssi;

    err = at_tok_nextint(&line, &ber);
    if (err < 0)
        goto cind;
    signalStrength->GW_SignalStrength.bitErrorRate = ber;

    at_response_free(atresponse);
    atresponse = NULL;
    /*
     * If we get 99 as signal strength. Try AT+CIND to give
     * some indication on what signal strength we got.
     *
     * Android calculates rssi and dBm values from this value, so the dBm
     * value presented in android will be wrong, but this is an error on
     * android's end.
     */
    if (rssi == 99) {
cind:
        at_response_free(atresponse);
        atresponse = NULL;

        err = at_send_command_singleline("AT+CIND?", "+CIND:", &atresponse);
        if (err != AT_NOERROR)
            goto error;

        line = atresponse->p_intermediates->line;

        err = at_tok_start(&line);
        if (err < 0)
            goto error;

        /* discard the first value */
        err = at_tok_nextint(&line,
                             &signalStrength->GW_SignalStrength.signalStrength);
        if (err < 0)
            goto error;

        err = at_tok_nextint(&line,
                             &signalStrength->GW_SignalStrength.signalStrength);
        if (err < 0)
            goto error;

        signalStrength->GW_SignalStrength.bitErrorRate = 99;

        /* Convert CIND value so Android understands it correctly */
        if (signalStrength->GW_SignalStrength.signalStrength > 0) {
            signalStrength->GW_SignalStrength.signalStrength *= 4;
            signalStrength->GW_SignalStrength.signalStrength--;
        }
    }

    at_response_free(atresponse);
    return 0;

error:
    at_response_free(atresponse);
    return -1;
}
Ejemplo n.º 30
0
/**
 * RIL_REQUEST_NEIGHBORINGCELL_IDS
 */
void requestNeighboringCellIDs(void *data, size_t datalen, RIL_Token t)
{
    (void) data; (void) datalen;
    int network = -1;
    int dummy = 0;
    char *dummyStr = NULL;
    int err = 0;
    ATResponse *cops_resp = NULL;
    char *line = NULL;

    /* Determine network radio access technology (AcT) */
    err = at_send_command_singleline("AT+COPS?", "+COPS:", &cops_resp);
    if (err < 0 || cops_resp->success == 0) goto error;

    line = cops_resp->p_intermediates->line;

    err = at_tok_start(&line);
    if (err < 0) goto error;
    /* Mode */
    err = at_tok_nextint(&line, &dummy);
    if (err < 0) goto error;
    /* Check to see if not registered */
    if (!at_tok_hasmore(&line)) {
        No_NCIs(t);
        goto finally;
    }
    /* Format */
    err = at_tok_nextint(&line, &dummy);
    if (err < 0) goto error;
    /* Operator */
    err = at_tok_nextstr(&line, &dummyStr);
    if (err < 0) goto error;
    /* Network */
    err = at_tok_nextint(&line, &network);
    if (err < 0) goto error;

    switch (network) {
    case 0:                    /* GSM (GPRS,2G)*/
    case 3:                    /* GSM w/EGPRS (EDGE, 2.75G)*/
        Get_GSM_NCIs(t);
        break;
    case 1:                    /* GSM Compact (Not supported)*/
        goto error;
        break;
    case 2:                    /* UTRAN (WCDMA/UMTS, 3G)*/
    case 4:                    /* UTRAN w/HSDPA (HSDPA,3G)*/
    case 5:                    /* UTRAN w/HSUPA (HSUPA,3G)*/
    case 6:                    /* UTRAN w/HSDPA and HSUPA (HSPA,3G)*/
        Get_WCDMA_NCIs(t);
        break;
    default:
        goto error;
    }

finally:
    at_response_free(cops_resp);
    return;

error:
    RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0);
    goto finally;
}