1e5b75505Sopenharmony_ci/* 2e5b75505Sopenharmony_ci * FST module - interface definitions 3e5b75505Sopenharmony_ci * Copyright (c) 2014, Qualcomm Atheros, Inc. 4e5b75505Sopenharmony_ci * 5e5b75505Sopenharmony_ci * This software may be distributed under the terms of the BSD license. 6e5b75505Sopenharmony_ci * See README for more details. 7e5b75505Sopenharmony_ci */ 8e5b75505Sopenharmony_ci 9e5b75505Sopenharmony_ci#ifndef FST_H 10e5b75505Sopenharmony_ci#define FST_H 11e5b75505Sopenharmony_ci 12e5b75505Sopenharmony_ci#ifdef CONFIG_FST 13e5b75505Sopenharmony_ci 14e5b75505Sopenharmony_ci#include "common/defs.h" 15e5b75505Sopenharmony_ci#include "fst/fst_ctrl_iface.h" 16e5b75505Sopenharmony_ci 17e5b75505Sopenharmony_ci/* FST module hostap integration API */ 18e5b75505Sopenharmony_ci 19e5b75505Sopenharmony_ci#define US_IN_MS 1000 20e5b75505Sopenharmony_ci#define LLT_UNIT_US 32 /* See 10.32.2.2 Transitioning between states */ 21e5b75505Sopenharmony_ci 22e5b75505Sopenharmony_ci/* 23e5b75505Sopenharmony_ci * These were originally 24e5b75505Sopenharmony_ci * #define FST_LLT_MS_TO_VAL(m) (((u32) (m)) * US_IN_MS / LLT_UNIT_US) 25e5b75505Sopenharmony_ci * #define FST_LLT_VAL_TO_MS(v) (((u32) (v)) * LLT_UNIT_US / US_IN_MS) 26e5b75505Sopenharmony_ci * #define FST_MAX_LLT_MS FST_LLT_VAL_TO_MS(-1) 27e5b75505Sopenharmony_ci * but those can overflow 32-bit unsigned integer, so use alternative defines 28e5b75505Sopenharmony_ci * to avoid undefined behavior with such overflow. 29e5b75505Sopenharmony_ci * LLT_UNIT_US/US_IN_MS = 32/1000 = 4/125 30e5b75505Sopenharmony_ci */ 31e5b75505Sopenharmony_ci#define FST_LLT_MS_TO_VAL(m) (((u32) (m)) * 125 / 4) 32e5b75505Sopenharmony_ci#define FST_LLT_VAL_TO_MS(v) (((u32) (v)) * 4 / 125) 33e5b75505Sopenharmony_ci#define FST_MAX_LLT_MS (((u32) -1) / 4) 34e5b75505Sopenharmony_ci#define FST_MAX_PRIO_VALUE ((u8) -1) 35e5b75505Sopenharmony_ci#define FST_MAX_GROUP_ID_LEN IFNAMSIZ 36e5b75505Sopenharmony_ci 37e5b75505Sopenharmony_ci#define FST_DEFAULT_LLT_CFG_VALUE 50 38e5b75505Sopenharmony_ci 39e5b75505Sopenharmony_cistruct hostapd_hw_modes; 40e5b75505Sopenharmony_cistruct ieee80211_mgmt; 41e5b75505Sopenharmony_cistruct fst_iface; 42e5b75505Sopenharmony_cistruct fst_group; 43e5b75505Sopenharmony_cistruct fst_session; 44e5b75505Sopenharmony_cistruct fst_get_peer_ctx; 45e5b75505Sopenharmony_cistruct fst_ctrl_handle; 46e5b75505Sopenharmony_ci 47e5b75505Sopenharmony_cistruct fst_wpa_obj { 48e5b75505Sopenharmony_ci void *ctx; 49e5b75505Sopenharmony_ci 50e5b75505Sopenharmony_ci /** 51e5b75505Sopenharmony_ci * get_bssid - Get BSSID of the interface 52e5b75505Sopenharmony_ci * @ctx: User context %ctx 53e5b75505Sopenharmony_ci * Returns: BSSID for success, %NULL for failure. 54e5b75505Sopenharmony_ci * 55e5b75505Sopenharmony_ci * NOTE: For AP it returns the own BSSID, while for STA - the BSSID of 56e5b75505Sopenharmony_ci * the associated AP. 57e5b75505Sopenharmony_ci */ 58e5b75505Sopenharmony_ci const u8 * (*get_bssid)(void *ctx); 59e5b75505Sopenharmony_ci 60e5b75505Sopenharmony_ci /** 61e5b75505Sopenharmony_ci * get_channel_info - Get current channel info 62e5b75505Sopenharmony_ci * @ctx: User context %ctx 63e5b75505Sopenharmony_ci * @hw_mode: OUT, current HW mode 64e5b75505Sopenharmony_ci * @channel: OUT, current channel 65e5b75505Sopenharmony_ci */ 66e5b75505Sopenharmony_ci void (*get_channel_info)(void *ctx, enum hostapd_hw_mode *hw_mode, 67e5b75505Sopenharmony_ci u8 *channel); 68e5b75505Sopenharmony_ci 69e5b75505Sopenharmony_ci /** 70e5b75505Sopenharmony_ci * get_hw_modes - Get hardware modes 71e5b75505Sopenharmony_ci * @ctx: User context %ctx 72e5b75505Sopenharmony_ci * @modes: OUT, pointer on array of hw modes 73e5b75505Sopenharmony_ci * 74e5b75505Sopenharmony_ci * Returns: Number of hw modes available. 75e5b75505Sopenharmony_ci */ 76e5b75505Sopenharmony_ci int (*get_hw_modes)(void *ctx, struct hostapd_hw_modes **modes); 77e5b75505Sopenharmony_ci 78e5b75505Sopenharmony_ci /** 79e5b75505Sopenharmony_ci * set_ies - Set interface's MB IE 80e5b75505Sopenharmony_ci * @ctx: User context %ctx 81e5b75505Sopenharmony_ci * @fst_ies: MB IE buffer (owned by FST module) 82e5b75505Sopenharmony_ci */ 83e5b75505Sopenharmony_ci void (*set_ies)(void *ctx, const struct wpabuf *fst_ies); 84e5b75505Sopenharmony_ci 85e5b75505Sopenharmony_ci /** 86e5b75505Sopenharmony_ci * send_action - Send FST Action frame via the interface 87e5b75505Sopenharmony_ci * @ctx: User context %ctx 88e5b75505Sopenharmony_ci * @addr: Address of the destination STA 89e5b75505Sopenharmony_ci * @data: Action frame buffer 90e5b75505Sopenharmony_ci * Returns: 0 for success, negative error code for failure. 91e5b75505Sopenharmony_ci */ 92e5b75505Sopenharmony_ci int (*send_action)(void *ctx, const u8 *addr, struct wpabuf *data); 93e5b75505Sopenharmony_ci 94e5b75505Sopenharmony_ci /** 95e5b75505Sopenharmony_ci * get_mb_ie - Get last MB IE received from STA 96e5b75505Sopenharmony_ci * @ctx: User context %ctx 97e5b75505Sopenharmony_ci * @addr: Address of the STA 98e5b75505Sopenharmony_ci * Returns: MB IE buffer, %NULL if no MB IE received from the STA 99e5b75505Sopenharmony_ci */ 100e5b75505Sopenharmony_ci const struct wpabuf * (*get_mb_ie)(void *ctx, const u8 *addr); 101e5b75505Sopenharmony_ci 102e5b75505Sopenharmony_ci /** 103e5b75505Sopenharmony_ci * update_mb_ie - Update last MB IE received from STA 104e5b75505Sopenharmony_ci * @ctx: User context %ctx 105e5b75505Sopenharmony_ci * @addr: Address of the STA 106e5b75505Sopenharmony_ci * @buf: Buffer that contains the MB IEs data 107e5b75505Sopenharmony_ci * @size: Size of data in %buf 108e5b75505Sopenharmony_ci */ 109e5b75505Sopenharmony_ci void (*update_mb_ie)(void *ctx, const u8 *addr, 110e5b75505Sopenharmony_ci const u8 *buf, size_t size); 111e5b75505Sopenharmony_ci 112e5b75505Sopenharmony_ci /** 113e5b75505Sopenharmony_ci * get_peer_first - Get MAC address of the 1st connected STA 114e5b75505Sopenharmony_ci * @ctx: User context %ctx 115e5b75505Sopenharmony_ci * @get_ctx: Context to be used for %get_peer_next call 116e5b75505Sopenharmony_ci * @mb_only: %true if only multi-band capable peer should be reported 117e5b75505Sopenharmony_ci * Returns: Address of the 1st connected STA, %NULL if no STAs connected 118e5b75505Sopenharmony_ci */ 119e5b75505Sopenharmony_ci const u8 * (*get_peer_first)(void *ctx, 120e5b75505Sopenharmony_ci struct fst_get_peer_ctx **get_ctx, 121e5b75505Sopenharmony_ci bool mb_only); 122e5b75505Sopenharmony_ci /** 123e5b75505Sopenharmony_ci * get_peer_next - Get MAC address of the next connected STA 124e5b75505Sopenharmony_ci * @ctx: User context %ctx 125e5b75505Sopenharmony_ci * @get_ctx: Context received from %get_peer_first or previous 126e5b75505Sopenharmony_ci * %get_peer_next call 127e5b75505Sopenharmony_ci * @mb_only: %true if only multi-band capable peer should be reported 128e5b75505Sopenharmony_ci * Returns: Address of the next connected STA, %NULL if no more STAs 129e5b75505Sopenharmony_ci * connected 130e5b75505Sopenharmony_ci */ 131e5b75505Sopenharmony_ci const u8 * (*get_peer_next)(void *ctx, 132e5b75505Sopenharmony_ci struct fst_get_peer_ctx **get_ctx, 133e5b75505Sopenharmony_ci bool mb_only); 134e5b75505Sopenharmony_ci}; 135e5b75505Sopenharmony_ci 136e5b75505Sopenharmony_ci/** 137e5b75505Sopenharmony_ci * fst_global_init - Global FST module initiator 138e5b75505Sopenharmony_ci * Returns: 0 for success, negative error code for failure. 139e5b75505Sopenharmony_ci * Note: The purpose of this function is to allocate and initiate global 140e5b75505Sopenharmony_ci * FST module data structures (linked lists, static data etc.) 141e5b75505Sopenharmony_ci * This function should be called prior to the 1st %fst_attach call. 142e5b75505Sopenharmony_ci */ 143e5b75505Sopenharmony_ciint fst_global_init(void); 144e5b75505Sopenharmony_ci 145e5b75505Sopenharmony_ci/** 146e5b75505Sopenharmony_ci * fst_global_deinit - Global FST module de-initiator 147e5b75505Sopenharmony_ci * Note: The purpose of this function is to deallocate and de-initiate global 148e5b75505Sopenharmony_ci * FST module data structures (linked lists, static data etc.) 149e5b75505Sopenharmony_ci */ 150e5b75505Sopenharmony_civoid fst_global_deinit(void); 151e5b75505Sopenharmony_ci 152e5b75505Sopenharmony_ci/** 153e5b75505Sopenharmony_ci * struct fst_ctrl - Notification interface for FST module 154e5b75505Sopenharmony_ci */ 155e5b75505Sopenharmony_cistruct fst_ctrl { 156e5b75505Sopenharmony_ci /** 157e5b75505Sopenharmony_ci * init - Initialize the notification interface 158e5b75505Sopenharmony_ci * Returns: 0 for success, negative error code for failure. 159e5b75505Sopenharmony_ci */ 160e5b75505Sopenharmony_ci int (*init)(void); 161e5b75505Sopenharmony_ci 162e5b75505Sopenharmony_ci /** 163e5b75505Sopenharmony_ci * deinit - Deinitialize the notification interface 164e5b75505Sopenharmony_ci */ 165e5b75505Sopenharmony_ci void (*deinit)(void); 166e5b75505Sopenharmony_ci 167e5b75505Sopenharmony_ci /** 168e5b75505Sopenharmony_ci * on_group_created - Notify about FST group creation 169e5b75505Sopenharmony_ci * Returns: 0 for success, negative error code for failure. 170e5b75505Sopenharmony_ci */ 171e5b75505Sopenharmony_ci int (*on_group_created)(struct fst_group *g); 172e5b75505Sopenharmony_ci 173e5b75505Sopenharmony_ci /** 174e5b75505Sopenharmony_ci * on_group_deleted - Notify about FST group deletion 175e5b75505Sopenharmony_ci */ 176e5b75505Sopenharmony_ci void (*on_group_deleted)(struct fst_group *g); 177e5b75505Sopenharmony_ci 178e5b75505Sopenharmony_ci /** 179e5b75505Sopenharmony_ci * on_iface_added - Notify about interface addition 180e5b75505Sopenharmony_ci * Returns: 0 for success, negative error code for failure. 181e5b75505Sopenharmony_ci */ 182e5b75505Sopenharmony_ci int (*on_iface_added)(struct fst_iface *i); 183e5b75505Sopenharmony_ci 184e5b75505Sopenharmony_ci /** 185e5b75505Sopenharmony_ci * on_iface_removed - Notify about interface removal 186e5b75505Sopenharmony_ci */ 187e5b75505Sopenharmony_ci void (*on_iface_removed)(struct fst_iface *i); 188e5b75505Sopenharmony_ci 189e5b75505Sopenharmony_ci /** 190e5b75505Sopenharmony_ci * on_session_added - Notify about FST session addition 191e5b75505Sopenharmony_ci * Returns: 0 for success, negative error code for failure. 192e5b75505Sopenharmony_ci */ 193e5b75505Sopenharmony_ci int (*on_session_added)(struct fst_session *s); 194e5b75505Sopenharmony_ci 195e5b75505Sopenharmony_ci /** 196e5b75505Sopenharmony_ci * on_session_removed - Notify about FST session removal 197e5b75505Sopenharmony_ci */ 198e5b75505Sopenharmony_ci void (*on_session_removed)(struct fst_session *s); 199e5b75505Sopenharmony_ci 200e5b75505Sopenharmony_ci /** 201e5b75505Sopenharmony_ci * on_event - Notify about FST event 202e5b75505Sopenharmony_ci * @event_type: Event type 203e5b75505Sopenharmony_ci * @i: Interface object that relates to the event or NULL 204e5b75505Sopenharmony_ci * @g: Group object that relates to the event or NULL 205e5b75505Sopenharmony_ci * @extra - Event specific data (see fst_ctrl_iface.h for more info) 206e5b75505Sopenharmony_ci */ 207e5b75505Sopenharmony_ci void (*on_event)(enum fst_event_type event_type, struct fst_iface *i, 208e5b75505Sopenharmony_ci struct fst_session *s, 209e5b75505Sopenharmony_ci const union fst_event_extra *extra); 210e5b75505Sopenharmony_ci}; 211e5b75505Sopenharmony_ci 212e5b75505Sopenharmony_cistruct fst_ctrl_handle * fst_global_add_ctrl(const struct fst_ctrl *ctrl); 213e5b75505Sopenharmony_civoid fst_global_del_ctrl(struct fst_ctrl_handle *h); 214e5b75505Sopenharmony_ci 215e5b75505Sopenharmony_ci/** 216e5b75505Sopenharmony_ci * NOTE: These values have to be read from configuration file 217e5b75505Sopenharmony_ci */ 218e5b75505Sopenharmony_cistruct fst_iface_cfg { 219e5b75505Sopenharmony_ci char group_id[FST_MAX_GROUP_ID_LEN + 1]; 220e5b75505Sopenharmony_ci u8 priority; 221e5b75505Sopenharmony_ci u32 llt; 222e5b75505Sopenharmony_ci}; 223e5b75505Sopenharmony_ci 224e5b75505Sopenharmony_ci/** 225e5b75505Sopenharmony_ci * fst_attach - Attach interface to an FST group according to configuration read 226e5b75505Sopenharmony_ci * @ifname: Interface name 227e5b75505Sopenharmony_ci * @own_addr: Own interface MAC address 228e5b75505Sopenharmony_ci * @iface_obj: Callbacks to be used by FST module to communicate with 229e5b75505Sopenharmony_ci * hostapd/wpa_supplicant 230e5b75505Sopenharmony_ci * @cfg: FST-related interface configuration read from the configuration file 231e5b75505Sopenharmony_ci * Returns: FST interface object for success, %NULL for failure. 232e5b75505Sopenharmony_ci */ 233e5b75505Sopenharmony_cistruct fst_iface * fst_attach(const char *ifname, 234e5b75505Sopenharmony_ci const u8 *own_addr, 235e5b75505Sopenharmony_ci const struct fst_wpa_obj *iface_obj, 236e5b75505Sopenharmony_ci const struct fst_iface_cfg *cfg); 237e5b75505Sopenharmony_ci 238e5b75505Sopenharmony_ci/** 239e5b75505Sopenharmony_ci * fst_detach - Detach an interface 240e5b75505Sopenharmony_ci * @iface: FST interface object 241e5b75505Sopenharmony_ci */ 242e5b75505Sopenharmony_civoid fst_detach(struct fst_iface *iface); 243e5b75505Sopenharmony_ci 244e5b75505Sopenharmony_ci/* FST module inputs */ 245e5b75505Sopenharmony_ci/** 246e5b75505Sopenharmony_ci * fst_rx_action - FST Action frames handler 247e5b75505Sopenharmony_ci * @iface: FST interface object 248e5b75505Sopenharmony_ci * @mgmt: Action frame arrived 249e5b75505Sopenharmony_ci * @len: Action frame length 250e5b75505Sopenharmony_ci */ 251e5b75505Sopenharmony_civoid fst_rx_action(struct fst_iface *iface, const struct ieee80211_mgmt *mgmt, 252e5b75505Sopenharmony_ci size_t len); 253e5b75505Sopenharmony_ci 254e5b75505Sopenharmony_ci/** 255e5b75505Sopenharmony_ci * fst_notify_peer_connected - FST STA connect handler 256e5b75505Sopenharmony_ci * @iface: FST interface object 257e5b75505Sopenharmony_ci * @addr: Address of the connected STA 258e5b75505Sopenharmony_ci */ 259e5b75505Sopenharmony_civoid fst_notify_peer_connected(struct fst_iface *iface, const u8 *addr); 260e5b75505Sopenharmony_ci 261e5b75505Sopenharmony_ci/** 262e5b75505Sopenharmony_ci * fst_notify_peer_disconnected - FST STA disconnect handler 263e5b75505Sopenharmony_ci * @iface: FST interface object 264e5b75505Sopenharmony_ci * @addr: Address of the disconnected STA 265e5b75505Sopenharmony_ci */ 266e5b75505Sopenharmony_civoid fst_notify_peer_disconnected(struct fst_iface *iface, const u8 *addr); 267e5b75505Sopenharmony_ci 268e5b75505Sopenharmony_ci/* FST module auxiliary routines */ 269e5b75505Sopenharmony_ci 270e5b75505Sopenharmony_ci/** 271e5b75505Sopenharmony_ci * fst_are_ifaces_aggregated - Determines whether 2 interfaces belong to the 272e5b75505Sopenharmony_ci * same FST group 273e5b75505Sopenharmony_ci * @iface1: 1st FST interface object 274e5b75505Sopenharmony_ci * @iface1: 2nd FST interface object 275e5b75505Sopenharmony_ci * 276e5b75505Sopenharmony_ci * Returns: %true if the interfaces belong to the same FST group, 277e5b75505Sopenharmony_ci * %false otherwise 278e5b75505Sopenharmony_ci */ 279e5b75505Sopenharmony_cibool fst_are_ifaces_aggregated(struct fst_iface *iface1, 280e5b75505Sopenharmony_ci struct fst_iface *iface2); 281e5b75505Sopenharmony_ci 282e5b75505Sopenharmony_ci/** 283e5b75505Sopenharmony_ci * fst_update_mac_addr - Notify FST about MAC address change 284e5b75505Sopenharmony_ci * @iface: FST interface object 285e5b75505Sopenharmony_ci * @addr: New MAC address 286e5b75505Sopenharmony_ci */ 287e5b75505Sopenharmony_civoid fst_update_mac_addr(struct fst_iface *iface, const u8 *addr); 288e5b75505Sopenharmony_ci 289e5b75505Sopenharmony_ci#else /* CONFIG_FST */ 290e5b75505Sopenharmony_ci 291e5b75505Sopenharmony_cistatic inline int fst_global_init(void) 292e5b75505Sopenharmony_ci{ 293e5b75505Sopenharmony_ci return 0; 294e5b75505Sopenharmony_ci} 295e5b75505Sopenharmony_ci 296e5b75505Sopenharmony_cistatic inline int fst_global_start(void) 297e5b75505Sopenharmony_ci{ 298e5b75505Sopenharmony_ci return 0; 299e5b75505Sopenharmony_ci} 300e5b75505Sopenharmony_ci 301e5b75505Sopenharmony_cistatic inline void fst_global_stop(void) 302e5b75505Sopenharmony_ci{ 303e5b75505Sopenharmony_ci} 304e5b75505Sopenharmony_ci 305e5b75505Sopenharmony_cistatic inline void fst_global_deinit(void) 306e5b75505Sopenharmony_ci{ 307e5b75505Sopenharmony_ci} 308e5b75505Sopenharmony_ci 309e5b75505Sopenharmony_ci#endif /* CONFIG_FST */ 310e5b75505Sopenharmony_ci 311e5b75505Sopenharmony_ci#endif /* FST_H */ 312