Added RST-MID matching for observing.
This commit is contained in:
parent
e4c506820d
commit
c1aa211dc7
|
@ -225,8 +225,8 @@ handle_incoming_data(void)
|
||||||
/* Cancel possible subscriptions. */
|
/* Cancel possible subscriptions. */
|
||||||
if (IS_OPTION(message, COAP_OPTION_TOKEN))
|
if (IS_OPTION(message, COAP_OPTION_TOKEN))
|
||||||
{
|
{
|
||||||
/* RST must be empty, so it is a full client reset. */
|
/* Erbium stores last MID for each observer. */
|
||||||
coap_remove_observer_by_client(&UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport);
|
coap_remove_observer_by_mid(&UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport, message->mid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,7 @@ coap_add_observer(uip_ipaddr_t *addr, uint16_t port, const uint8_t *token, size_
|
||||||
o->port = port;
|
o->port = port;
|
||||||
o->token_len = token_len;
|
o->token_len = token_len;
|
||||||
memcpy(o->token, token, token_len);
|
memcpy(o->token, token, token_len);
|
||||||
|
o->last_mid = 0;
|
||||||
|
|
||||||
stimer_set(&o->refresh_timer, COAP_OBSERVING_REFRESH_INTERVAL);
|
stimer_set(&o->refresh_timer, COAP_OBSERVING_REFRESH_INTERVAL);
|
||||||
|
|
||||||
|
@ -107,6 +108,7 @@ coap_remove_observer_by_client(uip_ipaddr_t *addr, uint16_t port)
|
||||||
}
|
}
|
||||||
return removed;
|
return removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
coap_remove_observer_by_token(uip_ipaddr_t *addr, uint16_t port, uint8_t *token, size_t token_len)
|
coap_remove_observer_by_token(uip_ipaddr_t *addr, uint16_t port, uint8_t *token, size_t token_len)
|
||||||
{
|
{
|
||||||
|
@ -124,6 +126,7 @@ coap_remove_observer_by_token(uip_ipaddr_t *addr, uint16_t port, uint8_t *token,
|
||||||
}
|
}
|
||||||
return removed;
|
return removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
coap_remove_observer_by_url(uip_ipaddr_t *addr, uint16_t port, const char *url)
|
coap_remove_observer_by_url(uip_ipaddr_t *addr, uint16_t port, const char *url)
|
||||||
{
|
{
|
||||||
|
@ -141,6 +144,24 @@ coap_remove_observer_by_url(uip_ipaddr_t *addr, uint16_t port, const char *url)
|
||||||
}
|
}
|
||||||
return removed;
|
return removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
coap_remove_observer_by_mid(uip_ipaddr_t *addr, uint16_t port, uint16_t mid)
|
||||||
|
{
|
||||||
|
int removed = 0;
|
||||||
|
coap_observer_t* obs = NULL;
|
||||||
|
|
||||||
|
for (obs = (coap_observer_t*)list_head(observers_list); obs; obs = obs->next)
|
||||||
|
{
|
||||||
|
PRINTF("Remove check URL %p\n", url);
|
||||||
|
if (uip_ipaddr_cmp(&obs->addr, addr) && obs->port==port && obs->last_mid==mid)
|
||||||
|
{
|
||||||
|
coap_remove_observer(obs);
|
||||||
|
removed++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return removed;
|
||||||
|
}
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
coap_notify_observers(const char *url, int type, uint32_t observe, uint8_t *payload, size_t payload_len)
|
coap_notify_observers(const char *url, int type, uint32_t observe, uint8_t *payload, size_t payload_len)
|
||||||
|
@ -177,6 +198,9 @@ coap_notify_observers(const char *url, int type, uint32_t observe, uint8_t *payl
|
||||||
PRINTF(":%u\n", obs->port);
|
PRINTF(":%u\n", obs->port);
|
||||||
PRINTF(" %.*s\n", payload_len, payload);
|
PRINTF(" %.*s\n", payload_len, payload);
|
||||||
|
|
||||||
|
/* Update last MID for RST matching. */
|
||||||
|
obs->last_mid = transaction->mid;
|
||||||
|
|
||||||
coap_send_transaction(transaction);
|
coap_send_transaction(transaction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,7 @@ typedef struct coap_observer {
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
uint8_t token_len;
|
uint8_t token_len;
|
||||||
uint8_t token[COAP_TOKEN_LEN];
|
uint8_t token[COAP_TOKEN_LEN];
|
||||||
|
uint16_t last_mid;
|
||||||
struct stimer refresh_timer;
|
struct stimer refresh_timer;
|
||||||
} coap_observer_t;
|
} coap_observer_t;
|
||||||
|
|
||||||
|
@ -72,6 +73,7 @@ void coap_remove_observer(coap_observer_t *o);
|
||||||
int coap_remove_observer_by_client(uip_ipaddr_t *addr, uint16_t port);
|
int coap_remove_observer_by_client(uip_ipaddr_t *addr, uint16_t port);
|
||||||
int coap_remove_observer_by_token(uip_ipaddr_t *addr, uint16_t port, uint8_t *token, size_t token_len);
|
int coap_remove_observer_by_token(uip_ipaddr_t *addr, uint16_t port, uint8_t *token, size_t token_len);
|
||||||
int coap_remove_observer_by_url(uip_ipaddr_t *addr, uint16_t port, const char *url);
|
int coap_remove_observer_by_url(uip_ipaddr_t *addr, uint16_t port, const char *url);
|
||||||
|
int coap_remove_observer_by_mid(uip_ipaddr_t *addr, uint16_t port, uint16_t mid);
|
||||||
|
|
||||||
void coap_notify_observers(const char *url, int type, uint32_t observe, uint8_t *payload, size_t payload_len);
|
void coap_notify_observers(const char *url, int type, uint32_t observe, uint8_t *payload, size_t payload_len);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue