admin管理员组

文章数量:1794759

cm

cm

声明

  • 本文使用的是代码是Nexus5的cm-14.1(要下载cm-14.1代码可参考此文:[日更-2019.3.31]如何下载Nexus5的LineageOS14.1(cm-14.1)系统源码并编译、刷机),实现通过USB连接以太网;
  • 代码实现在这里:cm-14.1 源码添加以太网功能前后对比
  • 虽然Nexus5 是一部手机,根本不用实现其通过usb连接以太网的这种需求,本文的目的只在于指导,不要较真哦;
  • Nexus5 这个设备通了其实平板之类的设备也是这个道理;

1 USB-以太网 驱动的支持

1.1 USB-以太网 驱动在源码中的位置

    以我的源码目录为例,其在源码中的位置为:

maxingrong@soc02:~/LineageOS/kernel/lge/hammerhead/drivers/net/usb$ ls
asix.c     cdc_ether.c   cdc_subset.c   gl620a.c   ipheth.c  Kconfig     mcs7830.c  pegasus.h   rmnet_usb_ctrl.c  rndis_host.c  smsc75xx.c  smsc95xx.h
catc.c     cdc_ncm.c     cx82310_eth.c  hso.c      kalmia.c  lg-vl600.c  net1080.c  plusb.c     rmnet_usb_data.c  rtl8150.c     smsc75xx.h  usbnet.c
cdc_eem.c  cdc-phonet.c  dm9601.c       int51x1.c  kaweth.c  Makefile    pegasus.c  qmi_wwan.c  rmnet_usb.h       sierra_net.c  smsc95xx.c  zaurus.c

    来看下它的Kconfg文件:

