Esempio n. 1
0
static inline int at_response (pvt_t* pvt, int iovcnt, at_res_t at_res)
{
	char*		str;
	size_t		len;
	at_queue_t*	e;

	if (iovcnt > 0)
	{
		len = pvt->d_read_iov[0].iov_len + pvt->d_read_iov[1].iov_len - 1;

		if (iovcnt == 2)
		{
			ast_debug (5, "[%s] iovcnt == 2\n", pvt->id);

			if (len > sizeof (pvt->d_parse_buf) - 1)
			{
				ast_debug (1, "[%s] buffer overflow\n", pvt->id);
				return -1;
			}

			str = pvt->d_parse_buf;

			memmove (str,					pvt->d_read_iov[0].iov_base, pvt->d_read_iov[0].iov_len);
			memmove (str + pvt->d_read_iov[0].iov_len,	pvt->d_read_iov[1].iov_base, pvt->d_read_iov[1].iov_len);
		}
		else
		{
			str = pvt->d_read_iov[0].iov_base;
		}

		str[len] = '\0';

//		ast_debug (5, "[%s] [%.*s]\n", pvt->id, (int) len, str);

		switch (at_res)
		{
			case RES_BOOT:
			case RES_CONF:
			case RES_CSSI:
			case RES_CSSU:
			case RES_RING:
			case RES_SRVST:
				break;

			case RES_OK:
				return at_response_ok (pvt);

			case RES_RSSI:
				return at_response_rssi (pvt, str, len);

			case RES_MODE:
				/* An error here is not fatal. Just keep going. */
				at_response_mode (pvt, str, len);
				break;

			case RES_ORIG:
				return at_response_orig (pvt, str, len);

			case RES_CEND:
				return at_response_cend (pvt, str, len);

			case RES_CONN:
				return at_response_conn (pvt);

			case RES_CREG:
				/* An error here is not fatal. Just keep going. */
				at_response_creg (pvt, str, len);
				break;

			case RES_COPS:
				/* An error here is not fatal. Just keep going. */
				at_response_cops (pvt, str, len);
				break;



			case RES_CSQ:
				return at_response_csq (pvt, str, len);

			case RES_CMS_ERROR:
			case RES_ERROR:
				return at_response_error (pvt);

			case RES_SMMEMFULL:
				return at_response_smmemfull (pvt);

			case RES_CLIP:
				return at_response_clip (pvt, str, len);

			case RES_CMTI:
				return at_response_cmti (pvt, str, len);

			case RES_CMGR:
				return at_response_cmgr (pvt, str, len);

			case RES_SMS_PROMPT:
				return at_response_sms_prompt (pvt);

			case RES_CUSD:
				return at_response_cusd (pvt, str, len);

			case RES_BUSY:
				return at_response_busy (pvt);

			case RES_NO_DIALTONE:
				return at_response_no_dialtone (pvt);

			case RES_NO_CARRIER:
				return at_response_no_carrier (pvt);

			case RES_CPIN:
				return at_response_cpin (pvt, str, len);

			case RES_CNUM:
				/* An error here is not fatal. Just keep going. */
				at_response_cnum (pvt, str, len);
				break;

			case RES_PARSE_ERROR:
				ast_log (LOG_ERROR, "[%s] Error parsing result\n", pvt->id);
				return -1;

			case RES_UNKNOWN:
				if ((e = at_fifo_queue_head (pvt)))
				{
					switch (e->cmd)
					{
						case CMD_AT_CGMI:
							ast_debug (1, "[%s] Got AT_CGMI data (manufacturer info)\n", pvt->id);
							return at_response_cgmi (pvt, str, len);

						case CMD_AT_CGMM:
							ast_debug (1, "[%s] Got AT_CGMM data (model info)\n", pvt->id);
							return at_response_cgmm (pvt, str, len);

						case CMD_AT_CGMR:
							ast_debug (1, "[%s] Got AT+CGMR data (firmware info)\n", pvt->id);
							return at_response_cgmr (pvt, str, len);

						case CMD_AT_CGSN:
							ast_debug (1, "[%s] Got AT+CGSN data (IMEI number)\n", pvt->id);
							return at_response_cgsn (pvt, str, len);

						case CMD_AT_CIMI:
							ast_debug (1, "[%s] Got AT+CIMI data (IMSI number)\n", pvt->id);
							return at_response_cimi (pvt, str, len);

						default:
							ast_debug (1, "[%s] Ignoring unknown result: '%.*s'\n", pvt->id, (int) len, str);
							break;
					}
				}
				else
				{
					ast_debug (1, "[%s] Ignoring unknown result: '%.*s'\n", pvt->id, (int) len, str);
				}

				break;
		}
	}

	return 0;
}
Esempio n. 2
0
int CardDevice::at_response(char* str, at_res_t at_res)
{
    size_t len = strlen(str);

    switch(at_res)
    {
	case RES_BOOT:
	case RES_CONF:
	case RES_CSSI:
	case RES_CSSU:
	case RES_SRVST:
	    return 0;

	case RES_OK:
	    return at_response_ok();

	case RES_RSSI:
	    return at_response_rssi(str, len);

	case RES_MODE:
	    /* An error here is not fatal. Just keep going. */
	    at_response_mode(str, len);
	    return 0;

	case RES_ORIG:
	    return at_response_orig(str, len);

	case RES_CEND:
	    return at_response_cend(str, len);

	case RES_CONN:
	    return at_response_conn(str, len);

	case RES_CREG:
	    /* An error here is not fatal. Just keep going. */
	    at_response_creg(str, len);
	    return 0;

	case RES_COPS:
	    /* An error here is not fatal. Just keep going. */
	    at_response_cops(str, len);
	    return 0;

	case RES_CSQ:
	    return at_response_csq(str, len);

	case RES_CMS_ERROR:
	case RES_ERROR:
	    return at_response_error();

	case RES_RING:
	    return at_response_ring();

	case RES_SMMEMFULL:
	    return at_response_smmemfull();

	case RES_CLIP:
	    return at_response_clip(str, len);

	case RES_CMTI:
	    return at_response_cmti(str, len);

	case RES_CMGR:
	    return at_response_cmgr(str, len);

	case RES_SMS_PROMPT:
	    return at_response_sms_prompt();

	case RES_CUSD:
	    return at_response_cusd(str, len);

	case RES_BUSY:
	    return at_response_busy();

	case RES_NO_DIALTONE:
	    return at_response_no_dialtone();

	case RES_NO_CARRIER:
	    return at_response_no_carrier();

	case RES_CPIN:
	    return at_response_cpin(str, len);

	case RES_CNUM:
	    /* An error here is not fatal. Just keep going. */
	    at_response_cnum(str, len);
	    return 0;

	case RES_PARSE_ERROR:
	    Debug(DebugAll, "[%s] Error parsing result", c_str());
	    return -1;

	case RES_UNKNOWN:
	    if (m_lastcmd)
	    {
		switch(m_lastcmd->m_cmd)
		{
		    case CMD_AT_CGMI:
			Debug(DebugAll,  "[%s] Got AT_CGMI data (manufacturer info)", c_str());
			return at_response_cgmi(str, len);
		    case CMD_AT_CGMM:
			Debug(DebugAll,  "[%s] Got AT_CGMM data (model info)", c_str());
			return at_response_cgmm(str, len);
		    case CMD_AT_CGMR:
			Debug(DebugAll,  "[%s] Got AT+CGMR data (firmware info)", c_str());
			return at_response_cgmr(str, len);
		    case CMD_AT_CGSN:
			Debug(DebugAll,  "[%s] Got AT+CGSN data (IMEI number)", c_str());
			return at_response_cgsn (str, len);
		    case CMD_AT_CIMI:
			Debug(DebugAll,  "[%s] Got AT+CIMI data (IMSI number)", c_str());
			return at_response_cimi(str, len);
		    case CMD_AT_CMGR:
			Debug(DebugAll,  "[%s] Got AT+CMGR data (SMS PDU data)", c_str());
			return at_response_pdu(str, len);
		    default:
			Debug(DebugAll, "[%s] Ignoring unknown result: '%.*s'", c_str(), (int) len, str);
			break;
		}
	    }
	    else
	    {
		Debug(DebugAll, "[%s] Ignoring unknown result: '%.*s'", c_str(), (int) len, str);
	    }
	    break;
	}
	return 0;
}