Fix gcc4 build (using __FUNCTION__), and more whitespaces cleanups...

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26804 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Ruiz Dorantes
2008-08-04 20:13:03 +00:00
parent 859039e124
commit 5c78f79f3a
3 changed files with 174 additions and 174 deletions
@@ -65,7 +65,7 @@ usb_support_descriptor supported_devices[] =
/* Broadcom BCM2035 */ /* Broadcom BCM2035 */
{ 0, 0, 0, 0x0a5c, 0x200a }, { 0, 0, 0, 0x0a5c, 0x200a },
{ 0, 0, 0, 0x0a5c, 0x2009 }, { 0, 0, 0, 0x0a5c, 0x2009 },
/* Devices taken from the linux Driver */ /* Devices taken from the linux Driver */
/* AVM BlueFRITZ! USB v2.0 */ /* AVM BlueFRITZ! USB v2.0 */
{ 0, 0, 0, 0x057c , 0x3800 }, { 0, 0, 0, 0x057c , 0x3800 },
@@ -76,15 +76,15 @@ usb_support_descriptor supported_devices[] =
{ 0, 0, 0, 0x044e , 0x3002 }, { 0, 0, 0, 0x044e , 0x3002 },
/* Ericsson with non-standard id */ /* Ericsson with non-standard id */
{ 0, 0, 0, 0x0bdb , 0x1002 } { 0, 0, 0, 0x0bdb , 0x1002 }
}; };
/* add a device to the list of connected devices */ /* add a device to the list of connected devices */
static bt_usb_dev* static bt_usb_dev*
spawn_device(const usb_device* usb_dev) spawn_device(const usb_device* usb_dev)
{ {
int32 i; int32 i;
status_t err = B_OK; status_t err = B_OK;
bt_usb_dev* new_bt_dev = NULL; bt_usb_dev* new_bt_dev = NULL;
flowf("add_device()\n"); flowf("add_device()\n");
@@ -93,7 +93,7 @@ spawn_device(const usb_device* usb_dev)
flowf("device table full\n"); flowf("device table full\n");
goto exit; goto exit;
} }
/* try the allocation */ /* try the allocation */
new_bt_dev = (bt_usb_dev*)malloc(sizeof(bt_usb_dev)); new_bt_dev = (bt_usb_dev*)malloc(sizeof(bt_usb_dev));
if ( new_bt_dev == NULL ) { if ( new_bt_dev == NULL ) {
@@ -116,18 +116,18 @@ spawn_device(const usb_device* usb_dev)
goto bail1; goto bail1;
} }
/* find a free slot and fill out the name */ /* find a free slot and fill out the name */
acquire_sem(dev_table_sem); acquire_sem(dev_table_sem);
for (i = 0; i < MAX_BT_GENERIC_USB_DEVICES; i++) { for (i = 0; i < MAX_BT_GENERIC_USB_DEVICES; i++) {
if (bt_usb_devices[i] == NULL) { if (bt_usb_devices[i] == NULL) {
bt_usb_devices[i] = new_bt_dev; bt_usb_devices[i] = new_bt_dev;
sprintf(new_bt_dev->name, "%s/%ld", BLUETOOTH_DEVICE_PATH, i); sprintf(new_bt_dev->name, "%s/%ld", BLUETOOTH_DEVICE_PATH, i);
new_bt_dev->num = i; new_bt_dev->num = i;
debugf("added device %p %ld %s\n", bt_usb_devices[i] ,new_bt_dev->num,new_bt_dev->name); debugf("added device %p %ld %s\n", bt_usb_devices[i] ,new_bt_dev->num,new_bt_dev->name);
break; break;
} }
} }
release_sem_etc(dev_table_sem, 1, B_DO_NOT_RESCHEDULE); release_sem_etc(dev_table_sem, 1, B_DO_NOT_RESCHEDULE);
/* In the case we cannot us */ /* In the case we cannot us */
if (bt_usb_devices[i] != new_bt_dev) { if (bt_usb_devices[i] != new_bt_dev) {
@@ -148,7 +148,7 @@ bail1:
delete_sem(new_bt_dev->cmd_complete); delete_sem(new_bt_dev->cmd_complete);
bail0: bail0:
free(new_bt_dev); free(new_bt_dev);
exit: exit:
return new_bt_dev; return new_bt_dev;
} }
@@ -159,13 +159,13 @@ kill_device(bt_usb_dev* bdev)
{ {
if (bdev != NULL) { if (bdev != NULL) {
debugf("(%p)\n", bdev); debugf("(%p)\n", bdev);
delete_sem(bdev->lock); delete_sem(bdev->lock);
delete_sem(bdev->cmd_complete); delete_sem(bdev->cmd_complete);
// mark it free // mark it free
bt_usb_devices[bdev->num] = NULL; bt_usb_devices[bdev->num] = NULL;
free(bdev); free(bdev);
dev_count--; dev_count--;
} }
@@ -176,38 +176,38 @@ bt_usb_dev*
fetch_device(bt_usb_dev* dev, hci_id hid) fetch_device(bt_usb_dev* dev, hci_id hid)
{ {
int i; int i;
debugf("(%p)\n", dev); debugf("(%p)\n", dev);
acquire_sem(dev_table_sem); acquire_sem(dev_table_sem);
if (dev != NULL) if (dev != NULL)
for (i = 0; i < MAX_BT_GENERIC_USB_DEVICES; i++) { for (i = 0; i < MAX_BT_GENERIC_USB_DEVICES; i++) {
/* somehow the device is still around */ /* somehow the device is still around */
if (bt_usb_devices[i] == dev) { if (bt_usb_devices[i] == dev) {
release_sem_etc(dev_table_sem, 1, B_DO_NOT_RESCHEDULE); release_sem_etc(dev_table_sem, 1, B_DO_NOT_RESCHEDULE);
return bt_usb_devices[i]; return bt_usb_devices[i];
} }
} }
else else
for (i = 0; i < MAX_BT_GENERIC_USB_DEVICES; i++) { for (i = 0; i < MAX_BT_GENERIC_USB_DEVICES; i++) {
/* somehow the device is still around */ /* somehow the device is still around */
if (bt_usb_devices[i] != NULL && bt_usb_devices[i]->hdev == hid) { if (bt_usb_devices[i] != NULL && bt_usb_devices[i]->hdev == hid) {
release_sem_etc(dev_table_sem, 1, B_DO_NOT_RESCHEDULE); release_sem_etc(dev_table_sem, 1, B_DO_NOT_RESCHEDULE);
return bt_usb_devices[i]; return bt_usb_devices[i];
} }
} }
release_sem_etc(dev_table_sem, 1, B_DO_NOT_RESCHEDULE); release_sem_etc(dev_table_sem, 1, B_DO_NOT_RESCHEDULE);
return NULL; return NULL;
} }
#if 0 #if 0
#pragma mark - #pragma mark -
#endif #endif
static bt_hci_transport bt_usb_hooks = static bt_hci_transport bt_usb_hooks =
{ {
NULL, NULL,
NULL, NULL,
@@ -222,26 +222,26 @@ static status_t
device_added(const usb_device* dev, void** cookie) device_added(const usb_device* dev, void** cookie)
{ {
const usb_interface_info* interface; const usb_interface_info* interface;
const usb_device_descriptor* desc; const usb_device_descriptor* desc;
const usb_configuration_info* config; const usb_configuration_info* config;
const usb_interface_info* uif; const usb_interface_info* uif;
const usb_endpoint_info* ep; const usb_endpoint_info* ep;
status_t err = B_ERROR; status_t err = B_ERROR;
bt_usb_dev* new_bt_dev = spawn_device(dev); bt_usb_dev* new_bt_dev = spawn_device(dev);
int e; int e;
debugf("device_added(%p, %p)\n", dev, new_bt_dev); debugf("device_added(%p, %p)\n", dev, new_bt_dev);
if (new_bt_dev == NULL) { if (new_bt_dev == NULL) {
flowf("Couldn't allocate device record.\n"); flowf("Couldn't allocate device record.\n");
err = ENOMEM; err = ENOMEM;
goto bail_no_mem; goto bail_no_mem;
} }
/* we only have 1 configuration number 0 */ /* we only have 1 configuration number 0 */
config = usb->get_nth_configuration(dev, 0); config = usb->get_nth_configuration(dev, 0);
//dump_usb_configuration_info(config); //dump_usb_configuration_info(config);
if (config == NULL) { if (config == NULL) {
flowf("couldn't get default config.\n"); flowf("couldn't get default config.\n");
err = B_ERROR; err = B_ERROR;
@@ -249,11 +249,11 @@ device_added(const usb_device* dev, void** cookie)
} }
debugf("found %ld alt interfaces.\n", config->interface->alt_count); debugf("found %ld alt interfaces.\n", config->interface->alt_count);
/* set first interface */ /* set first interface */
interface = &config->interface->alt[0]; interface = &config->interface->alt[0];
err = usb->set_alt_interface(new_bt_dev->dev, interface); err = usb->set_alt_interface(new_bt_dev->dev, interface);
if (err != B_OK) { if (err != B_OK) {
debugf("set_alt_interface() returned %ld.\n", err); debugf("set_alt_interface() returned %ld.\n", err);
goto bail; goto bail;
@@ -265,15 +265,15 @@ device_added(const usb_device* dev, void** cookie)
debugf("set_configuration() returned %ld.\n", err); debugf("set_configuration() returned %ld.\n", err);
goto bail; goto bail;
} }
/* Place to find out whats our concrete device and set up some special info to our driver */ /* Place to find out whats our concrete device and set up some special info to our driver */
/* TODO: if this code increases too much reconsider this implementation*/ /* TODO: if this code increases too much reconsider this implementation*/
desc = usb->get_device_descriptor(dev); desc = usb->get_device_descriptor(dev);
if ( desc->vendor_id == 0x0a5c && (desc->product_id == 0x200a || if ( desc->vendor_id == 0x0a5c && (desc->product_id == 0x200a ||
desc->product_id == 0x2009 || desc->product_id == 0x2009 ||
desc->product_id == 0x2035 )) { desc->product_id == 0x2035 )) {
new_bt_dev->driver_info = BT_WILL_NEED_A_RESET | BT_SCO_NOT_WORKING; new_bt_dev->driver_info = BT_WILL_NEED_A_RESET | BT_SCO_NOT_WORKING;
} }
/* /*
else if ( desc->vendor_id == YOUR_VENDOR_HERE && desc->product_id == YOUR_PRODUCT_HERE ) { else if ( desc->vendor_id == YOUR_VENDOR_HERE && desc->product_id == YOUR_PRODUCT_HERE ) {
YOUR_SPECIAL_FLAGS_HERE YOUR_SPECIAL_FLAGS_HERE
@@ -284,28 +284,28 @@ device_added(const usb_device* dev, void** cookie)
err = ENODEV; err = ENODEV;
goto bail; goto bail;
} }
// security check // security check
if (config->interface->active->descr->interface_number > 0){ if (config->interface->active->descr->interface_number > 0){
debugf("Strange condition happened %d\n", config->interface->active->descr->interface_number); debugf("Strange condition happened %d\n", config->interface->active->descr->interface_number);
err = B_ERROR; err = B_ERROR;
goto bail; goto bail;
} }
debugf("Found %ld interfaces. Expected 3\n", config->interface_count); debugf("Found %ld interfaces. Expected 3\n", config->interface_count);
/* Find endpoints that we need */ /* Find endpoints that we need */
uif = config->interface->active; uif = config->interface->active;
for (e = 0; e < uif->descr->num_endpoints; e++) { for (e = 0; e < uif->descr->num_endpoints; e++) {
ep = &uif->endpoint[e]; ep = &uif->endpoint[e];
switch (ep->descr->attributes & USB_ENDPOINT_ATTR_MASK) switch (ep->descr->attributes & USB_ENDPOINT_ATTR_MASK)
{ {
case USB_ENDPOINT_ATTR_INTERRUPT: case USB_ENDPOINT_ATTR_INTERRUPT:
if (ep->descr->endpoint_address & USB_ENDPOINT_ADDR_DIR_IN) if (ep->descr->endpoint_address & USB_ENDPOINT_ADDR_DIR_IN)
{ {
new_bt_dev->intr_in_ep = ep; new_bt_dev->intr_in_ep = ep;
new_bt_dev->max_packet_size_intr_in = ep->descr->max_packet_size; new_bt_dev->max_packet_size_intr_in = ep->descr->max_packet_size;
flowf("INT in\n"); flowf("INT in\n");
} else { } else {
flowf("INT out\n"); flowf("INT out\n");
} }
@@ -324,7 +324,7 @@ device_added(const usb_device* dev, void** cookie)
break; break;
} }
} }
if (!new_bt_dev->bulk_in_ep || !new_bt_dev->bulk_out_ep || !new_bt_dev->intr_in_ep) { if (!new_bt_dev->bulk_in_ep || !new_bt_dev->bulk_out_ep || !new_bt_dev->intr_in_ep) {
flowf("Minimal # endpoints for BT not found\n"); flowf("Minimal # endpoints for BT not found\n");
goto bail; goto bail;
@@ -340,13 +340,13 @@ device_added(const usb_device* dev, void** cookie)
/* set the cookie that will be passed to other USB /* set the cookie that will be passed to other USB
hook functions (currently device_removed() is the only other) */ hook functions (currently device_removed() is the only other) */
*cookie = new_bt_dev; *cookie = new_bt_dev;
debugf("Ok %p\n",bt_usb_devices[0]); debugf("Ok %p\n",bt_usb_devices[0]);
return B_OK; return B_OK;
bail: bail:
kill_device(new_bt_dev); kill_device(new_bt_dev);
bail_no_mem: bail_no_mem:
*cookie = NULL; *cookie = NULL;
return err; return err;
@@ -358,16 +358,16 @@ static status_t
device_removed(void* cookie) device_removed(void* cookie)
{ {
bt_usb_dev* bdev = (bt_usb_dev*) fetch_device(cookie, 0); bt_usb_dev* bdev = (bt_usb_dev*) fetch_device(cookie, 0);
debugf("device_removed(%p)\n", bdev); debugf("device_removed(%p)\n", bdev);
if (bdev == NULL) { if (bdev == NULL) {
flowf(" not present in driver¿?\n"); flowf(" not present in driver¿?\n");
return B_ERROR; return B_ERROR;
} }
if (!TEST_AND_CLEAR(&bdev->state, RUNNING) ) { if (!TEST_AND_CLEAR(&bdev->state, RUNNING) ) {
flowf(" wasnt running¿?\n"); flowf(" wasnt running¿?\n");
} }
@@ -376,24 +376,24 @@ device_removed(void* cookie)
usb->cancel_queued_transfers(bdev->intr_in_ep->handle); usb->cancel_queued_transfers(bdev->intr_in_ep->handle);
flowf("Cancelling impossible EVENTS\n"); flowf("Cancelling impossible EVENTS\n");
} }
if (bdev->bulk_in_ep!=NULL) { if (bdev->bulk_in_ep!=NULL) {
usb->cancel_queued_transfers(bdev->bulk_in_ep->handle); usb->cancel_queued_transfers(bdev->bulk_in_ep->handle);
flowf("Cancelling impossible ACL in\n"); flowf("Cancelling impossible ACL in\n");
} }
if (bdev->bulk_out_ep!=NULL) { if (bdev->bulk_out_ep!=NULL) {
usb->cancel_queued_transfers(bdev->bulk_out_ep->handle); usb->cancel_queued_transfers(bdev->bulk_out_ep->handle);
flowf("Cancelling impossible ACL out\n"); flowf("Cancelling impossible ACL out\n");
} }
bdev->connected = false; bdev->connected = false;
return B_OK; return B_OK;
} }
static usb_notify_hooks notify_hooks = static usb_notify_hooks notify_hooks =
{ {
&device_added, &device_added,
&device_removed &device_removed
@@ -411,7 +411,7 @@ device_open(const char *name, uint32 flags, void **cookie)
bt_usb_dev* bdev = NULL; bt_usb_dev* bdev = NULL;
hci_id hdev; hci_id hdev;
int i; int i;
flowf("device_open()\n"); flowf("device_open()\n");
acquire_sem(dev_table_sem); acquire_sem(dev_table_sem);
@@ -422,21 +422,21 @@ device_open(const char *name, uint32 flags, void **cookie)
} }
} }
release_sem_etc(dev_table_sem, 1, B_DO_NOT_RESCHEDULE); release_sem_etc(dev_table_sem, 1, B_DO_NOT_RESCHEDULE);
if (bdev == NULL) { if (bdev == NULL) {
flowf("Device not found in the open list!"); flowf("Device not found in the open list!");
*cookie = NULL; *cookie = NULL;
return B_ERROR; return B_ERROR;
} }
// Set RUNNING // Set RUNNING
if ( TEST_AND_SET(&bdev->state, ANCILLYANT) ) { if ( TEST_AND_SET(&bdev->state, ANCILLYANT) ) {
flowf("dev already running! - reOpened device!\n"); flowf("dev already running! - reOpened device!\n");
return B_ERROR; return B_ERROR;
} }
acquire_sem(bdev->lock); acquire_sem(bdev->lock);
// TX structures // TX structures
for (i = 0; i < BT_DRIVER_TXCOVERAGE; i++) { for (i = 0; i < BT_DRIVER_TXCOVERAGE; i++) {
list_init(&bdev->nbuffersTx[i]); list_init(&bdev->nbuffersTx[i]);
bdev->nbuffersPendingTx[i] = 0; bdev->nbuffersPendingTx[i] = 0;
@@ -448,7 +448,7 @@ device_open(const char *name, uint32 flags, void **cookie)
bdev->nbufferRx[i] = NULL; bdev->nbufferRx[i] = NULL;
} }
// dumping the USB frames // dumping the USB frames
init_room(&bdev->eventRoom); init_room(&bdev->eventRoom);
init_room(&bdev->aclRoom); init_room(&bdev->aclRoom);
//init_room(new_bt_dev->scoRoom); //init_room(new_bt_dev->scoRoom);
@@ -489,44 +489,44 @@ device_close(void *cookie)
int32 i; int32 i;
void* item; void* item;
bt_usb_dev* bdev = (bt_usb_dev*)cookie; bt_usb_dev* bdev = (bt_usb_dev*)cookie;
if (bdev == NULL) if (bdev == NULL)
panic("bad cookie"); panic("bad cookie");
debugf("device_close() called on %ld\n", bdev->hdev ); debugf("device_close() called on %ld\n", bdev->hdev );
// Clean queues // Clean queues
// TX // TX
for (i = 0; i < BT_DRIVER_TXCOVERAGE; i++) { for (i = 0; i < BT_DRIVER_TXCOVERAGE; i++) {
if (i == BT_COMMAND) if (i == BT_COMMAND)
while ((item = list_remove_head_item(&bdev->nbuffersTx[i])) != NULL) { while ((item = list_remove_head_item(&bdev->nbuffersTx[i])) != NULL) {
snb_free(item); snb_free(item);
} }
else else
while ((item = list_remove_head_item(&bdev->nbuffersTx[i])) != NULL) { while ((item = list_remove_head_item(&bdev->nbuffersTx[i])) != NULL) {
nb_destroy(item); nb_destroy(item);
} }
} }
// RX // RX
for (i = 0; i < BT_DRIVER_RXCOVERAGE; i++) { for (i = 0; i < BT_DRIVER_RXCOVERAGE; i++) {
nb_destroy(bdev->nbufferRx[i]); nb_destroy(bdev->nbufferRx[i]);
} }
snb_free(bdev->eventRx); snb_free(bdev->eventRx);
purge_room(&bdev->eventRoom); purge_room(&bdev->eventRoom);
purge_room(&bdev->aclRoom); purge_room(&bdev->aclRoom);
/* Device no longer in our Stack*/ /* Device no longer in our Stack*/
if (btDevices != NULL) if (btDevices != NULL)
btDevices->uninit_device(bdev->ndev); btDevices->uninit_device(bdev->ndev);
// unSet RUNNING // unSet RUNNING
if (TEST_AND_CLEAR(&bdev->state, RUNNING)) { if (TEST_AND_CLEAR(&bdev->state, RUNNING)) {
debugf(" %s not running¿?\n",bdev->name); debugf(" %s not running¿?\n",bdev->name);
return B_ERROR; return B_ERROR;
} }
return B_OK; return B_OK;
} }
@@ -539,9 +539,9 @@ device_free (void *cookie)
{ {
status_t err = B_OK; status_t err = B_OK;
bt_usb_dev* bdev = (bt_usb_dev*)cookie; bt_usb_dev* bdev = (bt_usb_dev*)cookie;
debugf("device_free() called on %s \n",BLUETOOTH_DEVICE_PATH); debugf("device_free() called on %s \n",BLUETOOTH_DEVICE_PATH);
if (--bdev->open_count == 0) { if (--bdev->open_count == 0) {
@@ -549,9 +549,9 @@ device_free (void *cookie)
// interesting ..... // interesting .....
} else { } else {
/* The last client has closed, and the device is no longer /* The last client has closed, and the device is no longer
connected, so remove it from the list. */ connected, so remove it from the list. */
} }
kill_device(bdev); kill_device(bdev);
return err; return err;
@@ -568,10 +568,10 @@ device_control(void *cookie, uint32 msg, void *params, size_t size)
#if BT_DRIVER_SUPPORTS_ACL // ACL #if BT_DRIVER_SUPPORTS_ACL // ACL
int32 i; int32 i;
#endif #endif
TOUCH(size); TOUCH(size);
debugf("ioctl() opcode %ld size %ld.\n", msg, size); debugf("ioctl() opcode %ld size %ld.\n", msg, size);
if (bdev == NULL) { if (bdev == NULL) {
flowf("Bad cookie\n"); flowf("Bad cookie\n");
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -581,30 +581,30 @@ device_control(void *cookie, uint32 msg, void *params, size_t size)
flowf("Invalid pointer control\n"); flowf("Invalid pointer control\n");
return B_BAD_VALUE; return B_BAD_VALUE;
} }
acquire_sem(bdev->lock); acquire_sem(bdev->lock);
switch (msg) { switch (msg) {
case ISSUE_BT_COMMAND: case ISSUE_BT_COMMAND:
#ifdef BT_IOCTLS_PASS_SIZE #ifdef BT_IOCTLS_PASS_SIZE
if (size == 0) { if (size == 0) {
flowf("Invalid size control\n"); flowf("Invalid size control\n");
err = B_BAD_VALUE; err = B_BAD_VALUE;
break; break;
} }
#else #else
size = (*((size_t*)params)); size = (*((size_t*)params));
(*(size_t**)&params)++; (*(size_t**)&params)++;
#endif #endif
// TODO: Reuse from some TXcompleted queue // TODO: Reuse from some TXcompleted queue
snbuf = snb_create(size); snbuf = snb_create(size);
snb_put(snbuf, params, size); snb_put(snbuf, params, size);
err = submit_tx_command(bdev, snbuf); err = submit_tx_command(bdev, snbuf);
debugf("device launched %ld\n", err); debugf("device launched %ld\n", err);
break; break;
case BT_UP: case BT_UP:
// EVENTS // EVENTS
@@ -614,7 +614,7 @@ device_control(void *cookie, uint32 msg, void *params, size_t size)
flowf("Queuing failed device stops running\n"); flowf("Queuing failed device stops running\n");
break; break;
} }
#if BT_DRIVER_SUPPORTS_ACL // ACL #if BT_DRIVER_SUPPORTS_ACL // ACL
for (i = 0; i < MAX_ACL_IN_WINDOW; i++) { for (i = 0; i < MAX_ACL_IN_WINDOW; i++) {
err = submit_rx_acl(bdev); err = submit_rx_acl(bdev);
@@ -625,15 +625,15 @@ device_control(void *cookie, uint32 msg, void *params, size_t size)
} }
} }
#endif #endif
SET_BIT(bdev->state, RUNNING); SET_BIT(bdev->state, RUNNING);
#if BT_DRIVER_SUPPORTS_SCO #if BT_DRIVER_SUPPORTS_SCO
// TODO: SCO / eSCO // TODO: SCO / eSCO
#endif #endif
flowf("device launched\n"); flowf("device launched\n");
break; break;
case GET_STATS: case GET_STATS:
memcpy(params, &bdev->stat, sizeof(bt_hci_statistics)); memcpy(params, &bdev->stat, sizeof(bt_hci_statistics));
err = B_OK; err = B_OK;
@@ -642,15 +642,15 @@ device_control(void *cookie, uint32 msg, void *params, size_t size)
case GET_HCI_ID: case GET_HCI_ID:
*(hci_id*)params = bdev->hdev; *(hci_id*)params = bdev->hdev;
err = B_OK; err = B_OK;
break; break;
default: default:
debugf("Invalid opcode %ld.\n", msg); debugf("Invalid opcode %ld.\n", msg);
err = B_DEV_INVALID_IOCTL; err = B_DEV_INVALID_IOCTL;
break; break;
} }
release_sem(bdev->lock); release_sem(bdev->lock);
return err; return err;
} }
@@ -672,7 +672,7 @@ static status_t
device_write(void *cookie, off_t pos, const void *buf, size_t *count) device_write(void *cookie, off_t pos, const void *buf, size_t *count)
{ {
flowf("device_write()\n"); flowf("device_write()\n");
return B_ERROR; return B_ERROR;
} }
@@ -686,14 +686,14 @@ init_driver(void)
{ {
int j; int j;
flowf("init_driver()\n"); flowf("init_driver()\n");
// BT devices MODULE INITS // BT devices MODULE INITS
if (get_module(btDevices_name,(module_info**)&btDevices) != B_OK) { if (get_module(btDevices_name,(module_info**)&btDevices) != B_OK) {
debugf("cannot get module \"%s\"\n", btDevices_name); debugf("cannot get module \"%s\"\n", btDevices_name);
return B_ERROR; return B_ERROR;
} else } else
debugf("btDevices module at %p\n", btDevices); debugf("btDevices module at %p\n", btDevices);
// HCI MODULE INITS // HCI MODULE INITS
@@ -703,10 +703,10 @@ init_driver(void)
return err_release2; return err_release2;
#endif #endif
} else { } else {
debugf("hci module at %p\n", hci); debugf("hci module at %p\n", hci);
} }
// USB MODULE INITS // USB MODULE INITS
if (get_module(usb_name,(module_info**)&usb) != B_OK) { if (get_module(usb_name,(module_info**)&usb) != B_OK) {
debugf("cannot get module \"%s\"\n", usb_name); debugf("cannot get module \"%s\"\n", usb_name);
goto err_release1; goto err_release1;
@@ -718,33 +718,33 @@ init_driver(void)
debugf("cannot get module \"%s\"\n", NET_BUFFER_MODULE_NAME); debugf("cannot get module \"%s\"\n", NET_BUFFER_MODULE_NAME);
#ifndef BT_SURVIVE_WITHOUT_NET_BUFFERS #ifndef BT_SURVIVE_WITHOUT_NET_BUFFERS
goto err_release; goto err_release;
#endif #endif
} else { } else {
debugf("nb module at %p\n", nb); debugf("nb module at %p\n", nb);
} }
// GENERAL INITS // GENERAL INITS
dev_table_sem = create_sem(1, BLUETOOTH_DEVICE_DEVFS_NAME "dev_table_lock"); dev_table_sem = create_sem(1, BLUETOOTH_DEVICE_DEVFS_NAME "dev_table_lock");
if (dev_table_sem < 0) { if (dev_table_sem < 0) {
goto err; goto err;
} }
for (j = 0; j < MAX_BT_GENERIC_USB_DEVICES; j++) { for (j = 0; j < MAX_BT_GENERIC_USB_DEVICES; j++) {
bt_usb_devices[j] = NULL; bt_usb_devices[j] = NULL;
} }
/* After here device_added and publish devices hooks are called /* After here device_added and publish devices hooks are called
be carefull USB devs */ be carefull USB devs */
usb->register_driver(BLUETOOTH_DEVICE_DEVFS_NAME, supported_devices, 1, NULL); usb->register_driver(BLUETOOTH_DEVICE_DEVFS_NAME, supported_devices, 1, NULL);
usb->install_notify(BLUETOOTH_DEVICE_DEVFS_NAME, &notify_hooks); usb->install_notify(BLUETOOTH_DEVICE_DEVFS_NAME, &notify_hooks);
return B_OK; return B_OK;
err: // Releasing err: // Releasing
put_module(NET_BUFFER_MODULE_NAME); put_module(NET_BUFFER_MODULE_NAME);
err_release: err_release:
put_module(usb_name); put_module(usb_name);
err_release1: err_release1:
put_module(hci_name); put_module(hci_name);
err_release2: err_release2:
put_module(btDevices_name); put_module(btDevices_name);
@@ -757,14 +757,14 @@ void
uninit_driver(void) uninit_driver(void)
{ {
int32 j; int32 j;
flowf("uninit_driver()\n"); flowf("uninit_driver()\n");
for (j = 0; j < MAX_BT_GENERIC_USB_DEVICES; j++) { for (j = 0; j < MAX_BT_GENERIC_USB_DEVICES; j++) {
if (publish_names[j] != NULL) if (publish_names[j] != NULL)
free(publish_names[j]); free(publish_names[j]);
if (bt_usb_devices[j] != NULL) { if (bt_usb_devices[j] != NULL) {
// if (connected_dev != NULL) { // if (connected_dev != NULL) {
// debugf("Device %p still exists.\n", connected_dev); // debugf("Device %p still exists.\n", connected_dev);
@@ -773,14 +773,14 @@ uninit_driver(void)
kill_device(bt_usb_devices[j]); kill_device(bt_usb_devices[j]);
} }
} }
usb->uninstall_notify(BLUETOOTH_DEVICE_DEVFS_NAME); usb->uninstall_notify(BLUETOOTH_DEVICE_DEVFS_NAME);
/* Releasing modules */ /* Releasing modules */
put_module(usb_name); put_module(usb_name);
put_module(hci_name); put_module(hci_name);
// TODO: netbuffers // TODO: netbuffers
delete_sem(dev_table_sem); delete_sem(dev_table_sem);
} }
@@ -792,7 +792,7 @@ publish_devices(void)
int32 i = 0; int32 i = 0;
char* str; char* str;
flowf("publish_devices()\n"); flowf("publish_devices()\n");
for (j = 0; j < MAX_BT_GENERIC_USB_DEVICES; j++) { for (j = 0; j < MAX_BT_GENERIC_USB_DEVICES; j++) {
@@ -801,7 +801,7 @@ publish_devices(void)
publish_names[j] = NULL; publish_names[j] = NULL;
} }
} }
acquire_sem(dev_table_sem); acquire_sem(dev_table_sem);
for (j = 0; j < MAX_BT_GENERIC_USB_DEVICES; j++) { for (j = 0; j < MAX_BT_GENERIC_USB_DEVICES; j++) {
if (bt_usb_devices[j] != NULL && bt_usb_devices[j]->connected) { if (bt_usb_devices[j] != NULL && bt_usb_devices[j]->connected) {
@@ -813,11 +813,11 @@ publish_devices(void)
} }
} }
release_sem_etc(dev_table_sem, 1, B_DO_NOT_RESCHEDULE); release_sem_etc(dev_table_sem, 1, B_DO_NOT_RESCHEDULE);
publish_names[i] = NULL; publish_names[i] = NULL;
debugf("published %ld devices\n", i); debugf("published %ld devices\n", i);
// TODO: this method might make better memory use // TODO: this method might make better memory use
// dev_names = (char**)malloc(sizeof (char*) * (dev_count+1)); // dev_names = (char**)malloc(sizeof (char*) * (dev_count+1));
// if (dev_names) { // if (dev_names) {
// for (i = 0; i < MAX_NUM_DEVS; i++) { // for (i = 0; i < MAX_NUM_DEVS; i++) {
@@ -827,7 +827,7 @@ publish_devices(void)
// debugf("publishing \"%s\"\n", dev_names[i]); // debugf("publishing \"%s\"\n", dev_names[i]);
// } // }
// } // }
return (const char**)publish_names; return (const char**)publish_names;
} }
@@ -850,6 +850,6 @@ device_hooks*
find_device(const char* name) find_device(const char* name)
{ {
debugf("find_device(%s)\n", name); debugf("find_device(%s)\n", name);
return &hooks; return &hooks;
} }
@@ -37,17 +37,17 @@ void event_complete(void* cookie, status_t status, void* data, size_t actual_len
#endif #endif
static status_t static status_t
assembly_rx(bt_usb_dev* bdev, bt_packet_t type, void *data, int count) assembly_rx(bt_usb_dev* bdev, bt_packet_t type, void *data, int count)
{ {
net_buffer* nbuf = NULL; net_buffer* nbuf = NULL;
snet_buffer* snbuf = NULL; snet_buffer* snbuf = NULL;
size_t currentPacketLen = 0; size_t currentPacketLen = 0;
size_t expectedPacketLen = 0; size_t expectedPacketLen = 0;
bdev->stat.bytesRX += count; bdev->stat.bytesRX += count;
if (type == BT_EVENT) if (type == BT_EVENT)
snbuf = bdev->eventRx; snbuf = bdev->eventRx;
else else
@@ -55,7 +55,7 @@ assembly_rx(bt_usb_dev* bdev, bt_packet_t type, void *data, int count)
while (count) { while (count) {
debugf("count %d nb=%p sb=%p type=%d\n",count, nbuf, snbuf, type); debugf("count %d nb=%p sb=%p type=%d\n",count, nbuf, snbuf, type);
if ( (type != BT_EVENT && nbuf == NULL) || if ( (type != BT_EVENT && nbuf == NULL) ||
(type == BT_EVENT && (snbuf == NULL || snb_completed(snbuf))) ) { (type == BT_EVENT && (snbuf == NULL || snb_completed(snbuf))) ) {
@@ -64,24 +64,24 @@ assembly_rx(bt_usb_dev* bdev, bt_packet_t type, void *data, int count)
switch (type) { switch (type) {
case BT_EVENT: case BT_EVENT:
if (count >= HCI_EVENT_HDR_SIZE) { if (count >= HCI_EVENT_HDR_SIZE) {
struct hci_event_header* headerPkt = data; struct hci_event_header* headerPkt = data;
expectedPacketLen = HCI_EVENT_HDR_SIZE + headerPkt->elen; expectedPacketLen = HCI_EVENT_HDR_SIZE + headerPkt->elen;
snbuf = bdev->eventRx = snb_fetch(&bdev->snetBufferRecycleTrash, expectedPacketLen); snbuf = bdev->eventRx = snb_fetch(&bdev->snetBufferRecycleTrash, expectedPacketLen);
} else { } else {
flowf("EVENT frame corrupted\n"); flowf("EVENT frame corrupted\n");
return -EILSEQ; return -EILSEQ;
} }
break; break;
case BT_ACL: case BT_ACL:
if (count >= HCI_ACL_HDR_SIZE) { if (count >= HCI_ACL_HDR_SIZE) {
int16 index; int16 index;
struct hci_acl_header* headerPkt = data; struct hci_acl_header* headerPkt = data;
expectedPacketLen = HCI_ACL_HDR_SIZE + B_LENDIAN_TO_HOST_INT16(headerPkt->alen); expectedPacketLen = HCI_ACL_HDR_SIZE + B_LENDIAN_TO_HOST_INT16(headerPkt->alen);
/* Create the buffer */ /* Create the buffer */
bdev->nbufferRx[type] = nbuf = nb->create(expectedPacketLen); bdev->nbufferRx[type] = nbuf = nb->create(expectedPacketLen);
// TODO: this allocation can fail!! // TODO: this allocation can fail!!
@@ -98,11 +98,11 @@ assembly_rx(bt_usb_dev* bdev, bt_packet_t type, void *data, int count)
return -EILSEQ; return -EILSEQ;
} }
break; break;
case BT_SCO: case BT_SCO:
break; break;
default: default:
panic("unkown packet type in assembly"); panic("unkown packet type in assembly");
break; break;
@@ -122,7 +122,7 @@ assembly_rx(bt_usb_dev* bdev, bt_packet_t type, void *data, int count)
if (type == BT_EVENT) if (type == BT_EVENT)
snb_put(snbuf, data, currentPacketLen); snb_put(snbuf, data, currentPacketLen);
else else
nb->append(nbuf, data, currentPacketLen); nb->append(nbuf, data, currentPacketLen);
/* Complete frame? */ /* Complete frame? */
@@ -141,7 +141,7 @@ assembly_rx(bt_usb_dev* bdev, bt_packet_t type, void *data, int count)
}*/ }*/
/* in case in the pipe there is info about the next buffer ... */ /* in case in the pipe there is info about the next buffer ... */
count -= currentPacketLen; count -= currentPacketLen;
data += currentPacketLen; data += currentPacketLen;
} }
@@ -163,7 +163,7 @@ event_complete(void* cookie, status_t status, void* data, size_t actual_len)
{ {
bt_usb_dev* bdev = cookie; bt_usb_dev* bdev = cookie;
status_t err; status_t err;
/* TODO: or not running anymore */ /* TODO: or not running anymore */
if (status == B_CANCELED) if (status == B_CANCELED)
return; return;
@@ -176,11 +176,11 @@ event_complete(void* cookie, status_t status, void* data, size_t actual_len)
} else { } else {
bdev->stat.errorRX++; bdev->stat.errorRX++;
} }
resubmit: resubmit:
err = usb->queue_interrupt(bdev->intr_in_ep->handle, err = usb->queue_interrupt(bdev->intr_in_ep->handle,
data, bdev->max_packet_size_intr_in , data, bdev->max_packet_size_intr_in ,
event_complete, bdev); event_complete, bdev);
if (err != B_OK) { if (err != B_OK) {
@@ -219,8 +219,8 @@ acl_rx_complete(void* cookie, status_t status, void* data, size_t actual_len)
resubmit: resubmit:
err = usb->queue_bulk(bdev->bulk_in_ep->handle, data, err = usb->queue_bulk(bdev->bulk_in_ep->handle, data,
max(HCI_MAX_FRAME_SIZE,bdev->max_packet_size_bulk_in), max(HCI_MAX_FRAME_SIZE,bdev->max_packet_size_bulk_in),
acl_rx_complete, (void*) bdev); acl_rx_complete, (void*) bdev);
if (err != B_OK) { if (err != B_OK) {
@@ -246,8 +246,8 @@ submit_rx_event(bt_usb_dev* bdev)
if (buf == NULL) if (buf == NULL)
return ENOMEM; return ENOMEM;
status = usb->queue_interrupt(bdev->intr_in_ep->handle, status = usb->queue_interrupt(bdev->intr_in_ep->handle,
buf, size , buf, size ,
event_complete, (void*) bdev); event_complete, (void*) bdev);
if (status != B_OK) { if (status != B_OK) {
@@ -290,7 +290,7 @@ submit_rx_acl(bt_usb_dev* bdev)
status_t status_t
submit_rx_sco(bt_usb_dev* bdev) submit_rx_sco(bt_usb_dev* bdev)
{ {
/* not yet implemented */ /* not yet implemented */
return B_ERROR; return B_ERROR;
} }
@@ -308,7 +308,7 @@ command_complete(void* cookie, status_t status, void* data, size_t actual_len)
#endif #endif
{ {
snet_buffer* snbuf = (snet_buffer*) cookie; snet_buffer* snbuf = (snet_buffer*) cookie;
bt_usb_dev* bdev = snb_cookie(snbuf); bt_usb_dev* bdev = snb_cookie(snbuf);
debugf("%ld %02x:%02x:%02x:\n", actual_len, ((uint8*)data)[0],((uint8*)data)[1],((uint8*)data)[2]); debugf("%ld %02x:%02x:%02x:\n", actual_len, ((uint8*)data)[0],((uint8*)data)[1],((uint8*)data)[2]);
@@ -323,7 +323,7 @@ command_complete(void* cookie, status_t status, void* data, size_t actual_len)
snb_park(&bdev->snetBufferRecycleTrash, snbuf); snb_park(&bdev->snetBufferRecycleTrash, snbuf);
#ifdef BT_RESCHEDULING_AFTER_COMPLETITIONS #ifdef BT_RESCHEDULING_AFTER_COMPLETITIONS
// TODO: check just the empty queues? // TODO: check just the empty queues?
schedTxProcessing(bdev); schedTxProcessing(bdev);
#endif #endif
@@ -338,11 +338,11 @@ acl_tx_complete(void* cookie, status_t status, void* data, size_t actual_len)
#endif #endif
{ {
net_buffer* nbuf = (net_buffer*) cookie; net_buffer* nbuf = (net_buffer*) cookie;
bt_usb_dev* bdev = GET_DEVICE(nbuf); bt_usb_dev* bdev = GET_DEVICE(nbuf);
if (status != B_OK) { if (status != B_OK) {
bdev->stat.successfulTX++; bdev->stat.successfulTX++;
bdev->stat.bytesTX += actual_len; bdev->stat.bytesTX += actual_len;
} else { } else {
bdev->stat.errorTX++; bdev->stat.errorTX++;
@@ -351,7 +351,7 @@ acl_tx_complete(void* cookie, status_t status, void* data, size_t actual_len)
} }
nb_destroy(nbuf); nb_destroy(nbuf);
#ifdef BT_RESCHEDULING_AFTER_COMPLETITIONS #ifdef BT_RESCHEDULING_AFTER_COMPLETITIONS
schedTxProcessing(bdev); schedTxProcessing(bdev);
#endif #endif
} }
@@ -364,10 +364,10 @@ status_t
submit_tx_command(bt_usb_dev* bdev, snet_buffer* snbuf) submit_tx_command(bt_usb_dev* bdev, snet_buffer* snbuf)
{ {
status_t err; status_t err;
uint8 bRequestType = bdev->ctrl_req; uint8 bRequestType = bdev->ctrl_req;
uint8 bRequest = 0; uint8 bRequest = 0;
uint16 wIndex = 0; uint16 wIndex = 0;
uint16 value = 0; uint16 value = 0;
uint16 wLength = B_HOST_TO_LENDIAN_INT16(snb_size(snbuf)); uint16 wLength = B_HOST_TO_LENDIAN_INT16(snb_size(snbuf));
@@ -377,18 +377,18 @@ submit_tx_command(bt_usb_dev* bdev, snet_buffer* snbuf)
/* set cookie */ /* set cookie */
snb_set_cookie(snbuf, bdev); snb_set_cookie(snbuf, bdev);
err = usb->queue_request(bdev->dev, bRequestType, bRequest, err = usb->queue_request(bdev->dev, bRequestType, bRequest,
value, wIndex, wLength, value, wIndex, wLength,
snb_get(snbuf), wLength //??? snb_get(snbuf), wLength //???
,command_complete, (void*) snbuf); ,command_complete, (void*) snbuf);
if (err != B_OK ) { if (err != B_OK ) {
bdev->stat.rejectedTX++; bdev->stat.rejectedTX++;
} else { } else {
bdev->stat.acceptedTX++; bdev->stat.acceptedTX++;
} }
return err; return err;
} }
@@ -396,7 +396,7 @@ status_t
submit_tx_acl(bt_usb_dev* bdev, net_buffer* nbuf) submit_tx_acl(bt_usb_dev* bdev, net_buffer* nbuf)
{ {
status_t err; status_t err;
/* set cookie */ /* set cookie */
SET_DEVICE(nbuf,bdev->hdev); SET_DEVICE(nbuf,bdev->hdev);
@@ -404,7 +404,7 @@ submit_tx_acl(bt_usb_dev* bdev, net_buffer* nbuf)
return B_DEV_NOT_READY; return B_DEV_NOT_READY;
} }
err = usb->queue_bulk(bdev->bulk_out_ep->handle, err = usb->queue_bulk(bdev->bulk_out_ep->handle,
nb_get_whole_buffer(nbuf), nbuf->size, nb_get_whole_buffer(nbuf), nbuf->size,
acl_tx_complete, (void*) nbuf); acl_tx_complete, (void*) nbuf);
@@ -426,6 +426,6 @@ submit_tx_sco(bt_usb_dev* bdev)
return B_DEV_NOT_READY; return B_DEV_NOT_READY;
} }
/* not yet implemented */ /* not yet implemented */
return B_ERROR; return B_ERROR;
} }
@@ -29,7 +29,7 @@ nb_get_whole_buffer(net_buffer* nbuf)
// !!! it could be trash from other upper protocols... // !!! it could be trash from other upper protocols...
if (nbuf->COOKIEFIELD != NULL) if (nbuf->COOKIEFIELD != NULL)
return (void*)nbuf->COOKIEFIELD; return (void*)nbuf->COOKIEFIELD;
#endif #endif
err = nb->direct_access(nbuf, 0, nbuf->size, &conPointer); err = nb->direct_access(nbuf, 0, nbuf->size, &conPointer);
if (err != B_OK) { if (err != B_OK) {
@@ -39,17 +39,17 @@ nb_get_whole_buffer(net_buffer* nbuf)
nbuf->COOKIEFIELD = (uint32) malloc(nbuf->size); nbuf->COOKIEFIELD = (uint32) malloc(nbuf->size);
if (nbuf->COOKIEFIELD == NULL) if (nbuf->COOKIEFIELD == NULL)
goto fail; goto fail;
err = nb->write(nbuf, 0, (void*) nbuf->COOKIEFIELD, nbuf->size); err = nb->write(nbuf, 0, (void*) nbuf->COOKIEFIELD, nbuf->size);
if (err != B_OK) if (err != B_OK)
goto free; goto free;
conPointer = (void*)nbuf->COOKIEFIELD; conPointer = (void*)nbuf->COOKIEFIELD;
#endif #endif
} }
return conPointer; return conPointer;
#if 0 #if 0
free: free:
free((void*) nbuf->COOKIEFIELD); free((void*) nbuf->COOKIEFIELD);
fail: fail:
@@ -71,7 +71,7 @@ nb_destroy(net_buffer* nbuf)
// TODO check for survivers... // TODO check for survivers...
if (nb != NULL) if (nb != NULL)
nb->free(nbuf); nb->free(nbuf);
} }
@@ -82,17 +82,17 @@ nb_destroy(net_buffer* nbuf)
size_t size_t
get_expected_size(net_buffer* nbuf) get_expected_size(net_buffer* nbuf)
{ {
if (nbuf == NULL) if (nbuf == NULL)
panic("Analizing NULL packet"); panic("Analizing NULL packet");
switch (nbuf->protocol) { switch (nbuf->protocol) {
case BT_COMMAND: { case BT_COMMAND: {
struct hci_command_header* header = nb_get_whole_buffer(nbuf); struct hci_command_header* header = nb_get_whole_buffer(nbuf);
return header->clen + sizeof(struct hci_command_header); return header->clen + sizeof(struct hci_command_header);
} }
case BT_EVENT: { case BT_EVENT: {
struct hci_event_header* header = nb_get_whole_buffer(nbuf); struct hci_event_header* header = nb_get_whole_buffer(nbuf);
return header->elen + sizeof(struct hci_event_header); return header->elen + sizeof(struct hci_event_header);
@@ -109,10 +109,10 @@ get_expected_size(net_buffer* nbuf)
} }
default: default:
panic(BLUETOOTH_DEVICE_DEVFS_NAME "no protocol specified for " __FUNCTION__); panic(BLUETOOTH_DEVICE_DEVFS_NAME ":no protocol specified for ");
break; break;
} }
return B_ERROR; return B_ERROR;
} }
@@ -120,24 +120,24 @@ get_expected_size(net_buffer* nbuf)
#pragma mark - room util - #pragma mark - room util -
#endif #endif
inline void inline void
init_room(struct list* l) init_room(struct list* l)
{ {
list_init(l); list_init(l);
} }
void* void*
alloc_room(struct list* l, size_t size) alloc_room(struct list* l, size_t size)
{ {
void* item = list_get_first_item(l); void* item = list_get_first_item(l);
if (item == NULL) if (item == NULL)
item = (void*) malloc(size); item = (void*) malloc(size);
return item; return item;
} }
@@ -152,7 +152,7 @@ void
purge_room(struct list* l) purge_room(struct list* l)
{ {
void* item; void* item;
while ((item = list_remove_head_item(l)) != NULL) { while ((item = list_remove_head_item(l)) != NULL) {
free(item); free(item);
} }