From d04eb939af076fdf8632bde41960d10bbd2e76c1 Mon Sep 17 00:00:00 2001 From: Oliver Ruiz Dorantes Date: Wed, 9 Jul 2008 17:01:30 +0000 Subject: [PATCH] -Move the launching of the Local Device to an IOCTL from the open hook to be more compatible with the net_stack -Implement Launch method in the accesors regarding previous comment -Fix KDL at removing device git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26345 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/bluetooth/HCI/btHCI_transport.h | 11 ++-- .../bluetooth/h2/h2generic/h2generic.c | 65 ++++++++++--------- .../drivers/bluetooth/h2/h2generic/h2util.c | 4 +- src/servers/bluetooth/BluetoothServer.cpp | 3 + .../bluetooth/HCITransportAccessor.cpp | 3 +- src/servers/bluetooth/LocalDeviceHandler.cpp | 6 ++ src/servers/bluetooth/LocalDeviceHandler.h | 5 +- 7 files changed, 59 insertions(+), 38 deletions(-) diff --git a/headers/os/bluetooth/HCI/btHCI_transport.h b/headers/os/bluetooth/HCI/btHCI_transport.h index b25bd34ee6..c268ddc175 100644 --- a/headers/os/bluetooth/HCI/btHCI_transport.h +++ b/headers/os/bluetooth/HCI/btHCI_transport.h @@ -13,11 +13,11 @@ #include #include -typedef enum { ANCILLYANT = 1, - RUNNING, - LEAVING, - SENDING, - PROCESSING +typedef enum { ANCILLYANT = (1<<0), + RUNNING = (1<<1), + LEAVING = (1<<2), + SENDING = (1<<3), + PROCESSING = (1<<4) } bt_transport_status_t; typedef uint8 bt_stat_t; @@ -84,6 +84,7 @@ typedef struct bt_hci_device { enum { ISSUE_BT_COMMAND = B_DEVICE_OP_CODES_END + BT_IOCTLS_OFFSET , + BT_UP, GET_STATICS, GET_NOTIFICATION_PORT, GET_HCI_ID 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 394a18b7bb..00c5118a7e 100644 --- a/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.c +++ b/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.c @@ -429,8 +429,8 @@ device_open(const char *name, uint32 flags, void **cookie) } acquire_sem(bdev->lock); - // Set HCI_RUNNING - if ( TEST_AND_SET(&bdev->state, RUNNING) ) { + // Set RUNNING + if ( TEST_AND_SET(&bdev->state, ANCILLYANT) ) { flowf("dev already running! - reOpened device!\n"); return B_ERROR; } @@ -451,7 +451,7 @@ device_open(const char *name, uint32 flags, void **cookie) // dumping the USB frames init_room(&bdev->eventRoom); init_room(&bdev->aclRoom); - //Init_room(new_bt_dev->scoRoom); + //init_room(new_bt_dev->scoRoom); list_init(&bdev->snetBufferRecycleTrash); @@ -470,37 +470,15 @@ device_open(const char *name, uint32 flags, void **cookie) hdev = bdev->num; } bdev->hdev = hdev; - - // H: set the special flags - - // EVENTS - err = submit_rx_event(bdev); - if (err != B_OK) - goto unrun; -#if BT_DRIVER_SUPPORTS_ACL - // ACL - for (i = 0; i < MAX_ACL_IN_WINDOW; i++) { - err = submit_rx_acl(bdev); - if (err != B_OK && i == 0 ) - goto unrun; - } -#endif - -#if BT_DRIVER_SUPPORTS_SCO - // TODO: SCO / eSCO -#endif + + *cookie = bdev; release_sem(bdev->lock); flowf(" successful\n"); return B_OK; -unrun: - CLEAR_BIT(bdev->state, RUNNING); // Set the flaq in the HCI world - flowf("Queuing failed device stops running\n"); - - return err; } @@ -617,13 +595,42 @@ device_control(void *cookie, uint32 msg, void *params, size_t size) snb_put(snbuf, params, size); err = submit_tx_command(bdev, snbuf); - + debugf("device launched %ld\n", err); + break; + + case BT_UP: + + // EVENTS + err = submit_rx_event(bdev); + if (err != B_OK) { + CLEAR_BIT(bdev->state, ANCILLYANT); + flowf("Queuing failed device stops running\n"); + break; + } + + #if BT_DRIVER_SUPPORTS_ACL // ACL + for (i = 0; i < MAX_ACL_IN_WINDOW; i++) { + err = submit_rx_acl(bdev); + if (err != B_OK && i == 0 ) { + CLEAR_BIT(bdev->state, ANCILLYANT); // Set the flaq in the HCI world + flowf("Queuing failed device stops running\n"); + break; + } + } + #endif + + SET_BIT(bdev->state, RUNNING); + + #if BT_DRIVER_SUPPORTS_SCO + // TODO: SCO / eSCO + #endif + flowf("device launched\n"); break; case GET_STATICS: memcpy(params, &bdev->stat, sizeof(bt_hci_statistics)); err = B_OK; - break; + break; case GET_HCI_ID: *(hci_id*)params = bdev->hdev; 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 3bc3c86550..05c99a5445 100644 --- a/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2util.c +++ b/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2util.c @@ -62,12 +62,14 @@ fail: void nb_destroy(net_buffer* nbuf) { + if (nbuf == NULL) + return; /* Free possible allocated */ if (nbuf->COOKIEFIELD != NULL) free((void*)nbuf->COOKIEFIELD); -// TODO check for survivers... + // TODO check for survivers... if (nb != NULL) nb->free(nbuf); diff --git a/src/servers/bluetooth/BluetoothServer.cpp b/src/servers/bluetooth/BluetoothServer.cpp index 28854371fb..5ea9f73d71 100644 --- a/src/servers/bluetooth/BluetoothServer.cpp +++ b/src/servers/bluetooth/BluetoothServer.cpp @@ -135,6 +135,9 @@ void BluetoothServer::MessageReceived(BMessage *message) } status = B_WOULD_BLOCK; + + /* TODO: This should be by user request only! */ + ldi->Launch(); } case BT_MSG_COUNT_LOCAL_DEVICES: diff --git a/src/servers/bluetooth/HCITransportAccessor.cpp b/src/servers/bluetooth/HCITransportAccessor.cpp index 4d2314a5c4..169c57974f 100644 --- a/src/servers/bluetooth/HCITransportAccessor.cpp +++ b/src/servers/bluetooth/HCITransportAccessor.cpp @@ -38,6 +38,7 @@ printf("### \n"); status_t HCITransportAccessor::Launch() { - return B_OK; + uint32 dummy; + return ioctl(fFD, BT_UP, &dummy, sizeof(uint32)); } diff --git a/src/servers/bluetooth/LocalDeviceHandler.cpp b/src/servers/bluetooth/LocalDeviceHandler.cpp index 67c3ca1884..8f961b3b64 100644 --- a/src/servers/bluetooth/LocalDeviceHandler.cpp +++ b/src/servers/bluetooth/LocalDeviceHandler.cpp @@ -29,6 +29,12 @@ LocalDeviceHandler::GetID() return fHCIDelegate->GetID(); } +status_t +LocalDeviceHandler::Launch(void) +{ + return fHCIDelegate->Launch(); +} + bool LocalDeviceHandler::Available() { diff --git a/src/servers/bluetooth/LocalDeviceHandler.h b/src/servers/bluetooth/LocalDeviceHandler.h index 8ddc18da70..29079b6524 100644 --- a/src/servers/bluetooth/LocalDeviceHandler.h +++ b/src/servers/bluetooth/LocalDeviceHandler.h @@ -20,10 +20,11 @@ class LocalDeviceHandler { public: - virtual hci_id GetID(); + hci_id GetID(); - virtual bool Available(); + bool Available(); void Acquire(void); + status_t Launch(void); BMessage* GetPropertiesMessage(void) { return fProperties; } bool IsPropertyAvailable(const BString& property);