WiFi on Android

Source: Internet
Author: User

Take the following blog information as a Referrence:

Http://blog.csdn.net/hongjiujing/archive/2010/05/07/5565431.aspx

 

 

Android WiFi state: Disabled, disabling, enabled, enabling, unknown.

 

1. Porting WiFi driver on Android

--> # Create filesystem for WiFi & DHCP (add this in the init. RC file)

++

Mkdir/data/MISC/WiFi 0771 WiFi system

Chown WiFi system/data/MISC/WiFi

Chmod 0771/data/MISC/WiFi

 

Mkdir/data/MISC/WiFi/sockets 0771 WiFi system

Chown WiFi system/data/MISC/WiFi/sockets

Chmod 07771/data/MISC/WiFi/sockets

Mkdir/data/MISC/DHCP 0770 DHCP

Chown DHCP/data/MISC/DHCP

Chmod 0770/data/MISC/DHCP

++

2. WPA and wpa2 implement

--> Init. RC configuration

++

Mkdir/data/system/wpa_supplicant 0771 WiFi system

Chown WiFi system/data/system/wpa_supplicant

Chmod 0771/data/eth0

Setprop wifi. Interface mlan0

 

Service wpa_supplicant/system/bin/wpa_supplicant-dwext-imlan0-C/data/MISC/WiFi/wpa_supplicant.conf

User Root

Group system WiFi

Disabled

 

Service dhcpcd/system/bin/dhcpcd-BKL mlan0

Disabled

One shot

++

 

--> Useful tool: wpa_cli

--> Requirement: driver_wext.c expects the WiFi kernel driver to implement the siocsiwpriv ioctrl and respond to Android commands like Arg, macaddr, linkspeed and etc.

--> Implement: add the upper IOCTL to kernel WiFi driver. (In wlan_wext.c). The following is the detail implement source code.

Add the "board_wpa_supplicant_driver: = wext" in boardconfig. mk

 

++

/**
* @ Brief set priv command
*
* @ Param Dev a pointer to net_device Structure
* @ Param info a pointer to iw_request_info Structure
* @ Param dwrq a pointer to iw_point Structure
* @ Param extra a pointer to extra data Buf
*
* @ Return 0 -- success, otherwise fail
*/
Static int wlan_set_priv (struct net_device * Dev, struct iw_request_info * info,
Struct iw_point * dwrq, char * extra)
{
Int ret = 0;
Wlan_private * priv = (wlan_private *) netdev_priv (Dev );
Char * Buf = NULL;
Int Len = 0;
Int EAP = 0;
Bssdescriptor_t * pbssdesc = NULL;

Enter ();
If (! (BUF = kmalloc (dwrq-> length, gfp_kernel ))){
Ret =-enomem;
Goto done;
}
If (copy_from_user (BUF, dwrq-> pointer, dwrq-> length )){
Ret =-efault;
Goto done;
}
Printm (Cmnd, "siocsiwpriv requst = % s/n", Buf );
If (strncmp (BUF, "reported", strlen ("reported") = 0 ){
If (priv-> adapter-> mediaconnectstatus = wlanmediastateconnected ){
If (wlan_prepare_cmd (priv,
Host1__assist_rssi_info,
Host1__act_gen_get, host1__option_waitforrsp,
0, null )){
Ret =-efault;
Goto done;
}
Http: // service.ap-southeast-1.maxcompute.aliyun-inc.com/api;
Pbssdesc = & priv-> adapter-> curbssparams. bssdescriptor;
Len = sprintf (BUF, "% s Arg % d/N", pbssdesc-> SSID. SSID, ARG) + 1;
}
}
Else if (strncmp (BUF, "linkspeed", strlen ("linkspeed") = 0 ){
If (wlan_prepare_cmd (priv, host1__802_11_tx_rate_query,
Host1__act_gen_get, host1__option_waitforrsp,
0, null )){
Ret =-efault;
Goto done;
}
Printm (Cmnd, "TX rate = % d/N", (INT) priv-> adapter-> txrate );
Len = sprintf (BUF, "linkspeed % d/N", (INT) (index_to_data_rate (priv-> adapter-> txrate) * 500000/1000000) + 1;
}
Else if (strncmp (BUF, "macaddr", strlen ("macaddr") = 0 ){
Len = sprintf (BUF, "macaddr = % 02x: % 02x: % 02x: % 02x: % 02x: % 02x/N ", priv-> adapter-> currentaddr [0],
Priv-> adapter-> currentaddr [1], priv-> adapter-> currentaddr [2], priv-> adapter-> currentaddr [3],
Priv-> adapter-> currentaddr [4], priv-> adapter-> currentaddr [5]);
}
Else {
Len = sprintf (BUF, "OK/N") + 1;
Printm (warn, "unknow private command: % s, ignored/N", Buf );
}
Printm (Cmnd, "priv command return: % s, length = % d/N", Buf, Len );
Dwrq-> length = Len;
If (copy_to_user (dwrq-> pointer, Buf, dwrq-> length )){
Ret =-efault;
}
Done:
If (BUF)
Kfree (BUF );
Leave ();
Return ret;
}

 

(Iw_handler) wlan_set_priv,/* siocsiwpriv */

++

 

3. WiFi Service

--> Android/frameworks/base/services/Java/COM/Android/Server/wifiservice. Java

 

4. WiFi Power Management

--> Take the following webpage for a reference

Http://www.cnmsdn.com/html/201003/1268408234ID1814.html

 

5. Problem:

--> After successfully connect to AP with wpa2 encryption, then disconnect with this AP, and reconnect with it, then it can not connect with this AP successfully.

Workaroud: Turn off the WiFi and then turn on it.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.