diff --git a/headers/os/bluetooth/HCI/btHCI_sco.h b/headers/os/bluetooth/HCI/btHCI_sco.h new file mode 100644 index 0000000000..461b31297a --- /dev/null +++ b/headers/os/bluetooth/HCI/btHCI_sco.h @@ -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 + +#define HCI_SCO_HDR_SIZE 3 + +struct hci_sco_header { + uint16 handle; + uint8 slen; +} __attribute__((packed)); + +#endif // _BTHCI_SCO_H_ diff --git a/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2util.c b/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2util.c index b2cda41b7b..ca9955d008 100644 --- a/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2util.c +++ b/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2util.c @@ -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 @@ -14,6 +13,7 @@ #include #include #include +#include #define BT_DEBUG_THIS_MODULE #include @@ -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); - } + } }