Skip to content

sys/net/nanocoap: introduce nanocoap_sock_*(), use in suit/transport/coap#17474

Merged
benpicco merged 12 commits intoRIOT-OS:masterfrom
benpicco:nanocoap-suit
Feb 27, 2022
Merged

sys/net/nanocoap: introduce nanocoap_sock_*(), use in suit/transport/coap#17474
benpicco merged 12 commits intoRIOT-OS:masterfrom
benpicco:nanocoap-suit

Conversation

@benpicco
Copy link
Copy Markdown
Contributor

@benpicco benpicco commented Jan 5, 2022

Contribution description

This refactors the nanocoap API to not open/close a socket for each request, to allow for socket re-use and align it more with what SUIT does.
As a result, we can remove the copy of _nanocoap_request() from SUIT.

The timeout handling differs a bit: In SUIT CONFIG_COAP_ACK_TIMEOUT is used as a timeout for the whole request (for all retransmissions combined) whereas nanocoap uses it as the initial timeout for the first request and then doubles the timeout.

I kept the nanocoap behavior, but changed the timeout to milliseconds so lower initial values can be used.

As a next step, this also moves suit_coap_get_blockwise() to nanocoap_get_blockwise() so it can be used outside SUIT.

Testing procedure

examples/suit_update still works

make BOARD=same54-xpro test-with-config

First, run

sudo dist/tools/ethos/setup_network.sh riot0 2001:db8::/64
> riotboot-hdr
Image magic_number: 0x544f4952
Image Version: 0x61d60952
Image start address: 0x00082400
Header chksum: 0xf04d2cd2

> ifconfig
ifconfig
Iface  4  HWaddr: 66:9B:87:4C:41:52 
          L2-PDU:1500  MTU:1500  HL:64  RTR  
          Source address length: 6
          Link type: wired
          inet6 addr: fe80::649b:87ff:fe4c:4152  scope: link  VAL
pinging node...
PING fe80::649b:87ff:fe4c:4152%riot0(fe80::649b:87ff:fe4c:4152%riot0) 56 data bytes

--- fe80::649b:87ff:fe4c:4152%riot0 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 37.730/37.730/37.730/0.000 ms
pinging node succeeded.
suit
          inet6 addr: fe80::2  scope: link  VAL
          inet6 group: ff02::2
          inet6 group: ff02::1
          inet6 group: ff02::1:ff4c:4152
          inet6 group: ff02::1:ff00:2
          
> suit
Usage: suit <manifest url>
compiling /home/benpicco/dev/RIOT/dist/tools/riotboot_gen_hdr/bin/genhdr...
make: Nothing to be done for 'all'.
creating /home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-slot0.1641417043.riot.bin...
creating /home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-slot1.1641417043.riot.bin...
published "/home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-riot.suit.1641417043.bin"
       as "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit.1641417043.bin"
published "/home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-riot.suit.latest.bin"
       as "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit.latest.bin"
published "/home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-riot.suit_signed.1641417043.bin"
       as "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit_signed.1641417043.bin"
published "/home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-riot.suit_signed.latest.bin"
       as "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit_signed.latest.bin"
published "/home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-slot0.1641417043.riot.bin"
       as "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-slot0.1641417043.riot.bin"
published "/home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-slot1.1641417043.riot.bin"
       as "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-slot1.1641417043.riot.bin"
aiocoap-client -m POST "coap://[fe80::649b:87ff:fe4c:4152%riot0]/suit/trigger" \
	--payload "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit_signed.1641417043.bin" && \
	echo "Triggered [fe80::649b:87ff:fe4c:4152%riot0] to update."
Triggered [fe80::649b:87ff:fe4c:4152%riot0] to update.
> suit: received URL: "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit_signed.1641417043.bin"
suit_coap: trigger received
suit_coap: downloading "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit_signed.1641417043.bin"
suit_coap: got manifest with size 507
suit: verifying manifest signature
Unable to validate signature: -2
compiling /home/benpicco/dev/RIOT/dist/tools/riotboot_gen_hdr/bin/genhdr...
make: Nothing to be done for 'all'.
creating /home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-slot0.1641417041.riot.bin...
creating /home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-slot1.1641417041.riot.bin...
published "/home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-riot.suit.1641417041.bin"
       as "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit.1641417041.bin"
published "/home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-riot.suit.latest.bin"
       as "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit.latest.bin"
