Zephyr Project API  3.4.0
A Scalable Open Source RTOS
coap_client.h
Go to the documentation of this file.
1
7/*
8 * Copyright (c) 2023 Nordic Semiconductor ASA
9 *
10 * SPDX-License-Identifier: Apache-2.0
11 */
12#ifndef ZEPHYR_INCLUDE_NET_COAP_CLIENT_H_
13#define ZEPHYR_INCLUDE_NET_COAP_CLIENT_H_
14
22#include <zephyr/net/coap.h>
23
24
25#define MAX_COAP_MSG_LEN (CONFIG_COAP_CLIENT_MESSAGE_HEADER_SIZE + \
26 CONFIG_COAP_CLIENT_MESSAGE_SIZE)
27
45typedef void (*coap_client_response_cb_t)(int16_t result_code,
46 size_t offset, const uint8_t *payload, size_t len,
47 bool last_block, void *user_data);
48
55 const char *path;
58 size_t len;
62 void *user_data;
63};
64
70#if defined(CONFIG_COAP_EXTENDED_OPTIONS_LEN)
72 uint8_t value[CONFIG_COAP_EXTENDED_OPTIONS_LEN_VALUE];
73#else
76#endif
77};
78
80struct coap_client {
81 int fd;
82 struct sockaddr address;
83 socklen_t socklen;
85 uint8_t recv_buf[MAX_COAP_MSG_LEN];
86 uint8_t request_token[COAP_TOKEN_MAX_LEN];
87 int request_tkl;
88 int offset;
89 int retry_count;
90 struct coap_block_context recv_blk_ctx;
91 struct coap_block_context send_blk_ctx;
92 struct coap_pending pending;
93 struct coap_client_request *coap_request;
94 struct coap_packet request;
96 struct k_thread thread;
97 struct k_sem coap_client_recv_sem;
98 atomic_t coap_client_recv_active;
99
100 K_THREAD_STACK_MEMBER(coap_thread_stack, CONFIG_COAP_CLIENT_STACK_SIZE);
101};
113int coap_client_init(struct coap_client *client, const char *info);
114
132int coap_client_req(struct coap_client *client, int sock, const struct sockaddr *addr,
133 struct coap_client_request *req, int retries);
134
139#endif /* ZEPHYR_INCLUDE_NET_COAP_CLIENT_H_ */
static struct k_thread thread[2]
Definition: atomic.c:26
long atomic_t
Definition: atomic.h:22
CoAP implementation for Zephyr.
static k_tid_t tid[ARRAY_SIZE(timeout_order_data_mult_fifo)]
Definition: main.c:86
int coap_client_req(struct coap_client *client, int sock, const struct sockaddr *addr, struct coap_client_request *req, int retries)
Send CoAP request.
#define MAX_COAP_MSG_LEN
Definition: coap_client.h:25
int coap_client_init(struct coap_client *client, const char *info)
Initialize the CoAP client.
void(* coap_client_response_cb_t)(int16_t result_code, size_t offset, const uint8_t *payload, size_t len, bool last_block, void *user_data)
Callback for CoAP request.
Definition: coap_client.h:45
#define COAP_TOKEN_MAX_LEN
Definition: coap.h:159
coap_method
Available request methods.
Definition: coap.h:71
coap_content_format
Set of Content-Format option values for CoAP.
Definition: coap.h:166
size_t socklen_t
Definition: net_ip.h:168
#define K_THREAD_STACK_MEMBER(sym, size)
Define an embedded stack memory region.
Definition: thread_stack.h:710
struct k_thread client
Definition: main.c:31
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
__INT16_TYPE__ int16_t
Definition: stdint.h:73
Represents the current state of a block-wise transaction.
Definition: coap.h:563
Representation of extra options for the CoAP client request.
Definition: coap_client.h:68
uint16_t code
Definition: coap_client.h:69
uint8_t value[12]
Definition: coap_client.h:75
uint8_t len
Definition: coap_client.h:74
Representation of a CoAP client request.
Definition: coap_client.h:52
uint8_t num_options
Definition: coap_client.h:61
size_t len
Definition: coap_client.h:58
enum coap_method method
Definition: coap_client.h:53
bool confirmable
Definition: coap_client.h:54
const char * path
Definition: coap_client.h:55
struct coap_client_option * options
Definition: coap_client.h:60
void * user_data
Definition: coap_client.h:62
enum coap_content_format fmt
Definition: coap_client.h:56
uint8_t * payload
Definition: coap_client.h:57
coap_client_response_cb_t cb
Definition: coap_client.h:59
Representation of a CoAP Packet.
Definition: coap.h:235
Represents a request awaiting for an acknowledgment (ACK).
Definition: coap.h:270
Definition: thread.h:245
Definition: net_ip.h:347
static ZTEST_DMEM uint32_t send_buf[2]
Definition: test_msgq_attrs.c:10
static const intptr_t user_data[5]
Definition: main.c:588