[BPI-R2] internal Wifi/BT (MT6625L) - Kernel

mhm, i guess the hook, triggered by ip link address is not implemented…but i do not know more…but still wondering why i has worked one time

I assume client-mode also works for 5.10.76, correct?

i guess too, as there were no changes…i use only ap-mode

UPDATE: Several hours later (and a complete work shift), I finally got around to trying it on 5.10.76. It does appear to work on the onboard wifi. Thanks!

EDIT: Apologees for not being brave enough to try it first before asking questions. It was right before my work shift started and I needed to leave in a few minutes. Thought I’d ask before trying it. Wanna save my hair from being pulled out! :stuck_out_tongue:

You could try on 5.15-main too :slight_smile:

I just compiled 5.15-main branch on my computer and tried it on my R2. It appears to work, as I can get a DHCP address from my primary router. I can aslo ping my primary router, as well. However, pinging my computer that I’m SSH’ing from doesn’t work, nor does any internet site… (Sigh…)

I need to do more investigation to see what the problem with my configuration is… I’ll update once I figure out how to fix the problem…

Without knowing your network topology and what works exactly and what not we can’t help here.

Do you try pinging over r2 (e.g. client on wifi - traffic over wan)? Then your main-router needs to know subnet of wifi to be reached over r2.

Okay, I figured out what was going on. I forgot I needed a firewall rule to masquerade to the wifi internet connection… Had one for the WAN port, not the wireless interface… Also had to rewrite some of my firewall script in order to deal with lack of pings and masquerading interfaces, so this is a plus…

I also figured out how to bring the mt6625_0 and ap0 interfaces up before the networking services starts. In this way, those interfaces can be correctly configured by the networking services.

My /sbin/networking-helper.sh script:

#!/bin/bash
#############################################################################
# Bring the "eth0" interface up if not already up:
#############################################################################
ifconfig eth0 2> /dev/null | grep "UP," &> /dev/null || /sbin/ifup eth0 >& /dev/null
ifconfig eth1 2> /dev/null | grep "UP," &> /dev/null || /sbin/ifup eth1 >& /dev/null

