virtual.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #include "ath9k.h"
  17. struct ath9k_vif_iter_data {
  18. int count;
  19. u8 *addr;
  20. };
  21. static void ath9k_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
  22. {
  23. struct ath9k_vif_iter_data *iter_data = data;
  24. u8 *nbuf;
  25. nbuf = krealloc(iter_data->addr, (iter_data->count + 1) * ETH_ALEN,
  26. GFP_ATOMIC);
  27. if (nbuf == NULL)
  28. return;
  29. memcpy(nbuf + iter_data->count * ETH_ALEN, mac, ETH_ALEN);
  30. iter_data->addr = nbuf;
  31. iter_data->count++;
  32. }
  33. void ath9k_set_bssid_mask(struct ieee80211_hw *hw)
  34. {
  35. struct ath_wiphy *aphy = hw->priv;
  36. struct ath_softc *sc = aphy->sc;
  37. struct ath9k_vif_iter_data iter_data;
  38. int i, j;
  39. u8 mask[ETH_ALEN];
  40. /*
  41. * Add primary MAC address even if it is not in active use since it
  42. * will be configured to the hardware as the starting point and the
  43. * BSSID mask will need to be changed if another address is active.
  44. */
  45. iter_data.addr = kmalloc(ETH_ALEN, GFP_ATOMIC);
  46. if (iter_data.addr) {
  47. memcpy(iter_data.addr, sc->sc_ah->macaddr, ETH_ALEN);
  48. iter_data.count = 1;
  49. } else
  50. iter_data.count = 0;
  51. /* Get list of all active MAC addresses */
  52. ieee80211_iterate_active_interfaces_atomic(hw, ath9k_vif_iter,
  53. &iter_data);
  54. /* Generate an address mask to cover all active addresses */
  55. memset(mask, 0, ETH_ALEN);
  56. for (i = 0; i < iter_data.count; i++) {
  57. u8 *a1 = iter_data.addr + i * ETH_ALEN;
  58. for (j = i + 1; j < iter_data.count; j++) {
  59. u8 *a2 = iter_data.addr + j * ETH_ALEN;
  60. mask[0] |= a1[0] ^ a2[0];
  61. mask[1] |= a1[1] ^ a2[1];
  62. mask[2] |= a1[2] ^ a2[2];
  63. mask[3] |= a1[3] ^ a2[3];
  64. mask[4] |= a1[4] ^ a2[4];
  65. mask[5] |= a1[5] ^ a2[5];
  66. }
  67. }
  68. kfree(iter_data.addr);
  69. /* Invert the mask and configure hardware */
  70. sc->bssidmask[0] = ~mask[0];
  71. sc->bssidmask[1] = ~mask[1];
  72. sc->bssidmask[2] = ~mask[2];
  73. sc->bssidmask[3] = ~mask[3];
  74. sc->bssidmask[4] = ~mask[4];
  75. sc->bssidmask[5] = ~mask[5];
  76. ath9k_hw_setbssidmask(sc);
  77. }