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

Commit 5d7768ff authored by Vinit Deshpande's avatar Vinit Deshpande
Browse files

Revert "Initial Passpoint code."

This reverts commit 2eba02a1.

Change-Id: I11da074b8d8990fc01faac3586fd3488f76af326
parent 2eba02a1
Loading
Loading
Loading
Loading
+0 −766

File changed.

Preview size limit exceeded, changes collapsed.

+0 −16
Original line number Diff line number Diff line
package android.net.wifi.anqp;

/**
 * Base class for an IEEE802.11u ANQP element.
 */
public abstract class ANQPElement {
    private final Constants.ANQPElementType mID;

    protected ANQPElement(Constants.ANQPElementType id) {
        mID = id;
    }

    public Constants.ANQPElementType getID() {
        return mID;
    }
}
+0 −213
Original line number Diff line number Diff line
package android.net.wifi.anqp;

import java.net.ProtocolException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;

import static android.net.wifi.anqp.Constants.*;

/**
 * Factory to build a collection of 802.11u ANQP elements from a byte buffer.
 */
public class ANQPFactory {

    public static ByteBuffer buildQueryRequest(Set<ANQPElementType> elements, ByteBuffer target) {
        List<ANQPElementType> list = new ArrayList<ANQPElementType>(elements);
        Collections.sort(list);

        ListIterator<ANQPElementType> elementIterator = list.listIterator();

        target.order(ByteOrder.LITTLE_ENDIAN);
        target.putShort((short) Constants.ANQP_QUERY_LIST);
        int lenPos = target.position();
        target.putShort((short) 0);

        while (elementIterator.hasNext()) {
            Integer id = Constants.getANQPElementID(elementIterator.next());
            if (id != null) {
                target.putShort(id.shortValue());
            } else {
                elementIterator.previous();
            }
        }
        target.putShort(lenPos, (short) (target.position() - lenPos - BYTES_IN_SHORT));

        // Start a new vendor specific element for HS2.0 elements:
        if (elementIterator.hasNext()) {
            target.putShort((short) ANQP_VENDOR_SPEC);
            int vsLenPos = target.position();
            target.putShort((short) 0);

            target.putInt(Constants.HS20_PREFIX);
            target.put((byte) Constants.HS_QUERY_LIST);
            target.put((byte) 0);

            while (elementIterator.hasNext()) {
                ANQPElementType elementType = elementIterator.next();
                Integer id = Constants.getHS20ElementID(elementType);
                if (id == null) {
                    throw new RuntimeException("Unmapped ANQPElementType: " + elementType);
                } else {
                    target.put(id.byteValue());
                }
            }
            target.putShort(vsLenPos, (short) (target.position() - vsLenPos - BYTES_IN_SHORT));
        }

        target.flip();
        return target;
    }

    public static ByteBuffer buildHomeRealmRequest(List<String> realmNames, ByteBuffer target) {
        target.order(ByteOrder.LITTLE_ENDIAN);
        target.putShort((short) ANQP_VENDOR_SPEC);
        int lenPos = target.position();
        target.putShort((short) 0);

        target.putInt(Constants.HS20_PREFIX);
        target.put((byte) Constants.HS_NAI_HOME_REALM_QUERY);
        target.put((byte) 0);

        target.put((byte) realmNames.size());
        for (String realmName : realmNames) {
            target.put((byte) UTF8_INDICATOR);
            byte[] octets = realmName.getBytes(StandardCharsets.UTF_8);
            target.put((byte) octets.length);
            target.put(octets);
        }
        target.putShort(lenPos, (short) (target.position() - lenPos - BYTES_IN_SHORT));

        target.flip();
        return target;
    }

    public static ByteBuffer buildIconRequest(String fileName, ByteBuffer target) {
        target.order(ByteOrder.LITTLE_ENDIAN);
        target.putShort((short) ANQP_VENDOR_SPEC);
        int lenPos = target.position();
        target.putShort((short) 0);

        target.putInt(Constants.HS20_PREFIX);
        target.put((byte) Constants.HS_ICON_REQUEST);
        target.put((byte) 0);

        target.put(fileName.getBytes(StandardCharsets.UTF_8));
        target.putShort(lenPos, (short) (target.position() - lenPos - BYTES_IN_SHORT));

        target.flip();
        return target;
    }

