Beispiel #1
0
JNIEXPORT void JNICALL
Java_org_iotivity_ca_service_RMInterface_RMSendNotification(JNIEnv *env, jobject obj, jstring uri,
                                                            jstring payload, jint selectedNetwork,
                                                            jint isSecured, jint msgType,
                                                            jint responseValue)
{
    LOGI("selectedNetwork - %d", selectedNetwork);
    if (!env || !obj)
    {
        LOGI("Invalid input parameter");
        return;
    }

    if (!payload)
    {
        LOGE("payload is NULL");
    }

    if (!uri)
    {
        LOGE("Invalid input parameter : uri");
        return;
    }

    CAResult_t res = get_network_type(selectedNetwork);
    if (CA_STATUS_OK != res)
    {
        LOGE("Not supported network type");
        return;
    }

    const char* strUri = (*env)->GetStringUTFChars(env, uri, NULL);
    LOGI("RMSendNotification - %s", strUri);

    CATransportFlags_t flags;
    addressSet_t address = {{0}, 0};
    parsing_coap_uri(strUri, &address, &flags);

    //create remote endpoint
    CAEndpoint_t* endpoint = NULL;
    if (CA_STATUS_OK != CACreateEndpoint(flags, g_selectedNwType,
                                         (const char*)address.ipAddress,
                                         address.port, &endpoint))
    {
        //ReleaseStringUTFChars for strUri
        (*env)->ReleaseStringUTFChars(env, uri, strUri);
        LOGE("Could not create remote end point");
        return;
    }

    char resourceURI[RESOURCE_URI_LENGTH + 1] = { 0 };
    get_resource_uri(strUri, resourceURI, RESOURCE_URI_LENGTH);

    //ReleaseStringUTFChars for strUri
    (*env)->ReleaseStringUTFChars(env, uri, strUri);

    CAMessageType_t messageType = msgType;

    // create token
    CAToken_t token = NULL;
    uint8_t tokenLength = CA_MAX_TOKEN_LEN;

    res = CAGenerateToken(&token, tokenLength);
    if ((CA_STATUS_OK != res) || (!token))
    {
        LOGE("token generate error!");
        CADestroyEndpoint(endpoint);
        return;
    }

    CAInfo_t responseData = { 0 };
    responseData.token = token;
    responseData.tokenLength = tokenLength;
    responseData.resourceUri = (CAURI_t) malloc(sizeof(resourceURI));
    if (NULL == responseData.resourceUri)
    {
        LOGE("Memory allocation failed!");
        // destroy token
        CADestroyToken(token);
        // destroy remote endpoint
        CADestroyEndpoint(endpoint);
        return;
    }
    memcpy(responseData.resourceUri, resourceURI, sizeof(resourceURI));

    if (1 == isSecured)
    {
        uint32_t length = sizeof(SECURE_INFO_DATA) + strlen(resourceURI);
        responseData.payload = (CAPayload_t) malloc(length);
        if (NULL == responseData.payload)
        {
            LOGE("Memory allocation failed!");
            // destroy token
            CADestroyToken(token);
            // destroy remote endpoint
            CADestroyEndpoint(endpoint);

            free(responseData.resourceUri);
            return;
        }
        snprintf((char *) responseData.payload, length, SECURE_INFO_DATA, resourceURI, g_localSecurePort);
        responseData.payloadSize = length;
    }
    else
    {
        uint32_t length = sizeof(NORMAL_INFO_DATA) + strlen(resourceURI);
        responseData.payload = (CAPayload_t) malloc(length);
        if (NULL == responseData.payload)
        {
            LOGE("Memory allocation failed!");
            // destroy token
            CADestroyToken(token);
            // destroy remote endpoint
            CADestroyEndpoint(endpoint);

            free(responseData.resourceUri);
            return;
        }
        snprintf((char *) responseData.payload, length, NORMAL_INFO_DATA, resourceURI);
        responseData.payloadSize = length;
    }

    responseData.type = messageType;

    CAResponseInfo_t responseInfo = { 0 };
    responseInfo.result = responseValue;
    responseInfo.info = responseData;

    // send notification
    if (CA_STATUS_OK != CASendNotification(endpoint, &responseInfo))
    {
        LOGE("Could not send notification");
    }

    LOGI("Send Notification");

    // destroy token
    CADestroyToken(token);

    // destroy remote endpoint
    CADestroyEndpoint(endpoint);

    free(responseData.payload);
    free(responseData.resourceUri);
}
void send_request()
{
    CAResult_t res = get_network_type();
    if (CA_STATUS_OK != res)
    {
        return;
    }

    printf("Do you want to send secure request ?.... enter (0/1): ");

    char secureRequest[MAX_BUF_LEN] = {0};
    if (CA_STATUS_OK != get_input_data(secureRequest, MAX_BUF_LEN))
    {
        return;
    }

    if (strcmp(secureRequest, "1") == 0)
    {
        printf("Enter the URI like below....\n");
        printf("coaps://10.11.12.13:4545/resource_uri ( for IP secure)\n");
    }
    else if (strcmp(secureRequest, "0") == 0)
    {
        printf("Enter the URI like below....\n");
        printf("coap://10.11.12.13:4545/resource_uri ( for IP )\n");
        printf("coap://10:11:12:13:45:45/resource_uri ( for BT )\n");
        printf("coap+tcp://10:11:12:13:45:45/resource_uri ( for TCP )\n");
    }
    else
    {
        printf("Input data is wrong value\n");
        return;
    }

    char uri[MAX_BUF_LEN] = {'\0'};
    if (CA_STATUS_OK != get_input_data(uri, MAX_BUF_LEN))
    {
        return;
    }

    // create remote endpoint
    CAEndpoint_t *endpoint = NULL;
    CATransportFlags_t flags;

    printf("URI : %s\n", uri);
    addressSet_t address = {};
    parse_coap_uri(uri, &address, &flags);

    res = CACreateEndpoint(flags, g_selected_nw_type,
                           (const char*)address.ipAddress, address.port, &endpoint);
    if (CA_STATUS_OK != res || !endpoint)
    {
        printf("Failed to create remote endpoint, error code : %d\n", res);
        return;
    }

    printf("\n=============================================\n");
    printf("0:CON, 1:NON\n");
    printf("select message type : ");

    char buf[MAX_BUF_LEN] = { 0 };
    if (CA_STATUS_OK != get_input_data(buf, MAX_BUF_LEN))
    {
        CADestroyEndpoint(endpoint);
        return;
    }

    CAMessageType_t msgType = (buf[0] == '1') ? 1 : 0;

    // create token
    CAToken_t token = NULL;
    uint8_t tokenLength = CA_MAX_TOKEN_LEN;

    res = CAGenerateToken(&token, tokenLength);
    if ((CA_STATUS_OK != res) || (!token))
    {
        printf("Token generate error, error code : %d\n", res);
        CADestroyEndpoint(endpoint);
        return;
    }

    printf("Generated token %s\n", token);

    // extract relative resourceuri from give uri
    char resourceURI[RESOURCE_URI_LENGTH + 1] = {0};
    get_resource_uri(uri, resourceURI, RESOURCE_URI_LENGTH);
    printf("resourceURI : %s\n", resourceURI);

    // create request data
    CAInfo_t requestData = { 0 };
    requestData.token = token;
    requestData.tokenLength = tokenLength;
    requestData.resourceUri = (CAURI_t)resourceURI;

    if (strcmp(secureRequest, "1") == 0)
    {
        size_t length = sizeof(SECURE_INFO_DATA) + strlen(resourceURI);
        requestData.payload = (CAPayload_t) calloc(length,  sizeof(char));
        if (NULL == requestData.payload)
        {
            printf("Memory allocation fail\n");
            CADestroyEndpoint(endpoint);
            CADestroyToken(token);
            return;
        }
        snprintf((char *) requestData.payload, length, SECURE_INFO_DATA,
                 (const char *) resourceURI, g_local_secure_port);
    }
    else
    {
        bool useBigPayload = select_payload();
        if (useBigPayload)
        {
            requestData.payload = (CAPayload_t) calloc(BIG_PAYLOAD_SIZE, sizeof(char));
            if (NULL == requestData.payload)
            {
                printf("Memory allocation fail\n");
                CADestroyEndpoint(endpoint);
                CADestroyToken(token);
                return;
            }
            populate_binary_payload(requestData.payload, BIG_PAYLOAD_SIZE);
        }
        else
        {
            size_t length = sizeof(NORMAL_INFO_DATA) + strlen(resourceURI);
            requestData.payload = (CAPayload_t) calloc(length, sizeof(char));
            if (NULL == requestData.payload)
            {
                printf("Memory allocation fail\n");
                CADestroyEndpoint(endpoint);
                CADestroyToken(token);
                return;
            }
            snprintf((char *) requestData.payload, length, NORMAL_INFO_DATA,
                     (const char *) resourceURI);
        }
    }
    requestData.payloadSize = strlen((char *)requestData.payload)+1;
    requestData.type = msgType;

    CARequestInfo_t requestInfo = { 0 };
    requestInfo.method = CA_GET;
    requestInfo.info = requestData;
    requestInfo.isMulticast = false;

    // send request
    res = CASendRequest(endpoint, &requestInfo);
    if (CA_STATUS_OK != res)
    {
        printf("Could not send request : %d\n", res);
    }

    //destroy token
    CADestroyToken(token);
    // destroy remote endpoint
    CADestroyEndpoint(endpoint);
    free(requestData.payload);


    printf("=============================================\n");
}
Beispiel #3
0
void send_request()
{
    CAResult_t res = get_network_type();
    if (CA_STATUS_OK != res)
    {
        return;
    }

    printf("Do you want to send secure request ?.... enter (0/1): ");

    char secureRequest[MAX_BUF_LEN] = {0};
    if (CA_STATUS_OK != get_input_data(secureRequest, MAX_BUF_LEN))
    {
        return;
    }

    if (strcmp(secureRequest, "1") == 0)
    {
        printf("Enter the URI like below....\n");
        printf("coaps://10.11.12.13:4545/resource_uri ( for IP secure)\n");
    }
    else if (strcmp(secureRequest, "0") == 0)
    {
        printf("Enter the URI like below....\n");
        printf("coap://10.11.12.13:4545/resource_uri ( for IP )\n");
        printf("coap://10:11:12:13:45:45/resource_uri ( for BT )\n");
    }
    else
    {
        printf("Input data is wrong value\n");
        return;
    }

    char uri[MAX_BUF_LEN] = {'\0'};
    if (CA_STATUS_OK != get_input_data(uri, MAX_BUF_LEN))
    {
        return;
    }

    // create remote endpoint
    CAEndpoint_t *endpoint = NULL;
    CATransportFlags_t flags;

    printf("URI : %s\n", uri);
    addressSet_t address = {{}, 0};
    parsing_coap_uri(uri, &address, &flags);

    res = CACreateEndpoint(flags, g_selected_nw_type,
                           (const char*)address.ipAddress, address.port, &endpoint);
    if (CA_STATUS_OK != res || !endpoint)
    {
        printf("Failed to create remote endpoint, error code : %d\n", res);
        return;
    }

    printf("\n=============================================\n");
    printf("0:CON, 1:NON\n");
    printf("select message type : ");

    char buf[MAX_BUF_LEN] = { 0 };
    if (CA_STATUS_OK != get_input_data(buf, MAX_BUF_LEN))
    {
        CADestroyEndpoint(endpoint);
        return;
    }

    CAMessageType_t msgType = (buf[0] == '1') ? 1 : 0;

    // create token
    CAToken_t token = NULL;
    uint8_t tokenLength = CA_MAX_TOKEN_LEN;

    res = CAGenerateToken(&token, tokenLength);
    if ((CA_STATUS_OK != res) || (!token))
    {
        printf("Token generate error, error code : %d\n", res);
        CADestroyEndpoint(endpoint);
        return;
    }

    printf("Generated token %s\n", token);

    // extract relative resourceuri from give uri
    char resourceURI[RESOURCE_URI_LENGTH + 1] = {0};
    get_resource_uri(uri, resourceURI, RESOURCE_URI_LENGTH);
    printf("resourceURI : %s\n", resourceURI);

    // create request data
    CAInfo_t requestData = { .type = msgType,
                             .messageId = 0,
                             .token = token,
                             .tokenLength = tokenLength,
                             .options = NULL,
                             .numOptions = 0,
                             .payload = NULL,
                             .payloadSize = 0,
                             .resourceUri = (CAURI_t)resourceURI };

    if (strcmp(secureRequest, "1") == 0)
    {
        size_t length = sizeof(SECURE_INFO_DATA) + strlen(resourceURI);
        requestData.payload = (CAPayload_t) calloc(length,  sizeof(char));
        if (NULL == requestData.payload)
        {
            printf("Memory allocation fail\n");
            CADestroyEndpoint(endpoint);
            CADestroyToken(token);
            return;
        }
        snprintf((char *) requestData.payload, length, SECURE_INFO_DATA,
                 (const char *) resourceURI, g_local_secure_port);
        requestData.payloadSize = length;
    }
    else
    {
        bool useBigPayload = select_payload_type();
        if (useBigPayload)
        {
            size_t payloadLength = 0;
            CAPayload_t binaryPayload = get_binary_payload(&payloadLength);
            if (!binaryPayload)
            {
                free(binaryPayload);
                CADestroyToken(token);
                CADestroyEndpoint(endpoint);
                return;
            }

            requestData.payload = (CAPayload_t) malloc(payloadLength);
            if (NULL == requestData.payload)
            {
                printf("Memory allocation failed!");
                free(binaryPayload);
                CADestroyToken(token);
                CADestroyEndpoint(endpoint);
                return;
            }
            memcpy(requestData.payload, binaryPayload, payloadLength);
            requestData.payloadSize = payloadLength;

            // memory free
            free(binaryPayload);
        }
        else
        {
            size_t length = sizeof(NORMAL_INFO_DATA) + strlen(resourceURI);
            requestData.payload = (CAPayload_t) calloc(length, sizeof(char));
            if (NULL == requestData.payload)
            {
                printf("Memory allocation fail\n");
                CADestroyEndpoint(endpoint);
                CADestroyToken(token);
                return;
            }
            snprintf((char *) requestData.payload, length, NORMAL_INFO_DATA,
                     (const char *) resourceURI);
            requestData.payloadSize = length;
        }
    }

    CAHeaderOption_t* headerOpt = get_option_data(&requestData);

    CARequestInfo_t requestInfo = { .method = CA_GET,
                                    .info = requestData,
                                    .isMulticast = false };

    // send request
    res = CASendRequest(endpoint, &requestInfo);
    if (CA_STATUS_OK != res)
    {
        printf("Could not send request : %d\n", res);
    }

    if (headerOpt)
    {
        free(headerOpt);
    }

    //destroy token
    CADestroyToken(token);
    // destroy remote endpoint
    CADestroyEndpoint(endpoint);
    free(requestData.payload);

    printf("=============================================\n");
}

