blob: 62a11106615f33d6d48abc73c5bd3e8ecaea4086 [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,
22 int argc, char **argv)
23{
Johannes Berg95940df2009-04-19 17:52:14 +020024 char *end;
Johannes Bergedea4d12009-04-19 00:53:31 +020025 unsigned char abssid[6];
Teemu Paasikivi6a24bb22010-06-16 09:22:16 +030026 unsigned char rates[NL80211_MAX_SUPP_RATES];
27 int n_rates = 0;
28 char *value = NULL, *sptr = NULL;
29 float rate;
Bruno Randolfec46ba52010-10-27 15:02:37 +090030 int bintval;
Simon Wunderlich135cb522011-11-30 16:56:35 +010031 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;
Johannes Bergedea4d12009-04-19 00:53:31 +020042
Johannes Berg95940df2009-04-19 17:52:14 +020043 if (argc < 2)
44 return 1;
Johannes Bergedea4d12009-04-19 00:53:31 +020045
Johannes Berg95940df2009-04-19 17:52:14 +020046 /* SSID */
47 NLA_PUT(msg, NL80211_ATTR_SSID, strlen(argv[0]), argv[0]);
Johannes Bergedea4d12009-04-19 00:53:31 +020048 argv++;
49 argc--;
50
Johannes Berg95940df2009-04-19 17:52:14 +020051 /* 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--;
Johannes Bergedea4d12009-04-19 00:53:31 +020058
Simon Wunderlich135cb522011-11-30 16:56:35 +010059 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
Johannes Berg95940df2009-04-19 17:52:14 +020075 if (argc && strcmp(argv[0], "fixed-freq") == 0) {
76 NLA_PUT_FLAG(msg, NL80211_ATTR_FREQ_FIXED);
77 argv++;
78 argc--;
Johannes Bergedea4d12009-04-19 00:53:31 +020079 }
80
Johannes Berg95940df2009-04-19 17:52:14 +020081 if (argc) {
Johannes Berg51e9bd82009-07-08 00:44:25 +020082 if (mac_addr_a2n(abssid, argv[0]) == 0) {
83 NLA_PUT(msg, NL80211_ATTR_MAC, 6, abssid);
84 argv++;
85 argc--;
86 }
Johannes Bergedea4d12009-04-19 00:53:31 +020087 }
88
Bruno Randolfec46ba52010-10-27 15:02:37 +090089 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
Teemu Paasikivi6a24bb22010-06-16 09:22:16 +0300100 /* 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
Felix Fietkau506b4422011-01-11 09:51:18 +0900126 /* 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
Jo-Philipp Wiche399be82011-05-22 15:09:51 +0200135 NLA_PUT_U32(msg, NL80211_ATTR_MCAST_RATE, (int)(rate * 10));
Felix Fietkau506b4422011-01-11 09:51:18 +0900136 argv++;
137 argc--;
138 }
139
Johannes Berg1e036902009-08-16 16:02:15 +0200140 if (!argc)
141 return 0;
Johannes Berg51e9bd82009-07-08 00:44:25 +0200142
Johannes Berg1e036902009-08-16 16:02:15 +0200143 if (strcmp(*argv, "key") != 0 && strcmp(*argv, "keys") != 0)
144 return 1;
Johannes Bergedea4d12009-04-19 00:53:31 +0200145
Johannes Berg1e036902009-08-16 16:02:15 +0200146 argv++;
147 argc--;
Johannes Berg51e9bd82009-07-08 00:44:25 +0200148
Johannes Berg1e036902009-08-16 16:02:15 +0200149 return parse_keys(msg, argv, argc);
Johannes Bergedea4d12009-04-19 00:53:31 +0200150 nla_put_failure:
151 return -ENOSPC;
152}
153
154static 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}
161COMMAND(ibss, leave, NULL,
Johannes Berg806bad32009-05-05 14:56:40 +0200162 NL80211_CMD_LEAVE_IBSS, 0, CIB_NETDEV, leave_ibss,
163 "Leave the current IBSS cell.");
Teemu Paasikivi6a24bb22010-06-16 09:22:16 +0300164COMMAND(ibss, join,
Simon Wunderlich135cb522011-11-30 16:56:35 +0100165 "<SSID> <freq in MHz> [HT20|HT40+|HT40-|NOHT] [fixed-freq] [<fixed bssid>] [beacon-interval <TU>]"
Felix Fietkau506b4422011-01-11 09:51:18 +0900166 " [basic-rates <rate in Mbps,rate2,...>] [mcast-rate <rate in Mbps>] "
167 "[key d:0:abcde]",
Johannes Berg806bad32009-05-05 14:56:40 +0200168 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"
Bruno Randolfec46ba52010-10-27 15:02:37 +0900173 "if it has higher TSF and the same SSID. If an IBSS is created, create\n"
Felix Fietkau506b4422011-01-11 09:51:18 +0900174 "it with the specified basic-rates, multicast-rate and beacon-interval.");