mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
Add fetching of configuration file and current cmd history
This commit is contained in:
+41
-12
@@ -42,7 +42,8 @@ __xdata uint8_t *content_type = 0;
|
|||||||
|
|
||||||
// Global variables holding POST state
|
// Global variables holding POST state
|
||||||
__xdata uint16_t bindex; // Current index into the boundary
|
__xdata uint16_t bindex; // Current index into the boundary
|
||||||
|
__xdata uint8_t verify_crc;
|
||||||
|
__xdata uint32_t max_upload;
|
||||||
__xdata uint16_t short_parsed;
|
__xdata uint16_t short_parsed;
|
||||||
|
|
||||||
#define TSTATE_NONE 0
|
#define TSTATE_NONE 0
|
||||||
@@ -232,14 +233,21 @@ uint8_t stream_upload(uint16_t bptr)
|
|||||||
uptr += write_len;
|
uptr += write_len;
|
||||||
write_len = 0;
|
write_len = 0;
|
||||||
// TODO: This is a bit premature, what about a nice web-page saying the device will reset???
|
// TODO: This is a bit premature, what about a nice web-page saying the device will reset???
|
||||||
print_string("CRC16: "); print_short(crc_final); write_char('\n');
|
if (verify_crc) {
|
||||||
if (crc_final == 0xb001) {
|
print_string("CRC16: "); print_short(crc_final); write_char('\n');
|
||||||
print_string("Checksum OK.");
|
if (crc_final == 0xb001) {
|
||||||
} else {
|
print_string("Checksum OK.");
|
||||||
print_string("Checksum incorrect!");
|
} else {
|
||||||
|
print_string("Checksum incorrect!");
|
||||||
|
}
|
||||||
|
print_string("Upload to flash done, will reset!\n");
|
||||||
|
reset_chip();
|
||||||
}
|
}
|
||||||
print_string("Upload to flash done, will reset!\n");
|
// Make sure there is a 0 at the end of the uploaded data
|
||||||
reset_chip();
|
flash_buf[0] = 0;
|
||||||
|
flash_region.addr = uptr;
|
||||||
|
flash_region.len = 1;
|
||||||
|
flash_write_bytes(flash_buf);
|
||||||
if (bptr >= uip_len)
|
if (bptr >= uip_len)
|
||||||
return 0;
|
return 0;
|
||||||
return 1;
|
return 1;
|
||||||
@@ -309,8 +317,8 @@ void handle_post(void)
|
|||||||
cmd_buffer[i] = '\0';
|
cmd_buffer[i] = '\0';
|
||||||
if (i)
|
if (i)
|
||||||
cmd_available = 1;
|
cmd_available = 1;
|
||||||
} else if (is_word(request_path, "upload")) {
|
} else if (is_word(request_path, "upload") || is_word(request_path, "config")) {
|
||||||
print_string("POST upload request\n");
|
print_string("POST upload/config request\n");
|
||||||
if (!boundary[0]) {
|
if (!boundary[0]) {
|
||||||
print_string("Bad request, no boundary!\n");
|
print_string("Bad request, no boundary!\n");
|
||||||
send_bad_request();
|
send_bad_request();
|
||||||
@@ -330,7 +338,18 @@ void handle_post(void)
|
|||||||
print_string("Have content octets\n");
|
print_string("Have content octets\n");
|
||||||
p += 4; // Skip \r\n\r\n sequence at end of preamble of part
|
p += 4; // Skip \r\n\r\n sequence at end of preamble of part
|
||||||
|
|
||||||
uptr = FIRMWARE_UPLOAD_START;
|
if (is_word(request_path, "upload")) {
|
||||||
|
uptr = FIRMWARE_UPLOAD_START;
|
||||||
|
verify_crc = 1;
|
||||||
|
max_upload = 1024576;
|
||||||
|
} else {
|
||||||
|
print_string("Configuration upload, erasing config mem!\n");
|
||||||
|
uptr = CONFIG_START;
|
||||||
|
verify_crc = 0;
|
||||||
|
max_upload = 2048;
|
||||||
|
flash_region.addr = CONFIG_START;
|
||||||
|
flash_sector_erase();
|
||||||
|
}
|
||||||
crc_value = 0;
|
crc_value = 0;
|
||||||
bindex = 0;
|
bindex = 0;
|
||||||
write_len = 0;
|
write_len = 0;
|
||||||
@@ -407,7 +426,13 @@ void httpd_appcall(void)
|
|||||||
s->tstate = TSTATE_TX;
|
s->tstate = TSTATE_TX;
|
||||||
}
|
}
|
||||||
} else if (uip_newdata() && s->tstate == TSTATE_POST) {
|
} else if (uip_newdata() && s->tstate == TSTATE_POST) {
|
||||||
stream_upload(0);
|
// Check here maxupload by subtracting uip_len and close socekt if fails!
|
||||||
|
if (max_upload - uip_len > 0) {
|
||||||
|
stream_upload(0);
|
||||||
|
} else {
|
||||||
|
send_bad_request();
|
||||||
|
goto do_send;
|
||||||
|
}
|
||||||
} else if (uip_newdata() && s->tstate != TSTATE_TX) {
|
} else if (uip_newdata() && s->tstate != TSTATE_TX) {
|
||||||
cont_len = 0;
|
cont_len = 0;
|
||||||
write_char('<'); print_short(uip_len); write_char('\n');
|
write_char('<'); print_short(uip_len); write_char('\n');
|
||||||
@@ -456,6 +481,10 @@ void httpd_appcall(void)
|
|||||||
send_eee();
|
send_eee();
|
||||||
} else if (is_word(q, "/mirror.json")) {
|
} else if (is_word(q, "/mirror.json")) {
|
||||||
send_mirror();
|
send_mirror();
|
||||||
|
} else if (is_word(q, "/config")) {
|
||||||
|
send_config();
|
||||||
|
} else if (is_word(q, "/cmd_log")) {
|
||||||
|
send_cmd_log();
|
||||||
} else {
|
} else {
|
||||||
send_not_found();
|
send_not_found();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "../rtl837x_common.h"
|
#include "../rtl837x_common.h"
|
||||||
#include "../rtl837x_regs.h"
|
#include "../rtl837x_regs.h"
|
||||||
#include "../rtl837x_port.h"
|
#include "../rtl837x_port.h"
|
||||||
|
#include "../rtl837x_flash.h"
|
||||||
#include "uip.h"
|
#include "uip.h"
|
||||||
#include "../html_data.h"
|
#include "../html_data.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -15,6 +16,8 @@
|
|||||||
|
|
||||||
extern __xdata uint8_t outbuf[TCP_OUTBUF_SIZE];
|
extern __xdata uint8_t outbuf[TCP_OUTBUF_SIZE];
|
||||||
extern __xdata uint16_t slen;
|
extern __xdata uint16_t slen;
|
||||||
|
extern __xdata uint16_t cont_len;
|
||||||
|
extern __xdata uint32_t cont_addr;
|
||||||
extern __code uint8_t * __code hex;
|
extern __code uint8_t * __code hex;
|
||||||
extern __xdata uip_ipaddr_t uip_hostaddr, uip_draddr, uip_netmask;
|
extern __xdata uip_ipaddr_t uip_hostaddr, uip_draddr, uip_netmask;
|
||||||
extern __code struct uip_eth_addr uip_ethaddr;
|
extern __code struct uip_eth_addr uip_ethaddr;
|
||||||
@@ -30,7 +33,13 @@ extern __xdata uint8_t isRTL8373;
|
|||||||
extern __xdata uint8_t sfp_pins_last;
|
extern __xdata uint8_t sfp_pins_last;
|
||||||
extern __xdata uint8_t vlan_names[VLAN_NAMES_SIZE];
|
extern __xdata uint8_t vlan_names[VLAN_NAMES_SIZE];
|
||||||
|
|
||||||
|
extern __xdata uint8_t cmd_history[CMD_HISTORY_SIZE];
|
||||||
|
extern __xdata uint16_t cmd_history_ptr;
|
||||||
|
|
||||||
|
extern __xdata struct flash_region_t flash_region;
|
||||||
|
|
||||||
__code uint8_t * __code HTTP_RESPONCE_JSON = "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n";
|
__code uint8_t * __code HTTP_RESPONCE_JSON = "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\n\r\n";
|
||||||
|
__code uint8_t * __code HTTP_RESPONCE_TXT = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\n";
|
||||||
|
|
||||||
/* Convert only the lower nibble to ascii HEX char.
|
/* Convert only the lower nibble to ascii HEX char.
|
||||||
For convenience the upper nibble is masked out.
|
For convenience the upper nibble is masked out.
|
||||||
@@ -371,3 +380,46 @@ void send_status(void)
|
|||||||
char_to_html(']');
|
char_to_html(']');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void send_config(void)
|
||||||
|
{
|
||||||
|
print_string("send_config called\n");
|
||||||
|
__xdata uint32_t pos = CONFIG_START; // 70000 , 6c000 / 0xc000 = 9
|
||||||
|
|
||||||
|
extern __xdata uint16_t len_left = CONFIG_LEN;
|
||||||
|
slen = strtox(outbuf, HTTP_RESPONCE_TXT);
|
||||||
|
while (read_flash((CONFIG_START-CODE0_SIZE) / CODE_BANK_SIZE + 1,
|
||||||
|
(__code uint8_t *) (((CONFIG_START + len_left - CODE0_SIZE) % CODE_BANK_SIZE) + CODE0_SIZE + len_left)) == 0xff) {
|
||||||
|
print_short(len_left);
|
||||||
|
len_left--;
|
||||||
|
}
|
||||||
|
len_left++;
|
||||||
|
|
||||||
|
if (len_left > (TCP_OUTBUF_SIZE - slen)) {
|
||||||
|
cont_len = len_left - (TCP_OUTBUF_SIZE - slen);
|
||||||
|
len_left = TCP_OUTBUF_SIZE - slen;
|
||||||
|
cont_addr = len_left;
|
||||||
|
}
|
||||||
|
flash_region.addr = CONFIG_START;
|
||||||
|
flash_region.len = len_left;
|
||||||
|
flash_read_bulk(outbuf + slen);
|
||||||
|
slen += len_left;
|
||||||
|
}
|
||||||
|
|
||||||
|
void send_cmd_log(void)
|
||||||
|
{
|
||||||
|
print_string("send_cmd_log called\n");
|
||||||
|
slen = strtox(outbuf, HTTP_RESPONCE_TXT);
|
||||||
|
__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) {
|
||||||
|
if (!cmd_history[p] || cmd_history[p] == '\n')
|
||||||
|
found_begin = 1;
|
||||||
|
if (found_begin && cmd_history[p])
|
||||||
|
outbuf[slen++] = cmd_history[p];
|
||||||
|
p = (p + 1) & CMD_HISTORY_MASK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,5 +7,7 @@ void send_vlan(register uint16_t vlan);
|
|||||||
void send_basic_info(void);
|
void send_basic_info(void);
|
||||||
void send_eee(void);
|
void send_eee(void);
|
||||||
void send_mirror(void);
|
void send_mirror(void);
|
||||||
|
void send_config(void);
|
||||||
|
void send_cmd_log(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user