• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Broadcom Dongle Host Driver (DHD), RTT
3  *
4  * Copyright (C) 1999-2017, Broadcom Corporation
5  *
6  *      Unless you and Broadcom execute a separate written software license
7  * agreement governing use of this software, this software is licensed to you
8  * under the terms of the GNU General Public License version 2 (the "GPL"),
9  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
10  * following added to such license:
11  *
12  *      As a special exception, the copyright holders of this software give you
13  * permission to link this software with independent modules, and to copy and
14  * distribute the resulting executable under terms of your choice, provided that
15  * you also meet, for each linked independent module, the terms and conditions of
16  * the license of that module.  An independent module is a module which is not
17  * derived from this software.  The special exception does not apply to any
18  * modifications of the software.
19  *
20  *      Notwithstanding the above, under no circumstances may you combine this
21  * software in any way with any other Broadcom software provided under a license
22  * other than the GPL, without Broadcom's express prior written consent.
23  *
24  *
25  * <<Broadcom-WL-IPTag/Open:>>
26  *
27  * $Id$
28  */
29 #ifndef __DHD_RTT_H__
30 #define __DHD_RTT_H__
31 
32 #include "dngl_stats.h"
33 
34 #define RTT_MAX_TARGET_CNT 50
35 #define RTT_MAX_FRAME_CNT 25
36 #define RTT_MAX_RETRY_CNT 10
37 #define DEFAULT_FTM_CNT 6
38 #define DEFAULT_RETRY_CNT 6
39 #define DEFAULT_FTM_FREQ 5180
40 #define DEFAULT_FTM_CNTR_FREQ0 5210
41 
42 #define TARGET_INFO_SIZE(count) (sizeof(rtt_target_info_t) * count)
43 
44 #define TARGET_TYPE(target) (target->type)
45 
46 #ifndef BIT
47 #define BIT(x) (1 << (x))
48 #endif
49 
50 /* DSSS, CCK and 802.11n rates in [500kbps] units */
51 #define WL_MAXRATE    108    /* in 500kbps units */
52 #define WL_RATE_1M    2    /* in 500kbps units */
53 #define WL_RATE_2M    4    /* in 500kbps units */
54 #define WL_RATE_5M5    11    /* in 500kbps units */
55 #define WL_RATE_11M    22    /* in 500kbps units */
56 #define WL_RATE_6M    12    /* in 500kbps units */
57 #define WL_RATE_9M    18    /* in 500kbps units */
58 #define WL_RATE_12M    24    /* in 500kbps units */
59 #define WL_RATE_18M    36    /* in 500kbps units */
60 #define WL_RATE_24M    48    /* in 500kbps units */
61 #define WL_RATE_36M    72    /* in 500kbps units */
62 #define WL_RATE_48M    96    /* in 500kbps units */
63 #define WL_RATE_54M    108    /* in 500kbps units */
64 #define GET_RTTSTATE(dhd) ((rtt_status_info_t *)dhd->rtt_state)
65 
66 enum rtt_role {
67     RTT_INITIATOR = 0,
68     RTT_TARGET = 1
69 };
70 enum rtt_status {
71     RTT_STOPPED = 0,
72     RTT_STARTED = 1,
73     RTT_ENABLED = 2
74 };
75 typedef int64_t wifi_timestamp; /* In microseconds (us) */
76 typedef int64_t wifi_timespan;
77 typedef int32 wifi_rssi_rtt;
78 
79 typedef enum {
80     RTT_INVALID,
81     RTT_ONE_WAY,
82     RTT_TWO_WAY,
83     RTT_AUTO
84 } rtt_type_t;
85 
86 typedef enum {
87     RTT_PEER_STA,
88     RTT_PEER_AP,
89     RTT_PEER_P2P,
90     RTT_PEER_NAN,
91     RTT_PEER_INVALID
92 } rtt_peer_type_t;
93 
94 typedef enum rtt_reason {
95     RTT_REASON_SUCCESS,
96     RTT_REASON_FAILURE,
97     RTT_REASON_FAIL_NO_RSP,
98     RTT_REASON_FAIL_INVALID_TS, /* Invalid timestamp */
99     RTT_REASON_FAIL_PROTOCOL, /* 11mc protocol failed */
100     RTT_REASON_FAIL_REJECTED,
101     RTT_REASON_FAIL_NOT_SCHEDULED_YET,
102     RTT_REASON_FAIL_SCHEDULE, /* schedule failed */
103     RTT_REASON_FAIL_TM_TIMEOUT,
104     RTT_REASON_FAIL_AP_ON_DIFF_CHANNEL,
105     RTT_REASON_FAIL_NO_CAPABILITY,
106     RTT_REASON_FAIL_BUSY_TRY_LATER,
107     RTT_REASON_ABORTED
108 } rtt_reason_t;
109 
110 enum {
111     RTT_CAP_ONE_WAY     = BIT(0),
112     /* IEEE802.11mc */
113     RTT_CAP_FTM_WAY  = BIT(1)
114 };
115 
116 enum {
117     RTT_FEATURE_LCI = BIT(0),
118     RTT_FEATURE_LCR = BIT(1),
119     RTT_FEATURE_PREAMBLE = BIT(2),
120     RTT_FEATURE_BW = BIT(3)
121 };
122 
123 enum {
124     RTT_PREAMBLE_LEGACY = BIT(0),
125     RTT_PREAMBLE_HT = BIT(1),
126     RTT_PREAMBLE_VHT = BIT(2)
127 };
128 
129 
130 enum {
131     RTT_BW_5 = BIT(0),
132     RTT_BW_10 = BIT(1),
133     RTT_BW_20 = BIT(2),
134     RTT_BW_40 = BIT(3),
135     RTT_BW_80 = BIT(4),
136     RTT_BW_160 = BIT(5)
137 };
138 #define FTM_MAX_NUM_BURST_EXP    14
139 #define HAS_11MC_CAP(cap) (cap & RTT_CAP_FTM_WAY)
140 #define HAS_ONEWAY_CAP(cap) (cap & RTT_CAP_ONE_WAY)
141 #define HAS_RTT_CAP(cap) (HAS_ONEWAY_CAP(cap) || HAS_11MC_CAP(cap))
142 
143 typedef struct wifi_channel_info {
144     wifi_channel_width_t width;
145     wifi_channel center_freq; /* primary 20 MHz channel */
146     wifi_channel center_freq0; /* center freq (MHz) first segment */
147     wifi_channel center_freq1; /* center freq (MHz) second segment valid for 80 + 80 */
148 } wifi_channel_info_t;
149 
150 typedef struct wifi_rate {
151     uint32 preamble :3; /* 0: OFDM, 1: CCK, 2 : HT, 3: VHT, 4..7 reserved */
152     uint32 nss        :2; /* 1 : 1x1, 2: 2x2, 3: 3x3, 4: 4x4 */
153     uint32 bw        :3; /* 0: 20Mhz, 1: 40Mhz, 2: 80Mhz, 3: 160Mhz */
154     /* OFDM/CCK rate code would be as per IEEE std in the unit of 0.5 mb
155     * HT/VHT it would be mcs index
156     */
157     uint32 rateMcsIdx :8;
158     uint32 reserved :16; /* reserved */
159     uint32 bitrate;    /* unit of 100 Kbps */
160 } wifi_rate_t;
161 
162 typedef struct rtt_target_info {
163     struct ether_addr addr;
164     rtt_type_t type; /* rtt_type */
165     rtt_peer_type_t peer; /* peer type */
166     wifi_channel_info_t channel; /* channel information */
167     chanspec_t chanspec; /* chanspec for channel */
168     bool    disable; /* disable for RTT measurement */
169     /*
170     * Time interval between bursts (units: 100 ms).
171     * Applies to 1-sided and 2-sided RTT multi-burst requests.
172     * Range: 0-31, 0: no preference by initiator (2-sided RTT)
173     */
174     uint32    burst_period;
175     /*
176     * Total number of RTT bursts to be executed. It will be
177     * specified in the same way as the parameter "Number of
178     * Burst Exponent" found in the FTM frame format. It
179     * applies to both: 1-sided RTT and 2-sided RTT. Valid
180     * values are 0 to 15 as defined in 802.11mc std.
181     * 0 means single shot
182     * The implication of this parameter on the maximum
183     * number of RTT results is the following:
184     * for 1-sided RTT: max num of RTT results = (2^num_burst)*(num_frames_per_burst)
185     * for 2-sided RTT: max num of RTT results = (2^num_burst)*(num_frames_per_burst - 1)
186     */
187     uint16 num_burst;
188     /*
189     * num of frames per burst.
190     * Minimum value = 1, Maximum value = 31
191     * For 2-sided this equals the number of FTM frames
192     * to be attempted in a single burst. This also
193     * equals the number of FTM frames that the
194     * initiator will request that the responder send
195     * in a single frame
196     */
197     uint32 num_frames_per_burst;
198     /* num of frames in each RTT burst
199      * for single side, measurement result num = frame number
200      * for 2 side RTT, measurement result num  = frame number - 1
201      */
202     uint32 num_retries_per_ftm; /* retry time for RTT measurment frame */
203     /* following fields are only valid for 2 side RTT */
204     uint32 num_retries_per_ftmr;
205     uint8  LCI_request;
206     uint8  LCR_request;
207     /*
208     * Applies to 1-sided and 2-sided RTT. Valid values will
209     * be 2-11 and 15 as specified by the 802.11mc std for
210     * the FTM parameter burst duration. In a multi-burst
211     * request, if responder overrides with larger value,
212     * the initiator will return failure. In a single-burst
213     * request if responder overrides with larger value,
214     * the initiator will sent TMR_STOP to terminate RTT
215     * at the end of the burst_duration it requested.
216     */
217     uint32 burst_duration;
218     uint8  preamble; /* 1 - Legacy, 2 - HT, 4 - VHT */
219     uint8  bw;  /* 5, 10, 20, 40, 80, 160 */
220 } rtt_target_info_t;
221 
222 typedef struct rtt_config_params {
223     int8 rtt_target_cnt;
224     rtt_target_info_t *target_info;
225 } rtt_config_params_t;
226 
227 typedef struct rtt_status_info {
228     dhd_pub_t *dhd;
229     int8 status;   /* current status for the current entry */
230     int8 txchain; /* current device tx chain */
231     int8 mpc; /* indicate we change mpc mode */
232     int pm; /* to save current value of pm */
233     int8 pm_restore; /* flag to reset the old value of pm */
234     int8 cur_idx; /* current entry to do RTT */
235     bool all_cancel; /* cancel all request once we got the cancel requet */
236     uint32 flags; /* indicate whether device is configured as initiator or target */
237     struct capability {
238         int32 proto     :8;
239         int32 feature   :8;
240         int32 preamble  :8;
241         int32 bw        :8;
242     } rtt_capa; /* rtt capability */
243     struct mutex rtt_mutex;
244     rtt_config_params_t rtt_config;
245     struct work_struct work;
246     struct list_head noti_fn_list;
247     struct list_head rtt_results_cache; /* store results for RTT */
248 } rtt_status_info_t;
249 
250 typedef struct rtt_report {
251     struct ether_addr addr;
252     unsigned int burst_num; /* # of burst inside a multi-burst request */
253     unsigned int ftm_num; /* total RTT measurement frames attempted */
254     unsigned int success_num; /* total successful RTT measurement frames */
255     uint8  num_per_burst_peer; /* max number of FTM number per burst the peer support */
256     rtt_reason_t status; /* raging status */
257     /* in s, 11mc only, only for RTT_REASON_FAIL_BUSY_TRY_LATER, 1- 31s */
258     uint8 retry_after_duration;
259     rtt_type_t type; /* rtt type */
260     wifi_rssi_rtt  rssi; /* average rssi in 0.5 dB steps e.g. 143 implies -71.5 dB */
261     wifi_rssi_rtt  rssi_spread; /* rssi spread in 0.5 db steps e.g. 5 implies 2.5 spread */
262     /*
263     * 1-sided RTT: TX rate of RTT frame.
264     * 2-sided RTT: TX rate of initiator's Ack in response to FTM frame.
265     */
266     wifi_rate_t tx_rate;
267     /*
268     * 1-sided RTT: TX rate of Ack from other side.
269     * 2-sided RTT: TX rate of FTM frame coming from responder.
270     */
271     wifi_rate_t rx_rate;
272     wifi_timespan rtt;    /*  round trip time in 0.1 nanoseconds */
273     wifi_timespan rtt_sd;    /* rtt standard deviation in 0.1 nanoseconds */
274     wifi_timespan rtt_spread; /* difference between max and min rtt times recorded */
275     int distance; /* distance in cm (optional) */
276     int distance_sd; /* standard deviation in cm (optional) */
277     int distance_spread; /* difference between max and min distance recorded (optional) */
278     wifi_timestamp ts; /* time of the measurement (in microseconds since boot) */
279     int burst_duration; /* in ms, how long the FW time is to fininish one burst measurement */
280     int negotiated_burst_num; /* Number of bursts allowed by the responder */
281     bcm_tlv_t *LCI; /* LCI Report */
282     bcm_tlv_t *LCR; /* Location Civic Report */
283 } rtt_report_t;
284 #define RTT_REPORT_SIZE (sizeof(rtt_report_t))
285 
286 /* rtt_results_header to maintain rtt result list per mac address */
287 typedef struct rtt_results_header {
288     struct ether_addr peer_mac;
289     uint32 result_cnt;
290     uint32 result_tot_len; /* sum of report_len of rtt_result */
291     struct list_head list;
292     struct list_head result_list;
293 } rtt_results_header_t;
294 
295 /* rtt_result to link all of rtt_report */
296 typedef struct rtt_result {
297     struct list_head list;
298     struct rtt_report report;
299     int32 report_len; /* total length of rtt_report */
300 } rtt_result_t;
301 
302 /* RTT Capabilities */
303 typedef struct rtt_capabilities {
304     uint8 rtt_one_sided_supported;  /* if 1-sided rtt data collection is supported */
305     uint8 rtt_ftm_supported;        /* if ftm rtt data collection is supported */
306     uint8 lci_support;        /* location configuration information */
307     uint8 lcr_support;        /* Civic Location */
308     uint8 preamble_support;         /* bit mask indicate what preamble is supported */
309     uint8 bw_support;               /* bit mask indicate what BW is supported */
310 } rtt_capabilities_t;
311 
312 
313 /* RTT responder information */
314 typedef struct wifi_rtt_responder {
315     wifi_channel_info channel;   /* channel of responder */
316     uint8 preamble;             /* preamble supported by responder */
317 } wifi_rtt_responder_t;
318 
319 typedef void (*dhd_rtt_compl_noti_fn)(void *ctx, void *rtt_data);
320 /* Linux wrapper to call common dhd_rtt_set_cfg */
321 int
322 dhd_dev_rtt_set_cfg(struct net_device *dev, void *buf);
323 
324 int
325 dhd_dev_rtt_cancel_cfg(struct net_device *dev, struct ether_addr *mac_list, int mac_cnt);
326 
327 int
328 dhd_dev_rtt_register_noti_callback(struct net_device *dev, void *ctx,
329     dhd_rtt_compl_noti_fn noti_fn);
330 
331 int
332 dhd_dev_rtt_unregister_noti_callback(struct net_device *dev, dhd_rtt_compl_noti_fn noti_fn);
333 
334 int
335 dhd_dev_rtt_capability(struct net_device *dev, rtt_capabilities_t *capa);
336 
337 #ifdef WL_CFG80211
338 int
339 dhd_dev_rtt_avail_channel(struct net_device *dev, wifi_channel_info *channel_info);
340 #endif /* WL_CFG80211 */
341 
342 int
343 dhd_dev_rtt_enable_responder(struct net_device *dev, wifi_channel_info *channel_info);
344 
345 int
346 dhd_dev_rtt_cancel_responder(struct net_device *dev);
347 /* export to upper layer */
348 chanspec_t
349 dhd_rtt_convert_to_chspec(wifi_channel_info_t channel);
350 
351 int
352 dhd_rtt_idx_to_burst_duration(uint idx);
353 
354 int
355 dhd_rtt_set_cfg(dhd_pub_t *dhd, rtt_config_params_t *params);
356 
357 int
358 dhd_rtt_stop(dhd_pub_t *dhd, struct ether_addr *mac_list, int mac_cnt);
359 
360 
361 int
362 dhd_rtt_register_noti_callback(dhd_pub_t *dhd, void *ctx, dhd_rtt_compl_noti_fn noti_fn);
363 
364 int
365 dhd_rtt_unregister_noti_callback(dhd_pub_t *dhd, dhd_rtt_compl_noti_fn noti_fn);
366 
367 int
368 dhd_rtt_event_handler(dhd_pub_t *dhd, wl_event_msg_t *event, void *event_data);
369 
370 int
371 dhd_rtt_capability(dhd_pub_t *dhd, rtt_capabilities_t *capa);
372 
373 int
374 dhd_rtt_avail_channel(dhd_pub_t *dhd, wifi_channel_info *channel_info);
375 
376 int
377 dhd_rtt_enable_responder(dhd_pub_t *dhd, wifi_channel_info *channel_info);
378 
379 int
380 dhd_rtt_cancel_responder(dhd_pub_t *dhd);
381 
382 int
383 dhd_rtt_init(dhd_pub_t *dhd);
384 
385 int
386 dhd_rtt_deinit(dhd_pub_t *dhd);
387 #endif /* __DHD_RTT_H__ */
388