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 22 /** 23 * A class representing link layer statistics collected over a Wifi Interface. 24 */ 25 /** {@hide} */ 26 public class WifiLinkLayerStats implements Parcelable { 27 private static final String TAG = "WifiLinkLayerStats"; 28 29 /** 30 * The current status of this network configuration entry. 31 * @see Status 32 */ 33 /** {@hide} */ 34 public int status; 35 36 /** 37 * The network's SSID. Can either be an ASCII string, 38 * which must be enclosed in double quotation marks 39 * (e.g., {@code "MyNetwork"}, or a string of 40 * hex digits,which are not enclosed in quotes 41 * (e.g., {@code 01a243f405}). 42 */ 43 /** {@hide} */ 44 public String SSID; 45 /** 46 * When set. this is the BSSID the radio is currently associated with. 47 * The value is a string in the format of an Ethernet MAC address, e.g., 48 * <code>XX:XX:XX:XX:XX:XX</code> where each <code>X</code> is a hex digit. 49 */ 50 /** {@hide} */ 51 public String BSSID; 52 53 /* number beacons received from our own AP */ 54 /** {@hide} */ 55 public int beacon_rx; 56 57 /* RSSI taken on management frames */ 58 /** {@hide} */ 59 public int rssi_mgmt; 60 61 /* packets counters */ 62 /** {@hide} */ 63 /* WME Best Effort Access Category (receive mpdu, transmit mpdu, lost mpdu, number of retries)*/ 64 public long rxmpdu_be; 65 /** {@hide} */ 66 public long txmpdu_be; 67 /** {@hide} */ 68 public long lostmpdu_be; 69 /** {@hide} */ 70 public long retries_be; 71 /** {@hide} */ 72 /* WME Background Access Category (receive mpdu, transmit mpdu, lost mpdu, number of retries) */ 73 public long rxmpdu_bk; 74 /** {@hide} */ 75 public long txmpdu_bk; 76 /** {@hide} */ 77 public long lostmpdu_bk; 78 /** {@hide} */ 79 public long retries_bk; 80 /** {@hide} */ 81 /* WME Video Access Category (receive mpdu, transmit mpdu, lost mpdu, number of retries) */ 82 public long rxmpdu_vi; 83 /** {@hide} */ 84 public long txmpdu_vi; 85 /** {@hide} */ 86 public long lostmpdu_vi; 87 /** {@hide} */ 88 public long retries_vi; 89 /** {@hide} */ 90 /* WME Voice Access Category (receive mpdu, transmit mpdu, lost mpdu, number of retries) */ 91 public long rxmpdu_vo; 92 /** {@hide} */ 93 public long txmpdu_vo; 94 /** {@hide} */ 95 public long lostmpdu_vo; 96 /** {@hide} */ 97 public long retries_vo; 98 99 /** {@hide} */ 100 public int on_time; 101 /** {@hide} */ 102 public int tx_time; 103 /** {@hide} */ 104 public int rx_time; 105 /** {@hide} */ 106 public int on_time_scan; 107 108 /** {@hide} */ WifiLinkLayerStats()109 public WifiLinkLayerStats() { 110 } 111 112 @Override 113 /** {@hide} */ toString()114 public String toString() { 115 StringBuilder sbuf = new StringBuilder(); 116 sbuf.append(" WifiLinkLayerStats: ").append('\n'); 117 118 if (this.SSID != null) { 119 sbuf.append(" SSID: ").append(this.SSID).append('\n'); 120 } 121 if (this.BSSID != null) { 122 sbuf.append(" BSSID: ").append(this.BSSID).append('\n'); 123 } 124 125 sbuf.append(" my bss beacon rx: ").append(Integer.toString(this.beacon_rx)).append('\n'); 126 sbuf.append(" RSSI mgmt: ").append(Integer.toString(this.rssi_mgmt)).append('\n'); 127 sbuf.append(" BE : ").append(" rx=").append(Long.toString(this.rxmpdu_be)) 128 .append(" tx=").append(Long.toString(this.txmpdu_be)) 129 .append(" lost=").append(Long.toString(this.lostmpdu_be)) 130 .append(" retries=").append(Long.toString(this.retries_be)).append('\n'); 131 sbuf.append(" BK : ").append(" rx=").append(Long.toString(this.rxmpdu_bk)) 132 .append(" tx=").append(Long.toString(this.txmpdu_bk)) 133 .append(" lost=").append(Long.toString(this.lostmpdu_bk)) 134 .append(" retries=").append(Long.toString(this.retries_bk)).append('\n'); 135 sbuf.append(" VI : ").append(" rx=").append(Long.toString(this.rxmpdu_vi)) 136 .append(" tx=").append(Long.toString(this.txmpdu_vi)) 137 .append(" lost=").append(Long.toString(this.lostmpdu_vi)) 138 .append(" retries=").append(Long.toString(this.retries_vi)).append('\n'); 139 sbuf.append(" VO : ").append(" rx=").append(Long.toString(this.rxmpdu_vo)) 140 .append(" tx=").append(Long.toString(this.txmpdu_vo)) 141 .append(" lost=").append(Long.toString(this.lostmpdu_vo)) 142 .append(" retries=").append(Long.toString(this.retries_vo)).append('\n'); 143 sbuf.append(" on_time : ").append(Integer.toString(this.on_time)) 144 .append(" tx_time=").append(Integer.toString(this.tx_time)) 145 .append(" rx_time=").append(Integer.toString(this.rx_time)) 146 .append(" scan_time=").append(Integer.toString(this.on_time_scan)).append('\n'); 147 return sbuf.toString(); 148 } 149 150 /** Implement the Parcelable interface {@hide} */ describeContents()151 public int describeContents() { 152 return 0; 153 } 154 155 /** {@hide} */ getPrintableSsid()156 public String getPrintableSsid() { 157 if (SSID == null) return ""; 158 final int length = SSID.length(); 159 if (length > 2 && (SSID.charAt(0) == '"') && SSID.charAt(length - 1) == '"') { 160 return SSID.substring(1, length - 1); 161 } 162 163 /** The ascii-encoded string format is P"<ascii-encoded-string>" 164 * The decoding is implemented in the supplicant for a newly configured 165 * network. 166 */ 167 if (length > 3 && (SSID.charAt(0) == 'P') && (SSID.charAt(1) == '"') && 168 (SSID.charAt(length-1) == '"')) { 169 WifiSsid wifiSsid = WifiSsid.createFromAsciiEncoded( 170 SSID.substring(2, length - 1)); 171 return wifiSsid.toString(); 172 } 173 return SSID; 174 } 175 176 /** Implement the Parcelable interface {@hide} */ writeToParcel(Parcel dest, int flags)177 public void writeToParcel(Parcel dest, int flags) { 178 dest.writeString(SSID); 179 dest.writeString(BSSID); 180 dest.writeInt(on_time); 181 dest.writeInt(tx_time); 182 dest.writeInt(rx_time); 183 dest.writeInt(on_time_scan); 184 } 185 186 /** Implement the Parcelable interface {@hide} */ 187 public static final Creator<WifiLinkLayerStats> CREATOR = 188 new Creator<WifiLinkLayerStats>() { 189 public WifiLinkLayerStats createFromParcel(Parcel in) { 190 WifiLinkLayerStats stats = new WifiLinkLayerStats(); 191 stats.SSID = in.readString(); 192 stats.BSSID = in.readString(); 193 stats.on_time = in.readInt(); 194 stats.tx_time = in.readInt(); 195 stats.rx_time = in.readInt(); 196 stats.on_time_scan = in.readInt(); 197 return stats; 198 }; 199 public WifiLinkLayerStats[] newArray(int size) { 200 return new WifiLinkLayerStats[size]; 201 } 202 203 }; 204 } 205