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 15 HCITransportAccessor::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 %" B_PRIx32 " status=%" B_PRId32 "\n", 24 __FUNCTION__, fIdentifier, status); 25 } else { 26 printf("%s: Device driver %s could not be opened %" B_PRId32 "\n", 27 __FUNCTION__, path->Path(), fIdentifier); 28 fIdentifier = B_ERROR; 29 } 30 31 } 32 33 34 HCITransportAccessor::~HCITransportAccessor() 35 { 36 if (fDescriptor > 0) 37 { 38 close(fDescriptor); 39 fDescriptor = -1; 40 fIdentifier = B_ERROR; 41 } 42 } 43 44 45 status_t 46 HCITransportAccessor::IssueCommand(raw_command rc, size_t size) 47 { 48 if (Id() < 0 || fDescriptor < 0) 49 return B_ERROR; 50 /* 51 printf("### Command going: len = %ld\n", size); 52 for (uint16 index = 0 ; index < size; index++ ) { 53 printf("%x:",((uint8*)rc)[index]); 54 } 55 printf("### \n"); 56 */ 57 58 return ioctl(fDescriptor, ISSUE_BT_COMMAND, rc, size); 59 } 60 61 62 status_t 63 HCITransportAccessor::Launch() { 64 65 uint32 dummy; 66 return ioctl(fDescriptor, BT_UP, &dummy, sizeof(uint32)); 67 68 } 69