]> git.ipfire.org Git - thirdparty/iw.git/blame - ibss.c
update nl80211.h
[thirdparty/iw.git] / ibss.c
CommitLineData
b893686f
JB
1#ifndef _POSIX_SOURCE
2#define _POSIX_SOURCE
3#endif
edea4d14 4#include <errno.h>
b893686f 5#include <string.h>
edea4d14
JB
6
7#include <netlink/genl/genl.h>
8#include <netlink/genl/family.h>
9#include <netlink/genl/ctrl.h>
10#include <netlink/msg.h>
11#include <netlink/attr.h>
12
13#include "nl80211.h"
14#include "iw.h"
15
4698bfc2
JB
16SECTION(ibss);
17
edea4d14
JB
18static int join_ibss(struct nl80211_state *state,
19 struct nl_cb *cb,
20 struct nl_msg *msg,
21 int argc, char **argv)
22{
95940df3 23 char *end;
edea4d14 24 unsigned char abssid[6];
6a24bb22
TP
25 unsigned char rates[NL80211_MAX_SUPP_RATES];
26 int n_rates = 0;
27 char *value = NULL, *sptr = NULL;
28 float rate;
ec46ba52 29 int bintval;
edea4d14 30
95940df3
JB
31 if (argc < 2)
32 return 1;
edea4d14 33
95940df3
JB
34 /* SSID */
35 NLA_PUT(msg, NL80211_ATTR_SSID, strlen(argv[0]), argv[0]);
edea4d14
JB
36 argv++;
37 argc--;
38
95940df3
JB
39 /* freq */
40 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ,
41 strtoul(argv[0], &end, 10));
42 if (*end != '\0')
43 return 1;
44 argv++;
45 argc--;
edea4d14 46
95940df3
JB
47 if (argc && strcmp(argv[0], "fixed-freq") == 0) {
48 NLA_PUT_FLAG(msg, NL80211_ATTR_FREQ_FIXED);
49 argv++;
50 argc--;
edea4d14
JB
51 }
52
95940df3 53 if (argc) {
51e9bd80
JB
54 if (mac_addr_a2n(abssid, argv[0]) == 0) {
55 NLA_PUT(msg, NL80211_ATTR_MAC, 6, abssid);
56 argv++;
57 argc--;
58 }
edea4d14
JB
59 }
60
ec46ba52
BR
61 if (argc > 1 && strcmp(argv[0], "beacon-interval") == 0) {
62 argv++;
63 argc--;
64 bintval = strtoul(argv[0], &end, 10);
65 if (*end != '\0')
66 return 1;
67 NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, bintval);
68 argv++;
69 argc--;
70 }
71
6a24bb22
TP
72 /* basic rates */
73 if (argc > 1 && strcmp(argv[0], "basic-rates") == 0) {
74 argv++;
75 argc--;
76
77 value = strtok_r(argv[0], ",", &sptr);
78
79 while (value && n_rates < NL80211_MAX_SUPP_RATES) {
80 rate = strtod(value, &end);
81 rates[n_rates] = rate * 2;
82
83 /* filter out suspicious values */
84 if (*end != '\0' || !rates[n_rates] ||
85 rate*2 != rates[n_rates])
86 return 1;
87
88 n_rates++;
89 value = strtok_r(NULL, ",", &sptr);
90 }
91
92 NLA_PUT(msg, NL80211_ATTR_BSS_BASIC_RATES, n_rates, rates);
93
94 argv++;
95 argc--;
96 }
97
506b442b
FF
98 /* multicast rate */
99 if (argc > 1 && strcmp(argv[0], "mcast-rate") == 0) {
100 argv++;
101 argc--;
102
103 rate = strtod(argv[0], &end);
104 if (*end != '\0')
105 return 1;
106
e399be8c 107 NLA_PUT_U32(msg, NL80211_ATTR_MCAST_RATE, (int)(rate * 10));
506b442b
FF
108 argv++;
109 argc--;
110 }
111
1e03690e
JB
112 if (!argc)
113 return 0;
edea4d14 114
1e03690e
JB
115 if (strcmp(*argv, "key") != 0 && strcmp(*argv, "keys") != 0)
116 return 1;
ded1f078 117
1e03690e
JB
118 argv++;
119 argc--;
51e9bd80 120
1e03690e 121 return parse_keys(msg, argv, argc);
edea4d14
JB
122 nla_put_failure:
123 return -ENOSPC;
124}
125
126static int leave_ibss(struct nl80211_state *state,
127 struct nl_cb *cb,
128 struct nl_msg *msg,
129 int argc, char **argv)
130{
131 return 0;
132}
133COMMAND(ibss, leave, NULL,
806bad30
JB
134 NL80211_CMD_LEAVE_IBSS, 0, CIB_NETDEV, leave_ibss,
135 "Leave the current IBSS cell.");
6a24bb22 136COMMAND(ibss, join,
506b442b
FF
137 "<SSID> <freq in MHz> [fixed-freq] [<fixed bssid>] [beacon-interval <TU>]"
138 " [basic-rates <rate in Mbps,rate2,...>] [mcast-rate <rate in Mbps>] "
139 "[key d:0:abcde]",
806bad30
JB
140 NL80211_CMD_JOIN_IBSS, 0, CIB_NETDEV, join_ibss,
141 "Join the IBSS cell with the given SSID, if it doesn't exist create\n"
142 "it on the given frequency. When fixed frequency is requested, don't\n"
143 "join/create a cell on a different frequency. When a fixed BSSID is\n"
144 "requested use that BSSID and do not adopt another cell's BSSID even\n"
ec46ba52 145 "if it has higher TSF and the same SSID. If an IBSS is created, create\n"
506b442b 146 "it with the specified basic-rates, multicast-rate and beacon-interval.");