published "/home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-riot.suit_signed.1641417041.bin"
       as "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit_signed.1641417041.bin"
published "/home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-riot.suit_signed.latest.bin"
       as "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit_signed.latest.bin"
published "/home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-slot0.1641417041.riot.bin"
       as "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-slot0.1641417041.riot.bin"
published "/home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-slot1.1641417041.riot.bin"
       as "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-slot1.1641417041.riot.bin"
aiocoap-client -m POST "coap://[fe80::649b:87ff:fe4c:4152%riot0]/suit/trigger" \
	--payload "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit_signed.1641417041.bin" && \
	echo "Triggered [fe80::649b:87ff:fe4c:4152%riot0] to update."
Triggered [fe80::649b:87ff:fe4c:4152%riot0] to update.
suit_parse() failed. res=-6
suit: received URL: "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit_signed.1641417041.bin"
suit_coap: trigger received
suit_coap: downloading "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit_signed.1641417041.bin"
suit_coap: got manifest with size 507
suit: verifying manifest signature
suit: validated manifest version
)Manifest seq_no: 1641417041, highest available: 1641417042
seq_nr <= running image
compiling /home/benpicco/dev/RIOT/dist/tools/riotboot_gen_hdr/bin/genhdr...
make: Nothing to be done for 'all'.
creating /home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-slot0.1641417043.riot.bin...
creating /home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-slot1.1641417043.riot.bin...
published "/home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-riot.suit.1641417043.bin"
       as "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit.1641417043.bin"
published "/home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-riot.suit.latest.bin"
       as "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit.latest.bin"
published "/home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-riot.suit_signed.1641417043.bin"
       as "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit_signed.1641417043.bin"
published "/home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-riot.suit_signed.latest.bin"
       as "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit_signed.latest.bin"
published "/home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-slot0.1641417043.riot.bin"
       as "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-slot0.1641417043.riot.bin"
published "/home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-slot1.1641417043.riot.bin"
       as "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-slot1.1641417043.riot.bin"
aiocoap-client -m POST "coap://[fe80::649b:87ff:fe4c:4152%riot0]/suit/trigger" \
	--payload "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit_signed.1641417043.bin" && \
	echo "Triggered [fe80::649b:87ff:fe4c:4152%riot0] to update."
Triggered [fe80::649b:87ff:fe4c:4152%riot0] to update.
)suit_parse() failed. res=-5
suit: received URL: "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit_signed.1641417043.bin"
suit_coap: trigger received
suit_coap: downloading "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit_signed.1641417043.bin"
suit_coap: got manifest with size 507
suit: verifying manifest signature
suit: validated manifest version
)Manifest seq_no: 1641417043, highest available: 1641417042
suit: validated sequence number
)Formatted component name: 
Comparing manifest offset 4000 with other slot offset
validating vendor ID
Comparing 547d0d74-6d3a-5a92-9662-4881afd9407b to 547d0d74-6d3a-5a92-9662-4881afd9407b from manifest
validating vendor ID: OK
validating class id
Comparing 50244518-6a7c-5ce7-932b-88b318336c82 to 50244518-6a7c-5ce7-932b-88b318336c82 from manifest
validating class id: OK
Comparing manifest offset 4000 with other slot offset
SUIT policy check OK.
Formatted component name: 
riotboot_flashwrite: initializing update to target slot 0
Fetching firmware |█████████████████████████| 100%
Finalizing payload store
Verifying image digest
Starting digest verification against image
Install correct payload
Verifying image digest
Starting digest verification against image
Install correct payload
Image magic_number: 0x544f4952
Image Version: 0x61d60953
Image start address: 0x00004400
Header chksum: 0x304a4ccb

suit_coap: rebooting...


----> ethos: hello received
Failed to send flush request: Operation not permitted
current-slot
gnrc_uhcpc: Using 4 as border interface and 0 as wireless interface.
gnrc_uhcpc: only one interface found, skipping setup.
main(): This is RIOT! (Version: 2022.01-devel-1477-gd72ff-nanocoap-suit)
RIOT SUIT update example application
Running from slot 0
Image magic_number: 0x544f4952
Image Version: 0x61d60953
Image start address: 0x00004400
Header chksum: 0x304a4ccb

