mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-16 08:42:28 +00:00
added support for sending connectionless L2CAP packets
This commit is contained in:
parent
5652b5ff9b
commit
2149f12ebb
41
src/l2cap.c
41
src/l2cap.c
@ -286,6 +286,33 @@ int l2cap_send_prepared(uint16_t local_cid, uint16_t len){
|
||||
return err;
|
||||
}
|
||||
|
||||
int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t len){
|
||||
|
||||
if (!hci_can_send_packet_now(HCI_ACL_DATA_PACKET)){
|
||||
log_info("l2cap_send_prepared_to_handle cid %u, cannot send\n", cid);
|
||||
return BTSTACK_ACL_BUFFERS_FULL;
|
||||
}
|
||||
|
||||
log_debug("l2cap_send_prepared_to_handle cid %u, handle %u\n", cid, handle);
|
||||
|
||||
uint8_t *acl_buffer = hci_get_outgoing_acl_packet_buffer();
|
||||
|
||||
// 0 - Connection handle : PB=10 : BC=00
|
||||
bt_store_16(acl_buffer, 0, handle | (2 << 12) | (0 << 14));
|
||||
// 2 - ACL length
|
||||
bt_store_16(acl_buffer, 2, len + 4);
|
||||
// 4 - L2CAP packet length
|
||||
bt_store_16(acl_buffer, 4, len + 0);
|
||||
// 6 - L2CAP channel DEST
|
||||
bt_store_16(acl_buffer, 6, cid);
|
||||
// send
|
||||
int err = hci_send_acl_packet(acl_buffer, len+8);
|
||||
|
||||
l2cap_hand_out_credits();
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int l2cap_send_internal(uint16_t local_cid, uint8_t *data, uint16_t len){
|
||||
|
||||
if (!hci_can_send_packet_now(HCI_ACL_DATA_PACKET)){
|
||||
@ -300,6 +327,20 @@ int l2cap_send_internal(uint16_t local_cid, uint8_t *data, uint16_t len){
|
||||
return l2cap_send_prepared(local_cid, len);
|
||||
}
|
||||
|
||||
int l2cap_send_connectionless(uint16_t handle, uint16_t cid, uint8_t *data, uint16_t len){
|
||||
|
||||
if (!hci_can_send_packet_now(HCI_ACL_DATA_PACKET)){
|
||||
log_info("l2cap_send_internal cid %u, cannot send\n", cid);
|
||||
return BTSTACK_ACL_BUFFERS_FULL;
|
||||
}
|
||||
|
||||
uint8_t *acl_buffer = hci_get_outgoing_acl_packet_buffer();
|
||||
|
||||
memcpy(&acl_buffer[8], data, len);
|
||||
|
||||
return l2cap_send_prepared_connectionless(handle, cid, len);
|
||||
}
|
||||
|
||||
static inline void channelStateVarSetFlag(l2cap_channel_t *channel, L2CAP_CHANNEL_STATE_VAR flag){
|
||||
channel->state_var = (L2CAP_CHANNEL_STATE_VAR) (channel->state_var | flag);
|
||||
}
|
||||
|
@ -75,18 +75,20 @@ void l2cap_init(void);
|
||||
void l2cap_register_packet_handler(void (*handler)(void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size));
|
||||
void l2cap_create_channel_internal(void * connection, btstack_packet_handler_t packet_handler, bd_addr_t address, uint16_t psm, uint16_t mtu);
|
||||
void l2cap_disconnect_internal(uint16_t local_cid, uint8_t reason);
|
||||
int l2cap_send_internal(uint16_t local_cid, uint8_t *data, uint16_t len);
|
||||
uint16_t l2cap_get_remote_mtu_for_local_cid(uint16_t local_cid);
|
||||
uint16_t l2cap_max_mtu(void);
|
||||
|
||||
void l2cap_block_new_credits(uint8_t blocked);
|
||||
int l2cap_can_send_packet_now(uint16_t local_cid); // non-blocking UART write
|
||||
|
||||
|
||||
// get outgoing buffer and prepare data
|
||||
uint8_t *l2cap_get_outgoing_buffer(void);
|
||||
int l2cap_send_prepared(uint16_t local_cid, uint16_t len);
|
||||
|
||||
int l2cap_send_prepared(uint16_t local_cid, uint16_t len);
|
||||
int l2cap_send_internal(uint16_t local_cid, uint8_t *data, uint16_t len);
|
||||
|
||||
int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t len);
|
||||
int l2cap_send_connectionless(uint16_t handle, uint16_t cid, uint8_t *data, uint16_t len);
|
||||
|
||||
void l2cap_close_connection(void *connection);
|
||||
|
||||
@ -99,6 +101,7 @@ void l2cap_decline_connection_internal(uint16_t local_cid, uint8_t reason);
|
||||
// Bluetooth 4.0 - allows to register handler for Attribute Protocol and Security Manager Protocol
|
||||
void l2cap_register_fixed_channel(btstack_packet_handler_t packet_handler, uint16_t channel_id);
|
||||
|
||||
|
||||
// private structs
|
||||
typedef enum {
|
||||
L2CAP_STATE_CLOSED = 1, // no baseband
|
||||
|
Loading…
x
Reference in New Issue
Block a user