--- /dev/null
+[Unit]
+Description=Service to run BT HCI logger forcefully
+
+[Service]
+Type=oneshot
+User=root
+Group=root
+ExecStart=/usr/etc/bluetooth/bt-run-hci-logger.sh force start hcidump
+ExecStop=/usr/etc/bluetooth/bt-run-hci-logger.sh force stop
+RemainAfterExit=yes
+StandardOutput=journal+console
+StandardError=inherit
--- /dev/null
+[Unit]
+Description=Service to run BT HCI logdump
+
+[Service]
+User=system
+Group=system
+Type=oneshot
+ExecStart=/usr/etc/bluetooth/bt-hci-logdump.sh %I
+StandardOutput=journal+console
+StandardError=inherit
--- /dev/null
+[Unit]
+Description=Service to run BT HCI logger normally
+
+[Service]
+Type=oneshot
+User=root
+Group=root
+ExecStart=/usr/etc/bluetooth/bt-run-hci-logger.sh normal start btmon
+ExecStop=/usr/etc/bluetooth/bt-run-hci-logger.sh normal stop
+RemainAfterExit=yes
+StandardOutput=journal+console
+StandardError=inherit
export LDFLAGS+=" -Wl,--rpath=/usr/lib -Wl,--as-needed -Wl,--unresolved-symbols=ignore-in-shared-libs -pie"
%cmake
-%cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
+%cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \
+%if 0%{?tizen_build_binary_release_type_eng}
+ -DBT_HCI_LOG_SIZE=10
+%else
+ -DBT_HCI_LOG_SIZE=5
+%endif
+
%__make %{?_smp_mflags}
%install
install -m 0755 scripts/bt-dev-end.sh %{buildroot}%{_prefix}/etc/bluetooth/bt-dev-end.sh
install -D -m 0644 LICENSE.APLv2 %{buildroot}%{_datadir}/license/bluetooth-tools
+install -D -m 0644 packaging/bluetooth-hci-logger.service %{buildroot}%{_libdir}/systemd/system/bluetooth-hci-logger.service
+install -D -m 0644 packaging/bluetooth-force-hci-logger.service %{buildroot}%{_libdir}/systemd/system/bluetooth-force-hci-logger.service
+install -D -m 0644 packaging/bluetooth-hci-dump@.service %{buildroot}%{_libdir}/systemd/system/bluetooth-hci-dump@.service
+
+%post
+mkdir -p %{_sysconfdir}/systemd/default-extra-dependencies/ignore-units.d/
+ln -sf %{_libdir}/systemd/system/bluetooth-hci-logger.service %{_sysconfdir}/systemd/default-extra-dependencies/ignore-units.d/
+ln -sf %{_libdir}/systemd/system/bluetooth-force-hci-logger.service %{_sysconfdir}/systemd/default-extra-dependencies/ignore-units.d/
+
+
%files
%manifest %{name}.manifest
%defattr(-,root,root,-)
%attr(0755,-,-) %{_prefix}/etc/bluetooth/bt-edutm-mode-on.sh
%attr(0755,-,-) %{_prefix}/etc/bluetooth/bt-edutm-off.sh
%attr(0755,-,-) %{_prefix}/etc/bluetooth/bt-hci-logdump.sh
-%attr(0755,-,-) %{_prefix}/etc/bluetooth/bt-run-hcidump.sh
+%attr(0755,-,-) %{_prefix}/etc/bluetooth/bt-run-hci-logger.sh
%{_datadir}/license/bluetooth-tools
%{_unitdir}/multi-user.target.wants/bluetooth-address.service
%{_unitdir}/bluetooth-address.service
+%{_libdir}/systemd/system/bluetooth-hci-logger.service
+%{_libdir}/systemd/system/bluetooth-force-hci-logger.service
+%{_libdir}/systemd/system/bluetooth-hci-dump@.service
%post profile_common
pushd %{_prefix}/etc/bluetooth/
# For All
+
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/bt-run-hci-logger.sh.in ${CMAKE_CURRENT_BINARY_DIR}/bt-run-hci-logger.sh @ONLY)
+
INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bt-edutm-on.sh DESTINATION etc/bluetooth)
INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bt-edutm-dev-up.sh DESTINATION etc/bluetooth)
INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bt-edutm-mode-on.sh DESTINATION etc/bluetooth)
INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bt-edutm-off.sh DESTINATION etc/bluetooth)
INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bt-hci-logdump.sh DESTINATION etc/bluetooth)
-INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bt-run-hcidump.sh DESTINATION etc/bluetooth)
+INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/bt-run-hci-logger.sh DESTINATION etc/bluetooth)
#!/bin/sh
-PATH=/bin:/usr/bin:/sbin:/usr/sbin
#--------------------------------------
# bluetooth hci
#--------------------------------------
+CHOWN="/bin/chown"
+
+eval $(tzplatform-get TZ_USER_DOWNLOADS)
+
+DUMP_BASE_DIR=$1
BLUETOOTH_DEBUG=${1}/bluetooth
+
PREV_PWD=${PWD}
-BT_DUMP_DIR=/opt/usr/media/Others/.bt_dump
+#BT_DUMP_DIR=${TZ_USER_DOWNLOADS}/.bt_dump
+BT_DUMP_DIR=/opt/usr/media/Downloads/.bt_dump
+
+if [ "$1" = "syslog" ]
+then
+ DUMP_BASE_DIR=${BT_DUMP_DIR}
+ BLUETOOTH_DEBUG=${DUMP_BASE_DIR}/bluetooth
+fi
+
+BT_DUMP_TMP_DIR=/tmp/bt_dump
+LOG_FILE="bt_hcidump.log"
+
+process_btdump()
+{
+ if [ -e btmon.log.1 -a -e btmon.log ]
+ then
+ /usr/bin/tail -c +17 btmon.log > btmon.log_bin
+ /bin/cat btmon.log.1 btmon.log_bin > final.log
+ /usr/bin/btsnoop -s final.log
+ if [ $? -eq 0 ]
+ then
+ /bin/rm -f btmon.log_bin btmon.log.1 btmon.log final.log
+ LOG_FILE="btsnoop_*.log"
+ else
+ /bin/rm -f btmon.log_bin btmon.log.1 btmon.log
+ /bin/mv final.log btmon.log
+ LOG_FILE=""
+ fi
+ elif [ -e bt_hcidump.log.1 -a -e bt_hcidump.log ]
+ then
+ /usr/bin/tail -c +17 bt_hcidump.log > bt_hcidump.log_bin
+ /bin/cat bt_hcidump.log.1 bt_hcidump.log_bin > bt_hcidump.log
+ /bin/rm -f bt_hcidump.log_bin bt_hcidump.log.1
+ elif [ -e btmon.log ]
+ then
+ /usr/bin/btsnoop -s btmon.log
+ if [ $? -eq 0 ]
+ then
+ /bin/rm -f btmon.log
+ LOG_FILE="btsnoop_*.log"
+ else
+ LOG_FILE=""
+ fi
+ fi
+
+ if [ "${LOG_FILE}a" != "a" ]
+ then
+ /usr/bin/rename .log .cfa ${LOG_FILE}
+ fi
+}
if [ ! -e ${BT_DUMP_DIR} ]
then
+ if [ "$1" = "syslog" ]
+ then
+ /bin/mkdir -p ${BT_DUMP_DIR}
+ /bin/chown 200:200 ${BT_DUMP_DIR}
+ else
+ exit 0
+ fi
+fi
+
+if [ "$1" = "syslog" ]
+then
+ cp /var/log/messages ${BT_DUMP_DIR}/messages_`date "+%b_%d_%H:%M:%S_%Y"`
+ cp /var/log/messages.0 ${BT_DUMP_DIR}/messages.0_`date "+%b_%d_%H:%M:%S_%Y"`
+ # Skip the orginal bt_dump extract part
exit 0
fi
+if [ ${DUMP_BASE_DIR} ]
+then
+ cd ${DUMP_BASE_DIR}
+fi
+
/bin/mkdir -p ${BLUETOOTH_DEBUG}
+${CHOWN} 200:200 ${BLUETOOTH_DEBUG}
+
+/bin/mkdir -p ${BT_DUMP_TMP_DIR}
+/bin/cp -rf ${BT_DUMP_DIR}/* ${BT_DUMP_TMP_DIR}
+
+cd ${BT_DUMP_TMP_DIR}
+process_btdump
+
+if [ -e "${BT_DUMP_TMP_DIR}/old_hcidump" ]
+then
+ cd ${BT_DUMP_TMP_DIR}/old_hcidump
+ process_btdump
+fi
+
+cd ${BT_DUMP_TMP_DIR}
+/bin/tar czf ${BLUETOOTH_DEBUG}/bt_dump.tar.gz *
-cd ${BT_DUMP_DIR}
-/bin/tar -cvzf ${BLUETOOTH_DEBUG}/bt_dump.tar.gz *
+cd ${BLUETOOTH_DEBUG}
+${CHOWN} 200:200 ${BLUETOOTH_DEBUG}/bt_dump.tar.gz
+/bin/rm -rf ${BT_DUMP_TMP_DIR}
cd ${PREV_PWD}
--- /dev/null
+#!/bin/sh
+
+MKDIR="/bin/mkdir"
+CP="/bin/cp"
+RM="/bin/rm"
+MV="/bin/mv"
+DATE="/bin/date"
+GREP="/bin/grep"
+CUT="/usr/bin/cut"
+PGREP="/usr/bin/pgrep"
+BTMON="/usr/bin/btmon"
+HCIDUMP="/usr/bin/hcidump"
+CHOWN="/bin/chown"
+
+eval $(tzplatform-get TZ_USER_DOWNLOADS)
+
+# When *#9900# is typed, this is executed to archive logs.
+LOGDUMP_DIR="/opt/etc/dump.d/module.d"
+LOGDUMP_PATH="${LOGDUMP_DIR}/bt-hci-logdump.sh"
+
+# BT HCI Log is saved here
+#LOG_BASEDIR=${TZ_USER_DOWNLOADS}
+LOG_BASEDIR=/opt/usr/media/Downloads
+LOG_DIR="${LOG_BASEDIR}/.bt_dump"
+
+HCIDUMP_LOG_FILENAME="bt_hcidump.log"
+BTMON_LOG_FILENAME="btmon.log"
+
+HCIDUMP_LOG_PATH="${LOG_DIR}/${HCIDUMP_LOG_FILENAME}"
+BTMON_LOG_PATH="${LOG_DIR}/${BTMON_LOG_FILENAME}"
+TMP_PID_FILE="/tmp/.bt_hci_logger.pid"
+
+DUMP_SIZE=@BT_HCI_LOG_SIZE@
+
+## Step 1. Check debug mode and force configuration
+debug_mode=`/bin/cat /sys/module/sec_debug/parameters/enable`
+debug_mode_user=`/bin/cat /sys/module/sec_debug/parameters/enable_user`
+
+case "$1" in
+ force)
+# Re-initialize the log directory for force mode
+ LOG_DIR="${LOG_DIR}/force"
+ HCIDUMP_LOG_PATH="${LOG_DIR}/${HCIDUMP_LOG_FILENAME}"
+ BTMON_LOG_PATH="${LOG_DIR}/${BTMON_LOG_FILENAME}"
+ TMP_PID_FILE="/tmp/.bt_hci_force_logger.pid"
+ ;;
+ normal)
+ if [ ${debug_mode} != '1' -a ${debug_mode_user} != '1' ]
+ then
+ if [ -e ${LOG_DIR} ]
+ then
+ ${RM} -rf ${LOG_DIR}
+ fi
+
+ if [ ! -e ${TMP_PID_FILE} ]
+ then
+ exit 0
+ fi
+
+ bt_hci_logger_pid=`cat ${TMP_PID_FILE}`
+ kill $bt_hci_logger_pid
+ ${RM} -f ${TMP_PID_FILE}
+ exit 0
+ fi
+ ;;
+ *)
+ echo "Usage : bt-run-hci-logger.sh {force | normal} {start | stop} {hcidump | btmon} [keep_old_dump]"
+ exit 255
+ ;;
+esac
+
+## Step 2. Check start / stop parameter
+case "$2" in
+ start)
+ ;;
+ stop)
+ if [ ! -e ${TMP_PID_FILE} ]
+ then
+ exit 0
+ fi
+
+ bt_hci_logger_pid=`cat ${TMP_PID_FILE}`
+ kill $bt_hci_logger_pid
+ ${RM} -f ${TMP_PID_FILE}
+ exit 0
+ ;;
+ *)
+ echo "Usage : bt-run-hci-logger.sh {force | normal} {start | stop} {hcidump | btmon} [keep_old_dump]"
+ exit 255
+ ;;
+esac
+
+## Step 3. Configure log tool
+case "$3" in
+ hcidump)
+ LOG_TOOL=${HCIDUMP}
+ LOG_PATH=${HCIDUMP_LOG_PATH}
+ LOG_OPT_END="-c 2 -s ${DUMP_SIZE}"
+ ;;
+ btmon)
+ BTMON_DUMP_SIZE=`expr ${DUMP_SIZE} \* 1000000`
+ LOG_TOOL=${BTMON}
+ LOG_PATH=${BTMON_LOG_PATH}
+ LOG_OPT_END="-C 2 -W ${BTMON_DUMP_SIZE}"
+ ;;
+ *)
+ echo "Usage : bt-run-hci-logger.sh {force | normal} {start | stop} {hcidump | btmon} [keep_old_dump]"
+ exit 255
+ ;;
+esac
+
+## Step 4. Configure keep_old_dump option
+case "$4" in
+ keep_old_dump)
+ KEEP_OLD_DUMP=1
+ LOG_PATH="${LOG_PATH}_`${DATE} +%s_%N`"
+ ;;
+ *)
+ KEEP_OLD_DUMP=0
+ ;;
+esac
+
+## Step 5. Copy a log archive script for all_log_dump.sh
+if [ ! -e ${LOGDUMP_PATH} ]
+then
+ ${MKDIR} -p ${LOGDUMP_DIR}
+ ${CP} -f /usr/etc/bluetooth/bt-hci-logdump.sh ${LOGDUMP_PATH}
+fi
+
+## Step 6. Check logging base directory
+# If it doesn't exist, exit
+if [ ! -e ${LOG_BASEDIR} ]
+then
+ exit 0
+fi
+
+## Step 7. Backup old log and Start logging
+if [ ! -e ${LOG_DIR}/old_hcidump ]
+then
+ ${MKDIR} -p ${LOG_DIR}/old_hcidump
+ #Make system owner/group to allow systemd.service logging service
+ ${CHOWN} -R 200:200 ${LOG_DIR}
+fi
+
+if [ ${KEEP_OLD_DUMP} = '0' ]
+then
+ ${RM} -f ${LOG_DIR}/old_hcidump/*
+fi
+
+${MV} ${LOG_DIR}/*.log* ${LOG_DIR}/old_hcidump/;\
+${LOG_TOOL} -w ${LOG_PATH} ${LOG_OPT_END} > /dev/null &
+echo $! > ${TMP_PID_FILE}
+
+exit 0
+++ /dev/null
-#!/bin/sh
-PATH=/bin:/usr/bin:/sbin:/usr/sbin
-
-HCIDUMP_BASEDIR="/opt/usr/media/Others"
-HCIDUMP_DIR="${HCIDUMP_BASEDIR}/.bt_dump"
-HCIDUMP_FILENAME="bt_hcidump.log"
-HCIDUMP_PATH="${HCIDUMP_DIR}/${HCIDUMP_FILENAME}"
-
-LOGDUMP_DIR="/opt/etc/dump.d/module.d"
-LOGDUMP_PATH="${LOGDUMP_DIR}/bt-hci-logdump.sh"
-
-debug_mode=`/bin/cat /sys/module/sec_debug/parameters/enable`
-debug_mode_user=`/bin/cat /sys/module/sec_debug/parameters/enable_user`
-
-if [ ${debug_mode} = '1' -o ${debug_mode_user} = '1' ]
-then
- if [ -e /usr/sbin/hcidump ]
- then
- # When *#9900# is typed, this is executed to archive logs.
- /bin/mkdir -p ${LOGDUMP_DIR}
- /bin/cp -f /usr/etc/bluetooth/bt-hci-logdump.sh ${LOGDUMP_PATH}
-
- # Create base directory as proper owner and smack rule
- # if it doesn't exist
- if [ ! -e ${HCIDUMP_BASEDIR} ]
- then
- /bin/mkdir - p ${HCIDUMP_BASEDIR}
- /bin/chown 5000:5000 ${HCIDUMP_BASEDIR}
- /usr/bin/chsmack -t -a 'system::media' ${HCIDUMP_BASEDIR}
- fi
- /bin/mkdir -p ${HCIDUMP_DIR}/old_hcidump
- /bin/rm -f ${HCIDUMP_DIR}/old_hcidump/*
- /bin/mv ${HCIDUMP_PATH}* ${HCIDUMP_DIR}/old_hcidump/
- /usr/sbin/hcidump -w ${HCIDUMP_PATH} &
- fi
-elif [ -e ${HCIDUMP_DIR} ]
-then
- /bin/rm -rf ${HCIDUMP_DIR}
-fi
# If radio is on, should not call the device down script
#/usr/etc/bluetooth/bt-dev-end.sh
+# Stop HCI logging
+systemctl stop bluetooth-hci-logger.service
+
# Kill BlueZ bluetooth stack
killall obexd obex-client
killall bt-syspopup
# Remove BT device
/usr/etc/bluetooth/bt-dev-end.sh
+# Stop HCI logging
+systemctl stop bluetooth-hci-logger.service
+
# Kill BlueZ bluetooth stack
killall obexd obex-client
killall bt-syspopup
# Script for executing Bluetooth stack
#
+# Start HCI logging
+systemctl start bluetooth-hci-logger.service
+
# Register BT Device
/usr/etc/bluetooth/bt-dev-start.sh
if !(/usr/bin/hciconfig | grep hci); then
echo "Registering BT device is failed."
+ systemctl stop bluetooth-hci-logger.service
exit 1
fi
# Remove BT device
/usr/etc/bluetooth/bt-dev-end.sh
+# Stop HCI logging
+systemctl stop bluetooth-hci-logger.service
+
# Kill BlueZ bluetooth stack
killall obexd obex-client
killall bluetooth-pb-agent
#!/bin/sh
PATH=/bin:/usr/bin:/sbin:/usr/sbin
-HCIDUMP_DIR="/opt/usr/media/.bluetooth"
-HCIDUMP_FILENAME="bt_hcidump.log"
-HCIDUMP_PATH="${HCIDUMP_DIR}/${HCIDUMP_FILENAME}"
-LOGDUMP_DIR="/opt/etc/dump.d/module.d"
-LOGDUMP_PATH="${LOGDUMP_DIR}/bt-hci-logdump.sh"
RFKILL=/usr/sbin/rfkill
GREP=/usr/bin/grep
HFP_HF=hfp_hf
# Script for executing Bluetooth stack
#
+# Start HCI logging
+systemctl start bluetooth-hci-logger.service
+
# Register BT Device
/usr/etc/bluetooth/bt-dev-start.sh
if !(/usr/bin/hciconfig | grep hci); then
echo "Registering BT device is failed."
+ systemctl stop bluetooth-hci-logger.service
exit 1
fi
-debug_mode=`cat /sys/module/sec_debug/parameters/enable`
-debug_mode_user=`cat /sys/module/sec_debug/parameters/enable_user`
-
-if [ ${debug_mode} = '1' -o ${debug_mode_user} = '1' ]
-then
- if [ -e /usr/sbin/hcidump ]
- then
- # When *#9900# is typed, this is executed to archive logs. #
- /bin/mkdir -p ${LOGDUMP_DIR}
- /bin/cp -f /usr/etc/bluetooth/bt-hci-logdump.sh ${LOGDUMP_PATH}
-
- /bin/mkdir -p ${HCIDUMP_DIR}/old_hcidump
- /bin/rm -f ${HCIDUMP_DIR}/old_hcidump/*
- /bin/mv ${HCIDUMP_PATH}* ${HCIDUMP_DIR}/old_hcidump/
- /usr/sbin/hcidump -w ${HCIDUMP_PATH} &
- fi
-elif [ -e ${HCIDUMP_DIR} ]
-then
- /bin/rm -rf ${HCIDUMP_DIR}
-fi
-
# Execute BlueZ BT stack
echo "Run bluetoothd"
/usr/libexec/bluetooth/bluetoothd -d -C &
-/usr/bin/dbus-send --print-reply --system --type=method_call \
- --dest=org.freedesktop.systemd1 /org/freedesktop/systemd1 \
- org.freedesktop.systemd1.Manager.StartUnit \
- string:'wms.service' string:'fail'
exit 0