• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Linux cfg80211 driver - Android related functions
3  *
4  * Copyright (C) 1999-2019, Broadcom.
5  *
6  *      Unless you and Broadcom execute a separate written software license
7  * agreement governing use of this software, this software is licensed to you
8  * under the terms of the GNU General Public License version 2 (the "GPL"),
9  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
10  * following added to such license:
11  *
12  *      As a special exception, the copyright holders of this software give you
13  * permission to link this software with independent modules, and to copy and
14  * distribute the resulting executable under terms of your choice, provided that
15  * you also meet, for each linked independent module, the terms and conditions
16  * of the license of that module.  An independent module is a module which is
17  * not derived from this software.  The special exception does not apply to any
18  * modifications of the software.
19  *
20  *      Notwithstanding the above, under no circumstances may you combine this
21  * software in any way with any other Broadcom software provided under a license
22  * other than the GPL, without Broadcom's express prior written consent.
23  *
24  *
25  * <<Broadcom-WL-IPTag/Open:>>
26  *
27  * $Id: wl_android.h 794110 2018-12-12 05:03:21Z $
28  */
29 
30 #ifndef _wl_android_
31 #define _wl_android_
32 
33 #include <linux/module.h>
34 #include <linux/netdevice.h>
35 #include <wldev_common.h>
36 #include <dngl_stats.h>
37 #include <dhd.h>
38 #ifdef WL_EXT_IAPSTA
39 #ifdef WL_ESCAN
40 #include <wl_escan.h>
41 #endif /* WL_ESCAN */
42 #include <wl_iapsta.h>
43 #endif /* WL_IAPSTA */
44 #if defined(WL_EXT_IAPSTA) || defined(USE_IW) || defined(WL_ESCAN) ||          \
45     (defined(WL_EXT_GENL) && defined(SENDPROB))
46 #ifndef WL_EVENT
47 #define WL_EVENT
48 #endif
49 #include <wl_event.h>
50 #endif
51 #include <wl_android_ext.h>
52 
53 /* If any feature uses the Generic Netlink Interface, put it here to enable
54  * WL_GENL automatically
55  */
56 #if defined(BT_WIFI_HANDOVER)
57 #define WL_GENL
58 #endif // endif
59 
60 #ifdef WL_GENL
61 #include <net/genetlink.h>
62 #endif // endif
63 
64 typedef struct _android_wifi_priv_cmd {
65     char *buf;
66     int used_len;
67     int total_len;
68 } android_wifi_priv_cmd;
69 
70 #ifdef CONFIG_COMPAT
71 typedef struct _compat_android_wifi_priv_cmd {
72     compat_caddr_t buf;
73     int used_len;
74     int total_len;
75 } compat_android_wifi_priv_cmd;
76 #endif /* CONFIG_COMPAT */
77 
78 /**
79  * Android platform dependent functions, feel free to add Android specific
80  * functions here (save the macros in dhd). Please do NOT declare functions that
81  * are NOT exposed to dhd or cfg, define them as static in wl_android.c
82  */
83 
84 /* message levels */
85 #define ANDROID_ERROR_LEVEL (1 << 0)
86 #define ANDROID_TRACE_LEVEL (1 << 1)
87 #define ANDROID_INFO_LEVEL (1 << 2)
88 #define ANDROID_SCAN_LEVEL (1 << 3)
89 #define ANDROID_DBG_LEVEL (1 << 4)
90 #define ANDROID_TPUT_LEVEL (1 << 8)
91 #define ANDROID_MSG_LEVEL (1 << 0)
92 
93 #define WL_MSG(name, arg1, args...)                                            \
94     do {                                                                       \
95         if (android_msg_level & ANDROID_MSG_LEVEL) {                           \
96             printk(KERN_ERR DHD_LOG_PREFIX "[%s] %s : " arg1, name, __func__,  \
97                    ##args);                                                    \
98         }                                                                      \
99     } while (0)
100 
101 #define WL_MSG_PRINT_RATE_LIMIT_PERIOD 1000000000u /* 1s in units of ns */
102 #define WL_MSG_RLMT(name, cmp, size, arg1, args...)                            \
103     do {                                                                       \
104         if (android_msg_level & ANDROID_MSG_LEVEL) {                           \
105             static uint64 __err_ts = 0;                                        \
106             static uint32 __err_cnt = 0;                                       \
107             uint64 __cur_ts = 0;                                               \
108             static uint8 static_tmp[size];                                     \
109             __cur_ts = osl_localtime_ns();                                     \
110             if (__err_ts == 0 ||                                               \
111                 (__cur_ts > __err_ts &&                                        \
112                  (__cur_ts - __err_ts > WL_MSG_PRINT_RATE_LIMIT_PERIOD)) ||    \
113                 memcmp(&static_tmp, cmp, size)) {                              \
114                 __err_ts = __cur_ts;                                           \
115                 memcpy(static_tmp, cmp, size);                                 \
116                 printk(KERN_ERR DHD_LOG_PREFIX "[%s] %s : [%u times] " arg1,   \
117                        name, __func__, __err_cnt, ##args);                     \
118                 __err_cnt = 0;                                                 \
119             } else {                                                           \
120                 ++__err_cnt;                                                   \
121             }                                                                  \
122         }                                                                      \
123     } while (0)
124 #define WL_GET_BAND(ch)                                                        \
125     (((uint)(ch) <= CH_MAX_2G_CHANNEL) ? WLC_BAND_2G : WLC_BAND_5G)
126 
127 /**
128  * wl_android_init will be called from module init function (dhd_module_init
129  * now), similarly wl_android_exit will be called from module exit function
130  * (dhd_module_cleanup now)
131  */
132 int wl_android_init(void);
133 int wl_android_exit(void);
134 void wl_android_post_init(void);
135 int wl_android_wifi_on(struct net_device *dev);
136 int wl_android_wifi_off(struct net_device *dev, bool on_failure);
137 int wl_android_priv_cmd(struct net_device *net, struct ifreq *ifr);
138 int wl_handle_private_cmd(struct net_device *net, char *command, u32 cmd_len);
139 
140 #ifdef WL_GENL
141 typedef struct bcm_event_hdr {
142     u16 event_type;
143     u16 len;
144 } bcm_event_hdr_t;
145 
146 /* attributes (variables): the index in this enum is used as a reference for the
147  * type, userspace application has to indicate the corresponding type the policy
148  * is used for security considerations
149  */
150 enum {
151     BCM_GENL_ATTR_UNSPEC,
152     BCM_GENL_ATTR_STRING,
153     BCM_GENL_ATTR_MSG,
154     __BCM_GENL_ATTR_MAX
155 };
156 #define BCM_GENL_ATTR_MAX (__BCM_GENL_ATTR_MAX - 1)
157 
158 /* commands: enumeration of all commands (functions),
159  * used by userspace application to identify command to be ececuted
160  */
161 enum { BCM_GENL_CMD_UNSPEC, BCM_GENL_CMD_MSG, __BCM_GENL_CMD_MAX };
162 #define BCM_GENL_CMD_MAX (__BCM_GENL_CMD_MAX - 1)
163 
164 /* Enum values used by the BCM supplicant to identify the events */
165 enum {
166     BCM_E_UNSPEC,
167     BCM_E_SVC_FOUND,
168     BCM_E_DEV_FOUND,
169     BCM_E_DEV_LOST,
170 #ifdef BT_WIFI_HANDOVER
171     BCM_E_DEV_BT_WIFI_HO_REQ,
172 #endif // endif
173     BCM_E_MAX
174 };
175 
176 s32 wl_genl_send_msg(struct net_device *ndev, u32 event_type, const u8 *string,
177                      u16 len, u8 *hdr, u16 hdrlen);
178 #endif /* WL_GENL */
179 s32 wl_netlink_send_msg(int pid, int type, int seq, const void *data,
180                         size_t size);
181 
182 /* hostap mac mode */
183 #define MACLIST_MODE_DISABLED 0
184 #define MACLIST_MODE_DENY 1
185 #define MACLIST_MODE_ALLOW 2
186 
187 /* max number of assoc list */
188 #define MAX_NUM_OF_ASSOCLIST 64
189 
190 /* Bandwidth */
191 #define WL_CH_BANDWIDTH_20MHZ 20
192 #define WL_CH_BANDWIDTH_40MHZ 40
193 #define WL_CH_BANDWIDTH_80MHZ 80
194 /* max number of mac filter list
195  * restrict max number to 10 as maximum cmd string size is 255
196  */
197 #define MAX_NUM_MAC_FILT 10
198 
199 int wl_android_set_ap_mac_list(struct net_device *dev, int macmode,
200                                struct maclist *maclist);
201 #ifdef WL_BCNRECV
202 extern int wl_android_bcnrecv_config(struct net_device *ndev, char *data,
203                                      int total_len);
204 extern int wl_android_bcnrecv_stop(struct net_device *ndev, uint reason);
205 extern int wl_android_bcnrecv_resume(struct net_device *ndev);
206 extern int wl_android_bcnrecv_suspend(struct net_device *ndev);
207 extern int wl_android_bcnrecv_event(struct net_device *ndev, uint attr_type,
208                                     uint status, uint reason, uint8 *data,
209                                     uint data_len);
210 #endif /* WL_BCNRECV */
211 #ifdef WL_CAC_TS
212 #define TSPEC_UPLINK_DIRECTION (0 << 5) /* uplink direction traffic stream */
213 #define TSPEC_DOWNLINK_DIRECTION                                               \
214     (1 << 5)                        /* downlink direction traffic stream */
215 #define TSPEC_BI_DIRECTION (3 << 5) /* bi direction traffic stream */
216 #define TSPEC_EDCA_ACCESS (1 << 7)  /* EDCA access policy */
217 #define TSPEC_UAPSD_PSB (1 << 2)    /* U-APSD power saving behavior */
218 #define TSPEC_TSINFO_TID_SHIFT 1    /* TID Shift */
219 #define TSPEC_TSINFO_PRIO_SHIFT 3   /* PRIO Shift */
220 #define TSPEC_MAX_ACCESS_CATEGORY 3
221 #define TSPEC_MAX_USER_PRIO 7
222 #define TSPEC_MAX_DIALOG_TOKEN 255
223 #define TSPEC_MAX_SURPLUS_BW 12410
224 #define TSPEC_MIN_SURPLUS_BW 11210
225 #define TSPEC_MAX_MSDU_SIZE 1520
226 #define TSPEC_DEF_MEAN_DATA_RATE 120000
227 #define TSPEC_DEF_MIN_PHY_RATE 6000000
228 #define TSPEC_DEF_DIALOG_TOKEN 7
229 #endif /* WL_CAC_TS */
230 #endif /* _wl_android_ */
231