Friends RaspberryPi with TP-Link TL-WN727N

Hello, Habr!



Somehow I thought to connect my raspberry to the Internet through the air.



No sooner said than done, for this, a whistle of the well-known TP-Link company was purchased in the nearest usb wi-fi store. I must say right away that this is not some kind of nano usb module, but quite an overall device about the size of an ordinary USB flash drive (well, or if you like with the index finger of an adult man). Before buying, I studied the list of supported whistle manufacturers for RPI and TP-Link a little bit on the list (though as it turned out later, I did not take into account the subtleties, because the devil is known to be in the details). So, the cold tale of my misadventures begins, a detective story in 3 parts is offered to your attention. Interested please under cat.



The article Connect the WN727N WiFi adapter to Ubuntu / Mint partially helped me, but first things first.



Conditions of the problem



Given:



  1. Raspberry Pi 2 B v1.1 single-board computer - 1 pc.
  2. usb wifi whistle WN727N - 1 piece
  3. a pair of not quite crooked hands - 2 pieces
  4. the latest Raspbian is installed as the OS (based on debian 10 Buster)
  5. kernel version 4.19.73-v7 +


Find: connect to the Internet (Wi-Fi is heard from a home router)



After unpacking the adapter, I read the instructions inside:

System Compatibility: Windows 10/8/7 / XP (even sky, even XP) and MacOS 10.9-10.13


Hmm, about Linux, as usual, not a word. It was 2k19, but the drivers still needed to be assembled manually ...

We had 2 compilers, 75 thousand libraries, five binary blobs, half a mass of naked women with a logo, and a whole sea of ā€‹ā€‹headers of all languages ā€‹ā€‹and markups. Not that it was a necessary set for work. But if you began to assemble the system for yourself, it becomes difficult to stop. The only thing that worried me was drivers under wi-fi. There is nothing more helpless, irresponsible and spoiled than the assembly of drivers from source. But I knew that sooner or later we will move on to this rubbish.




In general, as you know, fussing with usb wi-fi on Linux is painful and somewhat tasteless (like Russian sushi).



The box also contains a driver CD. Without much hope, I look at what is on it - for sure, they did not take care. A search on the Internet brought me to the manufacturerā€™s website, but there is a Linux driver only for revising the v4 device, and I had v5.21 on hand. And besides, under very old versions of the kernel 2.6-3.16. Discouraged by the failure at the very beginning, I already thought that it was necessary to take TL-WN727N (it is a bit more expensive and can do 300Mbps versus 150 for mine, but it turned out to be irrelevant for raspberries, it will be written later). But the most important driver already exists for it, and they are installed simply by the firmware-ralink package . You can usually see the revision of the device on the deviceā€™s case on the sticker next to the serial number.



Further googling and visiting various forums didnā€™t bring anything special. Apparently no one has tried to connect such an adapter to Linux before me. Hmm, I'm lucky as a drowned man.



Although no, Iā€™m lying, visiting forums (mostly English) also paid off, in some topics there was a mention of a certain Mr. lwfinger, who is famous for writing a number of drivers for Wi-Fi adapters. His git repository at the end of the article in the links. And the second lesson I learned is that you need to identify your device in order to understand which driver might work for it.



Part 1. Bourne Identification



When you turn on the device in the port, no LED, of course, lights up. And in general, in some way it is not clear whether something works or not.



First of all, to find out if the kernel sees our device, I look in 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 to be seen, and itā€™s even clear that there is a Realtek chip and the VID / PID device on the usb bus itself.



We go further, look at lsusb , and then another failure awaits us



 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 does not know what this device is, and bashfully shows an empty space instead of a name (although vendor = 2357 is definitely TP-Link).



At this stage, the inquisitive reader probably already noticed something interesting, but we will postpone it until our time.



