RDK Documentation (Open Sourced RDK Components)
Device_WiFi_SSID.cpp
Go to the documentation of this file.
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2018 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 
21 /**
22  * @file Device_WiFi_SSID.cpp
23  *
24  * @brief Device_WiFi_SSID API Implementation.
25  *
26  * This is the implementation of the WiFi API.
27  *
28  * @par Document
29  */
30 /** @addtogroup TR-069 WiFi Implementation
31  * This is the implementation of the Device Public API.
32  * @{
33  */
34 
35 /*****************************************************************************
36  * STANDARD INCLUDE FILES
37  *****************************************************************************/
38 #include <cstddef>
39 #include "safec_lib.h"
40 #ifdef USE_WIFI_PROFILE
41 
42 #include "Device_WiFi_SSID.h"
43 extern "C" {
44  /* #include "c_only_header.h"*/
45 #include "wifi_common_hal.h"
46 #include "wifiSrvMgrIarmIf.h"
47 };
48 
49 static time_t firstExTime = 0;
50 
51 GHashTable* hostIf_WiFi_SSID::ifHash = NULL;
52 
53 hostIf_WiFi_SSID* hostIf_WiFi_SSID::getInstance(int dev_id)
54 {
55  static hostIf_WiFi_SSID* pRet = NULL;
56 
57  if(ifHash)
58  {
59  pRet = (hostIf_WiFi_SSID *)g_hash_table_lookup(ifHash,(gpointer) dev_id);
60  }
61  else
62  {
63  ifHash = g_hash_table_new(NULL,NULL);
64  }
65 
66  if(!pRet)
67  {
68  try {
69  pRet = new hostIf_WiFi_SSID(dev_id);
70  } catch(int e)
71  {
72  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"Caught exception, not able create hostIf_WiFi_SSID instance..\n");
73  }
74  g_hash_table_insert(ifHash, (gpointer)dev_id, pRet);
75  }
76  return pRet;
77 }
78 
79 GList* hostIf_WiFi_SSID::getAllInstances()
80 {
81  if(ifHash)
82  return g_hash_table_get_keys(ifHash);
83  return NULL;
84 }
85 
86 void hostIf_WiFi_SSID::closeInstance(hostIf_WiFi_SSID *pDev)
87 {
88  if(pDev)
89  {
90  g_hash_table_remove(ifHash, (gconstpointer)pDev->dev_id);
91  delete pDev;
92  }
93 }
94 
95 void hostIf_WiFi_SSID::closeAllInstances()
96 {
97  if(ifHash)
98  {
99  GList* tmp_list = g_hash_table_get_values (ifHash);
100 
101  while(tmp_list)
102  {
103  hostIf_WiFi_SSID* pDev = (hostIf_WiFi_SSID *)tmp_list->data;
104  tmp_list = tmp_list->next;
105  closeInstance(pDev);
106  }
107  }
108 }
109 
110 
111 
112 hostIf_WiFi_SSID::hostIf_WiFi_SSID(int dev_id):
113  enable(false),
114  LastChange(0)
115 {
116  memset(status,0 , sizeof(status)); //CID:103996 - OVERRUN
117  memset(alias, 0, sizeof(alias)); //CID:103531 - OVERRUN
118  memset(name,0, sizeof(name));
119  memset(LowerLayers,0, sizeof(LowerLayers));
120  memset(BSSID,0, sizeof(BSSID));
121  memset(MACAddress,0, sizeof(MACAddress));
122  memset(SSID,0, sizeof(SSID)); //CID:103108 - OVERRUN
123 }
124 
125 int hostIf_WiFi_SSID::get_Device_WiFi_SSID_Fields(int ssidIndex)
126 {
127  errno_t rc = -1;
128  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
129  IARM_BUS_WiFi_DiagsPropParam_t param = {0};
130  int ret;
131  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
132 
133  hostIf_WiFi_SSID *pDev = hostIf_WiFi_SSID::getInstance(dev_id);
134  if (pDev)
135  {
136  retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_getSSIDProps, (void *)&param, sizeof(param));
137  if (IARM_RESULT_SUCCESS != retVal)
138  {
139  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] IARM BUS CALL failed with : %d.\n", __FILE__, __FUNCTION__, retVal);
140  return NOK;
141  }
142  rc=strcpy_s(name,sizeof(name),param.data.ssid.params.name);
143  if(rc!=EOK)
144  {
145  ERR_CHK(rc);
146  }
147  rc=strcpy_s(BSSID,sizeof(BSSID),param.data.ssid.params.bssid);
148  if(rc!=EOK)
149  {
150  ERR_CHK(rc);
151  }
152  rc=strcpy_s(MACAddress,sizeof(MACAddress),param.data.ssid.params.macaddr);
153  if(rc!=EOK)
154  {
155  ERR_CHK(rc);
156  }
157  rc=strcpy_s(SSID,sizeof(SSID),param.data.ssid.params.ssid);
158  if(rc!=EOK)
159  {
160  ERR_CHK(rc);
161  }
162  rc=strcpy_s(status,sizeof(status),param.data.ssid.params.status);
163  if(rc!=EOK)
164  {
165  ERR_CHK(rc);
166  }
167  enable=param.data.ssid.params.enable;
168  firstExTime = time (NULL);
169  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
170  return OK;
171  }
172  else
173  {
174  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s]Error! Unable to connect to wifi instance\n", __FILE__, __FUNCTION__);
175  return NOK;
176  }
177 }
178 
179 void hostIf_WiFi_SSID::checkWifiSSIDFetch(int ssidIndex)
180 {
181  int ret = NOK;
182  time_t currExTime = time (NULL);
183  if ((currExTime - firstExTime ) > QUERY_INTERVAL)
184  {
185  ret = get_Device_WiFi_SSID_Fields(ssidIndex);
186  if( OK != ret)
187  {
188  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] Failed to fetch : %d.\n", __FILE__, __FUNCTION__, ret);
189  }
190  }
191 }
192 
193 int hostIf_WiFi_SSID::get_Device_WiFi_SSID_Enable(HOSTIF_MsgData_t *stMsgData )
194 {
195  int ssidIndex=1;
196  int ret=OK;
197  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
198  checkWifiSSIDFetch(ssidIndex);
199  put_boolean(stMsgData->paramValue, enable);
200  stMsgData->paramtype = hostIf_BooleanType;
201  stMsgData->paramLen=1;
202  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
203 
204  return ret;
205 }
206 int hostIf_WiFi_SSID::set_Device_WiFi_SSID_Enable(HOSTIF_MsgData_t *stMsgData )
207 {
208  return OK;
209 }
210 
211 int hostIf_WiFi_SSID::get_Device_WiFi_SSID_Status(HOSTIF_MsgData_t *stMsgData )
212 {
213  char ssidStatus[32] = "Down";
214  int ret = OK;
215  int ssidIndex=1;
216 
217  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
218  checkWifiSSIDFetch(ssidIndex);
219  stMsgData->paramtype = hostIf_StringType;
220  stMsgData->paramLen = strlen(status);
221  snprintf(stMsgData->paramValue, TR69HOSTIFMGR_MAX_PARAM_LEN, status);
222 
223  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
224 
225  return ret;
226 }
227 
228 int hostIf_WiFi_SSID::get_Device_WiFi_SSID_Alias(HOSTIF_MsgData_t *stMsgData )
229 {
230  return OK;
231 }
232 int hostIf_WiFi_SSID::set_Device_WiFi_SSID_Alias(HOSTIF_MsgData_t *stMsgData )
233 {
234  return OK;
235 }
236 
237 int hostIf_WiFi_SSID::get_Device_WiFi_SSID_Name(HOSTIF_MsgData_t *stMsgData )
238 {
239  int ssidIndex=1;
240  int ret=OK;
241  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
242  checkWifiSSIDFetch(ssidIndex);
243  snprintf(stMsgData->paramValue, TR69HOSTIFMGR_MAX_PARAM_LEN, name);
244  stMsgData->paramtype = hostIf_StringType;
245  stMsgData->paramLen = strlen(name);
246  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
247  return OK;
248 }
249 
250 int hostIf_WiFi_SSID::get_Device_WiFi_SSID_LastChange(HOSTIF_MsgData_t *stMsgData )
251 {
252  return OK;
253 }
254 
255 int hostIf_WiFi_SSID::get_Device_WiFi_SSID_LowerLayers(HOSTIF_MsgData_t *stMsgData )
256 {
257  return OK;
258 }
259 
260 int hostIf_WiFi_SSID::set_Device_WiFi_SSID_LowerLayers(HOSTIF_MsgData_t *stMsgData )
261 {
262  return OK;
263 }
264 
265 int hostIf_WiFi_SSID::hostIf_WiFi_SSID::get_Device_WiFi_SSID_BSSID(HOSTIF_MsgData_t *stMsgData )
266 {
267 
268  int ssidIndex=1;
269  int ret=OK;
270  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
271  checkWifiSSIDFetch(ssidIndex);
272  snprintf(stMsgData->paramValue, TR69HOSTIFMGR_MAX_PARAM_LEN, BSSID);
273  stMsgData->paramtype = hostIf_StringType;
274  stMsgData->paramLen = strlen(BSSID);
275  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
276 
277  return ret;
278 }
279 
280 int hostIf_WiFi_SSID::hostIf_WiFi_SSID::get_Device_WiFi_SSID_MACAddress(HOSTIF_MsgData_t *stMsgData )
281 {
282  int ssidIndex=1;
283  int ret=OK;
284  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
285  checkWifiSSIDFetch(ssidIndex);
286  snprintf(stMsgData->paramValue, TR69HOSTIFMGR_MAX_PARAM_LEN, MACAddress);
287  stMsgData->paramtype = hostIf_StringType;
288  stMsgData->paramLen = strlen(MACAddress);
289  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
290  return ret;
291 }
292 
293 int hostIf_WiFi_SSID::get_Device_WiFi_SSID_SSID(HOSTIF_MsgData_t *stMsgData )
294 {
295  int ssidIndex=1;
296  int ret=OK;
297  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
298  checkWifiSSIDFetch(ssidIndex);
299  snprintf(stMsgData->paramValue,TR69HOSTIFMGR_MAX_PARAM_LEN, SSID);
300  stMsgData->paramtype = hostIf_StringType;
301  stMsgData->paramLen = strlen(SSID);
302  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
303 
304  return ret;
305 }
306 int hostIf_WiFi_SSID::set_Device_WiFi_SSID_SSID(HOSTIF_MsgData_t *stMsgData )
307 {
308  return OK;
309 }
310 
311 #endif /* #ifdef USE_WIFI_PROFILE */
312 
IARM_Bus_Call
IARM_Result_t IARM_Bus_Call(const char *ownerName, const char *methodName, void *arg, size_t argLen)
This API is used to Invoke RPC method by its application name and method name.
Definition: iarm_bus.c:57
_HostIf_MsgData_t
Definition: hostIf_tr69ReqHandler.h:170
Device_WiFi_SSID.h
put_boolean
void put_boolean(char *ptr, bool val)
This function converts the input data to Boolean type.
Definition: hostIf_utils.cpp:191
_IARM_BUS_WiFi_DiagsPropParam_t
Definition: wifiSrvMgrIarmIf.h:396
_HostIf_MsgData_t::paramtype
HostIf_ParamType_t paramtype
Definition: hostIf_tr69ReqHandler.h:177
RDK_LOG
#define RDK_LOG
Definition: rdk_debug.h:258
_HostIf_MsgData_t::paramValue
char paramValue[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:172
IARM_BUS_WIFI_MGR_API_getSSIDProps
#define IARM_BUS_WIFI_MGR_API_getSSIDProps
Definition: wifiSrvMgrIarmIf.h:85
_HostIf_MsgData_t::paramLen
short paramLen
Definition: hostIf_tr69ReqHandler.h:175