blob: 40a27e9ebe865fe45515fa7e400d2509b7187259 [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
76 * channel 36
77 * center frequency of 5210
78 */
79 band = 1;
80 primary_ch = 36;
81 center_freq = 5210;
82
83#define FMT_BW_NO_PREF 0
84#define FMT_BW_HT_20 9
85#define FMT_BW_VHT_20 10
86#define FMT_BW_HT_40 11
87#define FMT_BW_VHT_40 12
88#define FMT_BW_VHT_80 13
89
90#define LOC_BW_20 0
91#define LOC_BW_40 1
92#define LOC_BW_80 2
93#define LOC_PREAMBLE_HT 1
94#define LOC_PREAMBLE_VHT 2
95 switch (loc_cmd->fmtbw) {
96 case FMT_BW_NO_PREF:
97 case FMT_BW_HT_20:
98 bw = LOC_BW_20;
99 preamble = LOC_PREAMBLE_HT;
100 primary_ch = 36;
101 center_freq = 5180;
102 break;
103 case FMT_BW_VHT_20:
104 bw = LOC_BW_20;
105 preamble = LOC_PREAMBLE_VHT;
106 primary_ch = 36;
107 center_freq = 5180;
108 break;
109 case FMT_BW_HT_40:
110 bw = LOC_BW_40;
111 preamble = LOC_PREAMBLE_HT;
112 primary_ch = 36;
113 center_freq = 5190;
114 break;
115 case FMT_BW_VHT_40:
116 bw = LOC_BW_40;
117 preamble = LOC_PREAMBLE_VHT;
118 primary_ch = 36;
119 center_freq = 5190;
120 break;
121 case FMT_BW_VHT_80:
122 bw = LOC_BW_80;
123 preamble = LOC_PREAMBLE_VHT;
124 primary_ch = 36;
125 center_freq = 5210;
126 break;
127 default:
128 sigma_dut_print(dut, DUT_MSG_ERROR,
129 "%s - Bad Format/BW received", __func__);
130 return -1;
131 }
132
133#define LOC_CAPI_DEFAULT_FTMS_PER_BURST 5
134#define LOC_CAPI_DEFAULT_BURST_DUR 10
135 fprintf(xml, "<body>\n");
136 fprintf(xml, " <ranging>\n");
137 fprintf(xml, " <ap>\n");
138 fprintf(xml, " <band>%u</band>\n", band);
139 fprintf(xml, " <rttType>3</rttType>\n");
140 fprintf(xml, " <numFrames>%u</numFrames>\n",
141 LOC_CAPI_DEFAULT_FTMS_PER_BURST);
142 fprintf(xml, " <bw>%u</bw>\n", bw);
143 fprintf(xml, " <preamble>%u</preamble>\n", preamble);
144 fprintf(xml, " <asap>%u</asap>\n", loc_cmd->asap);
145 fprintf(xml, " <lci>%u</lci>\n", loc_cmd->lci);
146 fprintf(xml, " <civic>%u</civic>\n", loc_cmd->locCivic);
147 fprintf(xml, " <burstsexp>%u</burstsexp>\n", loc_cmd->burstExp);
148 fprintf(xml, " <burstduration>%u</burstduration>\n",
149 LOC_CAPI_DEFAULT_BURST_DUR);
150 fprintf(xml, " <burstperiod>%u</burstperiod>\n", 0);
151 /* Use parameters from LOWI cache */
152 fprintf(xml, " <paramControl>%u</paramControl>\n", 0);
priyadharshini gowthaman26357a02016-09-02 11:15:04 -0700153 fprintf(xml, " <ptsftimer>%u</ptsftimer>\n", 0);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700154 fprintf(xml, " <center_freq1>%u</center_freq1>\n", center_freq);
155 fprintf(xml, " <center_freq2>0</center_freq2>\n");
156 fprintf(xml, " <ch>%u</ch>\n", primary_ch);
157 fprintf(xml, " <mac>%s</mac>\n", dst_mac_str);
158 fprintf(xml, " </ap>\n");
159 fprintf(xml, " </ranging>\n");
160 fprintf(xml, " <summary>\n");
161 fprintf(xml, " <mac>%s</mac>\n", dst_mac_str);
162 fprintf(xml, " </summary>\n");
163 fprintf(xml, "</body>\n");
164
165 fclose(xml);
166 sigma_dut_print(dut, DUT_MSG_INFO,
167 "%s - Successfully created XML file", __func__);
168 return 0;
169}
170
171
172static int pass_request_to_ltest(struct sigma_dut *dut, enum lowi_tst_cmd cmd,
173 const char *params)
174{
175#define MAX_ANQP_CMND_SIZE 256
176 int ret;
177 const char *cmd_str;
178 char lowi_anqp_query[MAX_ANQP_CMND_SIZE];
179
180 switch (cmd) {
181 case LOWI_TST_RANGING:
182 cmd_str = LOC_LOWI_TEST_RANGING;
183 break;
184 case LOWI_TST_NEIGHBOR_REPORT_REQ:
185 cmd_str = LOC_LOWI_TEST_NEIGHBOR_RPT_REQ;
186 break;
187 case LOWI_TST_ANQP_REQ:
188 if (!params) {
189 sigma_dut_print(dut, DUT_MSG_ERROR,
190 "%s - No Destination Mac provided for ANQP Query",
191 __func__);
192 return -1;
193 }
194
195 sigma_dut_print(dut, DUT_MSG_INFO,
196 "%s - Destination Mac provided for ANQP Query: %s",
197 __func__, params);
198
199 snprintf(lowi_anqp_query, MAX_ANQP_CMND_SIZE, "%s%s",
200 LOC_LOWI_TEST_ANQP_REQ, params);
201 cmd_str = lowi_anqp_query;
202 break;
203 default:
204 cmd_str = LOC_LOWI_TEST_DISCOVERY;
205 break;
206 }
207
208 sigma_dut_print(dut, DUT_MSG_INFO, "%s - 1 - Running command: %s",
209 __func__, LOC_LOWI_TEST_DISCOVERY);
210 ret = system(LOC_LOWI_TEST_DISCOVERY);
211 sigma_dut_print(dut, DUT_MSG_INFO,
212 "%s - Finished Performing Discovery Scan through LOWI_test: ret: %d",
213 __func__, ret);
214 sleep(1);
215 sigma_dut_print(dut, DUT_MSG_INFO, "%s - 2 - Running command: %s",
216 __func__, cmd_str);
217 ret = system(cmd_str);
218 sigma_dut_print(dut, DUT_MSG_INFO,
219 "%s - Finished Performing command: %s, got ret: %d",
220 __func__, cmd_str, ret);
221
222 return ret;
223}
224
225
226int loc_cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
227 struct sigma_cmd *cmd)
228{
229 const char *params = NULL;
230 enum lowi_tst_cmd cmnd = LOWI_TST_RANGING;
vamsi krishnae7df6d82018-05-23 10:37:30 +0530231 const char *program = get_param(cmd, "prog");
232 const char *loc_op = get_param(cmd, "Trigger");
233 const char *interface = get_param(cmd, "interface");
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700234
vamsi krishnae7df6d82018-05-23 10:37:30 +0530235 const char *destMacStr = get_param(cmd, "destmac");
236 const char *burstExp = get_param(cmd, "burstsexponent");
237 const char *asap = get_param(cmd, "ASAP");
238 const char *fmtbw = get_param(cmd, "formatbwftm");
239 const char *locCivic = get_param(cmd, "askforloccivic");
240 const char *lci = get_param(cmd, "askforlci");
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700241 struct capi_loc_cmd loc_cmd;
242
243 memset(&loc_cmd, 0, sizeof(loc_cmd));
244
245 if (!loc_op) {
246 sigma_dut_print(dut, DUT_MSG_ERROR,
247 "%s - No Operation! - Aborting", __func__);
248 return -1;
249 }
250
vamsi krishnae7df6d82018-05-23 10:37:30 +0530251 cmnd = strcasecmp(loc_op, "ANQPQuery") == 0 ?
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700252 LOWI_TST_ANQP_REQ : LOWI_TST_RANGING;
253 sigma_dut_print(dut, DUT_MSG_INFO, "%s - Going to perform: %s",
254 __func__, loc_op);
255
256 if (!program) {
257 sigma_dut_print(dut, DUT_MSG_ERROR,
258 "%s - No Program in Command! - Aborting",
259 __func__);
260 return -1;
261 }
262
263 if (!interface) {
264 sigma_dut_print(dut, DUT_MSG_ERROR,
265 "%s - Incomplete command in LOC CAPI request",
266 __func__);
267 send_resp(dut, conn, SIGMA_ERROR,
268 "ErrMsg,Incomplete Loc CAPI command - missing interface");
269 return 0;
270 }
271
272 if (!destMacStr) {
273 sigma_dut_print(dut, DUT_MSG_ERROR,
274 "%s - Incomplete command in LOC CAPI request",
275 __func__);
276 send_resp(dut, conn, SIGMA_ERROR,
277 "ErrMsg,Incomplete Loc CAPI command - missing MAC");
278 return 0;
279 }
280
281 if (cmnd == LOWI_TST_RANGING) {
282 sigma_dut_print(dut, DUT_MSG_INFO, "%s - LOWI_TST_RANGING",
283 __func__);
284 if (!burstExp) {
285 sigma_dut_print(dut, DUT_MSG_ERROR,
286 "%s - Incomplete command in LOC CAPI request",
287 __func__);
288 send_resp(dut, conn, SIGMA_ERROR,
289 "ErrMsg,Incomplete Loc CAPI command - missing Burst Exp");
290 return 0;
291 }
292
293 if (!asap) {
294 sigma_dut_print(dut, DUT_MSG_INFO,
295 "%s - Incomplete command in LOC CAPI request",
296 __func__);
297 send_resp(dut, conn, SIGMA_ERROR,
298 "ErrMsg,Incomplete Loc CAPI command - missing ASAP");
299 return 0;
300 }
301
302 if (!fmtbw) {
303 sigma_dut_print(dut, DUT_MSG_ERROR,
304 "%s - Incomplete command in LOC CAPI request",
305 __func__);
306 send_resp(dut, conn, SIGMA_ERROR,
307 "ErrMsg,Incomplete Loc CAPI command - missing Format & BW");
308 return 0;
309 }
310
311 if (!locCivic) {
312 sigma_dut_print(dut, DUT_MSG_ERROR,
313 "%s - Incomplete command in LOC CAPI request",
314 __func__);
315 send_resp(dut, conn, SIGMA_ERROR,
316 "ErrMsg,Incomplete Loc CAPI command - missing Location Civic");
317 return 0;
318 }
319
320 if (!lci) {
321 sigma_dut_print(dut, DUT_MSG_ERROR,
322 "%s - Incomplete command in LOC CAPI request",
323 __func__);
324 send_resp(dut, conn, SIGMA_ERROR,
325 "ErrMsg,Incomplete Loc CAPI command - missing LCI");
326 return 0;
327 }
328
vamsi krishnae7df6d82018-05-23 10:37:30 +0530329 if (strcasecmp(program, "loc") != 0) {
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700330 sigma_dut_print(dut, DUT_MSG_ERROR,
331 "%s - Unsupported Program: %s",
332 __func__, program);
333 send_resp(dut, conn, SIGMA_ERROR,
334 "ErrMsg,Unsupported program");
335 return 0;
336 }
337
vamsi krishnae7df6d82018-05-23 10:37:30 +0530338 if (strcasecmp(interface, "wlan0") != 0) {
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700339 sigma_dut_print(dut, DUT_MSG_INFO,
340 "%s - Unsupported Interface Type: %s",
341 __func__, interface);
342 send_resp(dut, conn, SIGMA_ERROR,
343 "ErrMsg,Unsupported Interface Type");
344 return 0;
345 }
346
347 sscanf(burstExp, "%u", &loc_cmd.burstExp);
348 sigma_dut_print(dut, DUT_MSG_INFO, "%s - burstExp: %u",
349 __func__, loc_cmd.burstExp);
350 sscanf(asap, "%u", &loc_cmd.asap);
351 sigma_dut_print(dut, DUT_MSG_INFO, "%s - asap: %u",
352 __func__, loc_cmd.asap);
353 sscanf(fmtbw, "%u", &loc_cmd.fmtbw);
354 sigma_dut_print(dut, DUT_MSG_INFO, "%s - fmtbw: %u",
355 __func__, loc_cmd.fmtbw);
356 sscanf(locCivic, "%u", &loc_cmd.locCivic);
357 sigma_dut_print(dut, DUT_MSG_INFO, "%s - locCivic: %u",
358 __func__, loc_cmd.locCivic);
359 sscanf(lci, "%u", &loc_cmd.lci);
360 sigma_dut_print(dut, DUT_MSG_INFO, "%s - lci: %u",
361 __func__, loc_cmd.lci);
362
363 if (loc_write_xml_file(dut, destMacStr, &loc_cmd) < 0) {
364 sigma_dut_print(dut, DUT_MSG_ERROR,
365 "%s - Failed to write to XML file because of bad command",
366 __func__);
367 send_resp(dut, conn, SIGMA_ERROR,
368 "ErrMsg,Bad CAPI command");
369 return 0;
370 }
371 } else {
372 /* ANQP Query */
373 sigma_dut_print(dut, DUT_MSG_INFO,
374 "%s - LOWI_TST_ANQP_REQ", __func__);
375 params = destMacStr;
376 }
377
378 if (pass_request_to_ltest(dut, cmnd, params) < 0) {
379 /* Loc operation been failed. */
380 sigma_dut_print(dut, DUT_MSG_ERROR,
381 "%s - Failed to initiate Loc command",
382 __func__);
383 send_resp(dut, conn, SIGMA_ERROR,
384 "ErrMsg,Failed to initiate Loc command");
385 return 0;
386 }
387
388 sigma_dut_print(dut, DUT_MSG_INFO,
389 "%s - Succeeded to initiate Loc command", __func__);
390 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
391 return 0;
392}
393
394
395int loc_cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
396 struct sigma_cmd *cmd)
397{
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700398 const char *address3Cmnd = WPA_ADDRESS_3_DISABLE;
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700399 enum lowi_tst_cmd cmnd = LOWI_TST_NEIGHBOR_REPORT_REQ; /* Default */
400 /* Mandatory arguments */
vamsi krishnae7df6d82018-05-23 10:37:30 +0530401 const char *interface = get_param(cmd, "interface");
402 const char *program = get_param(cmd, "program");
403 const char *destMacStr = get_param(cmd, "destmac");
404 const char *frameName = get_param(cmd, "FrameName");
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700405
406 /* Optional Arguments */
vamsi krishnae7df6d82018-05-23 10:37:30 +0530407 const char *locCivic = get_param(cmd, "askforloccivic");
408 const char *lci = get_param(cmd, "askforlci");
409 const char *fqdn = get_param(cmd, "AskForPublicIdentifierURI-FQDN");
410 const char *address3 = get_param(cmd, "address3");
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700411
412 const char *params = NULL;
413
414 if (!program) {
415 sigma_dut_print(dut, DUT_MSG_ERROR,
416 "%s - No Program in Command! - Aborting",
417 __func__);
418 return -1;
419 }
420
421 if (!interface) {
422 sigma_dut_print(dut, DUT_MSG_ERROR,
423 "%s - Incomplete command in LOC CAPI request",
424 __func__);
425 send_resp(dut, conn, SIGMA_ERROR, NULL);
426 return 0;
427 }
428
429 if (!frameName) {
430 sigma_dut_print(dut, DUT_MSG_ERROR,
431 "%s - Incomplete command in LOC CAPI request",
432 __func__);
433 send_resp(dut, conn, SIGMA_ERROR, NULL);
434 return 0;
435 }
436
vamsi krishnae7df6d82018-05-23 10:37:30 +0530437 if (strcasecmp(frameName, "AnqpQuery") == 0 && !destMacStr) {
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700438 sigma_dut_print(dut, DUT_MSG_ERROR,
439 "%s - Incomplete command in LOC CAPI request",
440 __func__);
441 send_resp(dut, conn, SIGMA_ERROR, NULL);
442 return 0;
443 }
444
445 if (!locCivic)
446 sigma_dut_print(dut, DUT_MSG_ERROR,
447 "%s - Command missing LocCivic", __func__);
448 if (!lci)
449 sigma_dut_print(dut, DUT_MSG_ERROR,
450 "%s - Command missing LCI", __func__);
451 if (!fqdn)
452 sigma_dut_print(dut, DUT_MSG_ERROR,
453 "%s - Command missing FQDN", __func__);
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700454 if (!address3) {
455 sigma_dut_print(dut, DUT_MSG_ERROR,
456 "%s - Command missing address3", __func__);
457 } else {
458 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s - address3: %s",
459 __func__, address3);
vamsi krishnae7df6d82018-05-23 10:37:30 +0530460 if (strcasecmp(address3, "FF:FF:FF:FF:FF:FF") == 0)
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700461 address3Cmnd = WPA_ADDRESS_3_ENABLE;
462 else
463 address3Cmnd = WPA_ADDRESS_3_DISABLE;
464 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700465
vamsi krishnae7df6d82018-05-23 10:37:30 +0530466 if (strcasecmp(program, "loc") != 0) {
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700467 sigma_dut_print(dut, DUT_MSG_ERROR,
468 "%s - Unsupported Program: %s", __func__,
469 program);
470 send_resp(dut, conn, SIGMA_ERROR, NULL);
471 return 0;
472 }
473
474 sigma_dut_print(dut, DUT_MSG_INFO, "%s - Triggering Frame: %s",
475 __func__, frameName);
vamsi krishnae7df6d82018-05-23 10:37:30 +0530476 if (strcasecmp(frameName, "AnqpQuery") == 0) {
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700477 cmnd = LOWI_TST_ANQP_REQ;
478 params = destMacStr;
479 } else {
480 cmnd = LOWI_TST_NEIGHBOR_REPORT_REQ;
481 }
482
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700483 if (cmnd == LOWI_TST_ANQP_REQ) {
484 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s - Executing command %s",
485 __func__, address3Cmnd);
486 if (wpa_command(get_station_ifname(), address3Cmnd) < 0) {
487 send_resp(dut, conn, SIGMA_ERROR, NULL);
488 return -1;
489 }
490 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700491 if (pass_request_to_ltest(dut, cmnd, params) < 0) {
492 /* Loc operation has failed. */
493 sigma_dut_print(dut, DUT_MSG_ERROR,
494 "%s - Failed to initiate Loc command",
495 __func__);
496 send_resp(dut, conn, SIGMA_ERROR, NULL);
497 return 0;
498 }
499
500 sigma_dut_print(dut, DUT_MSG_INFO,
501 "%s - Succeeded to initiate Loc command", __func__);
502 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
503 return 0;
504}
505
506
507enum e_rm_parse_states {
508 LOC_LOOKING_FOR_BIT = 0,
509 LOC_LOOKING_FOR_VAL,
510 LOC_MAX
511};
512
513
514void parse_rm_bits(struct sigma_dut *dut, const char *rmFlags,
515 char rmBitFlags[LOC_MAX_RM_FLAGS][LOC_RM_FLAG_VAL_ARRAY])
516{
517
518 unsigned int bitPos = 0;
519 unsigned int bitVal = 0;
520 unsigned int idx = 0;
521 unsigned int i = 0;
522 enum e_rm_parse_states rmParseStates = LOC_LOOKING_FOR_BIT;
523 char temp = '\0';
524
525 if (!rmFlags) {
526 sigma_dut_print(dut, DUT_MSG_ERROR,
527 "%s - NULL pointer for rmFlags - Aborting", __func__);
528 return;
529 }
530
531 sigma_dut_print(dut, DUT_MSG_INFO, "%s - rmFlags: %s",
532 __func__, rmFlags);
533 while (*rmFlags != '\0' && idx < LOC_MAX_RM_FLAGS) {
534 temp = *rmFlags;
535 rmFlags++;
536 switch (rmParseStates) {
537 case LOC_LOOKING_FOR_BIT:
538 if (temp >= '0' && temp <= '9') {
539 /* Parse Digit for bit Position */
540 bitPos = (bitPos * 10) + (temp - '0');
541 sigma_dut_print(dut, DUT_MSG_INFO,
542 "%s - LOC_LOOKING_FOR_BIT - parsing: %c, bitPos: %u",
543 __func__, temp, bitPos);
544 } else if (temp == ':') {
545 /* move to Parsing Bit Value */
546 sigma_dut_print(dut, DUT_MSG_INFO,
547 "%s - LOC_LOOKING_FOR_BIT - processing: %c, bitPos: %u",
548 __func__, temp, bitPos);
549 rmBitFlags[idx][0] = bitPos;
550 rmParseStates = LOC_LOOKING_FOR_VAL;
551 } else if (temp == ';') {
552 /* End of Bit-Value Pair, reset and look for New Bit Position */
553 sigma_dut_print(dut, DUT_MSG_INFO,
554 "%s - LOC_LOOKING_FOR_BIT - processing: %c",
555 __func__, temp);
556 rmBitFlags[idx][0] = bitPos;
557 /* rmBitFlags[idx][1] = bitVal; */
558 bitPos = 0;
559 bitVal = 0;
560 idx++;
561 } else { /* Ignore */
562 sigma_dut_print(dut, DUT_MSG_INFO,
563 "%s - LOC_LOOKING_FOR_BIT - ignoring: %c",
564 __func__, temp);
565 }
566 break;
567 case LOC_LOOKING_FOR_VAL:
568 if (temp == '0' || temp == '1') {
569 sigma_dut_print(dut, DUT_MSG_INFO,
570 "%s - LOC_LOOKING_FOR_VAL - processing: %c",
571 __func__, temp);
572 bitVal = temp - '0';
573 rmBitFlags[idx][1] = bitVal;
574 } else if (temp == ';') {
575 sigma_dut_print(dut, DUT_MSG_INFO,
576 "%s - LOC_LOOKING_FOR_VAL - processing: %c, bitPos: %u, bitVal: %u",
577 __func__, temp, bitPos, bitVal);
578 /* rmBitFlags[idx][0] = bitPos; */
579 /* rmBitFlags[idx][1] = bitVal; */
580 bitPos = 0;
581 bitVal = 0;
582 idx++;
583 rmParseStates = LOC_LOOKING_FOR_BIT;
584 } else { /* Ignore */
585 sigma_dut_print(dut, DUT_MSG_INFO,
586 "%s - LOC_LOOKING_FOR_VAL - ignoring: %c",
587 __func__, temp);
588 }
589 break;
590 default: /* Ignore */
591 sigma_dut_print(dut, DUT_MSG_INFO,
592 "%s - default - ignoring: %c",
593 __func__, temp);
594 break;
595 }
596 }
597
598 for (i = 0; i < LOC_MAX_RM_FLAGS; i++) {
599 sigma_dut_print(dut, DUT_MSG_INFO,
600 "%s - Bit Pos: %u : Bit Val: %u",
601 __func__, rmBitFlags[i][0],
602 rmBitFlags[i][1]);
603 }
604}
605
606
607int loc_cmd_sta_preset_testparameters(struct sigma_dut *dut,
608 struct sigma_conn *conn,
609 struct sigma_cmd *cmd)
610{
vamsi krishnae7df6d82018-05-23 10:37:30 +0530611 const char *rmFTMRFlagStr = get_param(cmd, "RMEnabledCapBitmap");
612 const char *interworkingEn = get_param(cmd, "Interworking");
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700613 unsigned int rmFTMRFlag = 0;
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700614 unsigned int i, interworking = 0;
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700615 char rmBitFlags[LOC_MAX_RM_FLAGS][LOC_RM_FLAG_VAL_ARRAY];
616
617 sigma_dut_print(dut, DUT_MSG_INFO, "%s", __func__);
618
619 memset(rmBitFlags, 0, sizeof(rmBitFlags));
620
621 sigma_dut_print(dut, DUT_MSG_INFO, "%s - 1", __func__);
622 /*
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700623 * This function is used to configure the RM capability bits and
624 * the Interworking bit only.
625 * If these parameters are not present just returning COMPLETE
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700626 * because all other parameters are ignored.
627 */
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700628 if (!rmFTMRFlagStr && !interworkingEn) {
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700629 sigma_dut_print(dut, DUT_MSG_INFO, "%s - 2", __func__);
630 sigma_dut_print(dut, DUT_MSG_ERROR, "%s - Did not get %s",
vamsi krishnae7df6d82018-05-23 10:37:30 +0530631 __func__, "RMEnabledCapBitmap");
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700632 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
633 return 0;
634 }
635
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700636 if (rmFTMRFlagStr) {
637 rmFTMRFlag = 25; /* Default invalid */
638 sigma_dut_print(dut, DUT_MSG_INFO, "%s - rmFTMRFlagStr: %s",
639 __func__, rmFTMRFlagStr);
640 parse_rm_bits(dut, rmFTMRFlagStr, rmBitFlags);
641 for (i = 0; i < LOC_MAX_RM_FLAGS; i++) {
642 if (rmBitFlags[i][0] == 34)
643 rmFTMRFlag = rmBitFlags[i][1];
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700644 }
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700645 sigma_dut_print(dut, DUT_MSG_INFO, "%s - rmFTMRFlag %u",
646 __func__, rmFTMRFlag);
647 if (rmFTMRFlag == 0) { /* Disable RM - FTMRR capability */
648 sigma_dut_print(dut, DUT_MSG_INFO,
649 "%s - Disabling RM - FTMRR",
650 __func__);
651 if (wpa_command(get_station_ifname(), WPA_RM_DISABLE) <
652 0) {
653 send_resp(dut, conn, SIGMA_ERROR, NULL);
654 return -1;
655 }
656 } else if (rmFTMRFlag == 1) { /* Enable RM - FTMRR capability */
657 sigma_dut_print(dut, DUT_MSG_INFO,
658 "%s - Enabling RM - FTMRR",
659 __func__);
660 if (wpa_command(get_station_ifname(), WPA_RM_ENABLE) <
661 0) {
662 send_resp(dut, conn, SIGMA_ERROR, NULL);
663 return 0;
664 }
665 } else {
666 sigma_dut_print(dut, DUT_MSG_ERROR,
667 "%s - No Setting for - FTMRR",
668 __func__);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700669 }
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700670 sigma_dut_print(dut, DUT_MSG_INFO,
671 "%s - Succeeded in Enabling/Disabling RM Capability for FTMRR",
672 __func__);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700673 }
674
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700675 if (interworkingEn) {
676 sscanf(interworkingEn, "%u", &interworking);
677 sigma_dut_print(dut, DUT_MSG_INFO, "%s - interworking: %u",
678 __func__, interworking);
679 if (interworking)
680 wpa_command(get_station_ifname(),
681 WPA_INTERWORKING_ENABLE);
682 else
683 wpa_command(get_station_ifname(),
684 WPA_INTERWORKING_DISABLE);
685 }
686
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700687 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
688 return 0;
689}