mgmt/mcumgr/lib: Remove non-Zephyr code

The commit removes MYNEWT sepcific code and code that has been
conditionally compiled with "ifndef _ZEPHYR_".

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
This commit is contained in:
Dominik Ermel 2021-10-20 12:56:23 +00:00 committed by Carles Cufí
parent c8381a9d14
commit dfc57ae390
8 changed files with 0 additions and 401 deletions

View File

@ -28,10 +28,6 @@
#include <sys/types.h>
#include "tinycbor/cbor.h"
#ifdef MYNEWT
#include <os/os_mbuf.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
@ -127,44 +123,6 @@ struct cbor_attr_t {
bool nodefault;
};
#ifndef __ZEPHYR__
/** An array value to be encoded as CBOR. */
struct cbor_out_arr_val_t {
struct cbor_out_val_t *elems;
size_t len;
};
/** A single value to be encoded as CBOR. */
struct cbor_out_val_t {
/** The type of data. */
CborAttrType type;
/** The data value. */
union {
long long int integer;
long long unsigned int uinteger;
double real;
float fval;
uint16_t halffloat;
const char *string;
bool boolean;
struct {
const uint8_t *data;
size_t len;
} bytestring;
struct cbor_out_arr_val_t array;
struct cbor_out_attr_t *obj; /* Terminated with a type=0 entry. */
};
};
/** An object key-value pair to be encoded as CBOR. */
struct cbor_out_attr_t {
const char *attribute; /** The attribute name (key). */
struct cbor_out_val_t val; /** The attribute value. */
bool omit; /** Attribute ignored if true. */
};
#endif
/*
* Use the following macros to declare template initializers for
* CborAttrStructObjectType arrays. Writing the equivalents out by hand is
@ -192,33 +150,6 @@ int cbor_read_array(struct CborValue *, const struct cbor_array_t *);
int cbor_read_flat_attrs(const uint8_t *data, int len,
const struct cbor_attr_t *attrs);
#ifdef MYNEWT
int cbor_read_mbuf_attrs(struct os_mbuf *m, uint16_t off, uint16_t len,
const struct cbor_attr_t *attrs);
/**
* @brief Encodes a CBOR representation of the specified key-value map.
*
* @param enc The CBOR encoder to write to.
* @param attrs The key-value map to encode.
*
* @return 0 on success; SYS_E[...] error on failure.
*/
int cbor_write_object(struct CborEncoder *enc,
const struct cbor_out_attr_t *attrs);
/**
* @brief Encodes a CBOR representation of the specified key-value map into an
* msys mbuf chain.
*
* @param attrs The key-value map to encode.
* @param out_om On success, points to the populate mbuf chain.
*
* @return 0 on success; SYS_E[...] error on failure.
*/
int cbor_write_object_msys(const struct cbor_out_attr_t *attrs,
struct os_mbuf **out_om);
#endif
#ifdef __cplusplus
}
#endif

View File

