8 #include <netlink/genl/genl.h>
9 #include <netlink/genl/family.h>
10 #include <netlink/genl/ctrl.h>
11 #include <netlink/msg.h>
12 #include <netlink/attr.h>
19 static int join_ibss(struct nl80211_state
*state
,
21 int argc
, char **argv
,
25 unsigned char abssid
[6];
26 unsigned char rates
[NL80211_MAX_SUPP_RATES
];
28 char *value
= NULL
, *sptr
= NULL
;
37 int chantype
; /* for older kernel */
38 } *chanmode_selected
= NULL
, chanmode
[] = {
40 .width
= NL80211_CHAN_WIDTH_20
,
42 .chantype
= NL80211_CHAN_HT20
},
44 .width
= NL80211_CHAN_WIDTH_40
,
46 .chantype
= NL80211_CHAN_HT40PLUS
},
48 .width
= NL80211_CHAN_WIDTH_40
,
50 .chantype
= NL80211_CHAN_HT40MINUS
},
52 .width
= NL80211_CHAN_WIDTH_20_NOHT
,
54 .chantype
= NL80211_CHAN_NO_HT
},
56 .width
= NL80211_CHAN_WIDTH_5
,
60 .width
= NL80211_CHAN_WIDTH_10
,
69 NLA_PUT(msg
, NL80211_ATTR_SSID
, strlen(argv
[0]), argv
[0]);
74 freq
= strtoul(argv
[0], &end
, 10);
78 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
83 for (i
= 0; i
< ARRAY_SIZE(chanmode
); i
++) {
84 if (strcasecmp(chanmode
[i
].name
, argv
[0]) == 0) {
85 chanmode_selected
= &chanmode
[i
];
89 if (chanmode_selected
) {
90 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
91 chanmode_selected
->width
);
92 NLA_PUT_U32(msg
, NL80211_ATTR_CENTER_FREQ1
,
93 freq
+ chanmode_selected
->freq1_diff
);
94 if (chanmode_selected
->chantype
!= -1)
96 NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
97 chanmode_selected
->chantype
);
105 if (argc
&& strcmp(argv
[0], "fixed-freq") == 0) {
106 NLA_PUT_FLAG(msg
, NL80211_ATTR_FREQ_FIXED
);
112 if (mac_addr_a2n(abssid
, argv
[0]) == 0) {
113 NLA_PUT(msg
, NL80211_ATTR_MAC
, 6, abssid
);
119 if (argc
> 1 && strcmp(argv
[0], "beacon-interval") == 0) {
122 bintval
= strtoul(argv
[0], &end
, 10);
125 NLA_PUT_U32(msg
, NL80211_ATTR_BEACON_INTERVAL
, bintval
);
131 if (argc
> 1 && strcmp(argv
[0], "basic-rates") == 0) {
135 value
= strtok_r(argv
[0], ",", &sptr
);
137 while (value
&& n_rates
< NL80211_MAX_SUPP_RATES
) {
138 rate
= strtod(value
, &end
);
139 rates
[n_rates
] = rate
* 2;
141 /* filter out suspicious values */
142 if (*end
!= '\0' || !rates
[n_rates
] ||
143 rate
*2 != rates
[n_rates
])
147 value
= strtok_r(NULL
, ",", &sptr
);
150 NLA_PUT(msg
, NL80211_ATTR_BSS_BASIC_RATES
, n_rates
, rates
);
157 if (argc
> 1 && strcmp(argv
[0], "mcast-rate") == 0) {
161 rate
= strtod(argv
[0], &end
);
165 NLA_PUT_U32(msg
, NL80211_ATTR_MCAST_RATE
, (int)(rate
* 10));
173 if (strcmp(*argv
, "key") != 0 && strcmp(*argv
, "keys") != 0)
179 return parse_keys(msg
, argv
, argc
);
184 static int leave_ibss(struct nl80211_state
*state
,
186 int argc
, char **argv
,
191 COMMAND(ibss
, leave
, NULL
,
192 NL80211_CMD_LEAVE_IBSS
, 0, CIB_NETDEV
, leave_ibss
,
193 "Leave the current IBSS cell.");
195 "<SSID> <freq in MHz> [HT20|HT40+|HT40-|NOHT|5MHZ|10MHZ] [fixed-freq] [<fixed bssid>] [beacon-interval <TU>]"
196 " [basic-rates <rate in Mbps,rate2,...>] [mcast-rate <rate in Mbps>] "
198 NL80211_CMD_JOIN_IBSS
, 0, CIB_NETDEV
, join_ibss
,
199 "Join the IBSS cell with the given SSID, if it doesn't exist create\n"
200 "it on the given frequency. When fixed frequency is requested, don't\n"
201 "join/create a cell on a different frequency. When a fixed BSSID is\n"
202 "requested use that BSSID and do not adopt another cell's BSSID even\n"
203 "if it has higher TSF and the same SSID. If an IBSS is created, create\n"
204 "it with the specified basic-rates, multicast-rate and beacon-interval.");