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