# Switching from Raspbian OS to FreeBSD



## noahbar (Jun 5, 2022)

I got an SD card img file from the FreeBSD site and put it onto the micro SD card that goes into my raspberry pi 4. I am doing this so I can ssh into it and run my c files from my main computer easily. When I had Raspbian OS which is what came pre installed, I was able to wirelessly connect to the internet. I have been trying to figure out how i can replicate it within FreeBSD. 



_View: https://www.youtube.com/watch?v=nasH0VLkqrY_
, after following this tutorial I need to run a command - sysctl net.wlan.devices. I get 'unknown oid net.wlan.devices'. Okay so now I try it this guys way, 



_View: https://www.youtube.com/watch?v=SQxReyTmtiE_
, he searched through the output of a command - 'dmesg | more' He found the interface that was along the lines of 'wireless dual-band'. So, I did the same, and could not eyeball anything, so i used grep; the result of 'grep -i 'band' f.txt was that nothing was returned. grep -i "dual-band" f.txt returned nothing and grep -i "broadband" f.txt returned 3 things, none of which seemed to be of use. sdhci_bcm0: <Broadcom 2708 SDHCI controller> the second line was similar, and the third line was <Broadcom BCM2835/BCM2838 RNG>.
If i was able to connect wirelessly on raspbian, why can i not seem to do the same on FreeBSD? How am i able to retrieve the correct interface?


----------



## ccammack (Jun 5, 2022)

The wiki indicates WiFi is unsupported on RPi 4.


----------



## Alain De Vos (Jun 5, 2022)

Put in a cheap USB WIFI dongle.


----------



## noahbar (Jun 6, 2022)

ccammack umm, not sure how that's possible, I just did a search and sources say yes, aswell as i had wifi on my raspbian OS Update: just read the link you sent and it does support "dual band wireless".


----------



## noahbar (Jun 6, 2022)

Alain De Vos what dongles are supported?


----------



## ccammack (Jun 6, 2022)

noahbar said:


> ccammack umm, not sure how that's possible, I just did a search and sources say yes, aswell as i had wifi on my raspbian OS Update: just read the link you sent and it does support "dual band wireless".



I think maybe Raspbian would be a better option for you.


----------



## noahbar (Jun 6, 2022)

again, I had wifi on raspbian, so i do not know how that is possible. Unfortunately, i need kqueue so freeBSD is needed. The same link that chart is from says this
The Raspberry Pi 4 uses the BCM2711 SoC (a re-implementation of BCM283X on 28nm), 1.5GHz quad-core 64-bit ARM Cortex-A72 (ARMv8) processor, 1 (no longer sold), 2, 4, or 8GB of LPDDR4 SDRAM, full-throughput Gigabit Ethernet, dual-band 802.11ac wireless, two USB 3.0 and two USB 2.0 ports, dual 4K monitor support, VideoCore VI graphics, 4Kp60 HEVC video hardware decoding, USB-C power.


----------



## SirDice (Jun 7, 2022)

noahbar said:


> I had wifi on raspbian, so i do not know how that is possible.


Raspian is Linux (Debian based distribution). Broadcom supplies Linux drivers for it. There are no such drivers for FreeBSD. Hence, it doesn't work on FreeBSD.


----------



## kpedersen (Jun 7, 2022)

