wireless-carplay-dongle-reverse-engineering icon indicating copy to clipboard operation
wireless-carplay-dongle-reverse-engineering copied to clipboard

WiFi Radio Optimizations

Open edominicci opened this issue 3 years ago • 17 comments

Several WiFi optimizations can be done to relieve some of the performance issues due to interference or lack of bandwidth.

According to Apple's development notes, 5GHz 802.11ac is recommended for wireless CarPlay: https://developer.apple.com/videos/play/wwdc2017/717

The transceiver contained in this module is 802.11ac compliant, and is more than capable of doing it. Security is also that we should be able to modify by using WPA2-AES instead of WPA.

/etc/hostapd.conf contains a fairly basic config, I recommend the following changes:

driver=rtl871xdrv ieee80211ac=1 hw_mode=a channel=36 beacon_int=100 dtim_period=1

wmm_enabled=1 wmm_ac_bk_cwmin=4 wmm_ac_bk_cwmax=10 wmm_ac_bk_aifs=7 wmm_ac_bk_txop_limit=0 wmm_ac_bk_acm=0 wmm_ac_be_aifs=3 wmm_ac_be_cwmin=4 wmm_ac_be_cwmax=10 wmm_ac_be_txop_limit=0 wmm_ac_be_acm=0 wmm_ac_vi_aifs=2 wmm_ac_vi_cwmin=3 wmm_ac_vi_cwmax=4 wmm_ac_vi_txop_limit=94 wmm_ac_vi_acm=0 wmm_ac_vo_aifs=2 wmm_ac_vo_cwmin=2 wmm_ac_vo_cwmax=3 wmm_ac_vo_txop_limit=47 wmm_ac_vo_acm=0

The WMM parameters may need a bit more work, but WMM is required for a working AC configuration.

edominicci avatar Apr 13 '21 20:04 edominicci

Nice -- do you have any before and after results to share? E.g. any noticeable improvements?

dmavromatis avatar Apr 15 '21 00:04 dmavromatis

Not yet, I am still testing a few more things to try and figure out what causes the intermittent audio breakouts before I change these.

It could be related, but I am not entirely convinced that this is the root cause.

edominicci avatar Apr 15 '21 00:04 edominicci

What's the original hostapd.conf? I still believe the USB to be the bottleneck in terms of bandwidth...

CiNcH83 avatar Apr 18 '21 10:04 CiNcH83

OK, found original hostapd.conf:

# Basic configuration

interface=wlan0
ssid=AutoBox-582f
#bridge=br0

# WPA and WPA2 configuration

macaddr_acl=0
auth_algs=3
ignore_broadcast_ssid=0
wpa=3
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

#device_type=6-0050F204-1
# Hardware configuration

#wmm_enabled=1
#wmm_ac_bk_cwmin=4
#wmm_ac_bk_cwmax=10
#wmm_ac_bk_aifs=7
#wmm_ac_bk_txop_limit=0
#wmm_ac_bk_acm=0
#wmm_ac_be_aifs=3
#wmm_ac_be_cwmin=4
#wmm_ac_be_cwmax=10
#wmm_ac_be_txop_limit=0
#wmm_ac_be_acm=0
#wmm_ac_vi_aifs=2
#wmm_ac_vi_cwmin=3
#wmm_ac_vi_cwmax=4
#wmm_ac_vi_txop_limit=94
#wmm_ac_vi_acm=0
#wmm_ac_vo_aifs=2
#wmm_ac_vo_cwmin=2
#wmm_ac_vo_cwmax=3
#wmm_ac_vo_txop_limit=47
#wmm_ac_vo_acm=0

driver=rtl871xdrv
ieee80211n=1
#ieee80211ac=1
#hw_mode=g
#channel=1
hw_mode=a
channel=36
#require_ht=1
beacon_int=100
dtim_period=1

#ht_capab=[HT40+]
ht_capab=[SHORT-GI-20][SHORT-GI-40][HT40+]
device_name=RTL8822BS
#device_name=RTL8188EU
manufacturer=Realtek

CiNcH83 avatar Apr 18 '21 11:04 CiNcH83

Just some additional info on 802.11n vs. 802.11ac. On the Carlinkit/CPLAY2air dongles, we have a 2x2 antenna configuration. On 40MHz wide channels, this means up to 300mbps on N and 400mbps on AC (net speed is around half of that). For 80MHz wide channels, vht_capab has to be set.

CiNcH83 avatar Apr 22 '21 18:04 CiNcH83

Security is also that we should be able to modify by using WPA2-AES instead of WPA.

The given configuration supports both, WPA(TKIP) and WPA2(CCMP-AES). All CarPlay enabled iPhones connect with WPA2. So it may be safe to disable WPA altogether.

Not yet, I am still testing a few more things to try and figure out what causes the intermittent audio breakouts before I change these.

Since screen and control data have higher priority with WMM enabled (for better touchscreen reaction times), media audio may starve a bit. So you may have to increase Media Delay in the adapter's settings: grafik

1000ms is the default. You may try 1500ms. I actually hoped that the higher transfer speeds of 802.11ac would compensate for the higher priority touchscreen data.

(Also making phone calls benefits from WMM. So there may be less delay.)

Another possible enhancement... uapsd_advertisement_enabled=1 may help reducing the iPhone's power consumption during a CarPlay session. It is recommended by Apple to be enabled.

CiNcH83 avatar May 04 '21 11:05 CiNcH83

Have you tested these changes on the device yet? I'm willing to do it on a dev dongle I have, but want to make sure it doesn't brick the unit due to WiFi not working after making the modifications.

dmavromatis avatar May 04 '21 16:05 dmavromatis

I am not on a custom FW. I am just familiar with Wi-Fi and hostapd.