suit_coap: started.
Starting the shell
> 
> 
> ifconfig
current-slot
Running from slot 0
> ifconfig
Iface  4  HWaddr: 66:9B:87:4C:41:52 
          L2-PDU:1500  MTU:1500  HL:64  RTR  
          Source address length: 6
          Link type: wired
          inet6 addr: fe80::649b:87ff:fe4c:4152  scope: link  VAL
pinging node...
PING fe80::649b:87ff:fe4c:4152%riot0(fe80::649b:87ff:fe4c:4152%riot0) 56 data bytes

--- fe80::649b:87ff:fe4c:4152%riot0 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 39.213/39.213/39.213/0.000 ms
pinging node succeeded.
compiling /home/benpicco/dev/RIOT/dist/tools/riotboot_gen_hdr/bin/genhdr...
make: Nothing to be done for 'all'.
creating /home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-slot0.1641417044.riot.bin...
creating /home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-slot1.1641417044.riot.bin...
published "/home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-riot.suit.1641417044.bin"
       as "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit.1641417044.bin"
published "/home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-riot.suit.latest.bin"
       as "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit.latest.bin"
published "/home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-riot.suit_signed.1641417044.bin"
       as "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit_signed.1641417044.bin"
published "/home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-riot.suit_signed.latest.bin"
       as "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit_signed.latest.bin"
published "/home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-slot0.1641417044.riot.bin"
       as "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-slot0.1641417044.riot.bin"
published "/home/benpicco/dev/RIOT/examples/suit_update/bin/same54-xpro/suit_update-slot1.1641417044.riot.bin"
       as "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-slot1.1641417044.riot.bin"
aiocoap-client -m POST "coap://[fe80::649b:87ff:fe4c:4152%riot0]/suit/trigger" \
	--payload "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit_signed.1641417044.bin" && \
	echo "Triggered [fe80::649b:87ff:fe4c:4152%riot0] to update."
Triggered [fe80::649b:87ff:fe4c:4152%riot0] to update.
          inet6 addr: fe80::2  scope: link  VAL
          inet6 group: ff02::2
          inet6 group: ff02::1
          inet6 group: ff02::1:ff4c:4152
          inet6 group: ff02::1:ff00:2
          
> suit: received URL: "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit_signed.1641417044.bin"
suit_coap: trigger received
suit_coap: downloading "coap://[fd00:dead:beef::1]/fw/same54-xpro/suit_update-riot.suit_signed.1641417044.bin"
suit_coap: got manifest with size 507
suit: verifying manifest signature
suit: validated manifest version
)Manifest seq_no: 1641417044, highest available: 1641417043
suit: validated sequence number
)Formatted component name: 
Comparing manifest offset 4000 with other slot offset
Comparing manifest offset 82000 with other slot offset
validating vendor ID
Comparing 547d0d74-6d3a-5a92-9662-4881afd9407b to 547d0d74-6d3a-5a92-9662-4881afd9407b from manifest
validating vendor ID: OK
validating class id
Comparing 50244518-6a7c-5ce7-932b-88b318336c82 to 50244518-6a7c-5ce7-932b-88b318336c82 from manifest
validating class id: OK
Comparing manifest offset 4000 with other slot offset
Comparing manifest offset 82000 with other slot offset
SUIT policy check OK.
Formatted component name: 
riotboot_flashwrite: initializing update to target slot 1
Fetching firmware |█████████████████████████| 100%
Finalizing payload store
Verifying image digest
Starting digest verification against image
Install correct payload
Verifying image digest
Starting digest verification against image
Install correct payload
Image magic_number: 0x544f4952
Image Version: 0x61d60954
Image start address: 0x00082400
Header chksum: 0xf0552cd4

suit_coap: rebooting...


----> ethos: hello received
Failed to send flush request: Operation not permitted
current-slot
gnrc_uhcpc: Using 4 as border interface and 0 as wireless interface.
gnrc_uhcpc: only one interface found, skipping setup.
main(): This is RIOT! (Version: 2022.01-devel-1477-gd72ff-nanocoap-suit)
RIOT SUIT update example application
Running from slot 1
Image magic_number: 0x544f4952
Image Version: 0x61d60954
Image start address: 0x00082400
Header chksum: 0xf0552cd4

suit_coap: started.
Starting the shell
> 
> 
> ifconfig
current-slot
Running from slot 1
> ifconfig
Iface  4  HWaddr: 66:9B:87:4C:41:52 
          L2-PDU:1500  MTU:1500  HL:64  RTR  
          Source address length: 6
          Link type: wired
          inet6 addr: fe80::649b:87ff:fe4c:4152  scope: link  VAL
