1009fac99SOliver Ruiz Dorantes /* 2009fac99SOliver Ruiz Dorantes * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com 3e5da0ec5SOliver Ruiz Dorantes * Copyright 2008 Mika Lindqvist, monni1995_at_gmail.com 4009fac99SOliver Ruiz Dorantes * All rights reserved. Distributed under the terms of the MIT License. 5009fac99SOliver Ruiz Dorantes */ 630f1d1f3SOliver Ruiz Dorantes #ifndef _HCIDELEGATE_H_ 730f1d1f3SOliver Ruiz Dorantes #define _HCIDELEGATE_H_ 830f1d1f3SOliver Ruiz Dorantes 930f1d1f3SOliver Ruiz Dorantes #include <fcntl.h> 1030f1d1f3SOliver Ruiz Dorantes #include <unistd.h> 1130f1d1f3SOliver Ruiz Dorantes #include <stdio.h> 1230f1d1f3SOliver Ruiz Dorantes #include <Path.h> 1330f1d1f3SOliver Ruiz Dorantes 1430f1d1f3SOliver Ruiz Dorantes #include <bluetooth/HCI/btHCI_transport.h> 1530f1d1f3SOliver Ruiz Dorantes 1630f1d1f3SOliver Ruiz Dorantes 1730f1d1f3SOliver Ruiz Dorantes typedef void* raw_command; 1830f1d1f3SOliver Ruiz Dorantes 1930f1d1f3SOliver Ruiz Dorantes 2030f1d1f3SOliver Ruiz Dorantes class HCIDelegate { 2130f1d1f3SOliver Ruiz Dorantes 2230f1d1f3SOliver Ruiz Dorantes public: 2330f1d1f3SOliver Ruiz Dorantes HCIDelegate(BPath* path) 2430f1d1f3SOliver Ruiz Dorantes { 2530f1d1f3SOliver Ruiz Dorantes status_t status; 2630f1d1f3SOliver Ruiz Dorantes 2730f1d1f3SOliver Ruiz Dorantes fFD = open (path->Path(), O_RDWR); 2830f1d1f3SOliver Ruiz Dorantes if (fFD > 0) { 2930f1d1f3SOliver Ruiz Dorantes // find out which ID was assigned 3030f1d1f3SOliver Ruiz Dorantes status = ioctl(fFD, GET_HCI_ID, &fHID, 0); 31e5da0ec5SOliver Ruiz Dorantes printf("%s: hid retrieved %lx status=%ld\n", __FUNCTION__, 32e5da0ec5SOliver Ruiz Dorantes fHID, status); 33*06b6c3cbSOliver Ruiz Dorantes } else { 34e5da0ec5SOliver Ruiz Dorantes printf("%s: Device driver could not be opened %ld\n", __FUNCTION__, 35e5da0ec5SOliver Ruiz Dorantes fHID); 3630f1d1f3SOliver Ruiz Dorantes fHID = B_ERROR; 3730f1d1f3SOliver Ruiz Dorantes } 3830f1d1f3SOliver Ruiz Dorantes 393205e523SOliver Ruiz Dorantes //TODO create such queue 4030f1d1f3SOliver Ruiz Dorantes 4130f1d1f3SOliver Ruiz Dorantes } 4230f1d1f3SOliver Ruiz Dorantes 4348cca06aSOliver Ruiz Dorantes 4430f1d1f3SOliver Ruiz Dorantes hci_id GetID(void) 4530f1d1f3SOliver Ruiz Dorantes { 4630f1d1f3SOliver Ruiz Dorantes return fHID; 4730f1d1f3SOliver Ruiz Dorantes } 4830f1d1f3SOliver Ruiz Dorantes 49e5da0ec5SOliver Ruiz Dorantes 50e5da0ec5SOliver Ruiz Dorantes virtual ~HCIDelegate() 51e5da0ec5SOliver Ruiz Dorantes { 52e5da0ec5SOliver Ruiz Dorantes if (fFD > 0) 53e5da0ec5SOliver Ruiz Dorantes { 54e5da0ec5SOliver Ruiz Dorantes close (fFD); 55e5da0ec5SOliver Ruiz Dorantes fFD = -1; 56e5da0ec5SOliver Ruiz Dorantes fHID = B_ERROR; 57e5da0ec5SOliver Ruiz Dorantes } 58e5da0ec5SOliver Ruiz Dorantes } 59e5da0ec5SOliver Ruiz Dorantes 60e5da0ec5SOliver Ruiz Dorantes virtual status_t IssueCommand(raw_command rc, size_t size)=0; 61e5da0ec5SOliver Ruiz Dorantes // TODO means to be private use QueueCommand 6248cca06aSOliver Ruiz Dorantes virtual status_t Launch()=0; 6330f1d1f3SOliver Ruiz Dorantes 643205e523SOliver Ruiz Dorantes 65e5da0ec5SOliver Ruiz Dorantes void FreeWindow(uint8 slots) 66e5da0ec5SOliver Ruiz Dorantes { 67e5da0ec5SOliver Ruiz Dorantes // TODO: hci control flow 683205e523SOliver Ruiz Dorantes } 693205e523SOliver Ruiz Dorantes 70e5da0ec5SOliver Ruiz Dorantes 713205e523SOliver Ruiz Dorantes status_t QueueCommand(raw_command rc, size_t size) 723205e523SOliver Ruiz Dorantes { 73e5da0ec5SOliver Ruiz Dorantes // TODO: this is suposed to queue the command in a queue so all 74*06b6c3cbSOliver Ruiz Dorantes // are actually send to HW to implement HCI FlowControl requeriments 753205e523SOliver Ruiz Dorantes return IssueCommand(rc, size); 763205e523SOliver Ruiz Dorantes } 773205e523SOliver Ruiz Dorantes 7830f1d1f3SOliver Ruiz Dorantes protected: 7930f1d1f3SOliver Ruiz Dorantes 8030f1d1f3SOliver Ruiz Dorantes hci_id fHID; 8130f1d1f3SOliver Ruiz Dorantes int fFD; 8230f1d1f3SOliver Ruiz Dorantes 8330f1d1f3SOliver Ruiz Dorantes private: 8430f1d1f3SOliver Ruiz Dorantes 8530f1d1f3SOliver Ruiz Dorantes 8630f1d1f3SOliver Ruiz Dorantes }; 8730f1d1f3SOliver Ruiz Dorantes 8830f1d1f3SOliver Ruiz Dorantes #endif 89