Linux USB驱动probe()问题

发布于 2024-12-06 22:00:07 字数 1533 浏览 1 评论 0原文

我目前正在为 Seowon SWU-3220A WiMAX USB 调制解调器开发内核模式 USB 驱动程序。它是一个复杂的设备(插入后在系统中显示为USB CDROM,驱动程序需要将其切换到调制解调器模式)。我的问题是我的驱动程序中的probe()函数从未被调用。我认为这是因为操作系统使用标准 USB 大容量存储驱动程序而不是我自己的驱动程序。

我按如下方式初始化驱动程序:

#define GDM7213_VENDOR_ID 0x1076
#define GDM7213_PRODUCT_ID 0x7f40

static struct usb_device_id gdm7213_table [] = {
    { USB_DEVICE(GDM7213_VENDOR_ID, GDM7213_PRODUCT_ID) },
    { }
};

MODULE_DEVICE_TABLE(usb, gdm7213_table);

static struct usb_driver gdm7213_driver = {
    .name                 = "gdm7213",
    .probe                = gdm7213_probe,
    .disconnect           = gdm7213_disconnect,
    .suspend              = gdm7213_suspend,
    .resume               = gdm7213_resume,
    .pre_reset            = gdm7213_pre_reset,
    .post_reset           = gdm7213_post_reset,
    .id_table             = gdm7213_table,
};

static int gdm7213_probe(struct usb_interface *interface, const struct usb_device_id *id)
{
    printk(KERN_INFO "GDM7213 gdm7213_probe()\n");
    return 0;
}

static int __init gdm7213_init_module(void)
{
    int result;
    printk(KERN_INFO "GDM7213 init_module()\n");

    result = usb_register(&gdm7213_driver);
    if (result)
        err("usb_register failed. Error number %d", result);

    return result;
}

static void __exit gdm7213_cleanup_module(void)
{
    printk(KERN_INFO "GDM7213 cleanup_module()\n");
    usb_deregister(&gdm7213_driver);
}

module_init(gdm7213_init_module);
module_exit(gdm7213_cleanup_module);

有人能告诉我哪里有错误或建议任何解决方法吗?

I'm currently work on kernel-mode USB driver for Seowon SWU-3220A WiMAX USB modem. It is a complex device (after plugging it appear in system as USB CDROM, and driver needs to switch it to modem mode). My problem is that the probe() function from my driver is never called. I think it because OS uses standard usb mass storage driver instead of my own.

I initialize driver as follow:

#define GDM7213_VENDOR_ID 0x1076
#define GDM7213_PRODUCT_ID 0x7f40

static struct usb_device_id gdm7213_table [] = {
    { USB_DEVICE(GDM7213_VENDOR_ID, GDM7213_PRODUCT_ID) },
    { }
};

MODULE_DEVICE_TABLE(usb, gdm7213_table);

static struct usb_driver gdm7213_driver = {
    .name                 = "gdm7213",
    .probe                = gdm7213_probe,
    .disconnect           = gdm7213_disconnect,
    .suspend              = gdm7213_suspend,
    .resume               = gdm7213_resume,
    .pre_reset            = gdm7213_pre_reset,
    .post_reset           = gdm7213_post_reset,
    .id_table             = gdm7213_table,
};

static int gdm7213_probe(struct usb_interface *interface, const struct usb_device_id *id)
{
    printk(KERN_INFO "GDM7213 gdm7213_probe()\n");
    return 0;
}

static int __init gdm7213_init_module(void)
{
    int result;
    printk(KERN_INFO "GDM7213 init_module()\n");

    result = usb_register(&gdm7213_driver);
    if (result)
        err("usb_register failed. Error number %d", result);

    return result;
}

static void __exit gdm7213_cleanup_module(void)
{
    printk(KERN_INFO "GDM7213 cleanup_module()\n");
    usb_deregister(&gdm7213_driver);
}

module_init(gdm7213_init_module);
module_exit(gdm7213_cleanup_module);

Can anybody say me where is a bug or suggest any workaround?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰雪梦之恋 2024-12-13 22:00:07

如果是 USB 大容量存储驱动程序在您有机会之前窃取了它,您可能需要使用该驱动程序将设备的 VID/PID 列入黑名单。

既然您提到它是一个 USB WiMAX 适配器,我会大胆猜测它提供的是一个 USB 大容量存储设备,其中包含 Windows 上的驱动程序。如果是这种情况,您最好使用 USB Modeswitch,它已经为 3G 调制解调器处理了这个问题。通常,设备期望一些魔术字节(实际上通常是 SCSI 弹出命令)来说服它们停止作为大容量存储设备并成为真正的调制解调器。 (通常也有不同的 PID)。

即使无法说服您的设备显示真实设备而不是使用现有 USB 模式切换规则之一的驱动程序,解决该问题也比内核破解更合适。

与您提议的相比,使用 USB Modeswitch 进行此操作具有许多优点:

  1. 保持一切模块化:
    1. 您的驱动程序只需关心 WiMAX 和设备的一个 VID/PID
    2. 大容量存储驱动程序不需要关心疯狂的设备 - 它只是看起来像插入和拔出设备。向大容量存储驱动程序教授此类设备中的每一个是不合适的,您的设备似乎并不是一个特例。
    3. 有关设备人格分裂的知识仅与 USB Modeswitch 相关,而 USB Modeswitch 的存在只是为了解决这个问题。
  2. 它不会破坏设备的 USB 大容量存储方面 - 用户可能出于某种原因想要在 Linux 下查看 Windows 驱动程序,将此设备列入黑名单将使这变得不可能。如果您最终也在 Linux 下使用 Windows 驱动程序附带的某些固件,这可能很重要。
  3. 它遵循现有设置并将您的更改保留在模块本地。如果您希望将驱动程序添加到主线内核中,这可能很重要。

If it is the USB mass storage driver stealing it before you get a chance you might want to blacklist the VID/PID for the device with that driver.

Since you mentioned it's a USB WiMAX adapter I'm going to have a wild guess though that it's presenting a USB mass storage device that contains a driver for it on Windows. If that's the case you would be better off working with USB Modeswitch, which already handles this for 3G modems. Typically the devices expect some magic bytes (which often is actually a SCSI eject command) to persuade them to stop being mass storage devices and become the real modem. (That has a different PID normally too).

Even if your device can't be persuaded to show the real device instead of the driver with one of the existing USB Modeswitch rules it would be more appropriate to fix the problem with that than a kernel hack.

Doing it with USB Modeswitch has a number of advantages over what you proposed:

  1. Keeps everything modular:
    1. Your driver only has to care about WiMAX and one VID/PID for the device
    2. The mass storage driver doesn't need to care about crazy devices - it just looks like plugging and unplugging a device. Teaching the mass storage driver about every single one of these sort of devices isn't appropriate, your device doesn't seem to be a special case.
    3. The knowledge about the split personalities of the device is only relevant to USB Modeswitch, which only exists to solve this problem.
  2. It doesn't break the USB mass storage aspects of the device - users might want to view the Windows driver under Linux for some reason, blacklisting this device would make that impossible. This might be important if you end up using some firmware shipped with the Windows driver under Linux too.
  3. It follows the existing setup and keeps your changes local to your module. This might well be important if you want to get your driver in the mainline kernel ever.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文