From: Jin-Seong Kim Date: Fri, 7 Apr 2017 00:18:35 +0000 (+0900) Subject: external/wakaama: add an lwm2m client application X-Git-Tag: 1.1_Public_Release~614^2~126 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1ed8ee194d9f59ed308cf8a9d4adcd47cc4a49a0;p=rtos%2Ftinyara.git external/wakaama: add an lwm2m client application This commit is initial commit to support lwm2mclient example - lwm2mclient callback function for pthread is changed to lwm2m_client_run - to support arguments comes from pthread, add lwm2m_client_input structure Change-Id: Ica1e930ec49c084e24e1af32ee750c35a0dfe3ac Signed-off-by: Jin-Seong Kim --- diff --git a/apps/system/utils/netcmd.c b/apps/system/utils/netcmd.c index f12a40b..45edc9f 100644 --- a/apps/system/utils/netcmd.c +++ b/apps/system/utils/netcmd.c @@ -164,6 +164,9 @@ extern int artik_demo_main(int argc, char *argv[]); extern int mqtt_client_sub_main(int argc, char *argv[]); extern int mqtt_client_pub_main(int argc, char *argv[]); #endif +#ifdef CONFIG_DM +extern int lwm2m_client_main(int argc, char *argv[]); +#endif #if defined(CONFIG_NETUTILS_TFTPC) struct tftpc_args_s { @@ -777,6 +780,9 @@ const static tash_cmdlist_t net_appcmds[] = { {"mqtt_sub", mqtt_client_sub_main, TASH_EXECMD_SYNC}, {"mqtt_pub", mqtt_client_pub_main, TASH_EXECMD_SYNC}, #endif +#ifdef CONFIG_DM + {"lwm2mclient", lwm2m_client_main, TASH_EXECMD_SYNC}, +#endif {NULL, NULL, 0} }; diff --git a/external/wakaama/examples/client/Make.defs b/external/wakaama/examples/client/Make.defs index f82ca77..2671245 100644 --- a/external/wakaama/examples/client/Make.defs +++ b/external/wakaama/examples/client/Make.defs @@ -36,10 +36,16 @@ ifeq ($(CONFIG_DM),y) CSRCS += lwm2mclient.c +CSRCS += object_access_control.c CSRCS += object_connectivity_moni.c object_connectivity_stat.c CSRCS += object_device.c +CSRCS += object_firmware.c CSRCS += object_location.c CSRCS += object_security.c +CSRCS += object_server.c +CSRCS += system_api.c +CSRCS += test_object.c + # Interface API functions for dm frameworks CSRCS += connectivity_interface.c diff --git a/external/wakaama/examples/client/lwm2mclient.c b/external/wakaama/examples/client/lwm2mclient.c index 5efc621..1099591 100644 --- a/external/wakaama/examples/client/lwm2mclient.c +++ b/external/wakaama/examples/client/lwm2mclient.c @@ -80,6 +80,10 @@ #include #include +#if defined (__TINYARA__) +#include +#endif + #define MAX_PACKET_SIZE 1024 #define DEFAULT_SERVER_IPV6 "[::1]" #define DEFAULT_SERVER_IPV4 "127.0.0.1" @@ -106,19 +110,19 @@ #define STDERR_FILENO 2 #endif -#define SET_PARAM_DM_FRAMEWORK -10 +#define SET_PARAM_BY_GLOBAL_VALUE -10 #define DEFAULT_CLIENT_NAME "myawesomeclient" #define IPADDRLEN_MAX 32 #define PORTLEN_MAX 6 /* Global variables */ -static char g_serverAddr[IPADDRLEN_MAX]; -static char g_serverPort[PORTLEN_MAX]; -static char g_bootstrapserverAddr[IPADDRLEN_MAX]; -static char g_bootstrapserverPort[PORTLEN_MAX]; -static uint16_t g_lifetime; -bool g_bootstrapRequested; +static char g_serverAddr[IPADDRLEN_MAX] = {0,}; +static char g_serverPort[PORTLEN_MAX] = {0,}; +static char g_bootstrapserverAddr[IPADDRLEN_MAX] = {0,}; +static char g_bootstrapserverPort[PORTLEN_MAX] = {0,}; +static uint16_t g_lifetime = 300; +bool g_bootstrapRequested = false; #endif /* __TINYARA__ */ @@ -154,6 +158,8 @@ static void clear_client_globals(void); static void prv_close_sock(void); static void prv_update_server(client_data_t *dataP, uint16_t secObjInstID); static void process_udpconn(int sockfd, fd_set *readfds, client_data_t data); + +static int read_input_command_line(char *buf); #endif /*__TINYARA__*/ static void prv_quit(char * buffer, @@ -1007,7 +1013,7 @@ int lwm2m_client_main(int argc, char *argv[]) opt += 1; } #if defined (__TINYARA__) - if (argc == SET_PARAM_DM_FRAMEWORK) { + if (argc == SET_PARAM_BY_GLOBAL_VALUE) { /* To handling parameters set through dm frameworks */ name = DEFAULT_CLIENT_NAME; lifetime = g_lifetime; @@ -1405,7 +1411,7 @@ int lwm2m_client_main(int argc, char *argv[]) #endif { #if defined (__TINYARA__) - numBytes = read(STDIN_FILENO, buffer, MAX_PACKET_SIZE - 1); + numBytes = read_input_command_line((char *)buffer); #else numBytes = read(stdin, buffer, MAX_PACKET_SIZE - 1); #endif @@ -1474,10 +1480,16 @@ int lwm2m_client_main(int argc, char *argv[]) /* Public APIs */ -pthread_addr_t lwm2m_client_run(void) +pthread_addr_t lwm2m_client_run(void *arg) { + struct lwm2mclient_input *input; - lwm2m_client_main(SET_PARAM_DM_FRAMEWORK, NULL); + if (arg == NULL) { + lwm2m_client_main(SET_PARAM_BY_GLOBAL_VALUE, NULL); + } else { + input = arg; + lwm2m_client_main(input->argc, input->argv); + } return 0; } @@ -1634,6 +1646,67 @@ int client_object_dump(char *buffer) /* Private APIs */ +static int read_input_command_line(char *buf) +{ + char buffer[MAX_PACKET_SIZE] = {0,}; + + int nbytes = 0; + int pos = 0; + int char_idx = 0; + int bufsize = MAX_PACKET_SIZE; + + do { + nbytes = read(STDIN_FILENO, &buffer[pos], (bufsize - pos)); + if (nbytes <= 0) { + fprintf(stderr, "cannot read command\n"); + return 0; + } + + for (char_idx = 0; char_idx < nbytes; char_idx++) { + if ((buffer[pos] == ASCII_BS) || (buffer[pos] == ASCII_DEL)) { + int valid_char_pos = pos + 1; + + if (pos > 0) { + pos--; + /* update screen */ + if (write(STDOUT_FILENO, "\b \b",3) <= 0) { + fprintf(stderr, "write failed (errno = %d)\n", get_errno()); + } + } + + if (buffer[valid_char_pos] != 0x0 && (valid_char_pos < MAX_PACKET_SIZE)) { + memcpy(&buffer[pos], &buffer[valid_char_pos], (bufsize - valid_char_pos)); + } + } else { + if (buffer[pos] == ASCII_CR) { + buffer[pos] = ASCII_LF; + } + + /* echo */ + if (write(STDOUT_FILENO, &buffer[pos], 1) <= 0) { + fprintf(stderr, "failed to write (errno = %d)\n", get_errno()); + } + + if (buffer[pos] == ASCII_LF) { + pos++; + break; + } + + pos++; + if (pos >= MAX_PACKET_SIZE) { + fprintf(stderr, "out of range : command is too long, maximum length %d\n", MAX_PACKET_SIZE); + memset(buf, 0x0, MAX_PACKET_SIZE); + return 0; + } + } + } + } while(buffer[pos - 1] != ASCII_LF); + + memcpy(buf, buffer, pos); + + return pos; +} + static void prv_close_sock(void) { connection_t *connPtr = NULL; diff --git a/external/wakaama/examples/client/lwm2mclient.h b/external/wakaama/examples/client/lwm2mclient.h index c1cc7ae..d992d25 100644 --- a/external/wakaama/examples/client/lwm2mclient.h +++ b/external/wakaama/examples/client/lwm2mclient.h @@ -30,6 +30,15 @@ #include "liblwm2m.h" +/* + * struct lwm2mclient_input can be used for + * pthread arguments called by lwm2m_client_run API + */ +struct lwm2mclient_input { + int argc; + char **argv; +}; + extern int g_reboot; /* @@ -99,7 +108,7 @@ void handle_value_changed(lwm2m_context_t* lwm2mH, lwm2m_uri_t* uri, const char * TINYARA * DM (Device Management) Frameworks APIs */ -pthread_addr_t lwm2m_client_run(void); +pthread_addr_t lwm2m_client_run(void *arg); char *client_set_serverAddr(FAR const char *serverAddr, bool isbootstrap); char *client_get_serverAddr(void); diff --git a/external/wakaama/examples/shared/connection.c b/external/wakaama/examples/shared/connection.c index 45e2d33..a90ec8f 100644 --- a/external/wakaama/examples/shared/connection.c +++ b/external/wakaama/examples/shared/connection.c @@ -126,6 +126,9 @@ connection_t * connection_create(connection_t * connList, if (s >= 0) { sa = p->ai_addr; +#ifdef CONFIG_NET_LWIP + sa = p->ai_addrlen; +#endif sl = p->ai_addrlen; if (-1 == connect(s, p->ai_addr, p->ai_addrlen)) {