#
# USB Network devices configuration
#
comment "Networking support is needed for USB Network Adapter support"depends on USB && !NETmenu "USB Network Adapters"depends on USB && NETconfig USB_CATCtristate "USB CATC NetMate-based Ethernet device support (EXPERIMENTAL)"depends on EXPERIMENTALselect CRC32---help---Say Y if you want to use one of the following 10Mbps USB Ethernetdevice based on the EL1210A chip. Supported devices are:Belkin F5U011Belkin F5U111CATC NetMateCATC NetMate IIsmartBridges smartNICThis driver makes the adapter appear as a normal Ethernet interface,typically on eth0, if it is the only ethernet device, or perhaps oneth1, if you have a PCI or ISA ethernet card installed.To compile this driver as a module, choose M here: themodule will be called catc.config USB_KAWETHtristate "USB KLSI KL5USB101-based ethernet device support"---help---Say Y here if you want to use one of the following 10Mbps onlyUSB Ethernet adapters based on the KLSI KL5KUSB101B chipset:3Com 3C19250ADS USB-10BTATEN USB EthernetASANTE USB To Ethernet AdapterAOX Endpoints USB EthernetCorrega K.K.D-Link DSB-650C and DU-E10Entrega / Portgear E45I-O DATA USB-ET/TJaton USB Ethernet Device AdapterKingston Technology USB Ethernet AdapterLinksys USB10TMobility USB-Ethernet AdapterNetGear EA-101Peracom Enet and Enet2Portsmith Express Ethernet AdapterShark Pocket AdapterSMC 2202USBSony Vaio port extenderThis driver is likely to work with most 10Mbps only USB Ethernetadapters, including some "no brand" devices. It does NOT work onSmartBridges smartNIC or on Belkin F5U111 devices - you should usethe CATC NetMate driver for those. If you are not sure which oneyou need, select both, and the correct one should be selected foryou.This driver makes the adapter appear as a normal Ethernet interface,typically on eth0, if it is the only ethernet device, or perhaps oneth1, if you have a PCI or ISA ethernet card installed.To compile this driver as a module, choose M here: themodule will be called kaweth.config USB_PEGASUStristate "USB Pegasus/Pegasus-II based ethernet device support"select NET_COREselect MII---help---Say Y here if you know you have Pegasus or Pegasus-II based adapter.If in doubt then look at <file:drivers/net/usb/pegasus.h> for thecomplete list of supported devices.If your particular adapter is not in the list and you are _sure_ itis Pegasus or Pegasus II based then send me<petkan@users.sourceforge> vendor and device IDs.To compile this driver as a module, choose M here: themodule will be called pegasus.config USB_RTL8150tristate "USB RTL8150 based ethernet device support (EXPERIMENTAL)"depends on EXPERIMENTALselect NET_COREselect MIIhelpSay Y here if you have RTL8150 based usb-ethernet adapter.Send me <petkan@users.sourceforge> any comments you may have.You can also check for updates at </>.To compile this driver as a module, choose M here: themodule will be called rtl8150.config USB_USBNETtristate "Multi-purpose USB Networking Framework"select NET_COREselect MII---help---This driver supports several kinds of network links over USB,with "minidrivers" built around a common network driver corethat supports deep queues for efficient transfers.  (This givesbetter performance with small packets and at high speeds).The USB host runs "usbnet", and the other end of the link might be:- Another USB host, when using USB "network" or "data transfer"cables.  These are often used to network laptops to PCs, like"Laplink" parallel cables or some motherboards.  These relyon specialized chips from many suppliers.- An intelligent USB gadget, perhaps embedding a Linux system.These include PDAs running Linux (iPaq, Yopy, Zaurus, andothers), and devices that interoperate using the standardCDC-Ethernet specification (including many cable modems).- Network adapter hardware (like those for 10/100 Ethernet) whichuses this driver framework.The link will appear with a name like "usb0", when the link isa two-node link, or "eth0" for most CDC-Ethernet devices.  Thosetwo-node links are most easily managed with Ethernet Bridging(CONFIG_BRIDGE) instead of routing.For more information see </>.To compile this driver as a module, choose M here: themodule will be called usbnet.config USB_NET_AX8817Xtristate "ASIX AX88xxx Based USB 2.0 Ethernet Adapters"depends on USB_USBNETselect CRC32default yhelpThis option adds support for ASIX AX88xxx based USB 2.010/100 Ethernet adapters.This driver should work with at least the following devices:* Aten UC210T* ASIX AX88172* Billionton Systems, USB2AR* Buffalo LUA-U2-KTX* Corega FEther USB2-TX* D-Link DUB-E100* Hawking UF200* Linksys USB200M* Netgear FA120* Sitecom LN-029* Intellinet USB 2.0 Ethernet* ST Lab USB 2.0 Ethernet* TrendNet TU2-ET100This driver creates an interface named "ethX", where X depends onwhat other networking devices you have in use.config USB_NET_CDCETHERtristate "CDC Ethernet support (smart devices such as cable modems)"depends on USB_USBNETdefault yhelpThis option supports devices conforming to the Communication DeviceClass (CDC) Ethernet Control Model, a specification that's easy toimplement in device firmware.  The CDC specifications are availablefrom </>.CDC Ethernet is an implementation option for DOCSIS cable modemsthat support USB connectivity, used for non-Microsoft USB hosts.The Linux-USB CDC Ethernet Gadget driver is an open implementation.This driver should work with at least the following devices:* Dell Wireless 5530 HSPA* Ericsson PipeRider (all variants)* Ericsson Mobile Broadband Module (all variants)* Motorola (DM100 and SB4100)* Broadcom Cable Modem (reference design)* Toshiba (PCX1100U and F3507g/F3607gw)* ...This driver creates an interface named "ethX", where X depends onwhat other networking devices you have in use.  However, if theIEEE 802 "local assignment" bit is set in the address, a "usbX"name is used instead.config USB_NET_CDC_EEMtristate "CDC EEM support"depends on USB_USBNET && EXPERIMENTALhelpThis option supports devices conforming to the Communication DeviceClass (CDC) Ethernet Emulation Model, a specification that's easy toimplement in device firmware.  The CDC EEM specifications are availablefrom </>.This driver creates an interface named "ethX", where X depends onwhat other networking devices you have in use.  However, if theIEEE 802 "local assignment" bit is set in the address, a "usbX"name is used instead.config USB_NET_CDC_NCMtristate "CDC NCM support"depends on USB_USBNETdefault yhelpThis driver provides support for CDC NCM (Network Control ModelDevice USB Class Specification). The CDC NCM specification isavailable from </>.Say "y" to link the driver statically, or "m" to build adynamically linked module.This driver should work with at least the following devices:* ST-Ericsson M700 LTE FDD/TDD Mobile Broadband Modem (ref. design)* ST-Ericsson M5730 HSPA+ Mobile Broadband Modem (reference design)* ST-Ericsson M570 HSPA+ Mobile Broadband Modem (reference design)* ST-Ericsson M343 HSPA Mobile Broadband Modem (reference design)* Ericsson F5521gw Mobile Broadband Moduleconfig USB_NET_DM9601tristate "Davicom DM9601 based USB 1.1 10/100 ethernet devices"depends on USB_USBNETselect CRC32helpThis option adds support for Davicom DM9601 based USB 1.110/100 Ethernet adapters.config USB_NET_SMSC75XXtristate "SMSC LAN75XX based USB 2.0 gigabit ethernet devices"depends on USB_USBNETselect CRC32helpThis option adds support for SMSC LAN95XX based USB 2.0Gigabit Ethernet adapters.config USB_NET_SMSC95XXtristate "SMSC LAN95XX based USB 2.0 10/100 ethernet devices"depends on USB_USBNETselect CRC32helpThis option adds support for SMSC LAN95XX based USB 2.010/100 Ethernet adapters.config USB_NET_GL620Atristate "GeneSys GL620USB-A based cables"depends on USB_USBNEThelpChoose this option if you're using a host-to-host cable,or PC2PC motherboard, with this chip.Note that the half-duplex "GL620USB" is not supported.config USB_NET_NET1080tristate "NetChip 1080 based cables (Laplink, ...)"default ydepends on USB_USBNEThelpChoose this option if you're using a host-to-host cable basedon this design:  one NetChip 1080 chip and supporting logic,optionally with LEDs that indicate trafficconfig USB_NET_PLUSBtristate "Prolific PL-2301/2302/25A1 based cables"# if the handshake/init/reset problems, from original 'plusb',# are ever resolved ... then remove "experimental"depends on USB_USBNET && EXPERIMENTALhelpChoose this option if you're using a host-to-host cablewith one of these chips.config USB_NET_MCS7830tristate "MosChip MCS7830 based Ethernet adapters"depends on USB_USBNEThelpChoose this option if you're using a 10/100 Ethernet USB2adapter based on the MosChip 7830 controller. This includesadapters marketed under the DeLOCK brand.config USB_NET_RNDIS_HOSTtristate "Host for RNDIS and ActiveSync devices (EXPERIMENTAL)"depends on USB_USBNET && EXPERIMENTALselect USB_NET_CDCETHERhelpThis option enables hosting "Remote NDIS" USB networking links,as encouraged by Microsoft (instead of CDC Ethernet!) for use invarious devices that may only support this protocol.  A variantof this protocol (with even less public documentation) seems tobe at the root of Microsoft's "ActiveSync" too.Avoid using this protocol unless you have no better options.The protocol specification is incomplete, and is controlled by(and for) Microsoft; it isn't an "Open" ecosystem or market.config USB_NET_CDC_SUBSETtristate "Simple USB Network Links (CDC Ethernet subset)"depends on USB_USBNETdefault yhelpThis driver module supports USB network devices that can workwithout any device-specific information.  Select it if you haveone of these drivers.Note that while many USB host-to-host cables can work in this mode,that may mean not being able to talk to Win32 systems or morecommonly not being able to handle certain events (like repluggingthe host on the other end) very well.  Also, these devices willnot generally have permanently assigned Ethernet addresses.config USB_ALI_M5632boolean "ALi M5632 based 'USB 2.0 Data Link' cables"depends on USB_NET_CDC_SUBSEThelpChoose this option if you're using a host-to-host cablebased on this design, which supports USB 2.0 high speed.config USB_AN2720boolean "AnchorChips 2720 based cables (Xircom PGUNET, ...)"depends on USB_NET_CDC_SUBSEThelpChoose this option if you're using a host-to-host cablebased on this design.  Note that AnchorChips is now aCypress brand.config USB_BELKINboolean "eTEK based host-to-host cables (Advance, Belkin, ...)"depends on USB_NET_CDC_SUBSETdefault yhelpChoose this option if you're using a host-to-host cablebased on this design:  two NetChip 2890 chips and an Atmelmicrocontroller, with LEDs that indicate traffic.config USB_ARMLINUXboolean "Embedded ARM Linux links (iPaq, ...)"depends on USB_NET_CDC_SUBSETdefault yhelpChoose this option to support the "usb-eth" networking driverused by most of the ARM Linux community with device controllerssuch as the SA-11x0 and PXA-25x UDCs, or the tftp capabilitiesin some PXA versions of the "blob" boot loader.Linux-based "Gumstix" PXA-25x based systems use this protocolto talk with other Linux systems.Although the ROMs shipped with Sharp Zaurus products use adifferent link level framing protocol, you can have them usethis simpler protocol by installing a different kernel.config USB_EPSON2888boolean "Epson 2888 based firmware (DEVELOPMENT)"depends on USB_NET_CDC_SUBSEThelpChoose this option to support the usb networking links usedby some sample firmware from Epson.config USB_KC2190boolean "KT Technology KC2190 based cables (InstaNet)"depends on USB_NET_CDC_SUBSET && EXPERIMENTALhelpChoose this option if you're using a host-to-host cablewith one of these chips.config USB_NET_ZAURUStristate "Sharp Zaurus (stock ROMs) and compatible"depends on USB_USBNETselect USB_NET_CDCETHERselect CRC32default yhelpChoose this option to support the usb networking links used byZaurus models like the SL-5000D, SL-5500, SL-5600, A-300, B-500.This also supports some related device firmware, as used in somePDAs from Olympus and some cell phones from Motorola.If you install an alternate image, such as the Linux 2.6 basedversions of OpenZaurus, you should no longer need to support thisprotocol.  Only the "eth-fd" or "net_fd" drivers in these devicesreally need this non-conformant variant of CDC Ethernet (or insome cases CDC MDLM) protocol, not "g_ether".config USB_NET_CX82310_ETHtristate "Conexant CX82310 USB ethernet port"depends on USB_USBNEThelpChoose this option if you're using a Conexant CX82310-based ADSLrouter with USB ethernet port. This driver is for routers only,it will not work with ADSL modems (use cxacru driver instead).config USB_NET_KALMIAtristate "Samsung Kalmia based LTE USB modem"depends on USB_USBNEThelpChoose this option if you have a Samsung Kalmia based USB modemas Samsung GT-B3730.To compile this driver as a module, choose M here: themodule will be called kalmia.config USB_NET_QMI_WWANtristate "QMI WWAN driver for Qualcomm MSM based 3G and LTE modems"depends on USB_USBNETselect USB_WDMhelpSupport WWAN LTE/3G devices based on Qualcomm Mobile Data Modem(MDM) chipsets.  Examples of such devices are* Huawei E392/E398This driver will only drive the ethernet part of the chips.The devices require additional configuration to be usable.Multiple management interfaces with linux drivers areavailable:* option: AT commands on /dev/ttyUSBx* cdc-wdm: Qualcomm MSM Interface (QMI) protocol on /dev/cdc-wdmxA modem manager with support for QMI is recommended.To compile this driver as a module, choose M here: themodule will be called qmi_wwan.config USB_HSOtristate "Option USB High Speed Mobile Devices"depends on USB && RFKILLdefault nhelpChoose this option if you have an Option HSDPA/HSUPA card.These cards support downlink speeds of 7.2Mbps or greater.To compile this driver as a module, choose M here: themodule will be called hso.config USB_NET_INT51X1tristate "Intellon PLC based usb adapter"depends on USB_USBNEThelpChoose this option if you're using a 14Mb USB-based PLC(Powerline Communications) solution with an IntellonINT51x1/INT5200 chip, like the "devolo dLan duo".config USB_CDC_PHONETtristate "CDC Phonet support"depends on PHONEThelpChoose this option to support the Phonet interface to a Nokiacellular modem, as found on most Nokia handsets with the"PC suite" USB profile.config USB_IPHETHtristate "Apple iPhone USB Ethernet driver"default n---help---Module used to share Internet connection (tethering) from youriPhone (Original, 3G and 3GS) to your system.Note that you need userspace libraries and programs that are neededto pair your device with your system and that understand the iPhoneprotocol.For more information: .cgi/iPhoneEthernetDriverconfig USB_SIERRA_NETtristate "USB-to-WWAN Driver for Sierra Wireless modems"depends on USB_USBNEThelpChoose this option if you have a Sierra Wireless USB-to-WWAN device.To compile this driver as a module, choose M here: themodule will be called sierra_net.config USB_VL600tristate "LG VL600 modem dongle"depends on USB_NET_CDCETHERselect USB_ACMhelpSelect this if you want to use an LG Electronics 4G/LTE usb modemcalled VL600.  This driver only handles the ethernetinterface exposed by the modem firmware.  To establish a connectionyou will first need a userspace program that sends the rightcommand to the modem through its CDC ACM port, and mostlikely also a DHCP client.  See this thread about using the4G modem from Verizon:.php?p=10589647&postcount=17config MSM_RMNET_USBtristate "RMNET USB Driver"depends on USB_USBNEThelpSelect this if you have a Qualcomm modem device connected via USBsupporting RMNET network interface.To compile this driver as a module, choose M here: the modulewill be called rmnet_usb. If unsure, choose N.endmenu

    这些这些都是要加入到内核配置项中的。