pinging node...
PING fe80::649b:87ff:fe4c:4152%riot0(fe80::649b:87ff:fe4c:4152%riot0) 56 data bytes

--- fe80::649b:87ff:fe4c:4152%riot0 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 37.470/37.470/37.470/0.000 ms
pinging node succeeded.
TEST PASSED

Issues/PRs references

@benpicco benpicco requested a review from bergzand January 5, 2022 21:42
@benpicco benpicco added the Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation label Jan 5, 2022
@github-actions github-actions bot added Area: CoAP Area: Constrained Application Protocol implementations Area: network Area: Networking Area: OTA Area: Over-the-air updates Area: sys Area: System Area: tests Area: tests and testing framework labels Jan 5, 2022
@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jan 5, 2022
@benpicco benpicco changed the title suit/transport/coap: use nanocoap for request suit/transport/coap: move blockwise GET to nanocoap Jan 6, 2022
@benpicco benpicco requested a review from JKRhb January 9, 2022 14:32
Copy link
Copy Markdown
Member

@JKRhb JKRhb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, I have not been able to test this PR locally yet, but it looks good to me :) I just noticed a very minor typo (see below).

@benpicco benpicco removed the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jan 10, 2022
@benpicco benpicco added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jan 10, 2022

pkt.hdr = (coap_hdr_t*)buf;
pkt.hdr = buf;
pktpos += coap_build_hdr(pkt.hdr, COAP_TYPE_CON, NULL, 0, COAP_METHOD_GET, 1);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea why id is always 1 here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is indeed wrong. The message ID is used to uniquely identify a specific message (for the same sender and received endpoint) for a given timespan, after which it can be reused. If you hardcode 1 here, you might end up reusing it before the timespan is over after which it is safe to reuse.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to open an issue and not also solve this in this PR?

@benpicco benpicco requested a review from chrysn January 11, 2022 15:14
@fjmolinas fjmolinas added the Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. label Jan 17, 2022
Copy link
Copy Markdown
Contributor

@kaspar030 kaspar030 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're introducing a new way of using nanocoap, where a socket gets created and can be re-used.
IMO it would make a lot of sense to group this functionality in nanocoap_sock_*(), and give it a distinct type to work on.

typedef struct {
  //... (probably just a sock_udp in the beginning)
} nanocoap_sock_t;

nanocoap_sock_t coap_sock;
nanocoap_sock_create(&coap_sock, ...);
nanocoap_sock_get(&coap_sock, ...);
// ...
nanocoap_sock_close(&coap_sock, ...);

I know the current API is already a bit messy, but IMO grouping in nanocoap_sock_... would at least make clear that these new functions belong together.
I'm also looking into the future a bit here, if these functions work on their own type, I could see nanocoap_sock_t maybe be a tagged union that allows more transports than plain udp. API wise, we'd only have to change the create() function.

@fjmolinas
Copy link
Copy Markdown
Contributor

@kaspar030 does it seem ok now?

@kaspar030
Copy link
Copy Markdown
Contributor

LGTM, apart from the missing nanocoap_get().

@fjmolinas
Copy link
Copy Markdown
Contributor

@chrysn do you still have comments here?

@kaspar030
Copy link
Copy Markdown
Contributor

please squash!

@kaspar030 kaspar030 changed the title suit/transport/coap: move blockwise GET to nanocoap sys/net/nanocoap: introduce nanocoap_sock_*(), use in suit/transport/coap Feb 24, 2022
@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Feb 24, 2022
@kaspar030
Copy link
Copy Markdown
Contributor

ACK.

@benpicco benpicco requested a review from chrysn February 24, 2022 12:08
@fjmolinas
Copy link
Copy Markdown
Contributor

Tested on nrf52:

----> ethos: hello received
Failed to send flush request: Operation not permitted
gnrc_uhcpc: Using 4 as border interface and 0 as wireless interface.
gnrc_uhcpc: only one interface found, skipping setup.
main(): This is RIOT! (Version: 2022.04-devel-83-g67b98f-pr-17474)
RIOT SUIT update example application
Running from slot 0
Image magic_number: 0x544f4952
Image Version: 0x62177a8a
Image start address: 0x00002400
Header chksum: 0xb5ea9e43

