Sunday 1 September 2019

Ubuntu 16.04 on an HP Pavilion 15 laptop

I don’t buy many laptops — my previous one dated from about 1990! But last month I felt it was time to get another one so as to ensure my continuing Internet access. It was a process tinged with a little sadness, as my mother was keen that I should get a new laptop, and her gift of a cheque towards it was one of the last things she did. I eventually decided on an HP Pavilion 15-cw0980na laptop as it had most of the features I wanted and it also was on offer at the time... However, the big doubt in my mind was whether I would be able to successfully run Linux on it?

The inevitable Internet searching didn’t turn up any horror stories from people who had tried to install Linux on this hardware and failed, so although this seemed as though I was sailing into uncharted waters, it was actually reassuring. The next step was to download my distro of choice (the latest Ubuntu 16.04) and write it to a USB memory stick. When it came to booting and installing from the memory stick, it was textbook: even the GPU was recognised and supported. I went for a dual-boot configuration, just in case I ever needed to use Windows 10. (Shurely shome mishstake?) After rebooting to complete the installation, everything seemed fine — except that I wasn’t seeing any WiFi activity in the network menu.

Now, in a modern laptop, wireless networking is an expected norm. This was one of the main reasons for buying it. Getting Ubuntu 16.04 to use WiFi in an HP Pavilion 15-cw0980na could then be a challenge. Firing up a Terminal, I used the  lspci command to identify the wireless networking chip. As far as I could tell, it was a Realtek Semiconductor Co., Ltd. RTL8821CE. Although Ubuntu does provide support for the RTL8821AE, this is a different chip unfortunately.  (One nice thing about the HP Pavilion 15 laptop, and a reason why I bought it, is that it also comes with an Ethernet port. So I could connect a UTP network cable between my laptop and home router and still have an Internet connection.)

More Internet searching for the RTL8821CE and Ubuntu turned up a number of leads, including source for at least one driver on Github. (Thank you Tomas Pinho and friends.) The catch being that this was targetted for Ubuntu 18.04, not 16.04! Nevertheless, I reasoned that the driver source changes couldn't have been that drastic for 18.04, otherwise I would have heard (read) the criticism. (Even IT people are not that keen on change, especially if the benefits are questionable.)

Therefore, I installed the extra packages needed to access and compile the driver source code, and copied the driver code into a suitable directory. When I went into the driver code directory and ran the make command, predictably it chugged away for a few seconds and then stopped saying there was a problem with the file os_dep/linux/rtw_android.c: there was a mismatch of arguments in the macro access_ok. Fortunately, I was able to copy and change the file to work with Ubuntu 16.04, and to my relief the commands make and make install both ran without further errors. When I then rebooted my laptop, I was delighted to see that wireless networking had sprung to life -- and I was able to connect to my home WiFi without any problem. Excellent!

For a more detailed explanation, these are the steps I took to get wireless networking functioning:
  1. mkdir /usr/local/src/tomaspinho; cd /usr/local/src/tomaspinho
  2. apt-get install git
  3. git clone https://github.com/tomaspinho/rtl8821ce.git
  4. cd rtl8821ce
  5. Edit the file os_dep/linux/rtw_android.c (make a copy first) and use a text editor to change line 665 from: if (!access_ok(priv_cmd.buf, priv_cmd.total_len)) { to: if (!access_ok(VERIFY_WRITE, priv_cmd.buf, priv_cmd.total_len)) { .
  6. Run the make command.
  7. Run the make install command.
  8. Now reboot the laptop.
  9. Wireless networking should now be working. 
One downside of these steps is that the driver needs to be rebuilt every time the kernel is updated, which can be a little annoying. The full Ubuntu 18.04 solution uses DKMS which will automatically update the driver as required. But I was just happy to have my wireless networking functional. (I will write a simple script to automate the rebuild.) No doubt my mother would have been pleased to see me typing away on this blog posting on my new laptop...