void send_secure_request()
{
    char uri[MAX_BUF_LEN];
    char ipv4addr[CA_IPADDR_SIZE];

    printf("\n=============================================\n");
    printf("Enter IPv4 address of the source hosting secure resource (Ex: 11.12.13.14)\n");

    if (CA_STATUS_OK != get_input_data(ipv4addr, CA_IPADDR_SIZE))
    {
        return;
    }
    snprintf(uri, MAX_BUF_LEN, "%s%s:5684/a/light", COAPS_PREFIX, ipv4addr);

    // create remote endpoint
    CAEndpoint_t *endpoint = NULL;
    CAResult_t res = CACreateEndpoint(0, CA_ADAPTER_IP, ipv4addr, SECURE_DEFAULT_PORT, &endpoint);
    if (CA_STATUS_OK != res)
    {
        printf("Failed to create remote endpoint, error code: %d\n", res);
        goto exit;
    }

    // create token
    CAToken_t token = NULL;
    uint8_t tokenLength = CA_MAX_TOKEN_LEN;

    res = CAGenerateToken(&token, tokenLength);
    if (CA_STATUS_OK != res)
    {
        printf("Token generate error, error code : %d\n", res);
        goto exit;
    }

    printf("Generated token %s\n", token);

    // create request data
    CAInfo_t requestData = { .type = CA_MSG_NONCONFIRM,
                             .messageId = 0,
                             .token = token,
                             .tokenLength = tokenLength,
                             .options = NULL,
                             .numOptions = 0,
                             .payload = NULL,
                             .payloadSize = 0,
                             .resourceUri = NULL };

    CARequestInfo_t requestInfo = { .method = CA_GET,
                                    .info = requestData,
                                    .isMulticast = false };

    // send request
    CASendRequest(endpoint, &requestInfo);

exit:
    // cleanup
    CADestroyToken(token);
    CADestroyEndpoint(endpoint);
    printf("=============================================\n");
}


