13 #if defined(HAVE_ASSERT_H) && !defined(assert)
26 if (pdu && pdu->
hdr &&
28 < (
unsigned char *)pdu->
hdr + pdu->
length)) {
42 assert(opt); assert(result);
44 #define ADVANCE_OPT(o,e,step) if ((e) < step) { \
45 debug("cannot advance opt past end\n"); \
49 (o) = ((unsigned char *)(o)) + step; \
55 result->
delta = (*opt & 0xf0) >> 4;
56 result->
length = *opt & 0x0f;
58 switch(result->
delta) {
61 debug(
"ignored reserved option delta 15\n");
68 result->
delta = ((*opt & 0xff) << 8) + 269;
69 if (result->
delta < 269) {
70 debug(
"delta too large\n");
76 result->
delta += *opt & 0xff;
85 debug(
"found reserved option length 15\n");
92 result->
length = ((*opt & 0xff) << 8) + 269;
96 result->
length += *opt & 0xff;
106 result->
value = (
unsigned char *)opt;
107 if (length < result->length) {
108 debug(
"invalid option length\n");
114 return (opt + result->
length) - opt_start;
178 assert(optsize <= oi->length);
223 n = (*opt++ & 0xf0) >> 4;
227 warn(
"coap_opt_delta: illegal option delta\n");
236 n = ((*opt++ & 0xff) << 8) + 269;
250 unsigned short length;
252 length = *opt & 0x0f;
253 switch (*opt & 0xf0) {
255 debug(
"illegal option delta\n");
269 debug(
"illegal option length\n");
272 length = (*opt++ << 8) + 269;
287 switch (*opt & 0xf0) {
289 debug(
"illegal option delta\n");
301 switch (*opt & 0x0f) {
303 debug(
"illegal option length\n");
315 return (
unsigned char *)opt + ofs;
328 unsigned short delta,
size_t length) {
338 }
else if (delta < 270) {
340 debug(
"insufficient space to encode option delta %d", delta);
345 opt[++skip] = delta - 13;
348 debug(
"insufficient space to encode option delta %d", delta);
353 opt[++skip] = ((delta - 269) >> 8) & 0xff;
354 opt[++skip] = (delta - 269) & 0xff;
358 opt[0] |= length & 0x0f;
359 }
else if (length < 270) {
360 if (maxlen < skip + 1) {
361 debug(
"insufficient space to encode option length %d", length);
366 opt[++skip] = length - 13;
368 if (maxlen < skip + 2) {
369 debug(
"insufficient space to encode option delta %d", delta);
374 opt[++skip] = ((length - 269) >> 8) & 0xff;
375 opt[++skip] = (length - 269) & 0xff;
383 const unsigned char *val,
size_t length) {
390 debug(
"coap_opt_encode: cannot set option header\n");
397 if (maxlen < length) {
398 debug(
"coap_opt_encode: option too large for buffer\n");
403 memcpy(opt, val, length);