[Wine-patches] Update grdwine.

Alexander Morozov amorozov на etersoft.ru
Ср Дек 16 13:46:50 MSK 2009


----------- следующая часть -----------
From 448ba69d1bb2eb28437ab7e4fbd9445aa0d56ccc Mon Sep 17 00:00:00 2001
From: Aleksey Samsonov <samsonov на guardant.ru>
Date: Wed, 16 Dec 2009 13:19:15 +0300
Subject: [PATCH] Update grdwine.

---
 dlls/grdwine/grdimpl.h       |    2 +-
 dlls/grdwine/grdimpl_linux.c |  105 +++++++++++++++++++++++++++---------------
 dlls/grdwine/grdwine.c       |    2 +-
 3 files changed, 69 insertions(+), 40 deletions(-)

diff --git a/dlls/grdwine/grdimpl.h b/dlls/grdwine/grdimpl.h
index 58b60d1..5bd62bf 100644
--- a/dlls/grdwine/grdimpl.h
+++ b/dlls/grdwine/grdimpl.h
@@ -30,7 +30,7 @@ int grd_ioctl_device(const char* dev_path, unsigned int prod_id,
 
 /*
  * Check device.
- * Return zero if device is Guardant Stealth III Sign/Time.
+ * Return zero if device is Guardant Sign/Time or Guardant Code.
  */
 int grd_probe_device(const char* dev_path, unsigned int* prod_id);
 
diff --git a/dlls/grdwine/grdimpl_linux.c b/dlls/grdwine/grdimpl_linux.c
index 3854856..b6c7101 100644
--- a/dlls/grdwine/grdimpl_linux.c
+++ b/dlls/grdwine/grdimpl_linux.c
@@ -33,20 +33,21 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <limits.h> /* for PATH_MAX */
 #include <stdio.h> /* for snprintf */
 
 #include "grdimpl.h"
 
-#ifdef __linux__
+#if defined(__linux__) && HID_VERSION >= 0x010003
+
 #include <linux/usbdevice_fs.h>
 #include <linux/hiddev.h>
-#include <limits.h> /* for PATH_MAX */
-#endif
 
-#if HID_VERSION >= 0x010003
-
-#define GRD_PRODID_S3S          0x08 /* Guardant StealthIII Sign/Time USB */
-#define GRD_PRODID_S3S_HID      0x0C /* Guardant StealthIII Sign/Time USB HID */
+#define GRD_VENDOR              0x0a89
+#define GRD_PRODID_S3S          0x08 /* Guardant Sign/Time USB */
+#define GRD_PRODID_S3S_HID      0x0C /* Guardant Sign/Time USB HID */
+#define GRD_PRODID_S3C          0x09 /* Guardant Code USB */
+#define GRD_PRODID_S3C_HID      0x0D /* Guardant Code USB HID */
 #define USBFS_PATH_ENV          "USB_DEVFS_PATH"
 #define GRD_IPC_NAME_ENV        "GRD_IPC_NAME"
 #define USBFS_PATH_1            "/dev/bus/usb"
@@ -172,7 +173,7 @@ static int open_device(const char* dev_path, struct lock_descr* lock_dscr)
     return fd;
 }
 
-static int ioctl_device_bulk(int fd, unsigned int ep, void *buf, size_t len)
+static int ioctl_device_bulk(int fd, unsigned int ep, void* buf, size_t len)
 {
     struct usbdevfs_bulktransfer packet;
     int ret;
@@ -192,7 +193,23 @@ static int ioctl_device_bulk(int fd, unsigned int ep, void *buf, size_t len)
         return 0;
 }
 
-static int hiddevice_write(int fd, void *buf, size_t len)
+static int hiddevice_get_prodid(int fd, unsigned int* id)
+{
+    struct hiddev_devinfo devinfo;
+
+    assert(fd >= 0);
+    if (ioctl(fd, HIDIOCGDEVINFO, &devinfo) != 0)
+        return -1;
+    if (devinfo.vendor != GRD_VENDOR)
+        return -1;
+    if (devinfo.product != GRD_PRODID_S3S_HID && devinfo.product != GRD_PRODID_S3C_HID)
+        return -1;
+    assert(id);
+    *id = devinfo.product;
+    return 0;
+}
+
+static int hiddevice_write(int fd, void* buf, size_t len)
 {
     const size_t report_len = 64;
     struct hiddev_usage_ref_multi ref;
@@ -233,7 +250,7 @@ static int hiddevice_write(int fd, void *buf, size_t len)
     return 0;
 }
 
