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

Commit f1d4a074 authored by Bruno Randolf's avatar Bruno Randolf Committed by Gerrit Code Review
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 d464e60a
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -928,6 +928,21 @@ public 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
@@ -870,6 +870,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
@@ -799,5 +799,17 @@ public class WifiNative {
        return doBooleanCommand("P2P_SERV_DISC_CANCEL_REQ " + id);
    }

    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
@@ -113,6 +113,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;
@@ -369,6 +370,9 @@ public class WifiStateMachine extends StateMachine {
    public static final int CMD_DISABLE_P2P_REQ           = BASE + 132;
    public static final int CMD_DISABLE_P2P_RSP           = BASE + 133;

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

    private static final int CONNECT_MODE   = 1;
    private static final int SCAN_ONLY_MODE = 2;

@@ -1090,6 +1094,13 @@ public class WifiStateMachine extends StateMachine {
        return mCountryCode;
    }

    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
@@ -1936,6 +1947,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:
@@ -2406,6 +2418,8 @@ public class WifiStateMachine extends StateMachine {
                    mWifiConfigStore.initialize();
                    initializeWpsDetails();

                    mIbssSupported = mWifiNative.getModeCapability("IBSS");

                    sendSupplicantConnectionChangedBroadcast(true);
                    transitionTo(mDriverStartedState);
                    break;
@@ -2437,6 +2451,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:
@@ -2583,6 +2598,9 @@ public class WifiStateMachine extends StateMachine {
                                WifiManager.ERROR);
                    }
                    break;
                case CMD_GET_IBSS_SUPPORTED:
                    deferMessage(message);
                    break;
                default:
                    return NOT_HANDLED;
            }
@@ -2927,6 +2945,9 @@ public class WifiStateMachine extends StateMachine {
                        setSuspendOptimizationsNative(SUSPEND_DUE_TO_HIGH_PERF, true);
                    }
                    break;
                case CMD_GET_IBSS_SUPPORTED:
                    replyToMessage(message, message.what, mIbssSupported ? 1 : 0);
                    break;
                default:
                    return NOT_HANDLED;
            }