1 /*
2  * Copyright 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 com.android.server.wifi;
18 
19 import android.util.SparseArray;
20 
21 import java.util.Arrays;
22 
23 /**
24  * A class representing link layer statistics collected over a Wifi Interface.
25  */
26 
27 /**
28  * {@hide}
29  */
30 public class WifiLinkLayerStats {
31     public static final String V1_0 = "V1_0";
32     public static final String V1_3 = "V1_3";
33 
34     /** The version of hal StaLinkLayerStats **/
35     public String version;
36 
37     /** Number of beacons received from our own AP */
38     public int beacon_rx;
39 
40     /** RSSI of management frames */
41     public int rssi_mgmt;
42 
43     /* Packet counters */
44 
45     /** WME Best Effort Access Category received mpdu */
46     public long rxmpdu_be;
47     /** WME Best Effort Access Category transmitted mpdu */
48     public long txmpdu_be;
49     /** WME Best Effort Access Category lost mpdu */
50     public long lostmpdu_be;
51     /** WME Best Effort Access Category number of transmission retries */
52     public long retries_be;
53 
54     /** WME Background Access Category received mpdu */
55     public long rxmpdu_bk;
56     /** WME Background Access Category transmitted mpdu */
57     public long txmpdu_bk;
58     /** WME Background Access Category lost mpdu */
59     public long lostmpdu_bk;
60     /** WME Background Access Category number of transmission retries */
61     public long retries_bk;
62 
63     /** WME Video Access Category received mpdu */
64     public long rxmpdu_vi;
65     /** WME Video Access Category transmitted mpdu */
66     public long txmpdu_vi;
67     /** WME Video Access Category lost mpdu */
68     public long lostmpdu_vi;
69     /** WME Video Access Category number of transmission retries */
70     public long retries_vi;
71 
72     /** WME Voice Access Category received mpdu */
73     public long rxmpdu_vo;
74     /** WME Voice Access Category transmitted mpdu */
75     public long txmpdu_vo;
76     /** WME Voice Access Category lost mpdu */
77     public long lostmpdu_vo;
78     /** WME Voice Access Category number of transmission retries */
79     public long retries_vo;
80 
81     /**
82      * Cumulative milliseconds when radio is awake
83      */
84     public int on_time;
85     /**
86      * Cumulative milliseconds of active transmission
87      */
88     public int tx_time;
89     /**
90      * Cumulative milliseconds per level of active transmission
91      */
92     public int[] tx_time_per_level;
93     /**
94      * Cumulative milliseconds of active receive
95      */
96     public int rx_time;
97     /**
98      * Cumulative milliseconds when radio is awake due to scan
99      */
100     public int on_time_scan;
101     /**
102      * Cumulative milliseconds when radio is awake due to nan scan
103      */
104     public int on_time_nan_scan = -1;
105     /**
106      * Cumulative milliseconds when radio is awake due to background scan
107      */
108     public int on_time_background_scan = -1;
109     /**
110      * Cumulative milliseconds when radio is awake due to roam scan
111      */
112     public int on_time_roam_scan = -1;
113     /**
114      * Cumulative milliseconds when radio is awake due to pno scan
115      */
116     public int on_time_pno_scan = -1;
117     /**
118      * Cumulative milliseconds when radio is awake due to hotspot 2.0 scan amd GAS exchange
119      */
120     public int on_time_hs20_scan = -1;
121     /**
122      * channel stats
123      */
124     public static class ChannelStats {
125         /**
126          * Channel frequency in MHz;
127          */
128         public int frequency;
129         /**
130          * Cumulative milliseconds radio is awake on this channel
131          */
132         public int radioOnTimeMs;
133         /**
134          * Cumulative milliseconds CCA is held busy on this channel
135          */
136         public int ccaBusyTimeMs;
137     }
138     /**
139      * Channel stats list
140      */
141     public final SparseArray<ChannelStats> channelStatsMap = new SparseArray<>();
142 
143     /**
144      * TimeStamp - absolute milliseconds from boot when these stats were sampled.
145      */
146     public long timeStampInMs;
147 
148     @Override
toString()149     public String toString() {
150         StringBuilder sbuf = new StringBuilder();
151         sbuf.append(" WifiLinkLayerStats: ").append('\n');
152 
153         sbuf.append(" version of StaLinkLayerStats: ").append(version).append('\n');
154         sbuf.append(" my bss beacon rx: ").append(Integer.toString(this.beacon_rx)).append('\n');
155         sbuf.append(" RSSI mgmt: ").append(Integer.toString(this.rssi_mgmt)).append('\n');
156         sbuf.append(" BE : ").append(" rx=").append(Long.toString(this.rxmpdu_be))
157                 .append(" tx=").append(Long.toString(this.txmpdu_be))
158                 .append(" lost=").append(Long.toString(this.lostmpdu_be))
159                 .append(" retries=").append(Long.toString(this.retries_be)).append('\n');
160         sbuf.append(" BK : ").append(" rx=").append(Long.toString(this.rxmpdu_bk))
161                 .append(" tx=").append(Long.toString(this.txmpdu_bk))
162                 .append(" lost=").append(Long.toString(this.lostmpdu_bk))
163                 .append(" retries=").append(Long.toString(this.retries_bk)).append('\n');
164         sbuf.append(" VI : ").append(" rx=").append(Long.toString(this.rxmpdu_vi))
165                 .append(" tx=").append(Long.toString(this.txmpdu_vi))
166                 .append(" lost=").append(Long.toString(this.lostmpdu_vi))
167                 .append(" retries=").append(Long.toString(this.retries_vi)).append('\n');
168         sbuf.append(" VO : ").append(" rx=").append(Long.toString(this.rxmpdu_vo))
169                 .append(" tx=").append(Long.toString(this.txmpdu_vo))
170                 .append(" lost=").append(Long.toString(this.lostmpdu_vo))
171                 .append(" retries=").append(Long.toString(this.retries_vo)).append('\n');
172         sbuf.append(" on_time : ").append(Integer.toString(this.on_time))
173                 .append(" tx_time=").append(Integer.toString(this.tx_time))
174                 .append(" rx_time=").append(Integer.toString(this.rx_time))
175                 .append(" scan_time=").append(Integer.toString(this.on_time_scan)).append('\n')
176                 .append(" nan_scan_time=")
177                 .append(Integer.toString(this.on_time_nan_scan)).append('\n')
178                 .append(" g_scan_time=")
179                 .append(Integer.toString(this.on_time_background_scan)).append('\n')
180                 .append(" roam_scan_time=")
181                 .append(Integer.toString(this.on_time_roam_scan)).append('\n')
182                 .append(" pno_scan_time=")
183                 .append(Integer.toString(this.on_time_pno_scan)).append('\n')
184                 .append(" hs2.0_scan_time=")
185                 .append(Integer.toString(this.on_time_hs20_scan)).append('\n')
186                 .append(" tx_time_per_level=" + Arrays.toString(tx_time_per_level)).append('\n');
187         int numChanStats = this.channelStatsMap.size();
188         sbuf.append(" Number of channel stats=").append(numChanStats).append('\n');
189         for (int i = 0; i < numChanStats; ++i) {
190             ChannelStats channelStatsEntry = this.channelStatsMap.valueAt(i);
191             sbuf.append(" Frequency=").append(channelStatsEntry.frequency)
192                     .append(" radioOnTimeMs=").append(channelStatsEntry.radioOnTimeMs)
193                     .append(" ccaBusyTimeMs=").append(channelStatsEntry.ccaBusyTimeMs).append('\n');
194         }
195         sbuf.append(" ts=" + timeStampInMs);
196         return sbuf.toString();
197     }
198 
199 }
200