suit_coap: started.
Starting the shell
> current-slot
ifconfig

>
> current-slot
Running from slot 0
> ifconfig
Iface  4  HWaddr: FA:FC:4B:E6:DF:62
          L2-PDU:1500  MTU:1500  HL:64  RTR
          Source address length: 6
          Link type: wired
          inet6 addr: fe80::f8fc:4bff:fee6:df62  scope: link  VAL
pinging node...
PING fe80::f8fc:4bff:fee6:df62%riot0(fe80::f8fc:4bff:fee6:df62%riot0) 56 data bytes

--- fe80::f8fc:4bff:fee6:df62%riot0 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 39.259/39.259/39.259/0.000 ms
pinging node succeeded.
TEST PASSED

Tested also over the wireless link and it works as well... just takes longer...

@benpicco
Copy link
Copy Markdown
Contributor Author

just takes longer

yea this is to be expected due to the different ways SUIT's _nanocoap_request() and nanocoap's nanocoap_request() do calculate timeouts.
CONFIG_COAP_ACK_TIMEOUT_MS should be decreased, not sure why 2s was selected as a default, but I didn't want to change that too with this PR.

@fjmolinas
Copy link
Copy Markdown
Contributor

the

Yeah I know its not a complaint, it's always been much longer.

@benpicco
Copy link
Copy Markdown
Contributor Author

@chrysn have your comments been addressed?

@chrysn
Copy link
Copy Markdown
Member

chrysn commented Feb 26, 2022

I didn't do a full review, but my concerns have been addressed (so maybe I should have clicked "dismiss review", but neither is correct in my mental model; what I meant to indicate is that I have no objections to the current state, and with Kaspar's review this can go through.)

@benpicco
Copy link
Copy Markdown
Contributor Author

Thank you for the review!

@benpicco benpicco merged commit bbfa691 into RIOT-OS:master Feb 27, 2022
@benpicco benpicco deleted the nanocoap-suit branch February 27, 2022 01:07
@fjmolinas
Copy link
Copy Markdown
Contributor

I have no idea why, but after bisecting I have this PR as the reason why examples/suit_update is now failing, specifically after the first successful update the manifest signature fails to verify correctly:

8c9f413b334dfc616dd3270e3d214892ec6a66f7 is the first bad commit
commit 8c9f413b334dfc616dd3270e3d214892ec6a66f7
Author: Benjamin Valentin <[email protected]>
Date:   Thu Jan 6 12:55:17 2022 +0100

    suit/transport/coap: move suit_coap_get_blockwise() to socket based API

 sys/suit/transport/coap.c | 30 ++++++++++++------------------
 1 file changed, 12 insertions(+), 18 deletions(-)
examples/suit_update
> riotboot-hdr
Image magic_number: 0x544f4952
Image Version: 0x625ea84b
Image start address: 0x00001100
Header chksum: 0x47c4b94b

> ifconfig
ifconfig
Iface  4  HWaddr: AA:04:26:28:76:39 
          L2-PDU:1500  MTU:1500  HL:64  RTR  
          Source address length: 6
          Link type: wired
          inet6 addr: fe80::a804:26ff:fe28:7639  scope: link  VAL
pinging node...
PING fe80::a804:26ff:fe28:7639%riot0(fe80::a804:26ff:fe28:7639%riot0) 56 data bytes

--- fe80::a804:26ff:fe28:7639%riot0 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 39.413/39.413/39.413/0.000 ms
pinging node succeeded.
suit
          inet6 addr: fe80::2  scope: link  VAL
          inet6 group: ff02::2
          inet6 group: ff02::1
          inet6 group: ff02::1:ff28:7639
          inet6 group: ff02::1:ff00:2
          
> suit
Usage: suit <manifest url>
make[1]: warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.
compiling /home/francisco/workspace/RIOT/dist/tools/riotboot_gen_hdr/bin/genhdr...
make: Nothing to be done for 'all'.
creating /home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-slot0.1650370636.riot.bin...
creating /home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-slot1.1650370636.riot.bin...
published "/home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-riot.suit.1650370636.bin"
       as "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit.1650370636.bin"
published "/home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-riot.suit.latest.bin"
       as "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit.latest.bin"
published "/home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-riot.suit_signed.1650370636.bin"
       as "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit_signed.1650370636.bin"
published "/home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-riot.suit_signed.latest.bin"
       as "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit_signed.latest.bin"
