NonEAPInnerAuth.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.BYTE_MASK; 7 8/** 9 * An EAP authentication parameter, IEEE802.11-2012, table 8-188 10 */ 11public class NonEAPInnerAuth implements AuthParam { 12 13 public enum NonEAPType {Reserved, PAP, CHAP, MSCHAP, MSCHAPv2} 14 15 private final NonEAPType mType; 16 17 public NonEAPInnerAuth(ByteBuffer payload) throws ProtocolException { 18 if (payload.remaining() < 2) { 19 throw new ProtocolException("Runt payload: " + payload.remaining()); 20 } 21 22 int length = payload.get() & BYTE_MASK; 23 if (length != 1) { 24 throw new ProtocolException("Bad length: " + length); 25 } 26 int typeID = payload.get() & BYTE_MASK; 27 mType = typeID < NonEAPType.values().length ? 28 NonEAPType.values()[typeID] : 29 NonEAPType.Reserved; 30 } 31 32 @Override 33 public EAP.AuthInfoID getAuthInfoID() { 34 return EAP.AuthInfoID.NonEAPInnerAuthType; 35 } 36 37 public NonEAPType getType() { 38 return mType; 39 } 40 41 @Override 42 public int hashCode() { 43 return mType.hashCode(); 44 } 45 46 @Override 47 public boolean equals(Object thatObject) { 48 if (thatObject == this) { 49 return true; 50 } else if (thatObject == null || thatObject.getClass() != NonEAPInnerAuth.class) { 51 return false; 52 } else { 53 return ((NonEAPInnerAuth) thatObject).getType() == getType(); 54 } 55 } 56 57 @Override 58 public String toString() { 59 return "NonEAPInnerAuth{" + 60 "mType=" + mType + 61 '}'; 62 } 63} 64