RDK Documentation (Open Sourced RDK Components)
wifiSrvMgrTestClient.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 2016 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 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <string.h>
24 #include <iostream>
25 #ifdef ENABLE_IARM
26 #include <signal.h>
27 #include "libIBus.h"
28 #include "libIBusDaemon.h"
29 #include "wifiSrvMgrIarmIf.h"
30 #include "netsrvmgrIarm.h"
31 #endif
32 #include "NetworkMgrMain.h"
33 
34 #define NM_MGR_WIFI_CLIENT "NetworkMgrWiFiClientApps"
35 #ifdef SAFEC_RDKV
36 #include "safec_lib.h"
37 #else
38 #define STRCPY_S(dest,size,source) \
39  strcpy(dest, source);
40 #endif
41 
42 int Net_Srv_Reg_Events = false;
43 int Wifi_Mgr_Reg_Events = false;
44 
45 typedef enum _NetworkManager_Route_EventId_t {
46  IARM_BUS_NETWORK_MANAGER_EVENT_ROUTE_DATA=10,
47  IARM_BUS_NETWORK_MANAGER_EVENT_ROUTE_MAX,
48 } IARM_Bus_NetworkManager_Route_EventId_t;
49 
50 enum option {
51  Exit,
52  Test_getAvailableSSIDs,
53  Test_getCurrentState,
54  Test_setEnabled,
55  Test_getPairedSSID,
56  Test_connect,
57  Test_initiateWPSPairing,
58  Test_initiateWPSPairing2,
59  Test_saveSSID,
60  Test_clearSSID,
61  Test_isPaired,
62  Test_getRadioProps,
63  Test_getRadioStatsProps,
64  Test_getSSIDProps,
65 #ifdef ENABLE_LOST_FOUND
66  Test_getLAFState,
67 #endif
68  Test_getConnectedSSID,
69  Test_getEndPointProps,
70  Test_getAvailableSSIDsWithName,
71  Test_getAvailableSSIDsIncr,
72  Test_stopProgressiveScanning,
73  Test_disconnectSSID,
74  Test_cancelWPSPairing,
75  Test_nm_registerForEvents,
76  Test_nm_unregisterForEvents,
77  Test_wifi_registerForEvents,
78  Test_wifi_unregisterForEvents,
79  Test_Max_Api,
80 };
81 
82 struct { option number; const char* name; } options[] =
83 {
84  { Test_getAvailableSSIDs, "getAvailableSSIDs" },
85  { Test_getCurrentState, "getCurrentState" },
86  { Test_setEnabled, "setEnabled" },
87  { Test_getPairedSSID, "getPairedSSID" },
88  { Test_connect, "connect" },
89  { Test_initiateWPSPairing, "initiateWPSPairing" },
90  { Test_initiateWPSPairing2, "initiateWPSPairing2" },
91  { Test_saveSSID, "saveSSID" },
92  { Test_clearSSID, "clearSSID" },
93  { Test_isPaired, "isPaired" },
94  { Test_getRadioProps, "getRadioProps" },
95  { Test_getRadioStatsProps, "getRadioStatsProps" },
96  { Test_getSSIDProps, "getSSIDProps" },
97 #ifdef ENABLE_LOST_FOUND
98  { Test_getLAFState, "getLAFState" },
99 #endif
100  { Test_getConnectedSSID, "getConnectedSSID" },
101  { Test_getEndPointProps, "getEndPointProps" },
102  { Test_getAvailableSSIDsWithName, "getAvailableSSIDsWithName" },
103  { Test_getAvailableSSIDsIncr, "getAvailableSSIDsAsycIncr" },
104  { Test_stopProgressiveScanning, "stopProgressiveWifiScanning" },
105  { Test_disconnectSSID, "disconnectSSID" },
106  { Test_cancelWPSPairing, "cancelWPSPairing" },
107  { Test_nm_registerForEvents, "net_srv_mgr_registerForEvents" },
108  { Test_nm_unregisterForEvents, "net_srv_mgr_unregisterForEvents" },
109  { Test_wifi_registerForEvents, "wifi_mgr_registerForEvents" },
110  { Test_wifi_unregisterForEvents, "wifi_mgr_unregisterForEvents" },
111  { Exit, "Exit" }
112 };
113 
114 static bool user_answers_yes_to(const char* question)
115 {
116  char answer;
117  std::cout << "\n" << question << " (y/n) ";
118  std::cin >> answer;
119  return answer == 'y' || answer == 'Y';
120 }
121 
122 static void WIFI_MGR_API_getAvailableSSIDsWithName()
123 {
124 #ifdef ENABLE_IARM
125  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
126  char ssid[64] = {'\0'};
127  double freq ;
128  int timeout = 10000;
130  memset(&param, 0, sizeof(param));
131  printf("[%s] Entering...\r\n", __FUNCTION__);
132  printf("\nEnter SSID to get the info :");
133  scanf("%s",ssid);
134  printf("\nEnter the band to scan 2.4 / 5 / 0 :");
135  scanf("%lf",&freq);
136  STRCPY_S(param.SSID, sizeof(param.SSID), ssid);
137  param.frequency = freq;
139  printf("\n***********************************");
140  printf("\n \"%s\", status: \"%s\"", IARM_BUS_WIFI_MGR_API_getAvailableSSIDsWithName, ((param.status)?"true":"false"));
141  printf("\n***********************************\n");
142 
143  if(retVal == IARM_RESULT_SUCCESS && param.status)
144  {
145  printf("[\n[%s (with Message size: %d)]:\n %s \n '. \n", IARM_BUS_WIFI_MGR_API_getAvailableSSIDsWithName, param.curSsids.jdataLen, param.curSsids.jdata);
146  }
147  else
148  {
149  printf("%s : \"Empty\" with message size: \'%d\'). \n", IARM_BUS_WIFI_MGR_API_getAvailableSSIDsWithName, param.curSsids.jdataLen);
150  }
151  printf("[%s] Exiting..\r\n", __FUNCTION__);
152 #endif
153 }
154 static void WIFI_MGR_API_stopProgressiveScanning()
155 {
156 #ifdef ENABLE_IARM
157  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
159 
160  printf("[%s] Entering...\r\n", __FUNCTION__);
161 
162  memset(&param, 0, sizeof(param));
163 
164  retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME,IARM_BUS_WIFI_MGR_API_stopProgressiveWifiScanning, (void *)&param, sizeof(param));
165 
166  printf("\n***********************************");
167  printf("\n \"%s\", status: \"%s\"", IARM_BUS_WIFI_MGR_API_stopProgressiveWifiScanning, ((retVal == IARM_RESULT_SUCCESS)?"true":"false"));
168  printf("\n***********************************\n");
169 
170  printf("[%s] Exiting..\r\n", __FUNCTION__);
171 #endif
172 
173 }
174 
175 static void WIFI_MGR_API_disconnectSSID()
176 {
177 #ifdef ENABLE_IARM
178  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
180 
181  printf("[%s] Entering...\r\n", __FUNCTION__);
182 
183  memset(&param, 0, sizeof(param));
184 
185  retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_disconnectSSID, (void *)&param, sizeof(param));
186 
187  printf("\n***********************************");
188  printf("\n \"%s\", status: \"%s\"", IARM_BUS_WIFI_MGR_API_disconnectSSID, ((retVal == IARM_RESULT_SUCCESS && param.status)?"true":"false"));
189  printf("\n***********************************\n");
190 
191  printf("[%s] Exiting..\r\n", __FUNCTION__);
192 #endif
193 
194 }
195 
196 static void WIFI_MGR_API_cancelWPSPairing()
197 {
198 #ifdef ENABLE_IARM
199  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
201 
202  printf("[%s] Entering...\r\n", __FUNCTION__);
203 
204  memset(&param, 0, sizeof(param));
205 
206  retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_cancelWPSPairing, (void *)&param, sizeof(param));
207 
208  printf("\n***********************************");
209  printf("\n \"%s\", status: \"%s\"", IARM_BUS_WIFI_MGR_API_cancelWPSPairing, ((retVal == IARM_RESULT_SUCCESS && param.status)?"true":"false"));
210  printf("\n***********************************\n");
211 
212  printf("[%s] Exiting..\r\n", __FUNCTION__);
213 #endif
214 
215 }
216 
217 static void WIFI_MGR_API_getAvailableSSIDsIncr()
218 {
219 #ifdef ENABLE_IARM
220  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
222  memset(&param, 0, sizeof(param));
223  int timeout = 5000;
224  printf("[%s] Entering...\r\n", __FUNCTION__);
225  retVal = IARM_Bus_Call_with_IPCTimeout(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_getAvailableSSIDsAsyncIncr, (void *)&param, sizeof(IARM_Bus_WiFiSrvMgr_SsidList_Param_t),timeout);
226 
227  printf("\n***********************************");
228  printf("\n \"%s\", status: \"%s\"", IARM_BUS_WIFI_MGR_API_getAvailableSSIDsAsyncIncr, ((retVal == IARM_RESULT_SUCCESS)?"true":"false"));
229  printf("\n***********************************\n");
230 
231  printf("[%s] Exiting..\r\n", __FUNCTION__);
232 #endif
233 }
234 
235 
236 static void WIFI_MGR_API_getAvailableSSIDs()
237 {
238 #ifdef ENABLE_IARM
239  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
241  memset(&param, 0, sizeof(param));
242  int timeout = 10000;
243  printf("[%s] Entering...\r\n", __FUNCTION__);
244  retVal = IARM_Bus_Call_with_IPCTimeout(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_getAvailableSSIDs, (void *)&param, sizeof(IARM_Bus_WiFiSrvMgr_SsidList_Param_t),timeout);
245 
246  printf("\n***********************************");
247  printf("\n \"%s\", status: \"%s\"", IARM_BUS_WIFI_MGR_API_getAvailableSSIDs, ((param.status)?"true":"false"));
248  printf("\n***********************************\n");
249 
250  if(retVal == IARM_RESULT_SUCCESS && param.status) {
251  printf("[\n[%s (with Message size: %d)]:\n %s \n '. \n", IARM_BUS_WIFI_MGR_API_getAvailableSSIDs, param.curSsids.jdataLen, param.curSsids.jdata);
252  }
253  else {
254  printf("%s : \"Empty\" with message size: \'%d\'). \n", IARM_BUS_WIFI_MGR_API_getAvailableSSIDs, param.curSsids.jdataLen);
255  }
256  printf("[%s] Exiting..\r\n", __FUNCTION__);
257 #endif
258 }
259 
260 static void WIFI_MGR_API_getCurrentState()
261 {
262 #ifdef ENABLE_IARM
263  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
265 
266  printf("[%s] Entering...\r\n", __FUNCTION__);
267  memset(&param, 0, sizeof(param));
268 
269  retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_getCurrentState, (void *)&param, sizeof(param));
270 
271  printf("\n***********************************");
272  printf("\n \"%s\", status: \"%s\"", IARM_BUS_WIFI_MGR_API_getCurrentState, ((param.status)?"true":"false"));
273  printf("\n***********************************\n");
274 
275  if(retVal == IARM_RESULT_SUCCESS && param.status) {
276  printf(" \"getCurrentState\" : %d \n", param.data.wifiStatus );
277  }
278  printf("[%s] Exiting..\r\n", __FUNCTION__);
279 #endif
280 }
281 
282 #ifdef ENABLE_LOST_FOUND
283 static void WIFI_MGR_API_getLAFState()
284 {
285 #ifdef ENABLE_IARM
286  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
288 
289  printf("[%s] Entering...\r\n", __FUNCTION__);
290  memset(&param, 0, sizeof(param));
291 
292  retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_getLNFState, (void *)&param, sizeof(param));
293 
294  printf("\n***********************************");
295  printf("\n \"%s\", status: \"%s\"", IARM_BUS_WIFI_MGR_API_getLNFState, ((param.status)?"true":"false"));
296  printf("\n***********************************\n");
297 
298  if(retVal == IARM_RESULT_SUCCESS && param.status) {
299  printf(" \"getLAFState\" : %d \n", param.data.wifiLNFStatus );
300  }
301  printf("[%s] Exiting..\r\n", __FUNCTION__);
302 #endif
303 }
304 #endif
305 static void WIFI_MGR_API_setEnabled()
306 {
307 #ifdef ENABLE_IARM
308  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
310  printf("[%s] Entering...\r\n", __FUNCTION__);
311  memset(&param, 0, sizeof(param));
312 
313  param.data.setwifiadapter.enable = user_answers_yes_to("Press Y/y for setEnabled(true), anything else for setEnabled(false)");
314  retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_setEnabled, (void *)&param, sizeof(param));
315 
316  if(retVal == IARM_RESULT_SUCCESS) {
317  printf("[%s] to \'%d\'. \n", IARM_BUS_WIFI_MGR_API_setEnabled, param.data.setwifiadapter.enable );
318  }
319  printf("[%s] Exiting..\r\n", __FUNCTION__);
320 #endif
321 }
322 
323 
324 static void WIFI_MGR_API_getPairedSSID()
325 {
326 #ifdef ENABLE_IARM
327  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
329  char *ssid = NULL;
330 
331  printf("[%s] Entering...\r\n", __FUNCTION__);
332 
333  memset(&param, 0, sizeof(param));
334 
335  retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_getPairedSSID, (void *)&param, sizeof(param));
336 
337  printf("\n***********************************");
338  printf("\n \"%s\", status: \"%s\"", IARM_BUS_WIFI_MGR_API_getPairedSSID, ((param.status)?"true":"false"));
339  printf("\n***********************************\n");
340 
341  ssid = param.data.getPairedSSID.ssid;
342  if(retVal == IARM_RESULT_SUCCESS) {
343  printf("\nSSID: %s \n", (ssid)?ssid:"No ssid is assigned.");
344  }
345 
346  printf("[%s] Exiting..\r\n", __FUNCTION__);
347 #endif
348 }
349 
350 static void WIFI_MGR_API_connect()
351 {
352 #ifdef ENABLE_IARM
353  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
355  std::string ssid, passphrase, ans;
356  int securitymode;
357 
358  printf("[%s] Entering...\r\n", __FUNCTION__);
359  memset(&param, 0, sizeof(param));
360 
361  printf("\n***********************************");
362  printf("\n \"%s\"", IARM_BUS_WIFI_MGR_API_connect);
363  printf("\n***********************************\n");
364 
365  printf( "Would like to connect using ssid & passphrase. (Y/N)?" );
366  std::cin >> ans;
367 
368  if(!strcasecmp(ans.c_str(),"Y"))
369  {
370  std::cout<< " Enter ssid : ";
371  std::cin >> ssid;
372  std::cout <<" Enter passphrase : " ;
373  std::cin >> passphrase;
374  std::cout <<" Enter securitymode : " ;
375  std::cin >> securitymode;
376  STRCPY_S (param.data.connect.ssid, sizeof(param.data.connect.ssid), ssid.c_str());
377  STRCPY_S (param.data.connect.passphrase, sizeof(param.data.connect.passphrase), passphrase.c_str());
378  param.data.connect.security_mode=(SsidSecurity)securitymode;
379  printf("\n ssid = %s passphrase = %s security mode = %d",param.data.connect.ssid,param.data.connect.passphrase,param.data.connect.security_mode);
380  }
381  else {
382  printf( "\nNot selected any ssid & passphrase. so, connect\n" );
383  }
384 
385  retVal = IARM_Bus_Call( IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_connect, (void *)&param, sizeof(param));
386 
387  printf("\n \"%s\", status: \"%s\"", IARM_BUS_WIFI_MGR_API_connect, ((retVal == IARM_RESULT_SUCCESS && param.status)?"Success":"Failure"));
388 
389  printf("[%s] Exiting..\r\n", __FUNCTION__);
390 #endif
391 }
392 
393 static void WIFI_MGR_API_initiateWPSPairing()
394 {
395 #ifdef ENABLE_IARM
396  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
398  printf("[%s] Entering...\r\n", __FUNCTION__);
399 
400  IARM_Bus_Call( IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_initiateWPSPairing, (void *)&param, sizeof(param));
401 
402  printf("\n***********************************");
403  printf("\n \"%s\", status: \"%s\"", IARM_BUS_WIFI_MGR_API_initiateWPSPairing, ((param.status)?"true":"false"));
404  printf("\n***********************************\n");
405  printf("[%s] Exiting..\r\n", __FUNCTION__);
406 #endif
407 }
408 
409 static void WIFI_MGR_API_initiateWPSPairing2()
410 {
411  printf("[%s] Entering...\r\n", __FUNCTION__);
412 #ifdef ENABLE_IARM
413  IARM_Bus_WiFiSrvMgr_WPS_Parameters_t wps_parameters = {0};
414  if (user_answers_yes_to("PBC ?"))
415  wps_parameters.pbc = true;
416  else if (user_answers_yes_to("Auto-generate PIN ?"))
417  wps_parameters.pin[0] = '\0';
418  else if (user_answers_yes_to("Use serialized PIN ?"))
419  strcpy(wps_parameters.pin, "xxxxxxxx");
420  else
421  {
422  std::string pin;
423  std::cout << "\nEnter PIN (8 digits): ";
424  std::cin >> pin;
425  strncpy(wps_parameters.pin, pin.c_str(), 8);
426  }
427 
428  IARM_Bus_Call( IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_initiateWPSPairing2, (void *)&wps_parameters, sizeof(wps_parameters));
429 
430  printf("\n***********************************");
431  printf("\n \"%s\", status: \"%s\"", IARM_BUS_WIFI_MGR_API_initiateWPSPairing2, wps_parameters.status ? "true" : "false");
432  if (wps_parameters.status == true && !wps_parameters.pbc)
433  printf("\n \"%s\", PIN = \"%s\"", IARM_BUS_WIFI_MGR_API_initiateWPSPairing2, wps_parameters.pin);
434  printf("\n***********************************\n");
435 #endif
436  printf("[%s] Exiting..\r\n", __FUNCTION__);
437 }
438 
439 
440 static void WIFI_MGR_API_saveSSID()
441 {
442 #ifdef ENABLE_IARM
443  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
444  std::string ssid, passphrase, ans;
446 
447  printf("[%s] Entering...\r\n", __FUNCTION__);
448  memset(&param, 0, sizeof(param));
449  printf("\n***********************************");
450  printf("\n \"%s\"", IARM_BUS_WIFI_MGR_API_saveSSID);
451  printf("\n***********************************\n");
452 
453  printf( "This would saves the ssid and passphrase for future sessions.\n" );
454  std::cout << "Enter ssid :" ;
455  std::cin >>ssid;
456  std::cout << "\nEnter passphrase :" ;
457  std::cin >> passphrase;
458  STRCPY_S (param.data.connect.ssid, sizeof(param.data.connect.ssid), ssid.c_str());
459  STRCPY_S (param.data.connect.passphrase, sizeof(param.data.connect.passphrase), passphrase.c_str());
460 
461  retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_saveSSID, (void *)&param, sizeof(param));
462 
463  printf("\n%s : %s \n", IARM_BUS_WIFI_MGR_API_saveSSID, ((retVal == IARM_RESULT_SUCCESS && param.status)?"Successfully saved the SSID":"failed to save SSID"));
464  printf("[%s] Exiting..\r\n", __FUNCTION__);
465 #endif
466 }
467 
468 static void WIFI_MGR_API_clearSSID()
469 {
470 #ifdef ENABLE_IARM
471  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
473 
474  printf("[%s] Entering...\r\n", __FUNCTION__);
475 
476  memset(&param, 0, sizeof(param));
477 
478  retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_clearSSID, (void *)&param, sizeof(param));
479 
480  printf("\n***********************************");
481  printf("\n \"%s\", status: \"%s\"", IARM_BUS_WIFI_MGR_API_clearSSID, ((retVal == IARM_RESULT_SUCCESS && param.status)?"true":"false"));
482  printf("\n***********************************\n");
483 
484  printf("[%s] Exiting..\r\n", __FUNCTION__);
485 #endif
486 }
487 
488 static void WIFI_MGR_API_isPaired()
489 {
490 #ifdef ENABLE_IARM
491  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
493 
494  printf("[%s] Entering...\r\n", __FUNCTION__);
495 
496  memset(&param, 0, sizeof(param));
497 
498  retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_isPaired, (void *)&param, sizeof(param));
499 
500  printf("\n***********************************");
501  printf("\n \"%s\", status: \"%s\"", IARM_BUS_WIFI_MGR_API_isPaired, ((retVal == IARM_RESULT_SUCCESS && param.status)?"true":"false"));
502  printf("\n***********************************\n");
503  printf("%s \n", (param.data.isPaired)?"Paied.":"Not paired.");
504 
505  printf("[%s] Exiting..\r\n", __FUNCTION__);
506 #endif
507 }
508 
509 static void WIFI_MGR_API_getConnectedSSID() {
510 #ifdef ENABLE_IARM
511  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
513 
514  printf("[%s] Entering...\r\n", __FUNCTION__);
515 
516  memset(&param, 0, sizeof(param));
517 
518  retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_getConnectedSSID, (void *)&param, sizeof(param));
519 
520  printf("\n***********************************");
521  printf("\n \"%s\", status: \"%s\"", IARM_BUS_WIFI_MGR_API_getConnectedSSID, ((retVal == IARM_RESULT_SUCCESS && param.status)?"true":"false"));
522  printf("\n***********************************\n");
523 
524  printf("Connected SSID info: \n \
525  \tSSID: \"%s\"\n \
526  \tBSSID : \"%s\"\n \
527  \tPhyRate : \"%f\"\n \
528  \tNoise : \"%f\" \n \
529  \tBand : \"%s\"\n \
530  \tSignalStrength(rssi) : \"%f\" \n \
531  \tFrequency : \"%d\"\n \
532  \tSecurityMode : \"%d\"\n ",
533  param.data.getConnectedSSID.ssid, \
534  param.data.getConnectedSSID.bssid, \
535  param.data.getConnectedSSID.rate, \
536  param.data.getConnectedSSID.noise, \
537  param.data.getConnectedSSID.band, \
538  param.data.getConnectedSSID.signalStrength, \
539  param.data.getConnectedSSID.frequency, \
540  param.data.getConnectedSSID.securityMode);
541 
542  printf("[%s] Exiting..\r\n", __FUNCTION__);
543 #endif
544 }
545 
546 static void WIFI_MGR_API_getEndPointProps()
547 {
548 #ifdef ENABLE_IARM
549  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
551 
552  printf("[%s] Entering...\r\n", __FUNCTION__);
553 
554  memset(&param, 0, sizeof(param));
555 
556  retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_getEndPointProps, (void *)&param, sizeof(param));
557 
558  printf("\n***********************************");
559  printf("\n \"%s\", status: \"%s\"", IARM_BUS_WIFI_MGR_API_getEndPointProps, ((retVal == IARM_RESULT_SUCCESS && param.status)?"true":"false"));
560  printf("\n***********************************\n");
561 
562  printf("\n Profile : \"EndPoint.1.\": \n \
563  [Enable : \"%d\"| Status : \"%s\" | SSIDReference : \"%s\" ] \n",
564  param.data.endPointInfo.enable, param.data.endPointInfo.status, param.data.endPointInfo.SSIDReference);
565 
566  printf(" \n Profile : \"EndPoint.1.Stats.\": \n \
567  [SignalStrength : \"%d\"| Retransmissions : \"%ld\" | LastDataUplinkRate : \"%ld\" | LastDataDownlinkRate : \" %ld\" ] \n",
568  param.data.endPointInfo.stats.signalStrength, param.data.endPointInfo.stats.retransmissions,
569  param.data.endPointInfo.stats.lastDataDownlinkRate, param.data.endPointInfo.stats.lastDataUplinkRate);
570 
571  printf("[%s] Exiting..\r\n", __FUNCTION__);
572 #endif
573 }
574 
575 
576 static void WIFI_MGR_API_getSSIDProps()
577 {
578 #ifdef ENABLE_IARM
579  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
581 
582  printf("[%s] Entering...\r\n", __FUNCTION__);
583 
584  memset(&param, 0, sizeof(param));
585 
586  retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_getSSIDProps, (void *)&param, sizeof(param));
587 
588  printf("\n***********************************");
589  printf("\n \"%s\", status: \"%s\"", IARM_BUS_WIFI_MGR_API_getSSIDProps, ((retVal == IARM_RESULT_SUCCESS && param.status)?"true":"false"));
590  printf("\n***********************************\n");
591  std::cout << "enable : " << param.data.ssid.params.enable << std::endl;
592  std::cout << "status : " << param.data.ssid.params.status << std::endl;
593  std::cout << "name : " << param.data.ssid.params.name << std::endl;
594  std::cout << "bssid : " << param.data.ssid.params.bssid << std::endl;
595  std::cout << "macaddr : " << param.data.ssid.params.macaddr << std::endl;
596  std::cout << "ssid : " << param.data.ssid.params.ssid << std::endl;
597 
598  printf("[%s] Exiting..\r\n", __FUNCTION__);
599 #endif
600 }
601 
602 
603 static void WIFI_MGR_API_getRadioProps()
604 {
605 #ifdef ENABLE_IARM
606  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
608 
609  printf("[%s] Entering...\r\n", __FUNCTION__);
610 
611  memset(&param, 0, sizeof(param));
612 
613  retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_getRadioProps, (void *)&param, sizeof(param));
614 
615  printf("\n***********************************");
616  printf("\n \"%s\", status: \"%s\"", IARM_BUS_WIFI_MGR_API_getRadioProps, ((retVal == IARM_RESULT_SUCCESS && param.status)?"true":"false"));
617  printf("\n***********************************\n");
618  std::cout << "enable : " << param.data.radio.params.enable << std::endl;
619  std::cout << "status : " << param.data.radio.params.status << std::endl;
620  std::cout << "name : " << param.data.radio.params.name << std::endl;
621  std::cout << "maxBitRate : " << param.data.radio.params.maxBitRate << std::endl;
622  std::cout << "supportedFrequencyBands : " << param.data.radio.params.supportedFrequencyBands << std::endl;
623  std::cout << "operatingFrequencyBand : "<< param.data.radio.params.operatingFrequencyBand << std::endl;
624  std::cout << "autoChannelEnable : "<< param.data.radio.params.autoChannelEnable << std::endl;
625  std::cout << "autoChannelRefreshPeriod : "<< param.data.radio.params.autoChannelRefreshPeriod << std::endl;
626  std::cout << "autoChannelSupported : "<< param.data.radio.params.autoChannelSupported << std::endl;
627  std::cout << "channelsInUse : " << param.data.radio.params.channelsInUse << std::endl;
628  std::cout << "channel : " << param.data.radio.params.channel << std::endl;
629  std::cout << "extensionChannel : " << param.data.radio.params.extensionChannel << std::endl;
630  std::cout << "guardInterval : " << param.data.radio.params.guardInterval << std::endl;
631  std::cout << "mcs : " << param.data.radio.params.mcs << std::endl;
632  std::cout << "operatingChannelBandwidth : " << param.data.radio.params.operatingChannelBandwidth << std::endl;
633  std::cout << "operatingStandards : " << param.data.radio.params.operatingStandards << std::endl;
634  std::cout << "possibleChannels : " << param.data.radio.params.possibleChannels << std::endl;
635  std::cout << "regulatoryDomain : " << param.data.radio.params.regulatoryDomain << std::endl;
636 
637  printf("[%s] Exiting..\r\n", __FUNCTION__);
638 #endif
639 }
640 
641 static void WIFI_MGR_API_getRadioStatsProps()
642 {
643 #ifdef ENABLE_IARM
644  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
646 
647  printf("[%s] Entering...\r\n", __FUNCTION__);
648 
649  memset(&param, 0, sizeof(param));
650 
651  retVal = IARM_Bus_Call(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_API_getRadioStatsProps, (void *)&param, sizeof(param));
652 
653  printf("\n***********************************");
654  printf("\n \"%s\", status: \"%s\"", IARM_BUS_WIFI_MGR_API_getRadioStatsProps, ((retVal == IARM_RESULT_SUCCESS && param.status)?"true":"false"));
655  printf("\n***********************************\n");
656  std::cout << "BytesSent : " << param.data.radio_stats.params.bytesSent << std::endl;
657  std::cout << "BytesReceived : " << param.data.radio_stats.params.bytesReceived << std::endl;
658  std::cout << "PacketsSent : " << param.data.radio_stats.params.packetsSent << std::endl;
659  std::cout << "PacketsReceived : " << param.data.radio_stats.params.packetsReceived << std::endl;
660  std::cout << "ErrorsSent : " << param.data.radio_stats.params.errorsSent << std::endl;
661  std::cout << "ErrorsReceived : "<< param.data.radio_stats.params.errorsReceived << std::endl;
662  std::cout << "DiscardPacketsSent : " << param.data.radio_stats.params.discardPacketsSent << std::endl;
663  std::cout << "DiscardPacketsReceived : " << param.data.radio_stats.params.discardPacketsReceived << std::endl;
664  std::cout << "PLCPErrorCount : " << param.data.radio_stats.params.plcErrorCount << std::endl;
665  std::cout << "FCSErrorCount : " << param.data.radio_stats.params.fcsErrorCount << std::endl;
666  std::cout << "InvalidMACCount : " << param.data.radio_stats.params.invalidMACCount << std::endl;
667  std::cout << "PacketsOtherReceived : " << param.data.radio_stats.params.packetsOtherReceived << std::endl;
668 
669  printf("[%s] Exiting..\r\n", __FUNCTION__);
670 #endif
671 }
672 #ifdef ENABLE_IARM
673 #define IARM_CHECK(FUNC) { \
674  if ((res = FUNC) != IARM_RESULT_SUCCESS) { \
675  printf("IARM %s: %s\n", #FUNC, \
676  res == IARM_RESULT_INVALID_PARAM ? "invalid param" : ( \
677  res == IARM_RESULT_INVALID_STATE ? "invalid state" : ( \
678  res == IARM_RESULT_IPCCORE_FAIL ? "ipcore fail" : ( \
679  res == IARM_RESULT_OOM ? "oom" : "unknown")))); \
680  } \
681  else \
682  { \
683  printf("IARM %s: success\n", #FUNC); \
684  } \
685 }
686 #endif //#ifdef ENABLE_IARM
687 
688 #ifdef ENABLE_IARM
689 static void eventHandler_nm_mgr(const char *owner, IARM_EventId_t eventId, void *data, size_t len)
690 {
691  if (strcmp(owner, IARM_BUS_NM_SRV_MGR_NAME) != 0)
692  {
693  printf ("ERROR - nm_mgr unexpected event: owner %s, eventId: %d, data: %p, size: %d.\n", owner, (int)eventId, data, len);
694  return;
695  }
696  if (data == nullptr || len == 0)
697  {
698  printf ("ERROR - event with NO DATA: eventId: %d, data: %p, size: %d.\n", (int)eventId, data, len);
699  return;
700  }
701 
702  switch (eventId)
703  {
704  case IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_ENABLED_STATUS:
705  {
707  printf ("IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_ENABLED_STATUS interface = %s, enabled = %d\n",
708  e->interface, e->status);
709  break;
710  }
711  case IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_CONNECTION_STATUS:
712  {
714  printf ("IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_CONNECTION_STATUS interface = %s, connected = %d\n",
715  e->interface, e->status);
716  break;
717  }
718  case IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_IPADDRESS:
719  {
721  printf ("IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_IPADDRESS interface = %s, ip_address = %s, acquired = %d\n",
722  e->interface, e->ip_address, e->acquired);
723  break;
724  }
725  case IARM_BUS_NETWORK_MANAGER_EVENT_DEFAULT_INTERFACE:
726  {
728  printf ("IARM_BUS_NETWORK_MANAGER_EVENT_DEFAULT_INTERFACE oldInterface = %s newInterface = %s\n",
729  e->oldInterface, e->newInterface);
730  break;
731  }
732  case IARM_BUS_NETWORK_MANAGER_EVENT_SET_INTERFACE_ENABLED:
733  {
734  IARM_BUS_NetSrvMgr_Iface_EventData_t iarmData = { 0 };
735  printf ("IARM_BUS_NETWORK_MANAGER_EVENT_SET_INTERFACE_ENABLED = %d \n", iarmData.isInterfaceEnabled);
736  break;
737  }
738  case IARM_BUS_NETWORK_MANAGER_EVENT_SET_INTERFACE_CONTROL_PERSISTENCE:
739  {
740  IARM_BUS_NetSrvMgr_Iface_EventData_t iarmData = { 0 };
741  printf ("IARM_BUS_NETWORK_MANAGER_EVENT_SET_INTERFACE_CONTROL_PERSISTENCE = %d for interface %s\n", iarmData.isInterfaceEnabled,
742  iarmData.setInterface);
743  break;
744  }
745  case IARM_BUS_NETWORK_MANAGER_EVENT_WIFI_INTERFACE_STATE:
746  {
747  IARM_BUS_NetSrvMgr_Iface_EventData_t iarmData = { 0 };
748  printf ("IARM_BUS_NETWORK_MANAGER_EVENT_SET_INTERFACE_ENABLED = %d \n", iarmData.isInterfaceEnabled);
749  break;
750  }
751  case IARM_BUS_NETWORK_MANAGER_EVENT_SWITCH_TO_PRIVATE:
752  {
753  printf("IARM_BUS_NETWORK_MANAGER_EVENT_SWITCH_TO_PRIVATE broadcast!");
754  break;
755  }
756  case IARM_BUS_NETWORK_MANAGER_EVENT_STOP_LNF_WHILE_DISCONNECTED:
757  {
758  printf("IARM_BUS_NETWORK_MANAGER_EVENT_STOP_LNF_WHILE_DISCONNECTED event!");
759  break;
760  }
761  case IARM_BUS_NETWORK_MANAGER_EVENT_AUTO_SWITCH_TO_PRIVATE_ENABLED:
762  {
763  printf("IARM_BUS_NETWORK_MANAGER_EVENT_AUTO_SWITCH_TO_PRIVATE_ENABLED event!");
764  break;
765  }
766  case IARM_BUS_NETWORK_MANAGER_EVENT_ROUTE_DATA:
767  {
768  printf("IARM_BUS_NETWORK_MANAGER_EVENT_ROUTE_DATA event!");
769  break;
770  }
771  }
772 }
773 #endif //#ifdef ENABLE_IARM
774 
775 #ifdef ENABLE_IARM
776 static void eventHandler_wifi_mgr(const char *owner, IARM_EventId_t eventId, void *data, size_t len)
777 {
778  if (strcmp(owner, IARM_BUS_NM_SRV_MGR_NAME) != 0)
779  {
780  printf ("ERROR - wifi_mgr unexpected event: owner %s, eventId: %d, data: %p, size: %d.\n", owner, (int)eventId, data, len);
781  return;
782  }
783  if (data == nullptr || len == 0)
784  {
785  printf ("ERROR - event with NO DATA: eventId: %d, data: %p, size: %d.\n", (int)eventId, data, len);
786  return;
787  }
788 
789  switch (eventId)
790  {
791  case IARM_BUS_WIFI_MGR_EVENT_onAvailableSSIDs:
792  {
794  printf ("IARM_BUS_WIFI_MGR_EVENT_onAvailableSSIDs data.wifiSSIDList.ssid_list = %s\n",
795  e->data.wifiSSIDList.ssid_list);
796  break;
797  }
798  case IARM_BUS_WIFI_MGR_EVENT_onAvailableSSIDsIncr:
799  {
801  printf ("IARM_BUS_WIFI_MGR_EVENT_onAvailableSSIDsIncr data.wifiSSIDList.more_data = %d data.wifiSSIDList.ssid_list = %s\n",
802  e->data.wifiSSIDList.more_data, e->data.wifiSSIDList.ssid_list);
803  break;
804  }
805  case IARM_BUS_WIFI_MGR_EVENT_onError:
806  {
808  printf ("IARM_BUS_WIFI_MGR_EVENT_onError data.wifiError.code = %d\n",
809  e->data.wifiError.code);
810  break;
811  }
812  case IARM_BUS_WIFI_MGR_EVENT_onWIFIStateChanged:
813  {
815  printf ("IARM_BUS_WIFI_MGR_EVENT_onWIFIStateChanged data.wifiStateChange.state = %d\n",
816  e->data.wifiStateChange.state);
817  break;
818  }
819  case IARM_BUS_WIFI_MGR_EVENT_onSSIDsChanged:
820  {
822  printf ("IARM_BUS_WIFI_MGR_EVENT_onSSIDsChanged data.wifiSSIDList.ssid_list = %s data.wifiStateChange.state = %d \n",
823  e->data.wifiSSIDList.ssid_list, e->data.wifiStateChange.state);
824  break;
825  }
826  }
827 }
828 #endif //#ifdef ENABLE_IARM
829 
830 static void NET_MGR_registerForEvents()
831 {
832  #ifdef ENABLE_IARM
833  printf("[%s] Entering...\r\n", __FUNCTION__);
834 
835  if (Net_Srv_Reg_Events)
836  {
837  printf("[%s] Already registered\n", __FUNCTION__);
838  }
839  else
840  {
841  Net_Srv_Reg_Events = true;
842 
843  IARM_Result_t res;
844  IARM_CHECK( IARM_Bus_RegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_ENABLED_STATUS, eventHandler_nm_mgr) );
845  IARM_CHECK( IARM_Bus_RegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_CONNECTION_STATUS, eventHandler_nm_mgr) );
846  IARM_CHECK( IARM_Bus_RegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_IPADDRESS, eventHandler_nm_mgr) );
847  IARM_CHECK( IARM_Bus_RegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_DEFAULT_INTERFACE, eventHandler_nm_mgr) );
848  IARM_CHECK( IARM_Bus_RegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_SET_INTERFACE_ENABLED, eventHandler_nm_mgr) );
849  IARM_CHECK( IARM_Bus_RegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_SET_INTERFACE_CONTROL_PERSISTENCE, eventHandler_nm_mgr) );
850  IARM_CHECK( IARM_Bus_RegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_WIFI_INTERFACE_STATE , eventHandler_nm_mgr) );
851  IARM_CHECK( IARM_Bus_RegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_SWITCH_TO_PRIVATE, eventHandler_nm_mgr) );
852  IARM_CHECK( IARM_Bus_RegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_STOP_LNF_WHILE_DISCONNECTED, eventHandler_nm_mgr) );
853  IARM_CHECK( IARM_Bus_RegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_AUTO_SWITCH_TO_PRIVATE_ENABLED, eventHandler_nm_mgr) );
854  IARM_CHECK( IARM_Bus_RegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_ROUTE_DATA, eventHandler_nm_mgr) );
855 
856  }
857  printf("[%s] Exiting..\r\n", __FUNCTION__);
858 #endif
859 }
860 
861 static void WIFI_MGR_registerForEvents()
862 {
863 #ifdef ENABLE_IARM
864  printf("[%s] Entering...\r\n", __FUNCTION__);
865 
866  if (Wifi_Mgr_Reg_Events)
867  {
868  printf("[%s] Already registered\n", __FUNCTION__);
869  }
870  else
871  {
872  Wifi_Mgr_Reg_Events = true;
873 
874  IARM_Result_t res;
875  IARM_CHECK( IARM_Bus_RegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_EVENT_onAvailableSSIDs , eventHandler_wifi_mgr) );
876  IARM_CHECK( IARM_Bus_RegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_EVENT_onAvailableSSIDsIncr, eventHandler_wifi_mgr) );
877  IARM_CHECK( IARM_Bus_RegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_EVENT_onError, eventHandler_wifi_mgr) );
878  IARM_CHECK( IARM_Bus_RegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_EVENT_onWIFIStateChanged, eventHandler_wifi_mgr) );
879  IARM_CHECK( IARM_Bus_RegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_EVENT_onSSIDsChanged, eventHandler_wifi_mgr) );
880 
881  }
882 
883  printf("[%s] Exiting..\r\n", __FUNCTION__);
884 #endif
885 }
886 
887 static void NET_MGR_unregisterForEvents()
888 {
889 #ifdef ENABLE_IARM
890  printf("[%s] Entering...\r\n", __FUNCTION__);
891 
892  if (!Net_Srv_Reg_Events)
893  {
894  printf("[%s] Already unregistered\n", __FUNCTION__);
895  }
896  else
897  {
898  IARM_Result_t res;
899  IARM_CHECK( IARM_Bus_UnRegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_ENABLED_STATUS) );
900  IARM_CHECK( IARM_Bus_UnRegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_CONNECTION_STATUS) );
901  IARM_CHECK( IARM_Bus_UnRegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_IPADDRESS) );
902  IARM_CHECK( IARM_Bus_UnRegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_DEFAULT_INTERFACE) );
903 
904  IARM_CHECK( IARM_Bus_UnRegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_SET_INTERFACE_ENABLED) );
905  IARM_CHECK( IARM_Bus_UnRegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_SET_INTERFACE_CONTROL_PERSISTENCE) );
906  IARM_CHECK( IARM_Bus_UnRegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_WIFI_INTERFACE_STATE ) );
907  IARM_CHECK( IARM_Bus_UnRegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_SWITCH_TO_PRIVATE ) );
908  IARM_CHECK( IARM_Bus_UnRegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_STOP_LNF_WHILE_DISCONNECTED) );
909  IARM_CHECK( IARM_Bus_UnRegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_AUTO_SWITCH_TO_PRIVATE_ENABLED) );
910  IARM_CHECK( IARM_Bus_UnRegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETWORK_MANAGER_EVENT_ROUTE_DATA) );
911 
912  Net_Srv_Reg_Events = false;
913  }
914 
915  printf("[%s] Exiting..\r\n", __FUNCTION__);
916 #endif
917 }
918 
919 static void WIFI_MGR_unregisterForEvents()
920 {
921 #ifdef ENABLE_IARM
922  printf("[%s] Entering...\r\n", __FUNCTION__);
923 
924  if (!Wifi_Mgr_Reg_Events)
925  {
926  printf("[%s] Already unregistered\n", __FUNCTION__);
927  }
928  else
929  {
930  IARM_Result_t res;
931  IARM_CHECK( IARM_Bus_UnRegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_EVENT_onAvailableSSIDs) );
932  IARM_CHECK( IARM_Bus_UnRegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_EVENT_onAvailableSSIDsIncr) );
933  IARM_CHECK( IARM_Bus_UnRegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_EVENT_onError) );
934  IARM_CHECK( IARM_Bus_UnRegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_EVENT_onWIFIStateChanged) );
935  IARM_CHECK( IARM_Bus_UnRegisterEventHandler(IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_WIFI_MGR_EVENT_onSSIDsChanged) );
936 
937  Wifi_Mgr_Reg_Events = false;
938  }
939 
940  printf("[%s] Exiting..\r\n", __FUNCTION__);
941 #endif
942 }
943 
944 static void cleanup()
945 {
946 #ifdef ENABLE_IARM
947  if (Wifi_Mgr_Reg_Events)
948  {
949  WIFI_MGR_unregisterForEvents();
950  }
951  if (Net_Srv_Reg_Events)
952  {
953  NET_MGR_unregisterForEvents();
954  }
955 #endif //#ifdef ENABLE_IARM
956  return;
957 }
958 
959 void signal_handler (int sigNum)
960 {
961 #ifdef ENABLE_IARM
962  printf ("%s(): Received signal %d \n",__FUNCTION__, sigNum);
963 
964  cleanup();
965 
966  exit(0);
967 
968 #endif //#ifdef ENABLE_IARM
969 }
970 
971 int main()
972 {
973 #ifdef ENABLE_IARM
974  int input;
975  bool loop = true;
976  IARM_Result_t retVal = IARM_RESULT_SUCCESS;
977 // printf("[%s] Starting \'%s\' Client.\r\n", __FUNCTION__, IARM_BUS_NM_SRV_MGR_NAME);
978 
979  /* Signal handler */
980  signal (SIGHUP, signal_handler);
981  signal (SIGINT, signal_handler);
982  signal (SIGQUIT, signal_handler);
983  signal (SIGTERM, signal_handler);
984 
985  IARM_Bus_Init(NM_MGR_WIFI_CLIENT);
987 
988  do
989  {
990  printf("\n==================================================================\n");
991  printf("***** Network Mgr: Execute WiFi Manager Api's **** ");
992  printf("\n==================================================================\n");
993  for (int n = sizeof(options)/sizeof(options[0]), i = 0; i < n; i++)
994  printf( "%d. %s\n", options[i].number, options[i].name);
995  printf( "\n==================================================================\n");
996  printf( "\n Selection: " );
997  std::cin >> input;
998 
999  /* Get/Set RPC handler*/
1000  switch (input) {
1001  case Test_getAvailableSSIDs:
1002  WIFI_MGR_API_getAvailableSSIDs();
1003  break;
1004  case Test_getAvailableSSIDsWithName:
1005  WIFI_MGR_API_getAvailableSSIDsWithName();
1006  break;
1007  case Test_getCurrentState:
1008  WIFI_MGR_API_getCurrentState();
1009  break;
1010  case Test_setEnabled:
1011  WIFI_MGR_API_setEnabled();
1012  break;
1013  case Test_getPairedSSID:
1014  WIFI_MGR_API_getPairedSSID();
1015  break;
1016  case Test_connect:
1017  WIFI_MGR_API_connect();
1018  break;
1019  case Test_initiateWPSPairing:
1020  WIFI_MGR_API_initiateWPSPairing();
1021  break;
1022  case Test_initiateWPSPairing2:
1023  WIFI_MGR_API_initiateWPSPairing2();
1024  break;
1025  case Test_saveSSID:
1026  WIFI_MGR_API_saveSSID();
1027  break;
1028  case Test_clearSSID:
1029  WIFI_MGR_API_clearSSID();
1030  break;
1031  case Test_isPaired:
1032  WIFI_MGR_API_isPaired();
1033  break;
1034  case Test_getRadioProps:
1035  WIFI_MGR_API_getRadioProps();
1036  break;
1037  case Test_getRadioStatsProps:
1038  WIFI_MGR_API_getRadioStatsProps();
1039  break;
1040  case Test_getSSIDProps:
1041  WIFI_MGR_API_getSSIDProps();
1042  break;
1043 #ifdef ENABLE_LOST_FOUND
1044  case Test_getLAFState:
1045  WIFI_MGR_API_getLAFState();
1046  break;
1047 #endif
1048  case Test_getConnectedSSID:
1049  WIFI_MGR_API_getConnectedSSID();
1050  break;
1051  case Test_getEndPointProps:
1052  WIFI_MGR_API_getEndPointProps();
1053  break;
1054  case Test_getAvailableSSIDsIncr:
1055  WIFI_MGR_API_getAvailableSSIDsIncr();
1056  break;
1057  case Test_stopProgressiveScanning:
1058  WIFI_MGR_API_stopProgressiveScanning();
1059  break;
1060  case Test_disconnectSSID:
1061  WIFI_MGR_API_disconnectSSID();
1062  break;
1063  case Test_cancelWPSPairing:
1064  WIFI_MGR_API_cancelWPSPairing();
1065  break;
1066  case Test_nm_registerForEvents:
1067  NET_MGR_registerForEvents();
1068  break;
1069  case Test_nm_unregisterForEvents:
1070  NET_MGR_unregisterForEvents();
1071  break;
1072  case Test_wifi_registerForEvents:
1073  WIFI_MGR_registerForEvents();
1074  break;
1075  case Test_wifi_unregisterForEvents:
1076  WIFI_MGR_unregisterForEvents();
1077  break;
1078  default:
1079  loop = false;
1080  printf( "Wrong Input..., try again.\n" );
1081  break;
1082  }
1083  } while (loop);
1084 
1085  cleanup();
1086 
1088  IARM_Bus_Term();
1089 // printf("[%s] Exiting... \'%s\' Client Exiting\r\n", __FUNCTION__, IARM_BUS_NM_SRV_MGR_NAME );
1090 
1091 #endif
1092 }
netsrvmgrIarm.h
The header file provides components netSrvMgrIarm information APIs.
IARM_BUS_WIFI_MGR_API_initiateWPSPairing
#define IARM_BUS_WIFI_MGR_API_initiateWPSPairing
Definition: wifiSrvMgrIarmIf.h:66
IARM_Bus_Term
IARM_Result_t IARM_Bus_Term(void)
This API is used to terminate the IARM-Bus library.
IARM_BUS_WIFI_MGR_API_cancelWPSPairing
#define IARM_BUS_WIFI_MGR_API_cancelWPSPairing
Definition: wifiSrvMgrIarmIf.h:62
IARM_BUS_WIFI_MGR_API_initiateWPSPairing2
#define IARM_BUS_WIFI_MGR_API_initiateWPSPairing2
Definition: wifiSrvMgrIarmIf.h:67
IARM_BUS_NetSrvMgr_Iface_EventDefaultInterface_t
Definition: netsrvmgrIarm.h:159
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
IARM_BUS_WIFI_MGR_API_disconnectSSID
#define IARM_BUS_WIFI_MGR_API_disconnectSSID
Definition: wifiSrvMgrIarmIf.h:70
IARM_BUS_NetSrvMgr_Iface_EventInterfaceIPAddress_t
Definition: netsrvmgrIarm.h:152
IARM_Bus_Call_with_IPCTimeout
IARM_Result_t IARM_Bus_Call_with_IPCTimeout(const char *ownerName, const char *methodName, void *arg, size_t argLen, int timeout)
This API is used to Invoke RPC method by its application name and method name with specified timeout ...
IARM_BUS_WIFI_MGR_API_isPaired
#define IARM_BUS_WIFI_MGR_API_isPaired
Definition: wifiSrvMgrIarmIf.h:72
IARM_BUS_WIFI_MGR_API_getEndPointProps
#define IARM_BUS_WIFI_MGR_API_getEndPointProps
Definition: wifiSrvMgrIarmIf.h:86
IARM_Bus_RegisterEventHandler
IARM_Result_t IARM_Bus_RegisterEventHandler(const char *ownerName, IARM_EventId_t eventId, IARM_EventHandler_t handler)
This API register to listen to event and provide the callback function for event notification....
Definition: iarmMgrMocks.cpp:43
IARM_BUS_WIFI_MGR_API_setEnabled
#define IARM_BUS_WIFI_MGR_API_setEnabled
Definition: wifiSrvMgrIarmIf.h:64
IARM_BUS_WIFI_MGR_API_getLNFState
#define IARM_BUS_WIFI_MGR_API_getLNFState
Definition: wifiSrvMgrIarmIf.h:73
IARM_BUS_WIFI_MGR_API_connect
#define IARM_BUS_WIFI_MGR_API_connect
Definition: wifiSrvMgrIarmIf.h:65
_IARM_BUS_WiFi_DiagsPropParam_t
Definition: wifiSrvMgrIarmIf.h:396
IARM_Bus_Disconnect
IARM_Result_t IARM_Bus_Disconnect(void)
This API disconnect Application from IARM Bus so the application will not receive any IARM event or R...
IARM_BUS_WIFI_MGR_API_getCurrentState
#define IARM_BUS_WIFI_MGR_API_getCurrentState
Definition: wifiSrvMgrIarmIf.h:60
IARM_BUS_WIFI_MGR_API_getRadioStatsProps
#define IARM_BUS_WIFI_MGR_API_getRadioStatsProps
Definition: wifiSrvMgrIarmIf.h:83
SsidSecurity
enum _SsidSecurity SsidSecurity
libIBus.h
RDK IARM-Bus API Declarations.
IARM_BUS_WIFI_MGR_API_saveSSID
#define IARM_BUS_WIFI_MGR_API_saveSSID
Definition: wifiSrvMgrIarmIf.h:68
IARM_BUS_WIFI_MGR_API_getAvailableSSIDsAsyncIncr
#define IARM_BUS_WIFI_MGR_API_getAvailableSSIDsAsyncIncr
Definition: wifiSrvMgrIarmIf.h:58
IARM_BUS_WIFI_MGR_API_getConnectedSSID
#define IARM_BUS_WIFI_MGR_API_getConnectedSSID
Definition: wifiSrvMgrIarmIf.h:61
IARM_BUS_WIFI_MGR_API_clearSSID
#define IARM_BUS_WIFI_MGR_API_clearSSID
Definition: wifiSrvMgrIarmIf.h:69
IARM_BUS_WIFI_MGR_API_getPairedSSID
#define IARM_BUS_WIFI_MGR_API_getPairedSSID
Definition: wifiSrvMgrIarmIf.h:71
IARM_BUS_WIFI_MGR_API_getRadioProps
#define IARM_BUS_WIFI_MGR_API_getRadioProps
Definition: wifiSrvMgrIarmIf.h:82
_IARM_Bus_WiFiSrvMgr_SpecificSsidList_Param_t
Definition: wifiSrvMgrIarmIf.h:250
IARM_BUS_WIFI_MGR_API_stopProgressiveWifiScanning
#define IARM_BUS_WIFI_MGR_API_stopProgressiveWifiScanning
Definition: wifiSrvMgrIarmIf.h:59
IARM_BUS_NetSrvMgr_Iface_EventInterfaceStatus_t
Definition: netsrvmgrIarm.h:144
IARM_BUS_WIFI_MGR_API_getAvailableSSIDs
#define IARM_BUS_WIFI_MGR_API_getAvailableSSIDs
Definition: wifiSrvMgrIarmIf.h:55
_IARM_Bus_WiFiSrvMgr_WPS_Parameters_t
Definition: wifiSrvMgrIarmIf.h:277
_IARM_BUS_WiFiSrvMgr_EventData_t
Definition: wifiSrvMgrIarmIf.h:285
_IARM_Bus_WiFiSrvMgr_SsidList_Param_t
Definition: wifiSrvMgrIarmIf.h:240
IARM_Bus_Connect
IARM_Result_t IARM_Bus_Connect(void)
This API is used to connect application to the IARM bus daemon. After connected, the application can ...
Definition: iarmMgrMocks.cpp:33
_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
IARM_BUS_WIFI_MGR_API_getAvailableSSIDsWithName
#define IARM_BUS_WIFI_MGR_API_getAvailableSSIDsWithName
Definition: wifiSrvMgrIarmIf.h:56
IARM_Bus_UnRegisterEventHandler
IARM_Result_t IARM_Bus_UnRegisterEventHandler(const char *ownerName, IARM_EventId_t eventId)
This API is used to Remove ALL handlers registered for the given event. This API remove the all the e...
_IARM_Bus_WiFiSrvMgr_Param_t
Definition: wifiSrvMgrIarmIf.h:258
IARM_Bus_Init
IARM_Result_t IARM_Bus_Init(const char *name)
This API is used to initialize the IARM-Bus library.
Definition: iarmMgrMocks.cpp:38