Merge branch 'master' into ble-api-cleanup

This commit is contained in:
Matthias Ringwald 2016-01-28 15:04:34 +01:00
commit 787071125c
5 changed files with 37 additions and 7 deletions

View File

@ -1,7 +1,12 @@
/**
* Arduino Wrapper for BTstack
*/
#pragma once
#ifndef __ARDUINO_BTSTACK_H
#define __ARDUINO_BTSTACK_H
#if defined __cplusplus
extern "C" {
#endif
#include "ble/att.h"
#include "btstack_util.h"
@ -187,4 +192,10 @@ public:
uint16_t addGATTCharacteristicDynamic(UUID * uuid, uint16_t flags, uint16_t characteristic_id);
};
extern BTstackManager BTstack;
extern BTstackManager BTstack;
#if defined __cplusplus
}
#endif
#endif // __ARDUINO_BTSTACK_H

View File

@ -91,7 +91,7 @@ int main(int argc, const char * argv[]){
hci_dump_open("/tmp/hci_dump.pklg", HCI_DUMP_PACKETLOGGER);
// init HCI
cosnt hci_transport_t * transport = hci_transport_usb_instance();
const hci_transport_t * transport = hci_transport_usb_instance();
remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_fs;
hci_init(transport, NULL, remote_db);

View File

@ -1924,6 +1924,10 @@ int rfcomm_send_prepared(uint16_t rfcomm_cid, uint16_t len){
int err = rfcomm_assert_send_valid(channel, len);
if (err) return err;
if (l2cap_can_send_prepared_packet_now(channel->multiplexer->l2cap_cid)){
log_error("rfcomm_send_prepared: l2cap cannot send now");
return BTSTACK_ACL_BUFFERS_FULL;
}
// send might cause l2cap to emit new credits, update counters first
channel->credits_outgoing--;
@ -1932,10 +1936,10 @@ int rfcomm_send_prepared(uint16_t rfcomm_cid, uint16_t len){
if (result != 0) {
channel->credits_outgoing++;
log_info("rfcomm_send: error %d", result);
log_error("rfcomm_send_prepared: error %d", result);
return result;
}
return result;
}
@ -1948,11 +1952,19 @@ int rfcomm_send(uint16_t rfcomm_cid, uint8_t *data, uint16_t len){
int err = rfcomm_assert_send_valid(channel, len);
if (err) return err;
if (l2cap_can_send_packet_now(channel->multiplexer->l2cap_cid)){
log_error("rfcomm_send_internal: l2cap cannot send now");
return BTSTACK_ACL_BUFFERS_FULL;
}
rfcomm_reserve_packet_buffer();
uint8_t * rfcomm_payload = rfcomm_get_outgoing_buffer();
memcpy(rfcomm_payload, data, len);
return rfcomm_send_prepared(rfcomm_cid, len);
err = rfcomm_send_prepared(rfcomm_cid, len);
if (err){
rfcomm_release_packet_buffer();
}
return err;
}
// Sends Local Lnie Status, see LINE_STATUS_..

View File

@ -205,6 +205,12 @@ int l2cap_can_send_packet_now(uint16_t local_cid){
return hci_can_send_acl_packet_now(channel->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;
return hci_can_send_prepared_acl_packet_now(channel->handle);
}
int l2cap_can_send_fixed_channel_packet_now(uint16_t handle){
return hci_can_send_acl_packet_now(handle);
}

View File

@ -162,7 +162,7 @@ typedef struct l2cap_signaling_response {
} l2cap_signaling_response_t;
// internal use
int l2cap_can_send_fixed_channel_packet_now(uint16_t handle);
void l2cap_register_fixed_channel(btstack_packet_handler_t packet_handler, uint16_t channel_id);
int l2cap_send_connectionless(uint16_t handle, uint16_t cid, uint8_t *data, uint16_t len);
@ -244,6 +244,7 @@ void l2cap_decline_connection(uint16_t local_cid, uint8_t reason);
* @brief Check if outgoing buffer is available and that there's space on the Bluetooth module
*/
int l2cap_can_send_packet_now(uint16_t local_cid);
int l2cap_can_send_prepared_packet_now(uint16_t local_cid);
/**
* @brief Reserve outgoing buffer