1 package com.android.server.wifi.anqp; 2 3 import java.net.ProtocolException; 4 import java.nio.ByteBuffer; 5 import java.util.ArrayList; 6 import java.util.Collections; 7 import java.util.List; 8 9 /** 10 * The Connection Capability vendor specific ANQP Element, 11 * Wi-Fi Alliance Hotspot 2.0 (Release 2) Technical Specification - Version 5.00, 12 * section 4.5 13 */ 14 public class HSConnectionCapabilityElement extends ANQPElement { 15 16 public enum ProtoStatus {Closed, Open, Unknown} 17 18 private final List<ProtocolTuple> mStatusList; 19 20 public static class ProtocolTuple { 21 private final int mProtocol; 22 private final int mPort; 23 private final ProtoStatus mStatus; 24 25 private ProtocolTuple(ByteBuffer payload) throws ProtocolException { 26 if (payload.remaining() < 4) { 27 throw new ProtocolException("Runt protocol tuple: " + payload.remaining()); 28 } 29 mProtocol = payload.get() & Constants.BYTE_MASK; 30 mPort = payload.getShort() & Constants.SHORT_MASK; 31 int statusNumber = payload.get() & Constants.BYTE_MASK; 32 mStatus = statusNumber < ProtoStatus.values().length ? 33 ProtoStatus.values()[statusNumber] : 34 null; 35 } 36 37 public int getProtocol() { 38 return mProtocol; 39 } 40 41 public int getPort() { 42 return mPort; 43 } 44 45 public ProtoStatus getStatus() { 46 return mStatus; 47 } 48 49 @Override 50 public String toString() { 51 return "ProtocolTuple{" + 52 "mProtocol=" + mProtocol + 53 ", mPort=" + mPort + 54 ", mStatus=" + mStatus + 55 '}'; 56 } 57 } 58 59 public HSConnectionCapabilityElement(Constants.ANQPElementType infoID, ByteBuffer payload) 60 throws ProtocolException { 61 super(infoID); 62 63 mStatusList = new ArrayList<>(); 64 while (payload.hasRemaining()) { 65 mStatusList.add(new ProtocolTuple(payload)); 66 } 67 } 68 69 public List<ProtocolTuple> getStatusList() { 70 return Collections.unmodifiableList(mStatusList); 71 } 72 73 @Override 74 public String toString() { 75 return "HSConnectionCapability{" + 76 "mStatusList=" + mStatusList + 77 '}'; 78 } 79 } 80