Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
84bc8490
Commit
84bc8490
authored
7 years ago
by
Kaspar Schleiser
Browse files
Options
Downloads
Patches
Plain Diff
sys: net: nanocoap: ignore Uri-Host option
parent
7a636cb8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sys/net/application_layer/nanocoap/nanocoap.c
+42
-32
42 additions, 32 deletions
sys/net/application_layer/nanocoap/nanocoap.c
with
42 additions
and
32 deletions
sys/net/application_layer/nanocoap/nanocoap.c
+
42
−
32
View file @
84bc8490
...
@@ -48,6 +48,7 @@ int coap_parse(coap_pkt_t *pkt, uint8_t *buf, size_t len)
...
@@ -48,6 +48,7 @@ int coap_parse(coap_pkt_t *pkt, uint8_t *buf, size_t len)
{
{
uint8_t
*
urlpos
=
pkt
->
url
;
uint8_t
*
urlpos
=
pkt
->
url
;
coap_hdr_t
*
hdr
=
(
coap_hdr_t
*
)
buf
;
coap_hdr_t
*
hdr
=
(
coap_hdr_t
*
)
buf
;
pkt
->
hdr
=
hdr
;
pkt
->
hdr
=
hdr
;
uint8_t
*
pkt_pos
=
hdr
->
data
;
uint8_t
*
pkt_pos
=
hdr
->
data
;
...
@@ -61,7 +62,8 @@ int coap_parse(coap_pkt_t *pkt, uint8_t *buf, size_t len)
...
@@ -61,7 +62,8 @@ int coap_parse(coap_pkt_t *pkt, uint8_t *buf, size_t len)
if
(
coap_get_token_len
(
pkt
))
{
if
(
coap_get_token_len
(
pkt
))
{
pkt
->
token
=
pkt_pos
;
pkt
->
token
=
pkt_pos
;
pkt_pos
+=
coap_get_token_len
(
pkt
);
pkt_pos
+=
coap_get_token_len
(
pkt
);
}
else
{
}
else
{
pkt
->
token
=
NULL
;
pkt
->
token
=
NULL
;
}
}
...
@@ -90,6 +92,9 @@ int coap_parse(coap_pkt_t *pkt, uint8_t *buf, size_t len)
...
@@ -90,6 +92,9 @@ int coap_parse(coap_pkt_t *pkt, uint8_t *buf, size_t len)
DEBUG
(
"option nr=%i len=%i
\n
"
,
option_nr
,
option_len
);
DEBUG
(
"option nr=%i len=%i
\n
"
,
option_nr
,
option_len
);
switch
(
option_nr
)
{
switch
(
option_nr
)
{
case
COAP_OPT_URI_HOST
:
DEBUG
(
"nanocoap: ignoring Uri-Host option!
\n
"
);
break
;
case
COAP_OPT_URI_PATH
:
case
COAP_OPT_URI_PATH
:
*
urlpos
++
=
'/'
;
*
urlpos
++
=
'/'
;
memcpy
(
urlpos
,
pkt_pos
,
option_len
);
memcpy
(
urlpos
,
pkt_pos
,
option_len
);
...
@@ -98,9 +103,11 @@ int coap_parse(coap_pkt_t *pkt, uint8_t *buf, size_t len)
...
@@ -98,9 +103,11 @@ int coap_parse(coap_pkt_t *pkt, uint8_t *buf, size_t len)
case
COAP_OPT_CONTENT_FORMAT
:
case
COAP_OPT_CONTENT_FORMAT
:
if
(
option_len
==
0
)
{
if
(
option_len
==
0
)
{
pkt
->
content_type
=
0
;
pkt
->
content_type
=
0
;
}
else
if
(
option_len
==
1
)
{
}
else
if
(
option_len
==
1
)
{
pkt
->
content_type
=
*
pkt_pos
;
pkt
->
content_type
=
*
pkt_pos
;
}
else
if
(
option_len
==
2
)
{
}
else
if
(
option_len
==
2
)
{
memcpy
(
&
pkt
->
content_type
,
pkt_pos
,
2
);
memcpy
(
&
pkt
->
content_type
,
pkt_pos
,
2
);
pkt
->
content_type
=
ntohs
(
pkt
->
content_type
);
pkt
->
content_type
=
ntohs
(
pkt
->
content_type
);
}
}
...
@@ -108,7 +115,8 @@ int coap_parse(coap_pkt_t *pkt, uint8_t *buf, size_t len)
...
@@ -108,7 +115,8 @@ int coap_parse(coap_pkt_t *pkt, uint8_t *buf, size_t len)
case
COAP_OPT_OBSERVE
:
case
COAP_OPT_OBSERVE
:
if
(
option_len
<
4
)
{
if
(
option_len
<
4
)
{
pkt
->
observe_value
=
_decode_uint
(
pkt_pos
,
option_len
);
pkt
->
observe_value
=
_decode_uint
(
pkt_pos
,
option_len
);
}
else
{
}
else
{
DEBUG
(
"nanocoap: discarding packet with invalid option length.
\n
"
);
DEBUG
(
"nanocoap: discarding packet with invalid option length.
\n
"
);
return
-
EBADMSG
;
return
-
EBADMSG
;
}
}
...
@@ -126,9 +134,9 @@ int coap_parse(coap_pkt_t *pkt, uint8_t *buf, size_t len)
...
@@ -126,9 +134,9 @@ int coap_parse(coap_pkt_t *pkt, uint8_t *buf, size_t len)
}
}
DEBUG
(
"coap pkt parsed. code=%u detail=%u payload_len=%u, 0x%02x
\n
"
,
DEBUG
(
"coap pkt parsed. code=%u detail=%u payload_len=%u, 0x%02x
\n
"
,
coap_get_code_class
(
pkt
),
coap_get_code_class
(
pkt
),
coap_get_code_detail
(
pkt
),
coap_get_code_detail
(
pkt
),
pkt
->
payload_len
,
hdr
->
code
);
pkt
->
payload_len
,
hdr
->
code
);
return
0
;
return
0
;
}
}
...
@@ -147,11 +155,11 @@ ssize_t coap_handle_req(coap_pkt_t *pkt, uint8_t *resp_buf, unsigned resp_buf_le
...
@@ -147,11 +155,11 @@ ssize_t coap_handle_req(coap_pkt_t *pkt, uint8_t *resp_buf, unsigned resp_buf_le
unsigned
method_flag
=
coap_method2flag
(
coap_get_code_detail
(
pkt
));
unsigned
method_flag
=
coap_method2flag
(
coap_get_code_detail
(
pkt
));
for
(
unsigned
i
=
0
;
i
<
coap_resources_numof
;
i
++
)
{
for
(
unsigned
i
=
0
;
i
<
coap_resources_numof
;
i
++
)
{
if
(
!
(
coap_resources
[
i
].
methods
&
method_flag
))
{
if
(
!
(
coap_resources
[
i
].
methods
&
method_flag
))
{
continue
;
continue
;
}
}
int
res
=
strcmp
((
char
*
)
pkt
->
url
,
coap_resources
[
i
].
path
);
int
res
=
strcmp
((
char
*
)
pkt
->
url
,
coap_resources
[
i
].
path
);
if
(
res
>
0
)
{
if
(
res
>
0
)
{
continue
;
continue
;
}
}
...
@@ -167,10 +175,10 @@ ssize_t coap_handle_req(coap_pkt_t *pkt, uint8_t *resp_buf, unsigned resp_buf_le
...
@@ -167,10 +175,10 @@ ssize_t coap_handle_req(coap_pkt_t *pkt, uint8_t *resp_buf, unsigned resp_buf_le
}
}
ssize_t
coap_reply_simple
(
coap_pkt_t
*
pkt
,
ssize_t
coap_reply_simple
(
coap_pkt_t
*
pkt
,
unsigned
code
,
unsigned
code
,
uint8_t
*
buf
,
size_t
len
,
uint8_t
*
buf
,
size_t
len
,
unsigned
ct
,
unsigned
ct
,
const
uint8_t
*
payload
,
uint8_t
payload_len
)
const
uint8_t
*
payload
,
uint8_t
payload_len
)
{
{
uint8_t
*
payload_start
=
buf
+
coap_get_total_hdr_len
(
pkt
);
uint8_t
*
payload_start
=
buf
+
coap_get_total_hdr_len
(
pkt
);
uint8_t
*
bufpos
=
payload_start
;
uint8_t
*
bufpos
=
payload_start
;
...
@@ -187,7 +195,7 @@ ssize_t coap_reply_simple(coap_pkt_t *pkt,
...
@@ -187,7 +195,7 @@ ssize_t coap_reply_simple(coap_pkt_t *pkt,
}
}
ssize_t
coap_build_reply
(
coap_pkt_t
*
pkt
,
unsigned
code
,
ssize_t
coap_build_reply
(
coap_pkt_t
*
pkt
,
unsigned
code
,
uint8_t
*
rbuf
,
unsigned
rlen
,
unsigned
payload_len
)
uint8_t
*
rbuf
,
unsigned
rlen
,
unsigned
payload_len
)
{
{
unsigned
tkl
=
coap_get_token_len
(
pkt
);
unsigned
tkl
=
coap_get_token_len
(
pkt
);
unsigned
len
=
sizeof
(
coap_hdr_t
)
+
tkl
;
unsigned
len
=
sizeof
(
coap_hdr_t
)
+
tkl
;
...
@@ -199,9 +207,9 @@ ssize_t coap_build_reply(coap_pkt_t *pkt, unsigned code,
...
@@ -199,9 +207,9 @@ ssize_t coap_build_reply(coap_pkt_t *pkt, unsigned code,
/* if code is COAP_CODE_EMPTY (zero), use RST as type, else RESP */
/* if code is COAP_CODE_EMPTY (zero), use RST as type, else RESP */
unsigned
type
=
code
?
COAP_RESP
:
COAP_RST
;
unsigned
type
=
code
?
COAP_RESP
:
COAP_RST
;
coap_build_hdr
((
coap_hdr_t
*
)
rbuf
,
type
,
pkt
->
token
,
tkl
,
code
,
pkt
->
hdr
->
id
);
coap_build_hdr
((
coap_hdr_t
*
)
rbuf
,
type
,
pkt
->
token
,
tkl
,
code
,
pkt
->
hdr
->
id
);
coap_hdr_set_type
((
coap_hdr_t
*
)
rbuf
,
type
);
coap_hdr_set_type
((
coap_hdr_t
*
)
rbuf
,
type
);
coap_hdr_set_code
((
coap_hdr_t
*
)
rbuf
,
code
);
coap_hdr_set_code
((
coap_hdr_t
*
)
rbuf
,
code
);
len
+=
payload_len
;
len
+=
payload_len
;
...
@@ -230,9 +238,10 @@ static int _decode_value(unsigned val, uint8_t **pkt_pos_ptr, uint8_t *pkt_end)
...
@@ -230,9 +238,10 @@ static int _decode_value(unsigned val, uint8_t **pkt_pos_ptr, uint8_t *pkt_end)
uint8_t
*
pkt_pos
=
*
pkt_pos_ptr
;
uint8_t
*
pkt_pos
=
*
pkt_pos_ptr
;
size_t
left
=
pkt_end
-
pkt_pos
;
size_t
left
=
pkt_end
-
pkt_pos
;
int
res
;
int
res
;
switch
(
val
)
{
switch
(
val
)
{
case
13
:
case
13
:
{
{
/* An 8-bit unsigned integer follows the initial byte and
/* An 8-bit unsigned integer follows the initial byte and
indicates the Option Delta minus 13. */
indicates the Option Delta minus 13. */
if
(
left
<
1
)
{
if
(
left
<
1
)
{
...
@@ -241,9 +250,9 @@ static int _decode_value(unsigned val, uint8_t **pkt_pos_ptr, uint8_t *pkt_end)
...
@@ -241,9 +250,9 @@ static int _decode_value(unsigned val, uint8_t **pkt_pos_ptr, uint8_t *pkt_end)
uint8_t
delta
=
*
pkt_pos
++
;
uint8_t
delta
=
*
pkt_pos
++
;
res
=
delta
+
13
;
res
=
delta
+
13
;
break
;
break
;
}
}
case
14
:
case
14
:
{
{
/* A 16-bit unsigned integer in network byte order follows
/* A 16-bit unsigned integer in network byte order follows
* the initial byte and indicates the Option Delta minus
* the initial byte and indicates the Option Delta minus
* 269. */
* 269. */
...
@@ -251,12 +260,12 @@ static int _decode_value(unsigned val, uint8_t **pkt_pos_ptr, uint8_t *pkt_end)
...
@@ -251,12 +260,12 @@ static int _decode_value(unsigned val, uint8_t **pkt_pos_ptr, uint8_t *pkt_end)
return
-
ENOSPC
;
return
-
ENOSPC
;
}
}
uint16_t
delta
;
uint16_t
delta
;
uint8_t
*
_tmp
=
(
uint8_t
*
)
&
delta
;
uint8_t
*
_tmp
=
(
uint8_t
*
)
&
delta
;
*
_tmp
++=
*
pkt_pos
++
;
*
_tmp
++
=
*
pkt_pos
++
;
*
_tmp
++=
*
pkt_pos
++
;
*
_tmp
++
=
*
pkt_pos
++
;
res
=
ntohs
(
delta
)
+
269
;
res
=
ntohs
(
delta
)
+
269
;
break
;
break
;
}
}
case
15
:
case
15
:
/* Reserved for the Payload Marker. If the field is set to
/* Reserved for the Payload Marker. If the field is set to
* this value but the entire byte is not the payload
* this value but the entire byte is not the payload
...
@@ -277,7 +286,7 @@ static uint32_t _decode_uint(uint8_t *pkt_pos, unsigned nbytes)
...
@@ -277,7 +286,7 @@ static uint32_t _decode_uint(uint8_t *pkt_pos, unsigned nbytes)
uint32_t
res
=
0
;
uint32_t
res
=
0
;
if
(
nbytes
)
{
if
(
nbytes
)
{
memcpy
(((
uint8_t
*
)
&
res
)
+
(
4
-
nbytes
),
pkt_pos
,
nbytes
);
memcpy
(((
uint8_t
*
)
&
res
)
+
(
4
-
nbytes
),
pkt_pos
,
nbytes
);
}
}
return
ntohl
(
res
);
return
ntohl
(
res
);
}
}
...
@@ -314,7 +323,7 @@ size_t coap_put_option(uint8_t *buf, uint16_t lastonum, uint16_t onum, uint8_t *
...
@@ -314,7 +323,7 @@ size_t coap_put_option(uint8_t *buf, uint16_t lastonum, uint16_t onum, uint8_t *
/* write option length to option header: 4 lower bits of header (shift 0) +
/* write option length to option header: 4 lower bits of header (shift 0) +
* 1 or 2 optional bytes depending of the length of the option */
* 1 or 2 optional bytes depending of the length of the option */
n
=
_put_delta_optlen
(
buf
,
n
,
0
,
olen
);
n
=
_put_delta_optlen
(
buf
,
n
,
0
,
olen
);
if
(
olen
)
{
if
(
olen
)
{
memcpy
(
buf
+
n
,
odata
,
olen
);
memcpy
(
buf
+
n
,
odata
,
olen
);
n
+=
olen
;
n
+=
olen
;
}
}
...
@@ -331,7 +340,7 @@ size_t coap_put_option_ct(uint8_t *buf, uint16_t lastonum, uint16_t content_type
...
@@ -331,7 +340,7 @@ size_t coap_put_option_ct(uint8_t *buf, uint16_t lastonum, uint16_t content_type
return
coap_put_option
(
buf
,
lastonum
,
COAP_OPT_CONTENT_FORMAT
,
&
tmp
,
sizeof
(
tmp
));
return
coap_put_option
(
buf
,
lastonum
,
COAP_OPT_CONTENT_FORMAT
,
&
tmp
,
sizeof
(
tmp
));
}
}
else
{
else
{
return
coap_put_option
(
buf
,
lastonum
,
COAP_OPT_CONTENT_FORMAT
,
(
uint8_t
*
)
&
content_type
,
sizeof
(
content_type
));
return
coap_put_option
(
buf
,
lastonum
,
COAP_OPT_CONTENT_FORMAT
,
(
uint8_t
*
)
&
content_type
,
sizeof
(
content_type
));
}
}
}
}
...
@@ -339,17 +348,18 @@ size_t coap_put_option_uri(uint8_t *buf, uint16_t lastonum, const char *uri, uin
...
@@ -339,17 +348,18 @@ size_t coap_put_option_uri(uint8_t *buf, uint16_t lastonum, const char *uri, uin
{
{
char
separator
=
(
optnum
==
COAP_OPT_URI_PATH
)
?
'/'
:
'&'
;
char
separator
=
(
optnum
==
COAP_OPT_URI_PATH
)
?
'/'
:
'&'
;
size_t
uri_len
=
strlen
(
uri
);
size_t
uri_len
=
strlen
(
uri
);
if
(
uri_len
==
0
)
{
if
(
uri_len
==
0
)
{
return
0
;
return
0
;
}
}
uint8_t
*
bufpos
=
buf
;
uint8_t
*
bufpos
=
buf
;
char
*
uripos
=
(
char
*
)
uri
;
char
*
uripos
=
(
char
*
)
uri
;
while
(
uri_len
)
{
while
(
uri_len
)
{
size_t
part_len
;
size_t
part_len
;
uripos
++
;
uripos
++
;
uint8_t
*
part_start
=
(
uint8_t
*
)
uripos
;
uint8_t
*
part_start
=
(
uint8_t
*
)
uripos
;
while
(
uri_len
--
)
{
while
(
uri_len
--
)
{
if
((
*
uripos
==
separator
)
||
(
*
uripos
==
'\0'
))
{
if
((
*
uripos
==
separator
)
||
(
*
uripos
==
'\0'
))
{
...
@@ -358,7 +368,7 @@ size_t coap_put_option_uri(uint8_t *buf, uint16_t lastonum, const char *uri, uin
...
@@ -358,7 +368,7 @@ size_t coap_put_option_uri(uint8_t *buf, uint16_t lastonum, const char *uri, uin
uripos
++
;
uripos
++
;
}
}
part_len
=
(
uint8_t
*
)
uripos
-
part_start
;
part_len
=
(
uint8_t
*
)
uripos
-
part_start
;
if
(
part_len
)
{
if
(
part_len
)
{
bufpos
+=
coap_put_option
(
bufpos
,
lastonum
,
optnum
,
part_start
,
part_len
);
bufpos
+=
coap_put_option
(
bufpos
,
lastonum
,
optnum
,
part_start
,
part_len
);
...
@@ -369,7 +379,7 @@ size_t coap_put_option_uri(uint8_t *buf, uint16_t lastonum, const char *uri, uin
...
@@ -369,7 +379,7 @@ size_t coap_put_option_uri(uint8_t *buf, uint16_t lastonum, const char *uri, uin
return
bufpos
-
buf
;
return
bufpos
-
buf
;
}
}
ssize_t
coap_well_known_core_default_handler
(
coap_pkt_t
*
pkt
,
uint8_t
*
buf
,
\
ssize_t
coap_well_known_core_default_handler
(
coap_pkt_t
*
pkt
,
uint8_t
*
buf
,
\
size_t
len
)
size_t
len
)
{
{
uint8_t
*
payload
=
buf
+
coap_get_total_hdr_len
(
pkt
);
uint8_t
*
payload
=
buf
+
coap_get_total_hdr_len
(
pkt
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment