NimBLE-Arduino 2.1.3
Loading...
Searching...
No Matches
transport.h
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_NIMBLE_TRANSPORT_
21#define H_NIMBLE_TRANSPORT_
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27#include "transport_impl.h"
28#include "transport/monitor.h"
29
30#ifdef ESP_PLATFORM
31
32#include <inttypes.h>
33#include "nimble/porting/nimble/include/os/os_mempool.h"
34
35#define BLE_HCI_TRANS_CMD_SZ 260
36/*** Type of buffers for holding commands and events. */
61#define BLE_HCI_TRANS_BUF_EVT_LO 1
62#define BLE_HCI_TRANS_BUF_EVT_HI 2
63
64/* Host-to-controller command. */
65#define BLE_HCI_TRANS_BUF_CMD 3
66
67void ble_transport_init(void);
68
69esp_err_t ble_buf_alloc(void);
70
71void ble_buf_free(void);
72
73void ble_transport_deinit(void);
74
76typedef int ble_hci_trans_rx_cmd_fn(uint8_t *cmd, void *arg);
77typedef int ble_hci_trans_rx_acl_fn(struct os_mbuf *om, void *arg);
78
79#if SOC_ESP_NIMBLE_CONTROLLER && CONFIG_BT_CONTROLLER_ENABLED
80#define ble_transport_alloc_cmd() ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD)
81#define ble_transport_alloc_event(X) ble_hci_trans_buf_alloc(X ? BLE_HCI_TRANS_BUF_EVT_LO : BLE_HCI_TRANS_BUF_EVT_HI)
82#define ble_transport_free ble_hci_trans_buf_free
83
84struct ble_hci_trans_funcs_t {
85 int(*_ble_hci_trans_hs_acl_tx)(struct os_mbuf *om);
86 int(*_ble_hci_trans_hs_cmd_tx)(uint8_t *cmd);
87 int(*_ble_hci_trans_ll_acl_tx)(struct os_mbuf *om);
88 int(*_ble_hci_trans_ll_evt_tx)(uint8_t *hci_ev);
89 int(*_ble_hci_trans_reset)(void);
90 int(*_ble_hci_trans_set_acl_free_cb)(os_mempool_put_fn *cb,void *arg);
91};
92
93extern struct ble_hci_trans_funcs_t *ble_hci_trans_funcs_ptr;
94
104extern int r_ble_hci_trans_ll_evt_tx(uint8_t *hci_ev);
105#define ble_hci_trans_ll_evt_tx ble_hci_trans_funcs_ptr->_ble_hci_trans_ll_evt_tx
106
115extern int r_ble_hci_trans_ll_acl_tx(struct os_mbuf *om);
116#define ble_hci_trans_ll_acl_tx ble_hci_trans_funcs_ptr->_ble_hci_trans_ll_acl_tx
117
127extern int r_ble_hci_trans_hs_cmd_tx(uint8_t *cmd);
128#define ble_hci_trans_hs_cmd_tx ble_hci_trans_funcs_ptr->_ble_hci_trans_hs_cmd_tx
129
138extern int r_ble_hci_trans_hs_acl_tx(struct os_mbuf *om);
139#define ble_hci_trans_hs_acl_tx ble_hci_trans_funcs_ptr->_ble_hci_trans_hs_acl_tx
140
150extern uint8_t *r_ble_hci_trans_buf_alloc(int type);
151#define ble_hci_trans_buf_alloc r_ble_hci_trans_buf_alloc
152
159extern void r_ble_hci_trans_buf_free(uint8_t *buf);
160#define ble_hci_trans_buf_free r_ble_hci_trans_buf_free
161
173extern int r_ble_hci_trans_set_acl_free_cb(os_mempool_put_fn *cb, void *arg);
174#define ble_hci_trans_set_acl_free_cb ble_hci_trans_funcs_ptr->_ble_hci_trans_set_acl_free_cb
175
189extern void r_ble_hci_trans_cfg_ll(ble_hci_trans_rx_cmd_fn *cmd_cb,
190 void *cmd_arg,
191 ble_hci_trans_rx_acl_fn *acl_cb,
192 void *acl_arg);
193#define ble_hci_trans_cfg_ll r_ble_hci_trans_cfg_ll
194
208extern void r_ble_hci_trans_cfg_hs(ble_hci_trans_rx_cmd_fn *evt_cb,
209 void *evt_arg,
210 ble_hci_trans_rx_acl_fn *acl_cb,
211 void *acl_arg);
212#define ble_hci_trans_cfg_hs r_ble_hci_trans_cfg_hs
213
221extern int r_ble_hci_trans_reset(void);
222#define ble_hci_trans_reset ble_hci_trans_funcs_ptr->_ble_hci_trans_reset
223
224void esp_ble_hci_trans_init(uint8_t);
225
226#else
236int ble_hci_trans_ll_evt_tx(uint8_t *hci_ev);
237
246int ble_hci_trans_ll_acl_tx(struct os_mbuf *om);
247
257int ble_hci_trans_hs_cmd_tx(uint8_t *cmd);
258
267int ble_hci_trans_hs_acl_tx(struct os_mbuf *om);
268
278int esp_ble_hci_trans_hs_cmd_tx(uint8_t *cmd);
279
288int esp_ble_hci_trans_hs_acl_tx(struct os_mbuf *om);
289
299uint8_t *esp_ble_hci_trans_buf_alloc(int type);
300
307void esp_ble_hci_trans_buf_free(uint8_t *buf);
308
322void esp_ble_hci_trans_cfg_hs(ble_hci_trans_rx_cmd_fn *evt_cb,
323 void *evt_arg,
324 ble_hci_trans_rx_acl_fn *acl_cb,
325 void *acl_arg);
326
334int esp_ble_hci_trans_reset(void);
335#endif
336struct os_mbuf;
337
338/* Allocators for supported data types */
339#if !SOC_ESP_NIMBLE_CONTROLLER || !CONFIG_BT_CONTROLLER_ENABLED
340void *ble_transport_alloc_cmd(void);
341void *ble_transport_alloc_evt(int discardable);
342struct os_mbuf *ble_transport_alloc_acl_from_hs(void);
343struct os_mbuf *ble_transport_alloc_acl_from_ll(void);
344
345/* Generic deallocator for cmd/evt buffers */
346void ble_transport_free(void *buf);
347#endif
348
349/* Register put callback on acl_from_ll mbufs (for ll-hs flow control) */
350int ble_transport_register_put_acl_from_ll_cb(os_mempool_put_fn *cb);
351
352/* Send data to hs/ll side */
353#if CONFIG_BT_CONTROLLER_ENABLED
354#define ble_transport_to_ll_acl ble_hci_trans_hs_acl_tx
355#define ble_transport_to_ll_cmd ble_hci_trans_hs_cmd_tx
356#endif
357
358int ble_transport_to_hs_evt(void *buf);
359int ble_transport_to_hs_acl(struct os_mbuf *om);
360
361#else // ESP_PLATFORM
362
363struct os_mbuf;
364
365void ble_transport_init(void);
366void ble_transport_deinit(void);
367
368/* Allocators for supported data types */
369void *ble_transport_alloc_cmd(void);
370void *ble_transport_alloc_evt(int discardable);
371struct os_mbuf *ble_transport_alloc_acl_from_hs(void);
372struct os_mbuf *ble_transport_alloc_acl_from_ll(void);
373
374/* Generic deallocator for cmd/evt buffers */
375void ble_transport_free(void *buf);
376
377/* Register put callback on acl_from_ll mbufs (for ll-hs flow control) */
378int ble_transport_register_put_acl_from_ll_cb(os_mempool_put_fn *cb);
379
380/* Send data to hs/ll side */
381int ble_transport_to_ll_cmd(void *buf);
382int ble_transport_to_ll_acl(struct os_mbuf *om);
383int ble_transport_to_hs_evt(void *buf);
384int ble_transport_to_hs_acl(struct os_mbuf *om);
385
386#endif // ESP_PLATFORM
387
388#ifdef __cplusplus
389}
390#endif
391
392#endif /* H_NIMBLE_TRANSPORT_ */
os_error_t os_mempool_put_fn(struct os_mempool_ext *ome, void *data, void *arg)
Definition os_mempool.h:102
Definition os_mbuf.h:86