From: Jin-Seong Kim Date: Thu, 10 Aug 2017 02:47:28 +0000 (+0900) Subject: examples/libcoap : minor updates on libcoap examples X-Git-Tag: 1.1_Public_Release~318^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=466c2218a6a91a3fa1fa5a8b32f2df3beaec0325;p=rtos%2Ftinyara.git examples/libcoap : minor updates on libcoap examples This commit is minor updates on libcoap examples 1. build error fix without WITH_MBEDTLS 2. be able to test TCP without WITH_MBEDTLS Change-Id: I44116c6b6a7768891e6dbaeaf9d95e90c6096e57 Signed-off-by: Jin-Seong Kim --- diff --git a/apps/examples/libcoap_client/libcoap-client.c b/apps/examples/libcoap_client/libcoap-client.c index e92d120..e3d03ec 100644 --- a/apps/examples/libcoap_client/libcoap-client.c +++ b/apps/examples/libcoap_client/libcoap-client.c @@ -631,6 +631,7 @@ void usage(const char *program, const char *version) #ifdef WITH_MBEDTLS "examples for secure session:\n" "\tlibcoap-client -m get coaps://[::1]/.well-known/core\n" + "\tlibcoap-client -m get coaps+tcp://[::1]/.well-known/core\n" #endif , program, version, program, wait_seconds); } @@ -1173,6 +1174,7 @@ int main(int argc, char **argv) if (optind < argc) { protocol = coap_get_protocol_from_uri(argv[optind]); +#ifdef WITH_MBEDTLS if (protocol >= COAP_PROTO_MAX) { printf("coap-client : uri prefix might be wrong %s\n", argv[optind]); return 0; @@ -1182,6 +1184,12 @@ int main(int argc, char **argv) if (protocol != COAP_PROTO_UDP) msgtype = COAP_MESSAGE_NON; } +#else + if (protocol != COAP_PROTO_UDP && protocol != COAP_PROTO_TCP) { + printf("coap-client : not supported protocol\n"); + return 0; + } +#endif /* WITH_MBEDTLS*/ cmdline_uri(argv[optind]); } else { usage(argv[0], PACKAGE_VERSION); diff --git a/apps/examples/libcoap_server/libcoap-server.c b/apps/examples/libcoap_server/libcoap-server.c index c14e311..ef59c82 100644 --- a/apps/examples/libcoap_server/libcoap-server.c +++ b/apps/examples/libcoap_server/libcoap-server.c @@ -385,10 +385,13 @@ static void usage(const char *program, const char *version) "\t-v num\t\tverbosity level (default: 3)\n" #ifdef WITH_MBEDTLS "\t-P protocol\t\t type of transport protocol\n" - "\t\t\t\t - 0 : UDP, 1 : DTLS (default : 0)\n" + "\t\t\t\t - 0 : UDP, 1 : DTLS , 2 : TCP, 3 : TLS (default : 0)\n" "\t-i identity\tPre-Shared Key identity used to security session\n" "\t-s pre-shared key\tPre-Shared Key. Input length MUST be even (e.g, 11, 1111.)\n" -#endif +#else + "\t-P protocol\t\t type of transport protocol\n" + "\t\t\t\t - 0 : UDP, 2 : TCP (default : 0)\n" +#endif /* WITH_MBEDTLS */ "\t-Q exit server program\n" , program, version, program); } @@ -550,25 +553,30 @@ int main(int argc, char **argv) } if (cred.psk_identity == NULL && cred.psk == NULL) { printf("coap-server : failed to set psk info\n"); - return -1; + goto exit; } } else { printf("coap-server : need to set psk and psk ID\n"); - return -1; + goto exit; } tls_context = TLSCtx(&cred); if (tls_context == NULL) { printf("coap-server : failed to initialize TLS context\n"); - return -1; + goto exit; } } -#endif +#else + if (protocol == COAP_PROTO_TLS || protocol == COAP_PROTO_DTLS) { + printf("coap-server : not supported protocol\n"); + goto exit; + } +#endif /* WITH_MBEDTLS */ #ifdef WITH_MBEDTLS if (coap_net_bind(ctx, NULL, port_str, (void *)tls_context, (void *)&tls_option) < 0) #else - if (coap_net_bind(ctx, NULL, NULL) < 0) + if (coap_net_bind(ctx, NULL, port_str, NULL, NULL) < 0) #endif { printf("coap-server : failed to get session from client\n"); @@ -609,10 +617,8 @@ int main(int argc, char **argv) result = select(FD_SETSIZE, &readfds, 0, 0, timeout); if (result < 0) { /* error */ - if (errno != EINTR) { - printf("ERROR : failed to on select, errno %d\n", errno); - break; - } + printf("ERROR : failed on select, errno %d\n", errno); + break; } else if (result > 0) { /* read from socket */ if (FD_ISSET(ctx->sockfd, &readfds)) { coap_read(ctx); /* read received data */