net: lwm2m: Convert to new logging system

Use new logging system instead of SYS_LOG.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2018-09-19 11:22:19 +03:00
commit 5705573c46
13 changed files with 388 additions and 370 deletions

View file

@ -22,9 +22,11 @@
* - Handle Resource ObjLink type
*/
#define SYS_LOG_DOMAIN "lib/lwm2m_engine"
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_LWM2M_LEVEL
#include <logging/sys_log.h>
#define LOG_MODULE_NAME net_lwm2m_engine
#define LOG_LEVEL CONFIG_LWM2M_LOG_LEVEL
#include <logging/log.h>
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
#include <zephyr/types.h>
#include <stddef.h>
@ -190,11 +192,11 @@ char *lwm2m_sprint_ip_addr(const struct sockaddr *addr)
}
#endif
SYS_LOG_ERR("Unknown IP address family:%d", addr->sa_family);
LOG_ERR("Unknown IP address family:%d", addr->sa_family);
return NULL;
}
#if CONFIG_SYS_LOG_LWM2M_LEVEL > 3
#if LOG_LEVEL >= LOG_LEVEL_DBG
static u8_t to_hex_digit(u8_t digit)
{
if (digit >= 10) {
@ -279,7 +281,7 @@ init_block_ctx(const u8_t *token, u8_t tkl, struct block_context **ctx)
}
if (*ctx == NULL) {
SYS_LOG_ERR("Cannot find free block context");
LOG_ERR("Cannot find free block context");
return -ENOMEM;
}
@ -309,7 +311,7 @@ get_block_ctx(const u8_t *token, u8_t tkl, struct block_context **ctx)
}
if (*ctx == NULL) {
SYS_LOG_ERR("Cannot find block context");
LOG_ERR("Cannot find block context");
return -ENOENT;
}
@ -353,8 +355,8 @@ static int update_attrs(void *ref, struct notification_attrs *out)
out->st = write_attr_pool[i].float_val;
break;
default:
SYS_LOG_ERR("Unrecognize attr: %d",
write_attr_pool[i].type);
LOG_ERR("Unrecognize attr: %d",
write_attr_pool[i].type);
return -EINVAL;
}
@ -391,8 +393,8 @@ int lwm2m_notify_observer(u16_t obj_id, u16_t obj_inst_id, u16_t res_id)
/* update the event time for this observer */
obs->event_timestamp = k_uptime_get();
SYS_LOG_DBG("NOTIFY EVENT %u/%u/%u",
obj_id, obj_inst_id, res_id);
LOG_DBG("NOTIFY EVENT %u/%u/%u",
obj_id, obj_inst_id, res_id);
ret++;
}
@ -425,13 +427,13 @@ static int engine_add_observer(struct lwm2m_message *msg,
int i, ret;
if (!msg || !msg->ctx) {
SYS_LOG_ERR("valid lwm2m message is required");
LOG_ERR("valid lwm2m message is required");
return -EINVAL;
}
if (!token || (tkl == 0 || tkl > MAX_TOKEN_LEN)) {
SYS_LOG_ERR("token(%p) and token length(%u) must be valid.",
token, tkl);
LOG_ERR("token(%p) and token length(%u) must be valid.",
token, tkl);
return -EINVAL;
}
@ -451,10 +453,10 @@ static int engine_add_observer(struct lwm2m_message *msg,
memcpy(obs->token, token, tkl);
obs->tkl = tkl;
SYS_LOG_DBG("OBSERVER DUPLICATE %u/%u/%u(%u) [%s]",
path->obj_id, path->obj_inst_id,
path->res_id, path->level,
lwm2m_sprint_ip_addr(addr));
LOG_DBG("OBSERVER DUPLICATE %u/%u/%u(%u) [%s]",
path->obj_id, path->obj_inst_id,
path->res_id, path->level,
lwm2m_sprint_ip_addr(addr));
return 0;
}
@ -463,7 +465,7 @@ static int engine_add_observer(struct lwm2m_message *msg,
/* check if object exists */
obj = get_engine_obj(path->obj_id);
if (!obj) {
SYS_LOG_ERR("unable to find obj: %u", path->obj_id);
LOG_ERR("unable to find obj: %u", path->obj_id);
return -ENOENT;
}
@ -477,8 +479,8 @@ static int engine_add_observer(struct lwm2m_message *msg,
obj_inst = get_engine_obj_inst(path->obj_id,
path->obj_inst_id);
if (!obj_inst) {
SYS_LOG_ERR("unable to find obj_inst: %u/%u",
path->obj_id, path->obj_inst_id);
LOG_ERR("unable to find obj_inst: %u/%u",
path->obj_id, path->obj_inst_id);
return -ENOENT;
}
@ -497,9 +499,9 @@ static int engine_add_observer(struct lwm2m_message *msg,
}
if (i == obj_inst->resource_count) {
SYS_LOG_ERR("unable to find res_id: %u/%u/%u",
path->obj_id, path->obj_inst_id,
path->res_id);
LOG_ERR("unable to find res_id: %u/%u/%u",
path->obj_id, path->obj_inst_id,
path->res_id);
return -ENOENT;
}
@ -507,9 +509,9 @@ static int engine_add_observer(struct lwm2m_message *msg,
obj_field = lwm2m_get_engine_obj_field(obj,
obj_inst->resources[i].res_id);
if (!obj_field) {
SYS_LOG_ERR("unable to find obj_field: %u/%u/%u",
path->obj_id, path->obj_inst_id,
path->res_id);
LOG_ERR("unable to find obj_field: %u/%u/%u",
path->obj_id, path->obj_inst_id,
path->res_id);
return -ENOENT;
}
@ -551,9 +553,9 @@ static int engine_add_observer(struct lwm2m_message *msg,
sys_slist_append(&engine_observer_list,
&observe_node_data[i].node);
SYS_LOG_DBG("OBSERVER ADDED %u/%u/%u(%u) token:'%s' addr:%s",
path->obj_id, path->obj_inst_id, path->res_id, path->level,
sprint_token(token, tkl), lwm2m_sprint_ip_addr(addr));
LOG_DBG("OBSERVER ADDED %u/%u/%u(%u) token:'%s' addr:%s",
path->obj_id, path->obj_inst_id, path->res_id, path->level,
sprint_token(token, tkl), lwm2m_sprint_ip_addr(addr));
return 0;
}
@ -564,8 +566,8 @@ static int engine_remove_observer(const u8_t *token, u8_t tkl)
sys_snode_t *prev_node = NULL;
if (!token || (tkl == 0 || tkl > MAX_TOKEN_LEN)) {
SYS_LOG_ERR("token(%p) and token length(%u) must be valid.",
token, tkl);
LOG_ERR("token(%p) and token length(%u) must be valid.",
token, tkl);
return -EINVAL;
}
@ -586,7 +588,7 @@ static int engine_remove_observer(const u8_t *token, u8_t tkl)
sys_slist_remove(&engine_observer_list, prev_node, &found_obj->node);
(void)memset(found_obj, 0, sizeof(*found_obj));
SYS_LOG_DBG("observer '%s' removed", sprint_token(token, tkl));
LOG_DBG("observer '%s' removed", sprint_token(token, tkl));
return 0;
}
@ -708,24 +710,24 @@ int lwm2m_create_obj_inst(u16_t obj_id, u16_t obj_inst_id,
*obj_inst = NULL;
obj = get_engine_obj(obj_id);
if (!obj) {
SYS_LOG_ERR("unable to find obj: %u", obj_id);
LOG_ERR("unable to find obj: %u", obj_id);
return -ENOENT;
}
if (!obj->create_cb) {
SYS_LOG_ERR("obj %u has no create_cb", obj_id);
LOG_ERR("obj %u has no create_cb", obj_id);
return -EINVAL;
}
if (obj->instance_count + 1 > obj->max_instance_count) {
SYS_LOG_ERR("no more instances available for obj %u", obj_id);
LOG_ERR("no more instances available for obj %u", obj_id);
return -ENOMEM;
}
*obj_inst = obj->create_cb(obj_inst_id);
if (!*obj_inst) {
SYS_LOG_ERR("unable to create obj %u instance %u",
obj_id, obj_inst_id);
LOG_ERR("unable to create obj %u instance %u",
obj_id, obj_inst_id);
/*
* Already checked for instance count total.
* This can only be an error if the object instance exists.
@ -741,8 +743,8 @@ int lwm2m_create_obj_inst(u16_t obj_id, u16_t obj_inst_id,
if (obj->user_create_cb) {
ret = obj->user_create_cb(obj_inst_id);
if (ret < 0) {
SYS_LOG_ERR("Error in user obj create %u/%u: %d",
obj_id, obj_inst_id, ret);
LOG_ERR("Error in user obj create %u/%u: %d",
obj_id, obj_inst_id, ret);
lwm2m_delete_obj_inst(obj_id, obj_inst_id);
return ret;
}
@ -773,8 +775,8 @@ int lwm2m_delete_obj_inst(u16_t obj_id, u16_t obj_inst_id)
if (obj->user_delete_cb) {
ret = obj->user_delete_cb(obj_inst_id);
if (ret < 0) {
SYS_LOG_ERR("Error in user obj delete %u/%u: %d",
obj_id, obj_inst_id, ret);
LOG_ERR("Error in user obj delete %u/%u: %d",
obj_id, obj_inst_id, ret);
/* don't return error */
}
}
@ -987,20 +989,20 @@ int lwm2m_init_message(struct lwm2m_message *msg)
int r = 0;
if (!msg || !msg->ctx) {
SYS_LOG_ERR("LwM2M message is invalid.");
LOG_ERR("LwM2M message is invalid.");
return -EINVAL;
}
app_ctx = &msg->ctx->net_app_ctx;
pkt = net_app_get_net_pkt(app_ctx, AF_UNSPEC, BUF_ALLOC_TIMEOUT);
if (!pkt) {
SYS_LOG_ERR("Unable to get TX packet, not enough memory.");
LOG_ERR("Unable to get TX packet, not enough memory.");
return -ENOMEM;
}
frag = net_app_get_net_buf(app_ctx, pkt, BUF_ALLOC_TIMEOUT);
if (!frag) {
SYS_LOG_ERR("Unable to get DATA buffer, not enough memory.");
LOG_ERR("Unable to get DATA buffer, not enough memory.");
r = -ENOMEM;
goto cleanup;
}
@ -1021,7 +1023,7 @@ int lwm2m_init_message(struct lwm2m_message *msg)
tokenlen, token, msg->code,
(msg->mid > 0 ? msg->mid : coap_next_id()));
if (r < 0) {
SYS_LOG_ERR("coap packet init error (err:%d)", r);
LOG_ERR("coap packet init error (err:%d)", r);
goto cleanup;
}
@ -1034,8 +1036,8 @@ int lwm2m_init_message(struct lwm2m_message *msg)
msg->ctx->pendings,
CONFIG_LWM2M_ENGINE_MAX_PENDING);
if (!msg->pending) {
SYS_LOG_ERR("Unable to find a free pending to track "
"retransmissions.");
LOG_ERR("Unable to find a free pending to track "
"retransmissions.");
r = -ENOMEM;
goto cleanup;
}
@ -1043,8 +1045,8 @@ int lwm2m_init_message(struct lwm2m_message *msg)
r = coap_pending_init(msg->pending, &msg->cpkt,
&app_ctx->default_ctx->remote);
if (r < 0) {
SYS_LOG_ERR("Unable to initialize a pending "
"retransmission (err:%d).", r);
LOG_ERR("Unable to initialize a pending "
"retransmission (err:%d).", r);
goto cleanup;
}
@ -1053,8 +1055,7 @@ int lwm2m_init_message(struct lwm2m_message *msg)
msg->ctx->replies,
CONFIG_LWM2M_ENGINE_MAX_REPLIES);
if (!msg->reply) {
SYS_LOG_ERR("No resources for "
"waiting for replies.");
LOG_ERR("No resources for waiting for replies.");
r = -ENOMEM;
goto cleanup;
}
@ -1080,7 +1081,7 @@ int lwm2m_send_message(struct lwm2m_message *msg)
int ret;
if (!msg || !msg->ctx) {
SYS_LOG_ERR("LwM2M message is invalid.");
LOG_ERR("LwM2M message is invalid.");
return -EINVAL;
}
@ -1206,7 +1207,7 @@ static int select_writer(struct lwm2m_output_context *out, u16_t accept)
#endif
default:
SYS_LOG_WRN("Unknown content type %u", accept);
LOG_WRN("Unknown content type %u", accept);
return -ENOMSG;
}
@ -1230,7 +1231,7 @@ static int select_reader(struct lwm2m_input_context *in, u16_t format)
break;
default:
SYS_LOG_WRN("Unknown content type %u", format);
LOG_WRN("Unknown content type %u", format);
return -ENOMSG;
}
@ -1290,8 +1291,7 @@ static int string_to_path(char *pathstr, struct lwm2m_obj_path *path,
break;
default:
SYS_LOG_ERR("invalid level (%d)",
path->level);
LOG_ERR("invalid level (%d)", path->level);
return -EINVAL;
}
@ -1321,19 +1321,19 @@ static int path_to_objs(const struct lwm2m_obj_path *path,
oi = get_engine_obj_inst(path->obj_id, path->obj_inst_id);
if (!oi) {
SYS_LOG_ERR("obj instance %d/%d not found",
path->obj_id, path->obj_inst_id);
LOG_ERR("obj instance %d/%d not found",
path->obj_id, path->obj_inst_id);
return -ENOENT;
}
if (!oi->resources || oi->resource_count == 0) {
SYS_LOG_ERR("obj instance has no resources");
LOG_ERR("obj instance has no resources");
return -EINVAL;
}
of = lwm2m_get_engine_obj_field(oi->obj, path->res_id);
if (!of) {
SYS_LOG_ERR("obj field %d not found", path->res_id);
LOG_ERR("obj field %d not found", path->res_id);
return -ENOENT;
}
@ -1345,7 +1345,7 @@ static int path_to_objs(const struct lwm2m_obj_path *path,
}
if (!r) {
SYS_LOG_ERR("res instance %d not found", path->res_id);
LOG_ERR("res instance %d not found", path->res_id);
return -ENOENT;
}
@ -1370,7 +1370,7 @@ int lwm2m_engine_create_obj_inst(char *pathstr)
struct lwm2m_engine_obj_inst *obj_inst;
int ret = 0;
SYS_LOG_DBG("path:%s", pathstr);
LOG_DBG("path:%s", pathstr);
/* translate path -> path_obj */
ret = string_to_path(pathstr, &path, '/');
@ -1379,7 +1379,7 @@ int lwm2m_engine_create_obj_inst(char *pathstr)
}
if (path.level != 2) {
SYS_LOG_ERR("path must have 2 parts");
LOG_ERR("path must have 2 parts");
return -EINVAL;
}
@ -1400,7 +1400,7 @@ int lwm2m_engine_set_res_data(char *pathstr, void *data_ptr, u16_t data_len,
}
if (path.level < 3) {
SYS_LOG_ERR("path must have 3 parts");
LOG_ERR("path must have 3 parts");
return -EINVAL;
}
@ -1429,7 +1429,7 @@ static int lwm2m_engine_set(char *pathstr, void *value, u16_t len)
int ret = 0;
bool changed = false;
SYS_LOG_DBG("path:%s, value:%p, len:%d", pathstr, value, len);
LOG_DBG("path:%s, value:%p, len:%d", pathstr, value, len);
/* translate path -> path_obj */
ret = string_to_path(pathstr, &path, '/');
@ -1438,7 +1438,7 @@ static int lwm2m_engine_set(char *pathstr, void *value, u16_t len)
}
if (path.level < 3) {
SYS_LOG_ERR("path must have 3 parts");
LOG_ERR("path must have 3 parts");
return -EINVAL;
}
@ -1449,12 +1449,12 @@ static int lwm2m_engine_set(char *pathstr, void *value, u16_t len)
}
if (!res) {
SYS_LOG_ERR("res instance %d not found", path.res_id);
LOG_ERR("res instance %d not found", path.res_id);
return -ENOENT;
}
if (LWM2M_HAS_RES_FLAG(res, LWM2M_RES_DATA_FLAG_RO)) {
SYS_LOG_ERR("res data pointer is read-only");
LOG_ERR("res data pointer is read-only");
return -EACCES;
}
@ -1468,15 +1468,15 @@ static int lwm2m_engine_set(char *pathstr, void *value, u16_t len)
}
if (!data_ptr) {
SYS_LOG_ERR("res data pointer is NULL");
LOG_ERR("res data pointer is NULL");
return -EINVAL;
}
/* check length (note: we add 1 to string length for NULL pad) */
if (len > res->data_len -
(obj_field->data_type == LWM2M_RES_TYPE_STRING ? 1 : 0)) {
SYS_LOG_ERR("length %u is too long for resource %d data",
len, path.res_id);
LOG_ERR("length %u is too long for resource %d data",
len, path.res_id);
return -ENOMEM;
}
@ -1547,8 +1547,7 @@ static int lwm2m_engine_set(char *pathstr, void *value, u16_t len)
break;
default:
SYS_LOG_ERR("unknown obj data_type %d",
obj_field->data_type);
LOG_ERR("unknown obj data_type %d", obj_field->data_type);
return -EINVAL;
}
@ -1648,7 +1647,7 @@ int lwm2m_engine_get_res_data(char *pathstr, void **data_ptr, u16_t *data_len,
}
if (path.level < 3) {
SYS_LOG_ERR("path must have 3 parts");
LOG_ERR("path must have 3 parts");
return -EINVAL;
}
@ -1675,7 +1674,7 @@ static int lwm2m_engine_get(char *pathstr, void *buf, u16_t buflen)
void *data_ptr = NULL;
size_t data_len = 0;
SYS_LOG_DBG("path:%s, buf:%p, buflen:%d", pathstr, buf, buflen);
LOG_DBG("path:%s, buf:%p, buflen:%d", pathstr, buf, buflen);
/* translate path -> path_obj */
ret = string_to_path(pathstr, &path, '/');
@ -1684,7 +1683,7 @@ static int lwm2m_engine_get(char *pathstr, void *buf, u16_t buflen)
}
if (path.level < 3) {
SYS_LOG_ERR("path must have 3 parts");
LOG_ERR("path must have 3 parts");
return -EINVAL;
}
@ -1695,7 +1694,7 @@ static int lwm2m_engine_get(char *pathstr, void *buf, u16_t buflen)
}
if (!res) {
SYS_LOG_ERR("res instance %d not found", path.res_id);
LOG_ERR("res instance %d not found", path.res_id);
return -ENOENT;
}
@ -1777,8 +1776,8 @@ static int lwm2m_engine_get(char *pathstr, void *buf, u16_t buflen)
break;
default:
SYS_LOG_ERR("unknown obj data_type %d",
obj_field->data_type);
LOG_ERR("unknown obj data_type %d",
obj_field->data_type);
return -EINVAL;
}
@ -1871,7 +1870,7 @@ int lwm2m_engine_get_resource(char *pathstr, struct lwm2m_engine_res_inst **res)
}
if (path.level < 3) {
SYS_LOG_ERR("path must have 3 parts");
LOG_ERR("path must have 3 parts");
return -EINVAL;
}
@ -1945,7 +1944,7 @@ int lwm2m_engine_register_create_callback(u16_t obj_id,
obj = get_engine_obj(obj_id);
if (!obj) {
SYS_LOG_ERR("unable to find obj: %u", obj_id);
LOG_ERR("unable to find obj: %u", obj_id);
return -ENOENT;
}
@ -1960,7 +1959,7 @@ int lwm2m_engine_register_delete_callback(u16_t obj_id,
obj = get_engine_obj(obj_id);
if (!obj) {
SYS_LOG_ERR("unable to find obj: %u", obj_id);
LOG_ERR("unable to find obj: %u", obj_id);
return -ENOENT;
}
@ -2087,8 +2086,8 @@ static int lwm2m_read_handler(struct lwm2m_engine_obj_inst *obj_inst,
break;
default:
SYS_LOG_ERR("unknown obj data_type %d",
obj_field->data_type);
LOG_ERR("unknown obj data_type %d",
obj_field->data_type);
return -EINVAL;
}
@ -2215,11 +2214,11 @@ int lwm2m_write_handler(struct lwm2m_engine_obj_inst *obj_inst,
tkl = coap_header_get_token(in->in_cpkt, token);
if (tkl && !get_block_ctx(token, tkl, &block_ctx)) {
total_size = block_ctx->ctx.total_size;
SYS_LOG_DBG("BLOCK1: total:%zu current:%zu"
" last:%u",
block_ctx->ctx.total_size,
block_ctx->ctx.current,
last_block);
LOG_DBG("BLOCK1: total:%zu current:%zu"
" last:%u",
block_ctx->ctx.total_size,
block_ctx->ctx.current,
last_block);
}
}
}
@ -2308,8 +2307,8 @@ int lwm2m_write_handler(struct lwm2m_engine_obj_inst *obj_inst,
break;
default:
SYS_LOG_ERR("unknown obj data_type %d",
obj_field->data_type);
LOG_ERR("unknown obj data_type %d",
obj_field->data_type);
return -EINVAL;
}
@ -2363,7 +2362,7 @@ static int lwm2m_write_attr_handler(struct lwm2m_engine_obj *obj,
nr_opt = coap_find_options(in->in_cpkt, COAP_OPTION_URI_QUERY,
options, NR_LWM2M_ATTR);
if (nr_opt <= 0) {
SYS_LOG_ERR("No attribute found!");
LOG_ERR("No attribute found!");
/* translate as bad request */
return -EEXIST;
}
@ -2466,8 +2465,8 @@ static int lwm2m_write_attr_handler(struct lwm2m_engine_obj *obj,
}
if (ret < 0) {
SYS_LOG_ERR("invalid attr[%s] value",
LWM2M_ATTR_STR[type]);
LOG_ERR("invalid attr[%s] value",
LWM2M_ATTR_STR[type]);
/* bad request */
return -EEXIST;
}
@ -2483,14 +2482,14 @@ static int lwm2m_write_attr_handler(struct lwm2m_engine_obj *obj,
if ((nattrs.flags & (BIT(LWM2M_ATTR_PMIN) | BIT(LWM2M_ATTR_PMAX))) &&
nattrs.pmin > nattrs.pmax) {
SYS_LOG_DBG("pmin (%d) > pmax (%d)", nattrs.pmin, nattrs.pmax);
LOG_DBG("pmin (%d) > pmax (%d)", nattrs.pmin, nattrs.pmax);
return -EEXIST;
}
if (nattrs.flags & (BIT(LWM2M_ATTR_LT) | BIT(LWM2M_ATTR_GT))) {
if (!((nattrs.lt.val1 < nattrs.gt.val1) ||
(nattrs.lt.val2 < nattrs.gt.val2))) {
SYS_LOG_DBG("lt > gt");
LOG_DBG("lt > gt");
return -EEXIST;
}
@ -2500,7 +2499,7 @@ static int lwm2m_write_attr_handler(struct lwm2m_engine_obj *obj,
s32_t st2 = nattrs.st.val2 * 2 % 1000000;
if (!(((nattrs.lt.val1 + st1) < nattrs.gt.val1) ||
((nattrs.lt.val2 + st2) < nattrs.gt.val2))) {
SYS_LOG_DBG("lt + 2*st > gt");
LOG_DBG("lt + 2*st > gt");
return -EEXIST;
}
}
@ -2516,7 +2515,7 @@ static int lwm2m_write_attr_handler(struct lwm2m_engine_obj *obj,
type = attr->type;
if (!(BIT(type) & nattrs.flags)) {
SYS_LOG_DBG("Unset attr %s", LWM2M_ATTR_STR[type]);
LOG_DBG("Unset attr %s", LWM2M_ATTR_STR[type]);
(void)memset(attr, 0, sizeof(*attr));
if (type <= LWM2M_ATTR_PMAX) {
@ -2545,8 +2544,8 @@ static int lwm2m_write_attr_handler(struct lwm2m_engine_obj *obj,
sizeof(float32_value_t));
}
SYS_LOG_DBG("Update %s to %d.%06d", LWM2M_ATTR_STR[type],
attr->float_val.val1, attr->float_val.val2);
LOG_DBG("Update %s to %d.%06d", LWM2M_ATTR_STR[type],
attr->float_val.val1, attr->float_val.val2);
}
/* add attribute to obj/obj_inst/res */
@ -2579,8 +2578,8 @@ static int lwm2m_write_attr_handler(struct lwm2m_engine_obj *obj,
}
nattrs.flags &= ~BIT(type);
SYS_LOG_DBG("Add %s to %d.%06d", LWM2M_ATTR_STR[type],
attr->float_val.val1, attr->float_val.val2);
LOG_DBG("Add %s to %d.%06d", LWM2M_ATTR_STR[type],
attr->float_val.val1, attr->float_val.val2);
}
/* check only pmin/pmax */
@ -2652,11 +2651,11 @@ static int lwm2m_write_attr_handler(struct lwm2m_engine_obj *obj,
}
}
SYS_LOG_DBG("%d/%d/%d(%d) updated from %d/%d to %u/%u",
obs->path.obj_id, obs->path.obj_inst_id,
obs->path.res_id, obs->path.level,
obs->min_period_sec, obs->max_period_sec,
nattrs.pmin, max(nattrs.pmin, nattrs.pmax));
LOG_DBG("%d/%d/%d(%d) updated from %d/%d to %u/%u",
obs->path.obj_id, obs->path.obj_inst_id,
obs->path.res_id, obs->path.level,
obs->min_period_sec, obs->max_period_sec,
nattrs.pmin, max(nattrs.pmin, nattrs.pmax));
obs->min_period_sec = (u32_t)nattrs.pmin;
obs->max_period_sec = (u32_t)max(nattrs.pmin, nattrs.pmax);
(void)memset(&nattrs, 0, sizeof(nattrs));
@ -2725,7 +2724,7 @@ static int do_read_op(struct lwm2m_engine_obj *obj,
#endif
default:
SYS_LOG_ERR("Unsupported content-format: %u", content_format);
LOG_ERR("Unsupported content-format: %u", content_format);
return -ENOMSG;
}
@ -2759,13 +2758,13 @@ int lwm2m_perform_read_op(struct lwm2m_engine_obj *obj,
ret = coap_append_option_int(out->out_cpkt, COAP_OPTION_CONTENT_FORMAT,
content_format);
if (ret < 0) {
SYS_LOG_ERR("Error setting response content-format: %d", ret);
LOG_ERR("Error setting response content-format: %d", ret);
return ret;
}
ret = coap_packet_append_payload_marker(out->out_cpkt);
if (ret < 0) {
SYS_LOG_ERR("Error appending payload marker: %d", ret);
LOG_ERR("Error appending payload marker: %d", ret);
return ret;
}
@ -2821,7 +2820,7 @@ int lwm2m_perform_read_op(struct lwm2m_engine_obj *obj,
if (path->level > 2 &&
!LWM2M_HAS_PERM(obj_field,
BIT(LWM2M_FLAG_OPTIONAL))) {
SYS_LOG_ERR("READ OP: %d", ret);
LOG_ERR("READ OP: %d", ret);
}
} else {
num_read += 1;
@ -2935,7 +2934,7 @@ static int do_discover_op(struct lwm2m_engine_context *context, bool well_known)
COAP_OPTION_CONTENT_FORMAT,
LWM2M_FORMAT_APP_LINK_FORMAT);
if (ret < 0) {
SYS_LOG_ERR("Error setting response content-format: %d", ret);
LOG_ERR("Error setting response content-format: %d", ret);
return ret;
}
@ -3121,7 +3120,7 @@ static int do_write_op(struct lwm2m_engine_obj *obj,
#endif
default:
SYS_LOG_ERR("Unsupported format: %u", format);
LOG_ERR("Unsupported format: %u", format);
return -ENOMSG;
}
@ -3221,7 +3220,7 @@ static int handle_request(struct coap_packet *request,
if (r > 0) {
accept = coap_option_value_to_int(&options[0]);
} else {
SYS_LOG_DBG("No accept option given. Assume OMA TLV.");
LOG_DBG("No accept option given. Assume OMA TLV.");
accept = LWM2M_FORMAT_OMA_TLV;
}
@ -3309,7 +3308,7 @@ static int handle_request(struct coap_packet *request,
block_size = GET_BLOCK_SIZE(r);
if (!last_block &&
coap_block_size_to_bytes(block_size) > in.payload_len) {
SYS_LOG_DBG("Trailing payload is discarded!");
LOG_DBG("Trailing payload is discarded!");
r = -EFBIG;
goto error;
}
@ -3326,7 +3325,7 @@ static int handle_request(struct coap_packet *request,
r = coap_update_from_block(in.in_cpkt, &block_ctx->ctx);
if (r < 0) {
SYS_LOG_ERR("Error from block update: %d", r);
LOG_ERR("Error from block update: %d", r);
goto error;
}
@ -3352,19 +3351,18 @@ static int handle_request(struct coap_packet *request,
COAP_OPTION_OBSERVE,
1);
if (r < 0) {
SYS_LOG_ERR("OBSERVE option error: %d",
r);
LOG_ERR("OBSERVE option error: %d", r);
goto error;
}
r = engine_add_observer(msg, token, tkl, &path,
accept);
if (r < 0) {
SYS_LOG_ERR("add OBSERVE error: %d", r);
LOG_ERR("add OBSERVE error: %d", r);
goto error;
}
} else {
SYS_LOG_ERR("OBSERVE request missing token");
LOG_ERR("OBSERVE request missing token");
r = -EINVAL;
goto error;
}
@ -3372,7 +3370,7 @@ static int handle_request(struct coap_packet *request,
/* remove observer */
r = engine_remove_observer(token, tkl);
if (r < 0) {
SYS_LOG_ERR("remove observe error: %d", r);
LOG_ERR("remove observe error: %d", r);
}
}
@ -3401,7 +3399,7 @@ static int handle_request(struct coap_packet *request,
break;
default:
SYS_LOG_ERR("Unknown operation: %u", context.operation);
LOG_ERR("Unknown operation: %u", context.operation);
r = -EINVAL;
}
@ -3417,7 +3415,7 @@ static int handle_request(struct coap_packet *request,
&block_ctx->ctx);
if (r < 0) {
/* report as internal server error */
SYS_LOG_ERR("Fail adding block1 option: %d", r);
LOG_ERR("Fail adding block1 option: %d", r);
r = -EINVAL;
goto error;
}
@ -3452,7 +3450,7 @@ error:
r = lwm2m_init_message(msg);
if (r < 0) {
SYS_LOG_ERR("Error recreating message: %d", r);
LOG_ERR("Error recreating message: %d", r);
}
/* Free block context when error happened */
@ -3477,7 +3475,7 @@ void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, struct net_pkt *pkt,
udp_hdr = net_udp_get_hdr(pkt, &hdr);
if (!udp_hdr) {
SYS_LOG_ERR("Invalid UDP data");
LOG_ERR("Invalid UDP data");
return;
}
@ -3502,7 +3500,7 @@ void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, struct net_pkt *pkt,
r = coap_packet_parse(&response, pkt, NULL, 0);
if (r < 0) {
SYS_LOG_ERR("Invalid data received (err:%d)", r);
LOG_ERR("Invalid data received (err:%d)", r);
goto cleanup;
}
@ -3522,8 +3520,8 @@ void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, struct net_pkt *pkt,
}
}
SYS_LOG_DBG("checking for reply from [%s]",
lwm2m_sprint_ip_addr(&from_addr));
LOG_DBG("checking for reply from [%s]",
lwm2m_sprint_ip_addr(&from_addr));
reply = coap_response_received(&response, &from_addr,
client_ctx->replies,
CONFIG_LWM2M_ENGINE_MAX_REPLIES);
@ -3540,7 +3538,7 @@ void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, struct net_pkt *pkt,
*/
if (handle_separate_response && !tkl &&
coap_header_get_type(&response) == COAP_TYPE_ACK) {
SYS_LOG_DBG("separated response, not removing reply");
LOG_DBG("separated response, not removing reply");
goto cleanup;
}
@ -3554,7 +3552,7 @@ void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, struct net_pkt *pkt,
if (reply && reply->user_data != COAP_REPLY_STATUS_NONE) {
/* reset reply->user_data for next time */
reply->user_data = (void *)COAP_REPLY_STATUS_NONE;
SYS_LOG_DBG("reply %p NOT removed", reply);
LOG_DBG("reply %p NOT removed", reply);
goto cleanup;
}
@ -3563,7 +3561,7 @@ void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, struct net_pkt *pkt,
lwm2m_reset_message(msg, true);
}
SYS_LOG_DBG("reply %p handled and removed", reply);
LOG_DBG("reply %p handled and removed", reply);
goto cleanup;
}
@ -3576,7 +3574,7 @@ void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, struct net_pkt *pkt,
coap_header_get_type(&response) == COAP_TYPE_CON) {
msg = lwm2m_get_message(client_ctx);
if (!msg) {
SYS_LOG_ERR("Unable to get a lwm2m message!");
LOG_ERR("Unable to get a lwm2m message!");
goto cleanup;
}
@ -3595,12 +3593,11 @@ void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, struct net_pkt *pkt,
r = lwm2m_send_message(msg);
if (r < 0) {
SYS_LOG_ERR("Err sending response: %d",
r);
LOG_ERR("Err sending response: %d", r);
lwm2m_reset_message(msg, true);
}
} else {
SYS_LOG_ERR("No handler for response");
LOG_ERR("No handler for response");
}
cleanup:
@ -3635,14 +3632,14 @@ static void retransmit_request(struct k_work *work)
msg = find_msg(pending, NULL);
if (!msg) {
SYS_LOG_ERR("pending has no valid LwM2M message!");
LOG_ERR("pending has no valid LwM2M message!");
return;
}
/* ref pkt to avoid being freed after net_app_send_pkt() */
net_pkt_ref(pending->pkt);
SYS_LOG_DBG("Resending message: %p", msg);
LOG_DBG("Resending message: %p", msg);
msg->send_attempts++;
/*
* Don't use lwm2m_send_message() because it calls
@ -3655,7 +3652,7 @@ static void retransmit_request(struct k_work *work)
&msg->ctx->net_app_ctx.default_ctx->remote,
NET_SOCKADDR_MAX_SIZE, K_NO_WAIT, NULL);
if (r < 0) {
SYS_LOG_ERR("Error sending lwm2m message: %d", r);
LOG_ERR("Error sending lwm2m message: %d", r);
/* don't error here, retry until timeout */
net_pkt_unref(pending->pkt);
}
@ -3689,7 +3686,7 @@ static int notify_message_reply_cb(const struct coap_packet *response,
type = coap_header_get_type(response);
code = coap_header_get_code(response);
SYS_LOG_DBG("NOTIFY ACK type:%u code:%d.%d reply_token:'%s'",
LOG_DBG("NOTIFY ACK type:%u code:%d.%d reply_token:'%s'",
type,
COAP_RESPONSE_CODE_CLASS(code),
COAP_RESPONSE_CODE_DETAIL(code),
@ -3700,10 +3697,10 @@ static int notify_message_reply_cb(const struct coap_packet *response,
if (reply->tkl > 0) {
ret = engine_remove_observer(reply->token, reply->tkl);
if (ret) {
SYS_LOG_ERR("remove observe error: %d", ret);
LOG_ERR("remove observe error: %d", ret);
}
} else {
SYS_LOG_ERR("notify reply missing token -- ignored.");
LOG_ERR("notify reply missing token -- ignored.");
}
}
@ -3721,7 +3718,7 @@ static int generate_notify_message(struct observe_node *obs,
int ret = 0;
if (!obs->ctx) {
SYS_LOG_ERR("observer has no valid LwM2M ctx!");
LOG_ERR("observer has no valid LwM2M ctx!");
return -EINVAL;
}
@ -3734,29 +3731,29 @@ static int generate_notify_message(struct observe_node *obs,
context.path = &path;
context.operation = LWM2M_OP_READ;
SYS_LOG_DBG("[%s] NOTIFY MSG START: %u/%u/%u(%u) token:'%s' [%s] %lld",
manual_trigger ? "MANUAL" : "AUTO",
obs->path.obj_id,
obs->path.obj_inst_id,
obs->path.res_id,
obs->path.level,
sprint_token(obs->token, obs->tkl),
lwm2m_sprint_ip_addr(
&obs->ctx->net_app_ctx.default_ctx->remote),
k_uptime_get());
LOG_DBG("[%s] NOTIFY MSG START: %u/%u/%u(%u) token:'%s' [%s] %lld",
manual_trigger ? "MANUAL" : "AUTO",
obs->path.obj_id,
obs->path.obj_inst_id,
obs->path.res_id,
obs->path.level,
sprint_token(obs->token, obs->tkl),
lwm2m_sprint_ip_addr(
&obs->ctx->net_app_ctx.default_ctx->remote),
k_uptime_get());
obj_inst = get_engine_obj_inst(obs->path.obj_id,
obs->path.obj_inst_id);
if (!obj_inst) {
SYS_LOG_ERR("unable to get engine obj for %u/%u",
obs->path.obj_id,
obs->path.obj_inst_id);
LOG_ERR("unable to get engine obj for %u/%u",
obs->path.obj_id,
obs->path.obj_inst_id);
return -EINVAL;
}
msg = lwm2m_get_message(obs->ctx);
if (!msg) {
SYS_LOG_ERR("Unable to get a lwm2m message!");
LOG_ERR("Unable to get a lwm2m message!");
return -ENOMEM;
}
@ -3770,7 +3767,7 @@ static int generate_notify_message(struct observe_node *obs,
ret = lwm2m_init_message(msg);
if (ret < 0) {
SYS_LOG_ERR("Unable to init lwm2m message! (err: %d)", ret);
LOG_ERR("Unable to init lwm2m message! (err: %d)", ret);
goto cleanup;
}
@ -3779,7 +3776,7 @@ static int generate_notify_message(struct observe_node *obs,
ret = coap_append_option_int(&msg->cpkt, COAP_OPTION_OBSERVE,
obs->counter);
if (ret < 0) {
SYS_LOG_ERR("OBSERVE option error: %d", ret);
LOG_ERR("OBSERVE option error: %d", ret);
goto cleanup;
}
@ -3788,17 +3785,17 @@ static int generate_notify_message(struct observe_node *obs,
ret = do_read_op(obj_inst->obj, &context, obs->format);
if (ret < 0) {
SYS_LOG_ERR("error in multi-format read (err:%d)", ret);
LOG_ERR("error in multi-format read (err:%d)", ret);
goto cleanup;
}
ret = lwm2m_send_message(msg);
if (ret < 0) {
SYS_LOG_ERR("Error sending LWM2M packet (err:%d).", ret);
LOG_ERR("Error sending LWM2M packet (err:%d).", ret);
goto cleanup;
}
SYS_LOG_DBG("NOTIFY MSG: SENT");
LOG_DBG("NOTIFY MSG: SENT");
return 0;
cleanup:
@ -3985,7 +3982,7 @@ int lwm2m_engine_start(struct lwm2m_ctx *client_ctx,
client_ctx->net_init_timeout,
client_ctx);
if (ret) {
SYS_LOG_ERR("net_app_init_udp_client err:%d", ret);
LOG_ERR("net_app_init_udp_client err:%d", ret);
goto error_start;
}
@ -3995,7 +3992,7 @@ int lwm2m_engine_start(struct lwm2m_ctx *client_ctx,
ret = net_app_set_cb(&client_ctx->net_app_ctx,
NULL, udp_receive, NULL, NULL);
if (ret) {
SYS_LOG_ERR("Could not set receive callback (err:%d)", ret);
LOG_ERR("Could not set receive callback (err:%d)", ret);
goto error_start;
}
@ -4012,7 +4009,7 @@ int lwm2m_engine_start(struct lwm2m_ctx *client_ctx,
client_ctx->dtls_stack,
client_ctx->dtls_stack_len);
if (ret < 0) {
SYS_LOG_ERR("Cannot init DTLS (%d)", ret);
LOG_ERR("Cannot init DTLS (%d)", ret);
goto error_start;
}
#endif
@ -4020,7 +4017,7 @@ int lwm2m_engine_start(struct lwm2m_ctx *client_ctx,
ret = net_app_connect(&client_ctx->net_app_ctx,
client_ctx->net_timeout);
if (ret < 0) {
SYS_LOG_ERR("Cannot connect UDP (%d)", ret);
LOG_ERR("Cannot connect UDP (%d)", ret);
goto error_start;
}
@ -4046,7 +4043,7 @@ static int lwm2m_engine_init(struct device *dev)
/* Lowest priority cooperative thread */
K_PRIO_COOP(CONFIG_NUM_COOP_PRIORITIES - 1),
0, K_NO_WAIT);
SYS_LOG_DBG("LWM2M engine thread started");
LOG_DBG("LWM2M engine thread started");
return 0;
}