On Wed, Oct 30, 2019, at 6:52 PM, Austin Shafer via freebsd-wireless wrote:
> Hi all,
> 
> I’m interested in hacking around with a netgear wifi adapter I have (rtwn). 
> Are there any good resources for learning how to read and debug FreeBSD’s 
> wireless network stack?
> 
> Robert Watson has a great overview of starting points for understanding the 
> kernel as a whole, are there any similar "starting points" for network 
> drivers?
> http://www.watson.org/~robert/freebsd/reading/
> 
> The “Design and implementation ..” book covers networking and device driver 
> creation which is helpful, but nothing about wireless. I did find a few like 
> the following:
> https://wiki.freebsd.org/MateuszPiotrowski/Drivers
> https://wiki.freebsd.org/WiFi/BringUp
> 
> Any suggestions? I’d appreciate anything that helps me learn how all this 
> stuff works.
> 
> Thanks in advance,
> Austin
> _______________________________________________
> freebsd-wireless@freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/freebsd-wireless
> To unsubscribe, send any mail to "freebsd-wireless-unsubscr...@freebsd.org"
> 

Hi Austin!

I contributed a bit and dived into rtwn a reasonable bit so hopefully I can 
offer some useful thoughts. In short, the way rtwn and all other drivers work 
is by attaching to an existing stack and telling it "hey! I'm here!". rtwn, 
like all other drivers, populates a softc with the default device states and 
device-specific functions that interact with the hardware. (Side note: If you 
read the Design and Implementation book, you will see that "softc" is the 
BSD-side naming convention for a struct that holds the device state and 
functions that directly interact with the hardware.) After this, the attachment 
code configures general PCI-settings, specifically the type of device, DMA and 
interrupts (used to tell the device when memory has been written via DMA). 
Finally, the attachment code populates an ieee80211com structure, which tells 
wireless stack how to interact with the driver.

rtwn is a bit more complicated than other drivers. Any rtwn device will require 
at least three drivers: The PCI or USB driver, the general rtwn driver which 
contains shared code, and the device-specific driver. While I'm sure you can 
follow the code, I would suggest starting with something a bit simpler. I 
learned the hard way :)

One good approach would be to take a simple driver, look at its ieee802com 
object, and see what avenues the ieee80211 stack has to interact with the 
driver. I would learn about the powering on process, setting up DMA, 
initializing the interrupt code, and seeing how interrupts are handled. From 
there I would look into Rx, Tx and then the rest of it. The ieee80211 man pages 
are good - in addition to reading them, see how they're implemented in multiple 
drivers - don't just focus on one like I did at first. I also spent a good bit 
of time tracing code, both manually and using dtrace's stack dump functionality.

Please let me know if this helps. Also, if you have any more specific 
questions, please let us know. What are your objectives?
I was writing an introduction on this very topic, but $LIFE and other projects 
got in the way. Maybe I should get back into it?

Thanks!
--
Farhan Khan
PGP Fingerprint: 1312 89CE 663E 1EB2 179C 1C83 C41D 2281 F8DA C0DE

_______________________________________________
freebsd-wireless@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-wireless
To unsubscribe, send any mail to "freebsd-wireless-unsubscr...@freebsd.org"

Reply via email to