948c5568ed7bee812587d1db9a432c359f98a494
[mech_eap.git] / src / fst / fst_internal.h
1 /*
2  * FST module - auxiliary definitions
3  * Copyright (c) 2014, Qualcomm Atheros, Inc.
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  */
8
9 #ifndef FST_INTERNAL_H
10 #define FST_INTERNAL_H
11
12 #include "utils/includes.h"
13 #include "utils/common.h"
14 #include "common/defs.h"
15 #include "common/ieee802_11_defs.h"
16 #include "fst/fst_iface.h"
17 #include "fst/fst_group.h"
18 #include "fst/fst_session.h"
19
20 #define fst_printf(level, format, ...) \
21         wpa_printf((level), "FST: " format, ##__VA_ARGS__)
22
23 #define fst_printf_group(group, level, format, ...) \
24         wpa_printf((level), "FST: %s: " format, \
25                    fst_group_get_id(group), ##__VA_ARGS__)
26
27 #define fst_printf_iface(iface, level, format, ...) \
28         fst_printf_group(fst_iface_get_group(iface), (level), "%s: " format, \
29                          fst_iface_get_name(iface), ##__VA_ARGS__)
30
31 static inline enum mb_band_id
32 fst_hw_mode_to_band(enum hostapd_hw_mode mode)
33 {
34         switch (mode) {
35         case HOSTAPD_MODE_IEEE80211B:
36         case HOSTAPD_MODE_IEEE80211G:
37                 return MB_BAND_ID_WIFI_2_4GHZ;
38         case HOSTAPD_MODE_IEEE80211A:
39                 return MB_BAND_ID_WIFI_5GHZ;
40         case HOSTAPD_MODE_IEEE80211AD:
41                 return MB_BAND_ID_WIFI_60GHZ;
42         default:
43                 WPA_ASSERT(0);
44                 return MB_BAND_ID_WIFI_2_4GHZ;
45         }
46 }
47
48 #define IE_HEADER_SIZE               ((u8) (2 * sizeof(u8)))
49 #define IE_BUFFER_LENGTH(ie_len_val) ((size_t) ((ie_len_val) + IE_HEADER_SIZE))
50
51 static inline const u8 *
52 fst_mbie_get_peer_addr(const struct multi_band_ie *mbie)
53 {
54         const u8 *peer_addr = NULL;
55
56         switch (MB_CTRL_ROLE(mbie->mb_ctrl)) {
57         case MB_STA_ROLE_AP:
58                 peer_addr = mbie->bssid;
59                 break;
60         case MB_STA_ROLE_NON_PCP_NON_AP:
61                 if (mbie->mb_ctrl & MB_CTRL_STA_MAC_PRESENT &&
62                     IE_BUFFER_LENGTH(mbie->len) >= sizeof(*mbie) + ETH_ALEN)
63                         peer_addr = (const u8 *) &mbie[1];
64                 break;
65         default:
66                 break;
67         }
68
69         return peer_addr;
70 }
71
72 struct fst_ctrl_handle {
73         struct fst_ctrl ctrl;
74         struct dl_list global_ctrls_lentry;
75 };
76
77 extern struct dl_list fst_global_ctrls_list;
78
79 #define foreach_fst_ctrl_call(clb, ...) \
80         do { \
81                 struct fst_ctrl_handle *__fst_ctrl_h; \
82                 dl_list_for_each(__fst_ctrl_h, &fst_global_ctrls_list, \
83                         struct fst_ctrl_handle, global_ctrls_lentry) \
84                         if (__fst_ctrl_h->ctrl.clb) \
85                                 __fst_ctrl_h->ctrl.clb(__VA_ARGS__);\
86         } while (0)
87
88 #endif /* FST_INTERNAL_H */