@ -21,22 +21,12 @@
#include "tinycbor/cbor.h"
#include "tinycbor/cbor_buf_reader.h"
#ifdef __ZEPHYR__
#include <zephyr.h>
#ifdef CONFIG_MGMT_CBORATTR_MAX_SIZE
#define CBORATTR_MAX_SIZE CONFIG_MGMT_CBORATTR_MAX_SIZE
#else
#define CBORATTR_MAX_SIZE 512
#endif
#endif
#ifdef MYNEWT
#include "syscfg/syscfg.h"
#include "tinycbor/cbor_mbuf_reader.h"
#include "tinycbor/cbor_mbuf_writer.h"
#include "os/os_mbuf.h"
#define CBORATTR_MAX_SIZE MYNEWT_VAL(CBORATTR_MAX_SIZE)
#endif
/* this maps a CborType to a matching CborAtter Type. The mapping is not
* one-to-one because of signedness of integers
@ -424,222 +414,3 @@ cbor_read_flat_attrs(const uint8_t *data, int len,
}
return cbor_read_object(&value, attrs);
}
#ifdef MYNEWT
static int cbor_write_val(struct CborEncoder *enc,
const struct cbor_out_val_t *val);
/*
* Read in cbor key/values from os_mbuf pointed by m, and fill them
* into attrs.
*
* @param m Pointer to os_mbuf containing cbor encoded data
* @param off Offset into mbuf where cbor data begins
* @param len Number of bytes to decode
* @param attrs Array of cbor objects to look for.
*
* @return 0 on success; non-zero on failure.
*/
int
cbor_read_mbuf_attrs(struct os_mbuf *m, uint16_t off, uint16_t len,
const struct cbor_attr_t *attrs)
{
struct cbor_mbuf_reader cmr;
struct CborParser parser;
struct CborValue value;
CborError err;
cbor_mbuf_reader_init(&cmr, m, off);
err = cbor_parser_init(&cmr.r, 0, &parser, &value);
if (err != CborNoError) {
return -1;
}
return cbor_read_object(&value, attrs);
}
static int
cbor_write_arr_val(struct CborEncoder *enc,
const struct cbor_out_arr_val_t *arr)
{
struct CborEncoder arr_enc;
size_t i;
int rc;
rc = cbor_encoder_create_array(enc, &arr_enc, arr->len);
if (rc != 0) {
return SYS_ENOMEM;
}
for (i = 0; i < arr->len; i++) {
rc = cbor_write_val(&arr_enc, &arr->elems[i]);
if (rc != 0) {
return SYS_ENOMEM;
}
}
rc = cbor_encoder_close_container(enc, &arr_enc);
if (rc != 0) {
return SYS_ENOMEM;
}
return 0;
}
static int
cbor_write_val(struct CborEncoder *enc, const struct cbor_out_val_t *val)
{
int len;
int rc;
switch (val->type) {
case CborAttrNullType:
rc = cbor_encode_null(enc);
break;
case CborAttrBooleanType:
rc = cbor_encode_boolean(enc, val->boolean);
break;
case CborAttrIntegerType:
rc = cbor_encode_int(enc, val->integer);
break;
case CborAttrUnsignedIntegerType:
rc = cbor_encode_uint(enc, val->uinteger);
break;
#if FLOAT_SUPPORT
case CborAttrHalfFloatType:
rc = cbor_encode_half_float(enc, &val->halffloat);
break;
case CborAttrFloatType:
rc = cbor_encode_float(enc, val->fval);
break;
case CborAttrDoubleType:
rc = cbor_encode_double(enc, val->real);
break;
#endif
case CborAttrByteStringType:
if (val->bytestring.data == NULL &&
val->bytestring.len != 0) {
return SYS_EINVAL;
}
rc = cbor_encode_byte_string(enc, val->bytestring.data,
val->bytestring.len);
break;
case CborAttrTextStringType:
if (val->string == NULL) {
len = 0;
} else {
len = strlen(val->string);
}
rc = cbor_encode_text_string(enc, val->string, len);
break;
case CborAttrObjectType:
rc = cbor_write_object(enc, val->obj);
break;
case CborAttrArrayType:
rc = cbor_write_arr_val(enc, &val->array);
break;
default:
return SYS_ENOTSUP;
}
if (rc != 0) {
return SYS_ENOMEM;
}
return 0;
}
static int
cbor_write_attr(struct CborEncoder *enc, const struct cbor_out_attr_t *attr)
{
int len;
int rc;
if (attr->omit) {
return 0;
}
if (!attr->attribute) {
rc = SYS_EINVAL;
return rc;
}
len = strlen(attr->attribute);
rc = cbor_encode_text_string(enc, attr->attribute, len);
if (rc != 0) {
return rc;
}
rc = cbor_write_val(enc, &attr->val);
if (rc != 0) {
return rc;
}
return 0;
}
int
cbor_write_object(struct CborEncoder *enc, const struct cbor_out_attr_t *attrs)
{
const struct cbor_out_attr_t *attr;
struct CborEncoder map;
int rc;
rc = cbor_encoder_create_map(enc, &map, CborIndefiniteLength);
if (rc != 0) {
return SYS_ENOMEM;
}
for (attr = attrs; attr->val.type != 0; attr++) {
rc = cbor_write_attr(&map, attr);
if (rc != 0) {
return rc;
}
}
rc = cbor_encoder_close_container(enc, &map);
if (rc != 0) {
return SYS_ENOMEM;
}
return 0;
}
int
cbor_write_object_msys(const struct cbor_out_attr_t *attrs,
struct os_mbuf **out_om)
{
struct cbor_mbuf_writer writer;
struct CborEncoder encoder;
int rc;
*out_om = os_msys_get_pkthdr(0, 0);
if (*out_om == NULL) {
return SYS_ENOMEM;
}
cbor_mbuf_writer_init(&writer, *out_om);
cbor_encoder_init(&encoder, &writer.enc, 0);
rc = cbor_write_object(&encoder, attrs);
if (rc != 0) {
os_mbuf_free_chain(*out_om);
*out_om = NULL;
return rc;
}
return 0;
}
#endif

View File

@ -35,15 +35,3 @@ TEST_SUITE(test_cborattr_suite)
test_cborattr_decode_unnamed_array();
test_cborattr_decode_substring_key();
}
#if MYNEWT_VAL(SELFTEST)
int
main(int argc, char **argv)
{
sysinit();
test_cborattr_suite();
return tu_any_failed;
}
#endif

View File

