er-coap (observe): fix possible duplicate value for observe option in GET response and subsequent notification
Currently, the observe value for a response to a GET observe request is always set to zero. That may cause the subsequent notification to have the same observe value. In fact, that happens every time an observable resource is observed for the first time (since the obs_counter is implicitly initialized to zero). This patch fixes such a problem by setting the observe option value of responses to obs_counter (and then incrementing it).
This commit is contained in:
parent
35b6032c64
commit
21898f1e21
1 changed files with 6 additions and 5 deletions
|
@ -232,17 +232,18 @@ coap_observe_handler(resource_t *resource, void *request, void *response)
|
|||
{
|
||||
coap_packet_t *const coap_req = (coap_packet_t *)request;
|
||||
coap_packet_t *const coap_res = (coap_packet_t *)response;
|
||||
coap_observer_t * obs;
|
||||
|
||||
static char content[16];
|
||||
|
||||
if(coap_req->code == COAP_GET && coap_res->code < 128) { /* GET request and response without error code */
|
||||
if(IS_OPTION(coap_req, COAP_OPTION_OBSERVE)) {
|
||||
if(coap_req->observe == 0) {
|
||||
|
||||
if(coap_add_observer(&UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport,
|
||||
coap_req->token, coap_req->token_len,
|
||||
resource->url)) {
|
||||
coap_set_header_observe(coap_res, 0);
|
||||
obs = coap_add_observer(&UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport,
|
||||
coap_req->token, coap_req->token_len,
|
||||
resource->url);
|
||||
if(obs) {
|
||||
coap_set_header_observe(coap_res, (obs->obs_counter)++);
|
||||
/*
|
||||
* Following payload is for demonstration purposes only.
|
||||
* A subscription should return the same representation as a normal GET.
|
||||
|
|
Loading…
Reference in a new issue