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