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