+ int responseCode = 0 ;
+ char responseCodeBuf[MAX_BUF_LEN] = { 0 };
+ if (CA_MSG_RESET != messageType)
+ {
+ printf("\n=============================================\n");
+ printf("\tselect response code\n");
+ printf("EMPTY : 0\n");
+ printf("CREATED : 201\n");
+ printf("DELETED : 202\n");
+ printf("VALID : 203\n");
+ printf("CHANGED : 204\n");
+ printf("CONTENT : 205\n");
+ printf("BAD_REQ : 400\n");
+ printf("BAD_OPT : 402\n");
+ printf("NOT_FOUND : 404\n");
+ printf("INTERNAL_SERVER_ERROR : 500\n");
+ printf("RETRANSMIT_TIMEOUT : 504\n");
+ printf("select : ");
+
+ if (CA_STATUS_OK != get_input_data(responseCodeBuf, MAX_BUF_LEN))
+ {
+ return;
+ }
+ responseCode = atoi(responseCodeBuf);
+ }
+
+ // create response data
+ uint16_t messageId = (info != NULL) ? info->messageId : 0;
+ CAURI_t resourceUri = (info != NULL) ? info->resourceUri : 0;
+
+ CAInfo_t responseData = { .type = messageType,
+ .messageId = messageId,
+ .token = NULL,
+ .tokenLength = 0,
+ .options = NULL,
+ .numOptions = 0,
+ .payload = NULL,
+ .payloadSize = 0,
+ .resourceUri = resourceUri };
+
+ if(CA_MSG_RESET != messageType)
+ {
+ responseData.token = (info != NULL) ? info->token : NULL;
+ responseData.tokenLength = (info != NULL) ? info->tokenLength : 0;
+
+ if (endpoint->flags & CA_SECURE)
+ {
+ if(!responseData.resourceUri)
+ {
+ printf("resourceUri not available in SECURE\n");
+ return;
+ }
+ printf("Sending response on secure communication\n");
+
+ uint32_t length = sizeof(SECURE_INFO_DATA) + strlen(responseData.resourceUri);
+ responseData.payload = (CAPayload_t) calloc(length, sizeof(char));
+ if (NULL == responseData.payload)
+ {
+ printf("Memory allocation fail\n");
+ return;
+ }
+ snprintf((char *) responseData.payload, length, SECURE_INFO_DATA,
+ (const char *) responseData.resourceUri, g_local_secure_port);
+ responseData.payloadSize = length;
+ }
+ else
+ {
+ printf("Sending response on non-secure communication\n");
+
+ bool useBigPayload = select_payload_type();
+ if (useBigPayload)
+ {
+ size_t payloadLength = 0;
+ CAPayload_t binaryPayload = get_binary_payload(&payloadLength);
+ if (NULL == binaryPayload)
+ {
+ free(binaryPayload);
+ return;
+ }
+
+ responseData.payload = (CAPayload_t) malloc(payloadLength);
+ if (NULL == responseData.payload)
+ {
+ printf("Memory allocation failed!");
+ free(binaryPayload);
+ return;
+ }
+ memcpy(responseData.payload, binaryPayload, payloadLength);
+ responseData.payloadSize = payloadLength;
+
+ // memory free
+ free(binaryPayload);
+ }
+ else
+ {
+ if(!responseData.resourceUri)
+ {
+ printf("resourceUri not available in NON-SECURE\n");
+ return;
+ }
+ uint32_t length = sizeof(NORMAL_INFO_DATA) + strlen(responseData.resourceUri);
+ responseData.payload = (CAPayload_t) calloc(length, sizeof(char));
+ if (NULL == responseData.payload)
+ {
+ printf("Memory allocation fail\n");
+ return;
+ }
+ snprintf((char *) responseData.payload, length, NORMAL_INFO_DATA,
+ (const char *) responseData.resourceUri);
+ responseData.payloadSize = length;
+ }
+ }
+ }
+
+ CAResponseInfo_t responseInfo = { .result = responseCode,
+ .info = responseData };
+
+ // send response (transportType from remoteEndpoint of request Info)
+ CAResult_t res = CASendResponse(endpoint, &responseInfo);
+ if (CA_STATUS_OK != res)
+ {
+ printf("Send response error\n");
+ }
+ else
+ {
+ printf("Send response success\n");
+ }
+
+ if (responseData.payload)
+ {
+ free(responseData.payload);
+ }