-
Notifications
You must be signed in to change notification settings - Fork 0
/
coap_client.c
61 lines (44 loc) · 1.24 KB
/
coap_client.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* coap_client.c
*
* Created on: Dec 3, 2013
* Author: poppe
*/
#include "coap.h"
#include "stdint.h"
void coap_send_nonConfirmable(uint8_t *data, size_t len, coap_methods_t method)
{
}
void coap_simpleReply(coap_pkt_t *pkt, uint8_t code)
{
coap_pkt_hdr_t header;
header.bits.ver = pkt->header.bits.ver;
header.bits.t = COAP_ACK;
header.bits.tkl = pkt->header.bits.tkl;
header.code = code;
header.msgID = pkt->header.msgID;
coapd_sendto((uint8_t *)&header, 4, pkt->ip_addr, pkt->port);
}
void coap_reply(coap_pkt_t *pkt, uint8_t *data, size_t len, uint8_t code, coap_option_t *opts)
{
RT_ASSERT(pkt);
coap_pkt_t outPkt;
memset(&outPkt, 0, sizeof(coap_pkt_t));
outPkt.header.bits.ver = pkt->header.bits.ver;
outPkt.header.bits.t = COAP_ACK;
outPkt.header.bits.tkl = pkt->header.bits.tkl;
outPkt.header.code = code;
outPkt.header.msgID = pkt->header.msgID;
outPkt.ip_addr = pkt->ip_addr;
outPkt.port = pkt->port;
outPkt.options = opts;
if(outPkt.header.bits.tkl)
{
size_t numTks = (size_t)pkt->header.bits.tkl;
memcpy(outPkt.token, pkt->token, numTks);
}
outPkt.payload.data = data;
outPkt.payload.len = len;
LWIP_DEBUGF(COAP_DEBUG, ("Sending Coap Code: %i with data len %i\n", code, len));
coap_sendPkt(&outPkt);
}