[X Play Q&A, Help & Troubleshooting] RoDeltaLambda:
Wifi problems and fixes

I've still not found a solution for myself, but I figured I still can give some tips for people with problems, especially considering how confusing is to get information about this.

This is a work in progress. I would gladly receive corrections and new info.

Before anything, do a backup. Even if your wifi does not work, it can save you from a lot of problems. Remember to backup the persist folder, a lot of automated recoveries don't make a backup of that folders because it's supposed to survive flashes but there's ways in which you can do it by mistake. It also helps a lot with bug hunting.

Things you should have already tried:

Plane mode on, reboot, wifi on and plane mode off

Network settings reset in android and reboot

Rebooted to safemode (longpress in power off when turning phone off]

Factory reset in android

Removal of SD and SIM cards

Factory reset in recovery

Flash Stock ROM in RDSlite

Unlock bootloader

Activate developer mode and set usb debug on

Installed custom recovery

Clean Flash stock ROM trough fastboot

Flash custom Kernels

Things you need:

adb and fastboot

usb drivers for the phone

Optional Text editor that preserves text format (avoid notepad and MS word)

Optional Busybox for extended commands in android shell (root required)

Optional If you're in windows and want to mess with adb: A decent console to work with.

Option A: cash with cmder

Install cmder

Install NodeJs

Install cash tipping in cmd npm install cash-global -g (after NodeJs)

Option B: babun

http://babun.github.io/

optional Open text editor for easy copy-paste of long paths and commands

optional Hex editor if you want to edit .bin files. I use XVI32

Useful console commands (In windows you need one of the optional shells described above)

List files and folders

ls -la [path to list]

Find file/folder in linux (and android shell)

find / -iname '*[word you're looking]*'

* are 'wildcards', they allow for matching any text (or no text at all)

you can add, before -iname, -type f (for files) or -type d (for folders)

Symlink

It's an alternative of copying files. this allows you to simulate having a file in two different places, but really all paint to one. Modifications in this source are going to affect all the links, so it's easier to configure. Android does this a lot.

ln -s [path to] [from]

Copy files and folders

cp [-R if you want to move folders] [path to source] [path to target]

logcat for essential wifi messages (short-colored) If someone know more, please let me know

adb logcat -v brief -v color WifiSerice:V WifiHW:V WifiStateMachine:V FileUtils:V QSEECOMAPI:V *:S

change owners and permissions

the flag -R makes the command work for files and subfolders

chown user:group [path to file or folder]
chmod [num of user][num of group][num of all] [path to file or folder] [SIZE="2"](e.g. chmod 660 /persist/WCNSS_qcom_wlan_nv.bin)[/SIZE]

grep

This one is awesome; It's for filtering the results of any command, so you can use it for filtering.

