src/services/wifi/src/wifiHalUtiles.cpp
/* Callback function to connect to wifi */
Callback function to connect to wifi
Callback function to connect to wifi
int laf_wifi_connect(laf_wifi_ssid_t* const wificred)
{
    int retry = 0;
    bool retVal=false;
    int ssidIndex=1;
    bool notify = false;
    RDK_LOG( RDK_LOG_TRACE1, LOG_NMGR, "[%s:%s:%d] Enter\n", MODULE_NAME,__FUNCTION__, __LINE__ );
    if (laf_is_lnfssid(wificred->ssid) && (true == isLAFCurrConnectedssid) && (WIFI_CONNECTED == get_WifiRadioStatus()))
    {
        RDK_LOG( RDK_LOG_INFO, LOG_NMGR, "[%s:%s:%d] Already connected to LF ssid Ignoring the request \n", MODULE_NAME,__FUNCTION__, __LINE__ );
        return 0;
    }
    if(bStopLNFWhileDisconnected)
    {
        RDK_LOG( RDK_LOG_INFO, LOG_NMGR, "[%s:%s:%d] Already WPS flow has intiated so skipping the request the request \n", MODULE_NAME,__FUNCTION__, __LINE__ );
        return EPERM;
    }
    if (laf_is_lnfssid(wificred->ssid))
    {
        bLNFConnect=true;
    }
    else
    {
        bLNFConnect=false;
        retVal=lastConnectedSSID(&savedWiFiConnList);
        if (retVal && savedWiFiConnList.ssidSession.ssid[0] != '\0')
        {
          if((strcmp(wificred->ssid, savedWiFiConnList.ssidSession.ssid) != 0) && (strcmp(wificred->passphrase, savedWiFiConnList.ssidSession.passphrase) != 0))
          {
            RDK_LOG(RDK_LOG_INFO, LOG_NMGR, "[%s:%s:%d] Lnf response status Credentials changed : BOTH \n", MODULE_NAME,__FUNCTION__, __LINE__ );
          }
          else if(strcmp(wificred->ssid, savedWiFiConnList.ssidSession.ssid) != 0)
          {
            RDK_LOG(RDK_LOG_INFO, LOG_NMGR, "[%s:%s:%d] Lnf response status Credentials changed : SSID \n", MODULE_NAME,__FUNCTION__, __LINE__ );
          }
          else if(strcmp(wificred->passphrase, savedWiFiConnList.ssidSession.passphrase) != 0)
          {
            RDK_LOG(RDK_LOG_INFO, LOG_NMGR, "[%s:%s:%d] Lnf response status Credentials changed : KeyPassphrase \n", MODULE_NAME,__FUNCTION__, __LINE__ );
          }
        }
    }
#ifdef USE_RDK_WIFI_HAL
    if(gWifiLNFStatus != CONNECTED_PRIVATE)
    {
         setLNFState(LNF_IN_PROGRESS);
         if((bLNFConnect == true) && (RETURN_OK != wifi_disconnectEndpoint(1, wifiConnData.ssid)))
         {
            RDK_LOG( RDK_LOG_ERROR, LOG_NMGR, "[%s:%d] Failed to  Disconnect in wifi_disconnectEndpoint()", __FUNCTION__, __LINE__);
         }
        retVal=connect_withSSID(ssidIndex, wificred->ssid, (SsidSecurity)wificred->security_mode, NULL, wificred->psk, wificred->passphrase, (int)(!bLNFConnect),wificred->identity,wificred->carootcert,wificred->clientcert,wificred->privatekey,bLNFConnect ? WIFI_CON_LNF : WIFI_CON_PRIVATE);
    }
#endif
    if(false == retVal)
    {
        RDK_LOG( RDK_LOG_ERROR, LOG_NMGR, "[%s:%s:%d] connect with ssid %s failed \n",
                MODULE_NAME, __FUNCTION__, __LINE__, wificred->ssid);
        RDK_LOG( RDK_LOG_DEBUG, LOG_NMGR, "[%s:%s:%d] connect with ssid %s failed (passphrase %s)\n",
                MODULE_NAME, __FUNCTION__, __LINE__, wificred->ssid, wificred->passphrase );
        return EPERM;
    }
    while(get_WifiRadioStatus() != WIFI_CONNECTED && retry <= confProp.wifiProps.lnfRetryCount) {
        retry++; 
        if(bStopLNFWhileDisconnected)
        {
            RDK_LOG( RDK_LOG_INFO, LOG_NMGR, "[%s:%s:%d] Already WPS flow has intiated so skipping the request the request \n", MODULE_NAME,__FUNCTION__, __LINE__ );
            return EPERM;
        }
        sleep(1);
        RDK_LOG( RDK_LOG_TRACE1, LOG_NMGR, "[%s:%s:%d] Device not connected to wifi. waiting to connect... \n", MODULE_NAME,__FUNCTION__, __LINE__ );
    }
    if(retry > confProp.wifiProps.lnfRetryCount) {
        RDK_LOG( RDK_LOG_ERROR, LOG_NMGR, "[%s:%s:%d] Waited for %d seconds. Failed to connect. Abort \n", MODULE_NAME,__FUNCTION__, __LINE__, confProp.wifiProps.lnfRetryCount);
        return EPERM;
    }
    if(! laf_is_lnfssid(wificred->ssid))
    {
        setLNFState(CONNECTED_PRIVATE);
        notify = true;
    }
    RDK_LOG( RDK_LOG_TRACE1, LOG_NMGR, "[%s:%s:%d] Exit\n", MODULE_NAME,__FUNCTION__, __LINE__ );
    return 0;
}
int laf_wifi_connect ( laf_wifi_ssid_t * const wificred ) { int retry = 0 ; bool retVal = false ; int ssidIndex = 1 ; bool notify = false ; RDK_LOG ( RDK_LOG_TRACE1 , LOG_NMGR , " \n " , MODULE_NAME , __FUNCTION__ , __LINE__ ) ; if ( laf_is_lnfssid ( wificred -> ssid ) && ( true == isLAFCurrConnectedssid ) && ( WIFI_CONNECTED == get_WifiRadioStatus ( ) ) ) { RDK_LOG ( RDK_LOG_INFO , LOG_NMGR , " \n " , MODULE_NAME , __FUNCTION__ , __LINE__ ) ; return 0 ; } if ( bStopLNFWhileDisconnected ) { RDK_LOG ( RDK_LOG_INFO , LOG_NMGR , " \n " , MODULE_NAME , __FUNCTION__ , __LINE__ ) ; return EPERM ; } if ( laf_is_lnfssid ( wificred -> ssid ) ) { bLNFConnect = true ; } else { bLNFConnect = false ; retVal = lastConnectedSSID ( & savedWiFiConnList ) ; if ( retVal && savedWiFiConnList . ssidSession . ssid [ 0 ] != ' \0 ' ) { if ( ( strcmp ( wificred -> ssid , savedWiFiConnList . ssidSession . ssid ) != 0 ) && ( strcmp ( wificred -> passphrase , savedWiFiConnList . ssidSession . passphrase ) != 0 ) ) { RDK_LOG ( RDK_LOG_INFO , LOG_NMGR , " \n " , MODULE_NAME , __FUNCTION__ , __LINE__ ) ; } else if ( strcmp ( wificred -> ssid , savedWiFiConnList . ssidSession . ssid ) != 0 ) { RDK_LOG ( RDK_LOG_INFO , LOG_NMGR , " \n " , MODULE_NAME , __FUNCTION__ , __LINE__ ) ; } else if ( strcmp ( wificred -> passphrase , savedWiFiConnList . ssidSession . passphrase ) != 0 ) { RDK_LOG ( RDK_LOG_INFO , LOG_NMGR , " \n " , MODULE_NAME , __FUNCTION__ , __LINE__ ) ; } } } #ifdef USE_RDK_WIFI_HAL if ( gWifiLNFStatus != CONNECTED_PRIVATE ) { setLNFState ( LNF_IN_PROGRESS ) ; if ( ( bLNFConnect == true ) && ( RETURN_OK != wifi_disconnectEndpoint ( 1 , wifiConnData . ssid ) ) ) { RDK_LOG ( RDK_LOG_ERROR , LOG_NMGR , " " , __FUNCTION__ , __LINE__ ) ; } retVal = connect_withSSID ( ssidIndex , wificred -> ssid , ( SsidSecurity ) wificred -> security_mode , NULL , wificred -> psk , wificred -> passphrase , ( int ) ( ! bLNFConnect ) , wificred -> identity , wificred -> carootcert , wificred -> clientcert , wificred -> privatekey , bLNFConnect ? WIFI_CON_LNF : WIFI_CON_PRIVATE ) ; } #endif if ( false == retVal ) { RDK_LOG ( RDK_LOG_ERROR , LOG_NMGR , " \n " , MODULE_NAME , __FUNCTION__ , __LINE__ , wificred -> ssid ) ; RDK_LOG ( RDK_LOG_DEBUG , LOG_NMGR , " \n " , MODULE_NAME , __FUNCTION__ , __LINE__ , wificred -> ssid , wificred -> passphrase ) ; return EPERM ; } while ( get_WifiRadioStatus ( ) != WIFI_CONNECTED && retry <= confProp . wifiProps . lnfRetryCount ) { retry ++ ; if ( bStopLNFWhileDisconnected ) { RDK_LOG ( RDK_LOG_INFO , LOG_NMGR , " \n " , MODULE_NAME , __FUNCTION__ , __LINE__ ) ; return EPERM ; } sleep ( 1 ) ; RDK_LOG ( RDK_LOG_TRACE1 , LOG_NMGR , " \n " , MODULE_NAME , __FUNCTION__ , __LINE__ ) ; } if ( retry > confProp . wifiProps . lnfRetryCount ) { RDK_LOG ( RDK_LOG_ERROR , LOG_NMGR , " \n " , MODULE_NAME , __FUNCTION__ , __LINE__ , confProp . wifiProps . lnfRetryCount ) ; return EPERM ; } if ( ! laf_is_lnfssid ( wificred -> ssid ) ) { setLNFState ( CONNECTED_PRIVATE ) ; notify = true ; } RDK_LOG ( RDK_LOG_TRACE1 , LOG_NMGR , " \n " , MODULE_NAME , __FUNCTION__ , __LINE__ ) ; return 0 ; }
Callback function to connect to wifi
Callback function to connect to wifi
/* call api to connect to wifi */ //    retVal=connect_withSSID(ssidIndex, wificred->ssid, NET_WIFI_SECURITY_NONE, NULL, NULL, wificred->psk); //  } //max wait for 180 seconds /* Bounce xre session only if switching from LF to private */ //        sleep(10); //waiting for default route before bouncing the xre connection //        RDK_LOG( RDK_LOG_INFO, LOG_NMGR, "[%s:%s:%d] Connecting private ssid. Bouncing xre connection.\n", MODULE_NAME,__FUNCTION__, __LINE__ ); //#ifdef ENABLE_IARM //        if(false == setHostifParam(XRE_REFRESH_SESSION ,hostIf_BooleanType ,(void *)&notify)) //        { //            RDK_LOG( RDK_LOG_ERROR, LOG_NMGR, "[%s:%s:%d] refresh xre session failed .\n", MODULE_NAME,__FUNCTION__, __LINE__); //        } //#endif