Hello, Habr!
I once thought about connecting my Raspberry Pi to the internet wirelessly.
Done deal! For this, I purchased a USB Wi-Fi adapter from the well-known company TP-Link at the nearest store. I should clarify that this is not some nano USB module, but a rather sizable device, about the size of a regular USB flash drive (or if you prefer, roughly the length of an adult male's index finger). Before buying, I researched the list of supported Wi-Fi adapters for RPI, and TP-Link was on that list (though, as it turned out, I didn't consider the details, since the devil is in the details). Thus begins my cold tale of woes; I present to you a detective story in three parts. Interested parties, please continue reading.
Article It helped me partially, but let's take it step by step.
Task Conditions
Given:
- one-board computer Raspberry Pi 2 B v1.1 — 1 piece
- USB Wi-Fi adapter WN727N — 1 piece
- a pair of somewhat functional hands — 2 pieces
- the latest Raspbian is installed (based on Debian 10 Buster)
- kernel version 4.19.73-v7+
Find: establish an internet connection (Wi-Fi is provided by the home router)
After unpacking the adapter, I read the instructions inside:
System Compatibility: Windows 10/8/7/XP (even XP) and MacOS 10.9-10.13
Well, as usual, there’s no mention of Linux. It was 2019, and drivers still needed to be compiled manually…
We had with us 2 compilers, 75 thousand libraries, five binary blobs, half an array of header files with logos, and a whole ocean of headers in all languages and markup. Not that this was a necessary set for work. But once you start compiling a system for yourself, it becomes hard to stop. The only thing that worried me was the drivers for the Wi-Fi. There's nothing more helpless, irresponsible, and broken than compiling drivers from source. But I knew that sooner or later we would have to tackle this mess.
As is well known, fiddling with USB Wi-Fi on Linux is painful and somewhat unpalatable (like Russian sushi).
The box also contains a CD with drivers. Without much hope, I check what’s on it — sure enough, they didn’t bother much. Searching on the internet brought me to the manufacturer's website, but they only had Linux drivers for the device's v4, and I had v5.21 in hand.. Moreover, it supports very old kernel versions from 2.6 to 3.16. Discouraged by the failure right from the start, I thought I should have opted for the TL-WN727N (which is slightly more expensive and supports 300Mbps compared to 150 for mine, but as it turns out, this doesn't matter for the Raspberry Pi at all; more on this later). But most importantly, drivers for it are already available and can be installed easily through a package. firmware-ralink. You can usually find the device revision on the device case on a sticker next to the serial number.
Further Googling and visiting various forums didn't yield much good. Apparently, no one had tried to connect this specific adapter to Linux before me. Yeah, lucky me, like a drowned man.
Although, no, I'm lying; visiting forums (mostly English-speaking) did yield some results, as some threads mentioned a certain gentleman named lwfinger, who is known for having written several drivers for Wi-Fi adapters. His Git repository will be linked at the end of the article. And the second lesson I learned is that you need to identify your device to understand which driver might work for it.
Part 1. Device Identification
When the device is connected to the port, no LED lights up, and it's not clear whether anything is working or not.
The first thing I do to find out if the kernel sees our device is to check dmesg:
[ 965.606998] usb 1-1.3: new high-speed USB device number 9 using dwc_otg
[ 965.738195] usb 1-1.3: New USB device found, idVendor=2357, idProduct=0111, bcdDevice= 0.00
[ 965.738219] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 965.738231] usb 1-1.3: Product: 802.11n NIC
[ 965.738243] usb 1-1.3: Manufacturer: Realtek
[ 965.738255] usb 1-1.3: SerialNumber: 00E04C0001
It turned out it was detected, and it's clear that there's a Realtek chip and the device's VID/PID on the USB bus.
Let's move on and check lsusb, and here we encounter another failure
Bus 001 Device 008: ID 2357:0111
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
The system doesn't recognize what this device is and shamefully shows a blank space instead of a name (although vendor=2357 definitely corresponds to TP-Link).
At this point, the curious reader might have already noticed something interesting, but we'll set that aside for now.
Investigating the issue of blank names led me to a website with identifiers that keeps information on known VID/PID. Our 2357:0111 was not listed there. As it turned out later, the utility lsusb uses the file /usr/share/misc/usb.ids, which is the same list of identifiers from this site. For visual appeal, I simply added lines for the vendor TP-Link in my system.
2357 TP-Link
0111 TL-WN727N v5.21
We fixed the display in the device list, but that didn't bring us any closer to selecting the driver. To choose a driver, you need to know what chip your adapter is made with. Another unsuccessful attempt to find this information online led to nothing good. Armed with a fine flathead screwdriver, I carefully pry open the adapter's cover, revealing the sinful creation of Uncle Liao in all its original nakedness. Under the magnifying glass, the chip designation can be seen — RTL8188EUS. This is already good. On some forums, I've seen posts that say the driver from Mr. lwfinger is a good match for this chip (even though it only mentions RTL8188EU).
Part 2. The Supremacy of Born
I'm downloading the driver source from Git.
It's time to reinstall Windows and engage in what is usually associated with Linux users — building something from source. As it turns out, building drivers is not much different from compiling programs:
make
sudo make install
but to compile kernel modules, we need the kernel headers for our specific version.
In the stock repository, there is a package raspberrypi-kernel-headers, but it contains version files for the kernel 4.19.66-v7l+, and that doesn't work for us. However, to obtain the headers of the required version, there is a handy tool, rpi-source (link at the end on GitHub), which allows you to download the necessary headers. We clone the repository, make the script executable, and run it. The first run fails with an error — the utility bc. Fortunately, it is in the repository, and we simply install it.
sudo apt-get install bc
After that, a repeat run to download the headers (and then configure something, I don't remember now) takes some time, and I can lean back in my chair, Windows has become better in all its manifestations.
Once all the headers are downloaded, we check that the directory /lib/modules/4.19.73-v7+ is present, and in it, a symlink points to where the downloaded files are located (for me, that's /home/pi/linux):
pi@raspberrypi:/home/pi/rtl8188eu# ls -l /lib/modules/4.19.73-v7+
lrwxrwxrwx 1 root root 14 Sep 24 22:44 build -> /home/pi/linux
The preparation stage is complete, we can proceed to assembly. Assembling the modules takes a certain amount of time again; the Raspberry Pi is not very fast (it has a 32bit 900MHz Cortex ARM v7).
So, everything has been compiled. We will install the driver in step 2 (make install), during which additional firmware files necessary for the driver to function are copied:
install:
install -p -m 644 8188eu.ko $(MODDESTDIR)
@if [ -a /lib/modules/$(KVER)/kernel/drivers/staging/rtl8188eu/r8188eu.ko ] ; then modprobe -r r8188eu; fi;
@echo "blacklist r8188eu" > /etc/modprobe.d/50-8188eu.conf
cp rtl8188eufw.bin /lib/firmware/.
/sbin/depmod -a ${KVER}
mkdir -p /lib/firmware/rtlwifi
cp rtl8188eufw.bin /lib/firmware/rtlwifi/.
Part 3. Born's Ultimatum
I plug the dongle into the port and… nothing happens. Was all this for nothing?
I start to examine the files inside the project, and in one of them, I find the issue: the driver specifies a complete list of VID/PID identifiers that it can handle. To make our device work with this driver, I simply added my ID to the file rtl8188eu/os_dep/usb_intf.c
static struct usb_device_id rtw_usb_id_tbl[] = {
/*=== Realtek demoboard ===*/
{USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8179)}, /* 8188EUS */
{USB_DEVICE(USB_VENDER_ID_REALTEK, 0x0179)}, /* 8188ETV */
/*=== Customer ID ===*/
/****** 8188EUS ********/
{USB_DEVICE(0x07B8, 0x8179)}, /* Abocom - Abocom */
{USB_DEVICE(0x0DF6, 0x0076)}, /* Sitecom N150 v2 */
{USB_DEVICE(0x2001, 0x330F)}, /* DLink DWA-125 REV D1 */
{USB_DEVICE(0x2001, 0x3310)}, /* Dlink DWA-123 REV D1 */
{USB_DEVICE(0x2001, 0x3311)}, /* DLink GO-USB-N150 REV B1 */
{USB_DEVICE(0x2001, 0x331B)}, /* D-Link DWA-121 rev B1 */
{USB_DEVICE(0x056E, 0x4008)}, /* Elecom WDC-150SU2M */
{USB_DEVICE(0x2357, 0x010c)}, /* TP-Link TL-WN722N v2 */
{USB_DEVICE(0x2357, 0x0111)}, /* TP-Link TL-WN727N v5.21 */
{} /* Terminating entry */
};
I recompiled the driver and reinstalled it on the system.
And this time, everything started up. The light on the adapter lit up, and a new device appeared in the list of network interfaces.
Viewing the wireless interfaces yields the following:
pi@raspberrypi:/home/pi/rtl8188eu# iwconfig
ypt0 no wireless extensions.
lo no wireless extensions.
wlan0 unassociated ESSID:"" Nickname:""
Mode:Auto Frequency=2.412 GHz Access Point: Not-Associated
Sensitivity:0/0
Retry:off RTS thr:off Fragment thr:off
Encryption key:off
Power Management:off
Link Quality=0/100 Signal level=0 dBm Noise level=0 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
Bonus for those who read to the end
Remember how I said that it doesn't matter what the maximum speed is listed on your adapter?
So, on the Raspberry Pi (before the release of model 4), all devices (including the Ethernet adapter) share a single USB bus. Pretty neat, right? Therefore, the bandwidth of the USB bus is divided among all the devices connected to it. When measuring the speed via Ethernet, USB Wi-Fi (both connected to the same router), wireless, and wired, it yielded around 20 Mbps.
P.S. This guide to compiling the driver for this specific adapter is not only applicable on RPI. I later repeated it on my desktop with Linux Mint — everything worked there too. You will also need to download the necessary header files for your kernel version.
UPDATE. Informed sources suggested: to avoid dependency on the kernel version, drivers should be compiled and installed using dkms. This option is also mentioned in the driver’s readme.
pi@raspberrypi:/home/pi# sudo dkms add ./rtl8188eu
pi@raspberrypi:/home/pi# sudo dkms build 8188eu/1.0
pi@raspberrypi:/home/pi# sudo dkms install 8188eu/1.0
UPDATE 2. The proposed device ID was accepted into the mainstream branch of the lwfinger/rtl8188eu repository.
Links
—
—
—
—
Source: habr.com
