Arend van Spriel | 5b435de | 2011-10-05 13:19:03 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2010 Broadcom Corporation |
| 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 11 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 13 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 14 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/string.h> |
| 18 | #include <linux/sched.h> |
| 19 | #include <linux/netdevice.h> |
| 20 | #include <asm/unaligned.h> |
| 21 | #include <defs.h> |
| 22 | #include <brcmu_wifi.h> |
| 23 | #include <brcmu_utils.h> |
| 24 | #include "dhd.h" |
| 25 | #include "dhd_bus.h" |
| 26 | #include "dhd_proto.h" |
| 27 | #include "dhd_dbg.h" |
| 28 | |
| 29 | #define BRCM_OUI "\x00\x10\x18" |
| 30 | #define DOT11_OUI_LEN 3 |
| 31 | #define BCMILCP_BCM_SUBTYPE_EVENT 1 |
| 32 | #define PKTFILTER_BUF_SIZE 2048 |
| 33 | #define BRCMF_ARPOL_MODE 0xb /* agent|snoop|peer_autoreply */ |
| 34 | |
| 35 | int brcmf_msg_level; |
| 36 | |
| 37 | #define MSGTRACE_VERSION 1 |
| 38 | |
| 39 | #define BRCMF_PKT_FILTER_FIXED_LEN offsetof(struct brcmf_pkt_filter, u) |
| 40 | #define BRCMF_PKT_FILTER_PATTERN_FIXED_LEN \ |
| 41 | offsetof(struct brcmf_pkt_filter_pattern, mask_and_pattern) |
| 42 | |
| 43 | #ifdef BCMDBG |
| 44 | static const char brcmf_version[] = |
| 45 | "Dongle Host Driver, version " BRCMF_VERSION_STR "\nCompiled on " |
| 46 | __DATE__ " at " __TIME__; |
| 47 | #else |
| 48 | static const char brcmf_version[] = |
| 49 | "Dongle Host Driver, version " BRCMF_VERSION_STR; |
| 50 | #endif |
| 51 | |
| 52 | /* Message trace header */ |
| 53 | struct msgtrace_hdr { |
| 54 | u8 version; |
| 55 | u8 spare; |
| 56 | __be16 len; /* Len of the trace */ |
| 57 | __be32 seqnum; /* Sequence number of message. Useful |
| 58 | * if the messsage has been lost |
| 59 | * because of DMA error or a bus reset |
| 60 | * (ex: SDIO Func2) |
| 61 | */ |
| 62 | __be32 discarded_bytes; /* Number of discarded bytes because of |
| 63 | trace overflow */ |
| 64 | __be32 discarded_printf; /* Number of discarded printf |
| 65 | because of trace overflow */ |
| 66 | } __packed; |
| 67 | |
| 68 | void brcmf_c_init(void) |
| 69 | { |
| 70 | /* Init global variables at run-time, not as part of the declaration. |
| 71 | * This is required to support init/de-init of the driver. |
| 72 | * Initialization |
| 73 | * of globals as part of the declaration results in non-deterministic |
| 74 | * behaviour since the value of the globals may be different on the |
| 75 | * first time that the driver is initialized vs subsequent |
| 76 | * initializations. |
| 77 | */ |
| 78 | brcmf_msg_level = BRCMF_ERROR_VAL; |
| 79 | } |
| 80 | |
| 81 | bool brcmf_c_prec_enq(struct brcmf_pub *drvr, struct pktq *q, |
| 82 | struct sk_buff *pkt, int prec) |
| 83 | { |
| 84 | struct sk_buff *p; |
| 85 | int eprec = -1; /* precedence to evict from */ |
| 86 | bool discard_oldest; |
| 87 | |
| 88 | /* Fast case, precedence queue is not full and we are also not |
| 89 | * exceeding total queue length |
| 90 | */ |
| 91 | if (!pktq_pfull(q, prec) && !pktq_full(q)) { |
| 92 | brcmu_pktq_penq(q, prec, pkt); |
| 93 | return true; |
| 94 | } |
| 95 | |
| 96 | /* Determine precedence from which to evict packet, if any */ |
| 97 | if (pktq_pfull(q, prec)) |
| 98 | eprec = prec; |
| 99 | else if (pktq_full(q)) { |
| 100 | p = brcmu_pktq_peek_tail(q, &eprec); |
| 101 | if (eprec > prec) |
| 102 | return false; |
| 103 | } |
| 104 | |
| 105 | /* Evict if needed */ |
| 106 | if (eprec >= 0) { |
| 107 | /* Detect queueing to unconfigured precedence */ |
| 108 | discard_oldest = ac_bitmap_tst(drvr->wme_dp, eprec); |
| 109 | if (eprec == prec && !discard_oldest) |
| 110 | return false; /* refuse newer (incoming) packet */ |
| 111 | /* Evict packet according to discard policy */ |
| 112 | p = discard_oldest ? brcmu_pktq_pdeq(q, eprec) : |
| 113 | brcmu_pktq_pdeq_tail(q, eprec); |
| 114 | if (p == NULL) |
| 115 | brcmf_dbg(ERROR, "brcmu_pktq_penq() failed, oldest %d\n", |
| 116 | discard_oldest); |
| 117 | |
| 118 | brcmu_pkt_buf_free_skb(p); |
| 119 | } |
| 120 | |
| 121 | /* Enqueue */ |
| 122 | p = brcmu_pktq_penq(q, prec, pkt); |
| 123 | if (p == NULL) |
| 124 | brcmf_dbg(ERROR, "brcmu_pktq_penq() failed\n"); |
| 125 | |
| 126 | return p != NULL; |
| 127 | } |
| 128 | |
| 129 | #ifdef BCMDBG |
| 130 | static void |
| 131 | brcmf_c_show_host_event(struct brcmf_event_msg *event, void *event_data) |
| 132 | { |
| 133 | uint i, status, reason; |
| 134 | bool group = false, flush_txq = false, link = false; |
| 135 | char *auth_str, *event_name; |
| 136 | unsigned char *buf; |
| 137 | char err_msg[256], eabuf[ETHER_ADDR_STR_LEN]; |
| 138 | static struct { |
| 139 | uint event; |
| 140 | char *event_name; |
| 141 | } event_names[] = { |
| 142 | { |
| 143 | BRCMF_E_SET_SSID, "SET_SSID"}, { |
| 144 | BRCMF_E_JOIN, "JOIN"}, { |
| 145 | BRCMF_E_START, "START"}, { |
| 146 | BRCMF_E_AUTH, "AUTH"}, { |
| 147 | BRCMF_E_AUTH_IND, "AUTH_IND"}, { |
| 148 | BRCMF_E_DEAUTH, "DEAUTH"}, { |
| 149 | BRCMF_E_DEAUTH_IND, "DEAUTH_IND"}, { |
| 150 | BRCMF_E_ASSOC, "ASSOC"}, { |
| 151 | BRCMF_E_ASSOC_IND, "ASSOC_IND"}, { |
| 152 | BRCMF_E_REASSOC, "REASSOC"}, { |
| 153 | BRCMF_E_REASSOC_IND, "REASSOC_IND"}, { |
| 154 | BRCMF_E_DISASSOC, "DISASSOC"}, { |
| 155 | BRCMF_E_DISASSOC_IND, "DISASSOC_IND"}, { |
| 156 | BRCMF_E_QUIET_START, "START_QUIET"}, { |
| 157 | BRCMF_E_QUIET_END, "END_QUIET"}, { |
| 158 | BRCMF_E_BEACON_RX, "BEACON_RX"}, { |
| 159 | BRCMF_E_LINK, "LINK"}, { |
| 160 | BRCMF_E_MIC_ERROR, "MIC_ERROR"}, { |
| 161 | BRCMF_E_NDIS_LINK, "NDIS_LINK"}, { |
| 162 | BRCMF_E_ROAM, "ROAM"}, { |
| 163 | BRCMF_E_TXFAIL, "TXFAIL"}, { |
| 164 | BRCMF_E_PMKID_CACHE, "PMKID_CACHE"}, { |
| 165 | BRCMF_E_RETROGRADE_TSF, "RETROGRADE_TSF"}, { |
| 166 | BRCMF_E_PRUNE, "PRUNE"}, { |
| 167 | BRCMF_E_AUTOAUTH, "AUTOAUTH"}, { |
| 168 | BRCMF_E_EAPOL_MSG, "EAPOL_MSG"}, { |
| 169 | BRCMF_E_SCAN_COMPLETE, "SCAN_COMPLETE"}, { |
| 170 | BRCMF_E_ADDTS_IND, "ADDTS_IND"}, { |
| 171 | BRCMF_E_DELTS_IND, "DELTS_IND"}, { |
| 172 | BRCMF_E_BCNSENT_IND, "BCNSENT_IND"}, { |
| 173 | BRCMF_E_BCNRX_MSG, "BCNRX_MSG"}, { |
| 174 | BRCMF_E_BCNLOST_MSG, "BCNLOST_MSG"}, { |
| 175 | BRCMF_E_ROAM_PREP, "ROAM_PREP"}, { |
| 176 | BRCMF_E_PFN_NET_FOUND, "PNO_NET_FOUND"}, { |
| 177 | BRCMF_E_PFN_NET_LOST, "PNO_NET_LOST"}, { |
| 178 | BRCMF_E_RESET_COMPLETE, "RESET_COMPLETE"}, { |
| 179 | BRCMF_E_JOIN_START, "JOIN_START"}, { |
| 180 | BRCMF_E_ROAM_START, "ROAM_START"}, { |
| 181 | BRCMF_E_ASSOC_START, "ASSOC_START"}, { |
| 182 | BRCMF_E_IBSS_ASSOC, "IBSS_ASSOC"}, { |
| 183 | BRCMF_E_RADIO, "RADIO"}, { |
| 184 | BRCMF_E_PSM_WATCHDOG, "PSM_WATCHDOG"}, { |
| 185 | BRCMF_E_PROBREQ_MSG, "PROBREQ_MSG"}, { |
| 186 | BRCMF_E_SCAN_CONFIRM_IND, "SCAN_CONFIRM_IND"}, { |
| 187 | BRCMF_E_PSK_SUP, "PSK_SUP"}, { |
| 188 | BRCMF_E_COUNTRY_CODE_CHANGED, "COUNTRY_CODE_CHANGED"}, { |
| 189 | BRCMF_E_EXCEEDED_MEDIUM_TIME, "EXCEEDED_MEDIUM_TIME"}, { |
| 190 | BRCMF_E_ICV_ERROR, "ICV_ERROR"}, { |
| 191 | BRCMF_E_UNICAST_DECODE_ERROR, "UNICAST_DECODE_ERROR"}, { |
| 192 | BRCMF_E_MULTICAST_DECODE_ERROR, "MULTICAST_DECODE_ERROR"}, { |
| 193 | BRCMF_E_TRACE, "TRACE"}, { |
| 194 | BRCMF_E_ACTION_FRAME, "ACTION FRAME"}, { |
| 195 | BRCMF_E_ACTION_FRAME_COMPLETE, "ACTION FRAME TX COMPLETE"}, { |
| 196 | BRCMF_E_IF, "IF"}, { |
| 197 | BRCMF_E_RSSI, "RSSI"}, { |
| 198 | BRCMF_E_PFN_SCAN_COMPLETE, "SCAN_COMPLETE"} |
| 199 | }; |
| 200 | uint event_type, flags, auth_type, datalen; |
| 201 | static u32 seqnum_prev; |
| 202 | struct msgtrace_hdr hdr; |
| 203 | u32 nblost; |
| 204 | char *s, *p; |
| 205 | |
| 206 | event_type = be32_to_cpu(event->event_type); |
| 207 | flags = be16_to_cpu(event->flags); |
| 208 | status = be32_to_cpu(event->status); |
| 209 | reason = be32_to_cpu(event->reason); |
| 210 | auth_type = be32_to_cpu(event->auth_type); |
| 211 | datalen = be32_to_cpu(event->datalen); |
| 212 | /* debug dump of event messages */ |
| 213 | sprintf(eabuf, "%pM", event->addr); |
| 214 | |
| 215 | event_name = "UNKNOWN"; |
| 216 | for (i = 0; i < ARRAY_SIZE(event_names); i++) { |
| 217 | if (event_names[i].event == event_type) |
| 218 | event_name = event_names[i].event_name; |
| 219 | } |
| 220 | |
| 221 | brcmf_dbg(EVENT, "EVENT: %s, event ID = %d\n", event_name, event_type); |
| 222 | brcmf_dbg(EVENT, "flags 0x%04x, status %d, reason %d, auth_type %d MAC %s\n", |
| 223 | flags, status, reason, auth_type, eabuf); |
| 224 | |
| 225 | if (flags & BRCMF_EVENT_MSG_LINK) |
| 226 | link = true; |
| 227 | if (flags & BRCMF_EVENT_MSG_GROUP) |
| 228 | group = true; |
| 229 | if (flags & BRCMF_EVENT_MSG_FLUSHTXQ) |
| 230 | flush_txq = true; |
| 231 | |
| 232 | switch (event_type) { |
| 233 | case BRCMF_E_START: |
| 234 | case BRCMF_E_DEAUTH: |
| 235 | case BRCMF_E_DISASSOC: |
| 236 | brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s\n", event_name, eabuf); |
| 237 | break; |
| 238 | |
| 239 | case BRCMF_E_ASSOC_IND: |
| 240 | case BRCMF_E_REASSOC_IND: |
| 241 | brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s\n", event_name, eabuf); |
| 242 | break; |
| 243 | |
| 244 | case BRCMF_E_ASSOC: |
| 245 | case BRCMF_E_REASSOC: |
| 246 | if (status == BRCMF_E_STATUS_SUCCESS) |
| 247 | brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, SUCCESS\n", |
| 248 | event_name, eabuf); |
| 249 | else if (status == BRCMF_E_STATUS_TIMEOUT) |
| 250 | brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, TIMEOUT\n", |
| 251 | event_name, eabuf); |
| 252 | else if (status == BRCMF_E_STATUS_FAIL) |
| 253 | brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, FAILURE, reason %d\n", |
| 254 | event_name, eabuf, (int)reason); |
| 255 | else |
| 256 | brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, unexpected status %d\n", |
| 257 | event_name, eabuf, (int)status); |
| 258 | break; |
| 259 | |
| 260 | case BRCMF_E_DEAUTH_IND: |
| 261 | case BRCMF_E_DISASSOC_IND: |
| 262 | brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, reason %d\n", |
| 263 | event_name, eabuf, (int)reason); |
| 264 | break; |
| 265 | |
| 266 | case BRCMF_E_AUTH: |
| 267 | case BRCMF_E_AUTH_IND: |
| 268 | if (auth_type == WLAN_AUTH_OPEN) |
| 269 | auth_str = "Open System"; |
| 270 | else if (auth_type == WLAN_AUTH_SHARED_KEY) |
| 271 | auth_str = "Shared Key"; |
| 272 | else { |
| 273 | sprintf(err_msg, "AUTH unknown: %d", (int)auth_type); |
| 274 | auth_str = err_msg; |
| 275 | } |
| 276 | if (event_type == BRCMF_E_AUTH_IND) |
| 277 | brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, %s\n", |
| 278 | event_name, eabuf, auth_str); |
| 279 | else if (status == BRCMF_E_STATUS_SUCCESS) |
| 280 | brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, %s, SUCCESS\n", |
| 281 | event_name, eabuf, auth_str); |
| 282 | else if (status == BRCMF_E_STATUS_TIMEOUT) |
| 283 | brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, %s, TIMEOUT\n", |
| 284 | event_name, eabuf, auth_str); |
| 285 | else if (status == BRCMF_E_STATUS_FAIL) { |
| 286 | brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, %s, FAILURE, reason %d\n", |
| 287 | event_name, eabuf, auth_str, (int)reason); |
| 288 | } |
| 289 | |
| 290 | break; |
| 291 | |
| 292 | case BRCMF_E_JOIN: |
| 293 | case BRCMF_E_ROAM: |
| 294 | case BRCMF_E_SET_SSID: |
| 295 | if (status == BRCMF_E_STATUS_SUCCESS) |
| 296 | brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s\n", |
| 297 | event_name, eabuf); |
| 298 | else if (status == BRCMF_E_STATUS_FAIL) |
| 299 | brcmf_dbg(EVENT, "MACEVENT: %s, failed\n", event_name); |
| 300 | else if (status == BRCMF_E_STATUS_NO_NETWORKS) |
| 301 | brcmf_dbg(EVENT, "MACEVENT: %s, no networks found\n", |
| 302 | event_name); |
| 303 | else |
| 304 | brcmf_dbg(EVENT, "MACEVENT: %s, unexpected status %d\n", |
| 305 | event_name, (int)status); |
| 306 | break; |
| 307 | |
| 308 | case BRCMF_E_BEACON_RX: |
| 309 | if (status == BRCMF_E_STATUS_SUCCESS) |
| 310 | brcmf_dbg(EVENT, "MACEVENT: %s, SUCCESS\n", event_name); |
| 311 | else if (status == BRCMF_E_STATUS_FAIL) |
| 312 | brcmf_dbg(EVENT, "MACEVENT: %s, FAIL\n", event_name); |
| 313 | else |
| 314 | brcmf_dbg(EVENT, "MACEVENT: %s, status %d\n", |
| 315 | event_name, status); |
| 316 | break; |
| 317 | |
| 318 | case BRCMF_E_LINK: |
| 319 | brcmf_dbg(EVENT, "MACEVENT: %s %s\n", |
| 320 | event_name, link ? "UP" : "DOWN"); |
| 321 | break; |
| 322 | |
| 323 | case BRCMF_E_MIC_ERROR: |
| 324 | brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, Group %d, Flush %d\n", |
| 325 | event_name, eabuf, group, flush_txq); |
| 326 | break; |
| 327 | |
| 328 | case BRCMF_E_ICV_ERROR: |
| 329 | case BRCMF_E_UNICAST_DECODE_ERROR: |
| 330 | case BRCMF_E_MULTICAST_DECODE_ERROR: |
| 331 | brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s\n", event_name, eabuf); |
| 332 | break; |
| 333 | |
| 334 | case BRCMF_E_TXFAIL: |
| 335 | brcmf_dbg(EVENT, "MACEVENT: %s, RA %s\n", event_name, eabuf); |
| 336 | break; |
| 337 | |
| 338 | case BRCMF_E_SCAN_COMPLETE: |
| 339 | case BRCMF_E_PMKID_CACHE: |
| 340 | brcmf_dbg(EVENT, "MACEVENT: %s\n", event_name); |
| 341 | break; |
| 342 | |
| 343 | case BRCMF_E_PFN_NET_FOUND: |
| 344 | case BRCMF_E_PFN_NET_LOST: |
| 345 | case BRCMF_E_PFN_SCAN_COMPLETE: |
| 346 | brcmf_dbg(EVENT, "PNOEVENT: %s\n", event_name); |
| 347 | break; |
| 348 | |
| 349 | case BRCMF_E_PSK_SUP: |
| 350 | case BRCMF_E_PRUNE: |
| 351 | brcmf_dbg(EVENT, "MACEVENT: %s, status %d, reason %d\n", |
| 352 | event_name, (int)status, (int)reason); |
| 353 | break; |
| 354 | |
| 355 | case BRCMF_E_TRACE: |
| 356 | buf = (unsigned char *) event_data; |
| 357 | memcpy(&hdr, buf, sizeof(struct msgtrace_hdr)); |
| 358 | |
| 359 | if (hdr.version != MSGTRACE_VERSION) { |
| 360 | brcmf_dbg(ERROR, |
| 361 | "MACEVENT: %s [unsupported version --> brcmf" |
| 362 | " version:%d dongle version:%d]\n", |
| 363 | event_name, MSGTRACE_VERSION, hdr.version); |
| 364 | /* Reset datalen to avoid display below */ |
| 365 | datalen = 0; |
| 366 | break; |
| 367 | } |
| 368 | |
| 369 | /* There are 2 bytes available at the end of data */ |
| 370 | *(buf + sizeof(struct msgtrace_hdr) |
| 371 | + be16_to_cpu(hdr.len)) = '\0'; |
| 372 | |
| 373 | if (be32_to_cpu(hdr.discarded_bytes) |
| 374 | || be32_to_cpu(hdr.discarded_printf)) |
| 375 | brcmf_dbg(ERROR, |
| 376 | "WLC_E_TRACE: [Discarded traces in dongle -->" |
| 377 | " discarded_bytes %d discarded_printf %d]\n", |
| 378 | be32_to_cpu(hdr.discarded_bytes), |
| 379 | be32_to_cpu(hdr.discarded_printf)); |
| 380 | |
| 381 | nblost = be32_to_cpu(hdr.seqnum) - seqnum_prev - 1; |
| 382 | if (nblost > 0) |
| 383 | brcmf_dbg(ERROR, "WLC_E_TRACE: [Event lost --> seqnum " |
| 384 | " %d nblost %d\n", be32_to_cpu(hdr.seqnum), |
| 385 | nblost); |
| 386 | seqnum_prev = be32_to_cpu(hdr.seqnum); |
| 387 | |
| 388 | /* Display the trace buffer. Advance from \n to \n to |
| 389 | * avoid display big |
| 390 | * printf (issue with Linux printk ) |
| 391 | */ |
| 392 | p = (char *)&buf[sizeof(struct msgtrace_hdr)]; |
| 393 | while ((s = strstr(p, "\n")) != NULL) { |
| 394 | *s = '\0'; |
| 395 | printk(KERN_DEBUG"%s\n", p); |
| 396 | p = s + 1; |
| 397 | } |
| 398 | printk(KERN_DEBUG "%s\n", p); |
| 399 | |
| 400 | /* Reset datalen to avoid display below */ |
| 401 | datalen = 0; |
| 402 | break; |
| 403 | |
| 404 | case BRCMF_E_RSSI: |
| 405 | brcmf_dbg(EVENT, "MACEVENT: %s %d\n", |
| 406 | event_name, be32_to_cpu(*((__be32 *)event_data))); |
| 407 | break; |
| 408 | |
| 409 | default: |
| 410 | brcmf_dbg(EVENT, |
| 411 | "MACEVENT: %s %d, MAC %s, status %d, reason %d, " |
| 412 | "auth %d\n", event_name, event_type, eabuf, |
| 413 | (int)status, (int)reason, (int)auth_type); |
| 414 | break; |
| 415 | } |
| 416 | |
| 417 | /* show any appended data */ |
| 418 | if (datalen) { |
| 419 | buf = (unsigned char *) event_data; |
| 420 | brcmf_dbg(EVENT, " data (%d) : ", datalen); |
| 421 | for (i = 0; i < datalen; i++) |
| 422 | brcmf_dbg(EVENT, " 0x%02x ", *buf++); |
| 423 | brcmf_dbg(EVENT, "\n"); |
| 424 | } |
| 425 | } |
| 426 | #endif /* BCMDBG */ |
| 427 | |
| 428 | int |
| 429 | brcmf_c_host_event(struct brcmf_info *drvr_priv, int *ifidx, void *pktdata, |
| 430 | struct brcmf_event_msg *event, void **data_ptr) |
| 431 | { |
| 432 | /* check whether packet is a BRCM event pkt */ |
| 433 | struct brcmf_event *pvt_data = (struct brcmf_event *) pktdata; |
| 434 | struct brcmf_if_event *ifevent; |
| 435 | char *event_data; |
| 436 | u32 type, status; |
| 437 | u16 flags; |
| 438 | int evlen; |
| 439 | |
| 440 | if (memcmp(BRCM_OUI, &pvt_data->hdr.oui[0], DOT11_OUI_LEN)) { |
| 441 | brcmf_dbg(ERROR, "mismatched OUI, bailing\n"); |
| 442 | return -EBADE; |
| 443 | } |
| 444 | |
| 445 | /* BRCM event pkt may be unaligned - use xxx_ua to load user_subtype. */ |
| 446 | if (get_unaligned_be16(&pvt_data->hdr.usr_subtype) != |
| 447 | BCMILCP_BCM_SUBTYPE_EVENT) { |
| 448 | brcmf_dbg(ERROR, "mismatched subtype, bailing\n"); |
| 449 | return -EBADE; |
| 450 | } |
| 451 | |
| 452 | *data_ptr = &pvt_data[1]; |
| 453 | event_data = *data_ptr; |
| 454 | |
| 455 | /* memcpy since BRCM event pkt may be unaligned. */ |
| 456 | memcpy(event, &pvt_data->msg, sizeof(struct brcmf_event_msg)); |
| 457 | |
| 458 | type = get_unaligned_be32(&event->event_type); |
| 459 | flags = get_unaligned_be16(&event->flags); |
| 460 | status = get_unaligned_be32(&event->status); |
| 461 | evlen = get_unaligned_be32(&event->datalen) + |
| 462 | sizeof(struct brcmf_event); |
| 463 | |
| 464 | switch (type) { |
| 465 | case BRCMF_E_IF: |
| 466 | ifevent = (struct brcmf_if_event *) event_data; |
| 467 | brcmf_dbg(TRACE, "if event\n"); |
| 468 | |
| 469 | if (ifevent->ifidx > 0 && ifevent->ifidx < BRCMF_MAX_IFS) { |
| 470 | if (ifevent->action == BRCMF_E_IF_ADD) |
| 471 | brcmf_add_if(drvr_priv, ifevent->ifidx, NULL, |
| 472 | event->ifname, |
| 473 | pvt_data->eth.h_dest, |
| 474 | ifevent->flags, ifevent->bssidx); |
| 475 | else |
| 476 | brcmf_del_if(drvr_priv, ifevent->ifidx); |
| 477 | } else { |
| 478 | brcmf_dbg(ERROR, "Invalid ifidx %d for %s\n", |
| 479 | ifevent->ifidx, event->ifname); |
| 480 | } |
| 481 | |
| 482 | /* send up the if event: btamp user needs it */ |
| 483 | *ifidx = brcmf_ifname2idx(drvr_priv, event->ifname); |
| 484 | break; |
| 485 | |
| 486 | /* These are what external supplicant/authenticator wants */ |
| 487 | case BRCMF_E_LINK: |
| 488 | case BRCMF_E_ASSOC_IND: |
| 489 | case BRCMF_E_REASSOC_IND: |
| 490 | case BRCMF_E_DISASSOC_IND: |
| 491 | case BRCMF_E_MIC_ERROR: |
| 492 | default: |
| 493 | /* Fall through: this should get _everything_ */ |
| 494 | |
| 495 | *ifidx = brcmf_ifname2idx(drvr_priv, event->ifname); |
| 496 | brcmf_dbg(TRACE, "MAC event %d, flags %x, status %x\n", |
| 497 | type, flags, status); |
| 498 | |
| 499 | /* put it back to BRCMF_E_NDIS_LINK */ |
| 500 | if (type == BRCMF_E_NDIS_LINK) { |
| 501 | u32 temp1; |
| 502 | __be32 temp2; |
| 503 | |
| 504 | temp1 = get_unaligned_be32(&event->event_type); |
| 505 | brcmf_dbg(TRACE, "Converted to WLC_E_LINK type %d\n", |
| 506 | temp1); |
| 507 | |
| 508 | temp2 = cpu_to_be32(BRCMF_E_NDIS_LINK); |
| 509 | memcpy((void *)(&pvt_data->msg.event_type), &temp2, |
| 510 | sizeof(pvt_data->msg.event_type)); |
| 511 | } |
| 512 | break; |
| 513 | } |
| 514 | |
| 515 | #ifdef BCMDBG |
| 516 | brcmf_c_show_host_event(event, event_data); |
| 517 | #endif /* BCMDBG */ |
| 518 | |
| 519 | return 0; |
| 520 | } |
| 521 | |
| 522 | /* Convert user's input in hex pattern to byte-size mask */ |
| 523 | static int brcmf_c_pattern_atoh(char *src, char *dst) |
| 524 | { |
| 525 | int i; |
| 526 | if (strncmp(src, "0x", 2) != 0 && strncmp(src, "0X", 2) != 0) { |
| 527 | brcmf_dbg(ERROR, "Mask invalid format. Needs to start with 0x\n"); |
| 528 | return -EINVAL; |
| 529 | } |
| 530 | src = src + 2; /* Skip past 0x */ |
| 531 | if (strlen(src) % 2 != 0) { |
| 532 | brcmf_dbg(ERROR, "Mask invalid format. Length must be even.\n"); |
| 533 | return -EINVAL; |
| 534 | } |
| 535 | for (i = 0; *src != '\0'; i++) { |
| 536 | unsigned long res; |
| 537 | char num[3]; |
| 538 | strncpy(num, src, 2); |
| 539 | num[2] = '\0'; |
| 540 | if (kstrtoul(num, 16, &res)) |
| 541 | return -EINVAL; |
| 542 | dst[i] = (u8)res; |
| 543 | src += 2; |
| 544 | } |
| 545 | return i; |
| 546 | } |
| 547 | |
| 548 | void |
| 549 | brcmf_c_pktfilter_offload_enable(struct brcmf_pub *drvr, char *arg, int enable, |
| 550 | int master_mode) |
| 551 | { |
| 552 | unsigned long res; |
| 553 | char *argv[8]; |
| 554 | int i = 0; |
| 555 | const char *str; |
| 556 | int buf_len; |
| 557 | int str_len; |
| 558 | char *arg_save = NULL, *arg_org = NULL; |
| 559 | int rc; |
| 560 | char buf[128]; |
| 561 | struct brcmf_pkt_filter_enable enable_parm; |
| 562 | struct brcmf_pkt_filter_enable *pkt_filterp; |
| 563 | |
| 564 | arg_save = kmalloc(strlen(arg) + 1, GFP_ATOMIC); |
| 565 | if (!arg_save) |
| 566 | goto fail; |
| 567 | |
| 568 | arg_org = arg_save; |
| 569 | memcpy(arg_save, arg, strlen(arg) + 1); |
| 570 | |
| 571 | argv[i] = strsep(&arg_save, " "); |
| 572 | |
| 573 | i = 0; |
| 574 | if (NULL == argv[i]) { |
| 575 | brcmf_dbg(ERROR, "No args provided\n"); |
| 576 | goto fail; |
| 577 | } |
| 578 | |
| 579 | str = "pkt_filter_enable"; |
| 580 | str_len = strlen(str); |
| 581 | strncpy(buf, str, str_len); |
| 582 | buf[str_len] = '\0'; |
| 583 | buf_len = str_len + 1; |
| 584 | |
| 585 | pkt_filterp = (struct brcmf_pkt_filter_enable *) (buf + str_len + 1); |
| 586 | |
| 587 | /* Parse packet filter id. */ |
| 588 | enable_parm.id = 0; |
| 589 | if (!kstrtoul(argv[i], 0, &res)) |
| 590 | enable_parm.id = (u32)res; |
| 591 | |
| 592 | /* Parse enable/disable value. */ |
| 593 | enable_parm.enable = enable; |
| 594 | |
| 595 | buf_len += sizeof(enable_parm); |
| 596 | memcpy((char *)pkt_filterp, &enable_parm, sizeof(enable_parm)); |
| 597 | |
| 598 | /* Enable/disable the specified filter. */ |
| 599 | rc = brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, buf, buf_len); |
| 600 | rc = rc >= 0 ? 0 : rc; |
| 601 | if (rc) |
| 602 | brcmf_dbg(TRACE, "failed to add pktfilter %s, retcode = %d\n", |
| 603 | arg, rc); |
| 604 | else |
| 605 | brcmf_dbg(TRACE, "successfully added pktfilter %s\n", arg); |
| 606 | |
| 607 | /* Contorl the master mode */ |
| 608 | brcmu_mkiovar("pkt_filter_mode", (char *)&master_mode, 4, buf, |
| 609 | sizeof(buf)); |
| 610 | rc = brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, buf, |
| 611 | sizeof(buf)); |
| 612 | rc = rc >= 0 ? 0 : rc; |
| 613 | if (rc) |
| 614 | brcmf_dbg(TRACE, "failed to add pktfilter %s, retcode = %d\n", |
| 615 | arg, rc); |
| 616 | |
| 617 | fail: |
| 618 | kfree(arg_org); |
| 619 | } |
| 620 | |
| 621 | void brcmf_c_pktfilter_offload_set(struct brcmf_pub *drvr, char *arg) |
| 622 | { |
| 623 | const char *str; |
| 624 | struct brcmf_pkt_filter pkt_filter; |
| 625 | struct brcmf_pkt_filter *pkt_filterp; |
| 626 | unsigned long res; |
| 627 | int buf_len; |
| 628 | int str_len; |
| 629 | int rc; |
| 630 | u32 mask_size; |
| 631 | u32 pattern_size; |
| 632 | char *argv[8], *buf = NULL; |
| 633 | int i = 0; |
| 634 | char *arg_save = NULL, *arg_org = NULL; |
| 635 | |
| 636 | arg_save = kstrdup(arg, GFP_ATOMIC); |
| 637 | if (!arg_save) |
| 638 | goto fail; |
| 639 | |
| 640 | arg_org = arg_save; |
| 641 | |
| 642 | buf = kmalloc(PKTFILTER_BUF_SIZE, GFP_ATOMIC); |
| 643 | if (!buf) |
| 644 | goto fail; |
| 645 | |
| 646 | argv[i] = strsep(&arg_save, " "); |
| 647 | while (argv[i++]) |
| 648 | argv[i] = strsep(&arg_save, " "); |
| 649 | |
| 650 | i = 0; |
| 651 | if (NULL == argv[i]) { |
| 652 | brcmf_dbg(ERROR, "No args provided\n"); |
| 653 | goto fail; |
| 654 | } |
| 655 | |
| 656 | str = "pkt_filter_add"; |
| 657 | strcpy(buf, str); |
| 658 | str_len = strlen(str); |
| 659 | buf_len = str_len + 1; |
| 660 | |
| 661 | pkt_filterp = (struct brcmf_pkt_filter *) (buf + str_len + 1); |
| 662 | |
| 663 | /* Parse packet filter id. */ |
| 664 | pkt_filter.id = 0; |
| 665 | if (!kstrtoul(argv[i], 0, &res)) |
| 666 | pkt_filter.id = (u32)res; |
| 667 | |
| 668 | if (NULL == argv[++i]) { |
| 669 | brcmf_dbg(ERROR, "Polarity not provided\n"); |
| 670 | goto fail; |
| 671 | } |
| 672 | |
| 673 | /* Parse filter polarity. */ |
| 674 | pkt_filter.negate_match = 0; |
| 675 | if (!kstrtoul(argv[i], 0, &res)) |
| 676 | pkt_filter.negate_match = (u32)res; |
| 677 | |
| 678 | if (NULL == argv[++i]) { |
| 679 | brcmf_dbg(ERROR, "Filter type not provided\n"); |
| 680 | goto fail; |
| 681 | } |
| 682 | |
| 683 | /* Parse filter type. */ |
| 684 | pkt_filter.type = 0; |
| 685 | if (!kstrtoul(argv[i], 0, &res)) |
| 686 | pkt_filter.type = (u32)res; |
| 687 | |
| 688 | if (NULL == argv[++i]) { |
| 689 | brcmf_dbg(ERROR, "Offset not provided\n"); |
| 690 | goto fail; |
| 691 | } |
| 692 | |
| 693 | /* Parse pattern filter offset. */ |
| 694 | pkt_filter.u.pattern.offset = 0; |
| 695 | if (!kstrtoul(argv[i], 0, &res)) |
| 696 | pkt_filter.u.pattern.offset = (u32)res; |
| 697 | |
| 698 | if (NULL == argv[++i]) { |
| 699 | brcmf_dbg(ERROR, "Bitmask not provided\n"); |
| 700 | goto fail; |
| 701 | } |
| 702 | |
| 703 | /* Parse pattern filter mask. */ |
| 704 | mask_size = |
| 705 | brcmf_c_pattern_atoh |
| 706 | (argv[i], (char *)pkt_filterp->u.pattern.mask_and_pattern); |
| 707 | |
| 708 | if (NULL == argv[++i]) { |
| 709 | brcmf_dbg(ERROR, "Pattern not provided\n"); |
| 710 | goto fail; |
| 711 | } |
| 712 | |
| 713 | /* Parse pattern filter pattern. */ |
| 714 | pattern_size = |
| 715 | brcmf_c_pattern_atoh(argv[i], |
| 716 | (char *)&pkt_filterp->u.pattern. |
| 717 | mask_and_pattern[mask_size]); |
| 718 | |
| 719 | if (mask_size != pattern_size) { |
| 720 | brcmf_dbg(ERROR, "Mask and pattern not the same size\n"); |
| 721 | goto fail; |
| 722 | } |
| 723 | |
| 724 | pkt_filter.u.pattern.size_bytes = mask_size; |
| 725 | buf_len += BRCMF_PKT_FILTER_FIXED_LEN; |
| 726 | buf_len += (BRCMF_PKT_FILTER_PATTERN_FIXED_LEN + 2 * mask_size); |
| 727 | |
| 728 | /* Keep-alive attributes are set in local |
| 729 | * variable (keep_alive_pkt), and |
| 730 | ** then memcpy'ed into buffer (keep_alive_pktp) since there is no |
| 731 | ** guarantee that the buffer is properly aligned. |
| 732 | */ |
| 733 | memcpy((char *)pkt_filterp, |
| 734 | &pkt_filter, |
| 735 | BRCMF_PKT_FILTER_FIXED_LEN + BRCMF_PKT_FILTER_PATTERN_FIXED_LEN); |
| 736 | |
| 737 | rc = brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, buf, buf_len); |
| 738 | rc = rc >= 0 ? 0 : rc; |
| 739 | |
| 740 | if (rc) |
| 741 | brcmf_dbg(TRACE, "failed to add pktfilter %s, retcode = %d\n", |
| 742 | arg, rc); |
| 743 | else |
| 744 | brcmf_dbg(TRACE, "successfully added pktfilter %s\n", arg); |
| 745 | |
| 746 | fail: |
| 747 | kfree(arg_org); |
| 748 | |
| 749 | kfree(buf); |
| 750 | } |
| 751 | |
| 752 | static void brcmf_c_arp_offload_set(struct brcmf_pub *drvr, int arp_mode) |
| 753 | { |
| 754 | char iovbuf[32]; |
| 755 | int retcode; |
| 756 | |
| 757 | brcmu_mkiovar("arp_ol", (char *)&arp_mode, 4, iovbuf, sizeof(iovbuf)); |
| 758 | retcode = brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, |
| 759 | iovbuf, sizeof(iovbuf)); |
| 760 | retcode = retcode >= 0 ? 0 : retcode; |
| 761 | if (retcode) |
| 762 | brcmf_dbg(TRACE, "failed to set ARP offload mode to 0x%x, retcode = %d\n", |
| 763 | arp_mode, retcode); |
| 764 | else |
| 765 | brcmf_dbg(TRACE, "successfully set ARP offload mode to 0x%x\n", |
| 766 | arp_mode); |
| 767 | } |
| 768 | |
| 769 | static void brcmf_c_arp_offload_enable(struct brcmf_pub *drvr, int arp_enable) |
| 770 | { |
| 771 | char iovbuf[32]; |
| 772 | int retcode; |
| 773 | |
| 774 | brcmu_mkiovar("arpoe", (char *)&arp_enable, 4, iovbuf, sizeof(iovbuf)); |
| 775 | retcode = brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, |
| 776 | iovbuf, sizeof(iovbuf)); |
| 777 | retcode = retcode >= 0 ? 0 : retcode; |
| 778 | if (retcode) |
| 779 | brcmf_dbg(TRACE, "failed to enable ARP offload to %d, retcode = %d\n", |
| 780 | arp_enable, retcode); |
| 781 | else |
| 782 | brcmf_dbg(TRACE, "successfully enabled ARP offload to %d\n", |
| 783 | arp_enable); |
| 784 | } |
| 785 | |
| 786 | int brcmf_c_preinit_dcmds(struct brcmf_pub *drvr) |
| 787 | { |
| 788 | char iovbuf[BRCMF_EVENTING_MASK_LEN + 12]; /* Room for |
| 789 | "event_msgs" + '\0' + bitvec */ |
| 790 | uint up = 0; |
| 791 | char buf[128], *ptr; |
| 792 | u32 dongle_align = BRCMF_SDALIGN; |
| 793 | u32 glom = 0; |
| 794 | u32 roaming = 1; |
| 795 | uint bcn_timeout = 3; |
| 796 | int scan_assoc_time = 40; |
| 797 | int scan_unassoc_time = 40; |
| 798 | int i; |
| 799 | |
| 800 | brcmf_os_proto_block(drvr); |
| 801 | |
| 802 | /* Set Country code */ |
| 803 | if (drvr->country_code[0] != 0) { |
| 804 | if (brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_COUNTRY, |
| 805 | drvr->country_code, |
| 806 | sizeof(drvr->country_code)) < 0) |
| 807 | brcmf_dbg(ERROR, "country code setting failed\n"); |
| 808 | } |
| 809 | |
| 810 | /* query for 'ver' to get version info from firmware */ |
| 811 | memset(buf, 0, sizeof(buf)); |
| 812 | ptr = buf; |
| 813 | brcmu_mkiovar("ver", NULL, 0, buf, sizeof(buf)); |
| 814 | brcmf_proto_cdc_query_dcmd(drvr, 0, BRCMF_C_GET_VAR, buf, sizeof(buf)); |
| 815 | strsep(&ptr, "\n"); |
| 816 | /* Print fw version info */ |
| 817 | brcmf_dbg(ERROR, "Firmware version = %s\n", buf); |
| 818 | |
| 819 | /* Match Host and Dongle rx alignment */ |
| 820 | brcmu_mkiovar("bus:txglomalign", (char *)&dongle_align, 4, iovbuf, |
| 821 | sizeof(iovbuf)); |
| 822 | brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, iovbuf, |
| 823 | sizeof(iovbuf)); |
| 824 | |
| 825 | /* disable glom option per default */ |
| 826 | brcmu_mkiovar("bus:txglom", (char *)&glom, 4, iovbuf, sizeof(iovbuf)); |
| 827 | brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, iovbuf, |
| 828 | sizeof(iovbuf)); |
| 829 | |
| 830 | /* Setup timeout if Beacons are lost and roam is off to report |
| 831 | link down */ |
| 832 | brcmu_mkiovar("bcn_timeout", (char *)&bcn_timeout, 4, iovbuf, |
| 833 | sizeof(iovbuf)); |
| 834 | brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, iovbuf, |
| 835 | sizeof(iovbuf)); |
| 836 | |
| 837 | /* Enable/Disable build-in roaming to allowed ext supplicant to take |
| 838 | of romaing */ |
| 839 | brcmu_mkiovar("roam_off", (char *)&roaming, 4, |
| 840 | iovbuf, sizeof(iovbuf)); |
| 841 | brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, iovbuf, |
| 842 | sizeof(iovbuf)); |
| 843 | |
| 844 | /* Force STA UP */ |
| 845 | brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_UP, (char *)&up, sizeof(up)); |
| 846 | |
| 847 | /* Setup event_msgs */ |
| 848 | brcmu_mkiovar("event_msgs", drvr->eventmask, BRCMF_EVENTING_MASK_LEN, |
| 849 | iovbuf, sizeof(iovbuf)); |
| 850 | brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, iovbuf, |
| 851 | sizeof(iovbuf)); |
| 852 | |
| 853 | brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_SCAN_CHANNEL_TIME, |
| 854 | (char *)&scan_assoc_time, sizeof(scan_assoc_time)); |
| 855 | brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_SCAN_UNASSOC_TIME, |
| 856 | (char *)&scan_unassoc_time, sizeof(scan_unassoc_time)); |
| 857 | |
| 858 | /* Set and enable ARP offload feature */ |
| 859 | brcmf_c_arp_offload_set(drvr, BRCMF_ARPOL_MODE); |
| 860 | brcmf_c_arp_offload_enable(drvr, true); |
| 861 | |
| 862 | /* Set up pkt filter */ |
| 863 | for (i = 0; i < drvr->pktfilter_count; i++) { |
| 864 | brcmf_c_pktfilter_offload_set(drvr, drvr->pktfilter[i]); |
| 865 | brcmf_c_pktfilter_offload_enable(drvr, drvr->pktfilter[i], |
| 866 | 0, true); |
| 867 | } |
| 868 | |
| 869 | brcmf_os_proto_unblock(drvr); |
| 870 | |
| 871 | return 0; |
| 872 | } |