]> git.ipfire.org Git - thirdparty/iw.git/blame - ap.c
iw: Add support for start/stop AP
[thirdparty/iw.git] / ap.c
CommitLineData
60b6c638
IP
1#include <errno.h>
2#include <netlink/genl/genl.h>
3#include <netlink/genl/family.h>
4#include <netlink/genl/ctrl.h>
5#include <netlink/msg.h>
6#include <netlink/attr.h>
7#include "nl80211.h"
8#include "iw.h"
9
10SECTION(ap);
11
12static int handle_start_ap(struct nl80211_state *state,
13 struct nl_msg *msg, int argc, char **argv,
14 enum id_input id)
15{
16 char *end;
17 int val, len;
18 char buf[2304];
19
20 if (argc < 6)
21 return 1;
22
23 /* SSID */
24 NLA_PUT(msg, NL80211_ATTR_SSID, strlen(argv[0]), argv[0]);
25 argv++;
26 argc--;
27
28 /* freq */
29 val = strtoul(argv[0], &end, 10);
30 if (*end != '\0')
31 return -EINVAL;
32
33 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, val);
34 argv++;
35 argc--;
36
37 /* beacon interval */
38 val = strtoul(argv[0], &end, 10);
39 if (*end != '\0')
40 return -EINVAL;
41
42 NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, val);
43 argv++;
44 argc--;
45
46 /* dtim */
47 val = strtoul(argv[0], &end, 10);
48 if (*end != '\0')
49 return -EINVAL;
50
51 NLA_PUT_U32(msg, NL80211_ATTR_DTIM_PERIOD, val);
52 argv++;
53 argc--;
54
55 /* beacon head must be provided */
56 if (strcmp(argv[0], "head") != 0)
57 return -1;
58 argv++;
59 argc--;
60
61 len = strlen(argv[0]);
62 if (!len || (len % 2))
63 return -EINVAL;
64
65 if (!hex2bin(&argv[0][0], buf))
66 return -EINVAL;
67
68 NLA_PUT(msg, NL80211_ATTR_BEACON_HEAD, (len / 2), &buf);
69 argv++;
70 argc--;
71
72 if (!argc)
73 return 0;
74
75 /* tail is optional */
76 if (strcmp(argv[0], "tail") == 0) {
77 argv++;
78 argc--;
79
80 if (!argc)
81 return -EINVAL;
82
83 len = strlen(argv[0]);
84 if (!len || (len % 2))
85 return -EINVAL;
86
87 if (!hex2bin(&argv[0][0], buf))
88 return -EINVAL;
89
90 NLA_PUT(msg, NL80211_ATTR_BEACON_TAIL, (len / 2), &buf);
91 argv++;
92 argc--;
93 }
94
95 if (!argc)
96 return 0;
97
98 if (strcmp(*argv, "key") != 0 && strcmp(*argv, "keys") != 0)
99 return 1;
100
101 argv++;
102 argc--;
103
104 return parse_keys(msg, argv, argc);
105 nla_put_failure:
106 return -ENOSPC;
107}
108COMMAND(ap, start, "",
109 NL80211_CMD_NEW_BEACON, 0, CIB_NETDEV, handle_start_ap,
110 "<SSID> <freq in MHz> <beacon interval in TU> <DTIM period> <head>"
111 " <beacon head in hexadecimal> [<tail> <beacon tail in hexadecimal>]"
112 " [key0:abcde d:1:6162636465]\n");
113
114static int handle_stop_ap(struct nl80211_state *state,
115 struct nl_msg *msg,
116 int argc, char **argv,
117 enum id_input id)
118{
119 return 0;
120}
121COMMAND(ap, stop, "",
122 NL80211_CMD_DEL_BEACON, 0, CIB_NETDEV, handle_stop_ap,
123 "Stop AP functionality\n");