Change server to ocf reference 92/142092/2
authorSangkoo Kim <sangkoo.kim@samsung.com>
Wed, 2 Aug 2017 11:48:51 +0000 (20:48 +0900)
committerSangkoo Kim <sangkoo.kim@samsung.com>
Thu, 3 Aug 2017 02:43:25 +0000 (11:43 +0900)
Change-Id: I3ce226513a9ad96c65429feddf83d48851dbbb74
Signed-off-by: Sangkoo Kim <sangkoo.kim@samsung.com>
src/controlee_firmware_resource_internal.c
test/CMakeLists.txt
test/controlee_firmware_test.c

index bb07dab..79e3c9c 100644 (file)
@@ -177,12 +177,20 @@ void _update_firmware_resource(OCRepPayload *input)
        }
 
        int64_t *update = (int64_t *)calloc(1, sizeof(int64_t));
+       if (!update) {
+               FWR_LOGD("Memory allocation error!");
+               return;
+       }
+
        if (OCRepPayloadGetPropInt(input, OC_RSRVD_FIRMWARE_UPDATE, update)) {
                FWR_LOGD("update command = [%lld]", *update);
                pthread_t pThread;
                pthread_create(&pThread, NULL, _worker, update);
+       } else {
+               free(update);
        }
 
+
        controlee_propagate_firmware_resource();
 }
 
index c99234e..f00103b 100644 (file)
@@ -1,6 +1,7 @@
 set(testapp "controlee_firmware_test")
 
-ADD_DEFINITIONS(-D__WITH_DTLS__ -D__WITH_TLS__ -DRD_CLIENT)
+#ADD_DEFINITIONS(-D__WITH_DTLS__ -D__WITH_TLS__ -DRD_CLIENT)
+ADD_DEFINITIONS(-DRD_CLIENT)
 
 SET(CONTROLEE_FIRMWARE_TEST_SRCS
     ${CMAKE_CURRENT_SOURCE_DIR}/controlee_firmware_test.c
@@ -21,4 +22,4 @@ SET(LIBNAME controlee_firmware_resource)
 ADD_EXECUTABLE(${testapp} ${CONTROLEE_FIRMWARE_TEST_SRCS})
 TARGET_LINK_LIBRARIES(${testapp} ${test_pkgs_LIBRARIES} ${LIBNAME} ${RD_LIB} -lpthread)
 
-INSTALL(TARGETS ${testapp} DESTINATION bin/)
\ No newline at end of file
+INSTALL(TARGETS ${testapp} DESTINATION bin/)
index 3cb0449..8081f57 100644 (file)
 #include <ocstack.h>
 #include <ocpayload.h>
 #include <octypes.h>
-#include <ocprovisioningmanager.h>
 #include <rd_client.h>
+#ifdef _USE_WWST_
 #include <oickeepalive.h>
+#endif
+#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
+#include <ocprovisioningmanager.h>
+#endif
 
 #include <ckmc/ckmc-manager.h>
 
 #define DEFAULT_CONTEXT_VALUE 0x99
 #define LOGIN_OK 4
 
-#define OC_SECURITY_SQL_DB_FILE_NAME   "/opt/usr/data/ua-client/PDM.db"
 #define OC_CONTROLEE_DAT_FILE_PATH             "/opt/usr/data/ua-client/oic_svr_db_client.dat"
+#ifdef _USE_WWST_
+#define OC_SECURITY_SQL_DB_FILE_NAME   "/opt/usr/data/ua-client/PDM.db"
 #define CERT_FILE_PATH                                 "/opt/usr/data/ua-client/thawte.cert.pem"
+#endif
 
 OCResourceHandle res_handle[2];
 
 OCPersistentStorage *ps;
 
+#ifdef _USE_WWST_
 #define CLOUD_STG_SERVER                       "52.202.112.20:443"
 #define CLOUD_DEV_SERVER                       "54.86.109.131:443"
 #define CLOUD_AUTH_PROVIDER            "samsung-us"
 #define CLOUD_DEVICE_TYPE              "device"
+#define CLOUD_PROTOCOL                 "coaps+tcp://"
+#else
+#define CLOUD_STG_SERVER                       "52.78.68.250:5683"
+#define CLOUD_AUTH_PROVIDER            "tdc"
+#define CLOUD_PROTOCOL                 "coap+tcp://"
+#endif
 
 #define DEVICE_ID                      "di"
 #define CLIENT_ID                      "clientid"
@@ -43,6 +56,7 @@ OCPersistentStorage *ps;
 #define ACCESS_TOKEN           "accesstoken"
 #define USER_ID                                "uid"
 #define CLOUD_LOGIN                    "login"
+#define AUTH_CODE                      "authcode"
 
 #define CLOUD_ACCOUNT_RES_TYPE         "oic.wk.account"
 #define CLOUD_SESSION_RES_TYPE         "oic.wk.session"
@@ -59,9 +73,11 @@ typedef struct
        char *refreshToken;
        char *codeVerifier;
 
+#ifdef _USE_WWST_
        uint8_t *certificate;
        size_t certificateLength;
        OicEncodingType_t encodingType;
+#endif
 } CloudLoginInfo;
 
 
