Contiki-NG
Loading...
Searching...
No Matches
border-router-cbor.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024, RISE Research Institutes of Sweden
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/**
32 * \file
33 * CBOR-over-SLIP protocol for talking to the serialradio firmware
34 * (examples/serialradio) from the native border router.
35 *
36 * Frames carried over SLIP have the layout:
37 *
38 * [ CBOR map ] [ CRC16-LE (2 bytes) ]
39 *
40 * The opcode constants below MUST be kept in sync with
41 * examples/serialradio/serial-radio.h.
42 * \author
43 * Joakim Eriksson <joakim.eriksson@ri.se>
44 */
45
46#ifndef BORDER_ROUTER_CBOR_H_
47#define BORDER_ROUTER_CBOR_H_
48
49#include "contiki.h"
50#include <stdbool.h>
51#include <stdint.h>
52
53/* Command opcodes (host -> radio) */
54#define SRADIO_CMD_PING 0
55#define SRADIO_CMD_GET_PARAM 1
56#define SRADIO_CMD_SET_PARAM 2
57#define SRADIO_CMD_RX_ON 5
58#define SRADIO_CMD_RX_OFF 6
59#define SRADIO_CMD_GET_ADDR64 20
60#define SRADIO_CMD_ROUTER_MODE 21
61#define SRADIO_CMD_TX_RAW_FRAME 50
62
63/* Event opcodes (radio -> host) */
64#define SRADIO_EVT_PARAM_RESPONSE 51
65#define SRADIO_EVT_RX_FRAME 52
66#define SRADIO_EVT_TX_RESPONSE 54
67#define SRADIO_EVT_HEARTBEAT 55
68#define SRADIO_EVT_ADDR64_RESPONSE 57
69#define SRADIO_EVT_PONG 100
70#define SRADIO_EVT_ERROR 255
71
72/**
73 * \brief Send a raw 802.15.4 frame to the radio for transmission.
74 * \param msg_id Session id echoed back in the TX_RESPONSE event.
75 * \param frame The fully-framed 802.15.4 packet to transmit.
76 * \param len Length of \p frame in bytes.
77 */
78void br_cbor_send_tx_frame(uint8_t msg_id, const uint8_t *frame, uint16_t len);
79
80/**
81 * \brief Set a radio parameter on the serial radio (SET_PARAM).
82 */
83void br_cbor_send_set_param(uint8_t msg_id, uint16_t param, int32_t value);
84
85/**
86 * \brief Request the radio's EUI-64 link-layer address (GET_ADDR64).
87 */
88void br_cbor_send_get_addr64(uint8_t msg_id);
89
90/**
91 * \brief Enable or disable border-router radio mode (ROUTER_MODE).
92 */
93void br_cbor_send_router_mode(uint8_t msg_id, bool enable);
94
95/**
96 * \brief Parse and dispatch a complete CBOR frame (including trailing CRC16)
97 * received from the serial radio.
98 */
99void border_router_cbor_input(const uint8_t *data, int len);
100
101#endif /* BORDER_ROUTER_CBOR_H_ */
void br_cbor_send_router_mode(uint8_t msg_id, bool enable)
Enable or disable border-router radio mode (ROUTER_MODE).
void br_cbor_send_get_addr64(uint8_t msg_id)
Request the radio's EUI-64 link-layer address (GET_ADDR64).
void br_cbor_send_tx_frame(uint8_t msg_id, const uint8_t *frame, uint16_t len)
Send a raw 802.15.4 frame to the radio for transmission.
void br_cbor_send_set_param(uint8_t msg_id, uint16_t param, int32_t value)
Set a radio parameter on the serial radio (SET_PARAM).
void border_router_cbor_input(const uint8_t *data, int len)
Parse and dispatch a complete CBOR frame (including trailing CRC16) received from the serial radio.
static int value(int type)