blob: e85ef1d0f65bfbcc8458672f22e16c04c0bf2b1e [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;
Johannes Bergedea4d12009-04-19 00:53:31 +020029
Johannes Berg95940df2009-04-19 17:52:14 +020030 if (argc < 2)
31 return 1;
Johannes Bergedea4d12009-04-19 00:53:31 +020032
Johannes Berg95940df2009-04-19 17:52:14 +020033 /* SSID */
34 NLA_PUT(msg, NL80211_ATTR_SSID, strlen(argv[0]), argv[0]);
Johannes Bergedea4d12009-04-19 00:53:31 +020035 argv++;
36 argc--;
37
Johannes Berg95940df2009-04-19 17:52:14 +020038 /* freq */
39 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ,
40 strtoul(argv[0], &end, 10));
41 if (*end != '\0')
42 return 1;
43 argv++;
44 argc--;
Johannes Bergedea4d12009-04-19 00:53:31 +020045
Johannes Berg95940df2009-04-19 17:52:14 +020046 if (argc && strcmp(argv[0], "fixed-freq") == 0) {
47 NLA_PUT_FLAG(msg, NL80211_ATTR_FREQ_FIXED);
48 argv++;
49 argc--;
Johannes Bergedea4d12009-04-19 00:53:31 +020050 }
51
Johannes Berg95940df2009-04-19 17:52:14 +020052 if (argc) {
Johannes Berg51e9bd82009-07-08 00:44:25 +020053 if (mac_addr_a2n(abssid, argv[0]) == 0) {
54 NLA_PUT(msg, NL80211_ATTR_MAC, 6, abssid);
55 argv++;
56 argc--;
57 }
Johannes Bergedea4d12009-04-19 00:53:31 +020058 }
59
Teemu Paasikivi6a24bb22010-06-16 09:22:16 +030060 /* basic rates */
61 if (argc > 1 && strcmp(argv[0], "basic-rates") == 0) {
62 argv++;
63 argc--;
64
65 value = strtok_r(argv[0], ",", &sptr);
66
67 while (value && n_rates < NL80211_MAX_SUPP_RATES) {
68 rate = strtod(value, &end);
69 rates[n_rates] = rate * 2;
70
71 /* filter out suspicious values */
72 if (*end != '\0' || !rates[n_rates] ||
73 rate*2 != rates[n_rates])
74 return 1;
75
76 n_rates++;
77 value = strtok_r(NULL, ",", &sptr);
78 }
79
80 NLA_PUT(msg, NL80211_ATTR_BSS_BASIC_RATES, n_rates, rates);
81
82 argv++;
83 argc--;
84 }
85
Johannes Berg1e036902009-08-16 16:02:15 +020086 if (!argc)
87 return 0;
Johannes Berg51e9bd82009-07-08 00:44:25 +020088
Johannes Berg1e036902009-08-16 16:02:15 +020089 if (strcmp(*argv, "key") != 0 && strcmp(*argv, "keys") != 0)
90 return 1;
Johannes Bergedea4d12009-04-19 00:53:31 +020091
Johannes Berg1e036902009-08-16 16:02:15 +020092 argv++;
93 argc--;
Johannes Berg51e9bd82009-07-08 00:44:25 +020094
Johannes Berg1e036902009-08-16 16:02:15 +020095 return parse_keys(msg, argv, argc);
Johannes Bergedea4d12009-04-19 00:53:31 +020096 nla_put_failure:
97 return -ENOSPC;
98}
99
100static int leave_ibss(struct nl80211_state *state,
101 struct nl_cb *cb,
102 struct nl_msg *msg,
103 int argc, char **argv)
104{
105 return 0;
106}
107COMMAND(ibss, leave, NULL,
Johannes Berg806bad32009-05-05 14:56:40 +0200108 NL80211_CMD_LEAVE_IBSS, 0, CIB_NETDEV, leave_ibss,
109 "Leave the current IBSS cell.");
Teemu Paasikivi6a24bb22010-06-16 09:22:16 +0300110COMMAND(ibss, join,
111 "<SSID> <freq in MHz> [fixed-freq] [<fixed bssid>] "
112 "[basic-rates <rate in Mbps,rate2,...>] [key d:0:abcde]",
Johannes Berg806bad32009-05-05 14:56:40 +0200113 NL80211_CMD_JOIN_IBSS, 0, CIB_NETDEV, join_ibss,
114 "Join the IBSS cell with the given SSID, if it doesn't exist create\n"
115 "it on the given frequency. When fixed frequency is requested, don't\n"
116 "join/create a cell on a different frequency. When a fixed BSSID is\n"
117 "requested use that BSSID and do not adopt another cell's BSSID even\n"
118 "if it has higher TSF and the same SSID.");