Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcoap: move tl_type to coap_request_ctx_t #18313

Merged
merged 1 commit into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -684,13 +684,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 @@ -899,7 +898,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
}
benpicco marked this conversation as resolved.
Show resolved Hide resolved
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