summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2008-12-16 21:50:51 -0500
committerDan Williams <dcbw@redhat.com>2008-12-16 21:50:51 -0500
commit88f7fd43dab785b3fb450507b470e2f29dc4a6ae (patch)
tree3320db00a870f7714dc685ab418213369e9e23cd
parent6f85879c00a0a1471405e67205751187b579b354 (diff)
modem prober fixes and additional logging capability
-rw-r--r--probe-modem/62-probe-modem-capabilities.rules12
-rw-r--r--probe-modem/77-probe-modem-capabilities.rules10
-rw-r--r--probe-modem/probe-modem.89
-rw-r--r--probe-modem/probe-modem.c107
4 files changed, 96 insertions, 42 deletions
diff --git a/probe-modem/62-probe-modem-capabilities.rules b/probe-modem/62-probe-modem-capabilities.rules
deleted file mode 100644
index b430fe9..0000000
--- a/probe-modem/62-probe-modem-capabilities.rules
+++ /dev/null
@@ -1,12 +0,0 @@
-# do not edit this file, it will be overwritten on update
-
-ACTION!="add", GOTO="persistent_storage_edd_end"
-SUBSYSTEM!="block", GOTO="persistent_storage_edd_end"
-KERNEL!="sd*|hd*", GOTO="persistent_storage_edd_end"
-
-# BIOS Enhanced Disk Device
-ENV{DEVTYPE}=="disk", IMPORT{program}="edd_id --export $tempnode"
-ENV{DEVTYPE}=="disk", ENV{ID_EDD}=="?*", SYMLINK+="disk/by-id/edd-$env{ID_EDD}"
-ENV{DEVTYPE}=="partition", ENV{ID_EDD}=="?*", SYMLINK+="disk/by-id/edd-$env{ID_EDD}-part%n"
-
-LABEL="persistent_storage_edd_end"
diff --git a/probe-modem/77-probe-modem-capabilities.rules b/probe-modem/77-probe-modem-capabilities.rules
new file mode 100644
index 0000000..72dffdf
--- /dev/null
+++ b/probe-modem/77-probe-modem-capabilities.rules
@@ -0,0 +1,10 @@
+# do not edit this file, it will be overwritten on update
+
+ACTION!="add|change", GOTO="probe_modem_end"
+SUBSYSTEM!="tty", GOTO="probe_modem_end"
+KERNEL!="tty*", GOTO="probe_modem_end"
+
+DRIVERS=="option|sierra|cdc-acm|hso", IMPORT{program}="probe-modem --export $tempnode"
+
+LABEL="probe_modem_end"
+
diff --git a/probe-modem/probe-modem.8 b/probe-modem/probe-modem.8
index 3370b1b..099a4b3 100644
--- a/probe-modem/probe-modem.8
+++ b/probe-modem/probe-modem.8
@@ -13,14 +13,19 @@ capabilities for Hayes-compatible modems.
opens the tty node specified at the commandline and prints the
discovered modem capabilities.
.SH OPTIONS
-The following commandline switches are supported to specify what modem_caps
-should print:
+The following commandline switches alter probe-modem's behavior:
.TP
.BI \-\-export
print values as environment keys
.TP
.BI \-\-verbose
print debugging information
+.TP
+.BI \-\-quiet
+only output to logfile, not stdout
+.TP
+.BI \-\-log <file>
+log output to <file>
.RE
.SH SEE ALSO
.BR udev (7)
diff --git a/probe-modem/probe-modem.c b/probe-modem/probe-modem.c
index 2d8f091..1aa868b 100644
--- a/probe-modem/probe-modem.c
+++ b/probe-modem/probe-modem.c
@@ -20,6 +20,7 @@
#include <string.h>
#include <stdlib.h>
#include <getopt.h>
+#include <time.h>
#include <glib.h>
@@ -35,6 +36,8 @@
#define MODEM_CAP_IS856_A 0x0200 /* CDMA 3G EVDO rev A */
static gboolean verbose = FALSE;
+static gboolean quiet = FALSE;
+static FILE *logfile = NULL;
struct modem_caps {
char *name;
@@ -55,9 +58,27 @@ static struct modem_caps modem_caps[] = {
{NULL}
};
-#define debug(fmt, args...) \
+static void
+printerr_handler (const char *string)
+{
+ if (logfile)
+ fprintf (logfile, "E: %s", string);
+ if (!quiet)
+ fprintf (stderr, "E: %s", string);
+}
+
+static void
+print_handler (const char *string)
+{
+ if (logfile)
+ fprintf (logfile, "L: %s", string);
+ if (!quiet)
+ fprintf (stdout, "L: %s", string);
+}
+
+#define verbose(fmt, args...) \
if (verbose) { \
- g_printerr ("%s(): " fmt "\n", G_STRFUNC, ##args); \
+ g_print ("%s(): " fmt "\n", G_STRFUNC, ##args); \
}
static gboolean
@@ -67,7 +88,7 @@ modem_send_command (int fd, const char *cmd)
guint32 i;
ssize_t written;
- debug ("Sending: '%s'", cmd);
+ verbose ("Sending: '%s'", cmd);
for (i = 0; i < strlen (cmd) && eagain_count > 0;) {
written = write (fd, cmd + i, 1);
@@ -153,7 +174,7 @@ modem_wait_reply (int fd,
buf[bytes_read] = 0;
g_string_append (result, buf);
- debug ("Got: '%s'", result->str);
+ verbose ("Got: '%s'", result->str);
lines = g_strsplit_set (result->str, "\n\r", 0);
@@ -203,7 +224,7 @@ parse_gcap (const char *buf)
caps = g_strsplit_set (p, " ,\t", 0);
if (!caps)
- return -1;
+ return 0;
for (iter = caps; *iter; iter++) {
struct modem_caps *cap = modem_caps;
@@ -230,7 +251,7 @@ parse_gmm (const char *buf)
gmm = g_strsplit_set (p, " ,\t", 0);
if (!gmm)
- return -1;
+ return 0;
/* BUSlink SCWi275u USB GPRS modem */
for (iter = gmm; *iter && !gsm; iter++) {
@@ -248,7 +269,7 @@ static int modem_probe_caps(int fd)
const char *gcap_responses[] = { GCAP_TAG, NULL };
const char *terminators[] = { "OK", "ERROR", "ERR", NULL };
char *reply = NULL;
- int idx, term_idx, ret = -1;
+ int idx, term_idx, ret = 0;
if (!modem_send_command (fd, "AT+GCAP\r\n"))
return -1;
@@ -256,7 +277,7 @@ static int modem_probe_caps(int fd)
idx = modem_wait_reply (fd, 3, gcap_responses, terminators, &term_idx, &reply);
if (0 == term_idx && 0 == idx) {
/* Success */
- debug ("GCAP response: %s", reply);
+ verbose ("GCAP response: %s", reply);
ret = parse_gcap (reply);
} else if (1 == term_idx || 2 == term_idx) {
const char *ati_responses[] = { GCAP_TAG, NULL };
@@ -271,7 +292,7 @@ static int modem_probe_caps(int fd)
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) {
- debug ("ATI response: %s", reply);
+ verbose ("ATI response: %s", reply);
ret = parse_gcap (reply);
}
}
@@ -286,7 +307,7 @@ static int modem_probe_caps(int fd)
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) {
- debug ("GMM response: %s", reply);
+ verbose ("GMM response: %s", reply);
ret |= parse_gmm (reply);
}
g_free (reply);
@@ -302,6 +323,7 @@ print_usage (void)
printf("Usage: probe-modem [options] <device>\n"
" --export export key/value pairs\n"
" --verbose print verbose debugging output\n"
+ " --log <file> log all output\n"
" --help\n\n");
}
@@ -311,11 +333,14 @@ main(int argc, char *argv[])
static const struct option options[] = {
{ "export", 0, NULL, 'x' },
{ "verbose", 0, NULL, 'v' },
+ { "quiet", 0, NULL, 'q' },
+ { "log", required_argument, NULL, 'l' },
{ "help", 0, NULL, 'h' },
{}
};
const char *device = NULL;
+ const char *logpath = NULL;
gboolean export = 0;
struct termios orig, attrs;
int fd, caps;
@@ -323,7 +348,7 @@ main(int argc, char *argv[])
while (1) {
int option;
- option = getopt_long(argc, argv, "xvh", options, NULL);
+ option = getopt_long (argc, argv, "xvl:qh", options, NULL);
if (option == -1)
break;
@@ -334,31 +359,55 @@ main(int argc, char *argv[])
case 'v':
verbose = TRUE;
break;
+ case 'l':
+ logpath = optarg;
+ break;
+ case 'q':
+ quiet = TRUE;
+ break;
case 'h':
print_usage ();
- return 1;
+ return 0;
default:
return 1;
}
}
+ if (logpath) {
+ time_t t = time (NULL);
+
+ logfile = fopen (logpath, "a+");
+ if (!logfile) {
+ fprintf (stderr, "Couldn't open/create logfile %s", logpath);
+ return 2;
+ }
+
+ fprintf (logfile, "\n**** Started: %s\n", ctime (&t));
+ g_set_printerr_handler (printerr_handler);
+ }
+
+ g_set_print_handler (print_handler);
+
device = argv[optind];
if (device == NULL) {
g_printerr ("no node specified\n");
- return 2;
+ fclose (logfile);
+ return 3;
}
fd = open (device, O_RDWR | O_EXCL | O_NONBLOCK);
if (fd < 0) {
g_printerr ("open(%s) failed: %d\n", device, errno);
- return 3;
+ if (logfile) fclose (logfile);
+ return 4;
}
if (tcgetattr (fd, &orig)) {
g_printerr ("tcgetattr(%s): failed %d\n", device, errno);
- return 4;
+ if (logfile) fclose (logfile);
+ return 5;
}
-
+
memcpy (&attrs, &orig, sizeof (attrs));
attrs.c_iflag &= ~(IGNCR | ICRNL | IUCLC | INPCK | IXON | IXANY | IGNPAR);
attrs.c_oflag &= ~(OPOST | OLCUC | OCRNL | ONLCR | ONLRET);
@@ -377,28 +426,30 @@ main(int argc, char *argv[])
if (caps < 0) {
g_printerr ("%s: couldn't get modem capabilities\n", device);
- return 5;
+ if (logfile) fclose (logfile);
+ return 6;
}
if (export) {
if (caps & MODEM_CAP_GSM)
- g_print ("ID_MODEM_GSM=1\n");
+ printf ("ID_MODEM_GSM=1\n");
if (caps & MODEM_CAP_IS707_A)
- g_print ("ID_MODEM_IS707_A=1\n");
+ printf ("ID_MODEM_IS707_A=1\n");
if (caps & MODEM_CAP_IS707_P)
- g_print ("ID_MODEM_IS707P=1\n");
+ printf ("ID_MODEM_IS707P=1\n");
if (caps & MODEM_CAP_IS856)
- g_print ("ID_MODEM_IS856=1\n");
+ printf ("ID_MODEM_IS856=1\n");
if (caps & MODEM_CAP_IS856_A)
- g_print ("ID_MODEM_IS856_A=1\n");
- } else {
- g_print ("%s: caps 0x%X%s%s%s%s\n", device, caps,
- caps & MODEM_CAP_GSM ? " GSM" : "",
- caps & (MODEM_CAP_IS707_A | MODEM_CAP_IS707_P) ? " CDMA-1x" : "",
- caps & MODEM_CAP_IS856 ? " EVDOr0" : "",
- caps & MODEM_CAP_IS856_A ? " EVDOrA" : "");
+ printf ("ID_MODEM_IS856_A=1\n");
}
+ verbose ("%s: caps (0x%X)%s%s%s%s\n", device, caps,
+ caps & MODEM_CAP_GSM ? " GSM" : "",
+ caps & (MODEM_CAP_IS707_A | MODEM_CAP_IS707_P) ? " CDMA-1x" : "",
+ caps & MODEM_CAP_IS856 ? " EVDOr0" : "",
+ caps & MODEM_CAP_IS856_A ? " EVDOrA" : "");
+
+ if (logfile) fclose (logfile);
return 0;
}