1 package com.android.server.wifi.anqp; 2 3 import java.net.ProtocolException; 4 import java.nio.ByteBuffer; 5 6 /** 7 * The IP Address Type availability ANQP Element, IEEE802.11-2012 section 8.4.4.9 8 */ 9 public class IPAddressTypeAvailabilityElement extends ANQPElement { 10 public enum IPv4Availability { 11 NotAvailable, Public, PortRestricted, SingleNAT, DoubleNAT, 12 PortRestrictedAndSingleNAT, PortRestrictedAndDoubleNAT, Unknown 13 } 14 15 public enum IPv6Availability {NotAvailable, Available, Unknown, Reserved} 16 17 private final IPv4Availability mV4Availability; 18 private final IPv6Availability mV6Availability; 19 20 public IPAddressTypeAvailabilityElement(Constants.ANQPElementType infoID, ByteBuffer payload) 21 throws ProtocolException { 22 super(infoID); 23 24 if (payload.remaining() != 1) 25 throw new ProtocolException("Bad IP Address Type Availability length: " + 26 payload.remaining()); 27 28 int ipField = payload.get(); 29 mV6Availability = IPv6Availability.values()[ipField & 0x3]; 30 31 ipField = (ipField >> 2) & 0x3f; 32 mV4Availability = ipField < IPv4Availability.values().length ? 33 IPv4Availability.values()[ipField] : 34 IPv4Availability.Unknown; 35 } 36 37 public IPv4Availability getV4Availability() { 38 return mV4Availability; 39 } 40 41 public IPv6Availability getV6Availability() { 42 return mV6Availability; 43 } 44 45 @Override 46 public String toString() { 47 return "IPAddressTypeAvailability{" + 48 "mV4Availability=" + mV4Availability + 49 ", mV6Availability=" + mV6Availability + 50 '}'; 51 } 52 } 53