1 /* 2 * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com 3 * Copyright 2008 Mika Lindqvist, monni1995_at_gmail.com 4 * All rights reserved. Distributed under the terms of the MIT License. 5 */ 6 #ifndef _HCIDELEGATE_H_ 7 #define _HCIDELEGATE_H_ 8 9 #include <fcntl.h> 10 #include <unistd.h> 11 #include <stdio.h> 12 #include <Path.h> 13 14 #include <bluetooth/HCI/btHCI_transport.h> 15 16 17 typedef void* raw_command; 18 19 20 class HCIDelegate { 21 22 public: 23 HCIDelegate(BPath* path) 24 { 25 status_t status; 26 27 fFD = open (path->Path(), O_RDWR); 28 if (fFD > 0) { 29 // find out which ID was assigned 30 status = ioctl(fFD, GET_HCI_ID, &fHID, 0); 31 printf("%s: hid retrieved %lx status=%ld\n", __FUNCTION__, 32 fHID, status); 33 } else { 34 printf("%s: Device driver could not be opened %ld\n", __FUNCTION__, 35 fHID); 36 fHID = B_ERROR; 37 } 38 39 //TODO create such queue 40 41 } 42 43 44 hci_id GetID(void) 45 { 46 return fHID; 47 } 48 49 50 virtual ~HCIDelegate() 51 { 52 if (fFD > 0) 53 { 54 close (fFD); 55 fFD = -1; 56 fHID = B_ERROR; 57 } 58 } 59 60 virtual status_t IssueCommand(raw_command rc, size_t size)=0; 61 // TODO means to be private use QueueCommand 62 virtual status_t Launch()=0; 63 64 65 void FreeWindow(uint8 slots) 66 { 67 // TODO: hci control flow 68 } 69 70 71 status_t QueueCommand(raw_command rc, size_t size) 72 { 73 // TODO: this is suposed to queue the command in a queue so all 74 // are actually send to HW to implement HCI FlowControl requeriments 75 return IssueCommand(rc, size); 76 } 77 78 protected: 79 80 hci_id fHID; 81 int fFD; 82 83 private: 84 85 86 }; 87 88 #endif 89