]> git.ipfire.org Git - thirdparty/iw.git/blame - ibss.c
iw: nan: Add NAN interface type
[thirdparty/iw.git] / ibss.c
CommitLineData
edea4d14 1#include <errno.h>
b893686f 2#include <string.h>
135cb523 3#include <strings.h>
edea4d14 4
edea4d14
JB
5#include "nl80211.h"
6#include "iw.h"
7
4698bfc2
JB
8SECTION(ibss);
9
edea4d14 10static int join_ibss(struct nl80211_state *state,
edea4d14 11 struct nl_msg *msg,
05514f95
JB
12 int argc, char **argv,
13 enum id_input id)
edea4d14 14{
95940df3 15 char *end;
edea4d14 16 unsigned char abssid[6];
6a24bb22
TP
17 unsigned char rates[NL80211_MAX_SUPP_RATES];
18 int n_rates = 0;
19 char *value = NULL, *sptr = NULL;
20 float rate;
ec46ba52 21 int bintval;
0ee571d5 22 unsigned int i;
85da7703 23 unsigned long freq;
faeef830
JD
24 const struct chanmode *chanmode_selected = NULL;
25 static const struct chanmode chanmode[] = {
85da7703
SW
26 { .name = "HT20",
27 .width = NL80211_CHAN_WIDTH_20,
28 .freq1_diff = 0,
29 .chantype = NL80211_CHAN_HT20 },
30 { .name = "HT40+",
31 .width = NL80211_CHAN_WIDTH_40,
32 .freq1_diff = 10,
33 .chantype = NL80211_CHAN_HT40PLUS },
34 { .name = "HT40-",
35 .width = NL80211_CHAN_WIDTH_40,
36 .freq1_diff = -10,
37 .chantype = NL80211_CHAN_HT40MINUS },
38 { .name = "NOHT",
39 .width = NL80211_CHAN_WIDTH_20_NOHT,
40 .freq1_diff = 0,
41 .chantype = NL80211_CHAN_NO_HT },
7187aada 42 { .name = "5MHz",
85da7703
SW
43 .width = NL80211_CHAN_WIDTH_5,
44 .freq1_diff = 0,
45 .chantype = -1 },
7187aada 46 { .name = "10MHz",
85da7703
SW
47 .width = NL80211_CHAN_WIDTH_10,
48 .freq1_diff = 0,
49 .chantype = -1 },
7187aada 50 { .name = "80MHz",
faeef830
JD
51 .width = NL80211_CHAN_WIDTH_80,
52 .freq1_diff = 0,
53 .chantype = -1 },
135cb523 54 };
edea4d14 55
95940df3
JB
56 if (argc < 2)
57 return 1;
edea4d14 58
95940df3
JB
59 /* SSID */
60 NLA_PUT(msg, NL80211_ATTR_SSID, strlen(argv[0]), argv[0]);
edea4d14
JB
61 argv++;
62 argc--;
63
95940df3 64 /* freq */
85da7703 65 freq = strtoul(argv[0], &end, 10);
95940df3
JB
66 if (*end != '\0')
67 return 1;
85da7703
SW
68
69 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
95940df3
JB
70 argv++;
71 argc--;
edea4d14 72
135cb523 73 if (argc) {
85da7703
SW
74 for (i = 0; i < ARRAY_SIZE(chanmode); i++) {
75 if (strcasecmp(chanmode[i].name, argv[0]) == 0) {
76 chanmode_selected = &chanmode[i];
135cb523
SW
77 break;
78 }
79 }
85da7703
SW
80 if (chanmode_selected) {
81 NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH,
82 chanmode_selected->width);
83 NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ1,
faeef830 84 get_cf1(chanmode_selected, freq));
85da7703
SW
85 if (chanmode_selected->chantype != -1)
86 NLA_PUT_U32(msg,
87 NL80211_ATTR_WIPHY_CHANNEL_TYPE,
88 chanmode_selected->chantype);
89
135cb523
SW
90 argv++;
91 argc--;
92 }
93
94 }
95
95940df3
JB
96 if (argc && strcmp(argv[0], "fixed-freq") == 0) {
97 NLA_PUT_FLAG(msg, NL80211_ATTR_FREQ_FIXED);
98 argv++;
99 argc--;
edea4d14
JB
100 }
101
95940df3 102 if (argc) {
51e9bd80
JB
103 if (mac_addr_a2n(abssid, argv[0]) == 0) {
104 NLA_PUT(msg, NL80211_ATTR_MAC, 6, abssid);
105 argv++;
106 argc--;
107 }
edea4d14
JB
108 }
109
ec46ba52
BR
110 if (argc > 1 && strcmp(argv[0], "beacon-interval") == 0) {
111 argv++;
112 argc--;
113 bintval = strtoul(argv[0], &end, 10);
114 if (*end != '\0')
115 return 1;
116 NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, bintval);
117 argv++;
118 argc--;
119 }
120
6a24bb22
TP
121 /* basic rates */
122 if (argc > 1 && strcmp(argv[0], "basic-rates") == 0) {
123 argv++;
124 argc--;
125
126 value = strtok_r(argv[0], ",", &sptr);
127
128 while (value && n_rates < NL80211_MAX_SUPP_RATES) {
129 rate = strtod(value, &end);
130 rates[n_rates] = rate * 2;
131
132 /* filter out suspicious values */
133 if (*end != '\0' || !rates[n_rates] ||
134 rate*2 != rates[n_rates])
135 return 1;
136
137 n_rates++;
138 value = strtok_r(NULL, ",", &sptr);
139 }
140
141 NLA_PUT(msg, NL80211_ATTR_BSS_BASIC_RATES, n_rates, rates);
142
143 argv++;
144 argc--;
145 }
146
506b442b
FF
147 /* multicast rate */
148 if (argc > 1 && strcmp(argv[0], "mcast-rate") == 0) {
149 argv++;
150 argc--;
151
152 rate = strtod(argv[0], &end);
153 if (*end != '\0')
154 return 1;
155
e399be8c 156 NLA_PUT_U32(msg, NL80211_ATTR_MCAST_RATE, (int)(rate * 10));
506b442b
FF
157 argv++;
158 argc--;
159 }
160
1e03690e
JB
161 if (!argc)
162 return 0;
edea4d14 163
1e03690e
JB
164 if (strcmp(*argv, "key") != 0 && strcmp(*argv, "keys") != 0)
165 return 1;
ded1f078 166
1e03690e
JB
167 argv++;
168 argc--;
51e9bd80 169
1e03690e 170 return parse_keys(msg, argv, argc);
edea4d14
JB
171 nla_put_failure:
172 return -ENOSPC;
173}
174
175static int leave_ibss(struct nl80211_state *state,
edea4d14 176 struct nl_msg *msg,
05514f95
JB
177 int argc, char **argv,
178 enum id_input id)
edea4d14
JB
179{
180 return 0;
181}
182COMMAND(ibss, leave, NULL,
806bad30
JB
183 NL80211_CMD_LEAVE_IBSS, 0, CIB_NETDEV, leave_ibss,
184 "Leave the current IBSS cell.");
6a24bb22 185COMMAND(ibss, join,
8366d195 186 "<SSID> <freq in MHz> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz] [fixed-freq] [<fixed bssid>] [beacon-interval <TU>]"
506b442b
FF
187 " [basic-rates <rate in Mbps,rate2,...>] [mcast-rate <rate in Mbps>] "
188 "[key d:0:abcde]",
806bad30
JB
189 NL80211_CMD_JOIN_IBSS, 0, CIB_NETDEV, join_ibss,
190 "Join the IBSS cell with the given SSID, if it doesn't exist create\n"
191 "it on the given frequency. When fixed frequency is requested, don't\n"
192 "join/create a cell on a different frequency. When a fixed BSSID is\n"
193 "requested use that BSSID and do not adopt another cell's BSSID even\n"
ec46ba52 194 "if it has higher TSF and the same SSID. If an IBSS is created, create\n"
506b442b 195 "it with the specified basic-rates, multicast-rate and beacon-interval.");