Add nuttx to the system framework, which is 10.1.0
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config EXAMPLES_WEBSERVER
|
||||
tristate "uIP web server example"
|
||||
default n
|
||||
---help---
|
||||
Enable the uIP web server example
|
||||
|
||||
if EXAMPLES_WEBSERVER
|
||||
|
||||
config EXAMPLES_WEBSERVER_IPADDR
|
||||
hex "Device IP"
|
||||
default 0x0a000002
|
||||
---help---
|
||||
This is the IP address of your board.
|
||||
|
||||
config EXAMPLES_WEBSERVER_DRIPADDR
|
||||
hex "Default Router IP"
|
||||
default 0x0a000001
|
||||
---help---
|
||||
This is the IP address of your router/gateway.
|
||||
|
||||
config EXAMPLES_WEBSERVER_NETMASK
|
||||
hex "Network Mask"
|
||||
default 0xffffff00
|
||||
---help---
|
||||
This is the network mask to use on this device.
|
||||
|
||||
config EXAMPLES_WEBSERVER_DHCPC
|
||||
bool "Enable DHCPC"
|
||||
default n
|
||||
---help---
|
||||
Enable DHCP client.
|
||||
|
||||
config EXAMPLES_WEBSERVER_NOMAC
|
||||
bool "No hardware MAC"
|
||||
default y
|
||||
---help---
|
||||
Some devices don't have hardware MAC then we need to define a
|
||||
software MAC.
|
||||
|
||||
endif
|
||||
@@ -0,0 +1,39 @@
|
||||
############################################################################
|
||||
# apps/examples/webserver/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifneq ($(CONFIG_EXAMPLES_WEBSERVER),)
|
||||
CONFIGURED_APPS += $(APPDIR)/examples/webserver
|
||||
endif
|
||||
@@ -0,0 +1,58 @@
|
||||
############################################################################
|
||||
# apps/examples/webserver/Makefile
|
||||
#
|
||||
# Copyright (C) 2007-2008, 2010-2012 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
# uIP very tiny web server example
|
||||
|
||||
CSRCS = cgi.c httpd_fsdata.c
|
||||
MAINSRC = webserver_main.c
|
||||
|
||||
# Webserver built-in application info
|
||||
|
||||
PROGNAME = webserver
|
||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||
STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE)
|
||||
MODULE = $(CONFIG_EXAMPLES_WEBSERVER)
|
||||
|
||||
# Common build
|
||||
|
||||
httpd_fsdata.c: httpd-fs/*
|
||||
$(TOPDIR)/tools/mkfsdata.pl
|
||||
|
||||
clean::
|
||||
$(call DELFILE, httpd_fsdata.c)
|
||||
|
||||
include $(APPDIR)/Application.mk
|
||||
@@ -0,0 +1,122 @@
|
||||
/****************************************************************************
|
||||
* apps/examples/webserver/cgi.c
|
||||
* Web server script interface
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* Copyright (c) 2001-2006, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <nuttx/net/netstats.h>
|
||||
#include "netutils/httpd.h"
|
||||
|
||||
#include "cgi.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NETUTILS_HTTPDFILESTATS
|
||||
HTTPD_CGI_CALL(file, "file-stats", file_stats);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NETUTILS_HTTPDNETSTATS
|
||||
HTTPD_CGI_CALL(net, "net-stats", net_stats);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: net_stats
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NETUTILS_HTTPDNETSTATS
|
||||
static void net_stats(struct httpd_state *pstate, char *ptr)
|
||||
{
|
||||
char buffer[16];
|
||||
int i;
|
||||
bool chunked_http_tx = 0;
|
||||
|
||||
#if defined(CONFIG_NETUTILS_HTTPD_ENABLE_CHUNKED_ENCODING)
|
||||
chunked_http_tx = pstate->ht_chunked;
|
||||
#endif
|
||||
|
||||
for (i = 0; i < sizeof(g_netstats) / sizeof(net_stats_t); i++)
|
||||
{
|
||||
snprintf(buffer, 16, "%5u\n", ((net_stats_t *)&g_netstats)[i]);
|
||||
httpd_send_datachunk(pstate->ht_sockfd, buffer, strlen(buffer),
|
||||
chunked_http_tx);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: file_stats
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NETUTILS_HTTPDFILESTATS
|
||||
static void file_stats(struct httpd_state *pstate, char *ptr)
|
||||
{
|
||||
char buffer[16];
|
||||
char *pcount = strchr(ptr, ' ') + 1;
|
||||
bool chunked_http_tx = 0;
|
||||
|
||||
#if defined(CONFIG_NETUTILS_HTTPD_ENABLE_CHUNKED_ENCODING)
|
||||
chunked_http_tx = pstate->ht_chunked;
|
||||
#endif
|
||||
|
||||
snprintf(buffer, 16, "%5u", httpd_fs_count(pcount));
|
||||
httpd_send_datachunk(pstate->ht_sockfd, buffer, strlen(buffer),
|
||||
chunked_http_tx);
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: cgi_register
|
||||
****************************************************************************/
|
||||
|
||||
void cgi_register()
|
||||
{
|
||||
#ifdef CONFIG_NETUTILS_HTTPDFILESTATS
|
||||
httpd_cgi_register(&file);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NETUTILS_HTTPDNETSTATS
|
||||
httpd_cgi_register(&net);
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/****************************************************************************
|
||||
* apps/examples/webserver/cgi.h
|
||||
* Web server script interface header file
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
* Copyright (c) 2001, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __EXAMPLES_WEBSERVER_CGI_H
|
||||
#define __EXAMPLES_WEBSERVER_CGI_H
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
void cgi_register(void);
|
||||
|
||||
#endif /* __EXAMPLES_WEBSERVER_CGI_H */
|
||||
@@ -0,0 +1,8 @@
|
||||
<html>
|
||||
<body bgcolor="white">
|
||||
<center>
|
||||
<h1>404 - file not found</h1>
|
||||
<h3>Go <a href="/">here</a> instead.</h3>
|
||||
</center>
|
||||
</body>
|
||||
</html>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 196 B |
@@ -0,0 +1,31 @@
|
||||
%!: /header.html
|
||||
<h1>File statistics</h1>
|
||||
<center>
|
||||
<table width="300">
|
||||
<tr><td><a href="/index.shtml">/index.shtml</a></td>
|
||||
<td>%! file-stats /index.shtml
|
||||
</td><td><img src="/fade.png" height=10 width=%! file-stats /index.shtml
|
||||
> </td></tr>
|
||||
<tr><td><a href="/files.shtml">/files.shtml</a></td>
|
||||
<td>%! file-stats /files.shtml
|
||||
</td><td><img src="/fade.png" height=10 width=%! file-stats /files.shtml
|
||||
> </td></tr>
|
||||
<tr><td><a href="/stats.shtml">/stats.shtml</a></td>
|
||||
<td>%! file-stats /stats.shtml
|
||||
</td><td><img src="/fade.png" height=10 width=%! file-stats /stats.shtml
|
||||
> </td></tr>
|
||||
<tr><td><a href="/style.css">/style.css</a></td>
|
||||
<td>%! file-stats /style.css
|
||||
</td><td><img src="/fade.png" height=10 width=%! file-stats /style.css
|
||||
> </td></tr>
|
||||
<tr><td><a href="/404.html">/404.html</a></td>
|
||||
<td>%! file-stats /404.html
|
||||
</td><td><img src="/fade.png" height=10 width=%! file-stats /404.html
|
||||
> </td></tr>
|
||||
<tr><td><a href="/fade.png">/fade.png</a></td>
|
||||
<td>%! file-stats /fade.png
|
||||
</td><td><img src="/fade.png" height=10 width=%! file-stats /fade.png
|
||||
> </td></tr>
|
||||
</table>
|
||||
</center>
|
||||
%!: /footer.html
|
||||
@@ -0,0 +1,3 @@
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,16 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Welcome to the uIP web server!</title>
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
</head>
|
||||
<body bgcolor="#fffeec" text="black">
|
||||
|
||||
<div class="menu">
|
||||
<div class="menubox"><a href="/">Front page</a></div>
|
||||
<div class="menubox"><a href="files.shtml">File statistics</a></div>
|
||||
<div class="menubox"><a href="stats.shtml">Network statistics</a></div>
|
||||
<br>
|
||||
</div>
|
||||
|
||||
<div class="contentblock">
|
||||
@@ -0,0 +1,10 @@
|
||||
%!: /header.html
|
||||
<p>
|
||||
These web pages are served by a small web server running on top of
|
||||
the <a href="http://www.sics.se/~adam/uip/">uIP embedded TCP/IP
|
||||
stack</a>.
|
||||
</p>
|
||||
<p>
|
||||
Click on the links above for web server statistics.
|
||||
</p>
|
||||
%!: /footer.html
|
||||
@@ -0,0 +1,31 @@
|
||||
%!: /header.html
|
||||
<h1>Network statistics</h1>
|
||||
<center>
|
||||
<table width="300" border="0">
|
||||
<tr><td><pre>
|
||||
IP Packets received
|
||||
Packets sent
|
||||
Packets dropped
|
||||
IP errors IP version/header length
|
||||
IP length, high byte
|
||||
IP length, low byte
|
||||
IP fragments
|
||||
Header checksum
|
||||
Wrong protocol
|
||||
ICMP Packets received
|
||||
Packets sent
|
||||
Packets dropped
|
||||
Type errors
|
||||
TCP Packets received
|
||||
Packets sent
|
||||
Packets dropped
|
||||
Checksum errors
|
||||
Data packets without ACKs
|
||||
Resets
|
||||
Retransmissions
|
||||
No connection available
|
||||
Connection attempts to closed ports
|
||||
</pre></td><td><pre>%! net-stats
|
||||
</pre></table>
|
||||
</center>
|
||||
%!: /footer.html
|
||||
@@ -0,0 +1,91 @@
|
||||
h1
|
||||
{
|
||||
text-align: center;
|
||||
font-size:14pt;
|
||||
font-family:arial,helvetica;
|
||||
font-weight:bold;
|
||||
padding:10px;
|
||||
}
|
||||
|
||||
body
|
||||
{
|
||||
|
||||
background-color: #fffeec;
|
||||
color:black;
|
||||
|
||||
font-size:8pt;
|
||||
font-family:arial,helvetica;
|
||||
}
|
||||
|
||||
.menu
|
||||
{
|
||||
margin: 4px;
|
||||
width:60%;
|
||||
|
||||
padding:2px;
|
||||
|
||||
border: solid 1px;
|
||||
background-color: #fffcd2;
|
||||
text-align:left;
|
||||
|
||||
font-size:9pt;
|
||||
font-family:arial,helvetica;
|
||||
}
|
||||
|
||||
div.menubox
|
||||
{
|
||||
width: 25%;
|
||||
border: 0;
|
||||
float: left;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.contentblock
|
||||
{
|
||||
margin: 4px;
|
||||
width:60%;
|
||||
|
||||
padding:2px;
|
||||
|
||||
border: 1px dotted;
|
||||
background-color: white;
|
||||
|
||||
font-size:8pt;
|
||||
font-family:arial,helvetica;
|
||||
|
||||
}
|
||||
|
||||
p.intro
|
||||
{
|
||||
margin-left:20px;
|
||||
margin-right:20px;
|
||||
|
||||
font-size:10pt;
|
||||
/* font-weight:bold; */
|
||||
font-family:arial,helvetica;
|
||||
}
|
||||
|
||||
p.clink
|
||||
{
|
||||
font-size:12pt;
|
||||
font-family:courier,monospace;
|
||||
text-align:center;
|
||||
}
|
||||
|
||||
p.clink9
|
||||
{
|
||||
font-size:9pt;
|
||||
font-family:courier,monospace;
|
||||
text-align:center;
|
||||
}
|
||||
|
||||
|
||||
p
|
||||
{
|
||||
padding-left:10px;
|
||||
}
|
||||
|
||||
p.right
|
||||
{
|
||||
text-align:right;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
%!: /header.html
|
||||
<h1>Current connections</h1><br><table width="100%">
|
||||
<tr><th>Local</th><th>Remote</th><th>State</th><th>Retransmissions</th><th>Timer</th><th>Flags</th></tr>
|
||||
%! tcp-connections
|
||||
%!: /footer.html
|
||||
@@ -0,0 +1,232 @@
|
||||
/****************************************************************************
|
||||
* examples/webserver/webserver_main.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009-2012, 2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Based on uIP which also has a BSD style license:
|
||||
*
|
||||
* Copyright (c) 2001, Adam Dunkels.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Adam Dunkels.
|
||||
* 4. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <nuttx/net/arp.h>
|
||||
#include "netutils/netlib.h"
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_WEBSERVER_DHCPC
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
/* Here we include the header file for the application(s) we use in
|
||||
* our project as defined in the config/<board-name>/defconfig file
|
||||
*/
|
||||
|
||||
/* DHCPC may be used in conjunction with any other feature (or not) */
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_WEBSERVER_DHCPC
|
||||
# include "netutils/dhcpc.h"
|
||||
#endif
|
||||
|
||||
/* Include uIP webserver definitions */
|
||||
|
||||
#include "netutils/httpd.h"
|
||||
|
||||
#include "cgi.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* webserver_main
|
||||
****************************************************************************/
|
||||
|
||||
int main(int argc, FAR char *argv[])
|
||||
{
|
||||
#ifndef CONFIG_NSH_NETINIT
|
||||
/* We are running standalone (as opposed to a NSH built-in app). Therefore
|
||||
* we need to initialize the network before we start.
|
||||
*/
|
||||
|
||||
struct in_addr addr;
|
||||
#if defined(CONFIG_EXAMPLES_WEBSERVER_DHCPC) || defined(CONFIG_EXAMPLES_WEBSERVER_NOMAC)
|
||||
uint8_t mac[IFHWADDRLEN];
|
||||
#endif
|
||||
#ifdef CONFIG_EXAMPLES_WEBSERVER_DHCPC
|
||||
void *handle;
|
||||
#endif
|
||||
|
||||
/* Many embedded network interfaces must have a software assigned MAC */
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_WEBSERVER_NOMAC
|
||||
mac[0] = 0x00;
|
||||
mac[1] = 0xe0;
|
||||
mac[2] = 0xde;
|
||||
mac[3] = 0xad;
|
||||
mac[4] = 0xbe;
|
||||
mac[5] = 0xef;
|
||||
netlib_setmacaddr("eth0", mac);
|
||||
#endif
|
||||
|
||||
/* Set up our host address */
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_WEBSERVER_DHCPC
|
||||
addr.s_addr = 0;
|
||||
#else
|
||||
addr.s_addr = HTONL(CONFIG_EXAMPLES_WEBSERVER_IPADDR);
|
||||
#endif
|
||||
netlib_set_ipv4addr("eth0", &addr);
|
||||
|
||||
/* Set up the default router address */
|
||||
|
||||
addr.s_addr = HTONL(CONFIG_EXAMPLES_WEBSERVER_DRIPADDR);
|
||||
netlib_set_dripv4addr("eth0", &addr);
|
||||
|
||||
/* Setup the subnet mask */
|
||||
|
||||
addr.s_addr = HTONL(CONFIG_EXAMPLES_WEBSERVER_NETMASK);
|
||||
netlib_set_ipv4netmask("eth0", &addr);
|
||||
|
||||
/* New versions of netlib_set_ipvXaddr will not bring the network up,
|
||||
* So ensure the network is really up at this point.
|
||||
*/
|
||||
|
||||
netlib_ifup("eth0");
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_WEBSERVER_DHCPC
|
||||
/* Get the MAC address of the NIC */
|
||||
|
||||
netlib_getmacaddr("eth0", mac);
|
||||
|
||||
/* Set up the DHCPC modules */
|
||||
|
||||
handle = dhcpc_open("eth0", &mac, IFHWADDRLEN);
|
||||
|
||||
/* Get an IP address. Note: there is no logic here for renewing the
|
||||
* address in this example. The address should be renewed in
|
||||
* ds.lease_time/2 seconds.
|
||||
*/
|
||||
|
||||
printf("Getting IP address\n");
|
||||
if (handle)
|
||||
{
|
||||
struct dhcpc_state ds;
|
||||
dhcpc_request(handle, &ds);
|
||||
netlib_set_ipv4addr("eth0", &ds.ipaddr);
|
||||
|
||||
if (ds.netmask.s_addr != 0)
|
||||
{
|
||||
netlib_set_ipv4netmask("eth0", &ds.netmask);
|
||||
}
|
||||
|
||||
if (ds.default_router.s_addr != 0)
|
||||
{
|
||||
netlib_set_dripv4addr("eth0", &ds.default_router);
|
||||
}
|
||||
|
||||
if (ds.dnsaddr.s_addr != 0)
|
||||
{
|
||||
netlib_set_ipv4dnsaddr(&ds.dnsaddr);
|
||||
}
|
||||
|
||||
dhcpc_close(handle);
|
||||
printf("IP: %s\n", inet_ntoa(ds.ipaddr));
|
||||
}
|
||||
#endif
|
||||
#endif /* CONFIG_NSH_NETINIT */
|
||||
|
||||
#ifdef CONFIG_NET_TCP
|
||||
printf("Starting webserver\n");
|
||||
httpd_init();
|
||||
#ifndef CONFIG_NETUTILS_HTTPD_SCRIPT_DISABLE
|
||||
cgi_register();
|
||||
#endif
|
||||
httpd_listen();
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_NSH_NETINIT
|
||||
/* We are running standalone (as opposed to a NSH built-in app). Therefore
|
||||
* we should not exit after httpd failure.
|
||||
*/
|
||||
|
||||
while (1)
|
||||
{
|
||||
sleep(3);
|
||||
printf("webserver_main: Still running\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
#else /* CONFIG_NSH_NETINIT */
|
||||
/* We are running as a NSH built-in app. Therefore we should exit. This
|
||||
* allows to 'kill -9' the webserver app, assuming it was started as a
|
||||
* background process. For example:
|
||||
*
|
||||
* nsh> webserver &
|
||||
* webserver [6:100]
|
||||
* nsh> Starting webserver
|
||||
*
|
||||
* nsh> kill -9 6
|
||||
* nsh> webserver_main: Exiting
|
||||
*/
|
||||
|
||||
printf("webserver_main: Exiting\n");
|
||||
fflush(stdout);
|
||||
|
||||
#endif /* CONFIG_NSH_NETINIT */
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user