Thursday, October 18, 2012


PPPoE:
================

For internet connection we might have used DSL modem. I am using BSNL modem in my home. Internally how modem is working?

We will connect telephone connection with DSL modem to receive/send over the network. From modem, we will connect the ethernet cable with PC to get internet connection. Initially modem was connected to RS232 serial port or USB 1.1 port. But it will have very less speed. Serialport maxspeed is at max 192 kbps. To speed up internet connection, PPPoE connection was made.

PPP protocol client is running in PC. PPP server will be running in Modem.
PC 's ethernet card communicates with modem's ethernet card. It is like connection ethernet cable between two systems as like a serial cable.

PPP client is running in PC, It will interacts with modem [PPP server] to have internet connection. Usually modem internet connection will be authenticated by username and password.

Since internet connection is made through PPP protocol. If OS supports this PPP client, then it will be able to access the modem. That's why we are able to get internet connection regardless of OS .

Wireless DSL router has antennas to access wireless access points. Wireless router will have its own page settings. By giving this from PC, http://192.168.1.1 we can change the router settings.

How data is transmitted in DSL modem:

DSL modem communicates with nearest telephone exchange's device. This device is called as Digital Subscriber Line Access Multiplexer (DSLAM). Data will be transferred over the telephone exchange's optical fiber cable. Whenever we are downloading a web page, packets of webpage travel over optical fiber internet lines directly to the DSLAM at the neighborhood telephone exchange. At the DSLAM, they are split into as many as paralllel data streams, modulated onto a separate signal and sent through cable. The modem demodulates the signal to datastream also will do error correction,put the data in proper order and sends it to the computer over ethernet line.

Monday, October 15, 2012

Android ICS environment  setup issue with Ubuntu 12.04 LTS:

  I stuck up with installation problems and found the below blog is helpful to resolve the issue:

http://techblog.simoncpu.com/2011/07/required-packages-for-building-android.html
How to use Intents between two applications to pass message,data or notification:


what is Intent ? Intent is one of the mechanism to  communicate  between two application or more application.


     Assume Network status notifications are raised as Intent and whoever application handles network, he has to receive the notification and act accordingly. For example, the application which is using internet connection should receive the network connected or disconnected message.


  Sender has to send the data. Receiver application has to receive the intents and receive add filters which need to handle.
   For example, Many intents can be raised from system level. But we need to be notified for particular intents, then those intents are added in IntentFilter, registered along with broadcast receiver.
     In the below code, we are raising WiFI network state changed event from framework or application. Whatever parameters we have to pass we can use putExtra() function. From receiver we have to get the values by getXXXExtra() fns.
    We can also raise custom intents in the similar way.




Sending an intent from an application to pass data or from framework:


CONNECTED
===============
string WIFIManager.NETWORK_STATE_CHANGED_ACTION ="WiFi"

Intent sIntent = new Intent(WIFIManager.NETWORK_STATE_CHANGED_ACTION);
sIntent.putExtra("WiFiUp",true);
SendBroadcast(sIntent);
context.sendBroadcast(sIntent);

DISCONNECTED:
===========
Intent sIntent = new Intent(WIFIManager.NETWORK_STATE_CHANGED_ACTION);
sIntent.putExtra("WiFiUp",false);
context.sendBroadcast(sIntent);


Receiving  Application:
==================

    Message Receiving application should have BroadcastReceiver with Receive() function.  We have to create IntentFilter and add an action to the intentFilter and while registering the broadcast receiver, we have to pass IntentFilter too.


whenever we dont want to receive the intent, we have to unregister the receiver.



import android.content.BroadcastReceiver;

private final BroadcastReceiver mReceiver;
private final IntentFilter mWiFiStateFilter;

 mWiFiStateFilter = new IntentFilter(WIFIManager.WIFI_STATE_CHANGED_ACTION);
 mWiFiStateFilter.addAction(WIFIManager.NETWORK_ENABLED_ACTION);
//we can add many actions in an intent Filter

mReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                handleEvent(context, intent);
            }
        };

