this post was submitted on 17 Oct 2026
39 points (100.0% liked)
technology
24506 readers
206 users here now
On the road to fully automated luxury gay space communism.
Spreading Linux propaganda since 2020
- Ways to run Microsoft/Adobe and more on Linux
- The Ultimate FOSS Guide For Android
- Great libre software on Windows
- Hey you, the lib still using Chrome. Read this post!
Rules:
- 1. Obviously abide by the sitewide code of conduct. Bigotry will be met with an immediate ban
- 2. This community is about technology. Offtopic is permitted as long as it is kept in the comment sections
- 3. Although this is not /c/libre, FOSS related posting is tolerated, and even welcome in the case of effort posts
- 4. We believe technology should be liberating. As such, avoid promoting proprietary and/or bourgeois technology
- 5. Explanatory posts to correct the potential mistakes a comrade made in a post of their own are allowed, as long as they remain respectful
- 6. No crypto (Bitcoin, NFT, etc.) speculation, unless it is purely informative and not too cringe
- 7. Absolutely no tech bro shit. If you have a good opinion of Silicon Valley billionaires please manifest yourself so we can ban you.
founded 6 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I would suggest starting by trying to configure and build a NetBSD kernel.
BSD kernels have a unique and cool (imo :3) file format that defines a kind of device tree for setting compile-time options and drivers built into the kernel or as modules (in the case of FreeBSD and NetBSD). See here for the file format: https://man.netbsd.org/config.5 and here: https://man.netbsd.org/NetBSD-11.0/options.4 for misc but important compile-time options (which are set as preprocessor defines like #define BEANIS). Traditionally, machine-specific kernel configurations (like the NetBSD amd64 kernel config) include a more generic configuration that contains options that are set for all architectures. The reason I bring this up is because the way device drivers are compiled by the bespoke BSD build system (collection of makefiles primary found under /src/share/mk relative to the CVS repo root) and made known to the kernel at runtime is via that file (indirectly, it tells the autoconfiguration framework that walks down the device tree what drivers it should attach if it matches a device ID or what drivers it should call to probe for their respective devices).
So, basically, if you want to add your new network interface driver you would insert a line into the kernel configuration (usually the architecture specific one) like:
cupcakeif* at pci? dev ? function ?(assuming your interface is attached via PCI bus ^w^)which, when the relevant bus is configured, causes the autoconf framework to call that driver's "match" function (assuming you can directly configure your driver without having to probe for it) for every device on the bus. If your driver thinks it's relevant to that device and should be loaded your match function would return > 0. At which point that driver's "attach" function is called to setup the device. You can refer to this manpage for more details on device driver definition and how it interacts with the autoconf framework: https://man.netbsd.org/driver.9 (as well as how all this info and function pointers even get to the autoconf framework >w< it's a structure initialized with the CFATTACH_DECL_NEW macro described in that manpage)
You can see an example of all of this in the already existing WiFi interface drivers under /src/sys/dev/pci.
For example, the classic athn Atheros wifi interface defined in if_athn_pci.c (which I would suggest generously copy-pasting from :3):
long (edited for brevity)
Besides the generic device driver infrastructure, the other kernel infrastructure you will probably most interact with is the WiFi specific network interface glue/helper code described in https://man.netbsd.org/ieee80211.9 which does varies things like allow userspace to set encryption keys, specify access points to associate with, set media modes, etc, implement the generic ethernet interface API, etc etc
It's getting late and I rly need to go to bed but I hope this helps a little >w< It can get very complicated cuz this codebase is older than Linux and prolly even older than most surviving commercial Unixes. The ppl on the NetBSD IRC and mailing list (also maybe a Telegram group or two) will help you out if you need! Also I'll be around later. My experience is mainly in the OpenBSD codebase but OpenBSD is a fork of NetBSD and although they've diverged significantly they still share a lot of code and there are a few ppl that have copy-pasted code between them over the years (in a comradely manner)
Oh, one last tip! If you get confused or stuck with documentation, consider referring to OpenBSD documentation or code cuz the coverage (at least with userspace stuff.......) and quality tends to be better
If there's a Linux driver for your device, referring to it could help u a lot too as long as you're willing to put up with uhhhhh less than good code quality x3
Also, also: the index for the NetBSD kernel documentation: https://man.netbsd.org/intro.9 :3
Happy hacking!!
Thanks for the detailed answer! I do have another question, though. To test the driver, do I have to run it straight on my hardware? I've been able to build a live image and run it in QEMU; is there a way to expose my laptop's network card through QEMU so I can test without having to keep some partition aside for testing?
Just scrolled past this comment on Mastodon: https://justfollow.me.uk/@sborrill/117461932167067930
Uff. Spent most of yesterday and today trying to get NetBSD running with Xen, but I did finally get it working. Thanks for the direction.