Example #1
0
void
main(int argc, char *argv[])
{
	Modem *m;

	m = &modems[0];

	ARGBEGIN{
	case 'v':
		vflag = 1;
		break;

	case 's':
		spool = ARGF();
		break;

	default:
		usage();
		break;

	}ARGEND

	initmodem(m, 0, -1, type, 0);
	receivedone(m, faxreceive(m, spool));

	exits(0);
}
Example #2
0
int checkmodem(struct modem *mdm)
{
	char answer[500];

	/* Checking if modem needs PIN */
	put_command(mdm,"AT+CPIN?\r",9,answer,sizeof(answer),50,0);
	if (!strstr(answer,"+CPIN: READY")) {
		LOG(L_WARN,"WARNING:sms_checkmodem: modem wants the PIN again!\n");
		goto reinit;
	}

	if (mdm->mode!=MODE_DIGICOM) {
		put_command(mdm,"AT+CREG?\r",9,answer,sizeof(answer),100,0);
		if (!strchr(answer,'1') ) {
			LOG(L_WARN,"WARNING:sms_checkmodem: Modem is not registered to the"
					" network\n");
			goto reinit;
		}
	}

	return 1;
reinit:
	LOG(L_WARN,"WARNING:sms_checkmodem: re -init the modem!!\n");
	initmodem(mdm,cds_report_func);
	return -1;
}
Example #3
0
File: modem.c Project: nhanh0/hah
int checkmodem()
{
        char answer[500];
        int status = 0;
        put_command("AT+CREG?\r", 9, answer, sizeof(answer), 100, 0);
        if(!strchr(answer,'1')) {
                info("Modem is not registered to the network");
                status=initmodem();
        }
        return status;
}
Example #4
0
File: send.c Project: 99years/plan9
void
main(int argc, char *argv[])
{
	int fd, cfd, r;
	Modem *m;
	char *addr;

	m = &modems[0];

	ARGBEGIN{
	case 'v':
		vflag = 1;
		break;
	default:
		usage();
		break;

	}ARGEND

	if(argc <= 1)
		usage();
	verbose("send: %s %s...", argv[0], argv[1]);

	addr = netmkaddr(*argv, "telco", "fax!9600");
	fd = dial(addr, 0, 0, &cfd);
	if(fd < 0){
		fprint(2, "faxsend: can't dial %s: %r\n", addr);
		exits("Retry, can't dial");
	}
	initmodem(m, fd, cfd, 0, 0);
	argc--; argv++;
	r = faxsend(m, argc, argv);
	if(r != Eok){
		fprint(2, "faxsend: %s\n", m->error);
		syslog(0, "fax", "failed %s %s: %s", argv[0], argv[1], m->error); 
		exits(m->error);
	}
	syslog(0, "fax", "success %s %s", argv[0], argv[1]); 
	exits(0);
}
Example #5
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_unsupported;
	int max_mem=0, used_mem=0;

	sms_messg = 0;
	cpms_unsupported = 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 unsupported! using default values (10,10)\n");
		used_mem = max_mem = 10;
		cpms_unsupported = 1;
	}
	LM_DBG("modem maximum memory is %d\n",max_mem);

	set_gettime_function();

	while(1)
	{
		/* update the local config */
		cfg_update();

		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_unsupported )
			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, mdm);
					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*/
}