private void handleEvent(Context context, Intent intent)
{
        String action = intent.getAction();
        if (action.equals(WIFIManager.NETWORK_STATE_CHANGED_ACTION) )
    {
        mEnabled= intent.getBooleanExtra("WiFiUp", false);
         //Receiving the WiFi status
        }
       else
        if (action.equals(WIFIManager.NETWORK_ENABLED_ACTION) )
       {
       }

   
}

 public void resume() {
         //Registering the receiver.
        //Usually receivers are registered in OnResume()
         mContext.registerReceiver(mWiFiStateReceiver,mWiFiStateFilter);
    }

 public void pause() {
       //Receivers are unregistered in OnPause() fn
         mContext.unregisterReceiver(mWiFiStateReceiver);
    }





Sunday, October 14, 2012

Kernel to user space communication in linux:
=================================

  3 different ways to communicate between kernel and userspace in Linux:

1) proc file system
2)ioctl
3) netlink
ioctl is the old mechanism. Speciality of netlink is we can send the command as multicast, so that different applications can receive the command.

 
For more refer:

http://people.ee.ethz.ch/~arkeller/linux/kernel_user_space_howto.html
TO get/set an IP address from Linux over the socket:
 
int s;
    struct ifreq ifr = {};

    s = socket(PF_INET, SOCK_DGRAM, 0);

    strncpy(ifr.ifr_name, "eth0", sizeof(ifr.ifr_name));

    if (ioctl(s, SIOCGIFADDR, &ifr) >= 0)
        printf("%s\n",
          inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr));


ioctl call receives data from the kernel for SIOCGIFADDR for IP address.

In case of static IP address, we will set the IP address with ioctl( SIOCGIFADDR, socketDetails) call.
 
 
ioctl is the module which can be used for kernel/user or user to kernel communication. 
 
 For more, read Richard Steven's Unix Network Programming book
 
 
 

Difference between Static and DHCP ip address:
   In static IP address, We will configure the interface with the our IP address/netmask and so on.
 Whereas in DHCP, we will DHCP client protocol identifies the IP address from DHCP server and send the IP address to kernel via RTM_NEWADDR msg over the netlink.

  

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 
 
 
 

How to display logs from android service:

By default,If we added any android service in init.rc, logs are redirected to null device. So logs wont be shown from service. Sometimes it will show sometimes it wont show logs. To display logs always from service,


we have to do the following

service serviceName /system/bin/logwrapper /system/bin/dhcpcd -BKLA -d eth0
disabled
oneshot

/system/bin/logwrapper - this will redirect the  service logs to logcat.

init.rc script is executed by init process.

How to communicate between two process /To pass information from one application to another application in android java:

 Best ways are intents. whoever wants to send message, He has to raise an intent.Whichever Application wants to receive the message, It has to implement  BroadcastStatusReceiver class.

We can raise intent like this... 

Intent sIntent = new Intent(EthernetManager.ETHERNET_STATE_CHANGED_ACTION);
sIntent.putExtra("EthUp",true) //THis is information to be passed
                                                   //Intent has different methods for string/int and   //so on


whoever[applications] wants to receive this intent they register this intent in their androidmanifest.xml, they will implement the BroadcastStatusReceiver for the same.
From the receiver application's BroadcastStatusReciever's OnReceive()
{
   if(recvdIntent.Equals(ETHERNET_STATE_CHANGED_ACTION)
   {
     boolean b=getBooleanExtra("EthUp");
    }


}


To Know the disk freespace in linux

To know the disk freespace in Linux:

=======================================

df [disk free] command


df -k -h

it will list the partition,used space and free space available.



Thursday, October 04, 2012

To Enable logs in android Java files:   

import android.util.Slog;
 private void log(String s) {
        Slog.d(TAG, s);
    }
How to detect IP address change in Linux:

http://stackoverflow.com/questions/579783/how-to-detect-ip-address-change-programmatically-in-linux
Copy all the files except one folder in Linux:

We have to run the following commands:

shopt -s extglob       #setting bash shell option to recognize regex patterns
cp -r A/!(B) dest_dir  #This will copy directory A to dest_dir and
                                 #excludes B directory
Another way of adding NDK logs in C/C++:

#include
LOCAL_LDLIBS := -llog

void LOGI(char *szMsg)
{
__android_log_write(ANDROID_LOG_ERROR,"Tag",szMsg);
}
 Read and print all arguments in C/C++:
===========================
     
  int count;
   for (count = 0; count < argc; count++)
   {
            printf ("%s\n", argv[count]);
   }
How to add logs in android C/C++ files:

#define LOG_TAG XXX   // its the tag u can see in the logcat.
#include  

LOGE("printing log %s,%d",__FILE__,__LINE__);
 

In Android.mk, Add below line :

LOCAL_SHARED_LIBRARIES := \
        libutils          \
How to Launch an activity/application  in android from commandline:
=============================================

commands to launch an application in android:

adb shell am start -a android.intent.action.MAIN -n packageName/.mainActivityName

If I want to launch one application from commandline, what things I need to do:

1)From APK's AndroidManifest.xml,we can identify the main activity.Then we can use above command

