Android系统网络调试常用命令                   

1. ifconfig 查看网路状态

2.netstat

3. netcfg  

4.启动某个网络
    netcfg eth0 up 或者 busybox ifconfig eth0 up     

    netcfg wlan0 up

5. ping  连接IP地址

www.baidu.com

6.wpa_supplicant 命令

wpa_cli   进入wpa cilient命令模式 ,help

在wpa cilient命令模式输入命令:

例:driver macaddr 查看wifi mac地址

# wpa_cli  进入wpacilient命令模式
>help      查看wpa_supplicant支持的所有命令
>> ssid=PUB-WiFi                  //终端所连接到的AP(路由器)的名字
id=1
mode=station
pairwise_cipher=NONE
group_cipher=NONE
key_mgmt=NONE
wpa_state=COMPLETED
ip_address=12.20.21.250       //网络IP地址
p2p_device_address=7e:2a:80:78:f0:18   
address=9c:2a:71:18:0:88       //终端网卡(wifi模块)的mac地址
protocol_caps=802.11b/g/n      //协议
rate=12M
signal_level=-78> > LIST_NETWORKS
network id / ssid / bssid / flags
0       iCE    any
1       PUB-WiFi        any     [CURRENT]
2       Go M2S  any

>DRIVER MACADDR 


android中常用的wifi log 过滤方法及常用关键字              

logcat -s WifiHW Wifi

WifiInfo WifiStateMachine WifiNative-wlan0 WifiPowerSetting ConnectivityService

EthernetStateTracker dhcpcd ConnectivityService ethernet                
  

实例操作:             

shell@android:/ # netcfg
lo       UP                                   127.0.0.1/8   0x00000049 00:00:00:00:00:00
eth0     DOWN                                   0.0.0.0/0   0x00001202 00:63:18:00:00:01
sit0     DOWN                                   0.0.0.0/0   0x00000080 00:00:00:00:00:00
ip6tnl0  DOWN                                   0.0.0.0/0   0x00000080 00:00:00:00:00:00
wlan0    UP                                     0.0.0.0/0   0x00001003 94:5a:70:78:f0:88
p2p0     UP                                     0.0.0.0/0   0x00001003 91:4a:70:78:f0:88

shell@android:/ # busybox ifconfig
eth0      Link encap:Ethernet  HWaddr 40:8B:F6:96:01:FE  
          UP BROADCAST ALLMULTI MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:30 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:201 Base address:0x4000

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:369 errors:0 dropped:0 overruns:0 frame:0
          TX packets:369 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:29838 (29.1 KiB)  TX bytes:29838 (29.1 KiB)

p2p0      Link encap:Ethernet  HWaddr 90:2A:70:78:F0:88  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:421 errors:0 dropped:0 overruns:0 frame:0
          TX packets:11 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:173945 (169.8 KiB)  TX bytes:107 (107.0 B)

wlan0     Link encap:Ethernet  HWaddr 9C:2A:70:78:F0:88  
          inet addr:192.168.1.10  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::9e2a:70ff:fe78:f088/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:30179 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7059 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:24015605 (22.9 MiB)  TX bytes:1954950 (1.8 MiB)


android中通过终端命令访问网页命令

如:am start -a android.intent.action.VIEW -d  http://www.baidu.com



1. 系统架构

        Android WiFi系统引入了wpa_supplicant,它的整个WiFi系统以wpa_supplicant为核心来定义上层用户接口和下层驱动接口。整个WiFi系统架构如下图所示:

android wifi 终端 android/data/wifipwd_java

   一切尽在上图中,下面将对每部分进行详细分析。

1.1 WifiService   

     由SystemServer启动的时候生成的ConnecttivityService创建,负责启动关闭wpa_supplicant,启动和关闭WifiMonitor线程,把命令下发给wpa_supplicant以及更新WIFI的状态。

     处理其它模块通过IWifiManager接口发送过来的远端WiFi操作。

1.2 WifiMonitor

    负责从wpa_supplicant接收事件通知。

1.3 wpa_supplicant

  1) 读取配置文件
  2) 初始化配置参数,驱动函数
  3) 让驱动scan当前所有的bssid
  4) 检查扫描的参数是否和用户设置的相符
  5) 如果相符,通知驱动进行权限和认证操作
  6) 连上AP

1.4 Wifi驱动模块



     厂商提供的source,主要进行load firware和kernel的wireless进行通信

1.5 Wifi电源管理模块



     主要控制硬件的GPIO和上下电,让CPU和Wifi模组之间通过sdio接口或USB接口通信

1.6 Wifi工作步骤

  1) Wifi启动
  2) 开始扫描
  3) 显示扫描的AP
  4) 配置AP
  5) 连接AP
  6) 获取IP地址
  7) 上网

1.7 Wifi模块代码

   1) Wifi Settings应用程序       packages/apps/Settings/src/com/android/settings/wifi

   2) Wifi Framework       frameworks/base/wifi/Java/android/net/wifi (UI通过android.NET.wifi package
发送命令给wifi.c)

       frameworks/base/core/java/android/net(更高一级的网络管理)
       frameworks/base/services/java/com/android/server

   3) Wifi JNI       frameworks/base/core/jni/android_net_wifi_Wifi.cpp
   4) Wifi Hardware (wifi管理库)       hardware/libhardware_legacy/wifi/wifi.c

   5) wpa_supplicant(wifi  tool)

       external/wpa_supplicant8
       (1) wpa_client (生成库libwpaclient.so)

            external/wpa_supplicant_8/wpa_supplicant/src/common/wpa_ctrl.c

(2) wpa_server (生成守护进程wpa_supplicant)

            external/wpa_supplicant_8/wpa_supplicant/main.c
   6) Wifi kernel       net/wireless     drivers/wlan_xxx       arch/arm/mach-xxx/wlan_pm.c

2. WifiService和wpa_supplicant启动流程

     WifiService和wpa_supplicant启动流程如下图所示:

android wifi 终端 android/data/wifipwd_android wifi 终端_02

• 加载wifi驱动的状态变化流程如下:

初始状态:mInitialState

                         |
          mDriverUnloadedState

                         |
      mWaitForP2pDisableState

                         |
mDriverLoadingState(其enter中调用WifiNative.loadDriver)


• 启动wpa_supplicant的状态变化如下:
   在DriverLoadedState状态的processMessage中调用WifiNative.startSupplicant

3. 生产时自动打开Wifi

在生产时, 默认Wifi是关闭的,如果需要默认打开,可修改wifiservice.java中的如下代码:



1. /**
2.  * Check if Wi-Fi needs to be enabled and start
3.  * if needed
4.  *
5.  * This function is used only at boot time
6.  */  
7. public void checkAndStartWifi() {  
8.     mAirplaneModeOn.set(isAirplaneModeOn());  
9.     mPersistWifiState.set(getPersistedWifiState());  
10. /* Start if Wi-Fi should be enabled or the saved state indicates Wi-Fi was on */  
11.     boolean wifiEnabled = shouldWifiBeEnabled() || testAndClearWifiSavedState();  
12. "WifiService starting up with Wi-Fi " +  
13. "enabled" : "disabled"));  
14. //强制设置为true  
15.   
16.     mWifiWatchdogStateMachine = WifiWatchdogStateMachine.  
17.            makeWifiWatchdogStateMachine(mContext);  
18.   
19. }  
20.