我目前正在用 C 语言编写一个 Linux 内核模块。该模块为 USB 灯(该设备由三个彩色 LED 组成)提供了一个非常基本的驱动程序。我已经成功地让驱动程序加载和卸载没有问题,并创建了设备(/dev/wn0
, /dev/wn1
, ETC。)。但是,在尝试写入设备时,我不断收到错误:
$ echo "1" >/dev/wn0
bash: echo: write error: Broken pipe
该模块的完整代码是here https://github.com/nathan-osman/Webmail-Notifier-Linux-Driver/blob/master/webmail_notifier.c。然而,有趣的部分是wn_set_color()
功能:
/* Create the data buffer to be sent to the device. */
u8 buf[8] = {
red, green, blue, 0, 0, 0, 0x1F, 0x05
};
/* Send the data to the device. */
return usb_control_msg(udev,
usb_sndctrlpipe(udev, 0),
0, 0, 0, 0,
buf, 8, 0);
由于某种原因,它返回-32
而不是将数据发送到设备。
我对 Linux 内核编程完全陌生,所以我可能会做一些愚蠢的事情。如果您能对此有所了解,我们将不胜感激。
Edit:以下是一些进一步的信息:
lsusb -v
输出是here https://github.com/nathan-osman/Webmail-Notifier-Linux-Driver/blob/7c6d510af86b85a2fbc73dc095e1d2fad03e30d2/lsusb.txt
the bDescriptorType
的成员usb_endpoint_descriptor
类包含“5”表示设备公开的单个端点(bEndpointAddress
is 129
- or 0x81
in hex)
here https://i.stack.imgur.com/KbyZd.png是发送到设备的控制 URB 之一的屏幕截图