summaryrefslogtreecommitdiffstats
path: root/wifi/java/android/net/wifi/anqp/HSConnectionCapabilityElement.java
blob: 8937859446120a665473c3e9a754ceb1cd3e4cee (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
package android.net.wifi.anqp;

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

import static android.net.wifi.anqp.Constants.BYTE_MASK;
import static android.net.wifi.anqp.Constants.SHORT_MASK;

/**
 * The Connection Capability vendor specific ANQP Element,
 * Wi-Fi Alliance Hotspot 2.0 (Release 2) Technical Specification - Version 5.00,
 * section 4.5
 */
public class HSConnectionCapabilityElement extends ANQPElement {

    public enum ProtoStatus {Closed, Open, Unknown}

    private final List<ProtocolTuple> mStatusList;

    public static class ProtocolTuple {
        private final int mProtocol;
        private final int mPort;
        private final ProtoStatus mStatus;

        private ProtocolTuple(ByteBuffer payload) throws ProtocolException {
            if (payload.remaining() < 4) {
                throw new ProtocolException("Runt protocol tuple: " + payload.remaining());
            }
            mProtocol = payload.get() & BYTE_MASK;
            mPort = payload.getShort() & SHORT_MASK;
            int statusNumber = payload.get() & BYTE_MASK;
            mStatus = statusNumber < ProtoStatus.values().length ?
                    ProtoStatus.values()[statusNumber] :
                    null;
        }

        public int getProtocol() {
            return mProtocol;
        }

        public int getPort() {
            return mPort;
        }

        public ProtoStatus getStatus() {
            return mStatus;
        }

        @Override
        public String toString() {
            return "ProtocolTuple{" +
                    "mProtocol=" + mProtocol +
                    ", mPort=" + mPort +
                    ", mStatus=" + mStatus +
                    '}';
        }
    }

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

        mStatusList = new ArrayList<ProtocolTuple>();
        while (payload.hasRemaining()) {
            mStatusList.add(new ProtocolTuple(payload));
        }
    }

    public List<ProtocolTuple> getStatusList() {
        return Collections.unmodifiableList(mStatusList);
    }

    @Override
    public String toString() {
        return "HSConnectionCapabilityElement{" +
                "mStatusList=" + mStatusList +
                '}';
    }
}