1/* 2 * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com 3 * 4 * All rights reserved. Distributed under the terms of the MIT License. 5 * 6 */ 7 8 9#include <String.h> 10 11#include "BluetoothServer.h" 12#include "HCITransportAccessor.h" 13#include "Output.h" 14 15HCITransportAccessor::HCITransportAccessor(BPath* path) : HCIDelegate(path) 16{ 17 status_t status; 18 19 fDescriptor = open (path->Path(), O_RDWR); 20 if (fDescriptor > 0) { 21 // find out which ID was assigned 22 status = ioctl(fDescriptor, GET_HCI_ID, &fIdentifier, 0); 23 printf("%s: hid retrieved %lx status=%ld\n", __FUNCTION__, 24 fIdentifier, status); 25 } else { 26 printf("%s: Device driver %s could not be opened %ld\n", __FUNCTION__, 27 path->Path(), fIdentifier); 28 fIdentifier = B_ERROR; 29 } 30 31} 32 33 34HCITransportAccessor::~HCITransportAccessor() 35{ 36 if (fDescriptor > 0) 37 { 38 close(fDescriptor); 39 fDescriptor = -1; 40 fIdentifier = B_ERROR; 41 } 42} 43 44 45status_t 46HCITransportAccessor::IssueCommand(raw_command rc, size_t size) 47{ 48 if (Id() < 0 || fDescriptor < 0) 49 return B_ERROR; 50/* 51printf("### Command going: len = %ld\n", size); 52for (uint16 index = 0 ; index < size; index++ ) { 53 printf("%x:",((uint8*)rc)[index]); 54} 55printf("### \n"); 56*/ 57 58 return ioctl(fDescriptor, ISSUE_BT_COMMAND, rc, size); 59} 60 61 62status_t 63HCITransportAccessor::Launch() { 64 65 uint32 dummy; 66 return ioctl(fDescriptor, BT_UP, &dummy, sizeof(uint32)); 67 68} 69