1009fac99SOliver Ruiz Dorantes /* 2009fac99SOliver Ruiz Dorantes * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com 3*e5da0ec5SOliver 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); 31*e5da0ec5SOliver Ruiz Dorantes printf("%s: hid retrieved %lx status=%ld\n", __FUNCTION__, 32*e5da0ec5SOliver Ruiz Dorantes fHID, status); 3330f1d1f3SOliver Ruiz Dorantes } 3430f1d1f3SOliver Ruiz Dorantes else { 35*e5da0ec5SOliver Ruiz Dorantes printf("%s: Device driver could not be opened %ld\n", __FUNCTION__, 36*e5da0ec5SOliver Ruiz Dorantes fHID); 3730f1d1f3SOliver Ruiz Dorantes fHID = B_ERROR; 3830f1d1f3SOliver Ruiz Dorantes } 3930f1d1f3SOliver Ruiz Dorantes 403205e523SOliver Ruiz Dorantes //TODO create such queue 4130f1d1f3SOliver Ruiz Dorantes 4230f1d1f3SOliver Ruiz Dorantes } 4330f1d1f3SOliver Ruiz Dorantes 4448cca06aSOliver Ruiz Dorantes 4530f1d1f3SOliver Ruiz Dorantes hci_id GetID(void) 4630f1d1f3SOliver Ruiz Dorantes { 4730f1d1f3SOliver Ruiz Dorantes return fHID; 4830f1d1f3SOliver Ruiz Dorantes } 4930f1d1f3SOliver Ruiz Dorantes 50*e5da0ec5SOliver Ruiz Dorantes 51*e5da0ec5SOliver Ruiz Dorantes virtual ~HCIDelegate() 52*e5da0ec5SOliver Ruiz Dorantes { 53*e5da0ec5SOliver Ruiz Dorantes if (fFD > 0) 54*e5da0ec5SOliver Ruiz Dorantes { 55*e5da0ec5SOliver Ruiz Dorantes close (fFD); 56*e5da0ec5SOliver Ruiz Dorantes fFD = -1; 57*e5da0ec5SOliver Ruiz Dorantes fHID = B_ERROR; 58*e5da0ec5SOliver Ruiz Dorantes } 59*e5da0ec5SOliver Ruiz Dorantes } 60*e5da0ec5SOliver Ruiz Dorantes 61*e5da0ec5SOliver Ruiz Dorantes virtual status_t IssueCommand(raw_command rc, size_t size)=0; 62*e5da0ec5SOliver Ruiz Dorantes // TODO means to be private use QueueCommand 6348cca06aSOliver Ruiz Dorantes virtual status_t Launch()=0; 6430f1d1f3SOliver Ruiz Dorantes 653205e523SOliver Ruiz Dorantes 66*e5da0ec5SOliver Ruiz Dorantes void FreeWindow(uint8 slots) 67*e5da0ec5SOliver Ruiz Dorantes { 68*e5da0ec5SOliver Ruiz Dorantes // TODO: hci control flow 693205e523SOliver Ruiz Dorantes } 703205e523SOliver Ruiz Dorantes 71*e5da0ec5SOliver Ruiz Dorantes 723205e523SOliver Ruiz Dorantes status_t QueueCommand(raw_command rc, size_t size) 733205e523SOliver Ruiz Dorantes { 74*e5da0ec5SOliver Ruiz Dorantes // TODO: this is suposed to queue the command in a queue so all 75*e5da0ec5SOliver Ruiz Dorantes // are actually send to HW 763205e523SOliver Ruiz Dorantes return IssueCommand(rc, size); 773205e523SOliver Ruiz Dorantes } 783205e523SOliver Ruiz Dorantes 7930f1d1f3SOliver Ruiz Dorantes protected: 8030f1d1f3SOliver Ruiz Dorantes 8130f1d1f3SOliver Ruiz Dorantes hci_id fHID; 8230f1d1f3SOliver Ruiz Dorantes int fFD; 8330f1d1f3SOliver Ruiz Dorantes 8430f1d1f3SOliver Ruiz Dorantes private: 8530f1d1f3SOliver Ruiz Dorantes 8630f1d1f3SOliver Ruiz Dorantes 8730f1d1f3SOliver Ruiz Dorantes }; 8830f1d1f3SOliver Ruiz Dorantes 8930f1d1f3SOliver Ruiz Dorantes #endif 90