1 /* 2 * Linux Cfg80211 support 3 * 4 * Copyright (C) 1999-2010, Broadcom Corporation 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 of 16 * the license of that module. An independent module is a module which is not 17 * 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 * $Id: wl_cfg80211.h,v 1.1.2.19 2010/05/04 21:21:00 Exp $ 25 */ 26 27 #ifndef _wl_cfg80211_h_ 28 #define _wl_cfg80211_h_ 29 30 #include <linux/wireless.h> 31 #include <typedefs.h> 32 #include <proto/ethernet.h> 33 #include <wlioctl.h> 34 #include <linux/wireless.h> 35 #include <net/cfg80211.h> 36 37 struct wl_conf; 38 struct wl_iface; 39 struct wl_priv; 40 struct wl_security; 41 struct wl_ibss; 42 43 #if defined(IL_BIGENDIAN) 44 #include <bcmendian.h> 45 #define htod32(i) (bcmswap32(i)) 46 #define htod16(i) (bcmswap16(i)) 47 #define dtoh32(i) (bcmswap32(i)) 48 #define dtoh16(i) (bcmswap16(i)) 49 #define htodchanspec(i) htod16(i) 50 #define dtohchanspec(i) dtoh16(i) 51 #else 52 #define htod32(i) i 53 #define htod16(i) i 54 #define dtoh32(i) i 55 #define dtoh16(i) i 56 #define htodchanspec(i) i 57 #define dtohchanspec(i) i 58 #endif 59 60 #define WL_DBG_NONE 0 61 #define WL_DBG_DBG (1 << 2) 62 #define WL_DBG_INFO (1 << 1) 63 #define WL_DBG_ERR (1 << 0) 64 #define WL_DBG_MASK ((WL_DBG_DBG | WL_DBG_INFO | WL_DBG_ERR) << 1) 65 66 #define WL_DBG_LEVEL 1 /* 0 invalidates all debug messages. default is 1 */ 67 #define WL_ERR(args) \ 68 do { \ 69 if (wl_dbg_level & WL_DBG_ERR) { \ 70 if (net_ratelimit()) { \ 71 printk("ERROR @%s : ", __FUNCTION__); \ 72 printk args; \ 73 } \ 74 } \ 75 } while (0) 76 #define WL_INFO(args) \ 77 do { \ 78 if (wl_dbg_level & WL_DBG_INFO) { \ 79 if (net_ratelimit()) { \ 80 printk("INFO @%s : ", __FUNCTION__); \ 81 printk args; \ 82 } \ 83 } \ 84 } while (0) 85 #if (WL_DBG_LEVEL > 0) 86 #define WL_DBG(args) \ 87 do { \ 88 if (wl_dbg_level & WL_DBG_DBG) { \ 89 printk("DEBUG @%s :", __FUNCTION__); \ 90 printk args; \ 91 } \ 92 } while (0) 93 #else /* !(WL_DBG_LEVEL > 0) */ 94 #define WL_DBG(args) 95 #endif /* (WL_DBG_LEVEL > 0) */ 96 97 #define WL_SCAN_RETRY_MAX 3 /* used for ibss scan */ 98 #define WL_NUM_SCAN_MAX 1 99 #define WL_NUM_PMKIDS_MAX MAXPMKID /* will be used for 2.6.33 kernel 100 * or later 101 */ 102 #define WL_SCAN_BUF_MAX (1024 * 8) 103 #define WL_TLV_INFO_MAX 1024 104 #define WL_BSS_INFO_MAX 2048 105 #define WL_ASSOC_INFO_MAX 512 /* 106 * needs to grab assoc info from dongle to 107 * report it to cfg80211 through "connect" 108 * event 109 */ 110 #define WL_IOCTL_LEN_MAX 1024 111 #define WL_EXTRA_BUF_MAX 2048 112 #define WL_ISCAN_BUF_MAX 2048 /* the buf lengh can be WLC_IOCTL_MAXLEN (8K) 113 * to reduce iteration 114 */ 115 #define WL_ISCAN_TIMER_INTERVAL_MS 3000 116 #define WL_SCAN_ERSULTS_LAST (WL_SCAN_RESULTS_NO_MEM+1) 117 #define WL_AP_MAX 256 /* virtually unlimitted as long 118 * as kernel memory allows 119 */ 120 #define WL_FILE_NAME_MAX 256 121 122 /* dongle status */ 123 enum wl_status { 124 WL_STATUS_READY, 125 WL_STATUS_SCANNING, 126 WL_STATUS_SCAN_ABORTING, 127 WL_STATUS_CONNECTING, 128 WL_STATUS_CONNECTED 129 }; 130 131 /* wi-fi mode */ 132 enum wl_mode { 133 WL_MODE_BSS, 134 WL_MODE_IBSS, 135 WL_MODE_AP 136 }; 137 138 /* dongle profile list */ 139 enum wl_prof_list { 140 WL_PROF_MODE, 141 WL_PROF_SSID, 142 WL_PROF_SEC, 143 WL_PROF_IBSS, 144 WL_PROF_BAND, 145 WL_PROF_BSSID, 146 WL_PROF_ACT 147 }; 148 149 /* dongle iscan state */ 150 enum wl_iscan_state { 151 WL_ISCAN_STATE_IDLE, 152 WL_ISCAN_STATE_SCANING 153 }; 154 155 /* fw downloading status */ 156 enum wl_fw_status { 157 WL_FW_LOADING_DONE, 158 WL_NVRAM_LOADING_DONE 159 }; 160 161 /* dongle configuration */ 162 struct wl_conf { 163 uint32 mode; /* adhoc , infrastructure or ap */ 164 uint32 frag_threshold; 165 uint32 rts_threshold; 166 uint32 retry_short; 167 uint32 retry_long; 168 int32 tx_power; 169 struct ieee80211_channel channel; 170 }; 171 172 /* cfg80211 main event loop */ 173 struct wl_event_loop { 174 int32 (*handler[WLC_E_LAST])(struct wl_priv *wl, struct net_device *ndev, 175 const wl_event_msg_t *e, void *data); 176 }; 177 178 /* representing interface of cfg80211 plane */ 179 struct wl_iface { 180 struct wl_priv *wl; 181 }; 182 183 struct wl_dev { 184 void *driver_data; /* to store cfg80211 object information */ 185 }; 186 187 /* bss inform structure for cfg80211 interface */ 188 struct wl_cfg80211_bss_info { 189 uint16 band; 190 uint16 channel; 191 int16 rssi; 192 uint16 frame_len; 193 uint8 frame_buf[1]; 194 }; 195 196 /* basic structure of scan request */ 197 struct wl_scan_req { 198 struct wlc_ssid ssid; 199 }; 200 201 /* basic structure of information element */ 202 struct wl_ie { 203 uint16 offset; 204 uint8 buf[WL_TLV_INFO_MAX]; 205 }; 206 207 /* event queue for cfg80211 main event */ 208 struct wl_event_q { 209 struct list_head eq_list; 210 uint32 etype; 211 wl_event_msg_t emsg; 212 int8 edata[1]; 213 }; 214 215 /* security information with currently associated ap */ 216 struct wl_security { 217 uint32 wpa_versions; 218 uint32 auth_type; 219 uint32 cipher_pairwise; 220 uint32 cipher_group; 221 uint32 wpa_auth; 222 }; 223 224 /* ibss information for currently joined ibss network */ 225 struct wl_ibss { 226 uint8 beacon_interval; /* in millisecond */ 227 uint8 atim; /* in millisecond */ 228 int8 join_only; 229 uint8 band; 230 uint8 channel; 231 }; 232 233 /* dongle profile */ 234 struct wl_profile { 235 uint32 mode; 236 struct wlc_ssid ssid; 237 uint8 bssid[ETHER_ADDR_LEN]; 238 struct wl_security sec; 239 struct wl_ibss ibss; 240 int32 band; 241 bool active; 242 }; 243 244 /* dongle iscan event loop */ 245 struct wl_iscan_eloop { 246 int32 (*handler[WL_SCAN_ERSULTS_LAST])(struct wl_priv *wl); 247 }; 248 249 /* dongle iscan controller */ 250 struct wl_iscan_ctrl { 251 struct net_device *dev; 252 struct timer_list timer; 253 uint32 timer_ms; 254 uint32 timer_on; 255 int32 state; 256 int32 pid; 257 struct semaphore sync; 258 struct completion exited; 259 struct wl_iscan_eloop el; 260 void *data; 261 int8 ioctl_buf[WLC_IOCTL_SMLEN]; 262 int8 scan_buf[WL_ISCAN_BUF_MAX]; 263 }; 264 265 /* association inform */ 266 struct wl_connect_info { 267 uint8 *req_ie; 268 int32 req_ie_len; 269 uint8 *resp_ie; 270 int32 resp_ie_len; 271 }; 272 273 /* firmware /nvram downloading controller */ 274 struct wl_fw_ctrl { 275 const struct firmware *fw_entry; 276 ulong status; 277 uint32 ptr; 278 int8 fw_name[WL_FILE_NAME_MAX]; 279 int8 nvram_name[WL_FILE_NAME_MAX]; 280 }; 281 282 /* assoc ie length */ 283 struct wl_assoc_ielen { 284 uint32 req_len; 285 uint32 resp_len; 286 }; 287 288 /* wpa2 pmk list */ 289 struct wl_pmk_list { 290 pmkid_list_t pmkids; 291 pmkid_t foo[MAXPMKID-1]; 292 }; 293 294 295 /* dongle private data of cfg80211 interface */ 296 struct wl_priv { 297 struct wireless_dev *wdev; /* representing wl cfg80211 device */ 298 struct wl_conf *conf; /* dongle configuration */ 299 struct cfg80211_scan_request *scan_request; /* scan request object */ 300 struct wl_event_loop el; /* main event loop */ 301 struct list_head eq_list; /* used for event queue */ 302 spinlock_t eq_lock; /* for event queue synchronization */ 303 struct mutex usr_sync; /* maily for dongle up/down synchronization */ 304 struct wl_scan_results *bss_list; /* bss_list holding scanned ap information */ 305 struct wl_scan_results *scan_results; 306 struct wl_scan_req *scan_req_int; /* scan request object for internal purpose */ 307 struct wl_cfg80211_bss_info *bss_info; /* bss information for cfg80211 layer */ 308 struct wl_ie ie; /* information element object for internal purpose */ 309 struct ether_addr bssid; /* bssid of currently engaged network */ 310 struct semaphore event_sync; /* for synchronization of main event thread */ 311 struct completion event_exit; 312 struct wl_profile *profile; /* holding dongle profile */ 313 struct wl_iscan_ctrl *iscan; /* iscan controller */ 314 struct wl_connect_info conn_info; /* association information container */ 315 struct wl_fw_ctrl *fw; /* control firwmare / nvram paramter downloading */ 316 struct wl_pmk_list *pmk_list; /* wpa2 pmk list */ 317 int32 event_pid; /* pid of main event handler thread */ 318 ulong status; /* current dongle status */ 319 void * pub; 320 uint32 channel; /* current channel */ 321 bool iscan_on; /* iscan on/off switch */ 322 bool iscan_kickstart; /* indicate iscan already started */ 323 bool active_scan; /* current scan mode */ 324 bool ibss_starter; /* indicates this sta is ibss starter */ 325 bool link_up; /* link/connection up flag */ 326 bool pwr_save; /* indicate whether dongle to support power save mode */ 327 bool dongle_up; /* indicate whether dongle up or not */ 328 bool roam_on; /* on/off switch for dongle self-roaming */ 329 bool scan_tried; /* indicates if first scan attempted */ 330 uint8 *ioctl_buf; /* ioctl buffer */ 331 uint8 *extra_buf; /* maily to grab assoc information */ 332 uint8 ci[0] __attribute__((__aligned__(NETDEV_ALIGN))); 333 }; 334 335 #define wl_to_dev(w) (wiphy_dev(wl->wdev->wiphy)) 336 #define wl_to_wiphy(w) (w->wdev->wiphy) 337 #define wiphy_to_wl(w) ((struct wl_priv *)(wiphy_priv(w))) 338 #define wl_to_wdev(w) (w->wdev) 339 #define wdev_to_wl(w) ((struct wl_priv *)(wdev_priv(w))) 340 #define wl_to_ndev(w) (w->wdev->netdev) 341 #define ndev_to_wl(n) (wdev_to_wl(n->ieee80211_ptr)) 342 #define ci_to_wl(c) (ci->wl) 343 #define wl_to_ci(w) (&w->ci) 344 #define wl_to_sr(w) (w->scan_req_int) 345 #define wl_to_ie(w) (&w->ie) 346 #define iscan_to_wl(i) ((struct wl_priv *)(i->data)) 347 #define wl_to_iscan(w) (w->iscan) 348 #define wl_to_conn(w) (&w->conn_info) 349 350 inline static struct wl_bss_info * next_bss(struct wl_scan_results *list, 351 struct wl_bss_info *bss) { 352 return (bss = bss ? 353 (struct wl_bss_info *)((uintptr)bss + dtoh32(bss->length)) : list->bss_info); 354 } 355 #define for_each_bss(list, bss, __i) \ 356 for (__i = 0; __i < list->count && __i < WL_AP_MAX; __i++, bss = next_bss(list, bss)) 357 358 extern int32 wl_cfg80211_attach(struct net_device *ndev, void *data); 359 extern void wl_cfg80211_detach(void); 360 /* event handler from dongle */ 361 extern void wl_cfg80211_event(struct net_device *ndev, const wl_event_msg_t *e, void* data); 362 extern void wl_cfg80211_sdio_func(void *func); /* set sdio function info */ 363 extern int32 wl_cfg80211_up(void); /* dongle up */ 364 extern int32 wl_cfg80211_down(void); /* dongle down */ 365 extern void wl_cfg80211_dbg_level(uint32 level); /* set dongle debugging level */ 366 extern void * wl_cfg80211_request_fw(int8 *file_name); /* request fw /nvram downloading */ 367 extern int32 wl_cfg80211_read_fw(int8 *buf, uint32 size); /* read fw image */ 368 extern void wl_cfg80211_release_fw(void); /* release fw */ 369 extern int8 * wl_cfg80211_get_fwname(void); /* get firmware name for the dongle */ 370 extern int8 * wl_cfg80211_get_nvramname(void); /* get nvram name for the dongle */ 371 372 #endif /* _wl_cfg80211_h_ */ 373