xref: /openwifi/user_space/sdrctl_src/cmd.c (revision 855b59fd6a93401097234a1948a6fe61b591cced)
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_total_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 	unsigned int tmp;
314 
315 	nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL);
316 
317 	if (!attrs[NL80211_ATTR_TESTDATA])
318 		return NL_SKIP;
319 
320 	nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL);
321 
322 	tmp = nla_get_u32(tb[OPENWIFI_ATTR_SLICE_TOTAL]);
323 	printf("openwifi slice_total (duration) %dus of slice %d\n", tmp&0xFFFFF, tmp>>20);
324 
325 	return NL_SKIP;
326 }
327 
328 static int handle_set_slice_total(struct nl80211_state *state,
329 			  struct nl_cb *cb,
330 			  struct nl_msg *msg,
331 			  int argc, char **argv,
332 			  enum id_input id)
333 {
334 	struct nlattr *tmdata;
335 	char *end;
336 	unsigned int tmp;
337 
338 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
339 	if (!tmdata) {
340 		return 1;
341 	}
342 
343 	tmp = strtoul(argv[0], &end, 10);
344 
345 	if (*end) {
346 		return 1;
347 	}
348 
349 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_SLICE_TOTAL);
350 	NLA_PUT_U32(msg, OPENWIFI_ATTR_SLICE_TOTAL, tmp);
351 
352 	nla_nest_end(msg, tmdata);
353 
354 	printf("openwifi slice_total (duration): %dus\n", tmp);
355 
356 	return 0;
357 
358  nla_put_failure:
359 	return -ENOBUFS;
360 }
361 COMMAND(set, slice_total, "<slice_total(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_slice_total, "set slice_total");
362 
363 static int handle_get_slice_total(struct nl80211_state *state,
364 			  struct nl_cb *cb,
365 			  struct nl_msg *msg,
366 			  int argc, char **argv,
367 			  enum id_input id)
368 {
369 	struct nlattr *tmdata;
370 
371 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
372 	if (!tmdata)
373 		return 1;
374 
375 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_SLICE_TOTAL);
376 
377 	nla_nest_end(msg, tmdata);
378 
379 	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_slice_total_handler, NULL);
380 	return 0;
381 
382  nla_put_failure:
383 	return -ENOBUFS;
384 }
385 COMMAND(get, slice_total, "<slice_total(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_slice_total, "get slice_total");
386 
387 
388 // static int cb_openwifi_slice_total1_handler(struct nl_msg *msg, void *arg)
389 // {
390 // 	struct nlattr *attrs[NL80211_ATTR_MAX + 1];
391 // 	struct nlattr *tb[OPENWIFI_ATTR_MAX + 1];
392 // 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
393 
394 // 	nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL);
395 
396 // 	if (!attrs[NL80211_ATTR_TESTDATA])
397 // 		return NL_SKIP;
398 
399 // 	nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL);
400 
401 // 	printf("openwifi slice_total1 (duration): %dus\n", nla_get_u32(tb[OPENWIFI_ATTR_SLICE_TOTAL1]));
402 
403 // 	return NL_SKIP;
404 // }
405 
406 // static int handle_set_slice_total1(struct nl80211_state *state,
407 // 			  struct nl_cb *cb,
408 // 			  struct nl_msg *msg,
409 // 			  int argc, char **argv,
410 // 			  enum id_input id)
411 // {
412 // 	struct nlattr *tmdata;
413 // 	char *end;
414 // 	unsigned int tmp;
415 
416 // 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
417 // 	if (!tmdata) {
418 // 		return 1;
419 // 	}
420 
421 // 	tmp = strtoul(argv[0], &end, 10);
422 
423 // 	if (*end) {
424 // 		return 1;
425 // 	}
426 
427 // 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_SLICE_TOTAL1);
428 // 	NLA_PUT_U32(msg, OPENWIFI_ATTR_SLICE_TOTAL1, tmp);
429 
430 // 	nla_nest_end(msg, tmdata);
431 
432 // 	printf("openwifi slice_total1 (duration): %dus\n", tmp);
433 
434 // 	return 0;
435 
436 //  nla_put_failure:
437 // 	return -ENOBUFS;
438 // }
439 // COMMAND(set, slice_total1, "<slice_total1(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_slice_total1, "set slice_total1");
440 
441 // static int handle_get_slice_total1(struct nl80211_state *state,
442 // 			  struct nl_cb *cb,
443 // 			  struct nl_msg *msg,
444 // 			  int argc, char **argv,
445 // 			  enum id_input id)
446 // {
447 // 	struct nlattr *tmdata;
448 
449 // 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
450 // 	if (!tmdata)
451 // 		return 1;
452 
453 // 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_SLICE_TOTAL1);
454 
455 // 	nla_nest_end(msg, tmdata);
456 
457 // 	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_slice_total1_handler, NULL);
458 // 	return 0;
459 
460 //  nla_put_failure:
461 // 	return -ENOBUFS;
462 // }
463 // COMMAND(get, slice_total1, "<slice_total1(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_slice_total1, "get slice_total1");
464 
465 static int cb_openwifi_slice_start_handler(struct nl_msg *msg, void *arg)
466 {
467 	struct nlattr *attrs[NL80211_ATTR_MAX + 1];
468 	struct nlattr *tb[OPENWIFI_ATTR_MAX + 1];
469 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
470 	unsigned int tmp;
471 
472 	nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL);
473 
474 	if (!attrs[NL80211_ATTR_TESTDATA])
475 		return NL_SKIP;
476 
477 	nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL);
478 
479 	tmp = nla_get_u32(tb[OPENWIFI_ATTR_SLICE_START]);
480 	printf("openwifi slice_start (duration) %dus of slice %d\n", tmp&0xFFFFF, tmp>>20);
481 
482 	return NL_SKIP;
483 }
484 
485 static int handle_set_slice_start(struct nl80211_state *state,
486 			  struct nl_cb *cb,
487 			  struct nl_msg *msg,
488 			  int argc, char **argv,
489 			  enum id_input id)
490 {
491 	struct nlattr *tmdata;
492 	char *end;
493 	unsigned int tmp;
494 
495 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
496 	if (!tmdata) {
497 		return 1;
498 	}
499 
500 	tmp = strtoul(argv[0], &end, 10);
501 
502 	if (*end) {
503 		return 1;
504 	}
505 
506 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_SLICE_START);
507 	NLA_PUT_U32(msg, OPENWIFI_ATTR_SLICE_START, tmp);
508 
509 	nla_nest_end(msg, tmdata);
510 
511 	printf("openwifi slice_start (duration): %dus\n", tmp);
512 
513 	return 0;
514 
515  nla_put_failure:
516 	return -ENOBUFS;
517 }
518 COMMAND(set, slice_start, "<slice_start(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_slice_start, "set slice_start");
519 
520 static int handle_get_slice_start(struct nl80211_state *state,
521 			  struct nl_cb *cb,
522 			  struct nl_msg *msg,
523 			  int argc, char **argv,
524 			  enum id_input id)
525 {
526 	struct nlattr *tmdata;
527 
528 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
529 	if (!tmdata)
530 		return 1;
531 
532 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_SLICE_START);
533 
534 	nla_nest_end(msg, tmdata);
535 
536 	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_slice_start_handler, NULL);
537 	return 0;
538 
539  nla_put_failure:
540 	return -ENOBUFS;
541 }
542 COMMAND(get, slice_start, "<slice_start(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_slice_start, "get slice_start");
543 
544 
545 // static int cb_openwifi_slice_start1_handler(struct nl_msg *msg, void *arg)
546 // {
547 // 	struct nlattr *attrs[NL80211_ATTR_MAX + 1];
548 // 	struct nlattr *tb[OPENWIFI_ATTR_MAX + 1];
549 // 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
550 
551 // 	nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL);
552 
553 // 	if (!attrs[NL80211_ATTR_TESTDATA])
554 // 		return NL_SKIP;
555 
556 // 	nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL);
557 
558 // 	printf("openwifi slice_start1 (duration): %dus\n", nla_get_u32(tb[OPENWIFI_ATTR_SLICE_START1]));
559 
560 // 	return NL_SKIP;
561 // }
562 
563 // static int handle_set_slice_start1(struct nl80211_state *state,
564 // 			  struct nl_cb *cb,
565 // 			  struct nl_msg *msg,
566 // 			  int argc, char **argv,
567 // 			  enum id_input id)
568 // {
569 // 	struct nlattr *tmdata;
570 // 	char *end;
571 // 	unsigned int tmp;
572 
573 // 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
574 // 	if (!tmdata) {
575 // 		return 1;
576 // 	}
577 
578 // 	tmp = strtoul(argv[0], &end, 10);
579 
580 // 	if (*end) {
581 // 		return 1;
582 // 	}
583 
584 // 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_SLICE_START1);
585 // 	NLA_PUT_U32(msg, OPENWIFI_ATTR_SLICE_START1, tmp);
586 
587 // 	nla_nest_end(msg, tmdata);
588 
589 // 	printf("openwifi slice_start1 (duration): %dus\n", tmp);
590 
591 // 	return 0;
592 
593 //  nla_put_failure:
594 // 	return -ENOBUFS;
595 // }
596 // COMMAND(set, slice_start1, "<slice_start1(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_slice_start1, "set slice_start1");
597 
598 // static int handle_get_slice_start1(struct nl80211_state *state,
599 // 			  struct nl_cb *cb,
600 // 			  struct nl_msg *msg,
601 // 			  int argc, char **argv,
602 // 			  enum id_input id)
603 // {
604 // 	struct nlattr *tmdata;
605 
606 // 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
607 // 	if (!tmdata)
608 // 		return 1;
609 
610 // 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_SLICE_START1);
611 
612 // 	nla_nest_end(msg, tmdata);
613 
614 // 	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_slice_start1_handler, NULL);
615 // 	return 0;
616 
617 //  nla_put_failure:
618 // 	return -ENOBUFS;
619 // }
620 // COMMAND(get, slice_start1, "<slice_start1(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_slice_start1, "get slice_start1");
621 
622 
623 static int cb_openwifi_slice_end_handler(struct nl_msg *msg, void *arg)
624 {
625 	struct nlattr *attrs[NL80211_ATTR_MAX + 1];
626 	struct nlattr *tb[OPENWIFI_ATTR_MAX + 1];
627 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
628 	unsigned int tmp;
629 
630 	nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL);
631 
632 	if (!attrs[NL80211_ATTR_TESTDATA])
633 		return NL_SKIP;
634 
635 	nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL);
636 
637 	tmp = nla_get_u32(tb[OPENWIFI_ATTR_SLICE_END]);
638 	printf("openwifi slice_end (duration) %dus of slice %d\n", tmp&0xFFFFF, tmp>>20);
639 
640 	return NL_SKIP;
641 }
642 
643 static int handle_set_slice_end(struct nl80211_state *state,
644 			  struct nl_cb *cb,
645 			  struct nl_msg *msg,
646 			  int argc, char **argv,
647 			  enum id_input id)
648 {
649 	struct nlattr *tmdata;
650 	char *end;
651 	unsigned int tmp;
652 
653 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
654 	if (!tmdata) {
655 		return 1;
656 	}
657 
658 	tmp = strtoul(argv[0], &end, 10);
659 
660 	if (*end) {
661 		return 1;
662 	}
663 
664 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_SLICE_END);
665 	NLA_PUT_U32(msg, OPENWIFI_ATTR_SLICE_END, tmp);
666 
667 	nla_nest_end(msg, tmdata);
668 
669 	printf("openwifi slice_end (duration): %dus\n", tmp);
670 
671 	return 0;
672 
673  nla_put_failure:
674 	return -ENOBUFS;
675 }
676 COMMAND(set, slice_end, "<slice_end(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_slice_end, "set slice_end");
677 
678 static int handle_get_slice_end(struct nl80211_state *state,
679 			  struct nl_cb *cb,
680 			  struct nl_msg *msg,
681 			  int argc, char **argv,
682 			  enum id_input id)
683 {
684 	struct nlattr *tmdata;
685 
686 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
687 	if (!tmdata)
688 		return 1;
689 
690 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_SLICE_END);
691 
692 	nla_nest_end(msg, tmdata);
693 
694 	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_slice_end_handler, NULL);
695 	return 0;
696 
697  nla_put_failure:
698 	return -ENOBUFS;
699 }
700 COMMAND(get, slice_end, "<slice_end(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_slice_end, "get slice_end");
701 
702 
703 // static int cb_openwifi_slice_end1_handler(struct nl_msg *msg, void *arg)
704 // {
705 // 	struct nlattr *attrs[NL80211_ATTR_MAX + 1];
706 // 	struct nlattr *tb[OPENWIFI_ATTR_MAX + 1];
707 // 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
708 
709 // 	nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL);
710 
711 // 	if (!attrs[NL80211_ATTR_TESTDATA])
712 // 		return NL_SKIP;
713 
714 // 	nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL);
715 
716 // 	printf("openwifi slice_end1 (duration): %dus\n", nla_get_u32(tb[OPENWIFI_ATTR_SLICE_END1]));
717 
718 // 	return NL_SKIP;
719 // }
720 
721 // static int handle_set_slice_end1(struct nl80211_state *state,
722 // 			  struct nl_cb *cb,
723 // 			  struct nl_msg *msg,
724 // 			  int argc, char **argv,
725 // 			  enum id_input id)
726 // {
727 // 	struct nlattr *tmdata;
728 // 	char *end;
729 // 	unsigned int tmp;
730 
731 // 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
732 // 	if (!tmdata) {
733 // 		return 1;
734 // 	}
735 
736 // 	tmp = strtoul(argv[0], &end, 10);
737 
738 // 	if (*end) {
739 // 		return 1;
740 // 	}
741 
742 // 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_SLICE_END1);
743 // 	NLA_PUT_U32(msg, OPENWIFI_ATTR_SLICE_END1, tmp);
744 
745 // 	nla_nest_end(msg, tmdata);
746 
747 // 	printf("openwifi slice_end1 (duration): %dus\n", tmp);
748 
749 // 	return 0;
750 
751 //  nla_put_failure:
752 // 	return -ENOBUFS;
753 // }
754 // COMMAND(set, slice_end1, "<slice_end1(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_slice_end1, "set slice_end1");
755 
756 // static int handle_get_slice_end1(struct nl80211_state *state,
757 // 			  struct nl_cb *cb,
758 // 			  struct nl_msg *msg,
759 // 			  int argc, char **argv,
760 // 			  enum id_input id)
761 // {
762 // 	struct nlattr *tmdata;
763 
764 // 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
765 // 	if (!tmdata)
766 // 		return 1;
767 
768 // 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_SLICE_END1);
769 
770 // 	nla_nest_end(msg, tmdata);
771 
772 // 	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_slice_end1_handler, NULL);
773 // 	return 0;
774 
775 //  nla_put_failure:
776 // 	return -ENOBUFS;
777 // }
778 // COMMAND(get, slice_end1, "<slice_end1(duration) in us>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_slice_end1, "get slice_end1");
779 
780 
781 static int cb_openwifi_slice_idx_handler(struct nl_msg *msg, void *arg)
782 {
783 	struct nlattr *attrs[NL80211_ATTR_MAX + 1];
784 	struct nlattr *tb[OPENWIFI_ATTR_MAX + 1];
785 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
786 
787 	nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL);
788 
789 	if (!attrs[NL80211_ATTR_TESTDATA])
790 		return NL_SKIP;
791 
792 	nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL);
793 
794 	printf("openwifi slice_idx in hex: %08x\n", nla_get_u32(tb[OPENWIFI_ATTR_SLICE_IDX]));
795 
796 	return NL_SKIP;
797 }
798 
799 static int handle_set_slice_idx(struct nl80211_state *state,
800 			  struct nl_cb *cb,
801 			  struct nl_msg *msg,
802 			  int argc, char **argv,
803 			  enum id_input id)
804 {
805 	struct nlattr *tmdata;
806 	char *end;
807 	unsigned int slice_idx;
808 
809 	//printf("handle_set_slice_idx\n");
810 
811 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
812 	if (!tmdata) {
813 		//printf("handle_set_slice_idx 1\n");
814 		return 1;
815 	}
816 
817 	slice_idx = strtoul(argv[0], &end, 16);
818 
819 	if (*end) {
820 		//printf("handle_set_slice_idx 2 %d\n", slice_idx);
821 		return 1;
822 	}
823 
824 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_SLICE_IDX);
825 	NLA_PUT_U32(msg, OPENWIFI_ATTR_SLICE_IDX, slice_idx);
826 
827 	nla_nest_end(msg, tmdata);
828 
829 	printf("openwifi slice_idx in hex: %08x\n", slice_idx);
830 
831 	return 0;
832 
833  nla_put_failure:
834 	return -ENOBUFS;
835 }
836 COMMAND(set, slice_idx, "<slice_idx in hex>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_slice_idx, "set slice_idx");
837 
838 static int handle_get_slice_idx(struct nl80211_state *state,
839 			  struct nl_cb *cb,
840 			  struct nl_msg *msg,
841 			  int argc, char **argv,
842 			  enum id_input id)
843 {
844 	struct nlattr *tmdata;
845 
846 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
847 	if (!tmdata)
848 		return 1;
849 
850 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_SLICE_IDX);
851 
852 	nla_nest_end(msg, tmdata);
853 
854 	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_slice_idx_handler, NULL);
855 	return 0;
856 
857  nla_put_failure:
858 	return -ENOBUFS;
859 }
860 COMMAND(get, slice_idx, "<slice_idx in hex>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_slice_idx, "get slice_idx");
861 
862 static int cb_openwifi_slice_target_mac_addr_handler(struct nl_msg *msg, void *arg)
863 {
864 	struct nlattr *attrs[NL80211_ATTR_MAX + 1];
865 	struct nlattr *tb[OPENWIFI_ATTR_MAX + 1];
866 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
867 
868 	nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL);
869 
870 	if (!attrs[NL80211_ATTR_TESTDATA])
871 		return NL_SKIP;
872 
873 	nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL);
874 
875 	printf("openwifi slice_target_mac_addr(low32) in hex: %08x\n", nla_get_u32(tb[OPENWIFI_ATTR_ADDR]));
876 
877 	return NL_SKIP;
878 }
879 
880 static int handle_set_slice_target_mac_addr(struct nl80211_state *state,
881 			  struct nl_cb *cb,
882 			  struct nl_msg *msg,
883 			  int argc, char **argv,
884 			  enum id_input id)
885 {
886 	struct nlattr *tmdata;
887 	char *end;
888 	unsigned int slice_target_mac_addr;
889 
890 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
891 	if (!tmdata)
892 		return 1;
893 
894 	slice_target_mac_addr = strtoul(argv[0], &end, 16);
895 
896 	if (*end)
897 		return 1;
898 
899 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_ADDR);
900 	NLA_PUT_U32(msg, OPENWIFI_ATTR_ADDR, slice_target_mac_addr);
901 
902 	nla_nest_end(msg, tmdata);
903 
904 	printf("openwifi slice_target_mac_addr(low32) in hex: %08x\n", slice_target_mac_addr);
905 
906 	return 0;
907 
908  nla_put_failure:
909 	return -ENOBUFS;
910 }
911 COMMAND(set, addr, "<slice_target_mac_addr(low32) in hex>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_slice_target_mac_addr, "set addr");
912 
913 static int handle_get_slice_target_mac_addr(struct nl80211_state *state,
914 			  struct nl_cb *cb,
915 			  struct nl_msg *msg,
916 			  int argc, char **argv,
917 			  enum id_input id)
918 {
919 	struct nlattr *tmdata;
920 
921 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
922 	if (!tmdata)
923 		return 1;
924 
925 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_ADDR);
926 
927 	nla_nest_end(msg, tmdata);
928 
929 	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_slice_target_mac_addr_handler, NULL);
930 	return 0;
931 
932  nla_put_failure:
933 	return -ENOBUFS;
934 }
935 COMMAND(get, addr, "<slice_target_mac_addr(low32) in hex>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_slice_target_mac_addr, "get addr");
936 
937 static int cb_openwifi_gap_handler(struct nl_msg *msg, void *arg)
938 {
939 	struct nlattr *attrs[NL80211_ATTR_MAX + 1];
940 	struct nlattr *tb[OPENWIFI_ATTR_MAX + 1];
941 	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
942 
943 	nla_parse(attrs, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL);
944 
945 	if (!attrs[NL80211_ATTR_TESTDATA])
946 		return NL_SKIP;
947 
948 	nla_parse(tb, OPENWIFI_ATTR_MAX, nla_data(attrs[NL80211_ATTR_TESTDATA]), nla_len(attrs[NL80211_ATTR_TESTDATA]), NULL);
949 
950 	printf("openwifi GAP (usec): %d\n", nla_get_u32(tb[OPENWIFI_ATTR_GAP]));
951 
952 	return NL_SKIP;
953 }
954 
955 static int handle_set_gap(struct nl80211_state *state,
956 			  struct nl_cb *cb,
957 			  struct nl_msg *msg,
958 			  int argc, char **argv,
959 			  enum id_input id)
960 {
961 	struct nlattr *tmdata;
962 	char *end;
963 	unsigned int gap_us;
964 
965 	//printf("handle_set_gap\n");
966 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
967 	if (!tmdata)
968 		return 1;
969 
970 	gap_us = strtoul(argv[0], &end, 10);
971 
972 	if (*end)
973 		return 1;
974 
975 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_SET_GAP);
976 	NLA_PUT_U32(msg, OPENWIFI_ATTR_GAP, gap_us);
977 
978 	nla_nest_end(msg, tmdata);
979 	return 0;
980 
981  nla_put_failure:
982 	return -ENOBUFS;
983 }
984 COMMAND(set, gap, "<gap in usec>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_set_gap, "set inter frame gap of openwifi radio");
985 
986 static int handle_get_gap(struct nl80211_state *state,
987 			  struct nl_cb *cb,
988 			  struct nl_msg *msg,
989 			  int argc, char **argv,
990 			  enum id_input id)
991 {
992 	struct nlattr *tmdata;
993 
994 	tmdata = nla_nest_start(msg, NL80211_ATTR_TESTDATA);
995 	if (!tmdata)
996 		return 1;
997 
998 	NLA_PUT_U32(msg, OPENWIFI_ATTR_CMD, OPENWIFI_CMD_GET_GAP);
999 
1000 	nla_nest_end(msg, tmdata);
1001 
1002 	nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_openwifi_gap_handler, NULL);
1003 	return 0;
1004 
1005  nla_put_failure:
1006 	return -ENOBUFS;
1007 }
1008 COMMAND(get, gap, "<gap in usec>", NL80211_CMD_TESTMODE, 0, CIB_NETDEV, handle_get_gap, "get inter frame gap of openwifi radio");
1009