wip: ATT protocol

This commit is contained in:
Dan Halbert 2020-07-23 18:54:26 -04:00
parent 90ae1efa00
commit f6f45c82a1
15 changed files with 2290 additions and 46 deletions

View File

@ -31,7 +31,7 @@
#include <stdio.h>
#include <string.h>
#include "hci_api.h"
#include "hci.h"
#include "py/gc.h"
#include "py/mphal.h"

View File

@ -64,13 +64,16 @@ typedef struct {
//REMOVE ble_gap_conn_params_t conn_params;
volatile bool conn_params_updating;
uint16_t mtu;
// Request that CCCD values for this conenction be saved, using sys_attr values.
// Request that CCCD values for this connection be saved, using sys_attr values.
volatile bool do_bond_cccds;
// Request that security key info for this connection be saved.
volatile bool do_bond_keys;
// Time of setting do_bond_ccds: we delay a bit to consolidate multiple CCCD changes
// into one write. Time is currently in ticks_ms.
uint64_t do_bond_cccds_request_time;
//FIX from att.c
uint8_t role;
bt_addr_le_t addr;
} bleio_connection_internal_t;
typedef struct {

View File

@ -29,7 +29,7 @@
#include <stdbool.h>
#include "hci_api.h"
#include "hci.h"
void bleio_background(void);
void bleio_reset(void);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,57 @@
// Derived from ArduinoBLE.
// Copyright 2020 Dan Halbert for Adafruit Industries
/*
This file is part of the ArduinoBLE library.
Copyright (c) 2018 Arduino SA. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef MICROPY_INCLUDED_DEVICES_BLE_HCI_COMMON_HAL_BLEIO_ATT_H
#define MICROPY_INCLUDED_DEVICES_BLE_HCI_COMMON_HAL_BLEIO_ATT_H
#include <stdbool.h>
#include <stdint.h>
#include "hci_include/addr.h"
#include "hci_include/att.h"
#include "hci_include/att_internal.h"
//FIX BLEDevice att_central(void);
//FIX BLERemoteDevice* att_device(uint8_t address_type, const uint8_t address[6]);
//FIX void att_set_event_handler(BLEDeviceEvent event, BLEDeviceEventHandler eventHandler);
bool att_address_is_connected(bt_addr_le_t *addr);
bool att_connect_to_address(bt_addr_le_t *addr);
bool att_disconnect_all(void);
bool att_disconnect_from_address(bt_addr_le_t *addr);
bool att_discover_attributes(bt_addr_le_t *addr, const char* service_uuid_filter);
bool att_exchange_mtu(uint16_t conn_handle);
bool att_handle_ind(uint16_t handle, const uint8_t* value, int length);
bool att_handle_is_connected(uint16_t handle);
bool att_handle_notify(uint16_t handle, const uint8_t* value, int length);
bool att_is_connected(void);
int att_read_req(uint16_t conn_handle, uint16_t handle, uint8_t response_buffer[]);
int att_write_req(uint16_t conn_handle, uint16_t handle, const uint8_t* data, uint8_t data_len, uint8_t response_buffer[]);
uint16_t att_conn_handle(bt_addr_le_t *addr);
uint16_t att_mtu(uint16_t handle);
void att_add_connection(uint16_t handle, uint8_t role, bt_addr_le_t *peer_addr, uint16_t interval, uint16_t latency, uint16_t supervision_timeout, uint8_t master_clock_accuracy);
void att_process_data(uint16_t conn_handle, uint8_t dlen, uint8_t data[]);
void att_remove_connection(uint16_t handle, uint8_t reason);
void att_set_max_mtu(uint16_t max_mtu);
void att_set_timeout(unsigned long timeout);
void att_write_cmd(uint16_t conn_handle, uint16_t handle, const uint8_t* data, uint8_t data_len);
#endif // MICROPY_INCLUDED_DEVICES_BLE_HCI_COMMON_HAL_BLEIO_ATT_H

View File

@ -13,13 +13,15 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "hci_api.h"
#include "att.h"
#include "hci.h"
#include "py/obj.h"
// Zephyr include files to define HCI communication values and structs.
#include "hci_include/hci.h"
#include "hci_include/hci_err.h"
#include "hci_include/l2cap_internal.h"
#include <string.h>
@ -28,46 +30,18 @@
#include "common-hal/_bleio/Adapter.h"
#include "shared-bindings/microcontroller/__init__.h"
// HCI H4 protocol packet types: first byte in the packet.
#define H4_CMD 0x01
#define H4_ACL 0x02
#define H4_SCO 0x03
#define H4_EVT 0x04
//FIX replace
#define ATT_CID 0x0004
#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))
#define RX_BUFFER_SIZE (3 + 255)
#define ACL_DATA_BUFFER_SIZE (255 + 1)
#define CTS_TIMEOUT_MSECS (1000)
#define RESPONSE_TIMEOUT_MSECS (1000)
#define adapter (&common_hal_bleio_adapter_obj)
STATIC uint8_t rx_buffer[RX_BUFFER_SIZE];
STATIC size_t rx_idx;
STATIC size_t num_command_packets_allowed;
STATIC size_t max_pkt;
STATIC size_t pending_pkt;
// Results from parsing a command response packet.
STATIC bool cmd_response_received;
STATIC uint16_t cmd_response_opcode;
STATIC uint8_t cmd_response_status;
STATIC size_t cmd_response_len;
STATIC uint8_t* cmd_response_data;
STATIC uint8_t acl_data_buffer[ACL_DATA_BUFFER_SIZE];
STATIC size_t acl_data_len;
STATIC volatile bool hci_poll_in_progress = false;
STATIC bool debug = true;
// These are the headers of the full packets that are sent over the serial interface.
// They all have a one-byte type-field at the front, one of the H4_xxx packet types.
@ -109,6 +83,36 @@ typedef struct __attribute__ ((packed)) {
} h4_hci_evt_pkt_t;
//////////////////////////////////////////////////////////////////////
// Static storage:
//FIX size
#define RX_BUFFER_SIZE (3 + 255)
#define ACL_DATA_BUFFER_SIZE (255)
STATIC uint8_t rx_buffer[RX_BUFFER_SIZE];
STATIC size_t rx_idx;
STATIC uint8_t acl_data_buffer[ACL_DATA_BUFFER_SIZE];
STATIC size_t acl_data_len;
STATIC size_t num_command_packets_allowed;
STATIC size_t max_pkt;
STATIC size_t pending_pkt;
// Results from parsing a command response packet.
STATIC bool cmd_response_received;
STATIC uint16_t cmd_response_opcode;
STATIC uint8_t cmd_response_status;
STATIC size_t cmd_response_len;
STATIC uint8_t* cmd_response_data;
STATIC volatile bool hci_poll_in_progress = false;
STATIC bool debug = true;
//////////////////////////////////////////////////////////////////////
STATIC void dump_cmd_pkt(bool tx, uint8_t pkt_len, uint8_t pkt_data[]) {
if (debug) {
h4_hci_cmd_pkt_t *pkt = (h4_hci_cmd_pkt_t *) pkt_data;
@ -191,15 +195,16 @@ STATIC void process_acl_data_pkt(uint8_t pkt_len, uint8_t pkt_data[]) {
acl_data_len += pkt->data_len;
}
acl_data_t *acl_so_far = (acl_data_t *) acl_data_buffer;
if (acl_data_len != acl_so_far->acl_data_len) {
acl_data_t *acl = (acl_data_t *) &acl_data_buffer;
if (acl_data_len != acl->acl_data_len) {
// We don't have the full packet yet.
return;
}
// if (aclHdr->cid == ATT_CID) {
// ATT.handleData(aclHdr->handle & 0x0fff, aclHdr->len, &rx_buffer[1 + sizeof(HCIACLHdr)]);
// } else if (aclHdr->cid == SIGNALING_CID) {
if (acl->cid == BT_L2CAP_CID_ATT) {
att_process_data(pkt->handle, acl->acl_data_len, acl->acl_data);
}
// } else if (aclHdr->cid == BT_L2CAP_CID_LE_SIG) {
// L2CAPSignaling.handleData(aclHdr->handle & 0x0fff, aclHdr->len, &rx_buffer[1 + sizeof(HCIACLHdr)]);
// } else {
// struct __attribute__ ((packed)) {
@ -340,6 +345,20 @@ void hci_init(void) {
hci_poll_in_progress = false;
}
hci_result_t hci_poll_for_incoming_pkt_timeout(uint32_t timeout_msecs) {
uint64_t start = supervisor_ticks_ms64();
hci_result_t result;
while (supervisor_ticks_ms64() -start < timeout_msecs) {
result = hci_poll_for_incoming_pkt();
RUN_BACKGROUND_TASKS;
}
return result;
}
hci_result_t hci_poll_for_incoming_pkt(void) {
if (hci_poll_in_progress) {
return HCI_OK;
@ -500,8 +519,7 @@ STATIC hci_result_t send_command(uint16_t opcode, uint8_t params_len, void* para
return HCI_NO_RESPONSE;
}
//FIX remove unused
STATIC int __attribute__((unused)) send_acl_pkt(uint16_t handle, uint8_t cid, void* data, uint8_t data_len) {
hci_result_t hci_send_acl_pkt(uint16_t handle, uint8_t cid, uint8_t data_len, uint8_t *data) {
int result;
while (pending_pkt >= max_pkt) {
result = hci_poll_for_incoming_pkt();
@ -510,7 +528,7 @@ STATIC int __attribute__((unused)) send_acl_pkt(uint16_t handle, uint8_t cid, vo
}
}
// data_len does not include cid.
// data_len does not include cid
const size_t cid_len = sizeof_field(acl_data_t, cid);
// buf_len is size of entire packet including header.
const size_t buf_len = sizeof(h4_hci_acl_pkt_t) + cid_len + data_len;

View File

@ -17,8 +17,8 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef MICROPY_INCLUDED_DEVICES_BLE_HCI_COMMON_HAL_BLEIO_HCI_API_H
#define MICROPY_INCLUDED_DEVICES_BLE_HCI_COMMON_HAL_BLEIO_HCI_API_H
#ifndef MICROPY_INCLUDED_DEVICES_BLE_HCI_COMMON_HAL_BLEIO_HCI_H
#define MICROPY_INCLUDED_DEVICES_BLE_HCI_COMMON_HAL_BLEIO_HCI_H
#include <stdint.h>
@ -64,6 +64,7 @@ hci_result_t hci_le_set_scan_parameters(uint8_t scan_type, uint16_t interval, ui
hci_result_t hci_le_set_scan_response_data(uint8_t length, uint8_t data[]);
hci_result_t hci_poll_for_incoming_pkt(void);
hci_result_t hci_poll_for_incoming_pkt_timeout(uint32_t timeout_msecs);
hci_result_t hci_read_bd_addr(bt_addr_t *addr);
hci_result_t hci_read_buffer_size(uint16_t *acl_max_len, uint8_t *sco_max_len, uint16_t *acl_max_num, uint16_t *sco_max_num);
@ -72,6 +73,7 @@ hci_result_t hci_read_rssi(uint16_t handle, int *rssi);
hci_result_t hci_reset(void);
hci_result_t hci_send_acl_pkt(uint16_t handle, uint8_t cid, uint8_t data_len, uint8_t *data);
hci_result_t hci_set_evt_mask(uint64_t event_mask);
#endif // MICROPY_INCLUDED_DEVICES_BLE_HCI_COMMON_HAL_BLEIO_HCI_API_H
#endif // MICROPY_INCLUDED_DEVICES_BLE_HCI_COMMON_HAL_BLEIO_HCI_H

View File

@ -12,6 +12,7 @@
#ifndef ZEPHYR_INCLUDE_BLUETOOTH_ADDR_H_
#define ZEPHYR_INCLUDE_BLUETOOTH_ADDR_H_
#include <stdbool.h>
#include <string.h>
/**

View File

@ -0,0 +1,41 @@
// CircuitPython: Adapted from Zephyr include file.
/** @file
* @brief Attribute Protocol handling.
*/
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_BLUETOOTH_ATT_H_
#define ZEPHYR_INCLUDE_BLUETOOTH_ATT_H_
/* Error codes for Error response PDU */
#define BT_ATT_ERR_INVALID_HANDLE 0x01
#define BT_ATT_ERR_READ_NOT_PERMITTED 0x02
#define BT_ATT_ERR_WRITE_NOT_PERMITTED 0x03
#define BT_ATT_ERR_INVALID_PDU 0x04
#define BT_ATT_ERR_AUTHENTICATION 0x05
#define BT_ATT_ERR_NOT_SUPPORTED 0x06
#define BT_ATT_ERR_INVALID_OFFSET 0x07
#define BT_ATT_ERR_AUTHORIZATION 0x08
#define BT_ATT_ERR_PREPARE_QUEUE_FULL 0x09
#define BT_ATT_ERR_ATTRIBUTE_NOT_FOUND 0x0a
#define BT_ATT_ERR_ATTRIBUTE_NOT_LONG 0x0b
#define BT_ATT_ERR_ENCRYPTION_KEY_SIZE 0x0c
#define BT_ATT_ERR_INVALID_ATTRIBUTE_LEN 0x0d
#define BT_ATT_ERR_UNLIKELY 0x0e
#define BT_ATT_ERR_INSUFFICIENT_ENCRYPTION 0x0f
#define BT_ATT_ERR_UNSUPPORTED_GROUP_TYPE 0x10
#define BT_ATT_ERR_INSUFFICIENT_RESOURCES 0x11
#define BT_ATT_ERR_DB_OUT_OF_SYNC 0x12
#define BT_ATT_ERR_VALUE_NOT_ALLOWED 0x13
/* Common Profile Error Codes (from CSS) */
#define BT_ATT_ERR_WRITE_REQ_REJECTED 0xfc
#define BT_ATT_ERR_CCC_IMPROPER_CONF 0xfd
#define BT_ATT_ERR_PROCEDURE_IN_PROGRESS 0xfe
#define BT_ATT_ERR_OUT_OF_RANGE 0xff
#endif /* ZEPHYR_INCLUDE_BLUETOOTH_ATT_H_ */

View File

@ -0,0 +1,266 @@
// CircuitPython: Adapted from Zephyr include file.
/* att_internal.h - Attribute protocol handling */
/*
* Copyright (c) 2015-2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdbool.h>
// for __packed
#include <string.h>
#define BT_EATT_PSM 0x27
#define BT_ATT_DEFAULT_LE_MTU 23
#define BT_ATT_TIMEOUT K_SECONDS(30)
//FIX #if BT_L2CAP_RX_MTU < CONFIG_BT_L2CAP_TX_MTU
// #define BT_ATT_MTU BT_L2CAP_RX_MTU
// #else
// #define BT_ATT_MTU CONFIG_BT_L2CAP_TX_MTU
// #endif
struct bt_att_hdr {
uint8_t code;
} __packed;
#define BT_ATT_OP_ERROR_RSP 0x01
struct bt_att_error_rsp {
uint8_t request;
uint16_t handle;
uint8_t error;
} __packed;
#define BT_ATT_OP_MTU_REQ 0x02
struct bt_att_exchange_mtu_req {
uint16_t mtu;
} __packed;
#define BT_ATT_OP_MTU_RSP 0x03
struct bt_att_exchange_mtu_rsp {
uint16_t mtu;
} __packed;
/* Find Information Request */
#define BT_ATT_OP_FIND_INFO_REQ 0x04
struct bt_att_find_info_req {
uint16_t start_handle;
uint16_t end_handle;
} __packed;
/* Format field values for BT_ATT_OP_FIND_INFO_RSP */
#define BT_ATT_INFO_16 0x01
#define BT_ATT_INFO_128 0x02
struct bt_att_info_16 {
uint16_t handle;
uint16_t uuid;
} __packed;
struct bt_att_info_128 {
uint16_t handle;
uint8_t uuid[16];
} __packed;
/* Find Information Response */
#define BT_ATT_OP_FIND_INFO_RSP 0x05
struct bt_att_find_info_rsp {
uint8_t format;
uint8_t info[0];
} __packed;
/* Find By Type Value Request */
#define BT_ATT_OP_FIND_TYPE_REQ 0x06
struct bt_att_find_type_req {
uint16_t start_handle;
uint16_t end_handle;
uint16_t type;
uint8_t value[0];
} __packed;
struct bt_att_handle_group {
uint16_t start_handle;
uint16_t end_handle;
} __packed;
/* Find By Type Value Response */
#define BT_ATT_OP_FIND_TYPE_RSP 0x07
struct bt_att_find_type_rsp {
struct bt_att_handle_group list[0];
} __packed;
/* Read By Type Request */
#define BT_ATT_OP_READ_TYPE_REQ 0x08
struct bt_att_read_type_req {
uint16_t start_handle;
uint16_t end_handle;
uint8_t uuid[0];
} __packed;
struct bt_att_data {
uint16_t handle;
uint8_t value[0];
} __packed;
/* Read By Type Response */
#define BT_ATT_OP_READ_TYPE_RSP 0x09
struct bt_att_read_type_rsp {
uint8_t len;
struct bt_att_data data[0];
} __packed;
/* Read Request */
#define BT_ATT_OP_READ_REQ 0x0a
struct bt_att_read_req {
uint16_t handle;
} __packed;
/* Read Response */
#define BT_ATT_OP_READ_RSP 0x0b
struct bt_att_read_rsp {
uint8_t value[0];
} __packed;
/* Read Blob Request */
#define BT_ATT_OP_READ_BLOB_REQ 0x0c
struct bt_att_read_blob_req {
uint16_t handle;
uint16_t offset;
} __packed;
/* Read Blob Response */
#define BT_ATT_OP_READ_BLOB_RSP 0x0d
struct bt_att_read_blob_rsp {
uint8_t value[0];
} __packed;
/* Read Multiple Request */
#define BT_ATT_READ_MULT_MIN_LEN_REQ 0x04
#define BT_ATT_OP_READ_MULT_REQ 0x0e
struct bt_att_read_mult_req {
uint16_t handles[0];
} __packed;
/* Read Multiple Respose */
#define BT_ATT_OP_READ_MULT_RSP 0x0f
struct bt_att_read_mult_rsp {
uint8_t value[0];
} __packed;
/* Read by Group Type Request */
#define BT_ATT_OP_READ_GROUP_REQ 0x10
struct bt_att_read_group_req {
uint16_t start_handle;
uint16_t end_handle;
uint8_t uuid[0];
} __packed;
struct bt_att_group_data {
uint16_t start_handle;
uint16_t end_handle;
uint8_t value[0];
} __packed;
/* Read by Group Type Response */
#define BT_ATT_OP_READ_GROUP_RSP 0x11
struct bt_att_read_group_rsp {
uint8_t len;
struct bt_att_group_data data[0];
} __packed;
/* Write Request */
#define BT_ATT_OP_WRITE_REQ 0x12
struct bt_att_write_req {
uint16_t handle;
uint8_t value[0];
} __packed;
/* Write Response */
#define BT_ATT_OP_WRITE_RSP 0x13
/* Prepare Write Request */
#define BT_ATT_OP_PREPARE_WRITE_REQ 0x16
struct bt_att_prepare_write_req {
uint16_t handle;
uint16_t offset;
uint8_t value[0];
} __packed;
/* Prepare Write Respond */
#define BT_ATT_OP_PREPARE_WRITE_RSP 0x17
struct bt_att_prepare_write_rsp {
uint16_t handle;
uint16_t offset;
uint8_t value[0];
} __packed;
/* Execute Write Request */
#define BT_ATT_FLAG_CANCEL 0x00
#define BT_ATT_FLAG_EXEC 0x01
#define BT_ATT_OP_EXEC_WRITE_REQ 0x18
struct bt_att_exec_write_req {
uint8_t flags;
} __packed;
/* Execute Write Response */
#define BT_ATT_OP_EXEC_WRITE_RSP 0x19
/* Handle Value Notification */
#define BT_ATT_OP_NOTIFY 0x1b
struct bt_att_notify {
uint16_t handle;
uint8_t value[0];
} __packed;
/* Handle Value Indication */
#define BT_ATT_OP_INDICATE 0x1d
struct bt_att_indicate {
uint16_t handle;
uint8_t value[0];
} __packed;
/* Handle Value Confirm */
#define BT_ATT_OP_CONFIRM 0x1e
struct bt_att_signature {
uint8_t value[12];
} __packed;
#define BT_ATT_OP_READ_MULT_VL_REQ 0x20
struct bt_att_read_mult_vl_req {
uint16_t handles[0];
} __packed;
/* Read Multiple Respose */
#define BT_ATT_OP_READ_MULT_VL_RSP 0x21
struct bt_att_read_mult_vl_rsp {
uint16_t len;
uint8_t value[0];
} __packed;
/* Handle Multiple Value Notification */
#define BT_ATT_OP_NOTIFY_MULT 0x23
struct bt_att_notify_mult {
uint16_t handle;
uint16_t len;
uint8_t value[0];
} __packed;
/* Write Command */
#define BT_ATT_OP_WRITE_CMD 0x52
struct bt_att_write_cmd {
uint16_t handle;
uint8_t value[0];
} __packed;
/* Signed Write Command */
#define BT_ATT_OP_SIGNED_WRITE_CMD 0xd2
struct bt_att_signed_write_cmd {
uint16_t handle;
uint8_t value[0];
} __packed;

View File

@ -1,4 +1,5 @@
// CircuitPython: Adapted from Zephyr include file.
/* hci.h - Bluetooth Host Control Interface definitions */
/*

View File

@ -0,0 +1,230 @@
// CircuitPython: Adapted from Zephyr include file.
/** @file
* @brief Internal APIs for Bluetooth L2CAP handling.
*/
/*
* Copyright (c) 2015-2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdbool.h>
// for __packed
#include <string.h>
enum l2cap_conn_list_action {
BT_L2CAP_CHAN_LOOKUP,
BT_L2CAP_CHAN_DETACH,
};
#define BT_L2CAP_CID_BR_SIG 0x0001
#define BT_L2CAP_CID_ATT 0x0004
#define BT_L2CAP_CID_LE_SIG 0x0005
#define BT_L2CAP_CID_SMP 0x0006
#define BT_L2CAP_CID_BR_SMP 0x0007
#define BT_L2CAP_PSM_RFCOMM 0x0003
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;
struct bt_l2cap_cmd_reject_cid_data {
uint16_t scid;
uint16_t dcid;
} __packed;
#define BT_L2CAP_CONN_REQ 0x02
struct bt_l2cap_conn_req {
uint16_t psm;
uint16_t scid;
} __packed;
/* command statuses in reposnse */
#define BT_L2CAP_CS_NO_INFO 0x0000
#define BT_L2CAP_CS_AUTHEN_PEND 0x0001
/* valid results in conn response on BR/EDR */
#define BT_L2CAP_BR_SUCCESS 0x0000
#define BT_L2CAP_BR_PENDING 0x0001
#define BT_L2CAP_BR_ERR_PSM_NOT_SUPP 0x0002
#define BT_L2CAP_BR_ERR_SEC_BLOCK 0x0003
#define BT_L2CAP_BR_ERR_NO_RESOURCES 0x0004
#define BT_L2CAP_BR_ERR_INVALID_SCID 0x0006
#define BT_L2CAP_BR_ERR_SCID_IN_USE 0x0007
#define BT_L2CAP_CONN_RSP 0x03
struct bt_l2cap_conn_rsp {
uint16_t dcid;
uint16_t scid;
uint16_t result;
uint16_t status;
} __packed;
#define BT_L2CAP_CONF_SUCCESS 0x0000
#define BT_L2CAP_CONF_UNACCEPT 0x0001
#define BT_L2CAP_CONF_REJECT 0x0002
#define BT_L2CAP_CONF_REQ 0x04
struct bt_l2cap_conf_req {
uint16_t dcid;
uint16_t flags;
uint8_t data[0];
} __packed;
#define BT_L2CAP_CONF_RSP 0x05
struct bt_l2cap_conf_rsp {
uint16_t scid;
uint16_t flags;
uint16_t result;
uint8_t data[0];
} __packed;
/* Option type used by MTU config request data */
#define BT_L2CAP_CONF_OPT_MTU 0x01
/* Options bits selecting most significant bit (hint) in type field */
#define BT_L2CAP_CONF_HINT 0x80
#define BT_L2CAP_CONF_MASK 0x7f
struct bt_l2cap_conf_opt {
uint8_t type;
uint8_t len;
uint8_t data[0];
} __packed;
#define BT_L2CAP_DISCONN_REQ 0x06
struct bt_l2cap_disconn_req {
uint16_t dcid;
uint16_t scid;
} __packed;
#define BT_L2CAP_DISCONN_RSP 0x07
struct bt_l2cap_disconn_rsp {
uint16_t dcid;
uint16_t scid;
} __packed;
#define BT_L2CAP_INFO_FEAT_MASK 0x0002
#define BT_L2CAP_INFO_FIXED_CHAN 0x0003
#define BT_L2CAP_INFO_REQ 0x0a
struct bt_l2cap_info_req {
uint16_t type;
} __packed;
/* info result */
#define BT_L2CAP_INFO_SUCCESS 0x0000
#define BT_L2CAP_INFO_NOTSUPP 0x0001
#define BT_L2CAP_INFO_RSP 0x0b
struct bt_l2cap_info_rsp {
uint16_t type;
uint16_t result;
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;
#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;
#define BT_L2CAP_LE_CONN_REQ 0x14
struct bt_l2cap_le_conn_req {
uint16_t psm;
uint16_t scid;
uint16_t mtu;
uint16_t mps;
uint16_t credits;
} __packed;
/* valid results in conn response on LE */
#define BT_L2CAP_LE_SUCCESS 0x0000
#define BT_L2CAP_LE_ERR_PSM_NOT_SUPP 0x0002
#define BT_L2CAP_LE_ERR_NO_RESOURCES 0x0004
#define BT_L2CAP_LE_ERR_AUTHENTICATION 0x0005
#define BT_L2CAP_LE_ERR_AUTHORIZATION 0x0006
#define BT_L2CAP_LE_ERR_KEY_SIZE 0x0007
#define BT_L2CAP_LE_ERR_ENCRYPTION 0x0008
#define BT_L2CAP_LE_ERR_INVALID_SCID 0x0009
#define BT_L2CAP_LE_ERR_SCID_IN_USE 0x000A
#define BT_L2CAP_LE_ERR_UNACCEPT_PARAMS 0x000B
#define BT_L2CAP_LE_ERR_INVALID_PARAMS 0x000C
#define BT_L2CAP_LE_CONN_RSP 0x15
struct bt_l2cap_le_conn_rsp {
uint16_t dcid;
uint16_t mtu;
uint16_t mps;
uint16_t credits;
uint16_t result;
} __packed;
#define BT_L2CAP_LE_CREDITS 0x16
struct bt_l2cap_le_credits {
uint16_t cid;
uint16_t credits;
} __packed;
#define BT_L2CAP_ECRED_CONN_REQ 0x17
struct bt_l2cap_ecred_conn_req {
uint16_t psm;
uint16_t mtu;
uint16_t mps;
uint16_t credits;
uint16_t scid[0];
} __packed;
#define BT_L2CAP_ECRED_CONN_RSP 0x18
struct bt_l2cap_ecred_conn_rsp {
uint16_t mtu;
uint16_t mps;
uint16_t credits;
uint16_t result;
uint16_t dcid[0];
} __packed;
#define BT_L2CAP_ECRED_RECONF_REQ 0x19
struct bt_l2cap_ecred_reconf_req {
uint16_t mtu;
uint16_t mps;
uint16_t scid[0];
} __packed;
#define BT_L2CAP_RECONF_SUCCESS 0x0000
#define BT_L2CAP_RECONF_INVALID_MTU 0x0001
#define BT_L2CAP_RECONF_INVALID_MPS 0x0002
#define BT_L2CAP_ECRED_RECONF_RSP 0x1a
struct bt_l2cap_ecred_reconf_rsp {
uint16_t result;
} __packed;

View File

@ -318,8 +318,10 @@ SRC_COMMON_HAL_ALL = \
watchdog/__init__.c \
ifeq ($(CIRCUITPY_BLEIO_HCI),1)
# Helper code for _bleio HCI.
SRC_C += \
common-hal/_bleio/hci_api.c \
common-hal/_bleio/att.c \
common-hal/_bleio/hci.c \
endif

View File

@ -120,6 +120,8 @@ size_t m_get_peak_bytes_allocated(void);
// align ptr to the nearest multiple of "alignment"
#define MP_ALIGN(ptr, alignment) (void*)(((uintptr_t)(ptr) + ((alignment) - 1)) & ~((alignment) - 1))
#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))
/** unichar / UTF-8 *********************************************/
#if MICROPY_PY_BUILTINS_STR_UNICODE

View File

@ -19,7 +19,7 @@ endif
QSTR_GLOBAL_DEPENDENCIES += $(PY_SRC)/mpconfig.h mpconfigport.h
# some code is performance bottleneck and compiled with other optimization options
CSUPEROPT = -O3
_CSUPEROPT = -O3
# this sets the config file for FatFs
CFLAGS_MOD += -DFFCONF_H=\"lib/oofatfs/ffconf.h\"