From 65712868eb7ee0ea52f491c3c14c1ab59f03998a Mon Sep 17 00:00:00 2001 From: Jaehoon Chung Date: Thu, 6 Apr 2023 14:42:30 +0900 Subject: [PATCH 01/16] script: build: add local build script for v5.15 Add local build ssript for v5.15. Change-Id: I0f54869889fd787eeff8acf650e270b21fd8929f Signed-off-by: Jaehoon Chung --- build.sh | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100755 build.sh diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..a678f2d --- /dev/null +++ b/build.sh @@ -0,0 +1,83 @@ +#!/bin/bash +MOD_DIR="usr/tmp_mod" +MOD_IMG="usr/modules.img" +MOD_SIZE=32 +NCPUS=`grep ^processor /proc/cpuinfo | wc -l` +NCPUS=$(($NCPUS * 2)) + +# Check this system has ccache +check_ccache() +{ + type ccache + if [ "$?" -eq "0" ]; then + CCACHE=ccache + fi +} + +function mk_modules() { + [ -e /usr/bin/make_ext4fs ] && USE_MAKE_EXT4FS=1 + if [ "$USE_MAKE_EXT4FS" != "1" ]; then + sudo ls > /dev/null + fi + + make ARCH=${ARCH} CROSS_COMPILE="$CROSS_COMPILER" modules_prepare + make ARCH=${ARCH} CROSS_COMPILE="$CROSS_COMPILER" modules -j ${NCPUS} + + if [ "$?" != "0" ]; then + echo "Failed to make modules" + exit 1 + fi + + [ -d ${MOD_DIR} ] || mkdir ${MOD_DIR} + + make ARCH=${ARCH} CROSS_COMPILE="$CROSS_COMPILER" modules_install INSTALL_MOD_PATH=${MOD_DIR} INSTALL_MOD_STRIP=1 + + if [ "$USE_MAKE_EXT4FS" == "1" ]; then + /usr/bin/make_ext4fs -b 4096 -L modules -l ${MOD_SIZE}M $MOD_IMG ${MOD_DIR}/lib/modules/ + else + dd if=/dev/zero of=${MOD_IMG} bs=1M count=${MOD_SIZE} + mkfs.ext4 -F -b 4096 -L modules ${MOD_IMG} + [ -d ${MOD_DIR}/mnt ] || mkdir ${MOD_DIR}/mnt + sudo mount -o loop ${MOD_IMG} ${MOD_DIR}/mnt + sudo cp -rf ${MOD_DIR}/lib/modules/* ${MOD_DIR}/mnt + sync + sudo umount ${MOD_DIR}/mnt + fi + rm -rf ${MOD_DIR} + ls -al ${MOD_IMG} +} + +check_ccache + +echo "riscv64" +rm -f arch/riscv/boot/Image +rm -f arch/riscv/boot/dts/starfive/*.dtb +rm -f output/Image +rm -f output/*.dtb +rm -f output/modules.img +rm -f output/*.tar + +CROSS_COMPILER=riscv64-linux-gnu- +ARCH=riscv +if ! [ -e .config ] ; then + make ARCH=${ARCH} CROSS_COMPILE="$CROSS_COMPILER" tizen_vf2_defconfig +fi +make ARCH=${ARCH} CROSS_COMPILE="$CROSS_COMPILER" -j8 +if [ ! -f "./arch/riscv/boot/Image" ]; then + echo "Build fail" + exit 1 +fi + +# Make module.img file +mk_modules + +if [ ! -d output ] ; then + mkdir ./output +fi + +cp usr/modules.img ./output + +cp ./arch/riscv/boot/Image ./output +cp ./arch/riscv/boot/dts/starfive/*.dtb ./output +tar cvf linux-visionfive2.tar -C output Image jh7110-visionfive-v2.dtb modules.img +mv linux-visionfive2.tar ./output/ -- 2.7.4 From 3fedca836be43918455ea6bba0ede4da4dac5f36 Mon Sep 17 00:00:00 2001 From: Hoegeun Kwon Date: Tue, 9 May 2023 16:20:26 +0900 Subject: [PATCH 02/16] RISCV: configs: Enable usb wireless defconfig Enable usb wireless defconfig and realtek module. Change-Id: I86a7ac58de3e7234ef6a2da05acfbeab28f3034c Signed-off-by: Hoegeun Kwon --- arch/riscv/configs/tizen_vf2_defconfig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/riscv/configs/tizen_vf2_defconfig b/arch/riscv/configs/tizen_vf2_defconfig index 708ea6c..767a93e 100644 --- a/arch/riscv/configs/tizen_vf2_defconfig +++ b/arch/riscv/configs/tizen_vf2_defconfig @@ -150,11 +150,15 @@ CONFIG_DWMAC_STARFIVE_PLAT=y CONFIG_MARVELL_PHY=y CONFIG_MICREL_PHY=y CONFIG_MOTORCOMM_PHY=y +CONFIG_USB_RTL8152=y +CONFIG_USB_LAN78XX=y +CONFIG_USB_USBNET=y CONFIG_IWLWIFI=y CONFIG_IWLDVM=y CONFIG_IWLMVM=y CONFIG_HOSTAP=y -# CONFIG_RTL_CARDS is not set +CONFIG_RTL_CARDS=m +CONFIG_RTL8192CU=m CONFIG_USB_WIFI_ECR6600U=y CONFIG_INPUT_EVDEV=y # CONFIG_INPUT_KEYBOARD is not set -- 2.7.4 From 6f3d2bf895fe5307f9958cb5b8bbd3318e56a66a Mon Sep 17 00:00:00 2001 From: Hoegeun Kwon Date: Tue, 9 May 2023 16:22:43 +0900 Subject: [PATCH 03/16] RISCV: configs: Enable usb BT defconfig Enable usb BT defconfig. Change-Id: Ibbcd86557c0adf6f80beb229622d63ad74e62e06 Signed-off-by: Hoegeun Kwon --- arch/riscv/configs/tizen_vf2_defconfig | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/riscv/configs/tizen_vf2_defconfig b/arch/riscv/configs/tizen_vf2_defconfig index 767a93e..d21eb5e 100644 --- a/arch/riscv/configs/tizen_vf2_defconfig +++ b/arch/riscv/configs/tizen_vf2_defconfig @@ -72,6 +72,7 @@ CONFIG_IP_NF_NAT=y CONFIG_IP_NF_TARGET_MASQUERADE=y CONFIG_IP_NF_TARGET_NETMAP=y CONFIG_IP_NF_TARGET_REDIRECT=y +CONFIG_6LOWPAN=y CONFIG_NETLINK_DIAG=y CONFIG_CAN=y CONFIG_IPMS_CAN=y @@ -81,10 +82,15 @@ CONFIG_BT_RFCOMM_TTY=y CONFIG_BT_BNEP=y CONFIG_BT_BNEP_MC_FILTER=y CONFIG_BT_BNEP_PROTO_FILTER=y +CONFIG_BT_HIDP=y +CONFIG_BT_6LOWPAN=y +CONFIG_BT_HCIBTUSB=m CONFIG_BT_HCIUART=y CONFIG_BT_HCIUART_H4=y +CONFIG_BT_HCIBCM203X=m CONFIG_CFG80211=y CONFIG_MAC80211=y +CONFIG_RFKILL=y CONFIG_NET_9P=y CONFIG_NET_9P_VIRTIO=y CONFIG_PCI=y -- 2.7.4 From c02eebd9466de50caa0510bbdd173a869bf7f0e9 Mon Sep 17 00:00:00 2001 From: Jaehoon Chung Date: Fri, 10 Mar 2023 15:31:40 +0900 Subject: [PATCH 04/16] packaging: Add linux-visionfive2 spec file Add linux-visionfive2 spec file to build with gbs. This is for only visionfive2 board. Change-Id: Ia9ea5f73453250814bb768bab6eeb6997797167f Signed-off-by: Jaehoon Chung --- .gbs.conf | 4 + packaging/linux-visionfive2.spec | 193 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 197 insertions(+) create mode 100644 .gbs.conf create mode 100644 packaging/linux-visionfive2.spec diff --git a/.gbs.conf b/.gbs.conf new file mode 100644 index 0000000..f744dba --- /dev/null +++ b/.gbs.conf @@ -0,0 +1,4 @@ +[general] +upstream_branch = upstream +upstream_tag = v${upstreamversion} +squash_patches_until = HEAD~10 diff --git a/packaging/linux-visionfive2.spec b/packaging/linux-visionfive2.spec new file mode 100644 index 0000000..61b457c --- /dev/null +++ b/packaging/linux-visionfive2.spec @@ -0,0 +1,193 @@ +# Ignore double dash in version for rpmbuild +%define _wrong_version_format_terminate_build 0 + +%define config_name tizen_vf2_defconfig +%define buildarch riscv +%define target_board visionfive2 +%define variant %{buildarch}-%{target_board} + +Name: visionfive2-linux-kernel +Summary: The Linux Kernel for VisionFive2 Board +Version: 5.15.0 +Release: 0 +License: GPL-2.0 +ExclusiveArch: riscv64 +Group: System/Kernel +Vendor: The Linux Community +URL: https://www.kernel.org +Source0: linux-kernel-%{version}.tar.xz +BuildRoot: %{_tmppath}/%{name}-%{PACKAGE_VERSION}-root + +%define fullVersion %{version}-%{variant} + +BuildRequires: bc +BuildRequires: module-init-tools +BuildRequires: bison +BuildRequires: flex +BuildRequires: libopenssl1.1-devel +BuildRequires: libunwind-devel +BuildRequires: libdw-devel +BuildRequires: libelf-devel +BuildRequires: elfutils +BuildRequires: xz-devel +BuildRequires: binutils-devel +BuildRequires: python3 +BuildRequires: rsync + +%description +The Linux Kernel, the operating system core itself + +# kernel +%package -n %{variant}-linux-kernel +License: GPL-2.0 +Summary: Tizen kernel for %{target_board} +Group: System/Kernel +Provides: %{variant}-kernel-uname-r = %{fullVersion} +Provides: linux-kernel = %{version}-%{release} + +%description -n %{variant}-linux-kernel +This package contains the Linux kernel for Tizen (arch %{buildarch}, target board %{target_board}) + +# modules + +%package -n %{variant}-linux-kernel-modules +Summary: Kernel modules for %{target_board} +Group: System/Kernel +Provides: %{variant}-kernel-modules = %{fullVersion} +Provides: %{variant}-kernel-modules-uname-r = %{fullVersion} + +%description -n %{variant}-linux-kernel-modules +Kernel-modules includes the loadable kernel modules(.ko files) for %{target_board} + +# devel + +%package -n %{variant}-linux-kernel-devel +License: GPL-2.0 +Summary: Linux support kernel map and etc for other packages +Group: System/Kernel +Provides: %{variant}-kernel-devel = %{fullVersion} +Provides: %{variant}-kernel-devel-uname-r = %{fullVersion} + +%description -n %{variant}-linux-kernel-devel +This package provides kernel map and etc information. + +#headers +%package -n %{variant}-linux-kernel-headers +License: GPL-2.0 +Summary: Linux support headers for userspace development +Group: System/Kernel +Provides: kernel-headers-tizen-dev + +%description -n %{variant}-linux-kernel-headers +This package provides userspaces headers from the Linux kernel. These +headers are used by the installed headers for GNU glibc and other system + libraries. + +%package -n linux-kernel-perf +Summary: The perf performance counter tool +Group: System/Kernel +Provides: perf = %{version} + +%description -n linux-kernel-perf +This package provides the "perf" tool that can be used to monitor performance +counter events as well as various kernel internal events. + +%prep +%setup -q + +%build +%{?asan:/usr/bin/gcc-unforce-options} +%{?ubsan:/usr/bin/gcc-unforce-options} + +# extract uapi headers +make headers_install %{?_smp_mflags} + +# Set config file +make %{config_name} %{?_smp_mflags} + +# Build perf +make -s -C tools/lib/traceevent %{?_smp_mflags} +make -s -C tools/perf EXTRA_CFLAGS="-fPIE -rdynamic" %{?_smp_mflags} + +# Build Image/Image.gz +make %{?_smp_mflags} + +# Build modules +make modules %{?_smp_mflags} + +%install +QA_SKIP_BUILD_ROOT="DO_NOT_WANT"; export QA_SKIP_BUILD_ROOT + +# Destination directories +mkdir -p %{buildroot}/boot +mkdir -p %{buildroot}/lib/modules + +# Install kernel DTB +install -m 644 arch/%{buildarch}/boot/dts/starfive/jh7110*.dtb %{buildroot}/boot/ +mkdir -p %{buildroot}/boot/overlays + +# Install kernel headers +make headers_install %{?_smp_mflags} INSTALL_HDR_PATH=%{buildroot}/usr + +install -m 644 arch/%{buildarch}/boot/Image %{buildroot}/boot/Image + +# Install perf +make -s -C tools/perf EXTRA_CFLAGS="-fPIE -rdynamic" DESTDIR=%{buildroot}/usr install +rm -rf %{buildroot}/usr/etc +rm -rf %{buildroot}/usr/lib/debug +rm -rf %{buildroot}/usr/lib/perf +rm -rf %{buildroot}/usr/share + +# Install modules +make INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=%{buildroot} modules_install + +# Copy files for devel package +mkdir -p %{buildroot}/boot/kernel/devel/kernel-devel-%{variant} +rsync -r \ + --include "/scripts/**.c" \ + --exclude "/debug*.list" \ + --exclude "/documentation.list" \ + --exclude "/*.manifest" \ + --exclude "/packaging/" \ + --exclude "/.gbs.conf" \ + --exclude "/.git**" \ + --exclude ".gitignore" \ + --exclude "*\.c" \ + --exclude ".tmp_vmlinux*" \ + --exclude ".*dtb*tmp" \ + --exclude ".*dtb" \ + --exclude "*.*tmp" \ + --exclude "vmlinux" \ + --exclude "Image" \ + --exclude "zImage" \ + --exclude "Image.gz" \ + --exclude "*.cmd" \ + --exclude "*.ko" \ + --exclude "*.o" \ + --exclude "*.S" \ + --exclude "*.HEX" \ + --exclude "/build/" \ + ./ %{buildroot}/boot/kernel/devel/kernel-devel-%{variant} + +%clean +rm -rf %{buildroot} + +%files -n %{variant}-linux-kernel-modules +/lib/modules/ + +%files -n %{variant}-linux-kernel-devel +/boot/kernel/devel/ + +%files -n %{variant}-linux-kernel +%license COPYING +/boot/Image +/boot/jh7110*.dtb + +%files -n %{variant}-linux-kernel-headers +/usr/include/* + +%files -n linux-kernel-perf +%license COPYING +/usr/bin/* +/usr/libexec/* +/usr/lib/traceevent/* -- 2.7.4 From 466f35a269a780612c72c6a159e955ed991679b5 Mon Sep 17 00:00:00 2001 From: Marek Szulc Date: Fri, 19 Aug 2022 12:29:48 +0200 Subject: [PATCH 05/16] riscv: fix riscv64 unrecognized opcode build error MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Considering older gcc version, "imafd" has to be changed to "g", in order for asm to handle "zicsr" and "zifencei" extensions. Support for the mentioned extensions has been added in GCC 11.1, hence this commit may be removed after GCC update. The lack of this causes following errors: Error: unrecognized opcode `csrr a5,0xc01' Error: unrecognized opcode `csrr a2,0xc01' Change-Id: I0768a7b1255c828c4fc319f74f2783bc7e1581bf Signed-off-by: Marek Szulc Signed-off-by: Łukasz Stelmach --- arch/riscv/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index c18d8721..c78a52c 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -51,6 +51,7 @@ endif riscv-march-$(CONFIG_ARCH_RV32I) := rv32ima riscv-march-$(CONFIG_ARCH_RV64I) := rv64ima riscv-march-$(CONFIG_FPU) := $(riscv-march-y)fd +riscv-march-y := $(subst imafd,g,$(riscv-march-y)) riscv-march-$(CONFIG_RISCV_ISA_C) := $(riscv-march-y)c # Newer binutils versions default to ISA spec version 20191213 which moves some -- 2.7.4 From 3c86dd0e06be7e0272effeb2eff44c01c33e0c88 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Sun, 31 Jul 2022 18:38:27 -0700 Subject: [PATCH 06/16] tools build: Add feature test for init_disassemble_info API changes commit cfd59ca91467056bb2c36907b2fa67b8e1af9952 upstream. binutils changed the signature of init_disassemble_info(), which now causes compilation failures for tools/{perf,bpf}, e.g. on debian unstable. Relevant binutils commit: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=60a3da00bd5407f07 This commit adds a feature test to detect the new signature. Subsequent commits will use it to fix the build failures. Signed-off-by: Andres Freund Acked-by: Quentin Monnet Cc: Alexei Starovoitov Cc: Ben Hutchings Cc: Jiri Olsa Cc: Quentin Monnet Cc: Sedat Dilek Cc: bpf@vger.kernel.org Link: http://lore.kernel.org/lkml/20220622181918.ykrs5rsnmx3og4sv@alap3.anarazel.de Link: https://lore.kernel.org/r/20220801013834.156015-2-andres@anarazel.de Signed-off-by: Arnaldo Carvalho de Melo Cc: Hauke Mehrtens Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 51b99dc38c1a053e2e732d7f9e2740e343ae7eae) Change-Id: I1c17a17b2a2d8cfbc09bf44292366fb52b9fcd09 Signed-off-by: Jaehoon Chung --- tools/build/Makefile.feature | 1 + tools/build/feature/Makefile | 4 ++++ tools/build/feature/test-all.c | 4 ++++ tools/build/feature/test-disassembler-init-styled.c | 13 +++++++++++++ 4 files changed, 22 insertions(+) create mode 100644 tools/build/feature/test-disassembler-init-styled.c diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature index 3dd2f68..73439b5 100644 --- a/tools/build/Makefile.feature +++ b/tools/build/Makefile.feature @@ -70,6 +70,7 @@ FEATURE_TESTS_BASIC := \ libaio \ libzstd \ disassembler-four-args \ + disassembler-init-styled \ file-handle # FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile index eff55d2..9b35d25 100644 --- a/tools/build/feature/Makefile +++ b/tools/build/feature/Makefile @@ -18,6 +18,7 @@ FILES= \ test-libbfd.bin \ test-libbfd-buildid.bin \ test-disassembler-four-args.bin \ + test-disassembler-init-styled.bin \ test-reallocarray.bin \ test-libbfd-liberty.bin \ test-libbfd-liberty-z.bin \ @@ -235,6 +236,9 @@ $(OUTPUT)test-libbfd-buildid.bin: $(OUTPUT)test-disassembler-four-args.bin: $(BUILD) -DPACKAGE='"perf"' -lbfd -lopcodes +$(OUTPUT)test-disassembler-init-styled.bin: + $(BUILD) -DPACKAGE='"perf"' -lbfd -lopcodes + $(OUTPUT)test-reallocarray.bin: $(BUILD) diff --git a/tools/build/feature/test-all.c b/tools/build/feature/test-all.c index 9204395..4a514d8 100644 --- a/tools/build/feature/test-all.c +++ b/tools/build/feature/test-all.c @@ -170,6 +170,10 @@ # include "test-disassembler-four-args.c" #undef main +#define main main_test_disassembler_init_styled +# include "test-disassembler-init-styled.c" +#undef main + #define main main_test_libzstd # include "test-libzstd.c" #undef main diff --git a/tools/build/feature/test-disassembler-init-styled.c b/tools/build/feature/test-disassembler-init-styled.c new file mode 100644 index 0000000..f1ce0ec --- /dev/null +++ b/tools/build/feature/test-disassembler-init-styled.c @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include + +int main(void) +{ + struct disassemble_info info; + + init_disassemble_info(&info, stdout, + NULL, NULL); + + return 0; +} -- 2.7.4 From a82d1a9a9ba7bc52f47e8fd9dcec60d5fe4a8197 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Sun, 31 Jul 2022 18:38:30 -0700 Subject: [PATCH 07/16] tools perf: Fix compilation error with new binutils commit 83aa0120487e8bc3f231e72c460add783f71f17c upstream. binutils changed the signature of init_disassemble_info(), which now causes compilation failures for tools/perf/util/annotate.c, e.g. on debian unstable. Relevant binutils commit: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=60a3da00bd5407f07 Wire up the feature test and switch to init_disassemble_info_compat(), which were introduced in prior commits, fixing the compilation failure. I verified that perf can still disassemble bpf programs by using bpftrace under load, recording a perf trace, and then annotating the bpf "function" with and without the changes. With old binutils there's no change in output before/after this patch. When comparing the output from old binutils (2.35) to new bintuils with the patch (upstream snapshot) there are a few output differences, but they are unrelated to this patch. An example hunk is: 1.15 : 55:mov %rbp,%rdx 0.00 : 58:add $0xfffffffffffffff8,%rdx 0.00 : 5c:xor %ecx,%ecx - 1.03 : 5e:callq 0xffffffffe12aca3c + 1.03 : 5e:call 0xffffffffe12aca3c 0.00 : 63:xor %eax,%eax - 2.18 : 65:leaveq - 2.82 : 66:retq + 2.18 : 65:leave + 2.82 : 66:ret Signed-off-by: Andres Freund Acked-by: Quentin Monnet Cc: Alexei Starovoitov Cc: Ben Hutchings Cc: Jiri Olsa Cc: Sedat Dilek Cc: bpf@vger.kernel.org Link: http://lore.kernel.org/lkml/20220622181918.ykrs5rsnmx3og4sv@alap3.anarazel.de Link: https://lore.kernel.org/r/20220801013834.156015-5-andres@anarazel.de Signed-off-by: Arnaldo Carvalho de Melo Cc: Hauke Mehrtens Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 97f005c0bdbaf656a7808586d234965385a06c58) Change-Id: I72d8603797149776b20511f9c4b649853fb33a28 Signed-off-by: Jaehoon Chung --- tools/perf/Makefile.config | 8 ++++++++ tools/perf/util/annotate.c | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index 14e3e8d..104997b 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -277,6 +277,7 @@ FEATURE_CHECK_LDFLAGS-libpython-version := $(PYTHON_EMBED_LDOPTS) FEATURE_CHECK_LDFLAGS-libaio = -lrt FEATURE_CHECK_LDFLAGS-disassembler-four-args = -lbfd -lopcodes -ldl +FEATURE_CHECK_LDFLAGS-disassembler-init-styled = -lbfd -lopcodes -ldl CORE_CFLAGS += -fno-omit-frame-pointer CORE_CFLAGS += -ggdb3 @@ -843,13 +844,16 @@ ifndef NO_LIBBFD ifeq ($(feature-libbfd-liberty), 1) EXTLIBS += -lbfd -lopcodes -liberty FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -ldl + FEATURE_CHECK_LDFLAGS-disassembler-init-styled += -liberty -ldl else ifeq ($(feature-libbfd-liberty-z), 1) EXTLIBS += -lbfd -lopcodes -liberty -lz FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -lz -ldl + FEATURE_CHECK_LDFLAGS-disassembler-init-styled += -liberty -lz -ldl endif endif $(call feature_check,disassembler-four-args) + $(call feature_check,disassembler-init-styled) endif ifeq ($(feature-libbfd-buildid), 1) @@ -963,6 +967,10 @@ ifeq ($(feature-disassembler-four-args), 1) CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE endif +ifeq ($(feature-disassembler-init-styled), 1) + CFLAGS += -DDISASM_INIT_STYLED +endif + ifeq (${IS_64_BIT}, 1) ifndef NO_PERF_READ_VDSO32 $(call feature_check,compile-32) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 0bae061..a5e87c7 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -1694,6 +1694,7 @@ fallback: #include #include #include +#include static int symbol__disassemble_bpf(struct symbol *sym, struct annotate_args *args) @@ -1736,9 +1737,9 @@ static int symbol__disassemble_bpf(struct symbol *sym, ret = errno; goto out; } - init_disassemble_info(&info, s, - (fprintf_ftype) fprintf); - + init_disassemble_info_compat(&info, s, + (fprintf_ftype) fprintf, + fprintf_styled); info.arch = bfd_get_arch(bfdf); info.mach = bfd_get_mach(bfdf); -- 2.7.4 From 741e46fba140238536494a3a73717c3232fed1b8 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Sun, 31 Jul 2022 18:38:31 -0700 Subject: [PATCH 08/16] tools bpf_jit_disasm: Fix compilation error with new binutils commit 96ed066054abf11c7d3e106e3011a51f3f1227a3 upstream. binutils changed the signature of init_disassemble_info(), which now causes compilation to fail for tools/bpf/bpf_jit_disasm.c, e.g. on debian unstable. Relevant binutils commit: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=60a3da00bd5407f07 Wire up the feature test and switch to init_disassemble_info_compat(), which were introduced in prior commits, fixing the compilation failure. I verified that bpf_jit_disasm can still disassemble bpf programs, both with the old and new dis-asm.h API. With old binutils there's no change in output before/after this patch. When comparing the output from old binutils (2.35) to new bintuils with the patch (upstream snapshot) there are a few output differences, but they are unrelated to this patch. An example hunk is: f4: mov %r14,%rsi f7: mov %r15,%rdx fa: mov $0x2a,%ecx - ff: callq 0xffffffffea8c4988 + ff: call 0xffffffffea8c4988 104: test %rax,%rax 107: jge 0x0000000000000110 109: xor %eax,%eax - 10b: jmpq 0x0000000000000073 + 10b: jmp 0x0000000000000073 110: cmp $0x16,%rax However, I had to use an older kernel to generate the bpf_jit_enabled = 2 output, as that has been broken since 5.18 / 1022a5498f6f745c ("bpf, x86_64: Use bpf_jit_binary_pack_alloc"). https://lore.kernel.org/20220703030210.pmjft7qc2eajzi6c@alap3.anarazel.de Signed-off-by: Andres Freund Acked-by: Quentin Monnet Cc: Alexei Starovoitov Cc: Ben Hutchings Cc: Daniel Borkmann Cc: Jiri Olsa Cc: Quentin Monnet Cc: Sedat Dilek Cc: bpf@vger.kernel.org Link: http://lore.kernel.org/lkml/20220622181918.ykrs5rsnmx3og4sv@alap3.anarazel.de Link: https://lore.kernel.org/r/20220801013834.156015-6-andres@anarazel.de Signed-off-by: Arnaldo Carvalho de Melo Cc: Hauke Mehrtens Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 1c27fab243333821375e4d63128d60093fdbe149) Change-Id: I1e99c6bf30a8e7554a16f15e01240a7911f20e9f Signed-off-by: Jaehoon Chung --- tools/bpf/Makefile | 5 ++++- tools/bpf/bpf_jit_disasm.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/bpf/Makefile b/tools/bpf/Makefile index b11cfc8..664601a 100644 --- a/tools/bpf/Makefile +++ b/tools/bpf/Makefile @@ -34,7 +34,7 @@ else endif FEATURE_USER = .bpf -FEATURE_TESTS = libbfd disassembler-four-args +FEATURE_TESTS = libbfd disassembler-four-args disassembler-init-styled FEATURE_DISPLAY = libbfd disassembler-four-args check_feat := 1 @@ -56,6 +56,9 @@ endif ifeq ($(feature-disassembler-four-args), 1) CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE endif +ifeq ($(feature-disassembler-init-styled), 1) +CFLAGS += -DDISASM_INIT_STYLED +endif $(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y $(QUIET_BISON)$(YACC) -o $@ -d $< diff --git a/tools/bpf/bpf_jit_disasm.c b/tools/bpf/bpf_jit_disasm.c index c8ae958..a90a5d1 100644 --- a/tools/bpf/bpf_jit_disasm.c +++ b/tools/bpf/bpf_jit_disasm.c @@ -28,6 +28,7 @@ #include #include #include +#include #define CMD_ACTION_SIZE_BUFFER 10 #define CMD_ACTION_READ_ALL 3 @@ -64,7 +65,9 @@ static void get_asm_insns(uint8_t *image, size_t len, int opcodes) assert(bfdf); assert(bfd_check_format(bfdf, bfd_object)); - init_disassemble_info(&info, stdout, (fprintf_ftype) fprintf); + init_disassemble_info_compat(&info, stdout, + (fprintf_ftype) fprintf, + fprintf_styled); info.arch = bfd_get_arch(bfdf); info.mach = bfd_get_mach(bfdf); info.buffer = image; -- 2.7.4 From 9722eceaa0ef929c4e37042d1bb95fbe71a278e9 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Sun, 31 Jul 2022 18:38:29 -0700 Subject: [PATCH 09/16] tools include: add dis-asm-compat.h to handle version differences commit a45b3d6926231c3d024ea0de4f7bd967f83709ee upstream. binutils changed the signature of init_disassemble_info(), which now causes compilation failures for tools/{perf,bpf}, e.g. on debian unstable. Relevant binutils commit: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=60a3da00bd5407f07 This commit introduces a wrapper for init_disassemble_info(), to avoid spreading #ifdef DISASM_INIT_STYLED to a bunch of places. Subsequent commits will use it to fix the build failures. It likely is worth adding a wrapper for disassember(), to avoid the already existing DISASM_FOUR_ARGS_SIGNATURE ifdefery. Signed-off-by: Andres Freund Signed-off-by: Ben Hutchings Acked-by: Quentin Monnet Cc: Alexei Starovoitov Cc: Ben Hutchings Cc: Jiri Olsa Cc: Quentin Monnet Cc: Sedat Dilek Cc: bpf@vger.kernel.org Link: http://lore.kernel.org/lkml/20220622181918.ykrs5rsnmx3og4sv@alap3.anarazel.de Link: https://lore.kernel.org/r/20220801013834.156015-4-andres@anarazel.de Signed-off-by: Arnaldo Carvalho de Melo Cc: Hauke Mehrtens Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 451c9d7b16169645ed291ebb2ca9844caa088f2d) Change-Id: Ic46658e0093e2476e717a3c8d357df475b8a0d73 Signed-off-by: Jaehoon Chung --- tools/include/tools/dis-asm-compat.h | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tools/include/tools/dis-asm-compat.h diff --git a/tools/include/tools/dis-asm-compat.h b/tools/include/tools/dis-asm-compat.h new file mode 100644 index 0000000..70f331e --- /dev/null +++ b/tools/include/tools/dis-asm-compat.h @@ -0,0 +1,55 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause */ +#ifndef _TOOLS_DIS_ASM_COMPAT_H +#define _TOOLS_DIS_ASM_COMPAT_H + +#include +#include + +/* define types for older binutils version, to centralize ifdef'ery a bit */ +#ifndef DISASM_INIT_STYLED +enum disassembler_style {DISASSEMBLER_STYLE_NOT_EMPTY}; +typedef int (*fprintf_styled_ftype) (void *, enum disassembler_style, const char*, ...); +#endif + +/* + * Trivial fprintf wrapper to be used as the fprintf_styled_func argument to + * init_disassemble_info_compat() when normal fprintf suffices. + */ +static inline int fprintf_styled(void *out, + enum disassembler_style style, + const char *fmt, ...) +{ + va_list args; + int r; + + (void)style; + + va_start(args, fmt); + r = vfprintf(out, fmt, args); + va_end(args); + + return r; +} + +/* + * Wrapper for init_disassemble_info() that hides version + * differences. Depending on binutils version and architecture either + * fprintf_func or fprintf_styled_func will be called. + */ +static inline void init_disassemble_info_compat(struct disassemble_info *info, + void *stream, + fprintf_ftype unstyled_func, + fprintf_styled_ftype styled_func) +{ +#ifdef DISASM_INIT_STYLED + init_disassemble_info(info, stream, + unstyled_func, + styled_func); +#else + (void)styled_func; + init_disassemble_info(info, stream, + unstyled_func); +#endif +} + +#endif /* _TOOLS_DIS_ASM_COMPAT_H */ -- 2.7.4 From b830ab8b11c669e3ad63bcab04a543b913a33c01 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Sun, 31 Jul 2022 18:38:33 -0700 Subject: [PATCH 10/16] tools bpftool: Fix compilation error with new binutils commit 600b7b26c07a070d0153daa76b3806c1e52c9e00 upstream. binutils changed the signature of init_disassemble_info(), which now causes compilation to fail for tools/bpf/bpftool/jit_disasm.c, e.g. on debian unstable. Relevant binutils commit: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=60a3da00bd5407f07 Wire up the feature test and switch to init_disassemble_info_compat(), which were introduced in prior commits, fixing the compilation failure. I verified that bpftool can still disassemble bpf programs, both with an old and new dis-asm.h API. There are no output changes for plain and json formats. When comparing the output from old binutils (2.35) to new bintuils with the patch (upstream snapshot) there are a few output differences, but they are unrelated to this patch. An example hunk is: 2f: pop %r14 31: pop %r13 33: pop %rbx - 34: leaveq - 35: retq + 34: leave + 35: ret Signed-off-by: Andres Freund Acked-by: Quentin Monnet Cc: Alexei Starovoitov Cc: Ben Hutchings Cc: Jiri Olsa Cc: Quentin Monnet Cc: Sedat Dilek Cc: bpf@vger.kernel.org Link: http://lore.kernel.org/lkml/20220622181918.ykrs5rsnmx3og4sv@alap3.anarazel.de Link: https://lore.kernel.org/r/20220801013834.156015-8-andres@anarazel.de Signed-off-by: Arnaldo Carvalho de Melo Cc: Hauke Mehrtens Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 4441a90091931fd81607567961dc122f24f735bb) Change-Id: I832b16eae3bfc13cf83394403250d5843f6c6284 Signed-off-by: Jaehoon Chung --- tools/bpf/bpftool/Makefile | 5 ++++- tools/bpf/bpftool/jit_disasm.c | 42 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile index d73232b..cf341e2 100644 --- a/tools/bpf/bpftool/Makefile +++ b/tools/bpf/bpftool/Makefile @@ -77,7 +77,7 @@ INSTALL ?= install RM ?= rm -f FEATURE_USER = .bpftool -FEATURE_TESTS = libbfd disassembler-four-args reallocarray zlib libcap \ +FEATURE_TESTS = libbfd disassembler-four-args disassembler-init-styled reallocarray zlib libcap \ clang-bpf-co-re FEATURE_DISPLAY = libbfd disassembler-four-args zlib libcap \ clang-bpf-co-re @@ -112,6 +112,9 @@ ifeq ($(feature-libcap), 1) CFLAGS += -DUSE_LIBCAP LIBS += -lcap endif +ifeq ($(feature-disassembler-init-styled), 1) + CFLAGS += -DDISASM_INIT_STYLED +endif include $(wildcard $(OUTPUT)*.d) diff --git a/tools/bpf/bpftool/jit_disasm.c b/tools/bpf/bpftool/jit_disasm.c index 24734f2..aaf99a0 100644 --- a/tools/bpf/bpftool/jit_disasm.c +++ b/tools/bpf/bpftool/jit_disasm.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "json_writer.h" #include "main.h" @@ -39,15 +40,12 @@ static void get_exec_path(char *tpath, size_t size) } static int oper_count; -static int fprintf_json(void *out, const char *fmt, ...) +static int printf_json(void *out, const char *fmt, va_list ap) { - va_list ap; char *s; int err; - va_start(ap, fmt); err = vasprintf(&s, fmt, ap); - va_end(ap); if (err < 0) return -1; @@ -73,6 +71,32 @@ static int fprintf_json(void *out, const char *fmt, ...) return 0; } +static int fprintf_json(void *out, const char *fmt, ...) +{ + va_list ap; + int r; + + va_start(ap, fmt); + r = printf_json(out, fmt, ap); + va_end(ap); + + return r; +} + +static int fprintf_json_styled(void *out, + enum disassembler_style style __maybe_unused, + const char *fmt, ...) +{ + va_list ap; + int r; + + va_start(ap, fmt); + r = printf_json(out, fmt, ap); + va_end(ap); + + return r; +} + void disasm_print_insn(unsigned char *image, ssize_t len, int opcodes, const char *arch, const char *disassembler_options, const struct btf *btf, @@ -99,11 +123,13 @@ void disasm_print_insn(unsigned char *image, ssize_t len, int opcodes, assert(bfd_check_format(bfdf, bfd_object)); if (json_output) - init_disassemble_info(&info, stdout, - (fprintf_ftype) fprintf_json); + init_disassemble_info_compat(&info, stdout, + (fprintf_ftype) fprintf_json, + fprintf_json_styled); else - init_disassemble_info(&info, stdout, - (fprintf_ftype) fprintf); + init_disassemble_info_compat(&info, stdout, + (fprintf_ftype) fprintf, + fprintf_styled); /* Update architecture info for offload. */ if (arch) { -- 2.7.4 From 0605406005e7c0fdc13657120ae750845d79bb4c Mon Sep 17 00:00:00 2001 From: Jaehoon Chung Date: Wed, 17 May 2023 11:06:24 +0900 Subject: [PATCH 11/16] packaging: linux-visionfive2: Fix the number of version To use upstream branch, it need to use correct version. There is no v5.15.0 in tag. Use v5.15 instead of v5.15.0. Change-Id: I8e86b3b11e0796c0deab6e88d3aee093695eecc8 Signed-off-by: Jaehoon Chung --- packaging/linux-visionfive2.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/linux-visionfive2.spec b/packaging/linux-visionfive2.spec index 61b457c..c5dc164c 100644 --- a/packaging/linux-visionfive2.spec +++ b/packaging/linux-visionfive2.spec @@ -8,7 +8,7 @@ Name: visionfive2-linux-kernel Summary: The Linux Kernel for VisionFive2 Board -Version: 5.15.0 +Version: 5.15 Release: 0 License: GPL-2.0 ExclusiveArch: riscv64 -- 2.7.4 From c7a0efb90f6e49ceb2bd6ddb2fb0179c01bb547b Mon Sep 17 00:00:00 2001 From: Sudha Bheemanna Date: Tue, 23 Aug 2016 17:07:10 +0530 Subject: [PATCH 12/16] Bluetooth: Add "TIZEN_BT" flag Added the tizen specific flag for use in adding tizen patches. Change-Id: Ia391644fddbe600c8d845e0bf0808f587aa73e0c Signed-off-by: Sudha Bheemanna Signed-off-by: DoHyun Pyun Signed-off-by: Amit Purwar --- include/net/bluetooth/bluetooth.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h index 9125eff..061036c 100644 --- a/include/net/bluetooth/bluetooth.h +++ b/include/net/bluetooth/bluetooth.h @@ -37,6 +37,9 @@ #define PF_BLUETOOTH AF_BLUETOOTH #endif +/*To enable Tizen specific fixes */ +#define TIZEN_BT + /* Bluetooth versions */ #define BLUETOOTH_VER_1_1 1 #define BLUETOOTH_VER_1_2 2 -- 2.7.4 From e40524859d2588c6ac9b1dc994dc979b2178057e Mon Sep 17 00:00:00 2001 From: "h.sandeep" Date: Thu, 1 Sep 2016 12:00:57 +0530 Subject: [PATCH 13/16] Bluetooth: Add MGMT tizen_handlers and TIZEN_OP_BASE_CODE. Added the basic skeleton code for tizen_mgmt_handlers and mgmt_tizen.h header file. Change-Id: I8f3100aa79e6673840ba561f0a9c50238ca0880b Signed-off-by: h.sandeep Signed-off-by: Amit Purwar --- include/net/bluetooth/hci_core.h | 4 ++++ include/net/bluetooth/mgmt_tizen.h | 26 ++++++++++++++++++++++++++ net/bluetooth/hci_sock.c | 21 +++++++++++++++++++++ net/bluetooth/mgmt.c | 13 +++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 include/net/bluetooth/mgmt_tizen.h diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index a7360c8..bdcf290 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -1750,6 +1750,10 @@ struct hci_mgmt_chan { unsigned short channel; size_t handler_count; const struct hci_mgmt_handler *handlers; +#ifdef TIZEN_BT + size_t tizen_handler_count; + const struct hci_mgmt_handler *tizen_handlers; +#endif void (*hdev_init) (struct sock *sk, struct hci_dev *hdev); }; diff --git a/include/net/bluetooth/mgmt_tizen.h b/include/net/bluetooth/mgmt_tizen.h new file mode 100644 index 0000000..6bad3c9 --- /dev/null +++ b/include/net/bluetooth/mgmt_tizen.h @@ -0,0 +1,26 @@ +/* + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef __MGMT_TIZEN_H +#define __MGMT_TIZEN_H + +#define TIZEN_OP_CODE_BASE 0xff00 +#define TIZEN_EV_BASE 0xff00 + +#endif /* __MGMT_TIZEN_H */ diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c index f1128c2..d4a3c71 100644 --- a/net/bluetooth/hci_sock.c +++ b/net/bluetooth/hci_sock.c @@ -33,6 +33,9 @@ #include #include #include +#ifdef TIZEN_BT +#include +#endif #include "mgmt_util.h" @@ -1541,6 +1544,21 @@ static int hci_mgmt_cmd(struct hci_mgmt_chan *chan, struct sock *sk, goto done; } +#ifdef TIZEN_BT + if (opcode >= TIZEN_OP_CODE_BASE) { + u16 tizen_opcode_index = opcode - TIZEN_OP_CODE_BASE; + if (tizen_opcode_index >= chan->tizen_handler_count || + chan->tizen_handlers[tizen_opcode_index].func == NULL) { + BT_DBG("Unknown op %u", opcode); + err = mgmt_cmd_status(sk, index, opcode, + MGMT_STATUS_UNKNOWN_COMMAND); + goto done; + } + + handler = &chan->tizen_handlers[tizen_opcode_index]; + + } else { +#endif if (chan->channel == HCI_CHANNEL_CONTROL) { struct sk_buff *skb; @@ -1563,6 +1581,9 @@ static int hci_mgmt_cmd(struct hci_mgmt_chan *chan, struct sock *sk, } handler = &chan->handlers[opcode]; +#ifdef TIZEN_BT + } +#endif if (!hci_sock_test_flag(sk, HCI_SOCK_TRUSTED) && !(handler->flags & HCI_MGMT_UNTRUSTED)) { diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index cea01e2..e4e3c1c 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -32,6 +32,9 @@ #include #include #include +#ifdef TIZEN_BT +#include +#endif #include "hci_request.h" #include "smp.h" @@ -8460,6 +8463,12 @@ static const struct hci_mgmt_handler mgmt_handlers[] = { HCI_MGMT_VAR_LEN }, }; +#ifdef TIZEN_BT +static const struct hci_mgmt_handler tizen_mgmt_handlers[] = { + { NULL }, /* 0x0000 (no command) */ +}; +#endif + void mgmt_index_added(struct hci_dev *hdev) { struct mgmt_ev_ext_index ev; @@ -9519,6 +9528,10 @@ static struct hci_mgmt_chan chan = { .channel = HCI_CHANNEL_CONTROL, .handler_count = ARRAY_SIZE(mgmt_handlers), .handlers = mgmt_handlers, +#ifdef TIZEN_BT + .tizen_handler_count = ARRAY_SIZE(tizen_mgmt_handlers), + .tizen_handlers = tizen_mgmt_handlers, +#endif .hdev_init = mgmt_init_hdev, }; -- 2.7.4 From 78af4f6454eb69bc312507826b4c9d1eca89df7f Mon Sep 17 00:00:00 2001 From: Sudha Bheemanna Date: Wed, 24 Aug 2016 12:17:16 +0530 Subject: [PATCH 14/16] Bluetooth: Add Advertising Packet Configuration This patch provides new MGMT commands to configure the advertising data and scan response data packets for LE peripheral devices. Change-Id: I914d13795f4fb58e5f2e1cadb55086f4bcbc82df Signed-off-by: Sudha Bheemanna Signed-off-by: DoHyun Pyun Signed-off-by: Amit Purwar [jhoon20.kim: adjust some codes to apply it in 5.4 kernel] Signed-off-by: Junghoon Kim --- include/net/bluetooth/hci.h | 2 + include/net/bluetooth/hci_core.h | 5 + include/net/bluetooth/mgmt_tizen.h | 23 ++++ net/bluetooth/hci_core.c | 4 + net/bluetooth/hci_request.c | 39 ++++++- net/bluetooth/mgmt.c | 224 +++++++++++++++++++++++++++++++++++++ 6 files changed, 296 insertions(+), 1 deletion(-) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index b804150..dd81b23 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -591,6 +591,8 @@ enum { #define EIR_SSP_HASH_C192 0x0E /* Simple Pairing Hash C-192 */ #define EIR_SSP_RAND_R192 0x0F /* Simple Pairing Randomizer R-192 */ #define EIR_DEVICE_ID 0x10 /* device ID */ +#define EIR_SOLICIT_UUID16 0x14 /* 16-bit Solicitation UUID */ +#define EIR_MANUFACTURER_DATA 0XFF /* Manufacturer Specific Data*/ #define EIR_APPEARANCE 0x19 /* Device appearance */ #define EIR_LE_BDADDR 0x1B /* LE Bluetooth device address */ #define EIR_LE_ROLE 0x1C /* LE role */ diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index bdcf290..dec7380 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -593,6 +593,11 @@ struct hci_dev { bool aosp_capable; #endif +#ifdef TIZEN_BT + __u8 adv_filter_policy; + __u8 adv_type; +#endif + int (*open)(struct hci_dev *hdev); int (*close)(struct hci_dev *hdev); int (*flush)(struct hci_dev *hdev); diff --git a/include/net/bluetooth/mgmt_tizen.h b/include/net/bluetooth/mgmt_tizen.h index 6bad3c9..04bd255 100644 --- a/include/net/bluetooth/mgmt_tizen.h +++ b/include/net/bluetooth/mgmt_tizen.h @@ -23,4 +23,27 @@ #define TIZEN_OP_CODE_BASE 0xff00 #define TIZEN_EV_BASE 0xff00 +#define MGMT_OP_SET_ADVERTISING_PARAMS (TIZEN_OP_CODE_BASE + 0x01) +struct mgmt_cp_set_advertising_params { + __le16 interval_min; + __le16 interval_max; + __u8 filter_policy; + __u8 type; +} __packed; +#define MGMT_SET_ADVERTISING_PARAMS_SIZE 6 + +#define MGMT_OP_SET_ADVERTISING_DATA (TIZEN_OP_CODE_BASE + 0x02) +struct mgmt_cp_set_advertising_data { + __u8 data[HCI_MAX_AD_LENGTH]; +} __packed; +#define MGMT_SET_ADVERTISING_DATA_SIZE HCI_MAX_AD_LENGTH +#define MGMT_SET_ADV_MIN_APP_DATA_SIZE 1 + +#define MGMT_OP_SET_SCAN_RSP_DATA (TIZEN_OP_CODE_BASE + 0x03) +struct mgmt_cp_set_scan_rsp_data { + __u8 data[HCI_MAX_AD_LENGTH]; +} __packed; +#define MGMT_SET_SCAN_RSP_DATA_SIZE HCI_MAX_AD_LENGTH +#define MGMT_SET_SCAN_RSP_MIN_APP_DATA_SIZE 1 + #endif /* __MGMT_TIZEN_H */ diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 8a47a30..aac5cf7 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -3795,6 +3795,10 @@ struct hci_dev *hci_alloc_dev_priv(int sizeof_priv) hdev->le_adv_channel_map = 0x07; hdev->le_adv_min_interval = 0x0800; hdev->le_adv_max_interval = 0x0800; +#ifdef TIZEN_BT + hdev->adv_filter_policy = 0x00; + hdev->adv_type = 0x00; +#endif hdev->le_scan_interval = 0x0060; hdev->le_scan_window = 0x0030; hdev->le_scan_int_suspend = 0x0400; diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c index f156266..f4e43d6 100644 --- a/net/bluetooth/hci_request.c +++ b/net/bluetooth/hci_request.c @@ -1620,6 +1620,12 @@ void __hci_req_enable_advertising(struct hci_request *req) cp.min_interval = cpu_to_le16(adv_min_interval); cp.max_interval = cpu_to_le16(adv_max_interval); + +#ifdef TIZEN_BT + cp.filter_policy = hdev->adv_filter_policy; + cp.type = hdev->adv_type; +#endif + cp.own_address_type = own_addr_type; cp.channel_map = hdev->le_adv_channel_map; @@ -1728,6 +1734,13 @@ void __hci_req_update_scan_rsp_data(struct hci_request *req, u8 instance) pdu.data); else len = create_default_scan_rsp_data(hdev, pdu.data); +#ifdef TIZEN_BT + /* Advertising scan response data is handled in bluez. + * This value will be updated only when application request the update + * using adapter_set_scan_rsp_data() + */ + return; +#else if (hdev->scan_rsp_data_len == len && !memcmp(pdu.data, hdev->scan_rsp_data, len)) @@ -1743,6 +1756,7 @@ void __hci_req_update_scan_rsp_data(struct hci_request *req, u8 instance) hci_req_add(req, HCI_OP_LE_SET_EXT_SCAN_RSP_DATA, sizeof(pdu.cp) + len, &pdu.cp); +#endif } else { struct hci_cp_le_set_scan_rsp_data cp; @@ -1753,7 +1767,13 @@ void __hci_req_update_scan_rsp_data(struct hci_request *req, u8 instance) cp.data); else len = create_default_scan_rsp_data(hdev, cp.data); - +#ifdef TIZEN_BT + /* Advertising scan response data is handled in bluez. + * This value will be updated only when application request the update + * using adapter_set_scan_rsp_data() + */ + return; +#else if (hdev->scan_rsp_data_len == len && !memcmp(cp.data, hdev->scan_rsp_data, len)) return; @@ -1764,6 +1784,7 @@ void __hci_req_update_scan_rsp_data(struct hci_request *req, u8 instance) cp.length = len; hci_req_add(req, HCI_OP_LE_SET_SCAN_RSP_DATA, sizeof(cp), &cp); +#endif } } @@ -1874,6 +1895,13 @@ void __hci_req_update_adv_data(struct hci_request *req, u8 instance) len = create_instance_adv_data(hdev, instance, pdu.data); +#ifdef TIZEN_BT + /* Bluez will handle the advertising data including the flag and tx + * power. This value will be updated only when application request the + * update using adapter_set_advertising_data(). + */ + return; +#else /* There's nothing to do if the data hasn't changed */ if (hdev->adv_data_len == len && memcmp(pdu.data, hdev->adv_data, len) == 0) @@ -1889,6 +1917,7 @@ void __hci_req_update_adv_data(struct hci_request *req, u8 instance) hci_req_add(req, HCI_OP_LE_SET_EXT_ADV_DATA, sizeof(pdu.cp) + len, &pdu.cp); +#endif } else { struct hci_cp_le_set_adv_data cp; @@ -1896,6 +1925,13 @@ void __hci_req_update_adv_data(struct hci_request *req, u8 instance) len = create_instance_adv_data(hdev, instance, cp.data); +#ifdef TIZEN_BT + /* Bluez will handle the advertising data including the flag and tx + * power. This value will be updated only when application request the + * update using adapter_set_advertising_data(). + */ + return; +#else /* There's nothing to do if the data hasn't changed */ if (hdev->adv_data_len == len && memcmp(cp.data, hdev->adv_data, len) == 0) @@ -1907,6 +1943,7 @@ void __hci_req_update_adv_data(struct hci_request *req, u8 instance) cp.length = len; hci_req_add(req, HCI_OP_LE_SET_ADV_DATA, sizeof(cp), &cp); +#endif } } diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index e4e3c1c..bce96b57 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -6170,6 +6170,225 @@ static int load_irks(struct sock *sk, struct hci_dev *hdev, void *cp_data, return err; } +#ifdef TIZEN_BT +static int set_advertising_params(struct sock *sk, struct hci_dev *hdev, + void *data, u16 len) +{ + struct mgmt_cp_set_advertising_params *cp = data; + __u16 min_interval; + __u16 max_interval; + int err; + + BT_DBG("%s", hdev->name); + + if (!lmp_le_capable(hdev)) + return mgmt_cmd_status(sk, hdev->id, + MGMT_OP_SET_ADVERTISING_PARAMS, + MGMT_STATUS_NOT_SUPPORTED); + + if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) + return mgmt_cmd_status(sk, hdev->id, + MGMT_OP_SET_ADVERTISING_PARAMS, + MGMT_STATUS_BUSY); + + min_interval = __le16_to_cpu(cp->interval_min); + max_interval = __le16_to_cpu(cp->interval_max); + + if (min_interval > max_interval || + min_interval < 0x0020 || max_interval > 0x4000) + return mgmt_cmd_status(sk, hdev->id, + MGMT_OP_SET_ADVERTISING_PARAMS, + MGMT_STATUS_INVALID_PARAMS); + + hci_dev_lock(hdev); + + hdev->le_adv_min_interval = min_interval; + hdev->le_adv_max_interval = max_interval; + hdev->adv_filter_policy = cp->filter_policy; + hdev->adv_type = cp->type; + + err = mgmt_cmd_complete(sk, hdev->id, + MGMT_OP_SET_ADVERTISING_PARAMS, 0, NULL, 0); + + hci_dev_unlock(hdev); + + return err; +} + +static void set_advertising_data_complete(struct hci_dev *hdev, + u8 status, u16 opcode) +{ + struct mgmt_cp_set_advertising_data *cp; + struct mgmt_pending_cmd *cmd; + + BT_DBG("status 0x%02x", status); + + hci_dev_lock(hdev); + + cmd = pending_find(MGMT_OP_SET_ADVERTISING_DATA, hdev); + if (!cmd) + goto unlock; + + cp = cmd->param; + + if (status) + mgmt_cmd_status(cmd->sk, hdev->id, + MGMT_OP_SET_ADVERTISING_DATA, + mgmt_status(status)); + else + mgmt_cmd_complete(cmd->sk, hdev->id, + MGMT_OP_SET_ADVERTISING_DATA, 0, + cp, sizeof(*cp)); + + mgmt_pending_remove(cmd); + +unlock: + hci_dev_unlock(hdev); +} + +static int set_advertising_data(struct sock *sk, struct hci_dev *hdev, + void *data, u16 len) +{ + struct mgmt_pending_cmd *cmd; + struct hci_request req; + struct mgmt_cp_set_advertising_data *cp = data; + struct hci_cp_le_set_adv_data adv; + int err; + + BT_DBG("%s", hdev->name); + + if (!lmp_le_capable(hdev)) { + return mgmt_cmd_status(sk, hdev->id, + MGMT_OP_SET_ADVERTISING_DATA, + MGMT_STATUS_NOT_SUPPORTED); + } + + hci_dev_lock(hdev); + + if (pending_find(MGMT_OP_SET_ADVERTISING_DATA, hdev)) { + err = mgmt_cmd_status(sk, hdev->id, + MGMT_OP_SET_ADVERTISING_DATA, + MGMT_STATUS_BUSY); + goto unlocked; + } + + if (len > HCI_MAX_AD_LENGTH) { + err = mgmt_cmd_status(sk, hdev->id, + MGMT_OP_SET_ADVERTISING_DATA, + MGMT_STATUS_INVALID_PARAMS); + goto unlocked; + } + + cmd = mgmt_pending_add(sk, MGMT_OP_SET_ADVERTISING_DATA, + hdev, data, len); + if (!cmd) { + err = -ENOMEM; + goto unlocked; + } + + hci_req_init(&req, hdev); + + memset(&adv, 0, sizeof(adv)); + memcpy(adv.data, cp->data, len); + adv.length = len; + + hci_req_add(&req, HCI_OP_LE_SET_ADV_DATA, sizeof(adv), &adv); + + err = hci_req_run(&req, set_advertising_data_complete); + if (err < 0) + mgmt_pending_remove(cmd); + +unlocked: + hci_dev_unlock(hdev); + + return err; +} + +static void set_scan_rsp_data_complete(struct hci_dev *hdev, u8 status, + u16 opcode) +{ + struct mgmt_cp_set_scan_rsp_data *cp; + struct mgmt_pending_cmd *cmd; + + BT_DBG("status 0x%02x", status); + + hci_dev_lock(hdev); + + cmd = pending_find(MGMT_OP_SET_SCAN_RSP_DATA, hdev); + if (!cmd) + goto unlock; + + cp = cmd->param; + + if (status) + mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_SCAN_RSP_DATA, + mgmt_status(status)); + else + mgmt_cmd_complete(cmd->sk, hdev->id, + MGMT_OP_SET_SCAN_RSP_DATA, 0, + cp, sizeof(*cp)); + + mgmt_pending_remove(cmd); + +unlock: + hci_dev_unlock(hdev); +} + +static int set_scan_rsp_data(struct sock *sk, struct hci_dev *hdev, void *data, + u16 len) +{ + struct mgmt_pending_cmd *cmd; + struct hci_request req; + struct mgmt_cp_set_scan_rsp_data *cp = data; + struct hci_cp_le_set_scan_rsp_data rsp; + int err; + + BT_DBG("%s", hdev->name); + + if (!lmp_le_capable(hdev)) + return mgmt_cmd_status(sk, hdev->id, + MGMT_OP_SET_SCAN_RSP_DATA, + MGMT_STATUS_NOT_SUPPORTED); + + hci_dev_lock(hdev); + + if (pending_find(MGMT_OP_SET_SCAN_RSP_DATA, hdev)) { + err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_RSP_DATA, + MGMT_STATUS_BUSY); + goto unlocked; + } + + if (len > HCI_MAX_AD_LENGTH) { + err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_SCAN_RSP_DATA, + MGMT_STATUS_INVALID_PARAMS); + goto unlocked; + } + + cmd = mgmt_pending_add(sk, MGMT_OP_SET_SCAN_RSP_DATA, hdev, data, len); + if (!cmd) { + err = -ENOMEM; + goto unlocked; + } + + hci_req_init(&req, hdev); + + memset(&rsp, 0, sizeof(rsp)); + memcpy(rsp.data, cp->data, len); + rsp.length = len; + + hci_req_add(&req, HCI_OP_LE_SET_SCAN_RSP_DATA, sizeof(rsp), &rsp); + + err = hci_req_run(&req, set_scan_rsp_data_complete); + if (err < 0) + mgmt_pending_remove(cmd); + +unlocked: + hci_dev_unlock(hdev); + + return err; +} +#endif /* TIZEN_BT */ + static bool ltk_is_valid(struct mgmt_ltk_info *key) { if (key->initiator != 0x00 && key->initiator != 0x01) @@ -8466,6 +8685,11 @@ static const struct hci_mgmt_handler mgmt_handlers[] = { #ifdef TIZEN_BT static const struct hci_mgmt_handler tizen_mgmt_handlers[] = { { NULL }, /* 0x0000 (no command) */ + { set_advertising_params, MGMT_SET_ADVERTISING_PARAMS_SIZE }, + { set_advertising_data, MGMT_SET_ADV_MIN_APP_DATA_SIZE, + HCI_MGMT_VAR_LEN }, + { set_scan_rsp_data, MGMT_SET_SCAN_RSP_MIN_APP_DATA_SIZE, + HCI_MGMT_VAR_LEN }, }; #endif -- 2.7.4 From 3b316cfca588deee970969d23478c9cb3bd80de9 Mon Sep 17 00:00:00 2001 From: Sudha Bheemanna Date: Wed, 24 Aug 2016 15:02:56 +0530 Subject: [PATCH 15/16] Bluetooth: Functions to modify WhiteList This patch provides MGMT commands to manage the white list which includes, adding, removing and clearing the devices from white list. Change-Id: If71107129d3a090ae81448a8122b76accd4f5522 Signed-off-by: Sudha Bheemanna Signed-off-by: DoHyun Pyun Signed-off-by: Amit Purwar --- include/net/bluetooth/mgmt_tizen.h | 17 +++ net/bluetooth/mgmt.c | 241 +++++++++++++++++++++++++++++++++++++ 2 files changed, 258 insertions(+) diff --git a/include/net/bluetooth/mgmt_tizen.h b/include/net/bluetooth/mgmt_tizen.h index 04bd255..6dc8e36 100644 --- a/include/net/bluetooth/mgmt_tizen.h +++ b/include/net/bluetooth/mgmt_tizen.h @@ -46,4 +46,21 @@ struct mgmt_cp_set_scan_rsp_data { #define MGMT_SET_SCAN_RSP_DATA_SIZE HCI_MAX_AD_LENGTH #define MGMT_SET_SCAN_RSP_MIN_APP_DATA_SIZE 1 +#define MGMT_OP_ADD_DEV_WHITE_LIST (TIZEN_OP_CODE_BASE + 0x04) +struct mgmt_cp_add_dev_white_list { + __u8 bdaddr_type; + bdaddr_t bdaddr; +} __packed; +#define MGMT_ADD_DEV_WHITE_LIST_SIZE 7 + +#define MGMT_OP_REMOVE_DEV_FROM_WHITE_LIST (TIZEN_OP_CODE_BASE + 0x05) +struct mgmt_cp_remove_dev_from_white_list { + __u8 bdaddr_type; + bdaddr_t bdaddr; +} __packed; +#define MGMT_REMOVE_DEV_FROM_WHITE_LIST_SIZE 7 + +#define MGMT_OP_CLEAR_DEV_WHITE_LIST (TIZEN_OP_CODE_BASE + 0x06) +#define MGMT_OP_CLEAR_DEV_WHITE_LIST_SIZE 0 + #endif /* __MGMT_TIZEN_H */ diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index bce96b57..06333ac 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -6387,6 +6387,244 @@ unlocked: return err; } + +/* Adv White List feature */ +static void add_white_list_complete(struct hci_dev *hdev, u8 status, u16 opcode) +{ + struct mgmt_cp_add_dev_white_list *cp; + struct mgmt_pending_cmd *cmd; + + BT_DBG("status 0x%02x", status); + + hci_dev_lock(hdev); + + cmd = pending_find(MGMT_OP_ADD_DEV_WHITE_LIST, hdev); + if (!cmd) + goto unlock; + + cp = cmd->param; + + if (status) + mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_ADD_DEV_WHITE_LIST, + mgmt_status(status)); + else + mgmt_cmd_complete(cmd->sk, hdev->id, + MGMT_OP_ADD_DEV_WHITE_LIST, 0, cp, sizeof(*cp)); + + mgmt_pending_remove(cmd); + +unlock: + hci_dev_unlock(hdev); +} + +static int add_white_list(struct sock *sk, struct hci_dev *hdev, + void *data, u16 len) +{ + struct mgmt_pending_cmd *cmd; + struct mgmt_cp_add_dev_white_list *cp = data; + struct hci_request req; + int err; + + BT_DBG("%s", hdev->name); + + if (!lmp_le_capable(hdev)) + return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_DEV_WHITE_LIST, + MGMT_STATUS_NOT_SUPPORTED); + + if (!hdev_is_powered(hdev)) + return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_DEV_WHITE_LIST, + MGMT_STATUS_REJECTED); + + hci_dev_lock(hdev); + + if (pending_find(MGMT_OP_ADD_DEV_WHITE_LIST, hdev)) { + err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_DEV_WHITE_LIST, + MGMT_STATUS_BUSY); + goto unlocked; + } + + cmd = mgmt_pending_add(sk, MGMT_OP_ADD_DEV_WHITE_LIST, hdev, data, len); + if (!cmd) { + err = -ENOMEM; + goto unlocked; + } + + hci_req_init(&req, hdev); + + hci_req_add(&req, HCI_OP_LE_ADD_TO_WHITE_LIST, sizeof(*cp), cp); + + err = hci_req_run(&req, add_white_list_complete); + if (err < 0) { + mgmt_pending_remove(cmd); + goto unlocked; + } + +unlocked: + hci_dev_unlock(hdev); + + return err; +} + +static void remove_from_white_list_complete(struct hci_dev *hdev, + u8 status, u16 opcode) +{ + struct mgmt_cp_remove_dev_from_white_list *cp; + struct mgmt_pending_cmd *cmd; + + BT_DBG("status 0x%02x", status); + + hci_dev_lock(hdev); + + cmd = pending_find(MGMT_OP_REMOVE_DEV_FROM_WHITE_LIST, hdev); + if (!cmd) + goto unlock; + + cp = cmd->param; + + if (status) + mgmt_cmd_status(cmd->sk, hdev->id, + MGMT_OP_REMOVE_DEV_FROM_WHITE_LIST, + mgmt_status(status)); + else + mgmt_cmd_complete(cmd->sk, hdev->id, + MGMT_OP_REMOVE_DEV_FROM_WHITE_LIST, 0, + cp, sizeof(*cp)); + + mgmt_pending_remove(cmd); + +unlock: + hci_dev_unlock(hdev); +} + +static int remove_from_white_list(struct sock *sk, struct hci_dev *hdev, + void *data, u16 len) +{ + struct mgmt_pending_cmd *cmd; + struct mgmt_cp_remove_dev_from_white_list *cp = data; + struct hci_request req; + int err; + + BT_DBG("%s", hdev->name); + + if (!lmp_le_capable(hdev)) + return mgmt_cmd_status(sk, hdev->id, + MGMT_OP_REMOVE_DEV_FROM_WHITE_LIST, + MGMT_STATUS_NOT_SUPPORTED); + + if (!hdev_is_powered(hdev)) + return mgmt_cmd_status(sk, hdev->id, + MGMT_OP_REMOVE_DEV_FROM_WHITE_LIST, + MGMT_STATUS_REJECTED); + + hci_dev_lock(hdev); + + if (pending_find(MGMT_OP_REMOVE_DEV_FROM_WHITE_LIST, hdev)) { + err = mgmt_cmd_status(sk, hdev->id, + MGMT_OP_REMOVE_DEV_FROM_WHITE_LIST, + MGMT_STATUS_BUSY); + goto unlocked; + } + + cmd = mgmt_pending_add(sk, MGMT_OP_REMOVE_DEV_FROM_WHITE_LIST, + hdev, data, len); + if (!cmd) { + err = -ENOMEM; + goto unlocked; + } + + hci_req_init(&req, hdev); + + hci_req_add(&req, HCI_OP_LE_DEL_FROM_WHITE_LIST, sizeof(*cp), cp); + + err = hci_req_run(&req, remove_from_white_list_complete); + if (err < 0) { + mgmt_pending_remove(cmd); + goto unlocked; + } + +unlocked: + hci_dev_unlock(hdev); + + return err; +} + +static void clear_white_list_complete(struct hci_dev *hdev, u8 status, + u16 opcode) +{ + struct mgmt_pending_cmd *cmd; + + BT_DBG("status 0x%02x", status); + + hci_dev_lock(hdev); + + cmd = pending_find(MGMT_OP_CLEAR_DEV_WHITE_LIST, hdev); + if (!cmd) + goto unlock; + + if (status) + mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_CLEAR_DEV_WHITE_LIST, + mgmt_status(status)); + else + mgmt_cmd_complete(cmd->sk, hdev->id, + MGMT_OP_CLEAR_DEV_WHITE_LIST, + 0, NULL, 0); + + mgmt_pending_remove(cmd); + +unlock: + hci_dev_unlock(hdev); +} + +static int clear_white_list(struct sock *sk, struct hci_dev *hdev, + void *data, u16 len) +{ + struct mgmt_pending_cmd *cmd; + struct hci_request req; + int err; + + BT_DBG("%s", hdev->name); + + if (!lmp_le_capable(hdev)) + return mgmt_cmd_status(sk, hdev->id, + MGMT_OP_CLEAR_DEV_WHITE_LIST, + MGMT_STATUS_NOT_SUPPORTED); + + if (!hdev_is_powered(hdev)) + return mgmt_cmd_status(sk, hdev->id, + MGMT_OP_CLEAR_DEV_WHITE_LIST, + MGMT_STATUS_REJECTED); + + hci_dev_lock(hdev); + + if (pending_find(MGMT_OP_CLEAR_DEV_WHITE_LIST, hdev)) { + err = mgmt_cmd_status(sk, hdev->id, + MGMT_OP_CLEAR_DEV_WHITE_LIST, + MGMT_STATUS_BUSY); + goto unlocked; + } + + cmd = mgmt_pending_add(sk, MGMT_OP_CLEAR_DEV_WHITE_LIST, + hdev, NULL, 0); + if (!cmd) { + err = -ENOMEM; + goto unlocked; + } + + hci_req_init(&req, hdev); + + hci_req_add(&req, HCI_OP_LE_CLEAR_WHITE_LIST, 0, NULL); + + err = hci_req_run(&req, clear_white_list_complete); + if (err < 0) { + mgmt_pending_remove(cmd); + goto unlocked; + } + +unlocked: + hci_dev_unlock(hdev); + + return err; +} #endif /* TIZEN_BT */ static bool ltk_is_valid(struct mgmt_ltk_info *key) @@ -8690,6 +8928,9 @@ static const struct hci_mgmt_handler tizen_mgmt_handlers[] = { HCI_MGMT_VAR_LEN }, { set_scan_rsp_data, MGMT_SET_SCAN_RSP_MIN_APP_DATA_SIZE, HCI_MGMT_VAR_LEN }, + { add_white_list, MGMT_ADD_DEV_WHITE_LIST_SIZE }, + { remove_from_white_list, MGMT_REMOVE_DEV_FROM_WHITE_LIST_SIZE }, + { clear_white_list, MGMT_OP_CLEAR_DEV_WHITE_LIST_SIZE }, }; #endif -- 2.7.4 From 2a248163bb3b8378534e197b657e09cd2485706f Mon Sep 17 00:00:00 2001 From: Sudha Bheemanna Date: Wed, 24 Aug 2016 17:21:15 +0530 Subject: [PATCH 16/16] Bluetooth: Add RSSI Monitor feature Added feature support for monitoring the RSSI value. Commands and events for enabling, disabling and setting rssi threshold values are added. Change-Id: I850643a9228afc017e54217a11826b9c6a68a96b Signed-off-by: Sudha Bheemanna Signed-off-by: Seung-Woo Kim Signed-off-by: Amit Purwar --- include/net/bluetooth/hci.h | 54 +++ include/net/bluetooth/hci_core.h | 80 +++++ include/net/bluetooth/mgmt_tizen.h | 63 ++++ net/bluetooth/hci_event.c | 32 ++ net/bluetooth/mgmt.c | 686 +++++++++++++++++++++++++++++++++++++ 5 files changed, 915 insertions(+) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index dd81b23..74b653c 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -1898,6 +1898,60 @@ struct hci_cp_le_reject_cis { __u8 reason; } __packed; +#ifdef TIZEN_BT +/* + * Vendor Specific HCI Command + * Vendor: Broadcom + * Purpose: This HCI is used to enable RSSI monitoring and setting + * Threshold Values for LE Link + */ +#define HCI_OP_ENABLE_RSSI 0xfce9 + +struct hci_cp_set_enable_rssi { + __u8 hci_le_ext_opcode; + __u8 le_enable_cs_Features; + __u8 data[3]; +} __packed; + +struct hci_cp_set_rssi_threshold { + __u8 hci_le_ext_opcode; + __u8 mode; + __le16 conn_handle; + __u8 alert_mask; + __u8 low_th; + __u8 in_range_th; + __u8 high_th; +} __packed; + +struct hci_cc_rsp_enable_rssi { + __u8 status; + __u8 le_ext_opcode; +} __packed; + +struct hci_ev_vendor_specific_rssi_alert { + __le16 conn_handle; + __s8 alert_type; + __s8 rssi_dbm; +} __packed; + +/* + * Vendor Specific HCI Command + * Vendor: Broadcom + * Purpose: This HCI is used to get Raw RSSI value for a Link + */ +#define HCI_OP_GET_RAW_RSSI 0xfc48 + +struct hci_cp_get_raw_rssi { + __le16 conn_handle; +} __packed; + +struct hci_cc_rp_get_raw_rssi { + __u8 status; + __le16 conn_handle; + __s8 rssi_dbm; +} __packed; +#endif + /* ---- HCI Events ---- */ #define HCI_EV_INQUIRY_COMPLETE 0x01 diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index dec7380..a19ddef 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -703,6 +703,9 @@ struct hci_conn { void *sco_data; struct amp_mgr *amp_mgr; +#ifdef TIZEN_BT + bool rssi_monitored; +#endif struct hci_conn *link; void (*connect_cfm_cb) (struct hci_conn *conn, u8 status); @@ -1084,6 +1087,70 @@ static inline struct hci_conn *hci_lookup_le_connect(struct hci_dev *hdev) return NULL; } +#ifdef TIZEN_BT +static inline bool hci_conn_rssi_state_set(struct hci_dev *hdev, + __u8 type, bdaddr_t *ba, bool value) +{ + struct hci_conn_hash *h = &hdev->conn_hash; + struct hci_conn *c; + __u8 conn_type; + + if (type == 0x01) + conn_type = LE_LINK; + else + conn_type = ACL_LINK; + + rcu_read_lock(); + + list_for_each_entry_rcu(c, &h->list, list) { + if (c->type == conn_type && !bacmp(&c->dst, ba)) { + c->rssi_monitored = value; + rcu_read_unlock(); + return true; + } + } + + rcu_read_unlock(); + return false; +} + +static inline void hci_conn_rssi_unset_all(struct hci_dev *hdev, + __u8 type) +{ + struct hci_conn_hash *h = &hdev->conn_hash; + struct hci_conn *c; + __u8 conn_type; + + if (type == 0x01) + conn_type = LE_LINK; + else + conn_type = ACL_LINK; + + rcu_read_lock(); + list_for_each_entry_rcu(c, &h->list, list) { + if (c->type == conn_type) + c->rssi_monitored = false; + } + rcu_read_unlock(); +} + +static inline int hci_conn_hash_lookup_rssi_count(struct hci_dev *hdev) +{ + struct hci_conn_hash *h = &hdev->conn_hash; + struct hci_conn *c; + int count = 0; + + rcu_read_lock(); + list_for_each_entry_rcu(c, &h->list, list) { + if (c->rssi_monitored == true) + ++count; + } + rcu_read_unlock(); + + return count; +} +#endif + int hci_disconnect(struct hci_conn *conn, __u8 reason); bool hci_setup_sync(struct hci_conn *conn, __u16 handle); void hci_sco_setup(struct hci_conn *conn, __u8 status); @@ -1864,6 +1931,19 @@ int mgmt_phy_configuration_changed(struct hci_dev *hdev, struct sock *skip); int mgmt_add_adv_patterns_monitor_complete(struct hci_dev *hdev, u8 status); int mgmt_remove_adv_monitor_complete(struct hci_dev *hdev, u8 status); +#ifdef TIZEN_BT +void mgmt_rssi_enable_success(struct sock *sk, struct hci_dev *hdev, + void *data, struct hci_cc_rsp_enable_rssi *rp, int success); +void mgmt_rssi_disable_success(struct sock *sk, struct hci_dev *hdev, + void *data, struct hci_cc_rsp_enable_rssi *rp, int success); +int mgmt_set_rssi_threshold(struct sock *sk, struct hci_dev *hdev, + void *data, u16 len); +void mgmt_rssi_alert_evt(struct hci_dev *hdev, struct sk_buff *skb); +void mgmt_raw_rssi_response(struct hci_dev *hdev, + struct hci_cc_rp_get_raw_rssi *rp, int success); +void mgmt_enable_rssi_cc(struct hci_dev *hdev, void *response, u8 status); +#endif + u8 hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, u16 latency, u16 to_multiplier); void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand, diff --git a/include/net/bluetooth/mgmt_tizen.h b/include/net/bluetooth/mgmt_tizen.h index 6dc8e36..46f652b 100644 --- a/include/net/bluetooth/mgmt_tizen.h +++ b/include/net/bluetooth/mgmt_tizen.h @@ -63,4 +63,67 @@ struct mgmt_cp_remove_dev_from_white_list { #define MGMT_OP_CLEAR_DEV_WHITE_LIST (TIZEN_OP_CODE_BASE + 0x06) #define MGMT_OP_CLEAR_DEV_WHITE_LIST_SIZE 0 +/* For RSSI monitoring */ +#define MGMT_OP_SET_RSSI_ENABLE (TIZEN_OP_CODE_BASE + 0x07) +#define MGMT_SET_RSSI_ENABLE_SIZE 10 + +struct mgmt_cp_set_enable_rssi { + __s8 low_th; + __s8 in_range_th; + __s8 high_th; + bdaddr_t bdaddr; + __s8 link_type; +} __packed; + +struct mgmt_cc_rsp_enable_rssi { + __u8 status; + __u8 le_ext_opcode; + bdaddr_t bt_address; + __s8 link_type; +} __packed; + +#define MGMT_OP_GET_RAW_RSSI (TIZEN_OP_CODE_BASE + 0x08) +#define MGMT_GET_RAW_RSSI_SIZE 7 + +struct mgmt_cp_get_raw_rssi { + bdaddr_t bt_address; + __u8 link_type; +} __packed; + +#define MGMT_OP_SET_RSSI_DISABLE (TIZEN_OP_CODE_BASE + 0x09) +#define MGMT_SET_RSSI_DISABLE_SIZE 7 +struct mgmt_cp_disable_rssi { + bdaddr_t bdaddr; + __u8 link_type; +} __packed; +struct mgmt_cc_rp_disable_rssi { + __u8 status; + __u8 le_ext_opcode; + bdaddr_t bt_address; + __s8 link_type; +} __packed; +/* RSSI monitoring */ + +/* For handling of RSSI Events */ +#define MGMT_EV_RSSI_ALERT (TIZEN_EV_BASE + 0x04) +struct mgmt_ev_vendor_specific_rssi_alert { + bdaddr_t bdaddr; + __s8 link_type; + __s8 alert_type; + __s8 rssi_dbm; +} __packed; + +#define MGMT_EV_RAW_RSSI (TIZEN_EV_BASE + 0x05) +struct mgmt_cc_rp_get_raw_rssi { + __u8 status; + __s8 rssi_dbm; + __u8 link_type; + bdaddr_t bt_address; +} __packed; + +#define MGMT_EV_RSSI_ENABLED (TIZEN_EV_BASE + 0x06) + +#define MGMT_EV_RSSI_DISABLED (TIZEN_EV_BASE + 0x07) +/* Handling of RSSI Events */ + #endif /* __MGMT_TIZEN_H */ diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 0bca035..330cf77 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -1833,6 +1833,30 @@ static void hci_cc_set_ext_adv_param(struct hci_dev *hdev, struct sk_buff *skb) hci_dev_unlock(hdev); } +#ifdef TIZEN_BT +static void hci_cc_enable_rssi(struct hci_dev *hdev, + struct sk_buff *skb) +{ + struct hci_cc_rsp_enable_rssi *rp = (void *)skb->data; + + BT_DBG("hci_cc_enable_rssi - %s status 0x%2.2x Event_LE_ext_Opcode 0x%2.2x", + hdev->name, rp->status, rp->le_ext_opcode); + + mgmt_enable_rssi_cc(hdev, rp, rp->status); +} + +static void hci_cc_get_raw_rssi(struct hci_dev *hdev, + struct sk_buff *skb) +{ + struct hci_cc_rp_get_raw_rssi *rp = (void *)skb->data; + + BT_DBG("hci_cc_get_raw_rssi- %s Get Raw Rssi Response[%2.2x %4.4x %2.2X]", + hdev->name, rp->status, rp->conn_handle, rp->rssi_dbm); + + mgmt_raw_rssi_response(hdev, rp, rp->status); +} +#endif + static void hci_cc_read_rssi(struct hci_dev *hdev, struct sk_buff *skb) { struct hci_rp_read_rssi *rp = (void *) skb->data; @@ -3682,7 +3706,15 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb, case HCI_OP_LE_READ_TRANSMIT_POWER: hci_cc_le_read_transmit_power(hdev, skb); break; +#ifdef TIZEN_BT + case HCI_OP_ENABLE_RSSI: + hci_cc_enable_rssi(hdev, skb); + break; + case HCI_OP_GET_RAW_RSSI: + hci_cc_get_raw_rssi(hdev, skb); + break; +#endif default: BT_DBG("%s opcode 0x%4.4x", hdev->name, *opcode); break; diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 06333ac..e265536 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -6625,6 +6625,689 @@ unlocked: return err; } + +static void set_rssi_threshold_complete(struct hci_dev *hdev, + u8 status, u16 opcode) +{ + struct mgmt_pending_cmd *cmd; + + BT_DBG("status 0x%02x", status); + + hci_dev_lock(hdev); + + cmd = pending_find(MGMT_OP_SET_RSSI_ENABLE, hdev); + if (!cmd) + goto unlock; + + if (status) + mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_RSSI_ENABLE, + mgmt_status(status)); + else + mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_SET_RSSI_ENABLE, 0, + NULL, 0); + + mgmt_pending_remove(cmd); + +unlock: + hci_dev_unlock(hdev); +} + +static void set_rssi_disable_complete(struct hci_dev *hdev, + u8 status, u16 opcode) +{ + struct mgmt_pending_cmd *cmd; + + BT_DBG("status 0x%02x", status); + + hci_dev_lock(hdev); + + cmd = pending_find(MGMT_OP_SET_RSSI_DISABLE, hdev); + if (!cmd) + goto unlock; + + if (status) + mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_RSSI_DISABLE, + mgmt_status(status)); + else + mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_SET_RSSI_DISABLE, + 0, NULL, 0); + + mgmt_pending_remove(cmd); + +unlock: + hci_dev_unlock(hdev); +} + +int mgmt_set_rssi_threshold(struct sock *sk, struct hci_dev *hdev, + void *data, u16 len) +{ + int err = 0; + struct hci_cp_set_rssi_threshold th = { 0, }; + struct mgmt_cp_set_enable_rssi *cp = data; + struct hci_conn *conn; + struct mgmt_pending_cmd *cmd; + struct hci_request req; + __u8 dest_type; + + hci_dev_lock(hdev); + + cmd = pending_find(MGMT_OP_SET_RSSI_ENABLE, hdev); + if (!cmd) { + err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_RSSI_ENABLE, + MGMT_STATUS_FAILED); + goto unlocked; + } + + if (!lmp_le_capable(hdev)) { + mgmt_pending_remove(cmd); + err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_RSSI_ENABLE, + MGMT_STATUS_NOT_SUPPORTED); + goto unlocked; + } + + if (!hdev_is_powered(hdev)) { + BT_DBG("%s", hdev->name); + mgmt_pending_remove(cmd); + err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_RSSI_ENABLE, + MGMT_STATUS_NOT_POWERED); + goto unlocked; + } + + if (cp->link_type == 0x01) + dest_type = LE_LINK; + else + dest_type = ACL_LINK; + + /* Get LE/ACL link handle info */ + conn = hci_conn_hash_lookup_ba(hdev, + dest_type, &cp->bdaddr); + + if (!conn) { + err = mgmt_cmd_complete(sk, hdev->id, + MGMT_OP_SET_RSSI_ENABLE, 1, NULL, 0); + mgmt_pending_remove(cmd); + goto unlocked; + } + + hci_req_init(&req, hdev); + + th.hci_le_ext_opcode = 0x0B; + th.mode = 0x01; + th.conn_handle = conn->handle; + th.alert_mask = 0x07; + th.low_th = cp->low_th; + th.in_range_th = cp->in_range_th; + th.high_th = cp->high_th; + + hci_req_add(&req, HCI_OP_ENABLE_RSSI, sizeof(th), &th); + err = hci_req_run(&req, set_rssi_threshold_complete); + + if (err < 0) { + mgmt_pending_remove(cmd); + BT_ERR("Error in requesting hci_req_run"); + goto unlocked; + } + +unlocked: + hci_dev_unlock(hdev); + return err; +} + +void mgmt_rssi_enable_success(struct sock *sk, struct hci_dev *hdev, + void *data, struct hci_cc_rsp_enable_rssi *rp, int success) +{ + struct mgmt_cc_rsp_enable_rssi mgmt_rp = { 0, }; + struct mgmt_cp_set_enable_rssi *cp = data; + struct mgmt_pending_cmd *cmd; + + if (!cp || !rp) + goto remove_cmd; + + mgmt_rp.status = rp->status; + mgmt_rp.le_ext_opcode = rp->le_ext_opcode; + mgmt_rp.bt_address = cp->bdaddr; + mgmt_rp.link_type = cp->link_type; + + mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_RSSI_ENABLE, + MGMT_STATUS_SUCCESS, &mgmt_rp, + sizeof(struct mgmt_cc_rsp_enable_rssi)); + + mgmt_event(MGMT_EV_RSSI_ENABLED, hdev, &mgmt_rp, + sizeof(struct mgmt_cc_rsp_enable_rssi), NULL); + + hci_conn_rssi_unset_all(hdev, mgmt_rp.link_type); + hci_conn_rssi_state_set(hdev, mgmt_rp.link_type, + &mgmt_rp.bt_address, true); + +remove_cmd: + hci_dev_lock(hdev); + cmd = pending_find(MGMT_OP_SET_RSSI_ENABLE, hdev); + if (cmd) + mgmt_pending_remove(cmd); + + hci_dev_unlock(hdev); +} + +void mgmt_rssi_disable_success(struct sock *sk, struct hci_dev *hdev, + void *data, struct hci_cc_rsp_enable_rssi *rp, int success) +{ + struct mgmt_cc_rp_disable_rssi mgmt_rp = { 0, }; + struct mgmt_cp_disable_rssi *cp = data; + struct mgmt_pending_cmd *cmd; + + if (!cp || !rp) + goto remove_cmd; + + mgmt_rp.status = rp->status; + mgmt_rp.le_ext_opcode = rp->le_ext_opcode; + mgmt_rp.bt_address = cp->bdaddr; + mgmt_rp.link_type = cp->link_type; + + mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_RSSI_DISABLE, + MGMT_STATUS_SUCCESS, &mgmt_rp, + sizeof(struct mgmt_cc_rsp_enable_rssi)); + + mgmt_event(MGMT_EV_RSSI_DISABLED, hdev, &mgmt_rp, + sizeof(struct mgmt_cc_rsp_enable_rssi), NULL); + + hci_conn_rssi_state_set(hdev, mgmt_rp.link_type, + &mgmt_rp.bt_address, false); + +remove_cmd: + hci_dev_lock(hdev); + cmd = pending_find(MGMT_OP_SET_RSSI_DISABLE, hdev); + if (cmd) + mgmt_pending_remove(cmd); + + hci_dev_unlock(hdev); +} + +static int mgmt_set_disable_rssi(struct sock *sk, struct hci_dev *hdev, + void *data, u16 len) +{ + struct mgmt_pending_cmd *cmd; + struct hci_request req; + struct hci_cp_set_enable_rssi cp_en = { 0, }; + int err; + + BT_DBG("Set Disable RSSI."); + + cp_en.hci_le_ext_opcode = 0x01; + cp_en.le_enable_cs_Features = 0x00; + cp_en.data[0] = 0x00; + cp_en.data[1] = 0x00; + cp_en.data[2] = 0x00; + + hci_dev_lock(hdev); + + cmd = pending_find(MGMT_OP_SET_RSSI_DISABLE, hdev); + if (!cmd) { + err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_RSSI_DISABLE, + MGMT_STATUS_FAILED); + goto unlocked; + } + + if (!lmp_le_capable(hdev)) { + mgmt_pending_remove(cmd); + err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_RSSI_DISABLE, + MGMT_STATUS_NOT_SUPPORTED); + goto unlocked; + } + + if (!hdev_is_powered(hdev)) { + BT_DBG("%s", hdev->name); + mgmt_pending_remove(cmd); + err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_RSSI_DISABLE, + MGMT_STATUS_NOT_POWERED); + goto unlocked; + } + + hci_req_init(&req, hdev); + + BT_DBG("Enable Len: %zu [%2.2X %2.2X %2.2X %2.2X %2.2X]", + sizeof(struct hci_cp_set_enable_rssi), + cp_en.hci_le_ext_opcode, cp_en.le_enable_cs_Features, + cp_en.data[0], cp_en.data[1], cp_en.data[2]); + + hci_req_add(&req, HCI_OP_ENABLE_RSSI, sizeof(cp_en), &cp_en); + err = hci_req_run(&req, set_rssi_disable_complete); + + if (err < 0) { + mgmt_pending_remove(cmd); + BT_ERR("Error in requesting hci_req_run"); + goto unlocked; + } + +unlocked: + hci_dev_unlock(hdev); + return err; +} + +void mgmt_enable_rssi_cc(struct hci_dev *hdev, void *response, u8 status) +{ + struct hci_cc_rsp_enable_rssi *rp = response; + struct mgmt_pending_cmd *cmd_enable = NULL; + struct mgmt_pending_cmd *cmd_disable = NULL; + struct mgmt_cp_set_enable_rssi *cp_en; + struct mgmt_cp_disable_rssi *cp_dis; + + hci_dev_lock(hdev); + cmd_enable = pending_find(MGMT_OP_SET_RSSI_ENABLE, hdev); + cmd_disable = pending_find(MGMT_OP_SET_RSSI_DISABLE, hdev); + hci_dev_unlock(hdev); + + if (cmd_enable) + BT_DBG("Enable Request"); + + if (cmd_disable) + BT_DBG("Disable Request"); + + if (cmd_enable) { + cp_en = cmd_enable->param; + + if (status != 0x00) + return; + + switch (rp->le_ext_opcode) { + case 0x01: + BT_DBG("RSSI enabled.. Setting Threshold..."); + mgmt_set_rssi_threshold(cmd_enable->sk, hdev, + cp_en, sizeof(*cp_en)); + break; + + case 0x0B: + BT_DBG("Sending RSSI enable success"); + mgmt_rssi_enable_success(cmd_enable->sk, hdev, + cp_en, rp, rp->status); + break; + } + + } else if (cmd_disable) { + cp_dis = cmd_disable->param; + + if (status != 0x00) + return; + + switch (rp->le_ext_opcode) { + case 0x01: + BT_DBG("Sending RSSI disable success"); + mgmt_rssi_disable_success(cmd_disable->sk, hdev, + cp_dis, rp, rp->status); + break; + + case 0x0B: + /* + * Only unset RSSI Threshold values for the Link if + * RSSI is monitored for other BREDR or LE Links + */ + if (hci_conn_hash_lookup_rssi_count(hdev) > 1) { + BT_DBG("Unset Threshold. Other links being monitored"); + mgmt_rssi_disable_success(cmd_disable->sk, hdev, + cp_dis, rp, rp->status); + } else { + BT_DBG("Unset Threshold. Disabling..."); + mgmt_set_disable_rssi(cmd_disable->sk, hdev, + cp_dis, sizeof(*cp_dis)); + } + break; + } + } +} + +static void set_rssi_enable_complete(struct hci_dev *hdev, u8 status, + u16 opcode) +{ + struct mgmt_pending_cmd *cmd; + + BT_DBG("status 0x%02x", status); + + hci_dev_lock(hdev); + + cmd = pending_find(MGMT_OP_SET_RSSI_ENABLE, hdev); + if (!cmd) + goto unlock; + + if (status) + mgmt_cmd_status(cmd->sk, hdev->id, MGMT_OP_SET_RSSI_ENABLE, + mgmt_status(status)); + else + mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_SET_RSSI_ENABLE, 0, + NULL, 0); + + mgmt_pending_remove(cmd); + +unlock: + hci_dev_unlock(hdev); +} + +static int set_enable_rssi(struct sock *sk, struct hci_dev *hdev, + void *data, u16 len) +{ + struct mgmt_pending_cmd *cmd; + struct hci_request req; + struct mgmt_cp_set_enable_rssi *cp = data; + struct hci_cp_set_enable_rssi cp_en = { 0, }; + int err; + + BT_DBG("Set Enable RSSI."); + + cp_en.hci_le_ext_opcode = 0x01; + cp_en.le_enable_cs_Features = 0x04; + cp_en.data[0] = 0x00; + cp_en.data[1] = 0x00; + cp_en.data[2] = 0x00; + + hci_dev_lock(hdev); + + if (!lmp_le_capable(hdev)) { + err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_RSSI_ENABLE, + MGMT_STATUS_NOT_SUPPORTED); + goto unlocked; + } + + if (!hdev_is_powered(hdev)) { + BT_DBG("%s", hdev->name); + err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_RSSI_ENABLE, + MGMT_STATUS_NOT_POWERED); + goto unlocked; + } + + if (pending_find(MGMT_OP_SET_RSSI_ENABLE, hdev)) { + BT_DBG("%s", hdev->name); + err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_RSSI_ENABLE, + MGMT_STATUS_BUSY); + goto unlocked; + } + + cmd = mgmt_pending_add(sk, MGMT_OP_SET_RSSI_ENABLE, hdev, cp, + sizeof(*cp)); + if (!cmd) { + BT_DBG("%s", hdev->name); + err = -ENOMEM; + goto unlocked; + } + + /* If RSSI is already enabled directly set Threshold values */ + if (hci_conn_hash_lookup_rssi_count(hdev) > 0) { + hci_dev_unlock(hdev); + BT_DBG("RSSI Enabled. Directly set Threshold"); + err = mgmt_set_rssi_threshold(sk, hdev, cp, sizeof(*cp)); + return err; + } + + hci_req_init(&req, hdev); + + BT_DBG("Enable Len: %zu [%2.2X %2.2X %2.2X %2.2X %2.2X]", + sizeof(struct hci_cp_set_enable_rssi), + cp_en.hci_le_ext_opcode, cp_en.le_enable_cs_Features, + cp_en.data[0], cp_en.data[1], cp_en.data[2]); + + hci_req_add(&req, HCI_OP_ENABLE_RSSI, sizeof(cp_en), &cp_en); + err = hci_req_run(&req, set_rssi_enable_complete); + + if (err < 0) { + mgmt_pending_remove(cmd); + BT_ERR("Error in requesting hci_req_run"); + goto unlocked; + } + +unlocked: + hci_dev_unlock(hdev); + + return err; +} + +static void get_raw_rssi_complete(struct hci_dev *hdev, u8 status, u16 opcode) +{ + struct mgmt_pending_cmd *cmd; + + BT_DBG("status 0x%02x", status); + + hci_dev_lock(hdev); + + cmd = pending_find(MGMT_OP_GET_RAW_RSSI, hdev); + if (!cmd) + goto unlock; + + mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_GET_RAW_RSSI, + MGMT_STATUS_SUCCESS, &status, 1); + + mgmt_pending_remove(cmd); + +unlock: + hci_dev_unlock(hdev); +} + +static int get_raw_rssi(struct sock *sk, struct hci_dev *hdev, void *data, + u16 len) +{ + struct mgmt_pending_cmd *cmd; + struct hci_request req; + struct mgmt_cp_get_raw_rssi *cp = data; + struct hci_cp_get_raw_rssi hci_cp; + + struct hci_conn *conn; + int err; + __u8 dest_type; + + BT_DBG("Get Raw RSSI."); + + hci_dev_lock(hdev); + + if (!lmp_le_capable(hdev)) { + err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_RAW_RSSI, + MGMT_STATUS_NOT_SUPPORTED); + goto unlocked; + } + + if (cp->link_type == 0x01) + dest_type = LE_LINK; + else + dest_type = ACL_LINK; + + /* Get LE/BREDR link handle info */ + conn = hci_conn_hash_lookup_ba(hdev, + dest_type, &cp->bt_address); + if (!conn) { + err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_RAW_RSSI, + MGMT_STATUS_NOT_CONNECTED); + goto unlocked; + } + hci_cp.conn_handle = conn->handle; + + if (!hdev_is_powered(hdev)) { + BT_DBG("%s", hdev->name); + err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_RAW_RSSI, + MGMT_STATUS_NOT_POWERED); + goto unlocked; + } + + if (pending_find(MGMT_OP_GET_RAW_RSSI, hdev)) { + BT_DBG("%s", hdev->name); + err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_GET_RAW_RSSI, + MGMT_STATUS_BUSY); + goto unlocked; + } + + cmd = mgmt_pending_add(sk, MGMT_OP_GET_RAW_RSSI, hdev, data, len); + if (!cmd) { + BT_DBG("%s", hdev->name); + err = -ENOMEM; + goto unlocked; + } + + hci_req_init(&req, hdev); + + BT_DBG("Connection Handle [%d]", hci_cp.conn_handle); + hci_req_add(&req, HCI_OP_GET_RAW_RSSI, sizeof(hci_cp), &hci_cp); + err = hci_req_run(&req, get_raw_rssi_complete); + + if (err < 0) { + mgmt_pending_remove(cmd); + BT_ERR("Error in requesting hci_req_run"); + } + +unlocked: + hci_dev_unlock(hdev); + + return err; +} + +void mgmt_raw_rssi_response(struct hci_dev *hdev, + struct hci_cc_rp_get_raw_rssi *rp, int success) +{ + struct mgmt_cc_rp_get_raw_rssi mgmt_rp = { 0, }; + struct hci_conn *conn; + + mgmt_rp.status = rp->status; + mgmt_rp.rssi_dbm = rp->rssi_dbm; + + conn = hci_conn_hash_lookup_handle(hdev, rp->conn_handle); + if (!conn) + return; + + bacpy(&mgmt_rp.bt_address, &conn->dst); + if (conn->type == LE_LINK) + mgmt_rp.link_type = 0x01; + else + mgmt_rp.link_type = 0x00; + + mgmt_event(MGMT_EV_RAW_RSSI, hdev, &mgmt_rp, + sizeof(struct mgmt_cc_rp_get_raw_rssi), NULL); +} + +static void set_disable_threshold_complete(struct hci_dev *hdev, + u8 status, u16 opcode) +{ + struct mgmt_pending_cmd *cmd; + + BT_DBG("status 0x%02x", status); + + hci_dev_lock(hdev); + + cmd = pending_find(MGMT_OP_SET_RSSI_DISABLE, hdev); + if (!cmd) + goto unlock; + + mgmt_cmd_complete(cmd->sk, hdev->id, MGMT_OP_SET_RSSI_DISABLE, + MGMT_STATUS_SUCCESS, &status, 1); + + mgmt_pending_remove(cmd); + +unlock: + hci_dev_unlock(hdev); +} + +/** Removes monitoring for a link*/ +static int set_disable_threshold(struct sock *sk, struct hci_dev *hdev, + void *data, u16 len) +{ + int err = 0; + struct hci_cp_set_rssi_threshold th = { 0, }; + struct mgmt_cp_disable_rssi *cp = data; + struct hci_conn *conn; + struct mgmt_pending_cmd *cmd; + struct hci_request req; + __u8 dest_type; + + BT_DBG("Set Disable RSSI."); + + hci_dev_lock(hdev); + + if (!lmp_le_capable(hdev)) { + err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_RSSI_DISABLE, + MGMT_STATUS_NOT_SUPPORTED); + goto unlocked; + } + + /* Get LE/ACL link handle info*/ + if (cp->link_type == 0x01) + dest_type = LE_LINK; + else + dest_type = ACL_LINK; + + conn = hci_conn_hash_lookup_ba(hdev, dest_type, &cp->bdaddr); + if (!conn) { + err = mgmt_cmd_complete(sk, hdev->id, + MGMT_OP_SET_RSSI_DISABLE, 1, NULL, 0); + goto unlocked; + } + + th.hci_le_ext_opcode = 0x0B; + th.mode = 0x01; + th.conn_handle = conn->handle; + th.alert_mask = 0x00; + th.low_th = 0x00; + th.in_range_th = 0x00; + th.high_th = 0x00; + + if (!hdev_is_powered(hdev)) { + BT_DBG("%s", hdev->name); + err = mgmt_cmd_complete(sk, hdev->id, MGMT_OP_SET_RSSI_DISABLE, + 0, data, len); + goto unlocked; + } + + if (pending_find(MGMT_OP_SET_RSSI_DISABLE, hdev)) { + BT_DBG("%s", hdev->name); + err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_SET_RSSI_DISABLE, + MGMT_STATUS_BUSY); + goto unlocked; + } + + cmd = mgmt_pending_add(sk, MGMT_OP_SET_RSSI_DISABLE, hdev, cp, + sizeof(*cp)); + if (!cmd) { + BT_DBG("%s", hdev->name); + err = -ENOMEM; + goto unlocked; + } + + hci_req_init(&req, hdev); + + hci_req_add(&req, HCI_OP_ENABLE_RSSI, sizeof(th), &th); + err = hci_req_run(&req, set_disable_threshold_complete); + if (err < 0) { + mgmt_pending_remove(cmd); + BT_ERR("Error in requesting hci_req_run"); + goto unlocked; + } + +unlocked: + hci_dev_unlock(hdev); + + return err; +} + +void mgmt_rssi_alert_evt(struct hci_dev *hdev, struct sk_buff *skb) +{ + struct hci_ev_vendor_specific_rssi_alert *ev = (void *)skb->data; + struct mgmt_ev_vendor_specific_rssi_alert mgmt_ev; + struct hci_conn *conn; + + BT_DBG("RSSI alert [%2.2X %2.2X %2.2X]", + ev->conn_handle, ev->alert_type, ev->rssi_dbm); + + conn = hci_conn_hash_lookup_handle(hdev, ev->conn_handle); + + if (!conn) { + BT_ERR("RSSI alert Error: Device not found for handle"); + return; + } + bacpy(&mgmt_ev.bdaddr, &conn->dst); + + if (conn->type == LE_LINK) + mgmt_ev.link_type = 0x01; + else + mgmt_ev.link_type = 0x00; + + mgmt_ev.alert_type = ev->alert_type; + mgmt_ev.rssi_dbm = ev->rssi_dbm; + + mgmt_event(MGMT_EV_RSSI_ALERT, hdev, &mgmt_ev, + sizeof(struct mgmt_ev_vendor_specific_rssi_alert), + NULL); +} #endif /* TIZEN_BT */ static bool ltk_is_valid(struct mgmt_ltk_info *key) @@ -8931,6 +9614,9 @@ static const struct hci_mgmt_handler tizen_mgmt_handlers[] = { { add_white_list, MGMT_ADD_DEV_WHITE_LIST_SIZE }, { remove_from_white_list, MGMT_REMOVE_DEV_FROM_WHITE_LIST_SIZE }, { clear_white_list, MGMT_OP_CLEAR_DEV_WHITE_LIST_SIZE }, + { set_enable_rssi, MGMT_SET_RSSI_ENABLE_SIZE }, + { get_raw_rssi, MGMT_GET_RAW_RSSI_SIZE }, + { set_disable_threshold, MGMT_SET_RSSI_DISABLE_SIZE }, }; #endif -- 2.7.4