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