building WiFi support

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
prajwal
Member
Member
Posts: 154
Joined: Sat Oct 23, 2004 11:00 pm
Contact:

building WiFi support

Post 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
complexity is the core of simplicity
User avatar
MajickTek
Member
Member
Posts: 101
Joined: Sat Dec 17, 2016 6:58 am
Libera.chat IRC: MajickTek
Location: The Internet
Contact:

Re: building WiFi support

Post by MajickTek »

802.11 is the WIFI standard
Everyone should know how to program a computer, because it teaches you how to think! -Steve Jobs

Code: Select all

while ( ! ( succeed = try() ) ); 
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: building WiFi support

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
MajickTek
Member
Member
Posts: 101
Joined: Sat Dec 17, 2016 6:58 am
Libera.chat IRC: MajickTek
Location: The Internet
Contact:

Re: building WiFi support

Post 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
Everyone should know how to program a computer, because it teaches you how to think! -Steve Jobs

Code: Select all

while ( ! ( succeed = try() ) ); 
User avatar
prajwal
Member
Member
Posts: 154
Joined: Sat Oct 23, 2004 11:00 pm
Contact:

Re: building WiFi support

Post 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
complexity is the core of simplicity
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: building WiFi support

Post 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.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
User avatar
prajwal
Member
Member
Posts: 154
Joined: Sat Oct 23, 2004 11:00 pm
Contact:

Re: building WiFi support

Post 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
complexity is the core of simplicity
User avatar
hgoel
Member
Member
Posts: 89
Joined: Sun Feb 09, 2014 7:11 pm
Libera.chat IRC: hgoel
Location: Within a meter of a computer

Re: building WiFi support

Post 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.
"If the truth is a cruel mistress, than a lie must be a nice girl"
Working on Cardinal
Find me at [url=irc://chat.freenode.net:6697/Cardinal-OS]#Cardinal-OS[/url] on freenode!
User avatar
Schol-R-LEA
Member
Member
Posts: 1925
Joined: Fri Oct 27, 2006 9:42 am
Location: Athens, GA, USA

Re: building WiFi support

Post 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.
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

Re: building WiFi support

Post 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.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: building WiFi support

Post 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.
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

Re: building WiFi support

Post 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.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Post Reply