mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-26 21:35:16 +00:00
use buffers of size 1021 to fit 3-DH5 ACL packets, check buffer for SDP responses
This commit is contained in:
parent
47f1a3c4d8
commit
11c41d51ae
@ -48,7 +48,8 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static uint8_t hci_cmd_buffer[3+255];
|
||||
// static uint8_t hci_cmd_buffer[3+255]; // HCI Command Header + max payload
|
||||
static uint8_t hci_cmd_buffer[HCI_ACL_3DH5_SIZE]; // BTstack command packets are not size restricted
|
||||
|
||||
static connection_t *btstack_connection = NULL;
|
||||
|
||||
|
@ -53,6 +53,10 @@
|
||||
#define HCI_SCO_DATA_PKT_HDR 0x03
|
||||
#define HCI_EVENT_PKT_HDR 0x02
|
||||
|
||||
// packet sizes
|
||||
#define HCI_ACL_3DH5_SIZE 1021
|
||||
#define HCI_ACL_DH5_SIZE 339
|
||||
|
||||
// OGFs
|
||||
#define OGF_LINK_CONTROL 0x01
|
||||
#define OGF_LINK_POLICY 0x02
|
||||
|
@ -73,7 +73,7 @@ static H4_STATE h4_state;
|
||||
static int bytes_to_read;
|
||||
static int read_pos;
|
||||
// static uint8_t hci_event_buffer[255+2]; // maximal payload + 2 bytes header
|
||||
static uint8_t hci_packet[400]; // bigger than largest packet
|
||||
static uint8_t hci_packet[HCI_ACL_3DH5_SIZE]; // bigger than largest packet
|
||||
|
||||
#ifdef TEST_LONG_INVALID_REMOTE_NAME
|
||||
// test event with remote name of 255 bytes length
|
||||
|
@ -64,7 +64,7 @@ typedef enum {
|
||||
typedef struct h5_slip {
|
||||
state_t state;
|
||||
uint16_t length;
|
||||
uint8_t data[400];
|
||||
uint8_t data[HCI_ACL_3DH5_SIZE];
|
||||
} h5_slip_t;
|
||||
|
||||
// Global State
|
||||
|
@ -77,9 +77,9 @@ static hci_transport_t * hci_transport_usb = NULL;
|
||||
|
||||
static void (*packet_handler)(uint8_t *packet, int size) = dummy_handler;
|
||||
|
||||
static uint8_t hci_cmd_out[400]; // bigger than largest packet
|
||||
static uint8_t hci_event_buffer[400]; // bigger than largest packet
|
||||
static uint8_t hci_acl_in[400]; // bigger than largest packet
|
||||
static uint8_t hci_cmd_out[HCI_ACL_3DH5_SIZE]; // bigger than largest packet
|
||||
static uint8_t hci_event_buffer[HCI_ACL_3DH5_SIZE]; // bigger than largest packet
|
||||
static uint8_t hci_acl_in[HCI_ACL_3DH5_SIZE]; // bigger than largest packet
|
||||
|
||||
// libusb
|
||||
static struct libusb_device_descriptor desc;
|
||||
@ -278,7 +278,7 @@ static int usb_open(void *transport_config){
|
||||
|
||||
|
||||
// bulk in (= ACL packets) handler
|
||||
libusb_fill_bulk_transfer(bulk_in_transfer, handle, 0x82, hci_acl_in, 400, bulk_in_callback, NULL, 3000) ;
|
||||
libusb_fill_bulk_transfer(bulk_in_transfer, handle, 0x82, hci_acl_in, HCI_ACL_3DH5_SIZE, bulk_in_callback, NULL, 3000) ;
|
||||
// bulk_in_transfer->flags = LIBUSB_TRANSFER_SHORT_NOT_OK;
|
||||
r = libusb_submit_transfer(bulk_in_transfer);
|
||||
if (r) {
|
||||
|
@ -72,8 +72,7 @@ static uint8_t config_options[] = { 1, 2, 150, 0}; // mtu = 48
|
||||
|
||||
void l2cap_init(){
|
||||
sig_buffer = malloc( L2CAP_MINIMAL_MTU );
|
||||
// acl_buffer = malloc( 255 + 8 );
|
||||
acl_buffer = malloc( 400 + 8 );
|
||||
acl_buffer = malloc( HCI_ACL_3DH5_SIZE);
|
||||
|
||||
//
|
||||
// register callback with HCI
|
||||
|
11
src/sdp.c
11
src/sdp.c
@ -70,6 +70,10 @@ static uint32_t sdp_next_service_record_handle = maxReservedServiceRecordHandle
|
||||
// AttributeIDList used to remove ServiceRecordHandle
|
||||
const uint8_t removeServiceRecordHandleAttributeIDList[] = { 0x36, 0x00, 0x05, 0x0A, 0x00, 0x01, 0xFF, 0xFF };
|
||||
|
||||
#define SDP_RESPONSE_BUFFER_SIZE HCI_ACL_3DH5_SIZE
|
||||
static uint8_t sdp_response_buffer[SDP_RESPONSE_BUFFER_SIZE];
|
||||
|
||||
|
||||
void sdp_init(){
|
||||
// register with l2cap psm sevices
|
||||
l2cap_register_service_internal(NULL, sdp_packet_handler, PSM_SDP, 250);
|
||||
@ -195,8 +199,6 @@ void sdp_unregister_services_for_connection(void *connection){
|
||||
// PDU
|
||||
// PDU ID (1), Transaction ID (2), Param Length (2), Param 1, Param 2, ..
|
||||
|
||||
static uint8_t sdp_response_buffer[400];
|
||||
|
||||
int sdp_create_error_response(uint16_t transaction_id, uint16_t error_code){
|
||||
sdp_response_buffer[0] = SDP_ErrorResponse;
|
||||
net_store_16(sdp_response_buffer, 1, transaction_id);
|
||||
@ -445,6 +447,11 @@ static void sdp_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *p
|
||||
transaction_id = READ_NET_16(packet, 1);
|
||||
param_len = READ_NET_16(packet, 3);
|
||||
remote_mtu = l2cap_get_remote_mtu_for_local_cid(channel);
|
||||
// account for our buffer
|
||||
if (remote_mtu > SDP_RESPONSE_BUFFER_SIZE){
|
||||
remote_mtu = SDP_RESPONSE_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
// printf("SDP Request: type %u, transaction id %u, len %u, mtu %u\n", pdu_id, transaction_id, param_len, remote_mtu);
|
||||
switch (pdu_id){
|
||||
|
||||
|
@ -88,7 +88,7 @@ struct connection {
|
||||
SOCKET_STATE state;
|
||||
uint16_t bytes_read;
|
||||
uint16_t bytes_to_read;
|
||||
uint8_t buffer[360]; // packet_header(6) + max packet: DH5 = header(4) + payload (339)
|
||||
uint8_t buffer[6+HCI_ACL_3DH5_SIZE]; // packet_header(6) + max packet: 3-DH5 = header(6) + payload (1021)
|
||||
};
|
||||
|
||||
/** list of socket connections */
|
||||
|
Loading…
x
Reference in New Issue
Block a user