diff --git a/applications/bt/bt_service/bt.c b/applications/bt/bt_service/bt.c index 074ab980f..97cc156bb 100755 --- a/applications/bt/bt_service/bt.c +++ b/applications/bt/bt_service/bt.c @@ -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; diff --git a/firmware/targets/f6/ble-glue/app_conf.h b/firmware/targets/f6/ble-glue/app_conf.h index eebdbbdbd..059e8e4fe 100644 --- a/firmware/targets/f6/ble-glue/app_conf.h +++ b/firmware/targets/f6/ble-glue/app_conf.h @@ -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 diff --git a/firmware/targets/f6/ble-glue/serial_service.c b/firmware/targets/f6/ble-glue/serial_service.c index 4c70ccb09..ab2015468 100644 --- a/firmware/targets/f6/ble-glue/serial_service.c +++ b/firmware/targets/f6/ble-glue/serial_service.c @@ -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; } diff --git a/firmware/targets/f6/ble-glue/serial_service.h b/firmware/targets/f6/ble-glue/serial_service.h index 3ea548afa..1c365c0e0 100644 --- a/firmware/targets/f6/ble-glue/serial_service.h +++ b/firmware/targets/f6/ble-glue/serial_service.h @@ -3,7 +3,7 @@ #include #include -#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 } diff --git a/firmware/targets/f7/ble-glue/app_conf.h b/firmware/targets/f7/ble-glue/app_conf.h index eebdbbdbd..059e8e4fe 100644 --- a/firmware/targets/f7/ble-glue/app_conf.h +++ b/firmware/targets/f7/ble-glue/app_conf.h @@ -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 diff --git a/firmware/targets/f7/ble-glue/serial_service.c b/firmware/targets/f7/ble-glue/serial_service.c index 4c70ccb09..ab2015468 100644 --- a/firmware/targets/f7/ble-glue/serial_service.c +++ b/firmware/targets/f7/ble-glue/serial_service.c @@ -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; } diff --git a/firmware/targets/f7/ble-glue/serial_service.h b/firmware/targets/f7/ble-glue/serial_service.h index 3ea548afa..6e19f86dd 100644 --- a/firmware/targets/f7/ble-glue/serial_service.h +++ b/firmware/targets/f7/ble-glue/serial_service.h @@ -3,7 +3,8 @@ #include #include -#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 }