priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 1 | /* |
| 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 gowthaman | 0dd682a | 2016-09-02 11:17:41 -0700 | [diff] [blame] | 11 | #include "wpa_helpers.h" |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 12 | |
| 13 | static const char LOC_XML_FILE_PATH[] = "./data/sigma-dut-target.xml"; |
| 14 | |
| 15 | static const char LOC_LOWI_TEST_DISCOVERY[] = "lowi_test -a -b 2 -n 1"; |
| 16 | static const char LOC_LOWI_TEST_RANGING[] = |
| 17 | "lowi_test -r ./data/sigma-dut-target.xml -n 1"; |
| 18 | static const char LOC_LOWI_TEST_NEIGHBOR_RPT_REQ[] = "lowi_test -nrr"; |
| 19 | static const char LOC_LOWI_TEST_ANQP_REQ[] = "lowi_test -anqp -mac "; |
priyadharshini gowthaman | 0dd682a | 2016-09-02 11:17:41 -0700 | [diff] [blame] | 20 | static const char WPA_INTERWORKING_ENABLE[] = |
| 21 | "SET interworking 1"; |
| 22 | static const char WPA_INTERWORKING_DISABLE[] = |
| 23 | "SET interworking 0"; |
| 24 | static const char WPA_RM_ENABLE[] = |
| 25 | "VENDOR 1374 74 08000400BD000000"; |
| 26 | static const char WPA_RM_DISABLE[] = |
| 27 | "VENDOR 1374 74 0800040000000000"; |
| 28 | static const char WPA_ADDRESS_3_ENABLE[] = |
| 29 | "SET gas_address3 1"; |
| 30 | static const char WPA_ADDRESS_3_DISABLE[] = |
| 31 | "SET gas_address3 0"; |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 32 | |
| 33 | #ifndef ETH_ALEN |
| 34 | #define ETH_ALEN 6 |
| 35 | #endif |
| 36 | |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 37 | #define LOC_MAX_RM_FLAGS 10 |
| 38 | #define LOC_RM_FLAG_VAL_ARRAY 2 |
| 39 | |
| 40 | enum lowi_tst_cmd { |
| 41 | LOWI_TST_RANGING = 0, |
| 42 | LOWI_TST_NEIGHBOR_REPORT_REQ = 1, |
| 43 | LOWI_TST_ANQP_REQ = 2, |
| 44 | }; |
| 45 | |
| 46 | struct 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 | |
| 61 | static 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__); |
Srikanth Marepalli | 5fc02a0 | 2018-08-27 12:53:11 +0530 | [diff] [blame] | 130 | fclose(xml); |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 131 | return -1; |
| 132 | } |
| 133 | |
| 134 | #define LOC_CAPI_DEFAULT_FTMS_PER_BURST 5 |
| 135 | #define LOC_CAPI_DEFAULT_BURST_DUR 10 |
| 136 | fprintf(xml, "<body>\n"); |
| 137 | fprintf(xml, " <ranging>\n"); |
| 138 | fprintf(xml, " <ap>\n"); |
| 139 | fprintf(xml, " <band>%u</band>\n", band); |
| 140 | fprintf(xml, " <rttType>3</rttType>\n"); |
| 141 | fprintf(xml, " <numFrames>%u</numFrames>\n", |
| 142 | LOC_CAPI_DEFAULT_FTMS_PER_BURST); |
| 143 | fprintf(xml, " <bw>%u</bw>\n", bw); |
| 144 | fprintf(xml, " <preamble>%u</preamble>\n", preamble); |
| 145 | fprintf(xml, " <asap>%u</asap>\n", loc_cmd->asap); |
| 146 | fprintf(xml, " <lci>%u</lci>\n", loc_cmd->lci); |
| 147 | fprintf(xml, " <civic>%u</civic>\n", loc_cmd->locCivic); |
| 148 | fprintf(xml, " <burstsexp>%u</burstsexp>\n", loc_cmd->burstExp); |
| 149 | fprintf(xml, " <burstduration>%u</burstduration>\n", |
| 150 | LOC_CAPI_DEFAULT_BURST_DUR); |
| 151 | fprintf(xml, " <burstperiod>%u</burstperiod>\n", 0); |
| 152 | /* Use parameters from LOWI cache */ |
| 153 | fprintf(xml, " <paramControl>%u</paramControl>\n", 0); |
priyadharshini gowthaman | 26357a0 | 2016-09-02 11:15:04 -0700 | [diff] [blame] | 154 | fprintf(xml, " <ptsftimer>%u</ptsftimer>\n", 0); |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 155 | fprintf(xml, " <center_freq1>%u</center_freq1>\n", center_freq); |
| 156 | fprintf(xml, " <center_freq2>0</center_freq2>\n"); |
| 157 | fprintf(xml, " <ch>%u</ch>\n", primary_ch); |
| 158 | fprintf(xml, " <mac>%s</mac>\n", dst_mac_str); |
| 159 | fprintf(xml, " </ap>\n"); |
| 160 | fprintf(xml, " </ranging>\n"); |
| 161 | fprintf(xml, " <summary>\n"); |
| 162 | fprintf(xml, " <mac>%s</mac>\n", dst_mac_str); |
| 163 | fprintf(xml, " </summary>\n"); |
| 164 | fprintf(xml, "</body>\n"); |
| 165 | |
| 166 | fclose(xml); |
| 167 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 168 | "%s - Successfully created XML file", __func__); |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | |
| 173 | static int pass_request_to_ltest(struct sigma_dut *dut, enum lowi_tst_cmd cmd, |
| 174 | const char *params) |
| 175 | { |
| 176 | #define MAX_ANQP_CMND_SIZE 256 |
| 177 | int ret; |
| 178 | const char *cmd_str; |
| 179 | char lowi_anqp_query[MAX_ANQP_CMND_SIZE]; |
| 180 | |
| 181 | switch (cmd) { |
| 182 | case LOWI_TST_RANGING: |
| 183 | cmd_str = LOC_LOWI_TEST_RANGING; |
| 184 | break; |
| 185 | case LOWI_TST_NEIGHBOR_REPORT_REQ: |
| 186 | cmd_str = LOC_LOWI_TEST_NEIGHBOR_RPT_REQ; |
| 187 | break; |
| 188 | case LOWI_TST_ANQP_REQ: |
| 189 | if (!params) { |
| 190 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 191 | "%s - No Destination Mac provided for ANQP Query", |
| 192 | __func__); |
| 193 | return -1; |
| 194 | } |
| 195 | |
| 196 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 197 | "%s - Destination Mac provided for ANQP Query: %s", |
| 198 | __func__, params); |
| 199 | |
| 200 | snprintf(lowi_anqp_query, MAX_ANQP_CMND_SIZE, "%s%s", |
| 201 | LOC_LOWI_TEST_ANQP_REQ, params); |
| 202 | cmd_str = lowi_anqp_query; |
| 203 | break; |
| 204 | default: |
| 205 | cmd_str = LOC_LOWI_TEST_DISCOVERY; |
| 206 | break; |
| 207 | } |
| 208 | |
| 209 | sigma_dut_print(dut, DUT_MSG_INFO, "%s - 1 - Running command: %s", |
| 210 | __func__, LOC_LOWI_TEST_DISCOVERY); |
| 211 | ret = system(LOC_LOWI_TEST_DISCOVERY); |
| 212 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 213 | "%s - Finished Performing Discovery Scan through LOWI_test: ret: %d", |
| 214 | __func__, ret); |
| 215 | sleep(1); |
| 216 | sigma_dut_print(dut, DUT_MSG_INFO, "%s - 2 - Running command: %s", |
| 217 | __func__, cmd_str); |
| 218 | ret = system(cmd_str); |
| 219 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 220 | "%s - Finished Performing command: %s, got ret: %d", |
| 221 | __func__, cmd_str, ret); |
| 222 | |
| 223 | return ret; |
| 224 | } |
| 225 | |
| 226 | |
| 227 | int loc_cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn, |
| 228 | struct sigma_cmd *cmd) |
| 229 | { |
| 230 | const char *params = NULL; |
| 231 | enum lowi_tst_cmd cmnd = LOWI_TST_RANGING; |
vamsi krishna | e7df6d8 | 2018-05-23 10:37:30 +0530 | [diff] [blame] | 232 | const char *program = get_param(cmd, "prog"); |
| 233 | const char *loc_op = get_param(cmd, "Trigger"); |
| 234 | const char *interface = get_param(cmd, "interface"); |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 235 | |
vamsi krishna | e7df6d8 | 2018-05-23 10:37:30 +0530 | [diff] [blame] | 236 | const char *destMacStr = get_param(cmd, "destmac"); |
| 237 | const char *burstExp = get_param(cmd, "burstsexponent"); |
| 238 | const char *asap = get_param(cmd, "ASAP"); |
| 239 | const char *fmtbw = get_param(cmd, "formatbwftm"); |
| 240 | const char *locCivic = get_param(cmd, "askforloccivic"); |
| 241 | const char *lci = get_param(cmd, "askforlci"); |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 242 | struct capi_loc_cmd loc_cmd; |
| 243 | |
| 244 | memset(&loc_cmd, 0, sizeof(loc_cmd)); |
| 245 | |
| 246 | if (!loc_op) { |
| 247 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 248 | "%s - No Operation! - Aborting", __func__); |
| 249 | return -1; |
| 250 | } |
| 251 | |
vamsi krishna | e7df6d8 | 2018-05-23 10:37:30 +0530 | [diff] [blame] | 252 | cmnd = strcasecmp(loc_op, "ANQPQuery") == 0 ? |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 253 | LOWI_TST_ANQP_REQ : LOWI_TST_RANGING; |
| 254 | sigma_dut_print(dut, DUT_MSG_INFO, "%s - Going to perform: %s", |
| 255 | __func__, loc_op); |
| 256 | |
| 257 | if (!program) { |
| 258 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 259 | "%s - No Program in Command! - Aborting", |
| 260 | __func__); |
| 261 | return -1; |
| 262 | } |
| 263 | |
| 264 | if (!interface) { |
| 265 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 266 | "%s - Incomplete command in LOC CAPI request", |
| 267 | __func__); |
| 268 | send_resp(dut, conn, SIGMA_ERROR, |
| 269 | "ErrMsg,Incomplete Loc CAPI command - missing interface"); |
| 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | if (!destMacStr) { |
| 274 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 275 | "%s - Incomplete command in LOC CAPI request", |
| 276 | __func__); |
| 277 | send_resp(dut, conn, SIGMA_ERROR, |
| 278 | "ErrMsg,Incomplete Loc CAPI command - missing MAC"); |
| 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | if (cmnd == LOWI_TST_RANGING) { |
| 283 | sigma_dut_print(dut, DUT_MSG_INFO, "%s - LOWI_TST_RANGING", |
| 284 | __func__); |
| 285 | if (!burstExp) { |
| 286 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 287 | "%s - Incomplete command in LOC CAPI request", |
| 288 | __func__); |
| 289 | send_resp(dut, conn, SIGMA_ERROR, |
| 290 | "ErrMsg,Incomplete Loc CAPI command - missing Burst Exp"); |
| 291 | return 0; |
| 292 | } |
| 293 | |
| 294 | if (!asap) { |
| 295 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 296 | "%s - Incomplete command in LOC CAPI request", |
| 297 | __func__); |
| 298 | send_resp(dut, conn, SIGMA_ERROR, |
| 299 | "ErrMsg,Incomplete Loc CAPI command - missing ASAP"); |
| 300 | return 0; |
| 301 | } |
| 302 | |
| 303 | if (!fmtbw) { |
| 304 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 305 | "%s - Incomplete command in LOC CAPI request", |
| 306 | __func__); |
| 307 | send_resp(dut, conn, SIGMA_ERROR, |
| 308 | "ErrMsg,Incomplete Loc CAPI command - missing Format & BW"); |
| 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | if (!locCivic) { |
| 313 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 314 | "%s - Incomplete command in LOC CAPI request", |
| 315 | __func__); |
| 316 | send_resp(dut, conn, SIGMA_ERROR, |
| 317 | "ErrMsg,Incomplete Loc CAPI command - missing Location Civic"); |
| 318 | return 0; |
| 319 | } |
| 320 | |
| 321 | if (!lci) { |
| 322 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 323 | "%s - Incomplete command in LOC CAPI request", |
| 324 | __func__); |
| 325 | send_resp(dut, conn, SIGMA_ERROR, |
| 326 | "ErrMsg,Incomplete Loc CAPI command - missing LCI"); |
| 327 | return 0; |
| 328 | } |
| 329 | |
vamsi krishna | e7df6d8 | 2018-05-23 10:37:30 +0530 | [diff] [blame] | 330 | if (strcasecmp(program, "loc") != 0) { |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 331 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 332 | "%s - Unsupported Program: %s", |
| 333 | __func__, program); |
| 334 | send_resp(dut, conn, SIGMA_ERROR, |
| 335 | "ErrMsg,Unsupported program"); |
| 336 | return 0; |
| 337 | } |
| 338 | |
vamsi krishna | e7df6d8 | 2018-05-23 10:37:30 +0530 | [diff] [blame] | 339 | if (strcasecmp(interface, "wlan0") != 0) { |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 340 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 341 | "%s - Unsupported Interface Type: %s", |
| 342 | __func__, interface); |
| 343 | send_resp(dut, conn, SIGMA_ERROR, |
| 344 | "ErrMsg,Unsupported Interface Type"); |
| 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | sscanf(burstExp, "%u", &loc_cmd.burstExp); |
| 349 | sigma_dut_print(dut, DUT_MSG_INFO, "%s - burstExp: %u", |
| 350 | __func__, loc_cmd.burstExp); |
| 351 | sscanf(asap, "%u", &loc_cmd.asap); |
| 352 | sigma_dut_print(dut, DUT_MSG_INFO, "%s - asap: %u", |
| 353 | __func__, loc_cmd.asap); |
| 354 | sscanf(fmtbw, "%u", &loc_cmd.fmtbw); |
| 355 | sigma_dut_print(dut, DUT_MSG_INFO, "%s - fmtbw: %u", |
| 356 | __func__, loc_cmd.fmtbw); |
| 357 | sscanf(locCivic, "%u", &loc_cmd.locCivic); |
| 358 | sigma_dut_print(dut, DUT_MSG_INFO, "%s - locCivic: %u", |
| 359 | __func__, loc_cmd.locCivic); |
| 360 | sscanf(lci, "%u", &loc_cmd.lci); |
| 361 | sigma_dut_print(dut, DUT_MSG_INFO, "%s - lci: %u", |
| 362 | __func__, loc_cmd.lci); |
| 363 | |
| 364 | if (loc_write_xml_file(dut, destMacStr, &loc_cmd) < 0) { |
| 365 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 366 | "%s - Failed to write to XML file because of bad command", |
| 367 | __func__); |
| 368 | send_resp(dut, conn, SIGMA_ERROR, |
| 369 | "ErrMsg,Bad CAPI command"); |
| 370 | return 0; |
| 371 | } |
| 372 | } else { |
| 373 | /* ANQP Query */ |
| 374 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 375 | "%s - LOWI_TST_ANQP_REQ", __func__); |
| 376 | params = destMacStr; |
| 377 | } |
| 378 | |
| 379 | if (pass_request_to_ltest(dut, cmnd, params) < 0) { |
| 380 | /* Loc operation been failed. */ |
| 381 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 382 | "%s - Failed to initiate Loc command", |
| 383 | __func__); |
| 384 | send_resp(dut, conn, SIGMA_ERROR, |
| 385 | "ErrMsg,Failed to initiate Loc command"); |
| 386 | return 0; |
| 387 | } |
| 388 | |
| 389 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 390 | "%s - Succeeded to initiate Loc command", __func__); |
| 391 | send_resp(dut, conn, SIGMA_COMPLETE, NULL); |
| 392 | return 0; |
| 393 | } |
| 394 | |
| 395 | |
| 396 | int loc_cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn, |
| 397 | struct sigma_cmd *cmd) |
| 398 | { |
priyadharshini gowthaman | 0dd682a | 2016-09-02 11:17:41 -0700 | [diff] [blame] | 399 | const char *address3Cmnd = WPA_ADDRESS_3_DISABLE; |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 400 | enum lowi_tst_cmd cmnd = LOWI_TST_NEIGHBOR_REPORT_REQ; /* Default */ |
| 401 | /* Mandatory arguments */ |
vamsi krishna | e7df6d8 | 2018-05-23 10:37:30 +0530 | [diff] [blame] | 402 | const char *interface = get_param(cmd, "interface"); |
| 403 | const char *program = get_param(cmd, "program"); |
| 404 | const char *destMacStr = get_param(cmd, "destmac"); |
| 405 | const char *frameName = get_param(cmd, "FrameName"); |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 406 | |
| 407 | /* Optional Arguments */ |
vamsi krishna | e7df6d8 | 2018-05-23 10:37:30 +0530 | [diff] [blame] | 408 | const char *locCivic = get_param(cmd, "askforloccivic"); |
| 409 | const char *lci = get_param(cmd, "askforlci"); |
| 410 | const char *fqdn = get_param(cmd, "AskForPublicIdentifierURI-FQDN"); |
| 411 | const char *address3 = get_param(cmd, "address3"); |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 412 | |
| 413 | const char *params = NULL; |
| 414 | |
| 415 | if (!program) { |
| 416 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 417 | "%s - No Program in Command! - Aborting", |
| 418 | __func__); |
| 419 | return -1; |
| 420 | } |
| 421 | |
| 422 | if (!interface) { |
| 423 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 424 | "%s - Incomplete command in LOC CAPI request", |
| 425 | __func__); |
| 426 | send_resp(dut, conn, SIGMA_ERROR, NULL); |
| 427 | return 0; |
| 428 | } |
| 429 | |
| 430 | if (!frameName) { |
| 431 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 432 | "%s - Incomplete command in LOC CAPI request", |
| 433 | __func__); |
| 434 | send_resp(dut, conn, SIGMA_ERROR, NULL); |
| 435 | return 0; |
| 436 | } |
| 437 | |
vamsi krishna | e7df6d8 | 2018-05-23 10:37:30 +0530 | [diff] [blame] | 438 | if (strcasecmp(frameName, "AnqpQuery") == 0 && !destMacStr) { |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 439 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 440 | "%s - Incomplete command in LOC CAPI request", |
| 441 | __func__); |
| 442 | send_resp(dut, conn, SIGMA_ERROR, NULL); |
| 443 | return 0; |
| 444 | } |
| 445 | |
| 446 | if (!locCivic) |
| 447 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 448 | "%s - Command missing LocCivic", __func__); |
| 449 | if (!lci) |
| 450 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 451 | "%s - Command missing LCI", __func__); |
| 452 | if (!fqdn) |
| 453 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 454 | "%s - Command missing FQDN", __func__); |
priyadharshini gowthaman | 0dd682a | 2016-09-02 11:17:41 -0700 | [diff] [blame] | 455 | if (!address3) { |
| 456 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 457 | "%s - Command missing address3", __func__); |
| 458 | } else { |
| 459 | sigma_dut_print(dut, DUT_MSG_DEBUG, "%s - address3: %s", |
| 460 | __func__, address3); |
vamsi krishna | e7df6d8 | 2018-05-23 10:37:30 +0530 | [diff] [blame] | 461 | if (strcasecmp(address3, "FF:FF:FF:FF:FF:FF") == 0) |
priyadharshini gowthaman | 0dd682a | 2016-09-02 11:17:41 -0700 | [diff] [blame] | 462 | address3Cmnd = WPA_ADDRESS_3_ENABLE; |
| 463 | else |
| 464 | address3Cmnd = WPA_ADDRESS_3_DISABLE; |
| 465 | } |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 466 | |
vamsi krishna | e7df6d8 | 2018-05-23 10:37:30 +0530 | [diff] [blame] | 467 | if (strcasecmp(program, "loc") != 0) { |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 468 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 469 | "%s - Unsupported Program: %s", __func__, |
| 470 | program); |
| 471 | send_resp(dut, conn, SIGMA_ERROR, NULL); |
| 472 | return 0; |
| 473 | } |
| 474 | |
| 475 | sigma_dut_print(dut, DUT_MSG_INFO, "%s - Triggering Frame: %s", |
| 476 | __func__, frameName); |
vamsi krishna | e7df6d8 | 2018-05-23 10:37:30 +0530 | [diff] [blame] | 477 | if (strcasecmp(frameName, "AnqpQuery") == 0) { |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 478 | cmnd = LOWI_TST_ANQP_REQ; |
| 479 | params = destMacStr; |
| 480 | } else { |
| 481 | cmnd = LOWI_TST_NEIGHBOR_REPORT_REQ; |
| 482 | } |
| 483 | |
priyadharshini gowthaman | 0dd682a | 2016-09-02 11:17:41 -0700 | [diff] [blame] | 484 | if (cmnd == LOWI_TST_ANQP_REQ) { |
| 485 | sigma_dut_print(dut, DUT_MSG_DEBUG, "%s - Executing command %s", |
| 486 | __func__, address3Cmnd); |
| 487 | if (wpa_command(get_station_ifname(), address3Cmnd) < 0) { |
| 488 | send_resp(dut, conn, SIGMA_ERROR, NULL); |
| 489 | return -1; |
| 490 | } |
| 491 | } |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 492 | if (pass_request_to_ltest(dut, cmnd, params) < 0) { |
| 493 | /* Loc operation has failed. */ |
| 494 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 495 | "%s - Failed to initiate Loc command", |
| 496 | __func__); |
| 497 | send_resp(dut, conn, SIGMA_ERROR, NULL); |
| 498 | return 0; |
| 499 | } |
| 500 | |
| 501 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 502 | "%s - Succeeded to initiate Loc command", __func__); |
| 503 | send_resp(dut, conn, SIGMA_COMPLETE, NULL); |
| 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | |
| 508 | enum e_rm_parse_states { |
| 509 | LOC_LOOKING_FOR_BIT = 0, |
| 510 | LOC_LOOKING_FOR_VAL, |
| 511 | LOC_MAX |
| 512 | }; |
| 513 | |
| 514 | |
| 515 | void parse_rm_bits(struct sigma_dut *dut, const char *rmFlags, |
| 516 | char rmBitFlags[LOC_MAX_RM_FLAGS][LOC_RM_FLAG_VAL_ARRAY]) |
| 517 | { |
| 518 | |
| 519 | unsigned int bitPos = 0; |
| 520 | unsigned int bitVal = 0; |
| 521 | unsigned int idx = 0; |
| 522 | unsigned int i = 0; |
| 523 | enum e_rm_parse_states rmParseStates = LOC_LOOKING_FOR_BIT; |
| 524 | char temp = '\0'; |
| 525 | |
| 526 | if (!rmFlags) { |
| 527 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 528 | "%s - NULL pointer for rmFlags - Aborting", __func__); |
| 529 | return; |
| 530 | } |
| 531 | |
| 532 | sigma_dut_print(dut, DUT_MSG_INFO, "%s - rmFlags: %s", |
| 533 | __func__, rmFlags); |
| 534 | while (*rmFlags != '\0' && idx < LOC_MAX_RM_FLAGS) { |
| 535 | temp = *rmFlags; |
| 536 | rmFlags++; |
| 537 | switch (rmParseStates) { |
| 538 | case LOC_LOOKING_FOR_BIT: |
| 539 | if (temp >= '0' && temp <= '9') { |
| 540 | /* Parse Digit for bit Position */ |
| 541 | bitPos = (bitPos * 10) + (temp - '0'); |
| 542 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 543 | "%s - LOC_LOOKING_FOR_BIT - parsing: %c, bitPos: %u", |
| 544 | __func__, temp, bitPos); |
| 545 | } else if (temp == ':') { |
| 546 | /* move to Parsing Bit Value */ |
| 547 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 548 | "%s - LOC_LOOKING_FOR_BIT - processing: %c, bitPos: %u", |
| 549 | __func__, temp, bitPos); |
| 550 | rmBitFlags[idx][0] = bitPos; |
| 551 | rmParseStates = LOC_LOOKING_FOR_VAL; |
| 552 | } else if (temp == ';') { |
| 553 | /* End of Bit-Value Pair, reset and look for New Bit Position */ |
| 554 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 555 | "%s - LOC_LOOKING_FOR_BIT - processing: %c", |
| 556 | __func__, temp); |
| 557 | rmBitFlags[idx][0] = bitPos; |
| 558 | /* rmBitFlags[idx][1] = bitVal; */ |
| 559 | bitPos = 0; |
| 560 | bitVal = 0; |
| 561 | idx++; |
| 562 | } else { /* Ignore */ |
| 563 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 564 | "%s - LOC_LOOKING_FOR_BIT - ignoring: %c", |
| 565 | __func__, temp); |
| 566 | } |
| 567 | break; |
| 568 | case LOC_LOOKING_FOR_VAL: |
| 569 | if (temp == '0' || temp == '1') { |
| 570 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 571 | "%s - LOC_LOOKING_FOR_VAL - processing: %c", |
| 572 | __func__, temp); |
| 573 | bitVal = temp - '0'; |
| 574 | rmBitFlags[idx][1] = bitVal; |
| 575 | } else if (temp == ';') { |
| 576 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 577 | "%s - LOC_LOOKING_FOR_VAL - processing: %c, bitPos: %u, bitVal: %u", |
| 578 | __func__, temp, bitPos, bitVal); |
| 579 | /* rmBitFlags[idx][0] = bitPos; */ |
| 580 | /* rmBitFlags[idx][1] = bitVal; */ |
| 581 | bitPos = 0; |
| 582 | bitVal = 0; |
| 583 | idx++; |
| 584 | rmParseStates = LOC_LOOKING_FOR_BIT; |
| 585 | } else { /* Ignore */ |
| 586 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 587 | "%s - LOC_LOOKING_FOR_VAL - ignoring: %c", |
| 588 | __func__, temp); |
| 589 | } |
| 590 | break; |
| 591 | default: /* Ignore */ |
| 592 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 593 | "%s - default - ignoring: %c", |
| 594 | __func__, temp); |
| 595 | break; |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | for (i = 0; i < LOC_MAX_RM_FLAGS; i++) { |
| 600 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 601 | "%s - Bit Pos: %u : Bit Val: %u", |
| 602 | __func__, rmBitFlags[i][0], |
| 603 | rmBitFlags[i][1]); |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | |
| 608 | int loc_cmd_sta_preset_testparameters(struct sigma_dut *dut, |
| 609 | struct sigma_conn *conn, |
| 610 | struct sigma_cmd *cmd) |
| 611 | { |
vamsi krishna | e7df6d8 | 2018-05-23 10:37:30 +0530 | [diff] [blame] | 612 | const char *rmFTMRFlagStr = get_param(cmd, "RMEnabledCapBitmap"); |
| 613 | const char *interworkingEn = get_param(cmd, "Interworking"); |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 614 | unsigned int rmFTMRFlag = 0; |
priyadharshini gowthaman | 0dd682a | 2016-09-02 11:17:41 -0700 | [diff] [blame] | 615 | unsigned int i, interworking = 0; |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 616 | char rmBitFlags[LOC_MAX_RM_FLAGS][LOC_RM_FLAG_VAL_ARRAY]; |
| 617 | |
| 618 | sigma_dut_print(dut, DUT_MSG_INFO, "%s", __func__); |
| 619 | |
| 620 | memset(rmBitFlags, 0, sizeof(rmBitFlags)); |
| 621 | |
| 622 | sigma_dut_print(dut, DUT_MSG_INFO, "%s - 1", __func__); |
| 623 | /* |
priyadharshini gowthaman | 0dd682a | 2016-09-02 11:17:41 -0700 | [diff] [blame] | 624 | * This function is used to configure the RM capability bits and |
| 625 | * the Interworking bit only. |
| 626 | * If these parameters are not present just returning COMPLETE |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 627 | * because all other parameters are ignored. |
| 628 | */ |
priyadharshini gowthaman | 0dd682a | 2016-09-02 11:17:41 -0700 | [diff] [blame] | 629 | if (!rmFTMRFlagStr && !interworkingEn) { |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 630 | sigma_dut_print(dut, DUT_MSG_INFO, "%s - 2", __func__); |
| 631 | sigma_dut_print(dut, DUT_MSG_ERROR, "%s - Did not get %s", |
vamsi krishna | e7df6d8 | 2018-05-23 10:37:30 +0530 | [diff] [blame] | 632 | __func__, "RMEnabledCapBitmap"); |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 633 | send_resp(dut, conn, SIGMA_COMPLETE, NULL); |
| 634 | return 0; |
| 635 | } |
| 636 | |
priyadharshini gowthaman | 0dd682a | 2016-09-02 11:17:41 -0700 | [diff] [blame] | 637 | if (rmFTMRFlagStr) { |
| 638 | rmFTMRFlag = 25; /* Default invalid */ |
| 639 | sigma_dut_print(dut, DUT_MSG_INFO, "%s - rmFTMRFlagStr: %s", |
| 640 | __func__, rmFTMRFlagStr); |
| 641 | parse_rm_bits(dut, rmFTMRFlagStr, rmBitFlags); |
| 642 | for (i = 0; i < LOC_MAX_RM_FLAGS; i++) { |
| 643 | if (rmBitFlags[i][0] == 34) |
| 644 | rmFTMRFlag = rmBitFlags[i][1]; |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 645 | } |
priyadharshini gowthaman | 0dd682a | 2016-09-02 11:17:41 -0700 | [diff] [blame] | 646 | sigma_dut_print(dut, DUT_MSG_INFO, "%s - rmFTMRFlag %u", |
| 647 | __func__, rmFTMRFlag); |
| 648 | if (rmFTMRFlag == 0) { /* Disable RM - FTMRR capability */ |
| 649 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 650 | "%s - Disabling RM - FTMRR", |
| 651 | __func__); |
| 652 | if (wpa_command(get_station_ifname(), WPA_RM_DISABLE) < |
| 653 | 0) { |
| 654 | send_resp(dut, conn, SIGMA_ERROR, NULL); |
| 655 | return -1; |
| 656 | } |
| 657 | } else if (rmFTMRFlag == 1) { /* Enable RM - FTMRR capability */ |
| 658 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 659 | "%s - Enabling RM - FTMRR", |
| 660 | __func__); |
| 661 | if (wpa_command(get_station_ifname(), WPA_RM_ENABLE) < |
| 662 | 0) { |
| 663 | send_resp(dut, conn, SIGMA_ERROR, NULL); |
| 664 | return 0; |
| 665 | } |
| 666 | } else { |
| 667 | sigma_dut_print(dut, DUT_MSG_ERROR, |
| 668 | "%s - No Setting for - FTMRR", |
| 669 | __func__); |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 670 | } |
priyadharshini gowthaman | 0dd682a | 2016-09-02 11:17:41 -0700 | [diff] [blame] | 671 | sigma_dut_print(dut, DUT_MSG_INFO, |
| 672 | "%s - Succeeded in Enabling/Disabling RM Capability for FTMRR", |
| 673 | __func__); |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 674 | } |
| 675 | |
priyadharshini gowthaman | 0dd682a | 2016-09-02 11:17:41 -0700 | [diff] [blame] | 676 | if (interworkingEn) { |
| 677 | sscanf(interworkingEn, "%u", &interworking); |
| 678 | sigma_dut_print(dut, DUT_MSG_INFO, "%s - interworking: %u", |
| 679 | __func__, interworking); |
| 680 | if (interworking) |
| 681 | wpa_command(get_station_ifname(), |
| 682 | WPA_INTERWORKING_ENABLE); |
| 683 | else |
| 684 | wpa_command(get_station_ifname(), |
| 685 | WPA_INTERWORKING_DISABLE); |
| 686 | } |
| 687 | |
priyadharshini gowthaman | d66913a | 2016-07-29 15:11:17 -0700 | [diff] [blame] | 688 | send_resp(dut, conn, SIGMA_COMPLETE, NULL); |
| 689 | return 0; |
| 690 | } |