From 32c01b554aa6f49455cc8ea3de813ca4b6fad667 Mon Sep 17 00:00:00 2001 From: Oliver Ruiz Dorantes Date: Wed, 12 Mar 2008 21:44:25 +0000 Subject: [PATCH] Move the command builder module to the kit although meant to be kept private git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24379 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/bluetooth/CommandManager.h | 25 +++++ src/kits/bluetooth/CommandManager.cpp | 121 +++++++++++++++++++++ src/kits/bluetooth/Jamfile | 1 + 3 files changed, 147 insertions(+) create mode 100644 headers/private/bluetooth/CommandManager.h create mode 100644 src/kits/bluetooth/CommandManager.cpp diff --git a/headers/private/bluetooth/CommandManager.h b/headers/private/bluetooth/CommandManager.h new file mode 100644 index 0000000000..ae3a8e6bbe --- /dev/null +++ b/headers/private/bluetooth/CommandManager.h @@ -0,0 +1,25 @@ +/* + * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#ifndef _COMMAND_MANAGER_H +#define _COMMAND_MANAGER_H + +#include + +/* CONTROL BASEBAND */ +void* buildReset(size_t* outsize); +void* buildReadLocalName(size_t* outsize); + +/* LINK CONTROL */ +void* buildRemoteNameRequest(bdaddr_t bdaddr,uint8 pscan_rep_mode, uint16 clock_offset, size_t* outsize); +void* buildInquiry(uint32 lap, uint8 length, uint8 num_rsp, size_t* outsize); + +/* OGF_INFORMATIONAL_PARAM */ +void* buildReadBufferSize(size_t* outsize); +void* buildReadBdAddr(size_t* outsize); + +#endif diff --git a/src/kits/bluetooth/CommandManager.cpp b/src/kits/bluetooth/CommandManager.cpp new file mode 100644 index 0000000000..2874815187 --- /dev/null +++ b/src/kits/bluetooth/CommandManager.cpp @@ -0,0 +1,121 @@ +/* + * Copyright 2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + + +#include +#include + +#include + +#include "CommandManager.h" + + +inline void* buildCommand(uint8 ogf, uint8 ocf, void** param, size_t psize, size_t* outsize) +{ + struct hci_command_header* header; + +#ifdef BT_IOCTLS_PASS_SIZE + header = (struct hci_command_header*) malloc(psize + sizeof(struct hci_command_header)); + *outsize = psize + sizeof(struct hci_command_header); +#else + size_t* size = (size_t*)malloc(psize + sizeof(struct hci_command_header) + sizeof(size_t)); + *outsize = psize + sizeof(struct hci_command_header) + sizeof(size_t); + + *size = psize + sizeof(struct hci_command_header); + header = (struct hci_command_header*) (((uint8*)size)+4); +#endif + + + if (header != NULL) { + + header->opcode = B_HOST_TO_LENDIAN_INT16(PACK_OPCODE(ogf, ocf)); + header->clen = psize; + + if (param != NULL && psize != 0) { + *param = ((uint8*)header) + sizeof(struct hci_command_header); + } + } +#ifdef BT_IOCTLS_PASS_SIZE + return header; +#else + return (void*)size; +#endif +} + + +#if 0 +#pragma mark - CONTROL BASEBAND - +#endif + + +void* buildReset(size_t* outsize) +{ + return buildCommand(OGF_CONTROL_BASEBAND, OCF_RESET, NULL, 0, outsize); +} + + +void* buildReadLocalName(size_t* outsize) +{ + return buildCommand(OGF_CONTROL_BASEBAND, OCF_READ_LOCAL_NAME, NULL, 0, outsize); +} + + +#if 0 +#pragma mark - LINK CONTROL - +#endif + + +void* buildRemoteNameRequest(bdaddr_t bdaddr,uint8 pscan_rep_mode, uint16 clock_offset, size_t* outsize) +{ + + struct hci_remote_name_request* param; + void* command = buildCommand(OGF_LINK_CONTROL, OCF_REMOTE_NAME_REQUEST, (void**) ¶m, sizeof(struct hci_remote_name_request), outsize); + + if (command != NULL) { + param->bdaddr = bdaddr; + param->pscan_rep_mode = pscan_rep_mode; + param->clock_offset = clock_offset; + } + + return command; +} + + +void* buildInquiry(uint32 lap, uint8 length, uint8 num_rsp, size_t* outsize) +{ + + struct hci_cp_inquiry* param; + void* command = buildCommand(OGF_LINK_CONTROL, OCF_INQUIRY, (void**) ¶m, sizeof(struct hci_cp_inquiry), outsize); + + if (command != NULL) { + + param->lap[2] = (lap >> 16) & 0xFF; + param->lap[1] = (lap >> 8) & 0xFF; + param->lap[0] = (lap >> 0) & 0xFF; + param->length = length; + param->num_rsp = num_rsp; + } + + return command; +} + + +#if 0 +#pragma mark - INFORMATIONAL_PARAM - +#endif + + +void* buildReadBufferSize(size_t* outsize) +{ + return buildCommand(OGF_INFORMATIONAL_PARAM, OCF_READ_BUFFER_SIZE, NULL, 0, outsize); +} + + +void* buildReadBdAddr(size_t* outsize) +{ + return buildCommand(OGF_INFORMATIONAL_PARAM, OCF_READ_BD_ADDR, NULL, 0, outsize); +} diff --git a/src/kits/bluetooth/Jamfile b/src/kits/bluetooth/Jamfile index e3eb89a6e5..f30b71014a 100644 --- a/src/kits/bluetooth/Jamfile +++ b/src/kits/bluetooth/Jamfile @@ -12,5 +12,6 @@ SharedLibrary libbluetooth.so : LocalDevice.cpp DiscoveryAgent.cpp DiscoveryListener.cpp + CommandManager.cpp : be ;