    public static List<ANQPElement> parsePayload(ByteBuffer payload) throws ProtocolException {
        payload.order(ByteOrder.LITTLE_ENDIAN);
        List<ANQPElement> elements = new ArrayList<ANQPElement>();
        while (payload.hasRemaining()) {
            elements.add(buildElement(payload));
        }
        return elements;
    }

    private static ANQPElement buildElement(ByteBuffer payload) throws ProtocolException {
        if (payload.remaining() < 4)
            throw new ProtocolException("Runt payload: " + payload.remaining());

        int infoIDNumber = payload.getShort() & SHORT_MASK;
        ANQPElementType infoID = Constants.mapANQPElement(infoIDNumber);
        if (infoID == null) {
            throw new ProtocolException("Bad info ID: " + infoIDNumber);
        }
        int length = payload.getShort() & SHORT_MASK;

        if (payload.remaining() < length) {
            throw new ProtocolException("Truncated payload");
        }

        ByteBuffer elementPayload = payload.duplicate();
        payload.position(payload.position() + length);
        elementPayload.limit(elementPayload.position() + length);

        switch (infoID) {
            case ANQPCapabilityList:
                return new CapabilityListElement(infoID, elementPayload);
            case ANQPVenueName:
                return new VenueNameElement(infoID, elementPayload);
            case ANQPEmergencyNumber:
                return new EmergencyNumberElement(infoID, elementPayload);
            case ANQPNwkAuthType:
                return new NetworkAuthenticationTypeElement(infoID, elementPayload);
            case ANQPRoamingConsortium:
                return new RoamingConsortiumElement(infoID, elementPayload);
            case ANQPIPAddrAvailability:
                return new IPAddressTypeAvailabilityElement(infoID, elementPayload);
            case ANQPNAIRealm:
                return new NAIRealmElement(infoID, elementPayload);
            case ANQP3GPPNetwork:
                return new ThreeGPPNetworkElement(infoID, elementPayload);
            case ANQPGeoLoc:
                return new GEOLocationElement(infoID, elementPayload);
            case ANQPCivicLoc:
                return new CivicLocationElement(infoID, elementPayload);
            case ANQPLocURI:
                return new GenericStringElement(infoID, elementPayload);
            case ANQPDomName:
                return new DomainNameElement(infoID, elementPayload);
            case ANQPEmergencyAlert:
                return new GenericStringElement(infoID, elementPayload);
            case ANQPTDLSCap:
                return new GenericBlobElement(infoID, elementPayload);
            case ANQPEmergencyNAI:
                return new GenericStringElement(infoID, elementPayload);
            case ANQPNeighborReport:
                return new GenericBlobElement(infoID, elementPayload);
            case ANQPVendorSpec:
                if (elementPayload.remaining() > 5) {
                    int oi = elementPayload.getInt();
                    if (oi != Constants.HS20_PREFIX) {
                        return null;
                    }
                    int subType = elementPayload.get() & BYTE_MASK;
                    elementPayload.get();
                    return buildHS20Element(subType, elementPayload);
                } else {
                    return new GenericBlobElement(infoID, elementPayload);
                }
            default:
                throw new ProtocolException("Unknown element ID: " + infoID);
        }
    }

    private static ANQPElement buildHS20Element(int subType, ByteBuffer payload)
            throws ProtocolException {

        ANQPElementType infoID = Constants.mapHS20Element(subType);

        if (infoID == null) {
            throw new ProtocolException("Bad HS20 info ID: " + subType);
        }

        switch (infoID) {
            case HSCapabilityList:
                return new HSCapabilityListElement(infoID, payload);
            case HSFriendlyName:
                return new HSFriendlyNameElement(infoID, payload);
            case HSWANMetrics:
                return new HSWanMetricsElement(infoID, payload);
            case HSConnCapability:
                return new HSConnectionCapabilityElement(infoID, payload);
            case HSOperatingclass:
                return new GenericBlobElement(infoID, payload);
            case HSOSUProviders:
                return new HSOsuProvidersElement(infoID, payload);
            case HSIconFile:
                return new HSIconFileElement(infoID, payload);
            default:
                throw new ProtocolException("Unknown HS20 sub type: " + subType);
        }
    }
}
+0 −44
Original line number Diff line number Diff line
package android.net.wifi.anqp;

import java.net.ProtocolException;
import java.nio.ByteBuffer;
import java.util.Arrays;

import static android.net.wifi.anqp.Constants.ANQPElementType;
import static android.net.wifi.anqp.Constants.BYTES_IN_SHORT;
import static android.net.wifi.anqp.Constants.SHORT_MASK;

