mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-30 07:21:20 +00:00
Merge branch 'master' of https://github.com/bluekitchen/btstack
This commit is contained in:
commit
7234ca0d40
12
ble/gap_le.h
12
ble/gap_le.h
@ -82,6 +82,18 @@ gap_random_address_type_t gap_random_address_get_mode(void);
|
||||
int gap_update_connection_parameters(hci_con_handle_t con_handle, uint16_t conn_interval_min,
|
||||
uint16_t conn_interval_max, uint16_t conn_latency, uint16_t supervision_timeout);
|
||||
|
||||
/**
|
||||
* @brief Request an update of the connection parameter for a given LE connection
|
||||
* @param handle
|
||||
* @param conn_interval_min (unit: 1.25ms)
|
||||
* @param conn_interval_max (unit: 1.25ms)
|
||||
* @param conn_latency
|
||||
* @param supervision_timeout (unit: 10ms)
|
||||
* @returns 0 if ok
|
||||
*/
|
||||
int gap_request_connection_parameter_update(hci_con_handle_t con_handle, uint16_t conn_interval_min,
|
||||
uint16_t conn_interval_max, uint16_t conn_latency, uint16_t supervision_timeout);
|
||||
|
||||
/**
|
||||
* @brief Set Advertisement Data
|
||||
* @param advertising_data_length
|
||||
|
@ -226,30 +226,35 @@ static void l2cap_run(void){
|
||||
hci_connections_get_iterator(&it);
|
||||
while(linked_list_iterator_has_next(&it)){
|
||||
hci_connection_t * connection = (hci_connection_t *) linked_list_iterator_next(&it);
|
||||
int result;
|
||||
|
||||
if (!hci_can_send_acl_packet_now(connection->con_handle)) continue;
|
||||
uint8_t *acl_buffer;
|
||||
uint16_t len;
|
||||
switch (connection->le_con_parameter_update_state){
|
||||
case CON_PARAMETER_UPDATE_SEND_REQUEST:
|
||||
connection->le_con_parameter_update_state = CON_PARAMETER_UPDATE_NONE;
|
||||
hci_reserve_packet_buffer();
|
||||
acl_buffer = hci_get_outgoing_packet_buffer();
|
||||
len = l2cap_le_create_connection_parameter_update_request(acl_buffer, connection->con_handle, connection->le_con_param_update_identifier,
|
||||
connection->le_conn_interval_min, connection->le_conn_interval_max, connection->le_conn_latency, connection->le_supervision_timeout);
|
||||
hci_send_acl_packet_buffer(len);
|
||||
break;
|
||||
case CON_PARAMETER_UPDATE_SEND_RESPONSE:
|
||||
result = 0;
|
||||
connection->le_con_parameter_update_state = CON_PARAMETER_UPDATE_CHANGE_HCI_CON_PARAMETERS;
|
||||
hci_reserve_packet_buffer();
|
||||
acl_buffer = hci_get_outgoing_packet_buffer();
|
||||
len = l2cap_le_create_connection_parameter_update_response(acl_buffer, connection->con_handle, connection->le_con_param_update_identifier, 0);
|
||||
hci_send_acl_packet_buffer(len);
|
||||
break;
|
||||
case CON_PARAMETER_UPDATE_DENY:
|
||||
result = 1;
|
||||
connection->le_con_parameter_update_state = CON_PARAMETER_UPDATE_NONE;
|
||||
hci_reserve_packet_buffer();
|
||||
acl_buffer = hci_get_outgoing_packet_buffer();
|
||||
len = l2cap_le_create_connection_parameter_update_response(acl_buffer, connection->con_handle, connection->le_con_param_update_identifier, 1);
|
||||
hci_send_acl_packet_buffer(len);
|
||||
break;
|
||||
default:
|
||||
result = -1;
|
||||
break;
|
||||
}
|
||||
if (result < 0) break;
|
||||
|
||||
if (!hci_can_send_acl_packet_now(connection->con_handle)) break;
|
||||
hci_reserve_packet_buffer();
|
||||
uint8_t *acl_buffer = hci_get_outgoing_packet_buffer();
|
||||
connection->le_con_parameter_update_state = CON_PARAMETER_UPDATE_NONE;
|
||||
uint16_t len = l2cap_le_create_connection_parameter_update_response(acl_buffer, connection->con_handle, connection->le_con_param_update_identifier, result);
|
||||
hci_send_acl_packet_buffer(len);
|
||||
if (result == 0){
|
||||
connection->le_con_parameter_update_state = CON_PARAMETER_UPDATE_CHANGE_HCI_CON_PARAMETERS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,8 +184,7 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
||||
test_data_len = ATT_DEFAULT_MTU - 3;
|
||||
conn_handle = READ_BT_16(packet, 4);
|
||||
// min con interval 20 ms
|
||||
// res = gap_update_connection_parameters(conn_handle, 0x10, 0x10, 0, 0x0048);
|
||||
// l2cap_le_request_connection_parameter_update(conn_handle, 0x10, 0x18, 0, 0x0048);
|
||||
// gap_request_connection_parameter_update(conn_handle, 0x10, 0x18, 0, 0x0048);
|
||||
// printf("Connected, requesting conn param update for handle 0x%04x\n", conn_handle);
|
||||
break;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ DIR=.
|
||||
BTSTACK_ROOT=${DIR}/../..
|
||||
DUMMY=$(shell )
|
||||
VERSION=`sed -n -e 's/^.*BTSTACK_VERSION \"\(.*\)\"/\1/p' ${BTSTACK_ROOT}/include/btstack/version.h`
|
||||
BTSTACK_PACKAGE=${DIR}/btstack
|
||||
BTSTACK_PACKAGE=/tmp/btstack
|
||||
ARCHIVE=btstack-arduino-${VERSION}.zip
|
||||
|
||||
SRC_FILES =btstack_memory.c linked_list.c memory_pool.c run_loop.c run_loop_embedded.c
|
||||
@ -28,6 +28,9 @@ ARDUINO_LIBS=~/Documents/arduino/libraries/BTstack
|
||||
|
||||
all: release
|
||||
|
||||
clean:
|
||||
rm -rf ${BTSTACK_PACKAGE}
|
||||
|
||||
update_version:
|
||||
${BTSTACK_ROOT}/tools/get_version.sh
|
||||
|
||||
@ -41,5 +44,5 @@ release: update_version
|
||||
mkdir ${BTSTACK_PACKAGE}
|
||||
cp -r ${PATHS} ${BTSTACK_PACKAGE}
|
||||
rm -f ${ARCHIVE}
|
||||
zip -r ${ARCHIVE} btstack
|
||||
zip -r ${ARCHIVE} ${BTSTACK_PACKAGE}
|
||||
cp ${ARCHIVE} btstack-arduino-latest.zip
|
||||
|
22
src/hci.c
22
src/hci.c
@ -3091,6 +3091,28 @@ int gap_update_connection_parameters(hci_con_handle_t con_handle, uint16_t conn_
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request an update of the connection parameter for a given LE connection
|
||||
* @param handle
|
||||
* @param conn_interval_min (unit: 1.25ms)
|
||||
* @param conn_interval_max (unit: 1.25ms)
|
||||
* @param conn_latency
|
||||
* @param supervision_timeout (unit: 10ms)
|
||||
* @returns 0 if ok
|
||||
*/
|
||||
int gap_request_connection_parameter_update(hci_con_handle_t con_handle, uint16_t conn_interval_min,
|
||||
uint16_t conn_interval_max, uint16_t conn_latency, uint16_t supervision_timeout){
|
||||
hci_connection_t * connection = hci_connection_for_handle(con_handle);
|
||||
if (!connection) return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
|
||||
connection->le_conn_interval_min = conn_interval_min;
|
||||
connection->le_conn_interval_max = conn_interval_max;
|
||||
connection->le_conn_latency = conn_latency;
|
||||
connection->le_supervision_timeout = supervision_timeout;
|
||||
connection->le_con_parameter_update_state = CON_PARAMETER_UPDATE_SEND_REQUEST;
|
||||
hci_run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set Advertisement Data
|
||||
* @param advertising_data_length
|
||||
|
@ -242,6 +242,7 @@ extern "C" {
|
||||
|
||||
typedef enum {
|
||||
CON_PARAMETER_UPDATE_NONE,
|
||||
CON_PARAMETER_UPDATE_SEND_REQUEST,
|
||||
CON_PARAMETER_UPDATE_SEND_RESPONSE,
|
||||
CON_PARAMETER_UPDATE_CHANGE_HCI_CON_PARAMETERS,
|
||||
CON_PARAMETER_UPDATE_DENY
|
||||
|
43
src/l2cap.c
43
src/l2cap.c
@ -705,30 +705,24 @@ void l2cap_run(void){
|
||||
hci_connections_get_iterator(&it);
|
||||
while(linked_list_iterator_has_next(&it)){
|
||||
hci_connection_t * connection = (hci_connection_t *) linked_list_iterator_next(&it);
|
||||
int result;
|
||||
|
||||
if (!hci_can_send_acl_packet_now(connection->con_handle)) continue;
|
||||
switch (connection->le_con_parameter_update_state){
|
||||
case CON_PARAMETER_UPDATE_SEND_REQUEST:
|
||||
connection->le_con_parameter_update_state = CON_PARAMETER_UPDATE_NONE;
|
||||
l2cap_send_le_signaling_packet(connection->con_handle, CONNECTION_PARAMETER_UPDATE_REQUEST, connection->le_con_param_update_identifier,
|
||||
connection->le_conn_interval_min, connection->le_conn_interval_max, connection->le_conn_latency, connection->le_supervision_timeout);
|
||||
break;
|
||||
case CON_PARAMETER_UPDATE_SEND_RESPONSE:
|
||||
result = 0;
|
||||
connection->le_con_parameter_update_state = CON_PARAMETER_UPDATE_CHANGE_HCI_CON_PARAMETERS;
|
||||
l2cap_send_le_signaling_packet(connection->con_handle, CONNECTION_PARAMETER_UPDATE_RESPONSE, connection->le_con_param_update_identifier, 0);
|
||||
break;
|
||||
case CON_PARAMETER_UPDATE_DENY:
|
||||
result = 1;
|
||||
connection->le_con_parameter_update_state = CON_PARAMETER_UPDATE_NONE;
|
||||
l2cap_send_le_signaling_packet(connection->con_handle, CONNECTION_PARAMETER_UPDATE_RESPONSE, connection->le_con_param_update_identifier, 1);
|
||||
break;
|
||||
default:
|
||||
result = -1;
|
||||
break;
|
||||
}
|
||||
if (result < 0) break;
|
||||
|
||||
if (!hci_can_send_acl_packet_now(connection->con_handle)) break;
|
||||
hci_reserve_packet_buffer();
|
||||
uint8_t *acl_buffer = hci_get_outgoing_packet_buffer();
|
||||
connection->le_con_parameter_update_state = CON_PARAMETER_UPDATE_NONE;
|
||||
uint16_t len = l2cap_le_create_connection_parameter_update_response(acl_buffer, connection->con_handle, connection->le_con_param_update_identifier, result);
|
||||
hci_send_acl_packet_buffer(len);
|
||||
if (result == 0){
|
||||
connection->le_con_parameter_update_state = CON_PARAMETER_UPDATE_CHANGE_HCI_CON_PARAMETERS;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1586,20 +1580,3 @@ void l2cap_register_fixed_channel(btstack_packet_handler_t packet_handler, uint1
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_BLE
|
||||
|
||||
// Request LE connection parameter update
|
||||
int l2cap_le_request_connection_parameter_update(uint16_t handle, uint16_t interval_min, uint16_t interval_max, uint16_t slave_latency, uint16_t timeout_multiplier){
|
||||
if (!hci_can_send_acl_packet_now(handle)){
|
||||
log_info("l2cap_send_signaling_packet, cannot send");
|
||||
return BTSTACK_ACL_BUFFERS_FULL;
|
||||
}
|
||||
// log_info("l2cap_send_signaling_packet type %u", cmd);
|
||||
hci_reserve_packet_buffer();
|
||||
uint8_t *acl_buffer = hci_get_outgoing_packet_buffer();
|
||||
// TODO: find better way to get signaling identifier
|
||||
uint16_t len = l2cap_le_create_connection_parameter_update_request(acl_buffer, handle, 1, interval_min, interval_max, slave_latency, timeout_multiplier);
|
||||
return hci_send_acl_packet_buffer(len);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -259,11 +259,6 @@ void l2cap_unregister_service_internal(void *connection, uint16_t psm);
|
||||
void l2cap_accept_connection_internal(uint16_t local_cid);
|
||||
void l2cap_decline_connection_internal(uint16_t local_cid, uint8_t reason);
|
||||
|
||||
/**
|
||||
* @brief Request LE connection parameter update
|
||||
*/
|
||||
int l2cap_le_request_connection_parameter_update(uint16_t handle, uint16_t interval_min, uint16_t interval_max, uint16_t slave_latency, uint16_t timeout_multiplier);
|
||||
|
||||
/**
|
||||
* @brief Non-blocking UART write
|
||||
*/
|
||||
|
@ -49,20 +49,23 @@
|
||||
|
||||
static const char *l2cap_signaling_commands_format[] = {
|
||||
"2D", // 0x01 command reject: reason {cmd not understood (0), sig MTU exceeded (2:max sig MTU), invalid CID (4:req CID)}, data len, data
|
||||
"22", // 0x02 connection request: PSM, Source CID
|
||||
"2222", // 0x03 connection response: Dest CID, Source CID, Result, Status
|
||||
"22D", // 0x04 config request: Dest CID, Flags, Configuration options
|
||||
"222D", // 0x05 config response: Source CID, Flags, Result, Configuration options
|
||||
"22", // 0x06 disconection request: Dest CID, Source CID
|
||||
"22", // 0x07 disconection response: Dest CID, Source CID
|
||||
"D", // 0x08 echo request: Data
|
||||
"D", // 0x09 echo response: Data
|
||||
"2", // 0x0a information request: InfoType {1=Connectionless MTU, 2=Extended features supported}
|
||||
"22D", // 0x0b information response: InfoType, Result, Data
|
||||
"22", // 0x02 connection request: PSM, Source CID
|
||||
"2222", // 0x03 connection response: Dest CID, Source CID, Result, Status
|
||||
"22D", // 0x04 config request: Dest CID, Flags, Configuration options
|
||||
"222D", // 0x05 config response: Source CID, Flags, Result, Configuration options
|
||||
"22", // 0x06 disconection request: Dest CID, Source CID
|
||||
"22", // 0x07 disconection response: Dest CID, Source CID
|
||||
"D", // 0x08 echo request: Data
|
||||
"D", // 0x09 echo response: Data
|
||||
"2", // 0x0a information request: InfoType {1=Connectionless MTU, 2=Extended features supported}
|
||||
"22D", // 0x0b information response: InfoType, Result, Data
|
||||
#ifdef HAVE_BLE
|
||||
// skip 6 not supported signaling pdus, see below
|
||||
"2222", // 0x12 connection parameter update request: interval min, interval max, slave latency, timeout multipler
|
||||
"2", // 0x13 connection parameter update response: result
|
||||
"2222", // 0x12 connection parameter update request: interval min, interval max, slave latency, timeout multipler
|
||||
"2", // 0x13 connection parameter update response: result
|
||||
"22222", // 0X14 le credit based connection request: le psm, source cid, mtu, mps, initial credits
|
||||
"22222", // 0x15 le credit based connection respone: dest cid, mtu, mps, initial credits, result
|
||||
"22", // 0x16 le flow control credit: source cid, credits
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -146,64 +149,7 @@ uint16_t l2cap_create_signaling_classic(uint8_t * acl_buffer, hci_con_handle_t h
|
||||
}
|
||||
|
||||
#ifdef HAVE_BLE
|
||||
|
||||
uint16_t l2cap_create_signaling_le(uint8_t * acl_buffer, hci_con_handle_t handle, L2CAP_SIGNALING_COMMANDS cmd, uint8_t identifier, va_list argptr){
|
||||
return l2cap_create_signaling_internal(acl_buffer, handle, 5, cmd, identifier, argptr);
|
||||
}
|
||||
|
||||
uint16_t l2cap_le_create_connection_parameter_update_request(uint8_t * acl_buffer, uint16_t handle, uint8_t identifier, uint16_t interval_min, uint16_t interval_max, uint16_t slave_latency, uint16_t timeout_multiplier){
|
||||
|
||||
int pb = hci_non_flushable_packet_boundary_flag_supported() ? 0x00 : 0x02;
|
||||
|
||||
// 0 - Connection handle : PB=pb : BC=00
|
||||
bt_store_16(acl_buffer, 0, handle | (pb << 12) | (0 << 14));
|
||||
// 6 - L2CAP LE Signaling channel = 5
|
||||
bt_store_16(acl_buffer, 6, 5);
|
||||
// 8 - Code
|
||||
acl_buffer[8] = CONNECTION_PARAMETER_UPDATE_REQUEST;
|
||||
// 9 - id
|
||||
acl_buffer[9] = identifier;
|
||||
uint16_t pos = 12;
|
||||
bt_store_16(acl_buffer, pos, interval_min);
|
||||
pos += 2;
|
||||
bt_store_16(acl_buffer, pos, interval_max);
|
||||
pos += 2;
|
||||
bt_store_16(acl_buffer, pos, slave_latency);
|
||||
pos += 2;
|
||||
bt_store_16(acl_buffer, pos, timeout_multiplier);
|
||||
pos += 2;
|
||||
// 2 - ACL length
|
||||
bt_store_16(acl_buffer, 2, pos - 4);
|
||||
// 4 - L2CAP packet length
|
||||
bt_store_16(acl_buffer, 4, pos - 6 - 2);
|
||||
// 10 - L2CAP signaling parameter length
|
||||
bt_store_16(acl_buffer, 10, pos - 12);
|
||||
return pos;
|
||||
}
|
||||
|
||||
uint16_t l2cap_le_create_connection_parameter_update_response(uint8_t * acl_buffer, uint16_t handle, uint8_t identifier, uint16_t response){
|
||||
|
||||
int pb = hci_non_flushable_packet_boundary_flag_supported() ? 0x00 : 0x02;
|
||||
|
||||
// 0 - Connection handle : PB=pb : BC=00
|
||||
bt_store_16(acl_buffer, 0, handle | (pb << 12) | (0 << 14));
|
||||
// 6 - L2CAP LE Signaling channel = 5
|
||||
bt_store_16(acl_buffer, 6, 5);
|
||||
// 8 - Code
|
||||
acl_buffer[8] = CONNECTION_PARAMETER_UPDATE_RESPONSE;
|
||||
// 9 - id
|
||||
acl_buffer[9] = identifier;
|
||||
uint16_t pos = 12;
|
||||
bt_store_16(acl_buffer, pos, response);
|
||||
pos += 2;
|
||||
// 2 - ACL length
|
||||
bt_store_16(acl_buffer, 2, pos - 4);
|
||||
// 4 - L2CAP packet length
|
||||
bt_store_16(acl_buffer, 4, pos - 6 - 2);
|
||||
// 10 - L2CAP signaling parameter length
|
||||
bt_store_16(acl_buffer, 10, pos - 12);
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -65,15 +65,17 @@ typedef enum {
|
||||
ECHO_RESPONSE,
|
||||
INFORMATION_REQUEST,
|
||||
INFORMATION_RESPONSE,
|
||||
/* 0x0c - 0x11 used for AMP */
|
||||
CONNECTION_PARAMETER_UPDATE_REQUEST = 0x12,
|
||||
CONNECTION_PARAMETER_UPDATE_RESPONSE,
|
||||
COMMAND_REJECT_LE = 0x14, // internal to BTstack
|
||||
LE_CREDIT_BASED_CONNECTION_REQUEST,
|
||||
LE_CREDIT_BASED_CONNECTION_RESPONSE,
|
||||
LE_FLOW_CONTROL_CREDIT,
|
||||
COMMAND_REJECT_LE = 0x1F // internal to BTstack
|
||||
} L2CAP_SIGNALING_COMMANDS;
|
||||
|
||||
uint16_t l2cap_create_signaling_classic(uint8_t * acl_buffer,hci_con_handle_t handle, L2CAP_SIGNALING_COMMANDS cmd, uint8_t identifier, va_list argptr);
|
||||
uint16_t l2cap_create_signaling_le(uint8_t * acl_buffer, hci_con_handle_t handle, L2CAP_SIGNALING_COMMANDS cmd, uint8_t identifier, va_list argptr);
|
||||
uint16_t l2cap_le_create_connection_parameter_update_request(uint8_t * acl_buffer, uint16_t handle, uint8_t identifier, uint16_t interval_min, uint16_t interval_max, uint16_t slave_latency, uint16_t timeout_multiplier);
|
||||
uint16_t l2cap_le_create_connection_parameter_update_response(uint8_t * acl_buffer, uint16_t handle, uint8_t identifier, uint16_t response);
|
||||
uint8_t l2cap_next_sig_id(void);
|
||||
uint16_t l2cap_next_local_cid(void);
|
||||
|
||||
|
@ -637,6 +637,10 @@ int btstack_main(int argc, const char * argv[]){
|
||||
memcpy(current_pts_address, public_pts_address, 6);
|
||||
current_pts_address_type = public_pts_address_type;
|
||||
|
||||
// classic discoverable / connectable
|
||||
hci_connectable_control(1);
|
||||
hci_discoverable_control(1);
|
||||
|
||||
// allow foor terminal input
|
||||
btstack_stdin_setup(stdin_process);
|
||||
|
||||
|
@ -849,7 +849,7 @@ int stdin_process(struct data_source *ds){
|
||||
break;
|
||||
case 'z':
|
||||
printf("Sending l2cap connection update parameter request\n");
|
||||
l2cap_le_request_connection_parameter_update(handle, 50, 120, 0, 550);
|
||||
gap_request_connection_parameter_update(handle, 50, 120, 0, 550);
|
||||
break;
|
||||
case 'l':
|
||||
att_default_value_long = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user