Skip to content

Commit

Permalink
RDK-55421 : Implementation of new API - org.rdk.Wifi.retrieveSSID
Browse files Browse the repository at this point in the history
Reason for change: Implemented new API org.rdk.Wifi.retrieveSSID
Test Procedure: Call org.rdk.Wifi.retrieveSSID and verify that the
retrieved credentials are the same as those stored on the device.
  • Loading branch information
Anand73-n committed Jan 16, 2025
1 parent e95c29e commit c467d55
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,12 @@ add_library(${PLUGIN_LEGACY_DEPRECATED_NETWORK} SHARED
NetworkManagerLogger.cpp
Module.cpp
)
target_include_directories(${PLUGIN_LEGACY_DEPRECATED_NETWORK} PRIVATE ${IARMBUS_INCLUDE_DIRS})

target_link_libraries(${PLUGIN_LEGACY_DEPRECATED_NETWORK} PRIVATE
${NAMESPACE}Core::${NAMESPACE}Core
${NAMESPACE}Plugins::${NAMESPACE}Plugins
${IARMBUS_LIBRARIES}
)

if (USE_RDK_LOGGER)
Expand Down
68 changes: 68 additions & 0 deletions LegacyPlugin_WiFiManagerAPIs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "LegacyPlugin_WiFiManagerAPIs.h"
#include "NetworkManagerLogger.h"
#include "NetworkManagerJsonEnum.h"
#include "libIBus.h"

using namespace std;
using namespace WPEFramework::Plugin;
Expand All @@ -28,6 +29,11 @@ using namespace WPEFramework::Plugin;
#define NETWORK_MANAGER_CALLSIGN "org.rdk.NetworkManager.1"
#define SUBSCRIPTION_TIMEOUT_IN_MILLISECONDS 500

#define IARM_BUS_NM_SRV_MGR_NAME "NET_SRV_MGR"
#define IARM_BUS_MFRLIB_NAME "MFRLib"
#define IARM_BUS_MFRLIB_API_WIFI_Credentials "mfrWifiCredentials"


#define LOG_INPARAM() { string json; parameters.ToString(json); NMLOG_INFO("params=%s", json.c_str() ); }
#define LOG_OUTPARAM() { string json; response.ToString(json); NMLOG_INFO("response=%s", json.c_str() ); }

Expand Down Expand Up @@ -209,6 +215,7 @@ namespace WPEFramework
Register("saveSSID", &WiFiManager::saveSSID, this);
Register("startScan", &WiFiManager::startScan, this);
Register("stopScan", &WiFiManager::stopScan, this);
Register("retrieveSSID", &WiFiManager::retrieveSSID, this);
}

/**
Expand All @@ -230,6 +237,7 @@ namespace WPEFramework
Unregister("saveSSID");
Unregister("startScan");
Unregister("stopScan");
Unregister("retrieveSSID");
}

uint32_t WiFiManager::cancelWPSPairing (const JsonObject& parameters, JsonObject& response)
Expand Down Expand Up @@ -305,6 +313,66 @@ namespace WPEFramework
returnJson(rc);
}

uint32_t WiFiManager::retrieveSSID (const JsonObject& parameters, JsonObject& response)
{
LOG_INPARAM();
uint32_t rc = Core::ERROR_GENERAL;

IARM_Result_t retval = IARM_RESULT_SUCCESS;
IARM_BUS_MFRLIB_API_WIFI_Credentials_Param_t param{0};

param.requestType = WIFI_GET_CREDENTIALS;
if (IARM_RESULT_SUCCESS == IARM_Bus_Call(IARM_BUS_MFRLIB_NAME, IARM_BUS_MFRLIB_API_WIFI_Credentials, (void *) &param, sizeof(param)))
{
rc = Core::ERROR_NONE;
if (Core::ERROR_NONE == rc)
{
response["ssid"] = param.wifiCredentials.cSSID;
response["passphrase"] = "[HIDDEN]"; // passphrase hidden for logging
response["securityMode"] = JsonValue(param.wifiCredentials.iSecurityMode);
response["success"] = true;

string json;
response.ToString(json);
NMLOG_INFO("response=%s", json.c_str());

response["passphrase"] = param.wifiCredentials.cPassword;// overwrite with correct passphrase after logging
}
NMLOG_INFO ("RetrieveSSID Success");
NMLOG_INFO ("SSID: %s, passphrase: %s, security mode: %d", param.wifiCredentials.cSSID,
param.wifiCredentials.cPassword, (WIFISecurityMode) param.wifiCredentials.iSecurityMode);
}
else
NMLOG_ERROR ("RetrieveSSID Failed");

return rc;
/*auto _nwmgr = m_service->QueryInterfaceByCallsign<Exchange::INetworkManager>(NETWORK_MANAGER_CALLSIGN);
if (_nwmgr)
{
rc = _nwmgr->RetrieveSSID(credInfo);
_nwmgr->Release();
}
else
rc = Core::ERROR_UNAVAILABLE;
if (Core::ERROR_NONE == rc)
{
response["ssid"] = credInfo.ssid;
response["passphrase"] = "[HIDDEN]"; // passphrase hidden for logging
response["securityMode"] = JsonValue(credInfo.security);
response["success"] = true;
string json;
response.ToString(json);
NMLOG_INFO("response=%s", json.c_str());
response["passphrase"] = credInfo.passphrase; // overwrite with correct passphrase after logging
}
else
response["success"] = false;
return rc;*/
}

