From owner-freebsd-wireless@freebsd.org Thu Oct 31 04:49:37 2019 Return-Path: Delivered-To: freebsd-wireless@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 2F6C7178BDE for ; Thu, 31 Oct 2019 04:49:37 +0000 (UTC) (envelope-from farhan@farhan.codes) Received: from new2-smtp.messagingengine.com (new2-smtp.messagingengine.com [66.111.4.224]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 473Xt72pPjz3J6Q for ; Thu, 31 Oct 2019 04:49:35 +0000 (UTC) (envelope-from farhan@farhan.codes) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailnew.nyi.internal (Postfix) with ESMTP id 5FCD47447; Thu, 31 Oct 2019 00:49:34 -0400 (EDT) Received: from imap22 ([10.202.2.72]) by compute5.internal (MEProxy); Thu, 31 Oct 2019 00:49:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=farhan.codes; h= mime-version:message-id:in-reply-to:references:date:from:to :subject:content-type:content-transfer-encoding; s=fm1; bh=qycX9 e7N9ZuySp67PxEeyjjl9r3Ta8aYcPkjoLWSXxI=; b=FFQSFW97fLITrBcdzVSJL jkUGs+vIibMIHNrqCp3+AayFRm9E/sNxoww4y1GKHLTbgS5TBetPyaxhZQ/q5jE3 El8tmm6n31G/c+hv+xHNikts2MwlVC4Wr494SAucPEFmoVNEG/RhyLbFZ8XeEVJM zPsN5FxRxaBUNP0Ws1i/dKMY9neq8rEFzre0JBhiFkkVG5+uwIwZgqxuN1L2T8cE 9X/nutLlnyggmRyrWVv0yf7pmDMsSwtddeE5SivS4vraIGDLAZnEsMmwneIGFbul inXl76mGxHgsRpcdVihGttXbrU/+PDLKNt/svKraSnvv/7TUm1vUKohh9fRdFRq2 w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=qycX9e7N9ZuySp67PxEeyjjl9r3Ta8aYcPkjoLWSX xI=; b=ZMocr/rgVCQUTd60WA6ZH06LoECDSx0uq2dKnShNfIPgPX3lN9vO3ESvR AUCxrzVKGsbXpLFVwvKoibXvTHJriTtO4q6n5u4SaSTk0YCjXdDjzLPX60M3n1y9 dunpoPu+b5TzJNn/sUn/0EEVNiFI/JdBvmnHq0iJa6HWw/8vOJxld9QpXZ9QKdB2 /kuowe6+1+LYfpGv0JqIS0j+1iuHG7hVBhfUZW9HvwYvL0/zF1+z4cinAt24xm84 u+f1/ne6yUAta2j7i2v72kmoC0l+Z8s4YuRebzb897mKUx/ycZ+y5aK4kKX1Mdq0 O1f/saXeym5r8Yi3j9ga4jONw58VQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedruddtgedgjeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefofgggkfgjfhffhffvufgtgfesth hqredtreerjeenucfhrhhomhepfdfhrghrhhgrnhcumfhhrghnfdcuoehfrghrhhgrnhes fhgrrhhhrghnrdgtohguvghsqeenucffohhmrghinhepfhhrvggvsghsugdrohhrghdpfi grthhsohhnrdhorhhgnecurfgrrhgrmhepmhgrihhlfhhrohhmpehfrghrhhgrnhesfhgr rhhhrghnrdgtohguvghsnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 9F866668005F; Thu, 31 Oct 2019 00:49:33 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.1.7-509-ge3ec61c-fmstable-20191030v1 Mime-Version: 1.0 Message-Id: In-Reply-To: <1F9F7008-59C4-42DF-AF1E-0028BD9576F5@badland.io> References: <1F9F7008-59C4-42DF-AF1E-0028BD9576F5@badland.io> Date: Thu, 31 Oct 2019 00:49:13 -0400 From: "Farhan Khan" To: freebsd-wireless@freebsd.org, ashafer@badland.io Subject: Re: Best way to explore the 802.11 rtwn source code? Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 473Xt72pPjz3J6Q X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=farhan.codes header.s=fm1 header.b=FFQSFW97; dkim=pass header.d=messagingengine.com header.s=fm1 header.b=ZMocr/rg; dmarc=none; spf=pass (mx1.freebsd.org: domain of farhan@farhan.codes designates 66.111.4.224 as permitted sender) smtp.mailfrom=farhan@farhan.codes X-Spamd-Result: default: False [-3.58 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; R_DKIM_ALLOW(-0.20)[farhan.codes:s=fm1,messagingengine.com:s=fm1]; XM_UA_NO_VERSION(0.01)[]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:66.111.4.224]; MV_CASE(0.50)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; DMARC_NA(0.00)[farhan.codes]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; RCVD_COUNT_THREE(0.00)[4]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[farhan.codes:+,messagingengine.com:+]; RCPT_COUNT_TWO(0.00)[2]; IP_SCORE(-2.99)[ip: (-7.36), ipnet: 66.111.4.0/24(-4.87), asn: 11403(-2.68), country: US(-0.05)]; RCVD_IN_DNSWL_LOW(-0.10)[224.4.111.66.list.dnswl.org : 127.0.5.1]; SUBJECT_ENDS_QUESTION(1.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:11403, ipnet:66.111.4.0/24, country:US]; RCVD_TLS_LAST(0.00)[]; MID_RHS_WWW(0.50)[]; FROM_EQ_ENVFROM(0.00)[] X-BeenThere: freebsd-wireless@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Discussions of 802.11 stack, tools device driver development." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Oct 2019 04:49:37 -0000 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