If you still want to avoid Linux, then OpenBSD seems to have a working driver for the Raspberry Pi 3 onwards (https://man.openbsd.org/bwfm.4)

They do note that the firmware has known vulnerabilities and this unfortunately means that the Linux driver is also vulnerable because Broadcom haven't released new firmware.

I would recommend buying a usb Wifi dongle. Then you can probably also stick with FreeBSD anyway.


----------



## dbdemon (Jun 7, 2022)

FWIW, I successfully made WiFi work with FreeBSD 13.0 on RPi 400 (which is very similar to RPi 4) using an USB WiFi dongle (they are relatively cheap) as suggested by others here. 

More specifically, I got a Realtek USB WiFi dongle and used the rtwn driver.


----------



## SirDice (Jun 7, 2022)

I have a Pi3 (Wifi also doesn't work there) with an EDIMAX dongle for Wifi. Works just fine. But it seems the newer EDIMAX dongles use a different chipset, those don't seem to work. Mine's quite old now, the one I have works with the rtwn(4) driver.


```
rtwn0: <Realtek 802.11n WLAN Adapter, class 0/0, rev 2.00/2.00, addr 4> on usbus1
rtwn0: MAC/BB RTL8188CUS, RF 6052 1T1R
```
Not the fastest thing in the world, but it'll get your Raspberry online wirelessly (the wired gigabit connection works fine by the way).


----------



## noahbar (Jun 8, 2022)

SirDice how did you get the rtwn-usb driver installed? did you need to add it in the kernel or are you able to add it in your loader.conf?


----------



## SirDice (Jun 8, 2022)

Didn't need to load it anywhere. Not a custom kernel either. Only have this in /etc/rc.conf:

```
wlans_rtwn0="wlan0"
ifconfig_wlan0="WPA SYNCDHCP country NL"
```


----------



## noahbar (Jun 8, 2022)

so you have nothing pertaining to the dongle in the loader.conf file? I don't understand how that is possible since you also need the firmwares i think? I am probably making it a lot harder than it is


----------



## SirDice (Jun 8, 2022)

noahbar said:


> so you have nothing pertaining to the dongle in the loader.conf file?


Correct.



noahbar said:


> I don't understand how that is possible since you also need the firmwares i think


Firmware is loaded when the kernel module is loaded. It gets automatically loaded because I'm configuring it in /etc/rc.conf.


----------



## noahbar (Jun 8, 2022)

Wow, that is good news... amazing news actually. Have you had problems with your ssid showing up... my carrier status shows no carrier, but i have a theory. since my ssid does not get picked up by my ifconfig command whenever its in the supplicant, but it does whenever i put it in the rc.conf file, i think that the psk is doing the same, making it not connect. I can also scan for ssids just fine & it is visible.


----------



## SirDice (Jun 8, 2022)

noahbar said:


> my carrier status shows no carrier


That means you're not associated with the wireless network. You will need to use wpa_supplicant(8) (wpa_supplicant.conf(5)) to get associated with the wireless network first. Most people will need to do WPA authentication with their wireless access point. Then your `status` will become 'associated'. You need to get 'connected' with the wireless network before you can run TCP/IP on top of that.

With a wired connection you need to attach the cable obviously, but that cable needs to have a 'sync' signal on it too, that's the little green light that comes on when you connect a (working) ethernet cable. Same deal with wireless but without the wires.

Wired or wireless ethernet is layer 2. You need a layer 2 connection before you can run any of the higher layers (TCP/IP; layer 3/4) on top of that.


----------



## noahbar (Jun 8, 2022)

Yes, I believe I understand that bit. I have a file called wpa_supplicant.conf that contains

```
network={
ssid="myssid"
psk="mypassword"
}
```
this file i have is located in /etc/wpa_supplicant.conf
im using exactly what you have in your /etc/rc.conf file & my router credentials in my supplicant file. When i run service netif restart, it shows: ssid: "" which i believe means it doesnt even see wpa supplicant because my ssid is listed in it?


----------



## SirDice (Jun 8, 2022)

Good, you can test that using `wpa_supplicant -i wlan0 -c /etc/wpa_supplicant.conf`. If that appears to work then just put this in /etc/rc.conf:

```
wlans_rtwn0="wlan0"
ifconfig_wlan0="WPA SYNCDHCP country NL"
```
Change the country code to your region though, I had to set mine to NL because of regulations (countries have various frequencies reserved for wifi, but not all countries have all the bands available).


----------



## noahbar (Jun 8, 2022)

i get a socket function error, the error message:
successfully initialized wpa_supplicant
ioctl[..., op=20, val=0, arg_len=7] Invalid argument]
ioctl[..., op=20, val=0, arg_len=7] Invalid argument]
followed by a CTL-EVENT-SCAN-FAILED

that is for the exact command you sent, if i replace wlan0 with my interface (rtwn0) i get this,
successfully initialized wpa_supplicant
failed to initialize driver interface


----------



## serjsk8 (Jun 8, 2022)

noahbar said:


> Alain De Vos what dongles are supported?


Hi,
I use Comfast WiFi RTL8188EUS, 2,4G, 150Mbps, 802.11b/G/n USB dongles and it is work ok.


----------



## noahbar (Jun 8, 2022)

i have a netgear a6100 which is supported according to the docs


----------



## SirDice (Jun 8, 2022)

noahbar said:


> if i replace wlan0 with my interface (rtwn0) i get this,


No, you're not supposed to use the wireless interface directly. You must clone the interface (that's what wlan0 is). 

Just add the two lines I showed to /etc/rc.conf and reboot. See what that gets you.


----------



## noahbar (Jun 8, 2022)

i see, it was worth a shot since i'm trying pretty much everything atp. Once i have added the two lines you showed and called 'reboot' i still get nothing, and my ssid is still showing up blank in my ifconfig, i know there is a way to set the ssid using the rc.conf file, is there a way to set the psk using the rc.conf file too? I have also made sure i plugged the dongle into the usb2.0 and not 3.0 port since thats what the manpage says is supported


----------



## SirDice (Jun 8, 2022)

It's entirely possible that Netgear a6100 you have uses a different variant of that rtwn(4) chipset. Realtek has a tendency to push out a LOT of variants of existing chipsets. Not all of them are supported by rtwn(4) unfortunately.

What does `sysctl net.wlan.devices` show?


----------



## noahbar (Jun 8, 2022)

sysctl net.wlan.devices shows: rtwn0


----------



## noahbar (Jun 8, 2022)

its possible that that can happen even though it says my device is listed in the manpages?


----------



## SirDice (Jun 8, 2022)

Ok, at least the driver recognizes the card. Realtek has a tendency to modify their chips and not change the chip's identifications though. So the driver "thinks" it's a certain type of chip but in reality it's a slightly different one. 

We just need to figure out if that's the case.


----------



## noahbar (Jun 8, 2022)

i can also scan for ssids too. How we do continue debugging?


----------



## Alain De Vos (Jun 8, 2022)

I have a problem playing youtube videos with firefox. audacious works fine.


----------



## SirDice (Jun 8, 2022)

Alain De Vos said:


> I have a problem playing youtube videos with firefox. audacious works fine.


Mixed up your threads?



noahbar said:


> I can also scan for ssids too.


That's encouraging. Does your SSID show up?


----------



## noahbar (Jun 9, 2022)

SirDice said:


> Mixed up your threads?
> 
> 
> That's encouraging. Does your SSID show up?


yep, all nearby ssids show up including my main router and my extension thats placed in my room. I still think its because its not properly reading my wpa_supplicant file.


----------



## wb7odyfred (Oct 23, 2022)

Hello, NoahBar,  I have posted 2 forum posts at forums.ghostbsd.org about setting up wireless connection manually.  You seem close to a working solution.  Give the following a read and a test.

https://forums.ghostbsd.org/viewtopic.php?f=64&t=526   Edimax EW-7811un Version 1 that uses a RTL8192cu Realtek chipset.
https://forums.ghostbsd.org/viewtopic.php?f=64&t=570   RTL8188ce PCI Realtek chipset

Use the following lines for testing wpa_supplicant with the Debug and Password debug printout options

```
killall dhclient
wpa_supplicant -d -K -i wlan0 -c /etc/wpa_supplicant.conf
dhclient wlan0
```


Manually issue the  wpa_supplicant with the background Dameon option and dhclient commands

```
killall dhclient
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf
dhclient wlan0
```


----------



## wb7odyfred (Oct 23, 2022)

Your Netgear A6100 USB device is a Realtek RTL8811au chipset that should work with FreeBSD 12.1 or newer release.
https://bsd-hardware.info/?id=usb:0...802.11a/b/g/n/ac+WLAN+Adapter&dev_ident=77a9d

See this similar thread about RTL8812au Realtek device. It has other good troubleshooting details.
https://forums.freebsd.org/threads/freebsd-12-driver-to-use-with-rtl8812au.75090/


```
pkg install hw-probe
hw-probe -all -upload
```






The device is supported by FreeBSD versions 12.1 and newer:


----------



## wb7odyfred (Oct 23, 2022)

I have used FreeBSD 14.0-CURRENT on a Raspberry Pi 4B with 8 gigs of dram memory.  In fact I am typing this reply from this Raspberry Pi 4B.   Sound does now work from the HDMI VCHIQ outport audio.  I welcome your comments, NoahBar and others

https://ghostbsd-arm64.blogspot.com/2022/09/freebsd-140-compiling-kernel-for.html


----------

