]> git.ipfire.org Git - thirdparty/iw.git/blob - ibss.c
iw: add support for NL80211_CMD_DEL_STATION event
[thirdparty/iw.git] / ibss.c
1 #ifndef _POSIX_SOURCE
2 #define _POSIX_SOURCE
3 #endif
4 #include <errno.h>
5 #include <string.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 "iw.h"
16
17 SECTION(ibss);
18
19 static int join_ibss(struct nl80211_state *state,
20 struct nl_cb *cb,
21 struct nl_msg *msg,
22 int argc, char **argv)
23 {
24 char *end;
25 unsigned char abssid[6];
26 unsigned char rates[NL80211_MAX_SUPP_RATES];
27 int n_rates = 0;
28 char *value = NULL, *sptr = NULL;
29 float rate;
30 int bintval;
31 int i;
32 static const struct {
33 const char *name;
34 unsigned int val;
35 } htmap[] = {
36 { .name = "HT20", .val = NL80211_CHAN_HT20, },
37 { .name = "HT40+", .val = NL80211_CHAN_HT40PLUS, },
38 { .name = "HT40-", .val = NL80211_CHAN_HT40MINUS, },
39 { .name = "NOHT", .val = NL80211_CHAN_NO_HT, },
40 };
41 unsigned int htval;
42
43 if (argc < 2)
44 return 1;
45
46 /* SSID */
47 NLA_PUT(msg, NL80211_ATTR_SSID, strlen(argv[0]), argv[0]);
48 argv++;
49 argc--;
50
51 /* freq */
52 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ,
53 strtoul(argv[0], &end, 10));
54 if (*end != '\0')
55 return 1;
56 argv++;
57 argc--;
58
59 if (argc) {
60 for (i = 0; i < ARRAY_SIZE(htmap); i++) {
61 if (strcasecmp(htmap[i].name, argv[0]) == 0) {
62 htval = htmap[i].val;
63 break;
64 }
65 }
66 if (i != ARRAY_SIZE(htmap)) {
67 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
68 htval);
69 argv++;
70 argc--;
71 }
72
73 }
74
75 if (argc && strcmp(argv[0], "fixed-freq") == 0) {
76 NLA_PUT_FLAG(msg, NL80211_ATTR_FREQ_FIXED);
77 argv++;
78 argc--;
79 }
80
81 if (argc) {
82 if (mac_addr_a2n(abssid, argv[0]) == 0) {
83 NLA_PUT(msg, NL80211_ATTR_MAC, 6, abssid);
84 argv++;
85 argc--;
86 }
87 }
88
89 if (argc > 1 && strcmp(argv[0], "beacon-interval") == 0) {
90 argv++;
91 argc--;
92 bintval = strtoul(argv[0], &end, 10);
93 if (*end != '\0')
94 return 1;
95 NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, bintval);
96 argv++;
97 argc--;
98 }
99
100 /* basic rates */
101 if (argc > 1 && strcmp(argv[0], "basic-rates") == 0) {
102 argv++;
103 argc--;
104
105 value = strtok_r(argv[0], ",", &sptr);
106
107 while (value && n_rates < NL80211_MAX_SUPP_RATES) {
108 rate = strtod(value, &end);
109 rates[n_rates] = rate * 2;
110
111 /* filter out suspicious values */
112 if (*end != '\0' || !rates[n_rates] ||
113 rate*2 != rates[n_rates])
114 return 1;
115
116 n_rates++;
117 value = strtok_r(NULL, ",", &sptr);
118 }
119
120 NLA_PUT(msg, NL80211_ATTR_BSS_BASIC_RATES, n_rates, rates);
121
122 argv++;
123 argc--;
124 }
125
126 /* multicast rate */
127 if (argc > 1 && strcmp(argv[0], "mcast-rate") == 0) {
128 argv++;
129 argc--;
130
131 rate = strtod(argv[0], &end);
132 if (*end != '\0')
133 return 1;
134
135 NLA_PUT_U32(msg, NL80211_ATTR_MCAST_RATE, (int)(rate * 10));
136 argv++;
137 argc--;
138 }
139
140 if (!argc)
141 return 0;
142
143 if (strcmp(*argv, "key") != 0 && strcmp(*argv, "keys") != 0)
144 return 1;
145
146 argv++;
147 argc--;
148
149 return parse_keys(msg, argv, argc);
150 nla_put_failure:
151 return -ENOSPC;
152 }
153
154 static int leave_ibss(struct nl80211_state *state,
155 struct nl_cb *cb,
156 struct nl_msg *msg,
157 int argc, char **argv)
158 {
159 return 0;
160 }
161 COMMAND(ibss, leave, NULL,
162 NL80211_CMD_LEAVE_IBSS, 0, CIB_NETDEV, leave_ibss,
163 "Leave the current IBSS cell.");
164 COMMAND(ibss, join,
165 "<SSID> <freq in MHz> [HT20|HT40+|HT40-|NOHT] [fixed-freq] [<fixed bssid>] [beacon-interval <TU>]"
166 " [basic-rates <rate in Mbps,rate2,...>] [mcast-rate <rate in Mbps>] "
167 "[key d:0:abcde]",
168 NL80211_CMD_JOIN_IBSS, 0, CIB_NETDEV, join_ibss,
169 "Join the IBSS cell with the given SSID, if it doesn't exist create\n"
170 "it on the given frequency. When fixed frequency is requested, don't\n"
171 "join/create a cell on a different frequency. When a fixed BSSID is\n"
172 "requested use that BSSID and do not adopt another cell's BSSID even\n"
173 "if it has higher TSF and the same SSID. If an IBSS is created, create\n"
174 "it with the specified basic-rates, multicast-rate and beacon-interval.");