1 // SPDX-FileCopyrightText: 2019 Jiao Xianjun <[email protected]> 2 // SPDX-License-Identifier: AGPL-3.0-or-later 3 4 #include <stdbool.h> 5 #include <errno.h> 6 #include <net/if.h> 7 #include <strings.h> 8 9 #include <netlink/genl/genl.h> 10 #include <netlink/genl/family.h> 11 #include <netlink/genl/ctrl.h> 12 #include <netlink/msg.h> 13 #include <netlink/attr.h> 14 15 #include "nl80211.h" 16 #include "sdrctl.h" 17 #include "nl80211_testmode_def.h" 18 19 20 static int cb_reg_handler(struct nl_msg *msg, void *arg) 21 { 22 struct nlattr *attrs[NL80211_ATTR_MAX + 1]; 23 struct nlattr *tb[OPENWIFI_ATTR_MAX + 1]; 24 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); 25 26 //printf("cb_reg_handler\n"); 27 28 nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL); 29 30 if (!attrs[NL80211_ATTR_TESTDATA]) 31 return NL_SKIP; 32 33 nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL); 34 35 //printf("reg addr: %08x\n", nla_get_u32(tb[REG_ATTR_ADDR])); 36 printf("reg val: %08x\n", nla_get_u32(tb[REG_ATTR_VAL])); 37 38 return NL_SKIP; 39 } 40 41 static int handle_set_reg(struct nl80211_state *state, 42 struct nl_cb *cb, 43 struct nl_msg *msg, 44 int argc, char **argv, 45 enum id_input id) 46 { 47 struct nlattr *tmdata; 48 char *end; 49 unsigned int reg_cat, reg_addr, reg_val; 50 51 tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA); 52 if (!tmdata) { 53 return 1; 54 } 55 56 if (strcasecmp(argv[0],"rf")==0) 57 reg_cat=1; 58 else if (strcasecmp(argv[0],"rx_intf")==0) 59 reg_cat = 2; 60 else if (strcasecmp(argv[0],"tx_intf")==0) 61 reg_cat = 3; 62 else if (strcasecmp(argv[0],"rx")==0) 63 reg_cat = 4; 64 else if (strcasecmp(argv[0],"tx")==0) 65 reg_cat = 5; 66 else if (strcasecmp(argv[0],"xpu")==0) 67 reg_cat = 6; 68 else if (strcasecmp(argv[0],"drv_rx")==0) 69 reg_cat = 7; 70 else if (strcasecmp(argv[0],"drv_tx")==0) 71 reg_cat = 8; 72 else if (strcasecmp(argv[0],"drv_xpu")==0) 73 reg_cat = 9; 74 else { 75 printf("Wrong the 1st argument. Should be rf/rx_intf/tx_intf/rx/tx/xpu/drv_rx/drv_tx/drv_xpu\n"); 76 return 1; 77 } 78 79 reg_addr = strtoul(argv[1], &end, 10); 80 if (*end) { 81 return 1; 82 } 83 reg_addr = reg_addr<<2;//from idx to addr 84 reg_addr = ((reg_cat<<16)|reg_addr); 85 86 reg_val = strtoul(argv[2], &end, 10); 87 if (*end) { 88 return 1; 89 } 90 91 NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, REG_CMD_SET); 92 NLA_PUT_U32(msg, REG_ATTR_ADDR, reg_addr); 93 NLA_PUT_U32(msg, REG_ATTR_VAL, reg_val); 94 95 nla_nest_end(msg, tmdata); 96 97 printf("reg cat: %d\n", reg_cat); 98 printf("reg addr: %08x\n", reg_addr); 99 printf("reg val: %08x\n", reg_val); 100 101 return 0; 102 103 nla_put_failure: 104 return -ENOBUFS; 105 } 106 COMMAND(set, reg, "<rf/rx_intf/tx_intf/rx/tx/xpu/drv_rx/drv_tx/drv_xpu reg_idx value>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_reg, "set reg"); 107 108 static int handle_get_reg(struct nl80211_state *state, 109 struct nl_cb *cb, 110 struct nl_msg *msg, 111 int argc, char **argv, 112 enum id_input id) 113 { 114 char *end; 115 struct nlattr *tmdata; 116 unsigned int reg_cat, reg_addr; 117 118 tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA); 119 if (!tmdata) 120 return 1; 121 122 if (strcasecmp(argv[0],"rf")==0) 123 reg_cat=1; 124 else if (strcasecmp(argv[0],"rx_intf")==0) 125 reg_cat = 2; 126 else if (strcasecmp(argv[0],"tx_intf")==0) 127 reg_cat = 3; 128 else if (strcasecmp(argv[0],"rx")==0) 129 reg_cat = 4; 130 else if (strcasecmp(argv[0],"tx")==0) 131 reg_cat = 5; 132 else if (strcasecmp(argv[0],"xpu")==0) 133 reg_cat = 6; 134 else if (strcasecmp(argv[0],"drv_rx")==0) 135 reg_cat = 7; 136 else if (strcasecmp(argv[0],"drv_tx")==0) 137 reg_cat = 8; 138 else if (strcasecmp(argv[0],"drv_xpu")==0) 139 reg_cat = 9; 140 else { 141 printf("Wrong the 1st argument. Should be rf/rx_intf/tx_intf/rx/tx/xpu/drv_rx/drv_tx/drv_xpu\n"); 142 return 1; 143 } 144 145 reg_addr = strtoul(argv[1], &end, 10); 146 if (*end) { 147 return 1; 148 } 149 reg_addr = reg_addr<<2;//from idx to addr 150 reg_addr = ((reg_cat<<16)|reg_addr); 151 printf("SENDaddr: %08x\n", reg_addr); 152 153 NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, REG_CMD_GET); 154 NLA_PUT_U32(msg, REG_ATTR_ADDR, reg_addr); 155 156 nla_nest_end(msg, tmdata); 157 158 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_reg_handler, NULL); 159 return 0; 160 161 nla_put_failure: 162 return -ENOBUFS; 163 } 164 COMMAND(get, reg, "<rf/rx_intf/tx_intf/rx/tx/xpu/drv_rx/drv_tx/drv_xpu reg_idx>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_reg, "get reg"); 165 166 static int cb_openwifi_rssi_th_handler(struct nl_msg *msg, void *arg) 167 { 168 struct nlattr *attrs[NL80211_ATTR_MAX + 1]; 169 struct nlattr *tb[OPENWIFI_ATTR_MAX + 1]; 170 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); 171 172 nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL); 173 174 if (!attrs[NL80211_ATTR_TESTDATA]) 175 return NL_SKIP; 176 177 nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL); 178 179 printf("openwifi rssi_th: %d\n", nla_get_u32(tb[OPENWIFI_ATTR_RSSI_TH])); 180 181 return NL_SKIP; 182 } 183 184 static int handle_set_rssi_th(struct nl80211_state *state, 185 struct nl_cb *cb, 186 struct nl_msg *msg, 187 int argc, char **argv, 188 enum id_input id) 189 { 190 struct nlattr *tmdata; 191 char *end; 192 unsigned int tmp; 193 194 tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA); 195 if (!tmdata) { 196 return 1; 197 } 198 199 tmp = strtoul(argv[0], &end, 10); 200 201 if (*end) { 202 return 1; 203 } 204 205 NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_RSSI_TH); 206 NLA_PUT_U32(msg, OPENWIFI_ATTR_RSSI_TH, tmp); 207 208 nla_nest_end(msg, tmdata); 209 210 printf("openwifi rssi_th: %d\n", tmp); 211 212 return 0; 213 214 nla_put_failure: 215 return -ENOBUFS; 216 } 217 COMMAND(set, rssi_th, "<rssi_th in value>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_rssi_th, "set rssi_th"); 218 219 220 static int handle_set_tsf(struct nl80211_state *state, 221 struct nl_cb *cb, 222 struct nl_msg *msg, 223 int argc, char **argv, 224 enum id_input id) 225 { 226 struct nlattr *tmdata; 227 char *end; 228 unsigned int high_tsf, low_tsf; 229 230 tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA); 231 if (!tmdata) { 232 return 1; 233 } 234 235 high_tsf = strtoul(argv[0], &end, 10); 236 if (*end) { 237 return 1; 238 } 239 240 low_tsf = strtoul(argv[1], &end, 10); 241 if (*end) { 242 return 1; 243 } 244 245 NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_TSF); 246 NLA_PUT_U32(msg, OPENWIFI_ATTR_HIGH_TSF, high_tsf); 247 NLA_PUT_U32(msg, OPENWIFI_ATTR_LOW_TSF, low_tsf); 248 249 nla_nest_end(msg, tmdata); 250 251 printf("high_tsf val: %08x\n", high_tsf); 252 printf("low_tsf val: %08x\n", low_tsf); 253 254 return 0; 255 256 /*struct nlattr *tmdata; 257 char *end; 258 unsigned int tmp; 259 260 tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA); 261 if (!tmdata) { 262 return 1; 263 } 264 265 tmp = strtoul(argv[0], &end, 10); 266 267 if (*end) { 268 return 1; 269 } 270 271 NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_TSF); 272 NLA_PUT_U64(msg, OPENWIFI_ATTR_TSF, tmp); 273 274 nla_nest_end(msg, tmdata); 275 276 printf("openwifi tsf: %d\n", tmp); 277 278 return 0;*/ 279 280 nla_put_failure: 281 return -ENOBUFS; 282 } 283 COMMAND(set, tsf, "<high_tsf value low_tsf value>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_tsf, "set tsf"); 284 285 static int handle_get_rssi_th(struct nl80211_state *state, 286 struct nl_cb *cb, 287 struct nl_msg *msg, 288 int argc, char **argv, 289 enum id_input id) 290 { 291 struct nlattr *tmdata; 292 293 tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA); 294 if (!tmdata) 295 return 1; 296 297 NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_RSSI_TH); 298 299 nla_nest_end(msg, tmdata); 300 301 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_rssi_th_handler, NULL); 302 return 0; 303 304 nla_put_failure: 305 return -ENOBUFS; 306 } 307 COMMAND(get, rssi_th, "<rssi_th in value>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_rssi_th, "get rssi_th"); 308 309 static int cb_openwifi_slice_total_handler(struct nl_msg *msg, void *arg) 310 { 311 struct nlattr *attrs[NL80211_ATTR_MAX + 1]; 312 struct nlattr *tb[OPENWIFI_ATTR_MAX + 1]; 313 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); 314 unsigned int tmp; 315 316 nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL); 317 318 if (!attrs[NL80211_ATTR_TESTDATA]) 319 return NL_SKIP; 320 321 nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL); 322 323 tmp = nla_get_u32(tb[OPENWIFI_ATTR_SLICE_TOTAL]); 324 printf("openwifi slice_total (duration) %dus of slice %d\n", tmp&0xFFFFF, tmp>>20); 325 326 return NL_SKIP; 327 } 328 329 static int handle_set_slice_total(struct nl80211_state *state, 330 struct nl_cb *cb, 331 struct nl_msg *msg, 332 int argc, char **argv, 333 enum id_input id) 334 { 335 struct nlattr *tmdata; 336 char *end; 337 unsigned int tmp; 338 339 tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA); 340 if (!tmdata) { 341 return 1; 342 } 343 344 tmp = strtoul(argv[0], &end, 10); 345 346 if (*end) { 347 return 1; 348 } 349 350 NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_SLICE_TOTAL); 351 NLA_PUT_U32(msg, OPENWIFI_ATTR_SLICE_TOTAL, tmp); 352 353 nla_nest_end(msg, tmdata); 354 355 printf("openwifi slice_total (duration): %dus\n", tmp); 356 357 return 0; 358 359 nla_put_failure: 360 return -ENOBUFS; 361 } 362 COMMAND(set, slice_total, "<slice_total(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_slice_total, "set slice_total"); 363 364 static int handle_get_slice_total(struct nl80211_state *state, 365 struct nl_cb *cb, 366 struct nl_msg *msg, 367 int argc, char **argv, 368 enum id_input id) 369 { 370 struct nlattr *tmdata; 371 372 tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA); 373 if (!tmdata) 374 return 1; 375 376 NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_SLICE_TOTAL); 377 378 nla_nest_end(msg, tmdata); 379 380 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_slice_total_handler, NULL); 381 return 0; 382 383 nla_put_failure: 384 return -ENOBUFS; 385 } 386 COMMAND(get, slice_total, "<slice_total(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_slice_total, "get slice_total"); 387 388 389 // static int cb_openwifi_slice_total1_handler(struct nl_msg *msg, void *arg) 390 // { 391 // struct nlattr *attrs[NL80211_ATTR_MAX + 1]; 392 // struct nlattr *tb[OPENWIFI_ATTR_MAX + 1]; 393 // struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); 394 395 // nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL); 396 397 // if (!attrs[NL80211_ATTR_TESTDATA]) 398 // return NL_SKIP; 399 400 // nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL); 401 402 // printf("openwifi slice_total1 (duration): %dus\n", nla_get_u32(tb[OPENWIFI_ATTR_SLICE_TOTAL1])); 403 404 // return NL_SKIP; 405 // } 406 407 // static int handle_set_slice_total1(struct nl80211_state *state, 408 // struct nl_cb *cb, 409 // struct nl_msg *msg, 410 // int argc, char **argv, 411 // enum id_input id) 412 // { 413 // struct nlattr *tmdata; 414 // char *end; 415 // unsigned int tmp; 416 417 // tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA); 418 // if (!tmdata) { 419 // return 1; 420 // } 421 422 // tmp = strtoul(argv[0], &end, 10); 423 424 // if (*end) { 425 // return 1; 426 // } 427 428 // NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_SLICE_TOTAL1); 429 // NLA_PUT_U32(msg, OPENWIFI_ATTR_SLICE_TOTAL1, tmp); 430 431 // nla_nest_end(msg, tmdata); 432 433 // printf("openwifi slice_total1 (duration): %dus\n", tmp); 434 435 // return 0; 436 437 // nla_put_failure: 438 // return -ENOBUFS; 439 // } 440 // COMMAND(set, slice_total1, "<slice_total1(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_slice_total1, "set slice_total1"); 441 442 // static int handle_get_slice_total1(struct nl80211_state *state, 443 // struct nl_cb *cb, 444 // struct nl_msg *msg, 445 // int argc, char **argv, 446 // enum id_input id) 447 // { 448 // struct nlattr *tmdata; 449 450 // tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA); 451 // if (!tmdata) 452 // return 1; 453 454 // NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_SLICE_TOTAL1); 455 456 // nla_nest_end(msg, tmdata); 457 458 // nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_slice_total1_handler, NULL); 459 // return 0; 460 461 // nla_put_failure: 462 // return -ENOBUFS; 463 // } 464 // COMMAND(get, slice_total1, "<slice_total1(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_slice_total1, "get slice_total1"); 465 466 static int cb_openwifi_slice_start_handler(struct nl_msg *msg, void *arg) 467 { 468 struct nlattr *attrs[NL80211_ATTR_MAX + 1]; 469 struct nlattr *tb[OPENWIFI_ATTR_MAX + 1]; 470 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); 471 unsigned int tmp; 472 473 nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL); 474 475 if (!attrs[NL80211_ATTR_TESTDATA]) 476 return NL_SKIP; 477 478 nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL); 479 480 tmp = nla_get_u32(tb[OPENWIFI_ATTR_SLICE_START]); 481 printf("openwifi slice_start (duration) %dus of slice %d\n", tmp&0xFFFFF, tmp>>20); 482 483 return NL_SKIP; 484 } 485 486 static int handle_set_slice_start(struct nl80211_state *state, 487 struct nl_cb *cb, 488 struct nl_msg *msg, 489 int argc, char **argv, 490 enum id_input id) 491 { 492 struct nlattr *tmdata; 493 char *end; 494 unsigned int tmp; 495 496 tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA); 497 if (!tmdata) { 498 return 1; 499 } 500 501 tmp = strtoul(argv[0], &end, 10); 502 503 if (*end) { 504 return 1; 505 } 506 507 NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_SLICE_START); 508 NLA_PUT_U32(msg, OPENWIFI_ATTR_SLICE_START, tmp); 509 510 nla_nest_end(msg, tmdata); 511 512 printf("openwifi slice_start (duration): %dus\n", tmp); 513 514 return 0; 515 516 nla_put_failure: 517 return -ENOBUFS; 518 } 519 COMMAND(set, slice_start, "<slice_start(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_slice_start, "set slice_start"); 520 521 static int handle_get_slice_start(struct nl80211_state *state, 522 struct nl_cb *cb, 523 struct nl_msg *msg, 524 int argc, char **argv, 525 enum id_input id) 526 { 527 struct nlattr *tmdata; 528 529 tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA); 530 if (!tmdata) 531 return 1; 532 533 NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_SLICE_START); 534 535 nla_nest_end(msg, tmdata); 536 537 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_slice_start_handler, NULL); 538 return 0; 539 540 nla_put_failure: 541 return -ENOBUFS; 542 } 543 COMMAND(get, slice_start, "<slice_start(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_slice_start, "get slice_start"); 544 545 546 // static int cb_openwifi_slice_start1_handler(struct nl_msg *msg, void *arg) 547 // { 548 // struct nlattr *attrs[NL80211_ATTR_MAX + 1]; 549 // struct nlattr *tb[OPENWIFI_ATTR_MAX + 1]; 550 // struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); 551 552 // nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL); 553 554 // if (!attrs[NL80211_ATTR_TESTDATA]) 555 // return NL_SKIP; 556 557 // nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL); 558 559 // printf("openwifi slice_start1 (duration): %dus\n", nla_get_u32(tb[OPENWIFI_ATTR_SLICE_START1])); 560 561 // return NL_SKIP; 562 // } 563 564 // static int handle_set_slice_start1(struct nl80211_state *state, 565 // struct nl_cb *cb, 566 // struct nl_msg *msg, 567 // int argc, char **argv, 568 // enum id_input id) 569 // { 570 // struct nlattr *tmdata; 571 // char *end; 572 // unsigned int tmp; 573 574 // tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA); 575 // if (!tmdata) { 576 // return 1; 577 // } 578 579 // tmp = strtoul(argv[0], &end, 10); 580 581 // if (*end) { 582 // return 1; 583 // } 584 585 // NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_SLICE_START1); 586 // NLA_PUT_U32(msg, OPENWIFI_ATTR_SLICE_START1, tmp); 587 588 // nla_nest_end(msg, tmdata); 589 590 // printf("openwifi slice_start1 (duration): %dus\n", tmp); 591 592 // return 0; 593 594 // nla_put_failure: 595 // return -ENOBUFS; 596 // } 597 // COMMAND(set, slice_start1, "<slice_start1(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_slice_start1, "set slice_start1"); 598 599 // static int handle_get_slice_start1(struct nl80211_state *state, 600 // struct nl_cb *cb, 601 // struct nl_msg *msg, 602 // int argc, char **argv, 603 // enum id_input id) 604 // { 605 // struct nlattr *tmdata; 606 607 // tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA); 608 // if (!tmdata) 609 // return 1; 610 611 // NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_SLICE_START1); 612 613 // nla_nest_end(msg, tmdata); 614 615 // nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_slice_start1_handler, NULL); 616 // return 0; 617 618 // nla_put_failure: 619 // return -ENOBUFS; 620 // } 621 // COMMAND(get, slice_start1, "<slice_start1(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_slice_start1, "get slice_start1"); 622 623 624 static int cb_openwifi_slice_end_handler(struct nl_msg *msg, void *arg) 625 { 626 struct nlattr *attrs[NL80211_ATTR_MAX + 1]; 627 struct nlattr *tb[OPENWIFI_ATTR_MAX + 1]; 628 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); 629 unsigned int tmp; 630 631 nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL); 632 633 if (!attrs[NL80211_ATTR_TESTDATA]) 634 return NL_SKIP; 635 636 nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL); 637 638 tmp = nla_get_u32(tb[OPENWIFI_ATTR_SLICE_END]); 639 printf("openwifi slice_end (duration) %dus of slice %d\n", tmp&0xFFFFF, tmp>>20); 640 641 return NL_SKIP; 642 } 643 644 static int handle_set_slice_end(struct nl80211_state *state, 645 struct nl_cb *cb, 646 struct nl_msg *msg, 647 int argc, char **argv, 648 enum id_input id) 649 { 650 struct nlattr *tmdata; 651 char *end; 652 unsigned int tmp; 653 654 tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA); 655 if (!tmdata) { 656 return 1; 657 } 658 659 tmp = strtoul(argv[0], &end, 10); 660 661 if (*end) { 662 return 1; 663 } 664 665 NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_SLICE_END); 666 NLA_PUT_U32(msg, OPENWIFI_ATTR_SLICE_END, tmp); 667 668 nla_nest_end(msg, tmdata); 669 670 printf("openwifi slice_end (duration): %dus\n", tmp); 671 672 return 0; 673 674 nla_put_failure: 675 return -ENOBUFS; 676 } 677 COMMAND(set, slice_end, "<slice_end(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_slice_end, "set slice_end"); 678 679 static int handle_get_slice_end(struct nl80211_state *state, 680 struct nl_cb *cb, 681 struct nl_msg *msg, 682 int argc, char **argv, 683 enum id_input id) 684 { 685 struct nlattr *tmdata; 686 687 tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA); 688 if (!tmdata) 689 return 1; 690 691 NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_SLICE_END); 692 693 nla_nest_end(msg, tmdata); 694 695 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_slice_end_handler, NULL); 696 return 0; 697 698 nla_put_failure: 699 return -ENOBUFS; 700 } 701 COMMAND(get, slice_end, "<slice_end(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_slice_end, "get slice_end"); 702 703 704 // static int cb_openwifi_slice_end1_handler(struct nl_msg *msg, void *arg) 705 // { 706 // struct nlattr *attrs[NL80211_ATTR_MAX + 1]; 707 // struct nlattr *tb[OPENWIFI_ATTR_MAX + 1]; 708 // struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); 709 710 // nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL); 711 712 // if (!attrs[NL80211_ATTR_TESTDATA]) 713 // return NL_SKIP; 714 715 // nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL); 716 717 // printf("openwifi slice_end1 (duration): %dus\n", nla_get_u32(tb[OPENWIFI_ATTR_SLICE_END1])); 718 719 // return NL_SKIP; 720 // } 721 722 // static int handle_set_slice_end1(struct nl80211_state *state, 723 // struct nl_cb *cb, 724 // struct nl_msg *msg, 725 // int argc, char **argv, 726 // enum id_input id) 727 // { 728 // struct nlattr *tmdata; 729 // char *end; 730 // unsigned int tmp; 731 732 // tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA); 733 // if (!tmdata) { 734 // return 1; 735 // } 736 737 // tmp = strtoul(argv[0], &end, 10); 738 739 // if (*end) { 740 // return 1; 741 // } 742 743 // NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_SLICE_END1); 744 // NLA_PUT_U32(msg, OPENWIFI_ATTR_SLICE_END1, tmp); 745 746 // nla_nest_end(msg, tmdata); 747 748 // printf("openwifi slice_end1 (duration): %dus\n", tmp); 749 750 // return 0; 751 752 // nla_put_failure: 753 // return -ENOBUFS; 754 // } 755 // COMMAND(set, slice_end1, "<slice_end1(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_slice_end1, "set slice_end1"); 756 757 // static int handle_get_slice_end1(struct nl80211_state *state, 758 // struct nl_cb *cb, 759 // struct nl_msg *msg, 760 // int argc, char **argv, 761 // enum id_input id) 762 // { 763 // struct nlattr *tmdata; 764 765 // tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA); 766 // if (!tmdata) 767 // return 1; 768 769 // NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_SLICE_END1); 770 771 // nla_nest_end(msg, tmdata); 772 773 // nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_slice_end1_handler, NULL); 774 // return 0; 775 776 // nla_put_failure: 777 // return -ENOBUFS; 778 // } 779 // COMMAND(get, slice_end1, "<slice_end1(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_slice_end1, "get slice_end1"); 780 781 782 static int cb_openwifi_slice_idx_handler(struct nl_msg *msg, void *arg) 783 { 784 struct nlattr *attrs[NL80211_ATTR_MAX + 1]; 785 struct nlattr *tb[OPENWIFI_ATTR_MAX + 1]; 786 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); 787 788 nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL); 789 790 if (!attrs[NL80211_ATTR_TESTDATA]) 791 return NL_SKIP; 792 793 nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL); 794 795 printf("openwifi slice_idx in hex: %08x\n", nla_get_u32(tb[OPENWIFI_ATTR_SLICE_IDX])); 796 797 return NL_SKIP; 798 } 799 800 static int handle_set_slice_idx(struct nl80211_state *state, 801 struct nl_cb *cb, 802 struct nl_msg *msg, 803 int argc, char **argv, 804 enum id_input id) 805 { 806 struct nlattr *tmdata; 807 char *end; 808 unsigned int slice_idx; 809 810 //printf("handle_set_slice_idx\n"); 811 812 tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA); 813 if (!tmdata) { 814 //printf("handle_set_slice_idx 1\n"); 815 return 1; 816 } 817 818 slice_idx = strtoul(argv[0], &end, 16); 819 820 if (*end) { 821 //printf("handle_set_slice_idx 2 %d\n", slice_idx); 822 return 1; 823 } 824 825 NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_SLICE_IDX); 826 NLA_PUT_U32(msg, OPENWIFI_ATTR_SLICE_IDX, slice_idx); 827 828 nla_nest_end(msg, tmdata); 829 830 printf("openwifi slice_idx in hex: %08x\n", slice_idx); 831 832 return 0; 833 834 nla_put_failure: 835 return -ENOBUFS; 836 } 837 COMMAND(set, slice_idx, "<slice_idx in hex>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_slice_idx, "set slice_idx"); 838 839 static int handle_get_slice_idx(struct nl80211_state *state, 840 struct nl_cb *cb, 841 struct nl_msg *msg, 842 int argc, char **argv, 843 enum id_input id) 844 { 845 struct nlattr *tmdata; 846 847 tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA); 848 if (!tmdata) 849 return 1; 850 851 NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_SLICE_IDX); 852 853 nla_nest_end(msg, tmdata); 854 855 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_slice_idx_handler, NULL); 856 return 0; 857 858 nla_put_failure: 859 return -ENOBUFS; 860 } 861 COMMAND(get, slice_idx, "<slice_idx in hex>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_slice_idx, "get slice_idx"); 862 863 static int cb_openwifi_slice_target_mac_addr_handler(struct nl_msg *msg, void *arg) 864 { 865 struct nlattr *attrs[NL80211_ATTR_MAX + 1]; 866 struct nlattr *tb[OPENWIFI_ATTR_MAX + 1]; 867 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); 868 869 nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL); 870 871 if (!attrs[NL80211_ATTR_TESTDATA]) 872 return NL_SKIP; 873 874 nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL); 875 876 printf("openwifi slice_target_mac_addr(low32) in hex: %08x\n", nla_get_u32(tb[OPENWIFI_ATTR_ADDR])); 877 878 return NL_SKIP; 879 } 880 881 static int handle_set_slice_target_mac_addr(struct nl80211_state *state, 882 struct nl_cb *cb, 883 struct nl_msg *msg, 884 int argc, char **argv, 885 enum id_input id) 886 { 887 struct nlattr *tmdata; 888 char *end; 889 unsigned int slice_target_mac_addr; 890 891 tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA); 892 if (!tmdata) 893 return 1; 894 895 slice_target_mac_addr = strtoul(argv[0], &end, 16); 896 897 if (*end) 898 return 1; 899 900 NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_ADDR); 901 NLA_PUT_U32(msg, OPENWIFI_ATTR_ADDR, slice_target_mac_addr); 902 903 nla_nest_end(msg, tmdata); 904 905 printf("openwifi slice_target_mac_addr(low32) in hex: %08x\n", slice_target_mac_addr); 906 907 return 0; 908 909 nla_put_failure: 910 return -ENOBUFS; 911 } 912 COMMAND(set, addr, "<slice_target_mac_addr(low32) in hex>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_slice_target_mac_addr, "set addr"); 913 914 static int handle_get_slice_target_mac_addr(struct nl80211_state *state, 915 struct nl_cb *cb, 916 struct nl_msg *msg, 917 int argc, char **argv, 918 enum id_input id) 919 { 920 struct nlattr *tmdata; 921 922 tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA); 923 if (!tmdata) 924 return 1; 925 926 NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_ADDR); 927 928 nla_nest_end(msg, tmdata); 929 930 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_slice_target_mac_addr_handler, NULL); 931 return 0; 932 933 nla_put_failure: 934 return -ENOBUFS; 935 } 936 COMMAND(get, addr, "<slice_target_mac_addr(low32) in hex>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_slice_target_mac_addr, "get addr"); 937 938 static int cb_openwifi_gap_handler(struct nl_msg *msg, void *arg) 939 { 940 struct nlattr *attrs[NL80211_ATTR_MAX + 1]; 941 struct nlattr *tb[OPENWIFI_ATTR_MAX + 1]; 942 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); 943 944 nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL); 945 946 if (!attrs[NL80211_ATTR_TESTDATA]) 947 return NL_SKIP; 948 949 nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL); 950 951 printf("openwifi GAP (usec): %d\n", nla_get_u32(tb[OPENWIFI_ATTR_GAP])); 952 953 return NL_SKIP; 954 } 955 956 static int handle_set_gap(struct nl80211_state *state, 957 struct nl_cb *cb, 958 struct nl_msg *msg, 959 int argc, char **argv, 960 enum id_input id) 961 { 962 struct nlattr *tmdata; 963 char *end; 964 unsigned int gap_us; 965 966 //printf("handle_set_gap\n"); 967 tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA); 968 if (!tmdata) 969 return 1; 970 971 gap_us = strtoul(argv[0], &end, 10); 972 973 if (*end) 974 return 1; 975 976 NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_GAP); 977 NLA_PUT_U32(msg, OPENWIFI_ATTR_GAP, gap_us); 978 979 nla_nest_end(msg, tmdata); 980 return 0; 981 982 nla_put_failure: 983 return -ENOBUFS; 984 } 985 COMMAND(set, gap, "<gap in usec>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_gap, "set inter frame gap of openwifi radio"); 986 987 static int handle_get_gap(struct nl80211_state *state, 988 struct nl_cb *cb, 989 struct nl_msg *msg, 990 int argc, char **argv, 991 enum id_input id) 992 { 993 struct nlattr *tmdata; 994 995 tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA); 996 if (!tmdata) 997 return 1; 998 999 NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_GAP); 1000 1001 nla_nest_end(msg, tmdata); 1002 1003 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_gap_handler, NULL); 1004 return 0; 1005 1006 nla_put_failure: 1007 return -ENOBUFS; 1008 } 1009 COMMAND(get, gap, "<gap in usec>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_gap, "get inter frame gap of openwifi radio"); 1010