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 Original line Diff line number Diff line
@@ -28,6 +28,10 @@ import android.os.Parcel;
public class ScanResult implements Parcelable {
public class ScanResult implements Parcelable {
    /** The network name. */
    /** The network name. */
    public String SSID;
    public String SSID;

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

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


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



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


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


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


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


        value = mWifiNative.getNetworkVariable(netId, WifiConfiguration.ssidVarName);
        value = mWifiNative.getNetworkVariable(netId, WifiConfiguration.ssidVarName);
        if (!TextUtils.isEmpty(value)) {
        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;
                config.SSID = value;
            }
        } else {
        } else {
            config.SSID = null;
            config.SSID = null;
        }
        }
+21 −0
Original line number Original line 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) {
    private static BitSet readBitSet(Parcel src) {
        int cardinality = src.readInt();
        int cardinality = src.readInt();


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


import java.net.InetAddress;
import java.net.InetAddress;
import java.net.Inet6Address;
import java.net.Inet6Address;
@@ -31,6 +32,7 @@ import java.util.EnumMap;
 * is in the process of being set up.
 * is in the process of being set up.
 */
 */
public class WifiInfo implements Parcelable {
public class WifiInfo implements Parcelable {
    private static final String TAG = "WifiInfo";
    /**
    /**
     * This is the map described in the Javadoc comment above. The positions
     * This is the map described in the Javadoc comment above. The positions
     * of the elements of the array must correspond to the ordinal values
     * 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 SupplicantState mSupplicantState;
    private String mBSSID;
    private String mBSSID;
    private String mSSID;
    private WifiSsid mWifiSsid;
    private int mNetworkId;
    private int mNetworkId;
    private boolean mHiddenSSID;
    private boolean mHiddenSSID;
    /** Received Signal Strength Indicator */
    /** Received Signal Strength Indicator */
@@ -77,7 +79,7 @@ public class WifiInfo implements Parcelable {
    private boolean mMeteredHint;
    private boolean mMeteredHint;


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


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


    /**
    /**
     * Returns the service set identifier (SSID) of the current 802.11 network.
     * 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
     * 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.
     * SSID may be {@code null} if there is no network currently connected.
     * @return the SSID
     * @return the SSID
     */
     */
    public String getSSID() {
    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) {
    void setBSSID(String BSSID) {
@@ -279,7 +294,7 @@ public class WifiInfo implements Parcelable {
        StringBuffer sb = new StringBuffer();
        StringBuffer sb = new StringBuffer();
        String none = "<none>";
        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(", BSSID: ").append(mBSSID == null ? none : mBSSID).
            append(", MAC: ").append(mMacAddress == null ? none : mMacAddress).
            append(", MAC: ").append(mMacAddress == null ? none : mMacAddress).
            append(", Supplicant state: ").
            append(", Supplicant state: ").
@@ -308,7 +323,12 @@ public class WifiInfo implements Parcelable {
        } else {
        } else {
            dest.writeByte((byte)0);
            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(mBSSID);
        dest.writeString(mMacAddress);
        dest.writeString(mMacAddress);
        dest.writeInt(mMeteredHint ? 1 : 0);
        dest.writeInt(mMeteredHint ? 1 : 0);
@@ -328,7 +348,9 @@ public class WifiInfo implements Parcelable {
                        info.setInetAddress(InetAddress.getByAddress(in.createByteArray()));
                        info.setInetAddress(InetAddress.getByAddress(in.createByteArray()));
                    } catch (UnknownHostException e) {}
                    } catch (UnknownHostException e) {}
                }
                }
                info.setSSID(in.readString());
                if (in.readInt() == 1) {
                    info.mWifiSsid = WifiSsid.CREATOR.createFromParcel(in);
                }
                info.mBSSID = in.readString();
                info.mBSSID = in.readString();
                info.mMacAddress = in.readString();
                info.mMacAddress = in.readString();
                info.mMeteredHint = in.readInt() != 0;
                info.mMeteredHint = in.readInt() != 0;
Loading