Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion nimble/host/mesh/src/provisioner.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ static struct {
uint8_t uuid[16];
} prov_device;

#if !MYNEWT_VAL(BLE_MESH_CDB)
static struct bt_mesh_cdb_node prov_node;
#endif

static void send_pub_key(void);
static void prov_dh_key_gen(void);
static void pub_key_ready(const uint8_t *pkey);
Expand Down Expand Up @@ -234,6 +238,14 @@ static void prov_capabilities(const uint8_t *data)
prov_fail(PROV_ERR_RESOURCES);
return;
}
#else
prov_device.node = &prov_node;
memset(&prov_node, 0, sizeof(struct bt_mesh_cdb_node));
memcpy(prov_node.uuid, prov_device.uuid, 16);
prov_node.addr = prov_device.addr;
prov_node.num_elem = data[0];
prov_node.net_idx = prov_device.net_idx;
atomic_set(prov_node.flags, 0);
#endif
memcpy(bt_mesh_prov_link.conf_inputs.capabilities, data, PDU_LEN_CAPABILITIES);

Expand Down Expand Up @@ -454,7 +466,9 @@ static void send_prov_data(void)
{
struct os_mbuf *pdu = PROV_BUF(PDU_LEN_DATA);
#if MYNEWT_VAL(BLE_MESH_CDB)
struct bt_mesh_cdb_subnet *sub;
struct bt_mesh_cdb_subnet *sub;
#else
struct bt_mesh_subnet *sub;
#endif
uint8_t session_key[16];
uint8_t nonce[13];
Expand Down Expand Up @@ -497,13 +511,26 @@ static void send_prov_data(void)
prov_fail(PROV_ERR_UNEXP_ERR);
return;
}
#else
sub = bt_mesh_subnet_get(prov_device.node->net_idx);
if (sub == NULL) {
BT_ERR("No subnet with net_idx %u",
prov_device.node->net_idx);
prov_fail(PROV_ERR_UNEXP_ERR);
return;
}
#endif
bt_mesh_prov_buf_init(pdu, PROV_DATA);
#if MYNEWT_VAL(BLE_MESH_CDB)
net_buf_simple_add_mem(pdu, sub->keys[SUBNET_KEY_TX_IDX(sub)].net_key, 16);
net_buf_simple_add_be16(pdu, prov_device.node->net_idx);
net_buf_simple_add_u8(pdu, bt_mesh_cdb_subnet_flags(sub));
net_buf_simple_add_be32(pdu, bt_mesh_cdb.iv_index);
#else
net_buf_simple_add_mem(pdu, sub->keys[SUBNET_KEY_TX_IDX(sub)].net, 16);
net_buf_simple_add_be16(pdu, prov_device.node->net_idx);
net_buf_simple_add_u8(pdu, bt_mesh_net_flags(sub));
net_buf_simple_add_be32(pdu, bt_mesh.iv_index);
#endif
net_buf_simple_add_be16(pdu, prov_device.node->addr);
net_buf_simple_add(pdu, 8); /* For MIC */
Expand Down
18 changes: 12 additions & 6 deletions nimble/host/mesh/src/testing.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,22 @@ void bt_test_mesh_trans_incomp_timer_exp(void)

int bt_test_mesh_lpn_group_add(uint16_t group)
{
bt_mesh_lpn_group_add(group);

return 0;
#if MYNEWT_VAL(BLE_MESH_LOW_POWER)
bt_mesh_lpn_group_add(group);
return 0;
#else
return -ENOTSUP;
#endif
}

int bt_test_mesh_lpn_group_remove(uint16_t *groups, size_t groups_count)
{
bt_mesh_lpn_group_del(groups, groups_count);

return 0;
#if MYNEWT_VAL(BLE_MESH_LOW_POWER)
bt_mesh_lpn_group_del(groups, groups_count);
return 0;
#else
return -ENOTSUP;
#endif
}

int bt_test_mesh_rpl_clear(void)
Expand Down
110 changes: 110 additions & 0 deletions porting/examples/linux_blemesh_shell/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#
# 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.
#

# Toolchain commands
CROSS_COMPILE ?=
CC := ccache $(CROSS_COMPILE)gcc
CXX := ccache $(CROSS_COMPILE)g++
LD := $(CROSS_COMPILE)gcc
AR := $(CROSS_COMPILE)ar
AS := $(CROSS_COMPILE)as
NM := $(CROSS_COMPILE)nm
OBJDUMP := $(CROSS_COMPILE)objdump
OBJCOPY := $(CROSS_COMPILE)objcopy
SIZE := $(CROSS_COMPILE)size

# Configure NimBLE variables
NIMBLE_ROOT := ../../..
NIMBLE_CFG_TINYCRYPT := 1

