]>
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, | |
05514f95 JB |
22 | int argc, char **argv, |
23 | enum id_input id) | |
edea4d14 | 24 | { |
95940df3 | 25 | char *end; |
edea4d14 | 26 | unsigned char abssid[6]; |
6a24bb22 TP |
27 | unsigned char rates[NL80211_MAX_SUPP_RATES]; |
28 | int n_rates = 0; | |
29 | char *value = NULL, *sptr = NULL; | |
30 | float rate; | |
ec46ba52 | 31 | int bintval; |
135cb523 SW |
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; | |
edea4d14 | 43 | |
95940df3 JB |
44 | if (argc < 2) |
45 | return 1; | |
edea4d14 | 46 | |
95940df3 JB |
47 | /* SSID */ |
48 | NLA_PUT(msg, NL80211_ATTR_SSID, strlen(argv[0]), argv[0]); | |
edea4d14 JB |
49 | argv++; |
50 | argc--; | |
51 | ||
95940df3 JB |
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--; | |
edea4d14 | 59 | |
135cb523 SW |
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 | ||
95940df3 JB |
76 | if (argc && strcmp(argv[0], "fixed-freq") == 0) { |
77 | NLA_PUT_FLAG(msg, NL80211_ATTR_FREQ_FIXED); | |
78 | argv++; | |
79 | argc--; | |
edea4d14 JB |
80 | } |
81 | ||
95940df3 | 82 | if (argc) { |
51e9bd80 JB |
83 | if (mac_addr_a2n(abssid, argv[0]) == 0) { |
84 | NLA_PUT(msg, NL80211_ATTR_MAC, 6, abssid); | |
85 | argv++; | |
86 | argc--; | |
87 | } | |
edea4d14 JB |
88 | } |
89 | ||
ec46ba52 BR |
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 | ||
6a24bb22 TP |
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 | ||
506b442b FF |
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 | ||
e399be8c | 136 | NLA_PUT_U32(msg, NL80211_ATTR_MCAST_RATE, (int)(rate * 10)); |
506b442b FF |
137 | argv++; |
138 | argc--; | |
139 | } | |
140 | ||
1e03690e JB |
141 | if (!argc) |
142 | return 0; | |
edea4d14 | 143 | |
1e03690e JB |
144 | if (strcmp(*argv, "key") != 0 && strcmp(*argv, "keys") != 0) |
145 | return 1; | |
ded1f078 | 146 | |
1e03690e JB |
147 | argv++; |
148 | argc--; | |
51e9bd80 | 149 | |
1e03690e | 150 | return parse_keys(msg, argv, argc); |
edea4d14 JB |
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, | |
05514f95 JB |
158 | int argc, char **argv, |
159 | enum id_input id) | |
edea4d14 JB |
160 | { |
161 | return 0; | |
162 | } | |
163 | COMMAND(ibss, leave, NULL, | |
806bad30 JB |
164 | NL80211_CMD_LEAVE_IBSS, 0, CIB_NETDEV, leave_ibss, |
165 | "Leave the current IBSS cell."); | |
6a24bb22 | 166 | COMMAND(ibss, join, |
135cb523 | 167 | "<SSID> <freq in MHz> [HT20|HT40+|HT40-|NOHT] [fixed-freq] [<fixed bssid>] [beacon-interval <TU>]" |
506b442b FF |
168 | " [basic-rates <rate in Mbps,rate2,...>] [mcast-rate <rate in Mbps>] " |
169 | "[key d:0:abcde]", | |
806bad30 JB |
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" | |
ec46ba52 | 175 | "if it has higher TSF and the same SSID. If an IBSS is created, create\n" |
506b442b | 176 | "it with the specified basic-rates, multicast-rate and beacon-interval."); |