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