Mini210 WiFi - keep active

Dave McLaughlin
Hi all,

Anyone using the Mini210 with Android?

I have an issue with the WiFi on this board. It won't remain active unless
I have an application open (browser for instance) all the time. If there is
no application using the network, it stops working.

If I power down the board and power it back up again, the WiFi is not
started. I have to go into the WiFi settings to re-enable the WiFi. The AP
is in the list and it shows that it is obtaining an IP address but it sits
like this forever until I click on it. At this point the WiFi is now
connected.

I need to have the WiFi remain active all the time and it needs to auto
connect on rebooting. This should be possible as my phone does this.

Dave...

Dave McLaughlin
As an update to my information above I have this in the debug output from
the time that I press a button to wake it up from sleep.

[179757.151879] request_suspend_state: wakeup (3->0) at 179756504900287
(2012-07-29 10:48:08.531187160 UTC)
[179757.152684] s3cfb_late_resume is called
[179757.152965] FIMD src sclk = 166750000
[179757.304500] s3cfb_late_resume is complete
[179758.203948] ADDRCONF(NETDEV_UP): wlan0: link is not ready

It stays on the last line until I enter the WiFi settings page and click on
the APN and choose connect. When I do the following appears in the debug
and the screen shows that it is now connected.

[179977.874706] ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready

What I am after now is how to get it to always connect on wakeup or at
power up.

Dave...

Reggie
I have also seen similar behaviour with the SDIO wifi card, I would also
like to see a resolution :)  I'll take a look later and see if there's an
setting on the card that will sort it out.

Reggie
I've been doing some further investigations, it appears that the issue
comes from the fa-network-service application which is run for the ethernet
adapter.  I believe it's either conflicting with the wifi dhcpcd service or
there is something else i don't quite understand going on.

Basically, if you comment out the fanetworkservice section in init.rc (in
the root of your android fs) and then reboot the system, the wifi should
startup and correctly get an ip address from the router.

It all centres around the fa-network-service app, not sure entirely what
the mechanism is but the fanetworkservice calls dhcpcd early before the
wifi modules are loaded, the dhcpcd service that's setup in
/init.mini210.rc fails to get an ip address, probably because it's already
being run via the fanetworkservice call.

It appears that it needs fixing somehow in fa-network-service app so that
it looks for wlan0 and does dhcp for it or we disable the fanetwork service
and create a script of some sort that looks to see whether the dm9000 is
enabled and let the dhcpcd service in init.mini210.rc deal with eth0 as
well.

I've had a crazy little thought that perhaps setting ethernet to static IP
might solve the issue.

Regards,
Reggie.

Reggie
done some further testing and setting the ethernet to static ip also solves
the issue and allows the wifi dhcpcd service to run correctly and get an ip
address without the need to edit any init scripts.

This really needs resolving in fa-network-services, I think there are some
conf files that relate to fa-network-services in /data/system/ called
fa_ethernet.conf and fanetwork.conf, there isn't any documention to them at
all though so we have no way of setting it up correctly if it's possible.

Dave McLaughlin
Nice work Reggie. I'll have a play around with it tomorrow and see what
this does.

At least we have a starting point to look at the source.

All my parts should be arriving next week so I am keen to get this working
so that I can test the rest of the system and the GPIO, battery charger
etc.

Dave...

Reggie
Thanks Dave, a little more investigation tells me that setting a static IP
doesn't quite work, you still need to do:
ifconfig eth0 down

otherwise all traffic gets routed via the unconnected ethernet IP.  So,
it's really back to disabling the fanetworkservice service in init.rc, what
we really need is a little app. to toggle these things, enable/disable
services.  Not really sure what you'd do if you needed to use both ethernet
and wifi at the same time, although I guess, when you're at that level of
messing around then you're really going to be looking at pre-configuring
everything instead of letting android/fanetworkservice mangle everything?

btw. I have been testing this on android 2.3 and 4 images, it's a common
issue and hasn't been resolved, ideally we need friendly arm to publish
either the fa-network-service source code or the documentation on how to
use it, or they need to rewrite it so that it tracks and uses the android
wifi settings implementation.

I've not really delved into android and it's useage but it seems to me that
we should really be using it's settings somewhere along the line, if we can
query the system and place settings in the appropriate .db files we should
be able to do simple getprop/setprop stuff to work out what's going on with
the ethernet and proceed accordingly.

Reggie
Further investigation has led me to believe that this is a common problem
with android and not just a mini210S issue, it appears that android just
doesn't like dhcp for  wifi and ethernet at the same time.

