Home | History | Annotate | Download | only in include
      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 #pragma once
     20 
     21 #include <stdbool.h>
     22 
     23 #include "osi/include/allocator.h"
     24 #include "osi/include/data_dispatcher.h"
     25 #include "osi/include/fixed_queue.h"
     26 #include "osi/include/future.h"
     27 #include "osi/include/osi.h"
     28 #include "bt_types.h"
     29 
     30 static const char HCI_MODULE[] = "hci_module";
     31 
     32 ///// LEGACY DEFINITIONS /////
     33 
     34 /* Message event mask across Host/Controller lib and stack */
     35 #define MSG_EVT_MASK                    0xFF00 /* eq. BT_EVT_MASK */
     36 #define MSG_SUB_EVT_MASK                0x00FF /* eq. BT_SUB_EVT_MASK */
     37 
     38 /* Message event ID passed from Host/Controller lib to stack */
     39 #define MSG_HC_TO_STACK_HCI_ERR        0x1300 /* eq. BT_EVT_TO_BTU_HCIT_ERR */
     40 #define MSG_HC_TO_STACK_HCI_ACL        0x1100 /* eq. BT_EVT_TO_BTU_HCI_ACL */
     41 #define MSG_HC_TO_STACK_HCI_SCO        0x1200 /* eq. BT_EVT_TO_BTU_HCI_SCO */
     42 #define MSG_HC_TO_STACK_HCI_EVT        0x1000 /* eq. BT_EVT_TO_BTU_HCI_EVT */
     43 #define MSG_HC_TO_STACK_L2C_SEG_XMIT   0x1900 /* eq. BT_EVT_TO_BTU_L2C_SEG_XMIT */
     44 
     45 /* Message event ID passed from stack to vendor lib */
     46 #define MSG_STACK_TO_HC_HCI_ACL        0x2100 /* eq. BT_EVT_TO_LM_HCI_ACL */
     47 #define MSG_STACK_TO_HC_HCI_SCO        0x2200 /* eq. BT_EVT_TO_LM_HCI_SCO */
     48 #define MSG_STACK_TO_HC_HCI_CMD        0x2000 /* eq. BT_EVT_TO_LM_HCI_CMD */
     49 
     50 /* Local Bluetooth Controller ID for BR/EDR */
     51 #define LOCAL_BR_EDR_CONTROLLER_ID      0
     52 
     53 ///// END LEGACY DEFINITIONS /////
     54 
     55 typedef struct hci_hal_t hci_hal_t;
     56 typedef struct btsnoop_t btsnoop_t;
     57 typedef struct controller_t controller_t;
     58 typedef struct hci_inject_t hci_inject_t;
     59 typedef struct packet_fragmenter_t packet_fragmenter_t;
     60 typedef struct vendor_t vendor_t;
     61 typedef struct low_power_manager_t low_power_manager_t;
     62 
     63 typedef unsigned char * bdaddr_t;
     64 typedef uint16_t command_opcode_t;
     65 
     66 typedef enum {
     67   LPM_DISABLE,
     68   LPM_ENABLE,
     69   LPM_WAKE_ASSERT,
     70   LPM_WAKE_DEASSERT
     71 } low_power_command_t;
     72 
     73 typedef void (*command_complete_cb)(BT_HDR *response, void *context);
     74 typedef void (*command_status_cb)(uint8_t status, BT_HDR *command, void *context);
     75 
     76 typedef struct hci_t {
     77   // Send a low power command, if supported and the low power manager is enabled.
     78   void (*send_low_power_command)(low_power_command_t command);
     79 
     80   // Do the postload sequence (call after the rest of the BT stack initializes).
     81   void (*do_postload)(void);
     82 
     83   // Register with this data dispatcher to receive events flowing upward out of the HCI layer
     84   data_dispatcher_t *event_dispatcher;
     85 
     86   // Set the queue to receive ACL data in
     87   void (*set_data_queue)(fixed_queue_t *queue);
     88 
     89   // Send a command through the HCI layer
     90   void (*transmit_command)(
     91       BT_HDR *command,
     92       command_complete_cb complete_callback,
     93       command_status_cb status_cb,
     94       void *context
     95   );
     96 
     97   future_t *(*transmit_command_futured)(BT_HDR *command);
     98 
     99   // Send some data downward through the HCI layer
    100   void (*transmit_downward)(data_dispatcher_type_t type, void *data);
    101 } hci_t;
    102 
    103 const hci_t *hci_layer_get_interface();
    104 
    105 const hci_t *hci_layer_get_test_interface(
    106     const allocator_t *buffer_allocator_interface,
    107     const hci_hal_t *hal_interface,
    108     const btsnoop_t *btsnoop_interface,
    109     const hci_inject_t *hci_inject_interface,
    110     const packet_fragmenter_t *packet_fragmenter_interface,
    111     const vendor_t *vendor_interface,
    112     const low_power_manager_t *low_power_manager_interface);
    113 
    114 void hci_layer_cleanup_interface();
    115