Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 50 additions & 11 deletions cmd_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
// #define DEBUG
// #define REGDBG 1

#define CONFIG_START 0x70000
#define CONFIG_LEN 0x1000

#include "rtl837x_common.h"
#include "rtl837x_port.h"
#include "rtl837x_flash.h"
Expand Down Expand Up @@ -53,12 +50,16 @@ __xdata uint8_t cmd_available;
__xdata uint8_t l;
__xdata uint8_t line_ptr;
__xdata char is_white;
__xdata char save_cmd;

__xdata uint8_t ip[4];

#define N_WORDS SBUF_SIZE
__xdata signed char cmd_words_b[N_WORDS];

__xdata uint8_t cmd_history[CMD_HISTORY_SIZE];
__xdata uint16_t cmd_history_ptr;

// Maps the physical port (starting from 0) to the logical port
__code uint8_t phys_to_log_port[6] = {
4, 5, 6, 7, 3, 8
Expand Down Expand Up @@ -695,21 +696,52 @@ void cmd_parser(void) __banked
port_eee_status_all();
}
}
if (cmd_compare(0, "history")) {
__xdata uint16_t p = (cmd_history_ptr + 1) & CMD_HISTORY_MASK;
__xdata uint8_t found_begin = 0;
print_string("History ptr: ");
print_short(cmd_history_ptr); write_char('\n');
while (p != cmd_history_ptr) {
print_short(p); write_char(' ');
if (!cmd_history[p] || cmd_history[p] == '\n')
found_begin = 1;
if (found_begin && cmd_history[p])
write_char(cmd_history[p]);
p = (p + 1) & CMD_HISTORY_MASK;
}
}
if (save_cmd) {
uint8_t i;
for (i = 0; i < N_WORDS; i++) {
if (cmd_words_b[i] < 0)
break;
}
if (i < N_WORDS) {
i = cmd_words_b[--i];
cmd_history_ptr = (cmd_history_ptr + i) & CMD_HISTORY_MASK;
__xdata uint16_t p = cmd_history_ptr;
cmd_history[cmd_history_ptr++] = '\n';
do {
i--;
cmd_history[--p & CMD_HISTORY_MASK] = cmd_buffer[i];
} while (i);
}
}
}
}

#define FLASH_READ_BURST_SIZE 0x100;
void execute_config(void) __banked
{
memcpyc(flash_buf, "test", 5);
print_string_x(flash_buf);
__xdata uint32_t pos = CONFIG_START;
__xdata uint16_t len_left = CONFIG_LEN;

save_cmd = 0;

__xdata uint32_t pos = CONFIG_START;
__xdata uint16_t len_left = CONFIG_LEN;
do {
do {
flash_region.addr = pos;
flash_region.len = FLASH_READ_BURST_SIZE;
write_char('-'); print_long(flash_region.addr); write_char(':'); print_short(flash_region.len); write_char('\n');
write_char('-'); print_long(flash_region.addr); write_char(':'); print_short(flash_region.len); write_char('\n');

flash_read_bulk(flash_buf);

Expand All @@ -726,7 +758,7 @@ void execute_config(void) __banked
if (cmd_idx && !cmd_tokenize())
cmd_parser();
if (c == 0)
return;
goto config_done;
break;
}

Expand All @@ -737,5 +769,12 @@ void execute_config(void) __banked

len_left -= FLASH_READ_BURST_SIZE;
pos += FLASH_READ_BURST_SIZE;
} while(len_left);
} while(len_left);

config_done:
// Start saving commands to cmd_history
save_cmd = 1;
for (cmd_history_ptr = 0; cmd_history_ptr < CMD_HISTORY_SIZE; cmd_history_ptr++)
cmd_history[cmd_history_ptr] = 0;
cmd_history_ptr = 0;
}
1 change: 1 addition & 0 deletions html/config
41 changes: 41 additions & 0 deletions html/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
var configInterval = Number();
var configuration = {};

function parseConf(c){
var a = s.split(/\r\n|\n/);
for (var l = 0; l < a.length; l++) {
console.log(l + ' --> ' + a[l]);
}
}

function fetchConfig() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
s = xhttp.responseText;
console.log("CONFIG: ", s);
parseConf(s);
clearInterval(configInterval);
}
}
xhttp.open("GET", `/config`, true);
xhttp.send();
}

function fetchCmdLog() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
s = xhttp.responseText;
console.log("CMD-Log: ", s);
parseConf(s);
clearInterval(configInterval);
}
}
xhttp.open("GET", `/cmd_log`, true);
xhttp.send();
}

window.addEventListener("load", function() {
configInterval = setInterval(fetchConfig, 1000);
});
1 change: 1 addition & 0 deletions html/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ document.getElementById('sidebar').innerHTML =
+ "<li><a href='mirror.html'>Mirroring</a></li>"
+ "<li><a href='trunk.html'>Port Aggregation</a></li>"
+ "<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>";

