udev:PCIe 4G 网络设备的规则问题

udev:PCIe 4G 网络设备的规则问题

我的规则的目标是将网络接口从“eth0”(或其他)重命名为“gsm0”,并根据我们用来发出 AT 命令的设备创建一个符号链接 /dev/ATCMD 到 /dev/ttyUSBX。

我制定了这个规则:

SUBSYSTEMS=="usb", ATTRS{bInterfaceNumber}!="02", GOTO="symlink_huaweiME909_end"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="15c1", SYMLINK+="ATCMD"
LABEL="symlink_huaweiME909_end"
SUBSYSTEM=="net", ACTION=="add", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="15c1", NAME="gsm0"

界面的重命名效果很好,但对于符号链接部分,它仅在启动时起作用。如果我手动关闭 gsm0 接口并再次打开它,符号链接将不再重定向到 /dev/ttyUSBX。它来自:

lrwxrwxrwx  1 root root           7 Jan  1  1970 ATCMD -> ttyUSB0

到 :

lrwxrwxrwx  1 root root          15 Aug 14 11:03 ATCMD -> bus/usb/001/006

命令 udevadm info -a -p $(udevadm info -q path -n /dev/ttyUSB0) 给我:

  looking at device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1:2.2/ttyUSB0/tty/ttyUSB0':
    KERNEL=="ttyUSB0"
    SUBSYSTEM=="tty"
    DRIVER==""

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1:2.2/ttyUSB0':
    KERNELS=="ttyUSB0"
    SUBSYSTEMS=="usb-serial"
    DRIVERS=="option1"
    ATTRS{port_number}=="0"

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1:2.2':
    KERNELS=="1-1:2.2"
    SUBSYSTEMS=="usb"
    DRIVERS=="option"
    ATTRS{interface}=="Huawei Mobile Connect - Modem"
    ATTRS{bInterfaceProtocol}=="10"
    ATTRS{bInterfaceNumber}=="02"
    ATTRS{bInterfaceSubClass}=="06"
    ATTRS{bInterfaceClass}=="ff"
    ATTRS{bAlternateSetting}==" 0"
    ATTRS{authorized}=="1"
    ATTRS{bNumEndpoints}=="03"
    ATTRS{supports_autosuspend}=="1"

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1':
    KERNELS=="1-1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bDeviceClass}=="00"
    ATTRS{rx_lanes}=="1"
    ATTRS{manufacturer}=="Huawei Technologies Co., Ltd."
    ATTRS{bmAttributes}=="a0"
    ATTRS{bConfigurationValue}=="2"
    ATTRS{version}==" 2.00"
    ATTRS{devnum}=="2"
    ATTRS{bMaxPower}=="2mA"
    ATTRS{idProduct}=="15c1"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{urbnum}=="953"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{maxchild}=="0"
    ATTRS{bcdDevice}=="0102"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{idVendor}=="12d1"
    ATTRS{product}=="HUAWEI Mobile V7R11"
    ATTRS{speed}=="480"
    ATTRS{removable}=="unknown"
    ATTRS{ltm_capable}=="no"
    ATTRS{serial}=="0123456789ABCDEF"
    ATTRS{bNumConfigurations}=="3"
    ATTRS{busnum}=="1"
    ATTRS{authorized}=="1"
    ATTRS{tx_lanes}=="1"
    ATTRS{quirks}=="0x0"
    ATTRS{configuration}==""
    ATTRS{devpath}=="1"
    ATTRS{bDeviceProtocol}=="ff"
    ATTRS{bNumInterfaces}==" 7"

  looking at parent device '/devices/platform/soc/3f980000.usb/usb1':
    KERNELS=="usb1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bDeviceClass}=="09"
    ATTRS{rx_lanes}=="1"
    ATTRS{manufacturer}=="Linux 4.19.57 dwc_otg_hcd"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{version}==" 2.00"
    ATTRS{devnum}=="1"
    ATTRS{bMaxPower}=="0mA"
    ATTRS{idProduct}=="0002"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{urbnum}=="25"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{maxchild}=="1"
    ATTRS{bcdDevice}=="0419"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{idVendor}=="1d6b"
    ATTRS{product}=="DWC OTG Controller"
    ATTRS{speed}=="480"
    ATTRS{authorized_default}=="1"
    ATTRS{interface_authorized_default}=="1"
    ATTRS{removable}=="unknown"
    ATTRS{ltm_capable}=="no"
    ATTRS{serial}=="3f980000.usb"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{busnum}=="1"
    ATTRS{authorized}=="1"
    ATTRS{tx_lanes}=="1"
    ATTRS{quirks}=="0x0"
    ATTRS{configuration}==""
    ATTRS{devpath}=="0"
    ATTRS{bDeviceProtocol}=="01"
    ATTRS{bNumInterfaces}==" 1"

以及此后的一些事情。

感谢您的帮助!

EDIT1:此规则在内核 4.1 上完美运行,但在 4.19 上有此问题

答案1

我按如下方式修改了我的规则,现在它正在发挥作用。因此,我在内核 4.1 上使用上述规则,在 4.19 上使用以下规则:

SUBSYSTEMS=="usb", ATTRS{bInterfaceNumber}!="02", GOTO="symlink_huaweiME909_end"
SUBSYSTEM=="tty", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="15c1", SYMLINK+="ATCMD"
LABEL="symlink_huaweiME909_end"
SUBSYSTEM=="net", ACTION=="add", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="15c1", NAME="gsm0"

相关内容