framework/src/st_things/things_stack/utils/things_network.c
//--------------------------------------------------------------------------------
/**
 * Function definiton for callback of wifi, scanning ap is done.
 */
Function definiton for callback of wifi, scanning ap is done.
Function definiton for callback of wifi scanning ap is done .
void things_wifi_scan_done(wifi_manager_scan_info_s **scan_result, int res)
{
	THINGS_LOG_V(TAG, "T%d --> %s", getpid(), __FUNCTION__);
	if (scan_result == NULL) {
		return;
	}
	pthread_mutex_lock(&g_ap_list_mutex);
	things_wifi_list_cleanup();
	wifi_manager_scan_info_s *wifi_scan_iter = *scan_result;
	access_point_info_s *pinfo = NULL;
	access_point_info_s *p_last_info = NULL;
	while (wifi_scan_iter != NULL) {
		if ((wifi_scan_iter->ssid != NULL) && (strlen(wifi_scan_iter->ssid)) != 0) {
			pinfo = (access_point_info_s*)things_malloc(sizeof(access_point_info_s));
			pinfo->next = NULL;
			snprintf(pinfo->e_ssid, WIFIMGR_SSID_LEN, "%s", wifi_scan_iter->ssid);
			snprintf(pinfo->bss_id, WIFIMGR_MACADDR_STR_LEN, "%s", wifi_scan_iter->bssid);
			snprintf(pinfo->signal_level, MAX_LEVEL_SIGNAL, "%d", wifi_scan_iter->rssi);
			const char *sec_type;
			if (wifi_scan_iter->ap_auth_type == WIFI_MANAGER_AUTH_WEP_SHARED) {
				sec_type = SEC_TYPE_WEP;					
			} else if (wifi_scan_iter->ap_auth_type == WIFI_MANAGER_AUTH_WPA_PSK) {
				sec_type = SEC_TYPE_WPA_PSK;					
			} else if (wifi_scan_iter->ap_auth_type == WIFI_MANAGER_AUTH_WPA2_PSK) {
				sec_type = SEC_TYPE_WPA2_PSK;					
			} else {
				sec_type = SEC_TYPE_NONE;
			}
			snprintf(pinfo->sec_type, MAX_TYPE_SEC, "%s", sec_type);
			const char *enc_type;
			if (wifi_scan_iter->ap_crypto_type == WIFI_MANAGER_CRYPTO_WEP_64) {
				enc_type = ENC_TYPE_WEP_64;					
			} else if (wifi_scan_iter->ap_crypto_type == WIFI_MANAGER_CRYPTO_WEP_128) {
				enc_type = ENC_TYPE_WEP_128;					
			} else if (wifi_scan_iter->ap_crypto_type == WIFI_MANAGER_CRYPTO_TKIP) {
				enc_type = ENC_TYPE_TKIP;					
			} else if (wifi_scan_iter->ap_crypto_type == WIFI_MANAGER_CRYPTO_AES) {
				enc_type = ENC_TYPE_AES;					
			} else if (wifi_scan_iter->ap_crypto_type == WIFI_MANAGER_CRYPTO_TKIP_AND_AES) {
				enc_type = ENC_TYPE_TKIP_AES;					
			} else {
				enc_type = ENC_TYPE_NONE;
			}
			snprintf(pinfo->enc_type, MAX_TYPE_ENC, "%s", enc_type);
			if (g_wifi_scan_info == NULL) {
				g_wifi_scan_info = pinfo;
			} else {
				p_last_info->next = pinfo;
			}
			p_last_info = pinfo;
			g_wifi_count++;
		}
		wifi_scan_iter = wifi_scan_iter->next;
	}		
	pinfo = g_wifi_scan_info;
	while (pinfo != NULL) {
		THINGS_LOG_V(TAG, "WiFi AP - SSID: %-20s, WiFi AP BSSID: %-20s, WiFi Rssi: %d\n",
				   pinfo->e_ssid, pinfo->bss_id, pinfo->signal_level);
		pinfo = pinfo->next;
	}
	THINGS_LOG_V(TAG, "WiFi List Count is (%d)", g_wifi_count);
	pthread_mutex_unlock(&g_ap_list_mutex);
	return;
}
void things_wifi_scan_done ( wifi_manager_scan_info_s * * scan_result , int res ) { THINGS_LOG_V ( TAG , " " , getpid ( ) , __FUNCTION__ ) ; if ( scan_result == NULL ) { return ; } pthread_mutex_lock ( & g_ap_list_mutex ) ; things_wifi_list_cleanup ( ) ; wifi_manager_scan_info_s * wifi_scan_iter = * scan_result ; access_point_info_s * pinfo = NULL ; access_point_info_s * p_last_info = NULL ; while ( wifi_scan_iter != NULL ) { if ( ( wifi_scan_iter -> ssid != NULL ) && ( strlen ( wifi_scan_iter -> ssid ) ) != 0 ) { pinfo = ( access_point_info_s * ) things_malloc ( sizeof ( access_point_info_s ) ) ; pinfo -> next = NULL ; snprintf ( pinfo -> e_ssid , WIFIMGR_SSID_LEN , " " , wifi_scan_iter -> ssid ) ; snprintf ( pinfo -> bss_id , WIFIMGR_MACADDR_STR_LEN , " " , wifi_scan_iter -> bssid ) ; snprintf ( pinfo -> signal_level , MAX_LEVEL_SIGNAL , " " , wifi_scan_iter -> rssi ) ; const char * sec_type ; if ( wifi_scan_iter -> ap_auth_type == WIFI_MANAGER_AUTH_WEP_SHARED ) { sec_type = SEC_TYPE_WEP ; } else if ( wifi_scan_iter -> ap_auth_type == WIFI_MANAGER_AUTH_WPA_PSK ) { sec_type = SEC_TYPE_WPA_PSK ; } else if ( wifi_scan_iter -> ap_auth_type == WIFI_MANAGER_AUTH_WPA2_PSK ) { sec_type = SEC_TYPE_WPA2_PSK ; } else { sec_type = SEC_TYPE_NONE ; } snprintf ( pinfo -> sec_type , MAX_TYPE_SEC , " " , sec_type ) ; const char * enc_type ; if ( wifi_scan_iter -> ap_crypto_type == WIFI_MANAGER_CRYPTO_WEP_64 ) { enc_type = ENC_TYPE_WEP_64 ; } else if ( wifi_scan_iter -> ap_crypto_type == WIFI_MANAGER_CRYPTO_WEP_128 ) { enc_type = ENC_TYPE_WEP_128 ; } else if ( wifi_scan_iter -> ap_crypto_type == WIFI_MANAGER_CRYPTO_TKIP ) { enc_type = ENC_TYPE_TKIP ; } else if ( wifi_scan_iter -> ap_crypto_type == WIFI_MANAGER_CRYPTO_AES ) { enc_type = ENC_TYPE_AES ; } else if ( wifi_scan_iter -> ap_crypto_type == WIFI_MANAGER_CRYPTO_TKIP_AND_AES ) { enc_type = ENC_TYPE_TKIP_AES ; } else { enc_type = ENC_TYPE_NONE ; } snprintf ( pinfo -> enc_type , MAX_TYPE_ENC , " " , enc_type ) ; if ( g_wifi_scan_info == NULL ) { g_wifi_scan_info = pinfo ; } else { p_last_info -> next = pinfo ; } p_last_info = pinfo ; g_wifi_count ++ ; } wifi_scan_iter = wifi_scan_iter -> next ; } pinfo = g_wifi_scan_info ; while ( pinfo != NULL ) { THINGS_LOG_V ( TAG , " \n " , pinfo -> e_ssid , pinfo -> bss_id , pinfo -> signal_level ) ; pinfo = pinfo -> next ; } THINGS_LOG_V ( TAG , " " , g_wifi_count ) ; pthread_mutex_unlock ( & g_ap_list_mutex ) ; return ; }
Function definiton for callback of wifi, scanning ap is done.
Function definiton for callback of wifi scanning ap is done .
/**
	 *  Make sure you copy the scan results onto a local data structure.
	 * It will be deleted soon eventually as you exit this function.
	 */ /**
	 *  First it clean the existing global scan list.After that it start
	 * doing wifi scan.
	 */ /**
	 * Stored the wifi scan result into globally defined list g_wifi_scan_info. and
	 * also update the globally wifi list count variable.
	 */ // Create dynamic memory for pinfo list. // Set the ssid. // Set the bssid(mac address). // Set the signal level. // Set auth type. // Use Shared key(WEP key). // WPA_PSK mode. // WPA2_PSK mode. // Set encryption type. // WEP encryption wep-40. // WEP encryption wep-128. // TKIP encryption. // AES encryption. // TKIP and AES mixed encryption. // Increment global scan list count. /* while (wifi_scan_iter != NULL) to endicate end of while. */ // Print the all near by Wifi scan access point.