Investigation of the problem of empty names brought me to a site with identifiers, where information on known VID / PID is entered. Our 2357: 0111 was not there. As it turned out later, lsusb uses the file /usr/share/misc/usb.ids , which is the same list of identifiers from this site. For the sake of display beauty, I just added lines for the TP-Link vendor in my system.



 2357 TP-Link 0111 TL-WN727N v5.21
      
      





Well, we corrected the display in the list of devices, but this didnā€™t bring us a single step closer to choosing a driver. To select a driver, you need to know on which chip your whistle is made. The next unsuccessful attempts to find out on the Internet did not lead to anything good. Armed with a thin slotted screwdriver, I gently pry the adapter cap on and I see uncle Liao's vicious brainchild in all its pristine nudity. Under the magnifying glass, you can see the name of the chip - RTL8188EUS . This is already good. On some forums, I saw posts that the driver of that very Mr. lwfinger is well suited for this chip (even despite the fact that it only says about RTL8188EU).



Part 2. The Bourne Supremacy



I download driver sources from a gita.



It is time to reinstall the shindous to do what Linux is usually associated with - assembling something from sorts. The assembly of drivers turned out to be little different from compiling programs:



 make sudo make install
      
      





but to compile kernel modules, we need kernel header files for our specific version.



There is a raspberrypi-kernel-headers package in the stock repository, but it contains the version of the files for the kernel 4.19.66-v7l + , and this does not suit us. But to get the headers of the desired version, as it turned out, there is a convenient rpi -source tool (link at the end on the github), with which you can download the necessary headers. We clone the repository, make the script executable, run it. The first start fails with an error - there is no bc utility. Fortunately, it is in the repository and we just install it.



 sudo apt-get install bc
      
      





After this, restarting and downloading the headers (and then setting up something, I donā€™t remember it now) takes some time and you can sit back and become better in all its manifestations .



After all the headers have been downloaded, we check that the /lib/modules/4.19.73-v7+ directory appears and the symlink in it points to the place where the downloaded files are (I have this / 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 preparatory phase is completed, you can start assembling. The assembly of modules again takes a certain time, the raspberry beast is not fast (it has a 32bit 900Mhz Cortex ARM v7 stone).

So, everything compiled. We install the driver in the 2nd step (make install), while copying more firmware files necessary for the driver to work:



 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. The Bourne Ultimatum



I stick a whistle in the port and ... nothing happens. Was it all wasted?



I begin to study the files inside the project and in one of them I find what the problem was: the driver indicates the full list of VID / PIDs that it can serve. And in order for our device to work with this driver, I just added my id to the rtl8188eu / os_dep / usb_intf.c file



 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 */ };
      
      





Recompiled the driver and reinstalled it in 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.



Browsing wireless interfaces shows the following:



 pi@raspberrypi:/home/pi/rtl8188eu# iwconfig eth0 no wireless extensions. lo no wireless extensions. wlan0 unassociated ESSID:"" Nickname:"<WIFI@REALTEK>" 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 have read to the end



Remember how I said that it doesnā€™t matter what maximum speed is stated on your adapter?

So, on the raspberry (before the release of model 4), all devices (including the ethernet adapter) are sitting on the same usb bus. Great, right? And so the usb bus bandwidth is shared between all devices on it. When measuring speed through ethernet and via usb wi-fi (connected to 1 router) both through the air and through the wire it yielded in the region of 20 Mbps.



PS In general, this driver compilation guide for this particular adapter is valid not only on RPI. I then repeated it and on my desktop with Linux Mint - everything also worked there. Itā€™s just that you just need to download the necessary header files for your version of the kernel.



UPD. Knowledgeable people suggested: in order not to depend on the kernel version, you need to build and install drivers using dkms. In readme to the driver, this option is also there

 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
      
      







UPD2. The proposed patch for device id was accepted into the mainstream repository branch lwfinger / rtl8188eu.



References

- RPi USB Wi-Fi Adapters

- gitbub lwfinger / rtl8188eu

- usb.ids

- rpi-source



All Articles