Merge pull request #54 from logicog/speeds

Add a Port Speed and MTU configuration Web-Page
This commit is contained in:
René van Dorst
2025-12-25 09:11:31 +00:00
committed by GitHub
17 changed files with 375 additions and 45 deletions
+65 -21
View File
@@ -17,6 +17,7 @@
#include "version.h"
#include "machine.h"
#include "phy.h"
#pragma codeseg BANK1
#pragma constseg BANK1
@@ -420,36 +421,47 @@ void parse_port(void)
print_string(" is SFP no PHY information available.\n");
return;
}
if (cmd_words_b[2] > 0 && cmd_compare(2, "10m")) {
if (cmd_words_b[2] <= 0) {
print_string("\nport <port> [show|on|off|10m|100m|1g|2g5] [half|full]");
return;
}
if (cmd_compare(2, "10m")) {
print_string(" 10M\n");
phy_set_speed(p, PHY_SPEED_10M);
}
if (cmd_words_b[2] > 0 && cmd_compare(2, "100m")) {
if (cmd_words_b[3] > 0 && cmd_compare(3, "half"))
phy_set_speed(p, PHY_SPEED_10M, PHY_DUPLEX_HALF);
else if (cmd_words_b[3] > 0 && cmd_compare(3, "full"))
phy_set_speed(p, PHY_SPEED_10M, PHY_DUPLEX_FULL);
else
phy_set_speed(p, PHY_SPEED_10M, PHY_DUPLEX_BOTH);
} else if (cmd_compare(2, "100m")) {
print_string(" 100M\n");
phy_set_speed(p, PHY_SPEED_100M);
}
if (cmd_words_b[2] > 0 && cmd_compare(2, "2g5")) {
if (cmd_words_b[3] > 0 && cmd_compare(3, "half"))
phy_set_speed(p, PHY_SPEED_100M, PHY_DUPLEX_HALF);
else if (cmd_words_b[3] > 0 && cmd_compare(3, "full"))
phy_set_speed(p, PHY_SPEED_100M, PHY_DUPLEX_FULL);
else
phy_set_speed(p, PHY_SPEED_100M, PHY_DUPLEX_BOTH);
} else if (cmd_compare(2, "2g5")) {
print_string(" 2.5G\n");
phy_set_speed(p, PHY_SPEED_2G5);
}
if (cmd_words_b[2] > 0 && cmd_compare(2, "1g")) {
phy_set_speed(p, PHY_SPEED_2G5, PHY_DUPLEX_BOTH);
} else if (cmd_compare(2, "1g")) {
print_string(" 1G\n");
phy_set_speed(p, PHY_SPEED_1G);
}
if (cmd_words_b[2] > 0 && cmd_compare(2, "auto")) {
phy_set_speed(p, PHY_SPEED_1G, PHY_DUPLEX_BOTH);
} else if (cmd_compare(2, "auto")) {
print_string(" AUTO\n");
phy_set_speed(p, PHY_SPEED_AUTO);
}
if (cmd_words_b[2] > 0 && cmd_compare(2, "off")) {
phy_set_speed(p, PHY_SPEED_AUTO, PHY_DUPLEX_BOTH);
} else if (cmd_compare(2, "off")) {
print_string(" OFF\n");
phy_set_speed(p, PHY_OFF);
}
if (cmd_words_b[2] > 0 && cmd_compare(2, "duplex")) {
phy_set_speed(p, PHY_OFF, PHY_DUPLEX_BOTH);
} else if (cmd_compare(2, "on")) {
print_string(" ON\n");
phy_set_speed(p, PHY_SPEED_AUTO, PHY_DUPLEX_BOTH);
} else if (cmd_compare(2, "duplex")) {
print_string(" DUPLEX\n");
if (cmd_words_b[3] > 0 && cmd_compare(3, "full"))
phy_set_duplex(p, 1);
phy_set_duplex(p, PHY_DUPLEX_FULL);
else
phy_set_duplex(p, 0);
phy_set_duplex(p, PHY_DUPLEX_HALF);
}
if (cmd_words_b[2] > 0 && cmd_compare(2, "show")) {
phy_show(p);
@@ -457,6 +469,36 @@ void parse_port(void)
}
void parse_mtu(void)
{
__xdata uint16_t mtu;
uint8_t p;
if (cmd_words_b[1] > 0 && cmd_compare(1, "show")) {
for (p = machine.min_port; p <= machine.max_port; p++) {
reg_read_m(RTL8373_REG_MAC_L2_PORT_MAX_LEN + ((uint16_t) p << 8));
mtu = SFR_DATA_U16 & 0x3fff;
print_string("Port "); print_byte(machine.log_to_phys_port[p]);
write_char(' '); print_short(mtu); write_char('\n');
}
}
p = cmd_buffer[cmd_words_b[1]] - '1';
p = machine.phys_to_log_port[p];
print_byte(p);
if (cmd_words_b[2] <= 0) {
print_string("mtu [port] [size]");
return;
}
atoi_short(&mtu, cmd_words_b[2]);
if (mtu > 0x3fff) {
print_string("Maximum MTU is 16383\n");
return;
}
REG_WRITE(RTL8373_REG_MAC_L2_PORT_MAX_LEN + ((uint16_t) p << 8), (mtu >> 10) & 0xf, (mtu >> 2) & 0xff,
((mtu & 0x3) << 6) | ((mtu >> 8) & 0x3f), mtu & 0xff);
}
void sfp_print_measurements(uint8_t sfp)
{
print_string("Options: "); print_byte(sfp_read_reg(sfp, 92)); write_char('\n');
@@ -730,6 +772,8 @@ void cmd_parser(void) __banked
flash_write_bytes(flash_buf);
} else if (cmd_compare(0, "port") && cmd_words_b[1] > 0) {
parse_port();
} else if (cmd_compare(0, "mtu") && cmd_words_b[1] > 0) {
parse_mtu();
} else if (cmd_compare(0, "ip")) {
print_string("Got ip command: ");
if (!parse_ip(cmd_words_b[1]))
+6 -5
View File
@@ -1,8 +1,9 @@
function createEEE() {
var tbl = document.getElementById('eeetable');
if (tbl.rows.length <= 2) {
if (tbl.rows.length <= 2 && numPorts) {
clearInterval(createEEEInterval);
console.log("CREATING TABLE ", tbl.rows.length);
for (let i = 2; i < 8; i++) {
for (let i = 2; i < 2 + numPorts; i++) {
console.log("Table row: " + i + "pState: " + pState[i-2]);
const tr = tbl.insertRow();
let td = tr.insertCell(); td.appendChild(document.createTextNode(`Port ${i-1}`));
@@ -20,8 +21,8 @@ function getEEE() {
const s = JSON.parse(xhttp.responseText);
console.log("EEE: ", JSON.stringify(s));
var tbl = document.getElementById('eeetable');
if (tbl.rows.length > 2) {
for (let i = 2; i < 8; i++) {
if (tbl.rows.length > 2 && numPorts) {
for (let i = 2; i < 2 + numPorts; i++) {
p = s[i-2];
let n = p.portNum;
console.log("Table Update row: " + i + " portNum is " + n + ", pState is " + pState[i-2]);
@@ -46,4 +47,4 @@ window.addEventListener("load", function() {
getEEE();
const iCount = setInterval(getEEE, 2000);
});
const stat = setInterval(createEEE, 1000);
const createEEEInterval = setInterval(createEEE, 1000);
+8 -2
View File
@@ -5,9 +5,10 @@ var rxB = new BigInt64Array(10);
const linkS = ["Disabled", "No Link", "100M", "1000M", "500M", "10G", "2.5G", "5G"];
var pState = new Int8Array(10);
var pIsSFP = new Int8Array(10);
var pAdvertised = new Int8Array(10);
var numPorts = 0;
const logToPhysPort = [0, 0, 0, 5, 1, 2, 3, 4, 6];
const physToLogPort = [ 4, 5, 6, 7, 3, 8];
var logToPhysPort = new Int8Array(10);
var physToLogPort = new Int8Array(10);
function drawPorts() {
var f = document.getElementById('ports');
console.log("DRAWING PORTS: ", numPorts);
@@ -54,6 +55,8 @@ function update() {
for (let i = 0; i < s.length; i++) {
p = s[i];
let n = p.portNum;
logToPhysPort[p.logPort] = n;
physToLogPort[n-1] = p.logPort;
let pid = "port" + n;
let ttid = "tt_" + n;
n--;
@@ -84,6 +87,7 @@ function update() {
var iHTML = "<table border=\"0\" class=\"tt_table\">";
iHTML += "<tr><td align=\"left\">Link speed</td><td>:</td><td>" + linkS[p.link + 1] + "</td></tr>";
if (p.isSFP) {
pAdvertised[n] = 0;
iHTML += "<tr><td>Vendor</td><td>:</td><td>" + p.sfp_vendor + "</td></tr>";
iHTML += "<tr><td>Model</td><td>:</td><td>" + p.sfp_model + "</td></tr>";
iHTML += "<tr><td>Serial</td><td>:</td><td>" + p.sfp_serial + "</td></tr>";
@@ -94,6 +98,8 @@ function update() {
iHTML += "<tr><td>TX-Power</td><td>:</td><td>" + (Number(p.sfp_txpower) / 10.0).toFixed(0) + "&#8239;mW</td></tr>";
iHTML += "<tr><td>RX-Power</td><td>:</td><td>" + (Number(p.sfp_rxpower) / 10.0).toFixed(0) + "&#8239;mW</td></tr>";
}
} else {
pAdvertised[n] = parseInt(p.adv, 2);
}
iHTML += "</table>";
tt.innerHTML = iHTML;
+1 -1
View File
@@ -1,5 +1,6 @@
document.getElementById('sidebar').innerHTML =
"<ul><li><a href='index.html'>Overview</a></li>"
+ "<li><a href='ports.html'>Port Configuration</a></li>"
+ "<li><a href='stat.html'>Port Statistics</a></li>"
+ "<li><a href='vlan.html'>VLAN</a></li>"
+ "<li><a href='mirror.html'>Mirroring</a></li>"
@@ -7,4 +8,3 @@ document.getElementById('sidebar').innerHTML =
+ "<li><a href='eee.html'>EEE</a></li>"
+ "<li><a href='system.html'>System Settings</a></li>"
+ "<li><a href='update.html'>Firmware Update</a></li></ul>";
+24
View File
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<script src="/main.js"></script>
<link rel="stylesheet" href="style.css">
<title>FreeSwitchOS Port Configuration</title>
</head>
<body>
<nav id="sidebar"></nav>
<div style="margin-left:16%;padding:1px 16px;height:1000px;">
<div id="ports"></div>
<h1>Port Configuration</h1>
<form id="vform" action="/vlan.html">
<table id="speedtable">
<tr> <th>Port</th> <th>Current Link Speed</th><th>Set Speed</th><th>Disabled</th><th>Apply</th></tr>
</table>
<h2 style="margin-top:3em">Configure Maximum Frame Size (MTU) forwarded at Port</h2>
<table id="mtutable" style="margin-top:1em">
</table>
<script src="/ports.js"></script>
</form>
</div>
<script src="/navigation.js"></script>
</body>
</html>
+146
View File
@@ -0,0 +1,146 @@
var mtus = new Int16Array(10);
var clicked = new Int8Array(10);
function createPortTable() {
var tbl = document.getElementById('speedtable');
if (tbl.rows.length <= 2 && numPorts) {
clearInterval(pTableInterval);
const sSelect = '<select name="speed_sel" id="speed_sel">'
+ '<option value="auto">Auto</option>'
+ '<option value="2g5">2500MBit/Full</option>'
+ '<option value="1g">1000MBit/Full</option>'
+ '<option value="100m full">100MBit/Full</option>'
+ '<option value="100m half">100MBit/Half</option>'
+ '<option value="10m full">10MBit/Full</option>'
+ '<option value="10m half">10MBit/Half</option>'
+ '</select>';
const dSwitch = '<input type="checkbox" id="disable_port" onchange="portOnOff();">'
for (let i = 1; i <= numPorts; i++) {
if (pIsSFP[i-1])
continue;
console.log("Table row: " + i + "pState: " + pState[i-2]);
const tr = tbl.insertRow();
let td = tr.insertCell(); td.appendChild(document.createTextNode(`Port ${i}`));
td = tr.insertCell(); td.innerHTML = linkS[pState[i] + 1];
td = tr.insertCell(); td.innerHTML = sSelect.replaceAll("speed_sel", "speed_sel_" + i);
td = tr.insertCell(); td.innerHTML = dSwitch.replaceAll("disable_port", "disable_port_" + i)
.replace("portOnOff()", "portOnOff(" + i + ")");
var button = '<button type="button" style="margin: 0 0 0 24px" onclick="applySpeed(' + i + ');">Apply</button>';
td = tr.insertCell();
td.innerHTML = button;
}
}
tbl = document.getElementById('mtutable');
if (tbl.rows.length <= 2 && numPorts) {
const mSelect = '<select name="mtu_sel" id="mtu_sel">'
+ '<option value="16383">16383</option>'
+ '<option value="1522">1522</option>'
+ '<option value="1536">1536</option>'
+ '<option value="1552">1552</option>'
+ '<option value="9216">9216</option>'
+ '</select>';
var tr = tbl.insertRow();
for (let i = 1; i <= numPorts; i++) {
let td = tr.insertCell();
if (pIsSFP[i-1])
td.innerHTML = '<object type="image/svg+xml" data="sfp.svg", width="60"</object>'
else
td.innerHTML = '<object type="image/svg+xml" data="port.svg", width="40"</object>'
}
tr = tbl.insertRow();
for (let i = 1; i <= numPorts; i++) {
let td = tr.insertCell();
td.innerHTML = mSelect.replaceAll("mtu_sel", "mtu_sel_" + i);
}
tr = tbl.insertRow();
for (let i = 1; i <= numPorts; i++) {
let td = tr.insertCell();
td.innerHTML = '<button type="button" style="margin: 0 0 0 24px" onclick="applyMTU(' + i + ');">Apply</button>';
}
}
}
function updatePortTable() {
console.log("updatePortTable called");
var tbl = document.getElementById('speedtable');
if (tbl.rows.length <= 2 || !numPorts)
return;
for (let i = 1; i <= numPorts ; i++) {
if (pIsSFP[i-1])
continue;
tbl.rows[i].cells[1].innerHTML = `${linkS[pState[i-1]+1]}`;
if (!clicked[i] && pState[i - 1] < 0) {
document.getElementById('speed_sel_' + i).disabled = true;
document.getElementById('disable_port_' + i).checked = true;
}
}
}
async function applySpeed(port) {
var speed = document.getElementById('speed_sel_' + port).value;
var disabled = document.getElementById('disable_port_' + port).checked;
var cmd = "port " + port + " ";
if (!disabled)
cmd = cmd + speed;
else
cmd = cmd + "off";
console.log("CMD: " + cmd);
try {
const response = await fetch('/cmd', {
method: 'POST',
body: cmd
});
console.log('Completed!', response);
} catch(err) {
console.error(`Error: ${err}`);
}
}
async function portOnOff(p) {
var disabled = document.getElementById('disable_port_' + p).checked;
document.getElementById('speed_sel_' + p).disabled = disabled;
clicked[p] = 1;
}
async function applyMTU(port) {
var mtu = document.getElementById('mtu_sel_' + port).value;
var cmd = "mtu " + port + " " + mtu;
try {
const response = await fetch('/cmd', {
method: 'POST',
body: cmd
});
console.log('MTU Completed!', response);
getMTUs();
} catch(err) {
console.error(`Error: ${err}`);
}
}
function getMTUs() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
const s = JSON.parse(xhttp.responseText);
console.log("MTUS: ", JSON.stringify(s));
for (let i = 0; i < s.length; i++) {
p = s[i];
let n = p.portNum;
mtus[n] = parseInt(p.mtu, 16);
var mtu = document.getElementById('mtu_sel_' + n);
if (!mtu)
continue;
mtu.value = mtus[n];
clearInterval(pMTUInterval);
}
}
};
xhttp.open("GET", "/mtu.json", true);
xhttp.timeout = 1500; xhttp.send();
}
window.addEventListener("load", function() {
const updatePortTableInterval = setInterval(updatePortTable, 1000);
});
const pTableInterval = setInterval(createPortTable, 1000);
const pMTUInterval = setInterval(getMTUs, 1200);
+4 -2
View File
@@ -1,7 +1,9 @@
function fillStats() {
var tbl = document.getElementById('statstable');
if (!numPorts)
return;
if (tbl.rows.length > 1) {
for (let i = 0; i < 6; i++) {
for (let i = 0; i < numPorts; i++) {
console.log("Table Update row: " + i + " state " + pState[i] + " is " + linkS[pState[i] +1]);
tbl.rows[i+1].cells[1].innerHTML = `${linkS[pState[i]+1]}`;
tbl.rows[i+1].cells[2].innerHTML = `${txG[i]} pkts`;
@@ -10,7 +12,7 @@ function fillStats() {
tbl.rows[i+1].cells[5].innerHTML = `${rxB[i]} pkts`;
}
} else {
for (let i = 0; i < 6; i++) {
for (let i = 0; i < numPorts; i++) {
console.log("Table row: " + i);
const tr = tbl.insertRow();
let td = tr.insertCell(); td.appendChild(document.createTextNode(`Port ${i+1}`));
+2
View File
@@ -160,3 +160,5 @@ margin: 30px 0;
.tt_table td {
text-align: left;
}
select { text-align-last: right; font-family: monospace}
option { direction: rtl; font-family: sans-serif}
+2
View File
@@ -570,6 +570,8 @@ void httpd_appcall(void)
send_eee();
} else if (is_word(q, "/mirror.json")) {
send_mirror();
} else if (is_word(q, "/mtu.json")) {
send_mtu();
} else if (is_word(q, "/lag.json")) {
send_lag();
} else if (is_word(q, "/config")) {
+38
View File
@@ -380,6 +380,28 @@ void send_eee(void)
}
}
void send_mtu(void)
{
print_string("send_mtu called\n");
slen = strtox(outbuf, HTTP_RESPONCE_JSON);
char_to_html('[');
for (uint8_t i = machine.min_port; i <= machine.max_port; i++) {
slen += strtox(outbuf + slen, "{\"portNum\":");
itoa_html(machine.log_to_phys_port[i]);
slen += strtox(outbuf + slen, ",\"mtu\":\"0x");
reg_read_m(RTL8373_REG_MAC_L2_PORT_MAX_LEN + ((uint16_t) i << 8));
uint16_t mtu = SFR_DATA_U16 & 0x3fff;
byte_to_html(mtu >> 8);
byte_to_html(mtu & 0xff);
char_to_html('"');
char_to_html('}');
if (i < machine.max_port)
char_to_html(',');
else
char_to_html(']');
}
}
void send_status(void)
{
@@ -390,6 +412,8 @@ void send_status(void)
for (uint8_t i = machine.min_port; i <= machine.max_port; i++) {
slen += strtox(outbuf + slen, "{\"portNum\":");
itoa_html(machine.log_to_phys_port[i]);
slen += strtox(outbuf + slen, ",\"logPort\":");
itoa_html(i);
if (machine.is_sfp[i]) {
slen += strtox(outbuf + slen, ",\"isSFP\":1,\"enabled\":");
@@ -429,6 +453,20 @@ void send_status(void)
slen += strtox(outbuf + slen, ",\"isSFP\":0,\"enabled\":");
phy_read(i, 0x1f, 0xa610);
bool_to_html(SFR_DATA_8 == 0x20);
slen += strtox(outbuf + slen, ",\"adv\":\"");
phy_read(i, PHY_MMD_AN, 0x20);
uint16_t w = SFR_DATA_U16;
bool_to_html(!!(w & 0x80)); // 2500BaseN-Full
phy_read(i, PHY_MMD_CTRL, 0xa412);
w = SFR_DATA_U16;
bool_to_html(!!(w & 0x0200)); // 1000Base-Full
phy_read(i, PHY_MMD_AN, 0x10);
w = SFR_DATA_U16;
bool_to_html(!!(w & 0x0100)); // 100Base-Full
bool_to_html(!!(w & 0x80)); // 100Base-Half
bool_to_html(!!(w & 0x40)); // 10Base-Full
bool_to_html(!!(w & 0x20)); // 10Base-Half
char_to_html('"');
}
slen += strtox(outbuf + slen, ",\"link\":");
+1
View File
@@ -7,6 +7,7 @@ void send_vlan(uint16_t vlan);
void send_basic_info(void);
void send_eee(void);
void send_mirror(void);
void send_mtu(void);
void send_config(void);
void send_cmd_log(void);
void send_lag(void);
-1
View File
@@ -39,4 +39,3 @@ typedef struct machine {
};
#endif
+7 -1
View File
@@ -16,7 +16,6 @@
#define PHY_SDS_CTRL 30
#define PHY_MMD_CTRL 31
/*
* Define registers in Auto-Negotiation page
*/
@@ -34,4 +33,11 @@
* Define registers in Control page
*/
#define PHY_CTRL_5 0x7582
/*
* Duplex settings
*/
#define PHY_DUPLEX_HALF 0
#define PHY_DUPLEX_FULL 1
#define PHY_DUPLEX_BOTH 2
#endif
+17 -8
View File
@@ -184,8 +184,9 @@ void phy_config_8224(void) __banked
/*
* Set Speed of a PHY
* See e.g. RTL8221B datasheet
* duplex: 0: half, 1: full, 2: both
*/
void phy_set_speed(uint8_t port, uint8_t speed) __banked
void phy_set_speed(uint8_t port, uint8_t speed, uint8_t duplex) __banked
{
uint16_t v;
phy_read(port, PHY_MMD_CTRL, 0xa610);
@@ -213,11 +214,21 @@ void phy_set_speed(uint8_t port, uint8_t speed) __banked
phy_write(port, PHY_MMD_AN, 0x00, 0x2000); // Clear bit 12: No Autoneg, Set Extended Pages (bit 13)
if (speed == PHY_SPEED_10M) {
phy_write(port, PHY_MMD_AN, 0x20, 0x6001);
phy_write(port, PHY_MMD_AN, 0x10, 0x1461);
if (!duplex)
phy_write(port, PHY_MMD_AN, 0x10, 0x1421);
else if (duplex == 1)
phy_write(port, PHY_MMD_AN, 0x10, 0x1441);
else
phy_write(port, PHY_MMD_AN, 0x10, 0x1461);
phy_modify(port, PHY_MMD_CTRL, 0xa412, 0x0200, 0x0000);
} else if (speed == PHY_SPEED_100M) {
phy_write(port, PHY_MMD_AN, 0x20, 0x6001);
phy_write(port, PHY_MMD_AN, 0x10, 0x1581);
if (!duplex)
phy_write(port, PHY_MMD_AN, 0x10, 0x1481);
if (duplex == 1)
phy_write(port, PHY_MMD_AN, 0x10, 0x1501);
else
phy_write(port, PHY_MMD_AN, 0x10, 0x1581);
phy_modify(port, PHY_MMD_CTRL, 0xa412, 0x0200, 0x0000);
} else {
// AN Advertisement Register (MMD 7.0x0010)
@@ -286,8 +297,7 @@ void phy_show(uint8_t port) __banked
print_string("\nLink speed: ");
phy_read(port, PHY_MMD_CTRL, 0xA434);
v = SFR_DATA_U16;
v = ((v & 0x0600) >> 7) | ((v & 0x0030) >> 4);
switch(v) {
switch(((v & 0x0600) >> 7) | ((v & 0x0030) >> 4)) {
case 0:
print_string("10M");
break;
@@ -366,7 +376,7 @@ void phy_show(uint8_t port) __banked
print_string("\nAN enabled, advertising:");
phy_read(port, PHY_MMD_AN, 0x10);
v = SFR_DATA_U16;
if (v & 0x0040)
if (v & 0x0020)
print_string(" 10Base-Half");
if (v & 0x0040)
print_string(" 10Base-Full");
@@ -378,11 +388,10 @@ void phy_show(uint8_t port) __banked
v = SFR_DATA_U16;
if (v & 0x0200)
print_string(" 1000Base-Full");
phy_read(port, PHY_MMD_AN, 0x10);
phy_read(port, PHY_MMD_AN, 0x20);
v = SFR_DATA_U16;
if (v & 0x0080)
print_string(" 2500BaseN-Full");
}
phy_read(port, PHY_MMD_AN, 0x13);
v = SFR_DATA_U16;
+1 -1
View File
@@ -13,7 +13,7 @@
void rtl8224_phy_enable(void) __banked;
void phy_config(uint8_t phy) __banked;
void phy_config_8224(void) __banked;
void phy_set_speed(uint8_t port, uint8_t speed) __banked;
void phy_set_speed(uint8_t port, uint8_t speed, uint8_t duplex) __banked;
void phy_set_duplex(uint8_t port, uint8_t fullduplex) __banked;
void phy_show(uint8_t port) __banked;
void phy_reset(uint8_t port) __banked;
+2
View File
@@ -136,6 +136,8 @@
#define RTL837x_L2_TBL_FLUSH_CNF 0x53dc
#define RTL837X_L2_LRN_PORT_CONSTRAINT 0x5384
#define RTL837X_L2_LRN_PORT_CONSTRT_ACT 0x4f80
#define RTL8373_REG_MAC_L2_PORT_MAX_LEN 0x1250
/*
* VLAN configuration
*/
+51 -3
View File
@@ -15,7 +15,15 @@
#define PASSWORD "1234"
#define SESSION_TIMEOUT 2000
#define PORTS 6
#define PORTS 9
#define NSFP 1
#if PORTS == 9
const uint8_t physToLogPort[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8};
#else
const uint8_t physToLogPort[] = { 4, 5, 6, 7, 3, 8};
#endif
time_t last_called;
time_t last_session_use;
@@ -125,7 +133,8 @@ void send_status(int s)
for (int i = 1; i <= PORTS; i++) {
v = json_object_new_object();
json_object_object_add(v, "portNum", json_object_new_int(i));
json_object_object_add(v, "isSFP", json_object_new_int(i < 5 ? 0 : 1));
json_object_object_add(v, "logPort", json_object_new_int(physToLogPort[i-1]));
json_object_object_add(v, "isSFP", json_object_new_int(i <= PORTS - NSFP ? 0 : 1));
json_object_object_add(v, "enabled", json_object_new_int((i % 4) ? 1 : 0));
json_object_object_add(v, "link", json_object_new_int(i % 2 ? ((i == 1)? 5 : 2) : 0));
if (i % 2) {
@@ -143,7 +152,7 @@ void send_status(int s)
json_object_object_add(v, "txB", json_object_new_string(txB_buff));
json_object_object_add(v, "rxG", json_object_new_string(rxG_buff));
json_object_object_add(v, "rxB", json_object_new_string(rxB_buff));
if (i >= 5) {
if (i >= PORTS - NSFP) {
uint16_t temp = 0x28fb + rand() / (RAND_MAX / 100);
uint16_t vcc = 0x7eda + rand() / (RAND_MAX / 100);
uint16_t txbias = 0x0d24 +rand() / (RAND_MAX / 100);
@@ -169,6 +178,14 @@ void send_status(int s)
json_object_object_add(v, "sfp_txpower", json_object_new_string(sfp_txpower));
json_object_object_add(v, "sfp_rxpower", json_object_new_string(sfp_rxpower));
json_object_object_add(v, "sfp_laser", json_object_new_string(sfp_laser));
} else {
if (i == 1)
json_object_object_add(v, "adv", json_object_new_string("100000"));
else if (i==2)
json_object_object_add(v, "adv", json_object_new_string("000011"));
else
json_object_object_add(v, "adv", json_object_new_string("000100"));
}
json_object_array_add(ports, v);
}
@@ -269,6 +286,30 @@ void send_lag(int s)
}
void send_mtu(int s)
{
struct json_object *mtus, *v;
const char *jstring;
char *header = "HTTP/1.1 200 OK\r\n"
"Content-Type: application/json; charset=UTF-8\r\n\r\n";
mtus = json_object_new_array_ext(PORTS);
char mtu[8];
for (int i = 1; i <= PORTS; i++) {
v = json_object_new_object();
json_object_object_add(v, "portNum", json_object_new_int(i));
sprintf(mtu, "0x%04x", i % 2 ? 16383 : 1522);
json_object_object_add(v, "mtu", json_object_new_string(mtu));
json_object_array_add(mtus, v);
}
write(s, header, strlen(header));
jstring = json_object_to_json_string_ext(mtus, JSON_C_TO_STRING_PLAIN);
write(s, jstring, strlen(jstring));
json_object_put(mtus);
}
void send_cmd_log(int s)
{
char *header = "HTTP/1.1 200 OK\r\n"
@@ -477,6 +518,13 @@ void launch(struct Server *server)
else
send_lag(new_socket);
goto done;
} else if (!strncmp(&buffer[4], "/mtu.json", 9)) {
printf("MTU request\n");
if (!authenticated)
send_unauthorized(new_socket);
else
send_mtu(new_socket);
goto done;
} else if (!strncmp(&buffer[4], "/vlan.json?vid=", 15)) {
int vlan = atoi(&buffer[19]);
printf("VLAN request for %d\n", vlan);