Added CoAP ping support.

This commit is contained in:
Matthias Kovatsch 2013-06-19 15:17:45 +02:00
parent bad066abad
commit 75b958bb03
2 changed files with 17 additions and 4 deletions

View file

@ -220,9 +220,14 @@ coap_receive(void)
else else
{ {
/* Responses */ /* Responses */
if (message->type==COAP_TYPE_CON && message->code==0)
if (message->type==COAP_TYPE_ACK)
{ {
PRINTF("Received Ping\n");
coap_error_code = PING_RESPONSE;
}
else if (message->type==COAP_TYPE_ACK)
{
/* Transactions are closed through lookup below */
PRINTF("Received ACK\n"); PRINTF("Received ACK\n");
} }
else if (message->type==COAP_TYPE_RST) else if (message->type==COAP_TYPE_RST)
@ -261,6 +266,8 @@ coap_receive(void)
} }
else else
{ {
coap_message_type_t reply_type = COAP_TYPE_ACK;
PRINTF("ERROR %u: %s\n", coap_error_code, coap_error_message); PRINTF("ERROR %u: %s\n", coap_error_code, coap_error_message);
coap_clear_transaction(transaction); coap_clear_transaction(transaction);
@ -269,8 +276,13 @@ coap_receive(void)
{ {
coap_error_code = INTERNAL_SERVER_ERROR_5_00; coap_error_code = INTERNAL_SERVER_ERROR_5_00;
} }
if (coap_error_code == PING_RESPONSE)
{
coap_error_code = 0;
reply_type = COAP_TYPE_RST;
}
/* Reuse input buffer for error message. */ /* Reuse input buffer for error message. */
coap_init_message(message, COAP_TYPE_ACK, coap_error_code, message->mid); coap_init_message(message, reply_type, coap_error_code, message->mid);
coap_set_payload(message, coap_error_message, strlen(coap_error_message)); coap_set_payload(message, coap_error_message, strlen(coap_error_message));
coap_send_message(&UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport, uip_appdata, coap_serialize_message(message, uip_appdata)); coap_send_message(&UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport, uip_appdata, coap_serialize_message(message, uip_appdata));
} }

View file

@ -153,7 +153,8 @@ typedef enum {
PACKET_SERIALIZATION_ERROR, PACKET_SERIALIZATION_ERROR,
/* Erbium hooks */ /* Erbium hooks */
MANUAL_RESPONSE MANUAL_RESPONSE,
PING_RESPONSE
} coap_status_t; } coap_status_t;