Showing posts with label ethernet. Show all posts
Showing posts with label ethernet. Show all posts

Thursday, November 29, 2012

How Wifi/ethernet/3G  service is working in android:
===================================


   1) while bootup, connectivity service will launch all networking services.
 
In android, most of the system services cant be directly interactable by user applications/any other medium.
 Every service will have a manager which will talks with service. For example, To interact with connectivity service, Connectivity manager is available. User/application will query for the available network connections from Connectivity manager.

   In the same way, wifi manager is available for Wifi service, Window manager is available for Window service and so on.
During bootup, System server launches connectivity service.connectivity service launches/initiates wifi/3G/ethernet services.

     To receive whether the link is up or down, ethernet connection is connected or disconnected, we will receiving notifications from
framework.[android_net_wifi.cpp/android_net_   ] This framework file watches for network connectivity by reading /proc or sys file system.

    if wifi is available then under proc/net/wireless/wlan0 interface will be created. So the framework will waits for proc/net/wireless/ file for any changes.
    More over we will get notifications from driver on link up or down information. Once the link is up, it will be updated to Mobile/Wifi/ethernet trackers. These trackers will query for the network information like DHCP IP address,netmask and so on from DHCP service/dhcp daemon.
  
   Once the wifi/mobile state tracker got an IP address and necessary information about the network it update to Connectivity manager.
Meanwhile it will also update the Wifi/Ethernet manager which will talks to wifi/ethernet/3G services  .
    
    UpdateConnectivity of connectivity manager is being called to update the CONNECTED /DISCONNECTED network information to connectivity service.
 
   while user application queries for connected network information from connectivity manager, Connectivity manager will get this information from connectivity service.
     If multiple network connections are available, Connectivity service will decides which one to choose for network connection.
For example, if we have 3G connection, we reached into Wifi area, Wifi can download more data compare to 3G. So Wifi connection will be selected for network connection, 3G connection will be teared down.
    Every network has priority based on priority it will choose the desired connection.

  In linux and all, Ethernet/Wifi connection is possible at the same time. But the kernel will make use of any one interface[wifi/ethernet] at a time.

   wifi state tracker will make use of DHCP daemon to get dhcp ip address. For Dhcp request, Some class is available which will calls system/core/libnetutils library. which will talks to dhcp daemon initiated from init.rc.

           This DHCP daemon will query the ip address and set the IP address,netmask information in system properties [dhcp.wifi.ipaddress,dhcp.wifi.netmask]. If the Wifi state tracker doesnt receive any dhcp response for a particular timeout period, it will report timed out error. If dhcp reply is received it will reads Ip address and netmask from the given interface and update it on settings.
     CONNECTIVITY_ACTION is an intent which will be used to update the network information from connectivity manager/service.
  

Friday, November 23, 2012

Problem in static IP:
===============


I ported the android x86 ethernet support to android board.
I used the same kernel to run ICS and jellybean OS.
I faced  the problem in setting static IP. while switching from DHCP to Static IP, entire system hangs.
 Ethernet patch is storing the value in Settings. while reading the value from settings and setting the static IP, it hangs...
Since ethernet is configured in bootup time, system hangs and doesnt proceed booting android.

    I analysed and found that providers/settings data will be stored in /data/data/com.android.settings.provider/settings.db.
All android applications/providers database values will be stored under /data/data/com.android.ApplicationName.
To clear the settings value, we can format /data/ partition , So that stored information will be deleted.
Now I am able to proceed with booting android.
   But still problem is there while setting static IP.I doubted the network environments/OS/my program.

  1)Through ifconfig, I am able to set static IP address. So there is no problem in network environment.    
  2) I doubted IP settings are not allowd in jellybean, any  new services have been added to change IP address. Since I am using same kernel, there wont be any changes in kernel level.
  3) I doubted my entire program is not working. But same code was previously working with ICS.

Previously with ICS, I am able to set static IP and tested well.Same code is not working. I doubted my static Ip setting itself is not working.
 To narrow down the issue, I hardcoded the netmask value, afterwards it is able to set static IP.
  In my code, I debugged and found that it is hanging in netmask to prefix conversion which is required for setting static IP address.

 Lessons Learnt:  1) All android applications store data/database values under /data/data/com.android.ApplicationName[Package name of the android]
  2) Always document the sample inputs/environments for success cases, So in future, if the system is failing, we can try with that input.
  3) always test lower limit and upper limit values... System hangs since It is failed in lower limit

 Please refer my previous post about netmask to prefix conversion problem.
http://sundararajana.blogspot.in/2012/11/netmask-prefix-length-netmask-is-also.html




   

Sunday, October 14, 2012

Circular Dependency:

I added new xml to settings due to that I got "Stack overflow error" in android runtime,Settings application was not launched.
        Added xml file is ic_settings_ethernet.xml.





 

ic_settings_ethernet.xml contents:
=======================

https://groups.google.com/forum/?fromgroups=#!msg/rowboat/lP65eylKHkQ/flHykmz15xAJ

The stack overflow is caused by the the res/drawable/ic_settings_ethernet.xml file in packages/apps/Settings which references itself, creating a circular dependency. I could not find any use of this file in any of the other resource files or in the Java source code. Simply removing it allows me to start the Settings app without crashes.

How to disable the WiFi/any networking or add any network in android :
 
  In android framework, there is a file to configure available networks.
If we disabled particular network in that file, Particular network will be disabled in android.

name of the file need to be modified to disable networks:
frameworks/base/core/res/res/values/config.xml

This file contents are as below:
 
  translatable="false" name="networkAttributes">
        "wifi,1,1,1"
        "mobile,0,0,0"
        "mobile_mms,2,0,2"
        "mobile_supl,3,0,2"
        "mobile_dun,4,0,4"
        "mobile_hipri,5,0,3"
    
 
 
In android framework, Connnectivity manager/service is reponsible for handling available networks.
If I want to add new network, I have to develop a service,NetworkStateTracker  and add the content in the above file.
 
 
Let me say If I want to add ethernet support, ethernet service should be written, launched from ConnectivityService.
we need to develop our own NetworkStateTracker derived class to maintain the state of ethernet.
We also need to add new item in the above file.
   From the above file only, Android will comes to know the available networks.
Let me say if I removed the wifi item, then WiFi wont be detected. Because android framework doesnt know the wifi network is available