ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_layer3_switch.c
Go to the documentation of this file.
1
16
17#include "ra8_layer3_switch.h"
18
19#include <stdint.h>
20
21#include "ra8_check.h"
22#include "ra8_err.h"
23#include "ra8_log.h"
24
25static const char* s_tag = "L3SW";
26
27typedef struct {
28 bool opened;
31
33
35{
36 RA8_CHECK_NULL_PTR(cfg, s_tag, "cfg must not be nullptr");
37 if (cfg->port_count == 0U) {
39 }
40 if (cfg->mtu_bytes == 0U) {
42 }
43 if (s_state.opened) {
44 return k_ra8_err_exists;
45 }
46 s_state.opened = true;
47 s_state.promiscuous = (cfg->promiscuous != 0U);
48 ra8_log_info_val(s_tag, "l3sw open ports", (uint32_t)cfg->port_count);
49 return k_ra8_ok;
50}
51
53{
54 RA8_CHECK_NULL_PTR(route, s_tag, "route must not be nullptr");
55 if (!s_state.opened) {
57 }
59}
60
61ra8_err_t ra8_layer3_switch_route_delete(uint32_t dst_ip, uint32_t mask)
62{
63 (void)dst_ip;
64 (void)mask;
65 if (!s_state.opened) {
67 }
69}
70
71ra8_err_t ra8_layer3_switch_status_get(uint8_t* out_open, uint8_t* out_promisc)
72{
73 RA8_CHECK_NULL_PTR(out_open, s_tag, "out_open must not be nullptr");
74 RA8_CHECK_NULL_PTR(out_promisc, s_tag, "out_promisc must not be nullptr");
75 *out_open = (uint8_t)(s_state.opened ? 1U : 0U);
76 *out_promisc = (uint8_t)(s_state.promiscuous ? 1U : 0U);
77 return k_ra8_ok;
78}
79
81{
82 if (!s_state.opened) {
84 }
85 s_state.opened = false;
86 s_state.promiscuous = false;
87 return k_ra8_ok;
88}
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Definition ra8_check.h:243
Error Code Definitions for ra8-firmware.
@ k_ra8_err_not_supported
Requested feature not compiled in, not wired, or not supported by this MCU variant.
Definition ra8_err.h:180
@ k_ra8_err_invalid_arg
Invalid function argument.
Definition ra8_err.h:152
@ k_ra8_err_exists
Item already exists – cannot create again.
Definition ra8_err.h:216
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
Definition ra8_err.h:161
@ k_ra8_err_not_initialized
Module not initialized – _init() not yet called successfully.
Definition ra8_err.h:235
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
ra8_err_t ra8_layer3_switch_close(void)
Close the Layer-3 switch driver.
ra8_err_t ra8_layer3_switch_open(const ra8_layer3_switch_cfg_t *cfg)
Open the Layer-3 switch driver.
ra8_err_t ra8_layer3_switch_route_add(const ra8_layer3_switch_route_t *route)
Add a route to the forwarding table.
ra8_err_t ra8_layer3_switch_status_get(uint8_t *out_open, uint8_t *out_promisc)
Snapshot the open / promiscuous flags.
ra8_err_t ra8_layer3_switch_route_delete(uint32_t dst_ip, uint32_t mask)
Remove a route from the forwarding table.
Layer-3 Ethernet switch driver – placeholder.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_info_val(tag, message, value)
RA8 log info val.
Definition ra8_log.h:366
static uint32_t s_state
Configuration descriptor for ra8_layer3_switch_open.
uint16_t mtu_bytes
Maximum transfer unit per port.
uint8_t promiscuous
Non-zero to put switch in promisc.
uint8_t port_count
Number of physical ports.
A single forwarding-table entry.