-
Notifications
You must be signed in to change notification settings - Fork 0
/
coap_msg.h
189 lines (158 loc) · 3.34 KB
/
coap_msg.h
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
* coap_msg.h
*
* Created on: Aug 1, 2013
* Author: poppe
*/
#ifndef COAP_MSG_H_
#define COAP_MSG_H_
#include "sll.h"
#include "lwip/ip_addr.h"
struct coap_pkt_hdr_s {
union {
struct {
uint8_t tkl:4;
uint8_t t:2;
uint8_t ver:2;
}__attribute__( ( __packed__ ) )bits;
uint8_t firstByte;
}__attribute__( ( __packed__ ) );
union {
struct {
uint8_t code:5;
uint8_t type:3;
}__attribute__( ( __packed__ ) )code_bits;
uint8_t code;
}__attribute__( ( __packed__ ) );
uint16_t msgID;
}__attribute__( ( __packed__ ) );
/**
* Forward Declarations
*/
struct coap_pkt;
struct coap_resource;
struct coap_uriPath;
struct coap_option;
struct coap_attribute;
typedef struct coap_pkt_s coap_pkt_t;
typedef struct coap_resource coap_resource_t;
typedef struct coap_uriPath coap_uriPath_t;
typedef struct coap_option coap_option_t;
typedef struct coap_attribute coap_attribute_t;
typedef void (*coap_resourceCB)(coap_pkt_t *, coap_resource_t *);
typedef struct coap_data {
uint8_t * data;
uint32_t len;
}coap_data_t;
/**
* Based of RFC 6690...
*/
struct coap_attribute {
coap_attribute_t *next;
char *key;
char *value;
};
typedef struct coap_pkt_hdr_s coap_pkt_hdr_t;
struct coap_option {
coap_option_t *next;
uint16_t num;
uint8_t len;
uint8_t format;
uint8_t value[];
};
struct coap_pkt_s {
coap_pkt_hdr_t header;
uint8_t token[9];
coap_option_t * options;
coap_data_t payload;
coap_block_t block;
ip_addr_t * ip_addr;
uint16_t port;
};
enum coap_option_format_e {
coap_opt_opaque,
coap_opt_string,
coap_opt_uint,
coap_opt_none,
};
struct coap_uriPath {
coap_uriPath_t *next;
char * path;
uint32_t hash;
uint32_t size;
};
struct coap_resource {
void * next;
char * fullUri;
uint32_t fullUriHash;
sll_list_t pathList;
sll_list_t attrList;
uint32_t flags;
coap_resourceCB getCB;
coap_resourceCB postCB;
coap_resourceCB deleteCB;
coap_resourceCB putCB;
};
enum coap_options {
coap_If_Match = 1,
coap_Uri_host = 3,
coap_ETAG = 4,
coap_If_None_Match = 5,
coap_observe = 6, //draft-ietf-core-observe-11
coap_Uri_Port = 7,
coap_location_path = 8,
coap_Uri_path = 11,
coap_content_format = 12,
coap_max_age = 14,
coap_uri_query = 15,
coap_accept = 17,
coap_location_query = 20,
coap_block2 = 23, //draft-ietf-core-block-14
coap_block1 = 27, //draft-ietf-core-block-14
coap_size2 = 28, //draft-ietf-core-block-14
coap_proxy_uri = 35,
coap_proxy_scheme = 39,
coap_size1 = 60, //draft-ietf-core-block-14
};
typedef enum coap_methods {
coap_get,
coap_post,
coap_put,
coap_delete,
}coap_methods_t;
enum coap_mime_types {
mime_text_plain = 0,
mime_application_link_format = 40,
mime_application_xml = 41,
mime_application_octet_stream = 42,
mime_application_exi = 47,
mime_application_json = 50,
};
enum coap_respSuccess {
created = 1,
deleted = 2,
valid = 3,
changed = 4,
content = 5,
};
enum coap_respClientErr {
bad_request = 0,
unauthorized = 1,
bad_option = 2,
forbidden = 3,
not_found = 4,
method_not_allowed = 5,
not_acceptable = 6,
precondition_failed = 12,
enitiy_to_large = 13,
unsupported_format = 15,
};
enum coap_respServerErr {
internal_err = 0,
not_implemented = 1,
bad_gateway = 2,
service_unavail = 3,
gateway_timeout = 4,
proxy_not_supported = 5,
};
#endif /* COAP_MSG_H_ */