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

Commit b6deeed3 authored by Irfan Sheriff's avatar Irfan Sheriff
Browse files

Handle ascii encoded SSID

Supplicant now passes as an ascii encoded string that allows it to
pass any sequence of bytes for a SSID. see src/utils/common.c in supplicant
for details of the implementation.

We create a SSID structure WifiSsid in framework to store the ssid and handle
the conversion appropriately when required for printing and for an application.

At this point, we still do not handle non-printable octets from an application perspective
for connectivity

Bug: 7110903
Change-Id: I520e5ee23baed4867b8b408bbb3eda5c9e92b6bf
parent 799553e0
Loading
Loading
Loading
Loading
+23 −12
Original line number Diff line number Diff line
@@ -28,6 +28,10 @@ import android.os.Parcel;
public class ScanResult implements Parcelable {
    /** The network name. */
    public String SSID;

    /** Ascii encoded SSID. This will replace SSID when we deprecate it. @hide */
    public WifiSsid wifiSsid;

    /** The address of the access point. */
    public String BSSID;
    /**
@@ -52,15 +56,11 @@ public class ScanResult implements Parcelable {
     */
     public long timestamp;

    /**
     * We'd like to obtain the following attributes,
     * but they are not reported via the socket
     * interface, even though they are known
     * internally by wpa_supplicant.
     * {@hide}
     */
    public ScanResult(String SSID, String BSSID, String caps, int level, int frequency, long tsf) {
        this.SSID = SSID;
    /** {@hide} */
    public ScanResult(WifiSsid wifiSsid, String BSSID, String caps, int level, int frequency,
            long tsf) {
        this.wifiSsid = wifiSsid;
        this.SSID = (wifiSsid != null) ? wifiSsid.toString() : WifiSsid.NONE;
        this.BSSID = BSSID;
        this.capabilities = caps;
        this.level = level;
@@ -68,9 +68,11 @@ public class ScanResult implements Parcelable {
        this.timestamp = tsf;
    }


    /** copy constructor {@hide} */
    public ScanResult(ScanResult source) {
        if (source != null) {
            wifiSsid = source.wifiSsid;
            SSID = source.SSID;
            BSSID = source.BSSID;
            capabilities = source.capabilities;
@@ -86,7 +88,7 @@ public class ScanResult implements Parcelable {
        String none = "<none>";

        sb.append("SSID: ").
            append(SSID == null ? none : SSID).
            append(wifiSsid == null ? WifiSsid.NONE : wifiSsid).
            append(", BSSID: ").
            append(BSSID == null ? none : BSSID).
            append(", capabilities: ").
@@ -108,7 +110,12 @@ public class ScanResult implements Parcelable {

    /** Implement the Parcelable interface {@hide} */
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(SSID);
        if (wifiSsid != null) {
            dest.writeInt(1);
            wifiSsid.writeToParcel(dest, flags);
        } else {
            dest.writeInt(0);
        }
        dest.writeString(BSSID);
        dest.writeString(capabilities);
        dest.writeInt(level);
@@ -120,8 +127,12 @@ public class ScanResult implements Parcelable {
    public static final Creator<ScanResult> CREATOR =
        new Creator<ScanResult>() {
            public ScanResult createFromParcel(Parcel in) {
                WifiSsid wifiSsid = null;
                if (in.readInt() == 1) {
                    wifiSsid = WifiSsid.CREATOR.createFromParcel(in);
                }
                return new ScanResult(
                    in.readString(),
                    wifiSsid,
                    in.readString(),
                    in.readString(),
                    in.readInt(),
+4 −3
Original line number Diff line number Diff line
@@ -23,15 +23,16 @@
 * @hide
 */
public class StateChangeResult {
    StateChangeResult(int networkId, String SSID, String BSSID, SupplicantState state) {
    StateChangeResult(int networkId, WifiSsid wifiSsid, String BSSID,
            SupplicantState state) {
        this.state = state;
        this.SSID = SSID;
        this.wifiSsid= wifiSsid;
        this.BSSID = BSSID;
        this.networkId = networkId;
    }

    int networkId;
    String SSID;
    WifiSsid wifiSsid;
    String BSSID;
    SupplicantState state;
}
+7 −1
Original line number Diff line number Diff line
@@ -1318,7 +1318,13 @@ class WifiConfigStore {

        value = mWifiNative.getNetworkVariable(netId, WifiConfiguration.ssidVarName);
        if (!TextUtils.isEmpty(value)) {
            if (value.charAt(0) != '"') {
                config.SSID = "\"" + WifiSsid.createFromHex(value).toString() + "\"";
                //TODO: convert a hex string that is not UTF-8 decodable to a P-formatted
                //supplicant string
            } else {
                config.SSID = value;
            }
        } else {
            config.SSID = null;
        }
+21 −0
Original line number Diff line number Diff line
@@ -524,6 +524,27 @@ public class WifiConfiguration implements Parcelable {
    }
    */

    /** {@hide} */
    public String getPrintableSsid() {
        if (SSID == null) return "";
        final int length = SSID.length();
        if (length > 2 && (SSID.charAt(0) == '"') && SSID.charAt(length - 1) == '"') {
            return SSID.substring(1, length - 1);
        }

        /** The ascii-encoded string format is P"<ascii-encoded-string>"
         * The decoding is implemented in the supplicant for a newly configured
         * network.
         */
        if (length > 3 && (SSID.charAt(0) == 'P') && (SSID.charAt(1) == '"') &&
                (SSID.charAt(length-1) == '"')) {
            WifiSsid wifiSsid = WifiSsid.createFromAsciiEncoded(
                    SSID.substring(2, length - 1));
            return wifiSsid.toString();
        }
        return SSID;
    }

    private static BitSet readBitSet(Parcel src) {
        int cardinality = src.readInt();

+33 −11
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.os.Parcelable;
import android.os.Parcel;
import android.net.NetworkInfo.DetailedState;
import android.net.NetworkUtils;
import android.text.TextUtils;

import java.net.InetAddress;
import java.net.Inet6Address;
@@ -31,6 +32,7 @@ import java.util.EnumMap;
 * is in the process of being set up.
 */
public class WifiInfo implements Parcelable {
    private static final String TAG = "WifiInfo";
    /**
     * This is the map described in the Javadoc comment above. The positions
     * of the elements of the array must correspond to the ordinal values
@@ -57,7 +59,7 @@ public class WifiInfo implements Parcelable {

    private SupplicantState mSupplicantState;
    private String mBSSID;
    private String mSSID;
    private WifiSsid mWifiSsid;
    private int mNetworkId;
    private boolean mHiddenSSID;
    /** Received Signal Strength Indicator */
@@ -77,7 +79,7 @@ public class WifiInfo implements Parcelable {
    private boolean mMeteredHint;

    WifiInfo() {
        mSSID = null;
        mWifiSsid = null;
        mBSSID = null;
        mNetworkId = -1;
        mSupplicantState = SupplicantState.UNINITIALIZED;
@@ -94,7 +96,7 @@ public class WifiInfo implements Parcelable {
        if (source != null) {
            mSupplicantState = source.mSupplicantState;
            mBSSID = source.mBSSID;
            mSSID = source.mSSID;
            mWifiSsid = source.mWifiSsid;
            mNetworkId = source.mNetworkId;
            mHiddenSSID = source.mHiddenSSID;
            mRssi = source.mRssi;
@@ -105,21 +107,34 @@ public class WifiInfo implements Parcelable {
        }
    }

    void setSSID(String SSID) {
        mSSID = SSID;
    void setSSID(WifiSsid wifiSsid) {
        mWifiSsid = wifiSsid;
        // network is considered not hidden by default
        mHiddenSSID = false;
    }

    /**
     * Returns the service set identifier (SSID) of the current 802.11 network.
     * If the SSID is an ASCII string, it will be returned surrounded by double
     * If the SSID can be decoded as UTF-8, it will be returned surrounded by double
     * quotation marks. Otherwise, it is returned as a string of hex digits. The
     * SSID may be {@code null} if there is no network currently connected.
     * @return the SSID
     */
    public String getSSID() {
        return mSSID;
        if (mWifiSsid != null) {
            String unicode = mWifiSsid.toString();
            if (!TextUtils.isEmpty(unicode)) {
                return "\"" + unicode + "\"";
            } else {
                return mWifiSsid.getHexString();
            }
        }
        return WifiSsid.NONE;
    }

    /** @hide */
    public WifiSsid getWifiSsid() {
        return mWifiSsid;
    }

    void setBSSID(String BSSID) {
@@ -279,7 +294,7 @@ public class WifiInfo implements Parcelable {
        StringBuffer sb = new StringBuffer();
        String none = "<none>";

        sb.append("SSID: ").append(mSSID == null ? none : mSSID).
        sb.append("SSID: ").append(mWifiSsid == null ? WifiSsid.NONE : mWifiSsid).
            append(", BSSID: ").append(mBSSID == null ? none : mBSSID).
            append(", MAC: ").append(mMacAddress == null ? none : mMacAddress).
            append(", Supplicant state: ").
@@ -308,7 +323,12 @@ public class WifiInfo implements Parcelable {
        } else {
            dest.writeByte((byte)0);
        }
        dest.writeString(getSSID());
        if (mWifiSsid != null) {
            dest.writeInt(1);
            mWifiSsid.writeToParcel(dest, flags);
        } else {
            dest.writeInt(0);
        }
        dest.writeString(mBSSID);
        dest.writeString(mMacAddress);
        dest.writeInt(mMeteredHint ? 1 : 0);
@@ -328,7 +348,9 @@ public class WifiInfo implements Parcelable {
                        info.setInetAddress(InetAddress.getByAddress(in.createByteArray()));
                    } catch (UnknownHostException e) {}
                }
                info.setSSID(in.readString());
                if (in.readInt() == 1) {
                    info.mWifiSsid = WifiSsid.CREATOR.createFromParcel(in);
                }
                info.mBSSID = in.readString();
                info.mMacAddress = in.readString();
                info.mMeteredHint = in.readInt() != 0;
Loading