xref: /openwifi/user_space/sdrctl_src/cmd.c (revision 2ee67178825ee52f380c2f72b7135d15ddadca60)
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 static int handle_get_rssi_th(struct nl80211_state *state,
219 			  struct nl_cb *cb,
220 			  struct nl_msg *msg,
221 			  int argc, char **argv,
222 			  enum id_input id)
223 {
224 	struct nlattr *tmdata;
225 
226 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
227 	if (!tmdata)
228 		return 1;
229 
230 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_RSSI_TH);
231 
232 	nla_nest_end(msg, tmdata);
233 
234 	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_rssi_th_handler, NULL);
235 	return 0;
236 
237  nla_put_failure:
238 	return -ENOBUFS;
239 }
240 COMMAND(get, rssi_th, "<rssi_th in value>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_rssi_th, "get rssi_th");
241 
242 static int cb_openwifi_slice_total0_handler(struct nl_msg *msg, void *arg)
243 {
244 	struct nlattr *attrs[NL80211_ATTR_MAX + 1];
245 	struct nlattr *tb[OPENWIFI_ATTR_MAX + 1];
246 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
247 
248 	nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL);
249 
250 	if (!attrs[NL80211_ATTR_TESTDATA])
251 		return NL_SKIP;
252 
253 	nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL);
254 
255 	printf("openwifi slice_total0 (duration): %dus\n", nla_get_u32(tb[OPENWIFI_ATTR_SLICE_TOTAL0]));
256 
257 	return NL_SKIP;
258 }
259 
260 static int handle_set_slice_total0(struct nl80211_state *state,
261 			  struct nl_cb *cb,
262 			  struct nl_msg *msg,
263 			  int argc, char **argv,
264 			  enum id_input id)
265 {
266 	struct nlattr *tmdata;
267 	char *end;
268 	unsigned int tmp;
269 
270 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
271 	if (!tmdata) {
272 		return 1;
273 	}
274 
275 	tmp = strtoul(argv[0], &end, 10);
276 
277 	if (*end) {
278 		return 1;
279 	}
280 
281 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_SLICE_TOTAL0);
282 	NLA_PUT_U32(msg, OPENWIFI_ATTR_SLICE_TOTAL0, tmp);
283 
284 	nla_nest_end(msg, tmdata);
285 
286 	printf("openwifi slice_total0 (duration): %dus\n", tmp);
287 
288 	return 0;
289 
290  nla_put_failure:
291 	return -ENOBUFS;
292 }
293 COMMAND(set, slice_total0, "<slice_total0(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_slice_total0, "set slice_total0");
294 
295 static int handle_get_slice_total0(struct nl80211_state *state,
296 			  struct nl_cb *cb,
297 			  struct nl_msg *msg,
298 			  int argc, char **argv,
299 			  enum id_input id)
300 {
301 	struct nlattr *tmdata;
302 
303 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
304 	if (!tmdata)
305 		return 1;
306 
307 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_SLICE_TOTAL0);
308 
309 	nla_nest_end(msg, tmdata);
310 
311 	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_slice_total0_handler, NULL);
312 	return 0;
313 
314  nla_put_failure:
315 	return -ENOBUFS;
316 }
317 COMMAND(get, slice_total0, "<slice_total0(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_slice_total0, "get slice_total0");
318 
319 
320 static int cb_openwifi_slice_total1_handler(struct nl_msg *msg, void *arg)
321 {
322 	struct nlattr *attrs[NL80211_ATTR_MAX + 1];
323 	struct nlattr *tb[OPENWIFI_ATTR_MAX + 1];
324 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
325 
326 	nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL);
327 
328 	if (!attrs[NL80211_ATTR_TESTDATA])
329 		return NL_SKIP;
330 
331 	nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL);
332 
333 	printf("openwifi slice_total1 (duration): %dus\n", nla_get_u32(tb[OPENWIFI_ATTR_SLICE_TOTAL1]));
334 
335 	return NL_SKIP;
336 }
337 
338 static int handle_set_slice_total1(struct nl80211_state *state,
339 			  struct nl_cb *cb,
340 			  struct nl_msg *msg,
341 			  int argc, char **argv,
342 			  enum id_input id)
343 {
344 	struct nlattr *tmdata;
345 	char *end;
346 	unsigned int tmp;
347 
348 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
349 	if (!tmdata) {
350 		return 1;
351 	}
352 
353 	tmp = strtoul(argv[0], &end, 10);
354 
355 	if (*end) {
356 		return 1;
357 	}
358 
359 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_SLICE_TOTAL1);
360 	NLA_PUT_U32(msg, OPENWIFI_ATTR_SLICE_TOTAL1, tmp);
361 
362 	nla_nest_end(msg, tmdata);
363 
364 	printf("openwifi slice_total1 (duration): %dus\n", tmp);
365 
366 	return 0;
367 
368  nla_put_failure:
369 	return -ENOBUFS;
370 }
371 COMMAND(set, slice_total1, "<slice_total1(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_slice_total1, "set slice_total1");
372 
373 static int handle_get_slice_total1(struct nl80211_state *state,
374 			  struct nl_cb *cb,
375 			  struct nl_msg *msg,
376 			  int argc, char **argv,
377 			  enum id_input id)
378 {
379 	struct nlattr *tmdata;
380 
381 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
382 	if (!tmdata)
383 		return 1;
384 
385 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_SLICE_TOTAL1);
386 
387 	nla_nest_end(msg, tmdata);
388 
389 	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_slice_total1_handler, NULL);
390 	return 0;
391 
392  nla_put_failure:
393 	return -ENOBUFS;
394 }
395 COMMAND(get, slice_total1, "<slice_total1(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_slice_total1, "get slice_total1");
396 
397 
398 static int cb_openwifi_slice_start0_handler(struct nl_msg *msg, void *arg)
399 {
400 	struct nlattr *attrs[NL80211_ATTR_MAX + 1];
401 	struct nlattr *tb[OPENWIFI_ATTR_MAX + 1];
402 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
403 
404 	nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL);
405 
406 	if (!attrs[NL80211_ATTR_TESTDATA])
407 		return NL_SKIP;
408 
409 	nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL);
410 
411 	printf("openwifi slice_start0 (duration): %dus\n", nla_get_u32(tb[OPENWIFI_ATTR_SLICE_START0]));
412 
413 	return NL_SKIP;
414 }
415 
416 static int handle_set_slice_start0(struct nl80211_state *state,
417 			  struct nl_cb *cb,
418 			  struct nl_msg *msg,
419 			  int argc, char **argv,
420 			  enum id_input id)
421 {
422 	struct nlattr *tmdata;
423 	char *end;
424 	unsigned int tmp;
425 
426 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
427 	if (!tmdata) {
428 		return 1;
429 	}
430 
431 	tmp = strtoul(argv[0], &end, 10);
432 
433 	if (*end) {
434 		return 1;
435 	}
436 
437 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_SLICE_START0);
438 	NLA_PUT_U32(msg, OPENWIFI_ATTR_SLICE_START0, tmp);
439 
440 	nla_nest_end(msg, tmdata);
441 
442 	printf("openwifi slice_start0 (duration): %dus\n", tmp);
443 
444 	return 0;
445 
446  nla_put_failure:
447 	return -ENOBUFS;
448 }
449 COMMAND(set, slice_start0, "<slice_start0(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_slice_start0, "set slice_start0");
450 
451 static int handle_get_slice_start0(struct nl80211_state *state,
452 			  struct nl_cb *cb,
453 			  struct nl_msg *msg,
454 			  int argc, char **argv,
455 			  enum id_input id)
456 {
457 	struct nlattr *tmdata;
458 
459 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
460 	if (!tmdata)
461 		return 1;
462 
463 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_SLICE_START0);
464 
465 	nla_nest_end(msg, tmdata);
466 
467 	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_slice_start0_handler, NULL);
468 	return 0;
469 
470  nla_put_failure:
471 	return -ENOBUFS;
472 }
473 COMMAND(get, slice_start0, "<slice_start0(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_slice_start0, "get slice_start0");
474 
475 
476 static int cb_openwifi_slice_start1_handler(struct nl_msg *msg, void *arg)
477 {
478 	struct nlattr *attrs[NL80211_ATTR_MAX + 1];
479 	struct nlattr *tb[OPENWIFI_ATTR_MAX + 1];
480 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
481 
482 	nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL);
483 
484 	if (!attrs[NL80211_ATTR_TESTDATA])
485 		return NL_SKIP;
486 
487 	nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL);
488 
489 	printf("openwifi slice_start1 (duration): %dus\n", nla_get_u32(tb[OPENWIFI_ATTR_SLICE_START1]));
490 
491 	return NL_SKIP;
492 }
493 
494 static int handle_set_slice_start1(struct nl80211_state *state,
495 			  struct nl_cb *cb,
496 			  struct nl_msg *msg,
497 			  int argc, char **argv,
498 			  enum id_input id)
499 {
500 	struct nlattr *tmdata;
501 	char *end;
502 	unsigned int tmp;
503 
504 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
505 	if (!tmdata) {
506 		return 1;
507 	}
508 
509 	tmp = strtoul(argv[0], &end, 10);
510 
511 	if (*end) {
512 		return 1;
513 	}
514 
515 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_SLICE_START1);
516 	NLA_PUT_U32(msg, OPENWIFI_ATTR_SLICE_START1, tmp);
517 
518 	nla_nest_end(msg, tmdata);
519 
520 	printf("openwifi slice_start1 (duration): %dus\n", tmp);
521 
522 	return 0;
523 
524  nla_put_failure:
525 	return -ENOBUFS;
526 }
527 COMMAND(set, slice_start1, "<slice_start1(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_slice_start1, "set slice_start1");
528 
529 static int handle_get_slice_start1(struct nl80211_state *state,
530 			  struct nl_cb *cb,
531 			  struct nl_msg *msg,
532 			  int argc, char **argv,
533 			  enum id_input id)
534 {
535 	struct nlattr *tmdata;
536 
537 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
538 	if (!tmdata)
539 		return 1;
540 
541 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_SLICE_START1);
542 
543 	nla_nest_end(msg, tmdata);
544 
545 	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_slice_start1_handler, NULL);
546 	return 0;
547 
548  nla_put_failure:
549 	return -ENOBUFS;
550 }
551 COMMAND(get, slice_start1, "<slice_start1(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_slice_start1, "get slice_start1");
552 
553 
554 static int cb_openwifi_slice_end0_handler(struct nl_msg *msg, void *arg)
555 {
556 	struct nlattr *attrs[NL80211_ATTR_MAX + 1];
557 	struct nlattr *tb[OPENWIFI_ATTR_MAX + 1];
558 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
559 
560 	nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL);
561 
562 	if (!attrs[NL80211_ATTR_TESTDATA])
563 		return NL_SKIP;
564 
565 	nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL);
566 
567 	printf("openwifi slice_end0 (duration): %dus\n", nla_get_u32(tb[OPENWIFI_ATTR_SLICE_END0]));
568 
569 	return NL_SKIP;
570 }
571 
572 static int handle_set_slice_end0(struct nl80211_state *state,
573 			  struct nl_cb *cb,
574 			  struct nl_msg *msg,
575 			  int argc, char **argv,
576 			  enum id_input id)
577 {
578 	struct nlattr *tmdata;
579 	char *end;
580 	unsigned int tmp;
581 
582 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
583 	if (!tmdata) {
584 		return 1;
585 	}
586 
587 	tmp = strtoul(argv[0], &end, 10);
588 
589 	if (*end) {
590 		return 1;
591 	}
592 
593 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_SLICE_END0);
594 	NLA_PUT_U32(msg, OPENWIFI_ATTR_SLICE_END0, tmp);
595 
596 	nla_nest_end(msg, tmdata);
597 
598 	printf("openwifi slice_end0 (duration): %dus\n", tmp);
599 
600 	return 0;
601 
602  nla_put_failure:
603 	return -ENOBUFS;
604 }
605 COMMAND(set, slice_end0, "<slice_end0(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_slice_end0, "set slice_end0");
606 
607 static int handle_get_slice_end0(struct nl80211_state *state,
608 			  struct nl_cb *cb,
609 			  struct nl_msg *msg,
610 			  int argc, char **argv,
611 			  enum id_input id)
612 {
613 	struct nlattr *tmdata;
614 
615 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
616 	if (!tmdata)
617 		return 1;
618 
619 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_SLICE_END0);
620 
621 	nla_nest_end(msg, tmdata);
622 
623 	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_slice_end0_handler, NULL);
624 	return 0;
625 
626  nla_put_failure:
627 	return -ENOBUFS;
628 }
629 COMMAND(get, slice_end0, "<slice_end0(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_slice_end0, "get slice_end0");
630 
631 
632 static int cb_openwifi_slice_end1_handler(struct nl_msg *msg, void *arg)
633 {
634 	struct nlattr *attrs[NL80211_ATTR_MAX + 1];
635 	struct nlattr *tb[OPENWIFI_ATTR_MAX + 1];
636 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
637 
638 	nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL);
639 
640 	if (!attrs[NL80211_ATTR_TESTDATA])
641 		return NL_SKIP;
642 
643 	nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL);
644 
645 	printf("openwifi slice_end1 (duration): %dus\n", nla_get_u32(tb[OPENWIFI_ATTR_SLICE_END1]));
646 
647 	return NL_SKIP;
648 }
649 
650 static int handle_set_slice_end1(struct nl80211_state *state,
651 			  struct nl_cb *cb,
652 			  struct nl_msg *msg,
653 			  int argc, char **argv,
654 			  enum id_input id)
655 {
656 	struct nlattr *tmdata;
657 	char *end;
658 	unsigned int tmp;
659 
660 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
661 	if (!tmdata) {
662 		return 1;
663 	}
664 
665 	tmp = strtoul(argv[0], &end, 10);
666 
667 	if (*end) {
668 		return 1;
669 	}
670 
671 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_SLICE_END1);
672 	NLA_PUT_U32(msg, OPENWIFI_ATTR_SLICE_END1, tmp);
673 
674 	nla_nest_end(msg, tmdata);
675 
676 	printf("openwifi slice_end1 (duration): %dus\n", tmp);
677 
678 	return 0;
679 
680  nla_put_failure:
681 	return -ENOBUFS;
682 }
683 COMMAND(set, slice_end1, "<slice_end1(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_slice_end1, "set slice_end1");
684 
685 static int handle_get_slice_end1(struct nl80211_state *state,
686 			  struct nl_cb *cb,
687 			  struct nl_msg *msg,
688 			  int argc, char **argv,
689 			  enum id_input id)
690 {
691 	struct nlattr *tmdata;
692 
693 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
694 	if (!tmdata)
695 		return 1;
696 
697 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_SLICE_END1);
698 
699 	nla_nest_end(msg, tmdata);
700 
701 	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_slice_end1_handler, NULL);
702 	return 0;
703 
704  nla_put_failure:
705 	return -ENOBUFS;
706 }
707 COMMAND(get, slice_end1, "<slice_end1(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_slice_end1, "get slice_end1");
708 
709 
710 static int cb_openwifi_slice0_target_mac_addr_handler(struct nl_msg *msg, void *arg)
711 {
712 	struct nlattr *attrs[NL80211_ATTR_MAX + 1];
713 	struct nlattr *tb[OPENWIFI_ATTR_MAX + 1];
714 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
715 
716 	nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL);
717 
718 	if (!attrs[NL80211_ATTR_TESTDATA])
719 		return NL_SKIP;
720 
721 	nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL);
722 
723 	printf("openwifi slice0_target_mac_addr(low32) in hex: %08x\n", nla_get_u32(tb[OPENWIFI_ATTR_ADDR0]));
724 
725 	return NL_SKIP;
726 }
727 
728 static int handle_set_addr0(struct nl80211_state *state,
729 			  struct nl_cb *cb,
730 			  struct nl_msg *msg,
731 			  int argc, char **argv,
732 			  enum id_input id)
733 {
734 	struct nlattr *tmdata;
735 	char *end;
736 	unsigned int slice0_target_mac_addr;
737 
738 	//printf("handle_set_slice0_target_mac_addr\n");
739 
740 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
741 	if (!tmdata) {
742 		//printf("handle_set_slice0_target_mac_addr 1\n");
743 		return 1;
744 	}
745 
746 	slice0_target_mac_addr = strtoul(argv[0], &end, 16);
747 
748 	if (*end) {
749 		//printf("handle_set_slice0_target_mac_addr 2 %d\n", slice0_target_mac_addr);
750 		return 1;
751 	}
752 
753 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_ADDR0);
754 	NLA_PUT_U32(msg, OPENWIFI_ATTR_ADDR0, slice0_target_mac_addr);
755 
756 	nla_nest_end(msg, tmdata);
757 
758 	printf("openwifi slice0_target_mac_addr(low32) in hex: %08x\n", slice0_target_mac_addr);
759 
760 	return 0;
761 
762  nla_put_failure:
763 	return -ENOBUFS;
764 }
765 COMMAND(set, addr0, "<slice0_target_mac_addr(low32) in hex>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_addr0, "set addr0");
766 
767 static int handle_get_slice0_target_mac_addr(struct nl80211_state *state,
768 			  struct nl_cb *cb,
769 			  struct nl_msg *msg,
770 			  int argc, char **argv,
771 			  enum id_input id)
772 {
773 	struct nlattr *tmdata;
774 
775 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
776 	if (!tmdata)
777 		return 1;
778 
779 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_ADDR0);
780 
781 	nla_nest_end(msg, tmdata);
782 
783 	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_slice0_target_mac_addr_handler, NULL);
784 	return 0;
785 
786  nla_put_failure:
787 	return -ENOBUFS;
788 }
789 COMMAND(get, addr0, "<slice0_target_mac_addr(low32) in hex>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_slice0_target_mac_addr, "get addr0");
790 
791 static int cb_openwifi_slice1_target_mac_addr_handler(struct nl_msg *msg, void *arg)
792 {
793 	struct nlattr *attrs[NL80211_ATTR_MAX + 1];
794 	struct nlattr *tb[OPENWIFI_ATTR_MAX + 1];
795 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
796 
797 	nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL);
798 
799 	if (!attrs[NL80211_ATTR_TESTDATA])
800 		return NL_SKIP;
801 
802 	nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL);
803 
804 	printf("openwifi slice1_target_mac_addr(low32) in hex: %08x\n", nla_get_u32(tb[OPENWIFI_ATTR_ADDR1]));
805 
806 	return NL_SKIP;
807 }
808 
809 static int handle_set_slice1_target_mac_addr(struct nl80211_state *state,
810 			  struct nl_cb *cb,
811 			  struct nl_msg *msg,
812 			  int argc, char **argv,
813 			  enum id_input id)
814 {
815 	struct nlattr *tmdata;
816 	char *end;
817 	unsigned int slice1_target_mac_addr;
818 
819 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
820 	if (!tmdata)
821 		return 1;
822 
823 	slice1_target_mac_addr = strtoul(argv[0], &end, 16);
824 
825 	if (*end)
826 		return 1;
827 
828 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_ADDR1);
829 	NLA_PUT_U32(msg, OPENWIFI_ATTR_ADDR1, slice1_target_mac_addr);
830 
831 	nla_nest_end(msg, tmdata);
832 
833 	printf("openwifi slice1_target_mac_addr(low32) in hex: %08x\n", slice1_target_mac_addr);
834 
835 	return 0;
836 
837  nla_put_failure:
838 	return -ENOBUFS;
839 }
840 COMMAND(set, addr1, "<slice1_target_mac_addr(low32) in hex>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_slice1_target_mac_addr, "set addr1");
841 
842 static int handle_get_slice1_target_mac_addr(struct nl80211_state *state,
843 			  struct nl_cb *cb,
844 			  struct nl_msg *msg,
845 			  int argc, char **argv,
846 			  enum id_input id)
847 {
848 	struct nlattr *tmdata;
849 
850 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
851 	if (!tmdata)
852 		return 1;
853 
854 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_ADDR1);
855 
856 	nla_nest_end(msg, tmdata);
857 
858 	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_slice1_target_mac_addr_handler, NULL);
859 	return 0;
860 
861  nla_put_failure:
862 	return -ENOBUFS;
863 }
864 COMMAND(get, addr1, "<slice1_target_mac_addr(low32) in hex>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_slice1_target_mac_addr, "get addr1");
865 
866 static int cb_openwifi_gap_handler(struct nl_msg *msg, void *arg)
867 {
868 	struct nlattr *attrs[NL80211_ATTR_MAX + 1];
869 	struct nlattr *tb[OPENWIFI_ATTR_MAX + 1];
870 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
871 
872 	nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL);
873 
874 	if (!attrs[NL80211_ATTR_TESTDATA])
875 		return NL_SKIP;
876 
877 	nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL);
878 
879 	printf("openwifi GAP (usec): %d\n", nla_get_u32(tb[OPENWIFI_ATTR_GAP]));
880 
881 	return NL_SKIP;
882 }
883 
884 static int handle_set_gap(struct nl80211_state *state,
885 			  struct nl_cb *cb,
886 			  struct nl_msg *msg,
887 			  int argc, char **argv,
888 			  enum id_input id)
889 {
890 	struct nlattr *tmdata;
891 	char *end;
892 	unsigned int gap_us;
893 
894 	//printf("handle_set_gap\n");
895 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
896 	if (!tmdata)
897 		return 1;
898 
899 	gap_us = strtoul(argv[0], &end, 10);
900 
901 	if (*end)
902 		return 1;
903 
904 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_GAP);
905 	NLA_PUT_U32(msg, OPENWIFI_ATTR_GAP, gap_us);
906 
907 	nla_nest_end(msg, tmdata);
908 	return 0;
909 
910  nla_put_failure:
911 	return -ENOBUFS;
912 }
913 COMMAND(set, gap, "<gap in usec>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_gap, "set inter frame gap of openwifi radio");
914 
915 static int handle_get_gap(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_GAP);
928 
929 	nla_nest_end(msg, tmdata);
930 
931 	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_gap_handler, NULL);
932 	return 0;
933 
934  nla_put_failure:
935 	return -ENOBUFS;
936 }
937 COMMAND(get, gap, "<gap in usec>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_gap, "get inter frame gap of openwifi radio");
938