1 /*
2  * subscribe.h -- subscription handling for CoAP
3  *                see draft-ietf-core-observe-16
4  *
5  * Copyright (C) 2010-2012,2014-2015 Olaf Bergmann <bergmann@tzi.org>
6  *
7  * This file is part of the CoAP library libcoap. Please see README for terms
8  * of use.
9  */
10 
11 
12 #ifndef _COAP_SUBSCRIBE_H_
13 #define _COAP_SUBSCRIBE_H_
14 
15 #include "address.h"
16 #include "coap_io.h"
17 
18 /**
19  * @defgroup observe Resource observation
20  * @{
21  */
22 
23 /**
24  * The value COAP_OBSERVE_ESTABLISH in a GET request indicates a new observe
25  * relationship for (sender address, token) is requested.
26  */
27 #define COAP_OBSERVE_ESTABLISH 0
28 
29 /**
30  * The value COAP_OBSERVE_CANCEL in a GET request indicates that the observe
31  * relationship for (sender address, token) must be cancelled.
32  */
33 #define COAP_OBSERVE_CANCEL 1
34 
35 #ifndef COAP_OBS_MAX_NON
36 /**
37  * Number of notifications that may be sent non-confirmable before a confirmable
38  * message is sent to detect if observers are alive. The maximum allowed value
39  * here is @c 15.
40  */
41 #define COAP_OBS_MAX_NON   5
42 #endif /* COAP_OBS_MAX_NON */
43 
44 #ifndef COAP_OBS_MAX_FAIL
45 /**
46  * Number of confirmable notifications that may fail (i.e. time out without
47  * being ACKed) before an observer is removed. The maximum value for
48  * COAP_OBS_MAX_FAIL is @c 3.
49  */
50 #define COAP_OBS_MAX_FAIL  3
51 #endif /* COAP_OBS_MAX_FAIL */
52 
53 /** Subscriber information */
54 typedef struct coap_subscription_t {
55   struct coap_subscription_t *next; /**< next element in linked list */
56   coap_endpoint_t local_if;         /**< local communication interface */
57   coap_address_t subscriber;        /**< address and port of subscriber */
58 
59   unsigned int non_cnt:4;  /**< up to 15 non-confirmable notifies allowed */
60   unsigned int fail_cnt:2; /**< up to 3 confirmable notifies can fail */
61   unsigned int dirty:1;    /**< set if the notification temporarily could not be
62                             *   sent (in that case, the resource's partially
63                             *   dirty flag is set too) */
64   size_t token_length;     /**< actual length of token */
65   unsigned char token[8];  /**< token used for subscription */
66 } coap_subscription_t;
67 
68 void coap_subscription_init(coap_subscription_t *);
69 
70 /** @} */
71 
72 #endif /* _COAP_SUBSCRIBE_H_ */
73