Exemplo n.º 1
0
static inline int at_response_sms_prompt (pvt_t* pvt)
{
	at_queue_t* e;

	if ((e = at_fifo_queue_head (pvt)) && e->res == RES_SMS_PROMPT)
	{
		if (e->ptype != 0 || !e->param.data || at_send_sms_text (pvt, e->param.data) || at_fifo_queue_add (pvt, CMD_AT_CMGS, RES_OK))
		{
			ast_log (LOG_ERROR, "[%s] Error sending sms message\n", pvt->id);
			return -1;
		}

		at_fifo_queue_rem (pvt);
	}
	else if (e)
	{
		ast_log (LOG_ERROR, "[%s] Received sms prompt when expecting '%s' response to '%s', ignoring\n", pvt->id,
				at_res2str (e->res), at_cmd2str (e->cmd));
	}
	else
	{
		ast_log (LOG_ERROR, "[%s] Received unexpected sms prompt\n", pvt->id);
	}

	return 0;
}
Exemplo n.º 2
0
static inline void at_fifo_queue_rem (pvt_t* pvt)
{
	at_queue_t* e = AST_LIST_REMOVE_HEAD (&pvt->at_queue, entry);

	if (e)
	{
		ast_debug (4, "[%s] remove command '%s' expected response '%s'\n", pvt->id,
							at_cmd2str (e->cmd), at_res2str (e->res));

		if (e->ptype == 0 && e->param.data)
		{
			ast_free (e->param.data);
		}

		ast_free (e);
	}
}
Exemplo n.º 3
0
static int at_fifo_queue_add_num (pvt_t* pvt, at_cmd_t cmd, at_res_t res, int num)
{
	at_queue_t* e;

	if (!(e = ast_calloc (1, sizeof(*e))))
	{
		return -1;
	}

	e->cmd		= cmd;
	e->res		= res;
	e->ptype	= 1;
	e->param.num	= num;

	AST_LIST_INSERT_TAIL (&pvt->at_queue, e, entry);

	ast_debug (4, "[%s] add command '%s' expected response '%s'\n", pvt->id,
							 at_cmd2str (e->cmd), at_res2str (e->res));

	return 0;
}
Exemplo n.º 4
0
static inline int at_response_error (pvt_t* pvt)
{
	at_queue_t* e;

	if ((e = at_fifo_queue_head (pvt)) && (e->res == RES_OK || e->res == RES_ERROR ||
			e->res == RES_CMS_ERROR || e->res == RES_CMGR || e->res == RES_SMS_PROMPT))
	{
		switch (e->cmd)
		{
        		/* initilization stuff */
			case CMD_AT_Z:
			case CMD_AT_E:
			case CMD_AT_CURC:
			case CMD_AT_U2DIAG:
			case CMD_AT_CSQ:
				ast_log (LOG_ERROR, "[%s] Command '%s' failed\n", pvt->id, at_cmd2str (e->cmd));
				goto e_return;

			case CMD_AT_CGMI:
				ast_log (LOG_ERROR, "[%s] Getting manufacturer info failed\n", pvt->id);
				goto e_return;

			case CMD_AT_CGMM:
				ast_log (LOG_ERROR, "[%s] Getting model info failed\n", pvt->id);
				goto e_return;

			case CMD_AT_CGMR:
				ast_log (LOG_ERROR, "[%s] Getting firmware info failed\n", pvt->id);
				goto e_return;

			case CMD_AT_CMEE:
				ast_log (LOG_ERROR, "[%s] Setting error verbosity level failed\n", pvt->id);
				goto e_return;

			case CMD_AT_CGSN:
				ast_log (LOG_ERROR, "[%s] Getting IMEI number failed\n", pvt->id);
				goto e_return;

			case CMD_AT_CIMI:
				ast_log (LOG_ERROR, "[%s] Getting IMSI number failed\n", pvt->id);
				goto e_return;

			case CMD_AT_CPIN:
				ast_log (LOG_ERROR, "[%s] Error checking PIN state\n", pvt->id);
				goto e_return;

			case CMD_AT_COPS_INIT:
				ast_log (LOG_ERROR, "[%s] Error setting operator select parameters\n", pvt->id);
				goto e_return;

			case CMD_AT_CREG_INIT:
				ast_log (LOG_ERROR, "[%s] Error enableling registration info\n", pvt->id);
				goto e_return;

			case CMD_AT_CREG:
				ast_debug (1, "[%s] Error getting registration info\n", pvt->id);

				if (!pvt->initialized)
				{
					if (at_send_cnum (pvt) || at_fifo_queue_add (pvt, CMD_AT_CNUM, RES_OK))
					{
						ast_log (LOG_ERROR, "[%s] Error checking subscriber phone number\n", pvt->id);
						goto e_return;
					}
				}
				break;

			case CMD_AT_CNUM:
				ast_log (LOG_ERROR, "[%s] Error checking subscriber phone number\n", pvt->id);
				ast_verb (3, "Datacard %s needs to be reinitialized. The SIM card is not ready yet\n", pvt->id);
				goto e_return;

			case CMD_AT_CVOICE:
				ast_debug (1, "[%s] Datacard has NO voice support\n", pvt->id);

				pvt->has_voice = 0;

				if (!pvt->initialized)
				{
					if (at_send_cmgf (pvt, 1) || at_fifo_queue_add (pvt, CMD_AT_CMGF, RES_OK))
					{
						ast_log (LOG_ERROR, "[%s] Error setting CMGF\n", pvt->id);
						goto e_return;
					}
				}
				break;

			case CMD_AT_CLIP:
				ast_log (LOG_ERROR, "[%s] Error enabling calling line indication\n", pvt->id);
				goto e_return;

			case CMD_AT_CSSN:
				ast_log (LOG_ERROR, "[%s] Error Supplementary Service Notification activation failed\n", pvt->id);
				goto e_return;

			case CMD_AT_CMGF:
			case CMD_AT_CPMS:
			case CMD_AT_CNMI:
				ast_debug (1, "[%s] Command '%s' failed\n", pvt->id, at_cmd2str (e->cmd));
				ast_debug (1, "[%s] No SMS support\n", pvt->id);

				pvt->has_sms = 0;

				if (!pvt->initialized)
				{
					if (pvt->has_voice)
					{
						if (at_send_csq (pvt) || at_fifo_queue_add (pvt, CMD_AT_CSQ, RES_OK))
						{
							ast_log (LOG_ERROR, "[%s] Error querying signal strength\n", pvt->id);
							goto e_return;
						}
					}

					goto e_return;
				}
				break;

			case CMD_AT_CSCS:
				ast_debug (1, "[%s] No UCS-2 encoding support\n", pvt->id);

				pvt->use_ucs2_encoding = 0;

				if (!pvt->initialized)
				{
					/* set SMS storage location */
					if (at_send_cpms (pvt) || at_fifo_queue_add (pvt, CMD_AT_CPMS, RES_OK))
					{
						ast_log (LOG_ERROR, "[%s] Error setting SMS storage location\n", pvt->id);
						goto e_return;
					}
				}
				break;

			/* end initilization stuff */

			case CMD_AT_A:
				ast_log (LOG_ERROR, "[%s] Answer failed\n", pvt->id);
				channel_queue_hangup (pvt, 0);
				break;

			case CMD_AT_CLIR:
				ast_log (LOG_ERROR, "[%s] Setting CLIR failed\n", pvt->id);

				/* continue dialing */
				if (e->ptype != 0 || at_send_atd (pvt, e->param.data) || at_fifo_queue_add (pvt, CMD_AT_D, RES_OK))
				{
					ast_log (LOG_ERROR, "[%s] Error sending ATD command\n", pvt->id);
					goto e_return;
				}
				break;

			case CMD_AT_D:
				ast_log (LOG_ERROR, "[%s] Dial failed\n", pvt->id);
				pvt->outgoing = 0;
				pvt->needchup = 0;
				channel_queue_control (pvt, AST_CONTROL_CONGESTION);
				break;

			case CMD_AT_DDSETEX:
				ast_log (LOG_ERROR, "[%s] AT^DDSETEX failed\n", pvt->id);
				break;

			case CMD_AT_CHUP:
				ast_log (LOG_ERROR, "[%s] Error sending hangup, disconnecting\n", pvt->id);
				goto e_return;

			case CMD_AT_CMGR:
				ast_log (LOG_ERROR, "[%s] Error reading SMS message\n", pvt->id);
				pvt->incoming_sms = 0;
				break;

			case CMD_AT_CMGD:
				ast_log (LOG_ERROR, "[%s] Error deleting SMS message\n", pvt->id);
				pvt->incoming_sms = 0;
				break;

			case CMD_AT_CMGS:
				ast_log (LOG_ERROR, "[%s] Error sending SMS message\n", pvt->id);
				pvt->outgoing_sms = 0;
				break;

			case CMD_AT_DTMF:
				ast_log (LOG_ERROR, "[%s] Error sending DTMF\n", pvt->id);
				break;

			case CMD_AT_COPS:
				ast_debug (1, "[%s] Could not get provider name\n", pvt->id);
				break;

			case CMD_AT_CLVL:
				ast_debug (1, "[%s] Error setting audio level\n", pvt->id);
				break;

			case CMD_AT_CUSD:
				ast_log (LOG_ERROR, "[%s] Could not send USSD code\n", pvt->id);
				break;

			case CMD_AT_CCWA:
				ast_log (LOG_NOTICE, "[%s] Error Call-Waiting disable.\n", pvt->id);
				break;

			default:
				ast_log (LOG_ERROR, "[%s] Received 'ERROR' for unhandled command '%s'\n", pvt->id, at_cmd2str (e->cmd));
				break;
		}

		at_fifo_queue_rem (pvt);
	}
	else if (e)
	{
		ast_log (LOG_ERROR, "[%s] Received 'ERROR' when expecting '%s', ignoring\n", pvt->id, at_res2str (e->res));
	}
	else
	{
		ast_log (LOG_ERROR, "[%s] Received unexpected 'ERROR'\n", pvt->id);
	}

	return 0;

e_return:
	at_fifo_queue_rem (pvt);

	return -1;
}
Exemplo n.º 5
0
static inline int at_response_ok (pvt_t* pvt)
{
	at_queue_t* e;

	if ((e = at_fifo_queue_head (pvt)) && (e->res == RES_OK || e->res == RES_CMGR))
	{
		switch (e->cmd)
		{
			/* initilization stuff */
			case CMD_AT_Z:
				if (at_send_ate0 (pvt) || at_fifo_queue_add (pvt, CMD_AT_E, RES_OK))
				{
					ast_log (LOG_ERROR, "[%s] Error disabling echo\n", pvt->id);
					goto e_return;
				}
				break;

			case CMD_AT_E:
				if (!pvt->initialized)
				{
					if (at_send_curc (pvt) || at_fifo_queue_add (pvt, CMD_AT_CURC, RES_OK))
					{
						ast_log (LOG_ERROR, "[%s] Error setting service messages\n", pvt->id);
						goto e_return;
					}
				}
				break;

			case CMD_AT_CURC:
				if (!pvt->initialized)
				{
					if (pvt->u2diag != -1)
					{
						if (at_send_u2diag (pvt, pvt->u2diag) || at_fifo_queue_add (pvt, CMD_AT_U2DIAG, RES_OK))
						{
							ast_log (LOG_ERROR, "[%s] Error setting U2DIAG\n", pvt->id);
							goto e_return;
						}
					}
					else
					{
						if (at_send_cgmi (pvt) || at_fifo_queue_add (pvt, CMD_AT_CGMI, RES_OK))
						{
							ast_log (LOG_ERROR, "[%s] Error asking datacard for manufacturer info\n", pvt->id);
							goto e_return;
						}
					}
				}
				break;

			case CMD_AT_U2DIAG:
				if (!pvt->initialized)
				{
					if (at_send_cgmi (pvt) || at_fifo_queue_add (pvt, CMD_AT_CGMI, RES_OK))
					{
						ast_log (LOG_ERROR, "[%s] Error asking datacard for manufacturer info\n", pvt->id);
						goto e_return;
					}
				}
				break;

			case CMD_AT_CGMI:
				if (!pvt->initialized)
				{
					if (at_send_cgmm (pvt) || at_fifo_queue_add (pvt, CMD_AT_CGMM, RES_OK))
					{
						ast_log (LOG_ERROR, "[%s] Error asking datacard for model info\n", pvt->id);
						goto e_return;
					}
				}
				break;

			case CMD_AT_CGMM:
				if (!pvt->initialized)
				{
					if (at_send_cgmr (pvt) || at_fifo_queue_add (pvt, CMD_AT_CGMR, RES_OK))
					{
						ast_log (LOG_ERROR, "[%s] Error asking datacard for firmware info\n", pvt->id);
						goto e_return;
					}
				}
				break;

			case CMD_AT_CGMR:
				if (!pvt->initialized)
				{
					if (at_send_cmee (pvt, 0) || at_fifo_queue_add (pvt, CMD_AT_CMEE, RES_OK))
					{
						ast_log (LOG_ERROR, "[%s] Error setting error verbosity level\n", pvt->id);
						goto e_return;
					}
				}
				break;

			case CMD_AT_CMEE:
				if (!pvt->initialized)
				{
					if (at_send_cgsn (pvt) || at_fifo_queue_add (pvt, CMD_AT_CGSN, RES_OK))
					{
						ast_log (LOG_ERROR, "[%s] Error asking datacard for IMEI number\n", pvt->id);
						goto e_return;
					}
				}
				break;

			case CMD_AT_CGSN:
				if (!pvt->initialized)
				{
					if (at_send_cimi (pvt) || at_fifo_queue_add (pvt, CMD_AT_CIMI, RES_OK))
					{
						ast_log (LOG_ERROR, "[%s] Error asking datacard for IMSI number\n", pvt->id);
						goto e_return;
					}
				}
				break;

			case CMD_AT_CIMI:
				if (!pvt->initialized)
				{
					if (at_send_cpin_test (pvt) || at_fifo_queue_add (pvt, CMD_AT_CPIN, RES_OK))
					{
						ast_log (LOG_ERROR, "[%s] Error asking datacard for PIN state\n", pvt->id);
						goto e_return;
					}
				}
				break;

			case CMD_AT_CPIN:
				if (!pvt->initialized)
				{
					if (at_send_cops_init (pvt, 0, 0) || at_fifo_queue_add (pvt, CMD_AT_COPS_INIT, RES_OK))
					{
						ast_log (LOG_ERROR, "[%s] Error setting operator select parameters\n", pvt->id);
						goto e_return;
					}
				}
				break;

			case CMD_AT_COPS_INIT:
				ast_debug (1, "[%s] Operator select parameters set\n", pvt->id);

				if (!pvt->initialized)
				{
					if (at_send_creg_init (pvt, 2) || at_fifo_queue_add (pvt, CMD_AT_CREG_INIT, RES_OK))
					{
						ast_log (LOG_ERROR, "[%s] Error enabeling registration info\n", pvt->id);
						goto e_return;
					}
				}
				break;

			case CMD_AT_CREG_INIT:
				ast_debug (1, "[%s] registration info enabled\n", pvt->id);

				if (!pvt->initialized)
				{
					if (at_send_creg (pvt) || at_fifo_queue_add (pvt, CMD_AT_CREG, RES_OK))
					{
						ast_log (LOG_ERROR, "[%s] Error sending registration query\n", pvt->id);
						goto e_return;
					}
				}
				break;

			case CMD_AT_CREG:
				ast_debug (1, "[%s] registration query sent\n", pvt->id);

				if (!pvt->initialized)
				{
					if (at_send_cnum (pvt) || at_fifo_queue_add (pvt, CMD_AT_CNUM, RES_OK))
					{
						ast_log (LOG_ERROR, "[%s] Error checking subscriber phone number\n", pvt->id);
						goto e_return;
					}
				}
				break;

			case CMD_AT_CNUM:
				ast_debug (1, "[%s] Subscriber phone number query successed\n", pvt->id);

				if (!pvt->initialized)
				{
					if (at_send_cvoice_test (pvt) || at_fifo_queue_add (pvt, CMD_AT_CVOICE, RES_OK))
					{
						ast_log (LOG_ERROR, "[%s] Error checking voice capabilities\n", pvt->id);
						goto e_return;
					}
				}
				break;

			case CMD_AT_CVOICE:
				ast_debug (1, "[%s] Datacard has voice support\n", pvt->id);

				pvt->has_voice = 1;

				if (!pvt->initialized)
				{
					if (at_send_clip (pvt, 1) || at_fifo_queue_add (pvt, CMD_AT_CLIP, RES_OK))
					{
						ast_log (LOG_ERROR, "[%s] Error enabling calling line notification\n", pvt->id);
						goto e_return;
					}
				}
				break;

			case CMD_AT_CLIP:
				ast_debug (1, "[%s] Calling line indication enabled\n", pvt->id);

				if (!pvt->initialized)
				{
					if (at_send_cssn (pvt, 1, 1) || at_fifo_queue_add (pvt, CMD_AT_CSSN, RES_OK))
					{
						ast_log (LOG_ERROR, "[%s] Error activating Supplementary Service Notification\n", pvt->id);
						goto e_return;
					}
				}

				break;

			case CMD_AT_CSSN:
				ast_debug (1, "[%s] Supplementary Service Notification enabled successful\n", pvt->id);

				if (!pvt->initialized)
				{
					/* set the SMS operating mode to text mode */
					if (at_send_cmgf (pvt, 1) || at_fifo_queue_add (pvt, CMD_AT_CMGF, RES_OK))
					{
						ast_log (LOG_ERROR, "[%s] Error setting CMGF\n", pvt->id);
						goto e_return;
					}
				}

				break;

			case CMD_AT_CMGF:
				ast_debug (1, "[%s] SMS text mode enabled\n", pvt->id);

				if (!pvt->initialized)
				{
					/* set text encoding to UCS-2 */
					if (at_send_cscs (pvt, "UCS2") || at_fifo_queue_add (pvt, CMD_AT_CSCS, RES_OK))
					{
						ast_log (LOG_ERROR, "[%s] Error setting CSCS (text encoding)\n", pvt->id);
						goto e_return;
					}
				}
				break;

			case CMD_AT_CSCS:
				ast_debug (1, "[%s] UCS-2 text encoding enabled\n", pvt->id);

				pvt->use_ucs2_encoding = 1;

				if (!pvt->initialized)
				{
					/* set SMS storage location */
					if (at_send_cpms (pvt) || at_fifo_queue_add (pvt, CMD_AT_CPMS, RES_OK))
					{
						ast_log (LOG_ERROR, "[%s] Error setting CPMS\n", pvt->id);
						goto e_return;
					}
				}
				break;

			case CMD_AT_CPMS:
				ast_debug (1, "[%s] SMS storage location is established\n", pvt->id);

				if (!pvt->initialized)
				{
					/* turn on SMS new message indication */
					if (at_send_cnmi (pvt) || at_fifo_queue_add (pvt, CMD_AT_CNMI, RES_OK))
					{
						ast_log (LOG_ERROR, "[%s] Error sending CNMI\n", pvt->id);
						goto e_return;
					}
				}
				break;

			case CMD_AT_CNMI:
				ast_debug (1, "[%s] SMS new message indication enabled\n", pvt->id);
				ast_debug (1, "[%s] Datacard has sms support\n", pvt->id);

				pvt->has_sms = 1;

				if (!pvt->initialized)
				{
					if (at_send_csq (pvt) || at_fifo_queue_add (pvt, CMD_AT_CSQ, RES_OK))
					{
						ast_log (LOG_ERROR, "[%s] Error querying signal strength\n", pvt->id);
						goto e_return;
					}
				}
				break;

			case CMD_AT_CSQ:
				ast_debug (1, "[%s] Got signal strength result\n", pvt->id);

				if (!pvt->initialized)
				{
					ast_verb (3, "Datacard %s initialized and ready\n", pvt->id);

					pvt->timeout = 7000;
					pvt->initialized = 1;

					if (pvt->has_sms && pvt->auto_delete_sms)
					{
						if (at_send_cmgd (pvt, 1, 4) || at_fifo_queue_add (pvt, CMD_AT_CMGD, RES_OK))
						{
							ast_log (LOG_ERROR, "[%s] Error delete SMS messages\n", pvt->id);
							goto e_return;
						}
					}
				}
				break;

			/* end initilization stuff */

			case CMD_AT_A:
				ast_debug (1, "[%s] Answer sent successfully\n", pvt->id);

				if (at_send_ddsetex (pvt) || at_fifo_queue_add (pvt, CMD_AT_DDSETEX, RES_OK))
				{
					ast_log (LOG_ERROR, "[%s] Error sending AT^DDSETEX\n", pvt->id);
					goto e_return;
				}

				if (pvt->a_timer)
				{
					ast_timer_set_rate (pvt->a_timer, 50);
				}

				break;

			case CMD_AT_CLIR:
				ast_debug (1, "[%s] CLIR sent successfully\n", pvt->id);

				if (e->ptype != 0 || at_send_atd (pvt, e->param.data) || at_fifo_queue_add (pvt, CMD_AT_D, RES_OK))
				{
					ast_log (LOG_ERROR, "[%s] Error sending ATD command\n", pvt->id);
					goto e_return;
				}
				break;

			case CMD_AT_D:
				ast_debug (1, "[%s] Dial sent successfully\n", pvt->id);
				break;

			case CMD_AT_DDSETEX:
				ast_debug (1, "[%s] AT^DDSETEX sent successfully\n", pvt->id);
				break;

			case CMD_AT_CHUP:
				ast_debug (1, "[%s] Successful hangup\n", pvt->id);
				break;

			case CMD_AT_CMGS:
				ast_debug (1, "[%s] Successfully sent sms message\n", pvt->id);
				pvt->outgoing_sms = 0;
				break;

			case CMD_AT_DTMF:
				ast_debug (1, "[%s] DTMF sent successfully\n", pvt->id);
				break;

			case CMD_AT_CUSD:
				ast_debug (1, "[%s] CUSD code sent successfully\n", pvt->id);
				break;

			case CMD_AT_COPS:
				ast_debug (1, "[%s] Provider query successfully\n", pvt->id);
				break;

			case CMD_AT_CMGR:
				ast_debug (1, "[%s] SMS message see later\n", pvt->id);
				break;

			case CMD_AT_CMGD:
				ast_debug (1, "[%s] SMS message deleted successfully\n", pvt->id);
				break;
			
			case CMD_AT_CCWA:
				ast_log (LOG_NOTICE, "[%s] Call-Waiting disabled.\n", pvt->id);
				break;
			
			case CMD_AT_CFUN:
				ast_debug (1, "[%s] CFUN sent successfully\n", pvt->id);
				break;

			case CMD_AT_CLVL:
				ast_debug (1, "[%s] Audio level is set\n", pvt->id);
				break;

			default:
				ast_log (LOG_ERROR, "[%s] Received 'OK' for unhandled command '%s'\n", pvt->id, at_cmd2str (e->cmd));
				break;
		}

		at_fifo_queue_rem (pvt);
	}
	else if (e)
	{
		ast_log (LOG_ERROR, "[%s] Received 'OK' when expecting '%s', ignoring\n", pvt->id, at_res2str (e->res));
	}
	else
	{
		ast_log (LOG_ERROR, "[%s] Received unexpected 'OK'\n", pvt->id);
	}

	return 0;

e_return:
	at_fifo_queue_rem (pvt);

	return -1;
}
Exemplo n.º 6
0
static inline int at_response_cmgr (pvt_t* pvt, char* str, size_t len)
{
	at_queue_t*	e;
	ssize_t		res;
	char*		from_number;
	char		from_number_utf8[1024];
	char*		text;
	char		text_utf8[1024];
	char		text_base64[8192];

	if ((e = at_fifo_queue_head (pvt)) && e->res == RES_CMGR)
	{
		if (pvt->auto_delete_sms && e->ptype == 1)
		{
			if (at_send_cmgd (pvt, e->param.num, 0) || at_fifo_queue_add (pvt, CMD_AT_CMGD, RES_OK))
			{
				ast_log (LOG_ERROR, "[%s] Error sending CMGD to delete SMS message\n", pvt->id);
			}
		}

		at_fifo_queue_rem (pvt);

		pvt->incoming_sms = 0;

		if (at_parse_cmgr (pvt, str, len, &from_number, &text))
		{
			ast_log (LOG_ERROR, "[%s] Error parsing SMS message, disconnecting\n", pvt->id);
			return 0;
		}

		ast_debug (1, "[%s] Successfully read SMS message\n", pvt->id);

		if (pvt->use_ucs2_encoding)
		{
			res = conv_ucs2_8bit_hexstr_to_utf8 (text, strlen (text), text_utf8, sizeof (text_utf8));

			if (res > 0)
			{
				text = text_utf8;
			}
			else
			{
				ast_log (LOG_ERROR, "[%s] Error parsing SMS (convert UCS-2 to UTF-8): %s\n", pvt->id, text);
			}

			res = conv_ucs2_8bit_hexstr_to_utf8 (from_number, strlen (from_number), from_number_utf8, sizeof (from_number_utf8));

			if (res > 0)
			{
				from_number = from_number_utf8;
			}
			else
			{
				ast_log (LOG_ERROR, "[%s] Error parsing SMS from_number (convert UCS-2 to UTF-8): %s\n", pvt->id, from_number);
			}
		}

		ast_base64encode (text_base64, (unsigned char *) text, strlen (text), sizeof (text_base64));
		ast_verb (1, "[%s] Got SMS from %s: '%s'\n", pvt->id, from_number, text);

#ifdef __MANAGER__
		manager_event_new_sms		(pvt, from_number, text);
		manager_event_new_sms_base64	(pvt, from_number, text_base64);
#endif

#ifdef __ALLOW_LOCAL_CHANNELS__
		struct ast_channel* channel;

		snprintf (pvt->d_send_buf, sizeof (pvt->d_send_buf), "sms@%s", pvt->context);

		if (channel = channel_local_request (pvt, pvt->d_send_buf, pvt->id, from_number))
		{
			pbx_builtin_setvar_helper (channel, "SMS",		text);
			pbx_builtin_setvar_helper (channel, "SMS_BASE64",	text_base64);

			if (ast_pbx_start (channel))
			{
				ast_hangup (channel);
				ast_log (LOG_ERROR, "[%s] Unable to start pbx on incoming sms\n", pvt->id);
			}
		}
#endif /* __ALLOW_LOCAL_CHANNELS__ */
	}
	else if (e)
	{
		ast_log (LOG_ERROR, "[%s] Received '+CMGR' when expecting '%s' response to '%s', ignoring\n", pvt->id,
				at_res2str (e->res), at_cmd2str (e->cmd));
	}
	else
	{
		ast_log (LOG_ERROR, "[%s] Received unexpected '+CMGR'\n", pvt->id);
	}

	return 0;
}
Exemplo n.º 7
0
int CardDevice::at_response_sms_prompt()
{
    if(m_lastcmd && (m_lastcmd->m_cmd == CMD_AT_CMGS))
    {
	if(m_lastcmd->get())
	{
	    String* text = static_cast<String*>(m_lastcmd->get());
	    at_send_sms_text((char*)text->safe());
	}
    }
    else
    {
	if(m_lastcmd)
	    Debug(DebugAll,  "[%s] Received sms prompt when expecting '%s' response to '%s', ignoring", c_str(), at_res2str (m_lastcmd->m_res), at_cmd2str(m_lastcmd->m_cmd));
	else
	    Debug(DebugAll, "[%s] Received unexpected sms prompt", c_str());
//FIXME: Send empty SMS text. To exit from SMS prompt.
	at_send_sms_text("");
    }
    return 0;
}
Exemplo n.º 8
0
int CardDevice::at_response_error()
{
    if(m_lastcmd && (m_lastcmd->m_res == RES_OK || m_lastcmd->m_res == RES_ERROR || m_lastcmd->m_res == RES_CMS_ERROR || m_lastcmd->m_res == RES_SMS_PROMPT))
    {
	switch (m_lastcmd->m_cmd)
	{
	    /* initilization stuff */
	    case CMD_AT:
	    case CMD_AT_Z:
	    case CMD_AT_E:
	    case CMD_AT_U2DIAG:
		Debug(DebugAll,  "[%s] Command '%s' failed", c_str(), at_cmd2str (m_lastcmd->m_cmd));
		goto e_return;

	    case CMD_AT_CGMI:
		Debug(DebugAll, "[%s] Getting manufacturer info failed", c_str());
		goto e_return;

	    case CMD_AT_CGMM:
		Debug(DebugAll,  "[%s] Getting model info failed", c_str());
		goto e_return;

	    case CMD_AT_CGMR:
		Debug(DebugAll,  "[%s] Getting firmware info failed", c_str());
		goto e_return;

	    case CMD_AT_CMEE:
		Debug(DebugAll,  "[%s] Setting error verbosity level failed", c_str());
		goto e_return;

	    case CMD_AT_CGSN:
		Debug(DebugAll,  "[%s] Getting IMEI number failed", c_str());
		goto e_return;

	    case CMD_AT_CIMI:
		Debug(DebugAll,  "[%s] Getting IMSI number failed", c_str());
		goto e_return;

	    case CMD_AT_CPIN:
		Debug(DebugAll,  "[%s] Error checking PIN state", c_str());
		goto e_return;

	    case CMD_AT_CPIN_ENTER:
		Debug(DebugAll,  "[%s] Error enter PIN code", c_str());
		goto e_return;

	    case CMD_AT_COPS_INIT:
		Debug(DebugAll,  "[%s] Error setting operator select parameters", c_str());
		goto e_return;

	    case CMD_AT_CREG_INIT:
		Debug(DebugAll, "[%s] Error enableling registration info", c_str());
		goto e_return;

	    case CMD_AT_CREG:
		Debug(DebugAll, "[%s] Error getting registration info", c_str());
		if (!m_initialized)
		    m_commandQueue.append(new ATCommand("AT+CNUM", CMD_AT_CNUM));
		break;

	    case CMD_AT_CNUM:
		Debug(DebugAll, "[%s] Error checking subscriber phone number", c_str());
		Debug(DebugAll, "Datacard %s needs to be reinitialized. The SIM card is not ready yet", c_str());
		goto e_return;

	    case CMD_AT_CVOICE:
		Debug(DebugAll, "[%s] Datacard has NO voice support", c_str());
		m_has_voice = 0;
		if (!m_initialized)
		    m_commandQueue.append(new ATCommand("AT+CMGF=0", CMD_AT_CMGF));
		break;

	    case CMD_AT_CLIP:
		Debug(DebugAll, "[%s] Error enabling calling line indication", c_str());
		goto e_return;

	    case CMD_AT_CSSN:
		Debug(DebugAll, "[%s] Error Supplementary Service Notification activation failed", c_str());
		goto e_return;

	    case CMD_AT_CMGF:
	    case CMD_AT_CPMS:
	    case CMD_AT_CNMI:
		Debug(DebugAll, "[%s] Command '%s' failed", c_str(), at_cmd2str (m_lastcmd->m_cmd));
		Debug(DebugAll, "[%s] No SMS support", c_str());
		m_has_sms = 0;
		if (!m_initialized)
		{
		    if (m_has_voice)
		    {
			m_commandQueue.append(new ATCommand("AT+CSQ", CMD_AT_CSQ));
			m_initialized = 1;
			Debug(DebugAll, "Datacard %s initialized and ready", c_str());
		    }
		    goto e_return;
		}
		break;

	    case CMD_AT_CSCS:
		Debug(DebugAll, "[%s] No UCS-2 encoding support", c_str());
		m_use_ucs2_encoding = 0;
		/* set SMS storage location */
		if (!m_initialized)
		    m_commandQueue.append(new ATCommand("AT+CPMS=\"ME\",\"ME\",\"ME\"", CMD_AT_CPMS));
		break;
	    /* end initilization stuff */

	    case CMD_AT_A:
		Debug(DebugAll, "[%s] Answer failed", c_str());
		Hangup(DATACARD_FAILURE);
		break;

	    case CMD_AT_CLIR:
		Debug(DebugAll, "[%s] Setting CLIR failed", c_str());
		/* continue dialing */
		if(m_lastcmd->get())
		{
		    String* number = static_cast<String*>(m_lastcmd->get());
		    m_commandQueue.append(new ATCommand("ATD" + *number + ";", CMD_AT_D));
		}		
		break;

	    case CMD_AT_D:
		Debug(DebugAll, "[%s] Dial failed", c_str());
		m_outgoing = 0;
		m_needchup = 0;
		Hangup(DATACARD_CONGESTION);
		break;

	    case CMD_AT_DDSETEX:
		Debug(DebugAll, "[%s] AT^DDSETEX failed", c_str());
		break;

	    case CMD_AT_CHUP:
		Debug(DebugAll, "[%s] Error sending hangup, disconnecting", c_str());
		goto e_return;

	    case CMD_AT_CMGR:
		Debug(DebugAll, "[%s] Error reading SMS message", c_str());
		break;

	    case CMD_AT_CMGD:
		Debug(DebugAll, "[%s] Error deleting SMS message", c_str());
		break;

	    case CMD_AT_CMGS:
		Debug(DebugAll, "[%s] Error sending SMS message", c_str());
		break;

	    case CMD_AT_DTMF:
		Debug(DebugAll, "[%s] Error sending DTMF", c_str());
		break;

	    case CMD_AT_COPS:
		Debug(DebugAll, "[%s] Could not get provider name", c_str());
		break;

	    case CMD_AT_CLVL:
		Debug(DebugAll, "[%s] Error syncronizing audio level", c_str());
		m_volume_synchronized = 0;
		break;

	    case CMD_AT_CUSD:
		Debug(DebugAll, "[%s] Could not send USSD code", c_str());
		break;

	    default:
		Debug(DebugAll, "[%s] Received 'ERROR' for unhandled command '%s'", c_str(), at_cmd2str (m_lastcmd->m_cmd));
		break;
	}

	m_lastcmd->destruct();
	m_lastcmd = 0;
    }
    else if (m_lastcmd)
    {
	Debug(DebugAll, "[%s] Received 'ERROR' when expecting '%s', ignoring", c_str(), at_res2str (m_lastcmd->m_res));
    }
    else
    {
	Debug(DebugAll, "[%s] Received unexpected 'ERROR'", c_str());
    }

    return 0;

e_return:
    m_lastcmd->destruct();
    m_lastcmd = 0;
	
    return -1;
}
Exemplo n.º 9
0
int CardDevice::at_response_ok()
{
    if(m_lastcmd && (m_lastcmd->m_res == RES_OK))
    {
	switch (m_lastcmd->m_cmd)
	{
	    /* initilization stuff */
	    case CMD_AT:
		if(!m_initialized)
		{
		    if(m_reset_datacard)
			m_commandQueue.append(new ATCommand("ATZ", CMD_AT_Z));
		    else
			m_commandQueue.append(new ATCommand("ATE0", CMD_AT_E));
		}
		break;
		
	    case CMD_AT_Z:
	        m_commandQueue.append(new ATCommand("ATE0", CMD_AT_E));
		break;

	    case CMD_AT_E:
		if(!m_initialized)
		{
		    if(m_u2diag != -1)
		        m_commandQueue.append(new ATCommand("AT^U2DIAG=" + String(m_u2diag), CMD_AT_U2DIAG));
		    else
		        m_commandQueue.append(new ATCommand("AT+CGMI", CMD_AT_CGMI));
		}
		break;

	    case CMD_AT_U2DIAG:
		if(!m_initialized)
		    m_commandQueue.append(new ATCommand("AT+CGMI", CMD_AT_CGMI));
		break;

	    case CMD_AT_CGMI:
		if(!m_initialized)
		    m_commandQueue.append(new ATCommand("AT+CGMM", CMD_AT_CGMM));
		break;

	    case CMD_AT_CGMM:
		if(!m_initialized)
		    m_commandQueue.append(new ATCommand("AT+CGMR", CMD_AT_CGMR));
		break;

	    case CMD_AT_CGMR:
		if(!m_initialized)
		    m_commandQueue.append(new ATCommand("AT+CMEE=0", CMD_AT_CMEE));
		break;
		
	    case CMD_AT_CMEE:
		if(!m_initialized)
		    m_commandQueue.append(new ATCommand("AT+CGSN", CMD_AT_CGSN));
		break;

	    case CMD_AT_CGSN:
		if(!m_initialized)
		    m_commandQueue.append(new ATCommand("AT+CPIN?", CMD_AT_CPIN));
		break;

	    case CMD_AT_CIMI:
		if(!m_initialized)
		    m_commandQueue.append(new ATCommand("AT+COPS=0,0", CMD_AT_COPS_INIT));
		break;

	    case CMD_AT_CPIN:
		if(!m_initialized)
		{
		    if(m_simstatus == 0)
		        m_commandQueue.append(new ATCommand("AT+CIMI", CMD_AT_CIMI));
		    else if(m_simstatus == 1 && (m_sim_pin.length() > 0) && (m_pincount == 0))
		    {
			m_pincount++;
			m_commandQueue.append(new ATCommand("AT+CPIN=" + m_sim_pin, CMD_AT_CPIN_ENTER));
		    }
		    else
		    {
		    	Debug(DebugAll, "[%s] Wrong SIM State", c_str());
			m_lastcmd->destruct();
			m_lastcmd = 0;
			return -1;
		    }

		}
		break;

	    case CMD_AT_CPIN_ENTER:
		if(!m_initialized)
		    m_commandQueue.append(new ATCommand("AT+CPIN?", CMD_AT_CPIN));
		break;

	    case CMD_AT_COPS_INIT:
		Debug(DebugAll, "[%s] Operator select parameters set", c_str());
		if(!m_initialized)
		    m_commandQueue.append(new ATCommand("AT+CREG=2", CMD_AT_CREG_INIT));
		break;

	    case CMD_AT_CREG_INIT:
		Debug(DebugAll,  "[%s] registration info enabled", c_str());
		if(!m_initialized)
		    m_commandQueue.append(new ATCommand("AT+CREG?", CMD_AT_CREG));
		break;

	    case CMD_AT_CREG:
		Debug(DebugAll, "[%s] registration query sent", c_str());
		if(!m_initialized)
		    m_commandQueue.append(new ATCommand("AT+CNUM", CMD_AT_CNUM));
		break;

	    case CMD_AT_CNUM:
		Debug(DebugAll, "[%s] Subscriber phone number query successed", c_str());
		if(!m_initialized)
		    m_commandQueue.append(new ATCommand("AT^CVOICE?", CMD_AT_CVOICE));
		break;

	    case CMD_AT_CVOICE:
		Debug(DebugAll, "[%s] Datacard has voice support", c_str());
		m_has_voice = 1;
		if(!m_initialized)
		    m_commandQueue.append(new ATCommand("AT+CLIP=1", CMD_AT_CLIP));
		break;

	    case CMD_AT_CLIP:
		Debug(DebugAll, "[%s] Calling line indication enabled", c_str());
		if(!m_initialized)
		    m_commandQueue.append(new ATCommand("AT+CSSN=1,1", CMD_AT_CSSN));
		break;

	    case CMD_AT_CSSN:
		Debug(DebugAll, "[%s] Supplementary Service Notification enabled successful", c_str());
		if(!m_initialized)
		    m_commandQueue.append(new ATCommand("AT+CMGF=0", CMD_AT_CMGF));
		break;

	    case CMD_AT_CMGF:
		Debug(DebugAll, "[%s] SMS PDU mode enabled", c_str());
		m_use_ucs2_encoding = 1;
		if(!m_initialized)
		    m_commandQueue.append(new ATCommand("AT+CPMS=\"ME\",\"ME\",\"ME\"", CMD_AT_CPMS));
		break;

	    case CMD_AT_CPMS:
		Debug(DebugAll,  "[%s] SMS storage location is established", c_str());
		if(!m_initialized)
		    m_commandQueue.append(new ATCommand("AT+CNMI=2,1,0,0,0", CMD_AT_CNMI));
		break;

	    case CMD_AT_CNMI:
		Debug(DebugAll, "[%s] SMS new message indication enabled", c_str());
		Debug(DebugAll, "[%s] Datacard has sms support", c_str());
		m_has_sms = 1;
		if(!m_initialized)
		{
		    m_commandQueue.append(new ATCommand("AT+CSQ", CMD_AT_CSQ));
		    m_initialized = 1;
		}
		break;
	    /* end initilization stuff */
	    	
	    case CMD_AT_A:
		Debug(DebugAll,  "[%s] Answer sent successfully", c_str());
		//FIXME: Clear audio bufer
		m_audio_buf.clear();
		m_commandQueue.append(new ATCommand("AT^DDSETEX=2", CMD_AT_DDSETEX));
		break;

	    case CMD_AT_CLIR:
		Debug(DebugAll, "[%s] CLIR sent successfully", c_str());
		if(m_lastcmd->get())
		{
		    String* number = static_cast<String*>(m_lastcmd->get());
		    m_commandQueue.append(new ATCommand("ATD" + *number  + ";", CMD_AT_D));
		}
		break;

	    case CMD_AT_D:
		Debug(DebugAll,  "[%s] Dial sent successfully", c_str());
		m_commandQueue.append(new ATCommand("AT^DDSETEX=2", CMD_AT_DDSETEX));
		break;

	    case CMD_AT_DDSETEX:
		Debug(DebugAll,  "[%s] AT^DDSETEX sent successfully", c_str());
		break;

	    case CMD_AT_CHUP:
		Debug(DebugAll,  "[%s] Successful hangup", c_str());
		break;

	    case CMD_AT_CMGS:
		Debug(DebugAll, "[%s] Successfully sent sms message", c_str());
		break;

	    case CMD_AT_DTMF:
		Debug(DebugAll, "[%s] DTMF sent successfully", c_str());
		break;

	    case CMD_AT_CUSD:
		Debug(DebugAll, "[%s] CUSD code sent successfully", c_str());
		break;

	    case CMD_AT_COPS:
		Debug(DebugAll, "[%s] Provider query successfully", c_str());
		break;

	    case CMD_AT_CMGR:
		Debug(DebugAll, "[%s] SMS message read successfully", c_str());
		if(m_auto_delete_sms)
		{
		    if(m_lastcmd->get())
		    {
			String* index = static_cast<String*>(m_lastcmd->get());
			m_commandQueue.append(new ATCommand("AT+CMGD=" + *index, CMD_AT_CMGD));
		    }
		}
		break;

	    case CMD_AT_CMGD:
		Debug(DebugAll, "[%s] SMS message deleted successfully", c_str());
		break;

	    case CMD_AT_CSQ:
		Debug(DebugAll, "[%s] Got signal strength result", c_str());
		break;
			
	    case CMD_AT_CCWA:
		Debug(DebugAll, "Call-Waiting disabled on device %s.", c_str());
		break;
			
	    case CMD_AT_CFUN:
		Debug(DebugAll, "[%s] CFUN sent successfully", c_str());
		break;

	    case CMD_AT_CLVL:
		if (m_volume_synchronized == 0)
		{
		    m_volume_synchronized = 1;
		    m_commandQueue.append(new ATCommand("AT+CLVL=5", CMD_AT_CLVL));
		}
		break;

	    default:
		Debug(DebugAll, "[%s] Received 'OK' for unhandled command '%s'", c_str(), at_cmd2str (m_lastcmd->m_cmd));
		break;
	}
	
	m_lastcmd->destruct();
	m_lastcmd = 0;

    }
    else if (m_lastcmd)
    {
	Debug(DebugAll, "[%s] Received 'OK' when expecting '%s', ignoring", c_str(), at_res2str(m_lastcmd->m_res));
    }
    else
    {
	Debug(DebugAll,  "[%s] Received unexpected 'OK'", c_str());
    }
    return 0;
}