VenueNameElement.java revision 450a34955b855f0d813400013a9dbeead9d84c7b
1/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.wifi.anqp;
18
19import java.net.ProtocolException;
20import java.nio.ByteBuffer;
21import java.util.ArrayList;
22import java.util.Collections;
23import java.util.List;
24
25/**
26 * The Venue Name ANQP Element, IEEE802.11-2012 section 8.4.4.4.
27 *
28 * Format:
29 *
30 * | Info ID | Length | Venue Info | Venue Name Duple #1 (optional) | ...
31 *      2        2          2                  variable
32 * | Venue Name Duple #N (optional) |
33 *             variable
34 *
35 * Refer to {@link com.android.server.wifi.anqp.I18Name} for the format of the Venue Name Duple
36 * fields.
37 *
38 * Note: The payload parsed by this class already has 'Info ID' and 'Length' stripped off.
39 */
40public class VenueNameElement extends ANQPElement {
41    private final List<I18Name> mNames;
42
43    public VenueNameElement(Constants.ANQPElementType infoID, ByteBuffer payload)
44            throws ProtocolException {
45        super(infoID);
46
47        if (payload.remaining() < 2) {
48            throw new ProtocolException("Venue Name Element cannot contain less than 2 bytes");
49        }
50
51        // Skip the Venue Info field, which we don't use.
52        for (int i = 0; i < Constants.VENUE_INFO_LENGTH; ++i) {
53            payload.get();
54        }
55
56        mNames = new ArrayList<I18Name>();
57        while (payload.hasRemaining()) {
58            mNames.add(new I18Name(payload));
59        }
60    }
61
62    public List<I18Name> getNames() {
63        return Collections.unmodifiableList(mNames);
64    }
65
66    @Override
67    public String toString() {
68        return "VenueName{ mNames=" + mNames + "}";
69    }
70}
71