published "/home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-slot0.1650370636.riot.bin"
       as "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-slot0.1650370636.riot.bin"
published "/home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-slot1.1650370636.riot.bin"
       as "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-slot1.1650370636.riot.bin"
make[1]: warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.
aiocoap-client -m POST "coap://[fe80::a804:26ff:fe28:7639%riot0]/suit/trigger" \
	--payload "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit_signed.1650370636.bin" && \
	echo "Triggered [fe80::a804:26ff:fe28:7639%riot0] to update."
Triggered [fe80::a804:26ff:fe28:7639%riot0] to update.
> suit: received URL: "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit_signed.1650370636.bin"
suit_coap: trigger received
suit_coap: downloading "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit_signed.1650370636.bin"
suit_coap: got manifest with size 507
suit: verifying manifest signature
Unable to validate signature: -2
make[1]: warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.
compiling /home/francisco/workspace/RIOT/dist/tools/riotboot_gen_hdr/bin/genhdr...
make: Nothing to be done for 'all'.
creating /home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-slot0.1650370634.riot.bin...
creating /home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-slot1.1650370634.riot.bin...
published "/home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-riot.suit.1650370634.bin"
       as "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit.1650370634.bin"
published "/home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-riot.suit.latest.bin"
       as "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit.latest.bin"
published "/home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-riot.suit_signed.1650370634.bin"
       as "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit_signed.1650370634.bin"
published "/home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-riot.suit_signed.latest.bin"
       as "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit_signed.latest.bin"
published "/home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-slot0.1650370634.riot.bin"
       as "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-slot0.1650370634.riot.bin"
published "/home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-slot1.1650370634.riot.bin"
       as "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-slot1.1650370634.riot.bin"
make[1]: warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.
aiocoap-client -m POST "coap://[fe80::a804:26ff:fe28:7639%riot0]/suit/trigger" \
	--payload "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit_signed.1650370634.bin" && \
	echo "Triggered [fe80::a804:26ff:fe28:7639%riot0] to update."
Triggered [fe80::a804:26ff:fe28:7639%riot0] to update.
suit_parse() failed. res=-6
suit: received URL: "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit_signed.1650370634.bin"
suit_coap: trigger received
suit_coap: downloading "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit_signed.1650370634.bin"
suit_coap: got manifest with size 507
suit: verifying manifest signature
suit: validated manifest version
)riotboot_hdr_validate: riotboot_hdr magic number invalid
Manifest seq_no: 1650370634, highest available: 1650370635
seq_nr <= running image
make[1]: warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.
compiling /home/francisco/workspace/RIOT/dist/tools/riotboot_gen_hdr/bin/genhdr...
make: Nothing to be done for 'all'.
creating /home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-slot0.1650370636.riot.bin...
creating /home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-slot1.1650370636.riot.bin...
published "/home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-riot.suit.1650370636.bin"
       as "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit.1650370636.bin"
published "/home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-riot.suit.latest.bin"
       as "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit.latest.bin"
published "/home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-riot.suit_signed.1650370636.bin"
       as "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit_signed.1650370636.bin"
published "/home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-riot.suit_signed.latest.bin"
       as "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit_signed.latest.bin"
published "/home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-slot0.1650370636.riot.bin"
       as "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-slot0.1650370636.riot.bin"
published "/home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-slot1.1650370636.riot.bin"
       as "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-slot1.1650370636.riot.bin"
make[1]: warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.
aiocoap-client -m POST "coap://[fe80::a804:26ff:fe28:7639%riot0]/suit/trigger" \
	--payload "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit_signed.1650370636.bin" && \
	echo "Triggered [fe80::a804:26ff:fe28:7639%riot0] to update."
