Commit 4d2533ae authored by Abhishek Pandey's avatar Abhishek Pandey Committed by Uze Choi

TizenRT: Porting of st_app onto TizenRT

Adding Tizen RT Port for st_app and fixed few errors.

1. Tizen RT don't support scanf. Using __TIZENRT__ define to avoid
compiling any scanf and menu input related code handling.

2. Used Tizen RT Network APIs for Soft AP Creation and Target AP Wi-Fi
Connection.

3. Updated build configurations accordingly.

4. Added IP Adapter Port functions for session event handling.

5. Sample app changes with static to avoid redefinition error across
separate samples.

6. File mode changes: Few files had file mode = 755. Changed it to 644
for these files.

Change-Id: Iaba4b71952df873c04b56a88fc51af7c4b50f2d5
Signed-off-by: default avatarAbhishek Pandey <abhi.siso@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/25319Tested-by: default avatarIoTivity Jenkins <jenkins-daemon@iotivity.org>
Reviewed-by: default avatarUze Choi <uzchoi@samsung.com>
parent fc339a0f
File mode changed from 100755 to 100644
......@@ -188,6 +188,7 @@ get_cloud_access_status(int device_index)
int
st_cloud_access_check_connection(const char *ci_server)
{
st_print_log("[st_cloud_access_check_connection] ci_server %s\n", ci_server);
oc_string_t dns_str;
oc_new_string(&dns_str, CONNECTION_CHECK_SERVER,
strlen(CONNECTION_CHECK_SERVER));
......@@ -195,20 +196,27 @@ st_cloud_access_check_connection(const char *ci_server)
oc_endpoint_t ep;
if (oc_string_to_endpoint(&dns_str, &ep, NULL) != 0) {
oc_free_string(&dns_str);
st_print_log("error in getting conn server endpoint!\n");
return -1;
}
oc_free_string(&dns_str);
st_print_log("oc_string_to_endpoint for conn check server completed\n");
if (ci_server) {
oc_new_string(&dns_str, ci_server, strlen(ci_server));
if (oc_string_to_endpoint(&dns_str, &ep, NULL) != 0) {
oc_free_string(&dns_str);
st_print_log("error in getting ci server endpoint!\n");
return -1;
}
oc_free_string(&dns_str);
st_print_log("oc_string_to_endpoint for ci server completed\n");
}
st_print_log("[st_cloud_access_check_connection] out\n");
return 0;
}
......@@ -261,8 +269,10 @@ sign_up_process(st_cloud_context_t *context)
goto retry;
}
} else {
st_print_log("sign_up_process: oc_sign_up failed!\n");
return false;
}
st_print_log("sign_up_process: success\n");
return true;
retry:
......@@ -270,6 +280,7 @@ retry:
oc_set_delayed_callback(context, re_sign_up, RETRY_INTERVAL);
_oc_signal_event_loop();
}
st_print_log("sign_up_process: attempting retry\n");
return true;
}
......
......@@ -310,7 +310,11 @@ int
st_manager_initialize(void)
{
#ifdef OC_SECURITY
#ifdef __TIZENRT__
oc_storage_config("/mnt/st_things_creds");
#else
oc_storage_config("./st_things_creds");
#endif
#endif /* OC_SECURITY */
if (st_process_init() != 0) {
......
/****************************************************************************
*
* Copyright 2018 Samsung Electronics All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
#include "st_manager.h"
#include "st_port.h"
// TODO: resource handling callbacks.
int
stapp_main(void)
{
if (st_manager_initialize() != 0) {
st_print_log("[ST_APP] st_manager_initialize failed.\n");
return -1;
}
// TODO: callback registration.
if (st_manager_start() != 0) {
st_print_log("[ST_APP] st_manager_start failed.\n");
}
st_manager_stop();
st_manager_deinitialize();
return 0;
}
###########################################################################
#
# Copyright 2017 Samsung Electronics All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
#
###########################################################################
ifeq ($(CONFIG_EXAMPLES_STAPP),y)
CONFIGURED_APPS += iotlite_apps/st_app
endif
###########################################################################
#
# Copyright 2016 Samsung Electronics All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
#
###########################################################################
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Hello, World! built-in application info
APPNAME = stapp
FUNCNAME = $(APPNAME)_main
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 8192
THREADEXEC = TASH_EXECMD_ASYNC
# Hello, World! Example
IOTCON_BASE_DIR = $(APPDIR)/../external/iotivity-constrained/iotivity-constrained
CFLAGS += -I$(IOTCON_BASE_DIR)/
CFLAGS += -I$(IOTCON_BASE_DIR)/include
CFLAGS += -I$(IOTCON_BASE_DIR)/port/tizenrt
CFLAGS += -I$(IOTCON_BASE_DIR)/port/
CFLAGS += -I$(IOTCON_BASE_DIR)/security
CFLAGS += -I$(IOTCON_BASE_DIR)/service/easy-setup/enrollee
CFLAGS += -I$(IOTCON_BASE_DIR)/service/easy-setup/enrollee/include
CFLAGS += -I$(IOTCON_BASE_DIR)/service/easy-setup/enrollee/include/samsung
CFLAGS += -I$(IOTCON_BASE_DIR)/service/cloud-access/include
CFLAGS += -I$(IOTCON_BASE_DIR)/service/resource-directory/client/include
CFLAGS += -D__TIZENRT__ -DOC_SECURITY -DOC_CLIENT -DOC_IPV4 -DOC_DEBUG -DOC_SERVER -DOC_DYNAMIC_ALLOCATION -DOC_PROCESS_CONF_NO_OC_PROCESS_NAMES=0 -DOC_PROCESS_CONF_STATS=0 -std=gnu99
ASRCS =
CSRCS =
MAINSRC = st_ref_app_tizenrt.c st_manager.c st_easy_setup.c st_cloud_access.c st_store.c st_resource_manager.c tizenrt/st_port.c tizenrt/st_process.c tizenrt/wifi_soft_ap_util.c
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
MAINOBJ = $(MAINSRC:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS) $(MAINSRC)
OBJS = $(AOBJS) $(COBJS)
ifneq ($(CONFIG_BUILD_KERNEL),y)
OBJS += $(MAINOBJ)
endif
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
BIN = ..\..\libapps$(LIBEXT)
else
ifeq ($(WINTOOL),y)
BIN = ..\\..\\libapps$(LIBEXT)
else
BIN = ../../libapps$(LIBEXT)
endif
endif
ifeq ($(WINTOOL),y)
INSTALL_DIR = "${shell cygpath -w $(BIN_DIR)}"
else
INSTALL_DIR = $(BIN_DIR)
endif
CONFIG_EXAMPLES_STAPP_PROGNAME ?= iotlite$(EXEEXT)
PROGNAME = $(CONFIG_EXAMPLES_STAPP_PROGNAME)
ROOTDEPPATH = --dep-path .
# Common build
VPATH =
all: .built
.PHONY: clean depend distclean
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS) $(MAINOBJ): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
$(call ARCHIVE, $(BIN), $(OBJS))
@touch .built
ifeq ($(CONFIG_BUILD_KERNEL),y)
$(BIN_DIR)$(DELIM)$(PROGNAME): $(OBJS) $(MAINOBJ)
@echo "LD: $(PROGNAME)"
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(PROGNAME) $(ARCHCRT0OBJ) $(MAINOBJ) $(LDLIBS)
$(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(PROGNAME)
install: $(BIN_DIR)$(DELIM)$(PROGNAME)
else
install:
endif
ifeq ($(CONFIG_BUILTIN_APPS)$(CONFIG_EXAMPLES_STAPP),yy)
$(BUILTIN_REGISTRY)$(DELIM)$(FUNCNAME).bdat: $(DEPCONFIG) Makefile
$(Q) $(call REGISTER,$(APPNAME),$(FUNCNAME),$(THREADEXEC),$(PRIORITY),$(STACKSIZE))
context: $(BUILTIN_REGISTRY)$(DELIM)$(FUNCNAME).bdat
else
context:
endif
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
$(call DELFILE, .built)
$(call CLEAN)
distclean: clean
$(call DELFILE, Make.dep)
$(call DELFILE, .depend)
-include Make.dep
.PHONY: preconfig
preconfig:
/****************************************************************************
*
* Copyright 2018 Samsung Electronics All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
#include "../st_port.h"
#include "../st_process.h"
#include "port/oc_assert.h"
#include "port/oc_clock.h"
#include "port/oc_connectivity.h"
#include "util/oc_memb.h"
#include "wifi_soft_ap_util.h"
#include <pthread.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <unistd.h>
#define SYSTEM_RET_CHECK(ret) \
do { \
if (system_ret_chcek(ret) != 0) { \
goto exit; \
} \
} while (0);
typedef struct
{
st_thread_t thread;
st_mutex_t mutex;
st_cond_t cv;
int is_soft_ap_on;
oc_string_t ssid;
oc_string_t pwd;
int channel;
} st_soft_ap_t;
static st_soft_ap_t g_soft_ap;
OC_MEMB(st_mutex_s, pthread_mutex_t, 10);
OC_MEMB(st_cond_s, pthread_cond_t, 10);
OC_MEMB(st_thread_s, pthread_t, 10);
static void *soft_ap_process_routine(void *data);
int
st_port_specific_init(void)
{
/* set port specific logics. in here */
return 0;
}
void
st_port_specific_destroy(void)
{
/* set initialized port specific logics destroyer. in here */
return;
}
st_loop_status_t
st_port_main_loop(int *quit_flag)
{
st_loop_status_t status;
while (*quit_flag != 1) {
st_sleep(3);
}
status = ST_LOOP_QUIT;
return status;
}
void
st_print_log(const char *fmt, ...)
{
va_list arg;
va_start(arg, fmt);
vprintf(fmt, arg);
va_end(arg);
}
st_mutex_t
st_mutex_init(void)
{
st_mutex_t mutex = (st_mutex_t)oc_memb_alloc(&st_mutex_s);
if (!mutex)
oc_abort("alloc failed");
pthread_mutex_init((pthread_mutex_t *)mutex, NULL);
return mutex;
}
int
st_mutex_destroy(st_mutex_t mutex)
{
if (!mutex)
return -1;
pthread_mutex_destroy((pthread_mutex_t *)mutex);
oc_memb_free(&st_mutex_s, mutex);
return 0;
}
int
st_mutex_lock(st_mutex_t mutex)
{
if (!mutex)
return -1;
pthread_mutex_lock((pthread_mutex_t *)mutex);
return 0;
}
int
st_mutex_unlock(st_mutex_t mutex)
{
if (!mutex)
return -1;
pthread_mutex_unlock((pthread_mutex_t *)mutex);
return 0;
}
st_cond_t
st_cond_init(void)
{
st_cond_t cv = (st_cond_t)oc_memb_alloc(&st_cond_s);
if (!cv)
oc_abort("alloc failed");
pthread_cond_init((pthread_cond_t *)cv, NULL);
return cv;
}
int
st_cond_destroy(st_cond_t cv)
{
if (!cv)
return -1;
pthread_cond_destroy((pthread_cond_t *)cv);
oc_memb_free(&st_cond_s, cv);
return 0;
}
int
st_cond_wait(st_cond_t cv, st_mutex_t mutex)
{
if (!cv || !mutex)
return -1;
return pthread_cond_wait((pthread_cond_t *)cv, (pthread_mutex_t *)mutex);
}
int
st_cond_timedwait(st_cond_t cv, st_mutex_t mutex, oc_clock_time_t time)
{
if (!cv || !mutex)
return -1;
struct timespec ts;
ts.tv_sec = (time / OC_CLOCK_SECOND);
ts.tv_nsec = (time % OC_CLOCK_SECOND) * 1.e09 / OC_CLOCK_SECOND;
return pthread_cond_timedwait((pthread_cond_t *)cv, (pthread_mutex_t *)mutex,
&ts);
}
int
st_cond_signal(st_cond_t cv)
{
if (!cv)
return -1;
return pthread_cond_signal((pthread_cond_t *)cv);
}
#if 0
int
st_set_sigint_handler(st_sig_handler_t handler)
{
struct sigaction sa;
sigfillset(&sa.sa_mask);
sa.sa_flags = 0;
sa.sa_handler = handler;
return sigaction(SIGINT, &sa, NULL);
}
#endif
st_thread_t
st_thread_create(st_thread_process_t handler, const char *name, void *user_data)
{
if (!handler)
return NULL;
st_thread_t thread = (st_thread_t)oc_memb_alloc(&st_thread_s);
if (!thread)
oc_abort("alloc failed");
pthread_create((pthread_t *)thread, NULL, handler, user_data);
pthread_setname_np(*(pthread_t *)thread, name);
return thread;
}
int
st_thread_destroy(st_thread_t thread)
{
if (!thread)
return -1;
pthread_join(*(pthread_t *)(thread), NULL);
oc_memb_free(&st_thread_s, thread);
return 0;
}
int
st_thread_cancel(st_thread_t thread)
{
if (!thread)
return -1;
return pthread_cancel(*(pthread_t *)thread);
}
void
st_thread_exit(void *retval)
{
pthread_exit(retval);
}
void
st_sleep(int seconds)
{
sleep(seconds);
}
void
st_turn_on_soft_AP(const char *ssid, const char *pwd, int channel)
{
if (g_soft_ap.is_soft_ap_on) {
st_print_log("[St_Port] Soft AP is already turned on\n");
return;
}
st_print_log("[St_Port] st_turn_on_soft_AP\n");
if (oc_string(g_soft_ap.ssid)) {
oc_free_string(&g_soft_ap.ssid);
}
if (oc_string(g_soft_ap.pwd)) {
oc_free_string(&g_soft_ap.pwd);
}
oc_new_string(&g_soft_ap.ssid, ssid, strlen(ssid));
oc_new_string(&g_soft_ap.pwd, pwd, strlen(pwd));
g_soft_ap.channel = channel;
g_soft_ap.mutex = st_mutex_init();
g_soft_ap.cv = st_cond_init();
g_soft_ap.is_soft_ap_on = 1;
g_soft_ap.thread =
st_thread_create(soft_ap_process_routine, "SOFT_AP", &g_soft_ap);
st_mutex_lock(g_soft_ap.mutex);
st_cond_wait(g_soft_ap.cv, g_soft_ap.mutex);
st_mutex_unlock(g_soft_ap.mutex);
st_print_log("[St_Port] st_turn_on_soft_AP success\n");
}
static int
system_ret_chcek(int ret)
{
if (ret == -1 || ret == 127) {
st_print_log("[St_Port] system() invoke error(%d).\n", ret);
return -1;
}
return 0;
}
void
st_turn_off_soft_AP(void)
{
if (!g_soft_ap.is_soft_ap_on) {
st_print_log("[St_Port] soft AP is already turned off\n");
}
st_print_log("[St_Port] st_turn_off_soft_AP\n");
st_mutex_lock(g_soft_ap.mutex);
if (g_soft_ap.is_soft_ap_on) {
// Platform specific funtion for stopping Soft AP
es_stop_softap();
st_thread_cancel(g_soft_ap.thread);
g_soft_ap.is_soft_ap_on = 0;
}
st_print_log("[St_Port] st_turn_off_soft_AP success.\n");
exit:
st_thread_destroy(g_soft_ap.thread);
if (oc_string(g_soft_ap.ssid)) {
oc_free_string(&g_soft_ap.ssid);
}
if (oc_string(g_soft_ap.pwd)) {
oc_free_string(&g_soft_ap.pwd);
}
st_mutex_unlock(g_soft_ap.mutex);
st_cond_destroy(g_soft_ap.cv);
st_mutex_destroy(g_soft_ap.mutex);
g_soft_ap.thread = NULL;
g_soft_ap.mutex = NULL;
g_soft_ap.cv = NULL;
}
void
st_connect_wifi(const char *ssid, const char *pwd)
{
st_print_log("[St_Port] st_connect_wifi in\n");
st_sleep(5);
//TODO: auth and enc type should be passed from Wi-Fi Prob Cb
char auth_type[20] = "wpa2_psk";
//char enc_type[20] = "aes";
if (wifi_start_station() < 0) {
st_print_log("start station error! \n");
return;
}
int retry;
for (retry = 0; retry < 5; ++retry) {
if (0 == wifi_join(ssid, auth_type, pwd)) {
st_print_log("wifi_join success\n");
break;
} else {
st_print_log("wifi_join failed\n");
}
}
st_print_log("AP join done\n");
for (retry = 0; retry < 5; ++retry) {
if (0 == dhcpc_start()) {
st_print_log("dhcpc_start success\n");
break;
} else {