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