RoamingConsortiumElement.java revision 450a34955b855f0d813400013a9dbeead9d84c7b
1package com.android.server.wifi.anqp;
2
3import com.android.server.wifi.hotspot2.Utils;
4
5import java.net.ProtocolException;
6import java.nio.ByteBuffer;
7import java.nio.ByteOrder;
8import java.util.ArrayList;
9import java.util.Collections;
10import java.util.List;
11
12import static com.android.server.wifi.anqp.Constants.BYTE_MASK;
13import static com.android.server.wifi.anqp.Constants.getInteger;
14
15/**
16 * The Roaming Consortium ANQP Element, IEEE802.11-2012 section 8.4.4.7
17 */
18public class RoamingConsortiumElement extends ANQPElement {
19
20    private final List<Long> mOis;
21
22    public RoamingConsortiumElement(Constants.ANQPElementType infoID, ByteBuffer payload)
23            throws ProtocolException {
24        super(infoID);
25
26        mOis = new ArrayList<Long>();
27
28        while (payload.hasRemaining()) {
29            int length = payload.get() & BYTE_MASK;
30            if (length > payload.remaining()) {
31                throw new ProtocolException("Bad OI length: " + length);
32            }
33            mOis.add(getInteger(payload, ByteOrder.BIG_ENDIAN, length));
34        }
35    }
36
37    public List<Long> getOIs() {
38        return Collections.unmodifiableList(mOis);
39    }
40
41    @Override
42    public String toString() {
43        return "RoamingConsortium{mOis=[" + Utils.roamingConsortiumsToString(mOis) + "]}";
44    }
45}
46