Re: [PATCH] [UPDATED] identify mbm modems by GUID



On Mon, 2010-06-28 at 16:22 +0200, Jonas Sjöquist wrote:
> This updated version of the patch traverses the USB descriptors to find the MBM GUID. If someone could
> try this patch with a SE MD300 or SE MD400 I would be grateful, as I've been told that the these devices should
> use the same GUID.

Thanks; I'll look over this in more detail in a bit; but it doesn't look
like it may yet be robust enough against format problems in the
descriptor variable.  The way usb_id handles descriptors is:

http://git.kernel.org/?p=linux/hotplug/udev.git;a=blob;f=extras/usb_id/usb_id.c;h=fabd09283def1dfda56fc4828731d25e423e0bac;hb=HEAD#l184

which is a bit more complex.  Specifically, we should check if 'buf +=
buf[0]' will point us *beyond* 'size' to make sure we don't overflow the
buffer.  If you fix that up before I get there, awesome :)

Thanks again!
Dan 

> Regards,
> Jonas Sjöquist
> 
> ---
> 
> diff --git a/plugins/77-mm-ericsson-mbm.rules b/plugins/77-mm-ericsson-mbm.rules
> deleted file mode 100644
> index 8804036..0000000
> --- a/plugins/77-mm-ericsson-mbm.rules
> +++ /dev/null
> @@ -1,51 +0,0 @@
> -# do not edit this file, it will be overwritten on update
> -
> -ACTION!="add|change", GOTO="mm_mbm_end"
> -SUBSYSTEM!="usb", GOTO="mm_mbm_end"
> -ENV{DEVTYPE}!="usb_device", GOTO="mm_mbm_end"
> -
> -# Ericsson F3507g
> -ATTRS{idVendor}=="0bdb", ATTRS{idProduct}=="1900", ENV{ID_MM_ERICSSON_MBM}="1"
> -ATTRS{idVendor}=="0bdb", ATTRS{idProduct}=="1902", ENV{ID_MM_ERICSSON_MBM}="1"
> -
> -# Ericsson F3607gw
> -ATTRS{idVendor}=="0bdb", ATTRS{idProduct}=="1904", ENV{ID_MM_ERICSSON_MBM}="1"
> -ATTRS{idVendor}=="0bdb", ATTRS{idProduct}=="1905", ENV{ID_MM_ERICSSON_MBM}="1"
> -ATTRS{idVendor}=="0bdb", ATTRS{idProduct}=="1906", ENV{ID_MM_ERICSSON_MBM}="1"
> -
> -# Ericsson F3307
> -ATTRS{idVendor}=="0bdb", ATTRS{idProduct}=="190a", ENV{ID_MM_ERICSSON_MBM}="1"
> -ATTRS{idVendor}=="0bdb", ATTRS{idProduct}=="1909", ENV{ID_MM_ERICSSON_MBM}="1"
> -
> -# Ericsson C3607w
> -ATTRS{idVendor}=="0bdb", ATTRS{idProduct}=="1049", ENV{ID_MM_ERICSSON_MBM}="1"
> -
> -# Ericsson C3607w v2
> -ATTRS{idVendor}=="0bdb", ATTRS{idProduct}=="190b", ENV{ID_MM_ERICSSON_MBM}="1"
> -
> -# Sony-Ericsson MD300
> -ATTRS{idVendor}=="0fce", ATTRS{idProduct}=="d0cf", ENV{ID_MM_ERICSSON_MBM}="1"
> -
> -# Sony-Ericsson MD400
> -ATTRS{idVendor}=="0fce", ATTRS{idProduct}=="d0e1", ENV{ID_MM_ERICSSON_MBM}="1"
> -
> -# Dell 5530 HSDPA
> -ATTRS{idVendor}=="413c", ATTRS{idProduct}=="8147", ENV{ID_MM_ERICSSON_MBM}="1"
> -
> -# Dell F3607gw
> -ATTRS{idVendor}=="413c", ATTRS{idProduct}=="8183", ENV{ID_MM_ERICSSON_MBM}="1"
> -ATTRS{idVendor}=="413c", ATTRS{idProduct}=="8184", ENV{ID_MM_ERICSSON_MBM}="1"
> -
> -# Dell F3307
> -ATTRS{idVendor}=="413c", ATTRS{idProduct}=="818b", ENV{ID_MM_ERICSSON_MBM}="1"
> -ATTRS{idVendor}=="413c", ATTRS{idProduct}=="818c", ENV{ID_MM_ERICSSON_MBM}="1"
> -
> -# Toshiba
> -ATTRS{idVendor}=="0930", ATTRS{idProduct}=="130b", ENV{ID_MM_ERICSSON_MBM}="1"
> -
> -# Toshiba F3607gw
> -ATTRS{idVendor}=="0930", ATTRS{idProduct}=="130c", ENV{ID_MM_ERICSSON_MBM}="1"
> -ATTRS{idVendor}=="0930", ATTRS{idProduct}=="1311", ENV{ID_MM_ERICSSON_MBM}="1"
> -
> -LABEL="mm_mbm_end"
> -
> diff --git a/plugins/Makefile.am b/plugins/Makefile.am
> index 8192653..e302965 100644
> --- a/plugins/Makefile.am
> +++ b/plugins/Makefile.am
> @@ -277,7 +277,6 @@ libmm_plugin_simtech_la_LDFLAGS = \
>  
>  udevrulesdir = $(UDEV_BASE_DIR)/rules.d
>  udevrules_DATA = \
> -	77-mm-ericsson-mbm.rules \
>  	77-mm-zte-port-types.rules \
>  	77-mm-longcheer-port-types.rules \
>  	77-mm-simtech-port-types.rules
> diff --git a/plugins/mm-plugin-mbm.c b/plugins/mm-plugin-mbm.c
> index 5554d84..171c9cd 100644
> --- a/plugins/mm-plugin-mbm.c
> +++ b/plugins/mm-plugin-mbm.c
> @@ -25,6 +25,9 @@
>  #include "mm-plugin-mbm.h"
>  #include "mm-modem-mbm.h"
>  
> +#include <fcntl.h>
> +#include <unistd.h>
> +
>  G_DEFINE_TYPE (MMPluginMbm, mm_plugin_mbm, MM_TYPE_PLUGIN_BASE)
>  
>  int mm_plugin_major_version = MM_PLUGIN_MAJOR_VERSION;
> @@ -57,6 +60,28 @@ probe_result (MMPluginBase *base,
>      mm_plugin_base_supports_task_complete (task, get_level_for_capabilities (capabilities));
>  }
>  
> +#define GUID_OFFSET 5
> +#define MDLM_FUNC_DESC 0x12
> +
> +static int
> +cmp_mbm_guid(unsigned char *desc, ssize_t size)
> +{
> +    unsigned char *buf = desc;
> +    unsigned int i;
> +
> +    const char mbm_guid[16] = {
> +            0xa3, 0x17, 0xa8, 0x8b, 0x04, 0x5e, 0x4f, 0x01,
> +            0xa6, 0x07, 0xc0, 0xff, 0xcb, 0x7e, 0x39, 0x2a,
> +    };
> +
> +    for (i=0;i<size;i++) {
> +            if (buf[2] == MDLM_FUNC_DESC)
> +                    return memcmp(&buf[GUID_OFFSET], mbm_guid, sizeof(mbm_guid));
> +            buf += buf[0];
> +    }
> +    return 1;
> +}
> +
>  static MMPluginSupportsResult
>  supports_port (MMPluginBase *base,
>                 MMModem *existing,
> @@ -67,7 +92,10 @@ supports_port (MMPluginBase *base,
>      GUdevDevice *port, *physdev;
>      guint32 cached = 0, level;
>      const char *driver, *subsys, *physdev_path;
> -    gboolean is_mbm;
> +    char *desc_path;
> +    unsigned char desc[4096];
> +    int fd;
> +    ssize_t size;
>  
>      /* Can't do anything with non-serial ports */
>      port = mm_plugin_base_supports_task_get_port (task);
> @@ -90,15 +118,28 @@ supports_port (MMPluginBase *base,
>  
>      /* Look up the port's physical device and see if this port is really an
>       * 'mbm' modem, since we have no other way of telling.
> +     * The 'mbm' modem is identified by the GUID in the MDLM descriptor.
>       */
>      physdev_path = mm_plugin_base_supports_task_get_physdev_path (task);
>      physdev = g_udev_client_query_by_sysfs_path (client, physdev_path);
>      g_assert (physdev);
>  
> -    is_mbm = g_udev_device_get_property_as_boolean (physdev, "ID_MM_ERICSSON_MBM");
>      g_object_unref (client);
>  
> -    if (!is_mbm)
> +    desc_path = g_strconcat(physdev_path,"/descriptors",NULL);
> +
> +    fd = open(desc_path, O_RDONLY);
> +    g_free(desc_path);
> +    if (fd < 0)
> +            return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED;
> +
> +    size = read(fd, desc, sizeof(desc));
> +    close(fd);
> +
> +    if (size < 0)
> +            return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED;
> +
> +    if (cmp_mbm_guid(desc,size))
>          return MM_PLUGIN_SUPPORTS_PORT_UNSUPPORTED;
>  
>      if (!strcmp (subsys, "net")) {
>    
> _______________________________________________
> networkmanager-list mailing list
> networkmanager-list gnome org
> http://mail.gnome.org/mailman/listinfo/networkmanager-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]