hci_transport_h4: make HCI_OUTGOING_PRE_BUFFER_SIZE mandatory

This commit is contained in:
Matthias Ringwald 2015-12-18 19:56:02 +01:00
parent 8888c76903
commit 0a5fa5b3cb

View File

@ -56,6 +56,11 @@
#include "hci.h"
#include "hci_transport.h"
// assert pre-buffer for packet type is available
#if !defined(HCI_OUTGOING_PRE_BUFFER_SIZE) || (HCI_OUTGOING_PRE_BUFFER_SIZE == 0)
#error HCI_OUTGOING_PRE_BUFFER_SIZE not defined. Please update hci.h
#endif
static int h4_process(struct data_source *ds);
static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size);
static hci_uart_config_t *hci_uart_config;
@ -206,23 +211,13 @@ static int h4_send_packet(uint8_t packet_type, uint8_t * packet, int size){
if (hci_transport_h4->ds == NULL) return -1;
if (hci_transport_h4->uart_fd == 0) return -1;
// store packet type before actual data and increase size
char *data = (char*) packet;
int bytes_written;
#if HCI_OUTGOING_PRE_BUFFER_SIZE > 0
// just store packet type before actual data and increase size
size++;
data--;
*data = packet_type;
#else
// write out single byte
bytes_written = write(hci_transport_h4->uart_fd, &packet_type, 1);
while (bytes_written < 1) {
usleep(5000);
bytes_written = write(hci_transport_h4->uart_fd, &packet_type, 1);
};
#endif
while (size > 0) {
bytes_written = write(hci_transport_h4->uart_fd, data, size);
int bytes_written = write(hci_transport_h4->uart_fd, data, size);
if (bytes_written < 0) {
usleep(5000);
continue;