blob: 955446e445dddf1563cdeb9e901ac98edde905f6 [file] [log] [blame]
Johannes Bergb8936862010-09-22 11:33:51 +02001#ifndef _POSIX_SOURCE
2#define _POSIX_SOURCE
3#endif
Johannes Bergedea4d12009-04-19 00:53:31 +02004#include <errno.h>
Johannes Bergb8936862010-09-22 11:33:51 +02005#include <string.h>
Simon Wunderlich135cb522011-11-30 16:56:35 +01006#include <strings.h>
Johannes Bergedea4d12009-04-19 00:53:31 +02007
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
Johannes Berg4698bfc2009-08-24 12:53:34 +020017SECTION(ibss);
18
Johannes Bergedea4d12009-04-19 00:53:31 +020019static int join_ibss(struct nl80211_state *state,
20 struct nl_cb *cb,
21 struct nl_msg *msg,
Johannes Berg05514f92012-07-19 11:50:50 +020022 int argc, char **argv,
23 enum id_input id)
Johannes Bergedea4d12009-04-19 00:53:31 +020024{
Johannes Berg95940df2009-04-19 17:52:14 +020025 char *end;
Johannes Bergedea4d12009-04-19 00:53:31 +020026 unsigned char abssid[6];
Teemu Paasikivi6a24bb22010-06-16 09:22:16 +030027 unsigned char rates[NL80211_MAX_SUPP_RATES];
28 int n_rates = 0;
29 char *value = NULL, *sptr = NULL;
30 float rate;
Bruno Randolfec46ba52010-10-27 15:02:37 +090031 int bintval;
Simon Wunderlich135cb522011-11-30 16:56:35 +010032 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;
Johannes Bergedea4d12009-04-19 00:53:31 +020043
Johannes Berg95940df2009-04-19 17:52:14 +020044 if (argc < 2)
45 return 1;
Johannes Bergedea4d12009-04-19 00:53:31 +020046
Johannes Berg95940df2009-04-19 17:52:14 +020047 /* SSID */
48 NLA_PUT(msg, NL80211_ATTR_SSID, strlen(argv[0]), argv[0]);
Johannes Bergedea4d12009-04-19 00:53:31 +020049 argv++;
50 argc--;
51
Johannes Berg95940df2009-04-19 17:52:14 +020052 /* 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--;
Johannes Bergedea4d12009-04-19 00:53:31 +020059
Simon Wunderlich135cb522011-11-30 16:56:35 +010060 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
Johannes Berg95940df2009-04-19 17:52:14 +020076 if (argc && strcmp(argv[0], "fixed-freq") == 0) {
77 NLA_PUT_FLAG(msg, NL80211_ATTR_FREQ_FIXED);
78 argv++;
79 argc--;
Johannes Bergedea4d12009-04-19 00:53:31 +020080 }
81
Johannes Berg95940df2009-04-19 17:52:14 +020082 if (argc) {
Johannes Berg51e9bd82009-07-08 00:44:25 +020083 if (mac_addr_a2n(abssid, argv[0]) == 0) {
84 NLA_PUT(msg, NL80211_ATTR_MAC, 6, abssid);
85 argv++;
86 argc--;
87 }
Johannes Bergedea4d12009-04-19 00:53:31 +020088 }
89
Bruno Randolfec46ba52010-10-27 15:02:37 +090090 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
Teemu Paasikivi6a24bb22010-06-16 09:22:16 +0300101 /* 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
Felix Fietkau506b4422011-01-11 09:51:18 +0900127 /* 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
Jo-Philipp Wiche399be82011-05-22 15:09:51 +0200136 NLA_PUT_U32(msg, NL80211_ATTR_MCAST_RATE, (int)(rate * 10));
Felix Fietkau506b4422011-01-11 09:51:18 +0900137 argv++;
138 argc--;
139 }
140
Johannes Berg1e036902009-08-16 16:02:15 +0200141 if (!argc)
142 return 0;
Johannes Berg51e9bd82009-07-08 00:44:25 +0200143
Johannes Berg1e036902009-08-16 16:02:15 +0200144 if (strcmp(*argv, "key") != 0 && strcmp(*argv, "keys") != 0)
145 return 1;
Johannes Bergedea4d12009-04-19 00:53:31 +0200146
Johannes Berg1e036902009-08-16 16:02:15 +0200147 argv++;
148 argc--;
Johannes Berg51e9bd82009-07-08 00:44:25 +0200149
Johannes Berg1e036902009-08-16 16:02:15 +0200150 return parse_keys(msg, argv, argc);
Johannes Bergedea4d12009-04-19 00:53:31 +0200151 nla_put_failure:
152 return -ENOSPC;
153}
154
155static int leave_ibss(struct nl80211_state *state,
156 struct nl_cb *cb,
157 struct nl_msg *msg,
Johannes Berg05514f92012-07-19 11:50:50 +0200158 int argc, char **argv,
159 enum id_input id)
Johannes Bergedea4d12009-04-19 00:53:31 +0200160{
161 return 0;
162}
163COMMAND(ibss, leave, NULL,
Johannes Berg806bad32009-05-05 14:56:40 +0200164 NL80211_CMD_LEAVE_IBSS, 0, CIB_NETDEV, leave_ibss,
165 "Leave the current IBSS cell.");
Teemu Paasikivi6a24bb22010-06-16 09:22:16 +0300166COMMAND(ibss, join,
Simon Wunderlich135cb522011-11-30 16:56:35 +0100167 "<SSID> <freq in MHz> [HT20|HT40+|HT40-|NOHT] [fixed-freq] [<fixed bssid>] [beacon-interval <TU>]"
Felix Fietkau506b4422011-01-11 09:51:18 +0900168 " [basic-rates <rate in Mbps,rate2,...>] [mcast-rate <rate in Mbps>] "
169 "[key d:0:abcde]",
Johannes Berg806bad32009-05-05 14:56:40 +0200170 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"
Bruno Randolfec46ba52010-10-27 15:02:37 +0900175 "if it has higher TSF and the same SSID. If an IBSS is created, create\n"
Felix Fietkau506b4422011-01-11 09:51:18 +0900176 "it with the specified basic-rates, multicast-rate and beacon-interval.");