1/*
2 * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
3 *
4 * All rights reserved. Distributed under the terms of the MIT License.
5 *
6 */
7
8#ifndef _H2GENERIC_H_
9#define _H2GENERIC_H_
10
11#include <net_buffer.h>
12#include <net_device.h>
13
14#include <OS.h>
15#ifdef HAIKU_TARGET_PLATFORM_HAIKU
16#include <USB3.h>
17#else
18#include <USB_spec.h>
19#include <USB.h>
20#endif
21
22#include <util/list.h>
23#include <bluetooth/HCI/btHCI.h>
24#include <bluetooth/HCI/btHCI_transport.h>
25
26#include <btCoreData.h>
27
28#include "snet_buffer.h"
29
30// USB definitions for the generic device move to h2cfg
31#define UDCLASS_WIRELESS	0xe0
32#define UDSUBCLASS_RF		0x01
33#define UDPROTO_BLUETOOTH	0x01
34
35#define BLUETOOTH_DEVICE_TRANSPORT	"h2"
36#define BLUETOOTH_DEVICE_NAME "generic"
37#include "h2cfg.h"
38
39#define USB_TYPE_CLASS			(0x01 << 5)  /// Check if it is in some other header
40#define USB_TYPE_VENDOR			(0x02 << 5)
41
42
43// Expecting nobody is gonna have 16 USB-BT dongles connected in their system
44#define MAX_BT_GENERIC_USB_DEVICES	16
45
46extern usb_module_info* usb;
47extern bt_hci_module_info* hci;
48extern struct bt_hci_module_info* btDevices;
49extern struct net_buffer_module_info* nb;
50extern struct bluetooth_core_data_module_info* btCoreData;
51
52#define MAX_COMMAND_WINDOW 1
53#define MAX_ACL_OUT_WINDOW 4
54#define MAX_ACL_IN_WINDOW  1
55
56#define MAX_NUM_QUEUED_PACKETS 1
57#define NUM_BUFFERS 1
58
59typedef struct bt_usb_dev bt_usb_dev;
60
61struct bt_usb_dev {
62#ifdef HAIKU_TARGET_PLATFORM_HAIKU
63	usb_device		dev;          /* opaque handle */
64#else
65	usb_device*		dev;          /* opaque handle */
66#endif
67	hci_id					hdev; /* HCI device id*/
68	bluetooth_device*		ndev;
69
70	char			name[B_OS_NAME_LENGTH];
71	bool			connected;    /* is the device plugged into the USB? */
72	int32			open_count;   /* number of clients of the device */
73	int32			num;          /* instance number of the device */
74
75	sem_id			lock;         /* synchronize access to the device */
76	sem_id			cmd_complete; /* To synchronize completitions */
77
78	size_t			actual_len;   /* length of data returned by command */
79	status_t		cmd_status;   /* result of command */
80
81	uint8				ctrl_req;
82	uint8				driver_info;
83	uint32				state;
84
85	bt_hci_statistics	stat;
86
87	const	usb_endpoint_info*	bulk_in_ep;
88			uint16				max_packet_size_bulk_in;
89	const	usb_endpoint_info*	bulk_out_ep;
90			uint16				max_packet_size_bulk_out;
91	const	usb_endpoint_info*	intr_in_ep;
92			uint16				max_packet_size_intr_in;
93
94#ifdef BLUETOOTH_SUPPORTS_SCO
95	const usb_endpoint_info	*iso_in_ep;
96	const usb_endpoint_info	*iso_out_ep;
97#endif
98
99	/* This so called rooms, are for dumping the USB RX frames
100	 * and try to reuse the allocations. see util submodule
101	 */
102	struct list eventRoom;
103	struct list aclRoom;
104
105	// Tx buffers: net_buffers for BT_ACL and snet_buffers for BT_COMMAND
106	// in the same array
107	struct list	nbuffersTx[BT_DRIVER_TXCOVERAGE];
108	uint32		nbuffersPendingTx[BT_DRIVER_TXCOVERAGE];
109
110	// Rx buffer
111	net_buffer*		nbufferRx[BT_DRIVER_RXCOVERAGE];
112	snet_buffer*	eventRx;
113
114	// for who ever needs preallocated buffers
115	struct list		snetBufferRecycleTrash;
116
117};
118
119bt_usb_dev* fetch_device(bt_usb_dev* dev, hci_id hid);
120
121#endif
122