blob: 4715ac81b65ec6819c7d16d70475138f12999e71 [file] [log] [blame]
Johannes Bergedea4d12009-04-19 00:53:31 +02001#include <errno.h>
2
3#include <netlink/genl/genl.h>
4#include <netlink/genl/family.h>
5#include <netlink/genl/ctrl.h>
6#include <netlink/msg.h>
7#include <netlink/attr.h>
8
9#include "nl80211.h"
10#include "iw.h"
11
Johannes Berg4698bfc2009-08-24 12:53:34 +020012SECTION(ibss);
13
Johannes Bergedea4d12009-04-19 00:53:31 +020014static int join_ibss(struct nl80211_state *state,
15 struct nl_cb *cb,
16 struct nl_msg *msg,
17 int argc, char **argv)
18{
Johannes Berg95940df2009-04-19 17:52:14 +020019 char *end;
Johannes Bergedea4d12009-04-19 00:53:31 +020020 unsigned char abssid[6];
21
Johannes Berg95940df2009-04-19 17:52:14 +020022 if (argc < 2)
23 return 1;
Johannes Bergedea4d12009-04-19 00:53:31 +020024
Johannes Berg95940df2009-04-19 17:52:14 +020025 /* SSID */
26 NLA_PUT(msg, NL80211_ATTR_SSID, strlen(argv[0]), argv[0]);
Johannes Bergedea4d12009-04-19 00:53:31 +020027 argv++;
28 argc--;
29
Johannes Berg95940df2009-04-19 17:52:14 +020030 /* freq */
31 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ,
32 strtoul(argv[0], &end, 10));
33 if (*end != '\0')
34 return 1;
35 argv++;
36 argc--;
Johannes Bergedea4d12009-04-19 00:53:31 +020037
Johannes Berg95940df2009-04-19 17:52:14 +020038 if (argc && strcmp(argv[0], "fixed-freq") == 0) {
39 NLA_PUT_FLAG(msg, NL80211_ATTR_FREQ_FIXED);
40 argv++;
41 argc--;
Johannes Bergedea4d12009-04-19 00:53:31 +020042 }
43
Johannes Berg95940df2009-04-19 17:52:14 +020044 if (argc) {
Johannes Berg51e9bd82009-07-08 00:44:25 +020045 if (mac_addr_a2n(abssid, argv[0]) == 0) {
46 NLA_PUT(msg, NL80211_ATTR_MAC, 6, abssid);
47 argv++;
48 argc--;
49 }
Johannes Bergedea4d12009-04-19 00:53:31 +020050 }
51
Johannes Berg1e036902009-08-16 16:02:15 +020052 if (!argc)
53 return 0;
Johannes Berg51e9bd82009-07-08 00:44:25 +020054
Johannes Berg1e036902009-08-16 16:02:15 +020055 if (strcmp(*argv, "key") != 0 && strcmp(*argv, "keys") != 0)
56 return 1;
Johannes Bergedea4d12009-04-19 00:53:31 +020057
Johannes Berg1e036902009-08-16 16:02:15 +020058 argv++;
59 argc--;
Johannes Berg51e9bd82009-07-08 00:44:25 +020060
Johannes Berg1e036902009-08-16 16:02:15 +020061 return parse_keys(msg, argv, argc);
Johannes Bergedea4d12009-04-19 00:53:31 +020062 nla_put_failure:
63 return -ENOSPC;
64}
65
66static int leave_ibss(struct nl80211_state *state,
67 struct nl_cb *cb,
68 struct nl_msg *msg,
69 int argc, char **argv)
70{
71 return 0;
72}
73COMMAND(ibss, leave, NULL,
Johannes Berg806bad32009-05-05 14:56:40 +020074 NL80211_CMD_LEAVE_IBSS, 0, CIB_NETDEV, leave_ibss,
75 "Leave the current IBSS cell.");
Johannes Berg51e9bd82009-07-08 00:44:25 +020076COMMAND(ibss, join, "<SSID> <freq in MHz> [fixed-freq] [<fixed bssid>] [key d:0:abcde]",
Johannes Berg806bad32009-05-05 14:56:40 +020077 NL80211_CMD_JOIN_IBSS, 0, CIB_NETDEV, join_ibss,
78 "Join the IBSS cell with the given SSID, if it doesn't exist create\n"
79 "it on the given frequency. When fixed frequency is requested, don't\n"
80 "join/create a cell on a different frequency. When a fixed BSSID is\n"
81 "requested use that BSSID and do not adopt another cell's BSSID even\n"
82 "if it has higher TSF and the same SSID.");