uint32_t WiFiManager::getConnectedSSID (const JsonObject& parameters, JsonObject& response)
{
LOG_INPARAM();
Expand Down
62 changes: 62 additions & 0 deletions LegacyPlugin_WiFiManagerAPIs.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "Module.h"
#include "NetworkManagerTimer.h"
#include "libIBus.h"

/*! Error code: A recoverable, unexpected error occurred,
* as defined by one of the following values */
Expand All @@ -35,6 +36,66 @@ typedef enum _WiFiErrorCode_t {
WIFI_AUTH_FAILED /**< The connection failed due to auth failure */
} WiFiErrorCode_t;

#define WIFI_MAX_PASSWORD_LEN 64
#define SSID_SIZE 32

enum WIFISecurityMode : uint8_t
{
WIFI_SECURITY_NONE,
WIFI_SECURITY_WEP_64,
WIFI_SECURITY_WEP_128,
WIFI_SECURITY_WPA_PSK_TKIP,
WIFI_SECURITY_WPA_PSK_AES,
WIFI_SECURITY_WPA2_PSK_TKIP,
WIFI_SECURITY_WPA2_PSK_AES,
WIFI_SECURITY_WPA_ENTERPRISE_TKIP,
WIFI_SECURITY_WPA_ENTERPRISE_AES,
WIFI_SECURITY_WPA2_ENTERPRISE_TKIP,
WIFI_SECURITY_WPA2_ENTERPRISE_AES,
WIFI_SECURITY_WPA_WPA2_PSK,
WIFI_SECURITY_WPA_WPA2_ENTERPRISE,
WIFI_SECURITY_WPA3_PSK_AES,
WIFI_SECURITY_WPA3_SAE
};

/**
* @brief WIFI API return status
*
*/
typedef enum _WIFI_API_RESULT
{
WIFI_API_RESULT_SUCCESS = 0, ///< operation is successful
WIFI_API_RESULT_FAILED, ///< Operation general error. This enum is deprecated
WIFI_API_RESULT_NULL_PARAM, ///< NULL argument is passed to the module
WIFI_API_RESULT_INVALID_PARAM, ///< Invalid argument is passed to the module
WIFI_API_RESULT_NOT_INITIALIZED, ///< module not initialized
WIFI_API_RESULT_OPERATION_NOT_SUPPORTED, ///< operation not supported in the specific platform
WIFI_API_RESULT_READ_WRITE_FAILED, ///< flash read/write failed or crc check failed
WIFI_API_RESULT_MAX ///< Out of range - required to be the last item of the enum
} WIFI_API_RESULT;
/**
* @brief WIFI credentials data struct
*
*/
typedef struct
{
char cSSID[SSID_SIZE]; ///< SSID field.
char cPassword[WIFI_MAX_PASSWORD_LEN+1]; ///< password field
int iSecurityMode; ///< security mode. Platform dependent and caller is responsible to validate it
} WIFI_DATA;

typedef enum _WifiRequestType
{
WIFI_GET_CREDENTIALS = 0,
WIFI_SET_CREDENTIALS = 1
} WifiRequestType_t;

typedef struct _IARM_BUS_MFRLIB_API_WIFI_Credentials_Param_t{
WIFI_DATA wifiCredentials;
WifiRequestType_t requestType;
WIFI_API_RESULT returnVal;
}IARM_BUS_MFRLIB_API_WIFI_Credentials_Param_t;

namespace WPEFramework {

namespace Plugin {
Expand Down Expand Up @@ -73,6 +134,7 @@ namespace WPEFramework {
uint32_t getPairedSSIDInfo(const JsonObject& parameters, JsonObject& response);
uint32_t isPaired(const JsonObject& parameters, JsonObject& response);
uint32_t getSupportedSecurityModes(const JsonObject& parameters, JsonObject& response);
uint32_t retrieveSSID(const JsonObject& parameters, JsonObject& response);
//End methods

//Begin events
Expand Down

0 comments on commit c467d55

Please sign in to comment.