Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 31 Oct 2019 00:49:13 -0400
From:      "Farhan Khan" <farhan@farhan.codes>
To:        freebsd-wireless@freebsd.org, ashafer@badland.io
Subject:   Re: Best way to explore the 802.11 rtwn source code?
Message-ID:  <d3705517-ae52-4644-883d-6e65d327e93d@www.fastmail.com>
In-Reply-To: <1F9F7008-59C4-42DF-AF1E-0028BD9576F5@badland.io>
References:  <1F9F7008-59C4-42DF-AF1E-0028BD9576F5@badland.io>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Oct 30, 2019, at 6:52 PM, Austin Shafer via freebsd-wireless wrote:
> Hi all,
>=20
> I=E2=80=99m interested in hacking around with a netgear wifi adapter I ha=
ve (rtwn). Are there any good resources for learning how to read and debug =
FreeBSD=E2=80=99s wireless network stack?
>=20
> Robert Watson has a great overview of starting points for understanding t=
he kernel as a whole, are there any similar "starting points" for network d=
rivers?
> http://www.watson.org/~robert/freebsd/reading/
>=20
> The =E2=80=9CDesign and implementation ..=E2=80=9D 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
>=20
> Any suggestions? I=E2=80=99d appreciate anything that helps me learn how =
all this stuff works.
>=20
> 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-unsubscribe@freebsd.or=
g"
>=20

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 w=
ork is by attaching to an existing stack and telling it "hey! I'm here!". r=
twn, like all other drivers, populates a softc with the default device stat=
es and device-specific functions that interact with the hardware. (Side not=
e: 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 stat=
e and functions that directly interact with the hardware.) After this, the =
attachment code configures general PCI-settings, specifically the type of d=
evice, DMA and interrupts (used to tell the device when memory has been wri=
tten via DMA). Finally, the attachment code populates an ieee80211com struc=
ture, which tells wireless stack how to interact with the driver.

rtwn is a bit more complicated than other drivers. Any rtwn device will req=
uire 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 sim=
pler. 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 d=
river. I would learn about the powering on process, setting up DMA, initial=
izing 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 mult=
iple 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 quest=
ions, please let us know. What are your objectives?
I was writing an introduction on this very topic, but $LIFE and other proje=
cts 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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?d3705517-ae52-4644-883d-6e65d327e93d>