xref: /aosp_15_r20/external/iw/offch.c (revision 92022041c981f431db0b590d0c3272306d0ea2a2)
1 #include <errno.h>
2 
3 #include <netlink/genl/genl.h>
4 #include <netlink/genl/family.h>
5 #include <netlink/genl/ctrl.h>
6 #include <netlink/msg.h>
7 #include <netlink/attr.h>
8 
9 #include "nl80211.h"
10 #include "iw.h"
11 
offchannel(struct nl80211_state * state,struct nl_msg * msg,int argc,char ** argv,enum id_input id)12 static int offchannel(struct nl80211_state *state,
13 		      struct nl_msg *msg, int argc, char **argv,
14 		      enum id_input id)
15 {
16 	char *end;
17 
18 	if (argc < 2)
19 		return 1;
20 
21 	/* freq */
22 	NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ,
23 		    strtoul(argv[0], &end, 10));
24 	if (*end != '\0')
25 		return 1;
26 	argv++;
27 	argc--;
28 
29 	/* duration */
30 	NLA_PUT_U32(msg, NL80211_ATTR_DURATION,
31 		    strtoul(argv[0], &end, 10));
32 	if (*end != '\0')
33 		return 1;
34 	argv++;
35 	argc--;
36 
37 	if (argc)
38 		return 1;
39 
40 	return 0;
41  nla_put_failure:
42 	return -ENOSPC;
43 }
44 
45 TOPLEVEL(offchannel, "<freq> <duration>", NL80211_CMD_REMAIN_ON_CHANNEL, 0,
46 	 CIB_NETDEV, offchannel,
47 	 "Leave operating channel and go to the given channel for a while.");
48