@@ -99,6 +115,7 @@ int _signup();
 
 int _set_auth_cert_info()
 {
+#ifdef _USE_WWST_
        char *certFile = CERT_FILE_PATH;
        ckmc_cert_s* cert = NULL;
        int ret_cert = ckmc_load_cert_from_file(certFile, &cert);
@@ -121,7 +138,7 @@ int _set_auth_cert_info()
                        printf("Cred ID from saveCertFile = [%d]\n", g_cred_id);
                }
        }
-
+#endif
        return 0;
 }
 
@@ -160,15 +177,24 @@ static void _parse_payload(OCRepPayload *payload)
        if (!payload)
                return;
 
+#ifdef _USE_WWST_
        char *sid, *certificate;
        if (!OCRepPayloadGetPropString(payload, "sid", &sid))
                printf("Can't get 'sid'\n");
 
        if (!OCRepPayloadGetPropString(payload, "certificate", &certificate))
                printf("Can't get 'certificate'\n");
+#else
+       if (!OCRepPayloadGetPropString(payload, USER_ID, &loginDetails.uid))
+               printf("Can't get 'uid'\n");
+
+       if (!OCRepPayloadGetPropString(payload, ACCESS_TOKEN, &loginDetails.accessToken))
+               printf("Can't get 'access_token'\n");
+#endif
 
 }
 
+#ifdef _USE_WWST_
 static OCStackApplicationResult _send_keep_alive_cb(void *context, OCDoHandle handle,
                                                        OCClientResponse * clientResponse)
 {
@@ -217,7 +243,7 @@ static void *_send_keep_alive(void *data)
                        ++i;
 
                        char uri[MAX_URI_LENGTH] = { 0 };
-                       snprintf(uri, MAX_URI_LENGTH, "coaps+tcp://%s", CLOUD_STG_SERVER);
+                       snprintf(uri, MAX_URI_LENGTH, "%s%s", CLOUD_PROTOCOL, CLOUD_STG_SERVER);
 
                        OCCallbackData cbData = {0,};
                        cbData.cb = _send_keep_alive_cb;
@@ -272,7 +298,7 @@ static void _keep_alive_cb(OCRepPayload *payload)
 
        return;
 }
-
+#endif
 
 void _set_platform_info()
 {
@@ -309,6 +335,7 @@ void _set_device_info()
 
 void _get_login_info()
 {
+#ifdef _USE_WWST_
        char tmp[64];
 
        printf("Enter access_token : ");
@@ -334,12 +361,13 @@ void _get_login_info()
        scanf("%s", tmp);
        loginDetails.clientId = g_strdup(tmp);
        printf("client_id : %s\n", loginDetails.clientId);
-
+#endif
        loginDetails.deviceId = g_strdup(OCGetServerInstanceIDString());
        printf("Device ID = [%s]\n", loginDetails.deviceId);
-}
 
+}
 
