Jouni Malinen | 8ca21f0 | 2009-03-03 19:23:27 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008-2009 Atheros Communications Inc. |
| 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 |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
| 17 | #include "ath9k.h" |
| 18 | |
| 19 | struct ath9k_vif_iter_data { |
| 20 | int count; |
| 21 | u8 *addr; |
| 22 | }; |
| 23 | |
| 24 | static void ath9k_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif) |
| 25 | { |
| 26 | struct ath9k_vif_iter_data *iter_data = data; |
| 27 | u8 *nbuf; |
| 28 | |
| 29 | nbuf = krealloc(iter_data->addr, (iter_data->count + 1) * ETH_ALEN, |
| 30 | GFP_ATOMIC); |
| 31 | if (nbuf == NULL) |
| 32 | return; |
| 33 | |
| 34 | memcpy(nbuf + iter_data->count * ETH_ALEN, mac, ETH_ALEN); |
| 35 | iter_data->addr = nbuf; |
| 36 | iter_data->count++; |
| 37 | } |
| 38 | |
| 39 | void ath9k_set_bssid_mask(struct ieee80211_hw *hw) |
| 40 | { |
Jouni Malinen | bce048d | 2009-03-03 19:23:28 +0200 | [diff] [blame^] | 41 | struct ath_wiphy *aphy = hw->priv; |
| 42 | struct ath_softc *sc = aphy->sc; |
Jouni Malinen | 8ca21f0 | 2009-03-03 19:23:27 +0200 | [diff] [blame] | 43 | struct ath9k_vif_iter_data iter_data; |
| 44 | int i, j; |
| 45 | u8 mask[ETH_ALEN]; |
| 46 | |
| 47 | /* |
| 48 | * Add primary MAC address even if it is not in active use since it |
| 49 | * will be configured to the hardware as the starting point and the |
| 50 | * BSSID mask will need to be changed if another address is active. |
| 51 | */ |
| 52 | iter_data.addr = kmalloc(ETH_ALEN, GFP_ATOMIC); |
| 53 | if (iter_data.addr) { |
| 54 | memcpy(iter_data.addr, sc->sc_ah->macaddr, ETH_ALEN); |
| 55 | iter_data.count = 1; |
| 56 | } else |
| 57 | iter_data.count = 0; |
| 58 | |
| 59 | /* Get list of all active MAC addresses */ |
| 60 | ieee80211_iterate_active_interfaces_atomic(hw, ath9k_vif_iter, |
| 61 | &iter_data); |
| 62 | |
| 63 | /* Generate an address mask to cover all active addresses */ |
| 64 | memset(mask, 0, ETH_ALEN); |
| 65 | for (i = 0; i < iter_data.count; i++) { |
| 66 | u8 *a1 = iter_data.addr + i * ETH_ALEN; |
| 67 | for (j = i + 1; j < iter_data.count; j++) { |
| 68 | u8 *a2 = iter_data.addr + j * ETH_ALEN; |
| 69 | mask[0] |= a1[0] ^ a2[0]; |
| 70 | mask[1] |= a1[1] ^ a2[1]; |
| 71 | mask[2] |= a1[2] ^ a2[2]; |
| 72 | mask[3] |= a1[3] ^ a2[3]; |
| 73 | mask[4] |= a1[4] ^ a2[4]; |
| 74 | mask[5] |= a1[5] ^ a2[5]; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | kfree(iter_data.addr); |
| 79 | |
| 80 | /* Invert the mask and configure hardware */ |
| 81 | sc->bssidmask[0] = ~mask[0]; |
| 82 | sc->bssidmask[1] = ~mask[1]; |
| 83 | sc->bssidmask[2] = ~mask[2]; |
| 84 | sc->bssidmask[3] = ~mask[3]; |
| 85 | sc->bssidmask[4] = ~mask[4]; |
| 86 | sc->bssidmask[5] = ~mask[5]; |
| 87 | |
| 88 | ath9k_hw_setbssidmask(sc); |
| 89 | } |