# Skip files that don't build for this port
NIMBLE_IGNORE := $(NIMBLE_ROOT)/porting/nimble/src/hal_timer.c \
$(NIMBLE_ROOT)/porting/nimble/src/os_cputime.c \
$(NIMBLE_ROOT)/porting/nimble/src/os_cputime_pwr2.c \
$(NULL)

include $(NIMBLE_ROOT)/porting/nimble/Makefile.defs
include $(NIMBLE_ROOT)/porting/nimble/Makefile.mesh

SRC := $(NIMBLE_SRC)

# Source files for NPL OSAL
SRC += \
$(wildcard $(NIMBLE_ROOT)/porting/npl/linux/src/*.c) \
$(wildcard $(NIMBLE_ROOT)/porting/npl/linux/src/*.cc) \
$(wildcard $(NIMBLE_ROOT)/nimble/transport/socket/src/*.c) \
$(TINYCRYPT_SRC) \
$(wildcard $(NIMBLE_ROOT)/nimble/host/mesh/src/*.c) \
$(NULL)

# Source files for demo app
SRC += \
./src/main.c \
./src/ble.c \
./shell/shell_port.c \
./shell/console_port.c \
$(NULL)

# Add NPL and all NimBLE directories to include paths
INC = \
./include \
$(NIMBLE_ROOT)/porting/npl/linux/include \
$(NIMBLE_ROOT)/porting/npl/linux/src \
$(NIMBLE_ROOT)/nimble/transport/socket/include \
$(NIMBLE_INCLUDE) \
$(TINYCRYPT_INCLUDE) \
$(NULL)

INCLUDES := $(addprefix -I, $(INC))

SRC_C = $(filter %.c, $(SRC))
SRC_CC = $(filter %.cc, $(SRC))

OBJ := $(SRC_C:.c=.o)
OBJ += $(SRC_CC:.cc=.o)

TINYCRYPT_OBJ := $(TINYCRYPT_SRC:.c=.o)

CFLAGS = \
$(NIMBLE_CFLAGS) \
$(INCLUDES) \
-g \
-D_GNU_SOURCE \
$(NULL)

LIBS := $(NIMBLE_LDFLAGS) -lrt -lpthread -lstdc++

.PHONY: all clean
.DEFAULT: all

all: nimble-linux-blemesh-shell

clean:
rm $(OBJ) -f
rm nimble-linux-blemesh-shell -f

$(TINYCRYPT_OBJ): CFLAGS+=$(TINYCRYPT_CFLAGS)

%.o: %.c
$(CC) -c $(INCLUDES) $(CFLAGS) -o $@ $<

%.o: %.cc
$(CXX) -c $(INCLUDES) $(CFLAGS) -o $@ $<

nimble-linux-blemesh-shell: $(OBJ) $(TINYCRYPT_OBJ)
$(LD) -o $@ $^ $(LIBS)
$(SIZE) $@
76 changes: 76 additions & 0 deletions porting/examples/linux_blemesh_shell/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!--
#
# 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.
#
-->

# Apache Mynewt NimBLE

## Overview

See https://mynewt.apache.org/latest/network

## Building

NimBLE is usually built as a part of Apache Mynewt OS, but ports for
other RTOS-es are also available.

### Linux

1. Build the sample application

```no-highlight
cd porting/examples/linux_blemesh_shell
make
```

2. Run the sample application

First insert a USB Bluetooth dongle. These are typically BLE 4.0 capable.

Verify the dongle is connected with hciconfig:

```no-highlight
$ hciconfig
hci0: Type: BR/EDR Bus: USB
BD Address: 00:1B:DC:06:62:5E ACL MTU: 310:10 SCO MTU: 64:8
DOWN
RX bytes:5470 acl:0 sco:0 events:40 errors:0
TX bytes:5537 acl:176 sco:0 commands:139 errors:1
```

Then run the application built in step one. The application is configured
in sysconfig.h to use hci0.

```no-highlight
cd porting/examples/linux_blemesh_shell
sudo ./nimble-linux-blemesh-shell
```

3. Run shell commands

This example reads input form console, then execute all commands supported by nimble/host/mesh/src/shell.c


some example commands:

```no-highlight
mesh>help
mesh>provision 0 1 0
mesh>provision-adv c70512201872a85c9046a3e67ef1c55e 0 2 0
```
Original file line number Diff line number Diff line change
@@ -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.
*/

#ifndef __CONSOLE_PORT_H__
#define __CONSOLE_PORT_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "nimble/nimble_npl.h"
struct os_eventq;

void console_set_queues(struct os_eventq *avail, struct os_eventq *lines);

void console_set_event_cb(ble_npl_event_fn *cb);

int console_init();

#ifdef __cplusplus
}
#endif

#endif
Loading
Loading