]>
Commit | Line | Data |
---|---|---|
b893686f JB |
1 | #ifndef _POSIX_SOURCE |
2 | #define _POSIX_SOURCE | |
3 | #endif | |
edea4d14 | 4 | #include <errno.h> |
b893686f | 5 | #include <string.h> |
135cb523 | 6 | #include <strings.h> |
edea4d14 JB |
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 | ||
4698bfc2 JB |
17 | SECTION(ibss); |
18 | ||
edea4d14 JB |
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 | { | |
95940df3 | 24 | char *end; |
edea4d14 | 25 | unsigned char abssid[6]; |
6a24bb22 TP |
26 | unsigned char rates[NL80211_MAX_SUPP_RATES]; |
27 | int n_rates = 0; | |
28 | char *value = NULL, *sptr = NULL; | |
29 | float rate; | |
ec46ba52 | 30 | int bintval; |
135cb523 SW |
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; | |
edea4d14 | 42 | |
95940df3 JB |
43 | if (argc < 2) |
44 | return 1; | |
edea4d14 | 45 | |
95940df3 JB |
46 | /* SSID */ |
47 | NLA_PUT(msg, NL80211_ATTR_SSID, strlen(argv[0]), argv[0]); | |
edea4d14 JB |
48 | argv++; |
49 | argc--; | |
50 | ||
95940df3 JB |
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--; | |
edea4d14 | 58 | |
135cb523 SW |
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 | ||
95940df3 JB |
75 | if (argc && strcmp(argv[0], "fixed-freq") == 0) { |
76 | NLA_PUT_FLAG(msg, NL80211_ATTR_FREQ_FIXED); | |
77 | argv++; | |
78 | argc--; | |
edea4d14 JB |
79 | } |
80 | ||
95940df3 | 81 | if (argc) { |
51e9bd80 JB |
82 | if (mac_addr_a2n(abssid, argv[0]) == 0) { |
83 | NLA_PUT(msg, NL80211_ATTR_MAC, 6, abssid); | |
84 | argv++; | |
85 | argc--; | |
86 | } | |
edea4d14 JB |
87 | } |
88 | ||
ec46ba52 BR |
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 | ||
6a24bb22 TP |
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 | ||
506b442b FF |
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 | ||
e399be8c | 135 | NLA_PUT_U32(msg, NL80211_ATTR_MCAST_RATE, (int)(rate * 10)); |
506b442b FF |
136 | argv++; |
137 | argc--; | |
138 | } | |
139 | ||
1e03690e JB |
140 | if (!argc) |
141 | return 0; | |
edea4d14 | 142 | |
1e03690e JB |
143 | if (strcmp(*argv, "key") != 0 && strcmp(*argv, "keys") != 0) |
144 | return 1; | |
ded1f078 | 145 | |
1e03690e JB |
146 | argv++; |
147 | argc--; | |
51e9bd80 | 148 | |
1e03690e | 149 | return parse_keys(msg, argv, argc); |
edea4d14 JB |
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, | |
806bad30 JB |
162 | NL80211_CMD_LEAVE_IBSS, 0, CIB_NETDEV, leave_ibss, |
163 | "Leave the current IBSS cell."); | |
6a24bb22 | 164 | COMMAND(ibss, join, |
135cb523 | 165 | "<SSID> <freq in MHz> [HT20|HT40+|HT40-|NOHT] [fixed-freq] [<fixed bssid>] [beacon-interval <TU>]" |
506b442b FF |
166 | " [basic-rates <rate in Mbps,rate2,...>] [mcast-rate <rate in Mbps>] " |
167 | "[key d:0:abcde]", | |
806bad30 JB |
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" | |
ec46ba52 | 173 | "if it has higher TSF and the same SSID. If an IBSS is created, create\n" |
506b442b | 174 | "it with the specified basic-rates, multicast-rate and beacon-interval."); |