[GitHub] EvalZero opened a new pull request #344: bletest: update bletest HCI commands sending functions

2019-02-18 Thread GitBox
EvalZero opened a new pull request #344: bletest: update bletest HCI commands 
sending functions
URL: https://github.com/apache/mynewt-nimble/pull/344
 
 
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[mynewt-core] branch master updated: compiler/gdbmacros: scripts to dump stacks

2019-02-18 Thread ccollins
This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new e5f2545  compiler/gdbmacros: scripts to dump stacks
e5f2545 is described below

commit e5f2545492320296763850cfc20f275762fd3429
Author: Christopher Collins 
AuthorDate: Fri Feb 15 12:25:31 2019 -0800

compiler/gdbmacros: scripts to dump stacks

This commit adds two public gdb scripts:

usage: os_task_stack_dump 
Dumps the specified task's stack, including symbol info.

usage: os_task_stack_dump_all
Dumps all task stacks, including symbol info.
---
 compiler/gdbmacros/os.gdb | 50 +++
 1 file changed, 50 insertions(+)

diff --git a/compiler/gdbmacros/os.gdb b/compiler/gdbmacros/os.gdb
index e834d46..e83b9aa 100644
--- a/compiler/gdbmacros/os.gdb
+++ b/compiler/gdbmacros/os.gdb
@@ -71,3 +71,53 @@ document os_wakeups
 usage: os_wakeups
 Displays scheduled OS callouts, and next scheduled task wakeups
 end
+
+define os_stack_dump_range
+set $start = (uintptr_t)$arg0
+set $num_words = $arg1
+
+set $cur = 0
+while $cur < $num_words
+set $addr = ((os_stack_t *)$start) + $cur
+printf "0x%08x: ", $addr
+x/a *$addr
+
+set $cur++
+end
+end
+
+define os_task_stack_dump
+set $task = $arg0
+
+set $stackptr = $task.t_stackptr
+set $num_words = $task.t_stacktop - $stackptr
+
+os_stack_dump_range $stackptr $num_words
+end
+
+document os_task_stack_dump
+usage: os_task_stack_dump 
+Dumps the specified task's stack, including symbol info.
+end
+
+define os_task_stack_dump_all
+set $first = 1
+set $task = g_os_task_list.stqh_first
+while $task != 0
+if $first
+set $first = 0
+else
+printf "\n"
+end
+
+printf "[%s]\n", $task.t_name
+os_task_stack_dump $task
+
+set $task = $task.t_os_task_list.stqe_next
+end
+end
+
+document os_task_stack_dump_all
+usage: os_task_stack_dump_all
+Dumps all task stacks, including symbol info.
+end



[GitHub] ccollins476ad merged pull request #1648: compiler/gdbmacros: scripts to dump stacks

2019-02-18 Thread GitBox
ccollins476ad merged pull request #1648: compiler/gdbmacros: scripts to dump 
stacks
URL: https://github.com/apache/mynewt-core/pull/1648
 
 
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] michal-narajowski merged pull request #337: porting: Add blemesh example app for Linux

2019-02-18 Thread GitBox
michal-narajowski merged pull request #337: porting: Add blemesh example app 
for Linux
URL: https://github.com/apache/mynewt-nimble/pull/337
 
 
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] michal-narajowski merged pull request #331: apps/blemesh_models_example_2: Sync with Zephyr

2019-02-18 Thread GitBox
michal-narajowski merged pull request #331: apps/blemesh_models_example_2: Sync 
with Zephyr
URL: https://github.com/apache/mynewt-nimble/pull/331
 
 
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[mynewt-nimble] branch master updated: porting: Add blemesh example app for Linux

2019-02-18 Thread naraj
This is an automated email from the ASF dual-hosted git repository.

naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git


The following commit(s) were added to refs/heads/master by this push:
 new 65869c5  porting: Add blemesh example app for Linux
65869c5 is described below

commit 65869c55717b5c57fd4bee10b5b2233108c4883d
Author: MichaƂ Narajowski 
AuthorDate: Thu Feb 7 16:16:00 2019 +0100

porting: Add blemesh example app for Linux
---
 porting/examples/linux_blemesh/Makefile |  88 +++
 porting/examples/linux_blemesh/ble.c| 447 
 porting/examples/linux_blemesh/main.c   |  98 +++
 3 files changed, 633 insertions(+)

