AdapterService.java


上层一点搜索的button就开始走到底层so的JNI调用

start_discovery
btif_dm_start_discoveryBTA_DmBleScanFilterSetup设置扫描过滤->bta_dm_scan_filter_param_setup, /* BTA_DM_API_SCAN_FILTER_SETUP_EVT */BTA_DmBleScanFilterSetup

BTA_DmBleScanFilterSetup为扫描参数设置,接下来走到
bta_dm_scan_filter_param_setup,先清除扫描参数,再设置默认的扫描参数

搜索周边设备BTA_DmSearch(&inq_params, services, bte_search_devices_evt);
执行到
bta_dm_search_sm_execute-》bta_dm_search_start中先清醒扫描缓存,设置扫描参数,再进行扫描BTM_StartInquiry->btm_ble_start_inquiry->
btm_ble_start_scan->btsnd_hcic_ble_set_scan_enable发送命令到主控开始扫描
设置定时器,时间到了停止扫描static void btm_ble_inquiry_timer_timeout(UNUSED_ATTR void *data){           btm_ble_stop_inquiry();} 并调用完成扫描函数btm_process_inq_complete
``

当有事件响应时,即有广播包来时,触发事件读取函数
btu_hci_msg_process-》BT_EVT_TO_BTU_HCI_EVT-》 btu_hcif_process_event ((UINT8)(p_msg->event & BT_SUB_EVT_MASK), p_msg);
case HCI_BLE_EVENT:(BLE事件)
case HCI_BLE_ADV_PKT_RPT_EVT: /* result of inquiry */
btu_ble_process_adv_pkt§;处理扫描到的广播包-》btm_ble_process_adv_pkt_cont
btm_ble_update_inq_result 更新扫描到的数据库
btm_ble_is_discoverable找出可被扫描的设备
//执行回调 BTA_DmSearch(&inq_params, services, bte_search_devices_evt);
bte_search_devices_evt->
btif_dm_search_devices_evt

case BTA_DM_INQ_RES_EVT:
{
/* inquiry result */
UINT32 cod;
bt_bdname_t bdname;
bt_bdaddr_t bdaddr;
UINT8 remote_name_len;
tBTA_SERVICE_MASK services = 0;
bdstr_t bdstr;p_search_data = (tBTA_DM_SEARCH *)p_param;
bdcpy(bdaddr.address, p_search_data->inq_res.bd_addr);BTIF_TRACE_DEBUG("%s() %s device_type = 0x%x\n", __FUNCTION__, bdaddr_to_string(&bdaddr, bdstr, sizeof(bdstr)),
#if (BLE_INCLUDED == TRUE)
p_search_data->inq_res.device_type);
#else
BT_DEVICE_TYPE_BREDR);
#endif
bdname.name[0] = 0;cod = devclass2uint (p_search_data->inq_res.dev_class);if (cod == 0) {
LOG_DEBUG("%s cod is 0, set as unclassified", __func__);
cod = COD_UNCLASSIFIED;
}if (!check_eir_remote_name(p_search_data, bdname.name, &remote_name_len))
check_cached_remote_name(p_search_data, bdname.name, &remote_name_len);/* Check EIR for remote name and services */
if (p_search_data->inq_res.p_eir)
{
BTA_GetEirService(p_search_data->inq_res.p_eir, &services);
BTIF_TRACE_DEBUG("%s()EIR BTA services = %08X", __FUNCTION__, (UINT32)services);
/* TODO:  Get the service list and check to see which uuids we got and send it back to the client. */
}{
bt_property_t properties[5];
bt_device_type_t dev_type;
uint32_t num_properties = 0;
bt_status_t status;
int addr_type = 0;memset(properties, 0, sizeof(properties));
/* BD_ADDR */
BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
BT_PROPERTY_BDADDR, sizeof(bdaddr), &bdaddr);
num_properties++;
/* BD_NAME */
/* Don't send BDNAME if it is empty */
if (bdname.name[0])
{
BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
BT_PROPERTY_BDNAME,
strlen((char *)bdname.name), &bdname);
num_properties++;
}/* DEV_CLASS */
BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod);
num_properties++;
/* DEV_TYPE */
#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
/* FixMe: Assumption is that bluetooth.h and BTE enums match *//* Verify if the device is dual mode in NVRAM */
int stored_device_type = 0;
if (btif_get_device_type(bdaddr.address, &stored_device_type) &&
((stored_device_type == BT_DEVICE_TYPE_BLE &&
p_search_data->inq_res.device_type == BT_DEVICE_TYPE_BREDR) ||
(stored_device_type == BT_DEVICE_TYPE_BREDR &&
p_search_data->inq_res.device_type == BT_DEVICE_TYPE_BLE))) {
dev_type = BT_DEVICE_TYPE_DUMO;
} else {
dev_type = p_search_data->inq_res.device_type;
}if (p_search_data->inq_res.device_type == BT_DEVICE_TYPE_BLE)
addr_type = p_search_data->inq_res.ble_addr_type;
#else
dev_type = BT_DEVICE_TYPE_BREDR;
#endif
BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
BT_PROPERTY_TYPE_OF_DEVICE, sizeof(dev_type), &dev_type);
num_properties++;
/* RSSI */
BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
BT_PROPERTY_REMOTE_RSSI, sizeof(int8_t),
&(p_search_data->inq_res.rssi));
num_properties++;status = btif_storage_add_remote_device(&bdaddr, num_properties, properties);
ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device (inquiry)", status);
#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
status = btif_storage_set_remote_addr_type(&bdaddr, addr_type);
ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote addr type (inquiry)", status);
#endif
/* Callback to notify upper layer of device */
HAL_CBACK(bt_hal_cbacks, device_found_cb,
num_properties, properties);
}
}

