[PATCH] hal probe modem caps ondemand
- From: "Vitja Makarov" <vitja makarov gmail com>
- To: hal lists freedesktop org, "network manager" <networkmanager-list gnome org>
- Subject: [PATCH] hal probe modem caps ondemand
- Date: Sun, 4 May 2008 11:34:13 +0400
Probe CDC-ACM modems, found in most cell phones on the fly, using
AT+GCAP modem command.
I tested it with 1 Nokia GSM phone, and 2 CDMA.
vitja.
diff --git a/fdi/information/10freedesktop/10-modem.fdi b/fdi/information/10freedesktop/10-modem.fdi
index 1a93013..6753b51 100644
--- a/fdi/information/10freedesktop/10-modem.fdi
+++ b/fdi/information/10freedesktop/10-modem.fdi
@@ -275,7 +275,34 @@
</match>
</match>
</match>
-
+
+ <!-- command_sets isn't set, try generic way, now only CDC_ACM -->
+ <match key="modem.command_sets" exists="false">
+ <!-- USB_CLASS_COMM -->
+ <match key="@info.parent:usb.interface.class" int="0x2">
+ <!-- USB_CDC_SUBCLASS_ACM -->
+ <match key="@info.parent:usb.interface.subclass" int="0x2">
+ <!-- V25TER, probe it on the fly -->
+ <match key="@info.parent:usb.interface.protocol" int="1">
+ <append key="info.capabilities" type="strlist">modem</append>
+ <append key="modem.command_sets" type="strlist">V25TER</append>
+ <append key="info.callouts.add" type="strlist">hald-probe-modem</append>
+ </match>
+ <!-- GSM -->
+ <match key="@info.parent:usb.interface.protocol" int="4">
+ <append key="info.capabilities" type="strlist">modem</append>
+ <append key="modem.command_sets" type="strlist">GSM-07.07</append>
+ <append key="modem.command_sets" type="strlist">GSM-07.05</append>
+ </match>
+ <!-- TODO: match 3G modems -->
+ <!-- CDMA -->
+ <match key="@info.parent:usb.interface.protocol" int="6">
+ <append key="info.capabilities" type="strlist">modem</append>
+ <append key="modem.command_sets" type="strlist">IS-707-A</append>
+ </match>
+ </match>
+ </match>
+ </match>
</match>
</device>
</deviceinfo>
diff --git a/hald/linux/probing/Makefile.am b/hald/linux/probing/Makefile.am
index 274b870..9e0c7ec 100644
--- a/hald/linux/probing/Makefile.am
+++ b/hald/linux/probing/Makefile.am
@@ -20,7 +20,8 @@ libexec_PROGRAMS = \
hald-probe-serial \
hald-probe-ieee1394-unit \
hald-probe-net-bluetooth \
- hald-probe-video4linux
+ hald-probe-video4linux \
+ hald-probe-modem
endif
hald_probe_smbios_SOURCES = probe-smbios.c ../../logger.c
@@ -39,6 +40,9 @@ hald_probe_hiddev_LDADD = $(top_builddir)/libhal/libhal.la
hald_probe_serial_SOURCES = probe-serial.c ../../logger.c
hald_probe_serial_LDADD = $(top_builddir)/libhal/libhal.la
+hald_probe_modem_SOURCES = probe-modem.c ../../logger.c
+hald_probe_modem_LDADD = $(top_builddir)/libhal/libhal.la
+
hald_probe_storage_SOURCES = probe-storage.c linux_dvd_rw_utils.c linux_dvd_rw_utils.h ../../logger.c
hald_probe_storage_LDADD = $(top_builddir)/libhal/libhal.la $(top_builddir)/partutil/libpartutil.la @GLIB_LIBS@ @VOLUME_ID_LIBS@
diff --git a/hald/linux/probing/probe-modem.c b/hald/linux/probing/probe-modem.c
new file mode 100644
index 0000000..4599faa
--- /dev/null
+++ b/hald/linux/probing/probe-modem.c
@@ -0,0 +1,165 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <termios.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "libhal/libhal.h"
+#include "../../logger.h"
+
+#define MODEM_CAP_GSM 0x0001 /* GSM commands */
+#define MODEM_CAP_IS707_A 0x0002 /* CDMA circuit switched data commands */
+#define MODEM_CAP_DS 0x0004 /* data compression */
+#define MODEM_CAP_ES 0x0008 /* error control */
+#define MODEM_CAP_FCLASS 0x0010 /* Fax commands */
+#define MODEM_CAP_MS 0x0020 /* Modulation control commands */
+#define MODEM_CAP_W 0x0040 /* Wireless commands */
+
+struct modem_caps {
+ char *name;
+ int bits;
+};
+
+static struct modem_caps modem_caps[] = {
+ {"+CGSM", MODEM_CAP_GSM},
+ /* TODO: is that the same */
+ {"+CIS707-A", MODEM_CAP_IS707_A},
+ {"+CIS707", MODEM_CAP_IS707_A},
+ {"+CIS707P", MODEM_CAP_IS707_A},
+ {NULL}
+} ;
+
+#define AT_CAPS_PROBE "AT+GCAP\r\n"
+static
+int modem_probe_caps(int fd)
+{
+ char buf[200];
+ char *ptr, *field = NULL;
+ int err, ret = 0;
+
+ err = write(fd, AT_CAPS_PROBE, sizeof(AT_CAPS_PROBE) - 1);
+
+ if (err != sizeof(AT_CAPS_PROBE) - 1)
+ return -1;
+
+ /* 100ms is enough for modem to send all the data */
+ usleep(100000);
+
+ err = read(fd, buf, sizeof(buf) - 1);
+ if (err <= 0)
+ return -1;
+ buf[err] = 0;
+
+ /* check okay reply */
+ ptr = strstr(buf, "\r\nOK\r\n");
+ if (!ptr)
+ return -1;
+ *ptr = 0;
+
+ /* find +GCAP: string */
+ ptr = strstr(buf, "\r\n+GCAP:");
+
+ if (ptr == NULL)
+ return -1;
+ ptr += 8;
+
+ /* and parse it */
+ do {
+ err = *ptr == '\0' || *ptr == '\r' || *ptr == '\n';
+ if (*ptr == ' ' || *ptr == ',' || err) {
+ *ptr = 0;
+ if (field) {
+ struct modem_caps *cap = modem_caps;
+
+ while (cap->name) {
+ if (!strcmp(cap->name, field))
+ ret |= cap->bits;
+ cap++;
+ }
+ }
+ field = NULL;
+ } else if (NULL == field) {
+ field = ptr;
+ }
+ ptr++;
+ } while (!err);
+
+ return ret;
+}
+
+int main(int argc, char *argv[])
+{
+ struct termios orig, attrs;
+ DBusError error;
+ LibHalContext *ctx;
+ char *udi;
+ char *device;
+ int fd, caps;
+ system("set > /tmp/aa");
+
+ setup_logger();
+
+ if ((udi = getenv("UDI")) == NULL) {
+ HAL_ERROR(("UDI is not set"));
+ return -1;
+ }
+
+ if ((device = getenv("HAL_PROP_SERIAL_DEVICE")) == NULL) {
+ HAL_ERROR(("HAL_PROP_SERIAL_DEVICE is not set"));
+ return -1;
+ }
+
+ fd = open(device, O_RDWR|O_NDELAY);
+
+ if (-1 == fd) {
+ HAL_ERROR(("open():", strerror(errno)));
+ return -1;
+ }
+
+ if (tcgetattr(fd, &orig))
+ return -1;
+
+ memcpy(&attrs, &orig, sizeof(attrs));
+ attrs.c_iflag &= ~(IGNCR | ICRNL | IUCLC | INPCK | IXON | IXANY | IGNPAR);
+ attrs.c_oflag &= ~(OPOST | OLCUC | OCRNL | ONLCR | ONLRET);
+ attrs.c_lflag &= ~(ICANON | XCASE | ECHO | ECHOE | ECHONL);
+ attrs.c_lflag &= ~(ECHO | ECHOE);
+ attrs.c_cc[VMIN] = 1;
+ attrs.c_cc[VTIME] = 0;
+ attrs.c_cc[VEOF] = 1;
+ tcsetattr(fd, TCSANOW, &attrs);
+ caps = modem_probe_caps(fd);
+ tcsetattr(fd, TCSANOW, &orig);
+
+ if (caps < 0) {
+ HAL_ERROR(("Couldn't get caps"));
+ return -1;
+ }
+
+ dbus_error_init (&error);
+
+ if ((ctx = libhal_ctx_init_direct(&error)) == NULL) {
+ HAL_ERROR(("ctx init failed"));
+ return -1;
+ }
+
+ if (caps & MODEM_CAP_GSM) {
+ HAL_DEBUG(("Found GSM modem"));
+ libhal_device_property_strlist_append(ctx, udi, "modem.command_sets", "GSM-07.07", NULL);
+ libhal_device_property_strlist_append(ctx, udi, "modem.command_sets", "GSM-07.05", NULL);
+ }
+
+ if (caps & MODEM_CAP_IS707_A) {
+ HAL_DEBUG(("Found CDMA modem"));
+ libhal_device_property_strlist_append(ctx, udi, "modem.command_sets", "IS-707-A", NULL);
+ }
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]