Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use USB Network under Linux

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to use USB network under Linux". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use USB network under Linux".

When introducing the driver development of USB, I usually use the USB network of Linux to demonstrate that it is compatible with RNDIS network. A Linux can act as the deviceside of USB, another Linux can act as the host side of USB, and the host side can also be acted as a standard Rndis driver installed by Microsoft.

This network has a strong practical value, and the complete implementation of Linux USB Slave driver and Linux USB Gadget driver, so it has a strong demonstration effect.

Application scenarios:

Smart phone sharing network

Now the smartphone uses 3G network, and through the installation of related drivers on the Linux/Android phone, we can use USB cable to build a shared network between the host and the phone, so that the smartphone acts as a wireless router. Now mobile phones generally have this function, WINDOWS can install Rndis driver. And it uses the g_ether.ko driver that we mentioned later.

This way is far better than the mobile phone as a 3G modem, using USB to dial this way, sharing the network is equivalent to both mobile phones and computers surfing the Internet.

This method is the same as using mobile phone WIFI as wireless hotspot, but the requirement of APN is higher, many mobile phones may not support it, and USB has power supply at the same time. It still has its advantages.

Second, add a second wired network.

In the classroom, very often, there is only one network interface between the server and the student computer. When I connect the network cable to the local area network, my development board can not use NFS to connect my machine, and so is the student computer. Now the server connects the wired network to the local area network, while my development board is directly connected to the server.

(1) the structure of USB network

Unlike Ethernet, each terminal in USB network is not peer-to-peer, that is, the software and hardware interfaces required by USB Host and USB Device are different.

There are many kinds of USB networks, among which RNDIS network is the most commonly used. Its full name is

Remote Network Device Interface Specification.

It is a specification developed by Microsoft, because mobile phones are widely used, so LINUX is also compatible with this specification in the driver.

(the function of the PS:Android phone is almost standard, and the function that the phone needs to support, FAT,RNDIS,MTP (Media transfer Protocol), is the patent of MS. These cards have become an important weapon for MS to collect royalties from the manufacturers of Android phones, which Samsung has already paid.)

Generally, like a PC acting as a USB Host, a Linux development board with an USB Host interface can also play this role.

If it is a LINUX host, you need to install the rndis_host.ko driver. General distributions have been compiled and can be run directly.

If the embedded development board can configure the kernel rndis_host as a dynamic module

It is located in

│ Prompt: Host for RNDIS and ActiveSync devices (EXPERIMENTAL) │

│ Defined at drivers/net/usb/Kconfig:234 │

│ Depends on: NETDEVICES & & USB & & NET & & USB_USBNET & & EXPERIMENTAL │

│ Location: │

│-> Device Drivers │

│-> Network device support (NETDEVICES [= y]) │

│-> USB Network Adapters │

│-> Multi-purpose USB Networking Framework (USB_USBNET [= m]) │

If it is a WINDOWS host, you need to install the Generic RNDIS driver for MS.

At the other end of the USB, there are usually embedded devices. Take the embedded LINUX as an example, the USB Gadget driver g_ether.ko needs to be installed to communicate. The location of g_ether.ko in the configuration menu is as follows

Symbol: USB_ETH_RNDIS [= n] │

│ Prompt: RNDIS support │

│ Defined at drivers/usb/gadget/Kconfig:609 │

│ Depends on: & & USB_ETH │

│ Location: │

│-> Device Drivers │

│-> USB support (USB_SUPPORT [= y]) │

│-> USB Gadget Support (USB_GADGET [= y]) │

│-> USB Gadget Drivers ([= m]) │

│-> Ethernet Gadget (with CDC Ethernet support) (USB_ETH [= n │)

So a complete RNDIS network structure is as follows

II. Construction of Linux USB network

USB Host installation. Take RHEL5 as an example, run the following command directly to install rndis_host.ko

Modprobe rndis_host

It will install rndis_host.ko and usbnet.ko

[root@hxy] # find / lib/modules/2.6.18-194.el5/-name "rndis*" / lib/modules/2.6.18-194.el5/kernel/drivers/usb/net/rndis_host.ko [root@hxy] # modprobe rndis_host [root@hxy] # lsmod | grep rndis_host rndis_host 10433 0 cdc_ether 9793 1 rndis_host usbnet 19913 2 rndis_host,cdc_ether

Compile the kernel module on the development board, g_ether.ko. Execute the following command

# insmod g_ether.ko g_ether gadget: ing random self ethernet address g_ether gadget: using random host ethernet addr usb0: MAC de:5e:8b:3d:84:db usb0: HOST MAC 32:90:92:52:a9 g_ethethernet Gadget, morial Day 2008 g_ether gadget: g_ether ready Registered gadget driver 'galleether.'

Pull the Slave cable between the host and the development board, where the development board uses a D-type Slave end interface (don't plug it into the USB interface!) Let the USB network card node take effect. This is usually usb0.

Ifconfig usb0 192.168.3.101 up hub 1-0 g_ether gadget 1.0: unable to enumerate USB device 2 g_ether gadget: high speed config # 1: Chernet (ECM)

Make a similar configuration on the host side and configure it into another IP.

Ifconfig usb0 192.168.3.120 up # ifconfig usb0 192.168.3.120 up usb 1-1: new high speed USB device using ehci_hcd and address 5 usb 1-1: configuration # 1 chosen from 2 choices usb0: register 'cdc_ether' at usb-0000:00:1d.7-1, CDC Ethernet Device, 32:90:26:92:52:a9

At this point, you can ping each other at both ends.

Third, establish a connection with Windows.

If you want to establish a RNDIS network connection with Windows, you need to download the RNDIS driver and adjust and install the INF file according to the manufacturer number and device number of g_ether.ko.

1. Identify VID and PID

First confirm the vendor number and product number of g_ether.ko 's RNDIS. It is defined in drivers/usb/gadget/ether.c

# define RNDIS_VENDOR_NUM 0x0525 / * NetChip * / # define RNDIS_PRODUCT_NUM 0xa4a2 / * Ethernet/RNDIS Gadget * /

two。 Download the RNDIS driver for WINDOWS.

Http://www.microsoft.com/china/whdc/device/network/NDIS/rndis.mspx

Or

Http://gp2x.generation.free.fr/public/Autres/

If it doesn't work, look for the RNDIS-USB-Kit_05.exe file. It is a compressed file, in which rndismpy.sys,usb8023y.sys is the driver file.

3. Modify the installation inf file

Modify the installation file using the RNDIS_Template.inf in it as the blueprint. There are two main changes:

Change the mm/dd/yyyy,x.y.v.z to any time and version number, and I modify it to 09pm 28pm 2011 1.0.0.0

(note that there are two points)

Modify USB\ VID_vvvv&PID_pppp to the number found. This must be the USB\ VID_0525&PID_A4A2 defined by Linux.

Put inf and two sys together, pick a name at random, and I'll call it hxy_rndis.inf.

4. Install the driver

Insert the USB cable between the development board and the WINDOWS. At this point, WINDOWS will prompt to install the driver, select manual installation, and select the directory where sys is located in the previous step to install.

After installation, the system will appear a RNDIS network card, and configure IP to communicate with the development board.

Thank you for your reading, the above is the content of "how to use USB network under Linux". After the study of this article, I believe you have a deeper understanding of how to use USB network under Linux. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report