最后通过回调上报给安卓的framework

/* Callback to notify upper layer of device */
HAL_CBACK(bt_hal_cbacks, device_found_cb,
num_properties, properties);

ble扫描参数:
在scanmanager.java里配置

以上参数通过jni传到bt stack的接口进而设置到协议栈

然后通过gattClientScanNative进行扫描

这里为android O/mtk6580为对应的代码流程



下发到协议栈去执行

有时需要通过周围的枚举来找到当前的处理函数如:


bta_dm_ble_observe

btm_cb.ble_ctr_cb.p_obs_results_cb = p_results_cb;
btm_cb.ble_ctr_cb.p_obs_cmpl_cb = p_cmpl_cb;

bta_dm_search_cb.p_scan_cback ==
p_data->ble_observe.p_cback==
bta_scan_results_cb

采用上层给的扫描参数,如果上层有设置的话,否则采用协议栈默认的参数
设置扫描结果返回函数p_obs_results_cb   bta_dm_observe_results_cb,
扫描完成返回函数p_obs_cmpl_cb  bta_dm_observe_cmpl_cb

设置参数,使能扫描

下发到hci层

BTM_BleObserve超时后扫描结束



并掉用扫描完成函数
bta_dm_observe_cmpl_cb

返回扫描结果从hci返回

BTU                           btu_hcif_process_event/HCI_BLE_ADV_PKT_RPT_EVTbtu_ble_process_adv_pktBTM                           btm_ble_process_adv_pktbtm_ble_process_adv_pkt_contBTA                           bta_scan_results_cbBTIF                          BTIF_GATT_OBSERVE_EVT

返回扫描结果
btm_ble_process_adv_pkt_cont

  tBTM_INQ_RESULTS_CB* p_obs_results_cb = btm_cb.ble_ctr_cb.p_obs_results_cb;if (p_obs_results_cb && (result & BTM_BLE_OBS_RESULT)) {(p_obs_results_cb)((tBTM_INQ_RESULTS*)&p_i->inq_info.results,const_cast<uint8_t*>(adv_data.data()), adv_data.size());}

調用到bta_dm_observe_results_cb

 if (bta_dm_search_cb.p_scan_cback)bta_dm_search_cb.p_scan_cback(BTA_DM_INQ_RES_EVT, &result);

调用到bta_scan_results_cb


通过callback上传到jni层,再上传到应用层

  HAL_CBACK(bt_gatt_callbacks, scanner->scan_result_cb, ble_evt_type, addr_type,&bd_addr, ble_primary_phy, ble_secondary_phy, ble_advertising_sid,ble_tx_power, rssi, ble_periodic_adv_int, std::move(value));

