#define SYSTEM_INVOKE_ERROR 127
#define SYSTEM_ERROR -1
+#ifdef WITH_BWT
#define BLOCK_SIZE(arg) (1 << ((arg) + 4))
+#endif
/**
* @def RS_IDENTITY
void handle_request_response();
void get_network_info();
void send_secure_request();
+#ifdef CI_ADAPTER
+void create_tcp_connection();
+#endif
void request_handler(const CAEndpoint_t *object, const CARequestInfo_t *requestInfo);
void response_handler(const CAEndpoint_t *object, const CAResponseInfo_t *responseInfo);
static const char COAP_PREFIX[] = "coap://";
static const char COAPS_PREFIX[] = "coaps://";
+static const char COAP_TCP_PREFIX[] = "coap+tcp://";
+
static const uint16_t COAP_PREFIX_LEN = sizeof(COAP_PREFIX) - 1;
static const uint16_t COAPS_PREFIX_LEN = sizeof(COAPS_PREFIX) - 1;
+static const uint16_t COAP_TCP_PREFIX_LEN = sizeof(COAP_TCP_PREFIX) - 1;
static const char SECURE_INFO_DATA[] =
"{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
get_network_info();
break;
+#ifdef CI_ADAPTER
+ case 'p': // create tcp connection
+ case 'P':
+ create_tcp_connection();
+ break;
+#endif
+
default:
printf("not supported menu!!\n");
break;
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");
+#ifdef CI_ADAPTER
+ printf("coap+tcp://10:11:12:13:45:45/resource_uri ( for CI )\n");
+#endif
}
else
{
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");
+#ifdef CI_ADAPTER
+ printf("coap+tcp://10:11:12:13:45:45/resource_uri ( for CI )\n");
+#endif
printf("uri : ");
char uri[MAX_BUF_LEN] = { 0 };
printf("IP : 0\n");
printf("GATT : 1\n");
printf("RFCOMM : 2\n");
+#ifdef CI_ADAPTER
+ printf("CI : 5\n");
+#endif
printf("select : ");
char buf[MAX_BUF_LEN] = { 0 };
int number = buf[0] - '0';
- if (number < 0 || number > 3)
+ if (number < 0 || number > 5)
{
printf("Invalid network type\n");
return;
printf("IP : 0\n");
printf("GATT : 1\n");
printf("RFCOMM : 2\n");
+#ifdef CI_ADAPTER
+ printf("CI : 5\n");
+#endif
printf("select : ");
char buf[MAX_BUF_LEN] = { 0 };
int number = buf[0] - '0';
- if (number < 0 || number > 3)
+ if (number < 0 || number > 5)
{
printf("Invalid network type\n");
return;
printf("\th : handle request response\n");
printf("\tz : run static server\n");
printf("\tw : send secure request\n");
+#ifdef CI_ADAPTER
+ printf("\tp : create tcp connection\n");
+#endif
printf("\tq : quit\n");
printf("=============================================\n");
printf("select : ");
}
}
+#ifdef WITH_BWT
// if received message is bulk data, create output file
if ((requestInfo->info.payload) &&
(requestInfo->info.payloadSize > BLOCK_SIZE(CA_DEFAULT_BLOCK_SIZE)))
{
create_file(requestInfo->info.payload, requestInfo->info.payloadSize);
}
+#endif
printf("Send response with URI\n");
send_response(object, &requestInfo->info);
}
}
+#ifdef WITH_BWT
// if received message is bulk data, create output file
if ((responseInfo->info.payload) &&
(responseInfo->info.payloadSize > BLOCK_SIZE(CA_DEFAULT_BLOCK_SIZE)))
{
create_file(responseInfo->info.payload, responseInfo->info.payloadSize);
}
+#endif
}
void error_handler(const CAEndpoint_t *rep, const CAErrorInfo_t* errorInfo)
printf("IP : 0\n");
printf("GATT : 1\n");
printf("RFCOMM : 2\n");
+#ifdef CI_ADAPTER
+ printf("CI : 5\n");
+#endif
printf("select : ");
if (CA_STATUS_OK != get_input_data(buf, MAX_BUF_LEN))
int number = buf[0] - '0';
- number = (number < 0 || number > 3) ? 0 : 1 << number;
+ number = (number < 0 || number > 5) ? 0 : 1 << number;
- if (number == 1)
+ switch (number)
{
- g_selected_nw_type = CA_ADAPTER_IP;
- return CA_STATUS_OK;
- }
- if (number == 2)
- {
- g_selected_nw_type = CA_ADAPTER_GATT_BTLE;
- return CA_STATUS_OK;
- }
- if (number == 3)
- {
- g_selected_nw_type = CA_ADAPTER_RFCOMM_BTEDR;
- return CA_STATUS_OK;
+ case CA_ADAPTER_IP:
+ case CA_ADAPTER_GATT_BTLE:
+ case CA_ADAPTER_RFCOMM_BTEDR:
+#ifdef CI_ADAPTER
+ case CA_ADAPTER_CLOUD_INTERFACE:
+#endif
+ g_selected_nw_type = number;
+ return CA_STATUS_OK;
+ default:
+ return CA_NOT_SUPPORTED;
}
-
- return CA_NOT_SUPPORTED;
}
CAResult_t get_input_data(char *buf, int32_t length)
startIndex = COAP_PREFIX_LEN;
*flags = CA_IPV4;
}
+#ifdef CI_ADAPTER
+ else if (strncmp(COAP_TCP_PREFIX, uri, COAP_TCP_PREFIX_LEN) == 0)
+ {
+ printf("uri has '%s' prefix\n", COAP_TCP_PREFIX);
+ startIndex = COAP_TCP_PREFIX_LEN;
+ *flags = CA_IPV4_TCP;
+ }
+#endif
// #2. copy uri for parse
int32_t len = strlen(uri) - startIndex;
return true;
}
+
+#ifdef CI_ADAPTER
+void create_tcp_connection()
+{
+ printf("Enter the CI Server information....\n");
+ printf("IP: ");
+ char address[MAX_BUF_LEN] = {'\0'};
+ if (CA_STATUS_OK != get_input_data(address, MAX_BUF_LEN))
+ {
+ return;
+ }
+ printf("Port: ");
+ char port[MAX_BUF_LEN] = {'\0'};
+ if (CA_STATUS_OK != get_input_data(port, MAX_BUF_LEN))
+ {
+ return;
+ }
+
+ int portNum = atoi(port);
+ CACIServerInfo_t serverInfo = { .u4tcp.port = portNum };
+ strncpy(serverInfo.addr, address, strlen(address));
+
+ CAResult_t res = CACreateTCPConnection(&serverInfo);
+ if (CA_STATUS_OK != res)
+ {
+ printf("Failed to create TCP Connection");
+ }
+}
+#endif