1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
/* coap_session.h -- Session management for libcoap
*
* Copyright (C) 2017 Jean-Claue Michelou <jcm@spinetix.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*
* This file is part of the CoAP library libcoap. Please see
* README for terms of use.
*/
/**
* @file coap_session.h
* @brief Defines the application visible session information
*/
/**
* @ingroup application_api
* @defgroup session Sessions
* API for CoAP Session access
* @{
*/
/**
* Abstraction of a fixed point number that can be used where necessary instead
* of a float. 1,000 fractional bits equals one integer
*/
typedef struct coap_fixed_point_t coap_fixed_point_t;
/**
* coap_session_type_t values
*/
typedef enum coap_session_type_t coap_session_type_t;
/**
* coap_session_state_t values
*/
typedef enum coap_session_state_t coap_session_state_t;
/**
* Increment reference counter on a session.
*
* @param session The CoAP session.
* @return same as session
*/
coap_session_t *;
/**
* Decrement reference counter on a session.
* Note that the session may be deleted as a result and should not be used
* after this call.
*
* @param session The CoAP session.
*/
void ;
/**
* Notify session that it has failed. This cleans up any outstanding / queued
* transmissions, observations etc..
*
* @param session The CoAP session.
* @param reason The reason why the session was disconnected.
*/
void ;
/**
* Stores @p data with the given session. This function overwrites any value
* that has previously been stored with @p session.
*
* @param session The CoAP session.
* @param data The pointer to the data to store.
*/
void ;
/**
* Returns any application-specific data that has been stored with @p
* session using the function coap_session_set_app_data(). This function will
* return @c NULL if no data has been stored.
*
* @param session The CoAP session.
*
* @return Pointer to the stored data or @c NULL.
*/
void *;
/**
* Get the remote IP address from the session.
*
* @param session The CoAP session.
*
* @return The session's remote address or @c NULL on failure.
*/
const coap_address_t *;
/**
* Get the local IP address from the session.
*
* @param session The CoAP session.
*
* @return The session's local address or @c NULL on failure.
*/
const coap_address_t *;
/**
* Get the session protocol type
*
* @param session The CoAP session.
*
* @return The session's protocol type
*/
coap_proto_t ;
/**
* Get the session type
*
* @param session The CoAP session.
*
* @return The session's type
*/
coap_session_type_t ;
/**
* Get the session state
*
* @param session The CoAP session.
*
* @return The session's state
*/
coap_session_state_t ;
/**
* Get the session if index
*
* @param session The CoAP session.
*
* @return The session's if index, or @c -1 on error.
*/
int ;
/**
* Get the session TLS security ptr (TLS type dependent)
*
* OpenSSL: SSL*
* GnuTLS: gnutls_session_t (implicit *)
* Mbed TLS: mbedtls_ssl_context*
* TinyDTLS: struct dtls_context*
*
* @param session The CoAP session.
* @param tls_lib Updated with the library type.
*
* @return The session TLS ptr or @c NULL if not set up
*/
void *;
/**
* Get the session context
*
* @param session The CoAP session.
*
* @return The session's context
*/
coap_context_t *;
/**
* Set the session type to client. Typically used in a call-home server.
* The session needs to be of type COAP_SESSION_TYPE_SERVER.
* Note: If this function is successful, the session reference count is
* incremented and a subsequent coap_session_release() taking the
* reference count to 0 will cause the session to be freed off.
*
* @param session The CoAP session.
*
* @return @c 1 if updated, @c 0 on failure.
*/
int ;
/**
* Set the session MTU. This is the maximum message size that can be sent,
* excluding IP and UDP overhead.
*
* @param session The CoAP session.
* @param mtu maximum message size
*/
void ;
/**
* Get maximum acceptable PDU size
*
* @param session The CoAP session.
* @return maximum PDU size, not including header (but including token).
*/
size_t ;
/**
* Creates a new client session to the designated server.
* @param ctx The CoAP context.
* @param local_if Address of local interface. It is recommended to use NULL to let the operating system choose a suitable local interface. If an address is specified, the port number should be zero, which means that a free port is automatically selected.
* @param server The server's address. If the port number is zero, the default port for the protocol will be used.
* @param proto Protocol.
*
* @return A new CoAP session or NULL if failed. Call coap_session_release to free.
*/
coap_session_t *;
/**
* Creates a new client session to the designated server with PSK credentials
* @param ctx The CoAP context.
* @param local_if Address of local interface. It is recommended to use NULL to let the operating system choose a suitable local interface. If an address is specified, the port number should be zero, which means that a free port is automatically selected.
* @param server The server's address. If the port number is zero, the default port for the protocol will be used.
* @param proto Protocol.
* @param identity PSK client identity
* @param key PSK shared key
* @param key_len PSK shared key length
*
* @return A new CoAP session or NULL if failed. Call coap_session_release to free.
*/
coap_session_t *;
/**
* Creates a new client session to the designated server with PSK credentials
* @param ctx The CoAP context.
* @param local_if Address of local interface. It is recommended to use NULL to
* let the operating system choose a suitable local interface.
* If an address is specified, the port number should be zero,
* which means that a free port is automatically selected.
* @param server The server's address. If the port number is zero, the default
* port for the protocol will be used.
* @param proto CoAP Protocol.
* @param setup_data PSK parameters.
*
* @return A new CoAP session or NULL if failed. Call coap_session_release()
* to free.
*/
coap_session_t *;
/**
* Get the server session's current Identity Hint (PSK).
*
* @param session The current coap_session_t object.
*
* @return @c hint if successful, else @c NULL.
*/
const coap_bin_const_t * ;
/**
* Get the server session's current PSK identity (PSK).
*
* @param session The current coap_session_t object.
*
* @return PSK identity if successful, else @c NULL.
*/
const coap_bin_const_t *;
/**
* Get the session's current pre-shared key (PSK).
*
* @param session The current coap_session_t object.
*
* @return @c psk_key if successful, else @c NULL.
*/
const coap_bin_const_t * ;
/**
* Creates a new client session to the designated server with PKI credentials
* @param ctx The CoAP context.
* @param local_if Address of local interface. It is recommended to use NULL to
* let the operating system choose a suitable local interface.
* If an address is specified, the port number should be zero,
* which means that a free port is automatically selected.
* @param server The server's address. If the port number is zero, the default
* port for the protocol will be used.
* @param proto CoAP Protocol.
* @param setup_data PKI parameters.
*
* @return A new CoAP session or NULL if failed. Call coap_session_release()
* to free.
*/
coap_session_t *;
/**
* Initializes the token value to use as a starting point.
*
* @param session The current coap_session_t object.
* @param length The length of the token (0 - 8 bytes).
* @param token The token data.
*
*/
void ;
/**
* Creates a new token for use.
*
* @param session The current coap_session_t object.
* @param length Updated with the length of the new token.
* @param token Updated with the new token data (must be 8 bytes long).
*
*/
void ;
/**
* @ingroup logging
* Get session description.
*
* @param session The CoAP session.
* @return description string.
*/
const char *;
/**
* Create a new endpoint for communicating with peers.
*
* @param context The coap context that will own the new endpoint
* @param listen_addr Address the endpoint will listen for incoming requests on or originate outgoing requests from. Use NULL to specify that no incoming request will be accepted and use a random endpoint.
* @param proto Protocol used on this endpoint
*/
coap_endpoint_t *;
/**
* Set the endpoint's default MTU. This is the maximum message size that can be
* sent, excluding IP and UDP overhead.
*
* @param endpoint The CoAP endpoint.
* @param mtu maximum message size
*/
void ;
void ;
/** @} */
/**
* @ingroup logging
* Get endpoint description.
*
* @param endpoint The CoAP endpoint.
* @return description string.
*/
const char *;
coap_session_t *;
/**
* @ingroup application_api
* @defgroup cc Rate Control
* API for updating transmission parameters for CoAP rate control.
* The transmission parameters for CoAP rate control ("Congestion
* Control" in stream-oriented protocols) are defined in
* https://tools.ietf.org/html/rfc7252#section-4.8
* @{
*/
/**
* Number of seconds when to expect an ACK or a response to an
* outstanding CON message.
* RFC 7252, Section 4.8 Default value of ACK_TIMEOUT is 2
*
* Configurable using coap_session_set_ack_timeout()
*/
/**
* A factor that is used to randomize the wait time before a message
* is retransmitted to prevent synchronization effects.
* RFC 7252, Section 4.8 Default value of ACK_RANDOM_FACTOR is 1.5
*
* Configurable using coap_session_set_ack_random_factor()
*/
/**
* Number of message retransmissions before message sending is stopped.
* RFC 7252, Section 4.8 Default value of MAX_RETRANSMIT is 4
*
* Configurable using coap_session_set_max_retransmit()
*/
/**
* The number of simultaneous outstanding interactions that a client
* maintains to a given server.
* RFC 7252, Section 4.8 Default value of NSTART is 1
*
* Configurable using coap_session_set_nstart()
*/
/**
* The number of seconds to use as bounds for multicast traffic
* RFC 7252, Section 4.8 Default value of DEFAULT_LEISURE is 5.0
*
* Configurable using coap_session_set_default_leisure()
*/
/**
* The number of bytes/second allowed when there is no response
* RFC 7252, Section 4.8 Default value of PROBING_RATE is 1
*
* Configurable using coap_session_set_probing_rate()
*/
/**
* The MAX_LATENCY definition.
* RFC 7252, Section 4.8.2 MAX_LATENCY is 100.
*/
/**
* Set the CoAP initial ack response timeout before the next re-transmit
*
* Number of seconds when to expect an ACK or a response to an
* outstanding CON message.
* RFC7252 ACK_TIMEOUT
*
* @param session The CoAP session.
* @param value The value to set to. The default is 2.0 and should not normally
* get changed.
*/
void ;
/**
* Get the CoAP initial ack response timeout before the next re-transmit
*
* Number of seconds when to expect an ACK or a response to an
* outstanding CON message.
* RFC7252 ACK_TIMEOUT
*
* @param session The CoAP session.
*
* @return Current ack response timeout value
*/
coap_fixed_point_t ;
/**
* Set the CoAP ack randomize factor
*
* A factor that is used to randomize the wait time before a message
* is retransmitted to prevent synchronization effects.
* RFC7252 ACK_RANDOM_FACTOR
*
* @param session The CoAP session.
* @param value The value to set to. The default is 1.5 and should not normally
* get changed.
*/
void ;
/**
* Get the CoAP ack randomize factor
*
* A factor that is used to randomize the wait time before a message
* is retransmitted to prevent synchronization effects.
* RFC7252 ACK_RANDOM_FACTOR
*
* @param session The CoAP session.
*
* @return Current ack randomize value
*/
coap_fixed_point_t ;
/**
* Set the CoAP maximum retransmit count before failure
*
* Number of message retransmissions before message sending is stopped
* RFC7252 MAX_RETRANSMIT
*
* @param session The CoAP session.
* @param value The value to set to. The default is 4 and should not normally
* get changed.
*/
void ;
/**
* Get the CoAP maximum retransmit before failure
*
* Number of message retransmissions before message sending is stopped
* RFC7252 MAX_RETRANSMIT
*
* @param session The CoAP session.
*
* @return Current maximum retransmit value
*/
uint16_t ;
/**
* Set the CoAP maximum concurrent transmission count of Confirmable messages
* RFC7252 NSTART
*
* @param session The CoAP session.
* @param value The value to set to. The default is 1 and should not normally
* get changed.
*/
void ;
/**
* Get the CoAP maximum concurrent transmission count of Confirmable messages
* RFC7252 NSTART
*
* @param session The CoAP session.
*
* @return Current nstart value
*/
uint16_t ;
/**
* Set the CoAP default leisure time (for multicast)
* RFC7252 DEFAULT_LEISURE
*
* @param session The CoAP session.
* @param value The value to set to. The default is 5.0 and should not normally
* get changed.
*/
void ;
/**
* Get the CoAP default leisure time
* RFC7252 DEFAULT_LEISURE
*
* @param session The CoAP session.
*
* @return Current default_leisure value
*/
coap_fixed_point_t ;
/**
* Set the CoAP probing rate when there is no response
* RFC7252 PROBING_RATE
*
* @param session The CoAP session.
* @param value The value to set to. The default is 1 and should not normally
* get changed.
*/
void ;
/**
* Get the CoAP probing rate when there is no response
* RFC7252 PROBING_RATE
*
* @param session The CoAP session.
*
* @return Current probing_rate value
*/
uint32_t ;
/** @} */
/**
* Send a ping message for the session.
* @param session The CoAP session.
*
* @return COAP_INVALID_MID if there is an error
*/
coap_mid_t ;
/**
* Disable client automatically sending observe cancel on session close
*
* @param session The CoAP session.
*/
void ;
/* COAP_SESSION_H */