Add L2 entry deletion support via web

This commit is contained in:
logicog
2026-01-17 12:56:43 +01:00
parent 3509f7da04
commit e53f5e7134
4 changed files with 57 additions and 4 deletions
+1 -1
View File
@@ -134,6 +134,6 @@ function getL2() {
} }
window.addEventListener("load", function() { window.addEventListener("load", function() {
l2GetInterval = setInterval(getL2, 300); l2GetInterval = setInterval(getL2, 1000);
}); });
+3
View File
@@ -576,6 +576,9 @@ void httpd_appcall(void)
} else if (is_word(q, "/l2.json")) { } else if (is_word(q, "/l2.json")) {
parse_short(q + 13); // e.g.: /l2.json?idx=10 parse_short(q + 13); // e.g.: /l2.json?idx=10
send_l2(short_parsed); send_l2(short_parsed);
} else if (is_word(q, "/l2_del.json")) {
parse_short(q + 17);
l2_delete(short_parsed);
} else if (is_word(q, "/mirror.json")) { } else if (is_word(q, "/mirror.json")) {
send_mirror(); send_mirror();
} else if (is_word(q, "/mtu.json")) { } else if (is_word(q, "/mtu.json")) {
+52 -3
View File
@@ -16,7 +16,7 @@
// #define DEBUG // #define DEBUG
#include "debug.h" #include "debug.h"
#define L2_MAX_TRANSFER 2 #define L2_MAX_TRANSFER 30
#pragma codeseg BANK1 #pragma codeseg BANK1
#pragma constseg BANK1 #pragma constseg BANK1
@@ -288,8 +288,8 @@ void send_counters(char port)
void send_l2(uint16_t idx) void send_l2(uint16_t idx)
{ {
slen = strtox(outbuf, HTTP_RESPONCE_JSON); slen = strtox(outbuf, HTTP_RESPONCE_JSON);
dbg_string("sending L2\n"); // TODO: Remove dbg_string("sending L2\n");
print_short(idx); dbg_short(idx);
__xdata uint8_t entries_left = L2_MAX_TRANSFER; __xdata uint8_t entries_left = L2_MAX_TRANSFER;
do { do {
@@ -379,6 +379,55 @@ void send_l2(uint16_t idx)
} }
void l2_delete(uint16_t idx)
{
slen = strtox(outbuf, HTTP_RESPONCE_JSON);
dbg_string("L2 DELETE\n");
dbg_short(idx);
__xdata uint8_t entries_left = L2_MAX_TRANSFER;
do {
reg_read_m(RTL837X_TBL_CTRL);
} while (sfr_data[3] & 0x01);
slen += strtox(outbuf + slen, "{\"result\":");
// First, search for the entry based on the index
reg_read_m(RTL837x_TBL_DATA_0);
REG_WRITE(RTL837x_TBL_DATA_0, sfr_data[0], sfr_data[1],sfr_data[2] | 0xc0, sfr_data[3]);
REG_WRITE(RTL837X_TBL_CTRL, idx >> 8, idx, TBL_L2_UNICAST, 0x1);
do {
reg_read_m(RTL837X_TBL_CTRL);
} while (sfr_data[3] & 0x1);
reg_read_m(RTL837x_L2_DATA_OUT_B);
if (!(sfr_data[0] & 0x20)) {
char_to_html('0');
} else {
sfr_data[0] &= 0x3f; // Clear SPA
reg_write_m(RTL837x_TBL_DATA_IN_B);
// Second half of MAC is copied
reg_read_m(RTL837x_L2_DATA_OUT_A);
reg_write_m(RTL837x_TBL_DATA_IN_A);
reg_read_m(RTL837x_L2_DATA_OUT_C);
sfr_data[3] &= 0xc0; // Clear age, auth and second part of ports
sfr_data[1] &= 0xfe; // Clear nosalearn
reg_write_m(RTL837x_TBL_DATA_IN_C);
reg_read_m(RTL837x_TBL_DATA_0);
REG_WRITE(RTL837x_TBL_DATA_0, sfr_data[0], sfr_data[1],TBL_L2_UNICAST, sfr_data[3]);
REG_WRITE(RTL837X_TBL_CTRL, idx >> 8, idx, TBL_L2_UNICAST, TBL_WRITE | TBL_EXECUTE);
do {
reg_read_m(RTL837X_TBL_CTRL);
} while (sfr_data[3] & 0x1);
char_to_html('1');
}
char_to_html('}');
}
void send_mirror(void) void send_mirror(void)
{ {
dbg_string("send_mirror called\n"); dbg_string("send_mirror called\n");
+1
View File
@@ -7,6 +7,7 @@ void send_vlan(uint16_t vlan);
void send_basic_info(void); void send_basic_info(void);
void send_eee(void); void send_eee(void);
void send_l2(uint16_t idx); void send_l2(uint16_t idx);
void l2_delete(uint16_t idx);
void send_mirror(void); void send_mirror(void);
void send_mtu(void); void send_mtu(void);
void send_config(void); void send_config(void);