How to transmit evt response to BT vendor lib in OH
Recently, OH4 BT userspace encountered an issue where opening BT failed, and the driver needs to check what’s going on. However, nobody is checking this now. With no chice, I made a strong entrace. I specialize in BSP, but I haven’t dealt with BT that is another tech area, right?
BT Architecture
Firstly, there’s no introduction in official OpenHarmony website, I’m speechless…
There’s only one in code: https://gitee.com/openharmony/communication_bluetooth, but that is for foundation layer, I’m focused on driver.
However, I’m lucky, I found one from laval community, I change a little as below:
______________ |
ok, I need to check BT HDI and below. The code about BT service is in foundation, BT HDI is in drivers/peripheral/bluetooth, check vendor lib adapter/vendor lib under vendor side such as device or vendor directory.
Troubleshooting
Compared to the normal log, I found the behavior to vendor lib cmd BT_OP_EVENT_CALLBACK
is missing.
Definition is in drivers/peripheral/bluetooth/hci/hdi_service/implement/ohos_bt_vendor_lib.h:
/** |
This cmd is called by VendorInterface::OnEventReceived()
, ok, this article is just analyzing the calling relationship to this in BT HDI, of course see the mountain only since I am new to this area.
Analysis
Firstly, let me check struct bt_vendor_interface_t
, which is defined in foundation, located at communication/bluetooth_service/services/bluetooth/hardware/include/bt_vendor_lib.h:
/** |
init
and op
are all in the function VendorInterface::Initialize()
:
VendorInterface::Initialize() |
There’s a watcher_
in it:
bool VendorInterface::Initialize( |
Check WatchHciChannel()
first:
bool VendorInterface::WatchHciChannel(const ReceiveCallback &receiveCallback) |
channelCount == 1
is what I encountered, let me check the action first then h4
definition:
bool HciWatcher::AddFdToWatcher(int fd, HciDataCallback callback) |
fds_
:
51 std::map<int, HciDataCallback> fds_; |
HciWatcher::Start()
would start a thread of WatcherThread()
:
106 void HciWatcher::WatcherThread() |
aha, check line 153, fd.second
is the callback
of AddFdToWatcher()
, fd.first
is just fd
, and the usage:
AddFdToWatcher(channel[0], std::bind(&Hci::H4Protocol::ReadData, h4, std::placeholders::_1)); |
so, HciWatcher::WatcherThread
would call Hci::H4Protocol::ReadData
.
H4Protocol::ReadData -> H4Protocol::PacketCallback -> onEventReceive_(hciPacket_) |
What’s the definition to onEventReceive_()
? go back to check WatchHciChannel()
:
bool VendorInterface::WatchHciChannel(const ReceiveCallback &receiveCallback) |
H4Protocol::H4Protocol( |
So, onEventReceive_(hciPacket_)
is calling VendorInterface::OnEventReceived()
.
Ok, let me summarize the calling stack:
_________________________________ ____________________ |
Well done.
References
版权声明:本站所有文章均采用 CC BY-NC-SA 4.0 CN 许可协议。转载请注明原文链接!