From: Ashok Channa Date: Wed, 4 Feb 2015 09:48:20 +0000 (+0900) Subject: Added connectivity files for full code review X-Git-Tag: 1.2.0+RC1~1855^2~117 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ec501972e17105287c868a34f452841f2ad1bb2a;p=platform%2Fupstream%2Fiotivity.git Added connectivity files for full code review Please comment on patch set 14 if any comments are not addressed from 1~13. NOTE: 1)Code Comments till Patch Set 13 are updated. 2)Please put your comments on new patch sets(at least from 13) and try to avoid on old patch sets as it difficult to review the old sets Modified CA source files for review comments. Updated documentation, return parameters with CAResult, optimization etc. Global variable naming conventions .. Change-Id: Id19ec37831ae46896b59007cdde07217b5d8696a Signed-off-by: Ashok Channa Reviewed-on: https://gerrit.iotivity.org/gerrit/193 Tested-by: jenkins-iotivity Reviewed-by: Patrick Lankswert --- diff --git a/resource/csdk/connectivity/RELEASE v0.7 b/resource/csdk/connectivity/RELEASE v0.7 index f7b33bb..d3669a2 100644 --- a/resource/csdk/connectivity/RELEASE v0.7 +++ b/resource/csdk/connectivity/RELEASE v0.7 @@ -22,7 +22,7 @@ Preconditions: 3)libcoap.a library ( do make @lib/libcoap-4.1.1) 4)tinyDTLS library for DTLS enabled applications( enable DTLS = 1 in makefile @connectivity\build/linux) 5)Ethernet, BLE, TimedActions, Timer libraries for arduino support. -6)scons for scon script compilation. +6)scons for scons script compilation. Scope of Release: 1. Supported APIs ( please check below APIs) @@ -93,4 +93,5 @@ Client: Server side: n for network selection (WIFI enabled by default) How to Build for Linux/DTLS: -sudo ./sample.sh WITH_DTLS @@connectivity\samples\linux +./sample.sh WITH_DTLS @@connectivity\samples\linux + diff --git a/resource/csdk/connectivity/api/cacommon.h b/resource/csdk/connectivity/api/cacommon.h index 708f534..ad30ccc 100644 --- a/resource/csdk/connectivity/api/cacommon.h +++ b/resource/csdk/connectivity/api/cacommon.h @@ -28,7 +28,7 @@ #include #include - +#include #ifdef __cplusplus @@ -52,14 +52,27 @@ extern "C" #define CA_MAX_HEADER_OPTION_DATA_LENGTH 16 /** +* @brief Max token length +*/ +#define CA_MAX_TOKEN_LEN (8) + +/** * @brief Max URI length */ -#define CA_MAX_URI_LENGTH 2048 +#ifdef ARDUINO +#define CA_MAX_URI_LENGTH 128 /* maximum size of URI for embedded platforms*/ +#else +#define CA_MAX_URI_LENGTH 512 /* maximum size of URI for other platforms*/ +#endif /** - * @brief Max token length + * @brief Max PDU length supported */ -#define CA_MAX_TOKEN_LEN (8) +#ifdef ARDUINO +#define COAP_MAX_PDU_SIZE 320 /* maximum size of a CoAP PDU for embedded platforms*/ +#else +#define COAP_MAX_PDU_SIZE 1400 /* maximum size of a CoAP PDU for big platforms*/ +#endif /** * @brief option types - the highest option number 63 @@ -67,6 +80,7 @@ extern "C" #define CA_OPTION_IF_MATCH 1 #define CA_OPTION_ETAG 4 #define CA_OPTION_IF_NONE_MATCH 5 +#define CA_OPTION_OBSERVE 6 #define CA_OPTION_LOCATION_PATH 8 #define CA_OPTION_URI_PATH 11 #define CA_OPTION_CONTENT_FORMAT 12 @@ -75,7 +89,6 @@ extern "C" #define CA_OPTION_URI_QUERY 15 #define CA_OPTION_ACCEPT 17 #define CA_OPTION_LOCATION_QUERY 20 -#define CA_OPTION_OBSERVE 6 /** * @brief Payload information from resource model @@ -93,16 +106,6 @@ typedef char *CAURI_t; typedef char *CAToken_t; /** - * @enum CABool_t - * @brief Boolean value used for specifying the success or failure - */ -typedef enum -{ - CA_FALSE = 0, /**< False */ - CA_TRUE /**< True */ -} CABool_t; - -/** * @enum CAConnectivityType_t * @brief Different connectivities that are handled in Connectivity Abstraction */ @@ -120,8 +123,8 @@ typedef enum */ typedef enum { - CA_INTERFACE_UP, /**< Connection is Available */ - CA_INTERFACE_DOWN /**< Connection is not available */ + CA_INTERFACE_DOWN, /**< Connection is not available */ + CA_INTERFACE_UP /**< Connection is Available */ } CANetworkStatus_t; /** @@ -151,7 +154,7 @@ typedef union struct { char ipAddress[CA_IPADDR_SIZE]; /**< Ip address of the interface**/ - uint32_t port; /**< port information**/ + uint16_t port; /**< port information**/ } IP; } CAAddress_t; @@ -164,7 +167,8 @@ typedef enum CA_MSG_CONFIRM = 0, /**< confirmable message (requires ACK/RST) */ CA_MSG_NONCONFIRM, /**< non-confirmable message (one-shot message) */ CA_MSG_ACKNOWLEDGE, /**< used to acknowledge confirmable messages */ - CA_MSG_RESET /**< indicates error in received messages */ + CA_MSG_RESET /**< used to indicates not-interested or error (lack of context)in + received messages */ } CAMessageType_t; /** @@ -188,7 +192,7 @@ typedef struct CAURI_t resourceUri; /**< Resource URI information **/ CAAddress_t addressInfo; /**< Remote Endpoint address **/ CAConnectivityType_t connectivityType; /**< Connectivity of the endpoint**/ - CABool_t isSecured; /**< Secure connection**/ + bool isSecured; /**< Secure connection**/ } CARemoteEndpoint_t; @@ -207,8 +211,8 @@ typedef struct typedef struct { CAAddress_t addressInfo; /**< Address of the interface **/ - CAConnectivityType_t type; /**< Connectivity type that localconnectivity avaialble **/ - CABool_t isSecured; /**< Secure connection**/ + CAConnectivityType_t type; /**< Connectivity of local device **/ + bool isSecured; /**< Secure connection**/ } CALocalConnectivity_t; /** @@ -230,8 +234,8 @@ typedef enum CA_MEMORY_ALLOC_FAILED, /**< Memory allocation failed */ CA_REQUEST_TIMEOUT, /**< Request is Timeout */ CA_DESTINATION_DISCONNECTED, /**< Destination is disconnected */ - CA_STATUS_FAILED, /**< Failure */ - CA_NOT_SUPPORTED /**< Not supported */ + CA_NOT_SUPPORTED, /**< Not supported */ + CA_STATUS_FAILED =255 /**< Failure */ /* Result code - END HERE */ } CAResult_t; @@ -245,11 +249,10 @@ typedef enum CA_SUCCESS = 200, /**< Success */ CA_CREATED = 201, /**< Created */ CA_DELETED = 202, /**< Deleted */ - CA_EMPTY = 231, /**< Empty */ CA_BAD_REQ = 400, /**< Bad Request */ CA_BAD_OPT = 402, /**< Bad Option */ CA_NOT_FOUND = 404, /**< Not found */ - CA_RETRANSMIT_TIMEOUT = 531 /**< Retransmit timeout */ + CA_RETRANSMIT_TIMEOUT = 500 /**< Retransmit timeout */ /* Response status code - END HERE */ } CAResponseResult_t; @@ -269,8 +272,8 @@ typedef enum */ typedef enum { - CA_ADAPTER_ENABLED, /**< Adapter is Enabled */ - CA_ADAPTER_DISABLED /**< Adapter is Disabled */ + CA_ADAPTER_DISABLED, /**< Adapter is Disabled */ + CA_ADAPTER_ENABLED /**< Adapter is Enabled */ } CAAdapterState_t; /** @@ -294,10 +297,11 @@ typedef struct */ typedef struct { + + CAMessageType_t type; /**< Qos for the request */ uint16_t messageId; /**< Message id. * if message id is zero, it will generated by CA inside. * otherwise, you can use it */ - CAMessageType_t type; /**< Qos for the request */ CAToken_t token; /**< Token for CA */ CAHeaderOption_t *options; /** Header Options for the request */ uint8_t numOptions; /**< Number of Header options */ @@ -322,8 +326,8 @@ typedef struct */ typedef struct { - CAInfo_t info; /**< Information of the response */ CAResponseResult_t result; /**< Result for response by resource model */ + CAInfo_t info; /**< Information of the response */ } CAResponseInfo_t; #ifdef __cplusplus @@ -331,3 +335,4 @@ typedef struct #endif #endif //#ifndef __CA_COMMON_H_ + diff --git a/resource/csdk/connectivity/api/cainterface.h b/resource/csdk/connectivity/api/cainterface.h index 5689fb5..f84f139 100644 --- a/resource/csdk/connectivity/api/cainterface.h +++ b/resource/csdk/connectivity/api/cainterface.h @@ -27,7 +27,7 @@ #define __CA_INTERFACE_H_ /** - * Connectivity Abstraction Interface Description APIs. + * Connectivity Abstraction Interface APIs. */ #include "cacommon.h" @@ -107,6 +107,7 @@ CAResult_t CAStartDiscoveryServer(); * @param RespHandler [IN] Response Handler Callback * @see CARequestCallback * @see CAResponseCallback + * @return NONE */ void CARegisterHandler(CARequestCallback ReqHandler, CAResponseCallback RespHandler); @@ -179,7 +180,7 @@ CAResult_t CAFindResource(const CAURI_t resourceUri, const CAToken_t token); * @param requestInfo [IN] Information for the request. * @return #CA_STATUS_OK #CA_STATUS_FAILED #CA_MEMORY_ALLOC_FAILED */ -CAResult_t CASendRequest(const CARemoteEndpoint_t *object, CARequestInfo_t *requestInfo); +CAResult_t CASendRequest(const CARemoteEndpoint_t *object,const CARequestInfo_t *requestInfo); /** * @brief Send control Request on a resource to multicast group @@ -198,7 +199,8 @@ CAResult_t CASendRequestToAll(const CAGroupEndpoint_t *object, * @param responseInfo [IN] Information for the response * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED */ -CAResult_t CASendResponse(const CARemoteEndpoint_t *object, CAResponseInfo_t *responseInfo); +CAResult_t CASendResponse(const CARemoteEndpoint_t *object, + const CAResponseInfo_t *responseInfo); /** * @brief Send notification to the remote object @@ -208,18 +210,18 @@ CAResult_t CASendResponse(const CARemoteEndpoint_t *object, CAResponseInfo_t *re * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED */ CAResult_t CASendNotification(const CARemoteEndpoint_t *object, - CAResponseInfo_t *responseInfo); + const CAResponseInfo_t *responseInfo); /** * @brief To advertise the resource - * @param resourceUri [IN] URI to be advertised - * @param token [IN] Token for the request - * @param options [IN] Header options information - * @param numOptions [IN] Number of options + * @param resourceUri [IN] URI to be advertised + * @param token [IN] Token for the request + * @param options [IN] Header options information + * @param numOptions [IN] Number of options * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_MEMORY_ALLOC_FAILED */ -CAResult_t CAAdvertiseResource(const CAURI_t resourceUri, CAToken_t token, - CAHeaderOption_t *options, uint8_t numOptions); +CAResult_t CAAdvertiseResource(const CAURI_t resourceUri,const CAToken_t token, + const CAHeaderOption_t *options,const uint8_t numOptions); /** * @brief Select network to use @@ -240,7 +242,8 @@ CAResult_t CAUnSelectNetwork(const uint32_t nonInterestedNetwork); * It should be destroyed by the caller as it Get Information. * @param info [OUT] LocalConnectivity objects * @param size [OUT] No Of Array objects - * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_STATUS_INVALID_PARAM or #CA_MEMORY_ALLOC_FAILED + * @return #CA_STATUS_OK or #CA_STATUS_FAILED or #CA_STATUS_INVALID_PARAM or +* #CA_MEMORY_ALLOC_FAILED */ CAResult_t CAGetNetworkInformation(CALocalConnectivity_t **info, uint32_t *size); @@ -255,3 +258,4 @@ CAResult_t CAHandleRequestResponse(); #endif #endif + diff --git a/resource/csdk/connectivity/build/How_To_Build.txt b/resource/csdk/connectivity/build/How_To_Build.txt index d69465a..ebe81e5 100644 --- a/resource/csdk/connectivity/build/How_To_Build.txt +++ b/resource/csdk/connectivity/build/How_To_Build.txt @@ -1,4 +1,4 @@ -=== Pre requites === +=== Prerequisites === * 1. Scons @@ -31,7 +31,7 @@ Linux Build: 3) The above command will build sample also. - For Enabling Secured server, + For Enabling Secured server, * Note: tinydtls library has to copied to "connectivity/lib/tinydtls" for secured build. Secured Server will be only used for WIFI and ETHERNET transports. @@ -121,3 +121,4 @@ Note :- Currently only megaADK build is supported. By Default DEVICE_NAME=OIC-DEVICE, if device name option is not specified To change the port number, please modify "port" variable in __upload() function in: "/build/arduino/SConscript". + diff --git a/resource/csdk/connectivity/build/Makefile b/resource/csdk/connectivity/build/Makefile index a7cbc33..b0a6197 100644 --- a/resource/csdk/connectivity/build/Makefile +++ b/resource/csdk/connectivity/build/Makefile @@ -52,7 +52,11 @@ install: clean: sh arduino/build.sh clean + else $(info *********error**********) $(error Wrong value for PLATFORM !!) endif + + + diff --git a/resource/csdk/connectivity/build/SConscript b/resource/csdk/connectivity/build/SConscript index 4c76a53..55eb3c6 100644 --- a/resource/csdk/connectivity/build/SConscript +++ b/resource/csdk/connectivity/build/SConscript @@ -48,7 +48,10 @@ target_arch = ARGUMENTS.get('TARGET_ARCH', default_arch) # target arch # True if binary needs to be installed on board. (Might need root permissions) # set to 'no', 'false' or 0 for only compilation -require_upload = ARGUMENTS.get('UPLOAD', True) +require_upload = ARGUMENTS.get('UPLOAD', True) + +# Get the device name +device_name = ARGUMENTS.get('DEVICE_NAME', "OIC-DEVICE") ###################################################################### # Common build options (release, target os, target arch) @@ -61,6 +64,9 @@ help_vars.Add(EnumVariable('TARGET_ARCH', 'Target architecture', default_arch, o help_vars.Add(EnumVariable('SECURED', 'Build with DTLS', '0', allowed_values=('0', '1'))) help_vars.Add(BoolVariable('UPLOAD', 'Upload binary ? (For Arduino)', require_upload)) help_vars.Add(EnumVariable('BUILD_SAMPLE', 'Build with sample', 'ON', allowed_values=('ON', 'OFF'))) + +help_vars.AddVariables(('DEVICE_NAME', 'Network display name for device', 'OIC-DEVICE', None, None),) + ###################################################################### # Platform(build target) specific options: SDK/NDK & toolchain ###################################################################### @@ -82,9 +88,7 @@ else: Help(help_vars.GenerateHelpText(env)) -# Get the device name and set it to __OIC_DEVICE_NAME__ -device_name = ARGUMENTS.get('DEVICE_NAME', "OIC-DEVICE") -print device_name +# Set device name to __OIC_DEVICE_NAME__ env.AppendUnique(CPPDEFINES = ['-D__OIC_DEVICE_NAME__=' + "\'\"" + device_name + "\"\'"]) tc_set_msg = ''' @@ -187,8 +191,8 @@ Export('env') ###################################################################### if target_os == "yocto": ''' - This code injects Yocto cross-compilation tools+flags into scons' - build environment in order to invoke the relevant tools while + This code injects Yocto cross-compilation tools+flags into scons' + build environment in order to invoke the relevant tools while performing a build. ''' import os.path @@ -250,3 +254,4 @@ if env.GetOption('clean'): Execute(Delete(dir + '/.sconf_temp')) Return('env') + diff --git a/resource/csdk/connectivity/build/android/README.txt b/resource/csdk/connectivity/build/android/README.txt index 5f93b9f..b890949 100644 --- a/resource/csdk/connectivity/build/android/README.txt +++ b/resource/csdk/connectivity/build/android/README.txt @@ -1,7 +1,9 @@ Compiling Interface APIs FOR Android: =================================== •Preconditons : - Please download the glibc directory and keep $(CA_HOME)\lib\android\glib-master + Please download the following + 1) glib directory and keep at $(CA_HOME)/lib/android/glib-2.40.2 + 2) tinydlts library and keep at $(CA_HOME)/lib/tinydtls •Supported version : 5.0 ( Lollipop ) •Required NDK version : android-ndk-r10d ( https://developer.android.com/tools/sdk/ndk/index.html ) • Modify Makefile ( connectivity/build/android/Makefile ) @@ -13,3 +15,4 @@ Compiling Interface APIs FOR Android: $ cd ${CA_HOME}/connectivity/build/android $ ndk-build clean; ndk-build + diff --git a/resource/csdk/connectivity/build/android/SConscript b/resource/csdk/connectivity/build/android/SConscript index a5fabf9..7a70b4a 100644 --- a/resource/csdk/connectivity/build/android/SConscript +++ b/resource/csdk/connectivity/build/android/SConscript @@ -155,14 +155,16 @@ else: env.AppendUnique(CCFLAGS = ['-g']) env.AppendUnique(CPPDEFINES = ['WITH_POSIX', '__ANDROID__','-DTB_LOG']) -env.AppendUnique(CCFLAGS = ['-Wall', '-fPIC']) -env.AppendUnique(LINKFLAGS = ['-ldl', '-lpthread', '-llog', '-landroid']) +env.AppendUnique(CCFLAGS = ['-Wall', '-fPIC','`pkg-config','--cflags','glib-2.0`']) +env.AppendUnique(LINKFLAGS = ['-ldl', '-lpthread', '-lglib-2.0', '-lgthread-2.0', '-llog', '-landroid']) -env.ParseConfig("pkg-config --cflags --libs glib-2.0 gthread-2.0") +env.Append(LIBS=[ + '-lglib-2.0', '-lgthread-2.0' +]) # From android-5 (API > 20), all application must be built with flags '-fPIE' '-pie'. # Due to the limitation of Scons, it's required to added it into the command line # directly (otherwise, it will also be added when build share library) env.Replace(CCCOM = '$CC -o $TARGET -c $CFLAGS $CCFLAGS $_CCCOMCOM -fPIE $SOURCES') env.Replace(CXXCOM = '$CXX -o $TARGET -c $CXXFLAGS $CCFLAGS $_CCCOMCOM -fPIE $SOURCES') -env.Replace(LINKCOM = '$LINK -o $TARGET -pie $LINKFLAGS $__RPATH $SOURCES $_LIBDIRFLAGS $_LIBFLAGS') \ No newline at end of file +env.Replace(LINKCOM = '$LINK -o $TARGET -pie $LINKFLAGS $__RPATH $SOURCES $_LIBDIRFLAGS $_LIBFLAGS') diff --git a/resource/csdk/connectivity/build/android/jni/Android.mk b/resource/csdk/connectivity/build/android/jni/Android.mk index 95ff806..9d4f9e8 100644 --- a/resource/csdk/connectivity/build/android/jni/Android.mk +++ b/resource/csdk/connectivity/build/android/jni/Android.mk @@ -14,20 +14,20 @@ DTLS_LIB = $(PROJECT_LIB_PATH)/tinydtls #Modify below values to enable/disable the Adapter #Suffix "NO_" to disable given adapter -EDR = EDR_ADAPTER +EDR = EDR_ADAPTER WIFI = WIFI_ADAPTER -LE = LE_ADAPTER +LE = LE_ADAPTER ETHERNET = NO_ETHERNET_ADAPTER #Add Pre processor definitions DEFINE_FLAG = -DWITH_POSIX -D__ANDROID__ -D__WITH_DTLS__ -DEFINE_FLAG += -D$(EDR) -D$(LE) -D$(WIFI) -D$(ETHERNET) +DEFINE_FLAG += -D$(EDR) -D$(LE) -D$(WIFI) -D$(ETHERNET) #Add Debug flags here DEBUG_FLAG = -DTB_LOG #DEBUG_FLAG += -DADB_SHELL -BUILD_FLAG.debug = $(DEFINE_FLAG) $(DEBUG_FLAG) +BUILD_FLAG.debug = $(DEFINE_FLAG) $(DEBUG_FLAG) BUILD_FLAG.release = $(DEFINE_FLAG) BUILD_FLAG = $(BUILD_FLAG.$(BUILD)) @@ -146,3 +146,4 @@ LOCAL_SRC_FILES = \ $(WIFI_ADAPTER_PATH)/cawificlient.c $(WIFI_ADAPTER_PATH)/cawifinwmonitor.c \ include $(BUILD_STATIC_LIBRARY) + diff --git a/resource/csdk/connectivity/build/android/jni/Application.mk b/resource/csdk/connectivity/build/android/jni/Application.mk index 2ffa027..588be6d 100644 --- a/resource/csdk/connectivity/build/android/jni/Application.mk +++ b/resource/csdk/connectivity/build/android/jni/Application.mk @@ -6,4 +6,4 @@ APP_MODULES := CA APP_PLATFORM = android-19 APP_CPPFLAGS += -fexceptions APP_CPPFLAGS += -frtti += -Wno-error=format-security -APP_CFLAGS = -Wno-error=format-security \ No newline at end of file +APP_CFLAGS = -Wno-error=format-security diff --git a/resource/csdk/connectivity/build/arduino/Arduino_Setup_README.txt b/resource/csdk/connectivity/build/arduino/Arduino_Setup_README.txt index ea1caaa..3f1cc0e 100644 --- a/resource/csdk/connectivity/build/arduino/Arduino_Setup_README.txt +++ b/resource/csdk/connectivity/build/arduino/Arduino_Setup_README.txt @@ -1,31 +1,51 @@ STEPS to setup Arduino on linux machine for building CA code: -1) Download the Arduino package as per your system specification from the given link : +1) Download the Arduino package as per your system specification from the given link : http://arduino.cc/en/main/software - + 2) Unzip the downloaded package to some location say ARDUINO_DIR(This is the arduino installation directory). ARDUINO_DIR = /arduino-1.5.x -3) Change permissions for executable in "ARDUINO_DIR" - chmod -R +x ./* - -4) ONE TIME ONLY - ADDITIONAL LIBRARIES +3) Change permissions for executable in your "ARDUINO_DIR" + chmod -R +x + +4.1) ONE TIME ONLY - ADDITIONAL LIBRARIES (Time) Arduino builds are dependent on latest Time library. Download it from here: I. http://playground.arduino.cc/Code/Time - Place this library in the "ARDUINO_DIR/libraries/Time" folder where remaining libraries are present. - [P.S - The Time library files path should be as follows "ARDUINO_DIR/libraries/Time/Time/{***files***}"] - + Place this library in the "ARDUINO_DIR/libraries/Time" folder where other libraries are present. + [P.S - The Time library files path should be as follows "ARDUINO_DIR/libraries/Time/Time/{***files***}"] + Some files in this library has windows style line endings, for patch to run properly, please execute following command: + cd + find ./libraries/Time/ -type f -exec dos2unix {} \; + +4.2) ONE TIME ONLY - ADDITIONAL LIBRARIES (BLE) + Note: Prior to building for BLE Transport, following additional steps are required: + (1) Download RedBearLab Arduino RBL_nRF8001 Library from link(https://github.com/RedBearLab/nRF8001/tree/25643e7b1b7da3740406325a471e3faa4b948747) + (2) Extract zip file and apply RBL patch(connectivity/lib/arduino/RBL_nRF8001.patch) to "RBL_nRF8001" folder by following below steps, + i) Go to downloaded RBL_Library Folder ("nRF8001-master/Arduino/libraries/RBL_nRF8001") + ii) Apply dos2unix for RBL_Library Folder and RBL Patch File (RBL_nRF8001.patch), if we have downloaded Library in Non UNIX Platform. + iii) Apply RBL Patch by using the below command + patch -p1 < RBL_Patch_File_Location(RBL_nRF8001.patch) + (3) Copy the patched RBL_nRF8001 Library and place it in "arduino-/libraries" folder + (4) Download Nordic Arduino BLE library [Tag: "0.9.5.Beta" Version] from the link (https://github.com/NordicSemiconductor/ble-sdk-arduino). + Extract the zip file and copy the "BLE" folder available under "libraries" folder and place it in "arduino-/libraries" folder + 5) ONE TIME ONLY - PATCH Complete patch has been provided at : "connectivity\lib\arduino\arduino_libraries.patch" - Copy this patch file to "ARDUINO_DIR/libraries/" - -6) To apply patch give the command : + Copy this patch file to "ARDUINO_DIR/" + +6) To apply patch give the command : patch -p1 < arduino_libraries.patch To undo the patch give the command : patch -R -p1 < arduino_libraries.patch - -7) Launch Arduino IDE (required for logs and port and board selection.) + +7) ONE TIME ONLY - FIRMWARE UPGRADE (FOR WIFI SHIELD) + To support UDP over WiFi, WiFi shield needs to run latest firmware. Please refer: + (http://arduino.cc/en/Hacking/WiFiShieldFirmwareUpgrading) + for instructions on how to upgrade your firmware. + +8) Launch Arduino IDE (required for logs and port and board selection.) Goto to "ARDUINO_DIR" directory. Launch command := sudo ./arduino - -8) Select your board and port under the tools option in Arduino IDE. \ No newline at end of file + +9) Select your board and port under the tools option in Arduino IDE. diff --git a/resource/csdk/connectivity/build/arduino/Makefile b/resource/csdk/connectivity/build/arduino/Makefile index 46d418a..7524a33 100644 --- a/resource/csdk/connectivity/build/arduino/Makefile +++ b/resource/csdk/connectivity/build/arduino/Makefile @@ -9,7 +9,7 @@ BUILD := release PLATFORM := arduinomega TRANSPORT := BLE OBJ_DIR := ./bin -APP_NAME := sample_main +APP_NAME := casample ARDUINO_PORT := ttyACM0 include ./local.properties @@ -72,3 +72,4 @@ clean: + diff --git a/resource/csdk/connectivity/build/arduino/README.txt b/resource/csdk/connectivity/build/arduino/README.txt index d756d51..17bff7d 100644 --- a/resource/csdk/connectivity/build/arduino/README.txt +++ b/resource/csdk/connectivity/build/arduino/README.txt @@ -1,10 +1,3 @@ -Setting Wi-Fi SSID and Password for Arduino Wi-FI Shield -===================================== -PreCondition: In connectivity\src\wifi_adapter\arduino\cawifiserver.cpp -Update the SSID and Password credentials before testing with Wi-Fi Shield -char ssid[] = ""; // your network SSID (name) -char pass[] = ""; // your network password - BUILDING for ARDUINOMEGA: ======================================== PREREQ: Arduino MUST be installed in the machine where we compile. Refer to Arduino_Setup_README file for help. @@ -14,17 +7,6 @@ PREREQ: Arduino MUST be installed in the machine where we compile. Refer to Ardu sudo make PLATFORM=arduinomega TRANSPORT= ARDUINO_DIR = /arduino-1.5.x P.S : For PATH_TO_ARDUINO_INSTALL_DIR value refer Arduino_Setup_README.txt file. -Note: Prior to building for BLE Transport, following additional steps are required: -1) Download RedBearLab Arduino RBL_nRF8001 Library committed (2014/7/30 18:17:53) from link(https://github.com/RedBearLab/nRF8001) -2) Extract zip file and apply RBL patch(connectivity/lib/arduino/RBL_nRF8001.patch) to "RBL_nRF8001" folder by following below steps, - i) Go to downloaded RBL_Library Folder ("nRF8001-master/Arduino/libraries/RBL_nRF8001") - ii) Apply dos2unix for RBL_Library Folder and RBL Patch File (RBL_nRF8001.patch), if we have downloaded Library in Non UNIX Platform. - iii) Apply RBL Patch by using the below command - patch -p1 < RBL Patch File Location(RBL_nRF8001.patch) -3) Copy the patched RBL_nRF8001 Library and place it in "arduino-/libraries" folder -4) Download Nordic Arduino BLE library from the link (https://github.com/NordicSemiconductor/ble-sdk-arduino). - Extract the zip file and copy the "BLE" folder available under "libraries" folder and place it in "arduino-/libraries" folder - Flashing Interface APIs for ARDUINOMEGA: ======================================== Precondition: Connect Arduino Mega Board to Linux PC. Open Arduino IDE and select corresponding connected PORT @@ -33,6 +15,6 @@ Precondition: Connect Arduino Mega Board to Linux PC. Open Arduino IDE and selec It will flash BLE Transport Adaptor in Arduino Board. Similarly, TRANSPORT can be changed to ETHERNET, BLE, WIFI etc.. To Run Adapter code in ARDUINOMEGA Board: -======================================== +======================================== PreCondition: Flash the executable in ARDUINO MEGA BOARD. Follow above Step(Flashing Interface APIs for ARDUINOMEGA) -1) Open Serial Monitor in Arduino IDE. It will execute the flashed binary and logs will be available in serial Monitor under BaudRate(115200) \ No newline at end of file +1) Open Serial Monitor in Arduino IDE. It will execute the flashed binary and logs will be available in serial Monitor under BaudRate(115200) diff --git a/resource/csdk/connectivity/build/arduino/SConscript b/resource/csdk/connectivity/build/arduino/SConscript index c10446b..227cb09 100644 --- a/resource/csdk/connectivity/build/arduino/SConscript +++ b/resource/csdk/connectivity/build/arduino/SConscript @@ -71,7 +71,7 @@ def __search_files(path, pattern, ondisk=True, source=True, strings=False, recur matches = [] for root, dirnames, filenames in os.walk(path): #BLE library examples throw lot of errors. We dont need examples. - if 'examples' not in root: + if 'examples' not in root: matches.extend(Glob(root + '/' + pattern, ondisk, source, strings)) return matches @@ -413,3 +413,4 @@ env.AddMethod(__import_lib, "ImportLib") #import arduino library env.AddMethod(__create_bin, "CreateBin") #create binary files(.eep and .hex) env.AddMethod(__upload, "Upload") #Upload binary to board env.AddMethod(__upload_help, "UploadHelp") #print the command line that to upload binary to the boardf + diff --git a/resource/csdk/connectivity/build/arduino/arduino.scons b/resource/csdk/connectivity/build/arduino/arduino.scons index 15093ae..911712b 100644 --- a/resource/csdk/connectivity/build/arduino/arduino.scons +++ b/resource/csdk/connectivity/build/arduino/arduino.scons @@ -10,7 +10,7 @@ if 'WIFI' in env.get('TARGET_TRANSPORT'): env.ImportLib('WiFi') if 'BLE' in env.get('TARGET_TRANSPORT'): env.ImportLib('BLE') - env.ImportLib('RBL_nRF8001') + env.ImportLib('RBL_nRF8001') env.ImportLib('Time/Time') # we have variety of macros for arduino!! diff --git a/resource/csdk/connectivity/build/arduino/arduinomega.properties b/resource/csdk/connectivity/build/arduino/arduinomega.properties index 7b9da1d..9d55105 100644 --- a/resource/csdk/connectivity/build/arduino/arduinomega.properties +++ b/resource/csdk/connectivity/build/arduino/arduinomega.properties @@ -52,7 +52,7 @@ ifeq ($(TRANSPORT),ETHERNET) -I$(INCD_ARD_TIME) -I$(IDIR_ARD_SPI) \ -I$(INCD_ARD_BASE1) -I$(INCD_ARD_BASE2) -I$(INCD_ARD_BASE3) \ -I$(INCD_ARD_BASE4) -I$(IDIR_ARD_ETH) -I$(IDIR_ARD_ETH_UTIL) \ - -I$(IDIR_ARD_ETH1) + -I$(IDIR_ARD_ETH1) else ifeq ($(TRANSPORT),WIFI) IDIR_ARD_WIFI = $(ARDUINO_DIR)/libraries/WiFi/src IDIR_ARD_WIFI_UTIL = $(ARDUINO_DIR)/libraries/WiFi/src/utility @@ -60,8 +60,8 @@ else ifeq ($(TRANSPORT),WIFI) -I$(INCD_ARD_TIME) -I$(IDIR_ARD_SPI) \ -I$(INCD_ARD_BASE1) -I$(INCD_ARD_BASE2) -I$(INCD_ARD_BASE3) \ -I$(INCD_ARD_BASE4) -I$(IDIR_ARD_ETH_UTIL) -I$(IDIR_ARD_WIFI) \ - -I$(IDIR_ARD_WIFI_UTIL) -else ifeq ($(TRANSPORT),BLE) + -I$(IDIR_ARD_WIFI_UTIL) +else ifeq ($(TRANSPORT),BLE) IDIR_ARD_BLE = $(ARDUINO_DIR)/libraries/BLE IDIR_ARD_RBL = $(ARDUINO_DIR)/libraries/RBL_nRF8001 INCD_ARD_BLE1 = $(BASE_DIR)/src/bt_le_adapter/arduino/ @@ -97,7 +97,7 @@ SPI_OBJ = SPI.cpp.o LOGGER_OBJ = logger.c.o oic_logger.c.o oic_console_logger.c.o oic_malloc.c.o oic_string.c.o uarraylist.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_singlethread.c.o \ - caremotehandler.c.o caretransmission_singlethread.cpp.o + caremotehandler.c.o caretransmission_singlethread.c.o ifeq ($(TRANSPORT),ETHERNET) ETH_CPPOBJ = Dhcp.o Dns.o Ethernet.o EthernetUdp.o EthernetClient.o @@ -105,16 +105,17 @@ ifeq ($(TRANSPORT),ETHERNET) INTERFACE_OBJ = caethernetadapterutils.cpp.o caethernetclient.cpp.o caethernetserver.cpp.o caethernetnwmonitor.cpp.o caethernetadapter_singlethread.c.o PLATFORM_OBJS = $(CORE_COBJ) $(CORE_CPPOBJ) $(SPI_OBJ) $(LOGGER_OBJ) $(INTERFACE_OBJ) $(ETH_CPPOBJ) $(ETH_UTIL_CPPOBJ) $(UTIL_OBJ) $(CACOMMON_OBJ) else ifeq ($(TRANSPORT),WIFI) - WIFI_CPPOBJ = WiFi.cpp.o WiFiClient.cpp.o WiFiServer.cpp.o WiFiUdp.cpp.o + WIFI_CPPOBJ = WiFi.cpp.o WiFiClient.cpp.o WiFiServer.cpp.o WiFiUdp.cpp.o WIFI_UTIL_CPPOBJ = server_drv.cpp.o spi_drv.cpp.o wifi_drv.cpp.o INTERFACE_OBJ = cawificlient.cpp.o cawifiserver.cpp.o cawifinwmonitor.cpp.o cawifiadapter_singlethread.c.o PLATFORM_OBJS = $(CORE_COBJ) $(CORE_CPPOBJ) $(SPI_OBJ) $(LOGGER_OBJ) $(INTERFACE_OBJ) $(WIFI_CPPOBJ) $(WIFI_UTIL_CPPOBJ) $(UTIL_OBJ) $(CACOMMON_OBJ) -else ifeq ($(TRANSPORT),BLE) +else ifeq ($(TRANSPORT),BLE) 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_singlethread.c.o cableserver.cpp.o cablenwmonitor.cpp.o - PLATFORM_OBJS = $(CORE_COBJ) $(CORE_CPPOBJ) $(SPI_OBJ) $(LOGGER_OBJ) $(INTERFACE_OBJ) $(BLE_OBJ) $(RBL_OBJ) $(UTIL_OBJ) $(CACOMMON_OBJ) + PLATFORM_OBJS = $(CORE_COBJ) $(CORE_CPPOBJ) $(SPI_OBJ) $(LOGGER_OBJ) $(INTERFACE_OBJ) $(BLE_OBJ) $(RBL_OBJ) $(UTIL_OBJ) $(CACOMMON_OBJ) else $(info *********error**********) $(error Wrong value for TRANSPORT !!) endif + diff --git a/resource/csdk/connectivity/build/arduino/build.sh b/resource/csdk/connectivity/build/arduino/build.sh index ffac7cf..ccedb4c 100644 --- a/resource/csdk/connectivity/build/arduino/build.sh +++ b/resource/csdk/connectivity/build/arduino/build.sh @@ -18,4 +18,4 @@ make $1 -f makefile_arduino.mak PLATFORM=$2 ARDUINO_DIR=$4 cd ../../build/arduino/ make $1 PLATFORM=$2 TRANSPORT=$3 ARDUINO_DIR=$4 APP_NAME=$5 fi -fi +fi \ No newline at end of file diff --git a/resource/csdk/connectivity/build/arduino/local.properties b/resource/csdk/connectivity/build/arduino/local.properties index e318153..633e822 100644 --- a/resource/csdk/connectivity/build/arduino/local.properties +++ b/resource/csdk/connectivity/build/arduino/local.properties @@ -1,2 +1,3 @@ ARDUINO_DIR = /usr/share/arduino ARDUINO_TOOLS_DIR = $(ARDUINO_DIR)/hardware/tools/avr/bin + diff --git a/resource/csdk/connectivity/build/common.mk b/resource/csdk/connectivity/build/common.mk index 187d2e1..858dda1 100644 --- a/resource/csdk/connectivity/build/common.mk +++ b/resource/csdk/connectivity/build/common.mk @@ -24,14 +24,14 @@ SHELL = /bin/bash PROJECT_NAME = connectivity_abstraction PROJECT_ROOT_PATH = .. -PROJECT_API_PATH = $(PROJECT_ROOT_PATH)/api -PROJECT_INC_PATH = $(PROJECT_ROOT_PATH)/inc +PROJECT_API_PATH = $(PROJECT_ROOT_PATH)/api +PROJECT_INC_PATH = $(PROJECT_ROOT_PATH)/inc PROJECT_SRC_PATH = $(PROJECT_ROOT_PATH)/src -PROJECT_COMMON_INC_PATH = $(PROJECT_ROOT_PATH)/common/inc -PROJECT_COMMON_SRC_PATH = $(PROJECT_ROOT_PATH)/common/src -PROJECT_COMMON_PATH = $(PROJECT_ROOT_PATH)/common +PROJECT_COMMON_INC_PATH = $(PROJECT_ROOT_PATH)/common/inc +PROJECT_COMMON_SRC_PATH = $(PROJECT_ROOT_PATH)/common/src +PROJECT_COMMON_PATH = $(PROJECT_ROOT_PATH)/common PROJECT_OUT_PATH = $(PROJECT_ROOT_PATH)/build/out -PROJECT_LIB_PATH = $(PROJECT_ROOT_PATH)/lib +PROJECT_LIB_PATH = $(PROJECT_ROOT_PATH)/lib ## ## macro @@ -57,3 +57,4 @@ LN = ln CD = cd RANLIB = ranlib + diff --git a/resource/csdk/connectivity/build/linux/Makefile b/resource/csdk/connectivity/build/linux/Makefile index 6756615..3fcaeab 100644 --- a/resource/csdk/connectivity/build/linux/Makefile +++ b/resource/csdk/connectivity/build/linux/Makefile @@ -81,8 +81,8 @@ libtiny_lib_dir = $(PROJECT_LIB_PATH)/extlibs/tinydtls LDFLAGS := -L$(libcoap_build_dir) -L$(libtiny_lib_dir) LDLIBS := -lcoap -ltinydtls else -LDFLAGS := -L$(libcoap_build_dir) -LDLIBS := -lcoap +LDFLAGS := -L$(libcoap_build_dir) +LDLIBS := -lcoap endif BUILD_FLAG.debug = $(DEFINE_FLAG) $(DEBUG_FLAG) @@ -185,3 +185,4 @@ endef .PHONY: all clean install + diff --git a/resource/csdk/connectivity/build/linux/SConscript b/resource/csdk/connectivity/build/linux/SConscript index 4421aaa..2233a72 100644 --- a/resource/csdk/connectivity/build/linux/SConscript +++ b/resource/csdk/connectivity/build/linux/SConscript @@ -13,7 +13,7 @@ if env.get('RELEASE'): else: env.AppendUnique(CCFLAGS = ['-g']) env.AppendUnique(CPPDEFINES = ['-DTB_LOG']) - + env.AppendUnique(CPPDEFINES = ['WITH_POSIX', '__linux__']) env.AppendUnique(CCFLAGS = ['-Wall', '-fPIC']) env.AppendUnique(LINKFLAGS = ['-ldl', '-lpthread']) diff --git a/resource/csdk/connectivity/build/linux/common.mk b/resource/csdk/connectivity/build/linux/common.mk index 3207f83..3d8e139 100644 --- a/resource/csdk/connectivity/build/linux/common.mk +++ b/resource/csdk/connectivity/build/linux/common.mk @@ -58,3 +58,4 @@ LN = ln CD = cd RANLIB = ranlib + diff --git a/resource/csdk/connectivity/build/tizen/Makefile b/resource/csdk/connectivity/build/tizen/Makefile index ceda5c8..8e56590 100644 --- a/resource/csdk/connectivity/build/tizen/Makefile +++ b/resource/csdk/connectivity/build/tizen/Makefile @@ -62,3 +62,4 @@ clean: rm -f *.o *.d *.elf *.eep core.a *.hex *.bin *.map *- rm -rf $(OBJ_DIR) rm -rf $(LIBCOAP_OBJ_DIR) + diff --git a/resource/csdk/connectivity/build/tizen/SConscript b/resource/csdk/connectivity/build/tizen/SConscript index 675c931..3c72392 100644 --- a/resource/csdk/connectivity/build/tizen/SConscript +++ b/resource/csdk/connectivity/build/tizen/SConscript @@ -238,3 +238,4 @@ if env.GetOption('clean'): Execute(Delete(dir + '/.sconf_temp')) Return('env') + diff --git a/resource/csdk/connectivity/build/tizen/com.oic.ca.manifest b/resource/csdk/connectivity/build/tizen/com.oic.ca.manifest new file mode 100644 index 0000000..c26f59d --- /dev/null +++ b/resource/csdk/connectivity/build/tizen/com.oic.ca.manifest @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/resource/csdk/connectivity/build/tizen/com.oic.ca.pc b/resource/csdk/connectivity/build/tizen/com.oic.ca.pc index 6d4239b..fbfa187 100644 --- a/resource/csdk/connectivity/build/tizen/com.oic.ca.pc +++ b/resource/csdk/connectivity/build/tizen/com.oic.ca.pc @@ -1,9 +1,10 @@ prefix=/usr exec_prefix=${prefix} libdir=${prefix}/lib -includedir=${prefix}/include/interfaceHeaders +includedir=${prefix}/include/OICHeaders -Name: com.oic.ca +Name: com-oic-ca Description: Oic core library Version: 1.0 Cflags: -I${includedir} + diff --git a/resource/csdk/connectivity/build/tizen/gbsbuild.sh b/resource/csdk/connectivity/build/tizen/gbsbuild.sh index afb1ad2..385fe5b 100644 --- a/resource/csdk/connectivity/build/tizen/gbsbuild.sh +++ b/resource/csdk/connectivity/build/tizen/gbsbuild.sh @@ -93,3 +93,4 @@ fi cd $sourcedir rm -rf $sourcedir/tmp + diff --git a/resource/csdk/connectivity/build/tizen/packaging/com.oic.ca.spec b/resource/csdk/connectivity/build/tizen/packaging/com.oic.ca.spec index c9b956f..cea0eb1 100644 --- a/resource/csdk/connectivity/build/tizen/packaging/com.oic.ca.spec +++ b/resource/csdk/connectivity/build/tizen/packaging/com.oic.ca.spec @@ -1,18 +1,16 @@ %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 +%define DEST_INC_DIR %{buildroot}/%{_includedir}/OICHeaders +%define DEST_LIB_DIR %{buildroot}/%{_libdir} -Name: com.oic.ca +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: Apache License, Version 2.0 -Group: OIC/Application -#BuildRequires: cmake +License: Apache-2.0 +Group: Applications/OIC BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(capi-network-wifi) @@ -22,7 +20,7 @@ BuildRequires: boost-thread BuildRequires: boost-system BuildRequires: boost-filesystem BuildRequires: scons -#BuildRequires: oic-core + %description SLP oicca application @@ -39,17 +37,11 @@ scons TARGET_OS=tizen -c scons TARGET_OS=tizen TARGET_TRANSPORT=%{TARGET_TRANSPORT} RELEASE=%{RELEASE} %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.oic.ca/bin/ -mkdir -p %{buildroot}/usr/lib mkdir -p %{DEST_INC_DIR} mkdir -p %{DEST_LIB_DIR}/pkgconfig -cp -rf %{ROOTDIR}/con/src/libconnectivity_abstraction.a %{buildroot}/usr/lib -cp -rf %{ROOTDIR}/con/lib/libcoap-4.1.1/libcoap.a %{buildroot}/usr/lib +cp -f %{ROOTDIR}/con/src/libconnectivity_abstraction.a %{buildroot}/%{_libdir} +cp -f %{ROOTDIR}/con/lib/libcoap-4.1.1/libcoap.a %{buildroot}/%{_libdir} 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}/ @@ -62,8 +54,9 @@ cp -rf %{ROOTDIR}/com.oic.ca.pc %{DEST_LIB_DIR}/pkgconfig/ %files +%manifest com.oic.ca.manifest %defattr(-,root,root,-) -%attr(-,inhouse,inhouse) %{_libdir}/lib*.a* -%{_includedir}/interfaceHeaders/* +%{_includedir}/OICHeaders/* %{_libdir}/pkgconfig/*.pc + diff --git a/resource/csdk/connectivity/build/tizen/scons/SConscript b/resource/csdk/connectivity/build/tizen/scons/SConscript index 14042a2..fc6df2b 100644 --- a/resource/csdk/connectivity/build/tizen/scons/SConscript +++ b/resource/csdk/connectivity/build/tizen/scons/SConscript @@ -16,7 +16,6 @@ else: env.AppendUnique(CFLAGS = ['-std=c99', '-fPIC', '-D__TIZEN__','-DWITH_POSIX', '-Wall', '-DSLP_SDK_LOG', '-g','-D_GNU_SOURCE','-DTIZEN_DEBUG_ENABLE', '-DTB_LOG']) env.ParseConfig("pkg-config --cflags --libs capi-network-wifi dlog glib-2.0") - if 'ALL' in transport: env.AppendUnique(CPPDEFINES = ['WIFI_ADAPTER', 'NO_ETHERNET_ADAPTER','EDR_ADAPTER','LE_ADAPTER']) print "CA Transport is ALL" diff --git a/resource/csdk/connectivity/common/SConscript b/resource/csdk/connectivity/common/SConscript index 4bf6cb1..0747421 100644 --- a/resource/csdk/connectivity/common/SConscript +++ b/resource/csdk/connectivity/common/SConscript @@ -19,7 +19,7 @@ temp = env['CPPPATH'] header = ' ' for item in temp: header = header + ' -I' + item - + ###################################################################### # Source files and Target(s) ###################################################################### @@ -29,9 +29,9 @@ ca_common_src = [ ca_common_src_path + 'uarraylist.c', ca_common_src_path + 'uqueue.c', ] - + if ca_os == 'arduino': - env.Command(env.get('BUILD_DIR') + 'logger.c', None, '$CXX -o ' + env.get('BUILD_DIR') + 'logger.c' + ' $LINKFLAGS $CCFLAGS $CXXFLAGS ' + header + ' ' + 'common/src/logger.c') + env.Command(env.get('BUILD_DIR') + 'logger.c.o', None, '$CXX -o ' + env.get('BUILD_DIR') + 'logger.c.o' + ' $LINKFLAGS $CCFLAGS $CXXFLAGS ' + header + ' ' + 'common/src/logger.c') platform_src = [ env.get('BUILD_DIR') + 'logger.c.o', ] diff --git a/resource/csdk/connectivity/common/inc/logger.h b/resource/csdk/connectivity/common/inc/logger.h index 53ae94d..fab9daa 100644 --- a/resource/csdk/connectivity/common/inc/logger.h +++ b/resource/csdk/connectivity/common/inc/logger.h @@ -139,7 +139,8 @@ void OICLogInit(); * @param tag - Module name * @param logStr - log string */ -void OICLog(LogLevel level, PROGMEM const char *tag, const int16_t lineNum, PROGMEM const char *logStr); +void OICLog(LogLevel level, PROGMEM const char *tag, const int16_t lineNum, + PROGMEM const char *logStr); /** * Output the contents of the specified buffer (in hex) with the specified priority level. @@ -158,7 +159,8 @@ void OICLogBuffer(LogLevel level, const char *tag, const uint8_t *buffer, uint16 * @param tag - Module name * @param format - variadic log string */ -void OICLogv(LogLevel level, PROGMEM const char *tag, const int16_t lineNum, PROGMEM const char *format, ...); +void OICLogv(LogLevel level, PROGMEM const char *tag, const int16_t lineNum, + PROGMEM const char *format, ...); #endif #ifdef TB_LOG @@ -210,3 +212,4 @@ void OICLogv(LogLevel level, PROGMEM const char *tag, const int16_t lineNum, PRO } #endif // __cplusplus #endif /* _U_LOGGER_H_ */ + diff --git a/resource/csdk/connectivity/common/inc/oic_console_logger.h b/resource/csdk/connectivity/common/inc/oic_console_logger.h index 6ff5894..ac0374d 100644 --- a/resource/csdk/connectivity/common/inc/oic_console_logger.h +++ b/resource/csdk/connectivity/common/inc/oic_console_logger.h @@ -42,3 +42,4 @@ int oic_console_logger_set_module(oic_log_ctx_t *ctx, const char *module_name); #endif #endif + diff --git a/resource/csdk/connectivity/common/inc/oic_logger.h b/resource/csdk/connectivity/common/inc/oic_logger.h index 2488b9d..9e1cbc3 100644 --- a/resource/csdk/connectivity/common/inc/oic_logger.h +++ b/resource/csdk/connectivity/common/inc/oic_logger.h @@ -30,8 +30,9 @@ extern "C" /* Basic interface: */ oic_log_ctx_t *oic_log_make_ctx(void *world, const oic_log_level level, oic_log_init_t init, - oic_log_destroy_t destroy, oic_log_flush_t flush, oic_log_set_level_t set_level, - oic_log_write_level_t write_level, oic_log_set_module_t set_module); + oic_log_destroy_t destroy, oic_log_flush_t flush, + oic_log_set_level_t set_level,oic_log_write_level_t write_level, + oic_log_set_module_t set_module); void oic_log_destroy(oic_log_ctx_t *ctx); @@ -46,3 +47,4 @@ int oic_log_set_module(oic_log_ctx_t *ctx, const char *module_name); #endif #endif + diff --git a/resource/csdk/connectivity/common/inc/oic_logger_types.h b/resource/csdk/connectivity/common/inc/oic_logger_types.h index f02dc11..8271f1d 100644 --- a/resource/csdk/connectivity/common/inc/oic_logger_types.h +++ b/resource/csdk/connectivity/common/inc/oic_logger_types.h @@ -84,3 +84,4 @@ typedef int (*oic_log_try_lock_t)(oic_log_ctx_t *); #endif #endif + diff --git a/resource/csdk/connectivity/common/inc/oic_malloc.h b/resource/csdk/connectivity/common/inc/oic_malloc.h index ae06f14..be614af 100644 --- a/resource/csdk/connectivity/common/inc/oic_malloc.h +++ b/resource/csdk/connectivity/common/inc/oic_malloc.h @@ -68,6 +68,19 @@ extern "C" void *OICMalloc(size_t size); /** + * Allocates a block of memory for an array of num elements, each of them + * size bytes long and initializes all its bits to zero. + * + * @param num - The number of elements + * @param size - Size of the element type in bytes, where size > 0 + * + * @return + * on success, a pointer to the allocated memory block + * on failure, a null pointer is returned + */ +void *OICCalloc(size_t num, size_t size); + +/** * Deallocate a block of memory previously allocated by a call to OCMalloc * * NOTE: This function is intended to be used internally by the TB Stack. @@ -82,3 +95,4 @@ void OICFree(void *ptr); } #endif // __cplusplus #endif /* _OIC_MALLOC_H_ */ + diff --git a/resource/csdk/connectivity/common/inc/oic_string.h b/resource/csdk/connectivity/common/inc/oic_string.h index 771e741..3f830f2 100644 --- a/resource/csdk/connectivity/common/inc/oic_string.h +++ b/resource/csdk/connectivity/common/inc/oic_string.h @@ -20,14 +20,11 @@ #ifndef _OIC_STRING_H_ #define _OIC_STRING_H_ -#include -#include -#include "oic_malloc.h" - #ifdef __cplusplus extern "C" { #endif // __cplusplus + /** * Duplicates the source string and returns it. * @@ -44,4 +41,6 @@ char *OICStrdup(const char *str); #ifdef __cplusplus } #endif // __cplusplus -#endif /* _OIC_STRING_H_ */ +#endif +/* _OIC_STRING_H_ */ + diff --git a/resource/csdk/connectivity/common/inc/uarraylist.h b/resource/csdk/connectivity/common/inc/uarraylist.h index 1f28dca..245c195 100644 --- a/resource/csdk/connectivity/common/inc/uarraylist.h +++ b/resource/csdk/connectivity/common/inc/uarraylist.h @@ -30,11 +30,6 @@ extern "C" #endif /** - * Use this default size when initialized - */ -#define U_ARRAYLIST_DEFAULT_SIZE 1 - -/** * @struct u_arraylist_t * @brief array list structure */ @@ -53,10 +48,11 @@ u_arraylist_t *u_arraylist_create(); /** * @brief Resets and deletes the array list - * application should free the memory of data in array list + * Arraylist elements are deleted. Calling function must take care of free + * dynamic memory allocated before freeing the arraylist * @param list- u_arraylist pointer * @return CAResult_t - * CA_STATUS_OK if Success, CA_STATUS_FAILED otherwise + * CA_STATUS_OK if Success, CA_STATUS_INVALID_PARAM if pointer to list is NULL */ CAResult_t u_arraylist_free(u_arraylist_t **list); @@ -66,7 +62,7 @@ CAResult_t u_arraylist_free(u_arraylist_t **list); * [IN] pointer of array list * @param index * [IN] index of array list - * @return void pointer of the data + * @return void pointer of data if success or NULL pointer otherwise */ void *u_arraylist_get(const u_arraylist_t *list, uint32_t index); @@ -77,7 +73,7 @@ void *u_arraylist_get(const u_arraylist_t *list, uint32_t index); * @param data * [IN] pointer of data * @return CAResult_t - * CA_STATUS_OK if Success, CA_STATUS_FAILED otherwise + * CA_STATUS_OK if Success, CA_MEMORY_ALLOC_FAILED if memory allocation fails */ CAResult_t u_arraylist_add(u_arraylist_t *list, void *data); @@ -87,7 +83,7 @@ CAResult_t u_arraylist_add(u_arraylist_t *list, void *data); * [IN] pointer of array list * @param index * [IN] index of array list - * @return void pointer of the data + * @return void pointer of the data if success or NULL pointer otherwise */ void *u_arraylist_remove(u_arraylist_t *list, uint32_t index); @@ -105,9 +101,9 @@ uint32_t u_arraylist_length(const u_arraylist_t *list); * [IN] pointer of array list * @param data * [IN] pointer of data - * @return 1 if exists, 0 otherwise + * @return true if exists, false otherwise */ -uint8_t u_arraylist_contains(const u_arraylist_t *list, void *data); +bool u_arraylist_contains(const u_arraylist_t *list,const void *data); #ifdef __cplusplus } diff --git a/resource/csdk/connectivity/common/inc/umutex.h b/resource/csdk/connectivity/common/inc/umutex.h index 93459f0..f1277a0 100644 --- a/resource/csdk/connectivity/common/inc/umutex.h +++ b/resource/csdk/connectivity/common/inc/umutex.h @@ -24,11 +24,6 @@ #ifndef __UMUTEX_H_ #define __UMUTEX_H_ -#include -#include -#include -#include - #include "cacommon.h" #ifdef __cplusplus @@ -40,19 +35,11 @@ typedef void *u_mutex; typedef void *u_cond; /** - * @fn u_mutex_init - * @brief Initializes the thread system for using other mutex related APIs - * - */ -void u_mutex_init(void); - -/** * @fn u_mutex_new * @brief Creates new mutex * * @return Reference to newly created mutex, otherwise NULL. * - * @see u_mutex_Init */ u_mutex u_mutex_new(void); @@ -71,10 +58,10 @@ void u_mutex_lock(u_mutex mutex); * * @param mutex The mutex to be locked * - * @return CA_TRUE if the mutex is not locked currently, otherwise CA_FALSE. + * @return true if the mutex is not locked currently, otherwise false. * */ -CABool_t u_mutex_trylock(u_mutex mutex); +bool u_mutex_trylock(u_mutex mutex); /** * @fn u_mutex_unlock @@ -100,7 +87,6 @@ void u_mutex_free(u_mutex mutex); * * @return Reference to newly created @u_cond, otherwise NULL. * - * @see u_mutex_Init */ u_cond u_cond_new(void); @@ -124,7 +110,7 @@ void u_cond_broadcast(u_cond cond); /** * @fn u_cond_wait - * @brief Waits untill this thread woken up on @cond + * @brief Waits until this thread woken up on @cond * * @param cond The condtion to be wait for to signal * @param mutex The mutex which is currently locked from calling thread @@ -134,17 +120,17 @@ void u_cond_wait(u_cond cond, u_mutex mutex); /** * @fn u_cond_wait - * @brief Waits untill this thread woken up on @cond, - * but not longer than until the time specified by milliseconds. + * @brief Waits until this thread woken up on @cond, + * but not longer than until the time specified by microseconds. * The mutex is unlocked before falling asleep and locked again before resuming. - * If milliseconds is 0 or under, u_cond_timed_wait() acts like u_cond_wait(). + * If microseconds is 0 or under, u_cond_wait_until() acts like u_cond_wait(). * * @param cond The condtion to be wait for to signal * @param mutex The mutex which is currently locked from calling thread * @param microseconds relative time for waiting, microseconds * */ -void u_cond_timed_wait(u_cond cond, u_mutex mutex, int32_t microseconds); +void u_cond_wait_until(u_cond cond, u_mutex mutex, int32_t microseconds); /** * @fn u_cond_free @@ -159,4 +145,5 @@ void u_cond_free(u_cond cond); } /* extern "C" */ #endif /* __cplusplus */ -#endif //__UMUTEX_H_ +#endif /*__UMUTEX_H_ */ + diff --git a/resource/csdk/connectivity/common/inc/uqueue.h b/resource/csdk/connectivity/common/inc/uqueue.h index 7832214..d3c12f9 100644 --- a/resource/csdk/connectivity/common/inc/uqueue.h +++ b/resource/csdk/connectivity/common/inc/uqueue.h @@ -116,9 +116,8 @@ CAResult_t u_queue_remove_element(u_queue_t *queue); /** * @fn u_queue_get_size - * Returns number of elements in queue - * Input : queue - pointer to queue - * Return : number of elements in queue + * @param queue - pointer to queue + * @return number of elements in queue */ uint32_t u_queue_get_size(u_queue_t *queue); @@ -145,3 +144,4 @@ u_queue_message_t *u_queue_get_head(u_queue_t *queue); #endif /* __cplusplus */ #endif /* _U_QUEUE_H_ */ + diff --git a/resource/csdk/connectivity/common/inc/uthreadpool.h b/resource/csdk/connectivity/common/inc/uthreadpool.h index 57d1a96..09fd660 100644 --- a/resource/csdk/connectivity/common/inc/uthreadpool.h +++ b/resource/csdk/connectivity/common/inc/uthreadpool.h @@ -24,8 +24,6 @@ #ifndef __UTHREAD_POOL_H_ #define __UTHREAD_POOL_H_ -#include -#include #include #include "cacommon.h" @@ -70,13 +68,13 @@ CAResult_t u_thread_pool_init(uint32_t num_of_threads, u_thread_pool_t *thread_p * This function adds a routine to be executed by the thread pool at some future time. * * @param thread_pool The thread pool structure. - * @param routine The routine to be executed. + * @param method The routine to be executed. * @param data The data to be passed to the routine. * * @return CA_STATUS_OK on success. * @return Error on failure. */ -CAResult_t u_thread_pool_add_task(u_thread_pool_t thread_pool, void (*routine)(void *), +CAResult_t u_thread_pool_add_task(u_thread_pool_t thread_pool, u_thread_func method, void *data); /** @@ -92,3 +90,4 @@ void u_thread_pool_free(u_thread_pool_t thread_pool); #endif /* __cplusplus */ #endif /* __UTHREAD_POOL_H_ */ + diff --git a/resource/csdk/connectivity/common/src/logger.c b/resource/csdk/connectivity/common/src/logger.c index 8e58cd8..d6e9109 100644 --- a/resource/csdk/connectivity/common/src/logger.c +++ b/resource/csdk/connectivity/common/src/logger.c @@ -273,7 +273,8 @@ void OICLogInit() * @param tag - Module name * @param logStr - log string */ -void OICLog(LogLevel level, PROGMEM const char *tag, const int16_t lineNum, PROGMEM const char *logStr) +void OICLog(LogLevel level, PROGMEM const char *tag, const int16_t lineNum, + PROGMEM const char *logStr) { if (!logStr || !tag) { @@ -308,7 +309,8 @@ void OICLog(LogLevel level, PROGMEM const char *tag, const int16_t lineNum, PROG * @param tag - Module name * @param format - variadic log string */ -void OICLogv(LogLevel level, PROGMEM const char *tag, const int16_t lineNum, PROGMEM const char *format, ...) +void OICLogv(LogLevel level, PROGMEM const char *tag, const int16_t lineNum, + PROGMEM const char *format, ...) { char buffer[LINE_BUFFER_SIZE]; va_list ap; @@ -387,3 +389,4 @@ void OICLogv(LogLevel level, const char *tag, const __FlashStringHelper *format, } #endif //ARDUINO + diff --git a/resource/csdk/connectivity/common/src/oic_console_logger.c b/resource/csdk/connectivity/common/src/oic_console_logger.c index 40a24d5..bbad2c1 100644 --- a/resource/csdk/connectivity/common/src/oic_console_logger.c +++ b/resource/csdk/connectivity/common/src/oic_console_logger.c @@ -32,8 +32,8 @@ typedef struct oic_log_ctx_t *oic_make_console_logger() { return oic_log_make_ctx(NULL, OIC_LOG_ALL, oic_console_logger_init, oic_console_logger_destroy, - oic_console_logger_flush, oic_console_logger_set_level, oic_console_logger_write, - oic_console_logger_set_module); + oic_console_logger_flush, oic_console_logger_set_level, + oic_console_logger_write,oic_console_logger_set_module); } int oic_console_logger_init(oic_log_ctx_t *ctx, void *world) @@ -91,3 +91,4 @@ int oic_console_logger_set_module(oic_log_ctx_t *ctx, const char *module_name) /* We don't do anything special when the module name changes: */ return 1; } + diff --git a/resource/csdk/connectivity/common/src/oic_logger.c b/resource/csdk/connectivity/common/src/oic_logger.c index 2dc48d5..46106c6 100644 --- a/resource/csdk/connectivity/common/src/oic_logger.c +++ b/resource/csdk/connectivity/common/src/oic_logger.c @@ -24,8 +24,9 @@ #include oic_log_ctx_t *oic_log_make_ctx(void *world, const oic_log_level level, oic_log_init_t init, - oic_log_destroy_t destroy, oic_log_flush_t flush, oic_log_set_level_t set_level, - oic_log_write_level_t write_level, oic_log_set_module_t set_module) + oic_log_destroy_t destroy, oic_log_flush_t flush, + oic_log_set_level_t set_level,oic_log_write_level_t write_level, + oic_log_set_module_t set_module) { oic_log_ctx_t *log_ctx; @@ -150,3 +151,4 @@ int oic_log_set_module(oic_log_ctx_t *ctx, const char *module_name) return ctx->set_module(ctx, ctx->module_name); } + diff --git a/resource/csdk/connectivity/common/src/oic_malloc.c b/resource/csdk/connectivity/common/src/oic_malloc.c index ab9e52e..40b7363 100644 --- a/resource/csdk/connectivity/common/src/oic_malloc.c +++ b/resource/csdk/connectivity/common/src/oic_malloc.c @@ -80,6 +80,24 @@ void *OICMalloc(size_t size) #endif } +void *OICCalloc(size_t num, size_t size) +{ + if(0 == size || 0 == num) + { + return NULL; + } + +#ifdef ENABLE_MALLOC_DEBUG + void *ptr = 0; + + ptr = calloc(num, size); + OIC_LOG_V(INFO, TAG, "calloc: ptr=%p, num=%u, size=%u", ptr, num, size); + return ptr; +#else + return calloc(num, size); +#endif +} + void OICFree(void *ptr) { #ifdef ENABLE_MALLOC_DEBUG @@ -89,3 +107,4 @@ void OICFree(void *ptr) free(ptr); } + diff --git a/resource/csdk/connectivity/common/src/oic_string.c b/resource/csdk/connectivity/common/src/oic_string.c index b75a4ff..199b6f6 100644 --- a/resource/csdk/connectivity/common/src/oic_string.c +++ b/resource/csdk/connectivity/common/src/oic_string.c @@ -19,6 +19,9 @@ ******************************************************************/ #include "oic_string.h" +#include +#include "oic_malloc.h" + char *OICStrdup(const char *str) { // Allocate memory for original string length and 1 extra byte for '\0' @@ -26,8 +29,8 @@ char *OICStrdup(const char *str) char *dup = (char *)OICMalloc(length + 1); if (NULL != dup) { - memcpy(dup, str, length); - dup[length] = '\0'; + memcpy(dup, str, length + 1); } return dup; } + diff --git a/resource/csdk/connectivity/common/src/uarraylist.c b/resource/csdk/connectivity/common/src/uarraylist.c index f1425e8..7c569d4 100644 --- a/resource/csdk/connectivity/common/src/uarraylist.c +++ b/resource/csdk/connectivity/common/src/uarraylist.c @@ -26,11 +26,17 @@ #define TAG "UARRAYLIST" +/** + * Use this default size when initialized + */ +#define U_ARRAYLIST_DEFAULT_SIZE 1 + u_arraylist_t *u_arraylist_create() { u_arraylist_t *list = NULL; - if (!(list = (u_arraylist_t *) OICMalloc(sizeof(u_arraylist_t)))) + list = (u_arraylist_t *) OICMalloc(sizeof(u_arraylist_t)); + if (!list) { return NULL; } @@ -38,7 +44,8 @@ u_arraylist_t *u_arraylist_create() list->size = U_ARRAYLIST_DEFAULT_SIZE; list->length = 0; - if (!(list->data = (void *) OICMalloc(list->size * sizeof(void *)))) + list->data = (void *) OICMalloc(list->size * sizeof(void *)); + if (!list->data) { OIC_LOG(DEBUG, TAG, "Out of memory"); OICFree(list); @@ -49,8 +56,10 @@ u_arraylist_t *u_arraylist_create() CAResult_t u_arraylist_free(u_arraylist_t **list) { - if (*list == NULL) + if (!list || !(*list)) + { return CA_STATUS_INVALID_PARAM; + } OICFree((*list)->data); OICFree(*list); @@ -62,12 +71,12 @@ CAResult_t u_arraylist_free(u_arraylist_t **list) void *u_arraylist_get(const u_arraylist_t *list, uint32_t index) { - if (index >= list->length) + if (!list ) { return NULL; } - if (list->data) + if ((index < list->length) && (list->data)) { return list->data[index]; } @@ -77,18 +86,21 @@ void *u_arraylist_get(const u_arraylist_t *list, uint32_t index) CAResult_t u_arraylist_add(u_arraylist_t *list, void *data) { - uint32_t new_size = 0; + if (!list) + { + return CA_STATUS_INVALID_PARAM; + } if (list->size <= list->length) { - new_size = list->size + 1; + uint32_t new_size = list->size + 1; if (!(list->data = (void **) realloc(list->data, new_size * sizeof(void *)))) { return CA_MEMORY_ALLOC_FAILED; } - (void) memset(list->data + list->size, 0, (new_size - list->size) * sizeof(void *)); + memset(list->data + list->size, 0, (new_size - list->size) * sizeof(void *)); list->size = new_size; } @@ -102,6 +114,11 @@ void *u_arraylist_remove(u_arraylist_t *list, uint32_t index) { void *removed = NULL; + if (!list) + { + return NULL; + } + if (index >= list->length) { return NULL; @@ -131,7 +148,7 @@ void *u_arraylist_remove(u_arraylist_t *list, uint32_t index) uint32_t u_arraylist_length(const u_arraylist_t *list) { - if (NULL == list) + if (!list) { OIC_LOG(DEBUG, TAG, "Invalid Parameter"); return 0; @@ -139,22 +156,26 @@ uint32_t u_arraylist_length(const u_arraylist_t *list) return list->length; } -uint8_t u_arraylist_contains(const u_arraylist_t *list, void *data) +bool u_arraylist_contains(const u_arraylist_t *list,const void *data) { uint32_t i = 0; - for (i = 0; i < u_arraylist_length(list); i++) + if (!list) + { + return false; + } + + uint32_t length = u_arraylist_length(list); + + for (i = 0; i < length; i++) { if (data == u_arraylist_get(list, i)) { - return 1; - } - else - { - continue; + return true; } } - return 0; + return false; } + diff --git a/resource/csdk/connectivity/common/src/umutex.c b/resource/csdk/connectivity/common/src/umutex.c index e4ddf98..4e648c7 100644 --- a/resource/csdk/connectivity/common/src/umutex.c +++ b/resource/csdk/connectivity/common/src/umutex.c @@ -32,23 +32,10 @@ */ #define TAG PCF("UMUTEX") -void u_mutex_init(void) -{ - /*Initialize the glib thread system if it is not. GMutex works only if the threadsystem is initialized*/ - if (!g_thread_supported()) - { - g_thread_init(NULL); - } -} - u_mutex u_mutex_new(void) { - if (!g_thread_supported()) - { - return NULL; - } - - GMutex *mutexLock = g_mutex_new(); + GMutex *mutexLock = g_new(GMutex, 1); + g_mutex_init(mutexLock); return (u_mutex) mutexLock; } @@ -64,22 +51,17 @@ void u_mutex_lock(u_mutex mutex) g_mutex_lock(mutexLock); } -CABool_t u_mutex_trylock(u_mutex mutex) +bool u_mutex_trylock(u_mutex mutex) { if (NULL == mutex) { OIC_LOG_V(ERROR, TAG, "u_mutex_trylock, Invalid mutex !"); - return CA_FALSE; + return false; } GMutex *mutexLock = (GMutex *) mutex; - gboolean ret = g_mutex_trylock(mutexLock); - if (TRUE == ret) - { - return CA_TRUE; - } - return CA_FALSE; + return(g_mutex_trylock(mutexLock)); } void u_mutex_unlock(u_mutex mutex) @@ -103,17 +85,14 @@ void u_mutex_free(u_mutex mutex) } GMutex *mutexLock = (GMutex *) mutex; - g_mutex_free(mutexLock); + g_mutex_clear(mutexLock); + g_free(mutexLock); } u_cond u_cond_new(void) { - if (!g_thread_supported()) - { - return NULL; - } - - GCond *condition = g_cond_new(); + GCond *condition = g_new(GCond, 1); + g_cond_init(condition); return (u_cond) condition; } @@ -160,7 +139,7 @@ void u_cond_wait(u_cond cond, u_mutex mutex) g_cond_wait(condition, mutexLock); } -void u_cond_timed_wait(u_cond cond, u_mutex mutex, int32_t microseconds) +void u_cond_wait_until(u_cond cond, u_mutex mutex, int32_t microseconds) { if (NULL == mutex) { @@ -183,13 +162,10 @@ void u_cond_timed_wait(u_cond cond, u_mutex mutex, int32_t microseconds) return; } - GTimeVal abs_time; - memset(&abs_time, 0, sizeof(GTimeVal)); - - g_get_current_time(&abs_time); - g_time_val_add(&abs_time, microseconds); + gint64 end_time; + end_time = g_get_monotonic_time() + microseconds; - g_cond_timed_wait(condition, mutexLock, &abs_time); + g_cond_wait_until(condition, mutexLock, end_time); } void u_cond_free(u_cond cond) @@ -201,6 +177,8 @@ void u_cond_free(u_cond cond) } GCond *condition = (GCond *) cond; - g_cond_free(condition); + g_cond_clear(condition); + g_free(condition); } + diff --git a/resource/csdk/connectivity/common/src/uqueue.c b/resource/csdk/connectivity/common/src/uqueue.c index ed8740f..f9e0ada 100644 --- a/resource/csdk/connectivity/common/src/uqueue.c +++ b/resource/csdk/connectivity/common/src/uqueue.c @@ -107,8 +107,6 @@ CAResult_t u_queue_add_element(u_queue_t *queue, u_queue_message_t *message) queue->element = element; queue->count++; OIC_LOG_V(DEBUG, TAG, "Queue Count : %d", queue->count); - - return CA_STATUS_OK; } return CA_STATUS_OK; @@ -116,7 +114,6 @@ CAResult_t u_queue_add_element(u_queue_t *queue, u_queue_message_t *message) u_queue_message_t *u_queue_get_element(u_queue_t *queue) { - u_queue_element *next = NULL; u_queue_element *element = NULL; u_queue_message_t *message = NULL; @@ -134,8 +131,7 @@ u_queue_message_t *u_queue_get_element(u_queue_t *queue) return NULL; } - next = element->next; - queue->element = next; + queue->element = element->next;; queue->count--; message = element->message; @@ -186,8 +182,6 @@ uint32_t u_queue_get_size(u_queue_t *queue) CAResult_t u_queue_reset(u_queue_t *queue) { - CAResult_t error = CA_STATUS_FAILED; - if (NULL == queue) { OIC_LOG(DEBUG, TAG, "QueueReset FAIL, Invalid Queue"); @@ -202,9 +196,7 @@ CAResult_t u_queue_reset(u_queue_t *queue) while (NULL != queue->element) { - error = u_queue_remove_element(queue); - if (error == CA_STATUS_FAILED) - break; + u_queue_remove_element(queue); } if (NO_MESSAGES != queue->count) @@ -253,3 +245,4 @@ u_queue_message_t *u_queue_get_head(u_queue_t *queue) } return queue->element->message; } + diff --git a/resource/csdk/connectivity/common/src/uthreadpool.c b/resource/csdk/connectivity/common/src/uthreadpool.c index 266f3fb..1f7222f 100644 --- a/resource/csdk/connectivity/common/src/uthreadpool.c +++ b/resource/csdk/connectivity/common/src/uthreadpool.c @@ -29,12 +29,6 @@ #define TAG PCF("UTHREADPOOL") /** - * @var gThreadpool - * @brief Glib thread pool. - */ -static GThreadPool *gThreadpool = NULL; - -/** * @fn run * @brief function which is registed to glib thread pool. */ @@ -46,13 +40,9 @@ CAResult_t u_thread_pool_init(uint32_t num_of_threads, u_thread_pool_t *thread_p GError *error = NULL; -#ifdef __ANDROID__ - //If not intialized, gthreadpool intialize check fails - g_thread_init(NULL); -#endif //__ANDROID__ + GThreadPool *threadPool = g_thread_pool_new(run, NULL, num_of_threads, TRUE, &error); - gThreadpool = g_thread_pool_new(run, NULL, num_of_threads, TRUE, &error); - if (NULL == gThreadpool) + if (NULL == threadPool) { OIC_LOG(ERROR, TAG, "g_thread_pool_new failed!"); if (NULL != error) @@ -63,18 +53,18 @@ CAResult_t u_thread_pool_init(uint32_t num_of_threads, u_thread_pool_t *thread_p return CA_STATUS_FAILED; } - *thread_pool = (u_thread_pool_t) gThreadpool; + *thread_pool = (u_thread_pool_t) threadPool; 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 *), +CAResult_t u_thread_pool_add_task(u_thread_pool_t thread_pool, u_thread_func method, void *data) { OIC_LOG(DEBUG, TAG, "IN"); - if (NULL == routine) + if (NULL == method) { OIC_LOG(ERROR, TAG, "routine is NULL!"); return CA_STATUS_FAILED; @@ -88,7 +78,7 @@ CAResult_t u_thread_pool_add_task(u_thread_pool_t thread_pool, void (*routine)(v } message->data = data; - message->func = routine; + message->func = method; g_thread_pool_push((GThreadPool *) thread_pool, (void *) message, NULL); @@ -130,3 +120,4 @@ void run(void *thread_data, void *user_data) // Free message OICFree(message); } + diff --git a/resource/csdk/connectivity/doc/release/RELEASE v0.1 b/resource/csdk/connectivity/doc/release/RELEASE v0.1 deleted file mode 100644 index c1f3f27..0000000 --- a/resource/csdk/connectivity/doc/release/RELEASE v0.1 +++ /dev/null @@ -1,69 +0,0 @@ -Project Name: IoTivity -Release Version No. / Label Name: CA_v0.1 -API Version: CA_v0.4 - -Release Description: -Connectivity Abstraction provides a unified approach to send different OIC messages across multiple transports. - -Scope of Release: -1. Supported APIs ( please check below APIs) -2. Samples to test Supported APIs. -3. OIC Coding guidelines followed based on the current CSDK source. -4. Multi-Threaded Connectivity abstraction -5. Executed Open Source Verification and Prevent analysis. - -The following Connectivity Abstraction API features are supported in this release: - -Supported APIs -CAInitialize() -CATerminate() -CAStartListeningServer() -CAStartDiscoveryServer() -CARegisterHandler() -CAhandleRequestResponse() -FindResource() -SendRequest() -SendResponse() -SelectNetwork() -UnselectNetwork() - -Non Supported APIs -SendNotification() -AdvertizeResource() -CAGenerateToken() -CADestryToken() -CAGetNetworkInfo() - -Type of Release: Source, -Platform OS: Ubuntu 12.0.4 and above: - -Connectivity: WIFI only -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) - -Known and Open Issues: -1) OIC Log, OIC malloc will be removed once name changes applied to OIC Bases code -2) Support only WIFI Interface. -3) URI length is 16 characters. - -Nature of Release: Partial - -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 - -NOTE: sample.sh script can be used @connectivity\samples\linux for 3 steps together - -Execution: -linux$ export LD_LIBRARY_PATH=../../build/out/ -linux$ ./out/sample_main - -Client Option : d, f, h Client -Server Option : s, h diff --git a/resource/csdk/connectivity/doc/release/RELEASE v0.2 b/resource/csdk/connectivity/doc/release/RELEASE v0.2 deleted file mode 100644 index 81ab892..0000000 --- a/resource/csdk/connectivity/doc/release/RELEASE v0.2 +++ /dev/null @@ -1,91 +0,0 @@ -Project Name: IoTivity -Release Version No: CA_v0.2 -API Version: CA_v0.4 - -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). - -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 Connectivity abstraction. -5. Executed Open Source Verification and Prevent analysis. - -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() - -Non Supported APIs -CAGetNetworkInfo() - -Type of Release: Source - - -Known and Open Issues: -1) OIC Log, OIC Malloc will be removed once name changes applied to OIC Bases code -3) Termination sequence is not working.Its blocked. - -Nature of Release: Partial - -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) diff --git a/resource/csdk/connectivity/doc/release/RELEASE v0.3 b/resource/csdk/connectivity/doc/release/RELEASE v0.3 deleted file mode 100644 index 034abe1..0000000 --- a/resource/csdk/connectivity/doc/release/RELEASE v0.3 +++ /dev/null @@ -1,87 +0,0 @@ -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) diff --git a/resource/csdk/connectivity/doc/release/RELEASE v0.4 b/resource/csdk/connectivity/doc/release/RELEASE v0.4 deleted file mode 100644 index 6054cc9..0000000 --- a/resource/csdk/connectivity/doc/release/RELEASE v0.4 +++ /dev/null @@ -1,87 +0,0 @@ -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) diff --git a/resource/csdk/connectivity/doc/release/RELEASE v0.5 b/resource/csdk/connectivity/doc/release/RELEASE v0.5 deleted file mode 100644 index 131e7dc..0000000 --- a/resource/csdk/connectivity/doc/release/RELEASE v0.5 +++ /dev/null @@ -1,89 +0,0 @@ -Project Name: IoTivity -Release Version No: CA_v0.5 -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 -4) Android 5.0 - Connectivity : WIFI, 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) diff --git a/resource/csdk/connectivity/doc/release/RELEASE v0.6 b/resource/csdk/connectivity/doc/release/RELEASE v0.6 deleted file mode 100644 index 85906ef..0000000 --- a/resource/csdk/connectivity/doc/release/RELEASE v0.6 +++ /dev/null @@ -1,96 +0,0 @@ -Project Name: IoTivity -Release Version No: CA_v0.6 -API Version: CA_v0.7 - -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 - Security : DTLS for WIFI -2) Tizen 2.3 - Connectivity : WIFI, EDR, BLE(1:1). -3) Arduino Mega - Connectivity : WIFI, ETH,BLE -4) Android 5.0s - Connectivity : WIFI, BLE - -Preconditions: -1)gcc 4.6.3 and above. -2)glib library (sudo apt-get install libglib2.0-dev) for linux, tizen and android devices -3)libcoap.a library ( do make @lib/libcoap-4.1.1) -4)tinyDTLS library for DTLS enabled applications( enable DTLS = 1 in makefile @connectivity\build/linux) -5)Ethernet, BLE, TimedActions, Timer libraries for arduino support. - -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. -3) GetDtlsPskCredentials is implemented in sample which will be replace by security call during integration - -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) - - -How to Build for Linux/DTLS: -sudo ./sample.sh WITH_DTLS @@connectivity\samples\linux diff --git a/resource/csdk/connectivity/external/inc/ocsecurityconfig.h b/resource/csdk/connectivity/external/inc/ocsecurityconfig.h index bf02abd..fa94db2 100644 --- a/resource/csdk/connectivity/external/inc/ocsecurityconfig.h +++ b/resource/csdk/connectivity/external/inc/ocsecurityconfig.h @@ -56,3 +56,4 @@ typedef struct #endif //OC_SECURITY_CONFIG_H + diff --git a/resource/csdk/connectivity/inc/caadapterinterface.h b/resource/csdk/connectivity/inc/caadapterinterface.h index 4a9dbf8..9e3d170 100644 --- a/resource/csdk/connectivity/inc/caadapterinterface.h +++ b/resource/csdk/connectivity/inc/caadapterinterface.h @@ -39,7 +39,8 @@ extern "C" * port number as per specification. * EDR will not start any specific servers. * LE will not start any specific servers. - * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) + * @return CA_STATUS_OK or CA_STATUS_FAILED + * ERROR CODES (CAResult_t error codes in cacommon.h) */ typedef CAResult_t (*CAAdapterStart)(); @@ -50,7 +51,8 @@ typedef CAResult_t (*CAAdapterStart)(); * port number and as per specification. * EDR Starts RFCOMM Server with prefixed UUID as per specification. * LE Start GATT Server with prefixed UUID and Characteristics as per OIC Specification. - * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) + * @return CA_STATUS_OK or CA_STATUS_FAILED + * ERROR CODES (CAResult_t error codes in cacommon.h) */ typedef CAResult_t (*CAAdapterStartListeningServer)(); @@ -61,7 +63,8 @@ typedef CAResult_t (*CAAdapterStartListeningServer)(); * number as per OIC Specification. * EDR Starts RFCOMM Server with prefixed UUID as per OIC Specification. * LE Starts GATT Server with prefixed UUID and Characteristics as per OIC Specification. - * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) + * @return CA_STATUS_OK or CA_STATUS_FAILED + * ERROR CODES (CAResult_t error codes in cacommon.h) */ typedef CAResult_t (*CAAdapterStartDiscoveryServer)(); @@ -72,19 +75,19 @@ typedef CAResult_t (*CAAdapterStartDiscoveryServer)(); * reference uri and connectivity type) to which the unicast data has to be sent. * @param data [IN] Data which 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 zero indicates error. + * @return The number of bytes sent on the network. Return value equal to -1 indicates error. */ -typedef uint32_t (*CAAdapterSendUnitcastData)(const CARemoteEndpoint_t *endpoint, void *data, - uint32_t dataLen); +typedef int32_t (*CAAdapterSendUnitcastData)(const CARemoteEndpoint_t *endpoint, + const void *data, uint32_t dataLen); /** * @brief Sends Multicast data to the endpoint using the adapter connectivity. * Note: length must be > 0. * @param data [IN] Data which 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 zero indicates error. + * @return The number of bytes sent on the network. Return value equal to -1 indicates error. */ -typedef uint32_t (*CAAdapterSendMulticastData)(void *data, uint32_t dataLen); +typedef int32_t (*CAAdapterSendMulticastData)(const void *data, uint32_t dataLen); /** * @brief Get Network Information @@ -112,7 +115,7 @@ typedef CAResult_t (*CAAdapterStop)(); /** * @brief Terminate the connectivity adapter.Configuration information will be deleted from - * further use + * further use. Freeing Memory of threadpool and mutexs and cleanup will be done. */ typedef void (*CAAdapterTerminate)(); @@ -123,20 +126,28 @@ typedef struct { /** Start Transport specific functions*/ CAAdapterStart startAdapter; + /** Listening Server function address*/ CAAdapterStartListeningServer startListenServer; + /** Discovery Server function address **/ - CAAdapterStartDiscoveryServer startDiscoverServer; + CAAdapterStartDiscoveryServer startDiscoveryServer; + /** Unicast data function address**/ CAAdapterSendUnitcastData sendData; + /** Multicast data function address**/ CAAdapterSendMulticastData sendDataToAll; + /** Get Networking information **/ CAAdapterGetNetworkInfo GetnetInfo; + /** Read Data function address**/ CAAdapterReadData readData; + /** Stop Transport specific functions*/ CAAdapterStop stopAdapter; + /** Terminate function address stored in this pointer**/ CAAdapterTerminate terminate; @@ -157,7 +168,7 @@ typedef void (*CANetworkPacketReceivedCallback)(CARemoteEndpoint_t *endPoint, vo uint32_t dataLen); /** - * @brief This will be used to intimate network changes to the connectivity common logic layer + * @brief This will be used to notify network changes to the connectivity common logic layer * @see SendUnitcastData(), SendMulticastData() */ typedef void (*CANetworkChangeCallback)(CALocalConnectivity_t *info, CANetworkStatus_t status); @@ -167,3 +178,4 @@ typedef void (*CANetworkChangeCallback)(CALocalConnectivity_t *info, CANetworkSt #endif #endif // __CA_ADAPTER_INTERFACE_H_ + diff --git a/resource/csdk/connectivity/inc/caadapternetdtls.h b/resource/csdk/connectivity/inc/caadapternetdtls.h index 44447ff..17e1c10 100644 --- a/resource/csdk/connectivity/inc/caadapternetdtls.h +++ b/resource/csdk/connectivity/inc/caadapternetdtls.h @@ -27,6 +27,9 @@ #include "ocsecurityconfig.h" #include "cainterface.h" +/** + * Currently DTLS supported adapters(2) WIFI and ETHENET for linux platform. + */ #define MAX_SUPPORTED_ADAPTERS 2 /** @@ -34,10 +37,10 @@ */ extern void OCGetDtlsPskCredentials(OCDtlsPskCredsBlob **credInfo); -typedef void (*CAPacketReceivedCallback)(const char *ipAddress, const uint32_t port, - const void *data, const uint32_t dataLength, const CABool_t isSecured); +typedef void (*CAPacketReceivedCallback)(const char *ipAddress, const uint16_t port, + const void *data, const uint32_t dataLength, const bool isSecured); -typedef uint32_t (*CAPacketSendCallback)(const char *ipAddress, const uint32_t port, +typedef uint32_t (*CAPacketSendCallback)(const char *ipAddress, const uint16_t port, const void *data, const uint32_t dataLength); /** @@ -121,7 +124,9 @@ typedef struct CACacheMessage /** * @enum eDtlsAdapterType_t - * @brief adapter types + * @brief This enum is used as array index for storing adapter level callbacks. + * So Keeping 0 instead of "1 << 0". It is not going to be used as addition + * and removal of adapter. * */ typedef enum @@ -197,8 +202,8 @@ void CAAdapterNetDtlsDeInit(); */ CAResult_t CAAdapterNetDtlsEncrypt(const char *remoteAddress, - const uint32_t port, - const void *data, + const uint16_t port, + void *data, uint32_t dataLen, uint8_t *cacheFlag, eDtlsAdapterType_t type); @@ -219,10 +224,11 @@ CAResult_t CAAdapterNetDtlsEncrypt(const char *remoteAddress, * */ CAResult_t CAAdapterNetDtlsDecrypt(const char *remoteAddress, - const uint32_t port, + const uint16_t port, uint8_t *data, uint32_t dataLen, eDtlsAdapterType_t type); #endif //_CA_ADAPTER_NET_DTLS_H + diff --git a/resource/csdk/connectivity/inc/caadapterutils.h b/resource/csdk/connectivity/inc/caadapterutils.h index 4878a7f..fa3f45e 100644 --- a/resource/csdk/connectivity/inc/caadapterutils.h +++ b/resource/csdk/connectivity/inc/caadapterutils.h @@ -26,12 +26,9 @@ #ifndef _CA_ADAPTER_UTILS_H_ #define _CA_ADAPTER_UTILS_H_ -#include - #include "cacommon.h" #include "logger.h" -#include "oic_malloc.h" -#include "oic_string.h" +#include "pdu.h" #ifdef __cplusplus extern "C" @@ -69,6 +66,17 @@ extern "C" } \ /** + * @def IPV4_ADDR_ONE_OCTECT_LEN + * @brief Macro to allocate memory for ipv4 address in the form of uint8_t. + */ +#define IPV4_ADDR_ONE_OCTECT_LEN 4 + +/** + * @brief To log the PDU data + */ +void CALogPDUData(coap_pdu_t *pdu); + +/** * @fn CAAdapterCreateLocalEndpoint * @brief Create CALocalConnectivity_t instance. */ @@ -79,7 +87,7 @@ CALocalConnectivity_t *CAAdapterCreateLocalEndpoint(CAConnectivityType_t type, * @fn CAAdapterCopyLocalEndpoint * @brief Create CALocalConnectivity_t duplicate instance. */ -CALocalConnectivity_t *CAAdapterCopyLocalEndpoint(CALocalConnectivity_t *connectivity); +CALocalConnectivity_t *CAAdapterCopyLocalEndpoint(const CALocalConnectivity_t *connectivity); /** * @fn CAAdapterFreeLocalEndpoint @@ -108,6 +116,18 @@ CARemoteEndpoint_t *CAAdapterCopyRemoteEndpoint( void CAAdapterFreeRemoteEndpoint(CARemoteEndpoint_t *remoteEndPoint); /** + * @fn CAParseIPv4AddressInternal + * @brief To parse the IP address and port from "ipaddress:port" + * @param ipAddrStr [IN] IP address to be parsed + * @param ipAddr [OUT] Parsed IP address + * @param ipAddr [IN] Buffer length for parsed IP address + * @param port [OUT] Parsed Port number + * @return #CA_STATUS_OK or Appropriate error code + */ +CAResult_t CAParseIPv4AddressInternal(const char *ipAddrStr, uint8_t *ipAddr, + size_t ipAddrLen, uint16_t *port); + +/** * @fn CAAdapterIsSameSubnet * @brief Check if two ip address belong to same subnet */ @@ -117,3 +137,4 @@ bool CAAdapterIsSameSubnet(const char *ipAddress1, const char *ipAddress2, } /* extern "C" */ #endif #endif // _CA_ADAPTER_UTILS_H_ + diff --git a/resource/csdk/connectivity/inc/caedradapter.h b/resource/csdk/connectivity/inc/caedradapter.h index 70b3993..220bb3f 100644 --- a/resource/csdk/connectivity/inc/caedradapter.h +++ b/resource/csdk/connectivity/inc/caedradapter.h @@ -42,7 +42,7 @@ extern "C" * 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 + * @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 @@ -99,10 +99,10 @@ CAResult_t CAStartEDRDiscoveryServer(); * 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. + * @return The number of bytes sent on the network. Returns -1 on error. * */ -uint32_t CASendEDRUnicastData(const CARemoteEndpoint_t *remoteEndpoint, void *data, +int32_t CASendEDRUnicastData(const CARemoteEndpoint_t *remoteEndpoint, const void *data, uint32_t dataLength); /** @@ -110,9 +110,9 @@ uint32_t CASendEDRUnicastData(const CARemoteEndpoint_t *remoteEndpoint, void *da * 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. + * @return Number of bytes sent on the network. Returns -1 on error. */ -uint32_t CASendEDRMulticastData(void *data, uint32_t dataLength); +int32_t CASendEDRMulticastData(const void *data, uint32_t dataLength); /** * @brief Get EDR Connectivity network information. @@ -166,3 +166,4 @@ CAResult_t CAAdapterStartQueue(); #endif #endif //__CA_EDRADAPTER_H_ + diff --git a/resource/csdk/connectivity/inc/caedradapter_singlethread.h b/resource/csdk/connectivity/inc/caedradapter_singlethread.h index 88335ab..cb52b46 100644 --- a/resource/csdk/connectivity/inc/caedradapter_singlethread.h +++ b/resource/csdk/connectivity/inc/caedradapter_singlethread.h @@ -41,7 +41,7 @@ extern "C" * 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 + * @param netCallback [IN] Callback to notify the network additions to Connectivity * Abstraction Layer. * @return #CA_STATUS_OK or Appropriate error code * @retval #CA_STATUS_OK Successful @@ -92,9 +92,9 @@ CAResult_t CAStartEDRDiscoveryServer(); * 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 Number of bytes sent on the network. Returns 0 on error. + * @return Number of bytes sent on the network. Returns -1 on error. */ -uint32_t CASendEDRUnicastData(const CARemoteEndpoint_t *remoteEndpoint, void *data, +int32_t CASendEDRUnicastData(const CARemoteEndpoint_t *remoteEndpoint, const void *data, uint32_t dataLength); /** @@ -102,9 +102,9 @@ uint32_t CASendEDRUnicastData(const CARemoteEndpoint_t *remoteEndpoint, void *da * 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. + * @return Number of bytes sent on the network. Returns -1 on error. */ -uint32_t CASendEDRMulticastData(void *data, uint32_t dataLength); +int32_t CASendEDRMulticastData(const void *data, uint32_t dataLength); /** * @brief Get EDR Connectivity network information. @@ -147,3 +147,4 @@ void CATerminateEDR(); #endif #endif //__CA_EDRADAPTER_SINGLETHREAD_H_ + diff --git a/resource/csdk/connectivity/inc/caedrclient.h b/resource/csdk/connectivity/inc/caedrclient.h index 6a39313..f39f297 100644 --- a/resource/csdk/connectivity/inc/caedrclient.h +++ b/resource/csdk/connectivity/inc/caedrclient.h @@ -37,78 +37,257 @@ extern "C" { #endif +/** +* @brief Set context of application +* @param context [IN] context of application +* @return None +*/ void CAEDRJniSetContext(jobject context); +/** +* @brief Create JNI Object +* @param context [IN] context of application +* @return None +*/ void CAEDRCreateJNIInterfaceObject(jobject context); +/** + * @brief Initialize client for EDR + * @param handle [IN] thread pool handle object + * @return None + */ void CAEDRInitialize(u_thread_pool_t handle); +/** + * @brief Terminate server for EDR + * @return None + */ void CAEDRTerminate(); -void CAEDRCoreJniInit(JNIEnv *env, JavaVM* jvm); +/** + * @brief Initialize JNI object + * @param env [IN] JNI interface pointer + * @param jvm [IN] java virtual machine pointer + * @return None + */ +void CAEDRCoreJniInit(JNIEnv *env, JavaVM *jvm); -int32_t CAEDRSendUnicastMessage(const char *address, const char *data, uint32_t dataLen); +/** + * @brief Send data for unicast + * @param address [IN] remote address + * @param data [IN] data for transmission + * @param dataLen [IN] data length + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_STATUS_FAILED Operation failed + */ +CAResult_t CAEDRSendUnicastMessage(const char *address, + const char *data, uint32_t dataLen); -int32_t CAEDRSendMulticastMessage(const char *data, uint32_t dataLen); +/** + * @brief Send data for multicast + * @param data [IN] data for transmission + * @param dataLen [IN] data length + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_STATUS_FAILED Operation failed + */ +CAResult_t CAEDRSendMulticastMessage(const char *data, uint32_t dataLen); +/** + * @brief Get Local EDR Address + * @param address [OUT] local address + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_STATUS_FAILED Operation failed + */ CAResult_t CAEDRGetInterfaceInfo(char **address); -void CAEDRGetLocalAddress(char** address); +/** + * @brief Get address from a local device + * @param address [OUT] local address + * @return None + */ +void CAEDRGetLocalAddress(char **address); -int32_t CAEDRSendUnicastMessageImpl(const char *address, const char *data, uint32_t dataLen); +/** + * @brief Send data for unicast (implement) + * @param address [IN] remote address + * @param data [IN] data for transmission + * @param dataLen [IN] data length + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_STATUS_FAILED Operation failed + */ +CAResult_t CAEDRSendUnicastMessageImpl(const char *address, + const char *data, uint32_t dataLen); -int32_t CAEDRSendMulticastMessageImpl(JNIEnv *env, const char *data, uint32_t dataLen); +/** + * @brief Send data for multicast (implement) + * @param env [IN] JNI interface pointer + * @param data [IN] data for transmission + * @param dataLen [IN] data length + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_STATUS_FAILED Operation failed + */ +CAResult_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); -void CAEDRNativeConnect(JNIEnv *env, const char* address, uint32_t id); +/** + * @brief This function will send the data to remote device. + * @param env [IN] JNI interface pointer + * @param address [IN] Remote Address + * @param data [IN] Data to be transmitted from EDR + * @param id [IN] index of remote address + * @return None + */ +void CAEDRNativeSendData(JNIEnv *env, const char *address, const char *data, uint32_t id); + +/** + * @brief This function will connect to remote device. + * @param env [IN] JNI interface pointer + * @param address [IN] Remote Address + * @param id [IN] index of remote address + * @return None + */ +void CAEDRNativeConnect(JNIEnv *env, const char *address, uint32_t id); -void CAEDRNativeSocketClose(JNIEnv *env, const char* address, uint32_t id); +/** + * @brief This function will close socket. + * @param env [IN] JNI interface pointer + * @param address [IN] Remote Address + * @param id [IN] index of remote address + * @return None + */ +void CAEDRNativeSocketClose(JNIEnv *env, const char *address, uint32_t id); /** * BT State List */ + +/** + * @brief This function will create the device state list. + * @return None + */ void CAEDRNativeCreateDeviceStateList(); -void CAEDRUpdateDeviceState(uint32_t state, const char* address); +/** + * @brief Update connection state of device + * @param state [IN] connection state + * @param address [IN] remote address + * @return None + */ +void CAEDRUpdateDeviceState(CAConnectedState_t state, const char *address); -void CAEDRNativeAddDeviceStateToList(state_t* state); +/** + * @brief Add device object to the list + * @param state [IN] connection state object + * @return None + */ +void CAEDRNativeAddDeviceStateToList(state_t *state); +/** + * @brief Check whether the device exist in the list or not + * @param remoteAddress [IN] remote address + * @return TRUE or FALSE + */ jboolean CAEDRNativeIsDeviceInList(const char *remoteAddress); +/** + * @brief Remove all device objects in the list + * @return None + */ void CAEDRNativeRemoveAllDeviceState(); -void CAEDRNativeRemoveDevice(const char* remoteAddress); +/** + * @brief Remove target device in the list + * @param remoteAddress [IN] remote address + * @return None + */ +void CAEDRNativeRemoveDevice(const char *remoteAddress); -jboolean CAEDRIsConnectedDevice(const char* remoteAddress); +/** + * @brief Get current device connection state + * @param remoteAddress [IN] remote address + * @return STATE_DISCONNECTED or STATE_CONNECTED + */ +CAConnectedState_t CAEDRIsConnectedDevice(const char *remoteAddress); +/** + * @brief Reordering for the list + * @param index [IN] index of device list that want to reordering + * @return None + */ void CAEDRReorderingDeviceList(uint32_t index); /** * Bluetooth Socket Object List */ + +/** + * @brief This function will create the device socket list. + * @return None + */ void CAEDRNativeCreateDeviceSocketList(); +/** + * @brief Add device object to the list + * @param env [IN] JNI interface pointer + * @param deviceSocket [IN] device socket object + * @return None + */ void CAEDRNativeAddDeviceSocketToList(JNIEnv *env, jobject deviceSocket); +/** + * @brief Add device object to the list + * @param env [IN] JNI interface pointer + * @param remoteAddress [IN] remote address + * @return TRUE or FALSE + */ jboolean CAEDRNativeIsDeviceSocketInList(JNIEnv *env, const char *remoteAddress); +/** + * @brief Add device object to the list + * @param env [IN] JNI interface pointer + * @return None + */ void CAEDRNativeRemoveAllDeviceSocket(JNIEnv *env); +/** + * @brief Add device object to the list + * @param env [IN] JNI interface pointer + * @param deviceSocket [IN] device socket object + * @return None + */ void CAEDRNativeRemoveDeviceSocket(JNIEnv *env, jobject deviceSocket); +/** + * @brief Get device socket object from the list + * @param idx [IN] index of device list + * @return Device socket object or NULL + */ jobject CAEDRNativeGetDeviceSocket(uint32_t idx); +/** + * @brief Get length of device socket list + * @return length of list + */ uint32_t CAEDRGetSocketListLength(); +/** + * @brief Reordering for the list + * @param index [IN] index of device list that want to reordering + * @return None + */ void CAEDRReorderingDeviceSocketList(uint32_t index); - #ifdef __cplusplus } /* extern "C" */ #endif #endif + diff --git a/resource/csdk/connectivity/inc/caedrinterface.h b/resource/csdk/connectivity/inc/caedrinterface.h index a92236e..5a43db9 100644 --- a/resource/csdk/connectivity/inc/caedrinterface.h +++ b/resource/csdk/connectivity/inc/caedrinterface.h @@ -26,7 +26,6 @@ #ifndef __CA_EDR_INTERFACE_H_ #define __CA_EDR_INTERFACE_H_ -#include #include "caedradapter.h" #ifdef __cplusplus @@ -38,10 +37,15 @@ extern "C" #define OIC_EDR_SERVICE_ID "12341234-1C25-481F-9DFB-59193D238280" #endif //OIC_EDR_SERVICE_ID +typedef enum +{ + STATE_DISCONNECTED, /**< State is Disconnected */ + STATE_CONNECTED /**< State is Connected */ +} CAConnectedState_t; typedef struct connected_state { - char address[CA_MACADDR_SIZE]; - uint32_t state; + uint8_t address[CA_MACADDR_SIZE]; + CAConnectedState_t state; } state_t; /** @@ -78,15 +82,15 @@ typedef struct /** * @brief This will be used during the recive of network requests and response. - * @param remoteAddress [IN] EDR address of remote OIC device + * @param remoteAddress [IN] EDR address of remote OIC device from which data received. * @param data [IN] Data received * @param dataLength [IN] Length of the Data received - * @param sentLength [IN] Length of the sent data + * @param sentLength [OUT] 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); +typedef void (*CAEDRDataReceivedCallback)(const char *remoteAddress, + const void *data, uint32_t dataLength, uint32_t *sentLength); /** * @brief This will be used during change in network status. @@ -154,7 +158,7 @@ void CAEDRInitializeClient(u_thread_pool_t handle); * @brief Destroys the Device list and mutex. * @return NONE */ -void CAEDRTerminateClient(); +void CAEDRClientTerminate(); /** * @brief Closes all the client connection to peer bluetooth devices. @@ -208,7 +212,7 @@ CAResult_t CAEDRGetInterfaceInformation(CALocalConnectivity_t **info); * @retval #CA_STATUS_FAILED Operation failed * */ -CAResult_t CAEDRServerStart(const char *serviceUUID, int32_t *serverFD, u_thread_pool_t handle); +CAResult_t CAEDRServerStart(const char *serviceUUID, int *serverFD, u_thread_pool_t handle); /** * @brief Stop RFCOMM server @@ -219,7 +223,13 @@ CAResult_t CAEDRServerStart(const char *serviceUUID, int32_t *serverFD, u_thread * @retval #CA_STATUS_OK Successful * @retval #CA_STATUS_FAILED Operation failed */ -CAResult_t CAEDRServerStop(const int32_t serverFD); +CAResult_t CAEDRServerStop(int serverFD); + +/** + * @brief Terminate server for EDR + * @return None + */ +void CAEDRServerTerminate(); /** * @brief All received data will be notified to upper layer. @@ -236,7 +246,7 @@ CAResult_t CAEDRManagerReadData(void); * @param state [OUT] State of the Adapter. * @return #CA_STATUS_OK or Appropriate error code */ -CAResult_t CAEDRGetAdapterEnableState(CABool_t *state); +CAResult_t CAEDRGetAdapterEnableState(bool *state); /** * @brief This function sends data to specified remote bluetooth device. @@ -244,21 +254,21 @@ CAResult_t CAEDRGetAdapterEnableState(CABool_t *state); * @param serviceUUID [IN] Service UUID of the device * @param data [IN] Data to be sent * @param dataLength [IN] Length of the data to be sent - * @param sentLength [IN] Length of the actual sent data + * @param sentLength [OUT] Length of the actual sent data * @return #CA_STATUS_OK or Appropriate error code */ CAResult_t CAEDRClientSendUnicastData(const char *remoteAddress, const char *serviceUUID, - void *data, uint32_t dataLength, uint32_t *sentLength); + const void *data, uint32_t dataLength, uint32_t *sentLength); /** * @brief This function sends data to all bluetooth devices running OIC service. * @param serviceUUID [IN] Service UUID of the device * @param data [IN] Data to be sent * @param dataLength [IN] Length of the data to be sent - * @param sentLength [IN] Length of the actual sent data + * @param sentLength [OUT] Length of the actual sent data * @return #CA_STATUS_OK or Appropriate error code */ -CAResult_t CAEDRClientSendMulticastData(const char *serviceUUID, void *data, +CAResult_t CAEDRClientSendMulticastData(const char *serviceUUID, const void *data, uint32_t dataLength, uint32_t *sentLength); #ifdef __cplusplus @@ -267,3 +277,4 @@ CAResult_t CAEDRClientSendMulticastData(const char *serviceUUID, void *data, #endif //__CA_EDR_INTERFACE_H_ + diff --git a/resource/csdk/connectivity/inc/caedrserver.h b/resource/csdk/connectivity/inc/caedrserver.h index e6cc732..e3f406b 100644 --- a/resource/csdk/connectivity/inc/caedrserver.h +++ b/resource/csdk/connectivity/inc/caedrserver.h @@ -40,68 +40,205 @@ extern "C" typedef void (*CAPacketReceiveCallback)(const char *address, const char *data); -//getting jvm +/** + * @brief Initialize JNI object + * @param env [IN] JNI interface pointer + * @param jvm [IN] java virtual machine pointer + * @return None + */ void CAEDRServerJniInit(JNIEnv *env, JavaVM *jvm); +/** + * @brief Initialize server for EDR + * @param handle [IN] thread pool handle object + * @return None + */ void CAEDRServerInitialize(u_thread_pool_t handle); -void CAEDRServerTerminate(); - +/** + * @brief Start unicast server + * @param address [IN] remote address + * @param isSecured [IN] unicast server type + * @return Returns -1 on error and 0 on success + */ int32_t CAEDRStartUnicastServer(const char *address, bool isSecured); +/** + * @brief Start multicast server + * @param isSecured [IN] multicst server type + * @return Returns -1 on error and 0 on success + */ int32_t CAEDRStartMulticastServer(bool isSecured); +/** + * @brief Stop unicast server + * @param serverID [IN] unicast server id + * @return Returns -1 on error and 0 on success + */ int32_t CAEDRStopUnicastServer(int32_t serverID); +/** + * @brief Stop multicast server + * @param serverID [IN] multicast server id + * @return Returns -1 on error and 0 on success + */ int32_t CAEDRStopMulticastServer(int32_t serverID); /** * EDR Method */ -uint32_t CAEDRNativeReadData(JNIEnv *env, uint32_t id, CAAdapterServerType_t type); +/** + * @brief This function will read the data from remote device. + * @param env [IN] JNI interface pointer + * @param id [IN] index of remote address + * @param type [IN] EDR server type + * @return #CA_STATUS_OK or Appropriate error code + */ +CAResult_t CAEDRNativeReadData(JNIEnv *env, uint32_t id, CAAdapterServerType_t type); + +/** + * @brief This function will listen the connection from remote device. + * @param env [IN] JNI interface pointer + * @return server socket object or NULL + */ jobject CAEDRNativeListen(JNIEnv *env); +/** + * @brief This function will accept the connection from remote device. + * @param env [IN] JNI interface pointer + * @param severSocketObject [IN] server socket object + * @return None + */ void CAEDRNativeAccept(JNIEnv *env, jobject severSocketObject); -void CAEDRNativeServerSocketClose(JNIEnv *env, const char* address, uint32_t id); +/** + * @brief This function will accept the connection from remote device. + * @param env [IN] JNI interface pointer + * @param address [IN] remote address + * @param id [IN] index of remote address + * @return None + */ +void CAEDRNativeServerSocketClose(JNIEnv *env, const char *address, uint32_t id); /** * BT State List */ + +/** + * @brief This function will create the device state list. + * @return None + */ void CAEDRServerNativeCreateDeviceStateList(); -void CAEDRServerUpdateDeviceState(uint32_t state, const char* address); +/** + * @brief Update connection state of device + * @param state [IN] connection state + * @param address [IN] remote address + * @return None + */ +void CAEDRServerUpdateDeviceState(uint32_t state, const char *address); -void CAEDRServerNativeAddDeviceStateToList(state_t* state); +/** + * @brief Add device object to the list + * @param state [IN] connection state object + * @return None + */ +void CAEDRServerNativeAddDeviceStateToList(state_t *state); +/** + * @brief Check whether the device exist in the list or not + * @param remoteAddress [IN] remote address + * @return TRUE or FALSE + */ jboolean CAEDRServerNativeIsDeviceInList(const char *remoteAddress); +/** + * @brief Remove all device objects in the list + * @return None + */ void CAEDRServerNativeRemoveAllDeviceState(); -void CAEDRServerNativeRemoveDevice(const char* remoteAddress); +/** + * @brief Remove target device in the list + * @param remoteAddress [IN] remote address + * @return None + */ +void CAEDRServerNativeRemoveDevice(const char *remoteAddress); -jboolean CAEDRServerIsConnectedDevice(const char* remoteAddress); +/** + * @brief Check whether the state is connected or disconnected + * @param remoteAddress [IN] remote address + * @return TRUE or FALSE + */ +jboolean CAEDRServerIsConnectedDevice(const char *remoteAddress); +/** + * @brief Reordering for the list + * @param index [IN] index of device list that want to reordering + * @return None + */ void CAEDRServerReorderingDeviceList(uint32_t index); /** * Bluetooth Socket Object List */ + +/** + * @brief This function will create the device socket list. + * @return None + */ void CAEDRServerNativeCreateDeviceSocketList(); +/** + * @brief Add device object to the list + * @param env [IN] JNI interface pointer + * @param deviceSocket [IN] device socket object + * @return None + */ void CAEDRServerNativeAddDeviceSocketToList(JNIEnv *env, jobject deviceSocket); +/** + * @brief Add device object to the list + * @param env [IN] JNI interface pointer + * @param remoteAddress [IN] remote address + * @return TRUE or FALSE + */ jboolean CAEDRServerNativeIsDeviceSocketInList(JNIEnv *env, const char *remoteAddress); +/** + * @brief Add device object to the list + * @param env [IN] JNI interface pointer + * @return None + */ void CAEDRServerNativeRemoveAllDeviceSocket(JNIEnv *env); +/** + * @brief Add device object to the list + * @param env [IN] JNI interface pointer + * @param deviceSocket [IN] device socket object + * @return None + */ void CAEDRServerNativeRemoveDeviceSocket(JNIEnv *env, jobject deviceSocket); +/** + * @brief Get device socket object from the list + * @param idx [IN] index of device list + * @return Device socket object or NULL + */ jobject CAEDRServerNativeGetDeviceSocket(uint32_t idx); +/** + * @brief Get length of device socket list + * @return length of list + */ uint32_t CAEDRServerGetSocketListLength(); +/** + * @brief Reordering for the list + * @param index [IN] index of device list that want to reordering + * @return None + */ void CAEDRServerReorderingDeviceSocketList(uint32_t index); @@ -110,3 +247,4 @@ void CAEDRServerReorderingDeviceSocketList(uint32_t index); #endif #endif + diff --git a/resource/csdk/connectivity/inc/caedrutils.h b/resource/csdk/connectivity/inc/caedrutils.h index 2c868db..264df38 100644 --- a/resource/csdk/connectivity/inc/caedrutils.h +++ b/resource/csdk/connectivity/inc/caedrutils.h @@ -52,3 +52,4 @@ jstring CAEDRNativeGetAddressFromBTDevice(JNIEnv *env, jobject bluetoothDevice); #endif #endif + diff --git a/resource/csdk/connectivity/inc/caethernetadapter.h b/resource/csdk/connectivity/inc/caethernetadapter.h index 4e503d8..3ee5339 100644 --- a/resource/csdk/connectivity/inc/caethernetadapter.h +++ b/resource/csdk/connectivity/inc/caethernetadapter.h @@ -27,7 +27,7 @@ #include "cacommon.h" #include "caadapterinterface.h" -#include "uthreadpool.h" /* for thread pool */ +#include "uthreadpool.h" #ifdef __cplusplus extern "C" @@ -40,7 +40,7 @@ extern "C" * 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 intimate the network additions to Connectivity + * @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 @@ -79,20 +79,20 @@ CAResult_t CAStartEthernetDiscoveryServer(); * reference uri and connectivity 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 zero indicates error. + * @return The number of bytes sent on the network. Return value equal to -1 indicates error. * @remarks dataLen must be > 0. */ -uint32_t CASendEthernetUnicastData(const CARemoteEndpoint_t *endpoint, void *data, +int32_t CASendEthernetUnicastData(const CARemoteEndpoint_t *endpoint, const void *data, uint32_t dataLen); /** * @brief Sends Multicast data to the endpoint using the Ethernet connectivity. * @param data [IN] Data which 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 zero indicates error. + * @return The number of bytes sent on the network. Return value equal to -1 indicates error. * @remarks dataLen must be > 0. */ -uint32_t CASendEthernetMulticastData(void *data, uint32_t dataLen); +int32_t CASendEthernetMulticastData(const void *data, uint32_t dataLen); /** * @brief Get Ethernet Connectivity network information @@ -127,3 +127,4 @@ void CATerminateEthernet(); #endif #endif // #ifndef __CA_ETHERNET_ADAPTER_H__ + diff --git a/resource/csdk/connectivity/inc/caethernetadapter_singlethread.h b/resource/csdk/connectivity/inc/caethernetadapter_singlethread.h index a359b5f..99b5be9 100644 --- a/resource/csdk/connectivity/inc/caethernetadapter_singlethread.h +++ b/resource/csdk/connectivity/inc/caethernetadapter_singlethread.h @@ -39,7 +39,7 @@ extern "C" * 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 intimate the network additions to Connectivity + * @param netCallback [IN] Callback to notify the network additions to Connectivity * Abstraction Layer. * @return #CA_STATUS_OK or Appropriate error code */ @@ -77,20 +77,20 @@ CAResult_t CAStartEthernetDiscoveryServer(); * reference uri and connectivity type) to which the unicast data has to be sent. * @param data [IN] Data which 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 zero indicates error. + * @return The number of bytes sent on the network. Return value equal to -1 indicates error. * @remark dataLen must be > 0. */ -uint32_t CASendEthernetUnicastData(const CARemoteEndpoint_t *endpoint, void *data, - uint32_t dataLen); +int32_t CASendEthernetUnicastData(const CARemoteEndpoint_t *endpoint, const void *data, + uint32_t dataLen); /** * @brief Send Multicast data to the endpoint using the Ethernet connectivity. * @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 zero indicates error. + * @return The number of bytes sent on the network. Return value equal to -1 indicates error. * @remark dataLen must be > 0. */ -uint32_t CASendEthernetMulticastData(void *data, uint32_t dataLen); +int32_t CASendEthernetMulticastData(const void *data, uint32_t dataLen); /** * @brief Get Ethernet Connectivity network information @@ -125,3 +125,4 @@ void CATerminateEthernet(); #endif #endif // #ifndef __CA_ETHERNET_ADAPTER_SINGLETHREAD_H__ + diff --git a/resource/csdk/connectivity/inc/caethernetinterface.h b/resource/csdk/connectivity/inc/caethernetinterface.h index bc519e8..6a1c4cd 100644 --- a/resource/csdk/connectivity/inc/caethernetinterface.h +++ b/resource/csdk/connectivity/inc/caethernetinterface.h @@ -57,9 +57,9 @@ typedef enum * @return NONE * @pre Callback must be registered using CAEthernetSetPacketReceiveCallback() */ -typedef void (*CAEthernetPacketReceivedCallback)(const char *ipAddress, const uint32_t port, +typedef void (*CAEthernetPacketReceivedCallback)(const char *ipAddress, const uint16_t port, const void *data, const uint32_t dataLength, - const CABool_t isSecured); + const bool isSecured); /** * @brief Callback to be notified when exception occures on multicast/unicast server. @@ -100,8 +100,8 @@ void CAEthernetTerminateServer(void); * @retval #CA_SERVER_STARTED_ALREADY Multicast server is already started and running. * @retval #CA_STATUS_FAILED Operation failed */ -CAResult_t CAEthernetStartMulticastServer(const char *localAddress, const char *multicastAddress, - const int16_t multicastPort, int32_t *serverFD); +CAResult_t CAEthernetStartMulticastServer(const char *localAddress, + const char *multicastAddress, const uint16_t multicastPort, int32_t *serverFD); /** * @brief Start unicast server for specified local address and port @@ -120,8 +120,8 @@ CAResult_t CAEthernetStartMulticastServer(const char *localAddress, const char * * @retval #CA_SERVER_STARTED_ALREADY Unicast server is already started and running. * @retval #CA_STATUS_FAILED Operation failed */ -CAResult_t CAEthernetStartUnicastServer(const char *localAddress, int16_t *port, - const bool forceStart, const bool secured, int32_t *serverFD); +CAResult_t CAEthernetStartUnicastServer(const char *localAddress, uint16_t *port, + bool forceStart, bool secured, int32_t *serverFD); /** * @brief Stop multicast server. @@ -164,8 +164,8 @@ CAResult_t CAEthernetStopSecureUnicastServer(); * @retval #CA_STATUS_FAILED Operation failed * @remarks ipAddress must be freed using free(). */ -CAResult_t CAEthernetGetUnicastServerInfo(const bool secure, char **ipAddress, int16_t *port, - int32_t *serverFD); +CAResult_t CAEthernetGetUnicastServerInfo(bool secure, char **ipAddress, + uint16_t *port,int32_t *serverFD); /** * @brief Set this callback for receiving data packets from peer devices. @@ -199,7 +199,7 @@ void CAEthernetSetUnicastSocket(const int32_t socketFD); * @param port [IN] Port number used for sending UDP data. * @return NONE */ -void CAEthernetSetUnicastPort(const int32_t port); +void CAEthernetSetUnicastPort(const uint16_t port); #ifdef __WITH_DTLS__ /** @@ -224,9 +224,9 @@ void CAEthernetSetSecureUnicastSocket(const int32_t socketFD); * @return The number of bytes sent on the network. Returns 0 on error. * @remarks isSecure will be ignored when isMulticast is true. */ -uint32_t CAEthernetSendData(const char *remoteAddress, const uint32_t port, +uint32_t CAEthernetSendData(const char *remoteAddress, const uint16_t port, const void *data, const uint32_t dataLength, - CABool_t isMulticast, CABool_t isSecure); + bool isMulticast, bool isSecure); /** * @brief Callback to be notified when Ethernet adapter connection state changes. @@ -315,10 +315,12 @@ bool CAEthernetIsConnected(void); * @param callback [IN] Callback to be notified when local Ethernet adapter connection state changes. * @return NONE */ -void CAEthernetSetConnectionStateChangeCallback(CAEthernetConnectionStateChangeCallback callback); +void CAEthernetSetConnectionStateChangeCallback + (CAEthernetConnectionStateChangeCallback callback); #ifdef __cplusplus } #endif #endif //_CA_ETHERNET_INTERFACE_H_ + diff --git a/resource/csdk/connectivity/inc/caethernetinterface_singlethread.h b/resource/csdk/connectivity/inc/caethernetinterface_singlethread.h index a8450d6..9d77503 100644 --- a/resource/csdk/connectivity/inc/caethernetinterface_singlethread.h +++ b/resource/csdk/connectivity/inc/caethernetinterface_singlethread.h @@ -55,8 +55,8 @@ typedef enum * @return NONE * @pre Callback must be registered using CAEthernetSetPacketReceiveCallback() */ -typedef void (*CAEthernetPacketReceivedCallback)(const char *ipAddress, const uint32_t port, - const void *data, const uint32_t dataLength); +typedef void (*CAEthernetPacketReceivedCallback)(const char *ipAddress, uint32_t port, + const void *data, uint32_t dataLength); /** * @brief Callback to be notified when exception occures on multicast/unicast server. @@ -97,7 +97,7 @@ void CAEthernetTerminateServer(void); * @retval #CA_STATUS_FAILED Operation failed */ CAResult_t CAEthernetStartMulticastServer(const char *localAddress, const char *multicastAddress, - const int16_t multicastPort, int32_t *serverFD); + uint16_t multicastPort, int *serverFD); /** * @brief Start unicast server for specified local address and port @@ -115,8 +115,8 @@ CAResult_t CAEthernetStartMulticastServer(const char *localAddress, const char * * @retval #CA_SERVER_STARTED_ALREADY Unicast server is already started and running. * @retval #CA_STATUS_FAILED Operation failed */ -CAResult_t CAEthernetStartUnicastServer(const char *localAddress, int16_t *port, - const bool forceStart, int32_t *serverFD); +CAResult_t CAEthernetStartUnicastServer(const char *localAddress, uint16_t *port, + bool forceStart, int *serverFD); /** * @brief Stop multicast server. @@ -157,7 +157,7 @@ CAResult_t CAEthernetStopSecureUnicastServer(); * @retval #CA_STATUS_FAILED Operation failed * @remarks ipAddress must be freed using free(). */ -CAResult_t CAEthernetGetUnicastServerInfo(char **ipAddress, int16_t *port, int32_t *serverFD); +CAResult_t CAEthernetGetUnicastServerInfo(char **ipAddress, int16_t *port, int *serverFD); /** * @brief Set this callback for receiving data packets from peer devices. @@ -189,14 +189,14 @@ void CAEthernetSetExceptionCallback(CAEthernetExceptionCallback callback); * @param socketFD [IN] Socket descriptor used for sending UDP data. * @return NONE */ -void CAEthernetSetUnicastSocket(const int32_t socketFD); +void CAEthernetSetUnicastSocket(int socketFD); /** * @brief Set the port number for sending unicast UDP data * @param port [IN] Port number used for sending UDP data. * @return NONE */ -void CAEthernetSetUnicastPort(const int16_t port); +void CAEthernetSetUnicastPort(uint16_t port); /** * @brief Set socket description for sending secured (encrypted) unicast UDP data @@ -204,7 +204,7 @@ void CAEthernetSetUnicastPort(const int16_t port); * @param socketFD [IN] Socket descriptor used for sending secured (encrypted) UDP data. * @return NONE */ -void CAEthernetSetSecureUnicastSocket(const int32_t socketFD); +void CAEthernetSetSecureUnicastSocket(int socketFD); /** * @brief API to send unicast UDP data @@ -217,8 +217,8 @@ void CAEthernetSetSecureUnicastSocket(const int32_t socketFD); * * @return The number of bytes sent on the network. Returns 0 on error. */ -uint32_t CAEthernetSendData(const char *remoteAddress, const int16_t port, - const char *buf, const uint32_t bufLen, bool isMulticast); +uint32_t CAEthernetSendData(const char *remoteAddress, uint16_t port, + const char *buf, uint32_t bufLen, bool isMulticast); /** * @brief Callback to be notified when ethernet adapter connection state changes. @@ -229,7 +229,7 @@ uint32_t CAEthernetSendData(const char *remoteAddress, const int16_t port, * @pre Callback must be registered using CAEthernetSetConnectionStateChangeCallback() */ typedef void (*CAEthernetConnectionStateChangeCallback)(const char *ipAddress, - const CANetworkStatus_t status); + CANetworkStatus_t status); /** * @brief Initialize Ethernet network monitor @@ -292,10 +292,12 @@ bool CAEthernetIsConnected(void); * changes. * @return NONE */ -void CAEthernetSetConnectionStateChangeCallback(CAEthernetConnectionStateChangeCallback callback); +void CAEthernetSetConnectionStateChangeCallback + (CAEthernetConnectionStateChangeCallback callback); #ifdef __cplusplus } #endif #endif //_CA_ETHERNET_INTERFACE_SINGLETHREAD_H_ + diff --git a/resource/csdk/connectivity/inc/cainterfacecontroller.h b/resource/csdk/connectivity/inc/cainterfacecontroller.h index 52e8c4c..50e102d 100644 --- a/resource/csdk/connectivity/inc/cainterfacecontroller.h +++ b/resource/csdk/connectivity/inc/cainterfacecontroller.h @@ -36,7 +36,7 @@ extern "C" /** * @brief Initializes different adapters based on the compilation flags. - * @param handle [IN] thread pool handle created by message handler for different adapters. + * @param handle [IN] thread pool handle created by message handler for different adapters. * @return none */ void CAInitializeAdapters(u_thread_pool_t handle); @@ -57,22 +57,22 @@ void CASetNetworkChangeCallback(CANetworkChangeCallback callback); /** * @brief Starting different connectivity adapters based on the network selection. - * @param connectivity [IN] interested network for starting + * @param connectivity [IN] network type that want to start * @return none */ -void CAStartAdapter(CAConnectivityType_t connectivity); +CAResult_t CAStartAdapter(CAConnectivityType_t connectivity); /** * @brief Stopping different connectivity adapters based on the network un-selection. - * @param callback [IN] un selected network for stopping the packets transfer + * @param connectivity [IN] network type that want to stop * @return none */ void CAStopAdapter(CAConnectivityType_t connectivity); /** * @brief Get network information such as ipaddress and mac information - * @param info [OUT] connectivity information such as ipaddress and mac information - * @param size [OUT] number of connectivity information structures + * @param info [OUT] connectivity information such as ipaddress and mac information + * @param size [OUT] number of connectivity information structures * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ CAResult_t CAGetNetworkInfo(CALocalConnectivity_t **info, uint32_t *size); @@ -80,20 +80,20 @@ CAResult_t CAGetNetworkInfo(CALocalConnectivity_t **info, uint32_t *size); /** * @brief Sends unicast data to the remote endpoint * @param endpoint [IN] endpoint information where the data has to be sent - * @param data [IN] data that needs to be sent - * @param length [IN] length of the data that needs to be sent + * @param data [IN] data that needs to be sent + * @param length [IN] length of the data that needs to be sent * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ -CAResult_t CASendUnicastData(const CARemoteEndpoint_t *endpoint, void *data, uint32_t length); +CAResult_t CASendUnicastData(const CARemoteEndpoint_t *endpoint, const void *data, uint32_t length); /** * @brief Sends multicast data to all endpoints in the network. - * @param data [IN] data that needs to be sent - * @param length [IN] length of the data that needs to be sent + * @param data [IN] data that needs to be sent + * @param length [IN] length of the data that needs to be sent * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ -CAResult_t CASendMulticastData(void *data, uint32_t length); +CAResult_t CASendMulticastData(const void *data, uint32_t length); /** * @brief Start listening servers to receive search requests from clients @@ -118,3 +118,4 @@ void CATerminateAdapters(); #endif #endif //#ifndef __CA_INTERFACE_CONTROLLER_H_ + diff --git a/resource/csdk/connectivity/inc/cainterfacecontroller_singlethread.h b/resource/csdk/connectivity/inc/cainterfacecontroller_singlethread.h index dcde405..ef307b9 100644 --- a/resource/csdk/connectivity/inc/cainterfacecontroller_singlethread.h +++ b/resource/csdk/connectivity/inc/cainterfacecontroller_singlethread.h @@ -35,63 +35,67 @@ extern "C" /** * @brief Initializes different adapters based on the compilation flags. - * @param handle [IN] thread pool handle created by message handler for different adapters. + * @param handle [IN] thread pool handle created by message handler for different + * adapters. * @return none */ void CAInitializeAdapters(); /** * @brief Set the received packets callback for message handler - * @param callback [IN] message handler callback to receive packets from different adapters. + * @param callback [IN] message handler callback to receive packets from different + * adapters. * @return none */ void CASetPacketReceivedCallback(CANetworkPacketReceivedCallback callback); /** * @brief Set the network status changed callback for message handler - * @param callback [IN] message handler network status callback to receive network changes. + * @param callback [IN] message handler network status callback to receive network + * changes. * @return none */ void CASetNetworkChangeCallback(CANetworkChangeCallback callback); /** * @brief Starting different connectivity adapters based on the network selection. - * @param connectivity [IN] interested network for starting + * @param connectivity [IN] network type that want to stop * @return none */ -void CAStartAdapter(CAConnectivityType_t connectivity); +CAResult_t CAStartAdapter(CAConnectivityType_t connectivity); /** * @brief Stopping different connectivity adapters based on the network un-selection. - * @param callback [IN] un selected network for stopping the packets transfer + * @param connectivity [IN] un selected network for stopping the packets transfer * @return none */ void CAStopAdapter(CAConnectivityType_t connectivity); /** - * @brief Get network information such as ipaddress and mac information - * @param info [OUT] connectivity information such as ipaddress and mac information - * @param size [OUT] number of connectivity information structures + * @brief Get network information such as ipaddress and mac information. Gets the network + * information of the adapter whichever is enabled. Otherwise info is NULL. + * @param info [OUT] connectivity information such as ipaddress and mac information + * @param size [OUT] number of connectivity information structures * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ CAResult_t CAGetNetworkInfo(CALocalConnectivity_t **info, uint32_t *size); /** * @brief Sends unicast data to the remote endpoint - * @param endpoint [IN] endpoint information where the data has to be sent - * @param data [IN] data that needs to be sent - * @param length [IN] length of the data that needs to be sent + * @param endpoint [IN] endpoint information where the data has to be sent + * @param data [IN] data that needs to be sent + * @param length [IN] length of the data that needs to be sent * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ -CAResult_t CASendUnicastData(const CARemoteEndpoint_t *endpoint, void *data, uint32_t length); +CAResult_t CASendUnicastData(const CARemoteEndpoint_t *endpoint, const void *data, uint32_t length); /** * @brief Sends multicast data to all endpoints in the network. - * @param data [IN] data that needs to be sent - * @param length [IN] length of the data that needs to be sent + * @param data [IN] data that needs to be sent + * @param length [IN] length of the data that needs to be sent * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ -CAResult_t CASendMulticastData(void *data, uint32_t length); +CAResult_t CASendMulticastData(const void *data, uint32_t length); /** * @brief Start listening servers to receive search requests from clients @@ -122,3 +126,4 @@ CAResult_t CAReadData(); #endif #endif //#ifndef __CA_INTERFACE_CONTROLLER_H_ + diff --git a/resource/csdk/connectivity/inc/caleadapter.h b/resource/csdk/connectivity/inc/caleadapter.h index daa2425..799e9e8 100644 --- a/resource/csdk/connectivity/inc/caleadapter.h +++ b/resource/csdk/connectivity/inc/caleadapter.h @@ -38,7 +38,7 @@ extern "C" #endif /** - * @struct CABLEData + * @struct CALEData_t * @brief Stores the information of the Data to be sent from the queues. * This structure will be pushed to the sender/receiver queue for processing. */ @@ -48,7 +48,7 @@ typedef struct *remoteEndpoint; /**< Remote endpoint contains the inforamtion of remote device */ void *data; /**< Data to be transmitted over LE tranport */ uint32_t dataLen; /**< Length of the data being transmitted */ -} CABLEData; +} CALEData_t; /** * @brief Initialize LE connectivity interface. @@ -56,7 +56,7 @@ typedef struct * 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 + * @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 @@ -95,20 +95,20 @@ CAResult_t CAStartLEDiscoveryServer(); * and connectivity type) to which the unicast data has to be sent. * @param data [IN] Data which required to be sent. * @param dataLen [IN] Size of data to be sent. - * @return The number of bytes sent on the network. Returns 0 on error. + * @return The number of bytes sent on the network. Returns -1 on error. * @remarks dataLen must be > 0. */ -uint32_t CASendLEUnicastData(const CARemoteEndpoint_t *endpoint, void *data, +int32_t CASendLEUnicastData(const CARemoteEndpoint_t *endpoint, const void *data, uint32_t dataLen); /** * @brief Sends Multicast data to the endpoint using the LE connectivity. * @param data [IN] Data which required to be sent. * @param dataLen [IN] Size of data to be sent. - * @return The number of bytes sent on the network. Returns 0 on error. + * @return The number of bytes sent on the network. Returns -1 on error. * @remarks dataLen must be > 0. */ -uint32_t CASendLEMulticastData(void *data, uint32_t dataLen); +int32_t CASendLEMulticastData(const void *data, uint32_t dataLen); /** * @brief Starts notification server on EDR adapters. @@ -125,7 +125,7 @@ CAResult_t CAStartLENotifyServer(); * @return The number of bytes sent on the network. Returns 0 on error. * @remarks dataLen must be > 0. */ -uint32_t CASendLENotification(const CARemoteEndpoint_t *endpoint, void *data, +uint32_t CASendLENotification(const CARemoteEndpoint_t *endpoint, const void *data, uint32_t dataLen); /** @@ -170,7 +170,7 @@ void CATerminateLE(); * */ CAResult_t CABLEServerReceivedData(const char *remoteAddress, const char *serviceUUID, - void *data, uint32_t dataLength, uint32_t *sentLength); + const void *data, uint32_t dataLength, uint32_t *sentLength); /** * @brief This function will receive the data from the GattClient and add the data into the @@ -186,7 +186,7 @@ CAResult_t CABLEServerReceivedData(const char *remoteAddress, const char *servic * @retval #CA_STATUS_FAILED Operation failed */ CAResult_t CABLEClientReceivedData(const char *remoteAddress, const char *serviceUUID, - void *data, uint32_t dataLength, uint32_t *sentLength); + const void *data, uint32_t dataLength, uint32_t *sentLength); /** * @brief This function is used to set the NetworkPacket received callback to CA layer from @@ -209,7 +209,7 @@ void CASetBLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callback); * @retval #CA_STATUS_FAILED Operation failed */ CAResult_t CABLEServerSendData(const CARemoteEndpoint_t *remoteEndpoint, - void *data, uint32_t dataLen); + const void *data, uint32_t dataLen); /** * @brief This function will push the data from CA layer to the Sender processor queue. @@ -224,7 +224,7 @@ CAResult_t CABLEServerSendData(const CARemoteEndpoint_t *remoteEndpoint, * @retval #CA_STATUS_FAILED Operation failed */ CAResult_t CABLEClientSendData(const CARemoteEndpoint_t *remoteEndpoint, - void *data, uint32_t dataLen); + const void *data, uint32_t dataLen); /** * @brief This function will be associated with the sender queue for GattServer.This function will @@ -321,7 +321,7 @@ CAResult_t CAInitBleServerQueues(); CAResult_t CAInitBleClientQueues(); /** - * @brief This function will initalize the Receiver queue for GattServer. This will initlialize + * @brief This function will initalize the Receiver queue for GattServer. This will initialize * the queue to process the function CABLEServerSendDataThread() when ever the task is * added to this queue. * @@ -333,7 +333,7 @@ CAResult_t CAInitBleClientQueues(); CAResult_t CAInitBleServerSenderQueue(); /** - * @brief This function will initalize the Receiver queue for GattClient. This will initlialize + * @brief This function will initalize the Receiver queue for GattClient. This will initialize * the queue to process the function CABLEClientSendDataThread() when ever the task is * added to this queue. * @@ -345,7 +345,7 @@ CAResult_t CAInitBleServerSenderQueue(); CAResult_t CAInitBleClientSenderQueue(); /** - * @brief This function will initalize the Receiver queue for GattServer. This will initlialize + * @brief This function will initalize the Receiver queue for GattServer. This will initialize * the queue to process the function CABLEServerDataReceiverHandler() when ever the task * is added to this queue. * @@ -358,7 +358,7 @@ CAResult_t CAInitBleClientSenderQueue(); CAResult_t CAInitBleServerReceiverQueue(); /** - * @brief This function will initalize the Receiver queue for GattClient. This will initlialize + * @brief This function will initalize the Receiver queue for GattClient. This will initialize * the queue to process the function CABLEClientDataReceiverHandler() when ever the task * is added to this queue. * @@ -381,7 +381,7 @@ CAResult_t CAInitBleClientReceiverQueue(); * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets * @retval #CA_STATUS_FAILED Operation failed */ -CABLEData *CACreateBLEData(const CARemoteEndpoint_t *remoteEndpoint, void *data, +CALEData_t *CACreateBLEData(const CARemoteEndpoint_t *remoteEndpoint, const void *data, uint32_t dataLength); /** @@ -389,17 +389,17 @@ CABLEData *CACreateBLEData(const CARemoteEndpoint_t *remoteEndpoint, void *data, * @param bleData [IN] Structure contains the information of a particular data segment. * @return NONE */ -void CAFreeBLEData(CABLEData *bleData); +void CAFreeBLEData(CALEData_t *bleData); /** - * @brief This will be used to intimate device status changes to the LE adapter layer + * @brief This will be used to notify device status changes to the LE adapter layer * @param adapter_state [IN] State of the adapter * @return NONE */ typedef void (*CALEDeviceStateChangedCallback)(CAAdapterState_t adapter_state); /** - * @brief This will be used to intimate network packet recieved from GATTClient to adapter layer. + * @brief This will be used to notify that network packet recieved from GATTClient to adapter layer. * @param remoteAddress [IN] Remote endpoint Address * @param serviceUUID [IN] Service UUID * @param data [IN] Data received @@ -411,11 +411,11 @@ typedef void (*CALEDeviceStateChangedCallback)(CAAdapterState_t adapter_state); * @retval #CA_STATUS_FAILED Operation failed */ typedef CAResult_t (*CABLEClientDataReceivedCallback)(const char *remoteAddress, - const char *serviceUUID, void *data, + const char *serviceUUID, const void *data, uint32_t dataLength, uint32_t *sentLength); /** - * @brief This will be used to intimate network packet recieved from GATTServer to adapter layer. + * @brief This will be used to notify that network packet recieved from GATTServer to adapter layer. * @param remoteAddress [IN] Remote endpoint Address * @param serviceUUID [IN] Service UUID * @param data [IN] Data received @@ -427,7 +427,7 @@ typedef CAResult_t (*CABLEClientDataReceivedCallback)(const char *remoteAddress, * @retval #CA_STATUS_FAILED Operation failed */ typedef CAResult_t (*CABLEServerDataReceivedCallback)(const char *remoteAddress, - const char *serviceUUID, void *data, + const char *serviceUUID, const void *data, uint32_t dataLength, uint32_t *sentLength); #ifdef __cplusplus @@ -435,3 +435,4 @@ typedef CAResult_t (*CABLEServerDataReceivedCallback)(const char *remoteAddress, #endif #endif //#ifndef _CA_LEADAPTER_H_ + diff --git a/resource/csdk/connectivity/inc/caleadapter_singlethread.h b/resource/csdk/connectivity/inc/caleadapter_singlethread.h index cb451ea..f3d5726 100644 --- a/resource/csdk/connectivity/inc/caleadapter_singlethread.h +++ b/resource/csdk/connectivity/inc/caleadapter_singlethread.h @@ -37,7 +37,7 @@ extern "C" #endif /** - * @struct CABLEData + * @struct CALEData_t * @brief Stores the information of the Data to be sent from the queues. * This structure will be pushed to the sender/receiver queue for processing. */ @@ -47,14 +47,14 @@ typedef struct *remoteEndpoint; /**< Remote endpoint contains the inforamtion of remote device */ void *data; /**< Data to be transmitted over LE tranport */ uint32_t dataLen; /**< Length of the data being transmitted */ -} CABLEData; +} CALEData_t; /** * @brief Initialize LE connectivity interface. * @param registerCallback [IN] Callback to register LE interfaces 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 + * @param netCallback [IN] Callback to notify the network additions to Connectivity * Abstraction Layer. * @return #CA_STATUS_OK or Appropriate error code */ @@ -91,20 +91,20 @@ CAResult_t CAStartLEDiscoveryServer(); * and connectivity type) to which the unicast data has to be sent. * @param data [IN] Data which required to be sent. * @param dataLen [IN] Size of data to be sent. - * @return The number of bytes sent on the network. Returns 0 on error. + * @return The number of bytes sent on the network. Returns -1 on error. * @remarks dataLen must be > 0. */ -uint32_t CASendLEUnicastData(const CARemoteEndpoint_t *endpoint, void *data, +int32_t CASendLEUnicastData(const CARemoteEndpoint_t *endpoint, const void *data, uint32_t dataLen); /** * @brief Sends Multicast data to the endpoint using the LE connectivity. * @param data [IN] Data which required to be sent. * @param dataLen [IN] Size of data to be sent. - * @return The number of bytes sent on the network. Returns 0 on error. + * @return The number of bytes sent on the network. Returns -1 on error. * @remarks dataLen must be > 0. */ -uint32_t CASendLEMulticastData(void *data, uint32_t dataLen); +int32_t CASendLEMulticastData(const void *data, uint32_t dataLen); /** * @brief Starts notification server on EDR adapters. @@ -121,7 +121,7 @@ CAResult_t CAStartLENotifyServer(); * @return The number of bytes sent on the network. Returns 0 on error. * @remarks dataLen must be > 0. */ -uint32_t CASendLENotification(const CARemoteEndpoint_t *endpoint, void *data, +uint32_t CASendLENotification(const CARemoteEndpoint_t *endpoint, const void *data, uint32_t dataLen); /** @@ -165,7 +165,7 @@ void CATerminateLE(); * @retval #CA_STATUS_FAILED Operation failed */ CAResult_t CABLEServerReceivedData(const char *remoteAddress, const char *serviceUUID, - void *data, uint32_t dataLength, uint32_t *sentLength); + const void *data, uint32_t dataLength, uint32_t *sentLength); /** * @brief This function will receive the data from the GattClient and add the data into the @@ -181,7 +181,7 @@ CAResult_t CABLEServerReceivedData(const char *remoteAddress, const char *servic * @retval #CA_STATUS_FAILED Operation failed */ CAResult_t CABLEClientReceivedData(const char *remoteAddress, const char *serviceUUID, - void *data, uint32_t dataLength, uint32_t *sentLength); + const void *data, uint32_t dataLength, uint32_t *sentLength); /** * @brief This function is used to set the NetworkPacket received callback to CA layer from @@ -204,7 +204,7 @@ void CASetBLEReqRespAdapterCallback(CANetworkPacketReceivedCallback callback); * @retval #CA_STATUS_FAILED Operation failed */ CAResult_t CABLEServerSendData(const CARemoteEndpoint_t *remoteEndpoint, - void *data, uint32_t dataLen); + const void *data, uint32_t dataLen); /** * @brief This function will push the data from CA layer to the Sender processor queue. @@ -219,7 +219,7 @@ CAResult_t CABLEServerSendData(const CARemoteEndpoint_t *remoteEndpoint, * @retval #CA_STATUS_FAILED Operation failed */ CAResult_t CABLEClientSendData(const CARemoteEndpoint_t *remoteEndpoint, - void *data, uint32_t dataLen); + const void *data, uint32_t dataLen); /** * @brief This function will be associated with the sender queue for GattClient.This function will @@ -253,7 +253,7 @@ void CABLEClientDataReceiverHandler(void *threadData); void CATerminateBleQueues(); /** - * @brief This function will initalize the Receiver queue for GattClient. This will initlialize + * @brief This function will initalize the Receiver queue for GattClient. This will initialize * the queue to process the function CABLEClientDataReceiverHandler() when ever the task * is added to this queue. * @@ -265,7 +265,7 @@ void CATerminateBleQueues(); CAResult_t CAInitBleClientReceiverQueue(); /** - * @brief This function will initalize the Receiver queue for GattServer. This will initlialize + * @brief This function will initalize the Receiver queue for GattServer. This will initialize * the queue to process the function CABLEServerDataReceiverHandler() when ever the task * is added to this queue. * @@ -309,7 +309,7 @@ CAResult_t CAInitBleServerQueues(); CAResult_t CAInitBleClientQueues(); /** - * @brief This function will initalize the Receiver queue for GattServer. This will initlialize + * @brief This function will initalize the Receiver queue for GattServer. This will initialize * the queue to process the function CABLEServerSendDataThread() when ever the task is * added to this queue. * @@ -321,7 +321,7 @@ CAResult_t CAInitBleClientQueues(); CAResult_t CAInitBleServerSenderQueue(); /** - * @brief This function will initalize the Receiver queue for GattClient. This will initlialize + * @brief This function will initalize the Receiver queue for GattClient. This will initialize * the queue to process the function CABLEClientSendDataThread() when ever the task is * added to this queue. * @@ -369,7 +369,7 @@ void CABLEServerSendDataThread(void *threadData); * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets * @retval #CA_STATUS_FAILED Operation failed */ -CABLEData *CACreateBLEData(const CARemoteEndpoint_t *remoteEndpoint, void *data, +CALEData_t *CACreateBLEData(const CARemoteEndpoint_t *remoteEndpoint, const void *data, uint32_t dataLength); /** @@ -377,17 +377,17 @@ CABLEData *CACreateBLEData(const CARemoteEndpoint_t *remoteEndpoint, void *data, * @param bleData [IN] Structure contains the information of a particular data segment. * @return NONE */ -void CAFreeBLEData(CABLEData *bleData); +void CAFreeBLEData(CALEData_t *bleData); /** - * @brief This will be used to intimate device status changes to the LE adapter layer + * @brief This will be used to notify the device status changes to the LE adapter layer * @param adapter_state [IN] State of the adapter * @return NONE */ typedef void (*CALEDeviceStateChangedCallback)(CAAdapterState_t adapter_state); /** - * @brief This will be used to intimate network packet recieved from GATTClient to adapter layer. + * @brief This will be used to notify that network packet recieved from GATTClient to adapter layer. * @param remoteAddress [IN] Remote endpoint Address * @param serviceUUID [IN] Service UUID * @param data [IN] Data received @@ -399,10 +399,10 @@ typedef void (*CALEDeviceStateChangedCallback)(CAAdapterState_t adapter_state); * @retval #CA_STATUS_FAILED Operation failed */ typedef CAResult_t (*CABLEClientDataReceivedCallback)(const char *remoteAddress, - const char *serviceUUID, void *data, uint32_t dataLength, uint32_t *sentLength); + const char *serviceUUID, const void *data, uint32_t dataLength, uint32_t *sentLength); /** - * @brief This will be used to intimate network packet recieved from GATTServer to adapter layer. + * @brief This will be used to notify that network packet recieved from GATTServer to adapter layer. * @param remoteAddress [IN] Remote endpoint Address * @param serviceUUID [IN] Service UUID * @param data [IN] Data received @@ -414,10 +414,11 @@ typedef CAResult_t (*CABLEClientDataReceivedCallback)(const char *remoteAddress, * @retval #CA_STATUS_FAILED Operation failed */ typedef CAResult_t (*CABLEServerDataReceivedCallback)(const char *remoteAddress, - const char *serviceUUID, void *data, uint32_t dataLength, uint32_t *sentLength); + const char *serviceUUID, const void *data, uint32_t dataLength, uint32_t *sentLength); #ifdef __cplusplus } /* extern "C" */ #endif #endif //#ifndef _CA_LEADAPTER_SINGLETHREAD_H_ + diff --git a/resource/csdk/connectivity/inc/calecore.h b/resource/csdk/connectivity/inc/calecore.h index 0eee972..00b23d9 100644 --- a/resource/csdk/connectivity/inc/calecore.h +++ b/resource/csdk/connectivity/inc/calecore.h @@ -34,116 +34,420 @@ extern "C" { #endif +/** + * @brief Callback to be notified on reception of any data from remote devices. + * @param address [IN] MAC address of remote device. + * @param data [IN] Data received from remote device. + * @return NONE + * @pre Callback must be registered using CALESetCallback(CAPacketReceiveCallback callback) + */ typedef void (*CAPacketReceiveCallback)(const char *address, const char *data); +/** + * @brief set context of application + * @param env [IN] JNI interface pointer + * @param context [IN] context of application + * @return None + */ void CALEClientJNISetContext(JNIEnv *env, jobject context); +/** + * @brief create interface object and initialize the object + * @return None + */ void CALeCreateJniInterfaceObject(); +/** + * @brief initialize client for BLE + * @param handle [IN] thread pool handle object + * @return None + */ void CALEInitialize(u_thread_pool_t handle); +/** + * @brief terminate client for BLE + * @return None + */ void CALETerminate(); -void CANativeSendFinsih(JNIEnv *env, jobject gatt); +/** + * @brief for destroy sending routine + * @param env [IN] JNI interface pointer + * @param gatt [IN] Gatt profile object + * @return None + */ +void CANativeSendFinish(JNIEnv *env, jobject gatt); -int32_t CALESendUnicastMessage(const char *address, const char *data, uint32_t dataLen); +/** + * @brief send data for unicast (interface) + * @param address [IN] remote address + * @param data [IN] data for transmission + * @param dataLen [IN] data length + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_STATUS_FAILED Operation failed + */ +CAResult_t CALESendUnicastMessage(const char *address, const char *data, const uint32_t dataLen); -int32_t CALESendMulticastMessage(const char *data, uint32_t dataLen); +/** + * @brief send data for multicast (interface) + * @param data [IN] data for transmission + * @param dataLen [IN] data length + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_STATUS_FAILED Operation failed + */ +CAResult_t CALESendMulticastMessage(const char *data, const uint32_t dataLen); -int32_t CALEStartUnicastServer(const char *address); +/** + * @brief start unicast server + * @param address [IN] remote address + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_STATUS_FAILED Operation failed + */ +CAResult_t CALEStartUnicastServer(const char *address); -int32_t CALEStartMulticastServer(); +/** + * @brief start multicast server (start discovery) + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_STATUS_FAILED Operation failed + */ +CAResult_t CALEStartMulticastServer(); -int32_t CALEStopUnicastServer(int32_t serverID); +/** + * @brief stop unicast server + * @return None + */ +void CALEStopUnicastServer(); -int32_t CALEStopMulticastServer(int32_t serverID); +/** + * @brief stop multicast server (stop discovery) + * @return None + */ +void CALEStopMulticastServer(); +/** + * @brief set this callback for receiving data packets from peer devices. + * @param callback [IN] callback to be notified on reception of + * unicast/multicast data packets. + * @return None + */ void CALESetCallback(CAPacketReceiveCallback callback); +/** + * @brief get local address (interface) + * @param address [OUT] local address + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_STATUS_FAILED Operation failed + */ CAResult_t CALEGetInterfaceInfo(char **address); +/** + * @brief get local address (inplement) + * @param address [OUT] local address + * @return None + */ void CALEGetLocalAddress(char** address); -int32_t CALESendUnicastMessageImpl(const char *address, const char *data, uint32_t dataLen); +/** + * @brief send data for unicast (implement) + * @param address [IN] remote address + * @param data [IN] data for transmission + * @param dataLen [IN] data length + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_STATUS_FAILED Operation failed + */ +CAResult_t CALESendUnicastMessageImpl(const char *address, const char *data, const uint32_t dataLen); -int32_t CALESendMulticastMessageImpl(JNIEnv *env, const char *data, uint32_t dataLen); +/** + * @brief send data for multicast (implement) + * @param address [IN] remote address + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_STATUS_FAILED Operation failed + */ +CAResult_t CALESendMulticastMessageImpl(const char *data, const uint32_t dataLen); /** * BT Common Method : JNI */ +/** + * @brief get address from bluetooth gatt object + * @param env [IN] JNI interface pointer + * @param gatt [IN] Gatt profile object + * @return bluetooth address + */ jstring CANativeGetAddressFromGattObj(JNIEnv *env, jobject gatt); +/** + * @brief get remote address from bluetooth socket object + * @param env [IN] JNI interface pointer + * @param bluetoothSocketObj [IN] bluetooth socket + * @return bluetooth address + */ jstring CANativeGetRemoteAddress(JNIEnv *env, jobject bluetoothSocketObj); /** - * BLE Method : JNI + * @brief close gatt + * @param env [IN] JNI interface pointer + * @param bluetoothGatt [IN] Gatt profile object + * @return None */ void CANativeGattClose(JNIEnv *env, jobject bluetoothGatt); +/** + * @brief start to scan whole bluetooth devices (interface) + * @return None + */ void CANativeLEStartScan(); +/** + * @brief start to scan whole bluetooth devices (implement) + * @param env [IN] JNI interface pointer + * @param callback [IN] callback to receive device object by scanning + * @return None + */ void CANativeLEStartScanImpl(JNIEnv *env, jobject callback); +/** + * @brief start to scan target bluetooth devices for service uuid (implement) + * @param env [IN] JNI interface pointer + * @param uuids [IN] target UUID + * @param callback [IN] callback to receive device object by scanning + * @return None + */ void CANativeLEStartScanWithUUIDImpl(JNIEnv *env, jobjectArray uuids, jobject callback); +/** + * @brief get uuid object + * @param env [IN] JNI interface pointer + * @param uuid [IN] uuid + * @return uuid object + */ jobject CANativeGetUUIDObject(JNIEnv *env, const char *uuid); +/** + * @brief stop scan (interface) + * @return None + */ void CANativeLEStopScan(); +/** + * @brief stop scan (implement) + * @param env [IN] JNI interface pointer + * @param callback [IN] callback to receive device object by scanning + * @return None + */ void CANativeLEStopScanImpl(JNIEnv *env, jobject callback); -int32_t CANativeLEConnect(JNIEnv *env, jobject bluetoothDevice, jobject context, +/** + * @brief connect to gatt server hosted + * @param env [IN] JNI interface pointer + * @param bluetoothDevice [IN] bluetooth Device object + * @param context [IN] context of application + * @param autoconnect [IN] whether to directly connect to the remote device(false) or + * to automatically connect as soon as the remote device + * becomes available + * @param callback [IN] callback for connection state change + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_STATUS_FAILED Operation failed + */ +CAResult_t CANativeLEConnect(JNIEnv *env, jobject bluetoothDevice, jobject context, jboolean autoconnect, jobject callback); +/** + * @brief disconnect to gatt server by a target device + * @param env [IN] JNI interface pointer + * @param bluetoothGatt [IN] Gatt profile object + * @return None + */ void CANativeLEDisconnect(JNIEnv *env, jobject bluetoothGatt); +/** + * @brief disconnect to gatt server by whole devices + * @param env [IN] JNI interface pointer + * @return None + */ void CANativeLEDisconnectAll(JNIEnv *env); +/** + * @brief start discovery server + * @param env [IN] JNI interface pointer + * @param bluetoothGatt [IN] Gatt profile object + * @return None + */ void CANativeLEDiscoverServices(JNIEnv *env, jobject bluetoothGatt); -jboolean CANativeLESendData(JNIEnv *env, jobject bluetoothGatt, jobject gattCharacteristic); +/** + * @brief request to write gatt characteristic + * @param env [IN] JNI interface pointer + * @param bluetoothGatt [IN] Gatt profile object + * @param gattCharacteristic [IN] characteristic object that contain data to send + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_STATUS_FAILED Operation failed + */ +CAResult_t CANativeWriteCharacteristic(JNIEnv *env, jobject bluetoothGatt, jobject gattCharacteristic); +/** + * @brief request to read gatt characteristic + * @param env [IN] JNI interface pointer + * @param bluetoothGatt [IN] Gatt profile object + * @return None + */ void CANativeReadCharacteristic(JNIEnv *env, jobject bluetoothGatt); -jboolean CANativeSetCharacteristicNoti(JNIEnv *env, jobject bluetoothGatt, const char* uuid); +/** + * @brief enable notification for a target device + * @param env [IN] JNI interface pointer + * @param bluetoothGatt [IN] Gatt profile object + * @param uuid [IN] for set BluetoothGattCharacteristic object + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_ADAPTER_NOT_ENABLED Adapter is not enabled + * @retval #CA_STATUS_FAILED Operation failed + */ +CAResult_t CANativeSetCharacteristicNotification(JNIEnv *env, jobject bluetoothGatt, + const char* uuid); +/** + * @brief create gatt characteristic object + * @param env [IN] JNI interface pointer + * @param bluetoothGatt [IN] Gatt profile object + * @param data [IN] for make Characteristic with data + * @return Gatt Characteristic object + */ jobject CANativeCreateGattCharacteristic(JNIEnv *env, jobject bluetoothGatt, jbyteArray data); +/** + * @brief get gatt service + * @param env [IN] JNI interface pointer + * @param bluetoothGatt [IN] Gatt profile object + * @param characterUUID [IN] for make BluetoothGattCharacteristic object + * @return Gatt Service + */ jobject CANativeGetGattService(JNIEnv *env, jobject bluetoothGatt, jstring characterUUID); +/** + * @brief get value from characteristic + * @param env [IN] JNI interface pointer + * @param characteristic [IN] Characteristic object + * @return value in characteristic + */ jbyteArray CANativeGetValueFromCharacteristic(JNIEnv *env, jobject characteristic); +/** + * @brief create UUID List + * @return None + */ void CANativeCreateUUIDList(); + /** * BluetoothDevice List */ +/** + * @brief create scan device list + * @param env [IN] JNI interface pointer + * @return None + */ void CANativeCreateScanDeviceList(JNIEnv *env); +/** + * @brief add device object to scan device list + * @param env [IN] JNI interface pointer + * @param device [IN] bluetooth device object + * @return None + */ void CANativeAddScanDeviceToList(JNIEnv *env, jobject device); +/** + * @brief check whether the device exist in list or not + * @param env [IN] JNI interface pointer + * @param remoteAddress [IN] remote address + * @return TRUE or FALSE + */ jboolean CANativeIsDeviceInList(JNIEnv *env, const char *remoteAddress); +/** + * @brief remove all devices in scan device list + * @param env [IN] JNI interface pointer + * @return None + */ void CANativeRemoveAllDevices(JNIEnv *env); +/** + * @brief remove target device in scan device list + * @param env [IN] JNI interface pointer + * @param remoteAddress [IN] remote address + * @return None + */ void CANativeRemoveDevice(JNIEnv *env, jstring remoteAddress); +/** + * @brief Reordering for scan device list + * @param index [IN] index of device list that want to reordering + * @return None + */ void CAReorderingDeviceList(uint32_t index); /** * BluetoothGatt List */ +/** + * @brief create gatt object list + * @param env [IN] JNI interface pointer + * @return None + */ void CANativeCreateGattObjList(JNIEnv *env); +/** + * @brief add gatt object to gatt object list + * @param env [IN] JNI interface pointer + * @param gatt [IN] Gatt profile object + * @return None + */ void CANativeAddGattobjToList(JNIEnv *env, jobject gatt); +/** + * @brief check whether the gatt object exist in list or not + * @param env [IN] JNI interface pointer + * @param remoteAddress [IN] remote address + * @return TRUE or FALSE + */ jboolean CANativeIsGattObjInList(JNIEnv *env, const char *remoteAddress); +/** + * @brief remove all gatt objects in gatt object list + * @param env [IN] JNI interface pointer + * @return None + */ void CANativeRemoveAllGattObjsList(JNIEnv *env); +/** + * @brief remove target device in gatt object list + * @param env [IN] JNI interface pointer + * @param gatt [IN] Gatt profile object + * @return None + */ void CANativeRemoveGattObj(JNIEnv *env, jobject gatt); +/** + * @brief Reordering for gatt object list + * @param index [IN] index of device list that want to reordering + * @return None + */ void CAReorderingGattList(uint32_t index); +/** + * @brief check whether target device which send data is exist or not + * @param env [IN] JNI interface pointer + * @return None + */ void CANativeupdateSendCnt(JNIEnv *env); #ifdef __cplusplus @@ -151,3 +455,4 @@ void CANativeupdateSendCnt(JNIEnv *env); #endif #endif + diff --git a/resource/csdk/connectivity/inc/caleinterface.h b/resource/csdk/connectivity/inc/caleinterface.h index f7156fa..47c4d2d 100644 --- a/resource/csdk/connectivity/inc/caleinterface.h +++ b/resource/csdk/connectivity/inc/caleinterface.h @@ -37,15 +37,15 @@ extern "C" #endif /** - * @enum TRANSFER_TYPE + * @enum CALETransferType_t * @brief Provide info about different mode of data transfer * This enum is used to differentiate between unicast and multicast data transfer. */ typedef enum { - MULTICAST, /**< When this enum is selected, data will be updated to all OIC servers. */ - UNICAST /**< When this enum is selected, data will be updated to desired OIC Server. */ -} TRANSFER_TYPE; + LE_MULTICAST, /**< When this enum is selected, data will be updated to all OIC servers. */ + LE_UNICAST /**< When this enum is selected, data will be updated to desired OIC Server. */ +} CALETransferType_t; /** @@ -77,14 +77,14 @@ CAResult_t CAGetLEAdapterState(); * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets * @retval #CA_STATUS_FAILED Operation failed */ -CAResult_t CAInitializeLENwkMonitor(); +CAResult_t CAInitializeLENetworkMonitor(); /** * @brief Used to terminate the network monitor layer of the LE adapter. The variables intialized * in CAInitializeLEAdapterController() must be cleared in this function. * @return NONE */ -void CATerminateLENwkMonitor(); +void CATerminateLENetworkMonitor(); /** * @brief This function is used to set the callback for the Device state changes in the adapter. @@ -106,14 +106,14 @@ CAResult_t CASetLEAdapterStateChangedCb(CALEDeviceStateChangedCallback callback) * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets * @retval #CA_STATUS_FAILED Operation failed */ -CAResult_t CAInitLENwkMonitorMutexVaraibles(); +CAResult_t CAInitLENetworkMonitorMutexVariables(); /** * @brief Used to terminate all the mutex variables required to operate the LE network monitor * layer. * @return NONE */ -void CATerminateLENwkMonitorMutexVaraibles(); +void CATerminateLENetworkMonitorMutexVariables(); /** * @brief Provides the BD address of the local adapter. @@ -204,7 +204,7 @@ void CATerminateBLEGattClient(); * @param remoteAddress [IN] The address of the remote device * @param data [IN] The value of characteristic (byte array) * @param dataLen [IN] The length of value - * @param type [IN] Type of the transfer(#TRANSFER_TYPE) + * @param type [IN] Type of the transfer(#CALETransferType_t) * @param position [IN] The unique index of each ble server. Used for multicast feature. * * @return #CA_STATUS_OK or Appropriate error code @@ -213,7 +213,7 @@ void CATerminateBLEGattClient(); * @retval #CA_STATUS_FAILED Operation failed */ CAResult_t CAUpdateCharacteristicsToGattServer(const char *remoteAddress, const char *data, - const int32_t dataLen, TRANSFER_TYPE type, + const int32_t dataLen, CALETransferType_t type, const int32_t position); /** @@ -227,7 +227,7 @@ CAResult_t CAUpdateCharacteristicsToGattServer(const char *remoteAddress, const * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets * @retval #CA_STATUS_FAILED Operation failed */ -CAResult_t CAUpdateCharacteristicsToAllGattServers(const char *data, const int32_t dataLen); +CAResult_t CAUpdateCharacteristicsToAllGattServers(const char *data, int32_t dataLen); /** * @brief Used to store upper layer callback locally which will be used to send the data to @@ -272,3 +272,4 @@ CAResult_t CAUnSetLEAdapterStateChangedCb(); #endif #endif //_CA_LE_INTERFACE_H_ + diff --git a/resource/csdk/connectivity/inc/caleinterface_singlethread.h b/resource/csdk/connectivity/inc/caleinterface_singlethread.h index d088fb1..20ab2fc 100644 --- a/resource/csdk/connectivity/inc/caleinterface_singlethread.h +++ b/resource/csdk/connectivity/inc/caleinterface_singlethread.h @@ -37,15 +37,15 @@ extern "C" #endif /** - * @enum TRANSFER_TYPE + * @enum CALETransferType_t * @brief Provide information about different mode of data transfer * This enum is used to differentiate between unicast and multicast data transfer. */ typedef enum { - MULTICAST, /**< When this enum is selected, data will be updated to all OIC servers. */ - UNICAST /**< When this enum is selected, data will be updated to desired OIC Server. */ -} TRANSFER_TYPE; + LE_MULTICAST, /**< When this enum is selected, data will be updated to all OIC servers. */ + LE_UNICAST /**< When this enum is selected, data will be updated to desired OIC Server. */ +} CALETransferType_t; /** @@ -136,7 +136,7 @@ void CASetBLEReqRespServerCallback(CABLEServerDataReceivedCallback callback); * @retval #CA_STATUS_FAILED Operation failed */ CAResult_t CAUpdateCharacteristicsInGattServer(const char *charValue, - const uint32_t charValueLen); + uint32_t charValueLen); /** * @brief Used to start CAStartBleGattClientThread for initializing Gatt Client @@ -170,7 +170,7 @@ void CATerminateBLEGattClient(); * @param remoteAddress [IN] The address of the remote device * @param data [IN] The value of characteristic (byte array) * @param dataLen [IN] The length of value - * @param type [IN] Type of the transfer(#TRANSFER_TYPE) + * @param type [IN] Type of the transfer(#CALETransferType_t) * @param position [IN] The unique index of each ble server. Used for multicast feature. * * @return #CA_STATUS_OK or Appropriate error code @@ -179,7 +179,7 @@ void CATerminateBLEGattClient(); * @retval #CA_STATUS_FAILED Operation failed */ CAResult_t CAUpdateCharacteristicsToGattServer(const char *remoteAddress, const char *data, - const int32_t dataLen, TRANSFER_TYPE type, + const int32_t dataLen, CALETransferType_t type, const int32_t position); /** @@ -193,8 +193,7 @@ CAResult_t CAUpdateCharacteristicsToGattServer(const char *remoteAddress, const * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets * @retval #CA_STATUS_FAILED Operation failed */ -CAResult_t CAUpdateCharacteristicsToAllGattServers(const char *data, - const int32_t dataLen); +CAResult_t CAUpdateCharacteristicsToAllGattServers(const char *data, int32_t dataLen); /** * @brief Used to store upper layer callback locally which will be used to send the data to @@ -210,3 +209,4 @@ void CASetBLEReqRespClientCallback(CABLEClientDataReceivedCallback callback); #endif #endif //_CA_LE_INTERFACE_SINGLETHREAD_H_ + diff --git a/resource/csdk/connectivity/inc/calenwmonitor.h b/resource/csdk/connectivity/inc/calenwmonitor.h index 6706cd8..39d592b 100644 --- a/resource/csdk/connectivity/inc/calenwmonitor.h +++ b/resource/csdk/connectivity/inc/calenwmonitor.h @@ -35,12 +35,33 @@ extern "C" { #endif +/** + * @var CALENetStateChantedCallback + * @brief Maintains network connection state change callback. + */ typedef void (*CALENetStateChantedCallback)(const char* address, const uint32_t status); +/** + * @brief set context of application + * @param env [IN] JNI interface pointer + * @param context [IN] context of application + * @return None + */ void CALENetworkMonitorJNISetContext(JNIEnv *env, jobject context); +/** + * @brief initialize JNI object + * @param env [IN] JNI interface pointer + * @param jvm [IN] java virtual machine pointer + * @return None + */ void CALeNetworkMonitorJniInit(JNIEnv *env, JavaVM *jvm); +/** + * @brief Set this callback for receiving network information from BT stack. + * @param callback [IN] Callback to be notified on reception of BT state information + * @return NONE + */ void CALESetNetStateCallback(CALENetStateChantedCallback callback); #ifdef __cplusplus @@ -50,3 +71,4 @@ void CALESetNetStateCallback(CALENetStateChantedCallback callback); #endif + diff --git a/resource/csdk/connectivity/inc/caleserver.h b/resource/csdk/connectivity/inc/caleserver.h index 4541b6d..28a1bce 100644 --- a/resource/csdk/connectivity/inc/caleserver.h +++ b/resource/csdk/connectivity/inc/caleserver.h @@ -22,8 +22,8 @@ * @file calecore.h * @brief This file contains the APIs for BT LE communications. */ -#ifndef __CA_LECORE_H_ -#define __CA_LECORE_H_ +#ifndef __CA_LESERVER_H_ +#define __CA_LESERVER_H_ #include "cacommon.h" #include "uthreadpool.h" @@ -35,88 +35,323 @@ extern "C" { #endif +/** + * @brief Callback to be notified on reception of any data from remote devices. + * @param address [IN] MAC address of remote device. + * @param data [IN] Data received from remote device. + * @return None + * @pre Callback must be registered using CALEServerSetCallback(CAPacketReceiveCallback callback) + */ typedef void (*CAPacketReceiveCallback)(const char *address, const char *data); +/** + * @brief initialize server for BLE + * @param handle [IN] thread pool handle object + * @return None + */ void CALEServerInitialize(u_thread_pool_t handle); +/** + * @brief terminate client for BLE + * @return None + */ void CALEServerTerminate(); -int32_t CALEServerSendUnicastMessage(const char *address, const char *data, +/** + * @brief send data for unicast (interface) + * @param address [IN] remote address + * @param data [IN] data for transmission + * @param dataLen [IN] data length + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_STATUS_FAILED Operation failed + */ +CAResult_t CALEServerSendUnicastMessage(const char *address, const char *data, uint32_t dataLen); -int32_t CALEServerSendMulticastMessage(const char *data, uint32_t dataLen); +/** + * @brief send data for multicast (interface) + * @param data [IN] data for transmission + * @param dataLen [IN] data length + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_STATUS_FAILED Operation failed + */ +CAResult_t CALEServerSendMulticastMessage(const char *data, uint32_t dataLen); -int32_t CALEServerStartUnicastServer(const char *address); +/** + * @brief start unicast server + * @param address [IN] remote address + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_STATUS_FAILED Operation failed + */ +CAResult_t CALEServerStartUnicastServer(const char *address); -int32_t CALEServerStartMulticastServer(); +/** + * @brief start multicast server (start advertise) + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_STATUS_FAILED Operation failed + */ +CAResult_t CALEServerStartMulticastServer(); -int32_t CALEServerStopUnicastServer(int32_t serverID); +/** + * @brief stop unicast server + * @return None + */ +CAResult_t CALEServerStopUnicastServer(); -int32_t CALEServerStopMulticastServer(int32_t serverID); +/** + * @brief stop multicast server (stop discovery) + * @return None + */ +CAResult_t CALEServerStopMulticastServer(); +/** + * @brief set this callback for receiving data packets from peer devices. + * @param callback [IN] callback to be notified on reception of + * unicast/multicast data packets. + * @return None + */ void CALEServerSetCallback(CAPacketReceiveCallback callback); +/** + * @brief Get local adapter network information. + * @param info [OUT] local connectivity information + * @param size [OUT] connectivity count + * @return None + */ void CALEServerGetInterfaceInfo(CALocalConnectivity_t **info, uint32_t *size); +/** + * @brief get local address + * @param address [OUT] local address + * @return None + */ void CALEServerGetLocalAddress(char *address); -int32_t CALEServerSendUnicastMessageImpl(JNIEnv *env, const char *address, +/** + * @brief send data for unicast (implement) + * @param env [IN] JNI interface pointer + * @param address [IN] remote address + * @param data [IN] data for transmission + * @param dataLen [IN] data length + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_STATUS_FAILED Operation failed + */ +CAResult_t CALEServerSendUnicastMessageImpl(JNIEnv *env, const char *address, const char *data, uint32_t dataLen); -int32_t CALEServerSendMulticastMessageImpl(JNIEnv *env, const char *data, +/** + * @brief send data for multicast (implement) + * @param env [IN] JNI interface pointer + * @param address [IN] remote address + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_STATUS_FAILED Operation failed + */ +CAResult_t CALEServerSendMulticastMessageImpl(JNIEnv *env, const char *data, uint32_t dataLen); -/* BLE Server Functions */ - +/* Android BLE Server Functions */ +/** + * @brief set context of application + * @param env [IN] JNI interface pointer + * @param context [IN] context of application + * @return None + */ void CALEServerJNISetContext(JNIEnv *env, jobject context); +/** + * @brief initialize JNI object + * @param env [IN] JNI interface pointer + * @param jvm [IN] java virtual machine pointer + * @return None + */ void CALeServerJniInit(JNIEnv *env, JavaVM* jvm); +/** + * @brief create interface object and initialize the object + * @return None + */ void CALeServerCreateJniInterfaceObject(); +/** + * @brief start advertise in gatt server + * @param env [IN] JNI interface pointer + * @param advertiseCallback [IN] callback to be notified on reception of + * advertisement result + * @return None + */ void CANativeLEServerStartAdvertise(JNIEnv *env, jobject advertiseCallback); +/** + * @brief stop advertise in gatt server + * @param env [IN] JNI interface pointer + * @param advertiseCallback [IN] callback to be notified on reception of + * advertisement result + * @return None + */ void CANativeLEServerStopAdvertise(JNIEnv *env, jobject advertiseCallback); +/** + * @brief open a gatt server + * @param env [IN] JNI interface pointer + * @return gatt server object + */ jobject CANativeLEServerOpenGattServer(JNIEnv *env); +/** + * @brief create gatt service + * @param env [IN] JNI interface pointer + * @return gatt service object + */ jobject CANativeLEServerCreateGattService(JNIEnv *env); -jboolean CANativeLEServerAddGattService(JNIEnv *env, jobject bluetoothGattServer, +/** + * @brief create gatt service + * @param env [IN] JNI interface pointer + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_ADAPTER_NOT_ENABLED Adapter is not enabled + * @retval #CA_STATUS_FAILED Operation failed + */ +CAResult_t CANativeLEServerAddGattService(JNIEnv *env, jobject bluetoothGattServer, jobject bluetoothGattService); -jboolean CALEStartGattServer(JNIEnv *env, jobject gattServerCallback); +/** + * @brief start gatt server + * @param env [IN] JNI interface pointer + * @param gattServerCallback [IN] callback to be notified on reception of + * state change of gatt server + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_ADAPTER_NOT_ENABLED Adapter is not enabled + * @retval #CA_STATUS_FAILED Operation failed + */ +CAResult_t CALEStartGattServer(JNIEnv *env, jobject gattServerCallback); -jboolean CALEServerSend(JNIEnv *env, jobject bluetoothDevice, jstring data); +/** + * @brief send data + * @param env [IN] JNI interface pointer + * @param bluetoothDevice [IN] bluetooth device object + * @param data [IN] data which send + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_SEND_FAILED Send request failed + * @retval #CA_ADAPTER_NOT_ENABLED Adapter is not enabled + * @retval #CA_STATUS_FAILED Operation failed + */ +CAResult_t CALEServerSend(JNIEnv *env, jobject bluetoothDevice, jstring data); +/** + * @brief set data in BluetoothGattCharacteristic + * @param env [IN] JNI interface pointer + * @param bluetoothDevice [IN] bluetooth device object + * @return BluetoothGattCharacteristic object + */ jobject CANativeLEServerSetResponseData(JNIEnv *env, jbyteArray responseData); -jboolean CANativeLEServerSendResponseData(JNIEnv *env, jobject device, jobject responseData); +/** + * @brief send data through notifyCharacteristicChanged api of android + * @param env [IN] JNI interface pointer + * @param bluetoothDevice [IN] bluetooth device object + * @param data [IN] data which send + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_SEND_FAILED Send request failed + * @retval #CA_STATUS_FAILED Operation failed + */ +CAResult_t CANativeLEServerSendResponseData(JNIEnv *env, jobject device, jobject responseData); -jboolean CANativeLEServerSendResponse(JNIEnv *env, jobject device, jint requestId, jint status, +/** + * @brief send a response to a write request to a remote device + * @param env [IN] JNI interface pointer + * @param device [IN] bluetooth device object + * @param requestId [IN] the id of request + * @param status [IN] the status of the request to be sent to the remote devices + * @param offset [IN] value offset for partial write response + * @param value [IN] the value of the attribute that written (optional) + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_SEND_FAILED Send request failed + * @retval #CA_ADAPTER_NOT_ENABLED Adapter is not enabled + * @retval #CA_STATUS_FAILED Operation failed + */ +CAResult_t CANativeLEServerSendResponse(JNIEnv *env, jobject device, jint requestId, jint status, jint offset, jbyteArray value); -jboolean CANativeLEServerConnect(JNIEnv *env, jobject bluetoothDevice); +/** + * @brief connect BLE to remote device form gatt server + * @param env [IN] JNI interface pointer + * @param bluetoothDevice [IN] bluetooth device object + * @return #CA_STATUS_OK or Appropriate error code + * @retval #CA_STATUS_OK Successful + * @retval #CA_ADAPTER_NOT_ENABLED Adapter is not enabled + * @retval #CA_STATUS_FAILED Operation failed + */ +CAResult_t CANativeLEServerConnect(JNIEnv *env, jobject bluetoothDevice); +/** + * @brief disconnect BLE to remote device form gatt server + * @param env [IN] JNI interface pointer + * @param bluetoothDevice [IN] bluetooth device object + * @return None + */ void CANativeLEServerDisconnect(JNIEnv *env, jobject bluetoothDevice); /* BLE Server Utils */ +/** + * @brief create connected device list + * @return None + */ void CALEServerCreateCachedDeviceList(); +/** + * @brief check whether the device exist in the list or not + * @param env [IN] JNI interface pointer + * @param remoteAddress [IN] remote address + * @return TRUE or FALSE + */ jboolean CALEServerIsDeviceInList(JNIEnv *env, const char* remoteAddress); +/** + * @brief add device object to the list (connected device list) + * @param env [IN] JNI interface pointer + * @param device [IN] bluetooth device object + * @return None + */ void CALEServerAddDeviceToList(JNIEnv *env, jobject device); +/** + * @brief remove all devices objects in the list (connected device list) + * @param env [IN] JNI interface pointer + * @return None + */ void CALEServerRemoveAllDevices(JNIEnv *env); +/** + * @brief remove target device in the list (connected device list) + * @param env [IN] JNI interface pointer + * @param gatt [IN] Gatt profile object + * @return None + */ void CALEServerRemoveDevice(JNIEnv *env, jstring address); +/** + * @brief Reordering for the list (connected device list) + * @param index [IN] index of device list that want to reordering + * @return None + */ void CALEServerReorderinglist(uint32_t index); #ifdef __cplusplus } /* extern "C" */ #endif -#endif +#endif /* __CA_LESERVER_H_ */ + diff --git a/resource/csdk/connectivity/inc/caleutils.h b/resource/csdk/connectivity/inc/caleutils.h index 35546d6..2ea806a 100644 --- a/resource/csdk/connectivity/inc/caleutils.h +++ b/resource/csdk/connectivity/inc/caleutils.h @@ -35,18 +35,56 @@ extern "C" { #endif +/** + * @brief get uuid(jni object) from uuid(character) + * @param env [IN] JNI interface pointer + * @param uuid [IN] uuid(character) + * @return uuid(jni object) + */ jobject CALEGetUuidFromString(JNIEnv *env, const char* uuid); +/** + * @brief get parcel uuid object + * @param env [IN] JNI interface pointer + * @param uuid [IN] uuid (jni object) + * @return parcel uuid object + */ jobject CALEGetParcelUuid(JNIEnv *env, jobject uuid); +/** + * @brief get address from a local device + * @param env [IN] JNI interface pointer + * @return local address + */ jstring CALEGetLocalDeviceAddress(JNIEnv *env); +/** + * @brief get bonded list + * @param env [IN] JNI interface pointer + * @return bonded list + */ jobjectArray CALEGetBondedDevices(JNIEnv *env); +/** + * @brief get constants information of bluetooth state-on + * @param env [IN] JNI interface pointer + * @return constants information of bluetooth state-on + */ jint CALEGetBTStateOnInfo(JNIEnv *env); +/** + * @brief get bluetooth adapter state information + * @param env [IN] JNI interface pointer + * @return true if the local adapter is turned on + */ jboolean CALEIsEnableBTAdapter(JNIEnv *env); +/** + * @brief get address from remote device + * @param env [IN] JNI interface pointer + * @param bluetoothDevice [IN] bluetooth device object + * @return remote address + */ jstring CALEGetAddressFromBTDevice(JNIEnv *env, jobject bluetoothDevice); #ifdef __cplusplus @@ -54,3 +92,4 @@ jstring CALEGetAddressFromBTDevice(JNIEnv *env, jobject bluetoothDevice); #endif #endif + diff --git a/resource/csdk/connectivity/inc/camessagehandler.h b/resource/csdk/connectivity/inc/camessagehandler.h index a914d3c..d51bfa0 100644 --- a/resource/csdk/connectivity/inc/camessagehandler.h +++ b/resource/csdk/connectivity/inc/camessagehandler.h @@ -36,7 +36,7 @@ extern "C" /** * @brief Detaches control from the caller for sending unicast request * @param endpoint [IN] endpoint information where the data has to be sent - * @param request [IN] request that needs to be sent + * @param request [IN] request that needs to be sent * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ CAResult_t CADetachRequestMessage(const CARemoteEndpoint_t *endpoint, @@ -45,7 +45,7 @@ CAResult_t CADetachRequestMessage(const CARemoteEndpoint_t *endpoint, /** * @brief Detaches control from the caller for sending multicast request * @param endpoint [IN] endpoint information where the data has to be sent - * @param request [IN] request that needs to be sent + * @param request [IN] request that needs to be sent * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ CAResult_t CADetachRequestToAllMessage(const CAGroupEndpoint_t *object, @@ -54,7 +54,7 @@ CAResult_t CADetachRequestToAllMessage(const CAGroupEndpoint_t *object, /** * @brief Detaches control from the caller for sending response * @param endpoint [IN] endpoint information where the data has to be sent - * @param response [IN] request that needs to be sent + * @param response [IN] request that needs to be sent * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ CAResult_t CADetachResponseMessage(const CARemoteEndpoint_t *endpoint, @@ -62,19 +62,19 @@ CAResult_t CADetachResponseMessage(const CARemoteEndpoint_t *endpoint, /** * @brief Detaches control from the caller for sending request - * @param resourceUri [IN] resource uri that needs to be sent in the request - * @param token [IN] token information of the request - * @param options [IN] header options that need to be append in the request - * @param numOptions [IN] number of options be appended + * @param resourceUri [IN] resource uri that needs to be sent in the request + * @param token [IN] token information of the request + * @param options [IN] header options that need to be append in the request + * @param numOptions [IN] number of options be appended * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ CAResult_t CADetachMessageResourceUri(const CAURI_t resourceUri, const CAToken_t token, - const CAHeaderOption_t *options, uint8_t numOptions); + const CAHeaderOption_t *options, const uint8_t numOptions); /** * @brief Setting the request and response callbacks for network packets - * @param ReqHandler [IN] callback for receiving the requests - * @param RespHandler [IN] callback for receiving the response + * @param ReqHandler [IN] callback for receiving the requests + * @param RespHandler [IN] callback for receiving the response * @return void */ void CASetRequestResponseCallbacks(CARequestCallback ReqHandler, @@ -102,3 +102,4 @@ void CAHandleRequestResponseCallbacks(); #endif #endif //#ifndef __CA_MESSAGE_HANDLER_H_ + diff --git a/resource/csdk/connectivity/inc/camessagehandler_singlethread.h b/resource/csdk/connectivity/inc/camessagehandler_singlethread.h index 62550c6..65c5378 100644 --- a/resource/csdk/connectivity/inc/camessagehandler_singlethread.h +++ b/resource/csdk/connectivity/inc/camessagehandler_singlethread.h @@ -37,18 +37,12 @@ extern "C" #endif /** - * @brief Function pointer for message handler callback - */ -typedef void (*CAMessageHandlerCallback)(CAToken_t token, CAResult_t res); - - -/** * @brief Detaches control from the caller for sending unicast request * @param endpoint [IN] endpoint information where the data has to be sent - * @param request [IN] request that needs to be sent + * @param request [IN] request that needs to be sent * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ -CAResult_t CADetachRequestMessage(const CARemoteEndpoint_t *object, +CAResult_t CADetachRequestMessage(const CARemoteEndpoint_t *endpoint, const CARequestInfo_t *request); /** @@ -62,8 +56,8 @@ CAResult_t CADetachRequestToAllMessage(const CAGroupEndpoint_t *object, /** * @brief Detaches control from the caller for sending response - * @param endpoint [IN] endpoint information where the data has to be sent - * @param response [IN] request that needs to be sent + * @param object [IN] endpoint information where the data has to be sent + * @param response [IN] request that needs to be sent * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ CAResult_t CADetachResponseMessage(const CARemoteEndpoint_t *object, @@ -71,35 +65,27 @@ CAResult_t CADetachResponseMessage(const CARemoteEndpoint_t *object, /** * @brief Detaches control from the caller for sending request - * @param resourceUri [IN] resource uri that needs to be sent in the request - * @param token [IN] token information of the request - * @param options [IN] header options that need to be append in the request - * @param numOptions [IN] number of options be appended + * @param resourceUri [IN] resource uri that needs to be sent in the request + * @param token [IN] token information of the request + * @param options [IN] header options that need to be append in the request + * @param numOptions [IN] number of options be appended * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ CAResult_t CADetachMessageResourceUri(const CAURI_t resourceUri, const CAToken_t token, const CAHeaderOption_t *options, uint8_t numOptions); - -/** - * @brief Setting the message callback - * @param callback [IN] callback will be called after data is processed - * @return void - */ -void CASetMessageHandlerCallback(CAMessageHandlerCallback callback); - /** * @brief Setting the request and response callbacks for network packets * @param ReqHandler [IN] callback for receiving the requests * @param RespHandler [IN] callback for receiving the response * @return void */ -void CASetRequestResponseCallbacks(CARequestCallback ReqHandler, - CAResponseCallback RespHandler); +void CASetRequestResponseCallbacks(CARequestCallback ReqHandler, + CAResponseCallback RespHandler); /** - * @brief Initialize the message handler by starting thread pool and initializing the - * send and reive queue + * @brief Initialize the message handler by starting thread pool and initializing the + * send and receive queue * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ CAResult_t CAInitializeMessageHandler(); @@ -120,3 +106,4 @@ void CAHandleRequestResponseCallbacks(); #endif #endif //#ifndef __CA_MESSAGE_HANDLER_SINGLETHREAD_H_ + diff --git a/resource/csdk/connectivity/inc/camsgparser.h b/resource/csdk/connectivity/inc/camsgparser.h index eabca3a..1da013b 100644 --- a/resource/csdk/connectivity/inc/camsgparser.h +++ b/resource/csdk/connectivity/inc/camsgparser.h @@ -94,37 +94,23 @@ extern "C" #endif /***************************************************************** - * @file The CA Header format * - * @brief CA Header will be difined by 2 bytes of Header. * - * First two bits : Header version * - * Third bit nad fourth bit: Reserved and will be set as Zero. * - * 5th to 16th bit : 12 bits to provide the length of the data in bits. * - * * + * @file The CA Header format + * @brief CA Header will be difined by 2 bytes of Header. + * First two bits : Header version(Currently Its not being used) + * Third bit and fourth bit: Reserved bits for future use. + * 5th to 16th bit : 12 bits to provide the length of the data. *****************************************************************/ - -/** -* @fn printBinaryFormat -* @brief This function prints the binary format of one byte of data -* This functoin is added as debug utility and can be used to check the -* bits set in header while framing/parsing. -* -* @param[in] data Pointer to the charcter data which needs to be printed. -* -* @return 0 on failure and 1 on success. -*/ -void printBinaryFormat(char *data); - /** * @fn CAGenerateHeader * @brief This function is used to generate the CA specific header to maintain the fragmentation * logic. The header sturcture explained above will be formed and returned to the caller. * * @param[in] data Pointer to the charcter data which needs to be printed. -* @param[in] length The total legth of the data which ll be represed from 5th -16th bits +* @param[in] length The total legth of the data which will be represented from 5th -16th bits * in the header. * -* @return 0 on success otherwise a positive error value. +* @return CA_STATUS_OK on success. One of theCA_STATUS_FAILED or other error values on error. * @retval CA_STATUS_OK Successful * @retval CA_STATUS_INVALID_PARAM Invalid input argumets * @retval CA_STATUS_FAILED Operation failed @@ -148,3 +134,4 @@ uint32_t CAParseHeader(const char *header); #endif #endif // _CA_MSG_PARSER_H_ + diff --git a/resource/csdk/connectivity/inc/canetworkconfigurator.h b/resource/csdk/connectivity/inc/canetworkconfigurator.h index ef120f9..c74e099 100644 --- a/resource/csdk/connectivity/inc/canetworkconfigurator.h +++ b/resource/csdk/connectivity/inc/canetworkconfigurator.h @@ -19,7 +19,7 @@ ******************************************************************/ /** * @file canetworkconfigurator.h - * @brief This file contains utility function for network configurations. + * @brief This file contains utility functions for network configurations. */ #ifndef _NETWORK_CONFIGURATOR_H_ @@ -35,17 +35,17 @@ extern "C" /** * @brief Add network type to the selected networks for network packets reception - * @param CAConnectivityType [IN] connectivity type that needs to be added + * @param connectivityType [IN] connectivity type that needs to be added * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ -CAResult_t CAAddNetworkType(uint32_t CAConnectivityType); +CAResult_t CAAddNetworkType(CAConnectivityType_t connectivityType); /** - * @brief Add network type to the un selected for network packets reception - * @param CAConnectivityType [IN] connectivity type that needs to be removed + * @brief Remove network type from the selected configuration + * @param connectivityType [IN] connectivity type that needs to be removed * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ -CAResult_t CARemoveNetworkType(uint32_t CAConnectivityType); +CAResult_t CARemoveNetworkType(CAConnectivityType_t connectivityType); /** * @brief Get selected network information @@ -61,6 +61,10 @@ u_arraylist_t *CAGetSelectedNetworkList(); */ CAResult_t CAGetNetworkInformationInternal(CALocalConnectivity_t **info, uint32_t *size); +/** + * @brief Terminate network type from selected configuration + * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) + */ CAResult_t CATerminateNetworkType(); @@ -69,3 +73,4 @@ CAResult_t CATerminateNetworkType(); #endif #endif //#ifndef _NETWORK_CONFIGURATOR_H_ + diff --git a/resource/csdk/connectivity/inc/caprotocolmessage.h b/resource/csdk/connectivity/inc/caprotocolmessage.h index ee91e27..d6d8540 100644 --- a/resource/csdk/connectivity/inc/caprotocolmessage.h +++ b/resource/csdk/connectivity/inc/caprotocolmessage.h @@ -39,9 +39,9 @@ typedef uint32_t code_t; /** * @brief generates pdu structure from the given information. - * @param uri [IN] uri information of the pdu - * @param code [IN] cod of the pdu packet - * @param info [IN] pdu information such as request code ,response code and payload + * @param uri [IN] uri information of the pdu + * @param code [IN] code of the pdu packet + * @param info [IN] pdu information such as request code, response code, payload * @return coap_pdu_t created pdu */ coap_pdu_t *CAGeneratePdu(const char *uri, const uint32_t code, const CAInfo_t info); @@ -52,58 +52,41 @@ coap_pdu_t *CAGeneratePdu(const char *uri, const uint32_t code, const CAInfo_t i /** * @brief extracts request information from received pdu. - * @param pdu [IN] received pdu - * @param outReqInfo [OUT] request info structure made from received pdu + * @param pdu [IN] received pdu + * @param outReqInfo [OUT] request info structure made from received pdu * @param outUri [OUT] uri received in the received pdu - * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) + * @param buflen [IN] Buffer Length for outUri parameter + * @return None */ -uint32_t CAGetRequestInfoFromPdu(const coap_pdu_t *pdu, CARequestInfo_t *outReqInfo, - char *outUri); +void CAGetRequestInfoFromPdu(const coap_pdu_t *pdu, CARequestInfo_t *outReqInfo, char *outUri, + uint32_t buflen); /** * @brief extracts response information from received pdu. - * @param pdu [IN] received pdu - * @param outResInfo [OUT] request info structure made from received pdu + * @param pdu [IN] received pdu + * @param outResInfo [OUT] response info structure made from received pdu * @param outUri [OUT] uri received in the received pdu - * @return 0 or 1 ( CAResult_t error codes in cacommon.h) + * @param buflen [IN] Buffer Length for outUri parameter + * @return None */ -uint32_t CAGetResponseInfoFromPdu(const coap_pdu_t *pdu, CAResponseInfo_t *outResInfo, - char *outUri); +void CAGetResponseInfoFromPdu(const coap_pdu_t *pdu, CAResponseInfo_t *outResInfo, char *outUri, + uint32_t buflen); /** * @brief creates pdu from the request information * @param code [IN] request or response code - * @param options [IN] options for the request and response - * @param info [IN] pdu information such as request code ,response code - * @return coap_pdu_t - */ -coap_pdu_t *CACreatePDUforRequest(const code_t code, coap_list_t *options, - const CAInfo_t info); - -/** - * @brief creates pdu for ACK or RESET type - * @param code [IN] request or response code - * @param info [IN] pdu information such as response code - * @return coap_pdu_t - */ -coap_pdu_t *CACreatePDUforRSTandACK(const code_t code, const CAInfo_t info); - -/** - * @brief creates pdu from the request information and paylod - * @param code [IN] request or response code alloted - * @param options [IN] options for the request and response backpacked + * @param options [OUT] options for the request and response + * @param info [IN] information to create pdu * @param payload [IN] payload for the request or response consumed - * @param info [IN] pdu information such as request code ,response code * @return coap_pdu_t */ - -coap_pdu_t *CACreatePDUforRequestWithPayload(const code_t code, coap_list_t *optlist, - const char *payload, const CAInfo_t info); +coap_pdu_t *CAGeneratePduImpl(const code_t code, coap_list_t *options, const CAInfo_t info, + const char *payload); /** * @brief parse the URI and creates the options * @param uriInfo [IN] uri information - * @param options [IN] options information + * @param options [OUT] options information * @return None */ void CAParseURI(const char *uriInfo, coap_list_t **options); @@ -112,23 +95,23 @@ void CAParseURI(const char *uriInfo, coap_list_t **options); * @brief create option list from header information in the info * @param code [IN] uri information * @param info [IN] options information - * @param optlist [IN] options information + * @param optlist [OUT] options information * @return None */ void CAParseHeadOption(const uint32_t code, const CAInfo_t info, coap_list_t **optlist); /** - * @brief creates option node from key lenght and data + * @brief creates option node from key length and data * @param key [IN] key for the that needs to be sent * @param length [IN] length of the data that needs to be sent * @param data [IN] data that needs to be sent * @return created list */ -coap_list_t *CACreateNewOptionNode(const uint16_t key, const uint32_t length, - const uint8_t *data); +coap_list_t *CACreateNewOptionNode(const uint16_t key, const uint32_t length, const uint8_t *data); /** * @brief order the inserted options + * need to replace queue head if new node has to be added before the existing queue head * @param a [IN] option 1 for insertion * @param b [IN] option 2 for insertion * @return 0 or 1 @@ -146,43 +129,34 @@ uint32_t CAGetOptionCount(coap_opt_iterator_t opt_iter); * @brief gets option data * @param data [IN] data that is received * @param length [IN] length of the data - * @param result [IN] result of the operation + * @param option [OUT] option * @param buflen [IN] buffer length of the result - * @param encode_always [IN] encoded data - * @return 0 or 1 + * @return option count */ -uint32_t CAGetOptionData(const uint8_t *data, uint32_t len, uint8_t *result, uint32_t buflen, - uint32_t encode_always); +uint32_t CAGetOptionData(const uint8_t *data, uint32_t len, uint8_t *option, uint32_t buflen); /** * @brief extracts request information from received pdu. - * @param pdu [IN] received pdu + * @param pdu [IN] received pdu * @param outCode [OUT] code of the received pdu * @param outInfo [OUT] request info structure made from received pdu * @param outUri [OUT] uri received in the received pdu + * @param buflen [IN] Buffer Length for outUri parameter * @return None */ -void CAGetRequestPDUInfo(const coap_pdu_t *pdu, uint32_t *outCode, CAInfo_t *outInfo, - char *outUri); +void CAGetInfoFromPDU(const coap_pdu_t *pdu, uint32_t *outCode, CAInfo_t *outInfo, char *outUri, + uint32_t buflen); /** - * @brief create pdu fromn received data + * @brief create pdu from received data * @param data [IN] received data * @param length [IN] length of the data received - * @param outCode [IN] code received + * @param outCode [OUT] code received * @return None */ coap_pdu_t *CAParsePDU(const char *data, uint32_t length, uint32_t *outCode); /** - * @brief get Token fromn received data(pdu) - * @param pdu [IN] received pdu - * @param outCode [IN] Token received - * @return None - */ -CAResult_t CAGetTokenFromPDU(const coap_hdr_t *pdu_hdr, CAInfo_t *outInfo); - -/** * @brief generates the token * @param token [OUT] generated token * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) @@ -199,10 +173,10 @@ void CADestroyTokenInternal(CAToken_t token); /** * @brief destroy the ca info structure - * @param info [IN] info structure created from received packet + * @param info [IN] info structure created from received packet * @return none */ -void CADeinitialize(CAInfo_t *info); +void CADestroyInfo(CAInfo_t *info); /** * @brief gets message type from PDU binary data @@ -220,14 +194,6 @@ CAMessageType_t CAGetMessageTypeFromPduBinaryData(const void *pdu, uint32_t size */ uint16_t CAGetMessageIdFromPduBinaryData(const void *pdu, uint32_t size); -/** - * @brief gets code PDU binary data - * @param pdu [IN] pdu data - * @param size [IN] size of pdu data - * @return code - */ -CAResponseResult_t CAGetCodeFromPduBinaryData(const void *pdu, uint32_t size); - #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/resource/csdk/connectivity/inc/caprotocolmessage_singlethread.h b/resource/csdk/connectivity/inc/caprotocolmessage_singlethread.h index 042131d..e33f783 100644 --- a/resource/csdk/connectivity/inc/caprotocolmessage_singlethread.h +++ b/resource/csdk/connectivity/inc/caprotocolmessage_singlethread.h @@ -42,12 +42,12 @@ typedef uint32_t code_t; /** * @brief generates pdu structure from the given information. - * @param uri [IN] uri information of the pdu - * @param code [IN] cod of the pdu packet + * @param uri [IN] uri information of the pdu + * @param code [IN] code of the pdu packet * @param info [IN] pdu information such as request code ,response code and payload * @return coap_pdu_t created pdu */ -coap_pdu_t *CAGeneratePdu(const char *uri, const uint32_t code, const CAInfo_t info); +coap_pdu_t *CAGeneratePdu(const char *uri, uint32_t code, const CAInfo_t info); /** * function for generating @@ -56,57 +56,40 @@ coap_pdu_t *CAGeneratePdu(const char *uri, const uint32_t code, const CAInfo_t i /** * @brief extracts request information from received pdu. * @param pdu [IN] received pdu - * @param outReqInfo [OUT] request info structure made from received pdu - * @param outUri [OUT] uri received in the received pdu - * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) + * @param outReqInfo [OUT] request info structure made from received pdu + * @param outUri [OUT] uri received in the received pdu + * @param buflen [IN] Buffer Length for outUri parameter + * @return NONE */ -uint32_t CAGetRequestInfoFromPdu(const coap_pdu_t *pdu, CARequestInfo_t *outReqInfo, - char *outUri); +void CAGetRequestInfoFromPdu(const coap_pdu_t *pdu, CARequestInfo_t *outReqInfo, + char *outUri, uint32_t bufLen); /** * @brief extracts response information from received pdu. * @param pdu [IN] received pdu - * @param outResInfo [OUT] request info structure made from received pdu - * @param outUri [OUT] uri received in the received pdu - * @return 0 or 1 ( CAResult_t error codes in cacommon.h) + * @param outResInfo [OUT] response info structure made from received pdu + * @param outUri [OUT] uri received in the received pdu + * @param buflen [IN] Buffer Length for outUri parameter + * @return NONE */ -uint32_t CAGetResponseInfoFromPdu(const coap_pdu_t *pdu, CAResponseInfo_t *outResInfo, - char *outUri); +void CAGetResponseInfoFromPdu(const coap_pdu_t *pdu, CAResponseInfo_t *outResInfo, + char *outUri, uint32_t bufLen); /** * @brief creates pdu from the request information * @param code [IN] request or response code - * @param options [IN] options for the request and response - * @param outUri [IN] information to create pdu - * @return coap_pdu_t - */ -coap_pdu_t *CACreatePDUforRequest(const code_t code, coap_list_t *options, - const CAInfo_t info); - -/** - * @brief creates pdu for ACK or RESET type - * @param code [IN] request or response code - * @param info [IN] pdu information such as response code - * @return coap_pdu_t - */ -coap_pdu_t *CACreatePDUforRSTandACK(const code_t code, const CAInfo_t info); - -/** - * @brief creates pdu from the request information and paylod - * @param code [IN] request or response code alloted - * @param options [IN] options for the request and response backpacked + * @param options [OUT] options for the request and response + * @param info [IN] information to create pdu * @param payload [IN] payload for the request or response consumed - * @param outUri [IN] information to create pdu * @return coap_pdu_t */ - -coap_pdu_t *CACreatePDUforRequestWithPayload(const code_t code, coap_list_t *optlist, - const char *payload, const CAInfo_t info); +coap_pdu_t *CAGeneratePduImpl(const code_t code, coap_list_t *options, + const CAInfo_t info, const char *payload); /** * @brief parse the URI and creates the options * @param uriInfo [IN] uri information - * @param options [IN] options information + * @param options [OUT] options information * @return None */ void CAParseURI(const char *uriInfo, coap_list_t **options); @@ -115,19 +98,20 @@ void CAParseURI(const char *uriInfo, coap_list_t **options); * @brief create option list from header information in the info * @param code [IN] uri information * @param info [IN] options information - * @param optlist [IN] options information + * @param optlist [OUT] options information * @return None */ -void CAParseHeadOption(const uint32_t code, const CAInfo_t info, coap_list_t **optlist); +void CAParseHeadOption(uint32_t code, const CAInfo_t info, coap_list_t **optlist); /** - * @brief creates option node from key lenght and data + * @brief creates option node from key length and data + * need to replace queue head if new node has to be added before the existing queue head * @param key [IN] key for the that needs to be sent * @param length [IN] length of the data that needs to be sent * @param data [IN] data that needs to be sent * @return created list */ -coap_list_t *CACreateNewOptionNode(const uint16_t key, const uint32_t length, +coap_list_t *CACreateNewOptionNode(uint16_t key, uint32_t length, const uint8_t *data); /** @@ -149,43 +133,34 @@ uint32_t CAGetOptionCount(coap_opt_iterator_t opt_iter); * @brief gets option data * @param data [IN] data that is received * @param length [IN] length of the data - * @param result [IN] result of the operation + * @param option [OUT] result of the operation * @param buflen [IN] buffer length of the result - * @param encode_always [IN] encoded data - * @return 0 or 1 + * @return option count */ -uint32_t CAGetOptionData(const uint8_t *data, uint32_t len, uint8_t *result, uint32_t buflen, - uint32_t encode_always); +uint32_t CAGetOptionData(const uint8_t *data, uint32_t len, uint8_t *option, uint32_t buflen); /** * @brief extracts request information from received pdu. - * @param pdu [IN] received pdu + * @param pdu [IN] received pdu * @param outCode [OUT] code of the received pdu * @param outInfo [OUT] request info structure made from received pdu * @param outUri [OUT] uri received in the received pdu + * @param buflen [IN] Buffer Length for outUri parameter * @return None */ -void CAGetRequestPDUInfo(const coap_pdu_t *pdu, uint32_t *outCode, CAInfo_t *outInfo, - char *outUri); +void CAGetInfoFromPDU(const coap_pdu_t *pdu, uint32_t *outCode, CAInfo_t *outInfo, + char *outUri, uint32_t bufLen); /** * @brief create pdu fromn received data * @param data [IN] received data * @param length [IN] length of the data received - * @param outCode [IN] code received + * @param outCode [OUT] code received * @return None */ coap_pdu_t *CAParsePDU(const char *data, uint32_t length, uint32_t *outCode); /** - * @brief get Token fromn received data(pdu) - * @param pdu [IN] received pdu - * @param outCode [IN] Token received - * @return None - */ -CAResult_t CAGetTokenFromPDU(const coap_hdr_t *pdu_hdr, CAInfo_t *outInfo); - -/** * @brief generates the token * @param token [OUT] generated token * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) @@ -202,10 +177,10 @@ void CADestroyTokenInternal(CAToken_t token); /** * @brief destroy the ca info structure - * @param info [IN] info structure created from received packet + * @param info [IN] info structure created from received packet * @return none */ -void CADeinitialize(CAInfo_t *info); +void CADestroyInfo(CAInfo_t *info); /** * @brief gets message type from PDU binary data @@ -223,16 +198,9 @@ CAMessageType_t CAGetMessageTypeFromPduBinaryData(const void *pdu, uint32_t size */ uint16_t CAGetMessageIdFromPduBinaryData(const void *pdu, uint32_t size); -/** - * @brief gets code PDU binary data - * @param pdu [IN] pdu data - * @param size [IN] size of pdu data - * @return code - */ -CAResponseResult_t CAGetCodeFromPduBinaryData(const void *pdu, uint32_t size); - #ifdef __cplusplus } /* extern "C" */ #endif #endif //#ifndef __CA_PROTOCOL_MESSAGE_SINGLETHREAD_H_ + diff --git a/resource/csdk/connectivity/inc/caqueueingthread.h b/resource/csdk/connectivity/inc/caqueueingthread.h index c83ebf9..b6a3c0b 100644 --- a/resource/csdk/connectivity/inc/caqueueingthread.h +++ b/resource/csdk/connectivity/inc/caqueueingthread.h @@ -54,16 +54,16 @@ typedef struct /**Data destroy function**/ CADataDestroyFunction destroy; /** Variable to inform the thread to stop **/ - CABool_t isStop; + bool isStop; /** Que on which the thread is operating. **/ u_queue_t *dataQueue; } CAQueueingThread_t; /** * @brief Initializes the queing thread - * @param thread [IN] thread data for each thread - * @param handle [IN] thread pool handle created - * @param task [IN] function to be called for reach data + * @param thread [IN] thread data for each thread + * @param handle [IN] thread pool handle created + * @param task [IN] function to be called for each data * @param destroy [IN] function to data destroy * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ @@ -72,23 +72,23 @@ CAResult_t CAQueueingThreadInitialize(CAQueueingThread_t *thread, u_thread_pool_ /** * @brief Starting the queueing thread - * @param thread [IN] thread data that needs to be started + * @param thread [IN] thread data that needs to be started * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ CAResult_t CAQueueingThreadStart(CAQueueingThread_t *thread); /** * @brief Add queueing thread data for new thread - * @param thread [IN] thread data for new thread control - * @param data [IN] data that needs to be given for each thread - * @param size [IN] length of the data + * @param thread [IN] thread data for new thread control + * @param data [IN] data that needs to be given for each thread + * @param size [IN] length of the data * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ CAResult_t CAQueueingThreadAddData(CAQueueingThread_t *thread, void *data, uint32_t size); /** * @brief Stopping the queueing thread - * @param thread [IN] thread data that needs to be started + * @param thread [IN] thread data that needs to be started * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ @@ -96,7 +96,7 @@ CAResult_t CAQueueingThreadStop(CAQueueingThread_t *thread); /** * @brief Terminating the queing thread - * @param thread [IN] thread data for each thread + * @param thread [IN] thread data for each thread * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ @@ -107,3 +107,4 @@ CAResult_t CAQueueingThreadDestroy(CAQueueingThread_t *thread); #endif #endif // __CA_THREAD_H_ + diff --git a/resource/csdk/connectivity/inc/caremotehandler.h b/resource/csdk/connectivity/inc/caremotehandler.h index bfeb96f..9d41d39 100644 --- a/resource/csdk/connectivity/inc/caremotehandler.h +++ b/resource/csdk/connectivity/inc/caremotehandler.h @@ -26,10 +26,6 @@ #ifndef __CA_REMOTE_HANDLER_H_ #define __CA_REMOTE_HANDLER_H_ -#include -#include -#include - #include "cacommon.h" #ifdef __cplusplus @@ -46,8 +42,8 @@ CARemoteEndpoint_t *CACloneRemoteEndpoint(const CARemoteEndpoint_t *endpoint); /** * @brief Creates a new remote endpoint from the input uri - * @param uri [IN] absolute uri information to create remote endpoint - * @param type [IN] connectivity type of the endpoint + * @param uri [IN] absolute uri information to create remote endpoint + * @param connectivityType [IN] connectivity type of the endpoint * @return remote endpoint created */ CARemoteEndpoint_t *CACreateRemoteEndpointUriInternal(const CAURI_t uri, @@ -55,9 +51,9 @@ CARemoteEndpoint_t *CACreateRemoteEndpointUriInternal(const CAURI_t uri, /** * @brief Creates a new remote endpoint from the input and other information - * @param resourceUri [IN] absolute uri information to create remote endpoint - * @param addr [IN] address of the ednpoint - * @param type [IN] connectivity type of the endpoint + * @param resourceUri [IN] absolute uri information to create remote endpoint + * @param addr [IN] address of the endpoint + * @param type [IN] connectivity type of the endpoint * @return remote endpoint created */ CARemoteEndpoint_t *CACreateRemoteEndpointInternal(const CAURI_t resourceUri, @@ -72,28 +68,28 @@ void CADestroyRemoteEndpointInternal(CARemoteEndpoint_t *rep); /** * @brief Creates a new request information - * @param rep [IN] request information that needs to be duplicated + * @param request [IN] request information that needs to be duplicated * @return remote endpoint created */ CARequestInfo_t *CACloneRequestInfo(const CARequestInfo_t *request); /** * @brief Destroy the request information - * @param rep [IN] request information that needs to be destroyed + * @param request [IN] request information that needs to be destroyed * @return none */ void CADestroyRequestInfoInternal(CARequestInfo_t *request); /** * @brief Creates a new response information - * @param rep [IN] response information that needs to be duplicated + * @param response [IN] response information that needs to be duplicated * @return remote endpoint created */ CAResponseInfo_t *CACloneResponseInfo(const CAResponseInfo_t *response); /** * @brief Destroy the response information - * @param rep [IN] response information that needs to be destroyed + * @param response [IN] response information that needs to be destroyed * @return */ void CADestroyResponseInfoInternal(CAResponseInfo_t *response); @@ -103,3 +99,4 @@ void CADestroyResponseInfoInternal(CAResponseInfo_t *response); #endif #endif //#ifndef __CA_REMOTE_HANDLER_H_ + diff --git a/resource/csdk/connectivity/inc/caretransmission.h b/resource/csdk/connectivity/inc/caretransmission.h index 43d1bb7..c3eb9be 100644 --- a/resource/csdk/connectivity/inc/caretransmission.h +++ b/resource/csdk/connectivity/inc/caretransmission.h @@ -32,23 +32,23 @@ #include "cacommon.h" /** CA_ETHERNET, CA_WIFI, CA_EDR, CA_LE **/ -#define DEFAULT_RETRANSMISSION_TYPE ((1<<0)|(1<<1)|(1<<2)|(1<<3)) +#define DEFAULT_RETRANSMISSION_TYPE (CA_ETHERNET | CA_WIFI | CA_EDR | CA_LE) /** default ACK time is 2 sec.(CoAP) **/ -#define DEFAULT_ACK_TIMEOUT 2 +#define DEFAULT_ACK_TIMEOUT_SEC 2 /** default max retransmission trying count is 4.(CoAP) **/ #define DEFAULT_MAX_RETRANSMIT 4 /** check period is 1 sec. **/ -#define RETRANSMISSION_CHECK_PERIOD 1000000 +#define RETRANSMISSION_CHECK_PERIOD_SEC 1 /** retransmission data send method type**/ -typedef CAResult_t (*CADataSendMethod_t)(const CARemoteEndpoint_t *endpoint, void *pdu, +typedef CAResult_t (*CADataSendMethod_t)(const CARemoteEndpoint_t *endpoint, const void *pdu, uint32_t size); /** retransmission timeout callback type**/ -typedef void (*CATimeoutCallback_t)(const CARemoteEndpoint_t *endpoint, void *pdu, uint32_t size); +typedef void (*CATimeoutCallback_t)(const CARemoteEndpoint_t *endpoint, const void *pdu, uint32_t size); typedef struct { @@ -74,7 +74,7 @@ typedef struct /** retransmission configure data **/ CARetransmissionConfig_t config; /** Variable to inform the thread to stop **/ - CABool_t isStop; + bool isStop; /** array list on which the thread is operating. **/ u_arraylist_t *dataList; } CARetransmission_t; @@ -86,60 +86,62 @@ extern "C" /** * @brief Initializes the retransmission context - * @param context [IN]context for retransmission - * @param handle [IN]thread pool handle - * @param retransmissionSendMethod [IN]function to be called for retransmission - * @param timeoutCallback [IN]callback for retransmit timeout - * @param config [IN]configuration for retransmission. if NULL is coming, it will set default values. + * @param context [IN] context for retransmission + * @param handle [IN] thread pool handle + * @param retransmissionSendMethod [IN] function to be called for retransmission + * @param timeoutCallback [IN] callback for retransmit timeout + * @param config [IN] configuration for retransmission. + * if NULL is coming, it will set default values. * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ CAResult_t CARetransmissionInitialize(CARetransmission_t *context, u_thread_pool_t handle, - CADataSendMethod_t retransmissionSendMethod, CATimeoutCallback_t timeoutCallback, - CARetransmissionConfig_t* config); + CADataSendMethod_t retransmissionSendMethod, + CATimeoutCallback_t timeoutCallback, + CARetransmissionConfig_t* config); /** * @brief Starting the retransmission context - * @param context [IN]context for retransmission + * @param context [IN] context for retransmission * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ CAResult_t CARetransmissionStart(CARetransmission_t *context); /** * @brief Pass the sent pdu data. if retransmission process need, internal thread will wake up and - * process the retransmission data. - * @param context [IN]context for retransmission - * @param endpoint [IN]endpoint information - * @param pdu [IN]sent pdu binary data - * @param size [IN]sent pdu binary data size + * process the retransmission data. + * @param context [IN] context for retransmission + * @param endpoint [IN] endpoint information + * @param pdu [IN] sent pdu binary data + * @param size [IN] sent pdu binary data size * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ CAResult_t CARetransmissionSentData(CARetransmission_t* context, - const CARemoteEndpoint_t* endpoint,const void* pdu, uint32_t size); + const CARemoteEndpoint_t* endpoint,const void* pdu, + uint32_t size); /** - * @brief Paas the received pdu data. if received pdu is ACK data for the retransmission CON data, - * the specified CON data will remove on retransmission list. - * @param context [IN]context for retransmission - * @param endpoint [IN]endpoint information - * @param pdu [IN]received pdu binary data - * @param size [IN]received pdu binary data size - * @param void [OUT] pdu data of the request for reset and ack + * @brief Pass the received pdu data. if received pdu is ACK data for the retransmission CON data, + * the specified CON data will remove on retransmission list. + * @param context [IN] context for retransmission + * @param endpoint [IN] endpoint information + * @param pdu [IN] received pdu binary data + * @param size [IN] received pdu binary data size * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ CAResult_t CARetransmissionReceivedData(CARetransmission_t *context, const CARemoteEndpoint_t *endpoint, const void *pdu, - uint32_t size, void **retransmissionPdu); + uint32_t size); /** * @brief Stopping the retransmission context - * @param context [IN]context for retransmission + * @param context [IN] context for retransmission * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ CAResult_t CARetransmissionStop(CARetransmission_t *context); /** * @brief Terminating the retransmission context - * @param context [IN]context for retransmission + * @param context [IN] context for retransmission * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ CAResult_t CARetransmissionDestroy(CARetransmission_t *context); @@ -149,3 +151,4 @@ CAResult_t CARetransmissionDestroy(CARetransmission_t *context); #endif #endif // __CA_RETRANSMISSION_H_ + diff --git a/resource/csdk/connectivity/inc/caretransmission_singlethread.h b/resource/csdk/connectivity/inc/caretransmission_singlethread.h index bcfe0d1..8e777af 100644 --- a/resource/csdk/connectivity/inc/caretransmission_singlethread.h +++ b/resource/csdk/connectivity/inc/caretransmission_singlethread.h @@ -36,20 +36,21 @@ #define DEFAULT_RETRANSMISSION_COUNT 4 /** check period is 1 sec. **/ -#define RETRANSMISSION_CHECK_PERIOD 1000000 +#define RETRANSMISSION_CHECK_PERIOD_SEC 1 /** retransmission data send method type**/ -typedef CAResult_t (*CADataSendMethod_t)(const CARemoteEndpoint_t *endpoint, void *pdu, - uint32_t size); +typedef CAResult_t (*CADataSendMethod_t)(const CARemoteEndpoint_t *endpoint, const void *pdu, + uint32_t size); /** retransmission timeout callback type**/ -typedef void (*CATimeoutCallback_t)(const CARemoteEndpoint_t *endpoint, void *pdu, +typedef void (*CATimeoutCallback_t)(const CARemoteEndpoint_t *endpoint, const void *pdu, uint32_t size); typedef struct { /** retransmission support connectivity type **/ CAConnectivityType_t supportType; + /** retransmission trying count **/ uint8_t tryingCount; @@ -59,14 +60,19 @@ typedef struct { /** send method for retransmission data **/ CADataSendMethod_t dataSendMethod; + /** callback function for retransmit timeout **/ CATimeoutCallback_t timeoutCallback; + /** retransmission configure data **/ CARetransmissionConfig_t config; + /** Variable to inform the thread to stop **/ - CABool_t isStop; + bool isStop; + /** array list on which the thread is operating. **/ u_arraylist_t *dataList; + } CARetransmission_t; #ifdef __cplusplus @@ -76,11 +82,10 @@ extern "C" /** * @brief Initializes the retransmission context - * @param context [IN] context for retransmission - * @param handle [IN] thread pool handle - * @param retransmissionSendMethod [IN] function to be called for retransmission - * @param timeoutCallback [IN] callback for retransmit timeout - * @param config [IN] configuration for retransmission. + * @param context [IN] context for retransmission + * @param retransmissionSendMethod [IN] function to be called for retransmission + * @param timeoutCallback [IN] callback for retransmit timeout + * @param config [IN] configuration for retransmission. * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ CAResult_t CARetransmissionInitialize(CARetransmission_t *context, @@ -89,8 +94,8 @@ CAResult_t CARetransmissionInitialize(CARetransmission_t *context, CARetransmissionConfig_t *config); /** - * @brief Pass the sent pdu data. if retransmission process need, internal thread will wake up and - * process the retransmission data. + * @brief Pass the sent pdu data. if retransmission process need, internal thread will wake up + * and process the retransmission data. * @param context [IN] context for retransmission * @param endpoint [IN] endpoint information * @param pdu [IN] sent pdu binary data @@ -103,17 +108,16 @@ CAResult_t CARetransmissionSentData(CARetransmission_t *context, /** * @brief Paas the received pdu data. if received pdu is ACK data for the retransmission CON data, - * the specified CON data will remove on retransmission list. + * the specified CON data will remove on retransmission list. * @param context [IN] context for retransmission * @param endpoint [IN] endpoint information * @param pdu [IN] received pdu binary data * @param size [IN] received pdu binary data size - * @param void [OUT] pdu data of the request for reset and ack * @return CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h) */ CAResult_t CARetransmissionReceivedData(CARetransmission_t *context, const CARemoteEndpoint_t *endpoint, const void *pdu, - uint32_t size, void **retransmissionPdu); + uint32_t size); /** * @brief Stopping the retransmission context @@ -145,3 +149,4 @@ void CARetransmissionBaseRoutine(void *threadValue); #endif #endif // __CA_RETRANSMISSION_SINGLETHREAD_H_ + diff --git a/resource/csdk/connectivity/inc/cawifiadapter.h b/resource/csdk/connectivity/inc/cawifiadapter.h index f66971b..d69704a 100644 --- a/resource/csdk/connectivity/inc/cawifiadapter.h +++ b/resource/csdk/connectivity/inc/cawifiadapter.h @@ -40,7 +40,7 @@ extern "C" * 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 intimate the network additions to Connectivity + * @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 @@ -79,20 +79,20 @@ CAResult_t CAStartWIFIDiscoveryServer(); * connectivity type) to which the unicast data has to be sent. * @param data [IN] Data to be sent. * @param dataLen [IN] Size of data to be sent. - * @return The number of bytes sent on the network. Returns 0 on error. + * @return The number of bytes sent on the network. Returns -1 on error. * @remarks dataLen must be > 0. */ -uint32_t CASendWIFIUnicastData(const CARemoteEndpoint_t *endpoint, void *data, +int32_t CASendWIFIUnicastData(const CARemoteEndpoint_t *endpoint, const void *data, uint32_t dataLen); /** * @brief Sends Multicast data to the endpoint using the WIFI connectivity. * @param data [IN] Data which required to be sent. * @param dataLen [IN] Size of data to be sent. - * @return The number of bytes sent on the network. Returns 0 on error. + * @return The number of bytes sent on the network. Returns -1 on error. * @remarks dataLen must be > 0. */ -uint32_t CASendWIFIMulticastData(void *data, uint32_t dataLen); +int32_t CASendWIFIMulticastData(const void *data, uint32_t dataLen); /** * @brief Get WIFI Connectivity network information @@ -120,10 +120,11 @@ CAResult_t CAStopWIFI(); * Configuration information will be deleted from further use * @return NONE */ -void CATerminateWIfI(); +void CATerminateWIFI(); #ifdef __cplusplus } /* extern "C" */ #endif #endif // #ifndef __CA_WIFI_ADAPTER_H__ + diff --git a/resource/csdk/connectivity/inc/cawifiadapter_singlethread.h b/resource/csdk/connectivity/inc/cawifiadapter_singlethread.h index 42f110d..e6ed901 100644 --- a/resource/csdk/connectivity/inc/cawifiadapter_singlethread.h +++ b/resource/csdk/connectivity/inc/cawifiadapter_singlethread.h @@ -39,7 +39,7 @@ extern "C" * 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 intimate the network additions to Connectivity + * @param netCallback [IN] Callback to notify the network additions to Connectivity * Abstraction Layer. * @return #CA_STATUS_OK or Appropriate error code */ @@ -77,20 +77,20 @@ CAResult_t CAStartWIFIDiscoveryServer(); * connectivity type) to which the unicast data has to be sent. * @param data [IN] Data to be sent. * @param dataLen [IN] Size of data to be sent. - * @return The number of bytes sent on the network. Returns 0 on error. + * @return The number of bytes sent on the network. Returns -1 on error. * @remarks dataLen must be > 0. */ -uint32_t CASendWIFIUnicastData(const CARemoteEndpoint_t *endpoint, void *data, - uint32_t dataLen); +int32_t CASendWIFIUnicastData(const CARemoteEndpoint_t *endpoint, const void *data, + uint32_t dataLen); /** * @brief Sends Multicast data to the endpoint using the WIFI connectivity. * @param data [IN] Data which required to be sent. * @param dataLen [IN] Size of data to be sent. - * @return - The number of bytes sent on the network. Returns 0 on error. + * @return - The number of bytes sent on the network. Returns -1 on error. * @remarks dataLen must be > 0. */ -uint32_t CASendWIFIMulticastData(void *data, uint32_t dataLen); +int32_t CASendWIFIMulticastData(const void *data, uint32_t dataLen); /** * @brief Get WIFI Connectivity network information @@ -118,10 +118,11 @@ CAResult_t CAStopWIFI(); * Configuration information will be deleted from further use * @return NONE */ -void CATerminateWIfI(); +void CATerminateWIFI(); #ifdef __cplusplus } /* extern "C" */ #endif #endif // #ifndef __CA_WIFI_ADAPTER_SINGLETHREAD_H__ + diff --git a/resource/csdk/connectivity/inc/cawifiinterface.h b/resource/csdk/connectivity/inc/cawifiinterface.h index 6b89a02..8519434 100644 --- a/resource/csdk/connectivity/inc/cawifiinterface.h +++ b/resource/csdk/connectivity/inc/cawifiinterface.h @@ -57,8 +57,8 @@ typedef enum * @return NONE * @pre Callback must be registered using CAWiFiSetPacketReceiveCallback() */ -typedef void (*CAWiFiPacketReceivedCallback)(const char *ipAddress, const uint32_t port, - const void *data, const uint32_t dataLength, const CABool_t isSecure); +typedef void (*CAWiFiPacketReceivedCallback)(const char *ipAddress, uint16_t port, + const void *data, uint32_t dataLength, bool isSecure); /** * @brief Callback to be notified when exception occures on multicast/unicast server. @@ -101,7 +101,7 @@ void CAWiFiTerminateServer(void); * @retval #CA_STATUS_FAILED Operation failed */ CAResult_t CAWiFiStartMulticastServer(const char *localAddress, const char *multicastAddress, - const int16_t multicastPort, int32_t *serverFD); + uint16_t multicastPort, int *serverFD); /** * @brief Start unicast server for specified local address and port @@ -120,9 +120,9 @@ CAResult_t CAWiFiStartMulticastServer(const char *localAddress, const char *mult * @retval #CA_SERVER_STARTED_ALREADY Unicast server is already started and running. * @retval #CA_STATUS_FAILED Operation failed */ -CAResult_t CAWiFiStartUnicastServer(const char *localAddress, int16_t *port, - const bool forceStart, const CABool_t isSecured, - int32_t *serverFD); +CAResult_t CAWiFiStartUnicastServer(const char *localAddress, uint16_t *port, + bool forceStart, bool isSecured, + int *serverFD); /** * @brief Stop multicast server. @@ -167,8 +167,8 @@ CAResult_t CAWiFiStopSecureUnicastServer(); * @retval #CA_STATUS_FAILED Operation failed * @remarks ipAddress must be freed using free(). */ -CAResult_t CAWiFiGetUnicastServerInfo(const CABool_t isSecured, char **ipAddress, int16_t *port, - int32_t *serverFD); +CAResult_t CAWiFiGetUnicastServerInfo(bool isSecured, char **ipAddress, uint16_t *port, + int *serverFD); /** * @brief Set this callback for receiving data packets from peer devices. @@ -195,7 +195,7 @@ void CAWiFiSetExceptionCallback(CAWiFiExceptionCallback callback); * @param socketFD [IN] Socket descriptor used for sending UDP data. * @return NONE */ -void CAWiFiSetUnicastSocket(const int32_t socketFD); +void CAWiFiSetUnicastSocket(int socketFD); #ifdef __WITH_DTLS__ /** @@ -204,7 +204,7 @@ void CAWiFiSetUnicastSocket(const int32_t socketFD); * @param socketFD [IN] Socket descriptor used for sending secured (encrypted) UDP data. * @return NONE */ -void CAWiFiSetSecureUnicastSocket(const int32_t socketFD); +void CAWiFiSetSecureUnicastSocket(int socketFD); #endif /** @@ -220,9 +220,9 @@ void CAWiFiSetSecureUnicastSocket(const int32_t socketFD); * @return The number of bytes sent on the network. Returns 0 on error. * @remarks isSecure will be ignored when isMulticast is true. */ -uint32_t CAWiFiSendData(const char *remoteAddress, const uint32_t port, - const void *data, const uint32_t dataLength, - CABool_t isMulticast, CABool_t isSecured); +uint32_t CAWiFiSendData(const char *remoteAddress, uint16_t port, + const void *data, uint32_t dataLength, + bool isMulticast, bool isSecured); /** * @brief Callback to be notified when wifi adapter connection state changes. @@ -233,7 +233,7 @@ uint32_t CAWiFiSendData(const char *remoteAddress, const uint32_t port, * @pre Callback must be registered using CAWiFiSetConnectionStateChangeCallback() */ typedef void (*CAWiFiConnectionStateChangeCallback)(const char *ipAddress, - const CANetworkStatus_t status); + CANetworkStatus_t status); /** * @brief Initialize Wifi network monitor @@ -318,3 +318,4 @@ void CAWiFiSetConnectionStateChangeCallback(CAWiFiConnectionStateChangeCallback #endif #endif //_CA_WIFI_INTERFACE_H_ + diff --git a/resource/csdk/connectivity/inc/cawifiinterface_singlethread.h b/resource/csdk/connectivity/inc/cawifiinterface_singlethread.h index 5bbae53..a5b4363 100644 --- a/resource/csdk/connectivity/inc/cawifiinterface_singlethread.h +++ b/resource/csdk/connectivity/inc/cawifiinterface_singlethread.h @@ -55,8 +55,8 @@ typedef enum * @return NONE * @pre Callback must be registered using CAWiFiSetPacketReceiveCallback() */ -typedef void (*CAWiFiPacketReceivedCallback)(const char *ipAddress, const uint32_t port, - const void *data, const uint32_t dataLength); +typedef void (*CAWiFiPacketReceivedCallback)(const char *ipAddress, uint32_t port, + const void *data, uint32_t dataLength); /** * @brief Callback to be notified when exception occures on multicast/unicast server. @@ -97,7 +97,7 @@ void CAWiFiTerminateServer(void); * @retval #CA_STATUS_FAILED Operation failed */ CAResult_t CAWiFiStartMulticastServer(const char *localAddress, const char *multicastAddress, - const int16_t multicastPort, int32_t *serverFD); + int16_t multicastPort, int *serverFD); /** * @brief Start unicast server for specified local address and port @@ -116,7 +116,7 @@ CAResult_t CAWiFiStartMulticastServer(const char *localAddress, const char *mult * @retval #CA_STATUS_FAILED Operation failed */ CAResult_t CAWiFiStartUnicastServer(const char *localAddress, int16_t *port, - const bool forceStart, int32_t *serverFD); + bool forceStart, int *serverFD); /** * @brief Stop multicast server. @@ -159,7 +159,7 @@ CAResult_t CAWiFiStopSecureUnicastServer(); * @retval #CA_STATUS_FAILED Operation failed * @remarks ipAddress must be freed using free(). */ -CAResult_t CAWiFiGetUnicastServerInfo(char **ipAddress, int16_t *port, int32_t *serverFD); +CAResult_t CAWiFiGetUnicastServerInfo(char **ipAddress, int16_t *port, int *serverFD); /** * @brief Set this callback for receiving data packets from peer devices. @@ -191,7 +191,7 @@ void CAWiFiSetExceptionCallback(CAWiFiExceptionCallback callback); * @param socketFD [IN] Socket descriptor used for sending UDP data. * @return NONE */ -void CAWiFiSetUnicastSocket(const int32_t socketFD); +void CAWiFiSetUnicastSocket(int socketFD); #ifdef __WITH_DTLS__ /** @@ -200,7 +200,7 @@ void CAWiFiSetUnicastSocket(const int32_t socketFD); * @param socketFD [IN] Socket descriptor used for sending secured (encrypted) UDP data. * @return NONE */ -void CAWiFiSetSecureUnicastSocket(const int32_t socketFD); +void CAWiFiSetSecureUnicastSocket(int socketFD); #endif /** @@ -214,8 +214,8 @@ void CAWiFiSetSecureUnicastSocket(const int32_t socketFD); * * @return The number of bytes sent on the network. Returns 0 on error. */ -uint32_t CAWiFiSendData(const char *remoteAddress, const uint32_t port, - const void *data, const uint32_t dataLength, bool isMulticast); +uint32_t CAWiFiSendData(const char *remoteAddress, uint32_t port, + const void *data, uint32_t dataLength, bool isMulticast); /** * @brief Callback to be notified when wifi adapter connection state changes. @@ -226,7 +226,7 @@ uint32_t CAWiFiSendData(const char *remoteAddress, const uint32_t port, * @pre Callback must be registered using CAWiFiSetConnectionStateChangeCallback() */ typedef void (*CAWiFiConnectionStateChangeCallback)(const char *ipAddress, - const CANetworkStatus_t status); + CANetworkStatus_t status); /** * @brief Initialize Wifi network monitor @@ -295,3 +295,4 @@ void CAWiFiSetConnectionStateChangeCallback(CAWiFiConnectionStateChangeCallback #endif #endif //_CA_WIFI_INTERFACE_SINGLETHREAD_H_ + diff --git a/resource/csdk/connectivity/inc/com_iotivity_jar_CAWiFiInterface.h b/resource/csdk/connectivity/inc/com_iotivity_jar_CAWiFiInterface.h deleted file mode 100644 index 1ffefee..0000000 --- a/resource/csdk/connectivity/inc/com_iotivity_jar_CAWiFiInterface.h +++ /dev/null @@ -1,31 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include -/* Header for class com_iotivity_jar_CAWiFiInterface */ - -#ifndef _Included_com_iotivity_jar_CAWiFiInterface -#define _Included_com_iotivity_jar_CAWiFiInterface -#ifdef __cplusplus -extern "C" { -#endif -/* - * Class: com_iotivity_jar_CAWiFiInterface - * Method: CAWiFiStateEnabled - * Signature: ()V - */ -JNIEXPORT void JNICALL -Java_com_iotivity_jar_CAWiFiInterface_CAWiFiStateEnabled -(JNIEnv *, jclass); - -/* - * Class: com_iotivity_jar_CAWiFiInterface - * Method: CAWiFiStateDisabled - * Signature: ()V - */ -JNIEXPORT void JNICALL -Java_com_iotivity_jar_CAWiFiInterface_CAWiFiStateDisabled -(JNIEnv *, jclass); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/resource/csdk/connectivity/lib/arduino/RBL_nRF8001.patch b/resource/csdk/connectivity/lib/arduino/RBL_nRF8001.patch index 727f011..ab0e231 100644 --- a/resource/csdk/connectivity/lib/arduino/RBL_nRF8001.patch +++ b/resource/csdk/connectivity/lib/arduino/RBL_nRF8001.patch @@ -102,7 +102,7 @@ diff -rupN RBL_nRF8001_old/RBL_nRF8001.cpp RBL_nRF8001/RBL_nRF8001.cpp + tempAddr += 3; + } + gLeAddress[BLE_ADDRESS_SIZE - 1] = '\0'; -+ Serial.println("LEAddress :"); ++ Serial.println("LEAddress :"); + Serial.println((char *)gLeAddress); + return; + } @@ -134,3 +134,4 @@ diff -rupN RBL_nRF8001_old/RBL_nRF8001.h RBL_nRF8001/RBL_nRF8001.h #endif + diff --git a/resource/csdk/connectivity/lib/arduino/README.txt b/resource/csdk/connectivity/lib/arduino/README.txt deleted file mode 100644 index 33df458..0000000 --- a/resource/csdk/connectivity/lib/arduino/README.txt +++ /dev/null @@ -1,2 +0,0 @@ -External libs for arduino platform - diff --git a/resource/csdk/connectivity/lib/arduino/arduino_libraries.patch b/resource/csdk/connectivity/lib/arduino/arduino_libraries.patch index cfb4126..507aa99 100644 --- a/resource/csdk/connectivity/lib/arduino/arduino_libraries.patch +++ b/resource/csdk/connectivity/lib/arduino/arduino_libraries.patch @@ -1,7 +1,7 @@ -diff -rupN ./Ethernet/src/Ethernet.cpp ../../arduino-1.5.8/libraries/Ethernet/src/Ethernet.cpp ---- ./Ethernet/src/Ethernet.cpp 2014-10-01 20:45:35.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Ethernet/src/Ethernet.cpp 2014-12-12 16:39:26.000000000 +0530 -@@ -7,10 +7,11 @@ uint8_t EthernetClass::_state[MAX_SOCK_N +diff -rupN ./libraries/Ethernet/src/Ethernet.cpp ./arduino-1.5.8/libraries/Ethernet/src/Ethernet.cpp +--- ./libraries/Ethernet/src/Ethernet.cpp 2014-10-01 20:45:35.000000000 +0530 ++++ ./arduino-1.5.8/libraries/Ethernet/src/Ethernet.cpp 2015-02-05 15:51:09.000000000 +0530 +@@ -7,10 +7,10 @@ uint8_t EthernetClass::_state[MAX_SOCK_N 0, 0, 0, 0 }; uint16_t EthernetClass::_server_port[MAX_SOCK_NUM] = { 0, 0, 0, 0 }; @@ -10,13 +10,12 @@ diff -rupN ./Ethernet/src/Ethernet.cpp ../../arduino-1.5.8/libraries/Ethernet/sr int EthernetClass::begin(uint8_t *mac_address) { - static DhcpClass s_dhcp; -+ //static DhcpClass s_dhcp; _dhcp = &s_dhcp; -diff -rupN ./Ethernet/src/utility/socket.cpp ../../arduino-1.5.8/libraries/Ethernet/src/utility/socket.cpp ---- ./Ethernet/src/utility/socket.cpp 2014-10-01 20:45:35.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Ethernet/src/utility/socket.cpp 2014-12-17 17:02:20.000000000 +0530 +diff -rupN ./libraries/Ethernet/src/utility/socket.cpp ./arduino-1.5.8/libraries/Ethernet/src/utility/socket.cpp +--- ./libraries/Ethernet/src/utility/socket.cpp 2014-10-01 20:45:35.000000000 +0530 ++++ ./arduino-1.5.8/libraries/Ethernet/src/utility/socket.cpp 2015-02-05 15:55:18.000000000 +0530 @@ -295,6 +295,7 @@ uint16_t recvfrom(SOCKET s, uint8_t *buf { uint8_t head[8]; @@ -25,44 +24,37 @@ diff -rupN ./Ethernet/src/utility/socket.cpp ../../arduino-1.5.8/libraries/Ether uint16_t ptr=0; if ( len > 0 ) -@@ -316,10 +317,10 @@ uint16_t recvfrom(SOCKET s, uint8_t *buf +@@ -316,10 +317,6 @@ uint16_t recvfrom(SOCKET s, uint8_t *buf data_len = head[6]; data_len = (data_len << 8) + head[7]; - W5100.read_data(s, ptr, buf, data_len); // data copy. - ptr += data_len; -+ //W5100.read_data(s, ptr, buf, data_len); // data copy. -+ //ptr += data_len; - +- - W5100.writeSnRX_RD(s, ptr); -+ //W5100.writeSnRX_RD(s, ptr); break; case SnMR::IPRAW : -@@ -333,10 +334,10 @@ uint16_t recvfrom(SOCKET s, uint8_t *buf +@@ -332,11 +329,6 @@ uint16_t recvfrom(SOCKET s, uint8_t *buf + addr[3] = head[3]; data_len = head[4]; data_len = (data_len << 8) + head[5]; - +- - W5100.read_data(s, ptr, buf, data_len); // data copy. - ptr += data_len; -+ //W5100.read_data(s, ptr, buf, data_len); // data copy. -+ //ptr += data_len; - +- - W5100.writeSnRX_RD(s, ptr); -+ //W5100.writeSnRX_RD(s, ptr); break; case SnMR::MACRAW: -@@ -345,18 +346,25 @@ uint16_t recvfrom(SOCKET s, uint8_t *buf +@@ -344,19 +336,22 @@ uint16_t recvfrom(SOCKET s, uint8_t *buf + ptr+=2; data_len = head[0]; data_len = (data_len<<8) + head[1] - 2; - +- - W5100.read_data(s, ptr, buf, data_len); - ptr += data_len; - W5100.writeSnRX_RD(s, ptr); -+ //W5100.read_data(s, ptr, buf, data_len); -+ //ptr += data_len; -+ //W5100.writeSnRX_RD(s, ptr); break; default : @@ -84,98 +76,15 @@ diff -rupN ./Ethernet/src/utility/socket.cpp ../../arduino-1.5.8/libraries/Ether } /** -diff -rupN ./Time/Time/DateStrings.cpp ../../arduino-1.5.8/libraries/Time/Time/DateStrings.cpp ---- ./Time/Time/DateStrings.cpp 2010-03-06 11:09:22.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Time/Time/DateStrings.cpp 2013-03-24 00:28:08.000000000 +0530 -@@ -1,80 +1,90 @@ --/* DateStrings.cpp -- * Definitions for date strings for use with the Time library -- * -- * No memory is consumed in the sketch if your code does not call any of the string methods -- * You can change the text of the strings, make sure the short strings are each exactly 3 characters -- * the long strings can be any length up to the constant dt_MAX_STRING_LEN defined in Time.h -- * -- */ +diff -rupN ./libraries/Time/Time/DateStrings.cpp ./arduino-1.5.8/libraries/Time/Time/DateStrings.cpp +--- ./libraries/Time/Time/DateStrings.cpp 2010-03-06 11:09:22.000000000 +0530 ++++ ./arduino-1.5.8/libraries/Time/Time/DateStrings.cpp 2015-02-05 16:35:01.000000000 +0530 +@@ -6,8 +6,18 @@ + * the long strings can be any length up to the constant dt_MAX_STRING_LEN defined in Time.h + * + */ - -#include --#include "Time.h" -- --// the short strings for each day or month must be exactly dt_SHORT_STR_LEN --#define dt_SHORT_STR_LEN 3 // the length of short strings -- --static char buffer[dt_MAX_STRING_LEN+1]; // must be big enough for longest string and the terminating null -- --char monthStr1[] PROGMEM = "January"; --char monthStr2[] PROGMEM = "February"; --char monthStr3[] PROGMEM = "March"; --char monthStr4[] PROGMEM = "April"; --char monthStr5[] PROGMEM = "May"; --char monthStr6[] PROGMEM = "June"; --char monthStr7[] PROGMEM = "July"; --char monthStr8[] PROGMEM = "August"; --char monthStr9[] PROGMEM = "September"; --char monthStr10[] PROGMEM = "October"; --char monthStr11[] PROGMEM = "November"; --char monthStr12[] PROGMEM = "December"; -- --PGM_P monthNames_P[] PROGMEM = --{ -- "",monthStr1,monthStr2,monthStr3,monthStr4,monthStr5,monthStr6, -- monthStr7,monthStr8,monthStr9,monthStr10,monthStr11,monthStr12 --}; -- --char monthShortNames_P[] PROGMEM = "ErrJanFebMarAprMayJunJulAugSepOctNovDec"; -- --char dayStr0[] PROGMEM = "Err"; --char dayStr1[] PROGMEM = "Sunday"; --char dayStr2[] PROGMEM = "Monday"; --char dayStr3[] PROGMEM = "Tuesday"; --char dayStr4[] PROGMEM = "Wednesday"; --char dayStr5[] PROGMEM = "Thursday"; --char dayStr6[] PROGMEM = "Friday"; --char dayStr7[] PROGMEM = "Saturday"; -- --PGM_P dayNames_P[] PROGMEM = { dayStr0,dayStr1,dayStr2,dayStr3,dayStr4,dayStr5,dayStr6,dayStr7}; --char dayShortNames_P[] PROGMEM = "ErrSunMonTueWedThrFriSat"; -- --/* functions to return date strings */ -- --char* monthStr(uint8_t month) --{ -- strcpy_P(buffer, (PGM_P)pgm_read_word(&(monthNames_P[month]))); -- return buffer; --} -- --char* monthShortStr(uint8_t month) --{ -- for (int i=0; i < dt_SHORT_STR_LEN; i++) -- buffer[i] = pgm_read_byte(&(monthShortNames_P[i+ (month*dt_SHORT_STR_LEN)])); -- buffer[dt_SHORT_STR_LEN] = 0; -- return buffer; --} -- --char* dayStr(uint8_t day) --{ -- strcpy_P(buffer, (PGM_P)pgm_read_word(&(dayNames_P[day]))); -- return buffer; --} -- --char* dayShortStr(uint8_t day) --{ -- uint8_t index = day*dt_SHORT_STR_LEN; -- for (int i=0; i < dt_SHORT_STR_LEN; i++) -- buffer[i] = pgm_read_byte(&(dayShortNames_P[index + i])); -- buffer[dt_SHORT_STR_LEN] = 0; -- return buffer; --} -+/* DateStrings.cpp -+ * Definitions for date strings for use with the Time library -+ * -+ * No memory is consumed in the sketch if your code does not call any of the string methods -+ * You can change the text of the strings, make sure the short strings are each exactly 3 characters -+ * the long strings can be any length up to the constant dt_MAX_STRING_LEN defined in Time.h -+ * -+ */ + +#if defined(__AVR__) +#include @@ -188,13 +97,25 @@ diff -rupN ./Time/Time/DateStrings.cpp ../../arduino-1.5.8/libraries/Time/Time/D +#define strcpy_P(dest, src) strcpy((dest), (src)) +#endif +#include // for strcpy_P or strcpy -+#include "Time.h" -+ -+// the short strings for each day or month must be exactly dt_SHORT_STR_LEN -+#define dt_SHORT_STR_LEN 3 // the length of short strings -+ -+static char buffer[dt_MAX_STRING_LEN+1]; // must be big enough for longest string and the terminating null -+ + #include "Time.h" + + // the short strings for each day or month must be exactly dt_SHORT_STR_LEN +@@ -15,38 +25,38 @@ + + static char buffer[dt_MAX_STRING_LEN+1]; // must be big enough for longest string and the terminating null + +-char monthStr1[] PROGMEM = "January"; +-char monthStr2[] PROGMEM = "February"; +-char monthStr3[] PROGMEM = "March"; +-char monthStr4[] PROGMEM = "April"; +-char monthStr5[] PROGMEM = "May"; +-char monthStr6[] PROGMEM = "June"; +-char monthStr7[] PROGMEM = "July"; +-char monthStr8[] PROGMEM = "August"; +-char monthStr9[] PROGMEM = "September"; +-char monthStr10[] PROGMEM = "October"; +-char monthStr11[] PROGMEM = "November"; +-char monthStr12[] PROGMEM = "December"; +const char monthStr1[] PROGMEM = "January"; +const char monthStr2[] PROGMEM = "February"; +const char monthStr3[] PROGMEM = "March"; @@ -207,15 +128,25 @@ diff -rupN ./Time/Time/DateStrings.cpp ../../arduino-1.5.8/libraries/Time/Time/D +const char monthStr10[] PROGMEM = "October"; +const char monthStr11[] PROGMEM = "November"; +const char monthStr12[] PROGMEM = "December"; -+ -+PGM_P monthNames_P[] PROGMEM = -+{ -+ "",monthStr1,monthStr2,monthStr3,monthStr4,monthStr5,monthStr6, -+ monthStr7,monthStr8,monthStr9,monthStr10,monthStr11,monthStr12 -+}; -+ + +-PGM_P monthNames_P[] PROGMEM = ++PGM_P const monthNames_P[] PROGMEM = + { + "",monthStr1,monthStr2,monthStr3,monthStr4,monthStr5,monthStr6, + monthStr7,monthStr8,monthStr9,monthStr10,monthStr11,monthStr12 + }; + +-char monthShortNames_P[] PROGMEM = "ErrJanFebMarAprMayJunJulAugSepOctNovDec"; +const char monthShortNames_P[] PROGMEM = "ErrJanFebMarAprMayJunJulAugSepOctNovDec"; -+ + +-char dayStr0[] PROGMEM = "Err"; +-char dayStr1[] PROGMEM = "Sunday"; +-char dayStr2[] PROGMEM = "Monday"; +-char dayStr3[] PROGMEM = "Tuesday"; +-char dayStr4[] PROGMEM = "Wednesday"; +-char dayStr5[] PROGMEM = "Thursday"; +-char dayStr6[] PROGMEM = "Friday"; +-char dayStr7[] PROGMEM = "Saturday"; +const char dayStr0[] PROGMEM = "Err"; +const char dayStr1[] PROGMEM = "Sunday"; +const char dayStr2[] PROGMEM = "Monday"; @@ -224,2031 +155,39 @@ diff -rupN ./Time/Time/DateStrings.cpp ../../arduino-1.5.8/libraries/Time/Time/D +const char dayStr5[] PROGMEM = "Thursday"; +const char dayStr6[] PROGMEM = "Friday"; +const char dayStr7[] PROGMEM = "Saturday"; -+ -+PGM_P dayNames_P[] PROGMEM = { dayStr0,dayStr1,dayStr2,dayStr3,dayStr4,dayStr5,dayStr6,dayStr7}; -+char dayShortNames_P[] PROGMEM = "ErrSunMonTueWedThrFriSat"; -+ -+/* functions to return date strings */ -+ -+char* monthStr(uint8_t month) -+{ -+ strcpy_P(buffer, (PGM_P)pgm_read_word(&(monthNames_P[month]))); -+ return buffer; -+} -+ -+char* monthShortStr(uint8_t month) -+{ -+ for (int i=0; i < dt_SHORT_STR_LEN; i++) -+ buffer[i] = pgm_read_byte(&(monthShortNames_P[i+ (month*dt_SHORT_STR_LEN)])); -+ buffer[dt_SHORT_STR_LEN] = 0; -+ return buffer; -+} -+ -+char* dayStr(uint8_t day) -+{ -+ strcpy_P(buffer, (PGM_P)pgm_read_word(&(dayNames_P[day]))); -+ return buffer; -+} -+ -+char* dayShortStr(uint8_t day) -+{ -+ uint8_t index = day*dt_SHORT_STR_LEN; -+ for (int i=0; i < dt_SHORT_STR_LEN; i++) -+ buffer[i] = pgm_read_byte(&(dayShortNames_P[index + i])); -+ buffer[dt_SHORT_STR_LEN] = 0; -+ return buffer; -+} -diff -rupN ./Time/Time/examples/Processing/SyncArduinoClock/readme.txt ../../arduino-1.5.8/libraries/Time/Time/examples/Processing/SyncArduinoClock/readme.txt ---- ./Time/Time/examples/Processing/SyncArduinoClock/readme.txt 1970-01-01 05:30:00.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Time/Time/examples/Processing/SyncArduinoClock/readme.txt 2013-03-28 07:20:13.000000000 +0530 -@@ -0,0 +1,9 @@ -+SyncArduinoClock is a Processing sketch that responds to Arduino requests for -+time synchronization messages. -+ -+The portIndex must be set the Serial port connected to Arduino. -+ -+Download TimeSerial.pde onto Arduino and you should see the time -+message displayed when you run SyncArduinoClock in Processing. -+The Arduino time is set from the time on your computer through the -+Processing sketch. -diff -rupN ./Time/Time/examples/Processing/SyncArduinoClock/SyncArduinoClock.pde ../../arduino-1.5.8/libraries/Time/Time/examples/Processing/SyncArduinoClock/SyncArduinoClock.pde ---- ./Time/Time/examples/Processing/SyncArduinoClock/SyncArduinoClock.pde 1970-01-01 05:30:00.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Time/Time/examples/Processing/SyncArduinoClock/SyncArduinoClock.pde 2013-03-28 08:26:26.000000000 +0530 -@@ -0,0 +1,78 @@ -+/** -+ * SyncArduinoClock. -+ * -+ * portIndex must be set to the port connected to the Arduino -+ * -+ * The current time is sent in response to request message from Arduino -+ * or by clicking the display window -+ * -+ * The time message is 11 ASCII text characters; a header (the letter 'T') -+ * followed by the ten digit system time (unix time) -+ */ -+ -+ -+import processing.serial.*; -+import java.util.Date; -+import java.util.Calendar; -+import java.util.GregorianCalendar; -+ -+public static final short portIndex = 0; // select the com port, 0 is the first port -+public static final String TIME_HEADER = "T"; //header for arduino serial time message -+public static final char TIME_REQUEST = 7; // ASCII bell character -+public static final char LF = 10; // ASCII linefeed -+public static final char CR = 13; // ASCII linefeed -+Serial myPort; // Create object from Serial class -+ -+void setup() { -+ size(200, 200); -+ println(Serial.list()); -+ println(" Connecting to -> " + Serial.list()[portIndex]); -+ myPort = new Serial(this,Serial.list()[portIndex], 9600); -+ println(getTimeNow()); -+} -+ -+void draw() -+{ -+ textSize(20); -+ textAlign(CENTER); -+ fill(0); -+ text("Click to send\nTime Sync", 0, 75, 200, 175); -+ if ( myPort.available() > 0) { // If data is available, -+ char val = char(myPort.read()); // read it and store it in val -+ if(val == TIME_REQUEST){ -+ long t = getTimeNow(); -+ sendTimeMessage(TIME_HEADER, t); -+ } -+ else -+ { -+ if(val == LF) -+ ; //igonore -+ else if(val == CR) -+ println(); -+ else -+ print(val); // echo everying but time request -+ } -+ } -+} -+ -+void mousePressed() { -+ sendTimeMessage( TIME_HEADER, getTimeNow()); -+} -+ -+ -+void sendTimeMessage(String header, long time) { -+ String timeStr = String.valueOf(time); -+ myPort.write(header); // send header and time to arduino -+ myPort.write(timeStr); -+ myPort.write('\n'); -+} -+ -+long getTimeNow(){ -+ // java time is in ms, we want secs -+ Date d = new Date(); -+ Calendar cal = new GregorianCalendar(); -+ long current = d.getTime()/1000; -+ long timezone = cal.get(cal.ZONE_OFFSET)/1000; -+ long daylight = cal.get(cal.DST_OFFSET)/1000; -+ return current + timezone + daylight; -+} -diff -rupN ./Time/Time/examples/TimeArduinoDue/TimeArduinoDue.ino ../../arduino-1.5.8/libraries/Time/Time/examples/TimeArduinoDue/TimeArduinoDue.ino ---- ./Time/Time/examples/TimeArduinoDue/TimeArduinoDue.ino 1970-01-01 05:30:00.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Time/Time/examples/TimeArduinoDue/TimeArduinoDue.ino 2013-03-28 06:08:18.000000000 +0530 -@@ -0,0 +1,69 @@ -+/* -+ * TimeRTC.pde -+ * example code illustrating Time library with Real Time Clock. -+ * -+ * This example requires Markus Lange's Arduino Due RTC Library -+ * https://github.com/MarkusLange/Arduino-Due-RTC-Library -+ */ -+ -+#include -+#include -+ -+// Select the Slowclock source -+//RTC_clock rtc_clock(RC); -+RTC_clock rtc_clock(XTAL); -+ -+void setup() { -+ Serial.begin(9600); -+ rtc_clock.init(); -+ if (rtc_clock.date_already_set() == 0) { -+ // Unfortunately, the Arduino Due hardware does not seem to -+ // be designed to maintain the RTC clock state when the -+ // board resets. Markus described it thusly: "Uhh the Due -+ // does reset with the NRSTB pin. This resets the full chip -+ // with all backup regions including RTC, RTT and SC. Only -+ // if the reset is done with the NRST pin will these regions -+ // stay with their old values." -+ rtc_clock.set_time(__TIME__); -+ rtc_clock.set_date(__DATE__); -+ } -+ setSyncProvider(getArduinoDueTime); -+ if(timeStatus()!= timeSet) -+ Serial.println("Unable to sync with the RTC"); -+ else -+ Serial.println("RTC has set the system time"); -+} -+ -+time_t getArduinoDueTime() -+{ -+ return rtc_clock.unixtime(); -+} -+ -+void loop() -+{ -+ digitalClockDisplay(); -+ delay(1000); -+} -+ -+void digitalClockDisplay(){ -+ // digital clock display of the time -+ Serial.print(hour()); -+ printDigits(minute()); -+ printDigits(second()); -+ Serial.print(" "); -+ Serial.print(day()); -+ Serial.print(" "); -+ Serial.print(month()); -+ Serial.print(" "); -+ Serial.print(year()); -+ Serial.println(); -+} -+ -+void printDigits(int digits){ -+ // utility function for digital clock display: prints preceding colon and leading 0 -+ Serial.print(":"); -+ if(digits < 10) -+ Serial.print('0'); -+ Serial.print(digits); -+} -+ -diff -rupN ./Time/Time/examples/TimeGPS/TimeGPS.ino ../../arduino-1.5.8/libraries/Time/Time/examples/TimeGPS/TimeGPS.ino ---- ./Time/Time/examples/TimeGPS/TimeGPS.ino 1970-01-01 05:30:00.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Time/Time/examples/TimeGPS/TimeGPS.ino 2013-03-31 01:18:40.000000000 +0530 -@@ -0,0 +1,87 @@ -+/* -+ * TimeGPS.pde -+ * example code illustrating time synced from a GPS -+ * -+ */ -+ -+#include -+#include // http://arduiniana.org/libraries/TinyGPS/ -+#include -+// TinyGPS and SoftwareSerial libraries are the work of Mikal Hart -+ -+SoftwareSerial SerialGPS = SoftwareSerial(10, 11); // receive on pin 10 -+TinyGPS gps; -+ -+// To use a hardware serial port, which is far more efficient than -+// SoftwareSerial, uncomment this line and remove SoftwareSerial -+//#define SerialGPS Serial1 -+ -+// Offset hours from gps time (UTC) -+const int offset = 1; // Central European Time -+//const int offset = -5; // Eastern Standard Time (USA) -+//const int offset = -4; // Eastern Daylight Time (USA) -+//const int offset = -8; // Pacific Standard Time (USA) -+//const int offset = -7; // Pacific Daylight Time (USA) -+ -+// Ideally, it should be possible to learn the time zone -+// based on the GPS position data. However, that would -+// require a complex library, probably incorporating some -+// sort of database using Eric Muller's time zone shape -+// maps, at http://efele.net/maps/tz/ -+ -+time_t prevDisplay = 0; // when the digital clock was displayed -+ -+void setup() -+{ -+ Serial.begin(9600); -+ while (!Serial) ; // Needed for Leonardo only -+ SerialGPS.begin(4800); -+ Serial.println("Waiting for GPS time ... "); -+} -+ -+void loop() -+{ -+ while (SerialGPS.available()) { -+ if (gps.encode(SerialGPS.read())) { // process gps messages -+ // when TinyGPS reports new data... -+ unsigned long age; -+ int Year; -+ byte Month, Day, Hour, Minute, Second; -+ gps.crack_datetime(&Year, &Month, &Day, &Hour, &Minute, &Second, NULL, &age); -+ if (age < 500) { -+ // set the Time to the latest GPS reading -+ setTime(Hour, Minute, Second, Day, Month, Year); -+ adjustTime(offset * SECS_PER_HOUR); -+ } -+ } -+ } -+ if (timeStatus()!= timeNotSet) { -+ if (now() != prevDisplay) { //update the display only if the time has changed -+ prevDisplay = now(); -+ digitalClockDisplay(); -+ } -+ } -+} -+ -+void digitalClockDisplay(){ -+ // digital clock display of the time -+ Serial.print(hour()); -+ printDigits(minute()); -+ printDigits(second()); -+ Serial.print(" "); -+ Serial.print(day()); -+ Serial.print(" "); -+ Serial.print(month()); -+ Serial.print(" "); -+ Serial.print(year()); -+ Serial.println(); -+} -+ -+void printDigits(int digits) { -+ // utility function for digital clock display: prints preceding colon and leading 0 -+ Serial.print(":"); -+ if(digits < 10) -+ Serial.print('0'); -+ Serial.print(digits); -+} -+ -diff -rupN ./Time/Time/examples/TimeNTP/TimeNTP.ino ../../arduino-1.5.8/libraries/Time/Time/examples/TimeNTP/TimeNTP.ino ---- ./Time/Time/examples/TimeNTP/TimeNTP.ino 1970-01-01 05:30:00.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Time/Time/examples/TimeNTP/TimeNTP.ino 2013-03-31 01:19:07.000000000 +0530 -@@ -0,0 +1,135 @@ -+/* -+ * Time_NTP.pde -+ * Example showing time sync to NTP time source -+ * -+ * This sketch uses the Ethernet library -+ */ -+ -+#include -+#include -+#include -+#include -+ -+byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; -+// NTP Servers: -+IPAddress timeServer(132, 163, 4, 101); // time-a.timefreq.bldrdoc.gov -+// IPAddress timeServer(132, 163, 4, 102); // time-b.timefreq.bldrdoc.gov -+// IPAddress timeServer(132, 163, 4, 103); // time-c.timefreq.bldrdoc.gov -+ -+ -+const int timeZone = 1; // Central European Time -+//const int timeZone = -5; // Eastern Standard Time (USA) -+//const int timeZone = -4; // Eastern Daylight Time (USA) -+//const int timeZone = -8; // Pacific Standard Time (USA) -+//const int timeZone = -7; // Pacific Daylight Time (USA) -+ -+ -+EthernetUDP Udp; -+unsigned int localPort = 8888; // local port to listen for UDP packets -+ -+void setup() -+{ -+ Serial.begin(9600); -+ while (!Serial) ; // Needed for Leonardo only -+ delay(250); -+ Serial.println("TimeNTP Example"); -+ if (Ethernet.begin(mac) == 0) { -+ // no point in carrying on, so do nothing forevermore: -+ while (1) { -+ Serial.println("Failed to configure Ethernet using DHCP"); -+ delay(10000); -+ } -+ } -+ Serial.print("IP number assigned by DHCP is "); -+ Serial.println(Ethernet.localIP()); -+ Udp.begin(localPort); -+ Serial.println("waiting for sync"); -+ setSyncProvider(getNtpTime); -+} -+ -+time_t prevDisplay = 0; // when the digital clock was displayed -+ -+void loop() -+{ -+ if (timeStatus() != timeNotSet) { -+ if (now() != prevDisplay) { //update the display only if time has changed -+ prevDisplay = now(); -+ digitalClockDisplay(); -+ } -+ } -+} -+ -+void digitalClockDisplay(){ -+ // digital clock display of the time -+ Serial.print(hour()); -+ printDigits(minute()); -+ printDigits(second()); -+ Serial.print(" "); -+ Serial.print(day()); -+ Serial.print(" "); -+ Serial.print(month()); -+ Serial.print(" "); -+ Serial.print(year()); -+ Serial.println(); -+} -+ -+void printDigits(int digits){ -+ // utility for digital clock display: prints preceding colon and leading 0 -+ Serial.print(":"); -+ if(digits < 10) -+ Serial.print('0'); -+ Serial.print(digits); -+} -+ -+/*-------- NTP code ----------*/ -+ -+const int NTP_PACKET_SIZE = 48; // NTP time is in the first 48 bytes of message -+byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming & outgoing packets -+ -+time_t getNtpTime() -+{ -+ while (Udp.parsePacket() > 0) ; // discard any previously received packets -+ Serial.println("Transmit NTP Request"); -+ sendNTPpacket(timeServer); -+ uint32_t beginWait = millis(); -+ while (millis() - beginWait < 1500) { -+ int size = Udp.parsePacket(); -+ if (size >= NTP_PACKET_SIZE) { -+ Serial.println("Receive NTP Response"); -+ Udp.read(packetBuffer, NTP_PACKET_SIZE); // read packet into the buffer -+ unsigned long secsSince1900; -+ // convert four bytes starting at location 40 to a long integer -+ secsSince1900 = (unsigned long)packetBuffer[40] << 24; -+ secsSince1900 |= (unsigned long)packetBuffer[41] << 16; -+ secsSince1900 |= (unsigned long)packetBuffer[42] << 8; -+ secsSince1900 |= (unsigned long)packetBuffer[43]; -+ return secsSince1900 - 2208988800UL + timeZone * SECS_PER_HOUR; -+ } -+ } -+ Serial.println("No NTP Response :-("); -+ return 0; // return 0 if unable to get the time -+} -+ -+// send an NTP request to the time server at the given address -+void sendNTPpacket(IPAddress &address) -+{ -+ // set all bytes in the buffer to 0 -+ memset(packetBuffer, 0, NTP_PACKET_SIZE); -+ // Initialize values needed to form NTP request -+ // (see URL above for details on the packets) -+ packetBuffer[0] = 0b11100011; // LI, Version, Mode -+ packetBuffer[1] = 0; // Stratum, or type of clock -+ packetBuffer[2] = 6; // Polling Interval -+ packetBuffer[3] = 0xEC; // Peer Clock Precision -+ // 8 bytes of zero for Root Delay & Root Dispersion -+ packetBuffer[12] = 49; -+ packetBuffer[13] = 0x4E; -+ packetBuffer[14] = 49; -+ packetBuffer[15] = 52; -+ // all NTP fields have been given values, now -+ // you can send a packet requesting a timestamp: -+ Udp.beginPacket(address, 123); //NTP requests are to port 123 -+ Udp.write(packetBuffer, NTP_PACKET_SIZE); -+ Udp.endPacket(); -+} -+ -diff -rupN ./Time/Time/examples/TimeRTC/TimeRTC.pde ../../arduino-1.5.8/libraries/Time/Time/examples/TimeRTC/TimeRTC.pde ---- ./Time/Time/examples/TimeRTC/TimeRTC.pde 1970-01-01 05:30:00.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Time/Time/examples/TimeRTC/TimeRTC.pde 2013-03-24 10:27:58.000000000 +0530 -@@ -0,0 +1,55 @@ -+/* -+ * TimeRTC.pde -+ * example code illustrating Time library with Real Time Clock. -+ * -+ */ -+ -+#include -+#include -+#include // a basic DS1307 library that returns time as a time_t -+ -+void setup() { -+ Serial.begin(9600); -+ while (!Serial) ; // wait until Arduino Serial Monitor opens -+ setSyncProvider(RTC.get); // the function to get the time from the RTC -+ if(timeStatus()!= timeSet) -+ Serial.println("Unable to sync with the RTC"); -+ else -+ Serial.println("RTC has set the system time"); -+} -+ -+void loop() -+{ -+ if (timeStatus() == timeSet) { -+ digitalClockDisplay(); -+ } else { -+ Serial.println("The time has not been set. Please run the Time"); -+ Serial.println("TimeRTCSet example, or DS1307RTC SetTime example."); -+ Serial.println(); -+ delay(4000); -+ } -+ delay(1000); -+} -+ -+void digitalClockDisplay(){ -+ // digital clock display of the time -+ Serial.print(hour()); -+ printDigits(minute()); -+ printDigits(second()); -+ Serial.print(" "); -+ Serial.print(day()); -+ Serial.print(" "); -+ Serial.print(month()); -+ Serial.print(" "); -+ Serial.print(year()); -+ Serial.println(); -+} -+ -+void printDigits(int digits){ -+ // utility function for digital clock display: prints preceding colon and leading 0 -+ Serial.print(":"); -+ if(digits < 10) -+ Serial.print('0'); -+ Serial.print(digits); -+} -+ -diff -rupN ./Time/Time/examples/TimeRTCLog/TimeRTCLog.pde ../../arduino-1.5.8/libraries/Time/Time/examples/TimeRTCLog/TimeRTCLog.pde ---- ./Time/Time/examples/TimeRTCLog/TimeRTCLog.pde 1970-01-01 05:30:00.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Time/Time/examples/TimeRTCLog/TimeRTCLog.pde 2013-03-24 14:52:52.000000000 +0530 -@@ -0,0 +1,107 @@ -+/* -+ * TimeRTCLogger.pde -+ * example code illustrating adding and subtracting Time. -+ * -+ * this sketch logs pin state change events -+ * the time of the event and time since the previous event is calculated and sent to the serial port. -+ */ -+ -+#include -+#include -+#include // a basic DS1307 library that returns time as a time_t -+ -+const int nbrInputPins = 6; // monitor 6 digital pins -+const int inputPins[nbrInputPins] = {2,3,4,5,6,7}; // pins to monitor -+boolean state[nbrInputPins] ; // the state of the monitored pins -+time_t prevEventTime[nbrInputPins] ; // the time of the previous event -+ -+void setup() { -+ Serial.begin(9600); -+ setSyncProvider(RTC.get); // the function to sync the time from the RTC -+ for(int i=0; i < nbrInputPins; i++){ -+ pinMode( inputPins[i], INPUT); -+ // uncomment these lines if pull-up resistors are wanted -+ // pinMode( inputPins[i], INPUT_PULLUP); -+ // state[i] = HIGH; -+ } -+} -+ -+void loop() -+{ -+ for(int i=0; i < nbrInputPins; i++) -+ { -+ boolean val = digitalRead(inputPins[i]); -+ if(val != state[i]) -+ { -+ time_t duration = 0; // the time since the previous event -+ state[i] = val; -+ time_t timeNow = now(); -+ if(prevEventTime[i] > 0) -+ // if this was not the first state change, calculate the time from the previous change -+ duration = duration = timeNow - prevEventTime[i]; -+ logEvent(inputPins[i], val, timeNow, duration ); // log the event -+ prevEventTime[i] = timeNow; // store the time for this event -+ } -+ } -+} -+ -+void logEvent( int pin, boolean state, time_t timeNow, time_t duration) -+{ -+ Serial.print("Pin "); -+ Serial.print(pin); -+ if( state == HIGH) -+ Serial.print(" went High at "); -+ else -+ Serial.print(" went Low at "); -+ showTime(timeNow); -+ if(duration > 0){ -+ // only display duration if greater than 0 -+ Serial.print(", Duration was "); -+ showDuration(duration); -+ } -+ Serial.println(); -+} -+ -+ -+void showTime(time_t t){ -+ // display the given time -+ Serial.print(hour(t)); -+ printDigits(minute(t)); -+ printDigits(second(t)); -+ Serial.print(" "); -+ Serial.print(day(t)); -+ Serial.print(" "); -+ Serial.print(month(t)); -+ Serial.print(" "); -+ Serial.print(year(t)); -+} -+ -+void printDigits(int digits){ -+ // utility function for digital clock display: prints preceding colon and leading 0 -+ Serial.print(":"); -+ if(digits < 10) -+ Serial.print('0'); -+ Serial.print(digits); -+} -+ -+void showDuration(time_t duration){ -+// prints the duration in days, hours, minutes and seconds -+ if(duration >= SECS_PER_DAY){ -+ Serial.print(duration / SECS_PER_DAY); -+ Serial.print(" day(s) "); -+ duration = duration % SECS_PER_DAY; -+ } -+ if(duration >= SECS_PER_HOUR){ -+ Serial.print(duration / SECS_PER_HOUR); -+ Serial.print(" hour(s) "); -+ duration = duration % SECS_PER_HOUR; -+ } -+ if(duration >= SECS_PER_MIN){ -+ Serial.print(duration / SECS_PER_MIN); -+ Serial.print(" minute(s) "); -+ duration = duration % SECS_PER_MIN; -+ } -+ Serial.print(duration); -+ Serial.print(" second(s) "); -+} -+ -diff -rupN ./Time/Time/examples/TimeRTCSet/TimeRTCSet.ino ../../arduino-1.5.8/libraries/Time/Time/examples/TimeRTCSet/TimeRTCSet.ino ---- ./Time/Time/examples/TimeRTCSet/TimeRTCSet.ino 1970-01-01 05:30:00.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Time/Time/examples/TimeRTCSet/TimeRTCSet.ino 2013-03-31 01:19:58.000000000 +0530 -@@ -0,0 +1,80 @@ -+/* -+ * TimeRTCSet.pde -+ * example code illustrating Time library with Real Time Clock. -+ * -+ * RTC clock is set in response to serial port time message -+ * A Processing example sketch to set the time is included in the download -+ * On Linux, you can use "date +T%s > /dev/ttyACM0" (UTC time zone) -+ */ -+ -+#include -+#include -+#include // a basic DS1307 library that returns time as a time_t -+ -+ -+void setup() { -+ Serial.begin(9600); -+ while (!Serial) ; // Needed for Leonardo only -+ setSyncProvider(RTC.get); // the function to get the time from the RTC -+ if (timeStatus() != timeSet) -+ Serial.println("Unable to sync with the RTC"); -+ else -+ Serial.println("RTC has set the system time"); -+} -+ -+void loop() -+{ -+ if (Serial.available()) { -+ time_t t = processSyncMessage(); -+ if (t != 0) { -+ RTC.set(t); // set the RTC and the system time to the received value -+ setTime(t); -+ } -+ } -+ digitalClockDisplay(); -+ delay(1000); -+} -+ -+void digitalClockDisplay(){ -+ // digital clock display of the time -+ Serial.print(hour()); -+ printDigits(minute()); -+ printDigits(second()); -+ Serial.print(" "); -+ Serial.print(day()); -+ Serial.print(" "); -+ Serial.print(month()); -+ Serial.print(" "); -+ Serial.print(year()); -+ Serial.println(); -+} -+ -+void printDigits(int digits){ -+ // utility function for digital clock display: prints preceding colon and leading 0 -+ Serial.print(":"); -+ if(digits < 10) -+ Serial.print('0'); -+ Serial.print(digits); -+} -+ -+/* code to process time sync messages from the serial port */ -+#define TIME_HEADER "T" // Header tag for serial time sync message -+ -+unsigned long processSyncMessage() { -+ unsigned long pctime = 0L; -+ const unsigned long DEFAULT_TIME = 1357041600; // Jan 1 2013 -+ -+ if(Serial.find(TIME_HEADER)) { -+ pctime = Serial.parseInt(); -+ return pctime; -+ if( pctime < DEFAULT_TIME) { // check the value is a valid time (greater than Jan 1 2013) -+ pctime = 0L; // return 0 to indicate that the time is not valid -+ } -+ } -+ return pctime; -+} -+ -+ -+ -+ -+ -diff -rupN ./Time/Time/examples/TimeSerial/TimeSerial.ino ../../arduino-1.5.8/libraries/Time/Time/examples/TimeSerial/TimeSerial.ino ---- ./Time/Time/examples/TimeSerial/TimeSerial.ino 1970-01-01 05:30:00.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Time/Time/examples/TimeSerial/TimeSerial.ino 2013-03-31 01:20:31.000000000 +0530 -@@ -0,0 +1,81 @@ -+/* -+ * TimeSerial.pde -+ * example code illustrating Time library set through serial port messages. -+ * -+ * Messages consist of the letter T followed by ten digit time (as seconds since Jan 1 1970) -+ * you can send the text on the next line using Serial Monitor to set the clock to noon Jan 1 2013 -+ T1357041600 -+ * -+ * A Processing example sketch to automatically send the messages is inclided in the download -+ * On Linux, you can use "date +T%s > /dev/ttyACM0" (UTC time zone) -+ */ -+ -+#include -+ -+#define TIME_HEADER "T" // Header tag for serial time sync message -+#define TIME_REQUEST 7 // ASCII bell character requests a time sync message -+ -+void setup() { -+ Serial.begin(9600); -+ while (!Serial) ; // Needed for Leonardo only -+ pinMode(13, OUTPUT); -+ setSyncProvider( requestSync); //set function to call when sync required -+ Serial.println("Waiting for sync message"); -+} -+ -+void loop(){ -+ if (Serial.available()) { -+ processSyncMessage(); -+ } -+ if (timeStatus()!= timeNotSet) { -+ digitalClockDisplay(); -+ } -+ if (timeStatus() == timeSet) { -+ digitalWrite(13, HIGH); // LED on if synced -+ } else { -+ digitalWrite(13, LOW); // LED off if needs refresh -+ } -+ delay(1000); -+} -+ -+void digitalClockDisplay(){ -+ // digital clock display of the time -+ Serial.print(hour()); -+ printDigits(minute()); -+ printDigits(second()); -+ Serial.print(" "); -+ Serial.print(day()); -+ Serial.print(" "); -+ Serial.print(month()); -+ Serial.print(" "); -+ Serial.print(year()); -+ Serial.println(); -+} -+ -+void printDigits(int digits){ -+ // utility function for digital clock display: prints preceding colon and leading 0 -+ Serial.print(":"); -+ if(digits < 10) -+ Serial.print('0'); -+ Serial.print(digits); -+} -+ -+ -+void processSyncMessage() { -+ unsigned long pctime; -+ const unsigned long DEFAULT_TIME = 1357041600; // Jan 1 2013 -+ -+ if(Serial.find(TIME_HEADER)) { -+ pctime = Serial.parseInt(); -+ if( pctime >= DEFAULT_TIME) { // check the integer is a valid time (greater than Jan 1 2013) -+ setTime(pctime); // Sync Arduino clock to the time received on the serial port -+ } -+ } -+} -+ -+time_t requestSync() -+{ -+ Serial.write(TIME_REQUEST); -+ return 0; // the time will be sent later in response to serial mesg -+} -+ -diff -rupN ./Time/Time/examples/TimeSerialDateStrings/TimeSerialDateStrings.ino ../../arduino-1.5.8/libraries/Time/Time/examples/TimeSerialDateStrings/TimeSerialDateStrings.ino ---- ./Time/Time/examples/TimeSerialDateStrings/TimeSerialDateStrings.ino 1970-01-01 05:30:00.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Time/Time/examples/TimeSerialDateStrings/TimeSerialDateStrings.ino 2013-03-31 01:21:31.000000000 +0530 -@@ -0,0 +1,110 @@ -+/* -+ * TimeSerialDateStrings.pde -+ * example code illustrating Time library date strings -+ * -+ * This sketch adds date string functionality to TimeSerial sketch -+ * Also shows how to handle different messages -+ * -+ * A message starting with a time header sets the time -+ * A Processing example sketch to automatically send the messages is inclided in the download -+ * On Linux, you can use "date +T%s > /dev/ttyACM0" (UTC time zone) -+ * -+ * A message starting with a format header sets the date format -+ * -+ * send: Fs\n for short date format -+ * send: Fl\n for long date format -+ */ -+ -+#include -+ -+// single character message tags -+#define TIME_HEADER 'T' // Header tag for serial time sync message -+#define FORMAT_HEADER 'F' // Header tag indicating a date format message -+#define FORMAT_SHORT 's' // short month and day strings -+#define FORMAT_LONG 'l' // (lower case l) long month and day strings -+ -+#define TIME_REQUEST 7 // ASCII bell character requests a time sync message -+ -+static boolean isLongFormat = true; -+ -+void setup() { -+ Serial.begin(9600); -+ while (!Serial) ; // Needed for Leonardo only -+ setSyncProvider( requestSync); //set function to call when sync required -+ Serial.println("Waiting for sync message"); -+} -+ -+void loop(){ -+ if (Serial.available()) { -+ char c = Serial.read(); -+ if( c == TIME_HEADER) { -+ processSyncMessage(); -+ } -+ else if( c== FORMAT_HEADER) { -+ processFormatMessage(); -+ } -+ } -+ if (timeStatus()!= timeNotSet) { -+ digitalClockDisplay(); -+ } -+ delay(1000); -+} -+ -+void digitalClockDisplay(){ -+ // digital clock display of the time -+ Serial.print(hour()); -+ printDigits(minute()); -+ printDigits(second()); -+ Serial.print(" "); -+ if(isLongFormat) -+ Serial.print(dayStr(weekday())); -+ else -+ Serial.print(dayShortStr(weekday())); -+ Serial.print(" "); -+ Serial.print(day()); -+ Serial.print(" "); -+ if(isLongFormat) -+ Serial.print(monthStr(month())); -+ else -+ Serial.print(monthShortStr(month())); -+ Serial.print(" "); -+ Serial.print(year()); -+ Serial.println(); -+} -+ -+void printDigits(int digits){ -+ // utility function for digital clock display: prints preceding colon and leading 0 -+ Serial.print(":"); -+ if(digits < 10) -+ Serial.print('0'); -+ Serial.print(digits); -+} -+ -+void processFormatMessage() { -+ char c = Serial.read(); -+ if( c == FORMAT_LONG){ -+ isLongFormat = true; -+ Serial.println("Setting long format"); -+ } -+ else if( c == FORMAT_SHORT){ -+ isLongFormat = false; -+ Serial.println("Setting short format"); -+ } -+} -+ -+void processSyncMessage() { -+ unsigned long pctime; -+ const unsigned long DEFAULT_TIME = 1357041600; // Jan 1 2013 - paul, perhaps we define in time.h? -+ -+ pctime = Serial.parseInt(); -+ if( pctime >= DEFAULT_TIME) { // check the integer is a valid time (greater than Jan 1 2013) -+ setTime(pctime); // Sync Arduino clock to the time received on the serial port -+ } -+} -+ -+time_t requestSync() -+{ -+ Serial.write(TIME_REQUEST); -+ return 0; // the time will be sent later in response to serial mesg -+} -+ -diff -rupN ./Time/Time/examples/TimeTeensy3/TimeTeensy3.ino ../../arduino-1.5.8/libraries/Time/Time/examples/TimeTeensy3/TimeTeensy3.ino ---- ./Time/Time/examples/TimeTeensy3/TimeTeensy3.ino 1970-01-01 05:30:00.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Time/Time/examples/TimeTeensy3/TimeTeensy3.ino 2013-03-28 13:53:21.000000000 +0530 -@@ -0,0 +1,78 @@ -+/* -+ * TimeRTC.pde -+ * example code illustrating Time library with Real Time Clock. -+ * -+ */ -+ -+#include -+ -+void setup() { -+ // set the Time library to use Teensy 3.0's RTC to keep time -+ setSyncProvider(getTeensy3Time); -+ -+ Serial.begin(115200); -+ while (!Serial); // Wait for Arduino Serial Monitor to open -+ delay(100); -+ if (timeStatus()!= timeSet) { -+ Serial.println("Unable to sync with the RTC"); -+ } else { -+ Serial.println("RTC has set the system time"); -+ } -+} -+ -+void loop() { -+ if (Serial.available()) { -+ time_t t = processSyncMessage(); -+ if (t != 0) { -+ Teensy3Clock.set(t); // set the RTC -+ setTime(t); -+ } -+ } -+ digitalClockDisplay(); -+ delay(1000); -+} -+ -+void digitalClockDisplay() { -+ // digital clock display of the time -+ Serial.print(hour()); -+ printDigits(minute()); -+ printDigits(second()); -+ Serial.print(" "); -+ Serial.print(day()); -+ Serial.print(" "); -+ Serial.print(month()); -+ Serial.print(" "); -+ Serial.print(year()); -+ Serial.println(); -+} -+ -+time_t getTeensy3Time() -+{ -+ return Teensy3Clock.get(); -+} -+ -+/* code to process time sync messages from the serial port */ -+#define TIME_HEADER "T" // Header tag for serial time sync message -+ -+unsigned long processSyncMessage() { -+ unsigned long pctime = 0L; -+ const unsigned long DEFAULT_TIME = 1357041600; // Jan 1 2013 -+ -+ if(Serial.find(TIME_HEADER)) { -+ pctime = Serial.parseInt(); -+ return pctime; -+ if( pctime < DEFAULT_TIME) { // check the value is a valid time (greater than Jan 1 2013) -+ pctime = 0L; // return 0 to indicate that the time is not valid -+ } -+ } -+ return pctime; -+} -+ -+void printDigits(int digits){ -+ // utility function for digital clock display: prints preceding colon and leading 0 -+ Serial.print(":"); -+ if(digits < 10) -+ Serial.print('0'); -+ Serial.print(digits); -+} -+ -diff -rupN ./Time/Time/Examples/Processing/SyncArduinoClock/readme.txt ../../arduino-1.5.8/libraries/Time/Time/Examples/Processing/SyncArduinoClock/readme.txt ---- ./Time/Time/Examples/Processing/SyncArduinoClock/readme.txt 2009-12-29 17:24:28.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Time/Time/Examples/Processing/SyncArduinoClock/readme.txt 1970-01-01 05:30:00.000000000 +0530 -@@ -1,9 +0,0 @@ --SyncArduinoClock is a Processing sketch that responds to Arduino requests for --time synchronization messages. -- --The portIndex must be set the Serial port connected to Arduino. -- --Download TimeSerial.pde onto Arduino and you should see the time --message displayed when you run SyncArduinoClock in Processing. --The Arduino time is set from the time on your computer through the --Processing sketch. -\ No newline at end of file -diff -rupN ./Time/Time/Examples/Processing/SyncArduinoClock/SyncArduinoClock.pde ../../arduino-1.5.8/libraries/Time/Time/Examples/Processing/SyncArduinoClock/SyncArduinoClock.pde ---- ./Time/Time/Examples/Processing/SyncArduinoClock/SyncArduinoClock.pde 2009-12-30 18:02:06.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Time/Time/Examples/Processing/SyncArduinoClock/SyncArduinoClock.pde 1970-01-01 05:30:00.000000000 +0530 -@@ -1,70 +0,0 @@ --/** -- * SyncArduinoClock. -- * -- * portIndex must be set to the port connected to the Arduino -- * -- * The current time is sent in response to request message from Arduino -- * or by clicking the display window -- * -- * The time message is 11 ASCII text characters; a header (the letter 'T') -- * followed by the ten digit system time (unix time) -- */ -- -- --import processing.serial.*; -- --public static final short portIndex = 1; // select the com port, 0 is the first port --public static final char TIME_HEADER = 'T'; //header byte for arduino serial time message --public static final char TIME_REQUEST = 7; // ASCII bell character --public static final char LF = 10; // ASCII linefeed --public static final char CR = 13; // ASCII linefeed --Serial myPort; // Create object from Serial class -- --void setup() { -- size(200, 200); -- println(Serial.list()); -- println(" Connecting to -> " + Serial.list()[portIndex]); -- myPort = new Serial(this,Serial.list()[portIndex], 9600); --} -- --void draw() --{ -- if ( myPort.available() > 0) { // If data is available, -- char val = char(myPort.read()); // read it and store it in val -- if(val == TIME_REQUEST){ -- long t = getTimeNow(); -- sendTimeMessage(TIME_HEADER, t); -- } -- else -- { -- if(val == LF) -- ; //igonore -- else if(val == CR) -- println(); -- else -- print(val); // echo everying but time request -- } -- } --} -- --void mousePressed() { -- sendTimeMessage( TIME_HEADER, getTimeNow()); --} -- -- --void sendTimeMessage(char header, long time) { -- String timeStr = String.valueOf(time); -- myPort.write(header); // send header and time to arduino -- myPort.write(timeStr); --} -- --long getTimeNow(){ -- // java time is in ms, we want secs -- GregorianCalendar cal = new GregorianCalendar(); -- cal.setTime(new Date()); -- int tzo = cal.get(Calendar.ZONE_OFFSET); -- int dst = cal.get(Calendar.DST_OFFSET); -- long now = (cal.getTimeInMillis() / 1000) ; -- now = now + (tzo/1000) + (dst/1000); -- return now; --} -diff -rupN ./Time/Time/Examples/TimeGPS/TimeGPS.pde ../../arduino-1.5.8/libraries/Time/Time/Examples/TimeGPS/TimeGPS.pde ---- ./Time/Time/Examples/TimeGPS/TimeGPS.pde 2010-01-06 09:45:10.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Time/Time/Examples/TimeGPS/TimeGPS.pde 1970-01-01 05:30:00.000000000 +0530 -@@ -1,82 +0,0 @@ --/* -- * TimeGPS.pde -- * example code illustrating time synced from a GPS -- * -- */ -- --#include --#include //http://arduiniana.org/libraries/TinyGPS/ --#include //http://arduiniana.org/libraries/newsoftserial/ --// GPS and NewSoftSerial libraries are the work of Mikal Hart -- --TinyGPS gps; --NewSoftSerial serial_gps = NewSoftSerial(3, 2); // receive on pin 3 -- --const int offset = 1; // offset hours from gps time (UTC) --time_t prevDisplay = 0; // when the digital clock was displayed -- --void setup() --{ -- Serial.begin(9600); -- serial_gps.begin(4800); -- Serial.println("Waiting for GPS time ... "); -- setSyncProvider(gpsTimeSync); --} -- --void loop() --{ -- while (serial_gps.available()) -- { -- gps.encode(serial_gps.read()); // process gps messages -- } -- if(timeStatus()!= timeNotSet) -- { -- if( now() != prevDisplay) //update the display only if the time has changed -- { -- prevDisplay = now(); -- digitalClockDisplay(); -- } -- } --} -- --void digitalClockDisplay(){ -- // digital clock display of the time -- Serial.print(hour()); -- printDigits(minute()); -- printDigits(second()); -- Serial.print(" "); -- Serial.print(day()); -- Serial.print(" "); -- Serial.print(month()); -- Serial.print(" "); -- Serial.print(year()); -- Serial.println(); --} -- --void printDigits(int digits){ -- // utility function for digital clock display: prints preceding colon and leading 0 -- Serial.print(":"); -- if(digits < 10) -- Serial.print('0'); -- Serial.print(digits); --} -- --time_t gpsTimeSync(){ -- // returns time if avail from gps, else returns 0 -- unsigned long fix_age = 0 ; -- gps.get_datetime(NULL,NULL, &fix_age); -- unsigned long time_since_last_fix; -- if(fix_age < 1000) -- return gpsTimeToArduinoTime(); // return time only if updated recently by gps -- return 0; --} -- --time_t gpsTimeToArduinoTime(){ -- // returns time_t from gps date and time with the given offset hours -- tmElements_t tm; -- int year; -- gps.crack_datetime(&year, &tm.Month, &tm.Day, &tm.Hour, &tm.Minute, &tm.Second, NULL, NULL); -- tm.Year = year - 1970; -- time_t time = makeTime(tm); -- return time + (offset * SECS_PER_HOUR); --} -diff -rupN ./Time/Time/Examples/TimeNTP/TimeNTP.pde ../../arduino-1.5.8/libraries/Time/Time/Examples/TimeNTP/TimeNTP.pde ---- ./Time/Time/Examples/TimeNTP/TimeNTP.pde 2010-03-06 19:20:14.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Time/Time/Examples/TimeNTP/TimeNTP.pde 1970-01-01 05:30:00.000000000 +0530 -@@ -1,120 +0,0 @@ --/* -- * Time_NTP.pde -- * Example showing time sync to NTP time source -- * -- * This sketch uses the Ethenet library with the user contributed UdpBytewise extension -- */ -- --#include --#include --#include // UDP library from: bjoern@cs.stanford.edu 12/30/2008 --#if UDP_TX_PACKET_MAX_SIZE <64 || UDP_RX_PACKET_MAX_SIZE < 64 --#error : UDP packet size to small - modify UdpBytewise.h to set buffers to 64 bytes --#endif --/* -- * -- * You may need to modify the UdpBytewise.h library to allow enough space in the buffers for the NTP packets. -- * Open up UdpBytewse.h and set the following buffers to 64 bytes: -- * #define UDP_TX_PACKET_MAX_SIZE 64 -- * #define UDP_RX_PACKET_MAX_SIZE 64 -- */ -- -- --byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; --byte ip[] = { 192, 168, 1, 44 }; // set the IP address to an unused address on your network -- --byte SNTP_server_IP[] = { 192, 43, 244, 18}; // time.nist.gov --//byte SNTP_server_IP[] = { 130,149,17,21}; // ntps1-0.cs.tu-berlin.de --//byte SNTP_server_IP[] = { 192,53,103,108}; // ptbtime1.ptb.de -- -- --time_t prevDisplay = 0; // when the digital clock was displayed --const long timeZoneOffset = 0L; // set this to the offset in seconds to your local time; -- --void setup() --{ -- Serial.begin(9600); -- Ethernet.begin(mac,ip); -- Serial.println("waiting for sync"); -- setSyncProvider(getNtpTime); -- while(timeStatus()== timeNotSet) -- ; // wait until the time is set by the sync provider --} -- --void loop() --{ -- if( now() != prevDisplay) //update the display only if the time has changed -- { -- prevDisplay = now(); -- digitalClockDisplay(); -- } --} -- --void digitalClockDisplay(){ -- // digital clock display of the time -- Serial.print(hour()); -- printDigits(minute()); -- printDigits(second()); -- Serial.print(" "); -- Serial.print(day()); -- Serial.print(" "); -- Serial.print(month()); -- Serial.print(" "); -- Serial.print(year()); -- Serial.println(); --} -- --void printDigits(int digits){ -- // utility function for digital clock display: prints preceding colon and leading 0 -- Serial.print(":"); -- if(digits < 10) -- Serial.print('0'); -- Serial.print(digits); --} -- --/*-------- NTP code ----------*/ -- --unsigned long getNtpTime() --{ -- sendNTPpacket(SNTP_server_IP); -- delay(1000); -- if ( UdpBytewise.available() ) { -- for(int i=0; i < 40; i++) -- UdpBytewise.read(); // ignore every field except the time -- const unsigned long seventy_years = 2208988800UL + timeZoneOffset; -- return getUlong() - seventy_years; -- } -- return 0; // return 0 if unable to get the time --} -- --unsigned long sendNTPpacket(byte *address) --{ -- UdpBytewise.begin(123); -- UdpBytewise.beginPacket(address, 123); -- UdpBytewise.write(B11100011); // LI, Version, Mode -- UdpBytewise.write(0); // Stratum -- UdpBytewise.write(6); // Polling Interval -- UdpBytewise.write(0xEC); // Peer Clock Precision -- write_n(0, 8); // Root Delay & Root Dispersion -- UdpBytewise.write(49); -- UdpBytewise.write(0x4E); -- UdpBytewise.write(49); -- UdpBytewise.write(52); -- write_n(0, 32); //Reference and time stamps -- UdpBytewise.endPacket(); --} -- --unsigned long getUlong() --{ -- unsigned long ulong = (unsigned long)UdpBytewise.read() << 24; -- ulong |= (unsigned long)UdpBytewise.read() << 16; -- ulong |= (unsigned long)UdpBytewise.read() << 8; -- ulong |= (unsigned long)UdpBytewise.read(); -- return ulong; --} -- --void write_n(int what, int how_many) --{ -- for( int i = 0; i < how_many; i++ ) -- UdpBytewise.write(what); --} -diff -rupN ./Time/Time/Examples/TimeRTC/TimeRTC.pde ../../arduino-1.5.8/libraries/Time/Time/Examples/TimeRTC/TimeRTC.pde ---- ./Time/Time/Examples/TimeRTC/TimeRTC.pde 2010-01-05 14:13:46.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Time/Time/Examples/TimeRTC/TimeRTC.pde 1970-01-01 05:30:00.000000000 +0530 -@@ -1,47 +0,0 @@ --/* -- * TimeRTC.pde -- * example code illustrating Time library with Real Time Clock. -- * -- */ -- --#include --#include --#include // a basic DS1307 library that returns time as a time_t -- --void setup() { -- Serial.begin(9600); -- setSyncProvider(RTC.get); // the function to get the time from the RTC -- if(timeStatus()!= timeSet) -- Serial.println("Unable to sync with the RTC"); -- else -- Serial.println("RTC has set the system time"); --} -- --void loop() --{ -- digitalClockDisplay(); -- delay(1000); --} -- --void digitalClockDisplay(){ -- // digital clock display of the time -- Serial.print(hour()); -- printDigits(minute()); -- printDigits(second()); -- Serial.print(" "); -- Serial.print(day()); -- Serial.print(" "); -- Serial.print(month()); -- Serial.print(" "); -- Serial.print(year()); -- Serial.println(); --} -- --void printDigits(int digits){ -- // utility function for digital clock display: prints preceding colon and leading 0 -- Serial.print(":"); -- if(digits < 10) -- Serial.print('0'); -- Serial.print(digits); --} -- -diff -rupN ./Time/Time/Examples/TimeRTCLog/TimeRTCLog.pde ../../arduino-1.5.8/libraries/Time/Time/Examples/TimeRTCLog/TimeRTCLog.pde ---- ./Time/Time/Examples/TimeRTCLog/TimeRTCLog.pde 2010-01-06 10:30:36.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Time/Time/Examples/TimeRTCLog/TimeRTCLog.pde 1970-01-01 05:30:00.000000000 +0530 -@@ -1,106 +0,0 @@ --/* -- * TimeRTCLogger.pde -- * example code illustrating adding and subtracting Time. -- * -- * this sketch logs pin state change events -- * the time of the event and time since the previous event is calculated and sent to the serial port. -- */ -- --#include --#include --#include // a basic DS1307 library that returns time as a time_t -- --const int nbrInputPins = 6; // monitor 6 digital pins --const int inputPins[nbrInputPins] = {2,3,4,5,6,7}; // pins to monitor --boolean state[nbrInputPins] ; // the state of the monitored pins --time_t prevEventTime[nbrInputPins] ; // the time of the previous event -- --void setup() { -- Serial.begin(9600); -- setSyncProvider(RTC.get); // the function to sync the time from the RTC -- for(int i=0; i < nbrInputPins; i++){ -- pinMode( inputPins[i], INPUT); -- // digitalWrite( inputPins[i], HIGH); // uncomment these lines if -- // state[i] = HIGH; // pull-up resistors are wanted -- } --} -- --void loop() --{ -- for(int i=0; i < nbrInputPins; i++) -- { -- boolean val = digitalRead(inputPins[i]); -- if(val != state[i]) -- { -- time_t duration = 0; // the time since the previous event -- state[i] = val; -- time_t timeNow = now(); -- if(prevEventTime[i] > 0) -- // if this was not the first state change, calculate the time from the previous change -- duration = duration = timeNow - prevEventTime[i]; -- logEvent(inputPins[i], val, timeNow, duration ); // log the event -- prevEventTime[i] = timeNow; // store the time for this event -- } -- } --} -- --void logEvent( int pin, boolean state, time_t timeNow, time_t duration) --{ -- Serial.print("Pin "); -- Serial.print(pin); -- if( state == HIGH) -- Serial.print(" went High at "); -- else -- Serial.print(" went Low at "); -- showTime(timeNow); -- if(duration > 0){ -- // only display duration if greater than 0 -- Serial.print(", Duration was "); -- showDuration(duration); -- } -- Serial.println(); --} -- -- --void showTime(time_t t){ -- // display the given time -- Serial.print(hour(t)); -- printDigits(minute(t)); -- printDigits(second(t)); -- Serial.print(" "); -- Serial.print(day(t)); -- Serial.print(" "); -- Serial.print(month(t)); -- Serial.print(" "); -- Serial.print(year(t)); --} -- --void printDigits(int digits){ -- // utility function for digital clock display: prints preceding colon and leading 0 -- Serial.print(":"); -- if(digits < 10) -- Serial.print('0'); -- Serial.print(digits); --} -- --void showDuration(time_t duration){ --// prints the duration in days, hours, minutes and seconds -- if(duration >= SECS_PER_DAY){ -- Serial.print(duration / SECS_PER_DAY); -- Serial.print(" day(s) "); -- duration = duration % SECS_PER_DAY; -- } -- if(duration >= SECS_PER_HOUR){ -- Serial.print(duration / SECS_PER_HOUR); -- Serial.print(" hour(s) "); -- duration = duration % SECS_PER_HOUR; -- } -- if(duration >= SECS_PER_MIN){ -- Serial.print(duration / SECS_PER_MIN); -- Serial.print(" minute(s) "); -- duration = duration % SECS_PER_MIN; -- } -- Serial.print(duration); -- Serial.print(" second(s) "); --} -- -diff -rupN ./Time/Time/Examples/TimeRTCSet/TimeRTCSet.pde ../../arduino-1.5.8/libraries/Time/Time/Examples/TimeRTCSet/TimeRTCSet.pde ---- ./Time/Time/Examples/TimeRTCSet/TimeRTCSet.pde 2010-01-06 09:53:08.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Time/Time/Examples/TimeRTCSet/TimeRTCSet.pde 1970-01-01 05:30:00.000000000 +0530 -@@ -1,82 +0,0 @@ --/* -- * TimeRTCSet.pde -- * example code illustrating Time library with Real Time Clock. -- * -- * RTC clock is set in response to serial port time message -- * A Processing example sketch to set the time is inclided in the download -- */ -- --#include --#include --#include // a basic DS1307 library that returns time as a time_t -- -- --void setup() { -- Serial.begin(9600); -- setSyncProvider(RTC.get); // the function to get the time from the RTC -- if(timeStatus()!= timeSet) -- Serial.println("Unable to sync with the RTC"); -- else -- Serial.println("RTC has set the system time"); --} -- --void loop() --{ -- if(Serial.available()) -- { -- time_t t = processSyncMessage(); -- if(t >0) -- { -- RTC.set(t); // set the RTC and the system time to the received value -- setTime(t); -- } -- } -- digitalClockDisplay(); -- delay(1000); --} -- --void digitalClockDisplay(){ -- // digital clock display of the time -- Serial.print(hour()); -- printDigits(minute()); -- printDigits(second()); -- Serial.print(" "); -- Serial.print(day()); -- Serial.print(" "); -- Serial.print(month()); -- Serial.print(" "); -- Serial.print(year()); -- Serial.println(); --} -- --void printDigits(int digits){ -- // utility function for digital clock display: prints preceding colon and leading 0 -- Serial.print(":"); -- if(digits < 10) -- Serial.print('0'); -- Serial.print(digits); --} -- --/* code to process time sync messages from the serial port */ --#define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by unix time_t as ten ascii digits --#define TIME_HEADER 'T' // Header tag for serial time sync message -- --time_t processSyncMessage() { -- // return the time if a valid sync message is received on the serial port. -- while(Serial.available() >= TIME_MSG_LEN ){ // time message consists of a header and ten ascii digits -- char c = Serial.read() ; -- Serial.print(c); -- if( c == TIME_HEADER ) { -- time_t pctime = 0; -- for(int i=0; i < TIME_MSG_LEN -1; i++){ -- c = Serial.read(); -- if( c >= '0' && c <= '9'){ -- pctime = (10 * pctime) + (c - '0') ; // convert digits to a number -- } -- } -- return pctime; -- } -- } -- return 0; --} -- -diff -rupN ./Time/Time/Examples/TimeSerial/TimeSerial.pde ../../arduino-1.5.8/libraries/Time/Time/Examples/TimeSerial/TimeSerial.pde ---- ./Time/Time/Examples/TimeSerial/TimeSerial.pde 2010-01-06 10:55:18.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Time/Time/Examples/TimeSerial/TimeSerial.pde 1970-01-01 05:30:00.000000000 +0530 -@@ -1,82 +0,0 @@ --/* -- * TimeSerial.pde -- * example code illustrating Time library set through serial port messages. -- * -- * Messages consist of the letter T followed by ten digit time (as seconds since Jan 1 1970) -- * you can send the text on the next line using Serial Monitor to set the clock to noon Jan 1 2010 -- T1262347200 -- * -- * A Processing example sketch to automatically send the messages is inclided in the download -- */ -- --#include -- --#define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by unix time_t as ten ascii digits --#define TIME_HEADER 'T' // Header tag for serial time sync message --#define TIME_REQUEST 7 // ASCII bell character requests a time sync message -- --void setup() { -- Serial.begin(9600); -- setSyncProvider( requestSync); //set function to call when sync required -- Serial.println("Waiting for sync message"); --} -- --void loop(){ -- if(Serial.available() ) -- { -- processSyncMessage(); -- } -- if(timeStatus()!= timeNotSet) -- { -- digitalWrite(13,timeStatus() == timeSet); // on if synced, off if needs refresh -- digitalClockDisplay(); -- } -- delay(1000); --} -- --void digitalClockDisplay(){ -- // digital clock display of the time -- Serial.print(hour()); -- printDigits(minute()); -- printDigits(second()); -- Serial.print(" "); -- Serial.print(day()); -- Serial.print(" "); -- Serial.print(month()); -- Serial.print(" "); -- Serial.print(year()); -- Serial.println(); --} -- --void printDigits(int digits){ -- // utility function for digital clock display: prints preceding colon and leading 0 -- Serial.print(":"); -- if(digits < 10) -- Serial.print('0'); -- Serial.print(digits); --} -- --void processSyncMessage() { -- // if time sync available from serial port, update time and return true -- while(Serial.available() >= TIME_MSG_LEN ){ // time message consists of a header and ten ascii digits -- char c = Serial.read() ; -- Serial.print(c); -- if( c == TIME_HEADER ) { -- time_t pctime = 0; -- for(int i=0; i < TIME_MSG_LEN -1; i++){ -- c = Serial.read(); -- if( c >= '0' && c <= '9'){ -- pctime = (10 * pctime) + (c - '0') ; // convert digits to a number -- } -- } -- setTime(pctime); // Sync Arduino clock to the time received on the serial port -- } -- } --} -- --time_t requestSync() --{ -- Serial.print(TIME_REQUEST,BYTE); -- return 0; // the time will be sent later in response to serial mesg --} -- -diff -rupN ./Time/Time/Examples/TimeSerialDateStrings/TimeSerialDateStrings.pde ../../arduino-1.5.8/libraries/Time/Time/Examples/TimeSerialDateStrings/TimeSerialDateStrings.pde ---- ./Time/Time/Examples/TimeSerialDateStrings/TimeSerialDateStrings.pde 2010-01-06 10:55:48.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Time/Time/Examples/TimeSerialDateStrings/TimeSerialDateStrings.pde 1970-01-01 05:30:00.000000000 +0530 -@@ -1,80 +0,0 @@ --/* -- * TimeSerialDateStrings.pde -- * example code illustrating Time library date strings -- * -- * This sketch adds date string functionality to TimeSerial.pde -- * -- */ -- --#include -- --#define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by unix time_t as ten ascii digits --#define TIME_HEADER 'T' // Header tag for serial time sync message --#define TIME_REQUEST 7 // ASCII bell character requests a time sync message -- --void setup() { -- Serial.begin(9600); -- setSyncProvider( requestSync); //set function to call when sync required -- Serial.println("Waiting for sync message"); --} -- --void loop(){ -- if(Serial.available() ) -- { -- processSyncMessage(); -- } -- if(timeStatus()!= timeNotSet) -- { -- digitalClockDisplay(); -- } -- delay(1000); --} -- --void digitalClockDisplay(){ -- // digital clock display of the time -- Serial.print(hour()); -- printDigits(minute()); -- printDigits(second()); -- Serial.print(" "); -- Serial.print(dayStr(weekday())); -- Serial.print(" "); -- Serial.print(day()); -- Serial.print(" "); -- Serial.print(monthShortStr(month())); -- Serial.print(" "); -- Serial.print(year()); -- Serial.println(); --} -- --void printDigits(int digits){ -- // utility function for digital clock display: prints preceding colon and leading 0 -- Serial.print(":"); -- if(digits < 10) -- Serial.print('0'); -- Serial.print(digits); --} -- --void processSyncMessage() { -- // if time sync available from serial port, update time and return true -- while(Serial.available() >= TIME_MSG_LEN ){ // time message consists of a header and ten ascii digits -- char c = Serial.read() ; -- Serial.print(c); -- if( c == TIME_HEADER ) { -- time_t pctime = 0; -- for(int i=0; i < TIME_MSG_LEN -1; i++){ -- c = Serial.read(); -- if( c >= '0' && c <= '9'){ -- pctime = (10 * pctime) + (c - '0') ; // convert digits to a number -- } -- } -- setTime(pctime); // Sync Arduino clock to the time received on the serial port -- } -- } --} -- --time_t requestSync() --{ -- Serial.print(TIME_REQUEST,BYTE); -- return 0; // the time will be sent later in response to serial mesg --} -- -diff -rupN ./Time/Time/keywords.txt ../../arduino-1.5.8/libraries/Time/Time/keywords.txt ---- ./Time/Time/keywords.txt 2010-01-05 12:02:50.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Time/Time/keywords.txt 2013-03-23 22:36:10.000000000 +0530 -@@ -5,25 +5,25 @@ - ####################################### - # Datatypes (KEYWORD1) - ####################################### --time_t KEYWORD1 -+time_t KEYWORD1 - ####################################### - # Methods and Functions (KEYWORD2) - ####################################### - now KEYWORD2 --second KEYWORD2 -+second KEYWORD2 - minute KEYWORD2 --hour KEYWORD2 --day KEYWORD2 --month KEYWORD2 --year KEYWORD2 --isAM KEYWORD2 --isPM KEYWORD2 --weekday KEYWORD2 --setTime KEYWORD2 --adjustTime KEYWORD2 --setSyncProvider KEYWORD2 + +-PGM_P dayNames_P[] PROGMEM = { dayStr0,dayStr1,dayStr2,dayStr3,dayStr4,dayStr5,dayStr6,dayStr7}; +-char dayShortNames_P[] PROGMEM = "ErrSunMonTueWedThrFriSat"; ++PGM_P const dayNames_P[] PROGMEM = { dayStr0,dayStr1,dayStr2,dayStr3,dayStr4,dayStr5,dayStr6,dayStr7}; ++const char dayShortNames_P[] PROGMEM = "ErrSunMonTueWedThrFriSat"; + + /* functions to return date strings */ + +diff -rupN ./libraries/Time/Time/keywords.txt ./arduino-1.5.8/libraries/Time/Time/keywords.txt +--- ./libraries/Time/Time/keywords.txt 2010-01-05 12:02:50.000000000 +0530 ++++ ./arduino-1.5.8/libraries/Time/Time/keywords.txt 2015-02-05 16:35:47.000000000 +0530 +@@ -22,7 +22,7 @@ weekday KEYWORD2 + setTime KEYWORD2 + adjustTime KEYWORD2 + setSyncProvider KEYWORD2 -setSyncInteval KEYWORD2 --timeStatus KEYWORD2 -+hour KEYWORD2 -+day KEYWORD2 -+month KEYWORD2 -+year KEYWORD2 -+isAM KEYWORD2 -+isPM KEYWORD2 -+weekday KEYWORD2 -+setTime KEYWORD2 -+adjustTime KEYWORD2 -+setSyncProvider KEYWORD2 -+setSyncInterval KEYWORD2 -+timeStatus KEYWORD2 ++setSyncInterval KEYWORD2 + timeStatus KEYWORD2 ####################################### # Instances (KEYWORD2) - ####################################### -diff -rupN ./Time/Time/Readme.txt ../../arduino-1.5.8/libraries/Time/Time/Readme.txt ---- ./Time/Time/Readme.txt 2010-01-11 21:36:24.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Time/Time/Readme.txt 2013-03-23 21:37:54.000000000 +0530 -@@ -1,131 +1,131 @@ --Readme file for Arduino Time Library -- --Time is a library that provides timekeeping functionality for Arduino. -- --The code is derived from the Playground DateTime library but is updated --to provide an API that is more flexable and easier to use. -- --A primary goal was to enable date and time functionality that can be used with --a variety of external time sources with minimum differences required in sketch logic. -- --Example sketches illustrate how similar sketch code can be used with: a Real Time Clock, --internet NTP time service, GPS time data, and Serial time messages from a computer --for time synchronization. -- --The functions available in the library include: -- --hour(); // the hour now (0-23) --minute(); // the minute now (0-59) --second(); // the second now (0-59) --day(); // the day now (1-31) --weekday(); // day of the week, Sunday is day 0 --month(); // the month now (1-12) --year(); // the full four digit year: (2009, 2010 etc) -- --there are also functions to return the hour in 12 hour format --hourFormat12(); // the hour now in 12 hour format --isAM(); // returns true if time now is AM --isPM(); // returns true if time now is PM -- --now(); // returns the current time as seconds since Jan 1 1970 -- --The time and date functions can take an optional parameter for the time. This prevents --errors if the time rolls over between elements. For example, if a new minute begins --between getting the minute and second, the values will be inconsistent. Using the --following functions eliminates this probglem -- time_t t = now(); // store the current time in time variable t -- hour(t); // returns the hour for the given time t -- minute(t); // returns the minute for the given time t -- second(t); // returns the second for the given time t -- day(t); // the day for the given time t -- weekday(t); // day of the week for the given time t -- month(t); // the month for the given time t -- year(t); // the year for the given time t -- -- --Functions for managing the timer services are: --setTime(t); // set the system time to the give time t --setTime(hr,min,sec,day,mnth,yr); // alternative to above, yr is 2 or 4 digit yr (2010 or 10 sets year to 2010) --adjustTime(adjustment); // adjust system time by adding the adjustment value -- --timeStatus(); // indicates if time has been set and recently synchronized -- // returns one of the following enumerations: -- timeNotSet // the time has never been set, the clock started at Jan 1 1970 -- timeNeedsSync // the time had been set but a sync attempt did not succeed -- timeSet // the time is set and is synced --Time and Date values are not valid if the status is timeNotSet. Otherwise values can be used but --the returned time may have drifted if the status is timeNeedsSync. -- --setSyncProvider(getTimeFunction); // set the external time provider --setSyncInterval(interval); // set the number of seconds between re-sync -- -- --There are many convenience macros in the time.h file for time constants and conversion of time units. -- --To use the library, copy the download to the Library directory. -- --The Time directory contains the Time library and some example sketches --illustrating how the library can be used with various time sources: -- --- TimeSerial.pde shows Arduino as a clock without external hardware. -- It is synchronized by time messages sent over the serial port. -- A companion Processing sketch will automatically provide these messages -- if it is running and connected to the Arduino serial port. -- --- TimeSerialDateStrings.pde adds day and month name strings to the sketch above -- Short (3 character) and long strings are available to print the days of -- the week and names of the months. -- --- TimeRTC uses a DS1307 real time clock to provide time synchronization. -- A basic RTC library named DS1307RTC is included in the download. -- To run this sketch the DS1307RTC library must be installed. -- --- TimeRTCSet is similar to the above and adds the ability to set the Real Time Clock -- --- TimeRTCLog demonstrates how to calculate the difference between times. -- It is a vary simple logger application that monitors events on digtial pins -- and prints (to the serial port) the time of an event and the time period since the previous event. -- --- TimeNTP uses the Arduino Ethernet shield to access time using the internet NTP time service. -- The NTP protocol uses UDP and the UdpBytewise library is required, see: -- http://bitbucket.org/bjoern/arduino_osc/src/14667490521f/libraries/Ethernet/ -- ---TimeGPS gets time from a GPS -- This requires the TinyGPS and NewSoftSerial libraries from Mikal Hart: -- http://arduiniana.org/libraries/TinyGPS and http://arduiniana.org/libraries/newsoftserial/ -- --Differences between this code and the playground DateTime library --although the Time library is based on the DateTime codebase, the API has changed. --Changes in the Time library API: --- time elements are functions returning int (they are variables in DateTime) --- Years start from 1970 --- days of the week and months start from 1 (they start from 0 in DateTime) --- DateStrings do not require a seperate library --- time elements can be accessed non-atomically (in DateTime they are always atomic) --- function added to automatically sync time with extrnal source --- localTime and maketime parameters changed, localTime renamed to breakTime -- --Technical notes: -- --Internal system time is based on the standard Unix time_t. --The value is the number of seconds since Jan 1 1970. --System time begins at zero when the sketch starts. -- --The internal time can be automatically synchronized at regular intervals to an external time source. --This is enabled by calling the setSyncProvider(provider) function - the provider argument is --the address of a function that returns the current time as a time_t. --See the sketches in the examples directory for usage. -- --The default interval for re-syncing the time is 5 minutes but can be changed by calling the --setSyncInterval( interval) method to set the number of seconds between re-sync attempts. -- --The Time library defines a structure for holding time elements that is a compact version of the C tm structure. --All the members of the Arduino tm structure are bytes and the year is offset from 1970. --Convenience macros provide conversion to and from the Arduino format. -- --Low level functions to convert between system time and individual time elements are provided: -- breakTime( time, &tm); // break time_t into elements stored in tm struct -- makeTime( &tm); // return time_t from elements stored in tm struct -- --The DS1307RTC library included in the download provides an example of how a time provider --can use the low level functions to interface with the Time library. -\ No newline at end of file -+Readme file for Arduino Time Library -+ -+Time is a library that provides timekeeping functionality for Arduino. -+ -+The code is derived from the Playground DateTime library but is updated -+to provide an API that is more flexable and easier to use. -+ -+A primary goal was to enable date and time functionality that can be used with -+a variety of external time sources with minimum differences required in sketch logic. -+ -+Example sketches illustrate how similar sketch code can be used with: a Real Time Clock, -+internet NTP time service, GPS time data, and Serial time messages from a computer -+for time synchronization. -+ -+The functions available in the library include: -+ -+hour(); // the hour now (0-23) -+minute(); // the minute now (0-59) -+second(); // the second now (0-59) -+day(); // the day now (1-31) -+weekday(); // day of the week, Sunday is day 0 -+month(); // the month now (1-12) -+year(); // the full four digit year: (2009, 2010 etc) -+ -+there are also functions to return the hour in 12 hour format -+hourFormat12(); // the hour now in 12 hour format -+isAM(); // returns true if time now is AM -+isPM(); // returns true if time now is PM -+ -+now(); // returns the current time as seconds since Jan 1 1970 -+ -+The time and date functions can take an optional parameter for the time. This prevents -+errors if the time rolls over between elements. For example, if a new minute begins -+between getting the minute and second, the values will be inconsistent. Using the -+following functions eliminates this probglem -+ time_t t = now(); // store the current time in time variable t -+ hour(t); // returns the hour for the given time t -+ minute(t); // returns the minute for the given time t -+ second(t); // returns the second for the given time t -+ day(t); // the day for the given time t -+ weekday(t); // day of the week for the given time t -+ month(t); // the month for the given time t -+ year(t); // the year for the given time t -+ -+ -+Functions for managing the timer services are: -+setTime(t); // set the system time to the give time t -+setTime(hr,min,sec,day,mnth,yr); // alternative to above, yr is 2 or 4 digit yr (2010 or 10 sets year to 2010) -+adjustTime(adjustment); // adjust system time by adding the adjustment value -+ -+timeStatus(); // indicates if time has been set and recently synchronized -+ // returns one of the following enumerations: -+ timeNotSet // the time has never been set, the clock started at Jan 1 1970 -+ timeNeedsSync // the time had been set but a sync attempt did not succeed -+ timeSet // the time is set and is synced -+Time and Date values are not valid if the status is timeNotSet. Otherwise values can be used but -+the returned time may have drifted if the status is timeNeedsSync. -+ -+setSyncProvider(getTimeFunction); // set the external time provider -+setSyncInterval(interval); // set the number of seconds between re-sync -+ -+ -+There are many convenience macros in the time.h file for time constants and conversion of time units. -+ -+To use the library, copy the download to the Library directory. -+ -+The Time directory contains the Time library and some example sketches -+illustrating how the library can be used with various time sources: -+ -+- TimeSerial.pde shows Arduino as a clock without external hardware. -+ It is synchronized by time messages sent over the serial port. -+ A companion Processing sketch will automatically provide these messages -+ if it is running and connected to the Arduino serial port. -+ -+- TimeSerialDateStrings.pde adds day and month name strings to the sketch above -+ Short (3 character) and long strings are available to print the days of -+ the week and names of the months. -+ -+- TimeRTC uses a DS1307 real time clock to provide time synchronization. -+ A basic RTC library named DS1307RTC is included in the download. -+ To run this sketch the DS1307RTC library must be installed. -+ -+- TimeRTCSet is similar to the above and adds the ability to set the Real Time Clock -+ -+- TimeRTCLog demonstrates how to calculate the difference between times. -+ It is a vary simple logger application that monitors events on digtial pins -+ and prints (to the serial port) the time of an event and the time period since the previous event. -+ -+- TimeNTP uses the Arduino Ethernet shield to access time using the internet NTP time service. -+ The NTP protocol uses UDP and the UdpBytewise library is required, see: -+ http://bitbucket.org/bjoern/arduino_osc/src/14667490521f/libraries/Ethernet/ -+ -+- TimeGPS gets time from a GPS -+ This requires the TinyGPS library from Mikal Hart: -+ http://arduiniana.org/libraries/TinyGPS -+ -+Differences between this code and the playground DateTime library -+although the Time library is based on the DateTime codebase, the API has changed. -+Changes in the Time library API: -+- time elements are functions returning int (they are variables in DateTime) -+- Years start from 1970 -+- days of the week and months start from 1 (they start from 0 in DateTime) -+- DateStrings do not require a seperate library -+- time elements can be accessed non-atomically (in DateTime they are always atomic) -+- function added to automatically sync time with extrnal source -+- localTime and maketime parameters changed, localTime renamed to breakTime -+ -+Technical notes: -+ -+Internal system time is based on the standard Unix time_t. -+The value is the number of seconds since Jan 1 1970. -+System time begins at zero when the sketch starts. -+ -+The internal time can be automatically synchronized at regular intervals to an external time source. -+This is enabled by calling the setSyncProvider(provider) function - the provider argument is -+the address of a function that returns the current time as a time_t. -+See the sketches in the examples directory for usage. -+ -+The default interval for re-syncing the time is 5 minutes but can be changed by calling the -+setSyncInterval( interval) method to set the number of seconds between re-sync attempts. -+ -+The Time library defines a structure for holding time elements that is a compact version of the C tm structure. -+All the members of the Arduino tm structure are bytes and the year is offset from 1970. -+Convenience macros provide conversion to and from the Arduino format. -+ -+Low level functions to convert between system time and individual time elements are provided: -+ breakTime( time, &tm); // break time_t into elements stored in tm struct -+ makeTime( &tm); // return time_t from elements stored in tm struct -+ -+The DS1307RTC library included in the download provides an example of how a time provider -+can use the low level functions to interface with the Time library. -diff -rupN ./Time/Time/Time.cpp ../../arduino-1.5.8/libraries/Time/Time/Time.cpp ---- ./Time/Time/Time.cpp 2010-11-01 18:02:50.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Time/Time/Time.cpp 2013-03-28 03:19:40.000000000 +0530 -@@ -19,6 +19,11 @@ - 6 Jan 2010 - initial release - 12 Feb 2010 - fixed leap year calculation error - 1 Nov 2010 - fixed setTime bug (thanks to Korman for this) -+ 24 Mar 2012 - many edits by Paul Stoffregen: fixed timeStatus() to update -+ status, updated examples for Arduino 1.0, fixed ARM -+ compatibility issues, added TimeArduinoDue and TimeTeensy3 -+ examples, add error checking and messages to RTC examples, -+ add examples to DS1307RTC library. - */ - - #if ARDUINO >= 100 -@@ -30,12 +35,11 @@ - #include "Time.h" +diff -rupN ./libraries/Time/Time/Time.cpp ./arduino-1.5.8/libraries/Time/Time/Time.cpp +--- ./libraries/Time/Time/Time.cpp 2010-11-01 18:02:50.000000000 +0530 ++++ ./arduino-1.5.8/libraries/Time/Time/Time.cpp 2015-02-05 16:32:08.000000000 +0530 +@@ -31,7 +31,7 @@ static tmElements_t tm; // a cache of time elements --static time_t cacheTime; // the time the cache was updated + static time_t cacheTime; // the time the cache was updated -static time_t syncInterval = 300; // time sync will be attempted after this many seconds -+static time_t cacheTime; // the time the cache was updated -+static uint32_t syncInterval = 300; // time sync will be attempted after this many seconds ++static uint32_t syncInterval = 300; // time sync will be attempted after this many seconds --void refreshCache( time_t t){ -- if( t != cacheTime) -- { -+void refreshCache(time_t t) { -+ if (t != cacheTime) { - breakTime(t, tm); - cacheTime = t; - } -@@ -143,15 +147,17 @@ int year(time_t t) { // the year for the + void refreshCache( time_t t){ + if( t != cacheTime) +@@ -143,15 +143,17 @@ int year(time_t t) { // the year for the static const uint8_t monthDays[]={31,28,31,30,31,30,31,31,30,31,30,31}; // API starts months from 1, this array starts from 0 @@ -2268,7 +207,7 @@ diff -rupN ./Time/Time/Time.cpp ../../arduino-1.5.8/libraries/Time/Time/Time.cpp tm.Second = time % 60; time /= 60; // now it is minutes tm.Minute = time % 60; -@@ -200,7 +206,7 @@ time_t makeTime(tmElements_t &tm){ +@@ -200,7 +202,7 @@ time_t makeTime(tmElements_t &tm){ // previous version used full four digit year (or digits since 2000),i.e. 2009 was 2009 or 9 int i; @@ -2277,7 +216,7 @@ diff -rupN ./Time/Time/Time.cpp ../../arduino-1.5.8/libraries/Time/Time/Time.cpp // seconds from 1970 till 1 jan 00:00:00 of the given year seconds= tm.Year*(SECS_PER_DAY * 365); -@@ -222,14 +228,14 @@ time_t makeTime(tmElements_t &tm){ +@@ -222,14 +224,14 @@ time_t makeTime(tmElements_t &tm){ seconds+= tm.Hour * SECS_PER_HOUR; seconds+= tm.Minute * SECS_PER_MIN; seconds+= tm.Second; @@ -2296,35 +235,17 @@ diff -rupN ./Time/Time/Time.cpp ../../arduino-1.5.8/libraries/Time/Time/Time.cpp static timeStatus_t Status = timeNotSet; getExternalTime getTimePtr; // pointer to external sync function -@@ -240,39 +246,41 @@ time_t sysUnsyncedTime = 0; // the time - #endif - - --time_t now(){ -- while( millis() - prevMillis >= 1000){ -+time_t now() { -+ while (millis() - prevMillis >= 1000){ - sysTime++; - prevMillis += 1000; - #ifdef TIME_DRIFT_INFO - sysUnsyncedTime++; // this can be compared to the synced time to measure long term drift --#endif -+#endif - } -- if(nextSyncTime <= sysTime){ -- if(getTimePtr != 0){ -- time_t t = getTimePtr(); +@@ -251,13 +253,15 @@ time_t now(){ + if(nextSyncTime <= sysTime){ + if(getTimePtr != 0){ + time_t t = getTimePtr(); - if( t != 0) -+ if (nextSyncTime <= sysTime) { -+ if (getTimePtr != 0) { -+ time_t t = getTimePtr(); -+ if (t != 0) { ++ if( t != 0) { setTime(t); - else -- Status = (Status == timeNotSet) ? timeNotSet : timeNeedsSync; + } else { + nextSyncTime = sysTime + syncInterval; -+ Status = (Status == timeNotSet) ? timeNotSet : timeNeedsSync; + Status = (Status == timeNotSet) ? timeNotSet : timeNeedsSync; + } } } @@ -2332,10 +253,8 @@ diff -rupN ./Time/Time/Time.cpp ../../arduino-1.5.8/libraries/Time/Time/Time.cpp + return (time_t)sysTime; } --void setTime(time_t t){ -+void setTime(time_t t) { - #ifdef TIME_DRIFT_INFO - if(sysUnsyncedTime == 0) + void setTime(time_t t){ +@@ -266,9 +270,9 @@ void setTime(time_t t){ sysUnsyncedTime = t; // store the time of the first call to set a valid Time #endif @@ -2348,40 +267,26 @@ diff -rupN ./Time/Time/Time.cpp ../../arduino-1.5.8/libraries/Time/Time/Time.cpp prevMillis = millis(); // restart counting from now (thanks to Korman for this fix) } --void setTime(int hr,int min,int sec,int dy, int mnth, int yr){ -+void setTime(int hr,int min,int sec,int dy, int mnth, int yr){ - // year can be given as full four digit year or two digts (2010 or 10 for 2010); - //it is converted to years since 1970 - if( yr > 99) -@@ -288,11 +296,13 @@ void setTime(int hr,int min,int sec,int - setTime(makeTime(tm)); +@@ -293,6 +297,7 @@ void adjustTime(long adjustment){ } --void adjustTime(long adjustment){ -+void adjustTime(long adjustment) { - sysTime += adjustment; - } - --timeStatus_t timeStatus(){ // indicates if time has been set and recently synchronized -+// indicates if time has been set and recently synchronized -+timeStatus_t timeStatus() { + timeStatus_t timeStatus(){ // indicates if time has been set and recently synchronized + now(); // required to actually update the status return Status; } -@@ -303,5 +313,6 @@ void setSyncProvider( getExternalTime ge +@@ -303,5 +308,6 @@ void setSyncProvider( getExternalTime ge } void setSyncInterval(time_t interval){ // set the number of seconds between re-sync - syncInterval = interval; --} -\ No newline at end of file + syncInterval = (uint32_t)interval; + nextSyncTime = sysTime + syncInterval; -+} -diff -rupN ./Time/Time/Time.h ../../arduino-1.5.8/libraries/Time/Time/Time.h ---- ./Time/Time/Time.h 2011-07-22 17:30:06.000000000 +0530 -+++ ../../arduino-1.5.8/libraries/Time/Time/Time.h 2014-11-25 18:48:37.000000000 +0530 + } +\ No newline at end of file +diff -rupN ./libraries/Time/Time/Time.h ./arduino-1.5.8/libraries/Time/Time/Time.h +--- ./libraries/Time/Time/Time.h 2011-07-22 17:30:06.000000000 +0530 ++++ ./arduino-1.5.8/libraries/Time/Time/Time.h 2015-02-05 16:22:27.000000000 +0530 @@ -8,12 +8,29 @@ */ @@ -2412,7 +317,19 @@ diff -rupN ./Time/Time/Time.h ../../arduino-1.5.8/libraries/Time/Time/Time.h typedef enum {timeNotSet, timeNeedsSync, timeSet } timeStatus_t ; -@@ -121,6 +138,7 @@ void setSyncInterval(time_t interval) +@@ -100,7 +117,11 @@ int month(time_t t); // the month + int year(); // the full four digit year: (2009, 2010 etc) + int year(time_t t); // the year for the given time + ++extern "C" ++{ + time_t now(); // return the current time as seconds since Jan 1 1970 ++} ++ + void setTime(time_t t); + void setTime(int hr,int min,int sec,int day, int month, int yr); + void adjustTime(long adjustment); +@@ -121,6 +142,7 @@ void setSyncInterval(time_t interval) void breakTime(time_t time, tmElements_t &tm); // break time_t into elements time_t makeTime(tmElements_t &tm); // convert time elements into time_t @@ -2421,4 +338,3 @@ diff -rupN ./Time/Time/Time.h ../../arduino-1.5.8/libraries/Time/Time/Time.h +#endif // __cplusplus #endif /* _Time_h */ -Binary files ./Time/Time/.Time.h.swp and ../../arduino-1.5.8/libraries/Time/Time/.Time.h.swp differ diff --git a/resource/csdk/connectivity/lib/arduino/arduinomega.properties b/resource/csdk/connectivity/lib/arduino/arduinomega.properties index bf050d1..3da589e 100644 --- a/resource/csdk/connectivity/lib/arduino/arduinomega.properties +++ b/resource/csdk/connectivity/lib/arduino/arduinomega.properties @@ -30,3 +30,4 @@ CCPLUS=$(ARDUINO_TOOLS_DIR)/avr-g++ CC=$(ARDUINO_TOOLS_DIR)/avr-gcc AR=$(ARDUINO_TOOLS_DIR)/avr-ar RANLIB=$(ARDUINO_TOOLS_DIR)/avr-ranlib + diff --git a/resource/csdk/connectivity/lib/arduino/local.properties b/resource/csdk/connectivity/lib/arduino/local.properties index 62598c8..e318153 100644 --- a/resource/csdk/connectivity/lib/arduino/local.properties +++ b/resource/csdk/connectivity/lib/arduino/local.properties @@ -1,2 +1,2 @@ ARDUINO_DIR = /usr/share/arduino -ARDUINO_TOOLS_DIR = $(ARDUINO_DIR)/hardware/tools/avr/bin \ No newline at end of file +ARDUINO_TOOLS_DIR = $(ARDUINO_DIR)/hardware/tools/avr/bin diff --git a/resource/csdk/connectivity/lib/tizen/ble/inc/bluetooth.h b/resource/csdk/connectivity/lib/tizen/ble/inc/bluetooth.h new file mode 100644 index 0000000..957537e --- /dev/null +++ b/resource/csdk/connectivity/lib/tizen/ble/inc/bluetooth.h @@ -0,0 +1,4471 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd 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 __TIZEN_NETWORK_BLUETOOTH_H__ +#define __TIZEN_NETWORK_BLUETOOTH_H__ + +#include +#include +#include +#include + +#include "bluetooth_type.h" + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +/** + * @file bluetooth.h + * @brief API to control the Bluetooth adapter and devices and communications. + * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE + */ + + +/** + * @addtogroup CAPI_NETWORK_BLUETOOTH_MODULE + * @{ + */ + + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE + * @brief Initializes the Bluetooth API. + * @since_tizen 2.3 + * + * @remarks This function must be called before Bluetooth API starts. \n + * You must free all resources of the Bluetooth service by calling bt_deinitialize() if Bluetooth service is no longer needed. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * + * @see bt_deinitialize() + */ +int bt_initialize(void); + + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE + * @brief Releases all resources of the Bluetooth API. + * @since_tizen 2.3 + * + * @remarks This function must be called if Bluetooth API is no longer needed. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * + * @pre Bluetooth API must be initialized with bt_initialize(). + * + * @see bt_initialize() + */ +int bt_deinitialize(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Enables the local Bluetooth adapter, asynchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @details This function enables Bluetooth protocol stack and hardware. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_ALREADY_DONE Already enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre Bluetooth service must be initialized with bt_initialize(). + * @pre The state of local Bluetooth must be #BT_ADAPTER_DISABLED + * @post This function invokes bt_adapter_state_changed_cb(). + * + * @see bt_initialize() + * @see bt_adapter_get_state() + * @see bt_adapter_set_state_changed_cb() + * @see bt_adapter_unset_state_changed_cb() + * @see bt_adapter_state_changed_cb() + * + */ +int bt_adapter_enable(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Disables the local Bluetooth adapter, asynchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @details This function disables Bluetooth protocol stack and hardware. + * + * @remarks You should disable Bluetooth adapter, which is helpful for saving power. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED + * @post This function invokes bt_adapter_state_changed_cb(). + * + * @see bt_adapter_get_state() + * @see bt_adapter_state_changed_cb() + * @see bt_adapter_set_state_changed_cb() + * @see bt_adapter_unset_state_changed_cb () + * + */ +int bt_adapter_disable(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Recover the local Bluetooth adapter, asynchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @details This function does recovery logic, disables Bluetooth protocol stack and hardware, then enables after a few seconds. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED + * @post This function invokes bt_adapter_state_changed_cb(). + * + * @see bt_adapter_get_state() + * @see bt_adapter_state_changed_cb() + * @see bt_adapter_set_state_changed_cb() + * @see bt_adapter_unset_state_changed_cb () + * + */ +int bt_adapter_recover(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Reset the local Bluetooth adapter, synchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @details This function resets Bluetooth protocol and values. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_state_changed_cb() will be invoked if The state of local Bluetooth was #BT_ADAPTER_ENABLED. + * + * @see bt_initialize() + * @see bt_adapter_get_state() + * @see bt_adapter_set_state_changed_cb() + * @see bt_adapter_unset_state_changed_cb() + * @see bt_adapter_state_changed_cb() + * + */ +int bt_adapter_reset(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Gets the current state of local Bluetooth adapter. + * @since_tizen 2.3 + * + * @param[out] adapter_state The current adapter state + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + */ +int bt_adapter_get_state(bt_adapter_state_e *adapter_state); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Gets the address of local Bluetooth adapter. + * @since_tizen 2.3 + * + * @remarks The @a local_address must be released with free() by you. + * + * @param[out] local_address The device address of local Bluetooth adapter + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_adapter_get_name() + */ +int bt_adapter_get_address(char **local_address); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Gets the version of local Bluetooth adapter. + * @since_tizen 2.3 + * @remarks The @a local_version must be released with free() by you. + * + * @param[out] local_version The version of local Bluetooth adapter + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + */ +int bt_adapter_get_version(char **local_version); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Gets the information regarding local Bluetooth adapter. + * @since_tizen 2.3 + * @remarks The @a all parameters must be released with free() by you. + * + * @param[out] chipset Chipset name of local Bluetooth adapter + * @param[out] firmware Firmware info. of local Bluetooth adapter + * @param[out] stack_version Bluetooth stack version + * @param[out] profiles The profile list of local Bluetooth adapter + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + */ +int bt_adapter_get_local_info(char **chipset, char **firmware, char **stack_version, char **profiles); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Gets the name of local Bluetooth adapter. + * @since_tizen 2.3 + * + * @details Use this function to get the friendly name associated with Bluetooth + * device, retrieved by the remote Bluetooth devices. + * + * @remarks The @a local_name must be released with free() by you. + * + * @param[out] local_name The local device name + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_adapter_set_name() + */ +int bt_adapter_get_name(char **local_name); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Sets the name of local Bluetooth adapter. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] local_name The name of the Bluetooth device. \n + * The maximum length is 248 characters. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post bt_adapter_name_changed_cb() will be invoked if this function returns #BT_ERROR_NONE. + * + * @see bt_adapter_get_name() + * @see bt_adapter_name_changed_cb() + * @see bt_adapter_set_name_changed_cb() + * @see bt_adapter_unset_name_changed_cb() + */ +int bt_adapter_set_name(const char *local_name); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Gets the visibility mode of local Bluetooth adapter. + * @since_tizen 2.3 + * @param[out] mode The visibility mode of the Bluetooth device + * @param[out] duration The duration until the visibility mode is changed to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE (in seconds). + * @a duration is valid only if @a mode is #BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE. This value can be NULL. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + */ +int bt_adapter_get_visibility(bt_adapter_visibility_mode_e *mode, int *duration); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Sets the visibility mode. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @remarks #BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE will change to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE + * after the given @a duration goes. + * + * @param[in] discoverable_mode The Bluetooth visibility mode to set + * @param[in] duration The duration until the visibility mode is changed to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE (in seconds). + * @a duration is used only for #BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE mode. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post bt_adapter_visibility_mode_changed_cb() will be invoked if this function returns #BT_ERROR_NONE. + * + * @see bt_adapter_get_visibility() + * @see bt_adapter_visibility_mode_changed_cb() + * @see bt_adapter_set_visibility_mode_changed_cb() + * @see bt_adapter_unset_visibility_mode_changed_cb() + */ +int bt_adapter_set_visibility(bt_adapter_visibility_mode_e discoverable_mode, int duration); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Starts the device discovery, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @details If a device is discovered, bt_adapter_device_discovery_state_changed_cb() will be invoked + * with #BT_ADAPTER_DEVICE_DISCOVERY_FOUND, and then bt_adapter_device_discovery_state_changed_cb() + * will be called with #BT_ADAPTER_DEVICE_DISCOVERY_FINISHED in case of the completion or cancellation of the discovery. + * + * @remarks To connect to peer Bluetooth device, you need to know its Bluetooth address. \n + * The device discovery can be stopped by bt_adapter_stop_device_discovery(). + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation is now in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post This function invokes bt_adapter_device_discovery_state_changed_cb(). + * + * @see bt_adapter_is_discovering() + * @see bt_adapter_stop_device_discovery() + * @see bt_adapter_device_discovery_state_changed_cb() + * @see bt_adapter_set_device_discovery_state_changed_cb() + * @see bt_adapter_unset_device_discovery_state_changed_cb() + */ +int bt_adapter_start_device_discovery(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Stops the device discovery, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @remarks The device discovery process will take 10 ~ 20 seconds to get all the devices in vicinity. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOT_IN_PROGRESS Operation is not in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The device discovery must be in progress with bt_adapter_start_device_discovery(). + * @post This function invokes bt_adapter_device_discovery_state_changed_cb(). + * + * @see bt_adapter_is_discovering() + * @see bt_adapter_start_device_discovery() + * @see bt_adapter_set_device_discovery_state_changed_cb() + * @see bt_adapter_unset_device_discovery_state_changed_cb() + * @see bt_adapter_device_discovery_state_changed_cb() + */ +int bt_adapter_stop_device_discovery(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Checks for the device discovery is in progress or not. + * @since_tizen 2.3 + * + * @remarks If Bluetooth discovery is in progress, other operations are not allowed and + * you have to either stop the discovery operation, or wait for it to be finished, + * before performing other operations. + + * @param[out] is_discovering The discovering status: (@c true = in progress , @c false = not in progress ) + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_adapter_start_device_discovery() + * @see bt_adapter_stop_device_discovery() + */ +int bt_adapter_is_discovering(bool *is_discovering); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Get the service mask from the uuid list. + * @since_tizen 2.3 + * + * @param[in] uuids The UUID list of the device. + * @param[in] no_of_service The number of the UUID list count. + * @param[out] service_mask_list Service mask list converted from the given UUID list. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see bt_service_class_t + */ +int bt_device_get_service_mask_from_uuid_list(char **uuids, + int no_of_service, + bt_service_class_t *service_mask_list); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Retrieves the device information of all bonded devices. + * @since_tizen 2.3 + * + * @param [in] callback The callback function to invoke + * @param [in] user_data The user data passed from the foreach function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post This function invokes bt_adapter_bonded_device_cb(). + * + * @see bt_adapter_bonded_device_cb() + */ +int bt_adapter_foreach_bonded_device(bt_adapter_bonded_device_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Gets the device information of a bonded device. + * @since_tizen 2.3 + * @remarks The @a device_info must be released with bt_adapter_free_device_info() by you . + * + * @param [in] remote_address The address of remote device + * @param [out] device_info The bonded device information + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post This function invokes bt_adapter_bonded_device_cb(). + * + * @see bt_adapter_bonded_device_cb() + */ +int bt_adapter_get_bonded_device_info(const char *remote_address, bt_device_info_s **device_info); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Frees device info. + * @since_tizen 2.3 + * + * @param [in] device_info The bonded device information + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see bt_adapter_get_bonded_device_info() + */ +int bt_adapter_free_device_info(bt_device_info_s *device_info); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Checks whether the UUID of service is used or not + * @since_tizen 2.3 + * @param[in] service_uuid The UUID of service + * @param[out] used Indicates whether the service is used or not + * @return true on success, otherwise false. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + */ +int bt_adapter_is_service_used(const char *service_uuid, bool *used); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Registers a callback function to be invoked when the Bluetooth adapter state changes. + * @since_tizen 2.3 + * + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_state_changed_cb() will be invoked. + * + * @see bt_initialize() + * @see bt_adapter_state_changed_cb() + * @see bt_adapter_set_state_changed_cb() + * @see bt_adapter_unset_state_changed_cb() + */ +int bt_adapter_set_state_changed_cb(bt_adapter_state_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + * @see bt_adapter_set_state_changed_cb() + */ +int bt_adapter_unset_state_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Registers a callback function to be invoked when the name of Bluetooth adapter changes. + * @since_tizen 2.3 + * + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_name_changed_cb() will be invoked. + * + * @see bt_initialize() + * @see bt_adapter_name_changed_cb() + * @see bt_adapter_unset_name_changed_cb() + */ +int bt_adapter_set_name_changed_cb(bt_adapter_name_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + * @see bt_adapter_set_name_changed_cb() + */ +int bt_adapter_unset_name_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Registers a callback function to be invoked when the visibility mode changes. + * @since_tizen 2.3 + * + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_visibility_mode_changed_cb() will be invoked. + * + * @see bt_initialize() + * @see bt_adapter_visibility_mode_changed_cb() + * @see bt_adapter_unset_visibility_mode_changed_cb() + */ +int bt_adapter_set_visibility_mode_changed_cb(bt_adapter_visibility_mode_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + * @see bt_adapter_set_visibility_mode_changed_cb() + */ +int bt_adapter_unset_visibility_mode_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Registers a callback function to be invoked every second + * @since_tizen 2.3 + * until the visibility mode is changed from #BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE + * to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE. + * @details When you set visibility mode as #BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE, + * @a callback will be called every second until visibility mode is changed to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE. + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @post bt_adapter_visibility_duration_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_adapter_visibility_duration_changed_cb() + * @see bt_adapter_unset_visibility_duration_changed_cb() + */ +int bt_adapter_set_visibility_duration_changed_cb(bt_adapter_visibility_duration_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_adapter_set_visibility_duration_changed_cb() + */ +int bt_adapter_unset_visibility_duration_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Registers a callback function to be invoked when the device discovery state changes. + * @since_tizen 2.3 + * + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_device_discovery_state_changed_cb() will be invoked. + * + * @see bt_initialize() + * @see bt_adapter_device_discovery_state_changed_cb() + * @see bt_adapter_set_device_discovery_state_changed_cb() + * @see bt_adapter_unset_device_discovery_state_changed_cb() + */ +int bt_adapter_set_device_discovery_state_changed_cb(bt_adapter_device_discovery_state_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + * @see bt_adapter_set_device_discovery_state_changed_cb() + */ +int bt_adapter_unset_device_discovery_state_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Get the Hash and Randmoizer value, synchronously. + * @since_tizen 2.3 + * + * @param[out] hash The hash value recieved from the controller + * @param[out] randomizer The hash value recieved from the controller + * @param[out] hash_len The length of the hash value + * @param[out] randomizer_len The length of the randomizer value + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + */ +int bt_adapter_get_local_oob_data(unsigned char **hash, unsigned char **randomizer, + int *hash_len, int *randomizer_len); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Sets the Hash and Randmoizer value, synchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] remote_address Remote device address + * @param[in] hash The hash value recieved from the controller + * @param[in] randomizer The hash value recieved from the controller + * @param[in] hash_len The length of the hash value. Allowed value is 16 + * @param[in] randomizer_len The length of the randomizer value. Allowed value is 16 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + */ +int bt_adapter_set_remote_oob_data(const char *remote_address, + unsigned char *hash, unsigned char *randomizer, + int hash_len, int randomizer_len); +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Deletes the Hash and Randomizer value, synchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] remote_address Remote device address + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + */ +int bt_adapter_remove_remote_oob_data(const char *remote_address); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Registers a callback function to be invoked when the connectable state changes. + * @since_tizen 2.3 + * + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_connectable_changed_cb() will be invoked. + * + * @see bt_initialize() + * @see bt_adapter_connectable_changed_cb() + * @see bt_adapter_unset_connectable_changed_cb() + */ +int bt_adapter_set_connectable_changed_cb(bt_adapter_connectable_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + * @see bt_adapter_set_connectable_changed_cb() + */ +int bt_adapter_unset_connectable_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Gets the connectable state of local Bluetooth adapter. + * @since_tizen 2.3 + * + * @remarks When connectable state is false, no device can connect to this device and visibility mode cannot be changed. + * + * @param[out] connectable The connectable state of local Bluetooth adapter + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_adapter_set_connectable() + */ +int bt_adapter_get_connectable(bool *connectable); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Sets the connectable state of local Bluetooth adapter. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @remarks When connectable state is false, no device can connect to this device and visibility mode cannot be changed. + * + * @param[in] connectable The connectable state to set + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post bt_adapter_connectable_changed_cb() will be invoked if this function returns #BT_ERROR_NONE. + * + * @see bt_adapter_get_connectable() + * @see bt_adapter_connectable_changed_cb() + * @see bt_adapter_set_connectable_changed_cb() + * @see bt_adapter_unset_connectable_changed_cb() + */ +int bt_adapter_set_connectable(bool connectable); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enables the local Bluetooth le adapter, asynchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @details This function enables Bluetooth protocol stack and hardware. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_ALREADY_DONE Already enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre Bluetooth service must be initialized with bt_initialize(). + * @post This function invokes bt_adapter_le_state_changed_cb(). + * + * @see bt_initialize() + * @see bt_adapter_le_get_state() + * @see bt_adapter_le_set_state_changed_cb() + * @see bt_adapter_le_unset_state_changed_cb() + * @see bt_adapter_le_state_changed_cb() + * + */ +int bt_adapter_le_enable(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Disables the local Bluetooth le adapter, asynchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @details This function disables Bluetooth le protocol stack and hardware. + * + * @remarks + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_LE_ENABLED + * @post This function invokes bt_adapter_le_state_changed_cb(). + * + * @see bt_adapter_le_get_state() + * @see bt_adapter_le_state_changed_cb() + * @see bt_adapter_le_set_state_changed_cb() + * @see bt_adapter_le_unset_state_changed_cb () + * + */ +int bt_adapter_le_disable(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Gets the current state of local Bluetooth adapter. + * @since_tizen 2.3 + * + * @param[out] adapter_le_state The current adapter le state + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + */ +int bt_adapter_le_get_state(bt_adapter_le_state_e *adapter_le_state); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Starts the LE device discovery for a BT_ADAPTER_DEVICE_DISCOVERY_LE type. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @details If a LE device is discovered, bt_adapter_le_device_discovery_state_changed_cb() +* will be invoked with #BT_ADAPTER_LE_DEVICE_DISCOVERY_FOUND, and then bt_adapter_le_device_discovery_state_changed_cb() + * will be called with #BT_ADAPTER_LE_DEVICE_DISCOVERY_FINISHED in case of the completion or cancellation of the discovery. + * + * @remarks To connect to peer Bluetooth device, you need to know its Bluetooth address. \n + * The device discovery can be stopped by bt_adapter_le_stop_device_discovery(). + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation is now in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * or must be #BT_ADAPTER_LE_ENABLED. + * @post This function invokes bt_adapter_le_device_discovery_state_changed_cb(). + * + * @see bt_adapter_le_is_discovering() + * @see bt_adapter_le_device_discovery_state_changed_cb() + * @see bt_adapter_le_set_device_discovery_state_changed_cb() + * @see bt_adapter_le_unset_device_discovery_state_changed_cb() + */ +int bt_adapter_le_start_device_discovery(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Stops the LE device discovery, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOT_IN_PROGRESS Operation is not in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The device discovery must be in progress with bt_adapter_le_start_device_discovery(). + * @post This function invokes bt_adapter_le_device_discovery_state_changed_cb(). + * + * @see bt_adapter_le_is_discovering() + * @see bt_adapter_le_start_device_discovery() + * @see bt_adapter_le_set_device_discovery_state_changed_cb() + * @see bt_adapter_le_unset_device_discovery_state_changed_cb() + * @see bt_adapter_le_device_discovery_state_changed_cb() + */ +int bt_adapter_le_stop_device_discovery(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Checks for the LE device discovery is in progress or not. + * @since_tizen 2.3 + * + * @remarks If Bluetooth LE discovery is in progress, other operations are not allowed and + * you have to either stop the LE discovery operation, or wait for it to be finished, + * before performing other operations. + + * @param[out] is_discovering The discovering status: (@c true = in progress , @c false = not in progress ) + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * or must be #BT_ADAPTER_LE_ENABLED. + * + * @see bt_adapter_le_start_device_discovery() + * @see bt_adapter_le_stop_device_discovery() + */ +int bt_adapter_le_is_discovering(bool *is_discovering); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Registers a callback function to be invoked when the LE device discovery state changes. + * @since_tizen 2.3 + * + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_le_device_discovery_state_changed_cb() will be invoked. + * + * @see bt_initialize() + * @see bt_adapter_le_device_discovery_state_changed_cb() + * @see bt_adapter_le_unset_device_discovery_state_changed_cb() + */ +int bt_adapter_le_set_device_discovery_state_changed_cb(bt_adapter_le_device_discovery_state_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + * @see bt_adapter_le_set_device_discovery_state_changed_cb() + */ +int bt_adapter_le_unset_device_discovery_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Registers a callback function to be invoked when the Bluetooth adapter le state changes. + * @since_tizen 2.3 + * + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_le_state_changed_cb() will be invoked. + * + * @see bt_initialize() + * @see bt_adapter_le_state_changed_cb() + * @see bt_adapter_le_unset_state_changed_cb() + */ +int bt_adapter_le_set_state_changed_cb(bt_adapter_le_state_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + * @see bt_adapter_le_set_state_changed_cb() + */ +int bt_adapter_le_unset_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief add address to whitelist for accepting scanning request. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @remarks If the adress is in the whitelist then other LE devices are able to + * search this device. Before calling this API, make sure that the adapter is + * enabled. There is no callback event for this API. + + * @param[in] address The other device's address + * @param[in] address_type The other device's address type + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Adapter is not enabled + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_adapter_le_start_advertising() + * @see bt_adapter_le_stop_advertising() + */ +int bt_adapter_le_add_white_list(const char *address, bt_device_address_type_e address_type); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief remove address from the whitelist for not accepting scanning request. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @remarks If the adress is in the whitelist then other LE devices are able to + * search this device. Before calling this API, make sure that the adapter is + * enabled. There is no callback event for this API. + * + * @param[in] address The other device's address + * @param[in] address_type The other device's address type + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Adapter is not enabled + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_adapter_le_start_advertising() + * @see bt_adapter_le_stop_advertising() + */ +int bt_adapter_le_remove_white_list(const char *address, bt_device_address_type_e address_type); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief clear address from the whitelist for not accepting scanning request. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @remarks If the adress is in the whitelist then other LE devices are able to + * search this device. Before calling this API, make sure that the adapter is + * enabled. There is no callback event for this API. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Adapter is not enabled + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_adapter_le_start_advertising() + * @see bt_adapter_le_stop_advertising() + */ +int bt_adapter_le_clear_white_list(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Create advertiser to advertise device's existence or respond to LE scanning reqeust. + * @since_tizen 2.3 + * + * @param[out] advertiser The handle of advertiser + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_destroy_advertiser() + */ +int bt_adapter_le_create_advertiser(bt_advertiser_h *advertiser); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Destroy advertiser. + * @since_tizen 2.3 + * + * @param[out] advertiser The handle of advertiser + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_create_advertiser() + */ +int bt_adapter_le_destroy_advertiser(bt_advertiser_h advertiser); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Set the data to be advertised or responded to scan request from LE scanning device. + * The maximum advertised or responded data size is 31 bytes + * including data type and system wide data. + * @since_tizen 2.3 + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] data_type The data type that is included in packet + * @param[in] data The data to be advertised or be responded to scan request from LE scanning device + * @param[in] data_size The size of data to be set. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_QUOTA_EXCEEDED Quota exceeded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_remove_advertising_data() + * @see bt_adapter_le_clear_advertising_data() + */ +int bt_adapter_le_add_advertising_data(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, bt_adapter_le_packet_data_type_e data_type, + void *data, unsigned int data_size); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Unset the data to be advertised or responded to scan request from LE scanning device. + * @since_tizen 2.3 + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type + * @param[in] data_type The data type to be removed from selected packet + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_add_advertising_data() + * @see bt_adapter_le_clear_advertising_data() + */ +int bt_adapter_le_remove_advertising_data(bt_advertiser_h advertiser, + bt_adapter_le_packet_type_e pkt_type, bt_adapter_le_packet_data_type_e data_type); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Clear all data to be advertised or responded to scan request from LE scanning device. + * @since_tizen 2.3 + * + * @param[in] advertiser The handle of advertiser + * @param[in] pkt_type The packet type to be cleared + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_add_advertising_data() + * @see bt_adapter_le_remove_advertising_data() + */ +int bt_adapter_le_clear_advertising_data(bt_advertiser_h advertiser, bt_adapter_le_packet_type_e pkt_type); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Start advertising with passed advertiser and advertising parameters. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @details Once Bluetooth advertising is started, nearby Bluetooth LE(Low Energy) supported + * devices can know this device's existence. And one of them can make a connection reqeust, + * if it is allowed. + * + * @param[in] advertiser The handle of advertiser + * @param[in] adv_params The parameters of advertising \n + * If NULL is passed, default values which are defined in driver / controller are used. + * @param[in] cb The callback to report the result of this function + * @param[in] user_data The user data to be passed when callback is called + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation is now in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post This function invokes bt_adapter_le_advertising_state_changed_cb(). + * + * @see bt_adapter_le_stop_advertising() + * @see bt_adapter_le_advertising_state_changed_cb() + */ +int bt_adapter_le_start_advertising(bt_advertiser_h advertiser, bt_adapter_le_advertising_params_s *adv_params, + bt_adapter_le_advertising_state_changed_cb cb, void *user_data); +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Stops the advertising. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] advertiser The handle of advertiser + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOT_IN_PROGRESS Operation is not in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The advertising must be going on with bt_adapter_le_start_advertising(). + * @post This function invokes bt_adapter_le_advertising_state_changed_cb(). + * + * @see bt_adapter_le_start_advertising() + * @see bt_adapter_le_advertising_state_changed_cb() + */ +int bt_adapter_le_stop_advertising(bt_advertiser_h advertiser); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Sets the Privacy feature state of local Bluetooth adapter. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @param[in] enable_privacy The privacy feature to set/unset. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The state of local Bluetooth must be #BT_ADAPTER_LE_ENABLED. + * + */ +int bt_adapter_le_enable_privacy(bool enable_privacy); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Creates a bond with a remote Bluetooth device, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @remarks A bond can be destroyed by bt_device_destroy_bond().\n + * The bonding request can be cancelled by bt_device_cancel_bonding(). + * + * @param[in] remote_address The address of the remote Bluetooth device with which the bond should be created + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The remote device must be discoverable with bt_adapter_start_device_discovery(). + * @post This function invokes bt_device_bond_created_cb(). + * + * @see bt_adapter_start_device_discovery() + * @see bt_device_bond_created_cb() + * @see bt_device_cancel_bonding() + * @see bt_device_destroy_bond() + * @see bt_device_set_bond_created_cb() + * @see bt_device_unset_bond_created_cb() + */ +int bt_device_create_bond(const char *remote_address); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Creates a bond with a remote Bluetooth device, asynchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @remarks A bond can be destroyed by bt_device_destroy_bond().\n + * The bonding request can be cancelled by bt_device_cancel_bonding(). + * + * @param[in] remote_address The address of the remote Bluetooth device with which the bond should be created + * @param[in] conn_type The connection type(LE or BREDR) to create bond with remote device + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The remote device must be discoverable with bt_adapter_start_device_discovery(). + * @post This function invokes bt_device_bond_created_cb(). + * + * @see bt_adapter_start_device_discovery() + * @see bt_device_create_bond() + * @see bt_device_bond_created_cb() + * @see bt_device_cancel_bonding() + * @see bt_device_destroy_bond() + * @see bt_device_set_bond_created_cb() + * @see bt_device_unset_bond_created_cb() + */ +int bt_device_create_bond_by_type(const char *remote_address, + bt_device_connection_link_type_e conn_type); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Cancels the bonding process. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @remarks Use this function when the remote Bluetooth device is not responding to the + * bond request or you wish to cancel the bonding request. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOT_IN_PROGRESS Operation not in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The creating a bond must be in progress by bt_device_create_bond(). + * + * @see bt_device_create_bond() + * @see bt_device_bond_created_cb() + * @see bt_device_set_bond_created_cb() + * @see bt_device_unset_bond_created_cb() + */ +int bt_device_cancel_bonding(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Destroys the bond, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] remote_address The address of the remote Bluetooth device to remove bonding + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The bond with the remote device must be created with bt_device_create_bond(). + * @post This function invokes bt_device_bond_destroyed_cb(). + * + * @see bt_device_create_bond() + * @see bt_device_bond_destroyed_cb() + * @see bt_device_set_bond_destroyed_cb() + * @see bt_device_unset_bond_destroyed_cb() + */ +int bt_device_destroy_bond(const char *remote_address); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Sets an alias for the bonded device. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] remote_address The address of the remote Bluetooth device + * @param[in] alias The alias of the remote Bluetooth device + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The bond with the remote device must be created with bt_device_create_bond(). + * + * @see bt_device_create_bond() + */ +int bt_device_set_alias(const char *remote_address, const char *alias); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Sets the authorization of a bonded device, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @remarks Once a device is authorized, you don't need to receive a confirmation. + * + * @param[in] remote_address The address of the remote Bluetooth device to authorize + * @param[in] authorization_state The Bluetooth authorization state + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The bond with the remote device must be created with bt_device_create_bond(). + * @post bt_device_authorization_changed_cb() will be invoked. + * + * @see bt_device_create_bond() + * @see bt_device_authorization_changed_cb() + * @see bt_device_set_authorization_changed_cb() + * @see bt_device_unset_authorization_changed_cb() + */ +int bt_device_set_authorization(const char *remote_address, bt_device_authorization_e authorization_state); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Starts the search for services supported by the specified device, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @remarks If creating a bond succeeds, which means bt_device_bond_created_cb() is called with result #BT_ERROR_NONE, + * then you don't need to run this function.\n + * The service search takes a couple of seconds to complete normally. \n + * The service search can be canceled by bt_device_cancel_service_search(). + * + * @param[in] remote_address The address of the remote Bluetooth device whose services need to be checked + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_SERVICE_SEARCH_FAILED Service search failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The remote device must be discoverable with bt_adapter_start_device_discovery(). + * @pre The bond with the remote device must be created with bt_device_create_bond(). + * @post This function invokes bt_device_service_searched_cb(). + * + * @see bt_adapter_start_device_discovery() + * @see bt_device_create_bond() + * @see bt_device_bond_created_cb() + * @see bt_device_service_searched_cb() + * @see bt_device_cancel_service_search() + * @see bt_device_set_service_searched_cb() + * @see bt_device_unset_service_searched_cb() + */ +int bt_device_start_service_search(const char *remote_address); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Cancels service search process. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_NOT_IN_PROGRESS Operation not in progress + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The service search must be in progress by bt_device_start_service_search(). + * + * @see bt_device_start_service_search() + * @see bt_device_service_searched_cb() + * @see bt_device_set_service_searched_cb() + * @see bt_device_unset_service_searched_cb() + */ +int bt_device_cancel_service_search(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Gets the connected profiles. + * @since_tizen 2.3 + * @param[in] remote_address The address of the remote device + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post bt_device_connected_profile() will be invoked. + * @see bt_device_connected_profile() + */ +int bt_device_foreach_connected_profiles(const char *remote_address, bt_device_connected_profile callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Gets the profile connected status. + * @since_tizen 2.3 + * @param[in] remote_address The address of the remote device + * @param[in] bt_profile wish to know bt_profile + * @param[out] connected_status the connected status + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + */ +int bt_device_is_profile_connected(const char *remote_address, bt_profile_e bt_profile, + bool *connected_status); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Registers a callback function to be invoked when the bond creates. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_device_bond_created_cb() will be invoked. + * @see bt_initialize() + * @see bt_device_bond_created_cb() + * @see bt_device_unset_bond_created_cb() + */ +int bt_device_set_bond_created_cb(bt_device_bond_created_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_device_set_bond_created_cb() + */ +int bt_device_unset_bond_created_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Registers a callback function to be invoked when the bond destroys. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_device_bond_destroyed_cb() will be invoked. + * @see bt_initialize() + * @see bt_device_bond_destroyed_cb() + * @see bt_device_unset_bond_destroyed_cb() + */ +int bt_device_set_bond_destroyed_cb(bt_device_bond_destroyed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_device_set_bond_destroyed_cb() + */ +int bt_device_unset_bond_destroyed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Registers a callback function to be invoked when the authorization of device changes. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_device_authorization_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_device_authorization_changed_cb() + * @see bt_device_set_authorization_changed_cb() + * @see bt_device_unset_authorization_changed_cb() + */ +int bt_device_set_authorization_changed_cb(bt_device_authorization_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_device_set_authorization_changed_cb() + */ +int bt_device_unset_authorization_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Registers a callback function to be invoked when the process of service search finishes. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_device_service_searched_cb() will be invoked. + * @see bt_initialize() + * @see bt_device_service_searched_cb() + * @see bt_device_unset_service_searched_cb() + */ +int bt_device_set_service_searched_cb(bt_device_service_searched_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_device_set_service_searched_cb() + */ +int bt_device_unset_service_searched_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Registers a callback function to be invoked when the connection state is changed. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_device_connection_state_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_device_connection_state_changed_cb() + * @see bt_device_unset_connection_state_changed_cb() + */ +int bt_device_set_connection_state_changed_cb(bt_device_connection_state_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Unregisters the callback function to be invoked when the connection state is changed. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_device_set_connection_state_changed_cb() + */ +int bt_device_unset_connection_state_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Registers a rfcomm server socket with a specific UUID. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @remarks A socket can be destroyed by bt_socket_destroy_rfcomm(). + * + * @param[in] service_uuid The UUID of service to provide + * @param[out] socket_fd The file descriptor of socket to listen + * @return 0 on success, otherwise a negative error value. + * + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * + * @see bt_socket_listen_and_accept_rfcomm() + * @see bt_socket_destroy_rfcomm() + */ +int bt_socket_create_rfcomm(const char *service_uuid, int *socket_fd); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Removes the rfcomm server socket which was created using bt_socket_create_rfcomm(). + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @remarks If callback function bt_socket_connection_state_changed_cb() is set and the remote Bluetooth device is connected, + * then bt_socket_connection_state_changed_cb() will be called when this function is finished successfully. + * + * @param[in] socket_fd The file descriptor of socket (which was created using bt_socket_create_rfcomm()) to destroy + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The socket must be created with bt_socket_create_rfcomm(). + * @post If callback function bt_socket_connection_state_changed_cb() is set and the remote Bluetooth device is connected, + * then bt_socket_connection_state_changed_cb() will be called. + * @see bt_socket_create_rfcomm() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +int bt_socket_destroy_rfcomm(int socket_fd); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Starts listening on passed rfcomm socket and accepts connection requests. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @details Pop-up is shown automatically when a RFCOMM connection is requested. + * bt_socket_connection_state_changed_cb() will be called with + * #BT_SOCKET_CONNECTED if you click "yes" and connection is finished successfully. + * @param[in] socket_fd The file descriptor of socket on which start to listen + * @param[in] max_pending_connections The maximum number of pending connections + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The socket must be created with bt_socket_create_rfcomm(). + * @post If callback function bt_socket_connection_state_changed_cb() is set, + * then bt_socket_connection_state_changed_cb() will be called when the remote Bluetooth device is connected. + * @see bt_socket_create_rfcomm() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +int bt_socket_listen_and_accept_rfcomm(int socket_fd, int max_pending_connections); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Starts listening on passed rfcomm socket. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @details bt_socket_connection_requested_cb() will be called when a RFCOMM connection is requested. + * + * @param[in] socket_fd The file descriptor socket on which start to listen + * @param[in] max_pending_connections The number of pending connections + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The socket must be created with bt_socket_create_rfcomm(). + * @post This function invokes bt_socket_connection_state_changed_cb(). + * + * @see bt_socket_create_rfcomm() + * @see bt_socket_set_connection_requested_cb() + * @see bt_socket_unset_connection_requested_cb() + * @see bt_socket_connection_requested_cb() + */ +int bt_socket_listen(int socket_fd, int max_pending_connections); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Accepts a connection request. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] requested_socket_fd The file descriptor of socket on which a connection is requested + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The connection is requested by bt_socket_connection_requested_cb(). + * @see bt_socket_create_rfcomm() + * @see bt_socket_connection_requested_cb() + * @see bt_socket_listen() + * @see bt_socket_reject() +*/ +int bt_socket_accept(int requested_socket_fd); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Rejects a connection request. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] socket_fd The file descriptor of socket on which a connection is requested + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The connection is requested by bt_socket_connection_requested_cb(). + * @see bt_socket_create_rfcomm() + * @see bt_socket_connection_requested_cb() + * @see bt_socket_listen() + * @see bt_socket_accept() + */ +int bt_socket_reject(int socket_fd); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Connects to a specific RFCOMM based service on a remote Bluetooth device UUID, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @remarks A connection can be disconnected by bt_socket_disconnect_rfcomm(). + * + * @param[in] remote_address The address of the remote Bluetooth device + * @param[in] service_uuid The UUID of service provided by the remote Bluetooth device + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device not bonded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The remote device must be discoverable with bt_adapter_start_device_discovery(). + * @pre The bond with the remote device must be created with bt_device_create_bond(). + * @post This function invokes bt_socket_connection_state_changed_cb(). + * + * @see bt_device_create_bond() + * @see bt_adapter_start_device_discovery() + * @see bt_device_start_service_search() + * @see bt_socket_disconnect_rfcomm() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +int bt_socket_connect_rfcomm(const char *remote_address, const char *service_uuid); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Disconnects the RFCOMM connection with the given file descriptor of conneted socket. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] socket_fd The file descriptor of socket to close which was received using bt_socket_connection_state_changed_cb(). + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The connection must be established. + * + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +int bt_socket_disconnect_rfcomm(int socket_fd); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Sends data to the connected device. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @remark The specific error code can be obtained using the get_last_result() method. Error codes are described in Exception section. + * + * @param[in] socket_fd The file descriptor of connected socket which was received using bt_socket_connection_state_changed_cb() + * @param[in] data The data to be sent + * @param[in] length The length of data to be sent + * + * @return the number of bytes written (zero indicates nothing was written). + * @retval On error, -1 is returned, and errno is set appropriately. See write 2 man page. + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @exception BT_ERROR_NOT_INITIALIZED Not initialized + * @exception BT_ERROR_PERMISSION_DENIED Permission denied + * @exception BT_ERROR_AGAIN Resource temporarily unavailable + * + * @pre The connection must be established. + * + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +int bt_socket_send_data(int socket_fd, const char *data, int length); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Register a callback function that will be invoked when you receive data. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_socket_data_received_cb() will be invoked. + * @see bt_initialize() + * @see bt_socket_data_received_cb() + * @see bt_socket_set_data_received_cb() + * @see bt_socket_unset_data_received_cb() + */ +int bt_socket_set_data_received_cb(bt_socket_data_received_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_socket_data_received_cb() + * @see bt_socket_set_data_received_cb() + */ +int bt_socket_unset_data_received_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Register a callback function that will be invoked when a RFCOMM connection is requested. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post If you listen a socket by bt_socket_listen(), bt_socket_connection_requested_cb() will be invoked. + * @see bt_initialize() + * @see bt_socket_unset_connection_requested_cb() + */ +int bt_socket_set_connection_requested_cb(bt_socket_connection_requested_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_socket_set_connection_requested_cb() + * @see bt_socket_connection_requested_cb() + */ +int bt_socket_unset_connection_requested_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Register a callback function that will be invoked when the connection state changes. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_socket_connection_state_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +int bt_socket_set_connection_state_changed_cb(bt_socket_connection_state_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_socket_connection_state_changed_cb() + * @see bt_socket_set_connection_state_changed_cb() + */ +int bt_socket_unset_connection_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Initializes the Bluetooth OPP server requested by bt_opp_server_push_requested_cb(). + * @since_tizen 2.3 + * @details The popup appears when an OPP connection is requested from a remote device. + * If you accept the request, then connection will be established and bt_opp_server_push_requested_cb() will be called. + * At that time, you can call either bt_opp_server_accept() or bt_opp_server_reject(). + * @remarks This function must be called to start Bluetooth OPP server. You must free all resources of the Bluetooth service + * by calling bt_opp_server_deinitialize() if Bluetooth OPP service is no longer needed. + * @param[in] destination The destination path + * @param[in] push_requested_cb The callback called when a push is requested + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @see bt_opp_server_push_requested_cb() + * @see bt_opp_server_deinitialize() + * @see bt_opp_server_accept() + * @see bt_opp_server_reject() + */ +int bt_opp_server_initialize(const char *destination, bt_opp_server_push_requested_cb push_requested_cb, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Initializes the Bluetooth OPP server requested by bt_opp_server_connection_requested_cb(). + * @since_tizen 2.3 + * @details No popup appears when an OPP connection is requested from a remote device. + * Instead, @a connection_requested_cb() will be called. + * At that time, you can call either bt_opp_server_accept() or bt_opp_server_reject(). + * @remarks This function must be called to start Bluetooth OPP server. \n + * You must free all resources of the Bluetooth service by calling bt_opp_server_deinitialize() if Bluetooth OPP service is no longer needed. + * @param[in] destination The destination path + * @param[in] connection_requested_cb The callback called when an OPP connection is requested + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @see bt_opp_server_connection_requested_cb() + * @see bt_opp_server_deinitialize() + * @see bt_opp_server_accept_connection() + * @see bt_opp_server_reject_connection() + */ +int bt_opp_server_initialize_by_connection_request(const char *destination, bt_opp_server_connection_requested_cb connection_requested_cb, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Denitializes the Bluetooth OPP server. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @see bt_opp_server_initialize() + * @see bt_opp_server_deinitialize() + */ +int bt_opp_server_deinitialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Accepts the push request from the remote device. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @remarks If you initialize OPP server by bt_opp_server_initialize_by_connection_request(), then name is ignored. + * You can cancel the pushes by bt_opp_server_cancel_transfer() with transfer_id. + * @param[in] progress_cb The callback called when a file is being transfered + * @param[in] finished_cb The callback called when a transfer is finished + * @param[in] name The name to store. This can be NULL if you initialize OPP server by bt_opp_server_initialize_by_connection_request(). + * @param[in] user_data The user data to be passed to the callback function + * @param[out] transfer_id The ID of transfer + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @see bt_opp_server_reject() + */ +int bt_opp_server_accept(bt_opp_server_transfer_progress_cb progress_cb, bt_opp_server_transfer_finished_cb finished_cb, const char *name, + void *user_data, int *transfer_id); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Rejects the push request from the remote device. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @see bt_opp_server_accept() + */ +int bt_opp_server_reject(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Cancels the transfer. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] transfer_id The ID of transfer + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @see bt_opp_server_accept_connection() + * @see bt_opp_server_accept() + */ +int bt_opp_server_cancel_transfer(int transfer_id); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Sets the destination path of file to be pushed. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] destination The destination path of file to be pushed + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @see bt_opp_server_initialize() + */ +int bt_opp_server_set_destination(const char *destination); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Initializes the Bluetooth OPP client. + * @since_tizen 2.3 + * @remarks This function must be called before Bluetooth OPP client starts. \n + * You must free all resources of the Bluetooth service by calling bt_opp_client_deinitialize() + * if Bluetooth OPP service is no longer needed. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @see bt_opp_client_deinitialize() + */ +int bt_opp_client_initialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Denitializes the Bluetooth OPP client. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @see bt_opp_client_initialize() + */ +int bt_opp_client_deinitialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Adds file to be pushed. + * @since_tizen 2.3 + * @param[in] file The path of file to be pushed + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @see bt_opp_client_clear_files() + * @see bt_opp_client_push_files() + */ +int bt_opp_client_add_file(const char *file); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Adds file to be pushed. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @see bt_opp_client_add_file() + * @see bt_opp_client_push_files() + */ +int bt_opp_client_clear_files(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Pushes the file to the remote device, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @details At first, bt_opp_client_push_responded_cb() will be called when OPP server responds to the push request. + * After connection is established, bt_opp_client_push_progress_cb() will be called repeatedly until a file is tranfered completely. + * If you send several files, then bt_opp_client_push_progress_cb() with another file will be called repeatedly until the file is tranfered completely. + * bt_opp_client_push_finished_cb() will be called when the push request is finished. + * @param[in] remote_address The remote address + * @param[in] responded_cb The callback called when OPP server responds to the push request + * @param[in] progress_cb The callback called when each file is being transfered + * @param[in] finished_cb The callback called when the push request is finished + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOW_IN_PROGRESS Operation now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @see bt_opp_client_initialize() + * @see bt_opp_client_cancel_push + */ +int bt_opp_client_push_files(const char *remote_address, bt_opp_client_push_responded_cb responded_cb, + bt_opp_client_push_progress_cb progress_cb, bt_opp_client_push_finished_cb finished_cb, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Cancels the push request in progress, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre bt_opp_client_push_files() must be called. + * @post bt_opp_client_push_finished_cb() will be invoked with result #BT_ERROR_CANCELLED, + * which is a parameter of bt_opp_client_push_files(). + * @see bt_opp_client_initialize() + * @see bt_opp_client_push_files() + */ +int bt_opp_client_cancel_push(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Initializes the Bluetooth HID(Human Interface Device) Host. + * @since_tizen 2.3 + * @remarks This function must be called before Bluetooth HID Host starts. \n + * You must free all resources of the Bluetooth service by calling bt_hid_host_deinitialize() + * if Bluetooth HID Host service is no longer needed. + * @param[in] connection_cb The callback called when the connection state is changed + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_hid_host_deinitialize() + */ +int bt_hid_host_initialize(bt_hid_host_connection_state_changed_cb connection_cb, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Deinitializes the Bluetooth HID(Human Interface Device) Host. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @pre The Bluetooth HID service must be initialized with bt_hid_host_initialize(). + * @see bt_hid_host_initialize() + */ +int bt_hid_host_deinitialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Connects the remote device with the HID(Human Interface Device) service, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] remote_address The remote address + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device is not bonded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The local device must be bonded with the remote device by bt_device_create_bond(). + * @pre The Bluetooth HID service must be initialized with bt_hid_host_initialize(). + * @post bt_hid_host_connection_state_changed_cb() will be invoked. + * @see bt_hid_host_disconnect() + * @see bt_hid_host_connection_state_changed_cb() + */ +int bt_hid_host_connect(const char *remote_address); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Disconnects the remote device with the HID(Human Interface Device) service, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] remote_address The remote address + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The remote device must be connected by bt_hid_host_connect(). + * @post bt_hid_host_connection_state_changed_cb() will be invoked. + * @see bt_hid_host_connect() + * @see bt_hid_host_connection_state_changed_cb() + */ +int bt_hid_host_disconnect(const char *remote_address); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Initializes the Bluetooth profiles related with audio. + * @since_tizen 2.3 + * @remarks This function must be called before Bluetooth profiles related with audio starts. \n + * You must free all resources of the this service by calling bt_audio_deinitialize() + * if Bluetooth profiles related with audio service is no longer needed. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_audio_deinitialize() + */ +int bt_audio_initialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Deinitializes the Bluetooth profiles related with audio. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + */ +int bt_audio_deinitialize(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Connects the remote device with the given audio profile, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @details If you input type as #BT_AUDIO_PROFILE_TYPE_ALL and connection request succeeds, then bt_audio_connection_state_changed_cb() will be called twice + * when #BT_AUDIO_PROFILE_TYPE_HSP_HFP is connected and #BT_AUDIO_PROFILE_TYPE_A2DP is connected. + * @param[in] remote_address The remote address + * @param[in] type The type of audio profile + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device is not bonded + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @pre The local device must be bonded with the remote device by bt_device_create_bond(). + * @post bt_audio_connection_state_changed_cb() will be invoked. + * @see bt_audio_disconnect() + * @see bt_audio_connection_state_changed_cb() + */ +int bt_audio_connect(const char *remote_address, bt_audio_profile_type_e type); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Disconnects the remote device with the given audio profile, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @details If you input type as #BT_AUDIO_PROFILE_TYPE_ALL and disconnection request succeeds, then bt_audio_connection_state_changed_cb() will be called twice + * when #BT_AUDIO_PROFILE_TYPE_HSP_HFP is disconnected and #BT_AUDIO_PROFILE_TYPE_A2DP is disconnected. + * @param[in] remote_address The remote address + * @param[in] type The type of audio profile + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The remote device must be connected by bt_audio_connect(). + * @post bt_audio_connection_state_changed_cb() will be invoked. + * @see bt_audio_connect() + * @see bt_audio_connection_state_changed_cb() + */ +int bt_audio_disconnect(const char *remote_address, bt_audio_profile_type_e type); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Registers a callback function that will be invoked when the connection state is changed. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_audio_connection_state_changed_cb() + * @see bt_panu_unset_connection_state_changed_cb() + */ +int bt_audio_set_connection_state_changed_cb(bt_audio_connection_state_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Unregisters a callback function that will be invoked when the connection state is changed. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_audio_connection_state_changed_cb() + * @see bt_audio_set_connection_state_changed_cb() + */ +int bt_audio_unset_connection_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Opens a SCO(Synchronous Connection Oriented link) to connected remote device, asynchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device is not bonded + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_ALREADY_DONE Operation is already done + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio device must be connected with bt_audio_connect(). + * @post bt_ag_sco_state_changed_cb() will be invoked. + * @see bt_ag_close_sco() + * @see bt_ag_sco_state_changed_cb() + * @see bt_audio_connect() + */ +int bt_ag_open_sco(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Closes an opened SCO(Synchronous Connection Oriented link), asynchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device is not bonded + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The SCO must be opened with bt_ag_open_sco(). + * @post bt_ag_sco_state_changed_cb() will be invoked. + * @see bt_ag_open_sco() + * @see bt_ag_sco_state_changed_cb() + */ +int bt_ag_close_sco(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Checks whether an opened SCO(Synchronous Connection Oriented link) exists or not. + * @since_tizen 2.3 + * @param[out] opened The SCO status: (@c true = opened, @c false = not opened) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_ag_open_sco() + * @see bt_ag_close_sco() + */ +int bt_ag_is_sco_opened(bool *opened); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Registers a callback function that will be invoked when the SCO(Synchronous Connection Oriented link) state is changed. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_sco_state_changed_cb() + * @see bt_ag_unset_sco_state_changed_cb() + */ +int bt_ag_set_sco_state_changed_cb(bt_ag_sco_state_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Unregisters a callback function that will be invoked when the SCO(Synchronous Connection Oriented link) state is changed. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_sco_state_changed_cb() + * @see bt_ag_set_sco_state_changed_cb() + */ +int bt_ag_unset_sco_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Notifies the call event to the remote bluetooth device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @remarks Before notifying #BT_AG_CALL_EVENT_ANSWERED or #BT_AG_CALL_EVENT_DIALING, you should open SCO(Synchronous Connection Oriented link) + * if Bluetooth Hands-Free need SCO connection. + * @param[in] event The call event + * @param[in] call_id The call ID + * @param[in] phone_number The phone number. You must set this value in case of #BT_AG_CALL_EVENT_DIALING and #BT_AG_CALL_EVENT_INCOMING. + * In other cases, this value can be NULL. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device is not bonded + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio device must be connected with bt_audio_connect(). + * @see bt_audio_connect() + */ +int bt_ag_notify_call_event(bt_ag_call_event_e event, unsigned int call_id, const char *phone_number); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Notifies the call list to the remote bluetooth device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] list The call list + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device is not bonded + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio device must be connected with bt_audio_connect(). + * @see bt_audio_connect() + */ +int bt_ag_notify_call_list(bt_call_list_h list); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Notifies the state of voice recognition. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] state The state of voice recognition: (@c true = enabled, @c false = disabled) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device is not bonded + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio device must be connected with bt_audio_connect(). + * @see bt_audio_connect() + */ +int bt_ag_notify_voice_recognition_state(bool state); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Registers a callback function that will be invoked when a call handling event happened from Hands-Free. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_call_handling_event_cb() + * @see bt_ag_unset_call_handling_event_cb() + */ +int bt_ag_set_call_handling_event_cb(bt_ag_call_handling_event_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Unregisters a callback function that will be invoked when a call handling event happened from Hands-Free. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_call_handling_event_cb() + * @see bt_ag_set_call_handling_event_cb() + */ +int bt_ag_unset_call_handling_event_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Registers a callback function that will be invoked when a multi call handling event happened from Hands-Free. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_multi_call_handling_event_cb() + * @see bt_ag_unset_multi_call_handling_event_cb() + */ +int bt_ag_set_multi_call_handling_event_cb(bt_ag_multi_call_handling_event_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Unregisters a callback function that will be invoked when a multi call handling event happened from Hands-Free. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_multi_call_handling_event_cb() + * @see bt_ag_set_multi_call_handling_event_cb() + */ +int bt_ag_unset_multi_call_handling_event_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Registers a callback function that will be invoked when a DTMF(Dual Tone Multi Frequency) is transmitted from Hands-Free. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_dtmf_transmitted_cb() + * @see bt_ag_unset_dtmf_transmitted_cb() + */ +int bt_ag_set_dtmf_transmitted_cb(bt_ag_dtmf_transmitted_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Unregisters a callback function that will be invoked when a DTMF(Dual Tone Multi Frequency) is transmitted from Hands-Free. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_dtmf_transmitted_cb() + * @see bt_ag_set_dtmf_transmitted_cb() + */ +int bt_ag_unset_dtmf_transmitted_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Notifies the speaker gain to the remote device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @details This function sends a signal to the remote device. This signal has the gain value. + * @a gain is represented on a scale from 0 to 15. This value is absolute value relating to a particular volume level. + * When the speaker gain of remote device is changed to the requested gain, bt_audio_speaker_gain_changed_cb() will be called. + * @param[in] gain The gain of speaker (0 ~ 15) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The remote device is connected by bt_audio_connect() with #BT_AUDIO_PROFILE_TYPE_HSP_HFP service. + * @see bt_ag_get_speaker_gain() + * @see bt_ag_set_speaker_gain_changed_cb() + * @see bt_ag_unset_speaker_gain_changed_cb() + */ +int bt_ag_notify_speaker_gain(int gain); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Gets the current speaker gain of the remote device. + * @since_tizen 2.3 + * @details This function gets the value of speaker gain of the remote device. + * @a gain is represented on a scale from 0 to 15. This value is absolute value relating to a particular volume level. + * @param[out] gain The gain of speaker (0 ~ 15) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The remote device is connected by bt_audio_connect() with #BT_AUDIO_PROFILE_TYPE_HSP_HFP service. + * @see bt_ag_notify_speaker_gain() + * @see bt_ag_set_speaker_gain_changed_cb() + * @see bt_ag_unset_speaker_gain_changed_cb() + */ +int bt_ag_get_speaker_gain(int *gain); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Checks whether the remoted device enables NREC(Noise Reduction and Echo Canceling) or not. + * @since_tizen 2.3 + * @param[out] enabled The NREC status: (@c true = enabled, @c false = not enabled) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The remote device is connected by bt_audio_connect() with #BT_AUDIO_PROFILE_TYPE_HSP_HFP service. + * @see bt_audio_connect() + */ +int bt_ag_is_nrec_enabled(bool *enabled); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Registers a callback function that will be invoked when the speaker gain of the remote device is changed. + * @since_tizen 2.3 + * @details This function let you know the change of the speaker gain of the remote device. + * @a gain is represented on a scale from 0 to 15. This value is absolute value relating to a particular volume level. + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_unset_speaker_gain_changed_cb() + */ +int bt_ag_set_speaker_gain_changed_cb(bt_ag_speaker_gain_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Unregisters a callback function that will be invoked when the speaker gain of the remote device is changed. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_set_speaker_gain_changed_cb() + */ +int bt_ag_unset_speaker_gain_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Registers a callback function that will be invoked when the microphone gain of the remote device is changed. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_unset_microphone_gain_changed_cb() + */ +int bt_ag_set_microphone_gain_changed_cb(bt_ag_microphone_gain_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Unregisters a callback function that will be invoked when the microphone gain of the remote device is changed. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_set_microphone_gain_changed_cb() + */ +int bt_ag_unset_microphone_gain_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_CALL_MODULE + * @brief Creates a handle of call list. + * @since_tizen 2.3 + * @param[out] list The handle of call list + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @see bt_call_list_destroy() + */ +int bt_call_list_create(bt_call_list_h *list); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_CALL_MODULE + * @brief Destroys the handle of call list. + * @since_tizen 2.3 + * @param[in] list The handle of call list + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @see bt_call_list_create() + */ +int bt_call_list_destroy(bt_call_list_h list); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_CALL_MODULE + * @brief Resets the handle of call list. + * @since_tizen 2.3 + * @param[in] list The handle of call list + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @see bt_call_list_create() + */ +int bt_call_list_reset(bt_call_list_h list); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_CALL_MODULE + * @brief Adds a call to the handle of call list. + * @since_tizen 2.3 + * @param[in] list The handle of call list + * @param[in] call_id The call ID + * @param[in] state The state of audio gate call + * @param[in] phone_number The phone number. You must set this value in case of #BT_AG_CALL_EVENT_DIALING and #BT_AG_CALL_EVENT_INCOMING. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @see bt_call_list_create() + */ +int bt_call_list_add(bt_call_list_h list, unsigned int call_id, bt_ag_call_state_e state, const char *phone_number); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Initializes the Bluetooth AVRCP(Audio/Video Remote Control Profile) service. + * @since_tizen 2.3 + * @remarks This function must be called before Bluetooth AVRCP service. \n + * You must free all resources of the this service by calling bt_avrcp_target_deinitialize() + * if Bluetooth AVRCP service is no longer needed. + * @param[in] callback The callback function called when the connection state is changed + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_target_deinitialize() + */ +int bt_avrcp_target_initialize(bt_avrcp_target_connection_state_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Deinitializes the Bluetooth AVRCP(Audio/Video Remote Control Profile) service. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @pre The Bluetooth audio service must be initialized with bt_avrcp_target_initialize(). + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_target_deinitialize(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Notifies the equalize state to the remote device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] state The state of equalizer + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_target_notify_equalizer_state(bt_avrcp_equalizer_state_e state); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Notifies the repeat mode to the remote device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] mode The repeat mode + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_target_notify_repeat_mode(bt_avrcp_repeat_mode_e mode); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Notifies the shuffle mode to the remote device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] mode The repeat mode + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_target_notify_shuffle_mode(bt_avrcp_shuffle_mode_e mode); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Notifies the scan mode to the remote device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] mode The scan mode + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_target_notify_scan_mode(bt_avrcp_scan_mode_e mode); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Notifies the player state to the remote device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] state The player state + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_target_notify_player_state(bt_avrcp_player_state_e state); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Notifies the current position of song to the remote device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] position The current position in milliseconds + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_target_notify_position(unsigned int position); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Notifies the track to the remote device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] title The title of track + * @param[in] artist The artist of track + * @param[in] album The album of track + * @param[in] genre The genre of track + * @param[in] track_num The track number + * @param[in] total_tracks The number of all tracks + * @param[in] duration The duration of track in milliseconds + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The remote device must be connected. + * @see bt_avrcp_target_connection_state_changed_cb() + * @see bt_avrcp_target_initialize() + */ +int bt_avrcp_target_notify_track(const char *title, const char *artist, const char *album, const char *genre, unsigned int track_num, unsigned int total_tracks, unsigned int duration); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Registers a callback function that will be invoked when the equalizer state is changed by the remote control device. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_unset_equalizer_state_changed_cb() + */ +int bt_avrcp_set_equalizer_state_changed_cb(bt_avrcp_equalizer_state_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Unregisters a callback function that will be invoked when the equalizer state is changed by the remote control device. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_set_equalizer_state_changed_cb() + */ +int bt_avrcp_unset_equalizer_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Registers a callback function that will be invoked when the repeat mode is changed by the remote control device. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_unset_repeat_mode_changed_cb() + */ +int bt_avrcp_set_repeat_mode_changed_cb(bt_avrcp_repeat_mode_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Unregisters a callback function that will be invoked when the repeat mode is changed by the remote control device. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_set_repeat_mode_changed_cb() + */ +int bt_avrcp_unset_repeat_mode_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Registers a callback function that will be invoked when the shuffle mode is changed by the remote control device. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_unset_shuffle_mode_changed_cb() + */ +int bt_avrcp_set_shuffle_mode_changed_cb(bt_avrcp_shuffle_mode_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Unregisters a callback function that will be invoked when the shuffle mode is changed by the remote control device. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_set_shuffle_mode_changed_cb() + */ +int bt_avrcp_unset_shuffle_mode_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Registers a callback function that will be invoked when the scan mode is changed by the remote control device. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_unset_scan_mode_changed_cb() + */ +int bt_avrcp_set_scan_mode_changed_cb(bt_avrcp_scan_mode_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Unregisters a callback function that will be invoked when the scan mode is changed by the remote control device. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @see bt_initialize() + * @see bt_avrcp_set_scan_mode_changed_cb() + */ +int bt_avrcp_unset_scan_mode_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Registers an application that acts as the @a Sink role of HDP(Health Device Profile). + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @remarks The @a app_id must be released with free() by you. + * @param[in] data_type The data type of MDEP. This value is defined in ISO/IEEE 11073-20601 spec. + * For example, pulse oximeter is 0x1004 and blood pressure monitor is 0x1007. + * @param[out] app_id The ID of application + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_hdp_deactivate_sink() + */ +int bt_hdp_register_sink_app(unsigned short data_type, char **app_id); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Unregisters the given application that acts as the @a Sink role of HDP(Health Device Profile). + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] app_id The ID of application + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @see bt_hdp_register_sink_app() + */ +int bt_hdp_unregister_sink_app(const char *app_id); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Connects the remote device which acts as @a Source role, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] remote_address The remote address + * @param[in] app_id The ID of application + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device is not bonded + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The Sink role of HDP must be registered with bt_hdp_register_sink_app(). + * @pre The local device must be bonded with the remote device by bt_device_create_bond(). + * @post bt_hdp_connected_cb() will be invoked. + * @see bt_hdp_disconnect() + * @see bt_hdp_set_connection_state_changed_cb() + * @see bt_hdp_unset_connection_state_changed_cb() + */ +int bt_hdp_connect_to_source(const char *remote_address, const char *app_id); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Disconnects the remote device, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] remote_address The remote address + * @param[in] channel The connected data channel + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The remote device must be connected. + * @post bt_hdp_disconnected_cb() will be invoked. + * @see bt_hdp_set_connection_state_changed_cb() + * @see bt_hdp_unset_connection_state_changed_cb() + */ +int bt_hdp_disconnect(const char *remote_address, unsigned int channel); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Sends the data to the remote device. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] channel The connected data channel + * @param[in] data The data to send + * @param[in] size The size of data to send (byte) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The remote device must be connected. + * @see bt_hdp_data_received_cb() + * @see bt_hdp_set_data_received_cb() + * @see bt_hdp_unset_data_received_cb() + */ +int bt_hdp_send_data(unsigned int channel, const char *data, unsigned int size); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Registers a callback function that will be invoked when the connection state is changed. + * @since_tizen 2.3 + * @param[in] connected_cb The callback function called when a connection is established + * @param[in] disconnected_cb The callback function called when a connection is disconnected + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_hdp_unset_connection_state_changed_cb() + */ +int bt_hdp_set_connection_state_changed_cb(bt_hdp_connected_cb connected_cb, bt_hdp_disconnected_cb disconnected_cb, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Unregisters a callback function that will be invoked when the connection state is changed. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_hdp_set_connection_state_changed_cb() + */ +int bt_hdp_unset_connection_state_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Registers a callback function that will be invoked when you receive the data. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_hdp_unset_data_received_cb() + */ +int bt_hdp_set_data_received_cb(bt_hdp_data_received_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Unregisters a callback function that will be invoked when you receive the data. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_hdp_set_data_received_cb() + */ +int bt_hdp_unset_data_received_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the primary services of GATT(Generic Attribute Profile). + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] remote_address The address of the remote device + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post @a callback will be called if there are primary services. + * @see bt_gatt_primary_service_cb() + */ +int bt_gatt_foreach_primary_services(const char *remote_address, bt_gatt_primary_service_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Discovers the characteristics in service, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] service The attribute handle of service + * @param[in] callback The result callback + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post @a callback will be called. + * @see bt_gatt_characteristics_discovered_cb() + */ +int bt_gatt_discover_characteristics(bt_gatt_attribute_h service, bt_gatt_characteristics_discovered_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the UUID of service. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @remarks @a uuid must be released with free() by you. + * @param[in] service The attribute handle of service + * @param[out] uuid The UUID of service + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + */ +int bt_gatt_get_service_uuid(bt_gatt_attribute_h service, char **uuid); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the included services in service. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] service The attribute handle of service + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post @a callback will be called if there are included services. + * @see bt_gatt_included_service_cb() + */ +int bt_gatt_foreach_included_services(bt_gatt_attribute_h service, bt_gatt_included_service_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Registers a callback function that will be invoked when a characteristic value is changed. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_gatt_unset_characteristic_changed_cb() + */ +int bt_gatt_set_characteristic_changed_cb(bt_gatt_characteristic_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Unregisters a callback function that will be invoked when a characteristic is changed. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_gatt_set_characteristic_changed_cb() + */ +int bt_gatt_unset_characteristic_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Watches all the characteristic value changes of the service + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] service The attribute handle of service + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_gatt_unset_characteristic_changed_cb() + */ +int bt_gatt_watch_characteristic_changes(bt_gatt_attribute_h service); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Remove watching of all the characteristic value changes of the service + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] service The attribute handle of service + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_gatt_set_characteristic_changed_cb() + */ +int bt_gatt_unwatch_characteristic_changes(bt_gatt_attribute_h service); + + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets the characteristic declaration. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @remarks @a uuid and @a value must be released with free() by you. + * @param[in] characteristic The attribute handle of characteristic + * @param[out] uuid The UUID of service + * @param[out] value The value of characteristic (byte array) + * @param[out] value_length The length of value + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_gatt_set_characteristic_value() + */ +int bt_gatt_get_characteristic_declaration(bt_gatt_attribute_h characteristic, char **uuid, unsigned char **value, int *value_length); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Sets the value of characteristic. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] characteristic The attribute handle of characteristic + * @param[in] value The value of characteristic (byte array) + * @param[in] value_length The length of value + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_gatt_get_characteristic_declaration() + */ +int bt_gatt_set_characteristic_value(bt_gatt_attribute_h characteristic, const unsigned char *value, int value_length); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Sets the value of characteristic request. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] characteristic The attribute handle of characteristic + * @param[in] value The value of characteristic (byte array) + * @param[in] value_length The length of value + * @param[in] callback The result callback + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_gatt_get_characteristic_declaration() + */ +int bt_gatt_set_characteristic_value_request(bt_gatt_attribute_h characteristic, const unsigned char *value, + int value_length, bt_gatt_characteristic_write_cb callback); + +/** +* @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE +* @brief Clones the attribute handle. +* @since_tizen 2.3 +* @remarks @a clone must be released with bt_gatt_destroy_attribute_handle(). +* @param[out] clone The cloned attribute handle +* @param[in] origin The origin attribute handle +* @return 0 on success, otherwise negative error value. +* @retval #BT_ERROR_NONE Successful +* @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #BT_ERROR_OUT_OF_MEMORY Out of memory +* @see bt_gatt_destroy_attribute_handle() +*/ +int bt_gatt_clone_attribute_handle(bt_gatt_attribute_h* clone, bt_gatt_attribute_h origin); + +/** +* @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE +* @brief Destroys the attribute handle. +* @since_tizen 2.3 +* @param[in] handle The attribute handle +* @return 0 on success, otherwise negative error value. +* @retval #BT_ERROR_NONE Successful +* @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter +* @see bt_gatt_clone_attribute_handle() +*/ +int bt_gatt_destroy_attribute_handle(bt_gatt_attribute_h handle); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Reads the value of characteristic from remote device + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] char_handle The attribute handle of characteristic + * @param[in] callback The result callback + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_gatt_get_characteristic_declaration() + */ +int bt_gatt_read_characteristic_value(bt_gatt_attribute_h char_handle, + bt_gatt_characteristic_read_cb callback); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Discovers the characteristic descriptors of a characteristic within its definition, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] characteristic_handle The attribute handle of characteristic + * @param[in] callback The result callback + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post @a callback will be called. + * @see bt_gatt_characteristic_descriptor_discovered_cb() + */ +int bt_gatt_discover_characteristic_descriptor(bt_gatt_attribute_h characteristic_handle, + bt_gatt_characteristic_descriptor_discovered_cb callback, + void *user_data); +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Sets the value of characteristic descriptor request. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * @param[in] characteristic The attribute handle of characteristic + * @param[in] value The value of characteristic (byte array), desc handle, desc value + * @param[in] value_length The length of value + * @param[in] callback The result callback + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_gatt_get_characteristic_declaration() + */ +int bt_gatt_set_characteristic_desc_value_request(bt_gatt_attribute_h characteristic, + const unsigned char *value, int value_length, + bt_gatt_characteristic_write_cb callback); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Connect to a specific LE based service on a remote bluetooth dievice address, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @remarks A connection can be disconnected by bt_gatt_disconnect(). + * + * @param[in] address The address of the remote Bluetooth device. + * @param[in] auto_connect The flag of the auto connection. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid paramater + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @pre The remote device must support le connection. + * @post This function invokes bt_gatt_connection_state_changed_cb(). + * + * @see bt_initialize() + * @see bt_gatt_disconnect() + * @see bt_gatt_set_connection_state_changed_cb() + * @see bt_gatt_unset_connection_state_changed_cb() + * @see bt_gatt_connection_state_changed_cb() + */ +int bt_gatt_connect(const char *address, bool auto_connect); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Disconnect to LE connection with the given remote Bluetooth dievice address, asynchronously. + * @since_tizen 2.3 + * @privlevel public + * @privilege %http://tizen.org/privilege/bluetooth + * + * @param[in] address The address of the remote Bluetooth device + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_INVALID_PARAMETER Invalid paramater + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The connection must be established. + * @post This function invokes bt_gatt_connection_state_changed_cb(). + * + * @see bt_initialize() + * @see bt_gatt_connect() + * @see bt_gatt_set_connection_state_changed_cb() + * @see bt_gatt_unset_connection_state_changed_cb() + * @see bt_gatt_connection_state_changed_cb() + */ +int bt_gatt_disconnect(const char *address); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Registers a callback function that will be invoked when the connection state is changed. + * @since_tizen 2.3 + * + * @param[in] callback The callback function to register. + * @param[in] user_data The user data to be passed to the callback function. + * + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid paramater + * + * @see bt_gatt_connect() + * @see bt_gatt_disconnect() + * @see bt_gatt_unset_connection_state_changed_cb() + */ +int bt_gatt_set_connection_state_changed_cb(bt_gatt_connection_state_changed_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Unregisters a callback function that will be invoked when the connection state is changed. + * @since_tizen 2.3 + * + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * + * @see bt_gatt_connect() + * @see bt_gatt_disconnect() + * @see bt_gatt_connection_state_changed_cb() + */ +int bt_gatt_unset_connection_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Initializes the Gatt Service. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/bluetooth.admin + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_adapter_enable() + */ +int _bt_gatt_init_service(void); + + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief DeInitializes the Gatt Service. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/bluetooth.admin + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_adapter_enable() + * @see _bt_gatt_init_service(void) + */ +int _bt_gatt_deinit_service(void); + + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Adds Gatt Service to the service interface. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/bluetooth.admin + * + * @param[in] svc_uuid Gatt service uuid. + * @param[out] svc_path Object path of the GATT service. + * @remarks svc_path must be released with free() by you. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_adapter_enable() + */ +int bt_gatt_add_service(const char *svc_uuid, + char **svc_path); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Deletes a Gatt Service from the Gatt Server Database. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/bluetooth.admin + * + * @param[in] svc_path Service path of the gatt service to remove. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_adapter_enable() + */ +int bt_gatt_remove_service(const char *svc_path); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Adds Gatt characteristic to the Characteristics interface. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/bluetooth.admin + * + * @param[in] char_uuid Gatt characteristic uuid. + * @param[in] char_value Gatt characteristic value. + * @param[in] value_length Caracteristic value length. + * @param[in] char_flags Characteristic flags. + * @param[in] flags_length Caracteristic flags length. + * @param[in] svc_path service path to which this characteristic belongs to. + * @param[out] char_path characteristic path registered on the interface. + * @remarks char_path must be released with free() by you. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_adapter_enable() + */ +int bt_gatt_add_characteristic(const char *char_uuid, + const char *char_value, int value_length, + const char *char_flags[], int flags_length, + const char *svc_path, char **char_path); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Adds Gatt descriptor to the descriptor interface. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/bluetooth.admin + * + * @param[in] desc_uuid Gatt descriptor uuid. + * @param[in] desc_value Gatt descriptor value. + * @param[in] desc_length Gatt descriptor value. + * @param[in] permissions Permissions for the descriptor. + * @param[in] char_path Characteristic path to which this descriptor should belong to. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_adapter_enable() + */ +int bt_gatt_add_descriptor(const char *desc_uuid, + const char *desc_value, int value_length, + const char *permissions, const char *char_path, + char **desc_path); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Registers the given service path (including characteristics and descriptor) with the Bluez. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/bluetooth.admin + * + * @param[in] svc_path Gatt service path obtained from the add_service. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre bt_gatt_add_service, bt_gatt_add_characteristic and bt_gatt_add_descriptor + * must be called before calling bt_gatt_register_service + * + * @see bt_adapter_enable() + * @see bt_gatt_add_service() + * @see bt_gatt_add_characteristic() + * @see bt_gatt_add_descriptor() + */ +int bt_gatt_register_service(const char *svc_path, + bt_gatt_remote_characteristic_write_cb callback, + void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Updates the existing characteristic value. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/bluetooth.admin + * + * @param[in] char_path characteristic path registered on the interface. + * @param[in] char_value Gatt characteristic value. + * @param[in] value_length Characteristic value length. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @see bt_adapter_enable() + */ +int bt_gatt_update_characteristic(const char *char_path, + const char *char_value, int value_length); +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Delete Gatt Services from the Gatt Server Database. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/bluetooth.admin + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post @a callback will be called. + * @see bt_adapter_enable() + */ +int bt_gatt_delete_services(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE + * @brief Activates the NAP(Network Access Point). + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_ALREADY_DONE Operation is already done + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED + * @see bt_nap_deactivate() + */ +int bt_nap_activate(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE + * @brief Deactivates the NAP(Network Access Point). + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_ALREADY_DONE Operation is already done + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The Bluetooth NAP service must be activated with bt_nap_activate(). + * @see bt_nap_activate() + */ +int bt_nap_deactivate(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE + * @brief Disconnects the all PANUs(Personal Area Networking User) which are connected to you. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The Bluetooth NAP service must be activated with bt_nap_activate(). + * @see bt_nap_activate() + */ +int bt_nap_disconnect_all(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE + * @brief Disconnects the specified PANU(Personal Area Networking User) which is connected to you. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] remote_address The remote address + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The Bluetooth NAP service must be activated with bt_nap_activate(). + * @see bt_nap_activate() + */ +int bt_nap_disconnect(const char *remote_address); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE + * @brief Registers a callback function that will be invoked when the connection state changes. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_nap_connection_state_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_nap_connection_state_changed_cb() + * @see bt_nap_unset_connection_state_changed_cb() + */ +int bt_nap_set_connection_state_changed_cb(bt_nap_connection_state_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE + * @brief Unregisters a callback function that will be invoked when the connection state changes. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_nap_connection_state_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_nap_connection_state_changed_cb() + * @see bt_nap_set_connection_state_changed_cb() + */ +int bt_nap_unset_connection_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE + * @brief Registers a callback function that will be invoked when the connection state changes. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_nap_connection_state_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_panu_connection_state_changed_cb() + * @see bt_panu_unset_connection_state_changed_cb() + */ +int bt_panu_set_connection_state_changed_cb(bt_panu_connection_state_changed_cb callback, void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE + * @brief Unregisters a callback function that will be invoked when the connection state changes. + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_nap_connection_state_changed_cb() will be invoked. + * @see bt_initialize() + * @see bt_panu_connection_state_changed_cb() + * @see bt_panu_set_connection_state_changed_cb() + */ +int bt_panu_unset_connection_state_changed_cb(void); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE + * @brief Connects the remote device with the PAN(Personal Area Networking) service, asynchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] remote_address The remote address + * @param[in] type The type of PAN service + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device is not bonded + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The local device must be bonded with the remote device by bt_device_create_bond(). + * @post bt_panu_connection_state_changed_cb() will be invoked. + * @see bt_panu_disconnect() + * @see bt_panu_connection_state_changed_cb() + */ +int bt_panu_connect(const char *remote_address, bt_panu_service_type_e type); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE + * @brief Disconnects the remote device with the PAN(Personal Area Networking) service, asynchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] remote_address The remote address + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The remote device must be connected by bt_panu_connect(). + * @post bt_panu_connection_state_changed_cb() will be invoked. + * @see bt_panu_connect() + * @see bt_panu_connection_state_changed_cb() + */ +int bt_panu_disconnect(const char *remote_address); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief update LE connection. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @pre The Bluetooth service must be initialized by bt_initialize(). + * @pre The remote device must be connected with bt_gatt_connect(). + */ +int bt_device_le_conn_update(const char *device_address, + const bt_le_conn_update_s *parameters); + + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // __TIZEN_NETWORK_BLUETOOTH_H__ diff --git a/resource/csdk/connectivity/lib/tizen/ble/inc/bluetooth_private.h b/resource/csdk/connectivity/lib/tizen/ble/inc/bluetooth_private.h new file mode 100644 index 0000000..dbb8e44 --- /dev/null +++ b/resource/csdk/connectivity/lib/tizen/ble/inc/bluetooth_private.h @@ -0,0 +1,284 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd 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 __TIZEN_NETWORK_BLUETOOTH_PRIVATE_H__ +#define __TIZEN_NETWORK_BLUETOOTH_PRIVATE_H__ + +#include +#include +#include +#include +#include +#include +#include + +#include "bluetooth.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#undef LOG_TAG +#define LOG_TAG "CAPI_NETWORK_BLUETOOTH" + +#define BT_INFO(fmt, args...) SLOGI(fmt, ##args) +#define BT_DBG(fmt, args...) SLOGD(fmt, ##args) +#define BT_ERR(fmt, args...) SLOGE(fmt, ##args) + +#define OPP_UUID "00001105-0000-1000-8000-00805f9b34fb" + +/** + * @internal + * @brief Bluetooth callback. + */ +typedef enum +{ + BT_EVENT_STATE_CHANGED = 0x00, /**< Adapter state is changed */ + BT_EVENT_LE_STATE_CHANGED, /**< Adapter le state is changed */ + BT_EVENT_NAME_CHANGED, /**< Adapter name is changed */ + BT_EVENT_VISIBILITY_MODE_CHANGED, /**< Adapter visibility mode is changed */ + BT_EVENT_VISIBILITY_DURATION_CHANGED, /**< Adapter visibility duration is changed */ + BT_EVENT_DEVICE_DISCOVERY_STATE_CHANGED, /**< Device discovery state is changed */ + BT_EVENT_LE_DEVICE_DISCOVERY_STATE_CHANGED, /**< LE Device discovery state is changed */ + BT_EVENT_BOND_CREATED, /**< A bond is created */ + BT_EVENT_BOND_DESTROYED, /**< A bond is destroyed */ + BT_EVENT_AUTHORIZATION_CHANGED, /**< Authorization is changed */ + BT_EVENT_SERVICE_SEARCHED, /**< Service search finish */ + BT_EVENT_DATA_RECEIVED, /**< Data is received */ + BT_EVENT_CONNECTION_STATE_CHANGED, /**< Connection state is changed */ + BT_EVENT_RFCOMM_CONNECTION_REQUESTED, /**< RFCOMM connection is requested */ + BT_EVENT_OPP_CONNECTION_REQUESTED, /**< OPP connection is requested */ + BT_EVENT_OPP_PUSH_REQUESTED, /**< OPP push is requested */ + BT_EVENT_OPP_SERVER_TRANSFER_PROGRESS, /**< OPP transfer progress */ + BT_EVENT_OPP_SERVER_TRANSFER_FINISHED, /**< OPP transfer is completed */ + BT_EVENT_OPP_CLIENT_PUSH_RESPONSED, /**< OPP client connection is reponsed */ + BT_EVENT_OPP_CLIENT_PUSH_PROGRESS, /**< OPP client push progress */ + BT_EVENT_OPP_CLIENT_PUSH_FINISHED, /**< OPP client push is finished */ + BT_EVENT_PAN_CONNECTION_STATE_CHANGED, /**< PAN connection change */ + BT_EVENT_NAP_CONNECTION_STATE_CHANGED, /**< NAP connection change */ + BT_EVENT_HDP_CONNECTED, /**< HDP connection change */ + BT_EVENT_HDP_DISCONNECTED, /**< HDP disconnection change */ + BT_EVENT_HDP_DATA_RECEIVED, /**< HDP Data receive Callabck */ + BT_EVENT_AUDIO_CONNECTION_STATUS, /**< Audio Connection change callback */ + BT_EVENT_AG_SCO_CONNECTION_STATUS, /**< Audio - AG SCO Connection state change callback */ + BT_EVENT_AG_CALL_HANDLING_EVENT, /**< Audio - AG call event callback */ + BT_EVENT_AG_MULTI_CALL_HANDLING_EVENT, /**< Audio - AG 3-way call event callback */ + BT_EVENT_AG_DTMF_TRANSMITTED, /**< Audio - DTMF tone sending request */ + BT_EVENT_AG_MICROPHONE_GAIN_CHANGE, /**< Audio Microphone change callback */ + BT_EVENT_AG_SPEAKER_GAIN_CHANGE, /**< Audio Speaker gain change callback */ + BT_EVENT_AG_VENDOR_CMD, /**< Audio - XSAT Vendor cmd */ + BT_EVENT_AVRCP_CONNECTION_STATUS, /**< AVRCP connection change callback */ + BT_EVENT_AVRCP_EQUALIZER_STATE_CHANGED, /**< AVRCP equalizer state change callback */ + BT_EVENT_AVRCP_REPEAT_MODE_CHANGED, /**< AVRCP repeat mode change callback */ + BT_EVENT_AVRCP_SHUFFLE_MODE_CHANGED, /**< AVRCP equalizer mode change callback */ + BT_EVENT_AVRCP_SCAN_MODE_CHANGED, /**< AVRCP scan mode change callback */ + BT_EVENT_HID_CONNECTION_STATUS, /**< HID connection status callback */ + BT_EVENT_DEVICE_CONNECTION_STATUS, /**< Device connection status callback */ + BT_EVENT_GATT_CONNECTION_STATUS, /** < GATT connection status callback */ + BT_EVENT_GATT_PRIM_SVC_DISCOVERED, /**< GATT Primary Service discovered callback */ + BT_EVENT_GATT_CHARACTERISTIC_DISCOVERED, /**< GATT characteristic discovered callback */ + BT_EVENT_GATT_CHARACTERISTIC_DESCRIPTOR_DISCOVERED, /**< GATT characteristic descriptor discovered callback */ + BT_EVENT_GATT_VALUE_CHANGED, /**< GATT characteristic value changed callback */ + BT_EVENT_GATT_READ_CHARACTERISTIC, /**< GATT characteristic value read callback */ + BT_EVENT_GATT_WRITE_CHARACTERISTIC, /**< GATT characteristic value write callback */ + BT_EVENT_GATT_SERVER_ON_WRITE_CHAR, /**< GATT characteristic value write callback */ + BT_EVENT_ADVERTISING_STATE_CHANGED, /**< Advertising state changed callback */ + BT_EVENT_MANUFACTURER_DATA_CHANGED, /**< Manufacturer data changed callback */ + BT_EVENT_CONNECTABLE_CHANGED_EVENT, /**< Adapter connectable changed callback */ + BT_EVENT_RSSI_ENABLED_EVENT, /**< RSSI Enabled callback */ + BT_EVENT_RSSI_ALERT_EVENT, /**< RSSI Alert callback */ + BT_EVENT_GET_RSSI_EVENT, /**< Get RSSI Strength callback */ +#ifdef TIZEN_WEARABLE + BT_EVENT_PBAP_CONNECTION_STATUS, /**< PBAP connection status callback */ + BT_EVENT_PBAP_PHONEBOOK_SIZE, /**< PBAP Phonebook Size status callback */ + BT_EVENT_PBAP_PHONEBOOK_PULL, /**< PBAP Phonebook Pull status callback */ + BT_EVENT_PBAP_VCARD_LIST, /**< PBAP vCard List status callback */ + BT_EVENT_PBAP_VCARD_PULL, /**< PBAP vCard Pull status callback */ + BT_EVENT_PBAP_PHONEBOOK_SEARCH, /**< PBAP Phonebook Search status callback */ + BT_EVENT_HF_SCO_CONNECTION_STATUS, /**< Audio - HF SCO Connection state change callback */ + BT_EVENT_HF_SPEAKER_GAIN_CHANGE, /**< Audio - HF Speaker gain change callback */ + BT_EVENT_HF_CALL_HANDLING_EVENT, /**< Audio - HF call event callback */ + BT_EVENT_HF_VENDOR_DEP_CMD_EVENT, /**< Audio - HF Vendor Command callback */ + BT_EVENT_HF_MULTI_CALL_HANDLING_EVENT, /**< Audio - HF 3-way call event callback */ +#endif +} bt_event_e; + +/** + * @internal + */ +typedef struct { + int handle; + + bt_adapter_le_advertising_state_changed_cb cb; + void *cb_data; + + bt_adapter_le_advertising_params_s adv_params; + + unsigned int adv_data_len; + char *adv_data; + + unsigned int scan_rsp_data_len; + char *scan_rsp_data; + + void *user_data; +} bt_advertiser_s; + +/** + * @internal + */ +typedef struct bt_event_sig_event_slot_s +{ + int event_type; + const void *callback; + void *user_data; +} bt_event_sig_event_slot_s; + + +#define BT_CHECK_INPUT_PARAMETER(arg) \ + if (arg == NULL) \ + { \ + LOGE("[%s] INVALID_PARAMETER(0x%08x)", __FUNCTION__, BT_ERROR_INVALID_PARAMETER); \ + return BT_ERROR_INVALID_PARAMETER; \ + } + +/** + * @internal + * @brief Check the initialzating status + */ +int _bt_check_init_status(void); + +#define BT_CHECK_INIT_STATUS() \ + if (_bt_check_init_status() == BT_ERROR_NOT_INITIALIZED) \ + { \ + LOGE("[%s] NOT_INITIALIZED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_INITIALIZED); \ + return BT_ERROR_NOT_INITIALIZED; \ + } + +/** + * @internal + * @brief Initialize Bluetooth LE adapter + */ +int _bt_le_adapter_init(void); + +/** + * @internal + * @brief Deinitialize Bluetooth LE adapter + */ +int _bt_le_adapter_deinit(void); + +/** + * @internal + * @brief Set the event callback. + */ +void _bt_set_cb(int events, void *callback, void *user_data); + +/** + * @internal + * @brief Unset the event callback. + */ +void _bt_unset_cb(int events); + +/** + * @internal + * @brief Check if the event callback exist or not. + */ +bool _bt_check_cb(int events); + +/** + * @internal + * @brief Convert Bluetooth F/W error codes to capi Bluetooth error codes. + */ +int _bt_get_error_code(int origin_error); + + +/** + * @internal + * @brief Convert Bluetooth F/W bluetooth_device_info_t to capi bt_device_info_s. + */ +int _bt_get_bt_device_info_s(bt_device_info_s **dest_dev, bluetooth_device_info_t *source_dev); + + +/** + * @internal + * @brief Free bt_device_info_s. + */ +void _bt_free_bt_device_info_s(bt_device_info_s *device_info); + +/** + * @internal + * @brief Convert Bluetooth F/W bluetooth_device_address_t to string. + */ +int _bt_convert_address_to_string(char **addr_str, bluetooth_device_address_t *addr_hex); + + +/** + * @internal + * @brief Convert string to Bluetooth F/W bluetooth_device_address_t. + */ +void _bt_convert_address_to_hex(bluetooth_device_address_t *addr_hex, const char *addr_str); + + +/** + * @internal + * @brief Convert error code to string. + */ +char* _bt_convert_error_to_string(int error); + +/** + * @internal + * @brief Convert the visibility mode + */ +bt_adapter_visibility_mode_e _bt_get_bt_visibility_mode_e(bluetooth_discoverable_mode_t mode); + +/** + * @internal + * @brief Since the Audio call back and event proxy call backs have different prototype it is wrapper function. + */ +void _bt_audio_event_proxy(int event, bt_audio_event_param_t *param, void *user_data); + +#ifdef TIZEN_WEARABLE +/** + * @internal + * @brief Since the HF call back and event proxy call backs have different prototype it is wrapper function. + */ +void _bt_hf_event_proxy(int event, bt_hf_event_param_t *param, void *user_data); +#endif + +/** + * @internal + * @brief Since the Telephony call back and event proxy call backs have different prototype it is wrapper function. + */ +void _bt_telephony_event_proxy(int event, telephony_event_param_t *param, void *user_data); + +/** + * @internal + * @brief Since the AVRCP call back and event proxy call backs have different prototype it is wrapper function. + */ +void _bt_avrcp_event_proxy(int event, media_event_param_t *param, void *user_data); + +/** + * @internal + * @brief Since the HID call back and event proxy call backs have different prototype it is wrapper function. + */ +void _bt_hid_event_proxy(int event, hid_event_param_t *param, void *user_data); + + +#ifdef __cplusplus +} +#endif + +#endif /* __TIZEN_NETWORK_BLUETOOTH_PRIVATE_H__ */ diff --git a/resource/csdk/connectivity/lib/tizen/ble/inc/bluetooth_type.h b/resource/csdk/connectivity/lib/tizen/ble/inc/bluetooth_type.h new file mode 100644 index 0000000..5af00a4 --- /dev/null +++ b/resource/csdk/connectivity/lib/tizen/ble/inc/bluetooth_type.h @@ -0,0 +1,1493 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd 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 __TIZEN_NETWORK_BLUETOOTH_TYPE_H__ +#define __TIZEN_NETWORK_BLUETOOTH_TYPE_H__ + + #ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +/** + * @file bluetooth_type.h + * @brief API to control the Bluetooth adapter, devices and communications. + * @ingroup CAPI_NETWORK_BLUETOOTH_TYPE_MODULE + */ + + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_MODULE + * @brief Enumerations of Bluetooth error codes. + */ +typedef enum +{ + BT_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful*/ + BT_ERROR_CANCELLED = TIZEN_ERROR_CANCELED, /**< Operation cancelled */ + BT_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + BT_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + BT_ERROR_RESOURCE_BUSY = TIZEN_ERROR_RESOURCE_BUSY, /**< Device or resource busy */ + BT_ERROR_TIMED_OUT = TIZEN_ERROR_TIMED_OUT, /**< Timeout error */ + BT_ERROR_NOW_IN_PROGRESS = TIZEN_ERROR_NOW_IN_PROGRESS, /**< Operation now in progress */ + BT_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, + BT_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ + BT_ERROR_QUOTA_EXCEEDED = TIZEN_ERROR_QUOTA_EXCEEDED, /**< Quota exceeded */ + BT_ERROR_NOT_INITIALIZED = TIZEN_ERROR_BLUETOOTH|0x0101, /**< Local adapter not initialized */ + BT_ERROR_NOT_ENABLED = TIZEN_ERROR_BLUETOOTH|0x0102, /**< Local adapter not enabled */ + BT_ERROR_ALREADY_DONE = TIZEN_ERROR_BLUETOOTH|0x0103, /**< Operation already done */ + BT_ERROR_OPERATION_FAILED = TIZEN_ERROR_BLUETOOTH|0x0104, /**< Operation failed */ + BT_ERROR_NOT_IN_PROGRESS = TIZEN_ERROR_BLUETOOTH|0x0105, /**< Operation not in progress */ + BT_ERROR_REMOTE_DEVICE_NOT_BONDED = TIZEN_ERROR_BLUETOOTH|0x0106, /**< Remote device not bonded */ + BT_ERROR_AUTH_REJECTED = TIZEN_ERROR_BLUETOOTH|0x0107, /**< Authentication rejected */ + BT_ERROR_AUTH_FAILED = TIZEN_ERROR_BLUETOOTH|0x0108, /**< Authentication failed */ + BT_ERROR_REMOTE_DEVICE_NOT_FOUND = TIZEN_ERROR_BLUETOOTH|0x0109, /**< Remote device not found */ + BT_ERROR_SERVICE_SEARCH_FAILED = TIZEN_ERROR_BLUETOOTH|0x010A, /**< Service search failed */ + BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED = TIZEN_ERROR_BLUETOOTH|0x010B, /**< Remote device is not connected */ + BT_ERROR_AGAIN = TIZEN_ERROR_BLUETOOTH|0x010C, /**< Resource temporarily unavailable */ + BT_ERROR_SERVICE_NOT_FOUND = TIZEN_ERROR_BLUETOOTH|0x010D, /**< Service Not Found */ +} bt_error_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Enumerations of the Bluetooth adapter state. + */ +typedef enum +{ + BT_ADAPTER_DISABLED = 0x00, /**< Bluetooth adapter is disabled */ + BT_ADAPTER_ENABLED, /**< Bluetooth adapter is enabled */ +} bt_adapter_state_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enumerations of the Bluetooth adapter le state. + */ +typedef enum +{ + BT_ADAPTER_LE_DISABLED = 0x00, /**< Bluetooth le is disabled */ + BT_ADAPTER_LE_ENABLED, /**< Bluetooth le is enabled */ +} bt_adapter_le_state_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Enumerations of the Bluetooth visibility mode. + */ +typedef enum +{ + BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE = 0x00, /**< Other devices cannot find your device via discovery */ + BT_ADAPTER_VISIBILITY_MODE_GENERAL_DISCOVERABLE, /**< Discoverable mode */ + BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE, /**< Discoverable mode with time limit. After specific period, + it is changed to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE.*/ +} bt_adapter_visibility_mode_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Enumerations of the discovery state of Bluetooth device. + * + */ +typedef enum +{ + BT_ADAPTER_DEVICE_DISCOVERY_STARTED, /**< Device discovery is started */ + BT_ADAPTER_DEVICE_DISCOVERY_FINISHED, /**< Device discovery is finished */ + BT_ADAPTER_DEVICE_DISCOVERY_FOUND, /**< The remote Bluetooth device is found */ +} bt_adapter_device_discovery_state_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enumerations of the discovery state of Bluetooth LE device. + * + */ +typedef enum +{ + BT_ADAPTER_LE_DEVICE_DISCOVERY_STARTED, /**< LE device discovery is started */ + BT_ADAPTER_LE_DEVICE_DISCOVERY_FINISHED, /**< LE device discovery is finished */ + BT_ADAPTER_LE_DEVICE_DISCOVERY_FOUND, /**< The remote Bluetooth LE device is found */ +} bt_adapter_le_device_discovery_state_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enumerations of the Bluetooth advertising state. + */ +typedef enum { + BT_ADAPTER_LE_ADVERTISING_STOPPED = 0x00, /**< Bluetooth advertising is stopped */ + BT_ADAPTER_LE_ADVERTISING_STARTED, /**< Bluetooth advertising is started */ +} bt_adapter_le_advertising_state_e; + + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enumerations of the Bluetooth advertising filter policy. + */ +typedef enum { + BT_ADAPTER_LE_ADVERTISING_FILTER_DEFAULT = 0x00, /**< White list is not in use */ + BT_ADAPTER_LE_ADVERTISING_FILTER_ALLOW_SCAN_WL = 0x01, /**< Allow the scan + request that in the White list */ + BT_ADAPTER_LE_ADVERTISING_FILTER_ALLOW_CONN_WL = 0x02, /**< Allow the connectoin + request that in the White list */ + BT_ADAPTER_LE_ADVERTISING_FILTER_ALLOW_SCAN_CONN_WL = 0x03, /**< Allow the + scan and connectoin request that in the White list */ +} bt_adapter_le_advertising_filter_policy_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enumerations of the Bluetooth advertising type. + */ +typedef enum { + BT_ADAPTER_LE_ADVERTISING_CONNECTABLE = 0x00, /**< Connectable undirected advertising (ADV_IND) */ + BT_ADAPTER_LE_ADVERTISING_CONNECTABLE_DIRECT_HIGH = 0x01, /**< Connectable high duty cycle directed advertising (ADV_DIRECT_IND) */ + BT_ADAPTER_LE_ADVERTISING_SCANNABLE = 0x02, /**< Scannable undirected advertising (ADV_SCAN_IND) */ + BT_ADAPTER_LE_ADVERTISING_NON_CONNECTABLE = 0x03, /**< Non connectable undirected advertising (ADV_NONCOND_IND) */ + BT_ADAPTER_LE_ADVERTISING_CONNECTABLE_DIRECT_LOW = 0x04, /**< Connectable low duty cycle directed advertising (ADV_DIRECT_IND) */ +} bt_adapter_le_advertising_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enumerations of the Bluetooth LE packet type. + */ +typedef enum { + BT_ADAPTER_LE_PACKET_ADVERTISING, /**< Advertising packet */ + BT_ADAPTER_LE_PACKET_SCAN_RESPONSE, /**< Sacn response packet */ +} bt_adapter_le_packet_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enumerations of the Bluetooth LE data type + * that can be included in LE packets. + */ +typedef enum { + BT_ADAPTER_LE_PACKET_DATA_COMP_LIST_16_BIT_SERVICE_CLASS_UUIDS = 0x03, /**< 16 bit UUID */ + BT_ADAPTER_LE_PACKET_DATA_MANUFACTURER_SPECIFIC_DATA = 0xff, /**< Manufacturer data */ +} bt_adapter_le_packet_data_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of device disconnect reason. + */ +typedef enum +{ + BT_DEVICE_DISCONNECT_REASON_UNKNOWN, /**< Disconnected by unknown reason */ + BT_DEVICE_DISCONNECT_REASON_TIMEOUT, /**< Disconnected by timeout */ + BT_DEVICE_DISCONNECT_REASON_LOCAL_HOST, /**< Disconnected by local host */ + BT_DEVICE_DISCONNECT_REASON_REMOTE, /**< Disconnected by remote */ +} bt_device_disconnect_reason_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of connection link type. + */ +typedef enum +{ + BT_DEVICE_CONNECTION_LINK_BREDR, /**< BR/EDR link */ + BT_DEVICE_CONNECTION_LINK_LE, /**< LE link */ + BT_DEVICE_CONNECTION_LINK_DEFAULT = 0xFF, /**< The connection type defualt */ +} bt_device_connection_link_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of device authorization state. + */ +typedef enum +{ + BT_DEVICE_AUTHORIZED, /**< The remote Bluetooth device is authorized */ + BT_DEVICE_UNAUTHORIZED, /**< The remote Bluetooth device is unauthorized */ +} bt_device_authorization_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of Bluetooth profile. + */ +typedef enum +{ + BT_PROFILE_RFCOMM = 0x01, /**< RFCOMM Profile */ + BT_PROFILE_A2DP = 0x02, /**< Advanced Audio Distribution Profile */ + BT_PROFILE_HSP = 0x04, /**< Headset Profile */ + BT_PROFILE_HID = 0x08, /**< Human Interface Device Profile */ + BT_PROFILE_NAP = 0x10, /**< Network Access Point Profile */ + BT_PROFILE_AG = 0x20, /**< Audio Gateway Profile */ + BT_PROFILE_GATT = 0x40, /**< Generic Attribute Profile */ + BT_PROFILE_NAP_SERVER = 0x80, /**< NAP server Profile */ +} bt_profile_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of device address type. + */ +typedef enum +{ + BT_DEVICE_PUBLIC_ADDRESS = 0x00, /**< Public address */ + BT_DEVICE_RANDOM_ADDRESS, /**< Random address */ +} bt_device_address_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of service class. + */ +typedef enum { + BT_SC_NONE = 0, /**< No service class */ + BT_SC_RES_SERVICE_MASK = 0x00000001, /**< RES service class */ + BT_SC_SPP_SERVICE_MASK = 0x00000002, /**< SPP service class */ + BT_SC_DUN_SERVICE_MASK = 0x00000004, /**< DUN service class */ + BT_SC_FAX_SERVICE_MASK = 0x00000008, /**< FAX service class */ + BT_SC_LAP_SERVICE_MASK = 0x00000010, /**< LAP service class */ + BT_SC_HSP_SERVICE_MASK = 0x00000020, /**< HSP service class */ + BT_SC_HFP_SERVICE_MASK = 0x00000040, /**< HFP service class */ + BT_SC_OPP_SERVICE_MASK = 0x00000080, /**< OPP service class */ + BT_SC_FTP_SERVICE_MASK = 0x00000100, /**< FTP service class */ + BT_SC_CTP_SERVICE_MASK = 0x00000200, /**< CTP service class */ + BT_SC_ICP_SERVICE_MASK = 0x00000400, /**< ICP service class */ + BT_SC_SYNC_SERVICE_MASK = 0x00000800, /**< SYNC service class */ + BT_SC_BPP_SERVICE_MASK = 0x00001000, /**< BPP service class */ + BT_SC_BIP_SERVICE_MASK = 0x00002000, /**< BIP service class */ + BT_SC_PANU_SERVICE_MASK = 0x00004000, /**< PANU service class */ + BT_SC_NAP_SERVICE_MASK = 0x00008000, /**< NAP service class */ + BT_SC_GN_SERVICE_MASK = 0x00010000, /**< GN service class */ + BT_SC_SAP_SERVICE_MASK = 0x00020000, /**< SAP service class */ + BT_SC_A2DP_SERVICE_MASK = 0x00040000, /**< A2DP service class */ + BT_SC_AVRCP_SERVICE_MASK = 0x00080000, /**< AVRCP service class */ + BT_SC_PBAP_SERVICE_MASK = 0x00100000, /**< PBAP service class */ + BT_SC_HID_SERVICE_MASK = 0x00200000, /**< HID service class */ + BT_SC_ALL_SERVICE_MASK = 0x00FFFFFF, /**< ALL service class */ + BT_SC_MAX /**< MAX service class */ +} bt_service_class_t; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of major service class. + */ +typedef enum +{ + BT_MAJOR_SERVICE_CLASS_LIMITED_DISCOVERABLE_MODE = 0x002000, /**< Limited discoverable mode */ + BT_MAJOR_SERVICE_CLASS_POSITIONING = 0x010000, /**< Positioning class */ + BT_MAJOR_SERVICE_CLASS_NETWORKING = 0x020000, /**< Networking class */ + BT_MAJOR_SERVICE_CLASS_RENDERING = 0x040000, /**< Rendering class */ + BT_MAJOR_SERVICE_CLASS_CAPTURING = 0x080000, /**< Capturing class */ + BT_MAJOR_SERVICE_CLASS_OBJECT_TRANSFER = 0x100000, /**< Object transferring class */ + BT_MAJOR_SERVICE_CLASS_AUDIO = 0x200000, /**< Audio class*/ + BT_MAJOR_SERVICE_CLASS_TELEPHONY = 0x400000, /**< Telephony class */ + BT_MAJOR_SERVICE_CLASS_INFORMATION = 0x800000, /**< Information class */ +} bt_major_service_class_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of major device class. + */ +typedef enum +{ + BT_MAJOR_DEVICE_CLASS_MISC = 0x00, /**< Miscellaneous major device class*/ + BT_MAJOR_DEVICE_CLASS_COMPUTER = 0x01, /**< Computer major device class */ + BT_MAJOR_DEVICE_CLASS_PHONE = 0x02, /**< Phone major device class */ + BT_MAJOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT = 0x03, /**< LAN/Network access point major device class */ + BT_MAJOR_DEVICE_CLASS_AUDIO_VIDEO = 0x04, /**< Audio/Video major device class */ + BT_MAJOR_DEVICE_CLASS_PERIPHERAL = 0x05, /**< Peripheral major device class */ + BT_MAJOR_DEVICE_CLASS_IMAGING = 0x06, /**< Imaging major device class */ + BT_MAJOR_DEVICE_CLASS_WEARABLE = 0x07, /**< Wearable device class */ + BT_MAJOR_DEVICE_CLASS_TOY = 0x08, /**< Toy device class */ + BT_MAJOR_DEVICE_CLASS_HEALTH = 0x09, /**< Health device class */ + BT_MAJOR_DEVICE_CLASS_UNCATEGORIZED = 0x1F, /**< Uncategorized major device class */ +} bt_major_device_class_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of minor device class. + */ +typedef enum +{ + BT_MINOR_DEVICE_CLASS_COMPUTER_UNCATEGORIZED = 0x00, /**< Uncategorized minor device class of computer */ + BT_MINOR_DEVICE_CLASS_COMPUTER_DESKTOP_WORKSTATION = 0x04, /**< Desktop workstation minor device class of computer */ + BT_MINOR_DEVICE_CLASS_COMPUTER_SERVER_CLASS = 0x08, /**< Server minor device class of computer */ + BT_MINOR_DEVICE_CLASS_COMPUTER_LAPTOP = 0x0C, /**< Laptop minor device class of computer */ + BT_MINOR_DEVICE_CLASS_COMPUTER_HANDHELD_PC_OR_PDA = 0x10, /**< Handheld PC/PDA minor device class of computer */ + BT_MINOR_DEVICE_CLASS_COMPUTER_PALM_SIZED_PC_OR_PDA = 0x14, /**< Palm sized PC/PDA minor device class of computer */ + BT_MINOR_DEVICE_CLASS_COMPUTER_WEARABLE_COMPUTER = 0x18, /**< Wearable(watch sized) minor device class of computer */ + + BT_MINOR_DEVICE_CLASS_PHONE_UNCATEGORIZED = 0x00, /**< Uncategorized minor device class of phone */ + BT_MINOR_DEVICE_CLASS_PHONE_CELLULAR = 0x04, /**< Cellular minor device class of phone */ + BT_MINOR_DEVICE_CLASS_PHONE_CORDLESS = 0x08, /**< Cordless minor device class of phone */ + BT_MINOR_DEVICE_CLASS_PHONE_SMART_PHONE = 0x0C, /**< Smart phone minor device class of phone */ + BT_MINOR_DEVICE_CLASS_PHONE_WIRED_MODEM_OR_VOICE_GATEWAY = 0x10, /**< Wired modem or voice gateway minor device class of phone */ + BT_MINOR_DEVICE_CLASS_PHONE_COMMON_ISDN_ACCESS = 0x14, /**< Common ISDN minor device class of phone */ + + BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_FULLY_AVAILABLE = 0x04, /**< Fully available minor device class of LAN/Network access point */ + BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_1_TO_17_PERCENT_UTILIZED = 0x20, /**< 1-17% utilized minor device class of LAN/Network access point */ + BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_17_TO_33_PERCENT_UTILIZED = 0x40, /**< 17-33% utilized minor device class of LAN/Network access point */ + BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_33_TO_50_PERCENT_UTILIZED = 0x60, /**< 33-50% utilized minor device class of LAN/Network access point */ + BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_50_to_67_PERCENT_UTILIZED = 0x80, /**< 50-67% utilized minor device class of LAN/Network access point */ + BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_67_TO_83_PERCENT_UTILIZED = 0xA0, /**< 67-83% utilized minor device class of LAN/Network access point */ + BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_83_TO_99_PERCENT_UTILIZED = 0xC0, /**< 83-99% utilized minor device class of LAN/Network access point */ + BT_MINOR_DEVICE_CLASS_LAN_NETWORK_ACCESS_POINT_NO_SERVICE_AVAILABLE = 0xE0, /**< No service available minor device class of LAN/Network access point */ + + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_UNCATEGORIZED = 0x00, /**< Uncategorized minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_WEARABLE_HEADSET = 0x04, /**< Wearable headset minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_HANDS_FREE = 0x08, /**< Hands-free minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_MICROPHONE = 0x10, /**< Microphone minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_LOUDSPEAKER = 0x14, /**< Loudspeaker minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_HEADPHONES = 0x18, /**< Headphones minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_PORTABLE_AUDIO = 0x1C, /**< Portable audio minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_CAR_AUDIO = 0x20, /**< Car audio minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_SET_TOP_BOX = 0x24, /**< Set-top box minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_HIFI_AUDIO_DEVICE = 0x28, /**< Hifi audio minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VCR = 0x2C, /**< VCR minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_CAMERA = 0x30, /**< Video camera minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_CAMCORDER = 0x34, /**< Camcorder minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_MONITOR = 0x38, /**< Video monitor minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_DISPLAY_LOUDSPEAKER = 0x3C, /**< Video display and loudspeaker minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_VIDEO_CONFERENCING = 0x40, /**< Video conferencing minor device class of audio/video */ + BT_MINOR_DEVICE_CLASS_AUDIO_VIDEO_GAMING_TOY = 0x48, /**< Gaming/toy minor device class of audio/video */ + + BT_MINOR_DEVICE_CLASS_PERIPHERA_UNCATEGORIZED = 0x00, /**< Uncategorized minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_KEY_BOARD = 0x40, /**< Key board minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_POINTING_DEVICE = 0x80, /**< Pointing device minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_COMBO_KEYBOARD_POINTING_DEVICE = 0xC0, /**< Combo keyboard or pointing device minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_JOYSTICK = 0x04, /**< Joystick minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_GAME_PAD = 0x08, /**< Game pad minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_REMOTE_CONTROL = 0x0C, /**< Remote control minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_SENSING_DEVICE = 0x10, /**< Sensing device minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_DIGITIZER_TABLET = 0x14, /**< Digitizer minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_CARD_READER = 0x18, /**< Card reader minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_DIGITAL_PEN = 0x1C, /**< Digital pen minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_HANDHELD_SCANNER = 0x20, /**< Handheld scanner minor device class of peripheral */ + BT_MINOR_DEVICE_CLASS_PERIPHERAL_HANDHELD_GESTURAL_INPUT_DEVICE = 0x24, /**< Handheld gestural input device minor device class of peripheral */ + + BT_MINOR_DEVICE_CLASS_IMAGING_DISPLAY = 0x10, /**< Display minor device class of imaging */ + BT_MINOR_DEVICE_CLASS_IMAGING_CAMERA = 0x20, /**< Camera minor device class of imaging */ + BT_MINOR_DEVICE_CLASS_IMAGING_SCANNER = 0x40, /**< Scanner minor device class of imaging */ + BT_MINOR_DEVICE_CLASS_IMAGING_PRINTER = 0x80, /**< Printer minor device class of imaging */ + + BT_MINOR_DEVICE_CLASS_WEARABLE_WRIST_WATCH = 0x04, /**< Wrist watch minor device class of wearable */ + BT_MINOR_DEVICE_CLASS_WEARABLE_PAGER = 0x08, /**< Pager minor device class of wearable */ + BT_MINOR_DEVICE_CLASS_WEARABLE_JACKET = 0x0C, /**< Jacket minor device class of wearable */ + BT_MINOR_DEVICE_CLASS_WEARABLE_HELMET = 0x10, /**< Helmet minor device class of wearable */ + BT_MINOR_DEVICE_CLASS_WEARABLE_GLASSES = 0x14, /**< Glasses minor device class of wearable */ + + BT_MINOR_DEVICE_CLASS_TOY_ROBOT = 0x04, /**< Robot minor device class of toy */ + BT_MINOR_DEVICE_CLASS_TOY_VEHICLE = 0x08, /**< Vehicle minor device class of toy */ + BT_MINOR_DEVICE_CLASS_TOY_DOLL_ACTION = 0x0C, /**< Doll/Action minor device class of toy */ + BT_MINOR_DEVICE_CLASS_TOY_CONTROLLER = 0x10, /**< Controller minor device class of toy */ + BT_MINOR_DEVICE_CLASS_TOY_GAME = 0x14, /**< Game minor device class of toy */ + + BT_MINOR_DEVICE_CLASS_HEALTH_UNCATEGORIZED = 0x00, /**< Uncategorized minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_BLOOD_PRESSURE_MONITOR = 0x04, /**< Blood pressure monitor minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_THERMOMETER = 0x08, /**< Thermometer minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_WEIGHING_SCALE = 0x0C, /**< Weighing scale minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_GLUCOSE_METER = 0x10, /**< Glucose minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_PULSE_OXIMETER = 0x14, /**< Pulse oximeter minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_HEART_PULSE_RATE_MONITOR = 0x18, /**< Heart/Pulse rate monitor minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_DATA_DISPLAY = 0x1C, /**< Health data display minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_STEP_COUNTER = 0x20, /**< Step counter minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_BODY_COMPOSITION_ANALYZER = 0x24, /**< Body composition analyzer minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_PEAK_FLOW_MONITOR = 0x28, /**< Peak flow monitor minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_MEDICATION_MONITOR = 0x2C, /**< Medication monitor minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_KNEE_PROSTHESIS = 0x30, /**< Knee prosthesis minor device class of health */ + BT_MINOR_DEVICE_CLASS_HEALTH_ANKLE_PROSTHESIS = 0x34, /**< Ankle prosthesis minor device class of health */ +} bt_minor_device_class_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enumerations of gap appearance type. + */ +typedef enum +{ + BT_APPEARANCE_TYPE_UNKNOWN = 0x00, /**< Unknown appearance type */ + BT_APPEARANCE_TYPE_GENERIC_PHONE = 0x40, /**< Generic Phone type - Generic category */ + BT_APPEARANCE_TYPE_GENERIC_COMPUTER = 0x80, /**< Generic Computer type - Generic category */ + BT_APPEARANCE_TYPE_GENERIC_WATCH = 0xC0, /**< Generic Watch type - Generic category */ +} bt_appearance_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Enumerations of connected Bluetooth device event role. + */ +typedef enum +{ + BT_SOCKET_UNKNOWN = 0x00, /**< Unknown role*/ + BT_SOCKET_SERVER , /**< Server role*/ + BT_SOCKET_CLIENT, /**< Client role*/ +} bt_socket_role_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Enumerations of Bluetooth socket connection state. + */ +typedef enum +{ + BT_SOCKET_CONNECTED, /**< RFCOMM is connected */ + BT_SOCKET_DISCONNECTED, /**< RFCOMM is disconnected */ +} bt_socket_connection_state_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Enumerations for the types of profiles related with audio + */ +typedef enum { + BT_AUDIO_PROFILE_TYPE_ALL = 0, /**< All supported profiles related with audio */ + BT_AUDIO_PROFILE_TYPE_HSP_HFP, /**< HSP(Headset Profile) and HFP(Hands-Free Profile) */ + BT_AUDIO_PROFILE_TYPE_A2DP, /**< A2DP(Advanced Audio Distribution Profile) */ + BT_AUDIO_PROFILE_TYPE_AG, /**< AG(Audio Gateway) */ +} bt_audio_profile_type_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Enumerations for the call handling event + */ +typedef enum { + BT_AG_CALL_HANDLING_EVENT_ANSWER = 0x00, /**< Request to answer an incoming call */ + BT_AG_CALL_HANDLING_EVENT_RELEASE, /**< Request to release a call */ + BT_AG_CALL_HANDLING_EVENT_REJECT, /**< Request to reject an incoming call */ +} bt_ag_call_handling_event_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Enumerations for the multi call handling event + */ +typedef enum { + BT_AG_MULTI_CALL_HANDLING_EVENT_RELEASE_HELD_CALLS = 0x00, /**< Request to release held calls */ + BT_AG_MULTI_CALL_HANDLING_EVENT_RELEASE_ACTIVE_CALLS, /**< Request to release active calls */ + BT_AG_MULTI_CALL_HANDLING_EVENT_ACTIVATE_HELD_CALL, /**< Request to put active calls into hold state and activate another (held or waiting) call */ + BT_AG_MULTI_CALL_HANDLING_EVENT_MERGE_CALLS, /**< Request to add a held call to the conversation */ + BT_AG_MULTI_CALL_HANDLING_EVENT_EXPLICIT_CALL_TRANSFER, /**< Request to let a user who has two calls to connect these two calls together and release its connections to both other parties */ +} bt_ag_multi_call_handling_event_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Enumerations for the call state + */ +typedef enum { + BT_AG_CALL_EVENT_IDLE = 0x00, /**< Idle */ + BT_AG_CALL_EVENT_ANSWERED, /**< Answered */ + BT_AG_CALL_EVENT_HELD, /**< Held */ + BT_AG_CALL_EVENT_RETRIEVED, /**< Retrieved */ + BT_AG_CALL_EVENT_DIALING, /**< Dialing */ + BT_AG_CALL_EVENT_ALERTING, /**< Alerting */ + BT_AG_CALL_EVENT_INCOMING, /**< Incoming */ +} bt_ag_call_event_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Enumerations for the call state + */ +typedef enum { + BT_AG_CALL_STATE_IDLE = 0x00, /**< Idle state */ + BT_AG_CALL_STATE_ACTIVE, /**< Active state */ + BT_AG_CALL_STATE_HELD, /**< Held state */ + BT_AG_CALL_STATE_DIALING, /**< Dialing state */ + BT_AG_CALL_STATE_ALERTING, /**< Alerting state */ + BT_AG_CALL_STATE_INCOMING, /**< Incoming state */ + BT_AG_CALL_STATE_WAITING, /**< Waiting for connected indication event after answering an incoming call*/ +} bt_ag_call_state_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Enumerations for the equalizer state + */ +typedef enum { + BT_AVRCP_EQUALIZER_STATE_OFF = 0x01, /**< Equalizer Off */ + BT_AVRCP_EQUALIZER_STATE_ON, /**< Equalizer On */ +} bt_avrcp_equalizer_state_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Enumerations for the repeat mode + */ +typedef enum { + BT_AVRCP_REPEAT_MODE_OFF = 0x01, /**< Repeat Off */ + BT_AVRCP_REPEAT_MODE_SINGLE_TRACK, /**< Single track repeat */ + BT_AVRCP_REPEAT_MODE_ALL_TRACK, /**< All track repeat */ + BT_AVRCP_REPEAT_MODE_GROUP, /**< Group repeat */ +} bt_avrcp_repeat_mode_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Enumerations for the shuffle mode + */ +typedef enum { + BT_AVRCP_SHUFFLE_MODE_OFF = 0x01, /**< Shuffle Off */ + BT_AVRCP_SHUFFLE_MODE_ALL_TRACK, /**< All tracks shuffle */ + BT_AVRCP_SHUFFLE_MODE_GROUP, /**< Group shuffle */ +} bt_avrcp_shuffle_mode_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Enumerations for the scan mode + */ +typedef enum { + BT_AVRCP_SCAN_MODE_OFF = 0x01, /**< Scan Off */ + BT_AVRCP_SCAN_MODE_ALL_TRACK, /**< All tracks scan */ + BT_AVRCP_SCAN_MODE_GROUP, /**< Group scan */ +} bt_avrcp_scan_mode_e; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Enumerations for the player state + */ +typedef enum { + BT_AVRCP_PLAYER_STATE_STOPPED = 0x00, /**< Stopped */ + BT_AVRCP_PLAYER_STATE_PLAYING, /**< Playing */ + BT_AVRCP_PLAYER_STATE_PAUSED, /**< Paused */ + BT_AVRCP_PLAYER_STATE_FORWARD_SEEK, /**< Seek Forward */ + BT_AVRCP_PLAYER_STATE_REWIND_SEEK, /**< Seek Rewind */ +} bt_avrcp_player_state_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Enumerations for the data channel type + */ +typedef enum { + BT_HDP_CHANNEL_TYPE_RELIABLE = 0x01, /**< Reliable Data Channel */ + BT_HDP_CHANNEL_TYPE_STREAMING, /**< Streaming Data Channel */ +} bt_hdp_channel_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE + * @brief Enumerations for the types of PAN(Personal Area Networking) service + */ +typedef enum { + BT_PANU_SERVICE_TYPE_NAP = 0, /**< Network Access Point */ +} bt_panu_service_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief The handle to control Bluetooth LE advertising + */ +typedef void* bt_advertiser_h; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief The attribute handle of GATT(Generic Attribute Profile) + */ +typedef void* bt_gatt_attribute_h; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief The handle of calls state + */ +typedef void* bt_call_list_h; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Class structure of device and service. + * + * @see #bt_device_info_s + * @see #bt_adapter_device_discovery_info_s + * @see bt_device_bond_created_cb() + * @see bt_adapter_device_discovery_state_changed_cb() + */ +typedef struct +{ + bt_major_device_class_e major_device_class; /**< Major device class. */ + bt_minor_device_class_e minor_device_class; /**< Minor device class. */ + int major_service_class_mask; /**< Major service class mask. + This value can be a combination of #bt_major_service_class_e like #BT_MAJOR_SERVICE_CLASS_RENDERING | #BT_MAJOR_SERVICE_CLASS_AUDIO */ +} bt_class_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Structure of device discovery information. + * + * @see #bt_class_s + * @see bt_adapter_device_discovery_state_changed_cb() + */ +typedef struct +{ + char *remote_address; /**< The address of remote device */ + char *remote_name; /**< The name of remote device */ + bt_class_s bt_class; /**< The Bluetooth classes */ + int rssi; /**< The strength indicator of received signal */ + bool is_bonded; /**< The bonding state */ + char **service_uuid; /**< The UUID list of service */ + int service_count; /**< The number of services */ + bt_appearance_type_e appearance; /**< The Bluetooth appearance */ + int manufacturer_data_len; /**< manufacturer specific data length */ + char *manufacturer_data; /**< manufacturer specific data */ +} bt_adapter_device_discovery_info_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Structure of le device discovery information. + * + * @see #bt_class_s + * @see bt_adapter_le_device_discovery_state_changed_cb() + */ +typedef struct +{ + char *remote_address; /**< The address of remote device */ + int address_type; /**< The address type of remote device */ + int rssi; /**< The strength indicator of received signal */ + char **service_uuid; /**< The UUID list of service */ + int service_count; /**< The number of services */ + int adv_data_len; /**< advertising indication data length */ + char *adv_data; /**< advertising indication data */ + int scan_data_len; /**< scan response data length */ + char *scan_data; /**< scan response data */ +} bt_adapter_le_device_discovery_info_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Structure of advertising parameters + * + * @see #bt_class_s + * @see bt_adapter_le_advertising_state_changed_cb() + * @see bt_adapter_le_start_advertising() + */ +typedef struct { + float interval_min; /**< Minimum advertising interval for non-directed advertising. + A multiple of 0.625ms is only allowed (Time range : 20ms to 10.24sec). */ + float interval_max; /**< Maximum advertising interval for non-directed advertising. + A multiple of 0.625ms is only allowed (Time range : 20ms to 10.24sec). */ + char filter_policy; /* Advertising filter policy */ + char type; /* Advertising type */ +} bt_adapter_le_advertising_params_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Device information structure used for identifying pear device. + * + * @see #bt_class_s + * @see bt_device_bond_created_cb() + */ +typedef struct +{ + char *remote_address; /**< The address of remote device */ + char *remote_name; /**< The name of remote device */ + bt_class_s bt_class; /**< The Bluetooth classes */ + char **service_uuid; /**< The UUID list of service */ + int service_count; /**< The number of services */ + bool is_bonded; /**< The bonding state */ + bool is_connected; /**< The connection state */ + bool is_authorized; /**< The authorization state */ + int manufacturer_data_len; /**< manufacturer specific data length */ + char *manufacturer_data; /**< manufacturer specific data */ +} bt_device_info_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Service Discovery Protocol (SDP) data structure. + * + * @details This protocol is used for discovering available services or pear device, + * and finding one to connect with. + * + * @see bt_device_service_searched_cb() + */ +typedef struct +{ + char *remote_address; /**< The address of remote device */ + char **service_uuid; /**< The UUID list of service */ + int service_count; /**< The number of services. */ +} bt_device_sdp_info_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Device connection information structure. + * + * @see bt_device_connection_state_changed_cb() + */ +typedef struct +{ + char *remote_address; /**< The address of remote device */ + bt_device_connection_link_type_e link; /**< Link type */ + bt_device_disconnect_reason_e disconn_reason; /**< Disconnection reason */ +} bt_device_connection_info_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Device LE connection update structure. + * + * @see bt_device_le_conn_update() + */ +typedef struct +{ + unsigned int interval_min; /**< Minimum value for the connection event interval (msec) */ + unsigned int interval_max; /**< Maximum value for the connection event interval (msec) */ + unsigned int latency; /**< Slave latency (msec) */ + unsigned int time_out; /**< Supervision timeout (msec) */ +} bt_le_conn_update_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * + * @brief Rfcomm connection data used for exchanging data between Bluetooth devices. + * + * @see bt_socket_connection_state_changed_cb() + */ +typedef struct +{ + int socket_fd; /**< The file descriptor of connected socket */ + int server_fd; /**< The file descriptor of the server socket or -1 for client connection */ + bt_socket_role_e local_role; /**< The local device role in this connection */ + char *remote_address; /**< The remote device address */ + char *service_uuid; /**< The service UUId */ +} bt_socket_connection_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * + * @brief Structure of RFCOMM received data. + * + * @remarks User can use standard linux functions for reading/writing + * data from/to sockets. + * + * @see bt_socket_data_received_cb() + */ +typedef struct +{ + int socket_fd; /**< The socket fd */ + int data_size; /**< The length of the received data */ + char *data; /**< The received data */ +} bt_socket_received_data_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Called when the Bluetooth adapter state changes. + * @param[in] result The result of the adapter state changing + * @param[in] adapter_state The adapter state to be changed + * @param[in] user_data The user data passed from the callback registration function + * @see bt_adapter_set_state_changed_cb() + * @see bt_adapter_unset_state_changed_cb() + */ +typedef void (*bt_adapter_state_changed_cb)(int result, bt_adapter_state_e adapter_state, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Called when adapter name changes. + * @param[in] device_name The name of the Bluetooth device to be changed + * @param[in] user_data The user data passed from the callback registration function + * @pre This function will be invoked when the name of Bluetooth adapter changes + * if you register this callback using bt_adapter_set_name_changed_cb(). + * @see bt_adapter_set_name() + * @see bt_adapter_set_name_changed_cb() + * @see bt_adapter_unset_name_changed_cb() + */ +typedef void (*bt_adapter_name_changed_cb)(char *device_name, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Called when the visibility mode changes. + * @param[in] result The result of the visibility mode changing + * @param[in] visibility_mode The visibility mode to be changed + * @param[in] user_data The user data passed from the callback registration function + * + * @pre This function will be invoked when the visibility of Bluetooth adapter changes + * if you register this callback using bt_adapter_set_visibility_mode_changed_cb(). + * + * @see bt_adapter_set_visibility_mode_changed_cb() + * @see bt_adapter_unset_visibility_mode_changed_cb() + */ +typedef void (*bt_adapter_visibility_mode_changed_cb) + (int result, bt_adapter_visibility_mode_e visibility_mode, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Called every second until the visibility mode is changed to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE. + * @remarks This callback function is called only if visibility mode is #BT_ADAPTER_VISIBILITY_MODE_LIMITED_DISCOVERABLE. + * @param[in] duration The duration until the visibility mode is changed to #BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE (in seconds) + * @param[in] user_data The user data passed from the callback registration function + * @pre This function will be invoked if you register this callback using bt_adapter_set_visibility_duration_changed_cb(). + * @see bt_adapter_set_visibility_duration_changed_cb() + * @see bt_adapter_unset_visibility_duration_changed_cb() + */ +typedef void (*bt_adapter_visibility_duration_changed_cb)(int duration, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Called when the state of device discovery changes. + * + * @remarks If \a discovery_state is #BT_ADAPTER_DEVICE_DISCOVERY_FOUND, + * then you can get some information, such as remote device address, remote device name, rssi, and bonding state. + * + * @param[in] result The result of the device discovery + * @param[in] discovery_state The discovery state to be changed + * @param[in] discovery_info The information of the discovered device \n + * If \a discovery_state is #BT_ADAPTER_DEVICE_DISCOVERY_STARTED or + * #BT_ADAPTER_DEVICE_DISCOVERY_FINISHED, then \a discovery_info is NULL. + * @param[in] user_data The user data passed from the callback registration function + * + * @pre Either bt_adapter_start_device_discovery() or bt_adapter_stop_device_discovery() will invoke this function + * if you register this callback using bt_adapter_set_device_discovery_state_changed_cb(). + * + * @see bt_adapter_start_device_discovery() + * @see bt_adapter_stop_device_discovery() + * @see bt_adapter_set_device_discovery_state_changed_cb() + * @see bt_adapter_unset_device_discovery_state_changed_cb() + * + */ +typedef void (*bt_adapter_device_discovery_state_changed_cb) + (int result, bt_adapter_device_discovery_state_e discovery_state, bt_adapter_device_discovery_info_s *discovery_info, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Called when you get bonded devices repeatedly. + * + * @param[in] device_info The bonded device information + * @param[in] user_data The user data passed from the foreach function + * @return @c true to continue with the next iteration of the loop, + * \n @c false to break out of the loop. + * @pre bt_adapter_foreach_bonded_device() will invoke this function. + * + * @see bt_adapter_foreach_bonded_device() + * + */ +typedef bool (*bt_adapter_bonded_device_cb)(bt_device_info_s *device_info, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Called when the connectable state changes. + * @param[in] result The result of the connectable state changing + * @param[in] connectable The connectable to be changed + * @param[in] user_data The user data passed from the callback registration function + * + * @pre This function will be invoked when the connectable state of local Bluetooth adapter changes + * if you register this callback using bt_adapter_set_connectable_changed_cb(). + * + * @see bt_adapter_set_connectable() + * @see bt_adapter_set_connectable_changed_cb() + * @see bt_adapter_unset_connectable_changed_cb() + */ +typedef void (*bt_adapter_connectable_changed_cb) + (int result, bool connectable, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Called when the state of LE device discovery changes. + * + * @remarks If \a discovery_state is #BT_ADAPTER_LE_DEVICE_DISCOVERY_FOUND, + * then you can get some information, such as remote LE device address, remote device name, rssi, and bonding state. + * + * @param[in] result The result of the LE device discovery + * @param[in] discovery_state The discovery state to be changed + * @param[in] discovery_info The information of the discovered LE device \n + * If \a discovery_state is #BT_ADAPTER_LE_DEVICE_DISCOVERY_STARTED or + * #BT_ADAPTER_LE_DEVICE_DISCOVERY_FINISHED, then \a discovery_info is NULL. + * @param[in] user_data The user data passed from the callback registration function + * + * @pre Either bt_adapter_start_device_discovery() or bt_adapter_stop_device_discovery() will invoke this function + * if you register this callback using bt_adapter_set_device_discovery_state_changed_cb(). + * + * @see bt_adapter_le_start_device_discovery() + * @see bt_adapter_le_stop_device_discovery() + * @see bt_adapter_le_set_device_discovery_state_changed_cb() + * @see bt_adapter_le_unset_device_discovery_state_changed_cb() + * + */ +typedef void (*bt_adapter_le_device_discovery_state_changed_cb) + (int result, bt_adapter_le_device_discovery_state_e discovery_state, bt_adapter_le_device_discovery_info_s *discovery_info, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Called when the state of advertiser changes. + * + * @param[out] result The result of the requested state change of advertiser + * @param[out] advertiser The handle of the state changed advertiser + * @param[out] adv_state The advertiser state to be changed + * @param[out] user_data The user data passed from the start function + * + * @see bt_adapter_le_start_advertiser() + * @see bt_adapter_le_stop_advertiser() + */ +typedef void (*bt_adapter_le_advertising_state_changed_cb)(int result, + bt_advertiser_h advertiser, bt_adapter_le_advertising_state_e adv_state, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Called when the Bluetooth adapter le state changes. + * @param[in] result The result of the adapter state changing + * @param[in] adapter_le_state The adapter le state to be changed + * @param[in] user_data The user data passed from the callback registration function + * @pre Either bt_adapter_le_enable() or bt_adapter_le_disable() will invoke this callback if you register this callback using bt_adapter_le_set_state_changed_cb(). + * @see bt_adapter_le_enable() + * @see bt_adapter_le_disable() + * @see bt_adapter_le_set_state_changed_cb() + * @see bt_adapter_le_unset_state_changed_cb() + */ +typedef void (*bt_adapter_le_state_changed_cb)(int result, bt_adapter_le_state_e adapter_le_state, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Called when the process of creating bond finishes. + * @remarks If the remote user does not respond within 60 seconds, a time out will happen with #BT_ERROR_TIMED_OUT result code.\n + * If bt_device_cancel_bonding() is called and it returns #BT_ERROR_NONE, then this callback function will be called + * with #BT_ERROR_CANCELLED result. \n + * If creating a bond succeeds but service search fails, then this callback will be called with #BT_ERROR_SERVICE_SEARCH_FAILED. + * In this case, you should try service search again by bt_device_start_service_search() to get the supported service list. + * + * @param[in] result The result of the bonding device + * @param[in] device_info The device information which you creates bond with + * @param[in] user_data The user data passed from the callback registration function + * + * @pre Either bt_device_create_bond() will invoke this function + * if you register this callback using bt_device_set_bond_created_cb(). + * + * @see bt_device_create_bond() + * @see bt_device_cancel_bonding() + * @see bt_device_set_bond_created_cb() + * @see bt_device_unset_bond_created_cb() + */ +typedef void (*bt_device_bond_created_cb)(int result, bt_device_info_s *device_info, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Called when you get connected profiles repeatedly. + * @param[in] profile The connected Bluetooth profile + * @param[in] user_data The user data passed from the foreach function + * @return @c true to continue with the next iteration of the loop, + * \n @c false to break out of the loop. + * @pre bt_device_foreach_connected_profiles() will invoke this function. + * @see bt_device_foreach_connected_profiles() + */ +typedef bool (*bt_device_connected_profile)(bt_profile_e profile, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Called when the bond destroys. + * @param[in] result The result that a bond is destroyed + * @param[in] remote_address The address of the remote Bluetooth device to destroy bond with + * @param[in] user_data The user data passed from the callback registration function + * @pre bt_device_destroy_bond() will invoke this function + * if you register this callback using bt_device_set_bond_destroyed_cb(). + * + * @see bt_device_destroy_bond() + * @see bt_device_set_bond_destroyed_cb() + * @see bt_device_unset_bond_destroyed_cb() + */ +typedef void (*bt_device_bond_destroyed_cb)(int result, char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Called when the authorization of device changes. + * @param[in] authorization The authorization of device + * @param[in] remote_address The address of the remote Bluetooth device which is (un)authorized + * @param[in] user_data The user data passed from the callback registration function + * @pre bt_device_set_authorization() will invoke this function if you register this callback using bt_device_set_authorization_changed_cb(). + * + * @see bt_device_set_authorization() + * @see #bt_device_set_authorization_changed_cb() + * @see #bt_device_unset_authorization_changed_cb() + */ +typedef void (*bt_device_authorization_changed_cb) + (bt_device_authorization_e authorization, char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Called when the process of service search finishes. + * @remark If bt_device_cancel_service_search() is called and it returns #BT_ERROR_NONE, + * then this callback function will be called with #BT_ERROR_CANCELLED result. + * + * @param[in] result The result of the service searching + * @param[in] sdp_info The structure of service lists found on a device + * @param[in] user_data The user data passed from the callback registration function + * @pre Either bt_device_start_service_search() will invoke this function + * if you register this callback using bt_device_set_service_searched_cb(). + * + * @see bt_device_start_service_search() + * @see bt_device_cancel_service_search() + * @see bt_device_set_service_searched_cb() + * @see bt_device_unset_service_searched_cb() + * + */ +typedef void (*bt_device_service_searched_cb)(int result, bt_device_sdp_info_s *sdp_info, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Called when the connection state is changed. + * @param[in] connected The connection status: (@c true = connected, @c false = disconnected) + * @param[in] conn_info The connection information + * @param[in] user_data The user data passed from the callback registration function + * @see bt_device_set_connection_state_changed_cb() + * @see bt_device_unset_connection_state_changed_cb() + */ +typedef void (*bt_device_connection_state_changed_cb)(bool connected, bt_device_connection_info_s *conn_info, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Called when you receive data. + * + * @param[in] data The received data from the remote device + * @param[in] user_data The user data passed from the callback registration function + * + * @pre When the connected remote Bluetooth device invokes bt_socket_send_data(), + * this function will be invoked if you register this function using bt_socket_set_data_received_cb(). + * + * @see bt_socket_set_data_received_cb() + * @see bt_socket_unset_data_received_cb() + * @see bt_socket_send_data() + */ +typedef void (*bt_socket_data_received_cb)(bt_socket_received_data_s *data, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Called when the socket connection state changes. + * @param[in] result The result of connection state changing + * @param[in] connection_state The connection state + * @param[in] connection The connection information which is established or disconnected + * @param[in] user_data The user data passed from the callback registration function + * @pre Either bt_socket_connect_rfcomm() will invoke this function. + * In addtion, bt_socket_connection_state_changed_cb() will be invoked when the socket connection state is changed. + * @see bt_socket_listen_and_accept_rfcomm() + * @see bt_socket_connect_rfcomm() + * @see bt_socket_set_connection_state_changed_cb() + * @see bt_socket_unset_connection_state_changed_cb() + */ +typedef void (*bt_socket_connection_state_changed_cb) + (int result, bt_socket_connection_state_e connection_state, bt_socket_connection_s *connection, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_SOCKET_MODULE + * @brief Called when a RFCOMM connection is requested. + * @details You must call bt_socket_accept() if you want to accept. Otherwise, you must call bt_socket_reject(). + * @param[in] socket_fd The file descriptor of socket on which a connection is requested + * @param[in] remote_address The address of remote device + * @param[in] user_data The user data passed from the callback registration function + * @pre If you register this callback function by bt_socket_set_connection_requested_cb() and listen a socket by bt_socket_listen(), + * bt_socket_connection_requested_cb() will be invoked. + * @see bt_socket_listen() + * @see bt_socket_accept() + * @see bt_socket_reject() + */ +typedef void (*bt_socket_connection_requested_cb) (int socket_fd, const char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Called when the push is requested. + * @details You must call bt_opp_server_accept() if you want to accept. + * Otherwise, you must call bt_opp_server_reject(). + * @param[in] file The path of file to be pushed + * @param[in] size The file size (bytes) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_opp_server_initialize() + */ +typedef void (*bt_opp_server_push_requested_cb)(const char *file, int size, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Called when an OPP connection is requested. + * @details You must call bt_opp_server_accept_connection() if you want to accept. + * Otherwise, you must call bt_opp_server_reject_connection(). + * @param[in] remote_address The address of remote device + * @param[in] user_data The user data passed from the callback registration function + * @see bt_opp_server_initialize() + * @see bt_opp_server_accept_connection() + * @see bt_opp_server_reject_connection() + */ +typedef void (*bt_opp_server_connection_requested_cb)(const char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Called when a file is being transfered. + * @param[in] file The path of file to be pushed + * @param[in] size The file size (bytes) + * @param[in] percent The progress in percentage (1 ~ 100) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_opp_server_accept() + * @see bt_opp_server_accept_connection() + */ +typedef void (*bt_opp_server_transfer_progress_cb) (const char *file, long long size, int percent, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE + * @brief Called when a transfer is finished. + * @param[in] error_code The result of push + * @param[in] file The path of file to be pushed + * @param[in] size The file size (bytes) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_opp_server_accept() + * @see bt_opp_server_accept_connection() + */ +typedef void (*bt_opp_server_transfer_finished_cb) (int result, const char *file, long long size, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Called when OPP server responds to the push request. + * @param[in] result The result of OPP server response + * @param[in] remote_address The remote address + * @param[in] user_data The user data passed from the callback registration function + * @pre bt_opp_client_push_files() will invoke this function. + * @see bt_opp_client_push_files() + */ +typedef void (*bt_opp_client_push_responded_cb)(int result, const char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Called when each file is being transfered. + * @param[in] file The path of file to be pushed + * @param[in] size The file size (bytes) + * @param[in] percent The progress in percentage (1 ~ 100). 100 means that a file is transfered completely. + * @param[in] user_data The user data passed from the callback registration function + * @pre bt_opp_client_push_files() will invoke this function. + * @see bt_opp_client_push_files() + */ +typedef void (*bt_opp_client_push_progress_cb)(const char *file, long long size, int percent, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_CLIENT_MODULE + * @brief Called when the push request is finished. + * @param[in] result The result of the push request + * @param[in] remote_address The remote address + * @param[in] user_data The user data passed from the callback registration function + * @see bt_opp_client_push_files() + */ +typedef void (*bt_opp_client_push_finished_cb)(int result, const char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_MODULE + * @brief Called when the connection state is changed. + * @details This callback is called when the connection state is changed. + * When you call bt_audio_connect() or bt_audio_disconnect(), this callback is also called with error result even though these functions fail. + * @param[in] result The result of changing the connection state + * @param[in] connected The state to be changed. @a true means connected state, Otherwise, @a false. + * @param[in] remote_address The remote address + * @param[in] type The type of audio profile except #BT_AUDIO_PROFILE_TYPE_ALL + * @param[in] user_data The user data passed from the callback registration function + * @see bt_audio_set_connection_state_changed_cb() + * @see bt_audio_unset_connection_state_changed_cb() + */ +typedef void (*bt_audio_connection_state_changed_cb) (int result, bool connected, const char *remote_address, bt_audio_profile_type_e type, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Called when the SCO(Synchronous Connection Oriented link) state is changed. + * @details This callback is called when the SCO state is changed. + * When you call bt_ag_open_sco() or bt_ag_close_sco(), this callback is also called with error result even though these functions failed. + * @param[in] result The result of changing the connection state + * @param[in] opened The state to be changed: (@c true = opened, @c false = not opened) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_ag_set_sco_state_changed_cb() + * @see bt_ag_unset_sco_state_changed_cb() + * @see bt_ag_open_sco() + * @see bt_ag_close_sco() + */ +typedef void (*bt_ag_sco_state_changed_cb) (int result, bool opened, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Called when a call handling event happened from Hands-Free. + * @param[in] event The call handling event happened from Hands-Free + * @param[in] call_id The call ID + * @param[in] user_data The user data passed from the callback registration function + * @see bt_ag_set_call_handling_event_cb() + * @see bt_ag_unset_call_handling_event_cb() + */ +typedef void (*bt_ag_call_handling_event_cb) (bt_ag_call_handling_event_e event, unsigned int call_id, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Called when a multi call handling event happened from Hands-Free. + * @param[in] event The call handling event happened from Hands-Free + * @param[in] user_data The user data passed from the callback registration function + * @see bt_ag_set_multi_call_handling_event_cb() + * @see bt_ag_unset_multi_call_handling_event_cb() + */ +typedef void (*bt_ag_multi_call_handling_event_cb) (bt_ag_multi_call_handling_event_e event, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Called when a DTMF(Dual Tone Multi Frequency) is transmitted from Hands-Free. + * @param[in] dtmf The DTMF transmitted from Hands-Free + * @param[in] user_data The user data passed from the callback registration function + * @see bt_ag_set_dtmf_transmitted_cb() + * @see bt_ag_unset_dtmf_transmitted_cb() + */ +typedef void (*bt_ag_dtmf_transmitted_cb) (const char *dtmf, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Called when the speaker gain of the remote device is changed. + * @param[in] gain The gain of speaker (0 ~ 15) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_ag_set_speaker_gain_changed_cb() + * @see bt_ag_unset_speaker_gain_changed_cb() + */ +typedef void (*bt_ag_speaker_gain_changed_cb) (int gain, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Called when the microphone gain of the remote device is changed. + * @param[in] gain The gain of microphone (0 ~ 15) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_ag_set_microphone_gain_changed_cb() + * @see bt_ag_unset_microphone_gain_changed_cb() + */ +typedef void (*bt_ag_microphone_gain_changed_cb) (int gain, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Called when the connection state is changed. + * @param[in] connected The state to be changed. @a true means connected state, Otherwise, @a false. + * @param[in] remote_address The remote address + * @param[in] user_data The user data passed from the callback registration function + * @see bt_avrcp_target_initialize() + * @see bt_avrcp_target_deinitialize() + */ +typedef void (*bt_avrcp_target_connection_state_changed_cb) (bool connected, const char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Called when the equalizer state is changed by the remote control device. + * @param[in] equalizer The equalizer state + * @param[in] user_data The user data passed from the callback registration function + * @see bt_avrcp_set_equalizer_state_changed_cb() + * @see bt_avrcp_unset_equalizer_state_changed_cb() + */ +typedef void (*bt_avrcp_equalizer_state_changed_cb) (bt_avrcp_equalizer_state_e equalizer, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Called when the repeat mode is changed by the remote control device. + * @param[in] repeat The repeat mode + * @param[in] user_data The user data passed from the callback registration function + * @see bt_avrcp_set_repeat_mode_changed_cb() + * @see bt_avrcp_unset_repeat_mode_changed_cb() + */ +typedef void (*bt_avrcp_repeat_mode_changed_cb) (bt_avrcp_repeat_mode_e repeat, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Called when the shuffle mode is changed by the remote control device. + * @param[in] shuffle The shuffle mode + * @param[in] user_data The user data passed from the callback registration function + * @see bt_avrcp_set_shuffle_mode_changed_cb() + * @see bt_avrcp_unset_shuffle_mode_changed_cb() + */ +typedef void (*bt_avrcp_shuffle_mode_changed_cb) (bt_avrcp_shuffle_mode_e shuffle, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AVRCP_MODULE + * @brief Called when the scan mode is changed by the remote control device. + * @param[in] shuffle The shuffle mode + * @param[in] user_data The user data passed from the callback registration function + * @see bt_avrcp_set_scan_mode_changed_cb() + * @see bt_avrcp_unset_scan_mode_changed_cb() + */ +typedef void (*bt_avrcp_scan_mode_changed_cb) (bt_avrcp_scan_mode_e scan, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Called when the connection state is changed. + * @details This callback is called when the connection state is changed. + * When you call bt_hid_host_connect() or bt_hid_host_disconnect(), this callback is also called with error result even though these functions fail. + * @param[in] result The result of changing the connection state + * @param[in] connected The state to be changed. @a true means connected state, Otherwise, @a false. + * @param[in] remote_address The remote address + * @param[in] user_data The user data passed from the callback registration function + * @see bt_hid_host_connect() + * @see bt_hid_host_disconnect() + */ +typedef void (*bt_hid_host_connection_state_changed_cb) (int result, bool connected, const char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Called when the connection is established. + * @param[in] result The result of connecting to the remote device + * @param[in] remote_address The address of connected remote device + * @param[in] app_id The ID of application + * @param[in] type The type of HDP(Health Device Profile) channel + * @param[in] channel The connected data channel + * @param[in] user_data The user data passed from the callback registration function + * @see bt_hdp_disconnected_cb + * @see bt_hdp_set_connection_state_changed_cb() + * @see bt_hdp_unset_connection_state_changed_cb() + */ +typedef void (*bt_hdp_connected_cb) (int result, const char *remote_address, const char *app_id, + bt_hdp_channel_type_e type, unsigned int channel, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Called when the connection is disconnected. + * @param[in] result The result of disconnecting from the remote device + * @param[in] remote_address The address of disconnected remote device + * @param[in] channel The connected data channel + * @param[in] user_data The user data passed from the callback registration function + * @see bt_hdp_connected_cb + * @see bt_hdp_set_connection_state_changed_cb() + * @see bt_hdp_unset_connection_state_changed_cb() + */ +typedef void (*bt_hdp_disconnected_cb) (int result, const char *remote_address, unsigned int channel, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HDP_MODULE + * @brief Called when the you receive the data. + * @param[in] channel The connected data channel + * @param[in] data The received data + * @param[in] size The size of received data (byte) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_hdp_set_data_received_cb() + * @see bt_hdp_unset_data_received_cb() + */ +typedef void (*bt_hdp_data_received_cb) (unsigned int channel, const char *data, unsigned int size, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when you get the primary services repeatedly. + * @param[in] service The attribute handle of service + * @param[in] index The index of a service, starts from 0 + * @param[in] total The total number of services + * @param[in] user_data The user data passed from the foreach function + * @return @c true to continue with the next iteration of the loop, + * \n @c false to break out of the loop. + * @pre bt_gatt_foreach_primary_services() will invoke this function. + * @see bt_gatt_foreach_primary_services() + */ +typedef bool (*bt_gatt_primary_service_cb) (bt_gatt_attribute_h service, int index, int total, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called after the characteristics are discovered by bt_gatt_discover_characteristics(). + * @remarks If bt_gatt_discover_characteristics() failed, then this callback function is called only once with 0 totla and NULL characteristic_handle. + * @param[in] result The result of discovering + * @param[in] index The index of characteristics in a service, starts from 0 + * @param[in] total The total number of characteristics in a service + * @param[in] characteristic The attribute handle of characteristic + * @param[in] user_data The user data passed from the request function + * @return @c true to continue with the next iteration of the loop, + * \n @c false to break out of the loop. + * @pre bt_gatt_discover_characteristics() will invoke this callback. + * @see bt_gatt_discover_characteristics() + */ +typedef bool (*bt_gatt_characteristics_discovered_cb) (int result, int index, int total, bt_gatt_attribute_h characteristic, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when you get the included services repeatedly. + * @param[in] service The attribute handle of service + * @param[in] user_data The user data passed from the foreach function + * @return @c true to continue with the next iteration of the loop, + * \n @c false to break out of the loop. + * @pre bt_gatt_foreach_included_services() will invoke this function. + * @see bt_gatt_foreach_included_services() + */ +typedef bool (*bt_gatt_included_service_cb) (bt_gatt_attribute_h service, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when a characteristic in service is changed. + * @param[in] characteristic The attribute handle of characteristic + * @param[in] value The value of characteristic (byte array) + * @param[in] value_length The length of value + * @param[in] user_data The user data passed from the callback registration function + * @see bt_gatt_set_characteristic_changed_cb() + * @see bt_gatt_unset_characteristic_changed_cb() + */ +typedef void (*bt_gatt_characteristic_changed_cb) (bt_gatt_attribute_h characteristic, unsigned char *value, int value_length, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when a characteristic value is written. + * @see bt_gatt_set_characteristic_value() + */ +typedef void (*bt_gatt_characteristic_write_cb) (int result, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when a characteristic value is read. + * @param[in] value The value of characteristic (byte array) + * @param[in] value_length The length of value + * @param[in] user_data The user data passed from the foreach function + * @see bt_gatt_read_characteristic_value() + */ +typedef void (*bt_gatt_characteristic_read_cb) (unsigned char *value, + int value_length, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called after the characteristics descriptors are discovered by bt_gatt_discover_characteristic_descriptor(). + * @param[in] result The result of discovering + * @param[in] characteristic_format The format of the information data. + * characteristic_format = 0x01 indicates UUIDs are 16-bits + * characteristic_format = 0x02 indicates UUIDs are 128-bits + * @param[in] total The total number of elements in characteristic_descriptor + * @param[in] characteristic descriptor The attribute handle and the UUID of characteristic descriptor + * @param[in] characteristic The attribute handle and the UUID of characteristic + * @param[in] user_data The user data passed from the request function + * @see bt_gatt_discover_characteristic_descriptor() + */ +typedef void (*bt_gatt_characteristic_descriptor_discovered_cb) (int result, + unsigned char characteristic_format, int total, + bt_gatt_attribute_h characteristic_descriptor, + bt_gatt_attribute_h characteristic, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when the connection state is changed. + * @details This callback is called when the connection state is changed. + * When you called bt_gatt_connect() or bt_gatt_disconnect(), this callback is also called with error result even though these functions fail. + * + * @param[in] result The result of changing the connection state. + * @param[in] connected The state to be changed, @a true means connected state, Otherwise, @a false. + * @param[in] remote_address The remote_address + * @param[in] user_data The user data passed from the callback registration function. + * + * @see bt_gatt_connect() + * @see bt_gatt_disconnect() + * @see bt_gatt_set_connection_state_changed_cb() + * @see bt_gatt_unset_connection_state_changed_cb() + */ +typedef void (*bt_gatt_connection_state_changed_cb)(int result, bool connected, const char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Called when the remote devices writes a characteristic to the server db. + * @details This callback is called when the remote client device writes a characteristics + * to the server attribute database. + * + * @param[in] char_path Characteristic path for which the value is writtten. + * @param[in] char_value The characteristic value + * @param[in] value_length The length of the characteristic value written. + * + * @see bt_gatt_connect() + */ +typedef void (*bt_gatt_remote_characteristic_write_cb) (char *char_path, + unsigned char* char_value, int value_length, + void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_NAP_MODULE + * @brief Called when the connection state is changed. + * @param[in] connected Indicates whether a client is connected or disconnected + * @param[in] remote_address The remote address + * @param[in] interface_name The interface name. For example, bnep0, bnep1. + * @param[in] user_data The user data passed from the callback registration function + * @see bt_nap_set_connection_state_changed_cb() + * @see bt_nap_unset_connection_state_changed_cb() + */ +typedef void (*bt_nap_connection_state_changed_cb) (bool connected, const char *remote_address, const char *interface_name, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_PAN_PANU_MODULE + * @brief Called when the connection state is changed. + * @details This callback is called when the connection state is changed. + * When you call bt_panu_connect() or bt_panu_disconnect(), this callback is also called with error result even though these functions fail. + * @param[in] result The result of changing the connection state + * @param[in] connected The state to be changed. @a true means connected state, Otherwise, @a false. + * @param[in] remote_address The remote address + * @param[in] type The type of PAN service + * @param[in] user_data The user data passed from the callback registration function + * @see bt_nap_set_connection_state_changed_cb() + * @see bt_nap_unset_connection_state_changed_cb() + */ +typedef void (*bt_panu_connection_state_changed_cb) (int result, bool connected, const char *remote_address, bt_panu_service_type_e type, void *user_data); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // __TIZEN_NETWORK_BLUETOOTH_TYPE_H__ diff --git a/resource/csdk/connectivity/lib/tizen/ble/inc/mobile/bluetooth_product.h b/resource/csdk/connectivity/lib/tizen/ble/inc/mobile/bluetooth_product.h new file mode 100644 index 0000000..661a950 --- /dev/null +++ b/resource/csdk/connectivity/lib/tizen/ble/inc/mobile/bluetooth_product.h @@ -0,0 +1,314 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd 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 __TIZEN_NETWORK_BLUETOOTH_PRODUCT_H__ +#define __TIZEN_NETWORK_BLUETOOTH_PRODUCT_H__ + +#include "bluetooth_type.h" +#include "bluetooth_type_product.h" + +#ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +/** + * @file bluetooth_product.h + */ + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Sets the manufacturer data of local Bluetooth adapter. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @param[in] data The manufacturer specific data of the Bluetooth device. + * @param[in] len The length of @a data.Maximaum length is 240 bytes. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @post bt_adapter_manufacturer_data_changed_cb() will be invoked + * if this function returns #BT_ERROR_NONE. + * + * @see bt_adapter_manufacturer_data_changed_cb + * @see bt_adapter_set_manufacturer_data_changed_cb() + * @see bt_adapter_unset_manufacturer_data_changed_cb() + */ +int bt_adapter_set_manufacturer_data(char *data, int len); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Registers a callback function to be invoked + * when the manufacturer data of Bluetooth adapter changes. + * @since_tizen 2.3 + * + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @post bt_adapter_manufacturer_data_changed_cb() will be invoked. + * + * @see bt_initialize() + * @see bt_adapter_unset_manufacturer_data_changed_cb() + */ +int bt_adapter_set_manufacturer_data_changed_cb( + bt_adapter_manufacturer_data_changed_cb callback, + void *user_data); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Unregisters the callback function. + * @since_tizen 2.3 + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_initialize() + * @see bt_adapter_set_manufacturer_data_changed_cb() + */ +int bt_adapter_unset_manufacturer_data_changed_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Sets the scan interval and widow, synchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] scan_params The parameters of le scanning \n + * If NULL is passed, default values which are defined in driver / controller are used. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_ENABLED Adapter is not enabled + * @retval #BT_ERROR_INVALID_PARAM Parameter is invalid + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + */ +int bt_adapter_le_set_scan_parameter(bt_adapter_le_scan_params_s *scan_params); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Enables RSSI monitoring and sets threshold for LE/ACL link present with the remote device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @param[in] remote_address The address of the remote Bluetooth device for which RSSI is to be monitored + * @param[in] link_type Link type for the connection (@c 0 = BR/EDR link, @c 1 = LE link). + * @param[in] low_threshold Lower threshold value for the LE Link in dBm. + * @param[in] in_range_threshold In-Range threshold value for the LE Link in dBm. + * @param[in] cb_enable Callback to be called when RSSI monitoring is enabled. + * @param[in] user_data_enable Data to be passed to RSSI enable callback. + * @param[in] cb_alert Callback to receive RSSI Alert values. + * @param[in] user_data_alert Data to be passed to RSSI Alert callback. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * + * @remarks High Threshold value is set to 127. + * + * @see bt_device_unset_rssi_alert_cb() + * @see bt_device_disable_rssi_monitor() + */ +int bt_device_enable_rssi_monitor(const char *remote_address, + bt_device_connection_link_type_e link_type, + int low_threshold, int in_range_threshold, + bt_rssi_monitor_enabled_cb cb_enable, void *user_data_enable, + bt_rssi_alert_cb cb_alert, void *user_data_alert); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Disables RSSI monitoring for LE/ACL link present with the remote device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @param[in] remote_address The address of the remote Bluetooth device for which RSSI monitoring is to be disabled + * @param[in] link_type Link type for the connection (@c 0 = BR/EDR link, @c 1 = LE link). + * @param[in] cb_disable Callback to be called when RSSI monitoring is disabled. + * @param[in] user_data_enable Data to be passed to RSSI enable callback. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * + * @remarks Low Threshold, In-range Threshold and High Threshold value are set to 0 to disable RSSI monitoring. + * @remarks This also calls bt_device_unset_rssi_alert_cb() + * + * @see bt_device_unset_rssi_alert_cb() + * @see bt_device_enable_rssi_monitor() + */ +int bt_device_disable_rssi_monitor(const char *remote_address, + bt_device_connection_link_type_e link_type, + bt_rssi_monitor_enabled_cb cb_disable, void *user_data_disable); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Get Raw RSSI for LE link present with the remote device. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @param[in] remote_address The address of the remote Bluetooth device for which RSSI is to be monitored + * @param[in] link_type Link type for the connection (@c 0 = BR/EDR link, @c 1 = LE link). + * @param[in] callback Callback to receive Raw RSSI values. + * @param[in] user_data Data to be passed to Raw RSSI callback. + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * + * @see bt_device_le_unset_rssi_strength_cb() + */ +int bt_device_get_rssi_strength(const char *remote_address, + bt_device_connection_link_type_e link_type, + bt_rssi_strength_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Unset the callback to receive RSSI Alert values. + * @since_tizen 2.3 + * + * @return 0 on success, otherwise a negative error value. + * + * @see bt_device_le_enable_rssi() + */ +int bt_device_unset_rssi_alert_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Notifies the XSAT vendor command to the remote. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] state The XSAT vendor dependent command string. Ex: "AT+SAT= 00,TY,WA" + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_BONDED Remote device is not bonded + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @pre The Bluetooth audio device must be connected with bt_audio_connect(). + * @see bt_audio_connect() + */ +int bt_ag_notify_vendor_cmd(const char *command); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Registers a callback function that will be invoked when a XSATvendor AT command is transmitted from Hands-Free. + * @since_tizen 2.3 + * @param[in] callback The callback function to register + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_vendor_cmd_cb() + * @see bt_ag_unset_vendor_cmd_cb() + */ +int bt_ag_set_vendor_cmd_cb(bt_ag_vendor_cmd_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Unregisters a callback function that will be invoked when a XSATvendor AT command is transmitted from Hands-Free + * @since_tizen 2.3 + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @pre The Bluetooth audio service must be initialized with bt_audio_initialize(). + * @see bt_audio_initialize() + * @see bt_ag_vendor_cmd_cb() + * @see bt_ag_set_vendor_cmd_cb() + */ +int bt_ag_unset_vendor_cmd_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Checks whether the remoted device is wbs (Wide Band Speech) mode or not. + * @since_tizen 2.3 + * @param[out] wbs_mode The wbs status: (@c true = wide band speech, @c false = narrow band speech) + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @pre The remote device is connected by bt_audio_connect() with #BT_AUDIO_PROFILE_TYPE_HSP_HFP service. + * @see bt_audio_connect() + */ +int bt_ag_is_wbs_mode(bool *wbs_mode); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_A2DP_MODULE + * @brief Sets copy protection. streaming application that needs to have the copy protection for the streaming data, shall invoke this API. + * @since_tizen 2.3 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @param[in] status - TRUE/FALSE + * @return 0 on success, otherwise negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_OPERATION_FAILED on failure + */ +int bt_a2dp_set_content_protection(bool status); + + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // __TIZEN_NETWORK_BLUETOOTH_PRODUCT_H__ diff --git a/resource/csdk/connectivity/lib/tizen/ble/inc/mobile/bluetooth_type_product.h b/resource/csdk/connectivity/lib/tizen/ble/inc/mobile/bluetooth_type_product.h new file mode 100644 index 0000000..699da5e --- /dev/null +++ b/resource/csdk/connectivity/lib/tizen/ble/inc/mobile/bluetooth_type_product.h @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd 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 __TIZEN_NETWORK_BLUETOOTH_TYPE_PRODUCT_H__ +#define __TIZEN_NETWORK_BLUETOOTH_TYPE_PRODUCT_H__ + + #ifdef __cplusplus +extern "C" +{ +#endif /* __cplusplus */ + +/** + * @file bluetooth_type_product.h + */ + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Enumerations of the Bluetooth adapter le scan type. + */ +typedef enum +{ + BT_ADAPTER_LE_PASSIVE_SCAN = 0x00, + BT_ADAPTER_LE_ACTIVE_SCAN +} bt_adapter_le_scan_type_e; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Structure of le scan parameters + * + * @see bt_adapter_le_set_scan_parameter() + * @see bt_adapter_le_start_device_discovery() + */ +typedef struct { + bt_adapter_le_scan_type_e type; /**< LE scan type */ + float interval; /**< LE scan interval */ + float window; /**< LE scan window */ +} bt_adapter_le_scan_params_s; + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Called when the manufacturer dat changes. + * @param[in] data The manufacurer data of the Bluetooth device to be changed + * @param[in] len The length of @a data + * @param[in] user_data The user data passed from the callback registration function + * @pre This function will be invoked when the manufacturer data of Bluetooth adapter changes + * if callback is registered using bt_adapter_set_manufacturer_data_changed_cb(). + * @see bt_adapter_set_manufacturer_data() + * @see bt_adapter_set_manufacturer_data_changed_cb() + * @see bt_adapter_unset_manufacturer_data_changed_cb() + */ +typedef void (*bt_adapter_manufacturer_data_changed_cb) (char *data, + int len, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Called when RSSI monitoring is enabled. + * @param[in] remote_address Remote Device address + * @param[in] link_type Link type for the connection (@c 0 = BR/EDR link, @c 1 = LE link). + * @param[in] rssi_enabled RSSI monitoring status (@c 1 = enabled, @c 0 = disabled) + * @param[in] user_data The user data passed from the callback registration function + * @see bt_device_enable_rssi_monitor() + * @see bt_device_disable_rssi_monitor() + */ +typedef void (*bt_rssi_monitor_enabled_cb)(const char *remote_address, + bt_device_connection_link_type_e link_type, + int rssi_enabled, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Called when RSSI Alert is received. + * @param[in] remote_address Remote Device address + * @param[in] link_type Link type for the connection (@c 0 = BR/EDR link, @c 1 = LE link). + * @param[in] rssi_alert_type RSSI Alert type (@c 1 = High Alert (In-Range Alert), @c 2 = Low Alert) + * @param[in] rssi_alert_dbm RSSI Alert signal strength value + * @param[in] user_data The user data passed from the callback registration function + * @see bt_device_enable_rssi_monitor() + * @see bt_device_disable_rssi_monitor() + */ +typedef void (*bt_rssi_alert_cb)(char *bt_address, + bt_device_connection_link_type_e link_type, + int rssi_alert_type, int rssi_alert_dbm, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Called when Raw RSSI signal strength is received. + * @param[in] remote_address Remote Device address + * @param[in] link_type Link type for the connection (@c 0 = BR/EDR link, @c 1 = LE link). + * @param[in] rssi_dbm Raw RSSI signal strength value + * @param[in] user_data The user data passed from the callback registration function + * @see bt_device_get_rssi_strength() + */ +typedef void (*bt_rssi_strength_cb)(char *bt_address, + bt_device_connection_link_type_e link_type, + int rssi_dbm, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_AUDIO_AG_MODULE + * @brief Called when a XSAT vendor command is transmitted from Hands-Free. + * @param[in] command The XSAT vendor command transmitted from Hands-Free + * @param[in] user_data The user data passed from the callback registration function + * @see bt_ag_set_vendor_cmd_cb() + * @see bt_ag_unset_vendor_cmd_cb() + */ +typedef void (*bt_ag_vendor_cmd_cb) (char *command, void *user_data); + + +/** + * @} + */ + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // __TIZEN_NETWORK_BLUETOOTH_TYPE_PRODUCT_H__ diff --git a/resource/csdk/connectivity/samples/android/sample_app/Makefile b/resource/csdk/connectivity/samples/android/sample_app/Makefile deleted file mode 100644 index ae9fca9..0000000 --- a/resource/csdk/connectivity/samples/android/sample_app/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -#Assumes ndk directory is at ~/ -#set ndk directory PATH in .bashrc and use the ndk-build directly -NDK_PATH = ~/ndk -NDK_BUILD = $(NDK_PATH)/ndk-build - -BUILD_DIR = $(CURDIR) -APPLICATION_BUILD = $(BUILD_DIR) -ROOT_DIR = $(BUILD_DIR) - -#Clean files -LIBS_DIR = $(ROOT_DIR)/libs -OBJ_DIR = $(ROOT_DIR)/obj - -all: - $(NDK_BUILD) NDK_PROJECT_PATH=$(APPLICATION_BUILD) - -clean : - @$(RM) -rf $(LIBS_DIR) $(OBJ_DIR) \ No newline at end of file diff --git a/resource/csdk/connectivity/samples/android/sample_app/jni/Android.mk b/resource/csdk/connectivity/samples/android/sample_app/jni/Android.mk deleted file mode 100644 index 91c18d9..0000000 --- a/resource/csdk/connectivity/samples/android/sample_app/jni/Android.mk +++ /dev/null @@ -1,24 +0,0 @@ -APP_PATH := $(call my-dir) - -#specify project root path here wrt make file directory -PROJECT_ROOT_PATH = ../../.. -PROJECT_API_PATH = $(PROJECT_ROOT_PATH)/api - -#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -#Build sample_main -include $(CLEAR_VARS) -LOCAL_PATH = $(APP_PATH) -LOCAL_MODULE = sample -LOCAL_C_INCLUDES = $(PROJECT_API_PATH) -LOCAL_STATIC_LIBRARIES = CA -LOCAL_SRC_FILES = sample_main.c -include $(BUILD_EXECUTABLE) -#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -#Build glib CACommon CACoap CA -include $(CLEAR_VARS) -PROJECT_LIB_PATH = $(PROJECT_ROOT_PATH)/build/android -include $(PROJECT_LIB_PATH)/jni/Android.mk -#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - diff --git a/resource/csdk/connectivity/samples/android/sample_app/jni/Application.mk b/resource/csdk/connectivity/samples/android/sample_app/jni/Application.mk deleted file mode 100644 index 40d9615..0000000 --- a/resource/csdk/connectivity/samples/android/sample_app/jni/Application.mk +++ /dev/null @@ -1,6 +0,0 @@ -APP_STL := gnustl_static - -APP_PLATFORM = android-19 -APP_CPPFLAGS += -fexceptions -#APP_CPPFLAGS += -frtti += -Wno-error=format-security -APP_CFLAGS = -Wno-error=format-security \ No newline at end of file diff --git a/resource/csdk/connectivity/samples/android/sample_app/sample_main.c b/resource/csdk/connectivity/samples/android/sample_app/sample_main.c deleted file mode 100644 index c0a40cc..0000000 --- a/resource/csdk/connectivity/samples/android/sample_app/sample_main.c +++ /dev/null @@ -1,577 +0,0 @@ -/****************************************************************** - * - * 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 -#include -#include -#include "cacommon.h" -#include "cainterface.h" - -#define MAX_BUF_LEN 1024 -#define MAX_OPT_LEN 16 -#define TRUE 1 -#define FALSE 0 - -char get_menu(); -void process(); - -void start_listening_server(); -void start_discovery_server(); -void find_resource(); -void send_request(); -void send_response(); -void advertise_resource(); -void send_notification(); -void select_network(); -void unselect_network(); -void handle_request_response(); -void find_fixed_resource(); - -void request_handler(const CARemoteEndpoint_t* object, const CARequestInfo_t* requestInfo); -void response_handler(const CARemoteEndpoint_t* object, const CAResponseInfo_t* responseInfo); -void send_request_tmp(CARemoteEndpoint_t* endpoint, CAToken_t token); -int received = FALSE; - -int main() -{ - system("clear"); - - printf("=============================================\n"); - printf("\t\tsample main\n"); - printf("=============================================\n"); - - CAInitialize(); - - // network enable - // default - printf("select default network(WIFI)\n"); - CASelectNetwork(CA_WIFI); - - // set handler. - CARegisterHandler(request_handler, response_handler); - - process(); - - CATerminate(); - - return 0; -} - -void process() -{ - while (1) - { - char menu = get_menu(); - - switch (menu) - { - case 'm': // menu - case 'M': - continue; - - case 'q': // quit - case 'Q': - printf("quit..!!\n"); - return; - - case 's': // start server - case 'S': - start_listening_server(); - break; - - case 'c': // start client - case 'D': - start_discovery_server(); - break; - - case 'f': // find resource - case 'F': - find_resource(); - break; - - case 'r': // send request - case 'R': - send_request(); - break; - - case 'a': // advertise resource - case 'A': - advertise_resource(); - break; - - case 'b': // send notification - case 'B': - send_notification(); - break; - - case 'n': // select network - case 'N': - select_network(); - break; - - case 'x': // unselect network - case 'X': - unselect_network(); - break; - - case 'h': // handle request response - case 'H': - handle_request_response(); - break; - case 'y': - case 'Y': - while (1) - { - received = FALSE; - find_fixed_resource(); - while (received == FALSE) - { - sleep(1); - handle_request_response(); - - } - } - break; - case 'z': - case 'Z': - start_listening_server(); - while (1) - { - sleep(1); - handle_request_response(); - } - break; - - default: - printf("not supported menu!!\n"); - break; - } - } - -} - -void start_listening_server() -{ - printf("start listening server!!\n"); - - CAStartListeningServer(); -} - -void start_discovery_server() -{ - printf("start discovery client!!\n"); - - CAStartDiscoveryServer(); -} - -void find_fixed_resource() -{ - char buf[MAX_BUF_LEN] = - { 0, }; - strcpy(buf, "a/light"); - - CAResult_t res = CAFindResource(buf, "temptoken"); - - if (res != CA_STATUS_OK) - { - printf("find resource error!!\n"); - } - else - { - printf("find resource to %s URI\n", buf); - } - - printf("=============================================\n"); -} - -void find_resource() -{ - char buf[MAX_BUF_LEN]; - - memset(buf, 0, sizeof(char) * MAX_BUF_LEN); - - printf("\n=============================================\n"); - printf("ex) a/light\n"); - printf("reference uri : "); - - gets(buf); - - CAResult_t res = CAFindResource(buf, "temptoken"); - - if (res != CA_STATUS_OK) - { - printf("find resource error!!\n"); - } - else - { - printf("find resource to %s URI\n", buf); - } - - printf("=============================================\n"); -} - -void send_request() -{ - char buf[MAX_BUF_LEN]; - - memset(buf, 0, sizeof(char) * MAX_BUF_LEN); - - printf("\n=============================================\n"); - printf("10.11.12.13:4545/resource_uri ( for IP )\n"); - printf("10:11:12:13:45:45/resource_uri ( for BT )\n"); - printf("uri : "); - - gets(buf); - - // create remote endpoint - CARemoteEndpoint_t* endpoint = NULL; - CAResult_t res = CACreateRemoteEndpoint(buf, &endpoint); - - if (res != CA_STATUS_OK) - { - printf("create remote endpoint error!!"); - CADestroyRemoteEndpoint(endpoint); - return; - } - - // create token - CAToken_t token = NULL; - res = CAGenerateToken(&token); - - if (res != CA_STATUS_OK) - { - printf("token generate error!!"); - token = NULL; - } - - printf("generated token %s\n", (token != NULL) ? token : ""); - - CAInfo_t requestData; - memset(&requestData, 0, sizeof(CAInfo_t)); - requestData.token = token; - requestData.payload = "Temp Json Payload"; - - CARequestInfo_t requestInfo; - memset(&requestInfo, 0, sizeof(CARequestInfo_t)); - requestInfo.method = CA_GET; - requestInfo.info = requestData; - - // send request - CASendRequest(endpoint, &requestInfo); - - if (token != NULL) - { - CADestroyToken(token); - } - - // destroy remote endpoint - if (endpoint != NULL) - { - CADestroyRemoteEndpoint(endpoint); - } - - printf("=============================================\n"); -} - -void advertise_resource() -{ - char buf[MAX_BUF_LEN]; - - memset(buf, 0, sizeof(char) * MAX_BUF_LEN); - - printf("\n=============================================\n"); - printf("uri : "); - - scanf("%s", buf); - - int optionNum = 0; - char optionData[MAX_OPT_LEN]; - - printf("Option Num : "); - scanf("%d", &optionNum); - CAHeaderOption_t *headerOpt; - headerOpt = (CAHeaderOption_t*) malloc(sizeof(CAHeaderOption_t) * optionNum); - if (NULL == headerOpt) - { - printf("Memory allocation failed!\n"); - return; - } - memset(headerOpt, 0, sizeof(CAHeaderOption_t) * optionNum); - - int i; - for (i = 0; i < optionNum; i++) - { - int optionID = 0; - printf("[%d] Option ID : ", i + 1); - scanf("%d", &optionID); - headerOpt[i].optionID = optionID; - - memset(optionData, 0, sizeof(char) * MAX_OPT_LEN); - printf("[%d] Option Data : ", i + 1); - scanf("%s", optionData); - memcpy(headerOpt[i].optionData, optionData, strlen(optionData)); - printf("[%d] inputed option : ID : %d, data : %s\n", i + 1, optionID, optionData); - - headerOpt[i].optionLength = (uint16_t) strlen(optionData); - } - printf("\n=============================================\n"); - - CAAdvertiseResource(buf, "temptoken", headerOpt, (uint8_t) optionNum); - - free(headerOpt); - -} - -void send_notification() -{ - char buf[MAX_BUF_LEN]; - - memset(buf, 0, sizeof(char) * MAX_BUF_LEN); - - printf("\n=============================================\n"); - printf("10.11.12.13:4545/resource_uri ( for IP )\n"); - printf("10:11:12:13:45:45/resource_uri ( for BT )\n"); - printf("uri : "); - - gets(buf); - - // create remote endpoint - CARemoteEndpoint_t* endpoint = NULL; - CAResult_t res = CACreateRemoteEndpoint(buf, &endpoint); - - if (res != CA_STATUS_OK) - { - printf("create remote endpoint error!!"); - CADestroyRemoteEndpoint(endpoint); - return; - } - - CAInfo_t respondeData; - memset(&respondeData, 0, sizeof(CAInfo_t)); - respondeData.token = "client token"; - respondeData.payload = "Temp Notification Data"; - - CAResponseInfo_t responseInfo; - memset(&responseInfo, 0, sizeof(CAResponseInfo_t)); - responseInfo.result = CA_SUCCESS; - responseInfo.info = respondeData; - - // send request - CASendNotification(endpoint, &responseInfo); - - // destroy remote endpoint - if (endpoint != NULL) - { - CADestroyRemoteEndpoint(endpoint); - } - printf("\n=============================================\n"); -} - -void select_network() -{ - char buf[MAX_BUF_LEN]; - - printf("\n=============================================\n"); - printf("\tselect network\n"); - printf("ETHERNET : 0\n"); - printf("WIFI : 1\n"); - printf("EDR : 2\n"); - printf("LE : 3\n"); - printf("select : "); - - memset(buf, 0, sizeof(char) * MAX_BUF_LEN); - gets(buf); - - int number = buf[0] - '0'; - - number = (number < 0 || number > 3) ? 1 : number; - - CASelectNetwork(1 << number); - - printf("=============================================\n"); -} - -void unselect_network() -{ - char buf[MAX_BUF_LEN]; - - printf("\n=============================================\n"); - printf("\tunselect enabled network\n"); - printf("ETHERNET : 0\n"); - printf("WIFI : 1\n"); - printf("EDR : 2\n"); - printf("LE : 3\n"); - printf("select : "); - - memset(buf, 0, sizeof(char) * MAX_BUF_LEN); - gets(buf); - - int number = buf[0] - '0'; - - number = (number < 0 || number > 3) ? 1 : number; - - CAUnSelectNetwork(1 << number); - - printf("=============================================\n"); -} - -char get_menu() -{ - char buf[MAX_BUF_LEN]; - - printf("\n=============================================\n"); - printf("\t\tMenu\n"); - printf("\ts : start server\n"); - printf("\tc : start client\n"); - printf("\tf : find resource\n"); - printf("\tr : send request\n"); - printf("\ta : advertise resource\n"); - printf("\tb : send notification\n"); - printf("\tn : select network\n"); - printf("\tx : unselect network\n"); - printf("\th : handle request response\n"); - printf("\ty : run static client\n"); - printf("\tz : run static server\n"); - printf("\tq : quit\n"); - printf("=============================================\n"); - printf("select : "); - - memset(buf, 0, sizeof(char) * MAX_BUF_LEN); - - gets(buf); - - return buf[0]; -} - -void handle_request_response() -{ - printf("handle_request_response\n"); - CAHandleRequestResponse(); -} - -void request_handler(const CARemoteEndpoint_t* object, const CARequestInfo_t* requestInfo) -{ - - printf("[CALLBACK] request_handler, uri : %s, data : %s\n", - (object != NULL) ? object->resourceUri : "", - (requestInfo != NULL) ? requestInfo->info.payload : ""); - - printf("[CALLBACK] request_handler, address : %s\n", - (object != NULL) ? object->addressInfo.IP.ipAddress : ""); - - if (requestInfo->info.options) - { - uint32_t len = requestInfo->info.numOptions; - uint32_t i; - for (i = 0; i < len; i++) - { - printf("[CALLBACK] request_handler, option ID : %d\n", - requestInfo->info.options[i].optionID); - printf("[CALLBACK] request_handler, options data length : %d\n", - requestInfo->info.options[i].optionLength); - printf("[CALLBACK] request_handler, options data : %s\n", - requestInfo->info.options[i].optionData); - } - } - - printf("send response with URI\n"); - send_response(object, (requestInfo != NULL) ? requestInfo->info.token : ""); - - received = TRUE; - -} - -void response_handler(const CARemoteEndpoint_t* object, const CAResponseInfo_t* responseInfo) -{ - - printf("[CALLBACK] response_handler, uri : %s, data : %s\n", - (object != NULL) ? object->resourceUri : "", - (responseInfo != NULL) ? responseInfo->info.payload : ""); - - printf("[CALLBACK] response_handler, address : %s\n", - (object != NULL) ? object->addressInfo.IP.ipAddress : ""); - - if (responseInfo->info.options) - { - uint32_t len = responseInfo->info.numOptions; - uint32_t i; - for (i = 0; i < len; i++) - { - printf("[CALLBACK] response_handler, option ID : %d\n", - responseInfo->info.options[i].optionID); - printf("[CALLBACK] response_handler, options data length : %d\n", - responseInfo->info.options[i].optionLength); - printf("[CALLBACK] response_handler, options data : %s\n", - responseInfo->info.options[i].optionData); - } - } - received = TRUE; - - //printf("send request with URI\n"); - //send_request_tmp(object, (responseInfo != NULL) ? responseInfo->info.token : ""); -} - -void send_response(CARemoteEndpoint_t* endpoint, CAToken_t request_token) -{ - - printf("\n=============================================\n"); - - CAInfo_t responseData; - //responseData = (CAInfo*) malloc(sizeof(CAInfo)); - memset(&responseData, 0, sizeof(CAInfo_t)); - responseData.token = request_token; - responseData.payload = "response payload"; - - CAResponseInfo_t responseInfo; - //responseInfo = (CAResponseInfo*) malloc(sizeof(CAResponseInfo)); - memset(&responseInfo, 0, sizeof(CAResponseInfo_t)); - responseInfo.result = 203; - responseInfo.info = responseData; - - // send request (connectivityType from remoteEndpoint of request Info) - CASendResponse(endpoint, &responseInfo); - - printf("=============================================\n"); - -} - -void send_request_tmp(CARemoteEndpoint_t* endpoint, CAToken_t token) -{ - - printf("\n=============================================\n"); - - CAInfo_t requestData; - memset(&requestData, 0, sizeof(CAInfo_t)); - requestData.token = token; - requestData.payload = "Temp Json Payload"; - - CARequestInfo_t requestInfo; - memset(&requestInfo, 0, sizeof(CARequestInfo_t)); - requestInfo.method = CA_GET; - requestInfo.info = requestData; - - // send request - endpoint->connectivityType = CA_WIFI; - CASendRequest(endpoint, &requestInfo); - - printf("=============================================\n"); - -} - diff --git a/resource/csdk/connectivity/samples/android/sample_service/AndroidManifest.xml b/resource/csdk/connectivity/samples/android/sample_service/AndroidManifest.xml index 19a5385..a65a9fe 100644 --- a/resource/csdk/connectivity/samples/android/sample_service/AndroidManifest.xml +++ b/resource/csdk/connectivity/samples/android/sample_service/AndroidManifest.xml @@ -14,7 +14,7 @@ android:theme="@style/AppTheme" > @@ -23,7 +23,7 @@ - + @@ -34,3 +34,4 @@ + diff --git a/resource/csdk/connectivity/samples/android/sample_service/Makefile b/resource/csdk/connectivity/samples/android/sample_service/Makefile index 9710ed2..5fc1131 100644 --- a/resource/csdk/connectivity/samples/android/sample_service/Makefile +++ b/resource/csdk/connectivity/samples/android/sample_service/Makefile @@ -15,4 +15,4 @@ all: $(NDK_BUILD) NDK_PROJECT_PATH=$(APPLICATION_BUILD) clean : - @$(RM) -rf $(LIBS_DIR) $(OBJ_DIR) \ No newline at end of file + @$(RM) -rf $(LIBS_DIR) $(OBJ_DIR) diff --git a/resource/csdk/connectivity/samples/android/sample_service/jni/Android.mk b/resource/csdk/connectivity/samples/android/sample_service/jni/Android.mk index 8bf3c5d..f96f224 100644 --- a/resource/csdk/connectivity/samples/android/sample_service/jni/Android.mk +++ b/resource/csdk/connectivity/samples/android/sample_service/jni/Android.mk @@ -14,6 +14,7 @@ LOCAL_MODULE := RMInterface LOCAL_SRC_FILES := ResourceModel.c LOCAL_STATIC_LIBRARIES := CA LOCAL_LDLIBS := -llog +LOCAL_C_INCLUDES := ../../../api include $(BUILD_SHARED_LIBRARY) #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -23,3 +24,4 @@ PROJECT_ROOT_PATH = ../../.. CA_LIB_PATH = $(PROJECT_ROOT_PATH)/build/android include $(CA_LIB_PATH)/jni/Android.mk #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + diff --git a/resource/csdk/connectivity/samples/android/sample_service/jni/Application.mk b/resource/csdk/connectivity/samples/android/sample_service/jni/Application.mk index 26f13d9..7753668 100644 --- a/resource/csdk/connectivity/samples/android/sample_service/jni/Application.mk +++ b/resource/csdk/connectivity/samples/android/sample_service/jni/Application.mk @@ -3,4 +3,4 @@ APP_STL := gnustl_static APP_PLATFORM = android-19 APP_CPPFLAGS += -fexceptions APP_CPPFLAGS += -frtti -APP_CFLAGS = -Wno-error=format-security \ No newline at end of file +APP_CFLAGS = -Wno-error=format-security diff --git a/resource/csdk/connectivity/samples/android/sample_service/jni/ResourceModel.c b/resource/csdk/connectivity/samples/android/sample_service/jni/ResourceModel.c index e6707e2..abb7910 100644 --- a/resource/csdk/connectivity/samples/android/sample_service/jni/ResourceModel.c +++ b/resource/csdk/connectivity/samples/android/sample_service/jni/ResourceModel.c @@ -5,8 +5,8 @@ #include #include -#include <../../../../api/cainterface.h> -#include <../../../../api/cacommon.h> +#include "cainterface.h" +#include "cacommon.h" #include "com_iotivity_service_RMInterface.h" #define LOG_TAG "JNI_INTERFACE_SAMPLE" @@ -23,35 +23,37 @@ */ #define RS_CLIENT_PSK ("AAAAAAAAAAAAAAAA") -int gReceived; -CABool_t gLocalUnicastPort; -CABool_t gLocalSecurePort; +#define PORT_LENGTH 5 +#define SECURE_DEFAULT_PORT 5684 + +int g_received = 0; +uint16_t g_localSecurePort = SECURE_DEFAULT_PORT; void request_handler(const CARemoteEndpoint_t* object, const CARequestInfo_t* requestInfo); void response_handler(const CARemoteEndpoint_t* object, const CAResponseInfo_t* responseInfo); -void send_response(const CARemoteEndpoint_t* endpoint, CAToken_t request_token); -void get_resource_uri(char *URI, char *resourceURI, int length); +void get_resource_uri(const char *URI, char *resourceURI, int length); int get_secure_information(CAPayload_t payLoad); CAResult_t get_network_type(int selectedNetwork); void callback(char *subject, char *receivedData); -CAConnectivityType_t gSelectedNwType; -static CAToken_t gLastRequestToken = NULL; -static const char *gSecureInfoData = "{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"]," +CAConnectivityType_t g_selectedNwType = CA_WIFI; +static CAToken_t g_lastRequestToken = NULL; +static const char SECURE_COAPS_PREFIX[] = "coaps://"; +static const char SECURE_INFO_DATA[] + = "{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"]," "\"if\":[\"oc.mi.def\"],\"obs\":1,\"sec\":1,\"port\":%d}}]}"; -static const char *gNormalInfoData = "{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"]," +static const char NORMAL_INFO_DATA[] + = "{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"]," "\"if\":[\"oc.mi.def\"],\"obs\":1}}]}"; -static jobject gResponseListenerObject = NULL; +static jobject g_responseListenerObject = NULL; extern JavaVM *g_jvm; -static CARemoteEndpoint_t* clientEndpoint =NULL; -static CAToken_t clientToken; - // init -JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_setNativeResponseListener(JNIEnv *env, jobject obj, jobject listener){ +JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_setNativeResponseListener + (JNIEnv *env, jobject obj, jobject listener){ LOGI("setNativeResponseListener"); - gResponseListenerObject = (*env)->NewGlobalRef(env, obj); + g_responseListenerObject = (*env)->NewGlobalRef(env, obj); } #ifdef __WITH_DTLS__ @@ -59,99 +61,89 @@ static OCDtlsPskCredsBlob *pskCredsBlob = NULL; void clearDtlsCredentialInfo() { - printf("clearDtlsCredentialInfo IN\n"); + LOGI("clearDtlsCredentialInfo IN\n"); if (pskCredsBlob) { // Initialize sensitive data to zeroes before freeing. - memset(pskCredsBlob->creds, 0, sizeof(OCDtlsPskCredsBlob)*(pskCredsBlob->num)); - free(pskCredsBlob->creds); + if (pskCredsBlob->creds != NULL) + { + memset(pskCredsBlob->creds, 0, sizeof(OCDtlsPskCredsBlob)*(pskCredsBlob->num)); + free(pskCredsBlob->creds); + } memset(pskCredsBlob, 0, sizeof(OCDtlsPskCredsBlob)); free(pskCredsBlob); pskCredsBlob = NULL; } - printf("clearDtlsCredentialInfo OUT\n"); + LOGI("clearDtlsCredentialInfo OUT\n"); } // Internal API. Invoked by OC stack to retrieve credentials from this module void CAGetDtlsPskCredentials(OCDtlsPskCredsBlob **credInfo) { - printf("CAGetDtlsPskCredentials IN\n"); + LOGI("CAGetDtlsPskCredentials IN\n"); *credInfo = pskCredsBlob; - printf("CAGetDtlsPskCredentials OUT\n"); + LOGI("CAGetDtlsPskCredentials OUT\n"); } int32_t SetCredentials() { - printf("SetCredentials IN\n"); - pskCredsBlob = (OCDtlsPskCredsBlob *)malloc(sizeof(OCDtlsPskCredsBlob)); - - memset(pskCredsBlob, 0x0, sizeof(OCDtlsPskCredsBlob)); + LOGI("SetCredentials IN\n"); + pskCredsBlob = (OCDtlsPskCredsBlob *)calloc(1, sizeof(OCDtlsPskCredsBlob)); + if (NULL == pskCredsBlob) + { + LOGI("Memory allocation failed!\n"); + return -1; + } memcpy(pskCredsBlob->rsIdentity, IDENTITY, DTLS_PSK_ID_LEN); pskCredsBlob->num = 1; - pskCredsBlob->creds = (OCDtlsPskCredsBlob *)malloc(sizeof(OCDtlsPskCredsBlob) *(pskCredsBlob->num)); - - memcpy(pskCredsBlob->creds[0].clientIdentity, IDENTITY, DTLS_PSK_ID_LEN); - memcpy(pskCredsBlob->creds[0].rsClientPsk, RS_CLIENT_PSK, DTLS_PSK_PSK_LEN); - - printf("SetCredentials OUT\n"); - return 1; -} -#endif - -JNIEXPORT jint JNI_OnLoad(JavaVM *jvm, void *reserved) -{ - printf("JNI_OnLoad"); - - JNIEnv* env; - if((*jvm)->GetEnv(jvm, (void**)&env, JNI_VERSION_1_6) != JNI_OK) + pskCredsBlob->creds = (OCDtlsPskCredsBlob *)malloc(sizeof(OCDtlsPskCredsBlob) * + (pskCredsBlob->num)); + if (NULL == pskCredsBlob->creds) { + LOGI("Memory allocation failed!\n"); return -1; } - g_jvm = jvm; /* cache the JavaVM pointer */ - - CANativeJNISetJavaVM(g_jvm); - return JNI_VERSION_1_6; -} - -void JNI_OnUnload(JavaVM *jvm, void *reserved) -{ - printf("JNI_OnUnload"); - - JNIEnv* env; - if((*jvm)->GetEnv(jvm, (void**)&env, JNI_VERSION_1_6) != JNI_OK) + uint32_t i; + for (i = 0; i < pskCredsBlob->num; i++) { - return; + memcpy(pskCredsBlob->creds[i].id, IDENTITY, DTLS_PSK_ID_LEN); + memcpy(pskCredsBlob->creds[i].psk, RS_CLIENT_PSK, DTLS_PSK_PSK_LEN); } - g_jvm = 0; - return; + LOGI("SetCredentials OUT\n"); + return 1; } +#endif JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_RMInitialize (JNIEnv *env, jobject obj, jobject context) { LOGI("RMInitialize"); - - //Currently set context for Android Platform - CANativeJNISetContext(env, context); + //Currently set context for WiFiCore + CAJniSetContext(context); + CALEServerJNISetContext(env, context); + CALEClientJNISetContext(env, context); + CALENetworkMonitorJNISetContext(env, context); CAResult_t res; #ifdef __WITH_DTLS__ - if (SetCredentials() == 0) + if (SetCredentials() != 1) { - printf("SetCredentials failed\n"); + LOGI("SetCredentials failed\n"); + return; } res = CARegisterDTLSCredentialsHandler(CAGetDtlsPskCredentials); if(res != CA_STATUS_OK) { - printf("Set credential handler fail\n"); + LOGI("Set credential handler fail\n"); + return; } #endif @@ -198,8 +190,8 @@ JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_RMRegisterHandler(J CARegisterHandler(request_handler, response_handler); } -JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_RMFindResource(JNIEnv *env, jobject obj, - jstring uri) +JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_RMFindResource(JNIEnv *env, + jobject obj, jstring uri) { const char* strUri = (*env)->GetStringUTFChars(env, uri, NULL); LOGI("RMFindResource - %s", strUri); @@ -209,8 +201,9 @@ JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_RMFindResource(JNIE CAResult_t res = CAGenerateToken(&token); if (res != CA_STATUS_OK) { - printf("token generate error!!\n"); + LOGI("token generate error!!\n"); token = NULL; + return; } LOGI("generated token %s\n", (token != NULL) ? token : ""); @@ -222,12 +215,13 @@ JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_RMFindResource(JNIE else { LOGI("find resource to %s URI", strUri); - gLastRequestToken = token; + g_lastRequestToken = token; } } -JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_RMSendRequest(JNIEnv *env, jobject obj, - jstring uri, jstring payload, jint selectedNetwork, jint isSecured, jint msgType) +JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_RMSendRequest(JNIEnv *env, + jobject obj, jstring uri, jstring payload, jint selectedNetwork, jint isSecured, + jint msgType) { const char* strUri = (*env)->GetStringUTFChars(env, uri, NULL); LOGI("RMSendRequest - %s", strUri); @@ -244,7 +238,7 @@ JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_RMSendRequest(JNIEn //create remote endpoint CARemoteEndpoint_t* endpoint = NULL; - if(CA_STATUS_OK != CACreateRemoteEndpoint((const CAURI_t)strUri, gSelectedNwType, &endpoint)) + if(CA_STATUS_OK != CACreateRemoteEndpoint((const CAURI_t)strUri, g_selectedNwType, &endpoint)) { LOGI("Could not create remote end point"); CADestroyRemoteEndpoint(endpoint); @@ -258,36 +252,57 @@ JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_RMSendRequest(JNIEn res = CAGenerateToken(&token); if (res != CA_STATUS_OK) { - printf("token generate error!!\n"); + LOGI("token generate error!!\n"); token = NULL; + // destroy token + CADestroyToken(token); + // destroy remote endpoint + CADestroyRemoteEndpoint(endpoint); + return; } char resourceURI[15] = {0}; get_resource_uri((const CAURI_t)strUri, resourceURI, 14); - CAInfo_t requestData; - memset(&requestData, 0, sizeof(CAInfo_t)); + CAInfo_t requestData = {0}; requestData.token = token; const char* strPayload = (*env)->GetStringUTFChars(env, payload, NULL); if (isSecured == 1) { - int length = strlen(gSecureInfoData) + strlen(resourceURI) + 1; + uint32_t length = sizeof(SECURE_INFO_DATA) + strlen(resourceURI); requestData.payload = (CAPayload_t) malloc(length); - sprintf(requestData.payload, gSecureInfoData, resourceURI, gLocalSecurePort); + if (NULL == requestData.payload) + { + LOGI("Memory allocation failed!\n"); + // destroy token + CADestroyToken(token); + // destroy remote endpoint + CADestroyRemoteEndpoint(endpoint); + return; + } + snprintf(requestData.payload, length, SECURE_INFO_DATA, resourceURI, g_localSecurePort); } else { - int length = strlen(strPayload) + strlen(resourceURI) + 1; + uint32_t length = sizeof(NORMAL_INFO_DATA) + strlen(resourceURI); requestData.payload = (CAPayload_t) malloc(length); - sprintf(requestData.payload, strPayload, resourceURI); + if (NULL == requestData.payload) + { + LOGI("Memory allocation failed!\n"); + // destroy token + CADestroyToken(token); + // destroy remote endpoint + CADestroyRemoteEndpoint(endpoint); + return; + } + snprintf(requestData.payload, length, NORMAL_INFO_DATA, resourceURI); } requestData.type = messageType; - CARequestInfo_t requestInfo; - memset(&requestInfo, 0, sizeof(CARequestInfo_t)); + CARequestInfo_t requestInfo = {0}; requestInfo.method = CA_GET; requestInfo.info = requestData; @@ -298,23 +313,20 @@ JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_RMSendRequest(JNIEn } // destroy token - if (token != NULL) - { - CADestroyToken(token); - } + CADestroyToken(token); // destroy remote endpoint - if (endpoint != NULL) - { - CADestroyRemoteEndpoint(endpoint); - } + CADestroyRemoteEndpoint(endpoint); } JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_RMSendResponse(JNIEnv *env, - jobject obj, jint selectedNetwork, jint isSecured, jint msgType, jint responseValue) + jobject obj, jstring uri, jstring payload, jint selectedNetwork, jint isSecured) { LOGI("RMSendResponse"); + const char* strUri = (*env)->GetStringUTFChars(env, uri, NULL); + LOGI("RMSendResponse - %s", strUri); + CAResult_t res; LOGI("selectedNetwork - %d", selectedNetwork); @@ -322,60 +334,88 @@ JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_RMSendResponse(JNIE res = get_network_type(selectedNetwork); if (res != CA_STATUS_OK) { - LOGI("Not supported network type"); return; } - if (clientEndpoint == NULL) + //create remote endpoint + CARemoteEndpoint_t* endpoint = NULL; + + if(CA_STATUS_OK != CACreateRemoteEndpoint((const CAURI_t)strUri, g_selectedNwType, &endpoint)) { - LOGI("No Request received"); + LOGI("Could not create remote end point"); + CADestroyRemoteEndpoint(endpoint); return; } - CAMessageType_t messageType = msgType; + CAMessageType_t messageType = CA_MSG_ACKNOWLEDGE; - CAInfo_t responseData; - memset(&responseData, 0, sizeof(CAInfo_t)); - responseData.token = clientToken; + // create token + CAToken_t token = NULL; + res = CAGenerateToken(&token); + if (res != CA_STATUS_OK) + { + LOGI("token generate error!"); + token = NULL; + } + char resourceURI[15] = {0}; + + get_resource_uri((const CAURI_t)strUri, resourceURI, 14); + + CAInfo_t responseData = {0}; + responseData.token = token; + + const char* strPayload = (*env)->GetStringUTFChars(env, payload, NULL); if (isSecured == 1) { - int length = strlen(gSecureInfoData) + strlen(clientEndpoint->resourceUri) + 1; + uint32_t length = sizeof(SECURE_INFO_DATA) + strlen(resourceURI); responseData.payload = (CAPayload_t) malloc(length); - sprintf(responseData.payload, gSecureInfoData, clientEndpoint->resourceUri, gLocalSecurePort); + if (NULL == responseData.payload) + { + LOGI("Memory allocation failed!\n"); + // destroy token + CADestroyToken(token); + // destroy remote endpoint + CADestroyRemoteEndpoint(endpoint); + return; + } + snprintf(responseData.payload, length, SECURE_INFO_DATA, resourceURI, g_localSecurePort); } else { - int length = strlen("sendResponse Payload") + strlen(clientEndpoint->resourceUri) + 1; + uint32_t length = sizeof(NORMAL_INFO_DATA) + strlen(resourceURI); responseData.payload = (CAPayload_t) malloc(length); - sprintf(responseData.payload, gNormalInfoData, clientEndpoint->resourceUri); + if (NULL == responseData.payload) + { + LOGI("Memory allocation failed!\n"); + // destroy token + CADestroyToken(token); + // destroy remote endpoint + CADestroyRemoteEndpoint(endpoint); + return; + } + snprintf(responseData.payload, length, NORMAL_INFO_DATA, resourceURI); } responseData.type = messageType; - CAResponseInfo_t responseInfo; - memset(&responseInfo, 0, sizeof(CAResponseInfo_t)); - responseInfo.result = responseValue; + CAResponseInfo_t responseInfo = {0}; + responseInfo.result = CA_SUCCESS; responseInfo.info = responseData; // send request - if(CA_STATUS_OK != CASendResponse(clientEndpoint, &responseInfo)) + if(CA_STATUS_OK != CASendResponse(endpoint, &responseInfo)) { LOGI("Could not send response"); } + LOGI("Send response"); + // destroy token - if (clientToken != NULL) - { - CADestroyToken(clientToken); - } + CADestroyToken(token); // destroy remote endpoint - if (clientEndpoint != NULL) - { - CADestroyRemoteEndpoint(clientEndpoint); - } - + CADestroyRemoteEndpoint(endpoint); } JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_RMAdvertiseResource(JNIEnv *env, @@ -388,13 +428,12 @@ JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_RMAdvertiseResource int optionNum = 2; CAHeaderOption_t *headerOpt; - headerOpt = (CAHeaderOption_t*) malloc(sizeof(CAHeaderOption_t) * optionNum); + headerOpt = (CAHeaderOption_t*) calloc(1, sizeof(CAHeaderOption_t) * optionNum); if (NULL == headerOpt) { - printf("Memory allocation failed!\n"); + LOGI("Memory allocation failed!\n"); return; } - memset(headerOpt, 0, sizeof(CAHeaderOption_t) * optionNum); char* tmpOptionData1 = "Hello"; headerOpt[0].optionID = 3000; @@ -412,7 +451,8 @@ JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_RMAdvertiseResource if (res != CA_STATUS_OK) { LOGI("token generate error!"); - token = NULL; + free(headerOpt); + return; } CAAdvertiseResource((const CAURI_t)strUri, token, headerOpt, (uint8_t) optionNum); @@ -440,7 +480,7 @@ JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_RMSendNotification( //create remote endpoint CARemoteEndpoint_t* endpoint = NULL; - if(CA_STATUS_OK != CACreateRemoteEndpoint((const CAURI_t)strUri, gSelectedNwType, &endpoint)) + if(CA_STATUS_OK != CACreateRemoteEndpoint((const CAURI_t)strUri, g_selectedNwType, &endpoint)) { LOGI("Could not create remote end point"); CADestroyRemoteEndpoint(endpoint); @@ -462,28 +502,44 @@ JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_RMSendNotification( get_resource_uri((const CAURI_t)strUri, resourceURI, 14); - CAInfo_t responseData; - memset(&responseData, 0, sizeof(CAInfo_t)); + CAInfo_t responseData = {0}; responseData.token = token; const char* strPayload = (*env)->GetStringUTFChars(env, payload, NULL); if (isSecured == 1) { - int length = strlen(gSecureInfoData) + strlen(resourceURI) + 1; + uint32_t length = sizeof(SECURE_INFO_DATA) + strlen(resourceURI); responseData.payload = (CAPayload_t) malloc(length); - sprintf(responseData.payload, gSecureInfoData, resourceURI, gLocalSecurePort); + if (NULL == responseData.payload) + { + LOGI("Memory allocation failed!\n"); + // destroy token + CADestroyToken(token); + // destroy remote endpoint + CADestroyRemoteEndpoint(endpoint); + return; + } + snprintf(responseData.payload, length, SECURE_INFO_DATA, resourceURI, g_localSecurePort); } else { - int length = strlen(strPayload) + strlen(resourceURI) + 1; + uint32_t length = sizeof(NORMAL_INFO_DATA) + strlen(resourceURI); responseData.payload = (CAPayload_t) malloc(length); - sprintf(responseData.payload, strPayload, resourceURI); + if (NULL == responseData.payload) + { + LOGI("Memory allocation failed!\n"); + // destroy token + CADestroyToken(token); + // destroy remote endpoint + CADestroyRemoteEndpoint(endpoint); + return; + } + snprintf(responseData.payload, length, NORMAL_INFO_DATA, resourceURI); } responseData.type = messageType; - CAResponseInfo_t responseInfo; - memset(&responseInfo, 0, sizeof(CAResponseInfo_t)); + CAResponseInfo_t responseInfo = {0}; responseInfo.result = CA_SUCCESS; responseInfo.info = responseData; @@ -496,16 +552,10 @@ JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_RMSendNotification( LOGI("Send Notification"); // destroy token - if (token != NULL) - { - CADestroyToken(token); - } + CADestroyToken(token); // destroy remote endpoint - if (endpoint != NULL) - { - CADestroyRemoteEndpoint(endpoint); - } + CADestroyRemoteEndpoint(endpoint); } JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_RMSelectNetwork(JNIEnv *env, jobject obj, @@ -532,13 +582,6 @@ JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_RMHandleRequestResp void request_handler(const CARemoteEndpoint_t* object, const CARequestInfo_t* requestInfo) { - - char *cloneUri = NULL; - char *cloneRemoteAddress = NULL; - char *clonePayload = NULL; - char *cloneOptionData = NULL; - uint32_t len = 0; - if (!object) { LOGI("Remote endpoint is NULL!"); @@ -554,69 +597,24 @@ void request_handler(const CARemoteEndpoint_t* object, const CARequestInfo_t* re LOGI("##########received request from remote device #############\n"); LOGI("Uri: %s\n", object->resourceUri); LOGI("Remote Address: %s\n", object->addressInfo.IP.ipAddress); + LOGI("Data: %s\n", requestInfo->info.payload); - LOGI("Token: %s\n", requestInfo->info.token); - LOGI("Code: %d\n", requestInfo->method); - if (NULL != gResponseListenerObject) + if (NULL != g_responseListenerObject) { callback("received request from remote device", "#######"); + callback("Uri: ", object->resourceUri); - if (object->resourceUri != NULL) - { - len = strlen(object->resourceUri); - cloneUri = (char *) OICMalloc(sizeof(char) * (len + 1)); + callback("Remote Address: ", (char *) object->addressInfo.IP.ipAddress); - if (cloneUri == NULL) - { - LOGI("CACloneRemoteEndpoint Out of memory"); - return; - } - - memset(cloneUri, 0, sizeof(char) * (len + 1)); - strncpy(cloneUri, object->resourceUri, len); - - callback("Uri: ", cloneUri); - free(cloneUri); - } - - len = strlen(object->addressInfo.IP.ipAddress); - cloneRemoteAddress = (char *) OICMalloc(sizeof(char) * (len + 1)); - - if (cloneRemoteAddress == NULL) + if(requestInfo->info.payload) { - LOGI("CACloneRemoteEndpoint Out of memory"); - return; - } - - memset(cloneRemoteAddress, 0, sizeof(char) * (len + 1)); - strncpy(cloneRemoteAddress, object->addressInfo.IP.ipAddress, len); - - callback("Remote Address: ", cloneRemoteAddress); - free(cloneRemoteAddress); - - - if(requestInfo->info.payload != NULL) - { - len = strlen(requestInfo->info.payload); - clonePayload = (char *) OICMalloc(sizeof(char) * (len + 1)); - - if (clonePayload == NULL) - { - LOGI("CACloneRemoteEndpoint Out of memory"); - return; - } - - memset(clonePayload, 0, sizeof(char) * (len + 1)); - strncpy(clonePayload, requestInfo->info.payload, len); - - callback("Data: ", clonePayload); - free(clonePayload); + callback("Data: ", requestInfo->info.payload); } } - if (gLastRequestToken != NULL && requestInfo->info.token != NULL - && (strcmp((char *)gLastRequestToken, requestInfo->info.token) == 0)) + if (g_lastRequestToken != NULL && requestInfo->info.token != NULL + && (strcmp((char *)g_lastRequestToken, requestInfo->info.token) == 0)) { LOGI("token is same. received request of it's own. skip.. \n"); return; @@ -626,9 +624,6 @@ void request_handler(const CARemoteEndpoint_t* object, const CARequestInfo_t* re { uint32_t len = requestInfo->info.numOptions; uint32_t i; - - LOGI("Option count: %d\n", requestInfo->info.numOptions); - for (i = 0; i < len; i++) { LOGI("Option %d\n", i + 1); @@ -636,58 +631,43 @@ void request_handler(const CARemoteEndpoint_t* object, const CARequestInfo_t* re LOGI("Data[%d]: %s\n", requestInfo->info.options[i].optionLength, requestInfo->info.options[i].optionData); - if (NULL != gResponseListenerObject) + if (NULL != g_responseListenerObject) { - char optionInfo[1024] = {0,}; - sprintf(optionInfo, "Num[%d] - ID : %d, Option Length : %d", i+1, - requestInfo->info.options[i].optionID, requestInfo->info.options[i].optionLength); - - callback("Option info: ", optionInfo); - - if (requestInfo->info.options[i].optionData != NULL) - { - uint32_t optionDataLen = strlen(requestInfo->info.options[i].optionData); - cloneOptionData = (char *) OICMalloc(sizeof(char) * (optionDataLen + 1)); - - if (cloneOptionData == NULL) - { - LOGI("CACloneRemoteEndpoint Out of memory"); - return; - } + char tmpbuf[30]; + sprintf(tmpbuf, "%d", i + 1); + callback("Option: ", tmpbuf); - memset(cloneOptionData, 0, sizeof(char) * (optionDataLen + 1)); - strncpy(cloneOptionData, requestInfo->info.options[i].optionData, optionDataLen); + sprintf(tmpbuf, "%d", requestInfo->info.options[i].optionID); + callback("ID: ", tmpbuf); - callback("Option Data: ", cloneOptionData); - free(cloneOptionData); - } + sprintf(tmpbuf, "Data:[%d]", requestInfo->info.options[i].optionLength); + callback("tmpbuf: ", requestInfo->info.options[i].optionData); } } } - - printf("############################################################\n"); + LOGI("############################################################\n"); //Check if this has secure communication information - if (requestInfo->info.payload && object->resourceUri) + if (requestInfo->info.payload) { int securePort = get_secure_information(requestInfo->info.payload); if (0 < securePort) //Set the remote endpoint secure details and send response { LOGI("This is secure resource...\n"); char *uri = NULL; - int length = 0; + uint32_t length = 0; - length = 8; //length of "coaps://" - length += strlen(object->addressInfo.IP.ipAddress) + 5; // length of "ipaddress:port" + length = sizeof(SECURE_COAPS_PREFIX) - 1; //length of "coaps://" + length += strlen(object->addressInfo.IP.ipAddress) + PORT_LENGTH; // length of "ipaddress:port" length += strlen(object->resourceUri) + 1; uri = calloc(1,sizeof(char)*length); if (!uri) { - printf("Failed to create new uri\n"); + LOGI("Failed to create new uri\n"); return; } - sprintf(uri,"coaps://%s:%d/%s",object->addressInfo.IP.ipAddress, + sprintf(uri,"%s%s:%d/%s", SECURE_COAPS_PREFIX, object->addressInfo.IP.ipAddress, securePort, object->resourceUri); CARemoteEndpoint_t *endpoint = NULL; @@ -696,86 +676,54 @@ void request_handler(const CARemoteEndpoint_t* object, const CARequestInfo_t* re LOGI("Failed to create duplicate of remote endpoint!\n"); return; } - endpoint->isSecured = CA_TRUE; + endpoint->isSecured = true; object = endpoint; } } - gReceived = 1; + g_received = 1; - clientEndpoint = object; - clientToken = requestInfo->info.token; } void response_handler(const CARemoteEndpoint_t* object, const CAResponseInfo_t* responseInfo) { - char *cloneUri = NULL; - char *cloneRemoteAddress = NULL; - char *clonePayload = NULL; - char *cloneOptionData = NULL; - uint32_t len = 0; - LOGI("##########Received response from remote device #############\n"); LOGI("Uri: %s\n", object->resourceUri); - LOGI("Remote Address: %s\n", object->addressInfo.IP.ipAddress); - LOGI("response result: %d\n", responseInfo->result); - LOGI("Data: %s\n", responseInfo->info.payload); - LOGI("Token: %s\n", responseInfo->info.token); - LOGI("Code: %d\n", responseInfo->result); - if (NULL != gResponseListenerObject) + if(object->connectivityType == CA_EDR) { - if (object->resourceUri != NULL) - { - len = strlen(object->resourceUri); - cloneUri = (char *) OICMalloc(sizeof(char) * (len + 1)); - - if (cloneUri == NULL) - { - LOGI("CACloneRemoteEndpoint Out of memory"); - return; - } - - memset(cloneUri, 0, sizeof(char) * (len + 1)); - strncpy(cloneUri, object->resourceUri, len); + LOGI("Remote Address: %s\n", object->addressInfo.BT.btMacAddress); + } else if(object->connectivityType == CA_LE) + { + LOGI("Remote Address: %s\n", object->addressInfo.LE.leMacAddress); + } else if(object->connectivityType == CA_WIFI) + { + LOGI("Remote Address: %s\n", object->addressInfo.IP.ipAddress); + } - callback("Uri: ", cloneUri); - free(cloneUri); - } + LOGI("response result: %d\n", responseInfo->result); + LOGI("Data: %s\n", responseInfo->info.payload); - len = strlen(object->addressInfo.IP.ipAddress); - cloneRemoteAddress = (char *) OICMalloc(sizeof(char) * (len + 1)); + if (NULL != g_responseListenerObject) + { + callback("received response from remote device", "#######"); + callback("Uri: ", object->resourceUri); - if (cloneRemoteAddress == NULL) + if(object->connectivityType == CA_EDR) { - LOGI("CACloneRemoteEndpoint Out of memory"); - return; + callback("Remote Address: ", (char*) object->addressInfo.BT.btMacAddress); + } else if(object->connectivityType == CA_LE) + { + callback("Remote Address: ", (char*) object->addressInfo.LE.leMacAddress); + } else if(object->connectivityType == CA_WIFI) + { + callback("Remote Address: ", (char*) object->addressInfo.IP.ipAddress); } - memset(cloneRemoteAddress, 0, sizeof(char) * (len + 1)); - strncpy(cloneRemoteAddress, object->addressInfo.IP.ipAddress, len); - - callback("Remote Address: ", cloneRemoteAddress); - free(cloneRemoteAddress); - - - if(responseInfo->info.payload != NULL) + if(responseInfo->info.payload) { - len = strlen(responseInfo->info.payload); - clonePayload = (char *) OICMalloc(sizeof(char) * (len + 1)); - - if (clonePayload == NULL) - { - LOGI("CACloneRemoteEndpoint Out of memory"); - return; - } - - memset(clonePayload, 0, sizeof(char) * (len + 1)); - strncpy(clonePayload, responseInfo->info.payload, len); - - callback("Data: ", clonePayload); - free(clonePayload); + callback("Data: ", responseInfo->info.payload); } } @@ -790,35 +738,22 @@ void response_handler(const CARemoteEndpoint_t* object, const CAResponseInfo_t* LOGI("Data[%d]: %s\n", responseInfo->info.options[i].optionLength, responseInfo->info.options[i].optionData); - if (NULL != gResponseListenerObject) + if (NULL != g_responseListenerObject) { - char optionInfo[1024] = {0,}; - sprintf(optionInfo, "Num[%d] - ID : %d, Option Length : %d", i+1, - responseInfo->info.options[i].optionID, - responseInfo->info.options[i].optionLength); - - callback("Option info: ", optionInfo); - - if (responseInfo->info.options[i].optionData != NULL) - { - uint32_t optionDataLen = strlen(responseInfo->info.options[i].optionData); - cloneOptionData = (char *) OICMalloc(sizeof(char) * (optionDataLen + 1)); - - if (cloneOptionData == NULL) - { - LOGI("CACloneRemoteEndpoint Out of memory"); - return; - } - memset(cloneOptionData, 0, sizeof(char) * (optionDataLen + 1)); - strncpy(cloneOptionData, responseInfo->info.options[i].optionData, optionDataLen); - callback("Option Data: ", cloneOptionData); - free(cloneOptionData); - } + char tmpbuf[30]; + sprintf(tmpbuf, "%d", i + 1); + callback("Option: ", tmpbuf); + + sprintf(tmpbuf, "%d", responseInfo->info.options[i].optionID); + callback("ID: ", tmpbuf); + + sprintf(tmpbuf, "Data:[%d]", responseInfo->info.options[i].optionLength); + callback("tmpbuf: ", responseInfo->info.options[i].optionData); } } } LOGI("############################################################\n"); - gReceived = 1; + g_received = 1; //Check if this has secure communication information if (responseInfo->info.payload) @@ -831,74 +766,74 @@ void response_handler(const CARemoteEndpoint_t* object, const CAResponseInfo_t* } } -void get_resource_uri(char *URI, char *resourceURI, int length) +void get_resource_uri(const char *URI, char *resourceURI, int length) { - char *startPos = URI; - char *temp = NULL; + const char *startPos = URI; + const char *temp = NULL; if (NULL != (temp = strstr(URI, "://"))) { startPos = strchr(temp + 3, '/'); if (!startPos) { - printf("Resource URI is missing\n"); + LOGI("Resource URI is missing\n"); return; } } - char *endPos = strchr(startPos, '?'); + const char *endPos = strchr(startPos, '?'); if (!endPos) { endPos = URI + strlen(URI); } - endPos -= 1; + --endPos; if (endPos - startPos <= length) memcpy(resourceURI, startPos + 1, endPos - startPos); - printf("URI: %s, ResourceURI:%s\n", URI, resourceURI); + LOGI("URI: %s, ResourceURI:%s\n", URI, resourceURI); } int get_secure_information(CAPayload_t payLoad) { - printf("entering get_secure_information\n"); + LOGI("entering get_secure_information\n"); if (!payLoad) { - printf("Payload is NULL\n"); + LOGI("Payload is NULL\n"); return -1; } - char *subString = NULL; + const char *subString = NULL; if (NULL == (subString = strstr(payLoad, "\"sec\":1"))) { - printf("This is not secure resource\n"); + LOGI("This is not secure resource\n"); return -1; } if (NULL == (subString = strstr(payLoad, "\"port\":"))) { - printf("This secure resource does not have port information\n"); + LOGI("This secure resource does not have port information\n"); return -1; } - char *startPos = strstr(subString, ":"); + const char *startPos = strstr(subString, ":"); if (!startPos) { - printf("Parsing failed !\n"); + LOGI("Parsing failed !\n"); return -1; } - char *endPos = strstr(startPos, "}"); + const char *endPos = strstr(startPos, "}"); if (!endPos) { - printf("Parsing failed !\n"); + LOGI("Parsing failed !\n"); return -1; } - char portStr[4] = {0}; + char portStr[6] = {0}; memcpy(portStr, startPos + 1, (endPos-1) - startPos); - printf("secured port is: %s\n", portStr); + LOGI("secured port is: %s\n", portStr); return atoi(portStr); } @@ -913,39 +848,39 @@ CAResult_t get_network_type(int selectedNetwork) } if (number & CA_ETHERNET) { - gSelectedNwType = CA_ETHERNET; + g_selectedNwType = CA_ETHERNET; return CA_STATUS_OK; } if (number & CA_WIFI) { - gSelectedNwType = CA_WIFI; + g_selectedNwType = CA_WIFI; return CA_STATUS_OK; } if (number & CA_EDR) { - gSelectedNwType = CA_EDR; + g_selectedNwType = CA_EDR; return CA_STATUS_OK; } if (number & CA_LE) { - gSelectedNwType = CA_LE; + g_selectedNwType = CA_LE; return CA_STATUS_OK; } return CA_NOT_SUPPORTED; } -void callback(char *subject, char *receivedData) +void callback(char *subject, char *receicedData) { JNIEnv* env = NULL; int status = (*g_jvm)->GetEnv(g_jvm, (void **) &env, JNI_VERSION_1_6); int res = (*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL); - jclass cls = (*env)->GetObjectClass(env, gResponseListenerObject); - jmethodID mid = (*env)->GetMethodID(env, cls, "OnResponseReceived", "(Ljava/lang/String;Ljava/lang/String;)V"); + jclass cls = (*env)->GetObjectClass(env, g_responseListenerObject); + jmethodID mid = (*env)->GetMethodID(env, cls, "OnResponseReceived", + "(Ljava/lang/String;Ljava/lang/String;)V"); jstring jsubject = (*env)->NewStringUTF(env, (char*)subject); - jstring jreceivedData = (*env)->NewStringUTF(env, (char*)receivedData); - (*env)->CallVoidMethod(env, gResponseListenerObject, mid, jsubject, jreceivedData); - + jstring jreceivedData = (*env)->NewStringUTF(env, (char*)receicedData); + (*env)->CallVoidMethod(env, g_responseListenerObject, mid, jsubject, jreceivedData); } diff --git a/resource/csdk/connectivity/samples/android/sample_service/jni/com_iotivity_service_RMInterface.h b/resource/csdk/connectivity/samples/android/sample_service/jni/com_iotivity_service_RMInterface.h index 6f6717a..ad39dcf 100644 --- a/resource/csdk/connectivity/samples/android/sample_service/jni/com_iotivity_service_RMInterface.h +++ b/resource/csdk/connectivity/samples/android/sample_service/jni/com_iotivity_service_RMInterface.h @@ -1,4 +1,3 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ #include /* Header for class com_iotivity_service_RMInterface */ @@ -7,14 +6,13 @@ #ifdef __cplusplus extern "C" { #endif +JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_setNativeResponseListener + (JNIEnv *, jobject, jobject); /* * Class: com_iotivity_service_RMInterface * Method: RMInitialize - * Signature: (Landroid/content/Context;)I + * Signature: (Landroid/content/Context;)V */ -JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_setNativeResponseListener - (JNIEnv *, jobject, jobject); - JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_RMInitialize (JNIEnv *, jobject, jobject); @@ -69,10 +67,10 @@ JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_RMSendRequest /* * Class: com_iotivity_service_RMInterface * Method: RMSendResponse - * Signature: (IIII)V + * Signature: (Ljava/lang/String;III)V */ JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_RMSendResponse - (JNIEnv *, jobject, jint, jint, jint, jint); + (JNIEnv *, jobject, jstring, jstring, jint, jint); /* * Class: com_iotivity_service_RMInterface @@ -110,3 +108,4 @@ JNIEXPORT void JNICALL Java_com_iotivity_service_RMInterface_RMHandleRequestResp } #endif #endif + diff --git a/resource/csdk/connectivity/samples/android/sample_service/proguard-project.txt b/resource/csdk/connectivity/samples/android/sample_service/proguard-project.txt index f2fe155..c1ff32f 100644 --- a/resource/csdk/connectivity/samples/android/sample_service/proguard-project.txt +++ b/resource/csdk/connectivity/samples/android/sample_service/proguard-project.txt @@ -18,3 +18,4 @@ #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} + diff --git a/resource/csdk/connectivity/samples/android/sample_service/res/layout/activity_main.xml b/resource/csdk/connectivity/samples/android/sample_service/res/layout/activity_main.xml index 2848a98..3b7182d 100644 --- a/resource/csdk/connectivity/samples/android/sample_service/res/layout/activity_main.xml +++ b/resource/csdk/connectivity/samples/android/sample_service/res/layout/activity_main.xml @@ -7,7 +7,7 @@ android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.iotivity.service.MainActivity" > - + - + - + - - - + + + - + - + - + - + - +