void send_request_all()
{
    CAResult_t res = get_network_type();
    if (CA_STATUS_OK != res)
    {
        return;
    }

    printf("\n=============================================\n");
    printf("ex) /a/light\n");
    printf("resource uri : ");

    char resourceURI[MAX_BUF_LEN] = { 0 };
    if (CA_STATUS_OK != get_input_data(resourceURI, MAX_BUF_LEN))
    {
        return;
    }

    // create remote endpoint
    CAEndpoint_t *group = NULL;
    res = CACreateEndpoint(CA_IPV4, g_selected_nw_type, NULL, 0, &group);
    if (CA_STATUS_OK != res)
    {
        printf("Create remote endpoint error, error code: %d\n", res);
        return;
    }

    // create token
    CAToken_t token = NULL;
    uint8_t tokenLength = CA_MAX_TOKEN_LEN;

    res = CAGenerateToken(&token, tokenLength);
    if ((CA_STATUS_OK != res) || (!token))
    {
        printf("Token generate error!!\n");
        CADestroyEndpoint(group);
        return;
    }

    printf("generated token %s\n", token);

    // create request data
    CAPayload_t payload = (CAPayload_t) "TempJsonPayload";
    size_t payloadSize = strlen((const char *) payload);

    CAInfo_t requestData = { .type = CA_MSG_NONCONFIRM,
                             .messageId = 0,
                             .token = token,
                             .tokenLength = tokenLength,
                             .options = NULL,
                             .numOptions = 0,
                             .payload = payload,
                             .payloadSize = payloadSize,
                             .resourceUri = (CAURI_t) resourceURI };

    CARequestInfo_t requestInfo = { .method = CA_GET,
                                    .info = requestData,
                                    .isMulticast = true };

    CAHeaderOption_t* headerOpt = get_option_data(&requestData);

    // send request
    res = CASendRequest(group, &requestInfo);
    if (CA_STATUS_OK != res)
    {
        printf("Could not send request to all\n");
        CADestroyToken(token);
    }
    else
    {
        CADestroyToken(g_last_request_token);
        g_last_request_token = token;
    }

    if (headerOpt)
    {
        free(headerOpt);
    }

    // destroy remote endpoint
    CADestroyEndpoint(group);

    printf("=============================================\n");
}

