[Replicant] [PATCH v3] Add native Android support for external WiFi dongles
Joonas Kylmälä
joonas.kylmala at iki.fi
Mon Oct 14 15:26:51 UTC 2019
Hi,
I have pushed it now here:
<https://git.replicant.us/replicant/frameworks_opt_net_wifi/log/?h=replicant-6.0>.
It still needs to be added to the manifest which I will submit a patch
in a moment.
Joonas
Joonas Kylmälä:
> Hi,
>
> removing the multicast packet filtering is not ideal but I checked the
> RepWifi code and it doesn't seem to be setting any packet filters either
> so that seems to be a separate problem to be solved. Otherwise the patch
> seems okay and I have tested it works:
>
> Acked-by: Joonas Kylmälä <joonas.kylmala at iki.fi>
>
> Thanks a lot Belgin!
>
> Joonas
>
> Belgin ?tirbu:
>> With this patch, if the nonfree firmware is found, the internal WiFi
>> is used, otherwise the WiFi state machine tries to use the external
>> WiFi adapter.
>>
>> Because the WiFiStateMachine tries to do things with the
>> Bluetooth Coexistence mode, which the ath9k driver
>> doesn't seem to have (at least not by default),
>> wpa_supplicant registers enough consecutive errors
>> to think the driver hanged, so it stops the
>> connection. To work around this, I have commented
>> the calls to enable/disable Bluetooth Coexistence
>> mode in the WiFi state machine java file. A proper fix
>> for this would be to enable Bluetooth Coexistence
>> mode in the ath9k driver.
>>
>> Regarding removing the multicast packet filtering
>> code, the same wpa_supplicant issue as above was occuring,
>> causing wpa_supplicant to disconnect after a few errors.
>> I am unsure if this affects the firewall in any way.
>>
>> Signed-off-by: Belgin Stirbu <belginstirbu at hotmail.com>
>> ---
>> .../com/android/server/wifi/WifiStateMachine.java | 103 ++++++++++++++-------
>> 1 file changed, 67 insertions(+), 36 deletions(-)
>>
>> diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java
>> index 38d0ac8..6d9c0d0 100644
>> --- a/service/java/com/android/server/wifi/WifiStateMachine.java
>> +++ b/service/java/com/android/server/wifi/WifiStateMachine.java
>> @@ -198,7 +198,8 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno
>> private ConnectivityManager mCm;
>> private DummyWifiLogger mWifiLogger;
>> private WifiApConfigStore mWifiApConfigStore;
>> - private final boolean mP2pSupported;
>> + private boolean mP2pSupported;
>> + private boolean mDongleConnected;
>> private boolean mIbssSupported;
>> private final AtomicBoolean mP2pConnected = new AtomicBoolean(false);
>> private boolean mTemporarilyDisconnectWifi = false;
>> @@ -1155,6 +1156,8 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno
>> mP2pSupported = mContext.getPackageManager().hasSystemFeature(
>> PackageManager.FEATURE_WIFI_DIRECT);
>>
>> + mDongleConnected = false;
>> +
>> mWifiNative = new WifiNative(mInterfaceName);
>> mWifiConfigStore = new WifiConfigStore(context,this, mWifiNative);
>> mWifiAutoJoinController = new WifiAutoJoinController(context, this,
>> @@ -5274,16 +5277,19 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno
>>
>> void handlePreDhcpSetup() {
>> mDhcpActive = true;
>> - // Disable the coexistence mode
>> - mWifiNative.setBluetoothCoexistenceMode(
>> - mWifiNative.BLUETOOTH_COEXISTENCE_MODE_DISABLED);
>>
>> - // Disable power save and suspend optimizations during DHCP
>> - // Note: The order here is important for now. Brcm driver changes
>> - // power settings when we control suspend mode optimizations.
>> - // TODO: Remove this comment when the driver is fixed.
>> - setSuspendOptimizationsNative(SUSPEND_DUE_TO_DHCP, false);
>> - mWifiNative.setPowerSave(false);
>> + if (mDongleConnected == false) {
>> + // Disable the coexistence mode
>> + mWifiNative.setBluetoothCoexistenceMode(
>> + mWifiNative.BLUETOOTH_COEXISTENCE_MODE_DISABLED);
>> +
>> + // Disable power save and suspend optimizations during DHCP
>> + // Note: The order here is important for now. Brcm driver changes
>> + // power settings when we control suspend mode optimizations.
>> + // TODO: Remove this comment when the driver is fixed.
>> + setSuspendOptimizationsNative(SUSPEND_DUE_TO_DHCP, false);
>> + mWifiNative.setPowerSave(false);
>> + }
>>
>> // Update link layer stats
>> getWifiLinkLayerStats(false);
>> @@ -5337,15 +5343,17 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno
>> }
>>
>> void handlePostDhcpSetup() {
>> - /* Restore power save and suspend optimizations */
>> - setSuspendOptimizationsNative(SUSPEND_DUE_TO_DHCP, true);
>> - mWifiNative.setPowerSave(true);
>> + if (mDongleConnected == false) {
>> + /* Restore power save and suspend optimizations */
>> + setSuspendOptimizationsNative(SUSPEND_DUE_TO_DHCP, true);
>> + mWifiNative.setPowerSave(true);
>>
>> - mWifiP2pChannel.sendMessage(WifiP2pServiceImpl.BLOCK_DISCOVERY, WifiP2pServiceImpl.DISABLED);
>> + mWifiP2pChannel.sendMessage(WifiP2pServiceImpl.BLOCK_DISCOVERY, WifiP2pServiceImpl.DISABLED);
>>
>> - // Set the coexistence mode back to its default value
>> - mWifiNative.setBluetoothCoexistenceMode(
>> - mWifiNative.BLUETOOTH_COEXISTENCE_MODE_SENSE);
>> + // Set the coexistence mode back to its default value
>> + mWifiNative.setBluetoothCoexistenceMode(
>> + mWifiNative.BLUETOOTH_COEXISTENCE_MODE_SENSE);
>> + }
>>
>> mDhcpActive = false;
>> }
>> @@ -6047,8 +6055,12 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno
>> * Avoids issues with drivers that do not handle interface down
>> * on a running supplicant properly.
>> */
>> + mDongleConnected = false;
>> mWifiMonitor.killSupplicant(mP2pSupported);
>>
>> + mP2pSupported = mContext.getPackageManager().hasSystemFeature(
>> + PackageManager.FEATURE_WIFI_DIRECT);
>> +
>> if (mWifiNative.loadDriver()) {
>> try {
>> mNwService.wifiFirmwareReload(mInterfaceName, "STA");
>> @@ -6096,7 +6108,21 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno
>> }
>> } else {
>> loge("Failed to load driver");
>> - setWifiState(WifiManager.WIFI_STATE_FAILED);
>> +
>> + loge("trying to load external wifi dongle");
>> + mP2pSupported = false;
>> + mWifiMonitor.killSupplicant(mP2pSupported);
>> +
>> + if (mWifiNative.startSupplicant(mP2pSupported)) {
>> + setWifiState(WIFI_STATE_ENABLING);
>> + if (DBG) log("Supplicant start successful");
>> + mWifiMonitor.startMonitoring();
>> + mDongleConnected = true;
>> + transitionTo(mSupplicantStartingState);
>> + } else {
>> + loge("Failed to start supplicant!");
>> + setWifiState(WifiManager.WIFI_STATE_FAILED);
>> + }
>> }
>> break;
>> case CMD_START_AP:
>> @@ -6527,23 +6553,26 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno
>> mInDelayedStop = false;
>> mDelayedStopCounter++;
>> updateBatteryWorkSource(null);
>> - /**
>> - * Enable bluetooth coexistence scan mode when bluetooth connection is active.
>> - * When this mode is on, some of the low-level scan parameters used by the
>> - * driver are changed to reduce interference with bluetooth
>> - */
>> - mWifiNative.setBluetoothCoexistenceScanMode(mBluetoothConnectionActive);
>> - /* initialize network state */
>> - setNetworkDetailedState(DetailedState.DISCONNECTED);
>>
>> - /* Remove any filtering on Multicast v6 at start */
>> - mWifiNative.stopFilteringMulticastV6Packets();
>> + if (mDongleConnected == false) {
>> + /**
>> + * Enable bluetooth coexistence scan mode when bluetooth connection is active.
>> + * When this mode is on, some of the low-level scan parameters used by the
>> + * driver are changed to reduce interference with bluetooth
>> + */
>> + mWifiNative.setBluetoothCoexistenceScanMode(mBluetoothConnectionActive);
>> + /* initialize network state */
>> + setNetworkDetailedState(DetailedState.DISCONNECTED);
>>
>> - /* Reset Multicast v4 filtering state */
>> - if (mFilteringMulticastV4Packets.get()) {
>> - mWifiNative.startFilteringMulticastV4Packets();
>> - } else {
>> - mWifiNative.stopFilteringMulticastV4Packets();
>> + /* Remove any filtering on Multicast v6 at start */
>> + mWifiNative.stopFilteringMulticastV6Packets();
>> +
>> + /* Reset Multicast v4 filtering state */
>> + if (mFilteringMulticastV4Packets.get()) {
>> + mWifiNative.startFilteringMulticastV4Packets();
>> + } else {
>> + mWifiNative.stopFilteringMulticastV4Packets();
>> + }
>> }
>>
>> mDhcpActive = false;
>> @@ -6647,9 +6676,11 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiPno
>> }
>> break;
>> case CMD_BLUETOOTH_ADAPTER_STATE_CHANGE:
>> - mBluetoothConnectionActive = (message.arg1 !=
>> - BluetoothAdapter.STATE_DISCONNECTED);
>> - mWifiNative.setBluetoothCoexistenceScanMode(mBluetoothConnectionActive);
>> + if (mDongleConnected == false) {
>> + mBluetoothConnectionActive = (message.arg1 !=
>> + BluetoothAdapter.STATE_DISCONNECTED);
>> + mWifiNative.setBluetoothCoexistenceScanMode(mBluetoothConnectionActive);
>> + }
>> break;
>> case CMD_STOP_DRIVER:
>> int mode = message.arg1;
>>
> _______________________________________________
> Replicant mailing list
> Replicant at osuosl.org
> https://lists.osuosl.org/mailman/listinfo/replicant
>
More information about the Replicant
mailing list