2 * FST module 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"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
14 #include "fst/fst_internal.h"
15 #include "fst/fst_defs.h"
16 #include "fst/fst_ctrl_iface.h"
18 struct dl_list fst_global_ctrls_list;
21 static void fst_ctrl_iface_notify_peer_state_change(struct fst_iface *iface,
25 union fst_event_extra extra;
27 extra.peer_state.connected = connected;
28 os_strlcpy(extra.peer_state.ifname, fst_iface_get_name(iface),
29 sizeof(extra.peer_state.ifname));
30 os_memcpy(extra.peer_state.addr, peer_addr, ETH_ALEN);
32 foreach_fst_ctrl_call(on_event, EVENT_PEER_STATE_CHANGED,
37 struct fst_iface * fst_attach(const char *ifname, const u8 *own_addr,
38 const struct fst_wpa_obj *iface_obj,
39 const struct fst_iface_cfg *cfg)
42 struct fst_group *group = NULL;
43 struct fst_iface *iface = NULL;
44 Boolean new_group = FALSE;
46 WPA_ASSERT(ifname != NULL);
47 WPA_ASSERT(iface_obj != NULL);
48 WPA_ASSERT(cfg != NULL);
50 foreach_fst_group(g) {
51 if (os_strcmp(cfg->group_id, fst_group_get_id(g)) == 0) {
58 group = fst_group_create(cfg->group_id);
60 fst_printf(MSG_ERROR, "%s: FST group cannot be created",
67 iface = fst_iface_create(group, ifname, own_addr, iface_obj, cfg);
69 fst_printf_group(group, MSG_ERROR, "cannot create iface for %s",
72 fst_group_delete(group);
76 fst_group_attach_iface(group, iface);
77 fst_group_update_ie(group);
79 foreach_fst_ctrl_call(on_iface_added, iface);
81 fst_printf_iface(iface, MSG_DEBUG,
82 "iface attached to group %s (prio=%d, llt=%d)",
83 cfg->group_id, cfg->priority, cfg->llt);
89 void fst_detach(struct fst_iface *iface)
91 struct fst_group *group = fst_iface_get_group(iface);
93 fst_printf_iface(iface, MSG_DEBUG, "iface detached from group %s",
94 fst_group_get_id(group));
95 fst_session_global_on_iface_detached(iface);
96 foreach_fst_ctrl_call(on_iface_removed, iface);
97 fst_group_detach_iface(group, iface);
98 fst_iface_delete(iface);
99 fst_group_update_ie(group);
100 fst_group_delete_if_empty(group);
104 int fst_global_init(void)
106 dl_list_init(&fst_global_groups_list);
107 dl_list_init(&fst_global_ctrls_list);
108 fst_session_global_init();
113 void fst_global_deinit(void)
115 struct fst_group *group;
116 struct fst_ctrl_handle *h;
118 fst_session_global_deinit();
119 while ((group = fst_first_group()) != NULL)
120 fst_group_delete(group);
121 while ((h = dl_list_first(&fst_global_ctrls_list,
122 struct fst_ctrl_handle,
123 global_ctrls_lentry)))
124 fst_global_del_ctrl(h);
128 struct fst_ctrl_handle * fst_global_add_ctrl(const struct fst_ctrl *ctrl)
130 struct fst_ctrl_handle *h;
135 h = os_zalloc(sizeof(*h));
139 if (ctrl->init && ctrl->init()) {
145 dl_list_add_tail(&fst_global_ctrls_list, &h->global_ctrls_lentry);
151 void fst_global_del_ctrl(struct fst_ctrl_handle *h)
153 dl_list_del(&h->global_ctrls_lentry);
160 void fst_rx_action(struct fst_iface *iface, const struct ieee80211_mgmt *mgmt,
163 if (fst_iface_is_connected(iface, mgmt->sa))
164 fst_session_on_action_rx(iface, mgmt, len);
166 wpa_printf(MSG_DEBUG,
167 "FST: Ignore FST Action frame - no FST connection with "
168 MACSTR, MAC2STR(mgmt->sa));
172 void fst_notify_peer_connected(struct fst_iface *iface, const u8 *addr)
174 if (is_zero_ether_addr(addr))
178 fst_group_update_ie(fst_iface_get_group(iface));
181 fst_printf_iface(iface, MSG_DEBUG, MACSTR " became connected",
184 fst_ctrl_iface_notify_peer_state_change(iface, TRUE, addr);
188 void fst_notify_peer_disconnected(struct fst_iface *iface, const u8 *addr)
190 if (is_zero_ether_addr(addr))
194 fst_group_update_ie(fst_iface_get_group(iface));
197 fst_printf_iface(iface, MSG_DEBUG, MACSTR " became disconnected",
200 fst_ctrl_iface_notify_peer_state_change(iface, FALSE, addr);
204 Boolean fst_are_ifaces_aggregated(struct fst_iface *iface1,
205 struct fst_iface *iface2)
207 return fst_iface_get_group(iface1) == fst_iface_get_group(iface2);
211 enum mb_band_id fst_hw_mode_to_band(enum hostapd_hw_mode mode)
214 case HOSTAPD_MODE_IEEE80211B:
215 case HOSTAPD_MODE_IEEE80211G:
216 return MB_BAND_ID_WIFI_2_4GHZ;
217 case HOSTAPD_MODE_IEEE80211A:
218 return MB_BAND_ID_WIFI_5GHZ;
219 case HOSTAPD_MODE_IEEE80211AD:
220 return MB_BAND_ID_WIFI_60GHZ;
223 return MB_BAND_ID_WIFI_2_4GHZ;