blob: 769f5cb188934b3bd25963372ae3c3e0fbd29668 [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
37static const char LOC_CAPI_COMMAND_STR[] = "sta_exec_action";
38
39static const char LOC_CAPI_INTERFACE[] = "interface";
40static const char LOC_CAPI_INTERFACE_VAL[] = "wlan0";
41
42static const char LOC_CAPI_PROG[] = "prog";
43static const char LOC_CAPI_PROG_VAL[] = "loc";
44
45static const char LOC_CAPI_PROGRAM[] = "program";
46static const char LOC_CAPI_PROGRAM_VAL1[] = "24G";
47static const char LOC_CAPI_PROGRAM_VAL2[] = "5G";
48
49static const char LOC_CAPI_DEST_MAC[] = "destmac";
50static const char LOC_CAPI_OPER_CHAN[] = "operChn";
51static const char LOC_CAPI_TYPE_TRIGGER[] = "Trigger";
52static const char LOC_CAPI_TYPE_FTM_VAL[] = "FTMsession";
53static const char LOC_CAPI_TYPE_ANQP_VAL[] = "ANQPQuery";
54static const char LOC_CAPI_BURSTS_EXP[] = "burstsexponent";
55static const char LOC_CAPI_BURST_DURATION[] = "burstduration";
56static const char LOC_CAPI_MIN_DELTA_FTM[] = "mindeltaftm";
57static const char LOC_CAPI_PTSF[] = "partialtsf";
58static const char LOC_CAPI_ASAP[] = "ASAP";
59static const char LOC_CAPI_FTM_PER_BURST[] = "ftmsperburst";
60static const char LOC_CAPI_FORMAT_BW[] = "formatbwftm";
61static const char LOC_CAPI_BURST_PERIOD[] = "burstperiod";
62static const char LOC_CAPI_LOC_CIVIC[] = "askforloccivic";
63static const char LOC_CAPI_LCI[] = "askforlci";
64
65static const char LOC_CAPI_FRAME_NAME[] = "FrameName";
66static const char LOC_CAPI_FRAME_NAME_VAL_ANQP[] = "AnqpQuery";
67static const char LOC_CAPI_FRAME_NAME_VAL_NRR[] = "NeighReportReq";
68
69static const char LOC_CAPI_FQDN[] = "AskForPublicIdentifierURI-FQDN";
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -070070static const char LOC_CAPI_ADDRESS3[] = "address3";
71static const char LOC_WILD_CARD_BSSID[] = "FF:FF:FF:FF:FF:FF";
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070072
73static const char LOC_CAPI_RM_FTMRR_NAME[] = "RMEnabledCapBitmap";
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -070074static const char LOC_CAPI_INTERWORKING_NAME[] = "Interworking";
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070075
76#define LOC_MAX_RM_FLAGS 10
77#define LOC_RM_FLAG_VAL_ARRAY 2
78
79enum lowi_tst_cmd {
80 LOWI_TST_RANGING = 0,
81 LOWI_TST_NEIGHBOR_REPORT_REQ = 1,
82 LOWI_TST_ANQP_REQ = 2,
83};
84
85struct capi_loc_cmd {
86 unsigned int chan;
87 unsigned int burstExp;
88 unsigned int burstDur;
89 unsigned int minDeltaFtm;
90 unsigned int ptsf;
91 unsigned int asap;
92 unsigned int ftmsPerBurst;
93 unsigned int fmtbw;
94 unsigned int burstPeriod;
95 unsigned int locCivic;
96 unsigned int lci;
97};
98
99
100static int loc_write_xml_file(struct sigma_dut *dut, const char *dst_mac_str,
101 struct capi_loc_cmd *loc_cmd)
102{
103 FILE *xml;
104 unsigned int band, bw, preamble, primary_ch, center_freq;
105
106 xml = fopen(LOC_XML_FILE_PATH, "w");
107 if (!xml) {
108 sigma_dut_print(dut, DUT_MSG_ERROR,
109 "%s - Unable to create the XML file", __func__);
110 return -1;
111 }
112
113 /* Using this following defaults:
114 * default value of band 1
115 * channel 36
116 * center frequency of 5210
117 */
118 band = 1;
119 primary_ch = 36;
120 center_freq = 5210;
121
122#define FMT_BW_NO_PREF 0
123#define FMT_BW_HT_20 9
124#define FMT_BW_VHT_20 10
125#define FMT_BW_HT_40 11
126#define FMT_BW_VHT_40 12
127#define FMT_BW_VHT_80 13
128
129#define LOC_BW_20 0
130#define LOC_BW_40 1
131#define LOC_BW_80 2
132#define LOC_PREAMBLE_HT 1
133#define LOC_PREAMBLE_VHT 2
134 switch (loc_cmd->fmtbw) {
135 case FMT_BW_NO_PREF:
136 case FMT_BW_HT_20:
137 bw = LOC_BW_20;
138 preamble = LOC_PREAMBLE_HT;
139 primary_ch = 36;
140 center_freq = 5180;
141 break;
142 case FMT_BW_VHT_20:
143 bw = LOC_BW_20;
144 preamble = LOC_PREAMBLE_VHT;
145 primary_ch = 36;
146 center_freq = 5180;
147 break;
148 case FMT_BW_HT_40:
149 bw = LOC_BW_40;
150 preamble = LOC_PREAMBLE_HT;
151 primary_ch = 36;
152 center_freq = 5190;
153 break;
154 case FMT_BW_VHT_40:
155 bw = LOC_BW_40;
156 preamble = LOC_PREAMBLE_VHT;
157 primary_ch = 36;
158 center_freq = 5190;
159 break;
160 case FMT_BW_VHT_80:
161 bw = LOC_BW_80;
162 preamble = LOC_PREAMBLE_VHT;
163 primary_ch = 36;
164 center_freq = 5210;
165 break;
166 default:
167 sigma_dut_print(dut, DUT_MSG_ERROR,
168 "%s - Bad Format/BW received", __func__);
169 return -1;
170 }
171
172#define LOC_CAPI_DEFAULT_FTMS_PER_BURST 5
173#define LOC_CAPI_DEFAULT_BURST_DUR 10
174 fprintf(xml, "<body>\n");
175 fprintf(xml, " <ranging>\n");
176 fprintf(xml, " <ap>\n");
177 fprintf(xml, " <band>%u</band>\n", band);
178 fprintf(xml, " <rttType>3</rttType>\n");
179 fprintf(xml, " <numFrames>%u</numFrames>\n",
180 LOC_CAPI_DEFAULT_FTMS_PER_BURST);
181 fprintf(xml, " <bw>%u</bw>\n", bw);
182 fprintf(xml, " <preamble>%u</preamble>\n", preamble);
183 fprintf(xml, " <asap>%u</asap>\n", loc_cmd->asap);
184 fprintf(xml, " <lci>%u</lci>\n", loc_cmd->lci);
185 fprintf(xml, " <civic>%u</civic>\n", loc_cmd->locCivic);
186 fprintf(xml, " <burstsexp>%u</burstsexp>\n", loc_cmd->burstExp);
187 fprintf(xml, " <burstduration>%u</burstduration>\n",
188 LOC_CAPI_DEFAULT_BURST_DUR);
189 fprintf(xml, " <burstperiod>%u</burstperiod>\n", 0);
190 /* Use parameters from LOWI cache */
191 fprintf(xml, " <paramControl>%u</paramControl>\n", 0);
priyadharshini gowthaman26357a02016-09-02 11:15:04 -0700192 fprintf(xml, " <ptsftimer>%u</ptsftimer>\n", 0);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700193 fprintf(xml, " <center_freq1>%u</center_freq1>\n", center_freq);
194 fprintf(xml, " <center_freq2>0</center_freq2>\n");
195 fprintf(xml, " <ch>%u</ch>\n", primary_ch);
196 fprintf(xml, " <mac>%s</mac>\n", dst_mac_str);
197 fprintf(xml, " </ap>\n");
198 fprintf(xml, " </ranging>\n");
199 fprintf(xml, " <summary>\n");
200 fprintf(xml, " <mac>%s</mac>\n", dst_mac_str);
201 fprintf(xml, " </summary>\n");
202 fprintf(xml, "</body>\n");
203
204 fclose(xml);
205 sigma_dut_print(dut, DUT_MSG_INFO,
206 "%s - Successfully created XML file", __func__);
207 return 0;
208}
209
210
211static int pass_request_to_ltest(struct sigma_dut *dut, enum lowi_tst_cmd cmd,
212 const char *params)
213{
214#define MAX_ANQP_CMND_SIZE 256
215 int ret;
216 const char *cmd_str;
217 char lowi_anqp_query[MAX_ANQP_CMND_SIZE];
218
219 switch (cmd) {
220 case LOWI_TST_RANGING:
221 cmd_str = LOC_LOWI_TEST_RANGING;
222 break;
223 case LOWI_TST_NEIGHBOR_REPORT_REQ:
224 cmd_str = LOC_LOWI_TEST_NEIGHBOR_RPT_REQ;
225 break;
226 case LOWI_TST_ANQP_REQ:
227 if (!params) {
228 sigma_dut_print(dut, DUT_MSG_ERROR,
229 "%s - No Destination Mac provided for ANQP Query",
230 __func__);
231 return -1;
232 }
233
234 sigma_dut_print(dut, DUT_MSG_INFO,
235 "%s - Destination Mac provided for ANQP Query: %s",
236 __func__, params);
237
238 snprintf(lowi_anqp_query, MAX_ANQP_CMND_SIZE, "%s%s",
239 LOC_LOWI_TEST_ANQP_REQ, params);
240 cmd_str = lowi_anqp_query;
241 break;
242 default:
243 cmd_str = LOC_LOWI_TEST_DISCOVERY;
244 break;
245 }
246
247 sigma_dut_print(dut, DUT_MSG_INFO, "%s - 1 - Running command: %s",
248 __func__, LOC_LOWI_TEST_DISCOVERY);
249 ret = system(LOC_LOWI_TEST_DISCOVERY);
250 sigma_dut_print(dut, DUT_MSG_INFO,
251 "%s - Finished Performing Discovery Scan through LOWI_test: ret: %d",
252 __func__, ret);
253 sleep(1);
254 sigma_dut_print(dut, DUT_MSG_INFO, "%s - 2 - Running command: %s",
255 __func__, cmd_str);
256 ret = system(cmd_str);
257 sigma_dut_print(dut, DUT_MSG_INFO,
258 "%s - Finished Performing command: %s, got ret: %d",
259 __func__, cmd_str, ret);
260
261 return ret;
262}
263
264
265int loc_cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
266 struct sigma_cmd *cmd)
267{
268 const char *params = NULL;
269 enum lowi_tst_cmd cmnd = LOWI_TST_RANGING;
270 const char *program = get_param(cmd, LOC_CAPI_PROG);
271 const char *loc_op = get_param(cmd, LOC_CAPI_TYPE_TRIGGER);
272 const char *interface = get_param(cmd, LOC_CAPI_INTERFACE);
273
274 const char *destMacStr = get_param(cmd, LOC_CAPI_DEST_MAC);
275 const char *burstExp = get_param(cmd, LOC_CAPI_BURSTS_EXP);
276 const char *asap = get_param(cmd, LOC_CAPI_ASAP);
277 const char *fmtbw = get_param(cmd, LOC_CAPI_FORMAT_BW);
278 const char *locCivic = get_param(cmd, LOC_CAPI_LOC_CIVIC);
279 const char *lci = get_param(cmd, LOC_CAPI_LCI);
280 struct capi_loc_cmd loc_cmd;
281
282 memset(&loc_cmd, 0, sizeof(loc_cmd));
283
284 if (!loc_op) {
285 sigma_dut_print(dut, DUT_MSG_ERROR,
286 "%s - No Operation! - Aborting", __func__);
287 return -1;
288 }
289
290 cmnd = strcasecmp(loc_op, LOC_CAPI_TYPE_ANQP_VAL) == 0 ?
291 LOWI_TST_ANQP_REQ : LOWI_TST_RANGING;
292 sigma_dut_print(dut, DUT_MSG_INFO, "%s - Going to perform: %s",
293 __func__, loc_op);
294
295 if (!program) {
296 sigma_dut_print(dut, DUT_MSG_ERROR,
297 "%s - No Program in Command! - Aborting",
298 __func__);
299 return -1;
300 }
301
302 if (!interface) {
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 interface");
308 return 0;
309 }
310
311 if (!destMacStr) {
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 MAC");
317 return 0;
318 }
319
320 if (cmnd == LOWI_TST_RANGING) {
321 sigma_dut_print(dut, DUT_MSG_INFO, "%s - LOWI_TST_RANGING",
322 __func__);
323 if (!burstExp) {
324 sigma_dut_print(dut, DUT_MSG_ERROR,
325 "%s - Incomplete command in LOC CAPI request",
326 __func__);
327 send_resp(dut, conn, SIGMA_ERROR,
328 "ErrMsg,Incomplete Loc CAPI command - missing Burst Exp");
329 return 0;
330 }
331
332 if (!asap) {
333 sigma_dut_print(dut, DUT_MSG_INFO,
334 "%s - Incomplete command in LOC CAPI request",
335 __func__);
336 send_resp(dut, conn, SIGMA_ERROR,
337 "ErrMsg,Incomplete Loc CAPI command - missing ASAP");
338 return 0;
339 }
340
341 if (!fmtbw) {
342 sigma_dut_print(dut, DUT_MSG_ERROR,
343 "%s - Incomplete command in LOC CAPI request",
344 __func__);
345 send_resp(dut, conn, SIGMA_ERROR,
346 "ErrMsg,Incomplete Loc CAPI command - missing Format & BW");
347 return 0;
348 }
349
350 if (!locCivic) {
351 sigma_dut_print(dut, DUT_MSG_ERROR,
352 "%s - Incomplete command in LOC CAPI request",
353 __func__);
354 send_resp(dut, conn, SIGMA_ERROR,
355 "ErrMsg,Incomplete Loc CAPI command - missing Location Civic");
356 return 0;
357 }
358
359 if (!lci) {
360 sigma_dut_print(dut, DUT_MSG_ERROR,
361 "%s - Incomplete command in LOC CAPI request",
362 __func__);
363 send_resp(dut, conn, SIGMA_ERROR,
364 "ErrMsg,Incomplete Loc CAPI command - missing LCI");
365 return 0;
366 }
367
368 if (strcasecmp(program, LOC_CAPI_PROG_VAL) != 0) {
369 sigma_dut_print(dut, DUT_MSG_ERROR,
370 "%s - Unsupported Program: %s",
371 __func__, program);
372 send_resp(dut, conn, SIGMA_ERROR,
373 "ErrMsg,Unsupported program");
374 return 0;
375 }
376
377 if (strcasecmp(interface, LOC_CAPI_INTERFACE_VAL) != 0) {
378 sigma_dut_print(dut, DUT_MSG_INFO,
379 "%s - Unsupported Interface Type: %s",
380 __func__, interface);
381 send_resp(dut, conn, SIGMA_ERROR,
382 "ErrMsg,Unsupported Interface Type");
383 return 0;
384 }
385
386 sscanf(burstExp, "%u", &loc_cmd.burstExp);
387 sigma_dut_print(dut, DUT_MSG_INFO, "%s - burstExp: %u",
388 __func__, loc_cmd.burstExp);
389 sscanf(asap, "%u", &loc_cmd.asap);
390 sigma_dut_print(dut, DUT_MSG_INFO, "%s - asap: %u",
391 __func__, loc_cmd.asap);
392 sscanf(fmtbw, "%u", &loc_cmd.fmtbw);
393 sigma_dut_print(dut, DUT_MSG_INFO, "%s - fmtbw: %u",
394 __func__, loc_cmd.fmtbw);
395 sscanf(locCivic, "%u", &loc_cmd.locCivic);
396 sigma_dut_print(dut, DUT_MSG_INFO, "%s - locCivic: %u",
397 __func__, loc_cmd.locCivic);
398 sscanf(lci, "%u", &loc_cmd.lci);
399 sigma_dut_print(dut, DUT_MSG_INFO, "%s - lci: %u",
400 __func__, loc_cmd.lci);
401
402 if (loc_write_xml_file(dut, destMacStr, &loc_cmd) < 0) {
403 sigma_dut_print(dut, DUT_MSG_ERROR,
404 "%s - Failed to write to XML file because of bad command",
405 __func__);
406 send_resp(dut, conn, SIGMA_ERROR,
407 "ErrMsg,Bad CAPI command");
408 return 0;
409 }
410 } else {
411 /* ANQP Query */
412 sigma_dut_print(dut, DUT_MSG_INFO,
413 "%s - LOWI_TST_ANQP_REQ", __func__);
414 params = destMacStr;
415 }
416
417 if (pass_request_to_ltest(dut, cmnd, params) < 0) {
418 /* Loc operation been failed. */
419 sigma_dut_print(dut, DUT_MSG_ERROR,
420 "%s - Failed to initiate Loc command",
421 __func__);
422 send_resp(dut, conn, SIGMA_ERROR,
423 "ErrMsg,Failed to initiate Loc command");
424 return 0;
425 }
426
427 sigma_dut_print(dut, DUT_MSG_INFO,
428 "%s - Succeeded to initiate Loc command", __func__);
429 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
430 return 0;
431}
432
433
434int loc_cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
435 struct sigma_cmd *cmd)
436{
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700437 const char *address3Cmnd = WPA_ADDRESS_3_DISABLE;
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700438 enum lowi_tst_cmd cmnd = LOWI_TST_NEIGHBOR_REPORT_REQ; /* Default */
439 /* Mandatory arguments */
440 const char *interface = get_param(cmd, LOC_CAPI_INTERFACE);
441 const char *program = get_param(cmd, LOC_CAPI_PROGRAM);
442 const char *destMacStr = get_param(cmd, LOC_CAPI_DEST_MAC);
443 const char *frameName = get_param(cmd, LOC_CAPI_FRAME_NAME);
444
445 /* Optional Arguments */
446 const char *locCivic = get_param(cmd, LOC_CAPI_LOC_CIVIC);
447 const char *lci = get_param(cmd, LOC_CAPI_LCI);
448 const char *fqdn = get_param(cmd, LOC_CAPI_FQDN);
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700449 const char *address3 = get_param(cmd, LOC_CAPI_ADDRESS3);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700450
451 const char *params = NULL;
452
453 if (!program) {
454 sigma_dut_print(dut, DUT_MSG_ERROR,
455 "%s - No Program in Command! - Aborting",
456 __func__);
457 return -1;
458 }
459
460 if (!interface) {
461 sigma_dut_print(dut, DUT_MSG_ERROR,
462 "%s - Incomplete command in LOC CAPI request",
463 __func__);
464 send_resp(dut, conn, SIGMA_ERROR, NULL);
465 return 0;
466 }
467
468 if (!frameName) {
469 sigma_dut_print(dut, DUT_MSG_ERROR,
470 "%s - Incomplete command in LOC CAPI request",
471 __func__);
472 send_resp(dut, conn, SIGMA_ERROR, NULL);
473 return 0;
474 }
475
476 if (strcasecmp(frameName, LOC_CAPI_FRAME_NAME_VAL_ANQP) == 0 &&
477 !destMacStr) {
478 sigma_dut_print(dut, DUT_MSG_ERROR,
479 "%s - Incomplete command in LOC CAPI request",
480 __func__);
481 send_resp(dut, conn, SIGMA_ERROR, NULL);
482 return 0;
483 }
484
485 if (!locCivic)
486 sigma_dut_print(dut, DUT_MSG_ERROR,
487 "%s - Command missing LocCivic", __func__);
488 if (!lci)
489 sigma_dut_print(dut, DUT_MSG_ERROR,
490 "%s - Command missing LCI", __func__);
491 if (!fqdn)
492 sigma_dut_print(dut, DUT_MSG_ERROR,
493 "%s - Command missing FQDN", __func__);
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700494 if (!address3) {
495 sigma_dut_print(dut, DUT_MSG_ERROR,
496 "%s - Command missing address3", __func__);
497 } else {
498 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s - address3: %s",
499 __func__, address3);
500 if (strcasecmp(address3, LOC_WILD_CARD_BSSID) == 0)
501 address3Cmnd = WPA_ADDRESS_3_ENABLE;
502 else
503 address3Cmnd = WPA_ADDRESS_3_DISABLE;
504 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700505
506 if (strcasecmp(program, LOC_CAPI_PROG_VAL) != 0) {
507 sigma_dut_print(dut, DUT_MSG_ERROR,
508 "%s - Unsupported Program: %s", __func__,
509 program);
510 send_resp(dut, conn, SIGMA_ERROR, NULL);
511 return 0;
512 }
513
514 sigma_dut_print(dut, DUT_MSG_INFO, "%s - Triggering Frame: %s",
515 __func__, frameName);
516 if (strcasecmp(frameName, LOC_CAPI_FRAME_NAME_VAL_ANQP) == 0) {
517 cmnd = LOWI_TST_ANQP_REQ;
518 params = destMacStr;
519 } else {
520 cmnd = LOWI_TST_NEIGHBOR_REPORT_REQ;
521 }
522
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700523 if (cmnd == LOWI_TST_ANQP_REQ) {
524 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s - Executing command %s",
525 __func__, address3Cmnd);
526 if (wpa_command(get_station_ifname(), address3Cmnd) < 0) {
527 send_resp(dut, conn, SIGMA_ERROR, NULL);
528 return -1;
529 }
530 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700531 if (pass_request_to_ltest(dut, cmnd, params) < 0) {
532 /* Loc operation has failed. */
533 sigma_dut_print(dut, DUT_MSG_ERROR,
534 "%s - Failed to initiate Loc command",
535 __func__);
536 send_resp(dut, conn, SIGMA_ERROR, NULL);
537 return 0;
538 }
539
540 sigma_dut_print(dut, DUT_MSG_INFO,
541 "%s - Succeeded to initiate Loc command", __func__);
542 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
543 return 0;
544}
545
546
547enum e_rm_parse_states {
548 LOC_LOOKING_FOR_BIT = 0,
549 LOC_LOOKING_FOR_VAL,
550 LOC_MAX
551};
552
553
554void parse_rm_bits(struct sigma_dut *dut, const char *rmFlags,
555 char rmBitFlags[LOC_MAX_RM_FLAGS][LOC_RM_FLAG_VAL_ARRAY])
556{
557
558 unsigned int bitPos = 0;
559 unsigned int bitVal = 0;
560 unsigned int idx = 0;
561 unsigned int i = 0;
562 enum e_rm_parse_states rmParseStates = LOC_LOOKING_FOR_BIT;
563 char temp = '\0';
564
565 if (!rmFlags) {
566 sigma_dut_print(dut, DUT_MSG_ERROR,
567 "%s - NULL pointer for rmFlags - Aborting", __func__);
568 return;
569 }
570
571 sigma_dut_print(dut, DUT_MSG_INFO, "%s - rmFlags: %s",
572 __func__, rmFlags);
573 while (*rmFlags != '\0' && idx < LOC_MAX_RM_FLAGS) {
574 temp = *rmFlags;
575 rmFlags++;
576 switch (rmParseStates) {
577 case LOC_LOOKING_FOR_BIT:
578 if (temp >= '0' && temp <= '9') {
579 /* Parse Digit for bit Position */
580 bitPos = (bitPos * 10) + (temp - '0');
581 sigma_dut_print(dut, DUT_MSG_INFO,
582 "%s - LOC_LOOKING_FOR_BIT - parsing: %c, bitPos: %u",
583 __func__, temp, bitPos);
584 } else if (temp == ':') {
585 /* move to Parsing Bit Value */
586 sigma_dut_print(dut, DUT_MSG_INFO,
587 "%s - LOC_LOOKING_FOR_BIT - processing: %c, bitPos: %u",
588 __func__, temp, bitPos);
589 rmBitFlags[idx][0] = bitPos;
590 rmParseStates = LOC_LOOKING_FOR_VAL;
591 } else if (temp == ';') {
592 /* End of Bit-Value Pair, reset and look for New Bit Position */
593 sigma_dut_print(dut, DUT_MSG_INFO,
594 "%s - LOC_LOOKING_FOR_BIT - processing: %c",
595 __func__, temp);
596 rmBitFlags[idx][0] = bitPos;
597 /* rmBitFlags[idx][1] = bitVal; */
598 bitPos = 0;
599 bitVal = 0;
600 idx++;
601 } else { /* Ignore */
602 sigma_dut_print(dut, DUT_MSG_INFO,
603 "%s - LOC_LOOKING_FOR_BIT - ignoring: %c",
604 __func__, temp);
605 }
606 break;
607 case LOC_LOOKING_FOR_VAL:
608 if (temp == '0' || temp == '1') {
609 sigma_dut_print(dut, DUT_MSG_INFO,
610 "%s - LOC_LOOKING_FOR_VAL - processing: %c",
611 __func__, temp);
612 bitVal = temp - '0';
613 rmBitFlags[idx][1] = bitVal;
614 } else if (temp == ';') {
615 sigma_dut_print(dut, DUT_MSG_INFO,
616 "%s - LOC_LOOKING_FOR_VAL - processing: %c, bitPos: %u, bitVal: %u",
617 __func__, temp, bitPos, bitVal);
618 /* rmBitFlags[idx][0] = bitPos; */
619 /* rmBitFlags[idx][1] = bitVal; */
620 bitPos = 0;
621 bitVal = 0;
622 idx++;
623 rmParseStates = LOC_LOOKING_FOR_BIT;
624 } else { /* Ignore */
625 sigma_dut_print(dut, DUT_MSG_INFO,
626 "%s - LOC_LOOKING_FOR_VAL - ignoring: %c",
627 __func__, temp);
628 }
629 break;
630 default: /* Ignore */
631 sigma_dut_print(dut, DUT_MSG_INFO,
632 "%s - default - ignoring: %c",
633 __func__, temp);
634 break;
635 }
636 }
637
638 for (i = 0; i < LOC_MAX_RM_FLAGS; i++) {
639 sigma_dut_print(dut, DUT_MSG_INFO,
640 "%s - Bit Pos: %u : Bit Val: %u",
641 __func__, rmBitFlags[i][0],
642 rmBitFlags[i][1]);
643 }
644}
645
646
647int loc_cmd_sta_preset_testparameters(struct sigma_dut *dut,
648 struct sigma_conn *conn,
649 struct sigma_cmd *cmd)
650{
651 const char *rmFTMRFlagStr = get_param(cmd, LOC_CAPI_RM_FTMRR_NAME);
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700652 const char *interworkingEn = get_param(cmd, LOC_CAPI_INTERWORKING_NAME);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700653 unsigned int rmFTMRFlag = 0;
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700654 unsigned int i, interworking = 0;
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700655 char rmBitFlags[LOC_MAX_RM_FLAGS][LOC_RM_FLAG_VAL_ARRAY];
656
657 sigma_dut_print(dut, DUT_MSG_INFO, "%s", __func__);
658
659 memset(rmBitFlags, 0, sizeof(rmBitFlags));
660
661 sigma_dut_print(dut, DUT_MSG_INFO, "%s - 1", __func__);
662 /*
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700663 * This function is used to configure the RM capability bits and
664 * the Interworking bit only.
665 * If these parameters are not present just returning COMPLETE
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700666 * because all other parameters are ignored.
667 */
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700668 if (!rmFTMRFlagStr && !interworkingEn) {
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700669 sigma_dut_print(dut, DUT_MSG_INFO, "%s - 2", __func__);
670 sigma_dut_print(dut, DUT_MSG_ERROR, "%s - Did not get %s",
671 __func__, LOC_CAPI_RM_FTMRR_NAME);
672 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
673 return 0;
674 }
675
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700676 if (rmFTMRFlagStr) {
677 rmFTMRFlag = 25; /* Default invalid */
678 sigma_dut_print(dut, DUT_MSG_INFO, "%s - rmFTMRFlagStr: %s",
679 __func__, rmFTMRFlagStr);
680 parse_rm_bits(dut, rmFTMRFlagStr, rmBitFlags);
681 for (i = 0; i < LOC_MAX_RM_FLAGS; i++) {
682 if (rmBitFlags[i][0] == 34)
683 rmFTMRFlag = rmBitFlags[i][1];
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700684 }
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700685 sigma_dut_print(dut, DUT_MSG_INFO, "%s - rmFTMRFlag %u",
686 __func__, rmFTMRFlag);
687 if (rmFTMRFlag == 0) { /* Disable RM - FTMRR capability */
688 sigma_dut_print(dut, DUT_MSG_INFO,
689 "%s - Disabling RM - FTMRR",
690 __func__);
691 if (wpa_command(get_station_ifname(), WPA_RM_DISABLE) <
692 0) {
693 send_resp(dut, conn, SIGMA_ERROR, NULL);
694 return -1;
695 }
696 } else if (rmFTMRFlag == 1) { /* Enable RM - FTMRR capability */
697 sigma_dut_print(dut, DUT_MSG_INFO,
698 "%s - Enabling RM - FTMRR",
699 __func__);
700 if (wpa_command(get_station_ifname(), WPA_RM_ENABLE) <
701 0) {
702 send_resp(dut, conn, SIGMA_ERROR, NULL);
703 return 0;
704 }
705 } else {
706 sigma_dut_print(dut, DUT_MSG_ERROR,
707 "%s - No Setting for - FTMRR",
708 __func__);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700709 }
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700710 sigma_dut_print(dut, DUT_MSG_INFO,
711 "%s - Succeeded in Enabling/Disabling RM Capability for FTMRR",
712 __func__);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700713 }
714
priyadharshini gowthaman0dd682a2016-09-02 11:17:41 -0700715 if (interworkingEn) {
716 sscanf(interworkingEn, "%u", &interworking);
717 sigma_dut_print(dut, DUT_MSG_INFO, "%s - interworking: %u",
718 __func__, interworking);
719 if (interworking)
720 wpa_command(get_station_ifname(),
721 WPA_INTERWORKING_ENABLE);
722 else
723 wpa_command(get_station_ifname(),
724 WPA_INTERWORKING_DISABLE);
725 }
726
priyadharshini gowthamand66913a2016-07-29 15:11:17 -0700727 send_resp(dut, conn, SIGMA_COMPLETE, NULL);
728 return 0;
729}