andreasgal / B2G

Boot to Gecko aims to create a complete, standalone operating system for the open web.
https://wiki.mozilla.org/B2G
907 stars 158 forks source link

wifi isn't working on Galaxy S II #19

Closed joneschrisg closed 13 years ago

joneschrisg commented 13 years ago

There's a message about not being able to find a /system/etc/wifi/bcm[something].cfg file, and after that there are error messages from the wpa_supplicant. Wifi acts like it's enabled, but no scans succeed.

andreasgal commented 13 years ago

A bunch of vendor files are missing

From a clean device:

~/workspace/android-sdk-mac_x86/platform-tools/adb pull /system/etc/wifi/bcm4330_aps.bin . ~/workspace/android-sdk-mac_x86/platform-tools/adb pull /system/etc/wifi/bcm4330_mfg.bin ~/workspace/android-sdk-mac_x86/platform-tools/adb pull /system/etc/wifi/bcm4330_mfg.bin_b0 ~/workspace/android-sdk-mac_x86/platform-tools/adb pull /system/etc/wifi/bcm4330_sta.bin ~/workspace/android-sdk-mac_x86/platform-tools/adb pull /system/etc/wifi/bcm4330_sta.bin_b0 ~/workspace/android-sdk-mac_x86/platform-tools/adb pull /system/etc/wifi/iwmulticall ~/workspace/android-sdk-mac_x86/platform-tools/adb pull /system/etc/wifi/nvram_mfg.txt ~/workspace/android-sdk-mac_x86/platform-tools/adb pull /system/etc/wifi/nvram_mfg.txt_b0 ~/workspace/android-sdk-mac_x86/platform-tools/adb pull /system/etc/wifi/nvram_mfg.txt_murata ~/workspace/android-sdk-mac_x86/platform-tools/adb pull /system/etc/wifi/nvram_net.txt ~/workspace/android-sdk-mac_x86/platform-tools/adb pull /system/etc/wifi/nvram_net.txt_b0 ~/workspace/android-sdk-mac_x86/platform-tools/adb pull /system/etc/wifi/nvram_net.txt_murata ~/workspace/android-sdk-mac_x86/platform-tools/adb pull /system/etc/wifi/nvram_net_02K.txt ~/workspace/android-sdk-mac_x86/platform-tools/adb pull /system/etc/wifi/nvram_net_02K.txt_b0 ~/workspace/android-sdk-mac_x86/platform-tools/adb pull /system/etc/wifi/wifi.conf ~/workspace/android-sdk-mac_x86/platform-tools/adb pull /system/etc/wifi/wl ~/workspace/android-sdk-mac_x86/platform-tools/adb pull /system/etc/wifi/wpa_supplicant.conf

Then on B2G

mount -o remount,rw /system

and

~/workspace/android-sdk-mac_x86/platform-tools/adb push bcm4330_aps.bin /system/etc/wifi ~/workspace/android-sdk-mac_x86/platform-tools/adb push bcm4330_mfg.bin /system/etc/wifi ~/workspace/android-sdk-mac_x86/platform-tools/adb push bcm4330_mfg.bin_b0 /system/etc/wifi ~/workspace/android-sdk-mac_x86/platform-tools/adb push bcm4330_sta.bin /system/etc/wifi ~/workspace/android-sdk-mac_x86/platform-tools/adb push bcm4330_sta.bin_b0 /system/etc/wifi ~/workspace/android-sdk-mac_x86/platform-tools/adb push iwmulticall /system/etc/wifi ~/workspace/android-sdk-mac_x86/platform-tools/adb push nvram_mfg.txt /system/etc/wifi ~/workspace/android-sdk-mac_x86/platform-tools/adb push nvram_mfg.txt_b0 /system/etc/wifi ~/workspace/android-sdk-mac_x86/platform-tools/adb push nvram_mfg.txt_murata /system/etc/wifi ~/workspace/android-sdk-mac_x86/platform-tools/adb push nvram_net.txt /system/etc/wifi ~/workspace/android-sdk-mac_x86/platform-tools/adb push nvram_net.txt_b0 /system/etc/wifi ~/workspace/android-sdk-mac_x86/platform-tools/adb push nvram_net.txt_murata /system/etc/wifi ~/workspace/android-sdk-mac_x86/platform-tools/adb push nvram_net_02K.txt /system/etc/wifi ~/workspace/android-sdk-mac_x86/platform-tools/adb push nvram_net_02K.txt_b0 /system/etc/wifi ~/workspace/android-sdk-mac_x86/platform-tools/adb push wifi.conf /system/etc/wifi ~/workspace/android-sdk-mac_x86/platform-tools/adb push wl /system/etc/wifi ~/workspace/android-sdk-mac_x86/platform-tools/adb push wpa_supplicant.conf /system/etc/wifi

Reboot and wpa_supplicant starts crashing. A wpa_supplicant from a production rom crashes as well, so something else must be wrong. Here is the crash btw:

E/WifiHW ( 2683): Supplicant not running, cannot connect E/WifiHW ( 2683): Supplicant not running, cannot connect V/WifiStateTracker( 2683): Supplicant died unexpectedly D/WifiStateTracker( 2683): Reset connections and stopping DHCP W/dalvikvm( 2683): threadid=27: thread exiting with uncaught exception (group=0x4001e560) E/AndroidRuntime( 2683): *\ FATAL EXCEPTION IN SYSTEM PROCESS: ConnectivityThread E/AndroidRuntime( 2683): java.lang.NullPointerException E/AndroidRuntime( 2683): at android.net.wifi.WifiStateTracker.resetConnections(WifiStateTracker.java:1447) E/AndroidRuntime( 2683): at android.net.wifi.WifiStateTracker.handleMessage(WifiStateTracker.java:972) E/AndroidRuntime( 2683): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime( 2683): at android.os.Looper.loop(Looper.java:130) E/AndroidRuntime( 2683): at com.android.server.ConnectivityService$ConnectivityThread.run(ConnectivityService.java:232)

