Re: [PATCH] hal probe modem caps ondemand



2008/5/6 Alex Kanavin <ak sensi org>:
> 2008/5/4 Vitja Makarov <vitja makarov gmail com>:
>
> > 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.
>
>  In practice most if not all phones seem to use protocol 1 (generic
>  v.25) in their usb interface descriptions and require probing, but it
>  wouldn't hurt to list the other protocols as well. Otherwise, the
>  patch seems fine to me (if the coding style is ok - someone else
>  should review that). A much simpler patch for just tagging interface
>  class 2/subclass 2 devices as modems has just been committed, so you
>  should redo your patch against that.
>
>  --
>  Alexander
>

I'm wondering what for are CDMA, 3G, GSM subclasses.

Here is new version of patch.
It simply calls prober for V.250 CDC-ACM modems.
Also I don't understand why we don't check interface.class and only
test interface.subclass?

and some prober fixes, I'm not sure it should lay in
hald/linux/probing as it's actually callout,
but can be used as prober too.


vitja.
diff --git a/fdi/information/10freedesktop/10-modem.fdi b/fdi/information/10freedesktop/10-modem.fdi
index b5b6200..57490fd 100644
--- a/fdi/information/10freedesktop/10-modem.fdi
+++ b/fdi/information/10freedesktop/10-modem.fdi
@@ -282,6 +282,7 @@
         <match key="@info.parent:usb.interface.subclass" int="0x02">
           <append key="info.capabilities" type="strlist">modem</append>
           <append key="modem.command_sets" type="strlist">V.250</append>
+          <append key="info.callouts.add" type="strlist">hald-probe-modem</append>
         </match>
       </match>
 
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..43300e4
--- /dev/null
+++ b/hald/linux/probing/probe-modem.c
@@ -0,0 +1,167 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
+#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: are they 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;
+
+	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(%s): %s", device, 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]