1 /* 2 * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com 3 * Copyright 2008 Mika Lindqvist 4 * All rights reserved. Distributed under the terms of the MIT License. 5 */ 6 #ifndef _COMMAND_MANAGER_H 7 #define _COMMAND_MANAGER_H 8 9 #include <bluetooth/bluetooth.h> 10 #include <bluetooth/HCI/btHCI_command.h> 11 12 #include <malloc.h> 13 #include <string.h> 14 15 16 #define typed_command(type) type,sizeof(type) 17 18 /* Experimental stack allocated alternative to build commands */ 19 template <typename Type = void, int paramSize = 0, int HeaderSize = HCI_COMMAND_HDR_SIZE> 20 class BluetoothCommand { 21 22 public: 23 BluetoothCommand(uint8 ogf, uint8 ocf) 24 { 25 fHeader = (struct hci_command_header*) fBuffer; 26 27 if (paramSize != 0) 28 fContent = (Type*)(fHeader + 1); 29 else 30 fContent = (Type*)fHeader; // avoid pointing outside in case of not having parameters 31 32 fHeader->opcode = B_HOST_TO_LENDIAN_INT16(PACK_OPCODE(ogf, ocf)); 33 fHeader->clen = paramSize; 34 } 35 36 Type* 37 operator->() const 38 { 39 return fContent; 40 } 41 42 void* 43 Data() const 44 { 45 return (void*)fBuffer; 46 } 47 48 size_t Size() const 49 { 50 return HeaderSize + paramSize; 51 } 52 53 private: 54 char fBuffer[paramSize + HeaderSize]; 55 Type* fContent; 56 struct hci_command_header* fHeader; 57 }; 58 59 /* CONTROL BASEBAND */ 60 void* buildReset(size_t* outsize); 61 void* buildReadLocalName(size_t* outsize); 62 void* buildWriteScan(uint8 scanmode, size_t* outsize); 63 void* buildAuthEnable(uint8 auth, size_t* outsize); 64 void* buildReadClassOfDevice(size_t* outsize); 65 66 /* LINK CONTROL */ 67 void* buildRemoteNameRequest(bdaddr_t bdaddr,uint8 pscan_rep_mode, uint16 clock_offset, size_t* outsize); 68 void* buildInquiry(uint32 lap, uint8 length, uint8 num_rsp, size_t* outsize); 69 void* buildInquiryCancel(size_t* outsize); 70 void* buildPinCodeRequestReply(bdaddr_t bdaddr, uint8 length, char pincode[16], size_t* outsize); 71 void* buildPinCodeRequestNegativeReply(bdaddr_t bdaddr, size_t* outsize); 72 void* buildAcceptConnectionRequest(bdaddr_t bdaddr, uint8 role, size_t* outsize); 73 void* buildRejectConnectionRequest(bdaddr_t bdaddr, size_t* outsize); 74 75 /* OGF_INFORMATIONAL_PARAM */ 76 void* buildReadLocalVersionInformation(size_t* outsize); 77 void* buildReadBufferSize(size_t* outsize); 78 void* buildReadBdAddr(size_t* outsize); 79 80 #endif 81