mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
Make dhcp client implementation available
This commit is contained in:
@@ -21,7 +21,7 @@ all: create_build_dir $(VERSION_HEADER) $(SUBDIRS) $(BUILDDIR)rtlplayground.bin
|
||||
create_build_dir:
|
||||
mkdir -p $(BUILDDIR)
|
||||
|
||||
SRCS = rtlplayground.c rtl837x_flash.c rtl837x_phy.c rtl837x_port.c cmd_parser.c html_data.c rtl837x_igmp.c rtl837x_stp.c machine.c
|
||||
SRCS = rtlplayground.c rtl837x_flash.c rtl837x_phy.c rtl837x_port.c cmd_parser.c html_data.c rtl837x_igmp.c rtl837x_stp.c dhcp.c machine.c
|
||||
OBJS = ${SRCS:%.c=$(BUILDDIR)%.rel}
|
||||
OBJS += uip/$(BUILDDIR)/timer.rel uip/$(BUILDDIR)/uip-fw.rel uip/$(BUILDDIR)/uip-neighbor.rel uip/$(BUILDDIR)/uip-split.rel uip/$(BUILDDIR)/uip.rel uip/$(BUILDDIR)/uip_arp.rel uip/$(BUILDDIR)/uiplib.rel httpd/$(BUILDDIR)/httpd.rel httpd/$(BUILDDIR)/page_impl.rel
|
||||
|
||||
|
||||
+50
-10
@@ -13,6 +13,7 @@
|
||||
#include "rtl837x_sfr.h"
|
||||
#include "rtl837x_stp.h"
|
||||
#include "rtl837x_igmp.h"
|
||||
#include "dhcp.h"
|
||||
#include "uip/uip.h"
|
||||
#include "version.h"
|
||||
|
||||
@@ -37,6 +38,8 @@ extern __xdata struct flash_region_t flash_region;
|
||||
|
||||
extern __xdata char passwd[21];
|
||||
|
||||
extern __xdata struct dhcp_state dhcp_state;
|
||||
|
||||
__xdata uint8_t vlan_names[VLAN_NAMES_SIZE];
|
||||
__xdata uint16_t vlan_ptr;
|
||||
__xdata uint8_t gpio_last_value[8] = { 0 };
|
||||
@@ -149,6 +152,7 @@ uint8_t atoi_hex(uint8_t idx)
|
||||
return ((h_idx + 1) >> 1);
|
||||
}
|
||||
|
||||
|
||||
uint8_t atoi_short(register uint16_t *vlan, register uint8_t idx)
|
||||
{
|
||||
uint8_t err = 1;
|
||||
@@ -774,28 +778,64 @@ void cmd_parser(void) __banked
|
||||
} 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]))
|
||||
uip_ipaddr(&uip_hostaddr, ip[0], ip[1], ip[2], ip[3]);
|
||||
else
|
||||
print_string("Invalid IP address\n");
|
||||
print_byte(ip[0]); print_byte(ip[1]); print_byte(ip[2]); print_byte(ip[3]);
|
||||
if (cmd_words_b[2] > 0 && cmd_compare(1, "dhcp")) {
|
||||
dhcp_start();
|
||||
} else if (cmd_words_b[2] < 0) {
|
||||
print_string("Current IP: ");
|
||||
itoa(uip_hostaddr[0]); write_char('.'); itoa(uip_hostaddr[0] >> 8); write_char('.');
|
||||
itoa(uip_hostaddr[1]); write_char('.'); itoa(uip_hostaddr[1] >> 8);
|
||||
if (dhcp_state.state == DHCP_LEASING) {
|
||||
print_string(" (dhcp, renewal in sec: ");
|
||||
print_short(dhcp_state.dhcp_timer);
|
||||
write_char(')');
|
||||
} else {
|
||||
print_string(" (static)");
|
||||
}
|
||||
write_char('\n');
|
||||
} else {
|
||||
if (dhcp_state.state)
|
||||
dhcp_stop();
|
||||
if (!parse_ip(cmd_words_b[1])) {
|
||||
uip_ipaddr(&uip_hostaddr, ip[0], ip[1], ip[2], ip[3]);
|
||||
print_string("Setting ip: ");
|
||||
itoa(ip[0]); write_char('.'); itoa(ip[1]); write_char('.');
|
||||
itoa(ip[2]); write_char('.'); itoa(ip[3]); write_char('\n');
|
||||
} else {
|
||||
print_string("Invalid IP address\n");
|
||||
print_string("Error: ip [<ip-address>|dhcp]\n");
|
||||
print_string(" The dhcp option enables the dhcp client, calling ip without options prints the current IP\n");
|
||||
print_string(" Calling with a valid IP address will stop any ongoing dhcp client and set the IP address\n");
|
||||
}
|
||||
}
|
||||
} else if (cmd_compare(0, "gw")) {
|
||||
print_string("Got gw command: ");
|
||||
if (cmd_words_b[2] < 0) {
|
||||
print_string("Current gw: ");
|
||||
itoa(uip_draddr[0]); write_char('.'); itoa(uip_draddr[0] >> 8); write_char('.');
|
||||
itoa(uip_draddr[1]); write_char('.'); itoa(uip_draddr[1] >> 8);
|
||||
} else {
|
||||
if (!parse_ip(cmd_words_b[1]))
|
||||
uip_ipaddr(&uip_draddr, ip[0], ip[1], ip[2], ip[3]);
|
||||
else
|
||||
print_string("Invalid IP address\n");
|
||||
print_byte(ip[0]); print_byte(ip[1]); print_byte(ip[2]); print_byte(ip[3]);
|
||||
print_string("Setting gw: ");
|
||||
itoa(ip[0]); write_char('.'); itoa(ip[1]); write_char('.');
|
||||
itoa(ip[2]); write_char('.'); itoa(ip[3]);
|
||||
}
|
||||
write_char('\n');
|
||||
} else if (cmd_compare(0, "netmask")) {
|
||||
print_string("Got netmask command: ");
|
||||
if (cmd_words_b[2] < 0) {
|
||||
print_string("Current netmask: ");
|
||||
itoa(uip_netmask[0]); write_char('.'); itoa(uip_netmask[0] >> 8); write_char('.');
|
||||
itoa(uip_netmask[1]); write_char('.'); itoa(uip_netmask[1] >> 8);
|
||||
} else {
|
||||
if (!parse_ip(cmd_words_b[1]))
|
||||
uip_ipaddr(&uip_netmask, ip[0], ip[1], ip[2], ip[3]);
|
||||
else
|
||||
print_string("Invalid IP address\n");
|
||||
print_byte(ip[0]);print_byte(ip[1]);print_byte(ip[2]);print_byte(ip[3]);
|
||||
print_string("Setting netmask: ");
|
||||
itoa(ip[0]); write_char('.'); itoa(ip[1]); write_char('.');
|
||||
itoa(ip[2]); write_char('.'); itoa(ip[3]);
|
||||
}
|
||||
write_char('\n');
|
||||
} else if (cmd_compare(0, "l2")) {
|
||||
if (cmd_words_b[1] > 0 && cmd_compare(1, "forget"))
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "rtl837x_port.h"
|
||||
#include "rtl837x_stp.h"
|
||||
#include "rtl837x_igmp.h"
|
||||
#include "dhcp.h"
|
||||
#include "cmd_parser.h"
|
||||
#include "uip/uipopt.h"
|
||||
#include "uip/uip.h"
|
||||
@@ -80,6 +81,7 @@ volatile __xdata uint32_t ticks;
|
||||
volatile __xdata uint8_t sec_counter;
|
||||
volatile __xdata uint16_t sleep_ticks;
|
||||
__xdata uint8_t stp_clock;
|
||||
extern __xdata struct dhcp_state dhcp_state;
|
||||
|
||||
#define STP_TICK_DIVIDER 3
|
||||
|
||||
@@ -926,6 +928,10 @@ void handle_rx(void)
|
||||
uip_arp_out();
|
||||
tcpip_output();
|
||||
}
|
||||
} else {
|
||||
#ifdef RXTXDBG
|
||||
print_string("Unknown RX on port "); print_byte(rx_headers[3] & 0xf); write_char('\n');
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -943,6 +949,13 @@ void handle_tx(void)
|
||||
tcpip_output();
|
||||
}
|
||||
}
|
||||
for(uint8_t i = 0; i < UIP_UDP_CONNS; i++) {
|
||||
uip_udp_periodic(i);
|
||||
if(uip_len > 0) {
|
||||
uip_arp_out();
|
||||
tcpip_output();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1755,6 +1768,7 @@ void bootloader(void)
|
||||
{
|
||||
ticks = 0;
|
||||
stp_clock = STP_TICK_DIVIDER;
|
||||
dhcp_state.state = DHCP_OFF;
|
||||
sbuf_ptr = 0;
|
||||
|
||||
CKCON = 0; // Initial Clock configuration
|
||||
|
||||
Reference in New Issue
Block a user