/* 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 New Message Indications To TE */ wat_cmd_enqueue(span, "AT+CNMI=2,2", wat_response_cnmi, NULL, span->config.timeout_command); /* Enable Calling Line Presentation */ wat_cmd_enqueue(span, "AT+CLIP=1", wat_response_clip, NULL, span->config.timeout_command); /* Set Operator mode */ wat_cmd_enqueue(span, "AT+COPS=3,0", wat_response_cops, 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); /* Check the PIN status, this will also report if there is no SIM inserted */ wat_cmd_enqueue(span, "AT+CPIN?", wat_response_cpin, NULL, 15000); /* 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; }
/* Check for pending commands, and execute command if module is not cmd_busy */ void wat_span_run_cmds(wat_span_t *span) { wat_cmd_t *cmd = NULL; if (!span->cmd_busy) { if (span->cmd_next) { /* Check if there are any priority command to be transmitted */ cmd = span->cmd_next; span->cmd_next = NULL; } else { /* Check if there are any commands waiting to be transmitted */ cmd = wat_queue_dequeue(span->cmd_queue); } if (cmd) { if (cmd->cmd == NULL) { /* This is a dummy command, just call the callback function */ wat_log_span(span, WAT_LOG_DEBUG, "Dequeuing dummy command %p\n", cmd->cb); cmd->cb(span, NULL, WAT_SUCCESS, cmd->obj, NULL); wat_safe_free(cmd); return; } span->cmd = cmd; span->cmd_busy = 1; if (span->config.debug_mask & WAT_DEBUG_AT_HANDLE) { char mydata[WAT_MAX_CMD_SZ]; wat_log_span(span, WAT_LOG_DEBUG, "Dequeuing command %s\n", format_at_data(mydata, span->cmd->cmd, strlen(span->cmd->cmd))); } wat_write_command(span); wat_sched_timer(span->sched, "command timeout", cmd->timeout, wat_cmd_timeout, (void*) span, &span->timeouts[WAT_TIMEOUT_CMD]); } } /* Check if there are any commands that we received */ wat_cmd_process(span); return; }
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; }