Commit 89241536 authored by Gerson Fernando Budke's avatar Gerson Fernando Budke Committed by Anas Nashif
Browse files

net: lwm2m: Refactor to use coap_get_option_int

Small clean-up to use coap_get_option_int.

Signed-off-by: default avatarGerson Fernando Budke <nandojve@gmail.com>
parent a88ead52
Loading
Loading
Loading
Loading
+4 −21
Changes for subsys/net/lib/lwm2m/lwm2m_engine.c: 4 added lines, 21 removed lines.
Original line number Diff line number Diff line
@@ -142,10 +142,6 @@ static int sock_nfds;
/* TODO: figure out what's correct value */
#define TIMEOUT_BLOCKWISE_TRANSFER_MS (MSEC_PER_SEC * 30)

#define GET_BLOCK_NUM(v)	((v) >> 4)
#define GET_BLOCK_SIZE(v)	(((v) & 0x7))
#define GET_MORE(v)		(!!((v) & 0x08))

struct block_context {
	struct coap_block_context ctx;
	s64_t timestamp;
@@ -788,20 +784,6 @@ int lwm2m_delete_obj_inst(u16_t obj_id, u16_t obj_inst_id)

/* utility functions */

static int get_option_int(const struct coap_packet *cpkt, u8_t opt)
{
	struct coap_option option = {};
	u16_t count = 1U;
	int r;

	r = coap_find_options(cpkt, opt, &option, count);
	if (r <= 0) {
		return -ENOENT;
	}

	return coap_option_value_to_int(&option);
}

static u16_t atou16(u8_t *buf, u16_t buflen, u16_t *len)
{
	u16_t val = 0U;
@@ -2303,7 +2285,7 @@ int lwm2m_write_handler(struct lwm2m_engine_obj_inst *obj_inst,

	if (res->post_write_cb) {
		/* Get block1 option for checking MORE block flag */
		ret = get_option_int(msg->in.in_cpkt, COAP_OPTION_BLOCK1);
		ret = coap_get_option_int(msg->in.in_cpkt, COAP_OPTION_BLOCK1);
		if (ret >= 0) {
			last_block = !GET_MORE(ret);

@@ -3398,7 +3380,8 @@ static int handle_request(struct coap_packet *request,
		}

		/* check for observe */
		observe = get_option_int(msg->in.in_cpkt, COAP_OPTION_OBSERVE);
		observe = coap_get_option_int(msg->in.in_cpkt,
					      COAP_OPTION_OBSERVE);
		msg->code = COAP_RESPONSE_CODE_CONTENT;
		break;

@@ -3443,7 +3426,7 @@ static int handle_request(struct coap_packet *request,
	coap_packet_get_payload(msg->in.in_cpkt, &payload_len);

	/* Check for block transfer */
	r = get_option_int(msg->in.in_cpkt, COAP_OPTION_BLOCK1);
	r = coap_get_option_int(msg->in.in_cpkt, COAP_OPTION_BLOCK1);
	if (r > 0) {
		last_block = !GET_MORE(r);