~aleteoryx/muditaos

ref: fe708cdf31392bc009227c63ceb091ac450d6a78 muditaos/module-bluetooth/Bluetooth/interface/profiles/SCO/ScoUtils.cpp -rw-r--r-- 1.2 KiB
fe708cdf — Adam Wulkiewicz [MOS-670] Change clang-format AlwaysBreakTemplateDeclarations to Yes 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "ScoUtils.hpp"
#include <log/log.hpp>

extern "C"
{
#include <module-bluetooth/lib/btstack/src/btstack_defines.h>
#include <module-bluetooth/lib/btstack/src/hci.h>
}

namespace bluetooth::sco::utils
{
    void sendZeros(hci_con_handle_t scoHandle)
    {
        if (scoHandle == HCI_CON_HANDLE_INVALID) {
            LOG_ERROR("Invalid scoHandle!");
            return;
        }
        constexpr auto packetDataOffset = 3;
        constexpr auto lengthPosition   = 2;
        const auto scoPacketLength      = hci_get_sco_packet_length();
        const auto scoPayloadLength     = scoPacketLength - packetDataOffset;

        hci_reserve_packet_buffer();
        auto scoPacket     = hci_get_outgoing_packet_buffer();
        auto scoPayloadPtr = scoPacket + packetDataOffset;

        memset(scoPayloadPtr, 0, scoPayloadLength); // zero-fill the payload

        little_endian_store_16(scoPacket, 0, scoHandle);
        scoPacket[lengthPosition] = scoPayloadLength;

        hci_send_sco_packet_buffer(scoPacketLength);
        hci_request_sco_can_send_now_event();
    }
} // namespace bluetooth::sco::utils