Showing posts with label wifi. Show all posts
Showing posts with label wifi. 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.
  

Saturday, November 24, 2012


How to maintain various versions with the same target binary inside android file system ???


In Android, whatever folders with Android.mk files are added to external folder in android file system,while building the android, it will be compiled.

   I faced an interesting problem.  Wifi need wpa_supplicant. There are multiple wpa_supplicants are available in external folder. I could not figure it out which one will be compiled.
   external/wpa_supplicant
   external/wpa_supplicant_6
   external/wpa_supplicant_8

Because whatever things we copied to external folder, if it has Android.mk, then that folder will be compiled.
All 3 folders are having same target binary [wpa_supplicant,wpa_cli]. If we have multiple target binary with the same name, compilation will fail.

I analysed and found that in device.../BoardConfig.mk will have the macro to specify the WPA_SUPPLICANT_VERSION=0_x_8.0

if the WPA_SUPPLICANT_VERSION is 5.0, wpa_supplicant folder will be compiled.
if the WPA_SUPPLICANT_VERSION is 6.0, wpa_supplicant_6 folder will be compiled.
if the WPA_SUPPLICANT_VERSION is 8.0, wpa_supplicant_8 folder will be compiled.

within the external/wpa_supplicant/Android.mk if the WPA_SUPPLICANT_VERSION == 0_x_5.0, then only the folder source codes will be compiled.
within the external/wpa_supplicant6/Android.mk if the WPA_SUPPLICANT_VERSION == 0_x_6.0, then only the folder source codes will be compiled.
within the external/wpa_supplicant8/Android.mk if the WPA_SUPPLICANT_VERSION == 0_x_8.0, then only the folder source codes will be compiled.
Target android board can have any supplicant version, it might be 5.0 /6.0/8.0.


   Lessons learnt:
  
   we can have multiple versions of the same binary under external folder,decide which version to be compiled based on target board.

  where I can apply:

     Assume that TI android board has various accelerators for display.Some TI boards will use x hardware accelerators for display. Some boards will use Y hardware accelerators for display. We can use same target binary  so it can either use x hardware accelerator or y hardware accelerator for display based on BoardConfig. Finaly display binary is same.

 we can not put only x hardware accelerator source code in android. It will fail while compiling for Y hardware accelerator source.
User has to take care of copying the code based hardware accelerator. Or else we can copy x and y hardware accelerator code and decide which
one to be compiled by boardconfig.mk macros .



 

Sunday, October 14, 2012

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