android bluetooth stack-scan相关推荐

  1. 【转】Android bluetooth介绍(三): 蓝牙扫描(scan)设备分析

    原文网址:http://blog.csdn.net/xubin341719/article/details/38584469 关键词:蓝牙blueZ  A2DP.SINK.sink_connect.s ...

  2. Android Bluetooth杂记

    本文仅供个人记录一些日常笔记,仅供参考! 一.打开蓝牙LOG 将/etc/bluetooth/bt_stack.conf中的打印级别改成5,然后使用 logcat -v time 抓取相关 log,下 ...

  3. Android蓝牙无法通信,android.bluetooth.BluetoothSocket无法连接

    我已经尝试了其他评论中的所有建议,但都没有效果,我希望有人能帮助我.我已经为这个问题挣扎了三天了.我确信我的uuid是正确的,并且我知道清单中启用了蓝牙访问. 我正在尝试将我的android应用程序连 ...

  4. Android Bluetooth BLE相关开发资源汇总

    Android开启蓝牙开关 转载自Android:Bluetooth 的打开和关闭 检查系统蓝牙是否开启 BluetoothManager bluetoothManager = (BluetoothM ...

  5. Android Bluetooth蓝牙开发\蓝牙协议\蓝牙通信例子_Android支持蓝牙4.0版本_BLE开发

    一.Android Bluetooth现状 在android官网可以了解到android4.2新增了部分新功能,但是对于BT熟悉的人或许开始头疼了,那就是Android4.2引入了一个新的蓝牙协议栈针 ...

  6. Android Bluetooth HF client相关接口以及定义

    [APP] 应用程序通过BluetoothManager和BluetoothAdapter来操作蓝牙相关接口 [JNI]AdaptorService 中打开蓝牙协议栈的代码片段 static void ...

  7. Android bluetooth介绍(一):基本概念及硬件接口

    关键词:蓝牙硬件接口 UART  PCM  blueZ  版本:基于android4.2之前版本 bluez 内核:linux/linux3.08 系统:android/android4.1.3.4 ...

  8. Android bluetooth介绍(二): android 蓝牙代码架构及其uart 到rfcomm流程

    关键词:蓝牙blueZ  UART  HCI_UART H4  HCI  L2CAP RFCOMM  版本:基于android4.2之前版本 bluez内核:linux/linux3.08 系统:an ...

  9. Android bluetooth介绍(两): android 蓝牙源架构和uart 至rfcomm过程

    关键词:蓝牙blueZ  UART  HCI_UART H4  HCI  L2CAP RFCOMM  版本号:基于android4.2先前版本 bluez内核:linux/linux3.08 系统:a ...

最新文章

  1. Objective-C 什么是类
  2. python调用c++返回带成员指针的类指针
  3. LeetCode Plus One
  4. web开发中的缓存问题的研究(一)
  5. vs code python 插件_工具篇-vscode效率提升插件
  6. linux c 11 运行库,11.1.3 运行库与I/O
  7. 5分钟带你了解Kafka的技术架构 | 技术头条
  8. java for循环前面label_Java 实例
  9. c# int byte转
  10. 计算机底纹不起作用,CSS - 背景颜色在IE11中不起作用(CSS - background-color not working in IE11)...
  11. 聚类-----高斯混合模型
  12. 初探Windows用户态调试机制
  13. (带手机版数据同步)高等院校学院学校类网站源码 政府单位学院学校网站织梦模板
  14. appium+python实现手势密码
  15. 学 stm 32 单片机
  16. ROS(ROUTEROS) 端口映射
  17. ring buffer示例
  18. jenkins 下载插件失败处理办法
  19. spring获取Bean报错
  20. 固态硬盘在线测试软件,ssd测试软件,详细教您ssd测试软件

热门文章

  1. 【Linux负载均衡】
  2. java的比较级运算符的结果,「比较级和最高级的用法」英语语法---比较级和最高级的用法 - 金橙教程网...
  3. lib静态库逆向分析
  4. ups电源测试软件,UPS电源在线监测方案
  5. 发电机组与UPS电源如何搭配
  6. 【无聊的小东西之自动输入】
  7. 软件测试的入行与转型
  8. 【JS】原始值与引用值、执行上下文与作用域链、作用域链增强、变量声明、标识符查找
  9. 移动通信中的HLR和VLR
  10. [vb版机房] 机房收费系统总结