1009fac99SOliver Ruiz Dorantes /*
2009fac99SOliver Ruiz Dorantes * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
3009fac99SOliver Ruiz Dorantes * All rights reserved. Distributed under the terms of the MIT License.
4009fac99SOliver Ruiz Dorantes */
5009fac99SOliver Ruiz Dorantes
630f1d1f3SOliver Ruiz Dorantes
730f1d1f3SOliver Ruiz Dorantes #include <String.h>
830f1d1f3SOliver Ruiz Dorantes
930f1d1f3SOliver Ruiz Dorantes #include "BluetoothServer.h"
1030f1d1f3SOliver Ruiz Dorantes #include "HCITransportAccessor.h"
115559d51dSAugustin Cavalier
1230f1d1f3SOliver Ruiz Dorantes
HCITransportAccessor(BPath * path)1330f1d1f3SOliver Ruiz Dorantes HCITransportAccessor::HCITransportAccessor(BPath* path) : HCIDelegate(path)
1430f1d1f3SOliver Ruiz Dorantes {
15ccf28e4dSOliver Ruiz Dorantes status_t status;
1630f1d1f3SOliver Ruiz Dorantes
17ccf28e4dSOliver Ruiz Dorantes fDescriptor = open (path->Path(), O_RDWR);
18ccf28e4dSOliver Ruiz Dorantes if (fDescriptor > 0) {
19ccf28e4dSOliver Ruiz Dorantes // find out which ID was assigned
20ccf28e4dSOliver Ruiz Dorantes status = ioctl(fDescriptor, GET_HCI_ID, &fIdentifier, 0);
2148350f1aSJérôme Duval printf("%s: hid retrieved %" B_PRIx32 " status=%" B_PRId32 "\n",
2248350f1aSJérôme Duval __FUNCTION__, fIdentifier, status);
23ccf28e4dSOliver Ruiz Dorantes } else {
2448350f1aSJérôme Duval printf("%s: Device driver %s could not be opened %" B_PRId32 "\n",
2548350f1aSJérôme Duval __FUNCTION__, path->Path(), fIdentifier);
26ccf28e4dSOliver Ruiz Dorantes fIdentifier = B_ERROR;
27ccf28e4dSOliver Ruiz Dorantes }
2830f1d1f3SOliver Ruiz Dorantes
2930f1d1f3SOliver Ruiz Dorantes }
3030f1d1f3SOliver Ruiz Dorantes
31ccf28e4dSOliver Ruiz Dorantes
~HCITransportAccessor()32ccf28e4dSOliver Ruiz Dorantes HCITransportAccessor::~HCITransportAccessor()
33ccf28e4dSOliver Ruiz Dorantes {
34*cd6365c7SJérôme Duval if (fDescriptor > 0) {
35ccf28e4dSOliver Ruiz Dorantes close(fDescriptor);
36ccf28e4dSOliver Ruiz Dorantes fDescriptor = -1;
37ccf28e4dSOliver Ruiz Dorantes fIdentifier = B_ERROR;
38ccf28e4dSOliver Ruiz Dorantes }
39ccf28e4dSOliver Ruiz Dorantes }
40ccf28e4dSOliver Ruiz Dorantes
41ccf28e4dSOliver Ruiz Dorantes
4230f1d1f3SOliver Ruiz Dorantes status_t
IssueCommand(raw_command rc,size_t size)4330f1d1f3SOliver Ruiz Dorantes HCITransportAccessor::IssueCommand(raw_command rc, size_t size)
4430f1d1f3SOliver Ruiz Dorantes {
45ccf28e4dSOliver Ruiz Dorantes if (Id() < 0 || fDescriptor < 0)
4630f1d1f3SOliver Ruiz Dorantes return B_ERROR;
477a74a5dfSFredrik Modéen /*
48009fac99SOliver Ruiz Dorantes printf("### Command going: len = %ld\n", size);
49009fac99SOliver Ruiz Dorantes for (uint16 index = 0 ; index < size; index++ ) {
5030f1d1f3SOliver Ruiz Dorantes printf("%x:",((uint8*)rc)[index]);
5130f1d1f3SOliver Ruiz Dorantes }
52009fac99SOliver Ruiz Dorantes printf("### \n");
537a74a5dfSFredrik Modéen */
5430f1d1f3SOliver Ruiz Dorantes
55ccf28e4dSOliver Ruiz Dorantes return ioctl(fDescriptor, ISSUE_BT_COMMAND, rc, size);
5630f1d1f3SOliver Ruiz Dorantes }
5748cca06aSOliver Ruiz Dorantes
5848cca06aSOliver Ruiz Dorantes
5948cca06aSOliver Ruiz Dorantes status_t
Launch()6048cca06aSOliver Ruiz Dorantes HCITransportAccessor::Launch() {
6148cca06aSOliver Ruiz Dorantes
62d04eb939SOliver Ruiz Dorantes uint32 dummy;
63ccf28e4dSOliver Ruiz Dorantes return ioctl(fDescriptor, BT_UP, &dummy, sizeof(uint32));
6448cca06aSOliver Ruiz Dorantes
6548cca06aSOliver Ruiz Dorantes }
66