From 5ffbed6012f4557886e801f654184873f84524ee Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 17 Dec 2015 16:20:33 +0100 Subject: [PATCH] allow to limit ATT Server request buffer and SDP response buffer --- ble/att_server.c | 10 +++++++++- src/sdp.c | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ble/att_server.c b/ble/att_server.c index d3cd8728c..968fe436d 100644 --- a/ble/att_server.c +++ b/ble/att_server.c @@ -66,6 +66,11 @@ static void att_run(void); +// max ATT request matches L2CAP PDU -- allow to use smaller buffer +#ifndef ATT_REQUEST_BUFFER_SIZE +#define ATT_REQUEST_BUFFER_SIZE HCI_ACL_PAYLOAD_SIZE +#endif + typedef enum { ATT_SERVER_IDLE, ATT_SERVER_REQUEST_RECEIVED, @@ -79,7 +84,7 @@ static att_server_state_t att_server_state; static uint8_t att_client_addr_type; static bd_addr_t att_client_address; static uint16_t att_request_size = 0; -static uint8_t att_request_buffer[HCI_ACL_PAYLOAD_SIZE]; +static uint8_t att_request_buffer[ATT_REQUEST_BUFFER_SIZE]; static int att_ir_le_device_db_index = -1; static int att_ir_lookup_active = 0; @@ -146,6 +151,9 @@ static void att_event_packet_handler (uint8_t packet_type, uint16_t channel, uin att_connection.con_handle = READ_BT_16(packet, 4); att_connection.mtu = ATT_DEFAULT_MTU; att_connection.max_mtu = l2cap_max_le_mtu(); + if (att_connection.max_mtu > ATT_REQUEST_BUFFER_SIZE){ + att_connection.max_mtu = ATT_REQUEST_BUFFER_SIZE; + } att_connection.encryption_key_size = 0; att_connection.authenticated = 0; att_connection.authorized = 0; diff --git a/src/sdp.c b/src/sdp.c index 562c9725c..e842972e9 100644 --- a/src/sdp.c +++ b/src/sdp.c @@ -54,8 +54,10 @@ // max reserved ServiceRecordHandle #define maxReservedServiceRecordHandle 0xffff -// max SDP response +// max SDP response matches L2CAP PDU -- allow to use smaller buffer +#ifndef SDP_RESPONSE_BUFFER_SIZE #define SDP_RESPONSE_BUFFER_SIZE (HCI_ACL_BUFFER_SIZE-HCI_ACL_HEADER_SIZE) +#endif static void sdp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); uint32_t sdp_get_service_record_handle(uint8_t * record);