My Wiki!

*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:

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

  1. szym PhD blog post about making adhoc available with Android:

http://szym.net/2010/12/adhoc-wifi-in-android/

  • setup ad-hoc with wpacli from olsrd site http://www.olsr.org/?q=olsr_on_android ====== Wifi in Android ====== Have a look at wifi source code: - Wifi framwork: $ADRSRC/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 wpasuplicant.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 wpasupplicant.

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 wpasupplicant8:

  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

  1. In wpasupplicant8 change the wpa_supplicatn/events.c file :

static struct wpassid * wpascanresmatch(struct wpasupplicant *wpas,

                                          int i, struct wpa_scan_res *bss,
                                          struct wpa_ssid *group) {

….

if (bss→caps & IEEE80211CAPIBSS) { wpadbg(wpas, 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 wpasupplicant (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 wpasupplicant 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 wpasupplicant in your BoardConfig.mk 2. (Optional) Enable debug for wpasupplicant. 3. Provide a proper wpasupplicant.conf for your device 4. Have the correct paths and permissions created from init.rc 5. Make sure your wpasupplicant 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 wpasupplicant commands and SIOCSIWPRIV ioctl Now onto details. 0. Understand how Android WiFi works. Android uses a modified wpasupplicant ( external/wpasupplicant ) daemon for wifi support which is controlled through a socket by hardware/libhardwarelegacy/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/androidnetwifiWifi.cppHigher level network management is done in frameworks/base/core/java/android/net 1. Enable building of wpasupplicant in your BoardConfig.mk This is by simply adding: BOARDWPASUPPLICANTDRIVER := WEXT to your BoardConfig.mk . This will set WPABUILDSUPPLICANT to true in external/wpasupplicant/Android.mk enabling building ofdriverwext.c If you have a custom wpasupplicant 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 wpasupplicant. By default wpasupplicant is set to MSGINFO that doesn't tell much. To enable more messages: 2.1 modify common.c and set wpadebuglevel = MSGDEBUG

2.2 modify common.h and change #define wpa_printf from if ((level) >= MSG_INFO) to if ((level) >= MSG_DEBUG)

3. Provide a proper wpasupplicant.conf for your device Providing a wpasupplicant.conf it's important because the control socket for android is specified in this file (ctrlinterface= ). This file should be copied by your AndroidBoard.mk to $(TARGETOUTETC)/wifi(usually /system/etc/wifi/wpasupplicant.conf ). This location will be used on wpasupplicant service from init.rc. There are two different ways in which wpasupplicant can be configured, one is to use a “private” socket in android namespace, created by socketlocalclientconnect() function in wpactrl.c and another is by using a standard unix socket. Minimum required config options in wpasupplicant.conf : - Android private socket ctrlinterface=wlan0 updateconfig=1 - Unix standard socket ctrlinterface=DIR=/data/system/wpasupplicant GROUP=wifi updateconfig=1

Depending on your driver you might also want to add: apscan=1 If you have AP association problems with should change to apscan=0 to let the driver do the association instead of wpasupplicant. If you want to let wpasupplicant connect to non-WPA or open wireless networks (by default it skips these kind) add:

network={ key_mgmt=NONE }

  1. Have the correct permissions and paths created from init.rc Incorrect permisions will result in wpasupplicant not being able to create/open the control socket andlibhardwarelegacy/wifi/wifi.c won't connect. Since Google modified wpasupplicant to run as wifi user/group the directory structure and file ownership should belong to wifi user/group (see osprograminit() function in wpasupplicant/osunix.c ). Otherwise errors like: E/WifiHW ( ): Unable to open connection to supplicant on “/data/system/wpasupplicant/wlan0”: No such file or directory will appear. Also wpasupplicant.conf should belong to wifi user/group because wpasupplicant will want to modify this file. If your system has /system as read-only use a location like /data/misc/wifi/wpasupplicant.conf and modify wpasupplicant 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/wpasupplicant.conf chown wifi wifi /system/etc/wifi/wpasupplicant.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/wpasupplicant.conf chown wifi wifi /data/misc/wifi chown wifi wifi /data/misc/wifi/wpasupplicant.conf

If you use a Unix standard socket in wpasupplicant.conf (see above) add: # wpasupplicant socket (unix socket mode) mkdir /data/system/wpasupplicant 0771 wifi wifi chmod 0771 /data/system/wpasupplicant chown wifi wifi /data/system/wpasupplicant Do not add these if you use Android private socket because it will make wpasupplicant non-functional, becausehardware/libhardwarelegacy/wifi/wifi.c check for existence of the/data/system/wpasupplicant folder and will pass a wrong interface name to wpactrlopen()function. 5. Make sure your wpasupplicant and dhcpcd are starting from init.rc For wpasupplicant the init.rc startup like should be depending on which path you chosen: - Android private socket: service wpasupplicant /system/bin/wpasupplicant -dd -Dwext -iwlan0 -c /system/etc/wifi/wpasupplicant.conf socket wpawlan0 dgram 660 wifi wifi group system wifi inet disabled oneshot - Unix standard socket: service wpasupplicant /system/bin/wpasupplicant -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

  1. Provide your driver either as a module or built in kernel and proper kernel support for it. First make sure that CONFIGPACKET and CONFIGNETRADIO (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. WIFIDRIVERMODULEPATH := 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
    1. WIFIDRIVERMODULENAME:= the name of the network interface that the driver creates, for example wlan0 3. WIFIDRIVERMODULEARG:= 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/libhardwarelegacy/wifi/wifi.c about the name of the interface, that the driver is already loaded and set the status of wpasupplicant to running: setprop wifi.interface “wlan0” setprop wlan.driver.status “ok”

Do NOT add setprop init.svc.wpasupplicant “running” as I previously mentioned as it will prevent wpasupplicant from starting from init. - Secondly hardware/libhardwarelegacy/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 checkdriverloaded()function. You might encounter problems with WifiHW module not being able to connect to wpasupplicant 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 handlefirmwareevent()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 wpasupplicant 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/wpasupplicant( ): wpadriverprivdrivercmd failed wpadriverprivdrivercmd RSSI len = 4096 E/wpasupplicant( ): wpadriverprivdrivercmd failed D/wpasupplicant( ): wpadriverprivdrivercmd LINKSPEED len = 4096 E/wpasupplicant( ): wpadriverprivdrivercmd failed I/wpasupplicant( ): CTRL-EVENT-DRIVER-STATE HANGED After 4, WEXTNUMBERSEQUENTIALERRORS errors, android will abort using the device. To quickly test your wifi from interface you can disable error checking inexternal/wpasupplicant/driverwext.c by simply making ret = 0; inwpadriverprivdrivercmd() 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 driverxxx.c to google external/wpasupplicant/ implementingwpadriverprivdrivercmd() 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 driverwext.c. Below is a link to a patch for wpasupplicant 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: BOARDWPASUPPLICANTDRIVER := AWEXT 2. Change init.rc wpasupplicant service command line by replacind -Dwext with -Dawext AWEXT driver patch download: androidwextemulationdriverawext.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/wpasupplicant/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 wpasupplicant 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 wpasupplicant debug): D/wpasupplicant( 843): Initializing interface 'wlan0' conf '/system/etc/wifi/wpasupplicant.conf' driver 'awext' ctrlinterface 'N/A' bridge 'N/A' D/wpasupplicant( 843): Configuration file '/system/etc/wifi/wpasupplicant.conf' → '/system/etc/wifi/wpasupplicant.conf' D/wpasupplicant( 843): Reading configuration file '/system/etc/wifi/wpasupplicant.conf' D/wpasupplicant( 843): ctrlinterface='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 registeredservices drwxrwxrwx wifi wifi 2000-01-01 00:00 wpasupplicant -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.WIFISTATECHANGED D/SettingsWifiEnabler( 985): Received wifi state changed from Disabled to Enabling D/WifiService( 802): ACTIONBATTERYCHANGED pluggedType: 1 E/WifiHW ( 802): Unable to open connection to supplicant on “/data/system/wpasupplicant/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.WIFISTATECHANGED E/WifiHW ( 802): Unable to open connection to supplicant on “/data/system/wpasupplicant/wlan0”: No such file or directory E/WifiHW ( 802): Unable to open connection to supplicant on “/data/system/wpasupplicant/wlan0”: No such file or directory I/StatusBarPolicy( 802): received intent android.intent.action.TIMETICK E/WifiHW ( 802): Unable to opeinit: no such service 'dhcpcdwlan0' n connection to supplicant on “/data/system/wpasupplicant/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.CONNECTIONCHANGE I/StatusBarPolicy( 802): received intent android.net.wifi.WIFISTATECHANGED 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 wpasupplicant -iwlan0 -c/system/etc/wifi/wpasupplicant.conf -ddI/StatusBarPolicy( 802): received intent android.intent.action.TIMETICK D/wpasupplicant( 989): Initializing interface 'wlan0' conf '/system/etc/wifi/wpasupplicant.conf' driver 'default' ctrlinterface 'N/A' bridge 'N/A' D/wpasupplicant( 989): Configuration file '/system/etc/wifi/wpasupplicant.conf' → '/system/etc/wifi/wpasupplicant.conf' D/wpasupplicant( 989): Reading configuration file '/system/etc/wifi/wpasupplicant.conf' E/wpasupplicant( 989): Failed to read or parse configuration '/system/etc/wifi/wpasupplicant.conf'. D/wpasupplicant( 989): Failed to add interface wlan0 D/wpasupplicant( 989): Cancelling scan request D/wpasupplicant( 989): Cancelling authentication timeout

I/StatusBarPolicy( 802): received intent android.intent.action.TIME_TICK

cat /system/etc/wifi/wpa_supplicant.conf

ctrlinterface=DIR=/data/system/wpasupplicant GROUP=wifi update_config=1


Navigation