diff options
Diffstat (limited to 'modem-probe/modem-probe.c')
-rw-r--r-- | modem-probe/modem-probe.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/modem-probe/modem-probe.c b/modem-probe/modem-probe.c index 9494c3b..ddeb413 100644 --- a/modem-probe/modem-probe.c +++ b/modem-probe/modem-probe.c @@ -306,6 +306,7 @@ static int modem_probe_caps(int fd) g_free (reply); reply = NULL; + verbose ("GCAP failed, trying ATI..."); 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) { @@ -313,7 +314,9 @@ static int modem_probe_caps(int fd) ret = parse_gcap (reply); } } - } + } else + verbose ("timed out waiting for GCAP reply (idx %d, term_idx %d)", idx, term_idx); + g_free (reply); reply = NULL; @@ -339,6 +342,7 @@ print_usage (void) { printf("Usage: probe-modem [options] <device>\n" " --export export key/value pairs\n" + " --delay <ms> delay before probing (1 to 3000 ms inclusive)\n" " --verbose print verbose debugging output\n" " --log <file> log all output\n" " --help\n\n"); @@ -356,6 +360,7 @@ main(int argc, char *argv[]) { static const struct option options[] = { { "export", 0, NULL, 'x' }, + { "delay", required_argument, NULL, 'a' }, { "verbose", 0, NULL, 'v' }, { "quiet", 0, NULL, 'q' }, { "log", required_argument, NULL, 'l' }, @@ -365,9 +370,11 @@ main(int argc, char *argv[]) const char *device = NULL; const char *logpath = NULL; + const char *delay_str = NULL; gboolean export = 0; struct termios orig, attrs; int fd, caps; + guint32 delay_ms = 0; while (1) { int option; @@ -380,6 +387,9 @@ main(int argc, char *argv[]) case 'x': export = TRUE; break; + case 'a': + delay_str = optarg; + break; case 'v': verbose = TRUE; break; @@ -418,6 +428,24 @@ main(int argc, char *argv[]) do_exit (3); } + verbose ("probing %s", device); + + if (delay_str) { + unsigned long int tmp; + + tmp = strtoul (delay_str, NULL, 10); + if (tmp < 1 || tmp > 3000) { + g_printerr ("Invalid delay: %s\n", delay_str); + do_exit (3); + } + delay_ms = (guint32) tmp; + } + + if (delay_ms) { + verbose ("waiting %ums before probing", delay_ms); + g_usleep (delay_ms * 1000); + } + fd = open (device, O_RDWR | O_EXCL | O_NONBLOCK); if (fd < 0) { g_printerr ("open(%s) failed: %d\n", device, errno); @@ -439,7 +467,7 @@ main(int argc, char *argv[]) attrs.c_cc[VEOF] = 1; attrs.c_cflag &= ~(CBAUD | CSIZE | CSTOPB | CLOCAL | PARENB); - attrs.c_cflag |= (B9600 | CS8 | CREAD | 0 | 0 | 0); + attrs.c_cflag |= (B9600 | CS8 | CREAD | PARENB); tcsetattr (fd, TCSANOW, &attrs); caps = modem_probe_caps (fd); |