2 * FST module - FST group object implementation
3 * Copyright (c) 2014, Qualcomm Atheros, Inc.
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
10 #include "utils/common.h"
11 #include "common/defs.h"
12 #include "common/ieee802_11_defs.h"
13 #include "common/ieee802_11_common.h"
14 #include "drivers/driver.h"
15 #include "fst/fst_internal.h"
16 #include "fst/fst_defs.h"
19 struct dl_list fst_global_groups_list;
22 static void fst_dump_mb_ies(const char *group_id, const char *ifname,
25 const u8 *p = wpabuf_head(mbies);
26 size_t s = wpabuf_len(mbies);
29 const struct multi_band_ie *mbie =
30 (const struct multi_band_ie *) p;
31 WPA_ASSERT(mbie->eid == WLAN_EID_MULTI_BAND);
32 WPA_ASSERT(2 + mbie->len >= sizeof(*mbie));
34 fst_printf(MSG_WARNING,
35 "%s: %s: mb_ctrl=%u band_id=%u op_class=%u chan=%u bssid="
37 " beacon_int=%u tsf_offs=[%u %u %u %u %u %u %u %u] mb_cc=0x%02x tmout=%u",
39 mbie->mb_ctrl, mbie->band_id, mbie->op_class,
40 mbie->chan, MAC2STR(mbie->bssid), mbie->beacon_int,
41 mbie->tsf_offs[0], mbie->tsf_offs[1],
42 mbie->tsf_offs[2], mbie->tsf_offs[3],
43 mbie->tsf_offs[4], mbie->tsf_offs[5],
44 mbie->tsf_offs[6], mbie->tsf_offs[7],
45 mbie->mb_connection_capability,
46 mbie->fst_session_tmout);
54 static void fst_fill_mb_ie(struct wpabuf *buf, const u8 *bssid,
55 const u8 *own_addr, enum mb_band_id band, u8 channel)
57 struct multi_band_ie *mbie;
58 size_t len = sizeof(*mbie);
63 mbie = wpabuf_put(buf, len);
65 os_memset(mbie, 0, len);
67 mbie->eid = WLAN_EID_MULTI_BAND;
70 mbie->mb_ctrl = MB_STA_ROLE_AP;
71 mbie->mb_connection_capability = MB_CONNECTION_CAPABILITY_AP;
73 mbie->mb_ctrl = MB_STA_ROLE_NON_PCP_NON_AP;
74 mbie->mb_connection_capability = 0;
77 os_memcpy(mbie->bssid, bssid, ETH_ALEN);
79 mbie->op_class = 0; /* means all */
81 mbie->fst_session_tmout = FST_DEFAULT_SESSION_TIMEOUT_TU;
84 mbie->mb_ctrl |= MB_CTRL_STA_MAC_PRESENT;
85 os_memcpy(&mbie[1], own_addr, ETH_ALEN);
90 static unsigned fst_fill_iface_mb_ies(struct fst_iface *f, struct wpabuf *buf)
94 bssid = fst_iface_get_bssid(f);
96 enum hostapd_hw_mode hw_mode;
100 fst_iface_get_channel_info(f, &hw_mode, &channel);
101 fst_fill_mb_ie(buf, bssid, fst_iface_get_addr(f),
102 fst_hw_mode_to_band(hw_mode), channel);
106 unsigned bands[MB_BAND_ID_WIFI_60GHZ + 1] = {};
107 struct hostapd_hw_modes *modes;
109 int num_modes = fst_iface_get_hw_modes(f, &modes);
112 while (num_modes--) {
113 b = fst_hw_mode_to_band(modes->mode);
115 if (b >= ARRAY_SIZE(bands) || bands[b]++)
119 fst_fill_mb_ie(buf, NULL, fst_iface_get_addr(f),
120 b, MB_STA_CHANNEL_ALL);
127 static struct wpabuf * fst_group_create_mb_ie(struct fst_group *g,
132 unsigned int nof_mbies = 0;
133 unsigned int nof_ifaces_added = 0;
135 foreach_fst_group_iface(g, f) {
138 nof_mbies += fst_fill_iface_mb_ies(f, NULL);
141 buf = wpabuf_alloc(nof_mbies *
142 (sizeof(struct multi_band_ie) + ETH_ALEN));
144 fst_printf_iface(i, MSG_ERROR,
145 "cannot allocate mem for %u MB IEs",
150 /* The list is sorted in descending order by priorities, so MB IEs will
151 * be arranged in the same order, as required by spec (see corresponding
152 * comment in.fst_attach().
154 foreach_fst_group_iface(g, f) {
158 fst_fill_iface_mb_ies(f, buf);
161 fst_printf_iface(i, MSG_DEBUG, "added to MB IE");
164 if (!nof_ifaces_added) {
167 fst_printf_iface(i, MSG_INFO,
168 "cannot add MB IE: no backup ifaces");
170 fst_dump_mb_ies(fst_group_get_id(g), fst_iface_get_name(i),
178 static const u8 * fst_mbie_get_peer_addr(const struct multi_band_ie *mbie)
180 const u8 *peer_addr = NULL;
182 switch (MB_CTRL_ROLE(mbie->mb_ctrl)) {
184 peer_addr = mbie->bssid;
186 case MB_STA_ROLE_NON_PCP_NON_AP:
187 if (mbie->mb_ctrl & MB_CTRL_STA_MAC_PRESENT &&
188 (size_t) 2 + mbie->len >= sizeof(*mbie) + ETH_ALEN)
189 peer_addr = (const u8 *) &mbie[1];
199 static struct fst_iface *
200 fst_group_get_new_iface_by_mbie_and_band_id(struct fst_group *g,
201 const u8 *mb_ies_buff,
206 while (mb_ies_size >= 2) {
207 const struct multi_band_ie *mbie =
208 (const struct multi_band_ie *) mb_ies_buff;
210 if (mbie->eid != WLAN_EID_MULTI_BAND ||
211 (size_t) 2 + mbie->len < sizeof(*mbie))
214 if (mbie->band_id == band_id) {
215 struct fst_iface *iface;
217 foreach_fst_group_iface(g, iface) {
218 const u8 *peer_addr =
219 fst_mbie_get_peer_addr(mbie);
222 fst_iface_is_connected(iface, peer_addr,
224 band_id == fst_iface_get_band_id(iface)) {
225 os_memcpy(iface_peer_addr, peer_addr,
233 mb_ies_buff += 2 + mbie->len;
234 mb_ies_size -= 2 + mbie->len;
241 struct fst_iface * fst_group_get_iface_by_name(struct fst_group *g,
246 foreach_fst_group_iface(g, f) {
247 const char *in = fst_iface_get_name(f);
249 if (os_strncmp(in, ifname, os_strlen(in)) == 0)
257 u8 fst_group_assign_dialog_token(struct fst_group *g)
260 if (g->dialog_token == 0)
262 return g->dialog_token;
266 u32 fst_group_assign_fsts_id(struct fst_group *g)
274 fst_group_does_iface_appear_in_other_mbies(struct fst_group *g,
275 struct fst_iface *iface,
276 struct fst_iface *other,
279 struct fst_get_peer_ctx *ctx;
281 const u8 *iface_addr;
282 enum mb_band_id iface_band_id;
284 WPA_ASSERT(g == fst_iface_get_group(iface));
285 WPA_ASSERT(g == fst_iface_get_group(other));
287 iface_addr = fst_iface_get_addr(iface);
288 iface_band_id = fst_iface_get_band_id(iface);
290 addr = fst_iface_get_peer_first(other, &ctx, TRUE);
291 for (; addr; addr = fst_iface_get_peer_next(other, &ctx, TRUE)) {
292 const struct wpabuf *mbies;
293 u8 other_iface_peer_addr[ETH_ALEN];
294 struct fst_iface *other_new_iface;
296 mbies = fst_iface_get_peer_mb_ie(other, addr);
300 other_new_iface = fst_group_get_new_iface_by_mbie_and_band_id(
301 g, wpabuf_head(mbies), wpabuf_len(mbies),
302 iface_band_id, other_iface_peer_addr);
303 if (other_new_iface == iface &&
304 os_memcmp(iface_addr, other_iface_peer_addr,
306 os_memcpy(peer_addr, addr, ETH_ALEN);
316 fst_group_find_new_iface_by_stie(struct fst_group *g,
317 struct fst_iface *iface,
319 const struct session_transition_ie *stie,
324 foreach_fst_group_iface(g, i) {
326 stie->new_band_id != fst_iface_get_band_id(i))
328 if (fst_group_does_iface_appear_in_other_mbies(g, iface, i,
338 fst_group_get_new_iface_by_stie_and_mbie(
339 struct fst_group *g, const u8 *mb_ies_buff, size_t mb_ies_size,
340 const struct session_transition_ie *stie, u8 *iface_peer_addr)
342 return fst_group_get_new_iface_by_mbie_and_band_id(
343 g, mb_ies_buff, mb_ies_size, stie->new_band_id,
348 struct fst_group * fst_group_create(const char *group_id)
352 g = os_zalloc(sizeof(*g));
354 fst_printf(MSG_ERROR, "%s: Cannot alloc group", group_id);
358 dl_list_init(&g->ifaces);
359 os_strlcpy(g->group_id, group_id, sizeof(g->group_id));
361 dl_list_add_tail(&fst_global_groups_list, &g->global_groups_lentry);
362 fst_printf_group(g, MSG_DEBUG, "instance created");
364 foreach_fst_ctrl_call(on_group_created, g);
370 void fst_group_attach_iface(struct fst_group *g, struct fst_iface *i)
372 struct dl_list *list = &g->ifaces;
376 * Add new interface to the list.
377 * The list is sorted in descending order by priority to allow
378 * multiple MB IEs creation according to the spec (see 10.32 Multi-band
379 * operation, 10.32.1 General), as they should be ordered according to
382 foreach_fst_group_iface(g, f) {
383 if (fst_iface_get_priority(f) < fst_iface_get_priority(i))
385 list = &f->group_lentry;
387 dl_list_add(list, &i->group_lentry);
391 void fst_group_detach_iface(struct fst_group *g, struct fst_iface *i)
393 dl_list_del(&i->group_lentry);
397 void fst_group_delete(struct fst_group *group)
399 struct fst_session *s;
401 dl_list_del(&group->global_groups_lentry);
402 WPA_ASSERT(dl_list_empty(&group->ifaces));
403 foreach_fst_ctrl_call(on_group_deleted, group);
404 fst_printf_group(group, MSG_DEBUG, "instance deleted");
405 while ((s = fst_session_global_get_first_by_group(group)) != NULL)
406 fst_session_delete(s);
411 Boolean fst_group_delete_if_empty(struct fst_group *group)
413 Boolean is_empty = !fst_group_has_ifaces(group) &&
414 !fst_session_global_get_first_by_group(group);
417 fst_group_delete(group);
423 void fst_group_update_ie(struct fst_group *g)
427 foreach_fst_group_iface(g, i) {
428 struct wpabuf *mbie = fst_group_create_mb_ie(g, i);
431 fst_printf_iface(i, MSG_WARNING, "cannot create MB IE");
433 fst_iface_attach_mbie(i, mbie);
434 fst_iface_set_ies(i, mbie);
435 fst_printf_iface(i, MSG_DEBUG, "multi-band IE set to %p", mbie);