Triggered [fe80::a804:26ff:fe28:7639%riot0] to update.
)suit_parse() failed. res=-5
suit: received URL: "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit_signed.1650370636.bin"
suit_coap: trigger received
suit_coap: downloading "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit_signed.1650370636.bin"
suit_coap: got manifest with size 507
suit: verifying manifest signature
suit: validated manifest version
)riotboot_hdr_validate: riotboot_hdr magic number invalid
Manifest seq_no: 1650370636, highest available: 1650370635
suit: validated sequence number
)Formatted component name: 
Comparing manifest offset 1000 with other slot offset
Comparing manifest offset 20800 with other slot offset
validating vendor ID
Comparing 547d0d74-6d3a-5a92-9662-4881afd9407b to 547d0d74-6d3a-5a92-9662-4881afd9407b from manifest
validating vendor ID: OK
validating class id
Comparing 8818989e-a257-5994-ac9a-554b77898083 to 8818989e-a257-5994-ac9a-554b77898083 from manifest
validating class id: OK
Comparing manifest offset 1000 with other slot offset
Comparing manifest offset 20800 with other slot offset
SUIT policy check OK.
Formatted component name: 
riotboot_flashwrite: initializing update to target slot 1
Fetching firmware |█████████████████████████| 100%
Finalizing payload store
Verifying image digest
Starting digest verification against image
Install correct payload
Verifying image digest
Starting digest verification against image
Install correct payload
Image magic_number: 0x544f4952
Image Version: 0x625ea84c
Image start address: 0x00020900
Header chksum: 0x37cab14e

suit_coap: rebooting...


----> ethos: hello received
Failed to send flush request: Operation not permitted
gnrc_uhcpc: Using 4 as border interface and 0 as wireless interface.
gnrc_uhcpc: only one interface found, skipping setup.
current-slot
main(): This is RIOT! (Version: 2022.04-devel-77-g8c9f4-HEAD)
RIOT SUIT update example application
Running from slot 1
Image magic_number: 0x544f4952
Image Version: 0x625ea84c
Image start address: 0x00020900
Header chksum: 0x37cab14e

suit_coap: started.
Starting the shell
> 
> 
> ifconfig
current-slot
Running from slot 1
> ifconfig
Iface  4  HWaddr: AA:04:26:28:76:39 
          L2-PDU:1500  MTU:1500  HL:64  RTR  
          Source address length: 6
          Link type: wired
          inet6 addr: fe80::a804:26ff:fe28:7639  scope: link  VAL
pinging node...
PING fe80::a804:26ff:fe28:7639%riot0(fe80::a804:26ff:fe28:7639%riot0) 56 data bytes

--- fe80::a804:26ff:fe28:7639%riot0 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 41.142/41.142/41.142/0.000 ms
pinging node succeeded.
make[1]: warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.
compiling /home/francisco/workspace/RIOT/dist/tools/riotboot_gen_hdr/bin/genhdr...
make: Nothing to be done for 'all'.
creating /home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-slot0.1650370637.riot.bin...
creating /home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-slot1.1650370637.riot.bin...
published "/home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-riot.suit.1650370637.bin"
       as "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit.1650370637.bin"
published "/home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-riot.suit.latest.bin"
       as "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit.latest.bin"
published "/home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-riot.suit_signed.1650370637.bin"
       as "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit_signed.1650370637.bin"
published "/home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-riot.suit_signed.latest.bin"
       as "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit_signed.latest.bin"
published "/home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-slot0.1650370637.riot.bin"
       as "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-slot0.1650370637.riot.bin"
published "/home/francisco/workspace/RIOT/examples/suit_update/bin/samr21-xpro/suit_update-slot1.1650370637.riot.bin"
       as "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-slot1.1650370637.riot.bin"
make[1]: warning: jobserver unavailable: using -j1.  Add '+' to parent make rule.
aiocoap-client -m POST "coap://[fe80::a804:26ff:fe28:7639%riot0]/suit/trigger" \
	--payload "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit_signed.1650370637.bin" && \
	echo "Triggered [fe80::a804:26ff:fe28:7639%riot0] to update."
Triggered [fe80::a804:26ff:fe28:7639%riot0] to update.
          inet6 addr: fe80::2  scope: link  VAL
          inet6 group: ff02::2
          inet6 group: ff02::1
          inet6 group: ff02::1:ff28:7639
          inet6 group: ff02::1:ff00:2
          
> suit: received URL: "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit_signed.1650370637.bin"
suit_coap: trigger received
suit_coap: downloading "coap://[fd00:dead:beef::1]/fw/samr21-xpro/suit_update-riot.suit_signed.1650370637.bin"
suit_coap: got manifest with size 507
suit: verifying manifest signature
Unable to validate signature: -2
suit_parse() failed. res=-6

@OlegHahm OlegHahm added this to the Release 2022.04 milestone Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: CoAP Area: Constrained Application Protocol implementations Area: network Area: Networking Area: OTA Area: Over-the-air updates Area: sys Area: System Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants