Page 1 of 1

building WiFi support

Posted: Sat Sep 09, 2017 2:52 am
by prajwal
Hi

Where to start if I have to start building support for wireless network from scratch ?

For example, I have been able to code XHCI driver from scratch by going through intel manual and support USB MSD and Keyboard - all coded from scratch (also referred Ben's book)

Similarly, where to start if I need to support Wi-Fi ? i.e. to code low level device driver and then building other higher network protocol layers.. is that even practical ? How long (months and years) it might take if I get required documents and source code references (say from Linux kernel) ? say if I can spend max 1 hr a day for this

I prefer to do it from scratch as my intention is to learn and explore - but wonder if that's practical in case of network support... ! if it's not then what options do I have in order to support Wi-Fi in my kernel ?

Thanks
Prajwal

Re: building WiFi support

Posted: Sat Sep 09, 2017 8:30 am
by MajickTek
802.11 is the WIFI standard

Re: building WiFi support

Posted: Sat Sep 09, 2017 8:52 am
by Brendan
Hi,
prajwal wrote:Where to start if I have to start building support for wireless network from scratch ?
The first step would be finding a wifi card/chip where programming information is available. For "too many" there isn't any information and even well known OSs (e.g. Linux) struggle to provide bare minimum support. It's not like USB where there's only 4 (easily obtained) standards that all USB controllers follow.

Beyond that, I have no clue - I use wired ethernet (none of my computers have any wifi). :)
MajickTek wrote:802.11 is the WIFI standard
If you've got a bag full of transistors and a soldering iron, then that standard would help you to create your own wifi circuit. It won't help you figure out how to write a driver for someone else's wifi circuit/card/chip (e.g. which PCI and/or memory mapped registers do what).


Cheers,

Brendan

Re: building WiFi support

Posted: Sat Sep 09, 2017 12:41 pm
by MajickTek
brendan wrote:
MajickTek wrote:802.11 is the WIFI standard
If you've got a bag full of transistors and a soldering iron, then that standard would help you to create your own wifi circuit. It won't help you figure out how to write a driver for someone else's wifi circuit/card/chip (e.g. which PCI and/or memory mapped registers do what).


Cheers,

Brendan
Hardware is proprietary, might as well us an open source wifi dongle

Re: building WiFi support

Posted: Sat Sep 09, 2017 5:31 pm
by prajwal
ha ha.. ok, its very difficult as I expected :) can't compare it with USB

I have 2 machines with Ubuntu installed.
One has 'Qualcomm Atheros QCA9565 / AR9565 wireless network adapter'
The other has 'Intel Dual Band Wireless-AC 8265 adapter'

1. If not writing code from scratch, would Linux kernel open-source have required code/library/modules that can be ported - is that feasible ?
2. Even if I am able to port, what does the device driver code correspond to in network protocol stack ? the PHY/Data link layer ?
[ I am sorry, I am not familiar with network part ]
3. Appreciate if you can point me to some guide and/or explain (in brief) what are the different layers/protocol stacks to implement to build support up-to TCP/IP ?
4. Which module should I port from Linux open-source and which ones are feasible to write by myself (if any) ? (judging by the level of complexity I can deal with by writing XHCI driver) - in a time-frame say 200 hrs of development

Thanks
Prajwal

Re: building WiFi support

Posted: Sat Sep 09, 2017 5:55 pm
by BrightLight
prajwal wrote:1. If not writing code from scratch, would Linux kernel open-source have required code/library/modules that can be ported - is that feasible ?
I'm sure the Linux drivers can be ported, but I doubt it would be easy. Haiku also has some open-source wireless drivers.
prajwal wrote:2. Even if I am able to port, what does the device driver code correspond to in network protocol stack ? the PHY/Data link layer ?
Yes. The device driver, whether it's wireless or ethernet transmits and receives packets across the physical network.
prajwal wrote:3. Appreciate if you can point me to some guide and/or explain (in brief) what are the different layers/protocol stacks to implement to build support up-to TCP/IP ?
A minimalist TCP/IP stack must implement at least IP, ARP, ICMP, UDP and TCP. Of course, you'll need other things to make it practical, like DHCP which will allow you to have an IP address at all, and detect the router, DNS server, and other useful information.
prajwal wrote:4. Which module should I port from Linux open-source and which ones are feasible to write by myself (if any) ? (judging by the level of complexity I can deal with by writing XHCI driver) - in a time-frame say 200 hrs of development
I can't really answer this question, TBH.

If you want to implement networking, I'd suggest going with ethernet first, because it's much simpler than Wi-Fi, more people here (including myself) have implemented it, and there are more cards which have free specifications. Something relatively easy to start with is the RTL8139 or Intel i8254x cards.

