You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2017/03/06 21:18:37 UTC

[01/50] incubator-mynewt-core git commit: SensorAPI - BNO055: Add calibration support

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/master 8cf8f54dc -> cfe42df79


SensorAPI - BNO055: Add calibration support

- Adding calibration support to driver and shell


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/316c18ac
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/316c18ac
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/316c18ac

Branch: refs/heads/master
Commit: 316c18acef538bae7a22d30013aa616020f112c8
Parents: b3be6f0
Author: Vipul Rahane <vi...@apache.org>
Authored: Tue Feb 28 16:41:58 2017 -0800
Committer: Vipul Rahane <vi...@apache.org>
Committed: Tue Feb 28 16:43:22 2017 -0800

----------------------------------------------------------------------
 .../sensors/bno055/include/bno055/bno055.h      |  90 +++++-
 hw/drivers/sensors/bno055/src/bno055.c          | 315 ++++++++++++++++++-
 hw/drivers/sensors/bno055/src/bno055_priv.h     |  10 +-
 hw/drivers/sensors/bno055/src/bno055_shell.c    |  74 +++++
 4 files changed, 472 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/316c18ac/hw/drivers/sensors/bno055/include/bno055/bno055.h
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bno055/include/bno055/bno055.h b/hw/drivers/sensors/bno055/include/bno055/bno055.h
index b8ceb02..0529a2d 100644
--- a/hw/drivers/sensors/bno055/include/bno055/bno055.h
+++ b/hw/drivers/sensors/bno055/include/bno055/bno055.h
@@ -123,7 +123,6 @@ extern "C" {
 #define BNO055_MAG_CFG_PWR_MODE_SUSPEND                   (0x2 << 5)
 #define BNO055_MAG_CFG_PWR_MODE_FORCE_MODE                (0x3 << 5)
 
-
 struct bno055_cfg {
     uint8_t bc_opr_mode;
     uint8_t bc_pwr_mode;
@@ -145,6 +144,27 @@ struct bno055_rev_info {
      uint16_t bri_sw_rev;
 };
 
+struct bno055_calib_info {
+    uint8_t bci_sys;
+    uint8_t bci_gyro;
+    uint8_t bci_accel;
+    uint8_t bci_mag;
+};
+
+struct bno055_sensor_offsets {
+    uint16_t bso_acc_off_x;
+    uint16_t bso_acc_off_y;
+    uint16_t bso_acc_off_z;
+    uint16_t bso_gyro_off_x;
+    uint16_t bso_gyro_off_y;
+    uint16_t bso_gyro_off_z;
+    uint16_t bso_mag_off_x;
+    uint16_t bso_mag_off_y;
+    uint16_t bso_mag_off_z;
+    uint16_t bso_acc_radius;
+    uint16_t bso_mag_radius;
+};
+
 /**
  * Initialize the bno055. This function is normally called by sysinit.
  *
@@ -197,6 +217,74 @@ int
 bno055_write8(uint8_t reg, uint8_t value);
 
 /**
+ * Writes a multiple bytes to the specified register
+ *
+ * @param The register address to write to
+ * @param The data buffer to write from
+ *
+ * @return 0 on success, non-zero error on failure.
+ */
+int
+bno055_writelen(uint8_t reg, uint8_t *buffer, uint8_t len);
+
+/**
+ * Gets current calibration status
+ *
+ * @param Calibration info structure to fill up calib state
+ * @return 0 on success, non-zero on failure
+ */
+int
+bno055_get_calib_status(struct bno055_calib_info *bci);
+
+/**
+ * Checks if bno055 is fully calibrated
+ *
+ * @return 0 on success, non-zero on failure
+ */
+int
+bno055_is_calib(void);
+
+/**
+ * Reads the sensor's offset registers into a byte array
+ *
+ * @param byte array to return offsets into
+ * @return 0 on success, non-zero on failure
+ *
+ */
+int
+bno055_get_raw_sensor_offsets(uint8_t *offsets);
+
+/**
+ *
+ * Reads the sensor's offset registers into an offset struct
+ *
+ * @param structure to fill up offsets data
+ * @return 0 on success, non-zero on failure
+ */
+int
+bno055_get_sensor_offsets(struct bno055_sensor_offsets *offsets);
+
+/**
+ *
+ * Writes calibration data to the sensor's offset registers
+ *
+ * @param calibration data
+ * @return 0 on success, non-zero on success
+ */
+int
+bno055_set_sensor_raw_offsets(uint8_t* calibdata, uint8_t len);
+
+/**
+ *
+ * Writes to the sensor's offset registers from an offset struct
+ *
+ * @param pointer to the offset structure
+ * @return 0 on success, non-zero on failure
+ */
+int
+bno055_set_sensor_offsets(struct bno055_sensor_offsets  *offsets);
+
+/**
  * Set operation mode for the bno055 sensor
  *
  * @param Operation mode for the sensor

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/316c18ac/hw/drivers/sensors/bno055/src/bno055.c
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bno055/src/bno055.c b/hw/drivers/sensors/bno055/src/bno055.c
index 1d06545..fb98197 100644
--- a/hw/drivers/sensors/bno055/src/bno055.c
+++ b/hw/drivers/sensors/bno055/src/bno055.c
@@ -136,6 +136,59 @@ bno055_write8(uint8_t reg, uint8_t value)
 }
 
 /**
+ * Writes a multiple bytes to the specified register
+ *
+ * @param The register address to write to
+ * @param The data buffer to write from
+ *
+ * @return 0 on success, non-zero error on failure.
+ */
+int
+bno055_writelen(uint8_t reg, uint8_t *buffer, uint8_t len)
+{
+    int rc;
+    uint8_t payload[23] = { reg, 0, 0, 0, 0, 0, 0, 0,
+                              0, 0, 0, 0, 0, 0, 0, 0,
+                              0, 0, 0, 0, 0, 0, 0};
+
+    struct hal_i2c_master_data data_struct = {
+        .address = MYNEWT_VAL(BNO055_I2CADDR),
+        .len = 1,
+        .buffer = payload
+    };
+
+    memcpy(&payload[1], buffer, len);
+
+    /* Register write */
+    rc = hal_i2c_master_write(MYNEWT_VAL(BNO055_I2CBUS), &data_struct,
+                              OS_TICKS_PER_SEC / 10, 1);
+    if (rc) {
+        BNO055_ERR("I2C access failed at address 0x%02X\n", addr);
+#if MYNEWT_VAL(BNO055_STATS)
+        STATS_INC(g_bno055stats, errors);
+#endif
+        goto err;
+    }
+
+    memset(payload, 0, sizeof(payload));
+    data_struct.len = len;
+    rc = hal_i2c_master_write(MYNEWT_VAL(BNO055_I2CBUS), &data_struct,
+                              OS_TICKS_PER_SEC / 10, len);
+
+    if (rc) {
+        BNO055_ERR("Failed to read from 0x%02X:0x%02X\n", addr, reg);
+#if MYNEWT_VAL(BNO055_STATS)
+        STATS_INC(g_bno055stats, errors);
+#endif
+        goto err;
+    }
+
+    return 0;
+err:
+    return rc;
+}
+
+/**
  * Reads a single byte from the specified register
  *
  * @param The register address to read from
@@ -198,7 +251,9 @@ static int
 bno055_readlen(uint8_t reg, uint8_t *buffer, uint8_t len)
 {
     int rc;
-    uint8_t payload[8] = { reg, 0, 0, 0, 0, 0, 0, 0};
+    uint8_t payload[23] = { reg, 0, 0, 0, 0, 0, 0, 0,
+                              0, 0, 0, 0, 0, 0, 0, 0,
+                              0, 0, 0, 0, 0, 0, 0};
 
     struct hal_i2c_master_data data_struct = {
         .address = MYNEWT_VAL(BNO055_I2CADDR),
@@ -206,13 +261,8 @@ bno055_readlen(uint8_t reg, uint8_t *buffer, uint8_t len)
         .buffer = payload
     };
 
-    if (len > 8) {
-        rc = SYS_EINVAL;
-        goto err;
-    }
-
     /* Clear the supplied buffer */
-    memset(buffer, 0, 8);
+    memset(buffer, 0, 22);
 
     /* Register write */
     rc = hal_i2c_master_write(MYNEWT_VAL(BNO055_I2CBUS), &data_struct,
@@ -225,7 +275,7 @@ bno055_readlen(uint8_t reg, uint8_t *buffer, uint8_t len)
         goto err;
     }
 
-    /* Read six bytes back */
+    /* Read len bytes back */
     memset(payload, 0, sizeof(payload));
     data_struct.len = len;
     rc = hal_i2c_master_read(MYNEWT_VAL(BNO055_I2CBUS), &data_struct,
@@ -247,7 +297,6 @@ err:
     return rc;
 }
 
-
 /**
  * Setting operation mode for the bno055 sensor
  *
@@ -685,7 +734,7 @@ bno055_find_reg(sensor_type_t type, uint8_t *reg)
 {
     int rc;
 
-    rc = 0;
+    rc = SYS_EOK;
     switch(type) {
         case SENSOR_TYPE_ACCELEROMETER:
             *reg = BNO055_ACCEL_DATA_X_LSB_ADDR;
@@ -1035,6 +1084,248 @@ err:
     return rc;
 }
 
+/**
+ * Gets current calibration status
+ *
+ * @param Calibration info structure to fill up calib state
+ * @return 0 on success, non-zero on failure
+ */
+int
+bno055_get_calib_status(struct bno055_calib_info *bci)
+{
+    uint8_t status;
+    int rc;
+
+    rc = bno055_read8(BNO055_CALIB_STAT_ADDR, &status);
+    if (rc) {
+        goto err;
+    }
+
+    bci->bci_sys = (status >> 6) & 0x03;
+    bci->bci_gyro = (status >> 4) & 0x03;
+    bci->bci_accel = (status >> 2) & 0x03;
+    bci->bci_mag = status & 0x03;
+
+    return 0;
+err:
+    return rc;
+}
+
+/**
+ * Checks if bno055 is fully calibrated
+ *
+ * @return 0 on success, non-zero on failure
+ */
+int
+bno055_is_calib(void)
+{
+    struct bno055_calib_info bci;
+    int rc;
+
+    rc = bno055_get_calib_status(&bci);
+    if (rc) {
+        goto err;
+    }
+
+    if (bci.bci_sys< 3 || bci.bci_gyro < 3 || bci.bci_accel < 3 || bci.bci_mag < 3) {
+        goto err;
+    }
+
+    return 0;
+err:
+    return rc;
+}
+
+/**
+ * Reads the sensor's offset registers into a byte array
+ *
+ * @param byte array to return offsets into
+ * @return 0 on success, non-zero on failure
+ *
+ */
+int
+bno055_get_raw_sensor_offsets(uint8_t *offsets)
+{
+    uint8_t prev_mode;
+    int rc;
+
+    rc = SYS_EOK;
+    if (!bno055_is_calib()) {
+        rc = bno055_get_opr_mode(&prev_mode);
+        if (rc) {
+            goto err;
+        }
+
+        rc = bno055_set_opr_mode(BNO055_OPR_MODE_CONFIG);
+        if (rc) {
+            goto err;
+        }
+
+        rc = bno055_readlen(BNO055_ACCEL_OFFSET_X_LSB_ADDR, offsets,
+                            BNO055_NUM_OFFSET_REGISTERS);
+        if (rc) {
+            goto err;
+        }
+
+        rc = bno055_set_opr_mode(prev_mode);
+        if (rc) {
+            goto err;
+        }
+
+        return 0;
+    }
+err:
+    return rc;
+}
+
+/**
+ *
+ * Reads the sensor's offset registers into an offset struct
+ *
+ * @param structure to fill up offsets data
+ * @return 0 on success, non-zero on failure
+ */
+int
+bno055_get_sensor_offsets(struct bno055_sensor_offsets *offsets)
+{
+    uint8_t payload[22];
+    int rc;
+
+
+    rc = bno055_get_raw_sensor_offsets(payload);
+    if (rc) {
+        goto err;
+    }
+
+    offsets->bso_acc_off_x  = (payload[1] << 8)  | payload[0];
+    offsets->bso_acc_off_y  = (payload[3] << 8)  | payload[2];
+    offsets->bso_acc_off_z  = (payload[5] << 8)  | payload[4];
+
+    offsets->bso_gyro_off_x = (payload[7] << 8)  | payload[6];
+    offsets->bso_gyro_off_y = (payload[9] << 8)  | payload[8];
+    offsets->bso_gyro_off_z = (payload[11] << 8) | payload[10];
+
+    offsets->bso_mag_off_x  = (payload[13] << 8) | payload[12];
+    offsets->bso_mag_off_y  = (payload[15] << 8) | payload[14];
+    offsets->bso_mag_off_z  = (payload[17] << 8) | payload[16];
+
+    offsets->bso_acc_radius = (payload[19] << 8) | payload[18];
+    offsets->bso_mag_radius = (payload[21] << 8) | payload[20];
+
+    return 0;
+err:
+    return rc;
+}
+
+
+/**
+ *
+ * Writes calibration data to the sensor's offset registers
+ *
+ * @param calibration data
+ * @param calibration data length
+ * @return 0 on success, non-zero on success
+ */
+int
+bno055_set_sensor_raw_offsets(uint8_t* calibdata, uint8_t len)
+{
+    uint8_t prev_mode;
+    int rc;
+
+    if (len != 22) {
+        rc = SYS_EINVAL;
+        goto err;
+    }
+
+    rc = bno055_get_opr_mode(&prev_mode);
+    if (rc) {
+        goto err;
+    }
+
+    rc = bno055_set_opr_mode(BNO055_OPR_MODE_CONFIG);
+    if (rc) {
+        goto err;
+    }
+
+    os_time_delay((25 * OS_TICKS_PER_SEC)/1000 + 1);
+
+    rc = bno055_writelen(BNO055_ACCEL_OFFSET_X_LSB_ADDR, calibdata, len);
+    if (rc) {
+        goto err;
+    }
+
+    rc = bno055_set_opr_mode(prev_mode);
+    if (rc) {
+        goto err;
+    }
+
+    return 0;
+err:
+    return rc;
+}
+
+/**
+ *
+ * Writes to the sensor's offset registers from an offset struct
+ *
+ * @param pointer to the offset structure
+ * @return 0 on success, non-zero on failure
+ */
+int
+bno055_set_sensor_offsets(struct bno055_sensor_offsets  *offsets)
+{
+    uint8_t prev_mode;
+    int rc;
+
+    rc = bno055_get_opr_mode(&prev_mode);
+    if (rc) {
+        goto err;
+    }
+
+    rc = bno055_set_opr_mode(BNO055_OPR_MODE_CONFIG);
+    if (rc) {
+        goto err;
+    }
+
+    os_time_delay((25 * OS_TICKS_PER_SEC)/1000 + 1);
+
+    rc |= bno055_write8(BNO055_ACCEL_OFFSET_X_LSB_ADDR, (offsets->bso_acc_off_x) & 0x0FF);
+    rc |= bno055_write8(BNO055_ACCEL_OFFSET_X_MSB_ADDR, (offsets->bso_acc_off_x >> 8) & 0x0FF);
+    rc |= bno055_write8(BNO055_ACCEL_OFFSET_Y_LSB_ADDR, (offsets->bso_acc_off_y) & 0x0FF);
+    rc |= bno055_write8(BNO055_ACCEL_OFFSET_Y_MSB_ADDR, (offsets->bso_acc_off_y >> 8) & 0x0FF);
+    rc |= bno055_write8(BNO055_ACCEL_OFFSET_Z_LSB_ADDR, (offsets->bso_acc_off_z) & 0x0FF);
+    rc |= bno055_write8(BNO055_ACCEL_OFFSET_Z_MSB_ADDR, (offsets->bso_acc_off_z >> 8) & 0x0FF);
+
+    rc |= bno055_write8(BNO055_GYRO_OFFSET_X_LSB_ADDR, (offsets->bso_gyro_off_x) & 0x0FF);
+    rc |= bno055_write8(BNO055_GYRO_OFFSET_X_MSB_ADDR, (offsets->bso_gyro_off_x >> 8) & 0x0FF);
+    rc |= bno055_write8(BNO055_GYRO_OFFSET_Y_LSB_ADDR, (offsets->bso_gyro_off_y) & 0x0FF);
+    rc |= bno055_write8(BNO055_GYRO_OFFSET_Y_MSB_ADDR, (offsets->bso_gyro_off_y >> 8) & 0x0FF);
+    rc |= bno055_write8(BNO055_GYRO_OFFSET_Z_LSB_ADDR, (offsets->bso_gyro_off_z) & 0x0FF);
+    rc |= bno055_write8(BNO055_GYRO_OFFSET_Z_MSB_ADDR, (offsets->bso_gyro_off_z >> 8) & 0x0FF);
+
+    rc |= bno055_write8(BNO055_MAG_OFFSET_X_LSB_ADDR, (offsets->bso_mag_off_x) & 0x0FF);
+    rc |= bno055_write8(BNO055_MAG_OFFSET_X_MSB_ADDR, (offsets->bso_mag_off_x >> 8) & 0x0FF);
+    rc |= bno055_write8(BNO055_MAG_OFFSET_Y_LSB_ADDR, (offsets->bso_mag_off_y) & 0x0FF);
+    rc |= bno055_write8(BNO055_MAG_OFFSET_Y_MSB_ADDR, (offsets->bso_mag_off_y >> 8) & 0x0FF);
+    rc |= bno055_write8(BNO055_MAG_OFFSET_Z_LSB_ADDR, (offsets->bso_mag_off_z) & 0x0FF);
+    rc |= bno055_write8(BNO055_MAG_OFFSET_Z_MSB_ADDR, (offsets->bso_mag_off_z >> 8) & 0x0FF);
+
+    rc |= bno055_write8(BNO055_ACCEL_RADIUS_LSB_ADDR, (offsets->bso_acc_radius) & 0x0FF);
+    rc |= bno055_write8(BNO055_ACCEL_RADIUS_MSB_ADDR, (offsets->bso_acc_radius >> 8) & 0x0FF);
+
+    rc |= bno055_write8(BNO055_MAG_RADIUS_LSB_ADDR, (offsets->bso_mag_radius) & 0x0FF);
+    rc |= bno055_write8(BNO055_MAG_RADIUS_MSB_ADDR, (offsets->bso_mag_radius >> 8) & 0x0FF);
+
+    rc |= bno055_set_opr_mode(prev_mode);
+    if (rc) {
+        goto err;
+    }
+
+    return 0;
+err:
+    return rc;
+}
+
 static void *
 bno055_sensor_get_interface(struct sensor *sensor, sensor_type_t type)
 {
@@ -1064,8 +1355,8 @@ bno055_sensor_get_config(struct sensor *sensor, sensor_type_t type,
         cfg->sc_valtype = SENSOR_VALUE_TYPE_INT32;
     }
 
-    return (0);
+    return 0;
 err:
-    return (rc);
+    return rc;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/316c18ac/hw/drivers/sensors/bno055/src/bno055_priv.h
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bno055/src/bno055_priv.h b/hw/drivers/sensors/bno055/src/bno055_priv.h
index d98d3d0..b912a52 100644
--- a/hw/drivers/sensors/bno055/src/bno055_priv.h
+++ b/hw/drivers/sensors/bno055/src/bno055_priv.h
@@ -108,10 +108,10 @@
 #define BNO055_PWR_MODE_ADDR                                    0X3E
 
 #define BNO055_SYS_TRIGGER_ADDR                                 0X3F
-#define BNO055_SYS_TRIGGER_CLK_SEL                              (0x01 << 7)
-#define BNO055_SYS_TRIGGER_RST_INT                              (0x01 << 6)
-#define BNO055_SYS_TRIGGER_RST_SYS                              (0x01 << 5)
-#define BNO055_SYS_TRIGGER_SELF_TEST                            (0x01)
+#define BNO055_SYS_TRIGGER_CLK_SEL                       (0x01 << 7)
+#define BNO055_SYS_TRIGGER_RST_INT                       (0x01 << 6)
+#define BNO055_SYS_TRIGGER_RST_SYS                       (0x01 << 5)
+#define BNO055_SYS_TRIGGER_SELF_TEST                          (0x01)
 
 #define BNO055_TEMP_SOURCE_ADDR                                 0X40
 
@@ -218,4 +218,6 @@
 #define BNO055_GYRO_ANY_MOTION_THRES_ADDR                       0X1E
 #define BNO055_GYRO_ANY_MOTION_SET_ADDR                         0X1F
 
+#define BNO055_NUM_OFFSET_REGISTERS                             22
+
 #define BNO055_ID                                               0xA0

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/316c18ac/hw/drivers/sensors/bno055/src/bno055_shell.c
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bno055/src/bno055_shell.c b/hw/drivers/sensors/bno055/src/bno055_shell.c
index 5a74dfd..6404245 100644
--- a/hw/drivers/sensors/bno055/src/bno055_shell.c
+++ b/hw/drivers/sensors/bno055/src/bno055_shell.c
@@ -96,12 +96,81 @@ bno055_shell_help(void)
     console_printf("\trev\n");
     console_printf("\treset\n");
     console_printf("\tpmode [0-normal   | 1-lowpower     | 2-suspend]\n");
+    console_printf("\tsensor_offsets\n");
     console_printf("\tdumpreg [addr]\n");
 
     return 0;
 }
 
 static int
+bno055_shell_cmd_sensor_offsets(int argc, char **argv)
+{
+    int i;
+    int rc;
+    struct bno055_sensor_offsets bso;
+    long val;
+    uint16_t offsetdata[11] = {0};
+    char *tok;
+
+    rc = 0;
+    if (argc > 3) {
+        return bno055_shell_err_too_many_args(argv[1]);
+    }
+
+    /* Display the chip id */
+    if (argc == 2) {
+        rc = bno055_get_sensor_offsets(&bso);
+        if (rc) {
+            console_printf("Read failed %d\n", rc);
+            goto err;
+        }
+        console_printf("Offsets:\n");
+        console_printf("      \tacc \t |    gyro\t |    mag \t \n"
+                       "\tx  :0x%02X\t :  0x%02X\t :  0x%02X\t \n"
+                       "\ty  :0x%02X\t :  0x%02X\t :  0x%02X\t \n"
+                       "\tz  :0x%02X\t :  0x%02X\t :  0x%02X\t \n"
+                       "\trad:0x%02X\t :        \t :  0x%02X\t \n",
+                       bso.bso_acc_off_x, bso.bso_mag_off_x,
+                       bso.bso_gyro_off_x, bso.bso_acc_off_y,
+                       bso.bso_mag_off_y, bso.bso_gyro_off_y,
+                       bso.bso_acc_off_z, bso.bso_mag_off_z,
+                       bso.bso_gyro_off_z, bso.bso_acc_radius,
+                       bso.bso_mag_radius);
+    } else if (argc == 3) {
+        tok = strtok(argv[2], ":");
+        i = 0;
+        do {
+            if (bno055_shell_stol(tok, 0, UINT16_MAX, &val)) {
+                return bno055_shell_err_invalid_arg(argv[2]);
+            }
+            offsetdata[i] = val;
+            tok = strtok(0, ":");
+        } while(i++ < 11 && tok);
+
+        bso.bso_acc_off_x  = offsetdata[0];
+        bso.bso_acc_off_y  = offsetdata[1];
+        bso.bso_acc_off_z  = offsetdata[2];
+        bso.bso_gyro_off_x = offsetdata[3];
+        bso.bso_gyro_off_y = offsetdata[4];
+        bso.bso_gyro_off_z = offsetdata[5];
+        bso.bso_mag_off_x  = offsetdata[6];
+        bso.bso_mag_off_y  = offsetdata[7];
+        bso.bso_mag_off_z  = offsetdata[8];
+        bso.bso_acc_radius = offsetdata[9];
+        bso.bso_mag_radius = offsetdata[10];
+
+        rc = bno055_set_sensor_offsets(&bso);
+        if (rc) {
+            goto err;
+        }
+    }
+
+    return 0;
+err:
+    return rc;
+}
+
+static int
 bno055_shell_cmd_get_chip_id(int argc, char **argv)
 {
     uint8_t id;
@@ -490,6 +559,11 @@ bno055_shell_cmd(int argc, char **argv)
     if (argc > 1 && strcmp(argv[1], "units") == 0) {
         return bno055_shell_units_cmd(argc, argv);
     }
+
+    if (argc > 1 && strcmp(argv[1], "sensor_offsets") == 0) {
+        return bno055_shell_cmd_sensor_offsets(argc, argv);
+    }
+
     return bno055_shell_err_unknown_arg(argv[1]);
 }
 


[44/50] incubator-mynewt-core git commit: microbit bsp: fix split linker script typo

Posted by ma...@apache.org.
microbit bsp: fix split linker script typo


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/c9dabf04
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/c9dabf04
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/c9dabf04

Branch: refs/heads/master
Commit: c9dabf0471f83ee158733add94b19279f1840495
Parents: 2242bc1
Author: Jacob Rosenthal <ja...@gmail.com>
Authored: Sat Mar 4 13:59:24 2017 -0700
Committer: Jacob Rosenthal <ja...@gmail.com>
Committed: Sat Mar 4 13:59:24 2017 -0700

----------------------------------------------------------------------
 hw/bsp/bbc_microbit/bsp.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c9dabf04/hw/bsp/bbc_microbit/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/bbc_microbit/bsp.yml b/hw/bsp/bbc_microbit/bsp.yml
index c344752..7a7063c 100644
--- a/hw/bsp/bbc_microbit/bsp.yml
+++ b/hw/bsp/bbc_microbit/bsp.yml
@@ -25,7 +25,7 @@ bsp.linkerscript:
 bsp.linkerscript.BOOT_LOADER.OVERWRITE:
     - "hw/bsp/bbc_microbit/boot-nrf51xxac.ld"
     - "hw/mcu/nordic/nrf51xxx/nrf51.ld"
-bsp.part2linkerscript: "hw/bsp/bbc_microbit/split-nrf51dk.ld"
+bsp.part2linkerscript: "hw/bsp/bbc_microbit/split-microbit.ld"
 bsp.downloadscript: hw/bsp/bbc_microbit/microbit_download.sh
 bsp.debugscript: hw/bsp/bbc_microbit/microbit_debug.sh
 bsp.downloadscript.WINDOWS.OVERWRITE: hw/bsp/bbc_microbit/microbit_download.cmd


[14/50] incubator-mynewt-core git commit: nimble/l2cap: Fix L2CAP LE CoC disconnection handling

Posted by ma...@apache.org.
nimble/l2cap: Fix L2CAP LE CoC disconnection handling

This patch fixes mess around scid/dcid on L2CAP disconnection
request


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/506e3738
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/506e3738
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/506e3738

Branch: refs/heads/master
Commit: 506e3738f7cd4155b5126fa7427536b81613536f
Parents: ced3e8b
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Wed Feb 22 17:37:39 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 12:40:41 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_sig.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/506e3738/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index a1a3399..9292137 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -877,15 +877,21 @@ ble_l2cap_sig_disc_req_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
 
     req = (struct ble_l2cap_sig_disc_req *) (*om)->om_data;
 
+    /* Let's find matching channel. Note that destination CID in the request
+     * is from peer perspective. It is source CID from nimble perspective 
+     */
     chan = ble_hs_conn_chan_find(conn, le16toh(req->dcid));
-    if (!chan || (le16toh(req->scid) != chan->scid)) {
+    if (!chan || (le16toh(req->scid) != chan->dcid)) {
         os_mbuf_free_chain(txom);
         ble_hs_unlock();
         return 0;
     }
 
-    rsp->dcid = htole16(chan->dcid);
-    rsp->scid = htole16(chan->scid);
+    /* Note that in the response destination CID is form peer perspective and
+     * it is source CID from nimble perspective.
+     */
+    rsp->dcid = htole16(chan->scid);
+    rsp->scid = htole16(chan->dcid);
 
     ble_l2cap_event_coc_disconnected(chan);
 


[04/50] incubator-mynewt-core git commit: MYNEWT-647 Changes to NMP over OIC scheme

Posted by ma...@apache.org.
MYNEWT-647 Changes to NMP over OIC scheme

Update NMP handlers to account for new scheme.  Now the top-level
handler creates and closes the response root map rather than each
handler.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/38284705
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/38284705
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/38284705

Branch: refs/heads/master
Commit: 3828470558992547a6243df028af3142937cec85
Parents: 860d2d2
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Mar 1 17:48:55 2017 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Mar 2 08:15:05 2017 -0800

----------------------------------------------------------------------
 fs/fs/src/fs_nmgr.c                   |  63 +++++---------
 mgmt/imgmgr/src/imgmgr.c              |  38 +++------
 mgmt/imgmgr/src/imgmgr_coredump.c     |  70 ++++++++-------
 mgmt/imgmgr/src/imgmgr_state.c        |  41 ++++-----
 mgmt/newtmgr/nmgr_os/src/newtmgr_os.c | 132 ++++++++++++++---------------
 mgmt/newtmgr/src/newtmgr.c            |  54 ++++++++++--
 sys/config/src/config_nmgr.c          |   8 +-
 sys/log/full/src/log_nmgr.c           |  81 ++++++++----------
 sys/stats/full/src/stats_nmgr.c       |  51 +++++------
 test/crash_test/src/crash_nmgr.c      |  23 +++--
 test/runtest/src/runtest_nmgr.c       |  21 ++---
 11 files changed, 274 insertions(+), 308 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/38284705/fs/fs/src/fs_nmgr.c
----------------------------------------------------------------------
diff --git a/fs/fs/src/fs_nmgr.c b/fs/fs/src/fs_nmgr.c
index d04d768..bd87697 100644
--- a/fs/fs/src/fs_nmgr.c
+++ b/fs/fs/src/fs_nmgr.c
@@ -90,19 +90,15 @@ fs_nmgr_file_download(struct mgmt_cbuf *cb)
     uint32_t out_len;
     struct fs_file *file;
     CborError g_err = CborNoError;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp;
 
     rc = cbor_read_object(&cb->it, dload_attr);
     if (rc || off == UINT_MAX) {
-        rc = MGMT_ERR_EINVAL;
-        goto err;
+        return MGMT_ERR_EINVAL;
     }
 
     rc = fs_open(tmp_str, FS_ACCESS_READ, &file);
     if (rc || !file) {
-        rc = MGMT_ERR_ENOMEM;
-        goto err;
+        return MGMT_ERR_ENOMEM;
     }
 
     rc = fs_seek(file, off);
@@ -116,34 +112,30 @@ fs_nmgr_file_download(struct mgmt_cbuf *cb)
         goto err_close;
     }
 
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-
-    g_err |= cbor_encode_text_stringz(&rsp, "off");
-    g_err |= cbor_encode_uint(&rsp, off);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "off");
+    g_err |= cbor_encode_uint(&cb->encoder, off);
 
-    g_err |= cbor_encode_text_stringz(&rsp, "data");
-    g_err |= cbor_encode_byte_string(&rsp, img_data, out_len);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "data");
+    g_err |= cbor_encode_byte_string(&cb->encoder, img_data, out_len);
 
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
     if (off == 0) {
         rc = fs_filelen(file, &out_len);
-        g_err |= cbor_encode_text_stringz(&rsp, "len");
-        g_err |= cbor_encode_uint(&rsp, out_len);
+        g_err |= cbor_encode_text_stringz(&cb->encoder, "len");
+        g_err |= cbor_encode_uint(&cb->encoder, out_len);
     }
-    g_err |= cbor_encoder_close_container(penc, &rsp);
 
     fs_close(file);
     if (g_err) {
-          return MGMT_ERR_ENOMEM;
+        return MGMT_ERR_ENOMEM;
     }
+
     return 0;
 
 err_close:
     fs_close(file);
-err:
-    mgmt_cbuf_setoerr(cb, rc);
-    return 0;
+    return rc;
 }
 
 static int
@@ -183,14 +175,11 @@ fs_nmgr_file_upload(struct mgmt_cbuf *cb)
         [4] = { 0 },
     };
     CborError g_err = CborNoError;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp;
     int rc;
 
     rc = cbor_read_object(&cb->it, off_attr);
     if (rc || off == UINT_MAX) {
-        rc = MGMT_ERR_EINVAL;
-        goto err;
+        return MGMT_ERR_EINVAL;
     }
 
     if (off == 0) {
@@ -201,8 +190,7 @@ fs_nmgr_file_upload(struct mgmt_cbuf *cb)
         fs_nmgr_state.upload.size = size;
 
         if (!strlen(file_name)) {
-            rc = MGMT_ERR_EINVAL;
-            goto err;
+            return MGMT_ERR_EINVAL;
         }
         if (fs_nmgr_state.upload.file) {
             fs_close(fs_nmgr_state.upload.file);
@@ -211,8 +199,7 @@ fs_nmgr_file_upload(struct mgmt_cbuf *cb)
         rc = fs_open(file_name, FS_ACCESS_WRITE | FS_ACCESS_TRUNCATE,
           &fs_nmgr_state.upload.file);
         if (rc) {
-            rc = MGMT_ERR_EINVAL;
-            goto err;
+            return MGMT_ERR_EINVAL;
         }
     } else if (off != fs_nmgr_state.upload.off) {
         /*
@@ -223,8 +210,7 @@ fs_nmgr_file_upload(struct mgmt_cbuf *cb)
     }
 
     if (!fs_nmgr_state.upload.file) {
-        rc = MGMT_ERR_EINVAL;
-        goto err;
+        return MGMT_ERR_EINVAL;
     }
     if (img_len) {
         rc = fs_write(fs_nmgr_state.upload.file, img_data, img_len);
@@ -239,13 +225,12 @@ fs_nmgr_file_upload(struct mgmt_cbuf *cb)
             fs_nmgr_state.upload.file = NULL;
         }
     }
+
 out:
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
-    g_err |= cbor_encode_text_stringz(&rsp, "off");
-    g_err |= cbor_encode_uint(&rsp, fs_nmgr_state.upload.off);
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "off");
+    g_err |= cbor_encode_uint(&cb->encoder, fs_nmgr_state.upload.off);
     if (g_err) {
         return MGMT_ERR_ENOMEM;
     }
@@ -254,9 +239,7 @@ out:
 err_close:
     fs_close(fs_nmgr_state.upload.file);
     fs_nmgr_state.upload.file = NULL;
-err:
-    mgmt_cbuf_setoerr(cb, rc);
-    return 0;
+    return rc;
 }
 
 int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/38284705/mgmt/imgmgr/src/imgmgr.c
----------------------------------------------------------------------
diff --git a/mgmt/imgmgr/src/imgmgr.c b/mgmt/imgmgr/src/imgmgr.c
index 32744e2..7b4431e 100644
--- a/mgmt/imgmgr/src/imgmgr.c
+++ b/mgmt/imgmgr/src/imgmgr.c
@@ -257,14 +257,11 @@ imgr_upload(struct mgmt_cbuf *cb)
     int best;
     int rc;
     int i;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp;
     CborError g_err = CborNoError;
 
     rc = cbor_read_object(&cb->it, off_attr);
     if (rc || off == UINT_MAX) {
-        rc = MGMT_ERR_EINVAL;
-        goto err;
+        return MGMT_ERR_EINVAL;
     }
 
     if (off == 0) {
@@ -272,13 +269,11 @@ imgr_upload(struct mgmt_cbuf *cb)
             /*
              * Image header is the first thing in the image.
              */
-            rc = MGMT_ERR_EINVAL;
-            goto err;
+            return MGMT_ERR_EINVAL;
         }
         hdr = (struct image_header *)img_data;
         if (hdr->ih_magic != IMAGE_MAGIC) {
-            rc = MGMT_ERR_EINVAL;
-            goto err;
+            return MGMT_ERR_EINVAL;
         }
 
         /*
@@ -318,12 +313,10 @@ imgr_upload(struct mgmt_cbuf *cb)
             }
             rc = flash_area_open(area_id, &imgr_state.upload.fa);
             if (rc) {
-                rc = MGMT_ERR_EINVAL;
-                goto err;
+                return MGMT_ERR_EINVAL;
             }
             if (IMAGE_SIZE(hdr) > imgr_state.upload.fa->fa_size) {
-                rc = MGMT_ERR_EINVAL;
-                goto err;
+                return MGMT_ERR_EINVAL;
             }
             /*
              * XXX only erase if needed.
@@ -334,8 +327,7 @@ imgr_upload(struct mgmt_cbuf *cb)
             /*
              * No slot where to upload!
              */
-            rc = MGMT_ERR_ENOMEM;
-            goto err;
+            return MGMT_ERR_ENOMEM;
         }
     } else if (off != imgr_state.upload.off) {
         /*
@@ -346,8 +338,7 @@ imgr_upload(struct mgmt_cbuf *cb)
     }
 
     if (!imgr_state.upload.fa) {
-        rc = MGMT_ERR_EINVAL;
-        goto err;
+        return MGMT_ERR_EINVAL;
     }
     if (data_len) {
         rc = flash_area_write(imgr_state.upload.fa, imgr_state.upload.off,
@@ -363,13 +354,12 @@ imgr_upload(struct mgmt_cbuf *cb)
             imgr_state.upload.fa = NULL;
         }
     }
+
 out:
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
-    g_err |= cbor_encode_text_stringz(&rsp, "off");
-    g_err |= cbor_encode_int(&rsp, imgr_state.upload.off);
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "off");
+    g_err |= cbor_encode_int(&cb->encoder, imgr_state.upload.off);
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;
@@ -378,9 +368,7 @@ out:
 err_close:
     flash_area_close(imgr_state.upload.fa);
     imgr_state.upload.fa = NULL;
-err:
-    mgmt_cbuf_setoerr(cb, rc);
-    return 0;
+    return rc;
 }
 
 void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/38284705/mgmt/imgmgr/src/imgmgr_coredump.c
----------------------------------------------------------------------
diff --git a/mgmt/imgmgr/src/imgmgr_coredump.c b/mgmt/imgmgr/src/imgmgr_coredump.c
index df3e321..48058c9 100644
--- a/mgmt/imgmgr/src/imgmgr_coredump.c
+++ b/mgmt/imgmgr/src/imgmgr_coredump.c
@@ -40,20 +40,24 @@ imgr_core_list(struct mgmt_cbuf *cb)
     int rc;
 
     rc = flash_area_open(MYNEWT_VAL(COREDUMP_FLASH_AREA), &fa);
-    if (rc) {
-        rc = MGMT_ERR_EINVAL;
-    } else {
-        rc = flash_area_read(fa, 0, &hdr, sizeof(hdr));
-        if (rc != 0) {
-            rc = MGMT_ERR_EINVAL;
-        } else if (hdr.ch_magic != COREDUMP_MAGIC) {
-            rc = MGMT_ERR_ENOENT;
-        } else {
-            rc = 0;
-        }
+    if (rc != 0) {
+        return MGMT_ERR_EUNKNOWN;
+    }
+
+    rc = flash_area_read(fa, 0, &hdr, sizeof(hdr));
+    if (rc != 0) {
+        return MGMT_ERR_EINVAL;
+    }
+
+    if (hdr.ch_magic != COREDUMP_MAGIC) {
+        return MGMT_ERR_ENOENT;
+    }
+
+    rc = mgmt_cbuf_setoerr(cb, 0);
+    if (rc != 0) {
+        return rc;
     }
 
-    mgmt_cbuf_setoerr(cb, rc);
     return 0;
 }
 
@@ -75,21 +79,17 @@ imgr_core_load(struct mgmt_cbuf *cb)
     uint8_t data[IMGMGR_NMGR_MAX_MSG];
     struct coredump_header *hdr;
     CborError g_err = CborNoError;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp;
 
     hdr = (struct coredump_header *)data;
 
     rc = cbor_read_object(&cb->it, dload_attr);
     if (rc || off == UINT_MAX) {
-        rc = MGMT_ERR_EINVAL;
-        goto err;
+        return MGMT_ERR_EINVAL;
     }
 
     rc = flash_area_open(MYNEWT_VAL(COREDUMP_FLASH_AREA), &fa);
     if (rc) {
-        rc = MGMT_ERR_EINVAL;
-        goto err;
+        return MGMT_ERR_EINVAL;
     }
 
     rc = flash_area_read(fa, 0, hdr, sizeof(*hdr));
@@ -115,14 +115,12 @@ imgr_core_load(struct mgmt_cbuf *cb)
         goto err_close;
     }
 
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
-    g_err |= cbor_encode_text_stringz(&rsp, "off");
-    g_err |= cbor_encode_int(&rsp, off);
-    g_err |= cbor_encode_text_stringz(&rsp, "data");
-    g_err |= cbor_encode_byte_string(&rsp, data, sz);
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "off");
+    g_err |= cbor_encode_int(&cb->encoder, off);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "data");
+    g_err |= cbor_encode_byte_string(&cb->encoder, data, sz);
 
     flash_area_close(fa);
     if (g_err) {
@@ -132,8 +130,6 @@ imgr_core_load(struct mgmt_cbuf *cb)
 
 err_close:
     flash_area_close(fa);
-err:
-    mgmt_cbuf_setoerr(cb, rc);
     return rc;
 }
 
@@ -148,24 +144,26 @@ imgr_core_erase(struct mgmt_cbuf *cb)
     int rc;
 
     rc = flash_area_open(MYNEWT_VAL(COREDUMP_FLASH_AREA), &fa);
-    if (rc) {
-        rc = MGMT_ERR_EINVAL;
-        goto err;
+    if (rc != 0) {
+        return MGMT_ERR_EINVAL;
     }
 
     rc = flash_area_read(fa, 0, &hdr, sizeof(hdr));
     if (rc == 0 &&
       (hdr.ch_magic == COREDUMP_MAGIC || hdr.ch_magic == 0xffffffff)) {
         rc = flash_area_erase(fa, 0, fa->fa_size);
-        if (rc) {
-            rc = MGMT_ERR_EINVAL;
+        if (rc != 0) {
+            return MGMT_ERR_EINVAL;
         }
     }
-    rc = 0;
 
     flash_area_close(fa);
-err:
-    mgmt_cbuf_setoerr(cb, rc);
+
+    rc = mgmt_cbuf_setoerr(cb, rc);
+    if (rc != 0) {
+        return rc;
+    }
+
     return 0;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/38284705/mgmt/imgmgr/src/imgmgr_state.c
----------------------------------------------------------------------
diff --git a/mgmt/imgmgr/src/imgmgr_state.c b/mgmt/imgmgr/src/imgmgr_state.c
index ee7d76c..610b57f 100644
--- a/mgmt/imgmgr/src/imgmgr_state.c
+++ b/mgmt/imgmgr/src/imgmgr_state.c
@@ -240,15 +240,15 @@ imgmgr_state_read(struct mgmt_cbuf *cb)
     int split_status;
     uint8_t state_flags;
     CborError g_err = CborNoError;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp, images, image;
+    CborEncoder images;
+    CborEncoder image;
 
     any_non_bootable = 0;
 
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "images");
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "images");
 
-    g_err |= cbor_encoder_create_array(&rsp, &images, CborIndefiniteLength);
+    g_err |= cbor_encoder_create_array(&cb->encoder, &images,
+                                       CborIndefiniteLength);
     for (i = 0; i < 2; i++) {
         rc = imgr_read_info(i, &ver, hash, &flags);
         if (rc != 0) {
@@ -261,7 +261,8 @@ imgmgr_state_read(struct mgmt_cbuf *cb)
 
         state_flags = imgmgr_state_flags(i);
 
-        g_err |= cbor_encoder_create_map(&images, &image, CborIndefiniteLength);
+        g_err |= cbor_encoder_create_map(&images, &image,
+                                         CborIndefiniteLength);
         g_err |= cbor_encode_text_stringz(&image, "slot");
         g_err |= cbor_encode_int(&image, i);
 
@@ -294,7 +295,7 @@ imgmgr_state_read(struct mgmt_cbuf *cb)
         g_err |= cbor_encoder_close_container(&images, &image);
     }
 
-    g_err |= cbor_encoder_close_container(&rsp, &images);
+    g_err |= cbor_encoder_close_container(&cb->encoder, &images);
 
     if (any_non_bootable) {
         split_status = split_check_status();
@@ -302,10 +303,8 @@ imgmgr_state_read(struct mgmt_cbuf *cb)
         split_status = SPLIT_STATUS_INVALID;
     }
 
-    g_err |= cbor_encode_text_stringz(&rsp, "splitStatus");
-    g_err |= cbor_encode_int(&rsp, split_status);
-
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "splitStatus");
+    g_err |= cbor_encode_int(&cb->encoder, split_status);
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;
@@ -341,45 +340,37 @@ imgmgr_state_write(struct mgmt_cbuf *cb)
 
     rc = cbor_read_object(&cb->it, write_attr);
     if (rc != 0) {
-        rc = MGMT_ERR_EINVAL;
-        goto err;
+        return MGMT_ERR_EINVAL;
     }
 
     /* Validate arguments. */
     if ((hash_len == 0) && !confirm) {
-        rc = MGMT_ERR_EINVAL;
-        goto err;
+        return MGMT_ERR_EINVAL;
     }
 
     if (hash_len != 0) {
         slot = imgr_find_by_hash(hash, NULL);
         if (slot < 0) {
-            rc = MGMT_ERR_EINVAL;
-            goto err;
+            return MGMT_ERR_EINVAL;
         }
 
         rc = imgmgr_state_set_pending(slot, confirm);
         if (rc != 0) {
-            goto err;
+            return rc;
         }
     } else {
         /* Confirm current setup. */
         rc = imgmgr_state_confirm();
         if (rc != 0) {
-            goto err;
+            return rc;
         }
     }
 
     /* Send the current image state in the response. */
     rc = imgmgr_state_read(cb);
     if (rc != 0) {
-        goto err;
+        return rc;
     }
 
     return 0;
-
-err:
-    mgmt_cbuf_setoerr(cb, rc);
-
-    return 0;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/38284705/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c b/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
index c3e38d6..2a75d47 100644
--- a/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
+++ b/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
@@ -84,9 +84,8 @@ static int
 nmgr_def_echo(struct mgmt_cbuf *cb)
 {
     char echo_buf[128] = {'\0'};
-    CborEncoder *penc = &cb->encoder;
     CborError g_err = CborNoError;
-    CborEncoder rsp;
+
     struct cbor_attr_t attrs[2] = {
         [0] = {
             .attribute = "d",
@@ -100,11 +99,9 @@ nmgr_def_echo(struct mgmt_cbuf *cb)
         }
     };
 
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "r");
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "r");
     g_err |= cbor_read_object(&cb->it, attrs);
-    g_err |= cbor_encode_text_string(&rsp, echo_buf, strlen(echo_buf));
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    g_err |= cbor_encode_text_string(&cb->encoder, echo_buf, strlen(echo_buf));
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;
@@ -145,19 +142,18 @@ nmgr_def_taskstat_read(struct mgmt_cbuf *cb)
 {
     struct os_task *prev_task;
     struct os_task_info oti;
-
     CborError g_err = CborNoError;
-    CborEncoder rsp, tasks, task;
+    CborEncoder tasks;
+    CborEncoder task;
 
-    g_err |= cbor_encoder_create_map(&cb->encoder, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
-    g_err |= cbor_encode_text_stringz(&rsp, "tasks");
-    g_err |= cbor_encoder_create_map(&rsp, &tasks, CborIndefiniteLength);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "tasks");
+    g_err |= cbor_encoder_create_map(&cb->encoder, &tasks,
+                                     CborIndefiniteLength);
 
     prev_task = NULL;
     while (1) {
-
         prev_task = os_task_info_get_next(prev_task, &oti);
         if (prev_task == NULL) {
             break;
@@ -165,28 +161,27 @@ nmgr_def_taskstat_read(struct mgmt_cbuf *cb)
 
         g_err |= cbor_encode_text_stringz(&tasks, oti.oti_name);
         g_err |= cbor_encoder_create_map(&tasks, &task, CborIndefiniteLength);
-        g_err |= cbor_encode_text_stringz(&rsp, "prio");
-        g_err |= cbor_encode_uint(&rsp, oti.oti_prio);
-        g_err |= cbor_encode_text_stringz(&rsp, "tid");
-        g_err |= cbor_encode_uint(&rsp, oti.oti_taskid);
-        g_err |= cbor_encode_text_stringz(&rsp, "state");
-        g_err |= cbor_encode_uint(&rsp, oti.oti_state);
-        g_err |= cbor_encode_text_stringz(&rsp, "stkuse");
-        g_err |= cbor_encode_uint(&rsp, oti.oti_stkusage);
-        g_err |= cbor_encode_text_stringz(&rsp, "stksiz");
-        g_err |= cbor_encode_uint(&rsp, oti.oti_stksize);
-        g_err |= cbor_encode_text_stringz(&rsp, "cswcnt");
-        g_err |= cbor_encode_uint(&rsp, oti.oti_cswcnt);
-        g_err |= cbor_encode_text_stringz(&rsp, "runtime");
-        g_err |= cbor_encode_uint(&rsp, oti.oti_runtime);
-        g_err |= cbor_encode_text_stringz(&rsp, "last_checkin");
-        g_err |= cbor_encode_uint(&rsp, oti.oti_last_checkin);
-        g_err |= cbor_encode_text_stringz(&rsp, "next_checkin");
-        g_err |= cbor_encode_uint(&rsp, oti.oti_next_checkin);
+        g_err |= cbor_encode_text_stringz(&task, "prio");
+        g_err |= cbor_encode_uint(&task, oti.oti_prio);
+        g_err |= cbor_encode_text_stringz(&task, "tid");
+        g_err |= cbor_encode_uint(&task, oti.oti_taskid);
+        g_err |= cbor_encode_text_stringz(&task, "state");
+        g_err |= cbor_encode_uint(&task, oti.oti_state);
+        g_err |= cbor_encode_text_stringz(&task, "stkuse");
+        g_err |= cbor_encode_uint(&task, oti.oti_stkusage);
+        g_err |= cbor_encode_text_stringz(&task, "stksiz");
+        g_err |= cbor_encode_uint(&task, oti.oti_stksize);
+        g_err |= cbor_encode_text_stringz(&task, "cswcnt");
+        g_err |= cbor_encode_uint(&task, oti.oti_cswcnt);
+        g_err |= cbor_encode_text_stringz(&task, "runtime");
+        g_err |= cbor_encode_uint(&task, oti.oti_runtime);
+        g_err |= cbor_encode_text_stringz(&task, "last_checkin");
+        g_err |= cbor_encode_uint(&task, oti.oti_last_checkin);
+        g_err |= cbor_encode_text_stringz(&task, "next_checkin");
+        g_err |= cbor_encode_uint(&task, oti.oti_next_checkin);
         g_err |= cbor_encoder_close_container(&tasks, &task);
     }
-    g_err |= cbor_encoder_close_container(&rsp, &tasks);
-    g_err |= cbor_encoder_close_container(&cb->encoder, &rsp);
+    g_err |= cbor_encoder_close_container(&cb->encoder, &tasks);
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;
@@ -200,13 +195,14 @@ nmgr_def_mpstat_read(struct mgmt_cbuf *cb)
     struct os_mempool *prev_mp;
     struct os_mempool_info omi;
     CborError g_err = CborNoError;
-    CborEncoder rsp, pools, pool;
+    CborEncoder pools;
+    CborEncoder pool;
 
-    g_err |= cbor_encoder_create_map(&cb->encoder, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
-    g_err |= cbor_encode_text_stringz(&rsp, "mpools");
-    g_err |= cbor_encoder_create_map(&rsp, &pools, CborIndefiniteLength);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "mpools");
+    g_err |= cbor_encoder_create_map(&cb->encoder, &pools,
+                                     CborIndefiniteLength);
 
     prev_mp = NULL;
     while (1) {
@@ -217,19 +213,18 @@ nmgr_def_mpstat_read(struct mgmt_cbuf *cb)
 
         g_err |= cbor_encode_text_stringz(&pools, omi.omi_name);
         g_err |= cbor_encoder_create_map(&pools, &pool, CborIndefiniteLength);
-        g_err |= cbor_encode_text_stringz(&rsp, "blksiz");
-        g_err |= cbor_encode_uint(&rsp, omi.omi_block_size);
-        g_err |= cbor_encode_text_stringz(&rsp, "nblks");
-        g_err |= cbor_encode_uint(&rsp, omi.omi_num_blocks);
-        g_err |= cbor_encode_text_stringz(&rsp, "nfree");
-        g_err |= cbor_encode_uint(&rsp, omi.omi_num_free);
-        g_err |= cbor_encode_text_stringz(&rsp, "min");
-        g_err |= cbor_encode_uint(&rsp, omi.omi_min_free);
+        g_err |= cbor_encode_text_stringz(&pool, "blksiz");
+        g_err |= cbor_encode_uint(&pool, omi.omi_block_size);
+        g_err |= cbor_encode_text_stringz(&pool, "nblks");
+        g_err |= cbor_encode_uint(&pool, omi.omi_num_blocks);
+        g_err |= cbor_encode_text_stringz(&pool, "nfree");
+        g_err |= cbor_encode_uint(&pool, omi.omi_num_free);
+        g_err |= cbor_encode_text_stringz(&pool, "min");
+        g_err |= cbor_encode_uint(&pool, omi.omi_min_free);
         g_err |= cbor_encoder_close_container(&pools, &pool);
     }
 
-    g_err |= cbor_encoder_close_container(&rsp, &pools);
-    g_err |= cbor_encoder_close_container(&cb->encoder, &rsp);
+    g_err |= cbor_encoder_close_container(&cb->encoder, &pools);
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;
@@ -245,11 +240,9 @@ nmgr_datetime_get(struct mgmt_cbuf *cb)
     char buf[DATETIME_BUFSIZE];
     int rc;
     CborError g_err = CborNoError;
-    CborEncoder rsp;
 
-    g_err |= cbor_encoder_create_map(&cb->encoder, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
 
     /* Display the current datetime */
     rc = os_gettimeofday(&tv, &tz);
@@ -259,9 +252,8 @@ nmgr_datetime_get(struct mgmt_cbuf *cb)
         rc = MGMT_ERR_EINVAL;
         goto err;
     }
-    g_err |= cbor_encode_text_stringz(&rsp, "datetime");
-    g_err |= cbor_encode_text_stringz(&rsp, buf);
-    g_err |= cbor_encoder_close_container(&cb->encoder, &rsp);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "datetime");
+    g_err |= cbor_encode_text_stringz(&cb->encoder, buf);
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;
@@ -295,8 +287,7 @@ nmgr_datetime_set(struct mgmt_cbuf *cb)
 
     rc = cbor_read_object(&cb->it, datetime_write_attr);
     if (rc) {
-        rc = MGMT_ERR_EINVAL;
-        goto out;
+        return MGMT_ERR_EINVAL;
     }
 
     /* Set the current datetime */
@@ -304,18 +295,18 @@ nmgr_datetime_set(struct mgmt_cbuf *cb)
     if (!rc) {
         rc = os_settimeofday(&tv, &tz);
         if (rc) {
-          rc = MGMT_ERR_EINVAL;
-          goto out;
+          return MGMT_ERR_EINVAL;
         }
     } else {
-        rc = MGMT_ERR_EINVAL;
-        goto out;
+        return MGMT_ERR_EINVAL;
     }
 
-    rc = 0;
-out:
-    mgmt_cbuf_setoerr(cb, rc);
-    return rc;
+    rc = mgmt_cbuf_setoerr(cb, 0);
+    if (rc != 0) {
+        return rc;
+    }
+
+    return 0;
 }
 
 static void
@@ -327,6 +318,8 @@ nmgr_reset_tmo(struct os_event *ev)
 static int
 nmgr_reset(struct mgmt_cbuf *cb)
 {
+    int rc;
+
     os_callout_init(&nmgr_reset_callout, mgmt_evq_get(), nmgr_reset_tmo, NULL);
 
 #if MYNEWT_VAL(LOG_SOFT_RESET)
@@ -334,7 +327,10 @@ nmgr_reset(struct mgmt_cbuf *cb)
 #endif
     os_callout_reset(&nmgr_reset_callout, OS_TICKS_PER_SEC / 4);
 
-    mgmt_cbuf_setoerr(cb, OS_OK);
+    rc = mgmt_cbuf_setoerr(cb, 0);
+    if (rc != 0) {
+        return rc;
+    }
 
     return 0;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/38284705/mgmt/newtmgr/src/newtmgr.c
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/src/newtmgr.c b/mgmt/newtmgr/src/newtmgr.c
index 5d37021..043cef6 100644
--- a/mgmt/newtmgr/src/newtmgr.c
+++ b/mgmt/newtmgr/src/newtmgr.c
@@ -95,20 +95,36 @@ nmgr_init_rsp(struct os_mbuf *m, struct nmgr_hdr *src)
 
 static void
 nmgr_send_err_rsp(struct nmgr_transport *nt, struct os_mbuf *m,
-  struct nmgr_hdr *hdr, int rc)
+                  struct nmgr_hdr *hdr, int status)
 {
+    struct CborEncoder map;
+    int rc;
+
     hdr = nmgr_init_rsp(m, hdr);
     if (!hdr) {
         os_mbuf_free_chain(m);
         return;
     }
 
-    mgmt_cbuf_setoerr(&nmgr_task_cbuf.n_b, rc);
-    hdr->nh_len +=
-        cbor_encode_bytes_written(&nmgr_task_cbuf.n_b.encoder);
+    rc = cbor_encoder_create_map(&nmgr_task_cbuf.n_b.encoder, &map,
+                                 CborIndefiniteLength);
+    if (rc != 0) {
+        return;
+    }
+
+    rc = mgmt_cbuf_setoerr(&nmgr_task_cbuf.n_b, status);
+    if (rc != 0) {
+        return;
+    }
+
+    rc = cbor_encoder_close_container(&nmgr_task_cbuf.n_b.encoder, &map);
+    if (rc != 0) {
+        return;
+    }
+
+    hdr->nh_len =
+        htons(cbor_encode_bytes_written(&nmgr_task_cbuf.n_b.encoder));
 
-    hdr->nh_len = htons(hdr->nh_len);
-    hdr->nh_flags = 0;
     nt->nt_output(nt, nmgr_task_cbuf.n_out_m);
 }
 
@@ -172,6 +188,7 @@ nmgr_handle_req(struct nmgr_transport *nt, struct os_mbuf *req)
 {
     struct os_mbuf *rsp;
     const struct mgmt_handler *handler;
+    CborEncoder payload_enc;
     struct nmgr_hdr *rsp_hdr;
     struct nmgr_hdr hdr;
     int off;
@@ -194,7 +211,7 @@ nmgr_handle_req(struct nmgr_transport *nt, struct os_mbuf *req)
 
     mtu = nt->nt_get_mtu(req);
 
-    /* Copy the request packet header into the response. */
+    /* Copy the request user header into the response. */
     memcpy(OS_MBUF_USRHDR(rsp), OS_MBUF_USRHDR(req), OS_MBUF_USRHDR_LEN(req));
 
     off = 0;
@@ -228,6 +245,16 @@ nmgr_handle_req(struct nmgr_transport *nt, struct os_mbuf *req)
         cbor_parser_init(&nmgr_task_cbuf.reader.r, 0,
                          &nmgr_task_cbuf.n_b.parser, &nmgr_task_cbuf.n_b.it);
 
+        /* Begin response payload.  Response fields are inserted into the root
+         * map as key value pairs.
+         */
+        rc = cbor_encoder_create_map(&nmgr_task_cbuf.n_b.encoder, &payload_enc,
+                                     CborIndefiniteLength);
+        if (rc != 0) {
+            rc = MGMT_ERR_ENOMEM;
+            goto err;
+        }
+
         if (hdr.nh_op == NMGR_OP_READ) {
             if (handler->mh_read) {
                 rc = handler->mh_read(&nmgr_task_cbuf.n_b);
@@ -243,8 +270,15 @@ nmgr_handle_req(struct nmgr_transport *nt, struct os_mbuf *req)
         } else {
             rc = MGMT_ERR_EINVAL;
         }
+        if (rc != 0) {
+            goto err;
+        }
 
+        /* End response payload. */
+        rc = cbor_encoder_close_container(&nmgr_task_cbuf.n_b.encoder,
+                                          &payload_enc);
         if (rc != 0) {
+            rc = MGMT_ERR_ENOMEM;
             goto err;
         }
 
@@ -270,11 +304,15 @@ nmgr_handle_req(struct nmgr_transport *nt, struct os_mbuf *req)
     os_mbuf_free_chain(rsp);
     os_mbuf_free_chain(req);
     return;
+
 err:
-    OS_MBUF_PKTHDR(rsp)->omp_len = rsp->om_len = 0;
+    /* Clear partially written response. */
+    os_mbuf_adj(rsp, OS_MBUF_PKTLEN(rsp));
+
     nmgr_send_err_rsp(nt, rsp, &hdr, rc);
     os_mbuf_free_chain(req);
     return;
+
 err_norsp:
     os_mbuf_free_chain(rsp);
     os_mbuf_free_chain(req);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/38284705/sys/config/src/config_nmgr.c
----------------------------------------------------------------------
diff --git a/sys/config/src/config_nmgr.c b/sys/config/src/config_nmgr.c
index 24c7080..0b42bc6 100644
--- a/sys/config/src/config_nmgr.c
+++ b/sys/config/src/config_nmgr.c
@@ -49,7 +49,6 @@ conf_nmgr_read(struct mgmt_cbuf *cb)
     char val_str[CONF_MAX_VAL_LEN];
     char *val;
     CborError g_err = CborNoError;
-    CborEncoder rsp;
 
     const struct cbor_attr_t attr[2] = {
         [0] = {
@@ -73,10 +72,9 @@ conf_nmgr_read(struct mgmt_cbuf *cb)
         return MGMT_ERR_EINVAL;
     }
 
-    g_err |= cbor_encoder_create_map(&cb->encoder, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "val");
-    g_err |= cbor_encode_text_stringz(&rsp, val);
-    g_err |= cbor_encoder_close_container(&cb->encoder, &rsp);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "val");
+    g_err |= cbor_encode_text_stringz(&cb->encoder, val);
+
     if (g_err) {
         return MGMT_ERR_ENOMEM;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/38284705/sys/log/full/src/log_nmgr.c
----------------------------------------------------------------------
diff --git a/sys/log/full/src/log_nmgr.c b/sys/log/full/src/log_nmgr.c
index 6d51cb6..00beeba 100644
--- a/sys/log/full/src/log_nmgr.c
+++ b/sys/log/full/src/log_nmgr.c
@@ -250,8 +250,7 @@ log_nmgr_read(struct mgmt_cbuf *cb)
     int64_t ts;
     uint64_t index;
     CborError g_err = CborNoError;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp, logs;
+    CborEncoder logs;
 
     const struct cbor_attr_t attr[4] = {
         [0] = {
@@ -281,10 +280,9 @@ log_nmgr_read(struct mgmt_cbuf *cb)
     }
 
 
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "logs");
-
-    g_err |= cbor_encoder_create_array(&rsp, &logs, CborIndefiniteLength);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "logs");
+    g_err |= cbor_encoder_create_array(&cb->encoder, &logs,
+                                       CborIndefiniteLength);
 
     name_len = strlen(name);
     log = NULL;
@@ -321,10 +319,9 @@ log_nmgr_read(struct mgmt_cbuf *cb)
     }
 
 err:
-    g_err |= cbor_encoder_close_container(&rsp, &logs);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, rc);
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    g_err |= cbor_encoder_close_container(&cb->encoder, &logs);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, rc);
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;
@@ -344,15 +341,14 @@ log_nmgr_module_list(struct mgmt_cbuf *cb)
     int module;
     char *str;
     CborError g_err = CborNoError;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp, modules;
+    CborEncoder modules;
 
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
 
-    g_err |= cbor_encode_text_stringz(&rsp, "module_map");
-    g_err |= cbor_encoder_create_map(&rsp, &modules, CborIndefiniteLength);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "module_map");
+    g_err |= cbor_encoder_create_map(&cb->encoder, &modules,
+                                     CborIndefiniteLength);
 
     module = LOG_MODULE_DEFAULT;
     while (module < LOG_MODULE_MAX) {
@@ -367,8 +363,7 @@ log_nmgr_module_list(struct mgmt_cbuf *cb)
         module++;
     }
 
-    g_err |= cbor_encoder_close_container(&rsp, &modules);
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    g_err |= cbor_encoder_close_container(&cb->encoder, &modules);
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;
@@ -385,16 +380,15 @@ static int
 log_nmgr_logs_list(struct mgmt_cbuf *cb)
 {
     CborError g_err = CborNoError;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp, log_list;
+    CborEncoder log_list;
     struct log *log;
 
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
 
-    g_err |= cbor_encode_text_stringz(&rsp, "log_list");
-    g_err |= cbor_encoder_create_array(&rsp, &log_list, CborIndefiniteLength);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "log_list");
+    g_err |= cbor_encoder_create_array(&cb->encoder, &log_list,
+                                       CborIndefiniteLength);
 
     log = NULL;
     while (1) {
@@ -410,8 +404,7 @@ log_nmgr_logs_list(struct mgmt_cbuf *cb)
         g_err |= cbor_encode_text_stringz(&log_list, log->l_name);
     }
 
-    g_err |= cbor_encoder_close_container(&rsp, &log_list);
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    g_err |= cbor_encoder_close_container(&cb->encoder, &log_list);
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;
@@ -428,17 +421,16 @@ static int
 log_nmgr_level_list(struct mgmt_cbuf *cb)
 {
     CborError g_err = CborNoError;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp, level_map;
+    CborEncoder level_map;
     int level;
     char *str;
 
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
 
-    g_err |= cbor_encode_text_stringz(&rsp, "level_map");
-    g_err |= cbor_encoder_create_map(&rsp, &level_map, CborIndefiniteLength);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "level_map");
+    g_err |= cbor_encoder_create_map(&cb->encoder, &level_map,
+                                     CborIndefiniteLength);
 
     level = LOG_LEVEL_DEBUG;
     while (level < LOG_LEVEL_MAX) {
@@ -453,8 +445,7 @@ log_nmgr_level_list(struct mgmt_cbuf *cb)
         level++;
     }
 
-    g_err |= cbor_encoder_close_container(&rsp, &level_map);
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    g_err |= cbor_encoder_close_container(&cb->encoder, &level_map);
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;
@@ -470,9 +461,6 @@ log_nmgr_level_list(struct mgmt_cbuf *cb)
 static int
 log_nmgr_clear(struct mgmt_cbuf *cb)
 {
-    CborError g_err = CborNoError;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp;
     struct log *log;
     int rc;
 
@@ -489,19 +477,16 @@ log_nmgr_clear(struct mgmt_cbuf *cb)
 
         rc = log_flush(log);
         if (rc) {
-            goto err;
+            return rc;
         }
     }
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encoder_close_container(penc, &rsp);
 
-    if (g_err) {
-        return MGMT_ERR_ENOMEM;
+    rc = mgmt_cbuf_setoerr(cb, 0);
+    if (rc != 0) {
+        return rc;
     }
+
     return 0;
-err:
-    mgmt_cbuf_setoerr(cb, rc);
-    return (rc);
 }
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/38284705/sys/stats/full/src/stats_nmgr.c
----------------------------------------------------------------------
diff --git a/sys/stats/full/src/stats_nmgr.c b/sys/stats/full/src/stats_nmgr.c
index 5df6e7c..0b28b25 100644
--- a/sys/stats/full/src/stats_nmgr.c
+++ b/sys/stats/full/src/stats_nmgr.c
@@ -95,46 +95,39 @@ stats_nmgr_read(struct mgmt_cbuf *cb)
         { NULL },
     };
     CborError g_err = CborNoError;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp, stats;
+    CborEncoder stats;
 
     g_err = cbor_read_object(&cb->it, attrs);
     if (g_err != 0) {
-        g_err = MGMT_ERR_EINVAL;
-        goto err;
+        return MGMT_ERR_EINVAL;
     }
 
     hdr = stats_group_find(stats_name);
     if (!hdr) {
-        g_err = MGMT_ERR_EINVAL;
-        goto err;
+        return MGMT_ERR_EINVAL;
     }
 
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
 
-    g_err |= cbor_encode_text_stringz(&rsp, "name");
-    g_err |= cbor_encode_text_stringz(&rsp, stats_name);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "name");
+    g_err |= cbor_encode_text_stringz(&cb->encoder, stats_name);
 
-    g_err |= cbor_encode_text_stringz(&rsp, "group");
-    g_err |= cbor_encode_text_string(&rsp, "sys", sizeof("sys")-1);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "group");
+    g_err |= cbor_encode_text_string(&cb->encoder, "sys", sizeof("sys")-1);
 
-    g_err |= cbor_encode_text_stringz(&rsp, "fields");
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "fields");
 
-    g_err |= cbor_encoder_create_map(&rsp, &stats, CborIndefiniteLength);
+    g_err |= cbor_encoder_create_map(&cb->encoder, &stats,
+                                     CborIndefiniteLength);
 
     stats_walk(hdr, stats_nmgr_walk_func, &stats);
 
-    g_err |= cbor_encoder_close_container(&rsp, &stats);
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    g_err |= cbor_encoder_close_container(&cb->encoder, &stats);
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;
     }
-    return (0);
-err:
-    mgmt_cbuf_setoerr(cb, g_err);
 
     return (0);
 }
@@ -143,17 +136,15 @@ static int
 stats_nmgr_list(struct mgmt_cbuf *cb)
 {
     CborError g_err = CborNoError;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp, stats;
-
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
-    g_err |= cbor_encode_text_stringz(&rsp, "stat_list");
-    g_err |= cbor_encoder_create_array(&rsp, &stats, CborIndefiniteLength);
+    CborEncoder stats;
+
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "stat_list");
+    g_err |= cbor_encoder_create_array(&cb->encoder, &stats,
+                                       CborIndefiniteLength);
     stats_group_walk(stats_nmgr_encode_name, &stats);
-    g_err |= cbor_encoder_close_container(&rsp, &stats);
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    g_err |= cbor_encoder_close_container(&cb->encoder, &stats);
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/38284705/test/crash_test/src/crash_nmgr.c
----------------------------------------------------------------------
diff --git a/test/crash_test/src/crash_nmgr.c b/test/crash_test/src/crash_nmgr.c
index 7ffd969..b1b8eaa 100644
--- a/test/crash_test/src/crash_nmgr.c
+++ b/test/crash_test/src/crash_nmgr.c
@@ -33,7 +33,7 @@
 static int crash_test_nmgr_write(struct mgmt_cbuf *);
 
 static const struct mgmt_handler crash_test_nmgr_handler[] = {
-    [0] = { crash_test_nmgr_write, crash_test_nmgr_write }
+    [0] = { NULL, crash_test_nmgr_write }
 };
 
 struct mgmt_group crash_test_nmgr_group = {
@@ -60,15 +60,20 @@ crash_test_nmgr_write(struct mgmt_cbuf *cb)
     int rc;
 
     rc = cbor_read_object(&cb->it, attr);
-    if (rc) {
-        rc = MGMT_ERR_EINVAL;
-    } else {
-        rc = crash_device(tmp_str);
-        if (rc) {
-            rc = MGMT_ERR_EINVAL;
-        }
+    if (rc != 0) {
+        return MGMT_ERR_EINVAL;
+    }
+
+    rc = crash_device(tmp_str);
+    if (rc != 0) {
+        return MGMT_ERR_EINVAL;
     }
-    mgmt_cbuf_setoerr(cb, rc);
+
+    rc = mgmt_cbuf_setoerr(cb, 0);
+    if (rc != 0) {
+        return rc;
+    }
+
     return 0;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/38284705/test/runtest/src/runtest_nmgr.c
----------------------------------------------------------------------
diff --git a/test/runtest/src/runtest_nmgr.c b/test/runtest/src/runtest_nmgr.c
index 3c02ee3..ce282ce 100644
--- a/test/runtest/src/runtest_nmgr.c
+++ b/test/runtest/src/runtest_nmgr.c
@@ -105,11 +105,6 @@ run_nmgr_test(struct mgmt_cbuf *cb)
 
     os_eventq_put(run_evq_get(), &run_test_event);
             
-    if (rc) {
-        rc = MGMT_ERR_EINVAL;
-    }
-
-    mgmt_cbuf_setoerr(cb, rc);
     return 0;
 }
 
@@ -120,23 +115,21 @@ static int
 run_nmgr_list(struct mgmt_cbuf *cb)
 {
     CborError g_err = CborNoError;
-    CborEncoder *penc = &cb->encoder;
-    CborEncoder rsp, run_list;
+    CborEncoder run_list;
     struct ts_suite *ts;
 
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, MGMT_ERR_EOK);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "rc");
+    g_err |= cbor_encode_int(&cb->encoder, MGMT_ERR_EOK);
 
-    g_err |= cbor_encode_text_stringz(&rsp, "run_list");
-    g_err |= cbor_encoder_create_array(&rsp, &run_list, CborIndefiniteLength);
+    g_err |= cbor_encode_text_stringz(&cb->encoder, "run_list");
+    g_err |= cbor_encoder_create_array(&cb->encoder, &run_list,
+                                       CborIndefiniteLength);
 
     SLIST_FOREACH(ts, &g_ts_suites, ts_next) {
         g_err |= cbor_encode_text_stringz(&run_list, ts->ts_name);
     }
 
-    g_err |= cbor_encoder_close_container(&rsp, &run_list);
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    g_err |= cbor_encoder_close_container(&cb->encoder, &run_list);
 
     if (g_err) {
         return MGMT_ERR_ENOMEM;



[23/50] incubator-mynewt-core git commit: nimble/l2cap: Fix handling bad data in L2CAP update parameters response

Posted by ma...@apache.org.
nimble/l2cap: Fix handling bad data in L2CAP update parameters response

Returning error will cause sending L2CAP REJECT on that response and
this is incorrect. This patch fixes that.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/a4430354
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/a4430354
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/a4430354

Branch: refs/heads/master
Commit: a4430354b14e932312210adcf6b2830070abb9cd
Parents: eb576bc
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Thu Feb 2 11:32:25 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 12:40:42 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_sig.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a4430354/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index d6219d3..560311d 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -438,7 +438,7 @@ ble_l2cap_sig_update_rsp_rx(uint16_t conn_handle,
 
     default:
         cb_status = BLE_HS_EBADDATA;
-        rc = BLE_HS_EBADDATA;
+        rc = 0;
         break;
     }
 


[06/50] incubator-mynewt-core git commit: This closes #187.

Posted by ma...@apache.org.
This closes #187.

Merge branch 'mynewt-634' of https://github.com/sjanc/incubator-mynewt-core into develop


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/58378ccf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/58378ccf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/58378ccf

Branch: refs/heads/master
Commit: 58378ccfad173af6bebda22c5cf1d5f2b7d80d46
Parents: 3828470 259d2a8
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Mar 2 12:32:20 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Mar 2 12:32:20 2017 -0800

----------------------------------------------------------------------
 apps/blecent/src/main.c | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/58378ccf/apps/blecent/src/main.c
----------------------------------------------------------------------


[49/50] incubator-mynewt-core git commit: SensorAPI: move i2cscan cmd to sensor shell

Posted by ma...@apache.org.
SensorAPI: move i2cscan cmd to sensor shell

- Moving from bno055 driver to the sensor shell because it really
  doesn't belong in the driver but is cmd that would be useful for
  multiple sensors


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/c3b41745
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/c3b41745
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/c3b41745

Branch: refs/heads/master
Commit: c3b417456815272ff586ef644c52a0de6cea2589
Parents: bc1c683
Author: Vipul Rahane <vi...@apache.org>
Authored: Mon Mar 6 12:36:37 2017 -0800
Committer: Vipul Rahane <vi...@apache.org>
Committed: Mon Mar 6 12:39:47 2017 -0800

----------------------------------------------------------------------
 hw/drivers/sensors/bno055/src/bno055.c       |  8 +++
 hw/drivers/sensors/bno055/src/bno055_shell.c | 77 +++--------------------
 hw/sensor/include/sensor/sensor.h            |  4 ++
 hw/sensor/src/sensor_shell.c                 | 67 ++++++++++++++++++++
 4 files changed, 87 insertions(+), 69 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c3b41745/hw/drivers/sensors/bno055/src/bno055.c
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bno055/src/bno055.c b/hw/drivers/sensors/bno055/src/bno055.c
index 6773650..dbf0288 100644
--- a/hw/drivers/sensors/bno055/src/bno055.c
+++ b/hw/drivers/sensors/bno055/src/bno055.c
@@ -806,6 +806,14 @@ bno055_config(struct bno055 *bno055, struct bno055_cfg *cfg)
 
     bno055->cfg.bc_opr_mode = cfg->bc_opr_mode;
 
+    rc = bno055_acc_cfg(cfg);
+    if (rc) {
+        goto err;
+    }
+
+    bno055->cfg.bc_acc_range = cfg->bc_acc_range;
+    bno055->cfg.bc_acc_bw = cfg->bc_acc_bw;
+
     return 0;
 err:
     return rc;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c3b41745/hw/drivers/sensors/bno055/src/bno055_shell.c
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bno055/src/bno055_shell.c b/hw/drivers/sensors/bno055/src/bno055_shell.c
index 6404245..dd9ee08 100644
--- a/hw/drivers/sensors/bno055/src/bno055_shell.c
+++ b/hw/drivers/sensors/bno055/src/bno055_shell.c
@@ -42,23 +42,6 @@ static struct shell_cmd bno055_shell_cmd_struct = {
 };
 
 static int
-bno055_shell_stol(char *param_val, long min, long max, long *output)
-{
-    char *endptr;
-    long lval;
-
-    lval = strtol(param_val, &endptr, 10); /* Base 10 */
-    if (param_val != '\0' && *endptr == '\0' &&
-        lval >= min && lval <= max) {
-            *output = lval;
-    } else {
-        return EINVAL;
-    }
-
-    return 0;
-}
-
-static int
 bno055_shell_err_too_many_args(char *cmd_name)
 {
     console_printf("Error: too many arguments for command \"%s\"\n",
@@ -140,7 +123,7 @@ bno055_shell_cmd_sensor_offsets(int argc, char **argv)
         tok = strtok(argv[2], ":");
         i = 0;
         do {
-            if (bno055_shell_stol(tok, 0, UINT16_MAX, &val)) {
+            if (sensor_shell_stol(tok, 0, UINT16_MAX, &val)) {
                 return bno055_shell_err_invalid_arg(argv[2]);
             }
             offsetdata[i] = val;
@@ -238,16 +221,17 @@ bno055_shell_cmd_read(int argc, char **argv)
 
     /* Since this is the biggest struct, malloc space for it */
     databuf = malloc(sizeof(*sqd));
+    assert(databuf != NULL);
 
 
     /* Check if more than one sample requested */
     if (argc == 4) {
-        if (bno055_shell_stol(argv[2], 1, UINT16_MAX, &val)) {
+        if (sensor_shell_stol(argv[2], 1, UINT16_MAX, &val)) {
             return bno055_shell_err_invalid_arg(argv[2]);
         }
         samples = (uint16_t)val;
 
-        if (bno055_shell_stol(argv[3], 0, UINT16_MAX, &val)) {
+        if (sensor_shell_stol(argv[3], 0, UINT16_MAX, &val)) {
             return bno055_shell_err_invalid_arg(argv[2]);
         }
         type = (int)(1 << val);
@@ -331,7 +315,7 @@ bno055_shell_cmd_opr_mode(int argc, char **argv)
 
     /* Update the mode */
     if (argc == 3) {
-        if (bno055_shell_stol(argv[2], 0, 16, &val)) {
+        if (sensor_shell_stol(argv[2], 0, BNO055_OPR_MODE_NDOF, &val)) {
             return bno055_shell_err_invalid_arg(argv[2]);
         }
         /* Make sure mode is valid */
@@ -371,7 +355,7 @@ bno055_shell_cmd_pwr_mode(int argc, char **argv)
 
     /* Update the mode */
     if (argc == 3) {
-        if (bno055_shell_stol(argv[2], 0, 16, &val)) {
+        if (sensor_shell_stol(argv[2], 0, BNO055_PWR_MODE_SUSPEND, &val)) {
             return bno055_shell_err_invalid_arg(argv[2]);
         }
         /* Make sure mode is valid */
@@ -419,7 +403,7 @@ bno055_shell_units_cmd(int argc, char **argv)
 
     /* Update the units */
     if (argc == 3) {
-        if (bno055_shell_stol(argv[2], 0, UINT8_MAX, &val)) {
+        if (sensor_shell_stol(argv[2], 0, UINT8_MAX, &val)) {
             return bno055_shell_err_invalid_arg(argv[2]);
         }
 
@@ -441,7 +425,7 @@ bno055_shell_cmd_dumpreg(int argc, char **argv)
     uint8_t val;
     int rc;
 
-    if (bno055_shell_stol(argv[2], 0, UINT8_MAX, &addr)) {
+    if (sensor_shell_stol(argv[2], 0, UINT8_MAX, &addr)) {
         return bno055_shell_err_invalid_arg(argv[2]);
     }
     rc = bno055_read8((uint8_t)addr, &val);
@@ -456,47 +440,6 @@ err:
 }
 
 static int
-shell_i2cscan_cmd(int argc, char **argv)
-{
-    uint8_t addr;
-    int32_t timeout;
-    uint8_t dev_count = 0;
-    long i2cnum;
-    int rc;
-
-    timeout = OS_TICKS_PER_SEC / 10;
-
-    if (bno055_shell_stol(argv[2], 0, 0xf, &i2cnum)) {
-        return bno055_shell_err_invalid_arg(argv[2]);
-    }
-
-    console_printf("Scanning I2C bus %u\n"
-                   "     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f\n"
-                   "00:          ", (uint8_t)i2cnum);
-
-
-    /* Scan all valid I2C addresses (0x08..0x77) */
-    for (addr = 0x08; addr < 0x78; addr++) {
-        rc = hal_i2c_master_probe((uint8_t)i2cnum, addr, timeout);
-        /* Print addr header every 16 bytes */
-        if (!(addr % 16)) {
-            console_printf("\n%02x: ", addr);
-        }
-        /* Display the addr if a response was received */
-        if (!rc) {
-            console_printf("%02x ", addr);
-            dev_count++;
-        } else {
-            console_printf("-- ");
-        }
-        os_time_delay(OS_TICKS_PER_SEC/1000 * 20);
-    }
-    console_printf("\nFound %u devices on I2C bus %u\n", dev_count, (uint8_t)i2cnum);
-
-    return 0;
-}
-
-static int
 bno055_shell_cmd_reset(int argc, char **argv)
 {
     int rc;
@@ -552,10 +495,6 @@ bno055_shell_cmd(int argc, char **argv)
         return bno055_shell_cmd_dumpreg(argc, argv);
     }
 
-    if (argc > 1 && strcmp(argv[1], "i2cscan") == 0) {
-        return shell_i2cscan_cmd(argc, argv);
-    }
-
     if (argc > 1 && strcmp(argv[1], "units") == 0) {
         return bno055_shell_units_cmd(argc, argv);
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c3b41745/hw/sensor/include/sensor/sensor.h
----------------------------------------------------------------------
diff --git a/hw/sensor/include/sensor/sensor.h b/hw/sensor/include/sensor/sensor.h
index 769a148..813634b 100644
--- a/hw/sensor/include/sensor/sensor.h
+++ b/hw/sensor/include/sensor/sensor.h
@@ -325,8 +325,12 @@ struct sensor *sensor_mgr_find_next(sensor_mgr_compare_func_t, void *,
 struct sensor *sensor_mgr_find_next_bytype(sensor_type_t, struct sensor *);
 struct sensor *sensor_mgr_find_next_bydevname(char *, struct sensor *);
 
+#if MYNEWT_VAL(SENSOR_CLI)
 char*
 sensor_ftostr(float num, char *fltstr, int len);
+int
+sensor_shell_stol(char *param_val, long min, long max, long *output);
+#endif
 
 /**
  * }@

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c3b41745/hw/sensor/src/sensor_shell.c
----------------------------------------------------------------------
diff --git a/hw/sensor/src/sensor_shell.c b/hw/sensor/src/sensor_shell.c
index 545653f..8a9b969 100644
--- a/hw/sensor/src/sensor_shell.c
+++ b/hw/sensor/src/sensor_shell.c
@@ -38,6 +38,7 @@
 #include "sensor/euler.h"
 #include "console/console.h"
 #include "shell/shell.h"
+#include "hal/hal_i2c.h"
 
 static int sensor_cmd_exec(int, char **);
 static struct shell_cmd shell_sensor_cmd = {
@@ -239,6 +240,67 @@ err:
     return;
 }
 
+int
+sensor_shell_stol(char *param_val, long min, long max, long *output)
+{
+    char *endptr;
+    long lval;
+
+    lval = strtol(param_val, &endptr, 10); /* Base 10 */
+    if (param_val != '\0' && *endptr == '\0' &&
+        lval >= min && lval <= max) {
+            *output = lval;
+    } else {
+        return EINVAL;
+    }
+
+    return 0;
+}
+
+static int
+sensor_cmd_i2cscan(int argc, char **argv)
+{
+    uint8_t addr;
+    int32_t timeout;
+    uint8_t dev_count = 0;
+    long i2cnum;
+    int rc;
+
+    timeout = OS_TICKS_PER_SEC / 10;
+
+    if (sensor_shell_stol(argv[2], 0, 0xf, &i2cnum)) {
+        console_printf("Invalid i2c interface:%s\n", argv[2]);
+        rc = SYS_EINVAL;
+        goto err;
+    }
+
+    console_printf("Scanning I2C bus %u\n"
+                   "     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f\n"
+                   "00:          ", (uint8_t)i2cnum);
+
+
+    /* Scan all valid I2C addresses (0x08..0x77) */
+    for (addr = 0x08; addr < 0x78; addr++) {
+        rc = hal_i2c_master_probe((uint8_t)i2cnum, addr, timeout);
+        /* Print addr header every 16 bytes */
+        if (!(addr % 16)) {
+            console_printf("\n%02x: ", addr);
+        }
+        /* Display the addr if a response was received */
+        if (!rc) {
+            console_printf("%02x ", addr);
+            dev_count++;
+        } else {
+            console_printf("-- ");
+        }
+        os_time_delay(OS_TICKS_PER_SEC/1000 * 20);
+    }
+    console_printf("\nFound %u devices on I2C bus %u\n", dev_count, (uint8_t)i2cnum);
+
+    return 0;
+err:
+    return rc;
+}
 
 static int
 sensor_cmd_exec(int argc, char **argv)
@@ -264,6 +326,11 @@ sensor_cmd_exec(int argc, char **argv)
             goto err;
         }
         sensor_cmd_read(argv[2], (sensor_type_t) atoi(argv[3]), atoi(argv[4]));
+    } else if (!strcmp(argv[1], "i2cscan")) {
+        rc = sensor_cmd_i2cscan(argc, argv);
+        if (rc) {
+            goto err;
+        }
     } else {
         console_printf("Unknown sensor command %s\n", subcmd);
         rc = SYS_EINVAL;


[43/50] incubator-mynewt-core git commit: Fix invalid memory accesses in ble_uuid_cmp

Posted by ma...@apache.org.
Fix invalid memory accesses in ble_uuid_cmp

When the two uuid values differ in type, one of two things can happen:

1. Access to unallocated or uninitialised memory
2. Unaligned access to 16/32-bit values

Both of these cause crashes, so always make sure we are comparing like types.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/d50951d0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/d50951d0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/d50951d0

Branch: refs/heads/master
Commit: d50951d05479ea3e2749068e7f5cab3c635c3412
Parents: 2242bc1
Author: Simon Ratner <si...@probablyprime.net>
Authored: Sat Mar 4 12:02:40 2017 -0800
Committer: Simon Ratner <si...@probablyprime.net>
Committed: Sat Mar 4 12:02:40 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_uuid.c | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d50951d0/net/nimble/host/src/ble_uuid.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_uuid.c b/net/nimble/host/src/ble_uuid.c
index 028e227..f9ccc6d 100644
--- a/net/nimble/host/src/ble_uuid.c
+++ b/net/nimble/host/src/ble_uuid.c
@@ -76,6 +76,10 @@ ble_uuid_cmp(const ble_uuid_t *uuid1, const ble_uuid_t *uuid2)
     BLE_HS_DBG_ASSERT(verify_uuid(uuid1) == 0);
     BLE_HS_DBG_ASSERT(verify_uuid(uuid2) == 0);
 
+    if (uuid1->type != uuid2->type) {
+      return uuid1->type - uuid2->type;
+    }
+
     switch (uuid1->type) {
     case BLE_UUID_TYPE_16:
         return (int) BLE_UUID16(uuid1)->value - (int) BLE_UUID16(uuid2)->value;


[17/50] incubator-mynewt-core git commit: bletiny: Add debug log for CoC accept

Posted by ma...@apache.org.
bletiny: Add debug log for CoC accept


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/3d756b3f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3d756b3f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3d756b3f

Branch: refs/heads/master
Commit: 3d756b3fb2a91a6865b8c1ddb7f66242ebb0289b
Parents: be58d00
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Thu Feb 16 06:29:56 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 12:40:41 2017 +0100

----------------------------------------------------------------------
 apps/bletiny/src/main.c | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3d756b3f/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index b8f1e51..442a264 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -1643,6 +1643,9 @@ bletiny_l2cap_coc_accept(uint16_t conn_handle, uint16_t peer_mtu,
 {
     struct os_mbuf *sdu_rx;
 
+    console_printf("LE CoC accepting, chan: 0x%08lx, peer_mtu %d\n",
+                       (uint32_t) chan, peer_mtu);
+
     sdu_rx = os_mbuf_get_pkthdr(&sdu_os_mbuf_pool, 0);
     if (!sdu_rx) {
         return BLE_HS_ENOMEM;


[38/50] incubator-mynewt-core git commit: This closes #189.

Posted by ma...@apache.org.
This closes #189.

Merge branch 'mynewt-652' of https://github.com/mkiiskila/incubator-mynewt-core into develop


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/4a9cb512
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/4a9cb512
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/4a9cb512

Branch: refs/heads/master
Commit: 4a9cb51282816109479cbf9f08498e3dd916e7e6
Parents: 389d7f4 0b037a6
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Mar 3 08:00:49 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Mar 3 08:00:49 2017 -0800

----------------------------------------------------------------------
 net/oic/src/messaging/coap/observe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------



[03/50] incubator-mynewt-core git commit: MYNEWT-650 fs/fs/test build errors for non-native

Posted by ma...@apache.org.
MYNEWT-650 fs/fs/test build errors for non-native

The problem is that the fixed-size integer types map to different
"natural" integer types, depending on the target platform.
Unfortunately, the PRIxxx macros in inttypes.h don't work here, since
gcc assumes no cross compile when it generates the warning. The next
best solution is to cast everything to uintmax_t and apply the j format
specifier.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/a4df93c1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/a4df93c1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/a4df93c1

Branch: refs/heads/master
Commit: a4df93c102a6d4d0a4d6896af704bd7c1d2ebff6
Parents: 316c18a
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Mar 1 16:50:17 2017 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Wed Mar 1 16:51:24 2017 -0800

----------------------------------------------------------------------
 fs/nffs/test/src/nffs_test_debug.c | 274 ++++++++++++++++++++------------
 1 file changed, 168 insertions(+), 106 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a4df93c1/fs/nffs/test/src/nffs_test_debug.c
----------------------------------------------------------------------
diff --git a/fs/nffs/test/src/nffs_test_debug.c b/fs/nffs/test/src/nffs_test_debug.c
index 0d01fcf..f59fa42 100644
--- a/fs/nffs/test/src/nffs_test_debug.c
+++ b/fs/nffs/test/src/nffs_test_debug.c
@@ -64,8 +64,9 @@ print_inode_entry(struct nffs_inode_entry *inode_entry, int indent)
 
     name[inode.ni_filename_len] = '\0';
 
-    printf("%*s%s %d %x\n", indent, "", name[0] == '\0' ? "/" : name,
-           inode.ni_seq, inode.ni_inode_entry->nie_flags);
+    printf("%*s%s %ju %jx\n", indent, "", name[0] == '\0' ? "/" : name,
+           (uintmax_t) inode.ni_seq,
+           (uintmax_t) inode.ni_inode_entry->nie_flags);
 }
 
 void
@@ -99,16 +100,17 @@ print_nffs_flash_inode(struct nffs_area *area, uint32_t off)
     rc = hal_flash_read(area->na_flash_id, area->na_offset + off + sizeof(ndi),
                          filename, len);
 
-    printf("  off %x %s id %x flen %d seq %d last %x prnt %x flgs %x %s\n",
-           off,
+    printf("  off %jx %s id %jx flen %ju seq %ju last %jx prnt %jx "
+           "flgs %jx %s\n",
+           (uintmax_t) off,
            (nffs_hash_id_is_file(ndi.ndi_id) ? "File" :
             (nffs_hash_id_is_dir(ndi.ndi_id) ? "Dir" : "???")),
-           ndi.ndi_id,
-           ndi.ndi_filename_len,
-           ndi.ndi_seq,
-           ndi.ndi_lastblock_id,
-           ndi.ndi_parent_id,
-           ndi.ndi_flags,
+           (uintmax_t) ndi.ndi_id,
+           (uintmax_t) ndi.ndi_filename_len,
+           (uintmax_t) ndi.ndi_seq,
+           (uintmax_t) ndi.ndi_lastblock_id,
+           (uintmax_t) ndi.ndi_parent_id,
+           (uintmax_t) ndi.ndi_flags,
            filename);
     return sizeof(ndi) + ndi.ndi_filename_len;
 }
@@ -123,13 +125,13 @@ print_nffs_flash_block(struct nffs_area *area, uint32_t off)
                         &ndb, sizeof(ndb));
     assert(rc == 0);
 
-    printf("  off %x Block id %x len %d seq %d prev %x own ino %x\n",
-           off,
-           ndb.ndb_id,
-           ndb.ndb_data_len,
-           ndb.ndb_seq,
-           ndb.ndb_prev_id,
-           ndb.ndb_inode_id);
+    printf("  off %jx Block id %jx len %ju seq %ju prev %jx own ino %jx\n",
+           (uintmax_t) off,
+           (uintmax_t) ndb.ndb_id,
+           (uintmax_t) ndb.ndb_data_len,
+           (uintmax_t) ndb.ndb_seq,
+           (uintmax_t) ndb.ndb_prev_id,
+           (uintmax_t) ndb.ndb_inode_id);
     return sizeof(ndb) + ndb.ndb_data_len;
 }
 
@@ -176,9 +178,16 @@ print_nffs_flash_areas(int verbose)
         if (!nffs_area_magic_is_set(&darea)) {
             printf("Area header corrupt!\n");
         }
-        printf("area %d: id %d %x-%x cur %x len %d flashid %x gc-seq %d %s%s\n",
-               i, area.na_id, area.na_offset, area.na_offset + area.na_length,
-               area.na_cur, area.na_length, area.na_flash_id, darea.nda_gc_seq,
+        printf("area %d: id %ju %jx-%jx cur %jx len %ju flashid %jx "
+               "gc-seq %jd %s%s\n",
+               i,
+               (uintmax_t)area.na_id,
+               (uintmax_t)area.na_offset,
+               (uintmax_t)area.na_offset + area.na_length,
+               (uintmax_t)area.na_cur,
+               (uintmax_t)area.na_length,
+               (uintmax_t)area.na_flash_id,
+               (uintmax_t)darea.nda_gc_seq,
                nffs_scratch_area_idx == i ? "(scratch)" : "",
                !nffs_area_magic_is_set(&darea) ? "corrupt" : "");
         if (verbose < 2) {
@@ -204,11 +213,12 @@ print_hashlist(struct nffs_hash_entry *he)
     list = nffs_hash + idx;
 
     SLIST_FOREACH(he, list, nhe_next) {
-        printf("hash_entry %s 0x%x: id 0x%x flash_loc 0x%x next 0x%x\n",
+        printf("hash_entry %s %p: id 0x%jx flash_loc 0x%jx next %p\n",
                    nffs_hash_id_is_inode(he->nhe_id) ? "inode" : "block",
-                   (unsigned int)he,
-                   he->nhe_id, he->nhe_flash_loc,
-                   (unsigned int)he->nhe_next.sle_next);
+                   he,
+                   (uintmax_t)he->nhe_id,
+                   (uintmax_t)he->nhe_flash_loc,
+                   he->nhe_next.sle_next);
    }
 }
 
@@ -228,10 +238,13 @@ print_hash(void)
 
     NFFS_HASH_FOREACH(he, i, next) {
         if (nffs_hash_id_is_inode(he->nhe_id)) {
-            printf("hash_entry inode %d 0x%x: id 0x%x flash_loc 0x%x next 0x%x\n",
-                   i, (unsigned int)he,
-                   he->nhe_id, he->nhe_flash_loc,
-                   (unsigned int)he->nhe_next.sle_next);
+            printf("hash_entry inode %d %p: id 0x%jx flash_loc 0x%jx "
+                   "next %p\n",
+                   i,
+                   he,
+                   (uintmax_t)he->nhe_id,
+                   (uintmax_t)he->nhe_flash_loc,
+                   he->nhe_next.sle_next);
             if (he->nhe_id == NFFS_ID_ROOT_DIR) {
                 continue;
             }
@@ -239,56 +252,66 @@ print_hash(void)
                                   &area_idx, &area_offset);
             rc = nffs_inode_read_disk(area_idx, area_offset, &di);
             if (rc) {
-                printf("%d: fail inode read id 0x%x rc %d\n",
-                       i, he->nhe_id, rc);
+                printf("%d: fail inode read id 0x%jx rc %d\n",
+                       i, (uintmax_t)he->nhe_id, rc);
             }
-            printf("    Disk inode: id %x seq %d parent %x last %x flgs %x\n",
-                   di.ndi_id,
-                   di.ndi_seq,
-                   di.ndi_parent_id,
-                   di.ndi_lastblock_id,
-                   di.ndi_flags);
+            printf("    Disk inode: id %jx seq %ju parent %jx last %jx "
+                   "flgs %jx\n",
+                   (uintmax_t)di.ndi_id,
+                   (uintmax_t)di.ndi_seq,
+                   (uintmax_t)di.ndi_parent_id,
+                   (uintmax_t)di.ndi_lastblock_id,
+                   (uintmax_t)di.ndi_flags);
             ni.ni_inode_entry = (struct nffs_inode_entry *)he;
             ni.ni_seq = di.ndi_seq; 
             ni.ni_parent = nffs_hash_find_inode(di.ndi_parent_id);
-            printf("    RAM inode: entry 0x%x seq %d parent %x filename %s\n",
-                   (unsigned int)ni.ni_inode_entry,
-                   ni.ni_seq,
-                   (unsigned int)ni.ni_parent,
+            printf("    RAM inode: entry %p seq %ju parent %p "
+                   "filename %s\n",
+                   ni.ni_inode_entry,
+                   (uintmax_t)ni.ni_seq,
+                   ni.ni_parent,
                    ni.ni_filename);
 
         } else if (nffs_hash_id_is_block(he->nhe_id)) {
-            printf("hash_entry block %d 0x%x: id 0x%x flash_loc 0x%x next 0x%x\n",
-                   i, (unsigned int)he,
-                   he->nhe_id, he->nhe_flash_loc,
-                   (unsigned int)he->nhe_next.sle_next);
+            printf("hash_entry block %d %p: id 0x%jx flash_loc 0x%jx "
+                   "next %p\n",
+                   i,
+                   he,
+                   (uintmax_t)he->nhe_id,
+                   (uintmax_t)he->nhe_flash_loc,
+                   he->nhe_next.sle_next);
             rc = nffs_block_from_hash_entry(&nb, he);
             if (rc) {
-                printf("%d: fail block read id 0x%x rc %d\n",
-                       i, he->nhe_id, rc);
+                printf("%d: fail block read id 0x%jx rc %d\n",
+                       i, (uintmax_t)he->nhe_id, rc);
             }
-            printf("    block: id %x seq %d inode %x prev %x\n",
-                   nb.nb_hash_entry->nhe_id, nb.nb_seq, 
-                   nb.nb_inode_entry->nie_hash_entry.nhe_id, 
-                   nb.nb_prev->nhe_id);
+            printf("    block: id %jx seq %ju inode %jx prev %jx\n",
+                   (uintmax_t)nb.nb_hash_entry->nhe_id,
+                   (uintmax_t)nb.nb_seq, 
+                   (uintmax_t)nb.nb_inode_entry->nie_hash_entry.nhe_id, 
+                   (uintmax_t)nb.nb_prev->nhe_id);
             nffs_flash_loc_expand(nb.nb_hash_entry->nhe_flash_loc,
                                   &area_idx, &area_offset);
             rc = nffs_block_read_disk(area_idx, area_offset, &db);
             if (rc) {
-                printf("%d: fail disk block read id 0x%x rc %d\n",
-                       i, nb.nb_hash_entry->nhe_id, rc);
+                printf("%d: fail disk block read id 0x%jx rc %d\n",
+                       i, (uintmax_t)nb.nb_hash_entry->nhe_id, rc);
             }
-            printf("    disk block: id %x seq %d inode %x prev %x len %d\n",
-                   db.ndb_id,
-                   db.ndb_seq,
-                   db.ndb_inode_id,
-                   db.ndb_prev_id,
-                   db.ndb_data_len);
+            printf("    disk block: id %jx seq %ju inode %jx prev %jx "
+                   "len %ju\n",
+                   (uintmax_t)db.ndb_id,
+                   (uintmax_t)db.ndb_seq,
+                   (uintmax_t)db.ndb_inode_id,
+                   (uintmax_t)db.ndb_prev_id,
+                   (uintmax_t)db.ndb_data_len);
         } else {
-            printf("hash_entry UNKNONN %d 0x%x: id 0x%x flash_loc 0x%x next 0x%x\n",
-                   i, (unsigned int)he,
-                   he->nhe_id, he->nhe_flash_loc,
-                   (unsigned int)he->nhe_next.sle_next);
+            printf("hash_entry UNKNONN %d %p: id 0x%jx flash_loc 0x%jx "
+                   "next %p\n",
+                   i,
+                   he,
+                   (uintmax_t)he->nhe_id,
+                   (uintmax_t)he->nhe_flash_loc,
+                   he->nhe_next.sle_next);
         }
     }
 
@@ -301,27 +324,32 @@ nffs_print_object(struct nffs_disk_object *dobj)
     struct nffs_disk_block *db = &dobj->ndo_disk_block;
 
     if (dobj->ndo_type == NFFS_OBJECT_TYPE_INODE) {
-        printf("    %s id %x seq %d prnt %x last %x\n",
+        printf("    %s id %jx seq %ju prnt %jx last %jx\n",
                nffs_hash_id_is_file(di->ndi_id) ? "File" :
                 nffs_hash_id_is_dir(di->ndi_id) ? "Dir" : "???",
-               di->ndi_id, di->ndi_seq, di->ndi_parent_id,
-               di->ndi_lastblock_id);
+               (uintmax_t)di->ndi_id,
+               (uintmax_t)di->ndi_seq,
+               (uintmax_t)di->ndi_parent_id,
+               (uintmax_t)di->ndi_lastblock_id);
     } else if (dobj->ndo_type != NFFS_OBJECT_TYPE_BLOCK) {
-        printf("    %s: id %x seq %d ino %x prev %x len %d\n",
+        printf("    %s: id %jx seq %ju ino %jx prev %jx len %ju\n",
                nffs_hash_id_is_block(db->ndb_id) ? "Block" : "Block?",
-               db->ndb_id, db->ndb_seq, db->ndb_inode_id,
-               db->ndb_prev_id, db->ndb_data_len);
+               (uintmax_t)db->ndb_id,
+               (uintmax_t)db->ndb_seq,
+               (uintmax_t)db->ndb_inode_id,
+               (uintmax_t)db->ndb_prev_id,
+               (uintmax_t)db->ndb_data_len);
     }
 }
 
 void
 print_nffs_hash_block(struct nffs_hash_entry *he, int verbose)
 {
-    struct nffs_block nb;
+    struct nffs_block nb = { 0 };
     struct nffs_disk_block db;
     uint32_t area_offset;
     uint8_t area_idx;
-    int rc;
+    int rc = 0;
 
     if (he == NULL) {
         return;
@@ -331,8 +359,8 @@ print_nffs_hash_block(struct nffs_hash_entry *he, int verbose)
                               &area_idx, &area_offset);
         rc = nffs_block_read_disk(area_idx, area_offset, &db);
         if (rc) {
-            printf("%p: fail block read id 0x%x rc %d\n",
-                   he, he->nhe_id, rc);
+            printf("%p: fail block read id 0x%jx rc %d\n",
+                   he, (uintmax_t)he->nhe_id, rc);
         }
         nb.nb_hash_entry = he;
         nb.nb_seq = db.ndb_seq;
@@ -352,28 +380,43 @@ print_nffs_hash_block(struct nffs_hash_entry *he, int verbose)
         db.ndb_id = 0;
     }
     if (!verbose) {
-        printf("%s%s id %x idx/off %d/%x seq %d ino %x prev %x len %d\n",
+        printf("%s%s id %jx idx/off %ju/%jx seq %ju ino %jx prev %jx "
+               "len %ju\n",
                nffs_hash_entry_is_dummy(he) ? "Dummy " : "",
                nffs_hash_id_is_block(he->nhe_id) ? "Block" : "Unknown",
-               he->nhe_id, area_idx, area_offset, nb.nb_seq,
-               nb.nb_inode_entry->nie_hash_entry.nhe_id,
-               (unsigned int)db.ndb_prev_id, db.ndb_data_len);
+               (uintmax_t)he->nhe_id,
+               (uintmax_t)area_idx,
+               (uintmax_t)area_offset,
+               (uintmax_t)nb.nb_seq,
+               (uintmax_t)nb.nb_inode_entry->nie_hash_entry.nhe_id,
+               (uintmax_t)db.ndb_prev_id,
+               (uintmax_t)db.ndb_data_len);
         return;
     }
-    printf("%s%s id %x loc %x/%x %x ent %p\n",
+    printf("%s%s id %jx loc %jx/%jx %jx ent %p\n",
            nffs_hash_entry_is_dummy(he) ? "Dummy " : "",
            nffs_hash_id_is_block(he->nhe_id) ? "Block:" : "Unknown:",
-           he->nhe_id, area_idx, area_offset, he->nhe_flash_loc, he);
+           (uintmax_t)he->nhe_id,
+           (uintmax_t)area_idx,
+           (uintmax_t)area_offset,
+           (uintmax_t)he->nhe_flash_loc,
+           he);
     if (nb.nb_inode_entry) {
-        printf("  Ram: ent %p seq %d ino %p prev %p len %d\n",
-               nb.nb_hash_entry, nb.nb_seq,
-               nb.nb_inode_entry, nb.nb_prev, nb.nb_data_len);
+        printf("  Ram: ent %p seq %ju ino %p prev %p len %ju\n",
+               nb.nb_hash_entry,
+               (uintmax_t)nb.nb_seq,
+               nb.nb_inode_entry,
+               nb.nb_prev,
+               (uintmax_t)nb.nb_data_len);
     }
     if (db.ndb_id) {
-        printf("  Disk %s id %x seq %d ino %x prev %x len %d\n",
+        printf("  Disk %s id %jx seq %ju ino %jx prev %jx len %ju\n",
                nffs_hash_id_is_block(db.ndb_id) ? "Block:" : "???:",
-               db.ndb_id, db.ndb_seq, db.ndb_inode_id,
-               db.ndb_prev_id, db.ndb_data_len);
+               (uintmax_t)db.ndb_id,
+               (uintmax_t)db.ndb_seq,
+               (uintmax_t)db.ndb_inode_id,
+               (uintmax_t)db.ndb_prev_id,
+               (uintmax_t)db.ndb_data_len);
     }
 }
 
@@ -386,7 +429,7 @@ print_nffs_hash_inode(struct nffs_hash_entry *he, int verbose)
     int cached_name_len;
     uint32_t area_offset;
     uint8_t area_idx;
-    int rc;
+    int rc = 0;
 
     if (he == NULL) {
         return;
@@ -396,8 +439,8 @@ print_nffs_hash_inode(struct nffs_hash_entry *he, int verbose)
                               &area_idx, &area_offset);
         rc = nffs_inode_read_disk(area_idx, area_offset, &di);
         if (rc) {
-            printf("Entry %p: fail inode read id 0x%x rc %d\n",
-                   he, he->nhe_id, rc);
+            printf("Entry %p: fail inode read id 0x%jx rc %d\n",
+                   he, (uintmax_t)he->nhe_id, rc);
         }
         ni.ni_inode_entry = (struct nffs_inode_entry *)he;
         ni.ni_seq = di.ndi_seq; 
@@ -415,8 +458,8 @@ print_nffs_hash_inode(struct nffs_hash_entry *he, int verbose)
             rc = nffs_flash_read(area_idx, area_offset + sizeof di,
                          ni.ni_filename, cached_name_len);
             if (rc != 0) {
-                printf("entry %p: fail filename read id 0x%x rc %d\n",
-                       he, he->nhe_id, rc);
+                printf("entry %p: fail filename read id 0x%jx rc %d\n",
+                       he, (uintmax_t)he->nhe_id, rc);
                 return;
             }
         }
@@ -425,41 +468,56 @@ print_nffs_hash_inode(struct nffs_hash_entry *he, int verbose)
         di.ndi_id = 0;
     }
     if (!verbose) {
-        printf("%s%s id %x idx/off %x/%x seq %d prnt %x last %x flags %x",
+        printf("%s%s id %jx idx/off %jx/%jx seq %ju prnt %jx last %jx "
+               "flags %jx",
                nffs_hash_entry_is_dummy(he) ? "Dummy " : "",
-
                nffs_hash_id_is_file(he->nhe_id) ? "File" :
                 he->nhe_id == NFFS_ID_ROOT_DIR ? "**ROOT Dir" : 
                 nffs_hash_id_is_dir(he->nhe_id) ? "Dir" : "Inode",
 
-               he->nhe_id, area_idx, area_offset, ni.ni_seq, di.ndi_parent_id,
-               di.ndi_lastblock_id, nie->nie_flags);
+               (uintmax_t)he->nhe_id,
+               (uintmax_t)area_idx,
+               (uintmax_t)area_offset,
+               (uintmax_t)ni.ni_seq,
+               (uintmax_t)di.ndi_parent_id,
+               (uintmax_t)di.ndi_lastblock_id,
+               (uintmax_t)nie->nie_flags);
         if (ni.ni_inode_entry) {
-            printf(" ref %d\n", ni.ni_inode_entry->nie_refcnt);
+            printf(" ref %ju\n", (uintmax_t)ni.ni_inode_entry->nie_refcnt);
         } else {
             printf("\n");
         }
         return;
     }
-    printf("%s%s id %x loc %x/%x %x entry %p\n",
+    printf("%s%s id %jx loc %jx/%jx %jx entry %p\n",
            nffs_hash_entry_is_dummy(he) ? "Dummy " : "",
            nffs_hash_id_is_file(he->nhe_id) ? "File:" :
             he->nhe_id == NFFS_ID_ROOT_DIR ? "**ROOT Dir:" : 
             nffs_hash_id_is_dir(he->nhe_id) ? "Dir:" : "Inode:",
-           he->nhe_id, area_idx, area_offset, he->nhe_flash_loc, he);
+           (uintmax_t)he->nhe_id,
+           (uintmax_t)area_idx,
+           (uintmax_t)area_offset,
+           (uintmax_t)he->nhe_flash_loc,
+           he);
     if (ni.ni_inode_entry) {
-        printf("  ram: ent %p seq %d prnt %p lst %p ref %d flgs %x nm %s\n",
-               ni.ni_inode_entry, ni.ni_seq, ni.ni_parent,
+        printf("  ram: ent %p seq %ju prnt %p lst %p ref %ju flgs %jx nm %s\n",
+               ni.ni_inode_entry,
+               (uintmax_t)ni.ni_seq,
+               ni.ni_parent,
                ni.ni_inode_entry->nie_last_block_entry,
-               ni.ni_inode_entry->nie_refcnt, ni.ni_inode_entry->nie_flags,
+               (uintmax_t)ni.ni_inode_entry->nie_refcnt,
+               (uintmax_t)ni.ni_inode_entry->nie_flags,
                ni.ni_filename);
     }
     if (rc == 0) {
-        printf("  Disk %s: id %x seq %d prnt %x lst %x flgs %x\n",
+        printf("  Disk %s: id %jx seq %ju prnt %jx lst %jx flgs %jx\n",
                nffs_hash_id_is_file(di.ndi_id) ? "File" :
                 nffs_hash_id_is_dir(di.ndi_id) ? "Dir" : "???",
-               di.ndi_id, di.ndi_seq, di.ndi_parent_id,
-               di.ndi_lastblock_id, di.ndi_flags);
+               (uintmax_t)di.ndi_id,
+               (uintmax_t)di.ndi_seq,
+               (uintmax_t)di.ndi_parent_id,
+               (uintmax_t)di.ndi_lastblock_id,
+               (uintmax_t)di.ndi_flags);
     }
 }
 
@@ -480,8 +538,10 @@ print_hash_entries(int verbose)
             } else if (nffs_hash_id_is_block(he->nhe_id)) {
                 print_nffs_hash_block(he, verbose);
             } else {
-                printf("UNKNOWN type hash entry %d: id 0x%x loc 0x%x\n",
-                       i, he->nhe_id, he->nhe_flash_loc);
+                printf("UNKNOWN type hash entry %d: id 0x%jx loc 0x%jx\n",
+                       i,
+                       (uintmax_t)he->nhe_id,
+                       (uintmax_t)he->nhe_flash_loc);
             }
             he = next;
         }
@@ -501,8 +561,10 @@ print_nffs_hashlist(int verbose)
         } else if (nffs_hash_id_is_block(he->nhe_id)) {
             print_nffs_hash_block(he, verbose);
         } else {
-            printf("UNKNOWN type hash entry %d: id 0x%x loc 0x%x\n",
-                   i, he->nhe_id, he->nhe_flash_loc);
+            printf("UNKNOWN type hash entry %d: id 0x%jx loc 0x%jx\n",
+                   i,
+                   (uintmax_t)he->nhe_id,
+                   (uintmax_t)he->nhe_flash_loc);
         }
     }
 }


[20/50] incubator-mynewt-core git commit: nimble/l2cap: Refactor handling L2CAP reject command

Posted by ma...@apache.org.
nimble/l2cap: Refactor handling L2CAP reject command

With this patch L2CAP reject command uses a new way of preparing
command and sending it


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/ba9de55a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ba9de55a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ba9de55a

Branch: refs/heads/master
Commit: ba9de55afb41bf1c1b837ae93041953aa2f59493
Parents: a443035
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Tue Feb 28 12:14:46 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 12:40:42 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_sig_cmd.c  | 40 +++++----------------------
 net/nimble/host/src/ble_l2cap_sig_priv.h |  1 +
 2 files changed, 8 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ba9de55a/net/nimble/host/src/ble_l2cap_sig_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig_cmd.c b/net/nimble/host/src/ble_l2cap_sig_cmd.c
index 189efd7..e6a7209 100644
--- a/net/nimble/host/src/ble_l2cap_sig_cmd.c
+++ b/net/nimble/host/src/ble_l2cap_sig_cmd.c
@@ -94,48 +94,22 @@ ble_l2cap_sig_hdr_write(void *payload, uint16_t len,
     BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_HDR_SZ);
     ble_l2cap_sig_hdr_swap(payload, src);
 }
-static void
-ble_l2cap_sig_reject_swap(struct ble_l2cap_sig_reject *dst,
-                          struct ble_l2cap_sig_reject *src)
-{
-    dst->reason = TOFROMLE16(src->reason);
-}
-
-static void
-ble_l2cap_sig_reject_write(void *payload, uint16_t len,
-                           struct ble_l2cap_sig_reject *src,
-                           void *data, int data_len)
-{
-    uint8_t *u8ptr;
-
-    BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_REJECT_MIN_SZ + data_len);
-
-    ble_l2cap_sig_reject_swap(payload, src);
-
-    u8ptr = payload;
-    u8ptr += BLE_L2CAP_SIG_REJECT_MIN_SZ;
-    memcpy(u8ptr, data, data_len);
-}
 
 int
 ble_l2cap_sig_reject_tx(uint16_t conn_handle, uint8_t id, uint16_t reason,
                         void *data, int data_len)
 {
-    struct ble_l2cap_sig_reject cmd;
+    struct ble_l2cap_sig_reject *cmd;
     struct os_mbuf *txom;
-    void *payload_buf;
-    int rc;
 
-    rc = ble_l2cap_sig_init_cmd(BLE_L2CAP_SIG_OP_REJECT, id,
-                                BLE_L2CAP_SIG_REJECT_MIN_SZ + data_len, &txom,
-                                &payload_buf);
-    if (rc != 0) {
-        return rc;
+    cmd = ble_l2cap_sig_cmd_get(BLE_L2CAP_SIG_OP_REJECT, id,
+                           sizeof(*cmd) + data_len, &txom);
+    if (!cmd) {
+        return BLE_HS_ENOMEM;
     }
 
-    cmd.reason = reason;
-    ble_l2cap_sig_reject_write(payload_buf, txom->om_len, &cmd,
-                               data, data_len);
+    cmd->reason = htole16(reason);
+    memcpy(cmd->data, data, data_len);
 
     STATS_INC(ble_l2cap_stats, sig_rx);
     return ble_l2cap_sig_tx(conn_handle, txom);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ba9de55a/net/nimble/host/src/ble_l2cap_sig_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig_priv.h b/net/nimble/host/src/ble_l2cap_sig_priv.h
index f089dcb..ad3b846 100644
--- a/net/nimble/host/src/ble_l2cap_sig_priv.h
+++ b/net/nimble/host/src/ble_l2cap_sig_priv.h
@@ -39,6 +39,7 @@ struct ble_l2cap_sig_hdr {
 #define BLE_L2CAP_SIG_REJECT_MIN_SZ         2
 struct ble_l2cap_sig_reject {
     uint16_t reason;
+    uint8_t data[0];
 } __attribute__((packed));
 
 #define BLE_L2CAP_SIG_UPDATE_REQ_SZ         8


[50/50] incubator-mynewt-core git commit: Bringing in changes from develop branch.

Posted by ma...@apache.org.
Bringing in changes from develop branch.

Merge branch 'develop' of https://git-wip-us.apache.org/repos/asf/incubator-mynewt-core


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/cfe42df7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/cfe42df7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/cfe42df7

Branch: refs/heads/master
Commit: cfe42df79dfe5899ac39d8785ef8ab3862632b5e
Parents: 8cf8f54 c3b4174
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Mar 6 12:45:14 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Mar 6 12:45:14 2017 -0800

----------------------------------------------------------------------
 .rat-excludes                                   |    59 +-
 LICENSE                                         |   144 +-
 NOTICE                                          |     2 +-
 README.md                                       |    27 +-
 apps/blecent/pkg.yml                            |     4 +-
 apps/blecent/src/blecent.h                      |    12 +-
 apps/blecent/src/main.c                         |    95 +-
 apps/blecent/src/misc.c                         |    60 +-
 apps/blecent/src/peer.c                         |    20 +-
 apps/blecent/syscfg.yml                         |     3 +
 apps/blehci/pkg.yml                             |     2 +-
 apps/blehci/src/main.c                          |     9 +-
 apps/blehci/syscfg.yml                          |    23 +
 apps/bleprph/pkg.yml                            |     7 +-
 apps/bleprph/src/bleprph.h                      |     1 +
 apps/bleprph/src/gatt_svr.c                     |   172 +-
 apps/bleprph/src/main.c                         |   102 +-
 apps/bleprph/syscfg.yml                         |     3 +
 apps/bleprph_oic/pkg.yml                        |     4 +-
 apps/bleprph_oic/src/gatt_svr.c                 |    79 +-
 apps/bleprph_oic/src/main.c                     |   196 +-
 apps/bleprph_oic/syscfg.yml                     |    14 +-
 apps/blesplit/README.md                         |    55 +
 apps/blesplit/pkg.yml                           |    44 +
 apps/blesplit/src/blesplit.h                    |    59 +
 apps/blesplit/src/main.c                        |   287 +
 apps/blesplit/src/misc.c                        |    43 +
 apps/blesplit/syscfg.yml                        |    47 +
 apps/bletest/pkg.yml                            |     4 +-
 apps/bletest/src/bletest_hci.c                  |   191 +-
 apps/bletest/src/bletest_priv.h                 |    20 +-
 apps/bletest/src/main.c                         |   345 +-
 apps/bletest/syscfg.yml                         |    13 +-
 apps/bletiny/pkg.yml                            |     7 +-
 apps/bletiny/src/bletiny.h                      |    44 +-
 apps/bletiny/src/cmd.c                          |  1528 +-
 apps/bletiny/src/gatt_svr.c                     |   527 +-
 apps/bletiny/src/main.c                         |   510 +-
 apps/bletiny/src/misc.c                         |    36 +-
 apps/bletiny/src/parse.c                        |   127 +-
 apps/bletiny/syscfg.yml                         |     6 +-
 apps/bleuart/pkg.yml                            |     3 +-
 apps/bleuart/src/main.c                         |    62 +-
 apps/bleuart/syscfg.yml                         |     3 +
 apps/boot/pkg.yml                               |     2 +-
 apps/boot/src/boot.c                            |    20 +-
 apps/boot/syscfg.yml                            |     9 +-
 apps/fat2native/pkg.yml                         |    33 +
 apps/fat2native/src/main.c                      |   157 +
 apps/ffs2native/pkg.yml                         |     2 +
 apps/ocf_sample/pkg.yml                         |     4 +-
 apps/ocf_sample/src/main.c                      |   178 +-
 apps/ocf_sample/src/ocf_ble.c                   |    13 +-
 apps/ocf_sample/syscfg.yml                      |     2 +
 apps/sensors_test/pkg.yml                       |    51 +
 apps/sensors_test/src/main.c                    |   439 +
 apps/sensors_test/syscfg.yml                    |    57 +
 apps/slinky/pkg.yml                             |     6 +-
 apps/slinky/src/main.c                          |    62 +-
 apps/slinky_oic/pkg.yml                         |     6 +-
 apps/slinky_oic/src/main.c                      |    61 +-
 apps/slinky_oic/syscfg.yml                      |     3 +
 apps/spitest/pkg.yml                            |     4 +-
 apps/spitest/src/main.c                         |    46 +-
 apps/spitest/syscfg.yml                         |     3 +
 apps/splitty/pkg.yml                            |    15 +-
 apps/splitty/src/main.c                         |    55 +-
 apps/testbench/pkg.yml                          |    58 +
 apps/testbench/src/testbench.c                  |   386 +
 apps/testbench/src/testbench.h                  |   174 +
 apps/testbench/src/testbench_json.c             |    82 +
 apps/testbench/src/testbench_mempool.c          |    98 +
 apps/testbench/src/testbench_mutex.c            |   172 +
 apps/testbench/src/testbench_sem.c              |   141 +
 apps/testbench/syscfg.yml                       |    54 +
 apps/timtest/pkg.yml                            |     4 +-
 apps/timtest/src/main.c                         |    45 +-
 boot/boot_serial/pkg.yml                        |    10 +-
 boot/boot_serial/src/boot_serial.c              |   248 +-
 boot/boot_serial/src/boot_serial_priv.h         |    16 +-
 .../src/testcases/boot_serial_empty_img_msg.c   |     2 +-
 .../test/src/testcases/boot_serial_img_msg.c    |     2 +-
 .../testcases/boot_serial_upload_bigger_image.c |     2 +-
 boot/bootutil/design.txt                        |   791 +-
 boot/bootutil/include/bootutil/bootutil.h       |    15 +-
 boot/bootutil/include/bootutil/image.h          |    30 +-
 boot/bootutil/pkg.yml                           |     3 +
 boot/bootutil/signed_images.md                  |    18 +-
 boot/bootutil/src/bootutil_misc.c               |    65 +-
 boot/bootutil/src/bootutil_priv.h               |     4 +-
 boot/bootutil/src/image_ec.c                    |     5 +-
 boot/bootutil/src/image_ec256.c                 |   179 +
 boot/bootutil/src/image_rsa.c                   |     2 +
 boot/bootutil/src/image_validate.c              |    20 +-
 boot/bootutil/src/loader.c                      |   237 +-
 boot/bootutil/syscfg.yml                        |     7 +-
 boot/bootutil/test/src/boot_test.c              |     4 +
 boot/bootutil/test/src/boot_test.h              |     2 +
 boot/bootutil/test/src/boot_test_utils.c        |    39 +-
 .../test/src/testcases/boot_test_invalid_hash.c |     2 +-
 .../src/testcases/boot_test_no_flag_has_hash.c  |     2 +-
 .../test/src/testcases/boot_test_no_hash.c      |     2 +-
 .../test/src/testcases/boot_test_nv_bs_11.c     |     2 +-
 .../src/testcases/boot_test_nv_bs_11_2areas.c   |     2 +-
 .../test/src/testcases/boot_test_nv_ns_01.c     |     2 +-
 .../test/src/testcases/boot_test_permanent.c    |    53 +
 .../testcases/boot_test_permanent_continue.c    |    62 +
 .../test/src/testcases/boot_test_vb_ns_11.c     |     2 +-
 .../test/src/testcases/boot_test_vm_ns_01.c     |     2 +-
 .../src/testcases/boot_test_vm_ns_11_2areas.c   |     2 +-
 .../test/src/testcases/boot_test_vm_ns_11_b.c   |     2 +-
 boot/split/pkg.yml                              |     4 +-
 boot/split/src/split.c                          |    11 +-
 boot/split_app/pkg.yml                          |    29 +
 boot/split_app/src/split_app.c                  |    54 +
 compiler/arm-none-eabi-m0/compiler.yml          |     6 +-
 compiler/arm-none-eabi-m4/compiler.yml          |     8 +-
 compiler/arm-none-eabi-m4/syscfg.yml            |     4 +
 compiler/gdbmacros/ble.gdb                      |    52 +
 compiler/gdbmacros/mbuf.gdb                     |   200 +
 compiler/gdbmacros/os.gdb                       |    38 +
 compiler/gdbmacros/queue.gdb                    |    71 +
 compiler/mips/compiler.yml                      |     4 +-
 compiler/sim-mips/compiler.yml                  |     3 +-
 compiler/sim/compiler.yml                       |     7 +-
 crypto/mbedtls/pkg.yml                          |     2 +-
 crypto/tinycrypt/LICENSE                        |    62 +
 crypto/tinycrypt/README                         |    82 +-
 crypto/tinycrypt/VERSION                        |     1 +
 crypto/tinycrypt/include/tinycrypt/aes.h        |    16 +-
 crypto/tinycrypt/include/tinycrypt/cbc_mode.h   |     8 +-
 crypto/tinycrypt/include/tinycrypt/ccm_mode.h   |    12 +-
 crypto/tinycrypt/include/tinycrypt/cmac_mode.h  |    20 +-
 crypto/tinycrypt/include/tinycrypt/constants.h  |     4 +
 crypto/tinycrypt/include/tinycrypt/ctr_mode.h   |     4 +-
 crypto/tinycrypt/include/tinycrypt/ctr_prng.h   |   167 +
 crypto/tinycrypt/include/tinycrypt/ecc.h        |     8 +-
 crypto/tinycrypt/include/tinycrypt/ecc_dh.h     |    14 +-
 crypto/tinycrypt/include/tinycrypt/ecc_dsa.h    |     8 +-
 crypto/tinycrypt/include/tinycrypt/hmac.h       |    16 +-
 crypto/tinycrypt/include/tinycrypt/hmac_prng.h  |    12 +-
 crypto/tinycrypt/include/tinycrypt/sha256.h     |    12 +-
 crypto/tinycrypt/include/tinycrypt/utils.h      |     8 +-
 crypto/tinycrypt/src/aes_decrypt.c              |     8 +-
 crypto/tinycrypt/src/aes_encrypt.c              |    14 +-
 crypto/tinycrypt/src/cbc_mode.c                 |     8 +-
 crypto/tinycrypt/src/ccm_mode.c                 |    30 +-
 crypto/tinycrypt/src/cmac_mode.c                |    28 +-
 crypto/tinycrypt/src/ctr_mode.c                 |     6 +-
 crypto/tinycrypt/src/ctr_prng.c                 |   308 +
 crypto/tinycrypt/src/hmac.c                     |    24 +-
 crypto/tinycrypt/src/hmac_prng.c                |    16 +-
 crypto/tinycrypt/src/sha256.c                   |    18 +-
 crypto/tinycrypt/src/utils.c                    |     2 +-
 encoding/base64/include/base64/hex.h            |     2 +-
 encoding/base64/src/hex.c                       |     2 +-
 encoding/cborattr/include/cborattr/cborattr.h   |    35 +-
 encoding/cborattr/src/cborattr.c                |   402 +-
 encoding/cborattr/test/pkg.yml                  |    31 +
 encoding/cborattr/test/src/test_cborattr.c      |    48 +
 encoding/cborattr/test/src/test_cborattr.h      |    57 +
 .../cborattr/test/src/test_cborattr_utils.c     |    35 +
 .../test/src/testcases/cborattr_decode1.c       |    83 +
 .../src/testcases/cborattr_decode_bool_array.c  |   101 +
 .../src/testcases/cborattr_decode_int_array.c   |   143 +
 .../src/testcases/cborattr_decode_obj_array.c   |   109 +
 .../test/src/testcases/cborattr_decode_object.c |   198 +
 .../testcases/cborattr_decode_object_array.c    |   126 +
 .../src/testcases/cborattr_decode_partial.c     |    47 +
 .../test/src/testcases/cborattr_decode_simple.c |   123 +
 .../testcases/cborattr_decode_string_array.c    |   135 +
 .../testcases/cborattr_decode_unnamed_array.c   |    99 +
 encoding/json/test/src/test_json.h              |     7 +-
 encoding/json/test/src/test_json_utils.c        |     6 +-
 .../tinycbor/include/tinycbor/cbor_buf_reader.h |     4 +-
 .../tinycbor/include/tinycbor/cbor_buf_writer.h |    12 +-
 .../include/tinycbor/cbor_mbuf_reader.h         |    14 +-
 .../include/tinycbor/cbor_mbuf_writer.h         |     9 +-
 encoding/tinycbor/pkg.yml                       |     4 +-
 encoding/tinycbor/src/cbor_buf_reader.c         |    25 +-
 encoding/tinycbor/src/cbor_buf_writer.c         |    16 +-
 encoding/tinycbor/src/cbor_mbuf_reader.c        |    55 +-
 encoding/tinycbor/src/cbor_mbuf_writer.c        |    11 +-
 encoding/tinycbor/src/cborencoder.c             |    12 +-
 .../src/cborencoder_close_container_checked.c   |    10 +-
 encoding/tinycbor/src/cborerrorstrings.c        |     2 +-
 encoding/tinycbor/src/cborparser.c              |    10 +-
 encoding/tinycbor/src/cborparser_dup_string.c   |     2 +-
 encoding/tinycbor/src/cborpretty.c              |     6 +-
 encoding/tinycbor/src/cbortojson.c              |     8 +-
 encoding/tinycbor/src/open_memstream.c          |     2 +-
 fs/disk/include/disk/disk.h                     |    56 +
 fs/disk/pkg.yml                                 |    27 +
 fs/disk/src/disk.c                              |   151 +
 fs/fatfs/include/fatfs/diskio.h                 |    80 +
 fs/fatfs/include/fatfs/ff.h                     |   366 +
 fs/fatfs/include/fatfs/ffconf.h                 |   267 +
 fs/fatfs/include/fatfs/integer.h                |    38 +
 fs/fatfs/pkg.yml                                |    40 +
 fs/fatfs/src/00history.txt                      |   279 +
 fs/fatfs/src/00readme.txt                       |    21 +
 fs/fatfs/src/ff.c                               |  6040 +++++++
 fs/fatfs/src/mynewt_glue.c                      |   580 +
 fs/fatfs/src/option/unicode.c                   |    17 +
 fs/fcb/include/fcb/fcb.h                        |     6 +-
 fs/fcb/src/fcb.c                                |    34 +-
 fs/fcb/test/src/fcb_test.c                      |     7 +-
 fs/fcb/test/src/testcases/fcb_test_init.c       |     5 +
 fs/fcb/test/src/testcases/fcb_test_last_of_n.c  |    84 +
 fs/fs/include/fs/fs.h                           |     5 +
 fs/fs/include/fs/fs_if.h                        |    37 +-
 fs/fs/pkg.yml                                   |     3 +
 fs/fs/src/fs_dirent.c                           |    29 +-
 fs/fs/src/fs_file.c                             |   180 +-
 fs/fs/src/fs_mkdir.c                            |     8 +-
 fs/fs/src/fs_mount.c                            |    75 +-
 fs/fs/src/fs_nmgr.c                             |   253 +
 fs/fs/src/fs_priv.h                             |     7 +-
 fs/fs/src/fsutil.c                              |     4 +-
 fs/fs/syscfg.yml                                |     6 +-
 fs/nffs/pkg.yml                                 |     9 +-
 fs/nffs/src/nffs.c                              |    27 +-
 fs/nffs/src/nffs_dir.c                          |     5 +
 fs/nffs/src/nffs_file.c                         |     4 +
 fs/nffs/src/nffs_misc.c                         |     4 +-
 fs/nffs/src/nffs_priv.h                         |     3 +
 fs/nffs/syscfg.yml                              |     4 +-
 fs/nffs/test/pkg.yml                            |     2 +
 fs/nffs/test/src/nffs_test_debug.c              |   274 +-
 .../ada_feather_nrf52_debug.cmd                 |     3 +
 .../ada_feather_nrf52_debug.sh                  |    46 +
 .../ada_feather_nrf52_download.cmd              |     3 +
 .../ada_feather_nrf52_download.sh               |    40 +
 .../ada_feather_nrf52_no_boot.ld                |   191 +
 hw/bsp/ada_feather_nrf52/boot-nrf52xxaa.ld      |    25 +
 hw/bsp/ada_feather_nrf52/bsp.yml                |    64 +
 hw/bsp/ada_feather_nrf52/include/bsp/bsp.h      |    64 +
 .../ada_feather_nrf52/include/bsp/cmsis_nvic.h  |    29 +
 hw/bsp/ada_feather_nrf52/nrf52xxaa.ld           |    25 +
 hw/bsp/ada_feather_nrf52/pkg.yml                |    96 +
 .../split_ada_feather_nrf52.ld                  |   208 +
 .../src/arch/cortex_m4/gcc_startup_nrf52.s      |   299 +
 .../arch/cortex_m4/gcc_startup_nrf52_split.s    |   163 +
 hw/bsp/ada_feather_nrf52/src/hal_bsp.c          |   216 +
 hw/bsp/ada_feather_nrf52/src/sbrk.c             |    59 +
 hw/bsp/ada_feather_nrf52/syscfg.yml             |   101 +
 hw/bsp/arduino_primo_nrf52/bsp.yml              |     2 +
 hw/bsp/arduino_primo_nrf52/include/bsp/bsp.h    |     4 +-
 hw/bsp/arduino_primo_nrf52/pkg.yml              |     5 +-
 hw/bsp/arduino_primo_nrf52/primo_debug.cmd      |     3 +
 hw/bsp/arduino_primo_nrf52/primo_debug.sh       |     3 +-
 hw/bsp/arduino_primo_nrf52/primo_download.cmd   |     3 +
 hw/bsp/arduino_primo_nrf52/split-primo.ld       |     4 +-
 .../src/arch/cortex_m4/gcc_startup_nrf52.s      |    10 +
 .../arch/cortex_m4/gcc_startup_nrf52_split.s    |    15 +-
 hw/bsp/arduino_primo_nrf52/src/hal_bsp.c        |    15 +-
 hw/bsp/arduino_primo_nrf52/syscfg.yml           |    53 +-
 hw/bsp/bbc_microbit/boot-nrf51xxac.ld           |    27 +
 hw/bsp/bbc_microbit/bsp.yml                     |    64 +
 hw/bsp/bbc_microbit/include/bsp/bsp.h           |    50 +
 hw/bsp/bbc_microbit/include/bsp/cmsis_nvic.h    |    30 +
 hw/bsp/bbc_microbit/microbit_debug.cmd          |     3 +
 hw/bsp/bbc_microbit/microbit_debug.sh           |    37 +
 hw/bsp/bbc_microbit/microbit_download.cmd       |     3 +
 hw/bsp/bbc_microbit/microbit_download.sh        |    42 +
 hw/bsp/bbc_microbit/nrf51xxac.ld                |    30 +
 hw/bsp/bbc_microbit/pkg.yml                     |    88 +
 hw/bsp/bbc_microbit/split-microbit.ld           |   185 +
 .../src/arch/cortex_m0/gcc_startup_nrf51.s      |   280 +
 .../arch/cortex_m0/gcc_startup_nrf51_split.s    |   182 +
 hw/bsp/bbc_microbit/src/hal_bsp.c               |   176 +
 hw/bsp/bbc_microbit/src/sbrk.c                  |    57 +
 hw/bsp/bbc_microbit/syscfg.yml                  |    74 +
 hw/bsp/bmd200/boot-nrf51xxac.ld                 |    27 +
 hw/bsp/bmd200/bsp.yml                           |    64 +
 hw/bsp/bmd200/include/bsp/boards.h              |    19 +
 hw/bsp/bmd200/include/bsp/bsp.h                 |    53 +
 hw/bsp/bmd200/include/bsp/cmsis_nvic.h          |    30 +
 hw/bsp/bmd200/nrf51dk_debug.cmd                 |     3 +
 hw/bsp/bmd200/nrf51dk_debug.sh                  |    36 +
 hw/bsp/bmd200/nrf51dk_download.cmd              |     3 +
 hw/bsp/bmd200/nrf51dk_download.sh               |    41 +
 hw/bsp/bmd200/nrf51dk_no_boot.ld                |   179 +
 hw/bsp/bmd200/nrf51xxac.ld                      |    25 +
 hw/bsp/bmd200/pkg.yml                           |    90 +
 hw/bsp/bmd200/split-nrf51dk.ld                  |   185 +
 .../src/arch/cortex_m0/gcc_startup_nrf51.s      |   280 +
 .../arch/cortex_m0/gcc_startup_nrf51_split.s    |   182 +
 hw/bsp/bmd200/src/hal_bsp.c                     |   189 +
 hw/bsp/bmd200/src/sbrk.c                        |    59 +
 hw/bsp/bmd200/syscfg.yml                        |    96 +
 hw/bsp/bmd300eval/bmd300eval_debug.cmd          |     3 +
 hw/bsp/bmd300eval/bmd300eval_download.cmd       |     3 +
 hw/bsp/bmd300eval/bsp.yml                       |     2 +
 hw/bsp/bmd300eval/pkg.yml                       |     6 +-
 hw/bsp/bmd300eval/split-bmd300eval.ld           |     4 +-
 .../src/arch/cortex_m4/gcc_startup_nrf52.s      |    10 +
 .../arch/cortex_m4/gcc_startup_nrf52_split.s    |    15 +-
 hw/bsp/bmd300eval/src/hal_bsp.c                 |    15 +-
 hw/bsp/bmd300eval/syscfg.yml                    |    29 +-
 hw/bsp/ci40/bsp.yml                             |     4 +-
 hw/bsp/ci40/pkg.yml                             |     6 +
 hw/bsp/ci40/syscfg.yml                          |    25 +-
 hw/bsp/frdm-k64f/bsp.yml                        |     2 +
 hw/bsp/frdm-k64f/frdm-k64_debug.cmd             |     3 +
 hw/bsp/frdm-k64f/frdm-k64_debug.sh              |     1 +
 hw/bsp/frdm-k64f/frdm-k64_download.cmd          |     3 +
 hw/bsp/frdm-k64f/frdm-k64_download.sh           |     2 +-
 hw/bsp/frdm-k64f/pkg.yml                        |    19 +-
 hw/bsp/frdm-k64f/src/hal_bsp.c                  |     4 +
 hw/bsp/frdm-k64f/syscfg.yml                     |    62 +-
 hw/bsp/native/pkg.yml                           |     2 -
 hw/bsp/nrf51-arduino_101/bsp.yml                |     2 +
 .../nrf51-arduino_101/nrf51dk-16kbram_debug.cmd |     3 +
 .../nrf51dk-16kbram_download.cmd                |     3 +
 hw/bsp/nrf51-arduino_101/pkg.yml                |     3 -
 .../src/arch/cortex_m0/gcc_startup_nrf51.s      |    12 +-
 hw/bsp/nrf51-arduino_101/src/hal_bsp.c          |    13 +-
 hw/bsp/nrf51-arduino_101/syscfg.yml             |    34 +-
 hw/bsp/nrf51-blenano/bsp.yml                    |     2 +
 hw/bsp/nrf51-blenano/nrf51dk_debug.cmd          |     3 +
 hw/bsp/nrf51-blenano/nrf51dk_debug.sh           |     3 +-
 hw/bsp/nrf51-blenano/nrf51dk_download.cmd       |     3 +
 hw/bsp/nrf51-blenano/pkg.yml                    |     2 -
 .../src/arch/cortex_m0/gcc_startup_nrf51.s      |    12 +-
 .../arch/cortex_m0/gcc_startup_nrf51_split.s    |    20 +-
 hw/bsp/nrf51-blenano/src/hal_bsp.c              |    16 +-
 hw/bsp/nrf51-blenano/syscfg.yml                 |    31 +-
 hw/bsp/nrf51dk-16kbram/bsp.yml                  |     2 +
 .../nrf51dk-16kbram/nrf51dk-16kbram_debug.cmd   |     3 +
 .../nrf51dk-16kbram_download.cmd                |     3 +
 hw/bsp/nrf51dk-16kbram/pkg.yml                  |     2 -
 hw/bsp/nrf51dk-16kbram/split-nrf51dk-16kbram.ld |     2 +-
 .../src/arch/cortex_m0/gcc_startup_nrf51.s      |    14 +-
 .../arch/cortex_m0/gcc_startup_nrf51_split.s    |    19 +-
 hw/bsp/nrf51dk-16kbram/src/hal_bsp.c            |    13 +-
 hw/bsp/nrf51dk-16kbram/syscfg.yml               |    31 +-
 hw/bsp/nrf51dk/bsp.yml                          |     2 +
 hw/bsp/nrf51dk/nrf51dk_debug.cmd                |     3 +
 hw/bsp/nrf51dk/nrf51dk_download.cmd             |     3 +
 hw/bsp/nrf51dk/pkg.yml                          |     2 -
 hw/bsp/nrf51dk/split-nrf51dk.ld                 |     4 +-
 .../src/arch/cortex_m0/gcc_startup_nrf51.s      |    12 +-
 .../arch/cortex_m0/gcc_startup_nrf51_split.s    |    18 +-
 hw/bsp/nrf51dk/src/hal_bsp.c                    |    14 +-
 hw/bsp/nrf51dk/syscfg.yml                       |    31 +-
 hw/bsp/nrf52840pdk/boot-nrf52840aa.ld           |    26 +
 hw/bsp/nrf52840pdk/bsp.yml                      |    64 +
 hw/bsp/nrf52840pdk/include/bsp/boards.h         |    19 +
 hw/bsp/nrf52840pdk/include/bsp/bsp.h            |    53 +
 hw/bsp/nrf52840pdk/include/bsp/cmsis_nvic.h     |    29 +
 hw/bsp/nrf52840pdk/nrf52840aa.ld                |    26 +
 hw/bsp/nrf52840pdk/nrf52840pdk_debug.cmd        |     3 +
 hw/bsp/nrf52840pdk/nrf52840pdk_debug.sh         |    46 +
 hw/bsp/nrf52840pdk/nrf52840pdk_download.cmd     |     3 +
 hw/bsp/nrf52840pdk/nrf52840pdk_download.sh      |    40 +
 hw/bsp/nrf52840pdk/nrf52840pdk_no_boot.ld       |   191 +
 hw/bsp/nrf52840pdk/pkg.yml                      |    97 +
 hw/bsp/nrf52840pdk/split-nrf52840pdk.ld         |   204 +
 .../src/arch/cortex_m4/gcc_startup_nrf52840.s   |   322 +
 .../arch/cortex_m4/gcc_startup_nrf52_split.s    |   164 +
 hw/bsp/nrf52840pdk/src/hal_bsp.c                |   209 +
 hw/bsp/nrf52840pdk/src/sbrk.c                   |    59 +
 hw/bsp/nrf52840pdk/syscfg.yml                   |    97 +
 hw/bsp/nrf52dk/bsp.yml                          |     2 +
 hw/bsp/nrf52dk/include/bsp/bsp.h                |    11 +
 hw/bsp/nrf52dk/nrf52dk_debug.cmd                |     3 +
 hw/bsp/nrf52dk/nrf52dk_download.cmd             |     3 +
 hw/bsp/nrf52dk/pkg.yml                          |     5 +-
 hw/bsp/nrf52dk/split-nrf52dk.ld                 |     4 +-
 .../src/arch/cortex_m4/gcc_startup_nrf52.s      |    12 +-
 .../arch/cortex_m4/gcc_startup_nrf52_split.s    |    15 +-
 hw/bsp/nrf52dk/src/hal_bsp.c                    |    23 +-
 hw/bsp/nrf52dk/syscfg.yml                       |    44 +-
 hw/bsp/nucleo-f401re/bsp.yml                    |     2 +
 hw/bsp/nucleo-f401re/nucleo-f401re_debug.cmd    |     3 +
 hw/bsp/nucleo-f401re/nucleo-f401re_debug.sh     |     2 +-
 hw/bsp/nucleo-f401re/nucleo-f401re_download.cmd |     3 +
 hw/bsp/nucleo-f401re/pkg.yml                    |     3 +
 .../src/arch/cortex_m4/startup_STM32F40x.s      |    10 +
 hw/bsp/nucleo-f401re/src/hal_bsp.c              |     4 +
 hw/bsp/nucleo-f401re/syscfg.yml                 |    18 +-
 hw/bsp/olimex_stm32-e407_devboard/bsp.yml       |     2 +
 .../olimex_stm32-e407_devboard_debug.cmd        |     3 +
 .../olimex_stm32-e407_devboard_debug.sh         |     2 +-
 .../olimex_stm32-e407_devboard_download.cmd     |     3 +
 hw/bsp/olimex_stm32-e407_devboard/pkg.yml       |     5 +-
 .../run_from_flash.ld                           |   204 -
 .../run_from_loader.ld                          |   210 -
 .../olimex_stm32-e407_devboard/run_from_sram.ld |   202 -
 .../src/arch/cortex_m4/startup_STM32F40x.s      |    10 +
 hw/bsp/olimex_stm32-e407_devboard/src/hal_bsp.c |    48 +-
 hw/bsp/olimex_stm32-e407_devboard/syscfg.yml    |    25 +-
 hw/bsp/rb-nano2/bsp.yml                         |     2 +
 hw/bsp/rb-nano2/pkg.yml                         |     5 +-
 hw/bsp/rb-nano2/rb-nano2_debug.cmd              |     3 +
 hw/bsp/rb-nano2/rb-nano2_debug.sh               |     3 +-
 hw/bsp/rb-nano2/rb-nano2_download.cmd           |     3 +
 hw/bsp/rb-nano2/split-rb-nano2.ld               |     4 +-
 .../src/arch/cortex_m4/gcc_startup_nrf52.s      |    10 +
 .../arch/cortex_m4/gcc_startup_nrf52_split.s    |    16 +-
 hw/bsp/rb-nano2/src/hal_bsp.c                   |    21 +-
 hw/bsp/rb-nano2/syscfg.yml                      |    35 +-
 hw/bsp/stm32f4discovery/bsp.yml                 |     2 +
 hw/bsp/stm32f4discovery/pkg.yml                 |     3 +
 hw/bsp/stm32f4discovery/run_from_flash.ld       |   204 -
 hw/bsp/stm32f4discovery/run_from_loader.ld      |   210 -
 hw/bsp/stm32f4discovery/run_from_sram.ld        |   202 -
 .../src/arch/cortex_m4/startup_STM32F40x.s      |    10 +
 hw/bsp/stm32f4discovery/src/hal_bsp.c           |     4 +
 .../stm32f4discovery/stm32f4discovery_debug.cmd |     3 +
 .../stm32f4discovery/stm32f4discovery_debug.sh  |     3 +-
 .../stm32f4discovery_download.cmd               |     3 +
 hw/bsp/stm32f4discovery/syscfg.yml              |     5 +-
 hw/bsp/usbmkw41z/boot-mkw41z512.ld              |   197 +
 hw/bsp/usbmkw41z/bsp.yml                        |    62 +
 hw/bsp/usbmkw41z/include/bsp/bsp.h              |    47 +
 hw/bsp/usbmkw41z/include/bsp/cmsis_nvic.h       |    42 +
 hw/bsp/usbmkw41z/mkw41z512.ld                   |   186 +
 hw/bsp/usbmkw41z/no-boot-mkw41z512.ld           |   197 +
 hw/bsp/usbmkw41z/pkg.yml                        |    35 +
 .../src/arch/cortex_m0/gcc_startup_mkw41z.s     |   240 +
 hw/bsp/usbmkw41z/src/hal_bsp.c                  |    88 +
 hw/bsp/usbmkw41z/src/sbrk.c                     |    59 +
 hw/bsp/usbmkw41z/syscfg.yml                     |    31 +
 hw/bsp/usbmkw41z/usbkw41z_debug.cmd             |     3 +
 hw/bsp/usbmkw41z/usbkw41z_debug.sh              |    36 +
 hw/bsp/usbmkw41z/usbkw41z_download.cmd          |     3 +
 hw/bsp/usbmkw41z/usbkw41z_download.sh           |    41 +
 hw/drivers/flash/at45db/pkg.yml                 |    27 +
 hw/drivers/flash/at45db/src/at45db.c            |   452 +
 hw/drivers/lwip/stm32f4_eth/src/stm32f4_eth.c   |    16 +-
 hw/drivers/mmc/include/mmc/mmc.h                |    97 +
 hw/drivers/mmc/pkg.yml                          |    27 +
 hw/drivers/mmc/src/mmc.c                        |   602 +
 hw/drivers/nimble/nrf51/src/ble_hw.c            |    12 +-
 hw/drivers/nimble/nrf51/src/ble_phy.c           |     8 +-
 hw/drivers/nimble/nrf52/src/ble_hw.c            |    12 +-
 hw/drivers/nimble/nrf52/src/ble_phy.c           |    10 +-
 .../sensors/bno055/include/bno055/bno055.h      |   410 +
 hw/drivers/sensors/bno055/pkg.yml               |    32 +
 hw/drivers/sensors/bno055/src/bno055.c          |  1495 ++
 hw/drivers/sensors/bno055/src/bno055_priv.h     |   223 +
 hw/drivers/sensors/bno055/src/bno055_shell.c    |   520 +
 hw/drivers/sensors/bno055/syscfg.yml            |    35 +
 .../lsm303dlhc/include/lsm303dlhc/lsm303dlhc.h  |    92 +
 hw/drivers/sensors/lsm303dlhc/pkg.yml           |    24 +
 hw/drivers/sensors/lsm303dlhc/src/lsm303dlhc.c  |   543 +
 .../sensors/lsm303dlhc/src/lsm303dlhc_priv.h    |    89 +
 hw/drivers/sensors/lsm303dlhc/syscfg.yml        |    32 +
 hw/drivers/sensors/sim/include/sim/sim_accel.h  |    50 +
 hw/drivers/sensors/sim/include/sim/sim_mag.h    |    50 +
 hw/drivers/sensors/sim/pkg.yml                  |    25 +
 hw/drivers/sensors/sim/src/generic_accel.c      |   178 +
 hw/drivers/sensors/sim/src/generic_mag.c        |   177 +
 .../sensors/tsl2561/include/tsl2561/tsl2561.h   |   201 +
 hw/drivers/sensors/tsl2561/pkg.yml              |    35 +
 hw/drivers/sensors/tsl2561/src/tsl2561.c        |   724 +
 hw/drivers/sensors/tsl2561/src/tsl2561_priv.h   |   146 +
 hw/drivers/sensors/tsl2561/src/tsl2561_shell.c  |   434 +
 hw/drivers/sensors/tsl2561/syscfg.yml           |    38 +
 hw/drivers/uart/uart_hal/src/uart_hal.c         |     2 +-
 hw/hal/include/hal/hal_flash.h                  |     2 +-
 hw/hal/include/hal/hal_flash_int.h              |    18 +-
 hw/hal/include/hal/hal_system.h                 |    19 +-
 hw/hal/src/hal_flash.c                          |    20 +-
 hw/mcu/mips/danube/syscfg.yml                   |    26 +
 hw/mcu/native/pkg.yml                           |     2 +-
 hw/mcu/native/src/hal_flash.c                   |    31 +-
 hw/mcu/native/src/hal_system.c                  |    24 +-
 hw/mcu/native/src/hal_uart.c                    |     2 +-
 hw/mcu/native/syscfg.yml                        |    26 +
 hw/mcu/nordic/nrf51xxx/nrf51.ld                 |     4 +-
 hw/mcu/nordic/nrf51xxx/src/hal_flash.c          |    28 +-
 hw/mcu/nordic/nrf51xxx/src/hal_i2c.c            |     4 +-
 hw/mcu/nordic/nrf51xxx/src/hal_os_tick.c        |    84 +-
 hw/mcu/nordic/nrf51xxx/src/hal_system.c         |    63 +
 hw/mcu/nordic/nrf51xxx/src/hal_system_start.c   |    27 +
 hw/mcu/nordic/nrf51xxx/src/hal_timer.c          |   239 +-
 hw/mcu/nordic/nrf51xxx/syscfg.yml               |    26 +
 hw/mcu/nordic/nrf52xxx/include/mcu/cortex_m4.h  |     5 +
 hw/mcu/nordic/nrf52xxx/include/mcu/mcu.h        |     6 +-
 hw/mcu/nordic/nrf52xxx/nrf52.ld                 |     4 +-
 hw/mcu/nordic/nrf52xxx/src/hal_flash.c          |    30 +-
 hw/mcu/nordic/nrf52xxx/src/hal_gpio.c           |    62 +-
 hw/mcu/nordic/nrf52xxx/src/hal_i2c.c            |     6 +-
 hw/mcu/nordic/nrf52xxx/src/hal_os_tick.c        |     2 +-
 hw/mcu/nordic/nrf52xxx/src/hal_spi.c            |     2 +-
 hw/mcu/nordic/nrf52xxx/src/hal_system_start.c   |    29 +-
 hw/mcu/nordic/nrf52xxx/src/hal_timer.c          |   287 +-
 hw/mcu/nordic/nrf52xxx/src/hal_watchdog.c       |     3 +-
 hw/mcu/nordic/nrf52xxx/src/nrf52_hw_id.c        |     4 +-
 hw/mcu/nordic/nrf52xxx/src/system_nrf52.c       |   175 +-
 hw/mcu/nordic/nrf52xxx/syscfg.yml               |    26 +
 .../components/device/nrf.h                     |    25 +-
 .../components/device/nrf51_to_nrf52840.h       |   567 +
 .../components/device/nrf52840.h                |  2417 +++
 .../components/device/nrf52840_bitfields.h      | 14633 +++++++++++++++++
 .../components/device/nrf52840_peripherals.h    |   240 +
 .../components/device/nrf52_to_nrf52840.h       |    88 +
 .../components/toolchain/system_nrf52840.c      |   209 +
 .../components/toolchain/system_nrf52840.h      |    69 +
 hw/mcu/nxp/MK64F12/src/hal_flash.c              |    85 +-
 hw/mcu/nxp/MK64F12/src/hal_uart.c               |   144 +-
 hw/mcu/nxp/MK64F12/syscfg.yml                   |    26 +
 hw/mcu/nxp/mkw41z/include/mcu/MKW41Z4.h         | 12979 +++++++++++++++
 .../nxp/mkw41z/include/mcu/MKW41Z4_features.h   |  1719 ++
 hw/mcu/nxp/mkw41z/include/mcu/cortex_m0.h       |    41 +
 .../mkw41z/include/mcu/fsl_device_registers.h   |    56 +
 hw/mcu/nxp/mkw41z/include/mcu/mcu.h             |    38 +
 hw/mcu/nxp/mkw41z/include/mcu/mkw41z_hal.h      |    46 +
 hw/mcu/nxp/mkw41z/include/mcu/system_MKW41Z4.h  |   133 +
 hw/mcu/nxp/mkw41z/pkg.yml                       |    31 +
 hw/mcu/nxp/mkw41z/src/hal_gpio.c                |   161 +
 hw/mcu/nxp/mkw41z/src/hal_os_tick.c             |   104 +
 hw/mcu/nxp/mkw41z/src/hal_system.c              |    37 +
 hw/mcu/nxp/mkw41z/src/hal_watchdog.c            |    41 +
 hw/mcu/nxp/mkw41z/src/system_MKW41Z4.c          |   179 +
 .../STM32F410Rx_User_Manual.chm                 |   Bin 7230602 -> 0 bytes
 .../STM32F411xE_User_Manual.chm                 |   Bin 7087370 -> 0 bytes
 .../STM32F412Zx_User_Manual.chm                 |   Bin 8611134 -> 0 bytes
 .../STM32F417xx_User_Manual.chm                 |   Bin 8705036 -> 0 bytes
 .../STM32F439xx_User_Manual.chm                 |   Bin 9575430 -> 0 bytes
 .../STM32F446xx_User_Manual.chm                 |   Bin 8999608 -> 0 bytes
 .../STM32F479xx_User_Manual.chm                 |   Bin 10186550 -> 0 bytes
 hw/mcu/stm/stm32f4xx/src/hal_flash.c            |    30 +-
 hw/mcu/stm/stm32f4xx/src/hal_gpio.c             |    33 +-
 hw/mcu/stm/stm32f4xx/stm32f401.ld               |     8 +-
 hw/mcu/stm/stm32f4xx/stm32f407.ld               |     8 +-
 hw/mcu/stm/stm32f4xx/syscfg.yml                 |    26 +
 hw/scripts/jlink.sh                             |    15 +-
 hw/scripts/openocd.sh                           |     2 +-
 hw/sensor/include/sensor/accel.h                |    49 +
 hw/sensor/include/sensor/euler.h                |    50 +
 hw/sensor/include/sensor/light.h                |    49 +
 hw/sensor/include/sensor/mag.h                  |    49 +
 hw/sensor/include/sensor/quat.h                 |    50 +
 hw/sensor/include/sensor/sensor.h               |   349 +
 hw/sensor/pkg.yml                               |    28 +
 hw/sensor/src/sensor.c                          |   573 +
 hw/sensor/src/sensor_priv.h                     |    29 +
 hw/sensor/src/sensor_shell.c                    |   355 +
 hw/sensor/syscfg.yml                            |    28 +
 kernel/os/include/os/endian.h                   |   159 +-
 kernel/os/include/os/os.h                       |     5 +-
 kernel/os/include/os/os_dev.h                   |     1 +
 kernel/os/include/os/os_eventq.h                |     6 +-
 kernel/os/include/os/os_fault.h                 |    34 +
 kernel/os/include/os/os_mbuf.h                  |     3 +-
 kernel/os/include/os/os_mempool.h               |     2 +
 kernel/os/include/os/os_sched.h                 |     2 +-
 kernel/os/include/os/os_task.h                  |     5 +-
 kernel/os/pkg.yml                               |     4 +-
 kernel/os/src/arch/cortex_m0/os_fault.c         |     5 +-
 kernel/os/src/arch/cortex_m4/m4/HAL_CM4.s       |    18 +-
 kernel/os/src/arch/cortex_m4/os_arch_arm.c      |    13 +
 kernel/os/src/arch/cortex_m4/os_fault.c         |    31 +-
 kernel/os/src/arch/mips/os_fault.c              |     5 +-
 kernel/os/src/arch/sim-mips/os_fault.c          |     9 +-
 kernel/os/src/arch/sim/os_fault.c               |     9 +-
 kernel/os/src/endian.c                          |   218 +
 kernel/os/src/os.c                              |    43 +-
 kernel/os/src/os_dev.c                          |    51 +-
 kernel/os/src/os_eventq.c                       |    81 +-
 kernel/os/src/os_heap.c                         |     8 +-
 kernel/os/src/os_mbuf.c                         |    82 +-
 kernel/os/src/os_mempool.c                      |    13 +
 kernel/os/src/os_msys_init.c                    |     1 +
 kernel/os/src/os_sched.c                        |    24 +-
 kernel/os/src/os_task.c                         |    19 +-
 kernel/os/src/os_time.c                         |     9 +
 kernel/os/syscfg.yml                            |    33 +-
 kernel/os/test/src/callout_test.c               |    14 +-
 kernel/os/test/src/callout_test.h               |    16 +-
 kernel/os/test/src/eventq_test.c                |     9 -
 kernel/os/test/src/eventq_test.h                |    28 +-
 kernel/os/test/src/mempool_test.c               |     1 +
 kernel/os/test/src/mutex_test.c                 |    52 +-
 kernel/os/test/src/os_test.c                    |    37 +-
 kernel/os/test/src/os_test_priv.h               |    20 +-
 kernel/os/test/src/sem_test.c                   |   118 +-
 .../test/src/testcases/event_test_poll_0timo.c  |     2 +-
 .../src/testcases/event_test_poll_single_sr.c   |    12 +-
 .../os/test/src/testcases/event_test_poll_sr.c  |    10 -
 .../src/testcases/event_test_poll_timeout_sr.c  |    14 +-
 kernel/os/test/src/testcases/event_test_src.c   |    12 +-
 kernel/os/test/src/testcases/os_callout_test.c  |    15 +-
 .../test/src/testcases/os_callout_test_speak.c  |    15 +-
 .../test/src/testcases/os_callout_test_stop.c   |    19 +-
 .../os/test/src/testcases/os_mutex_test_basic.c |     7 +-
 .../test/src/testcases/os_mutex_test_case_1.c   |    14 +-
 .../test/src/testcases/os_mutex_test_case_2.c   |    24 +-
 .../os/test/src/testcases/os_sem_test_basic.c   |     7 +-
 .../os/test/src/testcases/os_sem_test_case_1.c  |    13 +-
 .../os/test/src/testcases/os_sem_test_case_2.c  |    16 +-
 .../os/test/src/testcases/os_sem_test_case_3.c  |    16 +-
 .../os/test/src/testcases/os_sem_test_case_4.c  |    16 +-
 libc/baselibc/include/assert.h                  |     2 +-
 libc/baselibc/pkg.yml                           |     3 +-
 libc/baselibc/src/start.c                       |    45 +
 mgmt/imgmgr/include/imgmgr/imgmgr.h             |    18 +-
 mgmt/imgmgr/pkg.yml                             |     4 +-
 mgmt/imgmgr/src/imgmgr.c                        |    58 +-
 mgmt/imgmgr/src/imgmgr_cli.c                    |   121 +-
 mgmt/imgmgr/src/imgmgr_coredump.c               |    70 +-
 mgmt/imgmgr/src/imgmgr_fs.c                     |   233 -
 mgmt/imgmgr/src/imgmgr_priv.h                   |     9 -
 mgmt/imgmgr/src/imgmgr_state.c                  |    90 +-
 mgmt/imgmgr/syscfg.yml                          |     7 +-
 mgmt/mgmt/include/mgmt/mgmt.h                   |    27 +-
 mgmt/mgmt/src/mgmt.c                            |    22 +-
 mgmt/newtmgr/include/newtmgr/newtmgr.h          |    28 +-
 mgmt/newtmgr/nmgr_os/pkg.yml                    |     5 +-
 mgmt/newtmgr/nmgr_os/src/newtmgr_os.c           |   144 +-
 mgmt/newtmgr/nmgr_os/syscfg.yml                 |    23 +
 mgmt/newtmgr/pkg.yml                            |     5 +-
 mgmt/newtmgr/src/newtmgr.c                      |   197 +-
 mgmt/newtmgr/syscfg.yml                         |    24 -
 mgmt/newtmgr/transport/ble/pkg.yml              |     4 +-
 mgmt/newtmgr/transport/ble/src/newtmgr_ble.c    |    22 +-
 mgmt/newtmgr/transport/nmgr_shell/pkg.yml       |     4 +-
 .../transport/nmgr_shell/src/nmgr_shell.c       |     5 +
 mgmt/newtmgr/transport/nmgr_uart/pkg.yml        |     5 +-
 .../newtmgr/transport/nmgr_uart/src/nmgr_uart.c |    48 +-
 mgmt/newtmgr/transport/nmgr_uart/syscfg.yml     |     2 +-
 mgmt/oicmgr/pkg.yml                             |     9 +-
 mgmt/oicmgr/src/oicmgr.c                        |   274 +-
 net/ip/mn_socket/include/mn_socket/mn_socket.h  |     2 +-
 net/ip/mn_socket/test/src/mn_sock_util.c        |     1 +
 .../mn_socket/test/src/testcases/socket_tests.c |     1 +
 net/ip/native_sockets/pkg.yml                   |     4 +-
 net/ip/native_sockets/src/native_sock.c         |     4 +
 .../controller/include/controller/ble_ll_adv.h  |    46 +-
 .../controller/include/controller/ble_ll_conn.h |     7 +-
 .../controller/include/controller/ble_ll_hci.h  |     4 +-
 .../include/controller/ble_ll_sched.h           |    25 +-
 net/nimble/controller/pkg.yml                   |     6 +-
 net/nimble/controller/src/ble_ll.c              |    23 +-
 net/nimble/controller/src/ble_ll_adv.c          |   506 +-
 net/nimble/controller/src/ble_ll_conn.c         |   171 +-
 net/nimble/controller/src/ble_ll_conn_hci.c     |   125 +-
 net/nimble/controller/src/ble_ll_conn_priv.h    |    10 +-
 net/nimble/controller/src/ble_ll_ctrl.c         |   116 +-
 net/nimble/controller/src/ble_ll_hci.c          |   153 +-
 net/nimble/controller/src/ble_ll_hci_ev.c       |    44 +-
 net/nimble/controller/src/ble_ll_resolv.c       |    21 +-
 net/nimble/controller/src/ble_ll_scan.c         |     8 +-
 net/nimble/controller/src/ble_ll_sched.c        |   186 +-
 net/nimble/controller/syscfg.yml                |    46 +-
 net/nimble/host/include/host/ble_gap.h          |    64 +-
 net/nimble/host/include/host/ble_gatt.h         |    53 +-
 net/nimble/host/include/host/ble_hs.h           |     5 +-
 net/nimble/host/include/host/ble_hs_adv.h       |    64 +-
 net/nimble/host/include/host/ble_hs_id.h        |     3 +-
 net/nimble/host/include/host/ble_l2cap.h        |   115 +
 net/nimble/host/include/host/ble_sm.h           |     1 +
 net/nimble/host/include/host/ble_store.h        |    26 +-
 net/nimble/host/include/host/ble_uuid.h         |    92 +-
 net/nimble/host/pkg.yml                         |    13 +-
 net/nimble/host/profiles/lls/src/ble_svc_lls.c  |     4 +-
 net/nimble/host/pts/README.txt                  |     8 +
 net/nimble/host/pts/pts-gap.txt                 |   370 +
 net/nimble/host/pts/pts-gatt.txt                |   530 +
 net/nimble/host/pts/pts-l2cap.txt               |   223 +
 net/nimble/host/pts/pts-sm.txt                  |   149 +
 .../host/pts/tpg/90359-20161220-172100175.tpg   |  1022 ++
 .../host/pts/tpg/90359-20161220-172113981.pts   |   288 +
 net/nimble/host/services/ans/pkg.yml            |     4 +-
 net/nimble/host/services/ans/src/ble_svc_ans.c  |    17 +-
 .../services/bleuart/include/bleuart/bleuart.h  |     2 +-
 net/nimble/host/services/bleuart/pkg.yml        |     4 +-
 net/nimble/host/services/bleuart/src/bleuart.c  |    31 +-
 net/nimble/host/services/bleuart/syscfg.yml     |     4 +-
 net/nimble/host/services/gap/pkg.yml            |     4 +-
 net/nimble/host/services/gap/src/ble_svc_gap.c  |    19 +-
 .../gatt/include/services/gatt/ble_svc_gatt.h   |     3 +
 net/nimble/host/services/gatt/pkg.yml           |     4 +-
 .../host/services/gatt/src/ble_svc_gatt.c       |    39 +-
 net/nimble/host/services/ias/pkg.yml            |     4 +-
 net/nimble/host/services/ias/src/ble_svc_ias.c  |     7 +-
 net/nimble/host/services/lls/src/ble_svc_lls.c  |     4 +-
 net/nimble/host/services/tps/pkg.yml            |     4 +-
 net/nimble/host/services/tps/src/ble_svc_tps.c  |     7 +-
 net/nimble/host/src/ble_att.c                   |    57 +-
 net/nimble/host/src/ble_att_clt.c               |    35 +-
 net/nimble/host/src/ble_att_cmd_priv.h          |     4 +-
 net/nimble/host/src/ble_att_priv.h              |    27 +-
 net/nimble/host/src/ble_att_svr.c               |   601 +-
 net/nimble/host/src/ble_eddystone.c             |    33 +-
 net/nimble/host/src/ble_gap.c                   |   565 +-
 net/nimble/host/src/ble_gap_priv.h              |     9 +-
 net/nimble/host/src/ble_gattc.c                 |   401 +-
 net/nimble/host/src/ble_gatts.c                 |   212 +-
 net/nimble/host/src/ble_hs.c                    |    25 +-
 net/nimble/host/src/ble_hs_adv.c                |   272 +-
 net/nimble/host/src/ble_hs_adv_priv.h           |     6 +-
 net/nimble/host/src/ble_hs_conn.c               |   190 +-
 net/nimble/host/src/ble_hs_conn_priv.h          |    33 +-
 net/nimble/host/src/ble_hs_dbg.c                |    72 +-
 net/nimble/host/src/ble_hs_hci.c                |    75 +-
 net/nimble/host/src/ble_hs_hci_cmd.c            |   124 +-
 net/nimble/host/src/ble_hs_hci_evt.c            |    71 +-
 net/nimble/host/src/ble_hs_hci_priv.h           |     4 +-
 net/nimble/host/src/ble_hs_hci_util.c           |     8 +-
 net/nimble/host/src/ble_hs_id.c                 |    38 +-
 net/nimble/host/src/ble_hs_misc.c               |    20 +-
 net/nimble/host/src/ble_hs_priv.h               |     9 +
 net/nimble/host/src/ble_hs_pvcy.c               |     6 +-
 net/nimble/host/src/ble_hs_startup.c            |     2 +-
 net/nimble/host/src/ble_ibeacon.c               |     4 +-
 net/nimble/host/src/ble_l2cap.c                 |   184 +-
 net/nimble/host/src/ble_l2cap_coc.c             |   510 +
 net/nimble/host/src/ble_l2cap_coc_priv.h        |    83 +
 net/nimble/host/src/ble_l2cap_priv.h            |    46 +-
 net/nimble/host/src/ble_l2cap_sig.c             |   777 +-
 net/nimble/host/src/ble_l2cap_sig_cmd.c         |   199 +-
 net/nimble/host/src/ble_l2cap_sig_priv.h        |    64 +-
 net/nimble/host/src/ble_sm.c                    |   629 +-
 net/nimble/host/src/ble_sm_alg.c                |    34 +-
 net/nimble/host/src/ble_sm_cmd.c                |   666 +-
 net/nimble/host/src/ble_sm_lgcy.c               |   103 +-
 net/nimble/host/src/ble_sm_priv.h               |   137 +-
 net/nimble/host/src/ble_sm_sc.c                 |   196 +-
 net/nimble/host/src/ble_store.c                 |    94 +-
 net/nimble/host/src/ble_uuid.c                  |   243 +-
 net/nimble/host/src/ble_uuid_priv.h             |     9 +-
 .../store/ram/include/store/ram/ble_store_ram.h |     1 +
 net/nimble/host/store/ram/pkg.yml               |     4 +-
 net/nimble/host/store/ram/src/ble_store_ram.c   |   140 +-
 net/nimble/host/syscfg.yml                      |   222 +-
 net/nimble/host/test/pkg.yml                    |     3 +
 net/nimble/host/test/src/ble_att_clt_test.c     |    34 +-
 net/nimble/host/test/src/ble_att_svr_test.c     |  1254 +-
 net/nimble/host/test/src/ble_gap_test.c         |   640 +-
 net/nimble/host/test/src/ble_gatt_conn_test.c   |   199 +-
 net/nimble/host/test/src/ble_gatt_disc_c_test.c |   154 +-
 net/nimble/host/test/src/ble_gatt_disc_d_test.c |    76 +-
 net/nimble/host/test/src/ble_gatt_disc_s_test.c |   131 +-
 net/nimble/host/test/src/ble_gatt_find_s_test.c |    64 +-
 net/nimble/host/test/src/ble_gatt_read_test.c   |    28 +-
 net/nimble/host/test/src/ble_gatt_write_test.c  |    13 +-
 .../host/test/src/ble_gatts_notify_test.c       |    40 +-
 net/nimble/host/test/src/ble_gatts_read_test.c  |     8 +-
 net/nimble/host/test/src/ble_gatts_reg_test.c   |   190 +-
 net/nimble/host/test/src/ble_hs_adv_test.c      |   640 +-
 net/nimble/host/test/src/ble_hs_conn_test.c     |    55 +-
 net/nimble/host/test/src/ble_hs_hci_test.c      |     4 +-
 net/nimble/host/test/src/ble_hs_test_util.c     |   808 +-
 net/nimble/host/test/src/ble_hs_test_util.h     |    95 +-
 .../host/test/src/ble_hs_test_util_store.c      |   248 -
 .../host/test/src/ble_hs_test_util_store.h      |    44 -
 net/nimble/host/test/src/ble_l2cap_test.c       |   134 +-
 net/nimble/host/test/src/ble_os_test.c          |    29 +-
 net/nimble/host/test/src/ble_sm_lgcy_test.c     |    28 +-
 net/nimble/host/test/src/ble_sm_sc_test.c       |    52 +-
 net/nimble/host/test/src/ble_sm_test.c          |   268 +-
 net/nimble/host/test/src/ble_sm_test_util.c     |   454 +-
 net/nimble/host/test/src/ble_uuid_test.c        |    93 +-
 net/nimble/include/nimble/ble.h                 |    72 +-
 net/nimble/include/nimble/hci_common.h          |     1 +
 net/nimble/include/nimble/hci_vendor.h          |   112 +
 net/nimble/include/nimble/nimble_opt_auto.h     |    13 +-
 net/nimble/src/util.c                           |   219 -
 net/nimble/syscfg.yml                           |    22 +-
 net/nimble/transport/ram/pkg.yml                |     4 +-
 net/nimble/transport/ram/src/ble_hci_ram.c      |     3 +
 net/nimble/transport/uart/pkg.yml               |     4 +-
 net/nimble/transport/uart/src/ble_hci_uart.c    |    14 +-
 net/nimble/transport/uart/syscfg.yml            |    18 +-
 net/oic/include/oic/oc_api.h                    |    35 +-
 net/oic/include/oic/oc_buffer.h                 |    36 -
 net/oic/include/oic/oc_client_state.h           |    29 +-
 net/oic/include/oic/oc_gatt.h                   |    10 +-
 net/oic/include/oic/oc_helpers.h                |    91 +-
 net/oic/include/oic/oc_log.h                    |    97 +
 net/oic/include/oic/oc_network_events.h         |    32 -
 net/oic/include/oic/oc_rep.h                    |    10 +-
 net/oic/include/oic/oc_ri.h                     |    33 +-
 net/oic/pkg.yml                                 |    16 +-
 net/oic/src/api/oc_buffer.c                     |   203 +-
 net/oic/src/api/oc_buffer.h                     |    35 +
 net/oic/src/api/oc_client_api.c                 |   394 +-
 net/oic/src/api/oc_core_res.c                   |   394 +-
 net/oic/src/api/oc_discovery.c                  |   117 +-
 net/oic/src/api/oc_helpers.c                    |   180 +-
 net/oic/src/api/oc_main.c                       |    81 +-
 net/oic/src/api/oc_network_events.c             |    57 -
 net/oic/src/api/oc_rep.c                        |    43 +-
 net/oic/src/api/oc_ri.c                         |   491 +-
 net/oic/src/api/oc_server_api.c                 |    86 +-
 net/oic/src/messaging/coap/coap.c               |  1925 ++-
 net/oic/src/messaging/coap/coap.h               |   415 +-
 net/oic/src/messaging/coap/constants.h          |    89 +-
 net/oic/src/messaging/coap/engine.c             |   406 +-
 net/oic/src/messaging/coap/engine.h             |     2 +-
 net/oic/src/messaging/coap/observe.c            |   163 +-
 net/oic/src/messaging/coap/observe.h            |    11 +-
 net/oic/src/messaging/coap/oc_coap.h            |    22 +-
 net/oic/src/messaging/coap/separate.c           |    41 +-
 net/oic/src/messaging/coap/separate.h           |    32 +-
 net/oic/src/messaging/coap/transactions.c       |   144 +-
 net/oic/src/messaging/coap/transactions.h       |    17 +-
 net/oic/src/port/mynewt/adaptor.c               |   122 +-
 net/oic/src/port/mynewt/adaptor.h               |    27 +-
 net/oic/src/port/mynewt/ble_adaptor.c           |   418 +-
 net/oic/src/port/mynewt/config.h                |     5 -
 net/oic/src/port/mynewt/ip4_adaptor.c           |   354 +
 net/oic/src/port/mynewt/ip_adaptor.c            |   308 +-
 net/oic/src/port/mynewt/log.c                   |   104 +-
 net/oic/src/port/mynewt/random.c                |     9 +-
 net/oic/src/port/mynewt/serial_adaptor.c        |   124 +-
 net/oic/src/port/oc_assert.h                    |    24 +-
 net/oic/src/port/oc_connectivity.h              |   112 +-
 net/oic/src/port/oc_log.h                       |    82 -
 net/oic/src/port/oc_network_events_mutex.h      |    34 -
 net/oic/src/util/oc_list.c                      |   317 -
 net/oic/src/util/oc_list.h                      |   152 -
 net/oic/src/util/oc_mmem.c                      |   154 -
 net/oic/src/util/oc_mmem.h                      |    61 -
 net/oic/syscfg.yml                              |    14 +-
 net/oic/test/pkg.yml                            |    34 +
 net/oic/test/src/test_discovery.c               |   153 +
 net/oic/test/src/test_getset.c                  |   127 +
 net/oic/test/src/test_oic.c                     |    46 +
 net/oic/test/src/test_oic.h                     |    51 +
 net/oic/test/src/testcases/oic_tests.c          |   115 +
 net/oic/test/syscfg.yml                         |    26 +
 net/wifi/wifi_mgmt/syscfg.yml                   |     2 +-
 sys/config/pkg.yml                              |     4 +-
 sys/config/src/config_fcb.c                     |     2 -
 sys/config/src/config_init.c                    |     3 +
 sys/config/src/config_nmgr.c                    |     8 +-
 sys/config/syscfg.yml                           |    20 +-
 .../src/testcases/config_test_compress_reset.c  |     2 +
 .../src/testcases/config_test_empty_fcb.c       |     1 +
 .../src/testcases/config_test_save_1_fcb.c      |     1 +
 .../src/testcases/config_test_save_2_fcb.c      |     1 +
 .../src/testcases/config_test_save_3_fcb.c      |     1 +
 .../src/testcases/config_test_save_one_fcb.c    |     1 +
 sys/config/test-nffs/pkg.yml                    |     2 +
 sys/console/full/include/console/prompt.h       |     2 +
 sys/console/full/include/console/ticks.h        |    41 +
 sys/console/full/pkg.yml                        |     4 +-
 sys/console/full/src/cons_fmt.c                 |    23 +-
 sys/console/full/src/cons_tty.c                 |     3 +
 sys/console/full/src/prompt.c                   |     6 +
 sys/console/full/src/ticks.c                    |    46 +
 sys/console/full/syscfg.yml                     |     4 +-
 sys/console/minimal/include/console/console.h   |    62 +
 sys/console/minimal/include/console/prompt.h    |    55 +
 sys/console/minimal/include/console/ticks.h     |    51 +
 sys/console/minimal/pkg.yml                     |    33 +
 sys/console/minimal/src/cons_tty.c              |   253 +
 sys/console/minimal/syscfg.yml                  |    33 +
 sys/console/stub/include/console/prompt.h       |    21 +-
 sys/console/stub/include/console/ticks.h        |    51 +
 sys/flash_map/pkg.yml                           |     5 +-
 sys/flash_map/src/flash_map.c                   |     5 +-
 sys/flash_map/syscfg.yml                        |     2 +-
 .../test/src/testcases/flash_map_test_case_1.c  |     4 -
 .../test/src/testcases/flash_map_test_case_2.c  |     4 -
 sys/id/pkg.yml                                  |     4 +-
 sys/id/src/id.c                                 |     3 +
 sys/log/full/include/log/ignore.h               |    64 +
 sys/log/full/include/log/log.h                  |   246 +
 sys/log/full/pkg.yml                            |    44 +
 sys/log/full/src/log.c                          |   322 +
 sys/log/full/src/log_cbmem.c                    |   131 +
 sys/log/full/src/log_console.c                  |    82 +
 sys/log/full/src/log_fcb.c                      |   284 +
 sys/log/full/src/log_nmgr.c                     |   514 +
 sys/log/full/src/log_shell.c                    |   108 +
 sys/log/full/syscfg.yml                         |    41 +
 sys/log/full/test/pkg.yml                       |    30 +
 sys/log/full/test/src/log_test.c                |   111 +
 sys/log/full/test/src/log_test.h                |    56 +
 .../full/test/src/testcases/log_append_fcb.c    |    33 +
 sys/log/full/test/src/testcases/log_flush_fcb.c |    31 +
 sys/log/full/test/src/testcases/log_setup_fcb.c |    39 +
 sys/log/full/test/src/testcases/log_walk_fcb.c  |    30 +
 sys/log/full/test/syscfg.yml                    |    22 +
 sys/log/include/log/ignore.h                    |    64 -
 sys/log/include/log/log.h                       |   223 -
 sys/log/pkg.yml                                 |    41 -
 sys/log/src/log.c                               |   233 -
 sys/log/src/log_cbmem.c                         |   120 -
 sys/log/src/log_console.c                       |    75 -
 sys/log/src/log_fcb.c                           |   275 -
 sys/log/src/log_nmgr.c                          |   524 -
 sys/log/src/log_shell.c                         |   101 -
 sys/log/stub/include/log/ignore.h               |    64 +
 sys/log/stub/include/log/log.h                  |    73 +
 sys/log/stub/pkg.yml                            |    29 +
 sys/log/stub/syscfg.yml                         |    27 +
 sys/log/syscfg.yml                              |    37 -
 sys/log/test/pkg.yml                            |    30 -
 sys/log/test/src/log_test.c                     |   110 -
 sys/log/test/src/log_test.h                     |    54 -
 sys/log/test/src/testcases/log_append_fcb.c     |    33 -
 sys/log/test/src/testcases/log_flush_fcb.c      |    30 -
 sys/log/test/src/testcases/log_setup_fcb.c      |    39 -
 sys/log/test/src/testcases/log_walk_fcb.c       |    29 -
 sys/log/test/syscfg.yml                         |    22 -
 sys/mfg/include/mfg/mfg.h                       |     9 +
 sys/mfg/pkg.yml                                 |     4 +-
 sys/mfg/src/mfg.c                               |     4 +
 sys/reboot/include/reboot/log_reboot.h          |    20 +-
 sys/reboot/pkg.yml                              |     7 +-
 sys/reboot/src/log_reboot.c                     |    38 +-
 sys/reboot/syscfg.yml                           |    12 +-
 sys/shell/include/shell/shell_tick.h            |    33 +
 sys/shell/pkg.yml                               |     4 +-
 sys/shell/src/shell.c                           |    89 +-
 sys/shell/src/shell_os.c                        |     8 +-
 sys/shell/src/shell_prompt.c                    |    30 +-
 sys/shell/src/shell_tick.c                      |    62 +
 sys/shell/syscfg.yml                            |     7 +-
 sys/stats/full/include/stats/stats.h            |   142 +
 sys/stats/full/pkg.yml                          |    37 +
 sys/stats/full/src/stats.c                      |   390 +
 sys/stats/full/src/stats_nmgr.c                 |   176 +
 sys/stats/full/src/stats_shell.c                |   119 +
 sys/stats/full/syscfg.yml                       |    32 +
 sys/stats/include/stats/stats.h                 |   140 -
 sys/stats/pkg.yml                               |    35 -
 sys/stats/src/stats.c                           |   387 -
 sys/stats/src/stats_nmgr.c                      |   185 -
 sys/stats/src/stats_shell.c                     |   119 -
 sys/stats/stub/include/stats/stats.h            |    83 +
 sys/stats/stub/pkg.yml                          |    29 +
 sys/stats/syscfg.yml                            |    32 -
 sys/sysinit/include/sysinit/sysinit.h           |    51 +-
 sys/sysinit/pkg.yml                             |     2 +-
 sys/sysinit/src/sysinit.c                       |    49 +
 sys/sysinit/syscfg.yml                          |     6 +-
 targets/unittest/pkg.yml                        |     2 +-
 targets/unittest/target.yml                     |     4 +-
 test/crash_test/pkg.yml                         |     4 +-
 test/crash_test/src/crash_nmgr.c                |    23 +-
 test/crash_test/src/crash_test.c                |     4 +
 test/crash_test/syscfg.yml                      |     4 +-
 test/flash_test/src/flash_test/flash_test.c     |    20 +-
 test/runtest/include/runtest/runtest.h          |    24 +-
 test/runtest/pkg.yml                            |     7 +-
 test/runtest/src/runtest.c                      |    33 +-
 test/runtest/src/runtest_cli.c                  |     4 +-
 test/runtest/src/runtest_nmgr.c                 |   141 +-
 test/runtest/syscfg.yml                         |     4 +-
 test/testreport/include/testreport/testreport.h |    42 -
 test/testreport/pkg.yml                         |    30 -
 test/testreport/src/arch/cortex_m4/io.c         |    91 -
 test/testreport/src/arch/sim/io.c               |   140 -
 test/testreport/src/results.c                   |   190 -
 test/testreport/src/testreport.c                |   131 -
 test/testreport/src/testreport_priv.h           |    56 -
 test/testutil/include/testutil/testutil.h       |    48 +-
 test/testutil/src/case.c                        |    26 +-
 test/testutil/src/suite.c                       |    13 +-
 test/testutil/src/testutil.c                    |     6 +-
 test/testutil/syscfg.yml                        |    24 +
 util/mem/include/mem/mem.h                      |    17 +
 util/mem/src/mem.c                              |    79 +
 962 files changed, 93547 insertions(+), 20337 deletions(-)
----------------------------------------------------------------------



[15/50] incubator-mynewt-core git commit: nimble/l2cap: Memset response in L2CAP LE CoC connect request

Posted by ma...@apache.org.
nimble/l2cap: Memset response in L2CAP LE CoC connect request

This is in order to not send trash in case of error response.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/ced3e8b2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ced3e8b2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ced3e8b2

Branch: refs/heads/master
Commit: ced3e8b2469a914562abbbb3c8711629fd69f846
Parents: 509cd5f
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Wed Feb 22 17:15:35 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 12:40:41 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_sig.c | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ced3e8b2/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index 94bb271..a1a3399 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -631,6 +631,8 @@ ble_l2cap_sig_coc_req_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
         return 0;
     }
 
+    memset(rsp, 0, sizeof(*rsp));
+
     req = (struct ble_l2cap_sig_le_con_req *)(*om)->om_data;
 
     ble_hs_lock();


[08/50] incubator-mynewt-core git commit: SensorAPI BNO055: Add default config

Posted by ma...@apache.org.
SensorAPI BNO055: Add default config

- Improve config


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/4af79d47
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/4af79d47
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/4af79d47

Branch: refs/heads/master
Commit: 4af79d47775b64093b3b2a27e7b7d3fe457b5818
Parents: 58378cc
Author: Vipul Rahane <vi...@apache.org>
Authored: Thu Mar 2 16:53:13 2017 -0800
Committer: Vipul Rahane <vi...@apache.org>
Committed: Thu Mar 2 16:54:15 2017 -0800

----------------------------------------------------------------------
 apps/sensors_test/src/main.c                    |   2 +
 .../sensors/bno055/include/bno055/bno055.h      |  55 ++++--
 hw/drivers/sensors/bno055/src/bno055.c          | 177 ++++++++++++++++---
 3 files changed, 196 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4af79d47/apps/sensors_test/src/main.c
----------------------------------------------------------------------
diff --git a/apps/sensors_test/src/main.c b/apps/sensors_test/src/main.c
index 3c5cedd..b79b2b5 100755
--- a/apps/sensors_test/src/main.c
+++ b/apps/sensors_test/src/main.c
@@ -312,6 +312,8 @@ config_sensor(void)
 
     bcfg.bc_pwr_mode = BNO055_PWR_MODE_NORMAL;
 
+    bcfg.bc_use_ext_xtal = 1;
+
     rc = bno055_config((struct bno055 *) dev, &bcfg);
     if (rc) {
         os_dev_close(dev);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4af79d47/hw/drivers/sensors/bno055/include/bno055/bno055.h
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bno055/include/bno055/bno055.h b/hw/drivers/sensors/bno055/include/bno055/bno055.h
index 0529a2d..f04c2ae 100644
--- a/hw/drivers/sensors/bno055/include/bno055/bno055.h
+++ b/hw/drivers/sensors/bno055/include/bno055/bno055.h
@@ -60,10 +60,10 @@ extern "C" {
 #define BNO055_DO_FORMAT_ANDROID                            (1 << 7)
 
 /* Accelerometer config */
-#define BNO055_ACC_CFG_2G                                        0x0
-#define BNO055_ACC_CFG_4G                                        0x1
-#define BNO055_ACC_CFG_8G                                        0x2
-#define BNO055_ACC_CFG_16G                                       0x3
+#define BNO055_ACC_CFG_RNG_2G                                    0x0
+#define BNO055_ACC_CFG_RNG_4G                                    0x1
+#define BNO055_ACC_CFG_RNG_8G                                    0x2
+#define BNO055_ACC_CFG_RNG_16G                                   0x3
 
 #define BNO055_ACC_CFG_BW_7_81HZ                          (0x0 << 2)
 #define BNO055_ACC_CFG_BW_15_63HZ                         (0x1 << 2)
@@ -104,14 +104,14 @@ extern "C" {
 #define BNO055_GYR_CFG_OPR_MODE_ADV_PWR_SAVE              (0x4 << 5)
 
 /* Magnetometer config */
-#define BNO055_MAG_CFG_BW_2HZ                                    0x0
-#define BNO055_MAG_CFG_BW_6HZ                                    0x1
-#define BNO055_MAG_CFG_BW_8HZ                                    0x2
-#define BNO055_MAG_CFG_BW_10HZ                                   0x3
-#define BNO055_MAG_CFG_BW_15HZ                                   0x4
-#define BNO055_MAG_CFG_BW_20HZ                                   0x5
-#define BNO055_MAG_CFG_BW_25HZ                                   0x6
-#define BNO055_MAG_CFG_BW_30HZ                                   0x7
+#define BNO055_MAG_CFG_ODR_2HZ                                    0x0
+#define BNO055_MAG_CFG_ODR_6HZ                                    0x1
+#define BNO055_MAG_CFG_ODR_8HZ                                    0x2
+#define BNO055_MAG_CFG_ODR_10HZ                                   0x3
+#define BNO055_MAG_CFG_ODR_15HZ                                   0x4
+#define BNO055_MAG_CFG_ODR_20HZ                                   0x5
+#define BNO055_MAG_CFG_ODR_25HZ                                   0x6
+#define BNO055_MAG_CFG_ODR_30HZ                                   0x7
 
 #define BNO055_MAG_CFG_OPR_MODE_LOWPWR                    (0x0 << 3)
 #define BNO055_MAG_CFG_OPR_MODE_REG                       (0x1 << 3)
@@ -123,10 +123,41 @@ extern "C" {
 #define BNO055_MAG_CFG_PWR_MODE_SUSPEND                   (0x2 << 5)
 #define BNO055_MAG_CFG_PWR_MODE_FORCE_MODE                (0x3 << 5)
 
+/*
+ * Just a placeholder to specify resolution/axis x:13 bits, y:13 bits,
+ * z:15 bits
+ */
+#define BNO055_MAG_RES_13_13_15                                 0x00
+
+#define BNO055_AXIS_CFG_P0                                      0x00
+#define BNO055_AXIS_CFG_P1                                      0x01 /* Default */
+#define BNO055_AXIS_CFG_P2                                      0x02
+#define BNO055_AXIS_CFG_P3                                      0x03
+#define BNO055_AXIS_CFG_P4                                      0x04
+#define BNO055_AXIS_CFG_P5                                      0x05
+#define BNO055_AXIS_CFG_P6                                      0x06
+#define BNO055_AXIS_CFG_P7                                      0x07
+
 struct bno055_cfg {
     uint8_t bc_opr_mode;
     uint8_t bc_pwr_mode;
     uint8_t bc_units;
+    uint8_t bc_placement;
+    uint8_t bc_acc_range;
+    uint8_t bc_acc_bw;
+    uint8_t bc_acc_opr_mode;
+    uint8_t bc_acc_res;
+    uint8_t bc_gyro_range;
+    uint8_t bc_gyro_bw;
+    uint8_t bc_gyro_opr_mode;
+    uint8_t bc_gyro_res;
+    uint8_t bc_mag_odr;
+    uint8_t bc_mag_xy_rep;
+    uint8_t bc_mag_z_rep;
+    uint8_t bc_mag_res;
+    uint8_t bc_mag_pwr_mode;
+    uint8_t bc_mag_opr_mode;
+    uint8_t bc_use_ext_xtal;
 };
 
 struct bno055 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4af79d47/hw/drivers/sensors/bno055/src/bno055.c
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bno055/src/bno055.c b/hw/drivers/sensors/bno055/src/bno055.c
index fb98197..4b9f32c 100644
--- a/hw/drivers/sensors/bno055/src/bno055.c
+++ b/hw/drivers/sensors/bno055/src/bno055.c
@@ -44,33 +44,11 @@
 #if MYNEWT_VAL(BNO055_STATS)
 /* Define the stats section and records */
 STATS_SECT_START(bno055_stat_section)
-    STATS_SECT_ENTRY(samples_acc_2g)
-    STATS_SECT_ENTRY(samples_acc_4g)
-    STATS_SECT_ENTRY(samples_acc_8g)
-    STATS_SECT_ENTRY(samples_acc_16g)
-    STATS_SECT_ENTRY(samples_mag_1_3g)
-    STATS_SECT_ENTRY(samples_mag_1_9g)
-    STATS_SECT_ENTRY(samples_mag_2_5g)
-    STATS_SECT_ENTRY(samples_mag_4_0g)
-    STATS_SECT_ENTRY(samples_mag_4_7g)
-    STATS_SECT_ENTRY(samples_mag_5_6g)
-    STATS_SECT_ENTRY(samples_mag_8_1g)
     STATS_SECT_ENTRY(errors)
 STATS_SECT_END
 
 /* Define stat names for querying */
 STATS_NAME_START(bno055_stat_section)
-    STATS_NAME(bno055_stat_section, samples_acc_2g)
-    STATS_NAME(bno055_stat_section, samples_acc_4g)
-    STATS_NAME(bno055_stat_section, samples_acc_8g)
-    STATS_NAME(bno055_stat_section, samples_acc_16g)
-    STATS_NAME(bno055_stat_section, samples_mag_1_3g)
-    STATS_NAME(bno055_stat_section, samples_mag_1_9g)
-    STATS_NAME(bno055_stat_section, samples_mag_2_5g)
-    STATS_NAME(bno055_stat_section, samples_mag_4_0g)
-    STATS_NAME(bno055_stat_section, samples_mag_4_7g)
-    STATS_NAME(bno055_stat_section, samples_mag_5_6g)
-    STATS_NAME(bno055_stat_section, samples_mag_8_1g)
     STATS_NAME(bno055_stat_section, errors)
 STATS_NAME_END(bno055_stat_section)
 
@@ -444,6 +422,31 @@ err:
     return rc;
 }
 
+static int
+bno055_default_cfg(struct bno055_cfg *cfg)
+{
+    cfg->bc_opr_mode = BNO055_OPR_MODE_ACCONLY;
+    cfg->bc_pwr_mode = BNO055_PWR_MODE_NORMAL;
+    cfg->bc_units = BNO055_DO_FORMAT_ANDROID|
+                    BNO055_ACC_UNIT_MS2|
+                    BNO055_ANGRATE_UNIT_DPS|
+                    BNO055_EULER_UNIT_DEG|
+                    BNO055_TEMP_UNIT_DEGC;
+    cfg->bc_placement = BNO055_AXIS_CFG_P1;
+    cfg->bc_acc_range = BNO055_ACC_CFG_RNG_4G;
+    cfg->bc_acc_bw = BNO055_ACC_CFG_BW_6_25HZ;
+    cfg->bc_acc_res = 14;
+    cfg->bc_gyro_range = BNO055_GYR_CFG_RNG_2000DPS;
+    cfg->bc_gyro_bw = BNO055_GYR_CFG_BW_32HZ;
+    cfg->bc_gyro_res = 16;
+    cfg->bc_mag_odr = BNO055_MAG_CFG_ODR_2HZ;
+    cfg->bc_mag_xy_rep = 15;
+    cfg->bc_mag_z_rep = 16;
+    cfg->bc_mag_res = BNO055_MAG_RES_13_13_15;
+
+    return 0;
+}
+
 /**
  * Expects to be called back through os_dev_create().
  *
@@ -461,6 +464,11 @@ bno055_init(struct os_dev *dev, void *arg)
 
     bno055 = (struct bno055 *) dev;
 
+    rc = bno055_default_cfg(&bno055->cfg);
+    if (rc) {
+        goto err;
+    }
+
 #if MYNEWT_VAL(BNO055_LOG)
     log_register("bno055", &_log, &log_console_handler, NULL, LOG_SYSLEVEL);
 #endif
@@ -582,6 +590,117 @@ err:
     return rc;
 }
 
+int
+bno055_placement_cfg(uint8_t placement)
+{
+    uint8_t remap_cfg;
+    uint8_t remap_sign;
+    int rc;
+
+    rc = SYS_EOK;
+
+    switch(placement) {
+
+    case BNO055_AXIS_CFG_P0:
+        remap_cfg = BNO055_REMAP_CONFIG_P0;
+        remap_sign = BNO055_REMAP_SIGN_P0;
+        break;
+    case BNO055_AXIS_CFG_P1:
+        remap_cfg = BNO055_REMAP_CONFIG_P1;
+        remap_sign = BNO055_REMAP_SIGN_P1;
+        break;
+    case BNO055_AXIS_CFG_P2:
+        remap_cfg = BNO055_REMAP_CONFIG_P2;
+        remap_sign = BNO055_REMAP_SIGN_P2;
+        break;
+    case BNO055_AXIS_CFG_P3:
+        remap_cfg = BNO055_REMAP_CONFIG_P3;
+        remap_sign = BNO055_REMAP_SIGN_P3;
+        break;
+    case BNO055_AXIS_CFG_P4:
+        remap_cfg = BNO055_REMAP_CONFIG_P4;
+        remap_sign = BNO055_REMAP_SIGN_P4;
+        break;
+    case BNO055_AXIS_CFG_P5:
+        remap_cfg = BNO055_REMAP_CONFIG_P5;
+        remap_sign = BNO055_REMAP_SIGN_P5;
+        break;
+    case BNO055_AXIS_CFG_P6:
+        remap_cfg = BNO055_REMAP_CONFIG_P6;
+        remap_sign = BNO055_REMAP_SIGN_P6;
+        break;
+    case BNO055_AXIS_CFG_P7:
+        remap_cfg = BNO055_REMAP_CONFIG_P7;
+        remap_sign = BNO055_REMAP_SIGN_P7;
+        break;
+    default:
+        BNO055_ERR("Invalid Axis config, Assuming P1(default) \n");
+        rc = SYS_EINVAL;
+        goto err;
+    }
+
+    rc = bno055_write8(BNO055_AXIS_MAP_CONFIG_ADDR, remap_cfg);
+    if (rc) {
+        goto err;
+    }
+
+    rc = bno055_write8(BNO055_AXIS_MAP_SIGN_ADDR, remap_sign);
+    if (rc) {
+        goto err;
+    }
+
+    return 0;
+err:
+    return rc;
+}
+
+int
+bno055_acc_cfg(struct bno055_cfg *cfg)
+{
+    int rc;
+
+    rc = bno055_write8(BNO055_ACCEL_CONFIG_ADDR, cfg->bc_acc_range|
+                       cfg->bc_acc_bw|cfg->bc_acc_opr_mode);
+    if (rc) {
+        goto err;
+    }
+
+    return 0;
+err:
+    return rc;
+}
+
+int
+bno055_mag_cfg(struct bno055_cfg *cfg)
+{
+    int rc;
+
+    rc = bno055_write8(BNO055_MAG_CONFIG_ADDR, cfg->bc_mag_odr|
+                       cfg->bc_mag_pwr_mode|cfg->bc_mag_opr_mode);
+    if (rc) {
+        goto err;
+    }
+
+    return 0;
+err:
+    return rc;
+}
+
+int
+bno055_gyro_cfg(struct bno055_cfg *cfg)
+{
+    int rc;
+
+    rc = bno055_write8(BNO055_GYRO_CONFIG_ADDR, cfg->bc_gyro_range|
+                       cfg->bc_gyro_bw|cfg->bc_gyro_opr_mode);
+    if (rc) {
+        goto err;
+    }
+
+    return 0;
+err:
+    return rc;
+}
 
 int
 bno055_config(struct bno055 *bno055, struct bno055_cfg *cfg)
@@ -629,22 +748,28 @@ bno055_config(struct bno055 *bno055, struct bno055_cfg *cfg)
         goto err;
     }
 
+    bno055->cfg.bc_pwr_mode = cfg->bc_pwr_mode;
+
     /**
      * As per Section 5.5 in the BNO055 Datasheet,
      * external crystal should be used for accurate
      * results
      */
-    rc = bno055_set_ext_xtal_use(1, BNO055_OPR_MODE_CONFIG);
+    rc = bno055_set_ext_xtal_use(cfg->bc_use_ext_xtal, BNO055_OPR_MODE_CONFIG);
     if (rc) {
         goto err;
     }
 
+    bno055->cfg.bc_use_ext_xtal = cfg->bc_use_ext_xtal;
+
     /* Setting units and data output format */
     rc = bno055_set_units(cfg->bc_units);
     if (rc) {
         goto err;
     }
 
+    bno055->cfg.bc_units = cfg->bc_units;
+
     /* Change mode to requested mode */
     rc = bno055_set_opr_mode(cfg->bc_opr_mode);
     if (rc) {
@@ -674,12 +799,12 @@ bno055_config(struct bno055 *bno055, struct bno055_cfg *cfg)
 
         if (cfg->bc_opr_mode != mode) {
             BNO055_ERR("Config mode and read mode do not match.\n");
-            return rc;
+            rc = SYS_EINVAL;
+            goto err;
         }
     }
 
-    /* Overwrite the configuration data. */
-    memcpy(&bno055->cfg, cfg, sizeof(*cfg));
+    bno055->cfg.bc_opr_mode = cfg->bc_opr_mode;
 
     return 0;
 err:


[28/50] incubator-mynewt-core git commit: nimble/l2cap: Add handling receiving SDU over L2CAP LE CoC

Posted by ma...@apache.org.
nimble/l2cap: Add handling receiving SDU over L2CAP LE CoC

With this patch nimble can receive full SDU from remote device.
Once it is done, callback with SDU is called to application.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/98e2cb9d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/98e2cb9d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/98e2cb9d

Branch: refs/heads/master
Commit: 98e2cb9d3c8cbb75be0c6462aa09391d8df31cbd
Parents: 754c445
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Sun Feb 12 15:20:50 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 12:40:42 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap.c          |   2 +-
 net/nimble/host/src/ble_l2cap_coc.c      | 136 ++++++++++++++++++++++++++
 net/nimble/host/src/ble_l2cap_coc_priv.h |   4 +
 3 files changed, 141 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98e2cb9d/net/nimble/host/src/ble_l2cap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap.c b/net/nimble/host/src/ble_l2cap.c
index e048ce9..b0ab23d 100644
--- a/net/nimble/host/src/ble_l2cap.c
+++ b/net/nimble/host/src/ble_l2cap.c
@@ -166,7 +166,7 @@ ble_l2cap_send(struct ble_l2cap_chan *chan, struct os_mbuf *sdu)
 void
 ble_l2cap_recv_ready(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_rx)
 {
-    /*TODO In here we going to update sdu_rx buffer */
+    ble_l2cap_coc_recv_ready(chan, sdu_rx);
 }
 
 void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98e2cb9d/net/nimble/host/src/ble_l2cap_coc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc.c b/net/nimble/host/src/ble_l2cap_coc.c
index 8d5f71f..b549ba7 100644
--- a/net/nimble/host/src/ble_l2cap_coc.c
+++ b/net/nimble/host/src/ble_l2cap_coc.c
@@ -28,6 +28,8 @@
 
 #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
 
+#define BLE_L2CAP_SDU_SIZE              2
+
 STAILQ_HEAD(ble_l2cap_coc_srv_list, ble_l2cap_coc_srv);
 
 static struct ble_l2cap_coc_srv_list ble_l2cap_coc_srvs;
@@ -116,9 +118,115 @@ ble_l2cap_coc_srv_find(uint16_t psm)
     return srv;
 }
 
+static void
+ble_l2cap_event_coc_received_data(struct ble_l2cap_chan *chan,
+                                  struct os_mbuf *om)
+{
+    struct ble_l2cap_event event;
+
+    event.type = BLE_L2CAP_EVENT_COC_DATA_RECEIVED;
+    event.receive.chan = chan;
+    event.receive.sdu_rx = om;
+
+    chan->cb(&event, chan->cb_arg);
+}
+
 static int
 ble_l2cap_coc_rx_fn(struct ble_l2cap_chan *chan)
 {
+    int rc;
+    struct os_mbuf **om;
+    struct ble_l2cap_coc_endpoint *rx;
+    uint16_t om_total;
+
+    /* Create a shortcut to rx_buf */
+    om = &chan->rx_buf;
+    BLE_HS_DBG_ASSERT(*om != NULL);
+
+    /* Create a shortcut to rx endpoint */
+    rx = &chan->coc_rx;
+
+    om_total = OS_MBUF_PKTLEN(*om);
+    rc = ble_hs_mbuf_pullup_base(om, om_total);
+    if (rc != 0) {
+        return rc;
+    }
+
+    /* Fist LE frame */
+    if (OS_MBUF_PKTLEN(rx->sdu) == 0) {
+        uint16_t sdu_len;
+
+        sdu_len = get_le16((*om)->om_data);
+        if (sdu_len > rx->mtu) {
+            /* TODO Disconnect?*/
+            BLE_HS_LOG(INFO, "error: sdu_len > rx->mtu (%d>%d)\n",
+                       sdu_len, rx->mtu);
+            return BLE_HS_EBADDATA;
+        }
+
+        BLE_HS_LOG(DEBUG, "sdu_len=%d, received LE frame=%d, credits=%d\n",
+                   sdu_len, om_total, rx->credits);
+
+        os_mbuf_adj(*om , BLE_L2CAP_SDU_SIZE);
+
+        rc = os_mbuf_appendfrom(rx->sdu, *om, 0, om_total - BLE_L2CAP_SDU_SIZE);
+        if (rc != 0) {
+            /* FIXME: User shall give us big enough buffer.
+             * need to handle it better
+             */
+            BLE_HS_LOG(INFO, "Could not append data rc=%d\n", rc);
+            assert(0);
+        }
+
+        /* In RX case data_offset keeps incoming SDU len */
+        rx->data_offset = sdu_len;
+
+    } else {
+        BLE_HS_LOG(DEBUG, "Continuation...received %d\n", (*om)->om_len);
+
+        rc  = os_mbuf_appendfrom(rx->sdu, *om, 0, om_total);
+        if (rc != 0) {
+            /* FIXME: need to handle it better */
+            BLE_HS_LOG(DEBUG, "Could not append data rc=%d\n", rc);
+            assert(0);
+        }
+    }
+
+    rx->credits--;
+
+    if (OS_MBUF_PKTLEN(rx->sdu) == rx->data_offset) {
+        struct os_mbuf *sdu_rx = rx->sdu;
+
+        /* Lets get back control to os_mbuf to application.
+         * Since it this callback application might want to set new sdu
+         * we need to prepare space for this. Therefore we need sdu_rx
+         */
+
+        rx->sdu = NULL;
+        rx->data_offset = 0;
+
+        ble_l2cap_event_coc_received_data(chan, sdu_rx);
+
+        goto done;
+    }
+
+    /* If we did not received full SDU and credits are 0 it means
+     * that remote was sending us not fully filled up LE frames.
+     * However, we still have buffer to for next LE Frame so lets give one more
+     * credit to peer so it can send us full SDU
+     */
+    if (rx->credits == 0 && rx->sdu) {
+        /* Remote did not send full SDU. Lets give him one more credits to do
+         * so since we have still buffer to handle it
+         */
+        rx->credits = 1;
+        ble_l2cap_sig_le_credits(chan, rx->credits);
+    }
+
+done:
+    BLE_HS_LOG(DEBUG, "Received sdu_len=%d, credits left=%d\n",
+               OS_MBUF_PKTLEN(rx->sdu), rx->credits);
+
     return 0;
 }
 
@@ -200,6 +308,34 @@ ble_l2cap_coc_le_credits_update(uint16_t conn_handle, uint16_t dcid,
     ble_hs_unlock();
 }
 
+void
+ble_l2cap_coc_recv_ready(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_rx)
+{
+    struct ble_hs_conn *conn;
+    struct ble_l2cap_chan *c;
+
+    chan->coc_rx.sdu = sdu_rx;
+
+    ble_hs_lock();
+    conn = ble_hs_conn_find_assert(chan->conn_handle);
+    c = ble_hs_conn_chan_find_by_scid(conn, chan->scid);
+    if (!c) {
+        ble_hs_unlock();
+        return;
+    }
+
+    /* FIXME 10 is hardcoded - make it better.
+     * We want to back only that much credits which remote side is missing
+     * to be able to send complete SDU.
+     */
+    if (chan->coc_rx.credits < 10) {
+        ble_l2cap_sig_le_credits(chan, 10 - chan->coc_rx.credits);
+        chan->coc_rx.credits = 10;
+    }
+
+    ble_hs_unlock();
+}
+
 int
 ble_l2cap_coc_init(void)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98e2cb9d/net/nimble/host/src/ble_l2cap_coc_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc_priv.h b/net/nimble/host/src/ble_l2cap_coc_priv.h
index 21f9ec2..88380ea 100644
--- a/net/nimble/host/src/ble_l2cap_coc_priv.h
+++ b/net/nimble/host/src/ble_l2cap_coc_priv.h
@@ -39,6 +39,7 @@ struct ble_l2cap_chan;
 struct ble_l2cap_coc_endpoint {
     uint16_t mtu;
     uint16_t credits;
+    uint16_t data_offset;
     struct os_mbuf *sdu;
 };
 
@@ -63,9 +64,12 @@ struct ble_l2cap_chan * ble_l2cap_coc_chan_alloc(uint16_t conn_handle,
                                                  void *cb_arg);
 void ble_l2cap_coc_le_credits_update(uint16_t conn_handle, uint16_t dcid,
                                     uint16_t credits);
+void ble_l2cap_coc_recv_ready(struct ble_l2cap_chan *chan,
+                              struct os_mbuf *sdu_rx);
 #else
 #define ble_l2cap_coc_init()                                    0
 #define ble_l2cap_coc_create_server(psm, mtu, cb, cb_arg)       BLE_HS_ENOTSUP
+#define ble_l2cap_coc_recv_ready(chan, sdu_rx)
 #endif
 
 #ifdef __cplusplus


[30/50] incubator-mynewt-core git commit: nibmle/l2cap: Clear LE CoC channel on ACL drop

Posted by ma...@apache.org.
nibmle/l2cap: Clear LE CoC channel on ACL drop

When ACL is disconnected before L2CAP is disconnected we need to
make sure proper cleaning is done and application is notified
about channel disconnection.

Therefore with this patch sending DISCONNECTED EVENT is moved to
function doing free of COC specific data in the channel


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/e488b9df
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/e488b9df
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/e488b9df

Branch: refs/heads/master
Commit: e488b9df404e1dc45ce6494d66fbe965d66a1758
Parents: 93ac0df
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Sun Feb 12 21:45:29 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 12:40:42 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_coc.c | 14 ++++++++++++++
 net/nimble/host/src/ble_l2cap_sig.c | 16 ----------------
 2 files changed, 14 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e488b9df/net/nimble/host/src/ble_l2cap_coc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc.c b/net/nimble/host/src/ble_l2cap_coc.c
index 12d79d6..ec01fec 100644
--- a/net/nimble/host/src/ble_l2cap_coc.c
+++ b/net/nimble/host/src/ble_l2cap_coc.c
@@ -276,6 +276,18 @@ ble_l2cap_coc_create_srv_chan(uint16_t conn_handle, uint16_t psm,
     return 0;
 }
 
+static void
+ble_l2cap_event_coc_disconnected(struct ble_l2cap_chan *chan)
+{
+    struct ble_l2cap_event event = { };
+
+    event.type = BLE_L2CAP_EVENT_COC_DISCONNECTED;
+    event.disconnect.conn_handle = chan->conn_handle;
+    event.disconnect.chan = chan;
+
+    chan->cb(&event, chan->cb_arg);
+}
+
 void
 ble_l2cap_coc_cleanup_chan(struct ble_l2cap_chan *chan)
 {
@@ -284,6 +296,8 @@ ble_l2cap_coc_cleanup_chan(struct ble_l2cap_chan *chan)
             return;
     }
 
+    ble_l2cap_event_coc_disconnected(chan);
+
     os_mbuf_free_chain(chan->coc_rx.sdu);
     os_mbuf_free_chain(chan->coc_tx.sdu);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e488b9df/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index 8da2dad..b77fa3b 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -585,18 +585,6 @@ ble_l2cap_event_coc_connected(struct ble_l2cap_chan *chan, uint16_t status)
     chan->cb(&event, chan->cb_arg);
 }
 
-static void
-ble_l2cap_event_coc_disconnected(struct ble_l2cap_chan *chan)
-{
-    struct ble_l2cap_event event = { };
-
-    event.type = BLE_L2CAP_EVENT_COC_DISCONNECTED;
-    event.disconnect.conn_handle = chan->conn_handle;
-    event.disconnect.chan = chan;
-
-    chan->cb(&event, chan->cb_arg);
-}
-
 static int
 ble_l2cap_event_coc_accept(struct ble_l2cap_chan *chan, uint16_t peer_sdu_size)
 {
@@ -891,8 +879,6 @@ ble_l2cap_sig_disc_req_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
     rsp->dcid = htole16(chan->scid);
     rsp->scid = htole16(chan->dcid);
 
-    ble_l2cap_event_coc_disconnected(chan);
-
     ble_hs_conn_delete_chan(conn, chan);
     ble_hs_unlock();
 
@@ -922,8 +908,6 @@ ble_l2cap_sig_coc_disconnect_cb(struct ble_l2cap_sig_proc *proc, int status)
         goto done;
     }
 
-    ble_l2cap_event_coc_disconnected(chan);
-
 done:
     ble_hs_lock();
     conn = ble_hs_conn_find(chan->conn_handle);


[13/50] incubator-mynewt-core git commit: bletiny: Refactor buffer handling in the application

Posted by ma...@apache.org.
bletiny: Refactor buffer handling in the application

With this patch we prepare os_mbuf_pool which is used later by application
to get sdu buffer


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/6a0f5a8f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/6a0f5a8f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/6a0f5a8f

Branch: refs/heads/master
Commit: 6a0f5a8f002eed9e66791b8c4a9b96c3945f81db
Parents: b552c16
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Wed Feb 22 17:06:53 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 10:08:17 2017 +0100

----------------------------------------------------------------------
 apps/bletiny/src/main.c | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6a0f5a8f/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index c468666..52cf7e6 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -73,6 +73,8 @@
 
 #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM)
 #define BLETINY_COC_MTU               (256)
+/* We use same pool for incoming and outgoing sdu */
+#define BLETINY_COC_BUF_COUNT         (3 * MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM))
 #endif
 
 struct log bletiny_log;
@@ -94,7 +96,8 @@ static void *bletiny_coc_conn_mem;
 static struct os_mempool bletiny_coc_conn_pool;
 
 static void *bletiny_sdu_coc_mem;
-static struct os_mempool bletiny_sdu_coc_pool;
+struct os_mbuf_pool sdu_os_mbuf_pool;
+static struct os_mempool sdu_coc_mbuf_mempool;
 #endif
 
 static struct os_callout bletiny_tx_timer;
@@ -1624,7 +1627,14 @@ bletiny_l2cap_coc_remove(uint16_t conn_handle, struct ble_l2cap_chan *chan)
 static void
 bletiny_l2cap_coc_recv(struct ble_l2cap_chan *chan, struct os_mbuf *sdu)
 {
-    console_printf("LE CoC SDU received, chan: 0x%08lx\n", (uint32_t) chan);
+    console_printf("LE CoC SDU received, chan: 0x%08lx, data len %d\n",
+                   (uint32_t) chan, OS_MBUF_PKTLEN(sdu));
+
+    os_mbuf_free_chain(sdu);
+    sdu = os_mbuf_get_pkthdr(&sdu_os_mbuf_pool, 0);
+    assert(sdu != NULL);
+
+    ble_l2cap_recv_ready(chan, sdu);
 }
 
 static int
@@ -1633,9 +1643,9 @@ bletiny_l2cap_coc_accept(uint16_t conn_handle, uint16_t peer_mtu,
 {
     struct os_mbuf *sdu_rx;
 
-    sdu_rx = os_memblock_get(&bletiny_sdu_coc_pool);
+    sdu_rx = os_mbuf_get_pkthdr(&sdu_os_mbuf_pool, 0);
     if (!sdu_rx) {
-            return BLE_HS_ENOMEM;
+        return BLE_HS_ENOMEM;
     }
 
     ble_l2cap_recv_ready(chan, sdu_rx);
@@ -1707,7 +1717,7 @@ bletiny_l2cap_connect(uint16_t conn_handle, uint16_t psm)
 
     struct os_mbuf *sdu_rx;
 
-    sdu_rx = os_memblock_get(&bletiny_sdu_coc_pool);
+    sdu_rx = os_mbuf_get_pkthdr(&sdu_os_mbuf_pool, 0);
     assert(sdu_rx != NULL);
 
     return ble_l2cap_connect(conn_handle, psm, BLETINY_COC_MTU, sdu_rx,
@@ -1793,16 +1803,18 @@ main(void)
 #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
     /* For testing we want to support all the available channels */
     bletiny_sdu_coc_mem = malloc(
-        OS_MEMPOOL_BYTES(BLETINY_COC_MTU * MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM),
-                         sizeof (struct os_mbuf)));
+        OS_MEMPOOL_BYTES(BLETINY_COC_BUF_COUNT, BLETINY_COC_MTU));
     assert(bletiny_sdu_coc_mem != NULL);
 
-    rc = os_mempool_init(&bletiny_sdu_coc_pool,
-                         BLETINY_COC_MTU * MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM),
-                         sizeof (struct os_mbuf), bletiny_sdu_coc_mem,
+    rc = os_mempool_init(&sdu_coc_mbuf_mempool, BLETINY_COC_BUF_COUNT,
+                         BLETINY_COC_MTU, bletiny_sdu_coc_mem,
                          "bletiny_coc_sdu_pool");
     assert(rc == 0);
 
+    rc = os_mbuf_pool_init(&sdu_os_mbuf_pool, &sdu_coc_mbuf_mempool,
+                           BLETINY_COC_MTU, BLETINY_COC_BUF_COUNT);
+    assert(rc == 0);
+
     bletiny_coc_conn_mem = malloc(
         OS_MEMPOOL_BYTES(MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM),
                          sizeof (struct bletiny_l2cap_coc)));


[47/50] incubator-mynewt-core git commit: This closes #193.

Posted by ma...@apache.org.
This closes #193.

Merge remote-tracking branch 'jacobrosenthal/microbit-bsp' into develop

* jacobrosenthal/microbit-bsp:
  microbit bsp: fix split linker script typo


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/63615018
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/63615018
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/63615018

Branch: refs/heads/master
Commit: 636150188eaced91980fbe0843f72fc04be0eb92
Parents: f052c82 c9dabf0
Author: Christopher Collins <cc...@apache.org>
Authored: Sat Mar 4 14:33:40 2017 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Sat Mar 4 14:33:40 2017 -0800

----------------------------------------------------------------------
 hw/bsp/bbc_microbit/bsp.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------



[11/50] incubator-mynewt-core git commit: MYNEWT-492 - Remove unused obsolete settings.

Posted by ma...@apache.org.
MYNEWT-492 - Remove unused obsolete settings.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/cc8ead34
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/cc8ead34
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/cc8ead34

Branch: refs/heads/master
Commit: cc8ead34b536f13ed20ab6ea10137550b2262c89
Parents: 929e256
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Mar 2 17:03:21 2017 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Mar 2 17:43:10 2017 -0800

----------------------------------------------------------------------
 mgmt/newtmgr/syscfg.yml      | 24 ------------------------
 net/nimble/host/src/ble_hs.c |  3 ---
 net/nimble/host/syscfg.yml   |  5 -----
 3 files changed, 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cc8ead34/mgmt/newtmgr/syscfg.yml
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/syscfg.yml b/mgmt/newtmgr/syscfg.yml
deleted file mode 100644
index 6b5da78..0000000
--- a/mgmt/newtmgr/syscfg.yml
+++ /dev/null
@@ -1,24 +0,0 @@
-# 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.
-#
-
-# Package: mgmt/newtmgr
-
-syscfg.defs:
-    NEWTMGR_BLE_HOST:
-        description: 'TBD'
-        value: 0

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cc8ead34/net/nimble/host/src/ble_hs.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs.c b/net/nimble/host/src/ble_hs.c
index ae7b4f5..9fb5702 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -61,9 +61,6 @@ static struct os_event ble_hs_ev_start = {
 uint8_t ble_hs_sync_state;
 static int ble_hs_reset_reason;
 
-#define BLE_HS_HEARTBEAT_OS_TICKS       \
-    (MYNEWT_VAL(BLE_HS_HEARTBEAT_FREQ) * OS_TICKS_PER_SEC / 1000)
-
 #define BLE_HS_SYNC_RETRY_RATE          (OS_TICKS_PER_SEC / 10)
 
 static struct os_task *ble_hs_parent_task;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cc8ead34/net/nimble/host/syscfg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/syscfg.yml b/net/nimble/host/syscfg.yml
index be9d953..6a52b82 100644
--- a/net/nimble/host/syscfg.yml
+++ b/net/nimble/host/syscfg.yml
@@ -34,11 +34,6 @@ syscfg.defs:
         description: 'TBD'
         value: 1
 
-    # Misc settings.
-    BLE_HS_HEARTBEAT_FREQ:
-        description: 'Milliseconds.'
-        value: 1000
-
     # L2CAP settings.
     BLE_L2CAP_MAX_CHANS:
         description: 'TBD'


[42/50] incubator-mynewt-core git commit: don't crash when dumping logs from shell. Dump full logs.

Posted by ma...@apache.org.
don't crash when dumping logs from shell.   Dump full logs.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/2242bc12
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/2242bc12
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/2242bc12

Branch: refs/heads/master
Commit: 2242bc12f239b54c1a3d1bc0cb38ec44437700ad
Parents: 84edc0e
Author: Sterling Hughes <st...@runtime.io>
Authored: Sat Mar 4 10:09:18 2017 -0800
Committer: Sterling Hughes <st...@runtime.io>
Committed: Sat Mar 4 10:09:28 2017 -0800

----------------------------------------------------------------------
 sys/log/full/src/log_shell.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2242bc12/sys/log/full/src/log_shell.c
----------------------------------------------------------------------
diff --git a/sys/log/full/src/log_shell.c b/sys/log/full/src/log_shell.c
index e0f6d71..ae1fd3d 100644
--- a/sys/log/full/src/log_shell.c
+++ b/sys/log/full/src/log_shell.c
@@ -71,6 +71,7 @@ int
 shell_log_dump_all_cmd(int argc, char **argv)
 {
     struct log *log;
+    struct log_offset log_offset;
     int rc;
 
     log = NULL;
@@ -86,7 +87,12 @@ shell_log_dump_all_cmd(int argc, char **argv)
 
         console_printf("Dumping log %s\n", log->l_name);
 
-        rc = log_walk(log, shell_log_dump_entry, NULL);
+        log_offset.lo_arg = NULL;
+        log_offset.lo_ts = 0;
+        log_offset.lo_index = 0;
+        log_offset.lo_data_len = 0;
+
+        rc = log_walk(log, shell_log_dump_entry, &log_offset);
         if (rc != 0) {
             goto err;
         }


[09/50] incubator-mynewt-core git commit: MYNEWT-509 - Specify min-write-sz per MCU.

Posted by ma...@apache.org.
MYNEWT-509 - Specify min-write-sz per MCU.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/929e2563
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/929e2563
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/929e2563

Branch: refs/heads/master
Commit: 929e2563a913b351624b729811da7f2d7192fa1e
Parents: 4af79d4
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Mar 2 16:37:51 2017 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Mar 2 16:54:40 2017 -0800

----------------------------------------------------------------------
 hw/mcu/mips/danube/syscfg.yml     | 26 ++++++++++++++++++++++++++
 hw/mcu/native/syscfg.yml          | 26 ++++++++++++++++++++++++++
 hw/mcu/nordic/nrf51xxx/syscfg.yml | 26 ++++++++++++++++++++++++++
 hw/mcu/nordic/nrf52xxx/syscfg.yml | 26 ++++++++++++++++++++++++++
 hw/mcu/nxp/MK64F12/syscfg.yml     | 26 ++++++++++++++++++++++++++
 hw/mcu/stm/stm32f4xx/syscfg.yml   | 26 ++++++++++++++++++++++++++
 6 files changed, 156 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/929e2563/hw/mcu/mips/danube/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/mcu/mips/danube/syscfg.yml b/hw/mcu/mips/danube/syscfg.yml
new file mode 100644
index 0000000..d0c40be
--- /dev/null
+++ b/hw/mcu/mips/danube/syscfg.yml
@@ -0,0 +1,26 @@
+# 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.
+#
+
+# Package: hw/bsp/nrf52dk
+
+syscfg.defs:
+    MCU_FLASH_MIN_WRITE_SIZE:
+        description: >
+            Specifies the required alignment for internal flash writes.
+            Used internally by the newt tool.
+        value: 1

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/929e2563/hw/mcu/native/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/mcu/native/syscfg.yml b/hw/mcu/native/syscfg.yml
new file mode 100644
index 0000000..d0c40be
--- /dev/null
+++ b/hw/mcu/native/syscfg.yml
@@ -0,0 +1,26 @@
+# 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.
+#
+
+# Package: hw/bsp/nrf52dk
+
+syscfg.defs:
+    MCU_FLASH_MIN_WRITE_SIZE:
+        description: >
+            Specifies the required alignment for internal flash writes.
+            Used internally by the newt tool.
+        value: 1

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/929e2563/hw/mcu/nordic/nrf51xxx/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf51xxx/syscfg.yml b/hw/mcu/nordic/nrf51xxx/syscfg.yml
new file mode 100644
index 0000000..d0c40be
--- /dev/null
+++ b/hw/mcu/nordic/nrf51xxx/syscfg.yml
@@ -0,0 +1,26 @@
+# 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.
+#
+
+# Package: hw/bsp/nrf52dk
+
+syscfg.defs:
+    MCU_FLASH_MIN_WRITE_SIZE:
+        description: >
+            Specifies the required alignment for internal flash writes.
+            Used internally by the newt tool.
+        value: 1

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/929e2563/hw/mcu/nordic/nrf52xxx/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf52xxx/syscfg.yml b/hw/mcu/nordic/nrf52xxx/syscfg.yml
new file mode 100644
index 0000000..d0c40be
--- /dev/null
+++ b/hw/mcu/nordic/nrf52xxx/syscfg.yml
@@ -0,0 +1,26 @@
+# 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.
+#
+
+# Package: hw/bsp/nrf52dk
+
+syscfg.defs:
+    MCU_FLASH_MIN_WRITE_SIZE:
+        description: >
+            Specifies the required alignment for internal flash writes.
+            Used internally by the newt tool.
+        value: 1

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/929e2563/hw/mcu/nxp/MK64F12/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/mcu/nxp/MK64F12/syscfg.yml b/hw/mcu/nxp/MK64F12/syscfg.yml
new file mode 100644
index 0000000..824f039
--- /dev/null
+++ b/hw/mcu/nxp/MK64F12/syscfg.yml
@@ -0,0 +1,26 @@
+# 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.
+#
+
+# Package: hw/bsp/nrf52dk
+
+syscfg.defs:
+    MCU_FLASH_MIN_WRITE_SIZE:
+        description: >
+            Specifies the required alignment for internal flash writes.
+            Used internally by the newt tool.
+        value: 8

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/929e2563/hw/mcu/stm/stm32f4xx/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/mcu/stm/stm32f4xx/syscfg.yml b/hw/mcu/stm/stm32f4xx/syscfg.yml
new file mode 100644
index 0000000..d0c40be
--- /dev/null
+++ b/hw/mcu/stm/stm32f4xx/syscfg.yml
@@ -0,0 +1,26 @@
+# 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.
+#
+
+# Package: hw/bsp/nrf52dk
+
+syscfg.defs:
+    MCU_FLASH_MIN_WRITE_SIZE:
+        description: >
+            Specifies the required alignment for internal flash writes.
+            Used internally by the newt tool.
+        value: 1


[27/50] incubator-mynewt-core git commit: nimble/l2cap: Remove not needed **om from ble_l2cap_rx_fn

Posted by ma...@apache.org.
nimble/l2cap: Remove not needed **om from ble_l2cap_rx_fn

Since this callback function has ble_l2cap_chan as a parameter,
we don't need to provide there os_mbuf with data as this is already
in chan->rx_buf


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/9b3899a0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/9b3899a0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/9b3899a0

Branch: refs/heads/master
Commit: 9b3899a0000e5c0425b097a536e98eee800e0c2e
Parents: 27bc9ed
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Thu Feb 2 15:00:25 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 12:40:42 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/src/ble_att.c               |  6 +++++-
 net/nimble/host/src/ble_hs_hci_evt.c        |  7 ++-----
 net/nimble/host/src/ble_l2cap.c             |  7 +++----
 net/nimble/host/src/ble_l2cap_coc.c         |  2 +-
 net/nimble/host/src/ble_l2cap_priv.h        |  3 +--
 net/nimble/host/src/ble_l2cap_sig.c         |  8 ++++++--
 net/nimble/host/src/ble_sm.c                | 14 +++++++++-----
 net/nimble/host/test/src/ble_hs_test_util.c |  7 ++-----
 net/nimble/host/test/src/ble_l2cap_test.c   |  2 +-
 9 files changed, 30 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9b3899a0/net/nimble/host/src/ble_att.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att.c b/net/nimble/host/src/ble_att.c
index 7876e0d..7fe095b 100644
--- a/net/nimble/host/src/ble_att.c
+++ b/net/nimble/host/src/ble_att.c
@@ -461,11 +461,12 @@ ble_att_chan_mtu(const struct ble_l2cap_chan *chan)
 }
 
 static int
-ble_att_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
+ble_att_rx(struct ble_l2cap_chan *chan)
 {
     const struct ble_att_rx_dispatch_entry *entry;
     uint8_t op;
     uint16_t conn_handle;
+    struct os_mbuf **om;
     int rc;
 
     conn_handle = ble_l2cap_get_conn_handle(chan);
@@ -473,6 +474,9 @@ ble_att_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
         return BLE_HS_ENOTCONN;
     }
 
+    om = &chan->rx_buf;
+    BLE_HS_DBG_ASSERT(*om != NULL);
+
     rc = os_mbuf_copydata(*om, 0, 1, &op);
     if (rc != 0) {
         return BLE_HS_EMSGSIZE;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9b3899a0/net/nimble/host/src/ble_hs_hci_evt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_hci_evt.c b/net/nimble/host/src/ble_hs_hci_evt.c
index 7f868a6..cd98f7f 100644
--- a/net/nimble/host/src/ble_hs_hci_evt.c
+++ b/net/nimble/host/src/ble_hs_hci_evt.c
@@ -612,7 +612,6 @@ ble_hs_hci_evt_acl_process(struct os_mbuf *om)
     struct hci_data_hdr hci_hdr;
     struct ble_hs_conn *conn;
     ble_l2cap_rx_fn *rx_cb;
-    struct os_mbuf *rx_buf;
     uint16_t conn_handle;
     int reject_cid;
     int rc;
@@ -648,7 +647,7 @@ ble_hs_hci_evt_acl_process(struct os_mbuf *om)
         reject_cid = -1;
     } else {
         /* Forward ACL data to L2CAP. */
-        rc = ble_l2cap_rx(conn, &hci_hdr, om, &rx_cb, &rx_buf, &reject_cid);
+        rc = ble_l2cap_rx(conn, &hci_hdr, om, &rx_cb, &reject_cid);
         om = NULL;
     }
 
@@ -658,10 +657,8 @@ ble_hs_hci_evt_acl_process(struct os_mbuf *om)
     case 0:
         /* Final fragment received. */
         BLE_HS_DBG_ASSERT(rx_cb != NULL);
-        BLE_HS_DBG_ASSERT(rx_buf != NULL);
-        rc = rx_cb(conn->bhc_rx_chan, &rx_buf);
+        rc = rx_cb(conn->bhc_rx_chan);
         ble_l2cap_forget_rx(conn, conn->bhc_rx_chan);
-        os_mbuf_free_chain(rx_buf);
         break;
 
     case BLE_HS_EAGAIN:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9b3899a0/net/nimble/host/src/ble_l2cap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap.c b/net/nimble/host/src/ble_l2cap.c
index d909b78..306eac1 100644
--- a/net/nimble/host/src/ble_l2cap.c
+++ b/net/nimble/host/src/ble_l2cap.c
@@ -173,6 +173,7 @@ void
 ble_l2cap_forget_rx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan)
 {
     conn->bhc_rx_chan = NULL;
+    os_mbuf_free_chain(chan->rx_buf);
     chan->rx_buf = NULL;
     chan->rx_len = 0;
 }
@@ -209,7 +210,7 @@ ble_l2cap_append_rx(struct ble_l2cap_chan *chan, struct os_mbuf *frag)
 static int
 ble_l2cap_rx_payload(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
                      struct os_mbuf *om,
-                     ble_l2cap_rx_fn **out_rx_cb, struct os_mbuf **out_rx_buf)
+                     ble_l2cap_rx_fn **out_rx_cb)
 {
     int len_diff;
     int rc;
@@ -231,7 +232,6 @@ ble_l2cap_rx_payload(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
     } else if (len_diff == 0) {
         /* All fragments received. */
         *out_rx_cb = chan->rx_fn;
-        *out_rx_buf = chan->rx_buf;
         rc = 0;
     } else {
         /* More fragments remain. */
@@ -299,7 +299,6 @@ ble_l2cap_rx(struct ble_hs_conn *conn,
              struct hci_data_hdr *hci_hdr,
              struct os_mbuf *om,
              ble_l2cap_rx_fn **out_rx_cb,
-             struct os_mbuf **out_rx_buf,
              int *out_reject_cid)
 {
     struct ble_l2cap_chan *chan;
@@ -367,7 +366,7 @@ ble_l2cap_rx(struct ble_hs_conn *conn,
         goto err;
     }
 
-    rc = ble_l2cap_rx_payload(conn, chan, om, out_rx_cb, out_rx_buf);
+    rc = ble_l2cap_rx_payload(conn, chan, om, out_rx_cb);
     om = NULL;
     if (rc != 0) {
         goto err;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9b3899a0/net/nimble/host/src/ble_l2cap_coc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc.c b/net/nimble/host/src/ble_l2cap_coc.c
index 178370d..ac1b6fa 100644
--- a/net/nimble/host/src/ble_l2cap_coc.c
+++ b/net/nimble/host/src/ble_l2cap_coc.c
@@ -117,7 +117,7 @@ ble_l2cap_coc_srv_find(uint16_t psm)
 }
 
 static int
-ble_l2cap_coc_rx_fn(struct ble_l2cap_chan *chan, struct os_mbuf **rxom)
+ble_l2cap_coc_rx_fn(struct ble_l2cap_chan *chan)
 {
     return 0;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9b3899a0/net/nimble/host/src/ble_l2cap_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_priv.h b/net/nimble/host/src/ble_l2cap_priv.h
index 64ffa22..5db63c3 100644
--- a/net/nimble/host/src/ble_l2cap_priv.h
+++ b/net/nimble/host/src/ble_l2cap_priv.h
@@ -62,7 +62,7 @@ extern struct os_mempool ble_l2cap_chan_pool;
 
 typedef uint8_t ble_l2cap_chan_flags;
 
-typedef int ble_l2cap_rx_fn(struct ble_l2cap_chan *chan, struct os_mbuf **rxom);
+typedef int ble_l2cap_rx_fn(struct ble_l2cap_chan *chan);
 
 struct ble_l2cap_chan {
     SLIST_ENTRY(ble_l2cap_chan) next;
@@ -113,7 +113,6 @@ int ble_l2cap_rx(struct ble_hs_conn *conn,
                  struct hci_data_hdr *hci_hdr,
                  struct os_mbuf *om,
                  ble_l2cap_rx_fn **out_rx_cb,
-                 struct os_mbuf **out_rx_buf,
                  int *out_reject_cid);
 int ble_l2cap_tx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
                  struct os_mbuf *txom);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9b3899a0/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index 93d73ed..abc00ae 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -1012,13 +1012,17 @@ ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan)
  *****************************************************************************/
 
 static int
-ble_l2cap_sig_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
+ble_l2cap_sig_rx(struct ble_l2cap_chan *chan)
 {
     struct ble_l2cap_sig_hdr hdr;
     ble_l2cap_sig_rx_fn *rx_cb;
-    uint16_t conn_handle = chan->conn_handle;
+    uint16_t conn_handle;
+    struct os_mbuf **om;
     int rc;
 
+    conn_handle = chan->conn_handle;
+    om = &chan->rx_buf;
+
     STATS_INC(ble_l2cap_stats, sig_rx);
     BLE_HS_LOG(DEBUG, "L2CAP - rxed signalling msg: ");
     ble_hs_log_mbuf(*om);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9b3899a0/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm.c b/net/nimble/host/src/ble_sm.c
index 603d99c..ef2f41b 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -2326,12 +2326,13 @@ ble_sm_unbond(uint8_t peer_id_addr_type, const uint8_t *peer_id_addr)
 }
 
 static int
-ble_sm_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
+ble_sm_rx(struct ble_l2cap_chan *chan)
 {
     struct ble_sm_result res;
     ble_sm_rx_fn *rx_cb;
     uint8_t op;
     uint16_t conn_handle;
+    struct os_mbuf *om;
     int rc;
 
     STATS_INC(ble_l2cap_stats, sm_rx);
@@ -2341,19 +2342,22 @@ ble_sm_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
         return BLE_HS_ENOTCONN;
     }
 
-    rc = os_mbuf_copydata(*om, 0, 1, &op);
+    om = chan->rx_buf;
+    BLE_HS_DBG_ASSERT(om != NULL);
+
+    rc = os_mbuf_copydata(om, 0, 1, &op);
     if (rc != 0) {
         return BLE_HS_EBADDATA;
     }
 
     /* Strip L2CAP SM header from the front of the mbuf. */
-    os_mbuf_adj(*om, 1);
+    os_mbuf_adj(om, 1);
 
     rx_cb = ble_sm_dispatch_get(op);
     if (rx_cb != NULL) {
         memset(&res, 0, sizeof res);
 
-        rx_cb(conn_handle, om, &res);
+        rx_cb(conn_handle, &om, &res);
         ble_sm_process_result(conn_handle, &res);
         rc = res.app_status;
     } else {
@@ -2491,7 +2495,7 @@ ble_sm_init(void)
  * simple
  */
 static int
-ble_sm_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
+ble_sm_rx(struct ble_l2cap_chan *chan)
 {
     struct ble_sm_pair_fail *cmd;
     struct os_mbuf *txom;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9b3899a0/net/nimble/host/test/src/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_hs_test_util.c b/net/nimble/host/test/src/ble_hs_test_util.c
index 9fa2d3d..d084c39 100644
--- a/net/nimble/host/test/src/ble_hs_test_util.c
+++ b/net/nimble/host/test/src/ble_hs_test_util.c
@@ -934,7 +934,6 @@ ble_hs_test_util_l2cap_rx(uint16_t conn_handle,
 {
     struct ble_hs_conn *conn;
     ble_l2cap_rx_fn *rx_cb;
-    struct os_mbuf *rx_buf;
     int reject_cid;
     int rc;
 
@@ -942,7 +941,7 @@ ble_hs_test_util_l2cap_rx(uint16_t conn_handle,
 
     conn = ble_hs_conn_find(conn_handle);
     if (conn != NULL) {
-        rc = ble_l2cap_rx(conn, hci_hdr, om, &rx_cb, &rx_buf, &reject_cid);
+        rc = ble_l2cap_rx(conn, hci_hdr, om, &rx_cb, &reject_cid);
     } else {
         os_mbuf_free_chain(om);
     }
@@ -953,10 +952,8 @@ ble_hs_test_util_l2cap_rx(uint16_t conn_handle,
         rc = BLE_HS_ENOTCONN;
     } else if (rc == 0) {
         TEST_ASSERT_FATAL(rx_cb != NULL);
-        TEST_ASSERT_FATAL(rx_buf != NULL);
-        rc = rx_cb(conn->bhc_rx_chan, &rx_buf);
+        rc = rx_cb(conn->bhc_rx_chan);
         ble_l2cap_forget_rx(conn, conn->bhc_rx_chan);
-        os_mbuf_free_chain(rx_buf);
     } else if (rc == BLE_HS_EAGAIN) {
         /* More fragments on the way. */
         rc = 0;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9b3899a0/net/nimble/host/test/src/ble_l2cap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_l2cap_test.c b/net/nimble/host/test/src/ble_l2cap_test.c
index e68971d..3fc7876 100644
--- a/net/nimble/host/test/src/ble_l2cap_test.c
+++ b/net/nimble/host/test/src/ble_l2cap_test.c
@@ -94,7 +94,7 @@ ble_l2cap_test_util_verify_tx_update_conn(
 }
 
 static int
-ble_l2cap_test_util_dummy_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
+ble_l2cap_test_util_dummy_rx(struct ble_l2cap_chan *chan)
 {
     return 0;
 }


[35/50] incubator-mynewt-core git commit: nimble/l2cap: Fix for possible memory leak

Posted by ma...@apache.org.
nimble/l2cap: Fix for possible memory leak

With this patch we remove allocated memory for proc in case we could
not allocate signaling request later on.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/34e64862
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/34e64862
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/34e64862

Branch: refs/heads/master
Commit: 34e648624d8b005a1aec4bd6ecb1b6a6a3b3cafa
Parents: 44df175
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Wed Mar 1 09:24:35 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 12:40:42 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_sig.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/34e64862/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index a33ddef..444a8f6 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -990,7 +990,8 @@ ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan)
     req = ble_l2cap_sig_cmd_get(BLE_L2CAP_SIG_OP_DISCONN_REQ, proc->id,
                                 sizeof(*req), &txom);
     if (!req) {
-        return BLE_HS_ENOMEM;
+        rc = BLE_HS_ENOMEM;
+        goto done;
     }
 
     req->dcid = htole16(chan->dcid);
@@ -998,6 +999,7 @@ ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan)
 
     rc = ble_l2cap_sig_tx(proc->conn_handle, txom);
 
+done:
     ble_l2cap_sig_process_status(proc, rc);
 
     return rc;


[41/50] incubator-mynewt-core git commit: MYNEWT-527; nrf51-blenano fix typo in bsp.yml.

Posted by ma...@apache.org.
MYNEWT-527; nrf51-blenano fix typo in bsp.yml.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/84edc0e8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/84edc0e8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/84edc0e8

Branch: refs/heads/master
Commit: 84edc0e894866bf4b27de4cb05dddfa418a00445
Parents: b2ea1dc
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Mar 3 22:00:00 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Mar 3 22:00:00 2017 -0800

----------------------------------------------------------------------
 hw/bsp/nrf51-blenano/bsp.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/84edc0e8/hw/bsp/nrf51-blenano/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-blenano/bsp.yml b/hw/bsp/nrf51-blenano/bsp.yml
index ee95b51..c72efec 100644
--- a/hw/bsp/nrf51-blenano/bsp.yml
+++ b/hw/bsp/nrf51-blenano/bsp.yml
@@ -28,8 +28,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/nrf51-blenano/split-nrf51dk.ld"
 bsp.downloadscript: "hw/bsp/nrf51-blenano/nrf51dk_download.sh"
 bsp.debugscript: "hw/bsp/nrf51-blenano/nrf51dk_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51-blenano/nrf51dk_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51-blenano/nrf51dk_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/nrf51-blenano/nrf51dk_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/nrf51-blenano/nrf51dk_debug.cmd"
 
 bsp.flash_map:
     areas:


[05/50] incubator-mynewt-core git commit: MYNEWT-647 Changes to NMP over OIC scheme

Posted by ma...@apache.org.
MYNEWT-647 Changes to NMP over OIC scheme

This commit addresses the following three issues with NMP over OIC (OMP):

1. Parts of NMP header missing from OMP responses.  This causes problems
when multiplexing OMP among many target devices.

2. Parts of the NMP header are scattered in a few different places.
This works, but it makes it difficult to debug packet traces.

3. NMP errors get lost in translation.  Instead of an NMP message with
an error code, the OMP server sends back a generic "Bad Request" OIC
message.

***** Current Scheme

*** Requests

The NMP op is indicated by the OIC op:
NMP read <=> OIC get
NMP write <=> OIC put

The NMP group and ID are indicated as CoAP URI Query options:

    gr=<group>
    id=<id>

The remaining NMP header fields, seq and flags, are not present.

The NMP payload is the entire CoAP request body. This is identical to the body
of a plain NMP request.

*** Responses

The NMP header is not present. The NMP op is indicated in the payload (see
below), but other header fields cannot be inferred.

Payload consists of a single CBOR key-value pair. For read responses, the key
is "r"; for write responses, the key is "w". The value is a second CBOR map
containing the actual NMP response fields.

Errors encountered during processing of NMP requests are reported via OIC error
responses (bad request, internal server error).

***** Proposed Scheme

*** Requests

    * The OIC op is always the same: put.

    * No URI Query CoAP options.

    * The NMP header is included in the payload as a key-value pair (key="_h").
      This pair is in the root map of the request and is a sibling of the other
      request fields. The value of this pair is the big-endian eight-byte NMP
      header with a length field of 0.

*** Responses

    * As with requests, the NMP header is included in the payload as a
      key-value pair (key="_h").

    * No "r" or "w" field. The response fields are inserted into the root map
      as a sibling of the "_h" pair.

    * Errors encountered during processing of NMP requests are reported
      identically to other NMP responses (embedded NMP response).

*** Notes

    * Keys that start with an underscore are reserved to the OIC manager
      protocol (e.g., "_h"). NMP requests and responses must not name any of
      their fields with a leading underscore.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/860d2d26
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/860d2d26
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/860d2d26

Branch: refs/heads/master
Commit: 860d2d266110918b4a6f923f1e18c9032d13c07d
Parents: a4df93c
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Mar 1 17:41:21 2017 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Mar 2 08:15:05 2017 -0800

----------------------------------------------------------------------
 mgmt/mgmt/include/mgmt/mgmt.h          |  24 ++-
 mgmt/mgmt/src/mgmt.c                   |  22 ++-
 mgmt/newtmgr/include/newtmgr/newtmgr.h |  21 ---
 mgmt/oicmgr/src/oicmgr.c               | 238 ++++++++++++++++++----------
 4 files changed, 192 insertions(+), 113 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/860d2d26/mgmt/mgmt/include/mgmt/mgmt.h
----------------------------------------------------------------------
diff --git a/mgmt/mgmt/include/mgmt/mgmt.h b/mgmt/mgmt/include/mgmt/mgmt.h
index 9b79723..3c402f2 100644
--- a/mgmt/mgmt/include/mgmt/mgmt.h
+++ b/mgmt/mgmt/include/mgmt/mgmt.h
@@ -36,6 +36,10 @@ extern "C" {
 #define STR(x) #x
 #endif
 
+#define NMGR_OP_READ            (0)
+#define NMGR_OP_READ_RSP        (1)
+#define NMGR_OP_WRITE           (2)
+#define NMGR_OP_WRITE_RSP       (3)
 
 /* First 64 groups are reserved for system level newtmgr commands.
  * Per-user commands are then defined after group 64.
@@ -63,6 +67,24 @@ extern "C" {
 #define MGMT_ERR_EBADSTATE  (6)     /* Current state disallows command. */
 #define MGMT_ERR_EPERUSER   (256)
 
+#define NMGR_HDR_SIZE           (8)
+
+struct nmgr_hdr {
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+    uint8_t  nh_op:3;           /* NMGR_OP_XXX */
+    uint8_t  _res1:5;
+#endif
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+    uint8_t  _res1:5;
+    uint8_t  nh_op:3;           /* NMGR_OP_XXX */
+#endif
+    uint8_t  nh_flags;          /* XXX reserved for future flags */
+    uint16_t nh_len;            /* length of the payload */
+    uint16_t nh_group;          /* NMGR_GROUP_XXX */
+    uint8_t  nh_seq;            /* sequence number */
+    uint8_t  nh_id;             /* message ID within group */
+};
+
 struct mgmt_cbuf;
 
 typedef int (*mgmt_handler_func_t)(struct mgmt_cbuf *);
@@ -85,7 +107,7 @@ struct mgmt_group {
             sizeof(struct mgmt_handler));
 
 int mgmt_group_register(struct mgmt_group *group);
-void mgmt_cbuf_setoerr(struct mgmt_cbuf *njb, int errcode);
+int mgmt_cbuf_setoerr(struct mgmt_cbuf *njb, int errcode);
 const struct mgmt_handler *mgmt_find_handler(uint16_t group_id,
   uint16_t handler_id);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/860d2d26/mgmt/mgmt/src/mgmt.c
----------------------------------------------------------------------
diff --git a/mgmt/mgmt/src/mgmt.c b/mgmt/mgmt/src/mgmt.c
index 4ac232a..c1a2a1e 100644
--- a/mgmt/mgmt/src/mgmt.c
+++ b/mgmt/mgmt/src/mgmt.c
@@ -137,14 +137,20 @@ err:
     return (NULL);
 }
 
-void
+int
 mgmt_cbuf_setoerr(struct mgmt_cbuf *cb, int errcode)
 {
-    CborEncoder *penc = &cb->encoder;
-    CborError g_err = CborNoError;
-    CborEncoder rsp;
-    g_err |= cbor_encoder_create_map(penc, &rsp, CborIndefiniteLength);
-    g_err |= cbor_encode_text_stringz(&rsp, "rc");
-    g_err |= cbor_encode_int(&rsp, errcode);
-    g_err |= cbor_encoder_close_container(penc, &rsp);
+    int rc;
+
+    rc = cbor_encode_text_stringz(&cb->encoder, "rc");
+    if (rc != 0) {
+        return rc;
+    }
+
+    rc = cbor_encode_int(&cb->encoder, errcode);
+    if (rc != 0) {
+        return rc;
+    }
+
+    return 0;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/860d2d26/mgmt/newtmgr/include/newtmgr/newtmgr.h
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/include/newtmgr/newtmgr.h b/mgmt/newtmgr/include/newtmgr/newtmgr.h
index 50deb15..1cf314d 100644
--- a/mgmt/newtmgr/include/newtmgr/newtmgr.h
+++ b/mgmt/newtmgr/include/newtmgr/newtmgr.h
@@ -29,27 +29,6 @@
 extern "C" {
 #endif
 
-#define NMGR_OP_READ            (0)
-#define NMGR_OP_READ_RSP        (1)
-#define NMGR_OP_WRITE           (2)
-#define NMGR_OP_WRITE_RSP       (3)
-
-struct nmgr_hdr {
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-    uint8_t  nh_op:3;           /* NMGR_OP_XXX */
-    uint8_t  _res1:5;
-#endif
-#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-    uint8_t  _res1:5;
-    uint8_t  nh_op:3;           /* NMGR_OP_XXX */
-#endif
-    uint8_t  nh_flags;          /* XXX reserved for future flags */
-    uint16_t nh_len;            /* length of the payload */
-    uint16_t nh_group;          /* NMGR_GROUP_XXX */
-    uint8_t  nh_seq;            /* sequence number */
-    uint8_t  nh_id;             /* message ID within group */
-};
-
 struct nmgr_transport;
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/860d2d26/mgmt/oicmgr/src/oicmgr.c
----------------------------------------------------------------------
diff --git a/mgmt/oicmgr/src/oicmgr.c b/mgmt/oicmgr/src/oicmgr.c
index d2110ef..d7d3591 100644
--- a/mgmt/oicmgr/src/oicmgr.c
+++ b/mgmt/oicmgr/src/oicmgr.c
@@ -22,6 +22,7 @@
 
 #include <os/os.h>
 #include <os/endian.h>
+#include <defs/error.h>
 
 #include <assert.h>
 #include <string.h>
@@ -52,9 +53,6 @@ static struct omgr_state omgr_state = {
     .os_event.ev_cb = omgr_event_start,
 };
 
-static void omgr_oic_get(oc_request_t *request, oc_interface_mask_t interface);
-static void omgr_oic_put(oc_request_t *request, oc_interface_mask_t interface);
-
 struct os_eventq *
 mgmt_evq_get(void)
 {
@@ -67,124 +65,199 @@ mgmt_evq_set(struct os_eventq *evq)
     os_eventq_designate(&omgr_state.os_evq, evq, &omgr_state.os_event);
 }
 
-static const struct mgmt_handler *
-omgr_find_handler(const char *q, int qlen)
+static int
+omgr_oic_read_hdr(struct CborValue *cv, struct nmgr_hdr *out_hdr)
 {
-    char id_str[8];
-    int grp = -1;
-    int id = -1;
-    char *str;
-    char *eptr;
-    int slen;
-
-    slen = oc_ri_get_query_value(q, qlen, "gr", &str);
-    if (slen > 0 && slen < sizeof(id_str) - 1) {
-        memcpy(id_str, str, slen);
-        id_str[slen] = '\0';
-        grp = strtoul(id_str, &eptr, 0);
-        if (*eptr != '\0') {
-            return NULL;
-        }
+    size_t hlen;
+    int rc;
+
+    struct cbor_attr_t attrs[] = {
+        [0] = {
+            .attribute = "_h",
+            .type = CborAttrByteStringType,
+            .addr.bytestring.data = (void *)out_hdr,
+            .addr.bytestring.len = &hlen,
+            .nodefault = 1,
+            .len = sizeof *out_hdr,
+        },
+        [1] = { 0 }
+    };
+
+    rc = cbor_read_object(cv, attrs);
+    if (rc != 0 || hlen != sizeof *out_hdr) {
+        return MGMT_ERR_EINVAL;
     }
-    slen = oc_ri_get_query_value(q, qlen, "id", &str);
-    if (slen > 0 && slen < sizeof(id_str) - 1) {
-        memcpy(id_str, str, slen);
-        id_str[slen] = '\0';
-        id = strtoul(id_str, &eptr, 0);
-        if (*eptr != '\0') {
-            return NULL;
-        }
+
+    out_hdr->nh_len = ntohs(out_hdr->nh_len);
+    out_hdr->nh_group = ntohs(out_hdr->nh_group);
+
+    return 0;
+}
+
+static int
+omgr_encode_nmp_hdr(struct CborEncoder *enc, struct nmgr_hdr hdr)
+{
+    int rc;
+
+    rc = cbor_encode_text_string(enc, "_h", 2);
+    if (rc != 0) {
+        return MGMT_ERR_ENOMEM;
+    }
+
+    hdr.nh_len = htons(hdr.nh_len);
+    hdr.nh_group = htons(hdr.nh_group);
+
+    /* Encode the NMP header in the response. */
+    rc = cbor_encode_byte_string(enc, (void *)&hdr, sizeof hdr);
+    if (rc != 0) {
+        return MGMT_ERR_ENOMEM;
+    }
+
+    return 0;
+}
+
+static int
+omgr_send_err_rsp(struct CborEncoder *enc, const struct nmgr_hdr *hdr,
+                  int nmp_status)
+{
+    int rc;
+
+    rc = omgr_encode_nmp_hdr(enc, *hdr);
+    if (rc != 0) {
+        return rc;
+    }
+
+    rc = cbor_encode_text_stringz(enc, "rc");
+    if (rc != 0) {
+        return MGMT_ERR_ENOMEM;
+    }
+
+    rc = cbor_encode_int(enc, nmp_status);
+    if (rc != 0) {
+        return MGMT_ERR_ENOMEM;
     }
-    return mgmt_find_handler(grp, id);
+
+    return 0;
 }
 
 static void
-omgr_oic_op(oc_request_t *req, oc_interface_mask_t mask, int isset)
+omgr_oic_put(oc_request_t *req, oc_interface_mask_t mask)
 {
     struct omgr_state *o = &omgr_state;
     const struct mgmt_handler *handler;
     uint16_t data_off;
     struct os_mbuf *m;
     int rc = 0;
-    extern CborEncoder g_encoder;
+    struct nmgr_hdr hdr;
+    int rsp_hdr_filled = 0;
 
-    if (!req->query_len) {
-        goto bad_req;
-    }
-
-    handler = omgr_find_handler(req->query, req->query_len);
-    if (!handler) {
-        goto bad_req;
-    }
+    coap_get_payload(req->packet, &m, &data_off);
 
-    rc = coap_get_payload(req->packet, &m, &data_off);
     cbor_mbuf_reader_init(&o->os_cbuf.ob_reader, m, data_off);
-
     cbor_parser_init(&o->os_cbuf.ob_reader.r, 0, &o->os_cbuf.ob_mj.parser,
                      &o->os_cbuf.ob_mj.it);
 
-    /* start generating the CBOR OUTPUT */
-    /* this is worth a quick note.  We are encoding CBOR within CBOR, so we
-     * need to use the same encoder as ocf stack.  We are using their global
-     * encoder g_encoder which they intialized before this function is called.
-     * But we can't call their macros here as it won't use the right mape
-     * encoder (ob_mj) */
+    rc = omgr_oic_read_hdr(&o->os_cbuf.ob_mj.it, &hdr);
+    if (rc != 0) {
+        rc = MGMT_ERR_EINVAL;
+        goto done;
+    }
+
+    /* Convert request header to response header to be sent. */
+    switch (hdr.nh_op) {
+    case NMGR_OP_READ:
+        hdr.nh_op = NMGR_OP_READ_RSP;
+        break;
+
+    case NMGR_OP_WRITE:
+        hdr.nh_op = NMGR_OP_WRITE_RSP;
+        break;
+
+    default:
+        goto done;
+    }
+    rsp_hdr_filled = 1;
+
+    /* Begin root map in response. */
     cbor_encoder_create_map(&g_encoder, &o->os_cbuf.ob_mj.encoder,
                             CborIndefiniteLength);
 
+    handler = mgmt_find_handler(hdr.nh_group, hdr.nh_id);
+    if (handler == NULL) {
+        rc = MGMT_ERR_ENOENT;
+        goto done;
+    }
+
+    cbor_mbuf_reader_init(&o->os_cbuf.ob_reader, m, data_off);
+    cbor_parser_init(&o->os_cbuf.ob_reader.r, 0, &o->os_cbuf.ob_mj.parser,
+                     &o->os_cbuf.ob_mj.it);
+
     switch (mask) {
     case OC_IF_BASELINE:
         oc_process_baseline_interface(req->resource);
+        /* Fallthrough */
+
     case OC_IF_RW:
-        if (!isset) {
-            cbor_encode_text_string(&root_map, "r", 1);
-            if (handler->mh_read) {
-                rc = handler->mh_read(&o->os_cbuf.ob_mj);
+        switch (hdr.nh_op) {
+        case NMGR_OP_READ_RSP:
+            if (handler->mh_read == NULL) {
+                rc = MGMT_ERR_ENOENT;
             } else {
-                goto bad_req;
+                rc = handler->mh_read(&o->os_cbuf.ob_mj);
             }
-        } else {
-            cbor_encode_text_string(&root_map, "w", 1);
-            if (handler->mh_write) {
-                rc = handler->mh_write(&o->os_cbuf.ob_mj);
+            break;
+
+        case NMGR_OP_WRITE_RSP:
+            if (handler->mh_write == NULL) {
+                rc = MGMT_ERR_ENOENT;
             } else {
-                goto bad_req;
+                rc = handler->mh_write(&o->os_cbuf.ob_mj);
             }
+            break;
+
+        default:
+            rc = MGMT_ERR_EINVAL;
+            break;
         }
-        if (rc) {
-            goto bad_req;
+        if (rc != 0) {
+            goto done;
+        }
+
+        /* Encode the NMP header in the response. */
+        rc = omgr_encode_nmp_hdr(&o->os_cbuf.ob_mj.encoder, hdr);
+        if (rc != 0) {
+            rc = MGMT_ERR_ENOMEM;
+            goto done;
         }
         break;
+
     default:
         break;
     }
 
-    cbor_encoder_close_container(&g_encoder, &o->os_cbuf.ob_mj.encoder);
-    oc_send_response(req, OC_STATUS_OK);
+    rc = 0;
 
-    return;
-bad_req:
-    /*
-     * XXXX might send partially constructed response as payload
-     */
-    if (rc == MGMT_ERR_ENOMEM) {
-        rc = OC_STATUS_INTERNAL_SERVER_ERROR;
-    } else {
-        rc = OC_STATUS_BAD_REQUEST;
-    }
-    oc_send_response(req, rc);
-}
+done:
+    if (rc != 0) {
+        if (rsp_hdr_filled) {
+            rc = omgr_send_err_rsp(&g_encoder, &hdr, rc);
+        }
+        switch (rc) {
+        case 0:
+            break;
 
-static void
-omgr_oic_get(oc_request_t *req, oc_interface_mask_t mask)
-{
-    omgr_oic_op(req, mask, 0);
-}
+        case MGMT_ERR_ENOMEM:
+            rc = OC_STATUS_INTERNAL_SERVER_ERROR;
+            break;
 
-static void
-omgr_oic_put(oc_request_t *req, oc_interface_mask_t mask)
-{
-    omgr_oic_op(req, mask, 1);
+        default:
+            rc = OC_STATUS_BAD_REQUEST;
+            break;
+        }
+    }
+
+    cbor_encoder_close_container(&g_encoder, &o->os_cbuf.ob_mj.encoder);
+    oc_send_response(req, rc);
 }
 
 static void
@@ -204,7 +277,6 @@ omgr_event_start(struct os_event *ev)
     oc_resource_bind_resource_interface(res, mode);
     oc_resource_set_default_interface(res, mode);
     oc_resource_set_discoverable(res);
-    oc_resource_set_request_handler(res, OC_GET, omgr_oic_get);
     oc_resource_set_request_handler(res, OC_PUT, omgr_oic_put);
     oc_add_resource(res);
 }


[33/50] incubator-mynewt-core git commit: nimble/l2cap: Improve L2CAP LE CoC connection handling

Posted by ma...@apache.org.
nimble/l2cap: Improve L2CAP LE CoC connection handling

With this patch we make sure remote does not use already used CID


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/6963daf8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/6963daf8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/6963daf8

Branch: refs/heads/master
Commit: 6963daf878259509b367e9a538302429bb5da0da
Parents: 38ae570
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Wed Mar 1 11:42:43 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 12:40:42 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_sig.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6963daf8/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index 439acfe..1840b0a 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -658,14 +658,19 @@ ble_l2cap_sig_coc_req_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
     ble_hs_lock();
     conn = ble_hs_conn_find_assert(conn_handle);
 
-    /* Verify CID */
+    /* Verify CID. Note, scid in the request is dcid for out local channel */
     scid = le16toh(req->scid);
     if (scid < BLE_L2CAP_COC_CID_START || scid > BLE_L2CAP_COC_CID_END) {
-        /*FIXME: Check if SCID is not already used */
         rsp->result = htole16(BLE_L2CAP_COC_ERR_INVALID_SOURCE_CID);
         goto failed;
     }
 
+    chan = ble_hs_conn_chan_find_by_dcid(conn, scid);
+    if (chan) {
+        rsp->result = htole16(BLE_L2CAP_COC_ERR_SOURCE_CID_ALREADY_USED);
+        goto failed;
+    }
+
     rc = ble_l2cap_coc_create_srv_chan(conn_handle, le16toh(req->psm), &chan);
     if (rc != 0) {
         uint16_t coc_err = ble_l2cap_sig_ble_hs_err2coc_err(rc);


[22/50] incubator-mynewt-core git commit: nimble/l2cap: Refactor update parameters handling

Posted by ma...@apache.org.
nimble/l2cap: Refactor update parameters handling

With this patch l2cap update parameters is handled in similar way as
other signaling commands.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/98ebb513
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/98ebb513
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/98ebb513

Branch: refs/heads/master
Commit: 98ebb5133ac345d8a9a93b335722e88b68373673
Parents: 506e373
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Thu Feb 2 10:21:57 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 12:40:42 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_sig.c         | 55 +++++++++-----
 net/nimble/host/src/ble_l2cap_sig_cmd.c     | 94 ------------------------
 net/nimble/host/src/ble_l2cap_sig_priv.h    | 17 +----
 net/nimble/host/test/src/ble_hs_test_util.c | 42 ++++++++++-
 net/nimble/host/test/src/ble_l2cap_test.c   | 20 ++++-
 5 files changed, 98 insertions(+), 130 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98ebb513/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index 9292137..7919a89 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -336,7 +336,9 @@ ble_l2cap_sig_update_req_rx(uint16_t conn_handle,
                             struct ble_l2cap_sig_hdr *hdr,
                             struct os_mbuf **om)
 {
-    struct ble_l2cap_sig_update_req req;
+    struct ble_l2cap_sig_update_req *req;
+    struct os_mbuf *txom;
+    struct ble_l2cap_sig_update_rsp *rsp;
     struct ble_gap_upd_params params;
     ble_hs_conn_flags_t conn_flags;
     uint16_t l2cap_result;
@@ -361,12 +363,12 @@ ble_l2cap_sig_update_req_rx(uint16_t conn_handle,
         return BLE_HS_EREJECT;
     }
 
-    ble_l2cap_sig_update_req_parse((*om)->om_data, (*om)->om_len, &req);
+    req = (struct ble_l2cap_sig_update_req *)(*om)->om_data;
 
-    params.itvl_min = req.itvl_min;
-    params.itvl_max = req.itvl_max;
-    params.latency = req.slave_latency;
-    params.supervision_timeout = req.timeout_multiplier;
+    params.itvl_min = le16toh(req->itvl_min);
+    params.itvl_max = le16toh(req->itvl_max);
+    params.latency = le16toh(req->slave_latency);
+    params.supervision_timeout = le16toh(req->timeout_multiplier);
     params.min_ce_len = BLE_GAP_INITIAL_CONN_MIN_CE_LEN;
     params.max_ce_len = BLE_GAP_INITIAL_CONN_MAX_CE_LEN;
 
@@ -383,11 +385,19 @@ ble_l2cap_sig_update_req_rx(uint16_t conn_handle,
         l2cap_result = BLE_L2CAP_SIG_UPDATE_RSP_RESULT_REJECT;
     }
 
+    rsp = ble_l2cap_sig_cmd_get(BLE_L2CAP_SIG_OP_UPDATE_RSP, hdr->identifier,
+                                sizeof(*rsp), &txom);
+    if (!rsp) {
+        /* No memory for response, lest allow to timeout on remote side */
+        return 0;
+    }
+
+    rsp->result = htole16(l2cap_result);
+
     /* Send L2CAP response. */
-    rc = ble_l2cap_sig_update_rsp_tx(conn_handle, hdr->identifier,
-                                         l2cap_result);
+    ble_l2cap_sig_tx(conn_handle, txom);
 
-    return rc;
+    return 0;
 }
 
 static int
@@ -395,7 +405,7 @@ ble_l2cap_sig_update_rsp_rx(uint16_t conn_handle,
                             struct ble_l2cap_sig_hdr *hdr,
                             struct os_mbuf **om)
 {
-    struct ble_l2cap_sig_update_rsp rsp;
+    struct ble_l2cap_sig_update_rsp *rsp;
     struct ble_l2cap_sig_proc *proc;
     int cb_status;
     int rc;
@@ -413,9 +423,9 @@ ble_l2cap_sig_update_rsp_rx(uint16_t conn_handle,
         goto done;
     }
 
-    ble_l2cap_sig_update_rsp_parse((*om)->om_data, (*om)->om_len, &rsp);
+    rsp = (struct ble_l2cap_sig_update_rsp *)(*om)->om_data;
 
-    switch (rsp.result) {
+    switch (le16toh(rsp->result)) {
     case BLE_L2CAP_SIG_UPDATE_RSP_RESULT_ACCEPT:
         cb_status = 0;
         rc = 0;
@@ -443,7 +453,8 @@ ble_l2cap_sig_update(uint16_t conn_handle,
                      struct ble_l2cap_sig_update_params *params,
                      ble_l2cap_sig_update_fn *cb, void *cb_arg)
 {
-    struct ble_l2cap_sig_update_req req;
+    struct os_mbuf *txom;
+    struct ble_l2cap_sig_update_req *req;
     struct ble_l2cap_sig_proc *proc;
     struct ble_l2cap_chan *chan;
     struct ble_hs_conn *conn;
@@ -481,12 +492,20 @@ ble_l2cap_sig_update(uint16_t conn_handle,
     proc->update.cb = cb;
     proc->update.cb_arg = cb_arg;
 
-    req.itvl_min = params->itvl_min;
-    req.itvl_max = params->itvl_max;
-    req.slave_latency = params->slave_latency;
-    req.timeout_multiplier = params->timeout_multiplier;
+    req = ble_l2cap_sig_cmd_get(BLE_L2CAP_SIG_OP_UPDATE_REQ, proc->id,
+                                sizeof(*req), &txom);
+    if (!req) {
+        STATS_INC(ble_l2cap_stats, update_fail);
+        rc = BLE_HS_ENOMEM;
+        goto done;
+    }
 
-    rc = ble_l2cap_sig_update_req_tx(conn_handle, proc->id, &req);
+    req->itvl_min = htole16(params->itvl_min);
+    req->itvl_max = htole16(params->itvl_max);
+    req->slave_latency = htole16(params->slave_latency);
+    req->timeout_multiplier = htole16(params->timeout_multiplier);
+
+    rc = ble_l2cap_sig_tx(conn_handle, txom);
 
 done:
     ble_l2cap_sig_process_status(proc, rc);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98ebb513/net/nimble/host/src/ble_l2cap_sig_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig_cmd.c b/net/nimble/host/src/ble_l2cap_sig_cmd.c
index f7e68c8..189efd7 100644
--- a/net/nimble/host/src/ble_l2cap_sig_cmd.c
+++ b/net/nimble/host/src/ble_l2cap_sig_cmd.c
@@ -158,99 +158,6 @@ ble_l2cap_sig_reject_invalid_cid_tx(uint16_t conn_handle, uint8_t id,
                                  &data, sizeof data);
 }
 
-static void
-ble_l2cap_sig_update_req_swap(struct ble_l2cap_sig_update_req *dst,
-                              struct ble_l2cap_sig_update_req *src)
-{
-    dst->itvl_min = TOFROMLE16(src->itvl_min);
-    dst->itvl_max = TOFROMLE16(src->itvl_max);
-    dst->slave_latency = TOFROMLE16(src->slave_latency);
-    dst->timeout_multiplier = TOFROMLE16(src->timeout_multiplier);
-}
-
-void
-ble_l2cap_sig_update_req_parse(void *payload, int len,
-                               struct ble_l2cap_sig_update_req *dst)
-{
-    BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_REQ_SZ);
-    ble_l2cap_sig_update_req_swap(dst, payload);
-}
-
-void
-ble_l2cap_sig_update_req_write(void *payload, int len,
-                               struct ble_l2cap_sig_update_req *src)
-{
-    BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_REQ_SZ);
-    ble_l2cap_sig_update_req_swap(payload, src);
-}
-
-int
-ble_l2cap_sig_update_req_tx(uint16_t conn_handle, uint8_t id,
-                            struct ble_l2cap_sig_update_req *req)
-{
-    struct os_mbuf *txom;
-    void *payload_buf;
-    int rc;
-
-    rc = ble_l2cap_sig_init_cmd(BLE_L2CAP_SIG_OP_UPDATE_REQ, id,
-                                BLE_L2CAP_SIG_UPDATE_REQ_SZ, &txom,
-                                &payload_buf);
-    if (rc != 0) {
-        return rc;
-    }
-
-    ble_l2cap_sig_update_req_write(payload_buf, BLE_L2CAP_SIG_UPDATE_REQ_SZ,
-                                   req);
-
-    return ble_l2cap_sig_tx(conn_handle, txom);
-}
-
-static void
-ble_l2cap_sig_update_rsp_swap(struct ble_l2cap_sig_update_rsp *dst,
-                              struct ble_l2cap_sig_update_rsp *src)
-{
-    dst->result = TOFROMLE16(src->result);
-}
-
-void
-ble_l2cap_sig_update_rsp_parse(void *payload, int len,
-                               struct ble_l2cap_sig_update_rsp *dst)
-{
-    BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_RSP_SZ);
-    ble_l2cap_sig_update_rsp_swap(dst, payload);
-}
-
-void
-ble_l2cap_sig_update_rsp_write(void *payload, int len,
-                               struct ble_l2cap_sig_update_rsp *src)
-{
-    BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_RSP_SZ);
-    ble_l2cap_sig_update_rsp_swap(payload, src);
-}
-
-int
-ble_l2cap_sig_update_rsp_tx(uint16_t conn_handle, uint8_t id, uint16_t result)
-{
-    struct ble_l2cap_sig_update_rsp rsp;
-    struct os_mbuf *txom;
-    void *payload_buf;
-    int rc;
-
-    rc = ble_l2cap_sig_init_cmd(BLE_L2CAP_SIG_OP_UPDATE_RSP, id,
-                                BLE_L2CAP_SIG_UPDATE_RSP_SZ, &txom,
-                                &payload_buf);
-    if (rc != 0) {
-        return rc;
-    }
-
-    rsp.result = result;
-    ble_l2cap_sig_update_rsp_write(payload_buf, BLE_L2CAP_SIG_UPDATE_RSP_SZ,
-                                   &rsp);
-
-    return ble_l2cap_sig_tx(conn_handle, txom);
-}
-
-#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
 void *
 ble_l2cap_sig_cmd_get(uint8_t opcode, uint8_t id, uint16_t len,
                       struct os_mbuf **txom)
@@ -275,4 +182,3 @@ ble_l2cap_sig_cmd_get(uint8_t opcode, uint8_t id, uint16_t len,
 
     return hdr->data;
 }
-#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98ebb513/net/nimble/host/src/ble_l2cap_sig_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig_priv.h b/net/nimble/host/src/ble_l2cap_sig_priv.h
index 48bff7e..f089dcb 100644
--- a/net/nimble/host/src/ble_l2cap_sig_priv.h
+++ b/net/nimble/host/src/ble_l2cap_sig_priv.h
@@ -92,28 +92,15 @@ void ble_l2cap_sig_hdr_write(void *payload, uint16_t len,
 int ble_l2cap_sig_reject_tx(uint16_t conn_handle,
                             uint8_t id, uint16_t reason,
                             void *data, int data_len);
-void ble_l2cap_sig_update_req_parse(void *payload, int len,
-                                    struct ble_l2cap_sig_update_req *req);
-void ble_l2cap_sig_update_req_write(void *payload, int len,
-                                    struct ble_l2cap_sig_update_req *src);
-int ble_l2cap_sig_update_req_tx(uint16_t conn_handle, uint8_t id,
-                                struct ble_l2cap_sig_update_req *req);
-void ble_l2cap_sig_update_rsp_parse(void *payload, int len,
-                                    struct ble_l2cap_sig_update_rsp *cmd);
-void ble_l2cap_sig_update_rsp_write(void *payload, int len,
-                                    struct ble_l2cap_sig_update_rsp *src);
-int ble_l2cap_sig_update_rsp_tx(uint16_t conn_handle, uint8_t id,
-                                uint16_t result);
 int ble_l2cap_sig_reject_invalid_cid_tx(uint16_t conn_handle, uint8_t id,
                                         uint16_t src_cid, uint16_t dst_cid);
 int ble_l2cap_sig_tx(uint16_t conn_handle, struct os_mbuf *txom);
+void *ble_l2cap_sig_cmd_get(uint8_t opcode, uint8_t id, uint16_t len,
+                            struct os_mbuf **txom);
 #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
 int ble_l2cap_sig_coc_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
                               struct os_mbuf *sdu_rx,
                               ble_l2cap_event_fn *cb, void *cb_arg);
-void *ble_l2cap_sig_cmd_get(uint8_t opcode, uint8_t id, uint16_t len,
-                            struct os_mbuf **txom);
-
 int ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan);
 #else
 #define ble_l2cap_sig_coc_connect(conn_handle, psm, mtu, sdu_rx, cb, cb_arg) \

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98ebb513/net/nimble/host/test/src/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_hs_test_util.c b/net/nimble/host/test/src/ble_hs_test_util.c
index cd9e1b2..ceabd1c 100644
--- a/net/nimble/host/test/src/ble_hs_test_util.c
+++ b/net/nimble/host/test/src/ble_hs_test_util.c
@@ -1764,6 +1764,24 @@ ble_hs_test_util_verify_tx_l2cap_sig_hdr(uint8_t op, uint8_t id,
     return om;
 }
 
+static void
+ble_l2cap_test_update_req_swap(struct ble_l2cap_sig_update_req *dst,
+                               struct ble_l2cap_sig_update_req *src)
+{
+    dst->itvl_min = le16toh(src->itvl_min);
+    dst->itvl_max = le16toh(src->itvl_max);
+    dst->slave_latency = le16toh(src->slave_latency);
+    dst->timeout_multiplier = le16toh(src->timeout_multiplier);
+}
+
+static void
+ble_l2cap_test_update_req_parse(void *payload, int len,
+                               struct ble_l2cap_sig_update_req *dst)
+{
+    BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_REQ_SZ);
+    ble_l2cap_test_update_req_swap(dst, payload);
+}
+
 /**
  * @return                      The L2CAP sig identifier in the request.
  */
@@ -1783,7 +1801,7 @@ ble_hs_test_util_verify_tx_l2cap_update_req(
                                                   &hdr);
 
     /* Verify payload. */
-    ble_l2cap_sig_update_req_parse(om->om_data, om->om_len, &req);
+    ble_l2cap_test_update_req_parse(om->om_data, om->om_len, &req);
     TEST_ASSERT(req.itvl_min == params->itvl_min);
     TEST_ASSERT(req.itvl_max == params->itvl_max);
     TEST_ASSERT(req.slave_latency == params->slave_latency);
@@ -1792,6 +1810,26 @@ ble_hs_test_util_verify_tx_l2cap_update_req(
     return hdr.identifier;
 }
 
+static void
+ble_l2cap_sig_update_rsp_parse(void *payload, int len,
+                               struct ble_l2cap_sig_update_rsp *dst)
+{
+    struct ble_l2cap_sig_update_rsp *src = payload;
+
+    BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_RSP_SZ);
+    dst->result = le16toh(src->result);
+}
+
+static void
+ble_l2cap_test_update_rsp_write(void *payload, int len,
+                               struct ble_l2cap_sig_update_rsp *src)
+{
+    struct ble_l2cap_sig_update_rsp *dst = payload;
+
+    BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_RSP_SZ);
+    dst->result = htole16(src->result);
+}
+
 int
 ble_hs_test_util_rx_l2cap_update_rsp(uint16_t conn_handle,
                                      uint8_t id, uint16_t result)
@@ -1811,7 +1849,7 @@ ble_hs_test_util_rx_l2cap_update_rsp(uint16_t conn_handle,
     TEST_ASSERT_FATAL(rc == 0);
 
     rsp.result = result;
-    ble_l2cap_sig_update_rsp_write(v, BLE_L2CAP_SIG_UPDATE_RSP_SZ, &rsp);
+    ble_l2cap_test_update_rsp_write(v, BLE_L2CAP_SIG_UPDATE_RSP_SZ, &rsp);
 
     rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SIG,
                                               &hci_hdr, om);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98ebb513/net/nimble/host/test/src/ble_l2cap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_l2cap_test.c b/net/nimble/host/test/src/ble_l2cap_test.c
index f4f16bc..2958a6c 100644
--- a/net/nimble/host/test/src/ble_l2cap_test.c
+++ b/net/nimble/host/test/src/ble_l2cap_test.c
@@ -44,6 +44,24 @@ ble_l2cap_test_util_init(void)
 }
 
 static void
+ble_l2cap_test_update_req_swap(struct ble_l2cap_sig_update_req *dst,
+                              struct ble_l2cap_sig_update_req *src)
+{
+    dst->itvl_min = le16toh(src->itvl_min);
+    dst->itvl_max = le16toh(src->itvl_max);
+    dst->slave_latency = le16toh(src->slave_latency);
+    dst->timeout_multiplier = le16toh(src->timeout_multiplier);
+}
+
+static void
+ble_l2cap_test_update_req_write(void *payload, int len,
+                               struct ble_l2cap_sig_update_req *src)
+{
+    BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_REQ_SZ);
+    ble_l2cap_test_update_req_swap(payload, src);
+}
+
+static void
 ble_l2cap_test_util_rx_update_req(uint16_t conn_handle, uint8_t id,
                                   struct ble_l2cap_sig_update_params *params)
 {
@@ -65,7 +83,7 @@ ble_l2cap_test_util_rx_update_req(uint16_t conn_handle, uint8_t id,
     req.itvl_max = params->itvl_max;
     req.slave_latency = params->slave_latency;
     req.timeout_multiplier = params->timeout_multiplier;
-    ble_l2cap_sig_update_req_write(v, BLE_L2CAP_SIG_UPDATE_REQ_SZ, &req);
+    ble_l2cap_test_update_req_write(v, BLE_L2CAP_SIG_UPDATE_REQ_SZ, &req);
 
     ble_hs_test_util_set_ack(
         ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE,


[36/50] incubator-mynewt-core git commit: nimble/l2cap: Add initial credits calculations

Posted by ma...@apache.org.
nimble/l2cap: Add initial credits calculations

With this patch we calculate initial credits in that way that
peer device is able to send full SDU by fill up fully LE frames.

If it happens that peer is not filling up LE Frames, there is mechanism
to handling it already in receiving function


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/750707ba
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/750707ba
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/750707ba

Branch: refs/heads/master
Commit: 750707ba60915ea182d416c8289324d16af8fa64
Parents: 6963daf
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Fri Mar 3 11:30:45 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 12:40:43 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_coc.c  | 16 ++++++++++------
 net/nimble/host/src/ble_l2cap_priv.h |  1 +
 2 files changed, 11 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/750707ba/net/nimble/host/src/ble_l2cap_coc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc.c b/net/nimble/host/src/ble_l2cap_coc.c
index f7ecef4..fbfbf31 100644
--- a/net/nimble/host/src/ble_l2cap_coc.c
+++ b/net/nimble/host/src/ble_l2cap_coc.c
@@ -249,9 +249,14 @@ ble_l2cap_coc_chan_alloc(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
     chan->my_mtu = BLE_L2CAP_COC_MTU;
     chan->rx_fn = ble_l2cap_coc_rx_fn;
     chan->coc_rx.mtu = mtu;
-    chan->coc_rx.credits = 10; /* FIXME Calculate it */
     chan->coc_rx.sdu = sdu_rx;
 
+    /* Number of credits should allow to send full SDU with on given
+     * L2CAP MTU
+     */
+    chan->coc_rx.credits = (mtu + (chan->my_mtu - 1) / 2) / chan->my_mtu;
+
+    chan->initial_credits = chan->coc_rx.credits;
     return chan;
 }
 
@@ -459,13 +464,12 @@ ble_l2cap_coc_recv_ready(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_rx)
         return;
     }
 
-    /* FIXME 10 is hardcoded - make it better.
-     * We want to back only that much credits which remote side is missing
+    /* We want to back only that much credits which remote side is missing
      * to be able to send complete SDU.
      */
-    if (chan->coc_rx.credits < 10) {
-        ble_l2cap_sig_le_credits(chan, 10 - chan->coc_rx.credits);
-        chan->coc_rx.credits = 10;
+    if (chan->coc_rx.credits < c->initial_credits) {
+        ble_l2cap_sig_le_credits(chan, c->initial_credits - chan->coc_rx.credits);
+        chan->coc_rx.credits = c->initial_credits;
     }
 
     ble_hs_unlock();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/750707ba/net/nimble/host/src/ble_l2cap_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_priv.h b/net/nimble/host/src/ble_l2cap_priv.h
index 5db63c3..1d035e8 100644
--- a/net/nimble/host/src/ble_l2cap_priv.h
+++ b/net/nimble/host/src/ble_l2cap_priv.h
@@ -82,6 +82,7 @@ struct ble_l2cap_chan {
     uint16_t psm;
     struct ble_l2cap_coc_endpoint coc_rx;
     struct ble_l2cap_coc_endpoint coc_tx;
+    uint16_t initial_credits;
     ble_l2cap_event_fn *cb;
     void *cb_arg;
 #endif


[46/50] incubator-mynewt-core git commit: This closes #192.

Posted by ma...@apache.org.
This closes #192.

Merge remote-tracking branch 'simonratner/fix-ble-uuid-cmp' into develop

* simonratner/fix-ble-uuid-cmp:
  Fix invalid memory accesses in ble_uuid_cmp


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/f052c825
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/f052c825
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/f052c825

Branch: refs/heads/master
Commit: f052c82582aec11ce4b46a5534b534d19fafc035
Parents: 847f024 d50951d
Author: Christopher Collins <cc...@apache.org>
Authored: Sat Mar 4 14:29:50 2017 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Sat Mar 4 14:29:50 2017 -0800

----------------------------------------------------------------------
 net/nimble/host/src/ble_uuid.c | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------



[32/50] incubator-mynewt-core git commit: nimble/l2cap: Handle REJECT CMD on L2CAP LE CoC connection create req

Posted by ma...@apache.org.
nimble/l2cap: Handle REJECT CMD on L2CAP LE CoC connection create req

With this patch, if legacy device response with REJECT CMD on
LE Create Base Connection request, application will be corretly
notified.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/44df175e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/44df175e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/44df175e

Branch: refs/heads/master
Commit: 44df175e480d0935346edf5b5b8be3bfa03f3304
Parents: e488b9d
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Sun Feb 12 21:49:47 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 12:40:42 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_coc.c |  5 ++++
 net/nimble/host/src/ble_l2cap_sig.c | 39 +++++++++++++++++++++++++++++++-
 2 files changed, 43 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/44df175e/net/nimble/host/src/ble_l2cap_coc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc.c b/net/nimble/host/src/ble_l2cap_coc.c
index ec01fec..f7ecef4 100644
--- a/net/nimble/host/src/ble_l2cap_coc.c
+++ b/net/nimble/host/src/ble_l2cap_coc.c
@@ -281,6 +281,11 @@ ble_l2cap_event_coc_disconnected(struct ble_l2cap_chan *chan)
 {
     struct ble_l2cap_event event = { };
 
+    /* FIXME */
+    if (!chan->cb) {
+        return;
+    }
+
     event.type = BLE_L2CAP_EVENT_COC_DISCONNECTED;
     event.disconnect.conn_handle = chan->conn_handle;
     event.disconnect.chan = chan;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/44df175e/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index b77fa3b..a33ddef 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -92,6 +92,7 @@ typedef int ble_l2cap_sig_rx_fn(uint16_t conn_handle,
 static ble_l2cap_sig_rx_fn ble_l2cap_sig_rx_noop;
 static ble_l2cap_sig_rx_fn ble_l2cap_sig_update_req_rx;
 static ble_l2cap_sig_rx_fn ble_l2cap_sig_update_rsp_rx;
+static ble_l2cap_sig_rx_fn ble_l2cap_sig_rx_reject;
 
 #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
 static ble_l2cap_sig_rx_fn ble_l2cap_sig_coc_req_rx;
@@ -108,7 +109,7 @@ static ble_l2cap_sig_rx_fn ble_l2cap_sig_le_credits_rx;
 #endif
 
 static ble_l2cap_sig_rx_fn * const ble_l2cap_sig_dispatch[] = {
-    [BLE_L2CAP_SIG_OP_REJECT]               = ble_l2cap_sig_rx_noop,
+    [BLE_L2CAP_SIG_OP_REJECT]               = ble_l2cap_sig_rx_reject,
     [BLE_L2CAP_SIG_OP_CONNECT_RSP]          = ble_l2cap_sig_rx_noop,
     [BLE_L2CAP_SIG_OP_CONFIG_RSP]           = ble_l2cap_sig_rx_noop,
     [BLE_L2CAP_SIG_OP_DISCONN_REQ]          = ble_l2cap_sig_disc_req_rx,
@@ -613,6 +614,15 @@ ble_l2cap_sig_coc_connect_cb(struct ble_l2cap_sig_proc *proc, int status)
     }
 
     ble_l2cap_event_coc_connected(chan, status);
+
+    if (status) {
+        /* Normally in channel free we send disconnected event to application.
+         * However in case on error during creation connection we send connected
+         * event with error status. To avoid additional disconnected event lets
+         * clear callbacks since we don't needed it anymore.*/
+        chan->cb = NULL;
+        ble_l2cap_chan_free(chan);
+    }
 }
 
 static int
@@ -1037,6 +1047,33 @@ ble_l2cap_sig_le_credits(struct ble_l2cap_chan *chan, uint16_t credits)
     return ble_l2cap_sig_tx(chan->conn_handle, txom);
 }
 #endif
+
+static int
+ble_l2cap_sig_rx_reject(uint16_t conn_handle,
+                        struct ble_l2cap_sig_hdr *hdr,
+                        struct os_mbuf **om)
+{
+    struct ble_l2cap_sig_proc *proc;
+    proc = ble_l2cap_sig_proc_extract(conn_handle,
+                                         BLE_L2CAP_SIG_PROC_OP_CONNECT,
+                                         hdr->identifier);
+   if (!proc) {
+       return 0;
+   }
+
+   switch (proc->id) {
+#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
+       case BLE_L2CAP_SIG_PROC_OP_CONNECT:
+           ble_l2cap_sig_coc_connect_cb(proc, BLE_HS_EREJECT);
+           break;
+#endif
+       default:
+           break;
+   }
+
+   ble_l2cap_sig_proc_free(proc);
+   return 0;
+}
 /*****************************************************************************
  * $misc                                                                     *
  *****************************************************************************/


[18/50] incubator-mynewt-core git commit: bletiny: Add support to send data over L2CAP LE CoC

Posted by ma...@apache.org.
bletiny: Add support to send data over L2CAP LE CoC

With this patch user can send random data to specified CoC
channel with command:
 l2cap send conn=<conn_handle> idx=<coc idx> bytes=<num of bytes>


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/be58d00d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/be58d00d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/be58d00d

Branch: refs/heads/master
Commit: be58d00d0d85812ea9ae2f3949e6ab446faf3d32
Parents: 6a0f5a8
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Sun Feb 12 15:07:58 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 12:40:41 2017 +0100

----------------------------------------------------------------------
 apps/bletiny/src/bletiny.h |  1 +
 apps/bletiny/src/cmd.c     | 50 +++++++++++++++++++++++++++
 apps/bletiny/src/main.c    | 75 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 126 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/be58d00d/apps/bletiny/src/bletiny.h
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/bletiny.h b/apps/bletiny/src/bletiny.h
index 8d8ac64..cdaff14 100644
--- a/apps/bletiny/src/bletiny.h
+++ b/apps/bletiny/src/bletiny.h
@@ -193,6 +193,7 @@ int bletiny_rssi(uint16_t conn_handle, int8_t *out_rssi);
 int bletiny_l2cap_create_srv(uint16_t psm);
 int bletiny_l2cap_connect(uint16_t conn, uint16_t psm);
 int bletiny_l2cap_disconnect(uint16_t conn, uint16_t idx);
+int bletiny_l2cap_send(uint16_t conn, uint16_t idx, uint16_t bytes);
 #define BLETINY_LOG_MODULE  (LOG_MODULE_PERUSER + 0)
 #define BLETINY_LOG(lvl, ...) \
     LOG_ ## lvl(&bletiny_log, BLETINY_LOG_MODULE, __VA_ARGS__)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/be58d00d/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index 47ab379..45debc5 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -1279,6 +1279,55 @@ cmd_l2cap_disconnect(int argc, char **argv)
     return bletiny_l2cap_disconnect(conn, idx);
 }
 
+static void
+bletiny_l2cap_send_help(void)
+{
+    console_printf("Available l2cap send commands: \n");
+    console_printf("\thelp\n");
+    console_printf("Available l2cap disconnect params: \n");
+    help_cmd_uint16("conn");
+    help_cmd_uint16("idx");
+    help_cmd_uint16("bytes");
+    console_printf("\n Use 'b show coc' to get conn and idx parameters.\n");
+    console_printf("bytes stands for number of bytes to send .\n");
+}
+
+static int
+cmd_l2cap_send(int argc, char **argv)
+{
+    uint16_t conn;
+    uint16_t idx;
+    uint16_t bytes;
+    int rc;
+
+    if (argc > 1 && strcmp(argv[1], "help") == 0) {
+        bletiny_l2cap_send_help();
+        return 0;
+    }
+    conn = parse_arg_uint16("conn", &rc);
+    if (rc != 0) {
+       console_printf("invalid 'conn' parameter\n");
+       help_cmd_uint16("conn");
+       return rc;
+    }
+
+    idx = parse_arg_uint16("idx", &rc);
+    if (rc != 0) {
+       console_printf("invalid 'idx' parameter\n");
+       help_cmd_uint16("idx");
+       return rc;
+    }
+
+    bytes = parse_arg_uint16("bytes", &rc);
+    if (rc != 0) {
+       console_printf("invalid 'bytes' parameter\n");
+       help_cmd_uint16("bytes");
+       return rc;
+    }
+
+    return bletiny_l2cap_send(conn, idx, bytes);
+}
+
 static const struct cmd_entry cmd_l2cap_entries[];
 
 static int
@@ -1298,6 +1347,7 @@ static const struct cmd_entry cmd_l2cap_entries[] = {
     { "create_srv", cmd_l2cap_create_srv },
     { "connect", cmd_l2cap_connect },
     { "disconnect", cmd_l2cap_disconnect },
+    { "send", cmd_l2cap_send },
     { "help", cmd_l2cap_help },
     { NULL, NULL }
 };

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/be58d00d/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 52cf7e6..b8f1e51 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -1756,6 +1756,81 @@ bletiny_l2cap_disconnect(uint16_t conn_handle, uint16_t idx)
 #endif
 }
 
+int
+bletiny_l2cap_send(uint16_t conn_handle, uint16_t idx, uint16_t bytes)
+{
+#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) == 0
+    console_printf("BLE L2CAP LE COC not supported.");
+    console_printf(" Configure nimble host to enable it\n");
+    return 0;
+#else
+
+    struct bletiny_conn *conn;
+    struct bletiny_l2cap_coc *coc;
+    struct os_mbuf *sdu_tx;
+    uint8_t b[] = {0x00, 0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88, 0x99};
+    int i;
+    int rc;
+
+    console_printf("conn=%d, idx=%d, bytes=%d\n", conn_handle, idx, bytes);
+
+    conn = bletiny_conn_find(conn_handle);
+    if (conn == NULL) {
+        console_printf("conn=%d does not exist\n", conn_handle);
+        return 0;
+    }
+
+    i = 0;
+    SLIST_FOREACH(coc, &conn->coc_list, next) {
+        if (i == idx) {
+            break;
+        }
+        i++;
+    }
+    if (coc == NULL) {
+        console_printf("Are you sure your channel exist?\n");
+        return 0;
+    }
+
+    sdu_tx = os_mbuf_get_pkthdr(&sdu_os_mbuf_pool, 0);
+    if (sdu_tx == NULL) {
+        console_printf("No memory in the test sdu pool\n");
+        return 0;
+    }
+
+    /* For the testing purpose we fill up buffer with known data, easy
+     * to validate on other side. In this loop we add as many full chunks as we
+     * can
+     */
+    for (i = 0; i < bytes / sizeof(b); i++) {
+        rc = os_mbuf_append(sdu_tx, b, sizeof(b));
+        if (rc) {
+            console_printf("Cannot append data %i !\n", i);
+            os_mbuf_free_chain(sdu_tx);
+            return rc;
+        }
+    }
+
+    /* Here we add the rest < sizeof(b) */
+    rc = os_mbuf_append(sdu_tx, b, bytes - (sizeof(b) * i));
+    if (rc) {
+        console_printf("Cannot append data %i !\n", i);
+        os_mbuf_free_chain(sdu_tx);
+        return rc;
+    }
+
+    rc = ble_l2cap_send(coc->chan, sdu_tx);
+    if (rc) {
+        console_printf("Could not send data rc=%d\n", rc);
+        if (rc == BLE_HS_EBUSY) {
+            os_mbuf_free_chain(sdu_tx);
+        }
+    }
+
+    return rc;
+
+#endif
+}
 /**
  * main
  *


[48/50] incubator-mynewt-core git commit: MYNEWT-527; fix OVERRIDE -> OVERWRITE

Posted by ma...@apache.org.
MYNEWT-527; fix OVERRIDE -> OVERWRITE


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/bc1c683f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/bc1c683f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/bc1c683f

Branch: refs/heads/master
Commit: bc1c683f5a1eb13cd2e10ed26f69238bff65b863
Parents: 6361501
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Sat Mar 4 19:20:35 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Sat Mar 4 19:20:35 2017 -0800

----------------------------------------------------------------------
 hw/bsp/bmd200/bsp.yml                     | 2 +-
 hw/bsp/bmd300eval/bsp.yml                 | 4 ++--
 hw/bsp/frdm-k64f/bsp.yml                  | 4 ++--
 hw/bsp/nrf51-arduino_101/bsp.yml          | 4 ++--
 hw/bsp/nrf51dk-16kbram/bsp.yml            | 4 ++--
 hw/bsp/nrf51dk/bsp.yml                    | 4 ++--
 hw/bsp/nrf52840pdk/bsp.yml                | 4 ++--
 hw/bsp/nrf52dk/bsp.yml                    | 4 ++--
 hw/bsp/nucleo-f401re/bsp.yml              | 4 ++--
 hw/bsp/olimex_stm32-e407_devboard/bsp.yml | 4 ++--
 hw/bsp/rb-nano2/bsp.yml                   | 4 ++--
 hw/bsp/stm32f4discovery/bsp.yml           | 4 ++--
 hw/bsp/usbmkw41z/bsp.yml                  | 4 ++--
 13 files changed, 25 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bc1c683f/hw/bsp/bmd200/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/bmd200/bsp.yml b/hw/bsp/bmd200/bsp.yml
index 3fe1275..388966d 100644
--- a/hw/bsp/bmd200/bsp.yml
+++ b/hw/bsp/bmd200/bsp.yml
@@ -28,7 +28,7 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/bmd200/split-nrf51dk.ld"
 bsp.downloadscript: "hw/bsp/bmd200/nrf51dk_download.sh"
 bsp.debugscript: "hw/bsp/bmd200/nrf51dk_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/bmd200/nrf51dk_download.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/bmd200/nrf51dk_download.cmd"
 bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/bmd200/nrf51dk_debug.cmd"
 
 bsp.flash_map:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bc1c683f/hw/bsp/bmd300eval/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/bmd300eval/bsp.yml b/hw/bsp/bmd300eval/bsp.yml
index f3a9a5d..68920b3 100644
--- a/hw/bsp/bmd300eval/bsp.yml
+++ b/hw/bsp/bmd300eval/bsp.yml
@@ -28,8 +28,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/bmd300eval/split-bmd300eval.ld"
 bsp.downloadscript: "hw/bsp/bmd300eval/bmd300eval_download.sh"
 bsp.debugscript: "hw/bsp/bmd300eval/bmd300eval_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/bmd300eval/bmd300eval_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/bmd300eval/bmd300eval_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/bmd300eval/bmd300eval_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/bmd300eval/bmd300eval_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bc1c683f/hw/bsp/frdm-k64f/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/frdm-k64f/bsp.yml b/hw/bsp/frdm-k64f/bsp.yml
index a771696..0da1a9a 100644
--- a/hw/bsp/frdm-k64f/bsp.yml
+++ b/hw/bsp/frdm-k64f/bsp.yml
@@ -23,8 +23,8 @@ bsp.linkerscript: "hw/bsp/frdm-k64f/MK64FN1M0xxx12_flash.ld"
 bsp.linkerscript.BOOT_LOADER.OVERWRITE: "hw/bsp/frdm-k64f/boot-MK64FN1M0xxx12_flash.ld"
 bsp.downloadscript: "hw/bsp/frdm-k64f/frdm-k64_download.sh"
 bsp.debugscript: "hw/bsp/frdm-k64f/frdm-k64_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/frdm-k64f/frdm-k64_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/frdm-k64f/frdm-k64_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/frdm-k64f/frdm-k64_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/frdm-k64f/frdm-k64_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bc1c683f/hw/bsp/nrf51-arduino_101/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-arduino_101/bsp.yml b/hw/bsp/nrf51-arduino_101/bsp.yml
index 7a75151..1b2cf94 100644
--- a/hw/bsp/nrf51-arduino_101/bsp.yml
+++ b/hw/bsp/nrf51-arduino_101/bsp.yml
@@ -27,8 +27,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
     - "hw/mcu/nordic/nrf51xxx/nrf51.ld"
 bsp.downloadscript: "hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_download.sh"
 bsp.debugscript: "hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/nrf51-arduino_101/nrf51dk-16kbram_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bc1c683f/hw/bsp/nrf51dk-16kbram/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk-16kbram/bsp.yml b/hw/bsp/nrf51dk-16kbram/bsp.yml
index 94dd59f..6aaaee4 100644
--- a/hw/bsp/nrf51dk-16kbram/bsp.yml
+++ b/hw/bsp/nrf51dk-16kbram/bsp.yml
@@ -28,8 +28,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/nrf51dk-16kbram/split-nrf51dk-16kbram.ld"
 bsp.downloadscript: "hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_download.sh"
 bsp.debugscript: "hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/nrf51dk-16kbram/nrf51dk-16kbram_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bc1c683f/hw/bsp/nrf51dk/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51dk/bsp.yml b/hw/bsp/nrf51dk/bsp.yml
index 247dc54..9382824 100644
--- a/hw/bsp/nrf51dk/bsp.yml
+++ b/hw/bsp/nrf51dk/bsp.yml
@@ -28,8 +28,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/nrf51dk/split-nrf51dk.ld"
 bsp.downloadscript: "hw/bsp/nrf51dk/nrf51dk_download.sh"
 bsp.debugscript: "hw/bsp/nrf51dk/nrf51dk_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51dk/nrf51dk_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51dk/nrf51dk_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/nrf51dk/nrf51dk_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/nrf51dk/nrf51dk_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bc1c683f/hw/bsp/nrf52840pdk/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52840pdk/bsp.yml b/hw/bsp/nrf52840pdk/bsp.yml
index e168d57..950c399 100644
--- a/hw/bsp/nrf52840pdk/bsp.yml
+++ b/hw/bsp/nrf52840pdk/bsp.yml
@@ -28,8 +28,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/nrf52840pdk/split-nrf52840pdk.ld"
 bsp.downloadscript: "hw/bsp/nrf52840pdk/nrf52840pdk_download.sh"
 bsp.debugscript: "hw/bsp/nrf52840pdk/nrf52840pdk_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/nrf52840pdk/nrf52840pdk_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/nrf52840pdk/nrf52840pdk_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/nrf52840pdk/nrf52840pdk_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/nrf52840pdk/nrf52840pdk_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bc1c683f/hw/bsp/nrf52dk/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf52dk/bsp.yml b/hw/bsp/nrf52dk/bsp.yml
index 050c16a..76e154d 100644
--- a/hw/bsp/nrf52dk/bsp.yml
+++ b/hw/bsp/nrf52dk/bsp.yml
@@ -28,8 +28,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/nrf52dk/split-nrf52dk.ld"
 bsp.downloadscript: "hw/bsp/nrf52dk/nrf52dk_download.sh"
 bsp.debugscript: "hw/bsp/nrf52dk/nrf52dk_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/nrf52dk/nrf52dk_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/nrf52dk/nrf52dk_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/nrf52dk/nrf52dk_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/nrf52dk/nrf52dk_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bc1c683f/hw/bsp/nucleo-f401re/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nucleo-f401re/bsp.yml b/hw/bsp/nucleo-f401re/bsp.yml
index 7610b47..4fdd6ce 100644
--- a/hw/bsp/nucleo-f401re/bsp.yml
+++ b/hw/bsp/nucleo-f401re/bsp.yml
@@ -27,8 +27,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
     - "hw/mcu/stm/stm32f4xx/stm32f401.ld"
 bsp.downloadscript: "hw/bsp/nucleo-f401re/nucleo-f401re_download.sh"
 bsp.debugscript: "hw/bsp/nucleo-f401re/nucleo-f401re_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/nucleo-f401re/nucleo-f401re_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/nucleo-f401re/nucleo-f401re_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/nucleo-f401re/nucleo-f401re_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/nucleo-f401re/nucleo-f401re_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bc1c683f/hw/bsp/olimex_stm32-e407_devboard/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/olimex_stm32-e407_devboard/bsp.yml b/hw/bsp/olimex_stm32-e407_devboard/bsp.yml
index 478703b..fdddd4b 100644
--- a/hw/bsp/olimex_stm32-e407_devboard/bsp.yml
+++ b/hw/bsp/olimex_stm32-e407_devboard/bsp.yml
@@ -27,8 +27,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
     - "hw/mcu/stm/stm32f4xx/stm32f407.ld"
 bsp.downloadscript: "hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_download.sh"
 bsp.debugscript: "hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/olimex_stm32-e407_devboard/olimex_stm32-e407_devboard_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bc1c683f/hw/bsp/rb-nano2/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/rb-nano2/bsp.yml b/hw/bsp/rb-nano2/bsp.yml
index c4fc926..7e04c46 100644
--- a/hw/bsp/rb-nano2/bsp.yml
+++ b/hw/bsp/rb-nano2/bsp.yml
@@ -28,8 +28,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/rb-nano2/split-rb-nano2.ld"
 bsp.downloadscript: "hw/bsp/rb-nano2/rb-nano2_download.sh"
 bsp.debugscript: "hw/bsp/rb-nano2/rb-nano2_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/rb-nano2/rb-nano2_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/rb-nano2/rb-nano2_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/rb-nano2/rb-nano2_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/rb-nano2/rb-nano2_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bc1c683f/hw/bsp/stm32f4discovery/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/stm32f4discovery/bsp.yml b/hw/bsp/stm32f4discovery/bsp.yml
index 658cb21..6c4a1a5 100644
--- a/hw/bsp/stm32f4discovery/bsp.yml
+++ b/hw/bsp/stm32f4discovery/bsp.yml
@@ -27,8 +27,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
     - "hw/mcu/stm/stm32f4xx/stm32f407.ld"
 bsp.downloadscript: "hw/bsp/stm32f4discovery/stm32f4discovery_download.sh"
 bsp.debugscript: "hw/bsp/stm32f4discovery/stm32f4discovery_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/stm32f4discovery/stm32f4discovery_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/stm32f4discovery/stm32f4discovery_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/stm32f4discovery/stm32f4discovery_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/stm32f4discovery/stm32f4discovery_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/bc1c683f/hw/bsp/usbmkw41z/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/usbmkw41z/bsp.yml b/hw/bsp/usbmkw41z/bsp.yml
index 55e9ae7..eff217c 100644
--- a/hw/bsp/usbmkw41z/bsp.yml
+++ b/hw/bsp/usbmkw41z/bsp.yml
@@ -26,8 +26,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/usbmkw41z/split-usbkw41z.ld"
 bsp.downloadscript: "hw/bsp/usbmkw41z/usbkw41z_download.sh"
 bsp.debugscript: "hw/bsp/usbmkw41z/usbkw41z_debug.sh"
-bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/usbmkw41z/usbkw41z_download.cmd"
-bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/usbmkw41z/usbkw41z_debug.cmd"
+bsp.downloadscript.WINDOWS.OVERWRITE: "hw/bsp/usbmkw41z/usbkw41z_download.cmd"
+bsp.debugscript.WINDOWS.OVERWRITE: "hw/bsp/usbmkw41z/usbkw41z_debug.cmd"
 
 bsp.flash_map:
     areas:


[31/50] incubator-mynewt-core git commit: nimble/l2cap: Add suppport to send data over L2CAP LE CoC

Posted by ma...@apache.org.
nimble/l2cap: Add suppport to send data over L2CAP LE CoC


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/93ac0dfa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/93ac0dfa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/93ac0dfa

Branch: refs/heads/master
Commit: 93ac0dfaf68e8b5614413b03b0ca787dc9f6142b
Parents: fbceba5
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Sun Feb 12 15:26:25 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 12:40:42 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap.c          |   3 +-
 net/nimble/host/src/ble_l2cap_coc.c      | 124 ++++++++++++++++++++++++++
 net/nimble/host/src/ble_l2cap_coc_priv.h |   2 +
 3 files changed, 127 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93ac0dfa/net/nimble/host/src/ble_l2cap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap.c b/net/nimble/host/src/ble_l2cap.c
index 046a136..b19a348 100644
--- a/net/nimble/host/src/ble_l2cap.c
+++ b/net/nimble/host/src/ble_l2cap.c
@@ -160,8 +160,7 @@ int ble_l2cap_disconnect(struct ble_l2cap_chan *chan)
 int
 ble_l2cap_send(struct ble_l2cap_chan *chan, struct os_mbuf *sdu)
 {
-    /*TODO Implement */
-    return BLE_HS_ENOTSUP;
+    return ble_l2cap_coc_send(chan, sdu);
 }
 
 void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93ac0dfa/net/nimble/host/src/ble_l2cap_coc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc.c b/net/nimble/host/src/ble_l2cap_coc.c
index 9794a00..12d79d6 100644
--- a/net/nimble/host/src/ble_l2cap_coc.c
+++ b/net/nimble/host/src/ble_l2cap_coc.c
@@ -288,6 +288,108 @@ ble_l2cap_coc_cleanup_chan(struct ble_l2cap_chan *chan)
     os_mbuf_free_chain(chan->coc_tx.sdu);
 }
 
+static int
+ble_l2cap_coc_continue_tx(struct ble_l2cap_chan *chan)
+{
+    struct ble_l2cap_coc_endpoint *tx;
+    uint16_t len;
+    uint16_t left_to_send;
+    struct os_mbuf *txom;
+    struct ble_hs_conn *conn;
+    uint16_t sdu_size_offset;
+    int rc;
+
+    /* If there is no data to send, just return success */
+    tx = &chan->coc_tx;
+    if (!tx->sdu) {
+        return 0;
+    }
+
+    while (tx->credits) {
+        sdu_size_offset = 0;
+
+        BLE_HS_LOG(DEBUG, "Available credits %d\n", tx->credits);
+
+        /* lets calculate data we are going to send */
+        left_to_send = OS_MBUF_PKTLEN(tx->sdu) - tx->data_offset;
+
+        if (tx->data_offset == 0) {
+            sdu_size_offset = BLE_L2CAP_SDU_SIZE;
+            left_to_send += sdu_size_offset;
+        }
+
+        /* Take into account peer MTU */
+        len = min(left_to_send, chan->peer_mtu);
+
+        /* Prepare packet */
+        txom = ble_hs_mbuf_l2cap_pkt();
+        if (!txom) {
+            BLE_HS_LOG(DEBUG, "Could not prepare l2cap packet len %d, err=%d",
+                                                                   len, rc);
+
+            rc = BLE_HS_ENOMEM;
+            goto failed;
+        }
+
+        if (tx->data_offset == 0) {
+            /* First packet needs SDU len first. Left to send */
+            uint16_t l = htole16(OS_MBUF_PKTLEN(tx->sdu));
+
+            BLE_HS_LOG(DEBUG, "Sending SDU len=%d\n", OS_MBUF_PKTLEN(tx->sdu));
+            rc = os_mbuf_append(txom, &l, sizeof(uint16_t));
+            if (rc) {
+                BLE_HS_LOG(DEBUG, "Could not append data rc=%d", rc);
+                goto failed;
+            }
+        }
+
+        /* In data_offset we keep track on what we already sent. Need to remember
+         * that for first packet we need to decrease data size by 2 bytes for sdu
+         * size
+         */
+        rc = os_mbuf_appendfrom(txom, tx->sdu, tx->data_offset,
+                                len - sdu_size_offset);
+        if (rc) {
+            BLE_HS_LOG(DEBUG, "Could not append data rc=%d", rc);
+           goto failed;
+        }
+
+        ble_hs_lock();
+        conn = ble_hs_conn_find_assert(chan->conn_handle);
+        rc = ble_l2cap_tx(conn, chan, txom);
+        ble_hs_unlock();
+
+        if (rc) {
+          /* txom is consumed by l2cap */
+          txom = NULL;
+          goto failed;
+        } else {
+            tx->credits --;
+            tx->data_offset += len - sdu_size_offset;
+        }
+
+        BLE_HS_LOG(DEBUG, "Sent %d bytes, credits=%d, to send %d bytes \n",
+                  len, tx->credits, OS_MBUF_PKTLEN(tx->sdu)- tx->data_offset );
+
+        if (tx->data_offset == OS_MBUF_PKTLEN(tx->sdu)) {
+                BLE_HS_LOG(DEBUG, "Complete package sent");
+                os_mbuf_free_chain(tx->sdu);
+                tx->sdu = 0;
+                tx->data_offset = 0;
+                break;
+        }
+    }
+
+    return 0;
+
+failed:
+    os_mbuf_free_chain(tx->sdu);
+    tx->sdu = NULL;
+    os_mbuf_free_chain(txom);
+
+    return rc;
+}
+
 void
 ble_l2cap_coc_le_credits_update(uint16_t conn_handle, uint16_t dcid,
                                 uint16_t credits)
@@ -317,6 +419,8 @@ ble_l2cap_coc_le_credits_update(uint16_t conn_handle, uint16_t dcid,
     }
 
     chan->coc_tx.credits += credits;
+    ble_l2cap_coc_continue_tx(chan);
+
     ble_hs_unlock();
 }
 
@@ -349,6 +453,26 @@ ble_l2cap_coc_recv_ready(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_rx)
 }
 
 int
+ble_l2cap_coc_send(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_tx)
+{
+    struct ble_l2cap_coc_endpoint *tx;
+
+    tx = &chan->coc_tx;
+
+    if (tx->sdu) {
+        return BLE_HS_EBUSY;
+    }
+
+    tx->sdu = sdu_tx;
+
+    if (OS_MBUF_PKTLEN(sdu_tx) > tx->mtu) {
+        return BLE_HS_EBADDATA;
+    }
+
+    return ble_l2cap_coc_continue_tx(chan);
+}
+
+int
 ble_l2cap_coc_init(void)
 {
     STAILQ_INIT(&ble_l2cap_coc_srvs);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/93ac0dfa/net/nimble/host/src/ble_l2cap_coc_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc_priv.h b/net/nimble/host/src/ble_l2cap_coc_priv.h
index 36ab4dc..4fe75e9 100644
--- a/net/nimble/host/src/ble_l2cap_coc_priv.h
+++ b/net/nimble/host/src/ble_l2cap_coc_priv.h
@@ -67,11 +67,13 @@ void ble_l2cap_coc_le_credits_update(uint16_t conn_handle, uint16_t dcid,
                                     uint16_t credits);
 void ble_l2cap_coc_recv_ready(struct ble_l2cap_chan *chan,
                               struct os_mbuf *sdu_rx);
+int ble_l2cap_coc_send(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_tx);
 #else
 #define ble_l2cap_coc_init()                                    0
 #define ble_l2cap_coc_create_server(psm, mtu, cb, cb_arg)       BLE_HS_ENOTSUP
 #define ble_l2cap_coc_recv_ready(chan, sdu_rx)
 #define ble_l2cap_coc_cleanup_chan(chan)
+#define ble_l2cap_coc_send(chan, sdu_tx)                        BLE_HS_ENOTSUP
 #endif
 
 #ifdef __cplusplus


[29/50] incubator-mynewt-core git commit: nimble/l2cap: Add helper to clean L2CAP LE CoC channel

Posted by ma...@apache.org.
nimble/l2cap: Add helper to clean L2CAP LE CoC channel

With this patch we make sure that when CoC is used, outstanding
os_mbufs are freed when channel is closing


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/fbceba58
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/fbceba58
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/fbceba58

Branch: refs/heads/master
Commit: fbceba584c5cd31f2b1253527023469b0a262162
Parents: 98e2cb9
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Sun Feb 12 15:23:09 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 12:40:42 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap.c          |  1 +
 net/nimble/host/src/ble_l2cap_coc.c      | 12 ++++++++++++
 net/nimble/host/src/ble_l2cap_coc_priv.h |  2 ++
 3 files changed, 15 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fbceba58/net/nimble/host/src/ble_l2cap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap.c b/net/nimble/host/src/ble_l2cap.c
index b0ab23d..046a136 100644
--- a/net/nimble/host/src/ble_l2cap.c
+++ b/net/nimble/host/src/ble_l2cap.c
@@ -79,6 +79,7 @@ ble_l2cap_chan_free(struct ble_l2cap_chan *chan)
     }
 
     os_mbuf_free_chain(chan->rx_buf);
+    ble_l2cap_coc_cleanup_chan(chan);
 
     rc = os_memblock_put(&ble_l2cap_chan_pool, chan);
     BLE_HS_DBG_ASSERT_EVAL(rc == 0);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fbceba58/net/nimble/host/src/ble_l2cap_coc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc.c b/net/nimble/host/src/ble_l2cap_coc.c
index b549ba7..9794a00 100644
--- a/net/nimble/host/src/ble_l2cap_coc.c
+++ b/net/nimble/host/src/ble_l2cap_coc.c
@@ -277,6 +277,18 @@ ble_l2cap_coc_create_srv_chan(uint16_t conn_handle, uint16_t psm,
 }
 
 void
+ble_l2cap_coc_cleanup_chan(struct ble_l2cap_chan *chan)
+{
+    /* PSM 0 is used for fixed channels. */
+    if (chan->psm == 0) {
+            return;
+    }
+
+    os_mbuf_free_chain(chan->coc_rx.sdu);
+    os_mbuf_free_chain(chan->coc_tx.sdu);
+}
+
+void
 ble_l2cap_coc_le_credits_update(uint16_t conn_handle, uint16_t dcid,
                                 uint16_t credits)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fbceba58/net/nimble/host/src/ble_l2cap_coc_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc_priv.h b/net/nimble/host/src/ble_l2cap_coc_priv.h
index 88380ea..36ab4dc 100644
--- a/net/nimble/host/src/ble_l2cap_coc_priv.h
+++ b/net/nimble/host/src/ble_l2cap_coc_priv.h
@@ -62,6 +62,7 @@ struct ble_l2cap_chan * ble_l2cap_coc_chan_alloc(uint16_t conn_handle,
                                                  struct os_mbuf *sdu_rx,
                                                  ble_l2cap_event_fn *cb,
                                                  void *cb_arg);
+void ble_l2cap_coc_cleanup_chan(struct ble_l2cap_chan *chan);
 void ble_l2cap_coc_le_credits_update(uint16_t conn_handle, uint16_t dcid,
                                     uint16_t credits);
 void ble_l2cap_coc_recv_ready(struct ble_l2cap_chan *chan,
@@ -70,6 +71,7 @@ void ble_l2cap_coc_recv_ready(struct ble_l2cap_chan *chan,
 #define ble_l2cap_coc_init()                                    0
 #define ble_l2cap_coc_create_server(psm, mtu, cb, cb_arg)       BLE_HS_ENOTSUP
 #define ble_l2cap_coc_recv_ready(chan, sdu_rx)
+#define ble_l2cap_coc_cleanup_chan(chan)
 #endif
 
 #ifdef __cplusplus


[37/50] incubator-mynewt-core git commit: This closes #188.

Posted by ma...@apache.org.
This closes #188.

Merge branch 'oci_ipv4' of https://github.com/mkiiskila/incubator-mynewt-core into develop


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/389d7f4a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/389d7f4a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/389d7f4a

Branch: refs/heads/master
Commit: 389d7f4adf4d3966946974f46db9294f63800e1e
Parents: 8d75770 9064dba
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Mar 3 07:56:35 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Mar 3 07:56:35 2017 -0800

----------------------------------------------------------------------
 net/oic/src/api/oc_client_api.c       |  61 ++++-
 net/oic/src/port/mynewt/adaptor.c     |  32 ++-
 net/oic/src/port/mynewt/adaptor.h     |  16 +-
 net/oic/src/port/mynewt/ip4_adaptor.c | 354 +++++++++++++++++++++++++++++
 net/oic/src/port/mynewt/ip_adaptor.c  |  96 ++++----
 net/oic/src/port/oc_connectivity.h    |  15 +-
 net/oic/syscfg.yml                    |   6 +
 net/oic/test/syscfg.yml               |   2 +
 8 files changed, 512 insertions(+), 70 deletions(-)
----------------------------------------------------------------------



[26/50] incubator-mynewt-core git commit: nimble/l2cap: Add LE credits update handling

Posted by ma...@apache.org.
nimble/l2cap: Add LE credits update handling

This patch add support to send singaling request to update LE creadits
as well as handle remote device sending us LE credits update.

Note, that this patch introduces also helper function to find channel
by scid and dcid


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/754c4456
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/754c4456
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/754c4456

Branch: refs/heads/master
Commit: 754c4456a022f89135bedc80807c755950d2d201
Parents: 9b3899a
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Sun Feb 12 15:30:21 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 12:40:42 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/src/ble_att.c               |  2 +-
 net/nimble/host/src/ble_hs_conn.c           | 23 ++++++++++-
 net/nimble/host/src/ble_hs_conn_priv.h      |  4 +-
 net/nimble/host/src/ble_hs_misc.c           |  2 +-
 net/nimble/host/src/ble_l2cap.c             |  2 +-
 net/nimble/host/src/ble_l2cap_coc.c         | 32 +++++++++++++++
 net/nimble/host/src/ble_l2cap_coc_priv.h    |  2 +
 net/nimble/host/src/ble_l2cap_sig.c         | 50 +++++++++++++++++++++++-
 net/nimble/host/src/ble_l2cap_sig_priv.h    |  6 +++
 net/nimble/host/test/src/ble_hs_conn_test.c |  6 +--
 10 files changed, 119 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/754c4456/net/nimble/host/src/ble_att.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att.c b/net/nimble/host/src/ble_att.c
index 7fe095b..0eaed34 100644
--- a/net/nimble/host/src/ble_att.c
+++ b/net/nimble/host/src/ble_att.c
@@ -545,7 +545,7 @@ ble_att_set_preferred_mtu(uint16_t mtu)
 
     i = 0;
     while ((conn = ble_hs_conn_find_by_idx(i)) != NULL) {
-        chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_ATT);
+        chan = ble_hs_conn_chan_find_by_scid(conn, BLE_L2CAP_CID_ATT);
         BLE_HS_DBG_ASSERT(chan != NULL);
 
         if (!(chan->flags & BLE_L2CAP_CHAN_F_TXED_MTU)) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/754c4456/net/nimble/host/src/ble_hs_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn.c b/net/nimble/host/src/ble_hs_conn.c
index a371ace..cef0e3a 100644
--- a/net/nimble/host/src/ble_hs_conn.c
+++ b/net/nimble/host/src/ble_hs_conn.c
@@ -50,7 +50,7 @@ ble_hs_conn_can_alloc(void)
 }
 
 struct ble_l2cap_chan *
-ble_hs_conn_chan_find(struct ble_hs_conn *conn, uint16_t cid)
+ble_hs_conn_chan_find_by_scid(struct ble_hs_conn *conn, uint16_t cid)
 {
 #if !NIMBLE_BLE_CONNECT
     return NULL;
@@ -70,6 +70,27 @@ ble_hs_conn_chan_find(struct ble_hs_conn *conn, uint16_t cid)
     return NULL;
 }
 
+struct ble_l2cap_chan *
+ble_hs_conn_chan_find_by_dcid(struct ble_hs_conn *conn, uint16_t cid)
+{
+#if !NIMBLE_BLE_CONNECT
+    return NULL;
+#endif
+
+    struct ble_l2cap_chan *chan;
+
+    SLIST_FOREACH(chan, &conn->bhc_channels, next) {
+        if (chan->dcid == cid) {
+            return chan;
+        }
+        if (chan->dcid > cid) {
+            return NULL;
+        }
+    }
+
+    return NULL;
+}
+
 int
 ble_hs_conn_chan_insert(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/754c4456/net/nimble/host/src/ble_hs_conn_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn_priv.h b/net/nimble/host/src/ble_hs_conn_priv.h
index 24e2e48..4c51646 100644
--- a/net/nimble/host/src/ble_hs_conn_priv.h
+++ b/net/nimble/host/src/ble_hs_conn_priv.h
@@ -84,7 +84,9 @@ struct ble_hs_conn *ble_hs_conn_find_by_addr(const ble_addr_t *addr);
 struct ble_hs_conn *ble_hs_conn_find_by_idx(int idx);
 int ble_hs_conn_exists(uint16_t conn_handle);
 struct ble_hs_conn *ble_hs_conn_first(void);
-struct ble_l2cap_chan *ble_hs_conn_chan_find(struct ble_hs_conn *conn,
+struct ble_l2cap_chan *ble_hs_conn_chan_find_by_scid(struct ble_hs_conn *conn,
+                                             uint16_t cid);
+struct ble_l2cap_chan *ble_hs_conn_chan_find_by_dcid(struct ble_hs_conn *conn,
                                              uint16_t cid);
 int ble_hs_conn_chan_insert(struct ble_hs_conn *conn,
                             struct ble_l2cap_chan *chan);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/754c4456/net/nimble/host/src/ble_hs_misc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_misc.c b/net/nimble/host/src/ble_hs_misc.c
index 578c7e4..f06bfae 100644
--- a/net/nimble/host/src/ble_hs_misc.c
+++ b/net/nimble/host/src/ble_hs_misc.c
@@ -39,7 +39,7 @@ ble_hs_misc_conn_chan_find(uint16_t conn_handle, uint16_t cid,
         chan = NULL;
         rc = BLE_HS_ENOTCONN;
     } else {
-        chan = ble_hs_conn_chan_find(conn, cid);
+        chan = ble_hs_conn_chan_find_by_scid(conn, cid);
         if (chan == NULL) {
             rc = BLE_HS_ENOTCONN;
         } else {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/754c4456/net/nimble/host/src/ble_l2cap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap.c b/net/nimble/host/src/ble_l2cap.c
index 306eac1..e048ce9 100644
--- a/net/nimble/host/src/ble_l2cap.c
+++ b/net/nimble/host/src/ble_l2cap.c
@@ -320,7 +320,7 @@ ble_l2cap_rx(struct ble_hs_conn *conn,
         /* Strip L2CAP header from the front of the mbuf. */
         os_mbuf_adj(om, BLE_L2CAP_HDR_SZ);
 
-        chan = ble_hs_conn_chan_find(conn, l2cap_hdr.cid);
+        chan = ble_hs_conn_chan_find_by_scid(conn, l2cap_hdr.cid);
         if (chan == NULL) {
             rc = BLE_HS_ENOENT;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/754c4456/net/nimble/host/src/ble_l2cap_coc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc.c b/net/nimble/host/src/ble_l2cap_coc.c
index ac1b6fa..8d5f71f 100644
--- a/net/nimble/host/src/ble_l2cap_coc.c
+++ b/net/nimble/host/src/ble_l2cap_coc.c
@@ -168,6 +168,38 @@ ble_l2cap_coc_create_srv_chan(uint16_t conn_handle, uint16_t psm,
     return 0;
 }
 
+void
+ble_l2cap_coc_le_credits_update(uint16_t conn_handle, uint16_t dcid,
+                                uint16_t credits)
+{
+    struct ble_hs_conn *conn;
+    struct ble_l2cap_chan *chan;
+
+    /* remote updated its credits */
+    ble_hs_lock();
+    conn = ble_hs_conn_find(conn_handle);
+    if (!conn) {
+        ble_hs_unlock();
+        return;
+    }
+
+    chan = ble_hs_conn_chan_find_by_dcid(conn, dcid);
+    if (!chan) {
+        ble_hs_unlock();
+        return;
+    }
+
+    if (chan->coc_tx.credits + credits > 0xFFFF) {
+        BLE_HS_LOG(INFO, "LE CoC credits overflow...disconnecting\n");
+        ble_l2cap_sig_disconnect(chan);
+        ble_hs_unlock();
+        return;
+    }
+
+    chan->coc_tx.credits += credits;
+    ble_hs_unlock();
+}
+
 int
 ble_l2cap_coc_init(void)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/754c4456/net/nimble/host/src/ble_l2cap_coc_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc_priv.h b/net/nimble/host/src/ble_l2cap_coc_priv.h
index 63c593e..21f9ec2 100644
--- a/net/nimble/host/src/ble_l2cap_coc_priv.h
+++ b/net/nimble/host/src/ble_l2cap_coc_priv.h
@@ -61,6 +61,8 @@ struct ble_l2cap_chan * ble_l2cap_coc_chan_alloc(uint16_t conn_handle,
                                                  struct os_mbuf *sdu_rx,
                                                  ble_l2cap_event_fn *cb,
                                                  void *cb_arg);
+void ble_l2cap_coc_le_credits_update(uint16_t conn_handle, uint16_t dcid,
+                                    uint16_t credits);
 #else
 #define ble_l2cap_coc_init()                                    0
 #define ble_l2cap_coc_create_server(psm, mtu, cb, cb_arg)       BLE_HS_ENOTSUP

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/754c4456/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index abc00ae..8da2dad 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -98,11 +98,13 @@ static ble_l2cap_sig_rx_fn ble_l2cap_sig_coc_req_rx;
 static ble_l2cap_sig_rx_fn ble_l2cap_sig_coc_rsp_rx;
 static ble_l2cap_sig_rx_fn ble_l2cap_sig_disc_rsp_rx;
 static ble_l2cap_sig_rx_fn ble_l2cap_sig_disc_req_rx;
+static ble_l2cap_sig_rx_fn ble_l2cap_sig_le_credits_rx;
 #else
 #define ble_l2cap_sig_coc_req_rx    ble_l2cap_sig_rx_noop
 #define ble_l2cap_sig_coc_rsp_rx    ble_l2cap_sig_rx_noop
 #define ble_l2cap_sig_disc_rsp_rx   ble_l2cap_sig_rx_noop
 #define ble_l2cap_sig_disc_req_rx   ble_l2cap_sig_rx_noop
+#define ble_l2cap_sig_le_credits_rx   ble_l2cap_sig_rx_noop
 #endif
 
 static ble_l2cap_sig_rx_fn * const ble_l2cap_sig_dispatch[] = {
@@ -120,7 +122,7 @@ static ble_l2cap_sig_rx_fn * const ble_l2cap_sig_dispatch[] = {
     [BLE_L2CAP_SIG_OP_UPDATE_RSP]           = ble_l2cap_sig_update_rsp_rx,
     [BLE_L2CAP_SIG_OP_CREDIT_CONNECT_REQ]   = ble_l2cap_sig_coc_req_rx,
     [BLE_L2CAP_SIG_OP_CREDIT_CONNECT_RSP]   = ble_l2cap_sig_coc_rsp_rx,
-    [BLE_L2CAP_SIG_OP_FLOW_CTRL_CREDIT]     = ble_l2cap_sig_rx_noop,
+    [BLE_L2CAP_SIG_OP_FLOW_CTRL_CREDIT]     = ble_l2cap_sig_le_credits_rx,
 };
 
 static uint8_t ble_l2cap_sig_cur_id;
@@ -876,7 +878,7 @@ ble_l2cap_sig_disc_req_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
     /* Let's find matching channel. Note that destination CID in the request
      * is from peer perspective. It is source CID from nimble perspective 
      */
-    chan = ble_hs_conn_chan_find(conn, le16toh(req->dcid));
+    chan = ble_hs_conn_chan_find_by_scid(conn, le16toh(req->dcid));
     if (!chan || (le16toh(req->scid) != chan->dcid)) {
         os_mbuf_free_chain(txom);
         ble_hs_unlock();
@@ -1006,6 +1008,50 @@ ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan)
 
     return rc;
 }
+
+static int
+ble_l2cap_sig_le_credits_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
+                            struct os_mbuf **om)
+{
+    struct ble_l2cap_sig_le_credits *req;
+    int rc;
+
+    rc = ble_hs_mbuf_pullup_base(om, sizeof(*req));
+    if (rc != 0) {
+        return 0;
+    }
+
+    req = (struct ble_l2cap_sig_le_credits *) (*om)->om_data;
+
+    /* Ignore when peer sends zero credits */
+    if (req->credits == 0) {
+            return 0;
+    }
+
+    ble_l2cap_coc_le_credits_update(conn_handle, le16toh(req->scid),
+                                    le16toh(req->credits));
+
+    return 0;
+}
+
+int
+ble_l2cap_sig_le_credits(struct ble_l2cap_chan *chan, uint16_t credits)
+{
+    struct ble_l2cap_sig_le_credits *cmd;
+    struct os_mbuf *txom;
+
+    cmd = ble_l2cap_sig_cmd_get(BLE_L2CAP_SIG_OP_FLOW_CTRL_CREDIT,
+                                ble_l2cap_sig_next_id(), sizeof(*cmd), &txom);
+
+    if (!cmd) {
+        return BLE_HS_ENOMEM;
+    }
+
+    cmd->scid = htole16(chan->scid);
+    cmd->credits = htole16(credits);
+
+    return ble_l2cap_sig_tx(chan->conn_handle, txom);
+}
 #endif
 /*****************************************************************************
  * $misc                                                                     *

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/754c4456/net/nimble/host/src/ble_l2cap_sig_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig_priv.h b/net/nimble/host/src/ble_l2cap_sig_priv.h
index 0677405..49d096c 100644
--- a/net/nimble/host/src/ble_l2cap_sig_priv.h
+++ b/net/nimble/host/src/ble_l2cap_sig_priv.h
@@ -84,6 +84,11 @@ struct ble_l2cap_sig_disc_rsp {
     uint16_t scid;
 } __attribute__((packed));
 
+struct ble_l2cap_sig_le_credits {
+    uint16_t scid;
+    uint16_t credits;
+} __attribute__((packed));
+
 int ble_l2cap_sig_init_cmd(uint8_t op, uint8_t id, uint8_t payload_len,
                            struct os_mbuf **out_om, void **out_payload_buf);
 void ble_l2cap_sig_hdr_parse(void *payload, uint16_t len,
@@ -103,6 +108,7 @@ int ble_l2cap_sig_coc_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
                               struct os_mbuf *sdu_rx,
                               ble_l2cap_event_fn *cb, void *cb_arg);
 int ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan);
+int ble_l2cap_sig_le_credits(struct ble_l2cap_chan *chan, uint16_t credits);
 #else
 #define ble_l2cap_sig_coc_connect(conn_handle, psm, mtu, sdu_rx, cb, cb_arg) \
                                                                 BLE_HS_ENOTSUP

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/754c4456/net/nimble/host/test/src/ble_hs_conn_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_hs_conn_test.c b/net/nimble/host/test/src/ble_hs_conn_test.c
index 8ae4971..87f9b46 100644
--- a/net/nimble/host/test/src/ble_hs_conn_test.c
+++ b/net/nimble/host/test/src/ble_hs_conn_test.c
@@ -77,7 +77,7 @@ TEST_CASE(ble_hs_conn_test_direct_connect_success)
     TEST_ASSERT(conn->bhc_handle == 2);
     TEST_ASSERT(memcmp(conn->bhc_peer_addr.val, addr.val, 6) == 0);
 
-    chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_ATT);
+    chan = ble_hs_conn_chan_find_by_scid(conn, BLE_L2CAP_CID_ATT);
     TEST_ASSERT_FATAL(chan != NULL);
     TEST_ASSERT(chan->my_mtu == BLE_ATT_MTU_PREFERRED_DFLT);
     TEST_ASSERT(chan->peer_mtu == 0);
@@ -131,7 +131,7 @@ TEST_CASE(ble_hs_conn_test_direct_connectable_success)
     TEST_ASSERT(conn->bhc_handle == 2);
     TEST_ASSERT(memcmp(conn->bhc_peer_addr.val, addr.val, 6) == 0);
 
-    chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_ATT);
+    chan = ble_hs_conn_chan_find_by_scid(conn, BLE_L2CAP_CID_ATT);
     TEST_ASSERT_FATAL(chan != NULL);
     TEST_ASSERT(chan->my_mtu == BLE_ATT_MTU_PREFERRED_DFLT);
     TEST_ASSERT(chan->peer_mtu == 0);
@@ -192,7 +192,7 @@ TEST_CASE(ble_hs_conn_test_undirect_connectable_success)
     TEST_ASSERT(conn->bhc_handle == 2);
     TEST_ASSERT(memcmp(conn->bhc_peer_addr.val, addr.val, 6) == 0);
 
-    chan = ble_hs_conn_chan_find(conn, BLE_L2CAP_CID_ATT);
+    chan = ble_hs_conn_chan_find_by_scid(conn, BLE_L2CAP_CID_ATT);
     TEST_ASSERT_FATAL(chan != NULL);
     TEST_ASSERT(chan->my_mtu == BLE_ATT_MTU_PREFERRED_DFLT);
     TEST_ASSERT(chan->peer_mtu == 0);


[07/50] incubator-mynewt-core git commit: MYNEWT-652; net/oic - remove check of OC_PERIODIC when deciding whether to send notify or not.

Posted by ma...@apache.org.
MYNEWT-652; net/oic - remove check of OC_PERIODIC when deciding
whether to send notify or not.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/0b037a6c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/0b037a6c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/0b037a6c

Branch: refs/heads/master
Commit: 0b037a6c72040d2fbe153f48e2da0e063cd4b7d4
Parents: 58378cc
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Thu Mar 2 14:41:13 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Thu Mar 2 14:41:13 2017 -0800

----------------------------------------------------------------------
 net/oic/src/messaging/coap/observe.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0b037a6c/net/oic/src/messaging/coap/observe.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/observe.c b/net/oic/src/messaging/coap/observe.c
index 24ddd2a..ed88682 100644
--- a/net/oic/src/messaging/coap/observe.c
+++ b/net/oic/src/messaging/coap/observe.c
@@ -206,7 +206,7 @@ coap_notify_observers(oc_resource_t *resource,
         num_observers = resource->num_observers;
     }
     response.separate_response = 0;
-    if (!response_buf && resource && (resource->properties & OC_PERIODIC)) {
+    if (!response_buf && resource) {
         OC_LOG_DEBUG("coap_notify_observers: Issue GET request to resource\n");
         /* performing GET on the resource */
         m = os_msys_get_pkthdr(0, 0);


[19/50] incubator-mynewt-core git commit: bletiny: Add error print when L2CAP LE CoC disconnect fails

Posted by ma...@apache.org.
bletiny: Add error print when L2CAP LE CoC disconnect fails


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/5c449bb1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/5c449bb1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/5c449bb1

Branch: refs/heads/master
Commit: 5c449bb18c87b87e9c00df6a324c0ef87e6dadeb
Parents: 3d756b3
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Wed Mar 1 11:16:15 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 12:40:41 2017 +0100

----------------------------------------------------------------------
 apps/bletiny/src/main.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5c449bb1/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 442a264..c0177c0 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -1740,6 +1740,7 @@ bletiny_l2cap_disconnect(uint16_t conn_handle, uint16_t idx)
     struct bletiny_conn *conn;
     struct bletiny_l2cap_coc *coc;
     int i;
+    int rc = 0;
 
     conn = bletiny_conn_find(conn_handle);
     assert(conn != NULL);
@@ -1753,9 +1754,12 @@ bletiny_l2cap_disconnect(uint16_t conn_handle, uint16_t idx)
     }
     assert(coc != NULL);
 
-    ble_l2cap_disconnect(coc->chan);
+    rc = ble_l2cap_disconnect(coc->chan);
+    if (rc) {
+        console_printf("Could not disconnect channel rc=%d\n", rc);
+    }
 
-    return 0;
+    return rc;
 #endif
 }
 


[24/50] incubator-mynewt-core git commit: nimble/l2cap: Make ble_l2cap_chan available in ble_l2cap_rx_fn

Posted by ma...@apache.org.
nimble/l2cap: Make ble_l2cap_chan available in ble_l2cap_rx_fn

Each L2CAP channel has its data handler function. Till now we had
function per CID. In order to handle COC we need to have possibility
to handle more channels in same data handler function. For this reason
we need to have pointer to ble_l2cap_chan to which data are comming.

This patch does it.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/27bc9edf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/27bc9edf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/27bc9edf

Branch: refs/heads/master
Commit: 27bc9edf37d344ba67110ee80af148b1861392c6
Parents: d9f788b
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Thu Feb 2 14:44:47 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 12:40:42 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_l2cap.h    |  1 +
 net/nimble/host/src/ble_att.c               | 12 +++++++++---
 net/nimble/host/src/ble_att_priv.h          |  2 +-
 net/nimble/host/src/ble_gap.c               |  3 +--
 net/nimble/host/src/ble_hs_conn.c           |  9 +++++----
 net/nimble/host/src/ble_hs_conn_priv.h      |  2 +-
 net/nimble/host/src/ble_hs_hci_evt.c        |  3 ++-
 net/nimble/host/src/ble_l2cap.c             | 16 +++++++++++++---
 net/nimble/host/src/ble_l2cap_coc.c         |  5 ++---
 net/nimble/host/src/ble_l2cap_priv.h        |  7 ++++---
 net/nimble/host/src/ble_l2cap_sig.c         |  7 ++++---
 net/nimble/host/src/ble_l2cap_sig_priv.h    |  2 +-
 net/nimble/host/src/ble_sm.c                | 20 ++++++++++++++++----
 net/nimble/host/src/ble_sm_priv.h           |  2 +-
 net/nimble/host/test/src/ble_hs_test_util.c |  3 ++-
 net/nimble/host/test/src/ble_l2cap_test.c   |  4 ++--
 16 files changed, 65 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27bc9edf/net/nimble/host/include/host/ble_l2cap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_l2cap.h b/net/nimble/host/include/host/ble_l2cap.h
index 604d080..b3b03b9 100644
--- a/net/nimble/host/include/host/ble_l2cap.h
+++ b/net/nimble/host/include/host/ble_l2cap.h
@@ -174,6 +174,7 @@ struct ble_l2cap_event {
 
 typedef int ble_l2cap_event_fn(struct ble_l2cap_event *event, void *arg);
 
+uint16_t ble_l2cap_get_conn_handle(struct ble_l2cap_chan *chan);
 int ble_l2cap_create_server(uint16_t psm, uint16_t mtu,
                             ble_l2cap_event_fn *cb, void *cb_arg);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27bc9edf/net/nimble/host/src/ble_att.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att.c b/net/nimble/host/src/ble_att.c
index 329fcec..7876e0d 100644
--- a/net/nimble/host/src/ble_att.c
+++ b/net/nimble/host/src/ble_att.c
@@ -461,12 +461,18 @@ ble_att_chan_mtu(const struct ble_l2cap_chan *chan)
 }
 
 static int
-ble_att_rx(uint16_t conn_handle, struct os_mbuf **om)
+ble_att_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
 {
     const struct ble_att_rx_dispatch_entry *entry;
     uint8_t op;
+    uint16_t conn_handle;
     int rc;
 
+    conn_handle = ble_l2cap_get_conn_handle(chan);
+    if (!conn_handle) {
+        return BLE_HS_ENOTCONN;
+    }
+
     rc = os_mbuf_copydata(*om, 0, 1, &op);
     if (rc != 0) {
         return BLE_HS_EMSGSIZE;
@@ -551,11 +557,11 @@ ble_att_set_preferred_mtu(uint16_t mtu)
 }
 
 struct ble_l2cap_chan *
-ble_att_create_chan(void)
+ble_att_create_chan(uint16_t conn_handle)
 {
     struct ble_l2cap_chan *chan;
 
-    chan = ble_l2cap_chan_alloc();
+    chan = ble_l2cap_chan_alloc(conn_handle);
     if (chan == NULL) {
         return NULL;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27bc9edf/net/nimble/host/src/ble_att_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_priv.h b/net/nimble/host/src/ble_att_priv.h
index 22ed62e..af05684 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -159,7 +159,7 @@ SLIST_HEAD(ble_att_clt_entry_list, ble_att_clt_entry);
 
 /*** @gen */
 
-struct ble_l2cap_chan *ble_att_create_chan(void);
+struct ble_l2cap_chan *ble_att_create_chan(uint16_t conn_handle);
 void ble_att_conn_chan_find(uint16_t conn_handle, struct ble_hs_conn **out_conn,
                             struct ble_l2cap_chan **out_chan);
 void ble_att_inc_tx_stat(uint8_t att_op);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27bc9edf/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index 92c3d12..0a09d4c 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -1151,10 +1151,9 @@ ble_gap_rx_conn_complete(struct hci_le_conn_complete *evt)
     }
 
     /* We verified that there is a free connection when the procedure began. */
-    conn = ble_hs_conn_alloc();
+    conn = ble_hs_conn_alloc(evt->connection_handle);
     BLE_HS_DBG_ASSERT(conn != NULL);
 
-    conn->bhc_handle = evt->connection_handle;
     conn->bhc_itvl = evt->conn_itvl;
     conn->bhc_latency = evt->conn_latency;
     conn->bhc_supervision_timeout = evt->supervision_timeout;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27bc9edf/net/nimble/host/src/ble_hs_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn.c b/net/nimble/host/src/ble_hs_conn.c
index 02676fa..a371ace 100644
--- a/net/nimble/host/src/ble_hs_conn.c
+++ b/net/nimble/host/src/ble_hs_conn.c
@@ -102,7 +102,7 @@ ble_hs_conn_chan_insert(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan)
 }
 
 struct ble_hs_conn *
-ble_hs_conn_alloc(void)
+ble_hs_conn_alloc(uint16_t conn_handle)
 {
 #if !NIMBLE_BLE_CONNECT
     return NULL;
@@ -117,10 +117,11 @@ ble_hs_conn_alloc(void)
         goto err;
     }
     memset(conn, 0, sizeof *conn);
+    conn->bhc_handle = conn_handle;
 
     SLIST_INIT(&conn->bhc_channels);
 
-    chan = ble_att_create_chan();
+    chan = ble_att_create_chan(conn_handle);
     if (chan == NULL) {
         goto err;
     }
@@ -129,7 +130,7 @@ ble_hs_conn_alloc(void)
         goto err;
     }
 
-    chan = ble_l2cap_sig_create_chan();
+    chan = ble_l2cap_sig_create_chan(conn_handle);
     if (chan == NULL) {
         goto err;
     }
@@ -141,7 +142,7 @@ ble_hs_conn_alloc(void)
     /* Create the SM channel even if not configured. We need it to reject SM
      * messages.
      */
-    chan = ble_sm_create_chan();
+    chan = ble_sm_create_chan(conn_handle);
     if (chan == NULL) {
         goto err;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27bc9edf/net/nimble/host/src/ble_hs_conn_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn_priv.h b/net/nimble/host/src/ble_hs_conn_priv.h
index b58a0df..24e2e48 100644
--- a/net/nimble/host/src/ble_hs_conn_priv.h
+++ b/net/nimble/host/src/ble_hs_conn_priv.h
@@ -74,7 +74,7 @@ struct ble_hs_conn_addrs {
 };
 
 int ble_hs_conn_can_alloc(void);
-struct ble_hs_conn *ble_hs_conn_alloc(void);
+struct ble_hs_conn *ble_hs_conn_alloc(uint16_t conn_handle);
 void ble_hs_conn_free(struct ble_hs_conn *conn);
 void ble_hs_conn_insert(struct ble_hs_conn *conn);
 void ble_hs_conn_remove(struct ble_hs_conn *conn);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27bc9edf/net/nimble/host/src/ble_hs_hci_evt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_hci_evt.c b/net/nimble/host/src/ble_hs_hci_evt.c
index a2d7a52..7f868a6 100644
--- a/net/nimble/host/src/ble_hs_hci_evt.c
+++ b/net/nimble/host/src/ble_hs_hci_evt.c
@@ -659,7 +659,8 @@ ble_hs_hci_evt_acl_process(struct os_mbuf *om)
         /* Final fragment received. */
         BLE_HS_DBG_ASSERT(rx_cb != NULL);
         BLE_HS_DBG_ASSERT(rx_buf != NULL);
-        rc = rx_cb(conn_handle, &rx_buf);
+        rc = rx_cb(conn->bhc_rx_chan, &rx_buf);
+        ble_l2cap_forget_rx(conn, conn->bhc_rx_chan);
         os_mbuf_free_chain(rx_buf);
         break;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27bc9edf/net/nimble/host/src/ble_l2cap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap.c b/net/nimble/host/src/ble_l2cap.c
index 09ca9dc..d909b78 100644
--- a/net/nimble/host/src/ble_l2cap.c
+++ b/net/nimble/host/src/ble_l2cap.c
@@ -52,7 +52,7 @@ STATS_NAME_START(ble_l2cap_stats)
 STATS_NAME_END(ble_l2cap_stats)
 
 struct ble_l2cap_chan *
-ble_l2cap_chan_alloc(void)
+ble_l2cap_chan_alloc(uint16_t conn_handle)
 {
     struct ble_l2cap_chan *chan;
 
@@ -62,6 +62,7 @@ ble_l2cap_chan_alloc(void)
     }
 
     memset(chan, 0, sizeof *chan);
+    chan->conn_handle = conn_handle;
 
     STATS_INC(ble_l2cap_stats, chan_create);
 
@@ -126,6 +127,16 @@ ble_l2cap_prepend_hdr(struct os_mbuf *om, uint16_t cid, uint16_t len)
     return om;
 }
 
+uint16_t
+ble_l2cap_get_conn_handle(struct ble_l2cap_chan *chan)
+{
+    if (!chan) {
+        return 0;
+    }
+
+    return chan->conn_handle;
+}
+
 int
 ble_l2cap_create_server(uint16_t psm, uint16_t mtu,
                         ble_l2cap_event_fn *cb, void *cb_arg)
@@ -158,7 +169,7 @@ ble_l2cap_recv_ready(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_rx)
     /*TODO In here we going to update sdu_rx buffer */
 }
 
-static void
+void
 ble_l2cap_forget_rx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan)
 {
     conn->bhc_rx_chan = NULL;
@@ -221,7 +232,6 @@ ble_l2cap_rx_payload(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
         /* All fragments received. */
         *out_rx_cb = chan->rx_fn;
         *out_rx_buf = chan->rx_buf;
-        ble_l2cap_forget_rx(conn, chan);
         rc = 0;
     } else {
         /* More fragments remain. */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27bc9edf/net/nimble/host/src/ble_l2cap_coc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc.c b/net/nimble/host/src/ble_l2cap_coc.c
index 46b903b..178370d 100644
--- a/net/nimble/host/src/ble_l2cap_coc.c
+++ b/net/nimble/host/src/ble_l2cap_coc.c
@@ -117,7 +117,7 @@ ble_l2cap_coc_srv_find(uint16_t psm)
 }
 
 static int
-ble_l2cap_coc_rx_fn(uint16_t conn_handle, struct os_mbuf **rxom)
+ble_l2cap_coc_rx_fn(struct ble_l2cap_chan *chan, struct os_mbuf **rxom)
 {
     return 0;
 }
@@ -129,12 +129,11 @@ ble_l2cap_coc_chan_alloc(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
 {
     struct ble_l2cap_chan *chan;
 
-    chan = ble_l2cap_chan_alloc();
+    chan = ble_l2cap_chan_alloc(conn_handle);
     if (!chan) {
         return NULL;
     }
 
-    chan->conn_handle = conn_handle;
     chan->psm = psm;
     chan->cb = cb;
     chan->cb_arg = cb_arg;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27bc9edf/net/nimble/host/src/ble_l2cap_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_priv.h b/net/nimble/host/src/ble_l2cap_priv.h
index 81e350d..64ffa22 100644
--- a/net/nimble/host/src/ble_l2cap_priv.h
+++ b/net/nimble/host/src/ble_l2cap_priv.h
@@ -62,10 +62,11 @@ extern struct os_mempool ble_l2cap_chan_pool;
 
 typedef uint8_t ble_l2cap_chan_flags;
 
-typedef int ble_l2cap_rx_fn(uint16_t conn_handle, struct os_mbuf **rxom);
+typedef int ble_l2cap_rx_fn(struct ble_l2cap_chan *chan, struct os_mbuf **rxom);
 
 struct ble_l2cap_chan {
     SLIST_ENTRY(ble_l2cap_chan) next;
+    uint16_t conn_handle;
     uint16_t dcid;
     uint16_t scid;
     uint16_t my_mtu;
@@ -78,7 +79,6 @@ struct ble_l2cap_chan {
     ble_l2cap_rx_fn *rx_fn;
 
 #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
-    uint16_t conn_handle;
     uint16_t psm;
     struct ble_l2cap_coc_endpoint coc_rx;
     struct ble_l2cap_coc_endpoint coc_tx;
@@ -104,7 +104,7 @@ int ble_l2cap_parse_hdr(struct os_mbuf *om, int off,
 struct os_mbuf *ble_l2cap_prepend_hdr(struct os_mbuf *om, uint16_t cid,
                                       uint16_t len);
 
-struct ble_l2cap_chan *ble_l2cap_chan_alloc(void);
+struct ble_l2cap_chan *ble_l2cap_chan_alloc(uint16_t conn_handle);
 void ble_l2cap_chan_free(struct ble_l2cap_chan *chan);
 
 bool ble_l2cap_is_mtu_req_sent(const struct ble_l2cap_chan *chan);
@@ -118,6 +118,7 @@ int ble_l2cap_rx(struct ble_hs_conn *conn,
 int ble_l2cap_tx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
                  struct os_mbuf *txom);
 
+void ble_l2cap_forget_rx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan);
 int ble_l2cap_init(void);
 
 #ifdef __cplusplus

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27bc9edf/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index 560311d..93d73ed 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -1012,10 +1012,11 @@ ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan)
  *****************************************************************************/
 
 static int
-ble_l2cap_sig_rx(uint16_t conn_handle, struct os_mbuf **om)
+ble_l2cap_sig_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
 {
     struct ble_l2cap_sig_hdr hdr;
     ble_l2cap_sig_rx_fn *rx_cb;
+    uint16_t conn_handle = chan->conn_handle;
     int rc;
 
     STATS_INC(ble_l2cap_stats, sig_rx);
@@ -1054,11 +1055,11 @@ ble_l2cap_sig_rx(uint16_t conn_handle, struct os_mbuf **om)
 }
 
 struct ble_l2cap_chan *
-ble_l2cap_sig_create_chan(void)
+ble_l2cap_sig_create_chan(uint16_t conn_handle)
 {
     struct ble_l2cap_chan *chan;
 
-    chan = ble_l2cap_chan_alloc();
+    chan = ble_l2cap_chan_alloc(conn_handle);
     if (chan == NULL) {
         return NULL;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27bc9edf/net/nimble/host/src/ble_l2cap_sig_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig_priv.h b/net/nimble/host/src/ble_l2cap_sig_priv.h
index ad3b846..0677405 100644
--- a/net/nimble/host/src/ble_l2cap_sig_priv.h
+++ b/net/nimble/host/src/ble_l2cap_sig_priv.h
@@ -111,7 +111,7 @@ int ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan);
 
 void ble_l2cap_sig_conn_broken(uint16_t conn_handle, int reason);
 int32_t ble_l2cap_sig_timer(void);
-struct ble_l2cap_chan *ble_l2cap_sig_create_chan(void);
+struct ble_l2cap_chan *ble_l2cap_sig_create_chan(uint16_t conn_handle);
 int ble_l2cap_sig_init(void);
 
 #ifdef __cplusplus

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27bc9edf/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm.c b/net/nimble/host/src/ble_sm.c
index 2a880dc..603d99c 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -2326,15 +2326,21 @@ ble_sm_unbond(uint8_t peer_id_addr_type, const uint8_t *peer_id_addr)
 }
 
 static int
-ble_sm_rx(uint16_t conn_handle, struct os_mbuf **om)
+ble_sm_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
 {
     struct ble_sm_result res;
     ble_sm_rx_fn *rx_cb;
     uint8_t op;
+    uint16_t conn_handle;
     int rc;
 
     STATS_INC(ble_l2cap_stats, sm_rx);
 
+    conn_handle = ble_l2cap_get_conn_handle(chan);
+    if (!conn_handle) {
+        return BLE_HS_ENOTCONN;
+    }
+
     rc = os_mbuf_copydata(*om, 0, 1, &op);
     if (rc != 0) {
         return BLE_HS_EBADDATA;
@@ -2485,10 +2491,16 @@ ble_sm_init(void)
  * simple
  */
 static int
-ble_sm_rx(uint16_t handle, struct os_mbuf **om)
+ble_sm_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
 {
     struct ble_sm_pair_fail *cmd;
     struct os_mbuf *txom;
+    uint16_t handle;
+
+    handle = ble_l2cap_get_conn_handle(chan);
+    if (!handle) {
+        return BLE_HS_ENOTCONN;
+    }
 
     cmd = ble_sm_cmd_get(BLE_SM_OP_PAIR_FAIL, sizeof(*cmd), &txom);
     if (cmd == NULL) {
@@ -2502,11 +2514,11 @@ ble_sm_rx(uint16_t handle, struct os_mbuf **om)
 #endif
 
 struct ble_l2cap_chan *
-ble_sm_create_chan(void)
+ble_sm_create_chan(uint16_t conn_handle)
 {
     struct ble_l2cap_chan *chan;
 
-    chan = ble_l2cap_chan_alloc();
+    chan = ble_l2cap_chan_alloc(conn_handle);
     if (chan == NULL) {
         return NULL;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27bc9edf/net/nimble/host/src/ble_sm_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_priv.h b/net/nimble/host/src/ble_sm_priv.h
index eb4f2da..86c31da 100644
--- a/net/nimble/host/src/ble_sm_priv.h
+++ b/net/nimble/host/src/ble_sm_priv.h
@@ -419,7 +419,7 @@ int ble_sm_init(void);
 
 #endif
 
-struct ble_l2cap_chan *ble_sm_create_chan(void);
+struct ble_l2cap_chan *ble_sm_create_chan(uint16_t handle);
 void *ble_sm_cmd_get(uint8_t opcode, size_t len, struct os_mbuf **txom);
 int ble_sm_tx(uint16_t conn_handle, struct os_mbuf *txom);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27bc9edf/net/nimble/host/test/src/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_hs_test_util.c b/net/nimble/host/test/src/ble_hs_test_util.c
index 0dc1b18..9fa2d3d 100644
--- a/net/nimble/host/test/src/ble_hs_test_util.c
+++ b/net/nimble/host/test/src/ble_hs_test_util.c
@@ -954,7 +954,8 @@ ble_hs_test_util_l2cap_rx(uint16_t conn_handle,
     } else if (rc == 0) {
         TEST_ASSERT_FATAL(rx_cb != NULL);
         TEST_ASSERT_FATAL(rx_buf != NULL);
-        rc = rx_cb(conn_handle, &rx_buf);
+        rc = rx_cb(conn->bhc_rx_chan, &rx_buf);
+        ble_l2cap_forget_rx(conn, conn->bhc_rx_chan);
         os_mbuf_free_chain(rx_buf);
     } else if (rc == BLE_HS_EAGAIN) {
         /* More fragments on the way. */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/27bc9edf/net/nimble/host/test/src/ble_l2cap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_l2cap_test.c b/net/nimble/host/test/src/ble_l2cap_test.c
index 9c11607..e68971d 100644
--- a/net/nimble/host/test/src/ble_l2cap_test.c
+++ b/net/nimble/host/test/src/ble_l2cap_test.c
@@ -94,7 +94,7 @@ ble_l2cap_test_util_verify_tx_update_conn(
 }
 
 static int
-ble_l2cap_test_util_dummy_rx(uint16_t conn_handle, struct os_mbuf **om)
+ble_l2cap_test_util_dummy_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
 {
     return 0;
 }
@@ -113,7 +113,7 @@ ble_l2cap_test_util_create_conn(uint16_t conn_handle, uint8_t *addr,
     conn = ble_hs_conn_find(conn_handle);
     TEST_ASSERT_FATAL(conn != NULL);
 
-    chan = ble_l2cap_chan_alloc();
+    chan = ble_l2cap_chan_alloc(conn_handle);
     TEST_ASSERT_FATAL(chan != NULL);
 
     chan->scid = BLE_L2CAP_TEST_CID;


[16/50] incubator-mynewt-core git commit: nimble/l2cap: Fix handling scid/dcid in the channel.

Posted by ma...@apache.org.
nimble/l2cap: Fix handling scid/dcid in the channel.

This patch makes sure that each l2cap channel has corretly
set scid and dcid. In the same time dcid is use when sending
data.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/509cd5fb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/509cd5fb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/509cd5fb

Branch: refs/heads/master
Commit: 509cd5fb6bffd3cc1e682ae247b28687cbac2354
Parents: 5c449bb
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Thu Feb 16 06:31:43 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 12:40:41 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/src/ble_att.c        | 1 +
 net/nimble/host/src/ble_l2cap.c      | 2 +-
 net/nimble/host/src/ble_l2cap_priv.h | 2 +-
 net/nimble/host/src/ble_l2cap_sig.c  | 1 +
 net/nimble/host/src/ble_sm.c         | 1 +
 5 files changed, 5 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/509cd5fb/net/nimble/host/src/ble_att.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att.c b/net/nimble/host/src/ble_att.c
index ff1eebf..329fcec 100644
--- a/net/nimble/host/src/ble_att.c
+++ b/net/nimble/host/src/ble_att.c
@@ -561,6 +561,7 @@ ble_att_create_chan(void)
     }
 
     chan->scid = BLE_L2CAP_CID_ATT;
+    chan->dcid = BLE_L2CAP_CID_ATT;
     chan->my_mtu = ble_att_preferred_mtu_val;
     chan->rx_fn = ble_att_rx;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/509cd5fb/net/nimble/host/src/ble_l2cap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap.c b/net/nimble/host/src/ble_l2cap.c
index e94a234..09ca9dc 100644
--- a/net/nimble/host/src/ble_l2cap.c
+++ b/net/nimble/host/src/ble_l2cap.c
@@ -385,7 +385,7 @@ ble_l2cap_tx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
 {
     int rc;
 
-    txom = ble_l2cap_prepend_hdr(txom, chan->scid, OS_MBUF_PKTLEN(txom));
+    txom = ble_l2cap_prepend_hdr(txom, chan->dcid, OS_MBUF_PKTLEN(txom));
     if (txom == NULL) {
         return BLE_HS_ENOMEM;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/509cd5fb/net/nimble/host/src/ble_l2cap_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_priv.h b/net/nimble/host/src/ble_l2cap_priv.h
index cc4e0ed..81e350d 100644
--- a/net/nimble/host/src/ble_l2cap_priv.h
+++ b/net/nimble/host/src/ble_l2cap_priv.h
@@ -66,6 +66,7 @@ typedef int ble_l2cap_rx_fn(uint16_t conn_handle, struct os_mbuf **rxom);
 
 struct ble_l2cap_chan {
     SLIST_ENTRY(ble_l2cap_chan) next;
+    uint16_t dcid;
     uint16_t scid;
     uint16_t my_mtu;
     uint16_t peer_mtu;      /* 0 if not exchanged. */
@@ -78,7 +79,6 @@ struct ble_l2cap_chan {
 
 #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
     uint16_t conn_handle;
-    uint16_t dcid;
     uint16_t psm;
     struct ble_l2cap_coc_endpoint coc_rx;
     struct ble_l2cap_coc_endpoint coc_tx;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/509cd5fb/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index 40cda11..94bb271 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -1060,6 +1060,7 @@ ble_l2cap_sig_create_chan(void)
     }
 
     chan->scid = BLE_L2CAP_CID_SIG;
+    chan->dcid = BLE_L2CAP_CID_SIG;
     chan->my_mtu = BLE_L2CAP_SIG_MTU;
     chan->rx_fn = ble_l2cap_sig_rx;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/509cd5fb/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm.c b/net/nimble/host/src/ble_sm.c
index bb2c1aa..2a880dc 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -2512,6 +2512,7 @@ ble_sm_create_chan(void)
     }
 
     chan->scid = BLE_L2CAP_CID_SM;
+    chan->dcid = BLE_L2CAP_CID_SM;
     chan->my_mtu = BLE_SM_MTU;
     chan->rx_fn = ble_sm_rx;
 


[21/50] incubator-mynewt-core git commit: nimble/l2cap: Add helper to create L2CAP channel for LE CoC

Posted by ma...@apache.org.
nimble/l2cap: Add helper to create L2CAP channel for LE CoC

With this patch, creating L2CAP channel for LE CoC purposes is moved
to ble_l2cap_coc.c. It is because in that file we want to have
all the logic related to CoC e.g. credits, available servers, data handling


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/eb576bc2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/eb576bc2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/eb576bc2

Branch: refs/heads/master
Commit: eb576bc2036d1322cbc1fb216dea8fa0153968d9
Parents: 98ebb51
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Thu Feb 2 11:27:14 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 12:40:42 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_coc.c      | 57 ++++++++++++++++++++++++++-
 net/nimble/host/src/ble_l2cap_coc_priv.h | 11 ++++--
 net/nimble/host/src/ble_l2cap_sig.c      | 43 +++++---------------
 3 files changed, 73 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/eb576bc2/net/nimble/host/src/ble_l2cap_coc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc.c b/net/nimble/host/src/ble_l2cap_coc.c
index 6286d43..46b903b 100644
--- a/net/nimble/host/src/ble_l2cap_coc.c
+++ b/net/nimble/host/src/ble_l2cap_coc.c
@@ -87,7 +87,7 @@ ble_l2cap_coc_create_server(uint16_t psm, uint16_t mtu,
     return 0;
 }
 
-uint16_t
+static uint16_t
 ble_l2cap_coc_get_cid(void)
 {
     static uint16_t next_cid = BLE_L2CAP_COC_CID_START;
@@ -100,7 +100,7 @@ ble_l2cap_coc_get_cid(void)
     return next_cid++;
 }
 
-struct ble_l2cap_coc_srv *
+static struct ble_l2cap_coc_srv *
 ble_l2cap_coc_srv_find(uint16_t psm)
 {
     struct ble_l2cap_coc_srv *cur, *srv;
@@ -116,6 +116,59 @@ ble_l2cap_coc_srv_find(uint16_t psm)
     return srv;
 }
 
+static int
+ble_l2cap_coc_rx_fn(uint16_t conn_handle, struct os_mbuf **rxom)
+{
+    return 0;
+}
+
+struct ble_l2cap_chan *
+ble_l2cap_coc_chan_alloc(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
+                         struct os_mbuf *sdu_rx, ble_l2cap_event_fn *cb,
+                         void *cb_arg)
+{
+    struct ble_l2cap_chan *chan;
+
+    chan = ble_l2cap_chan_alloc();
+    if (!chan) {
+        return NULL;
+    }
+
+    chan->conn_handle = conn_handle;
+    chan->psm = psm;
+    chan->cb = cb;
+    chan->cb_arg = cb_arg;
+    chan->scid = ble_l2cap_coc_get_cid();
+    chan->my_mtu = BLE_L2CAP_COC_MTU;
+    chan->rx_fn = ble_l2cap_coc_rx_fn;
+    chan->coc_rx.mtu = mtu;
+    chan->coc_rx.credits = 10; /* FIXME Calculate it */
+    chan->coc_rx.sdu = sdu_rx;
+
+    return chan;
+}
+
+int
+ble_l2cap_coc_create_srv_chan(uint16_t conn_handle, uint16_t psm,
+                              struct ble_l2cap_chan **chan)
+{
+    struct ble_l2cap_coc_srv *srv;
+
+    /* Check if there is server registered on this PSM */
+    srv = ble_l2cap_coc_srv_find(psm);
+    if (!srv) {
+        return BLE_HS_ENOTSUP;
+    }
+
+    *chan = ble_l2cap_coc_chan_alloc(conn_handle, psm, srv->mtu, NULL, srv->cb,
+                                     srv->cb_arg);
+    if (!*chan) {
+        return BLE_HS_ENOMEM;
+    }
+
+    return 0;
+}
+
 int
 ble_l2cap_coc_init(void)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/eb576bc2/net/nimble/host/src/ble_l2cap_coc_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_coc_priv.h b/net/nimble/host/src/ble_l2cap_coc_priv.h
index 31e81e7..63c593e 100644
--- a/net/nimble/host/src/ble_l2cap_coc_priv.h
+++ b/net/nimble/host/src/ble_l2cap_coc_priv.h
@@ -23,9 +23,9 @@
 #include <inttypes.h>
 #include "syscfg/syscfg.h"
 #include "os/queue.h"
+#include "os/os_mbuf.h"
 #include "host/ble_l2cap.h"
 #include "ble_l2cap_sig_priv.h"
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -52,10 +52,15 @@ struct ble_l2cap_coc_srv {
 
 #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
 int ble_l2cap_coc_init(void);
-uint16_t ble_l2cap_coc_get_cid(void);
 int ble_l2cap_coc_create_server(uint16_t psm, uint16_t mtu,
                                 ble_l2cap_event_fn *cb, void *cb_arg);
-struct ble_l2cap_coc_srv * ble_l2cap_coc_srv_find(uint16_t psm);
+int ble_l2cap_coc_create_srv_chan(uint16_t conn_handle, uint16_t psm,
+                                  struct ble_l2cap_chan **chan);
+struct ble_l2cap_chan * ble_l2cap_coc_chan_alloc(uint16_t conn_handle,
+                                                 uint16_t psm, uint16_t mtu,
+                                                 struct os_mbuf *sdu_rx,
+                                                 ble_l2cap_event_fn *cb,
+                                                 void *cb_arg);
 #else
 #define ble_l2cap_coc_init()                                    0
 #define ble_l2cap_coc_create_server(psm, mtu, cb, cb_arg)       BLE_HS_ENOTSUP

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/eb576bc2/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index 7919a89..d6219d3 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -551,6 +551,8 @@ static int
 ble_l2cap_sig_ble_hs_err2coc_err(uint16_t ble_hs_err)
 {
     switch (ble_hs_err) {
+    case BLE_HS_ENOTSUP:
+        return BLE_L2CAP_COC_ERR_UNKNOWN_LE_PSM;
     case BLE_HS_ENOMEM:
         return BLE_L2CAP_COC_ERR_NO_RESOURCES;
     case BLE_HS_EAUTHEN:
@@ -631,8 +633,7 @@ ble_l2cap_sig_coc_req_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
     struct ble_l2cap_sig_le_con_req *req;
     struct os_mbuf *txom;
     struct ble_l2cap_sig_le_con_rsp *rsp;
-    struct ble_l2cap_coc_srv *srv;
-    struct ble_l2cap_chan *chan;
+    struct ble_l2cap_chan *chan = NULL;
     struct ble_hs_conn *conn;
     uint16_t scid;
 
@@ -657,13 +658,6 @@ ble_l2cap_sig_coc_req_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
     ble_hs_lock();
     conn = ble_hs_conn_find_assert(conn_handle);
 
-    /* Check if there is server registered on this PSM */
-    srv = ble_l2cap_coc_srv_find(le16toh(req->psm));
-    if (!srv) {
-        rsp->result = htole16(BLE_L2CAP_COC_ERR_UNKNOWN_LE_PSM);
-        goto failed;
-    }
-
     /* Verify CID */
     scid = le16toh(req->scid);
     if (scid < BLE_L2CAP_COC_CID_START || scid > BLE_L2CAP_COC_CID_END) {
@@ -672,19 +666,15 @@ ble_l2cap_sig_coc_req_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
         goto failed;
     }
 
-    chan = ble_l2cap_chan_alloc();
-    if (!chan) {
-        rsp->result = htole16(BLE_L2CAP_COC_ERR_NO_RESOURCES);
+    rc = ble_l2cap_coc_create_srv_chan(conn_handle, le16toh(req->psm), &chan);
+    if (rc != 0) {
+        uint16_t coc_err = ble_l2cap_sig_ble_hs_err2coc_err(rc);
+        rsp->result = htole16(coc_err);
         goto failed;
     }
 
-    chan->cb = srv->cb;
-    chan->cb_arg = srv->cb_arg;
-    chan->conn_handle = conn_handle;
-    chan->dcid = scid;
-    chan->my_mtu = BLE_L2CAP_COC_MTU;
-
     /* Fill up remote configuration. Note MPS is the L2CAP MTU*/
+    chan->dcid = scid;
     chan->peer_mtu = le16toh(req->mps);
     chan->coc_tx.credits = le16toh(req->credits);
     chan->coc_tx.mtu = le16toh(req->mtu);
@@ -697,10 +687,6 @@ ble_l2cap_sig_coc_req_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
         goto failed;
     }
 
-    chan->scid = ble_l2cap_coc_get_cid();
-    chan->coc_rx.mtu = srv->mtu;
-    chan->coc_rx.credits = 10; //FIXME Calculate it
-
     rsp->dcid = htole16(chan->scid);
     rsp->credits = htole16(chan->coc_rx.credits);
     rsp->mps = htole16(chan->my_mtu);
@@ -795,7 +781,7 @@ ble_l2cap_sig_coc_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
     struct ble_l2cap_sig_proc *proc;
     struct os_mbuf *txom;
     struct ble_l2cap_sig_le_con_req *req;
-    struct ble_l2cap_chan *chan;
+    struct ble_l2cap_chan *chan = NULL;
     int rc;
 
     if (!sdu_rx || !cb) {
@@ -810,7 +796,7 @@ ble_l2cap_sig_coc_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
         return BLE_HS_ENOTCONN;
     }
 
-    chan = ble_l2cap_chan_alloc();
+    chan = ble_l2cap_coc_chan_alloc(conn_handle, psm, mtu, sdu_rx, cb, cb_arg);
     if (!chan) {
         ble_hs_unlock();
         return BLE_HS_ENOMEM;
@@ -823,15 +809,6 @@ ble_l2cap_sig_coc_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
         return BLE_HS_ENOMEM;
     }
 
-    chan->scid = ble_l2cap_coc_get_cid();
-    chan->my_mtu = BLE_L2CAP_COC_MTU;
-    chan->coc_rx.credits = 10;
-    chan->coc_rx.mtu = mtu;
-    chan->coc_rx.sdu = sdu_rx;
-    chan->cb = cb;
-    chan->cb_arg = cb_arg;
-    chan->conn_handle = conn_handle;
-
     proc->op = BLE_L2CAP_SIG_PROC_OP_CONNECT;
     proc->id = ble_l2cap_sig_next_id();
     proc->conn_handle = conn_handle;


[02/50] incubator-mynewt-core git commit: bletiny: Add missing returns in L2CAP connect/disconnect

Posted by ma...@apache.org.
bletiny: Add missing returns in L2CAP connect/disconnect

Fix missing error returns.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/b552c163
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/b552c163
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/b552c163

Branch: refs/heads/master
Commit: b552c1636787546611dd683f6efeddd73377dd4f
Parents: 316c18a
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Wed Feb 22 17:04:10 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Wed Mar 1 12:10:48 2017 +0100

----------------------------------------------------------------------
 apps/bletiny/src/cmd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b552c163/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index 8904ea2..47ab379 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -1226,6 +1226,7 @@ cmd_l2cap_connect(int argc, char **argv)
     if (rc != 0) {
         console_printf("invalid 'conn' parameter\n");
         help_cmd_uint16("conn");
+        return rc;
     }
 
     psm = parse_arg_uint16("psm", &rc);
@@ -1265,13 +1266,14 @@ cmd_l2cap_disconnect(int argc, char **argv)
     if (rc != 0) {
         console_printf("invalid 'conn' parameter\n");
         help_cmd_uint16("conn");
+        return rc;
     }
 
     idx = parse_arg_uint16("idx", &rc);
     if (rc != 0) {
         console_printf("invalid 'idx' parameter\n");
         help_cmd_uint16("idx");
-        return 0;
+        return rc;
     }
 
     return bletiny_l2cap_disconnect(conn, idx);


[10/50] incubator-mynewt-core git commit: MYNEWT-492 Add missing syscfg setting descriptions

Posted by ma...@apache.org.
MYNEWT-492 Add missing syscfg setting descriptions


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/b7c8714b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/b7c8714b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/b7c8714b

Branch: refs/heads/master
Commit: b7c8714b865bfa022fc174ff9adb84f2409de32f
Parents: cc8ead3
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Mar 2 17:41:40 2017 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Mar 2 17:43:10 2017 -0800

----------------------------------------------------------------------
 hw/bsp/ci40/syscfg.yml                      |   2 +-
 net/nimble/host/services/bleuart/syscfg.yml |   4 +-
 net/nimble/host/syscfg.yml                  | 179 ++++++++++++++++-------
 net/nimble/syscfg.yml                       |  18 ++-
 4 files changed, 142 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b7c8714b/hw/bsp/ci40/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/ci40/syscfg.yml b/hw/bsp/ci40/syscfg.yml
index ddcf459..09b7da4 100644
--- a/hw/bsp/ci40/syscfg.yml
+++ b/hw/bsp/ci40/syscfg.yml
@@ -21,7 +21,7 @@
 
 syscfg.defs:
     CLOCK_FREQ:
-        description: 'TBD'
+        description: 'Clock frequency (hertz).'
         value:  546000000ul
 
     UART_0:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b7c8714b/net/nimble/host/services/bleuart/syscfg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/bleuart/syscfg.yml b/net/nimble/host/services/bleuart/syscfg.yml
index 328838d..8ce3e63 100644
--- a/net/nimble/host/services/bleuart/syscfg.yml
+++ b/net/nimble/host/services/bleuart/syscfg.yml
@@ -20,5 +20,7 @@
 
 syscfg.defs:
     BLEUART_MAX_INPUT:
-        description: 'TBD'
+        description: >
+            The size of the largest line that can be received over the UART
+            service.
         value: 120

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b7c8714b/net/nimble/host/syscfg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/syscfg.yml b/net/nimble/host/syscfg.yml
index 6a52b82..d7ffddb 100644
--- a/net/nimble/host/syscfg.yml
+++ b/net/nimble/host/syscfg.yml
@@ -25,21 +25,30 @@ syscfg.defs:
 
     # Debug settings.
     BLE_HS_DEBUG:
-        description: 'TBD'
+        description: 'Enables extra runtime assertions.'
         value: 0
     BLE_HS_PHONY_HCI_ACKS:
-        description: 'TBD'
+        description: >
+            Rather than wait for HCI acknowledgements from a controller, the
+            host simulates incoming acks.  Only recommended for test code
+            running in the simulator.
         value: 0
     BLE_HS_REQUIRE_OS:
-        description: 'TBD'
+        description: >
+            Specifies whether the host can depend on the kernel being present.
+            This should only be disabled for unit tests running in the
+            simulator.
         value: 1
 
     # L2CAP settings.
     BLE_L2CAP_MAX_CHANS:
-        description: 'TBD'
+        description: >
+            The number of L2CAP channels to allocate.  The default value allows
+            for the signal, ATT, and SM channels for each connection.
         value: '3*MYNEWT_VAL_BLE_MAX_CONNECTIONS'
     BLE_L2CAP_SIG_MAX_PROCS:
-        description: 'TBD'
+        description: >
+            The maximum number of concurrent L2CAP signal procedures.
         value: 1
     BLE_L2CAP_JOIN_RX_FRAGS:
         description: >
@@ -69,147 +78,213 @@ syscfg.defs:
         value: 0
 
     BLE_SM_MAX_PROCS:
-        description: 'TBD'
+        description: >
+            The maximum number of concurrent security manager procedures.
         value: 1
     BLE_SM_IO_CAP:
-        description: 'TBD'
+        description: >
+            The IO capabilities to report during pairing.  Valid values are:
+                BLE_HS_IO_DISPLAY_ONLY
+                BLE_HS_IO_DISPLAY_YESNO
+                BLE_HS_IO_KEYBOARD_ONLY
+                BLE_HS_IO_NO_INPUT_OUTPUT
+                BLE_HS_IO_KEYBOARD_DISPLAY
         value: 'BLE_HS_IO_NO_INPUT_OUTPUT'
     BLE_SM_OOB_DATA_FLAG:
-        description: 'TBD'
+        description: >
+            Whether the out-of-band pairing algorithm is advertised. (0/1)
         value: 0
     BLE_SM_BONDING:
-        description: 'TBD'
+        description: >
+            Enables bonding (persistence and restoration of secure links). (0/1)
         value: 0
     BLE_SM_MITM:
-        description: 'TBD'
+        description: >
+            Whether man-in-the-middle protection is advertised during
+            pairing. (0/1)
         value: 0
     BLE_SM_KEYPRESS:
-        description: 'TBD'
+        description: >
+            Whether keypress support is advertised during pairing. (0/1)
         value: 0
     BLE_SM_OUR_KEY_DIST:
-        description: 'TBD'
+        description: >
+            A bitmap indicating which keys to distribute during pairing.  The
+            bits are defined as follows:
+                0x01: BLE_SM_PAIR_KEY_DIST_ENC
+                0x02: BLE_SM_PAIR_KEY_DIST_ID
+                0x04: BLE_SM_PAIR_KEY_DIST_SIGN
+                0x08: BLE_SM_PAIR_KEY_DIST_LINK
         value: 0
     BLE_SM_THEIR_KEY_DIST:
-        description: 'TBD'
+        description: >
+            A bitmap indicating which keys to accept during pairing.  The
+            bits are defined as follows:
+                0x01: BLE_SM_PAIR_KEY_DIST_ENC
+                0x02: BLE_SM_PAIR_KEY_DIST_ID
+                0x04: BLE_SM_PAIR_KEY_DIST_SIGN
+                0x08: BLE_SM_PAIR_KEY_DIST_LINK
         value: 0
 
     # Supported GATT procedures.  By default:
     #     o Notify and indicate are enabled;
     #     o All other procedures are enabled for centrals.
     BLE_GATT_DISC_ALL_SVCS:
-        description: 'TBD'
+        description: >
+            Enables the Discover All Primary Services GATT procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_DISC_SVC_UUID:
-        description: 'TBD'
+        description: >
+            Enables the Discover Primary Services by Service UUID GATT
+            procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_FIND_INC_SVCS:
-        description: 'TBD'
+        description: >
+            Enables the Find Included Services GATT procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_DISC_ALL_CHRS:
-        description: 'TBD'
+        description: >
+            Enables the Discover All Characteristics of a Service GATT
+            procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_DISC_CHR_UUID:
-        description: 'TBD'
+        description: >
+            Enables the Discover Characteristics by UUID GATT procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_DISC_ALL_DSCS:
-        description: 'TBD'
+        description: >
+            Enables the Discover All Primary Services GATT procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_READ:
-        description: 'TBD'
+        description: >
+            Enables the Read Characteristic Value GATT procedure. (0/1)
+            (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_READ_UUID:
-        description: 'TBD'
+        description: >
+            Enables the Read Using Characteristic UUID GATT procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_READ_LONG:
-        description: 'TBD'
+        description: >
+            Enables the Read Long Characteristic Values GATT procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_READ_MULT:
-        description: 'TBD'
+        description: >
+            Enables the Read Multiple Characteristic Values GATT procedure.
+            (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_WRITE_NO_RSP:
-        description: 'TBD'
+        description: >
+            Enables the Write Without Response GATT procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_SIGNED_WRITE:
-        description: 'TBD'
+        description: >
+            Enables the Signed Write Without Response GATT procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_WRITE:
-        description: 'TBD'
+        description: >
+            Enables the Write Characteristic Value GATT procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_WRITE_LONG:
-        description: 'TBD'
+        description: >
+            Enables the Write Long Characteristic Values GATT procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_WRITE_RELIABLE:
-        description: 'TBD'
+        description: >
+            Enables the Reliable Writes GATT procedure. (0/1)
         value: MYNEWT_VAL_BLE_ROLE_CENTRAL
     BLE_GATT_NOTIFY:
-        description: 'TBD'
+        description: >
+            Enables sending and receiving of GATT notifications. (0/1)
         value: 1
     BLE_GATT_INDICATE:
-        description: 'TBD'
+        description: >
+            Enables sending and receiving of GATT indications. (0/1)
         value: 1
 
     # GATT options.
     BLE_GATT_READ_MAX_ATTRS:
         description: >
             The maximum number of attributes that can be read with a single
-            GATT Read Multiple Characteristic Values procedure.
+            GATT Read Multiple Characteristic Values procedure. (0/1)
         value: 8
     BLE_GATT_WRITE_MAX_ATTRS:
         description: >
             The maximum number of attributes that can be written with a single
-            GATT Reliable Write procedure.
+            GATT Reliable Write procedure. (0/1)
         value: 4
     BLE_GATT_MAX_PROCS:
         description: >
-            The maximum number of concurrent client GATT procedures.
+            The maximum number of concurrent client GATT procedures. (0/1)
         value: 4
     BLE_GATT_RESUME_RATE:
         description: >
             The rate to periodically resume GATT procedures that have stalled
-            due to memory exhaustion.  Units are milliseconds.
+            due to memory exhaustion. (0/1)  Units are milliseconds. (0/1)
         value: 1000
 
-    # Supported server ATT commands.
+    # Supported server ATT commands. (0/1)
     BLE_ATT_SVR_FIND_INFO:
-        description: 'TBD'
+        description: >
+            Enables processing of incoming Find Information Request ATT
+            commands. (0/1)
         value: 1
     BLE_ATT_SVR_FIND_TYPE:
-        description: 'TBD'
+        description: >
+            Enables processing of incoming Find By Type Value Request ATT
+            commands. (0/1)
         value: 1
     BLE_ATT_SVR_READ_TYPE:
-        description: 'TBD'
+        description: >
+            Enables processing of incoming Read By Type Request ATT commands.
+            (0/1)
         value: 1
     BLE_ATT_SVR_READ:
-        description: 'TBD'
+        description: >
+            Enables processing of incoming Read Request ATT commands. (0/1)
         value: 1
     BLE_ATT_SVR_READ_BLOB:
-        description: 'TBD'
+        description: >
+            Enables processing of incoming Read Blob Request ATT commands.
+            (0/1)
         value: 1
     BLE_ATT_SVR_READ_MULT:
-        description: 'TBD'
+        description: >
+            Enables processing of incoming Read Multiple Request ATT commands.
+            (0/1)
         value: 1
     BLE_ATT_SVR_READ_GROUP_TYPE:
-        description: 'TBD'
+        description: >
+            Enables processing of incoming Read by Group Type Request ATT
+            commands. (0/1)
         value: 1
     BLE_ATT_SVR_WRITE:
-        description: 'TBD'
+        description: >
+            Enables processing of incoming Write Request ATT commands. (0/1)
         value: 1
     BLE_ATT_SVR_WRITE_NO_RSP:
-        description: 'TBD'
+        description: >
+            Enables processing of incoming Write Command ATT commands. (0/1)
         value: 1
     BLE_ATT_SVR_SIGNED_WRITE:
-        description: 'TBD'
+        description: >
+            Enables processing of incoming Signed Write Command ATT commands.
+            (0/1)
         value: 1
     BLE_ATT_SVR_QUEUED_WRITE:
         description: >
-            Whether the device can receive ATT queued writes (prepare write
-            and execute write requests).
+            Enables processing of incoming Prepare Write Request and Execute
+            Write Request ATT commands. (0/1)
         value: 1
     BLE_ATT_SVR_NOTIFY:
-        description: 'TBD'
+        description: >
+            Enables processing of incoming Handle Value Notification ATT
+            commands. (0/1)
         value: 1
     BLE_ATT_SVR_INDICATE:
-        description: 'TBD'
+        description: >
+            Enables processing of incoming Handle Value Indication ATT
+            commands.  (0/1)
         value: 1
 
     # ATT options.
@@ -230,10 +305,12 @@ syscfg.defs:
 
     # Privacy options.
     BLE_RPA_TIMEOUT:
-        description: 'TBD'
+        description: >
+            The rate that new random addresses should be generated (seconds).
         value: 300
 
     # Miscellaneous features.
     BLE_EDDYSTONE:
-        description: 'TBD'
+        description: >
+            Enables advertising of Eddystone beacons.
         value: 1

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b7c8714b/net/nimble/syscfg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/syscfg.yml b/net/nimble/syscfg.yml
index f44da01..7f348b8 100644
--- a/net/nimble/syscfg.yml
+++ b/net/nimble/syscfg.yml
@@ -21,23 +21,25 @@
 syscfg.defs:
     # Supported GAP roles.  By default, all four roles are enabled.
     BLE_ROLE_CENTRAL:
-        description: 'TBD'
+        description: 'Enables the Central bluetooth role. (0/1)'
         value: 1
     BLE_ROLE_PERIPHERAL:
-        description: 'TBD'
+        description: 'Enables the Peripheral bluetooth role. (0/1)'
         value: 1
     BLE_ROLE_BROADCASTER:
-        description: 'TBD'
+        description: 'Enables the Broadcaster bluetooth role. (0/1)'
         value: 1
     BLE_ROLE_OBSERVER:
-        description: 'TBD'
+        description: 'Enables the Observer bluetooth role. (0/1)'
         value: 1
 
     BLE_MAX_CONNECTIONS:
         description: 'The maximum number of concurrent connections.'
         value: 1
     BLE_WHITELIST:
-        description: 'TBD'
+        description: >
+            Enables the BLE whitelist for controlling who to connect to or
+            accept a connection from. (0/1)
         value: 1
     BLE_MULTI_ADV_SUPPORT:
         description: 'Support for multi-advertisers'
@@ -45,7 +47,7 @@ syscfg.defs:
     BLE_MULTI_ADV_INSTANCES:
         description: >
             This is the number of multi-advertising instances. This is NOT the
-            total number of advertising instances. The total number of advertising
-            instances is this number plus 1 (assuming the device supports
-            advertising).
+            total number of advertising instances. The total number of
+            advertising instances is this number plus 1 (assuming the device
+            supports advertising).
         value: 0


[12/50] incubator-mynewt-core git commit: BNO055 driver - fix multiple length read issue

Posted by ma...@apache.org.
BNO055 driver - fix multiple length read issue


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/8d757705
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/8d757705
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/8d757705

Branch: refs/heads/master
Commit: 8d757705fe2627b766da621cce2d01d4e5bad687
Parents: b7c8714
Author: Vipul Rahane <vi...@apache.org>
Authored: Thu Mar 2 18:56:30 2017 -0800
Committer: Vipul Rahane <vi...@apache.org>
Committed: Thu Mar 2 18:57:17 2017 -0800

----------------------------------------------------------------------
 hw/drivers/sensors/bno055/src/bno055.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8d757705/hw/drivers/sensors/bno055/src/bno055.c
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/bno055/src/bno055.c b/hw/drivers/sensors/bno055/src/bno055.c
index 4b9f32c..6773650 100644
--- a/hw/drivers/sensors/bno055/src/bno055.c
+++ b/hw/drivers/sensors/bno055/src/bno055.c
@@ -240,7 +240,7 @@ bno055_readlen(uint8_t reg, uint8_t *buffer, uint8_t len)
     };
 
     /* Clear the supplied buffer */
-    memset(buffer, 0, 22);
+    memset(buffer, 0, len);
 
     /* Register write */
     rc = hal_i2c_master_write(MYNEWT_VAL(BNO055_I2CBUS), &data_struct,


[40/50] incubator-mynewt-core git commit: This closes #190.

Posted by ma...@apache.org.
This closes #190.

Merge remote-tracking branch 'rymanluk/l2cap_coc' into develop

* rymanluk/l2cap_coc: (25 commits)
  nimble/l2cap: Add initial credits calculations
  nimble/l2cap: Improve L2CAP LE CoC connection handling
  nimble/l2cap: Fix hanlding broken ACL during L2CAP procedure
  nimble/l2cap: Fix for possible memory leak
  nimble/l2cap: Handle REJECT CMD on L2CAP LE CoC connection create req
  nibmle/l2cap: Clear LE CoC channel on ACL drop
  nimble/l2cap: Add suppport to send data over L2CAP LE CoC
  nimble/l2cap: Add helper to clean L2CAP LE CoC channel
  nimble/l2cap: Add handling receiving SDU over L2CAP LE CoC
  nimble/l2cap: Add LE credits update handling
  nimble/l2cap: Remove not needed **om from ble_l2cap_rx_fn
  nimble/l2cap: Make ble_l2cap_chan available in ble_l2cap_rx_fn
  nimble/l2cap: Remove not needed function ble_l2cap_sig_init_cmd
  nimble/l2cap: Refactor handling L2CAP reject command
  nimble/l2cap: Fix handling bad data in L2CAP update parameters response
  nimble/l2cap: Add helper to create L2CAP channel for LE CoC
  nimble/l2cap: Refactor update parameters handling
  nimble/l2cap: Fix L2CAP LE CoC disconnection handling
  nimble/l2cap: Memset response in L2CAP LE CoC connect request
  nimble/l2cap: Fix handling scid/dcid in the channel.
  ...


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/b2ea1dc2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/b2ea1dc2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/b2ea1dc2

Branch: refs/heads/master
Commit: b2ea1dc2caeb0706bad7d30e83488f48b56e1a3f
Parents: e324152 750707b
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Mar 3 09:18:06 2017 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Fri Mar 3 09:18:06 2017 -0800

----------------------------------------------------------------------
 apps/bletiny/src/bletiny.h                  |   1 +
 apps/bletiny/src/cmd.c                      |  54 +++-
 apps/bletiny/src/main.c                     | 118 ++++++-
 net/nimble/host/include/host/ble_l2cap.h    |   1 +
 net/nimble/host/src/ble_att.c               |  19 +-
 net/nimble/host/src/ble_att_priv.h          |   2 +-
 net/nimble/host/src/ble_gap.c               |   3 +-
 net/nimble/host/src/ble_hs_conn.c           |  32 +-
 net/nimble/host/src/ble_hs_conn_priv.h      |   6 +-
 net/nimble/host/src/ble_hs_hci_evt.c        |   8 +-
 net/nimble/host/src/ble_hs_misc.c           |   2 +-
 net/nimble/host/src/ble_l2cap.c             |  33 +-
 net/nimble/host/src/ble_l2cap_coc.c         | 383 ++++++++++++++++++++++-
 net/nimble/host/src/ble_l2cap_coc_priv.h    |  21 +-
 net/nimble/host/src/ble_l2cap_priv.h        |  11 +-
 net/nimble/host/src/ble_l2cap_sig.c         | 269 ++++++++++------
 net/nimble/host/src/ble_l2cap_sig_cmd.c     | 168 +---------
 net/nimble/host/src/ble_l2cap_sig_priv.h    |  26 +-
 net/nimble/host/src/ble_sm.c                |  31 +-
 net/nimble/host/src/ble_sm_priv.h           |   2 +-
 net/nimble/host/test/src/ble_hs_conn_test.c |   6 +-
 net/nimble/host/test/src/ble_hs_test_util.c |  50 ++-
 net/nimble/host/test/src/ble_l2cap_test.c   |  22 +-
 23 files changed, 912 insertions(+), 356 deletions(-)
----------------------------------------------------------------------



[34/50] incubator-mynewt-core git commit: nimble/l2cap: Fix hanlding broken ACL during L2CAP procedure

Posted by ma...@apache.org.
nimble/l2cap: Fix hanlding broken ACL during L2CAP procedure

With this patch we make sure that all processing procedures are
free and user is notified about broken link


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/38ae5704
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/38ae5704
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/38ae5704

Branch: refs/heads/master
Commit: 38ae570452466f55cd15f7b03b78b25babcd1c66
Parents: 34e6486
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Wed Mar 1 09:26:17 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 12:40:42 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_sig.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/38ae5704/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index 444a8f6..439acfe 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -1200,17 +1200,26 @@ ble_l2cap_sig_conn_broken(uint16_t conn_handle, int reason)
 {
     struct ble_l2cap_sig_proc *proc;
 
-    /* If there was a connection update in progress, indicate to the
-     * application that it did not complete.
-     */
-
-    proc = ble_l2cap_sig_proc_extract(conn_handle,
-                                      BLE_L2CAP_SIG_PROC_OP_UPDATE, 0);
+    /* Report a failure for each timed out procedure. */
+    while ((proc = STAILQ_FIRST(&ble_l2cap_sig_procs)) != NULL) {
+        switch(proc->op) {
+            case BLE_L2CAP_SIG_PROC_OP_UPDATE:
+                ble_l2cap_sig_update_call_cb(proc, reason);
+                break;
+#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
+            case BLE_L2CAP_SIG_PROC_OP_CONNECT:
+                ble_l2cap_sig_coc_connect_cb(proc, reason);
+            break;
+            case BLE_L2CAP_SIG_PROC_OP_DISCONNECT:
+                ble_l2cap_sig_coc_disconnect_cb(proc, reason);
+            break;
+#endif
+            }
 
-    if (proc != NULL) {
-        ble_l2cap_sig_update_call_cb(proc, reason);
-        ble_l2cap_sig_proc_free(proc);
+            STAILQ_REMOVE_HEAD(&ble_l2cap_sig_procs, next);
+            ble_l2cap_sig_proc_free(proc);
     }
+
 }
 
 /**


[39/50] incubator-mynewt-core git commit: MYNEWT-527; add Windows wrapper script to nrf51-blenano.

Posted by ma...@apache.org.
MYNEWT-527; add Windows wrapper script to nrf51-blenano.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/e3241525
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/e3241525
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/e3241525

Branch: refs/heads/master
Commit: e3241525f37c3d72506a6e8f2ccd2bde24540c60
Parents: 4a9cb51
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Fri Mar 3 08:10:38 2017 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Fri Mar 3 08:10:38 2017 -0800

----------------------------------------------------------------------
 hw/bsp/nrf51-blenano/bsp.yml              | 2 ++
 hw/bsp/nrf51-blenano/nrf51dk_debug.cmd    | 3 +++
 hw/bsp/nrf51-blenano/nrf51dk_download.cmd | 3 +++
 3 files changed, 8 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e3241525/hw/bsp/nrf51-blenano/bsp.yml
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-blenano/bsp.yml b/hw/bsp/nrf51-blenano/bsp.yml
index c174892..ee95b51 100644
--- a/hw/bsp/nrf51-blenano/bsp.yml
+++ b/hw/bsp/nrf51-blenano/bsp.yml
@@ -28,6 +28,8 @@ bsp.linkerscript.BOOT_LOADER.OVERWRITE:
 bsp.part2linkerscript: "hw/bsp/nrf51-blenano/split-nrf51dk.ld"
 bsp.downloadscript: "hw/bsp/nrf51-blenano/nrf51dk_download.sh"
 bsp.debugscript: "hw/bsp/nrf51-blenano/nrf51dk_debug.sh"
+bsp.downloadscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51-blenano/nrf51dk_download.cmd"
+bsp.debugscript.WINDOWS.OVERRIDE: "hw/bsp/nrf51-blenano/nrf51dk_debug.cmd"
 
 bsp.flash_map:
     areas:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e3241525/hw/bsp/nrf51-blenano/nrf51dk_debug.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-blenano/nrf51dk_debug.cmd b/hw/bsp/nrf51-blenano/nrf51dk_debug.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/nrf51-blenano/nrf51dk_debug.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e3241525/hw/bsp/nrf51-blenano/nrf51dk_download.cmd
----------------------------------------------------------------------
diff --git a/hw/bsp/nrf51-blenano/nrf51dk_download.cmd b/hw/bsp/nrf51-blenano/nrf51dk_download.cmd
new file mode 100755
index 0000000..d6cfc11
--- /dev/null
+++ b/hw/bsp/nrf51-blenano/nrf51dk_download.cmd
@@ -0,0 +1,3 @@
+@rem Execute a shell with a script of the same name and .sh extension
+
+@bash "%~dp0%~n0.sh"


[45/50] incubator-mynewt-core git commit: MYNEWT-654 datetime command may crash device

Posted by ma...@apache.org.
MYNEWT-654 datetime command may crash device

There are two issues here:

1. newtmgr tool always includes an extraneous rc:0 key-value pair in its
   outgoing datetime commands.
2. Server-side, the firmware parses the "rc" value and writes the result
   to null.

This commit addresses the second issue as follows: Don't attempt to
parse the rc entry in incoming requests.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/847f0241
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/847f0241
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/847f0241

Branch: refs/heads/master
Commit: 847f0241784e49a03cc44865d23958a126b3c210
Parents: 2242bc1
Author: Christopher Collins <cc...@apache.org>
Authored: Sat Mar 4 14:24:38 2017 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Sat Mar 4 14:24:38 2017 -0800

----------------------------------------------------------------------
 mgmt/newtmgr/nmgr_os/src/newtmgr_os.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/847f0241/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
----------------------------------------------------------------------
diff --git a/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c b/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
index 2a75d47..b69766e 100644
--- a/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
+++ b/mgmt/newtmgr/nmgr_os/src/newtmgr_os.c
@@ -271,17 +271,13 @@ nmgr_datetime_set(struct mgmt_cbuf *cb)
     struct os_timezone tz;
     char buf[DATETIME_BUFSIZE];
     int rc = 0;
-    const struct cbor_attr_t datetime_write_attr[3] = {
+    const struct cbor_attr_t datetime_write_attr[] = {
         [0] = {
             .attribute = "datetime",
             .type = CborAttrTextStringType,
             .addr.string = buf,
             .len = sizeof(buf),
         },
-        [1] = {
-            .attribute = "rc",
-            .type = CborAttrIntegerType,
-        },
         { 0 },
     };
 


[25/50] incubator-mynewt-core git commit: nimble/l2cap: Remove not needed function ble_l2cap_sig_init_cmd

Posted by ma...@apache.org.
nimble/l2cap: Remove not needed function ble_l2cap_sig_init_cmd

After refactor this function is not needed anymore in the host code.
The only user of it is unitest and this patch fixes that.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/d9f788b4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/d9f788b4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/d9f788b4

Branch: refs/heads/master
Commit: d9f788b49df395538cc2081eabe38161a3165ca7
Parents: ba9de55
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Tue Feb 28 13:23:41 2017 +0100
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Fri Mar 3 12:40:42 2017 +0100

----------------------------------------------------------------------
 net/nimble/host/src/ble_l2cap_sig_cmd.c     | 34 ----------------------
 net/nimble/host/test/src/ble_hs_test_util.c | 22 ++++-----------
 net/nimble/host/test/src/ble_l2cap_test.c   | 36 ++++++------------------
 3 files changed, 13 insertions(+), 79 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d9f788b4/net/nimble/host/src/ble_l2cap_sig_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig_cmd.c b/net/nimble/host/src/ble_l2cap_sig_cmd.c
index e6a7209..4381be5 100644
--- a/net/nimble/host/src/ble_l2cap_sig_cmd.c
+++ b/net/nimble/host/src/ble_l2cap_sig_cmd.c
@@ -21,40 +21,6 @@
 #include "ble_hs_priv.h"
 
 int
-ble_l2cap_sig_init_cmd(uint8_t op, uint8_t id, uint8_t payload_len,
-                       struct os_mbuf **out_om, void **out_payload_buf)
-{
-    struct ble_l2cap_sig_hdr hdr;
-    struct os_mbuf *txom;
-    void *v;
-
-    *out_om = NULL;
-    *out_payload_buf = NULL;
-
-    txom = ble_hs_mbuf_l2cap_pkt();
-    if (txom == NULL) {
-        return BLE_HS_ENOMEM;
-    }
-
-    v = os_mbuf_extend(txom, BLE_L2CAP_SIG_HDR_SZ + payload_len);
-    if (v == NULL) {
-        os_mbuf_free(txom);
-        return BLE_HS_ENOMEM;
-    }
-
-    hdr.op = op;
-    hdr.identifier = id;
-    hdr.length = TOFROMLE16(payload_len);
-
-    ble_l2cap_sig_hdr_write(v, BLE_L2CAP_SIG_HDR_SZ, &hdr);
-
-    *out_om = txom;
-    *out_payload_buf = (uint8_t *)v + BLE_L2CAP_SIG_HDR_SZ;
-
-    return 0;
-}
-
-int
 ble_l2cap_sig_tx(uint16_t conn_handle, struct os_mbuf *txom)
 {
     struct ble_l2cap_chan *chan;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d9f788b4/net/nimble/host/test/src/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_hs_test_util.c b/net/nimble/host/test/src/ble_hs_test_util.c
index ceabd1c..0dc1b18 100644
--- a/net/nimble/host/test/src/ble_hs_test_util.c
+++ b/net/nimble/host/test/src/ble_hs_test_util.c
@@ -1820,36 +1820,24 @@ ble_l2cap_sig_update_rsp_parse(void *payload, int len,
     dst->result = le16toh(src->result);
 }
 
-static void
-ble_l2cap_test_update_rsp_write(void *payload, int len,
-                               struct ble_l2cap_sig_update_rsp *src)
-{
-    struct ble_l2cap_sig_update_rsp *dst = payload;
-
-    BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_RSP_SZ);
-    dst->result = htole16(src->result);
-}
-
 int
 ble_hs_test_util_rx_l2cap_update_rsp(uint16_t conn_handle,
                                      uint8_t id, uint16_t result)
 {
-    struct ble_l2cap_sig_update_rsp rsp;
+    struct ble_l2cap_sig_update_rsp *rsp;
     struct hci_data_hdr hci_hdr;
     struct os_mbuf *om;
-    void *v;
     int rc;
 
     hci_hdr = BLE_HS_TEST_UTIL_L2CAP_HCI_HDR(
         2, BLE_HCI_PB_FIRST_FLUSH,
         BLE_L2CAP_HDR_SZ + BLE_L2CAP_SIG_HDR_SZ + BLE_L2CAP_SIG_UPDATE_RSP_SZ);
 
-    rc = ble_l2cap_sig_init_cmd(BLE_L2CAP_SIG_OP_UPDATE_RSP, id,
-                                BLE_L2CAP_SIG_UPDATE_RSP_SZ, &om, &v);
-    TEST_ASSERT_FATAL(rc == 0);
+    rsp = ble_l2cap_sig_cmd_get(BLE_L2CAP_SIG_OP_UPDATE_RSP, id,
+                                BLE_L2CAP_SIG_UPDATE_RSP_SZ, &om);
+    TEST_ASSERT_FATAL(rsp != NULL);
 
-    rsp.result = result;
-    ble_l2cap_test_update_rsp_write(v, BLE_L2CAP_SIG_UPDATE_RSP_SZ, &rsp);
+    rsp->result = htole16(result);
 
     rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SIG,
                                               &hci_hdr, om);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d9f788b4/net/nimble/host/test/src/ble_l2cap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/test/src/ble_l2cap_test.c b/net/nimble/host/test/src/ble_l2cap_test.c
index 2958a6c..9c11607 100644
--- a/net/nimble/host/test/src/ble_l2cap_test.c
+++ b/net/nimble/host/test/src/ble_l2cap_test.c
@@ -44,46 +44,26 @@ ble_l2cap_test_util_init(void)
 }
 
 static void
-ble_l2cap_test_update_req_swap(struct ble_l2cap_sig_update_req *dst,
-                              struct ble_l2cap_sig_update_req *src)
-{
-    dst->itvl_min = le16toh(src->itvl_min);
-    dst->itvl_max = le16toh(src->itvl_max);
-    dst->slave_latency = le16toh(src->slave_latency);
-    dst->timeout_multiplier = le16toh(src->timeout_multiplier);
-}
-
-static void
-ble_l2cap_test_update_req_write(void *payload, int len,
-                               struct ble_l2cap_sig_update_req *src)
-{
-    BLE_HS_DBG_ASSERT(len >= BLE_L2CAP_SIG_UPDATE_REQ_SZ);
-    ble_l2cap_test_update_req_swap(payload, src);
-}
-
-static void
 ble_l2cap_test_util_rx_update_req(uint16_t conn_handle, uint8_t id,
                                   struct ble_l2cap_sig_update_params *params)
 {
-    struct ble_l2cap_sig_update_req req;
+    struct ble_l2cap_sig_update_req *req;
     struct hci_data_hdr hci_hdr;
     struct os_mbuf *om;
-    void *v;
     int rc;
 
     hci_hdr = BLE_HS_TEST_UTIL_L2CAP_HCI_HDR(
         2, BLE_HCI_PB_FIRST_FLUSH,
         BLE_L2CAP_HDR_SZ + BLE_L2CAP_SIG_HDR_SZ + BLE_L2CAP_SIG_UPDATE_REQ_SZ);
 
-    rc = ble_l2cap_sig_init_cmd(BLE_L2CAP_SIG_OP_UPDATE_REQ, id,
-                                BLE_L2CAP_SIG_UPDATE_REQ_SZ, &om, &v);
-    TEST_ASSERT_FATAL(rc == 0);
+    req = ble_l2cap_sig_cmd_get(BLE_L2CAP_SIG_OP_UPDATE_REQ, id,
+                                BLE_L2CAP_SIG_UPDATE_REQ_SZ, &om);
+    TEST_ASSERT_FATAL(req != NULL);
 
-    req.itvl_min = params->itvl_min;
-    req.itvl_max = params->itvl_max;
-    req.slave_latency = params->slave_latency;
-    req.timeout_multiplier = params->timeout_multiplier;
-    ble_l2cap_test_update_req_write(v, BLE_L2CAP_SIG_UPDATE_REQ_SZ, &req);
+    req->itvl_min = htole16(params->itvl_min);
+    req->itvl_max = htole16(params->itvl_max);
+    req->slave_latency = htole16(params->slave_latency);
+    req->timeout_multiplier = htole16(params->timeout_multiplier);
 
     ble_hs_test_util_set_ack(
         ble_hs_hci_util_opcode_join(BLE_HCI_OGF_LE,