Udev

udev:PCIe 4G 網路設備的規則問題

  • August 16, 2019

我的規則的目標是將網路介面從“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 上存在此問題

我按照以下方式修改了我的規則,現在它正在工作。因此,我將上述規則用於核心 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"

引用自:https://unix.stackexchange.com/questions/535519