Commit | Line | Data |
---|---|---|
8ca21f01 JM |
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 | { | |
41 | struct ath_softc *sc = hw->priv; | |
42 | struct ath9k_vif_iter_data iter_data; | |
43 | int i, j; | |
44 | u8 mask[ETH_ALEN]; | |
45 | ||
46 | /* | |
47 | * Add primary MAC address even if it is not in active use since it | |
48 | * will be configured to the hardware as the starting point and the | |
49 | * BSSID mask will need to be changed if another address is active. | |
50 | */ | |
51 | iter_data.addr = kmalloc(ETH_ALEN, GFP_ATOMIC); | |
52 | if (iter_data.addr) { | |
53 | memcpy(iter_data.addr, sc->sc_ah->macaddr, ETH_ALEN); | |
54 | iter_data.count = 1; | |
55 | } else | |
56 | iter_data.count = 0; | |
57 | ||
58 | /* Get list of all active MAC addresses */ | |
59 | ieee80211_iterate_active_interfaces_atomic(hw, ath9k_vif_iter, | |
60 | &iter_data); | |
61 | ||
62 | /* Generate an address mask to cover all active addresses */ | |
63 | memset(mask, 0, ETH_ALEN); | |
64 | for (i = 0; i < iter_data.count; i++) { | |
65 | u8 *a1 = iter_data.addr + i * ETH_ALEN; | |
66 | for (j = i + 1; j < iter_data.count; j++) { | |
67 | u8 *a2 = iter_data.addr + j * ETH_ALEN; | |
68 | mask[0] |= a1[0] ^ a2[0]; | |
69 | mask[1] |= a1[1] ^ a2[1]; | |
70 | mask[2] |= a1[2] ^ a2[2]; | |
71 | mask[3] |= a1[3] ^ a2[3]; | |
72 | mask[4] |= a1[4] ^ a2[4]; | |
73 | mask[5] |= a1[5] ^ a2[5]; | |
74 | } | |
75 | } | |
76 | ||
77 | kfree(iter_data.addr); | |
78 | ||
79 | /* Invert the mask and configure hardware */ | |
80 | sc->bssidmask[0] = ~mask[0]; | |
81 | sc->bssidmask[1] = ~mask[1]; | |
82 | sc->bssidmask[2] = ~mask[2]; | |
83 | sc->bssidmask[3] = ~mask[3]; | |
84 | sc->bssidmask[4] = ~mask[4]; | |
85 | sc->bssidmask[5] = ~mask[5]; | |
86 | ||
87 | ath9k_hw_setbssidmask(sc); | |
88 | } |