/**
 * The ANQP Capability List element, 802.11-2012 section 8.4.4.3
 */
public class CapabilityListElement extends ANQPElement {
    private final ANQPElementType[] mCapabilities;

    public CapabilityListElement(ANQPElementType infoID, ByteBuffer payload)
            throws ProtocolException {
        super(infoID);
        if ((payload.remaining() & 1) == 1)
            throw new ProtocolException("Odd length");
        mCapabilities = new ANQPElementType[payload.remaining() / BYTES_IN_SHORT];

        int index = 0;
        while (payload.hasRemaining()) {
            int capID = payload.getShort() & SHORT_MASK;
            ANQPElementType capability = Constants.mapANQPElement(capID);
            if (capability == null)
                throw new ProtocolException("Unknown capability: " + capID);
            mCapabilities[index++] = capability;
        }
    }

    public ANQPElementType[] getCapabilities() {
        return mCapabilities;
    }

    @Override
    public String toString() {
        return "CapabilityListElement{" +
                "mCapabilities=" + Arrays.toString(mCapabilities) +
                '}';
    }
}
+0 −201
Original line number Diff line number Diff line
package android.net.wifi.anqp;

import java.net.ProtocolException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import static android.net.wifi.anqp.Constants.BYTE_MASK;

/**
 * The Civic Location ANQP Element, IEEE802.11-2012 section 8.4.4.13
 */
public class CivicLocationElement extends ANQPElement {
    public enum LocationType {DHCPServer, NwkElement, Client}

    private static final int GEOCONF_CIVIC4 = 99;
    private static final int RFC4776 = 0;       // Table 8-77, 1=vendor specific

    private final LocationType mLocationType;
    private final Locale mLocale;
    private final Map<CAType, String> mValues;

    public CivicLocationElement(Constants.ANQPElementType infoID, ByteBuffer payload)
            throws ProtocolException {
        super(infoID);

        if (payload.remaining() < 6) {
            throw new ProtocolException("Runt civic location:" + payload.remaining());
        }

        int locType = payload.get() & BYTE_MASK;
        if (locType != RFC4776) {
            throw new ProtocolException("Bad Civic location type: " + locType);
        }

        int locSubType = payload.get() & BYTE_MASK;
        if (locSubType != GEOCONF_CIVIC4) {
            throw new ProtocolException("Unexpected Civic location sub-type: " + locSubType +
                    " (cannot handle sub elements)");
        }

        int length = payload.get() & BYTE_MASK;
        if (length > payload.remaining()) {
            throw new ProtocolException("Invalid CA type length: " + length);
        }

        int what = payload.get() & BYTE_MASK;
        mLocationType = what < LocationType.values().length ? LocationType.values()[what] : null;

        mLocale = Locale.forLanguageTag(Constants.getString(payload, 2, StandardCharsets.US_ASCII));

        mValues = new HashMap<CAType, String>();
        while (payload.hasRemaining()) {
            int caTypeNumber = payload.get() & BYTE_MASK;
            CAType caType = s_caTypes.get(caTypeNumber);

            int caValLen = payload.get() & BYTE_MASK;
            if (caValLen > payload.remaining()) {
                throw new ProtocolException("Bad CA value length: " + caValLen);
            }
            byte[] caValOctets = new byte[caValLen];
            payload.get(caValOctets);

            if (caType != null) {
                mValues.put(caType, new String(caValOctets, StandardCharsets.UTF_8));
            }
        }
    }

    public LocationType getLocationType() {
        return mLocationType;
    }

    public Locale getLocale() {
        return mLocale;
    }

    public Map<CAType, String> getValues() {
        return Collections.unmodifiableMap(mValues);
    }

    @Override
    public String toString() {
        return "CivicLocationElement{" +
                "mLocationType=" + mLocationType +
                ", mLocale=" + mLocale +
                ", mValues=" + mValues +
                '}';
    }

    private static final Map<Integer, CAType> s_caTypes = new HashMap<Integer, CAType>();

