Merge branch 'develop' of https://github.com/bluekitchen/btstack into develop

This commit is contained in:
Milanka Ringwald 2016-04-01 14:31:24 +02:00
commit 66a3021620
9 changed files with 66 additions and 48 deletions

View File

@ -105,11 +105,7 @@ void att_dispatch_register_server(btstack_packet_handler_t packet_handler){
* @param handle
*/
int att_dispatch_client_can_send_now(hci_con_handle_t con_handle){
int res = l2cap_can_send_fixed_channel_packet_now(con_handle, L2CAP_CID_ATTRIBUTE_PROTOCOL);
if (!res){
att_client_waiting_for_can_send =1;
}
return res;
return l2cap_can_send_fixed_channel_packet_now(con_handle, L2CAP_CID_ATTRIBUTE_PROTOCOL);
}
/**
@ -117,9 +113,27 @@ int att_dispatch_client_can_send_now(hci_con_handle_t con_handle){
* @param handle
*/
int att_dispatch_server_can_send_now(hci_con_handle_t con_handle){
int res = l2cap_can_send_fixed_channel_packet_now(con_handle, L2CAP_CID_ATTRIBUTE_PROTOCOL);
if (!res){
att_server_waiting_for_can_send =1;
}
return res;
return l2cap_can_send_fixed_channel_packet_now(con_handle, L2CAP_CID_ATTRIBUTE_PROTOCOL);
}
/**
* @brief Request emission of L2CAP_EVENT_CAN_SEND_NOW as soon as possible for client
* @note L2CAP_EVENT_CAN_SEND_NOW might be emitted during call to this function
* so packet handler should be ready to handle it
* @param con_handle
*/
void att_dispatch_client_request_can_send_now_event(hci_con_handle_t con_handle){
att_client_waiting_for_can_send = 1;
l2cap_request_can_send_fix_channel_now_event(con_handle, L2CAP_CID_ATTRIBUTE_PROTOCOL);
}
/**
* @brief Request emission of L2CAP_EVENT_CAN_SEND_NOW as soon as possible for server
* @note L2CAP_EVENT_CAN_SEND_NOW might be emitted during call to this function
* so packet handler should be ready to handle it
* @param con_handle
*/
void att_dispatch_server_request_can_send_now_event(hci_con_handle_t con_handle){
att_server_waiting_for_can_send = 1;
l2cap_request_can_send_fix_channel_now_event(con_handle, L2CAP_CID_ATTRIBUTE_PROTOCOL);
}

View File

@ -73,6 +73,21 @@ int att_dispatch_client_can_send_now(hci_con_handle_t con_handle);
*/
int att_dispatch_server_can_send_now(hci_con_handle_t con_handle);
/**
* @brief Request emission of L2CAP_EVENT_CAN_SEND_NOW as soon as possible for client
* @note L2CAP_EVENT_CAN_SEND_NOW might be emitted during call to this function
* so packet handler should be ready to handle it
* @param con_handle
*/
void att_dispatch_client_request_can_send_now_event(hci_con_handle_t con_handle);
/**
* @brief Request emission of L2CAP_EVENT_CAN_SEND_NOW as soon as possible for server
* @note L2CAP_EVENT_CAN_SEND_NOW might be emitted during call to this function
* so packet handler should be ready to handle it
* @param con_handle
*/
void att_dispatch_server_request_can_send_now_event(hci_con_handle_t con_handle);
#if defined __cplusplus
}

View File

@ -415,16 +415,12 @@ void att_server_register_packet_handler(btstack_packet_handler_t handler){
int att_server_can_send_packet_now(void){
if (att_connection.con_handle == 0) return 0;
int can_send = att_dispatch_server_can_send_now(att_connection.con_handle);
if (!can_send){
att_client_waiting_for_can_send = 1;
}
return can_send;
return att_dispatch_server_can_send_now(att_connection.con_handle);
}
void att_server_request_can_send_now_event(){
att_client_waiting_for_can_send = 1;
att_server_notify_can_send();
att_dispatch_server_request_can_send_now_event(att_connection.con_handle);
}
int att_server_notify(uint16_t attribute_handle, uint8_t *value, uint16_t value_len){

View File

@ -378,13 +378,7 @@ int bnep_can_send_packet_now(uint16_t bnep_cid)
return 0;
}
int can_send = l2cap_can_send_packet_now(channel->l2cap_cid);
if (!can_send){
channel->waiting_for_can_send_now = 1;
}
return can_send;
return l2cap_can_send_packet_now(channel->l2cap_cid);
}
void bnep_request_can_send_now_event(uint16_t bnep_cid)

View File

