summaryrefslogtreecommitdiffstats
path: root/service/java/com/android/server/wifi/anqp/VenueNameElement.java
blob: f0b27dd330caef0bbb6800e2fb393857eca90fb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package com.android.server.wifi.anqp;

import java.net.ProtocolException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;

/**
 * The Venue Name ANQP Element, IEEE802.11-2012 section 8.4.4.4
 */
public class VenueNameElement extends ANQPElement {
    private final VenueGroup mGroup;
    private final VenueType mType;
    private final List<I18Name> mNames;

    private static final Map<VenueGroup, Integer> sGroupBases =
            new EnumMap<VenueGroup, Integer>(VenueGroup.class);

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

        if (payload.remaining() < 2)
            throw new ProtocolException("Runt Venue Name");

        int group = payload.get() & Constants.BYTE_MASK;
        int type = payload.get() & Constants.BYTE_MASK;

        if (group >= VenueGroup.values().length) {
            mGroup = VenueGroup.Reserved;
            mType = VenueType.Reserved;
        } else {
            mGroup = VenueGroup.values()[group];
            type += sGroupBases.get(mGroup);
            if (type >= VenueType.values().length) {
                mType = VenueType.Reserved;
            } else {
                mType = VenueType.values()[type];
            }
        }

        mNames = new ArrayList<I18Name>();
        while (payload.hasRemaining()) {
            mNames.add(new I18Name(payload));
        }
    }

    public VenueGroup getGroup() {
        return mGroup;
    }

    public VenueType getType() {
        return mType;
    }

    public List<I18Name> getNames() {
        return Collections.unmodifiableList(mNames);
    }

    @Override
    public String toString() {
        return "VenueName{" +
                "m_group=" + mGroup +
                ", m_type=" + mType +
                ", m_names=" + mNames +
                '}';
    }

    public enum VenueGroup {
        Unspecified,
        Assembly,
        Business,
        Educational,
        FactoryIndustrial,
        Institutional,
        Mercantile,
        Residential,
        Storage,
        UtilityMiscellaneous,
        Vehicular,
        Outdoor,
        Reserved
    }

    public enum VenueType {
        Unspecified,

        UnspecifiedAssembly,
        Arena,
        Stadium,
        PassengerTerminal,
        Amphitheater,
        AmusementPark,
        PlaceOfWorship,
        ConventionCenter,
        Library,
        Museum,
        Restaurant,
        Theater,
        Bar,
        CoffeeShop,
        ZooOrAquarium,
        EmergencyCoordinationCenter,

        UnspecifiedBusiness,
        DoctorDentistoffice,
        Bank,
        FireStation,
        PoliceStation,
        PostOffice,
        ProfessionalOffice,
        ResearchDevelopmentFacility,
        AttorneyOffice,

        UnspecifiedEducational,
        SchoolPrimary,
        SchoolSecondary,
        UniversityCollege,

        UnspecifiedFactoryIndustrial,
        Factory,

        UnspecifiedInstitutional,
        Hospital,
        LongTermCareFacility,
        AlcoholAndDrugRehabilitationCenter,
        GroupHome,
        PrisonJail,

        UnspecifiedMercantile,
        RetailStore,
        GroceryMarket,
        AutomotiveServiceStation,
        ShoppingMall,
        GasStation,

        UnspecifiedResidential,
        PrivateResidence,
        HotelMotel,
        Dormitory,
        BoardingHouse,

        UnspecifiedStorage,

        UnspecifiedUtilityMiscellaneous,

        UnspecifiedVehicular,
        AutomobileOrTruck,
        Airplane,
        Bus,
        Ferry,
        ShipOrBoat,
        Train,
        MotorBike,

        UnspecifiedOutdoor,
        MuniMeshNetwork,
        CityPark,
        RestArea,
        TrafficControl,
        BusStop,
        Kiosk,

        Reserved
    }

    private static final VenueType[] PerGroup =
            {
                    VenueType.Unspecified,
                    VenueType.UnspecifiedAssembly,
                    VenueType.UnspecifiedBusiness,
                    VenueType.UnspecifiedEducational,
                    VenueType.UnspecifiedFactoryIndustrial,
                    VenueType.UnspecifiedInstitutional,
                    VenueType.UnspecifiedMercantile,
                    VenueType.UnspecifiedResidential,
                    VenueType.UnspecifiedStorage,
                    VenueType.UnspecifiedUtilityMiscellaneous,
                    VenueType.UnspecifiedVehicular,
                    VenueType.UnspecifiedOutdoor
            };

    static {
        int index = 0;
        for (VenueType venue : PerGroup) {
            sGroupBases.put(VenueGroup.values()[index++], venue.ordinal());
        }
    }
}