@ -20,17 +20,6 @@
#ifndef H_FS_MGMT_CONFIG_
#define H_FS_MGMT_CONFIG_
#if defined MYNEWT
#include "syscfg/syscfg.h"
#define FS_MGMT_DL_CHUNK_SIZE MYNEWT_VAL(FS_MGMT_DL_CHUNK_SIZE)
#define FS_MGMT_PATH_SIZE MYNEWT_VAL(FS_MGMT_PATH_SIZE)
#define FS_MGMT_UL_CHUNK_SIZE MYNEWT_VAL(FS_MGMT_UL_CHUNK_SIZE)
#elif defined __ZEPHYR__
#define MCUMGR_BUF_SIZE CONFIG_MCUMGR_BUF_SIZE
/* File chunk needs to fit into MCUGMR_BUF_SZIE with all required headers
* and other data fields; following information takes space off the
@ -73,12 +62,4 @@
#define FS_MGMT_PATH_SIZE CONFIG_FS_MGMT_PATH_SIZE
#define FS_MGMT_UL_CHUNK_SIZE CONFIG_FS_MGMT_UL_CHUNK_SIZE
#else
/* No direct support for this OS. The application needs to define the above
* settings itself.
*/
#endif
#endif

View File

@ -25,18 +25,6 @@
/* Image status list will only contain image attributes that are true/non-zero */
#define IMG_MGMT_FRUGAL_LIST 0
#if defined MYNEWT
#include "syscfg/syscfg.h"
#define IMG_MGMT_UL_CHUNK_SIZE MYNEWT_VAL(IMG_MGMT_UL_CHUNK_SIZE)
#define IMG_MGMT_VERBOSE_ERR MYNEWT_VAL(IMG_MGMT_VERBOSE_ERR)
#define IMG_MGMT_LAZY_ERASE MYNEWT_VAL(IMG_MGMT_LAZY_ERASE)
#define IMG_MGMT_DUMMY_HDR MYNEWT_VAL(IMG_MGMT_DUMMY_HDR)
#define IMG_MGMT_BOOT_CURR_SLOT boot_current_slot
#elif defined __ZEPHYR__
#define IMG_MGMT_UL_CHUNK_SIZE CONFIG_IMG_MGMT_UL_CHUNK_SIZE
#define IMG_MGMT_VERBOSE_ERR CONFIG_IMG_MGMT_VERBOSE_ERR
#define IMG_MGMT_LAZY_ERASE CONFIG_IMG_ERASE_PROGRESSIVELY
@ -52,13 +40,4 @@
#define IMG_MGMT_FRUGAL_LIST CONFIG_IMG_MGMT_FRUGAL_LIST
#endif
#else
/* No direct support for this OS. The application needs to define the above
* settings itself.
*/
#error "Unknown OS/missing configuration"
#endif
#endif

View File

@ -20,26 +20,8 @@
#ifndef H_OS_MGMT_CONFIG_
#define H_OS_MGMT_CONFIG_
#if defined MYNEWT
#include "syscfg/syscfg.h"
#define OS_MGMT_RESET_MS MYNEWT_VAL(OS_MGMT_RESET_MS)
#define OS_MGMT_TASKSTAT MYNEWT_VAL(OS_MGMT_TASKSTAT)
#define OS_MGMT_ECHO MYNEWT_VAL(OS_MGMT_ECHO)
#elif defined __ZEPHYR__
#define OS_MGMT_RESET_MS CONFIG_OS_MGMT_RESET_MS
#define OS_MGMT_TASKSTAT CONFIG_OS_MGMT_TASKSTAT
#define OS_MGMT_ECHO CONFIG_OS_MGMT_ECHO
#else
/* No direct support for this OS. The application needs to define the above
* settings itself.
*/
#endif
#endif

View File

@ -20,24 +20,7 @@
#ifndef H_SHELL_MGMT_CONFIG_
#define H_SHELL_MGMT_CONFIG_
#if defined MYNEWT
#include "syscfg/syscfg.h"
#define SHELL_MGMT_MAX_LINE_LEN MYNEWT_VAL(SHELL_BRIDGE_MAX_IN_LEN)
#define SHELL_MGMT_MAX_ARGC MYNEWT_VAL(SHELL_CMD_ARGC_MAX)
#elif defined __ZEPHYR__
#define SHELL_MGMT_MAX_LINE_LEN CONFIG_SHELL_CMD_BUFF_SIZE
#define SHELL_MGMT_MAX_ARGC CONFIG_SHELL_ARGC_MAX
#else
/* No direct support for this OS. The application needs to define the above
* settings itself.
*/
#endif
#endif

View File

@ -20,22 +20,6 @@
#ifndef H_STAT_MGMT_CONFIG_
#define H_STAT_MGMT_CONFIG_
#if defined MYNEWT
#include "syscfg/syscfg.h"
#define STAT_MGMT_MAX_NAME_LEN MYNEWT_VAL(STAT_MGMT_MAX_NAME_LEN)
#elif defined __ZEPHYR__
#define STAT_MGMT_MAX_NAME_LEN CONFIG_STAT_MGMT_MAX_NAME_LEN
#else
/* No direct support for this OS. The application needs to define the above
* settings itself.
*/
#endif
#endif