@ -1934,11 +1934,7 @@ int rfcomm_can_send_packet_now(uint16_t rfcomm_cid){
log_error("rfcomm_send cid 0x%02x doesn't exist!", rfcomm_cid);
return 0;
}
int res = rfcomm_channel_can_send(channel);
if (!res){
channel->waiting_for_can_send_now = 1;
}
return res;
return rfcomm_channel_can_send(channel);
}
void rfcomm_request_can_send_now_event(uint16_t rfcomm_cid){

View File

@ -320,7 +320,6 @@ void rfcomm_grant_credits(uint16_t rfcomm_cid, uint8_t credits);
/**
* @brief Checks if RFCOMM can send packet.
* @note If packet cannot be sent now, a RFCOMM_EVENT_CAN_SEND_NOW will be emitted later
* @param rfcomm_cid
* @result != 0 if can send now
*/

View File

@ -246,6 +246,8 @@ static l2cap_channel_t * l2cap_get_channel_for_local_cid(uint16_t local_cid){
return NULL;
}
///
void l2cap_request_can_send_now_event(uint16_t local_cid){
l2cap_channel_t *channel = l2cap_get_channel_for_local_cid(local_cid);
if (!channel) return;
@ -253,37 +255,33 @@ void l2cap_request_can_send_now_event(uint16_t local_cid){
l2cap_notify_channel_can_send();
}
void l2cap_request_can_send_fix_channel_now_event(hci_con_handle_t con_handle, uint16_t channel_id){
int index = l2cap_fixed_channel_table_index_for_channel_id(channel_id);
if (index < 0) return;
fixed_channels[index].waiting_for_can_send_now = 1;
l2cap_notify_channel_can_send();
}
///
int l2cap_can_send_packet_now(uint16_t local_cid){
l2cap_channel_t *channel = l2cap_get_channel_for_local_cid(local_cid);
if (!channel) return 0;
int can_send = hci_can_send_acl_packet_now(channel->con_handle);
if (!can_send){
channel->waiting_for_can_send_now = 1;
}
return can_send;
return hci_can_send_acl_packet_now(channel->con_handle);
}
int l2cap_can_send_prepared_packet_now(uint16_t local_cid){
l2cap_channel_t *channel = l2cap_get_channel_for_local_cid(local_cid);
if (!channel) return 0;
int can_send = hci_can_send_prepared_acl_packet_now(channel->con_handle);
if (!can_send){
channel->waiting_for_can_send_now = 1;
}
return can_send;
return hci_can_send_prepared_acl_packet_now(channel->con_handle);
}
int l2cap_can_send_fixed_channel_packet_now(hci_con_handle_t con_handle, uint16_t channel_id){
int can_send = hci_can_send_acl_packet_now(con_handle);
if (!can_send){
int index = l2cap_fixed_channel_table_index_for_channel_id(channel_id);
if (index >= 0){
fixed_channels[index].waiting_for_can_send_now = 1;
}
}
return can_send;
return hci_can_send_acl_packet_now(con_handle);
}
///
uint16_t l2cap_get_remote_mtu_for_local_cid(uint16_t local_cid){
l2cap_channel_t * channel = l2cap_get_channel_for_local_cid(local_cid);
if (channel) {

View File

@ -167,6 +167,7 @@ typedef struct l2cap_signaling_response {
void l2cap_register_fixed_channel(btstack_packet_handler_t packet_handler, uint16_t channel_id);
int l2cap_can_send_fixed_channel_packet_now(hci_con_handle_t con_handle, uint16_t channel_id);
void l2cap_request_can_send_fix_channel_now_event(hci_con_handle_t con_handle, uint16_t channel_id);
int l2cap_send_connectionless(hci_con_handle_t con_handle, uint16_t cid, uint8_t *data, uint16_t len);
int l2cap_send_prepared_connectionless(hci_con_handle_t con_handle, uint16_t cid, uint16_t len);

View File

@ -25,7 +25,7 @@ uint16_t get_gatt_client_handle(void){
void mock_simulate_command_complete(const hci_cmd_t *cmd){
uint8_t packet[] = {HCI_EVENT_COMMAND_COMPLETE, 4, 1, (uint8_t) (cmd->opcode & 0xff), (uint8_t) (cmd->opcode >> 8), 0};
registered_hci_event_handler(HCI_EVENT_PACKET, NULL, (uint8_t *)&packet, sizeof(packet));
registered_hci_event_handler(HCI_EVENT_PACKET, 0, (uint8_t *)&packet, sizeof(packet));
}
void mock_simulate_hci_state_working(void){
@ -102,6 +102,11 @@ int l2cap_can_send_fixed_channel_packet_now(uint16_t handle, uint16_t channel_id
return 1;
}
void l2cap_request_can_send_fix_channel_now_event(uint16_t handle, uint16_t channel_id){
uint8_t event[] = { L2CAP_EVENT_CAN_SEND_NOW, 2, 1, 0};
att_packet_handler(HCI_EVENT_PACKET, 0, (uint8_t*)event, sizeof(event));
}
int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t len){
att_connection_t att_connection;
att_init_connection(&att_connection);