[command you want to filter] | grep -i [term you're looking for]

For example, [adb logcat] gives you a huge list of messages, but [adb logcat | grep -i wifi] gives you just the lines that contain 'wifi'

From my experience, this are the common folders related to wifi configs:

/persist/
/system/etc/firmware/wlan/prima/
/system/etc/wifi/
/data/misc/wifi/

Command list for do a full clean flash:

please note that system.img_sparsechunk can vary in number according to ROM, but I've put 9 in here because failed commands don't write to phone

note: fastboot flash partition gpt.bin works perfectly when used first, but for me it's failing when I erase system and boot first.

fastboot erase system -w
fastboot erase boot
fastboot erase fsg
fastboot flash partition gpt.bin
fastboot flash bootloader bootloader.img
fastboot flash logo logo.bin
fastboot flash boot boot.img
fastboot flash recovery recovery.img
fastboot flash system system.img_sparsechunk.0
fastboot flash system system.img_sparsechunk.1
fastboot flash system system.img_sparsechunk.2
fastboot flash system system.img_sparsechunk.3
fastboot flash system system.img_sparsechunk.4
fastboot flash system system.img_sparsechunk.5
fastboot flash system system.img_sparsechunk.6
fastboot flash system system.img_sparsechunk.7
fastboot flash system system.img_sparsechunk.8
fastboot flash system system.img_sparsechunk.9
fastboot flash modem NON-HLOS.bin.
fastboot erase modemst1
fastboot erase modemst2
fastboot flash fsg fsg.mbn
fastboot erase cache
fastboot erase userdata
fastboot erase customize
fastboot erase clogo
fastboot reboot (or reboot-bootloader)

Important: Every time you flash, do a clean wipe. In fastboot this usually means using erase system -w and erase boot before flashing.

Be aware that for getting the logcat your phone must be booted to android OS.

Be aware that for copying and modifying important files you must access the phone's shell either in recovery mode or switching to root with the command (su) that's only accesible if you're rooted.

Ok. If you made it this far you're probably losing your mind. To debug this, especially if you're going to post asking for help, get the catlog of your phone and/or a precise description to look for clues to your problem (I have a command ready for you above).

Here's some common solutions I've found while trying to solve my own problem: (Credits to the authors of the solutions)

Bad permissions/users

These appear to be correct or usable permissions for relevant files. Consider that there's a lot of fragmentation in this info so they might be wrong.

Confirmation of these would be great:

-rwxrwx--- wifi wifi /system/etc/wifi
-rw-rw---- wifi wifi /system/etc/wifi/wpa_supplicant.conf
-rwxrwx--- wifi wifi /data/misc/wifi
-rwxrwx--- wifi wifi /data/misc/wifi/sockets
-rw-rw---- wifi wifi /data/misc/wifi/wpa_supplicant.conf
-rw-rw---- system:wifi /data/misc/wifi/WCNSS_qcom_cfg.ini
-rw-rw---- wifi wifi WCNSS_qcom_wlan_nv.bin
-rw-rw---- root root WCNSS_wlan_dictionary.dat

-rwxrwx--- is 770, -rw-rw---- is 660

Is reported in some places that the parent folder of wpa_supplicant.conf should be -rw-rw---- wifi wifi

Missing or badly configured wpa_supplicant.conf

The solution is place a new copy of the file in the correct folders. If someone has a 'oficial' source or more info let me know

I remember reading that some people had success deleting the file so the SO rebuilds it. Do it to your discretion and remember to backup

Missing WCNSS files

These files are essential and must be in the correct paths for wifi drivers to load.

There's a lot of different sources for this files, but from my experiencie they don't change a lot (last commits are more than one year old).

Files in oficial source repository from motorola

These posts have info and files

http://xdaforums.com/showthread.php?t=2589790

http://xdaforums.com/showpost.php?p=48861415&postcount=19

Paths of relevant files. Please consider that not just because it's here means you need it

/persist/WCNSS_qcom_wlan_nv.bin
/persist/WCNSS_qcom_wlan_factory_nv.bin
/persist/WCNSS_qcom_wlan_dictionary.dat
/system/etc/firmware/wlan/prima/WCNSS_qcom_cfg.ini
/system/etc/firmware/wlan/prima/WCNSS_cfg.dat
/system/etc/firmware/wlan/prima/WCNSS_qcom_wlan_nv.bin
/system/etc/firmware/wlan/prima/WCNSS_qcom_wlan_dictionary.dat
/system/etc/firmware/wlan/prima/WCNSS_qcom_wlan_factory_nv.bin
/data/misc/wifi/WCNSS_qcom_cfg.ini
/data/misc/wifi/wpa_supplicant.conf

Missing /persist/drm/widevine and/or /persist/prov

Check this two posts:

http://xdaforums.com/showthread.php?t=2589790

http://xdaforums.com/showpost.php?p=48861415&postcount=19

In there you can find backups to get the folders, restore them to /persist/ and check permissions.

Bad MAC address in WCNSS_qcom_wlan_nv.bin

Sometimes the file WCNSS_qcom_wlan_nv.bin needs to be updated with the correct mac address.

Since it's a .bin file, it cannot be changed with a text editor. You need to use a hex editor (XVI32 link is in 'things you need' above).

The mac address starts at 'A' (since is hex) or, more simply, after 10 'cells'. Be aware that in this editor changes get 'inserted' instead of modified, so you have to delete the initial 6 addresses of the old mac.

Put the file back, and check permissions. There's two copies of this file: one in /persist/ and another in /system/etc/firmware/wlan/prima/ change one or both according with your situation

Some logcat messages and details about them

For getting more messages about wifiHW you need a userdebug build like CyanogenMod. Stock roms don't log wifiHW.

WifiStateMachine: failed to load driver

WCNSS_qcom_cfg.ini and/or WCNSS_cfg.dat is missing somewhere. In my case this was missing from /system/etc/wifi.

wcnss_service: CAL file not found

This refers to the calibration file. The source of wcnss-service.c defines this file as "WCNSS_qcom_wlan_cal.bin" in the path "/data/misc/wifi/WCNSS_qcom_wlan_cal.bin". however, source show that CAL file is not used if the factory file is present. Source in link gives this address '"/data/misc/wifi/WCN_FACTORY" which is weird because from posts in xda this file has the name "CNSS_qcom_wlan_factory_nv.bin" I'll update if I have more info

Info for nerds:

How android Wifi works:

https://community.freescale.com/docs/DOC-93603

source code for wifi opt framework - android 6.0.1 r22

source code for wifi qcom framework - android 6.0.1 r22