Пример #1
0
static void processLine(const char *line)
{
    pthread_mutex_lock(&s_commandmutex);

    if (sp_response == NULL) {
        /* no command pending */
        handleUnsolicited(line);
    } else if (isFinalResponseSuccess(line)) {
        sp_response->success = 1;
        handleFinalResponse(line);
    } else if (isFinalResponseError(line)) {
        sp_response->success = 0;
        handleFinalResponse(line);
    } else if (s_smsPDU != NULL && 0 == strcmp(line, "> ")) {
        // See eg. TS 27.005 4.3
        // Commands like AT+CMGS have a "> " prompt
        writeCtrlZ(s_smsPDU);
        s_smsPDU = NULL;
    } else switch (s_type) {
        case NO_RESULT:
            handleUnsolicited(line);
            break;
        case NUMERIC:
            if (sp_response->p_intermediates == NULL
                && isdigit(line[0])
            ) {
                addIntermediate(line);
            } else {
                /* either we already have an intermediate response or
                   the line doesn't begin with a digit */
                handleUnsolicited(line);
            }
            break;
        case SINGLELINE:
            if (sp_response->p_intermediates == NULL
                && strStartsWith (line, s_responsePrefix)
            ) {
                addIntermediate(line);
            } else {
                /* we already have an intermediate response */
                handleUnsolicited(line);
            }
            break;
        case MULTILINE:
            if (strStartsWith (line, s_responsePrefix)) {
                addIntermediate(line);
            } else {
                handleUnsolicited(line);
            }
        break;

        default: /* this should never be reached */
            RLOGE("Unsupported AT command type %d\n", s_type);
            handleUnsolicited(line);
        break;
    }

    pthread_mutex_unlock(&s_commandmutex);
}
Пример #2
0
static void processLine(const char *line)
{
    struct atcontext *ac = getAtContext();
    pthread_mutex_lock(&ac->commandmutex);

    if (ac->response == NULL) {
        /* No command pending. */
        handleUnsolicited(line);
    } else if (isFinalResponseSuccess(line)) {
        ac->response->success = 1;
        handleFinalResponse(line);
    } else if (isFinalResponseError(line)) {
        ac->response->success = 0;
        handleFinalResponse(line);
    } else if (ac->smsPDU != NULL && 0 == strcmp(line, "> ")) {
        /* See eg. TS 27.005 4.3.
           Commands like AT+CMGS have a "> " prompt. */
        writeCtrlZ(ac->smsPDU);
        ac->smsPDU = NULL;
    } else switch (ac->type) {
        case NO_RESULT:
            handleUnsolicited(line);
            break;
        case NUMERIC:
            if (ac->response->p_intermediates == NULL
                && isdigit(line[0])) {
                addIntermediate(line);
            } else {
                /* Either we already have an intermediate response or
                   the line doesn't begin with a digit. */
                handleUnsolicited(line);
            }
            break;
        case SINGLELINE:
            if (ac->response->p_intermediates == NULL
                && strStartsWith (line, ac->responsePrefix)) {
                addIntermediate(line);
            } else {
                /* We already have an intermediate response. */
                handleUnsolicited(line);
            }
            break;
        case MULTILINE:
            if (strStartsWith (line, ac->responsePrefix)) {
                addIntermediate(line);
            } else {
                handleUnsolicited(line);
            }
        break;

        default: /* This should never be reached */
            ALOGE("%s() Unsupported AT command type %d", __func__, ac->type);
            handleUnsolicited(line);
        break;
    }

    pthread_mutex_unlock(&ac->commandmutex);
}
Пример #3
0
static AT_Error at_get_error(const ATResponse *p_response)
{
    int ret;
    int err;
    char *p_cur;

    if (p_response == NULL)
        return merror(GENERIC_ERROR, GENERIC_ERROR_UNSPECIFIED);

    if (p_response->success > 0) {
        return AT_NOERROR;
    }

    if (p_response->finalResponse == NULL)
        return AT_ERROR_INVALID_RESPONSE;


    if (isFinalResponseSuccess(p_response->finalResponse))
        return AT_NOERROR;

    p_cur = p_response->finalResponse;
    err = at_tok_start(&p_cur);
    if (err < 0)
        return merror(GENERIC_ERROR, GENERIC_ERROR_UNSPECIFIED);

    err = at_tok_nextint(&p_cur, &ret);
    if (err < 0)
        return merror(GENERIC_ERROR, GENERIC_ERROR_UNSPECIFIED);

    if(strStartsWith(p_response->finalResponse, "+CME ERROR:"))
        return merror(CME_ERROR, ret);
    else if (strStartsWith(p_response->finalResponse, "+CMS ERROR:"))
        return merror(CMS_ERROR, ret);
    else if (strStartsWith(p_response->finalResponse, "ERROR:"))
        return merror(GENERIC_ERROR, GENERIC_ERROR_RESPONSE);
    else if (strStartsWith(p_response->finalResponse, "+NO CARRIER:"))
        return merror(GENERIC_ERROR, GENERIC_NO_CARRIER_RESPONSE);
    else if (strStartsWith(p_response->finalResponse, "+NO ANSWER:"))
        return merror(GENERIC_ERROR, GENERIC_NO_ANSWER_RESPONSE);
    else if (strStartsWith(p_response->finalResponse, "+NO DIALTONE:"))
        return merror(GENERIC_ERROR, GENERIC_NO_DIALTONE_RESPONSE);
    else
        return merror(GENERIC_ERROR, GENERIC_ERROR_UNSPECIFIED);
}
Пример #4
0
/**
 * returns 1 if line is a final response, either  error or success
 * See 27.007 annex B
 * WARNING: NO CARRIER and others are sometimes unsolicited
 */
