1009fac99SOliver Ruiz Dorantes /* 2009fac99SOliver Ruiz Dorantes * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com 3009fac99SOliver Ruiz Dorantes * 4009fac99SOliver Ruiz Dorantes * All rights reserved. Distributed under the terms of the MIT License. 5009fac99SOliver Ruiz Dorantes * 6009fac99SOliver Ruiz Dorantes */ 7009fac99SOliver Ruiz Dorantes 830f1d1f3SOliver Ruiz Dorantes 930f1d1f3SOliver Ruiz Dorantes #include <String.h> 1030f1d1f3SOliver Ruiz Dorantes 1130f1d1f3SOliver Ruiz Dorantes #include "BluetoothServer.h" 1230f1d1f3SOliver Ruiz Dorantes #include "HCITransportAccessor.h" 1330f1d1f3SOliver Ruiz Dorantes #include "Output.h" 1430f1d1f3SOliver Ruiz Dorantes 1530f1d1f3SOliver Ruiz Dorantes HCITransportAccessor::HCITransportAccessor(BPath* path) : HCIDelegate(path) 1630f1d1f3SOliver Ruiz Dorantes { 17ccf28e4dSOliver Ruiz Dorantes status_t status; 1830f1d1f3SOliver Ruiz Dorantes 19ccf28e4dSOliver Ruiz Dorantes fDescriptor = open (path->Path(), O_RDWR); 20ccf28e4dSOliver Ruiz Dorantes if (fDescriptor > 0) { 21ccf28e4dSOliver Ruiz Dorantes // find out which ID was assigned 22ccf28e4dSOliver Ruiz Dorantes status = ioctl(fDescriptor, GET_HCI_ID, &fIdentifier, 0); 23ccf28e4dSOliver Ruiz Dorantes printf("%s: hid retrieved %lx status=%ld\n", __FUNCTION__, 24ccf28e4dSOliver Ruiz Dorantes fIdentifier, status); 25ccf28e4dSOliver Ruiz Dorantes } else { 26ecd60ae8SOliver Ruiz Dorantes printf("%s: Device driver %s could not be opened %ld\n", __FUNCTION__, 27ecd60ae8SOliver Ruiz Dorantes path->Path(), fIdentifier); 28ccf28e4dSOliver Ruiz Dorantes fIdentifier = B_ERROR; 29ccf28e4dSOliver Ruiz Dorantes } 3030f1d1f3SOliver Ruiz Dorantes 3130f1d1f3SOliver Ruiz Dorantes } 3230f1d1f3SOliver Ruiz Dorantes 33ccf28e4dSOliver Ruiz Dorantes 34ccf28e4dSOliver Ruiz Dorantes HCITransportAccessor::~HCITransportAccessor() 35ccf28e4dSOliver Ruiz Dorantes { 36ccf28e4dSOliver Ruiz Dorantes if (fDescriptor > 0) 37ccf28e4dSOliver Ruiz Dorantes { 38ccf28e4dSOliver Ruiz Dorantes close(fDescriptor); 39ccf28e4dSOliver Ruiz Dorantes fDescriptor = -1; 40ccf28e4dSOliver Ruiz Dorantes fIdentifier = B_ERROR; 41ccf28e4dSOliver Ruiz Dorantes } 42ccf28e4dSOliver Ruiz Dorantes } 43ccf28e4dSOliver Ruiz Dorantes 44ccf28e4dSOliver Ruiz Dorantes 4530f1d1f3SOliver Ruiz Dorantes status_t 4630f1d1f3SOliver Ruiz Dorantes HCITransportAccessor::IssueCommand(raw_command rc, size_t size) 4730f1d1f3SOliver Ruiz Dorantes { 48ccf28e4dSOliver Ruiz Dorantes if (Id() < 0 || fDescriptor < 0) 4930f1d1f3SOliver Ruiz Dorantes return B_ERROR; 50*7a74a5dfSFredrik Modéen /* 51009fac99SOliver Ruiz Dorantes printf("### Command going: len = %ld\n", size); 52009fac99SOliver Ruiz Dorantes for (uint16 index = 0 ; index < size; index++ ) { 5330f1d1f3SOliver Ruiz Dorantes printf("%x:",((uint8*)rc)[index]); 5430f1d1f3SOliver Ruiz Dorantes } 55009fac99SOliver Ruiz Dorantes printf("### \n"); 56*7a74a5dfSFredrik Modéen */ 5730f1d1f3SOliver Ruiz Dorantes 58ccf28e4dSOliver Ruiz Dorantes return ioctl(fDescriptor, ISSUE_BT_COMMAND, rc, size); 5930f1d1f3SOliver Ruiz Dorantes } 6048cca06aSOliver Ruiz Dorantes 6148cca06aSOliver Ruiz Dorantes 6248cca06aSOliver Ruiz Dorantes status_t 6348cca06aSOliver Ruiz Dorantes HCITransportAccessor::Launch() { 6448cca06aSOliver Ruiz Dorantes 65d04eb939SOliver Ruiz Dorantes uint32 dummy; 66ccf28e4dSOliver Ruiz Dorantes return ioctl(fDescriptor, BT_UP, &dummy, sizeof(uint32)); 6748cca06aSOliver Ruiz Dorantes 6848cca06aSOliver Ruiz Dorantes } 69