5#ifndef NIMBLEL2CAPCHANNEL_H
6# define NIMBLEL2CAPCHANNEL_H
11# if defined(CONFIG_NIMBLE_CPP_IDF)
12# include "host/ble_l2cap.h"
13# include "os/os_mbuf.h"
15# include "nimble/nimble/host/include/host/ble_l2cap.h"
16# include "nimble/porting/nimble/include/os/os_mbuf.h"
56 bool write(
const std::vector<uint8_t>& bytes);
65 int handleConnectionEvent(
struct ble_l2cap_event* event);
66 int handleAcceptEvent(
struct ble_l2cap_event* event);
67 int handleDataReceivedEvent(
struct ble_l2cap_event* event);
68 int handleTxUnstalledEvent(
struct ble_l2cap_event* event);
69 int handleDisconnectionEvent(
struct ble_l2cap_event* event);
73 static constexpr const char* LOG_TAG =
"NimBLEL2CAPChannel";
77 struct ble_l2cap_chan* channel =
nullptr;
79 uint8_t* receiveBuffer =
nullptr;
82 void* _coc_memory =
nullptr;
83 struct os_mempool _coc_mempool;
84 struct os_mbuf_pool _coc_mbuf_pool;
87 std::atomic<bool> stalled{
false};
92 void teardownMemPool();
95 int writeFragment(std::vector<uint8_t>::const_iterator begin, std::vector<uint8_t>::const_iterator end);
98 static int handleL2capEvent(
struct ble_l2cap_event* event,
void* arg);
A model of a BLE client.
Definition NimBLEClient.h:49
Callbacks base class for the L2CAP channel.
Definition NimBLEL2CAPChannel.h:104
virtual void onRead(NimBLEL2CAPChannel *channel, std::vector< uint8_t > &data)
Definition NimBLEL2CAPChannel.h:118
virtual void onDisconnect(NimBLEL2CAPChannel *channel)
Definition NimBLEL2CAPChannel.h:121
virtual bool shouldAcceptConnection(NimBLEL2CAPChannel *channel)
Definition NimBLEL2CAPChannel.h:112
virtual void onConnect(NimBLEL2CAPChannel *channel, uint16_t negotiatedMTU)
Definition NimBLEL2CAPChannel.h:115
Encapsulates a L2CAP channel.
Definition NimBLEL2CAPChannel.h:38
static NimBLEL2CAPChannel * connect(NimBLEClient *client, uint16_t psm, uint16_t mtu, NimBLEL2CAPChannelCallbacks *callbacks)
Open an L2CAP channel via the specified PSM and MTU.
Definition NimBLEL2CAPChannel.cpp:145
bool write(const std::vector< uint8_t > &bytes)
Write data to the channel.
Definition NimBLEL2CAPChannel.cpp:171
bool isConnected() const
Definition NimBLEL2CAPChannel.h:59
L2CAP server class.
Definition NimBLEL2CAPServer.h:20
A structure to hold data for a task that is waiting for a response.
Definition NimBLEUtils.h:32