Android7 AT指令修改BT MAC地址

1.高通Android 7获取蓝牙MAC地址流程为开机后调用btnvtool -O从NV477节点中获取AT指令修改的蓝牙MAC地址,写入到.btnv.bin中,再从.btnv.bin中获取蓝牙MAC地址用于使用。若NV447中不存在BT MAC地址则随机生成。

2.高通原生的可能不生效,需要合入一些代码,分三部分:

       ①创建persiset/bluetooth路径,用于存放使用btnvtool -O产生的.btnv.bin,参考如下patch

diff --git a/device/qcom/common/rootdir/etc/init.qcom.rc b/device/qcom/common/rootdir/etc/init.qcom.rc
index 708a25c..e14b4ca 100644
--- a/device/qcom/common/rootdir/etc/init.qcom.rc
+++ b/device/qcom/common/rootdir/etc/init.qcom.rc
@@ -104,6 +104,7 @@ on boot
     mkdir /persist/drm 0770 system system
     mkdir /persist/misc 0770 system system
     mkdir /persist/alarm 0770 system system
+    mkdir /persist/bluetooth 0770 bluetooth bluetooth
 
     #Create NETMGR daemon socket area
     mkdir /dev/socket/netmgr 0750 radio radio

    ②解决权限问题:

diff --git a/device/qcom/sepolicy/common/atfwd.te b/device/qcom/sepolicy/common/atfwd.te
index 5712380..b667e64 100644
--- a/device/qcom/sepolicy/common/atfwd.te
+++ b/device/qcom/sepolicy/common/atfwd.te
@@ -16,5 +16,7 @@ r_dir_file(atfwd, sysfs_ssr);
 allow atfwd self:{ udp_socket socket } create_socket_perms;
 unix_socket_connect(atfwd, property, init);
 
+allow atfwd diag_device:chr_file { read write };
+
 allow atfwd radio_prop:property_service set;
 allow atfwd atfwd_service:service_manager find;
diff --git a/device/qcom/sepolicy/common/bluetooth.te b/device/qcom/sepolicy/common/bluetooth.te
index eef36b8..e13cf8b 100644
--- a/device/qcom/sepolicy/common/bluetooth.te
+++ b/device/qcom/sepolicy/common/bluetooth.te
@@ -26,6 +26,16 @@ domain_auto_trans(init, fmhal_service_exec, bluetooth)
 allow bluetooth bluetooth_prop:property_service set;
 allow bluetooth sysfs:file w_file_perms;
 
+allow qti_init_shell btnvtool_exec:file {getattr execute read open execute_no_trans};
+allow qti_init_shell persist_bluetooth_file:dir {remove_name add_name create read write search };
+allow qti_init_shell qti_init_shell:socket {read write create ioctl};
+allow qti_init_shell qmuxd_socket:dir {create search write add_name};
+allow qti_init_shell diag_device:chr_file {open read write ioctl };
+allow qti_init_shell persist_bluetooth_file:file {create setattr read write unlink};
+allow qti_init_shell qmuxd_socket:sock_file {create write};
+allow qti_init_shell qmuxd:unix_stream_socket connectto;
+
+
 #Access to /data/media
 allow bluetooth media_rw_data_file:dir create_dir_perms;
 allow bluetooth media_rw_data_file:file create_file_perms;

 如何确认是权限问题导致:

adb root

adb shell

setenforce 0

功能正常即为权限问题。

如何解决权限问题:

抓取dmesg或者logcat log,将文件放到linux环境下,
cat logcat.txt | grep avc | audit2allow

将报的权限加到工程中

③ 添加MAC地址全为0的校验:



diff --git a/vendor/qcom/proprietary/bt/hci_qcomm_init/btnvtool.cpp b/vendor/qcom/proprietary/bt/hci_qcomm_init/btnvtool.cpp
index 7af06e3..eb64ff0 100755
--- a/vendor/qcom/proprietary/bt/hci_qcomm_init/btnvtool.cpp
+++ b/vendor/qcom/proprietary/bt/hci_qcomm_init/btnvtool.cpp
@@ -160,6 +160,13 @@ int main(int argc, char *argv[])
        case 'O':
          snprintf(filename, NAME_MAX, "%s/%s", PERSISTENCE_PATH, BT_NV_FILE_NAME);
          ret = stat(filename, &sts);
+         //if mac is 00:00:00:00:00:00, get random mac.
+         if(ret==0&&sts.st_size>0)
+         {
+			     ALOGE("The file .bt_nv.bin exist %d ---%d,remove it",ret,sts.st_size);
+			     remove(filename);
+			     ret = stat(filename, &sts);
+         }
          is_exist_addr_random = bt_nv_is_random_addr();
          if ((ret == -1 && errno == ENOENT) || (ret == 0 && sts.st_size == 0) ||
             (TRUE == is_exist_addr_random) )
@@ -227,6 +234,11 @@ int main(int argc, char *argv[])
                     }
                 }
             }
+                if((BD_addr[0]|BD_addr[1]|BD_addr[2]|BD_addr[3]|BD_addr[4]|BD_addr[5]) == 0)
+                {
+                  ALOGE("BD_addr 6 bytes is 00:00:00:00:00:00");
+                  bd_set = FALSE;
+                }
 
             if(!bd_set && (FALSE == is_exist_addr_random))
             {
-- 
2.7.4

  • 1
    点赞
  • 0
    收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:数字20 设计师:CSDN官方博客 返回首页
评论 1

打赏作者

NV447

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值