1c87c5fbaSopenharmony_ci= Upgrade from 4.2.1 to 4.3.0
2c87c5fbaSopenharmony_ci
3c87c5fbaSopenharmony_ci== Summary
4c87c5fbaSopenharmony_ci
5c87c5fbaSopenharmony_ciWhen compiling 4.2.1 based code with a 4.3.0 environment, this will initially
6c87c5fbaSopenharmony_cithrow up many errors as the API has been updated to make future coding simpler,
7c87c5fbaSopenharmony_ciadds more functionality and adds more rigorous coding checks.  Updating your
8c87c5fbaSopenharmony_cicode with the following steps will significantly reduce the reported issues.
9c87c5fbaSopenharmony_ci
10c87c5fbaSopenharmony_ciThe examples are now also named with the (D)TLS library type as a suffix.
11c87c5fbaSopenharmony_ciE.g. coap-client is now coap-client-openssl.
12c87c5fbaSopenharmony_ci
13c87c5fbaSopenharmony_ci== Include directory changes
14c87c5fbaSopenharmony_ci
15c87c5fbaSopenharmony_ciBecause of the API changes, the libcoap's include file directory has changed from `coap2/` to `coap3/`. Also, there is now no need to define additional include paths to the compiler options such as `-I include/coap3`.
16c87c5fbaSopenharmony_ci
17c87c5fbaSopenharmony_ci=== Update coap2 to coap3
18c87c5fbaSopenharmony_ci
19c87c5fbaSopenharmony_ciExample
20c87c5fbaSopenharmony_ci----
21c87c5fbaSopenharmony_ci4.2.1
22c87c5fbaSopenharmony_ci  #include <coap2/coap.h>
23c87c5fbaSopenharmony_ci4.3.0
24c87c5fbaSopenharmony_ci  #include <coap3/coap.h>
25c87c5fbaSopenharmony_ci----
26c87c5fbaSopenharmony_ciNo other libcoap include files need to be included in your application.
27c87c5fbaSopenharmony_ci
28c87c5fbaSopenharmony_ci== Call-back handler updates
29c87c5fbaSopenharmony_ci
30c87c5fbaSopenharmony_ciInfrequently used parameters (which can easily be recreated) have been removed
31c87c5fbaSopenharmony_ciand others have been made const.  These call-back handlers are those
32c87c5fbaSopenharmony_ciregistered with the `coap_register_*()` functions as follows:
33c87c5fbaSopenharmony_ci
34c87c5fbaSopenharmony_ci=== coap_register_handler()
35c87c5fbaSopenharmony_ci
36c87c5fbaSopenharmony_ciThe definition of `coap_method_handler_t` has been updated, so all the
37c87c5fbaSopenharmony_cifunctions registered by `coap_register_handler()` need to be updated. Any
38c87c5fbaSopenharmony_ciapplication functions called by these functions may need to include `const` in
39c87c5fbaSopenharmony_citheir calling parameters.
40c87c5fbaSopenharmony_ci
41c87c5fbaSopenharmony_ciExample
42c87c5fbaSopenharmony_ci----
43c87c5fbaSopenharmony_ci4.2.1
44c87c5fbaSopenharmony_cistatic void
45c87c5fbaSopenharmony_ci  hnd_get_time(coap_context_t *context,
46c87c5fbaSopenharmony_ci               coap_resource_t *resource,
47c87c5fbaSopenharmony_ci               coap_session_t *session,
48c87c5fbaSopenharmony_ci               coap_pdu_t *request,
49c87c5fbaSopenharmony_ci               coap_binary_t *token,
50c87c5fbaSopenharmony_ci               coap_string_t *query,
51c87c5fbaSopenharmony_ci               coap_pdu_t *response) {
52c87c5fbaSopenharmony_ci4.3.0
53c87c5fbaSopenharmony_ci  static void
54c87c5fbaSopenharmony_ci  hnd_get_time(coap_resource_t *resource,
55c87c5fbaSopenharmony_ci               coap_session_t *session,
56c87c5fbaSopenharmony_ci               const coap_pdu_t *request,
57c87c5fbaSopenharmony_ci               const coap_string_t *query,
58c87c5fbaSopenharmony_ci               coap_pdu_t *response) {
59c87c5fbaSopenharmony_ci----
60c87c5fbaSopenharmony_ciIf `context` or `token` need to be recreated, this is done by
61c87c5fbaSopenharmony_ci----
62c87c5fbaSopenharmony_ci  coap_context_t *context = coap_session_get_context(session);
63c87c5fbaSopenharmony_ci  coap_bin_const_t rcvd_token = coap_pdu_get_token(request);
64c87c5fbaSopenharmony_ci----
65c87c5fbaSopenharmony_ci
66c87c5fbaSopenharmony_ci=== coap_register_response_handler()
67c87c5fbaSopenharmony_ci
68c87c5fbaSopenharmony_ciThe definition of `coap_response_handler_t` has been updated, so all the
69c87c5fbaSopenharmony_cifunctions registered by `coap_register_response_handler()` need to be updated.
70c87c5fbaSopenharmony_ciAny application functions called by these functions may need to include `const`
71c87c5fbaSopenharmony_ciin their calling parameters.  There is a new handler function exit code
72c87c5fbaSopenharmony_ci`COAP_RESPONSE_FAIL` (if the response is not liked and needs to be rejected
73c87c5fbaSopenharmony_ciwith a `RST` packet) or `COAP_RESPONSE_OK`. Note that `coap_tid_t` has been
74c87c5fbaSopenharmony_cireplaced with `coap_mid_t` to reflect the parameter is the message id.
75c87c5fbaSopenharmony_ci
76c87c5fbaSopenharmony_ciExample
77c87c5fbaSopenharmony_ci----
78c87c5fbaSopenharmony_ci4.2.1
79c87c5fbaSopenharmony_ci  static void
80c87c5fbaSopenharmony_ci  message_handler(struct coap_context_t *context,
81c87c5fbaSopenharmony_ci                  coap_session_t *session,
82c87c5fbaSopenharmony_ci                  coap_pdu_t *sent,
83c87c5fbaSopenharmony_ci                  coap_pdu_t *received,
84c87c5fbaSopenharmony_ci                  const coap_tid_t id) {
85c87c5fbaSopenharmony_ci4.3.0
86c87c5fbaSopenharmony_ci  static coap_response_t
87c87c5fbaSopenharmony_ci  message_handler(coap_session_t *session,
88c87c5fbaSopenharmony_ci                  const coap_pdu_t *sent,
89c87c5fbaSopenharmony_ci                  const coap_pdu_t *received,
90c87c5fbaSopenharmony_ci                  const coap_mid_t mid) {
91c87c5fbaSopenharmony_ci----
92c87c5fbaSopenharmony_ciIf `context` needs to be recreated, this is done by
93c87c5fbaSopenharmony_ci----
94c87c5fbaSopenharmony_ci  coap_context_t *context = coap_session_get_context(session);
95c87c5fbaSopenharmony_ci----
96c87c5fbaSopenharmony_ci
97c87c5fbaSopenharmony_ci=== coap_register_nack_handler()
98c87c5fbaSopenharmony_ci
99c87c5fbaSopenharmony_ciThe definition of `coap_nack_handler_t` has been updated, so all the functions
100c87c5fbaSopenharmony_ciregistered by `coap_register_nack_handler()` need to be updated. Any
101c87c5fbaSopenharmony_ciapplication functions called by these functions may need to include `const` in
102c87c5fbaSopenharmony_citheir calling parameters. Note that `coap_tid_t` has been replaced with
103c87c5fbaSopenharmony_ci`coap_mid_t` to reflect the parameter is the message id.
104c87c5fbaSopenharmony_ci
105c87c5fbaSopenharmony_ciExample
106c87c5fbaSopenharmony_ci----
107c87c5fbaSopenharmony_ci4.2.1
108c87c5fbaSopenharmony_ci  static void
109c87c5fbaSopenharmony_ci  nack_handler(coap_context_t *context,
110c87c5fbaSopenharmony_ci               coap_session_t *session,
111c87c5fbaSopenharmony_ci               coap_pdu_t *sent,
112c87c5fbaSopenharmony_ci               coap_nack_reason_t reason,
113c87c5fbaSopenharmony_ci               const coap_tid_t id) {
114c87c5fbaSopenharmony_ci4.3.0
115c87c5fbaSopenharmony_ci  static void
116c87c5fbaSopenharmony_ci  nack_handler(coap_session_t *session,
117c87c5fbaSopenharmony_ci               const coap_pdu_t *sent,
118c87c5fbaSopenharmony_ci               const coap_nack_reason_t reason,
119c87c5fbaSopenharmony_ci               const coap_mid_t mid) {
120c87c5fbaSopenharmony_ci----
121c87c5fbaSopenharmony_ciIf `context` needs to be recreated, this is done by
122c87c5fbaSopenharmony_ci----
123c87c5fbaSopenharmony_ci  coap_context_t *context = coap_session_get_context(session);
124c87c5fbaSopenharmony_ci----
125c87c5fbaSopenharmony_ci
126c87c5fbaSopenharmony_ci=== coap_register_event_handler()
127c87c5fbaSopenharmony_ci
128c87c5fbaSopenharmony_ciThe definition of `coap_event_handler_t` been updated, so all the functions
129c87c5fbaSopenharmony_ciregistered by `coap_register_event_handler()` need to be updated. Any
130c87c5fbaSopenharmony_ciapplication functions called by these functions may need to include `const` in
131c87c5fbaSopenharmony_citheir calling parameters.
132c87c5fbaSopenharmony_ci
133c87c5fbaSopenharmony_ciExample
134c87c5fbaSopenharmony_ci----
135c87c5fbaSopenharmony_ci4.2.1
136c87c5fbaSopenharmony_ci  static int
137c87c5fbaSopenharmony_ci  event_handler(coap_context_t *context,
138c87c5fbaSopenharmony_ci                coap_event_t event,
139c87c5fbaSopenharmony_ci                struct coap_session_t *session) {
140c87c5fbaSopenharmony_ci4.3.0
141c87c5fbaSopenharmony_ci  static int
142c87c5fbaSopenharmony_ci  event_handler(coap_session_t *session,
143c87c5fbaSopenharmony_ci                const coap_event_t event) {
144c87c5fbaSopenharmony_ci----
145c87c5fbaSopenharmony_ciNote the reversed order of the parameters. If `context` needs to be
146c87c5fbaSopenharmony_cirecreated, this is done by
147c87c5fbaSopenharmony_ci----
148c87c5fbaSopenharmony_ci  coap_context_t *context = coap_session_get_context(session);
149c87c5fbaSopenharmony_ci----
150c87c5fbaSopenharmony_ci
151c87c5fbaSopenharmony_ci=== coap_register_ping_handler()
152c87c5fbaSopenharmony_ci
153c87c5fbaSopenharmony_ciThe definition of `coap_ping_handler_t` been updated, so all the functions
154c87c5fbaSopenharmony_ciregistered by `coap_register_ping_handler()` need to be updated. Any
155c87c5fbaSopenharmony_ciapplication functions called by these functions may need to include `const` in
156c87c5fbaSopenharmony_citheir calling parameters. Note that `coap_tid_t` has been replaced with
157c87c5fbaSopenharmony_ci`coap_mid_t` to reflect the parameter is the message id.
158c87c5fbaSopenharmony_ci
159c87c5fbaSopenharmony_ciExample
160c87c5fbaSopenharmony_ci
161c87c5fbaSopenharmony_ci----
162c87c5fbaSopenharmony_ci4.2.1
163c87c5fbaSopenharmony_ci  void
164c87c5fbaSopenharmony_ci  ping_handler(coap_context_t *context,
165c87c5fbaSopenharmony_ci               coap_session_t *session,
166c87c5fbaSopenharmony_ci               coap_pdu_t *received,
167c87c5fbaSopenharmony_ci               const coap_tid_t id);
168c87c5fbaSopenharmony_ci4.3.0
169c87c5fbaSopenharmony_ci  void
170c87c5fbaSopenharmony_ci  ping_handler(coap_session_t *session,
171c87c5fbaSopenharmony_ci               const coap_pdu_t *received,
172c87c5fbaSopenharmony_ci               const coap_mid_t mid);
173c87c5fbaSopenharmony_ci----
174c87c5fbaSopenharmony_ciIf `context` needs to be recreated, this is done by
175c87c5fbaSopenharmony_ci----
176c87c5fbaSopenharmony_ci  coap_context_t *context = coap_session_get_context(session);
177c87c5fbaSopenharmony_ci----
178c87c5fbaSopenharmony_ci
179c87c5fbaSopenharmony_ci=== coap_register_pong_handler()
180c87c5fbaSopenharmony_ci
181c87c5fbaSopenharmony_ciThe definition of `coap_pong_handler_t` been updated, so all the functions
182c87c5fbaSopenharmony_ciregistered by `coap_register_pong_handler()` need to be updated. Any
183c87c5fbaSopenharmony_ciapplication functions called by these functions may need to include `const` in
184c87c5fbaSopenharmony_citheir calling parameters. Note that `coap_tid_t` has been replaced with
185c87c5fbaSopenharmony_ci`coap_mid_t` to reflect the parameter is the message id.
186c87c5fbaSopenharmony_ci
187c87c5fbaSopenharmony_ciExample
188c87c5fbaSopenharmony_ci----
189c87c5fbaSopenharmony_ci4.2.1
190c87c5fbaSopenharmony_ci  void
191c87c5fbaSopenharmony_ci  pong_handler(coap_context_t *context,
192c87c5fbaSopenharmony_ci               coap_session_t *session,
193c87c5fbaSopenharmony_ci               coap_pdu_t *received,
194c87c5fbaSopenharmony_ci               const coap_tid_t id);
195c87c5fbaSopenharmony_ci4.3.0
196c87c5fbaSopenharmony_ci  void
197c87c5fbaSopenharmony_ci  pong_handler(coap_session_t *session,
198c87c5fbaSopenharmony_ci               const coap_pdu_t *received,
199c87c5fbaSopenharmony_ci               const coap_mid_t mid);
200c87c5fbaSopenharmony_ci----
201c87c5fbaSopenharmony_ciIf `context` needs to be recreated, this is done by
202c87c5fbaSopenharmony_ci----
203c87c5fbaSopenharmony_ci  coap_context_t *context = coap_session_get_context(session);
204c87c5fbaSopenharmony_ci----
205c87c5fbaSopenharmony_ci
206c87c5fbaSopenharmony_ci== libcoap structures no longer directly accessible
207c87c5fbaSopenharmony_ci
208c87c5fbaSopenharmony_ciMany of the structures internally used by libcoap are no longer exposed to
209c87c5fbaSopenharmony_ciapplications. Additional functions of the form `coap_X_get_Y()` and
210c87c5fbaSopenharmony_ci`coap_X_set_Y()` where `X` is the structure type and `Y` is the variable. Below
211c87c5fbaSopenharmony_ciis a non exhaustive set of examples,
212c87c5fbaSopenharmony_ci
213c87c5fbaSopenharmony_ci=== coap_pdu_t code variable
214c87c5fbaSopenharmony_ci
215c87c5fbaSopenharmony_ci
216c87c5fbaSopenharmony_ciExample
217c87c5fbaSopenharmony_ci----
218c87c5fbaSopenharmony_ci4.2.1
219c87c5fbaSopenharmony_ci  if (received->code ==
220c87c5fbaSopenharmony_ci4.3.0
221c87c5fbaSopenharmony_ci  coap_pdu_code_t rcvd_code = coap_pdu_get_code(received);
222c87c5fbaSopenharmony_ci  ...
223c87c5fbaSopenharmony_ci  if (rcvd_code ==
224c87c5fbaSopenharmony_ci----
225c87c5fbaSopenharmony_ci
226c87c5fbaSopenharmony_ciExample
227c87c5fbaSopenharmony_ci----
228c87c5fbaSopenharmony_ci4.2.1
229c87c5fbaSopenharmony_ci  response->code = COAP_RESPONSE_CODE(404);
230c87c5fbaSopenharmony_ci4.3.0
231c87c5fbaSopenharmony_ci  coap_pdu_set_code(response, COAP_RESPONSE_CODE_NOT_FOUND);
232c87c5fbaSopenharmony_ci----
233c87c5fbaSopenharmony_ciNote that more descriptive names are now supported for the response codes, but
234c87c5fbaSopenharmony_cithe old form can still be used.
235c87c5fbaSopenharmony_ci
236c87c5fbaSopenharmony_ci=== coap_pdu_t type variable
237c87c5fbaSopenharmony_ci
238c87c5fbaSopenharmony_ci
239c87c5fbaSopenharmony_ciExample
240c87c5fbaSopenharmony_ci----
241c87c5fbaSopenharmony_ci4.2.1
242c87c5fbaSopenharmony_ci  if (received->type ==
243c87c5fbaSopenharmony_ci4.3.0
244c87c5fbaSopenharmony_ci  coap_pdu_code_t rcvd_type = coap_pdu_get_type(received);
245c87c5fbaSopenharmony_ci  ...
246c87c5fbaSopenharmony_ci  if (rcvd_type ==
247c87c5fbaSopenharmony_ci----
248c87c5fbaSopenharmony_ci
249c87c5fbaSopenharmony_ciExample
250c87c5fbaSopenharmony_ci----
251c87c5fbaSopenharmony_ci4.2.1
252c87c5fbaSopenharmony_ci  request->type = COAP_MESSAGE_NON;
253c87c5fbaSopenharmony_ci4.3.0
254c87c5fbaSopenharmony_ci  coap_pdu_set_type(request, COAP_MESSAGE_NON);
255c87c5fbaSopenharmony_ci----
256c87c5fbaSopenharmony_ci
257c87c5fbaSopenharmony_ci=== coap_pdu_t token variable
258c87c5fbaSopenharmony_ci
259c87c5fbaSopenharmony_ci
260c87c5fbaSopenharmony_ciExample
261c87c5fbaSopenharmony_ci----
262c87c5fbaSopenharmony_ci4.2.1
263c87c5fbaSopenharmony_ci  static inline int
264c87c5fbaSopenharmony_ci  check_token(coap_pdu_t *received) {
265c87c5fbaSopenharmony_ci    return received->token_length == the_token.length &&
266c87c5fbaSopenharmony_ci      memcmp(received->token, the_token.s, the_token.length) == 0;
267c87c5fbaSopenharmony_ci  }
268c87c5fbaSopenharmony_ci4.3.0
269c87c5fbaSopenharmony_ci  static inline int
270c87c5fbaSopenharmony_ci  check_token(const coap_pdu_t *received) {
271c87c5fbaSopenharmony_ci    coap_bin_const_t rcvd_token = coap_pdu_get_token(received);
272c87c5fbaSopenharmony_ci
273c87c5fbaSopenharmony_ci    return rcvd_token.length == the_token.length &&
274c87c5fbaSopenharmony_ci      memcmp(rcvd_token.s, the_token.s, the_token.length) == 0;
275c87c5fbaSopenharmony_ci  }
276c87c5fbaSopenharmony_ci----
277c87c5fbaSopenharmony_ci
278c87c5fbaSopenharmony_ci=== coap_session_t context variable
279c87c5fbaSopenharmony_ci
280c87c5fbaSopenharmony_ci
281c87c5fbaSopenharmony_ciExample
282c87c5fbaSopenharmony_ci----
283c87c5fbaSopenharmony_ci4.2.1
284c87c5fbaSopenharmony_ci  if (session->context ==
285c87c5fbaSopenharmony_ci4.3.0
286c87c5fbaSopenharmony_ci  coap_context_t context = coap_session_get_context(session);
287c87c5fbaSopenharmony_ci  ...
288c87c5fbaSopenharmony_ci  if (context ==
289c87c5fbaSopenharmony_ci----
290c87c5fbaSopenharmony_ci
291c87c5fbaSopenharmony_ci=== coap_session_t proto variable
292c87c5fbaSopenharmony_ci
293c87c5fbaSopenharmony_ci
294c87c5fbaSopenharmony_ciExample
295c87c5fbaSopenharmony_ci----
296c87c5fbaSopenharmony_ci4.2.1
297c87c5fbaSopenharmony_ci  if (session->proto ==
298c87c5fbaSopenharmony_ci4.3.0
299c87c5fbaSopenharmony_ci  coap_proto_t proto = coap_session_get_proto(session);
300c87c5fbaSopenharmony_ci  ...
301c87c5fbaSopenharmony_ci  if (proto ==
302c87c5fbaSopenharmony_ci----
303c87c5fbaSopenharmony_ci
304c87c5fbaSopenharmony_ci
305c87c5fbaSopenharmony_ci== Functions with changed parameters
306c87c5fbaSopenharmony_ci
307c87c5fbaSopenharmony_ciSome functions have had the parameters updated.  Below are some of the more common ones.
308c87c5fbaSopenharmony_ci
309c87c5fbaSopenharmony_ci=== coap_pdu_init()
310c87c5fbaSopenharmony_ci
311c87c5fbaSopenharmony_ciThe definition of the second parameter has changed from `coap_request_t` to
312c87c5fbaSopenharmony_ci`coap_pdu_code_t`.
313c87c5fbaSopenharmony_ci
314c87c5fbaSopenharmony_ciExample
315c87c5fbaSopenharmony_ci----
316c87c5fbaSopenharmony_ci4.2.1
317c87c5fbaSopenharmony_ci  pdu = coap_pdu_init(msgtype,
318c87c5fbaSopenharmony_ci                      COAP_REQUEST_GET,
319c87c5fbaSopenharmony_ci                      coap_new_message_id(session),
320c87c5fbaSopenharmony_ci                      coap_session_max_pdu_size(session));
321c87c5fbaSopenharmony_ci4.3.0
322c87c5fbaSopenharmony_ci  pdu = coap_pdu_init(msgtype,
323c87c5fbaSopenharmony_ci                      COAP_REQUEST_CODE_GET,
324c87c5fbaSopenharmony_ci                      coap_new_message_id(session),
325c87c5fbaSopenharmony_ci                      coap_session_max_pdu_size(session));
326c87c5fbaSopenharmony_ci----
327c87c5fbaSopenharmony_ciNote that the second parameter (`COAP_REQUEST_CODE_GET`) goes further than
328c87c5fbaSopenharmony_cijust request codes and includes the possibility of response codes (e.g.
329c87c5fbaSopenharmony_ci`COAP_RESPONSE_CODE_CREATED`) from the `enum coap_pdu_code_t`. Hence the
330c87c5fbaSopenharmony_ciaddition of `_CODE` in the parameter value.
331c87c5fbaSopenharmony_ci
332c87c5fbaSopenharmony_ci=== coap_get_data()
333c87c5fbaSopenharmony_ci
334c87c5fbaSopenharmony_ciThe definition of the third parameter has been changed to be `const`
335c87c5fbaSopenharmony_ci
336c87c5fbaSopenharmony_ciExample
337c87c5fbaSopenharmony_ci----
338c87c5fbaSopenharmony_ci4.2.1
339c87c5fbaSopenharmony_ci  uint8_t *data;
340c87c5fbaSopenharmony_ci  ...
341c87c5fbaSopenharmony_ci  ret = coap_get_data(pdu, &length, &data);
342c87c5fbaSopenharmony_ci4.3.0
343c87c5fbaSopenharmony_ci  const uint8_t *data;
344c87c5fbaSopenharmony_ci  ...
345c87c5fbaSopenharmony_ci  ret = coap_get_data(pdu, &length, &data);
346c87c5fbaSopenharmony_ci----
347c87c5fbaSopenharmony_ci
348c87c5fbaSopenharmony_ci== Large Data Handling
349c87c5fbaSopenharmony_ci
350c87c5fbaSopenharmony_ciSplitting up large data transmission into blocks (RFC7959) can now all be
351c87c5fbaSopenharmony_cihandled by internally by libcoap, removing the need for applications to know
352c87c5fbaSopenharmony_cianything about how to work with blocks, or need to do any block packet loss
353c87c5fbaSopenharmony_cirecovery. In simple terms, `coap_context_set_block_mode()` must be called,
354c87c5fbaSopenharmony_ci`coap_add_data()` (or `coap_add_data_blocked_response()`) is replaced by
355c87c5fbaSopenharmony_ci`coap_add_data_large_response()` or `coap_add_data_large_request()`, and
356c87c5fbaSopenharmony_ci`coap_get_data_large()` used instead of `coap_get_data()`.  See man page
357c87c5fbaSopenharmony_ci`coap_block(3)` for further information.
358c87c5fbaSopenharmony_ci
359c87c5fbaSopenharmony_ciThere are 3 ways of handling the block transfers
360c87c5fbaSopenharmony_ci
361c87c5fbaSopenharmony_ci=== Application does all the work
362c87c5fbaSopenharmony_ci
363c87c5fbaSopenharmony_ciThis is how things were done in 4.2.1.  The application recognizes the next
364c87c5fbaSopenharmony_ciblock request coming in and then generates the next block response (including
365c87c5fbaSopenharmony_cisetting up the PDU if client).  To continue using this method,
366c87c5fbaSopenharmony_ci`coap_context_set_block_mode()` must not be called and none of the `_large`
367c87c5fbaSopenharmony_cifunctions used.
368c87c5fbaSopenharmony_ci
369c87c5fbaSopenharmony_ci=== Application sees individual blocks
370c87c5fbaSopenharmony_ci
371c87c5fbaSopenharmony_ciBy calling `coap_context_set_block_mode(context, COAP_BLOCK_USE_LIBCOAP)` and
372c87c5fbaSopenharmony_ciusing the `_large` functions, all the existing code that builds the next block
373c87c5fbaSopenharmony_ciresponse is no longer needed (and must be removed to prevent packet
374c87c5fbaSopenharmony_cirequest/response duplication) as libcoap does this for the application.
375c87c5fbaSopenharmony_ci
376c87c5fbaSopenharmony_ciBy calling `coap_get_data_large()`, the application can determine if this is
377c87c5fbaSopenharmony_cithe first block or not (using `offset` value), whether the first block is all
378c87c5fbaSopenharmony_cithe data (`offset` = `0`, `length` = `total`) and whether this is the last
379c87c5fbaSopenharmony_ciblock (`offset` + `length` = `total`).  It is the responsibility of the
380c87c5fbaSopenharmony_ciapplication to re-assemble the individual blocks into a single body of data.
381c87c5fbaSopenharmony_ci
382c87c5fbaSopenharmony_ciIf this is the request handler in a server, the server still needs to return a
383c87c5fbaSopenharmony_ci`2.31 (Continue)` response code if the received data is not for the final block,
384c87c5fbaSopenharmony_ciotherwise a `2.01 (Created)` or `2.04 (Changed)` should be returned.
385c87c5fbaSopenharmony_ci
386c87c5fbaSopenharmony_ci=== Application only sees all the data
387c87c5fbaSopenharmony_ci
388c87c5fbaSopenharmony_ciBy calling `coap_context_set_block_mode(context,
389c87c5fbaSopenharmony_ciCOAP_BLOCK_USE_LIBCOAP|COAP_BLOCK_SINGLE_BODY)` and using the `_large`
390c87c5fbaSopenharmony_cifunctions, all the existing code that builds the next block response is no
391c87c5fbaSopenharmony_cilonger needed (and must be removed to prevent request/response packet
392c87c5fbaSopenharmony_ciduplication) as libcoap does this for the application.
393c87c5fbaSopenharmony_ci
394c87c5fbaSopenharmony_ci`coap_get_data_large()` will only return the entire body of data (`offset`
395c87c5fbaSopenharmony_cialways `0`, `length` = `total`) and there is no need to re-assemble individual
396c87c5fbaSopenharmony_ciblocks into a large body of data.
397c87c5fbaSopenharmony_ci
398c87c5fbaSopenharmony_ciIn RAM constrained environments, option 2 may be the preferred method.
399c87c5fbaSopenharmony_ci
400c87c5fbaSopenharmony_ci== Observe Handling
401c87c5fbaSopenharmony_ci
402c87c5fbaSopenharmony_ciIn the server's request handler's call-back, there is no longer any need to
403c87c5fbaSopenharmony_cicheck whether this is an Observe call (or Observe triggered requesting
404c87c5fbaSopenharmony_ciadditional response call) and add in the Observe Option into the response pdu.
405c87c5fbaSopenharmony_ciThis is now added by libcoap, and trying to add in the Observe Option for the
406c87c5fbaSopenharmony_cisecond time in the call-back handler will throw up a Informational warning.
407c87c5fbaSopenharmony_ci
408c87c5fbaSopenharmony_ciFor the client, there is a new function `coap_cancel_observe()` that can be
409c87c5fbaSopenharmony_cicalled to cancel an observation on the server. To use it,
410c87c5fbaSopenharmony_ci`coap_context_set_block_mode()` has to be called prior to sending the initial
411c87c5fbaSopenharmony_cirequest containing the Observe option.
412c87c5fbaSopenharmony_ci
413c87c5fbaSopenharmony_ci== Unused function parameters
414c87c5fbaSopenharmony_ci
415c87c5fbaSopenharmony_ci`UNUSED_PARAM` has been replaced with `COAP_UNUSED`. If `COAP_UNUSED` is used,
416c87c5fbaSopenharmony_cithen the definition for `UNUSED_PARAM` can be removed.
417c87c5fbaSopenharmony_ci
418c87c5fbaSopenharmony_ci== CoAP Message IDs
419c87c5fbaSopenharmony_ci
420c87c5fbaSopenharmony_ci`coap_tid_t` has been replaced with `coap_mid_t`, as well as `COAP_TID_INVALID`
421c87c5fbaSopenharmony_cihas been replaced with `COAP_MID_INVALID`. This is so that the Message ID aligns
422c87c5fbaSopenharmony_ciwith the definition in RFC7252.
423c87c5fbaSopenharmony_ci
424c87c5fbaSopenharmony_ci== Async Support
425c87c5fbaSopenharmony_ci
426c87c5fbaSopenharmony_ciThe `async` support has been re-written to simplify usage, and allows the
427c87c5fbaSopenharmony_ciunderlying libcoap to do the main management / work. A primary change is to
428c87c5fbaSopenharmony_ciregister the async request with a defined delay time before triggering - which
429c87c5fbaSopenharmony_ciif set to 0 is an infinite time and the delay time subsequently updated if
430c87c5fbaSopenharmony_cirequired.  Consequently the `coap_async_*()` functions now have different
431c87c5fbaSopenharmony_ciparameters.
432