BLE: Increase mtu (#837)

* Incease mtu & buffer size
* bt: process mtu size in RPC callbacks

Co-authored-by: Tony Freeman <tonyfreeman@users.noreply.github.com>
Co-authored-by: gornekich <n.gorbadey@gmail.com>
This commit is contained in:
tonyfreeman 2021-12-08 16:59:40 +03:00 committed by GitHub
parent f0aed7e583
commit c6cb6ae810
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 52 additions and 23 deletions

View file

@ -132,9 +132,9 @@ static void bt_rpc_send_bytes_callback(void* context, uint8_t* bytes, size_t byt
size_t bytes_sent = 0;
while(bytes_sent < bytes_len) {
size_t bytes_remain = bytes_len - bytes_sent;
if(bytes_remain > FURI_HAL_BT_SERIAL_PACKET_SIZE_MAX) {
furi_hal_bt_serial_tx(&bytes[bytes_sent], FURI_HAL_BT_SERIAL_PACKET_SIZE_MAX);
bytes_sent += FURI_HAL_BT_SERIAL_PACKET_SIZE_MAX;
if(bytes_remain > bt->max_packet_size) {
furi_hal_bt_serial_tx(&bytes[bytes_sent], bt->max_packet_size);
bytes_sent += bt->max_packet_size;
} else {
furi_hal_bt_serial_tx(&bytes[bytes_sent], bytes_remain);
bytes_sent += bytes_remain;

View file

@ -139,7 +139,7 @@
/**
* Maximum supported ATT_MTU size
*/
#define CFG_BLE_MAX_ATT_MTU (251)
#define CFG_BLE_MAX_ATT_MTU (489)
/**
* Size of the storage area for Attribute values

View file

@ -184,17 +184,31 @@ bool serial_svc_is_started() {
return serial_svc != NULL;
}
bool serial_svc_update_tx(uint8_t* data, uint8_t data_len) {
bool serial_svc_update_tx(uint8_t* data, uint16_t data_len) {
if(data_len > SERIAL_SVC_DATA_LEN_MAX) {
return false;
}
tBleStatus result = aci_gatt_update_char_value(serial_svc->svc_handle,
serial_svc->tx_char_handle,
for(uint16_t remained = data_len; remained > 0;) {
uint8_t value_len = MIN(SERIAL_SVC_CHAR_VALUE_LEN_MAX, remained);
uint16_t value_offset = data_len - remained;
remained -= value_len;
tBleStatus result = aci_gatt_update_char_value_ext(
0,
serial_svc->svc_handle,
serial_svc->tx_char_handle,
remained ? 0x00 : 0x02,
data_len,
data);
if(result) {
FURI_LOG_E(TAG, "Failed updating TX characteristic: %d", result);
value_offset,
value_len,
data + value_offset);
if(result) {
FURI_LOG_E(TAG, "Failed updating TX characteristic: %d", result);
return false;
}
}
return result != BLE_STATUS_SUCCESS;
return true;
}

View file

@ -3,7 +3,7 @@
#include <stdint.h>
#include <stdbool.h>
#define SERIAL_SVC_DATA_LEN_MAX (248)
#define SERIAL_SVC_DATA_LEN_MAX (486)
#ifdef __cplusplus
extern "C" {
@ -36,7 +36,7 @@ void serial_svc_stop();
bool serial_svc_is_started();
bool serial_svc_update_tx(uint8_t* data, uint8_t data_len);
bool serial_svc_update_tx(uint8_t* data, uint16_t data_len);
#ifdef __cplusplus
}

View file

@ -139,7 +139,7 @@
/**
* Maximum supported ATT_MTU size
*/
#define CFG_BLE_MAX_ATT_MTU (251)
#define CFG_BLE_MAX_ATT_MTU (489)
/**
* Size of the storage area for Attribute values

View file

@ -184,17 +184,31 @@ bool serial_svc_is_started() {
return serial_svc != NULL;
}
bool serial_svc_update_tx(uint8_t* data, uint8_t data_len) {
bool serial_svc_update_tx(uint8_t* data, uint16_t data_len) {
if(data_len > SERIAL_SVC_DATA_LEN_MAX) {
return false;
}
tBleStatus result = aci_gatt_update_char_value(serial_svc->svc_handle,
serial_svc->tx_char_handle,
for(uint16_t remained = data_len; remained > 0;) {
uint8_t value_len = MIN(SERIAL_SVC_CHAR_VALUE_LEN_MAX, remained);
uint16_t value_offset = data_len - remained;
remained -= value_len;
tBleStatus result = aci_gatt_update_char_value_ext(
0,
serial_svc->svc_handle,
serial_svc->tx_char_handle,
remained ? 0x00 : 0x02,
data_len,
data);
if(result) {
FURI_LOG_E(TAG, "Failed updating TX characteristic: %d", result);
value_offset,
value_len,
data + value_offset);
if(result) {
FURI_LOG_E(TAG, "Failed updating TX characteristic: %d", result);
return false;
}
}
return result != BLE_STATUS_SUCCESS;
return true;
}

View file

@ -3,7 +3,8 @@
#include <stdint.h>
#include <stdbool.h>
#define SERIAL_SVC_DATA_LEN_MAX (248)
#define SERIAL_SVC_DATA_LEN_MAX (486)
#define SERIAL_SVC_CHAR_VALUE_LEN_MAX (243)
#ifdef __cplusplus
extern "C" {
@ -36,7 +37,7 @@ void serial_svc_stop();
bool serial_svc_is_started();
bool serial_svc_update_tx(uint8_t* data, uint8_t data_len);
bool serial_svc_update_tx(uint8_t* data, uint16_t data_len);
#ifdef __cplusplus
}