1.2 在内核编译配置文件中查看是否内核编译时加入了这些模块

    查看Nexus5内核配置文件:

maxingrong@soc02:~/LineageOS/kernel/lge/hammerhead/arch/arm/configs$ vim hammerhead_defconfig

    发现hammerhead_defconfig中这些模块被加入进了配置项中:

CONFIG_USB_CATC=y
CONFIG_USB_KAWETH=y
CONFIG_USB_PEGASUS=y
CONFIG_USB_RTL8150=y
CONFIG_USB_USBNET=y
CONFIG_USB_NET_CDC_EEM=y
CONFIG_USB_NET_DM9601=y
CONFIG_USB_NET_SMSC75XX=y
CONFIG_USB_NET_SMSC95XX=y
CONFIG_USB_NET_GL620A=y
CONFIG_USB_NET_PLUSB=y
CONFIG_USB_NET_MCS7830=y
CONFIG_USB_NET_RNDIS_HOST=y
CONFIG_USB_ALI_M5632=y
CONFIG_USB_AN2720=y
CONFIG_USB_EPSON2888=y
CONFIG_USB_KC2190=y
CONFIG_USB_NET_CX82310_ETH=y
CONFIG_USB_NET_KALMIA=y
CONFIG_USB_NET_QMI_WWAN=y
CONFIG_USB_HSO=y
CONFIG_USB_NET_INT51X1=y
CONFIG_USB_IPHETH=y
CONFIG_USB_SIERRA_NET=y

    此时,不必担心内核中没有驱动支持了。
其实有个快捷的方法知道当前驱动支持还是不支持,那就是看一下开发者模式中USB功能选项中有没有RNDIS(USB以太网功能),如下图:

有的话就说明驱动已经支持了!!

2 接下来根据我的old/new对比,添加至源码中

    我的码云仓库:cm-14.1 源码添加前后对比

3 验证结果

  1. 刷机后进入Setting中,发现增加了以太网设置项:


  1. 在开发者选项网络部分,将USB模式选择为RNDIS模式:

  1. 利用RJ45转usb的hub测试一下就ok了!

4 Enjoy it  _

本文标签: cm