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