Zephyr API Documentation  3.5.0
A Scalable Open Source RTOS
3.5.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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_internal_request {
81 uint8_t request_token[COAP_TOKEN_MAX_LEN];
82 uint32_t offset;
83 uint32_t last_id;
84 uint8_t request_tkl;
85 uint8_t retry_count;
86 bool request_ongoing;
87 struct coap_block_context recv_blk_ctx;
88 struct coap_block_context send_blk_ctx;
89 struct coap_pending pending;
90 struct coap_client_request coap_request;
91 struct coap_packet request;
92};
93
94struct coap_client {
95 int fd;
96 struct sockaddr address;
97 socklen_t socklen;
98 bool response_ready;
99 struct k_mutex send_mutex;
100 uint8_t send_buf[MAX_COAP_MSG_LEN];
101 uint8_t recv_buf[MAX_COAP_MSG_LEN];
102 struct coap_client_internal_request requests[CONFIG_COAP_CLIENT_MAX_REQUESTS];
103};
115int coap_client_init(struct coap_client *client, const char *info);
116
134int coap_client_req(struct coap_client *client, int sock, const struct sockaddr *addr,
135 struct coap_client_request *req, int retries);
136
141#endif /* ZEPHYR_INCLUDE_NET_COAP_CLIENT_H_ */
CoAP implementation for Zephyr.
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:192
coap_method
Available request methods.
Definition: coap.h:71
coap_content_format
Set of Content-Format option values for CoAP.
Definition: coap.h:199
size_t socklen_t
Length of a socket address.
Definition: net_ip.h:168
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__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:626
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
Number of extra options.
Definition: coap_client.h:61
size_t len
Length of the payload.
Definition: coap_client.h:58
enum coap_method method
Method of the request.
Definition: coap_client.h:53
bool confirmable
CoAP Confirmable/Non-confirmable message.
Definition: coap_client.h:54
const char * path
Path of the requested resource.
Definition: coap_client.h:55
struct coap_client_option * options
Extra options to be added to request.
Definition: coap_client.h:60
void * user_data
User provided context.
Definition: coap_client.h:62
enum coap_content_format fmt
Content format to be used.
Definition: coap_client.h:56
uint8_t * payload
User allocated buffer for send request.
Definition: coap_client.h:57
coap_client_response_cb_t cb
Callback when response received.
Definition: coap_client.h:59
Representation of a CoAP Packet.
Definition: coap.h:268
Represents a request awaiting for an acknowledgment (ACK).
Definition: coap.h:313
Mutex Structure.
Definition: kernel.h:2911
Generic sockaddr struct.
Definition: net_ip.h:347