4 #include <condition_variable>
16 #include "ocpayload.h"
21 #include "OCPlatform.h"
26 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
27 #include "ocprovisioningmanager.h"
28 #include "mbedtls/ssl_ciphersuites.h"
29 #include "byte_array.h"
30 #include <ca_adapter_net_ssl.h>
31 #endif // WITH_DTLS__ or __WITH_TLS__
33 #include "ua_client.h"
35 #define OC_SECURITY_DB_DAT_FILE_NAME "oic_svr_db.dat"
36 #define OC_RSRVD_PROTOCOL_INDEPENDENT_ID "piid"
37 #define OC_CONTROLEE_DATA_FILE_PATH "/opt/usr/data/ua_client/"
38 #define OC_CONTROLEE_DB_DAT_FILE_NAME ".firmware_controlee.dat"
40 #define UA_OCF_SERVER_URL "13.124.29.169:5683"
41 #define UA_CONTENTS_SERVER_URL "http://13.124.95.191:8000"
46 static GMainLoop* mainloop = NULL;
50 condition_variable g_callbackLock;
54 static void _set_device_info(const char *key, const char *value);
55 static void _get_device_info(ua_device_info_s *device);
56 static void _exec_update();
61 OCResourceHandle m_handle;
62 Resource(string uri, vector<string> rt, vector<string> itf)
64 m_representation.setUri(uri);
65 m_representation.setResourceTypes(rt);
66 m_representation.setResourceInterfaces(itf);
69 string getResourceUri()
71 return m_representation.getUri();
74 vector<string> getResourceType()
76 return m_representation.getResourceTypes();
79 vector<string> getInterfaces()
81 return m_representation.getResourceInterfaces();
84 OCRepresentation getRepresentation(void)
86 m_representation.clearChildren();
87 for (auto it = m_childResources.begin(); it != m_childResources.end(); it++)
89 m_representation.addChild((*it)->getRepresentation());
91 return m_representation;
94 OCStackResult addChildResource(Resource *childResource)
96 m_childResources.push_back(childResource);
97 return OCPlatform::bindResource(m_handle, childResource->m_handle);
100 OCStackResult sendRepresentation(shared_ptr<OCResourceRequest> pRequest)
102 auto pResponse = make_shared<OC::OCResourceResponse>();
103 pResponse->setRequestHandle(pRequest->getRequestHandle());
104 pResponse->setResourceHandle(pRequest->getResourceHandle());
106 // Check for query params (if any)
107 QueryParamsMap queryParamsMap = pRequest->getQueryParameters();
109 UA_LOG("\tquery params:");
110 for (auto it = queryParamsMap.begin(); it != queryParamsMap.end(); it++)
112 // UA_LOG("\t\t%s : %s", query1, query2);
115 auto findRes = queryParamsMap.find("if");
117 if (findRes != queryParamsMap.end())
119 pResponse->setResourceRepresentation(getRepresentation(), findRes->second);
123 pResponse->setResourceRepresentation(getRepresentation(), DEFAULT_INTERFACE);
126 pResponse->setResponseResult(OC_EH_OK);
128 return OCPlatform::sendResponse(pResponse);
131 OCStackResult propagate()
133 if (m_interestedObservers.size() > 0)
135 shared_ptr<OCResourceResponse> resourceResponse =
136 { make_shared<OCResourceResponse>() };
138 resourceResponse->setResourceRepresentation(getRepresentation(), DEFAULT_INTERFACE);
140 return OCPlatform::notifyListOfObservers(m_handle,
141 m_interestedObservers,
148 virtual OCEntityHandlerResult entityHandler(shared_ptr<OCResourceRequest> request) = 0;
151 OCRepresentation m_representation;
152 vector<Resource *> m_childResources;
153 ObservationIds m_interestedObservers;
157 class FirmwareResource : public Resource // x.samsung.firmware
160 string m_currentversion;
161 int m_state; //0: Idle, 1: Downloading, 2: Downloaded, 3: Updating
162 int m_result; //0: Initial, 1: success, 2: not enough space, 3: out of ram, 4: connection lost, 5: invalid binary, 6: invalid uri, 7: update failed, 8: unsupport protocol
166 int m_update; // 0: initial value 1: download , 2: upgrade, 3: auto
168 char szState[2] = {0,};
171 FirmwareResource(string uri, vector<string> rt, vector<string> itf, string cur_ver, string new_ver, string url, int update_state)
172 : Resource(uri, rt, itf)
174 m_currentversion = cur_ver;
175 update_state == 3 ? m_state = 0 : m_state = update_state;
178 m_newversion = new_ver;
181 m_representation.setValue<string>("currentversion", m_currentversion);
182 m_representation.setValue<int>("state", m_state);
183 m_representation.setValue<int>("result", m_result);
185 m_representation.setValue<string>("packageuri", m_packageuri);
186 m_representation.setValue<string>("newversion", m_newversion);
187 m_representation.setValue<int>("update", m_update);
190 void onUpdateFirmware()
192 UA_LOG("onUpdateFirmware() called");
193 if ((m_state == 0 && m_update == 1) || (m_state == 0 && m_update == 3)) {
194 UA_LOG("currentversion [%s]", m_currentversion.c_str());
195 UA_LOG("newversion [%s]", m_newversion.c_str());
197 if(g_strcmp0(m_currentversion.c_str(), m_newversion.c_str()) == 0 ||
198 g_strcmp0(m_newversion.c_str(), "") == 0) {
199 UA_LOG("no need for update cur=[%s], new=[%s]", m_currentversion.c_str(), m_newversion.c_str());
203 UA_LOG("***Downloading image from [%s] ***", m_packageuri.c_str());
204 //Downloading, Initial
206 m_representation.setValue<int>("state", m_state);
207 m_representation.setValue<int>("result", 0);
210 snprintf(szState, sizeof(szState), "%d", m_state);
211 _set_device_info("firmware_update_state", szState);
213 if (ua_http_download_file(m_packageuri.c_str()) != 0) {
214 UA_LOG("ua_http_download_file() is failed");
216 m_representation.setValue<int>("state", m_state);
217 snprintf(szState, sizeof(szState), "%d", m_state);
218 _set_device_info("firmware_update_state", szState);
222 UA_LOG("***Firmware Image downloaded***");
225 m_representation.setValue<int>("state", m_state);
228 snprintf(szState, sizeof(szState), "%d", m_state);
229 _set_device_info("firmware_update_state", szState);
232 if ((m_state == 2 && m_update == 2) || (m_state == 2 && m_update == 3)) {
235 m_representation.setValue<int>("state", m_update);
238 snprintf(szState, sizeof(szState), "%d", m_state);
239 _set_device_info("firmware_update_state", szState);
241 //After Upgrade, state = Idle
243 m_representation.setValue<int>("state", m_state);
244 m_representation.setValue<int>("result", 1);
246 m_newversion = m_representation.getValue<string>("newversion");
247 m_currentversion = m_representation.getValue<string>("currentversion");
249 UA_LOG("*** Update completed from %s to %s ***", m_currentversion.c_str(), m_newversion.c_str());
251 m_representation.setValue<string>("currentversion", m_newversion);
252 m_representation.setValue<string>("newversion", "");
253 m_representation.setValue<string>("packageuri", "");
254 m_currentversion = m_newversion;
259 snprintf(szState, sizeof(szState), "%d", m_state);
260 _set_device_info("firmware_update_state", szState);
262 _set_device_info("firmware_ver", m_currentversion.c_str());
269 static void *_worker(void *pArg)
271 FirmwareResource *pThread = (FirmwareResource *)pArg;
272 pThread->onUpdateFirmware();
276 void setFirmwareRepresentation(OCRepresentation &rep)
279 bool hasUpdates = false;
282 if (rep.getValue<string>("packageuri", tmpStr))
284 m_packageuri = tmpStr;
285 UA_LOG("\tpackageuri: %s", m_packageuri.c_str());
286 m_representation.setValue<string>("packageuri", m_packageuri);
289 if (rep.getValue<string>("newversion", tmpStr))
291 m_newversion = tmpStr;
292 UA_LOG("\tnewversion: %s", m_newversion.c_str());
293 m_representation.setValue<string>("newversion", m_newversion);
297 // if (rep.getValue<int>("updatemethod", m_updatemethod))
299 // UA_LOG("\t\t\t\t updatemethod: %d", m_updatemethod);
300 // m_representation.setValue<int>("updatemethod", m_updatemethod);
301 // hasUpdates = true;
304 if (rep.getValue<int>("update", tmpUpdate))
306 m_update = tmpUpdate;
307 UA_LOG("\tupdate: %d", m_update);
311 //Start temp thread to manage update simulator
312 pthread_create(&hThread, NULL, (void *(*)(void *))_worker, (void *)this);
321 OCEntityHandlerResult entityHandler(shared_ptr<OCResourceRequest> request)
323 UA_LOG("\tIn Server Firmware entity handler:");
324 OCEntityHandlerResult ehResult = OC_EH_ERROR;
328 // Get the request type and request flag
329 string requestType = request->getRequestType();
330 int requestFlag = request->getRequestHandlerFlag();
332 if (requestFlag & RequestHandlerFlag::RequestFlag)
334 UA_LOG("\trequestFlag : Request");
336 // If the request type is GET
337 if (requestType == "GET")
339 UA_LOG("\trequestType : GET");
340 if (OC_STACK_OK == sendRepresentation(request))
345 else if (requestType == "PUT")
347 UA_LOG("\ttrequestType : PUT");
348 // PUT requeist operations
350 else if (requestType == "POST")
352 UA_LOG("\trequestType : POST");
353 // POST request operations
354 OCRepresentation rep = request->getResourceRepresentation();
355 setFirmwareRepresentation(rep);
357 if (OC_STACK_OK == sendRepresentation(request))
362 else if (requestType == "DELETE")
364 UA_LOG("\trequestType : DELETE");
365 // DELETE request operations
369 if (requestFlag & RequestHandlerFlag::ObserverFlag)
371 UA_LOG("\trequestFlag : Observer");
373 ObservationInfo observationInfo = request->getObservationInfo();
374 if (ObserveAction::ObserveRegister == observationInfo.action)
376 m_interestedObservers.push_back(observationInfo.obsId);
378 else if (ObserveAction::ObserveUnregister == observationInfo.action)
380 m_interestedObservers.erase(remove(
381 m_interestedObservers.begin(),
382 m_interestedObservers.end(),
383 observationInfo.obsId),
384 m_interestedObservers.end());
390 UA_LOG("Request invalid");
397 #define UPDATE_FILE "/opt/usr/data/fota/init_tota"
399 static void _exec_update()
401 FILE* fp = fopen(UPDATE_FILE, "w");
403 UA_LOG("fopen error: %d", errno);
409 static void _exec_update()
412 GError *gerror = NULL;
414 #if !GLIB_CHECK_VERSION(2, 36, 0)
418 GCancellable *proxy_cancel = g_cancellable_new();
419 GDBusProxy* bproxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
420 G_DBUS_PROXY_FLAGS_NONE,
422 "org.tizen.system.tota",
423 "/Org/Tizen/System/Tota",
424 "org.tizen.system.tota",
429 UA_LOG ("g_dbus_proxy_new_for_bus_sync error [%s]", gerror->message);
431 g_object_unref (bproxy);
433 g_object_unref(proxy_cancel);
435 g_error_free (gerror);
439 GVariant *result = g_dbus_proxy_call_sync (bproxy,
442 G_DBUS_CALL_FLAGS_NONE,
449 UA_LOG ("g_dbus_proxy_call_sync error [%s]", gerror->message);
451 g_object_unref (bproxy);
454 g_object_unref(proxy_cancel);
457 g_error_free (gerror);
464 g_object_unref (bproxy);
467 g_object_unref(proxy_cancel);
470 g_error_free (gerror);
474 static void _set_device_info(const char *key, const char *value)
476 UA_LOG("_set_device_info() key = %s, value = %s", key, value);
478 GKeyFileFlags flags = G_KEY_FILE_NONE;
479 GError *error = NULL;
480 char file_path[256] = {0,};
482 keyfile = g_key_file_new();
484 snprintf(file_path, sizeof(file_path), "%s/%s", OC_CONTROLEE_DATA_FILE_PATH, "device_info.ini");
486 if (!g_key_file_load_from_file(keyfile, file_path, flags, &error)) {
487 UA_LOG("error=[%s]", error->message);
489 g_key_file_set_string(keyfile, "device_info", key, value);
490 g_key_file_save_to_file(keyfile, file_path, NULL);
491 g_key_file_unref(keyfile);
496 static void _get_device_info(ua_device_info_s *device)
499 GKeyFileFlags flags = G_KEY_FILE_NONE;
500 GError *error = NULL;
501 char file_path[256] = {0,};
503 keyfile = g_key_file_new();
505 snprintf(file_path, sizeof(file_path), "%s/%s", OC_CONTROLEE_DATA_FILE_PATH, "device_info.ini");
507 // wait for /opt/ mount
510 } while(!g_key_file_load_from_file(keyfile, file_path, flags, &error));
512 if (!g_key_file_load_from_file(keyfile, file_path, flags, &error)) {
513 UA_LOG("error=[%s]", error->message);
516 device->manufacturer = g_key_file_get_string(keyfile, "device_info", "manufacturer", NULL);
517 device->model_name = g_key_file_get_string(keyfile, "device_info", "model_name", NULL);
518 device->firmware_ver = g_key_file_get_string(keyfile, "device_info", "firmware_ver", NULL);
519 device->firmware_update_state = g_key_file_get_string(keyfile, "device_info", "firmware_update_state", NULL);
520 device->uuid = g_key_file_get_string(keyfile, "device_info", "uuid", NULL);
521 device->access_token = g_key_file_get_string(keyfile, "device_info", "access_token", NULL);
523 g_key_file_unref(keyfile);
526 UA_LOG("manufacturer=[%s]", device->manufacturer);
527 UA_LOG("model_name=[%s]", device->model_name);
528 UA_LOG("firmware_ver=[%s]", device->firmware_ver);
529 UA_LOG("firmware_update_state=[%s]", device->firmware_update_state);
530 UA_LOG("uuid=[%s]", device->uuid);
531 UA_LOG("access_token=[%s]", device->access_token);
534 void onPublish(const OCRepresentation &, const int &eCode)
536 UA_LOG("Publish resource response received, code: %d", eCode);
538 g_callbackLock.notify_all();
541 void printRepresentation(OCRepresentation rep)
543 for (auto itr = rep.begin(); itr != rep.end(); ++itr)
545 UA_LOG("\t%s:\t%s", (itr->attrname()).c_str(), (itr->getValueToString()).c_str());
546 if (itr->type() == AttributeType::Vector)
548 switch (itr->base_type())
550 case AttributeType::OCRepresentation:
551 for (auto itr2 : (*itr).getValue<vector<OCRepresentation> >())
553 printRepresentation(itr2);
557 case AttributeType::Integer:
558 for (auto itr2 : (*itr).getValue<vector<int> >())
560 UA_LOG("\t\t%d", itr2);
564 case AttributeType::String:
565 for (auto itr2 : (*itr).getValue<vector<string> >())
567 UA_LOG("\t\t%s", itr2.c_str());
572 UA_LOG("Unhandled base type = %d" , itr->base_type());
576 else if (itr->type() == AttributeType::OCRepresentation)
578 printRepresentation((*itr).getValue<OCRepresentation>());
583 void handleSignupCB(const HeaderOptions &,
584 const OCRepresentation &rep, const int ecode)
586 UA_LOG("Auth response received code: %d", ecode);
588 if (rep.getPayload() != NULL)
590 printRepresentation(rep);
595 g_accesstoken = rep.getValueToString("accesstoken");
596 g_uid = rep.getValueToString("uid");
598 _set_device_info("uuid", g_uid.c_str());
599 _set_device_info("access_token", g_accesstoken.c_str());
602 g_callbackLock.notify_all();
606 void handleSigninCB(const HeaderOptions &,
607 const OCRepresentation &rep, const int ecode)
609 UA_LOG("Auth response received code: %d", ecode);
611 if (rep.getPayload() != NULL)
613 printRepresentation(rep);
616 g_callbackLock.notify_all();
619 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
620 int saveTrustCert(void)
622 OCStackResult res = OC_STACK_ERROR;
623 uint16_t g_credId = 0;
625 UA_LOG("Save Trust Cert. Chain into Cred of SVR");
627 ByteArray trustCertChainArray = {0, 0};
629 FILE *fp = fopen("rootca.crt", "rb+");
634 if (fseeko(fp, 0, SEEK_END) == 0 && (fsize = ftello(fp)) > 0)
636 trustCertChainArray.data = (uint8_t *)malloc(fsize);
637 trustCertChainArray.len = fsize;
638 if (NULL == trustCertChainArray.data)
640 UA_LOG("Failed to allocate memory");
645 if (fsize != fread(trustCertChainArray.data, 1, fsize, fp))
647 UA_LOG("Certiface not read completely");
653 res = OCSaveTrustCertChain(trustCertChainArray.data, trustCertChainArray.len, OIC_ENCODING_PEM,
656 if (OC_STACK_OK != res)
658 UA_LOG("OCSaveTrustCertChainBin API error");
661 UA_LOG("CredId of Saved Trust Cert. Chain into Cred of SVR : %d", g_credId);
667 static FILE *client_open(const char *path, const char *mode)
669 if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
671 char *file_path = g_strconcat(OC_CONTROLEE_DATA_FILE_PATH, OC_CONTROLEE_DB_DAT_FILE_NAME, NULL);
672 FILE *fp = fopen(file_path, mode);
678 return fopen(path, mode);
682 OCStackResult SetDeviceInfo()
684 OCStackResult result = OC_STACK_ERROR;
686 OCResourceHandle handle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI);
690 UA_LOG("Failed to find resource [%s]", OC_RSRVD_DEVICE_URI);
694 //result = OCBindResourceTypeToResource(handle, "oic.d.airconditioner");
695 result = OCBindResourceTypeToResource(handle, "x.tizen.ri3");
697 if (result != OC_STACK_OK)
699 UA_LOG("Failed to add device type");
703 result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME, "TIZEN_RI3");
705 if (result != OC_STACK_OK)
707 UA_LOG("Failed to set device name");
711 result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_PROTOCOL_INDEPENDENT_ID,
712 "d7d2b492-83ac-4783-9dcc-b1b54587ebed");
714 if (result != OC_STACK_OK)
716 UA_LOG("Failed to set piid");
724 #include <net_connection.h>
726 connection_cellular_state_e get_cellular_network_state()
728 connection_h connection;
729 connection_create(&connection);
731 connection_cellular_state_e cellular_state;
732 connection_get_cellular_state(connection, &cellular_state);
733 connection_destroy(connection);
735 return cellular_state;
738 connection_wifi_state_e get_wifi_network_state()
740 connection_h connection;
741 connection_create(&connection);
743 connection_wifi_state_e wifi_state;
744 connection_get_wifi_state(connection, &wifi_state);
745 connection_destroy(connection);
751 int is_network_connected()
754 int network_state = 0;
756 if (get_cellular_network_state() == CONNECTION_CELLULAR_STATE_CONNECTED)
758 network_state = true;
762 if (get_wifi_network_state() == CONNECTION_ETHERNET_STATE_CONNECTED)
764 network_state = true;
768 if (get_wifi_network_state() == CONNECTION_WIFI_STATE_CONNECTED)
770 network_state = true;
773 return network_state;
777 void *_start_ua_client(void *data)
781 ua_device_info_s *device = (ua_device_info_s *)data;
784 unique_lock<mutex> lock(blocker);
786 UA_LOG("Registering firmware resources to platform...");
788 OCStackResult result = OC_STACK_ERROR;
794 /* Check new firmware version at content server */
795 char *http_url = g_strconcat(UA_CONTENTS_SERVER_URL, "/firmware", "?manufacturer=", device->manufacturer, "&model=", device->model_name, \
796 "&version=", device->firmware_ver, NULL);
798 char *httr_res_header = NULL;
799 char *httr_res_body = NULL;
801 char *old_ver = NULL;
802 char *new_ver = NULL;
803 char *download_url = NULL;
804 char *priority = NULL;
806 if (ua_http_send_request(UA_HTTP_GET, http_url, &httr_res_header, &httr_res_body) != 0) {
807 UA_LOG("ua_http_send_request() is failed");
811 ua_json_parser_firmware_info(httr_res_body, &old_ver, &new_ver, &download_url, &priority);
814 UA_LOG("firm_ver: %s , new_ver: %s", device->firmware_ver, new_ver);
816 string cur_firmware_ver((device->firmware_ver)?device->firmware_ver:"");
817 string new_firmware_ver((new_ver)?new_ver:"");
818 string new_url((download_url)?download_url:"");
820 UA_LOG("device->firmware_update_state: %s", device->firmware_update_state);
821 FirmwareResource firmware("/firmware", { "x.samsung.firmware" }, { DEFAULT_INTERFACE }, \
822 cur_firmware_ver, new_firmware_ver, new_url, atoi(device->firmware_update_state));
825 string cur_firmware_ver(device->firmware_ver);
826 string new_firmware_ver("");
828 FirmwareResource firmware("/firmware", { "x.samsung.firmware" }, { DEFAULT_INTERFACE }, \
829 cur_firmware_ver, new_firmware_ver, atoi(device->firmware_update_state));
832 uri = firmware.getResourceUri();
833 rt = firmware.getResourceType()[0];
834 itf = firmware.getInterfaces()[0];
836 // Time to Live is 30 seconds
837 OCPlatform::startPresence(30);
839 result = OCPlatform::registerResource(firmware.m_handle,
843 bind(&FirmwareResource::entityHandler,
844 &firmware, placeholders::_1),
845 OC_DISCOVERABLE | OC_OBSERVABLE);
847 UA_LOG("registerResource firmware: result = %d", result);
848 if (result != OC_STACK_OK) {
849 UA_LOG("Resource registration was unsuccessful, [%d]", result);
853 UA_LOG("Publishing resources to cloud");
855 result = SetDeviceInfo();
856 if (result != OC_STACK_OK) {
857 UA_LOG("SetDeviceInfo() is failed, [%d]", result);
861 OCPlatform::stopPresence();
863 ResourceHandles resourceHandles;
865 result = RDClient::Instance().publishResourceToRD(g_host, OCConnectivityType::CT_ADAPTER_TCP,
869 UA_LOG(" result: %d, Waiting Publish default resource response from cloud", result);
871 resourceHandles.push_back(firmware.m_handle);
873 result = RDClient::Instance().publishResourceToRD(g_host, OCConnectivityType::CT_ADAPTER_TCP,
877 UA_LOG(" result: %d, Waiting Publish user resource response from cloud", result);
879 g_callbackLock.wait(lock);
889 int main(int argc, char *argv[])
891 #if !GLIB_CHECK_VERSION(2, 31, 0)
895 #if !GLIB_CHECK_VERSION(2, 36, 0)
899 signal(SIGCHLD, SIG_IGN);
900 signal(SIGINT, SIG_IGN);
901 signal(SIGPIPE, SIG_IGN);
904 GThread *main_thd = NULL;
907 unique_lock<mutex> lock(blocker);
910 OCPersistentStorage ps{ client_open, fread, fwrite, fclose, unlink };
916 "0.0.0.0", // By setting to "0.0.0.0", it binds to all available interfaces
917 0, // Uses randomly available port
918 QualityOfService::LowQos,
922 OCPlatform::Configure(cfg);
924 g_host = "coap+tcp://";
926 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
927 g_host = "coaps+tcp://";
934 string ocf_server_url(UA_OCF_SERVER_URL);
935 g_host += ocf_server_url;
937 ua_device_info_s *device = (ua_device_info_s *)calloc(1, sizeof(ua_device_info_s));
939 _get_device_info(device);
941 UA_LOG("host address = %s", g_host.c_str());
943 OCAccountManager::Ptr accountMgr = OCPlatform::constructAccountManagerObject(g_host,
947 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
948 UA_LOG("Security Mode");
949 if (CA_STATUS_OK != saveTrustCert())
951 UA_LOG("saveTrustCert returned an error");
954 uint16_t cipher = MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256;
955 if (CA_STATUS_OK != CASelectCipherSuite(cipher, CA_ADAPTER_TCP))
957 UA_LOG("CASelectCipherSuite returned an error");
961 // wait for network connection
962 while(is_network_connected() == 0){
963 UA_LOG("network not ready");
968 if (device->uuid == NULL || (device->uuid && strlen(device->uuid) == 0)) {
971 fprintf(stderr, "\n\nPut \"[authprovider] [authcode]\" for sign-up and sign-in and publish resources!!\n\n");
974 UA_LOG("Sign-up...");
975 accountMgr->signUp(argv[1], argv[2], &handleSignupCB);
976 g_callbackLock.wait(lock);
977 UA_LOG("Sign-In...");
978 accountMgr->signIn(g_uid, g_accesstoken, &handleSigninCB);
979 g_callbackLock.wait(lock);
981 UA_LOG("Sign-In...");
982 string uuid(device->uuid);
983 string access_token(device->access_token);
984 accountMgr->signIn(uuid, access_token, &handleSigninCB);
985 g_callbackLock.wait(lock);
988 catch (exception& e){
989 UA_LOG("Authentication failed");
993 main_thd = g_thread_new("ua_client", _start_ua_client, (void *)device);
994 if (main_thd == NULL) {
995 UA_LOG("Fail to run main thread");
998 mainloop = g_main_loop_new(NULL, FALSE);
1000 if (mainloop != NULL) {
1001 UA_LOG("Start ua_client");
1002 g_main_loop_run(mainloop);
1004 UA_LOG("Fail to start ua_client");
1009 g_free(device->manufacturer);
1010 g_free(device->model_name);
1011 g_free(device->firmware_ver);
1012 g_free(device->firmware_update_state);
1013 g_free(device->uuid);
1014 g_free(device->access_token);