Merge pull request #2180 from atiselsts/bugfix/coap-observe-option

Keep CoAP 'observe' option length <= 3 bytes
This commit is contained in:
Nicolas Tsiftes 2017-04-21 17:59:40 +02:00 committed by GitHub
commit ddf723f88d

View file

@ -249,6 +249,8 @@ coap_notify_observers_sub(resource_t *resource, const char *subpath)
if(notification->code < BAD_REQUEST_4_00) { if(notification->code < BAD_REQUEST_4_00) {
coap_set_header_observe(notification, (obs->obs_counter)++); coap_set_header_observe(notification, (obs->obs_counter)++);
/* mask out to keep the CoAP observe option length <= 3 bytes */
obs->obs_counter &= 0xffffff;
} }
coap_set_token(notification, obs->token, obs->token_len); coap_set_token(notification, obs->token, obs->token_len);
@ -276,6 +278,8 @@ coap_observe_handler(resource_t *resource, void *request, void *response)
coap_req->uri_path, coap_req->uri_path_len); coap_req->uri_path, coap_req->uri_path_len);
if(obs) { if(obs) {
coap_set_header_observe(coap_res, (obs->obs_counter)++); coap_set_header_observe(coap_res, (obs->obs_counter)++);
/* mask out to keep the CoAP observe option length <= 3 bytes */
obs->obs_counter &= 0xffffff;
/* /*
* Following payload is for demonstration purposes only. * Following payload is for demonstration purposes only.
* A subscription should return the same representation as a normal GET. * A subscription should return the same representation as a normal GET.