Пример #1
0
int _send_sms_as_sip(struct incame_sms *sms, struct modem *mdm) 
{
	switch(mdm->scan) 
	{
		case SMS_BODY_SCAN:
			return send_sms_as_sip(sms);	
	
		case SMS_BODY_SCAN_MIX:
			if(send_sms_as_sip(sms) == 1)
				return 1;

		case SMS_BODY_SCAN_NO:
			return send_sms_as_sip_scan_no(sms, mdm->to);

		default:
			break;
	}
	
	/* CASE IMPOSIBLE!!!!, scan assume default value SMS_BODY_SCAN */
	LM_ERR("SMS bad config param scan: %d for modem: %s\n",
		mdm->scan, mdm->name);

	return -1;
}
Пример #2
0
void modem_process(struct modem *mdm)
{
	struct sms_msg    *sms_messg;
	struct incame_sms sms;
	struct network *net;
	int i,k,len;
	int counter;
	int dont_wait;
	int empty_pipe;
	int cpms_unsuported;
	int max_mem=0, used_mem=0;

	sms_messg = 0;
	cpms_unsuported = 0;

	/* let's open/init the modem */
	LM_DBG("opening modem\n");
	if (openmodem(mdm)==-1) {
		LM_ERR("failed to open modem %s!"
			" %s \n",mdm->name,strerror(errno));
		return;
	}

	setmodemparams(mdm);
	initmodem(mdm,check_cds_report);

	if ( (max_mem=check_memory(mdm,MAX_MEM))==-1 ) {
		LM_WARN("CPMS command unsuported! using default values (10,10)\n");
		used_mem = max_mem = 10;
		cpms_unsuported = 1;
	}
	LM_DBG("modem maximum memory is %d\n",max_mem);

	set_gettime_function();

	while(1)
	{
		dont_wait = 0;
		for (i=0;i<nr_of_networks && mdm->net_list[i]!=-1;i++)
		{
			counter = 0;
			empty_pipe = 0;
			net = &(networks[mdm->net_list[i]]);
			/*getting msgs from pipe*/
			while( counter<net->max_sms_per_call && !empty_pipe )
			{
				/* let's read a sms from pipe */
				len = read(net->pipe_out, &sms_messg,
					sizeof(sms_messg));
				if (len!=sizeof(sms_messg)) {
					if (len>=0)
						LM_ERR("truncated message read from pipe! "
								"-> discarded\n");
					else if (errno==EAGAIN)
						empty_pipe = 1;
					else
						LM_ERR("pipe reading failed: %s\n",strerror(errno));
					sleep(1);
					counter++;
					continue;
				}
				(*queued_msgs)--;

				/* compute and send the sms */
				LM_DBG("%s processing sms for net %s:"
					" \n\tTo:[%.*s]\n\tBody=<%d>[%.*s]\n",
					mdm->device, net->name,
					sms_messg->to.len,sms_messg->to.s,
					sms_messg->text.len,sms_messg->text.len,sms_messg->text.s);
				send_as_sms( sms_messg , mdm);

				counter++;
				/* if I reached the limit -> set not to wait */
				if (counter==net->max_sms_per_call)
					dont_wait = 1;
			}/*while*/
		}/*for*/

		/* let's see if we have incoming sms */
		if ( !cpms_unsuported )
			if ((used_mem = check_memory(mdm,USED_MEM))==-1) {
				LM_ERR("CPMS command failed! cannot get used mem->using 10\n");
				used_mem = 10;
			}

		/* if any, let's get them */
		if (used_mem)
			LM_DBG("%d new SMS on modem\n",used_mem);
			for(i=1,k=1;k<=used_mem && i<=max_mem;i++) {
				if (getsms(&sms,mdm,i)!=-1) {
					k++;
					LM_DBG("SMS Get from location %d\n",i);
					/*for test ;-) ->  to be remove*/
					LM_DBG("SMS RECEIVED:\n\rFrom: %s %s\n\r%.*s %.*s"
						"\n\r\"%.*s\"\n\r",sms.sender,sms.name,
						DATE_LEN,sms.date,TIME_LEN,sms.time,
						sms.userdatalength,sms.ascii);
					if (!sms.is_statusreport)
						send_sms_as_sip(&sms);
					else 
						check_sms_report(&sms);
				}
			}

		/* if reports are used, checks for expired records in report queue */
		if (sms_report_type!=NO_REPORT)
			check_timeout_in_report_queue();

		/* sleep -> if it's needed */
		if (!dont_wait) {
				sleep(mdm->looping_interval);
		}
	}/*while*/
}