Bluetooth Device Address(BD_ADDR) - 1

术语:

Medium access control (MAC) protocol

FHS: Frequency Hop Synchronization

Organizationally Unique Identifier (OUI)

蓝牙MAC地址简介

v5.3蓝牙核心规范中对地址的介绍:Vol 2: BR/EDR Controller -> Part B: Baseband Specification -> 1 General description -> 1.2 BLUETOOTH DEVICE ADDRESSING。

每个蓝牙设备都应分配一个唯一的 48 位蓝牙设备地址 (BD_ADDR),也叫Bluetooth MAC address,用来作为该设备的唯一识别码。该地址应是根据 IEEE 802-2014 标准第 8.2 节("通用地址")创建的 48 位扩展唯一标识符 (EUI-48)。

蓝牙地址通常显示为以十六进制书写的 6 个字节,用冒号分隔(例如 - 00:11:22:33:FF:EE)。它们是基于蓝牙的协议的重要组成部分。

标准地址:

IEEE SA - IEEE 802-2014

IEEE SA - IEEE 802-2014

关于获得MAC地址块的相关信息,和如何使用地址,也可以查看IEEE的指南: 

IEEE SA - Registration Authority

制造商只能使用他们从 IEEE 注册机构购买的注册表段中的值,并应对设备的每个接口(蓝牙、Wifi、以太网......)使用不同的值。认真的制造商会努力遵守,但在生产过程中也会出现错误。

蓝牙、Wifi、以太网这类设备的MAC地址,都由IEEE注册机构分配。

因为蓝牙的物理接口和传输媒介同Wifi/Ethernet是不同的,所以理论上蓝牙的MAC地址与网卡的MAC地址是独立地址空间,不会冲突。只不过像上面提到的,同一台设备上不同接口类型的MAC地址应避免相同,即使本来这个概率也很低。

不过厂商在IEEE注册机构申请或购买的地址段并不按照接口来区分,代表的是某一设备的唯一识别符,你可以用于识别蓝牙设备、网络设备或其他有MAC地址的设备。拥有蓝牙地址的设备也可以拥有自己的以太网 MAC 地址。如果一个厂商既生产蓝牙设备,又生产网卡,那可以把同一个地址分配给一个蓝牙设备和一个网卡。我是这样理解的。

Bluetooth devices are required to have a unique device address, assigned from the same registry as Ethernet and Wifi MAC addresses. Quoting the Bluetooth specification version 5.0 volume 1:

Each Bluetooth device shall be allocated a unique 48-

