|
@@ -18,13 +18,15 @@ extern "C" {
|
|
|
|
|
|
#define COAP_RESPONSE_CLASS(C) (((C) >> 5) & 0xFF)
|
|
|
|
|
|
-// http://tools.ietf.org/html/draft-ietf-core-coap-18#section-3
|
|
|
+//http://tools.ietf.org/html/rfc7252#section-3
|
|
|
typedef struct
|
|
|
{
|
|
|
- uint8_t ver;
|
|
|
- uint8_t t;
|
|
|
- uint8_t tkl;
|
|
|
- uint8_t code;
|
|
|
+ uint8_t ver; /* CoAP version number */
|
|
|
+ uint8_t t; /* CoAP Message Type */
|
|
|
+ uint8_t tkl; /* Token length: indicates length of the Token field */
|
|
|
+ uint8_t code; /* CoAP status code. Can be request (0.xx), success reponse (2.xx),
|
|
|
+ * client error response (4.xx), or rever error response (5.xx)
|
|
|
+ * For possible values, see http://tools.ietf.org/html/rfc7252#section-12.1 */
|
|
|
uint8_t id[2];
|
|
|
} coap_header_t;
|
|
|
|
|
@@ -42,23 +44,24 @@ typedef struct
|
|
|
|
|
|
typedef struct
|
|
|
{
|
|
|
- uint8_t num;
|
|
|
- coap_buffer_t buf;
|
|
|
+ uint8_t num; /* Option number. See http://tools.ietf.org/html/rfc7252#section-5.10 */
|
|
|
+ coap_buffer_t buf; /* Option value */
|
|
|
} coap_option_t;
|
|
|
|
|
|
typedef struct
|
|
|
{
|
|
|
- coap_header_t hdr;
|
|
|
- coap_buffer_t tok;
|
|
|
- uint8_t numopts;
|
|
|
- coap_option_t opts[MAXOPT];
|
|
|
- coap_buffer_t payload;
|
|
|
- coap_rw_buffer_t scratch; // scratch->p = malloc(...) , and free it when done.
|
|
|
+ coap_header_t hdr; /* Header of the packet */
|
|
|
+ coap_buffer_t tok; /* Token value, size as specified by hdr.tkl */
|
|
|
+ uint8_t numopts; /* Number of options */
|
|
|
+ coap_option_t opts[MAXOPT]; /* Options of the packet. For possible entries see
|
|
|
+ * http://tools.ietf.org/html/rfc7252#section-5.10 */
|
|
|
+ coap_buffer_t payload; /* Payload carried by the packet */
|
|
|
+ coap_rw_buffer_t content; // content->p = malloc(...) , and free it when done.
|
|
|
} coap_packet_t;
|
|
|
|
|
|
/////////////////////////////////////////
|
|
|
|
|
|
-//http://tools.ietf.org/html/draft-ietf-core-coap-18#section-12.2
|
|
|
+//http://tools.ietf.org/html/rfc7252#section-12.2
|
|
|
typedef enum
|
|
|
{
|
|
|
COAP_OPTION_IF_MATCH = 1,
|
|
@@ -78,7 +81,7 @@ typedef enum
|
|
|
COAP_OPTION_PROXY_SCHEME = 39
|
|
|
} coap_option_num_t;
|
|
|
|
|
|
-//http://tools.ietf.org/html/draft-ietf-core-coap-18#section-12.1.1
|
|
|
+//http://tools.ietf.org/html/rfc7252#section-12.1.1
|
|
|
typedef enum
|
|
|
{
|
|
|
COAP_METHOD_GET = 1,
|
|
@@ -87,7 +90,7 @@ typedef enum
|
|
|
COAP_METHOD_DELETE = 4
|
|
|
} coap_method_t;
|
|
|
|
|
|
-//http://tools.ietf.org/html/draft-ietf-core-coap-18#section-12.1.1
|
|
|
+//http://tools.ietf.org/html/rfc7252#section-12.1.1
|
|
|
typedef enum
|
|
|
{
|
|
|
COAP_TYPE_CON = 0,
|
|
@@ -96,8 +99,8 @@ typedef enum
|
|
|
COAP_TYPE_RESET = 3
|
|
|
} coap_msgtype_t;
|
|
|
|
|
|
-//http://tools.ietf.org/html/draft-ietf-core-coap-18#section-5.2
|
|
|
-//http://tools.ietf.org/html/draft-ietf-core-coap-18#section-12.1.2
|
|
|
+//http://tools.ietf.org/html/rfc7252#section-5.2
|
|
|
+//http://tools.ietf.org/html/rfc7252#section-12.1.2
|
|
|
#define MAKE_RSPCODE(clas, det) ((clas << 5) | (det))
|
|
|
typedef enum
|
|
|
{
|
|
@@ -107,7 +110,7 @@ typedef enum
|
|
|
COAP_RSPCODE_CHANGED = MAKE_RSPCODE(2, 4)
|
|
|
} coap_responsecode_t;
|
|
|
|
|
|
-//http://tools.ietf.org/html/draft-ietf-core-coap-18#section-12.3
|
|
|
+//http://tools.ietf.org/html/rfc7252#section-12.3
|
|
|
typedef enum
|
|
|
{
|
|
|
COAP_CONTENTTYPE_NONE = -1, // bodge to allow us not to send option block
|
|
@@ -155,15 +158,21 @@ struct coap_luser_entry{
|
|
|
coap_luser_entry *next;
|
|
|
};
|
|
|
|
|
|
-struct coap_endpoint_t
|
|
|
-{
|
|
|
- coap_method_t method;
|
|
|
- coap_endpoint_func handler;
|
|
|
- const coap_endpoint_path_t *path;
|
|
|
- const char *core_attr;
|
|
|
- coap_luser_entry *user_entry;
|
|
|
+struct coap_endpoint_t{
|
|
|
+ coap_method_t method; /* (i.e. POST, PUT or GET) */
|
|
|
+ coap_endpoint_func handler; /* callback function which handles this
|
|
|
+ * type of endpoint (and calls
|
|
|
+ * coap_make_response() at some point) */
|
|
|
+ const coap_endpoint_path_t *path; /* path towards a resource (i.e. foo/bar/) */
|
|
|
+ const char *core_attr; /* the 'ct' attribute, as defined in RFC7252, section 7.2.1.:
|
|
|
+ * "The Content-Format code "ct" attribute
|
|
|
+ * provides a hint about the
|
|
|
+ * Content-Formats this resource returns."
|
|
|
+ * (Section 12.3. lists possible ct values.) */
|
|
|
+ coap_luser_entry *user_entry;
|
|
|
};
|
|
|
|
|
|
+
|
|
|
///////////////////////
|
|
|
void coap_dumpPacket(coap_packet_t *pkt);
|
|
|
int coap_parse(coap_packet_t *pkt, const uint8_t *buf, size_t buflen);
|
|
@@ -173,11 +182,11 @@ int coap_build(uint8_t *buf, size_t *buflen, const coap_packet_t *pkt);
|
|
|
void coap_dump(const uint8_t *buf, size_t buflen, bool bare);
|
|
|
int coap_make_response(coap_rw_buffer_t *scratch, coap_packet_t *pkt, const uint8_t *content, size_t content_len, uint8_t msgid_hi, uint8_t msgid_lo, const coap_buffer_t* tok, coap_responsecode_t rspcode, coap_content_type_t content_type);
|
|
|
int coap_handle_req(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt);
|
|
|
-void coap_option_nibble(uint16_t value, uint8_t *nibble);
|
|
|
+void coap_option_nibble(uint32_t value, uint8_t *nibble);
|
|
|
void coap_setup(void);
|
|
|
void endpoint_setup(void);
|
|
|
|
|
|
-int coap_buildOptionHeader(unsigned short optDelta, size_t length, uint8_t *buf, size_t buflen);
|
|
|
+int coap_buildOptionHeader(uint32_t optDelta, size_t length, uint8_t *buf, size_t buflen);
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
}
|