diff --git a/porting/examples/linux_blemesh/Makefile 
b/porting/examples/linux_blemesh/Makefile
new file mode 100644
index 000..ef19956
--- /dev/null
+++ b/porting/examples/linux_blemesh/Makefile
@@ -0,0 +1,88 @@
+# Toolchain commands
+CROSS_COMPILE ?=
+CC  := ccache $(CROSS_COMPLIE)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
+include $(NIMBLE_ROOT)/porting/nimble/Makefile.defs
+include $(NIMBLE_ROOT)/porting/nimble/Makefile.mesh
+
+SRC := $(NIMBLE_SRC)
+
+# Source files for NPL OSAL
+SRC += \
+   $(NIMBLE_ROOT)/porting/npl/linux/src/os_atomic.c   \
+   $(NIMBLE_ROOT)/porting/npl/linux/src/os_callout.c  \
+   $(NIMBLE_ROOT)/porting/npl/linux/src/os_eventq.cc  \
+   $(NIMBLE_ROOT)/porting/npl/linux/src/os_mutex.c\
+   $(NIMBLE_ROOT)/porting/npl/linux/src/os_sem.c  \
+   $(NIMBLE_ROOT)/porting/npl/linux/src/os_task.c \
+   $(NIMBLE_ROOT)/porting/npl/linux/src/os_time.c \
+   $(NIMBLE_ROOT)/nimble/transport/socket/src/ble_hci_socket.c \
+   $(TINYCRYPT_SRC) \
+   $(NULL)
+
+# Source files for demo app
+SRC += \
+   ./ble.c \
+   ./main.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 := -lrt -lpthread -lstdc++
+
+.PHONY: all clean
+.DEFAULT: all
+
+all: nimble-linux
+
+clean:
+   rm $(OBJ) -f
+   rm dummy -f
+
+$(TINYCRYPT_OBJ): CFLAGS+=$(TINYCRYPT_CFLAGS)
+
+%.o: %.c
+   $(CC) -c $(INCLUDES) $(CFLAGS) -o $@ $<
+
+%.o: %.cc
+   $(CXX) -c $(INCLUDES) $(CFLAGS) -o $@ $<
+
+nimble-linux: $(OBJ) $(TINYCRYPT_OBJ)
+   $(LD) -o $@ $^ $(LIBS)
+   $(SIZE) $@
diff --git a/porting/examples/linux_blemesh/ble.c 
b/porting/examples/linux_blemesh/ble.c
new file mode 100644
index 000..28caa8d
--- /dev/null
+++ b/porting/examples/linux_blemesh/ble.c
@@ -0,0 +1,447 @@
+/*
+ * 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 "mesh/mesh.h"
+#include "console/console.h"
+
+/* BLE */
+#include "nimble/ble.h"
+#include "host/ble_hs.h"
+#include "services/gap/ble_svc_gap.h"
+#include "mesh/glue.h"
+
+#define BT_DBG_ENABLED (MYNEWT_VAL(BLE_MESH_DEBUG))
+
+/* Company ID */
+#define CID_VENDOR 0x05C3
+#define STANDARD_TEST_ID 0x00
+#define TEST_ID 0x01
+static int recent_test_id = STANDARD_TEST_ID;
+
+#define FAULT_ARR_SIZE 2
+
+static bool has_reg_fault = true;
+
+static struct bt_mesh_cfg_srv cfg_srv = {
+.relay = BT_MESH_RELAY_ENABLED,
+.beacon = BT_MESH_BEACON_ENABLED,
+#if MYNEWT_VAL(BLE_MESH_FRIEND)
+.frnd = BT_MESH_FRIEND_ENABLED,
+#else
+.frnd = 

[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257584462
 
 

 ##
 File path: nimble/host/include/host/ble_gap.h
 ##
 @@ -708,6 +711,47 @@ struct ble_gap_event {
 uint8_t tx_phy;
 uint8_t rx_phy;
 } phy_updated;
+#if MYNEWT_VAL(BLE_EXT_ADV) && MYNEWT_VAL(BLE_PERIODIC_ADV)
+/**
+ * Represents an periodic advertising sync established during discovery
+ * procedure.  Valid for the following event types:
+ * o BLE_GAP_EVENT_PERIODIC_ADV_SYNC_ESTAB
+ */
+struct {
+uint8_t status;
+uint16_t sync_handle;
+uint8_t sid;
+uint8_t adv_addr_type;
+uint8_t adv_addr[6];
+uint8_t adv_phy;
+uint16_t per_adv_ival;
+uint8_t adv_clk_accuracy;
+} per_adv_sync_estab;
+
 
 Review comment:
   please remove empty line


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257625928
 
 

 ##
 File path: nimble/host/src/ble_hs_hci_evt.c
 ##
 @@ -28,8 +28,6 @@
 #include "ble_hs_priv.h"
 #include "ble_hs_dbg_priv.h"
 
-_Static_assert(sizeof (struct hci_data_hdr) == BLE_HCI_DATA_HDR_SZ,
 
 Review comment:
   Why this is removed? 


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257595528
 
 

 ##
 File path: nimble/host/mesh/src/prov.c
 ##
 @@ -449,7 +451,7 @@ static int prov_send_adv(struct os_mbuf *msg)
 #if (MYNEWT_VAL(BLE_MESH_PB_GATT))
 static int prov_send_gatt(struct os_mbuf *msg)
 {
-   if (!link.conn_handle) {
+   if (link.conn_handle == BLE_HS_CONN_HANDLE_NONE) {
 
 Review comment:
   Looks like this branch is not rebased. Please rebase as there should not be 
any changes in mesh code in this PR.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257586646
 
 

 ##
 File path: nimble/host/include/host/ble_gap.h
 ##
 @@ -708,6 +711,47 @@ struct ble_gap_event {
 uint8_t tx_phy;
 uint8_t rx_phy;
 } phy_updated;
+#if MYNEWT_VAL(BLE_EXT_ADV) && MYNEWT_VAL(BLE_PERIODIC_ADV)
+/**
+ * Represents an periodic advertising sync established during discovery
+ * procedure.  Valid for the following event types:
+ * o BLE_GAP_EVENT_PERIODIC_ADV_SYNC_ESTAB
+ */
+struct {
+uint8_t status;
+uint16_t sync_handle;
+uint8_t sid;
+uint8_t adv_addr_type;
+uint8_t adv_addr[6];
+uint8_t adv_phy;
+uint16_t per_adv_ival;
+uint8_t adv_clk_accuracy;
+} per_adv_sync_estab;
+
+
+/**
+ * Represents a Periodic advertising report received during discovery
+ * procedure.  Valid for the following event types:
+ * o BLE_GAP_EVENT_PERIODIC_DISC
+ */
+struct {
+uint16_t sync_handle;
+uint8_t tx_power;
+int8_t rssi;
+uint8_t _unused;
 
 Review comment:
   Let's removed unused from the API for now as in Bluetooth 5.0 it is always 
0xff and has no meaning for the application. When it will be defined in future 
specification it will change name for sure and then we decide how to add it.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257622012
 
 

 ##
 File path: nimble/host/src/ble_gap.c
 ##
 @@ -2919,13 +3049,533 @@ ble_gap_ext_adv_remove(uint8_t instance)
 return 0;
 }
 
+#if MYNEWT_VAL(BLE_PERIODIC_ADV)
+static int
+ble_gap_periodic_adv_params_tx(uint8_t instance,
+const struct ble_gap_periodic_adv_params *params)
+
+{
+struct hci_periodic_adv_params hci_adv_params;
+uint8_t buf[BLE_HCI_LE_SET_PERIODIC_ADV_PARAMS_LEN];
+int rc;
+
+memset(_adv_params, 0, sizeof(hci_adv_params));
+
+if (params->include_tx_power) {
+hci_adv_params.properties |= 
BLE_HCI_LE_SET_PERIODIC_ADV_PROP_INC_TX_PWR;
+}
+
+/* Fill optional fields if application did not specify them. */
+if (params->itvl_min == 0 && params->itvl_max == 0) {
+hci_adv_params.min_interval = 30 / 1.25;   //30 ms
+hci_adv_params.max_interval = 60 / 1.25;   //150 ms
+
+} else {
+hci_adv_params.min_interval = params->itvl_min;
+hci_adv_params.max_interval = params->itvl_max;
+}
+
+rc = ble_hs_hci_cmd_build_le_periodic_adv_params(instance, 
_adv_params, buf,
+sizeof(buf));
+if (rc != 0) {
+return rc;
+}
+
+rc = ble_hs_hci_cmd_tx_empty_ack(
+BLE_HCI_OP(BLE_HCI_OGF_LE, 
BLE_HCI_OCF_LE_SET_PERIODIC_ADV_PARAMS), buf,
+sizeof(buf));
+
+if (rc != 0) {
+return rc;
+}
+
+return 0;
+}
+
+static int
+ble_gap_periodic_adv_params_validate(
+const struct ble_gap_periodic_adv_params *params)
+{
+if (!params) {
+return BLE_HS_EINVAL;
+}
+
+if (params->itvl_min > 0x || params->itvl_min < 6){
+return BLE_HS_EINVAL;
+}
+if (params->itvl_max > 0x || params->itvl_max < 6){
+return BLE_HS_EINVAL;
+}
+return 0;
+
+}
+
+int
+ble_gap_periodic_adv_configure(uint8_t instance,
+const struct ble_gap_periodic_adv_params *params)
+{
+int rc;
+
+if (instance >= BLE_ADV_INSTANCES) {
+return BLE_HS_EINVAL;
+}
+
+rc = ble_gap_periodic_adv_params_validate(params);
+if (rc) {
+return rc;
+}
+
+ble_hs_lock();
+
+/* The corresponding extended advertising instance should be configured */
+if (!ble_gap_slave[instance].configured){
+ble_hs_unlock();
+return ENOMEM;
+}
+
+/* Periodic advertising shall not be configured while it is already
+ * running.
+ * Bluetooth Core Specification, Section 7.8.61
+ */
+if (ble_gap_slave[instance].per_op == BLE_GAP_OP_S_PERIODIC_ADV){
+ble_hs_unlock();
+return BLE_HS_EINVAL;
+}
+
+rc = ble_gap_periodic_adv_params_tx(instance, params);
+if (rc) {
+ble_hs_unlock();
+return rc;
+}
+
+ble_gap_slave[instance].per_configured = 1;
+
+ble_hs_unlock();
+
+return 0;
+}
+
+int
+ble_gap_periodic_adv_start(uint8_t instance)
+{
+uint8_t buf[BLE_HCI_LE_SET_PERIODIC_ADV_ENABLE_LEN];
+uint16_t opcode;
+int rc;
+
+if (instance >= BLE_ADV_INSTANCES) {
+return BLE_HS_EINVAL;
+}
+
+ble_hs_lock();
+
+/* Periodic advertising cannot start unless it is configured before */
+if (!ble_gap_slave[instance].per_configured) {
+ble_hs_unlock();
+return BLE_HS_EINVAL;
+}
+
+
+opcode = BLE_HCI_OP(BLE_HCI_OGF_LE, 
BLE_HCI_OCF_LE_SET_PERIODIC_ADV_ENABLE);
+
+rc = ble_hs_hci_cmd_build_le_periodic_adv_enable(1, instance, buf, 
sizeof(buf));
+if (rc != 0) {
+ble_hs_unlock();
+return rc;
+}
+
+rc = ble_hs_hci_cmd_tx_empty_ack(opcode, buf, sizeof(buf));
+if (rc != 0) {
+ble_hs_unlock();
+return rc;
+}
+
+ble_gap_slave[instance].per_op = BLE_GAP_OP_S_PERIODIC_ADV;
+
+ble_hs_unlock();
+return 0;
+}
+
+static int
+ble_gap_periodic_adv_set(uint8_t instance, uint16_t opcode,
+struct os_mbuf **data)
+{
+
+/* In that case we always fit all data in single HCI command */
+#if MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE) <= BLE_HCI_MAX_PERIODIC_ADV_DATA_LEN
+
+static uint8_t buf[BLE_HCI_SET_PERIODIC_ADV_DATA_HDR_LEN +
+   MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE)];
+uint16_t len = OS_MBUF_PKTLEN(*data);
+int rc;
+
+opcode = BLE_HCI_OP(BLE_HCI_OGF_LE, opcode);
+
+rc = ble_hs_hci_cmd_build_le_periodic_adv_data(
+instance,
+BLE_HCI_LE_SET_DATA_OPER_COMPLETE,
+*data, len,
+buf, sizeof(buf));
+
+if (rc) {
+return rc;
+}
+
+os_mbuf_adj(*data, MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE));
+*data = os_mbuf_trim_front(*data);
+
+return ble_hs_hci_cmd_tx_empty_ack(opcode, buf,
+BLE_HCI_SET_PERIODIC_ADV_DATA_HDR_LEN + len);
+#else
+static uint8_t buf[BLE_HCI_SET_PERIODIC_ADV_DATA_HDR_LEN +
+   BLE_HCI_MAX_PERIODIC_ADV_DATA_LEN];

[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257590465
 
 

 ##
 File path: nimble/host/include/host/ble_gap.h
 ##
 @@ -913,6 +966,28 @@ int ble_gap_ext_adv_stop(uint8_t instance);
 int ble_gap_ext_adv_set_data(uint8_t instance, struct os_mbuf *data);
 int ble_gap_ext_adv_rsp_set_data(uint8_t instance, struct os_mbuf *data);
 int ble_gap_ext_adv_remove(uint8_t instance);
+
+#if MYNEWT_VAL(BLE_PERIODIC_ADV)
+/* Periodic Advertising */
+int ble_gap_periodic_adv_configure(uint8_t instance, const struct 
ble_gap_periodic_adv_params *params);
+int ble_gap_periodic_adv_start(uint8_t instance);
+int ble_gap_periodic_adv_stop(uint8_t instance);
+int ble_gap_periodic_adv_set_data(uint8_t instance, struct os_mbuf *data);
+int ble_gap_periodic_adv_create_sync (uint8_t filter_policy,
+ uint8_tadv_sid, uint8_t adv_add_type,
+ const uint8_t *adv_addr, uint16_t skip,
+ uint16_t sync_timeout, uint8_t unused);
 
 Review comment:
   let's don't expose `unsed`  it in the yet and set this in 0x00 in HCI 
command as per BT 5.0 specification.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257623756
 
 

 ##
 File path: nimble/host/src/ble_hs_hci_cmd.c
 ##
 @@ -1605,6 +1605,167 @@ ble_hs_hci_cmd_build_le_ext_adv_remove(uint8_t handle,
 
 return 0;
 }
+
+#if MYNEWT_VAL(BLE_PERIODIC_ADV)
+int
+ble_hs_hci_cmd_build_le_periodic_adv_params(uint8_t handle,
+   const struct hci_periodic_adv_params 
*params,
+   uint8_t *cmd, int cmd_len)
+{
+BLE_HS_DBG_ASSERT(cmd_len >= BLE_HCI_LE_SET_PERIODIC_ADV_PARAMS_LEN);
+
+if (handle > 0xEF){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+if (params->max_interval > 0x || params->max_interval < 6){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+if (params->min_interval > 0x || params->min_interval < 6){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+
+cmd[0] = handle;
+
+put_le16([1], params->min_interval);
+put_le16([3], params->max_interval);
+put_le16([5], params->properties);
+
+return 0;
+}
+
+int
+ble_hs_hci_cmd_build_le_periodic_adv_enable(uint8_t enable,
+   uint8_t handle,
+   uint8_t *cmd, int cmd_len)
+{
+BLE_HS_DBG_ASSERT(cmd_len >= BLE_HCI_LE_SET_PERIODIC_ADV_ENABLE_LEN);
+
+if (enable > 1){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+
+cmd[0] = enable;
+cmd[1] = handle;
+
+return 0;
+}
+
+int
+ble_hs_hci_cmd_build_le_periodic_adv_data(uint8_t handle,
+ uint8_t operation,
+ struct os_mbuf *data,
+ uint8_t data_len,
+ uint8_t *cmd, int cmd_len)
+{
+BLE_HS_DBG_ASSERT(cmd_len >= 3 + data_len);
+
+if (!data){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+if (!data->om_data){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+if (handle > 0xEF){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+
+cmd[0] = handle;
+cmd[1] = operation;
+cmd[2] = data_len;
+os_mbuf_copydata(data, 0, data_len, cmd + 3);
+
+return 0;
+}
+
+int
+ble_hs_hci_cmd_build_le_periodic_adv_create_sync(uint8_t filter_policy,
+uint8_t adv_sid,
+uint8_t adv_add_type,
+const uint8_t *adv_addr,
+uint16_t skip,
+uint16_t sync_timeout, uint8_t unused,
+uint8_t *cmd, int cmd_len)
+{
+BLE_HS_DBG_ASSERT(cmd_len >= BLE_HCI_LE_PERIODIC_ADV_CREATE_SYNC_LEN);
+
+if (filter_policy > 1 || adv_add_type > 1){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+if (adv_sid > 0x0f){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+if (skip > 0x1f3 || sync_timeout > 0x4000 || sync_timeout < 0x0A){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+cmd[0] = filter_policy;
+cmd[1] = adv_sid;
+cmd[2] = adv_add_type;
+memcpy([3], adv_addr, 6);
+put_le16([9], skip);
+put_le16([11], sync_timeout);
+cmd[13] = unused;
 
 Review comment:
   use 0x00 for not instead `unused`


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257595895
 
 

 ##
 File path: nimble/host/mesh/src/proxy.c
 ##
 @@ -417,7 +417,7 @@ void bt_mesh_proxy_beacon_send(struct bt_mesh_subnet *sub)
}
 
for (i = 0; i < ARRAY_SIZE(clients); i++) {
-   if (clients[i].conn_handle) {
+   if (clients[i].conn_handle != BLE_HS_CONN_HANDLE_NONE) {
 
 Review comment:
   this file should also by untouched. Please rebase.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257635790
 
 

 ##
 File path: porting/nimble/include/syscfg/syscfg.h
 ##
 @@ -389,6 +389,10 @@
 #define MYNEWT_VAL_BLE_MAX_CONNECTIONS (1)
 #endif
 
+#ifndef MYNEWT_VAL_BLE_MAX_PERIODIC_SCANNING_SM
+#define MYNEWT_VAL_BLE_MAX_PERIODIC_SCANNING_SM (1)
 
 Review comment:
   Please set it to 0


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257596832
 
 

 ##
 File path: nimble/host/src/ble_gap.c
 ##
 @@ -128,6 +129,13 @@ struct ble_gap_master_state {
 uint8_t limited:1;
 } disc;
 };
+
+#if MYNEWT_VAL(BLE_PERIODIC_ADV)
+/* Counts how many times create_sync were called without
+ * receiving sync established event
+ */
+uint16_tpending_create_sync;
 
 Review comment:
   comment does not match how `pending_create_sync` is used as this seems to be 
a flag only. Please also change type of it.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257619010
 
 

 ##
 File path: nimble/host/src/ble_gap.c
 ##
 @@ -2919,13 +3049,533 @@ ble_gap_ext_adv_remove(uint8_t instance)
 return 0;
 }
 
+#if MYNEWT_VAL(BLE_PERIODIC_ADV)
+static int
+ble_gap_periodic_adv_params_tx(uint8_t instance,
+const struct ble_gap_periodic_adv_params *params)
+
+{
+struct hci_periodic_adv_params hci_adv_params;
+uint8_t buf[BLE_HCI_LE_SET_PERIODIC_ADV_PARAMS_LEN];
+int rc;
+
+memset(_adv_params, 0, sizeof(hci_adv_params));
+
+if (params->include_tx_power) {
+hci_adv_params.properties |= 
BLE_HCI_LE_SET_PERIODIC_ADV_PROP_INC_TX_PWR;
+}
+
+/* Fill optional fields if application did not specify them. */
+if (params->itvl_min == 0 && params->itvl_max == 0) {
+hci_adv_params.min_interval = 30 / 1.25;   //30 ms
+hci_adv_params.max_interval = 60 / 1.25;   //150 ms
+
+} else {
+hci_adv_params.min_interval = params->itvl_min;
+hci_adv_params.max_interval = params->itvl_max;
+}
+
+rc = ble_hs_hci_cmd_build_le_periodic_adv_params(instance, 
_adv_params, buf,
+sizeof(buf));
+if (rc != 0) {
+return rc;
+}
+
+rc = ble_hs_hci_cmd_tx_empty_ack(
+BLE_HCI_OP(BLE_HCI_OGF_LE, 
BLE_HCI_OCF_LE_SET_PERIODIC_ADV_PARAMS), buf,
+sizeof(buf));
+
+if (rc != 0) {
+return rc;
+}
+
+return 0;
+}
+
+static int
+ble_gap_periodic_adv_params_validate(
+const struct ble_gap_periodic_adv_params *params)
+{
+if (!params) {
+return BLE_HS_EINVAL;
+}
+
+if (params->itvl_min > 0x || params->itvl_min < 6){
+return BLE_HS_EINVAL;
+}
+if (params->itvl_max > 0x || params->itvl_max < 6){
+return BLE_HS_EINVAL;
+}
+return 0;
+
+}
+
+int
+ble_gap_periodic_adv_configure(uint8_t instance,
+const struct ble_gap_periodic_adv_params *params)
+{
+int rc;
+
+if (instance >= BLE_ADV_INSTANCES) {
+return BLE_HS_EINVAL;
+}
+
+rc = ble_gap_periodic_adv_params_validate(params);
+if (rc) {
+return rc;
+}
+
+ble_hs_lock();
+
+/* The corresponding extended advertising instance should be configured */
+if (!ble_gap_slave[instance].configured){
+ble_hs_unlock();
+return ENOMEM;
+}
+
+/* Periodic advertising shall not be configured while it is already
+ * running.
+ * Bluetooth Core Specification, Section 7.8.61
+ */
+if (ble_gap_slave[instance].per_op == BLE_GAP_OP_S_PERIODIC_ADV){
+ble_hs_unlock();
+return BLE_HS_EINVAL;
+}
+
+rc = ble_gap_periodic_adv_params_tx(instance, params);
+if (rc) {
+ble_hs_unlock();
+return rc;
+}
+
+ble_gap_slave[instance].per_configured = 1;
+
+ble_hs_unlock();
+
+return 0;
+}
+
+int
+ble_gap_periodic_adv_start(uint8_t instance)
+{
+uint8_t buf[BLE_HCI_LE_SET_PERIODIC_ADV_ENABLE_LEN];
+uint16_t opcode;
+int rc;
+
+if (instance >= BLE_ADV_INSTANCES) {
+return BLE_HS_EINVAL;
+}
+
+ble_hs_lock();
+
+/* Periodic advertising cannot start unless it is configured before */
+if (!ble_gap_slave[instance].per_configured) {
+ble_hs_unlock();
+return BLE_HS_EINVAL;
+}
+
+
+opcode = BLE_HCI_OP(BLE_HCI_OGF_LE, 
BLE_HCI_OCF_LE_SET_PERIODIC_ADV_ENABLE);
+
+rc = ble_hs_hci_cmd_build_le_periodic_adv_enable(1, instance, buf, 
sizeof(buf));
+if (rc != 0) {
+ble_hs_unlock();
+return rc;
+}
+
+rc = ble_hs_hci_cmd_tx_empty_ack(opcode, buf, sizeof(buf));
+if (rc != 0) {
+ble_hs_unlock();
+return rc;
+}
+
+ble_gap_slave[instance].per_op = BLE_GAP_OP_S_PERIODIC_ADV;
+
+ble_hs_unlock();
+return 0;
+}
+
+static int
+ble_gap_periodic_adv_set(uint8_t instance, uint16_t opcode,
+struct os_mbuf **data)
+{
+
+/* In that case we always fit all data in single HCI command */
+#if MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE) <= BLE_HCI_MAX_PERIODIC_ADV_DATA_LEN
+
+static uint8_t buf[BLE_HCI_SET_PERIODIC_ADV_DATA_HDR_LEN +
+   MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE)];
+uint16_t len = OS_MBUF_PKTLEN(*data);
+int rc;
+
+opcode = BLE_HCI_OP(BLE_HCI_OGF_LE, opcode);
+
+rc = ble_hs_hci_cmd_build_le_periodic_adv_data(
+instance,
+BLE_HCI_LE_SET_DATA_OPER_COMPLETE,
+*data, len,
+buf, sizeof(buf));
+
+if (rc) {
+return rc;
+}
+
+os_mbuf_adj(*data, MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE));
+*data = os_mbuf_trim_front(*data);
+
+return ble_hs_hci_cmd_tx_empty_ack(opcode, buf,
+BLE_HCI_SET_PERIODIC_ADV_DATA_HDR_LEN + len);
+#else
+static uint8_t buf[BLE_HCI_SET_PERIODIC_ADV_DATA_HDR_LEN +
+   BLE_HCI_MAX_PERIODIC_ADV_DATA_LEN];

[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257628078
 
 

 ##
 File path: nimble/host/src/ble_hs_periodic_disc.c
 ##
 @@ -0,0 +1,233 @@
+/*
+ * 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 "syscfg/syscfg.h"
+#include "os/os.h"
+#include "host/ble_hs_id.h"
+#include "ble_hs_priv.h"
+
+static SLIST_HEAD(, ble_hs_periodic_sync) ble_hs_periodic_sync_handles;
+static struct os_mempool ble_hs_periodic_sync_pool;
+
+static os_membuf_t ble_hs_psync_elem_mem[
+OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_MAX_PERIODIC_SCANNING_SM),
+sizeof (struct ble_hs_periodic_sync))
+];
+
+int
+ble_hs_periodic_sync_can_alloc(void)
+{
+#if !MYNEWT_VAL(BLE_PERIODIC_ADV)
+return 0;
+#endif
+
+return (ble_hs_periodic_sync_pool.mp_num_free >= 1);
+}
+
+struct ble_hs_periodic_sync *
+ble_hs_periodic_sync_alloc()
+{
+#if !MYNEWT_VAL(BLE_PERIODIC_ADV)
+return NULL;
+#endif
+
+struct ble_hs_periodic_sync *psync;
+
+psync = os_memblock_get(_hs_periodic_sync_pool);
+if (psync == NULL) {
+goto err;
+}
+memset(psync, 0, sizeof *psync);
+
+return psync;
+
+err:
+ble_hs_periodic_sync_free(psync);
+return NULL;
+}
+
+
+
+void
+ble_hs_periodic_sync_free(struct ble_hs_periodic_sync *psync)
+{
+#if !MYNEWT_VAL(BLE_PERIODIC_ADV)
+return;
+#endif
+
+int rc;
+if (psync == NULL) {
+return;
+}
+
+#if MYNEWT_VAL(BLE_HS_DEBUG)
+memset(psync, 0xff, sizeof *psync);
+#endif
+rc = os_memblock_put(_hs_periodic_sync_pool, psync);
+BLE_HS_DBG_ASSERT_EVAL(rc == 0);
+}
+
+void
+ble_hs_periodic_sync_insert(struct ble_hs_periodic_sync *psync)
+{
+#if !MYNEWT_VAL(BLE_PERIODIC_ADV)
+return;
+#endif
+
+BLE_HS_DBG_ASSERT(ble_hs_locked_by_cur_task());
+
+BLE_HS_DBG_ASSERT_EVAL(
+   ble_hs_periodic_sync_find(psync->sync_handle) == NULL);
+
+SLIST_INSERT_HEAD(_hs_periodic_sync_handles, psync, bhc_next);
+}
+
+void
+ble_hs_periodic_sync_remove(struct ble_hs_periodic_sync *psync)
+{
+#if !MYNEWT_VAL(BLE_PERIODIC_ADV)
+return;
+#endif
+
+BLE_HS_DBG_ASSERT(ble_hs_locked_by_cur_task());
+
+SLIST_REMOVE(_hs_periodic_sync_handles,
+ psync,
+ ble_hs_periodic_sync,
+ bhc_next);
+}
+
+struct ble_hs_periodic_sync *
+ble_hs_periodic_sync_find(uint16_t sync_handle)
+{
+#if !MYNEWT_VAL(BLE_PERIODIC_ADV)
+return NULL;
+#endif
+
+struct ble_hs_periodic_sync *psync;
+
+BLE_HS_DBG_ASSERT(ble_hs_locked_by_cur_task());
+
+SLIST_FOREACH(psync, _hs_periodic_sync_handles, bhc_next) {
+if (psync->sync_handle == sync_handle) {
+return psync;
+}
+}
+
+return NULL;
+}
+
+struct ble_hs_periodic_sync *
+ble_hs_periodic_sync_find_assert(uint16_t sync_handle)
+{
+struct ble_hs_periodic_sync *psync;
+
+psync = ble_hs_periodic_sync_find(sync_handle);
+BLE_HS_DBG_ASSERT(psync != NULL);
+
+return psync;
+}
+
+struct ble_hs_periodic_sync *
+ble_hs_periodic_sync_find_by_adv_addr(const ble_addr_t *addr)
+{
+#if !MYNEWT_VAL(BLE_PERIODIC_ADV)
+return NULL;
+#endif
+
+struct ble_hs_periodic_sync *psync;
+
+BLE_HS_DBG_ASSERT(ble_hs_locked_by_cur_task());
+
+if (!addr) {
+return NULL;
+}
+
+SLIST_FOREACH(psync, _hs_periodic_sync_handles, bhc_next) {
+if (ble_addr_cmp(>advertiser_addr, addr) == 0) {
+return psync;
+}
+}
+
+return NULL;
+}
+
+struct ble_hs_periodic_sync *
+ble_hs_periodic_sync_find_by_adv_sid(uint16_t sid)
+{
+#if !MYNEWT_VAL(BLE_PERIODIC_ADV)
+return 0;
+#endif
+
+struct ble_hs_periodic_sync *psync;
+
+BLE_HS_DBG_ASSERT(ble_hs_locked_by_cur_task());
+
+SLIST_FOREACH(psync, _hs_periodic_sync_handles, bhc_next) {
+if (psync->adv_sid == sid) {
+return psync;
+}
+}
+
+return NULL;
+}
+
+int
+ble_hs_periodic_sync_exists(uint16_t sync_handle)
+{
+#if !MYNEWT_VAL(BLE_PERIODIC_ADV)
+return 0;
+#endif
+return ble_hs_periodic_sync_find(sync_handle) != NULL;
+}
+
+/**
+ * Retrieves the first periodic 

[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257612951
 
 

 ##
 File path: nimble/host/src/ble_gap.c
 ##
 @@ -1353,15 +1477,15 @@ ble_gap_rx_conn_complete(struct hci_le_conn_complete 
*evt, uint8_t instance)
 
 STATS_INC(ble_gap_stats, rx_conn_complete);
 
-/* in that case *only* status field is valid so we determine role
 
 Review comment:
   There is a lot of changes from here down to the end of the file which are 
not relevant. Please remove them from this patch. It is already big patch and 
let's don't make it bigger.
   Could you please prepare instead a patch with a coding style fixes instead?
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257617713
 
 

 ##
 File path: nimble/host/src/ble_gap.c
 ##
 @@ -2919,13 +3049,533 @@ ble_gap_ext_adv_remove(uint8_t instance)
 return 0;
 }
 
+#if MYNEWT_VAL(BLE_PERIODIC_ADV)
+static int
+ble_gap_periodic_adv_params_tx(uint8_t instance,
+const struct ble_gap_periodic_adv_params *params)
+
+{
+struct hci_periodic_adv_params hci_adv_params;
+uint8_t buf[BLE_HCI_LE_SET_PERIODIC_ADV_PARAMS_LEN];
+int rc;
+
+memset(_adv_params, 0, sizeof(hci_adv_params));
+
+if (params->include_tx_power) {
+hci_adv_params.properties |= 
BLE_HCI_LE_SET_PERIODIC_ADV_PROP_INC_TX_PWR;
+}
+
+/* Fill optional fields if application did not specify them. */
+if (params->itvl_min == 0 && params->itvl_max == 0) {
+hci_adv_params.min_interval = 30 / 1.25;   //30 ms
+hci_adv_params.max_interval = 60 / 1.25;   //150 ms
+
+} else {
+hci_adv_params.min_interval = params->itvl_min;
+hci_adv_params.max_interval = params->itvl_max;
+}
+
+rc = ble_hs_hci_cmd_build_le_periodic_adv_params(instance, 
_adv_params, buf,
+sizeof(buf));
+if (rc != 0) {
+return rc;
+}
+
+rc = ble_hs_hci_cmd_tx_empty_ack(
+BLE_HCI_OP(BLE_HCI_OGF_LE, 
BLE_HCI_OCF_LE_SET_PERIODIC_ADV_PARAMS), buf,
+sizeof(buf));
+
+if (rc != 0) {
+return rc;
+}
+
+return 0;
+}
+
+static int
+ble_gap_periodic_adv_params_validate(
+const struct ble_gap_periodic_adv_params *params)
+{
+if (!params) {
+return BLE_HS_EINVAL;
+}
+
+if (params->itvl_min > 0x || params->itvl_min < 6){
+return BLE_HS_EINVAL;
+}
+if (params->itvl_max > 0x || params->itvl_max < 6){
+return BLE_HS_EINVAL;
+}
+return 0;
+
+}
+
+int
+ble_gap_periodic_adv_configure(uint8_t instance,
+const struct ble_gap_periodic_adv_params *params)
+{
+int rc;
+
+if (instance >= BLE_ADV_INSTANCES) {
+return BLE_HS_EINVAL;
+}
+
+rc = ble_gap_periodic_adv_params_validate(params);
+if (rc) {
+return rc;
+}
+
+ble_hs_lock();
+
+/* The corresponding extended advertising instance should be configured */
+if (!ble_gap_slave[instance].configured){
+ble_hs_unlock();
+return ENOMEM;
+}
+
+/* Periodic advertising shall not be configured while it is already
+ * running.
+ * Bluetooth Core Specification, Section 7.8.61
+ */
+if (ble_gap_slave[instance].per_op == BLE_GAP_OP_S_PERIODIC_ADV){
+ble_hs_unlock();
+return BLE_HS_EINVAL;
+}
+
+rc = ble_gap_periodic_adv_params_tx(instance, params);
+if (rc) {
+ble_hs_unlock();
+return rc;
+}
+
+ble_gap_slave[instance].per_configured = 1;
+
+ble_hs_unlock();
+
+return 0;
+}
+
+int
+ble_gap_periodic_adv_start(uint8_t instance)
+{
+uint8_t buf[BLE_HCI_LE_SET_PERIODIC_ADV_ENABLE_LEN];
+uint16_t opcode;
+int rc;
+
+if (instance >= BLE_ADV_INSTANCES) {
+return BLE_HS_EINVAL;
+}
+
+ble_hs_lock();
+
+/* Periodic advertising cannot start unless it is configured before */
+if (!ble_gap_slave[instance].per_configured) {
+ble_hs_unlock();
+return BLE_HS_EINVAL;
+}
+
+
 
 Review comment:
   not needed empty line


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257625038
 
 

 ##
 File path: nimble/host/src/ble_hs_hci_cmd.c
 ##
 @@ -1605,6 +1605,167 @@ ble_hs_hci_cmd_build_le_ext_adv_remove(uint8_t handle,
 
 return 0;
 }
+
+#if MYNEWT_VAL(BLE_PERIODIC_ADV)
+int
+ble_hs_hci_cmd_build_le_periodic_adv_params(uint8_t handle,
+   const struct hci_periodic_adv_params 
*params,
+   uint8_t *cmd, int cmd_len)
+{
+BLE_HS_DBG_ASSERT(cmd_len >= BLE_HCI_LE_SET_PERIODIC_ADV_PARAMS_LEN);
+
+if (handle > 0xEF){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+if (params->max_interval > 0x || params->max_interval < 6){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+if (params->min_interval > 0x || params->min_interval < 6){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+
+cmd[0] = handle;
+
+put_le16([1], params->min_interval);
+put_le16([3], params->max_interval);
+put_le16([5], params->properties);
+
+return 0;
+}
+
+int
+ble_hs_hci_cmd_build_le_periodic_adv_enable(uint8_t enable,
+   uint8_t handle,
+   uint8_t *cmd, int cmd_len)
+{
+BLE_HS_DBG_ASSERT(cmd_len >= BLE_HCI_LE_SET_PERIODIC_ADV_ENABLE_LEN);
+
+if (enable > 1){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+
+cmd[0] = enable;
+cmd[1] = handle;
+
+return 0;
+}
+
+int
+ble_hs_hci_cmd_build_le_periodic_adv_data(uint8_t handle,
+ uint8_t operation,
+ struct os_mbuf *data,
+ uint8_t data_len,
+ uint8_t *cmd, int cmd_len)
+{
+BLE_HS_DBG_ASSERT(cmd_len >= 3 + data_len);
+
+if (!data){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+if (!data->om_data){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+if (handle > 0xEF){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+
+cmd[0] = handle;
+cmd[1] = operation;
+cmd[2] = data_len;
+os_mbuf_copydata(data, 0, data_len, cmd + 3);
+
+return 0;
+}
+
+int
+ble_hs_hci_cmd_build_le_periodic_adv_create_sync(uint8_t filter_policy,
+uint8_t adv_sid,
+uint8_t adv_add_type,
+const uint8_t *adv_addr,
+uint16_t skip,
+uint16_t sync_timeout, uint8_t unused,
+uint8_t *cmd, int cmd_len)
+{
+BLE_HS_DBG_ASSERT(cmd_len >= BLE_HCI_LE_PERIODIC_ADV_CREATE_SYNC_LEN);
+
+if (filter_policy > 1 || adv_add_type > 1){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+if (adv_sid > 0x0f){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+if (skip > 0x1f3 || sync_timeout > 0x4000 || sync_timeout < 0x0A){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+cmd[0] = filter_policy;
+cmd[1] = adv_sid;
+cmd[2] = adv_add_type;
+memcpy([3], adv_addr, 6);
+put_le16([9], skip);
+put_le16([11], sync_timeout);
+cmd[13] = unused;
+
+
+return 0;
+}
+
+int
+ble_hs_hci_cmd_build_le_periodic_adv_terminate_sync(uint16_t sync_handle,
+   uint8_t *cmd, int cmd_len)
+{
+BLE_HS_DBG_ASSERT(cmd_len >= BLE_HCI_LE_PERIODIC_ADV_TERM_SYNC_LEN);
+
+if (sync_handle > 0xEF){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+
+cmd[0] = sync_handle;
+
+return 0;
+}
+
+int
+ble_hs_hci_cmd_build_le_add_dev_to_periodic_adv_list(
+uint8_t adv_add_type,
+const uint8_t *adv_addr,
+uint8_t adv_sid,
+uint8_t *cmd, int cmd_len)
+{
+BLE_HS_DBG_ASSERT(cmd_len >= BLE_HCI_LE_ADD_DEV_TO_PERIODIC_ADV_LIST_LEN);
+
+if (adv_add_type > 1 || adv_sid > 0x0f){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+
+
 
 Review comment:
   remove empty line


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257617433
 
 

 ##
 File path: nimble/host/src/ble_gap.c
 ##
 @@ -2919,13 +3049,533 @@ ble_gap_ext_adv_remove(uint8_t instance)
 return 0;
 }
 
+#if MYNEWT_VAL(BLE_PERIODIC_ADV)
+static int
+ble_gap_periodic_adv_params_tx(uint8_t instance,
+const struct ble_gap_periodic_adv_params *params)
+
+{
+struct hci_periodic_adv_params hci_adv_params;
+uint8_t buf[BLE_HCI_LE_SET_PERIODIC_ADV_PARAMS_LEN];
+int rc;
+
+memset(_adv_params, 0, sizeof(hci_adv_params));
+
+if (params->include_tx_power) {
+hci_adv_params.properties |= 
BLE_HCI_LE_SET_PERIODIC_ADV_PROP_INC_TX_PWR;
+}
+
+/* Fill optional fields if application did not specify them. */
+if (params->itvl_min == 0 && params->itvl_max == 0) {
+hci_adv_params.min_interval = 30 / 1.25;   //30 ms
+hci_adv_params.max_interval = 60 / 1.25;   //150 ms
+
+} else {
+hci_adv_params.min_interval = params->itvl_min;
+hci_adv_params.max_interval = params->itvl_max;
+}
+
+rc = ble_hs_hci_cmd_build_le_periodic_adv_params(instance, 
_adv_params, buf,
+sizeof(buf));
+if (rc != 0) {
+return rc;
+}
+
+rc = ble_hs_hci_cmd_tx_empty_ack(
+BLE_HCI_OP(BLE_HCI_OGF_LE, 
BLE_HCI_OCF_LE_SET_PERIODIC_ADV_PARAMS), buf,
+sizeof(buf));
+
+if (rc != 0) {
+return rc;
+}
+
+return 0;
+}
+
+static int
+ble_gap_periodic_adv_params_validate(
+const struct ble_gap_periodic_adv_params *params)
+{
+if (!params) {
+return BLE_HS_EINVAL;
+}
+
+if (params->itvl_min > 0x || params->itvl_min < 6){
+return BLE_HS_EINVAL;
+}
+if (params->itvl_max > 0x || params->itvl_max < 6){
 
 Review comment:
   as above


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257606400
 
 

 ##
 File path: nimble/host/src/ble_gap.c
 ##
 @@ -182,11 +194,14 @@ struct ble_gap_snapshot {
 void *cb_arg;
 };
 
-static SLIST_HEAD(ble_gap_hook_list, ble_gap_event_listener) 
ble_gap_event_listener_list;
 
 Review comment:
   I believe that from this place down to line 1336 changes are not relevant. 
Please remove them.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257607496
 
 

 ##
 File path: nimble/host/src/ble_gap.c
 ##
 @@ -1315,6 +1333,112 @@ ble_gap_rx_adv_set_terminated(struct 
hci_le_adv_set_terminated *evt)
 }
 #endif
 
+/* Periodic adv events */
+#if MYNEWT_VAL(BLE_EXT_ADV) && MYNEWT_VAL(BLE_PERIODIC_ADV)
+void
+ble_gap_rx_peroidic_adv_sync_estab(
+struct hci_le_subev_periodic_adv_sync_estab *evt)
+{
+struct ble_gap_event event;
+struct ble_gap_master_state state;
+struct ble_hs_periodic_sync * psync;
+
+memset(, 0, sizeof event);
+
+/* There must be memory for psync as the check was done when creating
+ * sync
+ */
+psync = ble_hs_periodic_sync_alloc();
+BLE_HS_DBG_ASSERT(psync != NULL);
 
 Review comment:
   It is good oto have BLE_HS_DBG_ASSERT here but if it is not enabled we 
should also handle out of memory also without it. Please return when `psync` is 
NULL


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257633933
 
 

 ##
 File path: nimble/host/src/ble_hs_stop.c
 ##
 @@ -71,8 +111,8 @@ ble_hs_stop_terminate_next_conn(void)
 
 handle = ble_hs_atomic_first_conn_handle();
 if (handle == BLE_HS_CONN_HANDLE_NONE) {
-/* No open connections.  Signal completion of the stop procedure. */
-ble_hs_stop_done(0);
+/* No open connections.  Check for any active periodic sync */
+ble_hs_stop_terminate_next_periodic_sync();
 
 Review comment:
Can we rename it to `ble_terminate_periodic_sync() ` which would return `0` 
on success and some error otherwise.
   Then I would move this function to `ble_hs_stop`  before host start close 
all the connections.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257636645
 
 

 ##
 File path: nimble/syscfg.yml
 ##
 @@ -34,6 +34,10 @@ syscfg.defs:
 BLE_MAX_CONNECTIONS:
 description: 'The maximum number of concurrent connections.'
 value: 1
+BLE_MAX_PERIODIC_SCANNING_SM:
+description: >
+The maximum number of concurrent periodic scanning state machines.
 
 Review comment:
   Could we add here that it is the maximum number of periodic sync which can 
be created?


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257619204
 
 

 ##
 File path: nimble/host/src/ble_gap.c
 ##
 @@ -2919,13 +3049,533 @@ ble_gap_ext_adv_remove(uint8_t instance)
 return 0;
 }
 
+#if MYNEWT_VAL(BLE_PERIODIC_ADV)
+static int
+ble_gap_periodic_adv_params_tx(uint8_t instance,
+const struct ble_gap_periodic_adv_params *params)
+
+{
+struct hci_periodic_adv_params hci_adv_params;
+uint8_t buf[BLE_HCI_LE_SET_PERIODIC_ADV_PARAMS_LEN];
+int rc;
+
+memset(_adv_params, 0, sizeof(hci_adv_params));
+
+if (params->include_tx_power) {
+hci_adv_params.properties |= 
BLE_HCI_LE_SET_PERIODIC_ADV_PROP_INC_TX_PWR;
+}
+
+/* Fill optional fields if application did not specify them. */
+if (params->itvl_min == 0 && params->itvl_max == 0) {
+hci_adv_params.min_interval = 30 / 1.25;   //30 ms
+hci_adv_params.max_interval = 60 / 1.25;   //150 ms
+
+} else {
+hci_adv_params.min_interval = params->itvl_min;
+hci_adv_params.max_interval = params->itvl_max;
+}
+
+rc = ble_hs_hci_cmd_build_le_periodic_adv_params(instance, 
_adv_params, buf,
+sizeof(buf));
+if (rc != 0) {
+return rc;
+}
+
+rc = ble_hs_hci_cmd_tx_empty_ack(
+BLE_HCI_OP(BLE_HCI_OGF_LE, 
BLE_HCI_OCF_LE_SET_PERIODIC_ADV_PARAMS), buf,
+sizeof(buf));
+
+if (rc != 0) {
+return rc;
+}
+
+return 0;
+}
+
+static int
+ble_gap_periodic_adv_params_validate(
+const struct ble_gap_periodic_adv_params *params)
+{
+if (!params) {
+return BLE_HS_EINVAL;
+}
+
+if (params->itvl_min > 0x || params->itvl_min < 6){
+return BLE_HS_EINVAL;
+}
+if (params->itvl_max > 0x || params->itvl_max < 6){
+return BLE_HS_EINVAL;
+}
+return 0;
+
+}
+
+int
+ble_gap_periodic_adv_configure(uint8_t instance,
+const struct ble_gap_periodic_adv_params *params)
+{
+int rc;
+
+if (instance >= BLE_ADV_INSTANCES) {
+return BLE_HS_EINVAL;
+}
+
+rc = ble_gap_periodic_adv_params_validate(params);
+if (rc) {
+return rc;
+}
+
+ble_hs_lock();
+
+/* The corresponding extended advertising instance should be configured */
+if (!ble_gap_slave[instance].configured){
+ble_hs_unlock();
+return ENOMEM;
+}
+
+/* Periodic advertising shall not be configured while it is already
+ * running.
+ * Bluetooth Core Specification, Section 7.8.61
+ */
+if (ble_gap_slave[instance].per_op == BLE_GAP_OP_S_PERIODIC_ADV){
+ble_hs_unlock();
+return BLE_HS_EINVAL;
+}
+
+rc = ble_gap_periodic_adv_params_tx(instance, params);
+if (rc) {
+ble_hs_unlock();
+return rc;
+}
+
+ble_gap_slave[instance].per_configured = 1;
+
+ble_hs_unlock();
+
+return 0;
+}
+
+int
+ble_gap_periodic_adv_start(uint8_t instance)
+{
+uint8_t buf[BLE_HCI_LE_SET_PERIODIC_ADV_ENABLE_LEN];
+uint16_t opcode;
+int rc;
+
+if (instance >= BLE_ADV_INSTANCES) {
+return BLE_HS_EINVAL;
+}
+
+ble_hs_lock();
+
+/* Periodic advertising cannot start unless it is configured before */
+if (!ble_gap_slave[instance].per_configured) {
+ble_hs_unlock();
+return BLE_HS_EINVAL;
+}
+
+
+opcode = BLE_HCI_OP(BLE_HCI_OGF_LE, 
BLE_HCI_OCF_LE_SET_PERIODIC_ADV_ENABLE);
+
+rc = ble_hs_hci_cmd_build_le_periodic_adv_enable(1, instance, buf, 
sizeof(buf));
+if (rc != 0) {
+ble_hs_unlock();
+return rc;
+}
+
+rc = ble_hs_hci_cmd_tx_empty_ack(opcode, buf, sizeof(buf));
+if (rc != 0) {
+ble_hs_unlock();
+return rc;
+}
+
+ble_gap_slave[instance].per_op = BLE_GAP_OP_S_PERIODIC_ADV;
+
+ble_hs_unlock();
+return 0;
+}
+
+static int
+ble_gap_periodic_adv_set(uint8_t instance, uint16_t opcode,
+struct os_mbuf **data)
+{
+
+/* In that case we always fit all data in single HCI command */
+#if MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE) <= BLE_HCI_MAX_PERIODIC_ADV_DATA_LEN
+
+static uint8_t buf[BLE_HCI_SET_PERIODIC_ADV_DATA_HDR_LEN +
+   MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE)];
+uint16_t len = OS_MBUF_PKTLEN(*data);
+int rc;
+
+opcode = BLE_HCI_OP(BLE_HCI_OGF_LE, opcode);
+
+rc = ble_hs_hci_cmd_build_le_periodic_adv_data(
+instance,
+BLE_HCI_LE_SET_DATA_OPER_COMPLETE,
+*data, len,
+buf, sizeof(buf));
+
+if (rc) {
+return rc;
+}
+
+os_mbuf_adj(*data, MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE));
+*data = os_mbuf_trim_front(*data);
+
+return ble_hs_hci_cmd_tx_empty_ack(opcode, buf,
+BLE_HCI_SET_PERIODIC_ADV_DATA_HDR_LEN + len);
+#else
+static uint8_t buf[BLE_HCI_SET_PERIODIC_ADV_DATA_HDR_LEN +
+   BLE_HCI_MAX_PERIODIC_ADV_DATA_LEN];

[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257635662
 
 

 ##
 File path: porting/nimble/include/syscfg/syscfg.h
 ##
 @@ -378,7 +378,7 @@
 
 /*** nimble */
 #ifndef MYNEWT_VAL_BLE_EXT_ADV
-#define MYNEWT_VAL_BLE_EXT_ADV (0)
+#define MYNEWT_VAL_BLE_EXT_ADV (1)
 
 Review comment:
   Please don't change  default configuration for port.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257635867
 
 

 ##
 File path: porting/nimble/include/syscfg/syscfg.h
 ##
 @@ -418,6 +422,11 @@
 #define MYNEWT_VAL_BLE_ATT_PREFERRED_MTU (256)
 #endif
 
+
+#ifndef MYNEWT_VAL_BLE_PERIODIC_ADV
+#define MYNEWT_VAL_BLE_PERIODIC_ADV (1)
 
 Review comment:
   please set it to 0


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257616398
 
 

 ##
 File path: nimble/host/src/ble_gap.c
 ##
 @@ -2919,13 +3049,533 @@ ble_gap_ext_adv_remove(uint8_t instance)
 return 0;
 }
 
+#if MYNEWT_VAL(BLE_PERIODIC_ADV)
+static int
+ble_gap_periodic_adv_params_tx(uint8_t instance,
+const struct ble_gap_periodic_adv_params *params)
+
+{
+struct hci_periodic_adv_params hci_adv_params;
+uint8_t buf[BLE_HCI_LE_SET_PERIODIC_ADV_PARAMS_LEN];
+int rc;
+
+memset(_adv_params, 0, sizeof(hci_adv_params));
+
+if (params->include_tx_power) {
+hci_adv_params.properties |= 
BLE_HCI_LE_SET_PERIODIC_ADV_PROP_INC_TX_PWR;
+}
+
+/* Fill optional fields if application did not specify them. */
+if (params->itvl_min == 0 && params->itvl_max == 0) {
+hci_adv_params.min_interval = 30 / 1.25;   //30 ms
+hci_adv_params.max_interval = 60 / 1.25;   //150 ms
 
 Review comment:
   comment does not match. BTW. Maybe we could have defines for default ones?


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257620884
 
 

 ##
 File path: nimble/host/src/ble_gap.c
 ##
 @@ -2919,13 +3049,533 @@ ble_gap_ext_adv_remove(uint8_t instance)
 return 0;
 }
 
+#if MYNEWT_VAL(BLE_PERIODIC_ADV)
+static int
+ble_gap_periodic_adv_params_tx(uint8_t instance,
+const struct ble_gap_periodic_adv_params *params)
+
+{
+struct hci_periodic_adv_params hci_adv_params;
+uint8_t buf[BLE_HCI_LE_SET_PERIODIC_ADV_PARAMS_LEN];
+int rc;
+
+memset(_adv_params, 0, sizeof(hci_adv_params));
+
+if (params->include_tx_power) {
+hci_adv_params.properties |= 
BLE_HCI_LE_SET_PERIODIC_ADV_PROP_INC_TX_PWR;
+}
+
+/* Fill optional fields if application did not specify them. */
+if (params->itvl_min == 0 && params->itvl_max == 0) {
+hci_adv_params.min_interval = 30 / 1.25;   //30 ms
+hci_adv_params.max_interval = 60 / 1.25;   //150 ms
+
+} else {
+hci_adv_params.min_interval = params->itvl_min;
+hci_adv_params.max_interval = params->itvl_max;
+}
+
+rc = ble_hs_hci_cmd_build_le_periodic_adv_params(instance, 
_adv_params, buf,
+sizeof(buf));
+if (rc != 0) {
+return rc;
+}
+
+rc = ble_hs_hci_cmd_tx_empty_ack(
+BLE_HCI_OP(BLE_HCI_OGF_LE, 
BLE_HCI_OCF_LE_SET_PERIODIC_ADV_PARAMS), buf,
+sizeof(buf));
+
+if (rc != 0) {
+return rc;
+}
+
+return 0;
+}
+
+static int
+ble_gap_periodic_adv_params_validate(
+const struct ble_gap_periodic_adv_params *params)
+{
+if (!params) {
+return BLE_HS_EINVAL;
+}
+
+if (params->itvl_min > 0x || params->itvl_min < 6){
+return BLE_HS_EINVAL;
+}
+if (params->itvl_max > 0x || params->itvl_max < 6){
+return BLE_HS_EINVAL;
+}
+return 0;
+
+}
+
+int
+ble_gap_periodic_adv_configure(uint8_t instance,
+const struct ble_gap_periodic_adv_params *params)
+{
+int rc;
+
+if (instance >= BLE_ADV_INSTANCES) {
+return BLE_HS_EINVAL;
+}
+
+rc = ble_gap_periodic_adv_params_validate(params);
+if (rc) {
+return rc;
+}
+
+ble_hs_lock();
+
+/* The corresponding extended advertising instance should be configured */
+if (!ble_gap_slave[instance].configured){
+ble_hs_unlock();
+return ENOMEM;
+}
+
+/* Periodic advertising shall not be configured while it is already
+ * running.
+ * Bluetooth Core Specification, Section 7.8.61
+ */
+if (ble_gap_slave[instance].per_op == BLE_GAP_OP_S_PERIODIC_ADV){
+ble_hs_unlock();
+return BLE_HS_EINVAL;
+}
+
+rc = ble_gap_periodic_adv_params_tx(instance, params);
+if (rc) {
+ble_hs_unlock();
+return rc;
+}
+
+ble_gap_slave[instance].per_configured = 1;
+
+ble_hs_unlock();
+
+return 0;
+}
+
+int
+ble_gap_periodic_adv_start(uint8_t instance)
+{
+uint8_t buf[BLE_HCI_LE_SET_PERIODIC_ADV_ENABLE_LEN];
+uint16_t opcode;
+int rc;
+
+if (instance >= BLE_ADV_INSTANCES) {
+return BLE_HS_EINVAL;
+}
+
+ble_hs_lock();
+
+/* Periodic advertising cannot start unless it is configured before */
+if (!ble_gap_slave[instance].per_configured) {
+ble_hs_unlock();
+return BLE_HS_EINVAL;
+}
+
+
+opcode = BLE_HCI_OP(BLE_HCI_OGF_LE, 
BLE_HCI_OCF_LE_SET_PERIODIC_ADV_ENABLE);
+
+rc = ble_hs_hci_cmd_build_le_periodic_adv_enable(1, instance, buf, 
sizeof(buf));
+if (rc != 0) {
+ble_hs_unlock();
+return rc;
+}
+
+rc = ble_hs_hci_cmd_tx_empty_ack(opcode, buf, sizeof(buf));
+if (rc != 0) {
+ble_hs_unlock();
+return rc;
+}
+
+ble_gap_slave[instance].per_op = BLE_GAP_OP_S_PERIODIC_ADV;
+
+ble_hs_unlock();
+return 0;
+}
+
+static int
+ble_gap_periodic_adv_set(uint8_t instance, uint16_t opcode,
+struct os_mbuf **data)
+{
+
+/* In that case we always fit all data in single HCI command */
+#if MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE) <= BLE_HCI_MAX_PERIODIC_ADV_DATA_LEN
+
+static uint8_t buf[BLE_HCI_SET_PERIODIC_ADV_DATA_HDR_LEN +
+   MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE)];
+uint16_t len = OS_MBUF_PKTLEN(*data);
+int rc;
+
+opcode = BLE_HCI_OP(BLE_HCI_OGF_LE, opcode);
+
+rc = ble_hs_hci_cmd_build_le_periodic_adv_data(
+instance,
+BLE_HCI_LE_SET_DATA_OPER_COMPLETE,
+*data, len,
+buf, sizeof(buf));
+
+if (rc) {
+return rc;
+}
+
+os_mbuf_adj(*data, MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE));
+*data = os_mbuf_trim_front(*data);
+
+return ble_hs_hci_cmd_tx_empty_ack(opcode, buf,
+BLE_HCI_SET_PERIODIC_ADV_DATA_HDR_LEN + len);
+#else
+static uint8_t buf[BLE_HCI_SET_PERIODIC_ADV_DATA_HDR_LEN +
+   BLE_HCI_MAX_PERIODIC_ADV_DATA_LEN];

[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257617527
 
 

 ##
 File path: nimble/host/src/ble_gap.c
 ##
 @@ -2919,13 +3049,533 @@ ble_gap_ext_adv_remove(uint8_t instance)
 return 0;
 }
 
+#if MYNEWT_VAL(BLE_PERIODIC_ADV)
+static int
+ble_gap_periodic_adv_params_tx(uint8_t instance,
+const struct ble_gap_periodic_adv_params *params)
+
+{
+struct hci_periodic_adv_params hci_adv_params;
+uint8_t buf[BLE_HCI_LE_SET_PERIODIC_ADV_PARAMS_LEN];
+int rc;
+
+memset(_adv_params, 0, sizeof(hci_adv_params));
+
+if (params->include_tx_power) {
+hci_adv_params.properties |= 
BLE_HCI_LE_SET_PERIODIC_ADV_PROP_INC_TX_PWR;
+}
+
+/* Fill optional fields if application did not specify them. */
+if (params->itvl_min == 0 && params->itvl_max == 0) {
+hci_adv_params.min_interval = 30 / 1.25;   //30 ms
+hci_adv_params.max_interval = 60 / 1.25;   //150 ms
+
+} else {
+hci_adv_params.min_interval = params->itvl_min;
+hci_adv_params.max_interval = params->itvl_max;
+}
+
+rc = ble_hs_hci_cmd_build_le_periodic_adv_params(instance, 
_adv_params, buf,
+sizeof(buf));
+if (rc != 0) {
+return rc;
+}
+
+rc = ble_hs_hci_cmd_tx_empty_ack(
+BLE_HCI_OP(BLE_HCI_OGF_LE, 
BLE_HCI_OCF_LE_SET_PERIODIC_ADV_PARAMS), buf,
+sizeof(buf));
+
+if (rc != 0) {
+return rc;
+}
+
+return 0;
+}
+
+static int
+ble_gap_periodic_adv_params_validate(
+const struct ble_gap_periodic_adv_params *params)
+{
+if (!params) {
+return BLE_HS_EINVAL;
+}
+
+if (params->itvl_min > 0x || params->itvl_min < 6){
+return BLE_HS_EINVAL;
+}
+if (params->itvl_max > 0x || params->itvl_max < 6){
+return BLE_HS_EINVAL;
+}
+return 0;
+
+}
+
+int
+ble_gap_periodic_adv_configure(uint8_t instance,
+const struct ble_gap_periodic_adv_params *params)
+{
+int rc;
+
+if (instance >= BLE_ADV_INSTANCES) {
+return BLE_HS_EINVAL;
+}
+
+rc = ble_gap_periodic_adv_params_validate(params);
+if (rc) {
+return rc;
+}
+
+ble_hs_lock();
+
+/* The corresponding extended advertising instance should be configured */
+if (!ble_gap_slave[instance].configured){
 
 Review comment:
   space before {


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257617850
 
 

 ##
 File path: nimble/host/src/ble_gap.c
 ##
 @@ -2919,13 +3049,533 @@ ble_gap_ext_adv_remove(uint8_t instance)
 return 0;
 }
 
+#if MYNEWT_VAL(BLE_PERIODIC_ADV)
+static int
+ble_gap_periodic_adv_params_tx(uint8_t instance,
+const struct ble_gap_periodic_adv_params *params)
+
+{
+struct hci_periodic_adv_params hci_adv_params;
+uint8_t buf[BLE_HCI_LE_SET_PERIODIC_ADV_PARAMS_LEN];
+int rc;
+
+memset(_adv_params, 0, sizeof(hci_adv_params));
+
+if (params->include_tx_power) {
+hci_adv_params.properties |= 
BLE_HCI_LE_SET_PERIODIC_ADV_PROP_INC_TX_PWR;
+}
+
+/* Fill optional fields if application did not specify them. */
+if (params->itvl_min == 0 && params->itvl_max == 0) {
+hci_adv_params.min_interval = 30 / 1.25;   //30 ms
+hci_adv_params.max_interval = 60 / 1.25;   //150 ms
+
+} else {
+hci_adv_params.min_interval = params->itvl_min;
+hci_adv_params.max_interval = params->itvl_max;
+}
+
+rc = ble_hs_hci_cmd_build_le_periodic_adv_params(instance, 
_adv_params, buf,
+sizeof(buf));
+if (rc != 0) {
+return rc;
+}
+
+rc = ble_hs_hci_cmd_tx_empty_ack(
+BLE_HCI_OP(BLE_HCI_OGF_LE, 
BLE_HCI_OCF_LE_SET_PERIODIC_ADV_PARAMS), buf,
+sizeof(buf));
+
+if (rc != 0) {
+return rc;
+}
+
+return 0;
+}
+
+static int
+ble_gap_periodic_adv_params_validate(
+const struct ble_gap_periodic_adv_params *params)
+{
+if (!params) {
+return BLE_HS_EINVAL;
+}
+
+if (params->itvl_min > 0x || params->itvl_min < 6){
+return BLE_HS_EINVAL;
+}
+if (params->itvl_max > 0x || params->itvl_max < 6){
+return BLE_HS_EINVAL;
+}
+return 0;
+
+}
+
+int
+ble_gap_periodic_adv_configure(uint8_t instance,
+const struct ble_gap_periodic_adv_params *params)
+{
+int rc;
+
+if (instance >= BLE_ADV_INSTANCES) {
+return BLE_HS_EINVAL;
+}
+
+rc = ble_gap_periodic_adv_params_validate(params);
+if (rc) {
+return rc;
+}
+
+ble_hs_lock();
+
+/* The corresponding extended advertising instance should be configured */
+if (!ble_gap_slave[instance].configured){
+ble_hs_unlock();
+return ENOMEM;
+}
+
+/* Periodic advertising shall not be configured while it is already
+ * running.
+ * Bluetooth Core Specification, Section 7.8.61
+ */
+if (ble_gap_slave[instance].per_op == BLE_GAP_OP_S_PERIODIC_ADV){
+ble_hs_unlock();
+return BLE_HS_EINVAL;
+}
+
+rc = ble_gap_periodic_adv_params_tx(instance, params);
+if (rc) {
+ble_hs_unlock();
+return rc;
+}
+
+ble_gap_slave[instance].per_configured = 1;
+
+ble_hs_unlock();
+
+return 0;
+}
+
+int
+ble_gap_periodic_adv_start(uint8_t instance)
+{
+uint8_t buf[BLE_HCI_LE_SET_PERIODIC_ADV_ENABLE_LEN];
+uint16_t opcode;
+int rc;
+
+if (instance >= BLE_ADV_INSTANCES) {
+return BLE_HS_EINVAL;
+}
+
+ble_hs_lock();
+
+/* Periodic advertising cannot start unless it is configured before */
+if (!ble_gap_slave[instance].per_configured) {
+ble_hs_unlock();
+return BLE_HS_EINVAL;
+}
+
+
+opcode = BLE_HCI_OP(BLE_HCI_OGF_LE, 
BLE_HCI_OCF_LE_SET_PERIODIC_ADV_ENABLE);
+
+rc = ble_hs_hci_cmd_build_le_periodic_adv_enable(1, instance, buf, 
sizeof(buf));
+if (rc != 0) {
+ble_hs_unlock();
+return rc;
+}
+
+rc = ble_hs_hci_cmd_tx_empty_ack(opcode, buf, sizeof(buf));
+if (rc != 0) {
+ble_hs_unlock();
+return rc;
+}
+
+ble_gap_slave[instance].per_op = BLE_GAP_OP_S_PERIODIC_ADV;
+
+ble_hs_unlock();
+return 0;
+}
+
+static int
+ble_gap_periodic_adv_set(uint8_t instance, uint16_t opcode,
+struct os_mbuf **data)
+{
+
 
 Review comment:
   not needed empty line


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257628177
 
 

 ##
 File path: nimble/host/src/ble_hs_periodic_disc.c
 ##
 @@ -0,0 +1,233 @@
+/*
+ * 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 "syscfg/syscfg.h"
+#include "os/os.h"
+#include "host/ble_hs_id.h"
+#include "ble_hs_priv.h"
+
+static SLIST_HEAD(, ble_hs_periodic_sync) ble_hs_periodic_sync_handles;
+static struct os_mempool ble_hs_periodic_sync_pool;
+
+static os_membuf_t ble_hs_psync_elem_mem[
+OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_MAX_PERIODIC_SCANNING_SM),
+sizeof (struct ble_hs_periodic_sync))
+];
+
+int
+ble_hs_periodic_sync_can_alloc(void)
+{
+#if !MYNEWT_VAL(BLE_PERIODIC_ADV)
+return 0;
+#endif
+
+return (ble_hs_periodic_sync_pool.mp_num_free >= 1);
+}
+
+struct ble_hs_periodic_sync *
+ble_hs_periodic_sync_alloc()
+{
+#if !MYNEWT_VAL(BLE_PERIODIC_ADV)
+return NULL;
+#endif
+
+struct ble_hs_periodic_sync *psync;
+
+psync = os_memblock_get(_hs_periodic_sync_pool);
+if (psync == NULL) {
+goto err;
+}
+memset(psync, 0, sizeof *psync);
+
+return psync;
+
+err:
+ble_hs_periodic_sync_free(psync);
+return NULL;
+}
+
+
 
 Review comment:
   please remove 2 empty lines


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257627439
 
 

 ##
 File path: nimble/host/src/ble_hs_hci_evt.c
 ##
 @@ -631,7 +709,8 @@ ble_hs_hci_evt_le_scan_timeout(uint8_t subevent, uint8_t 
*data, int len)
 }
 
 static int
-ble_hs_hci_evt_le_adv_set_terminated(uint8_t subevent, uint8_t *data, int len)
 
 Review comment:
   changes not relevant here and below in this file


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257602282
 
 

 ##
 File path: nimble/host/src/ble_gap.c
 ##
 @@ -155,6 +163,10 @@ struct ble_gap_slave_state {
 unsigned int directed:1;
 unsigned int legacy_pdu:1;
 unsigned int rnd_addr_set:1;
+#if MYNEWT_VAL(BLE_PERIODIC_ADV)
+unsigned int per_configured:1;
+uint8_t   per_op;
 
 Review comment:
   I think `per_op` should be removed. Instead `op` should be used with a code 
`BLE_GAP_OP_S_ADV`
   Having this and `per_configured` should be sufficient.
   
   BTW.  just a nitpick, can we change `per_configured` to 
`periodic_configured`?


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257617349
 
 

 ##
 File path: nimble/host/src/ble_gap.c
 ##
 @@ -2919,13 +3049,533 @@ ble_gap_ext_adv_remove(uint8_t instance)
 return 0;
 }
 
+#if MYNEWT_VAL(BLE_PERIODIC_ADV)
+static int
+ble_gap_periodic_adv_params_tx(uint8_t instance,
+const struct ble_gap_periodic_adv_params *params)
+
+{
+struct hci_periodic_adv_params hci_adv_params;
+uint8_t buf[BLE_HCI_LE_SET_PERIODIC_ADV_PARAMS_LEN];
+int rc;
+
+memset(_adv_params, 0, sizeof(hci_adv_params));
+
+if (params->include_tx_power) {
+hci_adv_params.properties |= 
BLE_HCI_LE_SET_PERIODIC_ADV_PROP_INC_TX_PWR;
+}
+
+/* Fill optional fields if application did not specify them. */
+if (params->itvl_min == 0 && params->itvl_max == 0) {
+hci_adv_params.min_interval = 30 / 1.25;   //30 ms
+hci_adv_params.max_interval = 60 / 1.25;   //150 ms
+
+} else {
+hci_adv_params.min_interval = params->itvl_min;
+hci_adv_params.max_interval = params->itvl_max;
+}
+
+rc = ble_hs_hci_cmd_build_le_periodic_adv_params(instance, 
_adv_params, buf,
+sizeof(buf));
+if (rc != 0) {
+return rc;
+}
+
+rc = ble_hs_hci_cmd_tx_empty_ack(
+BLE_HCI_OP(BLE_HCI_OGF_LE, 
BLE_HCI_OCF_LE_SET_PERIODIC_ADV_PARAMS), buf,
+sizeof(buf));
+
+if (rc != 0) {
+return rc;
+}
+
+return 0;
+}
+
+static int
+ble_gap_periodic_adv_params_validate(
+const struct ble_gap_periodic_adv_params *params)
+{
+if (!params) {
+return BLE_HS_EINVAL;
+}
+
+if (params->itvl_min > 0x || params->itvl_min < 6){
 
 Review comment:
   space before `{`


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257629476
 
 

 ##
 File path: nimble/host/src/ble_hs_periodic_disc_priv.h
 ##
 @@ -0,0 +1,63 @@
+/*
+ * 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 H_BLE_HS_PERIODIC_DISC_
+#define H_BLE_HS_PERIODIC_DISC_
+
+#include 
+#include "os/queue.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct ble_hs_periodic_sync {
+SLIST_ENTRY(ble_hs_periodic_sync) bhc_next;
+uint16_t   sync_handle;
+uint8_tadv_sid;
+uint8_tadvertiser_addr_type;
+ble_addr_t advertiser_addr;
+uint8_tadvertiser_phy;
+uint16_t   periodic_adv_itvl;
+uint8_tadvertiser_clock_accuracy;
+};
+
+
 
 Review comment:
   please remove 2 empty lines


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257618851
 
 

 ##
 File path: nimble/host/src/ble_gap.c
 ##
 @@ -2919,13 +3049,533 @@ ble_gap_ext_adv_remove(uint8_t instance)
 return 0;
 }
 
+#if MYNEWT_VAL(BLE_PERIODIC_ADV)
+static int
+ble_gap_periodic_adv_params_tx(uint8_t instance,
+const struct ble_gap_periodic_adv_params *params)
+
+{
+struct hci_periodic_adv_params hci_adv_params;
+uint8_t buf[BLE_HCI_LE_SET_PERIODIC_ADV_PARAMS_LEN];
+int rc;
+
+memset(_adv_params, 0, sizeof(hci_adv_params));
+
+if (params->include_tx_power) {
+hci_adv_params.properties |= 
BLE_HCI_LE_SET_PERIODIC_ADV_PROP_INC_TX_PWR;
+}
+
+/* Fill optional fields if application did not specify them. */
+if (params->itvl_min == 0 && params->itvl_max == 0) {
+hci_adv_params.min_interval = 30 / 1.25;   //30 ms
+hci_adv_params.max_interval = 60 / 1.25;   //150 ms
+
+} else {
+hci_adv_params.min_interval = params->itvl_min;
+hci_adv_params.max_interval = params->itvl_max;
+}
+
+rc = ble_hs_hci_cmd_build_le_periodic_adv_params(instance, 
_adv_params, buf,
+sizeof(buf));
+if (rc != 0) {
+return rc;
+}
+
+rc = ble_hs_hci_cmd_tx_empty_ack(
+BLE_HCI_OP(BLE_HCI_OGF_LE, 
BLE_HCI_OCF_LE_SET_PERIODIC_ADV_PARAMS), buf,
+sizeof(buf));
+
+if (rc != 0) {
+return rc;
+}
+
+return 0;
+}
+
+static int
+ble_gap_periodic_adv_params_validate(
+const struct ble_gap_periodic_adv_params *params)
+{
+if (!params) {
+return BLE_HS_EINVAL;
+}
+
+if (params->itvl_min > 0x || params->itvl_min < 6){
+return BLE_HS_EINVAL;
+}
+if (params->itvl_max > 0x || params->itvl_max < 6){
+return BLE_HS_EINVAL;
+}
+return 0;
+
+}
+
+int
+ble_gap_periodic_adv_configure(uint8_t instance,
+const struct ble_gap_periodic_adv_params *params)
+{
+int rc;
+
+if (instance >= BLE_ADV_INSTANCES) {
+return BLE_HS_EINVAL;
+}
+
+rc = ble_gap_periodic_adv_params_validate(params);
+if (rc) {
+return rc;
+}
+
+ble_hs_lock();
+
+/* The corresponding extended advertising instance should be configured */
+if (!ble_gap_slave[instance].configured){
+ble_hs_unlock();
+return ENOMEM;
+}
+
+/* Periodic advertising shall not be configured while it is already
+ * running.
+ * Bluetooth Core Specification, Section 7.8.61
+ */
+if (ble_gap_slave[instance].per_op == BLE_GAP_OP_S_PERIODIC_ADV){
+ble_hs_unlock();
+return BLE_HS_EINVAL;
+}
+
+rc = ble_gap_periodic_adv_params_tx(instance, params);
+if (rc) {
+ble_hs_unlock();
+return rc;
+}
+
+ble_gap_slave[instance].per_configured = 1;
+
+ble_hs_unlock();
+
+return 0;
+}
+
+int
+ble_gap_periodic_adv_start(uint8_t instance)
+{
+uint8_t buf[BLE_HCI_LE_SET_PERIODIC_ADV_ENABLE_LEN];
+uint16_t opcode;
+int rc;
+
+if (instance >= BLE_ADV_INSTANCES) {
+return BLE_HS_EINVAL;
+}
+
+ble_hs_lock();
+
+/* Periodic advertising cannot start unless it is configured before */
+if (!ble_gap_slave[instance].per_configured) {
+ble_hs_unlock();
+return BLE_HS_EINVAL;
+}
+
+
+opcode = BLE_HCI_OP(BLE_HCI_OGF_LE, 
BLE_HCI_OCF_LE_SET_PERIODIC_ADV_ENABLE);
+
+rc = ble_hs_hci_cmd_build_le_periodic_adv_enable(1, instance, buf, 
sizeof(buf));
+if (rc != 0) {
+ble_hs_unlock();
+return rc;
+}
+
+rc = ble_hs_hci_cmd_tx_empty_ack(opcode, buf, sizeof(buf));
+if (rc != 0) {
+ble_hs_unlock();
+return rc;
+}
+
+ble_gap_slave[instance].per_op = BLE_GAP_OP_S_PERIODIC_ADV;
+
+ble_hs_unlock();
+return 0;
+}
+
+static int
+ble_gap_periodic_adv_set(uint8_t instance, uint16_t opcode,
+struct os_mbuf **data)
+{
+
+/* In that case we always fit all data in single HCI command */
+#if MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE) <= BLE_HCI_MAX_PERIODIC_ADV_DATA_LEN
+
+static uint8_t buf[BLE_HCI_SET_PERIODIC_ADV_DATA_HDR_LEN +
+   MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE)];
+uint16_t len = OS_MBUF_PKTLEN(*data);
+int rc;
+
+opcode = BLE_HCI_OP(BLE_HCI_OGF_LE, opcode);
+
+rc = ble_hs_hci_cmd_build_le_periodic_adv_data(
+instance,
+BLE_HCI_LE_SET_DATA_OPER_COMPLETE,
+*data, len,
+buf, sizeof(buf));
+
+if (rc) {
+return rc;
+}
+
+os_mbuf_adj(*data, MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE));
+*data = os_mbuf_trim_front(*data);
+
+return ble_hs_hci_cmd_tx_empty_ack(opcode, buf,
+BLE_HCI_SET_PERIODIC_ADV_DATA_HDR_LEN + len);
+#else
+static uint8_t buf[BLE_HCI_SET_PERIODIC_ADV_DATA_HDR_LEN +
+   BLE_HCI_MAX_PERIODIC_ADV_DATA_LEN];

[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257623578
 
 

 ##
 File path: nimble/host/src/ble_hs_hci_cmd.c
 ##
 @@ -1605,6 +1605,167 @@ ble_hs_hci_cmd_build_le_ext_adv_remove(uint8_t handle,
 
 return 0;
 }
+
+#if MYNEWT_VAL(BLE_PERIODIC_ADV)
+int
+ble_hs_hci_cmd_build_le_periodic_adv_params(uint8_t handle,
+   const struct hci_periodic_adv_params 
*params,
+   uint8_t *cmd, int cmd_len)
+{
+BLE_HS_DBG_ASSERT(cmd_len >= BLE_HCI_LE_SET_PERIODIC_ADV_PARAMS_LEN);
+
+if (handle > 0xEF){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+if (params->max_interval > 0x || params->max_interval < 6){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+if (params->min_interval > 0x || params->min_interval < 6){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+
+cmd[0] = handle;
+
+put_le16([1], params->min_interval);
+put_le16([3], params->max_interval);
+put_le16([5], params->properties);
+
+return 0;
+}
+
+int
+ble_hs_hci_cmd_build_le_periodic_adv_enable(uint8_t enable,
+   uint8_t handle,
+   uint8_t *cmd, int cmd_len)
+{
+BLE_HS_DBG_ASSERT(cmd_len >= BLE_HCI_LE_SET_PERIODIC_ADV_ENABLE_LEN);
+
+if (enable > 1){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+
+cmd[0] = enable;
+cmd[1] = handle;
+
+return 0;
+}
+
+int
+ble_hs_hci_cmd_build_le_periodic_adv_data(uint8_t handle,
+ uint8_t operation,
+ struct os_mbuf *data,
+ uint8_t data_len,
+ uint8_t *cmd, int cmd_len)
+{
+BLE_HS_DBG_ASSERT(cmd_len >= 3 + data_len);
+
+if (!data){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+if (!data->om_data){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+if (handle > 0xEF){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+
+cmd[0] = handle;
+cmd[1] = operation;
+cmd[2] = data_len;
+os_mbuf_copydata(data, 0, data_len, cmd + 3);
+
+return 0;
+}
+
+int
+ble_hs_hci_cmd_build_le_periodic_adv_create_sync(uint8_t filter_policy,
+uint8_t adv_sid,
+uint8_t adv_add_type,
+const uint8_t *adv_addr,
+uint16_t skip,
+uint16_t sync_timeout, uint8_t unused,
+uint8_t *cmd, int cmd_len)
+{
+BLE_HS_DBG_ASSERT(cmd_len >= BLE_HCI_LE_PERIODIC_ADV_CREATE_SYNC_LEN);
+
+if (filter_policy > 1 || adv_add_type > 1){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+if (adv_sid > 0x0f){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+if (skip > 0x1f3 || sync_timeout > 0x4000 || sync_timeout < 0x0A){
+return BLE_ERR_INV_HCI_CMD_PARMS;
+}
+cmd[0] = filter_policy;
+cmd[1] = adv_sid;
+cmd[2] = adv_add_type;
+memcpy([3], adv_addr, 6);
+put_le16([9], skip);
+put_le16([11], sync_timeout);
+cmd[13] = unused;
+
 
 Review comment:
   remove empty line


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257584500
 
 

 ##
 File path: nimble/host/include/host/ble_gap.h
 ##
 @@ -708,6 +711,47 @@ struct ble_gap_event {
 uint8_t tx_phy;
 uint8_t rx_phy;
 } phy_updated;
+#if MYNEWT_VAL(BLE_EXT_ADV) && MYNEWT_VAL(BLE_PERIODIC_ADV)
+/**
+ * Represents an periodic advertising sync established during discovery
+ * procedure.  Valid for the following event types:
+ * o BLE_GAP_EVENT_PERIODIC_ADV_SYNC_ESTAB
+ */
+struct {
+uint8_t status;
+uint16_t sync_handle;
+uint8_t sid;
+uint8_t adv_addr_type;
+uint8_t adv_addr[6];
+uint8_t adv_phy;
+uint16_t per_adv_ival;
+uint8_t adv_clk_accuracy;
+} per_adv_sync_estab;
+
+
+/**
+ * Represents a Periodic advertising report received during discovery
+ * procedure.  Valid for the following event types:
+ * o BLE_GAP_EVENT_PERIODIC_DISC
+ */
+struct {
+uint16_t sync_handle;
+uint8_t tx_power;
+int8_t rssi;
+uint8_t _unused;
+uint8_t data_status;
+uint8_t data_length;
+uint8_t *data;
+} per_disc;
+/**
 
 Review comment:
   please add empty line


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] rymanluk commented on a change in pull request #283: Adding Periodic Advertising Feature

2019-02-18 Thread GitBox
rymanluk commented on a change in pull request #283: Adding Periodic 
Advertising Feature
URL: https://github.com/apache/mynewt-nimble/pull/283#discussion_r257618690
 
 

 ##
 File path: nimble/host/src/ble_gap.c
 ##
 @@ -2919,13 +3049,533 @@ ble_gap_ext_adv_remove(uint8_t instance)
 return 0;
 }
 
+#if MYNEWT_VAL(BLE_PERIODIC_ADV)
+static int
+ble_gap_periodic_adv_params_tx(uint8_t instance,
+const struct ble_gap_periodic_adv_params *params)
+
+{
+struct hci_periodic_adv_params hci_adv_params;
+uint8_t buf[BLE_HCI_LE_SET_PERIODIC_ADV_PARAMS_LEN];
+int rc;
+
+memset(_adv_params, 0, sizeof(hci_adv_params));
+
+if (params->include_tx_power) {
+hci_adv_params.properties |= 
BLE_HCI_LE_SET_PERIODIC_ADV_PROP_INC_TX_PWR;
+}
+
+/* Fill optional fields if application did not specify them. */
+if (params->itvl_min == 0 && params->itvl_max == 0) {
+hci_adv_params.min_interval = 30 / 1.25;   //30 ms
+hci_adv_params.max_interval = 60 / 1.25;   //150 ms
+
+} else {
+hci_adv_params.min_interval = params->itvl_min;
+hci_adv_params.max_interval = params->itvl_max;
+}
+
+rc = ble_hs_hci_cmd_build_le_periodic_adv_params(instance, 
_adv_params, buf,
+sizeof(buf));
+if (rc != 0) {
+return rc;
+}
+
+rc = ble_hs_hci_cmd_tx_empty_ack(
+BLE_HCI_OP(BLE_HCI_OGF_LE, 
BLE_HCI_OCF_LE_SET_PERIODIC_ADV_PARAMS), buf,
+sizeof(buf));
+
+if (rc != 0) {
+return rc;
+}
+
+return 0;
+}
+
+static int
+ble_gap_periodic_adv_params_validate(
+const struct ble_gap_periodic_adv_params *params)
+{
+if (!params) {
+return BLE_HS_EINVAL;
+}
+
+if (params->itvl_min > 0x || params->itvl_min < 6){
+return BLE_HS_EINVAL;
+}
+if (params->itvl_max > 0x || params->itvl_max < 6){
+return BLE_HS_EINVAL;
+}
+return 0;
+
+}
+
+int
+ble_gap_periodic_adv_configure(uint8_t instance,
+const struct ble_gap_periodic_adv_params *params)
+{
+int rc;
+
+if (instance >= BLE_ADV_INSTANCES) {
+return BLE_HS_EINVAL;
+}
+
+rc = ble_gap_periodic_adv_params_validate(params);
+if (rc) {
+return rc;
+}
+
+ble_hs_lock();
+
+/* The corresponding extended advertising instance should be configured */
+if (!ble_gap_slave[instance].configured){
+ble_hs_unlock();
+return ENOMEM;
+}
+
+/* Periodic advertising shall not be configured while it is already
+ * running.
+ * Bluetooth Core Specification, Section 7.8.61
+ */
+if (ble_gap_slave[instance].per_op == BLE_GAP_OP_S_PERIODIC_ADV){
+ble_hs_unlock();
+return BLE_HS_EINVAL;
+}
+
+rc = ble_gap_periodic_adv_params_tx(instance, params);
+if (rc) {
+ble_hs_unlock();
+return rc;
+}
+
+ble_gap_slave[instance].per_configured = 1;
+
+ble_hs_unlock();
+
+return 0;
+}
+
+int
+ble_gap_periodic_adv_start(uint8_t instance)
+{
+uint8_t buf[BLE_HCI_LE_SET_PERIODIC_ADV_ENABLE_LEN];
+uint16_t opcode;
+int rc;
+
+if (instance >= BLE_ADV_INSTANCES) {
+return BLE_HS_EINVAL;
+}
+
+ble_hs_lock();
+
+/* Periodic advertising cannot start unless it is configured before */
+if (!ble_gap_slave[instance].per_configured) {
+ble_hs_unlock();
+return BLE_HS_EINVAL;
+}
+
+
+opcode = BLE_HCI_OP(BLE_HCI_OGF_LE, 
BLE_HCI_OCF_LE_SET_PERIODIC_ADV_ENABLE);
+
+rc = ble_hs_hci_cmd_build_le_periodic_adv_enable(1, instance, buf, 
sizeof(buf));
+if (rc != 0) {
+ble_hs_unlock();
+return rc;
+}
+
+rc = ble_hs_hci_cmd_tx_empty_ack(opcode, buf, sizeof(buf));
+if (rc != 0) {
+ble_hs_unlock();
+return rc;
+}
+
+ble_gap_slave[instance].per_op = BLE_GAP_OP_S_PERIODIC_ADV;
+
+ble_hs_unlock();
+return 0;
+}
+
+static int
+ble_gap_periodic_adv_set(uint8_t instance, uint16_t opcode,
+struct os_mbuf **data)
+{
+
+/* In that case we always fit all data in single HCI command */
+#if MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE) <= BLE_HCI_MAX_PERIODIC_ADV_DATA_LEN
+
+static uint8_t buf[BLE_HCI_SET_PERIODIC_ADV_DATA_HDR_LEN +
+   MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE)];
+uint16_t len = OS_MBUF_PKTLEN(*data);
+int rc;
+
+opcode = BLE_HCI_OP(BLE_HCI_OGF_LE, opcode);
+
+rc = ble_hs_hci_cmd_build_le_periodic_adv_data(
+instance,
+BLE_HCI_LE_SET_DATA_OPER_COMPLETE,
+*data, len,
+buf, sizeof(buf));
+
+if (rc) {
+return rc;
+}
+
+os_mbuf_adj(*data, MYNEWT_VAL(BLE_EXT_ADV_MAX_SIZE));
+*data = os_mbuf_trim_front(*data);
+
+return ble_hs_hci_cmd_tx_empty_ack(opcode, buf,
+BLE_HCI_SET_PERIODIC_ADV_DATA_HDR_LEN + len);
+#else
+static uint8_t buf[BLE_HCI_SET_PERIODIC_ADV_DATA_HDR_LEN +
+   BLE_HCI_MAX_PERIODIC_ADV_DATA_LEN];

[GitHub] utzig merged pull request #1643: [FRDM-K64F] Increase size of bootloader slot

2019-02-18 Thread GitBox
utzig merged pull request #1643: [FRDM-K64F] Increase size of bootloader slot
URL: https://github.com/apache/mynewt-core/pull/1643
 
 
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[mynewt-core] branch master updated: [FRDM-K64F] Increase size of bootloader slot

2019-02-18 Thread utzig
This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
 new 05fb31b  [FRDM-K64F] Increase size of bootloader slot
05fb31b is described below

commit 05fb31b845ebb5a2849e16ae5e377f661ae2095e
Author: Fabio Utzig 
AuthorDate: Thu Feb 14 15:21:25 2019 -0200

[FRDM-K64F] Increase size of bootloader slot

This makes the bootloader 40kb (from 24kb) to have enough space to do
encrypted image testing, and reduces slot 0/1 sizes from 480KB to 472KB
which does not seem very significant.

Also the linker script size of the bootloader was correctly adjusted
to what is defined on the BSP avoiding non-caught errors when the
bootloader size is big enough to overflow the configured space.
---
 hw/bsp/frdm-k64f/MK64FN1M0xxx12_flash.ld  |  6 +++---
 hw/bsp/frdm-k64f/boot-MK64FN1M0xxx12_flash.ld |  2 +-
 hw/bsp/frdm-k64f/bsp.yml  | 12 ++--
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/hw/bsp/frdm-k64f/MK64FN1M0xxx12_flash.ld 
b/hw/bsp/frdm-k64f/MK64FN1M0xxx12_flash.ld
index 4ca8b6b..a14123a 100644
--- a/hw/bsp/frdm-k64f/MK64FN1M0xxx12_flash.ld
+++ b/hw/bsp/frdm-k64f/MK64FN1M0xxx12_flash.ld
@@ -58,9 +58,9 @@ M_VECTOR_RAM_SIZE = DEFINED(__ram_vector_table__) ? 0x0400 : 
0x0;
 /* Specify the memory areas */
 MEMORY
 {
-  m_interrupts  (RX)  : ORIGIN = 0x8000, LENGTH = 0x0420
-  m_flash_config(RX)  : ORIGIN = 0x8420, LENGTH = 0x0010
-  FLASH (RX)  : ORIGIN = 0x8430, LENGTH = 0x0010-0x8430
+  m_interrupts  (RX)  : ORIGIN = 0xC000, LENGTH = 0x0420
+  m_flash_config(RX)  : ORIGIN = 0xC420, LENGTH = 0x0010
+  FLASH (RX)  : ORIGIN = 0xC430, LENGTH = 0x0010-0xC430
   RAM   (RW)  : ORIGIN = 0x1FFF, LENGTH = 0x0004
 }
 
diff --git a/hw/bsp/frdm-k64f/boot-MK64FN1M0xxx12_flash.ld 
b/hw/bsp/frdm-k64f/boot-MK64FN1M0xxx12_flash.ld
index 845c16b..6a5989f 100644
--- a/hw/bsp/frdm-k64f/boot-MK64FN1M0xxx12_flash.ld
+++ b/hw/bsp/frdm-k64f/boot-MK64FN1M0xxx12_flash.ld
@@ -60,7 +60,7 @@ MEMORY
 {
   m_interrupts  (RX)  : ORIGIN = 0x, LENGTH = 0x0400
   m_flash_config(RX)  : ORIGIN = 0x0400, LENGTH = 0x0010
-  FLASH (RX)  : ORIGIN = 0x0410, LENGTH = 0x000FFBF0
+  FLASH (RX)  : ORIGIN = 0x0410, LENGTH = 0x9BF0
   RAM   (RW)  : ORIGIN = 0x1FFF, LENGTH = 0x0004
 }
 
diff --git a/hw/bsp/frdm-k64f/bsp.yml b/hw/bsp/frdm-k64f/bsp.yml
index 0da1a9a..58acd4f 100644
--- a/hw/bsp/frdm-k64f/bsp.yml
+++ b/hw/bsp/frdm-k64f/bsp.yml
@@ -32,19 +32,19 @@ bsp.flash_map:
 FLASH_AREA_BOOTLOADER:
 device: 0
 offset: 0x
-size: 24kB
+size: 40kB
 FLASH_AREA_IMAGE_SCRATCH:
 device: 0
-offset: 0x6000
+offset: 0xA000
 size: 8kB
 FLASH_AREA_IMAGE_0:
 device: 0
-offset: 0x8000
-size: 480kB
+offset: 0xC000
+size: 472kB
 FLASH_AREA_IMAGE_1:
 device: 0
-offset: 0x0008
-size: 480kB
+offset: 0x00082000
+size: 472kB
 
 # User areas
 FLASH_AREA_REBOOT_LOG:



[GitHub] mkiiskila commented on a change in pull request #1641: CoAP; cleanups for observing resources when using transport(s) with connections

2019-02-18 Thread GitBox
mkiiskila commented on a change in pull request #1641: CoAP; cleanups for 
observing resources when using transport(s) with connections
URL: https://github.com/apache/mynewt-core/pull/1641#discussion_r257804633
 
 

 ##
 File path: net/oic/src/port/mynewt/conns.c
 ##
 @@ -0,0 +1,109 @@
+/*
+ * 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 
+#include 
+
+#include "oic/oc_log.h"
+#include "oic/port/oc_connectivity.h"
+#include "oic/port/mynewt/adaptor.h"
+
+#define OC_CONN_EV_CB   MYNEWT_VAL(OC_CONN_EV_CB_CNT)
+
+static SLIST_HEAD(, oc_conn_cb) oc_conn_cbs =
+SLIST_HEAD_INITIALIZER(oc_conn_cbs);
+static STAILQ_HEAD(, oc_conn_ev) oc_conn_evs =
+STAILQ_HEAD_INITIALIZER(oc_conn_evs);
+
+static void oc_conn_ev_deliver(struct os_event *);
+static struct os_event oc_conn_cb_ev = {
+.ev_cb = oc_conn_ev_deliver,
+};
+static struct os_mempool oc_conn_ev_pool;
+static uint8_t oc_conn_ev_area[OS_MEMPOOL_BYTES(OC_CONN_EV_CB,
+sizeof(struct oc_conn_ev))];
+
+void
+oc_conn_cb_register(struct oc_conn_cb *cb)
+{
+SLIST_INSERT_HEAD(_conn_cbs, cb, occ_next);
+}
+
+void
+oc_conn_init(void)
+{
+os_mempool_init(_conn_ev_pool, OC_CONN_EV_CB, sizeof(struct oc_conn_ev),
+oc_conn_ev_area, "oc_conn_ev");
+}
+
+struct oc_conn_ev *
+oc_conn_ev_alloc(void)
+{
+return os_memblock_get(_conn_ev_pool);
+}
+
+static void
+oc_conn_ev_queue(struct oc_conn_ev *oce)
+{
+int sr;
+
+OS_ENTER_CRITICAL(sr);
+STAILQ_INSERT_TAIL(_conn_evs, oce, oce_next);
+OS_EXIT_CRITICAL(sr);
+os_eventq_put(oc_evq_get(), _conn_cb_ev);
+}
+
+void
+oc_conn_created(struct oc_conn_ev *oce)
+{
+OC_LOG(DEBUG, "oc_conn_created: ");
+OC_LOG_ENDPOINT(LOG_LEVEL_DEBUG, >oce_oe);
+oce->oce_type = OC_ENDPOINT_CONN_EV_CLOSE;
 
 Review comment:
   Yes, it should be.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] utzig opened a new pull request #1649: Add initial crypto driver framework

2019-02-18 Thread GitBox
utzig opened a new pull request #1649: Add initial crypto driver framework
URL: https://github.com/apache/mynewt-core/pull/1649
 
 
   This is a proposal for a crypto framework using HW acceleration in MCUs that 
have the support.
   
   It was tested with the added app (crypto_test) as well as enc_flash + 
encrypted images on NXP K64F and Nrf52840-PDK.
   
   Still a few TODOS before this is complete for reviews:
   
   1) Some error handling in the main driver needs finishing
   2) Expand doxygen comments
   3) STM32 driver must be finished (remove IRQ handling because it's slower)
   
   PS: there are two commits which are not part of the PR but are helping me on 
my tests, will remove soon them soon...


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] apache-mynewt-bot commented on issue #1649: [WIP] [RFC] Add initial crypto driver framework

2019-02-18 Thread GitBox
apache-mynewt-bot commented on issue #1649: [WIP] [RFC] Add initial crypto 
driver framework
URL: https://github.com/apache/mynewt-core/pull/1649#issuecomment-464842785
 
 
   
   
   
   ## RAT Report (2019-02-18 18:54:41)
   
   ## New files with unknown licenses
   
   * https://github.com/apache/mynewt-core/blob/a0887d079428a88963596f2a1f7df1698a049ae3/hw/drivers/crypto/crypto_k64f/src/arch/cortex_m4/mmcau_aes_functions.s;>hw/drivers/crypto/crypto_k64f/src/arch/cortex_m4/mmcau_aes_functions.s
   
   
 Detailed analysis
   
   ## New files in this PR
   
   | License | File |
   |-|--|
   | AL | https://github.com/apache/mynewt-core/blob/9ae178fec1560e2c416708c16ed62ff7c23fa6e7/apps/crypto_test/pkg.yml;>apps/crypto_test/pkg.yml
 |
   | AL | https://github.com/apache/mynewt-core/blob/9ae178fec1560e2c416708c16ed62ff7c23fa6e7/apps/crypto_test/src/generate_aes_tables.py;>apps/crypto_test/src/generate_aes_tables.py
 |
   | AL | https://github.com/apache/mynewt-core/blob/9ae178fec1560e2c416708c16ed62ff7c23fa6e7/apps/crypto_test/src/main.c;>apps/crypto_test/src/main.c
 |
   | AL | https://github.com/apache/mynewt-core/blob/9ae178fec1560e2c416708c16ed62ff7c23fa6e7/apps/crypto_test/src/tables.c;>apps/crypto_test/src/tables.c
 |
   | AL | https://github.com/apache/mynewt-core/blob/9ae178fec1560e2c416708c16ed62ff7c23fa6e7/apps/crypto_test/syscfg.yml;>apps/crypto_test/syscfg.yml
 |
   | AL | https://github.com/apache/mynewt-core/blob/b9a824b7a2abb5af05348bdb90bdec546505559c/crypto/mbedtls/include/mbedtls/aes_alt.h;>crypto/mbedtls/include/mbedtls/aes_alt.h
 |
   | AL | https://github.com/apache/mynewt-core/blob/a0887d079428a88963596f2a1f7df1698a049ae3/hw/drivers/crypto/crypto_k64f/include/crypto_k64f/crypto_k64f.h;>hw/drivers/crypto/crypto_k64f/include/crypto_k64f/crypto_k64f.h
 |
   | AL | https://github.com/apache/mynewt-core/blob/a0887d079428a88963596f2a1f7df1698a049ae3/hw/drivers/crypto/crypto_k64f/pkg.yml;>hw/drivers/crypto/crypto_k64f/pkg.yml
 |
   | ?  | https://github.com/apache/mynewt-core/blob/a0887d079428a88963596f2a1f7df1698a049ae3/hw/drivers/crypto/crypto_k64f/src/arch/cortex_m4/mmcau_aes_functions.s;>hw/drivers/crypto/crypto_k64f/src/arch/cortex_m4/mmcau_aes_functions.s
 |
   | AL | https://github.com/apache/mynewt-core/blob/a0887d079428a88963596f2a1f7df1698a049ae3/hw/drivers/crypto/crypto_k64f/src/crypto_k64f.c;>hw/drivers/crypto/crypto_k64f/src/crypto_k64f.c
 |
   | AL | https://github.com/apache/mynewt-core/blob/672b365acbeddb6fd1e31568a504fddcf24551fd/hw/drivers/crypto/crypto_nrf52/include/crypto_nrf52/crypto_nrf52.h;>hw/drivers/crypto/crypto_nrf52/include/crypto_nrf52/crypto_nrf52.h
 |
   | AL | https://github.com/apache/mynewt-core/blob/672b365acbeddb6fd1e31568a504fddcf24551fd/hw/drivers/crypto/crypto_nrf52/pkg.yml;>hw/drivers/crypto/crypto_nrf52/pkg.yml
 |
   | AL | https://github.com/apache/mynewt-core/blob/672b365acbeddb6fd1e31568a504fddcf24551fd/hw/drivers/crypto/crypto_nrf52/src/crypto_nrf52.c;>hw/drivers/crypto/crypto_nrf52/src/crypto_nrf52.c
 |
   | AL | https://github.com/apache/mynewt-core/blob/78b740cdb87afe43dfb353543150e65218aa7d18/hw/drivers/crypto/crypto_stm32/include/crypto_stm32/crypto_stm32.h;>hw/drivers/crypto/crypto_stm32/include/crypto_stm32/crypto_stm32.h
 |
   | AL | https://github.com/apache/mynewt-core/blob/78b740cdb87afe43dfb353543150e65218aa7d18/hw/drivers/crypto/crypto_stm32/pkg.yml;>hw/drivers/crypto/crypto_stm32/pkg.yml
 |
   | AL | https://github.com/apache/mynewt-core/blob/78b740cdb87afe43dfb353543150e65218aa7d18/hw/drivers/crypto/crypto_stm32/src/crypto_stm32.c;>hw/drivers/crypto/crypto_stm32/src/crypto_stm32.c
 |
   | AL | https://github.com/apache/mynewt-core/blob/b9a824b7a2abb5af05348bdb90bdec546505559c/hw/drivers/crypto/include/crypto/aes_alt.h;>hw/drivers/crypto/include/crypto/aes_alt.h
 |
   | AL | https://github.com/apache/mynewt-core/blob/a3d378b09238dfc9ef1a03d046ec8d0b110b9f4c/hw/drivers/crypto/include/crypto/crypto.h;>hw/drivers/crypto/include/crypto/crypto.h
 |
   | AL | https://github.com/apache/mynewt-core/blob/a3d378b09238dfc9ef1a03d046ec8d0b110b9f4c/hw/drivers/crypto/pkg.yml;>hw/drivers/crypto/pkg.yml
 |
   | AL | https://github.com/apache/mynewt-core/blob/a3d378b09238dfc9ef1a03d046ec8d0b110b9f4c/hw/drivers/crypto/src/crypto.c;>hw/drivers/crypto/src/crypto.c
 |
   | AL | https://github.com/apache/mynewt-core/blob/b9a824b7a2abb5af05348bdb90bdec546505559c/hw/drivers/crypto/src/mbedtls_aes_alt.c;>hw/drivers/crypto/src/mbedtls_aes_alt.c
 |
   | AL | https://github.com/apache/mynewt-core/blob/7b6f2fb558c60d95ffb9efc5972a2e0f169ceade/hw/drivers/flash/enc_flash/ef_crypto/include/ef_crypto/ef_crypto.h;>hw/drivers/flash/enc_flash/ef_crypto/include/ef_crypto/ef_crypto.h
 |
   | AL | 

[GitHub] apache-mynewt-bot commented on issue #1649: [WIP] [RFC] Add initial crypto driver framework

2019-02-18 Thread GitBox
apache-mynewt-bot commented on issue #1649: [WIP] [RFC] Add initial crypto 
driver framework
URL: https://github.com/apache/mynewt-core/pull/1649#issuecomment-464855563
 
 
   
   
   
   ## RAT Report (2019-02-18 19:46:49)
   
   ## New files with unknown licenses
   
   * https://github.com/apache/mynewt-core/blob/a0887d079428a88963596f2a1f7df1698a049ae3/hw/drivers/crypto/crypto_k64f/src/arch/cortex_m4/mmcau_aes_functions.s;>hw/drivers/crypto/crypto_k64f/src/arch/cortex_m4/mmcau_aes_functions.s
   
   
 Detailed analysis
   
   ## New files in this PR
   
   | License | File |
   |-|--|
   | AL | https://github.com/apache/mynewt-core/blob/9ae178fec1560e2c416708c16ed62ff7c23fa6e7/apps/crypto_test/pkg.yml;>apps/crypto_test/pkg.yml
 |
   | AL | https://github.com/apache/mynewt-core/blob/9ae178fec1560e2c416708c16ed62ff7c23fa6e7/apps/crypto_test/src/generate_aes_tables.py;>apps/crypto_test/src/generate_aes_tables.py
 |
   | AL | https://github.com/apache/mynewt-core/blob/9ae178fec1560e2c416708c16ed62ff7c23fa6e7/apps/crypto_test/src/main.c;>apps/crypto_test/src/main.c
 |
   | AL | https://github.com/apache/mynewt-core/blob/9ae178fec1560e2c416708c16ed62ff7c23fa6e7/apps/crypto_test/src/tables.c;>apps/crypto_test/src/tables.c
 |
   | AL | https://github.com/apache/mynewt-core/blob/9ae178fec1560e2c416708c16ed62ff7c23fa6e7/apps/crypto_test/syscfg.yml;>apps/crypto_test/syscfg.yml
 |
   | AL | https://github.com/apache/mynewt-core/blob/b9a824b7a2abb5af05348bdb90bdec546505559c/crypto/mbedtls/include/mbedtls/aes_alt.h;>crypto/mbedtls/include/mbedtls/aes_alt.h
 |
   | AL | https://github.com/apache/mynewt-core/blob/a0887d079428a88963596f2a1f7df1698a049ae3/hw/drivers/crypto/crypto_k64f/include/crypto_k64f/crypto_k64f.h;>hw/drivers/crypto/crypto_k64f/include/crypto_k64f/crypto_k64f.h
 |
   | AL | https://github.com/apache/mynewt-core/blob/a0887d079428a88963596f2a1f7df1698a049ae3/hw/drivers/crypto/crypto_k64f/pkg.yml;>hw/drivers/crypto/crypto_k64f/pkg.yml
 |
   | ?  | https://github.com/apache/mynewt-core/blob/a0887d079428a88963596f2a1f7df1698a049ae3/hw/drivers/crypto/crypto_k64f/src/arch/cortex_m4/mmcau_aes_functions.s;>hw/drivers/crypto/crypto_k64f/src/arch/cortex_m4/mmcau_aes_functions.s
 |
   | AL | https://github.com/apache/mynewt-core/blob/a0887d079428a88963596f2a1f7df1698a049ae3/hw/drivers/crypto/crypto_k64f/src/crypto_k64f.c;>hw/drivers/crypto/crypto_k64f/src/crypto_k64f.c
 |
   | AL | https://github.com/apache/mynewt-core/blob/672b365acbeddb6fd1e31568a504fddcf24551fd/hw/drivers/crypto/crypto_nrf52/include/crypto_nrf52/crypto_nrf52.h;>hw/drivers/crypto/crypto_nrf52/include/crypto_nrf52/crypto_nrf52.h
 |
   | AL | https://github.com/apache/mynewt-core/blob/672b365acbeddb6fd1e31568a504fddcf24551fd/hw/drivers/crypto/crypto_nrf52/pkg.yml;>hw/drivers/crypto/crypto_nrf52/pkg.yml
 |
   | AL | https://github.com/apache/mynewt-core/blob/672b365acbeddb6fd1e31568a504fddcf24551fd/hw/drivers/crypto/crypto_nrf52/src/crypto_nrf52.c;>hw/drivers/crypto/crypto_nrf52/src/crypto_nrf52.c
 |
   | AL | https://github.com/apache/mynewt-core/blob/78b740cdb87afe43dfb353543150e65218aa7d18/hw/drivers/crypto/crypto_stm32/include/crypto_stm32/crypto_stm32.h;>hw/drivers/crypto/crypto_stm32/include/crypto_stm32/crypto_stm32.h
 |
   | AL | https://github.com/apache/mynewt-core/blob/78b740cdb87afe43dfb353543150e65218aa7d18/hw/drivers/crypto/crypto_stm32/pkg.yml;>hw/drivers/crypto/crypto_stm32/pkg.yml
 |
   | AL | https://github.com/apache/mynewt-core/blob/78b740cdb87afe43dfb353543150e65218aa7d18/hw/drivers/crypto/crypto_stm32/src/crypto_stm32.c;>hw/drivers/crypto/crypto_stm32/src/crypto_stm32.c
 |
   | AL | https://github.com/apache/mynewt-core/blob/b9a824b7a2abb5af05348bdb90bdec546505559c/hw/drivers/crypto/include/crypto/aes_alt.h;>hw/drivers/crypto/include/crypto/aes_alt.h
 |
   | AL | https://github.com/apache/mynewt-core/blob/a3d378b09238dfc9ef1a03d046ec8d0b110b9f4c/hw/drivers/crypto/include/crypto/crypto.h;>hw/drivers/crypto/include/crypto/crypto.h
 |
   | AL | https://github.com/apache/mynewt-core/blob/a3d378b09238dfc9ef1a03d046ec8d0b110b9f4c/hw/drivers/crypto/pkg.yml;>hw/drivers/crypto/pkg.yml
 |
   | AL | https://github.com/apache/mynewt-core/blob/a3d378b09238dfc9ef1a03d046ec8d0b110b9f4c/hw/drivers/crypto/src/crypto.c;>hw/drivers/crypto/src/crypto.c
 |
   | AL | https://github.com/apache/mynewt-core/blob/b9a824b7a2abb5af05348bdb90bdec546505559c/hw/drivers/crypto/src/mbedtls_aes_alt.c;>hw/drivers/crypto/src/mbedtls_aes_alt.c
 |
   | AL | https://github.com/apache/mynewt-core/blob/7b6f2fb558c60d95ffb9efc5972a2e0f169ceade/hw/drivers/flash/enc_flash/ef_crypto/include/ef_crypto/ef_crypto.h;>hw/drivers/flash/enc_flash/ef_crypto/include/ef_crypto/ef_crypto.h
 |
   | AL | 

[GitHub] apache-mynewt-bot removed a comment on issue #1649: [WIP] [RFC] Add initial crypto driver framework

2019-02-18 Thread GitBox
apache-mynewt-bot removed a comment on issue #1649: [WIP] [RFC] Add initial 
crypto driver framework
URL: https://github.com/apache/mynewt-core/pull/1649#issuecomment-464842785
 
 
   
   
   
   ## RAT Report (2019-02-18 18:54:41)
   
   ## New files with unknown licenses
   
   * https://github.com/apache/mynewt-core/blob/a0887d079428a88963596f2a1f7df1698a049ae3/hw/drivers/crypto/crypto_k64f/src/arch/cortex_m4/mmcau_aes_functions.s;>hw/drivers/crypto/crypto_k64f/src/arch/cortex_m4/mmcau_aes_functions.s
   
   
 Detailed analysis
   
   ## New files in this PR
   
   | License | File |
   |-|--|
   | AL | https://github.com/apache/mynewt-core/blob/9ae178fec1560e2c416708c16ed62ff7c23fa6e7/apps/crypto_test/pkg.yml;>apps/crypto_test/pkg.yml
 |
   | AL | https://github.com/apache/mynewt-core/blob/9ae178fec1560e2c416708c16ed62ff7c23fa6e7/apps/crypto_test/src/generate_aes_tables.py;>apps/crypto_test/src/generate_aes_tables.py
 |
   | AL | https://github.com/apache/mynewt-core/blob/9ae178fec1560e2c416708c16ed62ff7c23fa6e7/apps/crypto_test/src/main.c;>apps/crypto_test/src/main.c
 |
   | AL | https://github.com/apache/mynewt-core/blob/9ae178fec1560e2c416708c16ed62ff7c23fa6e7/apps/crypto_test/src/tables.c;>apps/crypto_test/src/tables.c
 |
   | AL | https://github.com/apache/mynewt-core/blob/9ae178fec1560e2c416708c16ed62ff7c23fa6e7/apps/crypto_test/syscfg.yml;>apps/crypto_test/syscfg.yml
 |
   | AL | https://github.com/apache/mynewt-core/blob/b9a824b7a2abb5af05348bdb90bdec546505559c/crypto/mbedtls/include/mbedtls/aes_alt.h;>crypto/mbedtls/include/mbedtls/aes_alt.h
 |
   | AL | https://github.com/apache/mynewt-core/blob/a0887d079428a88963596f2a1f7df1698a049ae3/hw/drivers/crypto/crypto_k64f/include/crypto_k64f/crypto_k64f.h;>hw/drivers/crypto/crypto_k64f/include/crypto_k64f/crypto_k64f.h
 |
   | AL | https://github.com/apache/mynewt-core/blob/a0887d079428a88963596f2a1f7df1698a049ae3/hw/drivers/crypto/crypto_k64f/pkg.yml;>hw/drivers/crypto/crypto_k64f/pkg.yml
 |
   | ?  | https://github.com/apache/mynewt-core/blob/a0887d079428a88963596f2a1f7df1698a049ae3/hw/drivers/crypto/crypto_k64f/src/arch/cortex_m4/mmcau_aes_functions.s;>hw/drivers/crypto/crypto_k64f/src/arch/cortex_m4/mmcau_aes_functions.s
 |
   | AL | https://github.com/apache/mynewt-core/blob/a0887d079428a88963596f2a1f7df1698a049ae3/hw/drivers/crypto/crypto_k64f/src/crypto_k64f.c;>hw/drivers/crypto/crypto_k64f/src/crypto_k64f.c
 |
   | AL | https://github.com/apache/mynewt-core/blob/672b365acbeddb6fd1e31568a504fddcf24551fd/hw/drivers/crypto/crypto_nrf52/include/crypto_nrf52/crypto_nrf52.h;>hw/drivers/crypto/crypto_nrf52/include/crypto_nrf52/crypto_nrf52.h
 |
   | AL | https://github.com/apache/mynewt-core/blob/672b365acbeddb6fd1e31568a504fddcf24551fd/hw/drivers/crypto/crypto_nrf52/pkg.yml;>hw/drivers/crypto/crypto_nrf52/pkg.yml
 |
   | AL | https://github.com/apache/mynewt-core/blob/672b365acbeddb6fd1e31568a504fddcf24551fd/hw/drivers/crypto/crypto_nrf52/src/crypto_nrf52.c;>hw/drivers/crypto/crypto_nrf52/src/crypto_nrf52.c
 |
   | AL | https://github.com/apache/mynewt-core/blob/78b740cdb87afe43dfb353543150e65218aa7d18/hw/drivers/crypto/crypto_stm32/include/crypto_stm32/crypto_stm32.h;>hw/drivers/crypto/crypto_stm32/include/crypto_stm32/crypto_stm32.h
 |
   | AL | https://github.com/apache/mynewt-core/blob/78b740cdb87afe43dfb353543150e65218aa7d18/hw/drivers/crypto/crypto_stm32/pkg.yml;>hw/drivers/crypto/crypto_stm32/pkg.yml
 |
   | AL | https://github.com/apache/mynewt-core/blob/78b740cdb87afe43dfb353543150e65218aa7d18/hw/drivers/crypto/crypto_stm32/src/crypto_stm32.c;>hw/drivers/crypto/crypto_stm32/src/crypto_stm32.c
 |
   | AL | https://github.com/apache/mynewt-core/blob/b9a824b7a2abb5af05348bdb90bdec546505559c/hw/drivers/crypto/include/crypto/aes_alt.h;>hw/drivers/crypto/include/crypto/aes_alt.h
 |
   | AL | https://github.com/apache/mynewt-core/blob/a3d378b09238dfc9ef1a03d046ec8d0b110b9f4c/hw/drivers/crypto/include/crypto/crypto.h;>hw/drivers/crypto/include/crypto/crypto.h
 |
   | AL | https://github.com/apache/mynewt-core/blob/a3d378b09238dfc9ef1a03d046ec8d0b110b9f4c/hw/drivers/crypto/pkg.yml;>hw/drivers/crypto/pkg.yml
 |
   | AL | https://github.com/apache/mynewt-core/blob/a3d378b09238dfc9ef1a03d046ec8d0b110b9f4c/hw/drivers/crypto/src/crypto.c;>hw/drivers/crypto/src/crypto.c
 |
   | AL | https://github.com/apache/mynewt-core/blob/b9a824b7a2abb5af05348bdb90bdec546505559c/hw/drivers/crypto/src/mbedtls_aes_alt.c;>hw/drivers/crypto/src/mbedtls_aes_alt.c
 |
   | AL | https://github.com/apache/mynewt-core/blob/7b6f2fb558c60d95ffb9efc5972a2e0f169ceade/hw/drivers/flash/enc_flash/ef_crypto/include/ef_crypto/ef_crypto.h;>hw/drivers/flash/enc_flash/ef_crypto/include/ef_crypto/ef_crypto.h
 |
   | AL |