andreasgal commented 13 years ago

This looks like a permission issue.

The current config is read from /data/misc/wifi and /data/system/, and the wpa_supplicant runs as user wifi and it seems the java part can't attach to the socket.

http://blog.linuxconsulting.ro/2010/04/porting-wifi-drivers-to-android.html

The driver and the wpa_supplement exec are ok otherwise. Still trying to make it work.

andreasgal commented 13 years ago

Alright, so android really wants to talk to wpa_supplicant at

E/WifiHW ( 4340): Unable to open connection to supplicant on "/data/system/wpa_supplicant/eth0": No such file or directory

but all the config is in /data/misc/wifi (including eth0), so all we really need is a link

from /data/misc/wifi to /data/system/wpa_supplicant

I also added some stuff to init.rc while experimenting but thats likely not needed:

mkdir /system/etc/wifi 0770 wifi wifi chmod 0770 /system/etc/wifi chmod 0660 /system/etc/wifi/wpa_supplicant.conf chown wifi wifi /system/etc/wifi/wpa_supplicant.conf

wpa_supplicant control socket for android wifi.c (android private socket)

mkdir /data/misc/wifi 0770 wifi wifi mkdir /data/misc/wifi/sockets 0770 wifi wifi chmod 0770 /data/misc/wifi chmod 0660 /data/misc/wifi/wpa_supplicant.conf chown wifi wifi /data/misc/wifi chown wifi wifi /data/misc/wifi/wpa_supplicant.conf

wpa_supplicant socket (unix socket mode)

mkdir /data/system/wpa_supplicant 0771 wifi wifi chmod 0771 /data/system/wpa_supplicant chown wifi wifi /data/system/wpa_supplicant

someone should reproduce this with minimal steps and post them here @cgjones?

andreasgal commented 13 years ago

Something is still wonky, dhcp fails, but I get network scans and the PSK auth completes

V/WifiStateTracker( 5008): Changing supplicant state: SCANNING ==> DORMANT

andreasgal commented 13 years ago

Yeah its dhcpcd

E/WifiStateTracker( 5008): DHCP request failed: Timed out waiting for dhcpcd to start

andreasgal commented 13 years ago

I can bring up the interface by hand and it works just fine (PSK works too)

ifconfig eth0 192.168.1.120 netmask 255.255.255.0 route 192.168.1.1 up

dhcpcd still doesn't like me, but this should be fixable

there is definitely nothing wrong with the supplicant

shianyow commented 13 years ago

I can reproduce the issue of wpa_supplicant crash with following message: "Unable to open connection to supplicant on "/data/system/wpa_supplicant/eth0": No such file or directory"

The reason is, wpa_supplicant created control socket at /data/misc/wifi but libhardware_legacy/wifi/wifi.c connecting it at /data/system/wpa_supplicant.

One solution is to modify libhardware_legacy/wifi/wifi.c to use correct path. But for simplicity and to avoid further compatibility issues, it should be better to use proprietary library "libhardware_legacy.so" from a original S2 device. After replacing with "libhardware_legacy.so" pulled from original S2 device, the wpa_supplicant worked properly.

andreasgal commented 13 years ago

Nice diagnosis. Thank you. mrbkap, can you take a look? We should pull the library off the device when we configure and then put it in the right spot.

shianyow commented 13 years ago

Again, it seems we have to use "libnetutils.so" from original S2 device. This library provides utilities for managing DHCP client daemon.

Now the whole wifi is working on my S2.

andreasgal commented 13 years ago

This is really sad, I have no idea what Samsung was thinking. For now it probably makes sense to use the custom binaries from the device and not mess with this. @mrbkap?

shianyow commented 13 years ago

Below are files needed from original S2 device to make wifi working on my S2.

  1. BCM wifi driver and configuration /system/etc/wifi/bcm4330_aps.bin /system/etc/wifi/bcm4330_mfg.bin /system/etc/wifi/bcm4330_sta.bin /system/etc/wifi/nvram_mfg.txt /system/etc/wifi/nvram_net.txt /system/etc/wifi/wifi.conf /system/etc/wifi/wpa_supplicant.conf

    Note: not sure if all files in /system/etc/wifi are necessary, but it works for me with above.

  2. To fix wpa_supplicant crash issue /system/lib/libhardware_legacy.so
  3. To fix dhcpcd request timeout issue /system/lib/libnetutils.so
mrbkap commented 13 years ago

I basically did what shianyow said in https://github.com/cgjones/android_device_samsung_galaxys2/commit/10b8906d123e8e50998c789bad46607e0fc4368a

andreasgal commented 13 years ago

Did you merge your changes? I don't see them in the tree.

joneschrisg commented 13 years ago

After the merge, I get this error running |make config-galaxy-s2|

remote object '/system/etc/wifi/bcm4330_aps.bin' does not exist Failed to pull bcm4330_aps.bin. Giving up.

Was that file needed? I'll try removing it from extract-files.sh tomorrow.

joneschrisg commented 13 years ago

After removing the _aps.bin file and reflashing, I get http://pastebin.mozilla.org/1370728 in logcat, and my sgs2 stays hung at the start screen ("yellow triangle"). Looks like netd is failing to start and preventing the startup process from succeeding.

joneschrisg commented 13 years ago

Fixed my problems in 046c243471e81b56c67bb37538da5373e3d0294e (firmware too old). Let's close this out now.

ChewyLV commented 12 years ago

Can anyone guide me how to fix this porblem on 2.3.4 XXKI4?