diff --git a/README b/README index 4b3a58d..a3ae3d4 100644 --- a/README +++ b/README @@ -35,6 +35,8 @@ $$ CPPFLAGS=-I/xyz/abc/local/include ./configure --prefix=/xyz/abc/local/ --enab $$ make V=1 $$ make install +Telemetry: use `--enable-telemetry=no` for standalone CI/L2 builds without telemetry sender libs. + 2.3 To configure and use GDBus with Bluez5 ------------------------------------------- $$ PATH=/xyz/abc/local/bin:$PATH PKG_CONFIG_PATH=/xyz/abc/local/lib/x86_64-linux-gnu/pkgconfig CPPFLAGS=-I/xyz/abc/local/include ./configure --prefix=/xyz/abc/local/ --enable-btr-ifce=gdbus_bluez5 diff --git a/configure.ac b/configure.ac index 0461c38..7b8fc37 100644 --- a/configure.ac +++ b/configure.ac @@ -53,6 +53,8 @@ PKG_CHECK_MODULES([DBUS], [dbus-1]) BTR_CORE_SRC="src" BTR_CORE_TEST="tests" BTR_CORE_LOGGER_LIBS=" " +TELEMETRY_MSGLIBS=" " +TELEMETRY_CFLAGS=" " BTR_IFCE_DBUS_BLUEZ4=" " BTR_IFCE_DBUS_BLUEZ5=" " BTR_IFCE_GDBUS_BLUEZ5=" " @@ -176,6 +178,32 @@ AS_IF([test "x$rdk_logger_ok" = "xyes"], [ fi ], []) +# Check for telemetry sender library +AC_ARG_ENABLE([telemetry], + AS_HELP_STRING([--enable-telemetry],[enable telemetry sender integration (default is yes)]), + [ + case "${enableval}" in + yes) enable_telemetry=yes;; + no) enable_telemetry=no;; + *) AC_MSG_ERROR([bad value ${enableval} for --enable-telemetry]) ;; + esac + ], + [enable_telemetry=yes]) + +AS_IF([test "x$enable_telemetry" = "xyes"], [ + AC_CHECK_HEADERS([telemetry_busmessage_sender.h], [], + AC_MSG_ERROR([telemetry header (telemetry_busmessage_sender.h) not found])) + AC_CHECK_LIB(telemetry_msgsender, t2_init, + telemetry_msgsender_ok=yes, telemetry_msgsender_ok=no + AC_MSG_ERROR([telemetry library (libtelemetry_msgsender) not found])) + if test "x$telemetry_msgsender_ok" = "xyes"; then + TELEMETRY_MSGLIBS="-ltelemetry_msgsender" + TELEMETRY_CFLAGS="-DHAVE_TELEMETRY_MSGSENDER" + fi +], [ + AC_MSG_WARN([telemetry sender integration disabled]) +]) + AC_ARG_ENABLE([streaming-in], AS_HELP_STRING([--enable-streaming-in],[enable streaming in (a2dp sink) (default is yes)]), [ @@ -250,6 +278,8 @@ AM_CONDITIONAL([GATT_CLIENT], [test x$GATT_CLIENT = xtrue]) AC_SUBST(BTR_CORE_SRC) AC_SUBST(BTR_CORE_TEST) AC_SUBST(BTR_CORE_LOGGER_LIBS) +AC_SUBST(TELEMETRY_MSGLIBS) +AC_SUBST(TELEMETRY_CFLAGS) # Checks for library functions. diff --git a/include/telemetry/bt-telemetry.h b/include/telemetry/bt-telemetry.h new file mode 100644 index 0000000..cd169f8 --- /dev/null +++ b/include/telemetry/bt-telemetry.h @@ -0,0 +1,60 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2016 RDK Management + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ +/* + * @file bt-telemetry.h + * Includes telemetry wrapper utilities for Bluetooth Core and Bluetooth Manager + */ + +#ifndef __BT_TELEMETRY_H__ +#define __BT_TELEMETRY_H__ + +/** + * @brief Initialize telemetry with component name + * + * @param name Component name for telemetry identification + */ +void telemetry_init(char* name); + +/** + * @brief Send marker with string value to T2 + * + * @param marker Telemetry marker/event name (use _split suffix for split markers) + * @param value String value to send + */ +void telemetry_event_s(const char* marker, char* value); + +/** + * @brief Send marker with integer value to T2 or report count based markers + * + * @param marker Telemetry marker/event name + * @param value Integer value to send + */ +void telemetry_event_d(const char* marker, int value); + +/** + * @brief Send marker with double value to T2 + * + * @param marker Telemetry marker/event name (use _split suffix for split markers) + * @param value Double value to send + * + * Usage: telemetry_event_f("HWREV_split", 2.2); + */ +void telemetry_event_f(const char* marker, double value); + +#endif /* __BT_TELEMETRY_H__ */ diff --git a/src/Makefile.am b/src/Makefile.am index e710171..ce08cce 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,7 +21,7 @@ SUBDIRS = bt-ifce INCLUDE_FILES = BTRCORE_IFCE_INC = -I${top_srcdir}/include/bt-ifce -AM_CPPFLAGS = -Wall -Werror -I${top_srcdir}/include -I${top_srcdir}/include/logger -I${top_srcdir}/include/safec $(BTRCORE_IFCE_INC) +AM_CPPFLAGS = -Wall -Werror -I${top_srcdir}/include -I${top_srcdir}/include/telemetry -I${top_srcdir}/include/logger -I${top_srcdir}/include/safec $(BTRCORE_IFCE_INC) if IS_LIBSYSWRAPPER_ENABLED AM_LDFLAGS = -lsecure_wrapper @@ -30,15 +30,16 @@ endif lib_LTLIBRARIES = libbtrCore.la if LE_ONLY -libbtrCore_la_SOURCES = btrCore.c btrCore_le.c +libbtrCore_la_SOURCES = btrCore.c btrCore_le.c bt-telemetry.c else -libbtrCore_la_SOURCES = btrCore.c btrCore_avMedia.c btrCore_le.c +libbtrCore_la_SOURCES = btrCore.c btrCore_avMedia.c btrCore_le.c bt-telemetry.c endif -libbtrCore_la_CFLAGS = $(INCLUDE_FILES) $(GLIB_CFLAGS) $(LIBSYSWRAPPER_FLAG) $(SAFEC_CFLAGS) -libbtrCore_la_LIBADD = $(GLIB_LIBS) $(BTR_CORE_LOGGER_LIBS) $(SAFEC_LFLAGS) $(top_builddir)/src/bt-ifce/libbtrCoreIfce.la +libbtrCore_la_CFLAGS = $(INCLUDE_FILES) $(GLIB_CFLAGS) $(LIBSYSWRAPPER_FLAG) $(SAFEC_CFLAGS) $(TELEMETRY_CFLAGS) +libbtrCore_la_LIBADD = $(GLIB_LIBS) $(BTR_CORE_LOGGER_LIBS) $(SAFEC_LFLAGS) $(top_builddir)/src/bt-ifce/libbtrCoreIfce.la $(TELEMETRY_MSGLIBS) # Explicitly declare the header file U want to expose out of libbtrCore.so here include_HEADERS = $(top_srcdir)/include/btrCoreTypes.h include_HEADERS += $(top_srcdir)/include/btrCore.h include_HEADERS += $(top_srcdir)/include/btrCore_service.h +include_HEADERS += $(top_srcdir)/include/telemetry/bt-telemetry.h diff --git a/src/bt-ifce/Makefile.am b/src/bt-ifce/Makefile.am index 8c75456..71321ba 100644 --- a/src/bt-ifce/Makefile.am +++ b/src/bt-ifce/Makefile.am @@ -20,6 +20,7 @@ SUBDIRS = INCLUDE_FILES = + if BTR_IFCE_DBUS_BLUEZ4 BTRCORE_IFCE_SRCS = btrCore_dbus_bluez4.c BTRCORE_IFCE_BLUEZ_INC = $(DBUS_CFLAGS) @@ -40,16 +41,16 @@ endif endif endif -AM_CPPFLAGS = -Wall -Werror -I${top_srcdir}/include/logger -I${top_srcdir}/include/safec -I${top_srcdir}/include/bt-ifce $(BTRCORE_IFCE_BLUEZ_INC) +AM_CPPFLAGS = -Wall -Werror -I${top_srcdir}/include/logger -I${top_srcdir}/include/safec -I${top_srcdir}/include/bt-ifce $(BTRCORE_IFCE_BLUEZ_INC) -I${top_srcdir}/include/telemetry if IS_LIBSYSWRAPPER_ENABLED AM_LDFLAGS = -lsecure_wrapper endif - + lib_LTLIBRARIES = libbtrCoreIfce.la libbtrCoreIfce_la_SOURCES = $(BTRCORE_IFCE_SRCS) -libbtrCoreIfce_la_CFLAGS = $(INCLUDE_FILES) $(GLIB_CFLAGS) $(LIBSYSWRAPPER_FLAG) $(SAFEC_CFLAGS) -libbtrCoreIfce_la_LIBADD = $(GLIB_LIBS) $(BTR_CORE_LOGGER_LIBS) $(BTRCORE_IFCE_BLUEZ_LIB) $(UDEV_LIB) $(SAFEC_LFLAGS) +libbtrCoreIfce_la_CFLAGS = $(INCLUDE_FILES) $(GLIB_CFLAGS) $(LIBSYSWRAPPER_FLAG) $(SAFEC_CFLAGS) $(TELEMETRY_CFLAGS) +libbtrCoreIfce_la_LIBADD = $(GLIB_LIBS) $(BTR_CORE_LOGGER_LIBS) $(BTRCORE_IFCE_BLUEZ_LIB) $(UDEV_LIB) $(SAFEC_LFLAGS) $(TELEMETRY_MSGLIBS) if BTR_IFCE_GDBUS_BLUEZ5 libbtrCoreIfce_la_CFLAGS += $(GIO_CFLAGS) $(GIO_UNIX_CFLAGS) diff --git a/src/bt-ifce/btrCore_gdbus_bluez5.c b/src/bt-ifce/btrCore_gdbus_bluez5.c index 0b1a0f4..f967ff2 100644 --- a/src/bt-ifce/btrCore_gdbus_bluez5.c +++ b/src/bt-ifce/btrCore_gdbus_bluez5.c @@ -39,6 +39,7 @@ /* Interface lib Headers */ #include "btrCore_logger.h" +#include "bt-telemetry.h" /* Local Headers */ #include "btrCore_bt_ifce.h" @@ -896,6 +897,15 @@ btrCore_BTParseDevice ( apstBTDeviceInfo->bConnected = bluez_device1_get_connected(dev_proxy); BTRCORELOG_INFO ("bConnected = %d\n", apstBTDeviceInfo->bConnected); + { + //This is telemetry log. If we change this print,need to change and configure the telemetry string in xconf server. + char buffer[64]; + snprintf(buffer, sizeof(buffer), "bPaired = %d", apstBTDeviceInfo->bPaired); + telemetry_event_s("BTpair_split", buffer); + snprintf(buffer, sizeof(buffer), "bConnected = %d", apstBTDeviceInfo->bConnected); + telemetry_event_s("BTconn_split", buffer); + } + apstBTDeviceInfo->ui16Appearance = bluez_device1_get_appearance(dev_proxy); BTRCORELOG_INFO ("ui16Appearance = %d\n", apstBTDeviceInfo->ui16Appearance); @@ -5337,7 +5347,9 @@ btrCore_BTStartDiscoveryCb ( BTRCORELOG_INFO("Discovery started successfully\n"); } else { - BTRCORELOG_INFO("Discovery start failed - %s\n",error->message); + //This is telemetry log. If we change this marker name, need to change and configure the telemetry marker in xconf server. + telemetry_event_d("BT_ERR_DiscStartFail", 1); + BTRCORELOG_INFO("Discovery start failed - %s\n", error ? error->message : "Unknown error"); } } @@ -5358,7 +5370,9 @@ btrCore_BTStopDiscoveryCb ( BTRCORELOG_INFO("Discovery stopped successfully\n"); } else { - BTRCORELOG_INFO("Discovery stop failed - %s\n",error->message); + //This is telemetry log. If we change this marker name, need to change and configure the telemetry marker in xconf server. + telemetry_event_d("BT_ERR_DiscStopFail", 1); + BTRCORELOG_INFO("Discovery stop failed - %s\n", error ? error->message : "Unknown error"); } } diff --git a/src/bt-telemetry.c b/src/bt-telemetry.c new file mode 100644 index 0000000..0c8642f --- /dev/null +++ b/src/bt-telemetry.c @@ -0,0 +1,113 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2016 RDK Management + * + * 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. +*/ +/* + * bt-telemetry.c + * Implementation of telemetry wrapper utilities for Bluetooth Core and Bluetooth Manager + */ + +#include + +#ifdef HAVE_TELEMETRY_MSGSENDER +#include +#endif + +#include "btrCore_logger.h" +#include "bt-telemetry.h" + +/** + * @brief Initialize telemetry with component name + */ +void telemetry_init(char* name) +{ + if (name == NULL) { + BTRCORELOG_ERROR("T2: Failed to initialize telemetry - component name is NULL\n"); + return; + } + +#ifdef HAVE_TELEMETRY_MSGSENDER + BTRCORELOG_INFO("T2: Initializing telemetry with component name=\"%s\"\n", name); + t2_init(name); +#else + BTRCORELOG_INFO("T2: telemetry sender disabled - telemetry_init skipped for \"%s\"\n", name); +#endif +} + +/** + * @brief Send marker with string value to T2 + */ +void telemetry_event_s(const char* marker, char* value) +{ + if (marker == NULL) { + BTRCORELOG_ERROR("T2: telemetry_event_s - marker is NULL\n"); + return; + } + if (value == NULL) { + BTRCORELOG_ERROR("T2: telemetry_event_s - value is NULL\n"); + return; + } + +#ifdef HAVE_TELEMETRY_MSGSENDER + T2ERROR t2error = t2_event_s(marker, value); + if (t2error != T2ERROR_SUCCESS) { + BTRCORELOG_ERROR("t2_event_s(\"%s\", \"%s\") returned error code %d\n", marker, value, t2error); + } +#else + BTRCORELOG_INFO("T2: telemetry sender disabled - telemetry_event_s skipped for %s\n", marker); +#endif +} + +/** + * @brief Send marker with integer value to T2 or report count based markers + */ +void telemetry_event_d(const char* marker, int value) +{ + if (marker == NULL) { + BTRCORELOG_ERROR("T2: telemetry_event_d - marker is NULL\n"); + return; + } + +#ifdef HAVE_TELEMETRY_MSGSENDER + T2ERROR t2error = t2_event_d(marker, value); + if (t2error != T2ERROR_SUCCESS) { + BTRCORELOG_ERROR("t2_event_d(\"%s\", %d) returned error code %d\n", marker, value, t2error); + } +#else + BTRCORELOG_INFO("T2: telemetry sender disabled - telemetry_event_d skipped for %s\n", marker); +#endif +} + +/** + * @brief Send marker with double value to T2 + */ +void telemetry_event_f(const char* marker, double value) +{ + if (marker == NULL) { + BTRCORELOG_ERROR("T2: telemetry_event_f - marker is NULL\n"); + return; + } + +#ifdef HAVE_TELEMETRY_MSGSENDER + T2ERROR t2error = t2_event_f(marker, value); + if (t2error != T2ERROR_SUCCESS) { + BTRCORELOG_ERROR("t2_event_f(\"%s\", %f) returned error code %d\n", marker, value, t2error); + } +#else + BTRCORELOG_INFO("T2: telemetry sender disabled - telemetry_event_f skipped for %s\n", marker); +#endif +} diff --git a/src/btrCore.c b/src/btrCore.c index c97a173..9216eb9 100644 --- a/src/btrCore.c +++ b/src/btrCore.c @@ -42,6 +42,7 @@ /* Interface lib Headers */ #include "btrCore_logger.h" +#include "bt-telemetry.h" #include "safec_lib.h" /* Local Headers */ @@ -3111,7 +3112,15 @@ btrCore_OutTask ( BTRCORELOG_INFO ("Unsupported device detected: %s\n", lpstBTDeviceInfo->pcModalias); //This is telemetry log. If we change this print,need to change and configure the telemetry string in xconf server. - BTRCORELOG_ERROR ("Failed to pair a device name,class,apperance,modalias: %s,%u,%u,v%04Xp%04Xd%04X\n", + char buffer[256]; + snprintf(buffer, sizeof(buffer), "Failed to pair a device name,class,apperance,modalias: %s,%u,%hu,v%04Xp%04Xd%04X", + pstlhBTRCore->stScannedDevicesArr[i32LoopIdx].pcDeviceName, pstlhBTRCore->stScannedDevicesArr[i32LoopIdx].ui32DevClassBtSpec, + pstlhBTRCore->stScannedDevicesArr[i32LoopIdx].ui16DevAppearanceBleSpec, + pstlhBTRCore->stScannedDevicesArr[i32LoopIdx].ui32ModaliasVendorId, + pstlhBTRCore->stScannedDevicesArr[i32LoopIdx].ui32ModaliasProductId, + pstlhBTRCore->stScannedDevicesArr[i32LoopIdx].ui32ModaliasDeviceId); + telemetry_event_s("BTPairFail_split", buffer); + BTRCORELOG_ERROR ("Failed to pair a device name,class,apperance,modalias: %s,%u,%hu,v%04Xp%04Xd%04X\n", pstlhBTRCore->stScannedDevicesArr[i32LoopIdx].pcDeviceName, pstlhBTRCore->stScannedDevicesArr[i32LoopIdx].ui32DevClassBtSpec, pstlhBTRCore->stScannedDevicesArr[i32LoopIdx].ui16DevAppearanceBleSpec, pstlhBTRCore->stScannedDevicesArr[i32LoopIdx].ui32ModaliasVendorId, @@ -3138,6 +3147,12 @@ btrCore_OutTask ( } else { //This is telemetry log. If we change this print,need to change and configure the telemetry string in xconf server. + char buffer[128]; + snprintf(buffer, sizeof(buffer), "Unsupport BT device detected v%04Xp%04Xd%04X", + pstlhBTRCore->stScannedDevicesArr[i32LoopIdx].ui32ModaliasVendorId, + pstlhBTRCore->stScannedDevicesArr[i32LoopIdx].ui32ModaliasProductId, + pstlhBTRCore->stScannedDevicesArr[i32LoopIdx].ui32ModaliasDeviceId); + telemetry_event_s("BT_INFO_NotSupp_split", buffer); BTRCORELOG_INFO ("Unsupport BT device detected v%04Xp%04Xd%04X\n", pstlhBTRCore->stScannedDevicesArr[i32LoopIdx].ui32ModaliasVendorId, pstlhBTRCore->stScannedDevicesArr[i32LoopIdx].ui32ModaliasProductId, @@ -3749,6 +3764,8 @@ BTRCore_GetAdapter ( if (!pstlhBTRCore->curAdapterPath) { if ((pstlhBTRCore->curAdapterPath = BtrCore_BTGetAdapterPath(pstlhBTRCore->connHdl, NULL)) == NULL) { //mikek hard code to default adapter for now + //This is telemetry log. If we change this marker name, need to change and configure the telemetry marker in xconf server. + telemetry_event_d("BT_ERR_GetBTAdapterFail", 1); BTRCORELOG_ERROR ("Failed to get BT Adapter"); return enBTRCoreInvalidAdapter; } @@ -4458,6 +4475,8 @@ BTRCore_PairDevice ( pDeviceAddress, pairingOp) < 0) { BTRCORELOG_ERROR ("Failed to pair a device\n"); + //This is telemetry log. If we change this marker name, need to change and configure the telemetry marker in xconf server. + telemetry_event_d("BT_ERR_FailToPair", 1); return enBTRCorePairingFailed; } @@ -5257,6 +5276,8 @@ enBTRCoreRet BTRCore_newBatteryLevelDevice (tBTRCoreHandle hBTRCore) } else { + //This is telemetry log. If we change this marker name, need to change and configure the telemetry marker in xconf server. + telemetry_event_d("BT_ERR_BatteryThreadFail", 1); BTRCORELOG_ERROR("Battery thread creation failed\n"); } return enBTRCoreSuccess; diff --git a/unitTest/support/Untitled/telemetry_busmessage_sender.h b/unitTest/support/Untitled/telemetry_busmessage_sender.h new file mode 100644 index 0000000..e3819a6 --- /dev/null +++ b/unitTest/support/Untitled/telemetry_busmessage_sender.h @@ -0,0 +1,53 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2016 RDK Management + * + * 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. +*/ +/* + * Mock header for unit test simulation of telemetry_busmessage_sender.h + */ +#ifndef TELEMETRY_BUSMESSAGE_SENDER_H +#define TELEMETRY_BUSMESSAGE_SENDER_H + +// Minimal type definitions for unit test +#include +#include + +typedef enum { + T2ERROR_SUCCESS = 0, + T2ERROR_FAILURE = 1 +} T2ERROR; + +static inline void t2_init(char* name) { + // Stub: do nothing +} + +static inline T2ERROR t2_event_s(const char* marker, char* value) { + // Stub: always return success + return T2ERROR_SUCCESS; +} + +static inline T2ERROR t2_event_d(const char* marker, int value) { + // Stub: always return success + return T2ERROR_SUCCESS; +} + +static inline T2ERROR t2_event_f(const char* marker, double value) { + // Stub: always return success + return T2ERROR_SUCCESS; +} + +#endif // TELEMETRY_BUSMESSAGE_SENDER_H diff --git a/unitTest/test_btrCore.c b/unitTest/test_btrCore.c index a382f36..be1cd55 100644 --- a/unitTest/test_btrCore.c +++ b/unitTest/test_btrCore.c @@ -20,6 +20,7 @@ /* Local Headers */ #include "btrCore.h" #include "btrCore_service.h" +#include "bt-telemetry.h" #include "mock_btrCore_avMedia.h" @@ -3497,7 +3498,7 @@ _mock_BTGetPairedDeviceInfo3 ( return 0; } - + void test_BTRCore_GetListOfPairedDevices_should_GetPairedDevicesSuccessfully(void) { stBTRCoreHdl* hBTRCore = malloc(sizeof(stBTRCoreHdl));