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 7f842965bb..8daf2fed83 100644 --- a/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.c +++ b/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.c @@ -22,11 +22,9 @@ #include #define BT_DEBUG_THIS_MODULE - #define MODULE_NAME "BT" #define SUBMODULE_NAME BLUETOOTH_DEVICE_DEVFS_NAME #define SUBMODULE_COLOR 31 - #include #include "h2generic.h" @@ -41,8 +39,13 @@ int32 api_version = B_CUR_DRIVER_API_VERSION; static char* usb_name = B_USB_MODULE_NAME; static char* hci_name = BT_HCI_MODULE_NAME; +#define NET_BLUETOOTH_DEVICE_NAME "network/devices/bluetooth/v1" //move out!! +static char* btDevices_name = NET_BLUETOOTH_DEVICE_NAME; + + usb_module_info *usb = NULL; bt_hci_module_info *hci = NULL; +struct net_device_module_info* btDevices; struct net_buffer_module_info *nb = NULL; /* Driver Global data */ @@ -457,19 +460,21 @@ device_open(const char *name, uint32 flags, void **cookie) list_init(&bdev->snetBufferRecycleTrash); // Allocate set and register the HCI device - if (hci != NULL) { + if (btDevices != NULL) { + struct net_device* ndev; // TODO: Fill the transport descriptor - hci->RegisterDriver(&bt_usb_hooks, &hdev, (void*)bdev); + err = btDevices->init_device(bdev->name, &ndev); - if ( err != B_OK ) - { - flowf("Impossible to register a hci device.\n"); - hdev = bdev->num; /* XXX: Lets try to go on*/ - } + if ( err == B_OK ) { + hdev = ndev->index; + bdev->ndev = ndev; + } else + hdev = bdev->num; /* XXX: Lets try to go on*/ } else { - hdev = bdev->num; + hdev = bdev->num; /* XXX: Lets try to go on*/ } + bdev->hdev = hdev; @@ -521,8 +526,8 @@ device_close(void *cookie) purge_room(&bdev->aclRoom); /* Device no longer in our Stack*/ - if (hci != NULL) - hci->UnregisterDriver(bdev->hdev); + if (btDevices != NULL) + btDevices->uninit_device(bdev->ndev); // unSet RUNNING if (TEST_AND_CLEAR(&bdev->state, RUNNING)) { @@ -687,31 +692,42 @@ init_driver(void) int j; flowf("init_driver()\n"); + + // BT devices MODULE INITS + if (get_module(btDevices_name,(module_info**)&btDevices) != B_OK) { + debugf("cannot get module \"%s\"\n", btDevices_name); + return B_ERROR; + } else + debugf("btDevices module at %p\n", btDevices); + + // HCI MODULE INITS if (get_module(hci_name,(module_info**)&hci) != B_OK) { debugf("cannot get module \"%s\"\n", hci_name); #ifndef BT_SURVIVE_WITHOUT_HCI - return B_ERROR; + return err_release2; #endif + } else { + debugf("hci module at %p\n", hci); } - debugf("hci module at %p\n", hci); - + // USB MODULE INITS if (get_module(usb_name,(module_info**)&usb) != B_OK) { debugf("cannot get module \"%s\"\n", usb_name); - goto err_release; + goto err_release1; + } else { + debugf("usb module at %p\n", usb); } - debugf("usb module at %p\n", usb); - if (get_module(NET_BUFFER_MODULE_NAME,(module_info**)&nb) != B_OK) { debugf("cannot get module \"%s\"\n", NET_BUFFER_MODULE_NAME); #ifndef BT_SURVIVE_WITHOUT_NET_BUFFERS goto err_release; #endif + } else { + debugf("nb module at %p\n", nb); } - debugf("nb module at %p\n", nb); - + // GENERAL INITS dev_table_sem = create_sem(1, BLUETOOTH_DEVICE_DEVFS_NAME "dev_table_lock"); if (dev_table_sem < 0) { @@ -729,9 +745,13 @@ init_driver(void) return B_OK; -err: // Releasing +err: // Releasing + put_module(NET_BUFFER_MODULE_NAME); +err_release: put_module(usb_name); -err_release: +err_release1: + put_module(hci_name); +err_release2: put_module(hci_name); return B_ERROR; } diff --git a/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.h b/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.h index 310096ee3f..86dcfc1c98 100644 --- a/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.h +++ b/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.h @@ -8,6 +8,9 @@ #ifndef _H2GENERIC_H_ #define _H2GENERIC_H_ +#include +#include + #include #include @@ -15,8 +18,6 @@ #include #include -#include - #include "snet_buffer.h" /* USB definitions for the generic device*/ @@ -28,8 +29,6 @@ #define BLUETOOTH_DEVICE_NAME "generic" #include "h2cfg.h" -//#define ID DEVICE_NAME ": " /* prefix for debug messages */ - #define USB_TYPE_CLASS (0x01 << 5) /// Check if it is in some other header #define USB_TYPE_VENDOR (0x02 << 5) @@ -39,6 +38,7 @@ extern usb_module_info* usb; extern bt_hci_module_info* hci; +extern struct net_device_module_info* btDevices; extern struct net_buffer_module_info* nb; #define MAX_COMMAND_WINDOW 1 @@ -53,6 +53,7 @@ typedef struct bt_usb_dev bt_usb_dev; struct bt_usb_dev { const usb_device* dev; /* opaque handle */ hci_id hdev; /* HCI device id*/ + struct net_device* ndev; char name[B_OS_NAME_LENGTH]; bool connected; /* is the device plugged into the USB? */ diff --git a/src/add-ons/kernel/network/devices/Jamfile b/src/add-ons/kernel/network/devices/Jamfile index a6c6e26851..00a9a24769 100644 --- a/src/add-ons/kernel/network/devices/Jamfile +++ b/src/add-ons/kernel/network/devices/Jamfile @@ -2,3 +2,4 @@ SubDir HAIKU_TOP src add-ons kernel network devices ; SubInclude HAIKU_TOP src add-ons kernel network devices ethernet ; SubInclude HAIKU_TOP src add-ons kernel network devices loopback ; +SubInclude HAIKU_TOP src add-ons kernel network devices bluetooth ; diff --git a/src/add-ons/kernel/network/devices/bluetooth/bluetooth.cpp b/src/add-ons/kernel/network/devices/bluetooth/bluetooth.cpp index 09b06ad42e..902939ad90 100644 --- a/src/add-ons/kernel/network/devices/bluetooth/bluetooth.cpp +++ b/src/add-ons/kernel/network/devices/bluetooth/bluetooth.cpp @@ -28,6 +28,8 @@ #include #define BT_DEBUG_THIS_MODULE +#define SUBMODULE_NAME "bluetooth_device" +#define SUBMODULE_COLOR 34 #include @@ -49,10 +51,10 @@ static sem_id sLinkChangeSemaphore; status_t bluetooth_init(const char *name, net_device **_device) { - debugf("Inidializing bluetooth device %s\n",name); + debugf("Initializing bluetooth device %s\n",name); - // make sure this is a device in /dev/bluetooth - if (strncmp(name, "/dev/bluetooth/", 15)) + // TODO: make sure this is a device in /dev/bluetooth + if (strncmp(name, "bluetooth/h", 11)) return B_BAD_VALUE; if (gBufferModule == NULL) { // lazy allocation @@ -73,12 +75,17 @@ bluetooth_init(const char *name, net_device **_device) strcpy(device->name, name); MutexLocker _(&sListLock); - - device->index = (sDeviceList.Tail())->index + 1; // TODO: index will be assigned by netstack + + if (sDeviceList.IsEmpty()) + device->index = 0x0000007C; // REVIEW: dev index + else + device->index = (sDeviceList.Tail())->index + 1; // TODO: index will be assigned by netstack // TODO: add to list whould be done in up hook sDeviceList.Add(device); + debugf("Device %s %x\n", device->name, device->index ); + *_device = device; return B_OK; } @@ -89,7 +96,7 @@ bluetooth_uninit(net_device *_device) { bluetooth_device *device = (bluetooth_device *)_device; - debugf("index %ld\n",device->index); + debugf("index %x\n",device->index); // if the device is still part of the list, remove it if (device->GetDoublyLinkedListLink()->next != NULL @@ -241,6 +248,23 @@ bluetooth_remove_multicast(struct net_device *_device, const sockaddr *_address) } + +static int +dump_bluetooth_devices(int argc, char** argv) +{ + bluetooth_device* device; + + DoublyLinkedList::Iterator iterator = sDeviceList.GetIterator(); + while (iterator.HasNext()) { + + device = iterator.Next(); + kprintf("\tname=%s index=%#x\n",device->name, device->index); + } + + return 0; +} + + static status_t bluetooth_std_ops(int32 op, ...) { @@ -266,6 +290,8 @@ bluetooth_std_ops(int32 op, ...) mutex_init(&sListLock, "bluetooth devices"); + add_debugger_command("btLocalDevices", &dump_bluetooth_devices, "Lists Bluetooth LocalDevices registered in the Stack"); + return B_OK; } @@ -275,6 +301,9 @@ bluetooth_std_ops(int32 op, ...) mutex_destroy(&sListLock); put_module(NET_STACK_MODULE_NAME); + + remove_debugger_command("btLocalDevices", &dump_bluetooth_devices); + return B_OK; }