- First steps for SCO connections

- Some styling 
(Mika Lindqvist)


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26799 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Ruiz Dorantes
2008-08-04 17:14:06 +00:00
parent 2c0c5e6c21
commit 8976dbe878
2 changed files with 98 additions and 72 deletions
+17
View File
@@ -0,0 +1,17 @@
/*
* Copyright 2008 Mika Lindqvist, monni1995_at_gmail.com
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef _BTHCI_SCO_H_
#define _BTHCI_SCO_H_
#include <bluetooth/HCI/btHCI.h>
#define HCI_SCO_HDR_SIZE 3
struct hci_sco_header {
uint16 handle;
uint8 slen;
} __attribute__((packed));
#endif // _BTHCI_SCO_H_
@@ -1,8 +1,7 @@
/*
* Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
*
* Copyright 2008 Mika Lindqvist, monni1995_at_gmail.com
* All rights reserved. Distributed under the terms of the MIT License.
*
*/
#include <malloc.h>
@@ -14,6 +13,7 @@
#include <bluetooth/HCI/btHCI_acl.h>
#include <bluetooth/HCI/btHCI_command.h>
#include <bluetooth/HCI/btHCI_event.h>
#include <bluetooth/HCI/btHCI_sco.h>
#define BT_DEBUG_THIS_MODULE
#include <btDebug.h>
@@ -22,38 +22,38 @@
void*
nb_get_whole_buffer(net_buffer* nbuf)
{
void* conPointer;
status_t err;
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;
/* the job could be already done */
// !!! it could be trash from other upper protocols...
if (nbuf->COOKIEFIELD != NULL)
return (void*)nbuf->COOKIEFIELD;
#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)
goto fail;
err = nb->write(nbuf, 0, (void*) nbuf->COOKIEFIELD, nbuf->size);
if (err != B_OK)
goto free;
conPointer = (void*)nbuf->COOKIEFIELD;
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)
goto fail;
err = nb->write(nbuf, 0, (void*) nbuf->COOKIEFIELD, nbuf->size);
if (err != B_OK)
goto free;
conPointer = (void*)nbuf->COOKIEFIELD;
#endif
}
return conPointer;
}
return conPointer;
#if 0
free:
free((void*) nbuf->COOKIEFIELD);
free((void*) nbuf->COOKIEFIELD);
fail:
return NULL;
return NULL;
#endif
}
@@ -63,48 +63,57 @@ nb_destroy(net_buffer* nbuf)
{
if (nbuf == NULL)
return;
#if 0
/* Free possible allocated */
if (nbuf->COOKIEFIELD != NULL)
free((void*)nbuf->COOKIEFIELD);
#if 0
/* Free possible allocated */
if (nbuf->COOKIEFIELD != NULL)
free((void*)nbuf->COOKIEFIELD);
#endif
// TODO check for survivers...
if (nb != NULL)
nb->free(nbuf);
}
nb->free(nbuf);
}
/* Check from the completition if the queue is empty */
// Extract the expected size of the packet
// TODO: This might be inefficient as at the moment of the creation of the net_buffer
// this information is known and it could be stored in any of the net_buffer fields
// but I still dont know how many of those am i gonna have free....
size_t
get_expected_size(net_buffer* nbuf)
{
if (nbuf == NULL)
panic("Analizing NULL packet");
switch (nbuf->protocol) {
if (nbuf == NULL)
panic("Analizing NULL packet");
switch (nbuf->protocol) {
case BT_COMMAND: {
struct hci_command_header* header = nb_get_whole_buffer(nbuf);
return header->clen + sizeof(struct hci_command_header);
}
case BT_EVENT: {
struct hci_event_header* header = nb_get_whole_buffer(nbuf);
return header->elen + sizeof(struct hci_event_header);
}
case BT_ACL: {
struct hci_acl_header* header = nb_get_whole_buffer(nbuf);
return header->alen + sizeof(struct hci_acl_header);
}
case BT_ACL: {
struct hci_acl_header* header = nb_get_whole_buffer(nbuf);
return header->alen + sizeof(struct hci_acl_header);
}
case BT_COMMAND: {
struct hci_command_header* header = nb_get_whole_buffer(nbuf);
return header->clen + sizeof(struct hci_command_header);
}
case BT_EVENT: {
struct hci_event_header* header = nb_get_whole_buffer(nbuf);
return header->elen + sizeof(struct hci_event_header);
}
default:
panic("h2geneirc:no protocol specifiel for get expected size");
break;
}
return B_ERROR;
case BT_SCO: {
struct hci_sco_header* header = nb_get_whole_buffer(nbuf);
return header->slen + sizeof(struct hci_sco_header);
}
default:
panic(BLUETOOTH_DEVICE_DEVFS_NAME "no protocol specified for " __FUNCTION__);
break;
}
return B_ERROR;
}
#if 0
@@ -114,37 +123,37 @@ get_expected_size(net_buffer* nbuf)
inline void
init_room(struct list* l)
{
list_init(l);
list_init(l);
}
void*
alloc_room(struct list* l, size_t size)
{
void* item = list_get_first_item(l);
if (item == NULL)
item = (void*) malloc(size);
return item;
void* item = list_get_first_item(l);
if (item == NULL)
item = (void*) malloc(size);
return item;
}
inline void
reuse_room(struct list* l, void* room)
{
list_add_item(l, room);
list_add_item(l, room);
}
void
purge_room(struct list* l)
{
void* item;
while ((item = list_remove_head_item(l)) != NULL) {
void* item;
while ((item = list_remove_head_item(l)) != NULL) {
free(item);
}
}
}