]> git.ipfire.org Git - thirdparty/iw.git/blob - ibss.c
analyse HT operation IE
[thirdparty/iw.git] / ibss.c
1 #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
12 SECTION(ibss);
13
14 static int join_ibss(struct nl80211_state *state,
15 struct nl_cb *cb,
16 struct nl_msg *msg,
17 int argc, char **argv)
18 {
19 char *end;
20 unsigned char abssid[6];
21 unsigned char rates[NL80211_MAX_SUPP_RATES];
22 int n_rates = 0;
23 char *value = NULL, *sptr = NULL;
24 float rate;
25
26 if (argc < 2)
27 return 1;
28
29 /* SSID */
30 NLA_PUT(msg, NL80211_ATTR_SSID, strlen(argv[0]), argv[0]);
31 argv++;
32 argc--;
33
34 /* freq */
35 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ,
36 strtoul(argv[0], &end, 10));
37 if (*end != '\0')
38 return 1;
39 argv++;
40 argc--;
41
42 if (argc && strcmp(argv[0], "fixed-freq") == 0) {
43 NLA_PUT_FLAG(msg, NL80211_ATTR_FREQ_FIXED);
44 argv++;
45 argc--;
46 }
47
48 if (argc) {
49 if (mac_addr_a2n(abssid, argv[0]) == 0) {
50 NLA_PUT(msg, NL80211_ATTR_MAC, 6, abssid);
51 argv++;
52 argc--;
53 }
54 }
55
56 /* basic rates */
57 if (argc > 1 && strcmp(argv[0], "basic-rates") == 0) {
58 argv++;
59 argc--;
60
61 value = strtok_r(argv[0], ",", &sptr);
62
63 while (value && n_rates < NL80211_MAX_SUPP_RATES) {
64 rate = strtod(value, &end);
65 rates[n_rates] = rate * 2;
66
67 /* filter out suspicious values */
68 if (*end != '\0' || !rates[n_rates] ||
69 rate*2 != rates[n_rates])
70 return 1;
71
72 n_rates++;
73 value = strtok_r(NULL, ",", &sptr);
74 }
75
76 NLA_PUT(msg, NL80211_ATTR_BSS_BASIC_RATES, n_rates, rates);
77
78 argv++;
79 argc--;
80 }
81
82 if (!argc)
83 return 0;
84
85 if (strcmp(*argv, "key") != 0 && strcmp(*argv, "keys") != 0)
86 return 1;
87
88 argv++;
89 argc--;
90
91 return parse_keys(msg, argv, argc);
92 nla_put_failure:
93 return -ENOSPC;
94 }
95
96 static int leave_ibss(struct nl80211_state *state,
97 struct nl_cb *cb,
98 struct nl_msg *msg,
99 int argc, char **argv)
100 {
101 return 0;
102 }
103 COMMAND(ibss, leave, NULL,
104 NL80211_CMD_LEAVE_IBSS, 0, CIB_NETDEV, leave_ibss,
105 "Leave the current IBSS cell.");
106 COMMAND(ibss, join,
107 "<SSID> <freq in MHz> [fixed-freq] [<fixed bssid>] "
108 "[basic-rates <rate in Mbps,rate2,...>] [key d:0:abcde]",
109 NL80211_CMD_JOIN_IBSS, 0, CIB_NETDEV, join_ibss,
110 "Join the IBSS cell with the given SSID, if it doesn't exist create\n"
111 "it on the given frequency. When fixed frequency is requested, don't\n"
112 "join/create a cell on a different frequency. When a fixed BSSID is\n"
113 "requested use that BSSID and do not adopt another cell's BSSID even\n"
114 "if it has higher TSF and the same SSID.");