void main() { int fildes; fildes = setup_modem(); modem_send_command( fildes, MODEM_RESET_STRING ); modem_receive_response( fildes ); if ( strcmp(message, "OK\n") != 0 ) { fprintf( stderr, "Modem did not return OK on reset.\n" ); exit(1); } do { modem_send_command( fildes, MODEM_DIAL_STRING ); modem_receive_response( fildes ); } while ( strcmp(message, "BUSY\n") == 0 ); printf("modem returned: %s\n", message); close(fildes); exit(0); }
static int modem_probe_caps(int fd, glong timeout_ms) { const char *gcap_responses[] = { GCAP_TAG, NULL }; const char *terminators[] = { "OK", "ERROR", "ERR", "+CME ERROR", NULL }; char *reply = NULL; int idx = -1, term_idx = -1, ret = 0; gboolean try_ati = FALSE; GTimeVal start, end; gboolean send_success; /* If a delay was specified, start a bit later */ if (timeout_ms > 500) { g_usleep (500000); timeout_ms -= 500; } /* Standard response timeout case */ timeout_ms += 3000; while (timeout_ms > 0) { GTimeVal diff; gulong sleep_time = 100000; g_get_current_time (&start); idx = term_idx = 0; send_success = modem_send_command (fd, "AT+GCAP\r\n"); if (send_success) idx = modem_wait_reply (fd, 2, gcap_responses, terminators, &term_idx, &reply); else sleep_time = 300000; g_get_current_time (&end); g_timeval_subtract (&diff, &end, &start); timeout_ms -= (diff.tv_sec * 1000) + (diff.tv_usec / 1000); if (send_success) { if (0 == term_idx && 0 == idx) { /* Success */ verbose ("GCAP response: %s", reply); ret = parse_gcap (reply); break; } else if (0 == term_idx && -1 == idx) { /* Just returned "OK" but no GCAP (Sierra) */ try_ati = TRUE; break; } else if (3 == term_idx && -1 == idx) { /* No SIM (Huawei) */ try_ati = TRUE; break; } else if (1 == term_idx || 2 == term_idx) { try_ati = TRUE; } else verbose ("timed out waiting for GCAP reply (idx %d, term_idx %d)", idx, term_idx); g_free (reply); reply = NULL; } g_usleep (sleep_time); timeout_ms -= sleep_time / 1000; } if (!ret && try_ati) { const char *ati_responses[] = { GCAP_TAG, NULL }; /* Many cards (ex Sierra 860 & 875) won't accept AT+GCAP but * accept ATI when the SIM is missing. Often the GCAP info is * in the ATI response too. */ g_free (reply); reply = NULL; verbose ("GCAP failed, trying ATI...%s", ""); if (modem_send_command (fd, "ATI\r\n")) { idx = modem_wait_reply (fd, 3, ati_responses, terminators, &term_idx, &reply); if (0 == term_idx && 0 == idx) { verbose ("ATI response: %s", reply); ret = parse_gcap (reply); } } } g_free (reply); reply = NULL; /* Try an alternate method on some hardware (ex BUSlink SCWi275u) */ if ((idx != -2) && !(ret & MODEM_CAP_GSM) && !(ret & MODEM_CAP_IS707_A)) { const char *gmm_responses[] = { GMM_TAG, NULL }; if (modem_send_command (fd, "AT+GMM\r\n")) { idx = modem_wait_reply (fd, 5, gmm_responses, terminators, &term_idx, &reply); if (0 == term_idx && 0 == idx) { verbose ("GMM response: %s", reply); ret |= parse_gmm (reply); } g_free (reply); } } return ret; }