Bluetooth: Add skeleton for Attribute Protocol handling
This patch adds support for the ATT fixed channel. A dedicated att.c file is added to handle the ATT protocol handling. Change-Id: I2e481f56168b6f1b4c564f10d25dee0a85fb968f Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
c31237aa82
commit
33c50f332b
3 changed files with 152 additions and 0 deletions
92
net/bluetooth/att.c
Normal file
92
net/bluetooth/att.c
Normal file
|
@ -0,0 +1,92 @@
|
|||
/* att.c - Attribute protocol 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.
|
||||
*/
|
||||
|
||||
#include <nanokernel.h>
|
||||
#include <toolchain.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <misc/byteorder.h>
|
||||
|
||||
#include <bluetooth/hci.h>
|
||||
#include <bluetooth/bluetooth.h>
|
||||
|
||||
#include "hci_core.h"
|
||||
#include "conn.h"
|
||||
#include "l2cap.h"
|
||||
#include "att.h"
|
||||
|
||||
static void send_err_rsp(struct bt_conn *conn, uint8_t req, uint16_t handle,
|
||||
uint8_t err)
|
||||
{
|
||||
struct bt_att_error_rsp *rsp;
|
||||
struct bt_att_hdr *hdr;
|
||||
struct bt_buf *buf;
|
||||
|
||||
buf = bt_l2cap_create_pdu(conn, BT_L2CAP_CID_ATT,
|
||||
sizeof(*hdr) + sizeof(*rsp));
|
||||
if (!buf)
|
||||
return;
|
||||
|
||||
hdr = (void *)bt_buf_add(buf, sizeof(*hdr));
|
||||
hdr->code = BT_ATT_ERROR_RSP;
|
||||
|
||||
rsp = (void *)bt_buf_add(buf, sizeof(*rsp));
|
||||
rsp->request = req;
|
||||
rsp->handle = sys_cpu_to_le16(handle);
|
||||
rsp->error = err;
|
||||
|
||||
bt_conn_send(conn, buf);
|
||||
}
|
||||
|
||||
void bt_att_recv(struct bt_conn *conn, struct bt_buf *buf)
|
||||
{
|
||||
struct bt_att_hdr *hdr = (void *)buf->data;
|
||||
|
||||
if (buf->len < sizeof(*hdr)) {
|
||||
BT_ERR("Too small ATT PDU received\n");
|
||||
goto done;
|
||||
}
|
||||
|
||||
BT_DBG("Received ATT code %u len %u\n", buf->len);
|
||||
|
||||
bt_buf_pull(buf, sizeof*hdr);
|
||||
|
||||
switch (hdr->code) {
|
||||
default:
|
||||
BT_DBG("Unhandled ATT code %u\n", hdr->code);
|
||||
send_err_rsp(conn, hdr->code, 0, BT_ATT_ERR_NOT_SUPPORTED);
|
||||
break;
|
||||
}
|
||||
|
||||
done:
|
||||
bt_buf_put(buf);
|
||||
}
|
56
net/bluetooth/att.h
Normal file
56
net/bluetooth/att.h
Normal file
|
@ -0,0 +1,56 @@
|
|||
/* att.h - Attribute protocol 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.
|
||||
*/
|
||||
|
||||
struct bt_att_hdr {
|
||||
uint8_t code;
|
||||
} PACK_STRUCT;
|
||||
|
||||
#define BT_ATT_ERR_NOT_SUPPORTED 0x06
|
||||
|
||||
#define BT_ATT_ERROR_RSP 0x01
|
||||
struct bt_att_error_rsp {
|
||||
uint8_t request;
|
||||
uint16_t handle;
|
||||
uint8_t error;
|
||||
} PACK_STRUCT;
|
||||
|
||||
#define BT_L2CAP_ATT_EXCHANGE_MTU_REQ 0x02
|
||||
struct bt_att_exchange_mtu_req {
|
||||
uint16_t mtu;
|
||||
} PACK_STRUCT;
|
||||
|
||||
#define BT_L2CAP_ATT_EXCHANGE_MTU_RSP 0x03
|
||||
struct bt_att_exchange_mtu_rsp {
|
||||
uint16_t mtu;
|
||||
} PACK_STRUCT;
|
||||
|
||||
void bt_att_recv(struct bt_conn *conn, struct bt_buf *buf);
|
|
@ -10,6 +10,7 @@
|
|||
#include "hci_core.h"
|
||||
#include "conn.h"
|
||||
#include "l2cap.h"
|
||||
#include "att.h"
|
||||
|
||||
#define LE_CONN_MIN_INTERVAL 0x0028
|
||||
#define LE_CONN_MAX_INTERVAL 0x0038
|
||||
|
@ -138,6 +139,9 @@ void bt_l2cap_recv(struct bt_conn *conn, struct bt_buf *buf)
|
|||
case BT_L2CAP_CID_LE_SIG:
|
||||
le_sig(conn, buf);
|
||||
break;
|
||||
case BT_L2CAP_CID_ATT:
|
||||
bt_att_recv(conn, buf);
|
||||
break;
|
||||
default:
|
||||
BT_ERR("Ignoring data for unknown CID %u\n", cid);
|
||||
bt_buf_put(buf);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue