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 #ifndef _H2GENERIC_H_ 8 #define _H2GENERIC_H_ 9 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 31 // USB definitions for the generic device move to h2cfg 32 #define UDCLASS_WIRELESS 0xe0 33 #define UDSUBCLASS_RF 0x01 34 #define UDPROTO_BLUETOOTH 0x01 35 36 #define BLUETOOTH_DEVICE_TRANSPORT "h2" 37 #define BLUETOOTH_DEVICE_NAME "generic" 38 #include "h2cfg.h" 39 40 #define USB_TYPE_CLASS (0x01 << 5) /// Check if it is in some other header 41 #define USB_TYPE_VENDOR (0x02 << 5) 42 43 #define TOUCH(x) ((void)(x)) 44 45 // Expecting nobody is gonna have 16 USB-BT dongles connected in their system 46 #define MAX_BT_GENERIC_USB_DEVICES 16 47 48 extern usb_module_info* usb; 49 extern bt_hci_module_info* hci; 50 extern struct bt_hci_module_info* btDevices; 51 extern struct net_buffer_module_info* nb; 52 extern struct bluetooth_core_data_module_info* btCoreData; 53 54 #define MAX_COMMAND_WINDOW 1 55 #define MAX_ACL_OUT_WINDOW 4 56 #define MAX_ACL_IN_WINDOW 1 57 58 #define MAX_NUM_QUEUED_PACKETS 1 59 #define NUM_BUFFERS 1 60 61 typedef struct bt_usb_dev bt_usb_dev; 62 63 struct bt_usb_dev { 64 #ifdef HAIKU_TARGET_PLATFORM_HAIKU 65 usb_device dev; /* opaque handle */ 66 #else 67 usb_device* dev; /* opaque handle */ 68 #endif 69 hci_id hdev; /* HCI device id*/ 70 bluetooth_device* ndev; 71 72 char name[B_OS_NAME_LENGTH]; 73 bool connected; /* is the device plugged into the USB? */ 74 int32 open_count; /* number of clients of the device */ 75 int32 num; /* instance number of the device */ 76 77 sem_id lock; /* synchronize access to the device */ 78 sem_id cmd_complete; /* To synchronize completitions */ 79 80 size_t actual_len; /* length of data returned by command */ 81 status_t cmd_status; /* result of command */ 82 83 uint8 ctrl_req; 84 uint8 driver_info; 85 uint32 state; 86 87 bt_hci_statistics stat; 88 89 const usb_endpoint_info* bulk_in_ep; 90 uint16 max_packet_size_bulk_in; 91 const usb_endpoint_info* bulk_out_ep; 92 uint16 max_packet_size_bulk_out; 93 const usb_endpoint_info* intr_in_ep; 94 uint16 max_packet_size_intr_in; 95 96 #ifdef BLUETOOTH_SUPPORTS_SCO 97 const usb_endpoint_info *iso_in_ep; 98 const usb_endpoint_info *iso_out_ep; 99 #endif 100 101 /* This so called rooms, are for dumping the USB RX frames 102 * and try to reuse the allocations. see util submodule 103 */ 104 struct list eventRoom; 105 struct list aclRoom; 106 107 // Tx buffers: net_buffers for BT_ACL and snet_buffers for BT_COMMAND 108 // in the same array 109 struct list nbuffersTx[BT_DRIVER_TXCOVERAGE]; 110 uint32 nbuffersPendingTx[BT_DRIVER_TXCOVERAGE]; 111 112 // Rx buffer 113 net_buffer* nbufferRx[BT_DRIVER_RXCOVERAGE]; 114 snet_buffer* eventRx; 115 116 // for who ever needs preallocated buffers 117 struct list snetBufferRecycleTrash; 118 119 }; 120 121 bt_usb_dev* fetch_device(bt_usb_dev* dev, hci_id hid); 122 123 124 static inline uint32 125 TEST_AND_SET(uint32 *byte, uint32 bit_mask) 126 { 127 uint32 val = (*byte&bit_mask)!=0; 128 *byte |= bit_mask; 129 return val; 130 } 131 132 133 static inline uint32 134 TEST_AND_CLEAR(uint32* byte, uint32 bit_mask) 135 { 136 uint32 val = (*byte&bit_mask)!=0; 137 *byte &= ~bit_mask; 138 return val; 139 } 140 141 142 #endif 143