+++ /dev/null
-Project Name: IoTivity
-Release Version No: CA_v0.3
-API Version: CA_v0.5
-
-Release Description:
-Connectivity Abstraction provides a unified approach to send different OIC messages across multiple transports.
-
-Supported Platform OS:
-1) Ubuntu 12.0.4 and above:
- Connectivity : WIFI, ETHERNET
-2) Tizen 2.3
- Connectivity : WIFI, EDR, BLE(1:1).
-3) Arduino Mega
- Connectivity : WIFI, ETH
-
-Preconditions:
-1)gcc 4.6.3 and above.
-2)glib library (sudo apt-get install libglib2.0-dev)
-3)libcoap.a library ( do make @lib/libcoap-4.1.1)
-
-
-Scope of Release:
-1. Supported APIs ( please check below APIs)
-2. Samples to test for Supported APIs.
-3. OIC Coding guidelines followed based on the current CSDK source.
-4. Multi-Threaded, Single threaded Connectivity abstraction.
-5. Executed Open Source Verification and Prevent analysis.
-Type of Release: Source
-The following Connectivity Abstraction API features are supported in this release:
-
-Supported APIs
-CAInitialize()
-CATerminate()
-CAStartListeningServer()
-CAStartDiscoveryServer()
-CARegisterHandler()
-CAhandleRequestResponse()
-FindResource()
-SendRequest()
-SendResponse()
-SelectNetwork()
-UnselectNetwork()
-SendNotification()
-AdvertizeResource()
-CAGenerateToken()
-CADestryToken()
-CAGetNetworkInfo()
-
-
-Known and Open Issues:
-1) OIC Log, OIC Malloc will be removed once name changes applied to OIC Bases code.
-2) Tizen platform BLE stack is not stable. So we may see random crashes.
-
-How to Build:
-Follow below steps to execute CA Client / server in different systems
-Step 1: Build Libcoap library
-Make File Location @connectivity\lib\libcoap-4.1.1
-Step 2: Build CA library
-Make File Location @connectivity\build\linux
-Step 3: Samples
-Make File Location @connectivity\samples\linux
-
-Execution:
-linux$ export LD_LIBRARY_PATH=../../build/out/
-linux$ ./out/sample_main
-
-
-Follow below sequence to test
-
-Client Option: c
-Server Option: s
-
-Client Option: f (provide a/light)
-Server Option: h (will pick from queue and send response)
-Client Option: h (to pick server response)
-
-Client Option: r (provide “ServerIP:5383/a/request”)
-Server Option: h (will pick from queue and send response)
-Client Option: h (to pick server response)
-
-Server Option: a
-Client Option: h (to pick server response)
-
-Server Option: b (provide ServerIP:5383/a/notify)
-Client Option: h (to pick server response)
-
-Client: Server side: n for network selection (WIFI enabled by default)
--- /dev/null
+Project Name: IoTivity
+Release Version No: CA_v0.4
+API Version: CA_v0.5
+
+Release Description:
+Connectivity Abstraction provides a unified approach to send different OIC messages across multiple transports.
+
+Supported Platform OS:
+1) Ubuntu 12.0.4 and above:
+ Connectivity : WIFI, ETHERNET
+2) Tizen 2.3
+ Connectivity : WIFI, EDR, BLE(1:1).
+3) Arduino Mega
+ Connectivity : WIFI, ETH,BLE
+
+Preconditions:
+1)gcc 4.6.3 and above.
+2)glib library (sudo apt-get install libglib2.0-dev)
+3)libcoap.a library ( do make @lib/libcoap-4.1.1)
+
+
+Scope of Release:
+1. Supported APIs ( please check below APIs)
+2. Samples to test for Supported APIs.
+3. OIC Coding guidelines followed based on the current CSDK source.
+4. Multi-Threaded, Single threaded Connectivity abstraction.
+5. Executed Open Source Verification and Prevent analysis.
+Type of Release: Source
+The following Connectivity Abstraction API features are supported in this release:
+
+Supported APIs
+CAInitialize()
+CATerminate()
+CAStartListeningServer()
+CAStartDiscoveryServer()
+CARegisterHandler()
+CAhandleRequestResponse()
+FindResource()
+SendRequest()
+SendResponse()
+SelectNetwork()
+UnselectNetwork()
+SendNotification()
+AdvertizeResource()
+CAGenerateToken()
+CADestryToken()
+CAGetNetworkInfo()
+
+
+Known and Open Issues:
+1) OIC Log, OIC Malloc will be removed once name changes applied to OIC Bases code.
+2) Tizen platform BLE stack is not stable. So we may see random crashes.
+
+How to Build for Linux:
+Follow below steps to execute CA Client / server in different systems
+Step 1: Build Libcoap library
+Make File Location @connectivity\lib\libcoap-4.1.1
+Step 2: Build CA library
+Make File Location @connectivity\build\linux
+Step 3: Samples
+Make File Location @connectivity\samples\linux
+
+Execution:
+linux$ export LD_LIBRARY_PATH=../../build/out/
+linux$ ./out/sample_main
+
+
+Follow below sequence to test
+
+Client Option: c
+Server Option: s
+
+Client Option: f (provide a/light)
+Server Option: h (will pick from queue and send response)
+Client Option: h (to pick server response)
+
+Client Option: r (provide “ServerIP:5383/a/request”)
+Server Option: h (will pick from queue and send response)
+Client Option: h (to pick server response)
+
+Server Option: a
+Client Option: h (to pick server response)
+
+Server Option: b (provide ServerIP:5383/a/notify)
+Client Option: h (to pick server response)
+
+Client: Server side: n for network selection (WIFI enabled by default)
PLATFORM := arduinomega
TRANSPORT := BLE
OBJ_DIR := ./bin
-APP_NAME := sample_main
+APP_NAME := casample
ARDUINO_PORT := ttyACM0
include ./local.properties
SPI_OBJ = SPI.cpp.o
TIMED_OBJ = TimedAction.cpp.o
LOGGER_OBJ = logger.cpp.o oic_logger.c.o oic_console_logger.c.o oic_malloc.c.o uarraylist.c.o
-UTIL_OBJ = caadapterutils.c.o
+UTIL_OBJ = caadapterutils.c.o camsgparser.c.o
CACOMMON_OBJ = caconnectivitymanager_singlethread.c.o cainterfacecontroller_singlethread.c.o camessagehandler_singlethread.c.o canetworkconfigurator_singlethread.c.o caprotocolmessage.c.o \
caremotehandler.c.o
BLE_OBJ = aci_queue.cpp.o aci_setup.cpp.o acilib.cpp.o hal_aci_tl.cpp.o lib_aci.cpp.o
RBL_OBJ = RBL_nRF8001.cpp.o
INTERFACE_OBJ = caleadapter.cpp.o caleserver.cpp.o
- PLATFORM_OBJS = $(CORE_COBJ) $(CORE_CPPOBJ) $(SPI_OBJ) $(TIMED_OBJ) $(LOGGER_OBJ) $(INTERFACE_OBJ) $(BLE_OBJ) $(RBL_OBJ) $(CACOMMON_OBJ)
+ PLATFORM_OBJS = $(CORE_COBJ) $(CORE_CPPOBJ) $(SPI_OBJ) $(TIMED_OBJ) $(LOGGER_OBJ) $(INTERFACE_OBJ) $(BLE_OBJ) $(RBL_OBJ) $(UTIL_OBJ) $(CACOMMON_OBJ)
else
$(info *********error**********)
$(error Wrong value for TRANSPORT !!)
#define OIC_LOG_CONFIG(ctx)
#define OIC_LOG_SHUTDOWN()
#define OIC_LOG(level, tag, logStr) OICLog((level), (tag), __LINE__, (logStr))
-#define OIC_LOG_V(level, tag, ...) OICLogv((level), (tag), __LINE__, __VA_ARGS__)
+#define OIC_LOG_V(level, tag, ...)
#else
#define OIC_LOG_CONFIG(ctx) OICLogConfig((ctx))
#define OIC_LOG_SHUTDOWN() OICLogShutdown()
* @var gThreadpool
* @brief Glib thread pool.
*/
-static GThreadPool *gThreadpool;
+static GThreadPool *gThreadpool = NULL;
/**
* @fn run
CAResult_t u_thread_pool_init(uint32_t num_of_threads, u_thread_pool_t *thread_pool)
{
- OIC_LOG_V(DEBUG, TAG, "IN");
+ OIC_LOG(DEBUG, TAG, "IN");
GError *error = NULL;
gThreadpool = g_thread_pool_new(run, NULL, num_of_threads, TRUE, &error);
if (NULL == gThreadpool)
{
- OIC_LOG_V(ERROR, TAG, "g_thread_pool_new failed!");
+ OIC_LOG(ERROR, TAG, "g_thread_pool_new failed!");
if (NULL != error)
{
OIC_LOG_V(ERROR, TAG, "Error is: %s", error->message);
}
*thread_pool = (u_thread_pool_t) gThreadpool;
- OIC_LOG_V(DEBUG, TAG, "OUT");
+ OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
}
CAResult_t u_thread_pool_add_task(u_thread_pool_t thread_pool, void (*routine)(void *), void *data)
{
- OIC_LOG_V(DEBUG, TAG, "IN");
+ OIC_LOG(DEBUG, TAG, "IN");
if (NULL == routine)
{
- OIC_LOG_V(ERROR, TAG, "routine is NULL!");
+ OIC_LOG(ERROR, TAG, "routine is NULL!");
return CA_STATUS_FAILED;
}
u_thread_msg_t *message = (u_thread_msg_t *) OICMalloc(sizeof(u_thread_msg_t));
if (NULL == message)
{
- OIC_LOG_V(ERROR, TAG, "Memory allocation failed!");
+ OIC_LOG(ERROR, TAG, "Memory allocation failed!");
return CA_MEMORY_ALLOC_FAILED;
}
g_thread_pool_push((GThreadPool *) thread_pool, (void *) message, NULL);
- OIC_LOG_V(DEBUG, TAG, "OUT");
+ OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
}
void u_thread_pool_free(u_thread_pool_t thread_pool)
{
- OIC_LOG_V(DEBUG, TAG, "IN");
-
+ OIC_LOG(DEBUG, TAG, "IN");
+ if(NULL == thread_pool)
+ {
+ OIC_LOG(DEBUG, TAG, "thread_pool is NULL. Its already freed.");
+ return;
+ }
GThreadPool *threadpool = (GThreadPool *) thread_pool;
g_thread_pool_free(threadpool, TRUE, TRUE);
- OIC_LOG_V(DEBUG, TAG, "OUT");
+ OIC_LOG(DEBUG, TAG, "OUT");
}
void run(void *thread_data, void *user_data)
if (message && message->func)
{
- OIC_LOG_V(DEBUG, TAG, "Calling routine with data as parameter");
+ OIC_LOG(DEBUG, TAG, "Calling routine with data as parameter");
message->func(message->data);
}
else
{
- OIC_LOG_V(ERROR, TAG, "Invalid task data");
+ OIC_LOG(ERROR, TAG, "Invalid task data");
return;
}
--- /dev/null
+Project Name: IoTivity
+Release Version No: CA_v0.3
+API Version: CA_v0.5
+
+Release Description:
+Connectivity Abstraction provides a unified approach to send different OIC messages across multiple transports.
+
+Supported Platform OS:
+1) Ubuntu 12.0.4 and above:
+ Connectivity : WIFI, ETHERNET
+2) Tizen 2.3
+ Connectivity : WIFI, EDR, BLE(1:1).
+3) Arduino Mega
+ Connectivity : WIFI, ETH
+
+Preconditions:
+1)gcc 4.6.3 and above.
+2)glib library (sudo apt-get install libglib2.0-dev)
+3)libcoap.a library ( do make @lib/libcoap-4.1.1)
+
+
+Scope of Release:
+1. Supported APIs ( please check below APIs)
+2. Samples to test for Supported APIs.
+3. OIC Coding guidelines followed based on the current CSDK source.
+4. Multi-Threaded, Single threaded Connectivity abstraction.
+5. Executed Open Source Verification and Prevent analysis.
+Type of Release: Source
+The following Connectivity Abstraction API features are supported in this release:
+
+Supported APIs
+CAInitialize()
+CATerminate()
+CAStartListeningServer()
+CAStartDiscoveryServer()
+CARegisterHandler()
+CAhandleRequestResponse()
+FindResource()
+SendRequest()
+SendResponse()
+SelectNetwork()
+UnselectNetwork()
+SendNotification()
+AdvertizeResource()
+CAGenerateToken()
+CADestryToken()
+CAGetNetworkInfo()
+
+
+Known and Open Issues:
+1) OIC Log, OIC Malloc will be removed once name changes applied to OIC Bases code.
+2) Tizen platform BLE stack is not stable. So we may see random crashes.
+
+How to Build:
+Follow below steps to execute CA Client / server in different systems
+Step 1: Build Libcoap library
+Make File Location @connectivity\lib\libcoap-4.1.1
+Step 2: Build CA library
+Make File Location @connectivity\build\linux
+Step 3: Samples
+Make File Location @connectivity\samples\linux
+
+Execution:
+linux$ export LD_LIBRARY_PATH=../../build/out/
+linux$ ./out/sample_main
+
+
+Follow below sequence to test
+
+Client Option: c
+Server Option: s
+
+Client Option: f (provide a/light)
+Server Option: h (will pick from queue and send response)
+Client Option: h (to pick server response)
+
+Client Option: r (provide “ServerIP:5383/a/request”)
+Server Option: h (will pick from queue and send response)
+Client Option: h (to pick server response)
+
+Server Option: a
+Client Option: h (to pick server response)
+
+Server Option: b (provide ServerIP:5383/a/notify)
+Client Option: h (to pick server response)
+
+Client: Server side: n for network selection (WIFI enabled by default)
#include "oic_malloc.h"
#include "oic_string.h"
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
/**
* @def VERIFY_NON_NULL
* @brief Macro to verify the validity of input argument
*/
void CAAdapterFreeRemoteEndpoint(CARemoteEndpoint_t *remoteEndPoint);
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
#endif // _CA_ADAPTER_UTILS_H_
--- /dev/null
+/******************************************************************
+ *
+ * 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 camsgparser.h
+ * @brief This file contains common utility functions to manage the CA msg ragmentation and reassemebly.
+ */
+
+
+#ifndef _CA_MSG_PARSER_H_
+#define _CA_MSG_PARSER_H_
+
+#include "cacommon.h"
+#include "logger.h"
+
+#define MAX_DATA_LENGTH_SUPPORTED 4095
+#define NUMBER_OF_BITS_TO_IDENTIFY_DATA 12
+#define NUMBER_OF_BITS_IN_CA_HEADER 15
+#define CA_HEADER_LENGTH 2
+
+#ifdef __TIZEN__
+#define PLATFORM_IDENTIFIER_BIT 1
+#define CA_SUPPORTED_BLE_MTU_SIZE 200
+#else // #endif __TIZEN__
+#define PLATFORM_IDENTIFIER_BIT 0
+#define CA_SUPPORTED_BLE_MTU_SIZE 198
+#endif //#endif __ARDUINO__
+
+#define HEADER_VERSION 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+* @fn printBinaryFormat
+* @brief
+*
+* @return
+*/
+void printBinaryFormat(char* data);
+
+
+/**
+ * @file The CA Header format
+ * @brief CA Header will be difined by 2 bytes of Header.
+ * First two bits : Header version
+ * Third bit: Reserved and will be set as Zero.
+ * Fourth bit : PLATFORM_IDENTIFIER_BIT
+ * 5th to 16th bit : 12 bits to provide the length of the data in bits.
+ */
+
+/**
+* @fn CAGenerateHeader
+* @brief
+*
+* @return
+*/
+CAResult_t CAGenerateHeader(char* header, uint32_t length);
+
+/**
+* @fn CAParseHeader
+* @brief
+*
+* @return
+*/
+uint32_t CAParseHeader(const char* header);
+
+/**
+* @fn CAFragmentData
+* @brief
+*
+* @return
+*/
+uint32_t CAFragmentData(const char* data, char** dataSegment, uint32_t TotalLen, uint32_t offset);
+
+/**
+* @fn CADeFragmentData
+* @brief
+*
+* @return
+*/
+uint32_t CADeFragmentData(const char* datasegment, char** data, uint32_t TotalLen, uint32_t offset);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif // _CA_MSG_PARSER_H_
break;
}
}
+ //1:Add check for startserver before calling below api
+ handle_request_response();
}
void initialize()
char localBTAddress[20] = "DB:F7:EB:B5:0F:07"; //BT Address is not used internally by OIC API.
int number = 0;
-char coapData[7] = "hello";
+char coapData[30] = "Arduino Test Sample : \0";
CAConnectivityHandler_t *gConnectivityHandlers = NULL;
CALocalConnectivity_t localEndpoint;
}
}
- //Serial.println("zz");
return true;
}
void loop()
{
- Serial.println("Loop");
- if ((number % 2) == 0)
- coapData[5] = 'a';
- else
- coapData[6] = 'b';
- coapData[6] = '\0';
- number++;
- if (number == 10)
+ if (Serial.available() > 0)
{
- number = 0;
+ Serial.println("Serial available.");
+ switch (Serial.read())
+ {
+ case 's':
+ {
+ Serial.println("sending data");
+ if ( ble_connected() )
+ {
+ Serial.println("Sending Data");
+ gConnectivityHandlers->sendData(&remoteEndpoint[1], coapData, strlen(coapData));
+ Serial.println("Sent Data");
+ }
+ }
+ break;
}
- if ( ble_connected() )
- {
- Serial.println(PCF("Sending Data"));
- gConnectivityHandlers->sendData(&remoteEndpoint[1], coapData, strlen(coapData));
- Serial.println("Sent Data");
}
gConnectivityHandlers->readData();
- delay(2000);
}
#else
#include <stdlib.h>
--- /dev/null
+/******************************************************************
+ *
+ * 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.
+ *
+ ******************************************************************/
+
+#include "camsgparser.h"
+#include "cacommon.h"
+#include "caadapterutils.h"
+
+#include <string.h>
+
+#define CA_MSG_PARSER_TAG "CA_MSG_PARSER"
+
+
+void printBinaryFormat(char *data)
+{
+ OIC_LOG(DEBUG, CA_MSG_PARSER_TAG, "IN");
+ int i;
+ for (i = 0; i < 8; i++)
+ {
+ OIC_LOG_V(DEBUG, CA_MSG_PARSER_TAG, "c[%d]: %d", i, !!((*data << i) & 0x80));
+ }
+
+ OIC_LOG(DEBUG, CA_MSG_PARSER_TAG, "OUT");
+
+}
+
+CAResult_t CAGenerateHeader(char *header, uint32_t length)
+{
+ OIC_LOG(DEBUG, CA_MSG_PARSER_TAG, "IN");
+
+ VERIFY_NON_NULL(header, NULL, "header is NULL");
+
+ int temp = 0;
+
+ memset(header, 0x0, sizeof(char) * 2);
+
+ // Set the Header in the first two bits of the data as "01".
+ *header |= 0 << 7;
+ *header |= 1 << 6;
+
+ // Set the NEXT TWO reserved bits to Zero.
+ *header |= 0 << 5;
+ *header |= 0 << 4;
+
+ int i = 0;
+ for (i = 11; i >= 0; i--)
+ {
+ temp = length >> i;
+ if (temp & 1)
+ {
+ if (i > 7)
+ {
+ *header |= 1 << i - 8;
+ }
+ else
+ {
+ *(header + 1) |= 1 << i;
+ }
+ }
+ else
+ {
+ if (i > 7)
+ {
+ *header |= 0 << i - 8 ;
+ }
+ else
+ {
+ *(header + 1) |= 0 << i;
+ }
+ }
+ }
+
+ OIC_LOG(DEBUG, CA_MSG_PARSER_TAG, "OUT");
+
+ return CA_STATUS_OK;
+
+}
+
+uint32_t CAParseHeader(const char *header)
+{
+ OIC_LOG(DEBUG, CA_MSG_PARSER_TAG, "IN");
+
+ VERIFY_NON_NULL(header, NULL, "header is NULL");
+
+ int i, j;
+ int dataLen = 0;
+ for (i = 0; i < 8; i++)
+ {
+ int pos = 8 - i;
+ int bit = !!((*header << pos) & 0x80);
+ if ( i >= 4)
+ {
+ if ( 1 == bit)
+ {
+ dataLen = pow (2, pos + 7) + dataLen;
+ }
+ }
+ }
+
+ for (j = 0; j < 8; j++)
+ {
+ int pos = 7 - j;
+ int bit = !!((*(header + 1) << pos) & 0x80);
+ if ( 1 == bit)
+ {
+ dataLen = pow (2, j) + dataLen;
+ }
+ }
+ return dataLen;
+
+}
+
+
+uint32_t CAFragmentData(const char *data, char **dataSegment, uint32_t TotalLen, uint32_t offset)
+{
+ OIC_LOG(DEBUG, CA_MSG_PARSER_TAG, "IN");
+
+ VERIFY_NON_NULL(*data, NULL, "Param data is NULL");
+
+ uint32_t length = 0;
+
+ if (MAX_DATA_LENGTH_SUPPORTED < TotalLen)
+ {
+ OIC_LOG(ERROR, CA_MSG_PARSER_TAG, "dataLen is out of bound");
+ return -1;
+ }
+
+ if ( CA_SUPPORTED_BLE_MTU_SIZE <= TotalLen)
+ {
+ length = CA_SUPPORTED_BLE_MTU_SIZE;
+ }
+ else
+ {
+ length = TotalLen;
+ }
+
+ if (0 == offset)
+ {
+ OIC_LOG_V(DEBUG, CA_MSG_PARSER_TAG, "generatingf the Header info");
+
+ char *header = (char *) OICMalloc(sizeof(char) * CA_HEADER_LENGTH);
+ VERIFY_NON_NULL_RET(*header, CA_MSG_PARSER_TAG, "Malloc failed", -1);
+
+ *dataSegment = (char *) OICMalloc(sizeof(char) * length);
+ VERIFY_NON_NULL_RET(*dataSegment, CA_MSG_PARSER_TAG, "Malloc failed", -1);
+
+ memset(header, 0x0, sizeof(char) * CA_HEADER_LENGTH );
+ memset(*dataSegment, 0x0, sizeof(char) * length );
+
+ CAResult_t result = CAGenerateHeader(header, TotalLen);
+ if (CA_STATUS_OK != result )
+ {
+ OIC_LOG(ERROR, CA_MSG_PARSER_TAG, "Generate header failed");
+ return -1;
+ }
+
+ memcpy(*dataSegment, header, CA_HEADER_LENGTH);
+ OICFree(header);
+
+ memcpy(*dataSegment + CA_HEADER_LENGTH, data, length - CA_HEADER_LENGTH );
+ return length ;
+ }
+ else
+ {
+ OIC_LOG_V(DEBUG, CA_MSG_PARSER_TAG, "Appending actual data of length [%d]", length);
+
+ *dataSegment = (char *) OICMalloc(sizeof(char) * length);
+ memcpy(*dataSegment, data, length);
+ }
+
+ return length;
+
+}
+
+uint32_t CADeFragmentData(const char *datasegment, char **data, uint32_t TotalLen, uint32_t offset)
+{
+ OIC_LOG(DEBUG, CA_MSG_PARSER_TAG, "IN");
+
+ VERIFY_NON_NULL(*data, NULL, "Param data is NULL");
+
+ uint32_t length = 0;
+
+ memcpy(*data + offset, datasegment, strlen(datasegment));
+
+ length = TotalLen - offset;
+
+ if ( length < 0)
+ {
+ length = 0;
+ }
+
+ OIC_LOG(DEBUG, CA_MSG_PARSER_TAG, "OUT");
+
+ return length;
+
+}
+
+
+
--- /dev/null
+/******************************************************************
+*
+* 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.
+*
+******************************************************************/
+#include "caleadapter_singlethread.h"
+#include "caleserver.h"
+#include "logger.h"
+#include "caadapterutils.h"
+
+static CANetworkChangeCallback networkCallback = NULL;
+#define BLE_ADDRESS "DB:F7:EB:B5:0F:07"
+#define TAG "CALEADAPTER"
+
+/**
+ * @brief API to store the networkcallback passed from top layer, register BLE network notification
+ * @param net_callback - network notification callback
+ * @return - int
+ */
+int LERegisterNetworkNotifications(CANetworkChangeCallback netCallback);
+
+CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
+ CANetworkPacketReceivedCallback reqRespCallback, CANetworkChangeCallback netCallback)
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+ if (NULL == registerCallback || NULL == reqRespCallback || NULL == netCallback)
+ {
+ OIC_LOG(ERROR, TAG, "Invalid Parameter");
+ return CA_STATUS_INVALID_PARAM;
+ }
+
+ CASetBLEReqRescallback(reqRespCallback);
+ LERegisterNetworkNotifications(netCallback);
+ CAConnectivityHandler_t connHandler;
+ connHandler.startAdapter = NULL;
+ connHandler.startListenServer = CAStartLEListeningServer;
+ connHandler.startDiscoverServer = CAStartLEDiscoveryServer;
+ connHandler.sendData = CASendLEUnicastData;
+ connHandler.sendDataToAll = CASendLEMulticastData;
+ connHandler.GetnetInfo = CAGetLEInterfaceInformation;
+ connHandler.readData = CAReadLEData;
+ connHandler.terminate = CATerminateLE;
+ registerCallback(connHandler, CA_LE);
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return CA_STATUS_OK;
+}
+
+CAResult_t CAReadLEData()
+{
+ CAArduoinoCheckServerData();
+}
+
+void CATerminateLE()
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+ CASetBLEReqRescallback(NULL);
+ LERegisterNetworkNotifications(NULL);
+ CAStopBleGattServer();
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return;
+}
+CAResult_t CAStartLEListeningServer()
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+ CAInitializeBle();
+ CAArduoinoCheckServerData();
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return CA_STATUS_OK;
+}
+
+CAResult_t CAStartLEDiscoveryServer()
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return CA_STATUS_OK;
+}
+
+CAResult_t CAStartLENotifyServer()
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return CA_STATUS_OK;
+}
+
+uint32_t CASendLENotification(const CARemoteEndpoint_t *endpoint, void *data, uint32_t dataLen)
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return CA_STATUS_OK;
+}
+
+uint32_t CASendLEUnicastData(const CARemoteEndpoint_t *remoteEndpoint, void *data, uint32_t dataLen)
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+ if (NULL == remoteEndpoint)
+ {
+ OIC_LOG(ERROR, TAG, "Invalid Input Parameter");
+ return CA_STATUS_INVALID_PARAM;
+ }
+ char *tempPath = "a";
+ CAUpdateCharacteristicsInGattServer(tempPath, (char *)data, dataLen);
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return CA_STATUS_OK;
+}
+
+uint32_t CASendLEMulticastData(void *data, uint32_t dataLen)
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+ if (NULL == data || 0 == dataLen)
+ {
+ OIC_LOG(ERROR, TAG, "Invalid Parameter");
+ return CA_STATUS_INVALID_PARAM;
+ }
+ char *tempPath = "a";
+ CAUpdateCharacteristicsInGattServer(tempPath, (char *)data, dataLen);
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return CA_STATUS_OK;
+}
+
+CAResult_t CAGetLEInterfaceInformation(CALocalConnectivity_t **info, uint32_t *size)
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+
+ if (NULL == info || NULL == size)
+ {
+ OIC_LOG(DEBUG, TAG, "Invalid Parameter");
+ return CA_STATUS_INVALID_PARAM;
+ }
+
+ /**
+ * Create local endpoint using util function
+ */
+ (*info) = CAAdapterCreateLocalEndpoint(CA_LE, BLE_ADDRESS, "Le");
+ if (NULL == (*info))
+ {
+ OIC_LOG(DEBUG, TAG, "Out of memory");
+ return CA_MEMORY_ALLOC_FAILED;
+ }
+
+ (*size) = 1;
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return CA_STATUS_OK;
+}
+
+int LERegisterNetworkNotifications(CANetworkChangeCallback netCallback)
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+ networkCallback = netCallback;
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return CA_STATUS_OK;
+}
--- /dev/null
+/******************************************************************
+*
+* 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.
+*
+******************************************************************/
+
+#include "caleserver.h"
+#include <logger.h>
+#include "oic_malloc.h"
+#include <camsgparser.h>
+
+#define COAP_MAX_PDU_SIZE 320
+
+static CANetworkPacketReceivedCallback gRespCallback;
+static bool gServerRunning = false;
+static TimedAction gRcvAction = TimedAction(2000, CACheckData);
+static char *gCoapBuffer = NULL;
+static int32_t dataLen = 0;
+static uint16_t packetDataLen = 0;
+
+#define TAG "CLS"
+
+CAResult_t CAInitializeBle()
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+
+ // Set your BLE Shield name here, max. length 10
+ ble_set_name("SAMSUNG");
+
+ OIC_LOG(DEBUG, TAG, "BLE Name Set is completed");
+
+ ble_begin();
+ gRcvAction.enable();
+
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return CA_STATUS_OK;
+
+}
+
+void CANotifyCallback(void *data, int32_t dataLen, char *senderAdrs, int32_t senderPort)
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+ if (gRespCallback)
+ {
+
+ /* Cannot get Address as of now */
+ CARemoteEndpoint_t endPoint;
+ endPoint.resourceUri = ""; // will be filled by upper layer
+ endPoint.connectivityType = CA_LE;
+
+ gRespCallback(&endPoint, data, dataLen);
+ }
+ OIC_LOG(DEBUG, TAG, "OUT");
+}
+
+void CACheckData()
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+ dataLen = 0;
+ ble_do_events();
+
+ if (ble_available())
+ {
+ // Allocate Memory for COAP Buffer and do ParseHeader
+ if (NULL == gCoapBuffer)
+ {
+ OIC_LOG(DEBUG, TAG, "IN");
+ gCoapBuffer = (char *)OICMalloc(COAP_MAX_PDU_SIZE);
+ while (ble_available() && dataLen < 2)
+ {
+ gCoapBuffer[dataLen++] = (char)ble_read();
+ }
+
+ packetDataLen = CAParseHeader(gCoapBuffer);
+ OIC_LOG(DEBUG, TAG, "OUT");
+ memset(gCoapBuffer, 0, COAP_MAX_PDU_SIZE);
+ dataLen = 0;
+ }
+
+ OIC_LOG(DEBUG, TAG, "IN");
+ while (ble_available())
+ {
+ OIC_LOG(DEBUG, TAG, "Inside While loop");
+ gCoapBuffer[dataLen++] = (char)ble_read();
+ if (dataLen == packetDataLen)
+ {
+ OIC_LOG(DEBUG, TAG, "Read Comp BLE Pckt");
+ gCoapBuffer[dataLen] = '\0';
+ if (dataLen > 0)
+ {
+ OIC_LOG_V(DEBUG, TAG, "recv dataLen=%d", dataLen);
+ CANotifyCallback((void *)gCoapBuffer, dataLen, "", 0);
+ }
+ OICFree(gCoapBuffer);
+ gCoapBuffer = NULL;
+ break;
+ }
+ }
+ OIC_LOG(DEBUG, TAG, "OUT");
+ }
+ else
+ {
+ OIC_LOG(DEBUG, TAG, "No Data on BLE server");
+ }
+}
+
+void CAArduoinoCheckServerData()
+{
+ ble_do_events();
+ gRcvAction.check();
+}
+
+void CASetBLEReqRescallback(CANetworkPacketReceivedCallback callback)
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+ gRespCallback = callback;
+ OIC_LOG(DEBUG, TAG, "OUT");
+}
+
+CAResult_t CAStartBleGattServer()
+{
+ OIC_LOG(DEBUG, TAG, "IN");
+ // Done at time of setup i.e. in initializeBle api
+ gServerRunning = true;
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return CA_STATUS_OK;
+}
+CAResult_t CAStopBleGattServer()
+{
+ // Not Supported
+ return CA_STATUS_OK;
+}
+
+CAResult_t CAAddNewBleServiceInGattServer(const char *service_uuid)
+{
+ // Not Supported - Done at compile time
+ return CA_STATUS_OK;
+}
+
+CAResult_t CARemoveBleServiceFromGattServer(const char *svc_path)
+{
+ // Not Supported - Done at compile time
+ return CA_STATUS_OK;
+}
+
+CAResult_t CARemoveAllBleServicesFromGattServer()
+{
+ // Not Supported
+ return CA_STATUS_OK;
+}
+
+CAResult_t CARegisterBleServicewithGattServer(const char *svc_path)
+{
+ // Not Supported - Done at compile time
+ return CA_STATUS_OK;
+}
+
+CAResult_t CAAddNewCharacteristicsToGattServer(const char *svc_path, const char *char_uuid,
+ const char *char_value,
+ int char_value_len,
+ int read)
+{
+ // Not Supported - Done at compile time
+ return CA_STATUS_OK;
+}
+
+CAResult_t CARemoveCharacteristicsFromGattServer(const char *char_path)
+{
+ // Not Supported
+ return CA_STATUS_OK;
+}
+
+CAResult_t CAUpdateCharacteristicsInGattServer(const char *char_path,
+ const char *char_value, int value_length)
+{
+ // Only 1 characteristic will be used for sending data from server
+ OIC_LOG(DEBUG, TAG, "IN");
+
+ char *header = NULL;
+ header = (char *) OICMalloc(sizeof(char) * CA_HEADER_LENGTH);
+ memset(header, 0, sizeof(char) * CA_HEADER_LENGTH);
+ CAResult_t result = CAGenerateHeader(header, value_length);
+ if (CA_STATUS_OK != result)
+ {
+ return CA_STATUS_FAILED;
+ }
+ int index = 0;
+ if (ble_connected())
+ {
+ ble_write_bytes((unsigned char *)header, CA_HEADER_LENGTH);
+ int iter = value_length/CA_SUPPORTED_BLE_MTU_SIZE;
+
+ for (index = 0; index < iter; index++)
+ {
+ ble_write_bytes((unsigned char *)(char_value + (index * CA_SUPPORTED_BLE_MTU_SIZE)),
+ (unsigned char) CA_SUPPORTED_BLE_MTU_SIZE);
+ ble_do_events();
+ }
+
+ ble_write_bytes((unsigned char *)(char_value + (index * CA_SUPPORTED_BLE_MTU_SIZE)),
+ (unsigned char) value_length%CA_SUPPORTED_BLE_MTU_SIZE);
+ ble_do_events();
+ OIC_LOG(DEBUG, TAG,
+ "ble_write_bytes had been done");
+ }
+ else
+ {
+ OIC_LOG(DEBUG, TAG, "ble is not connected");
+ return CA_STATUS_FAILED;
+ }
+ OIC_LOG(DEBUG, TAG, "OUT");
+ return CA_STATUS_OK;
+}
--- /dev/null
+
+/******************************************************************
+*
+* 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.
+*
+******************************************************************/
+
+#ifndef _BLE_ADAPTER_ARDUINO_H_
+#define _BLE_ADAPTER_ARDUINO_H_
+
+
+#include <Arduino.h>
+#include <SPI.h>
+#include <boards.h>
+#include <RBL_nRF8001.h>
+#include <services.h>
+#include <TimedAction.h>
+
+#include "cacommon.h"
+#include "caadapterinterface.h"
+
+/**
+ * @brief API to initialize Arduino BLE module and advertise the service
+ * @return - int
+ */
+CAResult_t CAInitializeBle();
+
+/**
+ * @brief API to send received data to upper layer
+ * @param[in] data - data received from BLE characteristics
+ * @param[in] dataLen - received data Length
+ * @param[in] senderAdrs - sender Address.
+ * @param[in] senderPort - sender port
+ * @return - Error Code
+ */
+void CANotifyCallback(void *data, int32_t dataLen, char *senderAdrs, int32_t senderPort);
+
+/**
+ * @brief API to read the data from characteristics and invoke notifyCallback
+ * @return - void
+ */
+void CACheckData();
+
+/**
+ * @brief API to invoke CheckData at a regular interval of time.
+ * @return - void
+ */
+void CAArduoinoCheckServerData();
+
+/**
+ * @brief API to set request response callback to upper layer.
+ * @param[in] callback - upper layer callback function to pass the data received in the server.
+ * @return - Error Code
+ */
+void CASetBLEReqRescallback(CANetworkPacketReceivedCallback callback);
+
+/**
+ * @brief API to start Ble Gatt server.
+ * @return - Error Code
+ */
+CAResult_t CAStartBleGattServer();
+
+/**
+ * @brief API to stop Ble Gatt server.
+ * @param[in] serverID - unique identifier for each server.
+ * @return - Error Code
+ */
+CAResult_t CAStopBleGattServer();
+
+/**
+ * @brief API to add new service in Gatt Server
+ * @param[in] service_uuid - unique identifier for each service.
+ * @return - Error Code
+ */
+CAResult_t CAAddNewBleServiceInGattServer(const char *service_uuid);
+
+/**
+ * @brief API to remove the added service from Ble Gatt server.
+ * @param[in] svc_path - unique identifier for each service.
+ * @return - Error Code
+ */
+CAResult_t CARemoveBleServiceFromGattServer(const char *svc_path);
+
+/**
+ * @brief API to remove all the services from Ble Gatt server.
+ * @return - Error Code
+ */
+CAResult_t CARemoveAllBleServicesFromGattServer();
+
+/**
+ * @brief API to register service with GattService after adding the service.
+ * @param[in] svc_path - unique identifier for each service.
+ * @return - Error Code
+ */
+CAResult_t CARegisterBleServicewithGattServer(const char *svc_path);
+
+/**
+ * @brief API to add new characteristics to the service
+ * @param[in] svc_path service path to which this characteristic belongs to.
+ * @param[in] char_uuid Gatt characteristic uuid.
+ * @param[in] char_value Gatt characteristic value.
+ * @param[in] value_len Caracteristic value length.
+ * @param[in] char_flags Characteristic flags.
+ * @param[in] flags_length Caracteristic flags length.
+ * @param[out] char_path characteristic path registered on the interface.
+ * @return - Error Code
+ */
+CAResult_t CAAddNewCharacteristicsToGattServer(const char *svc_path, const char *char_uuid,
+ const char *char_value,
+ int char_value_len,
+ int read);
+
+/**
+ * @brief API to remove the characteristics.
+ * @param[in] char_path characteristic path registered on the interface and unique identifier for added characteristics.
+ * @return - Error Code
+ */
+CAResult_t CARemoveCharacteristicsFromGattServer(const char *char_path);
+
+/**
+ * @brief API to update the characteristic value from server side.
+ * @param[in] char_path characteristic path registered on the interface and unique identifier for added characteristics.
+ * @param[in] char_value Gatt characteristic value.
+ * @param[in] value_length Caracteristic value length.
+ * @return - Error Code
+ */
+CAResult_t CAUpdateCharacteristicsInGattServer(const char *char_path, const char *char_value,
+ int value_length);
+
+
+#endif //#ifndef _BLE_ADAPTER_ARDUINO_H_
coap_pdu_t *pdu;
uint32_t code = CA_NOT_FOUND;
- pdu = (coap_pdu_t *) CAParsePDU((const char *) data, &code);
+ pdu = (coap_pdu_t *) CAParsePDU((const char *) data,dataLen, &code);
//OICFree(data);
char uri[CA_MAX_URI_LENGTH] = { 0, };
static bool gServerRunning = false;
static TimedAction gRcvAction = TimedAction(3000, CACheckData);
+/**
+ * @var gUnicastPort
+ * @brief Unicast Port
+ */
+static int16_t gUnicastPort = 0;
+
// Retrieves a empty socket and bind it for UDP with the input port
/**
* @brief API to start unicast server.
return CA_STATUS_FAILED;
}
+ gUnicastPort = *port;
+ OIC_LOG_V(DEBUG, MOD_NAME, "gUnicastPort: %d", gUnicastPort);
+
// start thread to monitor socket here
if (!gServerRunning)
{
return CA_STATUS_OK;
}
-CAResult_t CAArduinoInitMulticastUdpSocket(const char *mcastAddress, const int16_t *port,
- int32_t *socketID)
+CAResult_t CAArduinoInitMulticastUdpSocket(const char *mcastAddress, const int16_t *mport,
+ const int16_t *lport, int32_t *socketID)
{
OIC_LOG(DEBUG, MOD_NAME, "IN");
VERIFY_NON_NULL(mcastAddress, MOD_NAME, "address");
VERIFY_NON_NULL(socketID, MOD_NAME, "socket");
- VERIFY_NON_NULL(port, MOD_NAME, "port");
+ VERIFY_NON_NULL(lport, MOD_NAME, "port");
+ VERIFY_NON_NULL(mport, MOD_NAME, "port");
uint8_t state;
uint8_t mcastMacAddr[] = { 0x01, 0x00, 0x5E, 0x00, 0x00, 0x00};
uint8_t ipAddr[4] = { 0 };
mcastMacAddr[5] = ipAddr[3];
W5100.writeSnDIPR(sockID, (uint8_t *)ipAddr);
W5100.writeSnDHAR(sockID, mcastMacAddr);
- W5100.writeSnDPORT(sockID, *port);
+ W5100.writeSnDPORT(sockID, *mport);
//Create a datagram socket on which to recv/send.
- if (!socket(sockID, SnMR::UDP, *port, SnMR::MULTI))
+ if (!socket(sockID, SnMR::UDP, *lport, SnMR::MULTI))
{
OIC_LOG(ERROR, MOD_NAME, "failed");
return CA_STATUS_FAILED;
const int16_t *port)
{
OIC_LOG(DEBUG, MOD_NAME, "IN");
- if (CAArduinoInitMulticastUdpSocket(mcastAddress, port, &gMulticastSocket) != CA_STATUS_OK)
+ if (CAArduinoInitMulticastUdpSocket(mcastAddress, port, port, &gMulticastSocket) != CA_STATUS_OK)
{
OIC_LOG(DEBUG, MOD_NAME, "failed");
return CA_STATUS_FAILED;
int16_t isMulticast)
{
OIC_LOG(DEBUG, MOD_NAME, "IN");
+ if(!isMulticast && 0 == gUnicastPort)
+ {
+ OIC_LOG(ERROR, MOD_NAME, "UnicastPort 0");
+ return 0;
+ }
+
int32_t socketID = 0;
if (isMulticast)
{
- if (CAArduinoInitMulticastUdpSocket(remoteIpAddress, &port, &socketID) != CA_STATUS_OK)
+ if (CAArduinoInitMulticastUdpSocket(remoteIpAddress, &port, &gUnicastPort, &socketID) != CA_STATUS_OK)
{
OIC_LOG(ERROR, MOD_NAME, "multicast");
return 0;
}
else
{
- if (CAArduinoInitUdpSocket((int16_t *)&port, &socketID) != CA_STATUS_OK)
+ if(0 == gUnicastSocket)
{
- OIC_LOG(ERROR, MOD_NAME, "unicast");
- return 0;
+ if (CAArduinoInitUdpSocket((int16_t *)&port, &socketID) != CA_STATUS_OK)
+ {
+ OIC_LOG(ERROR, MOD_NAME, "unicast");
+ return 0;
+ }
+ }
+ else
+ {
+ socketID = gUnicastSocket;
}
}
OIC_LOG(DEBUG, MOD_NAME, "OUT");
ret = sendto(sockFd, buf, bufLen, (uint8_t *)ipAddr, port);
delay(10);
- close(sockFd);
+ if(gUnicastSocket != sockFd)
+ {
+ close(sockFd);
+ }
+
OIC_LOG(DEBUG, MOD_NAME, "OUT");
return ret;
}
CAResult_t CAArduinoInitUdpSocket(int16_t *port, int32_t *socketID);
-CAResult_t CAArduinoInitMulticastUdpSocket(const char *mcastAddress, int16_t *port,
- int32_t *socketID);
+CAResult_t CAArduinoInitMulticastUdpSocket(const char *mcastAddress, const int16_t *mport,
+ const int16_t *lport, int32_t *socketID);
/**
* @brief API to start multicast server.