WifiCommand流程 wpa_supplicant啓動流程 Wifiservice啓動流程(轉)

1. 信號強度算法

    WifiManager.java

 
  1. /** Anything worse than or equal to this will show 0 bars. */  
  2. private static final int MIN_RSSI = -100;  
  3.   
  4. /** Anything better than or equal to this will show the max bars. */  
  5. private static final int MAX_RSSI = -55;  
  6.   
  7. /** 
  8.  * Calculates the level of the signal. This should be used any time a signal 
  9.  * is being shown. 
  10.  * 
  11.  * @param rssi The power of the signal measured in RSSI. 
  12.  * @param numLevels The number of levels to consider in the calculated 
  13.  *            level. 
  14.  * @return A level of the signal, given in the range of 0 to numLevels-1 
  15.  *         (both inclusive). 
  16.  */  
  17. public static int calculateSignalLevel(int rssi, int numLevels) {  
  18.     /* in general, numLevels is 4  */  
  19.     if (rssi <= MIN_RSSI) {  
  20.         return 0;  
  21.     } else if (rssi >= MAX_RSSI) {  
  22.         return numLevels - 1;  
  23.     } else {  
  24.         float inputRange = (MAX_RSSI - MIN_RSSI);  
  25.         float outputRange = (numLevels - 1);  
  26.           
  27.         return (int)((float)(rssi - MIN_RSSI) * outputRange / inputRange);  
  28.     }  
  29. }  
    /** Anything worse than or equal to this will show 0 bars. */
    private static final int MIN_RSSI = -100;

    /** Anything better than or equal to this will show the max bars. */
    private static final int MAX_RSSI = -55;

    /**
     * Calculates the level of the signal. This should be used any time a signal
     * is being shown.
     *
     * @param rssi The power of the signal measured in RSSI.
     * @param numLevels The number of levels to consider in the calculated
     *            level.
     * @return A level of the signal, given in the range of 0 to numLevels-1
     *         (both inclusive).
     */
    public static int calculateSignalLevel(int rssi, int numLevels) {
        /* in general, numLevels is 4  */
        if (rssi <= MIN_RSSI) {
            return 0;
        } else if (rssi >= MAX_RSSI) {
            return numLevels - 1;
        } else {
            float inputRange = (MAX_RSSI - MIN_RSSI);
            float outputRange = (numLevels - 1);
            
            return (int)((float)(rssi - MIN_RSSI) * outputRange / inputRange);
        }
    }

 

2. WiFi Command流程

 

3. wpa_supplicant啓動流程

4. WifiService啓動流程

5. SIGNAL_POLL調用流程

 
  1. eloop_run->..  
  2. wpa_supplicant_ctrl_iface_receive-> //接收並處理來自framework的command   
  3. wpa_supplicant_ctrl_iface_process-> (SIGNAL_POLL)  
  4. wpa_supplicant_signal_poll->  
  5. wpa_drv_signal_poll  (struct wpa_supplicant *wpa_s,struct wpa_signal_info *si)->  
  6. wpa_driver_signal_poll  (void *priv, struct wpa_signal_info *si)->  
  7.     wpa_driver_wext_driver_cmd(priv, RSSI_CMD, buf, sizeof(buf))或  //driver_cmd_wext.c   
  8.     wpa_driver_wext_driver_cmd(priv, LINKSPEED_CMD, buf, sizeof(buf))->  
  9.         
  10.       struct iwreq iwr;  
  11.       iwr.u.data.pointer = buf;  
  12.       iwr.u.data.length = buf_len;  
  13.       ioctl(drv->ioctl_sock, SIOCSIWPRIV, &iwr);  
  14.       在Kernel中對應函數:  
  15.       cfg80211_wext_setpriv (wext-compat.c)  
  16.       RSSI_CMD:  
  17.       cfg80211_wireless_stats (獲取當前已連接AP的信號強度等信息)  
  18.   
  19.      對於上面的LINKSPEED_CMD,如果ioctl不成功,則調用ioctl(drv->ioctl_sock, SIOCGIWRATE, &wrq)  
  20.      在Kernel中對應函數:  
  21.      cfg80211_wext_giwrate (獲取當前已連接AP的發送速度)  
  22.   
  23.      //每個AP對應的信息        
  24.      struct station_info {  
  25.     u32 filled;  
  26.     u32 connected_time;  
  27.     u32 inactive_time;  
  28.     u32 rx_bytes;  
  29.     u32 tx_bytes;  
  30.     u16 llid;  
  31.     u16 plid;  
  32.     u8 plink_state;  
  33.     s8 signal;  //信號強度   
  34.     s8 signal_avg;  
  35.     struct rate_info txrate;  //發送速度   
  36.     struct rate_info rxrate;  
  37.     u32 rx_packets;  
  38.     u32 tx_packets;  
  39.     u32 tx_retries;  
  40.     u32 tx_failed;  
  41.     u32 rx_dropped_misc;  
  42.     struct sta_bss_parameters bss_param;  
  43.   
  44.     int generation;  
  45.     };  
eloop_run->..
wpa_supplicant_ctrl_iface_receive-> //接收並處理來自framework的command
wpa_supplicant_ctrl_iface_process-> (SIGNAL_POLL)
wpa_supplicant_signal_poll->
wpa_drv_signal_poll  (struct wpa_supplicant *wpa_s,struct wpa_signal_info *si)->
wpa_driver_signal_poll  (void *priv, struct wpa_signal_info *si)->
    wpa_driver_wext_driver_cmd(priv, RSSI_CMD, buf, sizeof(buf))或  //driver_cmd_wext.c
    wpa_driver_wext_driver_cmd(priv, LINKSPEED_CMD, buf, sizeof(buf))->
      
      struct iwreq iwr;
      iwr.u.data.pointer = buf;
      iwr.u.data.length = buf_len;
      ioctl(drv->ioctl_sock, SIOCSIWPRIV, &iwr);
      在Kernel中對應函數:
      cfg80211_wext_setpriv (wext-compat.c)
      RSSI_CMD:
      cfg80211_wireless_stats (獲取當前已連接AP的信號強度等信息)

     對於上面的LINKSPEED_CMD,如果ioctl不成功,則調用ioctl(drv->ioctl_sock, SIOCGIWRATE, &wrq)
     在Kernel中對應函數:
     cfg80211_wext_giwrate (獲取當前已連接AP的發送速度)

     //每個AP對應的信息     
     struct station_info {
	u32 filled;
	u32 connected_time;
	u32 inactive_time;
	u32 rx_bytes;
	u32 tx_bytes;
	u16 llid;
	u16 plid;
	u8 plink_state;
	s8 signal;  //信號強度
	s8 signal_avg;
	struct rate_info txrate;  //發送速度
	struct rate_info rxrate;
	u32 rx_packets;
	u32 tx_packets;
	u32 tx_retries;
	u32 tx_failed;
	u32 rx_dropped_misc;
	struct sta_bss_parameters bss_param;

	int generation;
    };
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章