1 /****************************************************************************** 2 * 3 * Copyright (C) 2014 Google, Inc. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 #ifndef _HCI_LAYER_H_ 20 #define _HCI_LAYER_H_ 21 22 #include "common/bt_target.h" 23 #include "stack/bt_types.h" 24 #include "osi/allocator.h" 25 #include "osi/osi.h" 26 #include "osi/future.h" 27 #include "osi/thread.h" 28 #include "osi/pkt_queue.h" 29 30 ///// LEGACY DEFINITIONS ///// 31 32 /* Message event mask across Host/Controller lib and stack */ 33 #define MSG_EVT_MASK 0xFF00 /* eq. BT_EVT_MASK */ 34 #define MSG_SUB_EVT_MASK 0x00FF /* eq. BT_SUB_EVT_MASK */ 35 36 /* Message event ID passed from Host/Controller lib to stack */ 37 #define MSG_HC_TO_STACK_HCI_ERR 0x1300 /* eq. BT_EVT_TO_BTU_HCIT_ERR */ 38 #define MSG_HC_TO_STACK_HCI_ACL 0x1100 /* eq. BT_EVT_TO_BTU_HCI_ACL */ 39 #define MSG_HC_TO_STACK_HCI_SCO 0x1200 /* eq. BT_EVT_TO_BTU_HCI_SCO */ 40 #define MSG_HC_TO_STACK_HCI_EVT 0x1000 /* eq. BT_EVT_TO_BTU_HCI_EVT */ 41 #define MSG_HC_TO_STACK_L2C_SEG_XMIT 0x1900 /* eq. BT_EVT_TO_BTU_L2C_SEG_XMIT */ 42 43 /* Message event ID passed from stack to vendor lib */ 44 #define MSG_STACK_TO_HC_HCI_ACL 0x2100 /* eq. BT_EVT_TO_LM_HCI_ACL */ 45 #define MSG_STACK_TO_HC_HCI_SCO 0x2200 /* eq. BT_EVT_TO_LM_HCI_SCO */ 46 #define MSG_STACK_TO_HC_HCI_CMD 0x2000 /* eq. BT_EVT_TO_LM_HCI_CMD */ 47 48 /* Local Bluetooth Controller ID for BR/EDR */ 49 #define LOCAL_BR_EDR_CONTROLLER_ID 0 50 51 #define HCI_CMD_MSG_F_VND_FUTURE (0x01) 52 #define HCI_CMD_MSG_F_VND_QUEUED (0x02) 53 #define HCI_CMD_MSG_F_VND_SENT (0x04) 54 ///// END LEGACY DEFINITIONS ///// 55 56 typedef struct hci_hal_t hci_hal_t; 57 //typedef struct btsnoop_t btsnoop_t; 58 typedef struct controller_t controller_t; 59 //typedef struct hci_inject_t hci_inject_t; 60 typedef struct packet_fragmenter_t packet_fragmenter_t; 61 //typedef struct vendor_t vendor_t; 62 //typedef struct low_power_manager_t low_power_manager_t; 63 64 //typedef unsigned char * bdaddr_t; 65 typedef uint16_t command_opcode_t; 66 67 /* 68 typedef enum { 69 LPM_DISABLE, 70 LPM_ENABLE, 71 LPM_WAKE_ASSERT, 72 LPM_WAKE_DEASSERT 73 } low_power_command_t; 74 */ 75 76 typedef void (*command_complete_cb)(BT_HDR *response, void *context); 77 typedef void (*command_status_cb)(uint8_t status, BT_HDR *command, void *context); 78 79 typedef struct hci_t { 80 // Send a low power command, if supported and the low power manager is enabled. 81 //void (*send_low_power_command)(low_power_command_t command); 82 83 // Do the postload sequence (call after the rest of the BT stack initializes). 84 void (*do_postload)(void); 85 86 // Send a command through the HCI layer 87 void (*transmit_command)( 88 BT_HDR *command, 89 command_complete_cb complete_callback, 90 command_status_cb status_cb, 91 void *context 92 ); 93 94 future_t *(*transmit_command_futured)(BT_HDR *command); 95 96 // Send some data downward through the HCI layer 97 void (*transmit_downward)(uint16_t type, void *data); 98 } hci_t; 99 100 const hci_t *hci_layer_get_interface(void); 101 102 int hci_start_up(void); 103 void hci_shut_down(void); 104 105 bool hci_downstream_data_post(uint32_t timeout); 106 107 #if (BLE_ADV_REPORT_FLOW_CONTROL == TRUE) 108 int hci_adv_credits_prep_to_release(uint16_t num); 109 int hci_adv_credits_try_release(uint16_t num); 110 int hci_adv_credits_force_release(uint16_t num); 111 #endif 112 113 #endif /* _HCI_LAYER_H_ */ 114