Home | History | Annotate | Download | only in anqp
      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 import static com.android.server.wifi.anqp.Constants.BYTE_MASK;
     10 
     11 
     12 /**
     13  * The 3GPP Cellular Network ANQP Element, IEEE802.11-2012 section 8.4.4.11
     14  */
     15 public class ThreeGPPNetworkElement extends ANQPElement {
     16     private final int mUserData;
     17     private final List<CellularNetwork> mPlmns;
     18 
     19     public ThreeGPPNetworkElement(Constants.ANQPElementType infoID, ByteBuffer payload)
     20             throws ProtocolException {
     21         super(infoID);
     22 
     23         mPlmns = new ArrayList<CellularNetwork>();
     24         mUserData = payload.get() & BYTE_MASK;
     25         int length = payload.get() & BYTE_MASK;
     26         if (length > payload.remaining()) {
     27             throw new ProtocolException("Runt payload");
     28         }
     29 
     30         while (payload.hasRemaining()) {
     31             CellularNetwork network = CellularNetwork.buildCellularNetwork(payload);
     32             if (network != null) {
     33                 mPlmns.add(network);
     34             }
     35         }
     36     }
     37 
     38     public int getUserData() {
     39         return mUserData;
     40     }
     41 
     42     public List<CellularNetwork> getPlmns() {
     43         return Collections.unmodifiableList(mPlmns);
     44     }
     45 
     46     @Override
     47     public String toString() {
     48         return "ThreeGPPNetwork{" +
     49                 "mUserData=" + mUserData +
     50                 ", mPlmns=" + mPlmns +
     51                 '}';
     52     }
     53 }
     54