From 11b8107a371351a3adbad5dfe32571b07f9d4aab Mon Sep 17 00:00:00 2001 From: Jerzy Kasenberg Date: Mon, 22 Nov 2021 10:25:18 +0100 Subject: [PATCH] apps: Add blehcibridge application This application is equivalent of blehci for dual-core MCUs. It allows to forward traffic from external transport (USB/UART) to BLE core via internal transport. --- apps/blehcibridge/pkg.yml | 40 +++++++++++++++++++++ apps/blehcibridge/src/main.c | 69 ++++++++++++++++++++++++++++++++++++ apps/blehcibridge/syscfg.yml | 36 +++++++++++++++++++ 3 files changed, 145 insertions(+) create mode 100644 apps/blehcibridge/pkg.yml create mode 100644 apps/blehcibridge/src/main.c create mode 100644 apps/blehcibridge/syscfg.yml diff --git a/apps/blehcibridge/pkg.yml b/apps/blehcibridge/pkg.yml new file mode 100644 index 000000000..9d170a89f --- /dev/null +++ b/apps/blehcibridge/pkg.yml @@ -0,0 +1,40 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +pkg.name: apps/blehcibridge +pkg.type: app +pkg.description: BLE controller application exposing HCI over external interface +pkg.author: "Jerzy Kasenberg " +pkg.homepage: "http://mynewt.apache.org/" +pkg.keywords: + +pkg.deps: + - "@apache-mynewt-core/sys/log/stub" + - "@apache-mynewt-core/sys/stats/full" + - "@apache-mynewt-core/kernel/os" + - "@apache-mynewt-core/sys/shell" + - nimble/transport + +pkg.req_apis: + - ble_transport + +pkg.deps.'CONSOLE_MODE=="full"': + - "@apache-mynewt-core/sys/console/full" +pkg.deps.'CONSOLE_MODE=="minimal": + - "@apache-mynewt-core/sys/console/minimal" +pkg.deps.'CONSOLE_MODE=="stub": + - "@apache-mynewt-core/sys/console/stub" diff --git a/apps/blehcibridge/src/main.c b/apps/blehcibridge/src/main.c new file mode 100644 index 000000000..620cc3712 --- /dev/null +++ b/apps/blehcibridge/src/main.c @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include +#include +#include + +static int +forward_cmd_to_controller(uint8_t *cmdbuf, void *arg) +{ + (void)arg; + + return ble_hci_trans_hs_cmd_tx(cmdbuf); +} + +int +forward_acl_to_controller(struct os_mbuf *om, void *arg) +{ + (void)arg; + + return ble_hci_trans_hs_acl_tx(om); +} + +static int +forward_evt_to_host(uint8_t *hci_ev, void *arg) +{ + (void)arg; + + return ble_hci_trans_ll_evt_tx(hci_ev); +} + +int +forward_acl_to_host(struct os_mbuf *om, void *arg) +{ + (void)arg; + + return ble_hci_trans_ll_acl_tx(om); +} + +int +main(void) +{ + /* Initialize OS */ + sysinit(); + + ble_hci_trans_cfg_hs(forward_evt_to_host, NULL, forward_acl_to_host, NULL); + ble_hci_trans_cfg_ll(forward_cmd_to_controller, NULL, forward_acl_to_controller, NULL); + + while (1) { + os_eventq_run(os_eventq_dflt_get()); + } + return 0; +} diff --git a/apps/blehcibridge/syscfg.yml b/apps/blehcibridge/syscfg.yml new file mode 100644 index 000000000..146ab5264 --- /dev/null +++ b/apps/blehcibridge/syscfg.yml @@ -0,0 +1,36 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +syscfg.defs: + CONSOLE_MODE: + description: Which console to use + value: stub + choices: + - full + - minimal + - stub + +syscfg.vals: + # Default task settings + OS_MAIN_STACK_SIZE: 64 + # Use USB transport by default + BLE_HCI_TRANSPORT: usb + + SHELL_TASK: 1 + + BLE_HCI_BRIDGE: 1