Commit d5608cd3 authored by Sandipan Patra's avatar Sandipan Patra Committed by Madan Lanka

[TIZEN] Tizen console application support for enrollee

and SoftAp stubs API added for Tizen enrollee.

Change-Id: I7b524017e62cd82c8aa9db94279c0f2f7175272d
Signed-off-by: default avatarSandipan Patra <sandipan.p@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4887Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarMadan Lanka <lanka.madan@samsung.com>
parent 825d8c4d
......@@ -44,7 +44,8 @@ cp ./SConstruct ./tmp
# copy dependency RPMs and conf files for tizen build
cp ./tools/tizen/*.rpm ./tmp
cp ./tools/tizen/.gbs.conf ./tmp
cp ./tools/tizen/*.rpm $sourcedir/tmp/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample
cp ./tools/tizen/.gbs.conf ./tmp/service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample
cp -R $sourcedir/iotivity.pc.in $sourcedir/tmp
cd $sourcedir/tmp
......@@ -71,6 +72,28 @@ else
exit 1
fi
cd service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample
echo `pwd`
if [ ! -d .git ]; then
git init ./
git config user.email "you@example.com"
git config user.name "Your Name"
git add ./
git commit -m "Initial commit"
fi
echo "Calling sample gbs build command"
gbscommand="gbs build -A armv7l -B ~/GBS-ROOT --include-all --repository ./ --define 'TARGET_TRANSPORT IP' --define 'SECURED 0' --define 'RELEASE 0' --define 'LOGGING True' --define 'ROUTING EP' --define 'TARGET_ENROLLEE tizen
'"
echo $gbscommand
if eval $gbscommand; then
echo "Sample build is successful"
else
echo "Sample build is failed. "
exit 1
fi
cd $sourcedir
rm -rf $sourcedir/tmp
......
......@@ -49,7 +49,6 @@ if target_os not in ['arduino','darwin']:
SConscript('resource-directory/SConscript')
# Build EasySetup module
if target_os in ['arduino','android', 'linux']:
if target_os in ['arduino', 'android', 'linux','tizen']:
SConscript('easy-setup/SConscript')
......@@ -141,6 +141,7 @@ if target_os == 'tizen':
if target_os == 'arduino':
es_sdk_static = easy_setup_env.StaticLibrary('ESSDKLibrary',
['sdk/enrollee/src/easysetup.cpp',
'sdk/enrollee/src/onboarding.cpp',
'sdk/enrollee/src/resourceHandler.cpp',
'sdk/enrollee/arduino/wifi/networkHandler.cpp'])
easy_setup_env.InstallTarget(es_sdk_static, 'libESSDK')
......@@ -153,11 +154,14 @@ if target_os == 'android':
easy_setup_env.InstallTarget(es_sdk_shared, 'libESSDK')
if target_os == 'tizen':
es_sdk_shared = easy_setup_env.SharedLibrary('ESSDKLibrary',
['sdk/enrollee/src/easysetup.cpp',
'sdk/enrollee/src/resourceHandler.cpp',
'sdk/enrollee/tizen/wifi/networkHandler.cpp'])
easy_setup_env.InstallTarget(es_sdk_shared, 'libESSDK')
es_sdk_shared = easy_setup_env.SharedLibrary('ESSDKLibrary',
['sdk/enrollee/src/easysetup.cpp',
'sdk/enrollee/src/onboarding.cpp',
'sdk/enrollee/src/softap.cpp',
'sdk/enrollee/src/resourceHandler.cpp',
'sdk/enrollee/tizen/wifi/networkHandler.cpp',
'sdk/enrollee/tizen/wifi/softapnative.cpp'])
easy_setup_env.InstallTarget(es_sdk_shared, 'libESSDK')
print"easysetup_path %s" % easysetup_path
......
......@@ -38,7 +38,7 @@ target_os = env.get('TARGET_OS')
# Source files and Targets
######################################################################
if target_os == 'arduino' :
# Build linux sample app
# Build arduino sample app
SConscript('enrollee/arduino/SConscript')
if target_os == 'linux' :
......
##########################################################################
#
# Copyright 2015 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.
#
##########################################################################
##
# This script includes generic build options:
# release/debug, target os, target arch, cross toolchain, build environment etc
##
import os
import platform
print "Inside the Config SConscript"
# Map of host os and allowed target os (host: allowed target os)
host_target_map = {
'linux': ['linux', 'android', 'arduino', 'yocto', 'tizen'],
'windows': ['windows', 'winrt', 'android', 'arduino', 'tizen'],
'darwin': ['darwin', 'ios', 'android', 'arduino'],
}
# Map of os and allowed archs (os: allowed archs)
os_arch_map = {
'linux': ['x86', 'x86_64', 'arm', 'arm64'],
'android': ['x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'armeabi-v7a-hard', 'arm64-v8a'],
'windows': ['x86', 'amd64', 'arm'],
'winrt': ['arm'],
'darwin': ['i386', 'x86_64'],
'ios': ['i386', 'x86_64', 'armv7', 'armv7s', 'arm64'],
'arduino': ['avr', 'arm'],
'yocto': ['x86', 'x86_64'],
'tizen': ['armv7'],
}
host = platform.system().lower()
if not host_target_map.has_key(host):
print "\nError: Current system (%s) isn't supported\n" % host
Exit(1)
######################################################################
# Get build options (the optins from command line)
######################################################################
target_os = ARGUMENTS.get('TARGET_OS', host).lower() # target os
if target_os not in host_target_map[host]:
print "\nError: Unknown target os: %s (Allow values: %s)\n" % (target_os, host_target_map[host])
Exit(1)
default_arch = platform.machine()
if default_arch not in os_arch_map[target_os]:
default_arch = os_arch_map[target_os][0].lower()
target_arch = ARGUMENTS.get('TARGET_ARCH', default_arch) # target arch
######################################################################
# Common build options (release, target os, target arch)
######################################################################
help_vars = Variables()
help_vars.Add(BoolVariable('RELEASE', 'Build for release?', True)) # set to 'no', 'false' or 0 for debug
help_vars.Add(EnumVariable('TARGET_OS', 'Target platform', host, host_target_map[host]))
help_vars.Add(ListVariable('TARGET_TRANSPORT', 'Target transport', 'ALL', ['ALL', 'IP', 'BT', 'BLE']))
help_vars.Add(EnumVariable('TARGET_ARCH', 'Target architecture', default_arch, os_arch_map[target_os]))
help_vars.Add(EnumVariable('SECURED', 'Build with DTLS', '0', allowed_values=('0', '1')))
help_vars.Add(EnumVariable('ROUTING', 'Enable routing', 'EP', allowed_values=('GW', 'EP')))
######################################################################
# Platform(build target) specific options: SDK/NDK & toolchain
######################################################################
targets_support_cc = ['tizen']
if target_os in targets_support_cc:
# Set cross compile toolchain
help_vars.Add('TC_PREFIX', "Toolchain prefix (Generally only be required for cross-compiling)", os.environ.get('TC_PREFIX'))
help_vars.Add(PathVariable('TC_PATH',
'Toolchain path (Generally only be required for cross-compiling)',
os.environ.get('TC_PATH')))
if target_os in ['android', 'arduino']: # Android/Arduino always uses GNU compiler regardless of the host
env = Environment(variables = help_vars,
tools = ['gnulink', 'gcc', 'g++', 'ar', 'as']
)
else:
env = Environment(variables = help_vars, TARGET_ARCH = target_arch, TARGET_OS = target_os)
Help(help_vars.GenerateHelpText(env))
tc_set_msg = '''
************************************ Warning **********************************
* Enviornment variable TC_PREFIX/TC_PATH is set. It will change the default *
* toolchain, if it isn't what you expect you should unset it, otherwise it may*
* cause inexplicable errors. *
*******************************************************************************
'''
if target_os in targets_support_cc:
prefix = env.get('TC_PREFIX')
tc_path = env.get('TC_PATH')
if prefix:
env.Replace(CC = prefix + 'gcc')
env.Replace(CXX = prefix + 'g++')
env.Replace(AR = prefix + 'ar')
env.Replace(AS = prefix + 'as')
env.Replace(LINK = prefix + 'ld')
env.Replace(RANLIB = prefix + 'ranlib')
if tc_path:
env.PrependENVPath('PATH', tc_path)
sys_root = os.path.abspath(tc_path + '/../')
env.AppendUnique(CCFLAGS = ['--sysroot=' + sys_root])
env.AppendUnique(LINKFLAGS = ['--sysroot=' + sys_root])
if prefix or tc_path:
print tc_set_msg
# Ensure scons be able to change its working directory
env.SConscriptChdir(1)
# Set the source directory and build directory
# Source directory: 'dir'
# Build directory: 'dir'/out/<target_os>/<target_arch>/<release or debug>/
#
# You can get the directory as following:
# env.get('SRC_DIR')
# env.get('BUILD_DIR')
def __set_dir(env, dir):
if not os.path.exists(dir + '/SConstruct'):
print '''
*************************************** Error *********************************
* The directory(%s) seems isn't a source code directory, no SConstruct file is
* found. *
*******************************************************************************
''' % dir
Exit(1)
if env.get('RELEASE'):
build_dir = dir + '/out/' + target_os + '/' + target_arch + '/release/'
else:
build_dir = dir + '/out/' + target_os + '/' + target_arch + '/debug/'
env.VariantDir(build_dir, dir, duplicate=0)
env.Replace(BUILD_DIR = build_dir)
env.Replace(SRC_DIR = dir)
def __src_to_obj(env, src, home = ''):
obj = env.get('BUILD_DIR') + src.replace(home, '')
if env.get('OBJSUFFIX'):
obj += env.get('OBJSUFFIX')
return env.Object(obj, src)
def __install(ienv, targets, name):
i_n = ienv.Install(env.get('BUILD_DIR'), targets)
Alias(name, i_n)
env.AppendUnique(TS = [name])
def __append_target(ienv, target):
env.AppendUnique(TS = [target])
def __print_targets(env):
Help('''
===============================================================================
Targets:\n ''')
for t in env.get('TS'):
Help(t + ' ')
Help('''
\nDefault all targets will be built. You can specify the target to build:
$ scons [options] [target]
===============================================================================
''')
env.AddMethod(__set_dir, 'SetDir')
env.AddMethod(__print_targets, 'PrintTargets')
env.AddMethod(__src_to_obj, 'SrcToObj')
env.AddMethod(__append_target, 'AppendTarget')
env.AddMethod(__install, 'InstallTarget')
env.SetDir(env.GetLaunchDir())
env['ROOT_DIR']=env.GetLaunchDir()
env.AppendUnique(CPPDEFINES = ['TB_LOG'])
if env.get('ROUTING') == 'GW':
env.AppendUnique(CPPDEFINES = ['ROUTING_GATEWAY'])
elif env.get('ROUTING') == 'EP':
env.AppendUnique(CPPDEFINES = ['ROUTING_EP'])
env.AppendUnique(CPPDEFINES = ['__TIZEN__'])
Export('env')
######################################################################
# continue with the regular build process. Load config of target os
######################################################################
env.SConscript(target_os + '/SConscript')
# Delete the temp files of configuration
if env.GetOption('clean'):
dir = env.get('SRC_DIR')
if os.path.exists(dir + '/config.log'):
Execute(Delete(dir + '/config.log'))
Execute(Delete(dir + '/.sconsign.dblite'))
Execute(Delete(dir + '/.sconf_temp'))
Return('env')
##
# The main build script
#
##
# Load common build config
# Load common build config
SConscript('SConscript')
Import('env')
target_os = env.get('TARGET_OS')
transport = env.get('TARGET_TRANSPORT')
print "Given Transport is %s" % transport
print "Given OS is %s" % target_os
print "Secured %s" % env.get('SECURED')
if target_os == 'tizen':
SConscript('scons/SConscript')
else:
print "Given platform is not supported"
<manifest>
<define>
<domain name="essample" />
<permit>
<smack permit="system::use_internet" type="rwx"/>
</permit>
<request>
<smack request="system::use_internet" type="rwx"/>
<smack request="bt-service" type="rwx"/>
<smack request="sap" type="rwx"/>
<smack request="bt-service::spp" type="rwx"/>
<smack request="bt-service::gap" type="rwx"/>
<smack request="bt-service::admin" type="rwx"/>
<smack request="bt-service::manager" type="rwx"/>
<smack request="bt-service::public" type="rwx"/>
<smack request="bt-service::platform" type="rwx"/>
</request>
</define>
<assign>
<filesystem path="/opt/apps/com.oic.es.sample/bin/sample" exec_label="sample" />
</assign>
<request>
<domain name="essample" />
</request>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns="http://tizen.org/ns/packages" package="com.oic.es.sample" version="0.1.12" install-location="internal-only">
<label>essample</label>
<author email="oic" href="www.iotivity.org">OIC</author>
<description>essample</description>
<ui-application appid="com.oic.es.sample" exec="/usr/apps/com.oic.es.sample/bin/sample" nodisplay="false" multiple="false" type="capp" taskmanage="true">
<icon>com.oic.es.sample.png</icon>
<label>essample</label>
<label xml:lang="en-us">essample</label>
<label xml:lang="nl-nl">essample</label>
</ui-application>
<privileges>
<privilege>http://tizen.org/privilege/socket</privilege>
</privileges>
</manifest>
//******************************************************************
//
// Copyright 2015 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 "easysetup.h"
#include <string.h>
#include <iostream>
#include <pthread.h>
#define TAG "TS"
using namespace std;
void *listeningFunc(void*);
/**
* @var ssid
* @brief Target SSID of the Soft Access point to which the device has to connect
*/
static char ssid[] = "EasySetup123";
/**
* @var passwd
* @brief Password of the Soft Access point to which the device has to connect
*/
static char passwd[] = "EasySetup123";
void PrintMenu()
{
cout<<"============"<<endl;
cout<<"S: start easy setup"<<endl;
cout<<"P: start provisioning resources"<<endl;
cout<<"T: terminate"<<endl;
cout<<"Q: quit"<<endl;
cout<<"============"<<endl;
}
void EventCallbackInApp(ESResult esResult, EnrolleeState enrolleeState)
{
cout<<"Easy setup event callback"<<endl;
if(esResult == ES_OK)
{
if(enrolleeState == ES_ON_BOARDED_STATE)
{
cout<<"Device is successfully OnBoared on Adhoc network"<<endl;
}
else if (enrolleeState == ES_PROVISIONED_STATE)
{
cout<<"Device is provisioned with target network's credentials"<<endl;
}
else if (enrolleeState == ES_ON_BOARDED_TARGET_NETWORK_STATE)
{
cout<<"Device is onboarded/connected with target network"<<endl;
}
else
{
cout<<"Wrong state !! Easy setup is failed at Enrollee state = "<<enrolleeState<<endl;
}
}
else
{
cout<<"Easy stup is failed at Enrollee state = "<<enrolleeState<<endl;
}
PrintMenu();
}
void StartEasySetup()
{
cout<<"StartEasySetup and onboarding started.."<<endl;
if(InitEasySetup(CT_ADAPTER_IP, ssid, passwd, EventCallbackInApp) == ES_ERROR)
{
cout<<"StartEasySetup and onboarding Fail!!"<<endl;
return;
}
pthread_t thread_handle;
if (pthread_create(&thread_handle, NULL, listeningFunc, NULL))
{
cout<<"Thread creation failed"<<endl;
}
}
void StartProvisioning()
{
cout<<"Starting Enrollee Provisioning"<<endl;
if(InitProvisioning()== ES_ERROR)
{
cout<<"Init Provisioning Failed"<<endl;
return;
}
cout<<"InitProvisioning:Success"<<endl;
}
void StopEasySetup()
{
cout<<"StopEasySetup IN"<<endl;
if(TerminateEasySetup()== ES_ERROR)
{
cout<<"return value is: ES_ERROR"<<endl;
return;
}
cout<<"StopEasySetup OUT"<<endl;
}
int main()
{
cout<<"#########################"<<endl;
cout<<"EasySetup Enrollee SAMPLE"<<endl;
cout<<"#########################"<<endl;
PrintMenu();
char option;
while(true)
{
cin>>option;
switch (option)
{
case 'H': // help
case 'h':
PrintMenu();
break;
case 'Q': // quit
case 'q':
cout<<"quit";
break;
case 'S': // start easy setup
case 's':
StartEasySetup();
break;
case 'P': // start provisioning
case 'p':
StartProvisioning();
break;
case 'T': // stop easy setup
case 't':
StopEasySetup();
break;
default:
cout<<"wrong option"<<endl;
break;
}
if(option=='Q') break;
}
return 0;
}
void *listeningFunc(void*)
{
OCStackResult result;
while (true)
{
result = OCProcess();
if (result != OC_STACK_OK)
{
cout<<"OCStack stop error";
}
}
return NULL;
}
%define PREFIX /usr/apps/com.oic.es.sample
%define ROOTDIR %{_builddir}/%{name}-%{version}
Name: com-oic-es-sample
Version: 0.1
Release: 1
Summary: Tizen adapter interfacesample application
URL: http://slp-source.sec.samsung.net
Source: %{name}-%{version}.tar.gz
License: Apache-2.0
Group: Applications/OICSample
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: boost-devel
BuildRequires: boost-thread
BuildRequires: boost-system
BuildRequires: boost-filesystem
BuildRequires: pkgconfig(capi-network-wifi)
BuildRequires: pkgconfig(capi-network-bluetooth)
BuildRequires: scons
BuildRequires: iotivity
BuildRequires: iotivity-devel
BuildRequires: iotivity-service
%description
EasySetup Sample application
%prep
%setup -q
%build