diff --git a/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2cfg.h b/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2cfg.h index 471fd61c17..241b4c1d32 100644 --- a/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2cfg.h +++ b/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2cfg.h @@ -11,9 +11,11 @@ #define BT_DRIVER_SUPPORTS_CMD 1 #define BT_DRIVER_SUPPORTS_EVT 1 -#define BT_DRIVER_SUPPORTS_ESCO 0 +#define BT_DRIVER_SUPPORTS_ACL 1 #define BT_DRIVER_SUPPORTS_SCO 0 -#define BT_DRIVER_SUPPORTS_ACL 0 +#define BT_DRIVER_SUPPORTS_ESCO 0 + + /* TODO: move exclusive header for drivers*/ #define BT_DRIVER_RXCOVERAGE (BT_DRIVER_SUPPORTS_EVT+BT_DRIVER_SUPPORTS_ACL+BT_DRIVER_SUPPORTS_SCO+BT_DRIVER_SUPPORTS_ESCO) @@ -24,7 +26,7 @@ #endif #define BT_SURVIVE_WITHOUT_HCI -#define BT_SURVIVE_WITHOUT_NET_BUFFERS +//#define BT_SURVIVE_WITHOUT_NET_BUFFERS //////////////////////////////////// diff --git a/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.c b/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.c index 8daf2fed83..d2afac2774 100644 --- a/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.c +++ b/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.c @@ -432,13 +432,13 @@ device_open(const char *name, uint32 flags, void **cookie) return B_ERROR; } - acquire_sem(bdev->lock); // Set RUNNING if ( TEST_AND_SET(&bdev->state, ANCILLYANT) ) { flowf("dev already running! - reOpened device!\n"); return B_ERROR; } + acquire_sem(bdev->lock); // TX structures for (i = 0; i < BT_DRIVER_TXCOVERAGE; i++) { list_init(&bdev->nbuffersTx[i]); @@ -476,11 +476,9 @@ device_open(const char *name, uint32 flags, void **cookie) } bdev->hdev = hdev; - - - *cookie = bdev; - release_sem(bdev->lock); + *cookie = bdev; + release_sem(bdev->lock); flowf(" successful\n"); return B_OK; @@ -573,8 +571,11 @@ device_control(void *cookie, uint32 msg, void *params, size_t size) status_t err = B_ERROR; bt_usb_dev* bdev = (bt_usb_dev*)cookie; snet_buffer* snbuf; + #if BT_DRIVER_SUPPORTS_ACL // ACL + int32 i; + #endif + TOUCH(size); - debugf("ioctl() opcode %ld size %ld.\n", msg, size); if (bdev == NULL) { @@ -752,7 +753,7 @@ err_release: err_release1: put_module(hci_name); err_release2: - put_module(hci_name); + put_module(btDevices_name); return B_ERROR; } diff --git a/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2transactions.c b/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2transactions.c index edc7826fb6..fa1ea6a6ac 100644 --- a/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2transactions.c +++ b/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2transactions.c @@ -39,8 +39,7 @@ void event_complete(void* cookie, status_t status, void* data, size_t actual_len static status_t assembly_rx(bt_usb_dev* bdev, bt_packet_t type, void *data, int count) -{ - +{ net_buffer* nbuf = NULL; snet_buffer* snbuf = NULL; @@ -56,8 +55,7 @@ assembly_rx(bt_usb_dev* bdev, bt_packet_t type, void *data, int count) while (count) { - debugf("count %d %p %p\n",count, nbuf, nb); - + debugf("count %d nb=%p sb=%p type=%d\n",count, nbuf, snbuf, type); if ( (type != BT_EVENT && nbuf == NULL) || (type == BT_EVENT && (snbuf == NULL || snb_completed(snbuf))) ) { @@ -70,7 +68,7 @@ assembly_rx(bt_usb_dev* bdev, bt_packet_t type, void *data, int count) struct hci_event_header* headerPkt = data; expectedPacketLen = HCI_EVENT_HDR_SIZE + headerPkt->elen; snbuf = bdev->eventRx = snb_fetch(&bdev->snetBufferRecycleTrash, expectedPacketLen); - + } else { flowf("EVENT frame corrupted\n"); return -EILSEQ; @@ -79,15 +77,22 @@ assembly_rx(bt_usb_dev* bdev, bt_packet_t type, void *data, int count) case BT_ACL: if (count >= HCI_ACL_HDR_SIZE) { - + int16 index; struct hci_acl_header* headerPkt = data; + expectedPacketLen = HCI_ACL_HDR_SIZE + B_LENDIAN_TO_HOST_INT16(headerPkt->alen); /* Create the buffer */ bdev->nbufferRx[type] = nbuf = nb->create(expectedPacketLen); + // TODO: this allocation can fail!! nbuf->protocol = type; - - + debugf("new ACL frame %p\n", nbuf); + debugf("### Incoming ACL: len = %d\n", count); + for (index = 0 ; index < count; index++ ) { + dprintf("%x:",((uint8*)data)[index]); + } + flowf("### \n"); + } else { flowf("ACL frame corrupted\n"); return -EILSEQ; @@ -100,21 +105,7 @@ assembly_rx(bt_usb_dev* bdev, bt_packet_t type, void *data, int count) default: panic("unkown packet type in assembly"); break; - } -#if 0 - if (nb == NULL) { - port_id port; - /* Coded for test purpose only we should panic here */ - debugf("net_buffers are not ready post manually %d/%d\n",count,expectedPacketLen); - port = find_port(BT_USERLAND_PORT_NAME); - if (port != B_NAME_NOT_FOUND) { - (void)write_port(port, PACK_HEADER_PORT(bdev->num,type), data, count); - return B_OK; - } - panic("Algorithm just ready to arrive here"); - return B_ERROR; - } -#endif + } currentPacketLen = expectedPacketLen; @@ -136,8 +127,7 @@ assembly_rx(bt_usb_dev* bdev, bt_packet_t type, void *data, int count) /* Complete frame? */ if (type == BT_EVENT && snb_completed(snbuf)) { - - flowf("Frame goes up!\n"); + post_packet_up(bdev, type, snbuf); snbuf = bdev->eventRx = NULL; @@ -145,10 +135,12 @@ assembly_rx(bt_usb_dev* bdev, bt_packet_t type, void *data, int count) if (type != BT_EVENT && (get_expected_size(nbuf) - nbuf->size) == 0 ) { - flowf("Frame goes up!\n"); post_packet_up(bdev, type, nbuf); bdev->nbufferRx[type] = nbuf = NULL; - } + } /*else { + if (type == BT_ACL) + debugf("ACL Packet not filled size=%ld expected=%ld\n", nbuf->size, get_expected_size(nbuf)); + }*/ /* in case in the pipe there is info about the next buffer ... */ count -= currentPacketLen; diff --git a/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2upper.c b/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2upper.c index d3e644db96..d4dc3a8353 100644 --- a/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2upper.c +++ b/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2upper.c @@ -11,6 +11,7 @@ #include #include +#include "h2generic.h" #include "h2upper.h" #include "h2transactions.h" #include "snet_buffer.h" @@ -89,6 +90,8 @@ post_packet_up(bt_usb_dev* bdev, bt_packet_t type, void* buf) status_t err = B_OK; port_id port; + + debugf("Frame up type=%d\n", type); if (hci == NULL) { @@ -99,22 +102,28 @@ post_packet_up(bt_usb_dev* bdev, bt_packet_t type, void* buf) snet_buffer* snbuf = (snet_buffer*) buf; - flowf("HCI not present, Posting to userland\n"); + flowf("HCI not present for event, Posting to userland\n"); port = find_port(BT_USERLAND_PORT_NAME); if (port != B_NAME_NOT_FOUND) { - - err = write_port_etc(port, PACK_PORTCODE(type,bdev->hdev, -1), + err = write_port_etc(port, PACK_PORTCODE(type,bdev->hdev, -1), snb_get(snbuf), snb_size(snbuf), B_TIMEOUT, 1*1000*1000); - if (err != B_OK) + if (err != B_OK) debugf("Error posting userland %s\n", strerror(err)); + snb_park(&bdev->snetBufferRecycleTrash, snbuf); + } else { flowf("ERROR:bluetooth_server not found for posting\n"); err = B_NAME_NOT_FOUND; } - /* No need to free the buffer at allocation is gonna be reused */ + } else { + net_buffer* nbuf = (net_buffer*) buf; + /* No need to free the buffer at allocation is gonna be reused */ + flowf("HCI not present for acl posting to net_device\n"); + btDevices->receive_data(bdev->ndev, &nbuf); + } } else { @@ -126,6 +135,7 @@ post_packet_up(bt_usb_dev* bdev, bt_packet_t type, void* buf) return err; } + status_t send_packet(hci_id hid, bt_packet_t type, net_buffer* nbuf) { @@ -146,7 +156,6 @@ send_packet(hci_id hid, bt_packet_t type, net_buffer* nbuf) case BT_COMMAND: case BT_ACL: case BT_SCO: - list_add_item(&bdev->nbuffersTx[type],nbuf); bdev->nbuffersPendingTx[type]++; break; diff --git a/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2util.c b/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2util.c index 05c99a5445..b2cda41b7b 100644 --- a/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2util.c +++ b/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2util.c @@ -24,19 +24,17 @@ nb_get_whole_buffer(net_buffer* nbuf) { void* conPointer; status_t err; - +#if 0 /* the job could be already done */ // !!! it could be trash from other upper protocols... if (nbuf->COOKIEFIELD != NULL) return (void*)nbuf->COOKIEFIELD; - - if (nb == NULL) - goto fail; - +#endif err = nb->direct_access(nbuf, 0, nbuf->size, &conPointer); if (err != B_OK) { - + panic("I expected to be contiguous:("); + #if 0 /* pity, we are gonna need a realocation */ nbuf->COOKIEFIELD = (uint32) malloc(nbuf->size); if (nbuf->COOKIEFIELD == NULL) @@ -47,15 +45,16 @@ nb_get_whole_buffer(net_buffer* nbuf) goto free; conPointer = (void*)nbuf->COOKIEFIELD; - + #endif } return conPointer; - +#if 0 free: free((void*) nbuf->COOKIEFIELD); fail: return NULL; +#endif } @@ -64,11 +63,11 @@ nb_destroy(net_buffer* nbuf) { if (nbuf == NULL) return; - +#if 0 /* Free possible allocated */ if (nbuf->COOKIEFIELD != NULL) free((void*)nbuf->COOKIEFIELD); - +#endif // TODO check for survivers... if (nb != NULL) nb->free(nbuf); @@ -88,21 +87,20 @@ get_expected_size(net_buffer* nbuf) case BT_ACL: { struct hci_acl_header* header = nb_get_whole_buffer(nbuf); - return header->alen; + return header->alen + sizeof(struct hci_acl_header); } case BT_COMMAND: { struct hci_command_header* header = nb_get_whole_buffer(nbuf); - return header->clen; + return header->clen + sizeof(struct hci_command_header); } - case BT_EVENT: { struct hci_event_header* header = nb_get_whole_buffer(nbuf); - return header->elen; + return header->elen + sizeof(struct hci_event_header); } default: - + panic("h2geneirc:no protocol specifiel for get expected size"); break; }