5

I can start wpa_supplicant just fine through adb shell. The firmware and stuff for my WiFi radio is all loaded before this.

However, I want to start it via execv() in a C program. When I execute execv(), I get the following error:

E/wpa_supplicant( 3008): Failed to initialize control interface 'wlan0'.
E/wpa_supplicant( 3008): You may have another wpa_supplicant process already running or the file was
E/wpa_supplicant( 3008): left by an unclean termination of wpa_supplicant in which case you will need
E/wpa_supplicant( 3008): to manually remove this file before starting wpa_supplicant again.
I/wpa_supplicant( 3008): ELOOP: remaining socket: sock=15 eloop_data=0xa5320 user_data=0x0 handler=0x6acd9

I also have this in the serial console:

mkdir[ctrl_interface]: Permission denied

The full strace ouput is here: http://pastebin.com/fuQnqjXK

Here's the strace output snippet of interest:

2380  mkdir("wlan0", 0770)              = -1 EACCES (Permission denied)
2380  write(2, "mkdir[ctrl_interface]", 21) = 21
2380  write(2, ": ", 2)                 = 2
2380  write(2, "Permission denied", 17) = 17
2380  write(2, "\n", 1)                 = 1

Also, here's the logcat snippet. I've already verified that there's no wpa_supplicant running in the background, and the file that is created when wpa_supplicant is successfully run (/data/misc/wifi/wlan0/wlan0) does not exist. Are there other files that wpa_supplicant is creating?

D/wpa_supplicant( 3627): wpa_supplicant v0.8.x
D/wpa_supplicant( 3627): random: Trying to read entropy from /dev/random
D/wpa_supplicant( 3627): Initializing interface 'wlan0' conf '/data/misc/wifi/wpa_supplicant.conf' driver 'nl80211' ctr
_interface 'N/A' bridge 'N/A'
D/wpa_supplicant( 3627): Configuration file '/data/misc/wifi/wpa_supplicant.conf' -> '/data/misc/wifi/wpa_supplicant.co
f'
D/wpa_supplicant( 3627): Reading configuration file '/data/misc/wifi/wpa_supplicant.conf'
D/wpa_supplicant( 3627): update_config=1
D/wpa_supplicant( 3627): ctrl_interface='wlan0'
D/wpa_supplicant( 3627): eapol_version=1
D/wpa_supplicant( 3627): ap_scan=1
D/wpa_supplicant( 3627): fast_reauth=1
D/wpa_supplicant( 3627): config_methods='push_button keypad display'
D/wpa_supplicant( 3627): device_name='U8500'
D/wpa_supplicant( 3627): default_bgscan='learn:60:-70:300:10:20:/data/misc/wifi/wpa_supplicant_bgscan.db'
D/wpa_supplicant( 3627): wmm_enabled=1
D/wpa_supplicant( 3627): uapsd_enabled=1
D/wpa_supplicant( 3627): nl80211: interface wlan0 in phy phy0
I/wpa_supplicant( 3627): rfkill: Cannot open RFKILL control device
D/wpa_supplicant( 3627): nl80211: RFKILL status not available
D/wpa_supplicant( 3627): nl80211: Set mode ifindex 5 iftype 2 (STATION)
D/wpa_supplicant( 3627): netlink: Operstate: linkmode=1, operstate=5
D/wpa_supplicant( 3627): nl80211: Using driver-based off-channel TX
D/wpa_supplicant( 3627): nl80211: driver param='(null)'
D/wpa_supplicant( 3627): wapi_initialization()
D/wpa_supplicant( 3627): wlan0: Own MAC address: 00:80:e1:c2:89:9a
D/wpa_supplicant( 3627): Country: 00
D/wpa_supplicant( 3627): wpa_driver_nl80211_set_key: ifindex=5 alg=0 addr=0x0 key_idx=0 set_tx=0 seq_len=0 key_len=0
D/wpa_supplicant( 3627): wpa_driver_nl80211_set_key: ifindex=5 alg=0 addr=0x0 key_idx=1 set_tx=0 seq_len=0 key_len=0
D/wpa_supplicant( 3627): wpa_driver_nl80211_set_key: ifindex=5 alg=0 addr=0x0 key_idx=2 set_tx=0 seq_len=0 key_len=0
D/wpa_supplicant( 3627): wpa_driver_nl80211_set_key: ifindex=5 alg=0 addr=0x0 key_idx=3 set_tx=0 seq_len=0 key_len=0
D/wpa_supplicant( 3627): wlan0: RSN: flushing PMKID list in the driver
D/wpa_supplicant( 3627): nl80211: Flush PMKIDs
D/wpa_supplicant( 3627): wlan0: State: DISCONNECTED -> INACTIVE
I/wpa_supplicant( 3627): WPS: Converting display to virtual_display for WPS 2.0 compliance
I/wpa_supplicant( 3627): WPS: Converting push_button to virtual_push_button for WPS 2.0 compliance
D/wpa_supplicant( 3627): nl80211: Regulatory information - country=00
D/wpa_supplicant( 3627): nl80211: 2402-2472 @ 40 MHz
D/wpa_supplicant( 3627): nl80211: 2457-2482 @ 20 MHz
D/wpa_supplicant( 3627): nl80211: 2474-2494 @ 20 MHz
D/wpa_supplicant( 3627): nl80211: 5170-5250 @ 40 MHz
D/wpa_supplicant( 3627): nl80211: 5735-5835 @ 40 MHz
D/wpa_supplicant( 3627): nl80211: Added 802.11b mode based on 802.11g information
D/wpa_supplicant( 3627): WPS: Set UUID for interface wlan0
E/wpa_supplicant( 3627): WPS: UUID based on MAC address - hexdump(len=16): b2 15 b7 6a cb d7 55 cf b9 d4 3e 8c 40 ae 2d
30
D/wpa_supplicant( 3627): EAPOL: SUPP_PAE entering state DISCONNECTED
D/wpa_supplicant( 3627): EAPOL: Supplicant port status: Unauthorized
D/wpa_supplicant( 3627): EAPOL: KEY_RX entering state NO_KEY_RECEIVE
D/wpa_supplicant( 3627): EAPOL: SUPP_BE entering state INITIALIZE
D/wpa_supplicant( 3627): EAP: EAP entering state DISABLED
D/wpa_supplicant( 3627): EAPOL: Supplicant port status: Unauthorized
D/wpa_supplicant( 3627): EAPOL: Supplicant port status: Unauthorized
E/wpa_supplicant( 3627): Failed to initialize control interface 'wlan0'.
E/wpa_supplicant( 3627): You may have another wpa_supplicant process already running or the file was
E/wpa_supplicant( 3627): left by an unclean termination of wpa_supplicant in which case you will need
E/wpa_supplicant( 3627): to manually remove this file before starting wpa_supplicant again.
D/wpa_supplicant( 3627): Failed to add interface wlan0
D/wpa_supplicant( 3627): wlan0: No keys have been configured - skip key clearing
D/wpa_supplicant( 3627): wlan0: State: INACTIVE -> DISCONNECTED
D/wpa_supplicant( 3627): wpa_driver_nl80211_set_operstate: operstate 0->0 (DORMANT)
D/wpa_supplicant( 3627): netlink: Operstate: linkmode=-1, operstate=5
D/wpa_supplicant( 3627): EAPOL: External notification - portEnabled=0
D/wpa_supplicant( 3627): EAPOL: Supplicant port status: Unauthorized
D/wpa_supplicant( 3627): EAPOL: External notification - portValid=0
D/wpa_supplicant( 3627): EAPOL: Supplicant port status: Unauthorized
D/wpa_supplicant( 3627): wlan0: No keys have been configured - skip key clearing
D/wpa_supplicant( 3627): wlan0: Cancelling scan request
D/wpa_supplicant( 3627): wlan0: Cancelling authentication timeout
D/wpa_supplicant( 3627): nl80211: Set TX rates failed: ret=-22 (Invalid argument)
D/wpa_supplicant( 3627): netlink: Operstate: linkmode=0, operstate=6
D/wpa_supplicant( 3627): nl80211: Set mode ifindex 5 iftype 2 (STATION)
I/wpa_supplicant( 3627): ELOOP: remaining socket: sock=15 eloop_data=0xa5320 user_data=0x0 handler=0x6acd9

Anyone can hint to me what I might be doing wrong? Permissions?

9
  • have you tried to 'strace -f' your problem? Seems like you start it from an app, right? You probably need to start it as root.
    – ce4
    Sep 12, 2012 at 7:35
  • I'm starting it from a C program (let's call it myapp) that I compiled for ARM, and myapp is from init.rc as a replacement to console (a bit of a hack really) so I can't really strace -f right? When I do a ps myapp, it shows myapp running as root.
    – terencey
    Sep 12, 2012 at 8:35
  • you could do that as well (and write stderr of 'strace' to some /tmp folder to read it later). What I guess is: wpa_supplicant needs some location where it can store some tmp stuff to. You are launching it too early maybe and there's everything still read-only accessible. You can do a manual 'strace -f' just to see where it wants to write to.
    – ce4
    Sep 12, 2012 at 8:43
  • Thanks ce4. But how do I do that? Using execv and strace? By the way, when I do a ps in adb shell after getting the mkdir[ctrl_interface]: Permission denied, I get wpa_supplicant running as user wifi. I suppose I must force wpa_supplicant to run as root? ps wpa_supplicant USER PID PPID VSIZE RSS WCHAN PC NAME wifi 2611 1426 0 0 c009c348 00000000 Z wpa_supplicant
    – terencey
    Sep 12, 2012 at 9:34
  • Use strace just by doing a 'strace -f myapp' with your parent C program (-f is for following childs).
    – ce4
    Sep 12, 2012 at 11:32

1 Answer 1

3

I managed to find the answer, although I don't really understand why or how. If anyone can add on to why working directory matters, I will greatly appreciate it.

In my C program, I have to do a chdir() to /data/misc/wifi, then do the execvp().

if (chdir("/data/misc/wifi") == -1) {
    perror("chdir");
    return;
}

pid = fork();
if (pid == -1) {
    perror("Error forking process");
}
else if (pid != 0) {
    return;
}
execvp("/system/bin/wpa_supplicant", wpaparmlist);

where wpaparmlist is the args to wpa_supplicant.

Thanks for your help ce4!

1
  • Maybe wpa_supplicant checks if it's run from within a terminal or forked by another program - or- you recently launched it in the /sdcard folder where it has also all rights to modify files / mkdir.
    – ce4
    Sep 13, 2012 at 11:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .