summaryrefslogtreecommitdiff
path: root/posts/Fixing_Android_Mac_Address_Conflicts.adoc
blob: 06c8f55229a15e5bbabfa81a4819a16025baaf66 (plain)
    1 Fixing Android MAC Address Conflicts
    2 ====================================
    3 
    4 If you already know this is the fix for your issue, you can skip this section.
    5 Otherwise, I'll get on to describing the problem.
    6 
    7 I have been frustrated for the last few days with my phone. I have run
    8 CyanogenMod for a while now on my LG G3 (since the early alpha builds), while
    9 my wife ran a variant of the stock carrier rom. However, due to poor battery
   10 life issues, she wanted to have CyanogenMod since my phone gets about twice as
   11 much battery life than hers does. Obligingly, I flashed CyanogenMod on her
   12 phone. That night I noticed a problem was occuring with both of our phones,
   13 which I unfortunately didn't realize the source of until today.
   14 
   15 [[symptoms]]
   16 Symptoms
   17 ~~~~~~~~
   18 
   19 The symptoms of the issue were wifi was repeatedly dropping. Rebooting wifi
   20 and/or toggling airplane mode would fix the issue for a few minutes, but it got
   21 progressively worse. A few hours before writing this post, it was so bad I
   22 could only maintain a wifi connection for about 10 seconds before it would fail
   23 and not even try to reconnect for about five minutes.
   24 
   25 [[the-problem]]
   26 The Problem
   27 ~~~~~~~~~~~
   28 
   29 After puzzling through the issue, it occured to me what it must have
   30 been: conflicting mac addresses.
   31 
   32 I checked my wife's and my phones and sure enough, their mac addresses were
   33 identical, specifically **00:90:4c:c5:12:38**. I did some Googling and found
   34 many other people to have the same issue in varying versions and roms of
   35 Android. After some hunting, I found a
   36 http://forum.cyanogenmod.org/topic/105128-wifi-bug-cm12/[temporary fix], but
   37 the fix was for a different phone, which stored its config files in a different
   38 location (oddly). I did a bit of digging through the filesystem (+find /system
   39 -type f -exec grep -H macaddr "\{}" \;+) and finally found the file that needed
   40 to be modified for my phone/version of Android. For reusability purposes, I
   41 also turned this into a _fairly_ friendly script so other folks can do it too.
   42 
   43 Note though that this issue is very obscure and the likelyhood of seeing is it
   44 slim. Only people running at least two phones with this bug at the same time
   45 and on the same wifi network will experience this issue. This is why my phone
   46 operated fine for months until I put CyanogenMod on my wife's phone and she
   47 connected to our wifi. Further (to the credit of the CM and the various other
   48 Android devs out there), this problem would be tremendously difficult for a dev
   49 to track down because it is only problematic with two or more phones, something
   50 I doubt most devs are testing at the same time with.
   51 
   52 [[the-fix-script]]
   53 The Fix Script
   54 ~~~~~~~~~~~~~~
   55 
   56 This script needs to be run as root to work correctly (if you don't run it as
   57 root, it'll complain at you and exit). Once you've run this script as root,
   58 simply reboot your phone and your new mac address will take effect.
   59 
   60 ----
   61 #!/system/xbin/bash
   62 
   63 # Ensure we are running as root, because this won't work otherwise.
   64 uid=$(id | sed -n 's/uid=\([0-9]\+\).*/\1/p')
   65 if [[ ${uid} != 0 ]]; then
   66   echo "Not running as root. Cannot proceed. Exiting..."
   67   exit 1
   68 fi
   69 
   70 echo "Remounting /system with write access so we can make the modification."
   71 mount -o remount,rw /system
   72 
   73 # The path to the wlan cal file
   74 cal_path=/system/etc/wifi/bcmdhd.cal
   75 
   76 # Don't need this, but might be handy to have documented
   77 #old_mac=00:90:4c:c5:12:38
   78 
   79 # Generate the new mac address
   80 new_mac=$(printf '00:90:4c:%02x:%02x:%02x\n' $[RANDOM%256] $[RANDOM%256] $[RANDOM%256])
   81 
   82 # Sed expression to replace the mac address with something less problematic
   83 sed -i "s/macaddr=.*/macaddr=${new_mac}/" ${cal_path}
   84 
   85 echo "Your new mac address is ${new_mac}."
   86 ----
   87 
   88 I personally placed this on my internal storage at /storage/sdcard0/mac_fix.sh.
   89 To execute it, as root just run...
   90 
   91 ----
   92 bash /storage/sdcard0/mac_fix.sh
   93 ----
   94 
   95 Note the preceeding call to the bash command. Ordinarily you would be able to
   96 set the execute bit on the script and directly call it. However, Android
   97 defaults to setting the noexec mount option for the sdcard filesystems (both
   98 sdcard0 and sdcard1), thus chmod +x doesn't work. This could be worked around
   99 in the script, but it would make it longer and I don't see the need for it. :)
  100 
  101 
  102 // vim: set syntax=asciidoc:

Generated by cgit