2009-10-29 20:25:42 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2009-07-14 20:41:14 +00:00
|
|
|
#pragma once
|
|
|
|
|
2009-05-16 21:29:51 +00:00
|
|
|
#include "hci.h"
|
2009-07-23 21:55:36 +00:00
|
|
|
#include "l2cap_signaling.h"
|
2009-09-28 21:19:05 +00:00
|
|
|
#include <btstack/utils.h>
|
2010-06-09 15:31:46 +00:00
|
|
|
#include <btstack/btstack.h>
|
2009-07-28 21:04:16 +00:00
|
|
|
|
|
|
|
#define L2CAP_SIG_ID_INVALID 0
|
|
|
|
|
|
|
|
typedef enum {
|
2010-03-04 23:03:40 +00:00
|
|
|
L2CAP_STATE_CLOSED = 1, // no baseband
|
2010-01-26 20:49:02 +00:00
|
|
|
L2CAP_STATE_WAIT_CLIENT_ACCEPT_OR_REJECT,
|
2009-07-29 21:06:04 +00:00
|
|
|
L2CAP_STATE_WAIT_CONNECT_RSP, // from peer
|
2009-11-28 15:16:29 +00:00
|
|
|
L2CAP_STATE_WAIT_CONFIG_REQ_RSP_OR_CONFIG_REQ,
|
2009-07-29 21:06:04 +00:00
|
|
|
L2CAP_STATE_WAIT_CONFIG_REQ_RSP,
|
|
|
|
L2CAP_STATE_WAIT_CONFIG_REQ,
|
2009-07-28 21:04:16 +00:00
|
|
|
L2CAP_STATE_OPEN,
|
2009-07-29 21:06:04 +00:00
|
|
|
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 {
|
2009-07-29 21:06:04 +00:00
|
|
|
// linked list - assert: first field
|
|
|
|
linked_item_t item;
|
|
|
|
|
2009-07-28 21:04:16 +00:00
|
|
|
L2CAP_STATE state;
|
2010-06-18 20:00:05 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2010-03-04 23:03:40 +00:00
|
|
|
uint16_t local_cid;
|
|
|
|
uint16_t remote_cid;
|
2010-08-10 19:29:16 +00:00
|
|
|
|
|
|
|
uint16_t local_mtu;
|
2010-06-18 20:00:05 +00:00
|
|
|
uint16_t remote_mtu;
|
|
|
|
|
2009-07-28 21:04:16 +00:00
|
|
|
uint16_t psm;
|
2010-07-29 19:35:34 +00:00
|
|
|
|
|
|
|
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
|
2010-06-09 15:31:46 +00:00
|
|
|
|
2009-07-28 21:04:16 +00:00
|
|
|
// uint16_t flush_timeout_incoming;
|
|
|
|
// uint16_t flush_timeout_outgoing;
|
2010-06-09 15:31:46 +00:00
|
|
|
|
|
|
|
// client connection
|
2010-07-19 17:50:59 +00:00
|
|
|
void * connection;
|
2010-06-09 15:31:46 +00:00
|
|
|
|
|
|
|
// internal connection
|
2010-06-09 15:39:55 +00:00
|
|
|
btstack_packet_handler_t packet_handler;
|
2010-06-09 15:31:46 +00:00
|
|
|
|
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;
|
|
|
|
|
2010-06-09 15:31:46 +00:00
|
|
|
// client connection
|
2010-07-19 17:50:59 +00:00
|
|
|
void *connection;
|
2010-06-09 15:31:46 +00:00
|
|
|
|
|
|
|
// internal connection
|
2010-06-09 15:39:55 +00:00
|
|
|
btstack_packet_handler_t packet_handler;
|
2010-06-09 15:31:46 +00:00
|
|
|
|
2009-05-17 20:32:14 +00:00
|
|
|
} l2cap_service_t;
|
|
|
|
|
2009-05-16 21:29:51 +00:00
|
|
|
void l2cap_init();
|
2010-07-19 17:50:59 +00:00
|
|
|
void l2cap_register_packet_handler(void (*handler)(void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size));
|
2010-08-10 20:43:55 +00:00
|
|
|
void l2cap_create_channel_internal(void * connection, btstack_packet_handler_t packet_handler, bd_addr_t address, uint16_t psm, uint16_t mtu);
|
2010-03-04 23:03:40 +00:00
|
|
|
void l2cap_disconnect_internal(uint16_t local_cid, uint8_t reason);
|
2010-07-29 19:35:34 +00:00
|
|
|
int l2cap_send_internal(uint16_t local_cid, uint8_t *data, uint16_t len);
|
2010-06-18 20:31:05 +00:00
|
|
|
uint16_t l2cap_get_remote_mtu_for_local_cid(uint16_t local_cid);
|
2009-07-31 21:41:15 +00:00
|
|
|
|
2009-08-08 21:55:55 +00:00
|
|
|
void l2cap_finialize_channel_close(l2cap_channel_t *channel);
|
2010-07-19 17:50:59 +00:00
|
|
|
void l2cap_close_connection(void *connection);
|
2010-01-25 18:29:06 +00:00
|
|
|
|
|
|
|
l2cap_service_t * l2cap_get_service(uint16_t psm);
|
2010-07-19 17:50:59 +00:00
|
|
|
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
|
|
|
|
2010-03-04 23:03:40 +00:00
|
|
|
void l2cap_accept_connection_internal(uint16_t local_cid);
|
|
|
|
void l2cap_decline_connection_internal(uint16_t local_cid, uint8_t reason);
|
2009-07-31 21:41:15 +00:00
|
|
|
|
2009-10-19 20:21:32 +00:00
|
|
|
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);
|