应用场景:
有些公司想将模块换成合宙的模块,但是之前的模块出现的是USBxx 网卡,合宙的是ethxx ,这让就让应用程序改动应用程序,很是麻烦!
修改方法:
方法一 修改脚本
1.找到文件 /etc/udev/rules.d/70-persistent-net.rules 将SUBSYSTEM“net”, ACTION“add”, DRIVERS“?“, ATTR{address}“ac:00:00:c9:1e:c5”, ATTR{dev_id}“0x0”, ATTR{type}“1”, KERNEL“eth” 改成 SUBSYSTEM“net”, ACTION“add”, DRIVERS“?“, ATTR{address}“ac:00:00:c9:1e:c5”, ATTR{dev_id}“0x0”, ATTR{type}“1”, KERNEL“usb“,
方法二 修改内核
step 1:
For Linux Kernel Version newer than 2.6.30
File: [KERNEL]/drivers/net/usb/usbnet.c
<ol class="linenums" style="padding: 0px 0px 0px 2.5em;"><li class="L0" style="list-style-type: decimal;"><font color="#000088" face="YaHei Consolas Hybrid, Consolas, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Helvetica, monospace, monospace"><span style="font-size: 14px;">usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)</span></font></li><li class="L2" style="color: rgb(153, 153, 153); font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; font-size: 12px; list-style-type: decimal;"><code><span class="pun">{</span></code></li><li class="L3" style="list-style-type: decimal;"><code><span class="pln"> </span></code><font color="#000088" face="YaHei Consolas Hybrid, Consolas, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Helvetica, monospace, monospace"><span style="font-size: 14px;">net->netdev_ops = &usbnet_netdev_ops;</span></font></li><li class="L4" style="list-style-type: decimal;"><code><span class="pln"> </span></code><font color="#000000" face="YaHei Consolas Hybrid, Consolas, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Helvetica, monospace, monospace"><span style="font-size: 14px;">net->watchdog_timeo = TX_TIMEOUT_JIFFIES;</span></font></li><li class="L5" style="list-style-type: decimal;"><code><span class="pln"> </span></code><font color="#000088" face="YaHei Consolas Hybrid, Consolas, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Helvetica, monospace, monospace"><span style="font-size: 14px;">net->ethtool_ops = &usbnet_ethtool_ops;</span></font></li><li class="L7" style="color: rgb(153, 153, 153); font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; font-size: 12px; list-style-type: decimal;"><code><span class="pln"> </span><span class="com">/ allow device-specific bind/init procedures</span></code></li><li class="L8" style="list-style-type: decimal;"><code><span class="pln"> </span></code><font color="#000088" face="YaHei Consolas Hybrid, Consolas, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Helvetica, monospace, monospace"><span style="font-size: 14px;">// NOTE net->name still not usable ...</span></font></li><li class="L9" style="list-style-type: decimal;"><code><span class="pln"> </span></code><font color="#000000" face="YaHei Consolas Hybrid, Consolas, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Helvetica, monospace, monospace"><span style="font-size: 14px;">if (info->bind) {</span></font></li><li class="L0" style="color: rgb(153, 153, 153); font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; font-size: 12px; list-style-type: decimal;"><code><span class="pln"> </span><span class="com">status = info->bind (dev, udev);</span></code></li><li class="L1" style="list-style-type: decimal;"><code><span class="pln"> </span></code><font color="#000088" face="YaHei Consolas Hybrid, Consolas, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Helvetica, monospace, monospace"><span style="font-size: 14px;">if (status < 0)</span></font></li><li class="L2" style="list-style-type: decimal;"><code><span class="pln"> </span></code><font color="#000000" face="YaHei Consolas Hybrid, Consolas, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Helvetica, monospace, monospace"><span style="font-size: 14px;">goto out1;</span></font></li><li class="L3" style="color: rgb(153, 153, 153); font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; font-size: 12px; list-style-type: decimal;"><code><span class="pln"> // heuristic: "usb%d" for links we know are two-host,</span></code></li><li class="L4" style="color: rgb(153, 153, 153); font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; font-size: 12px; list-style-type: decimal;"><code><span class="pln"> // else "eth%d" when there's reasonable doubt. userspace</span></code></li><li class="L5" style="color: rgb(153, 153, 153); font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; font-size: 12px; list-style-type: decimal;"><code><span class="pln"> </span><span class="com">// can rename the link if it knows better.</span></code></li><li class="L6" style="color: rgb(153, 153, 153); font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; font-size: 12px; list-style-type: decimal;"><code><span class="pln"> </span><span class="com">if ((dev->driver_info->flags & FLAG_ETHER) != 0 &&</span></code></li><li class="L7" style="color: rgb(153, 153, 153); font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; font-size: 12px; list-style-type: decimal;"><code><span class="com"> ((dev->driver_info->flags & FLAG_POINTTOPOINT) == 0 ||</span></code></li><li class="L8" style="color: rgb(153, 153, 153); font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; font-size: 12px; list-style-type: decimal;"><code><span class="com"> (net->dev_addr [0] & 0x02) == 0))</span></code></li><li class="L9" style="color: rgb(153, 153, 153); font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; font-size: 12px; list-style-type: decimal;"><code><span class="com"> <b> strcpy (net->name, "eth%d"); /**** 请将此处修改为 </b></span></code><span style="font-weight: 700; color: rgb(136, 0, 0); font-size: 14px;">strcpy (net->name, "usb%d"); */</span></li><li class="L0" style="color: rgb(153, 153, 153); font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; font-size: 12px; list-style-type: decimal;"><code><span class="com"> /* WLAN devices should always be named "wlan%d" */</span></code></li><li class="L1" style="list-style-type: decimal;"><code><span class="pln"> </span></code><font color="#000000" face="YaHei Consolas Hybrid, Consolas, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Helvetica, monospace, monospace"><span style="font-size: 14px;">if ((dev->driver_info->flags & FLAG_WLAN) != 0)</span></font></li><li class="L2" style="list-style-type: decimal;"><code><span class="pln"> </span></code><font color="#000000" face="YaHei Consolas Hybrid, Consolas, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Helvetica, monospace, monospace"><span style="font-size: 14px;">strcpy(net->name, "wlan%d");</span></font></li><li class="L3" style="list-style-type: decimal;"><code><span class="pln"> </span></code><font color="#000000" face="YaHei Consolas Hybrid, Consolas, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Helvetica, monospace, monospace"><span style="font-size: 14px;">/* WWAN devices should always be named "wwan%d" */</span></font></li><li class="L4" style="list-style-type: decimal;"><code><span class="pln"> </span></code><font color="#666600" face="YaHei Consolas Hybrid, Consolas, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Helvetica, monospace, monospace"><span style="font-size: 14px;">if ((dev->driver_info->flags & FLAG_WWAN) != 0)</span></font></li><li class="L5" style="list-style-type: decimal;"><code><span class="pln"> </span></code><font color="#000088" face="YaHei Consolas Hybrid, Consolas, Meiryo UI, Malgun Gothic, Segoe UI, Trebuchet MS, Helvetica, monospace, monospace"><span style="font-size: 14px;">strcpy(net->name, "wwan%d");</span></font></li></ol>
-
step 2:
为了禁止驱动将usb M0,M1加载为ttyUSB设备,需要将usb serial 驱动部分做如下修改:
For Linux Kernel Version newer than 2.6.30
File: [KERNEL]/drivers/usb/serial/option.c
<ol class="linenums" style="padding: 0px 0px 0px 2.5em; color: rgb(153, 153, 153);"><li class="L0" style="list-style-type: decimal;"><code><span class="kwd">static</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> option_probe</span><span class="pun">(</span><span class="kwd">struct</span><span class="pln"> usb_serial </span><span class="pun">*</span><span class="pln">serial</span><span class="pun">,</span></code></li><li class="L1" style="list-style-type: decimal;"><code><span class="pln"> </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">struct</span><span class="pln"> usb_device_id </span><span class="pun">*</span><span class="pln">id</span><span class="pun">)</span></code></li><li class="L2" style="list-style-type: decimal;"><code><span class="pun">{</span></code></li><li class="L3" style="list-style-type: decimal;"><code><span class="pln"> </span><span class="kwd">struct</span><span class="pln"> usb_interface_descriptor </span><span class="pun">*</span><span class="pln">iface_desc </span><span class="pun">=</span></code></li><li class="L4" style="list-style-type: decimal;"><code><span class="pln"> </span><span class="pun">&</span><span class="pln">serial</span><span class="pun">-></span><span class="kwd">interface</span><span class="pun">-></span><span class="pln">cur_altsetting</span><span class="pun">-></span><span class="pln">desc</span><span class="pun">;</span></code></li><li class="L5" style="list-style-type: decimal;"><code><span class="pln"> </span><span class="kwd">struct</span><span class="pln"> usb_device_descriptor </span><span class="pun">*</span><span class="pln">dev_desc </span><span class="pun">=</span><span class="pln"> </span><span class="pun">&</span><span class="pln">serial</span><span class="pun">-></span><span class="pln">dev</span><span class="pun">-></span><span class="pln">descriptor</span><span class="pun">;</span></code></li><li class="L6" style="list-style-type: decimal;"><code></code></li><li class="L7" style="list-style-type: decimal;"><code><span class="pln"> </span><span class="com">/* Never bind to the CD-Rom emulation interface */</span></code></li><li class="L8" style="list-style-type: decimal;"><code><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">iface_desc</span><span class="pun">-></span><span class="pln">bInterfaceClass </span><span class="pun">==</span><span class="pln"> </span><span class="lit">0x08</span><span class="pun">)</span></code></li><li class="L9" style="list-style-type: decimal;"><code><span class="pln"> i </span><span class="kwd">return</span><span class="pln"> </span><span class="pun">-</span><span class="pln">ENODEV</span><span class="pun">;</span></code></li><li class="L0" style="list-style-type: decimal;"><code><span class="pln"> </span><span class="com">//+add by airm2m for Air72x</span></code></li><li class="L1" style="list-style-type: decimal;"><code><span class="pln"> </span><span class="kwd">if</span><span class="pun">(</span><span class="pln">dev_desc</span><span class="pun">-></span><span class="pln">idVendor </span><span class="pun">==</span><span class="pln"> cpu_to_le16</span><span class="pun">(</span><span class="lit">0x1286</span><span class="pun">)</span><span class="pln"> </span><span class="pun">&&</span></code></li><li class="L2" style="list-style-type: decimal;"><code><span class="pln"> dev_desc</span><span class="pun">-></span><span class="pln">idProduct </span><span class="pun">==</span><span class="pln"> cpu_to_le16</span><span class="pun">(</span><span class="lit">0x4e3d</span><span class="pun">)</span><span class="pln"> </span><span class="pun">&&</span></code></li><li class="L3" style="list-style-type: decimal;"><code><span class="pln"> iface_desc</span><span class="pun">-></span><span class="pln">bInterfaceNumber </span><span class="pun"><=</span><span class="pln"> </span><span class="lit">1</span><span class="pun">)</span></code></li><li class="L4" style="list-style-type: decimal;"><code><span class="pln"> </span><span class="kwd">return</span><span class="pln"> </span><span class="pun">-</span><span class="pln">ENODEV</span><span class="pun">;</span></code></li><li class="L5" style="list-style-type: decimal;"><code><span class="pln"> </span><span class="com">//-add by airm2m for Air72x</span></code></li><li class="L6" style="list-style-type: decimal;"><code><span class="pln"> </span><span class="com">/*</span></code></li><li class="L7" style="list-style-type: decimal;"><code><span class="com"> * Don't bind reserved interfaces (like network ones) which often have</span></code></li><li class="L8" style="list-style-type: decimal;"><code><span class="com"> * the same class/subclass/protocol as the serial interfaces. Look at</span></code></li><li class="L9" style="list-style-type: decimal;"><code><span class="com"> * the Windows driver .INF files for reserved interface numbers.</span></code></li><li class="L0" style="list-style-type: decimal;"><code><span class="com"> */</span></code></li><li class="L1" style="list-style-type: decimal;"><code><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">is_blacklisted</span><span class="pun">(</span></code></li><li class="L2" style="list-style-type: decimal;"><code><span class="pln"> iface_desc</span><span class="pun">-></span><span class="pln">bInterfaceNumber</span><span class="pun">,</span></code></li><li class="L3" style="list-style-type: decimal;"><code><span class="pln"> OPTION_BLACKLIST_RESERVED_IF</span><span class="pun">,</span></code></li><li class="L4" style="list-style-type: decimal;"><code><span class="pln"> </span><span class="pun">(</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">struct</span><span class="pln"> option_blacklist_info </span><span class="pun">*)</span><span class="pln"> id</span><span class="pun">-></span><span class="pln">driver_info</span><span class="pun">))</span></code></li><li class="L5" style="list-style-type: decimal;"><code><span class="pln"> </span><span class="kwd">return</span><span class="pln"> </span><span class="pun">-</span><span class="pln">ENODEV</span><span class="pun">;</span></code></li></ol>
优先推荐使用方法2