Merge pull request #276 from mkovatsc/er-coap-13

Erbium (Er) fixes and updates
This commit is contained in:
Nicolas Tsiftes 2013-06-24 01:44:23 -07:00
commit f606322ae0
24 changed files with 86 additions and 270 deletions

View file

@ -39,6 +39,7 @@
#ifndef COAP_OBSERVING_H_
#define COAP_OBSERVING_H_
#include "sys/stimer.h"
#include "er-coap-03.h"
#include "er-coap-03-transactions.h"

View file

@ -85,8 +85,8 @@
#define COAP_MAX_ATTEMPTS 4
#endif /* COAP_MAX_ATTEMPTS */
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN])
#define SET_OPTION(packet, opt) ((packet)->options |= 1<<opt)
#define IS_OPTION(packet, opt) ((packet)->options & 1<<opt)

View file

@ -39,6 +39,7 @@
#ifndef COAP_OBSERVING_H_
#define COAP_OBSERVING_H_
#include "sys/stimer.h"
#include "er-coap-07.h"
#include "er-coap-07-transactions.h"

View file

@ -87,8 +87,8 @@
#define COAP_MAX_ATTEMPTS 4
#endif /* COAP_MAX_ATTEMPTS */
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN])
#define SET_OPTION(packet, opt) ((packet)->options |= 1L<<opt)
#define IS_OPTION(packet, opt) ((packet)->options & 1L<<opt)

View file

@ -39,6 +39,7 @@
#ifndef COAP_OBSERVING_H_
#define COAP_OBSERVING_H_
#include "sys/stimer.h"
#include "er-coap-12.h"
#include "er-coap-12-transactions.h"

View file

