@@ -1292,11 +1292,23 @@ static struct lwm2m_message *find_msg(struct coap_pending *pending,
12921292 struct coap_reply * reply )
12931293{
12941294 size_t i ;
1295+ struct lwm2m_message * msg ;
12951296
12961297 if (!pending && !reply ) {
12971298 return NULL ;
12981299 }
12991300
1301+ msg = lwm2m_get_ongoing_rd_msg ();
1302+ if (msg ) {
1303+ if (pending != NULL && msg -> pending == pending ) {
1304+ return msg ;
1305+ }
1306+
1307+ if (reply != NULL && msg -> reply == reply ) {
1308+ return msg ;
1309+ }
1310+ }
1311+
13001312 for (i = 0 ; i < CONFIG_LWM2M_ENGINE_MAX_MESSAGES ; i ++ ) {
13011313 if (pending != NULL && messages [i ].ctx &&
13021314 messages [i ].pending == pending ) {
@@ -1326,7 +1338,7 @@ struct lwm2m_message *lwm2m_get_message(struct lwm2m_ctx *client_ctx)
13261338 return NULL ;
13271339}
13281340
1329- static void lm2m_message_clear_allocations (struct lwm2m_message * msg )
1341+ void lm2m_message_clear_allocations (struct lwm2m_message * msg )
13301342{
13311343 if (msg -> pending ) {
13321344 coap_pending_clear (msg -> pending );
@@ -1399,7 +1411,7 @@ int lwm2m_init_message(struct lwm2m_message *msg)
13991411
14001412 msg -> pending = coap_pending_next_unused (
14011413 msg -> ctx -> pendings ,
1402- CONFIG_LWM2M_ENGINE_MAX_PENDING );
1414+ ARRAY_SIZE ( msg -> ctx -> pendings ) );
14031415 if (!msg -> pending ) {
14041416 LOG_ERR ("Unable to find a free pending to track "
14051417 "retransmissions." );
@@ -1418,7 +1430,7 @@ int lwm2m_init_message(struct lwm2m_message *msg)
14181430 if (msg -> reply_cb ) {
14191431 msg -> reply = coap_reply_next_unused (
14201432 msg -> ctx -> replies ,
1421- CONFIG_LWM2M_ENGINE_MAX_REPLIES );
1433+ ARRAY_SIZE ( msg -> ctx -> replies ) );
14221434 if (!msg -> reply ) {
14231435 LOG_ERR ("No resources for waiting for replies." );
14241436 r = - ENOMEM ;
@@ -5094,7 +5106,7 @@ static int lwm2m_response_promote_to_con(struct lwm2m_message *msg)
50945106 /* Add the packet to the pending list. */
50955107 msg -> pending = coap_pending_next_unused (
50965108 msg -> ctx -> pendings ,
5097- CONFIG_LWM2M_ENGINE_MAX_PENDING );
5109+ ARRAY_SIZE ( msg -> ctx -> pendings ) );
50985110 if (!msg -> pending ) {
50995111 LOG_ERR ("Unable to find a free pending to track "
51005112 "retransmissions." );
@@ -5133,7 +5145,7 @@ static void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx,
51335145
51345146 tkl = coap_header_get_token (& response , token );
51355147 pending = coap_pending_received (& response , client_ctx -> pendings ,
5136- CONFIG_LWM2M_ENGINE_MAX_PENDING );
5148+ ARRAY_SIZE ( client_ctx -> pendings ) );
51375149 if (pending && coap_header_get_type (& response ) == COAP_TYPE_ACK ) {
51385150 msg = find_msg (pending , NULL );
51395151 if (msg == NULL ) {
@@ -5165,7 +5177,7 @@ static void lwm2m_udp_receive(struct lwm2m_ctx *client_ctx,
51655177 log_strdup (lwm2m_sprint_ip_addr (from_addr )));
51665178 reply = coap_response_received (& response , from_addr ,
51675179 client_ctx -> replies ,
5168- CONFIG_LWM2M_ENGINE_MAX_REPLIES );
5180+ ARRAY_SIZE ( client_ctx -> replies ) );
51695181 if (reply ) {
51705182 msg = find_msg (NULL , reply );
51715183
@@ -5251,7 +5263,7 @@ static int32_t retransmit_request(struct lwm2m_ctx *client_ctx,
52515263 int i ;
52525264
52535265 for (i = 0 , p = client_ctx -> pendings ;
5254- i < CONFIG_LWM2M_ENGINE_MAX_PENDING ; i ++ , p ++ ) {
5266+ i < ARRAY_SIZE ( client_ctx -> pendings ) ; i ++ , p ++ ) {
52555267 if (!p -> timeout ) {
52565268 continue ;
52575269 }
@@ -5607,9 +5619,10 @@ int lwm2m_engine_context_close(struct lwm2m_ctx *client_ctx)
56075619 }
56085620
56095621 coap_pendings_clear (client_ctx -> pendings ,
5610- CONFIG_LWM2M_ENGINE_MAX_PENDING );
5622+ ARRAY_SIZE ( client_ctx -> pendings ) );
56115623 coap_replies_clear (client_ctx -> replies ,
5612- CONFIG_LWM2M_ENGINE_MAX_REPLIES );
5624+ ARRAY_SIZE (client_ctx -> replies ));
5625+
56135626#if defined(CONFIG_LWM2M_QUEUE_MODE_ENABLED )
56145627 client_ctx -> connection_suspended = false;
56155628 client_ctx -> buffer_client_messages = true;
0 commit comments