mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
suit: move CoAP endpoints to the example
Those endpoints are very specific to the example and not useful for general use. Move them to the example's CoAP endpoints.
This commit is contained in:
parent
b69d060e35
commit
83569aa558
@ -1,19 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
* 2019 Freie Universität Berlin
|
||||
* 2019 Inria
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "suit.h"
|
||||
#include "net/nanocoap.h"
|
||||
#include "suit/transport/coap.h"
|
||||
#include "kernel_defines.h"
|
||||
|
||||
#ifdef MODULE_RIOTBOOT_SLOT
|
||||
#include "riotboot/slot.h"
|
||||
#endif
|
||||
|
||||
static ssize_t _riot_board_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len,
|
||||
coap_request_ctx_t *context)
|
||||
{
|
||||
@ -22,8 +26,71 @@ static ssize_t _riot_board_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len,
|
||||
COAP_FORMAT_TEXT, (uint8_t*)RIOT_BOARD, strlen(RIOT_BOARD));
|
||||
}
|
||||
|
||||
static ssize_t _version_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len,
|
||||
coap_request_ctx_t *context)
|
||||
{
|
||||
(void)context;
|
||||
return coap_reply_simple(pkt, COAP_CODE_205, buf, len,
|
||||
COAP_FORMAT_TEXT, (uint8_t *)"NONE", 4);
|
||||
}
|
||||
|
||||
static ssize_t _trigger_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len,
|
||||
coap_request_ctx_t *context)
|
||||
{
|
||||
(void)context;
|
||||
unsigned code;
|
||||
size_t payload_len = pkt->payload_len;
|
||||
if (payload_len) {
|
||||
if (payload_len >= CONFIG_SOCK_URLPATH_MAXLEN) {
|
||||
code = COAP_CODE_REQUEST_ENTITY_TOO_LARGE;
|
||||
}
|
||||
else {
|
||||
code = COAP_CODE_CREATED;
|
||||
LOG_INFO("suit: received URL: \"%s\"\n", (char *)pkt->payload);
|
||||
suit_worker_trigger((char *)pkt->payload, strlen((char *)pkt->payload));
|
||||
}
|
||||
}
|
||||
else {
|
||||
code = COAP_CODE_REQUEST_ENTITY_INCOMPLETE;
|
||||
}
|
||||
|
||||
return coap_reply_simple(pkt, code, buf, len,
|
||||
COAP_FORMAT_NONE, NULL, 0);
|
||||
}
|
||||
|
||||
#ifdef MODULE_RIOTBOOT_SLOT
|
||||
static ssize_t _slot_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len,
|
||||
coap_request_ctx_t *context)
|
||||
{
|
||||
/* context is passed either as NULL or 0x1 for /active or /inactive */
|
||||
char c = '0';
|
||||
|
||||
if (coap_request_ctx_get_context(context)) {
|
||||
c += riotboot_slot_other();
|
||||
}
|
||||
else {
|
||||
c += riotboot_slot_current();
|
||||
}
|
||||
|
||||
return coap_reply_simple(pkt, COAP_CODE_205, buf, len,
|
||||
COAP_FORMAT_TEXT, (uint8_t *)&c, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MODULE_RIOTBOOT_SLOT
|
||||
NANOCOAP_RESOURCE(slot_active) {
|
||||
.path = "/suit/slot/active", .methods = COAP_METHOD_GET, .handler = _slot_handler,
|
||||
};
|
||||
NANOCOAP_RESOURCE(slot_inactive) {
|
||||
.path = "/suit/slot/inactive", .methods = COAP_METHOD_GET, .handler = _slot_handler, .context = (void *)0x1,
|
||||
};
|
||||
#endif
|
||||
NANOCOAP_RESOURCE(trigger) {
|
||||
.path = "/suit/trigger", .methods = COAP_METHOD_PUT | COAP_METHOD_POST, .handler = _trigger_handler,
|
||||
};
|
||||
NANOCOAP_RESOURCE(version) {
|
||||
.path = "/suit/version", .methods = COAP_METHOD_GET, .handler = _version_handler,
|
||||
};
|
||||
NANOCOAP_RESOURCE(board) {
|
||||
.path = "/riot/board", .methods = COAP_GET, .handler = _riot_board_handler,
|
||||
};
|
||||
|
||||
NANOCOAP_RESOURCE(suit) SUIT_COAP_SUBTREE;
|
||||
|
@ -32,22 +32,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief SUIT CoAP endpoint entry.
|
||||
*
|
||||
* In order to use, include this header, then add SUIT_COAP_SUBTREE to the nanocoap endpoint array.
|
||||
* Mind the alphanumerical sorting!
|
||||
*
|
||||
* See examples/suit_update for an example.
|
||||
*/
|
||||
#define SUIT_COAP_SUBTREE \
|
||||
{ \
|
||||
.path="/suit/", \
|
||||
.methods=COAP_MATCH_SUBTREE | COAP_METHOD_GET | COAP_METHOD_POST | COAP_METHOD_PUT, \
|
||||
.handler=coap_subtree_handler, \
|
||||
.context=(void*)&coap_resource_subtree_suit \
|
||||
}
|
||||
|
||||
/*
|
||||
* Dear Reviewer,
|
||||
*
|
||||
@ -63,11 +47,6 @@ extern "C" {
|
||||
*/
|
||||
#ifndef DOXYGEN
|
||||
|
||||
/**
|
||||
* @brief Reference to the coap resource subtree
|
||||
*/
|
||||
extern const coap_resource_subtree_t coap_resource_subtree_suit;
|
||||
|
||||
/**
|
||||
* @brief Coap block-wise-transfer size used for SUIT
|
||||
*/
|
||||
|
@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Freie Universität Berlin
|
||||
* 2019 Inria
|
||||
* 2019 Kaspar Schleiser <kaspar@schleiser.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup sys_suit
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief SUIT coap
|
||||
*
|
||||
* @author Koen Zandberg <koen@bergzand.net>
|
||||
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
||||
* @author Francisco Molina <francois-xavier.molina@inria.fr>
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "log.h"
|
||||
#include "suit.h"
|
||||
#include "net/nanocoap.h"
|
||||
#include "suit/transport/coap.h"
|
||||
#include "kernel_defines.h"
|
||||
|
||||
#ifdef MODULE_RIOTBOOT_SLOT
|
||||
#include "riotboot/slot.h"
|
||||
#endif
|
||||
|
||||
static ssize_t _version_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len,
|
||||
coap_request_ctx_t *context)
|
||||
{
|
||||
(void)context;
|
||||
return coap_reply_simple(pkt, COAP_CODE_205, buf, len,
|
||||
COAP_FORMAT_TEXT, (uint8_t *)"NONE", 4);
|
||||
}
|
||||
|
||||
static ssize_t _trigger_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len,
|
||||
coap_request_ctx_t *context)
|
||||
{
|
||||
(void)context;
|
||||
unsigned code;
|
||||
size_t payload_len = pkt->payload_len;
|
||||
if (payload_len) {
|
||||
if (payload_len >= CONFIG_SOCK_URLPATH_MAXLEN) {
|
||||
code = COAP_CODE_REQUEST_ENTITY_TOO_LARGE;
|
||||
}
|
||||
else {
|
||||
code = COAP_CODE_CREATED;
|
||||
LOG_INFO("suit: received URL: \"%s\"\n", (char *)pkt->payload);
|
||||
suit_worker_trigger((char *)pkt->payload, payload_len);
|
||||
}
|
||||
}
|
||||
else {
|
||||
code = COAP_CODE_REQUEST_ENTITY_INCOMPLETE;
|
||||
}
|
||||
|
||||
return coap_reply_simple(pkt, code, buf, len,
|
||||
COAP_FORMAT_NONE, NULL, 0);
|
||||
}
|
||||
|
||||
#ifdef MODULE_RIOTBOOT_SLOT
|
||||
static ssize_t _slot_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len,
|
||||
coap_request_ctx_t *context)
|
||||
{
|
||||
/* context is passed either as NULL or 0x1 for /active or /inactive */
|
||||
char c = '0';
|
||||
|
||||
if (coap_request_ctx_get_context(context)) {
|
||||
c += riotboot_slot_other();
|
||||
}
|
||||
else {
|
||||
c += riotboot_slot_current();
|
||||
}
|
||||
|
||||
return coap_reply_simple(pkt, COAP_CODE_205, buf, len,
|
||||
COAP_FORMAT_TEXT, (uint8_t *)&c, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
static const coap_resource_t _subtree[] = {
|
||||
#ifdef MODULE_RIOTBOOT_SLOT
|
||||
{ "/suit/slot/active", COAP_METHOD_GET, _slot_handler, NULL },
|
||||
{ "/suit/slot/inactive", COAP_METHOD_GET, _slot_handler, (void *)0x1 },
|
||||
#endif
|
||||
{ "/suit/trigger", COAP_METHOD_PUT | COAP_METHOD_POST, _trigger_handler, NULL },
|
||||
{ "/suit/version", COAP_METHOD_GET, _version_handler, NULL },
|
||||
};
|
||||
|
||||
const coap_resource_subtree_t coap_resource_subtree_suit =
|
||||
{
|
||||
.resources = &_subtree[0],
|
||||
.resources_numof = ARRAY_SIZE(_subtree)
|
||||
};
|
Loading…
Reference in New Issue
Block a user