Commit 3a508b35 authored by Ashok Channa's avatar Ashok Channa Committed by Sudarshan Prasad

Tizen, Android BT , BLE optimization - making similar to wifi, eth adapters

For adapting new platforms at adapter level , common logic is added for each adapter.
Platform related calls are divided into client, server and network monitor.

Change-Id: I0086619ae5207e79fee08a6776bbc1a033ac6f44
Signed-off-by: default avatarAshok Channa <ashok.channa@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/143Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarSudarshan Prasad <sudarshan.prasad@intel.com>
parent e90065df
......@@ -9,10 +9,11 @@ PROJECT_COMMON_PATH = $(PROJECT_ROOT_PATH)/common
PROJECT_COMMON_INC_PATH = $(PROJECT_COMMON_PATH)/inc
PROJECT_COMMON_SRC_PATH = $(PROJECT_COMMON_PATH)/src
PROJECT_LIB_PATH = $(PROJECT_ROOT_PATH)/lib
DTLS_LIB = $(PROJECT_LIB_PATH)/extlibs/tinydtls
PROJECT_EXTERNAL_PATH = $(PROJECT_ROOT_PATH)/external/inc
DTLS_LIB = $(PROJECT_LIB_PATH)/tinydtls
#Modify below values to enable/disable the Adapter
#Suffix "NO_" to disable given adapter
#Suffix "NO_" to disable given adapter
EDR = EDR_ADAPTER
WIFI = WIFI_ADAPTER
LE = LE_ADAPTER
......@@ -122,6 +123,7 @@ LOCAL_C_INCLUDES = $(PROJECT_API_PATH)
LOCAL_C_INCLUDES += $(PROJECT_COMMON_INC_PATH)
LOCAL_C_INCLUDES += $(PROJECT_INC_PATH)
LOCAL_C_INCLUDES += $(PROJECT_LIB_PATH)/libcoap-4.1.1
LOCAL_C_INCLUDES += $(PROJECT_EXTERNAL_PATH)
LOCAL_C_INCLUDES += $(DTLS_LIB)
LOCAL_CFLAGS += $(BUILD_FLAG)
......@@ -134,8 +136,9 @@ LOCAL_SRC_FILES = \
$(ADAPTER_UTILS)/camsgparser.c $(EDR_ADAPTER_PATH)/caedradapter.c \
$(LE_ADAPTER_PATH)/caleadapter.c $(LE_ADAPTER_PATH)/caleclient.c \
$(LE_ADAPTER_PATH)/caleserver.c $(LE_ADAPTER_PATH)/caleutils.c \
$(LE_ADAPTER_PATH)/calenwmonitor.c \
$(EDR_ADAPTER_PATH)/caedrcore.c \
wifi_adapter/cawifiadapter.c $(WIFI_ADAPTER_PATH)/cawifiserver.c \
$(WIFI_ADAPTER_PATH)/cawificlient.c $(WIFI_ADAPTER_PATH)/cawifinwmonitor.c \
$(LE_ADAPTER_PATH)/calenwmonitor.c \
include $(BUILD_STATIC_LIBRARY)
......@@ -3,7 +3,7 @@ exec_prefix=${prefix}
libdir=${prefix}/lib
includedir=${prefix}/include/interfaceHeaders
Name: com.samsung.oicca
Name: com.oic.ca
Description: Oic core library
Version: 1.0
Cflags: -I${includedir}
\ No newline at end of file
Cflags: -I${includedir}
%define PREFIX /usr/apps/com.samsung.oicca
%define PREFIX /usr/apps/com.oic.ca
%define ROOTDIR %{_builddir}/%{name}-%{version}
%define USR_INC_DIR /usr/include
%define DEST_INC_DIR %{buildroot}%{USR_INC_DIR}/interfaceHeaders
%define DEST_LIB_DIR %{buildroot}/usr/lib
Name: com.samsung.oicca
Name: com.oic.ca
Version: 0.1
Release: 1
Summary: Tizen oicca application
URL: http://slp-source.sec.samsung.net
Source: %{name}-%{version}.tar.gz
License: SAMSUNG
Group: Samsung/Application
License: Apache License, Version 2.0
Group: OIC/Application
#BuildRequires: cmake
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(glib-2.0)
......@@ -21,41 +21,44 @@ BuildRequires: boost-devel
BuildRequires: boost-thread
BuildRequires: boost-system
BuildRequires: boost-filesystem
BuildRequires: scons
#BuildRequires: oic-core
%description
SLP oicca application
%prep
%setup -q
%build
make clean
make
echo %{ROOTDIR}
#make %{?jobs:-j%jobs}
scons TARGET_OS=tizen -c
scons TARGET_OS=tizen TARGET_TRANSPORT=%{TARGET_TRANSPORT}
%install
rm -rf %{buildroot}
mkdir -p %{buildroot}/usr/share/license
mkdir -p %{buildroot}/usr/share/packages
mkdir -p %{buildroot}/etc/smack/accesses2.d
mkdir -p %{buildroot}/usr/apps/com.samsung.oicca/bin/
mkdir -p %{buildroot}/usr/apps/com.oic.ca/bin/
mkdir -p %{buildroot}/usr/lib
mkdir -p %{DEST_INC_DIR}
mkdir -p %{DEST_LIB_DIR}/pkgconfig
cp -rf %{ROOTDIR}/liboicinterface.a %{buildroot}/usr/lib
cp -rf %{ROOTDIR}/cacommon.h* %{DEST_INC_DIR}/
cp -rf %{ROOTDIR}/caadapterinterface.h* %{DEST_INC_DIR}/
cp -rf %{ROOTDIR}/uthreadpool.h* %{DEST_INC_DIR}/
cp -rf %{ROOTDIR}/cawifiadapter.h* %{DEST_INC_DIR}/
cp -rf %{ROOTDIR}/caethernetadapter.h* %{DEST_INC_DIR}/
cp -rf %{ROOTDIR}/caedradapter.h* %{DEST_INC_DIR}/
cp -rf %{ROOTDIR}/caleadapter.h* %{DEST_INC_DIR}/
cp -rf %{ROOTDIR}/cainterface.h* %{DEST_INC_DIR}/
cp -rf %{ROOTDIR}/com.samsung.oicca.pc %{DEST_LIB_DIR}/pkgconfig/
cp -rf %{ROOTDIR}/con/libconnectivity_abstraction.a %{buildroot}/usr/lib
cp -rf %{ROOTDIR}/con/lib/libcoap-4.1.1/libcoap.a %{buildroot}/usr/lib
cp -rf %{ROOTDIR}/con/api/cacommon.h* %{DEST_INC_DIR}/
cp -rf %{ROOTDIR}/con/inc/caadapterinterface.h* %{DEST_INC_DIR}/
cp -rf %{ROOTDIR}/con/common/inc/uthreadpool.h* %{DEST_INC_DIR}/
cp -rf %{ROOTDIR}/con/inc/cawifiadapter.h* %{DEST_INC_DIR}/
cp -rf %{ROOTDIR}/con/inc/caethernetadapter.h* %{DEST_INC_DIR}/
cp -rf %{ROOTDIR}/con/inc/caedradapter.h* %{DEST_INC_DIR}/
cp -rf %{ROOTDIR}/con/inc/caleadapter.h* %{DEST_INC_DIR}/
cp -rf %{ROOTDIR}/con/api/cainterface.h* %{DEST_INC_DIR}/
cp -rf %{ROOTDIR}/com.oic.ca.pc %{DEST_LIB_DIR}/pkgconfig/
%files
......
......@@ -22,11 +22,12 @@
char *OICStrdup(const char *str)
{
// Allocate memory for original string length and 1 extra byte for '\0'
size_t length = strlen(str) + 1;
char *dup = OICMalloc(length);
size_t length = strlen(str);
char *dup = (char *)OICMalloc(length + 1);
if (NULL != dup)
{
memcpy(dup, str, length);
dup[length] = '\0';
}
return dup;
}
......@@ -18,14 +18,14 @@
*
******************************************************************/
/**
* @file caedradapter.h
* @brief This file contains the APIs for EDR adapters to be implemented
* @file caedradapter.h
* @brief This file contains the APIs for EDR adapters.
*/
#ifndef __CA_EDRADAPTER_H_
#define __CA_EDRADAPTER_H_
/**
* BT Interface AP
* EDR Interface AP
**/
#include "cacommon.h"
#include "caadapterinterface.h"
......@@ -37,20 +37,19 @@ extern "C"
#endif
/**
* @fn CAInitializeEDR
* @brief Initialize EDR connectivity interface.
*
* @param[in] registerCallback To register EDR interfaces to Connectivity Abstraction Layer
* @param[in] reqRespCallback Callback to be notified on receival of request/responses from
* peer bluetooth devices.
* @param[in] netCallback Callback to be notified when network adapter state changes.
* @param[in] threadPool Thread pool for handling asynchronous tasks.
*
* @return #CA_STATUS_OK or #CA_ADAPTER_NOT_ENABLED on success otherwise proper error code.
* @brief Initialize EDR Interface.
* @param registerCallback [IN] Callback to register EDR interface to Connectivity
* Abstraction Layer
* @param reqRespCallback [IN] Callback to notify request and response messages from server(s)
* started at Connectivity Abstraction Layer.
* @param netCallback [IN] Callback to intimate the network additions to Connectivity
* Abstraction Layer.
* @param handle [IN] Threadpool Handle
* @return #CA_STATUS_OK or Appropriate error code
* @retval #CA_STATUS_OK Successful
* @retval #CA_STATUS_INVALID_PARAM Invalid input parameters
* @retval #CA_ADAPTER_NOT_ENABLED Initialization is successful, but bluetooth adapter is
* not enabled
* not enabled
* @retval #CA_STATUS_FAILED Operation failed
*/
CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback,
......@@ -59,11 +58,9 @@ CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback,
u_thread_pool_t handle);
/**
* @fn CAStartEDR
* @brief Starting EDR connectivity adapters. As its peer to peer it doesnot require to start
* any servers.
*
* @return #CA_STATUS_OK on success otherwise proper error code.
* @brief Starts EDR connectivity adapters. As its peer to peer it doesnot require to start
* any servers.
* @return #CA_STATUS_OK or Appropriate error code
* @retval #CA_STATUS_OK Successful
* @retval #CA_ADAPTER_NOT_ENABLED Bluetooth adapter is not enabled
* @retval #CA_STATUS_FAILED Operation failed
......@@ -72,105 +69,98 @@ CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback,
CAResult_t CAStartEDR();
/**
* @fn CAStartEDRListeningServer
* @brief Starting listening server for receiving multicast search requests.
* Starts RFCOMM Server with prefixed UUID as per OIC specification.
* @brief Starts listening server for receiving multicast search requests.
* Starts RFCOMM Server with prefixed UUID as per OIC specification.
*
* @return #CA_STATUS_OK on success otherwise proper error code.
* @retval #CA_STATUS_OK Successful
* @retval #CA_SERVER_STARTED_ALREADY Server is already started and running for the predefined
* service UUID
* @retval #CA_STATUS_FAILED Operation failed
* @return #CA_STATUS_OK or Appropriate error code
* @retval #CA_STATUS_OK Successful
* @retval #CA_SERVER_STARTED_ALREADY Server is already started and running for the predefined
* service UUID
* @retval #CA_STATUS_FAILED Operation failed
*
*/
CAResult_t CAStartEDRListeningServer();
/**
* @fn CAStartEDRDiscoveryServer
* @brief Starting discovery server for receiving multicast advertisements.
* Starts RFCOMM Server with prefixed UUID as per OIC specification.
*
* @return #CA_STATUS_OK on success otherwise proper error code.
* @retval #CA_STATUS_OK Successful
* @retval #CA_SERVER_STARTED_ALREADY Server is already started and running for the predefined
* service UUID
* @retval #CA_STATUS_FAILED Operation failed
* Starts RFCOMM Server with prefixed UUID as per OIC specification.
*
* @return #CA_STATUS_OK or Appropriate error code
* @retval #CA_STATUS_OK Successful
* @retval #CA_SERVER_STARTED_ALREADY Server is already started and running for the predefined
* service UUID
* @retval #CA_STATUS_FAILED Operation failed
*/
CAResult_t CAStartEDRDiscoveryServer();
/**
* @fn CASendEDRUnicastData
* @brief Sends data to the peer bluetooth OIC device using the adapter connectivity.
*
* @param[in] remoteEndpoint Information about peer device to which data needs to be send.
* @param[in] data Data which needs to be send to peer OIC device.
* @param[in] dataLength Length of data in bytes.
*
* @return Number of bytes sent on the network. 0 indicates failed to send data.
* @param remoteEndpoint [IN] Remote Endpoint information (like ipaddress, port, reference uri and
* connectivity type) to which the unicast data has to be sent.
* @param data [IN] Data to be sent.
* @param dataLength [IN] Size of data to be sent.
* @return The number of bytes sent on the network. Returns 0 on error.
*
*/
uint32_t CASendEDRUnicastData(const CARemoteEndpoint_t *remoteEndpoint, void *data,
uint32_t dataLength);
/**
* @fn CASendEDRMulticastData
* @brief Sends multicast data to all discovered bluetooth OIC devices using the adapter
* connectivity.
*
* @param[in] data Data which needs to be send to all discovered bluetooth OIC device.
* @param[in] dataLength Length of data in bytes.
*
* @return Number of bytes sent on the network. 0 indicates failed to send data.
*
* connectivity.
* @param data [IN] Data which needs to be sent to all discovered bluetooth OIC device.
* @param dataLength [IN] Length of data in bytes.
* @return Number of bytes sent on the network. Returns 0 on error.
*/
uint32_t CASendEDRMulticastData(void *data, uint32_t dataLength);
/**
* @fn CAGetEDRInterfaceInformation
* @brief Get EDR Connectivity network information.
*
* @param[out] info Array of local connectivity information structures.
* @param[out] size Size of the array @info.
*
* @return #CA_STATUS_OK on success otherwise proper error code.
* @retval #CA_STATUS_OK Successful
* @retval #CA_STATUS_INVALID_PARAM Invalid input parameters
* @retval #CA_MEMORY_ALLOC_FAILED Failed to allocate memory
* @retval #CA_STATUS_FAILED Operation failed
* @param info [OUT] Array of local connectivity information structures.
* @param size [OUT] Size of the array @info.
*
* @return #CA_STATUS_OK or Appropriate error code
* @retval #CA_STATUS_OK Successful
* @retval #CA_STATUS_INVALID_PARAM Invalid input parameters
* @retval #CA_MEMORY_ALLOC_FAILED Failed to allocate memory
* @retval #CA_STATUS_FAILED Operation failed
* @remarks info is allocated in this API and should be freed by the caller.
*/
CAResult_t CAGetEDRInterfaceInformation(CALocalConnectivity_t **info, uint32_t *size);
/**
* @fn CAReadEDRData
* @brief Read Synchronous API callback.
*
* @return #CA_STATUS_OK on success otherwise proper error code.
* @retval #CA_STATUS_OK Successful
* @retval #CA_STATUS_FAILED Operation failed
*
* @return #CA_STATUS_OK on success otherwise proper error code.
* @retval #CA_STATUS_OK Successful
* @retval #CA_STATUS_FAILED Operation failed
*/
CAResult_t CAReadEDRData();
/**
* @fn CAStopEDR
* @brief Stopping the adapters and close socket connections
* EDR Stops all RFCOMM servers and close sockets.
*
* @return #CA_STATUS_OK on success
*
* @brief EDR Stops all RFCOMM servers and close sockets.
* @return #CA_STATUS_OK or Appropriate error code
*/
CAResult_t CAStopEDR();
/**
* @fn CATerminateEDR
* @brief Terminate the EDR connectivity adapter.
* Configuration information will be deleted from further use.
*
* @return NONE
*/
void CATerminateEDR();
/**
* @brief Initializes the adapter queues.
* This will initiates both server and receiver adapter queues.
* @return #CA_STATUS_OK or Appropriate error code
* @retval #CA_STATUS_OK Successful
* @retval #CA_STATUS_INVALID_PARAM Invalid input parameters
* @retval #CA_MEMORY_ALLOC_FAILED Failed to allocate memory
* @retval #CA_STATUS_FAILED Operation failed
*/
CAResult_t CAAdapterStartQueue();
#ifdef __cplusplus
} /* extern "C" */
#endif
......
/******************************************************************
*
* Copyright 2014 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.
*
******************************************************************/
/**
* @file caedrcore.h
* @brief This file contains the APIs for BT EDR communications.
*/
#ifndef __CA_EDRCORE_H_
#define __CA_EDRCORE_H_
#include <stdbool.h>
#include "cacommon.h"
#include "uthreadpool.h"
#include "jni.h"
#ifdef __cplusplus
extern "C"
{
#endif
typedef struct connected_state {
char address[CA_MACADDR_SIZE];
uint32_t state;
} state_t;
/**
* @enum CAAdapterServerType_t
* @brief Enum for defining different server types.
*/
typedef enum
{
CA_UNICAST_SERVER = 0, /**< Unicast Server */
CA_MULTICAST_SERVER, /**< Multicast Server */
CA_SECURED_UNICAST_SERVER /**< Secured Unicast Server */
} CAAdapterServerType_t;
typedef void (*CAPacketReceiveCallback)(const char *address, const char *data);
void CAEDRClientJNISetContext(JNIEnv *env, jobject context);
void CAEDRCreateJniInterfaceObject();
void CAEDRInitialize(u_thread_pool_t handle);
void CAEDRTerminate();
void CAEDRCoreJniInit(JNIEnv *env, JavaVM* jvm);
int32_t CAEDRSendUnicastMessage(const char *address, const char *data, uint32_t dataLen);
int32_t CAEDRSendMulticastMessage(const char *data, uint32_t dataLen);
int32_t CAEDRStartUnicastServer(const char *address, bool isSecured);
int32_t CAEDRStartMulticastServer(bool isSecured);
int32_t CAEDRStopUnicastServer(int32_t serverID);
int32_t CAEDRStopMulticastServer(int32_t serverID);
void CAEDRSetCallback(CAPacketReceiveCallback callback);
CAResult_t CAEDRGetInterfaceInfo(char **address);
void CAEDRGetLocalAddress(char** address);
int32_t CAEDRSendUnicastMessageImpl(const char *address, const char *data, uint32_t dataLen);
int32_t CAEDRSendMulticastMessageImpl(JNIEnv *env, const char *data, uint32_t dataLen);
/**
* EDR Method
*/
void CAEDRNativeSendData(JNIEnv *env, const char* address, const char* data, uint32_t id);
int CAEDRNativeReadData(JNIEnv *env, uint32_t id, CAAdapterServerType_t type);
jobject CAEDRNativeListen(JNIEnv *env);
void CAEDRNativeAccept(JNIEnv *env, jobject severSocketObject);
void CAEDRNativeConnect(JNIEnv *env, const char* address, uint32_t id);
void CAEDRNativeSocketClose(JNIEnv *env, const char* address, uint32_t id);
/**
* BT Common Method : JNI
*/
jstring CAEDRNativeGetAddressFromDeviceSocket(JNIEnv *env, jobject bluetoothSocketObj);
jstring CAEDRNativeGetLocalDeviceAddress(JNIEnv *env);
jobjectArray CAEDRNativeGetBondedDevices(JNIEnv *env);
jint CAEDRNativeGetBTStateOnInfo(JNIEnv *env);
jboolean CAEDRNativeIsEnableBTAdapter(JNIEnv *env);
jstring CAEDRNativeGetAddressFromBTDevice(JNIEnv *env, jobject bluetoothDevice);
/**
* BT State List
*/
void CAEDRNativeCreateDeviceStateList();
void CAEDRUpdateDeviceState(uint32_t state, const char* address);
void CAEDRNativeAddDeviceStateToList(state_t* state);
jboolean CAEDRNativeIsDeviceInList(const char *remoteAddress);
void CAEDRNativeRemoveAllDeviceState();
void CAEDRNativeRemoveDevice(const char* remoteAddress);
jboolean CAEDRIsConnectedDevice(const char* remoteAddress);
void CAEDRReorderingDeviceList(uint32_t index);
/**
* Bluetooth Socket Object List
*/
void CAEDRNativeCreateDeviceSocketList();
void CAEDRNativeAddDeviceSocketToList(JNIEnv *env, jobject deviceSocket);
jboolean CAEDRNativeIsDeviceSocketInList(JNIEnv *env, const char *remoteAddress);
void CAEDRNativeRemoveAllDeviceSocket(JNIEnv *env);
void CAEDRNativeRemoveDeviceSocket(JNIEnv *env, jobject deviceSocket);
jobject CAEDRNativeGetDeviceSocket(uint32_t idx);
uint32_t CAEDRGetSocketListLength();
void CAEDRReorderingDeviceSocketList(uint32_t index);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif
/******************************************************************
*
* Copyright 2014 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.
*
******************************************************************/
/**
* @file caedrinterface.h
* @brief This file provides APIs for EDR adapter - client, server, network monitor modules
*/
#ifndef __CA_EDR_INTERFACE_H_
#define __CA_EDR_INTERFACE_H_
#include <string.h>
#include "caedradapter.h"
#ifdef __cplusplus
extern "C"
{
#endif
#ifndef OIC_EDR_SERVICE_ID
#define OIC_EDR_SERVICE_ID "12341234-1C25-481F-9DFB-59193D238280"
#endif //OIC_EDR_SERVICE_ID
/**
* @struct CAEDRData
* @brief Structure to maintain the information of data in message queue.
*/
typedef struct
{
CARemoteEndpoint_t *remoteEndpoint; /**< Remote Endpoint */
void *data; /**< Data to be sent */
uint32_t dataLen; /**< Length of the data to be sent */
} CAEDRData;
/**
* @struct CAEDRNetworkEvent
* @brief Structure to maintain the adapter information and its status.
*/
typedef struct
{
CALocalConnectivity_t *info; /**< Local Connectivity Information */
CANetworkStatus_t status; /**< Network Status */
} CAEDRNetworkEvent;
/**
* @brief This will be used during the recive of network requests and response.
* @param remoteAddress [IN] EDR address of remote OIC device
* @param data [IN] Data received
* @param dataLength [IN] Length of the Data received
* @param sentLength [IN] Length of the sent data
* @return NONE
* @pre Callback must be registered using CAEDRSetPacketReceivedCallback()
*/
typedef void (*CAEDRDataReceivedCallback)(const char *remoteAddress, void *data, uint32_t dataLength,
uint32_t *sentLength);
/**
* @brief This will be used during change in network status.
* @param status [IN] Network Status of the adapter
* @return NONE
*/
typedef void (*CAEDRNetworkStatusCallback)(CANetworkStatus_t status);
/**
* @brief Initialize the network monitor module
*
* @return #CA_STATUS_OK or Appropriate error code
* @retval #CA_STATUS_OK Successful
* @retval #CA_ADAPTER_NOT_ENABLED Initialization is successful, but bluetooth adapter is
* not enabled.
* @retval #CA_STATUS_FAILED Operation failed
* @see CAEDRTerminateNetworkMonitor()
*/
CAResult_t CAEDRInitializeNetworkMonitor();
/**
* @brief Deinitialize with bluetooth adapter.
* @return NONE
* @pre CAEDRInitializeNetworkMonitor() should be invoked before using this API.