OpenWSN Firmware
opencoap.h
Go to the documentation of this file.
1 #ifndef __OPENCOAP_H
2 #define __OPENCOAP_H
3 
11 #include "opentimers.h"
12 
13 //=========================== define ==========================================
14 
15 // IPv6 addresses of servers on the Internet
16 static const uint8_t ipAddr_ipsoRD[] = {0x26, 0x07, 0xf7, 0x40, 0x00, 0x00, 0x00, 0x3f, \
17  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x29};
18 static const uint8_t ipAddr_motesEecs[] = {0x20, 0x01, 0x04, 0x70, 0x00, 0x66, 0x00, 0x19, \
19  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02};
20 static const uint8_t ipAddr_local[] = {0x26, 0x07, 0xf1, 0x40, 0x04, 0x00, 0x10, 0x36, \
21  0x4d, 0xcd, 0xab, 0x54, 0x81, 0x99, 0xc1, 0xf7};
22 
23 static const uint8_t ipAddr_motedata[] = {0x20, 0x01, 0x04, 0x70, 0x00, 0x66, 0x00, 0x17, \
24  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02};
25 
27 #define MAX_COAP_OPTIONS 10 //3 before but we want gets with more options
28 
29 // This value may be reduced as a memory optimization, but would invalidate spec compliance
30 #define COAP_MAX_TKL 8
31 
32 #define COAP_PAYLOAD_MARKER 0xFF
33 
34 #define COAP_VERSION 1
35 
36 typedef enum {
41 } coap_type_t;
42 
43 typedef enum {
45  // request
50  // response
51  // - OK
57  // - not OK
67  // - error
74 } coap_code_t;
75 
76 typedef enum {
93 
94 typedef enum {
102 
103 //=========================== typedef =========================================
104 
105 typedef struct {
106  uint8_t Ver;
108  uint8_t TKL;
110  uint16_t messageID;
111  uint8_t token[COAP_MAX_TKL];
113 
114 typedef struct {
116  uint8_t length;
117  uint8_t* pValue;
119 
121  coap_header_iht* coap_header,
122  coap_option_iht* coap_options);
124  owerror_t error);
125 
127 
129  uint8_t path0len;
130  uint8_t* path0val;
131  uint8_t path1len;
132  uint8_t* path1val;
133  uint8_t componentID;
134  uint16_t messageID;
135  uint8_t token; //should be 8bytes
139 };
140 
141 //=========================== module variables ================================
142 
143 typedef struct {
146  uint8_t delayCounter;
147  uint16_t messageID;
149 
150 //=========================== prototypes ======================================
151 
152 // from stack
153 void opencoap_init(void);
156 
157 // from CoAP resources
161  OpenQueueEntry_t* msg,
162  coap_type_t type,
163  coap_code_t code,
164  uint8_t numOptions,
165  coap_resource_desc_t* descSender
166 );
167 
173 #endif
owerror_t opencoap_send(OpenQueueEntry_t *msg, coap_type_t type, coap_code_t code, uint8_t TKL, coap_resource_desc_t *descSender)
Send a CoAP request.
Definition: opencoap.c:413
callbackRx_cbt callbackRx
Definition: opencoap.h:136
uint8_t path0len
Definition: opencoap.h:129
Definition: opencoap.h:46
Definition: opencoap.h:69
Definition: opencoap.h:72
Definition: opencoap.h:37
Definition: opencoap.h:53
Definition: opencoap.h:99
Definition: opencoap.h:49
owerror_t(* callbackRx_cbt)(OpenQueueEntry_t *msg, coap_header_iht *coap_header, coap_option_iht *coap_options)
Definition: opencoap.h:120
Definition: opencoap.h:100
uint8_t Ver
Definition: opencoap.h:106
coap_resource_desc_t * next
Definition: opencoap.h:138
uint8_t token
Definition: opencoap.h:135
Definition: opencoap.h:85
Definition: opencoap.h:143
Definition: opencoap.h:78
Definition: opencoap.h:114
Definition: opencoap.h:128
coap_code_t Code
Definition: opencoap.h:109
void(* callbackSendDone_cbt)(OpenQueueEntry_t *msg, owerror_t error)
Definition: opencoap.h:123
Definition: opencoap.h:95
Definition: opencoap.h:65
Definition: opencoap.h:86
Definition: opencoap.h:54
uint8_t owerror_t
Definition: openwsn.h:265
callbackSendDone_cbt callbackSendDone
Definition: opencoap.h:137
uint8_t * path0val
Definition: opencoap.h:130
Definition: opencoap.h:80
void opencoap_register(coap_resource_desc_t *desc)
Register a new CoAP resource.
Definition: opencoap.c:373
void opencoap_receive(OpenQueueEntry_t *msg)
Indicate a CoAP messages was received.
Definition: opencoap.c:47
Definition: opencoap.h:40
Definition: opencoap.h:56
Definition: opencoap.h:88
void opencoap_writeLinks(OpenQueueEntry_t *msg)
Writes the links to all the resources on this mote into the message.
Definition: opencoap.c:321
bool busySending
Definition: opencoap.h:145
Definition: opencoap.h:98
Definition: opencoap.h:81
Definition: opencoap.h:105
coap_option_t
Definition: opencoap.h:76
coap_type_t
Definition: opencoap.h:36
Definition: opencoap.h:97
Definition: opencoap.h:60
uint8_t * path1val
Definition: opencoap.h:132
Definition: opencoap.h:66
Definition: opencoap.h:71
Definition: opencoap.h:64
Definition: opencoap.h:55
uint8_t length
Definition: opencoap.h:116
uint8_t delayCounter
Definition: opencoap.h:146
Definition: opencoap.h:96
coap_media_type_t
Definition: opencoap.h:94
uint16_t messageID
Definition: opencoap.h:110
void opencoap_sendDone(OpenQueueEntry_t *msg, owerror_t error)
Indicates that the CoAP response has been sent.
Definition: opencoap.c:277
Definition: opencoap.h:58
Definition: opencoap.h:61
Definition: opencoap.h:47
Definition: opencoap.h:84
Definition: opencoap.h:90
Definition: opencoap.h:59
Definition: opencoap.h:91
uint8_t TKL
Definition: opencoap.h:108
void opencoap_init()
Initialize this module.
Definition: opencoap.c:29
Definition: opencoap.h:82
coap_type_t T
Definition: opencoap.h:107
Definition: opencoap.h:77
coap_resource_desc_t * resources
Definition: opencoap.h:144
uint16_t messageID
Definition: opencoap.h:147
Definition: opencoap.h:52
Definition: opencoap.h:63
uint16_t messageID
Definition: opencoap.h:134
Definition: opencoap.h:62
uint8_t componentID
Definition: opencoap.h:133
Definition: opencoap.h:89
Definition: openwsn.h:288
Definition: opencoap.h:73
#define COAP_MAX_TKL
Definition: opencoap.h:30
uint8_t * pValue
Definition: opencoap.h:117
Definition: opencoap.h:38
Definition: opencoap.h:87
Definition: opencoap.h:39
Definition: opencoap.h:70
Definition: opencoap.h:68
coap_code_t
Definition: opencoap.h:43
Definition: opencoap.h:48
Definition: opencoap.h:79
Definition: opencoap.h:83
uint8_t path1len
Definition: opencoap.h:131
Definition: opencoap.h:44
coap_option_t type
Definition: opencoap.h:115