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