]>
Commit | Line | Data |
---|---|---|
edea4d14 JB |
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 | ||
4698bfc2 JB |
12 | SECTION(ibss); |
13 | ||
edea4d14 JB |
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 | { | |
95940df3 | 19 | char *end; |
edea4d14 | 20 | unsigned char abssid[6]; |
6a24bb22 TP |
21 | unsigned char rates[NL80211_MAX_SUPP_RATES]; |
22 | int n_rates = 0; | |
23 | char *value = NULL, *sptr = NULL; | |
24 | float rate; | |
edea4d14 | 25 | |
95940df3 JB |
26 | if (argc < 2) |
27 | return 1; | |
edea4d14 | 28 | |
95940df3 JB |
29 | /* SSID */ |
30 | NLA_PUT(msg, NL80211_ATTR_SSID, strlen(argv[0]), argv[0]); | |
edea4d14 JB |
31 | argv++; |
32 | argc--; | |
33 | ||
95940df3 JB |
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--; | |
edea4d14 | 41 | |
95940df3 JB |
42 | if (argc && strcmp(argv[0], "fixed-freq") == 0) { |
43 | NLA_PUT_FLAG(msg, NL80211_ATTR_FREQ_FIXED); | |
44 | argv++; | |
45 | argc--; | |
edea4d14 JB |
46 | } |
47 | ||
95940df3 | 48 | if (argc) { |
51e9bd80 JB |
49 | if (mac_addr_a2n(abssid, argv[0]) == 0) { |
50 | NLA_PUT(msg, NL80211_ATTR_MAC, 6, abssid); | |
51 | argv++; | |
52 | argc--; | |
53 | } | |
edea4d14 JB |
54 | } |
55 | ||
6a24bb22 TP |
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 | ||
1e03690e JB |
82 | if (!argc) |
83 | return 0; | |
edea4d14 | 84 | |
1e03690e JB |
85 | if (strcmp(*argv, "key") != 0 && strcmp(*argv, "keys") != 0) |
86 | return 1; | |
ded1f078 | 87 | |
1e03690e JB |
88 | argv++; |
89 | argc--; | |
51e9bd80 | 90 | |
1e03690e | 91 | return parse_keys(msg, argv, argc); |
edea4d14 JB |
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, | |
806bad30 JB |
104 | NL80211_CMD_LEAVE_IBSS, 0, CIB_NETDEV, leave_ibss, |
105 | "Leave the current IBSS cell."); | |
6a24bb22 TP |
106 | COMMAND(ibss, join, |
107 | "<SSID> <freq in MHz> [fixed-freq] [<fixed bssid>] " | |
108 | "[basic-rates <rate in Mbps,rate2,...>] [key d:0:abcde]", | |
806bad30 JB |
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."); |