zephyr/net/bluetooth/l2cap.h

113 lines
3.6 KiB
C
Raw Normal View History

/* l2cap.h - L2CAP handling */
/*
* Copyright (c) 2015 Intel Corporation
*
* 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 Intel Corporation nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 THE COPYRIGHT HOLDER 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.
*/
#define BT_L2CAP_CID_ATT 0x0004
#define BT_L2CAP_CID_LE_SIG 0x0005
#define BT_L2CAP_CID_SMP 0x0006
struct bt_l2cap_hdr {
uint16_t len;
uint16_t cid;
} __packed;
struct bt_l2cap_sig_hdr {
uint8_t code;
uint8_t ident;
uint16_t len;
} __packed;
#define BT_L2CAP_REJ_NOT_UNDERSTOOD 0x0000
#define BT_L2CAP_REJ_MTU_EXCEEDED 0x0001
#define BT_L2CAP_REJ_INVALID_CID 0x0002
#define BT_L2CAP_CMD_REJECT 0x01
struct bt_l2cap_cmd_reject {
uint16_t reason;
uint8_t data[0];
} __packed;
#define BT_L2CAP_CONN_PARAM_REQ 0x12
struct bt_l2cap_conn_param_req {
uint16_t min_interval;
uint16_t max_interval;
uint16_t latency;
uint16_t timeout;
} __packed;
Bluetooth: Refactor LE Connection Params validator Move le_validate_conn_params() interface to internal HCI header to be commonly shared between HCI and L2CAP layers. Refactor the interface and its users and rename related to Connection Parameters Update procedure values used for validation. < ACL Data TX: Handle 42 flags 0x00 dlen 16 [hci1] 2832.387859 LE L2CAP: Connection Parameter Update Request (0x12) ident 1 len 8 Min interval: 40 Max interval: 56 Slave latency: 0 Timeout multiplier: 0 @ Device Connected: 00:AA:01:00:00:23 (1) flags 0x0000 < HCI Command: LE Read Remote Used Features (0x08|0x0016) plen 2 [hci0] 2832.389374 Handle: 42 > ACL Data RX: Handle 42 flags 0x02 dlen 16 [hci0] 2832.389437 LE L2CAP: Connection Parameter Update Request (0x12) ident 1 len 8 Min interval: 40 Max interval: 56 Slave latency: 0 Timeout multiplier: 0 > HCI Event: Number of Completed Packets (0x13) plen 5 [hci1] 2832.389440 Num handles: 1 Handle: 42 Count: 1 > HCI Event: Command Status (0x0f) plen 4 [hci0] 2832.389443 LE Read Remote Used Features (0x08|0x0016) ncmd 1 Status: Success (0x00) > HCI Event: LE Meta Event (0x3e) plen 12 [hci0] 2832.389444 LE Read Remote Used Features (0x04) Status: Success (0x00) Handle: 42 Features: 0x03 0x00 0x00 0x00 0x00 0x00 0x00 0x00 LE Encryption Connection Parameter Request Procedure < ACL Data TX: Handle 42 flags 0x00 dlen 10 [hci0] 2832.393154 LE L2CAP: Connection Parameter Update Response (0x13) ident 1 len 2 Result: Connection Parameters rejected (0x0001) > ACL Data RX: Handle 42 flags 0x02 dlen 10 [hci1] 2832.393181 LE L2CAP: Connection Parameter Update Response (0x13) ident 1 len 2 Result: Connection Parameters rejected (0x0001) Rejected due to Timeout multiplier: 0. Change-Id: Idaf4f452f560ff71d9637ec5d793154190e94b35 Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com> Signed-off-by: Mariusz Skamra <mariusz.skamra@tieto.com>
2015-07-29 18:45:33 +08:00
#define BT_L2CAP_CONN_PARAM_ACCEPTED 0x0000
#define BT_L2CAP_CONN_PARAM_REJECTED 0x0001
#define BT_L2CAP_CONN_PARAM_RSP 0x13
struct bt_l2cap_conn_param_rsp {
uint16_t result;
} __packed;
struct bt_l2cap_chan {
uint16_t cid;
void (*connected)(struct bt_conn *conn);
void (*disconnected)(struct bt_conn *conn);
void (*encrypt_change)(struct bt_conn *conn);
void (*recv)(struct bt_conn *conn,
struct bt_buf *buf);
struct bt_l2cap_chan *_next;
};
/* Register a fixed L2CAP channel for L2CAP */
void bt_l2cap_chan_register(struct bt_l2cap_chan *chan);
/* Notify L2CAP channels of a new connection */
void bt_l2cap_connected(struct bt_conn *conn);
/* Notify L2CAP channels of a disconnect event */
void bt_l2cap_disconnected(struct bt_conn *conn);
/* Notify L2CAP channels of a change in encryption state */
void bt_l2cap_encrypt_change(struct bt_conn *conn);
/* Prepare an L2CAP PDU to be sent over a connection */
struct bt_buf *bt_l2cap_create_pdu(struct bt_conn *conn);
/* Send L2CAP PDU over a connection */
void bt_l2cap_send(struct bt_conn *conn, uint16_t cid, struct bt_buf *buf);
/* Receive a new L2CAP PDU from a connection */
void bt_l2cap_recv(struct bt_conn *conn, struct bt_buf *buf);
/* Perform connection parameter update request */
int bt_l2cap_update_conn_param(struct bt_conn *conn);
/* Initialize L2CAP and supported channels */
int bt_l2cap_init(void);