8 changes: 7 additions & 1 deletion html/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ input[type=submit] { padding: 8px 16px;background-color:#aaf;color:#000; margin-
input[type=submit]:hover { background-color: #226; color: white;}
button {padding: 8px; background-color:#99f; color:#000;}
button:hover { background-color: #226; color: white;}
.action{padding: 8px 16px;margin-top: 2em;margin-right: 3em; background-color: #aaf;color: #000;}
.action:hover { background-color: #226; color: white;}

.psel {
position: absolute;
opacity: 0;
Expand Down Expand Up @@ -73,4 +76,7 @@ object {
.isSFP{ opacity: .4; background-color: #660;}
.isNOK{ color: #900;}
.isOK{ color: #090;}
.action{padding: 8px 16px;margin-top: 2em;margin-right: 3em; background-color: #aaf;color: #000;}
.ip{padding:8px 16px;margin-bottom: 1em;margin-left: 1em}
.row {display: flex;}
.rcol {flex: 90%;}
.lcol {flex: 10%;}
36 changes: 36 additions & 0 deletions html/system.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<title>System Settings</title>
</head>
<body>
<nav id="sidebar"></nav>
<div style="margin-left:16%;padding:1px 16px;height:1000px;">
<div id="ports"></div>
<h1>System Settings</h1>
<div class="row">
<div class="lcol"> <label for="ip">IP address:</label></div>
<div class="rcol"> <input id="ip" class="ip" type="text" minlength="7" maxlength="15" size="15"/></div>
</div>
<div class="row">
<div class="lcol"> <label for="nm">Netmask:</label></div>
<div class="rcol"><input id="nm" class="ip" type="text" minlength="7" maxlength="15" size="15"/></div>
</div>
<div class="row">
<div class="lcol"> <label for="gw">Gateway:</label></div>
<div class="rcol"><input id="gw" class="ip" type="text" minlength="7" maxlength="15" size="15"/></div>
</div>
<br/><br/>
When updating the above settings, remember to point your browser to the new IP afterwards:<br/>
<input style="width:40%;" class="action" id="ip_sub" onclick="ipSub();" type="button" value="Update Settings"><br/>
<br/><br/>
Save all current settings to Flash:<br/>
<input style="width:40%;" class="action" id="flash_sub" onclick="flashSave();" type="button" value="Save Settings to Flash">

</div>
<script src="/config.js"></script>
<script src="/system.js"></script>
<script src="/navigation.js"></script>
</body>
</html>
62 changes: 62 additions & 0 deletions html/system.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
var systemInterval = Number();
const ips = ["ip", "nm", "gw"];

function checkIp(ip) {
const ipv4 = /^(\d{1,3}\.){3}\d{1,3}$/;
if (!ipv4.test(ip)) {alert(`Invalid ip:${ip}`); return false };
return true;
}

async function ipSub() {
for (let i=0;i<3;i++) {
if (!checkIp(document.getElementById(ips[i]).value))
return;
}
for (let i=0; i<3;i++){
var cmd = ips[i]+' '+document.getElementById(ips[i]).value;
try {
const response = await fetch('/cmd', {
method: 'POST',
body: cmd
});
console.log('Completed!', response);
} catch(err) {
console.error(`Error: ${err}`);
}
}
}

async function flashSave() {
fetchConfig();
fetchCmdLog();
return;
try {
const response = await fetch('/save', {
method: 'POST',
body: cmd
});
console.log('Completed!', response);
} catch(err) {
console.error(`Error: ${err}`);
}
}

function fetchIP() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
const s = JSON.parse(xhttp.responseText);
console.log("IP: ", s);
document.getElementById("ip").value=s.ip_address;
document.getElementById("nm").value=s.ip_netmask;
document.getElementById("gw").value=s.ip_gateway;
clearInterval(systemInterval);
}
}
xhttp.open("GET", `/information.json`, true);
xhttp.send();
}

window.addEventListener("load", function() {
systemInterval = setInterval(fetchIP, 1000);
});
26 changes: 23 additions & 3 deletions httpd/httpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ __xdata uint16_t slen;
__xdata uint16_t o_idx;
__xdata uint16_t mpos;
__xdata uint16_t len_left;
__xdata uint16_t cont_len;
__xdata uint32_t cont_addr;

// HTTP header properties
__xdata uint8_t boundary[72];
Expand Down Expand Up @@ -386,12 +388,22 @@ void httpd_appcall(void)
if (slen > uip_mss()) {
print_string("Sending A: "); print_short(slen); write_char('\n');
uip_send(outbuf + o_idx, uip_mss());
print_string("Sending A done\n");
s->tstate = TSTATE_TX;
} else if (slen > 0) {
print_string("Sending B: "); print_short(slen); write_char('\n');
uip_send(outbuf + o_idx, slen);
print_string("Sending B done\n");
s->tstate = TSTATE_TX;
} else if (cont_len) {
print_string("CONT cont_len: "); print_short(cont_len);
slen = cont_len > uip_mss() ? uip_mss() : cont_len;
if (slen > TCP_OUTBUF_SIZE)
slen = TCP_OUTBUF_SIZE;
flash_region.addr = cont_addr;
flash_region.len = slen;
flash_read_bulk(outbuf);
uip_send(outbuf, slen);
cont_len -= slen;
cont_addr += slen;
s->tstate = TSTATE_TX;
}
} else if (uip_newdata() && s->tstate == TSTATE_POST) {
Expand Down Expand Up @@ -443,6 +455,10 @@ void httpd_appcall(void)
send_eee();
} else if (is_word(q, "/mirror.json")) {
send_mirror();
} else if (is_word(q, "/config")) {
send_config();
} else if (is_word(q, "/cmd_log")) {
send_cmd_log();
} else {
send_not_found();
}
Expand All @@ -452,7 +468,11 @@ void httpd_appcall(void)
slen += strtox(outbuf + slen, mime_strings[f_data[entry].mime]);
slen += strtox(outbuf + slen, "\r\nCache-Control: max-age=2592000\r\n\r\n");
len_left = f_data[entry].len;

if (len_left > (TCP_OUTBUF_SIZE - slen)) {
cont_len = len_left - (TCP_OUTBUF_SIZE - slen);
len_left = TCP_OUTBUF_SIZE - slen;
cont_addr = f_data[entry].start + len_left;
}
print_string("MIME: "); print_string(mime_strings[f_data[entry].mime]); write_char('\n');
flash_region.addr = f_data[entry].start;
flash_region.len = len_left;
Expand Down
Loading