• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements.  See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership.  The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License.  You may obtain a copy of the License at
9  *
10  *  http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied.  See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
20 #ifndef H_BLE_HS_HCI_PRIV_
21 #define H_BLE_HS_HCI_PRIV_
22 
23 #include "nimble/hci_common.h"
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 struct ble_hs_conn;
29 struct os_mbuf;
30 
31 #define BLE_HS_HCI_LE_FEAT_ENCRYPTION                   (0x00000001)
32 #define BLE_HS_HCI_LE_FEAT_CONN_PARAM_REQUEST           (0x00000002)
33 #define BLE_HS_HCI_LE_FEAT_EXT_REJECT                   (0x00000004)
34 #define BLE_HS_HCI_LE_FEAT_SLAVE_FEAT_EXCHANGE          (0x00000008)
35 #define BLE_HS_HCI_LE_FEAT_PING                         (0x00000010)
36 #define BLE_HS_HCI_LE_FEAT_DATA_PACKET_LENGTH_EXT       (0x00000020)
37 #define BLE_HS_HCI_LE_FEAT_LL_PRIVACY                   (0x00000040)
38 #define BLE_HS_HCI_LE_FEAT_EXT_SCANNER_FILTER_POLICIES  (0x00000080)
39 #define BLE_HS_HCI_LE_FEAT_2M_PHY                       (0x00000100)
40 #define BLE_HS_HCI_LE_FEAT_STABLE_MOD_INDEX_TX          (0x00000200)
41 #define BLE_HS_HCI_LE_FEAT_STABLE_MOD_INDEX_RX          (0x00000400)
42 #define BLE_HS_HCI_LE_FEAT_CODED_PHY                    (0x00000800)
43 #define BLE_HS_HCI_LE_FEAT_EXT_ADV                      (0x00001000)
44 #define BLE_HS_HCI_LE_FEAT_PERIODIC_ADV                 (0x00002000)
45 #define BLE_HS_HCI_LE_FEAT_CSA2                         (0x00004000)
46 #define BLE_HS_HCI_LE_FEAT_POWER_CLASS_1                (0x00008000)
47 #define BLE_HS_HCI_LE_FEAT_MIN_NUM_USED_CHAN            (0x00010000)
48 
49 struct ble_hs_hci_ack {
50     int bha_status;         /* A BLE_HS_E<...> error; NOT a naked HCI code. */
51     const uint8_t *bha_params;
52     int bha_params_len;
53     uint16_t bha_opcode;
54     uint8_t bha_hci_handle;
55 };
56 
57 #if MYNEWT_VAL(BLE_EXT_ADV)
58 struct ble_hs_hci_ext_scan_param {
59     uint8_t scan_type;
60     uint16_t scan_itvl;
61     uint16_t scan_window;
62 };
63 
64 struct ble_hs_hci_ext_conn_params {
65     uint16_t scan_itvl;
66     uint16_t scan_window;
67     uint16_t conn_itvl;
68     uint16_t conn_windows;
69 };
70 
71 #if MYNEWT_VAL(BLE_PERIODIC_ADV)
72 /* Periodic Advertising Parameters */
73 struct hci_periodic_adv_params {
74     uint16_t min_interval;
75     uint16_t max_interval;
76     uint16_t properties;
77 };
78 #endif
79 #endif
80 
81 extern uint16_t ble_hs_hci_avail_pkts;
82 
83 int ble_hs_hci_cmd_tx(uint16_t opcode, const void *cmd, uint8_t cmd_len,
84                       void *rsp, uint8_t rsp_len);
85 void ble_hs_hci_init(void);
86 void ble_hs_hci_deinit(void);
87 
88 void ble_hs_hci_set_le_supported_feat(uint32_t feat);
89 uint32_t ble_hs_hci_get_le_supported_feat(void);
90 void ble_hs_hci_set_hci_version(uint8_t hci_version);
91 uint8_t ble_hs_hci_get_hci_version(void);
92 
93 #if MYNEWT_VAL(BLE_HS_PHONY_HCI_ACKS)
94 typedef int ble_hs_hci_phony_ack_fn(uint8_t *ack, int ack_buf_len);
95 void ble_hs_hci_set_phony_ack_cb(ble_hs_hci_phony_ack_fn *cb);
96 #endif
97 
98 int ble_hs_hci_util_read_adv_tx_pwr(int8_t *out_pwr);
99 int ble_hs_hci_util_rand(void *dst, int len);
100 int ble_hs_hci_util_read_rssi(uint16_t conn_handle, int8_t *out_rssi);
101 int ble_hs_hci_util_set_random_addr(const uint8_t *addr);
102 int ble_hs_hci_util_set_data_len(uint16_t conn_handle, uint16_t tx_octets,
103                                  uint16_t tx_time);
104 int ble_hs_hci_util_data_hdr_strip(struct os_mbuf *om,
105                                    struct hci_data_hdr *out_hdr);
106 int ble_hs_hci_evt_process(const struct ble_hci_ev *ev);
107 
108 int ble_hs_hci_cmd_send_buf(uint16_t opcode, const void *buf, uint8_t buf_len);
109 int ble_hs_hci_set_buf_sz(uint16_t pktlen, uint16_t max_pkts);
110 int ble_hs_hci_set_tx_buf_sz(uint16_t pktlen);
111 void ble_hs_hci_add_avail_pkts(uint16_t delta);
112 
113 uint16_t ble_hs_hci_util_handle_pb_bc_join(uint16_t handle, uint8_t pb, uint8_t bc);
114 
115 int ble_hs_hci_acl_tx_now(struct ble_hs_conn *conn, struct os_mbuf **om);
116 int ble_hs_hci_acl_tx(struct ble_hs_conn *conn, struct os_mbuf **om);
117 
118 int ble_hs_hci_frag_num_mbufs(void);
119 int ble_hs_hci_frag_num_mbufs_free(void);
120 
121 #ifdef __cplusplus
122 }
123 #endif
124 
125 #endif