[Replicant] [PATCH v2] Add native Android support for external WiFi dongles
Joonas Kylmälä
joonas.kylmala at iki.fi
Sat Oct 12 15:56:23 UTC 2019
Hi,
I'm a bit worried about removing the code about multicast packet
filtering. Would this have some sort of effect on the firewall
configuration?
You also dropped the signed-off-by line and the description why
bluetooth and the packet filter needs to be removed, please add those
back for v3.
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.
> ---
> .../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;
>
More information about the Replicant
mailing list