Contiki-NG
Loading...
Searching...
No Matches
edhoc-client.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024, RISE Research Institutes of Sweden AB
3 * Copyright (c) 2020, Industrial Systems Institute (ISI), Patras, Greece
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the copyright holder nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 */
31
32/**
33 * \file
34 * EDHOC client functionality [RFC9528].
35 * \author
36 * Lidia Pocero <pocero@isi.gr>, Peter A Jonsson, Rikard Höglund, Marco Tiloca
37 * Christos Koulamas <cklm@isi.gr>
38 */
39
40/**
41 * \addtogroup edhoc
42 * @{
43 */
44
45#ifndef EDHOC_CLIENT_H_
46#define EDHOC_CLIENT_H_
47
48#include "coap-engine.h"
49#include "edhoc.h"
50
51/**
52 * \brief The CoAP Server IP where run the EDHOC Responder
53 */
54#ifdef EDHOC_CONF_SERVER_EP
55#define SERVER_EP EDHOC_CONF_SERVER_EP
56#else
57#define SERVER_EP "coap://[fd00::1]"
58#endif
59
60/**
61 * \brief Time limit value to EDHOC protocol finished
62 */
63#ifdef EDHOC_CONF_TIMEOUT
64#define CL_TIMEOUT_VAL EDHOC_CONF_TIMEOUT
65#else
66#define CL_TIMEOUT_VAL 10000
67#endif
68
69/**
70 * \brief EDHOC client struct
71 */
72typedef struct edhoc_client {
73 uint8_t state;
74 coap_endpoint_t server_ep;
75 coap_message_t request[1];
76 coap_message_t response[1];
77 uint16_t con_num;
78 bool tx_msg1;
79 bool rx_msg2;
80 bool tx_msg3;
81 bool rx_msg3_response;
83
84/**
85 * \brief EDHOC client Application data struct
86 */
87typedef struct edhoc_client_ad {
88 char ad_1[EDHOC_MAX_AD_SZ];
89 uint16_t ad_1_sz;
90 char ad_2[EDHOC_MAX_AD_SZ];
91 uint16_t ad_2_sz;
92 char ad_3[EDHOC_MAX_AD_SZ];
93 uint16_t ad_3_sz;
95
96/**
97 * \brief EDHOC data event struct
98 */
99typedef struct edhoc_data_event {
100 uint8_t val;
103
104/**
105 * \brief Run the EDHOC Initiator role
106 *
107 * This function must be called from the EDHOC Initiator program to start the EDHOC protocol
108 * as Initiator. Runs a new process that implements all the EDHOC protocol and exits
109 * when the EDHOC protocol finishes successfully or expire the EDHOC_CONF_ATTEMPTS.
110 * - When the EDHOC protocol finishes successfully a EVT_FINISHED event is triggered.
111 * - When the EDHOC protocol expires the EDHOC_CONF_ATTEMPTS attempts a EVT_TRIES_EXPIRE event is triggered
112 */
113void edhoc_client_run(void);
114
115/**
116 * \brief Check if the EDHOC client have finished
117 * \param ev process event
118 * \param data process data
119 * \retval 1 if EDHOC Client process finished success
120 * \retval -1 if EDHOC Client process expire attempts
121 * \retval 0 if the event is not from EDHOC Client process or the EDHOC client process has not finished yet
122 *
123 * This function checks the events trigger from the EDHOC client process looking for the
124 * EVT_FINISHED or EVT_TRIES_EXPIRE events.
125 */
126int8_t edhoc_client_callback(process_event_t ev, void *data);
127
128/**
129 * \brief Close the EDHOC context
130 *
131 * This function must be called after the Security Context is exported to free the
132 * allocated memory.
133 */
134void edhoc_client_close(void);
135
136/**
137 * \brief Get the Application Data received in EDHOC message 2
138 * \param buf A pointer to a buffer to copy the Application data
139 * \param buf_sz The size of the destination buffer
140 * \return ad_sz The Application data length, or 0 if error
141 *
142 * This function copies to the buff the Application data from the EDHOC message 2 received.
143 * Returns 0 if the destination buffer is too small or invalid.
144 */
145uint8_t edhoc_client_get_ad_2(char *buf, size_t buf_sz);
146
147/**
148 * \brief Set the Application Data to be carried in EDHOC message 1
149 * \param data_buffer A pointer to a buffer that contains the Application data to be copied
150 * \param buffer_size The Application data length
151 *
152 * This function sets the Application data to be carried in EDHOC message 1.
153 */
154void edhoc_client_set_ad_1(const void *data_buffer, uint8_t buffer_size);
155
156/**
157 * \brief Set the Application Data to be carried in EDHOC message 3
158 * \param data_buffer A pointer to a buffer that contains the Application data to be copied
159 * \param buffer_size The Application data length
160 *
161 * This function sets the Application data to be carried in EDHOC message 3.
162 */
163void edhoc_client_set_ad_3(const void *data_buffer, uint8_t buffer_size);
164
165#endif /* EDHOC_CLIENT_H_ */
166/** @} */
CoAP engine implementation.
An implementation of Ephemeral Diffie-Hellman Over COSE (EDHOC) (RFC9528).
void edhoc_client_run(void)
Run the EDHOC Initiator role.
#define EDHOC_MAX_AD_SZ
The max length of the Application Data.
struct edhoc_data_event edhoc_data_event_t
EDHOC data event struct.
void edhoc_client_set_ad_1(const void *data_buffer, uint8_t buffer_size)
Set the Application Data to be carried in EDHOC message 1.
void edhoc_client_set_ad_3(const void *data_buffer, uint8_t buffer_size)
Set the Application Data to be carried in EDHOC message 3.
struct edhoc_client_ad edhoc_client_ad_t
EDHOC client Application data struct.
int8_t edhoc_client_callback(process_event_t ev, void *data)
Check if the EDHOC client have finished.
uint8_t edhoc_client_get_ad_2(char *buf, size_t buf_sz)
Get the Application Data received in EDHOC message 2.
void edhoc_client_close(void)
Close the EDHOC context.
struct edhoc_client edhoc_client_t
EDHOC client struct.
EDHOC client Application data struct.
EDHOC client struct.
EDHOC data event struct.