void send_notification()
{
    CAResult_t res = get_network_type();
    if (CA_STATUS_OK != res)
    {
        return;
    }

    printf("\n=============================================\n");
    printf("Enter the URI like below....\n");
    printf("coap://10.11.12.13:4545/resource_uri ( for IP )\n");
    printf("coap://10:11:12:13:45:45/resource_uri ( for BT )\n");
    printf("uri : ");

    char uri[MAX_BUF_LEN] = { 0 };
    if (CA_STATUS_OK != get_input_data(uri, MAX_BUF_LEN))
    {
        return;
    }

    printf("\n=============================================\n");
    printf("\tselect message type\n");
    printf("CON     : 0\n");
    printf("NON     : 1\n");
    printf("ACK     : 2\n");
    printf("RESET   : 3\n");
    printf("select : ");

    char messageTypeBuf[MAX_BUF_LEN] = { 0 };
    if (CA_STATUS_OK != get_input_data(messageTypeBuf, MAX_BUF_LEN))
    {
        return;
    }

    int messageType = messageTypeBuf[0] - '0';

    CATransportFlags_t flags;
    addressSet_t address = {{}, 0};
    parsing_coap_uri(uri, &address, &flags);

    // create remote endpoint
    CAEndpoint_t *endpoint = NULL;
    res = CACreateEndpoint(flags, g_selected_nw_type, address.ipAddress, address.port, &endpoint);
    if (CA_STATUS_OK != res)
    {
        printf("Create remote endpoint error, error code: %d\n", res);
        return;
    }

    // create token
    CAToken_t token = NULL;
    uint8_t tokenLength = CA_MAX_TOKEN_LEN;

    res = CAGenerateToken(&token, tokenLength);
    if ((CA_STATUS_OK != res) || (!token))
    {
        printf("Token generate error!!\n");
        CADestroyEndpoint(endpoint);
        return;
    }

    printf("Generated token %s\n", token);

    // create response data
    CAPayload_t payload = (CAPayload_t) "TempNotificationData";
    size_t payloadSize = strlen((const char *) payload);

    CAInfo_t respondData = { .type = messageType,
                             .messageId = 0,
                             .token = token,
                             .tokenLength = tokenLength,
                             .options = NULL,
                             .numOptions = 0,
                             .payload = payload,
                             .payloadSize = payloadSize,
                             .resourceUri = (CAURI_t)uri };

    CAResponseInfo_t responseInfo = { .result = CA_CONTENT,
                                      .info = respondData };

    // send request
    res = CASendNotification(endpoint, &responseInfo);
    if (CA_STATUS_OK != res)
    {
        printf("Send notification error, error code: %d\n", res);
    }
    else
    {
        printf("Send notification success\n");
    }

    // destroy token
    CADestroyToken(token);
    // destroy remote endpoint
    CADestroyEndpoint(endpoint);

    printf("\n=============================================\n");
}

