net: wireless: bcm4329: Add SoftAP MAC address randomization
authorDmitry Shmidt <dimitrysh@google.com>
Thu, 17 Jun 2010 21:00:02 +0000 (14:00 -0700)
committerColin Cross <ccross@android.com>
Thu, 30 Sep 2010 00:49:37 +0000 (17:49 -0700)
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
drivers/net/wireless/bcm4329/Makefile
drivers/net/wireless/bcm4329/dhd_common.c

index 453630e90836bf6edd2cfe67bf87966c1dfe01a4..43f891a8ea3dd7a64bce5f0ee4e39c945eae944e 100644 (file)
@@ -6,7 +6,7 @@ DHDCFLAGS = -DLINUX -DBCMDRIVER -DBCMDONGLEHOST -DDHDTHREAD -DBCMWPA2         \
        -Wall -Wstrict-prototypes -Werror -DOOB_INTR_ONLY -DCUSTOMER_HW2      \
        -DDHD_USE_STATIC_BUF -DMMC_SDIO_ABORT -DDHD_DEBUG_TRAP -DSOFTAP       \
        -DEMBEDDED_PLATFORM -DARP_OFFLOAD_SUPPORT -DPKT_FILTER_SUPPORT        \
-       -DGET_CUSTOM_MAC_ENABLE                                               \
+       -DGET_CUSTOM_MAC_ENABLE -DSET_RANDOM_MAC_SOFTAP                       \
        -Idrivers/net/wireless/bcm4329 -Idrivers/net/wireless/bcm4329/include
 
 DHDOFILES = dhd_linux.o linux_osl.o bcmutils.o dhd_common.o dhd_custom_gpio.o \
index 652cf291de2b18eda3d8212948d015f733611155..41fe604281e2a5a516dc559345fe8f80b21bd209 100644 (file)
 
 #include <wlioctl.h>
 
+#ifdef SET_RANDOM_MAC_SOFTAP
+#include <linux/random.h>
+#include <linux/jiffies.h>
+#endif
+
 #ifdef GET_CUSTOM_MAC_ENABLE
 int wifi_get_mac_addr(unsigned char *buf);
 #endif /* GET_CUSTOM_MAC_ENABLE */
@@ -1259,12 +1264,36 @@ dhd_preinit_ioctls(dhd_pub_t *dhd)
                ret = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, buf, sizeof(buf));
                if (ret < 0) {
                        DHD_ERROR(("%s: can't set MAC address , error=%d\n", __FUNCTION__, ret));
-               }
-               else
+               } else
                        memcpy(dhd->mac.octet, (void *)&ea_addr, ETHER_ADDR_LEN);
        }
 #endif /* GET_CUSTOM_MAC_ENABLE */
 
+#ifdef SET_RANDOM_MAC_SOFTAP
+       if (strstr(fw_path, "apsta") != NULL) {
+               uint rand_mac;
+               int ret;
+
+               memcpy(iovbuf, dhd->mac.octet, ETHER_ADDR_LEN);
+               srandom32((uint)jiffies);
+               rand_mac = random32();
+               iovbuf[0] |= 0x02;              /* locally administered bit */
+               iovbuf[3] = (unsigned char)rand_mac;
+               iovbuf[4] = (unsigned char)(rand_mac >> 8);
+               iovbuf[5] = (unsigned char)(rand_mac >> 16);
+
+               printk("Broadcom Dongle Host Driver mac=%02x:%02x:%02x:%02x:%02x:%02x\n",
+                       iovbuf[0], iovbuf[1], iovbuf[2], iovbuf[3], iovbuf[4], iovbuf[5]);
+
+               bcm_mkiovar("cur_etheraddr", (void *)iovbuf, ETHER_ADDR_LEN, buf, sizeof(buf));
+               ret = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, buf, sizeof(buf));
+               if (ret < 0) {
+                       DHD_ERROR(("%s: can't set MAC address , error=%d\n", __FUNCTION__, ret));
+               } else
+                       memcpy(dhd->mac.octet, iovbuf, ETHER_ADDR_LEN);
+       }
+#endif /* SET_RANDOM_MAC_SOFTAP */
+
        /* Set Country code */
        if (dhd->country_code[0] != 0) {
                if (dhdcdc_set_ioctl(dhd, 0, WLC_SET_COUNTRY,