RDK Documentation (Open Sourced RDK Components)
Device_WiFi.cpp
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 #ifdef USE_WIFI_PROFILE
22 
23 /**
24  * @file Device_WiFi.c
25  *
26  * @brief MoCA_Interface API Implementation.
27  *
28  * This is the implementation of the MoCA_Interface API.
29  *
30  * @par Document
31  * TBD Relevant design or API documentation.
32  *
33  */
34 
35 /** @addtogroup MoCA_Interface Implementation
36  * This is the implementation of the Device Public API.
37  * @{
38  */
39 
40 /*****************************************************************************
41  * STANDARD INCLUDE FILES
42  *****************************************************************************/
43 #include "Device_WiFi.h"
44 #include <string.h>
45 #include <math.h>
46 
47 extern "C" {
48  /* #include "c_only_header.h"*/
49 #include "wifi_client_hal.h"
50 #include "wifiSrvMgrIarmIf.h"
51 #include "netsrvmgrIarm.h"
52 };
53 
54 //char *moca_interface = NULL;
55 GHashTable* WiFiDevice::devHash = NULL;
56 GHashTable* hostIf_WiFi::ifHash = NULL;
57 
58 WiFiDevice::WiFiDevice(int dev_id):dev_id(dev_id)
59 {
60 // ctxt = WiFiCtl_Open(interface);
61 
62  if(!ctxt)
63  {
64  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Error! Unable to connect to WiFi Device instance %d\n",dev_id);
65  throw 1;
66  }
67 }
68 
69 WiFiDevice* WiFiDevice::getInstance(int dev_id)
70 {
71  WiFiDevice* pRet = NULL;
72 
73  if(devHash)
74  {
75  pRet = (WiFiDevice *)g_hash_table_lookup(devHash, (gpointer) dev_id);
76  }
77  else
78  {
79  devHash = g_hash_table_new(NULL,NULL);
80  }
81 
82  if(!pRet)
83  {
84  try {
85  pRet = new WiFiDevice(dev_id);
86  } catch(int e)
87  {
88  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"Caught exception, not able create WiFi device instance..\n");
89  }
90  g_hash_table_insert(devHash,(gpointer)dev_id, pRet);
91  }
92  return pRet;
93 }
94 void* WiFiDevice::getContext()
95 {
96  return ctxt;
97 }
98 
99 void WiFiDevice::closeInstance(WiFiDevice *pDev)
100 {
101  if(pDev)
102  {
103  g_hash_table_remove(devHash, (gconstpointer)pDev->dev_id);
104  if(pDev->ctxt)
105  {
106 // WiFiCtl_Close(pDev->ctxt);
107  }
108  delete pDev;
109  }
110 }
111 
112 void WiFiDevice::closeAllInstances()
113 {
114  if(devHash)
115  {
116  GList* tmp_list = g_hash_table_get_values (devHash);
117 
118  while(tmp_list)
119  {
120  WiFiDevice* pDev = (WiFiDevice *)tmp_list->data;
121  tmp_list = tmp_list->next;
122  closeInstance(pDev);
123  }
124  }
125 }
126 
127 //------------------------------------------------------------------------------
128 // init: Perform the necessary operations to initialise the WiFi device.
129 // Returns 0 on success, -1 on failure.
130 //------------------------------------------------------------------------------
131 int WiFiDevice::init()
132 {
133  /* Initialise the WiFi HAL */
134  /* int ret = wifi_init();
135 
136  if (ret != 0)
137  {
138  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"Error! Unable to initialise WiFi HAL\n");
139  throw 1;
140  }*/
141  return 1;
142 }
143 
144 //------------------------------------------------------------------------------
145 // shutdown: Perform the necessary operations to shut down the WiFi device.
146 //------------------------------------------------------------------------------
147 void WiFiDevice::shutdown()
148 {
149  /* Shut down the WiFi HAL */
150 // (void)wifi_down();
151 }
152 
153 hostIf_WiFi::hostIf_WiFi(int dev_id):
154  dev_id(dev_id),
155  uiRadioNumberOfEntries(0),
156  uiSSIDNumberOfEntries(0),
157  uiAccessPointNumberOfEntries(0),
158  uiEndPointNumberOfEntries(0) //CID:103645 - UNINIT_CTOR
159 {
160 
161 }
162 
163 
164 hostIf_WiFi* hostIf_WiFi::getInstance(int dev_id)
165 {
166  hostIf_WiFi* pRet = NULL;
167 
168  if(ifHash)
169  {
170  pRet = (hostIf_WiFi *)g_hash_table_lookup(ifHash,(gpointer) dev_id);
171  }
172  else
173  {
174  ifHash = g_hash_table_new(NULL,NULL);
175  }
176 
177  if(!pRet)
178  {
179  try {
180  pRet = new hostIf_WiFi(dev_id);
181  } catch(int e)
182  {
183  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"Caught exception, not able create Wifi Interface instance..\n");
184  }
185  g_hash_table_insert(ifHash, (gpointer)dev_id, pRet);
186  }
187 
188  return pRet;
189 }
190 
191 GList* hostIf_WiFi::getAllIntefaces()
192 {
193  if(ifHash)
194  return g_hash_table_get_keys(ifHash);
195  return NULL;
196 }
197 
198 void hostIf_WiFi::closeInstance(hostIf_WiFi *pDev)
199 {
200  if(pDev)
201  {
202  g_hash_table_remove(ifHash, (gconstpointer)pDev->dev_id);
203  delete pDev;
204  }
205 }
206 
207 void hostIf_WiFi::closeAllInstances()
208 {
209  if(ifHash)
210  {
211  GList* tmp_list = g_hash_table_get_values (ifHash);
212 
213  while(tmp_list)
214  {
215  hostIf_WiFi* pDev = (hostIf_WiFi *)tmp_list->data;
216  tmp_list = tmp_list->next;
217  closeInstance(pDev);
218  }
219  }
220 }
221 
222 /****************************************************************************************************************************************************/
223 // Device.WiFi. Profile. Getters:
224 /****************************************************************************************************************************************************/
225 
226 int hostIf_WiFi::get_Device_WiFi_RadioNumberOfEntries(HOSTIF_MsgData_t *stMsgData)
227 {
228  ULONG radioNumOfEntries = 0;
229  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
231  int ret = OK;
232 
233  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
234 
235  param.numEntry=IARM_BUS_WIFI_MGR_RadioEntry;
236 // ret = wifi_getRadioNumberOfEntries(&radioNumOfEntries);
237 
238  retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_getSSIDProps, (void *)&param, sizeof(param));
239  if (IARM_RESULT_SUCCESS != retVal)
240  {
241  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] IARM BUS CALL failed with : %d.\n", __FILE__, __FUNCTION__, retVal);
242  return NOK;
243  }
244  RDK_LOG(RDK_LOG_DEBUG,LOG_TR69HOSTIF,"[%s:%s] param.data.radioNumberOfEntries returned %d radioNumOfEntries:%lu\n",
245  __FUNCTION__, __FILE__, ret, param.data.radioNumberOfEntries);
246  radioNumOfEntries=param.data.radioNumberOfEntries;
247  put_int(stMsgData->paramValue,radioNumOfEntries);
248  stMsgData->paramtype = hostIf_UnsignedIntType;
249  stMsgData->paramLen = sizeof(radioNumOfEntries);
250 
251  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
252 
253  return ret;
254 }
255 
256 int hostIf_WiFi::get_Device_WiFi_SSIDNumberOfEntries(HOSTIF_MsgData_t *stMsgData)
257 {
258  ULONG ssidNumOfEntries = 0;
259  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
260  int ret = OK;
262 
263  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
264  param.numEntry=IARM_BUS_WIFI_MGR_SSIDEntry;
265 
266  retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_getSSIDProps, (void *)&param, sizeof(param));
267  if (IARM_RESULT_SUCCESS != retVal)
268  {
269  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"[%s:%s] IARM BUS CALL failed with : %d.\n", __FILE__, __FUNCTION__, retVal);
270  return NOK;
271  }
272  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering.. param.data.ssidNumberOfEntries %d \n", __FUNCTION__, __FILE__,param.data.ssidNumberOfEntries);
273  ssidNumOfEntries=param.data.ssidNumberOfEntries;
274  put_int(stMsgData->paramValue,ssidNumOfEntries);
275  stMsgData->paramtype = hostIf_UnsignedIntType;
276  stMsgData->paramLen = 4;
277 
278  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
279 
280  return ret;
281 }
282 
283 int hostIf_WiFi::get_Device_WiFi_AccessPointNumberOfEntries(HOSTIF_MsgData_t *stMsgData)
284 {
285  unsigned int accessPointNumOfEntries = 1;
286  int ret = OK;
287  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Entering..\n", __FUNCTION__, __FILE__);
288 
289  put_int(stMsgData->paramValue, accessPointNumOfEntries);
290 
291  stMsgData->paramtype = hostIf_UnsignedIntType;
292  stMsgData->paramLen = sizeof (unsigned int);
293 
294  RDK_LOG(RDK_LOG_TRACE1,LOG_TR69HOSTIF,"[%s:%s] Exiting..\n", __FUNCTION__, __FILE__);
295 
296  return OK;
297 }
298 
299 int hostIf_WiFi::get_Device_WiFi_EndPointNumberOfEntries(HOSTIF_MsgData_t *stMsgData)
300 {
301  LOG_ENTRY_EXIT;
302 
303  unsigned int endPointNumOfEntries = 1;
304  put_int(stMsgData->paramValue, endPointNumOfEntries);
305  stMsgData->paramtype = hostIf_UnsignedIntType;
306  stMsgData->paramLen = sizeof (unsigned int);
307 
308  return OK;
309 }
310 
311 int hostIf_WiFi::get_Device_WiFi_EnableWiFi(HOSTIF_MsgData_t *stMsgData)
312 {
313  LOG_ENTRY_EXIT;
314 
316  snprintf (param.setInterface, INTERFACE_SIZE, "WIFI");
317  IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETSRVMGR_API_isInterfaceEnabled, (void*)&param, sizeof(param));
318  put_boolean(stMsgData->paramValue, param.isInterfaceEnabled);
319  stMsgData->paramtype = hostIf_BooleanType;
320  stMsgData->paramLen=1;
321  return OK;
322 }
323 
324 int hostIf_WiFi::set_Device_WiFi_EnableWiFi(HOSTIF_MsgData_t *stMsgData)
325 {
326  LOG_ENTRY_EXIT;
327 
328  if (stMsgData->paramtype != hostIf_BooleanType)
329  {
330  RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "[%s] Failed due to wrong data type for %s, please use boolean(0/1) to set.\n", __FUNCTION__, stMsgData->paramName);
331  stMsgData->faultCode = fcInvalidParameterType;
332  return NOK;
333  }
334 
335  IARM_BUS_NetSrvMgr_Iface_EventData_t iarmData = { 0 };
336  snprintf (iarmData.setInterface, INTERFACE_SIZE, "WIFI");
337  iarmData.isInterfaceEnabled = get_boolean(stMsgData->paramValue);
338  iarmData.persist = true; // set interface control persistence = true, whether WiFi is asked to be enabled or not
339 
340  if (IARM_RESULT_SUCCESS == IARM_Bus_Call (IARM_BUS_NM_SRV_MGR_NAME,
341  IARM_BUS_NETSRVMGR_API_setInterfaceEnabled,
342  (void*)&iarmData, sizeof(iarmData)))
343  {
344  RDK_LOG (RDK_LOG_DEBUG, LOG_TR69HOSTIF,
345  "[%s] IARM call succeeded %s %s (interface = %s enabled = %d persist = %d)\n",
346  __FUNCTION__, IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETSRVMGR_API_setInterfaceEnabled,
347  iarmData.setInterface, iarmData.isInterfaceEnabled, iarmData.persist);
348  return OK;
349  }
350  else
351  {
352  RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
353  "[%s] IARM call failed %s %s (interface = %s enabled = %d persist = %d)\n",
354  __FUNCTION__, IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETSRVMGR_API_setInterfaceEnabled,
355  iarmData.setInterface, iarmData.isInterfaceEnabled, iarmData.persist);
356  return NOK;
357  }
358 }
359 
360 #endif
361 /* End of doxygen group */
362 /**
363  * @}
364  */
365 
366 /* End of file xxx_api.c. */
netsrvmgrIarm.h
The header file provides components netSrvMgrIarm information APIs.
Device_WiFi.h
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
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
ULONG
#define ULONG
Defines for the basic data types.
Definition: wifi_common_hal.h:168
RDK_LOG
#define RDK_LOG
Definition: rdk_debug.h:258
_HostIf_MsgData_t::faultCode
faultCode_t faultCode
Definition: hostIf_tr69ReqHandler.h:179
_HostIf_MsgData_t::paramName
char paramName[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:171
_HostIf_MsgData_t::paramValue
char paramValue[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:172
_IARM_BUS_NetSrvMgr_Iface_EventData_t
IARM Bus struct contains active streaming interface, origional definition present in homenetworkingse...
Definition: priv_aamp.cpp:193
IARM_BUS_WIFI_MGR_API_getSSIDProps
#define IARM_BUS_WIFI_MGR_API_getSSIDProps
Definition: wifiSrvMgrIarmIf.h:85
put_int
void put_int(char *ptr, int val)
This function converts the input data to integer type.
Definition: hostIf_utils.cpp:152
_HostIf_MsgData_t::paramLen
short paramLen
Definition: hostIf_tr69ReqHandler.h:175