blob: 794cc26db594d307e3279bf6c8825e0648a6384b [file] [log] [blame]
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07001/*
2 * Sigma Control API DUT (FTM LOC functionality)
3 * Copyright (c) 2016, Qualcomm Atheros, Inc.
4 * All Rights Reserved.
5 * Licensed under the Clear BSD license. See README for more details.
6 */
7
8#include "sigma_dut.h"
9#include <sys/stat.h>
10#include <regex.h>
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -070011#include "wpa_helpers.h"
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070012
13static const char LOC_XML_FILE_PATH[] = "./data/sigma-dut-target.xml";
14
15static const char LOC_LOWI_TEST_DISCOVERY[] = "lowi_test -a -b 2 -n 1";
16static const char LOC_LOWI_TEST_RANGING[] =
17"lowi_test -r ./data/sigma-dut-target.xml -n 1";
18static const char LOC_LOWI_TEST_NEIGHBOR_RPT_REQ[] = "lowi_test -nrr";
19static const char LOC_LOWI_TEST_ANQP_REQ[] = "lowi_test -anqp -mac ";
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -070020static const char WPA_INTERWORKING_ENABLE[] =
21"SET interworking 1";
22static const char WPA_INTERWORKING_DISABLE[] =
23"SET interworking 0";
24static const char WPA_RM_ENABLE[] =
25"VENDOR 1374 74 08000400BD000000";
26static const char WPA_RM_DISABLE[] =
27"VENDOR 1374 74 0800040000000000";
28static const char WPA_ADDRESS_3_ENABLE[] =
29"SET gas_address3 1";
30static const char WPA_ADDRESS_3_DISABLE[] =
31"SET gas_address3 0";
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070032
33#ifndef ETH_ALEN
34#define ETH_ALEN 6
35#endif
36
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070037#define LOC_MAX_RM_FLAGS 10
38#define LOC_RM_FLAG_VAL_ARRAY 2
39
40enum lowi_tst_cmd {
41 LOWI_TST_RANGING = 0,
42 LOWI_TST_NEIGHBOR_REPORT_REQ = 1,
43 LOWI_TST_ANQP_REQ = 2,
44};
45
46struct capi_loc_cmd {
47 unsigned int chan;
48 unsigned int burstExp;
49 unsigned int burstDur;
50 unsigned int minDeltaFtm;
51 unsigned int ptsf;
52 unsigned int asap;
53 unsigned int ftmsPerBurst;
54 unsigned int fmtbw;
55 unsigned int burstPeriod;
56 unsigned int locCivic;
57 unsigned int lci;
58};
59
60
61static int loc_write_xml_file(struct sigma_dut *dut, const char *dst_mac_str,
62 struct capi_loc_cmd *loc_cmd)
63{
64 FILE *xml;
65 unsigned int band, bw, preamble, primary_ch, center_freq;
66
67 xml = fopen(LOC_XML_FILE_PATH, "w");
68 if (!xml) {
69 sigma_dut_print(dut, DUT_MSG_ERROR,
70 "%s - Unable to create the XML file", __func__);
71 return -1;
72 }
73
74 /* Using this following defaults:
75 * default value of band 1
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070076 */
77 band = 1;
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070078
79#define FMT_BW_NO_PREF 0
80#define FMT_BW_HT_20 9
81#define FMT_BW_VHT_20 10
82#define FMT_BW_HT_40 11
83#define FMT_BW_VHT_40 12
84#define FMT_BW_VHT_80 13
85
86#define LOC_BW_20 0
87#define LOC_BW_40 1
88#define LOC_BW_80 2
89#define LOC_PREAMBLE_HT 1
90#define LOC_PREAMBLE_VHT 2
91 switch (loc_cmd->fmtbw) {
92 case FMT_BW_NO_PREF:
93 case FMT_BW_HT_20:
94 bw = LOC_BW_20;
95 preamble = LOC_PREAMBLE_HT;
96 primary_ch = 36;
97 center_freq = 5180;
98 break;
99 case FMT_BW_VHT_20:
100 bw = LOC_BW_20;
101 preamble = LOC_PREAMBLE_VHT;
102 primary_ch = 36;
103 center_freq = 5180;
104 break;
105 case FMT_BW_HT_40:
106 bw = LOC_BW_40;
107 preamble = LOC_PREAMBLE_HT;
108 primary_ch = 36;
109 center_freq = 5190;
110 break;
111 case FMT_BW_VHT_40:
112 bw = LOC_BW_40;
113 preamble = LOC_PREAMBLE_VHT;
114 primary_ch = 36;
115 center_freq = 5190;
116 break;
117 case FMT_BW_VHT_80:
118 bw = LOC_BW_80;
119 preamble = LOC_PREAMBLE_VHT;
120 primary_ch = 36;
121 center_freq = 5210;
122 break;
123 default:
124 sigma_dut_print(dut, DUT_MSG_ERROR,
125 "%s - Bad Format/BW received", __func__);
Srikanth Marepalli5fc02a02018-08-27 12:53:11 +0530126 fclose(xml);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700127 return -1;
128 }
129
130#define LOC_CAPI_DEFAULT_FTMS_PER_BURST 5
131#define LOC_CAPI_DEFAULT_BURST_DUR 10
132 fprintf(xml, "<body>\n");
133 fprintf(xml, " <ranging>\n");
134 fprintf(xml, " <ap>\n");
135 fprintf(xml, " <band>%u</band>\n", band);
136 fprintf(xml, " <rttType>3</rttType>\n");
137 fprintf(xml, " <numFrames>%u</numFrames>\n",
138 LOC_CAPI_DEFAULT_FTMS_PER_BURST);
139 fprintf(xml, " <bw>%u</bw>\n", bw);
140 fprintf(xml, " <preamble>%u</preamble>\n", preamble);
141 fprintf(xml, " <asap>%u</asap>\n", loc_cmd->asap);
142 fprintf(xml, " <lci>%u</lci>\n", loc_cmd->lci);
143 fprintf(xml, " <civic>%u</civic>\n", loc_cmd->locCivic);
144 fprintf(xml, " <burstsexp>%u</burstsexp>\n", loc_cmd->burstExp);
145 fprintf(xml, " <burstduration>%u</burstduration>\n",
146 LOC_CAPI_DEFAULT_BURST_DUR);
147 fprintf(xml, " <burstperiod>%u</burstperiod>\n", 0);
148 /* Use parameters from LOWI cache */
149 fprintf(xml, " <paramControl>%u</paramControl>\n", 0);
priyadharshini gowthaman26357a02016-09-02 11:15:04 -0700150 fprintf(xml, " <ptsftimer>%u</ptsftimer>\n", 0);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700151 fprintf(xml, " <center_freq1>%u</center_freq1>\n", center_freq);
152 fprintf(xml, " <center_freq2>0</center_freq2>\n");
153 fprintf(xml, " <ch>%u</ch>\n", primary_ch);
154 fprintf(xml, " <mac>%s</mac>\n", dst_mac_str);
155 fprintf(xml, " </ap>\n");
156 fprintf(xml, " </ranging>\n");
157 fprintf(xml, " <summary>\n");
158 fprintf(xml, " <mac>%s</mac>\n", dst_mac_str);
159 fprintf(xml, " </summary>\n");
160 fprintf(xml, "</body>\n");
161
162 fclose(xml);
163 sigma_dut_print(dut, DUT_MSG_INFO,
164 "%s - Successfully created XML file", __func__);
165 return 0;
166}
167
168
169static int pass_request_to_ltest(struct sigma_dut *dut, enum lowi_tst_cmd cmd,
170 const char *params)
171{
172#define MAX_ANQP_CMND_SIZE 256
173 int ret;
174 const char *cmd_str;
175 char lowi_anqp_query[MAX_ANQP_CMND_SIZE];
176
177 switch (cmd) {
178 case LOWI_TST_RANGING:
179 cmd_str = LOC_LOWI_TEST_RANGING;
180 break;
181 case LOWI_TST_NEIGHBOR_REPORT_REQ:
182 cmd_str = LOC_LOWI_TEST_NEIGHBOR_RPT_REQ;
183 break;
184 case LOWI_TST_ANQP_REQ:
185 if (!params) {
186 sigma_dut_print(dut, DUT_MSG_ERROR,
187 "%s - No Destination Mac provided for ANQP Query",
188 __func__);
189 return -1;
190 }
191
192 sigma_dut_print(dut, DUT_MSG_INFO,
193 "%s - Destination Mac provided for ANQP Query: %s",
194 __func__, params);
195
196 snprintf(lowi_anqp_query, MAX_ANQP_CMND_SIZE, "%s%s",
197 LOC_LOWI_TEST_ANQP_REQ, params);
198 cmd_str = lowi_anqp_query;
199 break;
200 default:
201 cmd_str = LOC_LOWI_TEST_DISCOVERY;
202 break;
203 }
204
205 sigma_dut_print(dut, DUT_MSG_INFO, "%s - 1 - Running command: %s",
206 __func__, LOC_LOWI_TEST_DISCOVERY);
207 ret = system(LOC_LOWI_TEST_DISCOVERY);
208 sigma_dut_print(dut, DUT_MSG_INFO,
209 "%s - Finished Performing Discovery Scan through LOWI_test: ret: %d",
210 __func__, ret);
211 sleep(1);
212 sigma_dut_print(dut, DUT_MSG_INFO, "%s - 2 - Running command: %s",
213 __func__, cmd_str);
214 ret = system(cmd_str);
215 sigma_dut_print(dut, DUT_MSG_INFO,
216 "%s - Finished Performing command: %s, got ret: %d",
217 __func__, cmd_str, ret);
218
219 return ret;
220}
221
222
223int loc_cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
224 struct sigma_cmd *cmd)
225{
226 const char *params = NULL;
227 enum lowi_tst_cmd cmnd = LOWI_TST_RANGING;
vamsi krishnae7df6d82018-05-23 10:37:30 +0530228 const char *program = get_param(cmd, "prog");
229 const char *loc_op = get_param(cmd, "Trigger");
230 const char *interface = get_param(cmd, "interface");
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700231
vamsi krishnae7df6d82018-05-23 10:37:30 +0530232 const char *destMacStr = get_param(cmd, "destmac");
233 const char *burstExp = get_param(cmd, "burstsexponent");
234 const char *asap = get_param(cmd, "ASAP");
235 const char *fmtbw = get_param(cmd, "formatbwftm");
236 const char *locCivic = get_param(cmd, "askforloccivic");
237 const char *lci = get_param(cmd, "askforlci");
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700238 struct capi_loc_cmd loc_cmd;
239
240 memset(&loc_cmd, 0, sizeof(loc_cmd));
241
242 if (!loc_op) {
243 sigma_dut_print(dut, DUT_MSG_ERROR,
244 "%s - No Operation! - Aborting", __func__);
245 return -1;
246 }
247
vamsi krishnae7df6d82018-05-23 10:37:30 +0530248 cmnd = strcasecmp(loc_op, "ANQPQuery") == 0 ?
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700249 LOWI_TST_ANQP_REQ : LOWI_TST_RANGING;
250 sigma_dut_print(dut, DUT_MSG_INFO, "%s - Going to perform: %s",
251 __func__, loc_op);
252
253 if (!program) {
254 sigma_dut_print(dut, DUT_MSG_ERROR,
255 "%s - No Program in Command! - Aborting",
256 __func__);
257 return -1;
258 }
259
260 if (!interface) {
261 sigma_dut_print(dut, DUT_MSG_ERROR,
262 "%s - Incomplete command in LOC CAPI request",
263 __func__);
264 send_resp(dut, conn, SIGMA_ERROR,
265 "ErrMsg,Incomplete Loc CAPI command - missing interface");
266 return 0;
267 }
268
269 if (!destMacStr) {
270 sigma_dut_print(dut, DUT_MSG_ERROR,
271 "%s - Incomplete command in LOC CAPI request",
272 __func__);
273 send_resp(dut, conn, SIGMA_ERROR,
274 "ErrMsg,Incomplete Loc CAPI command - missing MAC");
275 return 0;
276 }
277
278 if (cmnd == LOWI_TST_RANGING) {
279 sigma_dut_print(dut, DUT_MSG_INFO, "%s - LOWI_TST_RANGING",
280 __func__);
281 if (!burstExp) {
282 sigma_dut_print(dut, DUT_MSG_ERROR,
283 "%s - Incomplete command in LOC CAPI request",
284 __func__);
285 send_resp(dut, conn, SIGMA_ERROR,
286 "ErrMsg,Incomplete Loc CAPI command - missing Burst Exp");
287 return 0;
288 }
289
290 if (!asap) {
291 sigma_dut_print(dut, DUT_MSG_INFO,
292 "%s - Incomplete command in LOC CAPI request",
293 __func__);
294 send_resp(dut, conn, SIGMA_ERROR,
295 "ErrMsg,Incomplete Loc CAPI command - missing ASAP");
296 return 0;
297 }
298
299 if (!fmtbw) {
300 sigma_dut_print(dut, DUT_MSG_ERROR,
301 "%s - Incomplete command in LOC CAPI request",
302 __func__);
303 send_resp(dut, conn, SIGMA_ERROR,
304 "ErrMsg,Incomplete Loc CAPI command - missing Format & BW");
305 return 0;
306 }
307
308 if (!locCivic) {
309 sigma_dut_print(dut, DUT_MSG_ERROR,
310 "%s - Incomplete command in LOC CAPI request",
311 __func__);
312 send_resp(dut, conn, SIGMA_ERROR,
313 "ErrMsg,Incomplete Loc CAPI command - missing Location Civic");
314 return 0;
315 }
316
317 if (!lci) {
318 sigma_dut_print(dut, DUT_MSG_ERROR,
319 "%s - Incomplete command in LOC CAPI request",
320 __func__);
321 send_resp(dut, conn, SIGMA_ERROR,
322 "ErrMsg,Incomplete Loc CAPI command - missing LCI");
323 return 0;
324 }
325
vamsi krishnae7df6d82018-05-23 10:37:30 +0530326 if (strcasecmp(program, "loc") != 0) {
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700327 sigma_dut_print(dut, DUT_MSG_ERROR,
328 "%s - Unsupported Program: %s",
329 __func__, program);
330 send_resp(dut, conn, SIGMA_ERROR,
331 "ErrMsg,Unsupported program");
332 return 0;
333 }
334
vamsi krishnae7df6d82018-05-23 10:37:30 +0530335 if (strcasecmp(interface, "wlan0") != 0) {
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700336 sigma_dut_print(dut, DUT_MSG_INFO,
337 "%s - Unsupported Interface Type: %s",
338 __func__, interface);
339 send_resp(dut, conn, SIGMA_ERROR,
340 "ErrMsg,Unsupported Interface Type");
341 return 0;
342 }
343
344 sscanf(burstExp, "%u", &loc_cmd.burstExp);
345 sigma_dut_print(dut, DUT_MSG_INFO, "%s - burstExp: %u",
346 __func__, loc_cmd.burstExp);
347 sscanf(asap, "%u", &loc_cmd.asap);
348 sigma_dut_print(dut, DUT_MSG_INFO, "%s - asap: %u",
349 __func__, loc_cmd.asap);
350 sscanf(fmtbw, "%u", &loc_cmd.fmtbw);
351 sigma_dut_print(dut, DUT_MSG_INFO, "%s - fmtbw: %u",
352 __func__, loc_cmd.fmtbw);
353 sscanf(locCivic, "%u", &loc_cmd.locCivic);
354 sigma_dut_print(dut, DUT_MSG_INFO, "%s - locCivic: %u",
355 __func__, loc_cmd.locCivic);
356 sscanf(lci, "%u", &loc_cmd.lci);
357 sigma_dut_print(dut, DUT_MSG_INFO, "%s - lci: %u",
358 __func__, loc_cmd.lci);
359
360 if (loc_write_xml_file(dut, destMacStr, &loc_cmd) < 0) {
361 sigma_dut_print(dut, DUT_MSG_ERROR,
362 "%s - Failed to write to XML file because of bad command",
363 __func__);
364 send_resp(dut, conn, SIGMA_ERROR,
365 "ErrMsg,Bad CAPI command");
366 return 0;
367 }
368 } else {
369 /* ANQP Query */
370 sigma_dut_print(dut, DUT_MSG_INFO,
371 "%s - LOWI_TST_ANQP_REQ", __func__);
372 params = destMacStr;
373 }
374
375 if (pass_request_to_ltest(dut, cmnd, params) < 0) {
376 /* Loc operation been failed. */
377 sigma_dut_print(dut, DUT_MSG_ERROR,
378 "%s - Failed to initiate Loc command",
379 __func__);
380 send_resp(dut, conn, SIGMA_ERROR,
381 "ErrMsg,Failed to initiate Loc command");
382 return 0;
383 }
384
385 sigma_dut_print(dut, DUT_MSG_INFO,
386 "%s - Succeeded to initiate Loc command", __func__);
387 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
388 return 0;
389}
390
391
392int loc_cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
393 struct sigma_cmd *cmd)
394{
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700395 const char *address3Cmnd = WPA_ADDRESS_3_DISABLE;
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700396 enum lowi_tst_cmd cmnd = LOWI_TST_NEIGHBOR_REPORT_REQ; /* Default */
397 /* Mandatory arguments */
vamsi krishnae7df6d82018-05-23 10:37:30 +0530398 const char *interface = get_param(cmd, "interface");
399 const char *program = get_param(cmd, "program");
400 const char *destMacStr = get_param(cmd, "destmac");
401 const char *frameName = get_param(cmd, "FrameName");
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700402
403 /* Optional Arguments */
vamsi krishnae7df6d82018-05-23 10:37:30 +0530404 const char *locCivic = get_param(cmd, "askforloccivic");
405 const char *lci = get_param(cmd, "askforlci");
406 const char *fqdn = get_param(cmd, "AskForPublicIdentifierURI-FQDN");
407 const char *address3 = get_param(cmd, "address3");
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700408
409 const char *params = NULL;
410
411 if (!program) {
412 sigma_dut_print(dut, DUT_MSG_ERROR,
413 "%s - No Program in Command! - Aborting",
414 __func__);
415 return -1;
416 }
417
418 if (!interface) {
419 sigma_dut_print(dut, DUT_MSG_ERROR,
420 "%s - Incomplete command in LOC CAPI request",
421 __func__);
422 send_resp(dut, conn, SIGMA_ERROR, NULL);
423 return 0;
424 }
425
426 if (!frameName) {
427 sigma_dut_print(dut, DUT_MSG_ERROR,
428 "%s - Incomplete command in LOC CAPI request",
429 __func__);
430 send_resp(dut, conn, SIGMA_ERROR, NULL);
431 return 0;
432 }
433
vamsi krishnae7df6d82018-05-23 10:37:30 +0530434 if (strcasecmp(frameName, "AnqpQuery") == 0 && !destMacStr) {
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700435 sigma_dut_print(dut, DUT_MSG_ERROR,
436 "%s - Incomplete command in LOC CAPI request",
437 __func__);
438 send_resp(dut, conn, SIGMA_ERROR, NULL);
439 return 0;
440 }
441
442 if (!locCivic)
443 sigma_dut_print(dut, DUT_MSG_ERROR,
444 "%s - Command missing LocCivic", __func__);
445 if (!lci)
446 sigma_dut_print(dut, DUT_MSG_ERROR,
447 "%s - Command missing LCI", __func__);
448 if (!fqdn)
449 sigma_dut_print(dut, DUT_MSG_ERROR,
450 "%s - Command missing FQDN", __func__);
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700451 if (!address3) {
452 sigma_dut_print(dut, DUT_MSG_ERROR,
453 "%s - Command missing address3", __func__);
454 } else {
455 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s - address3: %s",
456 __func__, address3);
vamsi krishnae7df6d82018-05-23 10:37:30 +0530457 if (strcasecmp(address3, "FF:FF:FF:FF:FF:FF") == 0)
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700458 address3Cmnd = WPA_ADDRESS_3_ENABLE;
459 else
460 address3Cmnd = WPA_ADDRESS_3_DISABLE;
461 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700462
vamsi krishnae7df6d82018-05-23 10:37:30 +0530463 if (strcasecmp(program, "loc") != 0) {
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700464 sigma_dut_print(dut, DUT_MSG_ERROR,
465 "%s - Unsupported Program: %s", __func__,
466 program);
467 send_resp(dut, conn, SIGMA_ERROR, NULL);
468 return 0;
469 }
470
471 sigma_dut_print(dut, DUT_MSG_INFO, "%s - Triggering Frame: %s",
472 __func__, frameName);
vamsi krishnae7df6d82018-05-23 10:37:30 +0530473 if (strcasecmp(frameName, "AnqpQuery") == 0) {
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700474 cmnd = LOWI_TST_ANQP_REQ;
475 params = destMacStr;
476 } else {
477 cmnd = LOWI_TST_NEIGHBOR_REPORT_REQ;
478 }
479
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700480 if (cmnd == LOWI_TST_ANQP_REQ) {
481 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s - Executing command %s",
482 __func__, address3Cmnd);
Jouni Malinen016ae6c2019-11-04 17:00:01 +0200483 if (wpa_command(get_station_ifname(dut), address3Cmnd) < 0) {
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700484 send_resp(dut, conn, SIGMA_ERROR, NULL);
485 return -1;
486 }
487 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700488 if (pass_request_to_ltest(dut, cmnd, params) < 0) {
489 /* Loc operation has failed. */
490 sigma_dut_print(dut, DUT_MSG_ERROR,
491 "%s - Failed to initiate Loc command",
492 __func__);
493 send_resp(dut, conn, SIGMA_ERROR, NULL);
494 return 0;
495 }
496
497 sigma_dut_print(dut, DUT_MSG_INFO,
498 "%s - Succeeded to initiate Loc command", __func__);
499 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
500 return 0;
501}
502
503
504enum e_rm_parse_states {
505 LOC_LOOKING_FOR_BIT = 0,
506 LOC_LOOKING_FOR_VAL,
507 LOC_MAX
508};
509
510
511void parse_rm_bits(struct sigma_dut *dut, const char *rmFlags,
512 char rmBitFlags[LOC_MAX_RM_FLAGS][LOC_RM_FLAG_VAL_ARRAY])
513{
514
515 unsigned int bitPos = 0;
516 unsigned int bitVal = 0;
517 unsigned int idx = 0;
518 unsigned int i = 0;
519 enum e_rm_parse_states rmParseStates = LOC_LOOKING_FOR_BIT;
520 char temp = '\0';
521
522 if (!rmFlags) {
523 sigma_dut_print(dut, DUT_MSG_ERROR,
524 "%s - NULL pointer for rmFlags - Aborting", __func__);
525 return;
526 }
527
528 sigma_dut_print(dut, DUT_MSG_INFO, "%s - rmFlags: %s",
529 __func__, rmFlags);
530 while (*rmFlags != '\0' && idx < LOC_MAX_RM_FLAGS) {
531 temp = *rmFlags;
532 rmFlags++;
533 switch (rmParseStates) {
534 case LOC_LOOKING_FOR_BIT:
535 if (temp >= '0' && temp <= '9') {
536 /* Parse Digit for bit Position */
537 bitPos = (bitPos * 10) + (temp - '0');
538 sigma_dut_print(dut, DUT_MSG_INFO,
539 "%s - LOC_LOOKING_FOR_BIT - parsing: %c, bitPos: %u",
540 __func__, temp, bitPos);
541 } else if (temp == ':') {
542 /* move to Parsing Bit Value */
543 sigma_dut_print(dut, DUT_MSG_INFO,
544 "%s - LOC_LOOKING_FOR_BIT - processing: %c, bitPos: %u",
545 __func__, temp, bitPos);
546 rmBitFlags[idx][0] = bitPos;
547 rmParseStates = LOC_LOOKING_FOR_VAL;
548 } else if (temp == ';') {
549 /* End of Bit-Value Pair, reset and look for New Bit Position */
550 sigma_dut_print(dut, DUT_MSG_INFO,
551 "%s - LOC_LOOKING_FOR_BIT - processing: %c",
552 __func__, temp);
553 rmBitFlags[idx][0] = bitPos;
554 /* rmBitFlags[idx][1] = bitVal; */
555 bitPos = 0;
556 bitVal = 0;
557 idx++;
558 } else { /* Ignore */
559 sigma_dut_print(dut, DUT_MSG_INFO,
560 "%s - LOC_LOOKING_FOR_BIT - ignoring: %c",
561 __func__, temp);
562 }
563 break;
564 case LOC_LOOKING_FOR_VAL:
565 if (temp == '0' || temp == '1') {
566 sigma_dut_print(dut, DUT_MSG_INFO,
567 "%s - LOC_LOOKING_FOR_VAL - processing: %c",
568 __func__, temp);
569 bitVal = temp - '0';
570 rmBitFlags[idx][1] = bitVal;
571 } else if (temp == ';') {
572 sigma_dut_print(dut, DUT_MSG_INFO,
573 "%s - LOC_LOOKING_FOR_VAL - processing: %c, bitPos: %u, bitVal: %u",
574 __func__, temp, bitPos, bitVal);
575 /* rmBitFlags[idx][0] = bitPos; */
576 /* rmBitFlags[idx][1] = bitVal; */
577 bitPos = 0;
578 bitVal = 0;
579 idx++;
580 rmParseStates = LOC_LOOKING_FOR_BIT;
581 } else { /* Ignore */
582 sigma_dut_print(dut, DUT_MSG_INFO,
583 "%s - LOC_LOOKING_FOR_VAL - ignoring: %c",
584 __func__, temp);
585 }
586 break;
587 default: /* Ignore */
588 sigma_dut_print(dut, DUT_MSG_INFO,
589 "%s - default - ignoring: %c",
590 __func__, temp);
591 break;
592 }
593 }
594
595 for (i = 0; i < LOC_MAX_RM_FLAGS; i++) {
596 sigma_dut_print(dut, DUT_MSG_INFO,
597 "%s - Bit Pos: %u : Bit Val: %u",
598 __func__, rmBitFlags[i][0],
599 rmBitFlags[i][1]);
600 }
601}
602
603
604int loc_cmd_sta_preset_testparameters(struct sigma_dut *dut,
605 struct sigma_conn *conn,
606 struct sigma_cmd *cmd)
607{
vamsi krishnae7df6d82018-05-23 10:37:30 +0530608 const char *rmFTMRFlagStr = get_param(cmd, "RMEnabledCapBitmap");
609 const char *interworkingEn = get_param(cmd, "Interworking");
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700610 unsigned int rmFTMRFlag = 0;
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700611 unsigned int i, interworking = 0;
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700612 char rmBitFlags[LOC_MAX_RM_FLAGS][LOC_RM_FLAG_VAL_ARRAY];
613
614 sigma_dut_print(dut, DUT_MSG_INFO, "%s", __func__);
615
616 memset(rmBitFlags, 0, sizeof(rmBitFlags));
617
618 sigma_dut_print(dut, DUT_MSG_INFO, "%s - 1", __func__);
619 /*
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700620 * This function is used to configure the RM capability bits and
621 * the Interworking bit only.
622 * If these parameters are not present just returning COMPLETE
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700623 * because all other parameters are ignored.
624 */
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700625 if (!rmFTMRFlagStr && !interworkingEn) {
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700626 sigma_dut_print(dut, DUT_MSG_INFO, "%s - 2", __func__);
627 sigma_dut_print(dut, DUT_MSG_ERROR, "%s - Did not get %s",
vamsi krishnae7df6d82018-05-23 10:37:30 +0530628 __func__, "RMEnabledCapBitmap");
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700629 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
630 return 0;
631 }
632
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700633 if (rmFTMRFlagStr) {
634 rmFTMRFlag = 25; /* Default invalid */
635 sigma_dut_print(dut, DUT_MSG_INFO, "%s - rmFTMRFlagStr: %s",
636 __func__, rmFTMRFlagStr);
637 parse_rm_bits(dut, rmFTMRFlagStr, rmBitFlags);
638 for (i = 0; i < LOC_MAX_RM_FLAGS; i++) {
639 if (rmBitFlags[i][0] == 34)
640 rmFTMRFlag = rmBitFlags[i][1];
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700641 }
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700642 sigma_dut_print(dut, DUT_MSG_INFO, "%s - rmFTMRFlag %u",
643 __func__, rmFTMRFlag);
644 if (rmFTMRFlag == 0) { /* Disable RM - FTMRR capability */
645 sigma_dut_print(dut, DUT_MSG_INFO,
646 "%s - Disabling RM - FTMRR",
647 __func__);
Jouni Malinen016ae6c2019-11-04 17:00:01 +0200648 if (wpa_command(get_station_ifname(dut),
649 WPA_RM_DISABLE) < 0) {
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700650 send_resp(dut, conn, SIGMA_ERROR, NULL);
651 return -1;
652 }
653 } else if (rmFTMRFlag == 1) { /* Enable RM - FTMRR capability */
654 sigma_dut_print(dut, DUT_MSG_INFO,
655 "%s - Enabling RM - FTMRR",
656 __func__);
Jouni Malinen016ae6c2019-11-04 17:00:01 +0200657 if (wpa_command(get_station_ifname(dut),
658 WPA_RM_ENABLE) < 0) {
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700659 send_resp(dut, conn, SIGMA_ERROR, NULL);
660 return 0;
661 }
662 } else {
663 sigma_dut_print(dut, DUT_MSG_ERROR,
664 "%s - No Setting for - FTMRR",
665 __func__);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700666 }
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700667 sigma_dut_print(dut, DUT_MSG_INFO,
668 "%s - Succeeded in Enabling/Disabling RM Capability for FTMRR",
669 __func__);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700670 }
671
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700672 if (interworkingEn) {
673 sscanf(interworkingEn, "%u", &interworking);
674 sigma_dut_print(dut, DUT_MSG_INFO, "%s - interworking: %u",
675 __func__, interworking);
676 if (interworking)
Jouni Malinen016ae6c2019-11-04 17:00:01 +0200677 wpa_command(get_station_ifname(dut),
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700678 WPA_INTERWORKING_ENABLE);
679 else
Jouni Malinen016ae6c2019-11-04 17:00:01 +0200680 wpa_command(get_station_ifname(dut),
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700681 WPA_INTERWORKING_DISABLE);
682 }
683
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700684 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
685 return 0;
686}
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +0530687
688
689int lowi_cmd_sta_reset_default(struct sigma_dut *dut, struct sigma_conn *conn,
690 struct sigma_cmd *cmd)
691{
692#ifdef ANDROID_WIFI_HAL
693 if (wifi_hal_initialize(dut)) {
694 sigma_dut_print(dut, DUT_MSG_ERROR,
695 "%s - wifihal init failed for - LOC",
696 __func__);
697 return -1;
698 }
699#endif /* ANDROID_WIFI_HAL */
700
701 return 0;
702}