WlanConnect(), how to connect to and open wireless access point

866 views Asked by At

in order to connecto to an open access point I fill the WLAN_CONNECTION_PARAMETERS structure as below

WLAN_CONNECTION_PARAMETERS ConnectionParameters;
ConnectionParameters.wlanConnectionMode = wlan_connection_mode_discovery_unsecure;
ConnectionParameters.strProfile         = L"";
ConnectionParameters.pDot11Ssid         = &Dot11Ssid;
ConnectionParameters.pDesiredBssidList  = nullptr;
ConnectionParameters.dot11BssType       = dot11_BSS_type_independent;
ConnectionParameters.dwFlags            = WLAN_CONNECTION_ADHOC_JOIN_ONLY;

The WlanConnect() function returns ERROR_SUCCESS.

The NotificationCallback() function prints:

wlan_notification_acm_connection_start
Currently connecting to "BT.03" using profile "BT.03" **// Correct**
WLAN_NOTIFICATION_SOURCE_ACM
**wlan_notification_acm_connection_attempt_fail**
The connection failed. wlanReasonCode:  163851
The reason is "La rete specificata non รจ disponibile."

Where is the error?

Have you got a piece of code to connect to a new open wireless access point with a specific ssid?

2

There are 2 answers

2
Dai On

The documentation for WLAN_CONNECTION_PARAMETERS states that strProfile should be set to NULL when using wlan_connection_mode_discovery_unsecure, but your code sets it to L"".

If wlanConnectionMode is set to wlan_connection_mode_discovery_secure or wlan_connection_mode_discovery_unsecure, then strProfile should be set to NULL.

So change your code to this:

ConnectionParameters.strProfile = NULL;
0
Denis Gottardello On

ConnectionParameters.strProfile= nullptr;

don't resolve.

The solution is to add

memset(&ConnectionParameters, 0, sizeof(WLAN_CONNECTION_PARAMETERS));