    public static final int LANGUAGE = 0;
    public static final int STATE_PROVINCE = 1;
    public static final int COUNTY_DISTRICT = 2;
    public static final int CITY = 3;
    public static final int DIVISION_BOROUGH = 4;
    public static final int BLOCK = 5;
    public static final int STREET_GROUP = 6;
    public static final int STREET_DIRECTION = 16;
    public static final int LEADING_STREET_SUFFIX = 17;
    public static final int STREET_SUFFIX = 18;
    public static final int HOUSE_NUMBER = 19;
    public static final int HOUSE_NUMBER_SUFFIX = 20;
    public static final int LANDMARK = 21;
    public static final int ADDITIONAL_LOCATION = 22;
    public static final int NAME = 23;
    public static final int POSTAL_ZIP = 24;
    public static final int BUILDING = 25;
    public static final int UNIT = 26;
    public static final int FLOOR = 27;
    public static final int ROOM = 28;
    public static final int TYPE = 29;
    public static final int POSTAL_COMMUNITY = 30;
    public static final int PO_BOX = 31;
    public static final int ADDITIONAL_CODE = 32;
    public static final int SEAT_DESK = 33;
    public static final int PRIMARY_ROAD = 34;
    public static final int ROAD_SECTION = 35;
    public static final int BRANCH_ROAD = 36;
    public static final int SUB_BRANCH_ROAD = 37;
    public static final int STREET_NAME_PRE_MOD = 38;
    public static final int STREET_NAME_POST_MOD = 39;
    public static final int SCRIPT = 128;
    public static final int RESERVED = 255;

    public enum CAType {
        Language,
        StateProvince,
        CountyDistrict,
        City,
        DivisionBorough,
        Block,
        StreetGroup,
        StreetDirection,
        LeadingStreetSuffix,
        StreetSuffix,
        HouseNumber,
        HouseNumberSuffix,
        Landmark,
        AdditionalLocation,
        Name,
        PostalZIP,
        Building,
        Unit,
        Floor,
        Room,
        Type,
        PostalCommunity,
        POBox,
        AdditionalCode,
        SeatDesk,
        PrimaryRoad,
        RoadSection,
        BranchRoad,
        SubBranchRoad,
        StreetNamePreMod,
        StreetNamePostMod,
        Script,
        Reserved
    }

    static {
        s_caTypes.put(LANGUAGE, CAType.Language);
        s_caTypes.put(STATE_PROVINCE, CAType.StateProvince);
        s_caTypes.put(COUNTY_DISTRICT, CAType.CountyDistrict);
        s_caTypes.put(CITY, CAType.City);
        s_caTypes.put(DIVISION_BOROUGH, CAType.DivisionBorough);
        s_caTypes.put(BLOCK, CAType.Block);
        s_caTypes.put(STREET_GROUP, CAType.StreetGroup);
        s_caTypes.put(STREET_DIRECTION, CAType.StreetDirection);
        s_caTypes.put(LEADING_STREET_SUFFIX, CAType.LeadingStreetSuffix);
        s_caTypes.put(STREET_SUFFIX, CAType.StreetSuffix);
        s_caTypes.put(HOUSE_NUMBER, CAType.HouseNumber);
        s_caTypes.put(HOUSE_NUMBER_SUFFIX, CAType.HouseNumberSuffix);
        s_caTypes.put(LANDMARK, CAType.Landmark);
        s_caTypes.put(ADDITIONAL_LOCATION, CAType.AdditionalLocation);
        s_caTypes.put(NAME, CAType.Name);
        s_caTypes.put(POSTAL_ZIP, CAType.PostalZIP);
        s_caTypes.put(BUILDING, CAType.Building);
        s_caTypes.put(UNIT, CAType.Unit);
        s_caTypes.put(FLOOR, CAType.Floor);
        s_caTypes.put(ROOM, CAType.Room);
        s_caTypes.put(TYPE, CAType.Type);
        s_caTypes.put(POSTAL_COMMUNITY, CAType.PostalCommunity);
        s_caTypes.put(PO_BOX, CAType.POBox);
        s_caTypes.put(ADDITIONAL_CODE, CAType.AdditionalCode);
        s_caTypes.put(SEAT_DESK, CAType.SeatDesk);
        s_caTypes.put(PRIMARY_ROAD, CAType.PrimaryRoad);
        s_caTypes.put(ROAD_SECTION, CAType.RoadSection);
        s_caTypes.put(BRANCH_ROAD, CAType.BranchRoad);
        s_caTypes.put(SUB_BRANCH_ROAD, CAType.SubBranchRoad);
        s_caTypes.put(STREET_NAME_PRE_MOD, CAType.StreetNamePreMod);
        s_caTypes.put(STREET_NAME_POST_MOD, CAType.StreetNamePostMod);
        s_caTypes.put(SCRIPT, CAType.Script);
        s_caTypes.put(RESERVED, CAType.Reserved);
    }
}
Loading