Skip to content

Commit

Permalink
make plan9 optional build, not built by default use make PLAN9=1 to b…
Browse files Browse the repository at this point in the history
…uild it

refactor Network to remove most of the statics
  • Loading branch information
wolfmanjm committed Apr 10, 2016
1 parent 883443c commit 54be3ba
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 23 deletions.
8 changes: 7 additions & 1 deletion build/common.mk
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -96,11 +96,17 @@ ASRCS = $(wildcard $(SRC)/*.S $(SRC)/*/*.S $(SRC)/*/*/*.S $(SRC)/*/*/*/*.S $(SR
ifneq "$(OS)" "Windows_NT" ifneq "$(OS)" "Windows_NT"
ASRCS += $(wildcard $(SRC)/*.s $(SRC)/*/*.s $(SRC)/*/*/*.s $(SRC)/*/*/*/*.s $(SRC)/*/*/*/*/*.s) ASRCS += $(wildcard $(SRC)/*.s $(SRC)/*/*.s $(SRC)/*/*/*.s $(SRC)/*/*/*/*.s $(SRC)/*/*/*/*/*.s)
endif endif

CPPSRCS1 = $(wildcard $(SRC)/*.cpp $(SRC)/*/*.cpp $(SRC)/*/*/*.cpp $(SRC)/*/*/*/*.cpp $(SRC)/*/*/*/*/*.cpp $(SRC)/*/*/*/*/*/*.cpp) CPPSRCS1 = $(wildcard $(SRC)/*.cpp $(SRC)/*/*.cpp $(SRC)/*/*/*.cpp $(SRC)/*/*/*/*.cpp $(SRC)/*/*/*/*/*.cpp $(SRC)/*/*/*/*/*/*.cpp)
ifeq "$(NONETWORK)" "1" ifeq "$(NONETWORK)" "1"
CPPSRCS2 = $(filter-out $(SRC)/libs/Network/%,$(CPPSRCS1)) CPPSRCS2 = $(filter-out $(SRC)/libs/Network/%,$(CPPSRCS1))
else else
CPPSRCS2 = $(CPPSRCS1) ifneq "$(PLAN9)" "1"
DEFINES += -DNOPLAN9
CPPSRCS2 = $(filter-out $(SRC)/libs/Network/uip/plan9/%,$(CPPSRCS1))
else
CPPSRCS2 = $(CPPSRCS1)
endif
endif endif


# Totally exclude any modules listed in EXCLUDE_MODULES # Totally exclude any modules listed in EXCLUDE_MODULES
Expand Down
36 changes: 20 additions & 16 deletions src/libs/Network/uip/Network.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
#include "webserver.h" #include "webserver.h"
#include "dhcpc.h" #include "dhcpc.h"
#include "sftpd.h" #include "sftpd.h"

#ifndef NOPLAN9
#include "plan9.h" #include "plan9.h"
#endif


#include <mri.h> #include <mri.h>


Expand All @@ -44,20 +47,17 @@ extern "C" void uip_log(char *m)
printf("uIP log message: %s\n", m); printf("uIP log message: %s\n", m);
} }


static bool webserver_enabled, telnet_enabled, plan9_enabled, use_dhcp; static Network* theNetwork;
static Network *theNetwork;
static Sftpd *sftpd;
static CommandQueue *command_q= CommandQueue::getInstance();


Network* Network::instance;
Network::Network() Network::Network()
{ {
theNetwork= this;
ethernet = new LPC17XX_Ethernet(); ethernet = new LPC17XX_Ethernet();
tickcnt= 0; tickcnt= 0;
theNetwork= this;
sftpd= NULL; sftpd= NULL;
instance= this;
hostname = NULL; hostname = NULL;
plan9_enabled= false;
command_q= CommandQueue::getInstance();
} }


Network::~Network() Network::~Network()
Expand All @@ -66,6 +66,7 @@ Network::~Network()
if (hostname != NULL) { if (hostname != NULL) {
delete hostname; delete hostname;
} }
theNetwork= nullptr;
} }


static uint32_t getSerialNumberHash() static uint32_t getSerialNumberHash()
Expand Down Expand Up @@ -131,7 +132,6 @@ void Network::on_module_loaded()
webserver_enabled = THEKERNEL->config->value( network_checksum, network_webserver_checksum, network_enable_checksum )->by_default(false)->as_bool(); webserver_enabled = THEKERNEL->config->value( network_checksum, network_webserver_checksum, network_enable_checksum )->by_default(false)->as_bool();
telnet_enabled = THEKERNEL->config->value( network_checksum, network_telnet_checksum, network_enable_checksum )->by_default(false)->as_bool(); telnet_enabled = THEKERNEL->config->value( network_checksum, network_telnet_checksum, network_enable_checksum )->by_default(false)->as_bool();
plan9_enabled = THEKERNEL->config->value( network_checksum, network_plan9_checksum, network_enable_checksum )->by_default(false)->as_bool(); plan9_enabled = THEKERNEL->config->value( network_checksum, network_plan9_checksum, network_enable_checksum )->by_default(false)->as_bool();

