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