ExpandedEAPMethod.java revision 777f4fc037d3ebd555f10041f8acfb41515b2f4b
1package com.android.server.wifi.anqp.eap;
2
3import java.net.ProtocolException;
4import java.nio.ByteBuffer;
5
6import static com.android.server.wifi.anqp.Constants.INT_MASK;
7import static com.android.server.wifi.anqp.Constants.getInteger;
8
9/**
10 * An EAP authentication parameter, IEEE802.11-2012, table 8-188
11 */
12public class ExpandedEAPMethod implements AuthParam {
13
14    private final EAP.AuthInfoID m_authInfoID;
15    private final int m_vendorID;
16    private final long m_vendorType;
17
18    public ExpandedEAPMethod(EAP.AuthInfoID authInfoID, ByteBuffer payload) throws ProtocolException {
19        if (payload.remaining() != 7) {
20            throw new ProtocolException("Bad length: " + payload.remaining());
21        }
22
23        m_authInfoID = authInfoID;
24        m_vendorID = (int) getInteger(payload, 3);
25        m_vendorType = payload.getInt() & INT_MASK;
26    }
27
28    @Override
29    public EAP.AuthInfoID getAuthInfoID() {
30        return m_authInfoID;
31    }
32
33    @Override
34    public int hashCode() {
35        return (m_authInfoID.hashCode() * 31 + m_vendorID) * 31 + (int) m_vendorType;
36    }
37
38    @Override
39    public boolean equals(Object thatObject) {
40        if (thatObject == this) {
41            return true;
42        } else if (thatObject == null || thatObject.getClass() != ExpandedEAPMethod.class) {
43            return false;
44        } else {
45            ExpandedEAPMethod that = (ExpandedEAPMethod) thatObject;
46            return that.getVendorID() == getVendorID() && that.getVendorType() == getVendorType();
47        }
48    }
49
50    public int getVendorID() {
51        return m_vendorID;
52    }
53
54    public long getVendorType() {
55        return m_vendorType;
56    }
57
58    @Override
59    public String toString() {
60        return "ExpandedEAPMethod{" +
61                "m_authInfoID=" + m_authInfoID +
62                ", m_vendorID=" + m_vendorID +
63                ", m_vendorType=" + m_vendorType +
64                '}';
65    }
66}
67