Skip to content

Commit 25ff6b0

Browse files
committed
ble_hci: instead of deleting code, disable unused function warnings
1 parent 340d6b9 commit 25ff6b0

File tree

1 file changed

+132
-1
lines changed
  • devices/ble_hci/common-hal/_bleio

1 file changed

+132
-1
lines changed

devices/ble_hci/common-hal/_bleio/att.c

Lines changed: 132 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// Derived from ArduinoBLE.
22
// Copyright 2020 Dan Halbert for Adafruit Industries
33

4+
// Some functions here are unused now, but may be used in the future.
5+
// Don't warn or error about this, and depend on the compiler & linker to
6+
// eliminate the associated code.
7+
#pragma GCC diagnostic ignored "-Wunused"
8+
#pragma GCC diagnostic ignored "-Wunused-function"
9+
410
/*
511
This file is part of the ArduinoBLE library.
612
Copyright (c) 2018 Arduino SA. All rights reserved.
@@ -857,6 +863,20 @@ STATIC void process_find_info_req(uint16_t conn_handle, uint16_t mtu, uint8_t dl
857863
}
858864
}
859865

866+
static int att_find_info_req(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle, uint8_t response_buffer[]) {
867+
struct __packed req {
868+
struct bt_att_hdr h;
869+
struct bt_att_find_info_req r;
870+
} req = { {
871+
.code = BT_ATT_OP_FIND_INFO_REQ,
872+
}, {
873+
.start_handle = start_handle,
874+
.end_handle = end_handle,
875+
}};
876+
877+
return send_req_wait_for_rsp(conn_handle, sizeof(req), (uint8_t *)&req, response_buffer);
878+
}
879+
860880
STATIC void process_find_info_rsp(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) {
861881
if (dlen < 2) {
862882
return; // invalid, drop
@@ -911,7 +931,7 @@ STATIC void process_find_type_req(uint16_t conn_handle, uint16_t mtu, uint8_t dl
911931
}
912932
}
913933

914-
STATIC void process_read_group_req(uint16_t conn_handle, uint16_t mtu, uint8_t dlen, uint8_t data[]) {
934+
static void process_read_group_req(uint16_t conn_handle, uint16_t mtu, uint8_t dlen, uint8_t data[]) {
915935
struct bt_att_read_group_req *req = (struct bt_att_read_group_req *)data;
916936
uint16_t type_uuid = req->uuid[0] | (req->uuid[1] << 8);
917937

@@ -995,6 +1015,25 @@ STATIC void process_read_group_req(uint16_t conn_handle, uint16_t mtu, uint8_t d
9951015
}
9961016
}
9971017

1018+
static int att_read_group_req(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle, uint16_t uuid, uint8_t response_buffer[]) {
1019+
1020+
typedef struct __packed {
1021+
struct bt_att_hdr h;
1022+
struct bt_att_read_group_req r;
1023+
} req_t;
1024+
1025+
uint8_t req_bytes[sizeof(req_t) + sizeof(uuid)];
1026+
req_t *req = (req_t *)req_bytes;
1027+
1028+
req->h.code = BT_ATT_OP_READ_GROUP_REQ;
1029+
req->r.start_handle = start_handle;
1030+
req->r.end_handle = end_handle;
1031+
req->r.uuid[0] = uuid & 0xff;
1032+
req->r.uuid[1] = uuid >> 8;
1033+
1034+
return send_req_wait_for_rsp(conn_handle, sizeof(req_bytes), req_bytes, response_buffer);
1035+
}
1036+
9981037
STATIC void process_read_group_rsp(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) {
9991038
if (dlen < 2) {
10001039
return; // invalid, drop
@@ -1272,6 +1311,24 @@ STATIC void process_read_type_req(uint16_t conn_handle, uint16_t mtu, uint8_t dl
12721311
}
12731312
}
12741313

1314+
static int att_read_type_req(uint16_t conn_handle, uint16_t start_handle, uint16_t end_handle, uint16_t type, uint8_t response_buffer[]) {
1315+
typedef struct __packed {
1316+
struct bt_att_hdr h;
1317+
struct bt_att_read_type_req r;
1318+
} req_t;
1319+
1320+
uint8_t req_bytes[sizeof(req_t) + sizeof(type)];
1321+
req_t *req = (req_t *)req_bytes;
1322+
1323+
req->h.code = BT_ATT_OP_READ_TYPE_REQ;
1324+
req->r.start_handle = start_handle;
1325+
req->r.end_handle = end_handle;
1326+
req->r.uuid[0] = type & 0xff;
1327+
req->r.uuid[1] = type >> 8;
1328+
1329+
return send_req_wait_for_rsp(conn_handle, sizeof(req_bytes), req_bytes, response_buffer);
1330+
}
1331+
12751332
STATIC void process_read_type_rsp(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) {
12761333
if (dlen < 1) {
12771334
return; // invalid, drop
@@ -1662,3 +1719,77 @@ void att_process_data(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) {
16621719
break;
16631720
}
16641721
}
1722+
1723+
// FIX Do we need all of these?
1724+
static void check_att_err(uint8_t err) {
1725+
const compressed_string_t *msg = NULL;
1726+
switch (err) {
1727+
case 0:
1728+
return;
1729+
case BT_ATT_ERR_INVALID_HANDLE:
1730+
msg = translate("Invalid handle");
1731+
break;
1732+
case BT_ATT_ERR_READ_NOT_PERMITTED:
1733+
msg = translate("Read not permitted");
1734+
break;
1735+
case BT_ATT_ERR_WRITE_NOT_PERMITTED:
1736+
msg = translate("Write not permitted");
1737+
break;
1738+
case BT_ATT_ERR_INVALID_PDU:
1739+
msg = translate("Invalid PDU");
1740+
break;
1741+
case BT_ATT_ERR_NOT_SUPPORTED:
1742+
msg = translate("Not supported");
1743+
break;
1744+
case BT_ATT_ERR_INVALID_OFFSET:
1745+
msg = translate("Invalid offset");
1746+
break;
1747+
case BT_ATT_ERR_PREPARE_QUEUE_FULL:
1748+
msg = translate("Prepare queue full");
1749+
break;
1750+
case BT_ATT_ERR_ATTRIBUTE_NOT_FOUND:
1751+
msg = translate("Attribute not found");
1752+
break;
1753+
case BT_ATT_ERR_ATTRIBUTE_NOT_LONG:
1754+
msg = translate("Attribute not long");
1755+
break;
1756+
case BT_ATT_ERR_ENCRYPTION_KEY_SIZE:
1757+
msg = translate("Encryption key size");
1758+
break;
1759+
case BT_ATT_ERR_INVALID_ATTRIBUTE_LEN:
1760+
msg = translate("Invalid attribute length");
1761+
break;
1762+
case BT_ATT_ERR_UNLIKELY:
1763+
msg = translate("Unlikely");
1764+
break;
1765+
case BT_ATT_ERR_UNSUPPORTED_GROUP_TYPE:
1766+
msg = translate("Unsupported group type");
1767+
break;
1768+
case BT_ATT_ERR_INSUFFICIENT_RESOURCES:
1769+
msg = translate("Insufficient resources");
1770+
break;
1771+
case BT_ATT_ERR_DB_OUT_OF_SYNC:
1772+
msg = translate("DB out of sync");
1773+
break;
1774+
case BT_ATT_ERR_VALUE_NOT_ALLOWED:
1775+
msg = translate("Value not allowed");
1776+
break;
1777+
}
1778+
if (msg) {
1779+
mp_raise_bleio_BluetoothError(msg);
1780+
}
1781+
1782+
switch (err) {
1783+
case BT_ATT_ERR_AUTHENTICATION:
1784+
msg = translate("Insufficient authentication");
1785+
break;
1786+
case BT_ATT_ERR_INSUFFICIENT_ENCRYPTION:
1787+
msg = translate("Insufficient encryption");
1788+
break;
1789+
}
1790+
if (msg) {
1791+
mp_raise_bleio_SecurityError(msg);
1792+
}
1793+
1794+
mp_raise_bleio_BluetoothError(translate("Unknown ATT error: 0x%02x"), err);
1795+
}

0 commit comments

Comments
 (0)