I've also noticed that android uses a 'thing' called 'toolbox', this seems
to be a very cut down version of busybox, with cutdown features and output
for most of the apps. we use on a normal linux system.

To check this out take a look at ifconfig, do the following at the command
line:
  ifconfig eth0
then do:
  busybox ifconfig eth0

I've just checked and we're using a standalone version of dhcpcd but there
is a busybox version but the interesting thing is that dhcpcd can actually
cope with 2 interfaces, if you start 2 instances of it.

Dave McLaughlin
Hi Reggie,

I have been playing around with this today and I have disabled the
fa_network settings in the init.rc file.

I run my test application which calls the wifi.reconnect to get it to
connect to the AP but in the debug output over ADB I can see a message,
Failed to initiate AP scan. The tag is wpa_supplicant

This is because the WiFi itself is powered down at some point within the
power control part of the OS. I am trying to work out where this happens
and I am logging the LogCat output to have a look through it later.

From the debug port I can get the WiFi to come up with ifconfig wlan0 up as
per your previous posting.

Reggie
I haven't attached adb to it properly yet, I've just been messing with the
mini210S and seeing if there was anything particularly obvious.  It's
fairly clear that it's fa-network-service that's causing the issues, if you
disable it and deal with dhcpcd calls to ethernet and wlan0 manually then
it all works fine, it seems that fa-network-service needs to deal with wifi
as well, taking into account whether the ethernet is enabled and *not* call
dhcpcd if it's disabled, although it really needs fa-network-service
calling later?  Either that or make fa-network-service *only* deal with
anything related to ethernet and make sure it doesn't touch anything else
and leave it in a correct state.

Dave McLaughlin
Hi Reggie,

I have been trying out some ideas tonight. So far I can keep the WiFi
active as long as send data over it and within the 5 mins that it seems to
be going into the power down state.

I have a broadcast receiver now that gets WiFi state but I can't find any
way to make the WiFi come up if I detect that it is down. From the debug
port I can type ifconfig wlan0 up. I just need to see how to do this from
Java code.

The full power wake lock also works and the screen stays on. Same with
partial wake lock, the WiFi keeps on as long as I send data. The screen in
this state powers down but the app keeps running in the background. This is
what I need for this system.

If I can get the WiFi to power up from code or better still, the OS does it
when an app tries to use TCP/IP then I have what I need.

Reggie
you should be able to tell the wifi to stay active in the settings
somewhere.  As for ifconfig, if you look in the init.rc and
init.mini210S.rc files then you should be able to see how they setup
services, you can do a oneshot, or you can setup a listener to look for
settings that change, although, you'd have to deal with someone
legitimately disabling the wifi.

Also, if you want bash history, edit /etc/init.mini210.sh, it appears that
you just need to setup bash history commands as usual but don't put the =
sign in the export for example:
export HISTFILE /.bash_history

Dave McLaughlin
Hi Reggie,

The WiFi is set in the advanced settings to stay alive on external power
but as you have seen, if there is no network activity, it simply powers
down.

My device is designed to run one app for data logging and stay in the
foreground. If someone does put it into the background, I detect this and
bring it back to the foreground. I also listen for WiFi changes and make
sure it is always active if WiFi is the chosen connection.

I am getting closer and it ran all night until 9:20 this morning and at
that time, it has stopped the WiFi. Need to check it later to find out why
but as it's the weekend, I am not allowed to play with my toys until Monday
now :o)

Cheers.

Reggie
I noticed that my system just goes into standby at some point, can't
remember if it's on gingerbread or ice cream sandwich, either way, screen
goes blank, serial console tells me something about it disabling the
console and then the mini210S becomes impossible to wake up.  I think you
can setup a wake_lock in /proc/ or /sys/ to stop it ever going to sleep,
perhaps you're getting that issue?  

I also cannot reboot 100% reliably, it's 40/60 whether it will reboot
properly or not, when it doesn't, the wifi light stays on, so I'm guessing
it doesn't properly shutdown everything, it gets to the uncompressing
kernel stage and fails but doesn't give any indication at all why, just
freezes at that point it would appear.  bringing down the sdio wifi card
before rebooting doesn't make a difference either unfortunately.

Yehuda Alon
We have a similar requirement - use WiFi (DHCP) and a local Ethernet (fixed
IP, on another network) under Android 4.0.4
It seems as if you guys have worked around the existing limitation. Is
there a simple 'cook book' how to do it ?