- 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 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. * All rights reserved. Distributed under the terms of the MIT License.
*
*/ */
#include <malloc.h> #include <malloc.h>
@@ -14,6 +13,7 @@
#include <bluetooth/HCI/btHCI_acl.h> #include <bluetooth/HCI/btHCI_acl.h>
#include <bluetooth/HCI/btHCI_command.h> #include <bluetooth/HCI/btHCI_command.h>
#include <bluetooth/HCI/btHCI_event.h> #include <bluetooth/HCI/btHCI_event.h>
#include <bluetooth/HCI/btHCI_sco.h>
#define BT_DEBUG_THIS_MODULE #define BT_DEBUG_THIS_MODULE
#include <btDebug.h> #include <btDebug.h>
@@ -22,38 +22,38 @@
void* void*
nb_get_whole_buffer(net_buffer* nbuf) nb_get_whole_buffer(net_buffer* nbuf)
{ {
void* conPointer; void* conPointer;
status_t err; status_t err;
#if 0 #if 0
/* the job could be already done */ /* the job could be already done */
// !!! 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) {
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 #endif
} }
return conPointer; return conPointer;
#if 0 #if 0
free: free:
free((void*) nbuf->COOKIEFIELD); free((void*) nbuf->COOKIEFIELD);
fail: fail:
return NULL; return NULL;
#endif #endif
} }
@@ -63,48 +63,57 @@ nb_destroy(net_buffer* nbuf)
{ {
if (nbuf == NULL) if (nbuf == NULL)
return; return;
#if 0 #if 0
/* Free possible allocated */ /* Free possible allocated */
if (nbuf->COOKIEFIELD != NULL) if (nbuf->COOKIEFIELD != NULL)
free((void*)nbuf->COOKIEFIELD); free((void*)nbuf->COOKIEFIELD);
#endif #endif
// TODO check for survivers... // TODO check for survivers...
if (nb != NULL) 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 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: {
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: { case BT_ACL: {
struct hci_acl_header* header = nb_get_whole_buffer(nbuf); struct hci_acl_header* header = nb_get_whole_buffer(nbuf);
return header->alen + sizeof(struct hci_acl_header); return header->alen + sizeof(struct hci_acl_header);
} }
case BT_COMMAND: { case BT_SCO: {
struct hci_command_header* header = nb_get_whole_buffer(nbuf); struct hci_sco_header* header = nb_get_whole_buffer(nbuf);
return header->clen + sizeof(struct hci_command_header); return header->slen + sizeof(struct hci_sco_header);
} }
case BT_EVENT: { default:
struct hci_event_header* header = nb_get_whole_buffer(nbuf); panic(BLUETOOTH_DEVICE_DEVFS_NAME "no protocol specified for " __FUNCTION__);
return header->elen + sizeof(struct hci_event_header); break;
} }
default:
panic("h2geneirc:no protocol specifiel for get expected size"); return B_ERROR;
break;
}
return B_ERROR;
} }
#if 0 #if 0
@@ -114,37 +123,37 @@ get_expected_size(net_buffer* nbuf)
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;
} }
inline void inline void
reuse_room(struct list* l, void* room) reuse_room(struct list* l, void* room)
{ {
list_add_item(l, room); list_add_item(l, room);
} }
void 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);
} }
} }