+#ifdef _USE_WWST_
 static OCStackApplicationResult _handle_keepalive_cb(void *context, OCDoHandle handle,
                                                                        OCClientResponse * clientResponse)
 {
@@ -358,13 +386,14 @@ static OCStackApplicationResult _handle_keepalive_cb(void *context, OCDoHandle h
        return OC_STACK_KEEP_TRANSACTION;
 }
 
+
 void *_ping_timer(void *timer)
 {
        OCStackResult ocResult = OC_STACK_ERROR;
        (void)timer;
 
        char uri[MAX_URI_LENGTH] = { 0 };
-       snprintf(uri, MAX_URI_LENGTH, "coaps+tcp://%s", CLOUD_STG_SERVER);
+       snprintf(uri, MAX_URI_LENGTH, "%s%s", CLOUD_PROTOCOL, CLOUD_STG_SERVER);
 
        OCCallbackData keepAliveCb = {0,};
        keepAliveCb.cb = _handle_keepalive_cb;
@@ -381,7 +410,7 @@ void *_ping_timer(void *timer)
 
        return NULL;
 }
-
+#endif
 
 static OCStackApplicationResult _handle_signin_response(void *ctx,
                                                                          OCDoHandle handle,
@@ -409,6 +438,7 @@ static OCStackApplicationResult _handle_signin_response(void *ctx,
                bSignin = true;
                printf("Sign-In Success!!!\n");
 
+#ifdef _USE_WWST_
                pthread_t pingThread;
                pthread_mutex_lock(&pingcycle_mutex);
                is_ping_timer = true;
@@ -417,6 +447,7 @@ static OCStackApplicationResult _handle_signin_response(void *ctx,
                int ret = pthread_create(&pingThread, NULL, _ping_timer, NULL);
                if (ret != 0)
                        printf("ping pthread_create fail!\n");
+#endif
        }
 
        return OC_STACK_KEEP_TRANSACTION;
@@ -474,8 +505,8 @@ static OCStackApplicationResult _handle_signout_response(void *ctx,
 int _signin()
 {
        char uri[MAX_URI_LENGTH] = { 0 };
-       snprintf(uri, MAX_URI_LENGTH, "coaps+tcp://%s%s",
-                       CLOUD_STG_SERVER, OC_RSRVD_ACCOUNT_SESSION_URI);
+       snprintf(uri, MAX_URI_LENGTH, "%s%s%s",
+                       CLOUD_PROTOCOL, CLOUD_STG_SERVER, OC_RSRVD_ACCOUNT_SESSION_URI);
        printf("server uri=[%s]\n", uri);
 
        OCCallbackData cbData;
@@ -522,8 +553,8 @@ int _signup()
        _set_auth_cert_info();
 
        char uri[MAX_URI_LENGTH] = { 0 };
-       snprintf(uri, MAX_URI_LENGTH, "coaps+tcp://%s%s",
-                       CLOUD_STG_SERVER, OC_RSRVD_ACCOUNT_URI);
+       snprintf(uri, MAX_URI_LENGTH, "%s%s%s",
+                       CLOUD_PROTOCOL, CLOUD_STG_SERVER, OC_RSRVD_ACCOUNT_URI);
        printf("server uri=[%s]\n", uri);
 
        OCCallbackData cbData;
@@ -536,6 +567,7 @@ int _signup()
        if (!payload) return -1;
 
        OCRepPayloadSetPropString(payload, AUTH_PROVIDER, CLOUD_AUTH_PROVIDER);
+#ifdef _USE_WWST_
        OCRepPayloadSetPropString(payload, DEVICE_TYPE, CLOUD_DEVICE_TYPE);
        OCRepPayloadSetPropString(payload, DEVICE_ID, (const char *)loginDetails.deviceId);
        OCRepPayloadSetPropString(payload, CLIENT_ID, (const char *)loginDetails.clientId);
@@ -543,6 +575,10 @@ int _signup()
        OCRepPayloadSetPropString(payload, USER_ID, (const char *)loginDetails.uid);
 //     OCRepPayloadAddResourceType(payload, CLOUD_ACCOUNT_RES_TYPE);
 //     OCRepPayloadAddInterface(payload, OC_RSRVD_INTERFACE_DEFAULT);
+#else
+       OCRepPayloadSetPropString(payload, AUTH_CODE, "123123123");
+       OCRepPayloadSetPropString(payload, DEVICE_ID, loginDetails.deviceId);
+#endif
 
        int ret;
        if (OCDoResource(NULL, OC_REST_POST, uri, NULL, (OCPayload *)payload,
@@ -561,8 +597,8 @@ int _signup()
 int _signout()
 {
        char uri[MAX_URI_LENGTH] = { 0 };
-       snprintf(uri, MAX_URI_LENGTH, "coaps+tcp://%s%s",
-                       CLOUD_STG_SERVER, OC_RSRVD_ACCOUNT_SESSION_URI);
+       snprintf(uri, MAX_URI_LENGTH, "%s%s%s",
+                       CLOUD_PROTOCOL, CLOUD_STG_SERVER, OC_RSRVD_ACCOUNT_SESSION_URI);
        printf("server uri=[%s]\n", uri);
 
        OCCallbackData cbData;
@@ -856,13 +892,14 @@ int _init_oc_stack()
                return -1;
        }
 
+#ifdef _USE_WWST_
        if (OCInitPM(OC_SECURITY_SQL_DB_FILE_NAME) == OC_STACK_OK) {
                printf("OCInitPM() is succeeded!\n");
        } else {
                printf("OCInitPM() is failed");
                return -1;
        }
-
+#endif
        _set_platform_info();
 
        _set_device_info();
@@ -929,8 +966,9 @@ int _publish_fw_res_to_rd()
        cb_data.context = (void *)DEFAULT_CONTEXT_VALUE;
 
        char uri[MAX_URI_LENGTH] = { 0 };
-       snprintf(uri, MAX_URI_LENGTH, "coaps+tcp://%s", CLOUD_STG_SERVER);
+       snprintf(uri, MAX_URI_LENGTH, "%s%s", CLOUD_PROTOCOL, CLOUD_STG_SERVER);
 
+#ifdef _USE_WWST_
        if (OCRDPublish(NULL, uri, CT_ADAPTER_TCP|CT_IP_USE_V4,
                        NULL, 0,
                        &cb_data, OC_LOW_QOS) != OC_STACK_OK) {
@@ -946,6 +984,23 @@ int _publish_fw_res_to_rd()
                printf("OCRDPublish() failed\n");
                return -1;
        }
+#else
+       if (OCRDPublish(uri, CT_ADAPTER_TCP|CT_IP_USE_V4,
+                       NULL, 0,
+                       &cb_data, OC_LOW_QOS) != OC_STACK_OK) {
+               printf("OCRDPublish() failed\n");
+               return -1;
+       }
+
+       _lock_and_wait();
+
+       if (OCRDPublish(uri, CT_ADAPTER_TCP|CT_IP_USE_V4,
+                       res_handle, 2,
+                       &cb_data, OC_LOW_QOS) != OC_STACK_OK) {
+               printf("OCRDPublish() failed\n");
+               return -1;
+       }
+#endif
 
        _lock_and_wait();
 
@@ -962,14 +1017,23 @@ int _delete_fw_res_from_rd()
        cb_data.context = (void *)DEFAULT_CONTEXT_VALUE;
 
        char uri[MAX_URI_LENGTH] = { 0 };
-       snprintf(uri, MAX_URI_LENGTH, "coaps+tcp://%s", CLOUD_STG_SERVER);
+       snprintf(uri, MAX_URI_LENGTH, "%s%s", CLOUD_PROTOCOL, CLOUD_STG_SERVER);
 
+#ifdef _USE_WWST_
        if (OCRDDelete(NULL, uri, CT_ADAPTER_TCP|CT_IP_USE_V4,
                        res_handle, 2,
                        &cb_data, OC_LOW_QOS) != OC_STACK_OK) {
                printf("OCRDDelete() failed\n");
                return -1;
        }
+#else
+       if (OCRDDelete(uri, CT_ADAPTER_TCP|CT_IP_USE_V4,
+                       res_handle, 2,
+                       &cb_data, OC_LOW_QOS) != OC_STACK_OK) {
+               printf("OCRDDelete() failed\n");
+               return -1;
+       }
+#endif
 
        _lock_and_wait();