]> git.ipfire.org Git - thirdparty/iw.git/blame - ibss.c
genl: include genetlink.h explicitly
[thirdparty/iw.git] / ibss.c
CommitLineData
b893686f
JB
1#ifndef _POSIX_SOURCE
2#define _POSIX_SOURCE
3#endif
edea4d14 4#include <errno.h>
b893686f 5#include <string.h>
edea4d14
JB
6
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
4698bfc2
JB
16SECTION(ibss);
17
edea4d14
JB
18static int join_ibss(struct nl80211_state *state,
19 struct nl_cb *cb,
20 struct nl_msg *msg,
21 int argc, char **argv)
22{
95940df3 23 char *end;
edea4d14 24 unsigned char abssid[6];
6a24bb22
TP
25 unsigned char rates[NL80211_MAX_SUPP_RATES];
26 int n_rates = 0;
27 char *value = NULL, *sptr = NULL;
28 float rate;
edea4d14 29
95940df3
JB
30 if (argc < 2)
31 return 1;
edea4d14 32
95940df3
JB
33 /* SSID */
34 NLA_PUT(msg, NL80211_ATTR_SSID, strlen(argv[0]), argv[0]);
edea4d14
JB
35 argv++;
36 argc--;
37
95940df3
JB
38 /* 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--;
edea4d14 45
95940df3
JB
46 if (argc && strcmp(argv[0], "fixed-freq") == 0) {
47 NLA_PUT_FLAG(msg, NL80211_ATTR_FREQ_FIXED);
48 argv++;
49 argc--;
edea4d14
JB
50 }
51
95940df3 52 if (argc) {
51e9bd80
JB
53 if (mac_addr_a2n(abssid, argv[0]) == 0) {
54 NLA_PUT(msg, NL80211_ATTR_MAC, 6, abssid);
55 argv++;
56 argc--;
57 }
edea4d14
JB
58 }
59
6a24bb22
TP
60 /* 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
1e03690e
JB
86 if (!argc)
87 return 0;
edea4d14 88
1e03690e
JB
89 if (strcmp(*argv, "key") != 0 && strcmp(*argv, "keys") != 0)
90 return 1;
ded1f078 91
1e03690e
JB
92 argv++;
93 argc--;
51e9bd80 94
1e03690e 95 return parse_keys(msg, argv, argc);
edea4d14
JB
96 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,
806bad30
JB
108 NL80211_CMD_LEAVE_IBSS, 0, CIB_NETDEV, leave_ibss,
109 "Leave the current IBSS cell.");
6a24bb22
TP
110COMMAND(ibss, join,
111 "<SSID> <freq in MHz> [fixed-freq] [<fixed bssid>] "
112 "[basic-rates <rate in Mbps,rate2,...>] [key d:0:abcde]",
806bad30
JB
113 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.");