Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
smlng committed Jun 23, 2016
1 parent 9b93e85 commit 7c694c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion coap.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ static const coap_option_t *_find_options(const coap_packet_t *pkt,
uint8_t *count);
static void _option_nibble(const uint32_t value, uint8_t *nibble);

static uint16_t seqno = 0;
/*
* options are always stored consecutively,
* so can return a block with same option num
Expand Down Expand Up @@ -127,6 +128,7 @@ int coap_build(const coap_packet_t *pkt, uint8_t *buf, size_t *buflen)
return COAP_SUCCESS;
}
int coap_make_request(const uint16_t msgid, const coap_buffer_t* tok,
const coap_msgtype_t msgt,
const coap_resource_t *resource,
const uint8_t *content, const size_t content_len,
coap_packet_t *outpkt)
Expand All @@ -137,7 +139,7 @@ int coap_make_request(const uint16_t msgid, const coap_buffer_t* tok,
return COAP_ERR_BUFFER_TOO_SMALL;
// init request header
outpkt->hdr.ver = 0x01;
outpkt->hdr.t = COAP_TYPE_CON;
outpkt->hdr.t = msgt;
outpkt->hdr.tkl = 0;
outpkt->hdr.code = resource->method;
outpkt->hdr.id = msgid;
Expand Down Expand Up @@ -170,6 +172,13 @@ int coap_make_request(const uint16_t msgid, const coap_buffer_t* tok,
return COAP_SUCCESS;
}

int coap_put_request(const coap_resource_t *resource, const bool confirm,
const uint8_t *content, const size_t content_len,
coap_packet_t *outpkt)
{
return coap_make_request(++seqno, NULL, (confirm ? COAP_TYPE_CON: COAP_TYPE_NONCON), resource, content, content_len, outpkt);
}

int coap_make_response(const uint16_t msgid, const coap_buffer_t* tok,
const coap_responsecode_t rspcode,
const uint8_t *content_type,
Expand Down
5 changes: 5 additions & 0 deletions coap.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extern "C" {
#include <stddef.h>

#define COAP_MAX_OPTIONS 8
#define COAP_MAX_TOKLEN 8

//http://tools.ietf.org/html/rfc7252#section-3
typedef struct coap_header
Expand Down Expand Up @@ -225,9 +226,13 @@ inline int16_t COAP_GET_CONTENTTYPE(const uint8_t *buf, const size_t buflen)
int coap_parse(const uint8_t *buf, const size_t buflen, coap_packet_t *pkt);
int coap_build(const coap_packet_t *pkt, uint8_t *buf, size_t *buflen);
int coap_make_request(const uint16_t msgid, const coap_buffer_t* tok,
const coap_msgtype_t msgt,
const coap_resource_t *resource,
const uint8_t *content, const size_t content_len,
coap_packet_t *outpkt);
int coap_put_request(const coap_resource_t *resource, const bool confirm,
const uint8_t *content, const size_t content_len,
coap_packet_t *outpkt);
int coap_make_response(const uint16_t msgid, const coap_buffer_t* tok,
const coap_responsecode_t rspcode,
const uint8_t *content_type,
Expand Down

0 comments on commit 7c694c9

Please sign in to comment.