1package com.android.server.wifi.anqp;
2
3import java.net.ProtocolException;
4import java.nio.ByteBuffer;
5import java.util.ArrayList;
6import java.util.Collections;
7import java.util.EnumMap;
8import java.util.List;
9import java.util.Map;
10
11/**
12 * The Venue Name ANQP Element, IEEE802.11-2012 section 8.4.4.4
13 */
14public class VenueNameElement extends ANQPElement {
15    private final VenueGroup mGroup;
16    private final VenueType mType;
17    private final List<I18Name> mNames;
18
19    private static final Map<VenueGroup, Integer> sGroupBases =
20            new EnumMap<VenueGroup, Integer>(VenueGroup.class);
21
22    public VenueNameElement(Constants.ANQPElementType infoID, ByteBuffer payload)
23            throws ProtocolException {
24        super(infoID);
25
26        if (payload.remaining() < 2)
27            throw new ProtocolException("Runt Venue Name");
28
29        int group = payload.get() & Constants.BYTE_MASK;
30        int type = payload.get() & Constants.BYTE_MASK;
31
32        if (group >= VenueGroup.values().length) {
33            mGroup = VenueGroup.Reserved;
34            mType = VenueType.Reserved;
35        } else {
36            mGroup = VenueGroup.values()[group];
37            type += sGroupBases.get(mGroup);
38            if (type >= VenueType.values().length) {
39                mType = VenueType.Reserved;
40            } else {
41                mType = VenueType.values()[type];
42            }
43        }
44
45        mNames = new ArrayList<I18Name>();
46        while (payload.hasRemaining()) {
47            mNames.add(new I18Name(payload));
48        }
49    }
50
51    public VenueGroup getGroup() {
52        return mGroup;
53    }
54
55    public VenueType getType() {
56        return mType;
57    }
58
59    public List<I18Name> getNames() {
60        return Collections.unmodifiableList(mNames);
61    }
62
63    @Override
64    public String toString() {
65        return "VenueName{" +
66                "m_group=" + mGroup +
67                ", m_type=" + mType +
68                ", m_names=" + mNames +
69                '}';
70    }
71
72    public enum VenueGroup {
73        Unspecified,
74        Assembly,
75        Business,
76        Educational,
77        FactoryIndustrial,
78        Institutional,
79        Mercantile,
80        Residential,
81        Storage,
82        UtilityMiscellaneous,
83        Vehicular,
84        Outdoor,
85        Reserved
86    }
87
88    public enum VenueType {
89        Unspecified,
90
91        UnspecifiedAssembly,
92        Arena,
93        Stadium,
94        PassengerTerminal,
95        Amphitheater,
96        AmusementPark,
97        PlaceOfWorship,
98        ConventionCenter,
99        Library,
100        Museum,
101        Restaurant,
102        Theater,
103        Bar,
104        CoffeeShop,
105        ZooOrAquarium,
106        EmergencyCoordinationCenter,
107
108        UnspecifiedBusiness,
109        DoctorDentistoffice,
110        Bank,
111        FireStation,
112        PoliceStation,
113        PostOffice,
114        ProfessionalOffice,
115        ResearchDevelopmentFacility,
116        AttorneyOffice,
117
118        UnspecifiedEducational,
119        SchoolPrimary,
120        SchoolSecondary,
121        UniversityCollege,
122
123        UnspecifiedFactoryIndustrial,
124        Factory,
125
126        UnspecifiedInstitutional,
127        Hospital,
128        LongTermCareFacility,
129        AlcoholAndDrugRehabilitationCenter,
130        GroupHome,
131        PrisonJail,
132
133        UnspecifiedMercantile,
134        RetailStore,
135        GroceryMarket,
136        AutomotiveServiceStation,
137        ShoppingMall,
138        GasStation,
139
140        UnspecifiedResidential,
141        PrivateResidence,
142        HotelMotel,
143        Dormitory,
144        BoardingHouse,
145
146        UnspecifiedStorage,
147
148        UnspecifiedUtilityMiscellaneous,
149
150        UnspecifiedVehicular,
151        AutomobileOrTruck,
152        Airplane,
153        Bus,
154        Ferry,
155        ShipOrBoat,
156        Train,
157        MotorBike,
158
159        UnspecifiedOutdoor,
160        MuniMeshNetwork,
161        CityPark,
162        RestArea,
163        TrafficControl,
164        BusStop,
165        Kiosk,
166
167        Reserved
168    }
169
170    private static final VenueType[] PerGroup =
171            {
172                    VenueType.Unspecified,
173                    VenueType.UnspecifiedAssembly,
174                    VenueType.UnspecifiedBusiness,
175                    VenueType.UnspecifiedEducational,
176                    VenueType.UnspecifiedFactoryIndustrial,
177                    VenueType.UnspecifiedInstitutional,
178                    VenueType.UnspecifiedMercantile,
179                    VenueType.UnspecifiedResidential,
180                    VenueType.UnspecifiedStorage,
181                    VenueType.UnspecifiedUtilityMiscellaneous,
182                    VenueType.UnspecifiedVehicular,
183                    VenueType.UnspecifiedOutdoor
184            };
185
186    static {
187        int index = 0;
188        for (VenueType venue : PerGroup) {
189            sGroupBases.put(VenueGroup.values()[index++], venue.ordinal());
190        }
191    }
192}
193