- Use CoreData module for posting events

- Fix type field for reporting devices id
- Snooze before panic for non contiguous buffers
- Debug output buffers



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28737 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Ruiz Dorantes 2008-11-27 19:02:52 +00:00
parent 243680e819
commit ea40c3030b
6 changed files with 89 additions and 62 deletions

View File

@ -41,10 +41,11 @@ static char* hci_name = BT_HCI_MODULE_NAME;
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;
usb_module_info* usb = NULL;
bt_hci_module_info* hci = NULL;
struct net_device_module_info* btDevices = NULL;
struct net_buffer_module_info* nb = NULL;
struct bluetooth_core_data_module_info* btCoreData = NULL;
/* Driver Global data */
static char *publish_names[MAX_BT_GENERIC_USB_DEVICES];
@ -53,6 +54,8 @@ int32 dev_count = 0; /* number of connected devices */
static bt_usb_dev* bt_usb_devices[MAX_BT_GENERIC_USB_DEVICES];
sem_id dev_table_sem = -1; /* sem to synchronize access to device table */
status_t submit_nbuffer(hci_id hid, net_buffer* nbuf);
usb_support_descriptor supported_devices[] =
{
/* Generic Bluetooth USB device */
@ -175,7 +178,7 @@ fetch_device(bt_usb_dev* dev, hci_id hid)
{
int i;
debugf("(%p)\n", dev);
// debugf("(%p) or %d\n", dev, hid);
acquire_sem(dev_table_sem);
if (dev != NULL)
@ -205,15 +208,6 @@ fetch_device(bt_usb_dev* dev, hci_id hid)
#pragma mark -
#endif
static bt_hci_transport bt_usb_hooks =
{
NULL,
NULL,
NULL,
NULL,
H2,
"H2 Bluetooth Device"
};
/* called by USB Manager when device is added to the USB */
static status_t
@ -401,6 +395,36 @@ static usb_notify_hooks notify_hooks =
#pragma mark -
#endif
status_t
submit_nbuffer(hci_id hid, net_buffer* nbuf)
{
bt_usb_dev* bdev = NULL;
bdev = fetch_device(NULL, hid);
debugf("index=%lx nbuf=%p bdev=%p\n",hid, nbuf, bdev);
if (bdev != NULL) {
switch (nbuf->protocol) {
case BT_COMMAND:
// not issed this way
break;
case BT_ACL:
return submit_tx_acl(bdev, nbuf);
break;
default:
panic("submit_nbuffer: no protocol");
break;
}
}
return B_ERROR;
}
/* implements the POSIX open() */
static status_t
device_open(const char *name, uint32 flags, void **cookie)
@ -458,10 +482,13 @@ device_open(const char *name, uint32 flags, void **cookie)
struct net_device* ndev;
// TODO: Fill the transport descriptor
err = btDevices->init_device(bdev->name, &ndev);
if ( err == B_OK ) {
hdev = ndev->index;
bdev->ndev = ndev;
bdev->hdev = hdev = ndev->index; // get the index
bdev->ndev = ndev; // get the net_device
ndev->media = (uint32) submit_nbuffer; //XXX: interlayer-Hack
} else
hdev = bdev->num; /* XXX: Lets try to go on*/
} else {
@ -685,20 +712,24 @@ init_driver(void)
int j;
flowf("init_driver()\n");
if (get_module(BT_CORE_DATA_MODULE_NAME,(module_info**)&btCoreData) != B_OK) {
debugf("cannot get module \"%s\"\n", BT_CORE_DATA_MODULE_NAME);
return B_ERROR;
} else
debugf("BT_CORE_DATA_MODULE_NAME module at %p\n", btDevices);
// 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;
goto err_release3;
} 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 err_release2;
goto err_release2;
#endif
} else {
debugf("hci module at %p\n", hci);
@ -744,8 +775,13 @@ err_release:
put_module(usb_name);
err_release1:
put_module(hci_name);
#ifndef BT_SURVIVE_WITHOUT_HCI
err_release2:
#endif
put_module(btDevices_name);
err_release3:
put_module(BT_CORE_DATA_MODULE_NAME);
return B_ERROR;
}

View File

@ -18,6 +18,8 @@
#include <bluetooth/HCI/btHCI.h>
#include <bluetooth/HCI/btHCI_module.h>
#include <btCoreData.h>
#include "snet_buffer.h"
/* USB definitions for the generic device*/
@ -40,6 +42,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;
extern struct bluetooth_core_data_module_info* btCoreData;
#define MAX_COMMAND_WINDOW 1
#define MAX_ACL_OUT_WINDOW 4

View File

@ -55,7 +55,7 @@ assembly_rx(bt_usb_dev* bdev, bt_packet_t type, void *data, int 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) ||
(type == BT_EVENT && (snbuf == NULL || snb_completed(snbuf))) ) {
@ -310,7 +310,7 @@ command_complete(void* cookie, status_t status, void* data, size_t actual_len)
snet_buffer* snbuf = (snet_buffer*) cookie;
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 @ %p\n", actual_len, data);
if (status != B_OK) {
bdev->stat.successfulTX++;
@ -340,6 +340,8 @@ acl_tx_complete(void* cookie, status_t status, void* data, size_t actual_len)
net_buffer* nbuf = (net_buffer*) cookie;
bt_usb_dev* bdev = GET_DEVICE(nbuf);
debugf("fetched=%p status=%ld nbuftype %lx B%p\n",bdev, status, nbuf->type, data);
if (status != B_OK) {
bdev->stat.successfulTX++;
@ -378,6 +380,8 @@ submit_tx_command(bt_usb_dev* bdev, snet_buffer* snbuf)
/* set cookie */
snb_set_cookie(snbuf, bdev);
debugf("@%p\n", snb_get(snbuf));
err = usb->queue_request(bdev->dev, bRequestType, bRequest,
value, wIndex, wLength,
snb_get(snbuf), wLength //???
@ -396,14 +400,21 @@ status_t
submit_tx_acl(bt_usb_dev* bdev, net_buffer* nbuf)
{
status_t err;
int32 index;
/* set cookie */
SET_DEVICE(nbuf,bdev->hdev);
SET_DEVICE(nbuf, bdev->hdev);
if (!GET_BIT(bdev->state, RUNNING) ) {
return B_DEV_NOT_READY;
}
debugf("### Outgoing ACL: len = %ld\n", nbuf->size);
for (index = 0 ; index < nbuf->size; index++ ) {
dprintf("%x:",((uint8*)nb_get_whole_buffer(nbuf))[index]);
}
flowf("### \n");
err = usb->queue_bulk(bdev->bulk_out_ep->handle,
nb_get_whole_buffer(nbuf), nbuf->size,
acl_tx_complete, (void*) nbuf);

View File

@ -16,7 +16,7 @@
#include "h2transactions.h"
#include "snet_buffer.h"
#define BT_DEBUG_THIS_MODULE
//#define BT_DEBUG_THIS_MODULE
#include <btDebug.h>
@ -89,46 +89,22 @@ 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) {
err = B_ERROR;
err = B_ERROR;
// ERROR but we will try to send if its a event!
if (type == BT_EVENT) {
snet_buffer* snbuf = (snet_buffer*) buf;
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),
snb_get(snbuf), snb_size(snbuf), B_TIMEOUT, 1*1000*1000);
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;
}
} 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 {
// TODO: Upper layer comunication
/* Not freeing because is being used by upper layers*/
if (type == BT_EVENT) {
snet_buffer* snbuf = (snet_buffer*) buf;
btCoreData->PostEvent(bdev->ndev, snb_get(snbuf), (size_t) snb_size(snbuf));
snb_park(&bdev->snetBufferRecycleTrash, snbuf);
} 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);
}
return err;
}

View File

@ -33,7 +33,8 @@ nb_get_whole_buffer(net_buffer* nbuf)
err = nb->direct_access(nbuf, 0, nbuf->size, &conPointer);
if (err != B_OK) {
panic("I expected to be contiguous:(");
snooze(3*1000*1000);
panic("expected to be contiguous");
#if 0
/* pity, we are gonna need a realocation */
nbuf->COOKIEFIELD = (uint32) malloc(nbuf->size);

View File

@ -14,8 +14,8 @@
/* net buffer utils for ACL, to be reviewed */
#define DEVICEFIELD type
#define SET_DEVICE(nbuf,hid) (nbuf->DEVICEFIELD=(nbuf->DEVICEFIELD&0xFFF0)|(hid&0xF))
#define GET_DEVICE(nbuf) fetch_device(NULL,(nbuf->DEVICEFIELD&0x0F))
#define SET_DEVICE(nbuf,hid) (nbuf->DEVICEFIELD=(nbuf->DEVICEFIELD&0xFFFFFF00)|(hid&0xFF))
#define GET_DEVICE(nbuf) fetch_device(NULL,(nbuf->DEVICEFIELD&0xFF))
#define COOKIEFIELD flags
void* nb_get_whole_buffer(net_buffer* nbuf);