Home | History | Annotate | Download | only in anqp
      1 package com.android.server.wifi.hotspot2.anqp;
      2 
      3 import java.net.ProtocolException;
      4 import java.nio.ByteBuffer;
      5 import java.nio.ByteOrder;
      6 import java.nio.charset.Charset;
      7 import java.util.Collection;
      8 import java.util.EnumMap;
      9 import java.util.HashMap;
     10 import java.util.List;
     11 import java.util.Map;
     12 
     13 /**
     14  * ANQP related constants (802.11-2012)
     15  */
     16 public class Constants {
     17 
     18     public static final int NIBBLE_MASK = 0x0f;
     19     public static final int BYTE_MASK = 0xff;
     20     public static final int SHORT_MASK = 0xffff;
     21     public static final long INT_MASK = 0xffffffffL;
     22     public static final int BYTES_IN_SHORT = 2;
     23     public static final int BYTES_IN_INT = 4;
     24     public static final int BYTES_IN_EUI48 = 6;
     25     public static final long MILLIS_IN_A_SEC = 1000L;
     26 
     27     public static final int HS20_PREFIX = 0x119a6f50;   // Note that this is represented as a LE int
     28     public static final int HS20_FRAME_PREFIX = 0x109a6f50;
     29     public static final int UTF8_INDICATOR = 1;
     30 
     31     public static final int LANG_CODE_LENGTH = 3;
     32     // From IEEE802.11-2012 section 8.4.1.34.
     33     public static final int VENUE_INFO_LENGTH = 2;
     34 
     35     public static final int ANQP_QUERY_LIST = 256;
     36     public static final int ANQP_VENUE_NAME = 258;
     37     public static final int ANQP_ROAMING_CONSORTIUM = 261;
     38     public static final int ANQP_IP_ADDR_AVAILABILITY = 262;
     39     public static final int ANQP_NAI_REALM = 263;
     40     public static final int ANQP_3GPP_NETWORK = 264;
     41     public static final int ANQP_DOM_NAME = 268;
     42     public static final int ANQP_VENDOR_SPEC = 56797;
     43 
     44     public static final int HS_QUERY_LIST = 1;
     45     public static final int HS_FRIENDLY_NAME = 3;
     46     public static final int HS_WAN_METRICS = 4;
     47     public static final int HS_CONN_CAPABILITY = 5;
     48     public static final int HS_NAI_HOME_REALM_QUERY = 6;
     49     public static final int HS_OSU_PROVIDERS = 8;
     50     public static final int HS_ICON_REQUEST = 10;
     51     public static final int HS_ICON_FILE = 11;
     52 
     53     public enum ANQPElementType {
     54         ANQPQueryList,
     55         ANQPVenueName,
     56         ANQPRoamingConsortium,
     57         ANQPIPAddrAvailability,
     58         ANQPNAIRealm,
     59         ANQP3GPPNetwork,
     60         ANQPDomName,
     61         ANQPVendorSpec,
     62         HSQueryList,
     63         HSFriendlyName,
     64         HSWANMetrics,
     65         HSConnCapability,
     66         HSNAIHomeRealmQuery,
     67         HSOSUProviders,
     68         HSIconRequest,
     69         HSIconFile
     70     }
     71 
     72     private static final Map<Integer, ANQPElementType> sAnqpMap = new HashMap<>();
     73     private static final Map<Integer, ANQPElementType> sHs20Map = new HashMap<>();
     74     private static final Map<ANQPElementType, Integer> sRevAnqpmap =
     75             new EnumMap<>(ANQPElementType.class);
     76     private static final Map<ANQPElementType, Integer> sRevHs20map =
     77             new EnumMap<>(ANQPElementType.class);
     78 
     79     static {
     80         sAnqpMap.put(ANQP_QUERY_LIST, ANQPElementType.ANQPQueryList);
     81         sAnqpMap.put(ANQP_VENUE_NAME, ANQPElementType.ANQPVenueName);
     82         sAnqpMap.put(ANQP_ROAMING_CONSORTIUM, ANQPElementType.ANQPRoamingConsortium);
     83         sAnqpMap.put(ANQP_IP_ADDR_AVAILABILITY, ANQPElementType.ANQPIPAddrAvailability);
     84         sAnqpMap.put(ANQP_NAI_REALM, ANQPElementType.ANQPNAIRealm);
     85         sAnqpMap.put(ANQP_3GPP_NETWORK, ANQPElementType.ANQP3GPPNetwork);
     86         sAnqpMap.put(ANQP_DOM_NAME, ANQPElementType.ANQPDomName);
     87         sAnqpMap.put(ANQP_VENDOR_SPEC, ANQPElementType.ANQPVendorSpec);
     88 
     89         sHs20Map.put(HS_QUERY_LIST, ANQPElementType.HSQueryList);
     90         sHs20Map.put(HS_FRIENDLY_NAME, ANQPElementType.HSFriendlyName);
     91         sHs20Map.put(HS_WAN_METRICS, ANQPElementType.HSWANMetrics);
     92         sHs20Map.put(HS_CONN_CAPABILITY, ANQPElementType.HSConnCapability);
     93         sHs20Map.put(HS_NAI_HOME_REALM_QUERY, ANQPElementType.HSNAIHomeRealmQuery);
     94         sHs20Map.put(HS_OSU_PROVIDERS, ANQPElementType.HSOSUProviders);
     95         sHs20Map.put(HS_ICON_REQUEST, ANQPElementType.HSIconRequest);
     96         sHs20Map.put(HS_ICON_FILE, ANQPElementType.HSIconFile);
     97 
     98         for (Map.Entry<Integer, ANQPElementType> entry : sAnqpMap.entrySet()) {
     99             sRevAnqpmap.put(entry.getValue(), entry.getKey());
    100         }
    101         for (Map.Entry<Integer, ANQPElementType> entry : sHs20Map.entrySet()) {
    102             sRevHs20map.put(entry.getValue(), entry.getKey());
    103         }
    104     }
    105 
    106     public static ANQPElementType mapANQPElement(int id) {
    107         return sAnqpMap.get(id);
    108     }
    109 
    110     public static ANQPElementType mapHS20Element(int id) {
    111         return sHs20Map.get(id);
    112     }
    113 
    114     public static Integer getANQPElementID(ANQPElementType elementType) {
    115         return sRevAnqpmap.get(elementType);
    116     }
    117 
    118     public static Integer getHS20ElementID(ANQPElementType elementType) {
    119         return sRevHs20map.get(elementType);
    120     }
    121 
    122     public static boolean hasBaseANQPElements(Collection<ANQPElementType> elements) {
    123         if (elements == null) {
    124             return false;
    125         }
    126         for (ANQPElementType element : elements) {
    127             if (sRevAnqpmap.containsKey(element)) {
    128                 return true;
    129             }
    130         }
    131         return false;
    132     }
    133 
    134     public static boolean hasR2Elements(List<ANQPElementType> elements) {
    135         return elements.contains(ANQPElementType.HSOSUProviders);
    136     }
    137 }
    138