Replacing hostapd.conf shouldn't be much of a problem though when using custom FW. It can be done via USB stick and U2W.sh. If the config doesn't work, the original hostapd.conf can be restored.

CiNcH83 avatar May 04 '21 17:05 CiNcH83

@CiNcH83 can you look over the following and check if it looks good to you? Just want to make sure I'm not missing anything from the discussion above 😀

# Basic configuration

interface=wlan0
ssid=AutoBox-582f
#bridge=br0

# WPA and WPA2 configuration

macaddr_acl=0
auth_algs=3
ignore_broadcast_ssid=0
wpa=3
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

#device_type=6-0050F204-1
# Hardware configuration

# https://github.com/ludwig-v/wireless-carplay-dongle-reverse-engineering/issues/54#issue-857282109

driver=rtl871xdrv
ieee80211ac=1
channel=36
hw_mode=a
channel=36
#require_ht=1
beacon_int=100
dtim_period=1

wmm_enabled=1
wmm_ac_bk_cwmin=4
wmm_ac_bk_cwmax=10
wmm_ac_bk_aifs=7
wmm_ac_bk_txop_limit=0
wmm_ac_bk_acm=0
wmm_ac_be_aifs=3
wmm_ac_be_cwmin=4
wmm_ac_be_cwmax=10
wmm_ac_be_txop_limit=0
wmm_ac_be_acm=0
wmm_ac_vi_aifs=2
wmm_ac_vi_cwmin=3
wmm_ac_vi_cwmax=4
wmm_ac_vi_txop_limit=94
wmm_ac_vi_acm=0
wmm_ac_vo_aifs=2
wmm_ac_vo_cwmin=2
wmm_ac_vo_cwmax=3
wmm_ac_vo_txop_limit=47
wmm_ac_vo_acm=0

#ht_capab=[HT40+]
ht_capab=[SHORT-GI-20][SHORT-GI-40][HT40+]
device_name=RTL8822BS
#device_name=RTL8188EU
manufacturer=Realtek

# https://github.com/ludwig-v/wireless-carplay-dongle-reverse-engineering/issues/54#issuecomment-831874170

uapsd_advertisement_enabled=1

hassankhan avatar May 05 '21 00:05 hassankhan

Yup -- looks good to me... however @CiNcH83 & @hassankhan, I can try it out on my dev Carlinkit 2 dongle running latest CFW if you'd like.

dmavromatis avatar May 05 '21 04:05 dmavromatis

@CiNcH83 can you look over the following and check if it looks good to you?

Here are some changes and additions from my side:

# WPA2 only
auth_algs=1
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_passphrase=12345678
rsn_pairwise=CCMP

# VHT80
vht_capab=[SHORT-GI-80]
vht_oper_chwidth=1

The channel is twice in your config.

CiNcH83 avatar May 05 '21 04:05 CiNcH83

It looks like Realtek isn't really a good choice for a Linux AP, see here. hostapd-rtl871xdrv seems to be really old sh** which probably doesn't allow for AC/VHT. That's probably why Carlinkit is considering switching to Broadcom. There are however also newer nl80211 based drivers around for RTL8822BS.

CiNcH83 avatar May 05 '21 05:05 CiNcH83

@dmavromatis Awesome, please do post back if it works, definitely would be interesting if there is a noticeable improvement.

hassankhan avatar May 09 '21 01:05 hassankhan

I just realized that they are trying to enable 802.11ac and WMM for BCM4354 based models:

# Basic configuration

interface=wlan0
ssid=AutoBox-582f

# WPA and WPA2 configuration

macaddr_acl=0
auth_algs=3
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

driver=nl80211
ieee80211n=1
ieee80211ac=1
wmm_enabled=1
#hw_mode=g
#channel=11
hw_mode=a
channel=36
require_ht=1
require_vht=1

#ht_capab=[SHORT-GI-20]
#ht_capab=[SHORT-GI-20][SHORT-GI-40][HT40+]
#ht_capab=[SHORT-GI-20][SHORT-GI-40][HT40-]
#vht_capab=[SHORT-GI-80][SHORT-GI-160]

So they might be abandoning Realtek because of the bad Linux soft AP driver.

CiNcH83 avatar May 18 '21 09:05 CiNcH83

Did anyone get chance to test this out? Device works fairly well but any improvement on latency particularly phone calls would be most welcome!

simps100 avatar Jun 22 '21 13:06 simps100

Seems hostapd compiled without AC support: random: Trying to read entropy from /dev/random Configuration file: /mnt/UPAN/hostapdORIMOD.conf Line 64: unknown configuration item 'ieee80211ac' Line 70: unknown configuration item 'vht_capab' Line 71: unknown configuration item 'vht_oper_chwidth' 3 errors found in configuration file '/mnt/UPAN/hostapdORIMOD.conf'

Ar4erR07 avatar Apr 14 '22 18:04 Ar4erR07

Replacing hostapd.conf shouldn't be much of a problem though when using custom FW. It can be done via USB stick and U2W.sh. If the config doesn't work, the original hostapd.conf can be restored.

Can it be replaced when using the original firmware? I have a Carlinkit A2A (AndroidAuto) dongle and I need to change the default 5Ghz wifi channel because at channel 36 I get occasional stuttering especially in highly populated areas. Carlinkit support also confirmed that's the issue but their way of changing the wifi channel did not work.

They told me to flash the firmware with a file named default_wifi_channel and the channel number inside, but that doesn't work the device gets flashed but the channel stays at 36.

So I am trying to unpack the img file to change this setting directly on the firmware. But can't figure out how, the img file cannot be mounted or extracted, it shows a "corrputed file" error. What am I missing? O2W_AUTOKIT_Update.zip

dmi97 avatar Feb 25 '23 13:02 dmi97