示例#1
0
文件: wat_core.c 项目: sangoma/libwat
wat_status_t wat_span_update_sig_status(wat_span_t *span, wat_bool_t up)
{
	wat_log_span(span, WAT_LOG_DEBUG, "Signalling status changed to %s\n", up ? "Up": "Down");

	span->sigstatus = up ? WAT_SIGSTATUS_UP: WAT_SIGSTATUS_DOWN;

	if (span->state == WAT_SPAN_STATE_RUNNING) {
		if (g_interface.wat_span_sts) {
			wat_span_status_t sts_event;

			memset(&sts_event, 0, sizeof(sts_event));
			sts_event.type = WAT_SPAN_STS_SIGSTATUS;
			sts_event.sts.sigstatus = span->sigstatus;
			g_interface.wat_span_sts(span->id, &sts_event);
		}
	}

	if (span->module.handle_sig_status) {
		/* If the module provides a method to take care of signaling status, use it instead */
		span->module.handle_sig_status(span, up);
	} else if (span->sigstatus == WAT_SIGSTATUS_UP) {
		/* Get the Operator Name */
		wat_cmd_enqueue(span, "AT+COPS?", wat_response_cops, NULL, 30000);

		/* Own Number */
		wat_cmd_enqueue(span, "AT+CNUM", wat_response_cnum, NULL, 5000); /* Could not find timeout value for CNUM */

		/* SMSC information */
		wat_cmd_enqueue(span, "AT+CSCA?", wat_response_csca, NULL, 5000);
	}

	return WAT_SUCCESS;
}
示例#2
0
wat_status_t telit_wait_sim(wat_span_t *span)
{
	wat_log_span(span, WAT_LOG_INFO, "Waiting for SIM acccess...\n");
	wat_cmd_register(span, "#QSS", wat_notify_qss);
	wat_cmd_enqueue(span, "AT#QSS=2", wat_response_qss, NULL, span->config.timeout_command);
	wat_cmd_enqueue(span, "AT#QSS?", wat_response_qss, NULL, span->config.timeout_command);
	return WAT_SUCCESS;
}
示例#3
0
wat_status_t telit_set_codec(wat_span_t *span, wat_codec_t codec_mask)
{
	/* since telit is the first module ever written we got to choose the codec mask to 
	 * match their spec and we can bypass mapping from wat codec values to telit values */
	char codec_cmd[WAT_MAX_CMD_SZ];
	snprintf(codec_cmd, sizeof(codec_cmd), "AT#CODEC=%d", codec_mask);
	wat_cmd_enqueue(span, codec_cmd, wat_response_set_codec, NULL, span->config.timeout_command);
	return WAT_SUCCESS;
}
示例#4
0
文件: wat_core.c 项目: sangoma/libwat
/* This function is executed once the SIM is Inserted and ready */
static wat_status_t wat_span_perform_post_start(wat_span_t *span)
{
	/* Enable Calling Line Presentation */
	wat_cmd_enqueue(span, "AT+CLIP=1", wat_response_clip, NULL, span->config.timeout_command);
	
	/* Set the Call Class to voice  */
	/* TODO: The FCLASS should be set before sending ATD command for each call */
	wat_cmd_enqueue(span, "AT+FCLASS=8", NULL, NULL, span->config.timeout_command);

	/* Call module specific start here */
	span->module.start(span);

	span->module.set_codec(span, span->config.codec_mask);

	/* Get some information about the chip */
	
	/* Get Module Model Identification */
	wat_cmd_enqueue(span, "AT+CGMM", wat_response_cgmm, NULL, span->config.timeout_command);

	/* Get Module Manufacturer Identification */
	wat_cmd_enqueue(span, "AT+CGMI", wat_response_cgmi, NULL, span->config.timeout_command);

	/* Get Module Revision Identification */
	wat_cmd_enqueue(span, "AT+CGMR", wat_response_cgmr, NULL, span->config.timeout_command);

	/* Get Module Serial Number */
	wat_cmd_enqueue(span, "AT+CGSN", wat_response_cgsn, NULL, span->config.timeout_command);

	/* Get Module IMSI */
	wat_cmd_enqueue(span, "AT+CIMI", wat_response_cimi, NULL, span->config.timeout_command);

	/* Signal Quality */
	wat_cmd_enqueue(span, "AT+CSQ", wat_response_csq, NULL, span->config.timeout_command);
	
	/* Enable Network Registration Unsolicited result code */
	wat_cmd_enqueue(span, "AT+CREG=1", NULL, NULL, span->config.timeout_command);

	/* Check Registration Status in case module is already registered */
	wat_cmd_enqueue(span, "AT+CREG?", wat_response_creg, NULL, span->config.timeout_command);

	wat_cmd_enqueue(span, NULL, wat_response_post_start_complete, NULL, 0);

	wat_sched_timer(span->sched, "signal_monitor", span->config.signal_poll_interval, wat_scheduled_csq, (void*) span, NULL);
	return WAT_SUCCESS;
}
示例#5
0
文件: wat_core.c 项目: sangoma/libwat
static wat_status_t wat_span_perform_start(wat_span_t *span)
{
	memset(span->calls, 0, sizeof(span->calls));
	memset(span->notifys, 0, sizeof(span->notifys));
	memset(&span->net_info, 0, sizeof(span->net_info));
	
	if (wat_queue_create(&span->event_queue, WAT_EVENT_QUEUE_SZ) != WAT_SUCCESS) {
		wat_log_span(span, WAT_LOG_CRIT, "Failed to create queue\n");
		return WAT_FAIL;
	}

	if (wat_queue_create(&span->cmd_queue, WAT_CMD_QUEUE_SZ) != WAT_SUCCESS) {
		wat_log_span(span, WAT_LOG_CRIT, "Failed to create queue\n");
		return WAT_FAIL;
	}

	if (wat_queue_create(&span->sms_queue, WAT_MAX_SMSS_PER_SPAN) != WAT_SUCCESS) {
		wat_log_span(span, WAT_LOG_CRIT, "Failed to create queue\n");
		return WAT_FAIL;
	}

	if (wat_buffer_create(&span->buffer, WAT_BUFFER_SZ) != WAT_SUCCESS) {
		wat_log_span(span, WAT_LOG_CRIT, "Failed to create buffer\n");
		return WAT_FAIL;
	}

	if (wat_sched_create(&span->sched, "span_schedule") != WAT_SUCCESS) {
		wat_log_span(span, WAT_LOG_CRIT, "Failed to create scheduler\n");
		return WAT_FAIL;
	}

	wat_log_span(span, WAT_LOG_DEBUG, "Starting span\n");

	wat_cmd_register(span, "+CRING", wat_notify_cring);

	wat_cmd_register(span, "+CMT", wat_notify_cmt);

	wat_cmd_register(span, "+CLIP", wat_notify_clip);
	wat_cmd_register(span, "+CREG", wat_notify_creg);

#if 0
	wat_cmd_register(span, "+CDIP", wat_notify_cdip);
	wat_cmd_register(span, "+CNAP", wat_notify_cnap);
	wat_cmd_register(span, "+CCWA", wat_notify_ccwa);
#endif

	/* Module soft reset */
	wat_cmd_enqueue(span, "ATZ", wat_response_atz, NULL, 60000);

	/* Disable echo mode */
	wat_cmd_enqueue(span, "ATE0", wat_response_ate, NULL, span->config.timeout_command);

	wat_cmd_enqueue(span, "ATX4", NULL, NULL, span->config.timeout_command);

	/* Enable Mobile Equipment Error Reporting, numeric mode */
	wat_cmd_enqueue(span, "AT+CMEE=1", NULL, NULL, span->config.timeout_command);

	/* Enable extended format reporting */
	wat_cmd_enqueue(span, "AT+CRC=1", NULL, NULL, span->config.timeout_command);

	if (wat_test_flag(&span->module, WAT_MODFLAG_IS_CDMA)) {
		/* This is a CDMA module, no SIM here */
		wat_log_span(span, WAT_LOG_DEBUG, "CDMA module does not require waiting for SIM ...\n");
		if (span->state < WAT_SPAN_STATE_POST_START) {
			wat_span_set_state(span, WAT_SPAN_STATE_POST_START);
		}
	} else {
		span->module.wait_sim(span);
		wat_sched_timer(span->sched, "wait_sim", span->config.timeout_wait_sim, wat_scheduled_wait_sim, (void *) span, &span->timeouts[WAT_TIMEOUT_WAIT_SIM]);
	}
	
	return WAT_SUCCESS;
}
示例#6
0
wat_status_t telit_start(wat_span_t *span)
{
	wat_log_span(span, WAT_LOG_DEBUG, "Starting Telit module\n");

	/* Section 2.1 of Telit AT Commands reference Guide recommends these options to be enabled */
	wat_cmd_enqueue(span, "AT#SELINT=2", wat_response_selint, NULL, span->config.timeout_command);

	wat_cmd_enqueue(span, "AT#SMSMODE=1", wat_response_smsmode, NULL, span->config.timeout_command);

	/* From Telit AT commands reference guide, page 105: Set AT#REGMODE=1
	 * makes CREG behavior more formal */
	wat_cmd_enqueue(span, "AT#REGMODE=1", NULL, NULL, span->config.timeout_command);
	wat_cmd_enqueue(span, "AT#DVI=1,1,0", wat_response_dvi, NULL, span->config.timeout_command);

	/* Enable Echo cancellation */
	wat_cmd_enqueue(span, "AT#SHFEC=1", NULL, NULL, span->config.timeout_command);
	wat_cmd_enqueue(span, "AT#SHSEC=1", NULL, NULL, span->config.timeout_command);

	/* Disable Sidetone as it sounds like echo on calls with long delay (e.g SIP calls) */
	wat_cmd_enqueue(span, "AT#SHSSD=0", wat_response_shssd, NULL, span->config.timeout_command);

	/* I guess we want full CPU power! */
	wat_cmd_enqueue(span, "AT#CPUMODE=1", NULL, NULL, span->config.timeout_command);

	/* Enable codec notifications 
	 * (format = 1 is text, mode 2 is short mode to get notifications only including the codec in use) */
	wat_cmd_enqueue(span, "AT#CODECINFO=1,2", wat_response_codecinfo, NULL, span->config.timeout_command);
	wat_cmd_register(span, "#CODECINFO", wat_notify_codec_info);
	
	/* Make sure the DIALMODE is set to 0 to receive an OK code as soon as possible
	 * the option of using DIALMODE=2 is tempting as provides progress status 
	 * notifications (DIALING, RINGING, CONNECTED, RELEASED, DISCONNECTED), but the modem
	 * will not accept any further commands in the meantime, which is not convenient */
	wat_cmd_enqueue(span, "AT#DIALMODE=0", NULL, NULL, span->config.timeout_command);

	/* Enable automatic Band selection */
	wat_cmd_enqueue(span, "AT+COPS=0", NULL, NULL, span->config.timeout_command);

	switch (span->config.band) {
		case WAT_BAND_900_1800:
			wat_cmd_enqueue(span, "AT#BND=0", NULL, NULL, span->config.timeout_command);
			break;
		case WAT_BAND_900_1900:
			wat_cmd_enqueue(span, "AT#BND=1", NULL, NULL, span->config.timeout_command);
			break;
		case WAT_BAND_850_1800:
			wat_cmd_enqueue(span, "AT#BND=2", NULL, NULL, span->config.timeout_command);
			break;
		case WAT_BAND_850_1900:
			wat_cmd_enqueue(span, "AT#BND=3", NULL, NULL, span->config.timeout_command);
			break;
		default:
			wat_log_span(span, WAT_LOG_CRIT, "Unsupported band value:%d\n", span->config.band);
		case WAT_BAND_AUTO:
			wat_cmd_enqueue(span, "AT#AUTOBND=2", NULL, NULL, span->config.timeout_command);
			break;
	}

	return WAT_SUCCESS;
}