framework/src/st_things/things_stack/utils/things_network.c
//--------------------------------------------------------------------------------
/**
 * This function set the Wi-Fi manager ap configuration from access point.
 */
This function set the Wi-Fi manager ap configuration from access point.
This function set the Wi - Fi manager ap configuration from access point .
int things_set_ap_connection(access_point_info_s *p_info)
{
	THINGS_LOG_D(TAG, "T%d --> %s", getpid(), __FUNCTION__);
	if (p_info == NULL) {
		THINGS_LOG_E(TAG, "Invalid params");
		return -1;
	}
	wifi_manager_ap_config_s connect_config;
	strncpy(connect_config.ssid, p_info->e_ssid, sizeof(connect_config.ssid));	
	connect_config.ssid_length = strlen(connect_config.ssid);
	strncpy(connect_config.passphrase, p_info->security_key, sizeof(connect_config.passphrase));	
	connect_config.passphrase_length = strlen(connect_config.passphrase);
	THINGS_LOG_V(TAG, "[%s] ssid : %s", __FUNCTION__, connect_config.ssid);
	if (strncmp(p_info->sec_type, SEC_TYPE_WEP, strlen(SEC_TYPE_WEP)) == 0) {
		connect_config.ap_auth_type = WIFI_MANAGER_AUTH_WEP_SHARED;
	} else if (strncmp(p_info->sec_type, SEC_TYPE_WPA_PSK, strlen(SEC_TYPE_WPA_PSK)) == 0) {
		connect_config.ap_auth_type = WIFI_MANAGER_AUTH_WPA_PSK;
	} else if (strncmp(p_info->sec_type, SEC_TYPE_WPA2_PSK, strlen(SEC_TYPE_WPA2_PSK)) == 0) {
		connect_config.ap_auth_type = WIFI_MANAGER_AUTH_WPA2_PSK;
	}
	if (strncmp(p_info->enc_type, ENC_TYPE_WEP_64, strlen(ENC_TYPE_WEP_64)) == 0) {
		connect_config.ap_crypto_type = WIFI_MANAGER_CRYPTO_WEP_64;
	} else if (strncmp(p_info->enc_type, ENC_TYPE_WEP_128, strlen(ENC_TYPE_WEP_128)) == 0) {
		connect_config.ap_crypto_type = WIFI_MANAGER_CRYPTO_WEP_128;
	} else if (strncmp(p_info->enc_type, ENC_TYPE_TKIP, strlen(ENC_TYPE_TKIP)) == 0) {
		connect_config.ap_crypto_type = WIFI_MANAGER_CRYPTO_TKIP;
	} else if (strncmp(p_info->enc_type, ENC_TYPE_AES, strlen(ENC_TYPE_AES)) == 0) {
		connect_config.ap_crypto_type = WIFI_MANAGER_CRYPTO_AES;
	} else if (strncmp(p_info->enc_type, ENC_TYPE_TKIP_AES, strlen(ENC_TYPE_TKIP_AES)) == 0) {
		connect_config.ap_crypto_type = WIFI_MANAGER_CRYPTO_TKIP_AND_AES;
	}
	wifi_manager_result_e res = wifi_manager_save_config(&connect_config);
	if (res != WIFI_MANAGER_SUCCESS) {
		THINGS_LOG_E(TAG, "Failed to save AP configuration : [%d]", res);
		return -1;
	} else {
		THINGS_LOG_V(TAG, "Success to save AP configuration");
	}
	if (!things_handle_stop_soft_ap(&connect_config)) {
		return -1;
	}
	return 1;
}
int things_set_ap_connection ( access_point_info_s * p_info ) { THINGS_LOG_D ( TAG , " " , getpid ( ) , __FUNCTION__ ) ; if ( p_info == NULL ) { THINGS_LOG_E ( TAG , " " ) ; return -1 ; } wifi_manager_ap_config_s connect_config ; strncpy ( connect_config . ssid , p_info -> e_ssid , sizeof ( connect_config . ssid ) ) ; connect_config . ssid_length = strlen ( connect_config . ssid ) ; strncpy ( connect_config . passphrase , p_info -> security_key , sizeof ( connect_config . passphrase ) ) ; connect_config . passphrase_length = strlen ( connect_config . passphrase ) ; THINGS_LOG_V ( TAG , " " , __FUNCTION__ , connect_config . ssid ) ; if ( strncmp ( p_info -> sec_type , SEC_TYPE_WEP , strlen ( SEC_TYPE_WEP ) ) == 0 ) { connect_config . ap_auth_type = WIFI_MANAGER_AUTH_WEP_SHARED ; } else if ( strncmp ( p_info -> sec_type , SEC_TYPE_WPA_PSK , strlen ( SEC_TYPE_WPA_PSK ) ) == 0 ) { connect_config . ap_auth_type = WIFI_MANAGER_AUTH_WPA_PSK ; } else if ( strncmp ( p_info -> sec_type , SEC_TYPE_WPA2_PSK , strlen ( SEC_TYPE_WPA2_PSK ) ) == 0 ) { connect_config . ap_auth_type = WIFI_MANAGER_AUTH_WPA2_PSK ; } if ( strncmp ( p_info -> enc_type , ENC_TYPE_WEP_64 , strlen ( ENC_TYPE_WEP_64 ) ) == 0 ) { connect_config . ap_crypto_type = WIFI_MANAGER_CRYPTO_WEP_64 ; } else if ( strncmp ( p_info -> enc_type , ENC_TYPE_WEP_128 , strlen ( ENC_TYPE_WEP_128 ) ) == 0 ) { connect_config . ap_crypto_type = WIFI_MANAGER_CRYPTO_WEP_128 ; } else if ( strncmp ( p_info -> enc_type , ENC_TYPE_TKIP , strlen ( ENC_TYPE_TKIP ) ) == 0 ) { connect_config . ap_crypto_type = WIFI_MANAGER_CRYPTO_TKIP ; } else if ( strncmp ( p_info -> enc_type , ENC_TYPE_AES , strlen ( ENC_TYPE_AES ) ) == 0 ) { connect_config . ap_crypto_type = WIFI_MANAGER_CRYPTO_AES ; } else if ( strncmp ( p_info -> enc_type , ENC_TYPE_TKIP_AES , strlen ( ENC_TYPE_TKIP_AES ) ) == 0 ) { connect_config . ap_crypto_type = WIFI_MANAGER_CRYPTO_TKIP_AND_AES ; } wifi_manager_result_e res = wifi_manager_save_config ( & connect_config ) ; if ( res != WIFI_MANAGER_SUCCESS ) { THINGS_LOG_E ( TAG , " " , res ) ; return -1 ; } else { THINGS_LOG_V ( TAG , " " ) ; } if ( ! things_handle_stop_soft_ap ( & connect_config ) ) { return -1 ; } return 1 ; }
This function set the Wi-Fi manager ap configuration from access point.
This function set the Wi - Fi manager ap configuration from access point .
// Keep Wi-Fi Manager access point configuration information. // Set the ssid. // Set the security key. // Set sec type. // Set encryption crypto type. // Call WiFi Manager to save AP configuration.