-static int hiddevice_read(int fd, void *buf, size_t len)
+static int hiddevice_read(int fd, void* buf, size_t len)
 {
     const size_t report_len = 64;
     struct hiddev_usage_ref_multi ref;
@@ -296,7 +313,7 @@ static int hiddevice_read(int fd, void *buf, size_t len)
 int grd_ioctl_device(const char* dev_path, unsigned int prod_id, size_t pack_size,
         void* in, size_t len_in, void* out, size_t len_out)
 {
-    const int ishid = (prod_id == GRD_PRODID_S3S_HID);
+    const int ishid = (prod_id == GRD_PRODID_S3S_HID || prod_id == GRD_PRODID_S3C_HID);
     struct lock_descr lock;
     int fd, r;
     int ret = -1, interface = 0, flags = HIDDEV_FLAG_UREF | HIDDEV_FLAG_REPORT;
@@ -366,57 +383,69 @@ int grd_ioctl_device(const char* dev_path, unsigned int prod_id, size_t pack_siz
 }
 
 /*
- * If device (dev_path is usbfs path) is Guardant Stealth III Sign/Time,
- * or dev_path eq "GRDHID_PATH_HEAD + N"
- * then return 0, else return -1
+ * If device (dev_path is usbfs path) is Guardant Sign/Time/Code,
+ * or device (dev_path eq "GRDHID_PATH_HEAD + N") is
+ * Guardant Sign/Time/Code HID  then return 0, else return -1
  */
 int grd_probe_device(const char* dev_path, unsigned int* prod_id)
 {
-    const unsigned char buf_tmpl[16] = {
+    unsigned char buf_tmpl[16] = {
         0x12, 0x01, 0x00, 0x02, 0xff, 0x00, 0x00, 0x40,
-        0x89, 0x0a, 0x08, 0x00, 0x00, 0x01, 0x01, 0x02
+        0x89, 0x0a, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02
     };
     unsigned char buf[16];
     struct lock_descr lock;
+    unsigned int id;
     int fd, ret;
 
     if (!dev_path || !prod_id)
         return -1;
 
-    if (strncmp(dev_path, GRDHID_PATH_HEAD, sizeof(GRDHID_PATH_HEAD) - 1) == 0)
-    {
-        *prod_id = GRD_PRODID_S3S_HID;
-        return 0;
-    }
-
     /* lock process and open usbdev_fs device */
     fd = open_device(dev_path, &lock);
     if (fd < 0)
         return -1;
 
-    assert(sizeof(buf) == sizeof(buf_tmpl)  &&  sizeof(buf_tmpl) == 16);
-    assert(buf_tmpl[10] == GRD_PRODID_S3S);
-    assert(fd >= 0);
-    ret = read(fd, buf, sizeof(buf));
-    if (ret < 0  ||  (size_t)ret != sizeof(buf)
-            ||  memcmp(buf, buf_tmpl, sizeof(buf_tmpl))
-    )
-        ret = -1;
+    if (strncmp(dev_path, GRDHID_PATH_HEAD, sizeof(GRDHID_PATH_HEAD) - 1) == 0)
+    {
+        assert(fd >= 0);
+        ret = hiddevice_get_prodid(fd, &id);
+    }
     else
-        ret = 0;
-
+    {
+        assert(fd >= 0);
+        ret = read(fd, buf, sizeof(buf));
+        if (ret < 0 || (size_t)ret != sizeof(buf))
+            ret = -1;
+        else
+        {
+            ret = 0;
+            assert(sizeof(buf) == sizeof(buf_tmpl)  &&  sizeof(buf_tmpl) == 16);
+            buf_tmpl[10] = GRD_PRODID_S3S;
+            if (!memcmp(buf, buf_tmpl, sizeof(buf_tmpl)))
+                id = GRD_PRODID_S3S;
+            else
+            {
+                buf_tmpl[10] = GRD_PRODID_S3C;
+                if (!memcmp(buf, buf_tmpl, sizeof(buf_tmpl)))
+                    id = GRD_PRODID_S3C;
+                else
+                    ret = -1;
+            }
+        }
+    }
     assert(fd >= 0);
     /* close usbdev_fs device and unlock process */
     if (close_device(fd, &lock) != 0)
         ret = -1;
     if (ret == 0)
-        *prod_id = GRD_PRODID_S3S;
+        *prod_id = id;
     return ret;
 }
 
 static int load_usbfs_path(char* buf, size_t size)
 {
-    char* env;
+    const char* env;
     struct stat buf_stat;
     size_t path_len;
     const char* path = NULL;
@@ -545,17 +574,17 @@ int search_usb_devices(search_usb_device_callback callback, void* param)
 int grd_ioctl_device(const char* dev_path, unsigned int prod_id, size_t pack_size,
         void* in, size_t len_in, void* out, size_t len_out)
 {
-	return -1;
+    return -1;
 }
 
 int grd_probe_device(const char* dev_path, unsigned int* prod_id)
 {
-	return -1;
+    return -1;
 }
 
 int search_usb_devices(search_usb_device_callback callback, void* param)
 {
-	return 0;
+    return 0;
 }
 
-#endif
+#endif /* __linux__ && HID_VERSION >= 0x010003 */
diff --git a/dlls/grdwine/grdwine.c b/dlls/grdwine/grdwine.c
index c2bb21e..38a3999 100644
--- a/dlls/grdwine/grdwine.c
+++ b/dlls/grdwine/grdwine.c
@@ -31,7 +31,7 @@
 #include "wine/debug.h" /* <wine/debug.h> */
 #include "grdimpl.h"
 
-#define GRD_DRIVER_VERSION      0x0530
+#define GRD_DRIVER_VERSION      0x0540
 
 WINE_DEFAULT_DEBUG_CHANNEL(grdwine);
 
-- 
1.6.5.6



Подробная информация о списке рассылки Wine-patches