Commit | Line | Data |
---|---|---|
7753f181 DD |
1 | #include <stdint.h> |
2 | #include <fcntl.h> | |
3 | #include <sys/socket.h> | |
4 | #include <netlink/genl/genl.h> | |
5 | #include <netlink/genl/family.h> | |
6 | #include <netlink/genl/ctrl.h> | |
7 | #include <linux/rtnetlink.h> | |
8 | #include <netpacket/packet.h> | |
9 | #include <linux/filter.h> | |
10 | #include <linux/errqueue.h> | |
11 | ||
12 | #include <linux/pkt_sched.h> | |
13 | #include <netlink/object-api.h> | |
14 | #include <netlink/netlink.h> | |
15 | #include <netlink/socket.h> | |
7753f181 | 16 | |
47e18f37 | 17 | #include <string> |
7753f181 DD |
18 | #include "nl80211_copy.h" |
19 | ||
20 | #include "sync.h" | |
21 | ||
7753f181 DD |
22 | #include <utils/Log.h> |
23 | ||
24 | #include "wifi_hal.h" | |
25 | #include "common.h" | |
26 | #include "cpp_bindings.h" | |
47e18f37 JPS |
27 | using namespace std; |
28 | ||
29 | typedef enum { | |
30 | SLSI_RTT_ATTRIBUTE_TARGET_CNT = 0, | |
31 | SLSI_RTT_ATTRIBUTE_TARGET_INFO, | |
32 | SLSI_RTT_ATTRIBUTE_TARGET_MAC, | |
33 | SLSI_RTT_ATTRIBUTE_TARGET_TYPE, | |
34 | SLSI_RTT_ATTRIBUTE_TARGET_PEER, | |
47e18f37 | 35 | SLSI_RTT_ATTRIBUTE_TARGET_CHAN_FREQ, |
47e18f37 JPS |
36 | SLSI_RTT_ATTRIBUTE_TARGET_PERIOD, |
37 | SLSI_RTT_ATTRIBUTE_TARGET_NUM_BURST, | |
38 | SLSI_RTT_ATTRIBUTE_TARGET_NUM_FTM_BURST, | |
39 | SLSI_RTT_ATTRIBUTE_TARGET_NUM_RETRY_FTM, | |
40 | SLSI_RTT_ATTRIBUTE_TARGET_NUM_RETRY_FTMR, | |
41 | SLSI_RTT_ATTRIBUTE_TARGET_LCI, | |
42 | SLSI_RTT_ATTRIBUTE_TARGET_LCR, | |
43 | SLSI_RTT_ATTRIBUTE_TARGET_BURST_DURATION, | |
44 | SLSI_RTT_ATTRIBUTE_TARGET_PREAMBLE, | |
45 | SLSI_RTT_ATTRIBUTE_TARGET_BW, | |
46 | SLSI_RTT_ATTRIBUTE_RESULTS_COMPLETE = 30, | |
47 | SLSI_RTT_ATTRIBUTE_RESULTS_PER_TARGET, | |
48 | SLSI_RTT_ATTRIBUTE_RESULT_CNT, | |
49 | SLSI_RTT_ATTRIBUTE_RESULT, | |
50 | SLSI_RTT_ATTRIBUTE_TARGET_ID | |
51 | } SLSI_RTT_ATTRIBUTE; | |
52 | ||
53 | enum slsi_rtt_event_attributes { | |
54 | SLSI_RTT_EVENT_ATTR_ADDR = 0, | |
55 | SLSI_RTT_EVENT_ATTR_BURST_NUM, | |
56 | SLSI_RTT_EVENT_ATTR_MEASUREMENT_NUM, | |
57 | SLSI_RTT_EVENT_ATTR_SUCCESS_NUM, | |
58 | SLSI_RTT_EVENT_ATTR_NUM_PER_BURST_PEER, | |
59 | SLSI_RTT_EVENT_ATTR_STATUS, | |
60 | SLSI_RTT_EVENT_ATTR_RETRY_AFTER_DURATION, | |
61 | SLSI_RTT_EVENT_ATTR_TYPE, | |
62 | SLSI_RTT_EVENT_ATTR_RSSI, | |
63 | SLSI_RTT_EVENT_ATTR_RSSI_SPREAD, | |
64 | SLSI_RTT_EVENT_ATTR_TX_PREAMBLE, | |
65 | SLSI_RTT_EVENT_ATTR_TX_NSS, | |
66 | SLSI_RTT_EVENT_ATTR_TX_BW, | |
67 | SLSI_RTT_EVENT_ATTR_TX_MCS, | |
68 | SLSI_RTT_EVENT_ATTR_TX_RATE, | |
69 | SLSI_RTT_EVENT_ATTR_RX_PREAMBLE, | |
70 | SLSI_RTT_EVENT_ATTR_RX_NSS, | |
71 | SLSI_RTT_EVENT_ATTR_RX_BW, | |
72 | SLSI_RTT_EVENT_ATTR_RX_MCS, | |
73 | SLSI_RTT_EVENT_ATTR_RX_RATE, | |
74 | SLSI_RTT_EVENT_ATTR_RTT, | |
75 | SLSI_RTT_EVENT_ATTR_RTT_SD, | |
76 | SLSI_RTT_EVENT_ATTR_RTT_SPREAD, | |
77 | SLSI_RTT_EVENT_ATTR_DISTANCE_MM, | |
78 | SLSI_RTT_EVENT_ATTR_DISTANCE_SD_MM, | |
79 | SLSI_RTT_EVENT_ATTR_DISTANCE_SPREAD_MM, | |
80 | SLSI_RTT_EVENT_ATTR_TIMESTAMP_US, | |
81 | SLSI_RTT_EVENT_ATTR_BURST_DURATION_MSN, | |
82 | SLSI_RTT_EVENT_ATTR_NEGOTIATED_BURST_NUM, | |
83 | SLSI_RTT_EVENT_ATTR_LCI, | |
84 | SLSI_RTT_EVENT_ATTR_LCR | |
85 | }; | |
86 | ||
87 | struct dot11_rm_ie { | |
88 | u8 id; | |
89 | u8 len; | |
90 | u8 token; | |
91 | u8 mode; | |
92 | u8 type; | |
93 | } __attribute__ ((packed)); | |
94 | typedef struct dot11_rm_ie dot11_rm_ie_t; | |
95 | typedef struct strmap_entry { | |
96 | int id; | |
97 | string text; | |
98 | } strmap_entry_t; | |
99 | ||
100 | static const strmap_entry_t err_info[] = { | |
101 | {RTT_STATUS_SUCCESS, string("Success")}, | |
102 | {RTT_STATUS_FAILURE, string("Failure")}, | |
103 | {RTT_STATUS_FAIL_NO_RSP, string("No reponse")}, | |
104 | {RTT_STATUS_FAIL_INVALID_TS, string("Invalid Timestamp")}, | |
105 | {RTT_STATUS_FAIL_PROTOCOL, string("Protocol error")}, | |
106 | {RTT_STATUS_FAIL_REJECTED, string("Rejected")}, | |
107 | {RTT_STATUS_FAIL_NOT_SCHEDULED_YET, string("not scheduled")}, | |
108 | {RTT_STATUS_FAIL_SCHEDULE, string("schedule failed")}, | |
109 | {RTT_STATUS_FAIL_TM_TIMEOUT, string("timeout")}, | |
110 | {RTT_STATUS_FAIL_AP_ON_DIFF_CHANNEL, string("AP is on difference channel")}, | |
111 | {RTT_STATUS_FAIL_NO_CAPABILITY, string("no capability")}, | |
112 | {RTT_STATUS_FAIL_BUSY_TRY_LATER, string("busy and try later")}, | |
113 | {RTT_STATUS_ABORTED, string("aborted")} | |
114 | }; | |
115 | /*static const string get_err_info(int status) | |
116 | { | |
117 | int i; | |
118 | const strmap_entry_t *p_entry; | |
119 | int num_entries = sizeof(err_info)/ sizeof(err_info[0]); | |
120 | * scan thru the table till end | |
121 | p_entry = err_info; | |
122 | for (i = 0; i < (int) num_entries; i++) | |
123 | { | |
124 | if (p_entry->id == status) | |
125 | return p_entry->text; | |
126 | p_entry++; * next entry | |
127 | } | |
128 | return "unknown error"; * not found | |
129 | }*/ | |
130 | class RttCommand : public WifiCommand | |
131 | { | |
ea44a0c5 | 132 | int rtt_id; |
47e18f37 JPS |
133 | unsigned numTargetDevice; |
134 | int mCompleted; | |
135 | int currentIdx; | |
136 | int totalCnt; | |
137 | static const int MAX_RESULTS = 1024; | |
138 | wifi_rtt_result *rttResults[MAX_RESULTS]; | |
139 | wifi_rtt_config *rttParams; | |
140 | wifi_rtt_event_handler rttHandler; | |
141 | public: | |
142 | RttCommand(wifi_interface_handle iface, int id, unsigned num_rtt_config, | |
143 | wifi_rtt_config rtt_config[], wifi_rtt_event_handler handler) | |
144 | : WifiCommand(iface, id), rtt_id(id), numTargetDevice(num_rtt_config), rttParams(rtt_config), | |
145 | rttHandler(handler) | |
146 | { | |
147 | memset(rttResults, 0, sizeof(rttResults)); | |
148 | currentIdx = 0; | |
149 | mCompleted = 0; | |
150 | totalCnt = 0; | |
151 | } | |
152 | ||
153 | RttCommand(wifi_interface_handle iface, int id) | |
c9af5606 | 154 | : WifiCommand(iface, id), rtt_id(id), rttParams(NULL) |
47e18f37 | 155 | { |
c9af5606 SP |
156 | rttHandler.on_rtt_results = NULL; |
157 | memset(rttResults, 0, sizeof(rttResults)); | |
47e18f37 JPS |
158 | currentIdx = 0; |
159 | mCompleted = 0; | |
160 | totalCnt = 0; | |
161 | numTargetDevice = 0; | |
162 | } | |
163 | int createSetupRequest(WifiRequest& request) { | |
164 | int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_RTT_RANGE_START); | |
165 | if (result < 0) { | |
166 | return result; | |
167 | } | |
168 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA); | |
169 | result = request.put_u16(SLSI_RTT_ATTRIBUTE_TARGET_ID, rtt_id); | |
170 | if (result < 0) { | |
171 | return result; | |
172 | } | |
173 | result = request.put_u8(SLSI_RTT_ATTRIBUTE_TARGET_CNT, numTargetDevice); | |
174 | ALOGI("numTargetDevice %d\n",numTargetDevice); | |
175 | if (result < 0) { | |
176 | return result; | |
177 | } | |
178 | nlattr *rtt_config = request.attr_start(SLSI_RTT_ATTRIBUTE_TARGET_INFO); | |
179 | for (unsigned i = 0; i < numTargetDevice; i++) { | |
180 | nlattr *attr2 = request.attr_start(i); | |
181 | ||
182 | result = request.put_addr(SLSI_RTT_ATTRIBUTE_TARGET_MAC, rttParams[i].addr); | |
183 | ALOGI("mac_addr %p\n",rttParams[i].addr); | |
184 | if (result < 0) { | |
185 | return result; | |
186 | } | |
187 | ||
188 | result = request.put_u16(SLSI_RTT_ATTRIBUTE_TARGET_TYPE, rttParams[i].type); | |
189 | ALOGI("\trtt_type %d\n",rttParams[i].type); | |
190 | if (result < 0) { | |
191 | return result; | |
192 | } | |
193 | ||
194 | result = request.put_u16(SLSI_RTT_ATTRIBUTE_TARGET_PEER, rttParams[i].peer); | |
195 | ALOGI("\trtt_peer %d\n",rttParams[i].peer); | |
196 | if (result < 0) { | |
197 | return result; | |
198 | } | |
199 | result = request.put_u16(SLSI_RTT_ATTRIBUTE_TARGET_CHAN_FREQ, rttParams[i].channel.center_freq); | |
200 | ALOGI("\trtt_ primary channel_freq %d\n",rttParams[i].channel.center_freq); | |
201 | if (result < 0) { | |
202 | return result; | |
47e18f37 JPS |
203 | } |
204 | result = request.put_u8(SLSI_RTT_ATTRIBUTE_TARGET_NUM_BURST, rttParams[i].num_burst); | |
205 | ALOGI("\tnum_burst %d\n",rttParams[i].num_burst); | |
206 | if (result < 0) { | |
207 | return result; | |
208 | } | |
209 | ||
210 | result = request.put_u8(SLSI_RTT_ATTRIBUTE_TARGET_NUM_FTM_BURST, | |
211 | rttParams[i].num_frames_per_burst); | |
212 | ALOGI("\tnum_frames_per_burst %d\n",rttParams[i].num_frames_per_burst); | |
213 | if (result < 0) { | |
214 | return result; | |
215 | } | |
216 | ||
217 | result = request.put_u8(SLSI_RTT_ATTRIBUTE_TARGET_NUM_RETRY_FTM, | |
218 | rttParams[i].num_retries_per_rtt_frame); | |
219 | ALOGI("\tnum_retries_per_rtt_frame %d\n",rttParams[i].num_retries_per_rtt_frame); | |
220 | if (result < 0) { | |
221 | return result; | |
222 | } | |
223 | ||
224 | result = request.put_u8(SLSI_RTT_ATTRIBUTE_TARGET_NUM_RETRY_FTMR, | |
225 | rttParams[i].num_retries_per_ftmr); | |
226 | ALOGI("\tnum_retries_per_ftmr %d\n",rttParams[i].num_retries_per_ftmr); | |
227 | if (result < 0) { | |
228 | return result; | |
229 | } | |
230 | ||
231 | result = request.put_u8(SLSI_RTT_ATTRIBUTE_TARGET_PERIOD, | |
232 | rttParams[i].burst_period); | |
233 | ALOGI("\tburst_period %d\n",rttParams[i].burst_period); | |
234 | if (result < 0) { | |
235 | return result; | |
236 | } | |
237 | ||
238 | result = request.put_u8(SLSI_RTT_ATTRIBUTE_TARGET_BURST_DURATION, | |
239 | rttParams[i].burst_duration); | |
240 | ALOGI("\tburst_duration %d\n",rttParams[i].burst_duration); | |
241 | if (result < 0) { | |
242 | return result; | |
243 | } | |
244 | ||
245 | result = request.put_u16(SLSI_RTT_ATTRIBUTE_TARGET_LCI, | |
246 | rttParams[i].LCI_request); | |
247 | ALOGI("\tLCI_request %d\n",rttParams[i].LCI_request); | |
248 | if (result < 0) { | |
249 | return result; | |
250 | } | |
251 | ||
252 | result = request.put_u16(SLSI_RTT_ATTRIBUTE_TARGET_LCR, | |
253 | rttParams[i].LCR_request); | |
254 | ALOGI("\tLCR_ request%d\n",rttParams[i].LCR_request); | |
255 | if (result < 0) { | |
256 | return result; | |
257 | } | |
258 | ||
259 | result = request.put_u16(SLSI_RTT_ATTRIBUTE_TARGET_BW, | |
260 | rttParams[i].bw); | |
261 | ALOGI("\tBW%d\n",rttParams[i].bw); | |
262 | if (result < 0) { | |
263 | return result; | |
264 | } | |
265 | ||
266 | result = request.put_u16(SLSI_RTT_ATTRIBUTE_TARGET_PREAMBLE, | |
267 | rttParams[i].preamble); | |
268 | ALOGI("\tpreamble%d\n",rttParams[i].preamble); | |
269 | if (result < 0) { | |
270 | return result; | |
271 | } | |
272 | request.attr_end(attr2); | |
273 | } | |
274 | ALOGE("setup request created"); | |
275 | request.attr_end(rtt_config); | |
276 | request.attr_end(data); | |
277 | return WIFI_SUCCESS; | |
278 | } | |
279 | ||
280 | int createTeardownRequest(WifiRequest& request, unsigned num_devices, mac_addr addr[]) { | |
281 | int result = request.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_RTT_RANGE_CANCEL); | |
282 | if (result < 0) { | |
283 | return result; | |
284 | } | |
285 | nlattr *data = request.attr_start(NL80211_ATTR_VENDOR_DATA); | |
286 | request.put_u16(SLSI_RTT_ATTRIBUTE_TARGET_ID, rtt_id); | |
287 | request.put_u16(SLSI_RTT_ATTRIBUTE_TARGET_CNT, num_devices); | |
288 | for(unsigned i = 0; i < num_devices; i++) { | |
289 | result = request.put_addr(SLSI_RTT_ATTRIBUTE_TARGET_MAC, addr[i]); | |
290 | if (result < 0) { | |
291 | return result; | |
292 | } | |
293 | } | |
294 | request.attr_end(data); | |
295 | return result; | |
296 | } | |
297 | int start() { | |
298 | WifiRequest request(familyId(), ifaceId()); | |
299 | int result = createSetupRequest(request); | |
300 | if (result != WIFI_SUCCESS) { | |
301 | ALOGE("failed to create setup request; result = %d", result); | |
302 | return result; | |
303 | } | |
304 | ||
305 | result = requestResponse(request); | |
306 | if (result != WIFI_SUCCESS) { | |
307 | ALOGE("failed to configure RTT setup; result = %d", result); | |
308 | return result; | |
309 | } | |
310 | registerVendorHandler(GOOGLE_OUI, SLSI_RTT_RESULT_EVENT); | |
311 | registerVendorHandler(GOOGLE_OUI, SLSI_RTT_EVENT_COMPLETE); | |
312 | return result; | |
313 | } | |
314 | ||
315 | virtual int cancel() { | |
316 | ALOGD("Stopping RTT"); | |
317 | ||
318 | WifiRequest request(familyId(), ifaceId()); | |
319 | int result = createTeardownRequest(request, 0, NULL); | |
320 | if (result != WIFI_SUCCESS) { | |
321 | ALOGE("failed to create stop request; result = %d", result); | |
322 | } else { | |
323 | result = requestResponse(request); | |
324 | if (result != WIFI_SUCCESS) { | |
325 | ALOGE("failed to stop scan; result = %d", result); | |
326 | } | |
327 | } | |
328 | ALOGE("RTT stopped"); | |
329 | /*This needs to be check */ | |
330 | unregisterVendorHandler(GOOGLE_OUI, SLSI_RTT_RESULT_EVENT); | |
331 | unregisterVendorHandler(GOOGLE_OUI, SLSI_RTT_EVENT_COMPLETE); | |
332 | return WIFI_SUCCESS; | |
333 | } | |
334 | ||
335 | int cancel_specific(unsigned num_devices, mac_addr addr[]) { | |
336 | ALOGE("Stopping RTT specific"); | |
337 | ||
338 | WifiRequest request(familyId(), ifaceId()); | |
339 | int result = createTeardownRequest(request, num_devices, addr); | |
340 | if (result != WIFI_SUCCESS) { | |
341 | ALOGE("failed to create stop request; result = %d", result); | |
342 | } else { | |
343 | result = requestResponse(request); | |
344 | if (result != WIFI_SUCCESS) { | |
345 | ALOGE("failed to stop RTT; result = %d", result); | |
346 | } | |
347 | } | |
348 | ALOGE("Specific RTT stopped"); | |
349 | /*This needs to be check */ | |
350 | unregisterVendorHandler(GOOGLE_OUI, SLSI_RTT_RESULT_EVENT); | |
351 | unregisterVendorHandler(GOOGLE_OUI, SLSI_RTT_EVENT_COMPLETE); | |
352 | return WIFI_SUCCESS; | |
353 | } | |
354 | ||
355 | virtual int handleResponse(WifiEvent& reply) { | |
356 | /* Nothing to do on response! */ | |
357 | return NL_SKIP; | |
358 | } | |
359 | ||
360 | virtual int handleEvent(WifiEvent& event) { | |
361 | currentIdx=0; | |
362 | nlattr *vendor_data = event.get_attribute(NL80211_ATTR_VENDOR_DATA); | |
363 | int event_id = event.get_vendor_subcmd(); | |
364 | ALOGD("Got an RTT event with id:%d\n",event_id); | |
365 | if(event_id == SLSI_RTT_EVENT_COMPLETE) { | |
366 | ALOGD("RTT event complete\n"); | |
367 | unregisterVendorHandler(GOOGLE_OUI, SLSI_RTT_RESULT_EVENT); | |
368 | WifiCommand *cmd = wifi_unregister_cmd(wifiHandle(), id()); | |
369 | if (cmd) | |
370 | cmd->releaseRef(); | |
371 | } else if (event_id == SLSI_RTT_RESULT_EVENT) { | |
372 | int result_cnt = 0; | |
373 | int rtt_id = 0; | |
374 | ALOGD("RTT result event\n"); | |
375 | for (nl_iterator it(vendor_data); it.has_next(); it.next()) { | |
376 | if (it.get_type() == SLSI_RTT_ATTRIBUTE_RESULT_CNT) { | |
377 | result_cnt = it.get_u16(); | |
378 | ALOGD("RTT results count : %d\n", result_cnt); | |
379 | } else if (it.get_type() == SLSI_RTT_ATTRIBUTE_TARGET_ID) { | |
380 | rtt_id = it.get_u16(); | |
381 | ALOGD("RTT target id : %d\n", rtt_id); | |
382 | } else if (it.get_type() == SLSI_RTT_ATTRIBUTE_RESULT) { | |
383 | ALOGD("RTT result attribute : %d\n", SLSI_RTT_ATTRIBUTE_RESULT); | |
384 | rttResults[currentIdx] = (wifi_rtt_result *)malloc(sizeof(wifi_rtt_result)); | |
385 | wifi_rtt_result *rtt_result = rttResults[currentIdx]; | |
386 | if (rtt_result == NULL) { | |
387 | ALOGE("failed to allocate the wifi_rtt_result\n"); | |
388 | unregisterVendorHandler(GOOGLE_OUI, SLSI_RTT_RESULT_EVENT); | |
389 | break; | |
390 | } | |
391 | for(nl_iterator nl_nested_itr((struct nlattr *)it.get()); nl_nested_itr.has_next(); nl_nested_itr.next()) { | |
392 | if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_ADDR) { | |
393 | memcpy(rtt_result->addr, nl_nested_itr.get_data(), nl_nested_itr.get_len()); | |
394 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_BURST_NUM) { | |
395 | rtt_result->burst_num = (unsigned)nl_nested_itr.get_u8(); | |
396 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_MEASUREMENT_NUM) { | |
397 | rtt_result->measurement_number = (unsigned)nl_nested_itr.get_u8(); | |
398 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_SUCCESS_NUM) { | |
399 | rtt_result->success_number = (unsigned)nl_nested_itr.get_u8(); | |
400 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_NUM_PER_BURST_PEER) { | |
ea44a0c5 | 401 | rtt_result->number_per_burst_peer = (unsigned char)nl_nested_itr.get_u8(); |
47e18f37 JPS |
402 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_STATUS) { |
403 | rtt_result->status = (wifi_rtt_status)nl_nested_itr.get_u16(); | |
404 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_RETRY_AFTER_DURATION) { | |
ea44a0c5 | 405 | rtt_result->retry_after_duration = (unsigned char)nl_nested_itr.get_u8(); |
47e18f37 JPS |
406 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_TYPE) { |
407 | rtt_result->type = (wifi_rtt_type)nl_nested_itr.get_u16(); | |
408 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_RSSI) { | |
409 | rtt_result->rssi = (wifi_rssi)nl_nested_itr.get_u16(); | |
410 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_RSSI_SPREAD) { | |
411 | rtt_result->rssi_spread= (wifi_rssi)nl_nested_itr.get_u16(); | |
412 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_TX_PREAMBLE) { | |
413 | rtt_result->tx_rate.preamble = nl_nested_itr.get_u32(); | |
414 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_TX_NSS) { | |
415 | rtt_result->tx_rate.nss = nl_nested_itr.get_u32(); | |
416 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_TX_BW) { | |
417 | rtt_result->tx_rate.bw = nl_nested_itr.get_u32(); | |
418 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_TX_MCS) { | |
419 | rtt_result->tx_rate.rateMcsIdx = nl_nested_itr.get_u32(); | |
420 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_TX_RATE) { | |
421 | rtt_result->tx_rate.bitrate = nl_nested_itr.get_u32(); | |
422 | }else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_RX_PREAMBLE) { | |
423 | rtt_result->rx_rate.preamble = nl_nested_itr.get_u32(); | |
424 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_RX_NSS) { | |
425 | rtt_result->rx_rate.nss = nl_nested_itr.get_u32(); | |
426 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_RX_BW) { | |
427 | rtt_result->rx_rate.bw = nl_nested_itr.get_u32(); | |
428 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_RX_MCS) { | |
429 | rtt_result->rx_rate.rateMcsIdx = nl_nested_itr.get_u32(); | |
430 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_RX_RATE) { | |
431 | rtt_result->rx_rate.bitrate = nl_nested_itr.get_u32(); | |
432 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_RTT) { | |
433 | rtt_result->rtt = (wifi_timespan)nl_nested_itr.get_u32(); | |
434 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_RTT_SD) { | |
435 | rtt_result->rtt_sd = (wifi_timespan)nl_nested_itr.get_u16(); | |
436 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_RTT_SPREAD) { | |
437 | rtt_result->rtt_spread = (wifi_timespan)nl_nested_itr.get_u16(); | |
438 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_DISTANCE_MM) { | |
439 | rtt_result->distance_mm = nl_nested_itr.get_u32(); | |
440 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_DISTANCE_SD_MM) { | |
441 | rtt_result->distance_sd_mm = nl_nested_itr.get_u32(); | |
442 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_DISTANCE_SPREAD_MM) { | |
443 | rtt_result->distance_spread_mm = nl_nested_itr.get_u32(); | |
444 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_TIMESTAMP_US) { | |
445 | rtt_result->ts = (wifi_timestamp)nl_nested_itr.get_u32(); | |
446 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_BURST_DURATION_MSN) { | |
c6066999 | 447 | rtt_result->burst_duration = nl_nested_itr.get_u8(); |
47e18f37 JPS |
448 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_NEGOTIATED_BURST_NUM) { |
449 | rtt_result->negotiated_burst_num = nl_nested_itr.get_u8(); | |
450 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_LCI) { | |
451 | u8 *lci_ie = (u8 *)nl_nested_itr.get_data(); | |
452 | rtt_result->LCI = (wifi_information_element *)malloc(sizeof(wifi_information_element) + nl_nested_itr.get_len() - 2); | |
453 | rtt_result->LCI->id = lci_ie[0]; | |
454 | rtt_result->LCI->len =lci_ie[1]; | |
455 | memcpy(rtt_result->LCI->data, &lci_ie[2], nl_nested_itr.get_len() - 2); | |
456 | } else if (nl_nested_itr.get_type() == SLSI_RTT_EVENT_ATTR_LCR) { | |
457 | u8 *lcr_ie = (u8 *)nl_nested_itr.get_data(); | |
458 | rtt_result->LCR = (wifi_information_element *)malloc(sizeof(wifi_information_element) + nl_nested_itr.get_len() - 2); | |
459 | rtt_result->LCR->id = lcr_ie[0]; | |
460 | rtt_result->LCR->len =lcr_ie[1]; | |
461 | memcpy(rtt_result->LCR->data, &lcr_ie[2], nl_nested_itr.get_len() - 2); | |
462 | } | |
463 | } | |
464 | currentIdx++; | |
465 | } | |
466 | } | |
467 | (*rttHandler.on_rtt_results)(id() ,currentIdx, rttResults); | |
468 | for (int i = 0; i < currentIdx; i++) { | |
469 | free(rttResults[i]); | |
470 | rttResults[i] = NULL; | |
471 | } | |
472 | currentIdx = 0; | |
473 | } | |
474 | ALOGE("Handled response for rtt config"); | |
475 | return NL_SKIP; | |
476 | } | |
477 | }; | |
478 | class GetRttCapabilitiesCommand : public WifiCommand | |
479 | { | |
480 | wifi_rtt_capabilities *mCapabilities; | |
481 | public: | |
482 | GetRttCapabilitiesCommand(wifi_interface_handle iface, wifi_rtt_capabilities *capabitlites) | |
483 | : WifiCommand(iface, 0), mCapabilities(capabitlites) | |
484 | { | |
485 | memset(mCapabilities, 0, sizeof(*mCapabilities)); | |
486 | } | |
487 | ||
488 | virtual int create() { | |
489 | int ret = mMsg.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_RTT_GET_CAPABILITIES); | |
490 | if (ret < 0) { | |
491 | ALOGE("NL message creation failed"); | |
492 | return ret; | |
493 | } | |
494 | ||
495 | return ret; | |
496 | } | |
497 | protected: | |
498 | virtual int handleResponse(WifiEvent& reply) { | |
499 | ||
500 | if (reply.get_cmd() != NL80211_CMD_VENDOR) { | |
501 | ALOGE("Ignoring reply with cmd = %d", reply.get_cmd()); | |
502 | return NL_SKIP; | |
503 | } | |
504 | void *data = reply.get_vendor_data(); | |
505 | int len = reply.get_vendor_data_len(); | |
506 | ||
507 | memcpy(mCapabilities, data, min(len, (int) sizeof(*mCapabilities))); | |
508 | ALOGE("RTT capa response"); | |
509 | return NL_OK; | |
510 | } | |
511 | }; | |
512 | /*class GetRttResponderInfoCommand : public WifiCommand | |
513 | { | |
514 | wifi_rtt_responder* mResponderInfo; | |
515 | public: | |
516 | GetRttResponderInfoCommand(wifi_interface_handle iface, wifi_rtt_responder *responderInfo) | |
517 | : WifiCommand(iface, 0), mResponderInfo(responderInfo) | |
518 | { | |
519 | memset(mResponderInfo, 0 , sizeof(*mResponderInfo)); | |
520 | ||
521 | } | |
522 | ||
523 | virtual int create() { | |
524 | ALOGD("Creating message to get responder info ; iface = %d", mIfaceInfo->id); | |
525 | ||
526 | int ret = mMsg.create(GOOGLE_OUI, SLSI_NL80211_VENDOR_SUBCMD_RTT_GETAVAILCHANNEL); | |
527 | if (ret < 0) { | |
528 | return ret; | |
529 | } | |
530 | ||
531 | // return ret; | |
532 | } | |
533 | ||
534 | protected: | |
535 | virtual int handleResponse(WifiEvent& reply) { | |
536 | ||
537 | ALOGD("In GetRttResponderInfoCommand::handleResponse"); | |
538 | ||
539 | if (reply.get_cmd() != NL80211_CMD_VENDOR) { | |
540 | ALOGD("Ignoring reply with cmd = %d", reply.get_cmd()); | |
541 | return NL_SKIP; | |
542 | } | |
543 | ||
544 | int id = reply.get_vendor_id(); | |
545 | int subcmd = reply.get_vendor_subcmd(); | |
546 | ||
547 | void *data = reply.get_vendor_data(); | |
548 | int len = reply.get_vendor_data_len(); | |
549 | ||
550 | ALOGD("Id = %0x, subcmd = %d, len = %d, expected len = %d", id, subcmd, len, | |
551 | sizeof(*mResponderInfo)); | |
552 | ||
553 | memcpy(mResponderInfo, data, min(len, (int) sizeof(*mResponderInfo))); | |
554 | ||
555 | return NL_OK; | |
556 | } | |
557 | };*/ | |
558 | ||
559 | /* API to request RTT measurement */ | |
7753f181 DD |
560 | wifi_error wifi_rtt_range_request(wifi_request_id id, wifi_interface_handle iface, |
561 | unsigned num_rtt_config, wifi_rtt_config rtt_config[], wifi_rtt_event_handler handler) | |
562 | { | |
47e18f37 JPS |
563 | ALOGE("Inside RTT RANGE range request"); |
564 | wifi_handle handle = getWifiHandle(iface); | |
565 | RttCommand *cmd = new RttCommand(iface, id, num_rtt_config, rtt_config, handler); | |
566 | NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY); | |
567 | wifi_error result = wifi_register_cmd(handle, id, cmd); | |
568 | if (result != WIFI_SUCCESS) { | |
569 | cmd->releaseRef(); | |
570 | return result; | |
571 | } | |
572 | result = (wifi_error)cmd->start(); | |
573 | if (result != WIFI_SUCCESS) { | |
574 | wifi_unregister_cmd(handle, id); | |
575 | cmd->releaseRef(); | |
576 | return result; | |
577 | } | |
578 | ALOGE("wifi range request successfully executed"); | |
579 | return result; | |
7753f181 DD |
580 | } |
581 | ||
582 | /* API to cancel RTT measurements */ | |
583 | wifi_error wifi_rtt_range_cancel(wifi_request_id id, wifi_interface_handle iface, | |
584 | unsigned num_devices, mac_addr addr[]) | |
585 | { | |
47e18f37 JPS |
586 | if (!iface) |
587 | return WIFI_ERROR_UNINITIALIZED; | |
588 | RttCommand *cmd = new RttCommand(iface, id); | |
589 | NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY); | |
590 | cmd->cancel_specific(num_devices, addr); | |
591 | cmd->releaseRef(); | |
592 | return WIFI_SUCCESS; | |
7753f181 DD |
593 | } |
594 | ||
595 | /* API to get RTT capability */ | |
596 | wifi_error wifi_get_rtt_capabilities(wifi_interface_handle iface, | |
597 | wifi_rtt_capabilities *capabilities) | |
598 | { | |
47e18f37 JPS |
599 | ALOGE("Inside get rtt capabilities cap:%p iface:%p", capabilities, iface); |
600 | if (!iface) | |
601 | return WIFI_ERROR_UNINITIALIZED; | |
602 | GetRttCapabilitiesCommand command(iface, capabilities); | |
603 | return (wifi_error) command.requestResponse(); | |
7753f181 | 604 | |
47e18f37 JPS |
605 | } |
606 | /* API to get the responder information */ | |
607 | wifi_error wifi_rtt_get_responder_info(wifi_interface_handle iface, | |
608 | wifi_rtt_responder* responderInfo) | |
609 | { | |
610 | /*GetRttResponderInfoCommand command(iface, responderInfo); | |
611 | return (wifi_error) command.requestResponse();*/ | |
7753f181 | 612 | return WIFI_ERROR_NOT_SUPPORTED; |
47e18f37 | 613 | |
7753f181 | 614 | } |