1 package com.android.server.wifi.anqp; 2 3 import java.net.ProtocolException; 4 import java.nio.ByteBuffer; 5 6 import static com.android.server.wifi.anqp.Constants.BYTE_MASK; 7 import static com.android.server.wifi.anqp.Constants.INT_MASK; 8 import static com.android.server.wifi.anqp.Constants.SHORT_MASK; 9 10 /** 11 * The WAN Metrics vendor specific ANQP Element, 12 * Wi-Fi Alliance Hotspot 2.0 (Release 2) Technical Specification - Version 5.00, 13 * section 4.4 14 */ 15 public class HSWanMetricsElement extends ANQPElement { 16 17 public enum LinkStatus {Reserved, Up, Down, Test} 18 19 private final LinkStatus mStatus; 20 private final boolean mSymmetric; 21 private final boolean mCapped; 22 private final long mDlSpeed; 23 private final long mUlSpeed; 24 private final int mDlLoad; 25 private final int mUlLoad; 26 private final int mLMD; 27 28 public HSWanMetricsElement(Constants.ANQPElementType infoID, ByteBuffer payload) 29 throws ProtocolException { 30 super(infoID); 31 32 if (payload.remaining() != 13) { 33 throw new ProtocolException("Bad WAN metrics length: " + payload.remaining()); 34 } 35 36 int status = payload.get() & BYTE_MASK; 37 mStatus = LinkStatus.values()[status & 0x03]; 38 mSymmetric = (status & 0x04) != 0; 39 mCapped = (status & 0x08) != 0; 40 mDlSpeed = payload.getInt() & INT_MASK; 41 mUlSpeed = payload.getInt() & INT_MASK; 42 mDlLoad = payload.get() & BYTE_MASK; 43 mUlLoad = payload.get() & BYTE_MASK; 44 mLMD = payload.getShort() & SHORT_MASK; 45 } 46 47 public LinkStatus getStatus() { 48 return mStatus; 49 } 50 51 public boolean isSymmetric() { 52 return mSymmetric; 53 } 54 55 public boolean isCapped() { 56 return mCapped; 57 } 58 59 public long getDlSpeed() { 60 return mDlSpeed; 61 } 62 63 public long getUlSpeed() { 64 return mUlSpeed; 65 } 66 67 public int getDlLoad() { 68 return mDlLoad; 69 } 70 71 public int getUlLoad() { 72 return mUlLoad; 73 } 74 75 public int getLMD() { 76 return mLMD; 77 } 78 79 @Override 80 public String toString() { 81 return String.format("HSWanMetrics{mStatus=%s, mSymmetric=%s, mCapped=%s, " + 82 "mDlSpeed=%d, mUlSpeed=%d, mDlLoad=%f, mUlLoad=%f, mLMD=%d}", 83 mStatus, mSymmetric, mCapped, 84 mDlSpeed, mUlSpeed, 85 (double)mDlLoad * 100.0 / 256.0, 86 (double)mUlLoad * 100.0 / 256.0, 87 mLMD); 88 } 89 } 90