I am trying to connect to an unsecured network using the WlanConnect function. It is returning ERROR_SUCCESS
, so far so good.
In my notification callback i receive WLAN_NOTIFICATION_ACM_CONNECTION_COMPLETE
followed instantly by WLAN_NOTIFICATION_ACM_CONNECTION_ATTEMPT_FAIL
.
Can someone give me a hint how i can find out what causes the connection to fail?
I'm assuming that you just forgot to mention the part where you called WlanRegisterNotification
, since you say that your notification callback is actually receiving notifications.
As it turns out, you're in luck—the API provides you with just such a hint. In the documentation for the structure passed to you in the callback function, WLAN_NOTIFICATION_DATA
, it describes what the WLAN_NOTIFICATION_ACM_CONNECTION_ATTEMPT_FAIL
notification code means:
A connection attempt has failed.
A connection consists of one or more connection attempts. An application may receive zero or more
wlan_notification_acm_connection_attempt_fail
notifications between receiving thewlan_notification_acm_connection_start
notification and thewlan_notification_acm_connection_complete
notification.The pData member points to a
WLAN_CONNECTION_NOTIFICATION_DATA
structure that identifies the network information for the connection attempt that failed.
And that structure has a wlanReasonCode
member that contains a WLAN_REASON_CODE
value that "indicates the reason for an operation failure." There are a bunch of error codes on that list. Check to see which one you are getting.
Also note that it is possible to receive a few WLAN_NOTIFICATION_ACM_CONNECTION_ATTEMPT_FAIL
notifications before the connection ultimately connects successfully.