blob: 84ea7f277f42b2048323f1ceaf6b4867f130e1a5 [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>
Johannes Bergedea4d12009-04-19 00:53:31 +02006
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
Johannes Berg4698bfc2009-08-24 12:53:34 +020016SECTION(ibss);
17
Johannes Bergedea4d12009-04-19 00:53:31 +020018static int join_ibss(struct nl80211_state *state,
19 struct nl_cb *cb,
20 struct nl_msg *msg,
21 int argc, char **argv)
22{
Johannes Berg95940df2009-04-19 17:52:14 +020023 char *end;
Johannes Bergedea4d12009-04-19 00:53:31 +020024 unsigned char abssid[6];
Teemu Paasikivi6a24bb22010-06-16 09:22:16 +030025 unsigned char rates[NL80211_MAX_SUPP_RATES];
26 int n_rates = 0;
27 char *value = NULL, *sptr = NULL;
28 float rate;
Bruno Randolfec46ba52010-10-27 15:02:37 +090029 int bintval;
Johannes Bergedea4d12009-04-19 00:53:31 +020030
Johannes Berg95940df2009-04-19 17:52:14 +020031 if (argc < 2)
32 return 1;
Johannes Bergedea4d12009-04-19 00:53:31 +020033
Johannes Berg95940df2009-04-19 17:52:14 +020034 /* SSID */
35 NLA_PUT(msg, NL80211_ATTR_SSID, strlen(argv[0]), argv[0]);
Johannes Bergedea4d12009-04-19 00:53:31 +020036 argv++;
37 argc--;
38
Johannes Berg95940df2009-04-19 17:52:14 +020039 /* 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--;
Johannes Bergedea4d12009-04-19 00:53:31 +020046
Johannes Berg95940df2009-04-19 17:52:14 +020047 if (argc && strcmp(argv[0], "fixed-freq") == 0) {
48 NLA_PUT_FLAG(msg, NL80211_ATTR_FREQ_FIXED);
49 argv++;
50 argc--;
Johannes Bergedea4d12009-04-19 00:53:31 +020051 }
52
Johannes Berg95940df2009-04-19 17:52:14 +020053 if (argc) {
Johannes Berg51e9bd82009-07-08 00:44:25 +020054 if (mac_addr_a2n(abssid, argv[0]) == 0) {
55 NLA_PUT(msg, NL80211_ATTR_MAC, 6, abssid);
56 argv++;
57 argc--;
58 }
Johannes Bergedea4d12009-04-19 00:53:31 +020059 }
60
Bruno Randolfec46ba52010-10-27 15:02:37 +090061 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
Teemu Paasikivi6a24bb22010-06-16 09:22:16 +030072 /* 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
Johannes Berg1e036902009-08-16 16:02:15 +020098 if (!argc)
99 return 0;
Johannes Berg51e9bd82009-07-08 00:44:25 +0200100
Johannes Berg1e036902009-08-16 16:02:15 +0200101 if (strcmp(*argv, "key") != 0 && strcmp(*argv, "keys") != 0)
102 return 1;
Johannes Bergedea4d12009-04-19 00:53:31 +0200103
Johannes Berg1e036902009-08-16 16:02:15 +0200104 argv++;
105 argc--;
Johannes Berg51e9bd82009-07-08 00:44:25 +0200106
Johannes Berg1e036902009-08-16 16:02:15 +0200107 return parse_keys(msg, argv, argc);
Johannes Bergedea4d12009-04-19 00:53:31 +0200108 nla_put_failure:
109 return -ENOSPC;
110}
111
112static int leave_ibss(struct nl80211_state *state,
113 struct nl_cb *cb,
114 struct nl_msg *msg,
115 int argc, char **argv)
116{
117 return 0;
118}
119COMMAND(ibss, leave, NULL,
Johannes Berg806bad32009-05-05 14:56:40 +0200120 NL80211_CMD_LEAVE_IBSS, 0, CIB_NETDEV, leave_ibss,
121 "Leave the current IBSS cell.");
Teemu Paasikivi6a24bb22010-06-16 09:22:16 +0300122COMMAND(ibss, join,
Bruno Randolfec46ba52010-10-27 15:02:37 +0900123 "<SSID> <freq in MHz> [fixed-freq] [<fixed bssid>] [beacon-interval "
124 "<TU>] [basic-rates <rate in Mbps,rate2,...>] [key d:0:abcde]",
Johannes Berg806bad32009-05-05 14:56:40 +0200125 NL80211_CMD_JOIN_IBSS, 0, CIB_NETDEV, join_ibss,
126 "Join the IBSS cell with the given SSID, if it doesn't exist create\n"
127 "it on the given frequency. When fixed frequency is requested, don't\n"
128 "join/create a cell on a different frequency. When a fixed BSSID is\n"
129 "requested use that BSSID and do not adopt another cell's BSSID even\n"
Bruno Randolfec46ba52010-10-27 15:02:37 +0900130 "if it has higher TSF and the same SSID. If an IBSS is created, create\n"
131 "it with the specified basic-rates and beacon-interval (in TU).");