====== *Android adhoc* ======
===== start adhoc network with ip and iwconfig =====
==== Disable Connectivity manager ====
* turn wi-fi off form settings. 'lsmod' will show that module bcm4329.ko is unloaded. This can also be done with 'svc'
to see full help:
svc
control wifi:
svc wifi enable
svc wifi disable
* enable this module again and you will get full control over the wlan-iface:
busybox insmod /system/modules/bcm4329.ko firmware_path=/system/vendor/firmware/fw_bcm4329.bin nvram_path=/system/vendor/firmware/nvram_net.txt
Attention*: Kernel modules in Android 4 (Cyanogen 9) have moved to /system/lib/modules/
=== see also: ===
using wpa_supplicant manually:
http://htc-linux.org/wiki/index.php?title=LeoWifi#AP_Mode
==== set ip addr with ip ====
ip l s wlan0 down
ip a a(dd) 192.168.1.100/24 broadcast 192.168.1.255 dev wlan0
ip a d(el) 192.168.1.100/24 dev wlan0
iwconfig wlan0 mode Ad-Hoc/Managed
iwconfig wlan0 essid my-adhoc-net
ip l s wlan0 up
====== Adhoc network with Android ======
- szym PhD blog post about making adhoc available with Android:
http://szym.net/2010/12/adhoc-wifi-in-android/
- setup ad-hoc with wpa_cli from olsrd site
http://www.olsr.org/?q=olsr_on_android
====== Wifi in Android ======
Have a look at wifi source code:
- Wifi framwork: $ADR_SRC/frameworks/base/wifi
- Setting apps: $ADR_SRC/packages/apps/Settings
source: http://groups.google.com/group/android-platform/browse_thread/thread/fcc3621462eee289/a47f411f01e98c68?lnk=gst&q=ad-hoc#a47f411f01e98c68
====== Editing wpa_supplicant.conf on Android ======
source: http://hydtechblog.com/tag/wpa_supplicant-conf/
This tablet is not like other android devices which are easily connected to adhoc by editing the tiwlan.ini and wpa_suplicant.conf. In fact, there is no tiwlan file on the device. We will have to use an alternate method, however, we will still be patching our wpa_supplicant.
The first step is to make an adhoc connection from your phone, laptop or desktop and name the ssid as ‘droidhoc’ and make sure you do not use a WEP key (it causes unnecessary problems). Set your ip address to static and use 192.168.0.1 (or you can use dhcp, but sometimes this causes problems). If you set static, then make sure you use a static IP, like 192.168.0.2, on your device under advanced settings. Set the mask to 255.255.255.0 and dns to 192.168.0.1.
The next step is to connect the gpad with adb and I will assume you know how to do that.
now we will type the following:
su (for superuser mode)
mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system (mount partition as writable)
cp /data/misc/wifi/wpa_supplicant.conf /sdcard/ (copy configuration file to sdcard)
exit (to exit out of adb)
adb pull /sdcard/wpa_supplicant.conf / (pull the file off the sdcard to edit it)
Now edit the file with your text editor and enter the following after the line ctrl_interface=DIR=/data/system/wpa_supplicant GROUP=system:
eapol_version=2
update_config=1
ap_scan=2
network={
ssid="droidhoc"
scan_ssid=1
key_mgmt=NONE
group=WEP104
auth_alg=OPEN SHARED
priority=99
mode=1
}
Place the wpa_supp file back and change owner, permissions and reboot:
adb push /wpa_supplicant.conf /sdcard/wpanew.conf
adb shell
su
cp /sdcard/wpanew.conf /data/misc/wifi/wpa_supplicant.conf
cd /data/misc/wifi
chown wifi.wifi wpa_supplicant.conf
chmod 777 wpa_supplicant.conf
reboot
Once your phone is rebooted, we will download the HydTech’s adhoc wifi app from the market and run it.(app costs only $1.99)
Enjoy your new adhoc connection!
====== enable ad-hoc with wpa-supplicant ======
I have made following changes in to my android source code make ad-hoc wifi connection in Android 4.0 with wpa_supplicant_8:
1. In WifiSettings.java file comment the code that does not allow to display IBSS type of stations:
// Ignore hidden and ad-hoc networks.
if (result.SSID == null || result.SSID.length() == 0) { // ||
//result.capabilities.contains(“[IBSS]“)) {
continue;
}
Location of that file is packages/apps/Settings/src/com/android/settings/wifi
2. In wpa_supplicant_8 change the wpa_supplicatn/events.c file :
static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
int i, struct wpa_scan_res *bss,
struct wpa_ssid *group) {
….
if (bss->caps & IEEE80211_CAP_IBSS) {
wpa_dbg(wpa_s, MSG_DEBUG, “ skip – IBSS (adhoc) “
“network”);
//continue; //Allow IBSS connection.
}
….
}
After making the above changes i was able to connect to ad-hoc stations. ( i have tried with my tethered iphone). Another method to make ad-hoc connection is add the network information in wpa_supplicant.conf file.
====== right description for Android adhoc problem ======
http://www.android-hilfe.de/root-hacking-modding-fuer-samsung-galaxy/6522-ad-hoc-wifi-print.html
Ad-hoc wifi
Hallo,
ich wollte mal ad-hoc WLAN-Netze angehen (für Tethering etc.); hab mir dazu die wireless_tools compiled, vor allem iwconfig ist nützlich. iwlist funktioniert leider nicht, ist aber verschmerzbar. Link: http://static.volatilevoid.net/wirel...android.tar.gz
Mit
iwconfig eth0 mode ad-hoc
iwconfig eth0 essid whatever
ifconfig eth0 192.168.0.1
kann man prinzipiell mit einem ad-hoc-Netz verbinden. Hab als Gegenstelle den Laptop schon in der richtigen Konfiguration gehabt und ein ping laufen lassen, das hat auch ein paar mal funktioniert. Prinzipiell gehts also.
Das Problem ist allerdings, dass offenbar wpa_supplicant (oder irgendwas anderes) im Hintergrund ständig wieder auf managed mode zurückschaltet, sodass die Verbindung wenn überhaupt immer nur kurz zustande kommt. Wenn man wpa_supplicant abschießt, ist auch das Interface weg und im Menü steht WLAN als disabled.
Ich hab auch probiert, das ad-hoc-Netz in /data/misc/wifi/bcm_supp.conf einzutragen; es wird dann zwar in der Liste angezeigt, aber immer als außer Reichweite und ich kann nicht verbinden.
Hat irgendwer eine Idee, wie man dem Android-Framework die WLAN-Verwaltung wegnehmen kann? Bei den HTC-Geräten gibts ja tiwlan.ini, aber beim Galaxy nicht.
====== wpa_supplicant ======
Wednesday, August 11, 2010
source: http://blog.linuxconsulting.ro/2010/04/porting-wifi-drivers-to-android.html
Porting WiFi drivers to Android
Update (11/08/2010): Updated patch to fix the loading of awext driver at run time.
Added STOP and RESTART commands.
For mini-box.com picoPC we want to support several USB and miniPCI WiFi dongles, this guide provides a step by step explanation of what's involved in adding a new wifi driver and making wifi work in a custom Android build (this guide was written for android 2.1 but should be applicable to previous android releases and hopefully future releases).
Contents
0. Understand how Android WiFi works.
1. Enable building of wpa_supplicant in your BoardConfig.mk
2. (Optional) Enable debug for wpa_supplicant.
3. Provide a proper wpa_supplicant.conf for your device
4. Have the correct paths and permissions created from init.rc
5. Make sure your wpa_supplicant and dhcpcd (optional) are starting from init.rc
6. Provide your driver either as a module or built in kernel and proper kernel support for it and modify Android source code accordingly.
7. Provide a firmware if your module needs it.
8. Make your driver work with Android custom wpa_supplicant commands and SIOCSIWPRIV ioctl
Now onto details.
0. Understand how Android WiFi works.
Android uses a modified wpa_supplicant ( external/wpa_supplicant ) daemon for wifi support which is controlled through a socket by hardware/libhardware_legacy/wifi/wifi.c (WiFiHW) that gets controlled from Android UI through android.net.wifi package from frameworks/base/wifi/java/android/net/wifi/and it's corresponding jni implementation in frameworks/base/core/jni/android_net_wifi_Wifi.cppHigher level network management is done in frameworks/base/core/java/android/net
1. Enable building of wpa_supplicant in your BoardConfig.mk
This is by simply adding: BOARD_WPA_SUPPLICANT_DRIVER := WEXT to your BoardConfig.mk . This will set WPA_BUILD_SUPPLICANT to true in external/wpa_supplicant/Android.mk enabling building ofdriver_wext.c
If you have a custom wpa_supplicant driver (like madwifi or my custom android private commands emulation - see last paragraph) you can replace WEXT with AWEXT or your driver name (MADWIFI, PRISM etc).
2. (Optional) Enable debug for wpa_supplicant.
By default wpa_supplicant is set to MSG_INFO that doesn't tell much.
To enable more messages:
2.1 modify common.c and set wpa_debug_level = MSG_DEBUG
2.2 modify common.h and change #define wpa_printf from if ((level) >= MSG_INFO) to if ((level) >= MSG_DEBUG)
3. Provide a proper wpa_supplicant.conf for your device
Providing a wpa_supplicant.conf it's important because the control socket for android is specified in this file (ctrl_interface= ). This file should be copied by your AndroidBoard.mk to $(TARGET_OUT_ETC)/wifi(usually /system/etc/wifi/wpa_supplicant.conf ). This location will be used on wpa_supplicant service from init.rc.
There are two different ways in which wpa_supplicant can be configured, one is to use a "private" socket in android namespace, created by socket_local_client_connect() function in wpa_ctrl.c and another is by using a standard unix socket.
Minimum required config options in wpa_supplicant.conf :
- Android private socket
ctrl_interface=wlan0
update_config=1
- Unix standard socket
ctrl_interface=DIR=/data/system/wpa_supplicant GROUP=wifi
update_config=1
Depending on your driver you might also want to add:
ap_scan=1
If you have AP association problems with should change to ap_scan=0 to let the driver do the association instead of wpa_supplicant.
If you want to let wpa_supplicant connect to non-WPA or open wireless networks (by default it skips these kind) add:
network={
key_mgmt=NONE
}
4. Have the correct permissions and paths created from init.rc
Incorrect permisions will result in wpa_supplicant not being able to create/open the control socket andlibhardware_legacy/wifi/wifi.c won't connect.
Since Google modified wpa_supplicant to run as wifi user/group the directory structure and file ownership should belong to wifi user/group (see os_program_init() function in wpa_supplicant/os_unix.c ).
Otherwise errors like:
E/WifiHW ( ): Unable to open connection to supplicant on "/data/system/wpa_supplicant/wlan0": No such file or directory will appear.
Also wpa_supplicant.conf should belong to wifi user/group because wpa_supplicant will want to modify this file. If your system has /system as read-only use a location like /data/misc/wifi/wpa_supplicant.conf and modify wpa_supplicant service in init.rc with new location.
Make sure the paths are correctly created in init.rc:
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
If you use a Unix standard socket in wpa_supplicant.conf (see above) add:
# 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
Do not add these if you use Android private socket because it will make wpa_supplicant non-functional, becausehardware/libhardware_legacy/wifi/wifi.c check for existence of the/data/system/wpa_supplicant folder and will pass a wrong interface name to wpa_ctrl_open()function.
5. Make sure your wpa_supplicant and dhcpcd are starting from init.rc
For wpa_supplicant the init.rc startup like should be depending on which path you chosen:
- Android private socket:
service wpa_supplicant /system/bin/wpa_supplicant -dd -Dwext -iwlan0 -c /system/etc/wifi/wpa_supplicant.conf
socket wpa_wlan0 dgram 660 wifi wifi
group system wifi inet
disabled
oneshot
- Unix standard socket:
service wpa_supplicant /system/bin/wpa_supplicant -dd -Dwext -iwlan0 -c /system/etc/wifi/wpa_supplicant.conf
group system wifi inet
disabled
oneshot
If your wifi driver creates a wifi interface with other name than wlan0 you will have to modify the above line accordingly.
You also should have dhcpcd starting from init.rc
service dhcpcd /system/bin/dhcpcd wlan0
group system dhcp
disabled
oneshot
6. Provide your driver either as a module or built in kernel and proper kernel support for it.
First make sure that CONFIG_PACKET and CONFIG_NET_RADIO (wireless extensions) are enabled in your kernel. The driver can be built as module (default android way) or built in kernel (if you want to rely in kernel auto probing to support multiple driver eg. USB wifi) but will require source code modifications (see below).
- As kernel module:
Define in your BoardConfig.mk :
1. WIFI_DRIVER_MODULE_PATH := path to the module to be loaded
You need to specify module name in that path too, usually should look something like /system/lib/modules/wlan.ko
2. WIFI_DRIVER_MODULE_NAME:= the name of the network interface that the driver creates, for example wlan0
3. WIFI_DRIVER_MODULE_ARG:= any arguments that you want to pass to the driver on insmod, for example nohwcrypt
Make sure you copy your kernel module when building android to the correct location.
- As built in kernel:
- First init.rc needs to be modified to inform hardware/libhardware_legacy/wifi/wifi.c about the name of the interface, that the driver is already loaded and set the status of wpa_supplicant to running:
setprop wifi.interface "wlan0"
setprop wlan.driver.status "ok"
Do NOT add setprop init.svc.wpa_supplicant "running" as I previously mentioned as it will prevent wpa_supplicant from starting from init.
- Secondly hardware/libhardware_legacy/wifi/wifi.c need to be modified so the functions insmod()and rmmod() return 0 (simply add return 0; as the first line in functions since they are not needed when driver is built in kernel) and return before checking for /proc/modules in check_driver_loaded()function.
You might encounter problems with WifiHW module not being able to connect to wpa_supplicant socket even with the correct permisions. Try to turn off / turn on Wifi from the GUI.
7. Provide a firmware if your driver needs it
If your driver needs a firmware you will have to copy this firmware file to /etc/firmware on your android build. Android doesn't use a standard hotplug binary (although there is an implementation available on android-x86system/code/toolbox/hotplug.c ) instead the init process takes care of firmware events and loads the firmware file from /etc/firmware (see: system/core/init/devices.c handle_firmware_event()function).
Firmware file name is defined by the driver and might also contain a folder like: RTL8192SU/rtl8192sfw.bin, entire file path should be available in /etc/firmware
8. Make your driver work with Android custom wpa_supplicant commands and SIOCSIWPRIV ioctl.
Android uses SIOCSIWPRIV ioctl to send commands to modify driver behaviour and receive information like signal strength, mac address of the AP, link speed etc. This ioctl is usually not implemented in any known wireless drivers except bcm4329 which is in google msm kernel branch .
The errors from not having this ioctl implemented will look like:
E/wpa_supplicant( ): wpa_driver_priv_driver_cmd failed wpa_driver_priv_driver_cmd RSSI len = 4096
E/wpa_supplicant( ): wpa_driver_priv_driver_cmd failed
D/wpa_supplicant( ): wpa_driver_priv_driver_cmd LINKSPEED len = 4096
E/wpa_supplicant( ): wpa_driver_priv_driver_cmd failed
I/wpa_supplicant( ): CTRL-EVENT-DRIVER-STATE HANGED
After 4, WEXT_NUMBER_SEQUENTIAL_ERRORS errors, android will abort using the device.
To quickly test your wifi from interface you can disable error checking inexternal/wpa_supplicant/driver_wext.c by simply making ret = 0; inwpa_driver_priv_driver_cmd() function after the SIOCSIWPRIV ioctl call. This will make all access points in android UI appear without signal or MAC address.
To proper implement the ioctl you will need to modify your kernel driver to reply to SIOCSIWPRIV ioctl with RSSI (signal strength) and MACADDR commands being the most important.
A better way is to add a custom driver_xxx.c to google external/wpa_supplicant/ implementingwpa_driver_priv_driver_cmd() function that will take care of RSSI, MACADDR and others, through calls to SIOCGIWSTATS, SIOCGIFHWADDR ioctls, with the rest of the functions being called from driver_wext.c.
Below is a link to a patch for wpa_supplicant that I did for mini-box.com picoPC Android build. It creates a new driver awext which "emulates" android driver commands using wireless extensions ioctls.
How to use the new driver:
1. In your BoardConfig.mk define: BOARD_WPA_SUPPLICANT_DRIVER := AWEXT
2. Change init.rc wpa_supplicant service command line by replacind -Dwext with -Dawext
AWEXT driver patch download: android_wext_emulation_driver_awext.patch
Labels: android
posted by panic @ 11:39 AM
22 Comments:
At May 10, 2010 8:23 AM , yonathana said...
Hi,
Was trying the same but have been facing some errors. E/WifiHW ( ): Unable to open connection to supplicant on "/data/system/wpa_supplicant/wlan0"
Even though i have added permissions as mentioned. Would like to compare my files with yours. Would you mind sharing a copy of the modified files ?
Thanks
Yonathana
At May 10, 2010 9:36 AM , panic said...
Add a chown wifi wifi on the folders and verify with ls -l /data/system/ on console. I placed the files here:
http://www.linuxconsulting.ro/android/files/wifi/
At May 10, 2010 12:41 PM , panic said...
Also try to turnoff/turnon wifi, maybe wpa_supplicant hasn't yet created the socket. I've seen this on my build.
You should see something similar to this in logcat (if you enabled wpa_supplicant debug):
D/wpa_supplicant( 843): Initializing interface 'wlan0' conf '/system/etc/wifi/wpa_supplicant.conf' driver 'awext' ctrl_interface 'N/A' bridge 'N/A'
D/wpa_supplicant( 843): Configuration file '/system/etc/wifi/wpa_supplicant.conf' -> '/system/etc/wifi/wpa_supplicant.conf'
D/wpa_supplicant( 843): Reading configuration file '/system/etc/wifi/wpa_supplicant.conf'
D/wpa_supplicant( 843): ctrl_interface='wlan0'
At May 10, 2010 5:24 PM , yonathana said...
This is what i did panic : drop both your files in the respective dir and cross check in the rfs if they are same
Check permissions of
s -l /data/system
-rw-rw-r-- system system 35326 2000-01-01 00:00 packages.xml
-rw------- system system 8 2000-01-01 00:01 syncmanager.prefs
drwxrwx--x system system 2000-01-01 00:00 registered_services
drwxrwxrwx wifi wifi 2000-01-01 00:00 wpa_supplicant
-rw------- system system 4096 2000-01-01 00:00 entropy.dat
-rw------- system system 171 2000-01-01 00:00 wallpaper_info.xml
-rw-rw---- system system 16384 2000-01-01 00:00 accounts.db
-rw------- system system 604 2000-01-01 00:00 batterystats.bin
drwx------ system system 2000-01-01 00:00 usagestats
-rw------- system system 64 2000-01-01 00:00 appwidgets.xml
I/ActivityManager( 802): Starting activity: Intent { act=android.intent.action.MAIN cmp=com.android.settings/.WirelessSettings }
D/dalvikvm( 802): GC freed 9763 objects / 499352 bytes in 96ms
I/ActivityManager( 802): Displayed activity com.android.settings/.WirelessSettings: 556 ms (total 556 ms)
W/WifiHW ( 802): Could not open /proc/modules: No such file or directory
I/StatusBarPolicy( 802): received intent android.net.wifi.WIFI_STATE_CHANGED
D/SettingsWifiEnabler( 985): Received wifi state changed from Disabled to Enabling
D/WifiService( 802): ACTION_BATTERY_CHANGED pluggedType: 1
E/WifiHW ( 802): Unable to open connection to supplicant on "/data/system/wpa_supplicant/wlan0": No such file or directory
D/SettingsWifiEnabler( 985): Received wifi state changed from Enabling to Enabled
I/StatusBarPolicy( 802): received intent android.net.wifi.WIFI_STATE_CHANGED
E/WifiHW ( 802): Unable to open connection to supplicant on "/data/system/wpa_supplicant/wlan0": No such file or directory
E/WifiHW ( 802): Unable to open connection to supplicant on "/data/system/wpa_supplicant/wlan0": No such file or directory
I/StatusBarPolicy( 802): received intent android.intent.action.TIME_TICK
E/WifiHW ( 802): Unable to opeinit: no such service 'dhcpcdwlan0'
n connection to supplicant on "/data/system/wpa_supplicant/wlan0": No such file or directory
V/WifiStateTracker( 802): Supplicant died unexpectedly
E/WifiStateTracker( 802): Could not stop DHCP
D/NetworkStateTracker( 802): setDetailed state, old =IDLE and new state=DISCONNECTED
D/ConnectivityService( 802): ConnectivityChange for WIFI: DISCONNECTED/DISCONNECTED
I/EthernetService( 802): setEthState from 2 to 2
init: no such service 'dhcpcdwlan0'
D/SettingsWifiEnabler( 985): Received wifi state changed from Enabled to Disabling
I/StatusBarPolicy( 802): received intent android.net.wifi.supplicant.CONNECTION_CHANGE
I/StatusBarPolicy( 802): received intent android.net.wifi.WIFI_STATE_CHANGED
Am i at loss of ideas, Any clues what could be wrong ?
At May 10, 2010 5:32 PM , yonathana said...
Also when i do a command line init as soon as system boots
wpa_supplicant -iwlan0 -c/system/etc/wifi/wpa_supplicant.conf -ddI/StatusBarPolicy( 802): received intent android.intent.action.TIME_TICK
D/wpa_supplicant( 989): Initializing interface 'wlan0' conf '/system/etc/wifi/wpa_supplicant.conf' driver 'default' ctrl_interface 'N/A' bridge 'N/A'
D/wpa_supplicant( 989): Configuration file '/system/etc/wifi/wpa_supplicant.conf' -> '/system/etc/wifi/wpa_supplicant.conf'
D/wpa_supplicant( 989): Reading configuration file '/system/etc/wifi/wpa_supplicant.conf'
E/wpa_supplicant( 989): Failed to read or parse configuration '/system/etc/wifi/wpa_supplicant.conf'.
D/wpa_supplicant( 989): Failed to add interface wlan0
D/wpa_supplicant( 989): Cancelling scan request
D/wpa_supplicant( 989): Cancelling authentication timeout
# I/StatusBarPolicy( 802): received intent android.intent.action.TIME_TICK
# cat /system/etc/wifi/wpa_supplicant.conf
ctrl_interface=DIR=/data/system/wpa_supplicant GROUP=wifi
update_config=1