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 15, 2025
1 parent e95c29e commit 3811c30
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 0 deletions.
1 change: 1 addition & 0 deletions INetworkManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ namespace WPEFramework
virtual uint32_t WiFiConnect(const WiFiConnectTo& ssid /* @in */) = 0;
virtual uint32_t WiFiDisconnect(void) = 0;
virtual uint32_t GetConnectedSSID(WiFiSSIDInfo& ssidInfo /* @out */) = 0;
virtual uint32_t RetrieveSSID(WiFiConnectTo& credInfo /* @out */) = 0;

virtual uint32_t StartWPS(const WiFiWPS& method /* @in */, const string& pin /* @in */) = 0;
virtual uint32_t StopWPS(void) = 0;
Expand Down
34 changes: 34 additions & 0 deletions LegacyPlugin_WiFiManagerAPIs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,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 +231,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 +307,38 @@ namespace WPEFramework
returnJson(rc);
}

uint32_t WiFiManager::retrieveSSID (const JsonObject& parameters, JsonObject& response)
{
LOG_INPARAM();
uint32_t rc = Core::ERROR_GENERAL;
Exchange::INetworkManager::WiFiConnectTo credInfo{};
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
1 change: 1 addition & 0 deletions LegacyPlugin_WiFiManagerAPIs.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,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
1 change: 1 addition & 0 deletions NetworkManagerImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ namespace WPEFramework
uint32_t WiFiConnect(const WiFiConnectTo& ssid /* @in */) override;
uint32_t WiFiDisconnect(void) override;
uint32_t GetConnectedSSID(WiFiSSIDInfo& ssidInfo /* @out */) override;
uint32_t RetrieveSSID(WiFiConnectTo& credInfo /* @out */) override;

uint32_t StartWPS(const WiFiWPS& method /* @in */, const string& wps_pin /* @in */) override;
uint32_t StopWPS(void) override;
Expand Down
66 changes: 66 additions & 0 deletions NetworkManagerRDKProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace WPEC = WPEFramework::Core;
namespace WPEJ = WPEFramework::Core::JSON;

#define IARM_BUS_NM_SRV_MGR_NAME "NET_SRV_MGR"
#define IARM_BUS_MFRLIB_NAME "MFRLib"

#define MAX_IP_ADDRESS_LEN 46
#define NETSRVMGR_INTERFACES_MAX 16
Expand Down Expand Up @@ -38,6 +39,8 @@ namespace WPEJ = WPEFramework::Core::JSON;
#define MAX_SSIDLIST_BUF (48*1024)
#define MAX_FILE_PATH_LEN 4096

#define WIFI_MAX_PASSWORD_LEN 64

typedef enum _NetworkManager_EventId_t {
IARM_BUS_NETWORK_MANAGER_EVENT_SET_INTERFACE_ENABLED=50,
IARM_BUS_NETWORK_MANAGER_EVENT_SET_INTERFACE_CONTROL_PERSISTENCE,
Expand Down Expand Up @@ -82,6 +85,45 @@ typedef enum _NetworkManager_GetIPSettings_ErrorCode_t
NETWORK_INVALID_IPADDRESS,
} NetworkManager_GetIPSettings_ErrorCode_t;

/**
* @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;

typedef struct {
char interface[16];
char ipversion[16];
Expand Down Expand Up @@ -352,6 +394,7 @@ typedef struct _IARM_Bus_WiFiSrvMgr_SsidList_Param_t {
#define IARM_BUS_WIFI_MGR_API_connect "connect" /**< Connect with given or saved SSID and passphrase */
#define IARM_BUS_WIFI_MGR_API_disconnectSSID "disconnectSSID" /**< Disconnect from current SSID */
#define IARM_BUS_WIFI_MGR_API_getCurrentState "getCurrentState" /**< Retrieve current state */
#define IARM_BUS_MFRLIB_API_WIFI_Credentials "mfrWifiCredentials" /**< Retrieve Wifi Credentials */

namespace WPEFramework
{
Expand Down Expand Up @@ -1269,6 +1312,29 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN+1] = {
return rc;
}

uint32_t NetworkManagerImplementation::RetrieveSSID(WiFiConnectTo& credInfo /* @out */)
{
LOG_ENTRY_FUNCTION();
uint32_t rc = Core::ERROR_RPC_CALL_FAILED;
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)))
{
credInfo.ssid = param.wifiCredentials.cSSID;
credInfo.passphrase = param.wifiCredentials.cPassword;
credInfo.security = (WIFISecurityMode) param.wifiCredentials.iSecurityMode;
NMLOG_INFO ("RetrieveSSID Success");
NMLOG_DEBUG ("SSID: %s, passphrase: %s, security mode: %d", param.wifiCredentials.cSSID,
param.wifiCredentials.cPassword, (WIFISecurityMode) param.wifiCredentials.iSecurityMode);
rc = Core::ERROR_NONE;
}
else
NMLOG_ERROR ("RetrieveSSID Failed");
return rc;
}


uint32_t NetworkManagerImplementation::GetConnectedSSID(WiFiSSIDInfo& ssidInfo /* @out */)
{
LOG_ENTRY_FUNCTION();
Expand Down

0 comments on commit 3811c30

Please sign in to comment.