static int isFinalResponse(const char *line)
{
    return isFinalResponseSuccess(line) || isFinalResponseError(line);
}
Пример #5
0
static void processLine(const char *line, RILChannelCtx *p_channel)
{
	ATResponse *p_response = p_channel->p_response;
	const char *smsPDU = p_channel->smsPDU;
	//Move out to the function
	//pthread_mutex_lock(&p_channel->commandmutex);
	int isIntermediateResult = 0;

	if (p_response == NULL) {
		/* no command pending */
		handleUnsolicited(line, p_channel);
		return;
	} else {
		switch (p_channel->type) {
		case NO_RESULT:
			//handleUnsolicited(line,p_channel);
			break;
		case NUMERIC:
			if (p_response->p_intermediates == NULL
			    && isdigit(line[0])
			    ) {
				addIntermediate(line, p_channel);
				isIntermediateResult = 1;
			} else {
				/* either we already have an intermediate response or
				 *     the line doesn't begin with a digit */
				//handleUnsolicited(line,p_channel);
			}
			break;
		case SINGLELINE:
			if (p_response->p_intermediates == NULL
			    && strStartsWith(line, p_channel->responsePrefix)
			    ) {
				addIntermediate(line, p_channel);
				isIntermediateResult = 1;
			} else {
				/* we already have an intermediate response */
				//handleUnsolicited(line,p_channel);
			}
			break;
		case MULTILINE:
			if (strStartsWith(line, p_channel->responsePrefix)) {
				addIntermediate(line, p_channel);
				isIntermediateResult = 1;
			} else {
				//handleUnsolicited(line,p_channel);
			}
			break;
		/* atci start */
		case RAW:
			if (!isFinalResponseSuccess(line) && !isFinalResponseErrorEx(line, p_channel) && !isIntermediatePattern(line) ) {
				addIntermediate(line, p_channel);
				isIntermediateResult = 1;
			}
			break;
		/* atci end */
		default: /* this should never be reached */
			RLOGE("Unsupported AT command type %d\n", p_channel->type);
			//handleUnsolicited(line,p_channel);
			break;
		}
	}

	if (isIntermediateResult) {
		/* No need to run the following code*/
	} else if (isFinalResponseSuccess(line)) {
		p_response->success = 1;
		handleFinalResponse(line, p_channel);
	} else if (isFinalResponseErrorEx(line, p_channel)) {
		p_response->success = 0;
		handleFinalResponse(line, p_channel);
	} else if (smsPDU != NULL && 0 == strcmp(line, "> ")) {
		// See eg. TS 27.005 4.3
		// Commands like AT+CMGS have a "> " prompt
		writeCtrlZ(smsPDU, p_channel);
		smsPDU = NULL;
	} else if (isIntermediatePattern(line)) {
		p_response->success = 1;
		handleFinalResponse(line, p_channel);
	} else {
		handleUnsolicited(line, p_channel);
	}
	// Move out to the function
	//pthread_mutex_unlock(&p_channel->commandmutex);
}