Skip to content

Commit

Permalink
Merge pull request #18313 from benpicco/coap_request_ctx_get_tl_type
Browse files Browse the repository at this point in the history
gcoap: move tl_type to coap_request_ctx_t
  • Loading branch information
benpicco authored Aug 17, 2022
2 parents 2321841 + d7bb422 commit 0713e0d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
17 changes: 10 additions & 7 deletions sys/include/net/nanocoap.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,6 @@ typedef struct {
BITFIELD(opt_crit, CONFIG_NANOCOAP_NOPTS_MAX); /**< unhandled critical option */
#ifdef MODULE_GCOAP
uint32_t observe_value; /**< observe value */
/**
* @brief transport the packet was received over
* @see @ref gcoap_socket_type_t for values.
* @note @ref gcoap_socket_type_t can not be used, as this would
* cyclically include the @ref net_gcoap header.
*/
uint32_t tl_type;
#endif
} coap_pkt_t;

Expand Down Expand Up @@ -344,6 +337,16 @@ const char *coap_request_ctx_get_path(const coap_request_ctx_t *ctx);
*/
void *coap_request_ctx_get_context(const coap_request_ctx_t *ctx);

/**
* @brief Get transport the packet was received over
* @see @ref gcoap_socket_type_t for values.
*
* @param[in] ctx The request context
*
* @return Transport Layer type of the request
*/
uint32_t coap_request_ctx_get_tl_type(const coap_request_ctx_t *ctx);

/**
* @brief Block1 helper struct
*/
Expand Down
5 changes: 2 additions & 3 deletions sys/net/application_layer/gcoap/gcoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,13 +705,12 @@ static size_t _handle_req(gcoap_socket_t *sock, coap_pkt_t *pdu, uint8_t *buf,
return -1;
}

pdu->tl_type = (uint32_t)sock->type;

ssize_t pdu_len;
char *offset;

coap_request_ctx_t ctx = {
.resource = resource,
.tl_type = (uint32_t)sock->type,
};

if (coap_get_proxy_uri(pdu, &offset) > 0) {
Expand Down Expand Up @@ -929,7 +928,7 @@ static ssize_t _well_known_core_handler(coap_pkt_t* pdu, uint8_t *buf, size_t le

plen += gcoap_get_resource_list_tl(pdu->payload, (size_t)pdu->payload_len,
COAP_FORMAT_LINK,
(gcoap_socket_type_t)pdu->tl_type);
(gcoap_socket_type_t)coap_request_ctx_get_tl_type(ctx));
return plen;
}

Expand Down
10 changes: 10 additions & 0 deletions sys/net/application_layer/nanocoap/nanocoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1246,3 +1246,13 @@ void *coap_request_ctx_get_context(const coap_request_ctx_t *ctx)
{
return ctx->context;
}

uint32_t coap_request_ctx_get_tl_type(const coap_request_ctx_t *ctx)
{
#ifdef MODULE_GCOAP
return ctx->tl_type;
#else
(void)ctx;
return 0;
#endif
}
9 changes: 9 additions & 0 deletions sys/net/application_layer/nanocoap/nanocoap_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ struct _coap_request_ctx {
const coap_resource_t *resource; /**< resource of the request */
void *context; /**< request context, needed to supply
the remote for the forward proxy */
#if defined(MODULE_GCOAP) || DOXYGEN
/**
* @brief transport the packet was received over
* @see @ref gcoap_socket_type_t for values.
* @note @ref gcoap_socket_type_t can not be used, as this would
* cyclically include the @ref net_gcoap header.
*/
uint32_t tl_type;
#endif
};

#ifdef __cplusplus
Expand Down

0 comments on commit 0713e0d

Please sign in to comment.