Main page | About | Posts

Wi-Fi, WebKitGTK, and more Wine progress

Astral running WebKitGTK on a Wi-Fi connection

Not being limited to wired connections is a pretty big deal nowadays, especially with mobile machines like phones and laptops. It is hard to find a home or business without a Wi-Fi access point. While mainstream operating systems have a pretty broad support for the underlying protocol (802.11) and device drivers, most hobby OSes are lacking in this regard.

Seeing this as a fun challenge and opportunity to learn, I have spent the past few weeks working on an 802.11 layer and an RTL8188EU driver. Not only that, I also decided to try my hand at making it portable across operating systems much like uACPI. So far, I have enough implemented to connect to open networks and WPA2-PSK networks with TKIP and CCMP encryption, using wpa_supplicant to perform the WPA2 4-way handshake and key negotiation. There are still a lot of limitations to the code, but it is a step in the right direction.

I have also had progress on fronts other than Wi-Fi: Astral now has a working WebKitGTK port and I have made some improvements to the Wine port, which can run Steam now.

Wi-Fi

The Wi-Fi code is divided into two parts. The first part, u80211, is responsible for the generic 802.11 code, handling things like scanning, association, key bookkeeping and hardware abstraction. The other part, u80211_drv, is responsible for implementing NIC drivers, with the only one currently implemented being for the RTL8188EU chips. They are not dependent on each other; you can have u80211 without u80211_drv and vice versa.

u80211

The first part I wrote was u80211, with a pretty linear plan: scanning -> association -> disassociation -> data tx/rx -> hardware encryption support. While I could have written this directly in the Astral tree, I opted to write it in userspace first so that I could use Linux's own mac80211 as a validator. Doing this involved setting up mac80211_hwsim, hostapd and even patching the Linux kernel to fix a bug related to switching channels on active monitors.

When I had open network association and ARP working under hwsim, I started working on the actual NIC driver. I had two "sane" pieces of hardware which I could have written the driver for: an RTL8188EU USB dongle or the RTL8188CE PCIe card in an old netbook. I opted for the dongle due to it being useful for all my hardware and not just one machine.

u80211_drv

Much like the 802.11 layer, I also wrote the NIC driver in the Linux userspace first, using libusb to talk to the device. This part is where the big issue with writing Wi-Fi code for a hobby OS appears: there is very little public programming documentation for these chips, meaning you are pretty much limited to having to read existing code to figure out what to do.

The RTL8188EU code itself is a lot of work mostly because you need to initialize a lot of things yourself. Accessing the hardware registers is done through USB control endpoint transfers. That can then be used to read calibration and configuration data from the eFUSE, power on the chip's MCU, load firmware, program PHY/RF tables adapted from OpenBSD, configure the MAC, do RF calibration and switch channels. The actual TX/RX transfers are done through bulk endpoints.

Astral Integration

Once everything was done and I had it associating to a real WPA2-PSK network under Linux, I started integrating it to Astral. This was relatively quick, as the code needed was not large, mostly involving:

Astral connected to a WPA2-PSK network with CCMP and TKIP

WebKitGTK

Astral now has a WebKitGTK port. While it still has a lot of rough edges, it is capable of accessing many different modern websites. One example is Reddit, where I accessed r/osdev and sent a joke "how do I do paging" post from inside Astral.

Astral searching YouTube in WebKitGTK

Steam

There has also been more progress on the Wine port. After finding and implementing missing glue code, Unity games now get further into startup (although they unfortunately still don't work). Not only that, but Steam can also start up in Astral under Wine now. While it is not fully functional yet, as there seem to be font issues, it was a pretty cool milestone to hit.

Astral running Steam

What's next?

There is still a lot of work to be done, as with anything OSDev. There is a branch with an in-progress rewrite of the page cache, I want to look into implementing a filesystem with journaling, proper power management, full self-hosting and eventually getting Astral to a point where I could reasonably have it installed on a laptop and use it for non-critical tasks.

Thanks for reading!