2)Another easy way is launch an application using GUI/by clicking the application At the same time take logs using "adb logcat".

ActivityManager(1132): Starting activity: Intent { cmp=com.android.providers.subscribedfeeds/com.android.settings.ManageAccountsSettings }

ActivityManager(1132): Displayed activity  com.android.providers.subscribedfeeds/com.android.settings.ManageAccountsSettings :500 ms


 we can launch this activity from commandline as below:

 adb shell am start -a android.intent.action.MAIN -n 
com.android.providers.subscribedfeeds/com.android.settings.ManageAccountsSettings
 

How to know the services currently running in Android:

     To list the running services in android

  •   Menu->Setting->Applications->Running Services 

How to mount usb in Linux:

Mount USB if there is no other way in case of embedded linux:

 
  1) insert USB
  2) give "fdisk -l" [lists the /dev/sda1 or sda5]
  3)  mount /dev/sda1 /mnt/ [mount usb,USB file contents will be available in /mnt/ folder]



  4) cp ts.txt /mnt/   #  copy files to usb 
  5) cp /mnt/ts.txt .     #copy files from usb to current folder
  6) sync #Flush buffer read/write contents
  6) umount /mnt/  #unmount usb


Tar/Untar commands in Linux:
=====================


Compress tar.gz file:
# tar -zcvf archiveName.tar.gz directoryToCompress

To decompress an archive use the following syntax:

# tar -zxvf archiveName.tar.gz

Tuesday, October 02, 2012


How to get logcat from the android device which is having IP address:

we can connect to the device with IP address by adb command.
If we are runnign the below command from system,

adb connect 10.1.20.100 #will makes the system to connect with device.

Afterwards if we are giving “adb logcat”, this will prints the logs in your system.So with adb command, we can connect to any emulator or device which is having IP address. It is possible that we can connect to any remote device and can take logs from another remote place.


Starting and stopping Android core services:

Any android core services can be started and stopped by settting properties of a core service. Application can start or stop the any service by below commands:

setprop ctl.stop serviceName
setprop ctl.start serviceName

setprop ctl.stop dhcpcd_eth0 #This will stop the dhcpcd_eth0 service
setprop ctl.start dhcpcd_eth0 #This will start the dhcpcd_eth0 service

From our system, we can communicate emulator or actual device and we can see the properties set by below commands:

>adb shell
$getprop
This will gives/lists  output of all the properties set...


How to compile ICS code in Ubuntu 12.04 64 bit OS?
In  Ubuntu 12.04 64 bit OS, while compiling android ICS code[thru make], it will give FORTIFY_SOURCE error as below:
 + FORTIFY_SOURCE error ... :0:0: warning: "_FORTIFY_SOURCE" redefined 
 Problem for this issue:
 ICS is trying to compile with gcc-4.6. ICS code is compilable in gcc-4.4 only. 
Resolution: 
While giving make{compiling android code}, we can mention the make file to use gcc-4.4 by below commands:
 make CC=gcc-4.4 CXX=g++-4.4 
or 
  export CC=gcc-4.4 CXX=g++-4.4
  make #This will use exported CC & CXX flag's value gcc/g++-4.4 version 

Use below steps to install sun-java6-jdk in Ubuntu 12.04 LTS:

sudo add-apt-repository ppa:flexiondotorg/java 
sudo apt-get update
sudo apt-get install sun-java6-jdk