2008-03-13 00:44:25 +03:00
|
|
|
/*
|
2008-07-16 23:30:45 +04:00
|
|
|
* Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
|
|
|
|
* Copyright 2008 Mika Lindqvist
|
2012-08-27 23:22:35 +04:00
|
|
|
* Copyright 2012 Fredrik Modéen [firstname]@[lastname].se
|
2008-03-13 00:44:25 +03:00
|
|
|
* All rights reserved. Distributed under the terms of the MIT License.
|
|
|
|
*/
|
|
|
|
#ifndef _COMMAND_MANAGER_H
|
|
|
|
#define _COMMAND_MANAGER_H
|
|
|
|
|
2010-04-24 15:16:49 +04:00
|
|
|
#include <malloc.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2008-03-13 00:44:25 +03:00
|
|
|
#include <bluetooth/bluetooth.h>
|
2010-04-24 21:51:39 +04:00
|
|
|
#include <bluetooth/bluetooth_error.h>
|
2009-03-14 20:54:42 +03:00
|
|
|
#include <bluetooth/HCI/btHCI_command.h>
|
2010-04-24 15:16:49 +04:00
|
|
|
#include <bluetooth/HCI/btHCI_event.h>
|
2009-03-14 20:54:42 +03:00
|
|
|
|
2010-04-24 15:16:49 +04:00
|
|
|
#include <Message.h>
|
|
|
|
#include <Messenger.h>
|
2009-03-14 20:54:42 +03:00
|
|
|
|
2010-04-24 15:16:49 +04:00
|
|
|
#include <bluetoothserver_p.h>
|
2009-03-14 20:54:42 +03:00
|
|
|
|
2010-04-24 15:16:49 +04:00
|
|
|
#define typed_command(type) type, sizeof(type)
|
2009-03-14 20:54:42 +03:00
|
|
|
|
2010-04-24 15:16:49 +04:00
|
|
|
template <typename Type = void, int paramSize = 0,
|
|
|
|
int HeaderSize = HCI_COMMAND_HDR_SIZE>
|
2009-03-14 20:54:42 +03:00
|
|
|
class BluetoothCommand {
|
|
|
|
|
|
|
|
public:
|
2009-03-24 02:07:07 +03:00
|
|
|
BluetoothCommand(uint8 ogf, uint8 ocf)
|
2009-03-14 20:54:42 +03:00
|
|
|
{
|
|
|
|
fHeader = (struct hci_command_header*) fBuffer;
|
2010-04-24 15:16:49 +04:00
|
|
|
|
2009-03-14 20:54:42 +03:00
|
|
|
if (paramSize != 0)
|
|
|
|
fContent = (Type*)(fHeader + 1);
|
|
|
|
else
|
2010-04-24 15:16:49 +04:00
|
|
|
// avoid pointing outside in case of not having parameters
|
|
|
|
fContent = (Type*)fHeader;
|
|
|
|
|
2009-03-14 20:54:42 +03:00
|
|
|
fHeader->opcode = B_HOST_TO_LENDIAN_INT16(PACK_OPCODE(ogf, ocf));
|
2010-04-24 15:16:49 +04:00
|
|
|
fHeader->clen = paramSize;
|
2009-03-14 20:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Type*
|
|
|
|
operator->() const
|
|
|
|
{
|
|
|
|
return fContent;
|
|
|
|
}
|
2010-04-24 15:16:49 +04:00
|
|
|
|
|
|
|
void*
|
2009-03-14 20:54:42 +03:00
|
|
|
Data() const
|
|
|
|
{
|
|
|
|
return (void*)fBuffer;
|
|
|
|
}
|
2010-04-24 15:16:49 +04:00
|
|
|
|
2009-03-24 02:07:07 +03:00
|
|
|
size_t Size() const
|
|
|
|
{
|
|
|
|
return HeaderSize + paramSize;
|
|
|
|
}
|
2010-04-24 15:16:49 +04:00
|
|
|
|
2009-03-14 20:54:42 +03:00
|
|
|
private:
|
|
|
|
char fBuffer[paramSize + HeaderSize];
|
|
|
|
Type* fContent;
|
|
|
|
struct hci_command_header* fHeader;
|
|
|
|
};
|
|
|
|
|
2010-04-24 15:16:49 +04:00
|
|
|
|
|
|
|
status_t
|
|
|
|
NonParameterCommandRequest(uint8 ofg, uint8 ocf, int32* result, hci_id hId,
|
|
|
|
BMessenger* messenger);
|
|
|
|
|
|
|
|
template<typename PARAMETERCONTAINER, typename PARAMETERTYPE>
|
|
|
|
status_t
|
|
|
|
SingleParameterCommandRequest(uint8 ofg, uint8 ocf, PARAMETERTYPE parameter,
|
|
|
|
int32* result, hci_id hId, BMessenger* messenger)
|
|
|
|
{
|
|
|
|
int8 bt_status = BT_ERROR;
|
|
|
|
|
|
|
|
BluetoothCommand<typed_command(PARAMETERCONTAINER)>
|
|
|
|
simpleCommand(ofg, ocf);
|
|
|
|
|
|
|
|
simpleCommand->param = parameter;
|
|
|
|
|
|
|
|
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
|
|
|
|
BMessage reply;
|
|
|
|
|
|
|
|
simpleCommand->param = parameter;
|
|
|
|
|
|
|
|
request.AddInt32("hci_id", hId);
|
|
|
|
request.AddData("raw command", B_ANY_TYPE, simpleCommand.Data(),
|
|
|
|
simpleCommand.Size());
|
|
|
|
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
|
|
|
|
request.AddInt16("opcodeExpected", PACK_OPCODE(ofg, ocf));
|
|
|
|
|
|
|
|
if (messenger->SendMessage(&request, &reply) == B_OK) {
|
|
|
|
reply.FindInt8("status", &bt_status);
|
|
|
|
if (result != NULL)
|
|
|
|
reply.FindInt32("result", result);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bt_status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-13 00:44:25 +03:00
|
|
|
/* CONTROL BASEBAND */
|
|
|
|
void* buildReset(size_t* outsize);
|
|
|
|
void* buildReadLocalName(size_t* outsize);
|
2012-08-27 23:22:35 +04:00
|
|
|
void* buildReadScan(size_t* outsize);
|
2008-03-31 01:43:59 +04:00
|
|
|
void* buildWriteScan(uint8 scanmode, size_t* outsize);
|
2008-12-14 02:24:11 +03:00
|
|
|
void* buildReadClassOfDevice(size_t* outsize);
|
2008-03-13 00:44:25 +03:00
|
|
|
|
|
|
|
/* LINK CONTROL */
|
2010-04-24 15:16:49 +04:00
|
|
|
void* buildRemoteNameRequest(bdaddr_t bdaddr, uint8 pscan_rep_mode,
|
|
|
|
uint16 clock_offset, size_t* outsize);
|
2008-03-13 00:44:25 +03:00
|
|
|
void* buildInquiry(uint32 lap, uint8 length, uint8 num_rsp, size_t* outsize);
|
2008-06-12 23:18:32 +04:00
|
|
|
void* buildInquiryCancel(size_t* outsize);
|
2010-04-24 15:16:49 +04:00
|
|
|
void* buildPinCodeRequestReply(bdaddr_t bdaddr, uint8 length, char pincode[16],
|
|
|
|
size_t* outsize);
|
2008-06-18 23:17:35 +04:00
|
|
|
void* buildPinCodeRequestNegativeReply(bdaddr_t bdaddr, size_t* outsize);
|
2010-04-24 15:16:49 +04:00
|
|
|
void* buildAcceptConnectionRequest(bdaddr_t bdaddr, uint8 role,
|
|
|
|
size_t* outsize);
|
2008-07-16 23:25:44 +04:00
|
|
|
void* buildRejectConnectionRequest(bdaddr_t bdaddr, size_t* outsize);
|
2008-03-13 00:44:25 +03:00
|
|
|
|
|
|
|
/* OGF_INFORMATIONAL_PARAM */
|
2009-03-12 00:43:01 +03:00
|
|
|
void* buildReadLocalVersionInformation(size_t* outsize);
|
2008-03-13 00:44:25 +03:00
|
|
|
void* buildReadBufferSize(size_t* outsize);
|
|
|
|
void* buildReadBdAddr(size_t* outsize);
|
|
|
|
|
|
|
|
#endif
|