#############################################################################
# Enable DBDC on any MT76xx wifi card that supports it:
#############################################################################
for file in /sys/kernel/debug/ieee80211/*; do
	test -e $file/mt76/dbdc && echo 1 > $file/mt76/dbdc
done

#############################################################################
# Load support files for R2's onboard Wifi/BT hardware and set WiFi mode:
#############################################################################
if [[ ! -e /dev/wmtWifi ]]; then
	/usr/bin/wmt_loader &> /var/log/wmtloader.log
	sleep 3
fi
if [[ -c /dev/stpwmt ]]; then
	if ! ps aux | grep stp_uart_launcher | grep -v grep >& /dev/null; then
		/usr/bin/stp_uart_launcher -p /etc/firmware &> /var/log/stp_launcher.log &
		sleep 5
	fi
fi
modprobe wlan_gen2
[[ -f /var/run/wmtWifi ]] && echo 0 > /dev/wmtWifi && sleep 3
echo $([[ "${ONBOARD_WIFI:-"A"}" == "A" ]] && echo A || echo 1) | tee /var/run/wmtWifi > /dev/wmtWifi

#############################################################################
# Rename the WiFi interfaces on the MT76xx wifi card:
#############################################################################
cd /sys/class/net
LIST=($(ls -l | grep pcie | awk '{print $9}'))
if [[ ! -z "${LIST[@]}" ]]; then
	for IFACE in ${LIST[@]}; do
		DEV="$(lspci -s $(basename $(ls -l ${IFACE}/device | awk '{print $NF}')) | grep MEDIATEK | awk '{print $NF}')"
		if [[ ! -z "${DEV}" ]]; then
			[[ -f /sys/kernel/debug/ieee80211/$(basename $(ls -l ${IFACE}/phy80211 | awk '{print $NF}'))/mt76/dbdc ]] && POST=24g || POST=5g
			NEW=mt${DEV}_${POST}
			ip link set ${IFACE} name ${NEW}
			iw dev ${NEW} interface add ${NEW}_0 type managed
			REN=$(dmesg | grep ${NEW}_0 | head -1 | awk '{print $5}' | sed 's|:||g')
			[[ "$REN" != "${NEW}_0" ]] && ip link set ${REN} name ${NEW}_0
		fi
	done
fi

#############################################################################
# Return error code 0 to the caller:
#############################################################################
exit 0

My /lib/systemd/system/networking.service.d/changes.conf:

[Service]
ExecStartPre=/sbin/networking-helper.sh
ExecStart=
ExecStart=/sbin/ifup -a --read-environment --exclude=eth0

Hopefully this will help someone…

These changes will allow the networking service to be restarted without the errors concerning the eth0 and/or eth1 interfaces… Speaking of which, eth1 and aux showed up while running kernel 5.15.11, while it didn’t on 5.10.76… Any insights to this?

Yes with masquerading you hide your wifi subnet…wifi clients reach your mainrouter with the subnet it knows.

It should be eth0 and aux and eth0/1 on older kernels (eth1 may be missing). Eth1/aux is same port but it needs some work to can use it. You can make a vlan-aware bridge to map wan-port to it an use both gmacs. This is becauae dsa core (which does the wan/lanX) only support 1 upstream/cpu port and the other cannot be used that easy

I assume using both gmacs would increase performance, right? If so, I’m interested in learning how…

It reduces traffic on eth0 by routing wan - traffic over eth1/aux

See second ethernet lane here: https://www.fw-web.de/dokuwiki/doku.php?id=en:bpi-r2:network:start#permanent

When booting from emmc the eth1 GMAC only works with bootswitch in 0 position…

On r2 too? I thought this was only r64. But imho bootswitch makes only sense in 1 position (try sdcard first than emmc). But cannot try it on r2 as my version (1.1) has no bootswitch (non working bat connector)

Ah forgot we’re writing about the R2… I do not own one so I also cannot test it. It is bootrom related so it could be in that rom too…

I’m waiting to buy an R2 pro. Just got an old rk3288 board out if the dustpile to get to know the rockchip boot process a little.

I tried this tip on my copy of Debian 10 running kernel 5.15.11 and I saw a definite improvement. Also, if anybody is interested, I want to note that while the onboard wifi is in AP mode, you CAN create a client connection, but not both AP and client at the same time. Must be one or the other…

EDIT: I can create a DHCP client connection only on the mt6625_0 interface. Apparently, I cannot do so on the ap0 interface, even though iw list says that I should be able to (it supports managed mode).

2nd EDIT: Cannot get bluetooth up and running… Maybe you can do client and AP, haven’t tested the combination…

Right ap0 only supports accesspoint mode. Thanks for testing client mode. And yes only one connection is possible (ap or client).

For bluetooth: it is important that bluetooth module is loaded after wmt/stp tools are finished. See my wifi.sh. and it does not support btle (bt4.0+) only legacy bt

I’m guessing that I don’t have the necessary bluetooth module loaded at all.

EDIT: Found it! Running command modprobe stp_chrdev_bt allows me to see the bluetooth stuff. Thanks!

2nd Edit: Okay, following the advice of the wiki, I can get up to “hciconfig hci0 up” without issue. But when I try that command, I get this: Can’t init device hci0: Input/output error (5), Any thoughts?

3rd Edit: After starting the the wifi programs, then loadng modules, then the bluetooth service, I launched bluetoothctl. When I type in devices, it says No default controller available… Hmmmmm…

You should only try after clean bootup,not loading/unloading modules.and try my wifi.sh to bring all up…it loads bluetooth module too. If you need client-mode instead of ap you can exit script there.

edit: mhm, i guess i miss something in 5.15…

based on my wiki there should be service classes

root@bpi-r2:~# hciconfig -a                                                     
hci0:   Type: Primary  Bus: SDIO                                                
        BD Address: 00:00:46:85:90:01  ACL MTU: 1021:4  SCO MTU: 184:1          
        DOWN                                                                    
        RX bytes:539 acl:0 sco:0 events:25 errors:0                             
        TX bytes:363 acl:0 sco:0 commands:25 errors:0                           
        Features: 0xbf 0x3e 0x8d 0xfe 0xdb 0xff 0x5b 0x87                       
        Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3                        
        Link policy: RSWITCH SNIFF                                              
        Link mode: MASTER

https://www.fw-web.de/dokuwiki/doku.php?id=en:bpi-r2:bluetooth

but dmesg looks good

dmesg | grep -i bluetooth                                        
[    3.450555] Bluetooth: Core ver 2.22                                         
[    3.454221] NET: Registered PF_BLUETOOTH protocol family                     
[    3.459568] Bluetooth: HCI device and connection manager initialized         
[    3.465997] Bluetooth: HCI socket layer initialized                          
[    3.470910] Bluetooth: L2CAP socket layer initialized                        
[    3.476037] Bluetooth: SCO socket layer initialized                          
[  429.325552] Bluetooth: BNEP (Ethernet Emulation) ver 1.3                     
[  429.325599] Bluetooth: BNEP socket layer initialized

edit: tried to put hci0 up

root@bpi-r2:~# hciconfig hci0 up                                                
Can't init device hci0: Invalid request code (56)

My hciconfig -a:

root@bpiwrt:~# hciconfig -a
hci0:	Type: Primary  Bus: SDIO
	BD Address: 00:00:46:85:90:01  ACL MTU: 1021:4  SCO MTU: 184:1
	DOWN 
	RX bytes:1078 acl:0 sco:0 events:50 errors:0
	TX bytes:726 acl:0 sco:0 commands:50 errors:0
	Features: 0xbf 0x3e 0x8d 0xfe 0xdb 0xff 0x5b 0x87
	Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
	Link policy: RSWITCH SNIFF 
	Link mode: MASTER 

root@bpiwrt:~# hciconfig hci0 up
Can't init device hci0: Input/output error (5)

My dmesg filtering the string bluetooth:

root@bpiwrt:~# dmesg | grep -i bluetooth
[    2.924406] Bluetooth: Core ver 2.22
[    2.924486] NET: Registered PF_BLUETOOTH protocol family
[    2.924508] Bluetooth: HCI device and connection manager initialized
[    2.924534] Bluetooth: HCI socket layer initialized
[    2.924555] Bluetooth: L2CAP socket layer initialized
[    2.924587] Bluetooth: SCO socket layer initialized
[   33.573870] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[   33.579324] Bluetooth: BNEP socket layer initialized

Looks same as yours…

I used your wifi.sh to bring up everything onboard and get the same results. Had same issue with 5.10.76, if it helps…

maybe something has changed for bluetooth…have not used it much…only did some tests afair in 4.19.

could you try 5.4/4.19?

else you could try adding debug-code in driver to see how far it goes

maybe driver aborts because a debugfs entry is present

dmesg | grep -i hci0                                             
[  265.910425] debugfs: File 'dut_mode' in directory 'hci0' already present!

did not see where driver should create this…seems to be done only in core ./net/bluetooth/hci_core.c in hci_debugfs_create_basic, seems not breaking anything

maybe set debug here