void select_network()
{
    printf("\n=============================================\n");
    printf("\tselect network\n");
    printf("IP     : 0\n");
    printf("GATT   : 1\n");
    printf("RFCOMM : 2\n");
    printf("select : ");

    char buf[MAX_BUF_LEN] = { 0 };
    if (CA_STATUS_OK != get_input_data(buf, MAX_BUF_LEN))
    {
        return;
    }

    int number = buf[0] - '0';

    if (number < 0 || number > 3)
    {
        printf("Invalid network type\n");
        return;
    }

    CAResult_t res = CASelectNetwork(1 << number);
    if (CA_STATUS_OK != res)
    {
        printf("Select network error\n");
    }
    else
    {
        printf("Select network success\n");
    }

    printf("=============================================\n");
}
JNIEXPORT void JNICALL
Java_org_iotivity_ca_service_RMInterface_RMSendRequest(JNIEnv *env, jobject obj, jstring uri,
                                                       jstring payload, jint selectedNetwork,
                                                       jint isSecured, jint msgType,
                                                       jboolean isBigData)
{
    LOGI("selectedNetwork - %d", selectedNetwork);
    if (!env || !obj)
    {
        LOGI("Invalid input parameter");
        return;
    }

    if (!uri)
    {
        LOGE("Invalid input parameter : uri");
        return;
    }

    CAResult_t res = get_network_type(selectedNetwork);
    if (CA_STATUS_OK != res)
    {
        return;
    }

    const char* strUri = (*env)->GetStringUTFChars(env, uri, NULL);
    LOGI("RMSendRequest - %s", strUri);

    CATransportFlags_t flags;
    addressSet_t address = {{0}, 0};
    parsing_coap_uri(strUri, &address, &flags);

    //create remote endpoint
    CAEndpoint_t* endpoint = NULL;
    res = CACreateEndpoint(flags, g_selectedNwType, (const char*)(address.ipAddress),
                           address.port, &endpoint);
    if (CA_STATUS_OK != res)
    {
        LOGE("Could not create remote end point");
        (*env)->ReleaseStringUTFChars(env, uri, strUri);
        return;
    }

    CAMessageType_t messageType = msgType;

    // create token
    CAToken_t token = NULL;
    uint8_t tokenLength = CA_MAX_TOKEN_LEN;

    res = CAGenerateToken(&token, tokenLength);
    if ((CA_STATUS_OK != res) || (!token))
    {
        LOGE("token generate error!!");
        // destroy remote endpoint
        CADestroyEndpoint(endpoint);
        (*env)->ReleaseStringUTFChars(env, uri, strUri);
        return;
    }

    char resourceURI[RESOURCE_URI_LENGTH + 1] = { 0 };

    get_resource_uri((const CAURI_t) strUri, resourceURI, RESOURCE_URI_LENGTH);
    (*env)->ReleaseStringUTFChars(env, uri, strUri);

    CAInfo_t requestData = { 0 };
    requestData.token = token;
    requestData.tokenLength = tokenLength;

    size_t payloadLength = 0;
    if (isBigData)
    {
        const char* path = NULL;
        if (payload)
        {
            path = (*env)->GetStringUTFChars(env, payload, NULL);
            if(path)
            {
                char* bigData = NULL;
                bool result = read_file(path, &bigData, &payloadLength);
                if (!result)
                {
                    LOGE("read has failed");
                    (*env)->ReleaseStringUTFChars(env, payload, path);
                    CADestroyToken(token);
                    CADestroyEndpoint(endpoint);
                    return;
                }
                (*env)->ReleaseStringUTFChars(env, payload, path);

                requestData.payload = (CAPayload_t) malloc(payloadLength);
                if (NULL == requestData.payload)
                {
                    LOGE("Memory allocation failed!");
                    // destroy token
                    CADestroyToken(token);
                    // destroy remote endpoint
                    CADestroyEndpoint(endpoint);
                    return;
                }
                memcpy(requestData.payload, bigData, payloadLength);
                requestData.payloadSize = payloadLength;
            }
        }
    }
    else
    {
        if (isSecured)
        {
            payloadLength = sizeof(SECURE_INFO_DATA) + strlen(resourceURI);
            requestData.payload = (CAPayload_t) malloc(payloadLength);
            if (NULL == requestData.payload)
            {
                LOGE("Memory allocation failed!");
                // destroy token
                CADestroyToken(token);
                // destroy remote endpoint
                CADestroyEndpoint(endpoint);
                return;
            }
            snprintf((char *) requestData.payload, payloadLength, SECURE_INFO_DATA,
                     resourceURI, g_localSecurePort);
            requestData.payloadSize = payloadLength;
        }
        else
        {
            payloadLength = sizeof(NORMAL_INFO_DATA) + strlen(resourceURI);
            requestData.payload = (CAPayload_t) malloc(payloadLength);
            if (NULL == requestData.payload)
            {
                LOGE("Memory allocation failed!");
                // destroy token
                CADestroyToken(token);
                // destroy remote endpoint
                CADestroyEndpoint(endpoint);
                return;
            }
            snprintf((char *) requestData.payload, payloadLength, NORMAL_INFO_DATA, resourceURI);
            requestData.payloadSize = payloadLength;
        }
    }

    requestData.type = messageType;
    requestData.resourceUri = (CAURI_t) malloc(sizeof(resourceURI));
    if (NULL == requestData.resourceUri)
    {
        LOGE("Memory allocation failed!");
        // destroy token
        CADestroyToken(token);
        // destroy remote endpoint
        CADestroyEndpoint(endpoint);
        free(requestData.payload);
        return;
    }
    memcpy(requestData.resourceUri, resourceURI, sizeof(resourceURI));

    CARequestInfo_t requestInfo = { 0 };
    requestInfo.method = CA_GET;
    requestInfo.isMulticast = false;
    requestInfo.info = requestData;

    // send request
    if (CA_STATUS_OK != CASendRequest(endpoint, &requestInfo))
    {
        LOGE("Could not send request");
    }

    // destroy token
    CADestroyToken(token);

    // destroy remote endpoint
    CADestroyEndpoint(endpoint);

    free(requestData.payload);
    free(requestData.resourceUri);
}