string mac = THEKERNEL->config->value( network_checksum, network_mac_override_checksum )->by_default("")->as_string(); string mac = THEKERNEL->config->value( network_checksum, network_mac_override_checksum )->by_default("")->as_string();
if (mac.size() == 17 ) { // parse mac address if (mac.size() == 17 ) { // parse mac address
if (!parse_ip_str(mac, mac_address, 6, 16, ':')) { if (!parse_ip_str(mac, mac_address, 6, 16, ':')) {
Expand Down Expand Up @@ -292,7 +292,7 @@ void Network::on_idle(void *argument)
} }
} }


static void setup_servers() void Network::setup_servers()
{ {
if (webserver_enabled) { if (webserver_enabled) {
// Initialize the HTTP server, listen to port 80. // Initialize the HTTP server, listen to port 80.
Expand All @@ -306,11 +306,13 @@ static void setup_servers()
printf("Telnetd initialized\n"); printf("Telnetd initialized\n");
} }


#ifndef NOPLAN9
if (plan9_enabled) { if (plan9_enabled) {
// Initialize the plan9 server // Initialize the plan9 server
Plan9::init(); Plan9::init();
printf("Plan9 initialized\n"); printf("Plan9 initialized\n");
} }
#endif


// sftpd service, which is lazily created on reciept of first packet // sftpd service, which is lazily created on reciept of first packet
uip_listen(HTONS(115)); uip_listen(HTONS(115));
Expand Down Expand Up @@ -396,24 +398,26 @@ extern "C" void app_select_appcall(void)
{ {
switch (uip_conn->lport) { switch (uip_conn->lport) {
case HTONS(80): case HTONS(80):
if (webserver_enabled) httpd_appcall(); if (theNetwork->webserver_enabled) httpd_appcall();
break; break;


case HTONS(23): case HTONS(23):
if (telnet_enabled) Telnetd::appcall(); if (theNetwork->telnet_enabled) Telnetd::appcall();
break; break;


#ifndef NOPLAN9
case HTONS(564): case HTONS(564):
if (plan9_enabled) Plan9::appcall(); if (theNetwork->plan9_enabled) Plan9::appcall();
break; break;
#endif


case HTONS(115): case HTONS(115):
if(sftpd == NULL) { if(theNetwork->sftpd == NULL) {
sftpd= new Sftpd(); theNetwork->sftpd= new Sftpd();
sftpd->init(); theNetwork->sftpd->init();
printf("Created sftpd service\n"); printf("Created sftpd service\n");
} }
sftpd->appcall(); theNetwork->sftpd->appcall();
break; break;


default: default:
Expand Down
22 changes: 16 additions & 6 deletions src/libs/Network/uip/Network.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "LPC17XX_Ethernet.h" #include "LPC17XX_Ethernet.h"
#include "Module.h" #include "Module.h"


class Sftpd;
class CommandQueue;


class Network : public Module class Network : public Module
{ {
Expand All @@ -17,26 +19,34 @@ class Network : public Module
void on_main_loop(void* argument); void on_main_loop(void* argument);
void on_get_public_data(void* argument); void on_get_public_data(void* argument);
void dhcpc_configured(uint32_t ipaddr, uint32_t ipmask, uint32_t ipgw); void dhcpc_configured(uint32_t ipaddr, uint32_t ipmask, uint32_t ipgw);
static Network *getInstance() { return instance;}
void tapdev_send(void *pPacket, unsigned int size); void tapdev_send(void *pPacket, unsigned int size);


// accessed from C
Sftpd *sftpd;
struct {
bool webserver_enabled:1;
bool telnet_enabled:1;
bool plan9_enabled:1;
bool use_dhcp:1;
};


private: private:
void init(); void init();
void setup_servers();
uint32_t tick(uint32_t dummy); uint32_t tick(uint32_t dummy);
void handlePacket(); void handlePacket();


static Network *instance; CommandQueue *command_q;

LPC17XX_Ethernet *ethernet; LPC17XX_Ethernet *ethernet;


struct timer periodic_timer, arp_timer; struct timer periodic_timer, arp_timer;
char *hostname;
volatile uint32_t tickcnt;
uint8_t mac_address[6]; uint8_t mac_address[6];
uint8_t ipaddr[4]; uint8_t ipaddr[4];
uint8_t ipmask[4]; uint8_t ipmask[4];
uint8_t ipgw[4]; uint8_t ipgw[4];
char *hostname;
volatile uint32_t tickcnt;

}; };


#endif #endif

0 comments on commit 54be3ba

Please sign in to comment.