Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f0928d2f authored by Bruno Randolf's avatar Bruno Randolf Committed by Ricardo Cerqueira
Browse files

Wifi: Add IBSS supported method

Add method isIbssSupported() to WifiManager and related classes to query wether
the driver supports IBSS mode. The query is answered by wpa_supplicants new
command "get_capability modes".

It will only return a correct result after WIFI_STATE_ENABLED has been
reached.

Change-Id: I93aa2fdff94cd897c91ec3beb7e58940d1de7b72
parent 3dc4364a
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -877,6 +877,21 @@ public final class WifiService extends IWifiManager.Stub {
                com.android.internal.R.bool.config_wifi_dual_band_support);
    }

    /**
     * Is Ad-Hoc (IBSS) mode supported by the driver?
     * Will only return correct results when we have reached WIFI_STATE_ENABLED
     * @return {@code true} if IBSS mode is supported, {@code false} if not
     */
    public boolean isIbssSupported() {
        enforceAccessPermission();
        if (mWifiStateMachineChannel != null) {
            return (mWifiStateMachine.syncIsIbssSupported(mWifiStateMachineChannel) == 1);
        } else {
            Slog.e(TAG, "mWifiStateMachineChannel is not initialized");
            return false;
        }
    }

    /**
     * Return the DHCP-assigned addresses from the last successful DHCP request,
     * if any.
+2 −0
Original line number Diff line number Diff line
@@ -69,6 +69,8 @@ interface IWifiManager

    boolean isDualBandSupported();

    boolean isIbssSupported();

    boolean saveConfiguration();

    DhcpInfo getDhcpInfo();
+13 −0
Original line number Diff line number Diff line
@@ -984,6 +984,19 @@ public class WifiManager {
        }
    }

    /**
     * Check if the chipset supports IBSS (Adhoc) mode
     * @return {@code true} if supported, {@code false} otherwise.
     * @hide
     */
    public boolean isIbssSupported() {
        try {
            return mService.isIbssSupported();
        } catch (RemoteException e) {
            return false;
        }
    }

    /**
     * Return the DHCP-assigned addresses from the last successful DHCP request,
     * if any.
+12 −0
Original line number Diff line number Diff line
@@ -971,5 +971,17 @@ public class WifiNative {
        doBooleanCommand("DRIVER MIRACAST " + mode);
    }

    public boolean getModeCapability(String mode) {
        String ret = doStringCommand("GET_CAPABILITY modes");
        if (!TextUtils.isEmpty(ret)) {
            String[] tokens = ret.split(" ");
            for (String t : tokens) {
                if (t.compareTo(mode) == 0)
                    return true;
            }
        }
        return false;
    }

    public native static boolean setMode(int mode);
}
+21 −0
Original line number Diff line number Diff line
@@ -118,6 +118,7 @@ public class WifiStateMachine extends StateMachine {
    private ConnectivityManager mCm;

    private final boolean mP2pSupported;
    private boolean mIbssSupported;
    private final AtomicBoolean mP2pConnected = new AtomicBoolean(false);
    private boolean mTemporarilyDisconnectWifi = false;
    private final String mPrimaryDeviceType;
@@ -413,6 +414,9 @@ public class WifiStateMachine extends StateMachine {
    public static final int CMD_DISABLE_P2P_RSP           = BASE + 133;

    public static final int CMD_BOOT_COMPLETED            = BASE + 134;
    /* Is IBSS mode supported by the driver? */
    public static final int CMD_GET_IBSS_SUPPORTED        = BASE + 135;


    /* change the batch scan settings.
     * arg1 = responsible UID
@@ -1483,6 +1487,13 @@ public class WifiStateMachine extends StateMachine {
        mWifiP2pChannel.sendMessage(WifiP2pService.SET_COUNTRY_CODE, countryCode);
    }

    public int syncIsIbssSupported(AsyncChannel channel) {
        Message resultMsg = channel.sendMessageSynchronously(CMD_GET_IBSS_SUPPORTED);
        int result = resultMsg.arg1;
        resultMsg.recycle();
        return result;
    }

    /**
     * Set the operational frequency band
     * @param band
@@ -2425,6 +2436,7 @@ public class WifiStateMachine extends StateMachine {
                case CMD_ADD_OR_UPDATE_NETWORK:
                case CMD_REMOVE_NETWORK:
                case CMD_SAVE_CONFIG:
                case CMD_GET_IBSS_SUPPORTED:
                    replyToMessage(message, message.what, FAILURE);
                    break;
                case CMD_GET_CONFIGURED_NETWORKS:
@@ -2714,6 +2726,8 @@ public class WifiStateMachine extends StateMachine {
                    mWifiConfigStore.loadAndEnableAllNetworks();
                    initializeWpsDetails();

                    mIbssSupported = mWifiNative.getModeCapability("IBSS");

                    sendSupplicantConnectionChangedBroadcast(true);
                    transitionTo(mDriverStartedState);
                    break;
@@ -2742,6 +2756,7 @@ public class WifiStateMachine extends StateMachine {
                case CMD_SET_FREQUENCY_BAND:
                case CMD_START_PACKET_FILTERING:
                case CMD_STOP_PACKET_FILTERING:
                case CMD_GET_IBSS_SUPPORTED:
                    deferMessage(message);
                    break;
                default:
@@ -2805,6 +2820,9 @@ public class WifiStateMachine extends StateMachine {
                case CMD_SET_OPERATIONAL_MODE:
                    mOperationalMode = message.arg1;
                    break;
                case CMD_GET_IBSS_SUPPORTED:
                    deferMessage(message);
                    break;
                default:
                    return NOT_HANDLED;
            }
@@ -3159,6 +3177,9 @@ public class WifiStateMachine extends StateMachine {
                        mWifiNative.startTdls(remoteAddress, enable);
                    }
                    break;
                case CMD_GET_IBSS_SUPPORTED:
                    replyToMessage(message, message.what, mIbssSupported ? 1 : 0);
                    break;
                default:
                    return NOT_HANDLED;
            }