xref: /haiku/headers/os/bluetooth/HCI/btHCI_transport.h (revision bb83316a5811a550c4f850d07fa8e328e7ac0a94)
1b06bf23fSOliver Ruiz Dorantes /*
2b06bf23fSOliver Ruiz Dorantes  * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
3b06bf23fSOliver Ruiz Dorantes  * All rights reserved. Distributed under the terms of the MIT License.
4b06bf23fSOliver Ruiz Dorantes  */
5b06bf23fSOliver Ruiz Dorantes #ifndef _BTHCI_TRANSPORT_H_
6b06bf23fSOliver Ruiz Dorantes #define _BTHCI_TRANSPORT_H_
7b06bf23fSOliver Ruiz Dorantes 
8b06bf23fSOliver Ruiz Dorantes #include <bluetooth/HCI/btHCI.h>
9b06bf23fSOliver Ruiz Dorantes 
109760dcaeSOliver Ruiz Dorantes #include <util/DoublyLinkedList.h>
119760dcaeSOliver Ruiz Dorantes 
12fc892ed4SOliver Ruiz Dorantes #include <net_buffer.h>
13d816d816SOliver Ruiz Dorantes #include <Drivers.h>
14b06bf23fSOliver Ruiz Dorantes 
159760dcaeSOliver Ruiz Dorantes 
169760dcaeSOliver Ruiz Dorantes typedef enum {
179760dcaeSOliver Ruiz Dorantes 	ANCILLYANT = (1<<0),
18d04eb939SOliver Ruiz Dorantes 	RUNNING = (1<<1),
19d04eb939SOliver Ruiz Dorantes 	LEAVING = (1<<2),
20d04eb939SOliver Ruiz Dorantes 	SENDING = (1<<3),
21d04eb939SOliver Ruiz Dorantes 	PROCESSING = (1<<4)
22b06bf23fSOliver Ruiz Dorantes } bt_transport_status_t;
23b06bf23fSOliver Ruiz Dorantes 
249760dcaeSOliver Ruiz Dorantes 
25b06bf23fSOliver Ruiz Dorantes typedef uint8 bt_stat_t;
26b06bf23fSOliver Ruiz Dorantes typedef struct bt_hci_statistics {
27b06bf23fSOliver Ruiz Dorantes 	bt_stat_t acceptedTX;
28b06bf23fSOliver Ruiz Dorantes 	bt_stat_t rejectedTX;
29b06bf23fSOliver Ruiz Dorantes 	bt_stat_t successfulTX;
30b06bf23fSOliver Ruiz Dorantes 	bt_stat_t errorTX;
31b06bf23fSOliver Ruiz Dorantes 
32b06bf23fSOliver Ruiz Dorantes 	bt_stat_t acceptedRX;
33b06bf23fSOliver Ruiz Dorantes 	bt_stat_t rejectedRX;
34b06bf23fSOliver Ruiz Dorantes 	bt_stat_t successfulRX;
35b06bf23fSOliver Ruiz Dorantes 	bt_stat_t errorRX;
36b06bf23fSOliver Ruiz Dorantes 
37b06bf23fSOliver Ruiz Dorantes 	bt_stat_t commandTX;
38b06bf23fSOliver Ruiz Dorantes 	bt_stat_t eventRX;
39b06bf23fSOliver Ruiz Dorantes 	bt_stat_t aclTX;
40b06bf23fSOliver Ruiz Dorantes 	bt_stat_t aclRX;
41b06bf23fSOliver Ruiz Dorantes 	bt_stat_t scoTX;
42b06bf23fSOliver Ruiz Dorantes 	bt_stat_t scoRX;
43b06bf23fSOliver Ruiz Dorantes 	bt_stat_t escoTX;
44b06bf23fSOliver Ruiz Dorantes 	bt_stat_t escoRX;
45b06bf23fSOliver Ruiz Dorantes 
46b06bf23fSOliver Ruiz Dorantes 	bt_stat_t bytesRX;
47b06bf23fSOliver Ruiz Dorantes 	bt_stat_t bytesTX;
48b06bf23fSOliver Ruiz Dorantes } bt_hci_statistics;
49b06bf23fSOliver Ruiz Dorantes 
50b06bf23fSOliver Ruiz Dorantes 
51b06bf23fSOliver Ruiz Dorantes typedef struct bt_hci_device {
52b06bf23fSOliver Ruiz Dorantes 	transport_type	kind;
53b06bf23fSOliver Ruiz Dorantes 	char			realName[B_OS_NAME_LENGTH];
54b06bf23fSOliver Ruiz Dorantes } bt_hci_device;
55b06bf23fSOliver Ruiz Dorantes 
56b06bf23fSOliver Ruiz Dorantes 
579760dcaeSOliver Ruiz Dorantes /* Hooks which drivers will have to provide.
589760dcaeSOliver Ruiz Dorantes  * The structure is meant to be allocated in driver side and
599760dcaeSOliver Ruiz Dorantes  * provided to the HCI where it will fill the remaining fields
609760dcaeSOliver Ruiz Dorantes  */
619760dcaeSOliver Ruiz Dorantes typedef struct bt_hci_transport_hooks {
629760dcaeSOliver Ruiz Dorantes 
639760dcaeSOliver Ruiz Dorantes 	// to be filled by driver
649760dcaeSOliver Ruiz Dorantes 	status_t	(*SendCommand)(hci_id hciId, void* command);
659760dcaeSOliver Ruiz Dorantes 	status_t	(*SendACL)(hci_id hciId, net_buffer* nbuf);
669760dcaeSOliver Ruiz Dorantes 	status_t	(*SendSCO)(hci_id hciId, net_buffer* nbuf);
679760dcaeSOliver Ruiz Dorantes 	status_t	(*SendESCO)(hci_id hciId, net_buffer* nbuf);
689760dcaeSOliver Ruiz Dorantes 
699760dcaeSOliver Ruiz Dorantes 	status_t	(*DeliverStatistics)(hci_id hciId, bt_hci_statistics* statistics);
709760dcaeSOliver Ruiz Dorantes 
719760dcaeSOliver Ruiz Dorantes 	transport_type kind;
729760dcaeSOliver Ruiz Dorantes 
739760dcaeSOliver Ruiz Dorantes } bt_hci_transport_hooks;
749760dcaeSOliver Ruiz Dorantes 
759760dcaeSOliver Ruiz Dorantes typedef struct bt_hci_device_information {
769760dcaeSOliver Ruiz Dorantes 
779760dcaeSOliver Ruiz Dorantes 	uint32	flags;
789760dcaeSOliver Ruiz Dorantes 	uint16	vendorId;
799760dcaeSOliver Ruiz Dorantes 	uint16	deviceId;
809760dcaeSOliver Ruiz Dorantes 	char	name[B_OS_NAME_LENGTH];
819760dcaeSOliver Ruiz Dorantes 
829760dcaeSOliver Ruiz Dorantes } bt_hci_device_information;
839760dcaeSOliver Ruiz Dorantes 
849760dcaeSOliver Ruiz Dorantes 
859760dcaeSOliver Ruiz Dorantes #ifdef __cplusplus
869760dcaeSOliver Ruiz Dorantes 
879760dcaeSOliver Ruiz Dorantes struct bluetooth_device : DoublyLinkedListLinkImpl<bluetooth_device> {
889760dcaeSOliver Ruiz Dorantes 
899760dcaeSOliver Ruiz Dorantes 	net_buffer*	fBuffersRx[HCI_NUM_PACKET_TYPES];
909760dcaeSOliver Ruiz Dorantes 	size_t		fExpectedPacketSize[HCI_NUM_PACKET_TYPES];
919760dcaeSOliver Ruiz Dorantes 	hci_id		index;
929760dcaeSOliver Ruiz Dorantes 
93*62f5ba00SOliver Ruiz Dorantes 	uint16		supportedPacketTypes;
94*62f5ba00SOliver Ruiz Dorantes 	uint16		linkMode;
959760dcaeSOliver Ruiz Dorantes 	int			fd;
969760dcaeSOliver Ruiz Dorantes 
979760dcaeSOliver Ruiz Dorantes 	bt_hci_device_information*	info;
989760dcaeSOliver Ruiz Dorantes 	bt_hci_transport_hooks*		hooks;
999760dcaeSOliver Ruiz Dorantes 	uint16						mtu;
1009760dcaeSOliver Ruiz Dorantes 
1019760dcaeSOliver Ruiz Dorantes };
1029760dcaeSOliver Ruiz Dorantes 
1039760dcaeSOliver Ruiz Dorantes #else
1049760dcaeSOliver Ruiz Dorantes 
1059760dcaeSOliver Ruiz Dorantes struct bluetooth_device;
1069760dcaeSOliver Ruiz Dorantes 
1079760dcaeSOliver Ruiz Dorantes #endif
1089760dcaeSOliver Ruiz Dorantes 
1099760dcaeSOliver Ruiz Dorantes 
1109760dcaeSOliver Ruiz Dorantes #define BT_HCI_MODULE_NAME "bluetooth/hci/v1"
1119760dcaeSOliver Ruiz Dorantes 
1129760dcaeSOliver Ruiz Dorantes // Possible definition of a bus manager
1139760dcaeSOliver Ruiz Dorantes typedef struct bt_hci_module_info {
1149760dcaeSOliver Ruiz Dorantes 	module_info info;
1159760dcaeSOliver Ruiz Dorantes 	// Registration in Stack
1169760dcaeSOliver Ruiz Dorantes 	status_t			(*RegisterDriver)(bt_hci_transport_hooks* hooks,
1179760dcaeSOliver Ruiz Dorantes 							bluetooth_device** device);
1189760dcaeSOliver Ruiz Dorantes 	status_t			(*UnregisterDriver)(hci_id id);
1199760dcaeSOliver Ruiz Dorantes 	bluetooth_device*	(*FindDeviceByID)(hci_id id);
1209760dcaeSOliver Ruiz Dorantes 
1219760dcaeSOliver Ruiz Dorantes 	// to be called from transport driver
1229760dcaeSOliver Ruiz Dorantes 	status_t			(*PostTransportPacket)(hci_id hid, bt_packet_t type,
1239760dcaeSOliver Ruiz Dorantes 							void* data, size_t count);
1249760dcaeSOliver Ruiz Dorantes 
1259760dcaeSOliver Ruiz Dorantes 	// To be called from upper layers
1269760dcaeSOliver Ruiz Dorantes 	status_t		(*PostACL)(hci_id hciId, net_buffer* buffer);
1279760dcaeSOliver Ruiz Dorantes 	status_t		(*PostSCO)(hci_id hciId, net_buffer* buffer);
1289760dcaeSOliver Ruiz Dorantes 	status_t		(*PostESCO)(hci_id hciId, net_buffer* buffer);
1299760dcaeSOliver Ruiz Dorantes 
1309760dcaeSOliver Ruiz Dorantes } bt_hci_module_info ;
1319760dcaeSOliver Ruiz Dorantes 
1329760dcaeSOliver Ruiz Dorantes 
1339760dcaeSOliver Ruiz Dorantes /* Here the transport driver have some flags that
1349760dcaeSOliver Ruiz Dorantes  * can be used to inform the upper layer about some
1359760dcaeSOliver Ruiz Dorantes  * special behaouvior to perform */
136b06bf23fSOliver Ruiz Dorantes 
137b06bf23fSOliver Ruiz Dorantes #define BT_IGNORE_THIS_DEVICE	(1 << 0)
138b06bf23fSOliver Ruiz Dorantes #define BT_SCO_NOT_WORKING		(1 << 1)
139b06bf23fSOliver Ruiz Dorantes #define BT_WILL_NEED_A_RESET	(1 << 2)
140b06bf23fSOliver Ruiz Dorantes #define BT_DIGIANSWER			(1 << 4)
141b06bf23fSOliver Ruiz Dorantes 
1429760dcaeSOliver Ruiz Dorantes // Mandatory IOCTLS
143d816d816SOliver Ruiz Dorantes #define BT_IOCTLS_OFFSET 3000
144d816d816SOliver Ruiz Dorantes 
145d816d816SOliver Ruiz Dorantes enum {
146a1163de8SOliver Ruiz Dorantes 	ISSUE_BT_COMMAND = B_DEVICE_OP_CODES_END + BT_IOCTLS_OFFSET, // 12999
1476ac63f93SFrançois Revol 	GET_STATS,
148d816d816SOliver Ruiz Dorantes 	GET_NOTIFICATION_PORT,
149ded32592SOliver Ruiz Dorantes 	GET_HCI_ID,
150ded32592SOliver Ruiz Dorantes 	BT_UP
151d816d816SOliver Ruiz Dorantes };
152b06bf23fSOliver Ruiz Dorantes 
153*62f5ba00SOliver Ruiz Dorantes // To deprecate ...
154b06bf23fSOliver Ruiz Dorantes #define PACK_PORTCODE(type,hid,data) ((type & 0xFF) << 24 | (hid & 0xFF) << 16 | (data & 0xFFFF))
155c9502bbeSOliver Ruiz Dorantes #define GET_PORTCODE_TYPE(code) ((code & 0xFF000000) >> 24)
156c9502bbeSOliver Ruiz Dorantes #define GET_PORTCODE_HID(code) ((code & 0x00FF0000) >> 16)
157c9502bbeSOliver Ruiz Dorantes #define GET_PORTCODE_DATA(code) ((code & 0x0000FFFF))
158b06bf23fSOliver Ruiz Dorantes 
159b06bf23fSOliver Ruiz Dorantes /*  Port drivers can use to send information (1 for all for
160b06bf23fSOliver Ruiz Dorantes 	at moment refer to ioctl GET_NOTIFICATION_PORT)*/
1619760dcaeSOliver Ruiz Dorantes #define BT_USERLAND_PORT_NAME "BT Kernel-User Event"
1629760dcaeSOliver Ruiz Dorantes #define BT_RX_PORT_NAME "BT Kernel RX assembly"
16307e4b460SOliver Ruiz Dorantes #define BLUETOOTH_CONNECTION_PORT "bluetooth connection port"
164b06bf23fSOliver Ruiz Dorantes 
165001662aeSOliver Ruiz Dorantes #endif // _BTHCI_TRANSPORT_H_
166