Home | History | Annotate | Download | only in wifi
      1 /*
      2  * Copyright (C) 2014 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.net.wifi;
     18 
     19 import android.os.Parcelable;
     20 import android.os.Parcel;
     21 import android.text.TextUtils;
     22 import java.util.HashMap;
     23 import java.util.Date;
     24 import java.util.ArrayList;
     25 
     26 import java.util.BitSet;
     27 
     28 /**
     29  * A class representing link layer statistics collected over a Wifi Interface.
     30  */
     31 /** {@hide} */
     32 public class WifiLinkLayerStats implements Parcelable {
     33     private static final String TAG = "WifiLinkLayerStats";
     34 
     35     /**
     36      * The current status of this network configuration entry.
     37      * @see Status
     38      */
     39     /** {@hide} */
     40     public int status;
     41 
     42     /**
     43      * The network's SSID. Can either be an ASCII string,
     44      * which must be enclosed in double quotation marks
     45      * (e.g., {@code "MyNetwork"}, or a string of
     46      * hex digits,which are not enclosed in quotes
     47      * (e.g., {@code 01a243f405}).
     48      */
     49     /** {@hide} */
     50     public String SSID;
     51     /**
     52      * When set. this is the BSSID the radio is currently associated with.
     53      * The value is a string in the format of an Ethernet MAC address, e.g.,
     54      * <code>XX:XX:XX:XX:XX:XX</code> where each <code>X</code> is a hex digit.
     55      */
     56     /** {@hide} */
     57     public String BSSID;
     58 
     59     /* number beacons received from our own AP */
     60     /** {@hide} */
     61     public int beacon_rx;
     62 
     63     /* RSSI taken on management frames */
     64     /** {@hide} */
     65     public int rssi_mgmt;
     66 
     67     /* packets counters */
     68     /** {@hide} */
     69     /* WME Best Effort Access Category (receive mpdu, transmit mpdu, lost mpdu, number of retries)*/
     70     public long rxmpdu_be;
     71     /** {@hide} */
     72     public long txmpdu_be;
     73     /** {@hide} */
     74     public long lostmpdu_be;
     75     /** {@hide} */
     76     public long retries_be;
     77     /** {@hide} */
     78     /* WME Background Access Category (receive mpdu, transmit mpdu, lost mpdu, number of retries) */
     79     public long rxmpdu_bk;
     80     /** {@hide} */
     81     public long txmpdu_bk;
     82     /** {@hide} */
     83     public long lostmpdu_bk;
     84     /** {@hide} */
     85     public long retries_bk;
     86     /** {@hide} */
     87     /* WME Video Access Category (receive mpdu, transmit mpdu, lost mpdu, number of retries) */
     88     public long rxmpdu_vi;
     89     /** {@hide} */
     90     public long txmpdu_vi;
     91     /** {@hide} */
     92     public long lostmpdu_vi;
     93     /** {@hide} */
     94     public long retries_vi;
     95     /** {@hide} */
     96     /* WME Voice Access Category (receive mpdu, transmit mpdu, lost mpdu, number of retries) */
     97     public long rxmpdu_vo;
     98     /** {@hide} */
     99     public long txmpdu_vo;
    100     /** {@hide} */
    101     public long lostmpdu_vo;
    102     /** {@hide} */
    103     public long retries_vo;
    104 
    105     /** {@hide} */
    106     public int on_time;
    107     /** {@hide} */
    108     public int tx_time;
    109     /** {@hide} */
    110     public int rx_time;
    111     /** {@hide} */
    112     public int on_time_scan;
    113 
    114     /** {@hide} */
    115     public WifiLinkLayerStats() {
    116     }
    117 
    118     @Override
    119     /** {@hide} */
    120     public String toString() {
    121         StringBuilder sbuf = new StringBuilder();
    122         sbuf.append(" WifiLinkLayerStats: ").append('\n');
    123 
    124         if (this.SSID != null) {
    125             sbuf.append(" SSID: ").append(this.SSID).append('\n');
    126         }
    127         if (this.BSSID != null) {
    128             sbuf.append(" BSSID: ").append(this.BSSID).append('\n');
    129         }
    130 
    131         sbuf.append(" my bss beacon rx: ").append(Integer.toString(this.beacon_rx)).append('\n');
    132         sbuf.append(" RSSI mgmt: ").append(Integer.toString(this.rssi_mgmt)).append('\n');
    133         sbuf.append(" BE : ").append(" rx=").append(Long.toString(this.rxmpdu_be))
    134                 .append(" tx=").append(Long.toString(this.txmpdu_be))
    135                 .append(" lost=").append(Long.toString(this.lostmpdu_be))
    136                 .append(" retries=").append(Long.toString(this.retries_be)).append('\n');
    137         sbuf.append(" BK : ").append(" rx=").append(Long.toString(this.rxmpdu_bk))
    138                 .append(" tx=").append(Long.toString(this.txmpdu_bk))
    139                 .append(" lost=").append(Long.toString(this.lostmpdu_bk))
    140                 .append(" retries=").append(Long.toString(this.retries_bk)).append('\n');
    141         sbuf.append(" VI : ").append(" rx=").append(Long.toString(this.rxmpdu_vi))
    142                 .append(" tx=").append(Long.toString(this.txmpdu_vi))
    143                 .append(" lost=").append(Long.toString(this.lostmpdu_vi))
    144                 .append(" retries=").append(Long.toString(this.retries_vi)).append('\n');
    145         sbuf.append(" VO : ").append(" rx=").append(Long.toString(this.rxmpdu_vo))
    146                 .append(" tx=").append(Long.toString(this.txmpdu_vo))
    147                 .append(" lost=").append(Long.toString(this.lostmpdu_vo))
    148                 .append(" retries=").append(Long.toString(this.retries_vo)).append('\n');
    149         sbuf.append(" on_time : ").append(Integer.toString(this.on_time))
    150                 .append(" tx_time=").append(Integer.toString(this.tx_time))
    151                 .append(" rx_time=").append(Integer.toString(this.rx_time))
    152                 .append(" scan_time=").append(Integer.toString(this.on_time_scan)).append('\n');
    153         return sbuf.toString();
    154     }
    155 
    156     /** Implement the Parcelable interface {@hide} */
    157     public int describeContents() {
    158         return 0;
    159     }
    160 
    161     /** {@hide} */
    162     public String getPrintableSsid() {
    163         if (SSID == null) return "";
    164         final int length = SSID.length();
    165         if (length > 2 && (SSID.charAt(0) == '"') && SSID.charAt(length - 1) == '"') {
    166             return SSID.substring(1, length - 1);
    167         }
    168 
    169         /** The ascii-encoded string format is P"<ascii-encoded-string>"
    170          * The decoding is implemented in the supplicant for a newly configured
    171          * network.
    172          */
    173         if (length > 3 && (SSID.charAt(0) == 'P') && (SSID.charAt(1) == '"') &&
    174                 (SSID.charAt(length-1) == '"')) {
    175             WifiSsid wifiSsid = WifiSsid.createFromAsciiEncoded(
    176                     SSID.substring(2, length - 1));
    177             return wifiSsid.toString();
    178         }
    179         return SSID;
    180     }
    181 
    182     /** Implement the Parcelable interface {@hide} */
    183     public void writeToParcel(Parcel dest, int flags) {
    184         dest.writeString(SSID);
    185         dest.writeString(BSSID);
    186         dest.writeInt(on_time);
    187         dest.writeInt(tx_time);
    188         dest.writeInt(rx_time);
    189         dest.writeInt(on_time_scan);
    190     }
    191 
    192     /** Implement the Parcelable interface {@hide} */
    193     public static final Creator<WifiLinkLayerStats> CREATOR =
    194         new Creator<WifiLinkLayerStats>() {
    195             public WifiLinkLayerStats createFromParcel(Parcel in) {
    196                 WifiLinkLayerStats stats = new WifiLinkLayerStats();
    197                 stats.SSID = in.readString();
    198                 stats.BSSID = in.readString();
    199                 stats.on_time = in.readInt();
    200                 stats.tx_time = in.readInt();
    201                 stats.rx_time = in.readInt();
    202                 stats.on_time_scan = in.readInt();
    203                 return stats;
    204             };
    205             public WifiLinkLayerStats[] newArray(int size) {
    206                 return new WifiLinkLayerStats[size];
    207             }
    208 
    209         };
    210 }
    211