Skip to content

Commit b918e92

Browse files
committed
[nrf fromtree] net: lib: coap_client: Parse incoming MID only once
Incomming Message-ID is already parsed, use it as a parameter to get_request_with_mid(). Signed-off-by: Seppo Takalo <[email protected]> (cherry picked from commit 7b0cce4)
1 parent 1d3e727 commit b918e92

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

subsys/net/lib/coap/coap_client.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ static void cancel_requests_with(struct coap_client *client, int error);
3030
static int recv_response(struct coap_client *client, struct coap_packet *response, bool *truncated);
3131
static int handle_response(struct coap_client *client, const struct coap_packet *response,
3232
bool response_truncated);
33-
static struct coap_client_internal_request *get_request_with_mid(
34-
struct coap_client *client, const struct coap_packet *resp);
35-
33+
static struct coap_client_internal_request *get_request_with_mid(struct coap_client *client,
34+
uint16_t mid);
3635

3736
static int send_request(int sock, const void *buf, size_t len, int flags,
3837
const struct sockaddr *dest_addr, socklen_t addrlen)
@@ -701,14 +700,12 @@ static struct coap_client_internal_request *get_request_with_token(
701700
return NULL;
702701
}
703702

704-
static struct coap_client_internal_request *get_request_with_mid(
705-
struct coap_client *client, const struct coap_packet *resp)
703+
static struct coap_client_internal_request *get_request_with_mid(struct coap_client *client,
704+
uint16_t mid)
706705
{
707-
uint16_t mid = coap_header_get_id(resp);
708-
709706
for (int i = 0; i < CONFIG_COAP_CLIENT_MAX_REQUESTS; i++) {
710707
if (client->requests[i].request_ongoing) {
711-
if (client->requests[i].last_id == mid) {
708+
if (client->requests[i].last_id == (int)mid) {
712709
return &client->requests[i];
713710
}
714711
}
@@ -717,7 +714,6 @@ static struct coap_client_internal_request *get_request_with_mid(
717714
return NULL;
718715
}
719716

720-
721717
static bool find_echo_option(const struct coap_packet *response, struct coap_option *option)
722718
{
723719
return coap_find_options(response, COAP_OPTION_ECHO, option, 1);
@@ -748,7 +744,7 @@ static int handle_response(struct coap_client *client, const struct coap_packet
748744
const uint8_t *payload = coap_packet_get_payload(response, &payload_len);
749745

750746
if (response_type == COAP_TYPE_RESET) {
751-
internal_req = get_request_with_mid(client, response);
747+
internal_req = get_request_with_mid(client, response_id);
752748
if (!internal_req) {
753749
LOG_WRN("No matching request for RESET");
754750
return 0;
@@ -761,7 +757,7 @@ static int handle_response(struct coap_client *client, const struct coap_packet
761757
/* Separate response coming */
762758
if (payload_len == 0 && response_type == COAP_TYPE_ACK &&
763759
response_code == COAP_CODE_EMPTY) {
764-
internal_req = get_request_with_mid(client, response);
760+
internal_req = get_request_with_mid(client, response_id);
765761
if (!internal_req) {
766762
LOG_WRN("No matching request for ACK");
767763
return 0;

0 commit comments

Comments
 (0)