As for the network stack itself, which isn't much different whether it's ethernet or Wi-Fi, you'd implement it in layers. There would be a link layer, which communicates with the ethernet/wireless driver directly to transmit/receive packets using MAC addresses. On top of the link layer, you would implement IP and ARP. ARP allows you to resolve IP addresses into MAC addresses. Just like your ARP layer can request other devices' MAC addresses, it also has to respond when someone requests your MAC address. On top of IP, you would implement the transport/control protocols, UDP, TCP and ICMP. Then you can implement any application-level protocols you'd like, such as DHCP, DNS, HTTP, NTP, and any others you can think of.

You'll definitely need Wireshark, and a dump of all the packets passing through your code. QEMU's "-net dump,file=file.pcap" option will help a lot here. This will help you verify that the network driver works at all.

Re: building WiFi support

Posted: Sat Sep 09, 2017 7:31 pm
by prajwal
Thanks a lot omarrx024! That was indeed very helpful information.

I was clueless but this post has got me some clarity good enough at-least to start in a proper direction.

More information or help welcome on this topic from all

Re: building WiFi support

Posted: Mon Sep 18, 2017 8:52 am
by hgoel
I've looked into this before, so I'd like to think I know a little about the situation. Essentially, you won't find documentation for pretty much any built-in wifi chipset. There are however, a few dongles available which do have their specifications easily obtainable on the internet. So essentially, you'll have to look around and find a dongle chipset that has documentation, they're usually less than $10 on Amazon, so it isn't all too expensive either. You'd be writing a USB device driver for it though, rather than a PCI driver. There is a unified linux driver for current realtek wifi chips, but honestly, the code is difficult to follow and at least to me, it's far more convenient to just write a usb driver than try to figure out the code.

Re: building WiFi support

Posted: Mon Sep 18, 2017 10:06 am
by Schol-R-LEA
MajickTek wrote:
brendan wrote:If you've got a bag full of transistors and a soldering iron, then that standard would help you to create your own wifi circuit. It won't help you figure out how to write a driver for someone else's wifi circuit/card/chip (e.g. which PCI and/or memory mapped registers do what).


Cheers,

Brendan
Hardware is proprietary, might as well us an open source wifi dongle
I think you missed Brendan's point. The problem is that the spec tells you how the hardware should behave, in terms of communicating with other wireless devices; it says nothing about the software interface, including whether there is one at all. That is the information you need when writing a driver, and there is no standard to speak of for that.

Re: building WiFi support

Posted: Sat Sep 23, 2017 12:06 pm
by onlyonemac
There are two things that are incredibly difficult (read: impossible, but I don't like saying impossible because theoretically anything's possible given enough time and resources) to implement in hobby operating systems: 3D graphics drivers and WiFi drivers. The reason for both of these is the same: the hardware is often proprietary, or has very little available documentation. And both 3D graphics cards and WiFi cards/chipsets often have poor Linux support for the same reason.

The short answer is that you should focus elsewhere, because WiFi is going to take, at a minimum, piecing together scraps of documentation and reverse-engineering Linux driver source code before you'll be able to implement it on your OS, and that's if you're lucky enough to have a WiFi chipset that's properly supported by Linux in the first place. If you're just looking for a way to get your OS on the network, focus on ethernet rather than WiFi.

Re: building WiFi support

Posted: Sat Sep 23, 2017 2:08 pm
by Korona
onlyonemac wrote:There are two things that are incredibly difficult (read: impossible, but I don't like saying impossible because theoretically anything's possible given enough time and resources) to implement in hobby operating systems: Nvidia 3D graphics drivers and WiFi drivers. The reason for both of these is the same: the hardware is often proprietary, or has very little available documentation. And both 3D graphics cards and WiFi cards/chipsets often have poor Linux support for the same reason.
FTFY.

Re: building WiFi support

Posted: Tue Sep 26, 2017 1:47 pm
by onlyonemac
Korona wrote:
onlyonemac wrote:There are two things that are incredibly difficult (read: impossible, but I don't like saying impossible because theoretically anything's possible given enough time and resources) to implement in hobby operating systems: Nvidia 3D graphics drivers and WiFi drivers. The reason for both of these is the same: the hardware is often proprietary, or has very little available documentation. And both 3D graphics cards and WiFi cards/chipsets often have poor Linux support for the same reason.
FTFY.
Even with the open-source Intel drivers and the increasing number of official open-source AMD drivers, there's still very little documentation and they're still difficult to implement in a hobby OS.