feat: A2DP bluetooth audio working

This commit is contained in:
daniel committed 2026-06-10 16:00:42 +02:00
1 parent 4eb4ba4073
commit e0c8787727
18 files changed
+1312 -4340

No files matched your search

+39 -4
View File
@@ -7,6 +7,7 @@
#include "L2cap.hpp"
#include "Hci.hpp"
#include "A2dp.hpp"
#include "Avrcp.hpp"
#include <Drivers/USB/Xhci.hpp>
#include <Terminal/Terminal.hpp>
#include <CppLib/Stream.hpp>
@@ -151,8 +152,8 @@ namespace Drivers::USB::Bluetooth::L2cap {
KernelLogStream(INFO, "BT-L2CAP") << "Connection Request: PSM="
<< base::hex << (uint64_t)psm << " srcCID=" << (uint64_t)srcCid;
// Accept connections for AVDTP
if (psm == PSM_AVDTP || psm == PSM_SDP) {
// Accept connections for AVDTP, SDP, and AVRCP control
if (psm == PSM_AVDTP || psm == PSM_SDP || psm == PSM_AVCTP) {
if (psm == PSM_AVDTP) g_incomingAvdtpReqs++;
auto* ch = AllocChannel(psm);
if (ch) {
@@ -223,6 +224,19 @@ namespace Drivers::USB::Bluetooth::L2cap {
break;
}
}
} else if (result == CONN_PENDING && dstCid != 0) {
// A PENDING response may already carry the remote's
// allocated CID. Record it (but do NOT configure --
// the final SUCCESS on this channel does that): the
// diagnostics then show the peer engaged, and if the
// dial is later abandoned, FreeChannel knows to send
// a Disconnect for the half-open remote endpoint.
for (int i = 0; i < MAX_CHANNELS; i++) {
if (g_channels[i].Active && g_channels[i].LocalCid == srcCid) {
g_channels[i].RemoteCid = dstCid;
break;
}
}
}
}
break;
@@ -369,8 +383,27 @@ namespace Drivers::USB::Bluetooth::L2cap {
break;
}
default:
case SIG_DISCONN_RSP:
// Response to a Disconnect Request we sent (e.g. closing the
// SDP client channel after a query); nothing left to do.
break;
case SIG_ECHO_REQ: {
// Echo Request must be answered (echo the payload back) or
// a peer probing the link times out on us.
SendSignal(SIG_ECHO_RSP, sig->Identifier, sigPayload, sigPayloadLen);
break;
}
default: {
// A signaling command we do not handle. Log it: a peer that
// sends something exotic while holding our dials at
// "authorization pending" is exactly what we need to see.
KernelLogStream(INFO, "BT-L2CAP") << "Unhandled signaling code="
<< base::hex << (uint64_t)sig->Code << base::dec
<< " len=" << (uint64_t)sigPayloadLen;
break;
}
}
sOff += sizeof(SignalHeader) + sigPayloadLen;
}
@@ -381,7 +414,9 @@ namespace Drivers::USB::Bluetooth::L2cap {
if (g_channels[i].Psm == PSM_AVDTP) {
A2dp::ProcessAvdtp(payload, l2len);
} else if (g_channels[i].Psm == PSM_SDP) {
A2dp::ProcessSdp(payload, l2len);
A2dp::ProcessSdp(cid, payload, l2len);
} else if (g_channels[i].Psm == PSM_AVCTP) {
Avrcp::ProcessAvctp(cid, payload, l2len);
}
break;
}