btstack/src/l2cap.h

133 lines
4.5 KiB
C
Raw Normal View History

/*
* Copyright (C) 2009 by Matthias Ringwald
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
* RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
2009-05-16 21:29:51 +00:00
/*
* l2cap.h
*
* Logical Link Control and Adaption Protocl (L2CAP)
*
* Created by Matthias Ringwald on 5/16/09.
*/
#pragma once
2009-05-16 21:29:51 +00:00
#include "hci.h"
#include "l2cap_signaling.h"
#include <btstack/utils.h>
#include <btstack/btstack.h>
2009-07-28 21:04:16 +00:00
#define L2CAP_SIG_ID_INVALID 0
typedef enum {
L2CAP_STATE_CLOSED = 1, // no baseband
2010-01-26 20:49:02 +00:00
L2CAP_STATE_WAIT_CLIENT_ACCEPT_OR_REJECT,
L2CAP_STATE_WAIT_CONNECT_RSP, // from peer
L2CAP_STATE_WAIT_CONFIG_REQ_RSP_OR_CONFIG_REQ,
L2CAP_STATE_WAIT_CONFIG_REQ_RSP,
L2CAP_STATE_WAIT_CONFIG_REQ,
2009-07-28 21:04:16 +00:00
L2CAP_STATE_OPEN,
L2CAP_STATE_WAIT_DISCONNECT, // from application
2009-07-28 21:04:16 +00:00
} L2CAP_STATE;
2009-05-16 21:29:51 +00:00
2010-01-25 18:29:06 +00:00
// info regarding an actual coneection
2009-05-17 20:32:14 +00:00
typedef struct {
// linked list - assert: first field
linked_item_t item;
2009-07-28 21:04:16 +00:00
L2CAP_STATE state;
bd_addr_t address;
hci_con_handle_t handle;
2010-01-26 20:49:02 +00:00
uint8_t sig_id; // other sig for conn requests
2010-08-10 19:29:16 +00:00
uint16_t local_cid;
uint16_t remote_cid;
2010-08-10 19:29:16 +00:00
uint16_t local_mtu;
uint16_t remote_mtu;
2009-07-28 21:04:16 +00:00
uint16_t psm;
uint8_t packets_granted; // number of L2CAP/ACL packets client is allowed to send
uint8_t packets_outgoing; // number of L2CAP/ACL packets send to BT module
2009-07-28 21:04:16 +00:00
// uint16_t flush_timeout_incoming;
// uint16_t flush_timeout_outgoing;
// client connection
void * connection;
// internal connection
btstack_packet_handler_t packet_handler;
2009-05-17 20:32:14 +00:00
} l2cap_channel_t;
2010-01-25 18:29:06 +00:00
// info regarding potential connections
2009-05-17 20:32:14 +00:00
typedef struct {
2010-01-25 18:29:06 +00:00
// linked list - assert: first field
linked_item_t item;
// service id
uint16_t psm;
2009-05-17 20:32:14 +00:00
2010-01-25 18:29:06 +00:00
// incoming MTU
uint16_t mtu;
// client connection
void *connection;
// internal connection
btstack_packet_handler_t packet_handler;
2009-05-17 20:32:14 +00:00
} l2cap_service_t;
2009-05-16 21:29:51 +00:00
void l2cap_init();
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);
void l2cap_finialize_channel_close(l2cap_channel_t *channel);
void l2cap_close_connection(void *connection);
2010-01-25 18:29:06 +00:00
l2cap_service_t * l2cap_get_service(uint16_t psm);
void l2cap_register_service_internal(void *connection, btstack_packet_handler_t packet_handler, uint16_t psm, uint16_t mtu);
void l2cap_unregister_service_internal(void *connection, uint16_t psm);
2010-01-25 18:29:06 +00:00
void l2cap_accept_connection_internal(uint16_t local_cid);
void l2cap_decline_connection_internal(uint16_t local_cid, uint8_t reason);
void l2cap_emit_channel_opened(l2cap_channel_t *channel, uint8_t status);
2009-08-08 21:29:38 +00:00
void l2cap_emit_channel_closed(l2cap_channel_t *channel);
2010-01-26 20:49:02 +00:00
void l2cap_emit_connection_request(l2cap_channel_t *channel);