From 1b296c7cf0fadafae13c105861b7ba20a297b617 Mon Sep 17 00:00:00 2001 From: pkroad Date: Sat, 6 Jan 2024 17:14:01 +0800 Subject: [PATCH] =?UTF-8?q?[bug]:=E4=BB=A3=E7=A0=81=E9=9D=99=E6=80=81?= =?UTF-8?q?=E6=89=AB=E6=8F=8F=E6=8A=A5=E8=AD=A6=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [处理方案]: 删除不使用的文件夹从新扫描。 --- .../peripherals/bluetooth/Makefile | 69 - .../peripherals/bluetooth/rtkbt/BUILD.gn | 93 - .../bluetooth/rtkbt/Firmware/BT/fw_info.txt | 2 - .../rtkbt/Firmware/BT/rtl8723d_config | Bin 6 -> 0 bytes .../bluetooth/rtkbt/Firmware/BT/rtl8723d_fw | Bin 50608 -> 0 bytes .../bluetooth/rtkbt/Firmware/LICENSE | 56 - .../peripherals/bluetooth/rtkbt/code/LICENSE | 177 - .../code/libbt-vendor/include/bt_hci_bdroid.h | 76 - .../rtkbt/code/libbt-vendor/include/bt_list.h | 160 - .../code/libbt-vendor/include/bt_skbuff.h | 339 -- .../code/libbt-vendor/include/bt_vendor_rtk.h | 255 -- .../code/libbt-vendor/include/hardware.h | 217 -- .../code/libbt-vendor/include/hci_h5_int.h | 80 - .../code/libbt-vendor/include/rtk_btservice.h | 26 - .../libbt-vendor/include/rtk_btsnoop_net.h | 58 - .../code/libbt-vendor/include/rtk_common.h | 66 - .../code/libbt-vendor/include/rtk_hcidefs.h | 2646 -------------- .../code/libbt-vendor/include/rtk_parse.h | 157 - .../code/libbt-vendor/include/rtk_poll.h | 32 - .../code/libbt-vendor/include/rtk_socket.h | 73 - .../rtkbt/code/libbt-vendor/include/unused.h | 25 - .../rtkbt/code/libbt-vendor/include/upio.h | 119 - .../rtkbt/code/libbt-vendor/include/userial.h | 74 - .../libbt-vendor/include/userial_vendor.h | 208 -- .../code/libbt-vendor/include/utils/Log.h | 24 - .../rtkbt/code/libbt-vendor/src/bt_list.c | 124 - .../rtkbt/code/libbt-vendor/src/bt_skbuff.c | 495 --- .../code/libbt-vendor/src/bt_vendor_rtk.c | 656 ---- .../rtkbt/code/libbt-vendor/src/hardware.c | 377 -- .../code/libbt-vendor/src/hardware_uart.c | 1456 -------- .../code/libbt-vendor/src/hardware_usb.c | 1171 ------- .../rtkbt/code/libbt-vendor/src/hci_h5.c | 2752 --------------- .../code/libbt-vendor/src/rtk_btservice.c | 758 ---- .../code/libbt-vendor/src/rtk_btsnoop_net.c | 428 --- .../code/libbt-vendor/src/rtk_heartbeat.c | 303 -- .../rtkbt/code/libbt-vendor/src/rtk_parse.c | 3059 ----------------- .../rtkbt/code/libbt-vendor/src/rtk_poll.c | 263 -- .../rtkbt/code/libbt-vendor/src/rtk_socket.c | 190 - .../rtkbt/code/libbt-vendor/src/upio.c | 543 --- .../code/libbt-vendor/src/userial_vendor.c | 2651 -------------- .../bluetooth/rtkbt/code/rtkcmd/rtkcmd.c | 264 -- .../rtkbt/vendor/etc/bluetooth/rtkbt.conf | 37 - 42 files changed, 20559 deletions(-) delete mode 100755 hispark_phoenix/peripherals/bluetooth/Makefile delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/BUILD.gn delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/Firmware/BT/fw_info.txt delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/Firmware/BT/rtl8723d_config delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/Firmware/BT/rtl8723d_fw delete mode 100644 hispark_phoenix/peripherals/bluetooth/rtkbt/Firmware/LICENSE delete mode 100644 hispark_phoenix/peripherals/bluetooth/rtkbt/code/LICENSE delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/bt_hci_bdroid.h delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/bt_list.h delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/bt_skbuff.h delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/bt_vendor_rtk.h delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/hardware.h delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/hci_h5_int.h delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_btservice.h delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_btsnoop_net.h delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_common.h delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_hcidefs.h delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_parse.h delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_poll.h delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_socket.h delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/unused.h delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/upio.h delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/userial.h delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/userial_vendor.h delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/utils/Log.h delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/bt_list.c delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/bt_skbuff.c delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/bt_vendor_rtk.c delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/hardware.c delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/hardware_uart.c delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/hardware_usb.c delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/hci_h5.c delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/rtk_btservice.c delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/rtk_btsnoop_net.c delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/rtk_heartbeat.c delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/rtk_parse.c delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/rtk_poll.c delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/rtk_socket.c delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/upio.c delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/userial_vendor.c delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/code/rtkcmd/rtkcmd.c delete mode 100755 hispark_phoenix/peripherals/bluetooth/rtkbt/vendor/etc/bluetooth/rtkbt.conf diff --git a/hispark_phoenix/peripherals/bluetooth/Makefile b/hispark_phoenix/peripherals/bluetooth/Makefile deleted file mode 100755 index d8dd4f4d..00000000 --- a/hispark_phoenix/peripherals/bluetooth/Makefile +++ /dev/null @@ -1,69 +0,0 @@ -#=============================================================================== -# export variables -#=============================================================================== -ifeq ($(CFG_HI_EXPORT_FLAG),) - ifneq ($(srctree),) - KERNEL_DIR := $(srctree) - - SDK_DIR := $(shell cd $(KERNEL_DIR)/../../.. && /bin/pwd) - else - SDK_DIR := $(shell cd $(CURDIR)/../../../.. && /bin/pwd) - endif - include $(SDK_DIR)/base.mak -endif - -#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -# variable -#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -objects := - -ifeq ($(CFG_HI_BT_DEVICE_REALTEK),y) -objects += rtkbt/driver -endif - -ifeq ($(CFG_HI_BT_DEVICE_MT7668U),y) -objects += mt7668u/driver -endif - -ifneq ($(objects),) -obj-y += $(addsuffix /,$(objects)) -else -$(error "If bluetooth support, you must choose one bluetooth device at least!!") -endif - -objects_clean:=$(addsuffix _clean,$(objects)) -objects_install:=$(addsuffix _install,$(objects)) -objects_uninstall:=$(addsuffix _uninstall,$(objects)) - -#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -# rules -#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -#================================================================== -# all -#================================================================== -.PHONY: all clean install uninstall -all: $(objects) - -clean: $(objects_clean) - -install: $(objects_install) - -uninstall: $(objects_uninstall) - -#================================================================== -# modules -#================================================================== -.PHONY: $(objects) $(objects_clean) $(objects_install) $(objects_uninstall) - -$(objects): - make -C $@ all - -$(objects_clean): - make -C $(patsubst %_clean,%,$@) clean - -$(objects_install): - make -C $(patsubst %_install,%,$@) install - -$(objects_uninstall): - make -C $(patsubst %_uninstall,%,$@) uninstall diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/BUILD.gn b/hispark_phoenix/peripherals/bluetooth/rtkbt/BUILD.gn deleted file mode 100755 index 512237a2..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/BUILD.gn +++ /dev/null @@ -1,93 +0,0 @@ -# Copyright (c) Hisilicon Technologies Co., Ltd. 2022-2022. All rights reserved. - -if (defined(ohos_lite)) { - import("//build/lite/config/component/lite_component.gni") -} else { - import("//build/ohos.gni") -} - -config("bt_warnings") { - cflags = [ - "-Wall", - "-Werror", - "-Wno-switch", - "-Wno-unused-function", - "-Wno-unused-parameter", - "-Wno-unused-variable", - "-Wno-implicit-function-declaration", - "-Wno-incompatible-pointer-types", - ] -} - -group("rtkbt_group") { - deps = [ - ":libbt_vendor", - ":rtkbt.conf", - ":rtl8723d_config", - ":rtl8723d_fw", - ] -} - -ohos_shared_library("libbt_vendor") { - output_name = "libbt_vendor" - sources = [ - "code/libbt-vendor/src/bt_list.c", - "code/libbt-vendor/src/bt_skbuff.c", - "code/libbt-vendor/src/bt_vendor_rtk.c", - "code/libbt-vendor/src/hardware.c", - "code/libbt-vendor/src/hardware_uart.c", - "code/libbt-vendor/src/hardware_usb.c", - "code/libbt-vendor/src/hci_h5.c", - "code/libbt-vendor/src/rtk_btservice.c", - "code/libbt-vendor/src/rtk_btsnoop_net.c", - "code/libbt-vendor/src/rtk_heartbeat.c", - "code/libbt-vendor/src/rtk_parse.c", - "code/libbt-vendor/src/rtk_poll.c", - "code/libbt-vendor/src/rtk_socket.c", - "code/libbt-vendor/src/upio.c", - "code/libbt-vendor/src/userial_vendor.c", - ] - - include_dirs = [ - "code/libbt-vendor/include", - "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", - "//foundation/communication/bluetooth/services/bluetooth/hardware/include", - "//drivers/peripheral/bluetooth/hdi/ohos/hardware/bt/v1_0/server/implement", - ] - - cflags = [] - - configs = [ ":bt_warnings" ] - - external_deps = [ - "c_utils:utils", - "hilog:libhilog", - ] - - install_enable = true - install_images = [ "system" ] - module_install_dir = "lib" - - part_name = "hisilicon_products" -} - -ohos_prebuilt_etc("rtl8723d_config") { - source = "Firmware/BT/rtl8723d_config" - install_images = [ chipset_base_dir ] - module_install_dir = "firmware" - part_name = "hisilicon_products" -} - -ohos_prebuilt_etc("rtl8723d_fw") { - source = "Firmware/BT/rtl8723d_fw" - install_images = [ chipset_base_dir ] - module_install_dir = "firmware" - part_name = "hisilicon_products" -} - -ohos_prebuilt_etc("rtkbt.conf") { - source = "vendor/etc/bluetooth/rtkbt.conf" - install_images = [ chipset_base_dir ] - relative_install_dir = "bluetooth" - part_name = "hisilicon_products" -} diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/Firmware/BT/fw_info.txt b/hispark_phoenix/peripherals/bluetooth/rtkbt/Firmware/BT/fw_info.txt deleted file mode 100755 index 65448c95..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/Firmware/BT/fw_info.txt +++ /dev/null @@ -1,2 +0,0 @@ - FW CUT SVN Coex -rtl8723d_fw C 21678 2f2f diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/Firmware/BT/rtl8723d_config b/hispark_phoenix/peripherals/bluetooth/rtkbt/Firmware/BT/rtl8723d_config deleted file mode 100755 index 91d3f4402289e7b0efd395c7fcc8b4789465aba6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6 NcmWGtt=!JQ000Mk0jmH2 diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/Firmware/BT/rtl8723d_fw b/hispark_phoenix/peripherals/bluetooth/rtkbt/Firmware/BT/rtl8723d_fw deleted file mode 100755 index bc8fc08fcdb03a05e29359fca81be12cbd88107d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 50608 zcmd4433wCNxi>x|jbz!D?XfUM>_RpHY?FW&$R1$~u|ZA=S?Ul-M;K>}G%|@HDQ!bK zA!MydvCS5ienK`WF@}O9lic3sR8BEh;HT@rI~!Ig9{70Ba7O*BQLcx*A^D6#FL1pm)nPVhog+) z{nrtQkMPE>BM~3zrK@HGb4gvvRF&-EO^sRVqMgAkLc*Z?? zeY8Ug$yO=ETw&)+VaBep$>q^{WGbrcICWu@xs|jc_avBzX;iva?Cv%F{_VrD~K^EmG-SV}e1pEJ44xd3gllPyd>i zFI^vP=e%_ROTH!F8BlvoJ(f?YkACN3_Aqv}*K$xvJNUqIgFFj?v6mL;d{3W4J3dQj zD=Dl$FLbiAlpYEs&FiyK{W#>yL-?jLVWIYLnkQOa*YjqJ$vATqr-|042`j|XovDH3 zobJoISrt7xkD+H;cXy=B#m=h`S)Q>cY|yS@E^(DRp2hgq8|1%MCN9(+NjMx`%v9gv zbu~pLeMoauHr9{lj&tiYjk^Mt4wPlD=rN(ai_dgNO5JSjARCuI(pz@c(voV{6%6+| z&k36!53)Judklf;y{zz{h*~eU_Ohk8+pRrG6-R8*ry09Sh}!c4ywB3fdsED=o$s9S zUvDaWBiwji{cwVfb?SYtPRl_RZ`o<-Ox&QWPe5HYl`Pszb)|Mw`%4fk2*n7oe!y3% z^`TfV49i&{R<|g14yGt$)E!xab+g^g7>{3KsuI0&A1}Ffa*jm-eb^ahjMHc8!|{Hh z@2p{&eY8fo!&Giv4|CZdQLa5Ab2;NiEb~Up*dNnu;80(6<=2&I3saAz(A$eu%Q}0f z*qE#Otx3ljR){LQDKewObOm!Ya;{^}LGAHm&&o{+>k}Jv8yMq*X0A)kGsb0m zj)-X+QtMMt8y(g&jWvV5ns17Yw`B`6cbLH1xvn&irpwl<%u`7U{Ke`2imhqBqF-V% zHb0~7(s`qj?6frP4A%vA1u&005;w4R8WE;yjzKHGhj~o%M}?A7P*RGAl~6_>k1|r0 zXuGJCgswzyB4|sZR~KO<%jVSq%cqH;Gx0JmM*YkeO}zXuXbP>1zRHmcM;sY`IBKs8 zFpi|I=RM4bKbnO06<(Dn^yM`@=fR5JECo0->qtJTKdR+(d;QnVlNqP}Nb>Pzo{~*` z*E00mvu<|jVB1DzW#}|~&gbG&yOlK&tm&T-R?xzx+%r&N3ZmkP% z6+N9v>m!ByhC@C4`rxHQm;BeyOzoK(4h`LKb;_ZTas4U8(>8pAcpid&ee#Awy%R&{ z5RcZR*LQ|!A6eZ~SZJu9gq-Ce<{CYxHl(bjakNfem0#YQ>&x?4+;Veg@0|RNg{uPz zQfp{+pi`l3$z8YLH`8QRVy;>8le%a=m@yxc8(##41wl6%~OR&9MK$}W$9t2=|}EOv-upCRZx z=a1N%G)piA;Cz4y5InP#Wz5qdhM72*h^>G&z`&xrn!@&9d?S3FD*;FIH01U=P!t?6E{D z+bxmoc2F9(0d;5W>1Zhh(8YQU#)QL|&>lr&LE~UWps}F6i^hV+ifAX%>X`^C1ftJ0 zMnp?fJ;El&p2E9!et{8a4JEg|yK8qyorgY>u+pzqZ@!$X$w_F7%>||=&WlLk5$KzD zuq;F6RJTT#4ik8+@O|#gvFLs0yTOz;^#1vGTja~dJ9neivzs|{Wiy9${GAd(yNJJu z&nGJLFO|s)la3@FHf_1jQ6lCACoPRiyltWT$GP`;{X1W9PjXbY^A1O_E@*3aZK8Rq zlFIn3r7ByNRLrL@ond1)ne&VD>jFc~DqIWaCD=w^XYI2C)*kI;#;)Tt<|PR66xCJ6 zUf#o8GZ%oPYtQ7zc`Y4`J+bx{uiEx=>9r1yXQlG9zX-`4=oe5Y+Vw~KOvZmLWU6Q! zqmJk-DUdpk6Y52i@k-$yahyb>$yBlS(fshGBW&i$=E-%v>Iuwcrdq{=>QuY>wEg=N zQG8C)d;a1St_`c%)|atFqtIyW;m?LJ_T&vo^@$j1Z6)!2>%ps)PK&LdE0seR8jlP) zJpA~G6N^N-b@bJt_BR3=^N+5kFY`y#!l(SorloDm_N5+M=Ckalz)EPtq1v{Mhc+CN z|M)ag7$@zzM8(pNrZ=Xpd;6@}&DbC1A3UpRPIInmZtdwPW-!MyP8>Pg)U3h`Ny)DC zbvLs==-$6ZKy^(Kt+^4VlSoFWeE_ti))~ZnG58{z?AB*yb5BvPh zo}y4V6~7)o@7kZSc8~bx*%#l+3)Njx-8QSuwX1BO>yK>B%SD~x!=h^9thST8%HBEo zr`L<~LA71knBUL1{Z~?ICR`r6B;hFSXF6OTb|-cXN3Nu< zVYnuDjmDKIs=jL|KfP(B?=Md3d+yjUpXQkV%HSGSns9m8l5~aYYP-@K8RrKgV_fQ$ zce3^bet08mw{(nH%h)kK_Msb$^+PcJDU|}&?2`yYLy4BsdU+goqPq(aDiEGPAlgba zHpVMiTA8bwTD8Dj9a=lY##AdDSdYG+Yplk8thIGV=D5{4CgaFE*N6kWVZf$vPRi;e z8bamiJ*>mh_w)7?Tz}f0gzL}REq%`+tU!3aUE|ZXF~+*P`F=`4Jp3jWJR)S5I8STz z4E0t9Zm}6X@+PDAjo_GERm+gJk^B%}@r>!AVK%=TyTOv_GpF}t*k+v13Z>g#*e+}* znJN_OzLGINQJCJH;!&5^pP?^>diIKE#t(3%OjYE*beUwOQiMl#X1($N?op&sU8oI- zKE}xye}1C6M%N$H*J%4=y8e34{|zq}B3Kb({g~%*MYL|tBpZK{3!2Nz#!}qJd5R$2 zENnO7x~M$^*Q)lxxIWolh^vTx68fs!=i<7!{TW=g$}C?8l@2-)+l`=0(jU`H=iG z9sl3&Q`K@dlVmb3c~<2Fh3}`wcbdjXQ%rwZUT9)Iy4~ck)XIg2GfkuBWn``U%e`4z zwI%CKHRL9q5m+XhNnjY^a6&c``v37GndbhP#-Hyz~s=oKI(ri~-Ms82Kzh3xY75VZK4|AQU6tv>g0~(1IY~ z-ER;)2=p5}p6O-tm{)gGzR9sWI~e5+W@Hn>G=#+nzd-OJe2NgIy!Rr{y~u-rxV#wQ z7YJU2PZ1~&TS5PxSpNLRU;W$P>0e33kC*Sji~G9DWxW1B@{i`-B1pE2ygFx0BT%Y!Je4b~XS2)es=e1c2DyBTs!_T<=4;KGc7G81aX_vFjsW%wEtR$c$qJD zorU-;U+g*?@!3AQS|TgmNb9gfUUVa0M_GT4fqZIk7Ou#%?P`ZB^5gdVz2G+cwJ`cq z13DNP^yFSuY@HQ-%*%JDLVtog5539@(5sBVeegbBei-Rny`V?9TPY9XYkz8x*Mdf$ zKZ<-QxcBR8p7{`Z9K81$p2vg7+KxMedwmBl@5kQ%CiEARpuc$yG_3^byP(&=WRnX~ zRz5-o(#GSy`Xl^~a#kGSlo^K=-rrJC}lh731q?<@AL9TwB?zDC?D@FY!<*1GkmTR5_PnuHP{&(mpjBOY!08TY@#Pq?qEFq z?d;iKhr*rVp%d9zoq@!8XKg%hoizB|+3m7(XSnrJw5Ib?@@?$dvo6Y|RdS`zy9llX z#LUjFLEXXQ{x01hpF{th!X3NZf2m`O<&nbm=U>S;^`L+4){EAVH5>~3@H}(PRm5Ct zDtb43^c=~C%(WK_DZe4SF=Pn6cAoO5_U})Sji7zY!F3UK?eFeViAbq#e+1XXistQR z-5YDC9%Rvj8nb0fI#z}huzW_NM}41y(a@PwkVC#P{wX<0c;@kj&Ma(EMHs|Lo>zgl zruV+acxB`otb=X~9L1K_pel>U%uqQf#(A+j-S`G=FEfjm?7T^--+mwUGBdeXgWgY@UwUo+-?17Pin=n%mP(%FF9S7m`aRZ3v0mP1~Q@jF<8St$*ggqx*Z{eMf^ ztpk0#lj`$7Ebmfz#8;ENOS+KsHrA2uQAtmtr@ooO)TH?=Ti99D;?-u%6}x`l8F8hU z1paz6G>STK&x}zvuXnNz&LbX3K#RG`LX<_kKkWw-LHnuih&Dv+L>;Ulou{}(F4|M{ z$azo-d%k3ap4HjK-jM4_mrL)s`i4O&ESX92A*aMF&Lj_Wm7$#xw0*Q)hWu&`OJVs6 zS57&t;dr0F{JnbGk{f#3Sd8?vu^8!TDHi8m<8lIh#TptbS}#VcS*PY0cOukdkw{WH zbIjVCX3FrG4$P5Q@bYJl9TB&RVoBm`c_;6Y4?HMo`RO-)DUrDKlm}(3AA@h5IR?F6 z|F2BVfaGw?&#-qQ#J@jm@9;gty_Pq}NNkO@hxr7$=`QLm%~7r))5q47hvZK*jZ~tu zYuirLp@-5a$dy)%!?A3vGv8=z}rHirIa_0nt zY{Xu0OaHv%4$H>vIZV|Ml$DY*#Dlq39g|2?!ZcS)W}cP|9_B!r*V4q!BE2SaZF)Xi zYw1X{VP!+Jo1CSG9L-#29CblWZjyI;P-SChT^!En3W0R6VS$3 zyEJH5yp}iDF+Lx$j`O3?y)6WQ;R%O=hlTO};hoi243$ z%FHTYu2mMKKg8O2&`yi;#5}ZIBrP!UK=HY!nyV4au(`>7L)}Sy+T77z&PGpqx0*6dGkkGCtPRXTHQjFi~F>S-lfgM1C1@r^UboEMqu zS1i%RiPpSOj4p5mY$@-{>v5hNRbe^UXS?~$bY;#<7h~_zFAKUxNyYgOIN!q<%Z_5c87Jqi5eMcr^>4gB`n}AX zY-!qf+4w%RK&-S^Ox(vTQFi9T-B)zzUD+(ZIq)vYWSY1xDZ(hD=HS;j;A+1{TU`mJ<9zCCM#D zo7=upqOp)TIHaHh9l{RqxR@xYiL5*?ICOUc2CN&)Z>QU8DD_U>3V`sX_WE{ zv8qIOS}y6w^Pz{$2XFKjXZu&fYW80l3|lCDubkJoEt~X{*fS+A$QZR_g(!4i49gOi(RJBAluAY#xR^PzR(s$__@s*(d zsJw@}V&)N&j9PPkdirRC$))05hwA0#KI%fR7 zZI>6mRgyc-3)^@Ta3xKyqSayOKM)t2h)V7PO(P8oBrA++O4dl)0VH9k6jEW&vj({= zrf>dRs(EGsRKI#csWFi0*((y_z!I6}D*FOgzigb6$E{8Ayl~m-R+~-6MI%9Z`sSh! zO~z`DTg$E8OEb`YGkZy8;aGr6-jTHV@uu zkDG1vuGuOQp!r7C*&E?qZC-VU(`!Pq(3cQXm)}BguNy8sP+i0 zdtFy*qowIR@had#NUyb1b|bbG0ILi((~qMbr#)VHtN^@d`Vf8 zfAbSXY&q4$dWq^mZ@-tL9`o>y8DA8B%-9Dg2FHsKT&&>ER`Nk zCdjViQsc@y>@2Wx&>Op`VSqjp1Z)pV1w zCdnEqhLx2uUYIfWV|LbzQ+d$xz64ayBB0<11NS82_X8P6^olqpX8>b`n%r)#a*>8e zn=^k$?T#Ou)jo8aaI1NR$k^wAzRnIj*ug~7H74UDBJK5an%UaXwx^rt?WhT8&FPqv z%iXj>2Io|{(v{gi1MeVSqP-cVZv?c^9%OQ_~QO;bIm}S7@yn5I%jNS7U%QAW^3W9>&>bqYd#P*bDX{D=?_>(?FYaqVb9QY z=^FF}!+_0N1PO*Mi*dJ6ht$glq(FvGugts`dq1`rzD13q_6b0a#gJ2$%d-@!UCpf# zbspONboLTIW1r!l>A&BfvO!;;jD05o?W8@2+8U!hOtozMbfRM81Lviy_}Zp+4DvXF zYKgSnuE>UV-t!VDb`{BTH*j{bZ>9iI2W{VtRGmTr5|J90S*S1Pml@>Sf%y=CxpP8S zd^h4{{}z)QV;DZQO*Rg?mFQ!fR>gU$(R&0}f*mV(F)ZxIl8>jH?Cc$HCY%w`K(34S z^aL~GfOOlhOUmRke6HpU4+pKGWm967<$7_!TlqDht1*3*icf`pk~AotDD+>x7jySUEj82XF!%A`}KKErwlD|H1`rRS1X)0L#!!8Xg5X1AkdhWo7| z^)soqLA82YH=*%@)GLe6_#@yevsj04c||*8Ou85^fvJkyQBB4XPsUT@JY7j^wrII( zs2yixwpd()YK^vqF3<#iQBhm>%I#@2ouT))8=wpUtL7Ba>^9(lbmt=1%rHXCSFDSJm0{Kt@7n=4I9ZL=5D1*>5xa&3P5 zjOEj5u4L~l;4Z+4o)ucy*}?%eZ!+F8h1$$vZW7+(n~5>JAn8<~DXv$4E zyObmP<4YBs-BQ>=25@%IkNP&w&Z(^1?#KYnZV|YY>Tlufp1cWXm)TX>=HLE!n``?5 z*caC~8IB8xn<7_XX?&(B{rD3=Z)A(cV;V6kg?sCI2!oe=IJ1G9Sb<-FC_47TIMU8R zNV^&!?Y4@`#b1}C9W5%Cw?7CA-2Fb_?0~r&G8US-e#Bj7SH=n1cw5fklV#sQ+>vHt z@P>@_nGGch;%+3cFW*e93wu6JYCH@{nyKd3JA3%XgBP6_{ny*4d<;b0(Dla(oFQZ5 za>P^CheP@ed3Zk5d#+$2(00yHr-HUKY*^iszIJUvq;Pex9Q&0};Ot2QH=n%LI(ZS$ zb`wBNI(tdRwBYF$pujC|p-DmG#w1 zXWKPs+7vEE)3rxDf<1w-OW(!Vksh8fcJX;#hq>_v!Y80lFXA4bGjBo1VgZefW9-J^ zw-d-i`s$Oole`h9FAx4FoZSNo&aNCfFT&Ybp&hp>I6JF?vzrB}z6|qXhJv%34xHUI zq|8)sc1XJkXE*&jIJ;DGYj!-y+wi^Yz z1fg@{XgkCewB6rs9VZR?9<&_~?I{p<-;1^*TM>;3jmN79G$v$2qA{T{qjgQ|dnLj> z2(+eYtm1MK?QY-39$)x>f<1obJJ@4t1I?A^OapT0|0FJF^*_Mnko}xTAY4u+?r~gB zjQ*o{s`Vk0k*NPa!;7axz7H=>bOC!Ab{DRa#)0tSalY+4hy0 z<0ilcv-<9&nkz$;T_2Pnw(Hy7<}BiWQ$wTjESFz%v&)9r(v}*9jHQ`^VQHGpADQRY zL#qvs2e&SlR*-5QXCs99qi#(O$L+=U{*=Sk#H5s@#}3tMB*A#y(woc9WkvL zSMk4Wsg1D1b;P(m;%kZDqd7PUI_<)2tuhyBoOb{(7?&Gnc{owtG*+BeLR`^L&5TpS z&FpWDs$gLOq>>=Jbb-y<`}i2&S{3EMk^!Ut)161KyBk2pAP;5aYZR*0~! z7$2N8r(Z&d$p;@pKSO=EAAMJiU_!sf=Mpffu#4seCe=nA588^G$JOeE@xXp+&9~I1 z3qF2)ZL+YJpAWl_j(^?aE#aePbO z0A}0GL5~!BXF&f;az$REL4FB%9+EG7z&^xfj8Ptcq{2<|`J^29e)Uzjx!PPoT{}Sl znsn1G;Nl;eOx{*Np)MKXeRN9bBKyFiC0}2ZcSfCti|rwU%>q4AE9~qE${l)b%+}9H@PWGtU1BgZ)r|4eF|n4>H6BNM72P#g zamkhrBoXNs3})Wj)Rc%d(HfZEVQEeQXZtAR5?7OY*29IPfl(mcz<^9bxC81J>JJ*T zbC^?~AzZIaU&tRxgLTr4u^8oH+@pZQ!^k0U&bqK=)01NI*q4iFKI{$vr5uPNkj8|C zyqd7MdsBwTwP`TMlRJ`dOm`ybWb$#tUJdlwW3H&7KQ}DV9MK+5#2)lHP{YuHW3^F8 z-@wM7gdNwZvbXkh1}2GI&X|(hdknp;z353NS#cNto;%7l4#JFgMP7Bg zB4utu7EbR?f*+m?4GeHF<|hlD?uMrLBUnIgc!tIF-89EZ_dxwgc%L|4eVwNtu?|#G z9brnO29JDN-WkKMC-&plM+&2_W-jZF7z9oF%BI)begPc&FMwF55W}&*){kR<6)A*M zARK$i{{fEur{BS`-!&g+jVErmpF6wLc1T9Izsxb@p1b48P@C>1d@SB{vrP76z(K9oklp0@F@aeZb(L=wR0Elw6oHb^w*{Zafff*dYXW~u z?K41sN%fYE=W{t&TFYl}Yh!32rs{?bU@=p}I_rAL>T8kap~Mxy!zlcAV7`LMSaB@1 zOCLz-N^M}SFg5d}@{2KKjs9Xvqq=6k`?b0_4^KlN% zv4j(3krb{QLBZ3Oa7Po5q$w0!*Ok_&J-k)qj`Cj3(T7_p&(NBLu18uapRViCR*gh! zB@tgu^i&-f(ED3}u`wb@2>TIeeiBb}vtB3@`@_oOk^(*B>|R^A^5Dw{!TmavAmt;P~b)l#47x%b41 zU6eaP$^ElKvAjPz^tt%_?*Fy>x4Zwkd-GZ5ntuv&tz*imi$NezWB41x#fpF-@Yn^s z3w&z&6B&Z@+*T1~w^|~rTHpKf%c(DPzbA?X36rds;Cs_!iQKx&5~}p4i1ux?1W$O*!88IRKX9(oczDPf1LDZhwR%yRtF zICMkQE){f7wFW~|!@YKPMYsEP$t5gAP1c zd61sKe}6K-HN zOQ!fN&CyyOoQlc`PHGd`sanZD*{n zkE)t>Lg>QL3n@#u!{kBzIXtLGc}K%9V07&2F?nlGo4gXj5`-ramLmuVKRay#|8&1Q z4St`odgx)ritTTIolptQIMsxyQaP|^92n{y>WSmz2LUIK{sI4|0nMj=CBN)Lzvty1 zV90xc$)95~$em8?Z~wx}y$JOPFChHnx4b;Dlb3B>C>*?3yj^j;J%iIQVthU6`Ptf0 zHUUyCWWw5^wlN+laF=y6YjB{dzXtON^P2iav-V)uCUjx{$hpbP^{Eck93 z7aHqT2;XN{it9FuYjS;zamNY9c{5_^yI3bKpO9LwSb!=7=7}xM3lYM`*_GEbs^VK% zr)qtGknZi`chOGWS6HC^tzlpTTkdnPHB#W={PHlN=$ybp5n5-2^zT?vBY?G|G`2=I zJ^>8f%{G>jlNdj&6T(Qv#$Y1mM}p#8_6N*^az4kGqv&M#nhE{*{r?)duZGvy;`UKK z!tv}lVXCq8BQ3Qxvn5OaF2~-4dzFnc>ctrO<4je|*KEg$;u^mHeLc{}v68gtA>h)$ zAHD&kQ(RJ_IYoYbAEPbA-*;oLqIQ`OZbyi%pG?J~Ck4hRJRK`pT&yDl@)vB$#^ZUb z0))yQVb@3%I1vJSy9U+)@oJOsO|mgg_;qZLjP+w$ z|MxQbdC2d651s?~UPUlLv4PMTA@TOyTxKH5r1FMBV#A75JQ;2=!&?y?Y8~2=>6z9d zU$x}RUlBzaYPKlSWz^Xk7=$>GJb73nMNE~R$LR+?YtYrnK_Z`x6gmZhFz^GiHOX(p zyVCbb&LsKs>;L%6Uv-H|$@*c#M@(QC=IgH+W&$GciDQ@w{0HNwG9iwDv^nX_DEP_! zE`*dhEW@X%kSmIRH|Hb2wp;Q0ZOm&M$baoW=f!C_CZ@F5#IPl}&or%KN>TnS6Z5qd z_XkWCW{yc$H`l}%9yKwODoo6rc_v=L z!$t5xyz!5Z`yHaKFT{Ne2Qf?*{08%=FLDrvpCHBATbV~LQCdOl&gL)=TXLD}QTPtt zIgv5`{#Is%^7|yD!H@9He54h`(%2yk(}VCX!t$HPg1(!>T`P)(D!d1pG0P19i^*O_UCq37^Zmq11oQ|?*CCFt~2&y*YbPc-&3rd zisXk4$nW)I=R+E<@AqHZ5pVa#t{sSXcw^W7i0}8(wL3Dy1!RbeT}*l-U_)HFz3+*H z4Jn7$-~BFbNm31QZO*`N;r~-y*c~bHL!0hrt`+C6#M8@oy5H~f`JgTE`Py)8^R)Tu zPPh5qK-h=pef`&W5P!#GI{l7MiTU2e^SjEGkW{Y7qrlO-B0uz-B0q9ja6ZxMz?=_E zk$-dH*{^~O_MZ6g2de|7$P>u%5KA0mXx|K4qH~57AI`Ai!@0pXt(k??7Yu2@Q%+@0&pRV_emQ3wq+Rg1*?W@{<+4f6c0(ihD z@6w)p!}kV$f5Z1nTz`pg_lE<&jHUS2Abm~j+E(wed>${a!3SWxvmU$Z@e?ZSVqs_z zu}en=Yhj5muc}0QzfVzV_tzyyJTv@4v2G{Xn0iv;(i<92;DfGPN6C^XQ!2?XP-V z?dAAl`De0mbDk{CYJ1sJ`uWSAvdd;M|4m5$VdgTeQ!So|*N;d^$(I2cJ&Z2`0dI z@)&e)Lt)QalM39+pRf-?CVw*_UH%<(zK;dqqnT`wxBZ=$eb6y{0KTjc=~%|{Htd_( zNc)eSNJE|ql=lV7t#9MyFqbZWhTmr3%q|Z3SrwjfUxYp4g%)0R;hS6Gr#T+?m#)FC zhC9mS=R+?jBhLy18TBO})xp5xkU!`|-1R8Kq5&?amzO_6o=5!f@4$C>#52ZfaCD!^-=!*3T5&L9l_Bfg3DrQ^2{?qhK0an~VCMtmE5S|f;)Kk3Mi&{z0= zj9+J(ZG<(3XkmvyM`-+&DwpV$#-cRKp{NJNd*O z2X9+}cXs^_dq3`<;F~h;&!TS25oYWI4}!M-8S#HdNWpXcUX+ROA2{DE1-`Qa@(az$ zJ}JNKoZJH4_yL>}WZf7{0B^ebETq;Z+a~8Z+i4aaqYK-as_LcKqYKd=(9b{p9iO=p z*ciw&Q4Kn&_TV%zH&aFW*{@)i*TSc(E@;`R@iAWs1%yz<@1GC&{0OZKP9vdnlNg*q z;tW_iV}5}v!!tzAw({akkrhh%&s!sZRr2GK3&C5$o69`$k!82H-Qm4spWbHad%Vf= zfu(PL(==QcG!^6eL=(@~1uT7=o9fTVc;15h3%GB^eI@R{YI^OA<-_q_oNv)L&+Tej zDHexW;U!V-$nx2m7Y0~ip=jH0@-6I-FWf)cE4;WcptUg%!Iu`^wdCoLW1+%fB}B1TfZD6CGrW?#=tul()YDpF!a=SZ~aoCWH^BL@WUI_?{U5YO$tZgLpK(GL31l}PUEo~ydtLWbl{vQ25^s9x` z?2zD*^3Tr48>#f`_<1TJ1^&q6Al=cK8L;E@EpSI`RYDS-y5Pvb^9uMVVC-&61#S(e zY5;H7_xO#}(a;sqc^e71K5ro1Hi>ORyGZx2-$Ba{H)kdDn>S zZB%Ye%-8iru`_50w_dEg$O?u~tmGjmd1v!@=?!>iTMIMy)n9ORZu`vLZ#zz!x6Kw^ z3ja%6I`BK>%_g|hfE;<}tpCPYcsN7Kne21z7nF9B4z>hyasY*)uy2-NTS=iFx?|EHNENL;1 zXr^iz%EdfZWO}0Y)c=^nm(o2^^q=fbgIyWx{)1LKE8P#vI!f$JSgQB=J5z;}9Lx5a zKvItGakZfHIM2X~4*s|7JX4Qys-t}^%4O=g_Dfsq* zXZ3fU|0_T3o7=&Gc9wj{PdnACA`P+~xZChTU=s+do|cv5@%Q}zHg)nLe$HMIPVgAQ zZD)SGy?p!Zvp@WRYD2mX>XWsl1{nza7NW^Oj8^&Kv+yzMEw^HpI&_}pA)TU$uw34< zSw1aXmN&nE>!O{eo<#>bk&ng~H1`Mtsta45b1?t@^y*0;Phrn}a;|%$=~riaRf6eM z_n$$>YC3~|D*o3C?Lqkamq#5^czU>>j@2`Y=YP}11mWcQ&59p3k3C@axpywao=iP_ zfT=2Nt=bZ;%@RzJ-A$@zM%zpgsi`I~Jg2gmaLz-_EzL=2tG*4g@%g5fWKY?7=rGVX zt%2eqPf@~HV}z;YgqWYe^!>3hnV+l76XndrBoD0tR|{F(#z<257omsq>%!$>e_w)? zF^-ub^?UCUo{VJQWX0Dv3Qs@!${4FvIgxS94D3914Jf`6`hBcTc&7*b)r%0<$J}zm z`Z3mPi8MAX6jj-tBY$LgS(k6s^+**(N3x2p5#%4K86takR`mn);IrJhur8Nn>hF2t#jN{fIUP_X{o zV_(?@v@ZsnMMrCu@RmskgAr)He1ZE3gb+eZmmr|WRnSZfSNtnUCt+&=1y}Tlb%AU% z<`6Uq&~OD_JJTJhcMs1S)COcqP}t?f8C%_vjqdKqE;nO*09d6|w5mBE>?9kdK1gR< zj+vo{cV$XkqoR0i(0EZ@Xx>ph;^$q)e6h#OAR8xnh>e-?&wa6Jlww*t~={LKz{ZB~^Y-wVnwMSi{7RcZ2--cvlrGdXl^QE;p&&f?`&ACZ;{i*zd!9y*ZGj=U&L8_X2lO z@AgNYqVuMlQ*22^$v@a|` zuJ(x@%4_PAsT4c;IZW^gofB|I=SVAjvJ~rIalXz`9$X+k-A+BVqa_RTD1M6V7)2Ll zf-cH*Q|fRfbtFC5CeBMzo3oQ#}NJ!!heO%@Ld&h_e8+3JQ*? z3ZP$t2&WO^XN3`M)TJ}~MqqA?2aj6lfLySHm-7(s1@Ar{m=KZ+Xl=yTM0^fq@3HJy zB;I3IXsDgWx*}x48YshVKQQBykB-y(Xv~Hoh&baQ}W>ZlM1V`u#=NkUmaER+EoMD9-wt^eO7m*f9$bh=nPd_ zC$wH@t^h73F3k}n_s$znS;8XsH_q1J z=-h?w*5HU-JFY`>t8vZD-R(9l7$mUHz3m<-Hhk?seBc~o;609Ny0k|**aXyB*(V~EwIjr0x3kNgJY1 z*9eNW*dg_F^i&I@?RkN;+Wf*nwl(6fVOy9pA^B)>qkcVGO21bK3&b_k8|?SRp>ulxBYwCj-(d)*ZF>G7eosjDIT1DYg_}yw~=H1;0skm&h||jfhij`|E(O zgMP60xArg*vSZGf@Cr_&FhBNSb8=%tvwr#O336e1$ZUUH@j|Bjt)cgb<6Xv+ zkHq=c52$eRFYLjyL1Ba3;~D|G7iwbd{oRm`o|kNijmcSCMSE)k(9??!IAB+O@_>YE z^??C|5Y3Y~MiI2z@pDONH$_;bMod+)`FZReb0+9C_m~%mrpOq#DMA$oQ6ET z6Fn2ouw_Df3=fe0n6)Qt8?YNv8MICmn*+-DpTsdgdDr)!FGxC}@d$)tz7_Xx;h1rz zEsb4taa~|=+3kUJFZrpnPD5|i7eeIKZG@1(*%a7Sgh=)KCgUY|ahZ&(GuPmB7o3%C zj3Ff>8HvsTzJ+uTao&o2|2lgI!*_P5XIqJ`hCKaVv5>a!L8}Fxjl>%#;d~CJZ=>4; zevdPkxPYDYYxqU|9;PLJeAz|VlmxR7akyk?9)!qjKUpHnC*JH4MBgP^LOhY)`@1F< z9A}F8ft~Ud?34kOS;iUJaw}sTU88sE?PT9r{0&)&$is);i|-rdp6%{zG3v1T&bd2- z?X9k&aQKg5eqxjRjQjomr^Jb_))(A3%@`|XH@rk}!YCl>;YF?Ey z8uTm@S!ppD=Z|5kx+ANB+tq->TM4Thc3-Tp$Imemc4P-*%)MfR&U>Q^e4xu@6p%lG zR-W;eyVkTo0)Ib|PX+oZ3S1^iwzF9VyXF1Z?gm{2cDG~Dbxi_KNc$VDk;8Z${H-P7e6hI<}=o2ue&gH>zCc1|BxTN{y^^_f#b$Qcj(`gvF;VoNT=ZD3_EFT z2pyTTHBcEiZ;Q?<&0iswowaWI(U)gK zDxqC`Ma)?Da^b&RsK1cCUjDPWVLDP7yXDVgHkj&1gBwh*>;g|5jj~W3d=sU0{Z-}Q zg&9W%9R^a{E`e%vSSfd$2z$dFszV?r8Y*%sUsF2$hNx7|@QO*85fwNo=mZeFxwvRzC>sPgdv= z(J}0>;m&|M2mbT7%B?Y472i9kO-$8zuQfQ{qdBT}$cp@12Sl?_z#YxT`9jdu!e5#@ zY6g8>?q)$lf#hGD+dGk`D^so1pojSP#b+v&--nywGu;E9>HaxC*gF>%aDx~0xrt6} zC@oZFY1XNDuA!ueRxMML1>LKePU2O(bWhkG{1&!08dWnVFqX#t3$~){rdey-;@tN|6*8U8+7jFLKfQ4iTntB zaZ%IMbBhWpyR*8Z;1AScwUF3Ye>ROT?`{gFApWy3o#?}d)nNnlbI}KuUo-@lp2J8s zjytRVLLEr7F_V%#BPOZvAJPmYtfT`#6WUG2RGl?6fR+RQkM<{_A87nc#)iZMX)sPG z7TPn=uK7UXGe*|PR1L+x7J|nC@8N+<6Y>YD}~9w9-rX4j67rqRxMbg}vYA@a6MXRiXrZ+tFzB^POgHCben6(VK+34Dxq z(#CivKb>Yk{1ewj-{l&Jiz)M)jQ3`et&(`Dy^s}5#z=!+R8RDStkjbTSHH0KlRSbSUob%!wKOXtR|^5bX%3V=^#@hGVki_4 z!=c?%t(Pp!n?nx=)pOX86j3 zGhl-lWnUd^g%qA-BQ*Z+-6X%c+IjHeY!0+z&}H4NAPiG-6#n%S3 zouY-%;4goea4Lbtz7;2Wnj*sfZ1X5jwl}xUvMJXm!Dso~VYqh}bZunalLF&_#>n#e zn?^Z0gDRXBpN;2i<#%Tw1qekP(|r#EB-vqTGa1Kd&r_!vqvIZ&wt3Uvx>*Jpjhh(L zWsq%@Ol~pL+h1|NPUZ`Qe@FN|!p{+683+?fHV!;rB1|Be@b(+v2v&8PL+4Rt=8_?cNDaS5 z?{|htOCjq&5>2%hfxRrfX)WTUU1vXR>I~hUXNsKKX2Bd&XBV2ZPvr|AHgVV|4~1|V zcJVL|d)c~)_Rd;s+nH@!O~%8CQpg01X{_9p;zz)OQ`wr6rdqC1vw??(e@bg;mff!P~(;K%HWHU3~pyL&IQ+g!a=nTZ7xS-G|+=HDnE` zN=VYw1I4Tw%a&SuCPQlzb(Z9Fvswd*XIcZ(gZLW-0tYE65AwciTbe!LSZhGrmDE5; z-?FP3XmQe(Bpyvxc0pZNa$^)4`lMr1`Sy^oEnOf@!AQKBhP@#{Ii08MY6{-rm070k z%Hrvl()_{nSEx2|=6Z4P7nZ;vE#a1}+cV%vWQxSNrc^Wgg>A=u_Ik`m*|=-cw2xWX zL&-;QiE59S)G#o6IPAa5Sc5JTJyG^v+P}kE;8M;{Vwc2txc{%x!2=b{pLn0ffsu73PQ zk#a?`W2#|;&BOUy&NGV&l01vgkZkH|fi&=b|9pacsi`Dc(pnOeFPm|`P+SLB?3wPC z!OP|;K5UD`bn|`iGnL^Nsa~cL?g2d_Er2QK4i8%`pC-?hO33N(+b~|fEBSajc81G$ zC3O)+t_u`TN?vD}q^{}gY3Mos`ns=%75;qR@f%bX^KYp*gjeN=UX8J2L zm+y*|l%&K{CAK=B*WuSm=0toW`M6U0i4ne$@93-KEuqkecfui@2ED|3>6@wHP>(48 zd(!&kbwfPd3GH!Bmt`Aaw`aoR@9n-}HJsFZC3T7JaE!yVY*R_<>eT_pc<>&}`}#(v zV~#kWO~V;MpfNho9>Tg34Z`0H1a82>&|Hkm!Y}Q4+5583ve6lM*=so!`#V}xLufjc z`j6;ZC@v6}ABeSV_|dK6{7$mrT)xXJw&NE|#D74iJP$iTE4sAv8M2Kn8Qz#z^%{1H zys8oFhOM8T{S;CY^0r8yBhQ*Yas|p)_|C~uDdA}M6>wg? zI2-JUPSJG#A(B~B0Y5RKHf)5YGJ}@ucsuCtL#aVMY$Hm^u#Z41eU*j8Va17q??IQl z_E26R0obs$+%PBQz(ge^XDph+-cRWGS!S_anLXVlM z(4~9C&qW_urmFQ}#`t%P&bx2Z`277YefW28)7VhV5^=pvV-t(-c$>zB;sVmuH`4dK zt+^3@_ib%|d_c-(s%U?UK}{GAC!Q(uhl75S=1pub`+YP{GZ+WFTicltzZsn^E)<7* z=51oChx4ConFG8-^DfgB{WFQSOknV8#z3oze)-`iTw@ylJDdy6mOc>P3GAT%`iq5i zIB~nKC)xMj7I)7VwnWc@O%L>_$LqkW|L_xL#Jm7(i(i9T8it zQIHTW9{JBO34$RAodmU~wH*^^6|lt+)N1`tD4@w?5+;C`Q)+YGZ(ouzVlV$W&pCOX zotfEt?X}ll>s#OY)^~gJ<`ux!;GfV9AD?dI8tT>{j&XQ}q&}wi(P7PtuF=}ybLAxO z#S}TaHC=B_k?cbvwj!+|H_R`6eMElg>))GSnyyIsrLPa=m%iSq`ko?lRc<@`u zD9YYqJUkf|L662c7q!C+)kvk^5{~XiJg#4NZd&#OIJXnEzAerrSEZN(w(0@Vum5_d z1G!r*l{26zr_8AiXviSfEj0@|YdrEqm>Q<$Pw?Yc9c2s*H%EKJ|I+0#I4B3%0YoK) z!Ja;*>Or}#+bW)@s0|!4YwvK+&x3wQWE`F1qG1F

53#%qT3zA_>O_3S+29ruzT#h< z(C0Y1zvQYazD$s17|AYwr`L86&sgJb(xV4+`}Ah;9_&L09UkG)(%e2Rw2@z-4UfV% zLe%}1+YVC1xjNf7z}D#aTf8PwcQh5bGmtys&_rb6V~$y3rq{I}>d%62itmHcmAQWD zeU$45I!Z6=>rAI?2i2%CBl{-ouC$q!_R%ef?U-!&1X%(+#*EaXaPNe!!(}YHnX>iO zQSKuIA zNriT4AF2_|!aT@x_ja~9Pj^@ zuzNpc7tr1n2fvwGH{>S!#z2n9yG&PBH*o8wTQ|S-3s4g2)F}7CeC%7ShipZ889NSg z_RWRc3(ErVoPmTJn`sI*Qw@&YeJSu>d+`!{I^e02Osg@nxI`^8+PG^}G7cq`XYt~* zy5Os&$${@eg9_GyaQH>4W$Ar*E|Jd($y+y}f64AnaxCd#mO!6GzEs4w2t#k2brgE^ zbx#H`^dJTH#t&iW%>#y>F}srdfO=y@9SSl{$as2@*_3y}uuN|=;8UAzIA(aA8Bb1D zIl#F^-x7L0J&$}$jCh_F2gN{}w5#tS{Zh0T8-8*!tBM-RI8p_R1!8bS)PXR>BaziW zD`p(ArSF7oinLRNH$c9|8~z4dUD-Y`2x%?6qZuuU?Kp)0M)5zbGD#h;wpa&hp&`@e z9)zB7BlbMCy^Y6!k+^q%Yjc1(BhDeaVpYTktA+pGy5(h7ZTL{NUf-#;{RhT@5IPO# z_O`y>98(pu0*Ihh&Hb$UrPi+FyN_-b($3OamHGh?7~P;r9LL<5LQKbkp6zJE;hyNu z1wHU@_e7n;tgar_@pF9t*)hK3d3+{z)PhR6xj(zy6kOD3D1Szn zi#!#F#jFlnj#*A@LH;xNG`Z92;?Hfy_sGuFopI+9GgF`=jmk;>@bP2GyEupYa9{`{ zG<{Z}Pt0uQOWm1Pm$Kb~`s*9BGMV#fq5O?~pWjmM8o1&fd?dl@9x%A|&=F`WjF-;@ z^|Lg2J;LbEyN<+l|D{`1%~`qXzJPi?xY&Zh>Oh}vMVC#Lx$2nf#47YpWI6rMEnkWM z&E*f^e{H!H|26lkZ5Bi)X!+g9jwWS853e7!i+#x|4tED{)z|;9T)*p3-`xd$eLkS> z9GvVI4quL{Z=HPj@(;^nb~OoK-`dv~y$kYn--2?#kc;yX_0FCNmm4QJFAv%smy_zd z^7&od3RAwJenR)P{I7-Jt$jVeo_x6Hy`Gt``(B~A+X>xItU29tCw|55imdgs=eGKcqV#_t9Fj{aAL zZo!8d4i;RTa#(1-^*#S-;mqVdj1jGZ79b5tHf`-!iPag18u+X8r&qA%A$GO-VI}Jt z&5mKIjr_mJAM7I>G*4-MQvS73_)T*s37&TkxF6V1G0qYUg{ob&<9WO{$!Go3v&Z#a^^M?tSM^}c(y(#>}K7BLiD{ldj|cNM{z26pQB*{JgEuS^)~poS%P-Yc>L0|RRz?!=>0Y| z&&|i#wgUKBflt}Fd7$Sj#$}dwrr0KWW9%9Sv?^yOw3LXxvO0JiA@4>Ld~gP0kze3u zJndQNV)Py3aCTWiIOXPOq6{5YPsCZ9C-Uq{Pt@5}p6Ih>o|v=c9{%iVPwZL26L+@4 z6MuHDhvr8DJa;Vb3`caca)thBF3=i6G)QqEM1v&D6P**i6Ft#vcuu`EBSyzlab*92E}Gj$nZQMnx#4w zeMLnhq#kIIv}R_Uu0k&Epgy}o%# zMAH43ZL8f+z~kECpA8E{dQGcy($F=Hjjqv^T&(U7hzQqVsGrWIi~HHxzOlISpvQt4 zjGQ{|bn(fk2{brUET3u~1COzru(qm@e|C<$v^Oq;uxB}Bc3thZ4z-jyblI>aX4C%G zD(YqbY}sPbLN1IYxo|gWhIJjqyT@M%Lq4sP>adQY-TIE1yTdz5cGLJ9IwTzk`5=U^ zqCEhOE9qP*o`uFyk*Sdn3K{GwkdJ9i<`InAddM_fE-e}~~OGPfdWaQF|vvmcF5K(VL8>&4KaxT3v zV2YAFsx~K~XSB%F_Y1*fd?jZ%quzTqW=AHkHYu;3bt2`}i~3exy*;*2shHlKXq@7r zi1ukNu$OsPEofKS!((Rw*+z3NrPVB8pHa`v8*3iK9uE3USjcwQY!hyRUkpi8gdK11 zwIbRBk=QRa`{S~C(bJ!AeRz@u7-%s=zW&gw{~3~)h|5lL&5I#Bc-n`j;aFsq{M;p- z!r)~K<^;k5n4%-5-HT>DkIby`$fW$R&9Yw&DvbdeMA2c=Qij=z_G8Wf6`SN1Yn#Qb ztyyT>;zmX~t*ekMjSB+fvR4ReCC=G9Nt8O_(c&5QY`#VIY{s)Hk035y@$_``!NacU zX4uS101xkQPRWw6pM~*}nK){0;`xF)71p_*leq3|S+{ua(AYmMu18Sg8|zZklAr8W|u zrS_5TB(!a&tNNOSUabvw0{i1_mY4pPU2@QLH5@skU2dhlaEwOZC@n1+npbhyrI6lc zJ7k1)R=O_=c`~fD`@!Dg_8XRaP%LMtS!A>9PI8oaa+>ygR!^c;>lS2q@^t%HUh0ix zu}{BEXG!FR?{po~*vtIQf#-XN=?vMZftp;>^E`SP-o(&A%YGfv{(u1KRN~ zt!I-$`_+VaM(W$o(WkVID0HCgUnmc^3wgLT$ntIRKl$?1IO`R@CI^&2c5-9DdJX8w z@UUtiPrJS`S=Qh|_|i4|T>~r|UUcpU@c!0;6s-CS5L-(Ab;Revqv2sk+8A~v#w=kr z%=Q`LT-R6)aDi=X54~ZT`?-U&+^Z)UJD(~3rnEVrx6?q>D1 z=nYyMG{M-L#@e)eByy0`uZY|)kDb`hRi7*j1ipB~^?S-Pbvp3$iKKN&HmR25?%jO> zu^wM=dt*Gjj|12t%*!?IK)xDhX+ONODl@D9${W{>w|$0P%Ff2jOydqb-}z?XKU?Ga z>M!BG{c-D)!GB-e&#j+ea|h=fb}qZaX529vUQnM;NIN&WF0FoYHpXv1_{4r@+;V`cX9*G5&V`EoahPu{u3tvPoTyk=Cr{_O9Au~oWr$@O99e(Y`(D4Kyr zHR9Z%gOTSB9-Diq#1joWmjjuxX1O(vn2yOt*gpT>{(W1R9 zvBS81blqUhGU9J*ruw&g<9f3G(iL2U+_8&nc*}he;9qs(9{RcTqk`#*W*=9%u$v9& z#y__QzJuw^iF0oc@CpHbtW1Mf#AB~=^YQ=PN1#DU+a3-1Dx5dgn~aal z-X_#QD%2tmrnT)MQB&+3YS(WuSEFpRkb~Y}GuGisolteKzZ!ryEKdQakO3W)~#Yq?|?koMREmy}Y{SPFrey{03K0 zWlNzaRHStnduNODik`Af0D6c!ZTmXNe|sh)Z}#>oUMvR=HT?$sVP=cQvBmE`v{jDv z8|DuwJEnbS6*BPC!F#8OG6Liz=+0>WQSvI~$&Wy*!zv$!MSl$DDp!MC`Dv$$3DxDw zYUE|bJ+Wr#{nS>Py9S$OkFnJ*uLs2I?*p$--X3L^dTy_Hu7TfK*@?;yW z0a50NmZuvumCyTUwG-z1prdDgZLey%*ZN%2@V=CMQixYkOok2oig*^uAS8#8T+%sX zIIctCW3)dcxjF*bPE^1_Svje+H{5H;uzC#3HQ@Yx$V8&SKEv9^@d{!c@j=oHDQgUa z7yhF5#qCSl?`prhomEb6S#ZJHFz6_QumA19uCO*3G8RtKXu}*EF2Uc^UKViee;!$N zr6}I4WuMy$;Nfxf6_@AzS4IoXfqkAU?s)gF)0Mmbkz}7Y&#j2OG(5rOh!Je=?ezgS=8aowL{vlLz*3 z=)Ua^pkaI(;!_@kJrr0DVoW^kXJ{OhzAg77CVf&Mq)z787UwVhPxT9;LY$fhh$QR-CYl13xPJ^RlYa#!y25JXM zU$@&H@MgFN;h|Q7WSh;smV#O5NvDjJ!O@J!n0WJj$9#ut5fu*0YQemMiHPJJbB)b= z&tL1eyr;pgc3wn54RK4BIdXUj>)yi zy$0OhUJ~)4<)Z}b)s}h;^%1+s)5B$4dE3*15x)HSCpQTy?9gYmo37GM{bKu~Q@V2o z?`9dbOL{)m7USY0?+e4vrM=l&JX;!z1V}3zkzcziue2M8e^=ce)rJV0>uM43sg0mb ztvOlTBb$OtkDH9g^~@25z1QvrIvbf+>yLt0)Y73$z%=JO=Y_;vRL~x;wp+E4+ z6l3Mq-efZweR^cif_G`tZ7K)t<#r=N;(31zd_L)l$+*=(x`M3+&JiwNrQDyj;*+FZ z-Ef45cS}c5>UB*vwA2S|JrS|$| z_wwy@#g^qm)@g zv?|f&DCjg)cnb~QLbo2VB;s2z`;g^W)>qPaDDm6$E+Q{JLugH^wYYmN?p_;hW0hv; zj{fS*x|&+$x`JGNV)n4+hjkqVJhCx(Mj^kp;(x?vbGTEDJGE=oHp%`;PX~Qtmu_uK z<|Vs$4A4tekRcHjV%4oP*oN=Y;;yh3)(&mu3CT_lo+9V!qxG5EN$pnVZw9ctHG=9# zhK>bR)w20k!wz`R*kNe^;?nv;(gR7}j~m+xTS32#stwqEUftXnpBa&Egyo6PGzIr~ zTqs9Al0SwHgML2&3mE-U^D5-T=6EeMq~mT!wrE7R?(z8GZAFo-zTi*refhVLxLlwm zM7fz$Fb2$c+SGtI=lD1~jDGAWX8FTkQp_BpW&{)Tm6Sp9c!j3Qu!DTS!aAe96#IAL zY8bq~Mpx@(-FifwG(RbJM2ydr=Mm|V7!K+e#ZTSZOc|dug(|}SUCFt^$PYQ}g;pGMy%!0jxhQzM1p=DPdx31jE%cq(;tcd{ z!H#O-F|NvYV&O5%d#cPut@puGClF9&E@)kPS}n%qJ+)6=xik>xFX}yR<6wDr1Yq@S zGZf4^2EBXm-V@Q-`K1&(0;b^ICrWT-)D&I8dsu0o$JKjI+ztvbZC;H@Z7=`0 z>|+(L{aEwyWKnB%TkGww-+nC0Y;EQ%!9%N^{(zr6Zjh-HD1p|3aNY{P^%(fA^Fe+d z_L!&1((#@jJ0n<5#oh0xWahsH9-`Pb z$Tp(KK{gb!dC*!(_6pKpkj;ebBV-#1&G|s<=tnq+CKTB!ANb_3QHdz7nvPq5%o~+G z@jEEc>9am|WFyXb+;>o*Bf$eQp%Gw+0)L@uDYjfhk4FmiLamynzFB62ge1=&$f4$Bh`ywd{YHd=&Z zA&yXd>8u-KA+xXk-(w-CPE)XuslCMGGe80AZ2E67n_DuVeS}o`iCKKhZ5`>3RPj3f zH)W@^jFz>NDc*gs^V4-MHI`T^=$@u5w6O$<8pVN1X>~F%V3@zc{I)-DG|3-0s z>jB&gZo;Mgn%oqjZ`1%Np zV=6%y$Au#>j^#TmhVyl}icj*dYuG5vSuNYbe^p}&$8OU!q6YpJlGW2fZd6apS&e8qv3y~t`^7T%7 zmP^K54nrQkVd;TK|2%{KqOpv`_o4m~v6o%&h%*Z=_?Zy)@*Ad5?Bzj+e!C04es;>T z&^7~Qq*`nJWZx&cu;RV9p$59MOl*M$7Red3dO$*u<5Ljx$}0XjCh;4le;1SZdgqNW ziHH19uuo+bi`w&GA+o{$+-1BxO+tr$BqQrD;(YFr)^_#Mew(@?rH31Tse5XxYrx(} zcs8zqxsCII8*LHsxn-nr?6=aE#38$jh9bJYG>O-=z!%r7$p#l7tF?#~-W!`S4tzB_ z2OMXh0z2XtMbyl)n|0u!K(3j{~qoGWYb= z_Eul&x_Z+(wUu2{%}>hFU|q_@x|G?Hbu_|NKhLVhUBn$YXV*Xp zu4>&sBHo&}pqqG2Za4OWc2yzfG`LjUlrVcE_=%%$d*Pdt9f8yEws3U23bzzS^*`UA z+b`aUx)$^g^XENBAq!RlCEbS@$N{_0H82Oq13s7W3@|5|@n&QVMxuI*yV`L#sAVni z>bYua;eyM#m!)&$XQ+1ED_=#6su$o&?qxbd*O27`EysSqK^l=DCqAm$S;9cJ5WI@5X%9%Q|;IQETC0i#Z@&Agd<*-?K%z4R*xn_bU z2znsD+JD8SABaF3w{?I6ueqH!p{I#|=iPcn=6rlTvIbrQce~TTVO(++ zYVu6nhVRm<(RG#DQQEuEJqG@kW1O{=ySkUMR&VP-{wF>|uGLUw#w?459|_i*YphCI zh3Gpce~&wA#n}D5W)w2_+>e&g=>IRVZaP0mwO5zI=YByiU8lPa0RO>dJTQ%wC+!;b zVj^})k)mxm7yh_3?>dpYryJj&!O@Jl=f{t{1)Z~{k|KR7k9V1jE3o~;x6eE zTvPH=g=ebx?jtcT=$+-&cE~@K1C1LpLi|XdnDfx`23b5wdJ# z$8GY{B)kin@eO6!Q3Jek8T^y3}E)Gfje0U#m5Proj9Gy6>VeE+p6#E zaq-$6MqpgTYnd_Y{Y2ef!4h=Hc{E|qmhxx@OHaRr^Xm^|Cr~N+hREmd2AakF6bm3@ zVm$r_1!JP*4=y9s3_J|2B{)h)wMT2dK`m8BM%J?MkE3z^;e#X3-}}xc;eHWuBV0z@ zctS?pumop|Eh;-~3F;32$Ke@=lYph+77-}k?8~{R$RKfjgr#xMC6NyLVpk+sZC#s$ zr_TfN;Sk>Q(761tJm*CLSRR((m(8U;rQM~ymf((NBykm6KS~#^p_V6TKShbPuZ?Ws zqCe0ZZT!v~EyWw%Pd-OAQp+tt>pM!%%z0-oVpSe!LWD%KCHPFUp?s4tSb0Jy?MF76 zL$$!)2!}`B!tzs}r-tBzC~ss(=^1Fd?og%h1Q0s9Ze?Fy5Mv_;A$fI)sDYsv92U{{eC&gIApQ*6 zlg|VNZhmY9zsAVJM<4fY!#h+R%DOZzUqUze8hx>|nVu-!zZWIB$mM++~%lUA3yOV_Cu!erSdc?U8? zY)2%{n%wR{&*|>dJ%qmzeiqo+9Z_NyM4FKot|r2FU5ayw?08Ff`LJ=C{I-CCM&513egu_JSbl=m51L8;#-Kblg~_qU!wifv$+aE-KRwFw00mQ-*zSs-BwY~Sl)_Q+yOXK3K?TtUo5>{s~2d&XwZ zX_?>3p%&=rKPhR^HOy+r6z^XwSn`V-P=}+od)E1)23tdIkELMEUuykrh+_YRIHo}7 zYT-^zZ!w+HY@dc5AhS<{R23?`2pn!AJ90f+`*fG$C-`XBst5XtT)wcvW`La-BhzRc1(>csJ5E$Kg#-} z*oifX)?1cotvTRz6Kb-pi(>O?eqb%Y)iCS4SXE`#S20yv`2)~gs4Ji2iyKuy^wiWq z=U<~n>@2H#lHce3Nz~Z!J&t1^3sm$X`8Y8kdc~^RdOIbZsqCcs` z9g+R8ceUrl(EVkeAK=P)TnWow>wVWV$K#u_pkDk&*17+0l zggSGt*Wq^sBh2>zcjlfD+!^8l#5Is#Si+ovG>JHc@{N3K%_?YN=c5MK?tQx;#-+R$}?n^)c2*Sr3AgXm|&vLLKBMY!JrZwCnlm%J_rEB3aQ z#TOS`a5t1Sa`T#d%f#J)VcAubH%!)Q()oPUncun?wr_W1cuh6p6T!oK;iYYR!s+O9 zAD3+3hGo6B@vU?ZE6-{j1n23T7GCv)-Rxb1-TEfTs_~#1hX+*AJ1T?nNhR>9;7ThA zT>-wXrvu|KMO?+2_}>8U1RY+@(uiB z^nyTyd5eeg*M#NxfomCI7 zNY|^_t5%)jEw8Gs=|L;ZSo^?>LR|KieZ~8ReGl0{94O!Q>X{~LA+-+ntys&eXsc*H z{ITUl;qSaAm|$Pno0QWq6S3>qQLmmB0geBrso@N|YS=K23K4aCMH_~2Tm#xUUJ>oM z0E|8@A_O`62CPWr`-rmFwChPbkqlp(hhXa(L_4LtW~ccok(PZygBdeHl&&3qJ7)4u z3gBOf8BFmYh;$>9YzR54*y%YtKXXisYWoW(YfnOJf;{B#{(yhA+L1~TZ=$U<9DQ5sx3o)bBPzHg#MZBdZ9>h* z*5R{Vwg|&gs9!}G2ISvKK9e*DDAtPRh6$glNXh4%<^jzal8G`=ZV~)wL|Q-d3^Z5I zv^?|1v#*!-K6~uh*2E05pFGo|{g8B2me&Xct?g=f6|_}{|LTN(s*!U@KGUOlD*42S zlF=b0RdPvYv}9@=8(^n=E+9z~>kv!vDe@iGKt>|(;D@|5z!IwgmRJq2#A<*gRs$Td z8sLf5080#|;5!`I@ertG`zxzp9iH!h98s}Ozq6%l;HieLfwl%$;d=qZ?N>GTp6Xva z=`^kp#VlzzAwt8^mz9N4T%Tkm&k~L7iI^zTmQ)J*Yw&{G5U(M916Ynz&r38()b}aX z^}9vh$U5uCi(8f;;&+Moe*r9x|L6I1r+ZBUR;+F_MS8mfG7d5h06k5e4gDMBy=lkB zc&D|%=H;MhAIm4Is;OSz$*ErHS1zdaryd`6km1=gz?-ZR&4Tmiqb8c`to#<5brtMN z3bI>sm66DTO*1I6k2s*D!B;_lk6+;3WIq6XL0Z+Ik?s} z{kp~0YF-sotAahnSbIYzYiqz~T>_`dG_sW}&d9(CRMRsHi!#&smDsVg9YL8o z^gWAXmIV65xvli6VMVp{>0-!gAz!1ql-(fsEeuUm37wyOQtu=#8 zydS^Cwx;3y`67*;?!|ZUoQqd6mr=zsjCfDHqds4HMZE=GB9+(|)L+W`Yq;WVT288uAsI8U?SZmUoHtxg$%uM3Gp+o5 zs*}o6U4yJFPs7a;+r`-ayev~A({LqjRf-yAR^@5A68YMeye#8WOv@F!|5+Q9>nc{V zO)WoDYGVoNEXvEl^TXsmp#FtR$JR&XK0YD$2lbQE4;(AX#P@~-jKA`J=u5FrRCxC% zKm$Yv*{JvMphQPXxd{3BiMU@GE24{aOri;#9~#p%)DJ|p%%2ag6lsy@1#|&g`OVhx zA@p(v^pXpD8L!Yh?_znVpJ%=!dH;ak(WWEF{vgsQ`e=wQm^_a3j?`|00gvU1n|buj z>vDPO3$$;XLhBC}NwluapKxa3sn5`kZp$AGIgBvzDmDD%Fon=+(-9|eWMwk zFL+P9`){`9{R{6;&sOT#BG1KV<#7(ZMspImI>b3e{YCS|XH>H}Go(4A&?)stBId~6 zVrj13s4Tm|e4)O@q3{urewFv+m^w3&6^niKtX!{BR+(osP9x8Oc8&lEFcZ9m#t7qJ zVF^a5pT4gigG_tG2S?VYT+6~Ws&_0t^U!~pA!DqJU7k#T%aPwBbj`>qmgbgH{_k?XM$2WD^M7N-L=Sb!oE$k`RF38{%3&@`^r#v! z??Rue^hM~ot#MLcM3hK#K$=G&k}Z-S_bK+_xEP+!$OZ{*Cwk zhhs={aAe(Wu~;LG7OX3(Od8KYR-A`&V!LO`@1243n6t$HYz0<0O=>?T^oGlyv7kpyWRmHYoSI{0=SL|=3FNqkeO zhvWqflV~|t?*HLyCAg-ZPU|+xHLq2v0NK)ZK%pIEGIw<+%{%6^z5A=lhg z4_#OIm_n;cpM2lAD0PgaWrZF>`MdJ`*pRk|J~KU!F@?5EXASeZ@B99Jvf0SB!30?z z^e*;;LJurW#nfqPQBMC-Bk?bmfO9y;fgdT~iJvIn(bfYv#PK11Ms$vS3079d;NQKT zK4VLybpzhr;%}a{@A|vUm*{?K2c4s`kXstlargJ_NxlXz*M!KIdeE#M<3wW;Dl5@? zO|_v-xl|YK*{c5sbL3yy+w{u)4|=@e8u5?zHds#+s6Di|IV;zLc_;S&Kik`YZidRC zzr^ohY^B)8Blih^451Owq1aC1KltA8uj~^({=cwKc;nyQC&+ta$XyMEVmp2Ro6-I*bl=flN9E$#N^x9i zzZAL;*(uBUSVP4z_`ZDz&F}Q7j4AsNl0DG}Lp&!>-k%T+-)PSf15H3QGc`_P^Xl{2 zb3eI*JG@YgWek_ZQ9>>_!@$BMMl+BDGLX3zI_vw?F{5hG4zo$+` zWAG;u*Z*If@6$_6EaBdN1Lyn3Sl$z5EboU#V0jl>M`C#wX1vP^GA4wt&S+9qWF$sa zX3R}=WLQS0m|CPRv2u|A!WgrD8|Rzwz|&wLqEGs}ld(C3y?qBWaChRE!G85C6T9%M zbT;*cu`DfZ9DC=X@i-Next - -Every List has an additional header, and list tail will be list header's previous node. -You can use list to form a queue or a stack data structure -queue: - ListAddToTail----->LIST_FOR_EACH iterate--->manipulate on the list entry -Stack: - ListAddToHead--- >LIST_FOR_EACH iterate--->manipulate on the list entry -*/ - -/// RT list structure definition -typedef struct _RT_LIST_ENTRY -{ - struct _RT_LIST_ENTRY *Next; ///< Entry's next element - struct _RT_LIST_ENTRY *Prev; ///< Entry's previous element -} RT_LIST_ENTRY, *PRT_LIST_ENTRY; - -/// List head would be another name of list entry, and it points to the list header -typedef RT_LIST_ENTRY RT_LIST_HEAD, *PRT_LIST_HEAD; - -/*---------------------------------------------------------------------------------- - EXTERNAL FUNCTION -----------------------------------------------------------------------------------*/ - -/// Initialize a list with its header -void ListInitializeHeader(PRT_LIST_HEAD ListHead); - -/** - Add a new entry to the list. - Insert a new entry after the specified head. This is good for implementing stacks. - \param [IN] ListNew : new entry to be added - \param [IN OUT] ListHead : List header after which to add new entry -*/ -void ListAddToHead(PRT_LIST_ENTRY ListNew, PRT_LIST_HEAD ListHead); - -/** - Add a new entry to the list. - Insert a new entry before the specified head. This is good for implementing queues. - \param [IN] ListNew : new entry to be added - \param [IN OUT] ListHead : List header before which to add new entry -*/ -void ListAddToTail(PRT_LIST_ENTRY ListNew, PRT_LIST_HEAD ListHead); - -/** - Get entry in the head of the list - \param [IN ] ListHead : List header - \return entry in the head , otherwise NULL -*/ -RT_LIST_ENTRY *ListGetTop(PRT_LIST_HEAD ListHead); - -/** - Get entry in the tail of the list - \param [IN ] ListHead : List header - \return entry in the tail , otherwise NULL -*/ -RT_LIST_ENTRY * -ListGetTail( - PRT_LIST_HEAD ListHead); - -/** - Delete entry from the list - Note: ListIsEmpty() on this list entry would not return true, since its state is undefined - \param [IN] ListToDelete : list entry to be deleted -*/ -void ListDeleteNode(PRT_LIST_ENTRY ListToDelete); - -/** - Tell whether the list is empty - \param [IN] ListHead : List header of which to be test -*/ -unsigned char ListIsEmpty(PRT_LIST_HEAD ListHead); - -// EXTERN void ListEmpty(PRT_LIST_HEAD ListHead); - -void ListAdd( - PRT_LIST_ENTRY New, - PRT_LIST_ENTRY Prev, - PRT_LIST_ENTRY Next); - -/*---------------------------------------------------------------------------------- - MACRO -----------------------------------------------------------------------------------*/ - -/** - Macros to iterate over the list. - \param _Iter : struct PRT_LIST_ENTRY type iterator to use as a loop cursor - \param _ListHead : List head of which to be iterated -*/ -#define LIST_FOR_EACH(_Iter, _ListHead) \ - for ((_Iter) = (_ListHead)->Next; (_Iter) != (_ListHead); (_Iter) = (_Iter)->Next) - -/** - Macros to iterate over the list safely against removal of list entry. - If you would delete any list entry from the list while iterating the list, should use this macro - \param _Iter : Struct PRT_LIST_ENTRY type iterator to use as a loop cursor - \param _Temp : Another Struct PRT_LIST_ENTRY type to use as a temporary storage - \param _ListHead : List head of which to be iterated -*/ -#define LIST_FOR_EACH_SAFELY(_Iter, _Temp, _ListHead) \ - for ((_Iter) = (_ListHead)->Next, (_Temp) = (_Iter)->Next; (_Iter) != (_ListHead); \ - (_Iter) = (_Temp), (_Temp) = (_Iter)->Next) - -/** - Macros to get the struct pointer of this list entry - You could make every RT_LIST_ENTRY at the first place of your structure to avoid the macro, which will be dangerouse. - Copy from winnt.h. - BUG:if offset of field in type larger than 32 bit integer, which is not likely to happen, it will error - \param _Ptr : Struct RT_LIST_ENTRY type pointer - \param _Type : The type of structure in which the RT_LIST_ENTRY embedded in - \param _Field : the name of the RT_LIST_ENTRY within the struct -*/ -#define LIST_ENTRY(_Ptr, _Type, _Field) ((_Type *)((char *)(_Ptr) - (unsigned long)(&((_Type *)0)->_Field))) - -#endif /*BT_LIST_H*/ diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/bt_skbuff.h b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/bt_skbuff.h deleted file mode 100755 index e274d1bc..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/bt_skbuff.h +++ /dev/null @@ -1,339 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -/****************************************************************************** - * - * Module Name: - * bt_skbuff.h - * - * Abstract: - * Data buffer managerment through whole bluetooth stack. - * - * Major Change History: - * When Who What - * -------------------------------------------------------------- - * 2010-06-11 W.Bi Created. - * - * Notes: - * To reduce memory copy when pass data buffer to other layers, - * RTK_BUFFER is designed referring to linux socket buffer. - * But I still wonder its effect, since RTK_BUFFER is much bigger - * than original data buffer.RTK_BUFFER will reduce its member if - * it would not reach what i had expected. - * - ******************************************************************************/ - -#ifndef BT_SKBUFF_H -#define BT_SKBUFF_H -#include "bt_list.h" -#include -#include -#include "bt_vendor_lib.h" - -#ifndef EXTERN -#define EXTERN -#endif - -#ifndef IN -#define IN -#endif - -#ifndef OUT -#define OUT -#endif -/*---------------------------------------------------------------------------------- - CONSTANT DEFINITION -----------------------------------------------------------------------------------*/ -#define RTK_CONTEXT_SIZE 12 - -#define RTB_QUEUE_ID_LENGTH 64 - -/*---------------------------------------------------------------------------------- - STRUCTURE DEFINITION -----------------------------------------------------------------------------------*/ -/** - Rtk buffer definition - Head -->|<---Data--->|<-----Length------>| <---End - _________________________________ - |_____________|___________________| - |<-headroom->|<--RealDataBuffer-->| - - Compared to socket buffer, there exists no tail and end pointer and tailroom as tail is rarely used in bluetooth stack - \param List : List structure used to list same type rtk buffer and manipulate rtk buffer like list. - \param Head : Pointer to truly allocated data buffer. It point to the headroom - \param Data : Pointer to real data buffer. - \param Length : currently data length - \param HeadRoom : Record initialize headroom size. - \param RefCount : Reference count. zero means able to be freed, otherwise somebody is handling it. - \param Priv : Reserved for multi-device support. Record Hci pointer which will handles this packet - \param Contest : Control buffer, put private variables here. -*/ -typedef struct _RTK_BUFFER -{ - RT_LIST_ENTRY List; - uint8_t *Head; - uint8_t *Data; - uint8_t *Tail; - uint8_t *End; - uint32_t Length; - uint32_t HeadRoom; - // RT_U16 TailRoom; - signed char RefCount; - - void *Priv; - uint8_t Context[RTK_CONTEXT_SIZE]; -} RTK_BUFFER, *PRTK_BUFFER; - -/** - RTK_BUFFER Control Buffer Context - \param PacketType : HCI data types, Command/Acl/... - \param LastFrag : Is Current Acl buffer the last fragment.(0 for no, 1 for yes) - \param TxSeq : Current packet tx sequence - \param Retries : Current packet retransmission times - \param Sar : L2cap control field segmentation and reassembly bits -*/ -struct BT_RTB_CONTEXT -{ - uint8_t PacketType; - uint16_t Handle; -}; - -/// definition to get rtk_buffer's control buffer context pointer -#define BT_CONTEXT(_Rtb) ((struct BT_RTB_CONTEXT *)((_Rtb)->Context)) - -/** - Since RTBs are always used into/from list, so abstract this struct and provide APIs to easy process on RTBs -*/ -typedef struct _RTB_QUEUE_HEAD RTB_QUEUE_HEAD; -/*---------------------------------------------------------------------------------- - EXTERNAL FUNCTION -----------------------------------------------------------------------------------*/ -/** - Allocate a RTK_BUFFER with specified data length and reserved headroom. - If caller does not know actual headroom to reserve for further usage, specify it to zero to use default value. - \param [IN] Length : current data buffer length to allcated - \param [IN] HeadRoom : if caller knows reserved head space, set it; otherwise set 0 to use default value - \return pointer to RTK_BUFFER if succeed, null otherwise -*/ -RTK_BUFFER * -RtbAllocate( - IN uint32_t Length, - IN uint32_t HeadRoom); - -/** - Free specified Rtk_buffer - \param [IN] RtkBuffer : buffer to free -*/ -void RtbFree( - IN RTK_BUFFER *RtkBuffer); - -/** - increment reference count -*/ -void RtbIncreaseRefCount( - IN RTK_BUFFER *RtkBuffer); - -/** - Recycle a rtk_buffer after its usage if specified rtb could - if rtb total length is not smaller than specified rtbsize to be recycled for, it will succeeded recycling - \param [IN OUT] RtkBuffer : buffer to recycle - \param [IN] RtbSize : size of buffer to be recycled for -*/ -/* -BOOLEAN -RtbCheckRecycle( - IN OUT RTK_BUFFER* RtkBuffer, - IN uint32_t RtbSize - ); -*/ -/** - Add a specified length protocol header to the start of data buffer hold by specified rtk_buffer. - This function extends used data area of the buffer at the buffer start. - \param [IN OUT] RtkBuffer : data buffer to add - \param [IN] Length : header length - \return Pointer to the first byte of the extra data is returned -*/ -uint8_t * -RtbAddHead( - IN OUT RTK_BUFFER *RtkBuffer, - IN uint32_t Length); - -/** - Remove a specified length data from the start of data buffer hold by specified rtk_buffer. - This function returns the memory to the headroom. - \param [IN OUT] RtkBuffer : data buffer to remove - \param [IN] Length : header length - \return Pointer to the next data in the buffer is returned, usually useless -*/ -unsigned char -RtbRemoveHead( - IN OUT RTK_BUFFER *RtkBuffer, - IN uint32_t Length); - -/** - Add a specified length protocol header to the end of data buffer hold by specified rtk_buffer. - This function extends used data area of the buffer at the buffer end. - \param [IN OUT] RtkBuffer : data buffer to add - \param [IN] Length : header length - \return Pointer to the first byte of the extra data is returned -*/ -EXTERN uint8_t * -RtbAddTail( - IN OUT RTK_BUFFER *RtkBuffer, - IN uint32_t Length); - -/** - Remove a specified length data from the end of data buffer hold by specified rtk_buffer. -*/ -EXTERN unsigned char -RtbRemoveTail( - IN OUT RTK_BUFFER *RtkBuffer, - IN uint32_t Length); - -/** - Initialize a rtb queue. - \return Initialized rtb queue if succeed, otherwise NULL -*/ -EXTERN RTB_QUEUE_HEAD * -RtbQueueInit(); - -/** - Free a rtb queue. - \param [IN] RtkQueueHead : Rtk Queue -*/ -EXTERN void -RtbQueueFree( - RTB_QUEUE_HEAD *RtkQueueHead); -/** - Queue specified RtkBuffer into a RtkQueue at list tail. - \param [IN OUT] RtkQueueHead : Rtk Queue - \param [IN] RtkBuffer : Rtk buffer to add -*/ -EXTERN void -RtbQueueTail( - IN OUT RTB_QUEUE_HEAD *RtkQueueHead, - IN RTK_BUFFER *RtkBuffer); - -/** - Queue specified RtkBuffer into a RtkQueue at list Head. - \param [IN OUT] RtkQueueHead : Rtk Queue - \param [IN] RtkBuffer : Rtk buffer to add -*/ -EXTERN void -RtbQueueHead( - IN OUT RTB_QUEUE_HEAD *RtkQueueHead, - IN RTK_BUFFER *RtkBuffer); - -/** - Remove a RtkBuffer from specified rtkqueue at list tail. - \param [IN OUT] RtkQueueHead : Rtk Queue - \return removed rtkbuffer if succeed, otherwise NULL -*/ -EXTERN RTK_BUFFER * -RtbDequeueTail( - IN OUT RTB_QUEUE_HEAD *RtkQueueHead); - -/** - Remove a RtkBuffer from specified rtkqueue at list head. - \param [IN OUT] RtkQueueHead : Rtk Queue - \return removed rtkbuffer if succeed, otherwise NULL -*/ -EXTERN RTK_BUFFER * -RtbDequeueHead( - IN OUT RTB_QUEUE_HEAD *RtkQueueHead); - -/** - Get current rtb queue's length. - \param [IN] RtkQueueHead : Rtk Queue - \return current queue's length -*/ -EXTERN signed long -RtbGetQueueLen( - IN RTB_QUEUE_HEAD *RtkQueueHead); - -/** - Empty the rtkqueue. - \param [IN OUT] RtkQueueHead : Rtk Queue -*/ -EXTERN void -RtbEmptyQueue( - IN OUT RTB_QUEUE_HEAD *RtkQueueHead); - -/** - Get the RtkBuffer which is the head of a RtkQueue - \param [IN OUT] RtkQueueHead : Rtk Queue - \return head of the RtkQueue , otherwise NULL -*/ -EXTERN RTK_BUFFER * -RtbTopQueue( - IN RTB_QUEUE_HEAD *RtkQueueHead); - -/** - Insert new Rtkbuffer in the old buffer - \param [IN OUT] RtkQueueHead : Rtk Queue - \param [IN] OldRtkBuffer : old rtk buffer - \param [IN] NewRtkBuffer : Rtk buffer to add -*/ -EXTERN void -RtbInsertBefore( - IN OUT RTB_QUEUE_HEAD *RtkQueueHead, - IN RTK_BUFFER *pOldRtkBuffer, - IN RTK_BUFFER *pNewRtkBuffer); - -/** - check whether the buffer is the last node in the queue -*/ -EXTERN unsigned char -RtbNodeIsLast( - IN RTB_QUEUE_HEAD *RtkQueueHead, - IN RTK_BUFFER *pRtkBuffer); - -/** - get the next buffer node after the specified buffer in the queue - if the specified buffer is the last node in the queue , return NULL - \param [IN] RtkBuffer : Rtk Queue - \param [IN] RtkBuffer : Rtk buffer - \return node after the specified buffer -*/ -EXTERN RTK_BUFFER * -RtbQueueNextNode( - IN RTB_QUEUE_HEAD *RtkQueueHead, - IN RTK_BUFFER *pRtkBuffer); - -/** - check whether queue is empty -*/ -EXTERN bool -RtbQueueIsEmpty( - IN RTB_QUEUE_HEAD *RtkQueueHead); - -// annie_tmp -EXTERN unsigned char -RtbCheckQueueLen( - IN RTB_QUEUE_HEAD *RtkQueueHead, - IN uint8_t Len); - -EXTERN void -RtbRemoveNode( - IN OUT RTB_QUEUE_HEAD *RtkQueueHead, - IN RTK_BUFFER *RtkBuffer); - -EXTERN RTK_BUFFER * -RtbCloneBuffer( - IN RTK_BUFFER *pDataBuffer); - -#endif /*BT_SKBUFF_H*/ diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/bt_vendor_rtk.h b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/bt_vendor_rtk.h deleted file mode 100755 index ba99e39a..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/bt_vendor_rtk.h +++ /dev/null @@ -1,255 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -/****************************************************************************** - * - * Filename: bt_vendor_rtk.h - * - * Description: A wrapper header file of bt_vendor_lib.h - * - * Contains definitions specific for interfacing with Realtek - * Bluetooth chipsets - * - ******************************************************************************/ - -#ifndef BT_VENDOR_RTK_H -#define BT_VENDOR_RTK_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "hardware.h" -#include "rtk_common.h" -#include "bt_vendor_lib.h" -#include "rtk_btsnoop_net.h" - -#define RTK_VERSION "5.0.1" -/****************************************************************************** -** Constants & Macros -******************************************************************************/ -#define RTKBT_TRANS_H4 0x20 -#define RTKBT_TRANS_H5 0x10 -#define RTKBT_TRANS_UART 0x01 -#define RTKBT_TRANS_USB 0x02 - -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE (!FALSE) -#endif - -#ifndef BTVND_DBG -#define BTVND_DBG TRUE -#endif - -#undef BTVNDDBG -#if (BTVND_DBG == TRUE) -#define BTVNDDBG(param, ...) \ - { \ - HILOGD(param, ##__VA_ARGS__); \ - } -#else -#define BTVNDDBG(param, ...) \ - { \ - } -#endif - -#define DOWN_FW_CFG _IOW('E', 176, int) -#define SET_ISO_CFG _IOW('E', 177, int) -#define RESET_CONTROLLER _IOW('E', 178, int) -#define DWFW_CMPLT _IOW('E', 179, int) - -#define GET_USB_INFO _IOR('E', 180, int) - -/* Device port name where Bluetooth controller attached */ -#ifndef BLUETOOTH_UART_DEVICE_PORT -#define BLUETOOTH_UART_DEVICE_PORT "/dev/ttyO1" /* maguro */ -#endif - -/* Location of firmware patch files */ -#ifndef FW_PATCHFILE_LOCATION -#define FW_PATCHFILE_LOCATION "/vendor/firmware/" /* maguro */ -#endif - -#ifndef UART_TARGET_BAUD_RATE -#define UART_TARGET_BAUD_RATE 3000000 -#endif - -/* The Bluetooth Device Aaddress source switch: - * - * -FALSE- (default value) - * Get the factory BDADDR from device's file system. Normally the BDADDR is - * stored in the location pointed by the PROPERTY_BT_BDADDR_PATH (defined in - * btif_common.h file) property. - * - * -TRUE- - * If the Bluetooth Controller has equipped with a non-volatile memory (such - * as BCM4330's OTP memory), the factory BDADDR can be stored in there and - * retrieved by the stack while enabling BT. - * !!! WARNING !!! Make sure that the OTP feature has been enabled in the - * firmware patchram (.hcd) file. - */ -#ifndef USE_CONTROLLER_BDADDR -#define USE_CONTROLLER_BDADDR TRUE // FALSE -#endif - -/* sleep mode - - 0: disable - 1: UART with Host wake/BT wake out of band signals -*/ -#ifndef LPM_SLEEP_MODE -#define LPM_SLEEP_MODE 1 -#endif - -/* Host Stack Idle Threshold in 300ms or 25ms - - In sleep mode 1, this is the number of firmware loops executed with no - activity before the Host wake line is deasserted. Activity includes HCI - traffic excluding certain sleep mode commands and the presence of SCO - connections if the "Allow Host Sleep During SCO" flag is not set to 1. - Each count of this parameter is roughly equivalent to 300ms or 25ms. -*/ -#ifndef LPM_IDLE_THRESHOLD -#define LPM_IDLE_THRESHOLD 1 -#endif - -/* Host Controller Idle Threshold in 300ms or 25ms - - This is the number of firmware loops executed with no activity before the - HC is considered idle. Depending on the mode, HC may then attempt to sleep. - Activity includes HCI traffic excluding certain sleep mode commands and - the presence of ACL/SCO connections. -*/ -#ifndef LPM_HC_IDLE_THRESHOLD -#define LPM_HC_IDLE_THRESHOLD 1 -#endif - -/* BT_WAKE Polarity - 0=Active Low, 1= Active High */ -#ifndef LPM_BT_WAKE_POLARITY -#define LPM_BT_WAKE_POLARITY 1 /* maguro */ -#endif - -/* HOST_WAKE Polarity - 0=Active Low, 1= Active High */ -#ifndef LPM_HOST_WAKE_POLARITY -#define LPM_HOST_WAKE_POLARITY 1 /* maguro */ -#endif - -/* LPM_ALLOW_HOST_SLEEP_DURING_SCO - - When this flag is set to 0, the host is not allowed to sleep while - an SCO is active. In sleep mode 1, the device will keep the host - wake line asserted while an SCO is active. - When this flag is set to 1, the host can sleep while an SCO is active. - This flag should only be set to 1 if SCO traffic is directed to the PCM - interface. -*/ -#ifndef LPM_ALLOW_HOST_SLEEP_DURING_SCO -#define LPM_ALLOW_HOST_SLEEP_DURING_SCO 1 -#endif - -/* LPM_COMBINE_SLEEP_MODE_AND_LPM - - In Mode 0, always set byte 7 to 0. In sleep mode 1, device always - requires permission to sleep between scans / periodic inquiries regardless - of the setting of this byte. In sleep mode 1, if byte is set, device must - have "permission" to sleep during the low power modes of sniff, hold, and - park. If byte is not set, device can sleep without permission during these - modes. Permission to sleep in Mode 1 is obtained if the BT_WAKE signal is - not asserted. -*/ -#ifndef LPM_COMBINE_SLEEP_MODE_AND_LPM -#define LPM_COMBINE_SLEEP_MODE_AND_LPM 1 -#endif - -/* LPM_ENABLE_UART_TXD_TRI_STATE - - When set to 0, the device will not tristate its UART TX line before going - to sleep. - When set to 1, the device will tristate its UART TX line before going to - sleep. -*/ -#ifndef LPM_ENABLE_UART_TXD_TRI_STATE -#define LPM_ENABLE_UART_TXD_TRI_STATE 0 -#endif - -/* LPM_PULSED_HOST_WAKE - */ -#ifndef LPM_PULSED_HOST_WAKE -#define LPM_PULSED_HOST_WAKE 0 -#endif - -/* LPM_IDLE_TIMEOUT_MULTIPLE - - The multiple factor of host stack idle threshold in 300ms/25ms -*/ -#ifndef LPM_IDLE_TIMEOUT_MULTIPLE -#define LPM_IDLE_TIMEOUT_MULTIPLE 10 -#endif - -/* BT_WAKE_VIA_USERIAL_IOCTL - - Use userial ioctl function to control BT_WAKE signal -*/ -#ifndef BT_WAKE_VIA_USERIAL_IOCTL -#define BT_WAKE_VIA_USERIAL_IOCTL FALSE -#endif - -/* BT_WAKE_VIA_PROC - - LPM & BT_WAKE control through PROC nodes -*/ -#ifndef BT_WAKE_VIA_PROC -#define BT_WAKE_VIA_PROC FALSE -#endif - -/* HW_END_WITH_HCI_RESET - - Sample code implementation of sending a HCI_RESET command during the epilog - process. It calls back to the callers after command complete of HCI_RESET - is received. -*/ -#ifndef HW_END_WITH_HCI_RESET -#define HW_END_WITH_HCI_RESET FALSE -#endif - -#define BD_ADDR_LEN 6 -#define PROPERTY_VALUE_MAX 92 -#define PATH_MAX 4096 - -/****************************************************************************** -** Extern variables and functions -******************************************************************************/ - -extern bt_vendor_callbacks_t *bt_vendor_cbacks; - -#endif /* BT_VENDOR_RTK_H */ diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/hardware.h b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/hardware.h deleted file mode 100755 index f968801e..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/hardware.h +++ /dev/null @@ -1,217 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -#ifndef HARDWARE_H -#define HARDWARE_H - -#include -#include - -#if __BYTE_ORDER == __LITTLE_ENDIAN -#define cpu_to_le16(d) (d) -#define cpu_to_le32(d) (d) -#define le16_to_cpu(d) (d) -#define le32_to_cpu(d) (d) -#elif __BYTE_ORDER == __BIG_ENDIAN -#define cpu_to_le16(d) bswap_16(d) -#define cpu_to_le32(d) bswap_32(d) -#define le16_to_cpu(d) bswap_16(d) -#define le32_to_cpu(d) bswap_32(d) -#else -#error "Unknown byte order" -#endif - -#define FIRMWARE_DIRECTORY "/vendor/firmware/%s" -#define BT_CONFIG_DIRECTORY "/vendor/firmware/%s" -#define PATCH_DATA_FIELD_MAX_SIZE 252 -#define RTK_VENDOR_CONFIG_MAGIC 0x8723ab55 -#define MAX_PATCH_SIZE_24K (1024 * 24) // 24K -#define MAX_PATCH_SIZE_40K (1024 * 40) // 40K - -#define MAX_ORG_CONFIG_SIZE (0x100 * 14) -#define MAX_ALT_CONFIG_SIZE (0x100 * 2) - -struct rtk_bt_vendor_config_entry -{ - uint16_t offset; - uint8_t entry_len; - uint8_t entry_data[0]; -} __attribute__((packed)); - -struct rtk_bt_vendor_config -{ - uint32_t signature; - uint16_t data_len; - struct rtk_bt_vendor_config_entry entry[0]; -} __attribute__((packed)); - -#define HCI_CMD_MAX_LEN 258 - -#define HCI_VERSION_MASK_10 (1 << 0) // Bluetooth Core Spec 1.0b -#define HCI_VERSION_MASK_11 (1 << 1) // Bluetooth Core Spec 1.1 -#define HCI_VERSION_MASK_12 (1 << 2) // Bluetooth Core Spec 1.2 -#define HCI_VERSION_MASK_20 (1 << 3) // Bluetooth Core Spec 2.0+EDR -#define HCI_VERSION_MASK_21 (1 << 4) // Bluetooth Core Spec 2.1+EDR -#define HCI_VERSION_MASK_30 (1 << 5) // Bluetooth Core Spec 3.0+HS -#define HCI_VERSION_MASK_40 (1 << 6) // Bluetooth Core Spec 4.0 -#define HCI_VERSION_MASK_41 (1 << 7) // Bluetooth Core Spec 4.1 -#define HCI_VERSION_MASK_42 (1 << 8) // Bluetooth Core Spec 4.2 -#define HCI_VERSION_MASK_ALL (0xFFFFFFFF) - -#define HCI_REVISION_MASK_ALL (0xFFFFFFFF) - -#define LMP_SUBVERSION_NONE (0x0) -#define LMPSUBVERSION_8723a (0x1200) - -#define CHIPTYPE_NONE (0x1F) // Chip Type's range: 0x0 ~ 0xF -#define CHIP_TYPE_MASK_ALL (0xFFFFFFFF) - -#define PROJECT_ID_MASK_ALL (0xFFFFFFFF) // temp used for unknown project id for a new chip - -#define PATCH_OPTIONAL_MATCH_FLAG_CHIPTYPE (0x1) - -#define CONFIG_MAC_OFFSET_GEN_1_2 (0x3C) // MAC's OFFSET in config/efuse for realtek generation 1~2 bluetooth chip -#define CONFIG_MAC_OFFSET_GEN_3PLUS (0x44) // MAC's OFFSET in config/efuse for rtk generation 3+ bluetooth chip -#define CONFIG_MAC_OFFSET_GEN_4PLUS (0x30) // MAC's OFFSET in config/efuse for rtk generation 4+ bluetooth chip - -#define HCI_EVT_CMD_CMPL_OPCODE_OFFSET (3) // opcode's offset in COMMAND Completed Event -#define HCI_EVT_CMD_CMPL_STATUS_OFFSET (5) // status's offset in COMMAND Completed Event - -#define HCI_EVT_CMD_CMPL_OP1001_HCI_VERSION_OFFSET (6) // HCI_Version's offset in COMMAND Completed Event for OpCode 0x1001(Read Local Version Information Command) -#define HCI_EVT_CMD_CMPL_OP1001_HCI_REVISION_OFFSET (7) // HCI_Revision's offset in COMMAND Completed Event for OpCode 0x1001(Read Local Version Information Command) -#define HCI_EVT_CMD_CMPL_OP1001_LMP_SUBVERSION_OFFSET (12) // LMP Subversion's offset in COMMAND Completed Event for OpCode 0x1001(Read Local Version Information Command) -#define HCI_EVT_CMD_CMPL_OP0C14_LOCAL_NAME_OFFSET (6) // Local Name's offset in COMMAND Completed Event for OpCode 0x0C14(Read Local Name Command) -#define HCI_EVT_CMD_CMPL_OP1009_BDADDR_OFFSET (6) // BD_ADDR's offset in COMMAND Completed Event for OpCode 0x1009(Read BD_ADDR Command) -#define HCI_EVT_CMD_CMPL_OPFC6D_EVERSION_OFFSET (6) // eversion's offset in COMMAND Completed Event for OpCode 0xfc6d(Read eVERSION Vendor Command) -#define HCI_EVT_CMD_CMPL_OPFC61_CHIPTYPE_OFFSET (6) // chip type's offset in COMMAND Completed Event for OpCode 0xfc61(Read ChipType Vendor Command) - -//#define UPDATE_BAUDRATE_CMD_PARAM_SIZE (6) -#define HCI_CMD_PREAMBLE_SIZE (3) -#define HCI_CMD_READ_CHIP_TYPE_SIZE (5) -//#define HCD_REC_PAYLOAD_LEN_BYTE (2) -//#define BD_ADDR_LEN (6) -//#define LOCAL_NAME_BUFFER_LEN (32) -//#define LOCAL_BDADDR_PATH_BUFFER_LEN (256) - -#define H5_SYNC_REQ_SIZE (2) -#define H5_SYNC_RESP_SIZE (2) -#define H5_CONF_REQ_SIZE (3) -#define H5_CONF_RESP_SIZE (2) - -/****************************************************************************** -** Local type definitions -******************************************************************************/ - -/* Hardware Configuration State */ -enum -{ - HW_CFG_H5_INIT = 1, - HW_CFG_READ_LOCAL_VER, - HW_CFG_READ_ECO_VER, // eco version - HW_CFG_READ_CHIP_TYPE, - HW_CFG_START, - HW_CFG_SET_UART_BAUD_HOST, // change FW baudrate - HW_CFG_SET_UART_BAUD_CONTROLLER, // change Host baudrate - HW_CFG_SET_UART_HW_FLOW_CONTROL, - HW_CFG_RESET_CHANNEL_CONTROLLER, - HW_RESET_CONTROLLER, - HARDWARE_INIT_COMPLETE, - HW_CFG_DL_FW_PATCH -}; - -/* h/w config control block */ -typedef struct -{ - uint32_t max_patch_size; - uint32_t baudrate; - uint16_t lmp_subversion; - uint16_t lmp_subversion_default; - uint16_t lmp_sub_current; - uint8_t state; /* Hardware configuration state */ - uint8_t eversion; - uint32_t project_id_mask; - uint8_t hci_version; - uint8_t hci_revision; - uint8_t chip_type; - uint8_t dl_fw_flag; - int fw_len; /* FW patch file len */ - size_t config_len; /* Config patch file len */ - unsigned int total_len; /* FW & config extracted buf len */ - uint8_t *fw_buf; /* FW patch file buf */ - uint8_t *config_buf; /* Config patch file buf */ - uint8_t *total_buf; /* FW & config extracted buf */ - uint8_t patch_frag_cnt; /* Patch fragment count download */ - uint8_t patch_frag_idx; /* Current patch fragment index */ - uint8_t patch_frag_len; /* Patch fragment length */ - uint8_t patch_frag_tail; /* Last patch fragment length */ - uint8_t hw_flow_cntrl; /* Uart flow control, bit7:set, bit0:enable */ - uint16_t vid; /* usb vendor id */ - uint16_t pid; /* usb product id */ - uint8_t heartbeat; /*heartbeat*/ -} bt_hw_cfg_cb_t; - -/* low power mode parameters */ -typedef struct -{ - uint8_t sleep_mode; /* 0(disable),1(UART),9(H5) */ - uint8_t host_stack_idle_threshold; /* Unit scale 300ms/25ms */ - uint8_t host_controller_idle_threshold; /* Unit scale 300ms/25ms */ - uint8_t bt_wake_polarity; /* 0=Active Low, 1= Active High */ - uint8_t host_wake_polarity; /* 0=Active Low, 1= Active High */ - uint8_t allow_host_sleep_during_sco; - uint8_t combine_sleep_mode_and_lpm; - uint8_t enable_uart_txd_tri_state; /* UART_TXD Tri-State */ - uint8_t sleep_guard_time; /* sleep guard time in 12.5ms */ - uint8_t wakeup_guard_time; /* wakeup guard time in 12.5ms */ - uint8_t txd_config; /* TXD is high in sleep state */ - uint8_t pulsed_host_wake; /* pulsed host wake if mode = 1 */ -} bt_lpm_param_t; - -#define ROM_LMP_NONE 0x0000 -#define ROM_LMP_8723a 0x1200 -#define ROM_LMP_8723b 0x8723 -#define ROM_LMP_8821a 0X8821 -#define ROM_LMP_8761a 0X8761 -#define ROM_LMP_8761b 0X8761 -#define ROM_LMP_8703a 0x8723 -#define ROM_LMP_8763a 0x8763 -#define ROM_LMP_8703b 0x8703 -#define ROM_LMP_8723c 0x8703 -#define ROM_LMP_8822b 0x8822 -#define ROM_LMP_8723d 0x8723 -#define ROM_LMP_8821c 0x8821 -#define ROM_LMP_8822c 0x8822 - -struct rtk_epatch_entry -{ - uint16_t chip_id; - uint16_t patch_length; - uint32_t patch_offset; - uint32_t svn_version; - uint32_t coex_version; -} __attribute__((packed)); - -struct rtk_epatch -{ - uint8_t signature[8]; - uint32_t fw_version; - uint16_t number_of_patch; - struct rtk_epatch_entry entry[0]; -} __attribute__((packed)); - -#endif diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/hci_h5_int.h b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/hci_h5_int.h deleted file mode 100755 index afdb593d..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/hci_h5_int.h +++ /dev/null @@ -1,80 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -#ifndef RTK_HCI_H5_INT_H -#define RTK_HCI_H5_INT_H - -#pragma once - -#include -#include -#include "bt_hci_bdroid.h" -#include "bt_vendor_lib.h" -#include -#include -#include -#include "rtk_hcidefs.h" -#include "rtk_common.h" - -// HCI Command opcodes -#define HCI_LE_READ_BUFFER_SIZE 0x2002 -#define DATA_TYPE_H5 0x05 - -// HCI VENDOR Command opcode -#define HCI_VSC_H5_INIT 0xFCEE -#define HCI_VSC_UPDATE_BAUDRATE 0xFC17 -#define HCI_VSC_DOWNLOAD_FW_PATCH 0xFC20 -#define HCI_VSC_READ_ROM_VERSION 0xFC6D -#define HCI_VSC_READ_CHIP_TYPE 0xFC61 -#define HCI_VSC_SET_WAKE_UP_DEVICE 0xFC7B -#define HCI_VSC_BT_OFF 0xFC28 -#define HCI_READ_LMP_VERSION 0x1001 -#define HCI_VENDOR_RESET 0x0C03 -#define HCI_VENDOR_FORCE_RESET_AND_PATCHABLE 0xFC66 - -void ms_delay(uint32_t timeout); - -typedef enum -{ - DATA_TYPE_COMMAND = 1, - DATA_TYPE_ACL = 2, - DATA_TYPE_SCO = 3, - DATA_TYPE_EVENT = 4 -} serial_data_type_t; - -typedef struct hci_h5_callbacks_t -{ - uint16_t (*h5_int_transmit_data_cb)(serial_data_type_t type, uint8_t *data, uint16_t length); - void (*h5_data_ready_cb)(serial_data_type_t type, unsigned int total_length); -} hci_h5_callbacks_t; - -typedef struct hci_h5_t -{ - void (*h5_int_init)(hci_h5_callbacks_t *h5_callbacks); - void (*h5_int_cleanup)(void); - uint16_t (*h5_send_cmd)(serial_data_type_t type, uint8_t *data, uint16_t length); - uint8_t (*h5_send_sync_cmd)(uint16_t opcode, uint8_t *data, uint16_t length); - uint16_t (*h5_send_acl_data)(serial_data_type_t type, uint8_t *data, uint16_t length); - uint16_t (*h5_send_sco_data)(serial_data_type_t type, uint8_t *data, uint16_t length); - bool (*h5_recv_msg)(uint8_t *byte, uint16_t length); - size_t (*h5_int_read_data)(uint8_t *data_buffer, size_t max_size); -} hci_h5_t; - -const hci_h5_t *hci_get_h5_int_interface(void); - -#endif diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_btservice.h b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_btservice.h deleted file mode 100755 index 4131ee28..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_btservice.h +++ /dev/null @@ -1,26 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#ifndef RTK_BTSERVICE_H -#define RTK_BTSERVICE_H - -#include -#include - -#define HCI_RTKBT_AUTOPAIR_EVT 0x30 - -#endif diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_btsnoop_net.h b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_btsnoop_net.h deleted file mode 100755 index 8fa21d4b..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_btsnoop_net.h +++ /dev/null @@ -1,58 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -/****************************************************************************** - * - * Filename: rtk_btsnoop_net.h - * - * Description: A wrapper header file of bt_vendor_lib.h - * - * Contains definitions specific for interfacing with Realtek - * Bluetooth chipsets - * - ******************************************************************************/ - -#ifndef RTK_BTSNOOP_NET_H -#define RTK_BTSNOOP_NET_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "hci_h5_int.h" -#include -#include -#include -#include -#include - -void rtk_btsnoop_open(void); -void rtk_btsnoop_close(void); -void rtk_btsnoop_capture(const HC_BT_HDR *p_buf, bool is_rcvd); - -void rtk_btsnoop_net_open(); -void rtk_btsnoop_net_close(); -void rtk_btsnoop_net_write(serial_data_type_t type, uint8_t *data, bool is_received); - -#endif diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_common.h b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_common.h deleted file mode 100755 index c5974925..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_common.h +++ /dev/null @@ -1,66 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#ifndef RTK_COMMON_H -#define RTK_COMMON_H - -#define RTK_UNUSED(x) (void)(x) - -#define STREAM_TO_UINT16(u16, p) \ - { \ - u16 = ((uint16_t)(*(p)) + (((uint16_t)(*((p) + 1))) << 8)); \ - (p) += 2; \ - } -#define UINT16_TO_STREAM(p, u16) \ - { \ - *(p)++ = (uint8_t)(u16); \ - *(p)++ = (uint8_t)((u16) >> 8); \ - } -#define UINT32_TO_STREAM(p, u32) \ - { \ - *(p)++ = (uint8_t)(u32); \ - *(p)++ = (uint8_t)((u32) >> 8); \ - *(p)++ = (uint8_t)((u32) >> 16); \ - *(p)++ = (uint8_t)((u32) >> 24); \ - } -#define STREAM_TO_UINT32(u32, p) \ - { \ - u32 = (((uint32_t)(*(p))) + ((((uint32_t)(*((p) + 1)))) << 8) + ((((uint32_t)(*((p) + 2)))) << 16) + ((((uint32_t)(*((p) + 3)))) << 24)); \ - (p) += 4; \ - } -#define UINT8_TO_STREAM(p, u8) \ - { \ - *(p)++ = (uint8_t)(u8); \ - } -#define STREAM_TO_UINT8(u8, p) \ - { \ - u8 = (uint8_t)(*(p)); \ - (p) += 1; \ - } - -#define STREAM_SKIP_UINT8(p) \ - do \ - { \ - (p) += 1; \ - } while (0) -#define STREAM_SKIP_UINT16(p) \ - do \ - { \ - (p) += 2; \ - } while (0) - -#endif diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_hcidefs.h b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_hcidefs.h deleted file mode 100755 index db2d615f..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_hcidefs.h +++ /dev/null @@ -1,2646 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#ifndef HCIDEFS_H -#define HCIDEFS_H - -#define HCI_PROTO_VERSION 0x01 /* Version for BT spec 1.1 */ -#define HCI_PROTO_VERSION_1_2 0x02 /* Version for BT spec 1.2 */ -#define HCI_PROTO_VERSION_2_0 0x03 /* Version for BT spec 2.0 */ -#define HCI_PROTO_VERSION_2_1 0x04 /* Version for BT spec 2.1 [Lisbon] */ -#define HCI_PROTO_VERSION_3_0 0x05 /* Version for BT spec 3.0 */ -#define HCI_PROTO_VERSION_4_0 0x06 /* Version for BT spec 4.0 */ -#define HCI_PROTO_VERSION_4_1 0x07 /* Version for BT spec 4.1 */ -#define HCI_PROTO_VERSION_4_2 0x08 /* Version for BT spec 4.2 */ -#define HCI_PROTO_VERSION_5_0 0x09 /* Version for BT spec 5.0 */ - -/* -** Definitions for HCI groups -*/ -#define HCI_GRP_LINK_CONTROL_CMDS (0x01 << 10) /* 0x0400 */ -#define HCI_GRP_LINK_POLICY_CMDS (0x02 << 10) /* 0x0800 */ -#define HCI_GRP_HOST_CONT_BASEBAND_CMDS (0x03 << 10) /* 0x0C00 */ -#define HCI_GRP_INFORMATIONAL_PARAMS (0x04 << 10) /* 0x1000 */ -#define HCI_GRP_STATUS_PARAMS (0x05 << 10) /* 0x1400 */ -#define HCI_GRP_TESTING_CMDS (0x06 << 10) /* 0x1800 */ - -#define HCI_GRP_VENDOR_SPECIFIC (0x3F << 10) /* 0xFC00 */ - -/* Group occupies high 6 bits of the HCI command rest is opcode itself */ -#define HCI_OGF(p) (uint8_t)((0xFC00 & (p)) >> 10) -#define HCI_OCF(p) (0x3FF & (p)) - -/* -** Definitions for Link Control Commands -*/ -/* Following opcode is used only in command complete event for flow control */ -#define HCI_COMMAND_NONE 0x0000 - -/* Commands of HCI_GRP_LINK_CONTROL_CMDS group */ -#define HCI_INQUIRY (0x0001 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_INQUIRY_CANCEL (0x0002 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_PERIODIC_INQUIRY_MODE (0x0003 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_EXIT_PERIODIC_INQUIRY_MODE (0x0004 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_CREATE_CONNECTION (0x0005 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_DISCONNECT (0x0006 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_ADD_SCO_CONNECTION (0x0007 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_CREATE_CONNECTION_CANCEL (0x0008 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_ACCEPT_CONNECTION_REQUEST (0x0009 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_REJECT_CONNECTION_REQUEST (0x000A | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_LINK_KEY_REQUEST_REPLY (0x000B | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_LINK_KEY_REQUEST_NEG_REPLY (0x000C | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_PIN_CODE_REQUEST_REPLY (0x000D | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_PIN_CODE_REQUEST_NEG_REPLY (0x000E | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_CHANGE_CONN_PACKET_TYPE (0x000F | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_AUTHENTICATION_REQUESTED (0x0011 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_SET_CONN_ENCRYPTION (0x0013 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_CHANGE_CONN_LINK_KEY (0x0015 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_MASTER_LINK_KEY (0x0017 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_RMT_NAME_REQUEST (0x0019 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_RMT_NAME_REQUEST_CANCEL (0x001A | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_READ_RMT_FEATURES (0x001B | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_READ_RMT_EXT_FEATURES (0x001C | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_READ_RMT_VERSION_INFO (0x001D | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_READ_RMT_CLOCK_OFFSET (0x001F | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_READ_LMP_HANDLE (0x0020 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_SETUP_ESCO_CONNECTION (0x0028 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_ACCEPT_ESCO_CONNECTION (0x0029 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_REJECT_ESCO_CONNECTION (0x002A | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_IO_CAPABILITY_REQUEST_REPLY (0x002B | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_USER_CONF_REQUEST_REPLY (0x002C | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_USER_CONF_VALUE_NEG_REPLY (0x002D | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_USER_PASSKEY_REQ_REPLY (0x002E | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_USER_PASSKEY_REQ_NEG_REPLY (0x002F | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_REM_OOB_DATA_REQ_REPLY (0x0030 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_REM_OOB_DATA_REQ_NEG_REPLY (0x0033 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_IO_CAP_REQ_NEG_REPLY (0x0034 | HCI_GRP_LINK_CONTROL_CMDS) - -/* AMP HCI */ -#define HCI_CREATE_PHYSICAL_LINK (0x0035 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_ACCEPT_PHYSICAL_LINK (0x0036 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_DISCONNECT_PHYSICAL_LINK (0x0037 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_CREATE_LOGICAL_LINK (0x0038 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_ACCEPT_LOGICAL_LINK (0x0039 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_DISCONNECT_LOGICAL_LINK (0x003A | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_LOGICAL_LINK_CANCEL (0x003B | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_FLOW_SPEC_MODIFY (0x003C | HCI_GRP_LINK_CONTROL_CMDS) - -#define HCI_ENH_SETUP_ESCO_CONNECTION (0x003D | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_ENH_ACCEPT_ESCO_CONNECTION (0x003E | HCI_GRP_LINK_CONTROL_CMDS) - -/* ConnectionLess Broadcast */ -#define HCI_TRUNCATED_PAGE (0x003F | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_TRUNCATED_PAGE_CANCEL (0x0040 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_SET_CLB (0x0041 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_RECEIVE_CLB (0x0042 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_START_SYNC_TRAIN (0x0043 | HCI_GRP_LINK_CONTROL_CMDS) -#define HCI_RECEIVE_SYNC_TRAIN (0x0044 | HCI_GRP_LINK_CONTROL_CMDS) - -#define HCI_LINK_CTRL_CMDS_FIRST HCI_INQUIRY -#define HCI_LINK_CTRL_CMDS_LAST HCI_RECEIVE_SYNC_TRAIN - -/* Commands of HCI_GRP_LINK_POLICY_CMDS */ -#define HCI_HOLD_MODE (0x0001 | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_SNIFF_MODE (0x0003 | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_EXIT_SNIFF_MODE (0x0004 | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_PARK_MODE (0x0005 | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_EXIT_PARK_MODE (0x0006 | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_QOS_SETUP (0x0007 | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_ROLE_DISCOVERY (0x0009 | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_SWITCH_ROLE (0x000B | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_READ_POLICY_SETTINGS (0x000C | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_WRITE_POLICY_SETTINGS (0x000D | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_READ_DEF_POLICY_SETTINGS (0x000E | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_WRITE_DEF_POLICY_SETTINGS (0x000F | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_FLOW_SPECIFICATION (0x0010 | HCI_GRP_LINK_POLICY_CMDS) -#define HCI_SNIFF_SUB_RATE (0x0011 | HCI_GRP_LINK_POLICY_CMDS) - -#define HCI_LINK_POLICY_CMDS_FIRST HCI_HOLD_MODE -#define HCI_LINK_POLICY_CMDS_LAST HCI_SNIFF_SUB_RATE - -/* Commands of HCI_GRP_HOST_CONT_BASEBAND_CMDS */ -#define HCI_SET_EVENT_MASK (0x0001 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_RESET (0x0003 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_SET_EVENT_FILTER (0x0005 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_FLUSH (0x0008 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_PIN_TYPE (0x0009 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_PIN_TYPE (0x000A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_CREATE_NEW_UNIT_KEY (0x000B | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_GET_MWS_TRANS_LAYER_CFG (0x000C | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_STORED_LINK_KEY (0x000D | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_STORED_LINK_KEY (0x0011 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_DELETE_STORED_LINK_KEY (0x0012 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_CHANGE_LOCAL_NAME (0x0013 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_LOCAL_NAME (0x0014 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_CONN_ACCEPT_TOUT (0x0015 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_CONN_ACCEPT_TOUT (0x0016 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_PAGE_TOUT (0x0017 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_PAGE_TOUT (0x0018 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_SCAN_ENABLE (0x0019 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_SCAN_ENABLE (0x001A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_PAGESCAN_CFG (0x001B | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_PAGESCAN_CFG (0x001C | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_INQUIRYSCAN_CFG (0x001D | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_INQUIRYSCAN_CFG (0x001E | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_AUTHENTICATION_ENABLE (0x001F | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_AUTHENTICATION_ENABLE (0x0020 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_ENCRYPTION_MODE (0x0021 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_ENCRYPTION_MODE (0x0022 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_CLASS_OF_DEVICE (0x0023 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_CLASS_OF_DEVICE (0x0024 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_VOICE_SETTINGS (0x0025 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_VOICE_SETTINGS (0x0026 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_AUTO_FLUSH_TOUT (0x0027 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_AUTO_FLUSH_TOUT (0x0028 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_NUM_BCAST_REXMITS (0x0029 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_NUM_BCAST_REXMITS (0x002A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_HOLD_MODE_ACTIVITY (0x002B | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_HOLD_MODE_ACTIVITY (0x002C | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_TRANSMIT_POWER_LEVEL (0x002D | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_SCO_FLOW_CTRL_ENABLE (0x002E | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_SCO_FLOW_CTRL_ENABLE (0x002F | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_SET_HC_TO_HOST_FLOW_CTRL (0x0031 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_HOST_BUFFER_SIZE (0x0033 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_HOST_NUM_PACKETS_DONE (0x0035 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_LINK_SUPER_TOUT (0x0036 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_LINK_SUPER_TOUT (0x0037 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_NUM_SUPPORTED_IAC (0x0038 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_CURRENT_IAC_LAP (0x0039 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_CURRENT_IAC_LAP (0x003A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_PAGESCAN_PERIOD_MODE (0x003B | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_PAGESCAN_PERIOD_MODE (0x003C | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_PAGESCAN_MODE (0x003D | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_PAGESCAN_MODE (0x003E | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_SET_AFH_CHANNELS (0x003F | HCI_GRP_HOST_CONT_BASEBAND_CMDS) - -#define HCI_READ_INQSCAN_TYPE (0x0042 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_INQSCAN_TYPE (0x0043 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_INQUIRY_MODE (0x0044 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_INQUIRY_MODE (0x0045 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_PAGESCAN_TYPE (0x0046 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_PAGESCAN_TYPE (0x0047 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_AFH_ASSESSMENT_MODE (0x0048 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_AFH_ASSESSMENT_MODE (0x0049 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_EXT_INQ_RESPONSE (0x0051 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_EXT_INQ_RESPONSE (0x0052 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_REFRESH_ENCRYPTION_KEY (0x0053 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_SIMPLE_PAIRING_MODE (0x0055 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_SIMPLE_PAIRING_MODE (0x0056 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_LOCAL_OOB_DATA (0x0057 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_INQ_TX_POWER_LEVEL (0x0058 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_INQ_TX_POWER_LEVEL (0x0059 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_ERRONEOUS_DATA_RPT (0x005A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_ERRONEOUS_DATA_RPT (0x005B | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_ENHANCED_FLUSH (0x005F | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_SEND_KEYPRESS_NOTIF (0x0060 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) - -/* AMP HCI */ -#define HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT (0x0061 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT (0x0062 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_SET_EVENT_MASK_PAGE_2 (0x0063 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_LOCATION_DATA (0x0064 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_LOCATION_DATA (0x0065 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_FLOW_CONTROL_MODE (0x0066 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_FLOW_CONTROL_MODE (0x0067 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_BE_FLUSH_TOUT (0x0069 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_BE_FLUSH_TOUT (0x006A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_SHORT_RANGE_MODE (0x006B | HCI_GRP_HOST_CONT_BASEBAND_CMDS) /* 802.11 only */ -#define HCI_READ_LE_HOST_SUPPORT (0x006C | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_LE_HOST_SUPPORT (0x006D | HCI_GRP_HOST_CONT_BASEBAND_CMDS) - -/* MWS coexistence */ -#define HCI_SET_MWS_CHANNEL_PARAMETERS (0x006E | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_SET_EXTERNAL_FRAME_CONFIGURATION (0x006F | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_SET_MWS_SIGNALING (0x0070 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_SET_MWS_TRANSPORT_LAYER (0x0071 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_SET_MWS_SCAN_FREQUENCY_TABLE (0x0072 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_SET_MWS_PATTERN_CONFIGURATION (0x0073 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) - -/* Connectionless Broadcast */ -#define HCI_SET_RESERVED_LT_ADDR (0x0074 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_DELETE_RESERVED_LT_ADDR (0x0075 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_CLB_DATA (0x0076 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_READ_SYNC_TRAIN_PARAM (0x0077 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_SYNC_TRAIN_PARAM (0x0078 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) - -#define HCI_READ_SECURE_CONNS_SUPPORT (0x0079 | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_WRITE_SECURE_CONNS_SUPPORT (0x007A | HCI_GRP_HOST_CONT_BASEBAND_CMDS) -#define HCI_CONT_BASEBAND_CMDS_FIRST HCI_SET_EVENT_MASK -#define HCI_CONT_BASEBAND_CMDS_LAST HCI_READ_SYNC_TRAIN_PARAM - -/* Commands of HCI_GRP_INFORMATIONAL_PARAMS group */ -#define HCI_READ_LOCAL_VERSION_INFO (0x0001 | HCI_GRP_INFORMATIONAL_PARAMS) -#define HCI_READ_LOCAL_SUPPORTED_CMDS (0x0002 | HCI_GRP_INFORMATIONAL_PARAMS) -#define HCI_READ_LOCAL_FEATURES (0x0003 | HCI_GRP_INFORMATIONAL_PARAMS) -#define HCI_READ_LOCAL_EXT_FEATURES (0x0004 | HCI_GRP_INFORMATIONAL_PARAMS) -#define HCI_READ_BUFFER_SIZE (0x0005 | HCI_GRP_INFORMATIONAL_PARAMS) -#define HCI_READ_COUNTRY_CODE (0x0007 | HCI_GRP_INFORMATIONAL_PARAMS) -#define HCI_READ_BD_ADDR (0x0009 | HCI_GRP_INFORMATIONAL_PARAMS) -#define HCI_READ_DATA_BLOCK_SIZE (0x000A | HCI_GRP_INFORMATIONAL_PARAMS) -#define HCI_READ_LOCAL_SUPPORTED_CODECS (0x000B | HCI_GRP_INFORMATIONAL_PARAMS) - -#define HCI_INFORMATIONAL_CMDS_FIRST HCI_READ_LOCAL_VERSION_INFO -#define HCI_INFORMATIONAL_CMDS_LAST HCI_READ_LOCAL_SUPPORTED_CODECS - -/* Commands of HCI_GRP_STATUS_PARAMS group */ -#define HCI_READ_FAILED_CONTACT_COUNT (0x0001 | HCI_GRP_STATUS_PARAMS) -#define HCI_RESET_FAILED_CONTACT_COUNT (0x0002 | HCI_GRP_STATUS_PARAMS) -#define HCI_GET_LINK_QUALITY (0x0003 | HCI_GRP_STATUS_PARAMS) -#define HCI_READ_RSSI (0x0005 | HCI_GRP_STATUS_PARAMS) -#define HCI_READ_AFH_CH_MAP (0x0006 | HCI_GRP_STATUS_PARAMS) -#define HCI_READ_CLOCK (0x0007 | HCI_GRP_STATUS_PARAMS) -#define HCI_READ_ENCR_KEY_SIZE (0x0008 | HCI_GRP_STATUS_PARAMS) - -/* AMP HCI */ -#define HCI_READ_LOCAL_AMP_INFO (0x0009 | HCI_GRP_STATUS_PARAMS) -#define HCI_READ_LOCAL_AMP_ASSOC (0x000A | HCI_GRP_STATUS_PARAMS) -#define HCI_WRITE_REMOTE_AMP_ASSOC (0x000B | HCI_GRP_STATUS_PARAMS) - -#define HCI_STATUS_PARAMS_CMDS_FIRST HCI_READ_FAILED_CONTACT_COUNT -#define HCI_STATUS_PARAMS_CMDS_LAST HCI_WRITE_REMOTE_AMP_ASSOC - -/* Commands of HCI_GRP_TESTING_CMDS group */ -#define HCI_READ_LOOPBACK_MODE (0x0001 | HCI_GRP_TESTING_CMDS) -#define HCI_WRITE_LOOPBACK_MODE (0x0002 | HCI_GRP_TESTING_CMDS) -#define HCI_ENABLE_DEV_UNDER_TEST_MODE (0x0003 | HCI_GRP_TESTING_CMDS) -#define HCI_WRITE_SIMP_PAIR_DEBUG_MODE (0x0004 | HCI_GRP_TESTING_CMDS) - -/* AMP HCI */ -#define HCI_ENABLE_AMP_RCVR_REPORTS (0x0007 | HCI_GRP_TESTING_CMDS) -#define HCI_AMP_TEST_END (0x0008 | HCI_GRP_TESTING_CMDS) -#define HCI_AMP_TEST (0x0009 | HCI_GRP_TESTING_CMDS) - -#define HCI_TESTING_CMDS_FIRST HCI_READ_LOOPBACK_MODE -#define HCI_TESTING_CMDS_LAST HCI_AMP_TEST - -#define HCI_VENDOR_CMDS_FIRST 0x0001 -#define HCI_VENDOR_CMDS_LAST 0xFFFF -#define HCI_VSC_MULTI_AV_HANDLE 0x0AAA -#define HCI_VSC_BURST_MODE_HANDLE 0x0BBB - -/* BLE HCI */ -#define HCI_GRP_BLE_CMDS (0x08 << 10) -/* Commands of BLE Controller setup and configuration */ -#define HCI_BLE_SET_EVENT_MASK (0x0001 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_BUFFER_SIZE (0x0002 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_LOCAL_SPT_FEAT (0x0003 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_WRITE_LOCAL_SPT_FEAT (0x0004 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_WRITE_RANDOM_ADDR (0x0005 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_WRITE_ADV_PARAMS (0x0006 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_ADV_CHNL_TX_POWER (0x0007 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_WRITE_ADV_DATA (0x0008 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_WRITE_SCAN_RSP_DATA (0x0009 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_WRITE_ADV_ENABLE (0x000A | HCI_GRP_BLE_CMDS) -#define HCI_BLE_WRITE_SCAN_PARAMS (0x000B | HCI_GRP_BLE_CMDS) -#define HCI_BLE_WRITE_SCAN_ENABLE (0x000C | HCI_GRP_BLE_CMDS) -#define HCI_BLE_CREATE_LL_CONN (0x000D | HCI_GRP_BLE_CMDS) -#define HCI_BLE_CREATE_CONN_CANCEL (0x000E | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_WHITE_LIST_SIZE (0x000F | HCI_GRP_BLE_CMDS) -#define HCI_BLE_CLEAR_WHITE_LIST (0x0010 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_ADD_WHITE_LIST (0x0011 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_REMOVE_WHITE_LIST (0x0012 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_UPD_LL_CONN_PARAMS (0x0013 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_SET_HOST_CHNL_CLASS (0x0014 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_CHNL_MAP (0x0015 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_REMOTE_FEAT (0x0016 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_ENCRYPT (0x0017 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_RAND (0x0018 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_START_ENC (0x0019 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_LTK_REQ_REPLY (0x001A | HCI_GRP_BLE_CMDS) -#define HCI_BLE_LTK_REQ_NEG_REPLY (0x001B | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_SUPPORTED_STATES (0x001C | HCI_GRP_BLE_CMDS) -/*0x001D, 0x001E and 0x001F are reserved*/ -#define HCI_BLE_RECEIVER_TEST (0x001D | HCI_GRP_BLE_CMDS) -#define HCI_BLE_TRANSMITTER_TEST (0x001E | HCI_GRP_BLE_CMDS) -/* BLE TEST COMMANDS */ -#define HCI_BLE_TEST_END (0x001F | HCI_GRP_BLE_CMDS) -#define HCI_BLE_RC_PARAM_REQ_REPLY (0x0020 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_RC_PARAM_REQ_NEG_REPLY (0x0021 | HCI_GRP_BLE_CMDS) - -#define HCI_BLE_SET_DATA_LENGTH (0x0022 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_DEFAULT_DATA_LENGTH (0x0023 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_WRITE_DEFAULT_DATA_LENGTH (0x0024 | HCI_GRP_BLE_CMDS) - -#define HCI_BLE_ADD_DEV_RESOLVING_LIST (0x0027 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_RM_DEV_RESOLVING_LIST (0x0028 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_CLEAR_RESOLVING_LIST (0x0029 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_RESOLVING_LIST_SIZE (0x002A | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_RESOLVABLE_ADDR_PEER (0x002B | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_RESOLVABLE_ADDR_LOCAL (0x002C | HCI_GRP_BLE_CMDS) -#define HCI_BLE_SET_ADDR_RESOLUTION_ENABLE (0x002D | HCI_GRP_BLE_CMDS) -#define HCI_BLE_SET_RAND_PRIV_ADDR_TIMOUT (0x002E | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_MAXIMUM_DATA_LENGTH (0x002F | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_PHY (0x0030 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_SET_DEFAULT_PHY (0x0031 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_SET_PHY (0x0032 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_ENH_RECEIVER_TEST (0x0033 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_ENH_TRANSMITTER_TEST (0x0034 | HCI_GRP_BLE_CMDS) -#define HCI_LE_SET_EXT_ADVERTISING_RANDOM_ADDRESS (0x35 | HCI_GRP_BLE_CMDS) -#define HCI_LE_SET_EXT_ADVERTISING_PARAM (0x36 | HCI_GRP_BLE_CMDS) -#define HCI_LE_SET_EXT_ADVERTISING_DATA (0x37 | HCI_GRP_BLE_CMDS) -#define HCI_LE_SET_EXT_ADVERTISING_SCAN_RESP (0x38 | HCI_GRP_BLE_CMDS) -#define HCI_LE_SET_EXT_ADVERTISING_ENABLE (0x39 | HCI_GRP_BLE_CMDS) -#define HCI_LE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH (0x003A | HCI_GRP_BLE_CMDS) -#define HCI_LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS \ - (0x003B | HCI_GRP_BLE_CMDS) -#define HCI_LE_REMOVE_ADVERTISING_SET (0x003C | HCI_GRP_BLE_CMDS) -#define HCI_LE_CLEAR_ADVERTISING_SETS (0x003D | HCI_GRP_BLE_CMDS) -#define HCI_LE_SET_PERIODIC_ADVERTISING_PARAM (0x003E | HCI_GRP_BLE_CMDS) -#define HCI_LE_SET_PERIODIC_ADVERTISING_DATA (0x003F | HCI_GRP_BLE_CMDS) -#define HCI_LE_SET_PERIODIC_ADVERTISING_ENABLE (0x0040 | HCI_GRP_BLE_CMDS) -#define HCI_LE_SET_EXTENDED_SCAN_PARAMETERS (0x0041 | HCI_GRP_BLE_CMDS) -#define HCI_LE_SET_EXTENDED_SCAN_ENABLE (0x0042 | HCI_GRP_BLE_CMDS) -#define HCI_LE_EXTENDED_CREATE_CONNECTION (0x0043 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_PERIODIC_ADVERTISING_CREATE_SYNC (0x0044 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL \ - (0x0045 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_PERIODIC_ADVERTISING_TERMINATE_SYNC \ - (0x0046 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_ADD_DEVICE_TO_PERIODIC_ADVERTISING_LIST \ - (0x0047 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_RM_DEVICE_FROM_PERIODIC_ADVERTISING_LIST \ - (0x0048 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_CLEAR_PERIODIC_ADVERTISING_LIST (0x0049 | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_PERIODIC_ADVERTISING_LIST_SIZE (0x004A | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_TRANSMIT_POWER (0x004B | HCI_GRP_BLE_CMDS) -#define HCI_BLE_READ_RF_COMPENS_POWER (0x004C | HCI_GRP_BLE_CMDS) -#define HCI_BLE_WRITE_RF_COMPENS_POWER (0x004D | HCI_GRP_BLE_CMDS) -#define HCI_BLE_SET_PRIVACY_MODE (0x004E | HCI_GRP_BLE_CMDS) - -/* LE Get Vendor Capabilities Command OCF */ -#define HCI_BLE_VENDOR_CAP_OCF (0x0153 | HCI_GRP_VENDOR_SPECIFIC) - -/* Multi adv OCF */ -#define HCI_BLE_MULTI_ADV_OCF (0x0154 | HCI_GRP_VENDOR_SPECIFIC) - -/* Batch scan OCF */ -#define HCI_BLE_BATCH_SCAN_OCF (0x0156 | HCI_GRP_VENDOR_SPECIFIC) - -/* ADV filter OCF */ -#define HCI_BLE_ADV_FILTER_OCF (0x0157 | HCI_GRP_VENDOR_SPECIFIC) - -/* Tracking OCF */ -#define HCI_BLE_TRACK_ADV_OCF (0x0158 | HCI_GRP_VENDOR_SPECIFIC) - -/* Energy info OCF */ -#define HCI_BLE_ENERGY_INFO_OCF (0x0159 | HCI_GRP_VENDOR_SPECIFIC) - -/* Extended BLE Scan parameters OCF */ -#define HCI_BLE_EXTENDED_SCAN_PARAMS_OCF (0x015A | HCI_GRP_VENDOR_SPECIFIC) - -/* Controller debug info OCF */ -#define HCI_CONTROLLER_DEBUG_INFO_OCF (0x015B | HCI_GRP_VENDOR_SPECIFIC) - -/* subcode for multi adv feature */ -#define BTM_BLE_MULTI_ADV_SET_PARAM 0x01 -#define BTM_BLE_MULTI_ADV_WRITE_ADV_DATA 0x02 -#define BTM_BLE_MULTI_ADV_WRITE_SCAN_RSP_DATA 0x03 -#define BTM_BLE_MULTI_ADV_SET_RANDOM_ADDR 0x04 -#define BTM_BLE_MULTI_ADV_ENB 0x05 - -/* multi adv VSE subcode */ -#define HCI_VSE_SUBCODE_BLE_MULTI_ADV_ST_CHG 0x55 /* multi adv instance state change */ - -/* subcode for batch scan feature */ -#define BTM_BLE_BATCH_SCAN_ENB_DISAB_CUST_FEATURE 0x01 -#define BTM_BLE_BATCH_SCAN_SET_STORAGE_PARAM 0x02 -#define BTM_BLE_BATCH_SCAN_SET_PARAMS 0x03 -#define BTM_BLE_BATCH_SCAN_READ_RESULTS 0x04 - -/* batch scan VSE subcode */ -#define HCI_VSE_SUBCODE_BLE_THRESHOLD_SUB_EVT 0x54 /* Threshold event */ - -/* tracking sub event */ -#define HCI_VSE_SUBCODE_BLE_TRACKING_SUB_EVT 0x56 /* Tracking event */ - -/* debug info sub event */ -#define HCI_VSE_SUBCODE_DEBUG_INFO_SUB_EVT 0x57 - -/* LE supported states definition */ -#define HCI_LE_ADV_STATE 0x00000001 -#define HCI_LE_SCAN_STATE 0x00000002 -#define HCI_LE_INIT_STATE 0x00000004 -#define HCI_LE_CONN_SL_STATE 0x00000008 -#define HCI_LE_ADV_SCAN_STATE 0x00000010 -#define HCI_LE_ADV_INIT_STATE 0x00000020 -#define HCI_LE_ADV_MA_STATE 0x00000040 -#define HCI_LE_ADV_SL_STATE 0x00000080 -#define HCI_LE_SCAN_INIT_STATE 0x00000100 -#define HCI_LE_SCAN_MA_STATE 0x00000200 -#define HCI_LE_SCAN_SL_STATE 0x00000400 -#define HCI_LE_INIT_MA_STATE 0x00000800 - -/* LE Supported States */ -/* Non Connectable Adv state is supported. 0x0000000000000001 */ -#define HCI_SUPP_LE_STATES_NON_CONN_ADV_MASK 0x01 -#define HCI_SUPP_LE_STATES_NON_CONN_ADV_OFF 0 -#define HCI_LE_STATES_NON_CONN_ADV_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_NON_CONN_ADV_OFF] & HCI_SUPP_LE_STATES_NON_CONN_ADV_MASK) - -/*Scanneable Connectable Adv state is supported. 0x0000000000000002 */ -#define HCI_SUPP_LE_STATES_SCAN_ADV_MASK 0x02 -#define HCI_SUPP_LE_STATESSCAN_ADV_OFF 0 -#define HCI_LE_STATES_SCAN_ADV_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATESSCAN_ADV_OFF] & HCI_SUPP_LE_STATES_SCAN_ADV_MASK) - -/* Connectable Adv state is supported. 0x0000000000000004 */ -#define HCI_SUPP_LE_STATES_CONN_ADV_MASK 0x04 -#define HCI_SUPP_LE_STATES_CONN_ADV_OFF 0 -#define HCI_LE_STATES_CONN_ADV_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_CONN_ADV_OFF] & HCI_SUPP_LE_STATES_CONN_ADV_MASK) - -/* Hi duty Cycle Directed Adv state is supported. 0x0000000000000008 */ -#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASK 0x08 -#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_OFF 0 -#define HCI_LE_STATES_HI_DUTY_DIR_ADV_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_OFF] & HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASK) - -/* Passive Scan state is supported. 0x0000000000000010 */ -#define HCI_SUPP_LE_STATES_PASS_SCAN_MASK 0x10 -#define HCI_SUPP_LE_STATES_PASS_SCAN_OFF 0 -#define HCI_LE_STATES_PASS_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_PASS_SCAN_OFF] & HCI_SUPP_LE_STATES_PASS_SCAN_MASK) - -/* Active Scan state is supported. 0x0000000000000020 */ -#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASK 0x20 -#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_OFF 0 -#define HCI_LE_STATES_ACTIVE_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_ACTIVE_SCAN_OFF] & HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASK) - -/* Initiating state is supported. 0x0000000000000040 (or connection state in master role is also supported) */ -#define HCI_SUPP_LE_STATES_INIT_MASK 0x40 -#define HCI_SUPP_LE_STATES_INIT_OFF 0 -#define HCI_LE_STATES_INIT_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_INIT_OFF] & HCI_SUPP_LE_STATES_INIT_MASK) - -/*connection state in slave role is also supported. 0x0000000000000080 */ -#define HCI_SUPP_LE_STATES_SLAVE_MASK 0x80 -#define HCI_SUPP_LE_STATES_SLAVE_OFF 0 -#define HCI_LE_STATES_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_SLAVE_OFF] & HCI_SUPP_LE_STATES_SLAVE_MASK) - -/* Non Connectable Adv state and Passive Scanning State combination is supported. 0x0000000000000100 */ -#define HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_MASK 0x01 -#define HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_OFF 1 -#define HCI_LE_STATES_NON_CONN_ADV_PASS_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_OFF] & HCI_SUPP_LE_STATES_NON_CONN_ADV_PASS_SCAN_MASK) - -/*Scannable Adv state and Passive Scanning State combination is supported. 0x0000000000000200 */ -#define HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_MASK 0x02 -#define HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_OFF 1 -#define HCI_LE_STATES_SCAN_ADV_PASS_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_OFF] & HCI_SUPP_LE_STATES_SCAN_ADV_PASS_SCAN_MASK) - -/*Connectable Adv state and Passive Scanning State combination is supported. 0x0000000000000400 */ -#define HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_MASK 0x04 -#define HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_OFF 1 -#define HCI_LE_STATES_CONN_ADV_PASS_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_OFF] & HCI_SUPP_LE_STATES_CONN_ADV_PASS_SCAN_MASK) - -/*High Duty Cycl Directed ADv and Passive Scanning State combination is supported. 0x0000000000000800 */ -#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_MASK 0x08 -#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_OFF 1 -#define HCI_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_MASK] & HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_PASS_SCAN_OFF) - -/*Non Connectable Adv state and Passive Scanning State combination is supported. 0x0000000000001000 */ -#define HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_MASK 0x10 -#define HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_OFF 1 -#define HCI_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_OFF] & HCI_SUPP_LE_STATES_NON_CONN_ADV_ACTIVE_SCAN_MASK) - -/*Scannable Adv state and Active Scanning State combination is supported. 0x0000000000002000 */ -#define HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_MASK 0x20 -#define HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_OFF 1 -#define HCI_LE_STATES_SCAN_ADV_ACTIVE_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_OFF] & HCI_SUPP_LE_STATES_SCAN_ADV_ACTIVE_SCAN_MASK) - -/*Connectable Adv state and Active Scanning State combination is supported. 0x0000000000004000 */ -#define HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_MASK 0x40 -#define HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_OFF 1 -#define HCI_LE_STATES_CONN_ADV_ACTIVE_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_OFF] & HCI_SUPP_LE_STATES_CONN_ADV_ACTIVE_SCAN_MASK) - -/*High Duty Cycl Directed ADv and ACtive Scanning State combination is supported. 0x0000000000008000 */ -#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_MASK 0x80 -#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_OFF 1 -#define HCI_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_MASK] & HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_ACTIVE_SCAN_OFF) - -/*Non-Connectable Adv state and Initiating State combination is supported. 0x0000000000010000 */ -#define HCI_SUPP_LE_STATES_NON_CONN_INIT_MASK 0x01 -#define HCI_SUPP_LE_STATES_NON_CONN_INIT_OFF 2 -#define HCI_LE_STATES_NON_CONN_INIT_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_NON_CONN_INIT_OFF] & HCI_SUPP_LE_STATES_NON_CONN_INIT_MASK) - -/* Scannable Adv state and Initiating State combination is supported. 0x0000000000020000 */ -#define HCI_SUPP_LE_STATES_SCAN_ADV_INIT_MASK 0x02 -#define HCI_SUPP_LE_STATES_SCAN_ADV_INIT_OFF 2 -#define HCI_LE_STATES_SCAN_ADV_INIT_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_SCAN_ADV_INIT_OFF] & HCI_SUPP_LE_STATES_SCAN_ADV_INIT_MASK) - -/* Non-Connectable Adv state and Master Role combination is supported. 0x0000000000040000 */ -#define HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_MASK 0x04 -#define HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_OFF 2 -#define HCI_LE_STATES_NON_CONN_ADV_MASTER_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_OFF] & HCI_SUPP_LE_STATES_NON_CONN_ADV_MASTER_MASK) - -/*Scannable Adv state and Master Role combination is supported. 0x0000000000040000 */ -#define HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_MASK 0x08 -#define HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_OFF 2 -#define HCI_LE_STATES_SCAN_ADV_MASTER_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_OFF] & HCI_SUPP_LE_STATES_SCAN_ADV_MASTER_MASK) - -/* Non-Connectable Adv and Slave Role combination is supported. 0x000000000100000 */ -#define HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_MASK 0x10 -#define HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_OFF 2 -#define HCI_LE_STATES_NON_CONN_ADV_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_OFF] & HCI_SUPP_LE_STATES_NON_CONN_ADV_SLAVE_MASK) - -/*Scannable Adv and Slave Role combination is supported. 0x000000000200000 */ -#define HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_MASK 0x20 -#define HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_OFF 2 -#define HCI_LE_STATES_SCAN_ADV_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_OFF] & HCI_SUPP_LE_STATES_SCAN_ADV_SLAVE_MASK) - -/*Passive Scan and Initiating State combination is supported. 0x000000000400000 */ -#define HCI_SUPP_LE_STATES_PASS_SCAN_INIT_MASK 0x40 -#define HCI_SUPP_LE_STATES_PASS_SCAN_INIT_OFF 2 -#define HCI_LE_STATES_PASS_SCAN_INIT_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_PASS_SCAN_INIT_OFF] & HCI_SUPP_LE_STATES_PASS_SCAN_INIT_MASK) - -/*Active Scan and Initiating State combination is supported. 0x000000000800000 */ -#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_MASK 0x80 -#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_OFF 2 -#define HCI_LE_STATES_ACTIVE_SCAN_INIT_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_OFF] & HCI_SUPP_LE_STATES_ACTIVE_SCAN_INIT_MASK) - -/*Passive Scan and Master Role combination is supported. 0x000000001000000 */ -#define HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_MASK 0x01 -#define HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_OFF 3 -#define HCI_LE_STATES_PASS_SCAN_MASTER_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_OFF] & HCI_SUPP_LE_STATES_PASS_SCAN_MASTER_MASK) - -/*Active Scan and Master Role combination is supported. 0x000000002000000 */ -#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_MASK 0x02 -#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_OFF 3 -#define HCI_LE_STATES_ACTIVE_SCAN_MASTER_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_OFF] & HCI_SUPP_LE_STATES_ACTIVE_SCAN_MASTER_MASK) - -/*Passive Scan and Slave Role combination is supported. 0x000000004000000 */ -#define HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_MASK 0x04 -#define HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_OFF 3 -#define HCI_LE_STATES_PASS_SCAN_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_OFF] & HCI_SUPP_LE_STATES_PASS_SCAN_SLAVE_MASK) - -/*Active Scan and Slave Role combination is supported. 0x000000008000000 */ -#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_MASK 0x08 -#define HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_OFF 3 -#define HCI_LE_STATES_ACTIVE_SCAN_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_OFF] & HCI_SUPP_LE_STATES_ACTIVE_SCAN_SLAVE_MASK) - -/*Link Layer Topology Added States Combo */ -/*Initiating State and Master Role combination supported. - Master Role and Master Role combination is also supported. 0x0000000010000000 */ -#define HCI_SUPP_LE_STATES_INIT_MASTER_MASK 0x10 -#define HCI_SUPP_LE_STATES_INIT_MASTER_OFF 3 -#define HCI_LE_STATES_INIT_MASTER_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_INIT_MASTER_OFF] & HCI_SUPP_LE_STATES_INIT_MASTER_MASK) - -/*Low Duty Cycle Directed Advertising State . 0x0000000020000000 */ -#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASK 0x20 -#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_OFF 3 -#define HCI_LE_STATES_LOW_DUTY_DIR_ADV_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_LOW_DUTY_DIR_ADV_OFF] & HCI_SUPP_LE_STATES_LOW_DUTY_DIR_ADV_MASK) - -/*Low Duty Cycle Directed Advertising State and Passive scan combination. 0x0000000040000000 */ -#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_PASS_SCAN_MASK 0x40 -#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_PASS_SCAN_OFF 3 -#define HCI_LE_STATES_LO_DUTY_DIR_ADV_PASS_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_PASS_SCAN_OFF] & HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_PASS_SCAN_MASK) - -/*Low Duty Cycle Directed Advertising State and Active scan combination . 0x0000000080000000 */ -#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_ACTIVE_SCAN_MASK 0x80 -#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_ACTIVE_SCAN_OFF 3 -#define HCI_LE_STATES_LO_DUTY_DIR_ADV_ACTIVE_SCAN_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_ACTIVE_SCAN_OFF] & HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_ACTIVE_SCAN_MASK) - -/* Connectable Advertising State and Initiating State combination supported. 0x0000000100000000 */ -#define HCI_SUPP_LE_STATES_CONN_ADV_INIT_MASK 0x01 -#define HCI_SUPP_LE_STATES_CONN_ADV_INIT_OFF 4 -#define HCI_LE_STATES_CONN_ADV_INIT_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_CONN_ADV_INIT_OFF] & HCI_SUPP_LE_STATES_CONN_ADV_INIT_MASK) - -/* High Duty Cycle Directed Advertising State and Initiating State combination supported. */ -#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_MASK 0x02 -#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_OFF 4 -#define HCI_LE_STATES_HI_DUTY_DIR_ADV_INIT_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_OFF] & HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_INIT_MASK) - -/* Low Duty Cycle Directed Advertising State and Initiating State combination supported.*/ -#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_MASK 0x04 -#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_OFF 4 -#define HCI_LE_STATES_LO_DUTY_DIR_ADV_INIT_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_OFF] & HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_INIT_MASK) - -/* Connectable Advertising State and Master Role combination supported.*/ -#define HCI_SUPP_LE_STATES_CONN_ADV_MASTER_MASK 0x08 -#define HCI_SUPP_LE_STATES_CONN_ADV_MASTER_OFF 4 -#define HCI_LE_STATES_CONN_ADV_MASTER_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_CONN_ADV_MASTER_OFF] & HCI_SUPP_LE_STATES_CONN_ADV_MASTER_MASK) - -/* High Duty Cycle Directed Advertising State and Master Role combination supported.*/ -#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_MASK 0x10 -#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_OFF 4 -#define HCI_LE_STATES_HI_DUTY_DIR_ADV_MASTER_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_OFF] & HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_MASTER_MASK) - -/* Low Duty Cycle Directed Advertising State and Master Role combination supported.*/ -#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_MASK 0x20 -#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_OFF 4 -#define HCI_LE_STATES_LO_DUTY_DIR_ADV_MASTER_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_OFF] & HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_MASTER_MASK) - -/* Connectable Advertising State and Slave Role combination supported. */ -#define HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_MASK 0x40 -#define HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_OFF 4 -#define HCI_LE_STATES_CONN_ADV_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_OFF] & HCI_SUPP_LE_STATES_CONN_ADV_SLAVE_MASK) - -/* High Duty Cycle Directed Advertising State and slave Role combination supported.*/ -#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_MASK 0x80 -#define HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_OFF 4 -#define HCI_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_OFF] & HCI_SUPP_LE_STATES_HI_DUTY_DIR_ADV_SLAVE_MASK) - -/* Low Duty Cycle Directed Advertising State and slave Role combination supported.*/ -#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_MASK 0x01 -#define HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_OFF 5 -#define HCI_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_OFF] & HCI_SUPP_LE_STATES_LO_DUTY_DIR_ADV_SLAVE_MASK) - -/* Initiating State and Slave Role combination supported. - Master Role and Slave Role combination also supported. - */ -#define HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_MASK 0x02 -#define HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_OFF 5 -#define HCI_LE_STATES_INIT_MASTER_SLAVE_SUPPORTED(x) ((x)[HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_OFF] & HCI_SUPP_LE_STATES_INIT_MASTER_SLAVE_MASK) - -/* -** Definitions for HCI Events -*/ -#define HCI_INQUIRY_COMP_EVT 0x01 -#define HCI_INQUIRY_RESULT_EVT 0x02 -#define HCI_CONNECTION_COMP_EVT 0x03 -#define HCI_CONNECTION_REQUEST_EVT 0x04 -#define HCI_DISCONNECTION_COMP_EVT 0x05 -#define HCI_AUTHENTICATION_COMP_EVT 0x06 -#define HCI_RMT_NAME_REQUEST_COMP_EVT 0x07 -#define HCI_ENCRYPTION_CHANGE_EVT 0x08 -#define HCI_CHANGE_CONN_LINK_KEY_EVT 0x09 -#define HCI_MASTER_LINK_KEY_COMP_EVT 0x0A -#define HCI_READ_RMT_FEATURES_COMP_EVT 0x0B -#define HCI_READ_RMT_VERSION_COMP_EVT 0x0C -#define HCI_QOS_SETUP_COMP_EVT 0x0D -#define HCI_COMMAND_COMPLETE_EVT 0x0E -#define HCI_COMMAND_STATUS_EVT 0x0F -#define HCI_HARDWARE_ERROR_EVT 0x10 -#define HCI_FLUSH_OCCURED_EVT 0x11 -#define HCI_ROLE_CHANGE_EVT 0x12 -#define HCI_NUM_COMPL_DATA_PKTS_EVT 0x13 -#define HCI_MODE_CHANGE_EVT 0x14 -#define HCI_RETURN_LINK_KEYS_EVT 0x15 -#define HCI_PIN_CODE_REQUEST_EVT 0x16 -#define HCI_LINK_KEY_REQUEST_EVT 0x17 -#define HCI_LINK_KEY_NOTIFICATION_EVT 0x18 -#define HCI_LOOPBACK_COMMAND_EVT 0x19 -#define HCI_DATA_BUF_OVERFLOW_EVT 0x1A -#define HCI_MAX_SLOTS_CHANGED_EVT 0x1B -#define HCI_READ_CLOCK_OFF_COMP_EVT 0x1C -#define HCI_CONN_PKT_TYPE_CHANGE_EVT 0x1D -#define HCI_QOS_VIOLATION_EVT 0x1E -#define HCI_PAGE_SCAN_MODE_CHANGE_EVT 0x1F -#define HCI_PAGE_SCAN_REP_MODE_CHNG_EVT 0x20 -#define HCI_FLOW_SPECIFICATION_COMP_EVT 0x21 -#define HCI_INQUIRY_RSSI_RESULT_EVT 0x22 -#define HCI_READ_RMT_EXT_FEATURES_COMP_EVT 0x23 -#define HCI_ESCO_CONNECTION_COMP_EVT 0x2C -#define HCI_ESCO_CONNECTION_CHANGED_EVT 0x2D -#define HCI_SNIFF_SUB_RATE_EVT 0x2E -#define HCI_EXTENDED_INQUIRY_RESULT_EVT 0x2F -#define HCI_ENCRYPTION_KEY_REFRESH_COMP_EVT 0x30 -#define HCI_IO_CAPABILITY_REQUEST_EVT 0x31 -#define HCI_IO_CAPABILITY_RESPONSE_EVT 0x32 -#define HCI_USER_CONFIRMATION_REQUEST_EVT 0x33 -#define HCI_USER_PASSKEY_REQUEST_EVT 0x34 -#define HCI_REMOTE_OOB_DATA_REQUEST_EVT 0x35 -#define HCI_SIMPLE_PAIRING_COMPLETE_EVT 0x36 -#define HCI_LINK_SUPER_TOUT_CHANGED_EVT 0x38 -#define HCI_ENHANCED_FLUSH_COMPLETE_EVT 0x39 -#define HCI_USER_PASSKEY_NOTIFY_EVT 0x3B -#define HCI_KEYPRESS_NOTIFY_EVT 0x3C -#define HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT 0x3D - -/*#define HCI_GENERIC_AMP_LINK_KEY_NOTIF_EVT 0x3E Removed from spec */ -#define HCI_PHYSICAL_LINK_COMP_EVT 0x40 -#define HCI_CHANNEL_SELECTED_EVT 0x41 -#define HCI_DISC_PHYSICAL_LINK_COMP_EVT 0x42 -#define HCI_PHY_LINK_LOSS_EARLY_WARNING_EVT 0x43 -#define HCI_PHY_LINK_RECOVERY_EVT 0x44 -#define HCI_LOGICAL_LINK_COMP_EVT 0x45 -#define HCI_DISC_LOGICAL_LINK_COMP_EVT 0x46 -#define HCI_FLOW_SPEC_MODIFY_COMP_EVT 0x47 -#define HCI_NUM_COMPL_DATA_BLOCKS_EVT 0x48 -#define HCI_SHORT_RANGE_MODE_COMPLETE_EVT 0x4C -#define HCI_AMP_STATUS_CHANGE_EVT 0x4D -#define HCI_SET_TRIGGERED_CLOCK_CAPTURE_EVT 0x4E -#ifdef BLUETOOTH_RTK_API -#define HCI_SL_PAGE_RESPONSE_TO_EVT 0x54 -#define HCI_CONNLESS_SL_BC_TO_EVT 0x52 -#endif - -/* ULP HCI Event */ -#define HCI_BLE_EVENT 0x3e -/* ULP Event sub code */ -#define HCI_BLE_CONN_COMPLETE_EVT 0x01 -#define HCI_BLE_ADV_PKT_RPT_EVT 0x02 -#define HCI_BLE_LL_CONN_PARAM_UPD_EVT 0x03 -#define HCI_BLE_READ_REMOTE_FEAT_CMPL_EVT 0x04 -#define HCI_BLE_LTK_REQ_EVT 0x05 -#define HCI_BLE_RC_PARAM_REQ_EVT 0x06 -#define HCI_BLE_DATA_LENGTH_CHANGE_EVT 0x07 -#define HCI_BLE_ENHANCED_CONN_COMPLETE_EVT 0x0a -#define HCI_BLE_DIRECT_ADV_EVT 0x0b - -/* Definitions for LE Channel Map */ -#define HCI_BLE_CHNL_MAP_SIZE 5 - -#define HCI_VENDOR_SPECIFIC_EVT 0xFF /* Vendor specific events */ -#define HCI_NAP_TRACE_EVT 0xFF /* was define 0xFE, 0xFD, change to 0xFF \ - because conflict w/ TCI_EVT and per \ - specification compliant */ - -/* -** Defentions for HCI Error Codes that are past in the events -*/ -#define HCI_SUCCESS 0x00 -#define HCI_PENDING 0x00 -#define HCI_ERR_ILLEGAL_COMMAND 0x01 -#define HCI_ERR_NO_CONNECTION 0x02 -#define HCI_ERR_HW_FAILURE 0x03 -#define HCI_ERR_PAGE_TIMEOUT 0x04 -#define HCI_ERR_AUTH_FAILURE 0x05 -#define HCI_ERR_KEY_MISSING 0x06 -#define HCI_ERR_MEMORY_FULL 0x07 -#define HCI_ERR_CONNECTION_TOUT 0x08 -#define HCI_ERR_MAX_NUM_OF_CONNECTIONS 0x09 -#define HCI_ERR_MAX_NUM_OF_SCOS 0x0A -#define HCI_ERR_CONNECTION_EXISTS 0x0B -#define HCI_ERR_COMMAND_DISALLOWED 0x0C -#define HCI_ERR_HOST_REJECT_RESOURCES 0x0D -#define HCI_ERR_HOST_REJECT_SECURITY 0x0E -#define HCI_ERR_HOST_REJECT_DEVICE 0x0F -#define HCI_ERR_HOST_TIMEOUT 0x10 -#define HCI_ERR_UNSUPPORTED_VALUE 0x11 -#define HCI_ERR_ILLEGAL_PARAMETER_FMT 0x12 -#define HCI_ERR_PEER_USER 0x13 -#define HCI_ERR_PEER_LOW_RESOURCES 0x14 -#define HCI_ERR_PEER_POWER_OFF 0x15 -#define HCI_ERR_CONN_CAUSE_LOCAL_HOST 0x16 -#define HCI_ERR_REPEATED_ATTEMPTS 0x17 -#define HCI_ERR_PAIRING_NOT_ALLOWED 0x18 -#define HCI_ERR_UNKNOWN_LMP_PDU 0x19 -#define HCI_ERR_UNSUPPORTED_REM_FEATURE 0x1A -#define HCI_ERR_SCO_OFFSET_REJECTED 0x1B -#define HCI_ERR_SCO_INTERVAL_REJECTED 0x1C -#define HCI_ERR_SCO_AIR_MODE 0x1D -#define HCI_ERR_INVALID_LMP_PARAM 0x1E -#define HCI_ERR_UNSPECIFIED 0x1F -#define HCI_ERR_UNSUPPORTED_LMP_FEATURE 0x20 -#define HCI_ERR_ROLE_CHANGE_NOT_ALLOWED 0x21 -#define HCI_ERR_LMP_RESPONSE_TIMEOUT 0x22 -#define HCI_ERR_LMP_ERR_TRANS_COLLISION 0x23 -#define HCI_ERR_LMP_PDU_NOT_ALLOWED 0x24 -#define HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE 0x25 -#define HCI_ERR_UNIT_KEY_USED 0x26 -#define HCI_ERR_QOS_NOT_SUPPORTED 0x27 -#define HCI_ERR_INSTANT_PASSED 0x28 -#define HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED 0x29 -#define HCI_ERR_DIFF_TRANSACTION_COLLISION 0x2A -#define HCI_ERR_UNDEFINED_0x2B 0x2B -#define HCI_ERR_QOS_UNACCEPTABLE_PARAM 0x2C -#define HCI_ERR_QOS_REJECTED 0x2D -#define HCI_ERR_CHAN_CLASSIF_NOT_SUPPORTED 0x2E -#define HCI_ERR_INSUFFCIENT_SECURITY 0x2F -#define HCI_ERR_PARAM_OUT_OF_RANGE 0x30 -#define HCI_ERR_UNDEFINED_0x31 0x31 -#define HCI_ERR_ROLE_SWITCH_PENDING 0x32 -#define HCI_ERR_UNDEFINED_0x33 0x33 -#define HCI_ERR_RESERVED_SLOT_VIOLATION 0x34 -#define HCI_ERR_ROLE_SWITCH_FAILED 0x35 -#define HCI_ERR_INQ_RSP_DATA_TOO_LARGE 0x36 -#define HCI_ERR_SIMPLE_PAIRING_NOT_SUPPORTED 0x37 -#define HCI_ERR_HOST_BUSY_PAIRING 0x38 -#define HCI_ERR_REJ_NO_SUITABLE_CHANNEL 0x39 -#define HCI_ERR_CONTROLLER_BUSY 0x3A -#define HCI_ERR_UNACCEPT_CONN_INTERVAL 0x3B -#define HCI_ERR_DIRECTED_ADVERTISING_TIMEOUT 0x3C -#define HCI_ERR_CONN_TOUT_DUE_TO_MIC_FAILURE 0x3D -#define HCI_ERR_CONN_FAILED_ESTABLISHMENT 0x3E -#define HCI_ERR_MAC_CONNECTION_FAILED 0x3F - -/* ConnectionLess Broadcast errors */ -#define HCI_ERR_LT_ADDR_ALREADY_IN_USE 0x40 -#define HCI_ERR_LT_ADDR_NOT_ALLOCATED 0x41 -#define HCI_ERR_CLB_NOT_ENABLED 0x42 -#define HCI_ERR_CLB_DATA_TOO_BIG 0x43 - -#define HCI_ERR_MAX_ERR 0x43 - -#define HCI_HINT_TO_RECREATE_AMP_PHYS_LINK 0xFF - -/* -** Definitions for HCI enable event -*/ -#define HCI_INQUIRY_COMPLETE_EV(p) (*((uint32_t *)(p)) & 0x00000001) -#define HCI_INQUIRY_RESULT_EV(p) (*((uint32_t *)(p)) & 0x00000002) -#define HCI_CONNECTION_COMPLETE_EV(p) (*((uint32_t *)(p)) & 0x00000004) -#define HCI_CONNECTION_REQUEST_EV(p) (*((uint32_t *)(p)) & 0x00000008) -#define HCI_DISCONNECTION_COMPLETE_EV(p) (*((uint32_t *)(p)) & 0x00000010) -#define HCI_AUTHENTICATION_COMPLETE_EV(p) (*((uint32_t *)(p)) & 0x00000020) -#define HCI_RMT_NAME_REQUEST_COMPL_EV(p) (*((uint32_t *)(p)) & 0x00000040) -#define HCI_CHANGE_CONN_ENCRPT_ENABLE_EV(p) (*((uint32_t *)(p)) & 0x00000080) -#define HCI_CHANGE_CONN_LINK_KEY_EV(p) (*((uint32_t *)(p)) & 0x00000100) -#define HCI_MASTER_LINK_KEY_COMPLETE_EV(p) (*((uint32_t *)(p)) & 0x00000200) -#define HCI_READ_RMT_FEATURES_COMPL_EV(p) (*((uint32_t *)(p)) & 0x00000400) -#define HCI_READ_RMT_VERSION_COMPL_EV(p) (*((uint32_t *)(p)) & 0x00000800) -#define HCI_QOS_SETUP_COMPLETE_EV(p) (*((uint32_t *)(p)) & 0x00001000) -#define HCI_COMMAND_COMPLETE_EV(p) (*((uint32_t *)(p)) & 0x00002000) -#define HCI_COMMAND_STATUS_EV(p) (*((uint32_t *)(p)) & 0x00004000) -#define HCI_HARDWARE_ERROR_EV(p) (*((uint32_t *)(p)) & 0x00008000) -#define HCI_FLASH_OCCURED_EV(p) (*((uint32_t *)(p)) & 0x00010000) -#define HCI_ROLE_CHANGE_EV(p) (*((uint32_t *)(p)) & 0x00020000) -#define HCI_NUM_COMPLETED_PKTS_EV(p) (*((uint32_t *)(p)) & 0x00040000) -#define HCI_MODE_CHANGE_EV(p) (*((uint32_t *)(p)) & 0x00080000) -#define HCI_RETURN_LINK_KEYS_EV(p) (*((uint32_t *)(p)) & 0x00100000) -#define HCI_PIN_CODE_REQUEST_EV(p) (*((uint32_t *)(p)) & 0x00200000) -#define HCI_LINK_KEY_REQUEST_EV(p) (*((uint32_t *)(p)) & 0x00400000) -#define HCI_LINK_KEY_NOTIFICATION_EV(p) (*((uint32_t *)(p)) & 0x00800000) -#define HCI_LOOPBACK_COMMAND_EV(p) (*((uint32_t *)(p)) & 0x01000000) -#define HCI_DATA_BUF_OVERFLOW_EV(p) (*((uint32_t *)(p)) & 0x02000000) -#define HCI_MAX_SLOTS_CHANGE_EV(p) (*((uint32_t *)(p)) & 0x04000000) -#define HCI_READ_CLOCK_OFFSET_COMP_EV(p) (*((uint32_t *)(p)) & 0x08000000) -#define HCI_CONN_PKT_TYPE_CHANGED_EV(p) (*((uint32_t *)(p)) & 0x10000000) -#define HCI_QOS_VIOLATION_EV(p) (*((uint32_t *)(p)) & 0x20000000) -#define HCI_PAGE_SCAN_MODE_CHANGED_EV(p) (*((uint32_t *)(p)) & 0x40000000) -#define HCI_PAGE_SCAN_REP_MODE_CHNG_EV(p) (*((uint32_t *)(p)) & 0x80000000) - -/* the default event mask for 2.1+EDR (Lisbon) does not include Lisbon events */ -#define HCI_DEFAULT_EVENT_MASK_0 0xFFFFFFFF -#define HCI_DEFAULT_EVENT_MASK_1 0x00001FFF - -/* the event mask for 2.0 + EDR and later (includes Lisbon events) */ -#define HCI_LISBON_EVENT_MASK_0 0xFFFFFFFF -#define HCI_LISBON_EVENT_MASK_1 0x1DBFFFFF -#define HCI_LISBON_EVENT_MASK "\x0D\xBF\xFF\xFF\xFF\xFF\xFF\xFF" -#define HCI_LISBON_EVENT_MASK_EXT "\x1D\xBF\xFF\xFF\xFF\xFF\xFF\xFF" -#define HCI_DUMO_EVENT_MASK_EXT "\x3D\xBF\xFF\xFF\xFF\xFF\xFF\xFF" -/* 0x00001FFF FFFFFFFF Default - no Lisbon events - 0x00000800 00000000 Synchronous Connection Complete Event - 0x00001000 00000000 Synchronous Connection Changed Event - 0x00002000 00000000 Sniff Subrate Event - 0x00004000 00000000 Extended Inquiry Result Event - 0x00008000 00000000 Encryption Key Refresh Complete Event - 0x00010000 00000000 IO Capability Request Event - 0x00020000 00000000 IO Capability Response Event - 0x00040000 00000000 User Confirmation Request Event - 0x00080000 00000000 User Passkey Request Event - 0x00100000 00000000 Remote OOB Data Request Event - 0x00200000 00000000 Simple Pairing Complete Event - 0x00400000 00000000 Generic AMP Link Key Notification Event - 0x00800000 00000000 Link Supervision Timeout Changed Event - 0x01000000 00000000 Enhanced Flush Complete Event - 0x04000000 00000000 User Passkey Notification Event - 0x08000000 00000000 Keypress Notification Event - 0x10000000 00000000 Remote Host Supported Features Notification Event - 0x20000000 00000000 LE Meta Event - */ - -/* the event mask for AMP controllers */ -#define HCI_AMP_EVENT_MASK_3_0 "\x00\x00\x00\x00\x00\x00\x3F\xFF" - -/* 0x0000000000000000 No events specified (default) - 0x0000000000000001 Physical Link Complete Event - 0x0000000000000002 Channel Selected Event - 0x0000000000000004 Disconnection Physical Link Event - 0x0000000000000008 Physical Link Loss Early Warning Event - 0x0000000000000010 Physical Link Recovery Event - 0x0000000000000020 Logical Link Complete Event - 0x0000000000000040 Disconnection Logical Link Complete Event - 0x0000000000000080 Flow Spec Modify Complete Event - 0x0000000000000100 Number of Completed Data Blocks Event - 0x0000000000000200 AMP Start Test Event - 0x0000000000000400 AMP Test End Event - 0x0000000000000800 AMP Receiver Report Event - 0x0000000000001000 Short Range Mode Change Complete Event - 0x0000000000002000 AMP Status Change Event -*/ - -/* the event mask page 2 (CLB + CSA4) for BR/EDR controller */ -#define HCI_PAGE_2_EVENT_MASK "\x00\x00\x00\x00\x00\x7F\xC0\x00" -/* 0x0000000000004000 Triggered Clock Capture Event - 0x0000000000008000 Sync Train Complete Event - 0x0000000000010000 Sync Train Received Event - 0x0000000000020000 Connectionless Broadcast Receive Event - 0x0000000000040000 Connectionless Broadcast Timeout Event - 0x0000000000080000 Truncated Page Complete Event - 0x0000000000100000 Salve Page Response Timeout Event - 0x0000000000200000 Connectionless Broadcast Channel Map Change Event - 0x0000000000400000 Inquiry Response Notification Event -*/ -#if BLE_PRIVACY_SPT == TRUE -/* BLE event mask */ -#define HCI_BLE_EVENT_MASK_DEF "\x00\x00\x00\x00\x00\x00\x07\xff" -#else -#define HCI_BLE_EVENT_MASK_DEF "\x00\x00\x00\x00\x00\x00\x00\x7f" -#endif -/* -** Definitions for packet type masks (BT1.2 and BT2.0 definitions) -*/ -#define HCI_PKT_TYPES_MASK_NO_2_DH1 0x0002 -#define HCI_PKT_TYPES_MASK_NO_3_DH1 0x0004 -#define HCI_PKT_TYPES_MASK_DM1 0x0008 -#define HCI_PKT_TYPES_MASK_DH1 0x0010 -#define HCI_PKT_TYPES_MASK_HV1 0x0020 -#define HCI_PKT_TYPES_MASK_HV2 0x0040 -#define HCI_PKT_TYPES_MASK_HV3 0x0080 -#define HCI_PKT_TYPES_MASK_NO_2_DH3 0x0100 -#define HCI_PKT_TYPES_MASK_NO_3_DH3 0x0200 -#define HCI_PKT_TYPES_MASK_DM3 0x0400 -#define HCI_PKT_TYPES_MASK_DH3 0x0800 -#define HCI_PKT_TYPES_MASK_NO_2_DH5 0x1000 -#define HCI_PKT_TYPES_MASK_NO_3_DH5 0x2000 -#define HCI_PKT_TYPES_MASK_DM5 0x4000 -#define HCI_PKT_TYPES_MASK_DH5 0x8000 - -/* Packet type should be one of valid but at least one should be specified */ -#define HCI_VALID_SCO_PKT_TYPE(t) (((((t) & ~(HCI_PKT_TYPES_MASK_HV1 | HCI_PKT_TYPES_MASK_HV2 | HCI_PKT_TYPES_MASK_HV3)) == 0)) && ((t) != 0)) - -/* Packet type should not be invalid and at least one should be specified */ -#define HCI_VALID_ACL_PKT_TYPE(t) (((((t) & ~(HCI_PKT_TYPES_MASK_DM1 | HCI_PKT_TYPES_MASK_DH1 | HCI_PKT_TYPES_MASK_DM3 | HCI_PKT_TYPES_MASK_DH3 | HCI_PKT_TYPES_MASK_DM5 | HCI_PKT_TYPES_MASK_DH5 | HCI_PKT_TYPES_MASK_NO_2_DH1 | HCI_PKT_TYPES_MASK_NO_3_DH1 | HCI_PKT_TYPES_MASK_NO_2_DH3 | HCI_PKT_TYPES_MASK_NO_3_DH3 | HCI_PKT_TYPES_MASK_NO_2_DH5 | HCI_PKT_TYPES_MASK_NO_3_DH5)) == 0)) && (((t) & (HCI_PKT_TYPES_MASK_DM1 | HCI_PKT_TYPES_MASK_DH1 | HCI_PKT_TYPES_MASK_DM3 | HCI_PKT_TYPES_MASK_DH3 | HCI_PKT_TYPES_MASK_DM5 | HCI_PKT_TYPES_MASK_DH5)) != 0)) - -/* -** Definitions for eSCO packet type masks (BT1.2 and BT2.0 definitions) -*/ -#define HCI_ESCO_PKT_TYPES_MASK_HV1 0x0001 -#define HCI_ESCO_PKT_TYPES_MASK_HV2 0x0002 -#define HCI_ESCO_PKT_TYPES_MASK_HV3 0x0004 -#define HCI_ESCO_PKT_TYPES_MASK_EV3 0x0008 -#define HCI_ESCO_PKT_TYPES_MASK_EV4 0x0010 -#define HCI_ESCO_PKT_TYPES_MASK_EV5 0x0020 -#define HCI_ESCO_PKT_TYPES_MASK_NO_2_EV3 0x0040 -#define HCI_ESCO_PKT_TYPES_MASK_NO_3_EV3 0x0080 -#define HCI_ESCO_PKT_TYPES_MASK_NO_2_EV5 0x0100 -#define HCI_ESCO_PKT_TYPES_MASK_NO_3_EV5 0x0200 - -/* Packet type should be one of valid but at least one should be specified for 1.2 */ -#define HCI_VALID_ESCO_PKT_TYPE(t) (((((t) & ~(HCI_ESCO_PKT_TYPES_MASK_EV3 | HCI_ESCO_PKT_TYPES_MASK_EV4 | HCI_ESCO_PKT_TYPES_MASK_EV5)) == 0)) && ((t) != 0)) /* Packet type should be one of valid but at least one should be specified */ - -#define HCI_VALID_ESCO_SCOPKT_TYPE(t) (((((t) & ~(HCI_ESCO_PKT_TYPES_MASK_HV1 | HCI_ESCO_PKT_TYPES_MASK_HV2 | HCI_ESCO_PKT_TYPES_MASK_HV3)) == 0)) && ((t) != 0)) - -#define HCI_VALID_SCO_ALL_PKT_TYPE(t) (((((t) & ~(HCI_ESCO_PKT_TYPES_MASK_HV1 | HCI_ESCO_PKT_TYPES_MASK_HV2 | HCI_ESCO_PKT_TYPES_MASK_HV3 | HCI_ESCO_PKT_TYPES_MASK_EV3 | HCI_ESCO_PKT_TYPES_MASK_EV4 | HCI_ESCO_PKT_TYPES_MASK_EV5)) == 0)) && ((t) != 0)) - -/* -** Define parameters to allow role switch during create connection -*/ -#define HCI_CR_CONN_NOT_ALLOW_SWITCH 0x00 -#define HCI_CR_CONN_ALLOW_SWITCH 0x01 - -/* -** Hold Mode command destination -*/ -#define HOLD_MODE_DEST_LOCAL_DEVICE 0x00 -#define HOLD_MODE_DEST_RMT_DEVICE 0x01 - -/* -** Definitions for different HCI parameters -*/ -#define HCI_PER_INQ_MIN_MAX_PERIOD 0x0003 -#define HCI_PER_INQ_MAX_MAX_PERIOD 0xFFFF -#define HCI_PER_INQ_MIN_MIN_PERIOD 0x0002 -#define HCI_PER_INQ_MAX_MIN_PERIOD 0xFFFE - -#define HCI_MAX_INQUIRY_LENGTH 0x30 - -#define HCI_MIN_INQ_LAP 0x9E8B00 -#define HCI_MAX_INQ_LAP 0x9E8B3F - -/* HCI role definitions */ -#define HCI_ROLE_MASTER 0x00 -#define HCI_ROLE_SLAVE 0x01 -#define HCI_ROLE_UNKNOWN 0xff - -/* HCI mode definitions */ -#define HCI_MODE_ACTIVE 0x00 -#define HCI_MODE_HOLD 0x01 -#define HCI_MODE_SNIFF 0x02 -#define HCI_MODE_PARK 0x03 - -/* HCI Flow Control Mode definitions */ -#define HCI_PACKET_BASED_FC_MODE 0x00 -#define HCI_BLOCK_BASED_FC_MODE 0x01 - -/* Define Packet types as requested by the Host */ -#define HCI_ACL_PKT_TYPE_NONE 0x0000 -#define HCI_ACL_PKT_TYPE_DM1 0x0008 -#define HCI_ACL_PKT_TYPE_DH1 0x0010 -#define HCI_ACL_PKT_TYPE_AUX1 0x0200 -#define HCI_ACL_PKT_TYPE_DM3 0x0400 -#define HCI_ACL_PKT_TYPE_DH3 0x0800 -#define HCI_ACL_PKT_TYPE_DM5 0x4000 -#define HCI_ACL_PKT_TYPE_DH5 0x8000 - -/* Define key type in the Master Link Key command */ -#define HCI_USE_SEMI_PERMANENT_KEY 0x00 -#define HCI_USE_TEMPORARY_KEY 0x01 - -/* Page scan period modes */ -#define HCI_PAGE_SCAN_REP_MODE_R0 0x00 -#define HCI_PAGE_SCAN_REP_MODE_R1 0x01 -#define HCI_PAGE_SCAN_REP_MODE_R2 0x02 - -/* Define limits for page scan repetition modes */ -#define HCI_PAGE_SCAN_R1_LIMIT 0x0800 -#define HCI_PAGE_SCAN_R2_LIMIT 0x1000 - -/* Page scan period modes */ -#define HCI_PAGE_SCAN_PER_MODE_P0 0x00 -#define HCI_PAGE_SCAN_PER_MODE_P1 0x01 -#define HCI_PAGE_SCAN_PER_MODE_P2 0x02 - -/* Page scan modes */ -#define HCI_MANDATARY_PAGE_SCAN_MODE 0x00 -#define HCI_OPTIONAL_PAGE_SCAN_MODE1 0x01 -#define HCI_OPTIONAL_PAGE_SCAN_MODE2 0x02 -#define HCI_OPTIONAL_PAGE_SCAN_MODE3 0x03 - -/* Page and inquiry scan types */ -#define HCI_SCAN_TYPE_STANDARD 0x00 -#define HCI_SCAN_TYPE_INTERLACED 0x01 /* 1.2 devices or later */ -#define HCI_DEF_SCAN_TYPE HCI_SCAN_TYPE_STANDARD - -/* Definitions for quality of service service types */ -#define HCI_SERVICE_NO_TRAFFIC 0x00 -#define HCI_SERVICE_BEST_EFFORT 0x01 -#define HCI_SERVICE_GUARANTEED 0x02 - -#define HCI_QOS_LATENCY_DO_NOT_CARE 0xFFFFFFFF -#define HCI_QOS_DELAY_DO_NOT_CARE 0xFFFFFFFF - -/* Definitions for Flow Specification */ -#define HCI_FLOW_SPEC_LATENCY_DO_NOT_CARE 0xFFFFFFFF - -/* Definitions for AFH Channel Map */ -#define HCI_AFH_CHANNEL_MAP_LEN 10 - -/* Definitions for Extended Inquiry Response */ -#define HCI_EXT_INQ_RESPONSE_LEN 240 -#define HCI_EIR_FLAGS_TYPE BT_EIR_FLAGS_TYPE -#define HCI_EIR_MORE_16BITS_UUID_TYPE BT_EIR_MORE_16BITS_UUID_TYPE -#define HCI_EIR_COMPLETE_16BITS_UUID_TYPE BT_EIR_COMPLETE_16BITS_UUID_TYPE -#define HCI_EIR_MORE_32BITS_UUID_TYPE BT_EIR_MORE_32BITS_UUID_TYPE -#define HCI_EIR_COMPLETE_32BITS_UUID_TYPE BT_EIR_COMPLETE_32BITS_UUID_TYPE -#define HCI_EIR_MORE_128BITS_UUID_TYPE BT_EIR_MORE_128BITS_UUID_TYPE -#define HCI_EIR_COMPLETE_128BITS_UUID_TYPE BT_EIR_COMPLETE_128BITS_UUID_TYPE -#define HCI_EIR_SHORTENED_LOCAL_NAME_TYPE BT_EIR_SHORTENED_LOCAL_NAME_TYPE -#define HCI_EIR_COMPLETE_LOCAL_NAME_TYPE BT_EIR_COMPLETE_LOCAL_NAME_TYPE -#define HCI_EIR_TX_POWER_LEVEL_TYPE BT_EIR_TX_POWER_LEVEL_TYPE -#define HCI_EIR_MANUFACTURER_SPECIFIC_TYPE BT_EIR_MANUFACTURER_SPECIFIC_TYPE -#define HCI_EIR_SERVICE_DATA_TYPE BT_EIR_SERVICE_DATA_TYPE -#define HCI_EIR_SERVICE_DATA_16BITS_UUID_TYPE BT_EIR_SERVICE_DATA_16BITS_UUID_TYPE -#define HCI_EIR_SERVICE_DATA_32BITS_UUID_TYPE BT_EIR_SERVICE_DATA_32BITS_UUID_TYPE -#define HCI_EIR_SERVICE_DATA_128BITS_UUID_TYPE BT_EIR_SERVICE_DATA_128BITS_UUID_TYPE -#define HCI_EIR_OOB_BD_ADDR_TYPE BT_EIR_OOB_BD_ADDR_TYPE -#define HCI_EIR_OOB_COD_TYPE BT_EIR_OOB_COD_TYPE -#define HCI_EIR_OOB_SSP_HASH_C_TYPE BT_EIR_OOB_SSP_HASH_C_TYPE -#define HCI_EIR_OOB_SSP_RAND_R_TYPE BT_EIR_OOB_SSP_RAND_R_TYPE - -/* Definitions for Write Simple Pairing Mode */ -#define HCI_SP_MODE_UNDEFINED 0x00 -#define HCI_SP_MODE_ENABLED 0x01 - -/* Definitions for Write Simple Pairing Debug Mode */ -#define HCI_SPD_MODE_DISABLED 0x00 -#define HCI_SPD_MODE_ENABLED 0x01 - -/* Definitions for Write Secure Connections Host Support */ -#define HCI_SC_MODE_DISABLED 0x00 -#define HCI_SC_MODE_ENABLED 0x01 - -/* Definitions for IO Capability Response/Command */ -#define HCI_IO_CAP_DISPLAY_ONLY 0x00 -#define HCI_IO_CAP_DISPLAY_YESNO 0x01 -#define HCI_IO_CAP_KEYBOARD_ONLY 0x02 -#define HCI_IO_CAP_NO_IO 0x03 - -#define HCI_OOB_AUTH_DATA_NOT_PRESENT 0x00 -#define HCI_OOB_REM_AUTH_DATA_PRESENT 0x01 - -#define HCI_MITM_PROTECT_NOT_REQUIRED 0x00 -#define HCI_MITM_PROTECT_REQUIRED 0x01 - -/* Policy settings status */ -#define HCI_DISABLE_ALL_LM_MODES 0x0000 -#define HCI_ENABLE_MASTER_SLAVE_SWITCH 0x0001 -#define HCI_ENABLE_HOLD_MODE 0x0002 -#define HCI_ENABLE_SNIFF_MODE 0x0004 -#define HCI_ENABLE_PARK_MODE 0x0008 - -/* By default allow switch, because host can not allow that */ -/* that until he created the connection */ -#define HCI_DEFAULT_POLICY_SETTINGS HCI_DISABLE_ALL_LM_MODES - -/* Filters that are sent in set filter command */ -#define HCI_FILTER_TYPE_CLEAR_ALL 0x00 -#define HCI_FILTER_INQUIRY_RESULT 0x01 -#define HCI_FILTER_CONNECTION_SETUP 0x02 - -#define HCI_FILTER_COND_NEW_DEVICE 0x00 -#define HCI_FILTER_COND_DEVICE_CLASS 0x01 -#define HCI_FILTER_COND_BD_ADDR 0x02 - -#define HCI_DO_NOT_AUTO_ACCEPT_CONNECT 1 -#define HCI_DO_AUTO_ACCEPT_CONNECT 2 /* role switch disabled */ -#define HCI_DO_AUTO_ACCEPT_CONNECT_RS 3 /* role switch enabled (1.1 errata 1115) */ - -/* Auto accept flags */ -#define HCI_AUTO_ACCEPT_OFF 0x00 -#define HCI_AUTO_ACCEPT_ACL_CONNECTIONS 0x01 -#define HCI_AUTO_ACCEPT_SCO_CONNECTIONS 0x02 - -/* PIN type */ -#define HCI_PIN_TYPE_VARIABLE 0 -#define HCI_PIN_TYPE_FIXED 1 - -/* Loopback Modes */ -#define HCI_LOOPBACK_MODE_DISABLED 0 -#define HCI_LOOPBACK_MODE_LOCAL 1 -#define HCI_LOOPBACK_MODE_REMOTE 2 - -#define SLOTS_PER_10MS 16 /* 0.625 ms slots in a 10 ms tick */ - -/* Maximum connection accept timeout in 0.625msec */ -#define HCI_MAX_CONN_ACCEPT_TOUT 0xB540 /* 29 sec */ -#define HCI_DEF_CONN_ACCEPT_TOUT 0x1F40 /* 5 sec */ - -/* Page timeout is used in LC only and LC is counting down slots not using OS */ -#define HCI_DEFAULT_PAGE_TOUT 0x2000 /* 5.12 sec (in slots) */ - -/* Scan enable flags */ -#define HCI_NO_SCAN_ENABLED 0x00 -#define HCI_INQUIRY_SCAN_ENABLED 0x01 -#define HCI_PAGE_SCAN_ENABLED 0x02 - -/* Pagescan timer definitions in 0.625 ms */ -#define HCI_MIN_PAGESCAN_INTERVAL 0x12 /* 11.25 ms */ -#define HCI_MAX_PAGESCAN_INTERVAL 0x1000 /* 2.56 sec */ -#define HCI_DEF_PAGESCAN_INTERVAL 0x0800 /* 1.28 sec */ - -/* Parameter for pagescan window is passed to LC and is kept in slots */ -#define HCI_MIN_PAGESCAN_WINDOW 0x11 /* 10.625 ms */ -#define HCI_MAX_PAGESCAN_WINDOW 0x1000 /* 2.56 sec */ -#define HCI_DEF_PAGESCAN_WINDOW 0x12 /* 11.25 ms */ - -/* Inquiryscan timer definitions in 0.625 ms */ -#define HCI_MIN_INQUIRYSCAN_INTERVAL 0x12 /* 11.25 ms */ -#define HCI_MAX_INQUIRYSCAN_INTERVAL 0x1000 /* 2.56 sec */ -#define HCI_DEF_INQUIRYSCAN_INTERVAL 0x1000 /* 2.56 sec */ - -/* Parameter for inquiryscan window is passed to LC and is kept in slots */ -#define HCI_MIN_INQUIRYSCAN_WINDOW 0x11 /* 10.625 ms */ -#define HCI_MAX_INQUIRYSCAN_WINDOW 0x1000 /* 2.56 sec */ -#define HCI_DEF_INQUIRYSCAN_WINDOW 0x12 /* 11.25 ms */ - -/* Encryption modes */ -#define HCI_ENCRYPT_MODE_DISABLED 0x00 -#define HCI_ENCRYPT_MODE_POINT_TO_POINT 0x01 -#define HCI_ENCRYPT_MODE_ALL 0x02 - -/* Voice settings */ -#define HCI_INP_CODING_LINEAR 0x0000 /* 0000000000 */ -#define HCI_INP_CODING_U_LAW 0x0100 /* 0100000000 */ -#define HCI_INP_CODING_A_LAW 0x0200 /* 1000000000 */ -#define HCI_INP_CODING_MASK 0x0300 /* 1100000000 */ - -#define HCI_INP_DATA_FMT_1S_COMPLEMENT 0x0000 /* 0000000000 */ -#define HCI_INP_DATA_FMT_2S_COMPLEMENT 0x0040 /* 0001000000 */ -#define HCI_INP_DATA_FMT_SIGN_MAGNITUDE 0x0080 /* 0010000000 */ -#define HCI_INP_DATA_FMT_UNSIGNED 0x00c0 /* 0011000000 */ -#define HCI_INP_DATA_FMT_MASK 0x00c0 /* 0011000000 */ - -#define HCI_INP_SAMPLE_SIZE_8BIT 0x0000 /* 0000000000 */ -#define HCI_INP_SAMPLE_SIZE_16BIT 0x0020 /* 0000100000 */ -#define HCI_INP_SAMPLE_SIZE_MASK 0x0020 /* 0000100000 */ - -#define HCI_INP_LINEAR_PCM_BIT_POS_MASK 0x001c /* 0000011100 */ -#define HCI_INP_LINEAR_PCM_BIT_POS_OFFS 2 - -#define HCI_AIR_CODING_FORMAT_CVSD 0x0000 /* 0000000000 */ -#define HCI_AIR_CODING_FORMAT_U_LAW 0x0001 /* 0000000001 */ -#define HCI_AIR_CODING_FORMAT_A_LAW 0x0002 /* 0000000010 */ -#define HCI_AIR_CODING_FORMAT_TRANSPNT 0x0003 /* 0000000011 */ -#define HCI_AIR_CODING_FORMAT_MASK 0x0003 /* 0000000011 */ - -/* default 0001100000 */ -#define HCI_DEFAULT_VOICE_SETTINGS (HCI_INP_CODING_LINEAR | HCI_INP_DATA_FMT_2S_COMPLEMENT | HCI_INP_SAMPLE_SIZE_16BIT | HCI_AIR_CODING_FORMAT_CVSD) - -#define HCI_CVSD_SUPPORTED(x) (((x)&HCI_AIR_CODING_FORMAT_MASK) == HCI_AIR_CODING_FORMAT_CVSD) -#define HCI_U_LAW_SUPPORTED(x) (((x)&HCI_AIR_CODING_FORMAT_MASK) == HCI_AIR_CODING_FORMAT_U_LAW) -#define HCI_A_LAW_SUPPORTED(x) (((x)&HCI_AIR_CODING_FORMAT_MASK) == HCI_AIR_CODING_FORMAT_A_LAW) -#define HCI_TRANSPNT_SUPPORTED(x) (((x)&HCI_AIR_CODING_FORMAT_MASK) == HCI_AIR_CODING_FORMAT_TRANSPNT) - -/* Retransmit timer definitions in 0.625 */ -#define HCI_MAX_AUTO_FLUSH_TOUT 0x07FF -#define HCI_DEFAULT_AUTO_FLUSH_TOUT 0 /* No auto flush */ - -/* Broadcast retransmitions */ -#define HCI_DEFAULT_NUM_BCAST_RETRAN 1 - -/* Define broadcast data types as passed in the hci data packet */ -#define HCI_DATA_POINT_TO_POINT 0x00 -#define HCI_DATA_ACTIVE_BCAST 0x01 -#define HCI_DATA_PICONET_BCAST 0x02 - -/* Hold mode activity */ -#define HCI_MAINTAIN_CUR_POWER_STATE 0x00 -#define HCI_SUSPEND_PAGE_SCAN 0x01 -#define HCI_SUSPEND_INQUIRY_SCAN 0x02 -#define HCI_SUSPEND_PERIODIC_INQUIRIES 0x04 - -/* Default Link Supervision timeoout */ -#define HCI_DEFAULT_INACT_TOUT 0x7D00 /* BR/EDR (20 seconds) */ -#define HCI_DEFAULT_AMP_INACT_TOUT 0x3E80 /* AMP (10 seconds) */ - -/* Read transmit power level parameter */ -#define HCI_READ_CURRENT 0x00 -#define HCI_READ_MAXIMUM 0x01 - -/* Link types for connection complete event */ -#define HCI_LINK_TYPE_SCO 0x00 -#define HCI_LINK_TYPE_ACL 0x01 -#define HCI_LINK_TYPE_ESCO 0x02 - -/* Link Key Notification Event (Key Type) definitions */ -#define HCI_LKEY_TYPE_COMBINATION 0x00 -#define HCI_LKEY_TYPE_LOCAL_UNIT 0x01 -#define HCI_LKEY_TYPE_REMOTE_UNIT 0x02 -#define HCI_LKEY_TYPE_DEBUG_COMB 0x03 -#define HCI_LKEY_TYPE_UNAUTH_COMB 0x04 -#define HCI_LKEY_TYPE_AUTH_COMB 0x05 -#define HCI_LKEY_TYPE_CHANGED_COMB 0x06 -#define HCI_LKEY_TYPE_UNAUTH_COMB_P_256 0x07 -#define HCI_LKEY_TYPE_AUTH_COMB_P_256 0x08 - -/* Internal definitions - not used over HCI */ -#define HCI_LKEY_TYPE_AMP_WIFI 0x80 -#define HCI_LKEY_TYPE_AMP_UWB 0x81 -#define HCI_LKEY_TYPE_UNKNOWN 0xff - -/* Read Local Version HCI Version return values (Command Complete Event) */ -#define HCI_VERSION_1_0B 0x00 -#define HCI_VERSION_1_1 0x01 - -/* Define an invalid value for a handle */ -#define HCI_INVALID_HANDLE 0xFFFF - -/* Define max amount of data in the HCI command */ -#define HCI_COMMAND_SIZE 255 - -/* Define the preamble length for all HCI Commands. -** This is 2-bytes for opcode and 1 byte for length -*/ -#define HCIC_PREAMBLE_SIZE 3 - -/* Define the preamble length for all HCI Events -** This is 1-byte for opcode and 1 byte for length -*/ -#define HCIE_PREAMBLE_SIZE 2 -#define HCI_SCO_PREAMBLE_SIZE 3 -#define HCI_DATA_PREAMBLE_SIZE 4 - -/* local Bluetooth controller id for AMP HCI */ -#define LOCAL_BR_EDR_CONTROLLER_ID 0 - -/* controller id types for AMP HCI */ -#define HCI_CONTROLLER_TYPE_BR_EDR 0 -#define HCI_CONTROLLER_TYPE_802_11 1 -#define HCI_CONTROLLER_TYPE_ECMA 2 -#define HCI_MAX_CONTROLLER_TYPES 3 - -/* ConnectionLess Broadcast */ -#define HCI_CLB_DISABLE 0x00 -#define HCI_CLB_ENABLE 0x01 - -/* ConnectionLess Broadcast Data fragment */ -#define HCI_CLB_FRAGMENT_CONT 0x00 -#define HCI_CLB_FRAGMENT_START 0x01 -#define HCI_CLB_FRAGMENT_END 0x02 -#define HCI_CLB_FRAGMENT_SINGLE 0x03 - -/* AMP Controller Status codes - */ -#define HCI_AMP_CTRLR_PHYSICALLY_DOWN 0 -#define HCI_AMP_CTRLR_USABLE_BY_BT 1 -#define HCI_AMP_CTRLR_UNUSABLE_FOR_BT 2 -#define HCI_AMP_CTRLR_LOW_CAP_FOR_BT 3 -#define HCI_AMP_CTRLR_MED_CAP_FOR_BT 4 -#define HCI_AMP_CTRLR_HIGH_CAP_FOR_BT 5 -#define HCI_AMP_CTRLR_FULL_CAP_FOR_BT 6 - -#define HCI_MAX_AMP_STATUS_TYPES 7 - -/* Define the extended flow specification fields used by AMP */ -typedef struct -{ - uint8_t id; - uint8_t stype; - uint16_t max_sdu_size; - uint32_t sdu_inter_time; - uint32_t access_latency; - uint32_t flush_timeout; -} tHCI_EXT_FLOW_SPEC; - -/* HCI message type definitions (for H4 messages) */ -#define HCIT_TYPE_COMMAND 1 -#define HCIT_TYPE_ACL_DATA 2 -#define HCIT_TYPE_SCO_DATA 3 -#define HCIT_TYPE_EVENT 4 -#define HCIT_TYPE_LM_DIAG 7 -#define HCIT_TYPE_NFC 16 - -#define HCIT_LM_DIAG_LENGTH 63 - -/* Parameter information for HCI_BRCM_SET_ACL_PRIORITY */ -#define HCI_BRCM_ACL_PRIORITY_PARAM_SIZE 3 -#define HCI_BRCM_ACL_PRIORITY_LOW 0x00 -#define HCI_BRCM_ACL_PRIORITY_HIGH 0xFF -#define HCI_BRCM_SET_ACL_PRIORITY (0x0057 | HCI_GRP_VENDOR_SPECIFIC) - -/* Define values for LMP Test Control parameters -** Test Scenario, Hopping Mode, Power Control Mode -*/ -#define LMP_TESTCTL_TESTSC_PAUSE 0 -#define LMP_TESTCTL_TESTSC_TXTEST_0 1 -#define LMP_TESTCTL_TESTSC_TXTEST_1 2 -#define LMP_TESTCTL_TESTSC_TXTEST_1010 3 -#define LMP_TESTCTL_TESTSC_PSRND_BITSEQ 4 -#define LMP_TESTCTL_TESTSC_CLOSEDLB_ACL 5 -#define LMP_TESTCTL_TESTSC_CLOSEDLB_SCO 6 -#define LMP_TESTCTL_TESTSC_ACL_NOWHIT 7 -#define LMP_TESTCTL_TESTSC_SCO_NOWHIT 8 -#define LMP_TESTCTL_TESTSC_TXTEST_11110000 9 -#define LMP_TESTCTL_TESTSC_EXITTESTMODE 255 - -#define LMP_TESTCTL_HOPMOD_RXTX1FREQ 0 -#define LMP_TESTCTL_HOPMOD_HOP_EURUSA 1 -#define LMP_TESTCTL_HOPMOD_HOP_JAPAN 2 -#define LMP_TESTCTL_HOPMOD_HOP_FRANCE 3 -#define LMP_TESTCTL_HOPMOD_HOP_SPAIN 4 -#define LMP_TESTCTL_HOPMOD_REDUCED_HOP 5 - -#define LMP_TESTCTL_POWCTL_FIXEDTX_OP 0 -#define LMP_TESTCTL_POWCTL_ADAPTIVE 1 - -// TODO(zachoverflow): remove this once broadcom specific hacks are removed -#define LMP_COMPID_BROADCOM 15 - -/* -** Define the packet types in the packet header, and a couple extra -*/ -#define PKT_TYPE_NULL 0x00 -#define PKT_TYPE_POLL 0x01 -#define PKT_TYPE_FHS 0x02 -#define PKT_TYPE_DM1 0x03 - -#define PKT_TYPE_DH1 0x04 -#define PKT_TYPE_HV1 0x05 -#define PKT_TYPE_HV2 0x06 -#define PKT_TYPE_HV3 0x07 -#define PKT_TYPE_DV 0x08 -#define PKT_TYPE_AUX1 0x09 - -#define PKT_TYPE_DM3 0x0a -#define PKT_TYPE_DH3 0x0b - -#define PKT_TYPE_DM5 0x0e -#define PKT_TYPE_DH5 0x0f - -#define PKT_TYPE_ID 0x10 /* Internally used packet types */ -#define PKT_TYPE_BAD 0x11 -#define PKT_TYPE_NONE 0x12 - -/* -** Define packet size -*/ -#define HCI_DM1_PACKET_SIZE 17 -#define HCI_DH1_PACKET_SIZE 27 -#define HCI_DM3_PACKET_SIZE 121 -#define HCI_DH3_PACKET_SIZE 183 -#define HCI_DM5_PACKET_SIZE 224 -#define HCI_DH5_PACKET_SIZE 339 -#define HCI_AUX1_PACKET_SIZE 29 -#define HCI_HV1_PACKET_SIZE 10 -#define HCI_HV2_PACKET_SIZE 20 -#define HCI_HV3_PACKET_SIZE 30 -#define HCI_DV_PACKET_SIZE 9 -#define HCI_EDR2_DH1_PACKET_SIZE 54 -#define HCI_EDR2_DH3_PACKET_SIZE 367 -#define HCI_EDR2_DH5_PACKET_SIZE 679 -#define HCI_EDR3_DH1_PACKET_SIZE 83 -#define HCI_EDR3_DH3_PACKET_SIZE 552 -#define HCI_EDR3_DH5_PACKET_SIZE 1021 - -/* Feature Pages */ -#define HCI_EXT_FEATURES_PAGE_0 0 /* Extended Feature Page 0 (regular features) */ -#define HCI_EXT_FEATURES_PAGE_1 1 /* Extended Feature Page 1 */ -#define HCI_EXT_FEATURES_PAGE_2 2 /* Extended Feature Page 2 */ -#define HCI_EXT_FEATURES_PAGE_MAX HCI_EXT_FEATURES_PAGE_2 - -#define HCI_FEATURE_BYTES_PER_PAGE 8 - -#define HCI_FEATURES_KNOWN(x) ((x[0] | x[1] | x[2] | x[3] | x[4] | x[5] | x[6] | x[7]) != 0) - -/* -** LMP features encoding - page 0 -*/ -#define HCI_FEATURE_3_SLOT_PACKETS_MASK 0x01 -#define HCI_FEATURE_3_SLOT_PACKETS_OFF 0 -#define HCI_3_SLOT_PACKETS_SUPPORTED(x) ((x)[HCI_FEATURE_3_SLOT_PACKETS_OFF] & HCI_FEATURE_3_SLOT_PACKETS_MASK) - -#define HCI_FEATURE_5_SLOT_PACKETS_MASK 0x02 -#define HCI_FEATURE_5_SLOT_PACKETS_OFF 0 -#define HCI_5_SLOT_PACKETS_SUPPORTED(x) ((x)[HCI_FEATURE_5_SLOT_PACKETS_OFF] & HCI_FEATURE_5_SLOT_PACKETS_MASK) - -#define HCI_FEATURE_ENCRYPTION_MASK 0x04 -#define HCI_FEATURE_ENCRYPTION_OFF 0 -#define HCI_ENCRYPTION_SUPPORTED(x) ((x)[HCI_FEATURE_ENCRYPTION_OFF] & HCI_FEATURE_ENCRYPTION_MASK) - -#define HCI_FEATURE_SLOT_OFFSET_MASK 0x08 -#define HCI_FEATURE_SLOT_OFFSET_OFF 0 -#define HCI_SLOT_OFFSET_SUPPORTED(x) ((x)[HCI_FEATURE_SLOT_OFFSET_OFF] & HCI_FEATURE_SLOT_OFFSET_MASK) - -#define HCI_FEATURE_TIMING_ACC_MASK 0x10 -#define HCI_FEATURE_TIMING_ACC_OFF 0 -#define HCI_TIMING_ACC_SUPPORTED(x) ((x)[HCI_FEATURE_TIMING_ACC_OFF] & HCI_FEATURE_TIMING_ACC_MASK) - -#define HCI_FEATURE_SWITCH_MASK 0x20 -#define HCI_FEATURE_SWITCH_OFF 0 -#define HCI_SWITCH_SUPPORTED(x) ((x)[HCI_FEATURE_SWITCH_OFF] & HCI_FEATURE_SWITCH_MASK) - -#define HCI_FEATURE_HOLD_MODE_MASK 0x40 -#define HCI_FEATURE_HOLD_MODE_OFF 0 -#define HCI_HOLD_MODE_SUPPORTED(x) ((x)[HCI_FEATURE_HOLD_MODE_OFF] & HCI_FEATURE_HOLD_MODE_MASK) - -#define HCI_FEATURE_SNIFF_MODE_MASK 0x80 -#define HCI_FEATURE_SNIFF_MODE_OFF 0 -#define HCI_SNIFF_MODE_SUPPORTED(x) ((x)[HCI_FEATURE_SNIFF_MODE_OFF] & HCI_FEATURE_SNIFF_MODE_MASK) - -#define HCI_FEATURE_PARK_MODE_MASK 0x01 -#define HCI_FEATURE_PARK_MODE_OFF 1 -#define HCI_PARK_MODE_SUPPORTED(x) ((x)[HCI_FEATURE_PARK_MODE_OFF] & HCI_FEATURE_PARK_MODE_MASK) - -#define HCI_FEATURE_RSSI_MASK 0x02 -#define HCI_FEATURE_RSSI_OFF 1 -#define HCI_RSSI_SUPPORTED(x) ((x)[HCI_FEATURE_RSSI_OFF] & HCI_FEATURE_RSSI_MASK) - -#define HCI_FEATURE_CQM_DATA_RATE_MASK 0x04 -#define HCI_FEATURE_CQM_DATA_RATE_OFF 1 -#define HCI_CQM_DATA_RATE_SUPPORTED(x) ((x)[HCI_FEATURE_CQM_DATA_RATE_OFF] & HCI_FEATURE_CQM_DATA_RATE_MASK) - -#define HCI_FEATURE_SCO_LINK_MASK 0x08 -#define HCI_FEATURE_SCO_LINK_OFF 1 -#define HCI_SCO_LINK_SUPPORTED(x) ((x)[HCI_FEATURE_SCO_LINK_OFF] & HCI_FEATURE_SCO_LINK_MASK) - -#define HCI_FEATURE_HV2_PACKETS_MASK 0x10 -#define HCI_FEATURE_HV2_PACKETS_OFF 1 -#define HCI_HV2_PACKETS_SUPPORTED(x) ((x)[HCI_FEATURE_HV2_PACKETS_OFF] & HCI_FEATURE_HV2_PACKETS_MASK) - -#define HCI_FEATURE_HV3_PACKETS_MASK 0x20 -#define HCI_FEATURE_HV3_PACKETS_OFF 1 -#define HCI_HV3_PACKETS_SUPPORTED(x) ((x)[HCI_FEATURE_HV3_PACKETS_OFF] & HCI_FEATURE_HV3_PACKETS_MASK) - -#define HCI_FEATURE_U_LAW_MASK 0x40 -#define HCI_FEATURE_U_LAW_OFF 1 -#define HCI_LMP_U_LAW_SUPPORTED(x) ((x)[HCI_FEATURE_U_LAW_OFF] & HCI_FEATURE_U_LAW_MASK) - -#define HCI_FEATURE_A_LAW_MASK 0x80 -#define HCI_FEATURE_A_LAW_OFF 1 -#define HCI_LMP_A_LAW_SUPPORTED(x) ((x)[HCI_FEATURE_A_LAW_OFF] & HCI_FEATURE_A_LAW_MASK) - -#define HCI_FEATURE_CVSD_MASK 0x01 -#define HCI_FEATURE_CVSD_OFF 2 -#define HCI_LMP_CVSD_SUPPORTED(x) ((x)[HCI_FEATURE_CVSD_OFF] & HCI_FEATURE_CVSD_MASK) - -#define HCI_FEATURE_PAGING_SCHEME_MASK 0x02 -#define HCI_FEATURE_PAGING_SCHEME_OFF 2 -#define HCI_PAGING_SCHEME_SUPPORTED(x) ((x)[HCI_FEATURE_PAGING_SCHEME_OFF] & HCI_FEATURE_PAGING_SCHEME_MASK) - -#define HCI_FEATURE_POWER_CTRL_MASK 0x04 -#define HCI_FEATURE_POWER_CTRL_OFF 2 -#define HCI_POWER_CTRL_SUPPORTED(x) ((x)[HCI_FEATURE_POWER_CTRL_OFF] & HCI_FEATURE_POWER_CTRL_MASK) - -#define HCI_FEATURE_TRANSPNT_MASK 0x08 -#define HCI_FEATURE_TRANSPNT_OFF 2 -#define HCI_LMP_TRANSPNT_SUPPORTED(x) ((x)[HCI_FEATURE_TRANSPNT_OFF] & HCI_FEATURE_TRANSPNT_MASK) - -#define HCI_FEATURE_FLOW_CTRL_LAG_MASK 0x70 -#define HCI_FEATURE_FLOW_CTRL_LAG_OFF 2 -#define HCI_FLOW_CTRL_LAG_VALUE(x) (((x)[HCI_FEATURE_FLOW_CTRL_LAG_OFF] & HCI_FEATURE_FLOW_CTRL_LAG_MASK) >> 4) - -#define HCI_FEATURE_BROADCAST_ENC_MASK 0x80 -#define HCI_FEATURE_BROADCAST_ENC_OFF 2 -#define HCI_LMP_BCAST_ENC_SUPPORTED(x) ((x)[HCI_FEATURE_BROADCAST_ENC_OFF] & HCI_FEATURE_BROADCAST_ENC_MASK) - -#define HCI_FEATURE_SCATTER_MODE_MASK 0x01 -#define HCI_FEATURE_SCATTER_MODE_OFF 3 -#define HCI_LMP_SCATTER_MODE_SUPPORTED(x) ((x)[HCI_FEATURE_SCATTER_MODE_OFF] & HCI_FEATURE_SCATTER_MODE_MASK) - -#define HCI_FEATURE_EDR_ACL_2MPS_MASK 0x02 -#define HCI_FEATURE_EDR_ACL_2MPS_OFF 3 -#define HCI_EDR_ACL_2MPS_SUPPORTED(x) ((x)[HCI_FEATURE_EDR_ACL_2MPS_OFF] & HCI_FEATURE_EDR_ACL_2MPS_MASK) - -#define HCI_FEATURE_EDR_ACL_3MPS_MASK 0x04 -#define HCI_FEATURE_EDR_ACL_3MPS_OFF 3 -#define HCI_EDR_ACL_3MPS_SUPPORTED(x) ((x)[HCI_FEATURE_EDR_ACL_3MPS_OFF] & HCI_FEATURE_EDR_ACL_3MPS_MASK) - -#define HCI_FEATURE_ENHANCED_INQ_MASK 0x08 -#define HCI_FEATURE_ENHANCED_INQ_OFF 3 -#define HCI_ENHANCED_INQ_SUPPORTED(x) ((x)[HCI_FEATURE_ENHANCED_INQ_OFF] & HCI_FEATURE_ENHANCED_INQ_MASK) - -#define HCI_FEATURE_INTERLACED_INQ_SCAN_MASK 0x10 -#define HCI_FEATURE_INTERLACED_INQ_SCAN_OFF 3 -#define HCI_LMP_INTERLACED_INQ_SCAN_SUPPORTED(x) ((x)[HCI_FEATURE_INTERLACED_INQ_SCAN_OFF] & HCI_FEATURE_INTERLACED_INQ_SCAN_MASK) - -#define HCI_FEATURE_INTERLACED_PAGE_SCAN_MASK 0x20 -#define HCI_FEATURE_INTERLACED_PAGE_SCAN_OFF 3 -#define HCI_LMP_INTERLACED_PAGE_SCAN_SUPPORTED(x) ((x)[HCI_FEATURE_INTERLACED_PAGE_SCAN_OFF] & HCI_FEATURE_INTERLACED_PAGE_SCAN_MASK) - -#define HCI_FEATURE_INQ_RSSI_MASK 0x40 -#define HCI_FEATURE_INQ_RSSI_OFF 3 -#define HCI_LMP_INQ_RSSI_SUPPORTED(x) ((x)[HCI_FEATURE_INQ_RSSI_OFF] & HCI_FEATURE_INQ_RSSI_MASK) - -#define HCI_FEATURE_ESCO_EV3_MASK 0x80 -#define HCI_FEATURE_ESCO_EV3_OFF 3 -#define HCI_ESCO_EV3_SUPPORTED(x) ((x)[HCI_FEATURE_ESCO_EV3_OFF] & HCI_FEATURE_ESCO_EV3_MASK) - -#define HCI_FEATURE_ESCO_EV4_MASK 0x01 -#define HCI_FEATURE_ESCO_EV4_OFF 4 -#define HCI_ESCO_EV4_SUPPORTED(x) ((x)[HCI_FEATURE_ESCO_EV4_OFF] & HCI_FEATURE_ESCO_EV4_MASK) - -#define HCI_FEATURE_ESCO_EV5_MASK 0x02 -#define HCI_FEATURE_ESCO_EV5_OFF 4 -#define HCI_ESCO_EV5_SUPPORTED(x) ((x)[HCI_FEATURE_ESCO_EV5_OFF] & HCI_FEATURE_ESCO_EV5_MASK) - -#define HCI_FEATURE_ABSENCE_MASKS_MASK 0x04 -#define HCI_FEATURE_ABSENCE_MASKS_OFF 4 -#define HCI_LMP_ABSENCE_MASKS_SUPPORTED(x) ((x)[HCI_FEATURE_ABSENCE_MASKS_OFF] & HCI_FEATURE_ABSENCE_MASKS_MASK) - -#define HCI_FEATURE_AFH_CAP_SLAVE_MASK 0x08 -#define HCI_FEATURE_AFH_CAP_SLAVE_OFF 4 -#define HCI_LMP_AFH_CAP_SLAVE_SUPPORTED(x) ((x)[HCI_FEATURE_AFH_CAP_SLAVE_OFF] & HCI_FEATURE_AFH_CAP_SLAVE_MASK) - -#define HCI_FEATURE_AFH_CLASS_SLAVE_MASK 0x10 -#define HCI_FEATURE_AFH_CLASS_SLAVE_OFF 4 -#define HCI_LMP_AFH_CLASS_SLAVE_SUPPORTED(x) ((x)[HCI_FEATURE_AFH_CLASS_SLAVE_OFF] & HCI_FEATURE_AFH_CLASS_SLAVE_MASK) - -#if 1 -#define HCI_FEATURE_BREDR_NOT_SPT_MASK 0x20 -#define HCI_FEATURE_BREDR_NOT_SPT_OFF 4 -#define HCI_BREDR_NOT_SPT_SUPPORTED(x) ((x)[HCI_FEATURE_BREDR_NOT_SPT_OFF] & HCI_FEATURE_BREDR_NOT_SPT_MASK) - -#define HCI_FEATURE_LE_SPT_MASK 0x40 -#define HCI_FEATURE_LE_SPT_OFF 4 -#define HCI_LE_SPT_SUPPORTED(x) ((x)[HCI_FEATURE_LE_SPT_OFF] & HCI_FEATURE_LE_SPT_MASK) -#else - -#define HCI_FEATURE_ALIAS_AUTH_MASK 0x20 -#define HCI_FEATURE_ALIAS_AUTH_OFF 4 -#define HCI_LMP_ALIAS_AUTH_SUPPORTED(x) ((x)[HCI_FEATURE_ALIAS_AUTH_OFF] & HCI_FEATURE_ALIAS_AUTH_MASK) - -#define HCI_FEATURE_ANON_MODE_MASK 0x40 -#define HCI_FEATURE_ANON_MODE_OFF 4 -#define HCI_LMP_ANON_MODE_SUPPORTED(x) ((x)[HCI_FEATURE_ANON_MODE_OFF] & HCI_FEATURE_ANON_MODE_MASK) -#endif - -#define HCI_FEATURE_3_SLOT_EDR_ACL_MASK 0x80 -#define HCI_FEATURE_3_SLOT_EDR_ACL_OFF 4 -#define HCI_3_SLOT_EDR_ACL_SUPPORTED(x) ((x)[HCI_FEATURE_3_SLOT_EDR_ACL_OFF] & HCI_FEATURE_3_SLOT_EDR_ACL_MASK) - -#define HCI_FEATURE_5_SLOT_EDR_ACL_MASK 0x01 -#define HCI_FEATURE_5_SLOT_EDR_ACL_OFF 5 -#define HCI_5_SLOT_EDR_ACL_SUPPORTED(x) ((x)[HCI_FEATURE_5_SLOT_EDR_ACL_OFF] & HCI_FEATURE_5_SLOT_EDR_ACL_MASK) - -#define HCI_FEATURE_SNIFF_SUB_RATE_MASK 0x02 -#define HCI_FEATURE_SNIFF_SUB_RATE_OFF 5 -#define HCI_SNIFF_SUB_RATE_SUPPORTED(x) ((x)[HCI_FEATURE_SNIFF_SUB_RATE_OFF] & HCI_FEATURE_SNIFF_SUB_RATE_MASK) - -#define HCI_FEATURE_ATOMIC_ENCRYPT_MASK 0x04 -#define HCI_FEATURE_ATOMIC_ENCRYPT_OFF 5 -#define HCI_ATOMIC_ENCRYPT_SUPPORTED(x) ((x)[HCI_FEATURE_ATOMIC_ENCRYPT_OFF] & HCI_FEATURE_ATOMIC_ENCRYPT_MASK) - -#define HCI_FEATURE_AFH_CAP_MASTR_MASK 0x08 -#define HCI_FEATURE_AFH_CAP_MASTR_OFF 5 -#define HCI_LMP_AFH_CAP_MASTR_SUPPORTED(x) ((x)[HCI_FEATURE_AFH_CAP_MASTR_OFF] & HCI_FEATURE_AFH_CAP_MASTR_MASK) - -#define HCI_FEATURE_AFH_CLASS_MASTR_MASK 0x10 -#define HCI_FEATURE_AFH_CLASS_MASTR_OFF 5 -#define HCI_LMP_AFH_CLASS_MASTR_SUPPORTED(x) ((x)[HCI_FEATURE_AFH_CLASS_MASTR_OFF] & HCI_FEATURE_AFH_CLASS_MASTR_MASK) - -#define HCI_FEATURE_EDR_ESCO_2MPS_MASK 0x20 -#define HCI_FEATURE_EDR_ESCO_2MPS_OFF 5 -#define HCI_EDR_ESCO_2MPS_SUPPORTED(x) ((x)[HCI_FEATURE_EDR_ESCO_2MPS_OFF] & HCI_FEATURE_EDR_ESCO_2MPS_MASK) - -#define HCI_FEATURE_EDR_ESCO_3MPS_MASK 0x40 -#define HCI_FEATURE_EDR_ESCO_3MPS_OFF 5 -#define HCI_EDR_ESCO_3MPS_SUPPORTED(x) ((x)[HCI_FEATURE_EDR_ESCO_3MPS_OFF] & HCI_FEATURE_EDR_ESCO_3MPS_MASK) - -#define HCI_FEATURE_3_SLOT_EDR_ESCO_MASK 0x80 -#define HCI_FEATURE_3_SLOT_EDR_ESCO_OFF 5 -#define HCI_3_SLOT_EDR_ESCO_SUPPORTED(x) ((x)[HCI_FEATURE_3_SLOT_EDR_ESCO_OFF] & HCI_FEATURE_3_SLOT_EDR_ESCO_MASK) - -#define HCI_FEATURE_EXT_INQ_RSP_MASK 0x01 -#define HCI_FEATURE_EXT_INQ_RSP_OFF 6 -#define HCI_EXT_INQ_RSP_SUPPORTED(x) ((x)[HCI_FEATURE_EXT_INQ_RSP_OFF] & HCI_FEATURE_EXT_INQ_RSP_MASK) - -#if 1 /* TOKYO spec definition */ -#define HCI_FEATURE_SIMUL_LE_BREDR_MASK 0x02 -#define HCI_FEATURE_SIMUL_LE_BREDR_OFF 6 -#define HCI_SIMUL_LE_BREDR_SUPPORTED(x) ((x)[HCI_FEATURE_SIMUL_LE_BREDR_OFF] & HCI_FEATURE_SIMUL_LE_BREDR_MASK) - -#else -#define HCI_FEATURE_ANUM_PIN_AWARE_MASK 0x02 -#define HCI_FEATURE_ANUM_PIN_AWARE_OFF 6 -#define HCI_ANUM_PIN_AWARE_SUPPORTED(x) ((x)[HCI_FEATURE_ANUM_PIN_AWARE_OFF] & HCI_FEATURE_ANUM_PIN_AWARE_MASK) -#endif - -#define HCI_FEATURE_ANUM_PIN_CAP_MASK 0x04 -#define HCI_FEATURE_ANUM_PIN_CAP_OFF 6 -#define HCI_ANUM_PIN_CAP_SUPPORTED(x) ((x)[HCI_FEATURE_ANUM_PIN_CAP_OFF] & HCI_FEATURE_ANUM_PIN_CAP_MASK) - -#define HCI_FEATURE_SIMPLE_PAIRING_MASK 0x08 -#define HCI_FEATURE_SIMPLE_PAIRING_OFF 6 -#define HCI_SIMPLE_PAIRING_SUPPORTED(x) ((x)[HCI_FEATURE_SIMPLE_PAIRING_OFF] & HCI_FEATURE_SIMPLE_PAIRING_MASK) - -#define HCI_FEATURE_ENCAP_PDU_MASK 0x10 -#define HCI_FEATURE_ENCAP_PDU_OFF 6 -#define HCI_ENCAP_PDU_SUPPORTED(x) ((x)[HCI_FEATURE_ENCAP_PDU_OFF] & HCI_FEATURE_ENCAP_PDU_MASK) - -#define HCI_FEATURE_ERROR_DATA_MASK 0x20 -#define HCI_FEATURE_ERROR_DATA_OFF 6 -#define HCI_ERROR_DATA_SUPPORTED(x) ((x)[HCI_FEATURE_ERROR_DATA_OFF] & HCI_FEATURE_ERROR_DATA_MASK) - -#define HCI_FEATURE_NON_FLUSHABLE_PB_MASK 0x40 -#define HCI_FEATURE_NON_FLUSHABLE_PB_OFF 6 - -/* This feature is causing frequent link drops when doing call switch with certain av/hfp headsets */ -#define HCI_NON_FLUSHABLE_PB_SUPPORTED(x) (0) //((x)[HCI_FEATURE_NON_FLUSHABLE_PB_OFF] & HCI_FEATURE_NON_FLUSHABLE_PB_MASK) - -#define HCI_FEATURE_LINK_SUP_TO_EVT_MASK 0x01 -#define HCI_FEATURE_LINK_SUP_TO_EVT_OFF 7 -#define HCI_LINK_SUP_TO_EVT_SUPPORTED(x) ((x)[HCI_FEATURE_LINK_SUP_TO_EVT_OFF] & HCI_FEATURE_LINK_SUP_TO_EVT_MASK) - -#define HCI_FEATURE_INQ_RESP_TX_MASK 0x02 -#define HCI_FEATURE_INQ_RESP_TX_OFF 7 -#define HCI_INQ_RESP_TX_SUPPORTED(x) ((x)[HCI_FEATURE_INQ_RESP_TX_OFF] & HCI_FEATURE_INQ_RESP_TX_MASK) - -#define HCI_FEATURE_EXTENDED_MASK 0x80 -#define HCI_FEATURE_EXTENDED_OFF 7 -#define HCI_LMP_EXTENDED_SUPPORTED(x) ((x)[HCI_FEATURE_EXTENDED_OFF] & HCI_FEATURE_EXTENDED_MASK) - -/* -** LMP features encoding - page 1 -*/ -#define HCI_EXT_FEATURE_SSP_HOST_MASK 0x01 -#define HCI_EXT_FEATURE_SSP_HOST_OFF 0 -#define HCI_SSP_HOST_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_SSP_HOST_OFF] & HCI_EXT_FEATURE_SSP_HOST_MASK) - -#define HCI_EXT_FEATURE_LE_HOST_MASK 0x02 -#define HCI_EXT_FEATURE_LE_HOST_OFF 0 -#define HCI_LE_HOST_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_LE_HOST_OFF] & HCI_EXT_FEATURE_LE_HOST_MASK) - -#define HCI_EXT_FEATURE_SIMUL_DUMO_HOST_MASK 0x04 -#define HCI_EXT_FEATURE_SIMUL_DUMO_HOST_OFF 0 -#define HCI_SIMUL_DUMO_HOST_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_SIMUL_DUMO_HOST_OFF] & HCI_EXT_FEATURE_SIMUL_DUMO_HOST_MASK) - -#define HCI_EXT_FEATURE_SC_HOST_MASK 0x08 -#define HCI_EXT_FEATURE_SC_HOST_OFF 0 -#define HCI_SC_HOST_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_SC_HOST_OFF] & HCI_EXT_FEATURE_SC_HOST_MASK) - -/* -** LMP features encoding - page 2 -*/ -#define HCI_EXT_FEATURE_CSB_MASTER_MASK 0x01 -#define HCI_EXT_FEATURE_CSB_MASTER_OFF 0 -#define HCI_CSB_MASTER_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_CSB_MASTER_OFF] & HCI_EXT_FEATURE_CSB_MASTER_MASK) - -#define HCI_EXT_FEATURE_CSB_SLAVE_MASK 0x02 -#define HCI_EXT_FEATURE_CSB_SLAVE_OFF 0 -#define HCI_CSB_SLAVE_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_CSB_SLAVE_OFF] & HCI_EXT_FEATURE_CSB_SLAVE_MASK) - -#define HCI_EXT_FEATURE_SYNC_TRAIN_MASTER_MASK 0x04 -#define HCI_EXT_FEATURE_SYNC_TRAIN_MASTER_OFF 0 -#define HCI_SYNC_TRAIN_MASTER_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_SYNC_TRAIN_MASTER_OFF] & HCI_EXT_FEATURE_SYNC_TRAIN_MASTER_MASK) - -#define HCI_EXT_FEATURE_SYNC_SCAN_SLAVE_MASK 0x08 -#define HCI_EXT_FEATURE_SYNC_SCAN_SLAVE_OFF 0 -#define HCI_SYNC_SCAN_SLAVE_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_SYNC_SCAN_SLAVE_OFF] & HCI_EXT_FEATURE_SYNC_SCAN_SLAVE_MASK) - -#define HCI_EXT_FEATURE_INQ_RESP_NOTIF_MASK 0x10 -#define HCI_EXT_FEATURE_INQ_RESP_NOTIF_OFF 0 -#define HCI_INQ_RESP_NOTIF_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_INQ_RESP_NOTIF_OFF] & HCI_EXT_FEATURE_INQ_RESP_NOTIF_MASK) - -#define HCI_EXT_FEATURE_SC_CTRLR_MASK 0x01 -#define HCI_EXT_FEATURE_SC_CTRLR_OFF 1 -#define HCI_SC_CTRLR_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_SC_CTRLR_OFF] & HCI_EXT_FEATURE_SC_CTRLR_MASK) - -#define HCI_EXT_FEATURE_PING_MASK 0x02 -#define HCI_EXT_FEATURE_PING_OFF 1 -#define HCI_PING_SUPPORTED(x) ((x)[HCI_EXT_FEATURE_PING_OFF] & HCI_EXT_FEATURE_PING_MASK) - -/* -** LE features encoding - page 0 (the only page for now) -*/ -/* LE Encryption */ -#define HCI_LE_FEATURE_LE_ENCRYPTION_MASK 0x01 -#define HCI_LE_FEATURE_LE_ENCRYPTION_OFF 0 -#define HCI_LE_ENCRYPTION_SUPPORTED(x) ((x)[HCI_LE_FEATURE_LE_ENCRYPTION_OFF] & HCI_LE_FEATURE_LE_ENCRYPTION_MASK) - -/* Connection Parameters Request Procedure */ -#define HCI_LE_FEATURE_CONN_PARAM_REQ_MASK 0x02 -#define HCI_LE_FEATURE_CONN_PARAM_REQ_OFF 0 -#define HCI_LE_CONN_PARAM_REQ_SUPPORTED(x) ((x)[HCI_LE_FEATURE_CONN_PARAM_REQ_OFF] & HCI_LE_FEATURE_CONN_PARAM_REQ_MASK) - -/* Extended Reject Indication */ -#define HCI_LE_FEATURE_EXT_REJ_IND_MASK 0x04 -#define HCI_LE_FEATURE_EXT_REJ_IND_OFF 0 -#define HCI_LE_EXT_REJ_IND_SUPPORTED(x) ((x)[HCI_LE_FEATURE_EXT_REJ_IND_OFF] & HCI_LE_FEATURE_EXT_REJ_IND_MASK) - -/* Slave-initiated Features Exchange */ -#define HCI_LE_FEATURE_SLAVE_INIT_FEAT_EXC_MASK 0x08 -#define HCI_LE_FEATURE_SLAVE_INIT_FEAT_EXC_OFF 0 -#define HCI_LE_SLAVE_INIT_FEAT_EXC_SUPPORTED(x) ((x)[HCI_LE_FEATURE_SLAVE_INIT_FEAT_EXC_OFF] & HCI_LE_FEATURE_SLAVE_INIT_FEAT_EXC_MASK) - -/* Enhanced privacy Feature: bit 6 */ -#define HCI_LE_FEATURE_ENHANCED_PRIVACY_MASK 0x40 -#define HCI_LE_FEATURE_ENHANCED_PRIVACY_OFF 0 -#define HCI_LE_ENHANCED_PRIVACY_SUPPORTED(x) ((x)[HCI_LE_FEATURE_ENHANCED_PRIVACY_OFF] & HCI_LE_FEATURE_ENHANCED_PRIVACY_MASK) - -/* Extended scanner filter policy : 7 */ -#define HCI_LE_FEATURE_EXT_SCAN_FILTER_POLICY_MASK 0x80 -#define HCI_LE_FEATURE_EXT_SCAN_FILTER_POLICY_OFF 0 -#define HCI_LE_EXT_SCAN_FILTER_POLICY_SUPPORTED(x) ((x)[HCI_LE_FEATURE_EXT_SCAN_FILTER_POLICY_OFF] & HCI_LE_FEATURE_EXT_SCAN_FILTER_POLICY_MASK) - -/* Slave-initiated Features Exchange */ -#define HCI_LE_FEATURE_DATA_LEN_EXT_MASK 0x20 -#define HCI_LE_FEATURE_DATA_LEN_EXT_OFF 0 -#define HCI_LE_DATA_LEN_EXT_SUPPORTED(x) ((x)[HCI_LE_FEATURE_DATA_LEN_EXT_OFF] & HCI_LE_FEATURE_DATA_LEN_EXT_MASK) - -/* -** Local Supported Commands encoding -*/ -#define HCI_NUM_SUPP_COMMANDS_BYTES 64 - -/* Supported Commands Byte 0 */ -#define HCI_SUPP_COMMANDS_INQUIRY_MASK 0x01 -#define HCI_SUPP_COMMANDS_INQUIRY_OFF 0 -#define HCI_INQUIRY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_INQUIRY_OFF] & HCI_SUPP_COMMANDS_INQUIRY_MASK) - -#define HCI_SUPP_COMMANDS_INQUIRY_CANCEL_MASK 0x02 -#define HCI_SUPP_COMMANDS_INQUIRY_CANCEL_OFF 0 -#define HCI_INQUIRY_CANCEL_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_INQUIRY_CANCEL_OFF] & HCI_SUPP_COMMANDS_INQUIRY_CANCEL_MASK) - -#define HCI_SUPP_COMMANDS_PERIODIC_INQUIRY_MASK 0x04 -#define HCI_SUPP_COMMANDS_PERIODIC_INQUIRY_OFF 0 -#define HCI_PERIODIC_INQUIRY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_PERIODIC_INQUIRY_OFF] & HCI_SUPP_COMMANDS_PERIODIC_INQUIRY_MASK) - -#define HCI_SUPP_COMMANDS_EXIT_PERIODIC_INQUIRY_MASK 0x08 -#define HCI_SUPP_COMMANDS_EXIT_PERIODIC_INQUIRY_OFF 0 -#define HCI_EXIT_PERIODIC_INQUIRY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_EXIT_PERIODIC_INQUIRY_OFF] & HCI_SUPP_COMMANDS_EXIT_PERIODIC_INQUIRY_MASK) - -#define HCI_SUPP_COMMANDS_CREATE_CONN_MASK 0x10 -#define HCI_SUPP_COMMANDS_CREATE_CONN_OFF 0 -#define HCI_CREATE_CONN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_CREATE_CONN_OFF] & HCI_SUPP_COMMANDS_CREATE_CONN_MASK) - -#define HCI_SUPP_COMMANDS_DISCONNECT_MASK 0x20 -#define HCI_SUPP_COMMANDS_DISCONNECT_OFF 0 -#define HCI_DISCONNECT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_DISCONNECT_OFF] & HCI_SUPP_COMMANDS_DISCONNECT_MASK) - -#define HCI_SUPP_COMMANDS_ADD_SCO_CONN_MASK 0x40 -#define HCI_SUPP_COMMANDS_ADD_SCO_CONN_OFF 0 -#define HCI_ADD_SCO_CONN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ADD_SCO_CONN_OFF] & HCI_SUPP_COMMANDS_ADD_SCO_CONN_MASK) - -#define HCI_SUPP_COMMANDS_CANCEL_CREATE_CONN_MASK 0x80 -#define HCI_SUPP_COMMANDS_CANCEL_CREATE_CONN_OFF 0 -#define HCI_CANCEL_CREATE_CONN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_CANCEL_CREATE_CONN_OFF] & HCI_SUPP_COMMANDS_CANCEL_CREATE_CONN_MASK) - -#define HCI_SUPP_COMMANDS_ACCEPT_CONN_REQUEST_MASK 0x01 -#define HCI_SUPP_COMMANDS_ACCEPT_CONN_REQUEST_OFF 1 -#define HCI_ACCEPT_CONN_REQUEST_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ACCEPT_CONN_REQUEST_OFF] & HCI_SUPP_COMMANDS_ACCEPT_CONN_REQUEST_MASK) - -#define HCI_SUPP_COMMANDS_REJECT_CONN_REQUEST_MASK 0x02 -#define HCI_SUPP_COMMANDS_REJECT_CONN_REQUEST_OFF 1 -#define HCI_REJECT_CONN_REQUEST_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_REJECT_CONN_REQUEST_OFF] & HCI_SUPP_COMMANDS_REJECT_CONN_REQUEST_MASK) - -#define HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_REPLY_MASK 0x04 -#define HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_REPLY_OFF 1 -#define HCI_LINK_KEY_REQUEST_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_REPLY_OFF] & HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_REPLY_MASK) - -#define HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_NEG_REPLY_MASK 0x08 -#define HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_NEG_REPLY_OFF 1 -#define HCI_LINK_KEY_REQUEST_NEG_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_NEG_REPLY_OFF] & HCI_SUPP_COMMANDS_LINK_KEY_REQUEST_NEG_REPLY_MASK) - -#define HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_REPLY_MASK 0x10 -#define HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_REPLY_OFF 1 -#define HCI_PIN_CODE_REQUEST_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_REPLY_OFF] & HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_REPLY_MASK) - -#define HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_NEG_REPLY_MASK 0x20 -#define HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_NEG_REPLY_OFF 1 -#define HCI_PIN_CODE_REQUEST_NEG_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_NEG_REPLY_OFF] & HCI_SUPP_COMMANDS_PIN_CODE_REQUEST_NEG_REPLY_MASK) - -#define HCI_SUPP_COMMANDS_CHANGE_CONN_PKT_TYPE_MASK 0x40 -#define HCI_SUPP_COMMANDS_CHANGE_CONN_PKT_TYPE_OFF 1 -#define HCI_CHANGE_CONN_PKT_TYPE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_CHANGE_CONN_PKT_TYPE_OFF] & HCI_SUPP_COMMANDS_CHANGE_CONN_PKT_TYPE_MASK) - -#define HCI_SUPP_COMMANDS_AUTH_REQUEST_MASK 0x80 -#define HCI_SUPP_COMMANDS_AUTH_REQUEST_OFF 1 -#define HCI_AUTH_REQUEST_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_AUTH_REQUEST_OFF] & HCI_SUPP_COMMANDS_AUTH_REQUEST_MASK) - -#define HCI_SUPP_COMMANDS_SET_CONN_ENCRYPTION_MASK 0x01 -#define HCI_SUPP_COMMANDS_SET_CONN_ENCRYPTION_OFF 2 -#define HCI_SET_CONN_ENCRYPTION_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_CONN_ENCRYPTION_OFF] & HCI_SUPP_COMMANDS_SET_CONN_ENCRYPTION_MASK) - -#define HCI_SUPP_COMMANDS_CHANGE_CONN_LINK_KEY_MASK 0x02 -#define HCI_SUPP_COMMANDS_CHANGE_CONN_LINK_KEY_OFF 2 -#define HCI_CHANGE_CONN_LINK_KEY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_CHANGE_CONN_LINK_KEY_OFF] & HCI_SUPP_COMMANDS_CHANGE_CONN_LINK_KEY_MASK) - -#define HCI_SUPP_COMMANDS_MASTER_LINK_KEY_MASK 0x04 -#define HCI_SUPP_COMMANDS_MASTER_LINK_KEY_OFF 2 -#define HCI_MASTER_LINK_KEY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_MASTER_LINK_KEY_OFF] & HCI_SUPP_COMMANDS_MASTER_LINK_KEY_MASK) - -#define HCI_SUPP_COMMANDS_REMOTE_NAME_REQUEST_MASK 0x08 -#define HCI_SUPP_COMMANDS_REMOTE_NAME_REQUEST_OFF 2 -#define HCI_REMOTE_NAME_REQUEST_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_REMOTE_NAME_REQUEST_OFF] & HCI_SUPP_COMMANDS_REMOTE_NAME_REQUEST_MASK) - -#define HCI_SUPP_COMMANDS_CANCEL_REMOTE_NAME_REQUEST_MASK 0x10 -#define HCI_SUPP_COMMANDS_CANCEL_REMOTE_NAME_REQUEST_OFF 2 -#define HCI_CANCEL_REMOTE_NAME_REQUEST_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_CANCEL_REMOTE_NAME_REQUEST_OFF] & HCI_SUPP_COMMANDS_CANCEL_REMOTE_NAME_REQUEST_MASK) - -#define HCI_SUPP_COMMANDS_READ_REMOTE_SUPP_FEATURES_MASK 0x20 -#define HCI_SUPP_COMMANDS_READ_REMOTE_SUPP_FEATURES_OFF 2 -#define HCI_READ_REMOTE_SUPP_FEATURES_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_REMOTE_SUPP_FEATURES_OFF] & HCI_SUPP_COMMANDS_READ_REMOTE_SUPP_FEATURES_MASK) - -#define HCI_SUPP_COMMANDS_READ_REMOTE_EXT_FEATURES_MASK 0x40 -#define HCI_SUPP_COMMANDS_READ_REMOTE_EXT_FEATURES_OFF 2 -#define HCI_READ_REMOTE_EXT_FEATURES_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_REMOTE_EXT_FEATURES_OFF] & HCI_SUPP_COMMANDS_READ_REMOTE_EXT_FEATURES_MASK) - -#define HCI_SUPP_COMMANDS_READ_REMOTE_VER_INFO_MASK 0x80 -#define HCI_SUPP_COMMANDS_READ_REMOTE_VER_INFO_OFF 2 -#define HCI_READ_REMOTE_VER_INFO_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_REMOTE_VER_INFO_OFF] & HCI_SUPP_COMMANDS_READ_REMOTE_VER_INFO_MASK) - -#define HCI_SUPP_COMMANDS_READ_CLOCK_OFFSET_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_CLOCK_OFFSET_OFF 3 -#define HCI_READ_CLOCK_OFFSET_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_CLOCK_OFFSET_OFF] & HCI_SUPP_COMMANDS_READ_CLOCK_OFFSET_MASK) - -#define HCI_SUPP_COMMANDS_READ_LMP_HANDLE_MASK 0x02 -#define HCI_SUPP_COMMANDS_READ_LMP_HANDLE_OFF 3 -#define HCI_READ_LMP_HANDLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LMP_HANDLE_OFF] & HCI_SUPP_COMMANDS_READ_LMP_HANDLE_MASK) - -#define HCI_SUPP_COMMANDS_HOLD_MODE_CMD_MASK 0x02 -#define HCI_SUPP_COMMANDS_HOLD_MODE_CMD_OFF 4 -#define HCI_HOLD_MODE_CMD_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_HOLD_MODE_CMD_OFF] & HCI_SUPP_COMMANDS_HOLD_MODE_CMD_MASK) - -#define HCI_SUPP_COMMANDS_SNIFF_MODE_CMD_MASK 0x04 -#define HCI_SUPP_COMMANDS_SNIFF_MODE_CMD_OFF 4 -#define HCI_SNIFF_MODE_CMD_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SNIFF_MODE_CMD_OFF] & HCI_SUPP_COMMANDS_SNIFF_MODE_CMD_MASK) - -#define HCI_SUPP_COMMANDS_EXIT_SNIFF_MODE_MASK 0x08 -#define HCI_SUPP_COMMANDS_EXIT_SNIFF_MODE_OFF 4 -#define HCI_EXIT_SNIFF_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_EXIT_SNIFF_MODE_OFF] & HCI_SUPP_COMMANDS_EXIT_SNIFF_MODE_MASK) - -#define HCI_SUPP_COMMANDS_PARK_STATE_MASK 0x10 -#define HCI_SUPP_COMMANDS_PARK_STATE_OFF 4 -#define HCI_PARK_STATE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_PARK_STATE_OFF] & HCI_SUPP_COMMANDS_PARK_STATE_MASK) - -#define HCI_SUPP_COMMANDS_EXIT_PARK_STATE_MASK 0x20 -#define HCI_SUPP_COMMANDS_EXIT_PARK_STATE_OFF 4 -#define HCI_EXIT_PARK_STATE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_EXIT_PARK_STATE_OFF] & HCI_SUPP_COMMANDS_EXIT_PARK_STATE_MASK) - -#define HCI_SUPP_COMMANDS_QOS_SETUP_MASK 0x40 -#define HCI_SUPP_COMMANDS_QOS_SETUP_OFF 4 -#define HCI_QOS_SETUP_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_QOS_SETUP_OFF] & HCI_SUPP_COMMANDS_QOS_SETUP_MASK) - -#define HCI_SUPP_COMMANDS_ROLE_DISCOVERY_MASK 0x80 -#define HCI_SUPP_COMMANDS_ROLE_DISCOVERY_OFF 4 -#define HCI_ROLE_DISCOVERY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ROLE_DISCOVERY_OFF] & HCI_SUPP_COMMANDS_ROLE_DISCOVERY_MASK) - -#define HCI_SUPP_COMMANDS_SWITCH_ROLE_MASK 0x01 -#define HCI_SUPP_COMMANDS_SWITCH_ROLE_OFF 5 -#define HCI_SWITCH_ROLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SWITCH_ROLE_OFF] & HCI_SUPP_COMMANDS_SWITCH_ROLE_MASK) - -#define HCI_SUPP_COMMANDS_READ_LINK_POLICY_SET_MASK 0x02 -#define HCI_SUPP_COMMANDS_READ_LINK_POLICY_SET_OFF 5 -#define HCI_READ_LINK_POLICY_SET_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LINK_POLICY_SET_OFF] & HCI_SUPP_COMMANDS_READ_LINK_POLICY_SET_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_LINK_POLICY_SET_MASK 0x04 -#define HCI_SUPP_COMMANDS_WRITE_LINK_POLICY_SET_OFF 5 -#define HCI_WRITE_LINK_POLICY_SET_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_LINK_POLICY_SET_OFF] & HCI_SUPP_COMMANDS_WRITE_LINK_POLICY_SET_MASK) - -#define HCI_SUPP_COMMANDS_READ_DEF_LINK_POLICY_SET_MASK 0x08 -#define HCI_SUPP_COMMANDS_READ_DEF_LINK_POLICY_SET_OFF 5 -#define HCI_READ_DEF_LINK_POLICY_SET_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_DEF_LINK_POLICY_SET_OFF] & HCI_SUPP_COMMANDS_READ_DEF_LINK_POLICY_SET_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_DEF_LINK_POLICY_SET_MASK 0x10 -#define HCI_SUPP_COMMANDS_WRITE_DEF_LINK_POLICY_SET_OFF 5 -#define HCI_WRITE_DEF_LINK_POLICY_SET_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_DEF_LINK_POLICY_SET_OFF] & HCI_SUPP_COMMANDS_WRITE_DEF_LINK_POLICY_SET_MASK) - -#define HCI_SUPP_COMMANDS_FLOW_SPECIFICATION_MASK 0x20 -#define HCI_SUPP_COMMANDS_FLOW_SPECIFICATION_OFF 5 -#define HCI_FLOW_SPECIFICATION_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_FLOW_SPECIFICATION_OFF] & HCI_SUPP_COMMANDS_FLOW_SPECIFICATION_MASK) - -#define HCI_SUPP_COMMANDS_SET_EVENT_MASK_MASK 0x40 -#define HCI_SUPP_COMMANDS_SET_EVENT_MASK_OFF 5 -#define HCI_SET_EVENT_MASK_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_EVENT_MASK_OFF] & HCI_SUPP_COMMANDS_SET_EVENT_MASK_MASK) - -#define HCI_SUPP_COMMANDS_RESET_MASK 0x80 -#define HCI_SUPP_COMMANDS_RESET_OFF 5 -#define HCI_RESET_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_RESET_OFF] & HCI_SUPP_COMMANDS_RESET_MASK) - -#define HCI_SUPP_COMMANDS_SET_EVENT_FILTER_MASK 0x01 -#define HCI_SUPP_COMMANDS_SET_EVENT_FILTER_OFF 6 -#define HCI_SET_EVENT_FILTER_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_EVENT_FILTER_OFF] & HCI_SUPP_COMMANDS_SET_EVENT_FILTER_MASK) - -#define HCI_SUPP_COMMANDS_FLUSH_MASK 0x02 -#define HCI_SUPP_COMMANDS_FLUSH_OFF 6 -#define HCI_FLUSH_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_FLUSH_OFF] & HCI_SUPP_COMMANDS_FLUSH_MASK) - -#define HCI_SUPP_COMMANDS_READ_PIN_TYPE_MASK 0x04 -#define HCI_SUPP_COMMANDS_READ_PIN_TYPE_OFF 6 -#define HCI_READ_PIN_TYPE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_PIN_TYPE_OFF] & HCI_SUPP_COMMANDS_READ_PIN_TYPE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_PIN_TYPE_MASK 0x08 -#define HCI_SUPP_COMMANDS_WRITE_PIN_TYPE_OFF 6 -#define HCI_WRITE_PIN_TYPE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_PIN_TYPE_OFF] & HCI_SUPP_COMMANDS_WRITE_PIN_TYPE_MASK) - -#define HCI_SUPP_COMMANDS_CREATE_NEW_UNIT_KEY_MASK 0x10 -#define HCI_SUPP_COMMANDS_CREATE_NEW_UNIT_KEY_OFF 6 -#define HCI_CREATE_NEW_UNIT_KEY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_CREATE_NEW_UNIT_KEY_OFF] & HCI_SUPP_COMMANDS_CREATE_NEW_UNIT_KEY_MASK) - -#define HCI_SUPP_COMMANDS_READ_STORED_LINK_KEY_MASK 0x20 -#define HCI_SUPP_COMMANDS_READ_STORED_LINK_KEY_OFF 6 -#define HCI_READ_STORED_LINK_KEY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_STORED_LINK_KEY_OFF] & HCI_SUPP_COMMANDS_READ_STORED_LINK_KEY_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_STORED_LINK_KEY_MASK 0x40 -#define HCI_SUPP_COMMANDS_WRITE_STORED_LINK_KEY_OFF 6 -#define HCI_WRITE_STORED_LINK_KEY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_STORED_LINK_KEY_OFF] & HCI_SUPP_COMMANDS_WRITE_STORED_LINK_KEY_MASK) - -#define HCI_SUPP_COMMANDS_DELETE_STORED_LINK_KEY_MASK 0x80 -#define HCI_SUPP_COMMANDS_DELETE_STORED_LINK_KEY_OFF 6 -#define HCI_DELETE_STORED_LINK_KEY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_DELETE_STORED_LINK_KEY_OFF] & HCI_SUPP_COMMANDS_DELETE_STORED_LINK_KEY_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_LOCAL_NAME_MASK 0x01 -#define HCI_SUPP_COMMANDS_WRITE_LOCAL_NAME_OFF 7 -#define HCI_WRITE_LOCAL_NAME_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_LOCAL_NAME_OFF] & HCI_SUPP_COMMANDS_WRITE_LOCAL_NAME_MASK) - -#define HCI_SUPP_COMMANDS_READ_LOCAL_NAME_MASK 0x02 -#define HCI_SUPP_COMMANDS_READ_LOCAL_NAME_OFF 7 -#define HCI_READ_LOCAL_NAME_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_NAME_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_NAME_MASK) - -#define HCI_SUPP_COMMANDS_READ_CONN_ACCEPT_TOUT_MASK 0x04 -#define HCI_SUPP_COMMANDS_READ_CONN_ACCEPT_TOUT_OFF 7 -#define HCI_READ_CONN_ACCEPT_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_CONN_ACCEPT_TOUT_OFF] & HCI_SUPP_COMMANDS_READ_CONN_ACCEPT_TOUT_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_CONN_ACCEPT_TOUT_MASK 0x08 -#define HCI_SUPP_COMMANDS_WRITE_CONN_ACCEPT_TOUT_OFF 7 -#define HCI_WRITE_CONN_ACCEPT_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_CONN_ACCEPT_TOUT_OFF] & HCI_SUPP_COMMANDS_WRITE_CONN_ACCEPT_TOUT_MASK) - -#define HCI_SUPP_COMMANDS_READ_PAGE_TOUT_MASK 0x10 -#define HCI_SUPP_COMMANDS_READ_PAGE_TOUT_OFF 7 -#define HCI_READ_PAGE_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_PAGE_TOUT_OFF] & HCI_SUPP_COMMANDS_READ_PAGE_TOUT_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_PAGE_TOUT_MASK 0x20 -#define HCI_SUPP_COMMANDS_WRITE_PAGE_TOUT_OFF 7 -#define HCI_WRITE_PAGE_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_PAGE_TOUT_OFF] & HCI_SUPP_COMMANDS_WRITE_PAGE_TOUT_MASK) - -#define HCI_SUPP_COMMANDS_READ_SCAN_ENABLE_MASK 0x40 -#define HCI_SUPP_COMMANDS_READ_SCAN_ENABLE_OFF 7 -#define HCI_READ_SCAN_ENABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_SCAN_ENABLE_OFF] & HCI_SUPP_COMMANDS_READ_SCAN_ENABLE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_SCAN_ENABLE_MASK 0x80 -#define HCI_SUPP_COMMANDS_WRITE_SCAN_ENABLE_OFF 7 -#define HCI_WRITE_SCAN_ENABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_SCAN_ENABLE_OFF] & HCI_SUPP_COMMANDS_WRITE_SCAN_ENABLE_MASK) - -#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_ACTIVITY_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_ACTIVITY_OFF 8 -#define HCI_READ_PAGE_SCAN_ACTIVITY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_PAGE_SCAN_ACTIVITY_OFF] & HCI_SUPP_COMMANDS_READ_PAGE_SCAN_ACTIVITY_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_ACTIVITY_MASK 0x02 -#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_ACTIVITY_OFF 8 -#define HCI_WRITE_PAGE_SCAN_ACTIVITY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_ACTIVITY_OFF] & HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_ACTIVITY_MASK) - -#define HCI_SUPP_COMMANDS_READ_INQURIY_SCAN_ACTIVITY_MASK 0x04 -#define HCI_SUPP_COMMANDS_READ_INQURIY_SCAN_ACTIVITY_OFF 8 -#define HCI_READ_INQURIY_SCAN_ACTIVITY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_INQURIY_SCAN_ACTIVITY_OFF] & HCI_SUPP_COMMANDS_READ_INQURIY_SCAN_ACTIVITY_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_INQURIY_SCAN_ACTIVITY_MASK 0x08 -#define HCI_SUPP_COMMANDS_WRITE_INQURIY_SCAN_ACTIVITY_OFF 8 -#define HCI_WRITE_INQURIY_SCAN_ACTIVITY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_INQURIY_SCAN_ACTIVITY_OFF] & HCI_SUPP_COMMANDS_WRITE_INQURIY_SCAN_ACTIVITY_MASK) - -#define HCI_SUPP_COMMANDS_READ_AUTH_ENABLE_MASK 0x10 -#define HCI_SUPP_COMMANDS_READ_AUTH_ENABLE_OFF 8 -#define HCI_READ_AUTH_ENABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_AUTH_ENABLE_OFF] & HCI_SUPP_COMMANDS_READ_AUTH_ENABLE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_AUTH_ENABLE_MASK 0x20 -#define HCI_SUPP_COMMANDS_WRITE_AUTH_ENABLE_OFF 8 -#define HCI_WRITE_AUTH_ENABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_AUTH_ENABLE_OFF] & HCI_SUPP_COMMANDS_WRITE_AUTH_ENABLE_MASK) - -#define HCI_SUPP_COMMANDS_READ_ENCRYPT_ENABLE_MASK 0x40 -#define HCI_SUPP_COMMANDS_READ_ENCRYPT_ENABLE_OFF 8 -#define HCI_READ_ENCRYPT_ENABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_ENCRYPT_ENABLE_OFF] & HCI_SUPP_COMMANDS_READ_ENCRYPT_ENABLE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_ENCRYPT_ENABLE_MASK 0x80 -#define HCI_SUPP_COMMANDS_WRITE_ENCRYPT_ENABLE_OFF 8 -#define HCI_WRITE_ENCRYPT_ENABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_ENCRYPT_ENABLE_OFF] & HCI_SUPP_COMMANDS_WRITE_ENCRYPT_ENABLE_MASK) - -#define HCI_SUPP_COMMANDS_READ_CLASS_DEVICE_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_CLASS_DEVICE_OFF 9 -#define HCI_READ_CLASS_DEVICE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_CLASS_DEVICE_OFF] & HCI_SUPP_COMMANDS_READ_CLASS_DEVICE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_CLASS_DEVICE_MASK 0x02 -#define HCI_SUPP_COMMANDS_WRITE_CLASS_DEVICE_OFF 9 -#define HCI_WRITE_CLASS_DEVICE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_CLASS_DEVICE_OFF] & HCI_SUPP_COMMANDS_WRITE_CLASS_DEVICE_MASK) - -#define HCI_SUPP_COMMANDS_READ_VOICE_SETTING_MASK 0x04 -#define HCI_SUPP_COMMANDS_READ_VOICE_SETTING_OFF 9 -#define HCI_READ_VOICE_SETTING_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_VOICE_SETTING_OFF] & HCI_SUPP_COMMANDS_READ_VOICE_SETTING_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_VOICE_SETTING_MASK 0x08 -#define HCI_SUPP_COMMANDS_WRITE_VOICE_SETTING_OFF 9 -#define HCI_WRITE_VOICE_SETTING_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_VOICE_SETTING_OFF] & HCI_SUPP_COMMANDS_WRITE_VOICE_SETTING_MASK) - -#define HCI_SUPP_COMMANDS_READ_AUTO_FLUSH_TOUT_MASK 0x10 -#define HCI_SUPP_COMMANDS_READ_AUTO_FLUSH_TOUT_OFF 9 -#define HCI_READ_AUTO_FLUSH_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_AUTO_FLUSH_TOUT_OFF] & HCI_SUPP_COMMANDS_READ_AUTO_FLUSH_TOUT_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_AUTO_FLUSH_TOUT_MASK 0x20 -#define HCI_SUPP_COMMANDS_WRITE_AUTO_FLUSH_TOUT_OFF 9 -#define HCI_WRITE_AUTO_FLUSH_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_AUTO_FLUSH_TOUT_OFF] & HCI_SUPP_COMMANDS_WRITE_AUTO_FLUSH_TOUT_MASK) - -#define HCI_SUPP_COMMANDS_READ_NUM_BROAD_RETRANS_MASK 0x40 -#define HCI_SUPP_COMMANDS_READ_NUM_BROAD_RETRANS_OFF 9 -#define HCI_READ_NUM_BROAD_RETRANS_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_NUM_BROAD_RETRANS_OFF] & HCI_SUPP_COMMANDS_READ_NUM_BROAD_RETRANS_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_NUM_BROAD_RETRANS_MASK 0x80 -#define HCI_SUPP_COMMANDS_WRITE_NUM_BROAD_RETRANS_OFF 9 -#define HCI_WRITE_NUM_BROAD_RETRANS_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_NUM_BROAD_RETRANS_OFF] & HCI_SUPP_COMMANDS_WRITE_NUM_BROAD_RETRANS_MASK) - -#define HCI_SUPP_COMMANDS_READ_HOLD_MODE_ACTIVITY_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_HOLD_MODE_ACTIVITY_OFF 10 -#define HCI_READ_HOLD_MODE_ACTIVITY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_HOLD_MODE_ACTIVITY_OFF] & HCI_SUPP_COMMANDS_READ_HOLD_MODE_ACTIVITY_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_HOLD_MODE_ACTIVITY_MASK 0x02 -#define HCI_SUPP_COMMANDS_WRITE_HOLD_MODE_ACTIVITY_OFF 10 -#define HCI_WRITE_HOLD_MODE_ACTIVITY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_HOLD_MODE_ACTIVITY_OFF] & HCI_SUPP_COMMANDS_WRITE_HOLD_MODE_ACTIVITY_MASK) - -#define HCI_SUPP_COMMANDS_READ_TRANS_PWR_LEVEL_MASK 0x04 -#define HCI_SUPP_COMMANDS_READ_TRANS_PWR_LEVEL_OFF 10 -#define HCI_READ_TRANS_PWR_LEVEL_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_TRANS_PWR_LEVEL_OFF] & HCI_SUPP_COMMANDS_READ_TRANS_PWR_LEVEL_MASK) - -#define HCI_SUPP_COMMANDS_READ_SYNCH_FLOW_CTRL_ENABLE_MASK 0x08 -#define HCI_SUPP_COMMANDS_READ_SYNCH_FLOW_CTRL_ENABLE_OFF 10 -#define HCI_READ_SYNCH_FLOW_CTRL_ENABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_SYNCH_FLOW_CTRL_ENABLE_OFF] & HCI_SUPP_COMMANDS_READ_SYNCH_FLOW_CTRL_ENABLE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_SYNCH_FLOW_CTRL_ENABLE_MASK 0x10 -#define HCI_SUPP_COMMANDS_WRITE_SYNCH_FLOW_CTRL_ENABLE_OFF 10 -#define HCI_WRITE_SYNCH_FLOW_CTRL_ENABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_SYNCH_FLOW_CTRL_ENABLE_OFF] & HCI_SUPP_COMMANDS_WRITE_SYNCH_FLOW_CTRL_ENABLE_MASK) - -#define HCI_SUPP_COMMANDS_SET_HOST_CTRLR_TO_HOST_FC_MASK 0x20 -#define HCI_SUPP_COMMANDS_SET_HOST_CTRLR_TO_HOST_FC_OFF 10 -#define HCI_SET_HOST_CTRLR_TO_HOST_FC_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_HOST_CTRLR_TO_HOST_FC_OFF] & HCI_SUPP_COMMANDS_SET_HOST_CTRLR_TO_HOST_FC_MASK) - -#define HCI_SUPP_COMMANDS_HOST_BUFFER_SIZE_MASK 0x40 -#define HCI_SUPP_COMMANDS_HOST_BUFFER_SIZE_OFF 10 -#define HCI_HOST_BUFFER_SIZE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_HOST_BUFFER_SIZE_OFF] & HCI_SUPP_COMMANDS_HOST_BUFFER_SIZE_MASK) - -#define HCI_SUPP_COMMANDS_HOST_NUM_COMPLETED_PKTS_MASK 0x80 -#define HCI_SUPP_COMMANDS_HOST_NUM_COMPLETED_PKTS_OFF 10 -#define HCI_HOST_NUM_COMPLETED_PKTS_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_HOST_NUM_COMPLETED_PKTS_OFF] & HCI_SUPP_COMMANDS_HOST_NUM_COMPLETED_PKTS_MASK) - -#define HCI_SUPP_COMMANDS_READ_LINK_SUP_TOUT_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_LINK_SUP_TOUT_OFF 11 -#define HCI_READ_LINK_SUP_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LINK_SUP_TOUT_OFF] & HCI_SUPP_COMMANDS_READ_LINK_SUP_TOUT_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_LINK_SUP_TOUT_MASK 0x02 -#define HCI_SUPP_COMMANDS_WRITE_LINK_SUP_TOUT_OFF 11 -#define HCI_WRITE_LINK_SUP_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_LINK_SUP_TOUT_OFF] & HCI_SUPP_COMMANDS_WRITE_LINK_SUP_TOUT_MASK) - -#define HCI_SUPP_COMMANDS_READ_NUM_SUPP_IAC_MASK 0x04 -#define HCI_SUPP_COMMANDS_READ_NUM_SUPP_IAC_OFF 11 -#define HCI_READ_NUM_SUPP_IAC_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_NUM_SUPP_IAC_OFF] & HCI_SUPP_COMMANDS_READ_NUM_SUPP_IAC_MASK) - -#define HCI_SUPP_COMMANDS_READ_CURRENT_IAC_LAP_MASK 0x08 -#define HCI_SUPP_COMMANDS_READ_CURRENT_IAC_LAP_OFF 11 -#define HCI_READ_CURRENT_IAC_LAP_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_CURRENT_IAC_LAP_OFF] & HCI_SUPP_COMMANDS_READ_CURRENT_IAC_LAP_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_CURRENT_IAC_LAP_MASK 0x10 -#define HCI_SUPP_COMMANDS_WRITE_CURRENT_IAC_LAP_OFF 11 -#define HCI_WRITE_CURRENT_IAC_LAP_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_CURRENT_IAC_LAP_OFF] & HCI_SUPP_COMMANDS_WRITE_CURRENT_IAC_LAP_MASK) - -#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_PER_MODE_MASK 0x20 -#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_PER_MODE_OFF 11 -#define HCI_READ_PAGE_SCAN_PER_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_PAGE_SCAN_PER_MODE_OFF] & HCI_SUPP_COMMANDS_READ_PAGE_SCAN_PER_MODE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_PER_MODE_MASK 0x40 -#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_PER_MODE_OFF 11 -#define HCI_WRITE_PAGE_SCAN_PER_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_PER_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_PER_MODE_MASK) - -#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_MODE_MASK 0x80 -#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_MODE_OFF 11 -#define HCI_READ_PAGE_SCAN_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_PAGE_SCAN_MODE_OFF] & HCI_SUPP_COMMANDS_READ_PAGE_SCAN_MODE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_MODE_MASK 0x01 -#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_MODE_OFF 12 -#define HCI_WRITE_PAGE_SCAN_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_MODE_MASK) - -#define HCI_SUPP_COMMANDS_SET_AFH_CHNL_CLASS_MASK 0x02 -#define HCI_SUPP_COMMANDS_SET_AFH_CHNL_CLASS_OFF 12 -#define HCI_SET_AFH_CHNL_CLASS_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_AFH_CHNL_CLASS_OFF] & HCI_SUPP_COMMANDS_SET_AFH_CHNL_CLASS_MASK) - -#define HCI_SUPP_COMMANDS_READ_INQUIRY_SCAN_TYPE_MASK 0x10 -#define HCI_SUPP_COMMANDS_READ_INQUIRY_SCAN_TYPE_OFF 12 -#define HCI_READ_INQUIRY_SCAN_TYPE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_INQUIRY_SCAN_TYPE_OFF] & HCI_SUPP_COMMANDS_READ_INQUIRY_SCAN_TYPE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_INQUIRY_SCAN_TYPE_MASK 0x20 -#define HCI_SUPP_COMMANDS_WRITE_INQUIRY_SCAN_TYPE_OFF 12 -#define HCI_WRITE_INQUIRY_SCAN_TYPE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_INQUIRY_SCAN_TYPE_OFF] & HCI_SUPP_COMMANDS_WRITE_INQUIRY_SCAN_TYPE_MASK) - -#define HCI_SUPP_COMMANDS_READ_INQUIRY_MODE_MASK 0x40 -#define HCI_SUPP_COMMANDS_READ_INQUIRY_MODE_OFF 12 -#define HCI_READ_INQUIRY_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_INQUIRY_MODE_OFF] & HCI_SUPP_COMMANDS_READ_INQUIRY_MODE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_INQUIRY_MODE_MASK 0x80 -#define HCI_SUPP_COMMANDS_WRITE_INQUIRY_MODE_OFF 12 -#define HCI_WRITE_INQUIRY_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_INQUIRY_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_INQUIRY_MODE_MASK) - -#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_TYPE_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_PAGE_SCAN_TYPE_OFF 13 -#define HCI_READ_PAGE_SCAN_TYPE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_PAGE_SCAN_TYPE_OFF] & HCI_SUPP_COMMANDS_READ_PAGE_SCAN_TYPE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_TYPE_MASK 0x02 -#define HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_TYPE_OFF 13 -#define HCI_WRITE_PAGE_SCAN_TYPE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_TYPE_OFF] & HCI_SUPP_COMMANDS_WRITE_PAGE_SCAN_TYPE_MASK) - -#define HCI_SUPP_COMMANDS_READ_AFH_CHNL_ASSESS_MODE_MASK 0x04 -#define HCI_SUPP_COMMANDS_READ_AFH_CHNL_ASSESS_MODE_OFF 13 -#define HCI_READ_AFH_CHNL_ASSESS_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_AFH_CHNL_ASSESS_MODE_OFF] & HCI_SUPP_COMMANDS_READ_AFH_CHNL_ASSESS_MODE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_AFH_CHNL_ASSESS_MODE_MASK 0x08 -#define HCI_SUPP_COMMANDS_WRITE_AFH_CHNL_ASSESS_MODE_OFF 13 -#define HCI_WRITE_AFH_CHNL_ASSESS_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_AFH_CHNL_ASSESS_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_AFH_CHNL_ASSESS_MODE_MASK) - -#define HCI_SUPP_COMMANDS_READ_LOCAL_VER_INFO_MASK 0x08 -#define HCI_SUPP_COMMANDS_READ_LOCAL_VER_INFO_OFF 14 -#define HCI_READ_LOCAL_VER_INFO_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_VER_INFO_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_VER_INFO_MASK) - -#define HCI_SUPP_COMMANDS_READ_LOCAL_SUP_CMDS_MASK 0x10 -#define HCI_SUPP_COMMANDS_READ_LOCAL_SUP_CMDS_OFF 14 -#define HCI_READ_LOCAL_SUP_CMDS_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_SUP_CMDS_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_SUP_CMDS_MASK) - -#define HCI_SUPP_COMMANDS_READ_LOCAL_SUPP_FEATURES_MASK 0x20 -#define HCI_SUPP_COMMANDS_READ_LOCAL_SUPP_FEATURES_OFF 14 -#define HCI_READ_LOCAL_SUPP_FEATURES_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_SUPP_FEATURES_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_SUPP_FEATURES_MASK) - -#define HCI_SUPP_COMMANDS_READ_LOCAL_EXT_FEATURES_MASK 0x40 -#define HCI_SUPP_COMMANDS_READ_LOCAL_EXT_FEATURES_OFF 14 -#define HCI_READ_LOCAL_EXT_FEATURES_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_EXT_FEATURES_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_EXT_FEATURES_MASK) - -#define HCI_SUPP_COMMANDS_READ_BUFFER_SIZE_MASK 0x80 -#define HCI_SUPP_COMMANDS_READ_BUFFER_SIZE_OFF 14 -#define HCI_READ_BUFFER_SIZE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_BUFFER_SIZE_OFF] & HCI_SUPP_COMMANDS_READ_BUFFER_SIZE_MASK) - -#define HCI_SUPP_COMMANDS_READ_COUNTRY_CODE_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_COUNTRY_CODE_OFF 15 -#define HCI_READ_COUNTRY_CODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_COUNTRY_CODE_OFF] & HCI_SUPP_COMMANDS_READ_COUNTRY_CODE_MASK) - -#define HCI_SUPP_COMMANDS_READ_BD_ADDR_MASK 0x02 -#define HCI_SUPP_COMMANDS_READ_BD_ADDR_OFF 15 -#define HCI_READ_BD_ADDR_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_BD_ADDR_OFF] & HCI_SUPP_COMMANDS_READ_BD_ADDR_MASK) - -#define HCI_SUPP_COMMANDS_READ_FAIL_CONTACT_CNTR_MASK 0x04 -#define HCI_SUPP_COMMANDS_READ_FAIL_CONTACT_CNTR_OFF 15 -#define HCI_READ_FAIL_CONTACT_CNTR_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_FAIL_CONTACT_CNTR_OFF] & HCI_SUPP_COMMANDS_READ_FAIL_CONTACT_CNTR_MASK) - -#define HCI_SUPP_COMMANDS_RESET_FAIL_CONTACT_CNTR_MASK 0x08 -#define HCI_SUPP_COMMANDS_RESET_FAIL_CONTACT_CNTR_OFF 15 -#define HCI_RESET_FAIL_CONTACT_CNTR_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_RESET_FAIL_CONTACT_CNTR_OFF] & HCI_SUPP_COMMANDS_RESET_FAIL_CONTACT_CNTR_MASK) - -#define HCI_SUPP_COMMANDS_GET_LINK_QUALITY_MASK 0x10 -#define HCI_SUPP_COMMANDS_GET_LINK_QUALITY_OFF 15 -#define HCI_GET_LINK_QUALITY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_GET_LINK_QUALITY_OFF] & HCI_SUPP_COMMANDS_GET_LINK_QUALITY_MASK) - -#define HCI_SUPP_COMMANDS_READ_RSSI_MASK 0x20 -#define HCI_SUPP_COMMANDS_READ_RSSI_OFF 15 -#define HCI_READ_RSSI_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_RSSI_OFF] & HCI_SUPP_COMMANDS_READ_RSSI_MASK) - -#define HCI_SUPP_COMMANDS_READ_AFH_CH_MAP_MASK 0x40 -#define HCI_SUPP_COMMANDS_READ_AFH_CH_MAP_OFF 15 -#define HCI_READ_AFH_CH_MAP_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_AFH_CH_MAP_OFF] & HCI_SUPP_COMMANDS_READ_AFH_CH_MAP_MASK) - -#define HCI_SUPP_COMMANDS_READ_BD_CLOCK_MASK 0x80 -#define HCI_SUPP_COMMANDS_READ_BD_CLOCK_OFF 15 -#define HCI_READ_BD_CLOCK_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_BD_CLOCK_OFF] & HCI_SUPP_COMMANDS_READ_BD_CLOCK_MASK) - -#define HCI_SUPP_COMMANDS_READ_LOOPBACK_MODE_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_LOOPBACK_MODE_OFF 16 -#define HCI_READ_LOOPBACK_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOOPBACK_MODE_OFF] & HCI_SUPP_COMMANDS_READ_LOOPBACK_MODE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_LOOPBACK_MODE_MASK 0x02 -#define HCI_SUPP_COMMANDS_WRITE_LOOPBACK_MODE_OFF 16 -#define HCI_WRITE_LOOPBACK_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_LOOPBACK_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_LOOPBACK_MODE_MASK) - -#define HCI_SUPP_COMMANDS_ENABLE_DEV_UNDER_TEST_MASK 0x04 -#define HCI_SUPP_COMMANDS_ENABLE_DEV_UNDER_TEST_OFF 16 -#define HCI_ENABLE_DEV_UNDER_TEST_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ENABLE_DEV_UNDER_TEST_OFF] & HCI_SUPP_COMMANDS_ENABLE_DEV_UNDER_TEST_MASK) - -#define HCI_SUPP_COMMANDS_SETUP_SYNCH_CONN_MASK 0x08 -#define HCI_SUPP_COMMANDS_SETUP_SYNCH_CONN_OFF 16 -#define HCI_SETUP_SYNCH_CONN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SETUP_SYNCH_CONN_OFF] & HCI_SUPP_COMMANDS_SETUP_SYNCH_CONN_MASK) - -#define HCI_SUPP_COMMANDS_ACCEPT_SYNCH_CONN_MASK 0x10 -#define HCI_SUPP_COMMANDS_ACCEPT_SYNCH_CONN_OFF 16 -#define HCI_ACCEPT_SYNCH_CONN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ACCEPT_SYNCH_CONN_OFF] & HCI_SUPP_COMMANDS_ACCEPT_SYNCH_CONN_MASK) - -#define HCI_SUPP_COMMANDS_REJECT_SYNCH_CONN_MASK 0x20 -#define HCI_SUPP_COMMANDS_REJECT_SYNCH_CONN_OFF 16 -#define HCI_REJECT_SYNCH_CONN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_REJECT_SYNCH_CONN_OFF] & HCI_SUPP_COMMANDS_REJECT_SYNCH_CONN_MASK) - -#define HCI_SUPP_COMMANDS_READ_EXT_INQUIRY_RESP_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_EXT_INQUIRY_RESP_OFF 17 -#define HCI_READ_EXT_INQUIRY_RESP_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_EXT_INQUIRY_RESP_OFF] & HCI_SUPP_COMMANDS_READ_EXT_INQUIRY_RESP_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_EXT_INQUIRY_RESP_MASK 0x02 -#define HCI_SUPP_COMMANDS_WRITE_EXT_INQUIRY_RESP_OFF 17 -#define HCI_WRITE_EXT_INQUIRY_RESP_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_EXT_INQUIRY_RESP_OFF] & HCI_SUPP_COMMANDS_WRITE_EXT_INQUIRY_RESP_MASK) - -#define HCI_SUPP_COMMANDS_REFRESH_ENCRYPTION_KEY_MASK 0x04 -#define HCI_SUPP_COMMANDS_REFRESH_ENCRYPTION_KEY_OFF 17 -#define HCI_REFRESH_ENCRYPTION_KEY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_REFRESH_ENCRYPTION_KEY_OFF] & HCI_SUPP_COMMANDS_REFRESH_ENCRYPTION_KEY_MASK) - -/* Octet 17, bit 3 is reserved */ - -#define HCI_SUPP_COMMANDS_SNIFF_SUB_RATE_MASK 0x10 -#define HCI_SUPP_COMMANDS_SNIFF_SUB_RATE_OFF 17 -#define HCI_SNIFF_SUB_RATE_CMD_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SNIFF_SUB_RATE_OFF] & HCI_SUPP_COMMANDS_SNIFF_SUB_RATE_MASK) - -#define HCI_SUPP_COMMANDS_READ_SIMPLE_PAIRING_MODE_MASK 0x20 -#define HCI_SUPP_COMMANDS_READ_SIMPLE_PAIRING_MODE_OFF 17 -#define HCI_READ_SIMPLE_PAIRING_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_SIMPLE_PAIRING_MODE_OFF] & HCI_SUPP_COMMANDS_READ_SIMPLE_PAIRING_MODE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_MODE_MASK 0x40 -#define HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_MODE_OFF 17 -#define HCI_WRITE_SIMPLE_PAIRING_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_MODE_MASK) - -#define HCI_SUPP_COMMANDS_READ_LOCAL_OOB_DATA_MASK 0x80 -#define HCI_SUPP_COMMANDS_READ_LOCAL_OOB_DATA_OFF 17 -#define HCI_READ_LOCAL_OOB_DATA_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_OOB_DATA_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_OOB_DATA_MASK) - -#define HCI_SUPP_COMMANDS_READ_INQUIRY_RESPONSE_TX_POWER_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_INQUIRY_RESPONSE_TX_POWER_OFF 18 -#define HCI_READ_INQUIRY_RESPONSE_TX_POWER_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_INQUIRY_RESPONSE_TX_POWER_OFF] & HCI_SUPP_COMMANDS_READ_INQUIRY_RESPONSE_TX_POWER_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_INQUIRY_RESPONSE_TX_POWER_MASK 0x02 -#define HCI_SUPP_COMMANDS_WRITE_INQUIRY_RESPONSE_TX_POWER_OFF 18 -#define HCI_WRITE_INQUIRY_RESPONSE_TX_POWER_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_INQUIRY_RESPONSE_TX_POWER_OFF] & HCI_SUPP_COMMANDS_WRITE_INQUIRY_RESPONSE_TX_POWER_MASK) - -#define HCI_SUPP_COMMANDS_READ_DEFAULT_ERRONEOUS_DATA_REPORTING_MASK 0x04 -#define HCI_SUPP_COMMANDS_READ_DEFAULT_ERRONEOUS_DATA_REPORTING_OFF 18 -#define HCI_READ_DEFAULT_ERRONEOUS_DATA_REPORTING_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_DEFAULT_ERRONEOUS_DATA_REPORTING_OFF] & HCI_SUPP_COMMANDS_READ_DEFAULT_ERRONEOUS_DATA_REPORTING_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING_MASK 0x08 -#define HCI_SUPP_COMMANDS_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING_OFF 18 -#define HCI_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING_OFF] & HCI_SUPP_COMMANDS_WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING_MASK) - -#define HCI_SUPP_COMMANDS_IO_CAPABILITY_REQUEST_REPLY_MASK 0x80 -#define HCI_SUPP_COMMANDS_IO_CAPABILITY_REQUEST_REPLY_OFF 18 -#define HCI_IO_CAPABILITY_REQUEST_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_IO_CAPABILITY_REQUEST_REPLY_OFF] & HCI_SUPP_COMMANDS_IO_CAPABILITY_REQUEST_REPLY_MASK) - -#define HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_REPLY_MASK 0x01 -#define HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_REPLY_OFF 19 -#define HCI_USER_CONFIRMATION_REQUEST_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_REPLY_OFF] & HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_REPLY_MASK) - -#define HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_NEG_REPLY_MASK 0x02 -#define HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_NEG_REPLY_OFF 19 -#define HCI_USER_CONFIRMATION_REQUEST_NEG_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_NEG_REPLY_OFF] & HCI_SUPP_COMMANDS_USER_CONFIRMATION_REQUEST_NEG_REPLY_MASK) - -#define HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_REPLY_MASK 0x04 -#define HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_REPLY_OFF 19 -#define HCI_USER_PASSKEY_REQUEST_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_REPLY_OFF] & HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_REPLY_MASK) - -#define HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_NEG_REPLY_MASK 0x08 -#define HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_NEG_REPLY_OFF 19 -#define HCI_USER_PASSKEY_REQUEST_NEG_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_NEG_REPLY_OFF] & HCI_SUPP_COMMANDS_USER_PASSKEY_REQUEST_NEG_REPLY_MASK) - -#define HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_REPLY_MASK 0x10 -#define HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_REPLY_OFF 19 -#define HCI_REMOTE_OOB_DATA_REQUEST_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_REPLY_OFF] & HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_REPLY_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_DBG_MODE_MASK 0x20 -#define HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_DBG_MODE_OFF 19 -#define HCI_WRITE_SIMPLE_PAIRING_DBG_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_DBG_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_SIMPLE_PAIRING_DBG_MODE_MASK) - -#define HCI_SUPP_COMMANDS_ENHANCED_FLUSH_MASK 0x40 -#define HCI_SUPP_COMMANDS_ENHANCED_FLUSH_OFF 19 -#define HCI_ENHANCED_FLUSH_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ENHANCED_FLUSH_OFF] & HCI_SUPP_COMMANDS_ENHANCED_FLUSH_MASK) - -#define HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_NEG_REPLY_MASK 0x80 -#define HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_NEG_REPLY_OFF 19 -#define HCI_REMOTE_OOB_DATA_REQUEST_NEG_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_NEG_REPLY_OFF] & HCI_SUPP_COMMANDS_REMOTE_OOB_DATA_REQUEST_NEG_REPLY_MASK) - -/* Supported Commands (Byte 20) */ -#define HCI_SUPP_COMMANDS_SEND_KEYPRESS_NOTIF_MASK 0x04 -#define HCI_SUPP_COMMANDS_SEND_KEYPRESS_NOTIF_OFF 20 -#define HCI_SEND_NOTIF_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SEND_KEYPRESS_NOTIF_OFF] & HCI_SUPP_COMMANDS_SEND_KEYPRESS_NOTIF_MASK) - -#define HCI_SUPP_COMMANDS_IO_CAP_REQ_NEG_REPLY_MASK 0x08 -#define HCI_SUPP_COMMANDS_IO_CAP_REQ_NEG_REPLY_OFF 20 -#define HCI_IO_CAP_REQ_NEG_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_IO_CAP_REQ_NEG_REPLY_OFF] & HCI_SUPP_COMMANDS_IO_CAP_REQ_NEG_REPLY_MASK) - -#define HCI_SUPP_COMMANDS_READ_ENCR_KEY_SIZE_MASK 0x10 -#define HCI_SUPP_COMMANDS_READ_ENCR_KEY_SIZE_OFF 20 -#define HCI_READ_ENCR_KEY_SIZE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_ENCR_KEY_SIZE_OFF] & HCI_SUPP_COMMANDS_READ_ENCR_KEY_SIZE_MASK) - -/* Supported Commands (Byte 21) */ -#define HCI_SUPP_COMMANDS_CREATE_PHYSICAL_LINK_MASK 0x01 -#define HCI_SUPP_COMMANDS_CREATE_PHYSICAL_LINK_OFF 21 -#define HCI_CREATE_PHYSICAL_LINK_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_CREATE_PHYSICAL_LINK_OFF] & HCI_SUPP_COMMANDS_CREATE_PHYSICAL_LINK_MASK) - -#define HCI_SUPP_COMMANDS_ACCEPT_PHYSICAL_LINK_MASK 0x02 -#define HCI_SUPP_COMMANDS_ACCEPT_PHYSICAL_LINK_OFF 21 -#define HCI_ACCEPT_PHYSICAL_LINK_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ACCEPT_PHYSICAL_LINK_OFF] & HCI_SUPP_COMMANDS_ACCEPT_PHYSICAL_LINK_MASK) - -#define HCI_SUPP_COMMANDS_DISCONNECT_PHYSICAL_LINK_MASK 0x04 -#define HCI_SUPP_COMMANDS_DISCONNECT_PHYSICAL_LINK_OFF 21 -#define HCI_DISCONNECT_PHYSICAL_LINK_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_DISCONNECT_PHYSICAL_LINK_OFF] & HCI_SUPP_COMMANDS_DISCONNECT_PHYSICAL_LINK_MASK) - -#define HCI_SUPP_COMMANDS_CREATE_LOGICAL_LINK_MASK 0x08 -#define HCI_SUPP_COMMANDS_CREATE_LOGICAL_LINK_OFF 21 -#define HCI_CREATE_LOGICAL_LINK_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_CREATE_LOGICAL_LINK_OFF] & HCI_SUPP_COMMANDS_CREATE_LOGICAL_LINK_MASK) - -#define HCI_SUPP_COMMANDS_ACCEPT_LOGICAL_LINK_MASK 0x10 -#define HCI_SUPP_COMMANDS_ACCEPT_LOGICAL_LINK_OFF 21 -#define HCI_ACCEPT_LOGICAL_LINK_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ACCEPT_LOGICAL_LINK_OFF] & HCI_SUPP_COMMANDS_ACCEPT_LOGICAL_LINK_MASK) - -#define HCI_SUPP_COMMANDS_DISCONNECT_LOGICAL_LINK_MASK 0x20 -#define HCI_SUPP_COMMANDS_DISCONNECT_LOGICAL_LINK_OFF 21 -#define HCI_DISCONNECT_LOGICAL_LINK_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_DISCONNECT_LOGICAL_LINK_OFF] & HCI_SUPP_COMMANDS_DISCONNECT_LOGICAL_LINK_MASK) - -#define HCI_SUPP_COMMANDS_LOGICAL_LINK_CANCEL_MASK 0x40 -#define HCI_SUPP_COMMANDS_LOGICAL_LINK_CANCEL_OFF 21 -#define HCI_LOGICAL_LINK_CANCEL_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_LOGICAL_LINK_CANCEL_OFF] & HCI_SUPP_COMMANDS_LOGICAL_LINK_CANCEL_MASK) - -#define HCI_SUPP_COMMANDS_FLOW_SPEC_MODIFY_MASK 0x80 -#define HCI_SUPP_COMMANDS_FLOW_SPEC_MODIFY_OFF 21 -#define HCI_FLOW_SPEC_MODIFY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_FLOW_SPEC_MODIFY_OFF] & HCI_SUPP_COMMANDS_FLOW_SPEC_MODIFY_MASK) - -/* Supported Commands (Byte 22) */ -#define HCI_SUPP_COMMANDS_READ_LOGICAL_LINK_ACCEPT_TIMEOUT_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_LOGICAL_LINK_ACCEPT_TIMEOUT_OFF 22 -#define HCI_READ_LOGICAL_LINK_ACCEPT_TIMEOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOGICAL_LINK_ACCEPT_TIMEOUT_OFF] & HCI_SUPP_COMMANDS_READ_LOGICAL_LINK_ACCEPT_TIMEOUT_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT_MASK 0x02 -#define HCI_SUPP_COMMANDS_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT_OFF 22 -#define HCI_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT_OFF] & HCI_SUPP_COMMANDS_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT_MASK) - -#define HCI_SUPP_COMMANDS_SET_EVENT_MASK_PAGE_2_MASK 0x04 -#define HCI_SUPP_COMMANDS_SET_EVENT_MASK_PAGE_2_OFF 22 -#define HCI_SET_EVENT_MASK_PAGE_2_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_EVENT_MASK_PAGE_2_OFF] & HCI_SUPP_COMMANDS_SET_EVENT_MASK_PAGE_2_MASK) - -#define HCI_SUPP_COMMANDS_READ_LOCATION_DATA_MASK 0x08 -#define HCI_SUPP_COMMANDS_READ_LOCATION_DATA_OFF 22 -#define HCI_READ_LOCATION_DATA_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCATION_DATA_OFF] & HCI_SUPP_COMMANDS_READ_LOCATION_DATA_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_LOCATION_DATA_MASK 0x10 -#define HCI_SUPP_COMMANDS_WRITE_LOCATION_DATA_OFF 22 -#define HCI_WRITE_LOCATION_DATA_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_LOCATION_DATA_OFF] & HCI_SUPP_COMMANDS_WRITE_LOCATION_DATA_MASK) - -#define HCI_SUPP_COMMANDS_READ_LOCAL_AMP_INFO_MASK 0x20 -#define HCI_SUPP_COMMANDS_READ_LOCAL_AMP_INFO_OFF 22 -#define HCI_READ_LOCAL_AMP_INFO_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_AMP_INFO_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_AMP_INFO_MASK) - -#define HCI_SUPP_COMMANDS_READ_LOCAL_AMP_ASSOC_MASK 0x40 -#define HCI_SUPP_COMMANDS_READ_LOCAL_AMP_ASSOC_OFF 22 -#define HCI_READ_LOCAL_AMP_ASSOC_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_AMP_ASSOC_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_AMP_ASSOC_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_REMOTE_AMP_ASSOC_MASK 0x80 -#define HCI_SUPP_COMMANDS_WRITE_REMOTE_AMP_ASSOC_OFF 22 -#define HCI_WRITE_REMOTE_AMP_ASSOC_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_REMOTE_AMP_ASSOC_OFF] & HCI_SUPP_COMMANDS_WRITE_REMOTE_AMP_ASSOC_MASK) - -/* Supported Commands (Byte 23) */ -#define HCI_SUPP_COMMANDS_READ_FLOW_CONTROL_MODE_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_FLOW_CONTROL_MODE_OFF 23 -#define HCI_READ_FLOW_CONTROL_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_FLOW_CONTROL_MODE_OFF] & HCI_SUPP_COMMANDS_READ_FLOW_CONTROL_MODE_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_FLOW_CONTROL_MODE_MASK 0x02 -#define HCI_SUPP_COMMANDS_WRITE_FLOW_CONTROL_MODE_OFF 23 -#define HCI_WRITE_FLOW_CONTROL_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_FLOW_CONTROL_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_FLOW_CONTROL_MODE_MASK) - -#define HCI_SUPP_COMMANDS_READ_DATA_BLOCK_SIZE_MASK 0x04 -#define HCI_SUPP_COMMANDS_READ_DATA_BLOCK_SIZE_OFF 23 -#define HCI_READ_DATA_BLOCK_SIZE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_DATA_BLOCK_SIZE_OFF] & HCI_SUPP_COMMANDS_READ_DATA_BLOCK_SIZE_MASK) - -#define HCI_SUPP_COMMANDS_ENABLE_AMP_RCVR_REPORTS_MASK 0x20 -#define HCI_SUPP_COMMANDS_ENABLE_AMP_RCVR_REPORTS_OFF 23 -#define HCI_ENABLE_AMP_RCVR_REPORTS_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ENABLE_AMP_RCVR_REPORTS_OFF] & HCI_SUPP_COMMANDS_ENABLE_AMP_RCVR_REPORTS_MASK) - -#define HCI_SUPP_COMMANDS_AMP_TEST_END_MASK 0x40 -#define HCI_SUPP_COMMANDS_AMP_TEST_END_OFF 23 -#define HCI_AMP_TEST_END_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_AMP_TEST_END_OFF] & HCI_SUPP_COMMANDS_AMP_TEST_END_MASK) - -#define HCI_SUPP_COMMANDS_AMP_TEST_MASK 0x80 -#define HCI_SUPP_COMMANDS_AMP_TEST_OFF 23 -#define HCI_AMP_TEST_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_AMP_TEST_OFF] & HCI_SUPP_COMMANDS_AMP_TEST_MASK) - -/* Supported Commands (Byte 24) */ -#define HCI_SUPP_COMMANDS_READ_TRANSMIT_POWER_LEVEL_MASK 0x01 -#define HCI_SUPP_COMMANDS_READ_TRANSMIT_POWER_LEVEL_OFF 24 -#define HCI_READ_TRANSMIT_POWER_LEVEL_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_TRANSMIT_POWER_LEVEL_OFF] & HCI_SUPP_COMMANDS_READ_TRANSMIT_POWER_LEVEL_MASK) - -#define HCI_SUPP_COMMANDS_READ_BE_FLUSH_TOUT_MASK 0x04 -#define HCI_SUPP_COMMANDS_READ_BE_FLUSH_TOUT_OFF 24 -#define HCI_READ_BE_FLUSH_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_BE_FLUSH_TOUT_OFF] & HCI_SUPP_COMMANDS_READ_BE_FLUSH_TOUT_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_BE_FLUSH_TOUT_MASK 0x08 -#define HCI_SUPP_COMMANDS_WRITE_BE_FLUSH_TOUT_OFF 24 -#define HCI_WRITE_BE_FLUSH_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_BE_FLUSH_TOUT_OFF] & HCI_SUPP_COMMANDS_WRITE_BE_FLUSH_TOUT_MASK) - -#define HCI_SUPP_COMMANDS_SHORT_RANGE_MODE_MASK 0x10 -#define HCI_SUPP_COMMANDS_SHORT_RANGE_MODE_OFF 24 -#define HCI_SHORT_RANGE_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SHORT_RANGE_MODE_OFF] & HCI_SUPP_COMMANDS_SHORT_RANGE_MODE_MASK) - -/* LE commands TBD -** Supported Commands (Byte 24 continued) -** Supported Commands (Byte 25) -** Supported Commands (Byte 26) -** Supported Commands (Byte 27) -** Supported Commands (Byte 28) -*/ - -/* Supported Commands (Byte 29) */ -#define HCI_SUPP_COMMANDS_ENH_SETUP_SYNCH_CONN_MASK 0x08 -#define HCI_SUPP_COMMANDS_ENH_SETUP_SYNCH_CONN_OFF 29 -#define HCI_READ_ENH_SETUP_SYNCH_CONN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ENH_SETUP_SYNCH_CONN_OFF] & HCI_SUPP_COMMANDS_ENH_SETUP_SYNCH_CONN_MASK) - -#define HCI_SUPP_COMMANDS_ENH_ACCEPT_SYNCH_CONN_MASK 0x10 -#define HCI_SUPP_COMMANDS_ENH_ACCEPT_SYNCH_CONN_OFF 29 -#define HCI_READ_ENH_ACCEPT_SYNCH_CONN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_ENH_ACCEPT_SYNCH_CONN_OFF] & HCI_SUPP_COMMANDS_ENH_ACCEPT_SYNCH_CONN_MASK) - -#define HCI_SUPP_COMMANDS_READ_LOCAL_CODECS_MASK 0x20 -#define HCI_SUPP_COMMANDS_READ_LOCAL_CODECS_OFF 29 -#define HCI_READ_LOCAL_CODECS_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_CODECS_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_CODECS_MASK) - -#define HCI_SUPP_COMMANDS_SET_MWS_CHANN_PARAM_MASK 0x40 -#define HCI_SUPP_COMMANDS_SET_MWS_CHANN_PARAM_OFF 29 -#define HCI_SET_MWS_CHANNEL_PARAMETERS_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_MWS_CHANN_PARAM_OFF] & HCI_SUPP_COMMANDS_SET_MWS_CHANN_PARAM_MASK) - -#define HCI_SUPP_COMMANDS_SET_EXT_FRAME_CONF_MASK 0x80 -#define HCI_SUPP_COMMANDS_SET_EXT_FRAME_CONF_OFF 29 -#define HCI_SET_EXTERNAL_FRAME_CONFIGURATION_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_EXT_FRAME_CONF_OFF] & HCI_SUPP_COMMANDS_SET_EXT_FRAME_CONF_MASK) - -/* Supported Commands (Byte 30) */ -#define HCI_SUPP_COMMANDS_SET_MWS_SIGNALING_MASK 0x01 -#define HCI_SUPP_COMMANDS_SET_MWS_SIGNALING_OFF 30 -#define HCI_SET_MWS_SIGNALING_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_MWS_SIGNALING_OFF] & HCI_SUPP_COMMANDS_SET_MWS_SIGNALING_MASK) - -#define HCI_SUPP_COMMANDS_SET_MWS_TRANS_LAYER_MASK 0x02 -#define HCI_SUPP_COMMANDS_SET_MWS_TRANS_LAYER_OFF 30 -#define HCI_SET_MWS_TRANSPORT_LAYER_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_MWS_TRANS_LAYER_OFF] & HCI_SUPP_COMMANDS_SET_MWS_TRANS_LAYER_MASK) - -#define HCI_SUPP_COMMANDS_SET_MWS_SCAN_FREQ_TABLE_MASK 0x04 -#define HCI_SUPP_COMMANDS_SET_MWS_SCAN_FREQ_TABLE_OFF 30 -#define HCI_SET_MWS_SCAN_FREQUENCY_TABLE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_MWS_SCAN_FREQ_TABLE_OFF] & HCI_SUPP_COMMANDS_SET_MWS_SCAN_FREQ_TABLE_MASK) - -#define HCI_SUPP_COMMANDS_GET_TRANS_LAYER_CONF_MASK 0x08 -#define HCI_SUPP_COMMANDS_GET_TRANS_LAYER_CONF_OFF 30 -#define HCI_GET_MWS_TRANS_LAYER_CFG_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_GET_TRANS_LAYER_CONF_OFF] & HCI_SUPP_COMMANDS_GET_TRANS_LAYER_CONF_MASK) - -#define HCI_SUPP_COMMANDS_SET_MWS_PATTERN_CONF_MASK 0x10 -#define HCI_SUPP_COMMANDS_SET_MWS_PATTERN_CONF_OFF 30 -#define HCI_SET_MWS_PATTERN_CONFIGURATION_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_MWS_PATTERN_CONF_OFF] & HCI_SUPP_COMMANDS_SET_MWS_PATTERN_CONF_MASK) - -/* Supported Commands (Byte 30 bit 5) */ -#define HCI_SUPP_COMMANDS_SET_TRIG_CLK_CAP_MASK 0x20 -#define HCI_SUPP_COMMANDS_SET_TRIG_CLK_CAP_OFF 30 -#define HCI_SET_TRIG_CLK_CAP_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_TRIG_CLK_CAP_OFF] & HCI_SUPP_COMMANDS_SET_TRIG_CLK_CAP_MASK) - -/* Supported Commands (Byte 30 bit 6-7) */ -#define HCI_SUPP_COMMANDS_TRUNCATED_PAGE 0x06 -#define HCI_SUPP_COMMANDS_TRUNCATED_PAGE_OFF 30 -#define HCI_TRUNCATED_PAGE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_TRUNCATED_PAGE_OFF] & HCI_SUPP_COMMANDS_TRUNCATED_PAGE) - -#define HCI_SUPP_COMMANDS_TRUNCATED_PAGE_CANCEL 0x07 -#define HCI_SUPP_COMMANDS_TRUNCATED_PAGE_CANCEL_OFF 30 -#define HCI_TRUNCATED_PAGE_CANCEL_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_TRUNCATED_PAGE_CANCEL_OFF] & HCI_SUPP_COMMANDS_TRUNCATED_PAGE_CANCEL) - -/* Supported Commands (Byte 31 bit 6-7) */ -#define HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST 0x00 -#define HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_OFF 31 -#define HCI_SET_CONLESS_SLAVE_BRCST_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_OFF] & HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST) - -#define HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_RECEIVE 0x01 -#define HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_RECEIVE_OFF 31 -#define HCI_SET_CONLESS_SLAVE_BRCST_RECEIVE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_RECEIVE_OFF] & HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_RECEIVE) - -#define HCI_SUPP_COMMANDS_START_SYNC_TRAIN 0x02 -#define HCI_SUPP_COMMANDS_START_SYNC_TRAIN_OFF 31 -#define HCI_START_SYNC_TRAIN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_START_SYNC_TRAIN_OFF] & HCI_SUPP_COMMANDS_START_SYNC_TRAIN) - -#define HCI_SUPP_COMMANDS_RECEIVE_SYNC_TRAIN 0x03 -#define HCI_SUPP_COMMANDS_RECEIVE_SYNC_TRAIN_OFF 31 -#define HCI_RECEIVE_SYNC_TRAIN_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_RECEIVE_SYNC_TRAIN_OFF] & HCI_SUPP_COMMANDS_RECEIVE_SYNC_TRAIN) - -#define HCI_SUPP_COMMANDS_SET_RESERVED_LT_ADDR 0x04 -#define HCI_SUPP_COMMANDS_SET_RESERVED_LT_ADDR_OFF 31 -#define HCI_SET_RESERVED_LT_ADDR_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_RESERVED_LT_ADDR_OFF] & HCI_SUPP_COMMANDS_SET_RESERVED_LT_ADDR) - -#define HCI_SUPP_COMMANDS_DELETE_RESERVED_LT_ADDR 0x05 -#define HCI_SUPP_COMMANDS_DELETE_RESERVED_LT_ADDR_OFF 31 -#define HCI_DELETE_RESERVED_LT_ADDR_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_DELETE_RESERVED_LT_ADDR_OFF] & HCI_SUPP_COMMANDS_DELETE_RESERVED_LT_ADDR) - -#define HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_DATA 0x06 -#define HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_DATA_OFF 31 -#define HCI_SET_CONLESS_SLAVE_BRCST_DATA_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_DATA_OFF] & HCI_SUPP_COMMANDS_SET_CONLESS_SLAVE_BRCST_DATA) - -#define HCI_SUPP_COMMANDS_READ_SYNC_TRAIN_PARAM 0x07 -#define HCI_SUPP_COMMANDS_READ_SYNC_TRAIN_PARAM_OFF 31 -#define HCI_READ_SYNC_TRAIN_PARAM_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_SYNC_TRAIN_PARAM_OFF] & HCI_SUPP_COMMANDS_READ_SYNC_TRAIN_PARAM) - -/* Supported Commands (Byte 32 bit 0) */ -#define HCI_SUPP_COMMANDS_WRITE_SYNC_TRAIN_PARAM 0x00 -#define HCI_SUPP_COMMANDS_WRITE_SYNC_TRAIN_PARAM_OFF 32 -#define HCI_WRITE_SYNC_TRAIN_PARAM_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_SYNC_TRAIN_PARAM_OFF] & HCI_SUPP_COMMANDS_WRITE_SYNC_TRAIN_PARAM) - -#define HCI_SUPP_COMMANDS_REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY_MASK 0x02 -#define HCI_SUPP_COMMANDS_REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY_OFF 32 -#define HCI_REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY_OFF] & HCI_SUPP_COMMANDS_REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY_MASK) - -#define HCI_SUPP_COMMANDS_READ_SECURE_CONNS_SUPPORT_MASK 0x04 -#define HCI_SUPP_COMMANDS_READ_SECURE_CONNS_SUPPORT_OFF 32 -#define HCI_READ_SECURE_CONNS_SUPPORT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_SECURE_CONNS_SUPPORT_OFF] & HCI_SUPP_COMMANDS_READ_SECURE_CONNS_SUPPORT_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_SECURE_CONNS_SUPPORT_MASK 0x08 -#define HCI_SUPP_COMMANDS_WRITE_SECURE_CONNS_SUPPORT_OFF 32 -#define HCI_WRITE_SECURE_CONNS_SUPPORT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_SECURE_CONNS_SUPPORT_OFF] & HCI_SUPP_COMMANDS_WRITE_SECURE_CONNS_SUPPORT_MASK) - -#define HCI_SUPP_COMMANDS_READ_AUTHENT_PAYLOAD_TOUT_MASK 0x10 -#define HCI_SUPP_COMMANDS_READ_AUTHENT_PAYLOAD_TOUT_OFF 32 -#define HCI_READ_AUTHENT_PAYLOAD_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_AUTHENT_PAYLOAD_TOUT_OFF] & HCI_SUPP_COMMANDS_READ_AUTHENT_PAYLOAD_TOUT_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_AUTHENT_PAYLOAD_TOUT_MASK 0x20 -#define HCI_SUPP_COMMANDS_WRITE_AUTHENT_PAYLOAD_TOUT_OFF 32 -#define HCI_WRITE_AUTHENT_PAYLOAD_TOUT_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_AUTHENT_PAYLOAD_TOUT_OFF] & HCI_SUPP_COMMANDS_WRITE_AUTHENT_PAYLOAD_TOUT_MASK) - -#define HCI_SUPP_COMMANDS_READ_LOCAL_OOB_EXTENDED_DATA_MASK 0x40 -#define HCI_SUPP_COMMANDS_READ_LOCAL_OOB_EXTENDED_DATA_OFF 32 -#define HCI_READ_LOCAL_OOB_EXTENDED_DATA_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_READ_LOCAL_OOB_EXTENDED_DATA_OFF] & HCI_SUPP_COMMANDS_READ_LOCAL_OOB_EXTENDED_DATA_MASK) - -#define HCI_SUPP_COMMANDS_WRITE_SECURE_CONNECTIONS_TEST_MODE_MASK 0x80 -#define HCI_SUPP_COMMANDS_WRITE_SECURE_CONNECTIONS_TEST_MODE_OFF 32 -#define HCI_WRITE_SECURE_CONNECTIONS_TEST_MODE_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_WRITE_SECURE_CONNECTIONS_TEST_MODE_OFF] & HCI_SUPP_COMMANDS_WRITE_SECURE_CONNECTIONS_TEST_MODE_MASK) - -/* supported LE remote control connection parameter request reply */ -#define HCI_SUPP_COMMANDS_LE_RC_CONN_PARAM_UPD_RPY_MASK 0x10 -#define HCI_SUPP_COMMANDS_LE_RC_CONN_PARAM_UPD_RPY_OFF 33 -#define HCI_LE_RC_CONN_PARAM_UPD_RPY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_LE_RC_CONN_PARAM_UPD_RPY_OFF] & HCI_SUPP_COMMANDS_LE_RC_CONN_PARAM_UPD_RPY_MASK) - -#define HCI_SUPP_COMMANDS_RLE_RC_CONN_PARAM_UPD_NEG_RPY_MASK 0x20 -#define HCI_SUPP_COMMANDS_LE_RC_CONN_PARAM_UPD_NEG_RPY_OFF 33 -#define HCI_LE_RC_CONN_PARAM_UPD_NEG_RPY_SUPPORTED(x) ((x)[HCI_SUPP_COMMANDS_LE_RC_CONN_PARAM_UPD_NEG_RPY_OFF] & HCI_SUPP_COMMANDS_RLE_RC_CONN_PARAM_UPD_NEG_RPY_MASK) - -#define HCI_DATA_EVENT_MASK 3 -#define HCI_DATA_EVENT_OFFSET 12 - -#define RTK_HANDLE_MASK 0x0FFF -#define RTK_NONF_START_PACKET_BOUNDARY 0 -#define RTK_START_PACKET_BOUNDARY 2 -#define RTK_CONTINUATION_PACKET_BOUNDARY 1 -#define RTK_L2CAP_HEADER_PDU_LEN_SIZE 2 -#define RTK_L2CAP_HEADER_CID_SIZE 2 -#define RTK_L2CAP_HEADER_SIZE (RTK_L2CAP_HEADER_PDU_LEN_SIZE + RTK_L2CAP_HEADER_CID_SIZE) - -#define RTK_GET_BOUNDARY_FLAG(handle) (((handle) >> 12) & 0x0003) - -// 2 bytes for opcode, 1 byte for parameter length (Volume 2, Part E, 5.4.1) -#define COMMAND_PREAMBLE_SIZE 3 -// 2 bytes for handle, 2 bytes for data length (Volume 2, Part E, 5.4.2) -#define ACL_PREAMBLE_SIZE 4 -// 2 bytes for handle, 1 byte for data length (Volume 2, Part E, 5.4.3) -#define SCO_PREAMBLE_SIZE 3 -// 1 byte for event code, 1 byte for parameter length (Volume 2, Part E, 5.4.4) -#define EVENT_PREAMBLE_SIZE 2 - -#define HCI_PACKET_TYPE_TO_INDEX(type) ((type)-1) - -#define COMMON_DATA_LENGTH_INDEX 3 - -#define EVENT_DATA_LENGTH_INDEX 2 - -typedef struct -{ - uint8_t hci_version; - uint16_t hci_revision; - uint8_t lmp_version; - uint16_t manufacturer; - uint16_t lmp_subversion; -} rtkbt_version_t; - -typedef struct -{ - uint8_t adverting_type; - bool adverting_enable; - bool adverting_start; - bool connetion_enable; -} rtkbt_lescn_t; - -#endif diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_parse.h b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_parse.h deleted file mode 100755 index 446c50f2..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_parse.h +++ /dev/null @@ -1,157 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -/****************************************************************************** - * - * Module Name: - * rtk_parse.h - * - * Abstract: - * Contains wifi-bt coex functions implemented by bluedroid stack - * - * Major Change History: - * When Who What - * --------------------------------------------------------------- - * 2015-12-15 lamparten modified - * 2014-10-23 kyle_xu modified - * - * Notes: - * This is designed for wifi-bt Coex in Android 6.0. - * - ******************************************************************************/ - -#ifndef RTK_PARSE_H -#define RTK_PARSE_H - -#pragma once - -#include -#include -#include "bt_vendor_rtk.h" -#include "userial_vendor.h" - -/****************************************************************************** -** Constants & Macros -******************************************************************************/ -#define HOST_PROFILE_INFO - -/****************************************************************************** -** Type definitions -******************************************************************************/ -typedef unsigned char UINT8; -#define BD_ADDR_LEN 6 /* Device address length */ -typedef UINT8 BD_ADDR[BD_ADDR_LEN]; /* Device address */ -typedef void *TRANSAC; - -/****************************************************************************** -** Extern variables and functions -******************************************************************************/ -extern uint8_t coex_log_enable; - -/****************************************************************************** -** Functions -******************************************************************************/ -typedef struct rtk_parse_manager_t -{ - - void (*rtk_parse_internal_event_intercept)(uint8_t *p); - - void (*rtk_parse_l2cap_data)(uint8_t *p, uint8_t direction); - - void (*rtk_parse_init)(void); - - void (*rtk_parse_cleanup)(void); - - void (*rtk_parse_command)(uint8_t *p); - - void (*rtk_add_le_profile)(BD_ADDR bdaddr, uint16_t handle, uint8_t profile_map); - - void (*rtk_delete_le_profile)(BD_ADDR bdaddr, uint16_t handle, uint8_t profile_map); - - void (*rtk_add_le_data_count)(uint8_t data_type); - - void (*rtk_set_bt_on)(uint8_t bt_on); - -} rtk_parse_manager_t; - -rtk_parse_manager_t *rtk_parse_manager_get_interface(); - -#ifdef __LITTLE_ENDIAN -struct sbc_frame_hdr -{ - uint8_t syncword : 8; /* Sync word */ - uint8_t subbands : 1; /* Subbands */ - uint8_t allocation_method : 1; /* Allocation method */ - uint8_t channel_mode : 2; /* Channel mode */ - uint8_t blocks : 2; /* Blocks */ - uint8_t sampling_frequency : 2; /* Sampling frequency */ - uint8_t bitpool : 8; /* Bitpool */ - uint8_t crc_check : 8; /* CRC check */ -} __attribute__((packed)); - -/* NOTE: The code is copied from pa. - * only the bit field in 8-bit is affected by endian, not the 16-bit or 32-bit. - * why? - */ -struct rtp_header -{ - unsigned cc : 4; - unsigned x : 1; - unsigned p : 1; - unsigned v : 2; - - unsigned pt : 7; - unsigned m : 1; - - uint16_t sequence_number; - uint32_t timestamp; - uint32_t ssrc; - uint32_t csrc[0]; -} __attribute__((packed)); - -#else -/* big endian */ -struct sbc_frame_hdr -{ - uint8_t syncword : 8; /* Sync word */ - uint8_t sampling_frequency : 2; /* Sampling frequency */ - uint8_t blocks : 2; /* Blocks */ - uint8_t channel_mode : 2; /* Channel mode */ - uint8_t allocation_method : 1; /* Allocation method */ - uint8_t subbands : 1; /* Subbands */ - uint8_t bitpool : 8; /* Bitpool */ - uint8_t crc_check : 8; /* CRC check */ -} __attribute__((packed)); - -struct rtp_header -{ - unsigned v : 2; - unsigned p : 1; - unsigned x : 1; - unsigned cc : 4; - - unsigned m : 1; - unsigned pt : 7; - - uint16_t sequence_number; - uint32_t timestamp; - uint32_t ssrc; - uint32_t csrc[0]; -} __attribute__((packed)); -#endif /* __LITTLE_ENDIAN */ - -#endif /*RTK_PARSE_H*/ diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_poll.h b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_poll.h deleted file mode 100755 index dd8e2a3b..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_poll.h +++ /dev/null @@ -1,32 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#include -#include -#include -#include -#include "bt_vendor_lib.h" - -typedef void (*timed_out)(union sigval arg); - -void poll_init(timed_out ptr_timeout, uint32_t timeout); - -void poll_cleanup(void); - -void poll_enable(uint8_t turn_on); - -void poll_timer_flush(void); diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_socket.h b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_socket.h deleted file mode 100755 index 6207e1a7..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/rtk_socket.h +++ /dev/null @@ -1,73 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -/****************************************************************************** - * - * Filename: userial_vendor.h - * - * Description: Contains vendor-specific definitions used in serial port - * controls - * - ******************************************************************************/ - -#ifndef RTK_SOCKET_H -#define RTK_SOCKET_H - -#include "bt_vendor_rtk.h" -#include "userial.h" -#include -#include -#include -#include -#include -#include - -#ifdef CONFIG_SCO_OVER_HCI -#define SCO_CTRL_PATH "/data/misc/bluedroid/.sco_ctrl" -#define SCO_DATA_PATH "/data/misc/bluedroid/.sco_data" - -typedef enum -{ - SCO_CTRL_CMD_NONE, - SCO_CTRL_CMD_CHECK_READY, - SCO_CTRL_CMD_OUT_START, - SCO_CTRL_CMD_IN_START, - SCO_CTRL_CMD_OUT_STOP, - SCO_CTRL_CMD_IN_STOP, - SCO_CTRL_CMD_SUSPEND, - SCO_CTRL_GET_AUDIO_CONFIG, - SCO_CTRL_CMD_OFFLOAD_START, - SCO_CTRL_CMD_CLOSE, -} tSCO_CTRL_CMD; - -#define SCO_SAMPLE_RATE_8K 1 -#define SCO_SAMPLE_RATE_16K 2 - -#endif - -#define MAX(a, b) ((a) > (b) ? (a) : (b)) - -/****************************************************************************** -** Constants & Macros -******************************************************************************/ - -uint32_t Skt_Read(int fd, uint8_t *p_buf, uint32_t len, bool *condition); -int Skt_Read_noblock(int fd, uint8_t *p_buf, uint32_t len); -bool Skt_Send(int fd, uint8_t *p_buf, uint16_t msglen); -int Skt_Send_noblock(int fd, uint8_t *p_buf, uint16_t msglen); -#endif diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/unused.h b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/unused.h deleted file mode 100755 index 6e541ddc..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/unused.h +++ /dev/null @@ -1,25 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#ifndef BT_UNUSED_H -#define BT_UNUSED_H -#ifdef __GNUC__ -#define UNUSED(x) UNUSED_##x __attribute__((__unused__)) -#else -#define UNUSED(x) UNUSED_##x -#endif -#endif /*BT_UNUSED_H*/ diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/upio.h b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/upio.h deleted file mode 100755 index dd4c2f19..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/upio.h +++ /dev/null @@ -1,119 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -/****************************************************************************** - * - * Filename: upio.h - * - * Description: Contains definitions used for I/O controls - * - ******************************************************************************/ - -#ifndef UPIO_H -#define UPIO_H -#include "bt_vendor_lib.h" -/****************************************************************************** -** Constants & Macros -******************************************************************************/ - -#define UPIO_BT_POWER_OFF 0 -#define UPIO_BT_POWER_ON 1 - -/* UPIO signals */ -enum -{ - UPIO_BT_WAKE = 0, - UPIO_HOST_WAKE, - UPIO_LPM_MODE, - UPIO_MAX_COUNT -}; - -/* UPIO assertion/deassertion */ -enum -{ - UPIO_UNKNOWN = 0, - UPIO_DEASSERT, - UPIO_ASSERT -}; - -/****************************************************************************** -** Extern variables and functions -******************************************************************************/ - -/****************************************************************************** -** Functions -******************************************************************************/ - -/******************************************************************************* -** -** Function upio_init -** -** Description Initialization -** -** Returns None -** -*******************************************************************************/ -void upio_init(void); - -/******************************************************************************* -** -** Function upio_cleanup -** -** Description Clean up -** -** Returns None -** -*******************************************************************************/ -void upio_cleanup(void); - -/******************************************************************************* -** -** Function upio_set_bluetooth_power -** -** Description Interact with low layer driver to set Bluetooth power -** on/off. -** -** Returns 0 : SUCCESS or Not-Applicable -** <0 : ERROR -** -*******************************************************************************/ -int upio_set_bluetooth_power(int on); - -/******************************************************************************* -** -** Function upio_set -** -** Description Set i/o based on polarity -** -** Returns None -** -*******************************************************************************/ -void upio_set(uint8_t pio, uint8_t action, uint8_t polarity); - -/******************************************************************************* -** -** Function bt_wake_up_host_mode_set -** -** Description To enable/disable bt_wake_up_host mode. -** -** Returns 0 : SUCCESS or Not-Applicable -** <0 : ERROR -** -*******************************************************************************/ -int bt_wake_up_host_mode_set(uint8_t mode); -#endif /* UPIO_H */ diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/userial.h b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/userial.h deleted file mode 100755 index 3ee2ac69..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/userial.h +++ /dev/null @@ -1,74 +0,0 @@ -/****************************************************************************** - * - * Copyright 2009-2012 Broadcom Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -// This module manages the serial port over which HCI commands -// and data are sent/received. - -#ifndef BT_VENDOR_USERIAL_H -#define BT_VENDOR_USERIAL_H - -#include -#include - -typedef enum -{ - USERIAL_PORT_1, - USERIAL_PORT_2, - USERIAL_PORT_3, - USERIAL_PORT_4, - USERIAL_PORT_5, - USERIAL_PORT_6, - USERIAL_PORT_7, - USERIAL_PORT_8, - USERIAL_PORT_9, - USERIAL_PORT_10, - USERIAL_PORT_11, - USERIAL_PORT_12, - USERIAL_PORT_13, - USERIAL_PORT_14, - USERIAL_PORT_15, - USERIAL_PORT_16, - USERIAL_PORT_17, - USERIAL_PORT_18, -} userial_port_t; - -// Initializes the userial module. This function should only be called once. -// It returns true if the module was initialized, false if there was an error. -bool userial_init(void); - -// Opens the given serial port. Returns true if successful, false otherwise. -// Once this function is called, the userial module will begin producing -// buffers from data read off the serial port. If you wish to pause the -// production of buffers, call |userial_pause_reading|. You can then resume -// by calling |userial_resume_reading|. This function returns true if the -// serial port was successfully opened and buffer production has started. It -// returns false if there was an error. -bool userial_open(userial_port_t port); -void userial_close(void); -void userial_close_reader(void); - -// Reads a maximum of |len| bytes from the serial port into |p_buffer|. -// This function returns the number of bytes actually read, which may be -// less than |len|. This function will not block. -uint16_t userial_read(uint16_t msg_id, uint8_t *p_buffer, uint16_t len); - -// Writes a maximum of |len| bytes from |p_data| to the serial port. -// This function returns the number of bytes actually written, which may be -// less than |len|. This function may block. -uint16_t userial_write(uint16_t msg_id, const uint8_t *p_data, uint16_t len); -#endif \ No newline at end of file diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/userial_vendor.h b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/userial_vendor.h deleted file mode 100755 index cc2dbfc0..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/userial_vendor.h +++ /dev/null @@ -1,208 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -/****************************************************************************** - * - * Filename: userial_vendor.h - * - * Description: Contains vendor-specific definitions used in serial port - * controls - * - ******************************************************************************/ - -#ifndef USERIAL_VENDOR_H -#define USERIAL_VENDOR_H - -#include "bt_vendor_rtk.h" -#include "userial.h" -#include "hci_h5_int.h" -#include -#include "rtk_parse.h" -#include "bt_skbuff.h" -#include "rtk_common.h" - -/****************************************************************************** -** Constants & Macros -******************************************************************************/ -#define RTK_NO_INTR(fn) \ - do \ - { \ - } while ((fn) == -1 && errno == EINTR) - -/**** baud rates ****/ -#define USERIAL_BAUD_300 0 -#define USERIAL_BAUD_600 1 -#define USERIAL_BAUD_1200 2 -#define USERIAL_BAUD_2400 3 -#define USERIAL_BAUD_9600 4 -#define USERIAL_BAUD_19200 5 -#define USERIAL_BAUD_57600 6 -#define USERIAL_BAUD_115200 7 -#define USERIAL_BAUD_230400 8 -#define USERIAL_BAUD_460800 9 -#define USERIAL_BAUD_921600 10 -#define USERIAL_BAUD_1M 11 -#define USERIAL_BAUD_1_5M 12 -#define USERIAL_BAUD_2M 13 -#define USERIAL_BAUD_3M 14 -#define USERIAL_BAUD_4M 15 -#define USERIAL_BAUD_AUTO 16 - -/**** Data Format ****/ -/* Stop Bits */ -#define USERIAL_STOPBITS_1 1 -#define USERIAL_STOPBITS_1_5 (1 << 1) -#define USERIAL_STOPBITS_2 (1 << 2) - -/* Parity Bits */ -#define USERIAL_PARITY_NONE (1 << 3) -#define USERIAL_PARITY_EVEN (1 << 4) -#define USERIAL_PARITY_ODD (1 << 5) - -/* Data Bits */ -#define USERIAL_DATABITS_5 (1 << 6) -#define USERIAL_DATABITS_6 (1 << 7) -#define USERIAL_DATABITS_7 (1 << 8) -#define USERIAL_DATABITS_8 (1 << 9) - -#define USERIAL_HW_FLOW_CTRL_OFF 0 -#define USERIAL_HW_FLOW_CTRL_ON 1 - -#if (BT_WAKE_VIA_USERIAL_IOCTL == TRUE) -/* These are the ioctl values used for bt_wake ioctl via UART driver. you may - * need to redefine them on you platform! - * Logically they need to be unique and not colide with existing uart ioctl's. - */ -#ifndef USERIAL_IOCTL_BT_WAKE_ASSERT -#define USERIAL_IOCTL_BT_WAKE_ASSERT 0x8003 -#endif -#ifndef USERIAL_IOCTL_BT_WAKE_DEASSERT -#define USERIAL_IOCTL_BT_WAKE_DEASSERT 0x8004 -#endif -#ifndef USERIAL_IOCTL_BT_WAKE_GET_ST -#define USERIAL_IOCTL_BT_WAKE_GET_ST 0x8005 -#endif -#endif // (BT_WAKE_VIA_USERIAL_IOCTL==TRUE) - -/****************************************************************************** -** Type definitions -******************************************************************************/ -/* Structure used to configure serial port during open */ -typedef struct -{ - uint16_t fmt; /* Data format */ - uint8_t baud; /* Baud rate */ - uint8_t hw_fctrl; /*hardware flowcontrol*/ -} tUSERIAL_CFG; - -typedef enum -{ -#if (BT_WAKE_VIA_USERIAL_IOCTL == TRUE) - USERIAL_OP_ASSERT_BT_WAKE, - USERIAL_OP_DEASSERT_BT_WAKE, - USERIAL_OP_GET_BT_WAKE_STATE, -#endif - USERIAL_OP_NOP, -} userial_vendor_ioctl_op_t; - -enum -{ - RTKBT_PACKET_IDLE, - RTKBT_PACKET_TYPE, - RTKBT_PACKET_HEADER, - RTKBT_PACKET_CONTENT, - RTKBT_PACKET_END -}; - -/****************************************************************************** -** Extern variables and functions -******************************************************************************/ - -/****************************************************************************** -** Functions -******************************************************************************/ - -/******************************************************************************* -** -** Function userial_vendor_init -** -** Description Initialize userial vendor-specific control block -** -** Returns None -** -*******************************************************************************/ -void userial_vendor_init(char *bt_device_node); - -/******************************************************************************* -** -** Function userial_vendor_open -** -** Description Open the serial port with the given configuration -** -** Returns device fd -** -*******************************************************************************/ -int userial_vendor_open(tUSERIAL_CFG *p_cfg); - -/******************************************************************************* -** -** Function userial_vendor_close -** -** Description Conduct vendor-specific close work -** -** Returns None -** -*******************************************************************************/ -void userial_vendor_close(void); - -/******************************************************************************* -** -** Function userial_vendor_set_baud -** -** Description Set new baud rate -** -** Returns None -** -*******************************************************************************/ -void userial_vendor_set_baud(uint8_t userial_baud); - -/******************************************************************************* -** -** Function userial_vendor_ioctl -** -** Description ioctl interface -** -** Returns None -** -*******************************************************************************/ -void userial_vendor_ioctl(userial_vendor_ioctl_op_t op, void *p_data); - -void userial_vendor_set_hw_fctrl(uint8_t hw_fctrl); - -int userial_socket_open(void); - -int userial_vendor_usb_ioctl(int operation, void *param); - -int userial_vendor_usb_open(void); - -void userial_recv_rawdata_hook(unsigned char *buffer, unsigned int total_length); - -#define RTK_HANDLE_EVENT -#define RTK_HANDLE_CMD -//#define CONFIG_SCO_OVER_HCI -#endif /* USERIAL_VENDOR_H */ diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/utils/Log.h b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/utils/Log.h deleted file mode 100755 index b4a898be..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/include/utils/Log.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef BT_VENDOR_LOG_H -#define BT_VENDOR_LOG_H - -#include "hilog/log.h" - -#define HILOGD(...) HiLogPrint(LOG_CORE, LOG_DEBUG, LOG_DOMAIN, "BTVENDOR", __VA_ARGS__) -#define HILOGI(...) HiLogPrint(LOG_CORE, LOG_INFO, LOG_DOMAIN, "BTVENDOR", __VA_ARGS__) -#define HILOGW(...) HiLogPrint(LOG_CORE, LOG_WARN, LOG_DOMAIN, "BTVENDOR", __VA_ARGS__) -#define HILOGE(...) HiLogPrint(LOG_CORE, LOG_ERROR, LOG_DOMAIN, "BTVENDOR", __VA_ARGS__) -#endif diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/bt_list.c b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/bt_list.c deleted file mode 100755 index f8f40022..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/bt_list.c +++ /dev/null @@ -1,124 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -/****************************************************************************** - * - * Module Name: - * bt_list.c - * - * Abstract: - * To implement list data structure - * - * Major Change History: - * When Who What - * -------------------------------------------------------------- - * 2010-06-04 W.Bi Created - * - * Notes: - * - ******************************************************************************/ -#include "bt_list.h" - -//**************************************************************************** -// Structure -//**************************************************************************** - -//**************************************************************************** -// FUNCTION -//**************************************************************************** -// Initialize a list with its header -void ListInitializeHeader(PRT_LIST_HEAD ListHead) -{ - ListHead->Next = ListHead; - ListHead->Prev = ListHead; -} - -/** - Tell whether the list is empty - \param [IN] ListHead : List header of which to be test -*/ -unsigned char ListIsEmpty(PRT_LIST_HEAD ListHead) -{ - return ListHead->Next == ListHead; -} - -/* - Insert a new entry between two known consecutive entries. - This is only for internal list manipulation where we know the prev&next entries already - @New : New element to be added - @Prev: previous element in the list - @Next: Next element in the list -*/ -void ListAdd(PRT_LIST_ENTRY New,PRT_LIST_ENTRY Prev,PRT_LIST_ENTRY Next) -{ - Next->Prev = New; - New->Next = Next; - New->Prev = Prev; - Prev->Next = New; -} -/** - Add a new entry to the list. - Insert a new entry after the specified head. This is good for implementing stacks. - \param [IN] ListNew : new entry to be added - \param [IN OUT] ListHead : List header after which to add new entry -*/ -void ListAddToHead(PRT_LIST_ENTRY ListNew,PRT_LIST_HEAD ListHead) -{ - ListAdd(ListNew, ListHead, ListHead->Next); -} - -/** - Add a new entry to the list. - Insert a new entry before the specified head. This is good for implementing queues. - \param [IN] ListNew : new entry to be added - \param [IN OUT] ListHead : List header before which to add new entry -*/ -void ListAddToTail(PRT_LIST_ENTRY ListNew,PRT_LIST_HEAD ListHead) -{ - ListAdd(ListNew, ListHead->Prev, ListHead); -} - -RT_LIST_ENTRY *ListGetTop(PRT_LIST_HEAD ListHead) -{ - - if (ListIsEmpty(ListHead)) - return 0; - - return ListHead->Next; -} - -RT_LIST_ENTRY *ListGetTail(PRT_LIST_HEAD ListHead) -{ - if (ListIsEmpty(ListHead)) - return 0; - - return ListHead->Prev; -} -/** - Delete entry from the list - Note: ListIsEmpty() on this list entry would not return true, since its state is undefined - \param [IN] ListToDelete : list entry to be deleted -*/ -void ListDeleteNode(PRT_LIST_ENTRY ListToDelete) -{ - // if (ListToDelete->Next != NULL && ListToDelete->Prev != NULL) - { - ListToDelete->Next->Prev = ListToDelete->Prev; - ListToDelete->Prev->Next = ListToDelete->Next; - ListToDelete->Next = ListToDelete->Prev = ListToDelete; - } -} diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/bt_skbuff.c b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/bt_skbuff.c deleted file mode 100755 index 0869c33b..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/bt_skbuff.c +++ /dev/null @@ -1,495 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -/****************************************************************************** - * - * Module Name: - * bt_skbuff.c - * - * Abstract: - * Data buffer managerment through whole bluetooth stack. - * - * Major Change History: - * When Who What - * -------------------------------------------------------------- - * 2010-06-11 W.Bi Created. - * - * Notes: - * To reduce memory copy when pass data buffer to other layers, - * RTK_BUFFER is designed referring to linux socket buffer. - * But I still wonder its effect, since RTK_BUFFER is much bigger - * than original data buffer.RTK_BUFFER will reduce its member if - * it would not reach what i had expected. - * - ******************************************************************************/ - -#define LOG_TAG "bt_h5" -#undef NDEBUG -#include -#include -#include - -#include -#include -#include - -#include "bt_list.h" -#include "bt_skbuff.h" -#include "string.h" -#include "hci_h5_int.h" -#define IN -#define OUT - -//**************************************************************************** -// CONSTANT DEFINITION -//**************************************************************************** -/// default header size -/// l2cap header(8)+hci acl(4) -#define DEFAULT_HEADER_SIZE (8 + 4) - -// RTK_BUFFER data buffer alignment -#define RTB_ALIGN 4 - -// do alignment with RTB_ALIGN -#define RTB_DATA_ALIGN(_Length) ((_Length + (RTB_ALIGN - 1)) & (~(RTB_ALIGN - 1))) - -//**************************************************************************** -// STRUCTURE DEFINITION -//**************************************************************************** -typedef struct _RTB_QUEUE_HEAD -{ - RT_LIST_HEAD List; - uint32_t QueueLen; - pthread_mutex_t Lock; - uint8_t Id[RTB_QUEUE_ID_LENGTH]; -} * PRTB_QUEUE_HEAD; - -//**************************************************************************** -// FUNCTION -//**************************************************************************** -/** - check whether queue is empty - \return : FALSE Queue is not empty - TRU Queue is empty -*/ -bool RtbQueueIsEmpty(IN RTB_QUEUE_HEAD *RtkQueueHead) -{ - // return ListIsEmpty(&RtkQueueHead->List); - return RtkQueueHead->QueueLen > 0 ? false : true; -} - -/** - Allocate a RTK_BUFFER with specified data length and reserved headroom. - If caller does not know actual headroom to reserve for further usage, specify it to zero to use default value. - \param [IN] Length : current data buffer length to allcated - \param [IN] HeadRoom : if caller knows reserved head space, set it; otherwise set 0 to use default value - \return pointer to RTK_BUFFER if succeed, null otherwise -*/ -RTK_BUFFER *RtbAllocate(uint32_t Length,uint32_t HeadRoom) -{ - RTK_BUFFER *Rtb = NULL; - /// Rtb buffer length: - /// RTK_BUFFER 48 - /// HeadRoom HeadRomm or 12 - /// Length - /// memory size: 48 + Length + 12(default) + 8*2(header for each memory) ---> a multiple of 8 - /// example: (48 + 8)+ (300 + 12 + 8) = 372 - Rtb = malloc(sizeof(RTK_BUFFER)); - if (Rtb) - { - uint32_t BufferLen = HeadRoom ? (Length + HeadRoom) : (Length + DEFAULT_HEADER_SIZE); - BufferLen = RTB_DATA_ALIGN(BufferLen); - Rtb->Head = malloc(BufferLen); - if (Rtb->Head) - { - Rtb->HeadRoom = HeadRoom ? HeadRoom : DEFAULT_HEADER_SIZE; - Rtb->Data = Rtb->Head + Rtb->HeadRoom; - Rtb->End = Rtb->Data; - Rtb->Tail = Rtb->End + Length; - Rtb->Length = 0; - ListInitializeHeader(&Rtb->List); - Rtb->RefCount = 1; - return Rtb; - } - } - - if (Rtb) - { - if (Rtb->Head) - { - free(Rtb->Head); - } - - free(Rtb); - } - return NULL; -} - -/** - Free specified Rtk_buffer - \param [IN] RtkBuffer : buffer to free -*/ -void RtbFree(RTK_BUFFER *RtkBuffer) -{ - if (RtkBuffer) - { - free(RtkBuffer->Head); - free(RtkBuffer); - } - return; -} - -/** - Add a specified length protocol header to the start of data buffer hold by specified rtk_buffer. - This function extends used data area of the buffer at the buffer start. - \param [IN OUT] RtkBuffer : data buffer to add - \param [IN] Length : header length - \return Pointer to the first byte of the extra data is returned -*/ -uint8_t *RtbAddHead(RTK_BUFFER *RtkBuffer,uint32_t Length) -{ - - if ((uint32_t)(RtkBuffer->Data - RtkBuffer->Head) >= Length) - { - RtkBuffer->Data -= Length; - RtkBuffer->Length += Length; - RtkBuffer->HeadRoom -= Length; - return RtkBuffer->Data; - } - - return NULL; -} -/** - Remove a specified length data from the start of data buffer hold by specified rtk_buffer. - This function returns the memory to the headroom. - \param [IN OUT] RtkBuffer : data buffer to remove - \param [IN] Length : header length - \return Pointer to the next data in the buffer is returned, usually useless -*/ -unsigned char RtbRemoveHead(RTK_BUFFER *RtkBuffer,uint32_t Length) -{ - - if (RtkBuffer->Length >= Length) - { - RtkBuffer->Data += Length; - RtkBuffer->Length -= Length; - RtkBuffer->HeadRoom += Length; - return true; - } - - return false; -} - -/** - Add a specified length protocol header to the end of data buffer hold by specified rtk_buffer. - This function extends used data area of the buffer at the buffer end. - \param [IN OUT] RtkBuffer : data buffer to add - \param [IN] Length : header length - \return Pointer to the first byte of the extra data is returned -*/ -uint8_t *RtbAddTail(RTK_BUFFER *RtkBuffer,uint32_t Length) -{ - - if ((uint32_t)(RtkBuffer->Tail - RtkBuffer->End) >= Length) - { - uint8_t *Tmp = RtkBuffer->End; - RtkBuffer->End += Length; - RtkBuffer->Length += Length; - return Tmp; - } - - return NULL; -} - -unsigned char RtbRemoveTail(IN OUT RTK_BUFFER *RtkBuffer,IN uint32_t Length) -{ - - if ((uint32_t)(RtkBuffer->End - RtkBuffer->Data) >= Length) - { - RtkBuffer->End -= Length; - RtkBuffer->Length -= Length; - return true; - } - - return false; -} -//**************************************************************************** -// RTB list manipulation -//**************************************************************************** -/** - Initialize a rtb queue. - \return Initialized rtb queue if succeed, otherwise NULL -*/ -RTB_QUEUE_HEAD *RtbQueueInit() -{ - RTB_QUEUE_HEAD *RtbQueue = NULL; - int ret = 0; - RtbQueue = malloc(sizeof(RTB_QUEUE_HEAD)); - if (RtbQueue) - { - ret = pthread_mutex_init(&RtbQueue->Lock, NULL); - if (!ret) - { - ListInitializeHeader(&RtbQueue->List); - RtbQueue->QueueLen = 0; - return RtbQueue; - } - } - - // error code comes here - if (RtbQueue) - { - free(RtbQueue); - } - return NULL; -} - -/** - Free a rtb queue. - \param [IN] RtkQueueHead : Rtk Queue -*/ -void RtbQueueFree(RTB_QUEUE_HEAD *RtkQueueHead) -{ - if (RtkQueueHead) - { - - RtbEmptyQueue(RtkQueueHead); - pthread_mutex_destroy(&RtkQueueHead->Lock); - free(RtkQueueHead); - } -} - -/** - Queue specified RtkBuffer into a RtkQueue at list tail. - \param [IN OUT] RtkQueueHead : Rtk Queue - \param [IN] RtkBuffer : Rtk buffer to add -*/ -void RtbQueueTail(IN OUT RTB_QUEUE_HEAD *RtkQueueHead,IN RTK_BUFFER *RtkBuffer) -{ - pthread_mutex_lock(&RtkQueueHead->Lock); - ListAddToTail(&RtkBuffer->List, &RtkQueueHead->List); - RtkQueueHead->QueueLen++; - pthread_mutex_unlock(&RtkQueueHead->Lock); -} - -/** - Queue specified RtkBuffer into a RtkQueue at list Head. - \param [IN OUT] RtkQueueHead : Rtk Queue - \param [IN] RtkBuffer : Rtk buffer to add -*/ -void RtbQueueHead(IN OUT RTB_QUEUE_HEAD *RtkQueueHead,IN RTK_BUFFER *RtkBuffer) -{ - pthread_mutex_lock(&RtkQueueHead->Lock); - ListAddToHead(&RtkBuffer->List, &RtkQueueHead->List); - RtkQueueHead->QueueLen++; - pthread_mutex_unlock(&RtkQueueHead->Lock); -} - -/** - Insert new Rtkbuffer in the old buffer - \param [IN OUT] RtkQueueHead : Rtk Queue - \param [IN] OldRtkBuffer : old rtk buffer - \param [IN] NewRtkBuffer : Rtk buffer to add -*/ -void RtbInsertBefore(IN OUT RTB_QUEUE_HEAD *RtkQueueHead,IN RTK_BUFFER *pOldRtkBuffer,IN RTK_BUFFER *pNewRtkBuffer) -{ - pthread_mutex_lock(&RtkQueueHead->Lock); - ListAdd(&pNewRtkBuffer->List, pOldRtkBuffer->List.Prev, &pOldRtkBuffer->List); - RtkQueueHead->QueueLen++; - pthread_mutex_unlock(&RtkQueueHead->Lock); -} - -/** - check whether the buffer is the last node in the queue -*/ -unsigned char RtbNodeIsLast(IN RTB_QUEUE_HEAD *RtkQueueHead,IN RTK_BUFFER *pRtkBuffer) -{ - RTK_BUFFER *pBuf; - pthread_mutex_lock(&RtkQueueHead->Lock); - - pBuf = (RTK_BUFFER *)RtkQueueHead->List.Prev; - if (pBuf == pRtkBuffer) - { - pthread_mutex_unlock(&RtkQueueHead->Lock); - return true; - } - pthread_mutex_unlock(&RtkQueueHead->Lock); - return false; -} - -/** - get the next buffer node after the specified buffer in the queue - if the specified buffer is the last node in the queue , return NULL - \param [IN] RtkBuffer : Rtk Queue - \param [IN] RtkBuffer : Rtk buffer - \return node after the specified buffer -*/ -RTK_BUFFER *RtbQueueNextNode(IN RTB_QUEUE_HEAD *RtkQueueHead,IN RTK_BUFFER *pRtkBuffer) -{ - RTK_BUFFER *pBuf; - pthread_mutex_lock(&RtkQueueHead->Lock); - pBuf = (RTK_BUFFER *)RtkQueueHead->List.Prev; - if (pBuf == pRtkBuffer) - { - pthread_mutex_unlock(&RtkQueueHead->Lock); - return NULL; ///< if it is already the last node in the queue , return NULL - } - pBuf = (RTK_BUFFER *)pRtkBuffer->List.Next; - pthread_mutex_unlock(&RtkQueueHead->Lock); - return pBuf; ///< return next node after this node -} - -/** - Delete specified RtkBuffer from a RtkQueue. - It don't hold spinlock itself, so caller must hold it at someplace. - \param [IN OUT] RtkQueueHead : Rtk Queue - \param [IN] RtkBuffer : Rtk buffer to Remove -*/ -void RtbRemoveNode(IN OUT RTB_QUEUE_HEAD *RtkQueueHead,IN RTK_BUFFER *RtkBuffer) -{ - RtkQueueHead->QueueLen--; - ListDeleteNode(&RtkBuffer->List); -} - -/** - Get the RtkBuffer which is the head of a RtkQueue - \param [IN OUT] RtkQueueHead : Rtk Queue - \return head of the RtkQueue , otherwise NULL -*/ -RTK_BUFFER *RtbTopQueue(IN RTB_QUEUE_HEAD *RtkQueueHead) -{ - RTK_BUFFER *Rtb = NULL; - pthread_mutex_lock(&RtkQueueHead->Lock); - - if (RtbQueueIsEmpty(RtkQueueHead)) - { - pthread_mutex_unlock(&RtkQueueHead->Lock); - return NULL; - } - - Rtb = (RTK_BUFFER *)RtkQueueHead->List.Next; - pthread_mutex_unlock(&RtkQueueHead->Lock); - - return Rtb; -} - -/** - Remove a RtkBuffer from specified rtkqueue at list tail. - \param [IN OUT] RtkQueueHead : Rtk Queue - \return removed rtkbuffer if succeed, otherwise NULL -*/ -RTK_BUFFER *RtbDequeueTail(IN OUT RTB_QUEUE_HEAD *RtkQueueHead) -{ - RTK_BUFFER *Rtb = NULL; - - pthread_mutex_lock(&RtkQueueHead->Lock); - if (RtbQueueIsEmpty(RtkQueueHead)) - { - pthread_mutex_unlock(&RtkQueueHead->Lock); - return NULL; - } - Rtb = (RTK_BUFFER *)RtkQueueHead->List.Prev; - RtbRemoveNode(RtkQueueHead, Rtb); - pthread_mutex_unlock(&RtkQueueHead->Lock); - - return Rtb; -} - -/** - Remove a RtkBuffer from specified rtkqueue at list head. - \param [IN OUT] RtkQueueHead : Rtk Queue - \return removed rtkbuffer if succeed, otherwise NULL -*/ -RTK_BUFFER *RtbDequeueHead(IN OUT RTB_QUEUE_HEAD *RtkQueueHead) -{ - RTK_BUFFER *Rtb = NULL; - pthread_mutex_lock(&RtkQueueHead->Lock); - - if (RtbQueueIsEmpty(RtkQueueHead)) - { - pthread_mutex_unlock(&RtkQueueHead->Lock); - return NULL; - } - Rtb = (RTK_BUFFER *)RtkQueueHead->List.Next; - RtbRemoveNode(RtkQueueHead, Rtb); - pthread_mutex_unlock(&RtkQueueHead->Lock); - return Rtb; -} - -/** - Get current rtb queue's length. - \param [IN] RtkQueueHead : Rtk Queue - \return current queue's length -*/ -signed long RtbGetQueueLen(IN RTB_QUEUE_HEAD *RtkQueueHead) -{ - return RtkQueueHead->QueueLen; -} - -/** - Empty the rtkqueue. - \param [IN OUT] RtkQueueHead : Rtk Queue -*/ -void RtbEmptyQueue(IN OUT RTB_QUEUE_HEAD *RtkQueueHead) -{ - RTK_BUFFER *Rtb = NULL; - pthread_mutex_lock(&RtkQueueHead->Lock); - - while (!RtbQueueIsEmpty(RtkQueueHead)) - { - Rtb = (RTK_BUFFER *)RtkQueueHead->List.Next; - RtbRemoveNode(RtkQueueHead, Rtb); - RtbFree(Rtb); - } - - pthread_mutex_unlock(&RtkQueueHead->Lock); - return; -} - -/// Annie_tmp -unsigned char RtbCheckQueueLen(IN RTB_QUEUE_HEAD *RtkQueueHead, IN uint8_t Len) -{ - return RtkQueueHead->QueueLen < Len ? true : false; -} - -/** - clone buffer for upper or lower layer, because original buffer should be stored in l2cap - \param Length, 0); - if (!pNewBuffer) - { - return NULL; - } - if (pDataBuffer && pDataBuffer->Data) - memcpy(pNewBuffer->Data, pDataBuffer->Data, pDataBuffer->Length); - else - { - RtbFree(pNewBuffer); - return NULL; - } - - pNewBuffer->Length = pDataBuffer->Length; - } - return pNewBuffer; -} diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/bt_vendor_rtk.c b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/bt_vendor_rtk.c deleted file mode 100755 index dd2c6850..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/bt_vendor_rtk.c +++ /dev/null @@ -1,656 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -/****************************************************************************** - * - * Filename: bt_vendor_rtk.c - * - * Description: Realtek vendor specific library implementation - * - ******************************************************************************/ - -#undef NDEBUG -#define LOG_TAG "libbt_vendor" -#define RTKBT_RELEASE_NAME "20190717_BT_ANDROID_9.0" - -#include "bt_vendor_rtk.h" - -#include -#include - -#include "upio.h" -#include "userial_vendor.h" - -#ifndef BTVND_DBG -#define BTVND_DBG FALSE -#endif -#undef BTVNDDBG -#if (BTVND_DBG == TRUE) -#define BTVNDDBG(param, ...) \ - { \ - HILOGD(param, ##__VA_ARGS__); \ - } -#else -#define BTVNDDBG(param, ...) \ - { \ - HILOGD(param, ##__VA_ARGS__); \ - } -#endif - -/****************************************************************************** -** Externs -******************************************************************************/ -extern unsigned int rtkbt_h5logfilter; -extern unsigned int h5_log_enable; -extern bool rtk_btsnoop_dump; -extern bool rtk_btsnoop_net_dump; -extern bool rtk_btsnoop_save_log; -extern char rtk_btsnoop_path[]; -extern uint8_t coex_log_enable; -extern void hw_config_start(char transtype); -extern void hw_usb_config_start(char transtype, uint32_t val); -extern void RTK_btservice_init(); -extern void hw_process_event(HC_BT_HDR *); - -#if (HW_END_WITH_HCI_RESET == TRUE) -void hw_epilog_process(void); -#endif - -/****************************************************************************** -** Variables -******************************************************************************/ -bt_vendor_callbacks_t *bt_vendor_cbacks = NULL; -uint8_t vnd_local_bd_addr[BD_ADDR_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; -bool rtkbt_auto_restart = false; - -/****************************************************************************** -** Local type definitions -******************************************************************************/ -#define DEVICE_NODE_MAX_LEN 512 -#define RTKBT_CONF_FILE "/vendor/etc/bluetooth/rtkbt.conf" -#define USB_DEVICE_DIR "/sys/bus/usb/devices" -#define DEBUG_SCAN_USB FALSE - -/****************************************************************************** -** Static Variables -******************************************************************************/ -// transfer_type(4 bit) | transfer_interface(4 bit) -char rtkbt_transtype = 0; -static char rtkbt_device_node[DEVICE_NODE_MAX_LEN] = {0}; - -static const tUSERIAL_CFG userial_H5_cfg = { - (USERIAL_DATABITS_8 | USERIAL_PARITY_EVEN | USERIAL_STOPBITS_1), - USERIAL_BAUD_115200, USERIAL_HW_FLOW_CTRL_OFF}; -static const tUSERIAL_CFG userial_H4_cfg = { - (USERIAL_DATABITS_8 | USERIAL_PARITY_NONE | USERIAL_STOPBITS_1), - USERIAL_BAUD_115200, USERIAL_HW_FLOW_CTRL_OFF}; - -/****************************************************************************** -** Functions -******************************************************************************/ -static int Check_Key_Value(char *path, char *key, int value) -{ - FILE *fp; - char newpath[100]; - char string_get[6]; - int value_int = 0; - memset(newpath, 0, 100); - sprintf(newpath, "%s/%s", path, key); - if ((fp = fopen(newpath, "r")) != NULL) - { - memset(string_get, 0, 6); - if (fgets(string_get, 5, fp) != NULL) - if (DEBUG_SCAN_USB) - HILOGE("string_get %s =%s\n", key, string_get); - fclose(fp); - value_int = strtol(string_get, NULL, 16); - if (value_int == value) - return 1; - } - return 0; -} - -static int Scan_Usb_Devices_For_RTK(char *path) -{ - char newpath[100]; - char subpath[100]; - DIR *pdir; - DIR *newpdir; - struct dirent *ptr; - struct dirent *newptr; - struct stat filestat; - struct stat subfilestat; - if (stat(path, &filestat) != 0) - { - HILOGE("The file or path(%s) can not be get stat!\n", newpath); - return -1; - } - if ((filestat.st_mode & S_IFDIR) != S_IFDIR) - { - HILOGE("(%s) is not be a path!\n", path); - return -1; - } - pdir = opendir(path); - /*enter sub direc*/ - while ((ptr = readdir(pdir)) != NULL) - { - if (strcmp(ptr->d_name, ".") == 0 || strcmp(ptr->d_name, "..") == 0) - continue; - memset(newpath, 0, 100); - sprintf(newpath, "%s/%s", path, ptr->d_name); - if (DEBUG_SCAN_USB) - HILOGE("The file or path(%s)\n", newpath); - if (stat(newpath, &filestat) != 0) - { - HILOGE("The file or path(%s) can not be get stat!\n", newpath); - continue; - } - /* Check if it is path. */ - if ((filestat.st_mode & S_IFDIR) == S_IFDIR) - { - if (!Check_Key_Value(newpath, "idVendor", 0x0bda)) - continue; - newpdir = opendir(newpath); - /*read sub directory*/ - while ((newptr = readdir(newpdir)) != NULL) - { - if (strcmp(newptr->d_name, ".") == 0 || - strcmp(newptr->d_name, "..") == 0) - continue; - memset(subpath, 0, 100); - sprintf(subpath, "%s/%s", newpath, newptr->d_name); - if (DEBUG_SCAN_USB) - HILOGE("The file or path(%s)\n", subpath); - if (stat(subpath, &subfilestat) != 0) - { - HILOGE("The file or path(%s) can not be get stat!\n", newpath); - continue; - } - /* Check if it is path. */ - if ((subfilestat.st_mode & S_IFDIR) == S_IFDIR) - { - if (Check_Key_Value(subpath, "bInterfaceClass", 0xe0) && - Check_Key_Value(subpath, "bInterfaceSubClass", 0x01) && - Check_Key_Value(subpath, "bInterfaceProtocol", 0x01)) - { - closedir(newpdir); - closedir(pdir); - return 1; - } - } - } - closedir(newpdir); - } - } - closedir(pdir); - return 0; -} - -static char *rtk_trim(char *str) -{ - while (isspace(*str)) - ++str; - - if (!*str) - return str; - - char *end_str = str + strlen(str) - 1; - while (end_str > str && isspace(*end_str)) - --end_str; - - end_str[1] = '\0'; - return str; -} - -static void load_rtkbt_conf() -{ - char *split; - memset(rtkbt_device_node, 0, sizeof(rtkbt_device_node)); - FILE *fp = fopen(RTKBT_CONF_FILE, "rt"); - if (!fp) - { - HILOGE("%s unable to open file '%s': %s", __func__, RTKBT_CONF_FILE, - strerror(errno)); - strcpy(rtkbt_device_node, "/dev/rtkbt_dev"); - return; - } - - int line_num = 0; - char line[1024]; - while (fgets(line, sizeof(line), fp)) - { - char *line_ptr = rtk_trim(line); - ++line_num; - - // Skip blank and comment lines. - if (*line_ptr == '\0' || *line_ptr == '#' || *line_ptr == '[') - continue; - - split = strchr(line_ptr, '='); - if (!split) - { - HILOGE("%s no key/value separator found on line %d.", __func__, line_num); - strcpy(rtkbt_device_node, "/dev/rtkbt_dev"); - fclose(fp); - return; - } - - *split = '\0'; - if (!strcmp(rtk_trim(line_ptr), "BtDeviceNode")) - { - strcpy(rtkbt_device_node, rtk_trim(split + 1)); - } - } - - fclose(fp); - - rtkbt_transtype = 0; - if (rtkbt_device_node[0] == '?') - { - /*1.Scan_Usb_Device*/ - if (Scan_Usb_Devices_For_RTK(USB_DEVICE_DIR) == 0x01) - { - strcpy(rtkbt_device_node, "/dev/rtkbt_dev"); - } - else - { - int i = 0; - while (rtkbt_device_node[i] != '\0') - { - rtkbt_device_node[i] = rtkbt_device_node[i + 1]; - i++; - } - } - } - - if ((split = strchr(rtkbt_device_node, ':')) != NULL) - { - *split = '\0'; - if (!strcmp(rtk_trim(split + 1), "H5")) - { - rtkbt_transtype |= RTKBT_TRANS_H5; - } - else if (!strcmp(rtk_trim(split + 1), "H4")) - { - rtkbt_transtype |= RTKBT_TRANS_H4; - } - } - else if (strcmp(rtkbt_device_node, "/dev/rtkbt_dev")) - { - // default use h5 - rtkbt_transtype |= RTKBT_TRANS_H5; - } - - if (strcmp(rtkbt_device_node, "/dev/rtkbt_dev")) - { - rtkbt_transtype |= RTKBT_TRANS_UART; - } - else - { - rtkbt_transtype |= RTKBT_TRANS_USB; - rtkbt_transtype |= RTKBT_TRANS_H4; - } -} - -static void rtkbt_stack_conf_cleanup() -{ - rtkbt_h5logfilter = 0; - h5_log_enable = 0; - rtk_btsnoop_dump = false; - rtk_btsnoop_net_dump = false; -} - -static void load_rtkbt_stack_conf() -{ - char *split; - FILE *fp = fopen(RTKBT_CONF_FILE, "rt"); - if (!fp) - { - HILOGE("%s unable to open file '%s': %s", __func__, RTKBT_CONF_FILE, - strerror(errno)); - return; - } - int line_num = 0; - char line[1024]; - // char value[1024]; - while (fgets(line, sizeof(line), fp)) - { - char *line_ptr = rtk_trim(line); - ++line_num; - - // Skip blank and comment lines. - if (*line_ptr == '\0' || *line_ptr == '#' || *line_ptr == '[') - continue; - - split = strchr(line_ptr, '='); - if (!split) - { - HILOGE("%s no key/value separator found on line %d.", __func__, line_num); - continue; - } - - *split = '\0'; - char *endptr; - if (!strcmp(rtk_trim(line_ptr), "RtkbtLogFilter")) - { - rtkbt_h5logfilter = strtol(rtk_trim(split + 1), &endptr, 0); - } - else if (!strcmp(rtk_trim(line_ptr), "H5LogOutput")) - { - h5_log_enable = strtol(rtk_trim(split + 1), &endptr, 0); - } - else if (!strcmp(rtk_trim(line_ptr), "RtkBtsnoopDump")) - { - if (!strcmp(rtk_trim(split + 1), "true")) - rtk_btsnoop_dump = true; - } - else if (!strcmp(rtk_trim(line_ptr), "RtkBtsnoopNetDump")) - { - if (!strcmp(rtk_trim(split + 1), "true")) - rtk_btsnoop_net_dump = true; - } - else if (!strcmp(rtk_trim(line_ptr), "BtSnoopFileName")) - { - sprintf(rtk_btsnoop_path, "%s_rtk", rtk_trim(split + 1)); - } - else if (!strcmp(rtk_trim(line_ptr), "BtSnoopSaveLog")) - { - if (!strcmp(rtk_trim(split + 1), "true")) - rtk_btsnoop_save_log = true; - } - else if (!strcmp(rtk_trim(line_ptr), "BtCoexLogOutput")) - { - coex_log_enable = strtol(rtk_trim(split + 1), &endptr, 0); - } - else if (!strcmp(rtk_trim(line_ptr), "RtkBtAutoRestart")) - { - if (!strcmp(rtk_trim(split + 1), "true")) - rtkbt_auto_restart = true; - } - } - - fclose(fp); -} - -static void byte_reverse(unsigned char *data, int len) -{ - int i; - int tmp; - - for (i = 0; i < len / 2; i++) - { - tmp = len - i - 1; - data[i] ^= data[tmp]; - data[tmp] ^= data[i]; - data[i] ^= data[tmp]; - } -} - -static int init(const bt_vendor_callbacks_t *p_cb, - unsigned char *local_bdaddr) -{ - int retval = -1; - HILOGD("init, bdaddr:%02x%02x:%02x%02x:%02x%02x", local_bdaddr[0], - local_bdaddr[1], local_bdaddr[2], local_bdaddr[3], local_bdaddr[4], - local_bdaddr[5]); - - if (p_cb == NULL) - { - HILOGE("init failed with no user callbacks!"); - return retval; - } - -#if (VENDOR_LIB_RUNTIME_TUNING_ENABLED == TRUE) - HILOGD("*****************************************************************"); - HILOGD("*****************************************************************"); - HILOGD("** Warning - BT Vendor Lib is loaded in debug tuning mode!"); - HILOGD("**"); - HILOGD("** If this is not intentional, rebuild libbt-vendor.so "); - HILOGD("** with VENDOR_LIB_RUNTIME_TUNING_ENABLED=FALSE and "); - HILOGD("** check if any run-time tuning parameters needed to be"); - HILOGD("** carried to the build-time configuration accordingly."); - HILOGD("*****************************************************************"); - HILOGD("*****************************************************************"); -#endif - - load_rtkbt_conf(); - load_rtkbt_stack_conf(); - if (p_cb == NULL) - { - HILOGE("init failed with no user callbacks!"); - return -1; - } - - userial_vendor_init(rtkbt_device_node); - - if (rtkbt_transtype & RTKBT_TRANS_UART) - { - upio_init(); - HILOGE("bt_wake_up_host_mode_set(1)"); - bt_wake_up_host_mode_set(1); - } - - /* store reference to user callbacks */ - bt_vendor_cbacks = (bt_vendor_callbacks_t *)p_cb; - - /* This is handed over from the stack */ - retval = memcpy_s(vnd_local_bd_addr, BD_ADDR_LEN, local_bdaddr, BD_ADDR_LEN); - - byte_reverse(vnd_local_bd_addr, BD_ADDR_LEN); - - if (rtk_btsnoop_dump) - rtk_btsnoop_open(); - if (rtk_btsnoop_net_dump) - rtk_btsnoop_net_open(); - - return retval; -} - -/** Requested operations */ -static int op(bt_opcode_t opcode, void *param) -{ - int retval = 0; - - // BTVNDDBG("op for %d", opcode); - - switch (opcode) - { - case BT_OP_POWER_ON: // Power on the BT Controller. - if (rtkbt_transtype & RTKBT_TRANS_UART) - { - upio_set_bluetooth_power(UPIO_BT_POWER_OFF); - usleep(200000); - BTVNDDBG("set power off and delay 200ms"); - upio_set_bluetooth_power(UPIO_BT_POWER_ON); - // usleep(200000); - BTVNDDBG("set power on and delay 00ms"); - } - break; - - case BT_OP_POWER_OFF: // Power off the BT Controller. - if (rtkbt_transtype & RTKBT_TRANS_UART) - { - upio_set_bluetooth_power(UPIO_BT_POWER_OFF); - usleep(200000); - BTVNDDBG("set power off and delay 200ms"); - } - break; - - // Establish hci channels. it will be called after BT_OP_POWER_ON. - case BT_OP_HCI_CHANNEL_OPEN: - { - if ((rtkbt_transtype & RTKBT_TRANS_UART) && - (rtkbt_transtype & RTKBT_TRANS_H5)) - { - int fd, idx; - int(*fd_array)[] = (int(*)[])param; - if (userial_vendor_open((tUSERIAL_CFG *)&userial_H5_cfg) != -1) - { - retval = 1; - } - - fd = userial_socket_open(); - if (fd != -1) - { - for (idx = 0; idx < HCI_MAX_CHANNEL; idx++) - (*fd_array)[idx] = fd; - } - else - retval = 0; - } - else if ((rtkbt_transtype & RTKBT_TRANS_UART) && - (rtkbt_transtype & RTKBT_TRANS_H4)) - { - /* retval contains numbers of open fd of HCI channels */ - int(*fd_array)[] = (int(*)[])param; - int fd, idx; - if (userial_vendor_open((tUSERIAL_CFG *)&userial_H4_cfg) != -1) - { - retval = 1; - } - fd = userial_socket_open(); - if (fd != -1) - { - for (idx = 0; idx < HCI_MAX_CHANNEL; idx++) - (*fd_array)[idx] = fd; - } - else - retval = 0; - /* retval contains numbers of open fd of HCI channels */ - } - else - { - BTVNDDBG("USB op for %d", opcode); - int fd, idx = 0; - int(*fd_array)[] = (int(*)[])param; - for (idx = 0; idx < 10; idx++) - { - if (userial_vendor_usb_open() != -1) - { - retval = 1; - break; - } - } - fd = userial_socket_open(); - if (fd != -1) - { - for (idx = 0; idx < HCI_MAX_CHANNEL; idx++) - (*fd_array)[idx] = fd; - } - else - retval = 0; - } - } - break; - - // Close all the hci channels which is opened. - case BT_OP_HCI_CHANNEL_CLOSE: - { - userial_vendor_close(); - } - break; - - // initialization the BT Controller. it will be called after - // BT_OP_HCI_CHANNEL_OPEN. Controller Must call init_cb to notify the host - // once it has been done. - case BT_OP_INIT: - { - if (rtkbt_transtype & RTKBT_TRANS_UART) - { - hw_config_start(rtkbt_transtype); - } - else - { - int usb_info = 0; - retval = userial_vendor_usb_ioctl(GET_USB_INFO, &usb_info); - if (retval == -1) - { - HILOGE("get usb info fail"); - // bt_vendor_cbacks->fwcfg_cb(BTC_OP_RESULT_FAIL); - return retval; - } - else - hw_usb_config_start(RTKBT_TRANS_H4, usb_info); - } - RTK_btservice_init(); - } - break; - - // Get the LPM idle timeout in milliseconds. - case BT_OP_GET_LPM_TIMER: - { - } - break; - - // Enable LPM mode on BT Controller. - case BT_OP_LPM_ENABLE: - { - } - break; - - // Disable LPM mode on BT Controller. - case BT_OP_LPM_DISABLE: - { - } - break; - - // Wakeup lock the BTC. - case BT_OP_WAKEUP_LOCK: - { - } - break; - - // Wakeup unlock the BTC. - case BT_OP_WAKEUP_UNLOCK: - { - } - break; - - // transmit event response to vendor lib. - case BT_OP_EVENT_CALLBACK: - { - hw_process_event((HC_BT_HDR *)param); - } - break; - } - - return retval; -} - -/** Closes the interface */ -static void cleanup(void) -{ - BTVNDDBG("cleanup"); - - if (rtkbt_transtype & RTKBT_TRANS_UART) - { - upio_cleanup(); - bt_wake_up_host_mode_set(0); - } - bt_vendor_cbacks = NULL; - - if (rtk_btsnoop_dump) - rtk_btsnoop_close(); - if (rtk_btsnoop_net_dump) - rtk_btsnoop_net_close(); - rtkbt_stack_conf_cleanup(); -} - -// Entry point of DLib -const bt_vendor_interface_t BLUETOOTH_VENDOR_LIB_INTERFACE = { - sizeof(bt_vendor_interface_t), init, op, cleanup}; diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/hardware.c b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/hardware.c deleted file mode 100755 index 11cc6721..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/hardware.c +++ /dev/null @@ -1,377 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -/****************************************************************************** - * - * Filename: hardware.c - * - * Description: Contains controller-specific functions, like - * firmware patch download - * low power mode operations - * - ******************************************************************************/ - -#define LOG_TAG "bt_hwcfg" -#define RTKBT_RELEASE_NAME "20190717_BT_ANDROID_9.0" - -#include "hardware.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "bt_hci_bdroid.h" -#include "bt_vendor_lib.h" -#include "bt_vendor_rtk.h" -#include "upio.h" -#include "userial.h" -#include "userial_vendor.h" - -/****************************************************************************** -** Constants & Macros -******************************************************************************/ - -/****************************************************************************** -** Externs -******************************************************************************/ - -// void hw_config_cback(void *p_evt_buf); -// void hw_usb_config_cback(void *p_evt_buf); - -extern uint8_t vnd_local_bd_addr[BD_ADDR_LEN]; -extern bool rtkbt_auto_restart; - -/****************************************************************************** -** Static variables -******************************************************************************/ -bt_hw_cfg_cb_t hw_cfg_cb; - -/* -static bt_lpm_param_t lpm_param = -{ - LPM_SLEEP_MODE, - LPM_IDLE_THRESHOLD, - LPM_HC_IDLE_THRESHOLD, - LPM_BT_WAKE_POLARITY, - LPM_HOST_WAKE_POLARITY, - LPM_ALLOW_HOST_SLEEP_DURING_SCO, - LPM_COMBINE_SLEEP_MODE_AND_LPM, - LPM_ENABLE_UART_TXD_TRI_STATE,*/ -// 0, /* not applicable */ -// 0, /* not applicable */ -// 0, /* not applicable */ -/*LPM_PULSED_HOST_WAKE -};*/ - -int getmacaddr(unsigned char *addr) -{ - int i = 0; - char data[256], *str; - int addr_fd; - - char property[100] = {0}; - memset(property, 0, sizeof(property)); - strcpy(property, "none"); - if (strncmp(property, "none", 4) == 0) - { - if (strcmp(property, "none") == 0) - { - return -1; - } - else if (strcmp(property, "default") == 0) - { - memcpy(addr, vnd_local_bd_addr, BD_ADDR_LEN); - return 0; - } - else if ((addr_fd = open(property, O_RDONLY)) != -1) - { - memset(data, 0, sizeof(data)); - int ret = read(addr_fd, data, 17); - if (ret < 17) - { - HILOGE("%s, read length = %d", __func__, ret); - close(addr_fd); - return -1; - } - for (i = 0, str = data; i < 6; i++) - { - addr[5 - i] = (unsigned char)strtoul(str, &str, 16); - str++; - } - close(addr_fd); - return 0; - } - } - return -1; -} - -int rtk_get_bt_firmware(uint8_t **fw_buf, char *fw_short_name) -{ - char filename[PATH_MAX] = {0}; - struct stat st; - int fd = -1; - size_t fwsize = 0; - size_t buf_size = 0; - - sprintf(filename, FIRMWARE_DIRECTORY, fw_short_name); - HILOGI("BT fw file: %s", filename); - - if (stat(filename, &st) < 0) - { - HILOGE("Can't access firmware, errno:%d", errno); - return -1; - } - - fwsize = st.st_size; - buf_size = fwsize; - - if ((fd = open(filename, O_RDONLY)) < 0) - { - HILOGE("Can't open firmware, errno:%d", errno); - return -1; - } - - if (!(*fw_buf = malloc(buf_size))) - { - HILOGE("Can't alloc memory for fw&config, errno:%d", errno); - if (fd >= 0) - close(fd); - return -1; - } - - if (read(fd, *fw_buf, fwsize) < (ssize_t)fwsize) - { - free(*fw_buf); - *fw_buf = NULL; - if (fd >= 0) - close(fd); - return -1; - } - - if (fd >= 0) - close(fd); - - HILOGI("Load FW OK"); - return buf_size; -} - -uint8_t rtk_get_fw_project_id(uint8_t *p_buf) -{ - uint8_t opcode; - uint8_t len; - uint8_t data = 0; - - do - { - opcode = *p_buf; - len = *(p_buf - 1); - if (opcode == 0x00) - { - if (len == 1) - { - data = *(p_buf - 2); - HILOGI("bt_hw_parse_project_id: opcode %d, len %d, data %d", opcode, - len, data); - break; - } - else - { - HILOGW("bt_hw_parse_project_id: invalid len %d", len); - } - } - p_buf -= len + 2; - } while (*p_buf != 0xFF); - - return data; -} - -uint8_t get_heartbeat_from_hardware() { return hw_cfg_cb.heartbeat; } - -struct rtk_epatch_entry *rtk_get_patch_entry(bt_hw_cfg_cb_t *cfg_cb) -{ - uint16_t i; - struct rtk_epatch *patch; - struct rtk_epatch_entry *entry; - uint8_t *p; - uint16_t chip_id; - - patch = (struct rtk_epatch *)cfg_cb->fw_buf; - entry = (struct rtk_epatch_entry *)malloc(sizeof(*entry)); - if (!entry) - { - HILOGE("rtk_get_patch_entry: failed to allocate mem for patch entry"); - return NULL; - } - - patch->number_of_patch = le16_to_cpu(patch->number_of_patch); - - HILOGI("rtk_get_patch_entry: fw_ver 0x%08x, patch_num %d", - le32_to_cpu(patch->fw_version), patch->number_of_patch); - - for (i = 0; i < patch->number_of_patch; i++) - { - p = cfg_cb->fw_buf + 14 + 2 * i; - STREAM_TO_UINT16(chip_id, p); - if (chip_id == cfg_cb->eversion + 1) - { - entry->chip_id = chip_id; - p = cfg_cb->fw_buf + 14 + 2 * patch->number_of_patch + 2 * i; - STREAM_TO_UINT16(entry->patch_length, p); - p = cfg_cb->fw_buf + 14 + 4 * patch->number_of_patch + 4 * i; - STREAM_TO_UINT32(entry->patch_offset, p); - HILOGI( - "rtk_get_patch_entry: chip_id %d, patch_len 0x%x, patch_offset 0x%x", - entry->chip_id, entry->patch_length, entry->patch_offset); - break; - } - } - - if (i == patch->number_of_patch) - { - HILOGE("rtk_get_patch_entry: failed to get etnry"); - free(entry); - entry = NULL; - } - - return entry; -} - -/****************************************************************************** -** LPM Static Functions -******************************************************************************/ - -/******************************************************************************* -** -** Function hw_lpm_ctrl_cback -** -** Description Callback function for lpm enable/disable request -** -** Returns None -** -*******************************************************************************/ -void hw_lpm_ctrl_cback(void *p_mem) -{ - HC_BT_HDR *p_evt_buf = (HC_BT_HDR *)p_mem; - // bt_vendor_op_result_t status = BTC_OP_RESULT_FAIL; - - if (*((uint8_t *)(p_evt_buf + 1) + HCI_EVT_CMD_CMPL_STATUS_OFFSET) == 0) - { - // status = BTC_OP_RESULT_SUCCESS; - } - - if (bt_vendor_cbacks) - { - // bt_vendor_cbacks->lpm_cb(status); - bt_vendor_cbacks->dealloc(p_evt_buf); - } -} - -#if (HW_END_WITH_HCI_RESET == TRUE) -/****************************************************************************** - * - ** - ** Function hw_epilog_cback - ** - ** Description Callback function for Command Complete Events from HCI - ** commands sent in epilog process. - ** - ** Returns None - ** - *******************************************************************************/ -void hw_epilog_cback(void *p_mem) -{ - HC_BT_HDR *p_evt_buf = (HC_BT_HDR *)p_mem; - uint8_t *p, status; - uint16_t opcode; - - status = *((uint8_t *)(p_evt_buf + 1) + HCI_EVT_CMD_CMPL_STATUS_OFFSET); - p = (uint8_t *)(p_evt_buf + 1) + HCI_EVT_CMD_CMPL_OPCODE_OFFSET; - STREAM_TO_UINT16(opcode, p); - - BTVNDDBG("%s Opcode:0x%04X Status: %d", __FUNCTION__, opcode, status); - - if (bt_vendor_cbacks) - { - /* Must free the RX event buffer */ - bt_vendor_cbacks->dealloc(p_evt_buf); - - /* Once epilog process is done, must call epilog_cb callback - to notify caller */ - bt_vendor_cbacks->init_cb(BTC_OP_RESULT_SUCCESS); - } -} - -/****************************************************************************** - * - ** - ** Function hw_epilog_process - ** - ** Description Sample implementation of epilog process - ** - ** Returns None - ** - *******************************************************************************/ -void hw_epilog_process(void) -{ - HC_BT_HDR *p_buf = NULL; - uint8_t *p; - - BTVNDDBG("hw_epilog_process"); - - /* Sending a HCI_RESET */ - if (bt_vendor_cbacks) - { - /* Must allocate command buffer via HC's alloc API */ - p_buf = (HC_BT_HDR *)bt_vendor_cbacks->alloc(BT_HC_HDR_SIZE + - HCI_CMD_PREAMBLE_SIZE); - } - - if (p_buf) - { - p_buf->event = MSG_STACK_TO_HC_HCI_CMD; - p_buf->offset = 0; - p_buf->layer_specific = 0; - p_buf->len = HCI_CMD_PREAMBLE_SIZE; - - p = (uint8_t *)(p_buf + 1); - UINT16_TO_STREAM(p, HCI_RESET); - *p = 0; /* parameter length */ - - /* Send command via HC's xmit_cb API */ - bt_vendor_cbacks->xmit_cb(HCI_RESET, p_buf); - } - else - { - if (bt_vendor_cbacks) - { - HILOGE("vendor lib epilog process aborted [no buffer]"); - bt_vendor_cbacks->init_cb(BTC_OP_RESULT_FAIL); - } - } -} -#endif // (HW_END_WITH_HCI_RESET == TRUE) diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/hardware_uart.c b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/hardware_uart.c deleted file mode 100755 index edb38f2d..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/hardware_uart.c +++ /dev/null @@ -1,1456 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -#define LOG_TAG "bt_hwcfg_uart" -#define RTKBT_RELEASE_NAME "20190717_BT_ANDROID_9.0" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "bt_hci_bdroid.h" -#include "bt_vendor_rtk.h" -#include "userial.h" -#include "userial_vendor.h" -#include "upio.h" -#include -#include -#include -#include - -#include "bt_vendor_lib.h" -#include "hardware.h" - -/****************************************************************************** -** Constants & Macros -******************************************************************************/ - -extern uint8_t vnd_local_bd_addr[BD_ADDR_LEN]; -extern bool rtkbt_auto_restart; -extern bt_hw_cfg_cb_t hw_cfg_cb; -void hw_config_cback(void *p_evt_buf); -extern int getmacaddr(unsigned char *addr); -extern uint8_t rtk_get_fw_project_id(uint8_t *p_buf); -extern struct rtk_epatch_entry *rtk_get_patch_entry(bt_hw_cfg_cb_t *cfg_cb); -extern int rtk_get_bt_firmware(uint8_t **fw_buf, char *fw_short_name); -extern volatile int h5_init_datatrans_flag; - -#define EXTRA_CONFIG_FILE "/vendor/etc/bluetooth/rtk_btconfig.txt" -static struct rtk_bt_vendor_config_entry *extra_extry; -static struct rtk_bt_vendor_config_entry *extra_entry_inx = NULL; - -/****************************************************************************** -** Static variables -******************************************************************************/ -// static bt_hw_cfg_cb_t hw_cfg_cb; - -//#define BT_CHIP_PROBE_SIMULATION -#ifdef BT_CHIP_PROBE_SIMULATION -static bt_hw_cfg_cb_t hw_cfg_test; -struct bt_chip_char -{ - uint16_t lmp_subversion; - uint8_t hci_version; - uint8_t hci_revision; - uint8_t chip_type; -}; -struct bt_chip_char bt_chip_chars[] = - { - {0x8723, 0x4, 0xb, CHIPTYPE_NONE}, // 8703as - {0x8723, 0x6, 0xb, CHIPTYPE_NONE}, // 8723bs - {0x8703, 0x4, 0xd, 0x7}, // 8703bs - {0x8703, 0x6, 0xb, 0x3}, // 8723cs-cg - {0x8703, 0x6, 0xb, 0x4}, // 8723cs-vf - {0x8703, 0x6, 0xb, 0x5}, // 8723cs-xx - {0x8723, 0x6, 0xd, CHIPTYPE_NONE}, // 8723ds -}; -#endif - -typedef struct -{ - uint16_t lmp_subversion; - uint32_t hci_version_mask; - uint32_t hci_revision_mask; - uint32_t chip_type_mask; - uint32_t project_id_mask; - char *patch_name; - char *config_name; - uint16_t mac_offset; - uint32_t max_patch_size; -} patch_info; - -static patch_info patch_table[] = { - /* lmp_subv hci_version_mask hci_revision_mask chip_type_mask project_id_mask fw name config name mac offset max_patch_size */ - {0x1200, HCI_VERSION_MASK_ALL, HCI_REVISION_MASK_ALL, CHIP_TYPE_MASK_ALL, 1 << 0, "rtl8723as_fw", "rtl8723as_config", CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, // Rtl8723AS - - {0x8723, ~(HCI_VERSION_MASK_21), ~(1 << 0xd), CHIP_TYPE_MASK_ALL, 1 << 1, "rtl8723bs_fw", "rtl8723bs_config", CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, // Rtl8723BS - // {0x8723, ~(HCI_VERSION_MASK_21), ~(1<<0xd), CHIP_TYPE_MASK_ALL, 1<<1, "rtl8723bs_VQ0_fw", "rtl8723bs_VQ0_config", CONFIG_MAC_OFFSET_GEN_1_2}, //Rtl8723BS_VQ0 - {0x8821, HCI_VERSION_MASK_ALL, ~(1 << 0xc), CHIP_TYPE_MASK_ALL, 1 << 2, "rtl8821as_fw", "rtl8821as_config", CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, // Rtl8821AS - // {0x8761, HCI_VERSION_MASK_ALL, HCI_REVISION_MASK_ALL, CHIP_TYPE_MASK_ALL, 1<<3, "rtl8761at_fw", "rtl8761at_config", CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, //Rtl8761AW - {0x8761, HCI_VERSION_MASK_ALL, ~(1 << 0xb), CHIP_TYPE_MASK_ALL, 1 << 3, "rtl8761at_fw", "rtl8761at_config", CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, // Rtl8761AW - {0x8761, HCI_VERSION_MASK_ALL, (1 << 0xb), CHIP_TYPE_MASK_ALL, 1 << 14, "rtl8761bt_fw", "rtl8761bt_config", CONFIG_MAC_OFFSET_GEN_4PLUS, MAX_PATCH_SIZE_40K}, // Rtl8761BW - - {0x8723, HCI_VERSION_MASK_21, HCI_REVISION_MASK_ALL, CHIP_TYPE_MASK_ALL, 1 << 4, "rtl8703as_fw", "rtl8703as_config", CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}, // Rtl8703AS - - {0x8703, HCI_VERSION_MASK_ALL, HCI_REVISION_MASK_ALL, 1 << 7, 1 << 6, "rtl8703bs_fw", "rtl8703bs_config", CONFIG_MAC_OFFSET_GEN_3PLUS, MAX_PATCH_SIZE_24K}, // Rtl8703BS - {0x8703, HCI_VERSION_MASK_ALL, HCI_REVISION_MASK_ALL, 1 << 5, 1 << 7, "rtl8723cs_xx_fw", "rtl8723cs_xx_config", CONFIG_MAC_OFFSET_GEN_3PLUS, MAX_PATCH_SIZE_24K}, // rtl8723cs_xx - {0x8703, HCI_VERSION_MASK_ALL, HCI_REVISION_MASK_ALL, 1 << 3, 1 << 7, "rtl8723cs_cg_fw", "rtl8723cs_cg_config", CONFIG_MAC_OFFSET_GEN_3PLUS, MAX_PATCH_SIZE_24K}, // rtl8723cs_cg - {0x8703, HCI_VERSION_MASK_ALL, HCI_REVISION_MASK_ALL, 1 << 4, 1 << 7, "rtl8723cs_vf_fw", "rtl8723cs_vf_config", CONFIG_MAC_OFFSET_GEN_3PLUS, MAX_PATCH_SIZE_24K}, // rtl8723cs_vf - // {0x8822, HCI_VERSION_MASK_ALL, HCI_REVISION_MASK_ALL, CHIP_TYPE_MASK_ALL, 1<<8, "rtl8822bs_fw", "rtl8822bs_config", CONFIG_MAC_OFFSET_GEN_3PLUS, MAX_PATCH_SIZE_24K}, //Rtl8822BS - {0x8822, HCI_VERSION_MASK_ALL, ~(1 << 0xc), CHIP_TYPE_MASK_ALL, 1 << 8, "rtl8822bs_fw", "rtl8822bs_config", CONFIG_MAC_OFFSET_GEN_3PLUS, MAX_PATCH_SIZE_24K}, // Rtl8822BS - {0x8822, HCI_VERSION_MASK_ALL, (1 << 0xc), CHIP_TYPE_MASK_ALL, 1 << 13, "rtl8822cs_fw", "rtl8822cs_config", CONFIG_MAC_OFFSET_GEN_4PLUS, MAX_PATCH_SIZE_40K}, // Rtl8822CS - - {0x8723, HCI_VERSION_MASK_ALL, (1 << 0xd), ~(1 << 7), 1 << 9, "rtl8723ds_fw", "rtl8723ds_config", CONFIG_MAC_OFFSET_GEN_3PLUS, MAX_PATCH_SIZE_40K}, // Rtl8723ds - {0x8723, HCI_VERSION_MASK_ALL, (1 << 0xd), 1 << 7, 1 << 9, "rtl8703cs_fw", "rtl8703cs_config", CONFIG_MAC_OFFSET_GEN_3PLUS, MAX_PATCH_SIZE_40K}, // Rtl8703cs - {0x8821, HCI_VERSION_MASK_ALL, (1 << 0xc), CHIP_TYPE_MASK_ALL, 1 << 10, "rtl8821cs_fw", "rtl8821cs_config", CONFIG_MAC_OFFSET_GEN_3PLUS, MAX_PATCH_SIZE_40K}, // RTL8821CS - /* todo: RTL8703CS */ - - {LMP_SUBVERSION_NONE, HCI_VERSION_MASK_ALL, HCI_REVISION_MASK_ALL, CHIP_TYPE_MASK_ALL, PROJECT_ID_MASK_ALL, "rtl_none_fw", "rtl_none_config", CONFIG_MAC_OFFSET_GEN_1_2, MAX_PATCH_SIZE_24K}}; - -/* -static bt_lpm_param_t lpm_param = -{ - LPM_SLEEP_MODE, - LPM_IDLE_THRESHOLD, - LPM_HC_IDLE_THRESHOLD, - LPM_BT_WAKE_POLARITY, - LPM_HOST_WAKE_POLARITY, - LPM_ALLOW_HOST_SLEEP_DURING_SCO, - LPM_COMBINE_SLEEP_MODE_AND_LPM, - LPM_ENABLE_UART_TXD_TRI_STATE,*/ -// 0, /* not applicable */ -// 0, /* not applicable */ -// 0, /* not applicable */ -/*LPM_PULSED_HOST_WAKE -};*/ -// signature: realtech -static const uint8_t RTK_EPATCH_SIGNATURE[8] = {0x52, 0x65, 0x61, 0x6C, 0x74, 0x65, 0x63, 0x68}; -// Extension Section IGNATURE:0x77FD0451 -static const uint8_t EXTENSION_SECTION_SIGNATURE[4] = {0x51, 0x04, 0xFD, 0x77}; - -static int check_match_state(bt_hw_cfg_cb_t *cfg, uint32_t mask) -{ - patch_info *patch_entry; - int res = 0; - - for (patch_entry = patch_table; patch_entry->lmp_subversion != LMP_SUBVERSION_NONE; patch_entry++) - { - if (patch_entry->lmp_subversion != cfg->lmp_subversion) - continue; - if ((patch_entry->hci_version_mask != HCI_VERSION_MASK_ALL) && ((patch_entry->hci_version_mask & (1 << cfg->hci_version)) == 0)) - continue; - if ((patch_entry->hci_revision_mask != HCI_REVISION_MASK_ALL) && ((patch_entry->hci_revision_mask & (1 << cfg->hci_revision)) == 0)) - continue; - if ((mask & PATCH_OPTIONAL_MATCH_FLAG_CHIPTYPE) && (patch_entry->chip_type_mask != CHIP_TYPE_MASK_ALL) && ((patch_entry->chip_type_mask & (1 << cfg->chip_type)) == 0)) - continue; - res++; - } - HILOGI("check_match_state return %d(cfg->lmp_subversion:0x%x cfg->hci_vesion:0x%x cfg->hci_revision:0x%x cfg->chip_type:0x%x mask:%08x)\n", - res, cfg->lmp_subversion, cfg->hci_version, cfg->hci_revision, cfg->chip_type, mask); - return res; -} - -static patch_info *get_patch_entry(bt_hw_cfg_cb_t *cfg) -{ - patch_info *patch_entry; - - HILOGI("get_patch_entry(lmp_subversion:0x%x hci_vesion:0x%x cfg->hci_revision:0x%x chip_type:0x%x)\n", - cfg->lmp_subversion, cfg->hci_version, cfg->hci_revision, cfg->chip_type); - for (patch_entry = patch_table; patch_entry->lmp_subversion != LMP_SUBVERSION_NONE; patch_entry++) - { - if (patch_entry->lmp_subversion != cfg->lmp_subversion) - continue; - if ((patch_entry->hci_version_mask != HCI_VERSION_MASK_ALL) && ((patch_entry->hci_version_mask & (1 << cfg->hci_version)) == 0)) - continue; - if ((patch_entry->hci_revision_mask != HCI_REVISION_MASK_ALL) && ((patch_entry->hci_revision_mask & (1 << cfg->hci_revision)) == 0)) - continue; - if ((patch_entry->chip_type_mask != CHIP_TYPE_MASK_ALL) && ((patch_entry->chip_type_mask & (1 << cfg->chip_type)) == 0)) - continue; - break; - } - HILOGI("get_patch_entry return(patch_name:%s config_name:%s mac_offset:0x%x)\n", - patch_entry->patch_name, patch_entry->config_name, patch_entry->mac_offset); - return patch_entry; -} - -typedef struct _baudrate_ex -{ - uint32_t rtk_speed; - uint32_t uart_speed; -} baudrate_ex; - -baudrate_ex baudrates[] = -{ - {0x00006004, 921600}, - {0x05F75004, 921600}, // RTL8723BS - {0x00004003, 1500000}, - {0x052A8002, 1500000}, // RTL8723BS - {0x04928002, 1500000}, // RTL8723BS - {0x00005002, 2000000}, // same as RTL8723AS - {0x00008001, 3000000}, - {0x04928001, 3000000}, // RTL8723BS - {0x06B58001, 3000000}, // add RTL8703as - {0x00007001, 3500000}, - {0x052A6001, 3500000}, // RTL8723BS - {0x00005001, 4000000}, // same as RTL8723AS - {0x0000701d, 115200}, - {0x0252C014, 115200} // RTL8723BS -}; - -/** - * Change realtek Bluetooth speed to uart speed. It is matching in the struct baudrates: - * - * @code - * baudrate_ex baudrates[] = - * { - * {0x7001, 3500000}, - * {0x6004, 921600}, - * {0x4003, 1500000}, - * {0x5001, 4000000}, - * {0x5002, 2000000}, - * {0x8001, 3000000}, - * {0x701d, 115200} - * }; - * @endcode - * - * If there is no match in baudrates, uart speed will be set as #115200. - * - * @param rtk_speed realtek Bluetooth speed - * @param uart_speed uart speed - * - */ -static void rtk_speed_to_uart_speed(uint32_t rtk_speed, uint32_t *uart_speed) -{ - *uart_speed = 115200; - - uint8_t i; - for (i = 0; i < sizeof(baudrates) / sizeof(baudrate_ex); i++) - { - if (baudrates[i].rtk_speed == rtk_speed) - { - *uart_speed = baudrates[i].uart_speed; - return; - } - } - return; -} - -/** - * Change uart speed to realtek Bluetooth speed. It is matching in the struct baudrates: - * - * @code - * baudrate_ex baudrates[] = - * { - * {0x7001, 3500000}, - * {0x6004, 921600}, - * {0x4003, 1500000}, - * {0x5001, 4000000}, - * {0x5002, 2000000}, - * {0x8001, 3000000}, - * {0x701d, 115200} - * }; - * @endcode - * - * If there is no match in baudrates, realtek Bluetooth speed will be set as #0x701D. - * - * @param uart_speed uart speed - * @param rtk_speed realtek Bluetooth speed - * - */ -/* -static inline void uart_speed_to_rtk_speed(uint32_t uart_speed, uint32_t* rtk_speed) -{ - *rtk_speed = 0x701D; - - unsigned int i; - for (i=0; i< sizeof(baudrates)/sizeof(baudrate_ex); i++) - { - if (baudrates[i].uart_speed == uart_speed) - { - *rtk_speed = baudrates[i].rtk_speed; - return; - } - } - return; -} -*/ - -/******************************************************************************* -** -** Function hw_config_set_bdaddr -** -** Description Program controller's Bluetooth Device Address -** -** Returns TRUE, if valid address is sent -** FALSE, otherwise -** -*******************************************************************************/ -static uint8_t hw_config_set_controller_baudrate(HC_BT_HDR *p_buf, uint32_t baudrate) -{ - uint8_t retval = FALSE; - uint8_t *p = (uint8_t *)(p_buf + 1); - - UINT16_TO_STREAM(p, HCI_VSC_UPDATE_BAUDRATE); - *p++ = 4; /* parameter length */ - UINT32_TO_STREAM(p, baudrate); - - p_buf->len = HCI_CMD_PREAMBLE_SIZE + 4; - - retval = bt_vendor_cbacks->xmit_cb(HCI_VSC_UPDATE_BAUDRATE, p_buf); - - return (retval); -} - -/******************************************************************************* -** -** Function line_speed_to_userial_baud -** -** Description helper function converts line speed number into USERIAL baud -** rate symbol -** -** Returns unit8_t (USERIAL baud symbol) -** -*******************************************************************************/ -static uint8_t line_speed_to_userial_baud(uint32_t line_speed) -{ - uint8_t baud; - - if (line_speed == 4000000) - baud = USERIAL_BAUD_4M; - else if (line_speed == 3000000) - baud = USERIAL_BAUD_3M; - else if (line_speed == 2000000) - baud = USERIAL_BAUD_2M; - else if (line_speed == 1500000) - baud = USERIAL_BAUD_1_5M; - else if (line_speed == 1000000) - baud = USERIAL_BAUD_1M; - else if (line_speed == 921600) - baud = USERIAL_BAUD_921600; - else if (line_speed == 460800) - baud = USERIAL_BAUD_460800; - else if (line_speed == 230400) - baud = USERIAL_BAUD_230400; - else if (line_speed == 115200) - baud = USERIAL_BAUD_115200; - else if (line_speed == 57600) - baud = USERIAL_BAUD_57600; - else if (line_speed == 19200) - baud = USERIAL_BAUD_19200; - else if (line_speed == 9600) - baud = USERIAL_BAUD_9600; - else if (line_speed == 1200) - baud = USERIAL_BAUD_1200; - else if (line_speed == 600) - baud = USERIAL_BAUD_600; - else - { - HILOGE("userial vendor: unsupported baud speed %d", line_speed); - baud = USERIAL_BAUD_115200; - } - - return baud; -} - -/** - * Change uart speed to realtek Bluetooth speed. It is matching in the struct baudrates: - * - * @code - * baudrate_ex baudrates[] = - * { - * {0x7001, 3500000}, - * {0x6004, 921600}, - * {0x4003, 1500000}, - * {0x5001, 4000000}, - * {0x5002, 2000000}, - * {0x8001, 3000000}, - * {0x701d, 115200} - * }; - * @endcode - * - * If there is no match in baudrates, realtek Bluetooth speed will be set as #0x701D. - * - * @param uart_speed uart speed - * @param rtk_speed realtek Bluetooth speed - * - */ -/* -static inline void uart_speed_to_rtk_speed(uint32_t uart_speed, uint32_t* rtk_speed) -{ - *rtk_speed = 0x701D; - - unsigned int i; - for (i=0; i< sizeof(baudrates)/sizeof(baudrate_ex); i++) - { - if (baudrates[i].uart_speed == uart_speed) - { - *rtk_speed = baudrates[i].rtk_speed; - return; - } - } - return; -} -*/ - -static void line_process(char *buf, unsigned short *offset, int *t) -{ - char *head = buf; - char *ptr = buf; - char *argv[32]; - int argc = 0; - unsigned char len = 0; - int i = 0; - static int alt_size = 0; - - if (buf[0] == '\0' || buf[0] == '#' || buf[0] == '[') - return; - if (alt_size > MAX_ALT_CONFIG_SIZE - 4) - { - HILOGW("Extra Config file is too large"); - return; - } - if (extra_entry_inx == NULL) - extra_entry_inx = extra_extry; - HILOGI("line_process:%s", buf); - while ((ptr = strsep(&head, ", \t")) != NULL) - { - if (!ptr[0]) - continue; - argv[argc++] = ptr; - if (argc >= 32) - { - HILOGW("Config item is too long"); - break; - } - } - - if (argc < 4) - { - HILOGE("Invalid Config item, ignore"); - return; - } - - offset[(*t)] = (unsigned short)((strtoul(argv[0], NULL, 16)) | (strtoul(argv[1], NULL, 16) << 8)); - HILOGI("Extra Config offset %04x", offset[(*t)]); - extra_entry_inx->offset = offset[(*t)]; - (*t)++; - len = (unsigned char)strtoul(argv[2], NULL, 16); - if (len != (unsigned char)(argc - 3)) - { - HILOGE("Extra Config item len %d is not match, we assume the actual len is %d", len, (argc - 3)); - len = argc - 3; - } - extra_entry_inx->entry_len = len; - - alt_size += len + sizeof(struct rtk_bt_vendor_config_entry); - if (alt_size > MAX_ALT_CONFIG_SIZE) - { - HILOGW("Extra Config file is too large"); - extra_entry_inx->offset = 0; - extra_entry_inx->entry_len = 0; - alt_size -= (len + sizeof(struct rtk_bt_vendor_config_entry)); - return; - } - for (i = 0; i < len; i++) - { - extra_entry_inx->entry_data[i] = (uint8_t)strtoul(argv[3 + i], NULL, 16); - HILOGI("data[%d]:%02x", i, extra_entry_inx->entry_data[i]); - } - extra_entry_inx = (struct rtk_bt_vendor_config_entry *)((uint8_t *)extra_entry_inx + len + sizeof(struct rtk_bt_vendor_config_entry)); -} - -static void parse_extra_config(const char *path, patch_info *patch_entry, unsigned short *offset, int *t) -{ - int fd, ret; - unsigned char buf[1024]; - - fd = open(path, O_RDONLY); - if (fd == -1) - { - HILOGI("Couldn't open extra config %s, err:%s", path, strerror(errno)); - return; - } - - ret = read(fd, buf, sizeof(buf)); - if (ret == -1) - { - HILOGE("Couldn't read %s, err:%s", path, strerror(errno)); - close(fd); - return; - } - else if (ret == 0) - { - HILOGE("%s is empty", path); - close(fd); - return; - } - - if (ret > 1022) - { - HILOGE("Extra config file is too big"); - close(fd); - return; - } - buf[ret++] = '\n'; - buf[ret++] = '\0'; - close(fd); - char *head = (void *)buf; - char *ptr = (void *)buf; - ptr = strsep(&head, "\n\r"); - if (strncmp(ptr, patch_entry->config_name, strlen(ptr))) - { - HILOGW("Extra config file not set for %s, ignore", patch_entry->config_name); - return; - } - while ((ptr = strsep(&head, "\n\r")) != NULL) - { - if (!ptr[0]) - continue; - line_process(ptr, offset, t); - } -} - -static inline int getAltSettings(patch_info *patch_entry, unsigned short *offset) //(patch_info *patch_entry, unsigned short *offset, int max_group_cnt) -{ - int n = 0; - if (patch_entry) - offset[n++] = patch_entry->mac_offset; - else - return n; - /* - //sample code, add special settings - - offset[n++] = 0x15B; - */ - if (extra_extry) - parse_extra_config(EXTRA_CONFIG_FILE, patch_entry, offset, &n); - - return n; -} -static inline int getAltSettingVal(patch_info *patch_entry, unsigned short offset, unsigned char *val) -{ - int res = 0; - int i = 0; - struct rtk_bt_vendor_config_entry *ptr = extra_extry; - - while (ptr->offset) - { - if (ptr->offset == offset) - { - if (offset != patch_entry->mac_offset) - { - memcpy(val, ptr->entry_data, ptr->entry_len); - res = ptr->entry_len; - HILOGI("Get Extra offset:%04x, val:", offset); - for (i = 0; i < ptr->entry_len; i++) - HILOGI("%02x", ptr->entry_data[i]); - } - break; - } - ptr = (struct rtk_bt_vendor_config_entry *)((uint8_t *)ptr + ptr->entry_len + sizeof(struct rtk_bt_vendor_config_entry)); - } - /* - switch(offset) - { - - //sample code, add special settings - case 0x15B: - val[0] = 0x0B; - val[1] = 0x0B; - val[2] = 0x0B; - val[3] = 0x0B; - res = 4; - break; - - default: - res = 0; - break; - } - */ - if ((patch_entry) && (offset == patch_entry->mac_offset) && (res == 0)) - { - if (getmacaddr(val) == 0) - { - HILOGI("MAC: %02x:%02x:%02x:%02x:%02x:%02x", val[5], val[4], val[3], val[2], val[1], val[0]); - res = 6; - } - } - return res; -} - -static void rtk_update_altsettings(patch_info *patch_entry, unsigned char *config_buf_ptr, size_t *config_len_ptr) -{ - unsigned short offset[256], data_len; - unsigned char val[256]; - - struct rtk_bt_vendor_config *config = (struct rtk_bt_vendor_config *)config_buf_ptr; - struct rtk_bt_vendor_config_entry *entry = config->entry; - size_t config_len = *config_len_ptr; - unsigned int i = 0; - int count = 0, temp = 0, j; - - if ((extra_extry = (struct rtk_bt_vendor_config_entry *)malloc(MAX_ALT_CONFIG_SIZE)) == NULL) - { - HILOGE("malloc buffer for extra_extry failed"); - } - else - memset(extra_extry, 0, MAX_ALT_CONFIG_SIZE); - - HILOGI("ORG Config len=%08zx:\n", config_len); - for (i = 0; i <= config_len; i += 0x10) - { - HILOGI("%08x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", i, - config_buf_ptr[i], config_buf_ptr[i + 1], config_buf_ptr[i + 2], config_buf_ptr[i + 3], config_buf_ptr[i + 4], config_buf_ptr[i + 5], config_buf_ptr[i + 6], config_buf_ptr[i + 7], - config_buf_ptr[i + 8], config_buf_ptr[i + 9], config_buf_ptr[i + 10], config_buf_ptr[i + 11], config_buf_ptr[i + 12], config_buf_ptr[i + 13], config_buf_ptr[i + 14], config_buf_ptr[i + 15]); - } - - memset(offset, 0, sizeof(offset)); - memset(val, 0, sizeof(val)); - data_len = le16_to_cpu(config->data_len); - - count = getAltSettings(patch_entry, offset); // getAltSettings(patch_entry, offset, sizeof(offset)/sizeof(unsigned short)); - if (count <= 0) - { - HILOGI("rtk_update_altsettings: No AltSettings"); - return; - } - else - { - HILOGI("rtk_update_altsettings: %d AltSettings", count); - } - - if (data_len != config_len - sizeof(struct rtk_bt_vendor_config)) - { - HILOGE("rtk_update_altsettings: config len(%x) is not right(%lx)", data_len, (unsigned long)(config_len - sizeof(struct rtk_bt_vendor_config))); - return; - } - - for (i = 0; i < data_len;) - { - for (j = 0; j < count; j++) - { - if (le16_to_cpu(entry->offset) == offset[j]) - { - if (offset[j] == patch_entry->mac_offset) - offset[j] = 0; - else - { - struct rtk_bt_vendor_config_entry *t = extra_extry; - while (t->offset) - { - if (t->offset == le16_to_cpu(entry->offset)) - { - if (t->entry_len == entry->entry_len) - offset[j] = 0; - break; - } - t = (struct rtk_bt_vendor_config_entry *)((uint8_t *)t + t->entry_len + sizeof(struct rtk_bt_vendor_config_entry)); - } - } - } - } - if (getAltSettingVal(patch_entry, le16_to_cpu(entry->offset), val) == entry->entry_len) - { - HILOGI("rtk_update_altsettings: replace %04x[%02x]", le16_to_cpu(entry->offset), entry->entry_len); - memcpy(entry->entry_data, val, entry->entry_len); - } - temp = entry->entry_len + sizeof(struct rtk_bt_vendor_config_entry); - i += temp; - entry = (struct rtk_bt_vendor_config_entry *)((uint8_t *)entry + temp); - } - for (j = 0; j < count; j++) - { - if (offset[j] == 0) - continue; - entry->entry_len = getAltSettingVal(patch_entry, offset[j], val); - if (entry->entry_len <= 0) - continue; - entry->offset = cpu_to_le16(offset[j]); - memcpy(entry->entry_data, val, entry->entry_len); - HILOGI("rtk_update_altsettings: add %04x[%02x]", le16_to_cpu(entry->offset), entry->entry_len); - temp = entry->entry_len + sizeof(struct rtk_bt_vendor_config_entry); - i += temp; - entry = (struct rtk_bt_vendor_config_entry *)((uint8_t *)entry + temp); - } - config->data_len = cpu_to_le16(i); - *config_len_ptr = i + sizeof(struct rtk_bt_vendor_config); - - if (extra_extry) - { - free(extra_extry); - extra_extry = NULL; - extra_entry_inx = NULL; - } - - HILOGI("NEW Config len=%08zx:\n", *config_len_ptr); - for (i = 0; i <= (*config_len_ptr); i += 0x10) - { - HILOGI("%08x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", i, - config_buf_ptr[i], config_buf_ptr[i + 1], config_buf_ptr[i + 2], config_buf_ptr[i + 3], config_buf_ptr[i + 4], config_buf_ptr[i + 5], config_buf_ptr[i + 6], config_buf_ptr[i + 7], - config_buf_ptr[i + 8], config_buf_ptr[i + 9], config_buf_ptr[i + 10], config_buf_ptr[i + 11], config_buf_ptr[i + 12], config_buf_ptr[i + 13], config_buf_ptr[i + 14], config_buf_ptr[i + 15]); - } - return; -} - -static uint32_t rtk_parse_config_file(unsigned char **config_buf, size_t *filelen, uint8_t bt_addr[6], uint16_t mac_offset) -{ - struct rtk_bt_vendor_config *config = (struct rtk_bt_vendor_config *)*config_buf; - uint16_t config_len = le16_to_cpu(config->data_len), temp = 0; - struct rtk_bt_vendor_config_entry *entry = config->entry; - unsigned int i = 0; - uint32_t baudrate = 0; - uint8_t heartbeat_buf = 0; - // uint32_t config_has_bdaddr = 0; - uint8_t *p; - - HILOGD("bt_addr = %x", bt_addr[0]); - if (le32_to_cpu(config->signature) != RTK_VENDOR_CONFIG_MAGIC) - { - HILOGE("config signature magic number(0x%x) is not set to RTK_VENDOR_CONFIG_MAGIC", config->signature); - return 0; - } - - if (config_len != *filelen - sizeof(struct rtk_bt_vendor_config)) - { - HILOGE("config len(0x%x) is not right(0x%lx)", config_len, (unsigned long)(*filelen - sizeof(struct rtk_bt_vendor_config))); - return 0; - } - - hw_cfg_cb.heartbeat = 0; - for (i = 0; i < config_len;) - { - switch (le16_to_cpu(entry->offset)) - { - case 0xc: - { - p = (uint8_t *)entry->entry_data; - STREAM_TO_UINT32(baudrate, p); - if (entry->entry_len >= 12) - { - hw_cfg_cb.hw_flow_cntrl |= 0x80; /* bit7 set hw flow control */ - if (entry->entry_data[12] & 0x04) /* offset 0x18, bit2 */ - hw_cfg_cb.hw_flow_cntrl |= 1; /* bit0 enable hw flow control */ - } - - HILOGI("config baud rate to :0x%08x, hwflowcontrol:0x%x, 0x%x", baudrate, entry->entry_data[12], hw_cfg_cb.hw_flow_cntrl); - break; - } - case 0x017a: - { - if (mac_offset == CONFIG_MAC_OFFSET_GEN_1_2) - { - p = (uint8_t *)entry->entry_data; - STREAM_TO_UINT8(heartbeat_buf, p); - if ((heartbeat_buf & 0x02) && (heartbeat_buf & 0x10)) - hw_cfg_cb.heartbeat = 1; - else - hw_cfg_cb.heartbeat = 0; - - HILOGI("config 0x017a heartbeat = %d", hw_cfg_cb.heartbeat); - } - break; - } - case 0x01be: - { - if (mac_offset == CONFIG_MAC_OFFSET_GEN_3PLUS || mac_offset == CONFIG_MAC_OFFSET_GEN_4PLUS) - { - p = (uint8_t *)entry->entry_data; - STREAM_TO_UINT8(heartbeat_buf, p); - if ((heartbeat_buf & 0x02) && (heartbeat_buf & 0x10)) - hw_cfg_cb.heartbeat = 1; - else - hw_cfg_cb.heartbeat = 0; - - HILOGI("config 0x01be heartbeat = %d", hw_cfg_cb.heartbeat); - } - break; - } - default: - HILOGI("config offset(0x%x),length(0x%x)", entry->offset, entry->entry_len); - break; - } - temp = entry->entry_len + sizeof(struct rtk_bt_vendor_config_entry); - i += temp; - entry = (struct rtk_bt_vendor_config_entry *)((uint8_t *)entry + temp); - } - - return baudrate; -} - -static void rtk_get_bt_final_patch(bt_hw_cfg_cb_t *cfg_cb) -{ - uint8_t proj_id = 0; - struct rtk_epatch_entry *entry = NULL; - struct rtk_epatch *patch = (struct rtk_epatch *)cfg_cb->fw_buf; - // int iBtCalLen = 0; - - if (cfg_cb->lmp_subversion == LMPSUBVERSION_8723a) - { - if (memcmp(cfg_cb->fw_buf, RTK_EPATCH_SIGNATURE, 8) == 0) - { - HILOGE("8723as check signature error!"); - cfg_cb->dl_fw_flag = 0; - goto free_buf; - } - else - { - cfg_cb->total_len = cfg_cb->fw_len + cfg_cb->config_len; - if (!(cfg_cb->total_buf = malloc(cfg_cb->total_len))) - { - HILOGE("can't alloc memory for fw&config, errno:%d", errno); - cfg_cb->dl_fw_flag = 0; - goto free_buf; - } - else - { - HILOGI("8723as, fw copy direct"); - memcpy(cfg_cb->total_buf, cfg_cb->fw_buf, cfg_cb->fw_len); - memcpy(cfg_cb->total_buf + cfg_cb->fw_len, cfg_cb->config_buf, cfg_cb->config_len); - cfg_cb->dl_fw_flag = 1; - goto free_buf; - } - } - } - - if (memcmp(cfg_cb->fw_buf, RTK_EPATCH_SIGNATURE, 8)) - { - HILOGE("check signature error"); - cfg_cb->dl_fw_flag = 0; - goto free_buf; - } - - /* check the extension section signature */ - if (memcmp(cfg_cb->fw_buf + cfg_cb->fw_len - 4, EXTENSION_SECTION_SIGNATURE, 4)) - { - HILOGE("check extension section signature error"); - cfg_cb->dl_fw_flag = 0; - goto free_buf; - } - - proj_id = rtk_get_fw_project_id(cfg_cb->fw_buf + cfg_cb->fw_len - 5); - - if ((hw_cfg_cb.project_id_mask != PROJECT_ID_MASK_ALL) && ((hw_cfg_cb.project_id_mask & (1 << proj_id)) == 0)) - { - HILOGE("hw_cfg_cb.project_id_mask is 0x%08x, fw project_id is %d, does not match!!!", - hw_cfg_cb.project_id_mask, proj_id); - cfg_cb->dl_fw_flag = 0; - goto free_buf; - } - - entry = rtk_get_patch_entry(cfg_cb); - if (entry) - { - cfg_cb->total_len = entry->patch_length + cfg_cb->config_len; - } - else - { - cfg_cb->dl_fw_flag = 0; - goto free_buf; - } - - HILOGI("total_len = 0x%x", cfg_cb->total_len); - - if (!(cfg_cb->total_buf = malloc(cfg_cb->total_len))) - { - HILOGE("Can't alloc memory for multi fw&config, errno:%d", errno); - cfg_cb->dl_fw_flag = 0; - goto free_buf; - } - else - { - memcpy(cfg_cb->total_buf, cfg_cb->fw_buf + entry->patch_offset, entry->patch_length); - memcpy(cfg_cb->total_buf + entry->patch_length - 4, &patch->fw_version, 4); - memcpy(&entry->svn_version, cfg_cb->total_buf + entry->patch_length - 8, 4); - memcpy(&entry->coex_version, cfg_cb->total_buf + entry->patch_length - 12, 4); - HILOGI("BTCOEX:20%06d-%04x svn_version:%d lmp_subversion:0x%x hci_version:0x%x hci_revision:0x%x chip_type:%d Cut:%d libbt-vendor_uart version:%s\n", - ((entry->coex_version >> 16) & 0x7ff) + ((entry->coex_version >> 27) * 10000), - (entry->coex_version & 0xffff), entry->svn_version, cfg_cb->lmp_subversion, cfg_cb->hci_version, cfg_cb->hci_revision, cfg_cb->chip_type, cfg_cb->eversion + 1, RTK_VERSION); - } - - if (cfg_cb->config_len) - { - memcpy(cfg_cb->total_buf + entry->patch_length, cfg_cb->config_buf, cfg_cb->config_len); - } - - cfg_cb->dl_fw_flag = 1; - HILOGI("Fw:%s exists, config file:%s exists", (cfg_cb->fw_len > 0) ? "" : "not", (cfg_cb->config_len > 0) ? "" : "not"); - -free_buf: - if (cfg_cb->fw_len > 0) - { - free(cfg_cb->fw_buf); - cfg_cb->fw_len = 0; - } - - if (cfg_cb->config_len > 0) - { - free(cfg_cb->config_buf); - cfg_cb->config_len = 0; - } - - if (entry) - { - free(entry); - } -} - -static uint32_t rtk_get_bt_config(unsigned char **config_buf, - uint32_t *config_baud_rate, char *config_file_short_name, uint16_t mac_offset) -{ - char bt_config_file_name[PATH_MAX] = {0}; - struct stat st; - size_t filelen; - int fd; - // FILE* file = NULL; - - sprintf(bt_config_file_name, BT_CONFIG_DIRECTORY, config_file_short_name); - HILOGI("BT config file: %s", bt_config_file_name); - - if (stat(bt_config_file_name, &st) < 0) - { - HILOGE("can't access bt config file:%s, errno:%d\n", bt_config_file_name, errno); - return 0; - } - - filelen = st.st_size; - if (filelen > MAX_ORG_CONFIG_SIZE) - { - HILOGE("bt config file is too large(>0x%04x)", MAX_ORG_CONFIG_SIZE); - return 0; - } - - if ((fd = open(bt_config_file_name, O_RDONLY)) < 0) - { - HILOGE("Can't open bt config file"); - return 0; - } - - if ((*config_buf = malloc(MAX_ORG_CONFIG_SIZE + MAX_ALT_CONFIG_SIZE)) == NULL) - { - HILOGE("malloc buffer for config file fail(0x%zx)\n", filelen); - close(fd); - return 0; - } - - if (read(fd, *config_buf, filelen) < (ssize_t)filelen) - { - HILOGE("Can't load bt config file"); - free(*config_buf); - close(fd); - return 0; - } - - *config_baud_rate = rtk_parse_config_file(config_buf, &filelen, vnd_local_bd_addr, mac_offset); - HILOGI("Get config baud rate from config file:0x%x", *config_baud_rate); - - close(fd); - return filelen; -} - -static int hci_download_patch_h4(HC_BT_HDR *p_buf, int index, uint8_t *data, int len) -{ - uint8_t retval = FALSE; - uint8_t *p = (uint8_t *)(p_buf + 1); - - UINT16_TO_STREAM(p, HCI_VSC_DOWNLOAD_FW_PATCH); - *p++ = 1 + len; /* parameter length */ - *p++ = index; - memcpy(p, data, len); - p_buf->len = HCI_CMD_PREAMBLE_SIZE + 1 + len; - - hw_cfg_cb.state = HW_CFG_DL_FW_PATCH; - - retval = bt_vendor_cbacks->xmit_cb(HCI_VSC_DOWNLOAD_FW_PATCH, p_buf); - return retval; -} - -/******************************************************************************* -** -** Function hw_config_cback -** -** Description Callback function for controller configuration -** -** Returns None -** -*******************************************************************************/ -void hw_config_cback(void *p_mem) -{ - HC_BT_HDR *p_evt_buf = NULL; - uint8_t *p = NULL, *pp = NULL; - uint8_t status = 0; - uint16_t opcode = 0; - HC_BT_HDR *p_buf = NULL; - uint8_t is_proceeding = FALSE; - int i = 0; - uint8_t iIndexRx = 0; - patch_info *prtk_patch_file_info = NULL; - uint32_t host_baudrate = 0; - -#if (USE_CONTROLLER_BDADDR == TRUE) - // const uint8_t null_bdaddr[BD_ADDR_LEN] = {0,0,0,0,0,0}; -#endif - - if (p_mem != NULL) - { - p_evt_buf = (HC_BT_HDR *)p_mem; - status = *((uint8_t *)(p_evt_buf + 1) + HCI_EVT_CMD_CMPL_STATUS_OFFSET); - p = (uint8_t *)(p_evt_buf + 1) + HCI_EVT_CMD_CMPL_OPCODE_OFFSET; - STREAM_TO_UINT16(opcode, p); - } - - if (opcode == HCI_VSC_H5_INIT) - { - if (status != 0) - { - HILOGE("%s, status = %d", __func__, status); - if ((bt_vendor_cbacks) && (p_evt_buf != NULL)) - bt_vendor_cbacks->dealloc(p_evt_buf); - if (rtkbt_auto_restart) - { - // if(bt_vendor_cbacks) - // bt_vendor_cbacks->fwcfg_cb(BTC_OP_RESULT_FAIL); - kill(getpid(), SIGKILL); - } - return; - } - } - - /* Ask a new buffer big enough to hold any HCI commands sent in here */ - /*a cut fc6d status==1*/ - if (((status == 0) || (opcode == HCI_VSC_READ_ROM_VERSION)) && bt_vendor_cbacks) - p_buf = (HC_BT_HDR *)bt_vendor_cbacks->alloc(BT_HC_HDR_SIZE + HCI_CMD_MAX_LEN); - - if (p_buf != NULL) - { - p_buf->event = MSG_STACK_TO_HC_HCI_CMD; - p_buf->offset = 0; - p_buf->len = 0; - p_buf->layer_specific = 0; - - BTVNDDBG("hw_cfg_cb.state = %i", hw_cfg_cb.state); - switch (hw_cfg_cb.state) - { - case HW_CFG_H5_INIT: - { - p = (uint8_t *)(p_buf + 1); - UINT16_TO_STREAM(p, HCI_READ_LMP_VERSION); - *p++ = 0; - p_buf->len = HCI_CMD_PREAMBLE_SIZE; - - hw_cfg_cb.state = HW_CFG_READ_LOCAL_VER; - is_proceeding = bt_vendor_cbacks->xmit_cb(HCI_READ_LMP_VERSION, p_buf); - break; - } - case HW_CFG_READ_LOCAL_VER: - { - if (status == 0 && p_evt_buf) - { - p = ((uint8_t *)(p_evt_buf + 1) + HCI_EVT_CMD_CMPL_OP1001_HCI_VERSION_OFFSET); - STREAM_TO_UINT16(hw_cfg_cb.hci_version, p); - p = ((uint8_t *)(p_evt_buf + 1) + HCI_EVT_CMD_CMPL_OP1001_HCI_REVISION_OFFSET); - STREAM_TO_UINT16(hw_cfg_cb.hci_revision, p); - p = (uint8_t *)(p_evt_buf + 1) + HCI_EVT_CMD_CMPL_OP1001_LMP_SUBVERSION_OFFSET; - STREAM_TO_UINT16(hw_cfg_cb.lmp_subversion, p); - BTVNDDBG("lmp_subversion = 0x%x hw_cfg_cb.hci_version = 0x%x hw_cfg_cb.hci_revision = 0x%x", hw_cfg_cb.lmp_subversion, hw_cfg_cb.hci_version, hw_cfg_cb.hci_revision); - if (hw_cfg_cb.lmp_subversion == LMPSUBVERSION_8723a) - { - hw_cfg_cb.state = HW_CFG_START; - goto CFG_START; - } - else - { - hw_cfg_cb.state = HW_CFG_READ_ECO_VER; - p = (uint8_t *)(p_buf + 1); - UINT16_TO_STREAM(p, HCI_VSC_READ_ROM_VERSION); - *p++ = 0; - p_buf->len = HCI_CMD_PREAMBLE_SIZE; - is_proceeding = bt_vendor_cbacks->xmit_cb(HCI_VSC_READ_ROM_VERSION, p_buf); - } - } - break; - } - case HW_CFG_READ_ECO_VER: - { - if (status == 0 && p_evt_buf) - { - hw_cfg_cb.eversion = *((uint8_t *)(p_evt_buf + 1) + HCI_EVT_CMD_CMPL_OPFC6D_EVERSION_OFFSET); - BTVNDDBG("hw_config_cback chip_id of the IC:%d", hw_cfg_cb.eversion + 1); - } - else if (1 == status) - { - hw_cfg_cb.eversion = 0; - } - else - { - is_proceeding = FALSE; - break; - } - - if (check_match_state(&hw_cfg_cb, 0) > 1) // check if have multiple matched patch_entry by lmp_subversion,hci_version, hci_revision - { - hw_cfg_cb.state = HW_CFG_READ_CHIP_TYPE; - p = (uint8_t *)(p_buf + 1); - UINT16_TO_STREAM(p, HCI_VSC_READ_CHIP_TYPE); - *p++ = 5; - UINT8_TO_STREAM(p, 0x00); - UINT32_TO_STREAM(p, 0xB000A094); - p_buf->len = HCI_CMD_PREAMBLE_SIZE + HCI_CMD_READ_CHIP_TYPE_SIZE; - - pp = (uint8_t *)(p_buf + 1); - for (i = 0; i < p_buf->len; i++) - BTVNDDBG("get chip type command data[%d]= 0x%x", i, *(pp + i)); - - is_proceeding = bt_vendor_cbacks->xmit_cb(HCI_VSC_READ_CHIP_TYPE, p_buf); - break; - } - else - { - hw_cfg_cb.state = HW_CFG_START; - goto CFG_START; - } - } - case HW_CFG_READ_CHIP_TYPE: - { - if (!p_evt_buf) - { - HILOGE("%s, buffer is null", __func__); - is_proceeding = FALSE; - break; - } - BTVNDDBG("READ_CHIP_TYPE status = %d, length = %d", status, p_evt_buf->len); - p = (uint8_t *)(p_evt_buf + 1); - for (i = 0; i < p_evt_buf->len; i++) - BTVNDDBG("READ_CHIP_TYPE event data[%d]= 0x%x", i, *(p + i)); - if (status == 0) - { - hw_cfg_cb.chip_type = ((*((uint8_t *)(p_evt_buf + 1) + HCI_EVT_CMD_CMPL_OPFC61_CHIPTYPE_OFFSET)) & 0x0F); - BTVNDDBG("READ_CHIP_TYPE hw_cfg_cb.lmp_subversion = 0x%x", hw_cfg_cb.lmp_subversion); - BTVNDDBG("READ_CHIP_TYPE hw_cfg_cb.hci_version = 0x%x", hw_cfg_cb.hci_version); - BTVNDDBG("READ_CHIP_TYPE hw_cfg_cb.hci_revision = 0x%x", hw_cfg_cb.hci_revision); - BTVNDDBG("READ_CHIP_TYPE hw_cfg_cb.chip_type = 0x%x", hw_cfg_cb.chip_type); - } - else - { - is_proceeding = FALSE; - break; - } - if (check_match_state(&hw_cfg_cb, PATCH_OPTIONAL_MATCH_FLAG_CHIPTYPE) > 1) // check if have multiple matched patch_entry by lmp_subversion,hci_version, hci_revision and chiptype - { - BTVNDDBG("check_match_state(lmp_subversion:0x%04x, hci_version:%d, hci_revision:%d chip_type:%d): Multi Matched Patch\n", hw_cfg_cb.lmp_subversion, hw_cfg_cb.hci_version, hw_cfg_cb.hci_revision, hw_cfg_cb.chip_type); - is_proceeding = FALSE; - break; - } - hw_cfg_cb.state = HW_CFG_START; - } - CFG_START: - case HW_CFG_START: - { -#ifdef BT_CHIP_PROBE_SIMULATION - { - int ii; - memcpy(&hw_cfg_test, &hw_cfg_cb, sizeof(hw_cfg_test)); - for (i = 0; i < sizeof(bt_chip_chars) / sizeof(bt_chip_chars[0]); i++) - { - BTVNDDBG("BT_CHIP_PROBE_SIMULATION loop:%d $$$ BEGIN $$$\n", i); - hw_cfg_test.lmp_subversion = bt_chip_chars[i].lmp_subversion; - hw_cfg_test.hci_version = bt_chip_chars[i].hci_version; - hw_cfg_test.hci_revision = bt_chip_chars[i].hci_revision; - hw_cfg_test.chip_type = CHIPTYPE_NONE; - if (check_match_state(&hw_cfg_test, 0) > 1) - { - BTVNDDBG("check_match_state hw_cfg_test(lmp_subversion:0x%04x, hci_version:%d, hci_revision:%d chip_type:%d): Multi Matched Patch\n", hw_cfg_test.lmp_subversion, hw_cfg_test.hci_version, hw_cfg_test.hci_revision, hw_cfg_test.chip_type); - if (bt_chip_chars[i].chip_type != CHIPTYPE_NONE) - { - BTVNDDBG("BT_CHIP_PROBE_SIMULATION loop:%d *** Include ChipType ***\n", i); - hw_cfg_test.chip_type = bt_chip_chars[i].chip_type; - if (check_match_state(&hw_cfg_test, PATCH_OPTIONAL_MATCH_FLAG_CHIPTYPE) > 1) - { - BTVNDDBG("check_match_state hw_cfg_test(lmp_subversion:0x%04x, hci_version:%d, hci_revision:%d chip_type:%d): Multi Matched Patch\n", hw_cfg_test.lmp_subversion, hw_cfg_test.hci_version, hw_cfg_test.hci_revision, hw_cfg_test.chip_type); - } - else - { - prtk_patch_file_info = get_patch_entry(&hw_cfg_test); - } - } - } - else - { - prtk_patch_file_info = get_patch_entry(&hw_cfg_test); - } - BTVNDDBG("BT_CHIP_PROBE_SIMULATION loop:%d $$$ END $$$\n", i); - } - } -#endif - // get efuse config file and patch code file - prtk_patch_file_info = get_patch_entry(&hw_cfg_cb); - - if ((prtk_patch_file_info == NULL) || (prtk_patch_file_info->lmp_subversion == 0)) - { - HILOGE("get patch entry error"); - is_proceeding = FALSE; - break; - } - hw_cfg_cb.max_patch_size = prtk_patch_file_info->max_patch_size; - hw_cfg_cb.config_len = rtk_get_bt_config(&hw_cfg_cb.config_buf, &hw_cfg_cb.baudrate, prtk_patch_file_info->config_name, prtk_patch_file_info->mac_offset); - if (hw_cfg_cb.config_len == 0) - { - HILOGE("Get Config file fail, just use efuse settings"); - // hw_cfg_cb.config_len = 0; - } - rtk_update_altsettings(prtk_patch_file_info, hw_cfg_cb.config_buf, &(hw_cfg_cb.config_len)); - - hw_cfg_cb.fw_len = rtk_get_bt_firmware(&hw_cfg_cb.fw_buf, prtk_patch_file_info->patch_name); - if (hw_cfg_cb.fw_len < 0) - { - HILOGE("Get BT firmware fail"); - hw_cfg_cb.fw_len = 0; - } - else - { - hw_cfg_cb.project_id_mask = prtk_patch_file_info->project_id_mask; - rtk_get_bt_final_patch(&hw_cfg_cb); - } - BTVNDDBG("Check total_len(0x%08x) max_patch_size(0x%08x)", hw_cfg_cb.total_len, hw_cfg_cb.max_patch_size); - if (hw_cfg_cb.total_len > hw_cfg_cb.max_patch_size) - { - HILOGE("total length of fw&config(0x%08x) larger than max_patch_size(0x%08x)", hw_cfg_cb.total_len, hw_cfg_cb.max_patch_size); - is_proceeding = FALSE; - break; - } - - if ((hw_cfg_cb.total_len > 0) && hw_cfg_cb.dl_fw_flag) - { - hw_cfg_cb.patch_frag_cnt = hw_cfg_cb.total_len / PATCH_DATA_FIELD_MAX_SIZE; - hw_cfg_cb.patch_frag_tail = hw_cfg_cb.total_len % PATCH_DATA_FIELD_MAX_SIZE; - if (hw_cfg_cb.patch_frag_tail) - hw_cfg_cb.patch_frag_cnt += 1; - else - hw_cfg_cb.patch_frag_tail = PATCH_DATA_FIELD_MAX_SIZE; - BTVNDDBG("patch fragment count %d, tail len %d", hw_cfg_cb.patch_frag_cnt, hw_cfg_cb.patch_frag_tail); - } - else - { - is_proceeding = FALSE; - break; - } - - if ((hw_cfg_cb.baudrate == 0) && ((hw_cfg_cb.hw_flow_cntrl & 0x80) == 0)) - { - BTVNDDBG("no baudrate to set and no need to set hw flow control"); - goto DOWNLOAD_FW; - } - - if ((hw_cfg_cb.baudrate == 0) && (hw_cfg_cb.hw_flow_cntrl & 0x80)) - { - BTVNDDBG("no baudrate to set but set hw flow control is needed"); - goto SET_HW_FLCNTRL; - } - } - /* fall through intentionally */ - case HW_CFG_SET_UART_BAUD_CONTROLLER: - BTVNDDBG("bt vendor lib: set CONTROLLER UART baud 0x%x", hw_cfg_cb.baudrate); - hw_cfg_cb.state = HW_CFG_SET_UART_BAUD_HOST; - is_proceeding = hw_config_set_controller_baudrate(p_buf, hw_cfg_cb.baudrate); - break; - - case HW_CFG_SET_UART_BAUD_HOST: - /* update baud rate of host's UART port */ - BTVNDDBG("bt vendor lib: set HOST UART baud start"); - rtk_speed_to_uart_speed(hw_cfg_cb.baudrate, &host_baudrate); - BTVNDDBG("bt vendor lib: set HOST UART baud %i", host_baudrate); - userial_vendor_set_baud(line_speed_to_userial_baud(host_baudrate)); - - if ((hw_cfg_cb.hw_flow_cntrl & 0x80) == 0) - goto DOWNLOAD_FW; - -SET_HW_FLCNTRL: - case HW_CFG_SET_UART_HW_FLOW_CONTROL: - BTVNDDBG("Change HW flowcontrol setting"); - if (hw_cfg_cb.hw_flow_cntrl & 0x01) - { - userial_vendor_set_hw_fctrl(1); - } - else - { - userial_vendor_set_hw_fctrl(0); - } - ms_delay(50); - hw_cfg_cb.state = HW_CFG_DL_FW_PATCH; - BTVNDDBG("start donwload fw"); - -DOWNLOAD_FW: - case HW_CFG_DL_FW_PATCH: - BTVNDDBG("bt vendor lib: HW_CFG_DL_FW_PATCH status:%i, opcode:0x%x", status, opcode); - - // recv command complete event for patch code download command - if (opcode == HCI_VSC_DOWNLOAD_FW_PATCH) - { - iIndexRx = *((uint8_t *)(p_evt_buf + 1) + HCI_EVT_CMD_CMPL_STATUS_OFFSET + 1); - BTVNDDBG("bt vendor lib: HW_CFG_DL_FW_PATCH status:%i, iIndexRx:%i", status, iIndexRx); - hw_cfg_cb.patch_frag_idx++; - - if (iIndexRx & 0x80) - { - BTVNDDBG("vendor lib fwcfg completed"); - free(hw_cfg_cb.total_buf); - hw_cfg_cb.total_len = 0; - - bt_vendor_cbacks->dealloc(p_buf); - // bt_vendor_cbacks->fwcfg_cb(BTC_OP_RESULT_SUCCESS); - - hw_cfg_cb.state = 0; - is_proceeding = TRUE; - h5_init_datatrans_flag = 0; - break; - } - } - - if (hw_cfg_cb.patch_frag_idx < hw_cfg_cb.patch_frag_cnt) - { - iIndexRx = hw_cfg_cb.patch_frag_idx ? ((hw_cfg_cb.patch_frag_idx - 1) % 0x7f + 1) : 0; - if (hw_cfg_cb.patch_frag_idx == hw_cfg_cb.patch_frag_cnt - 1) - { - BTVNDDBG("HW_CFG_DL_FW_PATCH: send last fw fragment"); - iIndexRx |= 0x80; - hw_cfg_cb.patch_frag_len = hw_cfg_cb.patch_frag_tail; - } - else - { - iIndexRx &= 0x7F; - hw_cfg_cb.patch_frag_len = PATCH_DATA_FIELD_MAX_SIZE; - } - } - - is_proceeding = hci_download_patch_h4(p_buf, iIndexRx, - hw_cfg_cb.total_buf + (hw_cfg_cb.patch_frag_idx * PATCH_DATA_FIELD_MAX_SIZE), - hw_cfg_cb.patch_frag_len); - break; - - default: - break; - } // switch(hw_cfg_cb.state) - } // if (p_buf != NULL) - - /* Free the RX event buffer */ - if ((bt_vendor_cbacks) && (p_evt_buf != NULL)) - bt_vendor_cbacks->dealloc(p_evt_buf); - - if (is_proceeding == FALSE) - { - HILOGE("vendor lib fwcfg aborted!!!"); - if (bt_vendor_cbacks) - { - if (p_buf != NULL) - bt_vendor_cbacks->dealloc(p_buf); - - // bt_vendor_cbacks->fwcfg_cb(BTC_OP_RESULT_FAIL); - } - - if (hw_cfg_cb.config_len) - { - free(hw_cfg_cb.config_buf); - hw_cfg_cb.config_len = 0; - } - - if (hw_cfg_cb.fw_len) - { - free(hw_cfg_cb.fw_buf); - hw_cfg_cb.fw_len = 0; - } - - if (hw_cfg_cb.total_len) - { - free(hw_cfg_cb.total_buf); - hw_cfg_cb.total_len = 0; - } - hw_cfg_cb.state = 0; - } -} - -/***************************************************************************** -** Hardware Configuration Interface Functions -*****************************************************************************/ - -/******************************************************************************* -** -** Function hw_config_start -** -** Description Kick off controller initialization process -** -** Returns None -** -*******************************************************************************/ -void hw_config_start(char transtype) -{ - memset(&hw_cfg_cb, 0, sizeof(bt_hw_cfg_cb_t)); - hw_cfg_cb.dl_fw_flag = 1; - hw_cfg_cb.chip_type = CHIPTYPE_NONE; - BTVNDDBG("RTKBT_RELEASE_NAME: %s", RTKBT_RELEASE_NAME); - BTVNDDBG("\nRealtek libbt-vendor_uart Version %s \n", RTK_VERSION); - HC_BT_HDR *p_buf = NULL; - uint8_t *p; - - BTVNDDBG("hw_config_start, transtype = 0x%x \n", transtype); - /* Start from sending H5 INIT */ - if (bt_vendor_cbacks) - { - /* Must allocate command buffer via HC's alloc API */ - p_buf = (HC_BT_HDR *)bt_vendor_cbacks->alloc(BT_HC_HDR_SIZE + - HCI_CMD_PREAMBLE_SIZE); - if (p_buf) - { - p_buf->event = MSG_STACK_TO_HC_HCI_CMD; - p_buf->offset = 0; - p_buf->layer_specific = 0; - p_buf->len = HCI_CMD_PREAMBLE_SIZE; - - p = (uint8_t *)(p_buf + 1); - - if (transtype & RTKBT_TRANS_H4) - { - p = (uint8_t *)(p_buf + 1); - UINT16_TO_STREAM(p, HCI_READ_LMP_VERSION); - *p++ = 0; - p_buf->len = HCI_CMD_PREAMBLE_SIZE; - - hw_cfg_cb.state = HW_CFG_READ_LOCAL_VER; - bt_vendor_cbacks->xmit_cb(HCI_READ_LMP_VERSION, p_buf); - } - else - { - UINT16_TO_STREAM(p, HCI_VSC_H5_INIT); - *p = 0; /* parameter length */ - hw_cfg_cb.state = HW_CFG_H5_INIT; - - bt_vendor_cbacks->xmit_cb(HCI_VSC_H5_INIT, p_buf); - } - } - else - { - HILOGE("%s buffer alloc fail!", __func__); - } - } - else - HILOGE("%s call back is null", __func__); -} diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/hardware_usb.c b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/hardware_usb.c deleted file mode 100755 index e1588eed..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/hardware_usb.c +++ /dev/null @@ -1,1171 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -#define LOG_TAG "bt_hwcfg_usb" -#define RTKBT_RELEASE_NAME "20190717_BT_ANDROID_9.0" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "bt_hci_bdroid.h" -#include "bt_vendor_rtk.h" -#include "userial.h" -#include "userial_vendor.h" -#include "upio.h" -#include -#include -#include -#include - -#include "bt_vendor_lib.h" -#include "hardware.h" -#include "rtk_common.h" - -/****************************************************************************** -** Constants & Macros -******************************************************************************/ - -extern uint8_t vnd_local_bd_addr[BD_ADDR_LEN]; -extern bool rtkbt_auto_restart; -void hw_usb_config_cback(void *p_evt_buf); -extern bt_hw_cfg_cb_t hw_cfg_cb; -extern int getmacaddr(unsigned char *addr); -extern struct rtk_epatch_entry *rtk_get_patch_entry(bt_hw_cfg_cb_t *cfg_cb); -extern int rtk_get_bt_firmware(uint8_t **fw_buf, char *fw_short_name); -extern uint8_t rtk_get_fw_project_id(uint8_t *p_buf); - -#define EXTRA_CONFIG_FILE "/vendor/etc/bluetooth/rtk_btconfig.txt" -static struct rtk_bt_vendor_config_entry *extra_extry; -static struct rtk_bt_vendor_config_entry *extra_entry_inx = NULL; - -#define BT_VENDOR_CFG_TIMEDELAY_ 40 - -typedef void (*tTIMER_HANDLE_CBACK)(union sigval sigval_value); - -static timer_t OsAllocateTimer(tTIMER_HANDLE_CBACK timer_callback) -{ - struct sigevent sigev; - timer_t timerid; - - (void)memset_s(&sigev, sizeof(struct sigevent), 0, sizeof(struct sigevent)); - // Create the POSIX timer to generate signo - sigev.sigev_notify = SIGEV_THREAD; - sigev.sigev_notify_function = timer_callback; - sigev.sigev_value.sival_ptr = &timerid; - - // Create the Timer using timer_create signal - - if (timer_create(CLOCK_REALTIME, &sigev, &timerid) == 0) - { - return timerid; - } - else - { - HILOGE("timer_create error!"); - return (timer_t)-1; - } -} - -static int OsFreeTimer(timer_t timerid) -{ - int ret = 0; - ret = timer_delete(timerid); - if (ret != 0) - { - HILOGE("timer_delete fail with errno(%d)", errno); - } - - return ret; -} - -static int OsStartTimer(timer_t timerid, int msec, int mode) -{ - struct itimerspec itval; - - itval.it_value.tv_sec = msec / 1000; - itval.it_value.tv_nsec = (long)(msec % 1000) * (1000000L); - - if (mode == 1) - { - itval.it_interval.tv_sec = itval.it_value.tv_sec; - itval.it_interval.tv_nsec = itval.it_value.tv_nsec; - } - else - { - itval.it_interval.tv_sec = 0; - itval.it_interval.tv_nsec = 0; - } - - // Set the Timer when to expire through timer_settime - - if (timer_settime(timerid, 0, &itval, NULL) != 0) - { - HILOGE("time_settime error!"); - return -1; - } - - return 0; -} - -static timer_t localtimer = 0; -static void local_timer_handler(union sigval sigev_value) -{ - bt_vendor_cbacks->init_cb(BTC_OP_RESULT_SUCCESS); - OsFreeTimer(localtimer); -} - -static void start_fwcfg_cbtimer(void) -{ - if (localtimer == 0) - { - localtimer = OsAllocateTimer(local_timer_handler); - } - OsStartTimer(localtimer, BT_VENDOR_CFG_TIMEDELAY_, 0); -} - -/****************************************************************************** -** Static variables -******************************************************************************/ -// static bt_hw_cfg_cb_t hw_cfg_cb; - -typedef struct -{ - uint16_t vid; - uint16_t pid; - uint16_t lmp_sub_default; - uint16_t lmp_sub; - uint16_t eversion; - char *mp_patch_name; - char *patch_name; - char *config_name; - uint8_t *fw_cache; - int fw_len; - uint16_t mac_offset; - uint32_t max_patch_size; -} usb_patch_info; - -static usb_patch_info usb_fw_patch_table[] = { - /* { vid, pid, lmp_sub_default, lmp_sub, everion, mp_fw_name, fw_name, config_name, fw_cache, fw_len, mac_offset } */ - {0x0BDA, 0xD723, 0x8723, 0, 0, "mp_rtl8723d_fw", "rtl8723d_fw", "rtl8723d_config", NULL, 0, CONFIG_MAC_OFFSET_GEN_3PLUS, MAX_PATCH_SIZE_40K}, /* RTL8723DU */ - /* todo: RTL8703CU */ - - /* NOTE: must append patch entries above the null entry */ - {0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, 0, 0, 0}}; - -uint16_t usb_project_id[] = { - ROM_LMP_8723a, - ROM_LMP_8723b, - ROM_LMP_8821a, - ROM_LMP_8761a, - ROM_LMP_8703a, - ROM_LMP_8763a, - ROM_LMP_8703b, - ROM_LMP_8723c, - ROM_LMP_8822b, - ROM_LMP_8723d, - ROM_LMP_8821c, - ROM_LMP_NONE, - ROM_LMP_NONE, - ROM_LMP_8822c, - ROM_LMP_8761b, - ROM_LMP_NONE}; -// signature: realtech -static const uint8_t RTK_EPATCH_SIGNATURE[8] = {0x52, 0x65, 0x61, 0x6C, 0x74, 0x65, 0x63, 0x68}; -// Extension Section IGNATURE:0x77FD0451 -static const uint8_t EXTENSION_SECTION_SIGNATURE[4] = {0x51, 0x04, 0xFD, 0x77}; - -static void usb_line_process(char *buf, unsigned short *offset, int *t) -{ - char *head = buf; - char *ptr = buf; - char *argv[32]; - int argc = 0; - unsigned char len = 0; - int i = 0; - static int alt_size = 0; - - if (buf[0] == '\0' || buf[0] == '#' || buf[0] == '[') - return; - if (alt_size > MAX_ALT_CONFIG_SIZE - 4) - { - HILOGW("Extra Config file is too large"); - return; - } - if (extra_entry_inx == NULL) - extra_entry_inx = extra_extry; - HILOGI("line_process:%s", buf); - while ((ptr = strsep(&head, ", \t")) != NULL) - { - if (!ptr[0]) - continue; - argv[argc++] = ptr; - if (argc >= 32) - { - HILOGW("Config item is too long"); - break; - } - } - - if (argc < 4) - { - HILOGE("Invalid Config item, ignore"); - return; - } - - offset[(*t)] = (unsigned short)((strtoul(argv[0], NULL, 16)) | (strtoul(argv[1], NULL, 16) << 8)); - HILOGI("Extra Config offset %04x", offset[(*t)]); - extra_entry_inx->offset = offset[(*t)]; - (*t)++; - len = (unsigned char)strtoul(argv[2], NULL, 16); - if (len != (unsigned char)(argc - 3)) - { - HILOGE("Extra Config item len %d is not match, we assume the actual len is %d", len, (argc - 3)); - len = argc - 3; - } - extra_entry_inx->entry_len = len; - - alt_size += len + sizeof(struct rtk_bt_vendor_config_entry); - if (alt_size > MAX_ALT_CONFIG_SIZE) - { - HILOGW("Extra Config file is too large"); - extra_entry_inx->offset = 0; - extra_entry_inx->entry_len = 0; - alt_size -= (len + sizeof(struct rtk_bt_vendor_config_entry)); - return; - } - for (i = 0; i < len; i++) - { - extra_entry_inx->entry_data[i] = (uint8_t)strtoul(argv[3 + i], NULL, 16); - HILOGI("data[%d]:%02x", i, extra_entry_inx->entry_data[i]); - } - extra_entry_inx = (struct rtk_bt_vendor_config_entry *)((uint8_t *)extra_entry_inx + len + sizeof(struct rtk_bt_vendor_config_entry)); -} - -static void usb_parse_extra_config(const char *path, usb_patch_info *patch_entry, unsigned short *offset, int *t) -{ - int fd, ret; - unsigned char buf[1024]; - - fd = open(path, O_RDONLY); - if (fd == -1) - { - HILOGI("Couldn't open extra config %s, err:%s", path, strerror(errno)); - return; - } - - ret = read(fd, buf, sizeof(buf)); - if (ret == -1) - { - HILOGE("Couldn't read %s, err:%s", path, strerror(errno)); - close(fd); - return; - } - else if (ret == 0) - { - HILOGE("%s is empty", path); - close(fd); - return; - } - - if (ret > 1022) - { - HILOGE("Extra config file is too big"); - close(fd); - return; - } - buf[ret++] = '\n'; - buf[ret++] = '\0'; - close(fd); - char *head = (void *)buf; - char *ptr = (void *)buf; - ptr = strsep(&head, "\n\r"); - if (strncmp(ptr, patch_entry->config_name, strlen(ptr))) - { - HILOGW("Extra config file not set for %s, ignore", patch_entry->config_name); - return; - } - while ((ptr = strsep(&head, "\n\r")) != NULL) - { - if (!ptr[0]) - continue; - usb_line_process(ptr, offset, t); - } -} - -static inline int getUsbAltSettings(usb_patch_info *patch_entry, unsigned short *offset) //(patch_info *patch_entry, unsigned short *offset, int max_group_cnt) -{ - int n = 0; - if (patch_entry) - offset[n++] = patch_entry->mac_offset; - else - return n; - /* - //sample code, add special settings - - offset[n++] = 0x15B; - */ - if (extra_extry) - usb_parse_extra_config(EXTRA_CONFIG_FILE, patch_entry, offset, &n); - - return n; -} - -static inline int getUsbAltSettingVal(usb_patch_info *patch_entry, unsigned short offset, unsigned char *val) -{ - int res = 0; - - int i = 0; - struct rtk_bt_vendor_config_entry *ptr = extra_extry; - - while (ptr->offset) - { - if (ptr->offset == offset) - { - if (offset != patch_entry->mac_offset) - { - memcpy(val, ptr->entry_data, ptr->entry_len); - res = ptr->entry_len; - HILOGI("Get Extra offset:%04x, val:", offset); - for (i = 0; i < ptr->entry_len; i++) - HILOGI("%02x", ptr->entry_data[i]); - } - break; - } - ptr = (struct rtk_bt_vendor_config_entry *)((uint8_t *)ptr + ptr->entry_len + sizeof(struct rtk_bt_vendor_config_entry)); - } - - /* switch(offset) - { - //sample code, add special settings - case 0x15B: - val[0] = 0x0B; - val[1] = 0x0B; - val[2] = 0x0B; - val[3] = 0x0B; - res = 4; - break; - - default: - res = 0; - break; - } - */ - if ((patch_entry) && (offset == patch_entry->mac_offset) && (res == 0)) - { - if (getmacaddr(val) == 0) - { - HILOGI("MAC: %02x:%02x:%02x:%02x:%02x:%02x", val[5], val[4], val[3], val[2], val[1], val[0]); - res = 6; - } - } - return res; -} - -static void rtk_usb_update_altsettings(usb_patch_info *patch_entry, unsigned char *config_buf_ptr, size_t *config_len_ptr) -{ - unsigned short offset[256], data_len; - unsigned char val[256]; - - struct rtk_bt_vendor_config *config = (struct rtk_bt_vendor_config *)config_buf_ptr; - struct rtk_bt_vendor_config_entry *entry = config->entry; - size_t config_len = *config_len_ptr; - unsigned int i = 0; - int count = 0, temp = 0, j; - - if ((extra_extry = (struct rtk_bt_vendor_config_entry *)malloc(MAX_ALT_CONFIG_SIZE)) == NULL) - { - HILOGE("malloc buffer for extra_extry failed"); - } - else - memset(extra_extry, 0, MAX_ALT_CONFIG_SIZE); - - HILOGI("ORG Config len=%08zx:\n", config_len); - for (i = 0; i <= config_len; i += 0x10) - { - HILOGI("%08x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", i, - config_buf_ptr[i], config_buf_ptr[i + 1], config_buf_ptr[i + 2], config_buf_ptr[i + 3], config_buf_ptr[i + 4], config_buf_ptr[i + 5], config_buf_ptr[i + 6], config_buf_ptr[i + 7], - config_buf_ptr[i + 8], config_buf_ptr[i + 9], config_buf_ptr[i + 10], config_buf_ptr[i + 11], config_buf_ptr[i + 12], config_buf_ptr[i + 13], config_buf_ptr[i + 14], config_buf_ptr[i + 15]); - } - - memset(offset, 0, sizeof(offset)); - memset(val, 0, sizeof(val)); - data_len = le16_to_cpu(config->data_len); - - count = getUsbAltSettings(patch_entry, offset); // getAltSettings(patch_entry, offset, sizeof(offset)/sizeof(unsigned short)); - if (count <= 0) - { - HILOGI("rtk_update_altsettings: No AltSettings"); - return; - } - else - { - HILOGI("rtk_update_altsettings: %d AltSettings", count); - } - - if (data_len != config_len - sizeof(struct rtk_bt_vendor_config)) - { - HILOGE("rtk_update_altsettings: config len(%x) is not right(%lx)", data_len, (unsigned long)(config_len - sizeof(struct rtk_bt_vendor_config))); - return; - } - - for (i = 0; i < data_len;) - { - for (j = 0; j < count; j++) - { - if (le16_to_cpu(entry->offset) == offset[j]) - { - if (offset[j] == patch_entry->mac_offset) - offset[j] = 0; - else - { - struct rtk_bt_vendor_config_entry *t = extra_extry; - while (t->offset) - { - if (t->offset == le16_to_cpu(entry->offset)) - { - if (t->entry_len == entry->entry_len) - offset[j] = 0; - break; - } - t = (struct rtk_bt_vendor_config_entry *)((uint8_t *)t + t->entry_len + sizeof(struct rtk_bt_vendor_config_entry)); - } - } - } - } - if (getUsbAltSettingVal(patch_entry, le16_to_cpu(entry->offset), val) == entry->entry_len) - { - HILOGI("rtk_update_altsettings: replace %04x[%02x]", le16_to_cpu(entry->offset), entry->entry_len); - memcpy(entry->entry_data, val, entry->entry_len); - } - temp = entry->entry_len + sizeof(struct rtk_bt_vendor_config_entry); - i += temp; - entry = (struct rtk_bt_vendor_config_entry *)((uint8_t *)entry + temp); - } - - for (j = 0; j < count; j++) - { - if (offset[j] == 0) - continue; - entry->entry_len = getUsbAltSettingVal(patch_entry, offset[j], val); - if (entry->entry_len <= 0) - continue; - entry->offset = cpu_to_le16(offset[j]); - memcpy(entry->entry_data, val, entry->entry_len); - HILOGI("rtk_update_altsettings: add %04x[%02x]", le16_to_cpu(entry->offset), entry->entry_len); - temp = entry->entry_len + sizeof(struct rtk_bt_vendor_config_entry); - i += temp; - entry = (struct rtk_bt_vendor_config_entry *)((uint8_t *)entry + temp); - } - config->data_len = cpu_to_le16(i); - *config_len_ptr = i + sizeof(struct rtk_bt_vendor_config); - - if (extra_extry) - { - free(extra_extry); - extra_extry = NULL; - extra_entry_inx = NULL; - } - - HILOGI("NEW Config len=%08zx:\n", *config_len_ptr); - for (i = 0; i <= (*config_len_ptr); i += 0x10) - { - HILOGI("%08x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", i, - config_buf_ptr[i], config_buf_ptr[i + 1], config_buf_ptr[i + 2], config_buf_ptr[i + 3], config_buf_ptr[i + 4], config_buf_ptr[i + 5], config_buf_ptr[i + 6], config_buf_ptr[i + 7], - config_buf_ptr[i + 8], config_buf_ptr[i + 9], config_buf_ptr[i + 10], config_buf_ptr[i + 11], config_buf_ptr[i + 12], config_buf_ptr[i + 13], config_buf_ptr[i + 14], config_buf_ptr[i + 15]); - } - return; -} - -static void rtk_usb_parse_config_file(unsigned char **config_buf, size_t *filelen, uint8_t bt_addr[6], uint16_t mac_offset) -{ - struct rtk_bt_vendor_config *config = (struct rtk_bt_vendor_config *)*config_buf; - uint16_t config_len = le16_to_cpu(config->data_len), temp = 0; - struct rtk_bt_vendor_config_entry *entry = config->entry; - unsigned int i = 0; - uint8_t heartbeat_buf = 0; - // uint32_t config_has_bdaddr = 0; - uint8_t *p; - - HILOGD("bt_addr = %x", bt_addr[0]); - if (le32_to_cpu(config->signature) != RTK_VENDOR_CONFIG_MAGIC) - { - HILOGE("config signature magic number(0x%x) is not set to RTK_VENDOR_CONFIG_MAGIC", config->signature); - return; - } - - if (config_len != *filelen - sizeof(struct rtk_bt_vendor_config)) - { - HILOGE("config len(0x%x) is not right(0x%zx)", config_len, *filelen - sizeof(struct rtk_bt_vendor_config)); - return; - } - - hw_cfg_cb.heartbeat = 0; - for (i = 0; i < config_len;) - { - switch (le16_to_cpu(entry->offset)) - { - case 0x017a: - { - if (mac_offset == CONFIG_MAC_OFFSET_GEN_1_2) - { - p = (uint8_t *)entry->entry_data; - STREAM_TO_UINT8(heartbeat_buf, p); - if ((heartbeat_buf & 0x02) && (heartbeat_buf & 0x10)) - hw_cfg_cb.heartbeat = 1; - else - hw_cfg_cb.heartbeat = 0; - - HILOGI("config 0x017a heartbeat = %d", hw_cfg_cb.heartbeat); - } - break; - } - case 0x01be: - { - if (mac_offset == CONFIG_MAC_OFFSET_GEN_3PLUS || mac_offset == CONFIG_MAC_OFFSET_GEN_4PLUS) - { - p = (uint8_t *)entry->entry_data; - STREAM_TO_UINT8(heartbeat_buf, p); - if ((heartbeat_buf & 0x02) && (heartbeat_buf & 0x10)) - hw_cfg_cb.heartbeat = 1; - else - hw_cfg_cb.heartbeat = 0; - - HILOGI("config 0x01be heartbeat = %d", hw_cfg_cb.heartbeat); - } - break; - } - default: - HILOGI("config offset(0x%x),length(0x%x)", entry->offset, entry->entry_len); - break; - } - temp = entry->entry_len + sizeof(struct rtk_bt_vendor_config_entry); - i += temp; - entry = (struct rtk_bt_vendor_config_entry *)((uint8_t *)entry + temp); - } - - return; -} - -static uint32_t rtk_usb_get_bt_config(unsigned char **config_buf, - char *config_file_short_name, uint16_t mac_offset) -{ - char bt_config_file_name[PATH_MAX] = {0}; - struct stat st; - size_t filelen; - int fd; - // FILE* file = NULL; - - sprintf(bt_config_file_name, BT_CONFIG_DIRECTORY, config_file_short_name); - HILOGI("BT config file: %s", bt_config_file_name); - - if (stat(bt_config_file_name, &st) < 0) - { - HILOGE("can't access bt config file:%s, errno:%d\n", bt_config_file_name, errno); - return 0; - } - - filelen = st.st_size; - if (filelen > MAX_ORG_CONFIG_SIZE) - { - HILOGE("bt config file is too large(>0x%04x)", MAX_ORG_CONFIG_SIZE); - return 0; - } - - if ((fd = open(bt_config_file_name, O_RDONLY)) < 0) - { - HILOGE("Can't open bt config file"); - return 0; - } - - if ((*config_buf = malloc(MAX_ORG_CONFIG_SIZE + MAX_ALT_CONFIG_SIZE)) == NULL) - { - HILOGE("malloc buffer for config file fail(0x%zx)\n", filelen); - close(fd); - return 0; - } - - if (read(fd, *config_buf, filelen) < (ssize_t)filelen) - { - HILOGE("Can't load bt config file"); - free(*config_buf); - close(fd); - return 0; - } - - rtk_usb_parse_config_file(config_buf, &filelen, vnd_local_bd_addr, mac_offset); - - close(fd); - return filelen; -} - -static usb_patch_info *rtk_usb_get_fw_table_entry(uint16_t vid, uint16_t pid) -{ - usb_patch_info *patch_entry = usb_fw_patch_table; - - uint32_t entry_size = sizeof(usb_fw_patch_table) / sizeof(usb_fw_patch_table[0]); - uint32_t i; - - for (i = 0; i < entry_size; i++, patch_entry++) - { - if ((vid == patch_entry->vid) && (pid == patch_entry->pid)) - break; - } - - if (i == entry_size) - { - HILOGE("%s: No fw table entry found", __func__); - return NULL; - } - - return patch_entry; -} - -static void rtk_usb_get_bt_final_patch(bt_hw_cfg_cb_t *cfg_cb) -{ - uint8_t proj_id = 0; - struct rtk_epatch_entry *entry = NULL; - struct rtk_epatch *patch = (struct rtk_epatch *)cfg_cb->fw_buf; - // int iBtCalLen = 0; - - if (cfg_cb->lmp_subversion == LMPSUBVERSION_8723a) - { - if (memcmp(cfg_cb->fw_buf, RTK_EPATCH_SIGNATURE, 8) == 0) - { - HILOGE("8723as check signature error!"); - cfg_cb->dl_fw_flag = 0; - goto free_buf; - } - else - { - cfg_cb->total_len = cfg_cb->fw_len + cfg_cb->config_len; - if (!(cfg_cb->total_buf = malloc(cfg_cb->total_len))) - { - HILOGE("can't alloc memory for fw&config, errno:%d", errno); - cfg_cb->dl_fw_flag = 0; - goto free_buf; - } - else - { - HILOGI("8723as, fw copy direct"); - memcpy(cfg_cb->total_buf, cfg_cb->fw_buf, cfg_cb->fw_len); - memcpy(cfg_cb->total_buf + cfg_cb->fw_len, cfg_cb->config_buf, cfg_cb->config_len); - // cfg_cb->lmp_sub_current = *(uint16_t *)(cfg_cb->total_buf + cfg_cb->total_len - cfg_cb->config_len - 4); - cfg_cb->dl_fw_flag = 1; - goto free_buf; - } - } - } - - if (memcmp(cfg_cb->fw_buf, RTK_EPATCH_SIGNATURE, 8)) - { - HILOGE("check signature error"); - cfg_cb->dl_fw_flag = 0; - goto free_buf; - } - - /* check the extension section signature */ - if (memcmp(cfg_cb->fw_buf + cfg_cb->fw_len - 4, EXTENSION_SECTION_SIGNATURE, 4)) - { - HILOGE("check extension section signature error"); - cfg_cb->dl_fw_flag = 0; - goto free_buf; - } - - proj_id = rtk_get_fw_project_id(cfg_cb->fw_buf + cfg_cb->fw_len - 5); - if (usb_project_id[proj_id] != hw_cfg_cb.lmp_subversion_default) - { - HILOGE("usb_project_id is 0x%08x, fw project_id is %d, does not match!!!", - usb_project_id[proj_id], hw_cfg_cb.lmp_subversion); - cfg_cb->dl_fw_flag = 0; - goto free_buf; - } - - entry = rtk_get_patch_entry(cfg_cb); - if (entry) - { - cfg_cb->total_len = entry->patch_length + cfg_cb->config_len; - } - else - { - cfg_cb->dl_fw_flag = 0; - goto free_buf; - } - - HILOGI("total_len = 0x%x", cfg_cb->total_len); - - if (!(cfg_cb->total_buf = malloc(cfg_cb->total_len))) - { - HILOGE("Can't alloc memory for multi fw&config, errno:%d", errno); - cfg_cb->dl_fw_flag = 0; - goto free_buf; - } - else - { - memcpy(cfg_cb->total_buf, cfg_cb->fw_buf + entry->patch_offset, entry->patch_length); - memcpy(cfg_cb->total_buf + entry->patch_length - 4, &patch->fw_version, 4); - memcpy(&entry->svn_version, cfg_cb->total_buf + entry->patch_length - 8, 4); - memcpy(&entry->coex_version, cfg_cb->total_buf + entry->patch_length - 12, 4); - - HILOGI("BTCOEX:20%06d-%04x svn_version:%d lmp_subversion:0x%x hci_version:0x%x hci_revision:0x%x chip_type:%d Cut:%d libbt-vendor_uart version:%s, patch->fw_version = %x\n", - ((entry->coex_version >> 16) & 0x7ff) + ((entry->coex_version >> 27) * 10000), - (entry->coex_version & 0xffff), entry->svn_version, cfg_cb->lmp_subversion, cfg_cb->hci_version, cfg_cb->hci_revision, cfg_cb->chip_type, cfg_cb->eversion + 1, RTK_VERSION, patch->fw_version); - } - - if (cfg_cb->config_len) - { - memcpy(cfg_cb->total_buf + entry->patch_length, cfg_cb->config_buf, cfg_cb->config_len); - } - - cfg_cb->dl_fw_flag = 1; - HILOGI("Fw:%s exists, config file:%s exists", (cfg_cb->fw_len > 0) ? "" : "not", (cfg_cb->config_len > 0) ? "" : "not"); - -free_buf: - if (cfg_cb->fw_len > 0) - { - free(cfg_cb->fw_buf); - cfg_cb->fw_len = 0; - } - - if (cfg_cb->config_len > 0) - { - free(cfg_cb->config_buf); - cfg_cb->config_len = 0; - } - - if (entry) - { - free(entry); - } -} - -static int usb_hci_download_patch_h4(HC_BT_HDR *p_buf, int index, uint8_t *data, int len) -{ - int retval = FALSE; - uint8_t *p = (uint8_t *)(p_buf + 1); - - UINT16_TO_STREAM(p, HCI_VSC_DOWNLOAD_FW_PATCH); - *p++ = 1 + len; /* parameter length */ - *p++ = index; - memcpy(p, data, len); - p_buf->len = HCI_CMD_PREAMBLE_SIZE + 1 + len; - - hw_cfg_cb.state = HW_CFG_DL_FW_PATCH; - - retval = bt_vendor_cbacks->xmit_cb(HCI_VSC_DOWNLOAD_FW_PATCH, p_buf); - return retval; -} - -static void rtk_usb_get_fw_version(bt_hw_cfg_cb_t *cfg_cb) -{ - struct rtk_epatch *patch = (struct rtk_epatch *)cfg_cb->fw_buf; - - if (cfg_cb->lmp_subversion == LMPSUBVERSION_8723a) - { - cfg_cb->lmp_sub_current = 0; - } - else - { - cfg_cb->lmp_sub_current = (uint16_t)patch->fw_version; - } -} -/******************************************************************************* -** -** Function hw_usb_config_cback -** -** Description Callback function for controller configuration -** -** Returns None -** -*******************************************************************************/ -void hw_usb_config_cback(void *p_mem) -{ - HC_BT_HDR *p_evt_buf = NULL; - uint8_t *p = NULL; //, *pp=NULL; - uint8_t status = 0; - uint16_t opcode = 0; - HC_BT_HDR *p_buf = NULL; - int is_proceeding = FALSE; - // int i = 0; - uint8_t iIndexRx = 0; - // patch_info* prtk_patch_file_info = NULL; - usb_patch_info *prtk_usb_patch_file_info = NULL; - // uint32_t host_baudrate = 0; - -#if (USE_CONTROLLER_BDADDR == TRUE) - // const uint8_t null_bdaddr[BD_ADDR_LEN] = {0,0,0,0,0,0}; -#endif - - if (p_mem != NULL) - { - p_evt_buf = (HC_BT_HDR *)p_mem; - status = *((uint8_t *)(p_evt_buf + 1) + HCI_EVT_CMD_CMPL_STATUS_OFFSET); - p = (uint8_t *)(p_evt_buf + 1) + HCI_EVT_CMD_CMPL_OPCODE_OFFSET; - STREAM_TO_UINT16(opcode, p); - } - - /* Ask a new buffer big enough to hold any HCI commands sent in here */ - /*a cut fc6d status==1*/ - if (((status == 0) || (opcode == HCI_VSC_READ_ROM_VERSION)) && bt_vendor_cbacks) - p_buf = (HC_BT_HDR *)bt_vendor_cbacks->alloc(BT_HC_HDR_SIZE + HCI_CMD_MAX_LEN); - - if (p_buf != NULL) - { - p_buf->event = MSG_STACK_TO_HC_HCI_CMD; - p_buf->offset = 0; - p_buf->len = 0; - p_buf->layer_specific = 0; - - BTVNDDBG("hw_cfg_cb.state = %i", hw_cfg_cb.state); - switch (hw_cfg_cb.state) - { - case HW_CFG_RESET_CHANNEL_CONTROLLER: - { - usleep(300000); - hw_cfg_cb.state = HW_CFG_READ_LOCAL_VER; - p = (uint8_t *)(p_buf + 1); - UINT16_TO_STREAM(p, HCI_READ_LMP_VERSION); - *p++ = 0; - p_buf->len = HCI_CMD_PREAMBLE_SIZE; - is_proceeding = bt_vendor_cbacks->xmit_cb(HCI_READ_LMP_VERSION, p_buf); - break; - } - case HW_CFG_READ_LOCAL_VER: - { - if (status == 0 && p_evt_buf) - { - p = ((uint8_t *)(p_evt_buf + 1) + HCI_EVT_CMD_CMPL_OP1001_HCI_VERSION_OFFSET); - STREAM_TO_UINT16(hw_cfg_cb.hci_version, p); - p = ((uint8_t *)(p_evt_buf + 1) + HCI_EVT_CMD_CMPL_OP1001_HCI_REVISION_OFFSET); - STREAM_TO_UINT16(hw_cfg_cb.hci_revision, p); - p = (uint8_t *)(p_evt_buf + 1) + HCI_EVT_CMD_CMPL_OP1001_LMP_SUBVERSION_OFFSET; - STREAM_TO_UINT16(hw_cfg_cb.lmp_subversion, p); - - prtk_usb_patch_file_info = rtk_usb_get_fw_table_entry(hw_cfg_cb.vid, hw_cfg_cb.pid); - if ((prtk_usb_patch_file_info == NULL) || (prtk_usb_patch_file_info->lmp_sub_default == 0)) - { - HILOGE("get patch entry error"); - is_proceeding = FALSE; - break; - } - hw_cfg_cb.config_len = rtk_usb_get_bt_config(&hw_cfg_cb.config_buf, prtk_usb_patch_file_info->config_name, prtk_usb_patch_file_info->mac_offset); - hw_cfg_cb.fw_len = rtk_get_bt_firmware(&hw_cfg_cb.fw_buf, prtk_usb_patch_file_info->patch_name); - rtk_usb_get_fw_version(&hw_cfg_cb); - - hw_cfg_cb.lmp_subversion_default = prtk_usb_patch_file_info->lmp_sub_default; - BTVNDDBG("lmp_subversion = 0x%x hw_cfg_cb.hci_version = 0x%x hw_cfg_cb.hci_revision = 0x%x, hw_cfg_cb.lmp_sub_current = 0x%x", - hw_cfg_cb.lmp_subversion, hw_cfg_cb.hci_version, hw_cfg_cb.hci_revision, hw_cfg_cb.lmp_sub_current); - - if (prtk_usb_patch_file_info->lmp_sub_default == hw_cfg_cb.lmp_subversion) - { - BTVNDDBG("%s: Cold BT controller startup", __func__); - // hw_cfg_cb.state = HW_CFG_START; - // goto CFG_USB_START; - hw_cfg_cb.state = HW_CFG_READ_ECO_VER; - p = (uint8_t *)(p_buf + 1); - UINT16_TO_STREAM(p, HCI_VSC_READ_ROM_VERSION); - *p++ = 0; - p_buf->len = HCI_CMD_PREAMBLE_SIZE; - is_proceeding = bt_vendor_cbacks->xmit_cb(HCI_VSC_READ_ROM_VERSION, p_buf); - } - else if (hw_cfg_cb.lmp_subversion != hw_cfg_cb.lmp_sub_current) - { - BTVNDDBG("%s: Warm BT controller startup with updated lmp", __func__); - goto RESET_HW_CONTROLLER; - } - else - { - BTVNDDBG("%s: Warm BT controller startup with same lmp", __func__); - userial_vendor_usb_ioctl(DWFW_CMPLT, &hw_cfg_cb.lmp_sub_current); - free(hw_cfg_cb.total_buf); - hw_cfg_cb.total_len = 0; - - bt_vendor_cbacks->dealloc(p_buf); - start_fwcfg_cbtimer(); - hw_cfg_cb.state = 0; - is_proceeding = TRUE; - } - - /* if(hw_cfg_cb.lmp_subversion == LMPSUBVERSION_8723a) - { - hw_cfg_cb.state = HW_CFG_START; - goto CFG_USB_START; - } - else - { - hw_cfg_cb.state = HW_CFG_READ_ECO_VER; - p = (uint8_t *) (p_buf + 1); - UINT16_TO_STREAM(p, HCI_VSC_READ_ROM_VERSION); - *p++ = 0; - p_buf->len = HCI_CMD_PREAMBLE_SIZE; - is_proceeding = bt_vendor_cbacks->xmit_cb(HCI_VSC_READ_ROM_VERSION, p_buf); - }*/ - } - else - { - HILOGE("status = %d, or p_evt_buf is NULL", status); - } - break; - } -RESET_HW_CONTROLLER: - case HW_RESET_CONTROLLER: - { - if (status == 0) - { - // usleep(300000);//300ms - userial_vendor_usb_ioctl(RESET_CONTROLLER, NULL); // reset controller - hw_cfg_cb.state = HW_CFG_READ_ECO_VER; - p = (uint8_t *)(p_buf + 1); - UINT16_TO_STREAM(p, HCI_VSC_READ_ROM_VERSION); - *p++ = 0; - p_buf->len = HCI_CMD_PREAMBLE_SIZE; - is_proceeding = bt_vendor_cbacks->xmit_cb(HCI_VSC_READ_ROM_VERSION, p_buf); - } - break; - } - case HW_CFG_READ_ECO_VER: - { - if (status == 0 && p_evt_buf) - { - hw_cfg_cb.eversion = *((uint8_t *)(p_evt_buf + 1) + HCI_EVT_CMD_CMPL_OPFC6D_EVERSION_OFFSET); - BTVNDDBG("hw_usb_config_cback chip_id of the IC:%d", hw_cfg_cb.eversion + 1); - } - else if (1 == status) - { - hw_cfg_cb.eversion = 0; - } - else - { - is_proceeding = FALSE; - break; - } - - hw_cfg_cb.state = HW_CFG_START; - goto CFG_USB_START; - } -CFG_USB_START: - case HW_CFG_START: - { - // get efuse config file and patch code file - prtk_usb_patch_file_info = rtk_usb_get_fw_table_entry(hw_cfg_cb.vid, hw_cfg_cb.pid); - - if ((prtk_usb_patch_file_info == NULL) || (prtk_usb_patch_file_info->lmp_sub_default == 0)) - { - HILOGE("get patch entry error"); - is_proceeding = FALSE; - break; - } - hw_cfg_cb.max_patch_size = prtk_usb_patch_file_info->max_patch_size; - hw_cfg_cb.config_len = rtk_usb_get_bt_config(&hw_cfg_cb.config_buf, prtk_usb_patch_file_info->config_name, prtk_usb_patch_file_info->mac_offset); - if (hw_cfg_cb.config_len) - { - HILOGE("update altsettings"); - rtk_usb_update_altsettings(prtk_usb_patch_file_info, hw_cfg_cb.config_buf, &(hw_cfg_cb.config_len)); - } - - hw_cfg_cb.fw_len = rtk_get_bt_firmware(&hw_cfg_cb.fw_buf, prtk_usb_patch_file_info->patch_name); - if (hw_cfg_cb.fw_len < 0) - { - HILOGE("Get BT firmware fail"); - hw_cfg_cb.fw_len = 0; - is_proceeding = FALSE; - break; - } - else - { - // hw_cfg_cb.project_id_mask = prtk_usb_patch_file_info->project_id_mask; - rtk_usb_get_bt_final_patch(&hw_cfg_cb); - } - - BTVNDDBG("Check total_len(0x%08x) max_patch_size(0x%08x)", hw_cfg_cb.total_len, hw_cfg_cb.max_patch_size); - if (hw_cfg_cb.total_len > hw_cfg_cb.max_patch_size) - { - HILOGE("total length of fw&config(0x%08x) larger than max_patch_size(0x%08x)", hw_cfg_cb.total_len, hw_cfg_cb.max_patch_size); - is_proceeding = FALSE; - break; - } - - if ((hw_cfg_cb.total_len > 0) && hw_cfg_cb.dl_fw_flag) - { - hw_cfg_cb.patch_frag_cnt = hw_cfg_cb.total_len / PATCH_DATA_FIELD_MAX_SIZE; - hw_cfg_cb.patch_frag_tail = hw_cfg_cb.total_len % PATCH_DATA_FIELD_MAX_SIZE; - if (hw_cfg_cb.patch_frag_tail) - hw_cfg_cb.patch_frag_cnt += 1; - else - hw_cfg_cb.patch_frag_tail = PATCH_DATA_FIELD_MAX_SIZE; - BTVNDDBG("patch fragment count %d, tail len %d", hw_cfg_cb.patch_frag_cnt, hw_cfg_cb.patch_frag_tail); - } - else - { - is_proceeding = FALSE; - break; - } - - goto DOWNLOAD_USB_FW; - } - /* fall through intentionally */ - -DOWNLOAD_USB_FW: - case HW_CFG_DL_FW_PATCH: - BTVNDDBG("bt vendor lib: HW_CFG_DL_FW_PATCH status:%i, opcode:0x%x", status, opcode); - - // recv command complete event for patch code download command - if (opcode == HCI_VSC_DOWNLOAD_FW_PATCH) - { - iIndexRx = *((uint8_t *)(p_evt_buf + 1) + HCI_EVT_CMD_CMPL_STATUS_OFFSET + 1); - BTVNDDBG("bt vendor lib: HW_CFG_DL_FW_PATCH status:%i, iIndexRx:%i", status, iIndexRx); - hw_cfg_cb.patch_frag_idx++; - - if (iIndexRx & 0x80) - { - BTVNDDBG("vendor lib fwcfg completed"); - userial_vendor_usb_ioctl(DWFW_CMPLT, &hw_cfg_cb.lmp_sub_current); - free(hw_cfg_cb.total_buf); - hw_cfg_cb.total_len = 0; - - bt_vendor_cbacks->dealloc(p_buf); - // bt_vendor_cbacks->fwcfg_cb(BTC_OP_RESULT_SUCCESS); - start_fwcfg_cbtimer(); - - hw_cfg_cb.state = 0; - is_proceeding = TRUE; - break; - } - } - - if (hw_cfg_cb.patch_frag_idx < hw_cfg_cb.patch_frag_cnt) - { - iIndexRx = hw_cfg_cb.patch_frag_idx ? ((hw_cfg_cb.patch_frag_idx - 1) % 0x7f + 1) : 0; - if (hw_cfg_cb.patch_frag_idx == hw_cfg_cb.patch_frag_cnt - 1) - { - BTVNDDBG("HW_CFG_DL_FW_PATCH: send last fw fragment"); - iIndexRx |= 0x80; - hw_cfg_cb.patch_frag_len = hw_cfg_cb.patch_frag_tail; - } - else - { - iIndexRx &= 0x7F; - hw_cfg_cb.patch_frag_len = PATCH_DATA_FIELD_MAX_SIZE; - } - } - - is_proceeding = usb_hci_download_patch_h4(p_buf, iIndexRx, - hw_cfg_cb.total_buf + (hw_cfg_cb.patch_frag_idx * PATCH_DATA_FIELD_MAX_SIZE), - hw_cfg_cb.patch_frag_len); - break; - default: - break; - } // switch(hw_cfg_cb.state) - } // if (p_buf != NULL) - - if (is_proceeding == FALSE) - { - HILOGE("vendor lib fwcfg aborted!!!"); - if (bt_vendor_cbacks) - { - if (p_buf != NULL) - bt_vendor_cbacks->dealloc(p_buf); - - userial_vendor_usb_ioctl(DWFW_CMPLT, &hw_cfg_cb.lmp_sub_current); - // bt_vendor_cbacks->fwcfg_cb(BTC_OP_RESULT_FAIL); - - bt_vendor_cbacks->init_cb(BTC_OP_RESULT_FAIL); - } - - if (hw_cfg_cb.config_len) - { - free(hw_cfg_cb.config_buf); - hw_cfg_cb.config_len = 0; - } - - if (hw_cfg_cb.fw_len) - { - free(hw_cfg_cb.fw_buf); - hw_cfg_cb.fw_len = 0; - } - - if (hw_cfg_cb.total_len) - { - free(hw_cfg_cb.total_buf); - hw_cfg_cb.total_len = 0; - } - hw_cfg_cb.state = 0; - } -} - -/******************************************************************************* -** -** Function hw__usb_config_start -** -** Description Kick off controller initialization process -** -** Returns None -** -*******************************************************************************/ -void hw_usb_config_start(char transtype, uint32_t usb_id) -{ - RTK_UNUSED(transtype); - memset(&hw_cfg_cb, 0, sizeof(bt_hw_cfg_cb_t)); - hw_cfg_cb.dl_fw_flag = 1; - hw_cfg_cb.chip_type = CHIPTYPE_NONE; - hw_cfg_cb.pid = usb_id & 0x0000ffff; - hw_cfg_cb.vid = (usb_id >> 16) & 0x0000ffff; - BTVNDDBG("RTKBT_RELEASE_NAME: %s", RTKBT_RELEASE_NAME); - BTVNDDBG("\nRealtek libbt-vendor_usb Version %s \n", RTK_VERSION); - HC_BT_HDR *p_buf = NULL; - uint8_t *p; - - BTVNDDBG("hw_usb_config_start, transtype = 0x%x, pid = 0x%04x, vid = 0x%04x \n", transtype, hw_cfg_cb.pid, hw_cfg_cb.vid); - - if (bt_vendor_cbacks) - { - /* Must allocate command buffer via HC's alloc API */ - p_buf = (HC_BT_HDR *)bt_vendor_cbacks->alloc(BT_HC_HDR_SIZE + - HCI_CMD_PREAMBLE_SIZE); - if (p_buf) - { - p_buf->event = MSG_STACK_TO_HC_HCI_CMD; - p_buf->offset = 0; - p_buf->layer_specific = 0; - p_buf->len = HCI_CMD_PREAMBLE_SIZE; - - p = (uint8_t *)(p_buf + 1); - - p = (uint8_t *)(p_buf + 1); - UINT16_TO_STREAM(p, HCI_VENDOR_RESET); - *p++ = 0; - p_buf->len = HCI_CMD_PREAMBLE_SIZE; - - hw_cfg_cb.state = HW_CFG_RESET_CHANNEL_CONTROLLER; - bt_vendor_cbacks->xmit_cb(HCI_VENDOR_RESET, p_buf); - } - else - { - HILOGE("%s buffer alloc fail!", __func__); - bt_vendor_cbacks->init_cb(BTC_OP_RESULT_FAIL); - } - } - else - HILOGE("%s call back is null", __func__); -} diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/hci_h5.c b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/hci_h5.c deleted file mode 100755 index 747a7943..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/hci_h5.c +++ /dev/null @@ -1,2752 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -/****************************************************************************** - * - * Module Name: - * hci_h5.c - * - * Abstract: - * Contain HCI transport send/receive functions for UART H5 Interface. - * - * Major Change History: - * When Who What - * --------------------------------------------------------------- - * 2016-09-23 cc modified - * - * Notes: - * This is designed for UART H5 HCI Interface in Android 8.0 - * - ******************************************************************************/ -#define LOG_TAG "bt_h5_int" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "hci_h5_int.h" -#include "bt_skbuff.h" -#include "bt_list.h" -#include "bt_hci_bdroid.h" -#include "userial.h" - -typedef void (*tINT_CMD_CBACK)(void *p_mem); -/****************************************************************************** -** Constants & Macros -******************************************************************************/ -#define H5_TRACE_DATA_ENABLE 0 // if you want to see data tx and rx, set H5_TRACE_DATA_ENABLE 1 -#define H5_LOG_VERBOSE 0 - -unsigned int h5_log_enable = 1; - -#ifndef H5_LOG_BUF_SIZE -#define H5_LOG_BUF_SIZE 1024 -#endif -#define H5_LOG_MAX_SIZE (H5_LOG_BUF_SIZE - 12) - -#ifndef H5_LOG_BUF_SIZE -#define H5_LOG_BUF_SIZE 1024 -#endif -#define H5_LOG_MAX_SIZE (H5_LOG_BUF_SIZE - 12) - -#define DATA_RETRANS_COUNT 40 // 40*100 = 4000ms(4s) -#define BT_INIT_DATA_RETRANS_COUNT 200 // 200*20 = 4000ms(4s) -#define SYNC_RETRANS_COUNT 350 // 350*10 = 3500ms(3.5s) -#define CONF_RETRANS_COUNT 350 - -#define DATA_RETRANS_TIMEOUT_VALUE 100 // ms -#define BT_INIT_DATA_RETRANS_TIMEOUT_VALUE 20 // ms -#define SYNC_RETRANS_TIMEOUT_VALUE 10 -#define CONF_RETRANS_TIMEOUT_VALUE 20 -#define WAIT_CT_BAUDRATE_READY_TIMEOUT_VALUE 5 -#define H5_HW_INIT_READY_TIMEOUT_VALUE 4000 // 4 - -/* Maximum numbers of allowed internal -** outstanding command packets at any time -*/ -#define INT_CMD_PKT_MAX_COUNT 8 -#define INT_CMD_PKT_IDX_MASK 0x07 - -// HCI Event codes -#define HCI_CONNECTION_COMP_EVT 0x03 -#define HCI_DISCONNECTION_COMP_EVT 0x05 -#define HCI_COMMAND_COMPLETE_EVT 0x0E -#define HCI_COMMAND_STATUS_EVT 0x0F -#define HCI_NUM_OF_CMP_PKTS_EVT 0x13 -#define HCI_BLE_EVT 0x3E - -#define PATCH_DATA_FIELD_MAX_SIZE 252 -#define READ_DATA_SIZE 16 - -// HCI data types // -#define H5_RELIABLE_PKT 0x01 -#define H5_UNRELIABLE_PKT 0x00 - -#define H5_ACK_PKT 0x00 -#define HCI_COMMAND_PKT 0x01 -#define HCI_ACLDATA_PKT 0x02 -#define HCI_SCODATA_PKT 0x03 -#define HCI_EVENT_PKT 0x04 -#define H5_VDRSPEC_PKT 0x0E -#define H5_LINK_CTL_PKT 0x0F - -#define H5_HDR_SEQ(hdr) ((hdr)[0] & 0x07) -#define H5_HDR_ACK(hdr) (((hdr)[0] >> 3) & 0x07) -#define H5_HDR_CRC(hdr) (((hdr)[0] >> 6) & 0x01) -#define H5_HDR_RELIABLE(hdr) (((hdr)[0] >> 7) & 0x01) -#define H5_HDR_PKT_TYPE(hdr) ((hdr)[1] & 0x0f) -#define H5_HDR_LEN(hdr) ((((hdr)[1] >> 4) & 0xff) + ((hdr)[2] << 4)) -#define H5_HDR_SIZE 4 - -#define H5_CFG_SLID_WIN(cfg) ((cfg)&0x07) -#define H5_CFG_OOF_CNTRL(cfg) (((cfg) >> 3) & 0x01) -#define H5_CFG_DIC_TYPE(cfg) (((cfg) >> 4) & 0x01) -#define H5_CFG_VER_NUM(cfg) (((cfg) >> 5) & 0x07) -#define H5_CFG_SIZE 1 - -/****************************************************************************** -** Local type definitions -******************************************************************************/ -/* Callback function for the returned event of internal issued command */ -typedef void (*tTIMER_HANDLE_CBACK)(union sigval sigval_value); - -typedef struct -{ - uint16_t opcode; /* OPCODE of outstanding internal commands */ - tINT_CMD_CBACK cback; /* Callback function when return of internal - * command is received */ -} tINT_CMD_Q; - -typedef RTK_BUFFER sk_buff; - -typedef enum H5_RX_STATE -{ - H5_W4_PKT_DELIMITER, - H5_W4_PKT_START, - H5_W4_HDR, - H5_W4_DATA, - H5_W4_CRC -} tH5_RX_STATE; - -typedef enum H5_RX_ESC_STATE -{ - H5_ESCSTATE_NOESC, - H5_ESCSTATE_ESC -} tH5_RX_ESC_STATE; - -typedef enum H5_LINK_STATE -{ - H5_UNINITIALIZED, - H5_INITIALIZED, - H5_ACTIVE -} tH5_LINK_STATE; - -#define H5_EVENT_RX 0x0001 -#define H5_EVENT_EXIT 0x0200 - -static volatile uint8_t h5_retransfer_running = 0; -static volatile uint16_t h5_ready_events = 0; -static volatile uint8_t h5_data_ready_running = 0; -volatile int h5_init_datatrans_flag; - -/* Control block for HCISU_H5 */ -typedef struct HCI_H5_CB -{ - HC_BT_HDR *p_rcv_msg; /* Buffer to hold current rx HCI message */ - uint32_t int_cmd_rsp_pending; /* Num of internal cmds pending for ack */ - uint8_t int_cmd_rd_idx; /* Read index of int_cmd_opcode queue */ - uint8_t int_cmd_wrt_idx; /* Write index of int_cmd_opcode queue */ - tINT_CMD_Q int_cmd[INT_CMD_PKT_MAX_COUNT]; /* FIFO queue */ - - tINT_CMD_CBACK cback_h5sync; /* Callback function when h5 sync*/ - - uint8_t sliding_window_size; - uint8_t oof_flow_control; - uint8_t dic_type; - - RTB_QUEUE_HEAD *unack; // Unack'ed packets queue - RTB_QUEUE_HEAD *rel; // Reliable packets queue - - RTB_QUEUE_HEAD *unrel; // Unreliable packets queue - RTB_QUEUE_HEAD *recv_data; // Unreliable packets queue - - uint8_t rxseq_txack; // rxseq == txack. // expected rx SeqNumber - uint8_t rxack; // Last packet sent by us that the peer ack'ed // - - uint8_t use_crc; - uint8_t is_txack_req; // txack required? Do we need to send ack's to the peer? // - - // Reliable packet sequence number - used to assign seq to each rel pkt. */ - uint8_t msgq_txseq; // next pkt seq - - uint16_t message_crc; - uint32_t rx_count; // expected pkts to recv - - tH5_RX_STATE rx_state; - tH5_RX_ESC_STATE rx_esc_state; - tH5_LINK_STATE link_estab_state; - - sk_buff *rx_skb; - sk_buff *data_skb; - sk_buff *internal_skb; - - timer_t timer_data_retrans; - timer_t timer_sync_retrans; - timer_t timer_conf_retrans; - timer_t timer_wait_ct_baudrate_ready; - timer_t timer_h5_hw_init_ready; - - uint32_t data_retrans_count; - uint32_t sync_retrans_count; - uint32_t conf_retrans_count; - - pthread_mutex_t mutex; - pthread_cond_t cond; - pthread_t thread_data_retrans; - - pthread_mutex_t data_mutex; - pthread_cond_t data_cond; - pthread_t thread_data_ready_cb; - - uint8_t cleanuping; -} tHCI_H5_CB; - -static tHCI_H5_CB rtk_h5; -static pthread_mutex_t h5_wakeup_mutex = PTHREAD_MUTEX_INITIALIZER; - -/****************************************************************************** -** Variables -******************************************************************************/ - -/* Num of allowed outstanding HCI CMD packets */ -volatile int num_hci_cmd_pkts = 1; -extern unsigned int rtkbt_h5logfilter; -extern void userial_recv_rawdata_hook(unsigned char *buffer, unsigned int total_length); - -/****************************************************************************** -** Static variables -******************************************************************************/ -struct patch_struct -{ - int nTxIndex; // current sending pkt number - int nTotal; // total pkt number - int nRxIndex; // ack index from board - int nNeedRetry; // if no response from board -}; - -/****************************************************************************** -** Static function -******************************************************************************/ -static timer_t OsAllocateTimer(tTIMER_HANDLE_CBACK timer_callback); -static int OsStartTimer(timer_t timerid, int msec, int mode); -static int OsStopTimer(timer_t timerid); -static uint16_t h5_wake_up(); - -static hci_h5_callbacks_t *h5_int_hal_callbacks; - -/****************************************************************************** -** Externs -******************************************************************************/ -extern void rtk_btsnoop_net_open(void); -extern void rtk_btsnoop_net_close(void); -extern void rtk_btsnoop_net_write(serial_data_type_t type, uint8_t *data, bool is_received); - -// timer API for retransfer -int h5_alloc_data_retrans_timer(); -int h5_free_data_retrans_timer(); -int h5_stop_data_retrans_timer(); -int h5_start_data_retrans_timer(); - -int h5_alloc_sync_retrans_timer(); -int h5_free_sync_retrans_timer(); -int h5_stop_sync_retrans_timer(); -int h5_start_sync_retrans_timer(); - -int h5_alloc_conf_retrans_timer(); -int h5_free_conf_retrans_timer(); -int h5_stop_conf_retrans_timer(); -int h5_start_conf_retrans_timer(); - -int h5_alloc_wait_controller_baudrate_ready_timer(); -int h5_free_wait_controller_baudrate_ready_timer(); -int h5_stop_wait_controller_baudrate_ready_timer(); -int h5_start_wait_controller_baudrate_ready_timer(); - -int h5_alloc_hw_init_ready_timer(); -int h5_free_hw_init_ready_timer(); -int h5_stop_hw_init_ready_timer(); -int h5_start_hw_init_ready_timer(); - -int h5_enqueue(IN sk_buff *skb); - -// bite reverse in bytes -// 00000001 -> 10000000 -// 00000100 -> 00100000 -const uint8_t byte_rev_table[256] = { - 0x00, - 0x80, - 0x40, - 0xc0, - 0x20, - 0xa0, - 0x60, - 0xe0, - 0x10, - 0x90, - 0x50, - 0xd0, - 0x30, - 0xb0, - 0x70, - 0xf0, - 0x08, - 0x88, - 0x48, - 0xc8, - 0x28, - 0xa8, - 0x68, - 0xe8, - 0x18, - 0x98, - 0x58, - 0xd8, - 0x38, - 0xb8, - 0x78, - 0xf8, - 0x04, - 0x84, - 0x44, - 0xc4, - 0x24, - 0xa4, - 0x64, - 0xe4, - 0x14, - 0x94, - 0x54, - 0xd4, - 0x34, - 0xb4, - 0x74, - 0xf4, - 0x0c, - 0x8c, - 0x4c, - 0xcc, - 0x2c, - 0xac, - 0x6c, - 0xec, - 0x1c, - 0x9c, - 0x5c, - 0xdc, - 0x3c, - 0xbc, - 0x7c, - 0xfc, - 0x02, - 0x82, - 0x42, - 0xc2, - 0x22, - 0xa2, - 0x62, - 0xe2, - 0x12, - 0x92, - 0x52, - 0xd2, - 0x32, - 0xb2, - 0x72, - 0xf2, - 0x0a, - 0x8a, - 0x4a, - 0xca, - 0x2a, - 0xaa, - 0x6a, - 0xea, - 0x1a, - 0x9a, - 0x5a, - 0xda, - 0x3a, - 0xba, - 0x7a, - 0xfa, - 0x06, - 0x86, - 0x46, - 0xc6, - 0x26, - 0xa6, - 0x66, - 0xe6, - 0x16, - 0x96, - 0x56, - 0xd6, - 0x36, - 0xb6, - 0x76, - 0xf6, - 0x0e, - 0x8e, - 0x4e, - 0xce, - 0x2e, - 0xae, - 0x6e, - 0xee, - 0x1e, - 0x9e, - 0x5e, - 0xde, - 0x3e, - 0xbe, - 0x7e, - 0xfe, - 0x01, - 0x81, - 0x41, - 0xc1, - 0x21, - 0xa1, - 0x61, - 0xe1, - 0x11, - 0x91, - 0x51, - 0xd1, - 0x31, - 0xb1, - 0x71, - 0xf1, - 0x09, - 0x89, - 0x49, - 0xc9, - 0x29, - 0xa9, - 0x69, - 0xe9, - 0x19, - 0x99, - 0x59, - 0xd9, - 0x39, - 0xb9, - 0x79, - 0xf9, - 0x05, - 0x85, - 0x45, - 0xc5, - 0x25, - 0xa5, - 0x65, - 0xe5, - 0x15, - 0x95, - 0x55, - 0xd5, - 0x35, - 0xb5, - 0x75, - 0xf5, - 0x0d, - 0x8d, - 0x4d, - 0xcd, - 0x2d, - 0xad, - 0x6d, - 0xed, - 0x1d, - 0x9d, - 0x5d, - 0xdd, - 0x3d, - 0xbd, - 0x7d, - 0xfd, - 0x03, - 0x83, - 0x43, - 0xc3, - 0x23, - 0xa3, - 0x63, - 0xe3, - 0x13, - 0x93, - 0x53, - 0xd3, - 0x33, - 0xb3, - 0x73, - 0xf3, - 0x0b, - 0x8b, - 0x4b, - 0xcb, - 0x2b, - 0xab, - 0x6b, - 0xeb, - 0x1b, - 0x9b, - 0x5b, - 0xdb, - 0x3b, - 0xbb, - 0x7b, - 0xfb, - 0x07, - 0x87, - 0x47, - 0xc7, - 0x27, - 0xa7, - 0x67, - 0xe7, - 0x17, - 0x97, - 0x57, - 0xd7, - 0x37, - 0xb7, - 0x77, - 0xf7, - 0x0f, - 0x8f, - 0x4f, - 0xcf, - 0x2f, - 0xaf, - 0x6f, - 0xef, - 0x1f, - 0x9f, - 0x5f, - 0xdf, - 0x3f, - 0xbf, - 0x7f, - 0xff, -}; -#ifndef H5_LOG_BUF_SIZE -#define H5_LOG_BUF_SIZE 1024 -#endif -#define H5_LOG_MAX_SIZE (H5_LOG_BUF_SIZE - 12) - -#define LOGI0(t, s) - -static void H5LogMsg(const char *fmt_str, ...) -{ - static char buffer[H5_LOG_BUF_SIZE]; - if (h5_log_enable == 1) - { - va_list ap; - va_start(ap, fmt_str); - vsnprintf(&buffer[0], H5_LOG_MAX_SIZE, fmt_str, ap); - va_end(ap); - - LOGI0("H5: ", buffer); - } - else - { - return; - } -} - -static void rtkbt_h5_send_hw_error() -{ - unsigned char p_buf[100]; - const char *str = "host stack: h5 send error"; - int length = strlen(str) + 1 + 4; - p_buf[0] = HCIT_TYPE_EVENT; // event - p_buf[1] = HCI_VSE_SUBCODE_DEBUG_INFO_SUB_EVT; // firmwre event log - p_buf[2] = strlen(str) + 2; // len - p_buf[3] = 0x01; // host log opcode - strcpy((char *)&p_buf[4], str); - userial_recv_rawdata_hook(p_buf, length); - - length = 4; - p_buf[0] = HCIT_TYPE_EVENT; // event - p_buf[1] = HCI_HARDWARE_ERROR_EVT; // hardware error - p_buf[2] = 0x01; // len - p_buf[3] = 0xfb; // h5 error code - userial_recv_rawdata_hook(p_buf, length); -} - -// reverse bit -static __inline uint8_t bit_rev8(uint8_t byte) -{ - return byte_rev_table[byte]; -} - -// reverse bit -static __inline uint16_t bit_rev16(uint16_t x) -{ - return (bit_rev8(x & 0xff) << 8) | bit_rev8(x >> 8); -} - -static const uint16_t crc_table[] = - { - 0x0000, 0x1081, 0x2102, 0x3183, - 0x4204, 0x5285, 0x6306, 0x7387, - 0x8408, 0x9489, 0xa50a, 0xb58b, - 0xc60c, 0xd68d, 0xe70e, 0xf78f}; - -// Initialise the crc calculator -#define H5_CRC_INIT(x) x = 0xffff - -/******************************************************************************* -** -** Function ms_delay -** -** Description sleep unconditionally for timeout milliseconds -** -** Returns None -** -*******************************************************************************/ -void ms_delay(uint32_t timeout) -{ - struct timespec delay; - int err; - - if (timeout == 0) - return; - - delay.tv_sec = timeout / 1000; - delay.tv_nsec = 1000 * 1000 * (timeout % 1000); - - /* [u]sleep can't be used because it uses SIGALRM */ - do - { - err = nanosleep(&delay, &delay); - } while (err < 0 && errno == EINTR); -} -/*********************************************** -// -//skb related functions -// -// -// -***********************************************/ -uint8_t *skb_get_data(IN sk_buff *skb) -{ - return skb->Data; -} - -uint32_t skb_get_data_length(IN sk_buff *skb) -{ - return skb->Length; -} - -sk_buff *skb_alloc(IN unsigned int len) -{ - sk_buff *skb = (sk_buff *)RtbAllocate(len, 0); - return skb; -} - -void skb_free(IN OUT sk_buff **skb) -{ - RtbFree(*skb); - *skb = NULL; - return; -} - -static void skb_unlink(sk_buff *skb, struct _RTB_QUEUE_HEAD *list) -{ - RtbRemoveNode(list, skb); -} - -// increase the date length in sk_buffer by len, -// and return the increased header pointer -uint8_t *skb_put(OUT sk_buff *skb, IN uint32_t len) -{ - RTK_BUFFER *rtb = (RTK_BUFFER *)skb; - - return RtbAddTail(rtb, len); -} - -// change skb->len to len -// !!! len should less than skb->len -void skb_trim(sk_buff *skb, unsigned int len) -{ - RTK_BUFFER *rtb = (RTK_BUFFER *)skb; - uint32_t skb_len = skb_get_data_length(skb); - - RtbRemoveTail(rtb, (skb_len - len)); - return; -} - -uint8_t skb_get_pkt_type(sk_buff *skb) -{ - return BT_CONTEXT(skb)->PacketType; -} - -void skb_set_pkt_type(sk_buff *skb, uint8_t pkt_type) -{ - BT_CONTEXT(skb)->PacketType = pkt_type; -} - -// decrease the data length in sk_buffer by len, -// and move the content forward to the header. -// the data in header will be removed. -void skb_pull(OUT sk_buff *skb, IN uint32_t len) -{ - RTK_BUFFER *rtb = (RTK_BUFFER *)skb; - RtbRemoveHead(rtb, len); - return; -} - -sk_buff *skb_alloc_and_init(IN uint8_t PktType, IN uint8_t *Data, IN uint32_t DataLen) -{ - sk_buff *skb = skb_alloc(DataLen); - if (NULL == skb) - return NULL; - memcpy(skb_put(skb, DataLen), Data, DataLen); - skb_set_pkt_type(skb, PktType); - - return skb; -} - -static void skb_queue_head(IN RTB_QUEUE_HEAD *skb_head, IN RTK_BUFFER *skb) -{ - RtbQueueHead(skb_head, skb); -} - -static void skb_queue_tail(IN RTB_QUEUE_HEAD *skb_head, IN RTK_BUFFER *skb) -{ - RtbQueueTail(skb_head, skb); -} - -static RTK_BUFFER *skb_dequeue_head(IN RTB_QUEUE_HEAD *skb_head) -{ - return RtbDequeueHead(skb_head); -} - -static RTK_BUFFER *skb_dequeue_tail(IN RTB_QUEUE_HEAD *skb_head) -{ - return RtbDequeueTail(skb_head); -} - -static uint32_t skb_queue_get_length(IN RTB_QUEUE_HEAD *skb_head) -{ - return RtbGetQueueLen(skb_head); -} - -/** - * Add "d" into crc scope, caculate the new crc value - * - * @param crc crc data - * @param d one byte data - */ -static void h5_crc_update(uint16_t *crc, uint8_t d) -{ - uint16_t reg = *crc; - - reg = (reg >> 4) ^ crc_table[(reg ^ d) & 0x000f]; - reg = (reg >> 4) ^ crc_table[(reg ^ (d >> 4)) & 0x000f]; - - *crc = reg; -} - -struct __una_u16 -{ - uint16_t x; -}; -/** - * Get crc data. - * - * @param h5 realtek h5 struct - * @return crc data - */ -static uint16_t h5_get_crc(tHCI_H5_CB *h5) -{ - uint16_t crc = 0; - uint8_t *data = skb_get_data(h5->rx_skb) + skb_get_data_length(h5->rx_skb) - 2; - crc = data[1] + (data[0] << 8); - return crc; -} - -/** - * Just add 0xc0 at the end of skb, - * we can also use this to add 0xc0 at start while there is no data in skb - * - * @param skb socket buffer - */ -static void h5_slip_msgdelim(sk_buff *skb) -{ - const char pkt_delim = 0xc0; - memcpy(skb_put(skb, 1), &pkt_delim, 1); -} - -/** - * Slip ecode one byte in h5 proto, as follows: - * 0xc0 -> 0xdb, 0xdc - * 0xdb -> 0xdb, 0xdd - * 0x11 -> 0xdb, 0xde - * 0x13 -> 0xdb, 0xdf - * others will not change - * - * @param skb socket buffer - * @c pure data in the one byte - */ -static void h5_slip_one_byte(sk_buff *skb, uint8_t unencode_form) -{ - const signed char esc_c0[2] = {0xdb, 0xdc}; - const signed char esc_db[2] = {0xdb, 0xdd}; - const signed char esc_11[2] = {0xdb, 0xde}; - const signed char esc_13[2] = {0xdb, 0xdf}; - - switch (unencode_form) - { - case 0xc0: - memcpy(skb_put(skb, 2), &esc_c0, 2); - break; - case 0xdb: - memcpy(skb_put(skb, 2), &esc_db, 2); - break; - - case 0x11: - { - if (rtk_h5.oof_flow_control) - { - memcpy(skb_put(skb, 2), &esc_11, 2); - } - else - { - memcpy(skb_put(skb, 1), &unencode_form, 1); - } - } - break; - - case 0x13: - { - if (rtk_h5.oof_flow_control) - { - memcpy(skb_put(skb, 2), &esc_13, 2); - } - else - { - memcpy(skb_put(skb, 1), &unencode_form, 1); - } - } - break; - - default: - memcpy(skb_put(skb, 1), &unencode_form, 1); - } -} - -/** - * Decode one byte in h5 proto, as follows: - * 0xdb, 0xdc -> 0xc0 - * 0xdb, 0xdd -> 0xdb - * 0xdb, 0xde -> 0x11 - * 0xdb, 0xdf -> 0x13 - * others will not change - * - * @param h5 realtek h5 struct - * @byte pure data in the one byte - */ -static void h5_unslip_one_byte(tHCI_H5_CB *h5, unsigned char byte) -{ - const uint8_t c0 = 0xc0, db = 0xdb; - const uint8_t oof1 = 0x11, oof2 = 0x13; - uint8_t *hdr = (uint8_t *)skb_get_data(h5->rx_skb); - - if (H5_ESCSTATE_NOESC == h5->rx_esc_state) - { - if (0xdb == byte) - { - h5->rx_esc_state = H5_ESCSTATE_ESC; - } - else - { - memcpy(skb_put(h5->rx_skb, 1), &byte, 1); - // Check Pkt Header's CRC enable bit - if (H5_HDR_CRC(hdr) && h5->rx_state != H5_W4_CRC) - { - h5_crc_update(&h5->message_crc, byte); - } - h5->rx_count--; - } - } - else if (H5_ESCSTATE_ESC == h5->rx_esc_state) - { - switch (byte) - { - case 0xdc: - memcpy(skb_put(h5->rx_skb, 1), &c0, 1); - if (H5_HDR_CRC(hdr) && h5->rx_state != H5_W4_CRC) - h5_crc_update(&h5->message_crc, 0xc0); - h5->rx_esc_state = H5_ESCSTATE_NOESC; - h5->rx_count--; - break; - case 0xdd: - memcpy(skb_put(h5->rx_skb, 1), &db, 1); - if (H5_HDR_CRC(hdr) && h5->rx_state != H5_W4_CRC) - h5_crc_update(&h5->message_crc, 0xdb); - h5->rx_esc_state = H5_ESCSTATE_NOESC; - h5->rx_count--; - break; - case 0xde: - memcpy(skb_put(h5->rx_skb, 1), &oof1, 1); - if (H5_HDR_CRC(hdr) && h5->rx_state != H5_W4_CRC) - h5_crc_update(&h5->message_crc, oof1); - h5->rx_esc_state = H5_ESCSTATE_NOESC; - h5->rx_count--; - break; - case 0xdf: - memcpy(skb_put(h5->rx_skb, 1), &oof2, 1); - if (H5_HDR_CRC(hdr) && h5->rx_state != H5_W4_CRC) - h5_crc_update(&h5->message_crc, oof2); - h5->rx_esc_state = H5_ESCSTATE_NOESC; - h5->rx_count--; - break; - default: - HILOGE("Error: Invalid byte %02x after esc byte", byte); - skb_free(&h5->rx_skb); - h5->rx_skb = NULL; - h5->rx_state = H5_W4_PKT_DELIMITER; - h5->rx_count = 0; - break; - } - } -} -/** - * Prepare h5 packet, packet format as follow: - * | LSB 4 octets | 0 ~4095| 2 MSB - * |packet header | payload | data integrity check | - * - * pakcket header fromat is show below: - * | LSB 3 bits | 3 bits | 1 bits | 1 bits | - * | 4 bits | 12 bits | 8 bits MSB - * |sequence number | acknowledgement number | data integrity check present | reliable packet | - * |packet type | payload length | header checksum - * - * @param h5 realtek h5 struct - * @param data pure data - * @param len the length of data - * @param pkt_type packet type - * @return socket buff after prepare in h5 proto - */ -static sk_buff *h5_prepare_pkt(tHCI_H5_CB *h5, uint8_t *data, signed long len, signed long pkt_type) -{ - sk_buff *nskb; - uint8_t hdr[4]; - uint16_t H5_CRC_INIT(h5_txmsg_crc); - int rel, i; - // H5LogMsg("HCI h5_prepare_pkt"); - - switch (pkt_type) - { - case HCI_ACLDATA_PKT: - case HCI_COMMAND_PKT: - case HCI_EVENT_PKT: - rel = H5_RELIABLE_PKT; // reliable - break; - case H5_ACK_PKT: - case H5_VDRSPEC_PKT: - case H5_LINK_CTL_PKT: - case HCI_SCODATA_PKT: - rel = H5_UNRELIABLE_PKT; // unreliable - break; - default: - HILOGE("Unknown packet type"); - return NULL; - } - - // Max len of packet: (original len +4(h5 hdr) +2(crc))*2 - // (because bytes 0xc0 and 0xdb are escaped, worst case is - // when the packet is all made of 0xc0 and 0xdb :) ) - // + 2 (0xc0 delimiters at start and end). - - nskb = skb_alloc((len + 6) * 2 + 2); - if (!nskb) - { - H5LogMsg("nskb is NULL"); - return NULL; - } - - // Add SLIP start byte: 0xc0 - h5_slip_msgdelim(nskb); - // set AckNumber in SlipHeader - hdr[0] = h5->rxseq_txack << 3; - h5->is_txack_req = 0; - - H5LogMsg("We request packet no(%u) to card", h5->rxseq_txack); - H5LogMsg("Sending packet with seqno %u and wait %u", h5->msgq_txseq, h5->rxseq_txack); - if (H5_RELIABLE_PKT == rel) - { - // set reliable pkt bit and SeqNumber - hdr[0] |= 0x80 + h5->msgq_txseq; - // H5LogMsg("Sending packet with seqno(%u)", h5->msgq_txseq); - ++(h5->msgq_txseq); - h5->msgq_txseq = (h5->msgq_txseq) & 0x07; - } - - // set DicPresent bit - if (h5->use_crc) - hdr[0] |= 0x40; - - // set packet type and payload length - hdr[1] = ((len << 4) & 0xff) | pkt_type; - hdr[2] = (uint8_t)(len >> 4); - // set checksum - hdr[3] = ~(hdr[0] + hdr[1] + hdr[2]); - - // Put h5 header */ - for (i = 0; i < 4; i++) - { - h5_slip_one_byte(nskb, hdr[i]); - - if (h5->use_crc) - h5_crc_update(&h5_txmsg_crc, hdr[i]); - } - - // Put payload */ - for (i = 0; i < len; i++) - { - h5_slip_one_byte(nskb, data[i]); - - if (h5->use_crc) - h5_crc_update(&h5_txmsg_crc, data[i]); - } - - // Put CRC */ - if (h5->use_crc) - { - h5_txmsg_crc = bit_rev16(h5_txmsg_crc); - h5_slip_one_byte(nskb, (uint8_t)((h5_txmsg_crc >> 8) & 0x00ff)); - h5_slip_one_byte(nskb, (uint8_t)(h5_txmsg_crc & 0x00ff)); - } - - // Add SLIP end byte: 0xc0 - h5_slip_msgdelim(nskb); - return nskb; -} -/** - * Removed controller acked packet from Host's unacked lists - * - * @param h5 realtek h5 struct - */ -static void h5_remove_acked_pkt(tHCI_H5_CB *h5) -{ - RT_LIST_HEAD *Head = NULL; - RT_LIST_ENTRY *Iter = NULL, *Temp = NULL; - RTK_BUFFER *skb = NULL; - - int pkts_to_be_removed = 0; - int seqno = 0; - int i = 0; - - pthread_mutex_lock(&h5_wakeup_mutex); - - seqno = h5->msgq_txseq; - pkts_to_be_removed = RtbGetQueueLen(h5->unack); - - while (pkts_to_be_removed) - { - if (h5->rxack == seqno) - break; - - pkts_to_be_removed--; - seqno = (seqno - 1) & 0x07; - } - - if (h5->rxack != seqno) - { - H5LogMsg("Peer acked invalid packet"); - } - - // remove ack'ed packet from bcsp->unack queue - i = 0; // number of pkts has been removed from un_ack queue. - Head = (RT_LIST_HEAD *)(h5->unack); - LIST_FOR_EACH_SAFELY(Iter, Temp, Head) - { - skb = LIST_ENTRY(Iter, sk_buff, List); - if (i >= pkts_to_be_removed) - break; - - skb_unlink(skb, h5->unack); - skb_free(&skb); - i++; - } - - if (0 == skb_queue_get_length(h5->unack)) - { - h5_stop_data_retrans_timer(); - rtk_h5.data_retrans_count = 0; - } - - if (i != pkts_to_be_removed) - { - H5LogMsg("Removed only (%u) out of (%u) pkts", i, pkts_to_be_removed); - } - - pthread_mutex_unlock(&h5_wakeup_mutex); -} - -static void hci_h5_send_sync_req() -{ - // uint16_t bytes_sent = 0; - unsigned char h5sync[2] = {0x01, 0x7E}; - sk_buff *skb = NULL; - - skb = skb_alloc_and_init(H5_LINK_CTL_PKT, h5sync, sizeof(h5sync)); - if (!skb) - { - HILOGE("skb_alloc_and_init fail!"); - return; - } - H5LogMsg("H5: --->>>send sync req"); - - h5_enqueue(skb); - h5_wake_up(); -#if 0 - sk_buff *nskb = h5_prepare_pkt(&rtk_h5, h5sync, sizeof(h5sync), H5_LINK_CTL_PKT); - if(nskb == NULL) - { - HILOGE("h5_prepare_pkt allocate memory fail"); - return; - } - H5LogMsg("H5: --->>>send sync req"); - uint8_t * data = skb_get_data(nskb); - -#if H5_TRACE_DATA_ENABLE - { - uint32_t iTemp = 0; - uint32_t iTempTotal = 16; - H5LogMsg("H5 TX: length(%d)", skb_get_data_length(nskb)); - if(iTempTotal > skb_get_data_length(nskb)) - { - iTempTotal = skb_get_data_length(nskb); - } - for(iTemp = 0; iTemp < iTempTotal; iTemp++) - { - H5LogMsg("0x%x", data[iTemp]); - } - } -#endif - - bytes_sent = h5_int_hal_callbacks->h5_int_transmit_data_cb(DATA_TYPE_H5, data, skb_get_data_length(nskb)); - H5LogMsg("bytes_sent(%d)", bytes_sent); - - skb_free(&nskb); -#endif - return; -} - -static void hci_h5_send_sync_resp() -{ - // uint16_t bytes_sent = 0; - unsigned char h5syncresp[2] = {0x02, 0x7D}; - sk_buff *skb = NULL; - - skb = skb_alloc_and_init(H5_LINK_CTL_PKT, h5syncresp, sizeof(h5syncresp)); - if (!skb) - { - HILOGE("skb_alloc_and_init fail!"); - return; - } - - H5LogMsg("H5: --->>>send sync resp"); - h5_enqueue(skb); - h5_wake_up(); -#if 0 - sk_buff *nskb = h5_prepare_pkt(&rtk_h5, h5syncresp, sizeof(h5syncresp), H5_LINK_CTL_PKT); - if(nskb == NULL) - { - HILOGE("h5_prepare_pkt allocate memory fail"); - return; - } - H5LogMsg("H5: --->>>send sync resp"); - uint8_t * data = skb_get_data(nskb); - -#if H5_TRACE_DATA_ENABLE - { - uint32_t iTemp = 0; - uint32_t iTempTotal = 16; - H5LogMsg("H5 TX: length(%d)", skb_get_data_length(nskb)); - if(iTempTotal > skb_get_data_length(nskb)) - { - iTempTotal = skb_get_data_length(nskb); - } - for(iTemp = 0; iTemp < iTempTotal; iTemp++) - { - H5LogMsg("0x%x", data[iTemp]); - } - } -#endif - - bytes_sent = h5_int_hal_callbacks->h5_int_transmit_data_cb(DATA_TYPE_H5, data, skb_get_data_length(nskb)); - H5LogMsg("bytes_sent(%d)", bytes_sent); - - skb_free(&nskb); -#endif - return; -} - -static void hci_h5_send_conf_req() -{ - // uint16_t bytes_sent = 0; - unsigned char h5conf[3] = {0x03, 0xFC, 0x14}; - sk_buff *skb = NULL; - - skb = skb_alloc_and_init(H5_LINK_CTL_PKT, h5conf, sizeof(h5conf)); - if (!skb) - { - HILOGE("skb_alloc_and_init fail!"); - return; - } - - H5LogMsg("H5: --->>>send conf req"); - h5_enqueue(skb); - h5_wake_up(); - -#if 0 - sk_buff *nskb = h5_prepare_pkt(&rtk_h5, h5conf, sizeof(h5conf), H5_LINK_CTL_PKT); - if(nskb == NULL) - { - HILOGE("h5_prepare_pkt allocate memory fail"); - return; - } - H5LogMsg("H5: --->>>send conf req"); - uint8_t * data = skb_get_data(nskb); - -#if H5_TRACE_DATA_ENABLE - { - uint32_t iTemp = 0; - uint32_t iTempTotal = 16; - H5LogMsg("H5 TX: length(%d)", skb_get_data_length(nskb)); - if(iTempTotal > skb_get_data_length(nskb)) - { - iTempTotal = skb_get_data_length(nskb); - } - for(iTemp = 0; iTemp < iTempTotal; iTemp++) - { - H5LogMsg("0x%x", data[iTemp]); - } - } -#endif - - bytes_sent = h5_int_hal_callbacks->h5_int_transmit_data_cb(DATA_TYPE_H5, data, skb_get_data_length(nskb)); - H5LogMsg("bytes_sent(%d)", bytes_sent); - - skb_free(&nskb); -#endif - return; -} - -static void hci_h5_send_conf_resp() -{ - // uint16_t bytes_sent = 0; - unsigned char h5confresp[2] = {0x04, 0x7B}; - sk_buff *skb = NULL; - - skb = skb_alloc_and_init(H5_LINK_CTL_PKT, h5confresp, sizeof(h5confresp)); - if (!skb) - { - HILOGE("skb_alloc_and_init fail!"); - return; - } - - H5LogMsg("H5: --->>>send conf resp"); - h5_enqueue(skb); - h5_wake_up(); -#if 0 - sk_buff *nskb = h5_prepare_pkt(&rtk_h5, h5confresp, sizeof(h5confresp), H5_LINK_CTL_PKT); - if(nskb == NULL) - { - HILOGE("h5_prepare_pkt allocate memory fail"); - return; - } - H5LogMsg("H5: --->>>send conf resp"); - uint8_t * data = skb_get_data(nskb); - -#if H5_TRACE_DATA_ENABLE - { - uint32_t iTemp = 0; - uint32_t iTempTotal = 16; - H5LogMsg("H5 TX: length(%d)", skb_get_data_length(nskb)); - if(iTempTotal > skb_get_data_length(nskb)) - { - iTempTotal = skb_get_data_length(nskb); - } - for(iTemp = 0; iTemp < iTempTotal; iTemp++) - { - H5LogMsg("0x%x", data[iTemp]); - } - } -#endif - - bytes_sent = h5_int_hal_callbacks->h5_int_transmit_data_cb(DATA_TYPE_H5, data, skb_get_data_length(nskb)); - H5LogMsg("bytes_sent(%d)", bytes_sent); - - skb_free(&nskb); -#endif - return; -} - -static void rtk_notify_hw_h5_init_result(uint8_t status) -{ - H5LogMsg("rtk_notify_hw_h5_init_result %d", status); - uint8_t sync_event[6] = {0x0e, 0x04, 0x03, 0xee, 0xfc, status}; - // we need to make a sync event to bt - sk_buff *rx_skb; - rx_skb = skb_alloc_and_init(HCI_EVENT_PKT, sync_event, sizeof(sync_event)); - - if (!rx_skb) - { - HILOGE("%s, rx_skb alloc fail!", __func__); - return; - } - pthread_mutex_lock(&rtk_h5.data_mutex); - skb_queue_tail(rtk_h5.recv_data, rx_skb); - pthread_cond_signal(&rtk_h5.data_cond); - pthread_mutex_unlock(&rtk_h5.data_mutex); -} - -static sk_buff *h5_dequeue() -{ - sk_buff *skb = NULL; - // First of all, check for unreliable messages in the queue, - // since they have higher priority - // H5LogMsg("h5_dequeue++"); - if ((skb = (sk_buff *)skb_dequeue_head(rtk_h5.unrel)) != NULL) - { - sk_buff *nskb = h5_prepare_pkt(&rtk_h5, - skb_get_data(skb), - skb_get_data_length(skb), - skb_get_pkt_type(skb)); - if (nskb) - { - skb_free(&skb); - return nskb; - } - else - { - skb_queue_head(rtk_h5.unrel, skb); - } - } - // Now, try to send a reliable pkt. We can only send a - // reliable packet if the number of packets sent but not yet ack'ed - // is < than the winsize - - // H5LogMsg("RtbGetQueueLen(rtk_h5.unack) = (%d), sliding_window_size = (%d)", RtbGetQueueLen(rtk_h5.unack), rtk_h5.sliding_window_size); - - if (RtbGetQueueLen(rtk_h5.unack) < rtk_h5.sliding_window_size && - (skb = (sk_buff *)skb_dequeue_head(rtk_h5.rel)) != NULL) - { - sk_buff *nskb = h5_prepare_pkt(&rtk_h5, - skb_get_data(skb), - skb_get_data_length(skb), - skb_get_pkt_type(skb)); - if (nskb) - { - skb_queue_tail(rtk_h5.unack, skb); - h5_start_data_retrans_timer(); - return nskb; - } - else - { - skb_queue_head(rtk_h5.rel, skb); - } - } - // We could not send a reliable packet, either because there are - // none or because there are too many unack'ed packets. Did we receive - // any packets we have not acknowledged yet - if (rtk_h5.is_txack_req) - { - // if so, craft an empty ACK pkt and send it on BCSP unreliable - // channel - sk_buff *nskb = h5_prepare_pkt(&rtk_h5, NULL, 0, H5_ACK_PKT); - return nskb; - } - // We have nothing to send - return NULL; -} - -int h5_enqueue(IN sk_buff *skb) -{ - // Pkt length must be less than 4095 bytes - if (skb_get_data_length(skb) > 0xFFF) - { - HILOGE("skb len > 0xFFF"); - skb_free(&skb); - return 0; - } - - switch (skb_get_pkt_type(skb)) - { - case HCI_ACLDATA_PKT: - case HCI_COMMAND_PKT: - skb_queue_tail(rtk_h5.rel, skb); - break; - - case H5_LINK_CTL_PKT: - case H5_ACK_PKT: - case H5_VDRSPEC_PKT: - case HCI_SCODATA_PKT: - skb_queue_tail(rtk_h5.unrel, skb); /* 3-wire LinkEstablishment*/ - break; - default: - skb_free(&skb); - break; - } - return 0; -} - -static uint16_t h5_wake_up() -{ - uint16_t bytes_sent = 0; - sk_buff *skb = NULL; - uint8_t *data = NULL; - uint32_t data_len = 0; - - pthread_mutex_lock(&h5_wakeup_mutex); - // H5LogMsg("h5_wake_up"); - while (NULL != (skb = h5_dequeue())) - { - data = skb_get_data(skb); - data_len = skb_get_data_length(skb); - // we adopt the hci_h5 interface to send data - bytes_sent = h5_int_hal_callbacks->h5_int_transmit_data_cb(DATA_TYPE_H5, data, data_len); - // bytes_sent = userial_write(0, data, data_len); - - H5LogMsg("bytes_sent(%d)", bytes_sent); - -#if H5_TRACE_DATA_ENABLE - { - uint32_t iTemp = 0; - uint32_t iTempTotal = 16; - H5LogMsg("H5 TX: length(%d)", data_len); - if (iTempTotal > data_len) - { - iTempTotal = data_len; - } - for (iTemp = 0; iTemp < iTempTotal; iTemp++) - { - H5LogMsg("0x%x", data[iTemp]); - } - } -#endif - skb_free(&skb); - } - - pthread_mutex_unlock(&h5_wakeup_mutex); - return bytes_sent; -} - -void h5_process_ctl_pkts(void) -{ - // process h5 link establish - uint8_t cfg; - - sk_buff *skb = rtk_h5.rx_skb; - - unsigned char h5sync[2] = {0x01, 0x7E}, - h5syncresp[2] = {0x02, 0x7D}, - h5conf[3] = {0x03, 0xFC, 0x14}, - h5confresp[2] = {0x04, 0x7B}; - // h5InitOk[2] = {0xF1, 0xF1}; - - // uint8_t *ph5_payload = NULL; - // ph5_payload = (uint8_t *)(p_cb->p_rcv_msg + 1); - - if (rtk_h5.link_estab_state == H5_UNINITIALIZED) - { // sync - if (!memcmp(skb_get_data(skb), h5sync, 2)) - { - H5LogMsg("H5: <<<---recv sync req"); - hci_h5_send_sync_resp(); - } - else if (!memcmp(skb_get_data(skb), h5syncresp, 2)) - { - H5LogMsg("H5: <<<---recv sync resp"); - h5_stop_sync_retrans_timer(); - rtk_h5.sync_retrans_count = 0; - rtk_h5.link_estab_state = H5_INITIALIZED; - - // send config req - hci_h5_send_conf_req(); - h5_start_conf_retrans_timer(); - } - } - else if (rtk_h5.link_estab_state == H5_INITIALIZED) - { // config - if (!memcmp(skb_get_data(skb), h5sync, 0x2)) - { - - H5LogMsg("H5: <<<---recv sync req in H5_INITIALIZED"); - hci_h5_send_sync_resp(); - } - else if (!memcmp(skb_get_data(skb), h5conf, 0x2)) - { - H5LogMsg("H5: <<<---recv conf req"); - hci_h5_send_conf_resp(); - } - else if (!memcmp(skb_get_data(skb), h5confresp, 0x2)) - { - H5LogMsg("H5: <<<---recv conf resp"); - h5_stop_conf_retrans_timer(); - rtk_h5.conf_retrans_count = 0; - - rtk_h5.link_estab_state = H5_ACTIVE; - // notify hw to download patch - memcpy(&cfg, skb_get_data(skb) + 2, H5_CFG_SIZE); - rtk_h5.sliding_window_size = H5_CFG_SLID_WIN(cfg); - rtk_h5.oof_flow_control = H5_CFG_OOF_CNTRL(cfg); - rtk_h5.dic_type = H5_CFG_DIC_TYPE(cfg); - H5LogMsg("rtk_h5.sliding_window_size(%d), oof_flow_control(%d), dic_type(%d)", - rtk_h5.sliding_window_size, rtk_h5.oof_flow_control, rtk_h5.dic_type); - if (rtk_h5.dic_type) - { - rtk_h5.use_crc = 1; - } - - rtk_notify_hw_h5_init_result(0); - } - else - { - H5LogMsg("H5_INITIALIZED receive event, ingnore"); - } - } - else if (rtk_h5.link_estab_state == H5_ACTIVE) - { - if (!memcmp(skb_get_data(skb), h5sync, 0x2)) - { - - H5LogMsg("H5: <<<---recv sync req in H5_ACTIVE"); - rtkbt_h5_send_hw_error(); - // kill(getpid(), SIGKILL); - hci_h5_send_sync_resp(); - H5LogMsg("H5 : H5_ACTIVE transit to H5_UNINITIALIZED"); - rtk_h5.link_estab_state = H5_UNINITIALIZED; - hci_h5_send_sync_req(); - h5_start_sync_retrans_timer(); - } - else if (!memcmp(skb_get_data(skb), h5conf, 0x2)) - { - H5LogMsg("H5: <<<---recv conf req in H5_ACTIVE"); - hci_h5_send_conf_resp(); - } - else if (!memcmp(skb_get_data(skb), h5confresp, 0x2)) - { - H5LogMsg("H5: <<<---recv conf resp in H5_ACTIVE, discard"); - } - else - { - H5LogMsg("H5_ACTIVE receive unknown link control msg, ingnore"); - } - } -} - -uint8_t isRtkInternalCommand(uint16_t opcode) -{ - if (opcode == 0xFC17 || opcode == 0xFC6D || opcode == 0xFC61 || opcode == 0xFC20) - { - return 1; - } - else - { - return 0; - } -} - -/***************************************************************************** - * Check if it's a hci frame, if it is, complete it with response or parse the cmd complete event - * - * @param skb socket buffer - * - ******************************************************************************/ -static uint8_t hci_recv_frame(sk_buff *skb, uint8_t pkt_type) -{ - uint8_t intercepted = 0; -#if H5_TRACE_DATA_ENABLE - uint8_t *data = skb_get_data(skb); -#endif - uint32_t data_len = skb_get_data_length(skb); - - H5LogMsg("UART H5 RX: length = %d", data_len); - -#if H5_TRACE_DATA_ENABLE - { - uint32_t iTemp = 0; - uint32_t iTempTotal = 16; - H5LogMsg("H5 RX: length(%d)", data_len); - if (iTempTotal > data_len) - { - iTempTotal = data_len; - } - for (iTemp = 0; iTemp < iTempTotal; iTemp++) - { - H5LogMsg("0x%x", data[iTemp]); - } - } -#endif - // we only intercept evt packet here - if (pkt_type == HCI_EVENT_PKT) - { - uint8_t *p; - uint8_t event_code; - uint16_t opcode, len; - p = (uint8_t *)skb_get_data(skb); - - event_code = *p++; - len = *p++; - H5LogMsg("hci_recv_frame event_code(0x%x), len = %d", event_code, len); - if (event_code == HCI_COMMAND_COMPLETE_EVT) - { - num_hci_cmd_pkts = *p++; - STREAM_TO_UINT16(opcode, p); - - if (opcode == HCI_VSC_UPDATE_BAUDRATE) - { - intercepted = 1; - rtk_h5.internal_skb = skb; - H5LogMsg("CommandCompleteEvent for command h5_start_wait_controller_baudrate_ready_timer (0x%04X)", opcode); - h5_start_wait_controller_baudrate_ready_timer(); - } - } - } - - H5LogMsg("hci_recv_frame intercepted = %d", intercepted); - return intercepted; -} - -/** - * after rx data is parsed, and we got a rx frame saved in h5->rx_skb, - * this routinue is called. - * things todo in this function: - * 1. check if it's a hci frame, if it is, complete it with response or ack - * 2. see the ack number, free acked frame in queue - * 3. reset h5->rx_state, set rx_skb to null. - * - * @param h5 realtek h5 struct - * - */ -static uint8_t h5_complete_rx_pkt(tHCI_H5_CB *h5) -{ - int pass_up = 1; - uint16_t eventtype = 0; - uint8_t *h5_hdr = NULL; - // uint8_t complete_pkt = true; - uint8_t pkt_type = 0; - // tHCI_H5_CB *p_cb=&rtk_h5; - uint8_t status = 0; - - // H5LogMsg("HCI 3wire h5_complete_rx_pkt"); - h5_hdr = (uint8_t *)skb_get_data(h5->rx_skb); - H5LogMsg("SeqNumber(%d), AckNumber(%d)", H5_HDR_SEQ(h5_hdr), H5_HDR_ACK(h5_hdr)); - -#if H5_TRACE_DATA_ENABLE - { - uint32_t iTemp = 0; - uint32_t iTempTotal = 16; - uint32_t data_len = skb_get_data_length(h5->rx_skb); - uint8_t *data = skb_get_data(h5->rx_skb); - H5LogMsg("H5 RX: length(%d)", data_len); - - if (iTempTotal > data_len) - { - iTempTotal = data_len; - } - for (iTemp = 0; iTemp < iTempTotal; iTemp++) - { - H5LogMsg("0x%x", data[iTemp]); - } - } -#endif - - if (H5_HDR_RELIABLE(h5_hdr)) - { - H5LogMsg("Received reliable seqno %u from card", h5->rxseq_txack); - pthread_mutex_lock(&h5_wakeup_mutex); - h5->rxseq_txack = H5_HDR_SEQ(h5_hdr) + 1; - h5->rxseq_txack %= 8; - h5->is_txack_req = 1; - pthread_mutex_unlock(&h5_wakeup_mutex); - // send down an empty ack if needed. - h5_wake_up(); - } - - h5->rxack = H5_HDR_ACK(h5_hdr); - pkt_type = H5_HDR_PKT_TYPE(h5_hdr); - // H5LogMsg("h5_complete_rx_pkt, pkt_type = %d", pkt_type); - switch (pkt_type) - { - case HCI_ACLDATA_PKT: - pass_up = 1; - eventtype = MSG_HC_TO_STACK_HCI_ACL; - break; - - case HCI_EVENT_PKT: - pass_up = 1; - eventtype = MSG_HC_TO_STACK_HCI_EVT; - break; - - case HCI_SCODATA_PKT: - pass_up = 1; - eventtype = MSG_HC_TO_STACK_HCI_SCO; - break; - case HCI_COMMAND_PKT: - pass_up = 1; - eventtype = MSG_HC_TO_STACK_HCI_ERR; - break; - - case H5_LINK_CTL_PKT: - pass_up = 0; - break; - - case H5_ACK_PKT: - pass_up = 0; - break; - - default: - HILOGE("Unknown pkt type(%d)", H5_HDR_PKT_TYPE(h5_hdr)); - eventtype = MSG_HC_TO_STACK_HCI_ERR; - pass_up = 0; - break; - } - - // remove h5 header and send packet to hci - h5_remove_acked_pkt(h5); - - if (H5_HDR_PKT_TYPE(h5_hdr) == H5_LINK_CTL_PKT) - { - - skb_pull(h5->rx_skb, H5_HDR_SIZE); - h5_process_ctl_pkts(); - } - - // decide if we need to pass up. - if (pass_up) - { - skb_pull(h5->rx_skb, H5_HDR_SIZE); - skb_set_pkt_type(h5->rx_skb, pkt_type); - - // send command or acl data it to bluedroid stack - uint16_t len = 0; - sk_buff *skb_complete_pkt = h5->rx_skb; - - /* Allocate a buffer for message */ - - len = BT_HC_HDR_SIZE + skb_get_data_length(skb_complete_pkt); - h5->p_rcv_msg = (HC_BT_HDR *)malloc(len); - - if (h5->p_rcv_msg) - { - /* Initialize buffer with received h5 data */ - h5->p_rcv_msg->offset = 0; - h5->p_rcv_msg->layer_specific = 0; - h5->p_rcv_msg->event = eventtype; - h5->p_rcv_msg->len = skb_get_data_length(skb_complete_pkt); - memcpy((uint8_t *)(h5->p_rcv_msg + 1), skb_get_data(skb_complete_pkt), skb_get_data_length(skb_complete_pkt)); - } - - status = hci_recv_frame(skb_complete_pkt, pkt_type); - - if (h5->p_rcv_msg) - free(h5->p_rcv_msg); - - if (!status) - { - pthread_mutex_lock(&rtk_h5.data_mutex); - skb_queue_tail(rtk_h5.recv_data, h5->rx_skb); - pthread_cond_signal(&rtk_h5.data_cond); - pthread_mutex_unlock(&rtk_h5.data_mutex); - } - } - else - { - // free ctl packet - skb_free(&h5->rx_skb); - } - h5->rx_state = H5_W4_PKT_DELIMITER; - rtk_h5.rx_skb = NULL; - return pkt_type; -} - -/** - * Parse the receive data in h5 proto. - * - * @param h5 realtek h5 struct - * @param data point to data received before parse - * @param count num of data - * @return reserved count - */ -static bool h5_recv(tHCI_H5_CB *h5, uint8_t *data, int count) -{ - // unsigned char *ptr; - uint8_t *ptr; - uint8_t *skb_data = NULL; - uint8_t *hdr = NULL; - bool complete_packet = false; - - ptr = (uint8_t *)data; - // H5LogMsg("count %d rx_state %d rx_count %ld", count, h5->rx_state, h5->rx_count); - while (count) - { - if (h5->rx_count) - { - if (*ptr == 0xc0) - { - HILOGE("short h5 packet"); - skb_free(&h5->rx_skb); - h5->rx_state = H5_W4_PKT_START; - h5->rx_count = 0; - } - else - h5_unslip_one_byte(h5, *ptr); - - ptr++; - count--; - continue; - } - - // H5LogMsg("h5_recv rx_state=%d", h5->rx_state); - switch (h5->rx_state) - { - case H5_W4_HDR: - // check header checksum. see Core Spec V4 "3-wire uart" page 67 - skb_data = skb_get_data(h5->rx_skb); - hdr = (uint8_t *)skb_data; - - if ((0xff & (uint8_t) ~(skb_data[0] + skb_data[1] + - skb_data[2])) != skb_data[3]) - { - HILOGE("h5 hdr checksum error!!!"); - skb_free(&h5->rx_skb); - h5->rx_state = H5_W4_PKT_DELIMITER; - h5->rx_count = 0; - continue; - } - - if (H5_HDR_RELIABLE(hdr) && (H5_HDR_SEQ(hdr) != h5->rxseq_txack)) - { - HILOGE("Out-of-order packet arrived, got(%u)expected(%u)", - H5_HDR_SEQ(hdr), h5->rxseq_txack); - h5->is_txack_req = 1; - h5_wake_up(); - - skb_free(&h5->rx_skb); - h5->rx_state = H5_W4_PKT_DELIMITER; - h5->rx_count = 0; - - continue; - } - h5->rx_state = H5_W4_DATA; - // payload length: May be 0 - h5->rx_count = H5_HDR_LEN(hdr); - continue; - case H5_W4_DATA: - hdr = (uint8_t *)skb_get_data(h5->rx_skb); - if (H5_HDR_CRC(hdr)) - { // pkt with crc / - h5->rx_state = H5_W4_CRC; - h5->rx_count = 2; - } - else - { - h5_complete_rx_pkt(h5); // Send ACK - complete_packet = true; - H5LogMsg("--------> H5_W4_DATA ACK\n"); - } - continue; - - case H5_W4_CRC: - if (bit_rev16(h5->message_crc) != h5_get_crc(h5)) - { - HILOGE("Checksum failed, computed(%04x)received(%04x)", - bit_rev16(h5->message_crc), h5_get_crc(h5)); - skb_free(&h5->rx_skb); - h5->rx_state = H5_W4_PKT_DELIMITER; - h5->rx_count = 0; - continue; - } - skb_trim(h5->rx_skb, skb_get_data_length(h5->rx_skb) - 2); - h5_complete_rx_pkt(h5); - complete_packet = true; - continue; - - case H5_W4_PKT_DELIMITER: - switch (*ptr) - { - case 0xc0: - h5->rx_state = H5_W4_PKT_START; - break; - default: - break; - } - ptr++; - count--; - break; - - case H5_W4_PKT_START: - switch (*ptr) - { - case 0xc0: - ptr++; - count--; - break; - default: - h5->rx_state = H5_W4_HDR; - h5->rx_count = 4; - h5->rx_esc_state = H5_ESCSTATE_NOESC; - H5_CRC_INIT(h5->message_crc); - - // Do not increment ptr or decrement count - // Allocate packet. Max len of a H5 pkt= - // 0xFFF (payload) +4 (header) +2 (crc) - h5->rx_skb = skb_alloc(0x1005); - if (!h5->rx_skb) - { - h5->rx_state = H5_W4_PKT_DELIMITER; - h5->rx_count = 0; - return false; - } - break; - } - break; - } - } - return complete_packet; -} - -/****************************************************************************** -** Static functions -******************************************************************************/ -static void data_ready_cb_thread(void *arg) -{ - RTK_UNUSED(arg); - sk_buff *skb; - uint8_t pkt_type = 0; - unsigned int total_length = 0; - - H5LogMsg("data_ready_cb_thread started"); - - prctl(PR_SET_NAME, (unsigned long)"data_ready_cb_thread", 0, 0, 0); - - while (h5_data_ready_running) - { - pthread_mutex_lock(&rtk_h5.data_mutex); - while (h5_data_ready_running && (skb_queue_get_length(rtk_h5.recv_data) == 0)) - { - pthread_cond_wait(&rtk_h5.data_cond, &rtk_h5.data_mutex); - } - pthread_mutex_unlock(&rtk_h5.data_mutex); - - if (h5_data_ready_running && (skb = skb_dequeue_head(rtk_h5.recv_data)) != NULL) - { - rtk_h5.data_skb = skb; - } - else - continue; - - pkt_type = skb_get_pkt_type(rtk_h5.data_skb); - total_length = skb_get_data_length(rtk_h5.data_skb); - h5_int_hal_callbacks->h5_data_ready_cb(pkt_type, total_length); - } - - H5LogMsg("data_ready_cb_thread exiting"); - pthread_exit(NULL); -} - -static void data_retransfer_thread(void *arg) -{ - RTK_UNUSED(arg); - uint16_t events; - uint16_t data_retrans_counts = DATA_RETRANS_COUNT; - - H5LogMsg("data_retransfer_thread started"); - - prctl(PR_SET_NAME, (unsigned long)"data_retransfer_thread", 0, 0, 0); - - while (h5_retransfer_running) - { - pthread_mutex_lock(&rtk_h5.mutex); - while (h5_ready_events == 0) - { - pthread_cond_wait(&rtk_h5.cond, &rtk_h5.mutex); - } - events = h5_ready_events; - h5_ready_events = 0; - pthread_mutex_unlock(&rtk_h5.mutex); - - if (events & H5_EVENT_RX) - { - sk_buff *skb; - HILOGE("retransmitting (%u) pkts, retransfer count(%d)", skb_queue_get_length(rtk_h5.unack), rtk_h5.data_retrans_count); - if (h5_init_datatrans_flag == 0) - data_retrans_counts = DATA_RETRANS_COUNT; - else - data_retrans_counts = BT_INIT_DATA_RETRANS_COUNT; - - if (rtk_h5.data_retrans_count < data_retrans_counts) - { - pthread_mutex_lock(&h5_wakeup_mutex); - while ((skb = skb_dequeue_tail(rtk_h5.unack)) != NULL) - { -#if H5_TRACE_DATA_ENABLE - uint32_t data_len = skb_get_data_length(skb); - uint8_t *pdata = skb_get_data(skb); - if (data_len > 16) - data_len = 16; - - for (i = 0; i < data_len; i++) - HILOGE("0x%02X", pdata[i]); -#endif - rtk_h5.msgq_txseq = (rtk_h5.msgq_txseq - 1) & 0x07; - skb_queue_head(rtk_h5.rel, skb); - } - pthread_mutex_unlock(&h5_wakeup_mutex); - rtk_h5.data_retrans_count++; - h5_wake_up(); - } - else - { - // do not put packet to rel queue, and do not send - // Kill bluetooth - rtkbt_h5_send_hw_error(); - // kill(getpid(), SIGKILL); - } - } - else if (events & H5_EVENT_EXIT) - { - break; - } - } - - H5LogMsg("data_retransfer_thread exiting"); - pthread_exit(NULL); -} - -void h5_retransfer_signal_event(uint16_t event) -{ - pthread_mutex_lock(&rtk_h5.mutex); - h5_ready_events |= event; - pthread_cond_signal(&rtk_h5.cond); - pthread_mutex_unlock(&rtk_h5.mutex); -} - -static int create_data_retransfer_thread() -{ - // struct sched_param param; - // int policy; - - pthread_attr_t thread_attr; - - if (h5_retransfer_running) - { - HILOGW("create_data_retransfer_thread has been called repeatedly without calling cleanup ?"); - } - - h5_retransfer_running = 1; - h5_ready_events = 0; - - pthread_attr_init(&thread_attr); - pthread_mutex_init(&rtk_h5.mutex, NULL); - pthread_cond_init(&rtk_h5.cond, NULL); - - if (pthread_create(&rtk_h5.thread_data_retrans, &thread_attr, - (void *)data_retransfer_thread, NULL) != 0) - { - HILOGE("pthread_create thread_data_retrans failed!"); - h5_retransfer_running = 0; - return -1; - } - /* - if(pthread_getschedparam(hc_cb.worker_thread, &policy, ¶m)==0) - { - policy = BTHC_LINUX_BASE_POLICY; - - #if (BTHC_LINUX_BASE_POLICY!=SCHED_NORMAL) - param.sched_priority = BTHC_MAIN_THREAD_PRIORITY; - #endif - result = pthread_setschedparam(hc_cb.worker_thread, policy, ¶m); - if (result != 0) - { - HILOGW("create_data_retransfer_thread pthread_setschedparam failed (%s)", \ - strerror(result)); - } - } - */ - return 0; -} - -static int create_data_ready_cb_thread() -{ - // struct sched_param param; - // int policy; - - pthread_attr_t thread_attr; - - if (h5_data_ready_running) - { - HILOGW("create_data_ready_cb_thread has been called repeatedly without calling cleanup ?"); - } - - h5_data_ready_running = 1; - - pthread_attr_init(&thread_attr); - pthread_mutex_init(&rtk_h5.data_mutex, NULL); - pthread_cond_init(&rtk_h5.data_cond, NULL); - - if (pthread_create(&rtk_h5.thread_data_ready_cb, &thread_attr, - (void *)data_ready_cb_thread, NULL) != 0) - { - HILOGE("pthread_create thread_data_ready_cb failed!"); - h5_data_ready_running = 0; - return -1; - } - return 0; -} - -/***************************************************************************** -** HCI H5 INTERFACE FUNCTIONS -*****************************************************************************/ - -/******************************************************************************* -** -** Function hci_h5_init -** -** Description Initialize H5 module -** -** Returns None -** -*******************************************************************************/ -void hci_h5_int_init(hci_h5_callbacks_t *h5_callbacks) -{ - H5LogMsg("hci_h5_int_init"); - - h5_int_hal_callbacks = h5_callbacks; - memset(&rtk_h5, 0, sizeof(tHCI_H5_CB)); - - /* Per HCI spec., always starts with 1 */ - num_hci_cmd_pkts = 1; - - h5_alloc_data_retrans_timer(); - h5_alloc_sync_retrans_timer(); - h5_alloc_conf_retrans_timer(); - h5_alloc_wait_controller_baudrate_ready_timer(); - h5_alloc_hw_init_ready_timer(); - - rtk_h5.thread_data_retrans = (pthread_t)-1; - - rtk_h5.recv_data = RtbQueueInit(); - - if (create_data_ready_cb_thread() != 0) - HILOGE("H5 create_data_ready_cb_thread failed"); - - if (create_data_retransfer_thread() != 0) - HILOGE("H5 create_data_retransfer_thread failed"); - - rtk_h5.unack = RtbQueueInit(); - rtk_h5.rel = RtbQueueInit(); - rtk_h5.unrel = RtbQueueInit(); - - rtk_h5.rx_state = H5_W4_PKT_DELIMITER; - rtk_h5.rx_esc_state = H5_ESCSTATE_NOESC; - - h5_init_datatrans_flag = 1; -} - -/******************************************************************************* -** -** Function hci_h5_cleanup -** -** Description Clean H5 module -** -** Returns None -** -*******************************************************************************/ -void hci_h5_cleanup(void) -{ - H5LogMsg("hci_h5_cleanup"); - // uint8_t try_cnt=10; - int result; - - rtk_h5.cleanuping = 1; - - // btsnoop_cleanup(); - - h5_free_data_retrans_timer(); - h5_free_sync_retrans_timer(); - h5_free_conf_retrans_timer(); - h5_free_wait_controller_baudrate_ready_timer(); - h5_free_hw_init_ready_timer(); - - if (h5_data_ready_running) - { - h5_data_ready_running = 0; - pthread_mutex_lock(&rtk_h5.data_mutex); - pthread_cond_signal(&rtk_h5.data_cond); - pthread_mutex_unlock(&rtk_h5.data_mutex); - if ((result = pthread_join(rtk_h5.thread_data_ready_cb, NULL)) < 0) - HILOGE("H5 thread_data_ready_cb pthread_join() FAILED result:%d", result); - } - - if (h5_retransfer_running) - { - h5_retransfer_running = 0; - h5_retransfer_signal_event(H5_EVENT_EXIT); - if ((result = pthread_join(rtk_h5.thread_data_retrans, NULL)) < 0) - HILOGE("H5 pthread_join() FAILED result:%d", result); - } - - // ms_delay(200); - - pthread_mutex_destroy(&rtk_h5.mutex); - pthread_mutex_destroy(&rtk_h5.data_mutex); - pthread_cond_destroy(&rtk_h5.cond); - pthread_cond_destroy(&rtk_h5.data_cond); - - RtbQueueFree(rtk_h5.unack); - RtbQueueFree(rtk_h5.rel); - RtbQueueFree(rtk_h5.unrel); - - h5_int_hal_callbacks = NULL; - rtk_h5.internal_skb = NULL; -} - -/******************************************************************************* -** -** Function hci_h5_receive_msg -** -** Description Construct HCI EVENT/ACL packets and send them to stack once -** complete packet has been received. -** -** Returns Number of read bytes -** -*******************************************************************************/ -bool hci_h5_receive_msg(uint8_t *byte, uint16_t length) -{ - bool status = false; - // H5LogMsg("hci_h5_receive_msg byte:%d",h5_byte); - status = h5_recv(&rtk_h5, byte, length); - return status; -} - -size_t hci_h5_int_read_data(uint8_t *data_buffer, size_t max_size) -{ - H5LogMsg("hci_h5_int_read_data need_size = %d", max_size); - if (!rtk_h5.data_skb) - { - HILOGE("hci_h5_int_read_data, there is no data to read for this packet!"); - return -1; - } - sk_buff *skb_complete_pkt = rtk_h5.data_skb; - uint8_t *data = skb_get_data(skb_complete_pkt); - uint32_t data_len = skb_get_data_length(skb_complete_pkt); - - H5LogMsg("hci_h5_int_read_data length = %d, need_size = %d", data_len, max_size); - if (data_len <= max_size) - { - memcpy(data_buffer, data, data_len); - skb_free(&rtk_h5.data_skb); - rtk_h5.data_skb = NULL; - return data_len; - } - else - { - memcpy(data_buffer, data, max_size); - skb_pull(rtk_h5.data_skb, max_size); - return max_size; - } -} - -/******************************************************************************* -** -** Function hci_h5_send_cmd -** -** Description get cmd data from hal and send cmd -** -** -** Returns bytes send -** -*******************************************************************************/ -uint16_t hci_h5_send_cmd(serial_data_type_t type, uint8_t *data, uint16_t length) -{ - sk_buff *skb = NULL; - uint16_t bytes_to_send, opcode; - - if (type != DATA_TYPE_COMMAND) - { - HILOGE("%s Receive wrong type type : %d", __func__, type); - return -1; - } - - skb = skb_alloc_and_init(type, data, length); - if (!skb) - { - HILOGE("send cmd skb_alloc_and_init fail!"); - return -1; - } - - h5_enqueue(skb); - - num_hci_cmd_pkts--; - - /* If this is an internal Cmd packet, the layer_specific field would - * have stored with the opcode of HCI command. - * Retrieve the opcode from the Cmd packet. - */ - STREAM_TO_UINT16(opcode, data); - H5LogMsg("HCI Command opcode(0x%04X)", opcode); - if (opcode == 0x0c03) - { - H5LogMsg("RX HCI RESET Command, stop hw init timer"); - h5_stop_hw_init_ready_timer(); - } - bytes_to_send = h5_wake_up(); - return length; -} - -/******************************************************************************* -** -** Function hci_h5_send_acl_data -** -** Description get cmd data from hal and send cmd -** -** -** Returns bytes send -** -*******************************************************************************/ -uint16_t hci_h5_send_acl_data(serial_data_type_t type, uint8_t *data, uint16_t length) -{ - uint16_t bytes_to_send; - sk_buff *skb = NULL; - - skb = skb_alloc_and_init(type, data, length); - if (!skb) - { - HILOGE("hci_h5_send_acl_data, alloc skb buffer fail!"); - return -1; - } - - h5_enqueue(skb); - - bytes_to_send = h5_wake_up(); - return length; -} - -/******************************************************************************* -** -** Function hci_h5_send_sco_data -** -** Description get sco data from hal and send sco data -** -** -** Returns bytes send -** -*******************************************************************************/ -uint16_t hci_h5_send_sco_data(serial_data_type_t type, uint8_t *data, uint16_t length) -{ - sk_buff *skb = NULL; - uint16_t bytes_to_send; - - skb = skb_alloc_and_init(type, data, length); - if (!skb) - { - HILOGE("send sco data skb_alloc_and_init fail!"); - return -1; - } - - h5_enqueue(skb); - - bytes_to_send = h5_wake_up(); - return length; -} - -/******************************************************************************* -** -** Function hci_h5_send_sync_cmd -** -** Description Place the internal commands (issued internally by vendor lib) -** in the tx_q. -** -** Returns TRUE/FALSE -** -*******************************************************************************/ -uint8_t hci_h5_send_sync_cmd(uint16_t opcode, uint8_t *p_buf, uint16_t length) -{ - if (p_buf != NULL) - { - H5LogMsg("hci_h5_send_sync_cmd buf is not null"); - } - if (rtk_h5.link_estab_state == H5_UNINITIALIZED) - { - if (opcode == HCI_VSC_H5_INIT) - { - h5_start_hw_init_ready_timer(); - hci_h5_send_sync_req(); - h5_start_sync_retrans_timer(); - } - } - else if (rtk_h5.link_estab_state == H5_ACTIVE) - { - H5LogMsg("hci_h5_send_sync_cmd(0x%x), link_estab_state = %d, length = %d", opcode, rtk_h5.link_estab_state, length); - return false; - } - - return true; -} - -/*** - Timer related functions -*/ -static timer_t OsAllocateTimer(tTIMER_HANDLE_CBACK timer_callback) -{ - struct sigevent sigev; - timer_t timerid; - - memset(&sigev, 0, sizeof(struct sigevent)); - // Create the POSIX timer to generate signo - sigev.sigev_notify = SIGEV_THREAD; - // sigev.sigev_notify_thread_id = syscall(__NR_gettid); - sigev.sigev_notify_function = timer_callback; - sigev.sigev_value.sival_ptr = &timerid; - - HILOGE("OsAllocateTimer rtk_parse sigev.sigev_notify_thread_id = syscall(__NR_gettid)!"); - // Create the Timer using timer_create signal - - if (timer_create(CLOCK_REALTIME, &sigev, &timerid) == 0) - { - return timerid; - } - else - { - HILOGE("timer_create error!"); - return (timer_t)-1; - } -} - -static int OsFreeTimer(timer_t timerid) -{ - int ret = 0; - ret = timer_delete(timerid); - if (ret != 0) - HILOGE("timer_delete fail with errno(%d)", errno); - - return ret; -} - -static int OsStartTimer(timer_t timerid, int msec, int mode) -{ - struct itimerspec itval; - - itval.it_value.tv_sec = msec / 1000; - itval.it_value.tv_nsec = (long)(msec % 1000) * (1000000L); - - if (mode == 1) - - { - itval.it_interval.tv_sec = itval.it_value.tv_sec; - itval.it_interval.tv_nsec = itval.it_value.tv_nsec; - } - else - { - itval.it_interval.tv_sec = 0; - itval.it_interval.tv_nsec = 0; - } - - // Set the Timer when to expire through timer_settime - - if (timer_settime(timerid, 0, &itval, NULL) != 0) - { - HILOGE("time_settime error!"); - return -1; - } - - return 0; -} - -static int OsStopTimer(timer_t timerid) -{ - return OsStartTimer(timerid, 0, 0); -} - -static void h5_retransfer_timeout_handler(union sigval sigev_value) -{ - RTK_UNUSED(sigev_value); - H5LogMsg("h5_retransfer_timeout_handler"); - if (rtk_h5.cleanuping) - { - HILOGE("h5_retransfer_timeout_handler H5 is cleanuping, EXIT here!"); - return; - } - h5_retransfer_signal_event(H5_EVENT_RX); -} - -static void h5_sync_retrans_timeout_handler(union sigval sigev_value) -{ - RTK_UNUSED(sigev_value); - H5LogMsg("h5_sync_retrans_timeout_handler"); - if (rtk_h5.cleanuping) - { - HILOGE("h5_sync_retrans_timeout_handler H5 is cleanuping, EXIT here!"); - return; - } - if (rtk_h5.sync_retrans_count < SYNC_RETRANS_COUNT) - { - hci_h5_send_sync_req(); - rtk_h5.sync_retrans_count++; - } - else - { - if (rtk_h5.link_estab_state == H5_UNINITIALIZED) - { - rtk_notify_hw_h5_init_result(0x03); - } - h5_stop_sync_retrans_timer(); - } -} - -static void h5_conf_retrans_timeout_handler(union sigval sigev_value) -{ - RTK_UNUSED(sigev_value); - H5LogMsg("h5_conf_retrans_timeout_handler"); - if (rtk_h5.cleanuping) - { - HILOGE("h5_conf_retrans_timeout_handler H5 is cleanuping, EXIT here!"); - return; - } - - H5LogMsg("Wait H5 Conf Resp timeout, %d times", rtk_h5.conf_retrans_count); - if (rtk_h5.conf_retrans_count < CONF_RETRANS_COUNT) - { - hci_h5_send_conf_req(); - rtk_h5.conf_retrans_count++; - } - else - { - if (rtk_h5.link_estab_state != H5_ACTIVE) - { - rtk_notify_hw_h5_init_result(0x03); - } - h5_stop_conf_retrans_timer(); - } -} - -static void h5_wait_controller_baudrate_ready_timeout_handler(union sigval sigev_value) -{ - RTK_UNUSED(sigev_value); - H5LogMsg("h5_wait_ct_baundrate_ready_timeout_handler"); - if (rtk_h5.cleanuping) - { - HILOGE("h5_wait_controller_baudrate_ready_timeout_handler H5 is cleanuping, EXIT here!"); - if (rtk_h5.internal_skb) - skb_free(&rtk_h5.internal_skb); - return; - } - H5LogMsg("No Controller retransfer, baudrate of controller ready"); - pthread_mutex_lock(&rtk_h5.data_mutex); - skb_queue_tail(rtk_h5.recv_data, rtk_h5.internal_skb); - pthread_cond_signal(&rtk_h5.data_cond); - pthread_mutex_unlock(&rtk_h5.data_mutex); - - rtk_h5.internal_skb = NULL; -} - -static void h5_hw_init_ready_timeout_handler(union sigval sigev_value) -{ - RTK_UNUSED(sigev_value); - H5LogMsg("h5_hw_init_ready_timeout_handler"); - if (rtk_h5.cleanuping) - { - HILOGE("H5 is cleanuping, EXIT here!"); - return; - } - H5LogMsg("TIMER_H5_HW_INIT_READY timeout, kill restart BT"); - // kill(getpid(), SIGKILL); -} - -/* -** h5 data retrans timer functions -*/ -int h5_alloc_data_retrans_timer() -{ - // Create and set the timer when to expire - rtk_h5.timer_data_retrans = OsAllocateTimer(h5_retransfer_timeout_handler); - - return 0; -} - -int h5_free_data_retrans_timer() -{ - return OsFreeTimer(rtk_h5.timer_data_retrans); -} - -int h5_start_data_retrans_timer() -{ - if (h5_init_datatrans_flag == 0) - return OsStartTimer(rtk_h5.timer_data_retrans, DATA_RETRANS_TIMEOUT_VALUE, 0); - else - return OsStartTimer(rtk_h5.timer_data_retrans, BT_INIT_DATA_RETRANS_TIMEOUT_VALUE, 0); -} - -int h5_stop_data_retrans_timer() -{ - return OsStopTimer(rtk_h5.timer_data_retrans); -} - -/* -** h5 sync retrans timer functions -*/ -int h5_alloc_sync_retrans_timer() -{ - // Create and set the timer when to expire - rtk_h5.timer_sync_retrans = OsAllocateTimer(h5_sync_retrans_timeout_handler); - - return 0; -} - -int h5_free_sync_retrans_timer() -{ - return OsFreeTimer(rtk_h5.timer_sync_retrans); -} - -int h5_start_sync_retrans_timer() -{ - return OsStartTimer(rtk_h5.timer_sync_retrans, SYNC_RETRANS_TIMEOUT_VALUE, 1); -} - -int h5_stop_sync_retrans_timer() -{ - return OsStopTimer(rtk_h5.timer_sync_retrans); -} - -/* -** h5 config retrans timer functions -*/ -int h5_alloc_conf_retrans_timer() -{ - // Create and set the timer when to expire - rtk_h5.timer_conf_retrans = OsAllocateTimer(h5_conf_retrans_timeout_handler); - - return 0; -} - -int h5_free_conf_retrans_timer() -{ - return OsFreeTimer(rtk_h5.timer_conf_retrans); -} - -int h5_start_conf_retrans_timer() -{ - return OsStartTimer(rtk_h5.timer_conf_retrans, CONF_RETRANS_TIMEOUT_VALUE, 1); -} - -int h5_stop_conf_retrans_timer() -{ - return OsStopTimer(rtk_h5.timer_conf_retrans); -} - -/* -** h5 wait controller baudrate ready timer functions -*/ -int h5_alloc_wait_controller_baudrate_ready_timer() -{ - // Create and set the timer when to expire - rtk_h5.timer_wait_ct_baudrate_ready = OsAllocateTimer(h5_wait_controller_baudrate_ready_timeout_handler); - - return 0; -} - -int h5_free_wait_controller_baudrate_ready_timer() -{ - return OsFreeTimer(rtk_h5.timer_wait_ct_baudrate_ready); -} - -int h5_start_wait_controller_baudrate_ready_timer() -{ - return OsStartTimer(rtk_h5.timer_wait_ct_baudrate_ready, WAIT_CT_BAUDRATE_READY_TIMEOUT_VALUE, 0); -} - -int h5_stop_wait_controller_baudrate_ready_timer() -{ - return OsStopTimer(rtk_h5.timer_wait_ct_baudrate_ready); -} - -/* -** h5 hw init ready timer functions -*/ -int h5_alloc_hw_init_ready_timer() -{ - // Create and set the timer when to expire - rtk_h5.timer_h5_hw_init_ready = OsAllocateTimer(h5_hw_init_ready_timeout_handler); - - return 0; -} - -int h5_free_hw_init_ready_timer() -{ - return OsFreeTimer(rtk_h5.timer_h5_hw_init_ready); -} - -int h5_start_hw_init_ready_timer() -{ - return OsStartTimer(rtk_h5.timer_h5_hw_init_ready, H5_HW_INIT_READY_TIMEOUT_VALUE, 0); -} - -int h5_stop_hw_init_ready_timer() -{ - return OsStopTimer(rtk_h5.timer_h5_hw_init_ready); -} - -/****************************************************************************** -** HCI H5 Services interface table -******************************************************************************/ -const hci_h5_t hci_h5_int_func_table = - { - .h5_int_init = hci_h5_int_init, - .h5_int_cleanup = hci_h5_cleanup, - .h5_send_cmd = hci_h5_send_cmd, - .h5_send_sync_cmd = hci_h5_send_sync_cmd, - .h5_send_acl_data = hci_h5_send_acl_data, - .h5_send_sco_data = hci_h5_send_sco_data, - .h5_recv_msg = hci_h5_receive_msg, - .h5_int_read_data = hci_h5_int_read_data, -}; - -const hci_h5_t *hci_get_h5_int_interface() -{ - return &hci_h5_int_func_table; -} diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/rtk_btservice.c b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/rtk_btservice.c deleted file mode 100755 index 1fd5a89b..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/rtk_btservice.c +++ /dev/null @@ -1,758 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -/****************************************************************************** - * - * Filename: rtk_btservice.c - * - * Description: start unix socketc - * - ******************************************************************************/ - -#define LOG_TAG "bt_service" -#define RTKBT_RELEASE_NAME "20190717_BT_ANDROID_9.0" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "bt_hci_bdroid.h" -#include "bt_vendor_rtk.h" -#include "userial.h" -#include "userial_vendor.h" -#include "rtk_btservice.h" -#include "upio.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "bt_vendor_lib.h" - -// HCI VENDOR Command opcode -#define HCI_VSC_READ_REGISTER 0xFFFF - -#define RTKBTSERVICE_SOCKETPATH "@/data/misc/bluedroid/rtkbt_service.sock" -#define MAX_CONNECTION_NUMBER 10 - -#define RTK_HCICMD 0x01 -#define RTK_CLOSESOCRET 0x02 -#define RTK_INNER 0x03 -#define OTHER 0xff - -#define Rtk_Service_Data_SIZE 259 -#define Rtk_Service_Send_Data_SIZE 259 - -#define HCICMD_REPLY_TIMEOUT_VALUE 8000 // ms -//#define HCI_CMD_PREAMBLE_SIZE 3 - -typedef void (*tTIMER_HANDLE_CBACK)(union sigval sigval_value); - -typedef struct Rtk_Btservice_Info -{ - int socketfd; - int sig_fd[2]; - pthread_t cmdreadythd; - pthread_t epollthd; - int current_client_sock; - int epoll_fd; - int autopair_fd; - sem_t cmdqueue_sem; - sem_t cmdsend_sem; - timer_t timer_hcicmd_reply; - RT_LIST_HEAD cmdqueue_list; - pthread_mutex_t cmdqueue_mutex; - volatile uint8_t cmdqueue_thread_running; - volatile uint8_t epoll_thread_running; - void (*current_complete_cback)(void *); -} Rtk_Btservice_Info; - -typedef struct Rtk_Service_Data -{ - uint16_t opcode; - uint8_t parameter_len; - uint8_t *parameter; - void (*complete_cback)(void *); -} Rtk_Service_Data; - -/* -typedef struct Rtk_Socket_Data -{ - char type; //hci,other,inner - uint8_t opcodeh; - uint8_t opcodel; - uint8_t parameter_len; - uint8_t parameter[0]; -}Rtk_Socket_Data; -*/ - -typedef struct Rtk_Queue_Data -{ - RT_LIST_ENTRY list; - int client_sock; - uint16_t opcode; - uint8_t parameter_len; - uint8_t *parameter; - void (*complete_cback)(void *); -} Rtkqueuedata; -typedef void (*tINT_CMD_CBACK)(void *p_mem); -extern void rtk_vendor_cmd_to_fw(uint16_t opcode, uint8_t parameter_len, uint8_t *parameter, tINT_CMD_CBACK p_cback); -static Rtk_Btservice_Info *rtk_btservice = NULL; -static void Rtk_Service_Send_Hwerror_Event(); -// extern void userial_recv_rawdata_hook(unsigned char *, unsigned int); -static timer_t OsAllocateTimer(tTIMER_HANDLE_CBACK timer_callback) -{ - struct sigevent sigev; - timer_t timerid; - - memset(&sigev, 0, sizeof(struct sigevent)); - // Create the POSIX timer to generate signo - sigev.sigev_notify = SIGEV_THREAD; - // sigev.sigev_notify_thread_id = syscall(__NR_gettid); - sigev.sigev_notify_function = timer_callback; - sigev.sigev_value.sival_ptr = &timerid; - - HILOGD("OsAllocateTimer bt_service sigev.sigev_notify_thread_id = syscall(__NR_gettid)!"); - // Create the Timer using timer_create signal - - if (timer_create(CLOCK_REALTIME, &sigev, &timerid) == 0) - { - return timerid; - } - else - { - HILOGE("timer_create error!"); - return (timer_t)-1; - } -} - -static int OsFreeTimer(timer_t timerid) -{ - int ret = 0; - ret = timer_delete(timerid); - if (ret != 0) - HILOGE("timer_delete fail with errno(%d)", errno); - - return ret; -} - -static int OsStartTimer(timer_t timerid, int msec, int mode) -{ - struct itimerspec itval; - - itval.it_value.tv_sec = msec / 1000; - itval.it_value.tv_nsec = (long)(msec % 1000) * (1000000L); - - if (mode == 1) - { - itval.it_interval.tv_sec = itval.it_value.tv_sec; - itval.it_interval.tv_nsec = itval.it_value.tv_nsec; - } - else - { - itval.it_interval.tv_sec = 0; - itval.it_interval.tv_nsec = 0; - } - - // Set the Timer when to expire through timer_settime - - if (timer_settime(timerid, 0, &itval, NULL) != 0) - { - HILOGE("time_settime error!"); - return -1; - } - - return 0; -} - -static int OsStopTimer(timer_t timerid) -{ - return OsStartTimer(timerid, 0, 0); -} - -static void init_cmdqueue_hash(Rtk_Btservice_Info *rtk_info) -{ - RT_LIST_HEAD *head = &rtk_info->cmdqueue_list; - ListInitializeHeader(head); -} - -static void delete_cmdqueue_from_hash(Rtkqueuedata *desc) -{ - if (desc) - { - ListDeleteNode(&desc->list); - free(desc); - desc = NULL; - } -} - -static void flush_cmdqueue_hash(Rtk_Btservice_Info *rtk_info) -{ - RT_LIST_HEAD *head = &rtk_info->cmdqueue_list; - RT_LIST_ENTRY *iter = NULL, *temp = NULL; - Rtkqueuedata *desc = NULL; - - pthread_mutex_lock(&rtk_info->cmdqueue_mutex); - LIST_FOR_EACH_SAFELY(iter, temp, head) - { - desc = LIST_ENTRY(iter, Rtkqueuedata, list); - delete_cmdqueue_from_hash(desc); - } - // ListInitializeHeader(head); - pthread_mutex_unlock(&rtk_info->cmdqueue_mutex); -} - -static void hcicmd_reply_timeout_handler() //(union sigval sigev_value) -{ - Rtk_Service_Send_Hwerror_Event(); - // return; -} - -static int hcicmd_alloc_reply_timer() -{ - // Create and set the timer when to expire - rtk_btservice->timer_hcicmd_reply = OsAllocateTimer(hcicmd_reply_timeout_handler); - - return 0; -} - -static int hcicmd_free_reply_timer() -{ - return OsFreeTimer(rtk_btservice->timer_hcicmd_reply); -} - -static int hcicmd_start_reply_timer() -{ - return OsStartTimer(rtk_btservice->timer_hcicmd_reply, HCICMD_REPLY_TIMEOUT_VALUE, 1); -} - -static int hcicmd_stop_reply_timer() -{ - return OsStopTimer(rtk_btservice->timer_hcicmd_reply); -} - -static void Rtk_Client_Cmd_Cback(void *p_mem) -{ - HC_BT_HDR *p_evt_buf = (HC_BT_HDR *)p_mem; - unsigned char *sendbuf = NULL; - int len; - - if (p_evt_buf != NULL) - { - len = 8 + p_evt_buf->len; - sendbuf = p_mem; - if (rtk_btservice->current_client_sock != -1) - { - write(rtk_btservice->current_client_sock, sendbuf, len); - } - else - { - HILOGE("%s current_client_sock is not exist!", __func__); - } - } -} - -void Rtk_Service_Vendorcmd_Hook(Rtk_Service_Data *RtkData, int client_sock) -{ - Rtkqueuedata *rtkqueue_data = NULL; - if (!rtk_btservice) - { - HILOGE("rtkbt service is null"); - return; - } - - pthread_mutex_lock(&rtk_btservice->cmdqueue_mutex); - rtkqueue_data = (Rtkqueuedata *)malloc(sizeof(Rtkqueuedata)); - if (NULL == rtkqueue_data) - { - HILOGE("rtkqueue_data: allocate error"); - if (RtkData->parameter_len > 0) - { - free(RtkData->parameter); - } - return; - } - - rtkqueue_data->opcode = RtkData->opcode; - rtkqueue_data->parameter = RtkData->parameter; - rtkqueue_data->parameter_len = RtkData->parameter_len; - rtkqueue_data->client_sock = client_sock; - rtkqueue_data->complete_cback = RtkData->complete_cback; - - ListAddToTail(&(rtkqueue_data->list), &(rtk_btservice->cmdqueue_list)); - sem_post(&rtk_btservice->cmdqueue_sem); - pthread_mutex_unlock(&rtk_btservice->cmdqueue_mutex); -} - -static void Rtk_Service_Cmd_Event_Cback(void *p_mem) -{ - if (p_mem != NULL) - { - if (rtk_btservice->current_complete_cback != NULL) - { - (*rtk_btservice->current_complete_cback)(p_mem); - } - else - { - HILOGE("%s current_complete_cback is not exist!", __func__); - } - rtk_btservice->current_complete_cback = NULL; - hcicmd_stop_reply_timer(); - sem_post(&rtk_btservice->cmdsend_sem); - } -} - -static void Rtk_Service_Send_Hwerror_Event() -{ - unsigned char p_buf[4]; - int length = 4; - p_buf[0] = 0x04; // event - p_buf[1] = 0x10; // hardware error - p_buf[2] = 0x01; // len - p_buf[3] = 0xfd; // rtkbtservice error code - userial_recv_rawdata_hook(p_buf, length); -} - -static void *cmdready_thread() -{ - // Rtkqueuedata* rtk_data; - - while (rtk_btservice->cmdqueue_thread_running) - { - sem_wait(&rtk_btservice->cmdqueue_sem); - sem_wait(&rtk_btservice->cmdsend_sem); - - if (rtk_btservice->cmdqueue_thread_running != 0) - { - pthread_mutex_lock(&rtk_btservice->cmdqueue_mutex); - RT_LIST_ENTRY *iter = ListGetTop(&(rtk_btservice->cmdqueue_list)); - Rtkqueuedata *desc = NULL; - if (iter) - { - desc = LIST_ENTRY(iter, Rtkqueuedata, list); - if (desc) - { - ListDeleteNode(&desc->list); - } - } - - pthread_mutex_unlock(&rtk_btservice->cmdqueue_mutex); - - if (desc) - { - if (desc->opcode == 0xfc77) - { - rtk_btservice->autopair_fd = desc->client_sock; - } - - if (desc->opcode != 0xfc94) - HILOGD("%s, transmit_command Opcode:%x", __func__, desc->opcode); - rtk_btservice->current_client_sock = desc->client_sock; - rtk_btservice->current_complete_cback = desc->complete_cback; - // bt_vendor_cbacks->xmit_cb(desc->opcode, p_buf, desc->complete_cback); - rtk_vendor_cmd_to_fw(desc->opcode, desc->parameter_len, desc->parameter, Rtk_Service_Cmd_Event_Cback); - hcicmd_start_reply_timer(); - if (desc->parameter_len > 0) - free(desc->parameter); - } - free(desc); - } - } - pthread_exit(0); -} - -static void Getpacket(int client_sock) -{ - unsigned char type = 0; - unsigned char opcodeh = 0; - unsigned char opcodel = 0; - unsigned char parameter_length = 0; - unsigned char *parameter = NULL; - int recvlen = 0; - Rtk_Service_Data *p_buf; - - recvlen = read(client_sock, &type, 1); - HILOGD("%s recvlen=%d,type=%d", __func__, recvlen, type); - if (recvlen <= 0) - { - close(client_sock); - if (client_sock == rtk_btservice->autopair_fd) - { - rtk_btservice->autopair_fd = -1; - } - return; - } - - switch (type) - { - case RTK_HCICMD: - { - recvlen = read(client_sock, &opcodeh, 1); - if (recvlen <= 0) - { - HILOGE("read opcode high char error"); - break; - } - recvlen = read(client_sock, &opcodel, 1); - if (recvlen <= 0) - { - HILOGE("read opcode low char error"); - break; - } - recvlen = read(client_sock, ¶meter_length, 1); - if (recvlen <= 0) - { - HILOGE("read parameter_length char error"); - break; - } - - if (parameter_length > 0) - { - parameter = (unsigned char *)malloc(sizeof(char) * parameter_length); - if (!parameter) - { - HILOGE("%s parameter alloc fail!", __func__); - return; - } - recvlen = read(client_sock, parameter, parameter_length); - HILOGD("%s parameter_length=%d,recvlen=%d", __func__, parameter_length, recvlen); - if (recvlen <= 0 || recvlen != parameter_length) - { - HILOGE("read parameter_length char error recvlen=%d,parameter_length=%d\n", recvlen, parameter_length); - free(parameter); - break; - } - } - p_buf = (Rtk_Service_Data *)malloc(sizeof(Rtk_Service_Data)); - if (NULL == p_buf) - { - HILOGE("p_buf: allocate error"); - if (parameter) - free(parameter); - return; - } - - p_buf->opcode = ((unsigned short)opcodeh) << 8 | opcodel; - p_buf->parameter = parameter; - p_buf->parameter_len = parameter_length; - p_buf->complete_cback = Rtk_Client_Cmd_Cback; - Rtk_Service_Vendorcmd_Hook(p_buf, client_sock); - free(p_buf); - break; - } - case RTK_CLOSESOCRET: - { - close(client_sock); - // pthread_exit(0); - break; - } - default: - { - HILOGE("%s The RtkSockData type is not found!", __func__); - break; - } - } -} - -void rtk_btservice_internal_event_intercept(uint8_t *p_full_msg, uint8_t *p_msg) -{ - uint8_t *p = p_msg; - uint8_t event_code = *p++; - uint8_t subcode; - HC_BT_HDR *p_evt_buf = (HC_BT_HDR *)p_full_msg; - if (event_code == 0xff) - HILOGD("rtk_btservice_internal_event_intercept event_code=0x%x", event_code); - switch (event_code) - { - case HCI_VENDOR_SPECIFIC_EVT: - { - STREAM_TO_UINT8(subcode, p); - switch (subcode) - { - case HCI_RTKBT_AUTOPAIR_EVT: - { - - HILOGD("p_evt_buf_len=%d", p_evt_buf->len); - if (rtk_btservice->autopair_fd != -1) - { - write(rtk_btservice->autopair_fd, p_evt_buf, p_evt_buf->len + 8); - uint8_t p_bluedroid_len = p_evt_buf->len + 1; - uint8_t p_bluedroid[p_bluedroid_len]; - p_bluedroid[0] = DATA_TYPE_EVENT; - memcpy((uint8_t *)(p_bluedroid + 1), p_msg, p_evt_buf->len); - p_bluedroid[1] = 0x3e; // event_code - p_bluedroid[3] = 0x02; // subcode - userial_recv_rawdata_hook(p_bluedroid, p_bluedroid_len); - } - } - - default: - break; - } - break; - } - default: - break; - } -} - -static int socket_accept(socketfd) -{ - struct sockaddr_un un; - socklen_t len; - int client_sock = 0; - len = sizeof(un); - struct epoll_event event; - - client_sock = accept(socketfd, (struct sockaddr *)&un, &len); - if (client_sock < 0) - { - printf("accept failed\n"); - return -1; - } - // pthread_create(&connectthread,NULL,(void *)accept_request_thread,&client_sock); - - event.data.fd = client_sock; - event.events = EPOLLIN | EPOLLHUP | EPOLLRDHUP | EPOLLERR; - // list_add(client_sock); - if (epoll_ctl(rtk_btservice->epoll_fd, EPOLL_CTL_ADD, client_sock, &event) == -1) - { - HILOGE("%s unable to register fd %d to epoll set: %s", __func__, client_sock, strerror(errno)); - close(client_sock); - return -1; - } - return 0; -} - -static void *epoll_thread() -{ - struct epoll_event events[64]; - int nfds = 0; - int i = 0; - - while (rtk_btservice->epoll_thread_running) - { - nfds = epoll_wait(rtk_btservice->epoll_fd, events, 32, 500); - if (rtk_btservice->epoll_thread_running != 0) - { - if (nfds > 0) - { - for (i = 0; i < nfds; i++) - { - if (events[i].data.fd == rtk_btservice->sig_fd[1]) - { - HILOGE("epoll_thread , receive exit signal"); - continue; - } - - if (events[i].data.fd == rtk_btservice->socketfd && events[i].events & EPOLLIN) - { - if (socket_accept(events[i].data.fd) < 0) - { - pthread_exit(0); - } - } - else if (events[i].events & (EPOLLIN | EPOLLHUP | EPOLLRDHUP | EPOLLERR)) - { - HILOGD("%s events[i].data.fd = %d ", __func__, events[i].data.fd); - Getpacket(events[i].data.fd); - } - } - } - } - } - pthread_exit(0); -} - -static int unix_socket_start(const char *servername) -{ - int len; - struct sockaddr_un un; - struct epoll_event event; - - if ((rtk_btservice->socketfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) - { - HILOGE("%s create AF_UNIX socket fail!", __func__); - return -1; - } - - memset(&un, 0, sizeof(un)); - un.sun_family = AF_UNIX; - strcpy(un.sun_path, servername); - un.sun_path[0] = 0; - len = offsetof(struct sockaddr_un, sun_path) + strlen(servername); - - if (bind(rtk_btservice->socketfd, (struct sockaddr *)&un, len) < 0) - { - HILOGE("%s bind socket fail!", __func__); - return -1; - } - - if (listen(rtk_btservice->socketfd, MAX_CONNECTION_NUMBER) < 0) - { - HILOGE("%s listen socket fail!", __func__); - return -1; - } - - event.data.fd = rtk_btservice->socketfd; - event.events = EPOLLIN; - if (epoll_ctl(rtk_btservice->epoll_fd, EPOLL_CTL_ADD, rtk_btservice->socketfd, &event) == -1) - { - HILOGE("%s unable to register fd %d to epoll set: %s", __func__, rtk_btservice->socketfd, strerror(errno)); - return -1; - } - - event.data.fd = rtk_btservice->sig_fd[1]; - event.events = EPOLLIN; - if (epoll_ctl(rtk_btservice->epoll_fd, EPOLL_CTL_ADD, rtk_btservice->sig_fd[1], &event) == -1) - { - HILOGE("%s unable to register signal fd %d to epoll set: %s", __func__, rtk_btservice->sig_fd[1], strerror(errno)); - return -1; - } - return 0; -} - -void RTK_btservice_send_close_signal(void) -{ - unsigned char close_signal = 1; - ssize_t ret; - RTK_NO_INTR(ret = write(rtk_btservice->sig_fd[0], &close_signal, 1)); -} - -int RTK_btservice_thread_start() -{ - rtk_btservice->epoll_thread_running = 1; - if (pthread_create(&rtk_btservice->epollthd, NULL, epoll_thread, NULL) != 0) - { - HILOGE("pthread_create epoll_thread: %s", strerror(errno)); - return -1; - } - - rtk_btservice->cmdqueue_thread_running = 1; - if (pthread_create(&rtk_btservice->cmdreadythd, NULL, cmdready_thread, NULL) != 0) - { - HILOGE("pthread_create cmdready_thread: %s", strerror(errno)); - return -1; - } - - return 0; -} - -void RTK_btservice_thread_stop() -{ - rtk_btservice->epoll_thread_running = 0; - rtk_btservice->cmdqueue_thread_running = 0; - RTK_btservice_send_close_signal(); - sem_post(&rtk_btservice->cmdqueue_sem); - sem_post(&rtk_btservice->cmdsend_sem); - pthread_join(rtk_btservice->cmdreadythd, NULL); - pthread_join(rtk_btservice->epollthd, NULL); - close(rtk_btservice->epoll_fd); - HILOGD("%s end!", __func__); -} - -int RTK_btservice_init() -{ - int ret; - rtk_btservice = (Rtk_Btservice_Info *)malloc(sizeof(Rtk_Btservice_Info)); - if (rtk_btservice) - memset(rtk_btservice, 0, sizeof(Rtk_Btservice_Info)); - else - { - HILOGE("%s, alloc fail", __func__); - return -1; - } - - rtk_btservice->current_client_sock = -1; - rtk_btservice->current_complete_cback = NULL; - rtk_btservice->autopair_fd = -1; - hcicmd_alloc_reply_timer(); - - sem_init(&rtk_btservice->cmdqueue_sem, 0, 0); - sem_init(&rtk_btservice->cmdsend_sem, 0, 1); - - pthread_mutex_init(&rtk_btservice->cmdqueue_mutex, NULL); - init_cmdqueue_hash(rtk_btservice); - if (bt_vendor_cbacks == NULL) - { - HILOGE("%s bt_vendor_cbacks is NULL!", __func__); - return -1; - } - - if ((ret = socketpair(AF_UNIX, SOCK_STREAM, 0, rtk_btservice->sig_fd)) < 0) - { - HILOGE("%s, errno : %s", __func__, strerror(errno)); - return ret; - } - - rtk_btservice->epoll_fd = epoll_create(64); - if (rtk_btservice->epoll_fd == -1) - { - HILOGE("%s unable to create epoll instance: %s", __func__, strerror(errno)); - return -1; - } - - if (unix_socket_start(RTKBTSERVICE_SOCKETPATH) < 0) - { - HILOGE("%s unix_socket_start fail!", __func__); - return -1; - } - - ret = RTK_btservice_thread_start(); - if (ret < 0) - { - HILOGE("%s RTK_btservice_thread_start fail!", __func__); - return -1; - } - HILOGD("%s init done!", __func__); - return 0; -} - -void RTK_btservice_destroyed() -{ - if (!rtk_btservice) - return; - RTK_btservice_thread_stop(); - close(rtk_btservice->socketfd); - rtk_btservice->socketfd = -1; - close(rtk_btservice->sig_fd[0]); - close(rtk_btservice->sig_fd[1]); - sem_destroy(&rtk_btservice->cmdqueue_sem); - sem_destroy(&rtk_btservice->cmdsend_sem); - flush_cmdqueue_hash(rtk_btservice); - hcicmd_free_reply_timer(); - pthread_mutex_destroy(&rtk_btservice->cmdqueue_mutex); - rtk_btservice->autopair_fd = -1; - rtk_btservice->current_client_sock = -1; - free(rtk_btservice); - rtk_btservice = NULL; - HILOGD("%s destroyed done!", __func__); -} diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/rtk_btsnoop_net.c b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/rtk_btsnoop_net.c deleted file mode 100755 index 60c58495..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/rtk_btsnoop_net.c +++ /dev/null @@ -1,428 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#define LOG_TAG "rtk_btsnoop_net" -#include -#include "rtk_btsnoop_net.h" -#include "bt_vendor_rtk.h" - -#define RTK_NO_INTR(fn) \ - do \ - { \ - } while ((fn) == -1 && errno == EINTR) - -#define DATA_DIRECT_2_ELLISY 1 - -#define HCI_COMMAND 0x01 -#define HCI_ACL_DATA_H2C 0x02 -#define HCI_ACL_DATA_C2H 0x82 -#define HCI_SCO_DATA_H2C 0x03 -#define HCI_SCO_DATA_C2H 0x83 -#define HCI_EVENT 0x84 - -#define HCI_COMMAND_PKT 0x01 -#define HCI_ACLDATA_PKT 0x02 -#define HCI_SCODATA_PKT 0x03 -#define HCI_EVENT_PKT 0x04 - -unsigned int rtkbt_h5logfilter = 0x01; -bool rtk_btsnoop_dump = false; -bool rtk_btsnoop_net_dump = false; -bool rtk_btsnoop_save_log = false; -char rtk_btsnoop_path[1024] = {'\0'}; -static pthread_mutex_t btsnoop_log_lock; - -static void rtk_safe_close_(int *fd); -static void *rtk_listen_fn_(void *context); - -static const char *RTK_LISTEN_THREAD_NAME_ = "rtk_btsnoop_net"; -static const int RTK_LOCALHOST_ = 0xC0A80AE2; // 192.168.10.226 -static const int RTK_LISTEN_PORT_ = 8872; - -static const int RTK_REMOTEHOST_ = 0xC0A80A03; // 192.168.10.21 -static const int RTK_REMOTE_PORT_ = 24352; - -static pthread_t rtk_listen_thread_; -static bool rtk_listen_thread_valid_ = false; -static pthread_mutex_t rtk_client_socket_lock_ = PTHREAD_MUTEX_INITIALIZER; -static int rtk_listen_socket_ = -1; - -// File descriptor for btsnoop file. -static int hci_btsnoop_fd = -1; -// Epoch in microseconds since 01/01/0000. -static const uint64_t BTSNOOP_EPOCH_DELTA = 0x00dcddb30f2f8000ULL; - -static uint64_t rtk_btsnoop_timestamp(void) -{ - struct timeval tv; - gettimeofday(&tv, NULL); - - // Timestamp is in microseconds. - uint64_t timestamp = tv.tv_sec * 1000LL * 1000LL; - timestamp += tv.tv_usec; - timestamp += BTSNOOP_EPOCH_DELTA; - return timestamp; -} - -void rtk_btsnoop_open() -{ - pthread_mutex_init(&btsnoop_log_lock, NULL); - char last_log_path[PATH_MAX]; - uint64_t timestamp; - uint32_t usec; - uint8_t sec, hour, minus, day; - - if (hci_btsnoop_fd != -1) - { - HILOGE("%s btsnoop log file is already open.", __func__); - return; - } - - if (rtk_btsnoop_save_log) - { - timestamp = rtk_btsnoop_timestamp() - BTSNOOP_EPOCH_DELTA; - usec = (uint32_t)(timestamp % 1000000LL); - timestamp /= 1000000LL; - sec = (uint8_t)(timestamp % 60LL); - timestamp /= 60LL; - minus = (uint8_t)(timestamp % 60LL); - timestamp /= 60LL; - hour = (uint8_t)(timestamp % 24LL); - timestamp /= 24LL; - day = (uint8_t)(timestamp % 30LL); - timestamp /= 30LL; - // snprintf(last_log_path, PATH_MAX, "%s.%llu", rtk_btsnoop_path, rtk_btsnoop_timestamp()); - snprintf(last_log_path, PATH_MAX, "%s.%uY-%dD-%dH-%dM-%dS-%dUS", rtk_btsnoop_path, - (uint32_t)timestamp, day, hour, minus, sec, usec); - if (!rename(rtk_btsnoop_path, last_log_path) && errno != ENOENT) - HILOGE("%s unable to rename '%s' to '%s': %s", __func__, rtk_btsnoop_path, last_log_path, strerror(errno)); - } - else - { - snprintf(last_log_path, PATH_MAX, "%s.last", rtk_btsnoop_path); - if (!rename(rtk_btsnoop_path, last_log_path) && errno != ENOENT) - HILOGE("%s unable to rename '%s' to '%s': %s", __func__, rtk_btsnoop_path, last_log_path, strerror(errno)); - } - - hci_btsnoop_fd = open(rtk_btsnoop_path, - O_WRONLY | O_CREAT | O_TRUNC, - S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); - - if (hci_btsnoop_fd == -1) - { - HILOGE("%s unable to open '%s': %s", __func__, rtk_btsnoop_path, strerror(errno)); - return; - } - - write(hci_btsnoop_fd, "btsnoop\0\0\0\0\1\0\0\x3\xea", 16); -} - -void rtk_btsnoop_close(void) -{ - pthread_mutex_destroy(&btsnoop_log_lock); - if (hci_btsnoop_fd != -1) - close(hci_btsnoop_fd); - hci_btsnoop_fd = -1; -} - -static void rtk_btsnoop_write(const void *data, size_t length) -{ - if (hci_btsnoop_fd != -1) - write(hci_btsnoop_fd, data, length); -} - -static void rtk_btsnoop_write_packet(serial_data_type_t type, const uint8_t *packet, bool is_received) -{ - int length_he = 0; - int length; - int flags; - int drops = 0; - pthread_mutex_lock(&btsnoop_log_lock); - switch (type) - { - case HCI_COMMAND_PKT: - length_he = packet[2] + 4; - flags = 2; - break; - case HCI_ACLDATA_PKT: - length_he = (packet[3] << 8) + packet[2] + 5; - flags = is_received; - break; - case HCI_SCODATA_PKT: - length_he = packet[2] + 4; - flags = is_received; - break; - case HCI_EVENT_PKT: - length_he = packet[1] + 3; - flags = 3; - break; - default: - break; - } - - uint64_t timestamp = rtk_btsnoop_timestamp(); - uint32_t time_hi = timestamp >> 32; - uint32_t time_lo = timestamp & 0xFFFFFFFF; - - length = htonl(length_he); - flags = htonl(flags); - drops = htonl(drops); - time_hi = htonl(time_hi); - time_lo = htonl(time_lo); - - rtk_btsnoop_write(&length, 4); - rtk_btsnoop_write(&length, 4); - rtk_btsnoop_write(&flags, 4); - rtk_btsnoop_write(&drops, 4); - rtk_btsnoop_write(&time_hi, 4); - rtk_btsnoop_write(&time_lo, 4); - rtk_btsnoop_write(&type, 1); - rtk_btsnoop_write(packet, length_he - 1); - pthread_mutex_unlock(&btsnoop_log_lock); -} - -void rtk_btsnoop_capture(const HC_BT_HDR *p_buf, bool is_rcvd) -{ - const uint8_t *p = (const uint8_t *)(p_buf + 1) + p_buf->offset; - - if (hci_btsnoop_fd == -1) - return; - - switch (p_buf->event & MSG_EVT_MASK) - { - case MSG_HC_TO_STACK_HCI_EVT: - if ((*(p + 3) == 0x94) && (*(p + 4) == 0xfc) && (*(p + 5) == 0x00) && (rtkbt_h5logfilter & 1)) - { - } - else - { - rtk_btsnoop_write_packet(HCI_EVENT_PKT, p, false); - } - break; - case MSG_HC_TO_STACK_HCI_ACL: - case MSG_STACK_TO_HC_HCI_ACL: - rtk_btsnoop_write_packet(HCI_ACLDATA_PKT, p, is_rcvd); - break; - case MSG_HC_TO_STACK_HCI_SCO: - case MSG_STACK_TO_HC_HCI_SCO: - rtk_btsnoop_write_packet(HCI_SCODATA_PKT, p, is_rcvd); - break; - case MSG_STACK_TO_HC_HCI_CMD: - if (((rtkbt_h5logfilter & 1) == 0) || (*p != 0x94) || (*(p + 1) != 0xfc)) - rtk_btsnoop_write_packet(HCI_COMMAND_PKT, p, true); - break; - } -} - -void rtk_btsnoop_net_open() -{ - rtk_listen_thread_valid_ = (pthread_create(&rtk_listen_thread_, NULL, rtk_listen_fn_, NULL) == 0); - if (!rtk_listen_thread_valid_) - { - HILOGE("%s pthread_create failed: %s", __func__, strerror(errno)); - } - else - { - HILOGD("initialized"); - } -} - -void rtk_btsnoop_net_close() -{ - if (rtk_listen_thread_valid_) - { - shutdown(rtk_listen_socket_, SHUT_RDWR); - pthread_join(rtk_listen_thread_, NULL); - rtk_listen_thread_valid_ = false; - } -} - -void rtk_btsnoop_net_write(serial_data_type_t type, uint8_t *data, bool is_received) -{ - if (rtk_listen_socket_ == -1) - { - return; - } - int length = 0; - uint8_t *p = data; - - switch (type) - { - case HCI_COMMAND_PKT: - if (((rtkbt_h5logfilter & 1) == 0) || (*p != 0x94) || (*(p + 1) != 0xfc)) - length = data[2] + 3; - else - return; - break; - case HCI_ACLDATA_PKT: - length = (data[3] << 8) + data[2] + 4; - break; - case HCI_SCODATA_PKT: - length = data[2] + 3; - break; - case HCI_EVENT_PKT: - if ((*(p + 3) == 0x94) && (*(p + 4) == 0xfc) && (*(p + 5) == 0x00) && (rtkbt_h5logfilter & 1)) - { - return; - } - else - length = data[1] + 2; - break; - default: - break; - } - - uint8_t buffer[4126] = {0}; - // uint8_t test_buffer[] = {0x03, 0x00, 0x00, 0x00, 0x01, 0x01, 0x10, 0x00}; - // uint8_t test_buffer2[] = {0x01, 0x10, 0x00}; - struct sockaddr_in client_addr; - int i = 0; - -#if DATA_DIRECT_2_ELLISY - uint8_t bit_rate[4] = {0x00, 0x1b, 0x37, 0x4b}; - struct tm *t; - time_t tt; - time(&tt); - t = localtime(&tt); - - struct timeval tv; - gettimeofday(&tv, NULL); - - uint64_t nano_time = (t->tm_hour * 3600 + t->tm_min * 60 + t->tm_sec) * 1000 * 1000LL * 1000 + tv.tv_usec * 1000; - uint16_t year = (t->tm_year + 1900) & 0xFFFF; - uint8_t month = (t->tm_mon + 1) & 0xFF; - uint8_t day = - buffer[0] = 0x02; - buffer[1] = 0x00; - buffer[2] = 0x01; - buffer[3] = 0x02; - // time - memcpy(&buffer[4], &year, 2); - buffer[6] = month; - buffer[7] = day; - memcpy(&buffer[8], &nano_time, 6); - // bit rate - buffer[14] = 0x80; - memcpy(&buffer[15], bit_rate, 4); - // type - buffer[19] = 0x81; - i = 20; -#else - memcpy(&buffer[i], &length, sizeof(int)); - i = 4; -#endif - switch (type) - { - case HCI_COMMAND_PKT: - buffer[i] = HCI_COMMAND; - break; - - case HCI_ACLDATA_PKT: - if (is_received) - { - buffer[i] = HCI_ACL_DATA_C2H; - } - else - { - buffer[i] = HCI_ACL_DATA_H2C; - } - break; - - case HCI_SCODATA_PKT: - if (is_received) - { - buffer[i] = HCI_SCO_DATA_C2H; - } - else - { - buffer[i] = HCI_SCO_DATA_H2C; - } - break; - - case HCI_EVENT_PKT: - buffer[i] = HCI_EVENT; - break; - - default: - buffer[i] = 0; - break; - } -#if DATA_DIRECT_2_ELLISY - // buffer[i] = HCI_COMMAND; - buffer[21] = 0x82; - i = 22; -#else - i = 5; -#endif - memcpy(&buffer[i], data, length); - // memcpy(&buffer[i], test_buffer2, 3); - memset(&client_addr, 0, sizeof(client_addr)); - client_addr.sin_family = AF_INET; - client_addr.sin_addr.s_addr = htonl(RTK_REMOTEHOST_); - client_addr.sin_port = htons(RTK_REMOTE_PORT_); - pthread_mutex_lock(&rtk_client_socket_lock_); - int ret; - RTK_NO_INTR(ret = sendto(rtk_listen_socket_, buffer, (length + i), 0, (struct sockaddr *)&client_addr, sizeof(struct sockaddr_in))); - // sendto(rtk_listen_socket_, buffer, 25, 0,(struct sockaddr*)&client_addr, sizeof(struct sockaddr_in)); - pthread_mutex_unlock(&rtk_client_socket_lock_); -} - -static void *rtk_listen_fn_(void *context) -{ - RTK_UNUSED(context); - prctl(PR_SET_NAME, (unsigned long)RTK_LISTEN_THREAD_NAME_, 0, 0, 0); - - rtk_listen_socket_ = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (rtk_listen_socket_ == -1) - { - HILOGE("%s socket creation failed: %s", __func__, strerror(errno)); - goto cleanup; - } - - struct sockaddr_in addr; - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = htonl(RTK_LOCALHOST_); - addr.sin_port = htons(RTK_LISTEN_PORT_); - - struct sockaddr_in client_addr; - memset(&client_addr, 0, sizeof(client_addr)); - client_addr.sin_family = AF_INET; - client_addr.sin_addr.s_addr = htonl(RTK_REMOTEHOST_); - client_addr.sin_port = htons(RTK_REMOTE_PORT_); - - if (bind(rtk_listen_socket_, (struct sockaddr *)&addr, sizeof(addr)) == -1) - { - HILOGE("%s unable to bind listen socket: %s", __func__, strerror(errno)); - goto cleanup; - } - - return NULL; -cleanup: - rtk_safe_close_(&rtk_listen_socket_); - return NULL; -} - -static void rtk_safe_close_(int *fd) -{ - assert(fd != NULL); - if (*fd != -1) - { - close(*fd); - *fd = -1; - } -} diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/rtk_heartbeat.c b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/rtk_heartbeat.c deleted file mode 100755 index ba6d35c4..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/rtk_heartbeat.c +++ /dev/null @@ -1,303 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#define LOG_TAG "rtk_heartbeat" -#define RTKBT_RELEASE_NAME "20190717_BT_ANDROID_9.0" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "bt_hci_bdroid.h" -#include "bt_vendor_rtk.h" -#include "userial.h" -#include "userial_vendor.h" -#include "rtk_btservice.h" -#include "rtk_poll.h" -#include "upio.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "bt_vendor_lib.h" - -#define RTKBT_HEARTBEAT_CONF_FILE "/vendor/etc/bluetooth/rtkbt_heartbeat.conf" - -#define HCI_EVT_HEARTBEAT_STATUS_OFFSET (5) -#define HCI_EVT_HEARTBEAT_SEQNUM_OFFSET_L (6) -#define HCI_EVT_HEARTBEAT_SEQNUM_OFFSET_H (7) - -static const uint32_t DEFALUT_HEARTBEAT_TIMEOUT_MS = 1000; // send a per sercond -int heartBeatLog = -1; -static int heartBeatTimeout = -1; -static bool heartbeatFlag = false; -static int heartbeatCount = 0; -static uint16_t nextSeqNum = 1; -static uint16_t cleanupFlag = 0; -static pthread_mutex_t heartbeat_mutex; - -typedef struct Rtk_Service_Data -{ - uint16_t opcode; - uint8_t parameter_len; - uint8_t *parameter; - void (*complete_cback)(void *); -} Rtk_Service_Data; - -#define HCI_CMD_VNDR_HEARTBEAT 0xFC94 - -extern void Rtk_Service_Vendorcmd_Hook(Rtk_Service_Data *RtkData, int client_sock); -extern uint8_t get_heartbeat_from_hardware(); - -static char *rtk_trim(char *str) -{ - while (isspace(*str)) - ++str; - - if (!*str) - return str; - - char *end_str = str + strlen(str) - 1; - while (end_str > str && isspace(*end_str)) - --end_str; - - end_str[1] = '\0'; - return str; -} - -static void load_rtkbt_heartbeat_conf() -{ - char *split; - FILE *fp = fopen(RTKBT_HEARTBEAT_CONF_FILE, "rt"); - if (!fp) - { - HILOGE("%s unable to open file '%s': %s", __func__, RTKBT_HEARTBEAT_CONF_FILE, strerror(errno)); - return; - } - int line_num = 0; - char line[1024]; - // char value[1024]; - while (fgets(line, sizeof(line), fp)) - { - char *line_ptr = rtk_trim(line); - ++line_num; - - // Skip blank and comment lines. - if (*line_ptr == '\0' || *line_ptr == '#' || *line_ptr == '[') - continue; - - split = strchr(line_ptr, '='); - if (!split) - { - HILOGE("%s no key/value separator found on line %d.", __func__, line_num); - continue; - } - - *split = '\0'; - char *endptr; - if (!strcmp(rtk_trim(line_ptr), "HeartBeatTimeOut")) - { - heartBeatTimeout = strtol(rtk_trim(split + 1), &endptr, 0); - } - else if (!strcmp(rtk_trim(line_ptr), "HeartBeatLog")) - { - heartBeatLog = strtol(rtk_trim(split + 1), &endptr, 0); - } - } - - fclose(fp); -} - -static void rtkbt_heartbeat_send_hw_error(uint8_t status, uint16_t seqnum, uint16_t next_seqnum, int heartbeatCnt) -{ - if (!heartbeatFlag) - return; - unsigned char p_buf[100]; - int length; - p_buf[0] = HCIT_TYPE_EVENT; // event - p_buf[1] = HCI_VSE_SUBCODE_DEBUG_INFO_SUB_EVT; // firmwre event log - p_buf[3] = 0x01; // host log opcode - length = sprintf((char *)&p_buf[4], "host stack: heartbeat hw error: %d:%d:%d:%d", - status, seqnum, next_seqnum, heartbeatCnt); - p_buf[2] = length + 2; // len - length = length + 1 + 4; - userial_recv_rawdata_hook(p_buf, length); - - length = 4; - p_buf[0] = HCIT_TYPE_EVENT; // event - p_buf[1] = HCI_HARDWARE_ERROR_EVT; // hardware error - p_buf[2] = 0x01; // len - p_buf[3] = 0xfc; // heartbeat error code - userial_recv_rawdata_hook(p_buf, length); -} - -static void rtkbt_heartbeat_cmpl_cback(void *p_params) -{ - uint8_t status = 0; - uint16_t seqnum = 0; - HC_BT_HDR *p_evt_buf = p_params; - // uint8_t *p = NULL; - - if (!heartbeatFlag) - return; - - if (p_params != NULL) - { - p_evt_buf = (HC_BT_HDR *)p_params; - status = p_evt_buf->data[HCI_EVT_HEARTBEAT_STATUS_OFFSET]; - seqnum = p_evt_buf->data[HCI_EVT_HEARTBEAT_SEQNUM_OFFSET_H] << 8 | p_evt_buf->data[HCI_EVT_HEARTBEAT_SEQNUM_OFFSET_L]; - } - - if (status == 0 && seqnum == nextSeqNum) - { - nextSeqNum = (seqnum + 1); - pthread_mutex_lock(&heartbeat_mutex); - heartbeatCount = 0; - pthread_mutex_unlock(&heartbeat_mutex); - } - else - { - HILOGE("rtkbt_heartbeat_cmpl_cback: Current SeqNum = %d,should SeqNum=%d, status = %d", seqnum, nextSeqNum, status); - HILOGE("heartbeat event missing: restart bluedroid stack\n"); - usleep(1000); - rtkbt_heartbeat_send_hw_error(status, seqnum, nextSeqNum, heartbeatCount); - } -} - -static void heartbeat_timed_out() //(union sigval arg) -{ - Rtk_Service_Data *p_buf; - int count; - - if (!heartbeatFlag) - return; - pthread_mutex_lock(&heartbeat_mutex); - heartbeatCount++; - if (heartbeatCount >= 3) - { - if (cleanupFlag == 1) - { - HILOGW("Already cleanup, ignore."); - pthread_mutex_unlock(&heartbeat_mutex); - return; - } - HILOGE("heartbeat_timed_out: heartbeatCount = %d, expected nextSeqNum = %d", heartbeatCount, nextSeqNum); - HILOGE("heartbeat_timed_out,controller may be suspend! Now restart bluedroid stack\n"); - count = heartbeatCount; - pthread_mutex_unlock(&heartbeat_mutex); - usleep(1000); - rtkbt_heartbeat_send_hw_error(0, 0, nextSeqNum, count); - - // kill(getpid(), SIGKILL); - return; - } - pthread_mutex_unlock(&heartbeat_mutex); - if (heartbeatFlag) - { - p_buf = (Rtk_Service_Data *)malloc(sizeof(Rtk_Service_Data)); - if (NULL == p_buf) - { - HILOGE("p_buf: allocate error"); - return; - } - p_buf->opcode = HCI_CMD_VNDR_HEARTBEAT; - p_buf->parameter = NULL; - p_buf->parameter_len = 0; - p_buf->complete_cback = rtkbt_heartbeat_cmpl_cback; - - Rtk_Service_Vendorcmd_Hook(p_buf, -1); - free(p_buf); - poll_timer_flush(); - } -} - -static void rtkbt_heartbeat_beginTimer_func(void) -{ - Rtk_Service_Data *p_buf; - - if ((heartBeatTimeout != -1) && (heartBeatLog != -1)) - { - poll_init(heartbeat_timed_out, heartBeatTimeout); - } - else - { - heartBeatLog = 0; - poll_init(heartbeat_timed_out, DEFALUT_HEARTBEAT_TIMEOUT_MS); - } - poll_enable(TRUE); - - p_buf = (Rtk_Service_Data *)malloc(sizeof(Rtk_Service_Data)); - if (NULL == p_buf) - { - HILOGE("p_buf: allocate error"); - return; - } - p_buf->opcode = HCI_CMD_VNDR_HEARTBEAT; - p_buf->parameter = NULL; - p_buf->parameter_len = 0; - p_buf->complete_cback = rtkbt_heartbeat_cmpl_cback; - - Rtk_Service_Vendorcmd_Hook(p_buf, -1); - free(p_buf); - - poll_timer_flush(); -} - -void Heartbeat_cleanup() -{ - if (!heartbeatFlag) - return; - heartbeatFlag = false; - nextSeqNum = 1; - heartbeatCount = 0; - cleanupFlag = 1; - poll_enable(FALSE); - poll_cleanup(); -} - -void Heartbeat_init() -{ - int res; - HILOGD("Heartbeat_init start"); - Heartbeat_cleanup(); - load_rtkbt_heartbeat_conf(); - pthread_mutex_init(&heartbeat_mutex, NULL); - heartbeatFlag = true; - heartbeatCount = 0; - cleanupFlag = 0; - res = get_heartbeat_from_hardware(); - HILOGD("Heartbeat_init res = %x", res); - if (res == 1) - rtkbt_heartbeat_beginTimer_func(); - else - Heartbeat_cleanup(); - HILOGD("Heartbeat_init end"); -} diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/rtk_parse.c b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/rtk_parse.c deleted file mode 100755 index e07cfd2e..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/rtk_parse.c +++ /dev/null @@ -1,3059 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -/****************************************************************************** - * - * Module Name: - * rtk_parse.c - * - * Abstract: - * Contains wifi-bt coex functions implemented by bluedroid stack - * - * Major Change History: - * When Who What - * --------------------------------------------------------------- - * 2015-12-15 lamparten modified - * 2014-10-23 kyle_xu modified - * Notes: - * This is designed for wifi-bt Coex in Android 6.0. - * - ******************************************************************************/ -#define LOG_TAG "rtk_parse" -#define RTKBT_RELEASE_NAME "20190717_BT_ANDROID_9.0" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "bt_list.h" -#include "bt_hci_bdroid.h" -#include "rtk_parse.h" -#include - -#define RTK_COEX_VERSION "3.0" -#define HCI_EVT_CMD_CMPL_OPCODE 3 -#define HCI_CMD_VNDR_HEARTBEAT 0xFC94 - -char invite_req[] = "INVITE_REQ"; -char invite_rsp[] = "INVITE_RSP"; -char attend_req[] = "ATTEND_REQ"; -char attend_ack[] = "ATTEND_ACK"; -char wifi_leave[] = "WIFI_LEAVE"; -char leave_ack[] = "LEAVE_ACK"; -char bt_leave[] = "BT_LEAVE"; - -#define CONNECT_PORT 30001 -#define CONNECT_PORT_WIFI 30000 -//#define NETLINK_USER 31 -#define MAX_PAYLOAD 255 /* maximum payload size*/ - -// L2CAP TYPE -#define L2CAP_CONNECTION_REQ 0x02 -#define L2CAP_CONNECTION_RSP 0x03 -#define L2CAP_DISCONNECTION_REQ 0x06 -#define L2CAP_DISCONNECTION_RSP 0x07 - -#define TIMER_A2DP_PACKET_COUNT (SIGRTMAX - 5) -#define TIMER_PAN_PACKET_COUNT (SIGRTMAX - 6) -#define TIMER_HOGP_PACKET_COUNT (SIGRTMAX - 7) -#define TIMER_POLLING (SIGRTMAX - 8) - -#define PAN_PACKET_COUNT 5 -#define PACKET_COUNT_TIOMEOUT_VALUE 1000 // ms - -// vendor cmd to fw -#define HCI_VENDOR_ENABLE_PROFILE_REPORT_COMMAND (0x0018 | HCI_GRP_VENDOR_SPECIFIC) -#define HCI_VENDOR_SET_PROFILE_REPORT_COMMAND (0x0019 | HCI_GRP_VENDOR_SPECIFIC) -#define HCI_VENDOR_MAILBOX_CMD (0x008F | HCI_GRP_VENDOR_SPECIFIC) - -#define HCI_VENDOR_ADD_BITPOOL_FW (0x0051 | HCI_GRP_VENDOR_SPECIFIC) - -// subcmd to fw for HCI_VENDOR_MAILBOX_CMD -#define HCI_VENDOR_SUB_CMD_WIFI_CHANNEL_AND_BANDWIDTH_CMD 0x11 -#define HCI_VENDOR_SUB_CMD_WIFI_FORCE_TX_POWER_CMD 0x17 -#define HCI_VENDOR_SUB_CMD_BT_ENABLE_IGNORE_WLAN_ACT_CMD 0x1B -#define HCI_VENDOR_SUB_CMD_BT_REPORT_CONN_SCO_INQ_INFO 0x23 -#define HCI_VENDOR_SUB_CMD_BT_AUTO_REPORT_STATUS_INFO 0x27 -#define HCI_VENDOR_SUB_CMD_BT_AUTO_REPORT_ENABLE 0x28 -#define HCI_VENDOR_SUB_CMD_BT_SET_TXRETRY_REPORT_PARAM 0x29 -#define HCI_VENDOR_SUB_CMD_BT_SET_PTATABLE 0x2A -#define HCI_VENDOR_SUB_CMD_SET_BT_PSD_MODE 0x31 -#define HCI_VENDOR_SUB_CMD_SET_BT_LNA_CONSTRAINT 0x32 -#define HCI_VENDOR_SUB_CMD_GET_AFH_MAP_L 0x40 -#define HCI_VENDOR_SUB_CMD_GET_AFH_MAP_M 0x41 -#define HCI_VENDOR_SUB_CMD_GET_AFH_MAP_H 0x42 -#define HCI_VENDOR_SUB_CMD_RD_REG_REQ 0x43 -#define HCI_VENDOR_SUB_CMD_WR_REG_REQ 0x44 - -// sub event from fw -#define HCI_VENDOR_PTA_REPORT_EVENT 0x24 -#define HCI_VENDOR_PTA_AUTO_REPORT_EVENT 0x25 - -// vendor cmd to wifi driver -#define HCI_OP_HCI_EXTENSION_VERSION_NOTIFY (0x0100 | HCI_GRP_VENDOR_SPECIFIC) -#define HCI_OP_BT_OPERATION_NOTIFY (0x0102 | HCI_GRP_VENDOR_SPECIFIC) -#define HCI_OP_HCI_BT_INFO_NOTIFY (0x0106 | HCI_GRP_VENDOR_SPECIFIC) -#define HCI_OP_HCI_BT_COEX_NOTIFY (0x0107 | HCI_GRP_VENDOR_SPECIFIC) -#define HCI_OP_HCI_BT_PATCH_VER_NOTIFY (0x0108 | HCI_GRP_VENDOR_SPECIFIC) -#define HCI_OP_HCI_BT_AFH_MAP_NOTIFY (0x0109 | HCI_GRP_VENDOR_SPECIFIC) -#define HCI_OP_HCI_BT_REGISTER_VALUE_NOTIFY (0x010a | HCI_GRP_VENDOR_SPECIFIC) - -// bt operation to notify for HCI_OP_BT_OPERATION_NOTIFY -#define BT_OPCODE_NONE 0 -#define BT_OPCODE_INQUIRY_START 1 -#define BT_OPCODE_INQUIRY_END 2 -#define BT_OPCODE_PAGE_START 3 -#define BT_OPCODE_PAGE_SUCCESS_END 4 -#define BT_OPCODE_PAGE_UNSUCCESS_END 5 -#define BT_OPCODE_PAIR_START 6 -#define BT_OPCODE_PAIR_END 7 -#define BT_OPCODE_ENABLE_BT 8 -#define BT_OPCODE_DISABLE_BT 9 - -// bt info reason to wifi for HCI_OP_HCI_BT_INFO_NOTIFY -#define HOST_RESPONSE 0 // Host response when receive the BT Info Control Event -#define POLLING_RESPONSE 1 // The BT Info response for polling by BT firmware. -#define AUTO_REPORT 2 // BT auto report by BT firmware. -#define STACK_REPORT_WHILE_DEVICE_D2 3 // Stack report when BT firmware is under power save state(ex:D2) - -// vendor event from wifi -#define RTK_HS_EXTENSION_EVENT_WIFI_SCAN 0x01 -#define RTK_HS_EXTENSION_EVENT_RADIO_STATUS_NOTIFY 0x02 -#define RTK_HS_EXTENSION_EVENT_HCI_BT_INFO_CONTROL 0x03 -#define RTK_HS_EXTENSION_EVENT_HCI_BT_COEX_CONTROL 0x04 - -// op code from wifi for RTK_HS_EXTENSION_EVENT_HCI_BT_COEX_CONTROL -#define BT_PATCH_VERSION_QUERY 0x00 -#define IGNORE_WLAN_ACTIVE_CONTROL 0x01 -#define LNA_CONSTRAIN_CONTROL 0x02 -#define BT_POWER_DECREASE_CONTROL 0x03 -#define BT_PSD_MODE_CONTROL 0x04 -#define WIFI_BW_CHNL_NOTIFY 0x05 -#define QUERY_BT_AFH_MAP 0x06 -#define BT_REGISTER_ACCESS 0x07 - -#define HCI_EXTENSION_VERSION 0x0004 - -//#define HCI_CMD_PREAMBLE_SIZE 3 - -#define PSM_SDP 0x0001 -#define PSM_RFCOMM 0x0003 -#define PSM_PAN 0x000F -#define PSM_HID 0x0011 -#define PSM_HID_INT 0x0013 -#define PSM_AVCTP 0x0017 -#define PSM_AVDTP 0x0019 -#define PSM_FTP 0x1001 -#define PSM_BIP 0x1003 -#define PSM_OPP 0x1015 -//--Add more if needed--// - -enum -{ - profile_sco = 0, - profile_hid = 1, - profile_a2dp = 2, - profile_pan = 3, - profile_hid_interval = 4, - profile_hogp = 5, - profile_voice = 6, - profile_sink = 7, - profile_max = 8 -}; -typedef void (*tINT_CMD_CBACK)(void *p_mem); -typedef struct RTK_COEX_INFO -{ - RT_LIST_ENTRY list; - HC_BT_HDR *p_buf; - uint16_t opcode; - tINT_CMD_CBACK p_cback; -} tRTK_COEX_INFO; - -// profile info data -typedef struct RTK_PROF_INFO -{ - RT_LIST_ENTRY list; - uint16_t handle; - uint16_t psm; - uint16_t dcid; - uint16_t scid; - uint8_t profile_index; -} tRTK_PROF_INFO; - -// profile info for each connection -typedef struct RTK_CONN_PROF -{ - RT_LIST_ENTRY list; - uint16_t handle; - uint8_t type; // 0:l2cap, 1:sco/esco, 2:le - uint8_t profile_bitmap; // 0:SCO, 1:HID, 2:A2DP, 3:FTP/PAN/OPP, 4: HID_interval, 5:HOGP, 6:VOICE - int8_t profile_refcount[8]; // 0:SCO, 1:HID, 2:A2DP, 3:FTP/PAN/OPP, 4:TBD, 5:HOGP, 6:VOICE -} tRTK_CONN_PROF; - -// profile info for all -typedef struct RTK_PROF -{ - RT_LIST_HEAD conn_hash; // hash for connections - RT_LIST_HEAD profile_list; // hash for profile info - RT_LIST_HEAD coex_list; - tINT_CMD_CBACK current_cback; - pthread_mutex_t profile_mutex; - pthread_mutex_t coex_mutex; - pthread_mutex_t btwifi_mutex; - pthread_t thread_monitor; - pthread_t thread_data; - timer_t timer_a2dp_packet_count; - timer_t timer_pan_packet_count; - timer_t timer_hogp_packet_count; - timer_t timer_polling; - // struct sockaddr_nl src_addr; //for netlink - struct sockaddr_in server_addr; // server addr for kernel socket - struct sockaddr_in client_addr; // client addr for kernel socket - uint32_t a2dp_packet_count; - uint32_t pan_packet_count; - uint32_t hogp_packet_count; - uint32_t voice_packet_count; - uint8_t profile_bitmap; - uint8_t profile_status; - int8_t profile_refcount[8]; - uint8_t ispairing; - uint8_t isinquirying; - uint8_t ispaging; - uint8_t wifi_state; - uint8_t autoreport; - uint8_t polling_enable; - uint8_t polling_interval; - volatile uint8_t coex_recv_thread_running; - // int32_t nlsocket; - int32_t btcoex_chr; - int32_t udpsocket; - uint8_t piconet_id; - uint8_t mode; - uint8_t afh_map[10]; - uint16_t hci_reversion; - uint16_t lmp_subversion; - uint8_t wifi_on; - uint8_t bt_on; - // uint8_t le_profile_index; -} tRTK_PROF; - -typedef struct HCI_RETURN_PARAMETER_MAILBOX_REGISTER -{ - uint8_t type; - uint32_t offset; - uint32_t value; -} tHCI_RETURN_PARAMETER_MAILBOX_REGISTER; - -typedef struct HCI_EVENT_BT_INFO_CONTROL -{ - uint8_t polling_enable; - uint8_t polling_time; - uint8_t autoreport_enable; -} tHCI_EVENT_BT_INFO_CONTROL; - -tRTK_PROF rtk_prof; -volatile int poweroff_allowed = 0; -uint8_t coex_log_enable = 0; -static volatile bool coex_cmd_send = false; - -#define BIT(_I) (uint16_t)(1 << (_I)) -#define is_profile_connected(profile) ((rtk_prof.profile_bitmap & BIT(profile)) > 0) -#define is_profile_busy(profile) ((rtk_prof.profile_status & BIT(profile)) > 0) - -static void timeout_handler(int signo, siginfo_t *info, void *context); -static void notify_func(union sigval sig); - -static int coex_msg_send(char *tx_msg, int msg_size); -static int coex_msg_recv(uint8_t *recv_msg, uint8_t *msg_size); - -#ifndef RTK_PARSE_LOG_BUF_SIZE -#define RTK_PARSE_LOG_BUF_SIZE 1024 -#endif -#define RTK_PARSE_LOG_MAX_SIZE (RTK_PARSE_LOG_BUF_SIZE - 12) - -#define LOGI0(t, s) -static void RtkLogMsg(const char *fmt_str, ...) -{ - static char buffer[RTK_PARSE_LOG_BUF_SIZE]; - if (coex_log_enable) - { - va_list ap; - va_start(ap, fmt_str); - vsnprintf(&buffer[0], RTK_PARSE_LOG_MAX_SIZE, fmt_str, ap); - va_end(ap); - - LOGI0("rtk_parse: ", buffer); - } - else - { - return; - } -} - -static const char sample_freqs[4][8] = { - "16", "32", "44.1", "48"}; - -static const uint8_t sbc_blocks[4] = {4, 8, 12, 16}; - -static const char chan_modes[4][16] = { - "MONO", "DUAL_CHANNEL", "STEREO", "JOINT_STEREO"}; - -static const char alloc_methods[2][12] = { - "LOUDNESS", "SNR"}; - -static const uint8_t subbands[2] = {4, 8}; - -void print_sbc_header(struct sbc_frame_hdr *hdr) -{ - RtkLogMsg("syncword: %02x", hdr->syncword); - RtkLogMsg("freq %skHz", sample_freqs[hdr->sampling_frequency]); - RtkLogMsg("blocks %u", sbc_blocks[hdr->blocks]); - RtkLogMsg("channel mode %s", chan_modes[hdr->channel_mode]); - RtkLogMsg("allocation method %s", alloc_methods[hdr->allocation_method]); - RtkLogMsg("subbands %u", subbands[hdr->subbands]); -} - -static timer_t OsAllocateTimer(int signo) -{ - struct sigevent sigev; - timer_t timerid = (timer_t)-1; - - // Create the POSIX timer to generate signo - // sigev.sigev_notify = SIGEV_THREAD_ID; - // sigev.sigev_notify_thread_id = syscall(__NR_gettid); - // sigev.sigev_signo = signo; - // sigev.sigev_value.sival_ptr = &timerid; - - memset(&sigev, 0, sizeof(sigev)); - sigev.sigev_notify = SIGEV_THREAD; - sigev.sigev_notify_function = notify_func; - sigev.sigev_value.sival_int = signo; - - // HILOGE("OsAllocateTimer rtk_parse sigev.sigev_notify_thread_id = syscall(__NR_gettid)!"); - - // Create the Timer using timer_create signal - if (timer_create(CLOCK_REALTIME, &sigev, &timerid) == 0) - { - return timerid; - } - else - { - HILOGE("timer_create error!"); - return (timer_t)-1; - } -} - -static int OsFreeTimer(timer_t timerid) -{ - int ret = 0; - ret = timer_delete(timerid); - if (ret != 0) - HILOGE("timer_delete fail with errno(%d)", errno); - - return ret; -} - -static int OsStartTimer(timer_t timerid, int msec, int mode) -{ - struct itimerspec itval; - - itval.it_value.tv_sec = msec / 1000; - itval.it_value.tv_nsec = (long)(msec % 1000) * (1000000L); - - if (mode == 1) - { - itval.it_interval.tv_sec = itval.it_value.tv_sec; - itval.it_interval.tv_nsec = itval.it_value.tv_nsec; - } - else - { - itval.it_interval.tv_sec = 0; - itval.it_interval.tv_nsec = 0; - } - - // Set the Timer when to expire through timer_settime - if (timer_settime(timerid, 0, &itval, NULL) != 0) - { - HILOGE("time_settime error!"); - return -1; - } - - return 0; -} - -static int OsStopTimer(timer_t timerid) -{ - return OsStartTimer(timerid, 0, 0); -} - -int alloc_polling_timer() -{ - /* - struct sigaction sigact; - - sigemptyset(&sigact.sa_mask); - sigact.sa_flags = SA_SIGINFO; - - //register the Signal Handler - sigact.sa_sigaction = timeout_handler; - - // Set up sigaction to catch signal first timer - if (sigaction(TIMER_POLLING, &sigact, NULL) == -1) - { - HILOGE("alloc_polling_timer, sigaction failed"); - return -1; - } - */ - // Create and set the timer when to expire - rtk_prof.timer_polling = OsAllocateTimer(TIMER_POLLING); - RtkLogMsg("alloc polling timer"); - - return 0; -} - -int free_polling_timer() -{ - return OsFreeTimer(rtk_prof.timer_polling); -} - -int stop_polling_timer() -{ - RtkLogMsg("stop polling timer"); - return OsStopTimer(rtk_prof.timer_polling); -} - -int start_polling_timer(int value) -{ - RtkLogMsg("start polling timer"); - return OsStartTimer(rtk_prof.timer_polling, value, 1); -} - -int alloc_hogp_packet_count_timer() -{ - /* - struct sigaction sigact; - - sigemptyset(&sigact.sa_mask); - sigact.sa_flags = SA_SIGINFO; - - //register the Signal Handler - sigact.sa_sigaction = timeout_handler; - - // Set up sigaction to catch signal first timer - if (sigaction(TIMER_HOGP_PACKET_COUNT, &sigact, NULL) == -1) - { - HILOGE("alloc_hogp_packet_count_timer, sigaction failed"); - return -1; - } - */ - // Create and set the timer when to expire - rtk_prof.timer_hogp_packet_count = OsAllocateTimer(TIMER_HOGP_PACKET_COUNT); - RtkLogMsg("alloc hogp packet"); - - return 0; -} - -int free_hogp_packet_count_timer() -{ - return OsFreeTimer(rtk_prof.timer_hogp_packet_count); -} - -int stop_hogp_packet_count_timer() -{ - RtkLogMsg("stop hogp packet"); - return OsStopTimer(rtk_prof.timer_hogp_packet_count); -} - -int start_hogp_packet_count_timer() -{ - RtkLogMsg("start hogp packet"); - return OsStartTimer(rtk_prof.timer_hogp_packet_count, PACKET_COUNT_TIOMEOUT_VALUE, 1); -} - -int alloc_a2dp_packet_count_timer() -{ - /* - struct sigaction sigact; - - sigemptyset(&sigact.sa_mask); - sigact.sa_flags = SA_SIGINFO; - - //register the Signal Handler - sigact.sa_sigaction = timeout_handler; - - // Set up sigaction to catch signal first timer - if (sigaction(TIMER_A2DP_PACKET_COUNT, &sigact, NULL) == -1) - { - HILOGE("alloc_a2dp_packet_count_timer, sigaction failed"); - return -1; - } - */ - // Create and set the timer when to expire - rtk_prof.timer_a2dp_packet_count = OsAllocateTimer(TIMER_A2DP_PACKET_COUNT); - RtkLogMsg("alloc a2dp packet"); - - return 0; -} - -int free_a2dp_packet_count_timer() -{ - return OsFreeTimer(rtk_prof.timer_a2dp_packet_count); -} - -int stop_a2dp_packet_count_timer() -{ - RtkLogMsg("stop a2dp packet"); - return OsStopTimer(rtk_prof.timer_a2dp_packet_count); -} - -int start_a2dp_packet_count_timer() -{ - RtkLogMsg("start a2dp packet"); - return OsStartTimer(rtk_prof.timer_a2dp_packet_count, PACKET_COUNT_TIOMEOUT_VALUE, 1); -} - -int alloc_pan_packet_count_timer() -{ - /* - struct sigaction sigact; - - sigemptyset(&sigact.sa_mask); - sigact.sa_flags = SA_SIGINFO; - - //register the Signal Handler - sigact.sa_sigaction = timeout_handler; - - // Set up sigaction to catch signal first timer - if (sigaction(TIMER_PAN_PACKET_COUNT, &sigact, NULL) == -1) - { - HILOGE("alloc_pan_packet_count_timer, sigaction failed"); - return -1; - } - */ - // Create and set the timer when to expire - rtk_prof.timer_pan_packet_count = OsAllocateTimer(TIMER_PAN_PACKET_COUNT); - - RtkLogMsg("alloc pan packet"); - return 0; -} - -int free_pan_packet_count_timer() -{ - return OsFreeTimer(rtk_prof.timer_pan_packet_count); -} - -int stop_pan_packet_count_timer() -{ - RtkLogMsg("stop pan packet"); - return OsStopTimer(rtk_prof.timer_pan_packet_count); -} - -int start_pan_packet_count_timer() -{ - RtkLogMsg("start pan packet"); - return OsStartTimer(rtk_prof.timer_pan_packet_count, PACKET_COUNT_TIOMEOUT_VALUE, 1); -} - -static int8_t psm_to_profile_index(uint16_t psm) -{ - switch (psm) - { - case PSM_AVCTP: - case PSM_SDP: - return -1; // ignore - - case PSM_HID: - case PSM_HID_INT: - return profile_hid; - - case PSM_AVDTP: - return profile_a2dp; - - case PSM_PAN: - case PSM_OPP: - case PSM_FTP: - case PSM_BIP: - case PSM_RFCOMM: - return profile_pan; - - default: - return profile_pan; - } -} - -tRTK_CONN_PROF *find_connection_by_handle(tRTK_PROF *h5, uint16_t handle) -{ - RT_LIST_HEAD *head = &h5->conn_hash; - RT_LIST_ENTRY *iter = NULL, *temp = NULL; - tRTK_CONN_PROF *desc = NULL; - - LIST_FOR_EACH_SAFELY(iter, temp, head) - { - desc = LIST_ENTRY(iter, tRTK_CONN_PROF, list); - if ((handle & 0xEFF) == desc->handle) // only last 12 bit are meanful for hci handle - { - return desc; - } - } - return NULL; -} - -tRTK_CONN_PROF *allocate_connection_by_handle(uint16_t handle) -{ - tRTK_CONN_PROF *phci_conn = NULL; - phci_conn = malloc(sizeof(tRTK_CONN_PROF)); - if (phci_conn) - phci_conn->handle = handle; - - return phci_conn; -} - -void init_connection_hash(tRTK_PROF *h5) -{ - RT_LIST_HEAD *head = &h5->conn_hash; - ListInitializeHeader(head); -} - -void add_connection_to_hash(tRTK_PROF *h5, tRTK_CONN_PROF *desc) -{ - RT_LIST_HEAD *head = &h5->conn_hash; - ListAddToTail(&desc->list, head); -} - -void delete_connection_from_hash(tRTK_CONN_PROF *desc) -{ - if (desc) - { - ListDeleteNode(&desc->list); - free(desc); - } -} - -void flush_connection_hash(tRTK_PROF *h5) -{ - RT_LIST_HEAD *head = &h5->conn_hash; - RT_LIST_ENTRY *iter = NULL, *temp = NULL; - tRTK_CONN_PROF *desc = NULL; - - LIST_FOR_EACH_SAFELY(iter, temp, head) - { - desc = LIST_ENTRY(iter, tRTK_CONN_PROF, list); - if (desc) - { - ListDeleteNode(&desc->list); - free(desc); - } - } - // ListInitializeHeader(head); -} - -void init_profile_hash(tRTK_PROF *h5) -{ - RT_LIST_HEAD *head = &h5->profile_list; - ListInitializeHeader(head); -} - -uint8_t list_allocate_add(uint16_t handle, uint16_t psm, int8_t profile_index, uint16_t dcid, uint16_t scid) -{ - tRTK_PROF_INFO *pprof_info = NULL; - - if (profile_index < 0) - { - HILOGE("PSM(0x%x) do not need parse", psm); - return FALSE; - } - - pprof_info = malloc(sizeof(tRTK_PROF_INFO)); - if (NULL == pprof_info) - { - HILOGE("list_allocate_add: allocate error"); - return FALSE; - } - - pprof_info->handle = handle; - pprof_info->psm = psm; - pprof_info->scid = scid; - pprof_info->dcid = dcid; - pprof_info->profile_index = profile_index; - - ListAddToTail(&(pprof_info->list), &(rtk_prof.profile_list)); - - return TRUE; -} - -void delete_profile_from_hash(tRTK_PROF_INFO *desc) -{ - // RtkLogMsg("delete profile for handle: %x, psm:%x, dcid:%x, scid:%x", desc->handle, desc->psm, desc->dcid, desc->scid); - if (desc) - { - ListDeleteNode(&desc->list); - free(desc); - desc = NULL; - } -} - -void flush_profile_hash(tRTK_PROF *h5) -{ - RT_LIST_HEAD *head = &h5->profile_list; - RT_LIST_ENTRY *iter = NULL, *temp = NULL; - tRTK_PROF_INFO *desc = NULL; - - pthread_mutex_lock(&rtk_prof.profile_mutex); - LIST_FOR_EACH_SAFELY(iter, temp, head) - { - desc = LIST_ENTRY(iter, tRTK_PROF_INFO, list); - delete_profile_from_hash(desc); - } - // ListInitializeHeader(head); - pthread_mutex_unlock(&rtk_prof.profile_mutex); -} - -tRTK_PROF_INFO *find_profile_by_handle_scid(tRTK_PROF *h5, uint16_t handle, uint16_t scid) -{ - RT_LIST_HEAD *head = &h5->profile_list; - RT_LIST_ENTRY *iter = NULL, *temp = NULL; - tRTK_PROF_INFO *desc = NULL; - - LIST_FOR_EACH_SAFELY(iter, temp, head) - { - desc = LIST_ENTRY(iter, tRTK_PROF_INFO, list); - if (((handle & 0xFFF) == desc->handle) && (scid == desc->scid)) - { - return desc; - } - } - return NULL; -} - -tRTK_PROF_INFO *find_profile_by_handle_dcid(tRTK_PROF *h5, uint16_t handle, uint16_t dcid) -{ - RT_LIST_HEAD *head = &h5->profile_list; - RT_LIST_ENTRY *iter = NULL, *temp = NULL; - tRTK_PROF_INFO *desc = NULL; - - LIST_FOR_EACH_SAFELY(iter, temp, head) - { - desc = LIST_ENTRY(iter, tRTK_PROF_INFO, list); - if (((handle & 0xFFF) == desc->handle) && (dcid == desc->dcid)) - { - return desc; - } - } - return NULL; -} - -tRTK_PROF_INFO *find_profile_by_handle_dcid_scid(tRTK_PROF *h5, uint16_t handle, uint16_t dcid, uint16_t scid) -{ - RT_LIST_HEAD *head = &h5->profile_list; - RT_LIST_ENTRY *iter = NULL, *temp = NULL; - tRTK_PROF_INFO *desc = NULL; - - LIST_FOR_EACH_SAFELY(iter, temp, head) - { - desc = LIST_ENTRY(iter, tRTK_PROF_INFO, list); - if (((handle & 0xFFF) == desc->handle) && (dcid == desc->dcid) && (scid == desc->scid)) - { - return desc; - } - } - return NULL; -} - -void init_coex_hash(tRTK_PROF *h5) -{ - RT_LIST_HEAD *head = &h5->coex_list; - ListInitializeHeader(head); -} - -void delete_coex_from_hash(tRTK_COEX_INFO *desc) -{ - if (desc) - { - ListDeleteNode(&desc->list); - free(desc); - desc = NULL; - } -} - -void flush_coex_hash(tRTK_PROF *h5) -{ - RT_LIST_HEAD *head = &h5->coex_list; - RT_LIST_ENTRY *iter = NULL, *temp = NULL; - tRTK_COEX_INFO *desc = NULL; - - pthread_mutex_lock(&rtk_prof.coex_mutex); - LIST_FOR_EACH_SAFELY(iter, temp, head) - { - desc = LIST_ENTRY(iter, tRTK_COEX_INFO, list); - delete_coex_from_hash(desc); - } - // ListInitializeHeader(head); - pthread_mutex_unlock(&rtk_prof.coex_mutex); -} - -static void rtk_cmd_complete_cback(void *p_mem) -{ - pthread_mutex_lock(&rtk_prof.coex_mutex); - RT_LIST_ENTRY *iter = ListGetTop(&(rtk_prof.coex_list)); - tRTK_COEX_INFO *desc = NULL; - if (iter) - { - desc = LIST_ENTRY(iter, tRTK_COEX_INFO, list); - if (desc) - { - ListDeleteNode(&desc->list); - } - } - else - { - coex_cmd_send = false; - } - pthread_mutex_unlock(&rtk_prof.coex_mutex); - - if (rtk_prof.current_cback) - { - rtk_prof.current_cback(p_mem); - rtk_prof.current_cback = NULL; - } - - if (desc) - { - HILOGE("%s, transmit_command Opcode:%x", __func__, desc->opcode); - rtk_prof.current_cback = desc->p_cback; - bt_vendor_cbacks->xmit_cb(desc->opcode, desc->p_buf); - } - - free(desc); - return; -} - -void rtk_vendor_cmd_to_fw(uint16_t opcode, uint8_t parameter_len, uint8_t *parameter, tINT_CMD_CBACK p_cback) -{ - HC_BT_HDR *p_buf = NULL; - - if (!rtk_prof.bt_on) - return; - - if (bt_vendor_cbacks) - p_buf = (HC_BT_HDR *)bt_vendor_cbacks->alloc(BT_HC_HDR_SIZE + HCI_CMD_PREAMBLE_SIZE + parameter_len); - - if (NULL == p_buf) - { - HILOGE("rtk_vendor_cmd_to_fw: HC_BT_HDR alloc error"); - return; - } - memset(p_buf, 0, (BT_HC_HDR_SIZE + HCI_CMD_PREAMBLE_SIZE + parameter_len)); - p_buf->event = MSG_STACK_TO_HC_HCI_CMD; - p_buf->offset = 0; - p_buf->len = HCI_CMD_PREAMBLE_SIZE + parameter_len; - p_buf->layer_specific = 0; - - uint8_t *p = (uint8_t *)(p_buf + 1); - UINT16_TO_STREAM(p, opcode); - *p++ = parameter_len; - RtkLogMsg("rtk_vendor_cmd_to_fw: Opcode:%x, parameter_len = %d", opcode, parameter_len); - - if (parameter_len > 0) - { - memcpy(p, parameter, parameter_len); - } - if (bt_vendor_cbacks) - { - pthread_mutex_lock(&rtk_prof.coex_mutex); - if (!coex_cmd_send) - { - coex_cmd_send = true; - RtkLogMsg("begin transmit_command Opcode:%x", opcode); - pthread_mutex_unlock(&rtk_prof.coex_mutex); - rtk_prof.current_cback = p_cback; - bt_vendor_cbacks->xmit_cb(opcode, p_buf); - } - else - { - tRTK_COEX_INFO *pcoex_info = NULL; - pcoex_info = malloc(sizeof(tRTK_COEX_INFO)); - if (NULL == pcoex_info) - { - HILOGE("rtk_vendor_cmd_to_fw: allocate error"); - pthread_mutex_unlock(&rtk_prof.coex_mutex); - return; - } - - pcoex_info->p_buf = p_buf; - pcoex_info->opcode = opcode; - pcoex_info->p_cback = p_cback; - - ListAddToTail(&(pcoex_info->list), &(rtk_prof.coex_list)); - pthread_mutex_unlock(&rtk_prof.coex_mutex); - } - } - return; -} - -void rtk_notify_profileinfo_to_fw() -{ - RT_LIST_HEAD *head = NULL; - RT_LIST_ENTRY *iter = NULL, *temp = NULL; - tRTK_CONN_PROF *hci_conn = NULL; - uint8_t handle_number = 0; - uint32_t buffer_size = 0; - uint8_t *p_buf = NULL; - - head = &rtk_prof.conn_hash; - LIST_FOR_EACH_SAFELY(iter, temp, head) - { - hci_conn = LIST_ENTRY(iter, tRTK_CONN_PROF, list); - if (hci_conn && hci_conn->profile_bitmap) - handle_number++; - } - - buffer_size = 1 + handle_number * 3 + 1; - - p_buf = (uint8_t *)malloc(buffer_size); - - if (NULL == p_buf) - { - HILOGE("rtk_notify_profileinfo_to_fw: alloc error"); - return; - } - uint8_t *p = (uint8_t *)p_buf; - - RtkLogMsg("rtk_notify_profileinfo_to_fw, BufferSize is %x", buffer_size); - *p++ = handle_number; - RtkLogMsg("rtk_notify_profileinfo_to_fw, NumberOfHandles is %x", handle_number); - head = &rtk_prof.conn_hash; - LIST_FOR_EACH_SAFELY(iter, temp, head) - { - hci_conn = LIST_ENTRY(iter, tRTK_CONN_PROF, list); - if (hci_conn && hci_conn->profile_bitmap) - { - UINT16_TO_STREAM(p, hci_conn->handle); - RtkLogMsg("rtk_notify_profileinfo_to_fw, handle is %x", hci_conn->handle); - *p++ = hci_conn->profile_bitmap; - RtkLogMsg("rtk_notify_profileinfo_to_fw, profile_bitmap is %x", hci_conn->profile_bitmap); - handle_number--; - } - if (0 == handle_number) - break; - } - - *p++ = rtk_prof.profile_status; - RtkLogMsg("rtk_notify_profileinfo_to_fw, profile_status is %x", rtk_prof.profile_status); - - rtk_vendor_cmd_to_fw(HCI_VENDOR_SET_PROFILE_REPORT_COMMAND, buffer_size, p_buf, NULL); - - free(p_buf); - - return; -} - -void update_profile_state(uint8_t profile_index, uint8_t is_busy) -{ - uint8_t need_update = FALSE; - - if ((rtk_prof.profile_bitmap & BIT(profile_index)) == 0) - { - HILOGE("update_profile_state: ERROR!!! profile(Index: %x) does not exist", profile_index); - return; - } - - if (is_busy) - { - if ((rtk_prof.profile_status & BIT(profile_index)) == 0) - { - need_update = TRUE; - rtk_prof.profile_status |= BIT(profile_index); - } - } - else - { - if ((rtk_prof.profile_status & BIT(profile_index)) > 0) - { - need_update = TRUE; - rtk_prof.profile_status &= ~(BIT(profile_index)); - } - } - - if (need_update) - { - RtkLogMsg("update_profile_state, rtk_prof.profie_bitmap = %x", rtk_prof.profile_bitmap); - RtkLogMsg("update_profile_state, rtk_prof.profile_status = %x", rtk_prof.profile_status); - rtk_notify_profileinfo_to_fw(); - } -} - -void rtk_check_setup_timer(int8_t profile_index) -{ - if (profile_index == profile_a2dp) - { - rtk_prof.a2dp_packet_count = 0; - start_a2dp_packet_count_timer(); - } - if (profile_index == profile_pan) - { - rtk_prof.pan_packet_count = 0; - start_pan_packet_count_timer(); - } - // hogp & voice share one timer now - if ((profile_index == profile_hogp) || (profile_index == profile_voice)) - { - if ((0 == rtk_prof.profile_refcount[profile_hogp]) && (0 == rtk_prof.profile_refcount[profile_voice])) - { - rtk_prof.hogp_packet_count = 0; - rtk_prof.voice_packet_count = 0; - start_hogp_packet_count_timer(); - } - } -} - -void rtk_check_del_timer(int8_t profile_index) -{ - if (profile_a2dp == profile_index) - { - rtk_prof.a2dp_packet_count = 0; - stop_a2dp_packet_count_timer(); - } - if (profile_pan == profile_index) - { - rtk_prof.pan_packet_count = 0; - stop_pan_packet_count_timer(); - } - if (profile_hogp == profile_index) - { - rtk_prof.hogp_packet_count = 0; - if (rtk_prof.profile_refcount[profile_voice] == 0) - stop_hogp_packet_count_timer(); - } - if (profile_voice == profile_index) - { - rtk_prof.voice_packet_count = 0; - if (rtk_prof.profile_refcount[profile_hogp] == 0) - stop_hogp_packet_count_timer(); - } -} -void update_profile_connection(tRTK_CONN_PROF *phci_conn, int8_t profile_index, uint8_t is_add) -{ - uint8_t need_update = FALSE; - int kk = 0; - - RtkLogMsg("update_profile_connection: is_add=%d, psm_index=%d", is_add, profile_index); - if (profile_index < 0) - return; - - if (is_add) - { - if (rtk_prof.profile_refcount[profile_index] == 0) - { - need_update = TRUE; - rtk_prof.profile_bitmap |= BIT(profile_index); - - // SCO is always busy - if (profile_index == profile_sco) - rtk_prof.profile_status |= BIT(profile_index); - - rtk_check_setup_timer(profile_index); - } - rtk_prof.profile_refcount[profile_index]++; - - if (0 == phci_conn->profile_refcount[profile_index]) - { - need_update = TRUE; - phci_conn->profile_bitmap |= BIT(profile_index); - } - phci_conn->profile_refcount[profile_index]++; - } - else - { - rtk_prof.profile_refcount[profile_index]--; - RtkLogMsg("for test: --, rtk_prof.profile_refcount[%x] = %x", profile_index, rtk_prof.profile_refcount[profile_index]); - if (rtk_prof.profile_refcount[profile_index] == 0) - { - need_update = TRUE; - rtk_prof.profile_bitmap &= ~(BIT(profile_index)); - - // If profile does not exist, Status is meaningless - rtk_prof.profile_status &= ~(BIT(profile_index)); - rtk_check_del_timer(profile_index); - } - - phci_conn->profile_refcount[profile_index]--; - if (0 == phci_conn->profile_refcount[profile_index]) - { - need_update = TRUE; - phci_conn->profile_bitmap &= ~(BIT(profile_index)); - - // clear profile_hid_interval if need - if (profile_hid == profile_index) - { - if ((phci_conn->profile_bitmap & (BIT(profile_hid_interval)))) - { - phci_conn->profile_bitmap &= ~(BIT(profile_hid_interval)); - rtk_prof.profile_refcount[profile_hid_interval]--; - } - } - } - } - - if (need_update) - { - RtkLogMsg("update_profile_connection: rtk_h5.profile_bitmap = %x", rtk_prof.profile_bitmap); - for (kk = 0; kk < 8; kk++) - RtkLogMsg("update_profile_connection: rtk_h5.profile_refcount[%d] = %d", kk, rtk_prof.profile_refcount[kk]); - rtk_notify_profileinfo_to_fw(); - } -} - -void update_hid_active_state(uint16_t handle, uint16_t interval) -{ - uint8_t need_update = 0; - RtkLogMsg("update_hid_active_state: handle = %x, interval = 0x%x", handle, interval); - tRTK_CONN_PROF *phci_conn = find_connection_by_handle(&rtk_prof, handle); - - if (phci_conn == NULL) - return; - - if (((phci_conn->profile_bitmap) & (BIT(profile_hid))) == 0) - { - RtkLogMsg("hid not connected in the handle, nothing to be down"); - return; - } - - if (interval < 60) - { - if ((phci_conn->profile_bitmap & (BIT(profile_hid_interval))) == 0) - { - need_update = 1; - phci_conn->profile_bitmap |= BIT(profile_hid_interval); - - rtk_prof.profile_refcount[profile_hid_interval]++; - if (rtk_prof.profile_refcount[profile_hid_interval] == 1) - rtk_prof.profile_status |= BIT(profile_hid); - } - } - else - { - if ((phci_conn->profile_bitmap & (BIT(profile_hid_interval)))) - { - need_update = 1; - phci_conn->profile_bitmap &= ~(BIT(profile_hid_interval)); - - rtk_prof.profile_refcount[profile_hid_interval]--; - if (rtk_prof.profile_refcount[profile_hid_interval] == 0) - rtk_prof.profile_status &= ~(BIT(profile_hid)); - } - } - - if (need_update) - rtk_notify_profileinfo_to_fw(); -} -uint8_t handle_l2cap_con_req(uint16_t handle, uint16_t psm, uint16_t scid, uint8_t direction) -{ - uint8_t status = FALSE; - tRTK_PROF_INFO *prof_info = NULL; - - int8_t profile_index = psm_to_profile_index(psm); - - if (profile_index < 0) - { - RtkLogMsg("PSM(0x%x) do not need parse", psm); - return status; - } - - pthread_mutex_lock(&rtk_prof.profile_mutex); - if (direction) // 1: out - prof_info = find_profile_by_handle_scid(&rtk_prof, handle, scid); - else // 0:in - prof_info = find_profile_by_handle_dcid(&rtk_prof, handle, scid); - - if (prof_info) - { - RtkLogMsg("handle_l2cap_con_req: This profile is already exist!!!"); - pthread_mutex_unlock(&rtk_prof.profile_mutex); - return status; - } - - if (direction) // 1: out - status = list_allocate_add(handle, psm, profile_index, 0, scid); - else // 0:in - status = list_allocate_add(handle, psm, profile_index, scid, 0); - - pthread_mutex_unlock(&rtk_prof.profile_mutex); - - if (!status) - HILOGE("handle_l2cap_con_req: list_allocate_add failed!"); - - return status; -} - -uint8_t handle_l2cap_con_rsp(uint16_t handle, uint16_t dcid, uint16_t scid, uint8_t direction, uint8_t result) -{ - tRTK_PROF_INFO *prof_info = NULL; - - pthread_mutex_lock(&rtk_prof.profile_mutex); - if (!direction) // 0, in - prof_info = find_profile_by_handle_scid(&rtk_prof, handle, scid); - else // 1, out - prof_info = find_profile_by_handle_dcid(&rtk_prof, handle, scid); - - if (!prof_info) - { - // RtkLogMsg("handle_l2cap_con_rsp: prof_info Not Find!!"); - pthread_mutex_unlock(&rtk_prof.profile_mutex); - return 0; - } - - if (!result) // success - { - RtkLogMsg("l2cap connection success, update connection"); - if (!direction) // 0, in - prof_info->dcid = dcid; - else // 1, out - prof_info->scid = dcid; - - tRTK_CONN_PROF *phci_conn = find_connection_by_handle(&rtk_prof, handle); - if (phci_conn) - update_profile_connection(phci_conn, prof_info->profile_index, TRUE); - } - - pthread_mutex_unlock(&rtk_prof.profile_mutex); - return 1; -} - -uint8_t handle_l2cap_discon_req(uint16_t handle, uint16_t dcid, uint16_t scid, uint8_t direction) -{ - tRTK_PROF_INFO *prof_info = NULL; - RtkLogMsg("l2cap_discon_req, handle = %x, dcid = %x, scid = %x, direction = %x", handle, dcid, scid, direction); - pthread_mutex_lock(&rtk_prof.profile_mutex); - if (!direction) // 0: in - prof_info = find_profile_by_handle_dcid_scid(&rtk_prof, handle, scid, dcid); - else // 1: out - prof_info = find_profile_by_handle_dcid_scid(&rtk_prof, handle, dcid, scid); - - if (!prof_info) - { - // RtkLogMsg("handle_l2cap_discon_req: prof_info Not Find!"); - pthread_mutex_unlock(&rtk_prof.profile_mutex); - return 0; - } - - tRTK_CONN_PROF *phci_conn = find_connection_by_handle(&rtk_prof, handle); - if (NULL == phci_conn) - { - pthread_mutex_unlock(&rtk_prof.profile_mutex); - return 0; - } - - update_profile_connection(phci_conn, prof_info->profile_index, FALSE); - if (prof_info->profile_index == profile_a2dp && (phci_conn->profile_bitmap & BIT(profile_sink))) - update_profile_connection(phci_conn, profile_sink, FALSE); - delete_profile_from_hash(prof_info); - pthread_mutex_unlock(&rtk_prof.profile_mutex); - - return 1; -} - -void packets_count(uint16_t handle, uint16_t scid, uint16_t length, uint8_t direction, uint8_t *user_data) -{ - tRTK_PROF_INFO *prof_info = NULL; - // uint8_t profile_type; - - tRTK_CONN_PROF *hci_conn = find_connection_by_handle(&rtk_prof, handle); - if (NULL == hci_conn) - return; - - if (0 == hci_conn->type) // l2cap - { - if (!direction) // 0: in - prof_info = find_profile_by_handle_scid(&rtk_prof, handle, scid); - else // 1: out - prof_info = find_profile_by_handle_dcid(&rtk_prof, handle, scid); - - if (!prof_info) - { - return; - } - - if ((prof_info->profile_index == profile_a2dp) && (length > 100)) // avdtp media data - { - if (!is_profile_busy(profile_a2dp)) - { - struct sbc_frame_hdr *sbc_header; - struct rtp_header *rtph; - uint8_t bitpool; - update_profile_state(profile_a2dp, TRUE); - if (!direction) - { - update_profile_connection(hci_conn, profile_sink, true); - update_profile_state(profile_sink, TRUE); - } - rtph = (struct rtp_header *)user_data; - RtkLogMsg("rtp: v %u, cc %u, pt %u", rtph->v, rtph->cc, rtph->pt); - /* move forward */ - user_data += sizeof(struct rtp_header) + rtph->cc * 4 + 1; - /* point to the sbc frame header */ - sbc_header = (struct sbc_frame_hdr *)user_data; - bitpool = sbc_header->bitpool; - print_sbc_header(sbc_header); - RtkLogMsg("rtp: v %u, cc %u, pt %u", rtph->v, rtph->cc, rtph->pt); - rtk_vendor_cmd_to_fw(HCI_VENDOR_ADD_BITPOOL_FW, 1, &bitpool, NULL); - } - rtk_prof.a2dp_packet_count++; - } - - if (prof_info->profile_index == profile_pan) - rtk_prof.pan_packet_count++; - } -} - -static void timeout_handler(int signo, siginfo_t *info, void *context) -{ - RTK_UNUSED(info); - RTK_UNUSED(context); - if (signo == TIMER_POLLING) - { - RtkLogMsg("polling timeout"); - if (rtk_prof.polling_enable) - { - uint8_t temp_cmd[1]; - temp_cmd[0] = HCI_VENDOR_SUB_CMD_BT_REPORT_CONN_SCO_INQ_INFO; - rtk_vendor_cmd_to_fw(HCI_VENDOR_MAILBOX_CMD, 1, temp_cmd, NULL); - } - } - else if (signo == TIMER_A2DP_PACKET_COUNT) - { - RtkLogMsg("count a2dp packet timeout, a2dp_packet_count = %d", rtk_prof.a2dp_packet_count); - if (rtk_prof.a2dp_packet_count == 0) - { - if (is_profile_busy(profile_a2dp)) - { - RtkLogMsg("timeout_handler: a2dp busy->idle!"); - update_profile_state(profile_a2dp, FALSE); - if (is_profile_busy(profile_sink)) - { - RtkLogMsg("timeout_handler: sink busy->idle!"); - update_profile_state(profile_sink, FALSE); - } - } - } - rtk_prof.a2dp_packet_count = 0; - } - else if (signo == TIMER_HOGP_PACKET_COUNT) - { - RtkLogMsg("count hogp packet timeout, hogp_packet_count = %d", rtk_prof.hogp_packet_count); - if (rtk_prof.hogp_packet_count == 0) - { - if (is_profile_busy(profile_hogp)) - { - RtkLogMsg("timeout_handler: hogp busy->idle!"); - update_profile_state(profile_hogp, FALSE); - } - } - rtk_prof.hogp_packet_count = 0; - - RtkLogMsg("count hogp packet timeout, voice_packet_count = %d", rtk_prof.voice_packet_count); - if (rtk_prof.voice_packet_count == 0) - { - if (is_profile_busy(profile_voice)) - { - RtkLogMsg("timeout_handler: voice busy->idle!"); - update_profile_state(profile_voice, FALSE); - } - } - rtk_prof.voice_packet_count = 0; - } - else if (signo == TIMER_PAN_PACKET_COUNT) - { - RtkLogMsg("count pan packet timeout, pan_packet_count = %d", rtk_prof.pan_packet_count); - if (rtk_prof.pan_packet_count < PAN_PACKET_COUNT) - { - if (is_profile_busy(profile_pan)) - { - RtkLogMsg("timeout_handler: pan busy->idle!"); - update_profile_state(profile_pan, FALSE); - } - } - else - { - if (!is_profile_busy(profile_pan)) - { - RtkLogMsg("timeout_handler: pan idle->busy!"); - update_profile_state(profile_pan, TRUE); - } - } - rtk_prof.pan_packet_count = 0; - } - else - { - HILOGE("rtk_parse_data timer unspported signo(%d)", signo); - } -} - -static void notify_func(union sigval sig) -{ - int signo = sig.sival_int; - timeout_handler(signo, NULL, NULL); -} - -#if 0 -int netlink_send(int nlsk, char *buffer) -{ - struct nlmsghdr* nlhdr; - struct iovec iov; - struct msghdr msg; - struct sockaddr_nl nladdr; - - if(nlsk <= 0) - return -1; - - memset(&msg, 0 ,sizeof(struct msghdr)); - memset(&nladdr, 0 ,sizeof(struct sockaddr_nl)); - - nlhdr = (struct nlmsghdr *)malloc(NLMSG_SPACE(strlen(buffer) + 1)); - strcpy(NLMSG_DATA(nlhdr),buffer); - - nlhdr->nlmsg_len = NLMSG_LENGTH(strlen(buffer) + 1); - nlhdr->nlmsg_pid = getpid(); //sender pid - nlhdr->nlmsg_flags = NLM_F_REQUEST; - nlhdr->nlmsg_type = NLMSG_MIN_TYPE; - - nladdr.nl_family = AF_NETLINK; - nladdr.nl_pid = 0; //send to kernel - nladdr.nl_groups = 0; - - iov.iov_base = (void *)nlhdr; - iov.iov_len = nlhdr->nlmsg_len; - - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - msg.msg_name = (void *)&(nladdr); - msg.msg_namelen = sizeof(nladdr); - - return sendmsg(nlsk, &msg, 0); -} -#endif - -int udpsocket_send(char *tx_msg, int msg_size) -{ - int n; /* message byte size */ - - RtkLogMsg("udpsocket_send tx_msg:%s", tx_msg); - n = sendto(rtk_prof.udpsocket, tx_msg, msg_size, 0, (struct sockaddr *)&rtk_prof.client_addr, sizeof(rtk_prof.client_addr)); - if (n < 0) - { - HILOGE("ERROR in sendto"); - return -1; - } - return 0; -} - -int udpsocket_recv(uint8_t *recv_msg, uint8_t *msg_size) -{ - // struct hostent *hostp; /* client host info */ - char buf[MAX_PAYLOAD]; /* message buf */ - // char *hostaddrp; /* dotted decimal host addr string */ - int n; /* message byte size */ - struct sockaddr_in recv_addr; - socklen_t clientlen = sizeof(recv_addr); - struct pollfd pfd = { - .events = POLLPRI | POLLIN, - .revents = 0, - .fd = rtk_prof.udpsocket}; - - bzero(buf, MAX_PAYLOAD); - - while (poll(&pfd, 1, 1000) <= 0) - { - if (rtk_prof.coex_recv_thread_running == 0) - { - RtkLogMsg("%s, SIGUSR2 should have caught us before this", __func__); - return -1; - } - } - - n = recvfrom(rtk_prof.udpsocket, buf, MAX_PAYLOAD, 0, (struct sockaddr *)&recv_addr, &clientlen); - if (n < 0) - { - HILOGE("ERROR in recvfrom"); - return -1; - } - else - { - *msg_size = n; - memcpy(recv_msg, buf, n); - } - return 0; -} - -int btcoex_chr_send(char *tx_msg, int msg_size) -{ - int n; /* message byte size */ - - RtkLogMsg("btcoex_chr_send tx_msg:%s", tx_msg); - RTK_NO_INTR(n = write(rtk_prof.btcoex_chr, tx_msg, msg_size)); - if (n < 0) - { - HILOGE("ERROR in write"); - return -1; - } - return n; -} - -int btcoex_chr_recv(uint8_t *recv_msg, uint8_t *msg_size) -{ - char buf[MAX_PAYLOAD]; /* message buf */ - int n = -1; /* message byte size */ - struct pollfd pfd = { - .events = POLLPRI | POLLIN | POLLHUP | POLLERR | POLLRDHUP, - .revents = 0, - .fd = rtk_prof.btcoex_chr}; - - bzero(buf, MAX_PAYLOAD); - - while (poll(&pfd, 1, 1000) <= 0) - { - if (rtk_prof.coex_recv_thread_running == 0) - { - RtkLogMsg("%s, SIGUSR2 should have caught us before this", __func__); - return -1; - } - } - - if (pfd.revents & POLLIN) - { - RTK_NO_INTR(n = read(rtk_prof.btcoex_chr, buf, MAX_PAYLOAD)); - if (n < 0) - { - HILOGE("ERROR in recvfrom"); - return -1; - } - else - { - *msg_size = n; - memcpy(recv_msg, buf, n); - } - } - else - { - HILOGE("rtk_btcoex is wrong"); - return -1; - } - return 0; -} - -void rtk_notify_extension_version_to_wifi() -{ - uint8_t para_length = 2; - char p_buf[para_length + HCI_CMD_PREAMBLE_SIZE]; - - if (!rtk_prof.wifi_on) - return; - - char *p = p_buf; - UINT16_TO_STREAM(p, HCI_OP_HCI_EXTENSION_VERSION_NOTIFY); - *p++ = para_length; - UINT16_TO_STREAM(p, HCI_EXTENSION_VERSION); - RtkLogMsg("extension version is 0x%x", HCI_EXTENSION_VERSION); - if (coex_msg_send(p_buf, para_length + HCI_CMD_PREAMBLE_SIZE) < 0) - HILOGE("rtk_notify_extension_version_to_wifi: udpsocket send error"); -} - -void rtk_notify_btpatch_version_to_wifi() -{ - uint8_t para_length = 4; - char p_buf[para_length + HCI_CMD_PREAMBLE_SIZE]; - - if (!rtk_prof.wifi_on) - return; - - char *p = p_buf; - UINT16_TO_STREAM(p, HCI_OP_HCI_BT_PATCH_VER_NOTIFY); - *p++ = para_length; - UINT16_TO_STREAM(p, rtk_prof.hci_reversion); - UINT16_TO_STREAM(p, rtk_prof.lmp_subversion); - RtkLogMsg("btpatch_version, length is 0x%x, hci_reversion is 0x%x, lmp_subversion is %x", para_length, rtk_prof.hci_reversion, rtk_prof.lmp_subversion); - - if (coex_msg_send(p_buf, para_length + HCI_CMD_PREAMBLE_SIZE) < 0) - HILOGE("rtk_notify_btpatch_version_to_wifi: udpsocket send error"); -} - -void rtk_notify_afhmap_to_wifi() -{ - uint8_t para_length = 13; - char p_buf[para_length + HCI_CMD_PREAMBLE_SIZE]; - - if (!rtk_prof.wifi_on) - return; - - char *p = p_buf; - UINT16_TO_STREAM(p, HCI_OP_HCI_BT_AFH_MAP_NOTIFY); - *p++ = para_length; - *p++ = rtk_prof.piconet_id; - *p++ = rtk_prof.mode; - *p++ = 10; - memcpy(p, rtk_prof.afh_map, 10); - - RtkLogMsg("afhmap, piconet_id is 0x%x, map type is 0x%x", rtk_prof.piconet_id, rtk_prof.mode); - uint8_t kk = 0; - for (kk = 0; kk < 10; kk++) - RtkLogMsg("afhmap data[%d] is 0x%x", kk, rtk_prof.afh_map[kk]); - - if (coex_msg_send(p_buf, para_length + HCI_CMD_PREAMBLE_SIZE) < 0) - HILOGE("rtk_notify_afhmap_to_wifi: udpsocket send error"); -} - -void rtk_notify_btcoex_to_wifi(uint8_t opcode, uint8_t status) -{ - uint8_t para_length = 2; - char p_buf[para_length + HCI_CMD_PREAMBLE_SIZE]; - - if (!rtk_prof.wifi_on) - return; - - char *p = p_buf; - UINT16_TO_STREAM(p, HCI_OP_HCI_BT_COEX_NOTIFY); - *p++ = para_length; - *p++ = opcode; - if (!status) - *p++ = 0; - else - *p++ = 1; - - RtkLogMsg("btcoex, opcode is 0x%x, status is 0x%x", opcode, status); - - if (coex_msg_send(p_buf, para_length + HCI_CMD_PREAMBLE_SIZE) < 0) - HILOGE("rtk_notify_btcoex_to_wifi: udpsocket send error"); -} - -void rtk_notify_btoperation_to_wifi(uint8_t operation, uint8_t append_data_length, uint8_t *append_data) -{ - uint8_t para_length = 3 + append_data_length; - char p_buf[para_length + HCI_CMD_PREAMBLE_SIZE]; - - if (!rtk_prof.wifi_on) - return; - - char *p = p_buf; - UINT16_TO_STREAM(p, HCI_OP_BT_OPERATION_NOTIFY); - *p++ = para_length; - *p++ = operation; - *p++ = append_data_length; - if (append_data_length) - memcpy(p, append_data, append_data_length); - - RtkLogMsg("btoperation, opration is 0x%x, append_data_length is 0x%x", operation, append_data_length); - uint8_t kk = 0; - if (append_data_length) - { - for (kk = 0; kk < append_data_length; kk++) - RtkLogMsg("append data is 0x%x", *(append_data + kk)); - } - - if (coex_msg_send(p_buf, para_length + HCI_CMD_PREAMBLE_SIZE) < 0) - HILOGE("rtk_notify_btoperation_to_wifi: udpsocket send error"); -} - -void rtk_notify_info_to_wifi(uint8_t reason, uint8_t length, uint8_t *report_info) -{ - uint8_t para_length = 4 + length; - char p_buf[para_length + HCI_CMD_PREAMBLE_SIZE]; - int i; - - if (!rtk_prof.wifi_on) - return; - - char *p = p_buf; - UINT16_TO_STREAM(p, HCI_OP_HCI_BT_INFO_NOTIFY); - *p++ = para_length; - *p++ = rtk_prof.polling_enable; - *p++ = rtk_prof.polling_interval; - *p++ = reason; - *p++ = length; - - if (length) - memcpy(p, report_info, length); - - RtkLogMsg("bt info, length is 0x%x, polling_enable is 0x%x, poiiling_interval is %x", para_length, rtk_prof.polling_enable, rtk_prof.polling_interval); - RtkLogMsg("bt info, reason is 0x%x, info length is 0x%x", reason, length); - if (length) - { - for (i = 0; i < length; i++) - RtkLogMsg("bt info[%d]: %02x", i, report_info[i]); - } - - if (coex_msg_send(p_buf, para_length + HCI_CMD_PREAMBLE_SIZE) < 0) - HILOGE("rtk_notify_info_to_wifi: udpsocket send error"); -} - -void rtk_notify_regester_to_wifi(uint8_t *reg_value) -{ - uint8_t para_length = 9; - char p_buf[para_length + HCI_CMD_PREAMBLE_SIZE]; - - if (!rtk_prof.wifi_on) - return; - - char *p = p_buf; - UINT16_TO_STREAM(p, HCI_OP_HCI_BT_REGISTER_VALUE_NOTIFY); - *p++ = para_length; - memcpy(p, reg_value, para_length); - - tHCI_RETURN_PARAMETER_MAILBOX_REGISTER *reg = (tHCI_RETURN_PARAMETER_MAILBOX_REGISTER *)reg_value; - RtkLogMsg("bt register, register type is %x", reg->type); - RtkLogMsg("bt register, register offset is %x", reg->offset); - RtkLogMsg("bt register, register value is %x", reg->value); - - if (coex_msg_send(p_buf, para_length + HCI_CMD_PREAMBLE_SIZE) < 0) - HILOGE("rtk_notify_regester_to_wifi: udpsocket send error"); -} - -static void rtk_handle_bt_info_control(uint8_t *p) -{ - tHCI_EVENT_BT_INFO_CONTROL *info = (tHCI_EVENT_BT_INFO_CONTROL *)p; - uint8_t temp_cmd[3]; - - RtkLogMsg("rtk_prof.polling_enable is %x", rtk_prof.polling_enable); - RtkLogMsg("receive bt info control event from wifi, polling enable is 0x%x, polling time is 0x%x, auto report is 0x%x", - info->polling_enable, info->polling_time, info->autoreport_enable); - - if (info->polling_enable && !rtk_prof.polling_enable) - start_polling_timer(info->polling_time * 1000); - - if (!info->polling_enable && rtk_prof.polling_enable) - stop_polling_timer(); - - rtk_prof.polling_enable = info->polling_enable; - rtk_prof.polling_interval = info->polling_time; - rtk_prof.autoreport = info->autoreport_enable; - - temp_cmd[0] = HCI_VENDOR_SUB_CMD_BT_AUTO_REPORT_ENABLE; - temp_cmd[1] = 1; - temp_cmd[2] = info->autoreport_enable; - rtk_vendor_cmd_to_fw(HCI_VENDOR_MAILBOX_CMD, 3, temp_cmd, NULL); - - rtk_notify_info_to_wifi(HOST_RESPONSE, 0, NULL); -} - -static void rtk_handle_bt_coex_control(uint8_t *p) -{ - uint8_t opcode = *p++; - uint8_t op_len = 0; - RtkLogMsg("receive bt coex control event from wifi, opration is 0x%x", opcode); - switch (opcode) - { - case BT_PATCH_VERSION_QUERY: - { - rtk_notify_btpatch_version_to_wifi(); - break; - } - - case IGNORE_WLAN_ACTIVE_CONTROL: - { - uint8_t opcode_len = *p++; - uint8_t value = *p++; - uint8_t temp_cmd[3]; - op_len = opcode_len; - temp_cmd[0] = HCI_VENDOR_SUB_CMD_BT_ENABLE_IGNORE_WLAN_ACT_CMD; - temp_cmd[1] = 1; - temp_cmd[2] = value; - rtk_vendor_cmd_to_fw(HCI_VENDOR_MAILBOX_CMD, 3, temp_cmd, NULL); - break; - } - - case LNA_CONSTRAIN_CONTROL: - { - uint8_t opcode_len = *p++; - uint8_t value = *p++; - uint8_t temp_cmd[3]; - op_len = opcode_len; - temp_cmd[0] = HCI_VENDOR_SUB_CMD_SET_BT_LNA_CONSTRAINT; - temp_cmd[1] = 1; - temp_cmd[2] = value; - rtk_vendor_cmd_to_fw(HCI_VENDOR_MAILBOX_CMD, 3, temp_cmd, NULL); - break; - } - - case BT_POWER_DECREASE_CONTROL: - { - uint8_t opcode_len = *p++; - uint8_t power_decrease = *p++; - uint8_t temp_cmd[3]; - op_len = opcode_len; - temp_cmd[0] = HCI_VENDOR_SUB_CMD_WIFI_FORCE_TX_POWER_CMD; - temp_cmd[1] = 1; - temp_cmd[2] = power_decrease; - rtk_vendor_cmd_to_fw(HCI_VENDOR_MAILBOX_CMD, 3, temp_cmd, NULL); - break; - } - - case BT_PSD_MODE_CONTROL: - { - uint8_t opcode_len = *p++; - uint8_t psd_mode = *p++; - uint8_t temp_cmd[3]; - op_len = opcode_len; - temp_cmd[0] = HCI_VENDOR_SUB_CMD_SET_BT_PSD_MODE; - temp_cmd[1] = 1; - temp_cmd[2] = psd_mode; - rtk_vendor_cmd_to_fw(HCI_VENDOR_MAILBOX_CMD, 3, temp_cmd, NULL); - break; - } - - case WIFI_BW_CHNL_NOTIFY: - { - uint8_t opcode_len = *p++; - uint8_t temp_cmd[5]; - op_len = opcode_len; - temp_cmd[0] = HCI_VENDOR_SUB_CMD_WIFI_CHANNEL_AND_BANDWIDTH_CMD; - temp_cmd[1] = 3; - memcpy(temp_cmd + 2, p, 3); // wifi_state, wifi_centralchannel, chnnels_btnotuse - rtk_vendor_cmd_to_fw(HCI_VENDOR_MAILBOX_CMD, 5, temp_cmd, NULL); - break; - } - - case QUERY_BT_AFH_MAP: - { - uint8_t opcode_len = *p++; - rtk_prof.piconet_id = *p++; - rtk_prof.mode = *p++; - uint8_t temp_cmd[4]; - op_len = opcode_len; - temp_cmd[0] = HCI_VENDOR_SUB_CMD_GET_AFH_MAP_L; - temp_cmd[1] = 2; - temp_cmd[2] = rtk_prof.piconet_id; - temp_cmd[3] = rtk_prof.mode; - rtk_vendor_cmd_to_fw(HCI_VENDOR_MAILBOX_CMD, 4, temp_cmd, NULL); - break; - } - - case BT_REGISTER_ACCESS: - { - uint8_t opcode_len = *p++; - uint8_t access_type = *p++; - op_len = opcode_len; - if (access_type == 0) // read - { - uint8_t temp_cmd[7]; - temp_cmd[0] = HCI_VENDOR_SUB_CMD_RD_REG_REQ; - temp_cmd[1] = 5; - temp_cmd[2] = *p++; - memcpy(temp_cmd + 3, p, 4); - rtk_vendor_cmd_to_fw(HCI_VENDOR_MAILBOX_CMD, 7, temp_cmd, NULL); - } - else // write - { - uint8_t temp_cmd[11]; - temp_cmd[0] = HCI_VENDOR_SUB_CMD_RD_REG_REQ; - temp_cmd[1] = 5; - temp_cmd[2] = *p++; - memcpy(temp_cmd + 3, p, 8); - rtk_vendor_cmd_to_fw(HCI_VENDOR_MAILBOX_CMD, 11, temp_cmd, NULL); - } - break; - } - - default: - break; - } -} - -void rtk_handle_event_from_wifi(uint8_t *msg) -{ - uint8_t *p = msg; - uint8_t event_code = *p++; - uint8_t total_length = 0; - - RtkLogMsg("receive invite rsp from wifi msg : %s", msg); - if (memcmp(msg, invite_rsp, sizeof(invite_rsp)) == 0) - { -#if 0 - RtkLogMsg("receive invite rsp from wifi, close netlink socket if needed"); - if(rtk_prof.nlsocket > 0) - { - close(rtk_prof.nlsocket); - RtkLogMsg("close netlink socket %d", rtk_prof.nlsocket); - } -#endif - RtkLogMsg("receive invite rsp from wifi, wifi is already on"); - rtk_prof.wifi_on = 1; - rtk_notify_extension_version_to_wifi(); - } - - if (memcmp(msg, attend_req, sizeof(attend_req)) == 0) - { - RtkLogMsg("receive attend req from wifi, wifi turn on"); - rtk_prof.wifi_on = 1; - coex_msg_send(attend_ack, sizeof(attend_ack)); - rtk_notify_extension_version_to_wifi(); - } - - if (memcmp(msg, wifi_leave, sizeof(wifi_leave)) == 0) - { - RtkLogMsg("receive wifi leave from wifi, wifi turn off"); - rtk_prof.wifi_on = 0; - coex_msg_send(leave_ack, sizeof(leave_ack)); - if (rtk_prof.polling_enable) - { - rtk_prof.polling_enable = 0; - stop_polling_timer(); - } - } - - if (memcmp(msg, leave_ack, sizeof(leave_ack)) == 0) - { - RtkLogMsg("receive leave ack from wifi"); - } - - if (event_code == 0xFE) - { - total_length = *p++; - uint8_t extension_event = *p++; - switch (extension_event) - { - case RTK_HS_EXTENSION_EVENT_WIFI_SCAN: - { - uint8_t operation = *p; - RtkLogMsg("receive wifi scan notify evnet from wifi, operation is 0x%x", operation); - break; - } - - case RTK_HS_EXTENSION_EVENT_HCI_BT_INFO_CONTROL: - { - rtk_handle_bt_info_control(p); - break; - } - - case RTK_HS_EXTENSION_EVENT_HCI_BT_COEX_CONTROL: - { - rtk_handle_bt_coex_control(p); - break; - } - - default: - break; - } - } - - if (event_code == 0x0E) - { - uint16_t wifi_opcode; - uint8_t op_status; - p += 2; // length, number of complete packets - STREAM_TO_UINT16(wifi_opcode, p); - op_status = *p; - RtkLogMsg("receive command complete event from wifi, op code is 0x%x, status is 0x%x", wifi_opcode, op_status); - } -} - -static void coex_receive_thread_exit_handler(int sig) -{ - RtkLogMsg("USR2, this signal is %d \n", sig); - usleep(100); - pthread_exit(0); -} - -static void btwifi_coex_receive_thread(void *arg) -{ - RTK_UNUSED(arg); - uint8_t msg_recv[MAX_PAYLOAD]; - uint8_t recv_length; - struct sigaction actions; - - memset(&actions, 0, sizeof(actions)); - sigemptyset(&actions.sa_mask); - actions.sa_flags = 0; - actions.sa_handler = coex_receive_thread_exit_handler; - - sigaction(SIGUSR2, &actions, NULL); // int rc = sigaction(SIGUSR2,&actions,NULL); - - RtkLogMsg("btwifi_coex_receive_thread started"); - prctl(PR_SET_NAME, (unsigned long)"btwifi_coex_receive_thread", 0, 0, 0); - - while (rtk_prof.coex_recv_thread_running) - { - memset(msg_recv, 0, MAX_PAYLOAD); - if (coex_msg_recv(msg_recv, &recv_length) == 0) - rtk_handle_event_from_wifi(msg_recv); - } - - RtkLogMsg("btwifi_coex_receive_thread exiting"); - pthread_exit(NULL); -} - -int create_udpsocket_socket() -{ - int portno = CONNECT_PORT; - int optval; /* flag value for setsockopt */ - - RtkLogMsg("create udpsocket port: %d\n", portno); - - pthread_mutex_lock(&rtk_prof.btwifi_mutex); - - pthread_attr_t thread_attr_data; - if (rtk_prof.coex_recv_thread_running) - { - HILOGE("udp_receive_thread already exit"); - pthread_mutex_unlock(&rtk_prof.btwifi_mutex); - return -1; - } - - rtk_prof.coex_recv_thread_running = 1; - rtk_prof.udpsocket = socket(AF_INET, SOCK_DGRAM, 0); - RtkLogMsg("create socket %d", rtk_prof.udpsocket); - - if (rtk_prof.udpsocket < 0) - { - HILOGE("create udpsocket error...%s\n", strerror(errno)); - rtk_prof.coex_recv_thread_running = 0; - RtkLogMsg("close socket %d", rtk_prof.udpsocket); - pthread_mutex_unlock(&rtk_prof.btwifi_mutex); - return -1; - } - - bzero((char *)&rtk_prof.server_addr, sizeof(rtk_prof.server_addr)); - rtk_prof.server_addr.sin_family = AF_INET; - rtk_prof.server_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - rtk_prof.server_addr.sin_port = htons(CONNECT_PORT); - - bzero((char *)&rtk_prof.client_addr, sizeof(rtk_prof.client_addr)); - rtk_prof.client_addr.sin_family = AF_INET; - rtk_prof.client_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - rtk_prof.client_addr.sin_port = htons(CONNECT_PORT_WIFI); - - optval = 1; - int ret = setsockopt(rtk_prof.udpsocket, SOL_SOCKET, SO_REUSEADDR, (const void *)&optval, sizeof(int)); - if (ret == -1) - { - HILOGE("%s, setsockopt error: %s", __func__, strerror(errno)); - } - - if (bind(rtk_prof.udpsocket, (struct sockaddr *)&rtk_prof.server_addr, sizeof(rtk_prof.server_addr)) < 0) - { - HILOGE("bind udpsocket error...%s\n", strerror(errno)); - rtk_prof.coex_recv_thread_running = 0; - close(rtk_prof.udpsocket); - RtkLogMsg("close socket %d", rtk_prof.udpsocket); - pthread_mutex_unlock(&rtk_prof.btwifi_mutex); - return -1; - } - - pthread_attr_init(&thread_attr_data); - if (pthread_create(&rtk_prof.thread_data, &thread_attr_data, (void *)btwifi_coex_receive_thread, NULL) != 0) - { - HILOGE("pthread_create failed!"); - pthread_attr_destroy(&thread_attr_data); - rtk_prof.coex_recv_thread_running = 0; - pthread_mutex_unlock(&rtk_prof.btwifi_mutex); - return -1; - } - pthread_attr_destroy(&thread_attr_data); - pthread_mutex_unlock(&rtk_prof.btwifi_mutex); - return 0; -} - -int stop_btwifi_coex_receive_thread() -{ - pthread_mutex_lock(&rtk_prof.btwifi_mutex); - int result = 0; - - RtkLogMsg("notify wifi bt turn off"); - if (rtk_prof.wifi_on) - coex_msg_send(bt_leave, sizeof(bt_leave)); - - if (rtk_prof.coex_recv_thread_running) - { - RtkLogMsg("data thread is running, stop it"); - - // add for pthread_cancel - if ((result = pthread_kill(rtk_prof.thread_data, SIGUSR2)) != 0) - { - HILOGE("error cancelling data thread"); - } - rtk_prof.coex_recv_thread_running = 0; - - if ((result = pthread_join(rtk_prof.thread_data, NULL)) < 0) - { - HILOGE("data thread pthread_join() failed result:%d", result); - } - - if (rtk_prof.udpsocket > 0) - { - RtkLogMsg("close socket %d", rtk_prof.udpsocket); - if ((result = close(rtk_prof.udpsocket)) != 0) - { - HILOGE("close socket error!"); - } - } - else if (rtk_prof.btcoex_chr > 0) - { - RtkLogMsg("close char device %d", rtk_prof.btcoex_chr); - if ((result = close(rtk_prof.btcoex_chr)) != 0) - { - HILOGE("close char device error!"); - } - } - } - pthread_mutex_unlock(&rtk_prof.btwifi_mutex); - return 0; -} - -#if 0 -int create_netlink_socket() -{ - RtkLogMsg("in creat netlink socket"); - rtk_prof.nlsocket = socket(PF_NETLINK, SOCK_RAW, NETLINK_USER); - - if (rtk_prof.nlsocket < 0) - { - HILOGE("create netlink socket error...%s\n", strerror(errno)); - close(rtk_prof.nlsocket); - RtkLogMsg("close netlink socket %d", rtk_prof.nlsocket); - return -1 ; - } - RtkLogMsg("create netlink socket %d", rtk_prof.nlsocket); - memset(&rtk_prof.src_addr, 0, sizeof(rtk_prof.src_addr)); - rtk_prof.src_addr.nl_family = AF_NETLINK; - rtk_prof.src_addr.nl_pid = getpid(); /* self pid */ - rtk_prof.src_addr.nl_groups = 0 ; /* not in mcast groups */ - int ret = bind(rtk_prof.nlsocket, (struct sockaddr *)&rtk_prof.src_addr, sizeof(rtk_prof.src_addr)); - if(ret < 0) - { - HILOGE("bind netlink socket error...%s\n", strerror(errno)); - close(rtk_prof.nlsocket); - RtkLogMsg("close netlink socket %d", rtk_prof.nlsocket); - return -1 ; - } - - return 0; -} -#endif - -int open_btcoex_chrdev() -{ - RtkLogMsg("open_btcoex_chrdev\n"); - - pthread_mutex_lock(&rtk_prof.btwifi_mutex); - - pthread_attr_t thread_attr_data; - if (rtk_prof.coex_recv_thread_running) - { - HILOGE("udp_receive_thread already exit"); - pthread_mutex_unlock(&rtk_prof.btwifi_mutex); - return -1; - } - - rtk_prof.coex_recv_thread_running = 1; - if ((rtk_prof.btcoex_chr = open("/dev/rtk_btcoex", O_RDWR)) < 0) - { - HILOGE("open rtk_btcoex error...%s\n", strerror(errno)); - rtk_prof.coex_recv_thread_running = 0; - pthread_mutex_unlock(&rtk_prof.btwifi_mutex); - return -1; - } - - pthread_attr_init(&thread_attr_data); - if (pthread_create(&rtk_prof.thread_data, &thread_attr_data, (void *)btwifi_coex_receive_thread, NULL) != 0) - { - HILOGE("create coexchr_receive_thread failed!"); - pthread_attr_destroy(&thread_attr_data); - rtk_prof.coex_recv_thread_running = 0; - pthread_mutex_unlock(&rtk_prof.btwifi_mutex); - return -1; - } - pthread_attr_destroy(&thread_attr_data); - pthread_mutex_unlock(&rtk_prof.btwifi_mutex); - return 0; -} - -void rtk_parse_init(void) -{ - HILOGI("RTKBT_RELEASE_NAME: %s", RTKBT_RELEASE_NAME); - RtkLogMsg("rtk_profile_init, version: %s", RTK_COEX_VERSION); - - memset(&rtk_prof, 0, sizeof(rtk_prof)); - pthread_mutex_init(&rtk_prof.profile_mutex, NULL); - pthread_mutex_init(&rtk_prof.coex_mutex, NULL); - pthread_mutex_init(&rtk_prof.btwifi_mutex, NULL); - alloc_a2dp_packet_count_timer(); - alloc_pan_packet_count_timer(); - alloc_hogp_packet_count_timer(); - alloc_polling_timer(); - - init_profile_hash(&rtk_prof); - init_connection_hash(&rtk_prof); - init_coex_hash(&rtk_prof); - - if (create_udpsocket_socket() < 0) - { - HILOGE("UDP socket fail, try to use rtk_btcoex chrdev"); - open_btcoex_chrdev(); - } -} - -void rtk_parse_cleanup() -{ - RtkLogMsg("rtk_profile_cleanup"); - free_a2dp_packet_count_timer(); - free_pan_packet_count_timer(); - free_hogp_packet_count_timer(); - free_polling_timer(); - - flush_connection_hash(&rtk_prof); - flush_profile_hash(&rtk_prof); - pthread_mutex_destroy(&rtk_prof.profile_mutex); - flush_coex_hash(&rtk_prof); - pthread_mutex_destroy(&rtk_prof.coex_mutex); - - stop_btwifi_coex_receive_thread(); - pthread_mutex_destroy(&rtk_prof.btwifi_mutex); - - memset(&rtk_prof, 0, sizeof(rtk_prof)); -} - -static void rtk_handle_vender_mailbox_cmp_evt(uint8_t *p, uint8_t len) -{ - uint8_t status = *p++; - if (len <= 4) - { - RtkLogMsg("receive mailbox cmd from fw, total length <= 4"); - return; - } - uint8_t subcmd = *p++; - RtkLogMsg("receive mailbox cmd from fw, subcmd is 0x%x, status is 0x%x", subcmd, status); - switch (subcmd) - { - case HCI_VENDOR_SUB_CMD_BT_REPORT_CONN_SCO_INQ_INFO: - if (status == 0) // success - { - if ((len - 5) != 8) - RtkLogMsg("rtk_handle_vender_mailbox_cmp_evt:HCI_VENDOR_SUB_CMD_BT_REPORT_CONN_SCO_INQ_INFO len=%d", len); - rtk_notify_info_to_wifi(POLLING_RESPONSE, (len - 5), (uint8_t *)p); - } - break; - - case HCI_VENDOR_SUB_CMD_WIFI_CHANNEL_AND_BANDWIDTH_CMD: - rtk_notify_btcoex_to_wifi(WIFI_BW_CHNL_NOTIFY, status); - break; - - case HCI_VENDOR_SUB_CMD_WIFI_FORCE_TX_POWER_CMD: - rtk_notify_btcoex_to_wifi(BT_POWER_DECREASE_CONTROL, status); - break; - - case HCI_VENDOR_SUB_CMD_BT_ENABLE_IGNORE_WLAN_ACT_CMD: - rtk_notify_btcoex_to_wifi(IGNORE_WLAN_ACTIVE_CONTROL, status); - break; - - case HCI_VENDOR_SUB_CMD_SET_BT_PSD_MODE: - rtk_notify_btcoex_to_wifi(BT_PSD_MODE_CONTROL, status); - break; - - case HCI_VENDOR_SUB_CMD_SET_BT_LNA_CONSTRAINT: - rtk_notify_btcoex_to_wifi(LNA_CONSTRAIN_CONTROL, status); - break; - - case HCI_VENDOR_SUB_CMD_BT_AUTO_REPORT_ENABLE: - break; - - case HCI_VENDOR_SUB_CMD_BT_SET_TXRETRY_REPORT_PARAM: - break; - - case HCI_VENDOR_SUB_CMD_BT_SET_PTATABLE: - break; - - case HCI_VENDOR_SUB_CMD_GET_AFH_MAP_L: - { - if (status == 0) // success - { - memcpy(rtk_prof.afh_map, p + 4, 4); // cmd_idx, length, piconet_id, mode - uint8_t temp_cmd[4]; - temp_cmd[0] = HCI_VENDOR_SUB_CMD_GET_AFH_MAP_M; - temp_cmd[1] = 2; - temp_cmd[2] = rtk_prof.piconet_id; - temp_cmd[3] = rtk_prof.mode; - rtk_vendor_cmd_to_fw(HCI_VENDOR_MAILBOX_CMD, 4, temp_cmd, NULL); - } - else // fail - { - memset(rtk_prof.afh_map, 0, 10); - rtk_notify_afhmap_to_wifi(); - } - break; - } - case HCI_VENDOR_SUB_CMD_GET_AFH_MAP_M: - { - if (status == 0) // success - { - memcpy(rtk_prof.afh_map + 4, p + 4, 4); - uint8_t temp_cmd[4]; - temp_cmd[0] = HCI_VENDOR_SUB_CMD_GET_AFH_MAP_H; - temp_cmd[1] = 2; - temp_cmd[2] = rtk_prof.piconet_id; - temp_cmd[3] = rtk_prof.mode; - rtk_vendor_cmd_to_fw(HCI_VENDOR_MAILBOX_CMD, 4, temp_cmd, NULL); - } - else // fail - { - memset(rtk_prof.afh_map, 0, 10); - rtk_notify_afhmap_to_wifi(); - } - break; - } - - case HCI_VENDOR_SUB_CMD_GET_AFH_MAP_H: - { - if (status == 0) - memcpy(rtk_prof.afh_map + 8, p + 4, 2); - else - memset(rtk_prof.afh_map, 0, 10); - - rtk_notify_afhmap_to_wifi(); - break; - } - - case HCI_VENDOR_SUB_CMD_RD_REG_REQ: - { - if (status == 0) - rtk_notify_regester_to_wifi(p + 3); // cmd_idx,length,regist type - break; - } - - case HCI_VENDOR_SUB_CMD_WR_REG_REQ: - rtk_notify_btcoex_to_wifi(BT_REGISTER_ACCESS, status); - break; - - default: - break; - } -} - -static void rtk_handle_cmd_complete_evt(uint8_t *p, uint8_t len) -{ - uint16_t opcode; - uint8_t status; - p++; - STREAM_TO_UINT16(opcode, p); - switch (opcode) - { - case HCI_PERIODIC_INQUIRY_MODE: - { - status = *p++; - if (status && rtk_prof.isinquirying) - { - rtk_prof.isinquirying = 0; - RtkLogMsg("HCI_PERIODIC_INQUIRY_MODE start error, notify wifi inquiry stop"); - rtk_notify_btoperation_to_wifi(BT_OPCODE_INQUIRY_END, 0, NULL); - } - break; - } - - case HCI_READ_LOCAL_VERSION_INFO: - { - status = *p++; - if (!status) - { - p++; - STREAM_TO_UINT16(rtk_prof.hci_reversion, p); - p += 3; - STREAM_TO_UINT16(rtk_prof.lmp_subversion, p); - } - RtkLogMsg("rtk_prof.hci_reversion = %x", rtk_prof.hci_reversion); - RtkLogMsg("rtk_prof.lmp_subversion = %x", rtk_prof.lmp_subversion); - break; - } - - case HCI_RESET: - { - RtkLogMsg("bt start ok"); - coex_msg_send(invite_req, sizeof(invite_req)); -#if 0 - if(create_netlink_socket() == 0) - { - RtkLogMsg("wifi is already on when bt turn on"); - rtk_prof.wifi_on = 1; - netlink_send(rtk_prof.nlsocket, invite_req); - } - else - RtkLogMsg("wifi is off when bt turn on, wait for wifi turning on..."); -#endif - break; - } - - case 0xfc1b: - RtkLogMsg("received cmd complete event for fc1b"); - poweroff_allowed = 1; - break; - - case HCI_VENDOR_MAILBOX_CMD: - rtk_handle_vender_mailbox_cmp_evt(p, len); - break; - - case HCI_VENDOR_ADD_BITPOOL_FW: - status = *p++; - RtkLogMsg("received cmd complete event for HCI_VENDOR_ADD_BITPOOL_FW status:%d", status); - - default: - break; - } -} - -static void rtk_handle_connection_complete_evt(uint8_t *p) -{ - uint8_t status = 0; - uint16_t handle = 0; - status = *p++; - STREAM_TO_UINT16(handle, p); - p += 6; - uint8_t link_type = *p++; - - if (status == 0) - { - if (rtk_prof.ispaging) - { - rtk_prof.ispaging = 0; - RtkLogMsg("notify wifi page success end"); - rtk_notify_btoperation_to_wifi(BT_OPCODE_PAGE_SUCCESS_END, 0, NULL); - } - - tRTK_CONN_PROF *hci_conn = find_connection_by_handle(&rtk_prof, handle); - if (hci_conn == NULL) - { - hci_conn = allocate_connection_by_handle(handle); - if (hci_conn) - { - add_connection_to_hash(&rtk_prof, hci_conn); - hci_conn->profile_bitmap = 0; - memset(hci_conn->profile_refcount, 0, 8); - if ((0 == link_type) || (2 == link_type)) // sco or esco - { - hci_conn->type = 1; - update_profile_connection(hci_conn, profile_sco, TRUE); - } - else - hci_conn->type = 0; - } - else - { - HILOGE("HciConnAllocate fail"); - } - } - else - { - RtkLogMsg("HCI Connection handle(0x%x) has already exist!", handle); - hci_conn->profile_bitmap = 0; - memset(hci_conn->profile_refcount, 0, 8); - if ((0 == link_type) || (2 == link_type)) // sco or esco - { - hci_conn->type = 1; - update_profile_connection(hci_conn, profile_sco, TRUE); - } - else - hci_conn->type = 0; - } - } - else if (rtk_prof.ispaging) - { - rtk_prof.ispaging = 0; - RtkLogMsg("notify wifi page unsuccess end"); - rtk_notify_btoperation_to_wifi(BT_OPCODE_PAGE_UNSUCCESS_END, 0, NULL); - } -} - -static void rtk_handle_disconnect_complete_evt(uint8_t *p) -{ - if (rtk_prof.ispairing) // for slave: connection will be disconnected if authentication fail - { - rtk_prof.ispairing = 0; - RtkLogMsg("notify wifi pair end"); - rtk_notify_btoperation_to_wifi(BT_OPCODE_PAIR_END, 0, NULL); - } - - uint8_t status = 0; - uint16_t handle = 0; - uint8_t reason = 0; - status = *p++; - STREAM_TO_UINT16(handle, p); - reason = *p; - - if (status == 0) - { - tRTK_CONN_PROF *hci_conn = find_connection_by_handle(&rtk_prof, handle); - if (hci_conn) - { - switch (hci_conn->type) - { - case 0: - { - RT_LIST_ENTRY *iter = NULL, *temp = NULL; - tRTK_PROF_INFO *prof_info = NULL; - - pthread_mutex_lock(&rtk_prof.profile_mutex); - LIST_FOR_EACH_SAFELY(iter, temp, &rtk_prof.profile_list) - { - prof_info = LIST_ENTRY(iter, tRTK_PROF_INFO, list); - if ((handle == prof_info->handle) && prof_info->scid && prof_info->dcid) - { - RtkLogMsg("find info when hci disconnect, handle:%x, psm:%x, dcid:%x, scid:%x", prof_info->handle, prof_info->psm, prof_info->dcid, prof_info->scid); - // If both scid and dcid > 0, L2cap connection is exist. - update_profile_connection(hci_conn, prof_info->profile_index, FALSE); - delete_profile_from_hash(prof_info); - } - } - pthread_mutex_unlock(&rtk_prof.profile_mutex); - break; - } - - case 1: - update_profile_connection(hci_conn, profile_sco, FALSE); - break; - - case 2: - { - if (hci_conn->profile_bitmap & BIT(profile_hogp)) - update_profile_connection(hci_conn, profile_hogp, FALSE); - - if (hci_conn->profile_bitmap & BIT(profile_voice)) - update_profile_connection(hci_conn, profile_voice, FALSE); - - update_profile_connection(hci_conn, profile_hid, FALSE); - break; - } - - default: - break; - } - delete_connection_from_hash(hci_conn); - } - else - { - HILOGE("HCI Connection handle(0x%x) not found", handle); - } - } -} - -static void rtk_handle_le_connection_complete_evt(uint8_t *p, bool enhanced) -{ - uint16_t handle, interval; - uint8_t status; - tRTK_CONN_PROF *hci_conn = NULL; - - status = *p++; - STREAM_TO_UINT16(handle, p); - p += 8; // role, address type, address - if (enhanced) - { - p += 12; - } - STREAM_TO_UINT16(interval, p); - - if (status == 0) - { - if (rtk_prof.ispaging) - { - rtk_prof.ispaging = 0; - RtkLogMsg("notify wifi page success end"); - rtk_notify_btoperation_to_wifi(BT_OPCODE_PAGE_SUCCESS_END, 0, NULL); - } - - hci_conn = find_connection_by_handle(&rtk_prof, handle); - if (hci_conn == NULL) - { - hci_conn = allocate_connection_by_handle(handle); - if (hci_conn) - { - add_connection_to_hash(&rtk_prof, hci_conn); - hci_conn->profile_bitmap = 0; - memset(hci_conn->profile_refcount, 0, 8); - hci_conn->type = 2; - update_profile_connection(hci_conn, profile_hid, TRUE); // for coex, le is the same as hid - update_hid_active_state(handle, interval); - } - else - { - HILOGE("hci connection allocate fail"); - } - } - else - { - RtkLogMsg("hci connection handle(0x%x) has already exist!", handle); - hci_conn->profile_bitmap = 0; - memset(hci_conn->profile_refcount, 0, 8); - hci_conn->type = 2; - update_profile_connection(hci_conn, profile_hid, TRUE); - update_hid_active_state(handle, interval); - } - } - else if (rtk_prof.ispaging) - { - rtk_prof.ispaging = 0; - RtkLogMsg("notify wifi page unsuccess end"); - rtk_notify_btoperation_to_wifi(BT_OPCODE_PAGE_UNSUCCESS_END, 0, NULL); - } -} - -static void rtk_handle_le_connection_update_complete_evt(uint8_t *p) -{ - uint16_t handle, interval; - uint8_t status; - - status = *p++; - STREAM_TO_UINT16(handle, p); - STREAM_TO_UINT16(interval, p); - update_hid_active_state(handle, interval); -} - -static void rtk_handle_le_meta_evt(uint8_t *p) -{ - uint8_t sub_event = *p++; - switch (sub_event) - { - case HCI_BLE_CONN_COMPLETE_EVT: - rtk_handle_le_connection_complete_evt(p, false); - break; - case HCI_BLE_ENHANCED_CONN_COMPLETE_EVT: - rtk_handle_le_connection_complete_evt(p, true); - break; - case HCI_BLE_LL_CONN_PARAM_UPD_EVT: - rtk_handle_le_connection_update_complete_evt(p); - break; - - default: - break; - } -} - -static int coex_msg_send(char *tx_msg, int msg_size) -{ - int ret = -1; - if (rtk_prof.udpsocket > 0) - { - ret = udpsocket_send(tx_msg, msg_size); - } - else if (rtk_prof.btcoex_chr > 0) - { - ret = btcoex_chr_send(tx_msg, msg_size); - } - return ret; -} - -static int coex_msg_recv(uint8_t *recv_msg, uint8_t *msg_size) -{ - int ret = -1; - if (rtk_prof.udpsocket > 0) - { - ret = udpsocket_recv(recv_msg, msg_size); - } - else if (rtk_prof.btcoex_chr > 0) - { - ret = btcoex_chr_recv(recv_msg, msg_size); - } - return ret; -} -void rtk_parse_internal_event_intercept(uint8_t *p_msg) -{ - uint8_t *p = p_msg; - uint8_t event_code = *p++; - uint8_t len = *p++; - uint16_t opcode, mode_change_handle, mode_interval, subcode; - uint8_t status, num_hci_cmd_pkts; - - switch (event_code) - { - case HCI_INQUIRY_COMP_EVT: - { - if (rtk_prof.isinquirying) - { - rtk_prof.isinquirying = 0; - RtkLogMsg("notify wifi inquiry end"); - rtk_notify_btoperation_to_wifi(BT_OPCODE_INQUIRY_END, 0, NULL); - } - break; - } - - case HCI_PIN_CODE_REQUEST_EVT: - { - if (!rtk_prof.ispairing) - { - rtk_prof.ispairing = 1; - RtkLogMsg("notify wifi pair start"); - rtk_notify_btoperation_to_wifi(BT_OPCODE_PAIR_START, 0, NULL); - } - break; - } - - case HCI_IO_CAPABILITY_REQUEST_EVT: - { - if (!rtk_prof.ispairing) - { - rtk_prof.ispairing = 1; - RtkLogMsg("notify wifi pair start"); - rtk_notify_btoperation_to_wifi(BT_OPCODE_PAIR_START, 0, NULL); - } - break; - } - - case HCI_AUTHENTICATION_COMP_EVT: - { - if (rtk_prof.ispairing) - { - rtk_prof.ispairing = 0; - RtkLogMsg("notify wifi pair end"); - rtk_notify_btoperation_to_wifi(BT_OPCODE_PAIR_END, 0, NULL); - } - break; - } - - case HCI_LINK_KEY_NOTIFICATION_EVT: - { - if (rtk_prof.ispairing) - { - rtk_prof.ispairing = 0; - RtkLogMsg("notify wifi pair end"); - rtk_notify_btoperation_to_wifi(BT_OPCODE_PAIR_END, 0, NULL); - } - break; - } - - case HCI_MODE_CHANGE_EVT: - { - status = *p++; - STREAM_TO_UINT16(mode_change_handle, p); - p++; - STREAM_TO_UINT16(mode_interval, p); - update_hid_active_state(mode_change_handle, mode_interval); - break; - } - - case HCI_COMMAND_COMPLETE_EVT: - rtk_handle_cmd_complete_evt(p, len); - break; - - case HCI_COMMAND_STATUS_EVT: - { - status = *p++; - num_hci_cmd_pkts = *p++; - STREAM_TO_UINT16(opcode, p); - if ((opcode == HCI_INQUIRY) && (status)) - { - if (rtk_prof.isinquirying) - { - rtk_prof.isinquirying = 0; - RtkLogMsg("inquiry start error, notify wifi inquiry stop"); - rtk_notify_btoperation_to_wifi(BT_OPCODE_INQUIRY_END, 0, NULL); - } - } - - if (opcode == HCI_CREATE_CONNECTION) - { - if (!status && !rtk_prof.ispaging) - { - rtk_prof.ispaging = 1; - RtkLogMsg("notify wifi start page"); - rtk_notify_btoperation_to_wifi(BT_OPCODE_PAGE_START, 0, NULL); - } - } - break; - } - - case HCI_CONNECTION_COMP_EVT: - case HCI_ESCO_CONNECTION_COMP_EVT: - rtk_handle_connection_complete_evt(p); - break; - - case HCI_DISCONNECTION_COMP_EVT: - rtk_handle_disconnect_complete_evt(p); - break; - - case HCI_VENDOR_SPECIFIC_EVT: - { - STREAM_TO_UINT16(subcode, p); - if (subcode == HCI_VENDOR_PTA_AUTO_REPORT_EVENT) - { - RtkLogMsg("notify wifi driver with autoreport data"); - if ((len - 2) != 8) - RtkLogMsg("rtk_parse_internal_event_intercept:HCI_VENDOR_SPECIFIC_EVT:HCI_VENDOR_PTA_AUTO_REPORT_EVENT len=%d", len); - rtk_notify_info_to_wifi(AUTO_REPORT, (len - 2), (uint8_t *)p); - } - break; - } - - case HCI_BLE_EVENT: - rtk_handle_le_meta_evt(p); - break; - - default: - break; - } -} - -void rtk_parse_command(uint8_t *pp) -{ - uint8_t *p = pp; - uint16_t cmd; - STREAM_TO_UINT16(cmd, p); - - switch (cmd) - { - case HCI_INQUIRY: - case HCI_PERIODIC_INQUIRY_MODE: - { - if (!rtk_prof.isinquirying) - { - rtk_prof.isinquirying = 1; - RtkLogMsg("notify wifi inquiry start"); - rtk_notify_btoperation_to_wifi(BT_OPCODE_INQUIRY_START, 0, NULL); - } - break; - } - - case HCI_INQUIRY_CANCEL: - case HCI_EXIT_PERIODIC_INQUIRY_MODE: - { - if (rtk_prof.isinquirying) - { - rtk_prof.isinquirying = 0; - RtkLogMsg("notify wifi inquiry stop"); - rtk_notify_btoperation_to_wifi(BT_OPCODE_INQUIRY_END, 0, NULL); - } - break; - } - - case HCI_ACCEPT_CONNECTION_REQUEST: - { - if (!rtk_prof.ispaging) - { - rtk_prof.ispaging = 1; - RtkLogMsg("notify wifi page start"); - rtk_notify_btoperation_to_wifi(BT_OPCODE_PAGE_START, 0, NULL); - } - break; - } - - default: - break; - } -} - -void rtk_parse_l2cap_data(uint8_t *pp, uint8_t direction) -{ - uint16_t handle, total_len, pdu_len, channel_ID, command_len, psm, scid, dcid, result, status; - uint8_t flag, code, identifier; - STREAM_TO_UINT16(handle, pp); - flag = (handle >> HCI_DATA_EVENT_OFFSET) & HCI_DATA_EVENT_MASK; - handle = handle & 0x0FFF; - STREAM_TO_UINT16(total_len, pp); - STREAM_TO_UINT16(pdu_len, pp); - STREAM_TO_UINT16(channel_ID, pp); - - if (flag != RTK_START_PACKET_BOUNDARY) - return; - - if (channel_ID == 0x0001) - { - code = (uint8_t)(*pp++); - switch (code) - { - case L2CAP_CONNECTION_REQ: - identifier = (uint8_t)(*pp++); - STREAM_TO_UINT16(command_len, pp); - STREAM_TO_UINT16(psm, pp); - STREAM_TO_UINT16(scid, pp); - RtkLogMsg("L2CAP_CONNECTION_REQ, handle=%x, PSM=%x, scid=%x", handle, psm, scid); - handle_l2cap_con_req(handle, psm, scid, direction); - break; - - case L2CAP_CONNECTION_RSP: - identifier = (uint8_t)(*pp++); - STREAM_TO_UINT16(command_len, pp); - STREAM_TO_UINT16(dcid, pp); - STREAM_TO_UINT16(scid, pp); - STREAM_TO_UINT16(result, pp); - STREAM_TO_UINT16(status, pp); - RtkLogMsg("L2CAP_CONNECTION_RESP, handle=%x, dcid=%x, scid=%x, result=%x", handle, dcid, scid, result); - // if(result == 0) - handle_l2cap_con_rsp(handle, dcid, scid, direction, result); - break; - - case L2CAP_DISCONNECTION_REQ: - identifier = (uint8_t)(*pp++); - STREAM_TO_UINT16(command_len, pp); - STREAM_TO_UINT16(dcid, pp); - STREAM_TO_UINT16(scid, pp); - RtkLogMsg("L2CAP_DISCONNECTION_REQ, handle=%x, dcid=%x, scid=%x", handle, dcid, scid); - handle_l2cap_discon_req(handle, dcid, scid, direction); - break; - - case L2CAP_DISCONNECTION_RSP: - break; - - default: - break; - } - } - else - { - if ((flag != 0x01) && (is_profile_connected(profile_a2dp) || is_profile_connected(profile_pan))) // Do not count the continuous packets - packets_count(handle, channel_ID, pdu_len, direction, pp); - } -} - -void rtk_add_le_profile(BD_ADDR bdaddr, uint16_t handle, uint8_t profile_map) -{ - RTK_UNUSED(bdaddr); - RtkLogMsg("rtk_add_le_profile, handle is %x, profile_map is %x", handle, profile_map); - - tRTK_CONN_PROF *hci_conn = find_connection_by_handle(&rtk_prof, handle); - if (hci_conn) - { - if ((profile_map & 0x01) || (profile_map & 0x02)) // bit0: mouse, bit1:keyboard - update_profile_connection(hci_conn, profile_hogp, TRUE); - - if (profile_map & 0x04) - update_profile_connection(hci_conn, profile_voice, TRUE); - } - else - { - HILOGE("rtk_add_le_profile, connection handle(0x%x) not exist!", handle); - } -} - -void rtk_delete_le_profile(BD_ADDR bdaddr, uint16_t handle, uint8_t profile_map) -{ - RTK_UNUSED(bdaddr); - RtkLogMsg("rtk_delete_le_profile, handle is %x, profile_map is %x", handle, profile_map); - - pthread_mutex_lock(&rtk_prof.profile_mutex); - tRTK_CONN_PROF *hci_conn = find_connection_by_handle(&rtk_prof, handle); - if (hci_conn == NULL) - { - HILOGE("rtk_delete_le_profile, hci_conn not exist with handle %x", handle); - } - else - { - if ((profile_map & 0x01) || (profile_map & 0x02)) // bit0: mouse, bit1:keyboard - update_profile_connection(hci_conn, profile_hogp, FALSE); - - if (profile_map & 0x04) - update_profile_connection(hci_conn, profile_voice, FALSE); - } - pthread_mutex_unlock(&rtk_prof.profile_mutex); -} - -void rtk_add_le_data_count(uint8_t data_type) -{ - RtkLogMsg("rtk_add_le_data_count, data_type is %x", data_type); - - if ((data_type == 1) || (data_type == 2)) // 1:keyboard, 2:mouse - { - rtk_prof.hogp_packet_count++; - if (!is_profile_busy(profile_hogp)) - { - RtkLogMsg("hogp idle->busy"); - update_profile_state(profile_hogp, TRUE); - } - } - - if (data_type == 3) // voice - { - rtk_prof.voice_packet_count++; - if (!is_profile_busy(profile_voice)) - { - RtkLogMsg("voice idle->busy"); - update_profile_state(profile_voice, TRUE); - } - } -} - -void rtk_set_bt_on(uint8_t bt_on) -{ - RtkLogMsg("bt stack is init"); - rtk_prof.bt_on = bt_on; - uint8_t ttmp[1] = {1}; - rtk_vendor_cmd_to_fw(0xfc1b, 1, ttmp, NULL); -} - -static rtk_parse_manager_t parse_interface = { - rtk_parse_internal_event_intercept, - rtk_parse_l2cap_data, - rtk_parse_init, - rtk_parse_cleanup, - rtk_parse_command, - rtk_add_le_profile, - rtk_delete_le_profile, - rtk_add_le_data_count, - rtk_set_bt_on, -}; - -rtk_parse_manager_t *rtk_parse_manager_get_interface() -{ - return &parse_interface; -} - -void hw_process_event(HC_BT_HDR *p_buf) -{ - uint16_t opcode; - uint8_t *p = (uint8_t *)(p_buf + 1) + HCI_EVT_CMD_CMPL_OPCODE; - STREAM_TO_UINT16(opcode, p); - - HILOGD("%s, opcode:0x%04x", __FUNCTION__, opcode); - switch (opcode) - { - case HCI_VSC_UPDATE_BAUDRATE: - case HCI_VSC_READ_CHIP_TYPE: - case HCI_VSC_H5_INIT: - case HCI_VSC_DOWNLOAD_FW_PATCH: - case HCI_READ_LMP_VERSION: - case HCI_VSC_READ_ROM_VERSION: - case HCI_VENDOR_RESET: - hw_usb_config_cback(p_buf); - break; - -#if (HW_END_WITH_HCI_RESET == TRUE) - case HCI_RESET: - hw_epilog_cback(p_buf); - break; -#endif - - case 0xfc1b: - case HCI_CMD_VNDR_HEARTBEAT: - case HCI_VENDOR_SET_PROFILE_REPORT_COMMAND: - case HCI_VENDOR_ADD_BITPOOL_FW: - case HCI_VENDOR_MAILBOX_CMD: - rtk_cmd_complete_cback(p_buf); - break; - } - - HILOGD("%s, Complete", __FUNCTION__); -} \ No newline at end of file diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/rtk_poll.c b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/rtk_poll.c deleted file mode 100755 index d7409f36..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/rtk_poll.c +++ /dev/null @@ -1,263 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -/****************************************************************************** - * - * Filename: poll.c - * - * Description: Contains host & controller handshake implementation - * - ******************************************************************************/ - -#define LOG_TAG "bt_poll" - -#include -#include -#include -#include -#include "bt_hci_bdroid.h" -//#include "bt_utils.h" -#include "rtk_poll.h" - -/****************************************************************************** -** Constants & Macros -******************************************************************************/ -#ifndef BTPOLL_DBG -#define BTPOLL_DBG false -#endif - -#if (BTPOLL_DBG == true) -#define BTPOLLDBG(param, ...) \ - { \ - HILOGD(param, ##__VA_ARGS__); \ - } -#else -#define BTPOLLDBG(param, ...) \ - { \ - } -#endif - -#ifndef ENABLE_BT_POLL_IN_ACTIVE_MODE -#define ENABLE_BT_POLL_IN_ACTIVE_MODE false -#endif - -#ifndef DEFAULT_POLL_IDLE_TIMEOUT -#define DEFAULT_POLL_IDLE_TIMEOUT 2500 -#endif - -volatile uint32_t rtkbt_heartbeat_noack_num = 0; -volatile uint32_t rtkbt_heartbeat_evt_seqno = 0xffffffff; - -timed_out poll_idle_timeout; - -/****************************************************************************** -** Externs -******************************************************************************/ - -/****************************************************************************** -** Local type definitions -******************************************************************************/ - -/* Poll state */ -enum -{ - POLL_DISABLED = 0, /* initial state */ - POLL_ENABLED, -}; - -/* poll control block */ -typedef struct -{ - uint8_t state; /* poll state */ - uint8_t timer_created; - timer_t timer_id; - uint32_t timeout_ms; -} bt_poll_cb_t; - -extern int timer_create(clockid_t clockid, struct sigevent *sevp, - timer_t *timerid); -extern int timer_delete(timer_t timerid); - -int timer_settime(timer_t timerid, int flags, - const struct itimerspec *new_value, - struct itimerspec *old_value); -/****************************************************************************** -** Static variables -******************************************************************************/ - -static bt_poll_cb_t bt_poll_cb; - -/****************************************************************************** -** Poll Static Functions -******************************************************************************/ - -/******************************************************************************* -** -** Function poll_timer_stop -** -** Description stop timer if allowed -** -** Returns None -** -*******************************************************************************/ -static void poll_timer_stop(void) -{ - int status; - struct itimerspec ts; - - HILOGI("poll_timer_stop: timer_created %d", bt_poll_cb.timer_created); - - if (bt_poll_cb.timer_created == true) - { - ts.it_value.tv_sec = 0; - ts.it_value.tv_nsec = 0; - ts.it_interval.tv_sec = 0; - ts.it_interval.tv_nsec = 0; - - status = timer_settime(bt_poll_cb.timer_id, 0, &ts, 0); - if (status == -1) - HILOGE("[STOP] Failed to set poll idle timeout"); - } -} - -/***************************************************************************** -** POLL Interface Functions -*****************************************************************************/ - -/******************************************************************************* -** -** Function poll_init -** -** Description Init bt poll -** -** Returns None -** -*******************************************************************************/ -void poll_init(timed_out ptr_timeout, uint32_t timeout) -{ - memset((void *)&bt_poll_cb, 0, sizeof(bt_poll_cb_t)); - poll_idle_timeout = ptr_timeout; - bt_poll_cb.state = POLL_DISABLED; - bt_poll_cb.timeout_ms = timeout; - - HILOGI("poll_init: state %d, timeout %d ms,timeout=%d", bt_poll_cb.state, bt_poll_cb.timeout_ms, timeout); -} - -/******************************************************************************* -** -** Function poll_cleanup -** -** Description Poll clean up -** -** Returns None -** -*******************************************************************************/ -void poll_cleanup(void) -{ - HILOGI("poll_cleanup: timer_created %d", bt_poll_cb.timer_created); - - if (bt_poll_cb.timer_created == true) - { - timer_delete(bt_poll_cb.timer_id); - } -} - -/******************************************************************************* -** -** Function poll_enable -** -** Description Enalbe/Disable poll -** -** Returns None -** -*******************************************************************************/ -void poll_enable(uint8_t turn_on) -{ - HILOGI("poll_enable: turn_on %d, state %d", turn_on, bt_poll_cb.state); - - if ((turn_on == true) && (bt_poll_cb.state == POLL_ENABLED)) - { - HILOGI("poll_enable: poll is already on!!!"); - return; - } - else if ((turn_on == false) && (bt_poll_cb.state == POLL_DISABLED)) - { - HILOGI("poll_enable: poll is already off!!!"); - return; - } - - if (turn_on == false) - { - poll_timer_stop(); - bt_poll_cb.state = POLL_DISABLED; - } - else - { - /* start poll timer when poll_timer_flush invoked first time */ - bt_poll_cb.state = POLL_ENABLED; - } -} - -/******************************************************************************* -** -** Function poll_timer_flush -** -** Description Called to delay notifying Bluetooth chip. -** Normally this is called when there is data to be sent -** over HCI. -** -** Returns None -** -*******************************************************************************/ -void poll_timer_flush(void) -{ - int status; - struct itimerspec ts; - struct sigevent se; - - memset(&se, 0, sizeof(struct sigevent)); - BTPOLLDBG("poll_timer_flush: state %d", bt_poll_cb.state); - - if (bt_poll_cb.state != POLL_ENABLED) - return; - - if (bt_poll_cb.timer_created == false) - { - se.sigev_notify = SIGEV_THREAD; - se.sigev_value.sival_ptr = &bt_poll_cb.timer_id; - se.sigev_notify_function = poll_idle_timeout; - se.sigev_notify_attributes = NULL; - - status = timer_create(CLOCK_MONOTONIC, &se, &bt_poll_cb.timer_id); - - if (status == 0) - bt_poll_cb.timer_created = true; - } -#if (defined(ENABLE_BT_POLL_IN_ACTIVE_MODE) && (ENABLE_BT_POLL_IN_ACTIVE_MODE == false)) - if (bt_poll_cb.timer_created == true) - { - ts.it_value.tv_sec = bt_poll_cb.timeout_ms / 1000; - ts.it_value.tv_nsec = 1000 * 1000 * (bt_poll_cb.timeout_ms % 1000); - ts.it_interval.tv_sec = 0; - ts.it_interval.tv_nsec = 0; - - status = timer_settime(bt_poll_cb.timer_id, 0, &ts, 0); - if (status == -1) - HILOGE("[Flush] Failed to set poll idle timeout"); - } -#endif -} diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/rtk_socket.c b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/rtk_socket.c deleted file mode 100755 index b0d27de5..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/rtk_socket.c +++ /dev/null @@ -1,190 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -/****************************************************************************** - * - * Filename: userial_vendor.c - * - * Description: Contains vendor-specific userial functions - * - ******************************************************************************/ -#undef NDEBUG -#define LOG_TAG "rtk_socket" - -#include -#include -#include -#include -#include -#include -#include "userial.h" -#include "userial_vendor.h" -#include "rtk_socket.h" - -/****************************************************************************** -** Constants & Macros -******************************************************************************/ - -/****************************************************************************** -** Extern functions -******************************************************************************/ - -/****************************************************************************** -** Local type definitions -******************************************************************************/ - -/****************************************************************************** -** Static functions -******************************************************************************/ - -/****************************************************************************** -** functions -******************************************************************************/ -uint32_t Skt_Read(int fd, uint8_t *p_buf, uint32_t len, bool *condition) -{ - int n_read = 0; - struct pollfd pfd; - - if (fd == -1) - { - return 0; - } - - while (n_read < (int)len) - { - if (condition && !(*condition)) - return n_read; - pfd.fd = fd; - pfd.events = POLLIN | POLLHUP | POLLNVAL | POLLRDHUP; - - /* make sure there is data prior to attempting read to avoid blocking - a read for more than poll timeout */ - - int poll_ret; - RTK_NO_INTR(poll_ret = poll(&pfd, 1, 100)); - if (poll_ret == 0) - { - continue; - } - if (poll_ret < 0) - { - HILOGE("%s(): poll() failed: return %d errno %d (%s)", - __func__, poll_ret, errno, strerror(errno)); - break; - } - - if (pfd.revents & (POLLHUP | POLLNVAL | POLLRDHUP)) - { - return 0; - } - - ssize_t n; - RTK_NO_INTR(n = recv(fd, p_buf + n_read, len - n_read, 0)); - - if (n == 0) - { - HILOGE("Skt_Read : channel detached remotely"); - return 0; - } - - if (n < 0) - { - HILOGE("Skt_Read : read failed (%s)", strerror(errno)); - return 0; - } - - n_read += n; - } - - return n_read; -} - -int Skt_Read_noblock(int fd, uint8_t *p_buf, uint32_t len) -{ - int n_read = 0; - struct pollfd pfd; - - if (fd == -1) - { - HILOGE("UIPC_Read_noblock closed"); - return 0; - } - - pfd.fd = fd; - pfd.events = POLLIN | POLLHUP | POLLRDHUP; - - if (poll(&pfd, 1, 0) == 0) - { - return 0; - } - - if (pfd.revents & (POLLHUP | POLLNVAL | POLLRDHUP)) - { - return 0; - } - - n_read = recv(fd, p_buf, len, MSG_DONTWAIT | MSG_NOSIGNAL); - - return n_read; -} - -bool Skt_Send(int fd, uint8_t *p_buf, uint16_t msglen) -{ - ssize_t ret; - RTK_NO_INTR(ret = write(fd, p_buf, msglen)); - if (ret < 0) - { - HILOGE("failed to write (%s)", strerror(errno)); - } - - return false; -} - -int Skt_Send_noblock(int fd, uint8_t *p_buf, uint16_t msglen) -{ - int res = 0; - struct pollfd pfd; - - pfd.fd = fd; - pfd.events = POLLOUT | POLLHUP; - if (poll(&pfd, 1, 0) == 0) - { - return 0; - } - - if (pfd.revents & (POLLHUP | POLLNVAL)) - { - HILOGE("poll : channel detached remotely"); - return 0; - } - - res = send(fd, p_buf, msglen, MSG_DONTWAIT); - if (res < 0) - { - HILOGE("failed to write (%s)", strerror(errno)); - } - - return res; -} - -/****************************************************************************** -** Static variables -******************************************************************************/ - -/***************************************************************************** -** Helper Functions -*****************************************************************************/ diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/upio.c b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/upio.c deleted file mode 100755 index b1759d6e..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/upio.c +++ /dev/null @@ -1,543 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -/****************************************************************************** - * - * Filename: upio.c - * - * Description: Contains I/O functions, like - * rfkill control - * BT_WAKE/HOST_WAKE control - * - ******************************************************************************/ - -#define LOG_TAG "bt_upio" - -#include -#include -#include -#include "bt_vendor_rtk.h" -#include "upio.h" -#include "userial_vendor.h" - -/****************************************************************************** -** Constants & Macros -******************************************************************************/ - -#ifndef UPIO_DBG -#define UPIO_DBG FALSE -#endif - -#if (UPIO_DBG == TRUE) -#define UPIODBG(param, ...) \ - { \ - HILOGD(param, ##__VA_ARGS__); \ - } -#else -#define UPIODBG(param, ...) \ - { \ - } -#endif - -/****************************************************************************** -** Local type definitions -******************************************************************************/ - -#if (BT_WAKE_VIA_PROC == TRUE) - -/* proc fs node for enable/disable lpm mode */ -#ifndef VENDOR_LPM_PROC_NODE -#define VENDOR_LPM_PROC_NODE "/proc/bluetooth/sleep/lpm" -#endif - -/* proc fs node for notifying write request */ -#ifndef VENDOR_BTWRITE_PROC_NODE -#define VENDOR_BTWRITE_PROC_NODE "/proc/bluetooth/sleep/btwrite" -#endif - -/* - * Maximum btwrite assertion holding time without consecutive btwrite kicking. - * This value is correlative(shorter) to the in-activity timeout period set in - * the bluesleep LPM code. The current value used in bluesleep is 10sec. - */ -#ifndef PROC_BTWRITE_TIMER_TIMEOUT_MS -#define PROC_BTWRITE_TIMER_TIMEOUT_MS 8000 -#endif - -/* lpm proc control block */ -typedef struct -{ - uint8_t btwrite_active; - uint8_t timer_created; - timer_t timer_id; - uint32_t timeout_ms; -} vnd_lpm_proc_cb_t; - -static vnd_lpm_proc_cb_t lpm_proc_cb; -#endif - -/****************************************************************************** -** Static variables -******************************************************************************/ - -static uint8_t upio_state[UPIO_MAX_COUNT]; -static int rfkill_id = -1; -static int bt_emul_enable = 0; -static char *rfkill_state_path = NULL; - -/****************************************************************************** -** Static functions -******************************************************************************/ - -/* for friendly debugging outpout string */ -static char *lpm_mode[] = { - "UNKNOWN", - "disabled", - "enabled"}; - -static char *lpm_state[] = { - "UNKNOWN", - "de-asserted", - "asserted"}; - -/***************************************************************************** -** Bluetooth On/Off Static Functions -*****************************************************************************/ -static int is_emulator_context(void) -{ - char value[PROPERTY_VALUE_MAX]; - - memset(value, 0, sizeof(value)); - strcpy(value, "1"); - UPIODBG("is_emulator_context : %s", value); - if (strcmp(value, "1") == 0) - { - return 1; - } - return 0; -} - -static int is_rfkill_disabled(void) -{ - char value[PROPERTY_VALUE_MAX]; - - memset(value, 0, sizeof(value)); - strcpy(value, "0"); - UPIODBG("is_rfkill_disabled ? [%s]", value); - - if (strcmp(value, "1") == 0) - { - return UPIO_BT_POWER_ON; - } - - return UPIO_BT_POWER_OFF; -} - -static int init_rfkill() -{ - char path[64]; - char buf[16]; - int fd, sz, id; - - if (is_rfkill_disabled()) - return -1; - - for (id = 0;; id++) - { - snprintf(path, sizeof(path), "/sys/class/rfkill/rfkill%d/type", id); - fd = open(path, O_RDONLY); - if (fd < 0) - { - HILOGE("init_rfkill : open(%s) failed: %s (%d)\n", - path, strerror(errno), errno); - return -1; - } - - sz = read(fd, &buf, sizeof(buf)); - close(fd); - - if (sz >= 9 && memcmp(buf, "bluetooth", 9) == 0) - { - rfkill_id = id; - - break; - } - } - - asprintf(&rfkill_state_path, "/sys/class/rfkill/rfkill%d/state", rfkill_id); - return 0; -} - -int bt_wake_up_host_mode_set(uint8_t mode) -{ - char path[64]; - char buffer = '0'; - int sz; - int fd = -1; - int ret = -1; - HILOGE("bt_wake_up_host_mode_set"); - - snprintf(path, sizeof(path), "/proc/bluetooth/sleep/lpm"); - HILOGE("bt_wake_up_host_mode_set path:%s", path); - - fd = open(path, O_WRONLY); - if (fd < 0) - { - HILOGE("bt_wake_up_host_mode_set fd:%d = open(path, O_RDWR): open(%s) failed: %s (%d)\n", - fd, path, strerror(errno), errno); - return -1; - } - - HILOGE("bt_wake_up_host_mode_set fd:%d = open(path, O_RDWR): open(%s) success\n", - fd, path); - - if (mode == 1) - { - buffer = '1'; - } - else - { - buffer = '0'; - } - - HILOGE("bt_wake_up_host_mode_set buffer:%d", buffer); - sz = write(fd, &buffer, 1); - - if (sz < 0) - { - HILOGE("bt_wake_up_host_mode_set : write(%s) failed: %s (%d)", - rfkill_state_path, strerror(errno), errno); - } - else - ret = 0; - - if (fd >= 0) - close(fd); - - return ret; -} - -/***************************************************************************** -** LPM Static Functions -*****************************************************************************/ - -#if (BT_WAKE_VIA_PROC == TRUE) -/******************************************************************************* -** -** Function proc_btwrite_timeout -** -** Description Timeout thread of proc/.../btwrite assertion holding timer -** -** Returns None -** -*******************************************************************************/ -static void proc_btwrite_timeout(union sigval arg) -{ - UPIODBG("..%s..", __FUNCTION__); - lpm_proc_cb.btwrite_active = FALSE; -} -#endif - -/***************************************************************************** -** UPIO Interface Functions -*****************************************************************************/ - -/******************************************************************************* -** -** Function upio_init -** -** Description Initialization -** -** Returns None -** -*******************************************************************************/ -void upio_init(void) -{ - memset(upio_state, UPIO_UNKNOWN, UPIO_MAX_COUNT); -#if (BT_WAKE_VIA_PROC == TRUE) - memset(&lpm_proc_cb, 0, sizeof(vnd_lpm_proc_cb_t)); -#endif -} - -/******************************************************************************* -** -** Function upio_cleanup -** -** Description Clean up -** -** Returns None -** -*******************************************************************************/ -void upio_cleanup(void) -{ -#if (BT_WAKE_VIA_PROC == TRUE) - if (lpm_proc_cb.timer_created == TRUE) - timer_delete(lpm_proc_cb.timer_id); - - lpm_proc_cb.timer_created = FALSE; -#endif -} - -/******************************************************************************* -** -** Function upio_set_bluetooth_power -** -** Description Interact with low layer driver to set Bluetooth power -** on/off. -** -** Returns 0 : SUCCESS or Not-Applicable -** <0 : ERROR -** -*******************************************************************************/ -int upio_set_bluetooth_power(int on) -{ - int sz; - int fd = -1; - int ret = -1; - char buffer = '0'; - - switch (on) - { - case UPIO_BT_POWER_OFF: - buffer = '0'; - break; - - case UPIO_BT_POWER_ON: - buffer = '1'; - break; - } - - if (is_emulator_context()) - { - /* if new value is same as current, return -1 */ - if (bt_emul_enable == on) - return ret; - - UPIODBG("set_bluetooth_power [emul] %d", on); - - bt_emul_enable = on; - return 0; - } - - /* check if we have rfkill interface */ - if (is_rfkill_disabled()) - return 0; - - if (rfkill_id == -1) - { - if (init_rfkill()) - return ret; - } - - fd = open(rfkill_state_path, O_WRONLY); - - if (fd < 0) - { - HILOGE("set_bluetooth_power : open(%s) for write failed: %s (%d)", - rfkill_state_path, strerror(errno), errno); - return ret; - } - - sz = write(fd, &buffer, 1); - - if (sz < 0) - { - HILOGE("set_bluetooth_power : write(%s) failed: %s (%d)", - rfkill_state_path, strerror(errno), errno); - } - else - ret = 0; - - if (fd >= 0) - close(fd); - - return ret; -} - -/******************************************************************************* -** -** Function upio_set -** -** Description Set i/o based on polarity -** -** Returns None -** -*******************************************************************************/ -void upio_set(uint8_t pio, uint8_t action, uint8_t polarity) -{ - // int rc; - RTK_UNUSED(polarity); -#if (BT_WAKE_VIA_PROC == TRUE) - int fd = -1; - char buffer; -#endif - - switch (pio) - { - case UPIO_LPM_MODE: - if (upio_state[UPIO_LPM_MODE] == action) - { - RTK_UNUSED(lpm_mode[action]); - UPIODBG("LPM is %s already", lpm_mode[action]); - return; - } - - upio_state[UPIO_LPM_MODE] = action; - -#if (BT_WAKE_VIA_PROC == TRUE) - fd = open(VENDOR_LPM_PROC_NODE, O_WRONLY); - - if (fd < 0) - { - HILOGE("upio_set : open(%s) for write failed: %s (%d)", - VENDOR_LPM_PROC_NODE, strerror(errno), errno); - return; - } - - if (action == UPIO_ASSERT) - { - buffer = '1'; - } - else - { - buffer = '0'; - - // delete btwrite assertion holding timer - if (lpm_proc_cb.timer_created == TRUE) - { - timer_delete(lpm_proc_cb.timer_id); - lpm_proc_cb.timer_created = FALSE; - } - } - - if (write(fd, &buffer, 1) < 0) - { - HILOGE("upio_set : write(%s) failed: %s (%d)", - VENDOR_LPM_PROC_NODE, strerror(errno), errno); - } - else - { - if (action == UPIO_ASSERT) - { - // create btwrite assertion holding timer - if (lpm_proc_cb.timer_created == FALSE) - { - int status; - struct sigevent se; - - se.sigev_notify = SIGEV_THREAD; - se.sigev_value.sival_ptr = &lpm_proc_cb.timer_id; - se.sigev_notify_function = proc_btwrite_timeout; - se.sigev_notify_attributes = NULL; - - status = timer_create(CLOCK_MONOTONIC, &se, - &lpm_proc_cb.timer_id); - - if (status == 0) - lpm_proc_cb.timer_created = TRUE; - } - } - } - - if (fd >= 0) - close(fd); -#endif - break; - - case UPIO_BT_WAKE: - if (upio_state[UPIO_BT_WAKE] == action) - { - RTK_UNUSED(lpm_state[action]); - UPIODBG("BT_WAKE is %s already", lpm_state[action]); - -#if (BT_WAKE_VIA_PROC == TRUE) - if (lpm_proc_cb.btwrite_active == TRUE) - /* - * The proc btwrite node could have not been updated for - * certain time already due to heavy downstream path flow. - * In this case, we want to explicity touch proc btwrite - * node to keep the bt_wake assertion in the LPM kernel - * driver. The current kernel bluesleep LPM code starts - * a 10sec internal in-activity timeout timer before it - * attempts to deassert BT_WAKE line. - */ -#endif - return; - } - - upio_state[UPIO_BT_WAKE] = action; - -#if (BT_WAKE_VIA_USERIAL_IOCTL == TRUE) - - userial_vendor_ioctl(((action == UPIO_ASSERT) ? USERIAL_OP_ASSERT_BT_WAKE : USERIAL_OP_DEASSERT_BT_WAKE), - NULL); - -#elif (BT_WAKE_VIA_PROC == TRUE) - - /* - * Kick proc btwrite node only at UPIO_ASSERT - */ - if (action == UPIO_DEASSERT) - return; - - fd = open(VENDOR_BTWRITE_PROC_NODE, O_WRONLY); - - if (fd < 0) - { - HILOGE("upio_set : open(%s) for write failed: %s (%d)", - VENDOR_BTWRITE_PROC_NODE, strerror(errno), errno); - return; - } - - buffer = '1'; - - if (write(fd, &buffer, 1) < 0) - { - HILOGE("upio_set : write(%s) failed: %s (%d)", - VENDOR_BTWRITE_PROC_NODE, strerror(errno), errno); - } - else - { - lpm_proc_cb.btwrite_active = TRUE; - - if (lpm_proc_cb.timer_created == TRUE) - { - struct itimerspec ts; - - ts.it_value.tv_sec = PROC_BTWRITE_TIMER_TIMEOUT_MS / 1000; - ts.it_value.tv_nsec = 1000 * (PROC_BTWRITE_TIMER_TIMEOUT_MS % 1000); - ts.it_interval.tv_sec = 0; - ts.it_interval.tv_nsec = 0; - - timer_settime(lpm_proc_cb.timer_id, 0, &ts, 0); - } - } - - UPIODBG("proc btwrite assertion"); - - if (fd >= 0) - close(fd); -#endif - - break; - - case UPIO_HOST_WAKE: - UPIODBG("upio_set: UPIO_HOST_WAKE"); - break; - } -} diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/userial_vendor.c b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/userial_vendor.c deleted file mode 100755 index e6d16cab..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/libbt-vendor/src/userial_vendor.c +++ /dev/null @@ -1,2651 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ - -/****************************************************************************** - * - * Filename: userial_vendor.c - * - * Description: Contains vendor-specific userial functions - * - ******************************************************************************/ -#undef NDEBUG -#define LOG_TAG "bt_userial_vendor" - -#include -#include -#include -#include -#include -#include -#include "userial.h" -#include "userial_vendor.h" -#include "rtk_socket.h" -#include - -#ifdef CONFIG_SCO_OVER_HCI -#include "sbc.h" -#endif -/****************************************************************************** -** Constants & Macros -******************************************************************************/ - -#ifndef VNDUSERIAL_DBG -#define VNDUSERIAL_DBG TRUE -#endif - -#if (VNDUSERIAL_DBG == TRUE) -#define VNDUSERIALDBG(param, ...) \ - { \ - HILOGD(param, ##__VA_ARGS__); \ - } -#else -#define VNDUSERIALDBG(param, ...) \ - { \ - } -#endif - -#define VND_PORT_NAME_MAXLEN 256 - -#ifndef BT_CHIP_HW_FLOW_CTRL_ON -#define BT_CHIP_HW_FLOW_CTRL_ON TRUE -#endif - -/****************************************************************************** -** Extern functions -******************************************************************************/ -extern char rtkbt_transtype; -extern void Heartbeat_cleanup(); -extern void Heartbeat_init(); - -/****************************************************************************** -** Local type definitions -******************************************************************************/ -#if !defined(EFD_SEMAPHORE) -#define EFD_SEMAPHORE (1 << 0) -#endif - -#define RTK_DATA_RECEIVED 1 -#define RTK_DATA_SEND 0 -struct rtk_object_t -{ - int fd; // the file descriptor to monitor for events. - void *context; // a context that's passed back to the *_ready functions.. - pthread_mutex_t lock; // protects the lifetime of this object and all variables. - - void (*read_ready)(void *context); // function to call when the file descriptor becomes readable. - void (*write_ready)(void *context); // function to call when the file descriptor becomes writeable. -}; - -/* vendor serial control block */ -typedef struct -{ - int fd; /* fd to Bluetooth device */ - int uart_fd[2]; - int signal_fd[2]; - int epoll_fd; - int cpoll_fd; - int event_fd; - struct termios termios; /* serial terminal of BT port */ - char port_name[VND_PORT_NAME_MAXLEN]; - pthread_t thread_socket_id; - pthread_t thread_uart_id; - pthread_t thread_coex_id; - bool thread_running; - - RTB_QUEUE_HEAD *recv_data; - RTB_QUEUE_HEAD *send_data; - RTB_QUEUE_HEAD *data_order; - volatile bool btdriver_state; -} vnd_userial_cb_t; - -#ifdef CONFIG_SCO_OVER_HCI -uint16_t btui_msbc_h2[] = {0x0801, 0x3801, 0xc801, 0xf801}; -typedef struct -{ - pthread_mutex_t sco_recv_mutex; - pthread_cond_t sco_recv_cond; - pthread_mutex_t sco_send_mutex; - pthread_t thread_socket_sco_id; - pthread_t thread_recv_sco_id; - pthread_t thread_send_sco_id; - uint16_t sco_handle; - bool thread_sco_running; - bool thread_recv_sco_running; - bool thread_send_sco_running; - uint16_t voice_settings; - RTB_QUEUE_HEAD *recv_sco_data; - RTB_QUEUE_HEAD *send_sco_data; - unsigned char enc_data[480]; - unsigned int current_pos; - uint16_t sco_packet_len; - bool msbc_used; - int ctrl_fd, data_fd; - sbc_t sbc_dec, sbc_enc; - uint32_t pcm_enc_seq; - int signal_fd[2]; -} sco_cb_t; -#endif - -/****************************************************************************** -** Static functions -******************************************************************************/ -static void h5_data_ready_cb(serial_data_type_t type, unsigned int total_length); -static uint16_t h5_int_transmit_data_cb(serial_data_type_t type, uint8_t *data, uint16_t length); -extern void RTK_btservice_destroyed(); -/****************************************************************************** -** Static variables -******************************************************************************/ -#ifdef CONFIG_SCO_OVER_HCI -static sco_cb_t sco_cb; -#endif -static vnd_userial_cb_t vnd_userial; -static const hci_h5_t *h5_int_interface; -static int packet_recv_state = RTKBT_PACKET_IDLE; -static unsigned int packet_bytes_need = 0; -static serial_data_type_t current_type = 0; -static struct rtk_object_t rtk_socket_object; -static struct rtk_object_t rtk_coex_object; -static unsigned char h4_read_buffer[2048] = {0}; -static int h4_read_length = 0; - -static int coex_packet_recv_state = RTKBT_PACKET_IDLE; -static int coex_packet_bytes_need = 0; -static serial_data_type_t coex_current_type = 0; -static unsigned char coex_resvered_buffer[2048] = {0}; -static int coex_resvered_length = 0; - -#ifdef RTK_HANDLE_EVENT -static int received_packet_state = RTKBT_PACKET_IDLE; -static unsigned int received_packet_bytes_need = 0; -static serial_data_type_t recv_packet_current_type = 0; -static unsigned char received_resvered_header[2048] = {0}; -static int received_resvered_length = 0; -static rtkbt_version_t rtkbt_version; -static rtkbt_lescn_t rtkbt_adv_con; -#endif - -static rtk_parse_manager_t *rtk_parse_manager = NULL; - -static hci_h5_callbacks_t h5_int_callbacks = { - .h5_int_transmit_data_cb = h5_int_transmit_data_cb, - .h5_data_ready_cb = h5_data_ready_cb, -}; - -static const uint8_t hci_preamble_sizes[] = { - COMMAND_PREAMBLE_SIZE, - ACL_PREAMBLE_SIZE, - SCO_PREAMBLE_SIZE, - EVENT_PREAMBLE_SIZE}; - -/***************************************************************************** -** Helper Functions -*****************************************************************************/ - -/******************************************************************************* -** -** Function userial_to_tcio_baud -** -** Description helper function converts USERIAL baud rates into TCIO -** conforming baud rates -** -** Returns TRUE/FALSE -** -*******************************************************************************/ -uint8_t userial_to_tcio_baud(uint8_t cfg_baud, uint32_t *baud) -{ - if (cfg_baud == USERIAL_BAUD_115200) - *baud = B115200; - else if (cfg_baud == USERIAL_BAUD_4M) - *baud = B4000000; - else if (cfg_baud == USERIAL_BAUD_3M) - *baud = B3000000; - else if (cfg_baud == USERIAL_BAUD_2M) - *baud = B2000000; - else if (cfg_baud == USERIAL_BAUD_1M) - *baud = B1000000; - else if (cfg_baud == USERIAL_BAUD_1_5M) - *baud = B1500000; - else if (cfg_baud == USERIAL_BAUD_921600) - *baud = B921600; - else if (cfg_baud == USERIAL_BAUD_460800) - *baud = B460800; - else if (cfg_baud == USERIAL_BAUD_230400) - *baud = B230400; - else if (cfg_baud == USERIAL_BAUD_57600) - *baud = B57600; - else if (cfg_baud == USERIAL_BAUD_19200) - *baud = B19200; - else if (cfg_baud == USERIAL_BAUD_9600) - *baud = B9600; - else if (cfg_baud == USERIAL_BAUD_1200) - *baud = B1200; - else if (cfg_baud == USERIAL_BAUD_600) - *baud = B600; - else - { - HILOGE("userial vendor open: unsupported baud idx %i", cfg_baud); - *baud = B115200; - return FALSE; - } - - return TRUE; -} - -#if (BT_WAKE_VIA_USERIAL_IOCTL == TRUE) -/******************************************************************************* -** -** Function userial_ioctl_init_bt_wake -** -** Description helper function to set the open state of the bt_wake if ioctl -** is used. it should not hurt in the rfkill case but it might -** be better to compile it out. -** -** Returns none -** -*******************************************************************************/ -void userial_ioctl_init_bt_wake(int fd) -{ - uint32_t bt_wake_state; - - /* assert BT_WAKE through ioctl */ - ioctl(fd, USERIAL_IOCTL_BT_WAKE_ASSERT, NULL); - ioctl(fd, USERIAL_IOCTL_BT_WAKE_GET_ST, &bt_wake_state); - VNDUSERIALDBG("userial_ioctl_init_bt_wake read back BT_WAKE state=%i", - bt_wake_state); -} -#endif // (BT_WAKE_VIA_USERIAL_IOCTL==TRUE) - -/***************************************************************************** -** Userial Vendor API Functions -*****************************************************************************/ - -/******************************************************************************* -** -** Function userial_vendor_init -** -** Description Initialize userial vendor-specific control block -** -** Returns None -** -*******************************************************************************/ -void userial_vendor_init(char *bt_device_node) -{ - memset(&rtkbt_adv_con, 0, sizeof(rtkbt_lescn_t)); - memset(&vnd_userial, 0, sizeof(vnd_userial_cb_t)); - vnd_userial.fd = -1; - char value[100]; - snprintf(vnd_userial.port_name, VND_PORT_NAME_MAXLEN, "%s", - bt_device_node); - if (rtkbt_transtype & RTKBT_TRANS_H5) - { - h5_int_interface = hci_get_h5_int_interface(); - h5_int_interface->h5_int_init(&h5_int_callbacks); - } - rtk_parse_manager = NULL; - memset(value, 0, sizeof(value)); - strcpy(value, "true"); - if (strncmp(value, "true", 4) == 0) - { - rtk_parse_manager = rtk_parse_manager_get_interface(); - rtk_parse_manager->rtk_parse_init(); - } - vnd_userial.data_order = RtbQueueInit(); - vnd_userial.recv_data = RtbQueueInit(); - vnd_userial.send_data = RtbQueueInit(); - - // reset coex gloable variables - coex_packet_recv_state = RTKBT_PACKET_IDLE; - coex_packet_bytes_need = 0; - coex_current_type = 0; - coex_resvered_length = 0; - -#ifdef RTK_HANDLE_EVENT - // reset handle event gloable variables - received_packet_state = RTKBT_PACKET_IDLE; - received_packet_bytes_need = 0; - recv_packet_current_type = 0; - received_resvered_length = 0; -#endif - -#ifdef CONFIG_SCO_OVER_HCI - sco_cb.recv_sco_data = RtbQueueInit(); - sco_cb.send_sco_data = RtbQueueInit(); - pthread_mutex_init(&sco_cb.sco_recv_mutex, NULL); - pthread_cond_init(&sco_cb.sco_recv_cond, NULL); - pthread_mutex_init(&sco_cb.sco_send_mutex, NULL); - memset(&sco_cb.sbc_enc, 0, sizeof(sbc_t)); - sbc_init_msbc(&sco_cb.sbc_enc, 0L); - sco_cb.sbc_enc.endian = SBC_LE; - memset(&sco_cb.sbc_dec, 0, sizeof(sbc_t)); - sbc_init_msbc(&sco_cb.sbc_dec, 0L); - sco_cb.sbc_dec.endian = SBC_LE; -#endif -} - -/******************************************************************************* -** -** Function userial_vendor_open -** -** Description Open the serial port with the given configuration -** -** Returns device fd -** -*******************************************************************************/ -int userial_vendor_open(tUSERIAL_CFG *p_cfg) -{ - uint32_t baud; - uint8_t data_bits; - uint16_t parity; - uint8_t stop_bits; - - vnd_userial.fd = -1; - - if (!userial_to_tcio_baud(p_cfg->baud, &baud)) - { - return -1; - } - - if (p_cfg->fmt & USERIAL_DATABITS_8) - data_bits = CS8; - else if (p_cfg->fmt & USERIAL_DATABITS_7) - data_bits = CS7; - else if (p_cfg->fmt & USERIAL_DATABITS_6) - data_bits = CS6; - else if (p_cfg->fmt & USERIAL_DATABITS_5) - data_bits = CS5; - else - { - HILOGE("userial vendor open: unsupported data bits"); - return -1; - } - - if (p_cfg->fmt & USERIAL_PARITY_NONE) - parity = 0; - else if (p_cfg->fmt & USERIAL_PARITY_EVEN) - parity = PARENB; - else if (p_cfg->fmt & USERIAL_PARITY_ODD) - parity = (PARENB | PARODD); - else - { - HILOGE("userial vendor open: unsupported parity bit mode"); - return -1; - } - - if (p_cfg->fmt & USERIAL_STOPBITS_1) - stop_bits = 0; - else if (p_cfg->fmt & USERIAL_STOPBITS_2) - stop_bits = CSTOPB; - else - { - HILOGE("userial vendor open: unsupported stop bits"); - return -1; - } - - HILOGI("userial vendor open: opening %s", vnd_userial.port_name); - - if ((vnd_userial.fd = open(vnd_userial.port_name, O_RDWR)) == -1) - { - HILOGE("userial vendor open: unable to open %s", vnd_userial.port_name); - return -1; - } - - tcflush(vnd_userial.fd, TCIOFLUSH); - - tcgetattr(vnd_userial.fd, &vnd_userial.termios); - cfmakeraw(&vnd_userial.termios); - - if (p_cfg->hw_fctrl == USERIAL_HW_FLOW_CTRL_ON) - { - HILOGI("userial vendor open: with HW flowctrl ON"); - vnd_userial.termios.c_cflag |= (CRTSCTS | stop_bits | parity); - } - else - { - HILOGI("userial vendor open: with HW flowctrl OFF"); - vnd_userial.termios.c_cflag &= ~CRTSCTS; - vnd_userial.termios.c_cflag |= (stop_bits | parity); - } - - tcsetattr(vnd_userial.fd, TCSANOW, &vnd_userial.termios); - tcflush(vnd_userial.fd, TCIOFLUSH); - - tcsetattr(vnd_userial.fd, TCSANOW, &vnd_userial.termios); - tcflush(vnd_userial.fd, TCIOFLUSH); - tcflush(vnd_userial.fd, TCIOFLUSH); - - /* set input/output baudrate */ - cfsetospeed(&vnd_userial.termios, baud); - cfsetispeed(&vnd_userial.termios, baud); - tcsetattr(vnd_userial.fd, TCSANOW, &vnd_userial.termios); - -#if (BT_WAKE_VIA_USERIAL_IOCTL == TRUE) - userial_ioctl_init_bt_wake(vnd_userial.fd); -#endif - - vnd_userial.btdriver_state = true; - HILOGI("device fd = %d open", vnd_userial.fd); - - return vnd_userial.fd; -} - -static void userial_socket_close(void) -{ - int result; - - if ((vnd_userial.uart_fd[0] > 0) && (result = close(vnd_userial.uart_fd[0])) < 0) - HILOGE("%s (fd:%d) FAILED result:%d", __func__, vnd_userial.uart_fd[0], result); - - if (epoll_ctl(vnd_userial.epoll_fd, EPOLL_CTL_DEL, vnd_userial.uart_fd[1], NULL) == -1) - HILOGE("%s unable to unregister fd %d from epoll set: %s", __func__, vnd_userial.uart_fd[1], strerror(errno)); - - if (epoll_ctl(vnd_userial.epoll_fd, EPOLL_CTL_DEL, vnd_userial.signal_fd[1], NULL) == -1) - HILOGE("%s unable to unregister signal fd %d from epoll set: %s", __func__, vnd_userial.signal_fd[1], strerror(errno)); - - if ((vnd_userial.uart_fd[1] > 0) && (result = close(vnd_userial.uart_fd[1])) < 0) - HILOGE("%s (fd:%d) FAILED result:%d", __func__, vnd_userial.uart_fd[1], result); - - if (vnd_userial.thread_socket_id != (pthread_t)-1) - pthread_join(vnd_userial.thread_socket_id, NULL); - - if (vnd_userial.epoll_fd > 0) - close(vnd_userial.epoll_fd); - - if ((vnd_userial.signal_fd[0] > 0) && (result = close(vnd_userial.signal_fd[0])) < 0) - HILOGE("%s (signal fd[0]:%d) FAILED result:%d", __func__, vnd_userial.signal_fd[0], result); - if ((vnd_userial.signal_fd[1] > 0) && (result = close(vnd_userial.signal_fd[1])) < 0) - HILOGE("%s (signal fd[1]:%d) FAILED result:%d", __func__, vnd_userial.signal_fd[1], result); - - vnd_userial.epoll_fd = -1; - vnd_userial.uart_fd[0] = -1; - vnd_userial.uart_fd[1] = -1; - vnd_userial.signal_fd[0] = -1; - vnd_userial.signal_fd[1] = -1; -} - -static void userial_uart_close(void) -{ - int result; - if ((vnd_userial.fd > 0) && (result = close(vnd_userial.fd)) < 0) - HILOGE("%s (fd:%d) FAILED result:%d", __func__, vnd_userial.fd, result); - if (vnd_userial.thread_uart_id != (pthread_t)-1) - pthread_join(vnd_userial.thread_uart_id, NULL); -} - -static void userial_coex_close(void) -{ - int result; - - if (epoll_ctl(vnd_userial.cpoll_fd, EPOLL_CTL_DEL, vnd_userial.event_fd, NULL) == -1) - HILOGE("%s unable to unregister fd %d from cpoll set: %s", __func__, vnd_userial.event_fd, strerror(errno)); - - if (epoll_ctl(vnd_userial.cpoll_fd, EPOLL_CTL_DEL, vnd_userial.signal_fd[1], NULL) == -1) - HILOGE("%s unable to unregister fd %d from cpoll set: %s", __func__, vnd_userial.signal_fd[1], strerror(errno)); - - if ((result = close(vnd_userial.event_fd)) < 0) - HILOGE("%s (fd:%d) FAILED result:%d", __func__, vnd_userial.event_fd, result); - - close(vnd_userial.cpoll_fd); - if (vnd_userial.thread_coex_id != (pthread_t)-1) - pthread_join(vnd_userial.thread_coex_id, NULL); - vnd_userial.cpoll_fd = -1; - vnd_userial.event_fd = -1; -} - -void userial_send_close_signal(void) -{ - unsigned char close_signal = 1; - ssize_t ret; - RTK_NO_INTR(ret = write(vnd_userial.signal_fd[0], &close_signal, 1)); -} - -/******************************************************************************* -** -** Function userial_vendor_close -** -** Description Conduct vendor-specific close work -** -** Returns None -** -*******************************************************************************/ -void userial_vendor_close(void) -{ - if (vnd_userial.fd == -1) - return; - - if ((rtkbt_transtype & RTKBT_TRANS_UART) && (rtkbt_transtype & RTKBT_TRANS_H5)) - { -#if (BT_WAKE_VIA_USERIAL_IOCTL == TRUE) - /* de-assert bt_wake BEFORE closing port */ - ioctl(vnd_userial.fd, USERIAL_IOCTL_BT_WAKE_DEASSERT, NULL); -#endif - // h5_int_interface->h5_int_cleanup(); - } - - vnd_userial.thread_running = false; -#ifdef CONFIG_SCO_OVER_HCI - if (sco_cb.thread_sco_running) - { - sco_cb.thread_sco_running = false; - unsigned char close_signal = 1; - ssize_t ret; - RTK_NO_INTR(ret = write(sco_cb.signal_fd[0], &close_signal, 1)); - pthread_join(sco_cb.thread_socket_sco_id, NULL); - } -#endif - Heartbeat_cleanup(); - RTK_btservice_destroyed(); - userial_send_close_signal(); - userial_uart_close(); - userial_coex_close(); - userial_socket_close(); - - if ((rtkbt_transtype & RTKBT_TRANS_UART) && (rtkbt_transtype & RTKBT_TRANS_H5)) - { - h5_int_interface->h5_int_cleanup(); - } - - vnd_userial.fd = -1; - vnd_userial.btdriver_state = false; - if (rtk_parse_manager) - { - rtk_parse_manager->rtk_parse_cleanup(); - } - rtk_parse_manager = NULL; -#ifdef CONFIG_SCO_OVER_HCI - sbc_finish(&sco_cb.sbc_enc); - sbc_finish(&sco_cb.sbc_dec); -#endif - HILOGD("%s finish", __func__); -} - -/******************************************************************************* -** -** Function userial_vendor_set_baud -** -** Description Set new baud rate -** -** Returns None -** -*******************************************************************************/ -void userial_vendor_set_baud(uint8_t userial_baud) -{ - uint32_t tcio_baud; - HILOGI("userial_vendor_set_baud"); - userial_to_tcio_baud(userial_baud, &tcio_baud); - - if (cfsetospeed(&vnd_userial.termios, tcio_baud) < 0) - HILOGE("cfsetospeed fail"); - - if (cfsetispeed(&vnd_userial.termios, tcio_baud) < 0) - HILOGE("cfsetispeed fail"); - - if (tcsetattr(vnd_userial.fd, TCSANOW, &vnd_userial.termios) < 0) - HILOGE("tcsetattr fail "); - - tcflush(vnd_userial.fd, TCIOFLUSH); -} - -/******************************************************************************* -** -** Function userial_vendor_ioctl -** -** Description ioctl inteface -** -** Returns None -** -*******************************************************************************/ -void userial_vendor_ioctl(userial_vendor_ioctl_op_t op, void *p_data) -{ - RTK_UNUSED(p_data); - switch (op) - { -#if (BT_WAKE_VIA_USERIAL_IOCTL == TRUE) - case USERIAL_OP_ASSERT_BT_WAKE: - VNDUSERIALDBG("## userial_vendor_ioctl: Asserting BT_Wake ##"); - ioctl(vnd_userial.fd, USERIAL_IOCTL_BT_WAKE_ASSERT, NULL); - break; - - case USERIAL_OP_DEASSERT_BT_WAKE: - VNDUSERIALDBG("## userial_vendor_ioctl: De-asserting BT_Wake ##"); - ioctl(vnd_userial.fd, USERIAL_IOCTL_BT_WAKE_DEASSERT, NULL); - break; - - case USERIAL_OP_GET_BT_WAKE_STATE: - ioctl(vnd_userial.fd, USERIAL_IOCTL_BT_WAKE_GET_ST, p_data); - break; -#endif // (BT_WAKE_VIA_USERIAL_IOCTL==TRUE) - - default: - break; - } -} - -/******************************************************************************* -** -** Function userial_set_port -** -** Description Configure UART port name -** -** Returns 0 : Success -** Otherwise : Fail -** -*******************************************************************************/ -int userial_set_port(char *p_conf_name, char *p_conf_value, int param) -{ - RTK_UNUSED(p_conf_name); - RTK_UNUSED(param); - strcpy(vnd_userial.port_name, p_conf_value); - - return 0; -} - -/******************************************************************************* -** -** Function userial_vendor_set_hw_fctrl -** -** Description Conduct vendor-specific close work -** -** Returns None -** -*******************************************************************************/ -void userial_vendor_set_hw_fctrl(uint8_t hw_fctrl) -{ - struct termios termios_old; - - if (vnd_userial.fd == -1) - { - HILOGE("vnd_userial.fd is -1"); - return; - } - - tcgetattr(vnd_userial.fd, &termios_old); - if (hw_fctrl) - { - if (termios_old.c_cflag & CRTSCTS) - { - BTVNDDBG("userial_vendor_set_hw_fctrl already hw flowcontrol on"); - return; - } - else - { - termios_old.c_cflag |= CRTSCTS; - tcsetattr(vnd_userial.fd, TCSANOW, &termios_old); - BTVNDDBG("userial_vendor_set_hw_fctrl set hw flowcontrol on"); - } - } - else - { - if (termios_old.c_cflag & CRTSCTS) - { - termios_old.c_cflag &= ~CRTSCTS; - tcsetattr(vnd_userial.fd, TCSANOW, &termios_old); - return; - } - else - { - HILOGI("userial_vendor_set_hw_fctrl set hw flowcontrol off"); - return; - } - } -} - -static uint16_t h4_int_transmit_data(uint8_t *data, uint16_t total_length) -{ - assert(data != NULL); - assert(total_length > 0); - - uint16_t length = total_length; - uint16_t transmitted_length = 0; - while (length > 0 && vnd_userial.btdriver_state) - { - ssize_t ret = write(vnd_userial.fd, data + transmitted_length, length); - switch (ret) - { - case -1: - HILOGE("In %s, error writing to the uart serial port: %s", __func__, strerror(errno)); - goto done; - case 0: - // If we wrote nothing, don't loop more because we - // can't go to infinity or beyond, ohterwise H5 can resend data - HILOGE("%s, ret %zd", __func__, ret); - goto done; - default: - transmitted_length += ret; - length -= ret; - break; - } - } - -done:; - return transmitted_length; -} - -static void userial_enqueue_coex_rawdata(unsigned char *buffer, int length, bool is_recved) -{ - RTK_BUFFER *skb_data = RtbAllocate(length, 0); - RTK_BUFFER *skb_type = RtbAllocate(1, 0); - memcpy(skb_data->Data, buffer, length); - skb_data->Length = length; - if (is_recved) - { - *skb_type->Data = RTK_DATA_RECEIVED; - skb_type->Length = 1; - RtbQueueTail(vnd_userial.recv_data, skb_data); - RtbQueueTail(vnd_userial.data_order, skb_type); - } - else - { - *skb_type->Data = RTK_DATA_SEND; - skb_type->Length = 1; - RtbQueueTail(vnd_userial.send_data, skb_data); - RtbQueueTail(vnd_userial.data_order, skb_type); - } - - if (eventfd_write(vnd_userial.event_fd, 1) == -1) - { - HILOGE("%s unable to write for coex event fd.", __func__); - } -} - -static void userial_send_cmd_to_controller(unsigned char *recv_buffer, int total_length) -{ - if (rtkbt_transtype & RTKBT_TRANS_H4) - { - h4_int_transmit_data(recv_buffer, total_length); - } - else - { - h5_int_interface->h5_send_cmd(DATA_TYPE_COMMAND, &recv_buffer[1], (total_length - 1)); - } - userial_enqueue_coex_rawdata(recv_buffer, total_length, false); -} - -static void userial_send_acl_to_controller(unsigned char *recv_buffer, int total_length) -{ - if (rtkbt_transtype & RTKBT_TRANS_H4) - { - h4_int_transmit_data(recv_buffer, total_length); - } - else - { - h5_int_interface->h5_send_acl_data(DATA_TYPE_ACL, &recv_buffer[1], (total_length - 1)); - } - userial_enqueue_coex_rawdata(recv_buffer, total_length, false); -} - -static void userial_send_sco_to_controller(unsigned char *recv_buffer, int total_length) -{ - if (rtkbt_transtype & RTKBT_TRANS_H4) - { - h4_int_transmit_data(recv_buffer, total_length); - } - else - { - h5_int_interface->h5_send_sco_data(DATA_TYPE_SCO, &recv_buffer[1], (total_length - 1)); - } - userial_enqueue_coex_rawdata(recv_buffer, total_length, false); -} - -static int userial_coex_recv_data_handler(unsigned char *recv_buffer, int total_length) -{ - serial_data_type_t type = 0; - unsigned char *p_data = recv_buffer; - int length = total_length; - HC_BT_HDR *p_buf; - uint8_t boundary_flag; - uint16_t len, handle, acl_length, l2cap_length; - switch (coex_packet_recv_state) - { - case RTKBT_PACKET_IDLE: - coex_packet_bytes_need = 1; - while (length) - { - type = p_data[0]; - length--; - p_data++; - assert((type > DATA_TYPE_COMMAND) && (type <= DATA_TYPE_EVENT)); - if (type < DATA_TYPE_ACL || type > DATA_TYPE_EVENT) - { - HILOGE("%s invalid data type: %d", __func__, type); - if (!length) - return total_length; - - continue; - } - break; - } - coex_current_type = type; - coex_packet_recv_state = RTKBT_PACKET_TYPE; - // fall through - - case RTKBT_PACKET_TYPE: - if (coex_current_type == DATA_TYPE_ACL) - { - coex_packet_bytes_need = 4; - } - else if (coex_current_type == DATA_TYPE_EVENT) - { - coex_packet_bytes_need = 2; - } - else - { - coex_packet_bytes_need = 3; - } - coex_resvered_length = 0; - coex_packet_recv_state = RTKBT_PACKET_HEADER; - // fall through - - case RTKBT_PACKET_HEADER: - if (length >= coex_packet_bytes_need) - { - memcpy(&coex_resvered_buffer[coex_resvered_length], p_data, coex_packet_bytes_need); - coex_resvered_length += coex_packet_bytes_need; - length -= coex_packet_bytes_need; - p_data += coex_packet_bytes_need; - } - else - { - memcpy(&coex_resvered_buffer[coex_resvered_length], p_data, length); - coex_resvered_length += length; - coex_packet_bytes_need -= length; - length = 0; - return total_length; - } - coex_packet_recv_state = RTKBT_PACKET_CONTENT; - - if (coex_current_type == DATA_TYPE_ACL) - { - coex_packet_bytes_need = *(uint16_t *)&coex_resvered_buffer[2]; - } - else if (coex_current_type == DATA_TYPE_EVENT) - { - coex_packet_bytes_need = coex_resvered_buffer[1]; - } - else - { - coex_packet_bytes_need = coex_resvered_buffer[2]; - } - // fall through - - case RTKBT_PACKET_CONTENT: - if (length >= coex_packet_bytes_need) - { - memcpy(&coex_resvered_buffer[coex_resvered_length], p_data, coex_packet_bytes_need); - length -= coex_packet_bytes_need; - p_data += coex_packet_bytes_need; - coex_resvered_length += coex_packet_bytes_need; - coex_packet_bytes_need = 0; - } - else - { - memcpy(&coex_resvered_buffer[coex_resvered_length], p_data, length); - coex_resvered_length += length; - coex_packet_bytes_need -= length; - length = 0; - return total_length; - } - coex_packet_recv_state = RTKBT_PACKET_END; - // fall through - - case RTKBT_PACKET_END: - { - len = BT_HC_HDR_SIZE + coex_resvered_length; - uint8_t packet[len]; - p_buf = (HC_BT_HDR *)packet; - p_buf->offset = 0; - p_buf->layer_specific = 0; - p_buf->len = coex_resvered_length; - memcpy((uint8_t *)(p_buf + 1), coex_resvered_buffer, coex_resvered_length); - switch (coex_current_type) - { - case DATA_TYPE_EVENT: - p_buf->event = MSG_HC_TO_STACK_HCI_EVT; - if (rtk_parse_manager) - rtk_parse_manager->rtk_parse_internal_event_intercept(coex_resvered_buffer); - break; - - case DATA_TYPE_ACL: - p_buf->event = MSG_HC_TO_STACK_HCI_ACL; - handle = *(uint16_t *)coex_resvered_buffer; - acl_length = *(uint16_t *)&coex_resvered_buffer[2]; - l2cap_length = *(uint16_t *)&coex_resvered_buffer[4]; - boundary_flag = RTK_GET_BOUNDARY_FLAG(handle); - if (rtk_parse_manager) - rtk_parse_manager->rtk_parse_l2cap_data(coex_resvered_buffer, 0); - break; - - case DATA_TYPE_SCO: - p_buf->event = MSG_HC_TO_STACK_HCI_SCO; - break; - - default: - p_buf->event = MSG_HC_TO_STACK_HCI_ERR; - break; - } - rtk_btsnoop_capture(p_buf, true); - } - break; - - default: - - break; - } - - coex_packet_recv_state = RTKBT_PACKET_IDLE; - coex_packet_bytes_need = 0; - coex_current_type = 0; - coex_resvered_length = 0; - - return (total_length - length); -} - -static void userial_coex_send_data_handler(unsigned char *send_buffer, int total_length) -{ - serial_data_type_t type = 0; - type = send_buffer[0]; - int length = total_length; - HC_BT_HDR *p_buf; - uint8_t boundary_flag; - uint16_t len, handle, acl_length, l2cap_length; - - len = BT_HC_HDR_SIZE + (length - 1); - uint8_t packet[len]; - p_buf = (HC_BT_HDR *)packet; - p_buf->offset = 0; - p_buf->layer_specific = 0; - p_buf->len = total_length - 1; - memcpy((uint8_t *)(p_buf + 1), &send_buffer[1], length - 1); - - switch (type) - { - case DATA_TYPE_COMMAND: - p_buf->event = MSG_STACK_TO_HC_HCI_CMD; - if (rtk_parse_manager) - rtk_parse_manager->rtk_parse_command(&send_buffer[1]); - break; - - case DATA_TYPE_ACL: - p_buf->event = MSG_STACK_TO_HC_HCI_ACL; - handle = *(uint16_t *)&send_buffer[1]; - acl_length = *(uint16_t *)&send_buffer[3]; - l2cap_length = *(uint16_t *)&send_buffer[5]; - boundary_flag = RTK_GET_BOUNDARY_FLAG(handle); - if (rtk_parse_manager) - rtk_parse_manager->rtk_parse_l2cap_data(&send_buffer[1], 1); - - break; - - case DATA_TYPE_SCO: - p_buf->event = MSG_STACK_TO_HC_HCI_SCO; - break; - default: - p_buf->event = 0; - HILOGE("%s invalid data type: %d", __func__, type); - break; - } - rtk_btsnoop_capture(p_buf, false); -} - -static void userial_coex_handler(void *context) -{ - RTK_UNUSED(context); - RTK_BUFFER *skb_data; - RTK_BUFFER *skb_type; - eventfd_t value; - unsigned int read_length = 0; - eventfd_read(vnd_userial.event_fd, &value); - if (!value && !vnd_userial.thread_running) - { - return; - } - - while (!RtbQueueIsEmpty(vnd_userial.data_order)) - { - read_length = 0; - skb_type = RtbDequeueHead(vnd_userial.data_order); - if (skb_type) - { - if (*(skb_type->Data) == RTK_DATA_RECEIVED) - { - skb_data = RtbDequeueHead(vnd_userial.recv_data); - if (skb_data) - { - do - { - read_length += userial_coex_recv_data_handler((skb_data->Data + read_length), (skb_data->Length - read_length)); - } while (read_length < skb_data->Length); - RtbFree(skb_data); - } - } - else - { - skb_data = RtbDequeueHead(vnd_userial.send_data); - if (skb_data) - { - userial_coex_send_data_handler(skb_data->Data, skb_data->Length); - RtbFree(skb_data); - } - } - - RtbFree(skb_type); - } - } -} - -#ifdef CONFIG_SCO_OVER_HCI -// receive sco encode or non-encode data over hci, we need to decode msbc data to pcm, and send it to sco audio hal -static void *userial_recv_sco_thread(void *arg) -{ - RTK_UNUSED(arg); - RTK_BUFFER *skb_sco_data; - unsigned char dec_data[480]; - unsigned char pcm_data[960]; - int index = 0; - // uint16_t sco_packet_len = 60; - uint8_t *p_data = NULL; - int res = 0; - size_t writen = 0; - prctl(PR_SET_NAME, (unsigned long)"userial_recv_sco_thread", 0, 0, 0); - /* - FILE *file; - unsigned char enc_data[60]; - file = fopen("/data/misc/bluedroid/sco_capture.raw", "rb"); - FILE *file2; - file2 = fopen("/data/misc/bluedroid/sco_capture.pcm", "wb"); - if (!file) { - HILOGE("Unable to create file"); - return NULL; - } - */ - // RtbEmptyQueue(sco_cb.recv_sco_data); - pthread_mutex_lock(&sco_cb.sco_recv_mutex); - while (RtbGetQueueLen(sco_cb.recv_sco_data) > 60) - { - RTK_BUFFER *sco_data = RtbDequeueHead(sco_cb.recv_sco_data); - if (sco_data) - RtbFree(sco_data); - } - pthread_mutex_unlock(&sco_cb.sco_recv_mutex); - - HILOGE("userial_recv_sco_thread start"); - while (sco_cb.thread_recv_sco_running) - { - pthread_mutex_lock(&sco_cb.sco_recv_mutex); - while (RtbQueueIsEmpty(sco_cb.recv_sco_data) && sco_cb.thread_sco_running) - { - pthread_cond_wait(&sco_cb.sco_recv_cond, &sco_cb.sco_recv_mutex); - } - pthread_mutex_unlock(&sco_cb.sco_recv_mutex); - skb_sco_data = RtbDequeueHead(sco_cb.recv_sco_data); - if (!skb_sco_data) - continue; - p_data = skb_sco_data->Data; - - if (!sco_cb.msbc_used) - { - res = Skt_Send_noblock(sco_cb.data_fd, p_data, sco_cb.sco_packet_len); - if (res < 0) - { - HILOGE("userial_recv_sco_thread, send noblock error"); - } - } - else - { - // if (fwrite(skb_sco_data->Data, 1, 60, file) != 60) { - // HILOGE("Error capturing sample"); - //} - /* - if(fread(enc_data, 1, 60, file) > 0) { - HILOGE("userial_recv_sco_thread, fread data"); - res = sbc_decode(&sco_cb.sbc_dec, &enc_data[2], 58, dec_data, 240, &writen); - } - else { - fseek(file, 0L, SEEK_SET); - if(fread(enc_data, 1, 60, file) > 0) { - res = sbc_decode(&sco_cb.sbc_dec, &enc_data[2], 58, dec_data, 240, &writen); - } - } - */ - res = sbc_decode(&sco_cb.sbc_dec, (p_data + 2), 58, dec_data, 240, &writen); - if (res > 0) - { - memcpy(&pcm_data[240 * index], dec_data, 240); - // if (fwrite(dec_data, 240, 1, file2) != 240) { - // HILOGE("Error capturing sample"); - //} - index = (index + 1) % 4; - if (index == 0) - { - Skt_Send_noblock(sco_cb.data_fd, pcm_data, 960); - } - } - else - { - HILOGE("msbc decode fail!"); - } - } - RtbFree(skb_sco_data); - } - HILOGE("userial_recv_sco_thread exit"); - RtbEmptyQueue(sco_cb.recv_sco_data); - return NULL; -} - -static void *userial_send_sco_thread(void *arg) -{ - RTK_UNUSED(arg); - unsigned char enc_data[240]; - unsigned char pcm_data[960 * 2]; - unsigned char send_data[100]; - int writen = 0; - int num_read; - prctl(PR_SET_NAME, (unsigned long)"userial_send_sco_thread", 0, 0, 0); - sco_cb.pcm_enc_seq = 0; - int i; - - /* - FILE *file; - file = fopen("/data/misc/bluedroid/sco_playback.raw", "rb"); - if (!file) { - HILOGE("Unable to create file"); - return NULL; - } - */ - // when start sco send thread, first send 6 sco data to controller - if (!sco_cb.msbc_used) - { - memset(pcm_data, 0, (48 * 6)); - for (i = 0; i < 6; i++) - { - send_data[0] = DATA_TYPE_SCO; - send_data[3] = 48; - *(uint16_t *)&send_data[1] = sco_cb.sco_handle; - memcpy(&send_data[4], &pcm_data[i * 48], 48); - userial_send_sco_to_controller(send_data, 52); - } - } - HILOGE("userial_send_sco_thread start"); - while (sco_cb.thread_send_sco_running) - { - if (!sco_cb.msbc_used) - { - num_read = Skt_Read(sco_cb.data_fd, pcm_data, 48 * 5, &sco_cb.thread_send_sco_running); - if (!num_read) - continue; - for (i = 0; i < 5; i++) - { - send_data[0] = DATA_TYPE_SCO; - send_data[3] = 48; - *(uint16_t *)&send_data[1] = sco_cb.sco_handle; - memcpy(&send_data[4], &pcm_data[i * 48], 48); - userial_send_sco_to_controller(send_data, 52); - } - } - else - { - num_read = Skt_Read(sco_cb.data_fd, pcm_data, 960, &sco_cb.thread_send_sco_running); - /* - for(i = 0; i < 5; i ++) { - if(fread(&enc_data[4], 1, 48, file) > 0) { - enc_data[0] = DATA_TYPE_SCO; - enc_data[3] = 48; - *(uint16_t *)&enc_data[1] = sco_cb.sco_handle; - userial_send_sco_to_controller(enc_data, 52); - } - else { - fseek(file, 0L, SEEK_SET); - } - } - //usleep(7500); - continue; - */ - if (!num_read) - continue; - for (i = 0; i < 4; i++) - { - if (sbc_encode(&sco_cb.sbc_enc, &pcm_data[240 * i], 240, &enc_data[i * 60 + 2], 58, (ssize_t *)&writen) <= 0) - { - HILOGE("sbc encode error!"); - } - else - { - *(uint16_t *)(&(enc_data[i * 60])) = btui_msbc_h2[sco_cb.pcm_enc_seq % 4]; - sco_cb.pcm_enc_seq++; - enc_data[i * 60 + 59] = 0x00; // padding - } - } - for (i = 0; i < 5; i++) - { - send_data[0] = DATA_TYPE_SCO; - send_data[3] = 48; - *(uint16_t *)&send_data[1] = sco_cb.sco_handle; - memcpy(&send_data[4], &enc_data[i * 48], 48); - userial_send_sco_to_controller(send_data, 52); - } - } - } - HILOGE("userial_send_sco_thread exit"); - return NULL; -} - -static void userial_sco_send_socket_stop() -{ - HILOGE("%s", __func__); - pthread_mutex_lock(&sco_cb.sco_send_mutex); - if (sco_cb.thread_send_sco_running) - { - sco_cb.thread_send_sco_running = false; - } - else - { - pthread_mutex_unlock(&sco_cb.sco_send_mutex); - return; - } - pthread_mutex_unlock(&sco_cb.sco_send_mutex); - - if (sco_cb.thread_send_sco_id != -1) - { - pthread_join(sco_cb.thread_send_sco_id, NULL); - sco_cb.thread_send_sco_id = -1; - } -} - -static void userial_sco_recv_socket_stop() -{ - HILOGE("%s", __func__); - pthread_mutex_lock(&sco_cb.sco_recv_mutex); - if (sco_cb.thread_recv_sco_running) - { - sco_cb.thread_recv_sco_running = false; - pthread_cond_signal(&sco_cb.sco_recv_cond); - } - else - { - pthread_mutex_unlock(&sco_cb.sco_recv_mutex); - return; - } - pthread_mutex_unlock(&sco_cb.sco_recv_mutex); - - if (sco_cb.thread_recv_sco_id != -1) - { - pthread_join(sco_cb.thread_recv_sco_id, NULL); - sco_cb.thread_recv_sco_id = -1; - } -} - -static void userial_sco_socket_stop() -{ - HILOGE("%s", __func__); - userial_sco_send_socket_stop(); - userial_sco_recv_socket_stop(); - if (sco_cb.ctrl_fd > 0) - { - close(sco_cb.ctrl_fd); - sco_cb.ctrl_fd = -1; - } - if (sco_cb.data_fd > 0) - { - close(sco_cb.data_fd); - sco_cb.data_fd = -1; - } - RtbEmptyQueue(sco_cb.recv_sco_data); -} - -static void userial_sco_ctrl_skt_handle() -{ - uint8_t cmd = 0, ack = 0; - ; - int result = Skt_Read(sco_cb.ctrl_fd, &cmd, 1, NULL); - - if (result == 0) - { - userial_sco_socket_stop(); - return; - } - - HILOGE("%s, cmd = %d, msbc_used = %d", __func__, cmd, sco_cb.msbc_used); - switch (cmd) - { - case SCO_CTRL_CMD_CHECK_READY: - - break; - - case SCO_CTRL_CMD_OUT_START: - { - pthread_attr_t thread_attr; - pthread_attr_init(&thread_attr); - pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE); - sco_cb.thread_send_sco_running = true; - if (pthread_create(&sco_cb.thread_send_sco_id, &thread_attr, userial_send_sco_thread, NULL) != 0) - { - HILOGE("pthread_create : %s", strerror(errno)); - } - } - break; - - case SCO_CTRL_CMD_IN_START: - { - pthread_attr_t thread_attr; - pthread_attr_init(&thread_attr); - pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE); - sco_cb.thread_recv_sco_running = true; - if (pthread_create(&sco_cb.thread_recv_sco_id, &thread_attr, userial_recv_sco_thread, NULL) != 0) - { - HILOGE("pthread_create : %s", strerror(errno)); - } - } - break; - - case SCO_CTRL_CMD_OUT_STOP: - userial_sco_send_socket_stop(); - break; - - case SCO_CTRL_CMD_IN_STOP: - userial_sco_recv_socket_stop(); - - break; - - case SCO_CTRL_CMD_SUSPEND: - - break; - - case SCO_CTRL_GET_AUDIO_CONFIG: - if (sco_cb.msbc_used) - { - ack = 2; - Skt_Send(sco_cb.ctrl_fd, &ack, 1); - } - else - { - ack = 1; - Skt_Send(sco_cb.ctrl_fd, &ack, 1); - } - break; - - case SCO_CTRL_CMD_CLOSE: - userial_sco_socket_stop(); - break; - - default: - - break; - } -} - -static void *userial_socket_sco_thread(void *arg) -{ - RTK_UNUSED(arg); - struct sockaddr_un addr, remote; - // socklen_t alen; - socklen_t len = sizeof(struct sockaddr_un); - fd_set read_set, active_set; - int result, max_fd; - int s_ctrl = socket(AF_LOCAL, SOCK_STREAM, 0); - if (s_ctrl < 0) - { - HILOGE("ctrl socket create fail"); - return NULL; - } - int s_data = socket(AF_LOCAL, SOCK_STREAM, 0); - if (s_data < 0) - { - HILOGE("data socket create fail"); - close(s_ctrl); - return NULL; - } - prctl(PR_SET_NAME, (unsigned long)"userial_socket_sco_thread", 0, 0, 0); - - if ((socketpair(AF_UNIX, SOCK_STREAM, 0, sco_cb.signal_fd)) < 0) - { - HILOGE("%s, errno : %s", __func__, strerror(errno)); - goto socket_close; - } - - // bind sco ctrl socket - // unlink(SCO_CTRL_PATH); - -#if 0 - memset(&addr, 0, sizeof(addr)); - strcpy(addr.sun_path, SCO_CTRL_PATH); - addr.sun_family = AF_UNIX; - addr.sun_path[0] = 0; - alen = strlen(addr.sun_path) + offsetof(struct sockaddr_un, sun_path); - if (bind(s_ctrl, (struct sockaddr *)&addr, alen) < 0) { - HILOGE("userial_socket_sco_thread, bind ctrl socket error : %s", strerror(errno)); - return NULL; - } -#else - if (socket_local_server_bind(s_ctrl, SCO_CTRL_PATH, ANDROID_SOCKET_NAMESPACE_ABSTRACT) < 0) - { - HILOGE("ctrl socket failed to create (%s)", strerror(errno)); - goto signal_close; - } -#endif - - if (listen(s_ctrl, 5) < 0) - { - HILOGE("userial_socket_sco_thread, listen ctrl socket error : %s", strerror(errno)); - goto signal_close; - } - - int res = chmod(SCO_CTRL_PATH, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); - if (res < 0) - { - HILOGE("chmod ctrl path fail"); - } - // bind sco data socket - // unlink(SCO_DATA_PATH); -#if 0 - memset(&addr, 0, sizeof(addr)); - strcpy(addr.sun_path, SCO_DATA_PATH); - addr.sun_family = AF_UNIX; - addr.sun_path[0] = 0; - alen = strlen(addr.sun_path) + offsetof(struct sockaddr_un, sun_path); - if (bind(s_data, (struct sockaddr *)&addr, alen) < 0) { - HILOGE("userial_socket_sco_thread, bind data socket error : %s", strerror(errno)); - return NULL; - } - -#else - if (socket_local_server_bind(s_data, SCO_DATA_PATH, ANDROID_SOCKET_NAMESPACE_ABSTRACT) < 0) - { - HILOGE("data socket failed to create (%s)", strerror(errno)); - goto signal_close; - } - -#endif - if (listen(s_data, 5) < 0) - { - HILOGE("userial_socket_sco_thread, listen data socket error : %s", strerror(errno)); - goto signal_close; - } - res = chmod(SCO_DATA_PATH, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); - if (res < 0) - { - HILOGE("chmod data path fail"); - } - - HILOGE("userial_socket_sco_thread"); - FD_ZERO(&read_set); - FD_ZERO(&active_set); - FD_SET(s_ctrl, &active_set); - FD_SET(s_data, &active_set); - FD_SET(sco_cb.signal_fd[1], &active_set); - max_fd = MAX(s_ctrl, s_data); - max_fd = MAX(max_fd, sco_cb.signal_fd[1]) + 1; - while (sco_cb.thread_sco_running) - { - read_set = active_set; - result = select(max_fd, &read_set, NULL, NULL, NULL); - if (result == 0) - { - HILOGE("select timeout"); - continue; - } - if (result < 0) - { - if (errno != EINTR) - HILOGE("select failed %s", strerror(errno)); - continue; - } - if (FD_ISSET(s_ctrl, &read_set)) - { - if (sco_cb.ctrl_fd > 0) - { - HILOGE("Already has connect a control fd: %d", sco_cb.ctrl_fd); - FD_SET(sco_cb.ctrl_fd, &read_set); - close(sco_cb.ctrl_fd); - } - RTK_NO_INTR(sco_cb.ctrl_fd = accept(s_ctrl, (struct sockaddr *)&remote, &len)); - if (sco_cb.ctrl_fd == -1) - { - HILOGE("sock accept failed (%s)", strerror(errno)); - continue; - } - const int size = (512); - setsockopt(sco_cb.ctrl_fd, SOL_SOCKET, SO_RCVBUF, (char *)&size, (int)sizeof(size)); - FD_SET(sco_cb.ctrl_fd, &active_set); - max_fd = (MAX(max_fd, sco_cb.ctrl_fd)) + 1; - } - - if (FD_ISSET(s_data, &read_set)) - { - if (sco_cb.data_fd > 0) - { - HILOGE("Already has connect a control fd: %d", sco_cb.data_fd); - close(sco_cb.data_fd); - } - RTK_NO_INTR(sco_cb.data_fd = accept(s_data, (struct sockaddr *)&remote, &len)); - if (sco_cb.data_fd == -1) - { - HILOGE("socket accept failed (%s)", strerror(errno)); - continue; - } - const int size = (30 * 960); - int ret = setsockopt(sco_cb.data_fd, SOL_SOCKET, SO_RCVBUF, (char *)&size, (int)sizeof(size)); - ret = setsockopt(sco_cb.data_fd, SOL_SOCKET, SO_SNDBUF, (char *)&size, (int)sizeof(size)); - } - - if (sco_cb.ctrl_fd > 0 && FD_ISSET(sco_cb.ctrl_fd, &read_set)) - { - userial_sco_ctrl_skt_handle(); - } - } - - userial_sco_socket_stop(); -signal_close: - close(sco_cb.signal_fd[0]); - close(sco_cb.signal_fd[1]); -socket_close: - close(s_ctrl); - close(s_data); - - memset(&addr, 0, sizeof(addr)); - strcpy((addr.sun_path + 1), SCO_DATA_PATH); - addr.sun_path[0] = 0; - unlink(addr.sun_path); - - memset(&addr, 0, sizeof(addr)); - strcpy((addr.sun_path + 1), SCO_CTRL_PATH); - addr.sun_path[0] = 0; - unlink(addr.sun_path); - HILOGE("userial_socket_sco_thread exit"); - return NULL; -} - -#endif - -#ifdef RTK_HANDLE_CMD -static void userial_handle_cmd(unsigned char *recv_buffer, int total_length) -{ - RTK_UNUSED(total_length); - uint16_t opcode = *(uint16_t *)recv_buffer; - uint16_t scan_int, scan_win; - static uint16_t voice_settings; - char prop_value[100]; - switch (opcode) - { - case HCI_BLE_WRITE_SCAN_PARAMS: - scan_int = *(uint16_t *)&recv_buffer[4]; - scan_win = *(uint16_t *)&recv_buffer[6]; - if (scan_win > 20) - { - if ((scan_int / scan_win) > 2) - { - *(uint16_t *)&recv_buffer[4] = (scan_int * 20) / scan_win; - *(uint16_t *)&recv_buffer[6] = 20; - } - else - { - *(uint16_t *)&recv_buffer[4] = 40; - *(uint16_t *)&recv_buffer[6] = 20; - } - } - else if (scan_win == scan_int) - { - *(uint16_t *)&recv_buffer[4] = (scan_int * 5) & 0xFE; - } - else if ((scan_int / scan_win) <= 2) - { - *(uint16_t *)&recv_buffer[4] = (scan_int * 3) & 0xFE; - } - break; - - case HCI_LE_SET_EXTENDED_SCAN_PARAMETERS: - scan_int = *(uint16_t *)&recv_buffer[7]; - scan_win = *(uint16_t *)&recv_buffer[9]; - if (scan_win > 20) - { - if ((scan_int / scan_win) > 2) - { - *(uint16_t *)&recv_buffer[7] = (scan_int * 20) / scan_win; - *(uint16_t *)&recv_buffer[9] = 20; - } - else - { - *(uint16_t *)&recv_buffer[7] = 40; - *(uint16_t *)&recv_buffer[9] = 20; - } - } - else if (scan_win == scan_int) - { - *(uint16_t *)&recv_buffer[7] = (scan_int * 5) & 0xFE; - } - else if ((scan_int / scan_win) <= 2) - { - *(uint16_t *)&recv_buffer[9] = (scan_int * 3) & 0xFE; - } - - break; - - case HCI_WRITE_VOICE_SETTINGS: - voice_settings = *(uint16_t *)&recv_buffer[3]; - if (rtkbt_transtype & RTKBT_TRANS_USB) - { - userial_vendor_usb_ioctl(SET_ISO_CFG, &voice_settings); - } -#ifdef CONFIG_SCO_OVER_HCI - sco_cb.voice_settings = voice_settings; -#endif - break; -#ifdef CONFIG_SCO_OVER_HCI - case HCI_SETUP_ESCO_CONNECTION: - sco_cb.voice_settings = *(uint16_t *)&recv_buffer[15]; - sco_cb.ctrl_fd = -1; - sco_cb.data_fd = -1; - break; -#endif - case HCI_SET_EVENT_MASK: - HILOGE("set event mask, it should bt stack init, set coex bt on"); - if (rtk_parse_manager) - { - rtk_parse_manager->rtk_set_bt_on(1); - } - Heartbeat_init(); - break; - - case HCI_ACCEPT_CONNECTION_REQUEST: - memset(prop_value, 0, sizeof(prop_value)); - strcpy(prop_value, "master"); - if (strcmp(prop_value, "none") != 0) - { - int role = recv_buffer[9]; - if (role == 0x01 && (strcmp(prop_value, "master") == 0)) - recv_buffer[9] = 0x00; - else if (role == 0x00 && (strcmp(prop_value, "slave") == 0)) - recv_buffer[9] = 0x01; - } - break; - - case HCI_BLE_WRITE_ADV_PARAMS: - { - if (rtkbt_version.hci_version > HCI_PROTO_VERSION_4_2) - { - break; - } - rtkbt_adv_con.adverting_type = recv_buffer[7]; - memset(prop_value, 0, sizeof(prop_value)); - strcpy(prop_value, "false"); - if (rtkbt_adv_con.adverting_type == 0x00 && (strcmp(prop_value, "true") == 0)) - { - recv_buffer[7] = 0x03; - rtkbt_adv_con.adverting_type = 0x03; - } - } - break; - case HCI_BLE_WRITE_ADV_ENABLE: - { - if (rtkbt_version.hci_version > HCI_PROTO_VERSION_4_2) - { - break; - } - if (recv_buffer[2] == 0x01) - { - rtkbt_adv_con.adverting_start = TRUE; - } - else if (recv_buffer[2] == 0x00) - { - rtkbt_adv_con.adverting_type = 0; - rtkbt_adv_con.adverting_enable = FALSE; - rtkbt_adv_con.adverting_start = FALSE; - } - } - break; - case HCI_BLE_CREATE_LL_CONN: - if (rtkbt_version.hci_version > HCI_PROTO_VERSION_4_2) - { - break; - } - if (rtkbt_adv_con.adverting_enable && - ((rtkbt_adv_con.adverting_type == 0x00) || - (rtkbt_adv_con.adverting_type == 0x01) || - (rtkbt_adv_con.adverting_type == 0x04))) - { - uint8_t disable_adv_cmd[5] = {0x01, 0x0A, 0x20, 0x01, 0x00}; - rtkbt_adv_con.adverting_enable = FALSE; - userial_send_cmd_to_controller(disable_adv_cmd, 5); - } - break; - default: - break; - } -} -#endif - -// This recv data from bt process. The data type only have ACL/SCO/COMMAND -// direction BT HOST ----> CONTROLLER -static void userial_recv_H4_rawdata(void *context) -{ - RTK_UNUSED(context); - serial_data_type_t type = 0; - ssize_t bytes_read; - uint16_t opcode; - uint16_t transmitted_length = 0; - // unsigned char *buffer = NULL; - - switch (packet_recv_state) - { - case RTKBT_PACKET_IDLE: - packet_bytes_need = 1; - do - { - RTK_NO_INTR(bytes_read = read(vnd_userial.uart_fd[1], &type, 1)); - if (bytes_read == -1) - { - HILOGE("%s, state = %d, read error %s", __func__, packet_recv_state, strerror(errno)); - return; - } - if (!bytes_read && packet_bytes_need) - { - HILOGE("%s, state = %d, bytes_read 0", __func__, packet_recv_state); - return; - } - - if (type < DATA_TYPE_COMMAND || type > DATA_TYPE_SCO) - { - HILOGE("%s invalid data type: %d", __func__, type); - assert((type >= DATA_TYPE_COMMAND) && (type <= DATA_TYPE_SCO)); - } - else - { - packet_bytes_need -= bytes_read; - packet_recv_state = RTKBT_PACKET_TYPE; - current_type = type; - h4_read_buffer[0] = type; - } - } while (packet_bytes_need); - // fall through - - case RTKBT_PACKET_TYPE: - packet_bytes_need = hci_preamble_sizes[HCI_PACKET_TYPE_TO_INDEX(current_type)]; - h4_read_length = 0; - packet_recv_state = RTKBT_PACKET_HEADER; - // fall through - - case RTKBT_PACKET_HEADER: - do - { - RTK_NO_INTR(bytes_read = read(vnd_userial.uart_fd[1], &h4_read_buffer[h4_read_length + 1], packet_bytes_need)); - if (bytes_read == -1) - { - HILOGE("%s, state = %d, read error %s", __func__, packet_recv_state, strerror(errno)); - return; - } - if (!bytes_read && packet_bytes_need) - { - HILOGE("%s, state = %d, bytes_read 0, type : %d", __func__, packet_recv_state, current_type); - return; - } - packet_bytes_need -= bytes_read; - h4_read_length += bytes_read; - } while (packet_bytes_need); - packet_recv_state = RTKBT_PACKET_CONTENT; - - if (current_type == DATA_TYPE_ACL) - { - packet_bytes_need = *(uint16_t *)&h4_read_buffer[COMMON_DATA_LENGTH_INDEX]; - } - else if (current_type == DATA_TYPE_EVENT) - { - packet_bytes_need = h4_read_buffer[EVENT_DATA_LENGTH_INDEX]; - } - else - { - packet_bytes_need = h4_read_buffer[COMMON_DATA_LENGTH_INDEX]; - } - // fall through - - case RTKBT_PACKET_CONTENT: - while (packet_bytes_need) - { - RTK_NO_INTR(bytes_read = read(vnd_userial.uart_fd[1], &h4_read_buffer[h4_read_length + 1], packet_bytes_need)); - if (bytes_read == -1) - { - HILOGE("%s, state = %d, read error %s", __func__, packet_recv_state, strerror(errno)); - return; - } - if (!bytes_read) - { - HILOGE("%s, state = %d, bytes_read 0", __func__, packet_recv_state); - return; - } - - packet_bytes_need -= bytes_read; - h4_read_length += bytes_read; - } - packet_recv_state = RTKBT_PACKET_END; - // fall through - - case RTKBT_PACKET_END: - switch (current_type) - { - case DATA_TYPE_COMMAND: -#ifdef RTK_HANDLE_CMD - userial_handle_cmd(&h4_read_buffer[1], h4_read_length); -#endif - if (rtkbt_transtype & RTKBT_TRANS_H4) - { - h4_int_transmit_data(h4_read_buffer, (h4_read_length + 1)); - } - else - { - opcode = *(uint16_t *)&h4_read_buffer[1]; - if (opcode == HCI_VSC_H5_INIT) - { - h5_int_interface->h5_send_sync_cmd(opcode, NULL, h4_read_length); - } - else - { - transmitted_length = h5_int_interface->h5_send_cmd(type, &h4_read_buffer[1], h4_read_length); - } - } - userial_enqueue_coex_rawdata(h4_read_buffer, (h4_read_length + 1), false); - break; - - case DATA_TYPE_ACL: - userial_send_acl_to_controller(h4_read_buffer, (h4_read_length + 1)); - break; - - case DATA_TYPE_SCO: - userial_send_sco_to_controller(h4_read_buffer, (h4_read_length + 1)); - break; - default: - HILOGE("%s invalid data type: %d", __func__, current_type); - userial_enqueue_coex_rawdata(h4_read_buffer, (h4_read_length + 1), false); - break; - } - break; - - default: - - break; - } - - packet_recv_state = RTKBT_PACKET_IDLE; - packet_bytes_need = 0; - current_type = 0; - h4_read_length = 0; -} - -static uint16_t h5_int_transmit_data_cb(serial_data_type_t type, uint8_t *data, uint16_t length) -{ - assert(data != NULL); - assert(length > 0); - - if (type != DATA_TYPE_H5) - { - HILOGE("%s invalid data type: %d", __func__, type); - return 0; - } - - uint16_t transmitted_length = 0; - while (length > 0 && vnd_userial.btdriver_state) - { - ssize_t ret = write(vnd_userial.fd, data + transmitted_length, length); - switch (ret) - { - case -1: - HILOGE("In %s, error writing to the uart serial port: %s", __func__, strerror(errno)); - goto done; - case 0: - // If we wrote nothing, don't loop more because we - // can't go to infinity or beyond, ohterwise H5 can resend data - HILOGE("%s, ret %zd", __func__, ret); - goto done; - default: - transmitted_length += ret; - length -= ret; - break; - } - } - -done:; - return transmitted_length; -} - -#ifdef RTK_HANDLE_EVENT -static void userial_handle_event(unsigned char *recv_buffer, int total_length) -{ - RTK_UNUSED(total_length); - uint8_t event; - uint8_t *p_data = recv_buffer; - event = p_data[0]; - switch (event) - { - case HCI_COMMAND_COMPLETE_EVT: - { - uint16_t opcode = *((uint16_t *)&p_data[3]); - uint8_t *stream = &p_data[6]; - if (opcode == HCI_READ_LOCAL_VERSION_INFO) - { - STREAM_TO_UINT8(rtkbt_version.hci_version, stream); - STREAM_TO_UINT16(rtkbt_version.hci_revision, stream); - STREAM_TO_UINT8(rtkbt_version.lmp_version, stream); - STREAM_TO_UINT16(rtkbt_version.manufacturer, stream); - STREAM_TO_UINT16(rtkbt_version.lmp_subversion, stream); - } - else if (opcode == HCI_BLE_WRITE_ADV_ENABLE) - { - if (rtkbt_version.hci_version > HCI_PROTO_VERSION_4_2) - { - break; - } - if (rtkbt_adv_con.adverting_start && (p_data[5] == HCI_SUCCESS)) - { - rtkbt_adv_con.adverting_enable = TRUE; - rtkbt_adv_con.adverting_start = FALSE; - } - } - } - break; -#ifdef CONFIG_SCO_OVER_HCI - case HCI_ESCO_CONNECTION_COMP_EVT: - { - if (p_data[2] != 0) - { - sco_cb.thread_sco_running = false; - sco_cb.thread_recv_sco_running = false; - sco_cb.thread_send_sco_running = false; - sco_cb.data_fd = -1; - sco_cb.ctrl_fd = -1; - } - else - { - sco_cb.sco_handle = *((uint16_t *)&p_data[3]); - pthread_attr_t thread_attr; - pthread_attr_init(&thread_attr); - pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE); - sco_cb.thread_sco_running = true; - sco_cb.thread_recv_sco_running = false; - sco_cb.thread_send_sco_running = false; - sco_cb.data_fd = -1; - sco_cb.ctrl_fd = -1; - if (pthread_create(&sco_cb.thread_socket_sco_id, &thread_attr, userial_socket_sco_thread, NULL) != 0) - { - HILOGE("pthread_create : %s", strerror(errno)); - } - - RtbEmptyQueue(sco_cb.recv_sco_data); - if (!(sco_cb.voice_settings & 0x0003)) - { - sco_cb.sco_packet_len = 240; // every 5 cvsd packets form a sco pcm data - sco_cb.msbc_used = false; - } - else - { - sco_cb.sco_packet_len = 60; - sco_cb.msbc_used = true; - } - sco_cb.current_pos = 0; - } - - HILOGE("userial_handle_event sco_handle: %d", sco_cb.sco_handle); - } - break; - - case HCI_DISCONNECTION_COMP_EVT: - { - if ((*((uint16_t *)&p_data[3])) == sco_cb.sco_handle) - { - sco_cb.sco_handle = 0; - sco_cb.msbc_used = false; - RtbEmptyQueue(sco_cb.recv_sco_data); - if (sco_cb.thread_sco_running) - { - sco_cb.thread_sco_running = false; - unsigned char close_signal = 1; - ssize_t ret; - RTK_NO_INTR(ret = write(sco_cb.signal_fd[0], &close_signal, 1)); - } - } - } - break; -#endif - default: - break; - } -} - -#ifdef CONFIG_SCO_OVER_HCI -static void userial_enqueue_recv_sco_data(unsigned char *recv_buffer, int total_length) -{ - RTK_UNUSED(total_length); - uint16_t sco_handle; - uint8_t sco_length; - uint8_t *p_data = recv_buffer; - RTK_BUFFER *skb_sco_data; - int i; - sco_handle = *((uint16_t *)p_data); - uint16_t current_pos = sco_cb.current_pos; - uint16_t sco_packet_len = sco_cb.sco_packet_len; - - if (sco_handle == sco_cb.sco_handle) - { - sco_length = p_data[SCO_PREAMBLE_SIZE - 1]; - p_data += SCO_PREAMBLE_SIZE; - - if (current_pos) - { - if ((sco_packet_len - current_pos) <= sco_length) - { - memcpy(&sco_cb.enc_data[current_pos], p_data, (sco_packet_len - current_pos)); - skb_sco_data = RtbAllocate(sco_packet_len, 0); - memcpy(skb_sco_data->Data, sco_cb.enc_data, sco_packet_len); - RtbAddTail(skb_sco_data, sco_packet_len); - pthread_mutex_lock(&sco_cb.sco_recv_mutex); - RtbQueueTail(sco_cb.recv_sco_data, skb_sco_data); - pthread_cond_signal(&sco_cb.sco_recv_cond); - pthread_mutex_unlock(&sco_cb.sco_recv_mutex); - - sco_cb.current_pos = 0; - p_data += (sco_packet_len - current_pos); - sco_length -= (sco_packet_len - current_pos); - } - else - { - memcpy(&sco_cb.enc_data[current_pos], p_data, sco_length); - sco_cb.current_pos += sco_length; - return; - } - } - - // if use cvsd codec - if (!sco_cb.msbc_used) - { - for (i = 0; i < (sco_length / sco_packet_len); i++) - { - skb_sco_data = RtbAllocate(sco_packet_len, 0); - memcpy(skb_sco_data->Data, p_data + i * sco_packet_len, sco_packet_len); - RtbAddTail(skb_sco_data, sco_packet_len); - RtbQueueTail(sco_cb.recv_sco_data, skb_sco_data); - } - if ((sco_length / sco_packet_len)) - { - pthread_mutex_lock(&sco_cb.sco_recv_mutex); - pthread_cond_signal(&sco_cb.sco_recv_cond); - pthread_mutex_unlock(&sco_cb.sco_recv_mutex); - } - - i = (sco_length % sco_packet_len); - current_pos = sco_length - i; - if (i) - { - memcpy(sco_cb.enc_data, p_data + current_pos, i); - sco_cb.current_pos = i; - } - return; - } - - // use msbc codec - for (i = 0; i < sco_length; i++) - { - if ((p_data[i] == 0x01) && ((p_data[i + 1] & 0x0f) == 0x08) && (p_data[i + 2] == 0xAD)) - { - if ((sco_length - i) < sco_packet_len) - { - memcpy(sco_cb.enc_data, &p_data[i], (sco_length - i)); - sco_cb.current_pos = sco_length - i; - return; - } - else - { - memcpy(sco_cb.enc_data, &p_data[i], sco_packet_len); // complete msbc data - skb_sco_data = RtbAllocate(sco_packet_len, 0); - memcpy(skb_sco_data->Data, sco_cb.enc_data, sco_packet_len); - RtbAddTail(skb_sco_data, sco_packet_len); - pthread_mutex_lock(&sco_cb.sco_recv_mutex); - RtbQueueTail(sco_cb.recv_sco_data, skb_sco_data); - pthread_cond_signal(&sco_cb.sco_recv_cond); - pthread_mutex_unlock(&sco_cb.sco_recv_mutex); - - sco_cb.current_pos = 0; - i += (sco_packet_len - 1); - } - } - } - } -} -#endif - -static int userial_handle_recv_data(unsigned char *recv_buffer, unsigned int total_length) -{ - serial_data_type_t type = 0; - unsigned char *p_data = recv_buffer; - unsigned int length = total_length; - uint8_t event; - - if (!length) - { - HILOGE("%s, length is 0, return immediately", __func__); - return total_length; - } - switch (received_packet_state) - { - case RTKBT_PACKET_IDLE: - received_packet_bytes_need = 1; - while (length) - { - type = p_data[0]; - length--; - p_data++; - if (type < DATA_TYPE_ACL || type > DATA_TYPE_EVENT) - { - HILOGE("%s invalid data type: %d", __func__, type); - assert((type > DATA_TYPE_COMMAND) && (type <= DATA_TYPE_EVENT)); - if (!length) - return total_length; - - continue; - } - break; - } - recv_packet_current_type = type; - received_packet_state = RTKBT_PACKET_TYPE; - // fall through - - case RTKBT_PACKET_TYPE: - received_packet_bytes_need = hci_preamble_sizes[HCI_PACKET_TYPE_TO_INDEX(recv_packet_current_type)]; - received_resvered_length = 0; - received_packet_state = RTKBT_PACKET_HEADER; - // fall through - - case RTKBT_PACKET_HEADER: - if (length >= received_packet_bytes_need) - { - memcpy(&received_resvered_header[received_resvered_length], p_data, received_packet_bytes_need); - received_resvered_length += received_packet_bytes_need; - length -= received_packet_bytes_need; - p_data += received_packet_bytes_need; - } - else - { - memcpy(&received_resvered_header[received_resvered_length], p_data, length); - received_resvered_length += length; - received_packet_bytes_need -= length; - length = 0; - return total_length; - } - received_packet_state = RTKBT_PACKET_CONTENT; - - if (recv_packet_current_type == DATA_TYPE_ACL) - { - received_packet_bytes_need = *(uint16_t *)&received_resvered_header[2]; - } - else if (recv_packet_current_type == DATA_TYPE_EVENT) - { - received_packet_bytes_need = received_resvered_header[1]; - } - else - { - received_packet_bytes_need = received_resvered_header[2]; - } - // fall through - - case RTKBT_PACKET_CONTENT: - if (recv_packet_current_type == DATA_TYPE_EVENT) - { - event = received_resvered_header[0]; - - if (event == HCI_COMMAND_COMPLETE_EVT) - { - if (received_resvered_length == 2) - { - if (length >= 1) - { - *p_data = 1; - } - } - } - else if (event == HCI_COMMAND_STATUS_EVT) - { - if (received_resvered_length < 4) - { - unsigned int act_len = 4 - received_resvered_length; - if (length >= act_len) - { - *(p_data + act_len - 1) = 1; - } - } - } - } - if (length >= received_packet_bytes_need) - { - memcpy(&received_resvered_header[received_resvered_length], p_data, received_packet_bytes_need); - length -= received_packet_bytes_need; - p_data += received_packet_bytes_need; - received_resvered_length += received_packet_bytes_need; - received_packet_bytes_need = 0; - } - else - { - memcpy(&received_resvered_header[received_resvered_length], p_data, length); - received_resvered_length += length; - received_packet_bytes_need -= length; - length = 0; - return total_length; - } - received_packet_state = RTKBT_PACKET_END; - // fall through - - case RTKBT_PACKET_END: - switch (recv_packet_current_type) - { - case DATA_TYPE_EVENT: - userial_handle_event(received_resvered_header, received_resvered_length); - break; -#ifdef CONFIG_SCO_OVER_HCI - case DATA_TYPE_SCO: - userial_enqueue_recv_sco_data(received_resvered_header, received_resvered_length); - break; -#endif - default: - - break; - } - break; - - default: - - break; - } - - received_packet_state = RTKBT_PACKET_IDLE; - received_packet_bytes_need = 0; - recv_packet_current_type = 0; - received_resvered_length = 0; - - return (total_length - length); -} -#endif - -static void h5_data_ready_cb(serial_data_type_t type, unsigned int total_length) -{ - unsigned char buffer[1028] = {0}; - int length = 0; - length = h5_int_interface->h5_int_read_data(&buffer[1], total_length); - if (length == -1) - { - HILOGE("%s, error read length", __func__); - assert(length != -1); - } - buffer[0] = type; - length++; - uint16_t transmitted_length = 0; - unsigned int real_length = length; -#ifdef RTK_HANDLE_EVENT - unsigned int read_length = 0; - do - { - read_length += userial_handle_recv_data(buffer + read_length, real_length - read_length); - } while (vnd_userial.thread_running && read_length < total_length); -#endif - - while (length > 0) - { - ssize_t ret; - RTK_NO_INTR(ret = write(vnd_userial.uart_fd[1], buffer + transmitted_length, length)); - switch (ret) - { - case -1: - HILOGE("In %s, error writing to the uart serial port: %s", __func__, strerror(errno)); - goto done; - case 0: - // If we wrote nothing, don't loop more because we - // can't go to infinity or beyond - goto done; - default: - transmitted_length += ret; - length -= ret; - break; - } - } -done:; - if (real_length) - userial_enqueue_coex_rawdata(buffer, real_length, true); - return; -} - -// This recv data from driver which is sent or recv by the controller. The data type have ACL/SCO/EVENT -// direction CONTROLLER -----> BT HOST -static void userial_recv_uart_rawdata(unsigned char *buffer, unsigned int total_length) -{ - unsigned int length = total_length; - uint16_t transmitted_length = 0; -#ifdef RTK_HANDLE_EVENT - unsigned int read_length = 0; - do - { - read_length += userial_handle_recv_data(buffer + read_length, total_length - read_length); - } while (read_length < total_length); -#endif - while (length > 0 && vnd_userial.thread_running) - { - ssize_t ret; - RTK_NO_INTR(ret = write(vnd_userial.uart_fd[1], buffer + transmitted_length, length)); - switch (ret) - { - case -1: - HILOGE("In %s, error writing to the uart serial port: %s", __func__, strerror(errno)); - goto done; - case 0: - // If we wrote nothing, don't loop more because we - // can't go to infinity or beyond - goto done; - default: - transmitted_length += ret; - length -= ret; - break; - } - } -done:; - if (total_length) - userial_enqueue_coex_rawdata(buffer, total_length, true); - return; -} - -void userial_recv_rawdata_hook(unsigned char *buffer, unsigned int total_length) -{ - uint16_t transmitted_length = 0; - unsigned int real_length = total_length; - - while (vnd_userial.thread_running && (total_length > 0)) - { - ssize_t ret; - RTK_NO_INTR(ret = write(vnd_userial.uart_fd[1], buffer + transmitted_length, total_length)); - switch (ret) - { - case -1: - HILOGE("In %s, error writing to the uart serial port: %s", __func__, strerror(errno)); - goto done; - case 0: - // If we wrote nothing, don't loop more because we - // can't go to infinity or beyond - goto done; - default: - transmitted_length += ret; - total_length -= ret; - break; - } - } -done:; - if (real_length && vnd_userial.thread_running) - userial_enqueue_coex_rawdata(buffer, real_length, true); - return; -} - -static void *userial_recv_socket_thread(void *arg) -{ - RTK_UNUSED(arg); - struct epoll_event events[64]; - int j; - while (vnd_userial.thread_running) - { - int ret; - do - { - ret = epoll_wait(vnd_userial.epoll_fd, events, 32, 500); - } while (vnd_userial.thread_running && ret == -1 && errno == EINTR); - - if (ret == -1) - { - HILOGE("%s error in epoll_wait: %s", __func__, strerror(errno)); - } - for (j = 0; j < ret; ++j) - { - struct rtk_object_t *object = (struct rtk_object_t *)events[j].data.ptr; - if (events[j].data.ptr == NULL) - continue; - else - { - if (events[j].events & (EPOLLIN | EPOLLHUP | EPOLLRDHUP | EPOLLERR) && object->read_ready) - object->read_ready(object->context); - if (events[j].events & EPOLLOUT && object->write_ready) - object->write_ready(object->context); - } - } - } - vnd_userial.thread_socket_id = (pthread_t)-1; - HILOGD("%s exit", __func__); - return NULL; -} - -static void *userial_recv_uart_thread(void *arg) -{ - RTK_UNUSED(arg); - struct pollfd pfd[2]; - pfd[0].events = POLLIN | POLLHUP | POLLERR | POLLRDHUP; - pfd[0].fd = vnd_userial.signal_fd[1]; - pfd[1].events = POLLIN | POLLHUP | POLLERR | POLLRDHUP; - pfd[1].fd = vnd_userial.fd; - int ret; - unsigned char read_buffer[2056] = {0}; - ssize_t bytes_read; - while (vnd_userial.thread_running) - { - do - { - ret = poll(pfd, 2, 500); - } while (ret == -1 && errno == EINTR && vnd_userial.thread_running); - - // exit signal is always at first index - if (pfd[0].revents && !vnd_userial.thread_running) - { - HILOGE("receive exit signal and stop thread "); - return NULL; - } - - if (pfd[1].revents & POLLIN) - { - RTK_NO_INTR(bytes_read = read(vnd_userial.fd, read_buffer, sizeof(read_buffer))); - if (!bytes_read) - continue; - if (bytes_read < 0) - { - HILOGE("%s, read fail, error : %s", __func__, strerror(errno)); - continue; - } - - if (rtkbt_transtype & RTKBT_TRANS_H5) - { - h5_int_interface->h5_recv_msg(read_buffer, bytes_read); - } - else - { - userial_recv_uart_rawdata(read_buffer, bytes_read); - } - } - - if (pfd[1].revents & (POLLERR | POLLHUP)) - { - HILOGE("%s poll error, fd : %d", __func__, vnd_userial.fd); - vnd_userial.btdriver_state = false; - close(vnd_userial.fd); - return NULL; - } - if (ret < 0) - { - HILOGE("%s : error (%d)", __func__, ret); - continue; - } - } - vnd_userial.thread_uart_id = (pthread_t)-1; - HILOGD("%s exit", __func__); - return NULL; -} - -static void *userial_coex_thread(void *arg) -{ - RTK_UNUSED(arg); - struct epoll_event events[64]; - int j; - while (vnd_userial.thread_running) - { - int ret; - do - { - ret = epoll_wait(vnd_userial.cpoll_fd, events, 64, 500); - } while (ret == -1 && errno == EINTR && vnd_userial.thread_running); - if (ret == -1) - { - HILOGE("%s error in epoll_wait: %s", __func__, strerror(errno)); - } - for (j = 0; j < ret; ++j) - { - struct rtk_object_t *object = (struct rtk_object_t *)events[j].data.ptr; - if (events[j].data.ptr == NULL) - continue; - else - { - if (events[j].events & (EPOLLIN | EPOLLHUP | EPOLLRDHUP | EPOLLERR) && object->read_ready) - object->read_ready(object->context); - if (events[j].events & EPOLLOUT && object->write_ready) - object->write_ready(object->context); - } - } - } - vnd_userial.thread_coex_id = (pthread_t)-1; - HILOGD("%s exit", __func__); - return NULL; -} - -int userial_socket_open() -{ - int ret = 0; - struct epoll_event event; - if ((ret = socketpair(AF_UNIX, SOCK_STREAM, 0, vnd_userial.uart_fd)) < 0) - { - HILOGE("%s, errno : %s", __func__, strerror(errno)); - return ret; - } - - if ((ret = socketpair(AF_UNIX, SOCK_STREAM, 0, vnd_userial.signal_fd)) < 0) - { - HILOGE("%s, errno : %s", __func__, strerror(errno)); - return ret; - } - - vnd_userial.epoll_fd = epoll_create(64); - if (vnd_userial.epoll_fd == -1) - { - HILOGE("%s unable to create epoll instance: %s", __func__, strerror(errno)); - return -1; - } - - rtk_socket_object.fd = vnd_userial.uart_fd[1]; - rtk_socket_object.read_ready = userial_recv_H4_rawdata; - memset(&event, 0, sizeof(event)); - event.events |= EPOLLIN | EPOLLHUP | EPOLLRDHUP | EPOLLERR; - event.data.ptr = (void *)&rtk_socket_object; - if (epoll_ctl(vnd_userial.epoll_fd, EPOLL_CTL_ADD, vnd_userial.uart_fd[1], &event) == -1) - { - HILOGE("%s unable to register fd %d to epoll set: %s", __func__, vnd_userial.uart_fd[1], strerror(errno)); - close(vnd_userial.epoll_fd); - vnd_userial.epoll_fd = -1; - return -1; - } - - event.data.ptr = NULL; - if (epoll_ctl(vnd_userial.epoll_fd, EPOLL_CTL_ADD, vnd_userial.signal_fd[1], &event) == -1) - { - HILOGE("%s unable to register signal fd %d to epoll set: %s", __func__, vnd_userial.signal_fd[1], strerror(errno)); - close(vnd_userial.epoll_fd); - vnd_userial.epoll_fd = -1; - return -1; - } - pthread_attr_t thread_attr; - pthread_attr_init(&thread_attr); - pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE); - vnd_userial.thread_running = true; - if (pthread_create(&vnd_userial.thread_socket_id, &thread_attr, userial_recv_socket_thread, NULL) != 0) - { - HILOGE("pthread_create : %s", strerror(errno)); - close(vnd_userial.epoll_fd); - vnd_userial.epoll_fd = -1; - vnd_userial.thread_socket_id = (pthread_t)-1; - return -1; - } - - if (pthread_create(&vnd_userial.thread_uart_id, &thread_attr, userial_recv_uart_thread, NULL) != 0) - { - HILOGE("pthread_create : %s", strerror(errno)); - close(vnd_userial.epoll_fd); - vnd_userial.thread_running = false; - pthread_join(vnd_userial.thread_socket_id, NULL); - vnd_userial.thread_socket_id = (pthread_t)-1; - return -1; - } - - vnd_userial.cpoll_fd = epoll_create(64); - assert(vnd_userial.cpoll_fd != -1); - - vnd_userial.event_fd = eventfd(10, EFD_NONBLOCK); - assert(vnd_userial.event_fd != -1); - if (vnd_userial.event_fd != -1) - { - rtk_coex_object.fd = vnd_userial.event_fd; - rtk_coex_object.read_ready = userial_coex_handler; - memset(&event, 0, sizeof(event)); - event.events |= EPOLLIN | EPOLLHUP | EPOLLRDHUP | EPOLLERR; - event.data.ptr = (void *)&rtk_coex_object; - if (epoll_ctl(vnd_userial.cpoll_fd, EPOLL_CTL_ADD, vnd_userial.event_fd, &event) == -1) - { - HILOGE("%s unable to register fd %d to cpoll set: %s", __func__, vnd_userial.event_fd, strerror(errno)); - assert(false); - } - - event.data.ptr = NULL; - if (epoll_ctl(vnd_userial.cpoll_fd, EPOLL_CTL_ADD, vnd_userial.signal_fd[1], &event) == -1) - { - HILOGE("%s unable to register fd %d to cpoll set: %s", __func__, vnd_userial.signal_fd[1], strerror(errno)); - assert(false); - } - - if (pthread_create(&vnd_userial.thread_coex_id, &thread_attr, userial_coex_thread, NULL) != 0) - { - HILOGE("pthread create coex : %s", strerror(errno)); - vnd_userial.thread_coex_id = (pthread_t)-1; - assert(false); - } - } - - ret = vnd_userial.uart_fd[0]; - return ret; -} - -int userial_vendor_usb_ioctl(int operation, void *param) -{ - int retval; - retval = ioctl(vnd_userial.fd, operation, param); - if (retval == -1) - HILOGE("%s: error: %d : %s", __func__, errno, strerror(errno)); - return retval; -} - -int userial_vendor_usb_open(void) -{ - if ((vnd_userial.fd = open(vnd_userial.port_name, O_RDWR)) == -1) - { - HILOGE("%s: unable to open %s: %s", __func__, vnd_userial.port_name, strerror(errno)); - return -1; - } - - vnd_userial.btdriver_state = true; - HILOGI("device fd = %d open", vnd_userial.fd); - - return vnd_userial.fd; -} diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/rtkcmd/rtkcmd.c b/hispark_phoenix/peripherals/bluetooth/rtkbt/code/rtkcmd/rtkcmd.c deleted file mode 100755 index 23d669f2..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/code/rtkcmd/rtkcmd.c +++ /dev/null @@ -1,264 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 2009-2018 Realtek Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - ******************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define UNIX_DOMAIN "@/data/misc/bluedroid/rtkbt_service.sock" - -typedef struct Rtk_Socket_Data -{ - unsigned char type; // hci,other,inner - unsigned char opcodeh; - unsigned char opcodel; - unsigned char parameter_len; - unsigned char parameter[0]; -} Rtk_Socket_Data; - -/*typedef struct -{ - unsigned short event; - unsigned short len; - unsigned short offset; - unsigned short layer_specific; - unsigned char data[]; -} HC_BT_HDR; -*/ -const char shortOptions[] = "f:r:h"; -const struct option longOptions[] = { - {"fullhcicmd", required_argument, NULL, 'f'}, - {"read", required_argument, NULL, 'r'}, - {"help", no_argument, NULL, 'h'}, - {0, 0, 0, 0}}; - -static void usage(void) -{ - fprintf(stderr, "Usage: rtkcmd [options]\n\n" - "Options:\n" - "-f | --fullhcicmd [opcode,parameter_len,parameter] send hci cmd\n" - "-r | --read [address] read register address \n" - "-h | --help Print this message\n\n"); -} - -int Rtkbt_Sendcmd(int socketfd, char *p) -{ - char *token = NULL; - int i = 0; - unsigned short OpCode = 0; - unsigned char ParamLen = 0; - unsigned char ParamLen_1 = 0; - int sendlen = 0; - int params_count = 0; - int ret = 0; - Rtk_Socket_Data *p_buf = NULL; - - token = strtok(p, ","); - if (token != NULL) - { - OpCode = strtol(token, NULL, 0); - // printf("OpCode = %x\n",OpCode); - params_count++; - } - else - { - // ret = FUNCTION_PARAMETER_ERROR; - printf("parameter error\n"); - return -1; - } - - token = strtok(NULL, ","); - if (token != NULL) - { - ParamLen = strtol(token, NULL, 0); - // printf("ParamLen = %d\n",ParamLen); - params_count++; - } - else - { - printf("parameter error\n"); - return -1; - } - - p_buf = (Rtk_Socket_Data *)malloc(sizeof(Rtk_Socket_Data) + sizeof(char) * ParamLen); - p_buf->type = 0x01; - p_buf->opcodeh = OpCode >> 8; - p_buf->opcodel = OpCode & 0xff; - p_buf->parameter_len = ParamLen; - - ParamLen_1 = ParamLen; - while (ParamLen_1--) - { - token = strtok(NULL, ","); - if (token != NULL) - { - p_buf->parameter[i++] = strtol(token, NULL, 0); - params_count++; - } - else - { - printf("parameter error\n"); - return -1; - } - } - - if (params_count != ParamLen + 2) - { - printf("parameter error\n"); - return -1; - } - - sendlen = sizeof(Rtk_Socket_Data) + sizeof(char) * p_buf->parameter_len; - ret = write(socketfd, p_buf, sendlen); - if (ret != sendlen) - return -1; - - free(p_buf); - return 0; -} - -int Rtkbt_Getevent(int sock_fd) -{ - unsigned short event = 0; - unsigned short event_len = 0; - unsigned short offset = 0; - unsigned short layer_specific = 0; - unsigned char *recvbuf = NULL; - int ret = 0; - int i; - - ret = read(sock_fd, &event, 2); - if (ret <= 0) - return -1; - // printf("event = %x\n",event); - - ret = read(sock_fd, &event_len, 2); - if (ret <= 0) - return -1; - // printf("event_len = %x\n",event_len); - - ret = read(sock_fd, &offset, 2); - if (ret <= 0) - return -1; - // printf("offset = %x\n",offset); - - ret = read(sock_fd, &layer_specific, 2); - if (ret <= 0) - return -1; - // printf("layer_specific = %x\n",layer_specific); - - recvbuf = (unsigned char *)malloc(sizeof(char) * event_len); - ret = read(sock_fd, recvbuf, event_len); - if (ret < event_len) - return -1; - - printf("Event: "); - for (i = 0; i < event_len - 1; i++) - printf("0x%02x ", recvbuf[i]); - printf("0x%02x\n", recvbuf[event_len - 1]); - - free(recvbuf); - return 0; -} - -int socketinit() -{ - int sock_fd; - struct sockaddr_un un; - int len; - memset(&un, 0, sizeof(un)); /* fill socket address structure with our address */ - un.sun_family = AF_UNIX; - strcpy(un.sun_path, UNIX_DOMAIN); - un.sun_path[0] = 0; - len = offsetof(struct sockaddr_un, sun_path) + strlen(UNIX_DOMAIN); - - sock_fd = socket(AF_UNIX, SOCK_STREAM, 0); - if (sock_fd < 0) - { - printf("socket failed %s\n", strerror(errno)); - return -1; - } - if (connect(sock_fd, (struct sockaddr *)&un, len) < 0) - { - printf("connect failed %s\n", strerror(errno)); - close(sock_fd); - return -1; - } - - return sock_fd; -} - -int main(int argc, char *argv[]) -{ - int index; - int c; - int ret; - int socketfd; - - socketfd = socketinit(); - if (socketfd < 0) - { - printf("socketinit failed\n"); - exit(0); - } - - c = getopt_long(argc, argv, shortOptions, longOptions, &index); - - if (c == -1) - { - usage(); - } - else - { - switch (c) - { - case 'f': - { - printf("Hcicmd %s\n", optarg); - ret = Rtkbt_Sendcmd(socketfd, optarg); - if (ret >= 0) - { - if (Rtkbt_Getevent(socketfd) < 0) - printf("Getevent fail\n"); - } - break; - } - case 'r': - { - printf("read register %s\n", optarg); - // Rtkbt_Readreg(socketfd,optarg); - break; - } - case 'h': - { - usage(); - break; - } - } - } - - close(socketfd); -} \ No newline at end of file diff --git a/hispark_phoenix/peripherals/bluetooth/rtkbt/vendor/etc/bluetooth/rtkbt.conf b/hispark_phoenix/peripherals/bluetooth/rtkbt/vendor/etc/bluetooth/rtkbt.conf deleted file mode 100755 index 6bf390ab..00000000 --- a/hispark_phoenix/peripherals/bluetooth/rtkbt/vendor/etc/bluetooth/rtkbt.conf +++ /dev/null @@ -1,37 +0,0 @@ -# RELEASE NAME: 20190717_BT_ANDROID_9.0 -# Bluetooth Device Name; NULL or comment means "ro.product.model" -#Name=Realtek Bluetooth - -# Device Class -DevClassServiceClass=0x1A -DevClassMajorClass=0x01 -DevClassMinorClass=0x1C - -#Indicate USB or UART driver bluetooth -BtDeviceNode=?/dev/ttyS1:H5 - -# Enable BtSnoop logging function -# valid value : true, false -RtkBtsnoopDump=false - -# BtSnoop log output file -BtSnoopFileName=/data/misc/bluedroid/btsnoop_hci.cfa - -# Preserve existing BtSnoop log before overwriting -BtSnoopSaveLog=true - -#bit0 = 1,don't show heartbeat packet in btsnoop -RtkbtLogFilter=1 - -# configuration for uart card to save HCI log for slave -H5LogOutput=0 - -# Enable Coex log -BtCoexLogOutput=0 - -# Enable net btsnoop Dump -RtkBtsnoopNetDump=false - - -# Enable auto restart bt -RtkBtAutoRestart=true -- Gitee