static void btif_dm_cb_create_bond(const RawAddress bd_addr, 760 tBT_TRANSPORT transport) { 761 bool is_hid = check_cod(&bd_addr, COD_HID_POINTING); 762 bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING); 763 764 if (transport == BT_TRANSPORT_AUTO && is_device_le_audio_capable(bd_addr)) { 765 LOG_INFO("LE Audio capable, forcing LE transport for Bonding"); 766 transport = BT_TRANSPORT_LE; 767 } 768 769 int device_type = 0; 770 tBLE_ADDR_TYPE addr_type = BLE_ADDR_PUBLIC; 771 std::string addrstr = bd_addr.ToString(); 772 const char* bdstr = addrstr.c_str(); 773 if (transport == BT_TRANSPORT_LE) { 774 if (!btif_config_get_int(bdstr, "DevType", &device_type)) { 775 btif_config_set_int(bdstr, "DevType", BT_DEVICE_TYPE_BLE); 776 } 777 if (btif_storage_get_remote_addr_type(&bd_addr, &addr_type) != 778 BT_STATUS_SUCCESS) { 779 // Try to read address type. OOB pairing might have set it earlier, but 780 // didn't store it, it defaults to BLE_ADDR_PUBLIC 781 uint8_t tmp_dev_type; 782 tBLE_ADDR_TYPE tmp_addr_type = BLE_ADDR_PUBLIC; 783 BTM_ReadDevInfo(bd_addr, &tmp_dev_type, &tmp_addr_type); 784 addr_type = tmp_addr_type; 785 786 btif_storage_set_remote_addr_type(&bd_addr, addr_type); 787 } 788 } 789 if ((btif_config_get_int(bdstr, "DevType", &device_type) && 790 (btif_storage_get_remote_addr_type(&bd_addr, &addr_type) == 791 BT_STATUS_SUCCESS) && 792 (device_type & BT_DEVICE_TYPE_BLE) == BT_DEVICE_TYPE_BLE) || 793 (transport == BT_TRANSPORT_LE)) { 794 BTA_DmAddBleDevice(bd_addr, addr_type, 795 static_cast<tBT_DEVICE_TYPE>(device_type)); 796 } 797 798 if (is_hid && (device_type & BT_DEVICE_TYPE_BLE) == 0) { 799 const bt_status_t status = 800 GetInterfaceToProfiles()->profileSpecific_HACK->btif_hh_connect( 801 &bd_addr); 802 if (status != BT_STATUS_SUCCESS) 803 bond_state_changed(status, bd_addr, BT_BOND_STATE_NONE); 804 } else { 805 BTA_DmBond(bd_addr, addr_type, transport, device_type); 806 } 807 /* Track originator of bond creation */ 808 pairing_cb.is_local_initiated = true; 这段代码的意思是
08-27
static void btif_stats_add_bond_event(const RawAddress& bd_addr, 3734 bt_bond_function_t function, 3735 bt_bond_state_t state) { 3736 std::unique_lock<std::mutex> lock(bond_event_lock); 3737 3738 btif_bond_event_t* event = &btif_dm_bond_events[btif_events_end_index]; 3739 event->bd_addr = bd_addr; 3740 event->function = function; 3741 event->state = state; 3742 clock_gettime(CLOCK_REALTIME, &event->timestamp); 3743 3744 btif_num_bond_events++; 3745 btif_events_end_index = 3746 (btif_events_end_index + 1) % (MAX_BTIF_BOND_EVENT_ENTRIES + 1); 3747 if (btif_events_end_index == btif_events_start_index) { 3748 btif_events_start_index = 3749 (btif_events_start_index + 1) % (MAX_BTIF_BOND_EVENT_ENTRIES + 1); 3750 } 3751 3752 int type; 3753 btif_get_device_type(bd_addr, &type); 3754 3755 bluetooth::common::device_type_t device_type; 3756 switch (type) { 3757 case BT_DEVICE_TYPE_BREDR: 3758 device_type = bluetooth::common::DEVICE_TYPE_BREDR; 3759 break; 3760 case BT_DEVICE_TYPE_BLE: 3761 device_type = bluetooth::common::DEVICE_TYPE_LE; 3762 break; 3763 case BT_DEVICE_TYPE_DUMO: 3764 device_type = bluetooth::common::DEVICE_TYPE_DUMO; 3765 break; 3766 default: 3767 device_type = bluetooth::common::DEVICE_TYPE_UNKNOWN; 3768 break; 3769 } 3770 3771 uint32_t cod = get_cod(&bd_addr); 3772 uint64_t ts = 3773 event->timestamp.tv_sec * 1000 + event->timestamp.tv_nsec / 1000000; 3774 bluetooth::common::BluetoothMetricsLogger::GetInstance()->LogPairEvent( 3775 0, ts, cod, device_type); 3776 逐行分析一下这段代码
08-27
static void bond_state_changed(bt_status_t status, const RawAddress& bd_addr, 548 bt_bond_state_t state) { 549 btif_stats_add_bond_event(bd_addr, BTIF_DM_FUNC_BOND_STATE_CHANGED, state); 550 551 if ((pairing_cb.state == state) && (state == BT_BOND_STATE_BONDING)) { 552 // Cross key pairing so send callback for static address 553 if (!pairing_cb.static_bdaddr.IsEmpty()) { 554 GetInterfaceToProfiles()->events->invoke_bond_state_changed_cb( 555 status, bd_addr, state, pairing_cb.fail_reason); 556 } 557 return; 558 } 559 560 if (pairing_cb.bond_type == tBTM_SEC_DEV_REC::BOND_TYPE_TEMPORARY) { 561 state = BT_BOND_STATE_NONE; 562 } 563 564 LOG_INFO( 565 "Bond state changed to state=%d [0:none, 1:bonding, 2:bonded]," 566 " prev_state=%d, sdp_attempts = %d", 567 state, pairing_cb.state, pairing_cb.sdp_attempts); 568 569 if (state == BT_BOND_STATE_NONE) { 570 forget_device_from_metric_id_allocator(bd_addr); 571 572 if (bluetooth::common::init_flags:: 573 pbap_pse_dynamic_version_upgrade_is_enabled()) { 574 if (btif_storage_is_pce_version_102(bd_addr)) { 575 update_pce_entry_to_interop_database(bd_addr); 576 } 577 } 578 } else if (state == BT_BOND_STATE_BONDED) { 579 allocate_metric_id_from_metric_id_allocator(bd_addr); 580 if (!save_metric_id_from_metric_id_allocator(bd_addr)) { 581 LOG(FATAL) << __func__ << ": Fail to save metric id for device " 582 << bd_addr; 583 } 584 } 585 GetInterfaceToProfiles()->events->invoke_bond_state_changed_cb( 586 status, bd_addr, state, pairing_cb.fail_reason); 587 588 int dev_type; 589 if (!btif_get_device_type(bd_addr, &dev_type)) { 590 dev_type = BT_DEVICE_TYPE_BREDR; 591 } 592 593 if ((state == BT_BOND_STATE_NONE) && (pairing_cb.bd_addr != bd_addr) 594 && is_bonding_or_sdp()) { 595 LOG_WARN("Ignoring bond state changed for unexpected device: %s pairing: %s", 596 ADDRESS_TO_LOGGABLE_CSTR(bd_addr), ADDRESS_TO_LOGGABLE_CSTR(pairing_cb.bd_addr)); 597 return; 598 } 599 600 if (state == BT_BOND_STATE_BONDING || 601 (state == BT_BOND_STATE_BONDED && 602 (pairing_cb.sdp_attempts > 0 || 603 pairing_cb.gatt_over_le == 604 btif_dm_pairing_cb_t::ServiceDiscoveryState::SCHEDULED))) { 605 // Save state for the device is bonding or SDP or GATT over LE discovery 606 pairing_cb.state = state; 607 pairing_cb.bd_addr = bd_addr; 608 } else { 609 LOG_INFO("clearing btif pairing_cb"); 610 pairing_cb = {}; 611 } 612 }代码分析
最新发布
08-27
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夜流冰

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

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

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

打赏作者

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

抵扣说明:

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

余额充值