|
1 | 1 | // Derived from ArduinoBLE.
|
2 | 2 | // Copyright 2020 Dan Halbert for Adafruit Industries
|
3 | 3 |
|
| 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 | + |
4 | 10 | /*
|
5 | 11 | This file is part of the ArduinoBLE library.
|
6 | 12 | 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
|
857 | 863 | }
|
858 | 864 | }
|
859 | 865 |
|
| 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 | + |
860 | 880 | STATIC void process_find_info_rsp(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) {
|
861 | 881 | if (dlen < 2) {
|
862 | 882 | return; // invalid, drop
|
@@ -911,7 +931,7 @@ STATIC void process_find_type_req(uint16_t conn_handle, uint16_t mtu, uint8_t dl
|
911 | 931 | }
|
912 | 932 | }
|
913 | 933 |
|
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[]) { |
915 | 935 | struct bt_att_read_group_req *req = (struct bt_att_read_group_req *)data;
|
916 | 936 | uint16_t type_uuid = req->uuid[0] | (req->uuid[1] << 8);
|
917 | 937 |
|
@@ -995,6 +1015,25 @@ STATIC void process_read_group_req(uint16_t conn_handle, uint16_t mtu, uint8_t d
|
995 | 1015 | }
|
996 | 1016 | }
|
997 | 1017 |
|
| 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 | + |
998 | 1037 | STATIC void process_read_group_rsp(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) {
|
999 | 1038 | if (dlen < 2) {
|
1000 | 1039 | return; // invalid, drop
|
@@ -1272,6 +1311,24 @@ STATIC void process_read_type_req(uint16_t conn_handle, uint16_t mtu, uint8_t dl
|
1272 | 1311 | }
|
1273 | 1312 | }
|
1274 | 1313 |
|
| 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 | + |
1275 | 1332 | STATIC void process_read_type_rsp(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) {
|
1276 | 1333 | if (dlen < 1) {
|
1277 | 1334 | return; // invalid, drop
|
@@ -1662,3 +1719,77 @@ void att_process_data(uint16_t conn_handle, uint8_t dlen, uint8_t data[]) {
|
1662 | 1719 | break;
|
1663 | 1720 | }
|
1664 | 1721 | }
|
| 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