summaryrefslogtreecommitdiffstats
path: root/service/java/com/android/server/wifi/anqp/HSConnectionCapabilityElement.java
blob: 53f1051d41050ef42b348a8f6c41ec046c540dfb (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
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.List;

/**
 * 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() & Constants.BYTE_MASK;
            mPort = payload.getShort() & Constants.SHORT_MASK;
            int statusNumber = payload.get() & Constants.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<>();
        while (payload.hasRemaining()) {
            mStatusList.add(new ProtocolTuple(payload));
        }
    }

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

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