@ -92,8 +92,8 @@
#define COAP_MAX_ATTEMPTS 4
#endif /* COAP_MAX_ATTEMPTS */
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN])
/* Bitmap for set options */
enum { OPTION_MAP_SIZE = sizeof(uint8_t) * 8 };

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -220,9 +220,14 @@ coap_receive(void)
else
{
/* Responses */
if (message->type==COAP_TYPE_ACK)
if (message->type==COAP_TYPE_CON && message->code==0)
{
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");
}
else if (message->type==COAP_TYPE_RST)
@ -261,6 +266,8 @@ coap_receive(void)
}
else
{
coap_message_type_t reply_type = COAP_TYPE_ACK;
PRINTF("ERROR %u: %s\n", coap_error_code, coap_error_message);
coap_clear_transaction(transaction);
@ -269,8 +276,13 @@ coap_receive(void)
{
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. */
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_send_message(&UIP_IP_BUF->srcipaddr, UIP_UDP_BUF->srcport, uip_appdata, coap_serialize_message(message, uip_appdata));
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -39,6 +39,7 @@
#ifndef COAP_OBSERVING_H_
#define COAP_OBSERVING_H_
#include "sys/stimer.h"
#include "er-coap-13.h"
#include "er-coap-13-transactions.h"

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -90,7 +90,7 @@ coap_parse_int_option(uint8_t *bytes, size_t length)
while (i<length)
{
var <<= 8;
var |= 0xFF & bytes[i++];
var |= bytes[i++];
}
return var;
}
@ -117,7 +117,7 @@ static
size_t
coap_set_option_header(unsigned int delta, size_t length, uint8_t *buffer)
{
size_t written = 1;
size_t written = 0;
buffer[0] = coap_option_nibble(delta)<<4 | coap_option_nibble(length);
@ -127,19 +127,19 @@ coap_set_option_header(unsigned int delta, size_t length, uint8_t *buffer)
{
if (*x>268)
{
buffer[written++] = (*x-269)>>8;
buffer[written++] = (*x-269);
buffer[++written] = (*x-269)>>8;
buffer[++written] = (*x-269);
}
else if (delta>12)
else if (*x>12)
{
buffer[written++] = (*x-13);
buffer[++written] = (*x-13);
}
}
while (x!=&length && (x=&length));
PRINTF("WRITTEN %u B opt header\n", written);
return written;
return ++written;
}
/*-----------------------------------------------------------------------------------*/
static
@ -148,14 +148,19 @@ coap_serialize_int_option(unsigned int number, unsigned int current_number, uint
{
size_t i = 0;
if (0xFF000000 & value) buffer[++i] = (uint8_t) (0xFF & value>>24);
if (0xFFFF0000 & value) buffer[++i] = (uint8_t) (0xFF & value>>16);
if (0xFFFFFF00 & value) buffer[++i] = (uint8_t) (0xFF & value>>8);
if (0xFFFFFFFF & value) buffer[++i] = (uint8_t) (0xFF & value);
if (0xFF000000 & value) ++i;
if (0xFFFF0000 & value) ++i;
if (0xFFFFFF00 & value) ++i;
if (0xFFFFFFFF & value) ++i;
PRINTF("OPTION %u (delta %u, len %u)\n", number, number - current_number, i);
i += coap_set_option_header(number - current_number, i, buffer);
i = coap_set_option_header(number - current_number, i, buffer);
if (0xFF000000 & value) buffer[i++] = (uint8_t) (value>>24);
if (0xFFFF0000 & value) buffer[i++] = (uint8_t) (value>>16);
if (0xFFFFFF00 & value) buffer[i++] = (uint8_t) (value>>8);
if (0xFFFFFFFF & value) buffer[i++] = (uint8_t) (value);
return i;
}
@ -319,8 +324,8 @@ coap_serialize_message(void *packet, uint8_t *buffer)
coap_pkt->buffer[0] |= COAP_HEADER_TYPE_MASK & (coap_pkt->type)<<COAP_HEADER_TYPE_POSITION;
coap_pkt->buffer[0] |= COAP_HEADER_TOKEN_LEN_MASK & (coap_pkt->token_len)<<COAP_HEADER_TOKEN_LEN_POSITION;
coap_pkt->buffer[1] = coap_pkt->code;
coap_pkt->buffer[2] = 0xFF & (coap_pkt->mid)>>8;
coap_pkt->buffer[3] = 0xFF & coap_pkt->mid;
coap_pkt->buffer[2] = (uint8_t) ((coap_pkt->mid)>>8);
coap_pkt->buffer[3] = (uint8_t) (coap_pkt->mid);
/* set Token */
PRINTF("Token (len %u)", coap_pkt->token_len);
@ -1008,7 +1013,7 @@ coap_set_header_observe(void *packet, uint32_t observe)
{
coap_packet_t *const coap_pkt = (coap_packet_t *) packet;
coap_pkt->observe = observe;
coap_pkt->observe = 0x00FFFFFF & observe;
SET_OPTION(coap_pkt, COAP_OPTION_OBSERVE);
return 1;
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Institute for Pervasive Computing, ETH Zurich
* Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -36,8 +36,8 @@
* Matthias Kovatsch <kovatsch@inf.ethz.ch>
*/
#ifndef COAP_12_H_
#define COAP_12_H_
#ifndef COAP_13_H_
#define COAP_13_H_
#include <stddef.h> /* for size_t */
#include "contiki-net.h"
@ -92,8 +92,8 @@
#define COAP_MAX_ATTEMPTS 4
#endif /* COAP_MAX_ATTEMPTS */
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[uip_l2_l3_hdr_len])
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
#define UIP_UDP_BUF ((struct uip_udp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN])
/* Bitmap for set options */
enum { OPTION_MAP_SIZE = sizeof(uint8_t) * 8 };
@ -153,7 +153,8 @@ typedef enum {
PACKET_SERIALIZATION_ERROR,
/* Erbium hooks */
MANUAL_RESPONSE
MANUAL_RESPONSE,
PING_RESPONSE
} coap_status_t;
@ -379,4 +380,4 @@ int coap_set_header_size(void *packet, uint32_t size);
int coap_get_payload(void *packet, const uint8_t **payload);
int coap_set_payload(void *packet, const void *payload, size_t length);
#endif /* COAP_12_H_ */
#endif /* COAP_13_H_ */