This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3220SF: Second call sl_WlanConnect() with same Ssid and different Key

Part Number: CC3220SF

Hello!

My customer have a lot of divisions with different AP.

My cc3220-device can be moved from one division to another. In cc3220 flash have a List of Ssid and Key of all AP in all divisions.

Then cc3220 tries to connect to AP i get a list of AP in range (using SL_WLAN_POLICY_SCAN), sort it by rssi and try to connect, using Key from List with matched Ssid.

Then i have a unique Ssid in List - all works fine. Then i have 2 entries in List with same Ssid, but different Keys, i first call sl_WlanConnect() with correct Ssid and wrong Key, it fails as expected. After that, i call sl_WlanConnect() with same Ssid and correct Key - it also fails (unexpected). After a long loop (10-60 minutes) connection to AP successes.

How can i handle this situation?

Code:

sl_WlanConnect(ssid, strlen(ssid), 0, secParams1, 0);//secParams1.Key - wrong, fails connection
sleep(1);
sl_WlanConnect(ssid, strlen(ssid), 0, secParams2, 0);//secParams2.Key - correct, fails connection

//secParams.Type = SL_WLAN_SEC_TYPE_WPA_WPA2

   

  • Hi,

    I did not tested this way, but I think you should store MAC address of AP as well and use it into sl_WlanConnect() API - see parameter pMacAddr.

    Jan
  • Hello!

    It's not a robust solution. If router will be changed (with the retention of Ssid), my device will fail to connect to it.
  • Hi,

    CC3220 need to know to what AP you want to connect. CC3220 is not able to determine which one is proper. You need provide this information to CC3220 if you are using manual connection (not connection profiles).

    From network scan command is returned BSSID. That mean you can select connection attempt to right AP. You can select first AP and after unsuccessfully connection you can select 2nd...

    Jan
  • Hello!

    I think, you do not understand the question. I have 2 entries with same Ssid and different Keys in my List, not in Network scan.

    Network scan returns only 1 entry with 1 Ssid. But i have 2 Keys for this Ssid and i do not know which Key is correct.

    I try first Key - it's, for example, incorrect, connection fails as expected. But then i try second Key (correct), i expect successful connection, but connection fails.  

  • Hi,

    No. In your case will wlan scan return two records with same SSID. See results from my test:

    18:48:12.921>  > Incoming CLI command: scan
    18:48:12.921>  > 10:fe:ed:a8:50:6e 10 -66dBm WPA2     AP2
    18:48:12.921>  > c0:25:e9:60:8d:fe 13 -82dBm WPA2     MujO2Internet_2.4G_608DFE
    18:48:12.921>  > 5c:f4:ab:0d:91:53 13 -86dBm WPA2     Internet_50
    18:48:12.921>  > b6:f7:a1:0c:f2:ab 1  -35dBm WPA2     AP2
    18:48:12.921>  > fe:ec:da:3e:81:a4 8  -88dBm WPA2     

    AP2 (10:fe:ed:a8:50:6e 10) my normal AP

    AP2 (b6:f7:a1:0c:f2:ab) AP created Tethering in my cell phone

    Update: OK. In this case you need to store BSSID. I don't see any other option.

    BTW: How do you have set connection policy?

    Jan

  • Hi,

    How looks your connection code? Because I tested similar situation I my code worked without any issue.

    My code have capability to change WLAN parameters via UART.
    - At first step I changed password to incorrect, I saved settings and connection was not successfully as I expected.
    - After that I set proper password and sl_WlanConnect() connected properly.

    Jan
  • Hello!

    If i manually change Key like you and then restart NWP, reset connection policies, ... etc -  connection will success. But i try different keys in loop.

    On second try with correct Key i get error SL_WLAN_DISCONNECT_WHILE_CONNNECTING

    Simplified code looks like this:

    bool SeekAndConnectAP ()
    {
        sl_WlanPolicySet(SL_WLAN_POLICY_CONNECTION, SL_WLAN_CONNECTION_POLICY(0,0,0,0), NULL ,0);
        
        SlWlanNetworkEntry_t netEntries[20];
        _i16 resultsCount;
    
        _u16 scanInterval = 600;
    
        sl_WlanPolicySet (SL_WLAN_POLICY_SCAN, 1, (_u8*) scanInterval, sizeof(scanInterval));
    
        sleep (1); // delay 1 second to verify scan is started
    
        resultsCount = sl_WlanGetNetworkList (0, 20, &netEntries[0]);
    
        sl_WlanPolicySet (SL_WLAN_POLICY_SCAN , SL_WLAN_SCAN_POLICY(0, 0), NULL, 0);
    
        int s, s1;
    
        for(s = 0; s < resultsCount; s++)
        {
            for (s1 = 0; s1 < APCount; s1++)
            {
                if (strcmp ((char*) netEntries[s].Ssid, APList[s1].ssid) == 0)
                {
                    sl_WlanConnect((_i8*)APList[s1].ssid, strlen(APList[s1].ssid), 0, &APList[s1].secParams, 0);
    
                    _u32 events = PendEventWithTimeout (wifiEventHandle, WLAN_EVENT_IP_ACQUIRED|WLAN_EVENT_IP_LOST|WLAN_EVENT_DISCONNECTED, WLAN_CONNECT_TIMEOUT); //my Event analog for POSIX, used semaphore
    
                    if (events & WLAN_EVENT_IP_ACQUIRED)
                        return true;
                    
                    sl_WlanDisconnect();
                }
            }
        }
        
        return false;
    }

  • Hi,

    From my point of view if logic of you connection code not correct. Few hints:
    - you did not read return codes from sl_ APIs (this approach is not good because you don't know that API was executed successfully)
    - you call sl_WlanDisconnect() in case you are not connected to WLAN
    - missing any delay after disconnect attempt - you did not wait for disconnect event

    You are say that approach with NWP reset works at your case. If your all attempts will failed you can still use this approach.

    (sorry for a delayed answer, but we have public holiday)

    Jan
  • Hello!

    -The code is simplified, that because you do not see return codes reads.
    -I call sl_WlanDisconnect() because i do not know connection state (can't find GetConnectionState function in SL API). If cc3220 not connected, sl_WlanDisconnect() just returns AlreadyDisconnected error, it's not a problem. Am i wrong? I tried to not call sl_WlanDisconnect() - nothing changed.
    -Disconnect event appears before i call sl_WlanDisconnect(), on this string:
    _u32 events = PendEventWithTimeout (wifiEventHandle, WLAN_EVENT_IP_ACQUIRED|WLAN_EVENT_IP_LOST|WLAN_EVENT_DISCONNECTED, WLAN_CONNECT_TIMEOUT);

  • Hi,

    - You connection state should be determined according states from asynchronous handlers.
    - Event with reason code SL_WLAN_DISCONNECT_WHILE_CONNNECTING is normal in case wrong password during connection into WPA network (it does not work in case of WEP is used).
    - After callings sl_WlanDisconnect() you should wait to be disconnect successfully done (signalised via handlers).

    Jan
  • -I get SL_WLAN_DISCONNECT_WHILE_CONNNECTING with correct password
    -I tried to wait disconnect event after sl_WlanDisconnect(), but it never appears because of my previous post.

    Anyway, i tried this simple code and do not get success connection:

    sl_WlanConnect("AP", 2, 0, secParams1, 0);//secParams1.Key - wrong, fails connection
    sleep(20);
    sl_WlanDisconnect();
    sleep(20);
    sl_WlanConnect("AP", 2, 0, secParams2, 0);//secParams2.Key - correct, fails connection
    .
    But this code gives success connection:

    sl_WlanConnect("AP", 2, 0, secParams2, 0);//secParams2.Key - correct, success connection 

  • Hi,

    You need to properly design state machine based on events from asynchronous handlers. According this states you need to determine state of connection.

    Code above cannot work because you not wait to proper establishing or refusing connection. Delay 20ms too small to establishing WLAN connection.

    Jan
  • Hello!

    -I have state machine, and i can get Events  from SL Handlers (see my code with PendEvent). I can send you full code in private message, if you want (it’s 10000+ strings).

    - sleep (20) it’s 20 seconds delay, not 20 ms

  • Hi,

    I am sorry, but I am not able to review your code. But I done same test as you and all worked as expected. I call sl_WlanConnect() with wrong password, sleep 20sec and after that I call sl_WlanConnect() with proper password. See my log:

    12:56:01.630> [WLAN] NWP info (CHIP 805306393, MAC 2.0.0.0, NWP 3.11.0.6, PHY 2.2.0.6)
    12:56:01.630> [WLAN] Request to STA
    12:56:01.690> [WLAN] Set to STA mode
    12:56:01.750> ... 1 (connect with wrong password)
    12:56:01.972> ... 2 (sleep 20sec)
    12:56:06.410> [WLAN] WlanDisconnectEvt: STA disconnected from AP (Code=204)
    12:56:10.720> [WLAN] WlanDisconnectEvt: STA disconnected from AP (Code=204)
    12:56:14.990> [WLAN] WlanDisconnectEvt: STA disconnected from AP (Code=204)
    12:56:19.330> [WLAN] WlanDisconnectEvt: STA disconnected from AP (Code=204)
    12:56:21.990> ... 3 (connect with right password)
    12:56:22.190> [WLAN] Set to STA mode done
    12:56:22.190> [WLAN] STA connecting
    12:56:22.190> [WLAN] WlanDisconnectEvt: STA disconnected from AP (Code=2)
    12:56:22.550> [WLAN] WlanConnectEvt: STA connected to AP (SSID=AP2, BSSID=10-fe-ed-a8-50-6e)
    12:56:22.550> [WLAN] NetAppIPv4AcquiredEvt: IP was acquired (IP=192.168.1.4)
    12:56:22.630> [WLAN] STA connected to AP
    12:56:22.630> [WLAN] STA acquired IP

    Jan

  • Hi,

    And results from another test:

    sl_WlanConnect() // with wrong password
    sleep(20sec)
    sl_WlanDisconnect()
    sleep(20sec)
    sl_WlanConnect() // with right password
    13:03:14.017> [WLAN] NWP info (CHIP 805306393, MAC 2.0.0.0, NWP 3.11.0.6, PHY 2.2.0.6)
    13:03:14.080> [WLAN] Request to STA
    13:03:14.080> [WLAN] Set to STA mode
    13:03:14.205> ... 1 (connect with wrong password)
    13:03:14.392> ... 2 (sleep 20sec)
    13:03:18.829> [WLAN] WlanDisconnectEvt: STA disconnected from AP (Code=204)
    13:03:23.142> [WLAN] WlanDisconnectEvt: STA disconnected from AP (Code=204)
    13:03:27.454> [WLAN] WlanDisconnectEvt: STA disconnected from AP (Code=204)
    13:03:31.766> [WLAN] WlanDisconnectEvt: STA disconnected from AP (Code=204)
    13:03:34.391> ... 3 (sleep 20sec; disconnect)
    13:03:34.391> [WLAN] WlanDisconnectEvt: STA disconnected from AP (Code=2)
    13:03:54.389> ... 4 (connect with right password)
    13:03:54.639> [WLAN] Set to STA mode done
    13:03:54.639> [WLAN] STA connecting
    13:03:55.014> [WLAN] WlanConnectEvt: STA connected to AP (SSID=AP2, BSSID=10-fe-ed-a8-50-6e)
    13:03:55.014> [WLAN] NetAppIPv4AcquiredEvt: IP was acquired (IP=192.168.1.4)
    13:03:55.014> [WLAN] STA connected to AP
    13:03:55.092> [WLAN] STA acquired IP

    Jan

  • Hello!

    Result depends on router. For example:

    With ASUS RT-N10PV2 second connection (with correct password) fails in 1-2%

    With ASUS RT-N56U - in 60%

    With iPhone 5SE (as AP) - in 99%

    P.S. Why you got 4 'WlanDisconnectEvt' on first try and 'Set to STA mode done' on second try?

    P.S.S. If i turn on router "Asus-1", call sl_WlanGetNetworkList (0, 20, &netEntries[0]), "Asus-1" will be returned in netEntries. Then i turn off router "Asus-1" and call sl_WlanGetNetworkList() again, "Asus-1" will be returned in netEntries, that is unexpected. I'm sure, that new scan was processed, because returned RSSI of other AP's was changed. If i call sl_Stop/sl_Start before sl_WlanGetNetworkList() - all ok.

    Where can i find full list of situations, then i must restart NWP to avoid such bugs? 

  • Hi,

    Sorry I have not available APs that you are using. From this reason I am not able test this. But I am slightly surprised that in corporate segment you are using such kind of low-cost APs. But this is not important. I done some quick tests with APs which I have at home. And all worked properly. I done tests with:

    • Ubiquiti UniFi AC PRO
    • Asus RT-N12B with DD-WRT v3.0-r33215M
    • TP-Link TL-WR741ND v4 with OpenWrt 18.06.2
    • cell phone LG V30 in AP mode

    - Returning event 'WlanDisconnectEvt' with reason code 204 (=SL_WLAN_DISCONNECT_SECURITY_FAILURE) is normal and is returned due to unsuccessful authentication attempt to the AP.

    - Entries from sl_WlanGetNetworkList() API are returned according pre-set scan interval from API sl_WlanPolicySet(SL_WLAN_POLICY_SCAN,...). I am not sure how yours scan policy are set. Was changed count of found APs from sl_WlanGetNetworkList()?

    - Just to be sure. Do you use latest SDK and ServicePack inside your device?

    If you are convinced that your issue is related to type of used AP, it slightly change situation that was described at first post. It can be some kind of interoperability issue. From my point of view it does not look like that, but I don't have all information as you have. If you suppose so, you may to open new thread with additional information:

    • detail description of issue, you can provide link to this thread as well
    • captured NWP log
    • captured log from wireless sniffer

    Jan