Commit 074d5ecd authored by Sakthivel Samidurai's avatar Sakthivel Samidurai Committed by Erich Keane

Rebase remote-access over master

Added the remote adapter code in connectivity/src/ra_adapter folder.
Adding plumbing throughout the stack for applications to do requests
over remote access.
Added a C sample app ocremoteaccessclient that makes all it's requests
ONLY through the RA adapter.

Change-Id: Ie1b250a0fad584e85631f66e3d2ec4f44607320d
Signed-off-by: default avatarMandeep Shetty <mandeep.shetty@intel.com>
Signed-off-by: default avatarSakthivel Samidurai <sakthivel.samidurai@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1639Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarErich Keane <erich.keane@intel.com>
parent 59ef2f1d
......@@ -16,11 +16,17 @@ function build()
{
if [ $(uname -s) = "Linux" ]
then
echo "*********** Build for linux *************"
echo "*********** Build for linux ************"
scons RELEASE=$3
echo "*********** Build for linux with Security*************"
echo "*********** Build for linux with Security *************"
scons RELEASE=$3 SECURED=1
echo "*********** Build for linux With Remote Access *************"
scons RELEASE=$3 WITH_RA=1
echo "*********** Build for linux With Remote Access & Security ************"
scons RELEASE=$3 WITH_RA=1 SECURED=1
fi
# Note: for android, as oic-resource uses C++11 feature stoi and to_string,
......
......@@ -77,10 +77,13 @@ help_vars.Add(BoolVariable('VERBOSE', 'Show compilation', False))
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(BoolVariable('WITH_RA', 'Build with Remote Access module', False))
if target_os in targets_disallow_multitransport:
help_vars.Add(ListVariable('TARGET_TRANSPORT', 'Target transport', 'IP', ['BT', 'BLE', 'IP']))
help_vars.Add(ListVariable('TARGET_TRANSPORT', 'Target transport', 'IP', ['BT', 'BLE', 'IP']))
else:
help_vars.Add(ListVariable('TARGET_TRANSPORT', 'Target transport', 'ALL', ['ALL', 'BT', 'BLE', 'IP']))
help_vars.Add(ListVariable('TARGET_TRANSPORT', 'Target transport', 'ALL', ['ALL', 'BT', 'BLE', 'IP']))
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')))
......
......@@ -124,6 +124,11 @@ SConscript('tools/UnpackAll.py')
# tinycbor build/fetch
SConscript(os.path.join(env.get('SRC_DIR'), 'extlibs', 'tinycbor', 'SConscript'))
with_ra = env.get('WITH_RA')
if with_ra:
SConscript(os.path.join(env.get('SRC_DIR'), 'extlibs', 'raxmpp', 'SConscript'))
env.AddMethod(__prepare_lib, "PrepareLib")
env.AddMethod(__configure, "Configure")
env.AddMethod(__download, "Download")
......
#******************************************************************
#
# Copyright 2015 Intel Mobile Communications GmbH 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.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
######################################################################
# raxmpp library build script
#
######################################################################
import os
import commands
Import('env')
src_dir = env.get('SRC_DIR')
target_os = env.get('TARGET_OS')
target_arch = env.get('TARGET_ARCH')
with_ra = env.get('WITH_RA')
if with_ra:
# check 'raxmppl' library, if it doesn't exits, ask user to download it
if not os.path.exists('raxmpp'):
print '''
*********************************** Error: ***********************************************
* Please download ra_xmpp as following :
* $ git clone https://gerrit.iotivity.org/gerrit/iotivity-xmpp extlibs/raxmpp/raxmpp
******************************************************************************************
'''
Exit(1)
print 'building with ra_xmpp'
if env.get('RELEASE'):
print src_dir
build_dir = os.path.join(src_dir, 'extlibs/raxmpp/raxmpp/out', target_os, target_arch, 'release/')
else:
build_dir = os.path.join(src_dir, 'extlibs/raxmpp/raxmpp/out/', target_os, target_arch, 'debug/')
os.chdir('raxmpp')
sconsflags = ' RELEASE=true' if env['RELEASE'] else ' RELEASE=false'
foo=commands.getoutput('scons external' + sconsflags )
print foo
foo=commands.getoutput('scons' + sconsflags )
print foo
env.AppendUnique(CPPPATH = src_dir+'/extlibs/raxmpp/raxmpp/ra_xmpp/',
LIBPATH=build_dir,
RPATH = build_dir)
......@@ -30,3 +30,4 @@ Import('env')
target_os = env.get('TARGET_OS')
target_arch = env.get('TARGET_ARCH')
src_dir = env.get('SRC_DIR')
......@@ -29,6 +29,7 @@ SConscript(env.get('SRC_DIR') + '/resource/third_party_libs.scons', 'lib_env')
liboctbstack_env = lib_env.Clone()
target_os = env.get('TARGET_OS')
with_ra = env.get('WITH_RA')
# As in the source code, it includes arduino Time library (C++)
# It requires compile the .c with g++
if target_os == 'arduino':
......@@ -65,8 +66,10 @@ if target_os not in ['windows', 'winrt']:
liboctbstack_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
if target_os in ['android', 'linux', 'tizen']:
if target_os in ['android', 'linux','tizen']:
liboctbstack_env.AppendUnique(LIBS = ['connectivity_abstraction'])
if with_ra:
liboctbstack_env.AppendUnique(LIBS = ['ra_xmpp'])
liboctbstack_env.AppendUnique(LIBS = ['coap', 'm'])
if target_os == 'tizen':
......
......@@ -7,6 +7,7 @@ Import('env')
target_os = env.get('TARGET_OS')
transport = env.get('TARGET_TRANSPORT')
build_sample = env.get('BUILD_SAMPLE')
with_ra = env.get('WITH_RA')
print "Given Transport is %s" % transport
print "Given OS is %s" % target_os
......@@ -21,6 +22,8 @@ if target_os in targets_disallow_multitransport:
Exit(1)
if 'ALL' in transport:
if with_ra == True:
env.AppendUnique(CPPDEFINES = ['RA_ADAPTER'])
if target_os == 'linux':
env.AppendUnique(CPPDEFINES = ['IP_ADAPTER','NO_EDR_ADAPTER','NO_LE_ADAPTER'])
elif target_os == 'tizen':
......@@ -60,6 +63,9 @@ else:
env.SConscript('./src/SConscript')
if build_sample == 'ON':
if target_os in ['linux', 'arduino', 'android']:
env.SConscript('./samples/' + target_os + '/SConscript')
if target_os in ['linux', 'arduino', 'android', 'darwin']:
target_path = target_os
if target_os == 'darwin':
target_path = 'linux'
env.SConscript('./samples/' + target_path + '/SConscript')
......@@ -41,6 +41,11 @@ extern "C"
*/
#define CA_IPADDR_SIZE 16
/**
* @brief Remote Access jabber ID length.
*/
#define CA_RAJABBERID_SIZE 256
/**
* @brief Mac address length for BT port
*/
......@@ -113,16 +118,24 @@ typedef char *CAToken_t;
// The following flags are the same as the equivalent OIC values in
// octypes.h, allowing direct copying with slight fixup.
// The CA layer should used the OC types when build allows that.
#ifdef RA_ADAPTER
#define MAX_ADDR_STR_SIZE_CA (256)
#else
#define MAX_ADDR_STR_SIZE_CA (40)
#endif
typedef enum
{
CA_DEFAULT_ADAPTER = 0,
// value zero indicates discovery
CA_ADAPTER_IP = (1 << 0), // IPv4 and IPv6, including 6LoWPAN
CA_ADAPTER_GATT_BTLE = (1 << 1), // GATT over Bluetooth LE
CA_ADAPTER_RFCOMM_BTEDR = (1 << 2), // RFCOMM over Bluetooth EDR
CA_ADAPTER_IP = (1 << 0), // IPv4 and IPv6, including 6LoWPAN
CA_ADAPTER_GATT_BTLE = (1 << 1), // GATT over Bluetooth LE
CA_ADAPTER_RFCOMM_BTEDR = (1 << 2), // RFCOMM over Bluetooth EDR
#ifdef RA_ADAPTER
CA_ADAPTER_REMOTE_ACCESS = (1 << 3) // Remote Access over XMPP.
#endif
} CATransportAdapter_t;
typedef enum
......@@ -348,6 +361,22 @@ typedef struct
helpful to identify the error */
} CAErrorInfo_t;
/**
* @brief CA Remote Access information for XMPP Client
*
*/
typedef struct
{
char *hostname; /**< XMPP server hostname */
uint16_t port; /**< XMPP server serivce port */
char *xmpp_domain; /**< XMPP login domain */
char *username; /**< login username */
char *password; /**< login password */
char *resource; /**< specific resource for login */
char *user_jid; /**< specific JID for login */
} CARAInfo_t;
/**
* @brief Hold global variables for CA layer (also used by RI layer)
*/
......
......@@ -245,6 +245,16 @@ CAResult_t CAGetNetworkInformation(CAEndpoint_t **info, uint32_t *size);
*/
CAResult_t CAHandleRequestResponse();
#ifdef RA_ADAPTER
/**
* @brief Set Remote Access information for XMPP Client.
* @param caraInfo [IN] remote access info.
*
* @return #CA_STATUS_OK
*/
CAResult_t CASetRAInfo(const CARAInfo_t *caraInfo);
#endif
#ifdef __WITH_DTLS__
......
......@@ -88,6 +88,16 @@ CAResult_t CAStartAdapter(CATransportAdapter_t transportType);
*/
void CAStopAdapter(CATransportAdapter_t transportType);
#ifdef RA_ADAPTER
/**
* @brief Set Remote Access information for XMPP Client.
* @param caraInfo [IN] remote access info.
*
* @return CA_STATUS_OK
*/
CAResult_t CASetAdapterRAInfo(const CARAInfo_t *caraInfo);
#endif
/**
* @brief Get network information such as ipaddress and mac information
* @param info [OUT] connectivity information such as ipaddress and mac information
......
/******************************************************************
//
// Copyright 2015 Intel Mobile Communications GmbH 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.
//
******************************************************************/
/**
* @file caraadapter.h
* @brief This file contains the APIs for IP Adapter.
*/
#ifndef CA_RA_ADAPTER_H_
#define CA_RA_ADAPTER_H_
#include "cacommon.h"
#include "caadapterinterface.h"
#include "cathreadpool.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
* @brief API to initialize RA Interface.
* @param registerCallback [IN] Callback to register RA interfaces to Connectivity
* Abstraction Layer
* @param networkPacketCallback [IN] Callback to notify request and response messages from server(s)
* started at Connectivity Abstraction Layer.
* @param netCallback [IN] Callback to notify the network additions to Connectivity
* Abstraction Layer.
* @param handle [IN] Threadpool Handle
* @return #CA_STATUS_OK or Appropriate error code
*/
CAResult_t CAInitializeRA(CARegisterConnectivityCallback registerCallback,
CANetworkPacketReceivedCallback networkPacketCallback,
CANetworkChangeCallback netCallback,
ca_thread_pool_t handle);
/**
* @brief Start RA Interface adapter.
* @return #CA_STATUS_OK or Appropriate error code
*/
CAResult_t CAStartRA();
/**
* @brief Sends data to the endpoint using the adapter connectivity.
* @param endpoint [IN] Remote Endpoint information (like ipaddress , port,
* reference uri and transport type) to which the unicast data has to be sent.
* @param data [IN] Data which is required to be sent.
* @param dataLen [IN] Size of data to be sent.
* @return The number of bytes sent on the network. Return value equal to -1 indicates error.
* @remarks dataLen must be > 0.
*/
int32_t CASendRAUnicastData(const CAEndpoint_t *endpoint, const void *data,
uint32_t dataLen);
/**
* @brief Get RA Connectivity network information
* @param info [OUT] Local connectivity information structures
* @param size [OUT] Number of local connectivity structures.
* @return #CA_STATUS_OK or Appropriate error code
* @remarks info is allocated in this API and should be freed by the caller.
*/
CAResult_t CAGetRAInterfaceInformation(CAEndpoint_t **info, uint32_t *size);
/**
* @brief Stops RA server and de-register XMPP callback listeners
* @return #CA_STATUS_OK or Appropriate error code
*/
CAResult_t CAStopRA();
/**
* @brief Terminate the RA connectivity adapter.
* Configuration information will be deleted from further use
* @return NONE
*/
void CATerminateRA();
/**
* @brief Set Remote Access information for XMPP Client.
* @param caraInfo [IN] remote access info.
*
* @return CA_STATUS_OK
*/
CAResult_t CASetRAInfo(const CARAInfo_t *caraInfo);
/**
* These functions are not applicable to Remote Access adapter
*/
int32_t CASendRAMulticastData(const CAEndpoint_t *endpoint,
const void *data, uint32_t dataLen);
/**
* @brief Start listening server for receiving search requests.
* @return #CA_NOT_SUPPORTED
*/
CAResult_t CAStartRAListeningServer();
/**
* @brief Start discovery servers for receiving advertisements.
* @return #CA_NOT_SUPPORTED
*/
CAResult_t CAStartRADiscoveryServer();
/**
* @brief Read Synchronous API callback.
* @return #CA_NOT_SUPPORTED
*/
CAResult_t CAReadRAData();
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif //CA_RA_ADAPTER_H_
......@@ -9,6 +9,7 @@ sample_env = env.Clone()
ca_os = sample_env.get('TARGET_OS')
ca_transport = sample_env.get('TARGET_TRANSPORT')
secured = sample_env.get('SECURED')
with_ra = sample_env.get('WITH_RA')
root_dir = './../../'
#####################################################################
......@@ -35,9 +36,15 @@ sample_src = ['./sample_main.c',]
print " sample src %s" % sample_src
#env.StaticLibrary('casample', sample_src)
sample_env.PrependUnique(LIBPATH = [sample_env.get('BUILD_DIR'), '.',])
sample_env.PrependUnique(LIBPATH = [sample_env.get('BUILD_DIR'), '.'])
sample_env.PrependUnique(RPATH = [sample_env.get('BUILD_DIR'), '.',])
sample_env.PrependUnique(LIBS = ['connectivity_abstraction', 'coap', 'pthread', 'rt'])
sample_env.PrependUnique(LIBS = ['connectivity_abstraction'])
if with_ra:
sample_env.AppendUnique(LIBS = ['ra_xmpp'])
sample_env.AppendUnique(LIBS = ['coap', 'pthread'])
if ca_os not in ['darwin']:
sample_env.PrependUnique(LIBS = ['rt'])
if secured == '1':
current_dir=env.get('SRC_DIR')
......
......@@ -9,6 +9,7 @@ Import('env')
ca_os = env.get('TARGET_OS')
ca_transport = env.get('TARGET_TRANSPORT')
secured = env.get('SECURED')
with_ra = env.get ('WITH_RA')
root_dir = os.pardir
ca_path = os.curdir
......@@ -89,9 +90,11 @@ ca_common_src = [
env.AppendUnique(CA_SRC = ca_common_src)
if 'ALL' in ca_transport:
transports = [ 'ip_adapter', 'bt_edr_adapter', 'bt_le_adapter' ]
env.SConscript(dirs = [
os.path.join(ca_path, d) for d in transports ])
transports = [ 'ip_adapter', 'bt_edr_adapter', 'bt_le_adapter' ]
if with_ra:
transports.append ('ra_adapter')
env.SConscript(dirs = [
os.path.join(ca_path, d) for d in transports ])
if 'IP' in ca_transport:
env.SConscript(os.path.join(ca_path, 'ip_adapter/SConscript'))
......
......@@ -253,11 +253,19 @@ CAResult_t CASelectNetwork(CATransportAdapter_t interestedNetwork)
res = CAAddNetworkType(CA_ADAPTER_GATT_BTLE);
OIC_LOG_V(ERROR, TAG, "CAAddNetworkType(CA_GATT_ADAPTER) function returns error : %d", res);
}
#ifdef RA_ADAPTER
else if (interestedNetwork & CA_ADAPTER_REMOTE_ACCESS)
{
res = CAAddNetworkType(CA_ADAPTER_REMOTE_ACCESS);
OIC_LOG_V(ERROR, TAG, "CAAddNetworkType(CA_ADAPTER_REMOTE_ACCESS) function returns error : %d",
res);
}
#endif
else
{
res = CA_NOT_SUPPORTED;
}
return res;
}
......@@ -287,11 +295,18 @@ CAResult_t CAUnSelectNetwork(CATransportAdapter_t nonInterestedNetwork)
res = CARemoveNetworkType(CA_ADAPTER_GATT_BTLE);
OIC_LOG_V(ERROR, TAG, "CARemoveNetworkType(CA_GATT_ADAPTER) function returns error : %d", res);
}
#ifdef RA_ADAPTER
else if (nonInterestedNetwork & CA_ADAPTER_REMOTE_ACCESS)
{
res = CARemoveNetworkType(CA_ADAPTER_REMOTE_ACCESS);
OIC_LOG_V(ERROR, TAG, "CARemoveNetworkType(CA_ADAPTER_REMOTE_ACCESS) function returns error : %d",
res);
}
#endif
else
{
res = CA_STATUS_FAILED;
}
return res;
}
......
......@@ -33,13 +33,26 @@
#include "caremotehandler.h"
#include "cathreadpool.h"
#include "caipadapter.h"
#include "cainterface.h"
#ifdef RA_ADAPTER
#include "caraadapter.h"
#endif
#define TAG "CA_INTRFC_CNTRLR"
#ifdef RA_ADAPTER
#include "caraadapter.h"
#endif
#define CA_MEMORY_ALLOC_CHECK(arg) {if (arg == NULL) \
{OIC_LOG(ERROR, TAG, "memory error");goto memory_error_exit;} }
#ifdef RA_ADAPTER
#define CA_TRANSPORT_TYPE_NUM 4
#else
#define CA_TRANSPORT_TYPE_NUM 3
#endif
static CAConnectivityHandler_t g_adapterHandler[CA_TRANSPORT_TYPE_NUM] = {};
......@@ -59,12 +72,15 @@ static int CAGetAdapterIndex(CATransportAdapter_t cType)
return 1;
case CA_ADAPTER_RFCOMM_BTEDR:
return 2;
#ifdef RA_ADAPTER
case CA_ADAPTER_REMOTE_ACCESS:
return 3;
#endif
default:
break;
}
OIC_LOG(DEBUG, TAG, "CA_TRANSPORT_TYPE_NUM is not 3");
return -1;
}
......@@ -100,6 +116,13 @@ static void CARegisterCallback(CAConnectivityHandler_t handler, CATransportAdapt
OIC_LOG(DEBUG, TAG, "OUT");
}
#ifdef RA_ADAPTER
CAResult_t CASetAdapterRAInfo(const CARAInfo_t *caraInfo)
{
return CASetRAInfo(caraInfo);
}
#endif
static void CAReceivedPacketCallback(const CAEndpoint_t *endpoint, void *data, uint32_t dataLen)
{
OIC_LOG(DEBUG, TAG, "IN");
......@@ -167,6 +190,12 @@ void CAInitializeAdapters(ca_thread_pool_t handle)
CAAdapterErrorHandleCallback, handle);
#endif /* LE_ADAPTER */
#ifdef RA_ADAPTER
CAInitializeRA(CARegisterCallback, CAReceivedPacketCallback, CANetworkChangedCallback,
handle);
#endif /* RA_ADAPTER */
}
void CASetPacketReceivedCallback(CANetworkPacketReceivedCallback callback)
......
......@@ -32,6 +32,10 @@ static uint32_t NETWORK_IP = CA_ADAPTER_IP;
static uint32_t NETWORK_RFCOMM = CA_ADAPTER_RFCOMM_BTEDR;
static uint32_t NETWORK_GATT = CA_ADAPTER_GATT_BTLE;
#ifdef RA_ADAPTER
static uint32_t NETWORK_RA = CA_ADAPTER_REMOTE_ACCESS;
#endif
CAResult_t CAAddNetworkType(CATransportAdapter_t transportType)
{
OIC_LOG(DEBUG, TAG, "IN");
......@@ -90,6 +94,19 @@ CAResult_t CAAddNetworkType(CATransportAdapter_t transportType)
}
res = u_arraylist_add(g_selectedNetworkList, &NETWORK_GATT);
break;
#ifdef RA_ADAPTER
case CA_ADAPTER_REMOTE_ACCESS:
OIC_LOG(DEBUG, TAG, "Add network type(RA)");
if (u_arraylist_contains(g_selectedNetworkList, &NETWORK_RA))
{
goto exit;
}
res = u_arraylist_add(g_selectedNetworkList, &NETWORK_RA);
break;
#endif /* RA_ADAPTER */
default:
break;
}
......@@ -164,7 +181,14 @@ CAResult_t CARemoveNetworkType(CATransportAdapter_t transportType)
OIC_LOG(DEBUG, TAG, "Remove network type(LE)");
u_arraylist_remove(g_selectedNetworkList, index);
#endif /* LE_ADAPTER */
break;
#ifdef RA_ADAPTER
case CA_ADAPTER_REMOTE_ACCESS:
OIC_LOG(DEBUG, TAG, "Remove network type(RA)");
u_arraylist_remove(g_selectedNetworkList, index);
break;
#endif /* RA_ADAPTER */
default:
break;
......
#******************************************************************
#
# Copyright 2015 Intel Mobile Communications GmbH 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.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Import('env')
import os
print "Reading RA adapter script"
target_os = env.get('TARGET_OS')
inc_files = env.get('CPPPATH')
src_dir = './ra_adapter'