From b9028bb7222bd15ba31b3e7d310fc60537a60422 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Fri, 11 Aug 2023 15:39:58 +0300 Subject: [PATCH] net: lwm2m: Remove unneeded function pointer parameter lwm2m_udp_receive() is only called with same function pointer, so there no need to carry that in the parameter. Signed-off-by: Seppo Takalo --- subsys/net/lib/lwm2m/lwm2m_engine.c | 2 +- subsys/net/lib/lwm2m/lwm2m_message_handling.c | 14 +++++--------- subsys/net/lib/lwm2m/lwm2m_message_handling.h | 6 +----- tests/net/lib/lwm2m/lwm2m_engine/src/stubs.c | 4 ++-- tests/net/lib/lwm2m/lwm2m_engine/src/stubs.h | 2 +- 5 files changed, 10 insertions(+), 18 deletions(-) diff --git a/subsys/net/lib/lwm2m/lwm2m_engine.c b/subsys/net/lib/lwm2m/lwm2m_engine.c index 91d8c3bd605..d38c081ed34 100644 --- a/subsys/net/lib/lwm2m/lwm2m_engine.c +++ b/subsys/net/lib/lwm2m/lwm2m_engine.c @@ -642,7 +642,7 @@ static int socket_recv_message(struct lwm2m_ctx *client_ctx) } in_buf[len] = 0U; - lwm2m_udp_receive(client_ctx, in_buf, len, &from_addr, handle_request); + lwm2m_udp_receive(client_ctx, in_buf, len, &from_addr); return 0; } diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.c b/subsys/net/lib/lwm2m/lwm2m_message_handling.c index 299b0330c0b..4eea849750b 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.c +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.c @@ -97,6 +97,7 @@ sys_slist_t *lwm2m_engine_obj_list(void); sys_slist_t *lwm2m_engine_obj_inst_list(void); +static int handle_request(struct coap_packet *request, struct lwm2m_message *msg); #if defined(CONFIG_LWM2M_COAP_BLOCK_TRANSFER) struct coap_block_context *lwm2m_output_block_context(void); #endif @@ -2193,7 +2194,7 @@ static int lwm2m_exec_handler(struct lwm2m_message *msg) return -ENOENT; } -int handle_request(struct coap_packet *request, struct lwm2m_message *msg) +static int handle_request(struct coap_packet *request, struct lwm2m_message *msg) { int r; uint8_t code; @@ -2557,7 +2558,7 @@ static int lwm2m_response_promote_to_con(struct lwm2m_message *msg) } void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, uint8_t *buf, uint16_t buf_len, - struct sockaddr *from_addr, udp_request_handler_cb_t udp_request_handler) + struct sockaddr *from_addr) { struct lwm2m_message *msg = NULL; struct coap_pending *pending; @@ -2684,12 +2685,7 @@ void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, uint8_t *buf, uint16_t buf_ return; } - /* - * If no normal response handler is found, then this is - * a new request coming from the server. Let's look - * at registered objects to find a handler. - */ - if (udp_request_handler && coap_header_get_type(&response) == COAP_TYPE_CON) { + if (coap_header_get_type(&response) == COAP_TYPE_CON) { msg = lwm2m_get_message(client_ctx); if (!msg) { LOG_ERR("Unable to get a lwm2m message!"); @@ -2707,7 +2703,7 @@ void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, uint8_t *buf, uint16_t buf_ lwm2m_registry_lock(); /* process the response to this request */ - r = udp_request_handler(&response, msg); + r = handle_request(&response, msg); lwm2m_registry_unlock(); if (r < 0) { return; diff --git a/subsys/net/lib/lwm2m/lwm2m_message_handling.h b/subsys/net/lib/lwm2m/lwm2m_message_handling.h index 12ba9e762fd..a98be3f8dc2 100644 --- a/subsys/net/lib/lwm2m/lwm2m_message_handling.h +++ b/subsys/net/lib/lwm2m/lwm2m_message_handling.h @@ -39,8 +39,6 @@ #define NUM_OUTPUT_BLOCK_CONTEXT CONFIG_LWM2M_NUM_OUTPUT_BLOCK_CONTEXT #endif -/* Establish a request handler callback type */ -typedef int (*udp_request_handler_cb_t)(struct coap_packet *request, struct lwm2m_message *msg); /* LwM2M message functions */ struct lwm2m_message *lwm2m_get_message(struct lwm2m_ctx *client_ctx); struct lwm2m_message *find_msg(struct coap_pending *pending, struct coap_reply *reply); @@ -49,10 +47,8 @@ void lm2m_message_clear_allocations(struct lwm2m_message *msg); int lwm2m_init_message(struct lwm2m_message *msg); int lwm2m_send_message_async(struct lwm2m_message *msg); -int handle_request(struct coap_packet *request, struct lwm2m_message *msg); - void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx, uint8_t *buf, uint16_t buf_len, - struct sockaddr *from_addr, udp_request_handler_cb_t udp_request_handler); + struct sockaddr *from_addr); int generate_notify_message(struct lwm2m_ctx *ctx, struct observe_node *obs, void *user_data); /* Notification and Send operation */ diff --git a/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.c b/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.c index 93f5cce1012..5db155f1e29 100644 --- a/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.c +++ b/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.c @@ -24,8 +24,8 @@ DEFINE_FAKE_VALUE_FUNC(int, generate_notify_message, struct lwm2m_ctx *, struct DEFINE_FAKE_VALUE_FUNC(int64_t, engine_observe_shedule_next_event, struct observe_node *, uint16_t, const int64_t); DEFINE_FAKE_VALUE_FUNC(int, handle_request, struct coap_packet *, struct lwm2m_message *); -DEFINE_FAKE_VOID_FUNC(lwm2m_udp_receive, struct lwm2m_ctx *, uint8_t *, uint16_t, struct sockaddr *, - udp_request_handler_cb_t); +DEFINE_FAKE_VOID_FUNC(lwm2m_udp_receive, struct lwm2m_ctx *, uint8_t *, uint16_t, + struct sockaddr *); DEFINE_FAKE_VALUE_FUNC(bool, lwm2m_rd_client_is_registred, struct lwm2m_ctx *); DEFINE_FAKE_VOID_FUNC(lwm2m_engine_context_close, struct lwm2m_ctx *); DEFINE_FAKE_VALUE_FUNC(int, lwm2m_get_res_buf, const struct lwm2m_obj_path *, void **, uint16_t *, diff --git a/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.h b/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.h index 088d72d4623..7b8ca481f85 100644 --- a/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.h +++ b/tests/net/lib/lwm2m/lwm2m_engine/src/stubs.h @@ -39,7 +39,7 @@ DECLARE_FAKE_VALUE_FUNC(int64_t, engine_observe_shedule_next_event, struct obser const int64_t); DECLARE_FAKE_VALUE_FUNC(int, handle_request, struct coap_packet *, struct lwm2m_message *); DECLARE_FAKE_VOID_FUNC(lwm2m_udp_receive, struct lwm2m_ctx *, uint8_t *, uint16_t, - struct sockaddr *, udp_request_handler_cb_t); + struct sockaddr *); DECLARE_FAKE_VALUE_FUNC(bool, lwm2m_rd_client_is_registred, struct lwm2m_ctx *); DECLARE_FAKE_VOID_FUNC(lwm2m_engine_context_close, struct lwm2m_ctx *); DECLARE_FAKE_VALUE_FUNC(int, lwm2m_get_res_buf, const struct lwm2m_obj_path *, void **, uint16_t *,