3 * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 /*Product: Samsung NService Framework (remote-server)
22 * Copyright 2013-2014 SWC, Samsung Electronics, Inc.
23 * All rights reserved.
28 * @brief This file is resposible to run the convergence manager as deamon.
29 and initialize the RCR and convergence manager
30 * @created on: 2013.10.30
31 * @author: Shivaram Yadav (shivaram.y@samsung.com)
32 * @reviewer: Ji-Hoon Kim(jihoon95.kim@samsung.com), Han Kang (han264,kang@samsung.com)
36 #include <CCDebugRemote.h>
38 #include "IPCServer.h"
39 #include "MSFServer.h"
44 #include <systemd/sd-daemon.h>
48 #include "net_connection.h"
54 #define config_path_nservice "/opt/usr/apps/remote-server"
55 #define uri_nservice "nservice/"
57 #define NOTIFY_TIME 15000 //watchdog notify time
60 #define LOG_TAG "Remote_Daemon"
63 static GMainLoop* mainloop = NULL;
64 IPCServer* ipc_server = NULL;
65 MSFServer* msf_server = NULL;
66 const char *service_name = "remote-server";
68 gboolean watchdog_notify_callback(gpointer data)
75 REMOTE_PRINT_WARN("smart_deadlock_watchdog_notify failed return = %d", ret);
79 REMOTE_PRINT_WARN("[sd_notify debug] called sd_notify() : ret = %d : Proc : %s(%d)", ret, service_name, (unsigned long)getpid());
84 static void CheckWifiSecurityEncryption(connection_h connection_info)
86 //Check_Result (Wifi Check for Omission OK : 0, Not OK : 1)
87 //int Check_Result = 1;
89 REMOTE_PRINT_FATAL("CheckWifiSecurityEncryption START");
91 connection_h connection = connection_info;
92 connection_type_e connection_type;
93 connection_profile_h connection_profile;
94 connection_wifi_security_type_e connection_wifi_security_type;
95 connection_wifi_encryption_type_e connection_wifi_encryption_type;
97 if(connection == NULL)
99 REMOTE_PRINT_FATAL("Failed to get Connection Profile");
100 //pCMInstance->SetACLOmissionResult(Check_Result);
104 // Check WIFI & WPA2 & AES (If all those are applied to TV, Allow Omission Access Popup)
105 if(connection_get_type(connection, &connection_type) == CONNECTION_ERROR_NONE)
107 if(connection_type == CONNECTION_TYPE_WIFI)
109 if(connection_get_current_profile(connection, &connection_profile) != CONNECTION_ERROR_NONE)
111 REMOTE_PRINT_FATAL("Failed to get Connection Profile");
112 //pCMInstance->SetACLOmissionResult(Check_Result);
116 if(connection_profile_get_wifi_security_type(connection_profile, &connection_wifi_security_type) != CONNECTION_ERROR_NONE)
118 REMOTE_PRINT_DEBUG("Failed to get Wifi Security Type");
120 else if (connection_profile_get_wifi_encryption_type(connection_profile, &connection_wifi_encryption_type) != CONNECTION_ERROR_NONE)
122 REMOTE_PRINT_DEBUG("Failed to get Wifi Encryption Type");
124 else if ( (connection_wifi_security_type == CONNECTION_WIFI_SECURITY_TYPE_WPA_PSK) &
125 ( (connection_wifi_encryption_type == CONNECTION_WIFI_ENCRYPTION_TYPE_AES) || (connection_wifi_encryption_type == CONNECTION_WIFI_ENCRYPTION_TYPE_TKIP_AES_MIXED)))
128 REMOTE_PRINT_DEBUG("Wifi Check for Omission is OK");
129 //pCMInstance->SetACLOmissionResult(Check_Result);
134 REMOTE_PRINT_DEBUG("Not Allow Ommission Of Access Popup : Because of Security type & Encryption type");
140 REMOTE_PRINT_DEBUG("Failed to get Connection Type");
142 //pCMInstance->SetACLOmissionResult(Check_Result);
143 REMOTE_PRINT_FATAL("Wifi Check for Omission is Not OK");
146 void InitUpnpDevices()
149 ipc_server = new IPCServer();
152 msf_server = new MSFServer();
156 static void Setup_CMDaemon()
160 mainloop = g_main_loop_new(NULL, FALSE);
163 void getTvName_cb(keynode_t *key, void* data)
165 ipc_server->UpdateMITNode(); // update Node Server When TV Name is changed.
168 void NetworkIPChanged_cb(const char* ipv4_address, const char* ipv6_address, void* user_data)
170 if(ipv4_address != 0 && (strlen(ipv4_address) > 7))
172 REMOTE_PRINT_DEBUG("UpdateMITNode request, IP_address : [%s]", ipv4_address);
173 ipc_server->UpdateMITNode(); //update Node Server when IP is changed.
175 CheckWifiSecurityEncryption(user_data);
179 REMOTE_PRINT_DEBUG("There is no IP address");
180 //pCMInstance->SetACLOmissionResult(1); //Check WIFI for omission is 'Not OK'(1)
186 REMOTE_PRINT_MAJOR("remote server main");
191 vconf_notify_key_changed("db/menu/network/devicename/tv_name", getTvName_cb, NULL);
195 connection_h connection = NULL;
197 ret = connection_create(&connection);
198 if(ret == CONNECTION_ERROR_NONE)
200 // connection_set_type_changed_cb(connection, NetworkTypeChanged_cb, NULL);
201 CheckWifiSecurityEncryption(connection);
202 connection_set_ip_address_changed_cb(connection, NetworkIPChanged_cb, connection);
206 REMOTE_PRINT_DEBUG("Fail to create connection_set_type_changed_cb\n");
208 //REMOTE_PRINT_DEBUG("Start Convergence Manager!");
209 ret = aw_register(60);
212 REMOTE_PRINT_DEBUG("Fail to register argos watchdog. ret is (%d)\n", ret);
214 REMOTE_PRINT_DEBUG("Success to register argos watchdog. ret is (%d)\n", ret);
216 g_timeout_add(NOTIFY_TIME, watchdog_notify_callback, mainloop);
220 REMOTE_PRINT_DEBUG("remote-server mainloop Start");
221 g_main_loop_run(mainloop);
222 g_main_loop_unref(mainloop);
223 connection_destroy(connection);
227 REMOTE_PRINT_WARN("Fail to start Convergence Manager!");
230 vconf_ignore_key_changed("db/menu/network/devicename/tv_name", getTvName_cb);