xref: /haiku/src/servers/bluetooth/HCITransportAccessor.cpp (revision 5ac9b506412b11afb993bb52d161efe7666958a5)
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 		close(fDescriptor);
36 		fDescriptor = -1;
37 		fIdentifier = B_ERROR;
38 	}
39 }
40 
41 
42 status_t
43 HCITransportAccessor::IssueCommand(raw_command rc, size_t size)
44 {
45 	if (Id() < 0 || fDescriptor < 0)
46 		return B_ERROR;
47 /*
48 printf("### Command going: len = %ld\n", size);
49 for (uint16 index = 0 ; index < size; index++ ) {
50 	printf("%x:",((uint8*)rc)[index]);
51 }
52 printf("### \n");
53 */
54 
55 	return ioctl(fDescriptor, ISSUE_BT_COMMAND, rc, size);
56 }
57 
58 
59 status_t
60 HCITransportAccessor::Launch() {
61 
62 	uint32 dummy;
63 	return ioctl(fDescriptor, BT_UP, &dummy, sizeof(uint32));
64 
65 }
66