mirror of
https://github.com/bouffalolab/bouffalo_sdk.git
synced 2025-05-09 03:11:58 +08:00
[update] update lwip, lwipopt and wifi6 lib, revert lwip format
This commit is contained in:
parent
552709e4cb
commit
731b9a1e5c
107
components/net/lwip/lwip/BUILDING
Normal file
107
components/net/lwip/lwip/BUILDING
Normal file
@ -0,0 +1,107 @@
|
||||
Building lwIP
|
||||
=============
|
||||
|
||||
lwIP uses a CMake based build system.
|
||||
|
||||
The CMake files in this project are designed to
|
||||
be included into your own CMake files. They are
|
||||
mainly variable definitions containing a list of
|
||||
source files and predefined static libraries to
|
||||
be linked against application code.
|
||||
|
||||
1) lwIP sources:
|
||||
src/Filelists.cmake provides file lists containing
|
||||
the lwIP core library.
|
||||
The file also contains two static libraries, lwipcore
|
||||
and lwipallapps, where you can link your app against.
|
||||
This is the file that is useful to all lwIP users.
|
||||
|
||||
2) Example applications:
|
||||
contrib/Filelists.cmake provides several file lists
|
||||
containing the example applications.
|
||||
The file also contains several static libraries
|
||||
for these example apps.
|
||||
This file is only useful for you, if you can use one
|
||||
of the examples in your application, which is normally
|
||||
not the case.
|
||||
|
||||
3) OS/platform port:
|
||||
Usually the OS port needs to be provided by the user.
|
||||
If a port to Linux, Windows or MacOS is useful for
|
||||
you, you can use
|
||||
contrib/ports/{win32, unix}/Filelists.cmake
|
||||
that contains file lists and libraries for
|
||||
these operating systems.
|
||||
|
||||
VARIABLES
|
||||
=========
|
||||
In all cases, you need to provide two variables.
|
||||
|
||||
"LWIP_DIR" pointing to the lwIP directory
|
||||
Example:
|
||||
set(LWIP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/externals/lwip)
|
||||
|
||||
"LWIP_INCLUDE_DIRS" that contains the include base paths
|
||||
- for lwIP itself (${LWIP_DIR}/src/include)
|
||||
- for lwIP contrib if you use it (${LWIP_DIR}/contrib)
|
||||
- to a directory containing an OS port
|
||||
- to a directory containing lwipopts.h
|
||||
|
||||
Example:
|
||||
set (LWIP_INCLUDE_DIRS
|
||||
"${LWIP_DIR}/src/include"
|
||||
"${LWIP_DIR}/contrib"
|
||||
"${LWIP_DIR}/contrib/ports/unix/port/include"
|
||||
"${LWIP_DIR}/contrib/examples/example_app"
|
||||
)
|
||||
|
||||
Putting it all together
|
||||
=======================
|
||||
To get a working application, your CMake system
|
||||
needs to provide the variables described above, e.g.
|
||||
set (LWIP_DIR <path to lwip sources>)
|
||||
set (LWIP_INCLUDE_DIRS
|
||||
"${LWIP_DIR}/src/include"
|
||||
"${LWIP_DIR}/contrib"
|
||||
"<path to my port>/include"
|
||||
"<path to lwipopts.h>"
|
||||
)
|
||||
|
||||
You may add some defines:
|
||||
set (LWIP_DEFINITIONS LWIP_DEBUG=1)
|
||||
|
||||
Then include the filelists you need:
|
||||
include(${LWIP_DIR}/src/Filelists.cmake)
|
||||
include(${LWIP_DIR}/contrib/Filelists.cmake)
|
||||
|
||||
Then, declare you executable:
|
||||
add_executable(my_app <my source files> <my lwip port files>)
|
||||
|
||||
Add lwIP include dirs to your app:
|
||||
target_include_directories(my_app PRIVATE ${LWIP_INCLUDE_DIRS})
|
||||
|
||||
Link your app against the lwIP libs from the filelists you need:
|
||||
target_link_libraries(my_app lwipcontribapps lwipallapps lwipcore)
|
||||
|
||||
Working example
|
||||
===============
|
||||
Working build examples can be found in the
|
||||
contrib/ports/{win32, unix}/example_app
|
||||
subdirectory.
|
||||
To use them, create a build directory and call cmake with
|
||||
the lwIP root dir:
|
||||
|
||||
- mkdir build
|
||||
- cd build
|
||||
- cmake ..
|
||||
- cmake --build .
|
||||
|
||||
The CMakeLists.txt will autoselect the correct port
|
||||
for your system (supported: Linux, Windows, Darwin).
|
||||
|
||||
Makefile based build system
|
||||
===========================
|
||||
lwIP also maintains file lists for Makefile-based
|
||||
build systems. Look for Filelists.mk files
|
||||
in the source tree. We try to maintain them,
|
||||
but lwIP's mainly focused build system is CMake.
|
@ -47,9 +47,8 @@ sdk_library_add_sources(src/core/timeouts.c)
|
||||
sdk_library_add_sources(src/core/udp.c)
|
||||
|
||||
sdk_library_add_sources(src/netif/ethernet.c)
|
||||
sdk_library_add_sources(system/os/sys_arch.c)
|
||||
sdk_library_add_sources(lwip-port/FreeRTOS/sys_arch.c)
|
||||
|
||||
sdk_add_include_directories(system)
|
||||
sdk_add_include_directories(lwip-port)
|
||||
sdk_add_include_directories(src/include)
|
||||
sdk_add_include_directories(src/include/compat/posix)
|
||||
|
||||
|
62
components/net/lwip/lwip/bouffalo.mk
Normal file
62
components/net/lwip/lwip/bouffalo.mk
Normal file
@ -0,0 +1,62 @@
|
||||
# Component Makefile
|
||||
|
||||
ifeq ($(CONFIG_ETHERNET), 1)
|
||||
CFLAGS += -DCFG_ETHERNET_ENABLE
|
||||
CPPFLAGS += -DCFG_ETHERNET_ENABLE
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_NETBUS_WIFI_ENABLE),1)
|
||||
CFLAGS += -DCFG_NETBUS_WIFI_ENABLE
|
||||
endif
|
||||
#
|
||||
## These include paths would be exported to project level
|
||||
COMPONENT_ADD_INCLUDEDIRS += src/include src/include/compat/posix lwip-port lwip-port/FreeRTOS lwip-port/arch
|
||||
|
||||
ifneq ($(CONFIG_CHIP_NAME),BL616)
|
||||
# bl616 lwipopt.h define in wifi6_lwip_adapter
|
||||
COMPONENT_ADD_INCLUDEDIRS += lwip-port/config
|
||||
else
|
||||
# bl616 need lwip errno.h
|
||||
COMPONENT_ADD_INCLUDEDIRS += src/include/compat/stdc
|
||||
endif
|
||||
|
||||
## not be exported to project level
|
||||
COMPONENT_PRIV_INCLUDEDIRS :=
|
||||
|
||||
## This component's src
|
||||
|
||||
COMPONENT_SRCDIRS := src/api src/core src/core/ipv4 src/netif lwip-port/FreeRTOS lwip-port src/apps/altcp_tls
|
||||
COMPONENT_SRCDIRS += src/apps/sntp
|
||||
|
||||
ifeq ($(CONFIG_COMPONENT_BUGKILLER_ENABLE),1)
|
||||
COMPONENT_ADD_INCLUDEDIRS += bugkiller/include
|
||||
COMPONENT_SRCDIRS += bugkiller
|
||||
CFLAGS += -DBUGKILLER
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LWIP_NETCONN_DUPLEX),1)
|
||||
CFLAGS += -DLWIP_NETCONN_DUPLEX_SWITCH
|
||||
endif
|
||||
ifeq ($(CONFIG_ENABLE_OS_TLS),1)
|
||||
CFLAGS += -Dconfig_ENABLE_OS_TLS_SWITCH
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_IPV6), 1)
|
||||
COMPONENT_SRCDIRS += src/core/ipv6
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_OTBR),1)
|
||||
## Openthread Border Router has its own src/core/ipv6/mld6.c
|
||||
COMPONENT_SRCS := $(foreach compsrcdir,$(COMPONENT_SRCDIRS),$(wildcard $(COMPONENT_PATH)/$(compsrcdir)/*.c))
|
||||
COMPONENT_SRCS := $(subst $(COMPONENT_PATH)/,,$(COMPONENT_SRCS))
|
||||
COMPONENT_SRCS := $(filter-out src/core/ipv6/mld6.c,$(COMPONENT_SRCS))
|
||||
COMPONENT_OBJS := $(patsubst %.c,%.o, $(COMPONENT_SRCS))
|
||||
CFLAGS += -DOPENTHREAD_BORDER_ROUTER
|
||||
endif
|
||||
|
||||
##
|
||||
#CPPFLAGS +=
|
||||
|
||||
ifeq ($(CONFIG_LWIP_PE_OPT),1)
|
||||
CFLAGS += -msave-restore
|
||||
endif
|
29
components/net/lwip/lwip/bugkiller/bugkiller_mbox_dump.inc
Normal file
29
components/net/lwip/lwip/bugkiller/bugkiller_mbox_dump.inc
Normal file
@ -0,0 +1,29 @@
|
||||
|
||||
unsigned long __attribute__((section(".bugkiller_code"))) bugkiller_mbox_peek_unrecved(sys_mbox_t recvmbox)
|
||||
{
|
||||
unsigned long sum = 0;
|
||||
struct pbuf *msg[TCPIP_MBOX_SIZE] = {0};
|
||||
int i = 0, j = 0;
|
||||
|
||||
while(sys_arch_mbox_tryfetch(&recvmbox, (void **)&msg[i++]) != SYS_MBOX_EMPTY) {
|
||||
sum += msg[i-1]->tot_len;
|
||||
}
|
||||
while(--i) {
|
||||
sys_mbox_trypost(&recvmbox, (void *)msg[j++]);
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
unsigned long __attribute__((section(".bugkiller_code"))) bugkiller_mbox_peek_accepted(sys_mbox_t acceptmbox)
|
||||
{
|
||||
unsigned long sum = 0;
|
||||
struct pbuf *msg[TCPIP_MBOX_SIZE] = {0};
|
||||
int i = 0, j = 0;
|
||||
|
||||
while(sys_arch_mbox_tryfetch(&acceptmbox, (void **)&msg[i++]) != SYS_MBOX_EMPTY) {
|
||||
sum++;
|
||||
}
|
||||
while(--i) {
|
||||
sys_mbox_trypost(&acceptmbox, (void *)msg[j++]);
|
||||
}
|
||||
return sum;
|
||||
}
|
82
components/net/lwip/lwip/bugkiller/bugkiller_socket_dump.inc
Normal file
82
components/net/lwip/lwip/bugkiller/bugkiller_socket_dump.inc
Normal file
@ -0,0 +1,82 @@
|
||||
#include "lwip_bugkiller_inner.h"
|
||||
|
||||
/*
|
||||
iperf server(recv) dump socket inner,
|
||||
SocketId: 0 Type: TCP Status: 192.168.1.116:5001 -> 0.0.0.0:49466 (LISTEN)
|
||||
SocketId: 1 Type: TCP Status: 192.168.1.116:5001 -> 192.168.1.143:44312 (ESTABLISHED)
|
||||
recv wnd : -1460 ~ 827230504 ~ +33580
|
||||
recv_ann wnd : -33580 ~ 827264084
|
||||
snd wnd : -0 ~ 6511 ~ +64240
|
||||
unsend len: 0, unacked len: 0, ooseq len: 0
|
||||
|
||||
iperf client(send) dump socket inner,
|
||||
SocketId: 0 Type: TCP Status: 192.168.1.116:61738 -> 192.168.1.143:5001 (ESTABLISHED)
|
||||
recv wnd : -0 ~ 76303226 ~ +43800
|
||||
recv_ann wnd : -43800 ~ 76347026
|
||||
snd wnd : -17520 ~ 7173790 ~ +48015
|
||||
unsend len: 0, unacked len: 17520, ooseq len: 0
|
||||
*/
|
||||
extern unsigned long bugkiller_mbox_peek_unrecved(sys_mbox_t recvmbox);
|
||||
extern unsigned long bugkiller_mbox_peek_accepted(sys_mbox_t acceptbox);
|
||||
void __attribute__((section(".bugkiller_code"))) bugkiller_socket_inner_dump(int id)
|
||||
{
|
||||
switch(sockets[id].conn->type) {
|
||||
case NETCONN_UDP:
|
||||
break;
|
||||
case NETCONN_TCP:
|
||||
if(sockets[id].conn->pcb.tcp->state == LISTEN) {
|
||||
bugkiller_tcp_listen_dump(bugkiller_mbox_peek_accepted(sockets[id].conn->acceptmbox), \
|
||||
sockets[id].conn->pcb.tcp);
|
||||
} else {
|
||||
bugkiller_tcp_wnd_dump(bugkiller_mbox_peek_unrecved(sockets[id].conn->recvmbox) + \
|
||||
(sockets[id].lastdata.pbuf ? sockets[id].lastdata.pbuf->tot_len : 0), \
|
||||
sockets[id].conn->pcb.tcp);
|
||||
bugkiller_tcp_seg_dump(sockets[id].conn->pcb.tcp);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
printf(lwip_bugkiller_format[4]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* sockets_dump():
|
||||
SocketId: 6 Type: TCP Status: localhost:33783 -> baidu.com:8000
|
||||
SocketId: 7 Type: UDP Status: localhost:33784 -> baidu.com:8001
|
||||
SocketId: 8 Type: TCP Status: localhost:8000 (Listen)
|
||||
....
|
||||
*/
|
||||
void __attribute__((section(".bugkiller_code"))) bugkiller_sockets_dump()
|
||||
{
|
||||
for(int i = 0; i < NUM_SOCKETS && sockets[i].conn; i++) {
|
||||
if(sockets[i].conn == NULL)
|
||||
continue;
|
||||
switch(sockets[i].conn->type) {
|
||||
case NETCONN_UDP:
|
||||
printf(lwip_bugkiller_format[0], i);
|
||||
printf(lwip_bugkiller_format[1],
|
||||
ip4addr_ntoa((const ip4_addr_t *) &sockets[i].conn->pcb.udp->local_ip.addr),
|
||||
sockets[i].conn->pcb.udp->local_port);
|
||||
printf(lwip_bugkiller_format[6],
|
||||
ip4addr_ntoa((const ip4_addr_t *) &sockets[i].conn->pcb.udp->remote_ip.addr),
|
||||
sockets[i].conn->pcb.udp->remote_port);
|
||||
break;
|
||||
case NETCONN_TCP:
|
||||
printf(lwip_bugkiller_format[3], i);
|
||||
printf(lwip_bugkiller_format[1],
|
||||
ip4addr_ntoa((const ip4_addr_t *) &sockets[i].conn->pcb.udp->local_ip.addr),
|
||||
sockets[i].conn->pcb.tcp->local_port);
|
||||
if(sockets[i].conn->pcb.tcp->state != LISTEN) {
|
||||
printf(lwip_bugkiller_format[2],
|
||||
ip4addr_ntoa((const ip4_addr_t *) &sockets[i].conn->pcb.tcp->remote_ip.addr),
|
||||
sockets[i].conn->pcb.tcp->remote_port);
|
||||
}
|
||||
puts(lwip_bugkiller_tcp_state[sockets[i].conn->pcb.tcp->state]);
|
||||
bugkiller_socket_inner_dump(i);
|
||||
break;
|
||||
default:
|
||||
printf(lwip_bugkiller_format[5]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
45
components/net/lwip/lwip/bugkiller/bugkiller_tcp_dump.inc
Normal file
45
components/net/lwip/lwip/bugkiller/bugkiller_tcp_dump.inc
Normal file
@ -0,0 +1,45 @@
|
||||
#include "lwip_bugkiller_inner.h"
|
||||
/* bugkiller_tcp_wnd_dump()
|
||||
recv wnd : -2345 ~ 327584 ~ +5466
|
||||
recv_ann wnd : -5466 ~ 330084
|
||||
snd wnd : -1245 ~ 133458 ~ +244
|
||||
*/
|
||||
void __attribute__((section(".bugkiller_code"))) bugkiller_tcp_wnd_dump(unsigned long unrecv_len, void *s)
|
||||
{
|
||||
struct tcp_pcb *pcb = (struct tcp_pcb *)s;
|
||||
/* receiver */
|
||||
printf(lwip_bugkiller_tcp_format[0], unrecv_len, pcb->rcv_nxt, pcb->rcv_wnd);
|
||||
|
||||
/* receiver ann */
|
||||
printf(lwip_bugkiller_tcp_format[1], pcb->rcv_ann_wnd, pcb->rcv_ann_right_edge);
|
||||
|
||||
/* sender */
|
||||
printf(lwip_bugkiller_tcp_format[2], pcb->snd_nxt - pcb->lastack, pcb->snd_nxt, pcb->snd_wnd + pcb->lastack - pcb->snd_nxt);
|
||||
}
|
||||
|
||||
/* bugkiller_tcp_seg_dump()
|
||||
unsend len: 1000, unakced len: 885
|
||||
*/
|
||||
void __attribute__((section(".bugkiller_code"))) bugkiller_tcp_seg_dump(void *s)
|
||||
{
|
||||
struct tcp_pcb *pcb = (struct tcp_pcb *)s;
|
||||
unsigned long unsend_len = 0, unacked_len = 0, ooseq_len = 0;
|
||||
for(struct tcp_seg *seg = pcb->unsent; seg; seg = seg->next) {
|
||||
unsend_len += seg->len;
|
||||
}
|
||||
for(struct tcp_seg *seg = pcb->unacked; seg; seg = seg->next) {
|
||||
unacked_len += seg->len;
|
||||
}
|
||||
#if TCP_QUEUE_OOSEQ
|
||||
for(struct tcp_seg *seg = pcb->ooseq; seg; seg = seg->next) {
|
||||
ooseq_len += seg->len;
|
||||
}
|
||||
#endif /* TCP_QUEUE_OOSEQ */
|
||||
printf(lwip_bugkiller_tcp_format[3], unsend_len, unacked_len, ooseq_len);
|
||||
}
|
||||
|
||||
void __attribute__((section(".bugkiller_code"))) bugkiller_tcp_listen_dump(unsigned long accept_num,void *s)
|
||||
{
|
||||
struct tcp_pcb_listen *listen_pcb = (struct tcp_pcb_listen *)s;
|
||||
printf(lwip_bugkiller_tcp_listen_format[0], accept_num);
|
||||
}
|
34
components/net/lwip/lwip/bugkiller/bugkillerinc_string.c
Normal file
34
components/net/lwip/lwip/bugkiller/bugkillerinc_string.c
Normal file
@ -0,0 +1,34 @@
|
||||
char *lwip_bugkiller_format[]={
|
||||
"SocketId: %d\tType: UDP\t",
|
||||
"Status: %s:%d",
|
||||
" -> %s:%d",
|
||||
"SocketId: %d\tType: TCP\t",
|
||||
" (Listen)\r\n",
|
||||
"type not support\r\n",
|
||||
" -> %s:%d\r\n"
|
||||
};
|
||||
|
||||
char *lwip_bugkiller_tcp_state[]={
|
||||
" (CLOSED) \r\n",
|
||||
" (LISTEN) \r\n",
|
||||
" (SYN_SENT) \r\n",
|
||||
" (SYN_RCVD) \r\n",
|
||||
" (ESTABLISHED)\r\n",
|
||||
" (FIN_WAIT_1) \r\n",
|
||||
" (FIN_WAIT_2) \r\n",
|
||||
" (CLOSE_WAIT) \r\n",
|
||||
" (CLOSING) \r\n",
|
||||
" (LAST_ACK) \r\n",
|
||||
" (TIME_WAIT) \r\n"
|
||||
};
|
||||
|
||||
char *lwip_bugkiller_tcp_format[]={
|
||||
"recv wnd : -%lu ~ %lu ~ +%lu\r\r\n",
|
||||
"recv_ann wnd : -%lu ~ %lu\r\r\n",
|
||||
"snd wnd : -%lu ~ %lu ~ +%lu\r\r\n",
|
||||
"unsend len: %lu, unacked len: %lu, ooseq len: %lu\r\r\n"
|
||||
};
|
||||
|
||||
char *lwip_bugkiller_tcp_listen_format[]={
|
||||
"wait_accept_num: %lu\r\r\n"
|
||||
};
|
@ -0,0 +1,8 @@
|
||||
|
||||
void bugkiller_tcp_wnd_dump(unsigned long unrecv_len, void *pcb);
|
||||
void bugkiller_tcp_seg_dump(void *pcb);
|
||||
void bugkiller_tcp_listen_dump(unsigned long accept_num, void *pcb);
|
||||
extern char *lwip_bugkiller_format[7];
|
||||
extern char *lwip_bugkiller_tcp_state[11];
|
||||
extern char *lwip_bugkiller_tcp_format[4];
|
||||
extern char *lwip_bugkiller_tcp_listen_format[1];
|
9
components/net/lwip/lwip/doc/FILES
Normal file
9
components/net/lwip/lwip/doc/FILES
Normal file
@ -0,0 +1,9 @@
|
||||
doxygen/ - Configuration files and scripts to create the lwIP doxygen source
|
||||
documentation (found at http://www.nongnu.org/lwip/)
|
||||
|
||||
savannah.txt - How to obtain the current development source code.
|
||||
contrib.txt - How to contribute to lwIP as a developer.
|
||||
rawapi.txt - The documentation for the core API of lwIP.
|
||||
Also provides an overview about the other APIs and multithreading.
|
||||
sys_arch.txt - The documentation for a system abstraction layer of lwIP.
|
||||
ppp.txt - Documentation of the PPP interface for lwIP.
|
122
components/net/lwip/lwip/doc/NO_SYS_SampleCode.c
Normal file
122
components/net/lwip/lwip/doc/NO_SYS_SampleCode.c
Normal file
@ -0,0 +1,122 @@
|
||||
void
|
||||
eth_mac_irq()
|
||||
{
|
||||
/* Service MAC IRQ here */
|
||||
|
||||
/* Allocate pbuf from pool (avoid using heap in interrupts) */
|
||||
struct pbuf* p = pbuf_alloc(PBUF_RAW, eth_data_count, PBUF_POOL);
|
||||
|
||||
if(p != NULL) {
|
||||
/* Copy ethernet frame into pbuf */
|
||||
pbuf_take(p, eth_data, eth_data_count);
|
||||
|
||||
/* Put in a queue which is processed in main loop */
|
||||
if(!queue_try_put(&queue, p)) {
|
||||
/* queue is full -> packet loss */
|
||||
pbuf_free(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static err_t
|
||||
netif_output(struct netif *netif, struct pbuf *p)
|
||||
{
|
||||
LINK_STATS_INC(link.xmit);
|
||||
|
||||
/* Update SNMP stats (only if you use SNMP) */
|
||||
MIB2_STATS_NETIF_ADD(netif, ifoutoctets, p->tot_len);
|
||||
int unicast = ((p->payload[0] & 0x01) == 0);
|
||||
if (unicast) {
|
||||
MIB2_STATS_NETIF_INC(netif, ifoutucastpkts);
|
||||
} else {
|
||||
MIB2_STATS_NETIF_INC(netif, ifoutnucastpkts);
|
||||
}
|
||||
|
||||
lock_interrupts();
|
||||
pbuf_copy_partial(p, mac_send_buffer, p->tot_len, 0);
|
||||
/* Start MAC transmit here */
|
||||
unlock_interrupts();
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static void
|
||||
netif_status_callback(struct netif *netif)
|
||||
{
|
||||
printf("netif status changed %s\n", ip4addr_ntoa(netif_ip4_addr(netif)));
|
||||
}
|
||||
|
||||
static err_t
|
||||
netif_init(struct netif *netif)
|
||||
{
|
||||
netif->linkoutput = netif_output;
|
||||
netif->output = etharp_output;
|
||||
netif->output_ip6 = ethip6_output;
|
||||
netif->mtu = ETHERNET_MTU;
|
||||
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP | NETIF_FLAG_MLD6;
|
||||
MIB2_INIT_NETIF(netif, snmp_ifType_ethernet_csmacd, 100000000);
|
||||
|
||||
SMEMCPY(netif->hwaddr, your_mac_address_goes_here, ETH_HWADDR_LEN);
|
||||
netif->hwaddr_len = ETH_HWADDR_LEN;
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void
|
||||
main(void)
|
||||
{
|
||||
struct netif netif;
|
||||
|
||||
lwip_init();
|
||||
|
||||
netif_add(&netif, IP4_ADDR_ANY, IP4_ADDR_ANY, IP4_ADDR_ANY, NULL, netif_init, netif_input);
|
||||
netif.name[0] = 'e';
|
||||
netif.name[1] = '0';
|
||||
netif_create_ip6_linklocal_address(&netif, 1);
|
||||
netif.ip6_autoconfig_enabled = 1;
|
||||
netif_set_status_callback(&netif, netif_status_callback);
|
||||
netif_set_default(&netif);
|
||||
netif_set_up(&netif);
|
||||
|
||||
/* Start DHCP and HTTPD */
|
||||
dhcp_start(&netif );
|
||||
httpd_init();
|
||||
|
||||
while(1) {
|
||||
/* Check link state, e.g. via MDIO communication with PHY */
|
||||
if(link_state_changed()) {
|
||||
if(link_is_up()) {
|
||||
netif_set_link_up(&netif);
|
||||
} else {
|
||||
netif_set_link_down(&netif);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check for received frames, feed them to lwIP */
|
||||
lock_interrupts();
|
||||
struct pbuf* p = queue_try_get(&queue);
|
||||
unlock_interrupts();
|
||||
|
||||
if(p != NULL) {
|
||||
LINK_STATS_INC(link.recv);
|
||||
|
||||
/* Update SNMP stats (only if you use SNMP) */
|
||||
MIB2_STATS_NETIF_ADD(netif, ifinoctets, p->tot_len);
|
||||
int unicast = ((p->payload[0] & 0x01) == 0);
|
||||
if (unicast) {
|
||||
MIB2_STATS_NETIF_INC(netif, ifinucastpkts);
|
||||
} else {
|
||||
MIB2_STATS_NETIF_INC(netif, ifinnucastpkts);
|
||||
}
|
||||
|
||||
if(netif.input(p, &netif) != ERR_OK) {
|
||||
pbuf_free(p);
|
||||
}
|
||||
}
|
||||
|
||||
/* Cyclic lwIP timers check */
|
||||
sys_check_timeouts();
|
||||
|
||||
/* your application goes here */
|
||||
}
|
||||
}
|
45
components/net/lwip/lwip/doc/ZeroCopyRx.c
Normal file
45
components/net/lwip/lwip/doc/ZeroCopyRx.c
Normal file
@ -0,0 +1,45 @@
|
||||
typedef struct my_custom_pbuf
|
||||
{
|
||||
struct pbuf_custom p;
|
||||
void* dma_descriptor;
|
||||
} my_custom_pbuf_t;
|
||||
|
||||
LWIP_MEMPOOL_DECLARE(RX_POOL, 10, sizeof(my_custom_pbuf_t), "Zero-copy RX PBUF pool");
|
||||
|
||||
void my_pbuf_free_custom(void* p)
|
||||
{
|
||||
SYS_ARCH_DECL_PROTECT(old_level);
|
||||
|
||||
my_custom_pbuf_t* my_puf = (my_custom_pbuf_t*)p;
|
||||
|
||||
// invalidate data cache here - lwIP and/or application may have written into buffer!
|
||||
// (invalidate is faster than flushing, and noone needs the correct data in the buffer)
|
||||
invalidate_cpu_cache(p->payload, p->tot_len);
|
||||
|
||||
SYS_ARCH_PROTECT(old_level);
|
||||
free_rx_dma_descriptor(my_pbuf->dma_descriptor);
|
||||
LWIP_MEMPOOL_FREE(RX_POOL, my_pbuf);
|
||||
SYS_ARCH_UNPROTECT(old_level);
|
||||
}
|
||||
|
||||
void eth_rx_irq()
|
||||
{
|
||||
dma_descriptor* dma_desc = get_RX_DMA_descriptor_from_ethernet();
|
||||
my_custom_pbuf_t* my_pbuf = (my_custom_pbuf_t*)LWIP_MEMPOOL_ALLOC(RX_POOL);
|
||||
|
||||
my_pbuf->p.custom_free_function = my_pbuf_free_custom;
|
||||
my_pbuf->dma_descriptor = dma_desc;
|
||||
|
||||
invalidate_cpu_cache(dma_desc->rx_data, dma_desc->rx_length);
|
||||
|
||||
struct pbuf* p = pbuf_alloced_custom(PBUF_RAW,
|
||||
dma_desc->rx_length,
|
||||
PBUF_REF,
|
||||
&my_pbuf->p,
|
||||
dma_desc->rx_data,
|
||||
dma_desc->max_buffer_size);
|
||||
|
||||
if(netif->input(p, netif) != ERR_OK) {
|
||||
pbuf_free(p);
|
||||
}
|
||||
}
|
58
components/net/lwip/lwip/doc/contrib.txt
Normal file
58
components/net/lwip/lwip/doc/contrib.txt
Normal file
@ -0,0 +1,58 @@
|
||||
1 Introduction
|
||||
|
||||
This document describes some guidelines for people participating
|
||||
in lwIP development.
|
||||
|
||||
2 How to contribute to lwIP
|
||||
|
||||
Here is a short list of suggestions to anybody working with lwIP and
|
||||
trying to contribute bug reports, fixes, enhancements, platform ports etc.
|
||||
First of all as you may already know lwIP is a volunteer project so feedback
|
||||
to fixes or questions might often come late. Hopefully the bug and patch tracking
|
||||
features of Savannah help us not lose users' input.
|
||||
|
||||
2.1 Source code style:
|
||||
|
||||
1. do not use tabs.
|
||||
2. indentation is two spaces per level (i.e. per tab).
|
||||
3. end debug messages with a trailing newline (\n).
|
||||
4. one space between keyword and opening bracket.
|
||||
5. no space between function and opening bracket.
|
||||
6. one space and no newline before opening curly braces of a block.
|
||||
7. closing curly brace on a single line.
|
||||
8. spaces surrounding assignment and comparisons.
|
||||
9. don't initialize static and/or global variables to zero, the compiler takes care of that.
|
||||
10. use current source code style as further reference.
|
||||
|
||||
2.2 Source code documentation style:
|
||||
|
||||
1. JavaDoc compliant and Doxygen compatible.
|
||||
2. Function documentation above functions in .c files, not .h files.
|
||||
(This forces you to synchronize documentation and implementation.)
|
||||
3. Use current documentation style as further reference.
|
||||
|
||||
2.3 Bug reports and patches:
|
||||
|
||||
1. Make sure you are reporting bugs or send patches against the latest
|
||||
sources. (From the latest release and/or the current Git sources.)
|
||||
2. If you think you found a bug make sure it's not already filed in the
|
||||
bugtracker at Savannah.
|
||||
3. If you have a fix put the patch on Savannah. If it is a patch that affects
|
||||
both core and arch specific stuff please separate them so that the core can
|
||||
be applied separately while leaving the other patch 'open'. The preferred way
|
||||
is to NOT touch archs you can't test and let maintainers take care of them.
|
||||
This is a good way to see if they are used at all - the same goes for unix
|
||||
netifs except tapif.
|
||||
4. Do not file a bug and post a fix to it to the patch area. Either a bug report
|
||||
or a patch will be enough.
|
||||
If you correct an existing bug then attach the patch to the bug rather than creating a new entry in the patch area.
|
||||
5. Patches should be specific to a single change or to related changes. Do not mix bugfixes with spelling and other
|
||||
trivial fixes unless the bugfix is trivial too. Do not reorganize code and rename identifiers in the same patch you
|
||||
change behaviour if not necessary. A patch is easier to read and understand if it's to the point and short than
|
||||
if it's not to the point and long :) so the chances for it to be applied are greater.
|
||||
|
||||
2.4 Platform porters:
|
||||
|
||||
1. If you have ported lwIP to a platform (an OS, a uC/processor or a combination of these) and
|
||||
you think it could benefit others[1] you might want discuss this on the mailing list. You
|
||||
can also ask for Git access to submit and maintain your port in the contrib Git module.
|
1
components/net/lwip/lwip/doc/doxygen/generate.bat
Normal file
1
components/net/lwip/lwip/doc/doxygen/generate.bat
Normal file
@ -0,0 +1 @@
|
||||
doxygen lwip.Doxyfile
|
3
components/net/lwip/lwip/doc/doxygen/generate.sh
Normal file
3
components/net/lwip/lwip/doc/doxygen/generate.sh
Normal file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
doxygen lwip.Doxyfile
|
2531
components/net/lwip/lwip/doc/doxygen/lwip.Doxyfile
Normal file
2531
components/net/lwip/lwip/doc/doxygen/lwip.Doxyfile
Normal file
File diff suppressed because it is too large
Load Diff
2531
components/net/lwip/lwip/doc/doxygen/lwip.Doxyfile.cmake.in
Normal file
2531
components/net/lwip/lwip/doc/doxygen/lwip.Doxyfile.cmake.in
Normal file
File diff suppressed because it is too large
Load Diff
403
components/net/lwip/lwip/doc/doxygen/main_page.h
Normal file
403
components/net/lwip/lwip/doc/doxygen/main_page.h
Normal file
@ -0,0 +1,403 @@
|
||||
/**
|
||||
* @defgroup lwip lwIP
|
||||
*
|
||||
* @defgroup infrastructure Infrastructure
|
||||
*
|
||||
* @defgroup api APIs
|
||||
* lwIP provides three Application Program's Interfaces (APIs) for programs
|
||||
* to use for communication with the TCP/IP code:
|
||||
* - low-level "core" / "callback" or @ref callbackstyle_api.
|
||||
* - higher-level @ref sequential_api.
|
||||
* - BSD-style @ref socket.
|
||||
*
|
||||
* The raw TCP/IP interface allows the application program to integrate
|
||||
* better with the TCP/IP code. Program execution is event based by
|
||||
* having callback functions being called from within the TCP/IP
|
||||
* code. The TCP/IP code and the application program both run in the same
|
||||
* thread. The sequential API has a much higher overhead and is not very
|
||||
* well suited for small systems since it forces a multithreaded paradigm
|
||||
* on the application.
|
||||
*
|
||||
* The raw TCP/IP interface is not only faster in terms of code execution
|
||||
* time but is also less memory intensive. The drawback is that program
|
||||
* development is somewhat harder and application programs written for
|
||||
* the raw TCP/IP interface are more difficult to understand. Still, this
|
||||
* is the preferred way of writing applications that should be small in
|
||||
* code size and memory usage.
|
||||
*
|
||||
* All APIs can be used simultaneously by different application
|
||||
* programs. In fact, the sequential API is implemented as an application
|
||||
* program using the raw TCP/IP interface.
|
||||
*
|
||||
* Do not confuse the lwIP raw API with raw Ethernet or IP sockets.
|
||||
* The former is a way of interfacing the lwIP network stack (including
|
||||
* TCP and UDP), the latter refers to processing raw Ethernet or IP data
|
||||
* instead of TCP connections or UDP packets.
|
||||
*
|
||||
* Raw API applications may never block since all packet processing
|
||||
* (input and output) as well as timer processing (TCP mainly) is done
|
||||
* in a single execution context.
|
||||
*
|
||||
* @defgroup callbackstyle_api "raw" APIs
|
||||
* @ingroup api
|
||||
* Non thread-safe APIs, callback style for maximum performance and minimum
|
||||
* memory footprint.
|
||||
* Program execution is driven by callbacks functions, which are then
|
||||
* invoked by the lwIP core when activity related to that application
|
||||
* occurs. A particular application may register to be notified via a
|
||||
* callback function for events such as incoming data available, outgoing
|
||||
* data sent, error notifications, poll timer expiration, connection
|
||||
* closed, etc. An application can provide a callback function to perform
|
||||
* processing for any or all of these events. Each callback is an ordinary
|
||||
* C function that is called from within the TCP/IP code. Every callback
|
||||
* function is passed the current TCP or UDP connection state as an
|
||||
* argument. Also, in order to be able to keep program specific state,
|
||||
* the callback functions are called with a program specified argument
|
||||
* that is independent of the TCP/IP state.
|
||||
* The raw API (sometimes called native API) is an event-driven API designed
|
||||
* to be used without an operating system that implements zero-copy send and
|
||||
* receive. This API is also used by the core stack for interaction between
|
||||
* the various protocols. It is the only API available when running lwIP
|
||||
* without an operating system.
|
||||
*
|
||||
* @defgroup sequential_api Sequential-style APIs
|
||||
* @ingroup api
|
||||
* Sequential-style APIs, blocking functions. More overhead, but can be called
|
||||
* from any thread except TCPIP thread.
|
||||
* The sequential API provides a way for ordinary, sequential, programs
|
||||
* to use the lwIP stack. It is quite similar to the BSD socket API. The
|
||||
* model of execution is based on the blocking open-read-write-close
|
||||
* paradigm. Since the TCP/IP stack is event based by nature, the TCP/IP
|
||||
* code and the application program must reside in different execution
|
||||
* contexts (threads).
|
||||
*
|
||||
* @defgroup socket Socket API
|
||||
* @ingroup api
|
||||
* BSD-style socket API.\n
|
||||
* Thread-safe, to be called from non-TCPIP threads only.\n
|
||||
* Can be activated by defining @ref LWIP_SOCKET to 1.\n
|
||||
* Header is in posix/sys/socket.h\n
|
||||
* The socket API is a compatibility API for existing applications,
|
||||
* currently it is built on top of the sequential API. It is meant to
|
||||
* provide all functions needed to run socket API applications running
|
||||
* on other platforms (e.g. unix / windows etc.). However, due to limitations
|
||||
* in the specification of this API, there might be incompatibilities
|
||||
* that require small modifications of existing programs.
|
||||
*
|
||||
* @defgroup netifs NETIFs
|
||||
*
|
||||
* @defgroup apps Applications
|
||||
*/
|
||||
|
||||
/**
|
||||
* @mainpage Overview
|
||||
* @verbinclude "README"
|
||||
*/
|
||||
|
||||
/**
|
||||
* @page upgrading Upgrading
|
||||
* @verbinclude "UPGRADING"
|
||||
*/
|
||||
|
||||
/**
|
||||
* @page changelog Changelog
|
||||
*
|
||||
* 2.1.0
|
||||
* -----
|
||||
* * Support TLS via new @ref altcp_api connection API (https, smtps, mqtt over TLS)
|
||||
* * Switch to cmake as the main build system (Makefile file lists are still
|
||||
* maintained for now)
|
||||
* * Improve IPv6 support: support address scopes, support stateless DHCPv6, bugfixes
|
||||
* * Add debug helper asserts to ensure threading/locking requirements are met
|
||||
* * Add sys_mbox_trypost_fromisr() and tcpip_callbackmsg_trycallback_fromisr()
|
||||
* (for FreeRTOS, mainly)
|
||||
* * socket API: support poll(), sendmsg() and recvmsg(); fix problems on close
|
||||
*
|
||||
* Detailed Changelog
|
||||
* ------------------
|
||||
* @verbinclude "CHANGELOG"
|
||||
*/
|
||||
|
||||
/**
|
||||
* @page contrib How to contribute to lwIP
|
||||
* @verbinclude "contrib.txt"
|
||||
*/
|
||||
|
||||
/**
|
||||
* @page pitfalls Common pitfalls
|
||||
*
|
||||
* Multiple Execution Contexts in lwIP code
|
||||
* ========================================
|
||||
*
|
||||
* The most common source of lwIP problems is to have multiple execution contexts
|
||||
* inside the lwIP code.
|
||||
*
|
||||
* lwIP can be used in two basic modes: @ref lwip_nosys (no OS/RTOS
|
||||
* running on target system) or @ref lwip_os (there is an OS running
|
||||
* on the target system).
|
||||
*
|
||||
* See also: @ref multithreading (especially the part about @ref LWIP_ASSERT_CORE_LOCKED()!)
|
||||
*
|
||||
* Mainloop Mode
|
||||
* -------------
|
||||
* In mainloop mode, only @ref callbackstyle_api can be used.
|
||||
* The user has two possibilities to ensure there is only one
|
||||
* exection context at a time in lwIP:
|
||||
*
|
||||
* 1) Deliver RX ethernet packets directly in interrupt context to lwIP
|
||||
* by calling netif->input directly in interrupt. This implies all lwIP
|
||||
* callback functions are called in IRQ context, which may cause further
|
||||
* problems in application code: IRQ is blocked for a long time, multiple
|
||||
* execution contexts in application code etc. When the application wants
|
||||
* to call lwIP, it only needs to disable interrupts during the call.
|
||||
* If timers are involved, even more locking code is needed to lock out
|
||||
* timer IRQ and ethernet IRQ from each other, assuming these may be nested.
|
||||
*
|
||||
* 2) Run lwIP in a mainloop. There is example code here: @ref lwip_nosys.
|
||||
* lwIP is _ONLY_ called from mainloop callstacks here. The ethernet IRQ
|
||||
* has to put received telegrams into a queue which is polled in the
|
||||
* mainloop. Ensure lwIP is _NEVER_ called from an interrupt, e.g.
|
||||
* some SPI IRQ wants to forward data to udp_send() or tcp_write()!
|
||||
*
|
||||
* OS Mode
|
||||
* -------
|
||||
* In OS mode, @ref callbackstyle_api AND @ref sequential_api can be used.
|
||||
* @ref sequential_api are designed to be called from threads other than
|
||||
* the TCPIP thread, so there is nothing to consider here.
|
||||
* But @ref callbackstyle_api functions must _ONLY_ be called from
|
||||
* TCPIP thread. It is a common error to call these from other threads
|
||||
* or from IRQ contexts. Ethernet RX needs to deliver incoming packets
|
||||
* in the correct way by sending a message to TCPIP thread, this is
|
||||
* implemented in tcpip_input().
|
||||
* Again, ensure lwIP is _NEVER_ called from an interrupt, e.g.
|
||||
* some SPI IRQ wants to forward data to udp_send() or tcp_write()!
|
||||
*
|
||||
* 1) tcpip_callback() can be used get called back from TCPIP thread,
|
||||
* it is safe to call any @ref callbackstyle_api from there.
|
||||
*
|
||||
* 2) Use @ref LWIP_TCPIP_CORE_LOCKING. All @ref callbackstyle_api
|
||||
* functions can be called when lwIP core lock is aquired, see
|
||||
* @ref LOCK_TCPIP_CORE() and @ref UNLOCK_TCPIP_CORE().
|
||||
* These macros cannot be used in an interrupt context!
|
||||
* Note the OS must correctly handle priority inversion for this.
|
||||
*
|
||||
* Cache / DMA issues
|
||||
* ==================
|
||||
*
|
||||
* DMA-capable ethernet hardware and zero-copy RX
|
||||
* ----------------------------------------------
|
||||
*
|
||||
* lwIP changes the content of RECEIVED pbufs in the TCP code path.
|
||||
* This implies one or more cacheline(s) of the RX pbuf become dirty
|
||||
* and need to be flushed before the memory is handed over to the
|
||||
* DMA ethernet hardware for the next telegram to be received.
|
||||
* See http://lists.nongnu.org/archive/html/lwip-devel/2017-12/msg00070.html
|
||||
* for a more detailed explanation.
|
||||
* Also keep in mind the user application may also write into pbufs,
|
||||
* so it is generally a bug not to flush the data cache before handing
|
||||
* a buffer to DMA hardware.
|
||||
*
|
||||
* DMA-capable ethernet hardware and cacheline alignment
|
||||
* -----------------------------------------------------
|
||||
* Nice description about DMA capable hardware and buffer handling:
|
||||
* http://www.pebblebay.com/a-guide-to-using-direct-memory-access-in-embedded-systems-part-two/
|
||||
* Read especially sections "Cache coherency" and "Buffer alignment".
|
||||
*/
|
||||
|
||||
/**
|
||||
* @page bugs Reporting bugs
|
||||
* Please report bugs in the lwIP bug tracker at savannah.\n
|
||||
* BEFORE submitting, please check if the bug has already been reported!\n
|
||||
* https://savannah.nongnu.org/bugs/?group=lwip
|
||||
*/
|
||||
|
||||
/**
|
||||
* @page zerocopyrx Zero-copy RX
|
||||
* The following code is an example for zero-copy RX ethernet driver:
|
||||
* @include ZeroCopyRx.c
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup lwip_nosys Mainloop mode ("NO_SYS")
|
||||
* @ingroup lwip
|
||||
* Use this mode if you do not run an OS on your system. \#define NO_SYS to 1.
|
||||
* Feed incoming packets to netif->input(pbuf, netif) function from mainloop,
|
||||
* *not* *from* *interrupt* *context*. You can allocate a @ref pbuf in interrupt
|
||||
* context and put them into a queue which is processed from mainloop.\n
|
||||
* Call sys_check_timeouts() periodically in the mainloop.\n
|
||||
* Porting: implement all functions in @ref sys_time, @ref sys_prot and
|
||||
* @ref compiler_abstraction.\n
|
||||
* You can only use @ref callbackstyle_api in this mode.\n
|
||||
* Sample code:\n
|
||||
* @include NO_SYS_SampleCode.c
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup lwip_os OS mode (TCPIP thread)
|
||||
* @ingroup lwip
|
||||
* Use this mode if you run an OS on your system. It is recommended to
|
||||
* use an RTOS that correctly handles priority inversion and
|
||||
* to use @ref LWIP_TCPIP_CORE_LOCKING.\n
|
||||
* Porting: implement all functions in @ref sys_layer.\n
|
||||
* You can use @ref callbackstyle_api together with @ref tcpip_callback,
|
||||
* and all @ref sequential_api.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @page sys_init System initalization
|
||||
A truly complete and generic sequence for initializing the lwIP stack
|
||||
cannot be given because it depends on additional initializations for
|
||||
your runtime environment (e.g. timers).
|
||||
|
||||
We can give you some idea on how to proceed when using the raw API.
|
||||
We assume a configuration using a single Ethernet netif and the
|
||||
UDP and TCP transport layers, IPv4 and the DHCP client.
|
||||
|
||||
Call these functions in the order of appearance:
|
||||
|
||||
- lwip_init(): Initialize the lwIP stack and all of its subsystems.
|
||||
|
||||
- netif_add(struct netif *netif, ...):
|
||||
Adds your network interface to the netif_list. Allocate a struct
|
||||
netif and pass a pointer to this structure as the first argument.
|
||||
Give pointers to cleared ip_addr structures when using DHCP,
|
||||
or fill them with sane numbers otherwise. The state pointer may be NULL.
|
||||
|
||||
The init function pointer must point to a initialization function for
|
||||
your Ethernet netif interface. The following code illustrates its use.
|
||||
|
||||
@code{.c}
|
||||
err_t netif_if_init(struct netif *netif)
|
||||
{
|
||||
u8_t i;
|
||||
|
||||
for (i = 0; i < ETHARP_HWADDR_LEN; i++) {
|
||||
netif->hwaddr[i] = some_eth_addr[i];
|
||||
}
|
||||
init_my_eth_device();
|
||||
return ERR_OK;
|
||||
}
|
||||
@endcode
|
||||
|
||||
For Ethernet drivers, the input function pointer must point to the lwIP
|
||||
function ethernet_input() declared in "netif/etharp.h". Other drivers
|
||||
must use ip_input() declared in "lwip/ip.h".
|
||||
|
||||
- netif_set_default(struct netif *netif)
|
||||
Registers the default network interface.
|
||||
|
||||
- netif_set_link_up(struct netif *netif)
|
||||
This is the hardware link state; e.g. whether cable is plugged for wired
|
||||
Ethernet interface. This function must be called even if you don't know
|
||||
the current state. Having link up and link down events is optional but
|
||||
DHCP and IPv6 discover benefit well from those events.
|
||||
|
||||
- netif_set_up(struct netif *netif)
|
||||
This is the administrative (= software) state of the netif, when the
|
||||
netif is fully configured this function must be called.
|
||||
|
||||
- dhcp_start(struct netif *netif)
|
||||
Creates a new DHCP client for this interface on the first call.
|
||||
You can peek in the netif->dhcp struct for the actual DHCP status.
|
||||
|
||||
- sys_check_timeouts()
|
||||
When the system is running, you have to periodically call
|
||||
sys_check_timeouts() which will handle all timers for all protocols in
|
||||
the stack; add this to your main loop or equivalent.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @page multithreading Multithreading
|
||||
* lwIP started targeting single-threaded environments. When adding multi-
|
||||
* threading support, instead of making the core thread-safe, another
|
||||
* approach was chosen: there is one main thread running the lwIP core
|
||||
* (also known as the "tcpip_thread"). When running in a multithreaded
|
||||
* environment, raw API functions MUST only be called from the core thread
|
||||
* since raw API functions are not protected from concurrent access (aside
|
||||
* from pbuf- and memory management functions). Application threads using
|
||||
* the sequential- or socket API communicate with this main thread through
|
||||
* message passing.
|
||||
*
|
||||
* As such, the list of functions that may be called from
|
||||
* other threads or an ISR is very limited! Only functions
|
||||
* from these API header files are thread-safe:
|
||||
* - api.h
|
||||
* - netbuf.h
|
||||
* - netdb.h
|
||||
* - netifapi.h
|
||||
* - pppapi.h
|
||||
* - sockets.h
|
||||
* - sys.h
|
||||
*
|
||||
* Additionaly, memory (de-)allocation functions may be
|
||||
* called from multiple threads (not ISR!) with NO_SYS=0
|
||||
* since they are protected by @ref SYS_LIGHTWEIGHT_PROT and/or
|
||||
* semaphores.
|
||||
*
|
||||
* Netconn or Socket API functions are thread safe against the
|
||||
* core thread but they are not reentrant at the control block
|
||||
* granularity level. That is, a UDP or TCP control block must
|
||||
* not be shared among multiple threads without proper locking.
|
||||
*
|
||||
* If @ref SYS_LIGHTWEIGHT_PROT is set to 1 and
|
||||
* @ref LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT is set to 1,
|
||||
* pbuf_free() may also be called from another thread or
|
||||
* an ISR (since only then, mem_free - for PBUF_RAM - may
|
||||
* be called from an ISR: otherwise, the HEAP is only
|
||||
* protected by semaphores).
|
||||
*
|
||||
* How to get threading done right
|
||||
* -------------------------------
|
||||
*
|
||||
* It is strongly recommended to implement the LWIP_ASSERT_CORE_LOCKED()
|
||||
* macro in an application that uses multithreading. lwIP code has
|
||||
* several places where a check for a correct thread context is
|
||||
* implemented which greatly helps the user to get threading done right.
|
||||
* See the example sys_arch.c files in unix and Win32 port
|
||||
* in the contrib repository.
|
||||
*
|
||||
* In short: Copy the functions sys_mark_tcpip_thread() and
|
||||
* sys_check_core_locking() to your port and modify them to work with your OS.
|
||||
* Then let @ref LWIP_ASSERT_CORE_LOCKED() and @ref LWIP_MARK_TCPIP_THREAD()
|
||||
* point to these functions.
|
||||
*
|
||||
* If you use @ref LWIP_TCPIP_CORE_LOCKING, you also need to copy and adapt
|
||||
* the functions sys_lock_tcpip_core() and sys_unlock_tcpip_core().
|
||||
* Let @ref LOCK_TCPIP_CORE() and @ref UNLOCK_TCPIP_CORE() point
|
||||
* to these functions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @page optimization Optimization hints
|
||||
The first thing you want to optimize is the lwip_standard_checksum()
|
||||
routine from src/core/inet.c. You can override this standard
|
||||
function with the \#define LWIP_CHKSUM your_checksum_routine().
|
||||
|
||||
There are C examples given in inet.c or you might want to
|
||||
craft an assembly function for this. RFC1071 is a good
|
||||
introduction to this subject.
|
||||
|
||||
Other significant improvements can be made by supplying
|
||||
assembly or inline replacements for htons() and htonl()
|
||||
if you're using a little-endian architecture.
|
||||
\#define lwip_htons(x) your_htons()
|
||||
\#define lwip_htonl(x) your_htonl()
|
||||
If you \#define them to htons() and htonl(), you should
|
||||
\#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS to prevent lwIP from
|
||||
defining htonx / ntohx compatibility macros.
|
||||
|
||||
Check your network interface driver if it reads at
|
||||
a higher speed than the maximum wire-speed. If the
|
||||
hardware isn't serviced frequently and fast enough
|
||||
buffer overflows are likely to occur.
|
||||
|
||||
E.g. when using the cs8900 driver, call cs8900if_service(ethif)
|
||||
as frequently as possible. When using an RTOS let the cs8900 interrupt
|
||||
wake a high priority task that services your driver using a binary
|
||||
semaphore or event flag. Some drivers might allow additional tuning
|
||||
to match your application and network.
|
||||
|
||||
For a production release it is recommended to set LWIP_STATS to 0.
|
||||
Note that speed performance isn't influenced much by simply setting
|
||||
high values to the memory options.
|
||||
*/
|
10
components/net/lwip/lwip/doc/doxygen/output/index.html
Normal file
10
components/net/lwip/lwip/doc/doxygen/output/index.html
Normal file
@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>Redirection</title>
|
||||
<meta http-equiv="refresh" content="0; url=html/index.html" />
|
||||
</head>
|
||||
<body>
|
||||
<a href="html/index.html">index.html</a>
|
||||
</body>
|
||||
</html>
|
112
components/net/lwip/lwip/doc/mdns.txt
Normal file
112
components/net/lwip/lwip/doc/mdns.txt
Normal file
@ -0,0 +1,112 @@
|
||||
Multicast DNS for lwIP
|
||||
|
||||
Author: Erik Ekman
|
||||
|
||||
|
||||
Note! The MDNS responder does not have all features required by the standards.
|
||||
See notes in src/apps/mdns/mdns.c for what is left. It is however usable in normal
|
||||
cases - but watch out if many devices on the same network try to use the same
|
||||
host/service instance names.
|
||||
|
||||
|
||||
How to enable:
|
||||
==============
|
||||
|
||||
MDNS support does not depend on DNS.
|
||||
MDNS supports using IPv4 only, v6 only, or v4+v6.
|
||||
|
||||
To enable MDNS responder, set
|
||||
LWIP_MDNS_RESPONDER = 1
|
||||
in lwipopts.h and add src/apps/mdns/mdns.c to your list of files to build.
|
||||
|
||||
The max number of services supported per netif is defined by MDNS_MAX_SERVICES,
|
||||
default is 1.
|
||||
|
||||
Increase MEMP_NUM_UDP_PCB by 1. MDNS needs one PCB.
|
||||
Increase LWIP_NUM_NETIF_CLIENT_DATA by 1 (MDNS needs one entry on netif).
|
||||
|
||||
MDNS with IPv4 requires LWIP_IGMP = 1, and preferably LWIP_AUTOIP = 1.
|
||||
MDNS with IPv6 requires LWIP_IPV6_MLD = 1, and that a link-local address is
|
||||
generated.
|
||||
|
||||
The MDNS code puts its structs on the stack where suitable to reduce dynamic
|
||||
memory allocation. It may use up to 1kB of stack.
|
||||
|
||||
MDNS (like other apps) needs a strncasecmp() implementation. If you have one, define
|
||||
'lwip_strnicmp' to it. Otherwise the code will provide an implementation
|
||||
for you.
|
||||
|
||||
|
||||
How to use:
|
||||
===========
|
||||
|
||||
Call mdns_resp_init() during system initialization.
|
||||
This opens UDP sockets on port 5353 for IPv4 and IPv6.
|
||||
|
||||
|
||||
To start responding on a netif, run
|
||||
mdns_resp_add_netif(struct netif *netif, char *hostname, u32_t dns_ttl)
|
||||
|
||||
The hostname will be copied. If this returns successfully, the netif will join
|
||||
the multicast groups and any MDNS/legacy DNS requests sent unicast or multicast
|
||||
to port 5353 will be handled:
|
||||
- <hostname>.local type A, AAAA or ANY returns relevant IP addresses
|
||||
- Reverse lookups (PTR in-addr.arpa, ip6.arpa) of netif addresses
|
||||
returns <hostname>.local
|
||||
Answers will use the supplied TTL (in seconds)
|
||||
MDNS allows UTF-8 names, but it is recommended to stay within ASCII,
|
||||
since the default case-insensitive comparison assumes this.
|
||||
|
||||
Call mdns_resp_announce() every time the IP address on the netif has changed.
|
||||
|
||||
Call mdns_resp_restart() every time the network interface comes up after being
|
||||
down, for example cable connected after being disconnected, administrative
|
||||
interface comes up after being down, or the device wakes up from sleep.
|
||||
|
||||
To stop responding on a netif, run
|
||||
mdns_resp_remove_netif(struct netif *netif)
|
||||
|
||||
|
||||
Adding services:
|
||||
================
|
||||
|
||||
The netif first needs to be registered. Then run
|
||||
mdns_resp_add_service(struct netif *netif, char *name, char *service,
|
||||
u16_t proto, u16_t port, u32_t dns_ttl,
|
||||
service_get_txt_fn_t txt_fn, void *txt_userdata);
|
||||
|
||||
The name and service pointers will be copied. Name refers to the name of the
|
||||
service instance, and service is the type of service, like _http
|
||||
proto can be DNSSD_PROTO_UDP or DNSSD_PROTO_TCP which represent _udp and _tcp.
|
||||
If this call returns successfully, the following queries will be answered:
|
||||
- _services._dns-sd._udp.local type PTR returns <service>.<proto>.local
|
||||
- <service>.<proto>.local type PTR returns <name>.<service>.<proto>.local
|
||||
- <name>.<service>.<proto>.local type SRV returns hostname and port of service
|
||||
- <name>.<service>.<proto>.local type TXT builds text strings by calling txt_fn
|
||||
with the supplied userdata. The callback adds strings to the reply by calling
|
||||
mdns_resp_add_service_txtitem(struct mdns_service *service, char *txt,
|
||||
int txt_len). Example callback method:
|
||||
|
||||
static void srv_txt(struct mdns_service *service, void *txt_userdata)
|
||||
{
|
||||
res = mdns_resp_add_service_txtitem(service, "path=/", 6);
|
||||
LWIP_ERROR("mdns add service txt failed\n", (res == ERR_OK), return);
|
||||
}
|
||||
|
||||
Since a hostname struct is used for TXT storage each single item can be max
|
||||
63 bytes long, and the total max length (including length bytes for each
|
||||
item) is 255 bytes.
|
||||
|
||||
If your device runs a webserver on port 80, an example call might be:
|
||||
|
||||
mdns_resp_add_service(netif, "myweb", "_http"
|
||||
DNSSD_PROTO_TCP, 80, 3600, srv_txt, NULL);
|
||||
|
||||
which will publish myweb._http._tcp.local for any hosts looking for web servers,
|
||||
and point them to <hostname>.local:80
|
||||
|
||||
Relevant information will be sent as additional records to reduce number of
|
||||
requests required from a client.
|
||||
|
||||
To remove a service from a netif, run
|
||||
mdns_resp_del_service(struct netif *netif, s8_t slot)
|
162
components/net/lwip/lwip/doc/mqtt_client.txt
Normal file
162
components/net/lwip/lwip/doc/mqtt_client.txt
Normal file
@ -0,0 +1,162 @@
|
||||
MQTT client for lwIP
|
||||
|
||||
Author: Erik Andersson
|
||||
|
||||
Details of the MQTT protocol can be found at:
|
||||
http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html
|
||||
|
||||
-----------------------------------------------------------------
|
||||
1. Initial steps, reserve memory and make connection to server:
|
||||
|
||||
1.1: Provide storage
|
||||
|
||||
Static allocation:
|
||||
mqtt_client_t static_client;
|
||||
example_do_connect(&static_client);
|
||||
|
||||
Dynamic allocation:
|
||||
mqtt_client_t *client = mqtt_client_new();
|
||||
if(client != NULL) {
|
||||
example_do_connect(&client);
|
||||
}
|
||||
|
||||
1.2: Establish Connection with server
|
||||
|
||||
void example_do_connect(mqtt_client_t *client)
|
||||
{
|
||||
struct mqtt_connect_client_info_t ci;
|
||||
err_t err;
|
||||
|
||||
/* Setup an empty client info structure */
|
||||
memset(&ci, 0, sizeof(ci));
|
||||
|
||||
/* Minimal amount of information required is client identifier, so set it here */
|
||||
ci.client_id = "lwip_test";
|
||||
|
||||
/* Initiate client and connect to server, if this fails immediately an error code is returned
|
||||
otherwise mqtt_connection_cb will be called with connection result after attempting
|
||||
to establish a connection with the server.
|
||||
For now MQTT version 3.1.1 is always used */
|
||||
|
||||
err = mqtt_client_connect(client, ip_addr, MQTT_PORT, mqtt_connection_cb, 0, &ci);
|
||||
|
||||
/* For now just print the result code if something goes wrong */
|
||||
if(err != ERR_OK) {
|
||||
printf("mqtt_connect return %d\n", err);
|
||||
}
|
||||
}
|
||||
|
||||
Connection to server can also be probed by calling mqtt_client_is_connected(client)
|
||||
|
||||
-----------------------------------------------------------------
|
||||
2. Implementing the connection status callback
|
||||
|
||||
|
||||
static void mqtt_connection_cb(mqtt_client_t *client, void *arg, mqtt_connection_status_t status)
|
||||
{
|
||||
err_t err;
|
||||
if(status == MQTT_CONNECT_ACCEPTED) {
|
||||
printf("mqtt_connection_cb: Successfully connected\n");
|
||||
|
||||
/* Setup callback for incoming publish requests */
|
||||
mqtt_set_inpub_callback(client, mqtt_incoming_publish_cb, mqtt_incoming_data_cb, arg);
|
||||
|
||||
/* Subscribe to a topic named "subtopic" with QoS level 1, call mqtt_sub_request_cb with result */
|
||||
err = mqtt_subscribe(client, "subtopic", 1, mqtt_sub_request_cb, arg);
|
||||
|
||||
if(err != ERR_OK) {
|
||||
printf("mqtt_subscribe return: %d\n", err);
|
||||
}
|
||||
} else {
|
||||
printf("mqtt_connection_cb: Disconnected, reason: %d\n", status);
|
||||
|
||||
/* Its more nice to be connected, so try to reconnect */
|
||||
example_do_connect(client);
|
||||
}
|
||||
}
|
||||
|
||||
static void mqtt_sub_request_cb(void *arg, err_t result)
|
||||
{
|
||||
/* Just print the result code here for simplicity,
|
||||
normal behaviour would be to take some action if subscribe fails like
|
||||
notifying user, retry subscribe or disconnect from server */
|
||||
printf("Subscribe result: %d\n", result);
|
||||
}
|
||||
|
||||
-----------------------------------------------------------------
|
||||
3. Implementing callbacks for incoming publish and data
|
||||
|
||||
/* The idea is to demultiplex topic and create some reference to be used in data callbacks
|
||||
Example here uses a global variable, better would be to use a member in arg
|
||||
If RAM and CPU budget allows it, the easiest implementation might be to just take a copy of
|
||||
the topic string and use it in mqtt_incoming_data_cb
|
||||
*/
|
||||
static int inpub_id;
|
||||
static void mqtt_incoming_publish_cb(void *arg, const char *topic, u32_t tot_len)
|
||||
{
|
||||
printf("Incoming publish at topic %s with total length %u\n", topic, (unsigned int)tot_len);
|
||||
|
||||
/* Decode topic string into a user defined reference */
|
||||
if(strcmp(topic, "print_payload") == 0) {
|
||||
inpub_id = 0;
|
||||
} else if(topic[0] == 'A') {
|
||||
/* All topics starting with 'A' might be handled at the same way */
|
||||
inpub_id = 1;
|
||||
} else {
|
||||
/* For all other topics */
|
||||
inpub_id = 2;
|
||||
}
|
||||
}
|
||||
|
||||
static void mqtt_incoming_data_cb(void *arg, const u8_t *data, u16_t len, u8_t flags)
|
||||
{
|
||||
printf("Incoming publish payload with length %d, flags %u\n", len, (unsigned int)flags);
|
||||
|
||||
if(flags & MQTT_DATA_FLAG_LAST) {
|
||||
/* Last fragment of payload received (or whole part if payload fits receive buffer
|
||||
See MQTT_VAR_HEADER_BUFFER_LEN) */
|
||||
|
||||
/* Call function or do action depending on reference, in this case inpub_id */
|
||||
if(inpub_id == 0) {
|
||||
/* Don't trust the publisher, check zero termination */
|
||||
if(data[len-1] == 0) {
|
||||
printf("mqtt_incoming_data_cb: %s\n", (const char *)data);
|
||||
}
|
||||
} else if(inpub_id == 1) {
|
||||
/* Call an 'A' function... */
|
||||
} else {
|
||||
printf("mqtt_incoming_data_cb: Ignoring payload...\n");
|
||||
}
|
||||
} else {
|
||||
/* Handle fragmented payload, store in buffer, write to file or whatever */
|
||||
}
|
||||
}
|
||||
|
||||
-----------------------------------------------------------------
|
||||
4. Using outgoing publish
|
||||
|
||||
|
||||
void example_publish(mqtt_client_t *client, void *arg)
|
||||
{
|
||||
const char *pub_payload= "PubSubHubLubJub";
|
||||
err_t err;
|
||||
u8_t qos = 2; /* 0 1 or 2, see MQTT specification */
|
||||
u8_t retain = 0; /* No don't retain such crappy payload... */
|
||||
err = mqtt_publish(client, "pub_topic", pub_payload, strlen(pub_payload), qos, retain, mqtt_pub_request_cb, arg);
|
||||
if(err != ERR_OK) {
|
||||
printf("Publish err: %d\n", err);
|
||||
}
|
||||
}
|
||||
|
||||
/* Called when publish is complete either with sucess or failure */
|
||||
static void mqtt_pub_request_cb(void *arg, err_t result)
|
||||
{
|
||||
if(result != ERR_OK) {
|
||||
printf("Publish result: %d\n", result);
|
||||
}
|
||||
}
|
||||
|
||||
-----------------------------------------------------------------
|
||||
5. Disconnecting
|
||||
|
||||
Simply call mqtt_disconnect(client)
|
529
components/net/lwip/lwip/doc/ppp.txt
Normal file
529
components/net/lwip/lwip/doc/ppp.txt
Normal file
@ -0,0 +1,529 @@
|
||||
PPP interface for lwIP
|
||||
|
||||
Author: Sylvain Rochet
|
||||
|
||||
Table of Contents:
|
||||
|
||||
1 - Supported PPP protocols and features
|
||||
2 - Raw API PPP example for all protocols
|
||||
3 - PPPoS input path (raw API, IRQ safe API, TCPIP API)
|
||||
4 - Thread safe PPP API (PPPAPI)
|
||||
5 - Notify phase callback (PPP_NOTIFY_PHASE)
|
||||
6 - Upgrading from lwIP <= 1.4.x to lwIP >= 2.0.x
|
||||
|
||||
|
||||
|
||||
1 Supported PPP protocols and features
|
||||
======================================
|
||||
|
||||
Supported Low level protocols:
|
||||
* PPP over serial using HDLC-like framing, such as wired dialup modems
|
||||
or mobile telecommunications GPRS/EDGE/UMTS/HSPA+/LTE modems
|
||||
* PPP over Ethernet, such as xDSL modems
|
||||
* PPP over L2TP (Layer 2 Tunneling Protocol) LAC (L2TP Access Concentrator),
|
||||
IP tunnel over UDP, such as VPN access
|
||||
|
||||
Supported auth protocols:
|
||||
* PAP, Password Authentication Protocol
|
||||
* CHAP, Challenge-Handshake Authentication Protocol, also known as CHAP-MD5
|
||||
* MSCHAPv1, Microsoft version of CHAP, version 1
|
||||
* MSCHAPv2, Microsoft version of CHAP, version 2
|
||||
* EAP, Extensible Authentication Protocol
|
||||
|
||||
Supported address protocols:
|
||||
* IPCP, IP Control Protocol, IPv4 addresses negotiation
|
||||
* IP6CP, IPv6 Control Protocol, IPv6 link-local addresses negotiation
|
||||
|
||||
Supported encryption protocols:
|
||||
* MPPE, Microsoft Point-to-Point Encryption
|
||||
|
||||
Supported compression or miscellaneous protocols, for serial links only:
|
||||
* PFC, Protocol Field Compression
|
||||
* ACFC, Address-and-Control-Field-Compression
|
||||
* ACCM, Asynchronous-Control-Character-Map
|
||||
* VJ, Van Jacobson TCP/IP Header Compression
|
||||
|
||||
|
||||
|
||||
2 Raw API PPP example for all protocols
|
||||
=======================================
|
||||
|
||||
As usual, raw API for lwIP means the lightweight API which *MUST* only be used
|
||||
for NO_SYS=1 systems or called inside lwIP core thread for NO_SYS=0 systems.
|
||||
|
||||
/*
|
||||
* Globals
|
||||
* =======
|
||||
*/
|
||||
|
||||
/* The PPP control block */
|
||||
ppp_pcb *ppp;
|
||||
|
||||
/* The PPP IP interface */
|
||||
struct netif ppp_netif;
|
||||
|
||||
|
||||
/*
|
||||
* PPP status callback
|
||||
* ===================
|
||||
*
|
||||
* PPP status callback is called on PPP status change (up, down, …) from lwIP
|
||||
* core thread
|
||||
*/
|
||||
|
||||
/* PPP status callback example */
|
||||
static void status_cb(ppp_pcb *pcb, int err_code, void *ctx) {
|
||||
struct netif *pppif = ppp_netif(pcb);
|
||||
LWIP_UNUSED_ARG(ctx);
|
||||
|
||||
switch(err_code) {
|
||||
case PPPERR_NONE: {
|
||||
#if LWIP_DNS
|
||||
const ip_addr_t *ns;
|
||||
#endif /* LWIP_DNS */
|
||||
printf("status_cb: Connected\n");
|
||||
#if PPP_IPV4_SUPPORT
|
||||
printf(" our_ipaddr = %s\n", ipaddr_ntoa(&pppif->ip_addr));
|
||||
printf(" his_ipaddr = %s\n", ipaddr_ntoa(&pppif->gw));
|
||||
printf(" netmask = %s\n", ipaddr_ntoa(&pppif->netmask));
|
||||
#if LWIP_DNS
|
||||
ns = dns_getserver(0);
|
||||
printf(" dns1 = %s\n", ipaddr_ntoa(ns));
|
||||
ns = dns_getserver(1);
|
||||
printf(" dns2 = %s\n", ipaddr_ntoa(ns));
|
||||
#endif /* LWIP_DNS */
|
||||
#endif /* PPP_IPV4_SUPPORT */
|
||||
#if PPP_IPV6_SUPPORT
|
||||
printf(" our6_ipaddr = %s\n", ip6addr_ntoa(netif_ip6_addr(pppif, 0)));
|
||||
#endif /* PPP_IPV6_SUPPORT */
|
||||
break;
|
||||
}
|
||||
case PPPERR_PARAM: {
|
||||
printf("status_cb: Invalid parameter\n");
|
||||
break;
|
||||
}
|
||||
case PPPERR_OPEN: {
|
||||
printf("status_cb: Unable to open PPP session\n");
|
||||
break;
|
||||
}
|
||||
case PPPERR_DEVICE: {
|
||||
printf("status_cb: Invalid I/O device for PPP\n");
|
||||
break;
|
||||
}
|
||||
case PPPERR_ALLOC: {
|
||||
printf("status_cb: Unable to allocate resources\n");
|
||||
break;
|
||||
}
|
||||
case PPPERR_USER: {
|
||||
printf("status_cb: User interrupt\n");
|
||||
break;
|
||||
}
|
||||
case PPPERR_CONNECT: {
|
||||
printf("status_cb: Connection lost\n");
|
||||
break;
|
||||
}
|
||||
case PPPERR_AUTHFAIL: {
|
||||
printf("status_cb: Failed authentication challenge\n");
|
||||
break;
|
||||
}
|
||||
case PPPERR_PROTOCOL: {
|
||||
printf("status_cb: Failed to meet protocol\n");
|
||||
break;
|
||||
}
|
||||
case PPPERR_PEERDEAD: {
|
||||
printf("status_cb: Connection timeout\n");
|
||||
break;
|
||||
}
|
||||
case PPPERR_IDLETIMEOUT: {
|
||||
printf("status_cb: Idle Timeout\n");
|
||||
break;
|
||||
}
|
||||
case PPPERR_CONNECTTIME: {
|
||||
printf("status_cb: Max connect time reached\n");
|
||||
break;
|
||||
}
|
||||
case PPPERR_LOOPBACK: {
|
||||
printf("status_cb: Loopback detected\n");
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
printf("status_cb: Unknown error code %d\n", err_code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This should be in the switch case, this is put outside of the switch
|
||||
* case for example readability.
|
||||
*/
|
||||
|
||||
if (err_code == PPPERR_NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* ppp_close() was previously called, don't reconnect */
|
||||
if (err_code == PPPERR_USER) {
|
||||
/* ppp_free(); -- can be called here */
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Try to reconnect in 30 seconds, if you need a modem chatscript you have
|
||||
* to do a much better signaling here ;-)
|
||||
*/
|
||||
ppp_connect(pcb, 30);
|
||||
/* OR ppp_listen(pcb); */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Creating a new PPPoS session
|
||||
* ============================
|
||||
*
|
||||
* In lwIP, PPPoS is not PPPoSONET, in lwIP PPPoS is PPPoSerial.
|
||||
*/
|
||||
|
||||
#include "netif/ppp/pppos.h"
|
||||
|
||||
/*
|
||||
* PPPoS serial output callback
|
||||
*
|
||||
* ppp_pcb, PPP control block
|
||||
* data, buffer to write to serial port
|
||||
* len, length of the data buffer
|
||||
* ctx, optional user-provided callback context pointer
|
||||
*
|
||||
* Return value: len if write succeed
|
||||
*/
|
||||
static u32_t output_cb(ppp_pcb *pcb, u8_t *data, u32_t len, void *ctx) {
|
||||
return uart_write(UART, data, len);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a new PPPoS interface
|
||||
*
|
||||
* ppp_netif, netif to use for this PPP link, i.e. PPP IP interface
|
||||
* output_cb, PPPoS serial output callback
|
||||
* status_cb, PPP status callback, called on PPP status change (up, down, …)
|
||||
* ctx_cb, optional user-provided callback context pointer
|
||||
*/
|
||||
ppp = pppos_create(&ppp_netif,
|
||||
output_cb, status_cb, ctx_cb);
|
||||
|
||||
|
||||
/*
|
||||
* Creating a new PPPoE session
|
||||
* ============================
|
||||
*/
|
||||
|
||||
#include "netif/ppp/pppoe.h"
|
||||
|
||||
/*
|
||||
* Create a new PPPoE interface
|
||||
*
|
||||
* ppp_netif, netif to use for this PPP link, i.e. PPP IP interface
|
||||
* ethif, already existing and setup Ethernet interface to use
|
||||
* service_name, PPPoE service name discriminator (not supported yet)
|
||||
* concentrator_name, PPPoE concentrator name discriminator (not supported yet)
|
||||
* status_cb, PPP status callback, called on PPP status change (up, down, …)
|
||||
* ctx_cb, optional user-provided callback context pointer
|
||||
*/
|
||||
ppp = pppoe_create(&ppp_netif,
|
||||
ðif,
|
||||
service_name, concentrator_name,
|
||||
status_cb, ctx_cb);
|
||||
|
||||
|
||||
/*
|
||||
* Creating a new PPPoL2TP session
|
||||
* ===============================
|
||||
*/
|
||||
|
||||
#include "netif/ppp/pppol2tp.h"
|
||||
|
||||
/*
|
||||
* Create a new PPPoL2TP interface
|
||||
*
|
||||
* ppp_netif, netif to use for this PPP link, i.e. PPP IP interface
|
||||
* netif, optional already existing and setup output netif, necessary if you
|
||||
* want to set this interface as default route to settle the chicken
|
||||
* and egg problem with VPN links
|
||||
* ipaddr, IP to connect to
|
||||
* port, UDP port to connect to (usually 1701)
|
||||
* secret, L2TP secret to use
|
||||
* secret_len, size in bytes of the L2TP secret
|
||||
* status_cb, PPP status callback, called on PPP status change (up, down, …)
|
||||
* ctx_cb, optional user-provided callback context pointer
|
||||
*/
|
||||
ppp = pppol2tp_create(&ppp_netif,
|
||||
struct netif *netif, ip_addr_t *ipaddr, u16_t port,
|
||||
u8_t *secret, u8_t secret_len,
|
||||
ppp_link_status_cb_fn link_status_cb, void *ctx_cb);
|
||||
|
||||
|
||||
/*
|
||||
* Initiate PPP client connection
|
||||
* ==============================
|
||||
*/
|
||||
|
||||
/* Set this interface as default route */
|
||||
ppp_set_default(ppp);
|
||||
|
||||
/*
|
||||
* Basic PPP client configuration. Can only be set if PPP session is in the
|
||||
* dead state (i.e. disconnected). We don't need to provide thread-safe
|
||||
* equivalents through PPPAPI because those helpers are only changing
|
||||
* structure members while session is inactive for lwIP core. Configuration
|
||||
* only need to be done once.
|
||||
*/
|
||||
|
||||
/* Ask the peer for up to 2 DNS server addresses. */
|
||||
ppp_set_usepeerdns(ppp, 1);
|
||||
|
||||
/* Auth configuration, this is pretty self-explanatory */
|
||||
ppp_set_auth(ppp, PPPAUTHTYPE_ANY, "login", "password");
|
||||
|
||||
/*
|
||||
* Initiate PPP negotiation, without waiting (holdoff=0), can only be called
|
||||
* if PPP session is in the dead state (i.e. disconnected).
|
||||
*/
|
||||
u16_t holdoff = 0;
|
||||
ppp_connect(ppp, holdoff);
|
||||
|
||||
|
||||
/*
|
||||
* Initiate PPP server listener
|
||||
* ============================
|
||||
*/
|
||||
|
||||
/*
|
||||
* Basic PPP server configuration. Can only be set if PPP session is in the
|
||||
* dead state (i.e. disconnected). We don't need to provide thread-safe
|
||||
* equivalents through PPPAPI because those helpers are only changing
|
||||
* structure members while session is inactive for lwIP core. Configuration
|
||||
* only need to be done once.
|
||||
*/
|
||||
ip4_addr_t addr;
|
||||
|
||||
/* Set our address */
|
||||
IP4_ADDR(&addr, 192,168,0,1);
|
||||
ppp_set_ipcp_ouraddr(ppp, &addr);
|
||||
|
||||
/* Set peer(his) address */
|
||||
IP4_ADDR(&addr, 192,168,0,2);
|
||||
ppp_set_ipcp_hisaddr(ppp, &addr);
|
||||
|
||||
/* Set primary DNS server */
|
||||
IP4_ADDR(&addr, 192,168,10,20);
|
||||
ppp_set_ipcp_dnsaddr(ppp, 0, &addr);
|
||||
|
||||
/* Set secondary DNS server */
|
||||
IP4_ADDR(&addr, 192,168,10,21);
|
||||
ppp_set_ipcp_dnsaddr(ppp, 1, &addr);
|
||||
|
||||
/* Auth configuration, this is pretty self-explanatory */
|
||||
ppp_set_auth(ppp, PPPAUTHTYPE_ANY, "login", "password");
|
||||
|
||||
/* Require peer to authenticate */
|
||||
ppp_set_auth_required(ppp, 1);
|
||||
|
||||
/*
|
||||
* Only for PPPoS, the PPP session should be up and waiting for input.
|
||||
*
|
||||
* Note: for PPPoS, ppp_connect() and ppp_listen() are actually the same thing.
|
||||
* The listen call is meant for future support of PPPoE and PPPoL2TP server
|
||||
* mode, where we will need to negotiate the incoming PPPoE session or L2TP
|
||||
* session before initiating PPP itself. We need this call because there is
|
||||
* two passive modes for PPPoS, ppp_set_passive and ppp_set_silent.
|
||||
*/
|
||||
ppp_set_silent(pppos, 1);
|
||||
|
||||
/*
|
||||
* Initiate PPP listener (i.e. wait for an incoming connection), can only
|
||||
* be called if PPP session is in the dead state (i.e. disconnected).
|
||||
*/
|
||||
ppp_listen(ppp);
|
||||
|
||||
|
||||
/*
|
||||
* Closing PPP connection
|
||||
* ======================
|
||||
*/
|
||||
|
||||
/*
|
||||
* Initiate the end of the PPP session, without carrier lost signal
|
||||
* (nocarrier=0), meaning a clean shutdown of PPP protocols.
|
||||
* You can call this function at anytime.
|
||||
*/
|
||||
u8_t nocarrier = 0;
|
||||
ppp_close(ppp, nocarrier);
|
||||
/*
|
||||
* Then you must wait your status_cb() to be called, it may takes from a few
|
||||
* seconds to several tens of seconds depending on the current PPP state.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Freeing a PPP connection
|
||||
* ========================
|
||||
*/
|
||||
|
||||
/*
|
||||
* Free the PPP control block, can only be called if PPP session is in the
|
||||
* dead state (i.e. disconnected). You need to call ppp_close() before.
|
||||
*/
|
||||
ppp_free(ppp);
|
||||
|
||||
|
||||
|
||||
3 PPPoS input path (raw API, IRQ safe API, TCPIP API)
|
||||
=====================================================
|
||||
|
||||
Received data on serial port should be sent to lwIP using the pppos_input()
|
||||
function or the pppos_input_tcpip() function.
|
||||
|
||||
If NO_SYS is 1 and if PPP_INPROC_IRQ_SAFE is 0 (the default), pppos_input()
|
||||
is not IRQ safe and then *MUST* only be called inside your main loop.
|
||||
|
||||
Whatever the NO_SYS value, if PPP_INPROC_IRQ_SAFE is 1, pppos_input() is IRQ
|
||||
safe and can be safely called from an interrupt context, using that is going
|
||||
to reduce your need of buffer if pppos_input() is called byte after byte in
|
||||
your rx serial interrupt.
|
||||
|
||||
if NO_SYS is 0, the thread safe way outside an interrupt context is to use
|
||||
the pppos_input_tcpip() function to pass input data to the lwIP core thread
|
||||
using the TCPIP API. This is thread safe in all cases but you should avoid
|
||||
passing data byte after byte because it uses heavy locking (mailbox) and it
|
||||
allocates pbuf, better fill them !
|
||||
|
||||
if NO_SYS is 0 and if PPP_INPROC_IRQ_SAFE is 1, you may also use pppos_input()
|
||||
from an RX thread, however pppos_input() is not thread safe by itself. You can
|
||||
do that *BUT* you should NEVER call pppos_connect(), pppos_listen() and
|
||||
ppp_free() if pppos_input() can still be running, doing this is NOT thread safe
|
||||
at all. Using PPP_INPROC_IRQ_SAFE from an RX thread is discouraged unless you
|
||||
really know what you are doing, your move ;-)
|
||||
|
||||
|
||||
/*
|
||||
* Fonction to call for received data
|
||||
*
|
||||
* ppp, PPP control block
|
||||
* buffer, input buffer
|
||||
* buffer_len, buffer length in bytes
|
||||
*/
|
||||
void pppos_input(ppp, buffer, buffer_len);
|
||||
|
||||
or
|
||||
|
||||
void pppos_input_tcpip(ppp, buffer, buffer_len);
|
||||
|
||||
|
||||
|
||||
4 Thread safe PPP API (PPPAPI)
|
||||
==============================
|
||||
|
||||
There is a thread safe API for all corresponding ppp_* functions, you have to
|
||||
enable LWIP_PPP_API in your lwipopts.h file, then see
|
||||
include/netif/ppp/pppapi.h, this is actually pretty obvious.
|
||||
|
||||
|
||||
|
||||
5 Notify phase callback (PPP_NOTIFY_PHASE)
|
||||
==========================================
|
||||
|
||||
Notify phase callback, enabled using the PPP_NOTIFY_PHASE config option, let
|
||||
you configure a callback that is called on each PPP internal state change.
|
||||
This is different from the status callback which only warns you about
|
||||
up(running) and down(dead) events.
|
||||
|
||||
Notify phase callback can be used, for example, to set a LED pattern depending
|
||||
on the current phase of the PPP session. Here is a callback example which
|
||||
tries to mimic what we usually see on xDSL modems while they are negotiating
|
||||
the link, which should be self-explanatory:
|
||||
|
||||
static void ppp_notify_phase_cb(ppp_pcb *pcb, u8_t phase, void *ctx) {
|
||||
switch (phase) {
|
||||
|
||||
/* Session is down (either permanently or briefly) */
|
||||
case PPP_PHASE_DEAD:
|
||||
led_set(PPP_LED, LED_OFF);
|
||||
break;
|
||||
|
||||
/* We are between two sessions */
|
||||
case PPP_PHASE_HOLDOFF:
|
||||
led_set(PPP_LED, LED_SLOW_BLINK);
|
||||
break;
|
||||
|
||||
/* Session just started */
|
||||
case PPP_PHASE_INITIALIZE:
|
||||
led_set(PPP_LED, LED_FAST_BLINK);
|
||||
break;
|
||||
|
||||
/* Session is running */
|
||||
case PPP_PHASE_RUNNING:
|
||||
led_set(PPP_LED, LED_ON);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
6 Upgrading from lwIP <= 1.4.x to lwIP >= 2.0.x
|
||||
===============================================
|
||||
|
||||
PPP API was fully reworked between 1.4.x and 2.0.x releases. However porting
|
||||
from previous lwIP version is pretty easy:
|
||||
|
||||
* Previous PPP API used an integer to identify PPP sessions, we are now
|
||||
using ppp_pcb* control block, therefore all functions changed from "int ppp"
|
||||
to "ppp_pcb *ppp"
|
||||
|
||||
* struct netif was moved outside the PPP structure, you have to provide a netif
|
||||
for PPP interface in pppoX_create() functions
|
||||
|
||||
* PPP session are not started automatically after you created them anymore,
|
||||
you have to call ppp_connect(), this way you can configure the session before
|
||||
starting it.
|
||||
|
||||
* Previous PPP API used CamelCase, we are now using snake_case.
|
||||
|
||||
* Previous PPP API mixed PPPoS and PPPoE calls, this isn't the case anymore,
|
||||
PPPoS functions are now prefixed pppos_ and PPPoE functions are now prefixed
|
||||
pppoe_, common functions are now prefixed ppp_.
|
||||
|
||||
* New PPPERR_ error codes added, check you have all of them in your status
|
||||
callback function
|
||||
|
||||
* Only the following include files should now be used in user application:
|
||||
#include "netif/ppp/pppapi.h"
|
||||
#include "netif/ppp/pppos.h"
|
||||
#include "netif/ppp/pppoe.h"
|
||||
#include "netif/ppp/pppol2tp.h"
|
||||
|
||||
Functions from ppp.h can be used, but you don't need to include this header
|
||||
file as it is already included by above header files.
|
||||
|
||||
* PPP_INPROC_OWNTHREAD was broken by design and was removed, you have to create
|
||||
your own serial rx thread
|
||||
|
||||
* PPP_INPROC_MULTITHREADED option was misnamed and confusing and was renamed
|
||||
PPP_INPROC_IRQ_SAFE, please read the "PPPoS input path" documentation above
|
||||
because you might have been fooled by that
|
||||
|
||||
* If you used tcpip_callback_with_block() on ppp_ functions you may wish to use
|
||||
the PPPAPI API instead.
|
||||
|
||||
* ppp_sighup and ppp_close functions were merged using an optional argument
|
||||
"nocarrier" on ppp_close.
|
||||
|
||||
* DNS servers are now only remotely asked if LWIP_DNS is set and if
|
||||
ppp_set_usepeerdns() is set to true, they are now automatically registered
|
||||
using the dns_setserver() function so you don't need to do that in the PPP
|
||||
callback anymore.
|
||||
|
||||
* PPPoS does not use the SIO API anymore, as such it now requires a serial
|
||||
output callback in place of sio_write
|
||||
|
||||
* PPP_MAXIDLEFLAG is now in ms instead of jiffies
|
120
components/net/lwip/lwip/doc/savannah.txt
Normal file
120
components/net/lwip/lwip/doc/savannah.txt
Normal file
@ -0,0 +1,120 @@
|
||||
Daily Use Guide for using Savannah for lwIP
|
||||
|
||||
Table of Contents:
|
||||
|
||||
1 - Obtaining lwIP from the Git repository
|
||||
2 - Committers/developers Git access using SSH
|
||||
3 - Merging a development branch to master branch
|
||||
4 - How to release lwIP
|
||||
|
||||
|
||||
|
||||
1 Obtaining lwIP from the Git repository
|
||||
----------------------------------------
|
||||
|
||||
To perform an anonymous Git clone of the master branch (this is where
|
||||
bug fixes and incremental enhancements occur), do this:
|
||||
git clone git://git.savannah.nongnu.org/lwip.git
|
||||
|
||||
Or, obtain a stable branch (updated with bug fixes only) as follows:
|
||||
git clone --branch DEVEL-1_4_1 git://git.savannah.nongnu.org/lwip.git
|
||||
|
||||
Or, obtain a specific (fixed) release as follows:
|
||||
git clone --branch STABLE-1_4_1 git://git.savannah.nongnu.org/lwip.git
|
||||
|
||||
|
||||
2 Committers/developers Git access using SSH
|
||||
--------------------------------------------
|
||||
|
||||
The Savannah server uses SSH (Secure Shell) protocol 2 authentication and encryption.
|
||||
As such, Git commits to the server occur through a SSH tunnel for project members.
|
||||
To create a SSH2 key pair in UNIX-like environments, do this:
|
||||
ssh-keygen
|
||||
|
||||
Under Windows, a recommended SSH client is "PuTTY", freely available with good
|
||||
documentation and a graphic user interface. Use its key generator.
|
||||
|
||||
Now paste the id_rsa.pub contents into your Savannah account public key list. Wait
|
||||
a while so that Savannah can update its configuration (This can take minutes).
|
||||
|
||||
Try to login using SSH:
|
||||
ssh -v your_login@git.sv.gnu.org
|
||||
|
||||
If it tells you:
|
||||
Linux vcs.savannah.gnu.org 2.6.32-5-xen-686 #1 SMP Wed Jun 17 17:10:03 UTC 2015 i686
|
||||
|
||||
Interactive shell login is not possible for security reasons.
|
||||
VCS commands are allowed.
|
||||
Last login: Tue May 15 23:10:12 2012 from 82.245.102.129
|
||||
You tried to execute:
|
||||
Sorry, you are not allowed to execute that command.
|
||||
Shared connection to git.sv.gnu.org closed.
|
||||
|
||||
then you could login; Savannah refuses to give you a shell - which is OK, as we
|
||||
are allowed to use SSH for Git only. Now, you should be able to do this:
|
||||
git clone your_login@git.sv.gnu.org:/srv/git/lwip.git
|
||||
|
||||
After which you can edit your local files with bug fixes or new features and
|
||||
commit them. Make sure you know what you are doing when using Git to make
|
||||
changes on the repository. If in doubt, ask on the lwip-members mailing list.
|
||||
|
||||
(If SSH asks about authenticity of the host, you can check the key
|
||||
fingerprint against https://savannah.nongnu.org/git/?group=lwip
|
||||
|
||||
|
||||
3 - Merging a development branch to master branch
|
||||
-------------------------------------------------
|
||||
|
||||
Merging is a straightforward process in Git. How to merge all changes in a
|
||||
development branch since our last merge from main:
|
||||
|
||||
Checkout the master branch:
|
||||
git checkout master
|
||||
|
||||
Merge the development branch to master:
|
||||
git merge your-development-branch
|
||||
|
||||
Resolve any conflict.
|
||||
|
||||
Commit the merge result.
|
||||
git commit -a
|
||||
|
||||
Push your commits:
|
||||
git push
|
||||
|
||||
|
||||
4 How to release lwIP
|
||||
---------------------
|
||||
|
||||
First, tag the release using Git: (I use release number 1.4.1 throughout
|
||||
this example).
|
||||
git tag -a STABLE-1_4_1
|
||||
|
||||
Share the tag reference by pushing it to remote:
|
||||
git push origin STABLE-1_4_1
|
||||
|
||||
Prepare the release:
|
||||
cp -r lwip lwip-1.4.1
|
||||
rm -rf lwip-1.4.1/.git lwip-1.4.1/.gitattributes
|
||||
|
||||
Archive the current directory using tar, gzip'd, bzip2'd and zip'd.
|
||||
tar czvf lwip-1.4.1.tar.gz lwip-1.4.1
|
||||
tar cjvf lwip-1.4.1.tar.bz2 lwip-1.4.1
|
||||
zip -r lwip-1.4.1.zip lwip-1.4.1
|
||||
|
||||
Now, sign the archives with a detached GPG binary signature as follows:
|
||||
gpg -b lwip-1.4.1.tar.gz
|
||||
gpg -b lwip-1.4.1.tar.bz2
|
||||
gpg -b lwip-1.4.1.zip
|
||||
|
||||
Upload these files using anonymous FTP:
|
||||
ncftp ftp://savannah.gnu.org/incoming/savannah/lwip
|
||||
ncftp> mput *1.4.1.*
|
||||
|
||||
Additionally, you may post a news item on Savannah, like this:
|
||||
|
||||
A new 1.4.1 release is now available here:
|
||||
http://savannah.nongnu.org/files/?group=lwip&highlight=1.4.1
|
||||
|
||||
You will have to submit this via the user News interface, then approve
|
||||
this via the Administrator News interface.
|
197
components/net/lwip/lwip/lwip-port/FreeRTOS/ethernetif.c
Normal file
197
components/net/lwip/lwip/lwip-port/FreeRTOS/ethernetif.c
Normal file
@ -0,0 +1,197 @@
|
||||
/**
|
||||
* @file
|
||||
* Ethernet Interface Skeleton
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
||||
* 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.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is a skeleton for developing Ethernet network interface
|
||||
* drivers for lwIP. Add code to the low_level functions and do a
|
||||
* search-and-replace for the word "ethernetif" to replace it with
|
||||
* something that better describes your network interface.
|
||||
*/
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "timers.h"
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/def.h"
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/pbuf.h"
|
||||
#include "netif/etharp.h"
|
||||
#include "ethernetif.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#define netifMTU (1500)
|
||||
#define netifINTERFACE_TASK_STACK_SIZE ( 350 )
|
||||
#define netifINTERFACE_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
|
||||
#define netifGUARD_BLOCK_TIME ( 250 )
|
||||
/* The time to block waiting for input. */
|
||||
#define emacBLOCK_TIME_WAITING_FOR_INPUT ( ( portTickType ) 100 )
|
||||
|
||||
/* Define those to better describe your network interface. */
|
||||
#define IFNAME0 's'
|
||||
#define IFNAME1 't'
|
||||
|
||||
/**
|
||||
* In this function, the hardware should be initialized.
|
||||
* Called from ethernetif_init().
|
||||
*
|
||||
* @param netif the already initialized lwip network interface structure
|
||||
* for this ethernetif
|
||||
*/
|
||||
static void low_level_init(struct netif *netif)
|
||||
{
|
||||
/* set netif MAC hardware address length */
|
||||
netif->hwaddr_len = ETHARP_HWADDR_LEN;
|
||||
|
||||
/* set netif MAC hardware address */
|
||||
netif->hwaddr[0] = 0x00;
|
||||
netif->hwaddr[1] = 0x50;
|
||||
netif->hwaddr[2] = 0x43;
|
||||
netif->hwaddr[3] = 0xC9;
|
||||
netif->hwaddr[4] = 0x00;
|
||||
netif->hwaddr[5] = 0x01;
|
||||
|
||||
/* set netif maximum transfer unit */
|
||||
netif->mtu = 1500;
|
||||
|
||||
/* Accept broadcast address and ARP traffic */
|
||||
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP;
|
||||
#if 0
|
||||
|
||||
s_pxNetIf =netif;
|
||||
|
||||
/* create binary semaphore used for informing ethernetif of frame reception */
|
||||
if (s_xSemaphore == NULL)
|
||||
{
|
||||
vSemaphoreCreateBinary(s_xSemaphore);
|
||||
xSemaphoreTake( s_xSemaphore, 0);
|
||||
}
|
||||
|
||||
/* initialize MAC address in ethernet MAC */
|
||||
ETH_MACAddressConfig(ETH_MAC_Address0, netif->hwaddr);
|
||||
|
||||
/* Initialize Tx Descriptors list: Chain Mode */
|
||||
ETH_DMATxDescChainInit(DMATxDscrTab, &Tx_Buff[0][0], ETH_TXBUFNB);
|
||||
/* Initialize Rx Descriptors list: Chain Mode */
|
||||
ETH_DMARxDescChainInit(DMARxDscrTab, &Rx_Buff[0][0], ETH_RXBUFNB);
|
||||
|
||||
/* Enable Ethernet Rx interrrupt */
|
||||
{
|
||||
for(i=0; i<ETH_RXBUFNB; i++)
|
||||
{
|
||||
ETH_DMARxDescReceiveITConfig(&DMARxDscrTab[i], ENABLE);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CHECKSUM_BY_HARDWARE
|
||||
/* Enable the checksum insertion for the Tx frames */
|
||||
{
|
||||
for(i=0; i<ETH_TXBUFNB; i++)
|
||||
{
|
||||
ETH_DMATxDescChecksumInsertionConfig(&DMATxDscrTab[i], ETH_DMATxDesc_ChecksumTCPUDPICMPFull);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* create the task that handles the ETH_MAC */
|
||||
xTaskCreate(ethernetif_input, (signed char*) "Eth_if", netifINTERFACE_TASK_STACK_SIZE, NULL,
|
||||
netifINTERFACE_TASK_PRIORITY,NULL);
|
||||
|
||||
/* Enable MAC and DMA transmission and reception */
|
||||
ETH_Start();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This function should do the actual transmission of the packet. The packet is
|
||||
* contained in the pbuf that is passed to the function. This pbuf
|
||||
* might be chained.
|
||||
*
|
||||
* @param netif the lwip network interface structure for this ethernetif
|
||||
* @param p the MAC packet to send (e.g. IP packet including MAC addresses and type)
|
||||
* @return ERR_OK if the packet could be sent
|
||||
* an err_t value if the packet couldn't be sent
|
||||
*
|
||||
* @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to
|
||||
* strange results. You might consider waiting for space in the DMA queue
|
||||
* to become availale since the stack doesn't retry to send a packet
|
||||
* dropped because of memory failure (except for the TCP timers).
|
||||
*/
|
||||
|
||||
static err_t low_level_output(struct netif *netif, struct pbuf *p)
|
||||
{
|
||||
static int count;
|
||||
|
||||
printf("---------------Sending packet(%d)\r\n", count++);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should be called at the beginning of the program to set up the
|
||||
* network interface. It calls the function low_level_init() to do the
|
||||
* actual setup of the hardware.
|
||||
*
|
||||
* This function should be passed as a parameter to netif_add().
|
||||
*
|
||||
* @param netif the lwip network interface structure for this ethernetif
|
||||
* @return ERR_OK if the loopif is initialized
|
||||
* ERR_MEM if private data couldn't be allocated
|
||||
* any other err_t on error
|
||||
*/
|
||||
err_t ethernetif_init(struct netif *netif)
|
||||
{
|
||||
LWIP_ASSERT("netif != NULL", (netif != NULL));
|
||||
|
||||
#if LWIP_NETIF_HOSTNAME
|
||||
/* Initialize interface hostname */
|
||||
netif->hostname = "lwip";
|
||||
#endif /* LWIP_NETIF_HOSTNAME */
|
||||
|
||||
netif->name[0] = IFNAME0;
|
||||
netif->name[1] = IFNAME1;
|
||||
|
||||
netif->output = etharp_output;
|
||||
netif->linkoutput = low_level_output;
|
||||
|
||||
/* initialize the hardware */
|
||||
low_level_init(netif);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
12
components/net/lwip/lwip/lwip-port/FreeRTOS/ethernetif.h
Normal file
12
components/net/lwip/lwip/lwip-port/FreeRTOS/ethernetif.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef __ETHERNETIF_H__
|
||||
#define __ETHERNETIF_H__
|
||||
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/netif.h"
|
||||
|
||||
err_t ethernetif_init(struct netif *netif);
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -36,40 +36,33 @@
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/stats.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
#if !NO_SYS
|
||||
|
||||
#if defined(LWIP_PROVIDE_ERRNO)
|
||||
int errno;
|
||||
#endif
|
||||
xTaskHandle xTaskGetCurrentTaskHandle( void ) PRIVILEGED_FUNCTION;
|
||||
|
||||
/* This is the number of threads that can be started with sys_thread_new() */
|
||||
#define SYS_THREAD_MAX 6
|
||||
|
||||
static u16_t s_nextthread = 0;
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
// Creates an empty mailbox.
|
||||
err_t sys_mbox_new(sys_mbox_t *mbox, int size)
|
||||
{
|
||||
(void)size;
|
||||
|
||||
*mbox = xQueueCreate(TCPIP_MBOX_SIZE, sizeof(void *));
|
||||
*mbox = xQueueCreate( size, sizeof( void * ) );
|
||||
|
||||
#if SYS_STATS
|
||||
++lwip_stats.sys.mbox.used;
|
||||
|
||||
if (lwip_stats.sys.mbox.max < lwip_stats.sys.mbox.used) {
|
||||
lwip_stats.sys.mbox.max = lwip_stats.sys.mbox.used;
|
||||
}
|
||||
|
||||
++lwip_stats.sys.mbox.used;
|
||||
if (lwip_stats.sys.mbox.max < lwip_stats.sys.mbox.used) {
|
||||
lwip_stats.sys.mbox.max = lwip_stats.sys.mbox.used;
|
||||
}
|
||||
#endif /* SYS_STATS */
|
||||
if (*mbox == NULL)
|
||||
return ERR_MEM;
|
||||
|
||||
if (*mbox == NULL) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
@ -80,19 +73,21 @@ err_t sys_mbox_new(sys_mbox_t *mbox, int size)
|
||||
*/
|
||||
void sys_mbox_free(sys_mbox_t *mbox)
|
||||
{
|
||||
if (uxQueueMessagesWaiting(*mbox)) {
|
||||
/* Line for breakpoint. Should never break here! */
|
||||
portNOP();
|
||||
if( uxQueueMessagesWaiting( *mbox ) )
|
||||
{
|
||||
/* Line for breakpoint. Should never break here! */
|
||||
portNOP();
|
||||
#if SYS_STATS
|
||||
lwip_stats.sys.mbox.err++;
|
||||
lwip_stats.sys.mbox.err++;
|
||||
#endif /* SYS_STATS */
|
||||
// TODO notify the user of failure.
|
||||
}
|
||||
|
||||
vQueueDelete(*mbox);
|
||||
// TODO notify the user of failure.
|
||||
}
|
||||
|
||||
vQueueDelete( *mbox );
|
||||
|
||||
#if SYS_STATS
|
||||
--lwip_stats.sys.mbox.used;
|
||||
--lwip_stats.sys.mbox.used;
|
||||
#endif /* SYS_STATS */
|
||||
}
|
||||
|
||||
@ -100,34 +95,31 @@ void sys_mbox_free(sys_mbox_t *mbox)
|
||||
// Posts the "msg" to the mailbox.
|
||||
void sys_mbox_post(sys_mbox_t *mbox, void *data)
|
||||
{
|
||||
while (xQueueSendToBack(*mbox, &data, portMAX_DELAY) != pdTRUE) {
|
||||
};
|
||||
while ( xQueueSendToBack(*mbox, &data, portMAX_DELAY ) != pdTRUE ){}
|
||||
}
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
// Try to post the "msg" to the mailbox.
|
||||
err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg)
|
||||
{
|
||||
err_t result;
|
||||
err_t result;
|
||||
|
||||
if ( xQueueSend( *mbox, &msg, 0 ) == pdPASS )
|
||||
{
|
||||
result = ERR_OK;
|
||||
}
|
||||
else {
|
||||
// could not post, queue must be full
|
||||
result = ERR_MEM;
|
||||
|
||||
if (xQueueSend(*mbox, &msg, 0) == pdPASS) {
|
||||
result = ERR_OK;
|
||||
} else {
|
||||
// could not post, queue must be full
|
||||
result = ERR_MEM;
|
||||
#if SYS_STATS
|
||||
lwip_stats.sys.mbox.err++;
|
||||
lwip_stats.sys.mbox.err++;
|
||||
#endif /* SYS_STATS */
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
// Try to post the "msg" to the mailbox.
|
||||
err_t sys_mbox_trypost_fromisr_unused(sys_mbox_t *mbox, void *msg)
|
||||
{
|
||||
return sys_mbox_trypost(mbox, msg);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
@ -148,34 +140,40 @@ err_t sys_mbox_trypost_fromisr_unused(sys_mbox_t *mbox, void *msg)
|
||||
*/
|
||||
u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout)
|
||||
{
|
||||
void *dummyptr;
|
||||
portTickType StartTime, EndTime, Elapsed;
|
||||
void *dummyptr;
|
||||
portTickType StartTime, EndTime, Elapsed;
|
||||
|
||||
StartTime = xTaskGetTickCount();
|
||||
StartTime = xTaskGetTickCount();
|
||||
|
||||
if (msg == NULL) {
|
||||
msg = &dummyptr;
|
||||
}
|
||||
if ( msg == NULL )
|
||||
{
|
||||
msg = &dummyptr;
|
||||
}
|
||||
|
||||
if (timeout != 0) {
|
||||
if (pdTRUE == xQueueReceive(*mbox, &(*msg), timeout / portTICK_RATE_MS)) {
|
||||
EndTime = xTaskGetTickCount();
|
||||
Elapsed = (EndTime - StartTime) * portTICK_RATE_MS;
|
||||
return (Elapsed);
|
||||
} else {
|
||||
// timed out blocking for message
|
||||
*msg = NULL;
|
||||
return SYS_ARCH_TIMEOUT;
|
||||
}
|
||||
} else {
|
||||
// block forever for a message.
|
||||
while (pdTRUE != xQueueReceive(*mbox, &(*msg), portMAX_DELAY)) {
|
||||
} // time is arbitrary
|
||||
if ( timeout != 0 )
|
||||
{
|
||||
if ( pdTRUE == xQueueReceive( *mbox, &(*msg), timeout / portTICK_RATE_MS ) )
|
||||
{
|
||||
EndTime = xTaskGetTickCount();
|
||||
Elapsed = (EndTime - StartTime) * portTICK_RATE_MS;
|
||||
|
||||
EndTime = xTaskGetTickCount();
|
||||
Elapsed = (EndTime - StartTime) * portTICK_RATE_MS;
|
||||
return (Elapsed); // return time blocked TODO test
|
||||
}
|
||||
return ( Elapsed );
|
||||
}
|
||||
else // timed out blocking for message
|
||||
{
|
||||
*msg = NULL;
|
||||
|
||||
return SYS_ARCH_TIMEOUT;
|
||||
}
|
||||
}
|
||||
else // block forever for a message.
|
||||
{
|
||||
while( pdTRUE != xQueueReceive( *mbox, &(*msg), portMAX_DELAY ) ){} // time is arbitrary
|
||||
EndTime = xTaskGetTickCount();
|
||||
Elapsed = (EndTime - StartTime) * portTICK_RATE_MS;
|
||||
|
||||
return ( Elapsed ); // return time blocked TODO test
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
@ -185,31 +183,34 @@ u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout)
|
||||
*/
|
||||
u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg)
|
||||
{
|
||||
void *dummyptr;
|
||||
void *dummyptr;
|
||||
|
||||
if (msg == NULL) {
|
||||
msg = &dummyptr;
|
||||
}
|
||||
if ( msg == NULL )
|
||||
{
|
||||
msg = &dummyptr;
|
||||
}
|
||||
|
||||
if (pdTRUE == xQueueReceive(*mbox, &(*msg), 0)) {
|
||||
return ERR_OK;
|
||||
} else {
|
||||
return SYS_MBOX_EMPTY;
|
||||
}
|
||||
if ( pdTRUE == xQueueReceive( *mbox, &(*msg), 0 ) )
|
||||
{
|
||||
return ERR_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SYS_MBOX_EMPTY;
|
||||
}
|
||||
}
|
||||
/*----------------------------------------------------------------------------------*/
|
||||
int sys_mbox_valid(sys_mbox_t *mbox)
|
||||
{
|
||||
if (*mbox == SYS_MBOX_NULL) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
if (*mbox == SYS_MBOX_NULL)
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void sys_mbox_set_invalid(sys_mbox_t *mbox)
|
||||
{
|
||||
*mbox = SYS_MBOX_NULL;
|
||||
*mbox = SYS_MBOX_NULL;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
@ -217,29 +218,28 @@ void sys_mbox_set_invalid(sys_mbox_t *mbox)
|
||||
// the initial state of the semaphore.
|
||||
err_t sys_sem_new(sys_sem_t *sem, u8_t count)
|
||||
{
|
||||
vSemaphoreCreateBinary(*sem);
|
||||
|
||||
if (*sem == NULL) {
|
||||
vSemaphoreCreateBinary(*sem );
|
||||
if(*sem == NULL)
|
||||
{
|
||||
#if SYS_STATS
|
||||
++lwip_stats.sys.sem.err;
|
||||
++lwip_stats.sys.sem.err;
|
||||
#endif /* SYS_STATS */
|
||||
return ERR_MEM;
|
||||
}
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
if (count == 0) // Means it can't be taken
|
||||
{
|
||||
xSemaphoreTake(*sem, 1);
|
||||
}
|
||||
if(count == 0) // Means it can't be taken
|
||||
{
|
||||
xSemaphoreTake(*sem,1);
|
||||
}
|
||||
|
||||
#if SYS_STATS
|
||||
++lwip_stats.sys.sem.used;
|
||||
|
||||
if (lwip_stats.sys.sem.max < lwip_stats.sys.sem.used) {
|
||||
lwip_stats.sys.sem.max = lwip_stats.sys.sem.used;
|
||||
}
|
||||
|
||||
++lwip_stats.sys.sem.used;
|
||||
if (lwip_stats.sys.sem.max < lwip_stats.sys.sem.used) {
|
||||
lwip_stats.sys.sem.max = lwip_stats.sys.sem.used;
|
||||
}
|
||||
#endif /* SYS_STATS */
|
||||
return ERR_OK;
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
@ -260,34 +260,40 @@ err_t sys_sem_new(sys_sem_t *sem, u8_t count)
|
||||
*/
|
||||
u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout)
|
||||
{
|
||||
portTickType StartTime, EndTime, Elapsed;
|
||||
portTickType StartTime, EndTime, Elapsed;
|
||||
|
||||
StartTime = xTaskGetTickCount();
|
||||
StartTime = xTaskGetTickCount();
|
||||
|
||||
if (timeout != 0) {
|
||||
if (xSemaphoreTake(*sem, timeout / portTICK_RATE_MS) == pdTRUE) {
|
||||
EndTime = xTaskGetTickCount();
|
||||
Elapsed = (EndTime - StartTime) * portTICK_RATE_MS;
|
||||
return (Elapsed); // return time blocked TODO test
|
||||
} else {
|
||||
return SYS_ARCH_TIMEOUT;
|
||||
}
|
||||
} else {
|
||||
// must block without a timeout
|
||||
while (xSemaphoreTake(*sem, portMAX_DELAY) != pdTRUE) {
|
||||
}
|
||||
if( timeout != 0)
|
||||
{
|
||||
if( xSemaphoreTake( *sem, timeout / portTICK_RATE_MS ) == pdTRUE )
|
||||
{
|
||||
EndTime = xTaskGetTickCount();
|
||||
Elapsed = (EndTime - StartTime) * portTICK_RATE_MS;
|
||||
|
||||
EndTime = xTaskGetTickCount();
|
||||
Elapsed = (EndTime - StartTime) * portTICK_RATE_MS;
|
||||
return (Elapsed); // return time blocked
|
||||
}
|
||||
return (Elapsed); // return time blocked TODO test
|
||||
}
|
||||
else
|
||||
{
|
||||
return SYS_ARCH_TIMEOUT;
|
||||
}
|
||||
}
|
||||
else // must block without a timeout
|
||||
{
|
||||
while( xSemaphoreTake(*sem, portMAX_DELAY) != pdTRUE){}
|
||||
EndTime = xTaskGetTickCount();
|
||||
Elapsed = (EndTime - StartTime) * portTICK_RATE_MS;
|
||||
|
||||
return ( Elapsed ); // return time blocked
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
// Signals a semaphore
|
||||
void sys_sem_signal(sys_sem_t *sem)
|
||||
{
|
||||
xSemaphoreGive(*sem);
|
||||
xSemaphoreGive(*sem);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
@ -295,85 +301,94 @@ void sys_sem_signal(sys_sem_t *sem)
|
||||
void sys_sem_free(sys_sem_t *sem)
|
||||
{
|
||||
#if SYS_STATS
|
||||
--lwip_stats.sys.sem.used;
|
||||
--lwip_stats.sys.sem.used;
|
||||
#endif /* SYS_STATS */
|
||||
|
||||
vQueueDelete(*sem);
|
||||
vQueueDelete(*sem);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
int sys_sem_valid(sys_sem_t *sem)
|
||||
{
|
||||
if (*sem == SYS_SEM_NULL) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
if (*sem == SYS_SEM_NULL)
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void sys_sem_set_invalid(sys_sem_t *sem)
|
||||
{
|
||||
*sem = SYS_SEM_NULL;
|
||||
*sem = SYS_SEM_NULL;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
// Initialize sys arch
|
||||
void sys_init(void)
|
||||
{
|
||||
// keep track of how many threads have been created
|
||||
s_nextthread = 0;
|
||||
// keep track of how many threads have been created
|
||||
s_nextthread = 0;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Mutexes*/
|
||||
/* Mutexes*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#if LWIP_COMPAT_MUTEX == 0
|
||||
/* Create a new mutex*/
|
||||
err_t sys_mutex_new(sys_mutex_t *mutex)
|
||||
{
|
||||
*mutex = xSemaphoreCreateMutex();
|
||||
err_t sys_mutex_new(sys_mutex_t *mutex) {
|
||||
|
||||
if (*mutex == NULL) {
|
||||
*mutex = xSemaphoreCreateMutex();
|
||||
if(*mutex == NULL)
|
||||
{
|
||||
#if SYS_STATS
|
||||
++lwip_stats.sys.mutex.err;
|
||||
++lwip_stats.sys.mutex.err;
|
||||
#endif /* SYS_STATS */
|
||||
return ERR_MEM;
|
||||
}
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
#if SYS_STATS
|
||||
++lwip_stats.sys.mutex.used;
|
||||
|
||||
if (lwip_stats.sys.mutex.max < lwip_stats.sys.mutex.used) {
|
||||
lwip_stats.sys.mutex.max = lwip_stats.sys.mutex.used;
|
||||
}
|
||||
|
||||
++lwip_stats.sys.mutex.used;
|
||||
if (lwip_stats.sys.mutex.max < lwip_stats.sys.mutex.used) {
|
||||
lwip_stats.sys.mutex.max = lwip_stats.sys.mutex.used;
|
||||
}
|
||||
#endif /* SYS_STATS */
|
||||
return ERR_OK;
|
||||
return ERR_OK;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Deallocate a mutex*/
|
||||
void sys_mutex_free(sys_mutex_t *mutex)
|
||||
{
|
||||
#if SYS_STATS
|
||||
--lwip_stats.sys.mutex.used;
|
||||
--lwip_stats.sys.mutex.used;
|
||||
#endif /* SYS_STATS */
|
||||
vQueueDelete(*mutex);
|
||||
|
||||
vQueueDelete(*mutex);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Lock a mutex*/
|
||||
void sys_mutex_lock(sys_mutex_t *mutex)
|
||||
{
|
||||
sys_arch_sem_wait(mutex, 0);
|
||||
sys_arch_sem_wait(mutex, 0);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Unlock a mutex*/
|
||||
void sys_mutex_unlock(sys_mutex_t *mutex)
|
||||
{
|
||||
xSemaphoreGive(*mutex);
|
||||
xSemaphoreGive(*mutex);
|
||||
}
|
||||
|
||||
/* Mutex is locked */
|
||||
int sys_mutex_is_locked(sys_mutex_t *mutex)
|
||||
{
|
||||
return uxSemaphoreGetCount(*mutex) == 0;
|
||||
}
|
||||
#endif /*LWIP_COMPAT_MUTEX*/
|
||||
|
||||
int sys_is_inside_interrupt()
|
||||
{
|
||||
return xPortIsInsideInterrupt();
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
// TODO
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
@ -383,26 +398,38 @@ void sys_mutex_unlock(sys_mutex_t *mutex)
|
||||
thread() function. The id of the new thread is returned. Both the id and
|
||||
the priority are system dependent.
|
||||
*/
|
||||
sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, int stacksize, int prio)
|
||||
xTaskHandle TcpipTask;
|
||||
int sys_current_is_tcpip()
|
||||
{
|
||||
xTaskHandle CreatedTask;
|
||||
int result;
|
||||
return TcpipTask == xTaskGetCurrentTaskHandle();
|
||||
}
|
||||
sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread , void *arg, int stacksize, int prio)
|
||||
{
|
||||
xTaskHandle CreatedTask;
|
||||
int result;
|
||||
|
||||
if (s_nextthread < SYS_THREAD_MAX) {
|
||||
result = xTaskCreate(thread, name, stacksize, arg, prio, &CreatedTask);
|
||||
if ( s_nextthread < SYS_THREAD_MAX )
|
||||
{
|
||||
result = xTaskCreate( thread, name, stacksize, arg, prio, &CreatedTask );
|
||||
|
||||
// For each task created, store the task handle (pid) in the timers array.
|
||||
// This scheme doesn't allow for threads to be deleted
|
||||
//s_timeoutlist[s_nextthread++].pid = CreatedTask;
|
||||
// For each task created, store the task handle (pid) in the timers array.
|
||||
// This scheme doesn't allow for threads to be deleted
|
||||
//s_timeoutlist[s_nextthread++].pid = CreatedTask;
|
||||
|
||||
if (result == pdPASS) {
|
||||
return CreatedTask;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
if(result == pdPASS)
|
||||
{
|
||||
TcpipTask = CreatedTask;
|
||||
return CreatedTask;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -417,14 +444,11 @@ sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread, void *arg,
|
||||
|
||||
sys_arch_protect() is only required if your port is supporting an operating
|
||||
system.
|
||||
|
||||
Note: This function is based on FreeRTOS API, because no equivalent CMSIS-RTOS
|
||||
API is available
|
||||
*/
|
||||
sys_prot_t sys_arch_protect(void)
|
||||
{
|
||||
taskENTER_CRITICAL();
|
||||
return (sys_prot_t)1;
|
||||
taskENTER_CRITICAL();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -432,14 +456,27 @@ sys_prot_t sys_arch_protect(void)
|
||||
value specified by pval. See the documentation for sys_arch_protect() for
|
||||
more information. This function is only required if your port is supporting
|
||||
an operating system.
|
||||
|
||||
Note: This function is based on FreeRTOS API, because no equivalent CMSIS-RTOS
|
||||
API is available
|
||||
*/
|
||||
void sys_arch_unprotect(sys_prot_t pval)
|
||||
{
|
||||
(void)pval;
|
||||
taskEXIT_CRITICAL();
|
||||
( void ) pval;
|
||||
taskEXIT_CRITICAL();
|
||||
}
|
||||
|
||||
/*
|
||||
* Prints an assertion messages and aborts execution.
|
||||
*/
|
||||
void sys_assert( const char *msg )
|
||||
{
|
||||
( void ) msg;
|
||||
/*FSL:only needed for debugging
|
||||
printf(msg);
|
||||
printf("\n\r");
|
||||
*/
|
||||
taskENTER_CRITICAL();
|
||||
printf("[LWIP] sys_assert %s\r\n", msg);
|
||||
for(;;)
|
||||
;
|
||||
}
|
||||
|
||||
u32_t sys_now(void)
|
||||
@ -448,4 +485,75 @@ u32_t sys_now(void)
|
||||
return xTaskGetTickCount() / portTICK_PERIOD_MS;
|
||||
}
|
||||
|
||||
#endif /* !NO_SYS */
|
||||
#if LWIP_NETCONN_SEM_PER_THREAD
|
||||
#define PTHREAD_TLS_INDEX 0
|
||||
|
||||
static void sys_thread_sem_free(void *data)
|
||||
{
|
||||
sys_sem_t *sem = (sys_sem_t *)(data);
|
||||
|
||||
if (sem)
|
||||
{
|
||||
sys_sem_free(sem);
|
||||
free(sem);
|
||||
}
|
||||
}
|
||||
|
||||
static void pthread_local_storage_thread_deleted_callback(int index, void *value)
|
||||
{
|
||||
sys_sem_t *sem = (sys_sem_t *)value;
|
||||
|
||||
if (sem) {
|
||||
sys_thread_sem_free(sem);
|
||||
}
|
||||
|
||||
vTaskSetThreadLocalStoragePointerAndDelCallback(NULL, PTHREAD_TLS_INDEX, NULL, NULL);
|
||||
}
|
||||
|
||||
static sys_sem_t *sys_thread_sem_alloc(void)
|
||||
{
|
||||
sys_sem_t *sem;
|
||||
err_t err;
|
||||
int ret;
|
||||
|
||||
sem = (sys_sem_t *)malloc(sizeof(sys_sem_t));
|
||||
LWIP_ASSERT("failed to allocate memory for TLS semaphore", sem != NULL);
|
||||
err = sys_sem_new(sem, 0);
|
||||
LWIP_ASSERT("failed to initialise TLS semaphore", err == ERR_OK);
|
||||
ret = vTaskSetThreadLocalStoragePointerAndDelCallback(NULL, PTHREAD_TLS_INDEX, (void *)sem,
|
||||
pthread_local_storage_thread_deleted_callback);
|
||||
LWIP_ASSERT("failed to initialise TLS semaphore storage", ret == pdTRUE);
|
||||
|
||||
#if SYS_STATS
|
||||
++lwip_stats.sys.sem.used;
|
||||
if (lwip_stats.sys.sem.max < lwip_stats.sys.sem.used)
|
||||
{
|
||||
lwip_stats.sys.sem.max = lwip_stats.sys.sem.used;
|
||||
}
|
||||
#endif /* SYS_STATS */
|
||||
return sem;
|
||||
}
|
||||
|
||||
void *sys_thread_sem_get(void)
|
||||
{
|
||||
sys_sem_t *sem = (sys_sem_t *)pvTaskGetThreadLocalStoragePointer(NULL, PTHREAD_TLS_INDEX);
|
||||
if (sem == NULL)
|
||||
{
|
||||
return sys_thread_sem_alloc();
|
||||
}
|
||||
|
||||
return sem;
|
||||
}
|
||||
|
||||
void sys_thread_sem_init(void)
|
||||
{
|
||||
__attribute__((unused)) sys_sem_t *sem = sys_thread_sem_alloc();
|
||||
}
|
||||
|
||||
void sys_thread_sem_deinit(void)
|
||||
{
|
||||
sys_sem_t *sem = (sys_sem_t *)pvTaskGetThreadLocalStoragePointer(NULL, PTHREAD_TLS_INDEX);
|
||||
sys_thread_sem_free(sem);
|
||||
vTaskSetThreadLocalStoragePointerAndDelCallback(NULL, PTHREAD_TLS_INDEX, NULL, NULL);
|
||||
}
|
||||
#endif
|
66
components/net/lwip/lwip/lwip-port/FreeRTOS/sys_arch.h
Normal file
66
components/net/lwip/lwip/lwip-port/FreeRTOS/sys_arch.h
Normal file
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
|
||||
* 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.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
#ifndef __SYS_RTXC_H__
|
||||
#define __SYS_RTXC_H__
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "queue.h"
|
||||
#include "semphr.h"
|
||||
|
||||
#define SYS_MBOX_NULL (xQueueHandle)0
|
||||
#define SYS_SEM_NULL (xSemaphoreHandle)0
|
||||
#define SYS_DEFAULT_THREAD_STACK_DEPTH configMINIMAL_STACK_SIZE
|
||||
|
||||
typedef xSemaphoreHandle sys_sem_t;
|
||||
typedef xQueueHandle sys_mbox_t;
|
||||
typedef xTaskHandle sys_thread_t;
|
||||
|
||||
typedef struct _sys_arch_state_t
|
||||
{
|
||||
// Task creation data.
|
||||
char cTaskName[configMAX_TASK_NAME_LEN];
|
||||
unsigned short nStackDepth;
|
||||
unsigned short nTaskCount;
|
||||
} sys_arch_state_t;
|
||||
|
||||
|
||||
|
||||
//extern sys_arch_state_t s_sys_arch_state;
|
||||
|
||||
//void sys_set_default_state();
|
||||
//void sys_set_state(signed char *pTaskName, unsigned short nStackSize);
|
||||
|
||||
/* Message queue constants. */
|
||||
#define archMESG_QUEUE_LENGTH ( 6 )
|
||||
#endif /* __SYS_RTXC_H__ */
|
||||
|
351
components/net/lwip/lwip/lwip-port/Standalone/ethernetif.c
Normal file
351
components/net/lwip/lwip/lwip-port/Standalone/ethernetif.c
Normal file
@ -0,0 +1,351 @@
|
||||
/**
|
||||
* @file
|
||||
* Ethernet Interface for standalone applications (without RTOS) - works only for
|
||||
* ethernet polling mode (polling for ethernet frame reception)
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
||||
* 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.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/mem.h"
|
||||
#include "netif/etharp.h"
|
||||
#include "ethernetif.h"
|
||||
#include <string.h>
|
||||
|
||||
/* Network interface name */
|
||||
#define IFNAME0 's'
|
||||
#define IFNAME1 't'
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* In this function, the hardware should be initialized.
|
||||
* Called from ethernetif_init().
|
||||
*
|
||||
* @param netif the already initialized lwip network interface structure
|
||||
* for this ethernetif
|
||||
*/
|
||||
static void low_level_init(struct netif *netif)
|
||||
{
|
||||
#ifdef CHECKSUM_BY_HARDWARE
|
||||
int i;
|
||||
#endif
|
||||
/* set MAC hardware address length */
|
||||
netif->hwaddr_len = ETHARP_HWADDR_LEN;
|
||||
|
||||
/* set MAC hardware address */
|
||||
netif->hwaddr[0] = MAC_ADDR0;
|
||||
netif->hwaddr[1] = MAC_ADDR1;
|
||||
netif->hwaddr[2] = MAC_ADDR2;
|
||||
netif->hwaddr[3] = MAC_ADDR3;
|
||||
netif->hwaddr[4] = MAC_ADDR4;
|
||||
netif->hwaddr[5] = MAC_ADDR5;
|
||||
|
||||
/* initialize MAC address in ethernet MAC */
|
||||
ETH_MACAddressConfig(ETH_MAC_Address0, netif->hwaddr);
|
||||
|
||||
/* maximum transfer unit */
|
||||
netif->mtu = 1500;
|
||||
|
||||
/* device capabilities */
|
||||
/* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
|
||||
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP;
|
||||
|
||||
/* Initialize Tx Descriptors list: Chain Mode */
|
||||
ETH_DMATxDescChainInit(DMATxDscrTab, &Tx_Buff[0][0], ETH_TXBUFNB);
|
||||
/* Initialize Rx Descriptors list: Chain Mode */
|
||||
ETH_DMARxDescChainInit(DMARxDscrTab, &Rx_Buff[0][0], ETH_RXBUFNB);
|
||||
|
||||
#ifdef CHECKSUM_BY_HARDWARE
|
||||
/* Enable the TCP, UDP and ICMP checksum insertion for the Tx frames */
|
||||
for(i=0; i<ETH_TXBUFNB; i++)
|
||||
{
|
||||
ETH_DMATxDescChecksumInsertionConfig(&DMATxDscrTab[i], ETH_DMATxDesc_ChecksumTCPUDPICMPFull);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Note: TCP, UDP, ICMP checksum checking for received frame are enabled in DMA config */
|
||||
|
||||
/* Enable MAC and DMA transmission and reception */
|
||||
ETH_Start();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This function should do the actual transmission of the packet. The packet is
|
||||
* contained in the pbuf that is passed to the function. This pbuf
|
||||
* might be chained.
|
||||
*
|
||||
* @param netif the lwip network interface structure for this ethernetif
|
||||
* @param p the MAC packet to send (e.g. IP packet including MAC addresses and type)
|
||||
* @return ERR_OK if the packet could be sent
|
||||
* an err_t value if the packet couldn't be sent
|
||||
*
|
||||
* @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to
|
||||
* strange results. You might consider waiting for space in the DMA queue
|
||||
* to become availale since the stack doesn't retry to send a packet
|
||||
* dropped because of memory failure (except for the TCP timers).
|
||||
*/
|
||||
|
||||
static err_t low_level_output(struct netif *netif, struct pbuf *p)
|
||||
{
|
||||
err_t errval;
|
||||
struct pbuf *q;
|
||||
u8 *buffer = (u8 *)(DMATxDescToSet->Buffer1Addr);
|
||||
__IO ETH_DMADESCTypeDef *DmaTxDesc;
|
||||
uint16_t framelength = 0;
|
||||
uint32_t bufferoffset = 0;
|
||||
uint32_t byteslefttocopy = 0;
|
||||
uint32_t payloadoffset = 0;
|
||||
|
||||
DmaTxDesc = DMATxDescToSet;
|
||||
bufferoffset = 0;
|
||||
|
||||
/* copy frame from pbufs to driver buffers */
|
||||
for(q = p; q != NULL; q = q->next)
|
||||
{
|
||||
/* Is this buffer available? If not, goto error */
|
||||
if((DmaTxDesc->Status & ETH_DMATxDesc_OWN) != (u32)RESET)
|
||||
{
|
||||
errval = ERR_BUF;
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Get bytes in current lwIP buffer */
|
||||
byteslefttocopy = q->len;
|
||||
payloadoffset = 0;
|
||||
|
||||
/* Check if the length of data to copy is bigger than Tx buffer size*/
|
||||
while( (byteslefttocopy + bufferoffset) > ETH_TX_BUF_SIZE )
|
||||
{
|
||||
/* Copy data to Tx buffer*/
|
||||
memcpy( (u8_t*)((u8_t*)buffer + bufferoffset), (u8_t*)((u8_t*)q->payload + payloadoffset), (ETH_TX_BUF_SIZE - bufferoffset) );
|
||||
|
||||
/* Point to next descriptor */
|
||||
DmaTxDesc = (ETH_DMADESCTypeDef *)(DmaTxDesc->Buffer2NextDescAddr);
|
||||
|
||||
/* Check if the buffer is available */
|
||||
if((DmaTxDesc->Status & ETH_DMATxDesc_OWN) != (u32)RESET)
|
||||
{
|
||||
errval = ERR_USE;
|
||||
goto error;
|
||||
}
|
||||
|
||||
buffer = (u8 *)(DmaTxDesc->Buffer1Addr);
|
||||
|
||||
byteslefttocopy = byteslefttocopy - (ETH_TX_BUF_SIZE - bufferoffset);
|
||||
payloadoffset = payloadoffset + (ETH_TX_BUF_SIZE - bufferoffset);
|
||||
framelength = framelength + (ETH_TX_BUF_SIZE - bufferoffset);
|
||||
bufferoffset = 0;
|
||||
}
|
||||
|
||||
/* Copy the remaining bytes */
|
||||
memcpy( (u8_t*)((u8_t*)buffer + bufferoffset), (u8_t*)((u8_t*)q->payload + payloadoffset), byteslefttocopy );
|
||||
bufferoffset = bufferoffset + byteslefttocopy;
|
||||
framelength = framelength + byteslefttocopy;
|
||||
}
|
||||
|
||||
/* Note: padding and CRC for transmitted frame
|
||||
are automatically inserted by DMA */
|
||||
|
||||
/* Prepare transmit descriptors to give to DMA*/
|
||||
ETH_Prepare_Transmit_Descriptors(framelength);
|
||||
|
||||
errval = ERR_OK;
|
||||
|
||||
error:
|
||||
|
||||
/* When Transmit Underflow flag is set, clear it and issue a Transmit Poll Demand to resume transmission */
|
||||
if ((ETH->DMASR & ETH_DMASR_TUS) != (uint32_t)RESET)
|
||||
{
|
||||
/* Clear TUS ETHERNET DMA flag */
|
||||
ETH->DMASR = ETH_DMASR_TUS;
|
||||
|
||||
/* Resume DMA transmission*/
|
||||
ETH->DMATPDR = 0;
|
||||
}
|
||||
return errval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should allocate a pbuf and transfer the bytes of the incoming
|
||||
* packet from the interface into the pbuf.
|
||||
*
|
||||
* @param netif the lwip network interface structure for this ethernetif
|
||||
* @return a pbuf filled with the received packet (including MAC header)
|
||||
* NULL on memory error
|
||||
*/
|
||||
static struct pbuf * low_level_input(struct netif *netif)
|
||||
{
|
||||
struct pbuf *p, *q;
|
||||
uint32_t len;
|
||||
FrameTypeDef frame;
|
||||
u8 *buffer;
|
||||
__IO ETH_DMADESCTypeDef *DMARxDesc;
|
||||
uint32_t bufferoffset = 0;
|
||||
uint32_t payloadoffset = 0;
|
||||
uint32_t byteslefttocopy = 0;
|
||||
uint32_t i=0;
|
||||
|
||||
/* get received frame */
|
||||
frame = ETH_Get_Received_Frame();
|
||||
|
||||
/* Obtain the size of the packet and put it into the "len" variable. */
|
||||
len = frame.length;
|
||||
buffer = (u8 *)frame.buffer;
|
||||
|
||||
/* We allocate a pbuf chain of pbufs from the Lwip buffer pool */
|
||||
p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
|
||||
|
||||
if (p != NULL)
|
||||
{
|
||||
DMARxDesc = frame.descriptor;
|
||||
bufferoffset = 0;
|
||||
for(q = p; q != NULL; q = q->next)
|
||||
{
|
||||
byteslefttocopy = q->len;
|
||||
payloadoffset = 0;
|
||||
|
||||
/* Check if the length of bytes to copy in current pbuf is bigger than Rx buffer size*/
|
||||
while( (byteslefttocopy + bufferoffset) > ETH_RX_BUF_SIZE )
|
||||
{
|
||||
/* Copy data to pbuf*/
|
||||
memcpy( (u8_t*)((u8_t*)q->payload + payloadoffset), (u8_t*)((u8_t*)buffer + bufferoffset), (ETH_RX_BUF_SIZE - bufferoffset));
|
||||
|
||||
/* Point to next descriptor */
|
||||
DMARxDesc = (ETH_DMADESCTypeDef *)(DMARxDesc->Buffer2NextDescAddr);
|
||||
buffer = (unsigned char *)(DMARxDesc->Buffer1Addr);
|
||||
|
||||
byteslefttocopy = byteslefttocopy - (ETH_RX_BUF_SIZE - bufferoffset);
|
||||
payloadoffset = payloadoffset + (ETH_RX_BUF_SIZE - bufferoffset);
|
||||
bufferoffset = 0;
|
||||
}
|
||||
/* Copy remaining data in pbuf */
|
||||
memcpy( (u8_t*)((u8_t*)q->payload + payloadoffset), (u8_t*)((u8_t*)buffer + bufferoffset), byteslefttocopy);
|
||||
bufferoffset = bufferoffset + byteslefttocopy;
|
||||
}
|
||||
}
|
||||
|
||||
/* Release descriptors to DMA */
|
||||
DMARxDesc =frame.descriptor;
|
||||
|
||||
/* Set Own bit in Rx descriptors: gives the buffers back to DMA */
|
||||
for (i=0; i<DMA_RX_FRAME_infos->Seg_Count; i++)
|
||||
{
|
||||
DMARxDesc->Status = ETH_DMARxDesc_OWN;
|
||||
DMARxDesc = (ETH_DMADESCTypeDef *)(DMARxDesc->Buffer2NextDescAddr);
|
||||
}
|
||||
|
||||
/* Clear Segment_Count */
|
||||
DMA_RX_FRAME_infos->Seg_Count =0;
|
||||
|
||||
/* When Rx Buffer unavailable flag is set: clear it and resume reception */
|
||||
if ((ETH->DMASR & ETH_DMASR_RBUS) != (u32)RESET)
|
||||
{
|
||||
/* Clear RBUS ETHERNET DMA flag */
|
||||
ETH->DMASR = ETH_DMASR_RBUS;
|
||||
/* Resume DMA reception */
|
||||
ETH->DMARPDR = 0;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function should be called when a packet is ready to be read
|
||||
* from the interface. It uses the function low_level_input() that
|
||||
* should handle the actual reception of bytes from the network
|
||||
* interface. Then the type of the received packet is determined and
|
||||
* the appropriate input function is called.
|
||||
*
|
||||
* @param netif the lwip network interface structure for this ethernetif
|
||||
*/
|
||||
err_t ethernetif_input(struct netif *netif)
|
||||
{
|
||||
err_t err;
|
||||
struct pbuf *p;
|
||||
|
||||
/* move received packet into a new pbuf */
|
||||
p = low_level_input(netif);
|
||||
|
||||
/* no packet could be read, silently ignore this */
|
||||
if (p == NULL) return ERR_MEM;
|
||||
|
||||
/* entry point to the LwIP stack */
|
||||
err = netif->input(p, netif);
|
||||
|
||||
if (err != ERR_OK)
|
||||
{
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
|
||||
pbuf_free(p);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Should be called at the beginning of the program to set up the
|
||||
* network interface. It calls the function low_level_init() to do the
|
||||
* actual setup of the hardware.
|
||||
*
|
||||
* This function should be passed as a parameter to netif_add().
|
||||
*
|
||||
* @param netif the lwip network interface structure for this ethernetif
|
||||
* @return ERR_OK if the loopif is initialized
|
||||
* ERR_MEM if private data couldn't be allocated
|
||||
* any other err_t on error
|
||||
*/
|
||||
err_t ethernetif_init(struct netif *netif)
|
||||
{
|
||||
LWIP_ASSERT("netif != NULL", (netif != NULL));
|
||||
#if 0
|
||||
|
||||
#if LWIP_NETIF_HOSTNAME
|
||||
/* Initialize interface hostname */
|
||||
netif->hostname = "lwip";
|
||||
#endif /* LWIP_NETIF_HOSTNAME */
|
||||
|
||||
netif->name[0] = IFNAME0;
|
||||
netif->name[1] = IFNAME1;
|
||||
/* We directly use etharp_output() here to save a function call.
|
||||
* You can instead declare your own function an call etharp_output()
|
||||
* from it if you have to do some checks before sending (e.g. if link
|
||||
* is available...) */
|
||||
netif->output = etharp_output;
|
||||
netif->linkoutput = low_level_output;
|
||||
|
||||
/* initialize the hardware */
|
||||
low_level_init(netif);
|
||||
#endif
|
||||
|
||||
return ERR_OK;
|
||||
}
|
11
components/net/lwip/lwip/lwip-port/Standalone/ethernetif.h
Normal file
11
components/net/lwip/lwip/lwip-port/Standalone/ethernetif.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef __ETHERNETIF_H__
|
||||
#define __ETHERNETIF_H__
|
||||
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/netif.h"
|
||||
|
||||
err_t ethernetif_init(struct netif *netif);
|
||||
err_t ethernetif_input(struct netif *netif);
|
||||
|
||||
#endif
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* 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,
|
||||
@ -11,21 +11,21 @@
|
||||
* 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.
|
||||
* 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
|
||||
* 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.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
@ -33,3 +33,4 @@
|
||||
#if defined(__IAR_SYSTEMS_ICC__)
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* 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,
|
||||
@ -11,21 +11,21 @@
|
||||
* 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.
|
||||
* 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
|
||||
* 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.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
@ -33,45 +33,52 @@
|
||||
#define __CC_H__
|
||||
|
||||
#include "cpu.h"
|
||||
#include "sys_arch.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
// #include "bflb_platform.h"
|
||||
|
||||
typedef int sys_prot_t;
|
||||
#if 0
|
||||
typedef unsigned char u8_t;
|
||||
typedef signed char s8_t;
|
||||
typedef unsigned short u16_t;
|
||||
typedef signed short s16_t;
|
||||
typedef unsigned int u32_t;
|
||||
typedef signed int s32_t;
|
||||
typedef int sys_prot_t;
|
||||
|
||||
#if defined(__GNUC__) & !defined(__CC_ARM)
|
||||
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
#include <sys/time.h>
|
||||
#define U16_F "hu"
|
||||
#define S16_F "d"
|
||||
#define X16_F "hx"
|
||||
#define U32_F "u"
|
||||
#define S32_F "d"
|
||||
#define X32_F "x"
|
||||
#define SZT_F "uz"
|
||||
|
||||
#endif
|
||||
|
||||
/* define compiler specific symbols */
|
||||
#if defined(__ICCARM__)
|
||||
#if defined (__ICCARM__)
|
||||
|
||||
#define PACK_STRUCT_BEGIN
|
||||
#define PACK_STRUCT_STRUCT
|
||||
#define PACK_STRUCT_STRUCT
|
||||
#define PACK_STRUCT_END
|
||||
#define PACK_STRUCT_FIELD(x) x
|
||||
#define PACK_STRUCT_USE_INCLUDES
|
||||
|
||||
#elif defined(__GNUC__)
|
||||
|
||||
#define PACK_STRUCT_BEGIN
|
||||
#define PACK_STRUCT_STRUCT __attribute__((__packed__))
|
||||
#define PACK_STRUCT_END
|
||||
#define PACK_STRUCT_FIELD(x) x
|
||||
|
||||
#elif defined(__CC_ARM)
|
||||
#elif defined (__CC_ARM)
|
||||
|
||||
#define PACK_STRUCT_BEGIN __packed
|
||||
#define PACK_STRUCT_STRUCT
|
||||
#define PACK_STRUCT_STRUCT
|
||||
#define PACK_STRUCT_END
|
||||
#define PACK_STRUCT_FIELD(x) x
|
||||
|
||||
#elif defined(__TASKING__)
|
||||
#elif defined (__GNUC__)
|
||||
|
||||
#define PACK_STRUCT_BEGIN
|
||||
#define PACK_STRUCT_STRUCT __attribute__ ((__packed__))
|
||||
#define PACK_STRUCT_END
|
||||
#define PACK_STRUCT_FIELD(x) x
|
||||
|
||||
#elif defined (__TASKING__)
|
||||
|
||||
#define PACK_STRUCT_BEGIN
|
||||
#define PACK_STRUCT_STRUCT
|
||||
@ -80,16 +87,6 @@ typedef int sys_prot_t;
|
||||
|
||||
#endif
|
||||
|
||||
#define LWIP_PLATFORM_ASSERT(x) \
|
||||
do { \
|
||||
printf("Assertion \"%s\" failed at line %d in %s\n", \
|
||||
x, __LINE__, __FILE__); \
|
||||
} while (0)
|
||||
|
||||
#define LWIP_PLATFORM_DIAG(x) \
|
||||
do { \
|
||||
printf x; \
|
||||
printf("\r"); \
|
||||
} while (0)
|
||||
#define LWIP_PLATFORM_ASSERT(x) printf(x); asm("ebreak") //do { if(!(x)) while(1); } while(0)
|
||||
|
||||
#endif /* __CC_H__ */
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* 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,
|
||||
@ -11,21 +11,21 @@
|
||||
* 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.
|
||||
* 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
|
||||
* 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.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* 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,
|
||||
@ -11,21 +11,21 @@
|
||||
* 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.
|
||||
* 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
|
||||
* 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.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
@ -33,3 +33,4 @@
|
||||
#if defined(__IAR_SYSTEMS_ICC__)
|
||||
#pragma pack()
|
||||
#endif
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* 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,
|
||||
@ -11,30 +11,34 @@
|
||||
* 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.
|
||||
* 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
|
||||
* 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.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
#ifndef __ARCH_INIT_H__
|
||||
#define __ARCH_INIT_H__
|
||||
|
||||
#define TCPIP_INIT_DONE(arg) tcpip_init_done(arg)
|
||||
#define TCPIP_INIT_DONE(arg) tcpip_init_done(arg)
|
||||
|
||||
void tcpip_init_done(void *);
|
||||
int wait_for_tcpip_init(void);
|
||||
|
||||
#endif /* __ARCH_INIT_H__ */
|
||||
|
||||
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* 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,
|
||||
@ -11,21 +11,21 @@
|
||||
* 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.
|
||||
* 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
|
||||
* 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.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
@ -34,4 +34,5 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#endif /* __LIB_H__ */
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* 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,
|
||||
@ -11,28 +11,28 @@
|
||||
* 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.
|
||||
* 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
|
||||
* 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.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
#ifndef __PERF_H__
|
||||
#define __PERF_H__
|
||||
|
||||
#define PERF_START /* null definition */
|
||||
#define PERF_STOP(x) /* null definition */
|
||||
#define PERF_START /* null definition */
|
||||
#define PERF_STOP(x) /* null definition */
|
||||
|
||||
#endif /* __PERF_H__ */
|
@ -29,42 +29,39 @@
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
*
|
||||
*/
|
||||
#ifndef __SYS_ARCH_H__
|
||||
#define __SYS_ARCH_H__
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#ifndef __SYS_RTXC_H__
|
||||
#define __SYS_RTXC_H__
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "queue.h"
|
||||
#include "semphr.h"
|
||||
|
||||
#if (NO_SYS != 0)
|
||||
#error "NO_SYS need to be set to 0 to use threaded API"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SYS_MBOX_NULL (xQueueHandle)0
|
||||
#define SYS_SEM_NULL (xSemaphoreHandle)0
|
||||
|
||||
#define osPriorityIdle 0 //< priority: idle (lowest)
|
||||
#define osPriorityLow 1 //< priority: low
|
||||
#define osPriorityBelowNormal 2 //< priority: below normal
|
||||
#define osPriorityNormal 3 //< priority: normal (default)
|
||||
#define osPriorityAboveNormal 4 //< priority: above normal
|
||||
#define osPriorityHigh 5 //< priority: high
|
||||
#define osPriorityRealtime 6 //< priority: realtime (highest)
|
||||
#define SYS_DEFAULT_THREAD_STACK_DEPTH configMINIMAL_STACK_SIZE
|
||||
|
||||
typedef xSemaphoreHandle sys_sem_t;
|
||||
typedef xSemaphoreHandle sys_mutex_t;
|
||||
typedef xQueueHandle sys_mbox_t;
|
||||
typedef xTaskHandle sys_thread_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
typedef struct _sys_arch_state_t
|
||||
{
|
||||
// Task creation data.
|
||||
char cTaskName[configMAX_TASK_NAME_LEN];
|
||||
unsigned short nStackDepth;
|
||||
unsigned short nTaskCount;
|
||||
} sys_arch_state_t;
|
||||
|
||||
|
||||
|
||||
//extern sys_arch_state_t s_sys_arch_state;
|
||||
|
||||
//void sys_set_default_state();
|
||||
//void sys_set_state(signed char *pTaskName, unsigned short nStackSize);
|
||||
|
||||
/* Message queue constants. */
|
||||
#define archMESG_QUEUE_LENGTH ( 6 )
|
||||
#endif /* __SYS_RTXC_H__ */
|
||||
|
||||
#endif /* __SYS_ARCH_H__ */
|
420
components/net/lwip/lwip/lwip-port/config/lwipopts.h
Normal file
420
components/net/lwip/lwip/lwip-port/config/lwipopts.h
Normal file
@ -0,0 +1,420 @@
|
||||
#ifndef __LWIPOPTS_H__
|
||||
#define __LWIPOPTS_H__
|
||||
|
||||
#include "stdbool.h"
|
||||
|
||||
/**
|
||||
* SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain
|
||||
* critical regions during buffer allocation, deallocation and memory
|
||||
* allocation and deallocation.
|
||||
*/
|
||||
#define SYS_LIGHTWEIGHT_PROT 1
|
||||
|
||||
#define LWIP_NETIF_HOSTNAME 1
|
||||
#define ETHARP_TRUST_IP_MAC 0
|
||||
#define IP_REASSEMBLY 0
|
||||
#define IP_FRAG 0
|
||||
#define ARP_QUEUEING 0
|
||||
#define LWIP_NETIF_API 1
|
||||
|
||||
#define LWIP_MDNS_RESPONDER 1
|
||||
#define LWIP_IGMP 1
|
||||
|
||||
#define LWIP_NUM_NETIF_CLIENT_DATA 1
|
||||
|
||||
#define LWIP_ALTCP 1
|
||||
#define LWIP_ALTCP_TLS 1
|
||||
/**
|
||||
* NO_SYS==1: Provides VERY minimal functionality. Otherwise,
|
||||
* use lwIP facilities.
|
||||
*/
|
||||
#define NO_SYS 0
|
||||
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
|
||||
#define LWIP_HAVE_LOOPIF 1
|
||||
|
||||
/**
|
||||
* LWIP_TCPIP_CORE_LOCKING_INPUT: when LWIP_TCPIP_CORE_LOCKING is enabled,
|
||||
* this lets tcpip_input() grab the mutex for input packets as well,
|
||||
* instead of allocating a message and passing it to tcpip_thread.
|
||||
*
|
||||
* ATTENTION: this does not work when tcpip_input() is called from
|
||||
* interrupt context!
|
||||
*/
|
||||
#if defined(CFG_CHIP_BL808)
|
||||
#define LWIP_TCPIP_CORE_LOCKING_INPUT 1
|
||||
#elif defined(CFG_CHIP_BL606P)
|
||||
#define LWIP_TCPIP_CORE_LOCKING_INPUT 1
|
||||
#else
|
||||
#define LWIP_TCPIP_CORE_LOCKING_INPUT 0
|
||||
#endif
|
||||
|
||||
/* ---------- Memory options ---------- */
|
||||
/* MEM_ALIGNMENT: should be set to the alignment of the CPU for which
|
||||
lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2
|
||||
byte alignment -> define MEM_ALIGNMENT to 2. */
|
||||
#define MEM_ALIGNMENT 4
|
||||
|
||||
/* MEM_SIZE: the size of the heap memory. If the application will send
|
||||
a lot of data that needs to be copied, this should be set high. */
|
||||
#if defined(CFG_CHIP_BL808)
|
||||
#define MEM_SIZE (60*1024)
|
||||
#elif defined(CFG_CHIP_BL606P)
|
||||
#define MEM_SIZE (60*1024)
|
||||
#elif defined(CFG_SDIOWIFI)
|
||||
#define MEM_SIZE (8*1024)
|
||||
#elif defined(CFG_NETBUS_WIFI_ENABLE)
|
||||
#define MEM_SIZE (12*1024)
|
||||
#else
|
||||
#define MEM_SIZE (8*1024)
|
||||
#endif
|
||||
|
||||
|
||||
/* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application
|
||||
sends a lot of data out of ROM (or other static memory), this
|
||||
should be set high. */
|
||||
#define MEMP_NUM_PBUF 26
|
||||
/* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One
|
||||
per active UDP "connection". */
|
||||
#ifdef OPENTHREAD_BORDER_ROUTER
|
||||
#define MEMP_NUM_UDP_PCB 20
|
||||
#else
|
||||
#define MEMP_NUM_UDP_PCB 6
|
||||
#endif
|
||||
|
||||
/* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP
|
||||
connections. */
|
||||
#define MEMP_NUM_TCP_PCB 10
|
||||
/* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP
|
||||
connections. */
|
||||
#define MEMP_NUM_TCP_PCB_LISTEN 5
|
||||
/* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP
|
||||
segments. */
|
||||
#if defined(CFG_CHIP_BL808)
|
||||
#define MEMP_NUM_TCP_SEG 100
|
||||
#elif defined(CFG_CHIP_BL606P)
|
||||
#define MEMP_NUM_TCP_SEG 100
|
||||
#else
|
||||
#define MEMP_NUM_TCP_SEG 32
|
||||
#endif
|
||||
|
||||
/* NUM of sys_timeout pool*/
|
||||
#define MEMP_NUM_SYS_TIMEOUT (LWIP_NUM_SYS_TIMEOUT_INTERNAL + 8 + 3)
|
||||
|
||||
#define MEMP_NUM_NETCONN (MEMP_NUM_TCP_PCB + MEMP_NUM_UDP_PCB + MEMP_NUM_TCP_PCB_LISTEN)
|
||||
|
||||
/* ---------- Pbuf options ---------- */
|
||||
/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */
|
||||
#if !defined PBUF_POOL_SIZE
|
||||
#if defined(CFG_CHIP_BL808)
|
||||
#define PBUF_POOL_SIZE 200
|
||||
#elif defined(CFG_CHIP_BL606P)
|
||||
#define PBUF_POOL_SIZE 200
|
||||
#else
|
||||
|
||||
#if defined(CFG_ETHERNET_ENABLE)
|
||||
#define PBUF_POOL_SIZE 12
|
||||
#else
|
||||
#define PBUF_POOL_SIZE 0
|
||||
#endif
|
||||
#endif /*CFG_ETHERNET_ENABLE*/
|
||||
#endif
|
||||
|
||||
/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */
|
||||
#if defined(CFG_CHIP_BL808)||defined(CFG_ETHERNET_ENABLE)
|
||||
#define PBUF_POOL_BUFSIZE 1600
|
||||
#elif defined(CFG_CHIP_BL606P)
|
||||
#define PBUF_POOL_BUFSIZE 1600
|
||||
#else
|
||||
#ifndef PBUF_POOL_BUFSIZE
|
||||
#define PBUF_POOL_BUFSIZE 760
|
||||
#endif
|
||||
#endif /* CFG_ETHERNET_ENABLE */
|
||||
|
||||
|
||||
/* ---------- TCP options ---------- */
|
||||
#define LWIP_TCP 1
|
||||
#define IP_DEFAULT_TTL 64
|
||||
|
||||
/* Controls if TCP should queue segments that arrive out of
|
||||
order. Define to 0 if your device is low on memory. */
|
||||
#define TCP_QUEUE_OOSEQ 1
|
||||
|
||||
/* TCP Maximum segment size. */
|
||||
#define TCP_MSS (1500 - 40) /* TCP_MSS = (Ethernet MTU - IP header size - TCP header size) */
|
||||
//#define TCP_MSS (1500 - 80) /* TCP_MSS = (Ethernet MTU - IP header size - TCP header size) */
|
||||
//#define TCP_MSS (800 - 40 - 80 + 8) /* TCP_MSS = (Ethernet MTU - IP header size - TCP header size) */
|
||||
|
||||
|
||||
/* TCP sender buffer space (bytes). */
|
||||
#if defined(CFG_CHIP_BL808)
|
||||
#define TCP_SND_BUF (12*TCP_MSS)
|
||||
#elif defined(CFG_CHIP_BL606P)
|
||||
#define TCP_SND_BUF (12*TCP_MSS)
|
||||
#else
|
||||
#ifdef CFG_ETHERNET_ENABLE
|
||||
#define TCP_SND_BUF (11*TCP_MSS)
|
||||
#else
|
||||
#define TCP_SND_BUF (3*TCP_MSS)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* TCP_SND_QUEUELEN: TCP sender buffer space (pbufs). This must be at least
|
||||
as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. */
|
||||
|
||||
#define TCP_SND_QUEUELEN ((2 * (TCP_SND_BUF) + (TCP_MSS - 1))/(TCP_MSS))
|
||||
|
||||
#define MEMP_NUM_TCPIP_MSG_INPKT (32)
|
||||
|
||||
/**
|
||||
* TCP_SNDQUEUELOWAT: TCP writable bufs (pbuf count). This must be less
|
||||
* than TCP_SND_QUEUELEN. If the number of pbufs queued on a pcb drops below
|
||||
* this number, select returns writable (combined with TCP_SNDLOWAT).
|
||||
*/
|
||||
#define TCP_SNDQUEUELOWAT ((TCP_SND_QUEUELEN)/2)
|
||||
|
||||
/* TCP receive window. */
|
||||
#if defined(CFG_CHIP_BL808)
|
||||
#define TCP_WND (30*TCP_MSS)
|
||||
#elif defined(CFG_CHIP_BL606P)
|
||||
#define TCP_WND (30*TCP_MSS)
|
||||
#else
|
||||
#ifdef CFG_ETHERNET_ENABLE
|
||||
#define TCP_WND (6*TCP_MSS)
|
||||
#else
|
||||
#define TCP_WND (3*TCP_MSS)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(CFG_CHIP_BL808)
|
||||
#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[LWIP_MEM_ALIGN_BUFFER(size)]
|
||||
#endif
|
||||
|
||||
#if defined(CFG_CHIP_BL606P)
|
||||
#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[LWIP_MEM_ALIGN_BUFFER(size)]
|
||||
#endif
|
||||
|
||||
/**
|
||||
* TCP_WND_UPDATE_THRESHOLD: difference in window to trigger an
|
||||
* explicit window update
|
||||
*/
|
||||
#if defined(CFG_CHIP_BL808)
|
||||
#define TCP_WND_UPDATE_THRESHOLD LWIP_MIN((TCP_WND / 2), (TCP_MSS * 16))
|
||||
#elif defined(CFG_CHIP_BL606P)
|
||||
#define TCP_WND_UPDATE_THRESHOLD LWIP_MIN((TCP_WND / 2), (TCP_MSS * 16))
|
||||
#else
|
||||
#define TCP_WND_UPDATE_THRESHOLD LWIP_MIN((TCP_WND / 2), (TCP_MSS * 6))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* By default, TCP socket/netconn close waits 20 seconds max to send the FIN
|
||||
*/
|
||||
#define LWIP_TCP_CLOSE_TIMEOUT_MS_DEFAULT 5000
|
||||
|
||||
/**
|
||||
* LWIP_SO_SNDTIMEO==1: Enable send timeout for sockets/netconns and
|
||||
* SO_SNDTIMEO processing.
|
||||
*/
|
||||
#define LWIP_SO_SNDTIMEO 1
|
||||
/**
|
||||
* LWIP_SO_RCVTIMEO==1: Enable receive timeout for sockets/netconns and
|
||||
* SO_RCVTIMEO processing.
|
||||
*/
|
||||
#define LWIP_SO_RCVTIMEO 1
|
||||
|
||||
|
||||
/* ---------- ICMP options ---------- */
|
||||
#define LWIP_ICMP 1
|
||||
|
||||
|
||||
/* ---------- DHCP options ---------- */
|
||||
/* Define LWIP_DHCP to 1 if you want DHCP configuration of
|
||||
interfaces. DHCP is not implemented in lwIP 0.5.1, however, so
|
||||
turning this on does currently not work. */
|
||||
#define LWIP_DHCP 1
|
||||
|
||||
|
||||
/* ---------- UDP options ---------- */
|
||||
#define LWIP_UDP 1
|
||||
|
||||
|
||||
/* ---------- Statistics options ---------- */
|
||||
#define LWIP_STATS 1
|
||||
#ifdef OPENTHREAD_BORDER_ROUTER
|
||||
#define LWIP_ERRNO_STDINCLUDE 1
|
||||
#else
|
||||
#define LWIP_PROVIDE_ERRNO 1
|
||||
#endif
|
||||
|
||||
/* ---------- link callback options ---------- */
|
||||
/* LWIP_NETIF_LINK_CALLBACK==1: Support a callback function from an interface
|
||||
* whenever the link changes (i.e., link down)
|
||||
*/
|
||||
#define LWIP_NETIF_LINK_CALLBACK 1
|
||||
|
||||
/*
|
||||
--------------------------------------
|
||||
---------- Checksum options ----------
|
||||
--------------------------------------
|
||||
*/
|
||||
|
||||
#define LWIP_CHECKSUM_ON_COPY 1
|
||||
#ifdef CFG_ETHERNET_ENABLE
|
||||
#define LWIP_NETIF_TX_SINGLE_PBUF 0
|
||||
#else
|
||||
#define LWIP_NETIF_TX_SINGLE_PBUF 1
|
||||
#endif /* CFG_ETHERNET_ENABLE */
|
||||
|
||||
#ifdef CHECKSUM_BY_HARDWARE
|
||||
/* CHECKSUM_GEN_IP==0: Generate checksums by hardware for outgoing IP packets.*/
|
||||
#define CHECKSUM_GEN_IP 0
|
||||
/* CHECKSUM_GEN_UDP==0: Generate checksums by hardware for outgoing UDP packets.*/
|
||||
#define CHECKSUM_GEN_UDP 0
|
||||
/* CHECKSUM_GEN_TCP==0: Generate checksums by hardware for outgoing TCP packets.*/
|
||||
#define CHECKSUM_GEN_TCP 0
|
||||
/* CHECKSUM_CHECK_IP==0: Check checksums by hardware for incoming IP packets.*/
|
||||
#define CHECKSUM_CHECK_IP 0
|
||||
/* CHECKSUM_CHECK_UDP==0: Check checksums by hardware for incoming UDP packets.*/
|
||||
#define CHECKSUM_CHECK_UDP 0
|
||||
/* CHECKSUM_CHECK_TCP==0: Check checksums by hardware for incoming TCP packets.*/
|
||||
#define CHECKSUM_CHECK_TCP 0
|
||||
/* CHECKSUM_CHECK_ICMP==0: Check checksums by hardware for incoming ICMP packets.*/
|
||||
#define CHECKSUM_GEN_ICMP 0
|
||||
#else
|
||||
/* CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP packets.*/
|
||||
#define CHECKSUM_GEN_IP 1
|
||||
/* CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets.*/
|
||||
#define CHECKSUM_GEN_UDP 1
|
||||
/* CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets.*/
|
||||
#define CHECKSUM_GEN_TCP 1
|
||||
/* CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets.*/
|
||||
#define CHECKSUM_CHECK_IP 1
|
||||
/* CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets.*/
|
||||
#define CHECKSUM_CHECK_UDP 1
|
||||
/* CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets.*/
|
||||
#define CHECKSUM_CHECK_TCP 1
|
||||
/* CHECKSUM_CHECK_ICMP==1: Check checksums by hardware for incoming ICMP packets.*/
|
||||
#define CHECKSUM_GEN_ICMP 1
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
----------------------------------------------
|
||||
---------- Sequential layer options ----------
|
||||
----------------------------------------------
|
||||
*/
|
||||
#define LWIP_CHKSUM_ALGORITHM 3
|
||||
|
||||
/**
|
||||
* LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c)
|
||||
*/
|
||||
#define LWIP_NETCONN 1
|
||||
|
||||
/*
|
||||
------------------------------------
|
||||
---------- Socket options ----------
|
||||
------------------------------------
|
||||
*/
|
||||
/**
|
||||
* LWIP_SOCKET==1: Enable Socket API (require to use sockets.c)
|
||||
*/
|
||||
#define LWIP_SOCKET 1
|
||||
|
||||
/*
|
||||
-----------------------------------
|
||||
---------- DEBUG options ----------
|
||||
-----------------------------------
|
||||
*/
|
||||
|
||||
//#define LWIP_DEBUG 0
|
||||
|
||||
/*
|
||||
---------------------------------
|
||||
---------- OS options ----------
|
||||
---------------------------------
|
||||
*/
|
||||
|
||||
#define TCPIP_THREAD_NAME "TCP/IP"
|
||||
#ifdef CFG_ETHERNET_ENABLE
|
||||
#define TCPIP_THREAD_STACKSIZE 1536
|
||||
#elif defined(CFG_SDIOWIFI)
|
||||
#define TCPIP_THREAD_STACKSIZE 512
|
||||
#elif defined(CFG_NETBUS_WIFI_ENABLE)
|
||||
#define TCPIP_THREAD_STACKSIZE 1536
|
||||
#elif defined(CFG_TCPIP_STACKSIZE)
|
||||
#define TCPIP_THREAD_STACKSIZE CFG_TCPIP_STACKSIZE
|
||||
#else
|
||||
#define TCPIP_THREAD_STACKSIZE 4000
|
||||
#endif /* CFG_ETHERNET_ENABLE */
|
||||
#define TCPIP_MBOX_SIZE 50
|
||||
#define DEFAULT_UDP_RECVMBOX_SIZE 50
|
||||
#define DEFAULT_TCP_RECVMBOX_SIZE 50
|
||||
#define DEFAULT_ACCEPTMBOX_SIZE 50
|
||||
#define DEFAULT_THREAD_STACKSIZE 500
|
||||
#define TCPIP_THREAD_PRIO (configMAX_PRIORITIES - 2)
|
||||
|
||||
#define LWIP_COMPAT_MUTEX 0
|
||||
#if defined(CFG_CHIP_BL808)
|
||||
#define LWIP_TCPIP_CORE_LOCKING 1
|
||||
#elif defined(CFG_CHIP_BL606P)
|
||||
#define LWIP_TCPIP_CORE_LOCKING 1
|
||||
#else
|
||||
#define LWIP_TCPIP_CORE_LOCKING 0
|
||||
#endif
|
||||
#define LWIP_SOCKET_SET_ERRNO 1
|
||||
#define SO_REUSE 1
|
||||
#define LWIP_TCP_KEEPALIVE 1
|
||||
|
||||
/*Enable Status callback and link callback*/
|
||||
#define LWIP_NETIF_STATUS_CALLBACK 1
|
||||
#define LWIP_NETIF_LINK_CALLBACK 1
|
||||
/*Enable dns*/
|
||||
#define LWIP_DNS 1
|
||||
#define LWIP_DNS_SECURE 0
|
||||
|
||||
#define MEMP_MEM_MALLOC 0
|
||||
#define LWIP_SUPPORT_CUSTOM_PBUF 1
|
||||
|
||||
#define PBUF_LINK_ENCAPSULATION_HLEN 48u
|
||||
|
||||
#define LWIP_RAW 1
|
||||
|
||||
/*
|
||||
---------------------------------
|
||||
---------- MISC. options ----------
|
||||
---------------------------------
|
||||
*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" int bl_rand(void);
|
||||
extern "C" int * __errno(void);
|
||||
#else
|
||||
extern int bl_rand(void);
|
||||
extern int * __errno(void);
|
||||
#endif
|
||||
|
||||
#define errno (*__errno())
|
||||
|
||||
/**
|
||||
* LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS==1: randomize the local port for the first
|
||||
* local TCP/UDP pcb (default==0). This can prevent creating predictable port
|
||||
* numbers after booting a device.
|
||||
*/
|
||||
|
||||
#define LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS 1
|
||||
#define LWIP_RAND() ((u32_t)bl_rand())
|
||||
|
||||
#ifdef LWIP_NETCONN_DUPLEX_SWITCH
|
||||
#define LWIP_NETCONN_FULLDUPLEX 1
|
||||
#define LWIP_NETCONN_SEM_PER_THREAD 1
|
||||
|
||||
void *sys_thread_sem_get(void);
|
||||
void sys_thread_sem_init(void);
|
||||
void sys_thread_sem_deinit(void);
|
||||
#define LWIP_NETCONN_THREAD_SEM_GET() sys_thread_sem_get()
|
||||
#define LWIP_NETCONN_THREAD_SEM_ALLOC() sys_thread_sem_init()
|
||||
#define LWIP_NETCONN_THREAD_SEM_FREE() sys_thread_sem_deinit()
|
||||
#endif
|
||||
|
||||
#endif /* __LWIPOPTS_H__ */
|
@ -61,6 +61,7 @@ set(lwipcore4_SRCS
|
||||
${LWIP_DIR}/src/core/ipv4/igmp.c
|
||||
${LWIP_DIR}/src/core/ipv4/ip4_frag.c
|
||||
${LWIP_DIR}/src/core/ipv4/ip4.c
|
||||
${LWIP_DIR}/src/core/ipv4/ip4_napt.c
|
||||
${LWIP_DIR}/src/core/ipv4/ip4_addr.c
|
||||
)
|
||||
set(lwipcore6_SRCS
|
||||
|
@ -58,6 +58,7 @@ CORE4FILES=$(LWIPDIR)/core/ipv4/autoip.c \
|
||||
$(LWIPDIR)/core/ipv4/igmp.c \
|
||||
$(LWIPDIR)/core/ipv4/ip4_frag.c \
|
||||
$(LWIPDIR)/core/ipv4/ip4.c \
|
||||
$(LWIPDIR)/core/ipv4/ip4_napt.c \
|
||||
$(LWIPDIR)/core/ipv4/ip4_addr.c
|
||||
|
||||
CORE6FILES=$(LWIPDIR)/core/ipv6/dhcp6.c \
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -46,55 +46,55 @@
|
||||
/** Table to quickly map an lwIP error (err_t) to a socket error
|
||||
* by using -err as an index */
|
||||
static const int err_to_errno_table[] = {
|
||||
0, /* ERR_OK 0 No error, everything OK. */
|
||||
ENOMEM, /* ERR_MEM -1 Out of memory error. */
|
||||
ENOBUFS, /* ERR_BUF -2 Buffer error. */
|
||||
EWOULDBLOCK, /* ERR_TIMEOUT -3 Timeout */
|
||||
EHOSTUNREACH, /* ERR_RTE -4 Routing problem. */
|
||||
EINPROGRESS, /* ERR_INPROGRESS -5 Operation in progress */
|
||||
EINVAL, /* ERR_VAL -6 Illegal value. */
|
||||
EWOULDBLOCK, /* ERR_WOULDBLOCK -7 Operation would block. */
|
||||
EADDRINUSE, /* ERR_USE -8 Address in use. */
|
||||
EALREADY, /* ERR_ALREADY -9 Already connecting. */
|
||||
EISCONN, /* ERR_ISCONN -10 Conn already established.*/
|
||||
ENOTCONN, /* ERR_CONN -11 Not connected. */
|
||||
-1, /* ERR_IF -12 Low-level netif error */
|
||||
ECONNABORTED, /* ERR_ABRT -13 Connection aborted. */
|
||||
ECONNRESET, /* ERR_RST -14 Connection reset. */
|
||||
ENOTCONN, /* ERR_CLSD -15 Connection closed. */
|
||||
EIO /* ERR_ARG -16 Illegal argument. */
|
||||
0, /* ERR_OK 0 No error, everything OK. */
|
||||
ENOMEM, /* ERR_MEM -1 Out of memory error. */
|
||||
ENOBUFS, /* ERR_BUF -2 Buffer error. */
|
||||
EWOULDBLOCK, /* ERR_TIMEOUT -3 Timeout */
|
||||
EHOSTUNREACH, /* ERR_RTE -4 Routing problem. */
|
||||
EINPROGRESS, /* ERR_INPROGRESS -5 Operation in progress */
|
||||
EINVAL, /* ERR_VAL -6 Illegal value. */
|
||||
EWOULDBLOCK, /* ERR_WOULDBLOCK -7 Operation would block. */
|
||||
EADDRINUSE, /* ERR_USE -8 Address in use. */
|
||||
EALREADY, /* ERR_ALREADY -9 Already connecting. */
|
||||
EISCONN, /* ERR_ISCONN -10 Conn already established.*/
|
||||
ENOTCONN, /* ERR_CONN -11 Not connected. */
|
||||
-1, /* ERR_IF -12 Low-level netif error */
|
||||
ECONNABORTED, /* ERR_ABRT -13 Connection aborted. */
|
||||
ECONNRESET, /* ERR_RST -14 Connection reset. */
|
||||
ENOTCONN, /* ERR_CLSD -15 Connection closed. */
|
||||
EIO /* ERR_ARG -16 Illegal argument. */
|
||||
};
|
||||
|
||||
int err_to_errno(err_t err)
|
||||
int
|
||||
err_to_errno(err_t err)
|
||||
{
|
||||
if ((err > 0) || (-err >= (err_t)LWIP_ARRAYSIZE(err_to_errno_table))) {
|
||||
return EIO;
|
||||
}
|
||||
|
||||
return err_to_errno_table[-err];
|
||||
if ((err > 0) || (-err >= (err_t)LWIP_ARRAYSIZE(err_to_errno_table))) {
|
||||
return EIO;
|
||||
}
|
||||
return err_to_errno_table[-err];
|
||||
}
|
||||
#endif /* !NO_SYS */
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
|
||||
static const char *err_strerr[] = {
|
||||
"Ok.", /* ERR_OK 0 */
|
||||
"Out of memory error.", /* ERR_MEM -1 */
|
||||
"Buffer error.", /* ERR_BUF -2 */
|
||||
"Timeout.", /* ERR_TIMEOUT -3 */
|
||||
"Routing problem.", /* ERR_RTE -4 */
|
||||
"Operation in progress.", /* ERR_INPROGRESS -5 */
|
||||
"Illegal value.", /* ERR_VAL -6 */
|
||||
"Operation would block.", /* ERR_WOULDBLOCK -7 */
|
||||
"Address in use.", /* ERR_USE -8 */
|
||||
"Already connecting.", /* ERR_ALREADY -9 */
|
||||
"Already connected.", /* ERR_ISCONN -10 */
|
||||
"Not connected.", /* ERR_CONN -11 */
|
||||
"Low-level netif error.", /* ERR_IF -12 */
|
||||
"Connection aborted.", /* ERR_ABRT -13 */
|
||||
"Connection reset.", /* ERR_RST -14 */
|
||||
"Connection closed.", /* ERR_CLSD -15 */
|
||||
"Illegal argument." /* ERR_ARG -16 */
|
||||
"Ok.", /* ERR_OK 0 */
|
||||
"Out of memory error.", /* ERR_MEM -1 */
|
||||
"Buffer error.", /* ERR_BUF -2 */
|
||||
"Timeout.", /* ERR_TIMEOUT -3 */
|
||||
"Routing problem.", /* ERR_RTE -4 */
|
||||
"Operation in progress.", /* ERR_INPROGRESS -5 */
|
||||
"Illegal value.", /* ERR_VAL -6 */
|
||||
"Operation would block.", /* ERR_WOULDBLOCK -7 */
|
||||
"Address in use.", /* ERR_USE -8 */
|
||||
"Already connecting.", /* ERR_ALREADY -9 */
|
||||
"Already connected.", /* ERR_ISCONN -10 */
|
||||
"Not connected.", /* ERR_CONN -11 */
|
||||
"Low-level netif error.", /* ERR_IF -12 */
|
||||
"Connection aborted.", /* ERR_ABRT -13 */
|
||||
"Connection reset.", /* ERR_RST -14 */
|
||||
"Connection closed.", /* ERR_CLSD -15 */
|
||||
"Illegal argument." /* ERR_ARG -16 */
|
||||
};
|
||||
|
||||
/**
|
||||
@ -103,13 +103,13 @@ static const char *err_strerr[] = {
|
||||
* @param err an lwip internal err_t
|
||||
* @return a string representation for err
|
||||
*/
|
||||
const char *lwip_strerr(err_t err)
|
||||
const char *
|
||||
lwip_strerr(err_t err)
|
||||
{
|
||||
if ((err > 0) || (-err >= (err_t)LWIP_ARRAYSIZE(err_strerr))) {
|
||||
return "Unknown error.";
|
||||
}
|
||||
|
||||
return err_strerr[-err];
|
||||
if ((err > 0) || (-err >= (err_t)LWIP_ARRAYSIZE(err_strerr))) {
|
||||
return "Unknown error.";
|
||||
}
|
||||
return err_strerr[-err];
|
||||
}
|
||||
|
||||
#endif /* LWIP_DEBUG */
|
||||
|
@ -57,24 +57,22 @@
|
||||
* value supplied in ifname, which points to a buffer now containing the interface name.
|
||||
* Otherwise, the function shall return a NULL pointer.
|
||||
*/
|
||||
char *lwip_if_indextoname(unsigned int ifindex, char *ifname)
|
||||
char *
|
||||
lwip_if_indextoname(unsigned int ifindex, char *ifname)
|
||||
{
|
||||
#if LWIP_NETIF_API
|
||||
|
||||
if (ifindex <= 0xff) {
|
||||
err_t err = netifapi_netif_index_to_name((u8_t)ifindex, ifname);
|
||||
|
||||
if (!err && ifname[0] != '\0') {
|
||||
return ifname;
|
||||
}
|
||||
if (ifindex <= 0xff) {
|
||||
err_t err = netifapi_netif_index_to_name((u8_t)ifindex, ifname);
|
||||
if (!err && ifname[0] != '\0') {
|
||||
return ifname;
|
||||
}
|
||||
|
||||
}
|
||||
#else /* LWIP_NETIF_API */
|
||||
LWIP_UNUSED_ARG(ifindex);
|
||||
LWIP_UNUSED_ARG(ifname);
|
||||
LWIP_UNUSED_ARG(ifindex);
|
||||
LWIP_UNUSED_ARG(ifname);
|
||||
#endif /* LWIP_NETIF_API */
|
||||
set_errno(ENXIO);
|
||||
return NULL;
|
||||
set_errno(ENXIO);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,22 +82,21 @@ char *lwip_if_indextoname(unsigned int ifindex, char *ifname)
|
||||
* @return The corresponding index if ifname is the name of an interface;
|
||||
* otherwise, zero.
|
||||
*/
|
||||
unsigned int lwip_if_nametoindex(const char *ifname)
|
||||
unsigned int
|
||||
lwip_if_nametoindex(const char *ifname)
|
||||
{
|
||||
#if LWIP_NETIF_API
|
||||
err_t err;
|
||||
u8_t idx;
|
||||
|
||||
err = netifapi_netif_name_to_index(ifname, &idx);
|
||||
|
||||
if (!err) {
|
||||
return idx;
|
||||
}
|
||||
err_t err;
|
||||
u8_t idx;
|
||||
|
||||
err = netifapi_netif_name_to_index(ifname, &idx);
|
||||
if (!err) {
|
||||
return idx;
|
||||
}
|
||||
#else /* LWIP_NETIF_API */
|
||||
LWIP_UNUSED_ARG(ifname);
|
||||
LWIP_UNUSED_ARG(ifname);
|
||||
#endif /* LWIP_NETIF_API */
|
||||
return 0; /* invalid index */
|
||||
return 0; /* invalid index */
|
||||
}
|
||||
|
||||
#endif /* LWIP_SOCKET */
|
||||
|
@ -60,18 +60,15 @@
|
||||
* NULL on lack of memory
|
||||
*/
|
||||
struct
|
||||
netbuf *
|
||||
netbuf_new(void)
|
||||
netbuf *netbuf_new(void)
|
||||
{
|
||||
struct netbuf *buf;
|
||||
struct netbuf *buf;
|
||||
|
||||
buf = (struct netbuf *)memp_malloc(MEMP_NETBUF);
|
||||
|
||||
if (buf != NULL) {
|
||||
memset(buf, 0, sizeof(struct netbuf));
|
||||
}
|
||||
|
||||
return buf;
|
||||
buf = (struct netbuf *)memp_malloc(MEMP_NETBUF);
|
||||
if (buf != NULL) {
|
||||
memset(buf, 0, sizeof(struct netbuf));
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,16 +77,16 @@ struct
|
||||
*
|
||||
* @param buf pointer to a netbuf allocated by netbuf_new()
|
||||
*/
|
||||
void netbuf_delete(struct netbuf *buf)
|
||||
void
|
||||
netbuf_delete(struct netbuf *buf)
|
||||
{
|
||||
if (buf != NULL) {
|
||||
if (buf->p != NULL) {
|
||||
pbuf_free(buf->p);
|
||||
buf->p = buf->ptr = NULL;
|
||||
}
|
||||
|
||||
memp_free(MEMP_NETBUF, buf);
|
||||
if (buf != NULL) {
|
||||
if (buf->p != NULL) {
|
||||
pbuf_free(buf->p);
|
||||
buf->p = buf->ptr = NULL;
|
||||
}
|
||||
memp_free(MEMP_NETBUF, buf);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -101,25 +98,23 @@ void netbuf_delete(struct netbuf *buf)
|
||||
* @return pointer to the allocated memory
|
||||
* NULL if no memory could be allocated
|
||||
*/
|
||||
void *netbuf_alloc(struct netbuf *buf, u16_t size)
|
||||
void *
|
||||
netbuf_alloc(struct netbuf *buf, u16_t size)
|
||||
{
|
||||
LWIP_ERROR("netbuf_alloc: invalid buf", (buf != NULL), return NULL;);
|
||||
LWIP_ERROR("netbuf_alloc: invalid buf", (buf != NULL), return NULL;);
|
||||
|
||||
/* Deallocate any previously allocated memory. */
|
||||
if (buf->p != NULL) {
|
||||
pbuf_free(buf->p);
|
||||
}
|
||||
|
||||
buf->p = pbuf_alloc(PBUF_TRANSPORT, size, PBUF_RAM);
|
||||
|
||||
if (buf->p == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LWIP_ASSERT("check that first pbuf can hold size",
|
||||
(buf->p->len >= size));
|
||||
buf->ptr = buf->p;
|
||||
return buf->p->payload;
|
||||
/* Deallocate any previously allocated memory. */
|
||||
if (buf->p != NULL) {
|
||||
pbuf_free(buf->p);
|
||||
}
|
||||
buf->p = pbuf_alloc(PBUF_TRANSPORT, size, PBUF_RAM);
|
||||
if (buf->p == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
LWIP_ASSERT("check that first pbuf can hold size",
|
||||
(buf->p->len >= size));
|
||||
buf->ptr = buf->p;
|
||||
return buf->p->payload;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -128,18 +123,17 @@ void *netbuf_alloc(struct netbuf *buf, u16_t size)
|
||||
*
|
||||
* @param buf pointer to the netbuf which contains the packet buffer to free
|
||||
*/
|
||||
void netbuf_free(struct netbuf *buf)
|
||||
void
|
||||
netbuf_free(struct netbuf *buf)
|
||||
{
|
||||
LWIP_ERROR("netbuf_free: invalid buf", (buf != NULL), return;);
|
||||
|
||||
if (buf->p != NULL) {
|
||||
pbuf_free(buf->p);
|
||||
}
|
||||
|
||||
buf->p = buf->ptr = NULL;
|
||||
LWIP_ERROR("netbuf_free: invalid buf", (buf != NULL), return;);
|
||||
if (buf->p != NULL) {
|
||||
pbuf_free(buf->p);
|
||||
}
|
||||
buf->p = buf->ptr = NULL;
|
||||
#if LWIP_CHECKSUM_ON_COPY
|
||||
buf->flags = 0;
|
||||
buf->toport_chksum = 0;
|
||||
buf->flags = 0;
|
||||
buf->toport_chksum = 0;
|
||||
#endif /* LWIP_CHECKSUM_ON_COPY */
|
||||
}
|
||||
|
||||
@ -153,25 +147,22 @@ void netbuf_free(struct netbuf *buf)
|
||||
* @return ERR_OK if data is referenced
|
||||
* ERR_MEM if data couldn't be referenced due to lack of memory
|
||||
*/
|
||||
err_t netbuf_ref(struct netbuf *buf, const void *dataptr, u16_t size)
|
||||
err_t
|
||||
netbuf_ref(struct netbuf *buf, const void *dataptr, u16_t size)
|
||||
{
|
||||
LWIP_ERROR("netbuf_ref: invalid buf", (buf != NULL), return ERR_ARG;);
|
||||
|
||||
if (buf->p != NULL) {
|
||||
pbuf_free(buf->p);
|
||||
}
|
||||
|
||||
buf->p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF);
|
||||
|
||||
if (buf->p == NULL) {
|
||||
buf->ptr = NULL;
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
((struct pbuf_rom *)buf->p)->payload = dataptr;
|
||||
buf->p->len = buf->p->tot_len = size;
|
||||
buf->ptr = buf->p;
|
||||
return ERR_OK;
|
||||
LWIP_ERROR("netbuf_ref: invalid buf", (buf != NULL), return ERR_ARG;);
|
||||
if (buf->p != NULL) {
|
||||
pbuf_free(buf->p);
|
||||
}
|
||||
buf->p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF);
|
||||
if (buf->p == NULL) {
|
||||
buf->ptr = NULL;
|
||||
return ERR_MEM;
|
||||
}
|
||||
((struct pbuf_rom *)buf->p)->payload = dataptr;
|
||||
buf->p->len = buf->p->tot_len = size;
|
||||
buf->ptr = buf->p;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -181,13 +172,14 @@ err_t netbuf_ref(struct netbuf *buf, const void *dataptr, u16_t size)
|
||||
* @param head the first netbuf
|
||||
* @param tail netbuf to chain after head, freed by this function, may not be reference after returning
|
||||
*/
|
||||
void netbuf_chain(struct netbuf *head, struct netbuf *tail)
|
||||
void
|
||||
netbuf_chain(struct netbuf *head, struct netbuf *tail)
|
||||
{
|
||||
LWIP_ERROR("netbuf_chain: invalid head", (head != NULL), return;);
|
||||
LWIP_ERROR("netbuf_chain: invalid tail", (tail != NULL), return;);
|
||||
pbuf_cat(head->p, tail->p);
|
||||
head->ptr = head->p;
|
||||
memp_free(MEMP_NETBUF, tail);
|
||||
LWIP_ERROR("netbuf_chain: invalid head", (head != NULL), return;);
|
||||
LWIP_ERROR("netbuf_chain: invalid tail", (tail != NULL), return;);
|
||||
pbuf_cat(head->p, tail->p);
|
||||
head->ptr = head->p;
|
||||
memp_free(MEMP_NETBUF, tail);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -200,19 +192,19 @@ void netbuf_chain(struct netbuf *head, struct netbuf *tail)
|
||||
* @return ERR_OK if the information was retrieved,
|
||||
* ERR_BUF on error.
|
||||
*/
|
||||
err_t netbuf_data(struct netbuf *buf, void **dataptr, u16_t *len)
|
||||
err_t
|
||||
netbuf_data(struct netbuf *buf, void **dataptr, u16_t *len)
|
||||
{
|
||||
LWIP_ERROR("netbuf_data: invalid buf", (buf != NULL), return ERR_ARG;);
|
||||
LWIP_ERROR("netbuf_data: invalid dataptr", (dataptr != NULL), return ERR_ARG;);
|
||||
LWIP_ERROR("netbuf_data: invalid len", (len != NULL), return ERR_ARG;);
|
||||
LWIP_ERROR("netbuf_data: invalid buf", (buf != NULL), return ERR_ARG;);
|
||||
LWIP_ERROR("netbuf_data: invalid dataptr", (dataptr != NULL), return ERR_ARG;);
|
||||
LWIP_ERROR("netbuf_data: invalid len", (len != NULL), return ERR_ARG;);
|
||||
|
||||
if (buf->ptr == NULL) {
|
||||
return ERR_BUF;
|
||||
}
|
||||
|
||||
*dataptr = buf->ptr->payload;
|
||||
*len = buf->ptr->len;
|
||||
return ERR_OK;
|
||||
if (buf->ptr == NULL) {
|
||||
return ERR_BUF;
|
||||
}
|
||||
*dataptr = buf->ptr->payload;
|
||||
*len = buf->ptr->len;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -226,21 +218,18 @@ err_t netbuf_data(struct netbuf *buf, void **dataptr, u16_t *len)
|
||||
* 1 if moved to the next part but now there is no next part
|
||||
* 0 if moved to the next part and there are still more parts
|
||||
*/
|
||||
s8_t netbuf_next(struct netbuf *buf)
|
||||
s8_t
|
||||
netbuf_next(struct netbuf *buf)
|
||||
{
|
||||
LWIP_ERROR("netbuf_next: invalid buf", (buf != NULL), return -1;);
|
||||
|
||||
if (buf->ptr->next == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
buf->ptr = buf->ptr->next;
|
||||
|
||||
if (buf->ptr->next == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
LWIP_ERROR("netbuf_next: invalid buf", (buf != NULL), return -1;);
|
||||
if (buf->ptr->next == NULL) {
|
||||
return -1;
|
||||
}
|
||||
buf->ptr = buf->ptr->next;
|
||||
if (buf->ptr->next == NULL) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -251,10 +240,11 @@ s8_t netbuf_next(struct netbuf *buf)
|
||||
*
|
||||
* @param buf the netbuf to modify
|
||||
*/
|
||||
void netbuf_first(struct netbuf *buf)
|
||||
void
|
||||
netbuf_first(struct netbuf *buf)
|
||||
{
|
||||
LWIP_ERROR("netbuf_first: invalid buf", (buf != NULL), return;);
|
||||
buf->ptr = buf->p;
|
||||
LWIP_ERROR("netbuf_first: invalid buf", (buf != NULL), return;);
|
||||
buf->ptr = buf->p;
|
||||
}
|
||||
|
||||
#endif /* LWIP_NETCONN */
|
||||
|
@ -51,9 +51,9 @@
|
||||
|
||||
/** helper struct for gethostbyname_r to access the char* buffer */
|
||||
struct gethostbyname_r_helper {
|
||||
ip_addr_t *addr_list[2];
|
||||
ip_addr_t addr;
|
||||
char *aliases;
|
||||
ip_addr_t *addr_list[2];
|
||||
ip_addr_t addr;
|
||||
char *aliases;
|
||||
};
|
||||
|
||||
/** h_errno is exported in netdb.h for access by applications. */
|
||||
@ -86,63 +86,59 @@ int h_errno;
|
||||
struct hostent *
|
||||
lwip_gethostbyname(const char *name)
|
||||
{
|
||||
err_t err;
|
||||
ip_addr_t addr;
|
||||
err_t err;
|
||||
ip_addr_t addr;
|
||||
|
||||
/* buffer variables for lwip_gethostbyname() */
|
||||
HOSTENT_STORAGE struct hostent s_hostent;
|
||||
HOSTENT_STORAGE char *s_aliases;
|
||||
HOSTENT_STORAGE ip_addr_t s_hostent_addr;
|
||||
HOSTENT_STORAGE ip_addr_t *s_phostent_addr[2];
|
||||
HOSTENT_STORAGE char s_hostname[DNS_MAX_NAME_LENGTH + 1];
|
||||
/* buffer variables for lwip_gethostbyname() */
|
||||
HOSTENT_STORAGE struct hostent s_hostent;
|
||||
HOSTENT_STORAGE char *s_aliases;
|
||||
HOSTENT_STORAGE ip_addr_t s_hostent_addr;
|
||||
HOSTENT_STORAGE ip_addr_t *s_phostent_addr[2];
|
||||
HOSTENT_STORAGE char s_hostname[DNS_MAX_NAME_LENGTH + 1];
|
||||
|
||||
/* query host IP address */
|
||||
err = netconn_gethostbyname(name, &addr);
|
||||
/* query host IP address */
|
||||
err = netconn_gethostbyname(name, &addr);
|
||||
if (err != ERR_OK) {
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("lwip_gethostbyname(%s) failed, err=%d\n", name, err));
|
||||
h_errno = HOST_NOT_FOUND;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (err != ERR_OK) {
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("lwip_gethostbyname(%s) failed, err=%d\n", name, err));
|
||||
h_errno = HOST_NOT_FOUND;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* fill hostent */
|
||||
s_hostent_addr = addr;
|
||||
s_phostent_addr[0] = &s_hostent_addr;
|
||||
s_phostent_addr[1] = NULL;
|
||||
strncpy(s_hostname, name, DNS_MAX_NAME_LENGTH);
|
||||
s_hostname[DNS_MAX_NAME_LENGTH] = 0;
|
||||
s_hostent.h_name = s_hostname;
|
||||
s_aliases = NULL;
|
||||
s_hostent.h_aliases = &s_aliases;
|
||||
s_hostent.h_addrtype = AF_INET;
|
||||
s_hostent.h_length = sizeof(ip_addr_t);
|
||||
s_hostent.h_addr_list = (char **)&s_phostent_addr;
|
||||
/* fill hostent */
|
||||
s_hostent_addr = addr;
|
||||
s_phostent_addr[0] = &s_hostent_addr;
|
||||
s_phostent_addr[1] = NULL;
|
||||
strncpy(s_hostname, name, DNS_MAX_NAME_LENGTH);
|
||||
s_hostname[DNS_MAX_NAME_LENGTH] = 0;
|
||||
s_hostent.h_name = s_hostname;
|
||||
s_aliases = NULL;
|
||||
s_hostent.h_aliases = &s_aliases;
|
||||
s_hostent.h_addrtype = AF_INET;
|
||||
s_hostent.h_length = sizeof(ip_addr_t);
|
||||
s_hostent.h_addr_list = (char **)&s_phostent_addr;
|
||||
|
||||
#if DNS_DEBUG
|
||||
/* dump hostent */
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_name == %s\n", s_hostent.h_name));
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_aliases == %p\n", (void *)s_hostent.h_aliases));
|
||||
/* h_aliases are always empty */
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addrtype == %d\n", s_hostent.h_addrtype));
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_length == %d\n", s_hostent.h_length));
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list == %p\n", (void *)s_hostent.h_addr_list));
|
||||
|
||||
if (s_hostent.h_addr_list != NULL) {
|
||||
u8_t idx;
|
||||
|
||||
for (idx = 0; s_hostent.h_addr_list[idx]; idx++) {
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list[%i] == %p\n", idx, s_hostent.h_addr_list[idx]));
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list[%i]-> == %s\n", idx, ipaddr_ntoa((ip_addr_t *)s_hostent.h_addr_list[idx])));
|
||||
}
|
||||
/* dump hostent */
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_name == %s\n", s_hostent.h_name));
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_aliases == %p\n", (void *)s_hostent.h_aliases));
|
||||
/* h_aliases are always empty */
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addrtype == %d\n", s_hostent.h_addrtype));
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_length == %d\n", s_hostent.h_length));
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list == %p\n", (void *)s_hostent.h_addr_list));
|
||||
if (s_hostent.h_addr_list != NULL) {
|
||||
u8_t idx;
|
||||
for (idx = 0; s_hostent.h_addr_list[idx]; idx++) {
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list[%i] == %p\n", idx, s_hostent.h_addr_list[idx]));
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list[%i]-> == %s\n", idx, ipaddr_ntoa((ip_addr_t *)s_hostent.h_addr_list[idx])));
|
||||
}
|
||||
|
||||
}
|
||||
#endif /* DNS_DEBUG */
|
||||
|
||||
#if LWIP_DNS_API_HOSTENT_STORAGE
|
||||
/* this function should return the "per-thread" hostent after copy from s_hostent */
|
||||
return sys_thread_hostent(&s_hostent);
|
||||
/* this function should return the "per-thread" hostent after copy from s_hostent */
|
||||
return sys_thread_hostent(&s_hostent);
|
||||
#else
|
||||
return &s_hostent;
|
||||
return &s_hostent;
|
||||
#endif /* LWIP_DNS_API_HOSTENT_STORAGE */
|
||||
}
|
||||
|
||||
@ -162,74 +158,71 @@ lwip_gethostbyname(const char *name)
|
||||
* @return 0 on success, non-zero on error, additional error information
|
||||
* is stored in *h_errnop instead of h_errno to be thread-safe
|
||||
*/
|
||||
int lwip_gethostbyname_r(const char *name, struct hostent *ret, char *buf,
|
||||
size_t buflen, struct hostent **result, int *h_errnop)
|
||||
int
|
||||
lwip_gethostbyname_r(const char *name, struct hostent *ret, char *buf,
|
||||
size_t buflen, struct hostent **result, int *h_errnop)
|
||||
{
|
||||
err_t err;
|
||||
struct gethostbyname_r_helper *h;
|
||||
char *hostname;
|
||||
size_t namelen;
|
||||
int lh_errno;
|
||||
err_t err;
|
||||
struct gethostbyname_r_helper *h;
|
||||
char *hostname;
|
||||
size_t namelen;
|
||||
int lh_errno;
|
||||
|
||||
if (h_errnop == NULL) {
|
||||
/* ensure h_errnop is never NULL */
|
||||
h_errnop = &lh_errno;
|
||||
}
|
||||
if (h_errnop == NULL) {
|
||||
/* ensure h_errnop is never NULL */
|
||||
h_errnop = &lh_errno;
|
||||
}
|
||||
|
||||
if (result == NULL) {
|
||||
/* not all arguments given */
|
||||
*h_errnop = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if (result == NULL) {
|
||||
/* not all arguments given */
|
||||
*h_errnop = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
/* first thing to do: set *result to nothing */
|
||||
*result = NULL;
|
||||
if ((name == NULL) || (ret == NULL) || (buf == NULL)) {
|
||||
/* not all arguments given */
|
||||
*h_errnop = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* first thing to do: set *result to nothing */
|
||||
*result = NULL;
|
||||
namelen = strlen(name);
|
||||
if (buflen < (sizeof(struct gethostbyname_r_helper) + LWIP_MEM_ALIGN_BUFFER(namelen + 1))) {
|
||||
/* buf can't hold the data needed + a copy of name */
|
||||
*h_errnop = ERANGE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((name == NULL) || (ret == NULL) || (buf == NULL)) {
|
||||
/* not all arguments given */
|
||||
*h_errnop = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
h = (struct gethostbyname_r_helper *)LWIP_MEM_ALIGN(buf);
|
||||
hostname = ((char *)h) + sizeof(struct gethostbyname_r_helper);
|
||||
|
||||
namelen = strlen(name);
|
||||
/* query host IP address */
|
||||
err = netconn_gethostbyname(name, &h->addr);
|
||||
if (err != ERR_OK) {
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("lwip_gethostbyname(%s) failed, err=%d\n", name, err));
|
||||
*h_errnop = HOST_NOT_FOUND;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (buflen < (sizeof(struct gethostbyname_r_helper) + LWIP_MEM_ALIGN_BUFFER(namelen + 1))) {
|
||||
/* buf can't hold the data needed + a copy of name */
|
||||
*h_errnop = ERANGE;
|
||||
return -1;
|
||||
}
|
||||
/* copy the hostname into buf */
|
||||
MEMCPY(hostname, name, namelen);
|
||||
hostname[namelen] = 0;
|
||||
|
||||
h = (struct gethostbyname_r_helper *)LWIP_MEM_ALIGN(buf);
|
||||
hostname = ((char *)h) + sizeof(struct gethostbyname_r_helper);
|
||||
/* fill hostent */
|
||||
h->addr_list[0] = &h->addr;
|
||||
h->addr_list[1] = NULL;
|
||||
h->aliases = NULL;
|
||||
ret->h_name = hostname;
|
||||
ret->h_aliases = &h->aliases;
|
||||
ret->h_addrtype = AF_INET;
|
||||
ret->h_length = sizeof(ip_addr_t);
|
||||
ret->h_addr_list = (char **)&h->addr_list;
|
||||
|
||||
/* query host IP address */
|
||||
err = netconn_gethostbyname(name, &h->addr);
|
||||
/* set result != NULL */
|
||||
*result = ret;
|
||||
|
||||
if (err != ERR_OK) {
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("lwip_gethostbyname(%s) failed, err=%d\n", name, err));
|
||||
*h_errnop = HOST_NOT_FOUND;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* copy the hostname into buf */
|
||||
MEMCPY(hostname, name, namelen);
|
||||
hostname[namelen] = 0;
|
||||
|
||||
/* fill hostent */
|
||||
h->addr_list[0] = &h->addr;
|
||||
h->addr_list[1] = NULL;
|
||||
h->aliases = NULL;
|
||||
ret->h_name = hostname;
|
||||
ret->h_aliases = &h->aliases;
|
||||
ret->h_addrtype = AF_INET;
|
||||
ret->h_length = sizeof(ip_addr_t);
|
||||
ret->h_addr_list = (char **)&h->addr_list;
|
||||
|
||||
/* set result != NULL */
|
||||
*result = ret;
|
||||
|
||||
/* return success */
|
||||
return 0;
|
||||
/* return success */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -239,15 +232,16 @@ int lwip_gethostbyname_r(const char *name, struct hostent *ret, char *buf,
|
||||
*
|
||||
* @param ai struct addrinfo to free
|
||||
*/
|
||||
void lwip_freeaddrinfo(struct addrinfo *ai)
|
||||
void
|
||||
lwip_freeaddrinfo(struct addrinfo *ai)
|
||||
{
|
||||
struct addrinfo *next;
|
||||
struct addrinfo *next;
|
||||
|
||||
while (ai != NULL) {
|
||||
next = ai->ai_next;
|
||||
memp_free(MEMP_NETDB, ai);
|
||||
ai = next;
|
||||
}
|
||||
while (ai != NULL) {
|
||||
next = ai->ai_next;
|
||||
memp_free(MEMP_NETDB, ai);
|
||||
ai = next;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -271,168 +265,150 @@ void lwip_freeaddrinfo(struct addrinfo *ai)
|
||||
*
|
||||
* @todo: implement AI_V4MAPPED, AI_ADDRCONFIG
|
||||
*/
|
||||
int lwip_getaddrinfo(const char *nodename, const char *servname,
|
||||
const struct addrinfo *hints, struct addrinfo **res)
|
||||
int
|
||||
lwip_getaddrinfo(const char *nodename, const char *servname,
|
||||
const struct addrinfo *hints, struct addrinfo **res)
|
||||
{
|
||||
err_t err;
|
||||
ip_addr_t addr;
|
||||
struct addrinfo *ai;
|
||||
struct sockaddr_storage *sa = NULL;
|
||||
int port_nr = 0;
|
||||
size_t total_size;
|
||||
size_t namelen = 0;
|
||||
int ai_family;
|
||||
err_t err;
|
||||
ip_addr_t addr;
|
||||
struct addrinfo *ai;
|
||||
struct sockaddr_storage *sa = NULL;
|
||||
int port_nr = 0;
|
||||
size_t total_size;
|
||||
size_t namelen = 0;
|
||||
int ai_family;
|
||||
|
||||
if (res == NULL) {
|
||||
return EAI_FAIL;
|
||||
if (res == NULL) {
|
||||
return EAI_FAIL;
|
||||
}
|
||||
*res = NULL;
|
||||
if ((nodename == NULL) && (servname == NULL)) {
|
||||
return EAI_NONAME;
|
||||
}
|
||||
|
||||
if (hints != NULL) {
|
||||
ai_family = hints->ai_family;
|
||||
if ((ai_family != AF_UNSPEC)
|
||||
#if LWIP_IPV4
|
||||
&& (ai_family != AF_INET)
|
||||
#endif /* LWIP_IPV4 */
|
||||
#if LWIP_IPV6
|
||||
&& (ai_family != AF_INET6)
|
||||
#endif /* LWIP_IPV6 */
|
||||
) {
|
||||
return EAI_FAMILY;
|
||||
}
|
||||
} else {
|
||||
ai_family = AF_UNSPEC;
|
||||
}
|
||||
|
||||
*res = NULL;
|
||||
if (servname != NULL) {
|
||||
/* service name specified: convert to port number
|
||||
* @todo?: currently, only ASCII integers (port numbers) are supported (AI_NUMERICSERV)! */
|
||||
port_nr = atoi(servname);
|
||||
if ((port_nr <= 0) || (port_nr > 0xffff)) {
|
||||
return EAI_SERVICE;
|
||||
}
|
||||
}
|
||||
|
||||
if ((nodename == NULL) && (servname == NULL)) {
|
||||
if (nodename != NULL) {
|
||||
/* service location specified, try to resolve */
|
||||
if ((hints != NULL) && (hints->ai_flags & AI_NUMERICHOST)) {
|
||||
/* no DNS lookup, just parse for an address string */
|
||||
if (!ipaddr_aton(nodename, &addr)) {
|
||||
return EAI_NONAME;
|
||||
}
|
||||
|
||||
if (hints != NULL) {
|
||||
ai_family = hints->ai_family;
|
||||
|
||||
if ((ai_family != AF_UNSPEC)
|
||||
#if LWIP_IPV4
|
||||
&& (ai_family != AF_INET)
|
||||
#endif /* LWIP_IPV4 */
|
||||
#if LWIP_IPV6
|
||||
&& (ai_family != AF_INET6)
|
||||
#endif /* LWIP_IPV6 */
|
||||
) {
|
||||
return EAI_FAMILY;
|
||||
}
|
||||
} else {
|
||||
ai_family = AF_UNSPEC;
|
||||
}
|
||||
|
||||
if (servname != NULL) {
|
||||
/* service name specified: convert to port number
|
||||
* @todo?: currently, only ASCII integers (port numbers) are supported (AI_NUMERICSERV)! */
|
||||
port_nr = atoi(servname);
|
||||
|
||||
if ((port_nr <= 0) || (port_nr > 0xffff)) {
|
||||
return EAI_SERVICE;
|
||||
}
|
||||
}
|
||||
|
||||
if (nodename != NULL) {
|
||||
/* service location specified, try to resolve */
|
||||
if ((hints != NULL) && (hints->ai_flags & AI_NUMERICHOST)) {
|
||||
/* no DNS lookup, just parse for an address string */
|
||||
if (!ipaddr_aton(nodename, &addr)) {
|
||||
return EAI_NONAME;
|
||||
}
|
||||
|
||||
}
|
||||
#if LWIP_IPV4 && LWIP_IPV6
|
||||
|
||||
if ((IP_IS_V6_VAL(addr) && ai_family == AF_INET) ||
|
||||
(IP_IS_V4_VAL(addr) && ai_family == AF_INET6)) {
|
||||
return EAI_NONAME;
|
||||
}
|
||||
|
||||
if ((IP_IS_V6_VAL(addr) && ai_family == AF_INET) ||
|
||||
(IP_IS_V4_VAL(addr) && ai_family == AF_INET6)) {
|
||||
return EAI_NONAME;
|
||||
}
|
||||
#endif /* LWIP_IPV4 && LWIP_IPV6 */
|
||||
} else {
|
||||
} else {
|
||||
#if LWIP_IPV4 && LWIP_IPV6
|
||||
/* AF_UNSPEC: prefer IPv4 */
|
||||
u8_t type = NETCONN_DNS_IPV4_IPV6;
|
||||
|
||||
if (ai_family == AF_INET) {
|
||||
type = NETCONN_DNS_IPV4;
|
||||
} else if (ai_family == AF_INET6) {
|
||||
type = NETCONN_DNS_IPV6;
|
||||
}
|
||||
|
||||
/* AF_UNSPEC: prefer IPv4 */
|
||||
u8_t type = NETCONN_DNS_IPV4_IPV6;
|
||||
if (ai_family == AF_INET) {
|
||||
type = NETCONN_DNS_IPV4;
|
||||
} else if (ai_family == AF_INET6) {
|
||||
type = NETCONN_DNS_IPV6;
|
||||
}
|
||||
#endif /* LWIP_IPV4 && LWIP_IPV6 */
|
||||
err = netconn_gethostbyname_addrtype(nodename, &addr, type);
|
||||
|
||||
if (err != ERR_OK) {
|
||||
return EAI_FAIL;
|
||||
}
|
||||
}
|
||||
err = netconn_gethostbyname_addrtype(nodename, &addr, type);
|
||||
if (err != ERR_OK) {
|
||||
return EAI_FAIL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* service location specified, use loopback address */
|
||||
if ((hints != NULL) && (hints->ai_flags & AI_PASSIVE)) {
|
||||
ip_addr_set_any_val(ai_family == AF_INET6, addr);
|
||||
} else {
|
||||
/* service location specified, use loopback address */
|
||||
if ((hints != NULL) && (hints->ai_flags & AI_PASSIVE)) {
|
||||
ip_addr_set_any_val(ai_family == AF_INET6, addr);
|
||||
} else {
|
||||
ip_addr_set_loopback_val(ai_family == AF_INET6, addr);
|
||||
}
|
||||
ip_addr_set_loopback_val(ai_family == AF_INET6, addr);
|
||||
}
|
||||
}
|
||||
|
||||
total_size = sizeof(struct addrinfo) + sizeof(struct sockaddr_storage);
|
||||
|
||||
if (nodename != NULL) {
|
||||
namelen = strlen(nodename);
|
||||
|
||||
if (namelen > DNS_MAX_NAME_LENGTH) {
|
||||
/* invalid name length */
|
||||
return EAI_FAIL;
|
||||
}
|
||||
|
||||
LWIP_ASSERT("namelen is too long", total_size + namelen + 1 > total_size);
|
||||
total_size += namelen + 1;
|
||||
total_size = sizeof(struct addrinfo) + sizeof(struct sockaddr_storage);
|
||||
if (nodename != NULL) {
|
||||
namelen = strlen(nodename);
|
||||
if (namelen > DNS_MAX_NAME_LENGTH) {
|
||||
/* invalid name length */
|
||||
return EAI_FAIL;
|
||||
}
|
||||
|
||||
/* If this fails, please report to lwip-devel! :-) */
|
||||
LWIP_ASSERT("total_size <= NETDB_ELEM_SIZE: please report this!",
|
||||
total_size <= NETDB_ELEM_SIZE);
|
||||
ai = (struct addrinfo *)memp_malloc(MEMP_NETDB);
|
||||
|
||||
if (ai == NULL) {
|
||||
return EAI_MEMORY;
|
||||
}
|
||||
|
||||
memset(ai, 0, total_size);
|
||||
/* cast through void* to get rid of alignment warnings */
|
||||
sa = (struct sockaddr_storage *)(void *)((u8_t *)ai + sizeof(struct addrinfo));
|
||||
|
||||
if (IP_IS_V6_VAL(addr)) {
|
||||
LWIP_ASSERT("namelen is too long", total_size + namelen + 1 > total_size);
|
||||
total_size += namelen + 1;
|
||||
}
|
||||
/* If this fails, please report to lwip-devel! :-) */
|
||||
LWIP_ASSERT("total_size <= NETDB_ELEM_SIZE: please report this!",
|
||||
total_size <= NETDB_ELEM_SIZE);
|
||||
ai = (struct addrinfo *)memp_malloc(MEMP_NETDB);
|
||||
if (ai == NULL) {
|
||||
return EAI_MEMORY;
|
||||
}
|
||||
memset(ai, 0, total_size);
|
||||
/* cast through void* to get rid of alignment warnings */
|
||||
sa = (struct sockaddr_storage *)(void *)((u8_t *)ai + sizeof(struct addrinfo));
|
||||
if (IP_IS_V6_VAL(addr)) {
|
||||
#if LWIP_IPV6
|
||||
struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)sa;
|
||||
/* set up sockaddr */
|
||||
inet6_addr_from_ip6addr(&sa6->sin6_addr, ip_2_ip6(&addr));
|
||||
sa6->sin6_family = AF_INET6;
|
||||
sa6->sin6_len = sizeof(struct sockaddr_in6);
|
||||
sa6->sin6_port = lwip_htons((u16_t)port_nr);
|
||||
sa6->sin6_scope_id = ip6_addr_zone(ip_2_ip6(&addr));
|
||||
ai->ai_family = AF_INET6;
|
||||
struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)sa;
|
||||
/* set up sockaddr */
|
||||
inet6_addr_from_ip6addr(&sa6->sin6_addr, ip_2_ip6(&addr));
|
||||
sa6->sin6_family = AF_INET6;
|
||||
sa6->sin6_len = sizeof(struct sockaddr_in6);
|
||||
sa6->sin6_port = lwip_htons((u16_t)port_nr);
|
||||
sa6->sin6_scope_id = ip6_addr_zone(ip_2_ip6(&addr));
|
||||
ai->ai_family = AF_INET6;
|
||||
#endif /* LWIP_IPV6 */
|
||||
} else {
|
||||
} else {
|
||||
#if LWIP_IPV4
|
||||
struct sockaddr_in *sa4 = (struct sockaddr_in *)sa;
|
||||
/* set up sockaddr */
|
||||
inet_addr_from_ip4addr(&sa4->sin_addr, ip_2_ip4(&addr));
|
||||
sa4->sin_family = AF_INET;
|
||||
sa4->sin_len = sizeof(struct sockaddr_in);
|
||||
sa4->sin_port = lwip_htons((u16_t)port_nr);
|
||||
ai->ai_family = AF_INET;
|
||||
struct sockaddr_in *sa4 = (struct sockaddr_in *)sa;
|
||||
/* set up sockaddr */
|
||||
inet_addr_from_ip4addr(&sa4->sin_addr, ip_2_ip4(&addr));
|
||||
sa4->sin_family = AF_INET;
|
||||
sa4->sin_len = sizeof(struct sockaddr_in);
|
||||
sa4->sin_port = lwip_htons((u16_t)port_nr);
|
||||
ai->ai_family = AF_INET;
|
||||
#endif /* LWIP_IPV4 */
|
||||
}
|
||||
}
|
||||
|
||||
/* set up addrinfo */
|
||||
if (hints != NULL) {
|
||||
/* copy socktype & protocol from hints if specified */
|
||||
ai->ai_socktype = hints->ai_socktype;
|
||||
ai->ai_protocol = hints->ai_protocol;
|
||||
}
|
||||
/* set up addrinfo */
|
||||
if (hints != NULL) {
|
||||
/* copy socktype & protocol from hints if specified */
|
||||
ai->ai_socktype = hints->ai_socktype;
|
||||
ai->ai_protocol = hints->ai_protocol;
|
||||
}
|
||||
if (nodename != NULL) {
|
||||
/* copy nodename to canonname if specified */
|
||||
ai->ai_canonname = ((char *)ai + sizeof(struct addrinfo) + sizeof(struct sockaddr_storage));
|
||||
MEMCPY(ai->ai_canonname, nodename, namelen);
|
||||
ai->ai_canonname[namelen] = 0;
|
||||
}
|
||||
ai->ai_addrlen = sizeof(struct sockaddr_storage);
|
||||
ai->ai_addr = (struct sockaddr *)sa;
|
||||
|
||||
if (nodename != NULL) {
|
||||
/* copy nodename to canonname if specified */
|
||||
ai->ai_canonname = ((char *)ai + sizeof(struct addrinfo) + sizeof(struct sockaddr_storage));
|
||||
MEMCPY(ai->ai_canonname, nodename, namelen);
|
||||
ai->ai_canonname[namelen] = 0;
|
||||
}
|
||||
*res = ai;
|
||||
|
||||
ai->ai_addrlen = sizeof(struct sockaddr_storage);
|
||||
ai->ai_addr = (struct sockaddr *)sa;
|
||||
|
||||
*res = ai;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* LWIP_DNS && LWIP_SOCKET */
|
||||
|
@ -49,99 +49,103 @@
|
||||
|
||||
#include <string.h> /* strncpy */
|
||||
|
||||
#define NETIFAPI_VAR_REF(name) API_VAR_REF(name)
|
||||
#define NETIFAPI_VAR_DECLARE(name) API_VAR_DECLARE(struct netifapi_msg, name)
|
||||
#define NETIFAPI_VAR_ALLOC(name) API_VAR_ALLOC(struct netifapi_msg, MEMP_NETIFAPI_MSG, name, ERR_MEM)
|
||||
#define NETIFAPI_VAR_FREE(name) API_VAR_FREE(MEMP_NETIFAPI_MSG, name)
|
||||
#define NETIFAPI_VAR_REF(name) API_VAR_REF(name)
|
||||
#define NETIFAPI_VAR_DECLARE(name) API_VAR_DECLARE(struct netifapi_msg, name)
|
||||
#define NETIFAPI_VAR_ALLOC(name) API_VAR_ALLOC(struct netifapi_msg, MEMP_NETIFAPI_MSG, name, ERR_MEM)
|
||||
#define NETIFAPI_VAR_FREE(name) API_VAR_FREE(MEMP_NETIFAPI_MSG, name)
|
||||
|
||||
/**
|
||||
* Call netif_add() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t netifapi_do_netif_add(struct tcpip_api_call_data *m)
|
||||
static err_t
|
||||
netifapi_do_netif_add(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct netifapi_msg */
|
||||
struct netifapi_msg *msg = (struct netifapi_msg *)(void *)m;
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct netifapi_msg */
|
||||
struct netifapi_msg *msg = (struct netifapi_msg *)(void *)m;
|
||||
|
||||
if (!netif_add(msg->netif,
|
||||
if (!netif_add( msg->netif,
|
||||
#if LWIP_IPV4
|
||||
API_EXPR_REF(msg->msg.add.ipaddr),
|
||||
API_EXPR_REF(msg->msg.add.netmask),
|
||||
API_EXPR_REF(msg->msg.add.gw),
|
||||
API_EXPR_REF(msg->msg.add.ipaddr),
|
||||
API_EXPR_REF(msg->msg.add.netmask),
|
||||
API_EXPR_REF(msg->msg.add.gw),
|
||||
#endif /* LWIP_IPV4 */
|
||||
msg->msg.add.state,
|
||||
msg->msg.add.init,
|
||||
msg->msg.add.input)) {
|
||||
return ERR_IF;
|
||||
} else {
|
||||
return ERR_OK;
|
||||
}
|
||||
msg->msg.add.state,
|
||||
msg->msg.add.init,
|
||||
msg->msg.add.input)) {
|
||||
return ERR_IF;
|
||||
} else {
|
||||
return ERR_OK;
|
||||
}
|
||||
}
|
||||
|
||||
#if LWIP_IPV4
|
||||
/**
|
||||
* Call netif_set_addr() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t netifapi_do_netif_set_addr(struct tcpip_api_call_data *m)
|
||||
static err_t
|
||||
netifapi_do_netif_set_addr(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct netifapi_msg */
|
||||
struct netifapi_msg *msg = (struct netifapi_msg *)(void *)m;
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct netifapi_msg */
|
||||
struct netifapi_msg *msg = (struct netifapi_msg *)(void *)m;
|
||||
|
||||
netif_set_addr(msg->netif,
|
||||
API_EXPR_REF(msg->msg.add.ipaddr),
|
||||
API_EXPR_REF(msg->msg.add.netmask),
|
||||
API_EXPR_REF(msg->msg.add.gw));
|
||||
return ERR_OK;
|
||||
netif_set_addr( msg->netif,
|
||||
API_EXPR_REF(msg->msg.add.ipaddr),
|
||||
API_EXPR_REF(msg->msg.add.netmask),
|
||||
API_EXPR_REF(msg->msg.add.gw));
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif /* LWIP_IPV4 */
|
||||
|
||||
/**
|
||||
* Call netif_name_to_index() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t netifapi_do_name_to_index(struct tcpip_api_call_data *m)
|
||||
static err_t
|
||||
netifapi_do_name_to_index(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct netifapi_msg */
|
||||
struct netifapi_msg *msg = (struct netifapi_msg *)(void *)m;
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct netifapi_msg */
|
||||
struct netifapi_msg *msg = (struct netifapi_msg *)(void *)m;
|
||||
|
||||
msg->msg.ifs.index = netif_name_to_index(msg->msg.ifs.name);
|
||||
return ERR_OK;
|
||||
msg->msg.ifs.index = netif_name_to_index(msg->msg.ifs.name);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call netif_index_to_name() inside the tcpip_thread context.
|
||||
*/
|
||||
static err_t netifapi_do_index_to_name(struct tcpip_api_call_data *m)
|
||||
static err_t
|
||||
netifapi_do_index_to_name(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct netifapi_msg */
|
||||
struct netifapi_msg *msg = (struct netifapi_msg *)(void *)m;
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct netifapi_msg */
|
||||
struct netifapi_msg *msg = (struct netifapi_msg *)(void *)m;
|
||||
|
||||
if (!netif_index_to_name(msg->msg.ifs.index, msg->msg.ifs.name)) {
|
||||
/* return failure via empty name */
|
||||
msg->msg.ifs.name[0] = '\0';
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
if (!netif_index_to_name(msg->msg.ifs.index, msg->msg.ifs.name)) {
|
||||
/* return failure via empty name */
|
||||
msg->msg.ifs.name[0] = '\0';
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the "errtfunc" (or the "voidfunc" if "errtfunc" is NULL) inside the
|
||||
* tcpip_thread context.
|
||||
*/
|
||||
static err_t netifapi_do_netif_common(struct tcpip_api_call_data *m)
|
||||
static err_t
|
||||
netifapi_do_netif_common(struct tcpip_api_call_data *m)
|
||||
{
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct netifapi_msg */
|
||||
struct netifapi_msg *msg = (struct netifapi_msg *)(void *)m;
|
||||
/* cast through void* to silence alignment warnings.
|
||||
* We know it works because the structs have been instantiated as struct netifapi_msg */
|
||||
struct netifapi_msg *msg = (struct netifapi_msg *)(void *)m;
|
||||
|
||||
if (msg->msg.common.errtfunc != NULL) {
|
||||
return msg->msg.common.errtfunc(msg->netif);
|
||||
} else {
|
||||
msg->msg.common.voidfunc(msg->netif);
|
||||
return ERR_OK;
|
||||
}
|
||||
if (msg->msg.common.errtfunc != NULL) {
|
||||
return msg->msg.common.errtfunc(msg->netif);
|
||||
} else {
|
||||
msg->msg.common.voidfunc(msg->netif);
|
||||
return ERR_OK;
|
||||
}
|
||||
}
|
||||
|
||||
#if LWIP_ARP && LWIP_IPV4
|
||||
@ -155,25 +159,26 @@ static err_t netifapi_do_netif_common(struct tcpip_api_call_data *m)
|
||||
* @param type type of ARP cache entry
|
||||
* @return ERR_OK: entry added/updated, else error from err_t
|
||||
*/
|
||||
err_t netifapi_arp_add(const ip4_addr_t *ipaddr, struct eth_addr *ethaddr, enum netifapi_arp_entry type)
|
||||
err_t
|
||||
netifapi_arp_add(const ip4_addr_t *ipaddr, struct eth_addr *ethaddr, enum netifapi_arp_entry type)
|
||||
{
|
||||
err_t err;
|
||||
err_t err;
|
||||
|
||||
/* We only support permanent entries currently */
|
||||
LWIP_UNUSED_ARG(type);
|
||||
/* We only support permanent entries currently */
|
||||
LWIP_UNUSED_ARG(type);
|
||||
|
||||
#if ETHARP_SUPPORT_STATIC_ENTRIES && LWIP_TCPIP_CORE_LOCKING
|
||||
LOCK_TCPIP_CORE();
|
||||
err = etharp_add_static_entry(ipaddr, ethaddr);
|
||||
UNLOCK_TCPIP_CORE();
|
||||
LOCK_TCPIP_CORE();
|
||||
err = etharp_add_static_entry(ipaddr, ethaddr);
|
||||
UNLOCK_TCPIP_CORE();
|
||||
#else
|
||||
/* @todo add new vars to struct netifapi_msg and create a 'do' func */
|
||||
LWIP_UNUSED_ARG(ipaddr);
|
||||
LWIP_UNUSED_ARG(ethaddr);
|
||||
err = ERR_VAL;
|
||||
/* @todo add new vars to struct netifapi_msg and create a 'do' func */
|
||||
LWIP_UNUSED_ARG(ipaddr);
|
||||
LWIP_UNUSED_ARG(ethaddr);
|
||||
err = ERR_VAL;
|
||||
#endif /* ETHARP_SUPPORT_STATIC_ENTRIES && LWIP_TCPIP_CORE_LOCKING */
|
||||
|
||||
return err;
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -184,24 +189,25 @@ err_t netifapi_arp_add(const ip4_addr_t *ipaddr, struct eth_addr *ethaddr, enum
|
||||
* @param type type of ARP cache entry
|
||||
* @return ERR_OK: entry removed, else error from err_t
|
||||
*/
|
||||
err_t netifapi_arp_remove(const ip4_addr_t *ipaddr, enum netifapi_arp_entry type)
|
||||
err_t
|
||||
netifapi_arp_remove(const ip4_addr_t *ipaddr, enum netifapi_arp_entry type)
|
||||
{
|
||||
err_t err;
|
||||
err_t err;
|
||||
|
||||
/* We only support permanent entries currently */
|
||||
LWIP_UNUSED_ARG(type);
|
||||
/* We only support permanent entries currently */
|
||||
LWIP_UNUSED_ARG(type);
|
||||
|
||||
#if ETHARP_SUPPORT_STATIC_ENTRIES && LWIP_TCPIP_CORE_LOCKING
|
||||
LOCK_TCPIP_CORE();
|
||||
err = etharp_remove_static_entry(ipaddr);
|
||||
UNLOCK_TCPIP_CORE();
|
||||
LOCK_TCPIP_CORE();
|
||||
err = etharp_remove_static_entry(ipaddr);
|
||||
UNLOCK_TCPIP_CORE();
|
||||
#else
|
||||
/* @todo add new vars to struct netifapi_msg and create a 'do' func */
|
||||
LWIP_UNUSED_ARG(ipaddr);
|
||||
err = ERR_VAL;
|
||||
/* @todo add new vars to struct netifapi_msg and create a 'do' func */
|
||||
LWIP_UNUSED_ARG(ipaddr);
|
||||
err = ERR_VAL;
|
||||
#endif /* ETHARP_SUPPORT_STATIC_ENTRIES && LWIP_TCPIP_CORE_LOCKING */
|
||||
|
||||
return err;
|
||||
return err;
|
||||
}
|
||||
#endif /* LWIP_ARP && LWIP_IPV4 */
|
||||
|
||||
@ -212,44 +218,41 @@ err_t netifapi_arp_remove(const ip4_addr_t *ipaddr, enum netifapi_arp_entry type
|
||||
*
|
||||
* @note for params @see netif_add()
|
||||
*/
|
||||
err_t netifapi_netif_add(struct netif *netif,
|
||||
err_t
|
||||
netifapi_netif_add(struct netif *netif,
|
||||
#if LWIP_IPV4
|
||||
const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw,
|
||||
const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw,
|
||||
#endif /* LWIP_IPV4 */
|
||||
void *state, netif_init_fn init, netif_input_fn input)
|
||||
void *state, netif_init_fn init, netif_input_fn input)
|
||||
{
|
||||
err_t err;
|
||||
NETIFAPI_VAR_DECLARE(msg);
|
||||
NETIFAPI_VAR_ALLOC(msg);
|
||||
err_t err;
|
||||
NETIFAPI_VAR_DECLARE(msg);
|
||||
NETIFAPI_VAR_ALLOC(msg);
|
||||
|
||||
#if LWIP_IPV4
|
||||
|
||||
if (ipaddr == NULL) {
|
||||
ipaddr = IP4_ADDR_ANY4;
|
||||
}
|
||||
|
||||
if (netmask == NULL) {
|
||||
netmask = IP4_ADDR_ANY4;
|
||||
}
|
||||
|
||||
if (gw == NULL) {
|
||||
gw = IP4_ADDR_ANY4;
|
||||
}
|
||||
|
||||
if (ipaddr == NULL) {
|
||||
ipaddr = IP4_ADDR_ANY4;
|
||||
}
|
||||
if (netmask == NULL) {
|
||||
netmask = IP4_ADDR_ANY4;
|
||||
}
|
||||
if (gw == NULL) {
|
||||
gw = IP4_ADDR_ANY4;
|
||||
}
|
||||
#endif /* LWIP_IPV4 */
|
||||
|
||||
NETIFAPI_VAR_REF(msg).netif = netif;
|
||||
NETIFAPI_VAR_REF(msg).netif = netif;
|
||||
#if LWIP_IPV4
|
||||
NETIFAPI_VAR_REF(msg).msg.add.ipaddr = NETIFAPI_VAR_REF(ipaddr);
|
||||
NETIFAPI_VAR_REF(msg).msg.add.netmask = NETIFAPI_VAR_REF(netmask);
|
||||
NETIFAPI_VAR_REF(msg).msg.add.gw = NETIFAPI_VAR_REF(gw);
|
||||
NETIFAPI_VAR_REF(msg).msg.add.ipaddr = NETIFAPI_VAR_REF(ipaddr);
|
||||
NETIFAPI_VAR_REF(msg).msg.add.netmask = NETIFAPI_VAR_REF(netmask);
|
||||
NETIFAPI_VAR_REF(msg).msg.add.gw = NETIFAPI_VAR_REF(gw);
|
||||
#endif /* LWIP_IPV4 */
|
||||
NETIFAPI_VAR_REF(msg).msg.add.state = state;
|
||||
NETIFAPI_VAR_REF(msg).msg.add.init = init;
|
||||
NETIFAPI_VAR_REF(msg).msg.add.input = input;
|
||||
err = tcpip_api_call(netifapi_do_netif_add, &API_VAR_REF(msg).call);
|
||||
NETIFAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
NETIFAPI_VAR_REF(msg).msg.add.state = state;
|
||||
NETIFAPI_VAR_REF(msg).msg.add.init = init;
|
||||
NETIFAPI_VAR_REF(msg).msg.add.input = input;
|
||||
err = tcpip_api_call(netifapi_do_netif_add, &API_VAR_REF(msg).call);
|
||||
NETIFAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
}
|
||||
|
||||
#if LWIP_IPV4
|
||||
@ -260,34 +263,33 @@ err_t netifapi_netif_add(struct netif *netif,
|
||||
*
|
||||
* @note for params @see netif_set_addr()
|
||||
*/
|
||||
err_t netifapi_netif_set_addr(struct netif *netif,
|
||||
const ip4_addr_t *ipaddr,
|
||||
const ip4_addr_t *netmask,
|
||||
const ip4_addr_t *gw)
|
||||
err_t
|
||||
netifapi_netif_set_addr(struct netif *netif,
|
||||
const ip4_addr_t *ipaddr,
|
||||
const ip4_addr_t *netmask,
|
||||
const ip4_addr_t *gw)
|
||||
{
|
||||
err_t err;
|
||||
NETIFAPI_VAR_DECLARE(msg);
|
||||
NETIFAPI_VAR_ALLOC(msg);
|
||||
err_t err;
|
||||
NETIFAPI_VAR_DECLARE(msg);
|
||||
NETIFAPI_VAR_ALLOC(msg);
|
||||
|
||||
if (ipaddr == NULL) {
|
||||
ipaddr = IP4_ADDR_ANY4;
|
||||
}
|
||||
if (ipaddr == NULL) {
|
||||
ipaddr = IP4_ADDR_ANY4;
|
||||
}
|
||||
if (netmask == NULL) {
|
||||
netmask = IP4_ADDR_ANY4;
|
||||
}
|
||||
if (gw == NULL) {
|
||||
gw = IP4_ADDR_ANY4;
|
||||
}
|
||||
|
||||
if (netmask == NULL) {
|
||||
netmask = IP4_ADDR_ANY4;
|
||||
}
|
||||
|
||||
if (gw == NULL) {
|
||||
gw = IP4_ADDR_ANY4;
|
||||
}
|
||||
|
||||
NETIFAPI_VAR_REF(msg).netif = netif;
|
||||
NETIFAPI_VAR_REF(msg).msg.add.ipaddr = NETIFAPI_VAR_REF(ipaddr);
|
||||
NETIFAPI_VAR_REF(msg).msg.add.netmask = NETIFAPI_VAR_REF(netmask);
|
||||
NETIFAPI_VAR_REF(msg).msg.add.gw = NETIFAPI_VAR_REF(gw);
|
||||
err = tcpip_api_call(netifapi_do_netif_set_addr, &API_VAR_REF(msg).call);
|
||||
NETIFAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
NETIFAPI_VAR_REF(msg).netif = netif;
|
||||
NETIFAPI_VAR_REF(msg).msg.add.ipaddr = NETIFAPI_VAR_REF(ipaddr);
|
||||
NETIFAPI_VAR_REF(msg).msg.add.netmask = NETIFAPI_VAR_REF(netmask);
|
||||
NETIFAPI_VAR_REF(msg).msg.add.gw = NETIFAPI_VAR_REF(gw);
|
||||
err = tcpip_api_call(netifapi_do_netif_set_addr, &API_VAR_REF(msg).call);
|
||||
NETIFAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
}
|
||||
#endif /* LWIP_IPV4 */
|
||||
|
||||
@ -297,19 +299,20 @@ err_t netifapi_netif_set_addr(struct netif *netif,
|
||||
*
|
||||
* @note use only for functions where there is only "netif" parameter.
|
||||
*/
|
||||
err_t netifapi_netif_common(struct netif *netif, netifapi_void_fn voidfunc,
|
||||
netifapi_errt_fn errtfunc)
|
||||
err_t
|
||||
netifapi_netif_common(struct netif *netif, netifapi_void_fn voidfunc,
|
||||
netifapi_errt_fn errtfunc)
|
||||
{
|
||||
err_t err;
|
||||
NETIFAPI_VAR_DECLARE(msg);
|
||||
NETIFAPI_VAR_ALLOC(msg);
|
||||
err_t err;
|
||||
NETIFAPI_VAR_DECLARE(msg);
|
||||
NETIFAPI_VAR_ALLOC(msg);
|
||||
|
||||
NETIFAPI_VAR_REF(msg).netif = netif;
|
||||
NETIFAPI_VAR_REF(msg).msg.common.voidfunc = voidfunc;
|
||||
NETIFAPI_VAR_REF(msg).msg.common.errtfunc = errtfunc;
|
||||
err = tcpip_api_call(netifapi_do_netif_common, &API_VAR_REF(msg).call);
|
||||
NETIFAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
NETIFAPI_VAR_REF(msg).netif = netif;
|
||||
NETIFAPI_VAR_REF(msg).msg.common.voidfunc = voidfunc;
|
||||
NETIFAPI_VAR_REF(msg).msg.common.errtfunc = errtfunc;
|
||||
err = tcpip_api_call(netifapi_do_netif_common, &API_VAR_REF(msg).call);
|
||||
NETIFAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -320,28 +323,27 @@ err_t netifapi_netif_common(struct netif *netif, netifapi_void_fn voidfunc,
|
||||
* @param name the interface name of the netif
|
||||
* @param idx output index of the found netif
|
||||
*/
|
||||
err_t netifapi_netif_name_to_index(const char *name, u8_t *idx)
|
||||
err_t
|
||||
netifapi_netif_name_to_index(const char *name, u8_t *idx)
|
||||
{
|
||||
err_t err;
|
||||
NETIFAPI_VAR_DECLARE(msg);
|
||||
NETIFAPI_VAR_ALLOC(msg);
|
||||
err_t err;
|
||||
NETIFAPI_VAR_DECLARE(msg);
|
||||
NETIFAPI_VAR_ALLOC(msg);
|
||||
|
||||
*idx = 0;
|
||||
*idx = 0;
|
||||
|
||||
#if LWIP_MPU_COMPATIBLE
|
||||
strncpy(NETIFAPI_VAR_REF(msg).msg.ifs.name, name, NETIF_NAMESIZE - 1);
|
||||
NETIFAPI_VAR_REF(msg).msg.ifs.name[NETIF_NAMESIZE - 1] = '\0';
|
||||
strncpy(NETIFAPI_VAR_REF(msg).msg.ifs.name, name, NETIF_NAMESIZE - 1);
|
||||
NETIFAPI_VAR_REF(msg).msg.ifs.name[NETIF_NAMESIZE - 1] = '\0';
|
||||
#else
|
||||
NETIFAPI_VAR_REF(msg).msg.ifs.name = LWIP_CONST_CAST(char *, name);
|
||||
NETIFAPI_VAR_REF(msg).msg.ifs.name = LWIP_CONST_CAST(char *, name);
|
||||
#endif /* LWIP_MPU_COMPATIBLE */
|
||||
err = tcpip_api_call(netifapi_do_name_to_index, &API_VAR_REF(msg).call);
|
||||
|
||||
if (!err) {
|
||||
*idx = NETIFAPI_VAR_REF(msg).msg.ifs.index;
|
||||
}
|
||||
|
||||
NETIFAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
err = tcpip_api_call(netifapi_do_name_to_index, &API_VAR_REF(msg).call);
|
||||
if (!err) {
|
||||
*idx = NETIFAPI_VAR_REF(msg).msg.ifs.index;
|
||||
}
|
||||
NETIFAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -353,27 +355,26 @@ err_t netifapi_netif_name_to_index(const char *name, u8_t *idx)
|
||||
* @param name output name of the found netif, empty '\0' string if netif not found.
|
||||
* name should be of at least NETIF_NAMESIZE bytes
|
||||
*/
|
||||
err_t netifapi_netif_index_to_name(u8_t idx, char *name)
|
||||
err_t
|
||||
netifapi_netif_index_to_name(u8_t idx, char *name)
|
||||
{
|
||||
err_t err;
|
||||
NETIFAPI_VAR_DECLARE(msg);
|
||||
NETIFAPI_VAR_ALLOC(msg);
|
||||
err_t err;
|
||||
NETIFAPI_VAR_DECLARE(msg);
|
||||
NETIFAPI_VAR_ALLOC(msg);
|
||||
|
||||
NETIFAPI_VAR_REF(msg).msg.ifs.index = idx;
|
||||
NETIFAPI_VAR_REF(msg).msg.ifs.index = idx;
|
||||
#if !LWIP_MPU_COMPATIBLE
|
||||
NETIFAPI_VAR_REF(msg).msg.ifs.name = name;
|
||||
NETIFAPI_VAR_REF(msg).msg.ifs.name = name;
|
||||
#endif /* LWIP_MPU_COMPATIBLE */
|
||||
err = tcpip_api_call(netifapi_do_index_to_name, &API_VAR_REF(msg).call);
|
||||
err = tcpip_api_call(netifapi_do_index_to_name, &API_VAR_REF(msg).call);
|
||||
#if LWIP_MPU_COMPATIBLE
|
||||
|
||||
if (!err) {
|
||||
strncpy(name, NETIFAPI_VAR_REF(msg).msg.ifs.name, NETIF_NAMESIZE - 1);
|
||||
name[NETIF_NAMESIZE - 1] = '\0';
|
||||
}
|
||||
|
||||
if (!err) {
|
||||
strncpy(name, NETIFAPI_VAR_REF(msg).msg.ifs.name, NETIF_NAMESIZE - 1);
|
||||
name[NETIF_NAMESIZE - 1] = '\0';
|
||||
}
|
||||
#endif /* LWIP_MPU_COMPATIBLE */
|
||||
NETIFAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
NETIFAPI_VAR_FREE(msg);
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif /* LWIP_NETIF_API */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -36,6 +36,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "lwip/opt.h"
|
||||
|
||||
#if !NO_SYS /* don't build if not configured for use in lwipopts.h */
|
||||
@ -80,37 +81,36 @@ static void tcpip_thread_handle_msg(struct tcpip_msg *msg);
|
||||
* @param mbox the mbox to fetch the message from
|
||||
* @param msg the place to store the message
|
||||
*/
|
||||
static void tcpip_timeouts_mbox_fetch(sys_mbox_t *mbox, void **msg)
|
||||
static void
|
||||
tcpip_timeouts_mbox_fetch(sys_mbox_t *mbox, void **msg)
|
||||
{
|
||||
u32_t sleeptime, res;
|
||||
u32_t sleeptime, res;
|
||||
|
||||
again:
|
||||
LWIP_ASSERT_CORE_LOCKED();
|
||||
|
||||
sleeptime = sys_timeouts_sleeptime();
|
||||
|
||||
if (sleeptime == SYS_TIMEOUTS_SLEEPTIME_INFINITE) {
|
||||
UNLOCK_TCPIP_CORE();
|
||||
sys_arch_mbox_fetch(mbox, msg, 0);
|
||||
LOCK_TCPIP_CORE();
|
||||
return;
|
||||
} else if (sleeptime == 0) {
|
||||
sys_check_timeouts();
|
||||
/* We try again to fetch a message from the mbox. */
|
||||
goto again;
|
||||
}
|
||||
LWIP_ASSERT_CORE_LOCKED();
|
||||
|
||||
sleeptime = sys_timeouts_sleeptime();
|
||||
if (sleeptime == SYS_TIMEOUTS_SLEEPTIME_INFINITE) {
|
||||
UNLOCK_TCPIP_CORE();
|
||||
res = sys_arch_mbox_fetch(mbox, msg, sleeptime);
|
||||
sys_arch_mbox_fetch(mbox, msg, 0);
|
||||
LOCK_TCPIP_CORE();
|
||||
return;
|
||||
} else if (sleeptime == 0) {
|
||||
sys_check_timeouts();
|
||||
/* We try again to fetch a message from the mbox. */
|
||||
goto again;
|
||||
}
|
||||
|
||||
if (res == SYS_ARCH_TIMEOUT) {
|
||||
/* If a SYS_ARCH_TIMEOUT value is returned, a timeout occurred
|
||||
before a message could be fetched. */
|
||||
sys_check_timeouts();
|
||||
/* We try again to fetch a message from the mbox. */
|
||||
goto again;
|
||||
}
|
||||
UNLOCK_TCPIP_CORE();
|
||||
res = sys_arch_mbox_fetch(mbox, msg, sleeptime);
|
||||
LOCK_TCPIP_CORE();
|
||||
if (res == SYS_ARCH_TIMEOUT) {
|
||||
/* If a SYS_ARCH_TIMEOUT value is returned, a timeout occurred
|
||||
before a message could be fetched. */
|
||||
sys_check_timeouts();
|
||||
/* We try again to fetch a message from the mbox. */
|
||||
goto again;
|
||||
}
|
||||
}
|
||||
#endif /* !LWIP_TIMERS */
|
||||
|
||||
@ -124,120 +124,109 @@ again:
|
||||
*
|
||||
* @param arg unused argument
|
||||
*/
|
||||
static void tcpip_thread(void *arg)
|
||||
static void
|
||||
tcpip_thread(void *arg)
|
||||
{
|
||||
struct tcpip_msg *msg;
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
struct tcpip_msg *msg;
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
|
||||
LWIP_MARK_TCPIP_THREAD();
|
||||
LWIP_MARK_TCPIP_THREAD();
|
||||
|
||||
LOCK_TCPIP_CORE();
|
||||
LOCK_TCPIP_CORE();
|
||||
if (tcpip_init_done != NULL) {
|
||||
tcpip_init_done(tcpip_init_done_arg);
|
||||
}
|
||||
|
||||
if (tcpip_init_done != NULL) {
|
||||
tcpip_init_done(tcpip_init_done_arg);
|
||||
}
|
||||
|
||||
while (1) /* MAIN Loop */
|
||||
{
|
||||
LWIP_TCPIP_THREAD_ALIVE();
|
||||
/* wait for a message, timeouts are processed while waiting */
|
||||
TCPIP_MBOX_FETCH(&tcpip_mbox, (void **)&msg);
|
||||
|
||||
if (msg == NULL) {
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: invalid message: NULL\n"));
|
||||
LWIP_ASSERT("tcpip_thread: invalid message", 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
tcpip_thread_handle_msg(msg);
|
||||
while (1) { /* MAIN Loop */
|
||||
LWIP_TCPIP_THREAD_ALIVE();
|
||||
/* wait for a message, timeouts are processed while waiting */
|
||||
TCPIP_MBOX_FETCH(&tcpip_mbox, (void **)&msg);
|
||||
if (msg == NULL) {
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: invalid message: NULL\n"));
|
||||
LWIP_ASSERT("tcpip_thread: invalid message", 0);
|
||||
continue;
|
||||
}
|
||||
tcpip_thread_handle_msg(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle a single tcpip_msg
|
||||
* This is in its own function for access by tests only.
|
||||
*/
|
||||
static void tcpip_thread_handle_msg(struct tcpip_msg *msg)
|
||||
static void
|
||||
tcpip_thread_handle_msg(struct tcpip_msg *msg)
|
||||
{
|
||||
switch (msg->type) {
|
||||
switch (msg->type) {
|
||||
#if !LWIP_TCPIP_CORE_LOCKING
|
||||
|
||||
case TCPIP_MSG_API:
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API message %p\n", (void *)msg));
|
||||
msg->msg.api_msg.function(msg->msg.api_msg.msg);
|
||||
break;
|
||||
|
||||
case TCPIP_MSG_API_CALL:
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API CALL message %p\n", (void *)msg));
|
||||
msg->msg.api_call.arg->err = msg->msg.api_call.function(msg->msg.api_call.arg);
|
||||
sys_sem_signal(msg->msg.api_call.sem);
|
||||
break;
|
||||
case TCPIP_MSG_API:
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API message %p\n", (void *)msg));
|
||||
msg->msg.api_msg.function(msg->msg.api_msg.msg);
|
||||
break;
|
||||
case TCPIP_MSG_API_CALL:
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API CALL message %p\n", (void *)msg));
|
||||
msg->msg.api_call.arg->err = msg->msg.api_call.function(msg->msg.api_call.arg);
|
||||
sys_sem_signal(msg->msg.api_call.sem);
|
||||
break;
|
||||
#endif /* !LWIP_TCPIP_CORE_LOCKING */
|
||||
|
||||
#if !LWIP_TCPIP_CORE_LOCKING_INPUT
|
||||
|
||||
case TCPIP_MSG_INPKT:
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: PACKET %p\n", (void *)msg));
|
||||
|
||||
if (msg->msg.inp.input_fn(msg->msg.inp.p, msg->msg.inp.netif) != ERR_OK) {
|
||||
pbuf_free(msg->msg.inp.p);
|
||||
}
|
||||
|
||||
memp_free(MEMP_TCPIP_MSG_INPKT, msg);
|
||||
break;
|
||||
case TCPIP_MSG_INPKT:
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: PACKET %p\n", (void *)msg));
|
||||
if (msg->msg.inp.input_fn(msg->msg.inp.p, msg->msg.inp.netif) != ERR_OK) {
|
||||
pbuf_free(msg->msg.inp.p);
|
||||
}
|
||||
memp_free(MEMP_TCPIP_MSG_INPKT, msg);
|
||||
break;
|
||||
#endif /* !LWIP_TCPIP_CORE_LOCKING_INPUT */
|
||||
|
||||
#if LWIP_TCPIP_TIMEOUT && LWIP_TIMERS
|
||||
|
||||
case TCPIP_MSG_TIMEOUT:
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: TIMEOUT %p\n", (void *)msg));
|
||||
sys_timeout(msg->msg.tmo.msecs, msg->msg.tmo.h, msg->msg.tmo.arg);
|
||||
memp_free(MEMP_TCPIP_MSG_API, msg);
|
||||
break;
|
||||
|
||||
case TCPIP_MSG_UNTIMEOUT:
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: UNTIMEOUT %p\n", (void *)msg));
|
||||
sys_untimeout(msg->msg.tmo.h, msg->msg.tmo.arg);
|
||||
memp_free(MEMP_TCPIP_MSG_API, msg);
|
||||
break;
|
||||
case TCPIP_MSG_TIMEOUT:
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: TIMEOUT %p\n", (void *)msg));
|
||||
sys_timeout(msg->msg.tmo.msecs, msg->msg.tmo.h, msg->msg.tmo.arg);
|
||||
memp_free(MEMP_TCPIP_MSG_API, msg);
|
||||
break;
|
||||
case TCPIP_MSG_UNTIMEOUT:
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: UNTIMEOUT %p\n", (void *)msg));
|
||||
sys_untimeout(msg->msg.tmo.h, msg->msg.tmo.arg);
|
||||
memp_free(MEMP_TCPIP_MSG_API, msg);
|
||||
break;
|
||||
#endif /* LWIP_TCPIP_TIMEOUT && LWIP_TIMERS */
|
||||
|
||||
case TCPIP_MSG_CALLBACK:
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: CALLBACK %p\n", (void *)msg));
|
||||
msg->msg.cb.function(msg->msg.cb.ctx);
|
||||
memp_free(MEMP_TCPIP_MSG_API, msg);
|
||||
break;
|
||||
case TCPIP_MSG_CALLBACK:
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: CALLBACK %p\n", (void *)msg));
|
||||
msg->msg.cb.function(msg->msg.cb.ctx);
|
||||
memp_free(MEMP_TCPIP_MSG_API, msg);
|
||||
break;
|
||||
|
||||
case TCPIP_MSG_CALLBACK_STATIC:
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: CALLBACK_STATIC %p\n", (void *)msg));
|
||||
msg->msg.cb.function(msg->msg.cb.ctx);
|
||||
break;
|
||||
case TCPIP_MSG_CALLBACK_STATIC:
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: CALLBACK_STATIC %p\n", (void *)msg));
|
||||
msg->msg.cb.function(msg->msg.cb.ctx);
|
||||
break;
|
||||
|
||||
default:
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: invalid message: %d\n", msg->type));
|
||||
LWIP_ASSERT("tcpip_thread: invalid message", 0);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: invalid message: %d\n", msg->type));
|
||||
LWIP_ASSERT("tcpip_thread: invalid message", 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TCPIP_THREAD_TEST
|
||||
/** Work on queued items in single-threaded test mode */
|
||||
int tcpip_thread_poll_one(void)
|
||||
int
|
||||
tcpip_thread_poll_one(void)
|
||||
{
|
||||
int ret = 0;
|
||||
struct tcpip_msg *msg;
|
||||
int ret = 0;
|
||||
struct tcpip_msg *msg;
|
||||
|
||||
if (sys_arch_mbox_tryfetch(&tcpip_mbox, (void **)&msg) != SYS_ARCH_TIMEOUT) {
|
||||
LOCK_TCPIP_CORE();
|
||||
|
||||
if (msg != NULL) {
|
||||
tcpip_thread_handle_msg(msg);
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
UNLOCK_TCPIP_CORE();
|
||||
if (sys_arch_mbox_tryfetch(&tcpip_mbox, (void **)&msg) != SYS_ARCH_TIMEOUT) {
|
||||
LOCK_TCPIP_CORE();
|
||||
if (msg != NULL) {
|
||||
tcpip_thread_handle_msg(msg);
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
UNLOCK_TCPIP_CORE();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -248,37 +237,37 @@ int tcpip_thread_poll_one(void)
|
||||
* @param inp the network interface on which the packet was received
|
||||
* @param input_fn input function to call
|
||||
*/
|
||||
err_t tcpip_inpkt(struct pbuf *p, struct netif *inp, netif_input_fn input_fn)
|
||||
err_t
|
||||
tcpip_inpkt(struct pbuf *p, struct netif *inp, netif_input_fn input_fn)
|
||||
{
|
||||
#if LWIP_TCPIP_CORE_LOCKING_INPUT
|
||||
err_t ret;
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_inpkt: PACKET %p/%p\n", (void *)p, (void *)inp));
|
||||
LOCK_TCPIP_CORE();
|
||||
ret = input_fn(p, inp);
|
||||
UNLOCK_TCPIP_CORE();
|
||||
return ret;
|
||||
err_t ret;
|
||||
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_inpkt: PACKET %p/%p\n", (void *)p, (void *)inp));
|
||||
LOCK_TCPIP_CORE();
|
||||
ret = input_fn(p, inp);
|
||||
UNLOCK_TCPIP_CORE();
|
||||
return ret;
|
||||
#else /* LWIP_TCPIP_CORE_LOCKING_INPUT */
|
||||
struct tcpip_msg *msg;
|
||||
struct tcpip_msg *msg;
|
||||
|
||||
LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(tcpip_mbox));
|
||||
LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(tcpip_mbox));
|
||||
|
||||
msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_INPKT);
|
||||
msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_INPKT);
|
||||
if (msg == NULL) {
|
||||
printf("[LWIP] NO TCP MSG\r\n");
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
if (msg == NULL) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
msg->type = TCPIP_MSG_INPKT;
|
||||
msg->msg.inp.p = p;
|
||||
msg->msg.inp.netif = inp;
|
||||
msg->msg.inp.input_fn = input_fn;
|
||||
|
||||
if (sys_mbox_trypost(&tcpip_mbox, msg) != ERR_OK) {
|
||||
memp_free(MEMP_TCPIP_MSG_INPKT, msg);
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
msg->type = TCPIP_MSG_INPKT;
|
||||
msg->msg.inp.p = p;
|
||||
msg->msg.inp.netif = inp;
|
||||
msg->msg.inp.input_fn = input_fn;
|
||||
if (sys_mbox_trypost(&tcpip_mbox, msg) != ERR_OK) {
|
||||
printf("[LWIP] NO MBOX\r\n");
|
||||
memp_free(MEMP_TCPIP_MSG_INPKT, msg);
|
||||
return ERR_MEM;
|
||||
}
|
||||
return ERR_OK;
|
||||
#endif /* LWIP_TCPIP_CORE_LOCKING_INPUT */
|
||||
}
|
||||
|
||||
@ -293,15 +282,15 @@ err_t tcpip_inpkt(struct pbuf *p, struct netif *inp, netif_input_fn input_fn)
|
||||
* NETIF_FLAG_ETHERNET flags)
|
||||
* @param inp the network interface on which the packet was received
|
||||
*/
|
||||
err_t tcpip_input(struct pbuf *p, struct netif *inp)
|
||||
err_t
|
||||
tcpip_input(struct pbuf *p, struct netif *inp)
|
||||
{
|
||||
#if LWIP_ETHERNET
|
||||
|
||||
if (inp->flags & (NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET)) {
|
||||
return tcpip_inpkt(p, inp, ethernet_input);
|
||||
} else
|
||||
if (inp->flags & (NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET)) {
|
||||
return tcpip_inpkt(p, inp, ethernet_input);
|
||||
} else
|
||||
#endif /* LWIP_ETHERNET */
|
||||
return tcpip_inpkt(p, inp, ip_input);
|
||||
return tcpip_inpkt(p, inp, ip_input);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -319,24 +308,24 @@ err_t tcpip_input(struct pbuf *p, struct netif *inp)
|
||||
*
|
||||
* @see tcpip_try_callback
|
||||
*/
|
||||
err_t tcpip_callback(tcpip_callback_fn function, void *ctx)
|
||||
err_t
|
||||
tcpip_callback(tcpip_callback_fn function, void *ctx)
|
||||
{
|
||||
struct tcpip_msg *msg;
|
||||
struct tcpip_msg *msg;
|
||||
|
||||
LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(tcpip_mbox));
|
||||
LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(tcpip_mbox));
|
||||
|
||||
msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API);
|
||||
msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API);
|
||||
if (msg == NULL) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
if (msg == NULL) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
msg->type = TCPIP_MSG_CALLBACK;
|
||||
msg->msg.cb.function = function;
|
||||
msg->msg.cb.ctx = ctx;
|
||||
|
||||
msg->type = TCPIP_MSG_CALLBACK;
|
||||
msg->msg.cb.function = function;
|
||||
msg->msg.cb.ctx = ctx;
|
||||
|
||||
sys_mbox_post(&tcpip_mbox, msg);
|
||||
return ERR_OK;
|
||||
sys_mbox_post(&tcpip_mbox, msg);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -355,28 +344,27 @@ err_t tcpip_callback(tcpip_callback_fn function, void *ctx)
|
||||
*
|
||||
* @see tcpip_callback
|
||||
*/
|
||||
err_t tcpip_try_callback(tcpip_callback_fn function, void *ctx)
|
||||
err_t
|
||||
tcpip_try_callback(tcpip_callback_fn function, void *ctx)
|
||||
{
|
||||
struct tcpip_msg *msg;
|
||||
struct tcpip_msg *msg;
|
||||
|
||||
LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(tcpip_mbox));
|
||||
LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(tcpip_mbox));
|
||||
|
||||
msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API);
|
||||
msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API);
|
||||
if (msg == NULL) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
if (msg == NULL) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
msg->type = TCPIP_MSG_CALLBACK;
|
||||
msg->msg.cb.function = function;
|
||||
msg->msg.cb.ctx = ctx;
|
||||
|
||||
msg->type = TCPIP_MSG_CALLBACK;
|
||||
msg->msg.cb.function = function;
|
||||
msg->msg.cb.ctx = ctx;
|
||||
|
||||
if (sys_mbox_trypost(&tcpip_mbox, msg) != ERR_OK) {
|
||||
memp_free(MEMP_TCPIP_MSG_API, msg);
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
if (sys_mbox_trypost(&tcpip_mbox, msg) != ERR_OK) {
|
||||
memp_free(MEMP_TCPIP_MSG_API, msg);
|
||||
return ERR_MEM;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
#if LWIP_TCPIP_TIMEOUT && LWIP_TIMERS
|
||||
@ -388,24 +376,24 @@ err_t tcpip_try_callback(tcpip_callback_fn function, void *ctx)
|
||||
* @param arg argument to pass to timeout function h
|
||||
* @return ERR_MEM on memory error, ERR_OK otherwise
|
||||
*/
|
||||
err_t tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg)
|
||||
err_t
|
||||
tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg)
|
||||
{
|
||||
struct tcpip_msg *msg;
|
||||
struct tcpip_msg *msg;
|
||||
|
||||
LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(tcpip_mbox));
|
||||
LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(tcpip_mbox));
|
||||
|
||||
msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API);
|
||||
msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API);
|
||||
if (msg == NULL) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
if (msg == NULL) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
msg->type = TCPIP_MSG_TIMEOUT;
|
||||
msg->msg.tmo.msecs = msecs;
|
||||
msg->msg.tmo.h = h;
|
||||
msg->msg.tmo.arg = arg;
|
||||
sys_mbox_post(&tcpip_mbox, msg);
|
||||
return ERR_OK;
|
||||
msg->type = TCPIP_MSG_TIMEOUT;
|
||||
msg->msg.tmo.msecs = msecs;
|
||||
msg->msg.tmo.h = h;
|
||||
msg->msg.tmo.arg = arg;
|
||||
sys_mbox_post(&tcpip_mbox, msg);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -415,26 +403,27 @@ err_t tcpip_timeout(u32_t msecs, sys_timeout_handler h, void *arg)
|
||||
* @param arg argument to pass to timeout function h
|
||||
* @return ERR_MEM on memory error, ERR_OK otherwise
|
||||
*/
|
||||
err_t tcpip_untimeout(sys_timeout_handler h, void *arg)
|
||||
err_t
|
||||
tcpip_untimeout(sys_timeout_handler h, void *arg)
|
||||
{
|
||||
struct tcpip_msg *msg;
|
||||
struct tcpip_msg *msg;
|
||||
|
||||
LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(tcpip_mbox));
|
||||
LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(tcpip_mbox));
|
||||
|
||||
msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API);
|
||||
msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API);
|
||||
if (msg == NULL) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
if (msg == NULL) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
msg->type = TCPIP_MSG_UNTIMEOUT;
|
||||
msg->msg.tmo.h = h;
|
||||
msg->msg.tmo.arg = arg;
|
||||
sys_mbox_post(&tcpip_mbox, msg);
|
||||
return ERR_OK;
|
||||
msg->type = TCPIP_MSG_UNTIMEOUT;
|
||||
msg->msg.tmo.h = h;
|
||||
msg->msg.tmo.arg = arg;
|
||||
sys_mbox_post(&tcpip_mbox, msg);
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif /* LWIP_TCPIP_TIMEOUT && LWIP_TIMERS */
|
||||
|
||||
|
||||
/**
|
||||
* Sends a message to TCPIP thread to call a function. Caller thread blocks on
|
||||
* on a provided semaphore, which ist NOT automatically signalled by TCPIP thread,
|
||||
@ -447,28 +436,29 @@ err_t tcpip_untimeout(sys_timeout_handler h, void *arg)
|
||||
* @param sem semaphore to wait on
|
||||
* @return ERR_OK if the function was called, another err_t if not
|
||||
*/
|
||||
err_t tcpip_send_msg_wait_sem(tcpip_callback_fn fn, void *apimsg, sys_sem_t *sem)
|
||||
err_t
|
||||
tcpip_send_msg_wait_sem(tcpip_callback_fn fn, void *apimsg, sys_sem_t *sem)
|
||||
{
|
||||
#if LWIP_TCPIP_CORE_LOCKING
|
||||
LWIP_UNUSED_ARG(sem);
|
||||
LOCK_TCPIP_CORE();
|
||||
fn(apimsg);
|
||||
UNLOCK_TCPIP_CORE();
|
||||
return ERR_OK;
|
||||
LWIP_UNUSED_ARG(sem);
|
||||
LOCK_TCPIP_CORE();
|
||||
fn(apimsg);
|
||||
UNLOCK_TCPIP_CORE();
|
||||
return ERR_OK;
|
||||
#else /* LWIP_TCPIP_CORE_LOCKING */
|
||||
TCPIP_MSG_VAR_DECLARE(msg);
|
||||
TCPIP_MSG_VAR_DECLARE(msg);
|
||||
|
||||
LWIP_ASSERT("semaphore not initialized", sys_sem_valid(sem));
|
||||
LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(tcpip_mbox));
|
||||
LWIP_ASSERT("semaphore not initialized", sys_sem_valid(sem));
|
||||
LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(tcpip_mbox));
|
||||
|
||||
TCPIP_MSG_VAR_ALLOC(msg);
|
||||
TCPIP_MSG_VAR_REF(msg).type = TCPIP_MSG_API;
|
||||
TCPIP_MSG_VAR_REF(msg).msg.api_msg.function = fn;
|
||||
TCPIP_MSG_VAR_REF(msg).msg.api_msg.msg = apimsg;
|
||||
sys_mbox_post(&tcpip_mbox, &TCPIP_MSG_VAR_REF(msg));
|
||||
sys_arch_sem_wait(sem, 0);
|
||||
TCPIP_MSG_VAR_FREE(msg);
|
||||
return ERR_OK;
|
||||
TCPIP_MSG_VAR_ALLOC(msg);
|
||||
TCPIP_MSG_VAR_REF(msg).type = TCPIP_MSG_API;
|
||||
TCPIP_MSG_VAR_REF(msg).msg.api_msg.function = fn;
|
||||
TCPIP_MSG_VAR_REF(msg).msg.api_msg.msg = apimsg;
|
||||
sys_mbox_post(&tcpip_mbox, &TCPIP_MSG_VAR_REF(msg));
|
||||
sys_arch_sem_wait(sem, 0);
|
||||
TCPIP_MSG_VAR_FREE(msg);
|
||||
return ERR_OK;
|
||||
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
||||
}
|
||||
|
||||
@ -482,46 +472,45 @@ err_t tcpip_send_msg_wait_sem(tcpip_callback_fn fn, void *apimsg, sys_sem_t *sem
|
||||
* @param call Call parameters
|
||||
* @return Return value from tcpip_api_call_fn
|
||||
*/
|
||||
err_t tcpip_api_call(tcpip_api_call_fn fn, struct tcpip_api_call_data *call)
|
||||
err_t
|
||||
tcpip_api_call(tcpip_api_call_fn fn, struct tcpip_api_call_data *call)
|
||||
{
|
||||
#if LWIP_TCPIP_CORE_LOCKING
|
||||
err_t err;
|
||||
LOCK_TCPIP_CORE();
|
||||
err = fn(call);
|
||||
UNLOCK_TCPIP_CORE();
|
||||
return err;
|
||||
err_t err;
|
||||
LOCK_TCPIP_CORE();
|
||||
err = fn(call);
|
||||
UNLOCK_TCPIP_CORE();
|
||||
return err;
|
||||
#else /* LWIP_TCPIP_CORE_LOCKING */
|
||||
TCPIP_MSG_VAR_DECLARE(msg);
|
||||
TCPIP_MSG_VAR_DECLARE(msg);
|
||||
|
||||
#if !LWIP_NETCONN_SEM_PER_THREAD
|
||||
err_t err = sys_sem_new(&call->sem, 0);
|
||||
|
||||
if (err != ERR_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err_t err = sys_sem_new(&call->sem, 0);
|
||||
if (err != ERR_OK) {
|
||||
return err;
|
||||
}
|
||||
#endif /* LWIP_NETCONN_SEM_PER_THREAD */
|
||||
|
||||
LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(tcpip_mbox));
|
||||
LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(tcpip_mbox));
|
||||
|
||||
TCPIP_MSG_VAR_ALLOC(msg);
|
||||
TCPIP_MSG_VAR_REF(msg).type = TCPIP_MSG_API_CALL;
|
||||
TCPIP_MSG_VAR_REF(msg).msg.api_call.arg = call;
|
||||
TCPIP_MSG_VAR_REF(msg).msg.api_call.function = fn;
|
||||
TCPIP_MSG_VAR_ALLOC(msg);
|
||||
TCPIP_MSG_VAR_REF(msg).type = TCPIP_MSG_API_CALL;
|
||||
TCPIP_MSG_VAR_REF(msg).msg.api_call.arg = call;
|
||||
TCPIP_MSG_VAR_REF(msg).msg.api_call.function = fn;
|
||||
#if LWIP_NETCONN_SEM_PER_THREAD
|
||||
TCPIP_MSG_VAR_REF(msg).msg.api_call.sem = LWIP_NETCONN_THREAD_SEM_GET();
|
||||
TCPIP_MSG_VAR_REF(msg).msg.api_call.sem = LWIP_NETCONN_THREAD_SEM_GET();
|
||||
#else /* LWIP_NETCONN_SEM_PER_THREAD */
|
||||
TCPIP_MSG_VAR_REF(msg).msg.api_call.sem = &call->sem;
|
||||
TCPIP_MSG_VAR_REF(msg).msg.api_call.sem = &call->sem;
|
||||
#endif /* LWIP_NETCONN_SEM_PER_THREAD */
|
||||
sys_mbox_post(&tcpip_mbox, &TCPIP_MSG_VAR_REF(msg));
|
||||
sys_arch_sem_wait(TCPIP_MSG_VAR_REF(msg).msg.api_call.sem, 0);
|
||||
TCPIP_MSG_VAR_FREE(msg);
|
||||
sys_mbox_post(&tcpip_mbox, &TCPIP_MSG_VAR_REF(msg));
|
||||
sys_arch_sem_wait(TCPIP_MSG_VAR_REF(msg).msg.api_call.sem, 0);
|
||||
TCPIP_MSG_VAR_FREE(msg);
|
||||
|
||||
#if !LWIP_NETCONN_SEM_PER_THREAD
|
||||
sys_sem_free(&call->sem);
|
||||
sys_sem_free(&call->sem);
|
||||
#endif /* LWIP_NETCONN_SEM_PER_THREAD */
|
||||
|
||||
return call->err;
|
||||
return call->err;
|
||||
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
||||
}
|
||||
|
||||
@ -533,7 +522,7 @@ err_t tcpip_api_call(tcpip_api_call_fn fn, struct tcpip_api_call_data *call)
|
||||
* e.g. the message is allocated once and posted several times from an IRQ
|
||||
* using tcpip_callbackmsg_trycallback().
|
||||
* Example usage: Trigger execution of an ethernet IRQ DPC routine in lwIP thread context.
|
||||
*
|
||||
*
|
||||
* @param function the function to call
|
||||
* @param ctx parameter passed to function
|
||||
* @return a struct pointer to pass to tcpip_callbackmsg_trycallback().
|
||||
@ -544,16 +533,14 @@ err_t tcpip_api_call(tcpip_api_call_fn fn, struct tcpip_api_call_data *call)
|
||||
struct tcpip_callback_msg *
|
||||
tcpip_callbackmsg_new(tcpip_callback_fn function, void *ctx)
|
||||
{
|
||||
struct tcpip_msg *msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API);
|
||||
|
||||
if (msg == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
msg->type = TCPIP_MSG_CALLBACK_STATIC;
|
||||
msg->msg.cb.function = function;
|
||||
msg->msg.cb.ctx = ctx;
|
||||
return (struct tcpip_callback_msg *)msg;
|
||||
struct tcpip_msg *msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API);
|
||||
if (msg == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
msg->type = TCPIP_MSG_CALLBACK_STATIC;
|
||||
msg->msg.cb.function = function;
|
||||
msg->msg.cb.ctx = ctx;
|
||||
return (struct tcpip_callback_msg *)msg;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -564,9 +551,10 @@ tcpip_callbackmsg_new(tcpip_callback_fn function, void *ctx)
|
||||
*
|
||||
* @see tcpip_callbackmsg_new()
|
||||
*/
|
||||
void tcpip_callbackmsg_delete(struct tcpip_callback_msg *msg)
|
||||
void
|
||||
tcpip_callbackmsg_delete(struct tcpip_callback_msg *msg)
|
||||
{
|
||||
memp_free(MEMP_TCPIP_MSG_API, msg);
|
||||
memp_free(MEMP_TCPIP_MSG_API, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -578,10 +566,11 @@ void tcpip_callbackmsg_delete(struct tcpip_callback_msg *msg)
|
||||
*
|
||||
* @see tcpip_callbackmsg_new()
|
||||
*/
|
||||
err_t tcpip_callbackmsg_trycallback(struct tcpip_callback_msg *msg)
|
||||
err_t
|
||||
tcpip_callbackmsg_trycallback(struct tcpip_callback_msg *msg)
|
||||
{
|
||||
LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(tcpip_mbox));
|
||||
return sys_mbox_trypost(&tcpip_mbox, msg);
|
||||
LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(tcpip_mbox));
|
||||
return sys_mbox_trypost(&tcpip_mbox, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -596,10 +585,11 @@ err_t tcpip_callbackmsg_trycallback(struct tcpip_callback_msg *msg)
|
||||
*
|
||||
* @see tcpip_callbackmsg_new()
|
||||
*/
|
||||
err_t tcpip_callbackmsg_trycallback_fromisr(struct tcpip_callback_msg *msg)
|
||||
err_t
|
||||
tcpip_callbackmsg_trycallback_fromisr(struct tcpip_callback_msg *msg)
|
||||
{
|
||||
LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(tcpip_mbox));
|
||||
return sys_mbox_trypost_fromisr(&tcpip_mbox, msg);
|
||||
LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(tcpip_mbox));
|
||||
return sys_mbox_trypost_fromisr(&tcpip_mbox, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -611,27 +601,23 @@ err_t tcpip_callbackmsg_trycallback_fromisr(struct tcpip_callback_msg *msg)
|
||||
* @param initfunc a function to call when tcpip_thread is running and finished initializing
|
||||
* @param arg argument to pass to initfunc
|
||||
*/
|
||||
void tcpip_init(tcpip_init_done_fn initfunc, void *arg)
|
||||
void
|
||||
tcpip_init(tcpip_init_done_fn initfunc, void *arg)
|
||||
{
|
||||
lwip_init();
|
||||
printf("lwip init done\r\n");
|
||||
tcpip_init_done = initfunc;
|
||||
tcpip_init_done_arg = arg;
|
||||
lwip_init();
|
||||
|
||||
if (sys_mbox_new(&tcpip_mbox, TCPIP_MBOX_SIZE) != ERR_OK) {
|
||||
LWIP_ASSERT("failed to create tcpip_thread mbox", 0);
|
||||
}
|
||||
printf("sys_mbox_new done!\r\n");
|
||||
tcpip_init_done = initfunc;
|
||||
tcpip_init_done_arg = arg;
|
||||
if (sys_mbox_new(&tcpip_mbox, TCPIP_MBOX_SIZE) != ERR_OK) {
|
||||
LWIP_ASSERT("failed to create tcpip_thread mbox", 0);
|
||||
}
|
||||
#if LWIP_TCPIP_CORE_LOCKING
|
||||
|
||||
if (sys_mutex_new(&lock_tcpip_core) != ERR_OK) {
|
||||
LWIP_ASSERT("failed to create lock_tcpip_core", 0);
|
||||
}
|
||||
printf("sys_mutex_new done!\r\n");
|
||||
if (sys_mutex_new(&lock_tcpip_core) != ERR_OK) {
|
||||
LWIP_ASSERT("failed to create lock_tcpip_core", 0);
|
||||
}
|
||||
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
||||
|
||||
sys_thread_new(TCPIP_THREAD_NAME, tcpip_thread, NULL, TCPIP_THREAD_STACKSIZE, TCPIP_THREAD_PRIO);
|
||||
printf("tcpip thread init done!\r\n");
|
||||
sys_thread_new(TCPIP_THREAD_NAME, tcpip_thread, NULL, TCPIP_THREAD_STACKSIZE, TCPIP_THREAD_PRIO);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -640,10 +626,11 @@ void tcpip_init(tcpip_init_done_fn initfunc, void *arg)
|
||||
*
|
||||
* @param p The pbuf (chain) to be dereferenced.
|
||||
*/
|
||||
static void pbuf_free_int(void *p)
|
||||
static void
|
||||
pbuf_free_int(void *p)
|
||||
{
|
||||
struct pbuf *q = (struct pbuf *)p;
|
||||
pbuf_free(q);
|
||||
struct pbuf *q = (struct pbuf *)p;
|
||||
pbuf_free(q);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -652,9 +639,10 @@ static void pbuf_free_int(void *p)
|
||||
* @param p The pbuf (chain) to be dereferenced.
|
||||
* @return ERR_OK if callback could be enqueued, an err_t if not
|
||||
*/
|
||||
err_t pbuf_free_callback(struct pbuf *p)
|
||||
err_t
|
||||
pbuf_free_callback(struct pbuf *p)
|
||||
{
|
||||
return tcpip_try_callback(pbuf_free_int, p);
|
||||
return tcpip_try_callback(pbuf_free_int, p);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -664,9 +652,10 @@ err_t pbuf_free_callback(struct pbuf *p)
|
||||
* @param m the heap memory to free
|
||||
* @return ERR_OK if callback could be enqueued, an err_t if not
|
||||
*/
|
||||
err_t mem_free_callback(void *m)
|
||||
err_t
|
||||
mem_free_callback(void *m)
|
||||
{
|
||||
return tcpip_try_callback(mem_free, m);
|
||||
return tcpip_try_callback(mem_free, m);
|
||||
}
|
||||
|
||||
#endif /* !NO_SYS */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -65,12 +65,12 @@
|
||||
#include <string.h>
|
||||
|
||||
#ifndef ALTCP_MBEDTLS_MEM_DEBUG
|
||||
#define ALTCP_MBEDTLS_MEM_DEBUG LWIP_DBG_OFF
|
||||
#define ALTCP_MBEDTLS_MEM_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PLATFORM_MEMORY) && \
|
||||
(!defined(MBEDTLS_PLATFORM_FREE_MACRO) || \
|
||||
defined(MBEDTLS_PLATFORM_CALLOC_MACRO))
|
||||
#if defined(MBEDTLS_PLATFORM_MEMORY) && \
|
||||
(!defined(MBEDTLS_PLATFORM_FREE_MACRO) || \
|
||||
defined(MBEDTLS_PLATFORM_CALLOC_MACRO))
|
||||
#define ALTCP_MBEDTLS_PLATFORM_ALLOC 1
|
||||
#else
|
||||
#define ALTCP_MBEDTLS_PLATFORM_ALLOC 0
|
||||
@ -84,135 +84,127 @@
|
||||
|
||||
/* This is an example/debug implementation of alloc/free functions only */
|
||||
typedef struct altcp_mbedtls_malloc_helper_s {
|
||||
size_t c;
|
||||
size_t len;
|
||||
size_t c;
|
||||
size_t len;
|
||||
} altcp_mbedtls_malloc_helper_t;
|
||||
|
||||
#if ALTCP_MBEDTLS_PLATFORM_ALLOC_STATS
|
||||
typedef struct altcp_mbedtls_malloc_stats_s {
|
||||
size_t allocedBytes;
|
||||
size_t allocCnt;
|
||||
size_t maxBytes;
|
||||
size_t totalBytes;
|
||||
size_t allocedBytes;
|
||||
size_t allocCnt;
|
||||
size_t maxBytes;
|
||||
size_t totalBytes;
|
||||
} altcp_mbedtls_malloc_stats_t;
|
||||
altcp_mbedtls_malloc_stats_t altcp_mbedtls_malloc_stats;
|
||||
volatile int altcp_mbedtls_malloc_clear_stats;
|
||||
#endif
|
||||
|
||||
static void *tls_malloc(size_t c, size_t len)
|
||||
static void *
|
||||
tls_malloc(size_t c, size_t len)
|
||||
{
|
||||
altcp_mbedtls_malloc_helper_t *hlpr;
|
||||
void *ret;
|
||||
size_t alloc_size;
|
||||
altcp_mbedtls_malloc_helper_t *hlpr;
|
||||
void *ret;
|
||||
size_t alloc_size;
|
||||
#if ALTCP_MBEDTLS_PLATFORM_ALLOC_STATS
|
||||
|
||||
if (altcp_mbedtls_malloc_clear_stats) {
|
||||
altcp_mbedtls_malloc_clear_stats = 0;
|
||||
memset(&altcp_mbedtls_malloc_stats, 0, sizeof(altcp_mbedtls_malloc_stats));
|
||||
}
|
||||
|
||||
if (altcp_mbedtls_malloc_clear_stats) {
|
||||
altcp_mbedtls_malloc_clear_stats = 0;
|
||||
memset(&altcp_mbedtls_malloc_stats, 0, sizeof(altcp_mbedtls_malloc_stats));
|
||||
}
|
||||
#endif
|
||||
alloc_size = sizeof(altcp_mbedtls_malloc_helper_t) + (c * len);
|
||||
|
||||
/* check for maximum allocation size, mainly to prevent mem_size_t overflow */
|
||||
if (alloc_size > MEM_SIZE) {
|
||||
LWIP_DEBUGF(ALTCP_MBEDTLS_MEM_DEBUG, ("mbedtls allocation too big: %c * %d bytes vs MEM_SIZE=%d",
|
||||
(int)c, (int)len, (int)MEM_SIZE));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hlpr = (altcp_mbedtls_malloc_helper_t *)mem_malloc((mem_size_t)alloc_size);
|
||||
|
||||
if (hlpr == NULL) {
|
||||
LWIP_DEBUGF(ALTCP_MBEDTLS_MEM_DEBUG, ("mbedtls alloc callback failed for %c * %d bytes", (int)c, (int)len));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
alloc_size = sizeof(altcp_mbedtls_malloc_helper_t) + (c * len);
|
||||
/* check for maximum allocation size, mainly to prevent mem_size_t overflow */
|
||||
if (alloc_size > MEM_SIZE) {
|
||||
LWIP_DEBUGF(ALTCP_MBEDTLS_MEM_DEBUG, ("mbedtls allocation too big: %c * %d bytes vs MEM_SIZE=%d",
|
||||
(int)c, (int)len, (int)MEM_SIZE));
|
||||
return NULL;
|
||||
}
|
||||
hlpr = (altcp_mbedtls_malloc_helper_t *)mem_malloc((mem_size_t)alloc_size);
|
||||
if (hlpr == NULL) {
|
||||
LWIP_DEBUGF(ALTCP_MBEDTLS_MEM_DEBUG, ("mbedtls alloc callback failed for %c * %d bytes", (int)c, (int)len));
|
||||
return NULL;
|
||||
}
|
||||
#if ALTCP_MBEDTLS_PLATFORM_ALLOC_STATS
|
||||
altcp_mbedtls_malloc_stats.allocCnt++;
|
||||
altcp_mbedtls_malloc_stats.allocedBytes += c * len;
|
||||
|
||||
if (altcp_mbedtls_malloc_stats.allocedBytes > altcp_mbedtls_malloc_stats.maxBytes) {
|
||||
altcp_mbedtls_malloc_stats.maxBytes = altcp_mbedtls_malloc_stats.allocedBytes;
|
||||
}
|
||||
|
||||
altcp_mbedtls_malloc_stats.totalBytes += c * len;
|
||||
altcp_mbedtls_malloc_stats.allocCnt++;
|
||||
altcp_mbedtls_malloc_stats.allocedBytes += c * len;
|
||||
if (altcp_mbedtls_malloc_stats.allocedBytes > altcp_mbedtls_malloc_stats.maxBytes) {
|
||||
altcp_mbedtls_malloc_stats.maxBytes = altcp_mbedtls_malloc_stats.allocedBytes;
|
||||
}
|
||||
altcp_mbedtls_malloc_stats.totalBytes += c * len;
|
||||
#endif
|
||||
hlpr->c = c;
|
||||
hlpr->len = len;
|
||||
ret = hlpr + 1;
|
||||
/* zeroing the allocated chunk is required by mbedTLS! */
|
||||
memset(ret, 0, c * len);
|
||||
return ret;
|
||||
hlpr->c = c;
|
||||
hlpr->len = len;
|
||||
ret = hlpr + 1;
|
||||
/* zeroing the allocated chunk is required by mbedTLS! */
|
||||
memset(ret, 0, c * len);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void tls_free(void *ptr)
|
||||
static void
|
||||
tls_free(void *ptr)
|
||||
{
|
||||
altcp_mbedtls_malloc_helper_t *hlpr;
|
||||
|
||||
if (ptr == NULL) {
|
||||
/* this obviously happened in mbedtls... */
|
||||
return;
|
||||
}
|
||||
|
||||
hlpr = ((altcp_mbedtls_malloc_helper_t *)ptr) - 1;
|
||||
altcp_mbedtls_malloc_helper_t *hlpr;
|
||||
if (ptr == NULL) {
|
||||
/* this obviously happened in mbedtls... */
|
||||
return;
|
||||
}
|
||||
hlpr = ((altcp_mbedtls_malloc_helper_t *)ptr) - 1;
|
||||
#if ALTCP_MBEDTLS_PLATFORM_ALLOC_STATS
|
||||
|
||||
if (!altcp_mbedtls_malloc_clear_stats) {
|
||||
altcp_mbedtls_malloc_stats.allocedBytes -= hlpr->c * hlpr->len;
|
||||
}
|
||||
|
||||
if (!altcp_mbedtls_malloc_clear_stats) {
|
||||
altcp_mbedtls_malloc_stats.allocedBytes -= hlpr->c * hlpr->len;
|
||||
}
|
||||
#endif
|
||||
mem_free(hlpr);
|
||||
mem_free(hlpr);
|
||||
}
|
||||
#endif /* ALTCP_MBEDTLS_PLATFORM_ALLOC*/
|
||||
|
||||
void altcp_mbedtls_mem_init(void)
|
||||
void
|
||||
altcp_mbedtls_mem_init(void)
|
||||
{
|
||||
/* not much to do here when using the heap */
|
||||
/* not much to do here when using the heap */
|
||||
|
||||
#if ALTCP_MBEDTLS_PLATFORM_ALLOC
|
||||
/* set mbedtls allocation methods */
|
||||
mbedtls_platform_set_calloc_free(&tls_malloc, &tls_free);
|
||||
/* set mbedtls allocation methods */
|
||||
mbedtls_platform_set_calloc_free(&tls_malloc, &tls_free);
|
||||
#endif
|
||||
}
|
||||
|
||||
altcp_mbedtls_state_t *altcp_mbedtls_alloc(void *conf)
|
||||
altcp_mbedtls_state_t *
|
||||
altcp_mbedtls_alloc(void *conf)
|
||||
{
|
||||
altcp_mbedtls_state_t *ret = (altcp_mbedtls_state_t *)mem_calloc(1, sizeof(altcp_mbedtls_state_t));
|
||||
|
||||
if (ret != NULL) {
|
||||
ret->conf = conf;
|
||||
}
|
||||
|
||||
return ret;
|
||||
altcp_mbedtls_state_t *ret = (altcp_mbedtls_state_t *)mem_calloc(1, sizeof(altcp_mbedtls_state_t));
|
||||
if (ret != NULL) {
|
||||
ret->conf = conf;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void altcp_mbedtls_free(void *conf, altcp_mbedtls_state_t *state)
|
||||
void
|
||||
altcp_mbedtls_free(void *conf, altcp_mbedtls_state_t *state)
|
||||
{
|
||||
LWIP_UNUSED_ARG(conf);
|
||||
LWIP_ASSERT("state != NULL", state != NULL);
|
||||
mem_free(state);
|
||||
LWIP_UNUSED_ARG(conf);
|
||||
LWIP_ASSERT("state != NULL", state != NULL);
|
||||
mem_free(state);
|
||||
}
|
||||
|
||||
void *altcp_mbedtls_alloc_config(size_t size)
|
||||
void *
|
||||
altcp_mbedtls_alloc_config(size_t size)
|
||||
{
|
||||
void *ret;
|
||||
size_t checked_size = (mem_size_t)size;
|
||||
|
||||
if (size != checked_size) {
|
||||
/* allocation too big (mem_size_t overflow) */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = (altcp_mbedtls_state_t *)mem_calloc(1, (mem_size_t)size);
|
||||
return ret;
|
||||
void *ret;
|
||||
size_t checked_size = (mem_size_t)size;
|
||||
if (size != checked_size) {
|
||||
/* allocation too big (mem_size_t overflow) */
|
||||
return NULL;
|
||||
}
|
||||
ret = (altcp_mbedtls_state_t *)mem_calloc(1, (mem_size_t)size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void altcp_mbedtls_free_config(void *item)
|
||||
void
|
||||
altcp_mbedtls_free_config(void *item)
|
||||
{
|
||||
LWIP_ASSERT("item != NULL", item != NULL);
|
||||
mem_free(item);
|
||||
LWIP_ASSERT("item != NULL", item != NULL);
|
||||
mbedtls_ssl_config_free(item);
|
||||
mem_free(item);
|
||||
}
|
||||
|
||||
#endif /* LWIP_ALTCP_TLS && LWIP_ALTCP_TLS_MBEDTLS */
|
||||
|
@ -56,22 +56,22 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ALTCP_MBEDTLS_FLAGS_HANDSHAKE_DONE 0x01
|
||||
#define ALTCP_MBEDTLS_FLAGS_UPPER_CALLED 0x02
|
||||
#define ALTCP_MBEDTLS_FLAGS_RX_CLOSE_QUEUED 0x04
|
||||
#define ALTCP_MBEDTLS_FLAGS_RX_CLOSED 0x08
|
||||
#define ALTCP_MBEDTLS_FLAGS_APPLDATA_SENT 0x10
|
||||
#define ALTCP_MBEDTLS_FLAGS_HANDSHAKE_DONE 0x01
|
||||
#define ALTCP_MBEDTLS_FLAGS_UPPER_CALLED 0x02
|
||||
#define ALTCP_MBEDTLS_FLAGS_RX_CLOSE_QUEUED 0x04
|
||||
#define ALTCP_MBEDTLS_FLAGS_RX_CLOSED 0x08
|
||||
#define ALTCP_MBEDTLS_FLAGS_APPLDATA_SENT 0x10
|
||||
|
||||
typedef struct altcp_mbedtls_state_s {
|
||||
void *conf;
|
||||
mbedtls_ssl_context ssl_context;
|
||||
/* chain of rx pbufs (before decryption) */
|
||||
struct pbuf *rx;
|
||||
struct pbuf *rx_app;
|
||||
u8_t flags;
|
||||
int rx_passed_unrecved;
|
||||
int bio_bytes_read;
|
||||
int bio_bytes_appl;
|
||||
void *conf;
|
||||
mbedtls_ssl_context ssl_context;
|
||||
/* chain of rx pbufs (before decryption) */
|
||||
struct pbuf *rx;
|
||||
struct pbuf *rx_app;
|
||||
u8_t flags;
|
||||
int rx_passed_unrecved;
|
||||
int bio_bytes_read;
|
||||
int bio_bytes_appl;
|
||||
} altcp_mbedtls_state_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -58,14 +58,15 @@
|
||||
#define ALTCP_PROXYCONNECT_CLIENT_AGENT "lwIP/" LWIP_VERSION_STRING " (http://savannah.nongnu.org/projects/lwip)"
|
||||
#endif
|
||||
|
||||
#define ALTCP_PROXYCONNECT_FLAGS_CONNECT_STARTED 0x01
|
||||
#define ALTCP_PROXYCONNECT_FLAGS_HANDSHAKE_DONE 0x02
|
||||
#define ALTCP_PROXYCONNECT_FLAGS_CONNECT_STARTED 0x01
|
||||
#define ALTCP_PROXYCONNECT_FLAGS_HANDSHAKE_DONE 0x02
|
||||
|
||||
typedef struct altcp_proxyconnect_state_s {
|
||||
ip_addr_t outer_addr;
|
||||
u16_t outer_port;
|
||||
struct altcp_proxyconnect_config *conf;
|
||||
u8_t flags;
|
||||
typedef struct altcp_proxyconnect_state_s
|
||||
{
|
||||
ip_addr_t outer_addr;
|
||||
u16_t outer_port;
|
||||
struct altcp_proxyconnect_config *conf;
|
||||
u8_t flags;
|
||||
} altcp_proxyconnect_state_t;
|
||||
|
||||
/* Variable prototype, the actual declaration is at the end of this file
|
||||
@ -74,87 +75,81 @@ extern const struct altcp_functions altcp_proxyconnect_functions;
|
||||
|
||||
/* memory management functions: */
|
||||
|
||||
static altcp_proxyconnect_state_t *altcp_proxyconnect_state_alloc(void)
|
||||
static altcp_proxyconnect_state_t *
|
||||
altcp_proxyconnect_state_alloc(void)
|
||||
{
|
||||
altcp_proxyconnect_state_t *ret = (altcp_proxyconnect_state_t *)mem_calloc(1, sizeof(altcp_proxyconnect_state_t));
|
||||
return ret;
|
||||
altcp_proxyconnect_state_t *ret = (altcp_proxyconnect_state_t *)mem_calloc(1, sizeof(altcp_proxyconnect_state_t));
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void altcp_proxyconnect_state_free(altcp_proxyconnect_state_t *state)
|
||||
static void
|
||||
altcp_proxyconnect_state_free(altcp_proxyconnect_state_t *state)
|
||||
{
|
||||
LWIP_ASSERT("state != NULL", state != NULL);
|
||||
mem_free(state);
|
||||
LWIP_ASSERT("state != NULL", state != NULL);
|
||||
mem_free(state);
|
||||
}
|
||||
|
||||
/* helper functions */
|
||||
|
||||
#define PROXY_CONNECT "CONNECT %s:%d HTTP/1.1\r\n" /* HOST, PORT */ \
|
||||
"User-Agent: %s\r\n" /* User-Agent */ \
|
||||
"Proxy-Connection: keep-alive\r\n" \
|
||||
"Connection: keep-alive\r\n" \
|
||||
"\r\n"
|
||||
"User-Agent: %s\r\n" /* User-Agent */\
|
||||
"Proxy-Connection: keep-alive\r\n" \
|
||||
"Connection: keep-alive\r\n" \
|
||||
"\r\n"
|
||||
#define PROXY_CONNECT_FORMAT(host, port) PROXY_CONNECT, host, port, ALTCP_PROXYCONNECT_CLIENT_AGENT
|
||||
|
||||
/* Format the http proxy connect request via snprintf */
|
||||
static int altcp_proxyconnect_format_request(char *buffer, size_t bufsize, const char *host, int port)
|
||||
static int
|
||||
altcp_proxyconnect_format_request(char *buffer, size_t bufsize, const char *host, int port)
|
||||
{
|
||||
return snprintf(buffer, bufsize, PROXY_CONNECT_FORMAT(host, port));
|
||||
return snprintf(buffer, bufsize, PROXY_CONNECT_FORMAT(host, port));
|
||||
}
|
||||
|
||||
/* Create and send the http proxy connect request */
|
||||
static err_t altcp_proxyconnect_send_request(struct altcp_pcb *conn)
|
||||
static err_t
|
||||
altcp_proxyconnect_send_request(struct altcp_pcb *conn)
|
||||
{
|
||||
int len, len2;
|
||||
mem_size_t alloc_len;
|
||||
char *buffer, *host;
|
||||
altcp_proxyconnect_state_t *state = (altcp_proxyconnect_state_t *)conn->state;
|
||||
int len, len2;
|
||||
mem_size_t alloc_len;
|
||||
char *buffer, *host;
|
||||
altcp_proxyconnect_state_t *state = (altcp_proxyconnect_state_t *)conn->state;
|
||||
|
||||
if (!state) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
/* Use printf with zero length to get the required allocation size */
|
||||
len = altcp_proxyconnect_format_request(NULL, 0, "", state->outer_port);
|
||||
|
||||
if (len < 0) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
/* add allocation size for IP address strings */
|
||||
if (!state) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
/* Use printf with zero length to get the required allocation size */
|
||||
len = altcp_proxyconnect_format_request(NULL, 0, "", state->outer_port);
|
||||
if (len < 0) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
/* add allocation size for IP address strings */
|
||||
#if LWIP_IPV6
|
||||
len += 40; /* worst-case IPv6 address length */
|
||||
len += 40; /* worst-case IPv6 address length */
|
||||
#else
|
||||
len += 16; /* worst-case IPv4 address length */
|
||||
len += 16; /* worst-case IPv4 address length */
|
||||
#endif
|
||||
alloc_len = (mem_size_t)len;
|
||||
|
||||
if ((len < 0) || (int)alloc_len != len) {
|
||||
/* overflow */
|
||||
return ERR_MEM;
|
||||
alloc_len = (mem_size_t)len;
|
||||
if ((len < 0) || (int)alloc_len != len) {
|
||||
/* overflow */
|
||||
return ERR_MEM;
|
||||
}
|
||||
/* Allocate a bufer for the request string */
|
||||
buffer = (char *)mem_malloc(alloc_len);
|
||||
if (buffer == NULL) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
host = ipaddr_ntoa(&state->outer_addr);
|
||||
len2 = altcp_proxyconnect_format_request(buffer, alloc_len, host, state->outer_port);
|
||||
if ((len2 > 0) && (len2 <= len) && (len2 <= 0xFFFF)) {
|
||||
err_t err = altcp_write(conn->inner_conn, buffer, (u16_t)len2, TCP_WRITE_FLAG_COPY);
|
||||
if (err != ERR_OK) {
|
||||
/* @todo: abort? */
|
||||
mem_free(buffer);
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Allocate a bufer for the request string */
|
||||
buffer = (char *)mem_malloc(alloc_len);
|
||||
|
||||
if (buffer == NULL) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
host = ipaddr_ntoa(&state->outer_addr);
|
||||
len2 = altcp_proxyconnect_format_request(buffer, alloc_len, host, state->outer_port);
|
||||
|
||||
if ((len2 > 0) && (len2 <= len) && (len2 <= 0xFFFF)) {
|
||||
err_t err = altcp_write(conn->inner_conn, buffer, (u16_t)len2, TCP_WRITE_FLAG_COPY);
|
||||
|
||||
if (err != ERR_OK) {
|
||||
/* @todo: abort? */
|
||||
mem_free(buffer);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
mem_free(buffer);
|
||||
return ERR_OK;
|
||||
}
|
||||
mem_free(buffer);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/* callback functions from inner/lower connection: */
|
||||
@ -162,204 +157,183 @@ static err_t altcp_proxyconnect_send_request(struct altcp_pcb *conn)
|
||||
/** Connected callback from lower connection (i.e. TCP).
|
||||
* Not really implemented/tested yet...
|
||||
*/
|
||||
static err_t altcp_proxyconnect_lower_connected(void *arg, struct altcp_pcb *inner_conn, err_t err)
|
||||
static err_t
|
||||
altcp_proxyconnect_lower_connected(void *arg, struct altcp_pcb *inner_conn, err_t err)
|
||||
{
|
||||
struct altcp_pcb *conn = (struct altcp_pcb *)arg;
|
||||
|
||||
if (conn && conn->state) {
|
||||
LWIP_ASSERT("pcb mismatch", conn->inner_conn == inner_conn);
|
||||
LWIP_UNUSED_ARG(inner_conn); /* for LWIP_NOASSERT */
|
||||
|
||||
/* upper connected is called when handshake is done */
|
||||
if (err != ERR_OK) {
|
||||
if (conn->connected) {
|
||||
if (conn->connected(conn->arg, conn, err) == ERR_ABRT) {
|
||||
return ERR_ABRT;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
struct altcp_pcb *conn = (struct altcp_pcb *)arg;
|
||||
if (conn && conn->state) {
|
||||
LWIP_ASSERT("pcb mismatch", conn->inner_conn == inner_conn);
|
||||
LWIP_UNUSED_ARG(inner_conn); /* for LWIP_NOASSERT */
|
||||
/* upper connected is called when handshake is done */
|
||||
if (err != ERR_OK) {
|
||||
if (conn->connected) {
|
||||
if (conn->connected(conn->arg, conn, err) == ERR_ABRT) {
|
||||
return ERR_ABRT;
|
||||
}
|
||||
|
||||
/* send proxy connect request here */
|
||||
return altcp_proxyconnect_send_request(conn);
|
||||
return ERR_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return ERR_VAL;
|
||||
/* send proxy connect request here */
|
||||
return altcp_proxyconnect_send_request(conn);
|
||||
}
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
/** Recv callback from lower connection (i.e. TCP)
|
||||
* This one mainly differs between connection setup (wait for proxy OK string)
|
||||
* and application phase (data is passed on to the application).
|
||||
*/
|
||||
static err_t altcp_proxyconnect_lower_recv(void *arg, struct altcp_pcb *inner_conn, struct pbuf *p, err_t err)
|
||||
static err_t
|
||||
altcp_proxyconnect_lower_recv(void *arg, struct altcp_pcb *inner_conn, struct pbuf *p, err_t err)
|
||||
{
|
||||
altcp_proxyconnect_state_t *state;
|
||||
struct altcp_pcb *conn = (struct altcp_pcb *)arg;
|
||||
altcp_proxyconnect_state_t *state;
|
||||
struct altcp_pcb *conn = (struct altcp_pcb *)arg;
|
||||
|
||||
LWIP_ASSERT("no err expected", err == ERR_OK);
|
||||
LWIP_UNUSED_ARG(err);
|
||||
LWIP_ASSERT("no err expected", err == ERR_OK);
|
||||
LWIP_UNUSED_ARG(err);
|
||||
|
||||
if (!conn) {
|
||||
/* no connection given as arg? should not happen, but prevent pbuf/conn leaks */
|
||||
if (p != NULL) {
|
||||
pbuf_free(p);
|
||||
}
|
||||
|
||||
altcp_close(inner_conn);
|
||||
return ERR_CLSD;
|
||||
if (!conn) {
|
||||
/* no connection given as arg? should not happen, but prevent pbuf/conn leaks */
|
||||
if (p != NULL) {
|
||||
pbuf_free(p);
|
||||
}
|
||||
|
||||
state = (altcp_proxyconnect_state_t *)conn->state;
|
||||
LWIP_ASSERT("pcb mismatch", conn->inner_conn == inner_conn);
|
||||
|
||||
if (!state) {
|
||||
/* already closed */
|
||||
if (p != NULL) {
|
||||
pbuf_free(p);
|
||||
}
|
||||
|
||||
altcp_close(inner_conn);
|
||||
return ERR_CLSD;
|
||||
altcp_close(inner_conn);
|
||||
return ERR_CLSD;
|
||||
}
|
||||
state = (altcp_proxyconnect_state_t *)conn->state;
|
||||
LWIP_ASSERT("pcb mismatch", conn->inner_conn == inner_conn);
|
||||
if (!state) {
|
||||
/* already closed */
|
||||
if (p != NULL) {
|
||||
pbuf_free(p);
|
||||
}
|
||||
|
||||
if (state->flags & ALTCP_PROXYCONNECT_FLAGS_HANDSHAKE_DONE) {
|
||||
/* application phase, just pass this through */
|
||||
if (conn->recv) {
|
||||
return conn->recv(conn->arg, conn, p, err);
|
||||
}
|
||||
|
||||
pbuf_free(p);
|
||||
return ERR_OK;
|
||||
altcp_close(inner_conn);
|
||||
return ERR_CLSD;
|
||||
}
|
||||
if (state->flags & ALTCP_PROXYCONNECT_FLAGS_HANDSHAKE_DONE) {
|
||||
/* application phase, just pass this through */
|
||||
if (conn->recv) {
|
||||
return conn->recv(conn->arg, conn, p, err);
|
||||
}
|
||||
pbuf_free(p);
|
||||
return ERR_OK;
|
||||
} else {
|
||||
/* setup phase */
|
||||
/* handle NULL pbuf (inner connection closed) */
|
||||
if (p == NULL) {
|
||||
if (altcp_close(conn) != ERR_OK) {
|
||||
altcp_abort(conn);
|
||||
return ERR_ABRT;
|
||||
}
|
||||
return ERR_OK;
|
||||
} else {
|
||||
/* setup phase */
|
||||
/* handle NULL pbuf (inner connection closed) */
|
||||
if (p == NULL) {
|
||||
if (altcp_close(conn) != ERR_OK) {
|
||||
altcp_abort(conn);
|
||||
return ERR_ABRT;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
} else {
|
||||
/* @todo: parse setup phase rx data
|
||||
for now, we just wait for the end of the header... */
|
||||
u16_t idx = pbuf_memfind(p, "\r\n\r\n", 4, 0);
|
||||
altcp_recved(inner_conn, p->tot_len);
|
||||
pbuf_free(p);
|
||||
|
||||
if (idx != 0xFFFF) {
|
||||
state->flags |= ALTCP_PROXYCONNECT_FLAGS_HANDSHAKE_DONE;
|
||||
|
||||
if (conn->connected) {
|
||||
return conn->connected(conn->arg, conn, ERR_OK);
|
||||
}
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
/* @todo: parse setup phase rx data
|
||||
for now, we just wait for the end of the header... */
|
||||
u16_t idx = pbuf_memfind(p, "\r\n\r\n", 4, 0);
|
||||
altcp_recved(inner_conn, p->tot_len);
|
||||
pbuf_free(p);
|
||||
if (idx != 0xFFFF) {
|
||||
state->flags |= ALTCP_PROXYCONNECT_FLAGS_HANDSHAKE_DONE;
|
||||
if (conn->connected) {
|
||||
return conn->connected(conn->arg, conn, ERR_OK);
|
||||
}
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Sent callback from lower connection (i.e. TCP)
|
||||
* This only informs the upper layer to try to send more, not about
|
||||
* the number of ACKed bytes.
|
||||
*/
|
||||
static err_t altcp_proxyconnect_lower_sent(void *arg, struct altcp_pcb *inner_conn, u16_t len)
|
||||
static err_t
|
||||
altcp_proxyconnect_lower_sent(void *arg, struct altcp_pcb *inner_conn, u16_t len)
|
||||
{
|
||||
struct altcp_pcb *conn = (struct altcp_pcb *)arg;
|
||||
LWIP_UNUSED_ARG(len);
|
||||
|
||||
if (conn) {
|
||||
altcp_proxyconnect_state_t *state = (altcp_proxyconnect_state_t *)conn->state;
|
||||
LWIP_ASSERT("pcb mismatch", conn->inner_conn == inner_conn);
|
||||
LWIP_UNUSED_ARG(inner_conn); /* for LWIP_NOASSERT */
|
||||
|
||||
if (!state || !(state->flags & ALTCP_PROXYCONNECT_FLAGS_HANDSHAKE_DONE)) {
|
||||
/* @todo: do something here? */
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/* pass this on to upper sent */
|
||||
if (conn->sent) {
|
||||
return conn->sent(conn->arg, conn, len);
|
||||
}
|
||||
struct altcp_pcb *conn = (struct altcp_pcb *)arg;
|
||||
LWIP_UNUSED_ARG(len);
|
||||
if (conn) {
|
||||
altcp_proxyconnect_state_t *state = (altcp_proxyconnect_state_t *)conn->state;
|
||||
LWIP_ASSERT("pcb mismatch", conn->inner_conn == inner_conn);
|
||||
LWIP_UNUSED_ARG(inner_conn); /* for LWIP_NOASSERT */
|
||||
if (!state || !(state->flags & ALTCP_PROXYCONNECT_FLAGS_HANDSHAKE_DONE)) {
|
||||
/* @todo: do something here? */
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
/* pass this on to upper sent */
|
||||
if (conn->sent) {
|
||||
return conn->sent(conn->arg, conn, len);
|
||||
}
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/** Poll callback from lower connection (i.e. TCP)
|
||||
* Just pass this on to the application.
|
||||
* @todo: retry sending?
|
||||
*/
|
||||
static err_t altcp_proxyconnect_lower_poll(void *arg, struct altcp_pcb *inner_conn)
|
||||
static err_t
|
||||
altcp_proxyconnect_lower_poll(void *arg, struct altcp_pcb *inner_conn)
|
||||
{
|
||||
struct altcp_pcb *conn = (struct altcp_pcb *)arg;
|
||||
|
||||
if (conn) {
|
||||
LWIP_ASSERT("pcb mismatch", conn->inner_conn == inner_conn);
|
||||
LWIP_UNUSED_ARG(inner_conn); /* for LWIP_NOASSERT */
|
||||
|
||||
if (conn->poll) {
|
||||
return conn->poll(conn->arg, conn);
|
||||
}
|
||||
struct altcp_pcb *conn = (struct altcp_pcb *)arg;
|
||||
if (conn) {
|
||||
LWIP_ASSERT("pcb mismatch", conn->inner_conn == inner_conn);
|
||||
LWIP_UNUSED_ARG(inner_conn); /* for LWIP_NOASSERT */
|
||||
if (conn->poll) {
|
||||
return conn->poll(conn->arg, conn);
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static void altcp_proxyconnect_lower_err(void *arg, err_t err)
|
||||
static void
|
||||
altcp_proxyconnect_lower_err(void *arg, err_t err)
|
||||
{
|
||||
struct altcp_pcb *conn = (struct altcp_pcb *)arg;
|
||||
|
||||
if (conn) {
|
||||
conn->inner_conn = NULL; /* already freed */
|
||||
|
||||
if (conn->err) {
|
||||
conn->err(conn->arg, err);
|
||||
}
|
||||
|
||||
altcp_free(conn);
|
||||
struct altcp_pcb *conn = (struct altcp_pcb *)arg;
|
||||
if (conn) {
|
||||
conn->inner_conn = NULL; /* already freed */
|
||||
if (conn->err) {
|
||||
conn->err(conn->arg, err);
|
||||
}
|
||||
altcp_free(conn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* setup functions */
|
||||
|
||||
static void altcp_proxyconnect_setup_callbacks(struct altcp_pcb *conn, struct altcp_pcb *inner_conn)
|
||||
static void
|
||||
altcp_proxyconnect_setup_callbacks(struct altcp_pcb *conn, struct altcp_pcb *inner_conn)
|
||||
{
|
||||
altcp_arg(inner_conn, conn);
|
||||
altcp_recv(inner_conn, altcp_proxyconnect_lower_recv);
|
||||
altcp_sent(inner_conn, altcp_proxyconnect_lower_sent);
|
||||
altcp_err(inner_conn, altcp_proxyconnect_lower_err);
|
||||
/* tcp_poll is set when interval is set by application */
|
||||
/* listen is set totally different :-) */
|
||||
altcp_arg(inner_conn, conn);
|
||||
altcp_recv(inner_conn, altcp_proxyconnect_lower_recv);
|
||||
altcp_sent(inner_conn, altcp_proxyconnect_lower_sent);
|
||||
altcp_err(inner_conn, altcp_proxyconnect_lower_err);
|
||||
/* tcp_poll is set when interval is set by application */
|
||||
/* listen is set totally different :-) */
|
||||
}
|
||||
|
||||
static err_t altcp_proxyconnect_setup(struct altcp_proxyconnect_config *config, struct altcp_pcb *conn, struct altcp_pcb *inner_conn)
|
||||
static err_t
|
||||
altcp_proxyconnect_setup(struct altcp_proxyconnect_config *config, struct altcp_pcb *conn, struct altcp_pcb *inner_conn)
|
||||
{
|
||||
altcp_proxyconnect_state_t *state;
|
||||
altcp_proxyconnect_state_t *state;
|
||||
if (!config) {
|
||||
return ERR_ARG;
|
||||
}
|
||||
LWIP_ASSERT("invalid inner_conn", conn != inner_conn);
|
||||
|
||||
if (!config) {
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
LWIP_ASSERT("invalid inner_conn", conn != inner_conn);
|
||||
|
||||
/* allocate proxyconnect context */
|
||||
state = altcp_proxyconnect_state_alloc();
|
||||
|
||||
if (state == NULL) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
state->flags = 0;
|
||||
state->conf = config;
|
||||
altcp_proxyconnect_setup_callbacks(conn, inner_conn);
|
||||
conn->inner_conn = inner_conn;
|
||||
conn->fns = &altcp_proxyconnect_functions;
|
||||
conn->state = state;
|
||||
return ERR_OK;
|
||||
/* allocate proxyconnect context */
|
||||
state = altcp_proxyconnect_state_alloc();
|
||||
if (state == NULL) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
state->flags = 0;
|
||||
state->conf = config;
|
||||
altcp_proxyconnect_setup_callbacks(conn, inner_conn);
|
||||
conn->inner_conn = inner_conn;
|
||||
conn->fns = &altcp_proxyconnect_functions;
|
||||
conn->state = state;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/** Allocate a new altcp layer connecting through a proxy.
|
||||
@ -371,22 +345,18 @@ static err_t altcp_proxyconnect_setup(struct altcp_proxyconnect_config *config,
|
||||
struct altcp_pcb *
|
||||
altcp_proxyconnect_new(struct altcp_proxyconnect_config *config, struct altcp_pcb *inner_pcb)
|
||||
{
|
||||
struct altcp_pcb *ret;
|
||||
|
||||
if (inner_pcb == NULL) {
|
||||
return NULL;
|
||||
struct altcp_pcb *ret;
|
||||
if (inner_pcb == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
ret = altcp_alloc();
|
||||
if (ret != NULL) {
|
||||
if (altcp_proxyconnect_setup(config, ret, inner_pcb) != ERR_OK) {
|
||||
altcp_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = altcp_alloc();
|
||||
|
||||
if (ret != NULL) {
|
||||
if (altcp_proxyconnect_setup(config, ret, inner_pcb) != ERR_OK) {
|
||||
altcp_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** Allocate a new altcp layer connecting through a proxy.
|
||||
@ -399,22 +369,18 @@ altcp_proxyconnect_new(struct altcp_proxyconnect_config *config, struct altcp_pc
|
||||
struct altcp_pcb *
|
||||
altcp_proxyconnect_new_tcp(struct altcp_proxyconnect_config *config, u8_t ip_type)
|
||||
{
|
||||
struct altcp_pcb *inner_pcb, *ret;
|
||||
struct altcp_pcb *inner_pcb, *ret;
|
||||
|
||||
/* inner pcb is tcp */
|
||||
inner_pcb = altcp_tcp_new_ip_type(ip_type);
|
||||
|
||||
if (inner_pcb == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = altcp_proxyconnect_new(config, inner_pcb);
|
||||
|
||||
if (ret == NULL) {
|
||||
altcp_close(inner_pcb);
|
||||
}
|
||||
|
||||
return ret;
|
||||
/* inner pcb is tcp */
|
||||
inner_pcb = altcp_tcp_new_ip_type(ip_type);
|
||||
if (inner_pcb == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
ret = altcp_proxyconnect_new(config, inner_pcb);
|
||||
if (ret == NULL) {
|
||||
altcp_close(inner_pcb);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** Allocator function to allocate a proxy connect altcp pcb connecting directly
|
||||
@ -430,9 +396,10 @@ altcp_proxyconnect_new_tcp(struct altcp_proxyconnect_config *config, u8_t ip_typ
|
||||
struct altcp_pcb *
|
||||
altcp_proxyconnect_alloc(void *arg, u8_t ip_type)
|
||||
{
|
||||
return altcp_proxyconnect_new_tcp((struct altcp_proxyconnect_config *)arg, ip_type);
|
||||
return altcp_proxyconnect_new_tcp((struct altcp_proxyconnect_config *)arg, ip_type);
|
||||
}
|
||||
|
||||
|
||||
#if LWIP_ALTCP_TLS
|
||||
|
||||
/** Allocator function to allocate a TLS connection through a proxy.
|
||||
@ -448,180 +415,169 @@ altcp_proxyconnect_alloc(void *arg, u8_t ip_type)
|
||||
struct altcp_pcb *
|
||||
altcp_proxyconnect_tls_alloc(void *arg, u8_t ip_type)
|
||||
{
|
||||
struct altcp_proxyconnect_tls_config *cfg = (struct altcp_proxyconnect_tls_config *)arg;
|
||||
struct altcp_pcb *proxy_pcb;
|
||||
struct altcp_pcb *tls_pcb;
|
||||
struct altcp_proxyconnect_tls_config *cfg = (struct altcp_proxyconnect_tls_config *)arg;
|
||||
struct altcp_pcb *proxy_pcb;
|
||||
struct altcp_pcb *tls_pcb;
|
||||
|
||||
proxy_pcb = altcp_proxyconnect_new_tcp(&cfg->proxy, ip_type);
|
||||
tls_pcb = altcp_tls_wrap(cfg->tls_config, proxy_pcb);
|
||||
proxy_pcb = altcp_proxyconnect_new_tcp(&cfg->proxy, ip_type);
|
||||
tls_pcb = altcp_tls_wrap(cfg->tls_config, proxy_pcb);
|
||||
|
||||
if (tls_pcb == NULL) {
|
||||
altcp_close(proxy_pcb);
|
||||
}
|
||||
|
||||
return tls_pcb;
|
||||
if (tls_pcb == NULL) {
|
||||
altcp_close(proxy_pcb);
|
||||
}
|
||||
return tls_pcb;
|
||||
}
|
||||
#endif /* LWIP_ALTCP_TLS */
|
||||
|
||||
/* "virtual" functions */
|
||||
static void altcp_proxyconnect_set_poll(struct altcp_pcb *conn, u8_t interval)
|
||||
static void
|
||||
altcp_proxyconnect_set_poll(struct altcp_pcb *conn, u8_t interval)
|
||||
{
|
||||
if (conn != NULL) {
|
||||
altcp_poll(conn->inner_conn, altcp_proxyconnect_lower_poll, interval);
|
||||
}
|
||||
if (conn != NULL) {
|
||||
altcp_poll(conn->inner_conn, altcp_proxyconnect_lower_poll, interval);
|
||||
}
|
||||
}
|
||||
|
||||
static void altcp_proxyconnect_recved(struct altcp_pcb *conn, u16_t len)
|
||||
static void
|
||||
altcp_proxyconnect_recved(struct altcp_pcb *conn, u16_t len)
|
||||
{
|
||||
altcp_proxyconnect_state_t *state;
|
||||
|
||||
if (conn == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
state = (altcp_proxyconnect_state_t *)conn->state;
|
||||
|
||||
if (state == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(state->flags & ALTCP_PROXYCONNECT_FLAGS_HANDSHAKE_DONE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
altcp_recved(conn->inner_conn, len);
|
||||
altcp_proxyconnect_state_t *state;
|
||||
if (conn == NULL) {
|
||||
return;
|
||||
}
|
||||
state = (altcp_proxyconnect_state_t *)conn->state;
|
||||
if (state == NULL) {
|
||||
return;
|
||||
}
|
||||
if (!(state->flags & ALTCP_PROXYCONNECT_FLAGS_HANDSHAKE_DONE)) {
|
||||
return;
|
||||
}
|
||||
altcp_recved(conn->inner_conn, len);
|
||||
}
|
||||
|
||||
static err_t altcp_proxyconnect_connect(struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port, altcp_connected_fn connected)
|
||||
static err_t
|
||||
altcp_proxyconnect_connect(struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port, altcp_connected_fn connected)
|
||||
{
|
||||
altcp_proxyconnect_state_t *state;
|
||||
altcp_proxyconnect_state_t *state;
|
||||
|
||||
if ((conn == NULL) || (ipaddr == NULL)) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
if ((conn == NULL) || (ipaddr == NULL)) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
state = (altcp_proxyconnect_state_t *)conn->state;
|
||||
if (state == NULL) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
if (state->flags & ALTCP_PROXYCONNECT_FLAGS_CONNECT_STARTED) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
state->flags |= ALTCP_PROXYCONNECT_FLAGS_CONNECT_STARTED;
|
||||
|
||||
state = (altcp_proxyconnect_state_t *)conn->state;
|
||||
conn->connected = connected;
|
||||
/* connect to our proxy instead, but store the requested address and port */
|
||||
ip_addr_copy(state->outer_addr, *ipaddr);
|
||||
state->outer_port = port;
|
||||
|
||||
if (state == NULL) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
if (state->flags & ALTCP_PROXYCONNECT_FLAGS_CONNECT_STARTED) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
state->flags |= ALTCP_PROXYCONNECT_FLAGS_CONNECT_STARTED;
|
||||
|
||||
conn->connected = connected;
|
||||
/* connect to our proxy instead, but store the requested address and port */
|
||||
ip_addr_copy(state->outer_addr, *ipaddr);
|
||||
state->outer_port = port;
|
||||
|
||||
return altcp_connect(conn->inner_conn, &state->conf->proxy_addr, state->conf->proxy_port, altcp_proxyconnect_lower_connected);
|
||||
return altcp_connect(conn->inner_conn, &state->conf->proxy_addr, state->conf->proxy_port, altcp_proxyconnect_lower_connected);
|
||||
}
|
||||
|
||||
static struct altcp_pcb *altcp_proxyconnect_listen(struct altcp_pcb *conn, u8_t backlog, err_t *err)
|
||||
static struct altcp_pcb *
|
||||
altcp_proxyconnect_listen(struct altcp_pcb *conn, u8_t backlog, err_t *err)
|
||||
{
|
||||
LWIP_UNUSED_ARG(conn);
|
||||
LWIP_UNUSED_ARG(backlog);
|
||||
LWIP_UNUSED_ARG(err);
|
||||
/* listen not supported! */
|
||||
return NULL;
|
||||
LWIP_UNUSED_ARG(conn);
|
||||
LWIP_UNUSED_ARG(backlog);
|
||||
LWIP_UNUSED_ARG(err);
|
||||
/* listen not supported! */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void altcp_proxyconnect_abort(struct altcp_pcb *conn)
|
||||
static void
|
||||
altcp_proxyconnect_abort(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn != NULL) {
|
||||
if (conn->inner_conn != NULL) {
|
||||
altcp_abort(conn->inner_conn);
|
||||
}
|
||||
|
||||
altcp_free(conn);
|
||||
}
|
||||
}
|
||||
|
||||
static err_t altcp_proxyconnect_close(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn == NULL) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
if (conn != NULL) {
|
||||
if (conn->inner_conn != NULL) {
|
||||
err_t err = altcp_close(conn->inner_conn);
|
||||
|
||||
if (err != ERR_OK) {
|
||||
/* closing inner conn failed, return the error */
|
||||
return err;
|
||||
}
|
||||
altcp_abort(conn->inner_conn);
|
||||
}
|
||||
|
||||
/* no inner conn or closing it succeeded, deallocate myself */
|
||||
altcp_free(conn);
|
||||
return ERR_OK;
|
||||
}
|
||||
}
|
||||
|
||||
static err_t altcp_proxyconnect_write(struct altcp_pcb *conn, const void *dataptr, u16_t len, u8_t apiflags)
|
||||
static err_t
|
||||
altcp_proxyconnect_close(struct altcp_pcb *conn)
|
||||
{
|
||||
altcp_proxyconnect_state_t *state;
|
||||
|
||||
LWIP_UNUSED_ARG(apiflags);
|
||||
|
||||
if (conn == NULL) {
|
||||
return ERR_VAL;
|
||||
if (conn == NULL) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
if (conn->inner_conn != NULL) {
|
||||
err_t err = altcp_close(conn->inner_conn);
|
||||
if (err != ERR_OK) {
|
||||
/* closing inner conn failed, return the error */
|
||||
return err;
|
||||
}
|
||||
|
||||
state = (altcp_proxyconnect_state_t *)conn->state;
|
||||
|
||||
if (state == NULL) {
|
||||
/* @todo: which error? */
|
||||
return ERR_CLSD;
|
||||
}
|
||||
|
||||
if (!(state->flags & ALTCP_PROXYCONNECT_FLAGS_HANDSHAKE_DONE)) {
|
||||
/* @todo: which error? */
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
return altcp_write(conn->inner_conn, dataptr, len, apiflags);
|
||||
}
|
||||
/* no inner conn or closing it succeeded, deallocate myself */
|
||||
altcp_free(conn);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static void altcp_proxyconnect_dealloc(struct altcp_pcb *conn)
|
||||
static err_t
|
||||
altcp_proxyconnect_write(struct altcp_pcb *conn, const void *dataptr, u16_t len, u8_t apiflags)
|
||||
{
|
||||
/* clean up and free tls state */
|
||||
if (conn) {
|
||||
altcp_proxyconnect_state_t *state = (altcp_proxyconnect_state_t *)conn->state;
|
||||
altcp_proxyconnect_state_t *state;
|
||||
|
||||
if (state) {
|
||||
altcp_proxyconnect_state_free(state);
|
||||
conn->state = NULL;
|
||||
}
|
||||
LWIP_UNUSED_ARG(apiflags);
|
||||
|
||||
if (conn == NULL) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
state = (altcp_proxyconnect_state_t *)conn->state;
|
||||
if (state == NULL) {
|
||||
/* @todo: which error? */
|
||||
return ERR_CLSD;
|
||||
}
|
||||
if (!(state->flags & ALTCP_PROXYCONNECT_FLAGS_HANDSHAKE_DONE)) {
|
||||
/* @todo: which error? */
|
||||
return ERR_VAL;
|
||||
}
|
||||
return altcp_write(conn->inner_conn, dataptr, len, apiflags);
|
||||
}
|
||||
|
||||
static void
|
||||
altcp_proxyconnect_dealloc(struct altcp_pcb *conn)
|
||||
{
|
||||
/* clean up and free tls state */
|
||||
if (conn) {
|
||||
altcp_proxyconnect_state_t *state = (altcp_proxyconnect_state_t *)conn->state;
|
||||
if (state) {
|
||||
altcp_proxyconnect_state_free(state);
|
||||
conn->state = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
const struct altcp_functions altcp_proxyconnect_functions = {
|
||||
altcp_proxyconnect_set_poll,
|
||||
altcp_proxyconnect_recved,
|
||||
altcp_default_bind,
|
||||
altcp_proxyconnect_connect,
|
||||
altcp_proxyconnect_listen,
|
||||
altcp_proxyconnect_abort,
|
||||
altcp_proxyconnect_close,
|
||||
altcp_default_shutdown,
|
||||
altcp_proxyconnect_write,
|
||||
altcp_default_output,
|
||||
altcp_default_mss,
|
||||
altcp_default_sndbuf,
|
||||
altcp_default_sndqueuelen,
|
||||
altcp_default_nagle_disable,
|
||||
altcp_default_nagle_enable,
|
||||
altcp_default_nagle_disabled,
|
||||
altcp_default_setprio,
|
||||
altcp_proxyconnect_dealloc,
|
||||
altcp_default_get_tcp_addrinfo,
|
||||
altcp_default_get_ip,
|
||||
altcp_default_get_port
|
||||
altcp_proxyconnect_set_poll,
|
||||
altcp_proxyconnect_recved,
|
||||
altcp_default_bind,
|
||||
altcp_proxyconnect_connect,
|
||||
altcp_proxyconnect_listen,
|
||||
altcp_proxyconnect_abort,
|
||||
altcp_proxyconnect_close,
|
||||
altcp_default_shutdown,
|
||||
altcp_proxyconnect_write,
|
||||
altcp_default_output,
|
||||
altcp_default_mss,
|
||||
altcp_default_sndbuf,
|
||||
altcp_default_sndqueuelen,
|
||||
altcp_default_nagle_disable,
|
||||
altcp_default_nagle_enable,
|
||||
altcp_default_nagle_disabled,
|
||||
altcp_default_setprio,
|
||||
altcp_proxyconnect_dealloc,
|
||||
altcp_default_get_tcp_addrinfo,
|
||||
altcp_default_get_ip,
|
||||
altcp_default_get_port
|
||||
#ifdef LWIP_DEBUG
|
||||
,
|
||||
altcp_default_dbg_get_tcp_state
|
||||
, altcp_default_dbg_get_tcp_state
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "lwip/apps/fs.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
#include HTTPD_FSDATA_FILE
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
@ -52,129 +53,122 @@ int fs_read_custom(struct fs_file *file, char *buffer, int count);
|
||||
#endif /* LWIP_HTTPD_CUSTOM_FILES */
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
err_t fs_open(struct fs_file *file, const char *name)
|
||||
err_t
|
||||
fs_open(struct fs_file *file, const char *name)
|
||||
{
|
||||
const struct fsdata_file *f;
|
||||
const struct fsdata_file *f;
|
||||
|
||||
if ((file == NULL) || (name == NULL)) {
|
||||
return ERR_ARG;
|
||||
}
|
||||
if ((file == NULL) || (name == NULL)) {
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
#if LWIP_HTTPD_CUSTOM_FILES
|
||||
|
||||
if (fs_open_custom(file, name)) {
|
||||
file->is_custom_file = 1;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
file->is_custom_file = 0;
|
||||
if (fs_open_custom(file, name)) {
|
||||
file->is_custom_file = 1;
|
||||
return ERR_OK;
|
||||
}
|
||||
file->is_custom_file = 0;
|
||||
#endif /* LWIP_HTTPD_CUSTOM_FILES */
|
||||
|
||||
for (f = FS_ROOT; f != NULL; f = f->next) {
|
||||
if (!strcmp(name, (const char *)f->name)) {
|
||||
file->data = (const char *)f->data;
|
||||
file->len = f->len;
|
||||
file->index = f->len;
|
||||
file->pextension = NULL;
|
||||
file->flags = f->flags;
|
||||
for (f = FS_ROOT; f != NULL; f = f->next) {
|
||||
if (!strcmp(name, (const char *)f->name)) {
|
||||
file->data = (const char *)f->data;
|
||||
file->len = f->len;
|
||||
file->index = f->len;
|
||||
file->pextension = NULL;
|
||||
file->flags = f->flags;
|
||||
#if HTTPD_PRECALCULATED_CHECKSUM
|
||||
file->chksum_count = f->chksum_count;
|
||||
file->chksum = f->chksum;
|
||||
file->chksum_count = f->chksum_count;
|
||||
file->chksum = f->chksum;
|
||||
#endif /* HTTPD_PRECALCULATED_CHECKSUM */
|
||||
#if LWIP_HTTPD_FILE_STATE
|
||||
file->state = fs_state_init(file, name);
|
||||
file->state = fs_state_init(file, name);
|
||||
#endif /* #if LWIP_HTTPD_FILE_STATE */
|
||||
return ERR_OK;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/* file not found */
|
||||
return ERR_VAL;
|
||||
}
|
||||
/* file not found */
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void fs_close(struct fs_file *file)
|
||||
void
|
||||
fs_close(struct fs_file *file)
|
||||
{
|
||||
#if LWIP_HTTPD_CUSTOM_FILES
|
||||
|
||||
if (file->is_custom_file) {
|
||||
fs_close_custom(file);
|
||||
}
|
||||
|
||||
if (file->is_custom_file) {
|
||||
fs_close_custom(file);
|
||||
}
|
||||
#endif /* LWIP_HTTPD_CUSTOM_FILES */
|
||||
#if LWIP_HTTPD_FILE_STATE
|
||||
fs_state_free(file, file->state);
|
||||
fs_state_free(file, file->state);
|
||||
#endif /* #if LWIP_HTTPD_FILE_STATE */
|
||||
LWIP_UNUSED_ARG(file);
|
||||
LWIP_UNUSED_ARG(file);
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#if LWIP_HTTPD_DYNAMIC_FILE_READ
|
||||
#if LWIP_HTTPD_FS_ASYNC_READ
|
||||
int fs_read_async(struct fs_file *file, char *buffer, int count, fs_wait_cb callback_fn, void *callback_arg)
|
||||
int
|
||||
fs_read_async(struct fs_file *file, char *buffer, int count, fs_wait_cb callback_fn, void *callback_arg)
|
||||
#else /* LWIP_HTTPD_FS_ASYNC_READ */
|
||||
int fs_read(struct fs_file *file, char *buffer, int count)
|
||||
int
|
||||
fs_read(struct fs_file *file, char *buffer, int count)
|
||||
#endif /* LWIP_HTTPD_FS_ASYNC_READ */
|
||||
{
|
||||
int read;
|
||||
|
||||
if (file->index == file->len) {
|
||||
return FS_READ_EOF;
|
||||
}
|
||||
|
||||
int read;
|
||||
if (file->index == file->len) {
|
||||
return FS_READ_EOF;
|
||||
}
|
||||
#if LWIP_HTTPD_FS_ASYNC_READ
|
||||
LWIP_UNUSED_ARG(callback_fn);
|
||||
LWIP_UNUSED_ARG(callback_arg);
|
||||
LWIP_UNUSED_ARG(callback_fn);
|
||||
LWIP_UNUSED_ARG(callback_arg);
|
||||
#endif /* LWIP_HTTPD_FS_ASYNC_READ */
|
||||
#if LWIP_HTTPD_CUSTOM_FILES
|
||||
|
||||
if (file->is_custom_file) {
|
||||
if (file->is_custom_file) {
|
||||
#if LWIP_HTTPD_FS_ASYNC_READ
|
||||
return fs_read_async_custom(file, buffer, count, callback_fn, callback_arg);
|
||||
return fs_read_async_custom(file, buffer, count, callback_fn, callback_arg);
|
||||
#else /* LWIP_HTTPD_FS_ASYNC_READ */
|
||||
return fs_read_custom(file, buffer, count);
|
||||
return fs_read_custom(file, buffer, count);
|
||||
#endif /* LWIP_HTTPD_FS_ASYNC_READ */
|
||||
}
|
||||
|
||||
}
|
||||
#endif /* LWIP_HTTPD_CUSTOM_FILES */
|
||||
|
||||
read = file->len - file->index;
|
||||
read = file->len - file->index;
|
||||
if (read > count) {
|
||||
read = count;
|
||||
}
|
||||
|
||||
if (read > count) {
|
||||
read = count;
|
||||
}
|
||||
MEMCPY(buffer, (file->data + file->index), read);
|
||||
file->index += read;
|
||||
|
||||
MEMCPY(buffer, (file->data + file->index), read);
|
||||
file->index += read;
|
||||
|
||||
return (read);
|
||||
return (read);
|
||||
}
|
||||
#endif /* LWIP_HTTPD_DYNAMIC_FILE_READ */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
#if LWIP_HTTPD_FS_ASYNC_READ
|
||||
int fs_is_file_ready(struct fs_file *file, fs_wait_cb callback_fn, void *callback_arg)
|
||||
int
|
||||
fs_is_file_ready(struct fs_file *file, fs_wait_cb callback_fn, void *callback_arg)
|
||||
{
|
||||
if (file != NULL) {
|
||||
if (file != NULL) {
|
||||
#if LWIP_HTTPD_FS_ASYNC_READ
|
||||
#if LWIP_HTTPD_CUSTOM_FILES
|
||||
|
||||
if (!fs_canread_custom(file)) {
|
||||
if (fs_wait_read_custom(file, callback_fn, callback_arg)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!fs_canread_custom(file)) {
|
||||
if (fs_wait_read_custom(file, callback_fn, callback_arg)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#else /* LWIP_HTTPD_CUSTOM_FILES */
|
||||
LWIP_UNUSED_ARG(callback_fn);
|
||||
LWIP_UNUSED_ARG(callback_arg);
|
||||
LWIP_UNUSED_ARG(callback_fn);
|
||||
LWIP_UNUSED_ARG(callback_arg);
|
||||
#endif /* LWIP_HTTPD_CUSTOM_FILES */
|
||||
#endif /* LWIP_HTTPD_FS_ASYNC_READ */
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif /* LWIP_HTTPD_FS_ASYNC_READ */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
int fs_bytes_left(struct fs_file *file)
|
||||
int
|
||||
fs_bytes_left(struct fs_file *file)
|
||||
{
|
||||
return file->len - file->index;
|
||||
return file->len - file->index;
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
#include "lwip/apps/fs.h"
|
||||
#include "lwip/def.h"
|
||||
|
||||
#define file_NULL (struct fsdata_file *)NULL
|
||||
|
||||
#define file_NULL (struct fsdata_file *) NULL
|
||||
|
||||
|
||||
#ifndef FS_FILE_FLAGS_HEADER_INCLUDED
|
||||
#define FS_FILE_FLAGS_HEADER_INCLUDED 1
|
||||
@ -19,14 +21,12 @@
|
||||
#ifndef FSDATA_ALIGN_POST
|
||||
#define FSDATA_ALIGN_POST
|
||||
#endif
|
||||
#if FSDATA_FILE_ALIGNMENT == 2
|
||||
#if FSDATA_FILE_ALIGNMENT==2
|
||||
#include "fsdata_alignment.h"
|
||||
#endif
|
||||
#if FSDATA_FILE_ALIGNMENT == 1
|
||||
#if FSDATA_FILE_ALIGNMENT==1
|
||||
static const unsigned int dummy_align__img_sics_gif = 0;
|
||||
#endif
|
||||
// clang-format off
|
||||
|
||||
static const unsigned char FSDATA_ALIGN_PRE data__img_sics_gif[] FSDATA_ALIGN_POST = {
|
||||
/* /img/sics.gif (14 chars) */
|
||||
0x2f,0x69,0x6d,0x67,0x2f,0x73,0x69,0x63,0x73,0x2e,0x67,0x69,0x66,0x00,0x00,0x00,
|
||||
@ -306,31 +306,32 @@ static const unsigned char FSDATA_ALIGN_PRE data__index_html[] FSDATA_ALIGN_POST
|
||||
0x3e,0x0d,0x0a,0x3c,0x2f,0x62,0x6f,0x64,0x79,0x3e,0x0d,0x0a,0x3c,0x2f,0x68,0x74,
|
||||
0x6d,0x6c,0x3e,0x0d,0x0a,0x0d,0x0a,};
|
||||
|
||||
// clang-format on
|
||||
|
||||
|
||||
const struct fsdata_file file__img_sics_gif[] = { {
|
||||
file_NULL,
|
||||
data__img_sics_gif,
|
||||
data__img_sics_gif + 16,
|
||||
sizeof(data__img_sics_gif) - 16,
|
||||
FS_FILE_FLAGS_HEADER_INCLUDED | FS_FILE_FLAGS_HEADER_PERSISTENT,
|
||||
} };
|
||||
file_NULL,
|
||||
data__img_sics_gif,
|
||||
data__img_sics_gif + 16,
|
||||
sizeof(data__img_sics_gif) - 16,
|
||||
FS_FILE_FLAGS_HEADER_INCLUDED | FS_FILE_FLAGS_HEADER_PERSISTENT,
|
||||
}};
|
||||
|
||||
const struct fsdata_file file__404_html[] = { {
|
||||
file__img_sics_gif,
|
||||
data__404_html,
|
||||
data__404_html + 12,
|
||||
sizeof(data__404_html) - 12,
|
||||
FS_FILE_FLAGS_HEADER_INCLUDED | FS_FILE_FLAGS_HEADER_PERSISTENT,
|
||||
} };
|
||||
file__img_sics_gif,
|
||||
data__404_html,
|
||||
data__404_html + 12,
|
||||
sizeof(data__404_html) - 12,
|
||||
FS_FILE_FLAGS_HEADER_INCLUDED | FS_FILE_FLAGS_HEADER_PERSISTENT,
|
||||
}};
|
||||
|
||||
const struct fsdata_file file__index_html[] = { {
|
||||
file__404_html,
|
||||
data__index_html,
|
||||
data__index_html + 12,
|
||||
sizeof(data__index_html) - 12,
|
||||
FS_FILE_FLAGS_HEADER_INCLUDED | FS_FILE_FLAGS_HEADER_PERSISTENT,
|
||||
} };
|
||||
file__404_html,
|
||||
data__index_html,
|
||||
data__index_html + 12,
|
||||
sizeof(data__index_html) - 12,
|
||||
FS_FILE_FLAGS_HEADER_INCLUDED | FS_FILE_FLAGS_HEADER_PERSISTENT,
|
||||
}};
|
||||
|
||||
#define FS_ROOT file__index_html
|
||||
#define FS_ROOT file__index_html
|
||||
#define FS_NUMFILES 3
|
||||
|
||||
|
@ -1,794 +0,0 @@
|
||||
#include "lwip/apps/fs.h"
|
||||
#include "lwip/def.h"
|
||||
|
||||
#define file_NULL (struct fsdata_file *)NULL
|
||||
|
||||
// clang-format off
|
||||
#ifndef FS_FILE_FLAGS_HEADER_INCLUDED
|
||||
#define FS_FILE_FLAGS_HEADER_INCLUDED 1
|
||||
#endif
|
||||
#ifndef FS_FILE_FLAGS_HEADER_PERSISTENT
|
||||
#define FS_FILE_FLAGS_HEADER_PERSISTENT 0
|
||||
#endif
|
||||
/* FSDATA_FILE_ALIGNMENT: 0=off, 1=by variable, 2=by include */
|
||||
#ifndef FSDATA_FILE_ALIGNMENT
|
||||
#define FSDATA_FILE_ALIGNMENT 0
|
||||
#endif
|
||||
#ifndef FSDATA_ALIGN_PRE
|
||||
#define FSDATA_ALIGN_PRE
|
||||
#endif
|
||||
#ifndef FSDATA_ALIGN_POST
|
||||
#define FSDATA_ALIGN_POST
|
||||
#endif
|
||||
#if FSDATA_FILE_ALIGNMENT==2
|
||||
#include "fsdata_alignment.h"
|
||||
#endif
|
||||
#if FSDATA_FILE_ALIGNMENT==1
|
||||
static const unsigned int dummy_align__asset_favicon_ico = 0;
|
||||
#endif
|
||||
static const unsigned char FSDATA_ALIGN_PRE data__asset_favicon_ico[] FSDATA_ALIGN_POST = {
|
||||
/* /asset/favicon.ico (19z chars) */
|
||||
0x2f,0x61,0x73,0x73,0x65,0x74,0x2f,0x66,0x61,0x76,0x69,0x63,0x6f,0x6e,0x2e,0x69,
|
||||
0x63,0x6f,0x00,0x00,
|
||||
|
||||
/* HTTP header */
|
||||
/* "HTTP/1.0 200 OK
|
||||
" (17z bytes) */
|
||||
0x48,0x54,0x54,0x50,0x2f,0x31,0x2e,0x30,0x20,0x32,0x30,0x30,0x20,0x4f,0x4b,0x0d,
|
||||
0x0a,
|
||||
/* "Server: lwIP/2.1.3d (http://savannah.nongnu.org/projects/lwip)
|
||||
" (64z bytes) */
|
||||
0x53,0x65,0x72,0x76,0x65,0x72,0x3a,0x20,0x6c,0x77,0x49,0x50,0x2f,0x32,0x2e,0x31,
|
||||
0x2e,0x33,0x64,0x20,0x28,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x73,0x61,0x76,0x61,
|
||||
0x6e,0x6e,0x61,0x68,0x2e,0x6e,0x6f,0x6e,0x67,0x6e,0x75,0x2e,0x6f,0x72,0x67,0x2f,
|
||||
0x70,0x72,0x6f,0x6a,0x65,0x63,0x74,0x73,0x2f,0x6c,0x77,0x69,0x70,0x29,0x0d,0x0a,
|
||||
|
||||
/* "Content-Length: 1935
|
||||
" (18z+ bytes) */
|
||||
0x43,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x2d,0x4c,0x65,0x6e,0x67,0x74,0x68,0x3a,0x20,
|
||||
0x31,0x39,0x33,0x35,0x0d,0x0a,
|
||||
/* "Content-Type: image/x-icon
|
||||
|
||||
" (30z bytes) */
|
||||
0x43,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x2d,0x54,0x79,0x70,0x65,0x3a,0x20,0x69,0x6d,
|
||||
0x61,0x67,0x65,0x2f,0x78,0x2d,0x69,0x63,0x6f,0x6e,0x0d,0x0a,0x0d,0x0a,
|
||||
/* raw file data (1935 bytes) */
|
||||
0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
|
||||
0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x30,0x08,0x06,0x00,0x00,0x00,0x57,0x02,0xf9,
|
||||
0x87,0x00,0x00,0x00,0x01,0x73,0x52,0x47,0x42,0x01,0xd9,0xc9,0x2c,0x7f,0x00,0x00,
|
||||
0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0e,0xc4,0x00,0x00,0x0e,0xc4,0x01,0x95,
|
||||
0x2b,0x0e,0x1b,0x00,0x00,0x07,0x34,0x49,0x44,0x41,0x54,0x78,0x9c,0xad,0x59,0x7b,
|
||||
0x6c,0x14,0x45,0x18,0xdf,0x5e,0x4b,0x4a,0x85,0x02,0x0d,0xc1,0x48,0x28,0x18,0xfe,
|
||||
0x01,0x0d,0x2d,0xbd,0xbd,0xf8,0x87,0x8a,0x89,0x51,0xb4,0xca,0x43,0xa0,0x05,0x54,
|
||||
0x4c,0x00,0xa5,0x14,0x48,0x4c,0xa3,0x08,0x04,0xb8,0xbe,0x68,0xf7,0x14,0xb0,0x2d,
|
||||
0x14,0xdb,0x02,0x55,0x02,0xad,0x06,0x49,0xa4,0xe5,0xd1,0xda,0x07,0x2d,0x7b,0x6a,
|
||||
0xe5,0x9a,0x0a,0x55,0x93,0x23,0x62,0x9b,0x90,0x14,0xa3,0x98,0xa0,0x31,0x3e,0x6a,
|
||||
0x00,0x51,0xc1,0xdf,0xec,0x3d,0xd8,0x9d,0xfb,0x66,0x76,0x0f,0xdc,0xe4,0x97,0x6f,
|
||||
0xf6,0x9b,0x99,0x6f,0x7e,0xdf,0x63,0x66,0x77,0xef,0x14,0x45,0x51,0x12,0x08,0xb8,
|
||||
0xc2,0x52,0x31,0xe9,0x14,0xee,0xde,0xdc,0x4f,0xe9,0x15,0xae,0xcd,0x8f,0x91,0xad,
|
||||
0x2b,0xeb,0xe7,0xc7,0x48,0x0d,0x8b,0x08,0x8a,0xc6,0x89,0xe6,0x3a,0x21,0x2f,0xb3,
|
||||
0x49,0x11,0x8f,0xe8,0x2d,0x03,0x79,0xc2,0x4e,0xa2,0x28,0x73,0x92,0xb2,0x6d,0x8e,
|
||||
0xb4,0x28,0xe2,0xd4,0x5a,0xd2,0xb1,0xf1,0x44,0xf6,0xff,0x18,0x2b,0x2a,0x57,0x3b,
|
||||
0x3e,0x94,0x13,0x31,0x13,0x15,0xaa,0x83,0xd0,0xcb,0x48,0x8b,0x88,0x88,0x48,0xca,
|
||||
0xd6,0xb1,0x9d,0x23,0x4a,0x27,0x65,0xc8,0xac,0x17,0x45,0x43,0x16,0x35,0x3b,0x32,
|
||||
0x4e,0x82,0x10,0xb3,0xa6,0x5d,0x24,0xe2,0x89,0x30,0xe5,0x38,0xb5,0x17,0x44,0x7a,
|
||||
0x91,0x1d,0x51,0xc9,0x25,0xc8,0x0c,0x88,0xb2,0x62,0x77,0xd4,0xd9,0x65,0x44,0x46,
|
||||
0x54,0xd4,0x67,0x17,0xc8,0xb8,0xa2,0x2f,0x72,0x2e,0x9e,0x7d,0xe0,0xb4,0x4c,0xa9,
|
||||
0x4c,0x90,0xbc,0x9d,0x64,0x81,0xef,0xe3,0x6b,0xdb,0x69,0x56,0x64,0x01,0x70,0x92,
|
||||
0x5d,0xfe,0x99,0x20,0x8d,0x00,0x75,0x91,0x29,0x34,0xcf,0x99,0xb6,0xb6,0xd6,0x95,
|
||||
0x55,0xdc,0x36,0xd2,0x5d,0xd2,0x9e,0x9a,0x55,0xd4,0x9a,0x92,0xb1,0xf1,0xc3,0x44,
|
||||
0x81,0x5d,0xa7,0x25,0xc8,0x73,0x8b,0xb9,0xa7,0x52,0x25,0x5b,0x30,0x66,0x8e,0xea,
|
||||
0xf3,0x27,0xa9,0xe5,0xdd,0x53,0x55,0xed,0xf4,0x7c,0x55,0xd3,0x37,0x7b,0x7c,0xfe,
|
||||
0x1d,0x1e,0xcd,0x5f,0x8b,0x76,0x05,0xda,0x5e,0x60,0x15,0xfa,0x3c,0x90,0xa9,0x1e,
|
||||
0x9f,0xee,0xe2,0xec,0x39,0xd9,0x3b,0x74,0x69,0x62,0x91,0x34,0x77,0x71,0xdb,0x28,
|
||||
0xc5,0x9a,0x42,0xb3,0xe4,0xd3,0x1a,0x2d,0xa9,0x4c,0xef,0xf1,0x64,0x10,0x9c,0x65,
|
||||
0x90,0xf5,0xf9,0xbf,0x03,0xfe,0x01,0x6e,0xd9,0xe0,0x4f,0xa0,0x0f,0x58,0xef,0xd1,
|
||||
0x4e,0x67,0xcc,0x58,0xff,0x41,0x12,0x61,0xdf,0xb6,0xbc,0x66,0x16,0x9d,0x1c,0x9d,
|
||||
0x55,0x78,0x72,0xac,0x02,0x43,0x2d,0x70,0x62,0x0f,0xa2,0x73,0xbf,0xd4,0xd3,0xb0,
|
||||
0x6e,0xf4,0x54,0x77,0x42,0xe6,0xd6,0xe3,0xa3,0x30,0x4f,0x45,0x24,0xeb,0x55,0x9f,
|
||||
0x3e,0x80,0xe8,0xff,0xe5,0x80,0x38,0x8f,0x61,0xe0,0x2b,0x60,0xb7,0x47,0xd3,0x33,
|
||||
0xb3,0x8a,0x5a,0x52,0x28,0xa2,0x14,0xd4,0xb2,0xae,0x07,0x30,0x6f,0x3f,0x70,0x98,
|
||||
0x39,0x70,0x05,0xb8,0x0a,0x22,0x07,0x33,0x36,0x7f,0x34,0xc2,0x64,0x44,0xe1,0x0c,
|
||||
0x2a,0x13,0x9f,0x5c,0x99,0x00,0xd2,0xd3,0x30,0xbe,0x18,0x18,0x88,0x90,0x51,0x39,
|
||||
0x69,0x86,0x6a,0x82,0xd0,0x19,0xcd,0x1f,0x84,0x7c,0x1d,0x48,0xe7,0x82,0xc7,0x73,
|
||||
0x48,0xc0,0xd8,0x14,0x8c,0x6b,0x85,0xbd,0x1b,0xe0,0x32,0xc8,0x1c,0x28,0x00,0x7e,
|
||||
0xc1,0x0d,0x33,0xd6,0x8e,0xb4,0xce,0x81,0x4c,0x36,0x1b,0xc2,0xfd,0x78,0xe8,0x73,
|
||||
0x21,0x1b,0x80,0xeb,0xd2,0xc8,0x6a,0xba,0xd5,0x01,0x8d,0x70,0xca,0x18,0x13,0x81,
|
||||
0xc5,0x91,0x61,0x04,0x72,0x1f,0xaa,0x61,0x1e,0x08,0x8e,0x35,0x47,0xdd,0x5d,0xda,
|
||||
0x9e,0x0a,0xdb,0x4b,0x31,0xe7,0x4c,0x78,0xfc,0x65,0xe0,0x79,0xc5,0x5d,0xd2,0x96,
|
||||
0x86,0xc1,0x5b,0x31,0x91,0x29,0xfe,0x05,0x2e,0x01,0x1d,0x40,0x65,0xb8,0xb6,0x6b,
|
||||
0xd1,0x1f,0x80,0xfc,0xd1,0x61,0x8d,0xdf,0x1d,0x34,0xfd,0x6f,0x38,0xf2,0x3d,0xda,
|
||||
0x9f,0x01,0xd5,0xb8,0xdf,0x61,0x94,0x99,0xcf,0xaf,0x87,0x49,0xdf,0x04,0x2e,0x82,
|
||||
0xd3,0xab,0x90,0xa3,0x8c,0x14,0xe1,0xa8,0x83,0x77,0xfe,0x17,0xa1,0xf8,0x99,0x36,
|
||||
0x4c,0x44,0xeb,0x76,0xd4,0x1c,0x12,0x13,0xf5,0x51,0x76,0xe9,0xb5,0x40,0xfa,0x26,
|
||||
0xb2,0xc7,0x9c,0x9b,0x93,0xb9,0xa5,0x69,0x64,0xa4,0x4a,0xa2,0x1b,0x14,0x1d,0xf7,
|
||||
0x62,0xc0,0xba,0x70,0x06,0xfe,0x08,0x67,0x84,0x37,0xc2,0x74,0x57,0x81,0x5f,0x81,
|
||||
0x1f,0x80,0x9f,0x80,0x61,0xba,0x54,0xa4,0xce,0x30,0xfb,0x6c,0xff,0x5d,0x56,0x43,
|
||||
0xb6,0xae,0x51,0xeb,0x85,0xb3,0xfe,0x1b,0x70,0x12,0xd9,0x58,0x3e,0xb3,0xa8,0x25,
|
||||
0x8d,0xdf,0x9b,0x96,0x0b,0xde,0x8f,0xc0,0xe0,0x74,0xc8,0x6c,0x4c,0x58,0x85,0x36,
|
||||
0x3b,0xd3,0xcb,0x81,0x52,0x2c,0xfc,0x06,0x4a,0x6d,0x05,0x16,0xcc,0xc1,0xfd,0x42,
|
||||
0xc8,0x79,0x18,0xb7,0x00,0x6d,0x56,0x9b,0x2c,0xd5,0xfd,0x1e,0x63,0x73,0xd1,0xc4,
|
||||
0x31,0xfe,0x1a,0xc0,0x6a,0xb8,0x34,0xbb,0xfa,0xcc,0x92,0xc5,0xfb,0xfb,0x9e,0x7b,
|
||||
0xa1,0xfe,0x8b,0xf9,0x73,0x6b,0x02,0x8b,0x1e,0xaf,0xec,0x59,0xf6,0xd0,0x9b,0xfe,
|
||||
0x57,0xd4,0xd0,0x66,0x2e,0x64,0x6b,0x22,0x98,0x1b,0x20,0x5f,0x06,0x9e,0xc2,0xda,
|
||||
0x13,0x33,0x36,0x1c,0x4e,0x32,0x91,0x8e,0x79,0x8d,0x70,0xfa,0x4a,0x80,0x67,0x87,
|
||||
0x3e,0x05,0x84,0xdf,0xf1,0xb0,0x23,0xd8,0xe7,0x3f,0x06,0xd4,0x03,0xac,0x04,0xb3,
|
||||
0x81,0x43,0xe1,0x3a,0xe5,0x1d,0xb8,0x01,0x72,0x15,0x78,0xd8,0x4d,0xdf,0x74,0x34,
|
||||
0x98,0xd8,0xd8,0x7b,0xa9,0x08,0x38,0xd6,0x18,0xb8,0xd4,0x02,0xf9,0x7e,0x43,0x60,
|
||||
0x68,0x0f,0x64,0x49,0x63,0xef,0xd0,0x98,0x38,0xb8,0x88,0xde,0x16,0xe4,0x93,0xdd,
|
||||
0xdb,0x4e,0xe1,0x19,0xe0,0x1f,0x22,0x48,0x96,0x1b,0x47,0xad,0xc6,0xb2,0xe7,0x7f,
|
||||
0x57,0x0d,0x65,0x84,0x6d,0xc6,0xb7,0xd0,0x76,0x9b,0x8f,0x45,0x10,0x9d,0x0d,0xc2,
|
||||
0xbb,0x80,0x5a,0x33,0x0e,0xf6,0x5c,0x9c,0x64,0xe3,0x00,0xf9,0x51,0xaf,0x70,0x37,
|
||||
0x52,0xaf,0x3d,0xe5,0xa7,0xdd,0x22,0x07,0x58,0xff,0xa4,0x67,0xd7,0x25,0xaa,0xa5,
|
||||
0xed,0xe3,0x1f,0xde,0xfe,0xc9,0x83,0x4f,0x54,0xf5,0x4c,0x5f,0x54,0xd3,0x33,0x7e,
|
||||
0x67,0xe7,0x40,0x72,0x65,0xd7,0x60,0xb2,0xef,0xc4,0x97,0xc9,0xdb,0x8e,0xf6,0xa5,
|
||||
0x56,0x75,0x0d,0x2e,0xdb,0xd5,0x3d,0xb8,0xc9,0x8c,0x2a,0xa0,0xa2,0x2d,0x38,0xc6,
|
||||
0x6e,0x7d,0x19,0xf9,0x98,0xd7,0x05,0x6a,0xa2,0x5a,0xd6,0x1d,0x93,0x81,0xd0,0xc3,
|
||||
0x4a,0xd7,0xc2,0x73,0x15,0x90,0x4d,0x07,0xd6,0x02,0x95,0x15,0x5d,0x83,0x55,0x15,
|
||||
0xa7,0x06,0xab,0xd0,0x36,0x80,0xfb,0x7d,0x95,0xa7,0x06,0x86,0xd1,0xbe,0x15,0x41,
|
||||
0x45,0x08,0xd7,0xd1,0x1e,0x2d,0xe1,0x45,0x05,0xd9,0x72,0x51,0x13,0x5c,0x7c,0x5b,
|
||||
0x95,0x67,0x40,0x29,0xa8,0xef,0x4a,0xf1,0xb5,0x7e,0x33,0x7d,0x7b,0xfb,0xb7,0x8f,
|
||||
0x39,0xc3,0x05,0x26,0x67,0xed,0xec,0x18,0xc8,0xcc,0x5e,0x5e,0x20,0x2b,0x1f,0x4a,
|
||||
0x2f,0x4d,0x0f,0xa9,0xb7,0x66,0xc0,0x7c,0x66,0xeb,0x46,0x09,0x79,0x9b,0xcf,0xe7,
|
||||
0x03,0x9f,0x7b,0x9b,0xce,0xf7,0x79,0x9b,0x82,0x7d,0x68,0xf7,0x15,0x9a,0xc0,0xf4,
|
||||
0x86,0xb4,0xa2,0xa3,0xb0,0x39,0xf8,0xb4,0x83,0xe8,0x93,0x65,0xe4,0xb4,0xe6,0x12,
|
||||
0xa4,0x19,0xd0,0x8c,0x12,0x62,0x0e,0xac,0x2c,0x6c,0x0a,0x9e,0x00,0xc9,0x8f,0x0b,
|
||||
0x9b,0x80,0x66,0x0e,0x86,0x2e,0x18,0xbd,0xf7,0x86,0xe4,0x51,0x6f,0x73,0x30,0x97,
|
||||
0xc8,0xbc,0xd9,0x99,0xb8,0x32,0x20,0xfc,0xe2,0xa2,0xf6,0x80,0xc9,0x01,0xd7,0xca,
|
||||
0xbd,0x7a,0xf2,0x9a,0x86,0xfe,0xc5,0x6b,0x1a,0xfb,0xbd,0xf9,0x8d,0xe7,0x0c,0xb0,
|
||||
0x36,0x05,0xbe,0x2f,0xef,0x40,0x60,0x8a,0x62,0x7d,0xa5,0x76,0x11,0xf7,0x66,0xbd,
|
||||
0xa3,0x6f,0x5b,0xee,0x18,0xed,0x24,0x1d,0x50,0xc3,0x0e,0x64,0xbf,0x56,0x99,0x94,
|
||||
0x7f,0xe8,0xec,0x6c,0x90,0x3b,0x00,0x52,0x9d,0x90,0x9d,0x4c,0x5a,0xd0,0xd0,0x7f,
|
||||
0x01,0x18,0x42,0xdb,0x82,0xfc,0x86,0xb3,0x4b,0xb3,0xe6,0xae,0x88,0x87,0x53,0x5c,
|
||||
0x19,0x30,0x74,0xee,0xb2,0x2e,0x99,0x03,0xc6,0xb8,0xc9,0x33,0x1f,0x75,0xad,0xac,
|
||||
0xd3,0x93,0x57,0x1d,0x08,0x8c,0x63,0xc8,0x63,0xf2,0xbd,0xc0,0xb8,0xd5,0x07,0xfb,
|
||||
0xc6,0xe6,0x41,0x82,0xec,0x23,0xf9,0x0d,0xfd,0x0b,0x57,0x37,0x9c,0xcb,0x85,0xcc,
|
||||
0x5d,0x7d,0x08,0x60,0xb2,0xe1,0xdc,0x8c,0x67,0x36,0xd4,0x24,0x3a,0xe0,0x65,0xa9,
|
||||
0x29,0xaa,0xbe,0x14,0xa2,0x6d,0x48,0x63,0x0f,0x68,0xe4,0x29,0x14,0x75,0x80,0xb0,
|
||||
0x61,0x89,0xea,0xfc,0xb7,0x3b,0x92,0x73,0xeb,0x02,0x47,0x72,0x6a,0x03,0x57,0x72,
|
||||
0xeb,0x7a,0x6f,0xa3,0x36,0x50,0xb3,0xb0,0xfa,0xd3,0x34,0x45,0xec,0x00,0x15,0x5c,
|
||||
0x9a,0xa8,0x40,0xc7,0x5e,0xfa,0xa4,0x0f,0x32,0x22,0x18,0x96,0x88,0xb1,0xfb,0x9c,
|
||||
0x9a,0x33,0x13,0x40,0x76,0x0b,0x1c,0xd8,0x9b,0x53,0xd7,0x5b,0x97,0x53,0x17,0x92,
|
||||
0xd0,0xbd,0xb4,0xa0,0xaa,0x3b,0x45,0x10,0xd4,0x88,0x1d,0xa1,0x03,0x4e,0xd2,0x26,
|
||||
0x39,0x85,0xfc,0xcd,0xee,0xf2,0xee,0x65,0xec,0xbd,0x08,0x1f,0x25,0x16,0x84,0x74,
|
||||
0x7a,0x18,0x18,0x63,0x48,0x6b,0x1f,0x93,0xee,0xd2,0x8e,0x74,0x09,0x27,0xea,0xc7,
|
||||
0x00,0x61,0xa7,0xa2,0x58,0xc9,0x47,0x81,0xc5,0x0d,0x07,0x54,0x8d,0x78,0x6f,0xd7,
|
||||
0x04,0xed,0xd8,0xfd,0x12,0x45,0x68,0x9c,0xf1,0xcd,0xf1,0x3b,0x9e,0xe6,0x13,0x1c,
|
||||
0x04,0x34,0x26,0xfa,0xfc,0x25,0xda,0x17,0xa1,0x12,0x8a,0x64,0x20,0xea,0x80,0x4e,
|
||||
0x93,0xd7,0x44,0xed,0xc8,0x78,0xdd,0x0c,0xf6,0x91,0x5f,0x0d,0xc8,0xf6,0xa4,0x99,
|
||||
0x9b,0x25,0x03,0x94,0x23,0xa2,0x5a,0x0e,0x3d,0x07,0xe8,0x4d,0x2c,0xfe,0xea,0xa2,
|
||||
0xb2,0x75,0xbb,0x8f,0xbd,0x7e,0x1f,0x71,0x97,0x75,0x4f,0xe6,0xd6,0x72,0xf2,0xeb,
|
||||
0x9d,0xa3,0x54,0x59,0x26,0x49,0xde,0x85,0x68,0x82,0xe2,0x3e,0x7c,0xd9,0xe9,0x5f,
|
||||
0xa3,0x3d,0x2f,0xab,0xb8,0xf5,0x9e,0x38,0x4a,0x27,0x6e,0x07,0x2c,0xc8,0x2a,0x69,
|
||||
0xbf,0x0f,0xb5,0x5b,0x80,0x37,0xd0,0x22,0x06,0x0f,0x93,0x9a,0x6e,0xc0,0x13,0xd6,
|
||||
0x45,0xf4,0x20,0x68,0xe9,0xc7,0x67,0x66,0x48,0xaf,0xe9,0x1b,0x81,0x25,0x08,0xc6,
|
||||
0x8c,0x69,0x79,0xbb,0xf9,0x73,0x9f,0xaf,0x04,0x5b,0x07,0xec,0x4a,0x47,0x64,0x8c,
|
||||
0x1f,0xcf,0xdb,0xa0,0xe6,0xd9,0xad,0x49,0x5d,0x94,0x63,0xa4,0x71,0x27,0xbf,0x0e,
|
||||
0x53,0x8e,0x48,0xbf,0x1f,0x24,0xb6,0x65,0xe3,0xed,0xf8,0x58,0x1c,0x76,0x54,0x6b,
|
||||
0x36,0x8b,0x98,0x6d,0x29,0x84,0xee,0x6e,0x21,0xb2,0x13,0xf3,0xc1,0x42,0x41,0x16,
|
||||
0xe9,0x78,0xfe,0xb1,0xa1,0xd6,0xba,0x23,0xd2,0xe6,0xb6,0x93,0x85,0x28,0xd2,0xb2,
|
||||
0xc5,0xe3,0x75,0x4a,0xf4,0x0b,0xb8,0x13,0xdb,0x71,0xa5,0x91,0x77,0x46,0x56,0xfb,
|
||||
0x4e,0xce,0x70,0xe1,0x1b,0x6f,0x1c,0x81,0x92,0x92,0x50,0x4c,0x52,0xe6,0xac,0xa2,
|
||||
0x88,0x49,0x50,0xb6,0xe3,0xfd,0xa3,0xd0,0xbc,0x3e,0xef,0xa0,0xbc,0xbe,0x24,0x0e,
|
||||
0x88,0xee,0x29,0xbd,0xa8,0xef,0x4e,0x1c,0x8a,0x59,0xcf,0xe9,0x62,0x76,0x4e,0xf0,
|
||||
0x73,0x45,0x64,0x45,0x01,0x88,0x46,0x94,0xbb,0xec,0xe6,0x4a,0x17,0x91,0x9d,0x44,
|
||||
0xb6,0x86,0x1d,0xb4,0x9d,0x42,0xf4,0x97,0x97,0xeb,0x3f,0x3f,0xec,0x38,0x66,0xde,
|
||||
0xb6,0xc9,0x48,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82,};
|
||||
|
||||
#if FSDATA_FILE_ALIGNMENT==1
|
||||
static const unsigned int dummy_align__asset_off_png = 1;
|
||||
#endif
|
||||
static const unsigned char FSDATA_ALIGN_PRE data__asset_off_png[] FSDATA_ALIGN_POST = {
|
||||
/* /asset/off.png (15z chars) */
|
||||
0x2f,0x61,0x73,0x73,0x65,0x74,0x2f,0x6f,0x66,0x66,0x2e,0x70,0x6e,0x67,0x00,0x00,
|
||||
|
||||
/* HTTP header */
|
||||
/* "HTTP/1.0 200 OK
|
||||
" (17z bytes) */
|
||||
0x48,0x54,0x54,0x50,0x2f,0x31,0x2e,0x30,0x20,0x32,0x30,0x30,0x20,0x4f,0x4b,0x0d,
|
||||
0x0a,
|
||||
/* "Server: lwIP/2.1.3d (http://savannah.nongnu.org/projects/lwip)
|
||||
" (64z bytes) */
|
||||
0x53,0x65,0x72,0x76,0x65,0x72,0x3a,0x20,0x6c,0x77,0x49,0x50,0x2f,0x32,0x2e,0x31,
|
||||
0x2e,0x33,0x64,0x20,0x28,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x73,0x61,0x76,0x61,
|
||||
0x6e,0x6e,0x61,0x68,0x2e,0x6e,0x6f,0x6e,0x67,0x6e,0x75,0x2e,0x6f,0x72,0x67,0x2f,
|
||||
0x70,0x72,0x6f,0x6a,0x65,0x63,0x74,0x73,0x2f,0x6c,0x77,0x69,0x70,0x29,0x0d,0x0a,
|
||||
|
||||
/* "Content-Length: 449
|
||||
" (18z+ bytes) */
|
||||
0x43,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x2d,0x4c,0x65,0x6e,0x67,0x74,0x68,0x3a,0x20,
|
||||
0x34,0x34,0x39,0x0d,0x0a,
|
||||
/* "Content-Type: image/png
|
||||
|
||||
" (27z bytes) */
|
||||
0x43,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x2d,0x54,0x79,0x70,0x65,0x3a,0x20,0x69,0x6d,
|
||||
0x61,0x67,0x65,0x2f,0x70,0x6e,0x67,0x0d,0x0a,0x0d,0x0a,
|
||||
/* raw file data (449 bytes) */
|
||||
0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
|
||||
0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x30,0x08,0x06,0x00,0x00,0x00,0x57,0x02,0xf9,
|
||||
0x87,0x00,0x00,0x00,0x06,0x62,0x4b,0x47,0x44,0x00,0xff,0x00,0xff,0x00,0xff,0xa0,
|
||||
0xbd,0xa7,0x93,0x00,0x00,0x01,0x76,0x49,0x44,0x41,0x54,0x68,0x81,0xed,0xd8,0xbd,
|
||||
0x4a,0x03,0x41,0x14,0x86,0xe1,0xf7,0xcc,0x8e,0x29,0x02,0x8a,0x7f,0x31,0x8d,0xb9,
|
||||
0x83,0x88,0x16,0x36,0x22,0x58,0xaa,0xa5,0xe0,0xa5,0x58,0x68,0x25,0x68,0x97,0x42,
|
||||
0xbc,0x0f,0x05,0x6b,0x2d,0x2c,0x03,0x5a,0x08,0x92,0xce,0x5e,0x09,0x1b,0x11,0x35,
|
||||
0x82,0x45,0x9c,0xcd,0x58,0x18,0x25,0x68,0xe1,0xdf,0x2c,0xa3,0x70,0x9e,0x6a,0x8b,
|
||||
0xe5,0xcc,0xf7,0xc1,0x34,0x67,0x40,0x29,0xa5,0x94,0xfa,0xc7,0x04,0xe0,0xaa,0xba,
|
||||
0x50,0xb1,0x64,0xbb,0x08,0x8b,0xc0,0x60,0xe4,0x4c,0x9f,0x79,0x00,0x7f,0x6c,0x44,
|
||||
0x36,0x4a,0x8d,0xfa,0x85,0x5c,0x55,0x17,0x2a,0x56,0xb2,0x73,0x60,0x34,0x76,0xb2,
|
||||
0x6f,0xba,0x75,0x3e,0x99,0x36,0x96,0x6c,0x97,0xff,0x17,0x1e,0x60,0xc4,0x4a,0xb6,
|
||||
0x63,0x7b,0xd7,0x06,0x80,0x8e,0xf7,0x3c,0x76,0x1d,0xdd,0x40,0x27,0x18,0xa0,0x68,
|
||||
0x2c,0x05,0x91,0x40,0x13,0x3f,0x58,0xb2,0xf4,0xee,0x7c,0xc7,0x7b,0x3a,0x73,0xb3,
|
||||
0x4c,0x6e,0xae,0x63,0x27,0xc6,0x83,0x4c,0x77,0xe9,0x35,0xcd,0xed,0x1a,0x9c,0x9c,
|
||||
0xe5,0x55,0x62,0x48,0xd2,0xa9,0x79,0x0f,0x70,0x97,0x3d,0x31,0x79,0x78,0x80,0x2d,
|
||||
0x97,0x82,0x9e,0xe0,0xd2,0x16,0x97,0xcb,0xab,0x0c,0x27,0x03,0x41,0xe7,0xbe,0x32,
|
||||
0xaf,0x1f,0x99,0x27,0x78,0x78,0x00,0x5b,0x9e,0x20,0xf3,0xc1,0xc7,0xbe,0x31,0x9f,
|
||||
0xff,0xf2,0xb7,0x69,0x81,0xd8,0xb4,0x40,0x6c,0x5a,0x20,0x36,0x2d,0x10,0x9b,0x16,
|
||||
0x88,0x4d,0x0b,0xc4,0xa6,0x05,0x62,0xd3,0x02,0xb1,0xbd,0x15,0x48,0xe4,0x65,0x87,
|
||||
0x0d,0xcd,0xa5,0x2d,0x92,0xdc,0x76,0xfa,0xbe,0x02,0x45,0x63,0x69,0x6e,0xd7,0x82,
|
||||
0x96,0x70,0x69,0x8b,0xe6,0x56,0x8d,0xa2,0xb1,0xc1,0x66,0xbe,0x27,0xe9,0xd4,0x7c,
|
||||
0x9b,0xbe,0x97,0x89,0xc7,0xae,0x0b,0xb6,0xc3,0x26,0x92,0xf7,0xb3,0x8a,0xdc,0x5b,
|
||||
0xf0,0xc7,0x20,0x2b,0x00,0x05,0x11,0x0a,0x39,0xbd,0x1e,0xe4,0xc1,0xe3,0x8f,0x8c,
|
||||
0x11,0xd9,0x00,0x6e,0x63,0x87,0xf9,0x81,0x9b,0x01,0x71,0x6b,0xa6,0xd4,0xa8,0x5f,
|
||||
0x38,0x9f,0x4c,0x03,0xfb,0x40,0x3b,0x76,0xaa,0x2f,0x68,0x7b,0xd8,0xb3,0xe2,0x66,
|
||||
0xc6,0x1a,0xa7,0x97,0xb1,0xc3,0x28,0xa5,0x94,0x52,0xbf,0xf2,0x0c,0x2c,0x65,0x66,
|
||||
0x1b,0xdc,0xfd,0xdf,0xa1,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,
|
||||
0x82,};
|
||||
|
||||
#if FSDATA_FILE_ALIGNMENT==1
|
||||
static const unsigned int dummy_align__asset_ok_json = 2;
|
||||
#endif
|
||||
static const unsigned char FSDATA_ALIGN_PRE data__asset_ok_json[] FSDATA_ALIGN_POST = {
|
||||
/* /asset/ok.json (15z chars) */
|
||||
0x2f,0x61,0x73,0x73,0x65,0x74,0x2f,0x6f,0x6b,0x2e,0x6a,0x73,0x6f,0x6e,0x00,0x00,
|
||||
|
||||
/* HTTP header */
|
||||
/* "HTTP/1.0 200 OK
|
||||
" (17z bytes) */
|
||||
0x48,0x54,0x54,0x50,0x2f,0x31,0x2e,0x30,0x20,0x32,0x30,0x30,0x20,0x4f,0x4b,0x0d,
|
||||
0x0a,
|
||||
/* "Server: lwIP/2.1.3d (http://savannah.nongnu.org/projects/lwip)
|
||||
" (64z bytes) */
|
||||
0x53,0x65,0x72,0x76,0x65,0x72,0x3a,0x20,0x6c,0x77,0x49,0x50,0x2f,0x32,0x2e,0x31,
|
||||
0x2e,0x33,0x64,0x20,0x28,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x73,0x61,0x76,0x61,
|
||||
0x6e,0x6e,0x61,0x68,0x2e,0x6e,0x6f,0x6e,0x67,0x6e,0x75,0x2e,0x6f,0x72,0x67,0x2f,
|
||||
0x70,0x72,0x6f,0x6a,0x65,0x63,0x74,0x73,0x2f,0x6c,0x77,0x69,0x70,0x29,0x0d,0x0a,
|
||||
|
||||
/* "Content-Type: application/json
|
||||
|
||||
" (34z bytes) */
|
||||
0x43,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x2d,0x54,0x79,0x70,0x65,0x3a,0x20,0x61,0x70,
|
||||
0x70,0x6c,0x69,0x63,0x61,0x74,0x69,0x6f,0x6e,0x2f,0x6a,0x73,0x6f,0x6e,0x0d,0x0a,
|
||||
0x0d,0x0a,
|
||||
/* raw file data (20 bytes) */
|
||||
0x7b,0x22,0x73,0x74,0x61,0x74,0x75,0x73,0x22,0x3a,0x22,0x73,0x75,0x63,0x63,0x65,
|
||||
0x73,0x73,0x22,0x7d,};
|
||||
|
||||
#if FSDATA_FILE_ALIGNMENT==1
|
||||
static const unsigned int dummy_align__asset_on_png = 3;
|
||||
#endif
|
||||
static const unsigned char FSDATA_ALIGN_PRE data__asset_on_png[] FSDATA_ALIGN_POST = {
|
||||
/* /asset/on.png (14z chars) */
|
||||
0x2f,0x61,0x73,0x73,0x65,0x74,0x2f,0x6f,0x6e,0x2e,0x70,0x6e,0x67,0x00,0x00,0x00,
|
||||
|
||||
/* HTTP header */
|
||||
/* "HTTP/1.0 200 OK
|
||||
" (17z bytes) */
|
||||
0x48,0x54,0x54,0x50,0x2f,0x31,0x2e,0x30,0x20,0x32,0x30,0x30,0x20,0x4f,0x4b,0x0d,
|
||||
0x0a,
|
||||
/* "Server: lwIP/2.1.3d (http://savannah.nongnu.org/projects/lwip)
|
||||
" (64z bytes) */
|
||||
0x53,0x65,0x72,0x76,0x65,0x72,0x3a,0x20,0x6c,0x77,0x49,0x50,0x2f,0x32,0x2e,0x31,
|
||||
0x2e,0x33,0x64,0x20,0x28,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x73,0x61,0x76,0x61,
|
||||
0x6e,0x6e,0x61,0x68,0x2e,0x6e,0x6f,0x6e,0x67,0x6e,0x75,0x2e,0x6f,0x72,0x67,0x2f,
|
||||
0x70,0x72,0x6f,0x6a,0x65,0x63,0x74,0x73,0x2f,0x6c,0x77,0x69,0x70,0x29,0x0d,0x0a,
|
||||
|
||||
/* "Content-Length: 435
|
||||
" (18z+ bytes) */
|
||||
0x43,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x2d,0x4c,0x65,0x6e,0x67,0x74,0x68,0x3a,0x20,
|
||||
0x34,0x33,0x35,0x0d,0x0a,
|
||||
/* "Content-Type: image/png
|
||||
|
||||
" (27z bytes) */
|
||||
0x43,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x2d,0x54,0x79,0x70,0x65,0x3a,0x20,0x69,0x6d,
|
||||
0x61,0x67,0x65,0x2f,0x70,0x6e,0x67,0x0d,0x0a,0x0d,0x0a,
|
||||
/* raw file data (435 bytes) */
|
||||
0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
|
||||
0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x30,0x08,0x06,0x00,0x00,0x00,0x57,0x02,0xf9,
|
||||
0x87,0x00,0x00,0x00,0x06,0x62,0x4b,0x47,0x44,0x00,0xff,0x00,0xff,0x00,0xff,0xa0,
|
||||
0xbd,0xa7,0x93,0x00,0x00,0x01,0x68,0x49,0x44,0x41,0x54,0x68,0x81,0xed,0xd8,0x3d,
|
||||
0x4e,0x02,0x41,0x18,0xc6,0xf1,0xff,0x0c,0x1f,0x86,0x42,0x51,0x4b,0x91,0xc4,0x44,
|
||||
0x6b,0xd7,0x53,0x68,0xec,0x6c,0xf0,0x0e,0xd4,0x36,0x24,0xdc,0x80,0xc4,0x58,0xc9,
|
||||
0x1d,0xc0,0x13,0x50,0x70,0x07,0x13,0x6c,0x48,0xa8,0x0c,0x94,0x86,0x0f,0x0b,0xc2,
|
||||
0x92,0x9d,0xb1,0x58,0x50,0x43,0x4c,0xc0,0xb8,0xe3,0x84,0xe4,0xfd,0x75,0xbb,0x99,
|
||||
0xcc,0x3c,0xcf,0xee,0x54,0x2f,0x08,0x21,0x84,0x10,0x5b,0x4c,0x01,0x50,0xed,0x14,
|
||||
0x89,0xd4,0x03,0x70,0x09,0xec,0x7a,0x4d,0xb4,0xde,0x3b,0xd6,0xb6,0xb1,0xa6,0x42,
|
||||
0x2d,0xe8,0x2a,0xaa,0x9d,0x22,0x46,0x3d,0x63,0x39,0xf4,0x9d,0xec,0x97,0x86,0xa4,
|
||||
0x6c,0x90,0x5e,0x7c,0xf9,0x6d,0x0b,0x0f,0x70,0x40,0xa4,0xee,0xd3,0xc4,0xd7,0xc6,
|
||||
0x8d,0x28,0x84,0xf9,0x14,0x8c,0x4d,0x66,0x3f,0xad,0x20,0x93,0x83,0x54,0x76,0xf9,
|
||||
0xe6,0x2a,0x8d,0xab,0x3b,0x1f,0x85,0x5c,0x9f,0x28,0xea,0xa5,0x73,0x8e,0xf2,0xd9,
|
||||
0xf5,0xeb,0x37,0x30,0x18,0x87,0x94,0x1b,0x3d,0x5a,0xaf,0xe1,0xb2,0xc4,0x9e,0x4e,
|
||||
0x64,0xe7,0x9f,0xcc,0xa7,0x3c,0x96,0xce,0x12,0x0b,0x0f,0x50,0xc8,0x67,0xa9,0xdf,
|
||||
0x9e,0xc6,0x7f,0x75,0xc1,0x5d,0x01,0x63,0x28,0x24,0x18,0x7e,0xe9,0x78,0x7f,0x07,
|
||||
0x8c,0xf9,0x7c,0x76,0x57,0xe0,0x9f,0x48,0x01,0xdf,0xa4,0x80,0x6f,0x52,0xc0,0x37,
|
||||
0x29,0xe0,0x9b,0x14,0xf0,0x4d,0x0a,0xf8,0x26,0x05,0x7c,0x93,0x02,0xbe,0xb9,0x2b,
|
||||
0xa0,0x35,0x83,0x71,0x98,0xf8,0xb6,0xfd,0xd1,0x0c,0xf4,0x57,0x6c,0x77,0x05,0x32,
|
||||
0x39,0xca,0x8d,0x5e,0xa2,0x25,0xfa,0xa3,0x19,0xe5,0x66,0x2f,0x9e,0x4c,0x2c,0x28,
|
||||
0x2a,0x2f,0x13,0x1c,0x4e,0x26,0xe2,0xb1,0x8a,0x59,0xbf,0x76,0x13,0x5a,0xaf,0x8c,
|
||||
0x55,0xd4,0x38,0x8d,0xb5,0x6d,0x94,0xba,0x49,0xe6,0x84,0x15,0xa9,0xec,0xf7,0x19,
|
||||
0x4e,0xf2,0x94,0x69,0x69,0xac,0xa9,0x00,0x43,0x77,0xa7,0x38,0xf3,0x46,0x64,0xee,
|
||||
0x34,0xb5,0xa0,0x4b,0xca,0x06,0xc0,0x13,0x30,0xf1,0x9d,0x6a,0x03,0x13,0x94,0x6d,
|
||||
0x62,0xa2,0x0b,0x6a,0x41,0xdf,0x77,0x18,0x21,0x84,0x10,0xe2,0x4f,0x3e,0x00,0x0a,
|
||||
0xb5,0x60,0x22,0x58,0x89,0x57,0x9c,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,0x44,0xae,
|
||||
0x42,0x60,0x82,};
|
||||
|
||||
#if FSDATA_FILE_ALIGNMENT==1
|
||||
static const unsigned int dummy_align__css_style_css = 4;
|
||||
#endif
|
||||
static const unsigned char FSDATA_ALIGN_PRE data__css_style_css[] FSDATA_ALIGN_POST = {
|
||||
/* /css/style.css (15z chars) */
|
||||
0x2f,0x63,0x73,0x73,0x2f,0x73,0x74,0x79,0x6c,0x65,0x2e,0x63,0x73,0x73,0x00,0x00,
|
||||
|
||||
/* HTTP header */
|
||||
/* "HTTP/1.0 200 OK
|
||||
" (17z bytes) */
|
||||
0x48,0x54,0x54,0x50,0x2f,0x31,0x2e,0x30,0x20,0x32,0x30,0x30,0x20,0x4f,0x4b,0x0d,
|
||||
0x0a,
|
||||
/* "Server: lwIP/2.1.3d (http://savannah.nongnu.org/projects/lwip)
|
||||
" (64z bytes) */
|
||||
0x53,0x65,0x72,0x76,0x65,0x72,0x3a,0x20,0x6c,0x77,0x49,0x50,0x2f,0x32,0x2e,0x31,
|
||||
0x2e,0x33,0x64,0x20,0x28,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x73,0x61,0x76,0x61,
|
||||
0x6e,0x6e,0x61,0x68,0x2e,0x6e,0x6f,0x6e,0x67,0x6e,0x75,0x2e,0x6f,0x72,0x67,0x2f,
|
||||
0x70,0x72,0x6f,0x6a,0x65,0x63,0x74,0x73,0x2f,0x6c,0x77,0x69,0x70,0x29,0x0d,0x0a,
|
||||
|
||||
/* "Content-Length: 1132
|
||||
" (18z+ bytes) */
|
||||
0x43,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x2d,0x4c,0x65,0x6e,0x67,0x74,0x68,0x3a,0x20,
|
||||
0x31,0x31,0x33,0x32,0x0d,0x0a,
|
||||
/* "Content-Type: text/css
|
||||
|
||||
" (26z bytes) */
|
||||
0x43,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x2d,0x54,0x79,0x70,0x65,0x3a,0x20,0x74,0x65,
|
||||
0x78,0x74,0x2f,0x63,0x73,0x73,0x0d,0x0a,0x0d,0x0a,
|
||||
/* raw file data (1132 bytes) */
|
||||
0x62,0x6f,0x64,0x79,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x68,0x65,0x69,0x67,0x68,
|
||||
0x74,0x3a,0x20,0x38,0x30,0x25,0x3b,0x0a,0x20,0x20,0x20,0x20,0x77,0x69,0x64,0x74,
|
||||
0x68,0x3a,0x20,0x31,0x30,0x30,0x30,0x70,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,
|
||||
0x61,0x64,0x64,0x69,0x6e,0x67,0x3a,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,
|
||||
0x61,0x63,0x6b,0x67,0x72,0x6f,0x75,0x6e,0x64,0x2d,0x63,0x6f,0x6c,0x6f,0x72,0x3a,
|
||||
0x20,0x23,0x30,0x43,0x30,0x43,0x30,0x43,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,
|
||||
0x72,0x64,0x65,0x72,0x2d,0x72,0x61,0x64,0x69,0x75,0x73,0x3a,0x20,0x33,0x30,0x70,
|
||||
0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x72,0x67,0x69,0x6e,0x3a,0x20,0x33,
|
||||
0x36,0x70,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x78,0x2d,0x73,0x68,0x61,
|
||||
0x64,0x6f,0x77,0x3a,0x20,0x35,0x70,0x78,0x20,0x35,0x70,0x78,0x20,0x35,0x70,0x78,
|
||||
0x20,0x72,0x67,0x62,0x61,0x28,0x30,0x2c,0x30,0x2c,0x30,0x2c,0x2e,0x35,0x29,0x3b,
|
||||
0x0a,0x7d,0x0a,0x0a,0x68,0x74,0x6d,0x6c,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x68,
|
||||
0x65,0x69,0x67,0x68,0x74,0x3a,0x20,0x31,0x30,0x30,0x25,0x3b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x77,0x69,0x64,0x74,0x68,0x3a,0x20,0x31,0x30,0x30,0x25,0x3b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x6d,0x61,0x72,0x67,0x69,0x6e,0x3a,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x70,0x61,0x64,0x64,0x69,0x6e,0x67,0x3a,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x62,0x61,0x63,0x6b,0x67,0x72,0x6f,0x75,0x6e,0x64,0x2d,0x63,0x6f,0x6c,0x6f,
|
||||
0x72,0x3a,0x20,0x23,0x65,0x65,0x65,0x3b,0x0a,0x7d,0x0a,0x0a,0x68,0x74,0x6d,0x6c,
|
||||
0x2c,0x20,0x62,0x6f,0x64,0x79,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x6e,
|
||||
0x74,0x2d,0x66,0x61,0x6d,0x69,0x6c,0x79,0x3a,0x20,0x22,0x43,0x6f,0x75,0x72,0x69,
|
||||
0x65,0x72,0x20,0x4e,0x65,0x77,0x22,0x2c,0x20,0x43,0x6f,0x75,0x72,0x69,0x65,0x72,
|
||||
0x2c,0x20,0x6d,0x6f,0x6e,0x6f,0x73,0x70,0x61,0x63,0x65,0x3b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x66,0x6f,0x6e,0x74,0x2d,0x73,0x69,0x7a,0x65,0x3a,0x20,0x31,0x38,0x70,0x78,
|
||||
0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3a,0x20,0x23,0x43,0x43,
|
||||
0x43,0x43,0x43,0x43,0x3b,0x0a,0x7d,0x0a,0x0a,0x68,0x74,0x6d,0x6c,0x20,0x7b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x68,0x65,0x69,0x67,0x68,0x74,0x3a,0x20,0x31,0x30,0x30,0x25,
|
||||
0x3b,0x0a,0x20,0x20,0x20,0x20,0x77,0x69,0x64,0x74,0x68,0x3a,0x20,0x31,0x30,0x30,
|
||||
0x25,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x64,0x64,0x69,0x6e,0x67,0x3a,0x20,
|
||||
0x30,0x3b,0x0a,0x7d,0x0a,0x0a,0x68,0x31,0x2c,0x0a,0x68,0x32,0x20,0x7b,0x0a,0x20,
|
||||
0x20,0x20,0x20,0x66,0x6f,0x6e,0x74,0x2d,0x77,0x65,0x69,0x67,0x68,0x74,0x3a,0x20,
|
||||
0x32,0x30,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x72,0x67,0x69,0x6e,0x3a,
|
||||
0x20,0x30,0x2e,0x34,0x65,0x6d,0x20,0x30,0x3b,0x0a,0x7d,0x0a,0x68,0x31,0x20,0x7b,
|
||||
0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x6e,0x74,0x2d,0x73,0x69,0x7a,0x65,0x3a,0x20,
|
||||
0x33,0x32,0x70,0x78,0x3b,0x0a,0x7d,0x0a,0x68,0x32,0x20,0x7b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3a,0x20,0x23,0x38,0x38,0x38,0x3b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x66,0x6f,0x6e,0x74,0x2d,0x73,0x69,0x7a,0x65,0x3a,0x20,0x32,0x65,0x6d,
|
||||
0x3b,0x0a,0x7d,0x0a,0x0a,0x2e,0x74,0x69,0x74,0x6c,0x65,0x20,0x7b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x66,0x6f,0x6e,0x74,0x2d,0x73,0x69,0x7a,0x65,0x3a,0x20,0x33,0x32,0x70,
|
||||
0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x61,0x63,0x6b,0x67,0x72,0x6f,0x75,0x6e,
|
||||
0x64,0x2d,0x63,0x6f,0x6c,0x6f,0x72,0x3a,0x20,0x23,0x63,0x37,0x63,0x37,0x63,0x37,
|
||||
0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x72,0x64,0x65,0x72,0x2d,0x72,0x61,0x64,
|
||||
0x69,0x75,0x73,0x3a,0x20,0x31,0x38,0x70,0x78,0x20,0x31,0x38,0x70,0x78,0x20,0x30,
|
||||
0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x64,0x64,0x69,0x6e,0x67,0x3a,
|
||||
0x20,0x31,0x38,0x70,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,
|
||||
0x3a,0x20,0x72,0x67,0x62,0x28,0x32,0x35,0x35,0x2c,0x20,0x32,0x35,0x35,0x2c,0x20,
|
||||
0x32,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x6e,0x74,0x2d,0x66,
|
||||
0x61,0x6d,0x69,0x6c,0x79,0x3a,0x56,0x65,0x72,0x64,0x61,0x6e,0x61,0x2c,0x20,0x47,
|
||||
0x65,0x6e,0x65,0x76,0x61,0x2c,0x20,0x54,0x61,0x68,0x6f,0x6d,0x61,0x2c,0x20,0x73,
|
||||
0x61,0x6e,0x73,0x2d,0x73,0x65,0x72,0x69,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,
|
||||
0x6f,0x6e,0x74,0x2d,0x77,0x65,0x69,0x67,0x68,0x74,0x3a,0x20,0x36,0x30,0x30,0x3b,
|
||||
0x0a,0x20,0x20,0x20,0x20,0x74,0x65,0x78,0x74,0x2d,0x73,0x68,0x61,0x64,0x6f,0x77,
|
||||
0x3a,0x20,0x62,0x6c,0x61,0x63,0x6b,0x20,0x30,0x2e,0x30,0x35,0x65,0x6d,0x20,0x30,
|
||||
0x2e,0x30,0x35,0x65,0x6d,0x20,0x30,0x2e,0x30,0x35,0x65,0x6d,0x0a,0x7d,0x0a,0x0a,
|
||||
0x2e,0x63,0x6d,0x64,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x6e,0x74,0x2d,
|
||||
0x73,0x69,0x7a,0x65,0x3a,0x20,0x32,0x34,0x70,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x6d,0x61,0x72,0x67,0x69,0x6e,0x2d,0x6c,0x65,0x66,0x74,0x3a,0x20,0x33,0x30,0x70,
|
||||
0x78,0x3b,0x0a,0x7d,0x0a,0x0a,0x2e,0x69,0x63,0x6f,0x6e,0x2d,0x73,0x77,0x69,0x74,
|
||||
0x63,0x68,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x62,0x61,0x63,0x6b,0x67,0x72,0x6f,
|
||||
0x75,0x6e,0x64,0x2d,0x69,0x6d,0x61,0x67,0x65,0x3a,0x20,0x75,0x72,0x6c,0x28,0x27,
|
||||
0x2e,0x2f,0x61,0x73,0x73,0x65,0x74,0x2f,0x6f,0x66,0x66,0x2e,0x70,0x6e,0x67,0x27,
|
||||
0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x61,0x63,0x6b,0x67,0x72,0x6f,0x75,0x6e,
|
||||
0x64,0x2d,0x72,0x65,0x70,0x65,0x61,0x74,0x3a,0x20,0x6e,0x6f,0x2d,0x72,0x65,0x70,
|
||||
0x65,0x61,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x68,0x65,0x69,0x67,0x68,0x74,0x3a,
|
||||
0x20,0x33,0x36,0x70,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x77,0x69,0x64,0x74,0x68,
|
||||
0x3a,0x20,0x36,0x30,0x70,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x61,0x63,0x6b,
|
||||
0x67,0x72,0x6f,0x75,0x6e,0x64,0x2d,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3a,
|
||||
0x20,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,
|
||||
0x61,0x74,0x3a,0x20,0x72,0x69,0x67,0x68,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,
|
||||
0x61,0x64,0x64,0x69,0x6e,0x67,0x2d,0x74,0x6f,0x70,0x3a,0x20,0x31,0x30,0x70,0x78,
|
||||
0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x64,0x64,0x69,0x6e,0x67,0x2d,0x72,0x69,
|
||||
0x67,0x68,0x74,0x3a,0x20,0x31,0x30,0x70,0x78,0x3b,0x0a,0x7d,};
|
||||
|
||||
#if FSDATA_FILE_ALIGNMENT==1
|
||||
static const unsigned int dummy_align__js_main_js = 5;
|
||||
#endif
|
||||
static const unsigned char FSDATA_ALIGN_PRE data__js_main_js[] FSDATA_ALIGN_POST = {
|
||||
/* /js/main.js (12z chars) */
|
||||
0x2f,0x6a,0x73,0x2f,0x6d,0x61,0x69,0x6e,0x2e,0x6a,0x73,0x00,
|
||||
|
||||
/* HTTP header */
|
||||
/* "HTTP/1.0 200 OK
|
||||
" (17z bytes) */
|
||||
0x48,0x54,0x54,0x50,0x2f,0x31,0x2e,0x30,0x20,0x32,0x30,0x30,0x20,0x4f,0x4b,0x0d,
|
||||
0x0a,
|
||||
/* "Server: lwIP/2.1.3d (http://savannah.nongnu.org/projects/lwip)
|
||||
" (64z bytes) */
|
||||
0x53,0x65,0x72,0x76,0x65,0x72,0x3a,0x20,0x6c,0x77,0x49,0x50,0x2f,0x32,0x2e,0x31,
|
||||
0x2e,0x33,0x64,0x20,0x28,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x73,0x61,0x76,0x61,
|
||||
0x6e,0x6e,0x61,0x68,0x2e,0x6e,0x6f,0x6e,0x67,0x6e,0x75,0x2e,0x6f,0x72,0x67,0x2f,
|
||||
0x70,0x72,0x6f,0x6a,0x65,0x63,0x74,0x73,0x2f,0x6c,0x77,0x69,0x70,0x29,0x0d,0x0a,
|
||||
|
||||
/* "Content-Length: 2260
|
||||
" (18z+ bytes) */
|
||||
0x43,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x2d,0x4c,0x65,0x6e,0x67,0x74,0x68,0x3a,0x20,
|
||||
0x32,0x32,0x36,0x30,0x0d,0x0a,
|
||||
/* "Content-Type: application/javascript
|
||||
|
||||
" (40z bytes) */
|
||||
0x43,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x2d,0x54,0x79,0x70,0x65,0x3a,0x20,0x61,0x70,
|
||||
0x70,0x6c,0x69,0x63,0x61,0x74,0x69,0x6f,0x6e,0x2f,0x6a,0x61,0x76,0x61,0x73,0x63,
|
||||
0x72,0x69,0x70,0x74,0x0d,0x0a,0x0d,0x0a,
|
||||
/* raw file data (2260 bytes) */
|
||||
0x6c,0x65,0x74,0x20,0x54,0x78,0x74,0x52,0x6f,0x74,0x61,0x74,0x65,0x20,0x3d,0x20,
|
||||
0x66,0x75,0x6e,0x63,0x74,0x69,0x6f,0x6e,0x20,0x28,0x65,0x6c,0x2c,0x20,0x74,0x6f,
|
||||
0x52,0x6f,0x74,0x61,0x74,0x65,0x2c,0x20,0x70,0x65,0x72,0x69,0x6f,0x64,0x29,0x20,
|
||||
0x7b,0x0a,0x20,0x20,0x20,0x20,0x74,0x68,0x69,0x73,0x2e,0x74,0x6f,0x52,0x6f,0x74,
|
||||
0x61,0x74,0x65,0x20,0x3d,0x20,0x74,0x6f,0x52,0x6f,0x74,0x61,0x74,0x65,0x3b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x74,0x68,0x69,0x73,0x2e,0x65,0x6c,0x20,0x3d,0x20,0x65,0x6c,
|
||||
0x3b,0x0a,0x20,0x20,0x20,0x20,0x74,0x68,0x69,0x73,0x2e,0x6c,0x6f,0x6f,0x70,0x4e,
|
||||
0x75,0x6d,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x74,0x68,0x69,0x73,
|
||||
0x2e,0x70,0x65,0x72,0x69,0x6f,0x64,0x20,0x3d,0x20,0x70,0x61,0x72,0x73,0x65,0x49,
|
||||
0x6e,0x74,0x28,0x70,0x65,0x72,0x69,0x6f,0x64,0x2c,0x20,0x31,0x30,0x29,0x20,0x7c,
|
||||
0x7c,0x20,0x32,0x30,0x30,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x74,0x68,0x69,0x73,
|
||||
0x2e,0x74,0x78,0x74,0x20,0x3d,0x20,0x22,0x22,0x3b,0x0a,0x20,0x20,0x20,0x20,0x74,
|
||||
0x68,0x69,0x73,0x2e,0x74,0x69,0x63,0x6b,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x74,0x68,0x69,0x73,0x2e,0x69,0x73,0x44,0x65,0x6c,0x65,0x74,0x69,0x6e,0x67,0x20,
|
||||
0x3d,0x20,0x66,0x61,0x6c,0x73,0x65,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x54,0x78,0x74,
|
||||
0x52,0x6f,0x74,0x61,0x74,0x65,0x2e,0x70,0x72,0x6f,0x74,0x6f,0x74,0x79,0x70,0x65,
|
||||
0x2e,0x74,0x69,0x63,0x6b,0x20,0x3d,0x20,0x66,0x75,0x6e,0x63,0x74,0x69,0x6f,0x6e,
|
||||
0x20,0x28,0x29,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6c,0x65,0x74,0x20,0x69,0x20,
|
||||
0x3d,0x20,0x74,0x68,0x69,0x73,0x2e,0x6c,0x6f,0x6f,0x70,0x4e,0x75,0x6d,0x20,0x25,
|
||||
0x20,0x74,0x68,0x69,0x73,0x2e,0x74,0x6f,0x52,0x6f,0x74,0x61,0x74,0x65,0x2e,0x6c,
|
||||
0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6c,0x65,0x74,0x20,0x66,
|
||||
0x75,0x6c,0x6c,0x54,0x78,0x74,0x20,0x3d,0x20,0x74,0x68,0x69,0x73,0x2e,0x74,0x6f,
|
||||
0x52,0x6f,0x74,0x61,0x74,0x65,0x5b,0x69,0x5d,0x3b,0x0a,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x69,0x66,0x20,0x28,0x74,0x68,0x69,0x73,0x2e,0x69,0x73,0x44,0x65,0x6c,0x65,0x74,
|
||||
0x69,0x6e,0x67,0x29,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,
|
||||
0x68,0x69,0x73,0x2e,0x74,0x78,0x74,0x20,0x3d,0x20,0x66,0x75,0x6c,0x6c,0x54,0x78,
|
||||
0x74,0x2e,0x73,0x75,0x62,0x73,0x74,0x72,0x69,0x6e,0x67,0x28,0x30,0x2c,0x20,0x74,
|
||||
0x68,0x69,0x73,0x2e,0x74,0x78,0x74,0x2e,0x6c,0x65,0x6e,0x67,0x74,0x68,0x20,0x2d,
|
||||
0x20,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x20,0x65,0x6c,0x73,0x65,0x20,
|
||||
0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x68,0x69,0x73,0x2e,0x74,
|
||||
0x78,0x74,0x20,0x3d,0x20,0x66,0x75,0x6c,0x6c,0x54,0x78,0x74,0x2e,0x73,0x75,0x62,
|
||||
0x73,0x74,0x72,0x69,0x6e,0x67,0x28,0x30,0x2c,0x20,0x74,0x68,0x69,0x73,0x2e,0x74,
|
||||
0x78,0x74,0x2e,0x6c,0x65,0x6e,0x67,0x74,0x68,0x20,0x2b,0x20,0x31,0x29,0x3b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x7d,0x0a,0x0a,0x20,0x20,0x20,0x20,0x74,0x68,0x69,0x73,0x2e,
|
||||
0x65,0x6c,0x2e,0x69,0x6e,0x6e,0x65,0x72,0x48,0x54,0x4d,0x4c,0x20,0x3d,0x20,0x27,
|
||||
0x3c,0x73,0x70,0x61,0x6e,0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x77,0x72,0x61,
|
||||
0x70,0x22,0x3e,0x27,0x20,0x2b,0x20,0x74,0x68,0x69,0x73,0x2e,0x74,0x78,0x74,0x20,
|
||||
0x2b,0x20,0x22,0x3c,0x2f,0x73,0x70,0x61,0x6e,0x3e,0x22,0x3b,0x0a,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x76,0x61,0x72,0x20,0x74,0x68,0x61,0x74,0x20,0x3d,0x20,0x74,0x68,0x69,
|
||||
0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x61,0x72,0x20,0x64,0x65,0x6c,0x74,0x61,
|
||||
0x20,0x3d,0x20,0x33,0x30,0x30,0x20,0x2d,0x20,0x4d,0x61,0x74,0x68,0x2e,0x72,0x61,
|
||||
0x6e,0x64,0x6f,0x6d,0x28,0x29,0x20,0x2a,0x20,0x31,0x30,0x30,0x3b,0x0a,0x0a,0x20,
|
||||
0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x74,0x68,0x69,0x73,0x2e,0x69,0x73,0x44,0x65,
|
||||
0x6c,0x65,0x74,0x69,0x6e,0x67,0x29,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,
|
||||
0x20,0x20,0x64,0x65,0x6c,0x74,0x61,0x20,0x2f,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x7d,0x0a,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x74,0x68,
|
||||
0x69,0x73,0x2e,0x69,0x73,0x44,0x65,0x6c,0x65,0x74,0x69,0x6e,0x67,0x20,0x26,0x26,
|
||||
0x20,0x74,0x68,0x69,0x73,0x2e,0x74,0x78,0x74,0x20,0x3d,0x3d,0x3d,0x20,0x66,0x75,
|
||||
0x6c,0x6c,0x54,0x78,0x74,0x29,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
|
||||
0x20,0x64,0x65,0x6c,0x74,0x61,0x20,0x3d,0x20,0x74,0x68,0x69,0x73,0x2e,0x70,0x65,
|
||||
0x72,0x69,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x68,
|
||||
0x69,0x73,0x2e,0x69,0x73,0x44,0x65,0x6c,0x65,0x74,0x69,0x6e,0x67,0x20,0x3d,0x20,
|
||||
0x74,0x72,0x75,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x20,0x65,0x6c,0x73,0x65,
|
||||
0x20,0x69,0x66,0x20,0x28,0x74,0x68,0x69,0x73,0x2e,0x69,0x73,0x44,0x65,0x6c,0x65,
|
||||
0x74,0x69,0x6e,0x67,0x20,0x26,0x26,0x20,0x74,0x68,0x69,0x73,0x2e,0x74,0x78,0x74,
|
||||
0x20,0x3d,0x3d,0x3d,0x20,0x22,0x22,0x29,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,
|
||||
0x20,0x20,0x20,0x74,0x68,0x69,0x73,0x2e,0x69,0x73,0x44,0x65,0x6c,0x65,0x74,0x69,
|
||||
0x6e,0x67,0x20,0x3d,0x20,0x66,0x61,0x6c,0x73,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x20,0x20,0x20,0x20,0x74,0x68,0x69,0x73,0x2e,0x6c,0x6f,0x6f,0x70,0x4e,0x75,0x6d,
|
||||
0x2b,0x2b,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x65,0x6c,0x74,
|
||||
0x61,0x20,0x3d,0x20,0x35,0x30,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x73,0x65,0x74,0x54,0x69,0x6d,0x65,0x6f,0x75,0x74,0x28,0x66,
|
||||
0x75,0x6e,0x63,0x74,0x69,0x6f,0x6e,0x20,0x28,0x29,0x20,0x7b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x20,0x20,0x20,0x20,0x74,0x68,0x61,0x74,0x2e,0x74,0x69,0x63,0x6b,0x28,0x29,
|
||||
0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x2c,0x20,0x64,0x65,0x6c,0x74,0x61,0x29,0x3b,
|
||||
0x0a,0x7d,0x3b,0x0a,0x0a,0x77,0x69,0x6e,0x64,0x6f,0x77,0x2e,0x6f,0x6e,0x6c,0x6f,
|
||||
0x61,0x64,0x20,0x3d,0x20,0x66,0x75,0x6e,0x63,0x74,0x69,0x6f,0x6e,0x20,0x28,0x29,
|
||||
0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x61,0x72,0x20,0x65,0x6c,0x65,0x6d,0x65,
|
||||
0x6e,0x74,0x73,0x20,0x3d,0x20,0x64,0x6f,0x63,0x75,0x6d,0x65,0x6e,0x74,0x2e,0x67,
|
||||
0x65,0x74,0x45,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x42,0x79,0x43,0x6c,0x61,0x73,
|
||||
0x73,0x4e,0x61,0x6d,0x65,0x28,0x22,0x74,0x78,0x74,0x2d,0x72,0x6f,0x74,0x61,0x74,
|
||||
0x65,0x22,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x76,0x61,
|
||||
0x72,0x20,0x69,0x20,0x3d,0x20,0x30,0x3b,0x20,0x69,0x20,0x3c,0x20,0x65,0x6c,0x65,
|
||||
0x6d,0x65,0x6e,0x74,0x73,0x2e,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b,0x20,0x69,0x2b,
|
||||
0x2b,0x29,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x61,0x72,
|
||||
0x20,0x74,0x6f,0x52,0x6f,0x74,0x61,0x74,0x65,0x20,0x3d,0x20,0x65,0x6c,0x65,0x6d,
|
||||
0x65,0x6e,0x74,0x73,0x5b,0x69,0x5d,0x2e,0x67,0x65,0x74,0x41,0x74,0x74,0x72,0x69,
|
||||
0x62,0x75,0x74,0x65,0x28,0x22,0x64,0x61,0x74,0x61,0x2d,0x72,0x6f,0x74,0x61,0x74,
|
||||
0x65,0x22,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x61,0x72,
|
||||
0x20,0x70,0x65,0x72,0x69,0x6f,0x64,0x20,0x3d,0x20,0x65,0x6c,0x65,0x6d,0x65,0x6e,
|
||||
0x74,0x73,0x5b,0x69,0x5d,0x2e,0x67,0x65,0x74,0x41,0x74,0x74,0x72,0x69,0x62,0x75,
|
||||
0x74,0x65,0x28,0x22,0x64,0x61,0x74,0x61,0x2d,0x70,0x65,0x72,0x69,0x6f,0x64,0x22,
|
||||
0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x74,
|
||||
0x6f,0x52,0x6f,0x74,0x61,0x74,0x65,0x29,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,
|
||||
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x65,0x77,0x20,0x54,0x78,0x74,0x52,0x6f,
|
||||
0x74,0x61,0x74,0x65,0x28,0x65,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x73,0x5b,0x69,0x5d,
|
||||
0x2c,0x20,0x4a,0x53,0x4f,0x4e,0x2e,0x70,0x61,0x72,0x73,0x65,0x28,0x74,0x6f,0x52,
|
||||
0x6f,0x74,0x61,0x74,0x65,0x29,0x2c,0x20,0x70,0x65,0x72,0x69,0x6f,0x64,0x29,0x3b,
|
||||
0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,
|
||||
0x0a,0x20,0x20,0x20,0x20,0x2f,0x2f,0x20,0x49,0x4e,0x4a,0x45,0x43,0x54,0x20,0x43,
|
||||
0x53,0x53,0x0a,0x20,0x20,0x20,0x20,0x76,0x61,0x72,0x20,0x63,0x73,0x73,0x20,0x3d,
|
||||
0x20,0x64,0x6f,0x63,0x75,0x6d,0x65,0x6e,0x74,0x2e,0x63,0x72,0x65,0x61,0x74,0x65,
|
||||
0x45,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x28,0x22,0x73,0x74,0x79,0x6c,0x65,0x22,0x29,
|
||||
0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x73,0x73,0x2e,0x69,0x6e,0x6e,0x65,0x72,0x48,
|
||||
0x54,0x4d,0x4c,0x20,0x3d,0x20,0x22,0x2e,0x74,0x78,0x74,0x2d,0x72,0x6f,0x74,0x61,
|
||||
0x74,0x65,0x20,0x3e,0x20,0x2e,0x77,0x72,0x61,0x70,0x20,0x7b,0x20,0x62,0x6f,0x72,
|
||||
0x64,0x65,0x72,0x2d,0x72,0x69,0x67,0x68,0x74,0x3a,0x20,0x30,0x2e,0x30,0x38,0x65,
|
||||
0x6d,0x20,0x73,0x6f,0x6c,0x69,0x64,0x20,0x23,0x36,0x36,0x36,0x20,0x7d,0x22,0x3b,
|
||||
0x0a,0x20,0x20,0x20,0x20,0x64,0x6f,0x63,0x75,0x6d,0x65,0x6e,0x74,0x2e,0x62,0x6f,
|
||||
0x64,0x79,0x2e,0x61,0x70,0x70,0x65,0x6e,0x64,0x43,0x68,0x69,0x6c,0x64,0x28,0x63,
|
||||
0x73,0x73,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x6c,0x65,0x74,0x20,0x6c,0x65,0x64,
|
||||
0x53,0x74,0x61,0x74,0x75,0x73,0x20,0x3d,0x20,0x66,0x61,0x6c,0x73,0x65,0x3b,0x0a,
|
||||
0x0a,0x66,0x75,0x6e,0x63,0x74,0x69,0x6f,0x6e,0x20,0x74,0x6f,0x67,0x67,0x6c,0x65,
|
||||
0x4c,0x65,0x64,0x28,0x29,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6c,0x65,0x74,0x20,
|
||||
0x63,0x6c,0x69,0x63,0x6b,0x65,0x64,0x20,0x3d,0x20,0x6e,0x65,0x77,0x20,0x58,0x4d,
|
||||
0x4c,0x48,0x74,0x74,0x70,0x52,0x65,0x71,0x75,0x65,0x73,0x74,0x28,0x29,0x3b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x6c,0x65,0x74,0x20,0x6c,0x65,0x64,0x42,0x75,0x74,0x74,0x6f,
|
||||
0x6e,0x20,0x3d,0x20,0x64,0x6f,0x63,0x75,0x6d,0x65,0x6e,0x74,0x2e,0x67,0x65,0x74,
|
||||
0x45,0x6c,0x65,0x6d,0x65,0x6e,0x74,0x42,0x79,0x49,0x64,0x28,0x22,0x6c,0x65,0x64,
|
||||
0x2d,0x62,0x74,0x6e,0x22,0x29,0x3b,0x0a,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,
|
||||
0x28,0x6c,0x65,0x64,0x53,0x74,0x61,0x74,0x75,0x73,0x20,0x3d,0x3d,0x3d,0x20,0x74,
|
||||
0x72,0x75,0x65,0x29,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6c,
|
||||
0x65,0x64,0x53,0x74,0x61,0x74,0x75,0x73,0x20,0x3d,0x20,0x66,0x61,0x6c,0x73,0x65,
|
||||
0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6c,0x65,0x64,0x42,0x75,0x74,
|
||||
0x74,0x6f,0x6e,0x2e,0x73,0x74,0x79,0x6c,0x65,0x2e,0x62,0x61,0x63,0x6b,0x67,0x72,
|
||||
0x6f,0x75,0x6e,0x64,0x49,0x6d,0x61,0x67,0x65,0x20,0x3d,0x20,0x22,0x75,0x72,0x6c,
|
||||
0x28,0x27,0x2e,0x2f,0x61,0x73,0x73,0x65,0x74,0x2f,0x6f,0x66,0x66,0x2e,0x70,0x6e,
|
||||
0x67,0x27,0x29,0x22,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x20,0x65,0x6c,0x73,0x65,
|
||||
0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6c,0x65,0x64,0x53,0x74,
|
||||
0x61,0x74,0x75,0x73,0x20,0x3d,0x20,0x74,0x72,0x75,0x65,0x3b,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x20,0x20,0x20,0x20,0x6c,0x65,0x64,0x42,0x75,0x74,0x74,0x6f,0x6e,0x2e,0x73,
|
||||
0x74,0x79,0x6c,0x65,0x2e,0x62,0x61,0x63,0x6b,0x67,0x72,0x6f,0x75,0x6e,0x64,0x49,
|
||||
0x6d,0x61,0x67,0x65,0x20,0x3d,0x20,0x22,0x75,0x72,0x6c,0x28,0x27,0x2e,0x2f,0x61,
|
||||
0x73,0x73,0x65,0x74,0x2f,0x6f,0x6e,0x2e,0x70,0x6e,0x67,0x27,0x29,0x22,0x3b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x7d,0x0a,0x0a,0x20,0x20,0x20,0x20,0x63,0x6c,0x69,0x63,0x6b,
|
||||
0x65,0x64,0x2e,0x6f,0x70,0x65,0x6e,0x28,0x22,0x50,0x4f,0x53,0x54,0x22,0x2c,0x20,
|
||||
0x22,0x2f,0x62,0x75,0x74,0x74,0x6f,0x6e,0x5f,0x63,0x6c,0x69,0x63,0x6b,0x65,0x64,
|
||||
0x22,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6c,0x69,0x63,0x6b,0x65,0x64,0x2e,
|
||||
0x73,0x65,0x6e,0x64,0x28,0x60,0x7b,0x22,0x6c,0x65,0x64,0x22,0x3a,0x20,0x22,0x24,
|
||||
0x7b,0x6c,0x65,0x64,0x53,0x74,0x61,0x74,0x75,0x73,0x7d,0x22,0x7d,0x60,0x29,0x3b,
|
||||
0x0a,0x20,0x20,0x20,0x20,0x63,0x6c,0x69,0x63,0x6b,0x65,0x64,0x2e,0x6f,0x6e,0x72,
|
||||
0x65,0x61,0x64,0x79,0x73,0x74,0x61,0x74,0x65,0x63,0x68,0x61,0x6e,0x67,0x65,0x20,
|
||||
0x3d,0x20,0x66,0x75,0x6e,0x63,0x74,0x69,0x6f,0x6e,0x20,0x28,0x29,0x20,0x7b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x6c,0x69,0x63,
|
||||
0x6b,0x65,0x64,0x2e,0x72,0x65,0x61,0x64,0x79,0x53,0x74,0x61,0x74,0x65,0x20,0x3d,
|
||||
0x3d,0x3d,0x20,0x34,0x20,0x26,0x26,0x20,0x63,0x6c,0x69,0x63,0x6b,0x65,0x64,0x2e,
|
||||
0x73,0x74,0x61,0x74,0x75,0x73,0x20,0x3d,0x3d,0x3d,0x20,0x32,0x30,0x30,0x29,0x20,
|
||||
0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x6f,
|
||||
0x6e,0x73,0x6f,0x6c,0x65,0x2e,0x6c,0x6f,0x67,0x28,0x63,0x6c,0x69,0x63,0x6b,0x65,
|
||||
0x64,0x2e,0x72,0x65,0x73,0x70,0x6f,0x6e,0x73,0x65,0x54,0x65,0x78,0x74,0x29,0x3b,
|
||||
0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,
|
||||
0x3b,0x0a,0x7d,0x0a,};
|
||||
|
||||
#if FSDATA_FILE_ALIGNMENT==1
|
||||
static const unsigned int dummy_align__404_html = 6;
|
||||
#endif
|
||||
static const unsigned char FSDATA_ALIGN_PRE data__404_html[] FSDATA_ALIGN_POST = {
|
||||
/* /404.html (10z chars) */
|
||||
0x2f,0x34,0x30,0x34,0x2e,0x68,0x74,0x6d,0x6c,0x00,0x00,0x00,
|
||||
|
||||
/* HTTP header */
|
||||
/* "HTTP/1.0 404 File not found
|
||||
" (29z bytes) */
|
||||
0x48,0x54,0x54,0x50,0x2f,0x31,0x2e,0x30,0x20,0x34,0x30,0x34,0x20,0x46,0x69,0x6c,
|
||||
0x65,0x20,0x6e,0x6f,0x74,0x20,0x66,0x6f,0x75,0x6e,0x64,0x0d,0x0a,
|
||||
/* "Server: lwIP/2.1.3d (http://savannah.nongnu.org/projects/lwip)
|
||||
" (64z bytes) */
|
||||
0x53,0x65,0x72,0x76,0x65,0x72,0x3a,0x20,0x6c,0x77,0x49,0x50,0x2f,0x32,0x2e,0x31,
|
||||
0x2e,0x33,0x64,0x20,0x28,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x73,0x61,0x76,0x61,
|
||||
0x6e,0x6e,0x61,0x68,0x2e,0x6e,0x6f,0x6e,0x67,0x6e,0x75,0x2e,0x6f,0x72,0x67,0x2f,
|
||||
0x70,0x72,0x6f,0x6a,0x65,0x63,0x74,0x73,0x2f,0x6c,0x77,0x69,0x70,0x29,0x0d,0x0a,
|
||||
|
||||
/* "Content-Length: 108
|
||||
" (18z+ bytes) */
|
||||
0x43,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x2d,0x4c,0x65,0x6e,0x67,0x74,0x68,0x3a,0x20,
|
||||
0x31,0x30,0x38,0x0d,0x0a,
|
||||
/* "Content-Type: text/html
|
||||
|
||||
" (27z bytes) */
|
||||
0x43,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x2d,0x54,0x79,0x70,0x65,0x3a,0x20,0x74,0x65,
|
||||
0x78,0x74,0x2f,0x68,0x74,0x6d,0x6c,0x0d,0x0a,0x0d,0x0a,
|
||||
/* raw file data (108 bytes) */
|
||||
0x3c,0x21,0x44,0x4f,0x43,0x54,0x59,0x50,0x45,0x20,0x68,0x74,0x6d,0x6c,0x3e,0x3c,
|
||||
0x68,0x74,0x6d,0x6c,0x20,0x6c,0x61,0x6e,0x67,0x3d,0x22,0x65,0x6e,0x22,0x3e,0x3c,
|
||||
0x68,0x65,0x61,0x64,0x3e,0x3c,0x74,0x69,0x74,0x6c,0x65,0x3e,0x50,0x61,0x67,0x65,
|
||||
0x20,0x4e,0x6f,0x74,0x20,0x46,0x6f,0x75,0x6e,0x64,0x3c,0x2f,0x74,0x69,0x74,0x6c,
|
||||
0x65,0x3e,0x3c,0x2f,0x68,0x65,0x61,0x64,0x3e,0x3c,0x62,0x6f,0x64,0x79,0x3e,0x50,
|
||||
0x61,0x67,0x65,0x20,0x4e,0x6f,0x74,0x20,0x46,0x6f,0x75,0x6e,0x64,0x2e,0x3c,0x2f,
|
||||
0x62,0x6f,0x64,0x79,0x3e,0x3c,0x2f,0x68,0x74,0x6d,0x6c,0x3e,};
|
||||
|
||||
#if FSDATA_FILE_ALIGNMENT==1
|
||||
static const unsigned int dummy_align__index_html = 7;
|
||||
#endif
|
||||
static const unsigned char FSDATA_ALIGN_PRE data__index_html[] FSDATA_ALIGN_POST = {
|
||||
/* /index.html (12z chars) */
|
||||
0x2f,0x69,0x6e,0x64,0x65,0x78,0x2e,0x68,0x74,0x6d,0x6c,0x00,
|
||||
|
||||
/* HTTP header */
|
||||
/* "HTTP/1.0 200 OK
|
||||
" (17z bytes) */
|
||||
0x48,0x54,0x54,0x50,0x2f,0x31,0x2e,0x30,0x20,0x32,0x30,0x30,0x20,0x4f,0x4b,0x0d,
|
||||
0x0a,
|
||||
/* "Server: lwIP/2.1.3d (http://savannah.nongnu.org/projects/lwip)
|
||||
" (64z bytes) */
|
||||
0x53,0x65,0x72,0x76,0x65,0x72,0x3a,0x20,0x6c,0x77,0x49,0x50,0x2f,0x32,0x2e,0x31,
|
||||
0x2e,0x33,0x64,0x20,0x28,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x73,0x61,0x76,0x61,
|
||||
0x6e,0x6e,0x61,0x68,0x2e,0x6e,0x6f,0x6e,0x67,0x6e,0x75,0x2e,0x6f,0x72,0x67,0x2f,
|
||||
0x70,0x72,0x6f,0x6a,0x65,0x63,0x74,0x73,0x2f,0x6c,0x77,0x69,0x70,0x29,0x0d,0x0a,
|
||||
|
||||
/* "Content-Length: 973
|
||||
" (18z+ bytes) */
|
||||
0x43,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x2d,0x4c,0x65,0x6e,0x67,0x74,0x68,0x3a,0x20,
|
||||
0x39,0x37,0x33,0x0d,0x0a,
|
||||
/* "Content-Type: text/html
|
||||
|
||||
" (27z bytes) */
|
||||
0x43,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x2d,0x54,0x79,0x70,0x65,0x3a,0x20,0x74,0x65,
|
||||
0x78,0x74,0x2f,0x68,0x74,0x6d,0x6c,0x0d,0x0a,0x0d,0x0a,
|
||||
/* raw file data (973 bytes) */
|
||||
0x3c,0x21,0x44,0x4f,0x43,0x54,0x59,0x50,0x45,0x20,0x68,0x74,0x6d,0x6c,0x3e,0x0a,
|
||||
0x3c,0x68,0x74,0x6d,0x6c,0x20,0x6c,0x61,0x6e,0x67,0x3d,0x22,0x65,0x6e,0x22,0x3e,
|
||||
0x0a,0x20,0x20,0x20,0x20,0x3c,0x68,0x65,0x61,0x64,0x3e,0x0a,0x20,0x20,0x20,0x20,
|
||||
0x20,0x20,0x20,0x20,0x3c,0x6d,0x65,0x74,0x61,0x20,0x68,0x74,0x74,0x70,0x2d,0x65,
|
||||
0x71,0x75,0x69,0x76,0x3d,0x22,0x43,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x2d,0x54,0x79,
|
||||
0x70,0x65,0x22,0x20,0x63,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x3d,0x22,0x74,0x65,0x78,
|
||||
0x74,0x2f,0x68,0x74,0x6d,0x6c,0x3b,0x20,0x63,0x68,0x61,0x72,0x73,0x65,0x74,0x3d,
|
||||
0x55,0x54,0x46,0x2d,0x38,0x22,0x20,0x2f,0x3e,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,
|
||||
0x20,0x20,0x3c,0x6d,0x65,0x74,0x61,0x20,0x6e,0x61,0x6d,0x65,0x3d,0x22,0x76,0x69,
|
||||
0x65,0x77,0x70,0x6f,0x72,0x74,0x22,0x20,0x63,0x6f,0x6e,0x74,0x65,0x6e,0x74,0x3d,
|
||||
0x22,0x77,0x69,0x64,0x74,0x68,0x3d,0x64,0x65,0x76,0x69,0x63,0x65,0x2d,0x77,0x69,
|
||||
0x64,0x74,0x68,0x2c,0x20,0x69,0x6e,0x69,0x74,0x69,0x61,0x6c,0x2d,0x73,0x63,0x61,
|
||||
0x6c,0x65,0x3d,0x31,0x22,0x20,0x2f,0x3e,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
|
||||
0x20,0x3c,0x74,0x69,0x74,0x6c,0x65,0x3e,0x42,0x6f,0x75,0x66,0x66,0x61,0x6c,0x6f,
|
||||
0x4c,0x61,0x62,0x20,0x44,0x65,0x6d,0x6f,0x20,0x50,0x61,0x67,0x65,0x3c,0x2f,0x74,
|
||||
0x69,0x74,0x6c,0x65,0x3e,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3c,0x6c,
|
||||
0x69,0x6e,0x6b,0x20,0x68,0x72,0x65,0x66,0x3d,0x22,0x63,0x73,0x73,0x2f,0x73,0x74,
|
||||
0x79,0x6c,0x65,0x2e,0x63,0x73,0x73,0x22,0x20,0x74,0x79,0x70,0x65,0x3d,0x22,0x74,
|
||||
0x65,0x78,0x74,0x2f,0x63,0x73,0x73,0x22,0x20,0x72,0x65,0x6c,0x3d,0x22,0x73,0x74,
|
||||
0x79,0x6c,0x65,0x73,0x68,0x65,0x65,0x74,0x22,0x20,0x2f,0x3e,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x3c,0x2f,0x68,0x65,0x61,0x64,0x3e,0x0a,0x20,0x20,0x20,0x20,0x3c,0x62,0x6f,
|
||||
0x64,0x79,0x3e,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3c,0x68,0x31,0x20,
|
||||
0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x74,0x69,0x74,0x6c,0x65,0x22,0x3e,0x20,0x42,
|
||||
0x6f,0x75,0x66,0x66,0x61,0x6c,0x6f,0x4c,0x61,0x62,0x20,0x57,0x65,0x62,0x20,0x44,
|
||||
0x65,0x6d,0x6f,0x20,0x50,0x61,0x67,0x65,0x20,0x3c,0x69,0x20,0x69,0x64,0x3d,0x22,
|
||||
0x6c,0x65,0x64,0x2d,0x62,0x74,0x6e,0x22,0x20,0x6f,0x6e,0x63,0x6c,0x69,0x63,0x6b,
|
||||
0x3d,0x22,0x74,0x6f,0x67,0x67,0x6c,0x65,0x4c,0x65,0x64,0x28,0x29,0x22,0x20,0x63,
|
||||
0x6c,0x61,0x73,0x73,0x3d,0x22,0x69,0x63,0x6f,0x6e,0x2d,0x73,0x77,0x69,0x74,0x63,
|
||||
0x68,0x22,0x3e,0x3c,0x2f,0x69,0x3e,0x3c,0x2f,0x68,0x31,0x3e,0x0a,0x20,0x20,0x20,
|
||||
0x20,0x20,0x20,0x20,0x20,0x3c,0x68,0x31,0x20,0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,
|
||||
0x63,0x6d,0x64,0x22,0x3e,0x20,0x3e,0x3e,0x3e,0x20,0x65,0x63,0x68,0x6f,0x20,0x22,
|
||||
0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57,0x6f,0x72,0x6c,0x64,0x21,0x22,0x20,0x3c,0x2f,
|
||||
0x68,0x31,0x3e,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3c,0x68,0x31,0x20,
|
||||
0x63,0x6c,0x61,0x73,0x73,0x3d,0x22,0x63,0x6d,0x64,0x22,0x3e,0x20,0x48,0x65,0x6c,
|
||||
0x6c,0x6f,0x20,0x57,0x6f,0x72,0x6c,0x64,0x21,0x20,0x3c,0x2f,0x68,0x31,0x3e,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3c,0x68,0x31,0x20,0x63,0x6c,0x61,0x73,
|
||||
0x73,0x3d,0x22,0x63,0x6d,0x64,0x22,0x3e,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
|
||||
0x20,0x20,0x20,0x20,0x20,0x3e,0x3e,0x3e,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
|
||||
0x20,0x20,0x20,0x20,0x20,0x3c,0x73,0x70,0x61,0x6e,0x0a,0x20,0x20,0x20,0x20,0x20,
|
||||
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x6c,0x61,0x73,0x73,
|
||||
0x3d,0x22,0x74,0x78,0x74,0x2d,0x72,0x6f,0x74,0x61,0x74,0x65,0x22,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x61,
|
||||
0x74,0x61,0x2d,0x70,0x65,0x72,0x69,0x6f,0x64,0x3d,0x22,0x32,0x30,0x30,0x30,0x22,
|
||||
0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
|
||||
0x20,0x64,0x61,0x74,0x61,0x2d,0x72,0x6f,0x74,0x61,0x74,0x65,0x3d,0x27,0x5b,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
|
||||
0x22,0x54,0x68,0x69,0x73,0x20,0x69,0x73,0x20,0x42,0x6f,0x75,0x66,0x66,0x61,0x6c,
|
||||
0x6f,0x4c,0x61,0x62,0x20,0x68,0x74,0x74,0x70,0x20,0x64,0x65,0x6d,0x6f,0x20,0x70,
|
||||
0x61,0x67,0x65,0x2e,0x22,0x2c,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
|
||||
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x22,0x68,0x74,0x74,0x70,0x3a,0x2f,0x2f,0x77,
|
||||
0x77,0x77,0x2e,0x62,0x6f,0x75,0x66,0x66,0x61,0x6c,0x6f,0x6c,0x61,0x62,0x2e,0x63,
|
||||
0x6f,0x6d,0x2f,0x22,0x2c,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
|
||||
0x20,0x20,0x20,0x20,0x20,0x20,0x22,0x57,0x65,0x6c,0x63,0x6f,0x6d,0x65,0x20,0x74,
|
||||
0x6f,0x20,0x75,0x73,0x65,0x20,0x42,0x6f,0x75,0x66,0x66,0x61,0x6c,0x6f,0x4c,0x61,
|
||||
0x62,0x20,0x43,0x68,0x69,0x70,0x2e,0x22,0x5d,0x27,0x0a,0x20,0x20,0x20,0x20,0x20,
|
||||
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3e,0x3c,0x2f,0x73,0x70,0x61,0x6e,0x3e,0x0a,
|
||||
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3c,0x2f,0x68,0x31,0x3e,0x0a,0x20,0x20,
|
||||
0x20,0x20,0x20,0x20,0x20,0x20,0x3c,0x73,0x63,0x72,0x69,0x70,0x74,0x20,0x73,0x72,
|
||||
0x63,0x3d,0x22,0x6a,0x73,0x2f,0x6d,0x61,0x69,0x6e,0x2e,0x6a,0x73,0x22,0x3e,0x3c,
|
||||
0x2f,0x73,0x63,0x72,0x69,0x70,0x74,0x3e,0x0a,0x20,0x20,0x20,0x20,0x3c,0x2f,0x62,
|
||||
0x6f,0x64,0x79,0x3e,0x0a,0x3c,0x2f,0x68,0x74,0x6d,0x6c,0x3e,0x0a,};
|
||||
|
||||
|
||||
|
||||
const struct fsdata_file file__asset_favicon_ico[] = { {
|
||||
file_NULL,
|
||||
data__asset_favicon_ico,
|
||||
data__asset_favicon_ico + 20,
|
||||
sizeof(data__asset_favicon_ico) - 20,
|
||||
FS_FILE_FLAGS_HEADER_INCLUDED | FS_FILE_FLAGS_HEADER_PERSISTENT,
|
||||
}};
|
||||
|
||||
const struct fsdata_file file__asset_off_png[] = { {
|
||||
file__asset_favicon_ico,
|
||||
data__asset_off_png,
|
||||
data__asset_off_png + 16,
|
||||
sizeof(data__asset_off_png) - 16,
|
||||
FS_FILE_FLAGS_HEADER_INCLUDED | FS_FILE_FLAGS_HEADER_PERSISTENT,
|
||||
}};
|
||||
|
||||
const struct fsdata_file file__asset_ok_json[] = { {
|
||||
file__asset_off_png,
|
||||
data__asset_ok_json,
|
||||
data__asset_ok_json + 16,
|
||||
sizeof(data__asset_ok_json) - 16,
|
||||
FS_FILE_FLAGS_HEADER_INCLUDED | FS_FILE_FLAGS_SSI,
|
||||
}};
|
||||
|
||||
const struct fsdata_file file__asset_on_png[] = { {
|
||||
file__asset_ok_json,
|
||||
data__asset_on_png,
|
||||
data__asset_on_png + 16,
|
||||
sizeof(data__asset_on_png) - 16,
|
||||
FS_FILE_FLAGS_HEADER_INCLUDED | FS_FILE_FLAGS_HEADER_PERSISTENT,
|
||||
}};
|
||||
|
||||
const struct fsdata_file file__css_style_css[] = { {
|
||||
file__asset_on_png,
|
||||
data__css_style_css,
|
||||
data__css_style_css + 16,
|
||||
sizeof(data__css_style_css) - 16,
|
||||
FS_FILE_FLAGS_HEADER_INCLUDED | FS_FILE_FLAGS_HEADER_PERSISTENT,
|
||||
}};
|
||||
|
||||
const struct fsdata_file file__js_main_js[] = { {
|
||||
file__css_style_css,
|
||||
data__js_main_js,
|
||||
data__js_main_js + 12,
|
||||
sizeof(data__js_main_js) - 12,
|
||||
FS_FILE_FLAGS_HEADER_INCLUDED | FS_FILE_FLAGS_HEADER_PERSISTENT,
|
||||
}};
|
||||
|
||||
const struct fsdata_file file__404_html[] = { {
|
||||
file__js_main_js,
|
||||
data__404_html,
|
||||
data__404_html + 12,
|
||||
sizeof(data__404_html) - 12,
|
||||
FS_FILE_FLAGS_HEADER_INCLUDED | FS_FILE_FLAGS_HEADER_PERSISTENT,
|
||||
}};
|
||||
|
||||
const struct fsdata_file file__index_html[] = { {
|
||||
file__404_html,
|
||||
data__index_html,
|
||||
data__index_html + 12,
|
||||
sizeof(data__index_html) - 12,
|
||||
FS_FILE_FLAGS_HEADER_INCLUDED | FS_FILE_FLAGS_HEADER_PERSISTENT,
|
||||
}};
|
||||
|
||||
#define FS_ROOT file__index_html
|
||||
#define FS_NUMFILES 8
|
||||
// clang-format on
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -6,32 +6,30 @@
|
||||
#if LWIP_HTTPD_DYNAMIC_HEADERS
|
||||
/** This struct is used for a list of HTTP header strings for various
|
||||
* filename extensions. */
|
||||
typedef struct
|
||||
{
|
||||
const char *extension;
|
||||
const char *content_type;
|
||||
typedef struct {
|
||||
const char *extension;
|
||||
const char *content_type;
|
||||
} tHTTPHeader;
|
||||
|
||||
/** A list of strings used in HTTP headers (see RFC 1945 HTTP/1.0 and
|
||||
* RFC 2616 HTTP/1.1 for header field definitions) */
|
||||
static const char *const g_psHTTPHeaderStrings[] = {
|
||||
"HTTP/1.0 200 OK\r\n",
|
||||
"HTTP/1.0 404 File not found\r\n",
|
||||
"HTTP/1.0 400 Bad Request\r\n",
|
||||
"HTTP/1.0 501 Not Implemented\r\n",
|
||||
"HTTP/1.1 200 OK\r\n",
|
||||
"HTTP/1.1 404 File not found\r\n",
|
||||
"HTTP/1.1 400 Bad Request\r\n",
|
||||
"HTTP/1.1 501 Not Implemented\r\n",
|
||||
"Content-Length: ",
|
||||
"Connection: Close\r\n",
|
||||
"Connection: keep-alive\r\n",
|
||||
"Connection: keep-alive\r\nContent-Length: ",
|
||||
"Server: " HTTPD_SERVER_AGENT "\r\n",
|
||||
"\r\n<html><body><h2>404: The requested file cannot be found.</h2></body></html>\r\n"
|
||||
"HTTP/1.0 200 OK\r\n",
|
||||
"HTTP/1.0 404 File not found\r\n",
|
||||
"HTTP/1.0 400 Bad Request\r\n",
|
||||
"HTTP/1.0 501 Not Implemented\r\n",
|
||||
"HTTP/1.1 200 OK\r\n",
|
||||
"HTTP/1.1 404 File not found\r\n",
|
||||
"HTTP/1.1 400 Bad Request\r\n",
|
||||
"HTTP/1.1 501 Not Implemented\r\n",
|
||||
"Content-Length: ",
|
||||
"Connection: Close\r\n",
|
||||
"Connection: keep-alive\r\n",
|
||||
"Connection: keep-alive\r\nContent-Length: ",
|
||||
"Server: "HTTPD_SERVER_AGENT"\r\n",
|
||||
"\r\n<html><body><h2>404: The requested file cannot be found.</h2></body></html>\r\n"
|
||||
#if LWIP_HTTPD_SUPPORT_11_KEEPALIVE
|
||||
,
|
||||
"Connection: keep-alive\r\nContent-Length: 77\r\n\r\n<html><body><h2>404: The requested file cannot be found.</h2></body></html>\r\n"
|
||||
, "Connection: keep-alive\r\nContent-Length: 77\r\n\r\n<html><body><h2>404: The requested file cannot be found.</h2></body></html>\r\n"
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -54,61 +52,60 @@ static const char *const g_psHTTPHeaderStrings[] = {
|
||||
#define DEFAULT_404_HTML_PERSISTENT 14 /* default 404 body, but including Connection: keep-alive */
|
||||
#endif
|
||||
|
||||
#define HTTP_CONTENT_TYPE(contenttype) "Content-Type: " contenttype "\r\n\r\n"
|
||||
#define HTTP_CONTENT_TYPE_ENCODING(contenttype, encoding) "Content-Type: " contenttype "\r\nContent-Encoding: " encoding "\r\n\r\n"
|
||||
#define HTTP_CONTENT_TYPE(contenttype) "Content-Type: "contenttype"\r\n\r\n"
|
||||
#define HTTP_CONTENT_TYPE_ENCODING(contenttype, encoding) "Content-Type: "contenttype"\r\nContent-Encoding: "encoding"\r\n\r\n"
|
||||
|
||||
#define HTTP_HDR_HTML HTTP_CONTENT_TYPE("text/html")
|
||||
#define HTTP_HDR_SSI HTTP_CONTENT_TYPE("text/html\r\nExpires: Fri, 10 Apr 2008 14:00:00 GMT\r\nPragma: no-cache")
|
||||
#define HTTP_HDR_GIF HTTP_CONTENT_TYPE("image/gif")
|
||||
#define HTTP_HDR_PNG HTTP_CONTENT_TYPE("image/png")
|
||||
#define HTTP_HDR_JPG HTTP_CONTENT_TYPE("image/jpeg")
|
||||
#define HTTP_HDR_BMP HTTP_CONTENT_TYPE("image/bmp")
|
||||
#define HTTP_HDR_ICO HTTP_CONTENT_TYPE("image/x-icon")
|
||||
#define HTTP_HDR_APP HTTP_CONTENT_TYPE("application/octet-stream")
|
||||
#define HTTP_HDR_JS HTTP_CONTENT_TYPE("application/javascript")
|
||||
#define HTTP_HDR_RA HTTP_CONTENT_TYPE("application/javascript")
|
||||
#define HTTP_HDR_CSS HTTP_CONTENT_TYPE("text/css")
|
||||
#define HTTP_HDR_SWF HTTP_CONTENT_TYPE("application/x-shockwave-flash")
|
||||
#define HTTP_HDR_XML HTTP_CONTENT_TYPE("text/xml")
|
||||
#define HTTP_HDR_PDF HTTP_CONTENT_TYPE("application/pdf")
|
||||
#define HTTP_HDR_JSON HTTP_CONTENT_TYPE("application/json")
|
||||
#define HTTP_HDR_CSV HTTP_CONTENT_TYPE("text/csv")
|
||||
#define HTTP_HDR_TSV HTTP_CONTENT_TYPE("text/tsv")
|
||||
#define HTTP_HDR_SVG HTTP_CONTENT_TYPE("image/svg+xml")
|
||||
#define HTTP_HDR_SVGZ HTTP_CONTENT_TYPE_ENCODING("image/svg+xml", "gzip")
|
||||
#define HTTP_HDR_HTML HTTP_CONTENT_TYPE("text/html")
|
||||
#define HTTP_HDR_SSI HTTP_CONTENT_TYPE("text/html\r\nExpires: Fri, 10 Apr 2008 14:00:00 GMT\r\nPragma: no-cache")
|
||||
#define HTTP_HDR_GIF HTTP_CONTENT_TYPE("image/gif")
|
||||
#define HTTP_HDR_PNG HTTP_CONTENT_TYPE("image/png")
|
||||
#define HTTP_HDR_JPG HTTP_CONTENT_TYPE("image/jpeg")
|
||||
#define HTTP_HDR_BMP HTTP_CONTENT_TYPE("image/bmp")
|
||||
#define HTTP_HDR_ICO HTTP_CONTENT_TYPE("image/x-icon")
|
||||
#define HTTP_HDR_APP HTTP_CONTENT_TYPE("application/octet-stream")
|
||||
#define HTTP_HDR_JS HTTP_CONTENT_TYPE("application/javascript")
|
||||
#define HTTP_HDR_RA HTTP_CONTENT_TYPE("application/javascript")
|
||||
#define HTTP_HDR_CSS HTTP_CONTENT_TYPE("text/css")
|
||||
#define HTTP_HDR_SWF HTTP_CONTENT_TYPE("application/x-shockwave-flash")
|
||||
#define HTTP_HDR_XML HTTP_CONTENT_TYPE("text/xml")
|
||||
#define HTTP_HDR_PDF HTTP_CONTENT_TYPE("application/pdf")
|
||||
#define HTTP_HDR_JSON HTTP_CONTENT_TYPE("application/json")
|
||||
#define HTTP_HDR_CSV HTTP_CONTENT_TYPE("text/csv")
|
||||
#define HTTP_HDR_TSV HTTP_CONTENT_TYPE("text/tsv")
|
||||
#define HTTP_HDR_SVG HTTP_CONTENT_TYPE("image/svg+xml")
|
||||
#define HTTP_HDR_SVGZ HTTP_CONTENT_TYPE_ENCODING("image/svg+xml", "gzip")
|
||||
|
||||
#define HTTP_HDR_DEFAULT_TYPE HTTP_CONTENT_TYPE("text/plain")
|
||||
#define HTTP_HDR_DEFAULT_TYPE HTTP_CONTENT_TYPE("text/plain")
|
||||
|
||||
/** A list of extension-to-HTTP header strings (see outdated RFC 1700 MEDIA TYPES
|
||||
* and http://www.iana.org/assignments/media-types for registered content types
|
||||
* and subtypes) */
|
||||
static const tHTTPHeader g_psHTTPHeaders[] = {
|
||||
{ "html", HTTP_HDR_HTML },
|
||||
{ "htm", HTTP_HDR_HTML },
|
||||
{ "shtml", HTTP_HDR_SSI },
|
||||
{ "shtm", HTTP_HDR_SSI },
|
||||
{ "ssi", HTTP_HDR_SSI },
|
||||
{ "gif", HTTP_HDR_GIF },
|
||||
{ "png", HTTP_HDR_PNG },
|
||||
{ "jpg", HTTP_HDR_JPG },
|
||||
{ "bmp", HTTP_HDR_BMP },
|
||||
{ "ico", HTTP_HDR_ICO },
|
||||
{ "class", HTTP_HDR_APP },
|
||||
{ "cls", HTTP_HDR_APP },
|
||||
{ "js", HTTP_HDR_JS },
|
||||
{ "ram", HTTP_HDR_RA },
|
||||
{ "css", HTTP_HDR_CSS },
|
||||
{ "swf", HTTP_HDR_SWF },
|
||||
{ "xml", HTTP_HDR_XML },
|
||||
{ "xsl", HTTP_HDR_XML },
|
||||
{ "pdf", HTTP_HDR_PDF },
|
||||
{ "json", HTTP_HDR_JSON }
|
||||
{ "html", HTTP_HDR_HTML},
|
||||
{ "htm", HTTP_HDR_HTML},
|
||||
{ "shtml", HTTP_HDR_SSI},
|
||||
{ "shtm", HTTP_HDR_SSI},
|
||||
{ "ssi", HTTP_HDR_SSI},
|
||||
{ "gif", HTTP_HDR_GIF},
|
||||
{ "png", HTTP_HDR_PNG},
|
||||
{ "jpg", HTTP_HDR_JPG},
|
||||
{ "bmp", HTTP_HDR_BMP},
|
||||
{ "ico", HTTP_HDR_ICO},
|
||||
{ "class", HTTP_HDR_APP},
|
||||
{ "cls", HTTP_HDR_APP},
|
||||
{ "js", HTTP_HDR_JS},
|
||||
{ "ram", HTTP_HDR_RA},
|
||||
{ "css", HTTP_HDR_CSS},
|
||||
{ "swf", HTTP_HDR_SWF},
|
||||
{ "xml", HTTP_HDR_XML},
|
||||
{ "xsl", HTTP_HDR_XML},
|
||||
{ "pdf", HTTP_HDR_PDF},
|
||||
{ "json", HTTP_HDR_JSON}
|
||||
#ifdef HTTPD_ADDITIONAL_CONTENT_TYPES
|
||||
/* If you need to add content types not listed here:
|
||||
* #define HTTPD_ADDITIONAL_CONTENT_TYPES {"ct1", HTTP_CONTENT_TYPE("text/ct1")}, {"exe", HTTP_CONTENT_TYPE("application/exe")}
|
||||
*/
|
||||
,
|
||||
HTTPD_ADDITIONAL_CONTENT_TYPES
|
||||
/* If you need to add content types not listed here:
|
||||
* #define HTTPD_ADDITIONAL_CONTENT_TYPES {"ct1", HTTP_CONTENT_TYPE("text/ct1")}, {"exe", HTTP_CONTENT_TYPE("application/exe")}
|
||||
*/
|
||||
, HTTPD_ADDITIONAL_CONTENT_TYPES
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -118,7 +115,7 @@ static const tHTTPHeader g_psHTTPHeaders[] = {
|
||||
|
||||
#if LWIP_HTTPD_SSI
|
||||
static const char *const g_pcSSIExtensions[] = {
|
||||
".shtml", ".shtm", ".ssi", ".xml", ".json"
|
||||
".shtml", ".shtm", ".ssi", ".xml", ".json"
|
||||
};
|
||||
#define NUM_SHTML_EXTENSIONS LWIP_ARRAYSIZE(g_pcSSIExtensions)
|
||||
#endif /* LWIP_HTTPD_SSI */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,13 +0,0 @@
|
||||
This directory contains a script ('makefsdata') to create C code suitable for
|
||||
httpd for given html pages (or other files) in a directory.
|
||||
|
||||
There is also a plain C console application doing the same and extended a bit.
|
||||
|
||||
Usage: htmlgen [targetdir] [-s] [-i]s
|
||||
targetdir: relative or absolute path to files to convert
|
||||
switch -s: toggle processing of subdirectories (default is on)
|
||||
switch -e: exclude HTTP header from file (header is created at runtime, default is on)
|
||||
switch -11: include HTTP 1.1 header (1.0 is default)
|
||||
|
||||
if targetdir not specified, makefsdata will attempt to
|
||||
process files in subdirectory 'fs'.
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @file
|
||||
* NetBIOS name service responder
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
* NetBIOS name service responder
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup netbiosns NETBIOS responder
|
||||
@ -48,7 +48,7 @@
|
||||
|
||||
#include "lwip/apps/netbiosns.h"
|
||||
|
||||
#if LWIP_IPV4 && LWIP_UDP /* don't build if not configured for use in lwipopts.h */
|
||||
#if LWIP_IPV4 && LWIP_UDP /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "lwip/def.h"
|
||||
#include "lwip/udp.h"
|
||||
@ -66,167 +66,167 @@
|
||||
#define NETBIOS_NAME_TTL 300000u
|
||||
|
||||
/** NetBIOS header flags */
|
||||
#define NETB_HFLAG_RESPONSE 0x8000U
|
||||
#define NETB_HFLAG_OPCODE 0x7800U
|
||||
#define NETB_HFLAG_OPCODE_NAME_QUERY 0x0000U
|
||||
#define NETB_HFLAG_AUTHORATIVE 0x0400U
|
||||
#define NETB_HFLAG_TRUNCATED 0x0200U
|
||||
#define NETB_HFLAG_RECURS_DESIRED 0x0100U
|
||||
#define NETB_HFLAG_RECURS_AVAILABLE 0x0080U
|
||||
#define NETB_HFLAG_BROADCAST 0x0010U
|
||||
#define NETB_HFLAG_REPLYCODE 0x0008U
|
||||
#define NETB_HFLAG_REPLYCODE_NOERROR 0x0000U
|
||||
#define NETB_HFLAG_RESPONSE 0x8000U
|
||||
#define NETB_HFLAG_OPCODE 0x7800U
|
||||
#define NETB_HFLAG_OPCODE_NAME_QUERY 0x0000U
|
||||
#define NETB_HFLAG_AUTHORATIVE 0x0400U
|
||||
#define NETB_HFLAG_TRUNCATED 0x0200U
|
||||
#define NETB_HFLAG_RECURS_DESIRED 0x0100U
|
||||
#define NETB_HFLAG_RECURS_AVAILABLE 0x0080U
|
||||
#define NETB_HFLAG_BROADCAST 0x0010U
|
||||
#define NETB_HFLAG_REPLYCODE 0x0008U
|
||||
#define NETB_HFLAG_REPLYCODE_NOERROR 0x0000U
|
||||
|
||||
/* NetBIOS question types */
|
||||
#define NETB_QTYPE_NB 0x0020U
|
||||
#define NETB_QTYPE_NBSTAT 0x0021U
|
||||
#define NETB_QTYPE_NB 0x0020U
|
||||
#define NETB_QTYPE_NBSTAT 0x0021U
|
||||
|
||||
/** NetBIOS name flags */
|
||||
#define NETB_NFLAG_UNIQUE 0x8000U
|
||||
#define NETB_NFLAG_NODETYPE 0x6000U
|
||||
#define NETB_NFLAG_NODETYPE_HNODE 0x6000U
|
||||
#define NETB_NFLAG_NODETYPE_MNODE 0x4000U
|
||||
#define NETB_NFLAG_NODETYPE_PNODE 0x2000U
|
||||
#define NETB_NFLAG_NODETYPE_BNODE 0x0000U
|
||||
#define NETB_NFLAG_UNIQUE 0x8000U
|
||||
#define NETB_NFLAG_NODETYPE 0x6000U
|
||||
#define NETB_NFLAG_NODETYPE_HNODE 0x6000U
|
||||
#define NETB_NFLAG_NODETYPE_MNODE 0x4000U
|
||||
#define NETB_NFLAG_NODETYPE_PNODE 0x2000U
|
||||
#define NETB_NFLAG_NODETYPE_BNODE 0x0000U
|
||||
|
||||
#define NETB_NFLAG_NAME_IN_CONFLICT 0x0800U /* 1=Yes, 0=No */
|
||||
#define NETB_NFLAG_NAME_IS_ACTIVE 0x0400U /* 1=Yes, 0=No */
|
||||
#define NETB_NFLAG_NAME_IS_PERMANENT 0x0200U /* 1=Yes (Name is Permanent Node Name), 0=No */
|
||||
#define NETB_NFLAG_NAME_IN_CONFLICT 0x0800U /* 1=Yes, 0=No */
|
||||
#define NETB_NFLAG_NAME_IS_ACTIVE 0x0400U /* 1=Yes, 0=No */
|
||||
#define NETB_NFLAG_NAME_IS_PERMANENT 0x0200U /* 1=Yes (Name is Permanent Node Name), 0=No */
|
||||
|
||||
/** NetBIOS message header */
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
#include "arch/bpstruct.h"
|
||||
# include "arch/bpstruct.h"
|
||||
#endif
|
||||
PACK_STRUCT_BEGIN
|
||||
struct netbios_hdr {
|
||||
PACK_STRUCT_FIELD(u16_t trans_id);
|
||||
PACK_STRUCT_FIELD(u16_t flags);
|
||||
PACK_STRUCT_FIELD(u16_t questions);
|
||||
PACK_STRUCT_FIELD(u16_t answerRRs);
|
||||
PACK_STRUCT_FIELD(u16_t authorityRRs);
|
||||
PACK_STRUCT_FIELD(u16_t additionalRRs);
|
||||
PACK_STRUCT_FIELD(u16_t trans_id);
|
||||
PACK_STRUCT_FIELD(u16_t flags);
|
||||
PACK_STRUCT_FIELD(u16_t questions);
|
||||
PACK_STRUCT_FIELD(u16_t answerRRs);
|
||||
PACK_STRUCT_FIELD(u16_t authorityRRs);
|
||||
PACK_STRUCT_FIELD(u16_t additionalRRs);
|
||||
} PACK_STRUCT_STRUCT;
|
||||
PACK_STRUCT_END
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
#include "arch/epstruct.h"
|
||||
# include "arch/epstruct.h"
|
||||
#endif
|
||||
|
||||
/** NetBIOS message question part */
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
#include "arch/bpstruct.h"
|
||||
# include "arch/bpstruct.h"
|
||||
#endif
|
||||
PACK_STRUCT_BEGIN
|
||||
struct netbios_question_hdr {
|
||||
PACK_STRUCT_FLD_8(u8_t nametype);
|
||||
PACK_STRUCT_FLD_8(u8_t encname[(NETBIOS_NAME_LEN * 2) + 1]);
|
||||
PACK_STRUCT_FIELD(u16_t type);
|
||||
PACK_STRUCT_FIELD(u16_t cls);
|
||||
PACK_STRUCT_FLD_8(u8_t nametype);
|
||||
PACK_STRUCT_FLD_8(u8_t encname[(NETBIOS_NAME_LEN * 2) + 1]);
|
||||
PACK_STRUCT_FIELD(u16_t type);
|
||||
PACK_STRUCT_FIELD(u16_t cls);
|
||||
} PACK_STRUCT_STRUCT;
|
||||
PACK_STRUCT_END
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
#include "arch/epstruct.h"
|
||||
# include "arch/epstruct.h"
|
||||
#endif
|
||||
|
||||
/** NetBIOS message name part */
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
#include "arch/bpstruct.h"
|
||||
# include "arch/bpstruct.h"
|
||||
#endif
|
||||
PACK_STRUCT_BEGIN
|
||||
struct netbios_name_hdr {
|
||||
PACK_STRUCT_FLD_8(u8_t nametype);
|
||||
PACK_STRUCT_FLD_8(u8_t encname[(NETBIOS_NAME_LEN * 2) + 1]);
|
||||
PACK_STRUCT_FIELD(u16_t type);
|
||||
PACK_STRUCT_FIELD(u16_t cls);
|
||||
PACK_STRUCT_FIELD(u32_t ttl);
|
||||
PACK_STRUCT_FIELD(u16_t datalen);
|
||||
PACK_STRUCT_FIELD(u16_t flags);
|
||||
PACK_STRUCT_FLD_S(ip4_addr_p_t addr);
|
||||
PACK_STRUCT_FLD_8(u8_t nametype);
|
||||
PACK_STRUCT_FLD_8(u8_t encname[(NETBIOS_NAME_LEN * 2) + 1]);
|
||||
PACK_STRUCT_FIELD(u16_t type);
|
||||
PACK_STRUCT_FIELD(u16_t cls);
|
||||
PACK_STRUCT_FIELD(u32_t ttl);
|
||||
PACK_STRUCT_FIELD(u16_t datalen);
|
||||
PACK_STRUCT_FIELD(u16_t flags);
|
||||
PACK_STRUCT_FLD_S(ip4_addr_p_t addr);
|
||||
} PACK_STRUCT_STRUCT;
|
||||
PACK_STRUCT_END
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
#include "arch/epstruct.h"
|
||||
# include "arch/epstruct.h"
|
||||
#endif
|
||||
|
||||
/** NetBIOS message */
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
#include "arch/bpstruct.h"
|
||||
# include "arch/bpstruct.h"
|
||||
#endif
|
||||
PACK_STRUCT_BEGIN
|
||||
struct netbios_resp {
|
||||
struct netbios_hdr resp_hdr;
|
||||
struct netbios_name_hdr resp_name;
|
||||
struct netbios_hdr resp_hdr;
|
||||
struct netbios_name_hdr resp_name;
|
||||
} PACK_STRUCT_STRUCT;
|
||||
PACK_STRUCT_END
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
#include "arch/epstruct.h"
|
||||
# include "arch/epstruct.h"
|
||||
#endif
|
||||
|
||||
/** The NBNS Structure Responds to a Name Query */
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
#include "arch/bpstruct.h"
|
||||
# include "arch/bpstruct.h"
|
||||
#endif
|
||||
PACK_STRUCT_BEGIN
|
||||
struct netbios_answer {
|
||||
struct netbios_hdr answer_hdr;
|
||||
/** the length of the next string */
|
||||
PACK_STRUCT_FIELD(u8_t name_size);
|
||||
/** WARNING!!! this item may be of a different length (we use this struct for transmission) */
|
||||
PACK_STRUCT_FLD_8(u8_t query_name[(NETBIOS_NAME_LEN * 2) + 1]);
|
||||
PACK_STRUCT_FIELD(u16_t packet_type);
|
||||
PACK_STRUCT_FIELD(u16_t cls);
|
||||
PACK_STRUCT_FIELD(u32_t ttl);
|
||||
PACK_STRUCT_FIELD(u16_t data_length);
|
||||
struct netbios_hdr answer_hdr;
|
||||
/** the length of the next string */
|
||||
PACK_STRUCT_FIELD(u8_t name_size);
|
||||
/** WARNING!!! this item may be of a different length (we use this struct for transmission) */
|
||||
PACK_STRUCT_FLD_8(u8_t query_name[(NETBIOS_NAME_LEN * 2) + 1]);
|
||||
PACK_STRUCT_FIELD(u16_t packet_type);
|
||||
PACK_STRUCT_FIELD(u16_t cls);
|
||||
PACK_STRUCT_FIELD(u32_t ttl);
|
||||
PACK_STRUCT_FIELD(u16_t data_length);
|
||||
#define OFFSETOF_STRUCT_NETBIOS_ANSWER_NUMBER_OF_NAMES 56
|
||||
/** number of names */
|
||||
PACK_STRUCT_FLD_8(u8_t number_of_names);
|
||||
/** node name */
|
||||
PACK_STRUCT_FLD_8(u8_t answer_name[NETBIOS_NAME_LEN]);
|
||||
/** node flags */
|
||||
PACK_STRUCT_FIELD(u16_t answer_name_flags);
|
||||
/** Unit ID */
|
||||
PACK_STRUCT_FLD_8(u8_t unit_id[6]);
|
||||
/** Jumpers */
|
||||
PACK_STRUCT_FLD_8(u8_t jumpers);
|
||||
/** Test result */
|
||||
PACK_STRUCT_FLD_8(u8_t test_result);
|
||||
/** Version number */
|
||||
PACK_STRUCT_FIELD(u16_t version_number);
|
||||
/** Period of statistics */
|
||||
PACK_STRUCT_FIELD(u16_t period_of_statistics);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t number_of_crcs);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t number_of_alignment_errors);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t number_of_collisions);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t number_of_send_aborts);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u32_t number_of_good_sends);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u32_t number_of_good_receives);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t number_of_retransmits);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t number_of_no_resource_condition);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t number_of_free_command_blocks);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t total_number_of_command_blocks);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t max_total_number_of_command_blocks);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t number_of_pending_sessions);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t max_number_of_pending_sessions);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t max_total_sessions_possible);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t session_data_packet_size);
|
||||
/** number of names */
|
||||
PACK_STRUCT_FLD_8(u8_t number_of_names);
|
||||
/** node name */
|
||||
PACK_STRUCT_FLD_8(u8_t answer_name[NETBIOS_NAME_LEN]);
|
||||
/** node flags */
|
||||
PACK_STRUCT_FIELD(u16_t answer_name_flags);
|
||||
/** Unit ID */
|
||||
PACK_STRUCT_FLD_8(u8_t unit_id[6]);
|
||||
/** Jumpers */
|
||||
PACK_STRUCT_FLD_8(u8_t jumpers);
|
||||
/** Test result */
|
||||
PACK_STRUCT_FLD_8(u8_t test_result);
|
||||
/** Version number */
|
||||
PACK_STRUCT_FIELD(u16_t version_number);
|
||||
/** Period of statistics */
|
||||
PACK_STRUCT_FIELD(u16_t period_of_statistics);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t number_of_crcs);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t number_of_alignment_errors);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t number_of_collisions);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t number_of_send_aborts);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u32_t number_of_good_sends);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u32_t number_of_good_receives);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t number_of_retransmits);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t number_of_no_resource_condition);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t number_of_free_command_blocks);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t total_number_of_command_blocks);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t max_total_number_of_command_blocks);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t number_of_pending_sessions);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t max_number_of_pending_sessions);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t max_total_sessions_possible);
|
||||
/** Statistics */
|
||||
PACK_STRUCT_FIELD(u16_t session_data_packet_size);
|
||||
} PACK_STRUCT_STRUCT;
|
||||
PACK_STRUCT_END
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
#include "arch/epstruct.h"
|
||||
# include "arch/epstruct.h"
|
||||
#endif
|
||||
|
||||
#ifdef NETBIOS_LWIP_NAME
|
||||
@ -239,276 +239,256 @@ static char netbiosns_local_name[NETBIOS_NAME_LEN];
|
||||
static struct udp_pcb *netbiosns_pcb;
|
||||
|
||||
/** Decode a NetBIOS name (from packet to string) */
|
||||
static int netbiosns_name_decode(char *name_enc, char *name_dec, int name_dec_len)
|
||||
static int
|
||||
netbiosns_name_decode(char *name_enc, char *name_dec, int name_dec_len)
|
||||
{
|
||||
char *pname;
|
||||
char cname;
|
||||
char cnbname;
|
||||
int idx = 0;
|
||||
char *pname;
|
||||
char cname;
|
||||
char cnbname;
|
||||
int idx = 0;
|
||||
|
||||
LWIP_UNUSED_ARG(name_dec_len);
|
||||
LWIP_UNUSED_ARG(name_dec_len);
|
||||
|
||||
/* Start decoding netbios name. */
|
||||
pname = name_enc;
|
||||
|
||||
for (;;) {
|
||||
/* Every two characters of the first level-encoded name
|
||||
* turn into one character in the decoded name. */
|
||||
cname = *pname;
|
||||
|
||||
if (cname == '\0') {
|
||||
break; /* no more characters */
|
||||
}
|
||||
|
||||
if (cname == '.') {
|
||||
break; /* scope ID follows */
|
||||
}
|
||||
|
||||
if (!lwip_isupper(cname)) {
|
||||
/* Not legal. */
|
||||
return -1;
|
||||
}
|
||||
|
||||
cname -= 'A';
|
||||
cnbname = cname << 4;
|
||||
pname++;
|
||||
|
||||
cname = *pname;
|
||||
|
||||
if (!lwip_isupper(cname)) {
|
||||
/* Not legal. */
|
||||
return -1;
|
||||
}
|
||||
|
||||
cname -= 'A';
|
||||
cnbname |= cname;
|
||||
pname++;
|
||||
|
||||
/* Do we have room to store the character? */
|
||||
if (idx < NETBIOS_NAME_LEN) {
|
||||
/* Yes - store the character. */
|
||||
name_dec[idx++] = (cnbname != ' ' ? cnbname : '\0');
|
||||
}
|
||||
/* Start decoding netbios name. */
|
||||
pname = name_enc;
|
||||
for (;;) {
|
||||
/* Every two characters of the first level-encoded name
|
||||
* turn into one character in the decoded name. */
|
||||
cname = *pname;
|
||||
if (cname == '\0') {
|
||||
break; /* no more characters */
|
||||
}
|
||||
if (cname == '.') {
|
||||
break; /* scope ID follows */
|
||||
}
|
||||
if (!lwip_isupper(cname)) {
|
||||
/* Not legal. */
|
||||
return -1;
|
||||
}
|
||||
cname -= 'A';
|
||||
cnbname = cname << 4;
|
||||
pname++;
|
||||
|
||||
return 0;
|
||||
cname = *pname;
|
||||
if (!lwip_isupper(cname)) {
|
||||
/* Not legal. */
|
||||
return -1;
|
||||
}
|
||||
cname -= 'A';
|
||||
cnbname |= cname;
|
||||
pname++;
|
||||
|
||||
/* Do we have room to store the character? */
|
||||
if (idx < NETBIOS_NAME_LEN) {
|
||||
/* Yes - store the character. */
|
||||
name_dec[idx++] = (cnbname != ' ' ? cnbname : '\0');
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0 /* function currently unused */
|
||||
/** Encode a NetBIOS name (from string to packet) - currently unused because
|
||||
we don't ask for names. */
|
||||
static int netbiosns_name_encode(char *name_enc, char *name_dec, int name_dec_len)
|
||||
static int
|
||||
netbiosns_name_encode(char *name_enc, char *name_dec, int name_dec_len)
|
||||
{
|
||||
char *pname;
|
||||
char cname;
|
||||
unsigned char ucname;
|
||||
int idx = 0;
|
||||
char *pname;
|
||||
char cname;
|
||||
unsigned char ucname;
|
||||
int idx = 0;
|
||||
|
||||
/* Start encoding netbios name. */
|
||||
pname = name_enc;
|
||||
/* Start encoding netbios name. */
|
||||
pname = name_enc;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
/* Every two characters of the first level-encoded name
|
||||
* turn into one character in the decoded name. */
|
||||
cname = *pname;
|
||||
|
||||
if(cname == '\0')
|
||||
{
|
||||
break; /* no more characters */
|
||||
}
|
||||
|
||||
if(cname == '.')
|
||||
{
|
||||
break; /* scope ID follows */
|
||||
}
|
||||
|
||||
if((cname < 'A' || cname > 'Z') && (cname < '0' || cname > '9'))
|
||||
{
|
||||
/* Not legal. */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Do we have room to store the character? */
|
||||
if(idx >= name_dec_len)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Yes - store the character. */
|
||||
ucname = cname;
|
||||
name_dec[idx++] = ('A' + ((ucname >> 4) & 0x0F));
|
||||
name_dec[idx++] = ('A' + (ucname & 0x0F));
|
||||
pname++;
|
||||
for (;;) {
|
||||
/* Every two characters of the first level-encoded name
|
||||
* turn into one character in the decoded name. */
|
||||
cname = *pname;
|
||||
if (cname == '\0') {
|
||||
break; /* no more characters */
|
||||
}
|
||||
if (cname == '.') {
|
||||
break; /* scope ID follows */
|
||||
}
|
||||
if ((cname < 'A' || cname > 'Z') && (cname < '0' || cname > '9')) {
|
||||
/* Not legal. */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Fill with "space" coding */
|
||||
for(; idx < name_dec_len - 1;)
|
||||
{
|
||||
name_dec[idx++] = 'C';
|
||||
name_dec[idx++] = 'A';
|
||||
/* Do we have room to store the character? */
|
||||
if (idx >= name_dec_len) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Terminate string */
|
||||
name_dec[idx] = '\0';
|
||||
/* Yes - store the character. */
|
||||
ucname = cname;
|
||||
name_dec[idx++] = ('A' + ((ucname >> 4) & 0x0F));
|
||||
name_dec[idx++] = ('A' + ( ucname & 0x0F));
|
||||
pname++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
/* Fill with "space" coding */
|
||||
for (; idx < name_dec_len - 1;) {
|
||||
name_dec[idx++] = 'C';
|
||||
name_dec[idx++] = 'A';
|
||||
}
|
||||
|
||||
/* Terminate string */
|
||||
name_dec[idx] = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* 0 */
|
||||
|
||||
/** NetBIOS Name service recv callback */
|
||||
static void netbiosns_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
|
||||
static void
|
||||
netbiosns_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
|
||||
{
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
|
||||
/* if packet is valid */
|
||||
if (p != NULL) {
|
||||
char netbios_name[NETBIOS_NAME_LEN + 1];
|
||||
struct netbios_hdr *netbios_hdr = (struct netbios_hdr *)p->payload;
|
||||
struct netbios_question_hdr *netbios_question_hdr = (struct netbios_question_hdr *)(netbios_hdr + 1);
|
||||
/* if packet is valid */
|
||||
if (p != NULL) {
|
||||
char netbios_name[NETBIOS_NAME_LEN + 1];
|
||||
struct netbios_hdr *netbios_hdr = (struct netbios_hdr *)p->payload;
|
||||
struct netbios_question_hdr *netbios_question_hdr = (struct netbios_question_hdr *)(netbios_hdr + 1);
|
||||
|
||||
/* is the packet long enough (we need the header in one piece) */
|
||||
if (p->len < (sizeof(struct netbios_hdr) + sizeof(struct netbios_question_hdr))) {
|
||||
/* packet too short */
|
||||
pbuf_free(p);
|
||||
return;
|
||||
}
|
||||
|
||||
/* we only answer if we got a default interface */
|
||||
if (netif_default != NULL) {
|
||||
/* @todo: do we need to check answerRRs/authorityRRs/additionalRRs? */
|
||||
/* if the packet is a NetBIOS name query question */
|
||||
if (((netbios_hdr->flags & PP_NTOHS(NETB_HFLAG_OPCODE)) == PP_NTOHS(NETB_HFLAG_OPCODE_NAME_QUERY)) &&
|
||||
((netbios_hdr->flags & PP_NTOHS(NETB_HFLAG_RESPONSE)) == 0) &&
|
||||
(netbios_hdr->questions == PP_NTOHS(1))) {
|
||||
/* decode the NetBIOS name */
|
||||
netbiosns_name_decode((char *)(netbios_question_hdr->encname), netbios_name, sizeof(netbios_name));
|
||||
|
||||
/* check the request type */
|
||||
if (netbios_question_hdr->type == PP_HTONS(NETB_QTYPE_NB)) {
|
||||
/* if the packet is for us */
|
||||
if (lwip_strnicmp(netbios_name, NETBIOS_LOCAL_NAME, sizeof(NETBIOS_LOCAL_NAME)) == 0) {
|
||||
struct pbuf *q;
|
||||
struct netbios_resp *resp;
|
||||
|
||||
q = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct netbios_resp), PBUF_RAM);
|
||||
|
||||
if (q != NULL) {
|
||||
resp = (struct netbios_resp *)q->payload;
|
||||
|
||||
/* prepare NetBIOS header response */
|
||||
resp->resp_hdr.trans_id = netbios_hdr->trans_id;
|
||||
resp->resp_hdr.flags = PP_HTONS(NETB_HFLAG_RESPONSE |
|
||||
NETB_HFLAG_OPCODE_NAME_QUERY |
|
||||
NETB_HFLAG_AUTHORATIVE |
|
||||
NETB_HFLAG_RECURS_DESIRED);
|
||||
resp->resp_hdr.questions = 0;
|
||||
resp->resp_hdr.answerRRs = PP_HTONS(1);
|
||||
resp->resp_hdr.authorityRRs = 0;
|
||||
resp->resp_hdr.additionalRRs = 0;
|
||||
|
||||
/* prepare NetBIOS header datas */
|
||||
MEMCPY(resp->resp_name.encname, netbios_question_hdr->encname, sizeof(netbios_question_hdr->encname));
|
||||
resp->resp_name.nametype = netbios_question_hdr->nametype;
|
||||
resp->resp_name.type = netbios_question_hdr->type;
|
||||
resp->resp_name.cls = netbios_question_hdr->cls;
|
||||
resp->resp_name.ttl = PP_HTONL(NETBIOS_NAME_TTL);
|
||||
resp->resp_name.datalen = PP_HTONS(sizeof(resp->resp_name.flags) + sizeof(resp->resp_name.addr));
|
||||
resp->resp_name.flags = PP_HTONS(NETB_NFLAG_NODETYPE_BNODE);
|
||||
ip4_addr_copy(resp->resp_name.addr, *netif_ip4_addr(netif_default));
|
||||
|
||||
/* send the NetBIOS response */
|
||||
udp_sendto(upcb, q, addr, port);
|
||||
|
||||
/* free the "reference" pbuf */
|
||||
pbuf_free(q);
|
||||
}
|
||||
}
|
||||
|
||||
#if LWIP_NETBIOS_RESPOND_NAME_QUERY
|
||||
} else if (netbios_question_hdr->type == PP_HTONS(NETB_QTYPE_NBSTAT)) {
|
||||
/* if the packet is for us or general query */
|
||||
if (!lwip_strnicmp(netbios_name, NETBIOS_LOCAL_NAME, sizeof(NETBIOS_LOCAL_NAME)) ||
|
||||
!lwip_strnicmp(netbios_name, "*", sizeof(NETBIOS_LOCAL_NAME))) {
|
||||
/* general query - ask for our IP address */
|
||||
struct pbuf *q;
|
||||
struct netbios_answer *resp;
|
||||
|
||||
q = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct netbios_answer), PBUF_RAM);
|
||||
|
||||
if (q != NULL) {
|
||||
/* buffer to which a response is compiled */
|
||||
resp = (struct netbios_answer *)q->payload;
|
||||
|
||||
/* Init response to zero, especially the statistics fields */
|
||||
memset(resp, 0, sizeof(*resp));
|
||||
|
||||
/* copy the query to the response ID */
|
||||
resp->answer_hdr.trans_id = netbios_hdr->trans_id;
|
||||
/* acknowledgment of termination */
|
||||
resp->answer_hdr.flags = PP_HTONS(NETB_HFLAG_RESPONSE | NETB_HFLAG_OPCODE_NAME_QUERY | NETB_HFLAG_AUTHORATIVE);
|
||||
/* resp->answer_hdr.questions = PP_HTONS(0); done by memset() */
|
||||
/* serial number of the answer */
|
||||
resp->answer_hdr.answerRRs = PP_HTONS(1);
|
||||
/* resp->answer_hdr.authorityRRs = PP_HTONS(0); done by memset() */
|
||||
/* resp->answer_hdr.additionalRRs = PP_HTONS(0); done by memset() */
|
||||
/* we will copy the length of the station name */
|
||||
resp->name_size = netbios_question_hdr->nametype;
|
||||
/* we will copy the queried name */
|
||||
MEMCPY(resp->query_name, netbios_question_hdr->encname, (NETBIOS_NAME_LEN * 2) + 1);
|
||||
/* NBSTAT */
|
||||
resp->packet_type = PP_HTONS(0x21);
|
||||
/* Internet name */
|
||||
resp->cls = PP_HTONS(1);
|
||||
/* resp->ttl = PP_HTONL(0); done by memset() */
|
||||
resp->data_length = PP_HTONS(sizeof(struct netbios_answer) - offsetof(struct netbios_answer, number_of_names));
|
||||
resp->number_of_names = 1;
|
||||
|
||||
/* make windows see us as workstation, not as a server */
|
||||
memset(resp->answer_name, 0x20, NETBIOS_NAME_LEN - 1);
|
||||
/* strlen is checked to be < NETBIOS_NAME_LEN during initialization */
|
||||
MEMCPY(resp->answer_name, NETBIOS_LOCAL_NAME, strlen(NETBIOS_LOCAL_NAME));
|
||||
|
||||
/* b-node, unique, active */
|
||||
resp->answer_name_flags = PP_HTONS(NETB_NFLAG_NAME_IS_ACTIVE);
|
||||
|
||||
/* Set responder netif MAC address */
|
||||
SMEMCPY(resp->unit_id, ip_current_input_netif()->hwaddr, sizeof(resp->unit_id));
|
||||
|
||||
udp_sendto(upcb, q, addr, port);
|
||||
pbuf_free(q);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* LWIP_NETBIOS_RESPOND_NAME_QUERY */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* free the pbuf */
|
||||
pbuf_free(p);
|
||||
/* is the packet long enough (we need the header in one piece) */
|
||||
if (p->len < (sizeof(struct netbios_hdr) + sizeof(struct netbios_question_hdr))) {
|
||||
/* packet too short */
|
||||
pbuf_free(p);
|
||||
return;
|
||||
}
|
||||
/* we only answer if we got a default interface */
|
||||
if (netif_default != NULL) {
|
||||
/* @todo: do we need to check answerRRs/authorityRRs/additionalRRs? */
|
||||
/* if the packet is a NetBIOS name query question */
|
||||
if (((netbios_hdr->flags & PP_NTOHS(NETB_HFLAG_OPCODE)) == PP_NTOHS(NETB_HFLAG_OPCODE_NAME_QUERY)) &&
|
||||
((netbios_hdr->flags & PP_NTOHS(NETB_HFLAG_RESPONSE)) == 0) &&
|
||||
(netbios_hdr->questions == PP_NTOHS(1))) {
|
||||
/* decode the NetBIOS name */
|
||||
netbiosns_name_decode((char *)(netbios_question_hdr->encname), netbios_name, sizeof(netbios_name));
|
||||
/* check the request type */
|
||||
if (netbios_question_hdr->type == PP_HTONS(NETB_QTYPE_NB)) {
|
||||
/* if the packet is for us */
|
||||
if (lwip_strnicmp(netbios_name, NETBIOS_LOCAL_NAME, sizeof(NETBIOS_LOCAL_NAME)) == 0) {
|
||||
struct pbuf *q;
|
||||
struct netbios_resp *resp;
|
||||
|
||||
q = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct netbios_resp), PBUF_RAM);
|
||||
if (q != NULL) {
|
||||
resp = (struct netbios_resp *)q->payload;
|
||||
|
||||
/* prepare NetBIOS header response */
|
||||
resp->resp_hdr.trans_id = netbios_hdr->trans_id;
|
||||
resp->resp_hdr.flags = PP_HTONS(NETB_HFLAG_RESPONSE |
|
||||
NETB_HFLAG_OPCODE_NAME_QUERY |
|
||||
NETB_HFLAG_AUTHORATIVE |
|
||||
NETB_HFLAG_RECURS_DESIRED);
|
||||
resp->resp_hdr.questions = 0;
|
||||
resp->resp_hdr.answerRRs = PP_HTONS(1);
|
||||
resp->resp_hdr.authorityRRs = 0;
|
||||
resp->resp_hdr.additionalRRs = 0;
|
||||
|
||||
/* prepare NetBIOS header datas */
|
||||
MEMCPY( resp->resp_name.encname, netbios_question_hdr->encname, sizeof(netbios_question_hdr->encname));
|
||||
resp->resp_name.nametype = netbios_question_hdr->nametype;
|
||||
resp->resp_name.type = netbios_question_hdr->type;
|
||||
resp->resp_name.cls = netbios_question_hdr->cls;
|
||||
resp->resp_name.ttl = PP_HTONL(NETBIOS_NAME_TTL);
|
||||
resp->resp_name.datalen = PP_HTONS(sizeof(resp->resp_name.flags) + sizeof(resp->resp_name.addr));
|
||||
resp->resp_name.flags = PP_HTONS(NETB_NFLAG_NODETYPE_BNODE);
|
||||
ip4_addr_copy(resp->resp_name.addr, *netif_ip4_addr(netif_default));
|
||||
|
||||
/* send the NetBIOS response */
|
||||
udp_sendto(upcb, q, addr, port);
|
||||
|
||||
/* free the "reference" pbuf */
|
||||
pbuf_free(q);
|
||||
}
|
||||
}
|
||||
#if LWIP_NETBIOS_RESPOND_NAME_QUERY
|
||||
} else if (netbios_question_hdr->type == PP_HTONS(NETB_QTYPE_NBSTAT)) {
|
||||
/* if the packet is for us or general query */
|
||||
if (!lwip_strnicmp(netbios_name, NETBIOS_LOCAL_NAME, sizeof(NETBIOS_LOCAL_NAME)) ||
|
||||
!lwip_strnicmp(netbios_name, "*", sizeof(NETBIOS_LOCAL_NAME))) {
|
||||
/* general query - ask for our IP address */
|
||||
struct pbuf *q;
|
||||
struct netbios_answer *resp;
|
||||
|
||||
q = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct netbios_answer), PBUF_RAM);
|
||||
if (q != NULL) {
|
||||
/* buffer to which a response is compiled */
|
||||
resp = (struct netbios_answer *) q->payload;
|
||||
|
||||
/* Init response to zero, especially the statistics fields */
|
||||
memset(resp, 0, sizeof(*resp));
|
||||
|
||||
/* copy the query to the response ID */
|
||||
resp->answer_hdr.trans_id = netbios_hdr->trans_id;
|
||||
/* acknowledgment of termination */
|
||||
resp->answer_hdr.flags = PP_HTONS(NETB_HFLAG_RESPONSE | NETB_HFLAG_OPCODE_NAME_QUERY | NETB_HFLAG_AUTHORATIVE);
|
||||
/* resp->answer_hdr.questions = PP_HTONS(0); done by memset() */
|
||||
/* serial number of the answer */
|
||||
resp->answer_hdr.answerRRs = PP_HTONS(1);
|
||||
/* resp->answer_hdr.authorityRRs = PP_HTONS(0); done by memset() */
|
||||
/* resp->answer_hdr.additionalRRs = PP_HTONS(0); done by memset() */
|
||||
/* we will copy the length of the station name */
|
||||
resp->name_size = netbios_question_hdr->nametype;
|
||||
/* we will copy the queried name */
|
||||
MEMCPY(resp->query_name, netbios_question_hdr->encname, (NETBIOS_NAME_LEN * 2) + 1);
|
||||
/* NBSTAT */
|
||||
resp->packet_type = PP_HTONS(0x21);
|
||||
/* Internet name */
|
||||
resp->cls = PP_HTONS(1);
|
||||
/* resp->ttl = PP_HTONL(0); done by memset() */
|
||||
resp->data_length = PP_HTONS(sizeof(struct netbios_answer) - offsetof(struct netbios_answer, number_of_names));
|
||||
resp->number_of_names = 1;
|
||||
|
||||
/* make windows see us as workstation, not as a server */
|
||||
memset(resp->answer_name, 0x20, NETBIOS_NAME_LEN - 1);
|
||||
/* strlen is checked to be < NETBIOS_NAME_LEN during initialization */
|
||||
MEMCPY(resp->answer_name, NETBIOS_LOCAL_NAME, strlen(NETBIOS_LOCAL_NAME));
|
||||
|
||||
/* b-node, unique, active */
|
||||
resp->answer_name_flags = PP_HTONS(NETB_NFLAG_NAME_IS_ACTIVE);
|
||||
|
||||
/* Set responder netif MAC address */
|
||||
SMEMCPY(resp->unit_id, ip_current_input_netif()->hwaddr, sizeof(resp->unit_id));
|
||||
|
||||
udp_sendto(upcb, q, addr, port);
|
||||
pbuf_free(q);
|
||||
}
|
||||
}
|
||||
#endif /* LWIP_NETBIOS_RESPOND_NAME_QUERY */
|
||||
}
|
||||
}
|
||||
}
|
||||
/* free the pbuf */
|
||||
pbuf_free(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup netbiosns
|
||||
* Init netbios responder
|
||||
*/
|
||||
void netbiosns_init(void)
|
||||
void
|
||||
netbiosns_init(void)
|
||||
{
|
||||
/* LWIP_ASSERT_CORE_LOCKED(); is checked by udp_new() */
|
||||
/* LWIP_ASSERT_CORE_LOCKED(); is checked by udp_new() */
|
||||
#ifdef NETBIOS_LWIP_NAME
|
||||
LWIP_ASSERT("NetBIOS name is too long!", strlen(NETBIOS_LWIP_NAME) < NETBIOS_NAME_LEN);
|
||||
LWIP_ASSERT("NetBIOS name is too long!", strlen(NETBIOS_LWIP_NAME) < NETBIOS_NAME_LEN);
|
||||
#endif
|
||||
|
||||
netbiosns_pcb = udp_new_ip_type(IPADDR_TYPE_ANY);
|
||||
|
||||
if (netbiosns_pcb != NULL) {
|
||||
/* we have to be allowed to send broadcast packets! */
|
||||
ip_set_option(netbiosns_pcb, SOF_BROADCAST);
|
||||
udp_bind(netbiosns_pcb, IP_ANY_TYPE, LWIP_IANA_PORT_NETBIOS);
|
||||
udp_recv(netbiosns_pcb, netbiosns_recv, netbiosns_pcb);
|
||||
}
|
||||
netbiosns_pcb = udp_new_ip_type(IPADDR_TYPE_ANY);
|
||||
if (netbiosns_pcb != NULL) {
|
||||
/* we have to be allowed to send broadcast packets! */
|
||||
ip_set_option(netbiosns_pcb, SOF_BROADCAST);
|
||||
udp_bind(netbiosns_pcb, IP_ANY_TYPE, LWIP_IANA_PORT_NETBIOS);
|
||||
udp_recv(netbiosns_pcb, netbiosns_recv, netbiosns_pcb);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NETBIOS_LWIP_NAME
|
||||
@ -517,23 +497,22 @@ void netbiosns_init(void)
|
||||
* Set netbios name. ATTENTION: the hostname must be less than 15 characters!
|
||||
* the NetBIOS name spec says the name MUST be upper case, so incoming name is forced into uppercase :-)
|
||||
*/
|
||||
void netbiosns_set_name(const char *hostname)
|
||||
void
|
||||
netbiosns_set_name(const char *hostname)
|
||||
{
|
||||
size_t i;
|
||||
size_t copy_len = strlen(hostname);
|
||||
LWIP_ASSERT_CORE_LOCKED();
|
||||
LWIP_ASSERT("NetBIOS name is too long!", copy_len < NETBIOS_NAME_LEN);
|
||||
size_t i;
|
||||
size_t copy_len = strlen(hostname);
|
||||
LWIP_ASSERT_CORE_LOCKED();
|
||||
LWIP_ASSERT("NetBIOS name is too long!", copy_len < NETBIOS_NAME_LEN);
|
||||
if (copy_len >= NETBIOS_NAME_LEN) {
|
||||
copy_len = NETBIOS_NAME_LEN - 1;
|
||||
}
|
||||
|
||||
if (copy_len >= NETBIOS_NAME_LEN) {
|
||||
copy_len = NETBIOS_NAME_LEN - 1;
|
||||
}
|
||||
|
||||
/* make name into upper case */
|
||||
for (i = 0; i < copy_len; i++) {
|
||||
netbiosns_local_name[i] = (char)lwip_toupper(hostname[i]);
|
||||
}
|
||||
|
||||
netbiosns_local_name[copy_len] = '\0';
|
||||
/* make name into upper case */
|
||||
for (i = 0; i < copy_len; i++ ) {
|
||||
netbiosns_local_name[i] = (char)lwip_toupper(hostname[i]);
|
||||
}
|
||||
netbiosns_local_name[copy_len] = '\0';
|
||||
}
|
||||
#endif /* NETBIOS_LWIP_NAME */
|
||||
|
||||
@ -541,14 +520,14 @@ void netbiosns_set_name(const char *hostname)
|
||||
* @ingroup netbiosns
|
||||
* Stop netbios responder
|
||||
*/
|
||||
void netbiosns_stop(void)
|
||||
void
|
||||
netbiosns_stop(void)
|
||||
{
|
||||
LWIP_ASSERT_CORE_LOCKED();
|
||||
|
||||
if (netbiosns_pcb != NULL) {
|
||||
udp_remove(netbiosns_pcb);
|
||||
netbiosns_pcb = NULL;
|
||||
}
|
||||
LWIP_ASSERT_CORE_LOCKED();
|
||||
if (netbiosns_pcb != NULL) {
|
||||
udp_remove(netbiosns_pcb);
|
||||
netbiosns_pcb = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* LWIP_IPV4 && LWIP_UDP */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -41,10 +41,10 @@
|
||||
|
||||
#include "snmp_asn1.h"
|
||||
|
||||
#define PBUF_OP_EXEC(code) \
|
||||
if ((code) != ERR_OK) { \
|
||||
return ERR_BUF; \
|
||||
}
|
||||
#define PBUF_OP_EXEC(code) \
|
||||
if ((code) != ERR_OK) { \
|
||||
return ERR_BUF; \
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes a TLV into a pbuf stream.
|
||||
@ -53,72 +53,72 @@
|
||||
* @param tlv TLV to encode
|
||||
* @return ERR_OK if successful, ERR_ARG if we can't (or won't) encode
|
||||
*/
|
||||
err_t snmp_ans1_enc_tlv(struct snmp_pbuf_stream *pbuf_stream, struct snmp_asn1_tlv *tlv)
|
||||
err_t
|
||||
snmp_ans1_enc_tlv(struct snmp_pbuf_stream *pbuf_stream, struct snmp_asn1_tlv *tlv)
|
||||
{
|
||||
u8_t data;
|
||||
u8_t length_bytes_required;
|
||||
u8_t data;
|
||||
u8_t length_bytes_required;
|
||||
|
||||
/* write type */
|
||||
if ((tlv->type & SNMP_ASN1_DATATYPE_MASK) == SNMP_ASN1_DATATYPE_EXTENDED) {
|
||||
/* extended format is not used by SNMP so we do not accept those values */
|
||||
return ERR_ARG;
|
||||
/* write type */
|
||||
if ((tlv->type & SNMP_ASN1_DATATYPE_MASK) == SNMP_ASN1_DATATYPE_EXTENDED) {
|
||||
/* extended format is not used by SNMP so we do not accept those values */
|
||||
return ERR_ARG;
|
||||
}
|
||||
if (tlv->type_len != 0) {
|
||||
/* any other value as auto is not accepted for type (we always use one byte because extended syntax is prohibited) */
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, tlv->type));
|
||||
tlv->type_len = 1;
|
||||
|
||||
/* write length */
|
||||
if (tlv->value_len <= 127) {
|
||||
length_bytes_required = 1;
|
||||
} else if (tlv->value_len <= 255) {
|
||||
length_bytes_required = 2;
|
||||
} else {
|
||||
length_bytes_required = 3;
|
||||
}
|
||||
|
||||
/* check for forced min length */
|
||||
if (tlv->length_len > 0) {
|
||||
if (tlv->length_len < length_bytes_required) {
|
||||
/* unable to code requested length in requested number of bytes */
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
if (tlv->type_len != 0) {
|
||||
/* any other value as auto is not accepted for type (we always use one byte because extended syntax is prohibited) */
|
||||
return ERR_ARG;
|
||||
}
|
||||
length_bytes_required = tlv->length_len;
|
||||
} else {
|
||||
tlv->length_len = length_bytes_required;
|
||||
}
|
||||
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, tlv->type));
|
||||
tlv->type_len = 1;
|
||||
if (length_bytes_required > 1) {
|
||||
/* multi byte representation required */
|
||||
length_bytes_required--;
|
||||
data = 0x80 | length_bytes_required; /* extended length definition, 1 length byte follows */
|
||||
|
||||
/* write length */
|
||||
if (tlv->value_len <= 127) {
|
||||
length_bytes_required = 1;
|
||||
} else if (tlv->value_len <= 255) {
|
||||
length_bytes_required = 2;
|
||||
} else {
|
||||
length_bytes_required = 3;
|
||||
}
|
||||
|
||||
/* check for forced min length */
|
||||
if (tlv->length_len > 0) {
|
||||
if (tlv->length_len < length_bytes_required) {
|
||||
/* unable to code requested length in requested number of bytes */
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
length_bytes_required = tlv->length_len;
|
||||
} else {
|
||||
tlv->length_len = length_bytes_required;
|
||||
}
|
||||
|
||||
if (length_bytes_required > 1) {
|
||||
/* multi byte representation required */
|
||||
length_bytes_required--;
|
||||
data = 0x80 | length_bytes_required; /* extended length definition, 1 length byte follows */
|
||||
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, data));
|
||||
|
||||
while (length_bytes_required > 1) {
|
||||
if (length_bytes_required == 2) {
|
||||
/* append high byte */
|
||||
data = (u8_t)(tlv->value_len >> 8);
|
||||
} else {
|
||||
/* append leading 0x00 */
|
||||
data = 0x00;
|
||||
}
|
||||
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, data));
|
||||
length_bytes_required--;
|
||||
}
|
||||
}
|
||||
|
||||
/* append low byte */
|
||||
data = (u8_t)(tlv->value_len & 0xFF);
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, data));
|
||||
|
||||
return ERR_OK;
|
||||
while (length_bytes_required > 1) {
|
||||
if (length_bytes_required == 2) {
|
||||
/* append high byte */
|
||||
data = (u8_t)(tlv->value_len >> 8);
|
||||
} else {
|
||||
/* append leading 0x00 */
|
||||
data = 0x00;
|
||||
}
|
||||
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, data));
|
||||
length_bytes_required--;
|
||||
}
|
||||
}
|
||||
|
||||
/* append low byte */
|
||||
data = (u8_t)(tlv->value_len & 0xFF);
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, data));
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -129,11 +129,12 @@ err_t snmp_ans1_enc_tlv(struct snmp_pbuf_stream *pbuf_stream, struct snmp_asn1_t
|
||||
* @param raw points raw data
|
||||
* @return ERR_OK if successful, ERR_ARG if we can't (or won't) encode
|
||||
*/
|
||||
err_t snmp_asn1_enc_raw(struct snmp_pbuf_stream *pbuf_stream, const u8_t *raw, u16_t raw_len)
|
||||
err_t
|
||||
snmp_asn1_enc_raw(struct snmp_pbuf_stream *pbuf_stream, const u8_t *raw, u16_t raw_len)
|
||||
{
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_writebuf(pbuf_stream, raw, raw_len));
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_writebuf(pbuf_stream, raw, raw_len));
|
||||
|
||||
return ERR_OK;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -146,27 +147,27 @@ err_t snmp_asn1_enc_raw(struct snmp_pbuf_stream *pbuf_stream, const u8_t *raw, u
|
||||
*
|
||||
* @see snmp_asn1_enc_u32t_cnt()
|
||||
*/
|
||||
err_t snmp_asn1_enc_u32t(struct snmp_pbuf_stream *pbuf_stream, u16_t octets_needed, u32_t value)
|
||||
err_t
|
||||
snmp_asn1_enc_u32t(struct snmp_pbuf_stream *pbuf_stream, u16_t octets_needed, u32_t value)
|
||||
{
|
||||
if (octets_needed > 5) {
|
||||
return ERR_ARG;
|
||||
}
|
||||
if (octets_needed > 5) {
|
||||
return ERR_ARG;
|
||||
}
|
||||
if (octets_needed == 5) {
|
||||
/* not enough bits in 'value' add leading 0x00 */
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, 0x00));
|
||||
octets_needed--;
|
||||
}
|
||||
|
||||
if (octets_needed == 5) {
|
||||
/* not enough bits in 'value' add leading 0x00 */
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, 0x00));
|
||||
octets_needed--;
|
||||
}
|
||||
while (octets_needed > 1) {
|
||||
octets_needed--;
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, (u8_t)(value >> (octets_needed << 3))));
|
||||
}
|
||||
|
||||
while (octets_needed > 1) {
|
||||
octets_needed--;
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, (u8_t)(value >> (octets_needed << 3))));
|
||||
}
|
||||
/* (only) one least significant octet */
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, (u8_t)value));
|
||||
|
||||
/* (only) one least significant octet */
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, (u8_t)value));
|
||||
|
||||
return ERR_OK;
|
||||
return ERR_OK;
|
||||
}
|
||||
/**
|
||||
* Encodes s32_t integer into a pbuf chained ASN1 msg.
|
||||
@ -178,18 +179,19 @@ err_t snmp_asn1_enc_u32t(struct snmp_pbuf_stream *pbuf_stream, u16_t octets_need
|
||||
*
|
||||
* @see snmp_asn1_enc_s32t_cnt()
|
||||
*/
|
||||
err_t snmp_asn1_enc_s32t(struct snmp_pbuf_stream *pbuf_stream, u16_t octets_needed, s32_t value)
|
||||
err_t
|
||||
snmp_asn1_enc_s32t(struct snmp_pbuf_stream *pbuf_stream, u16_t octets_needed, s32_t value)
|
||||
{
|
||||
while (octets_needed > 1) {
|
||||
octets_needed--;
|
||||
while (octets_needed > 1) {
|
||||
octets_needed--;
|
||||
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, (u8_t)(value >> (octets_needed << 3))));
|
||||
}
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, (u8_t)(value >> (octets_needed << 3))));
|
||||
}
|
||||
|
||||
/* (only) one least significant octet */
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, (u8_t)value));
|
||||
/* (only) one least significant octet */
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, (u8_t)value));
|
||||
|
||||
return ERR_OK;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -200,49 +202,45 @@ err_t snmp_asn1_enc_s32t(struct snmp_pbuf_stream *pbuf_stream, u16_t octets_need
|
||||
* @param oid_len object identifier array length
|
||||
* @return ERR_OK if successful, ERR_ARG if we can't (or won't) encode
|
||||
*/
|
||||
err_t snmp_asn1_enc_oid(struct snmp_pbuf_stream *pbuf_stream, const u32_t *oid, u16_t oid_len)
|
||||
err_t
|
||||
snmp_asn1_enc_oid(struct snmp_pbuf_stream *pbuf_stream, const u32_t *oid, u16_t oid_len)
|
||||
{
|
||||
if (oid_len > 1) {
|
||||
/* write compressed first two sub id's */
|
||||
u32_t compressed_byte = ((oid[0] * 40) + oid[1]);
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, (u8_t)compressed_byte));
|
||||
oid_len -= 2;
|
||||
oid += 2;
|
||||
} else {
|
||||
/* @bug: allow empty varbinds for symmetry (we must decode them for getnext), allow partial compression?? */
|
||||
/* ident_len <= 1, at least we need zeroDotZero (0.0) (ident_len == 2) */
|
||||
return ERR_ARG;
|
||||
if (oid_len > 1) {
|
||||
/* write compressed first two sub id's */
|
||||
u32_t compressed_byte = ((oid[0] * 40) + oid[1]);
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, (u8_t)compressed_byte));
|
||||
oid_len -= 2;
|
||||
oid += 2;
|
||||
} else {
|
||||
/* @bug: allow empty varbinds for symmetry (we must decode them for getnext), allow partial compression?? */
|
||||
/* ident_len <= 1, at least we need zeroDotZero (0.0) (ident_len == 2) */
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
while (oid_len > 0) {
|
||||
u32_t sub_id;
|
||||
u8_t shift, tail;
|
||||
|
||||
oid_len--;
|
||||
sub_id = *oid;
|
||||
tail = 0;
|
||||
shift = 28;
|
||||
while (shift > 0) {
|
||||
u8_t code;
|
||||
|
||||
code = (u8_t)(sub_id >> shift);
|
||||
if ((code != 0) || (tail != 0)) {
|
||||
tail = 1;
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, code | 0x80));
|
||||
}
|
||||
shift -= 7;
|
||||
}
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, (u8_t)sub_id & 0x7F));
|
||||
|
||||
while (oid_len > 0) {
|
||||
u32_t sub_id;
|
||||
u8_t shift, tail;
|
||||
|
||||
oid_len--;
|
||||
sub_id = *oid;
|
||||
tail = 0;
|
||||
shift = 28;
|
||||
|
||||
while (shift > 0) {
|
||||
u8_t code;
|
||||
|
||||
code = (u8_t)(sub_id >> shift);
|
||||
|
||||
if ((code != 0) || (tail != 0)) {
|
||||
tail = 1;
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, code | 0x80));
|
||||
}
|
||||
|
||||
shift -= 7;
|
||||
}
|
||||
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, (u8_t)sub_id & 0x7F));
|
||||
|
||||
/* proceed to next sub-identifier */
|
||||
oid++;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
/* proceed to next sub-identifier */
|
||||
oid++;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -251,15 +249,16 @@ err_t snmp_asn1_enc_oid(struct snmp_pbuf_stream *pbuf_stream, const u32_t *oid,
|
||||
* @param length parameter length
|
||||
* @param octets_needed points to the return value
|
||||
*/
|
||||
void snmp_asn1_enc_length_cnt(u16_t length, u8_t *octets_needed)
|
||||
void
|
||||
snmp_asn1_enc_length_cnt(u16_t length, u8_t *octets_needed)
|
||||
{
|
||||
if (length < 0x80U) {
|
||||
*octets_needed = 1;
|
||||
} else if (length < 0x100U) {
|
||||
*octets_needed = 2;
|
||||
} else {
|
||||
*octets_needed = 3;
|
||||
}
|
||||
if (length < 0x80U) {
|
||||
*octets_needed = 1;
|
||||
} else if (length < 0x100U) {
|
||||
*octets_needed = 2;
|
||||
} else {
|
||||
*octets_needed = 3;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -272,19 +271,20 @@ void snmp_asn1_enc_length_cnt(u16_t length, u8_t *octets_needed)
|
||||
* as 0x00,0xFF,0xFF. Note the leading sign octet. A positive value
|
||||
* of 0xFFFFFFFF is preceded with 0x00 and the length is 5 octets!!
|
||||
*/
|
||||
void snmp_asn1_enc_u32t_cnt(u32_t value, u16_t *octets_needed)
|
||||
void
|
||||
snmp_asn1_enc_u32t_cnt(u32_t value, u16_t *octets_needed)
|
||||
{
|
||||
if (value < 0x80UL) {
|
||||
*octets_needed = 1;
|
||||
} else if (value < 0x8000UL) {
|
||||
*octets_needed = 2;
|
||||
} else if (value < 0x800000UL) {
|
||||
*octets_needed = 3;
|
||||
} else if (value < 0x80000000UL) {
|
||||
*octets_needed = 4;
|
||||
} else {
|
||||
*octets_needed = 5;
|
||||
}
|
||||
if (value < 0x80UL) {
|
||||
*octets_needed = 1;
|
||||
} else if (value < 0x8000UL) {
|
||||
*octets_needed = 2;
|
||||
} else if (value < 0x800000UL) {
|
||||
*octets_needed = 3;
|
||||
} else if (value < 0x80000000UL) {
|
||||
*octets_needed = 4;
|
||||
} else {
|
||||
*octets_needed = 5;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -295,21 +295,21 @@ void snmp_asn1_enc_u32t_cnt(u32_t value, u16_t *octets_needed)
|
||||
*
|
||||
* @note ASN coded integers are _always_ signed.
|
||||
*/
|
||||
void snmp_asn1_enc_s32t_cnt(s32_t value, u16_t *octets_needed)
|
||||
void
|
||||
snmp_asn1_enc_s32t_cnt(s32_t value, u16_t *octets_needed)
|
||||
{
|
||||
if (value < 0) {
|
||||
value = ~value;
|
||||
}
|
||||
|
||||
if (value < 0x80L) {
|
||||
*octets_needed = 1;
|
||||
} else if (value < 0x8000L) {
|
||||
*octets_needed = 2;
|
||||
} else if (value < 0x800000L) {
|
||||
*octets_needed = 3;
|
||||
} else {
|
||||
*octets_needed = 4;
|
||||
}
|
||||
if (value < 0) {
|
||||
value = ~value;
|
||||
}
|
||||
if (value < 0x80L) {
|
||||
*octets_needed = 1;
|
||||
} else if (value < 0x8000L) {
|
||||
*octets_needed = 2;
|
||||
} else if (value < 0x800000L) {
|
||||
*octets_needed = 3;
|
||||
} else {
|
||||
*octets_needed = 4;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -319,33 +319,30 @@ void snmp_asn1_enc_s32t_cnt(s32_t value, u16_t *octets_needed)
|
||||
* @param oid_len object identifier array length
|
||||
* @param octets_needed points to the return value
|
||||
*/
|
||||
void snmp_asn1_enc_oid_cnt(const u32_t *oid, u16_t oid_len, u16_t *octets_needed)
|
||||
void
|
||||
snmp_asn1_enc_oid_cnt(const u32_t *oid, u16_t oid_len, u16_t *octets_needed)
|
||||
{
|
||||
u32_t sub_id;
|
||||
u32_t sub_id;
|
||||
|
||||
*octets_needed = 0;
|
||||
*octets_needed = 0;
|
||||
if (oid_len > 1) {
|
||||
/* compressed prefix in one octet */
|
||||
(*octets_needed)++;
|
||||
oid_len -= 2;
|
||||
oid += 2;
|
||||
}
|
||||
while (oid_len > 0) {
|
||||
oid_len--;
|
||||
sub_id = *oid;
|
||||
|
||||
if (oid_len > 1) {
|
||||
/* compressed prefix in one octet */
|
||||
(*octets_needed)++;
|
||||
oid_len -= 2;
|
||||
oid += 2;
|
||||
}
|
||||
|
||||
while (oid_len > 0) {
|
||||
oid_len--;
|
||||
sub_id = *oid;
|
||||
|
||||
sub_id >>= 7;
|
||||
(*octets_needed)++;
|
||||
|
||||
while (sub_id > 0) {
|
||||
sub_id >>= 7;
|
||||
(*octets_needed)++;
|
||||
}
|
||||
|
||||
oid++;
|
||||
sub_id >>= 7;
|
||||
(*octets_needed)++;
|
||||
while (sub_id > 0) {
|
||||
sub_id >>= 7;
|
||||
(*octets_needed)++;
|
||||
}
|
||||
oid++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -355,63 +352,57 @@ void snmp_asn1_enc_oid_cnt(const u32_t *oid, u16_t oid_len, u16_t *octets_needed
|
||||
* @param tlv returns decoded TLV
|
||||
* @return ERR_OK if successful, ERR_VAL if we can't decode
|
||||
*/
|
||||
err_t snmp_asn1_dec_tlv(struct snmp_pbuf_stream *pbuf_stream, struct snmp_asn1_tlv *tlv)
|
||||
err_t
|
||||
snmp_asn1_dec_tlv(struct snmp_pbuf_stream *pbuf_stream, struct snmp_asn1_tlv *tlv)
|
||||
{
|
||||
u8_t data;
|
||||
u8_t data;
|
||||
|
||||
/* decode type first */
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data));
|
||||
tlv->type = data;
|
||||
/* decode type first */
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data));
|
||||
tlv->type = data;
|
||||
|
||||
if ((tlv->type & SNMP_ASN1_DATATYPE_MASK) == SNMP_ASN1_DATATYPE_EXTENDED) {
|
||||
/* extended format is not used by SNMP so we do not accept those values */
|
||||
return ERR_VAL;
|
||||
if ((tlv->type & SNMP_ASN1_DATATYPE_MASK) == SNMP_ASN1_DATATYPE_EXTENDED) {
|
||||
/* extended format is not used by SNMP so we do not accept those values */
|
||||
return ERR_VAL;
|
||||
}
|
||||
tlv->type_len = 1;
|
||||
|
||||
/* now, decode length */
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data));
|
||||
|
||||
if (data < 0x80) { /* short form */
|
||||
tlv->length_len = 1;
|
||||
tlv->value_len = data;
|
||||
} else if (data > 0x80) { /* long form */
|
||||
u8_t length_bytes = data - 0x80;
|
||||
if (length_bytes > pbuf_stream->length) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
tlv->length_len = length_bytes + 1; /* this byte + defined number of length bytes following */
|
||||
tlv->value_len = 0;
|
||||
|
||||
tlv->type_len = 1;
|
||||
|
||||
/* now, decode length */
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data));
|
||||
|
||||
if (data < 0x80) /* short form */
|
||||
{
|
||||
tlv->length_len = 1;
|
||||
tlv->value_len = data;
|
||||
} else if (data > 0x80) /* long form */
|
||||
{
|
||||
u8_t length_bytes = data - 0x80;
|
||||
|
||||
if (length_bytes > pbuf_stream->length) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
tlv->length_len = length_bytes + 1; /* this byte + defined number of length bytes following */
|
||||
tlv->value_len = 0;
|
||||
|
||||
while (length_bytes > 0) {
|
||||
/* we only support up to u16.maxvalue-1 (2 bytes) but have to accept leading zero bytes */
|
||||
if (tlv->value_len > 0xFF) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data));
|
||||
tlv->value_len <<= 8;
|
||||
tlv->value_len |= data;
|
||||
|
||||
/* take care for special value used for indefinite length */
|
||||
if (tlv->value_len == 0xFFFF) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
length_bytes--;
|
||||
}
|
||||
} else /* data == 0x80 indefinite length form */
|
||||
{
|
||||
/* (not allowed for SNMP; RFC 1157, 3.2.2) */
|
||||
while (length_bytes > 0) {
|
||||
/* we only support up to u16.maxvalue-1 (2 bytes) but have to accept leading zero bytes */
|
||||
if (tlv->value_len > 0xFF) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
}
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data));
|
||||
tlv->value_len <<= 8;
|
||||
tlv->value_len |= data;
|
||||
|
||||
return ERR_OK;
|
||||
/* take care for special value used for indefinite length */
|
||||
if (tlv->value_len == 0xFFFF) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
length_bytes--;
|
||||
}
|
||||
} else { /* data == 0x80 indefinite length form */
|
||||
/* (not allowed for SNMP; RFC 1157, 3.2.2) */
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -426,31 +417,32 @@ err_t snmp_asn1_dec_tlv(struct snmp_pbuf_stream *pbuf_stream, struct snmp_asn1_t
|
||||
* as 0x00,0xFF,0xFF. Note the leading sign octet. A positive value
|
||||
* of 0xFFFFFFFF is preceded with 0x00 and the length is 5 octets!!
|
||||
*/
|
||||
err_t snmp_asn1_dec_u32t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u32_t *value)
|
||||
err_t
|
||||
snmp_asn1_dec_u32t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u32_t *value)
|
||||
{
|
||||
u8_t data;
|
||||
u8_t data;
|
||||
|
||||
if ((len > 0) && (len <= 5)) {
|
||||
if ((len > 0) && (len <= 5)) {
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data));
|
||||
|
||||
/* expecting sign bit to be zero, only unsigned please! */
|
||||
if (((len == 5) && (data == 0x00)) || ((len < 5) && ((data & 0x80) == 0))) {
|
||||
*value = data;
|
||||
len--;
|
||||
|
||||
while (len > 0) {
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data));
|
||||
len--;
|
||||
|
||||
/* expecting sign bit to be zero, only unsigned please! */
|
||||
if (((len == 5) && (data == 0x00)) || ((len < 5) && ((data & 0x80) == 0))) {
|
||||
*value = data;
|
||||
len--;
|
||||
*value <<= 8;
|
||||
*value |= data;
|
||||
}
|
||||
|
||||
while (len > 0) {
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data));
|
||||
len--;
|
||||
|
||||
*value <<= 8;
|
||||
*value |= data;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return ERR_VAL;
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -463,35 +455,33 @@ err_t snmp_asn1_dec_u32t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u32_t
|
||||
*
|
||||
* @note ASN coded integers are _always_ signed!
|
||||
*/
|
||||
err_t snmp_asn1_dec_s32t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, s32_t *value)
|
||||
err_t
|
||||
snmp_asn1_dec_s32t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, s32_t *value)
|
||||
{
|
||||
u8_t data;
|
||||
u8_t data;
|
||||
|
||||
if ((len > 0) && (len < 5)) {
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data));
|
||||
if ((len > 0) && (len < 5)) {
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data));
|
||||
|
||||
if (data & 0x80) {
|
||||
/* negative, start from -1 */
|
||||
*value = -1;
|
||||
*value = (*value << 8) | data;
|
||||
} else {
|
||||
/* positive, start from 0 */
|
||||
*value = data;
|
||||
}
|
||||
|
||||
len--;
|
||||
|
||||
/* shift in the remaining value */
|
||||
while (len > 0) {
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data));
|
||||
*value = (*value << 8) | data;
|
||||
len--;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
if (data & 0x80) {
|
||||
/* negative, start from -1 */
|
||||
*value = -1;
|
||||
*value = (*value << 8) | data;
|
||||
} else {
|
||||
/* positive, start from 0 */
|
||||
*value = data;
|
||||
}
|
||||
len--;
|
||||
/* shift in the remaining value */
|
||||
while (len > 0) {
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data));
|
||||
*value = (*value << 8) | data;
|
||||
len--;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
return ERR_VAL;
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -504,88 +494,84 @@ err_t snmp_asn1_dec_s32t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, s32_t
|
||||
* @param oid_max_len size of oid buffer
|
||||
* @return ERR_OK if successful, ERR_ARG if we can't (or won't) decode
|
||||
*/
|
||||
err_t snmp_asn1_dec_oid(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u32_t *oid, u8_t *oid_len, u8_t oid_max_len)
|
||||
err_t
|
||||
snmp_asn1_dec_oid(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u32_t *oid, u8_t *oid_len, u8_t oid_max_len)
|
||||
{
|
||||
u32_t *oid_ptr;
|
||||
u8_t data;
|
||||
u32_t *oid_ptr;
|
||||
u8_t data;
|
||||
|
||||
*oid_len = 0;
|
||||
oid_ptr = oid;
|
||||
*oid_len = 0;
|
||||
oid_ptr = oid;
|
||||
if (len > 0) {
|
||||
if (oid_max_len < 2) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
if (len > 0) {
|
||||
if (oid_max_len < 2) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data));
|
||||
len--;
|
||||
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data));
|
||||
len--;
|
||||
|
||||
/* first compressed octet */
|
||||
if (data == 0x2B) {
|
||||
/* (most) common case 1.3 (iso.org) */
|
||||
*oid_ptr = 1;
|
||||
oid_ptr++;
|
||||
*oid_ptr = 3;
|
||||
oid_ptr++;
|
||||
} else if (data < 40) {
|
||||
*oid_ptr = 0;
|
||||
oid_ptr++;
|
||||
*oid_ptr = data;
|
||||
oid_ptr++;
|
||||
} else if (data < 80) {
|
||||
*oid_ptr = 1;
|
||||
oid_ptr++;
|
||||
*oid_ptr = data - 40;
|
||||
oid_ptr++;
|
||||
} else {
|
||||
*oid_ptr = 2;
|
||||
oid_ptr++;
|
||||
*oid_ptr = data - 80;
|
||||
oid_ptr++;
|
||||
}
|
||||
|
||||
*oid_len = 2;
|
||||
/* first compressed octet */
|
||||
if (data == 0x2B) {
|
||||
/* (most) common case 1.3 (iso.org) */
|
||||
*oid_ptr = 1;
|
||||
oid_ptr++;
|
||||
*oid_ptr = 3;
|
||||
oid_ptr++;
|
||||
} else if (data < 40) {
|
||||
*oid_ptr = 0;
|
||||
oid_ptr++;
|
||||
*oid_ptr = data;
|
||||
oid_ptr++;
|
||||
} else if (data < 80) {
|
||||
*oid_ptr = 1;
|
||||
oid_ptr++;
|
||||
*oid_ptr = data - 40;
|
||||
oid_ptr++;
|
||||
} else {
|
||||
/* accepting zero length identifiers e.g. for getnext operation. uncommon but valid */
|
||||
return ERR_OK;
|
||||
*oid_ptr = 2;
|
||||
oid_ptr++;
|
||||
*oid_ptr = data - 80;
|
||||
oid_ptr++;
|
||||
}
|
||||
*oid_len = 2;
|
||||
} else {
|
||||
/* accepting zero length identifiers e.g. for getnext operation. uncommon but valid */
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
while ((len > 0) && (*oid_len < oid_max_len)) {
|
||||
while ((len > 0) && (*oid_len < oid_max_len)) {
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data));
|
||||
len--;
|
||||
|
||||
if ((data & 0x80) == 0x00) {
|
||||
/* sub-identifier uses single octet */
|
||||
*oid_ptr = data;
|
||||
} else {
|
||||
/* sub-identifier uses multiple octets */
|
||||
u32_t sub_id = (data & ~0x80);
|
||||
while ((len > 0) && ((data & 0x80) != 0)) {
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data));
|
||||
len--;
|
||||
|
||||
if ((data & 0x80) == 0x00) {
|
||||
/* sub-identifier uses single octet */
|
||||
*oid_ptr = data;
|
||||
} else {
|
||||
/* sub-identifier uses multiple octets */
|
||||
u32_t sub_id = (data & ~0x80);
|
||||
sub_id = (sub_id << 7) + (data & ~0x80);
|
||||
}
|
||||
|
||||
while ((len > 0) && ((data & 0x80) != 0)) {
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data));
|
||||
len--;
|
||||
|
||||
sub_id = (sub_id << 7) + (data & ~0x80);
|
||||
}
|
||||
|
||||
if ((data & 0x80) != 0) {
|
||||
/* "more bytes following" bit still set at end of len */
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
*oid_ptr = sub_id;
|
||||
}
|
||||
|
||||
oid_ptr++;
|
||||
(*oid_len)++;
|
||||
if ((data & 0x80) != 0) {
|
||||
/* "more bytes following" bit still set at end of len */
|
||||
return ERR_VAL;
|
||||
}
|
||||
*oid_ptr = sub_id;
|
||||
}
|
||||
oid_ptr++;
|
||||
(*oid_len)++;
|
||||
}
|
||||
|
||||
if (len > 0) {
|
||||
/* OID to long to fit in our buffer */
|
||||
return ERR_MEM;
|
||||
}
|
||||
if (len > 0) {
|
||||
/* OID to long to fit in our buffer */
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -599,22 +585,22 @@ err_t snmp_asn1_dec_oid(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u32_t *
|
||||
* @param buf_max_len buffer size
|
||||
* @return ERR_OK if successful, ERR_ARG if we can't (or won't) decode
|
||||
*/
|
||||
err_t snmp_asn1_dec_raw(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u8_t *buf, u16_t *buf_len, u16_t buf_max_len)
|
||||
err_t
|
||||
snmp_asn1_dec_raw(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u8_t *buf, u16_t *buf_len, u16_t buf_max_len)
|
||||
{
|
||||
if (len > buf_max_len) {
|
||||
/* not enough dst space */
|
||||
return ERR_MEM;
|
||||
}
|
||||
if (len > buf_max_len) {
|
||||
/* not enough dst space */
|
||||
return ERR_MEM;
|
||||
}
|
||||
*buf_len = len;
|
||||
|
||||
*buf_len = len;
|
||||
while (len > 0) {
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, buf));
|
||||
buf++;
|
||||
len--;
|
||||
}
|
||||
|
||||
while (len > 0) {
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, buf));
|
||||
buf++;
|
||||
len--;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
#if LWIP_HAVE_INT64
|
||||
@ -628,17 +614,18 @@ err_t snmp_asn1_dec_raw(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u8_t *b
|
||||
* as 0x00,0xFF,0xFF. Note the leading sign octet. A positive value
|
||||
* of 0xFFFFFFFFFFFFFFFF is preceded with 0x00 and the length is 9 octets!!
|
||||
*/
|
||||
void snmp_asn1_enc_u64t_cnt(u64_t value, u16_t *octets_needed)
|
||||
void
|
||||
snmp_asn1_enc_u64t_cnt(u64_t value, u16_t *octets_needed)
|
||||
{
|
||||
/* check if high u32 is 0 */
|
||||
if ((value >> 32) == 0) {
|
||||
/* only low u32 is important */
|
||||
snmp_asn1_enc_u32t_cnt((u32_t)value, octets_needed);
|
||||
} else {
|
||||
/* low u32 does not matter for length determination */
|
||||
snmp_asn1_enc_u32t_cnt((u32_t)(value >> 32), octets_needed);
|
||||
*octets_needed = *octets_needed + 4; /* add the 4 bytes of low u32 */
|
||||
}
|
||||
/* check if high u32 is 0 */
|
||||
if ((value >> 32) == 0) {
|
||||
/* only low u32 is important */
|
||||
snmp_asn1_enc_u32t_cnt((u32_t)value, octets_needed);
|
||||
} else {
|
||||
/* low u32 does not matter for length determination */
|
||||
snmp_asn1_enc_u32t_cnt((u32_t)(value >> 32), octets_needed);
|
||||
*octets_needed = *octets_needed + 4; /* add the 4 bytes of low u32 */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -653,30 +640,31 @@ void snmp_asn1_enc_u64t_cnt(u64_t value, u16_t *octets_needed)
|
||||
* as 0x00,0xFF,0xFF. Note the leading sign octet. A positive value
|
||||
* of 0xFFFFFFFFFFFFFFFF is preceded with 0x00 and the length is 9 octets!!
|
||||
*/
|
||||
err_t snmp_asn1_dec_u64t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u64_t *value)
|
||||
err_t
|
||||
snmp_asn1_dec_u64t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u64_t *value)
|
||||
{
|
||||
u8_t data;
|
||||
u8_t data;
|
||||
|
||||
if ((len > 0) && (len <= 9)) {
|
||||
if ((len > 0) && (len <= 9)) {
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data));
|
||||
|
||||
/* expecting sign bit to be zero, only unsigned please! */
|
||||
if (((len == 9) && (data == 0x00)) || ((len < 9) && ((data & 0x80) == 0))) {
|
||||
*value = data;
|
||||
len--;
|
||||
|
||||
while (len > 0) {
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data));
|
||||
*value <<= 8;
|
||||
*value |= data;
|
||||
len--;
|
||||
}
|
||||
|
||||
/* expecting sign bit to be zero, only unsigned please! */
|
||||
if (((len == 9) && (data == 0x00)) || ((len < 9) && ((data & 0x80) == 0))) {
|
||||
*value = data;
|
||||
len--;
|
||||
|
||||
while (len > 0) {
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data));
|
||||
*value <<= 8;
|
||||
*value |= data;
|
||||
len--;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return ERR_VAL;
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -689,27 +677,27 @@ err_t snmp_asn1_dec_u64t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u64_t
|
||||
*
|
||||
* @see snmp_asn1_enc_u64t_cnt()
|
||||
*/
|
||||
err_t snmp_asn1_enc_u64t(struct snmp_pbuf_stream *pbuf_stream, u16_t octets_needed, u64_t value)
|
||||
err_t
|
||||
snmp_asn1_enc_u64t(struct snmp_pbuf_stream *pbuf_stream, u16_t octets_needed, u64_t value)
|
||||
{
|
||||
if (octets_needed > 9) {
|
||||
return ERR_ARG;
|
||||
}
|
||||
if (octets_needed > 9) {
|
||||
return ERR_ARG;
|
||||
}
|
||||
if (octets_needed == 9) {
|
||||
/* not enough bits in 'value' add leading 0x00 */
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, 0x00));
|
||||
octets_needed--;
|
||||
}
|
||||
|
||||
if (octets_needed == 9) {
|
||||
/* not enough bits in 'value' add leading 0x00 */
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, 0x00));
|
||||
octets_needed--;
|
||||
}
|
||||
while (octets_needed > 1) {
|
||||
octets_needed--;
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, (u8_t)(value >> (octets_needed << 3))));
|
||||
}
|
||||
|
||||
while (octets_needed > 1) {
|
||||
octets_needed--;
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, (u8_t)(value >> (octets_needed << 3))));
|
||||
}
|
||||
/* always write at least one octet (also in case of value == 0) */
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, (u8_t)(value)));
|
||||
|
||||
/* always write at least one octet (also in case of value == 0) */
|
||||
PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, (u8_t)(value)));
|
||||
|
||||
return ERR_OK;
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -68,24 +68,18 @@ extern "C" {
|
||||
#define SNMP_ASN1_CONTEXT_PDU_V2_TRAP 7
|
||||
#define SNMP_ASN1_CONTEXT_PDU_REPORT 8
|
||||
|
||||
#define SNMP_ASN1_CONTEXT_VARBIND_NO_SUCH_OBJECT 0
|
||||
#define SNMP_ASN1_CONTEXT_VARBIND_END_OF_MIB_VIEW 2
|
||||
#define SNMP_ASN1_CONTEXT_VARBIND_NO_SUCH_OBJECT 0
|
||||
#define SNMP_ASN1_CONTEXT_VARBIND_END_OF_MIB_VIEW 2
|
||||
|
||||
struct snmp_asn1_tlv {
|
||||
u8_t type; /* only U8 because extended types are not specified by SNMP */
|
||||
u8_t type_len; /* encoded length of 'type' field (normally 1) */
|
||||
u8_t length_len; /* indicates how many bytes are required to encode the 'value_len' field */
|
||||
u16_t value_len; /* encoded length of the value */
|
||||
u8_t type; /* only U8 because extended types are not specified by SNMP */
|
||||
u8_t type_len; /* encoded length of 'type' field (normally 1) */
|
||||
u8_t length_len; /* indicates how many bytes are required to encode the 'value_len' field */
|
||||
u16_t value_len; /* encoded length of the value */
|
||||
};
|
||||
#define SNMP_ASN1_TLV_HDR_LENGTH(tlv) ((tlv).type_len + (tlv).length_len)
|
||||
#define SNMP_ASN1_TLV_LENGTH(tlv) ((tlv).type_len + (tlv).length_len + (tlv).value_len)
|
||||
#define SNMP_ASN1_SET_TLV_PARAMS(tlv, type_, length_len_, value_len_) \
|
||||
do { \
|
||||
(tlv).type = (type_); \
|
||||
(tlv).type_len = 0; \
|
||||
(tlv).length_len = (length_len_); \
|
||||
(tlv).value_len = (value_len_); \
|
||||
} while (0);
|
||||
#define SNMP_ASN1_TLV_LENGTH(tlv) ((tlv).type_len + (tlv).length_len + (tlv).value_len)
|
||||
#define SNMP_ASN1_SET_TLV_PARAMS(tlv, type_, length_len_, value_len_) do { (tlv).type = (type_); (tlv).type_len = 0; (tlv).length_len = (length_len_); (tlv).value_len = (value_len_); } while (0);
|
||||
|
||||
err_t snmp_asn1_dec_tlv(struct snmp_pbuf_stream *pbuf_stream, struct snmp_asn1_tlv *tlv);
|
||||
err_t snmp_asn1_dec_u32t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u32_t *value);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -53,8 +53,8 @@ extern "C" {
|
||||
/* error codes which are internal and shall not be used by MIBS
|
||||
* shall not be used by MIBS anymore, nevertheless required from core for properly answering a v1 request
|
||||
*/
|
||||
#define SNMP_ERR_TOOBIG 1
|
||||
#define SNMP_ERR_AUTHORIZATIONERROR 16
|
||||
#define SNMP_ERR_TOOBIG 1
|
||||
#define SNMP_ERR_AUTHORIZATIONERROR 16
|
||||
|
||||
#define SNMP_ERR_UNKNOWN_ENGINEID 30
|
||||
#define SNMP_ERR_UNKNOWN_SECURITYNAME 31
|
||||
@ -62,8 +62,9 @@ extern "C" {
|
||||
#define SNMP_ERR_NOTINTIMEWINDOW 33
|
||||
#define SNMP_ERR_DECRYIPTION_ERROR 34
|
||||
|
||||
#define SNMP_ERR_NOSUCHOBJECT SNMP_VARBIND_EXCEPTION_OFFSET + SNMP_ASN1_CONTEXT_VARBIND_NO_SUCH_OBJECT
|
||||
#define SNMP_ERR_ENDOFMIBVIEW SNMP_VARBIND_EXCEPTION_OFFSET + SNMP_ASN1_CONTEXT_VARBIND_END_OF_MIB_VIEW
|
||||
#define SNMP_ERR_NOSUCHOBJECT SNMP_VARBIND_EXCEPTION_OFFSET + SNMP_ASN1_CONTEXT_VARBIND_NO_SUCH_OBJECT
|
||||
#define SNMP_ERR_ENDOFMIBVIEW SNMP_VARBIND_EXCEPTION_OFFSET + SNMP_ASN1_CONTEXT_VARBIND_END_OF_MIB_VIEW
|
||||
|
||||
|
||||
const struct snmp_node *snmp_mib_tree_resolve_exact(const struct snmp_mib *mib, const u32_t *oid, u8_t oid_len, u8_t *oid_instance_len);
|
||||
const struct snmp_node *snmp_mib_tree_resolve_next(const struct snmp_mib *mib, const u32_t *oid, u8_t oid_len, struct snmp_obj_id *oidret);
|
||||
|
@ -58,14 +58,15 @@
|
||||
#if SNMP_USE_NETCONN
|
||||
#include "lwip/tcpip.h"
|
||||
#include "lwip/priv/tcpip_priv.h"
|
||||
void snmp_mib2_lwip_synchronizer(snmp_threadsync_called_fn fn, void *arg)
|
||||
void
|
||||
snmp_mib2_lwip_synchronizer(snmp_threadsync_called_fn fn, void *arg)
|
||||
{
|
||||
#if LWIP_TCPIP_CORE_LOCKING
|
||||
LOCK_TCPIP_CORE();
|
||||
fn(arg);
|
||||
UNLOCK_TCPIP_CORE();
|
||||
LOCK_TCPIP_CORE();
|
||||
fn(arg);
|
||||
UNLOCK_TCPIP_CORE();
|
||||
#else
|
||||
tcpip_callback(fn, arg);
|
||||
tcpip_callback(fn, arg);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -87,29 +88,29 @@ extern const struct snmp_tree_node snmp_mib2_at_root;
|
||||
extern const struct snmp_tree_node snmp_mib2_ip_root;
|
||||
|
||||
static const struct snmp_node *const mib2_nodes[] = {
|
||||
&snmp_mib2_system_node.node.node,
|
||||
&snmp_mib2_interface_root.node,
|
||||
&snmp_mib2_system_node.node.node,
|
||||
&snmp_mib2_interface_root.node,
|
||||
#if LWIP_ARP && LWIP_IPV4
|
||||
&snmp_mib2_at_root.node,
|
||||
&snmp_mib2_at_root.node,
|
||||
#endif /* LWIP_ARP && LWIP_IPV4 */
|
||||
#if LWIP_IPV4
|
||||
&snmp_mib2_ip_root.node,
|
||||
&snmp_mib2_ip_root.node,
|
||||
#endif /* LWIP_IPV4 */
|
||||
#if LWIP_ICMP
|
||||
&snmp_mib2_icmp_root.node.node,
|
||||
&snmp_mib2_icmp_root.node.node,
|
||||
#endif /* LWIP_ICMP */
|
||||
#if LWIP_TCP
|
||||
&snmp_mib2_tcp_root.node,
|
||||
&snmp_mib2_tcp_root.node,
|
||||
#endif /* LWIP_TCP */
|
||||
#if LWIP_UDP
|
||||
&snmp_mib2_udp_root.node,
|
||||
&snmp_mib2_udp_root.node,
|
||||
#endif /* LWIP_UDP */
|
||||
&snmp_mib2_snmp_root.node.node
|
||||
&snmp_mib2_snmp_root.node.node
|
||||
};
|
||||
|
||||
static const struct snmp_tree_node mib2_root = SNMP_CREATE_TREE_NODE(1, mib2_nodes);
|
||||
|
||||
static const u32_t mib2_base_oid_arr[] = { 1, 3, 6, 1, 2, 1 };
|
||||
static const u32_t mib2_base_oid_arr[] = { 1, 3, 6, 1, 2, 1 };
|
||||
const struct snmp_mib mib2 = SNMP_MIB_CREATE(mib2_base_oid_arr, &mib2_root.node);
|
||||
|
||||
#endif /* LWIP_SNMP && SNMP_LWIP_MIB2 */
|
||||
|
@ -45,9 +45,9 @@
|
||||
#if LWIP_SNMP && SNMP_LWIP_MIB2 && LWIP_ICMP
|
||||
|
||||
#if SNMP_USE_NETCONN
|
||||
#define SYNC_NODE_NAME(node_name) node_name##_synced
|
||||
#define SYNC_NODE_NAME(node_name) node_name ## _synced
|
||||
#define CREATE_LWIP_SYNC_NODE(oid, node_name) \
|
||||
static const struct snmp_threadsync_node node_name##_synced = SNMP_CREATE_THREAD_SYNC_NODE(oid, &node_name.node, &snmp_mib2_lwip_locks);
|
||||
static const struct snmp_threadsync_node node_name ## _synced = SNMP_CREATE_THREAD_SYNC_NODE(oid, &node_name.node, &snmp_mib2_lwip_locks);
|
||||
#else
|
||||
#define SYNC_NODE_NAME(node_name) node_name
|
||||
#define CREATE_LWIP_SYNC_NODE(oid, node_name)
|
||||
@ -55,150 +55,126 @@
|
||||
|
||||
/* --- icmp .1.3.6.1.2.1.5 ----------------------------------------------------- */
|
||||
|
||||
static s16_t icmp_get_value(const struct snmp_scalar_array_node_def *node, void *value)
|
||||
static s16_t
|
||||
icmp_get_value(const struct snmp_scalar_array_node_def *node, void *value)
|
||||
{
|
||||
u32_t *uint_ptr = (u32_t *)value;
|
||||
u32_t *uint_ptr = (u32_t *)value;
|
||||
|
||||
switch (node->oid) {
|
||||
case 1: /* icmpInMsgs */
|
||||
*uint_ptr = STATS_GET(mib2.icmpinmsgs);
|
||||
return sizeof(*uint_ptr);
|
||||
switch (node->oid) {
|
||||
case 1: /* icmpInMsgs */
|
||||
*uint_ptr = STATS_GET(mib2.icmpinmsgs);
|
||||
return sizeof(*uint_ptr);
|
||||
case 2: /* icmpInErrors */
|
||||
*uint_ptr = STATS_GET(mib2.icmpinerrors);
|
||||
return sizeof(*uint_ptr);
|
||||
case 3: /* icmpInDestUnreachs */
|
||||
*uint_ptr = STATS_GET(mib2.icmpindestunreachs);
|
||||
return sizeof(*uint_ptr);
|
||||
case 4: /* icmpInTimeExcds */
|
||||
*uint_ptr = STATS_GET(mib2.icmpintimeexcds);
|
||||
return sizeof(*uint_ptr);
|
||||
case 5: /* icmpInParmProbs */
|
||||
*uint_ptr = STATS_GET(mib2.icmpinparmprobs);
|
||||
return sizeof(*uint_ptr);
|
||||
case 6: /* icmpInSrcQuenchs */
|
||||
*uint_ptr = STATS_GET(mib2.icmpinsrcquenchs);
|
||||
return sizeof(*uint_ptr);
|
||||
case 7: /* icmpInRedirects */
|
||||
*uint_ptr = STATS_GET(mib2.icmpinredirects);
|
||||
return sizeof(*uint_ptr);
|
||||
case 8: /* icmpInEchos */
|
||||
*uint_ptr = STATS_GET(mib2.icmpinechos);
|
||||
return sizeof(*uint_ptr);
|
||||
case 9: /* icmpInEchoReps */
|
||||
*uint_ptr = STATS_GET(mib2.icmpinechoreps);
|
||||
return sizeof(*uint_ptr);
|
||||
case 10: /* icmpInTimestamps */
|
||||
*uint_ptr = STATS_GET(mib2.icmpintimestamps);
|
||||
return sizeof(*uint_ptr);
|
||||
case 11: /* icmpInTimestampReps */
|
||||
*uint_ptr = STATS_GET(mib2.icmpintimestampreps);
|
||||
return sizeof(*uint_ptr);
|
||||
case 12: /* icmpInAddrMasks */
|
||||
*uint_ptr = STATS_GET(mib2.icmpinaddrmasks);
|
||||
return sizeof(*uint_ptr);
|
||||
case 13: /* icmpInAddrMaskReps */
|
||||
*uint_ptr = STATS_GET(mib2.icmpinaddrmaskreps);
|
||||
return sizeof(*uint_ptr);
|
||||
case 14: /* icmpOutMsgs */
|
||||
*uint_ptr = STATS_GET(mib2.icmpoutmsgs);
|
||||
return sizeof(*uint_ptr);
|
||||
case 15: /* icmpOutErrors */
|
||||
*uint_ptr = STATS_GET(mib2.icmpouterrors);
|
||||
return sizeof(*uint_ptr);
|
||||
case 16: /* icmpOutDestUnreachs */
|
||||
*uint_ptr = STATS_GET(mib2.icmpoutdestunreachs);
|
||||
return sizeof(*uint_ptr);
|
||||
case 17: /* icmpOutTimeExcds */
|
||||
*uint_ptr = STATS_GET(mib2.icmpouttimeexcds);
|
||||
return sizeof(*uint_ptr);
|
||||
case 18: /* icmpOutParmProbs: not supported -> always 0 */
|
||||
*uint_ptr = 0;
|
||||
return sizeof(*uint_ptr);
|
||||
case 19: /* icmpOutSrcQuenchs: not supported -> always 0 */
|
||||
*uint_ptr = 0;
|
||||
return sizeof(*uint_ptr);
|
||||
case 20: /* icmpOutRedirects: not supported -> always 0 */
|
||||
*uint_ptr = 0;
|
||||
return sizeof(*uint_ptr);
|
||||
case 21: /* icmpOutEchos */
|
||||
*uint_ptr = STATS_GET(mib2.icmpoutechos);
|
||||
return sizeof(*uint_ptr);
|
||||
case 22: /* icmpOutEchoReps */
|
||||
*uint_ptr = STATS_GET(mib2.icmpoutechoreps);
|
||||
return sizeof(*uint_ptr);
|
||||
case 23: /* icmpOutTimestamps: not supported -> always 0 */
|
||||
*uint_ptr = 0;
|
||||
return sizeof(*uint_ptr);
|
||||
case 24: /* icmpOutTimestampReps: not supported -> always 0 */
|
||||
*uint_ptr = 0;
|
||||
return sizeof(*uint_ptr);
|
||||
case 25: /* icmpOutAddrMasks: not supported -> always 0 */
|
||||
*uint_ptr = 0;
|
||||
return sizeof(*uint_ptr);
|
||||
case 26: /* icmpOutAddrMaskReps: not supported -> always 0 */
|
||||
*uint_ptr = 0;
|
||||
return sizeof(*uint_ptr);
|
||||
default:
|
||||
LWIP_DEBUGF(SNMP_MIB_DEBUG, ("icmp_get_value(): unknown id: %"S32_F"\n", node->oid));
|
||||
break;
|
||||
}
|
||||
|
||||
case 2: /* icmpInErrors */
|
||||
*uint_ptr = STATS_GET(mib2.icmpinerrors);
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 3: /* icmpInDestUnreachs */
|
||||
*uint_ptr = STATS_GET(mib2.icmpindestunreachs);
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 4: /* icmpInTimeExcds */
|
||||
*uint_ptr = STATS_GET(mib2.icmpintimeexcds);
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 5: /* icmpInParmProbs */
|
||||
*uint_ptr = STATS_GET(mib2.icmpinparmprobs);
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 6: /* icmpInSrcQuenchs */
|
||||
*uint_ptr = STATS_GET(mib2.icmpinsrcquenchs);
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 7: /* icmpInRedirects */
|
||||
*uint_ptr = STATS_GET(mib2.icmpinredirects);
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 8: /* icmpInEchos */
|
||||
*uint_ptr = STATS_GET(mib2.icmpinechos);
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 9: /* icmpInEchoReps */
|
||||
*uint_ptr = STATS_GET(mib2.icmpinechoreps);
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 10: /* icmpInTimestamps */
|
||||
*uint_ptr = STATS_GET(mib2.icmpintimestamps);
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 11: /* icmpInTimestampReps */
|
||||
*uint_ptr = STATS_GET(mib2.icmpintimestampreps);
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 12: /* icmpInAddrMasks */
|
||||
*uint_ptr = STATS_GET(mib2.icmpinaddrmasks);
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 13: /* icmpInAddrMaskReps */
|
||||
*uint_ptr = STATS_GET(mib2.icmpinaddrmaskreps);
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 14: /* icmpOutMsgs */
|
||||
*uint_ptr = STATS_GET(mib2.icmpoutmsgs);
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 15: /* icmpOutErrors */
|
||||
*uint_ptr = STATS_GET(mib2.icmpouterrors);
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 16: /* icmpOutDestUnreachs */
|
||||
*uint_ptr = STATS_GET(mib2.icmpoutdestunreachs);
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 17: /* icmpOutTimeExcds */
|
||||
*uint_ptr = STATS_GET(mib2.icmpouttimeexcds);
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 18: /* icmpOutParmProbs: not supported -> always 0 */
|
||||
*uint_ptr = 0;
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 19: /* icmpOutSrcQuenchs: not supported -> always 0 */
|
||||
*uint_ptr = 0;
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 20: /* icmpOutRedirects: not supported -> always 0 */
|
||||
*uint_ptr = 0;
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 21: /* icmpOutEchos */
|
||||
*uint_ptr = STATS_GET(mib2.icmpoutechos);
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 22: /* icmpOutEchoReps */
|
||||
*uint_ptr = STATS_GET(mib2.icmpoutechoreps);
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 23: /* icmpOutTimestamps: not supported -> always 0 */
|
||||
*uint_ptr = 0;
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 24: /* icmpOutTimestampReps: not supported -> always 0 */
|
||||
*uint_ptr = 0;
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 25: /* icmpOutAddrMasks: not supported -> always 0 */
|
||||
*uint_ptr = 0;
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 26: /* icmpOutAddrMaskReps: not supported -> always 0 */
|
||||
*uint_ptr = 0;
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
default:
|
||||
LWIP_DEBUGF(SNMP_MIB_DEBUG, ("icmp_get_value(): unknown id: %" S32_F "\n", node->oid));
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static const struct snmp_scalar_array_node_def icmp_nodes[] = {
|
||||
{ 1, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY },
|
||||
{ 2, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY },
|
||||
{ 3, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY },
|
||||
{ 4, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY },
|
||||
{ 5, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY },
|
||||
{ 6, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY },
|
||||
{ 7, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY },
|
||||
{ 8, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY },
|
||||
{ 9, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY },
|
||||
{ 10, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY },
|
||||
{ 11, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY },
|
||||
{ 12, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY },
|
||||
{ 13, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY },
|
||||
{ 14, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY },
|
||||
{ 15, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY },
|
||||
{ 16, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY },
|
||||
{ 17, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY },
|
||||
{ 18, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY },
|
||||
{ 19, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY },
|
||||
{ 20, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY },
|
||||
{ 21, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY },
|
||||
{ 22, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY },
|
||||
{ 23, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY },
|
||||
{ 24, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY },
|
||||
{ 25, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY },
|
||||
{ 26, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }
|
||||
{ 1, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
|
||||
{ 2, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
|
||||
{ 3, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
|
||||
{ 4, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
|
||||
{ 5, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
|
||||
{ 6, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
|
||||
{ 7, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
|
||||
{ 8, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
|
||||
{ 9, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
|
||||
{10, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
|
||||
{11, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
|
||||
{12, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
|
||||
{13, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
|
||||
{14, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
|
||||
{15, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
|
||||
{16, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
|
||||
{17, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
|
||||
{18, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
|
||||
{19, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
|
||||
{20, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
|
||||
{21, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
|
||||
{22, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
|
||||
{23, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
|
||||
{24, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
|
||||
{25, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY},
|
||||
{26, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}
|
||||
};
|
||||
|
||||
const struct snmp_scalar_array_node snmp_mib2_icmp_root = SNMP_SCALAR_CREATE_ARRAY_NODE(5, icmp_nodes, icmp_get_value, NULL, NULL);
|
||||
|
@ -47,286 +47,266 @@
|
||||
#if LWIP_SNMP && SNMP_LWIP_MIB2
|
||||
|
||||
#if SNMP_USE_NETCONN
|
||||
#define SYNC_NODE_NAME(node_name) node_name##_synced
|
||||
#define SYNC_NODE_NAME(node_name) node_name ## _synced
|
||||
#define CREATE_LWIP_SYNC_NODE(oid, node_name) \
|
||||
static const struct snmp_threadsync_node node_name##_synced = SNMP_CREATE_THREAD_SYNC_NODE(oid, &node_name.node, &snmp_mib2_lwip_locks);
|
||||
static const struct snmp_threadsync_node node_name ## _synced = SNMP_CREATE_THREAD_SYNC_NODE(oid, &node_name.node, &snmp_mib2_lwip_locks);
|
||||
#else
|
||||
#define SYNC_NODE_NAME(node_name) node_name
|
||||
#define CREATE_LWIP_SYNC_NODE(oid, node_name)
|
||||
#endif
|
||||
|
||||
|
||||
/* --- interfaces .1.3.6.1.2.1.2 ----------------------------------------------------- */
|
||||
|
||||
static s16_t interfaces_get_value(struct snmp_node_instance *instance, void *value)
|
||||
static s16_t
|
||||
interfaces_get_value(struct snmp_node_instance *instance, void *value)
|
||||
{
|
||||
if (instance->node->oid == 1) {
|
||||
s32_t *sint_ptr = (s32_t *)value;
|
||||
s32_t num_netifs = 0;
|
||||
if (instance->node->oid == 1) {
|
||||
s32_t *sint_ptr = (s32_t *)value;
|
||||
s32_t num_netifs = 0;
|
||||
|
||||
struct netif *netif;
|
||||
NETIF_FOREACH(netif)
|
||||
{
|
||||
num_netifs++;
|
||||
}
|
||||
|
||||
*sint_ptr = num_netifs;
|
||||
return sizeof(*sint_ptr);
|
||||
struct netif *netif;
|
||||
NETIF_FOREACH(netif) {
|
||||
num_netifs++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
*sint_ptr = num_netifs;
|
||||
return sizeof(*sint_ptr);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* list of allowed value ranges for incoming OID */
|
||||
static const struct snmp_oid_range interfaces_Table_oid_ranges[] = {
|
||||
{ 1, 0xff } /* netif->num is u8_t */
|
||||
{ 1, 0xff } /* netif->num is u8_t */
|
||||
};
|
||||
|
||||
static const u8_t iftable_ifOutQLen = 0;
|
||||
static const u8_t iftable_ifOutQLen = 0;
|
||||
|
||||
static const u8_t iftable_ifOperStatus_up = 1;
|
||||
static const u8_t iftable_ifOperStatus_up = 1;
|
||||
static const u8_t iftable_ifOperStatus_down = 2;
|
||||
|
||||
static const u8_t iftable_ifAdminStatus_up = 1;
|
||||
static const u8_t iftable_ifAdminStatus_up = 1;
|
||||
static const u8_t iftable_ifAdminStatus_lowerLayerDown = 7;
|
||||
static const u8_t iftable_ifAdminStatus_down = 2;
|
||||
static const u8_t iftable_ifAdminStatus_down = 2;
|
||||
|
||||
static snmp_err_t interfaces_Table_get_cell_instance(const u32_t *column, const u32_t *row_oid, u8_t row_oid_len, struct snmp_node_instance *cell_instance)
|
||||
static snmp_err_t
|
||||
interfaces_Table_get_cell_instance(const u32_t *column, const u32_t *row_oid, u8_t row_oid_len, struct snmp_node_instance *cell_instance)
|
||||
{
|
||||
u32_t ifIndex;
|
||||
struct netif *netif;
|
||||
u32_t ifIndex;
|
||||
struct netif *netif;
|
||||
|
||||
LWIP_UNUSED_ARG(column);
|
||||
LWIP_UNUSED_ARG(column);
|
||||
|
||||
/* check if incoming OID length and if values are in plausible range */
|
||||
if (!snmp_oid_in_range(row_oid, row_oid_len, interfaces_Table_oid_ranges, LWIP_ARRAYSIZE(interfaces_Table_oid_ranges))) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
/* check if incoming OID length and if values are in plausible range */
|
||||
if (!snmp_oid_in_range(row_oid, row_oid_len, interfaces_Table_oid_ranges, LWIP_ARRAYSIZE(interfaces_Table_oid_ranges))) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
/* get netif index from incoming OID */
|
||||
ifIndex = row_oid[0];
|
||||
|
||||
/* find netif with index */
|
||||
NETIF_FOREACH(netif) {
|
||||
if (netif_to_num(netif) == ifIndex) {
|
||||
/* store netif pointer for subsequent operations (get/test/set) */
|
||||
cell_instance->reference.ptr = netif;
|
||||
return SNMP_ERR_NOERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/* get netif index from incoming OID */
|
||||
ifIndex = row_oid[0];
|
||||
/* not found */
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
/* find netif with index */
|
||||
NETIF_FOREACH(netif)
|
||||
{
|
||||
if (netif_to_num(netif) == ifIndex) {
|
||||
/* store netif pointer for subsequent operations (get/test/set) */
|
||||
cell_instance->reference.ptr = netif;
|
||||
return SNMP_ERR_NOERROR;
|
||||
static snmp_err_t
|
||||
interfaces_Table_get_next_cell_instance(const u32_t *column, struct snmp_obj_id *row_oid, struct snmp_node_instance *cell_instance)
|
||||
{
|
||||
struct netif *netif;
|
||||
struct snmp_next_oid_state state;
|
||||
u32_t result_temp[LWIP_ARRAYSIZE(interfaces_Table_oid_ranges)];
|
||||
|
||||
LWIP_UNUSED_ARG(column);
|
||||
|
||||
/* init struct to search next oid */
|
||||
snmp_next_oid_init(&state, row_oid->id, row_oid->len, result_temp, LWIP_ARRAYSIZE(interfaces_Table_oid_ranges));
|
||||
|
||||
/* iterate over all possible OIDs to find the next one */
|
||||
NETIF_FOREACH(netif) {
|
||||
u32_t test_oid[LWIP_ARRAYSIZE(interfaces_Table_oid_ranges)];
|
||||
test_oid[0] = netif_to_num(netif);
|
||||
|
||||
/* check generated OID: is it a candidate for the next one? */
|
||||
snmp_next_oid_check(&state, test_oid, LWIP_ARRAYSIZE(interfaces_Table_oid_ranges), netif);
|
||||
}
|
||||
|
||||
/* did we find a next one? */
|
||||
if (state.status == SNMP_NEXT_OID_STATUS_SUCCESS) {
|
||||
snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len);
|
||||
/* store netif pointer for subsequent operations (get/test/set) */
|
||||
cell_instance->reference.ptr = /* (struct netif*) */state.reference;
|
||||
return SNMP_ERR_NOERROR;
|
||||
}
|
||||
|
||||
/* not found */
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
static s16_t
|
||||
interfaces_Table_get_value(struct snmp_node_instance *instance, void *value)
|
||||
{
|
||||
struct netif *netif = (struct netif *)instance->reference.ptr;
|
||||
u32_t *value_u32 = (u32_t *)value;
|
||||
s32_t *value_s32 = (s32_t *)value;
|
||||
u16_t value_len;
|
||||
|
||||
switch (SNMP_TABLE_GET_COLUMN_FROM_OID(instance->instance_oid.id)) {
|
||||
case 1: /* ifIndex */
|
||||
*value_s32 = netif_to_num(netif);
|
||||
value_len = sizeof(*value_s32);
|
||||
break;
|
||||
case 2: /* ifDescr */
|
||||
value_len = sizeof(netif->name);
|
||||
MEMCPY(value, netif->name, value_len);
|
||||
break;
|
||||
case 3: /* ifType */
|
||||
*value_s32 = netif->link_type;
|
||||
value_len = sizeof(*value_s32);
|
||||
break;
|
||||
case 4: /* ifMtu */
|
||||
*value_s32 = netif->mtu;
|
||||
value_len = sizeof(*value_s32);
|
||||
break;
|
||||
case 5: /* ifSpeed */
|
||||
*value_u32 = netif->link_speed;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
case 6: /* ifPhysAddress */
|
||||
value_len = sizeof(netif->hwaddr);
|
||||
MEMCPY(value, &netif->hwaddr, value_len);
|
||||
break;
|
||||
case 7: /* ifAdminStatus */
|
||||
if (netif_is_up(netif)) {
|
||||
*value_s32 = iftable_ifOperStatus_up;
|
||||
} else {
|
||||
*value_s32 = iftable_ifOperStatus_down;
|
||||
}
|
||||
value_len = sizeof(*value_s32);
|
||||
break;
|
||||
case 8: /* ifOperStatus */
|
||||
if (netif_is_up(netif)) {
|
||||
if (netif_is_link_up(netif)) {
|
||||
*value_s32 = iftable_ifAdminStatus_up;
|
||||
} else {
|
||||
*value_s32 = iftable_ifAdminStatus_lowerLayerDown;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
*value_s32 = iftable_ifAdminStatus_down;
|
||||
}
|
||||
value_len = sizeof(*value_s32);
|
||||
break;
|
||||
case 9: /* ifLastChange */
|
||||
*value_u32 = netif->ts;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
case 10: /* ifInOctets */
|
||||
*value_u32 = netif->mib2_counters.ifinoctets;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
case 11: /* ifInUcastPkts */
|
||||
*value_u32 = netif->mib2_counters.ifinucastpkts;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
case 12: /* ifInNUcastPkts */
|
||||
*value_u32 = netif->mib2_counters.ifinnucastpkts;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
case 13: /* ifInDiscards */
|
||||
*value_u32 = netif->mib2_counters.ifindiscards;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
case 14: /* ifInErrors */
|
||||
*value_u32 = netif->mib2_counters.ifinerrors;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
case 15: /* ifInUnkownProtos */
|
||||
*value_u32 = netif->mib2_counters.ifinunknownprotos;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
case 16: /* ifOutOctets */
|
||||
*value_u32 = netif->mib2_counters.ifoutoctets;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
case 17: /* ifOutUcastPkts */
|
||||
*value_u32 = netif->mib2_counters.ifoutucastpkts;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
case 18: /* ifOutNUcastPkts */
|
||||
*value_u32 = netif->mib2_counters.ifoutnucastpkts;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
case 19: /* ifOutDiscarts */
|
||||
*value_u32 = netif->mib2_counters.ifoutdiscards;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
case 20: /* ifOutErrors */
|
||||
*value_u32 = netif->mib2_counters.ifouterrors;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
case 21: /* ifOutQLen */
|
||||
*value_u32 = iftable_ifOutQLen;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
/** @note returning zeroDotZero (0.0) no media specific MIB support */
|
||||
case 22: /* ifSpecific */
|
||||
value_len = snmp_zero_dot_zero.len * sizeof(u32_t);
|
||||
MEMCPY(value, snmp_zero_dot_zero.id, value_len);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* not found */
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
static snmp_err_t interfaces_Table_get_next_cell_instance(const u32_t *column, struct snmp_obj_id *row_oid, struct snmp_node_instance *cell_instance)
|
||||
{
|
||||
struct netif *netif;
|
||||
struct snmp_next_oid_state state;
|
||||
u32_t result_temp[LWIP_ARRAYSIZE(interfaces_Table_oid_ranges)];
|
||||
|
||||
LWIP_UNUSED_ARG(column);
|
||||
|
||||
/* init struct to search next oid */
|
||||
snmp_next_oid_init(&state, row_oid->id, row_oid->len, result_temp, LWIP_ARRAYSIZE(interfaces_Table_oid_ranges));
|
||||
|
||||
/* iterate over all possible OIDs to find the next one */
|
||||
NETIF_FOREACH(netif)
|
||||
{
|
||||
u32_t test_oid[LWIP_ARRAYSIZE(interfaces_Table_oid_ranges)];
|
||||
test_oid[0] = netif_to_num(netif);
|
||||
|
||||
/* check generated OID: is it a candidate for the next one? */
|
||||
snmp_next_oid_check(&state, test_oid, LWIP_ARRAYSIZE(interfaces_Table_oid_ranges), netif);
|
||||
}
|
||||
|
||||
/* did we find a next one? */
|
||||
if (state.status == SNMP_NEXT_OID_STATUS_SUCCESS) {
|
||||
snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len);
|
||||
/* store netif pointer for subsequent operations (get/test/set) */
|
||||
cell_instance->reference.ptr = /* (struct netif*) */ state.reference;
|
||||
return SNMP_ERR_NOERROR;
|
||||
}
|
||||
|
||||
/* not found */
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
static s16_t interfaces_Table_get_value(struct snmp_node_instance *instance, void *value)
|
||||
{
|
||||
struct netif *netif = (struct netif *)instance->reference.ptr;
|
||||
u32_t *value_u32 = (u32_t *)value;
|
||||
s32_t *value_s32 = (s32_t *)value;
|
||||
u16_t value_len;
|
||||
|
||||
switch (SNMP_TABLE_GET_COLUMN_FROM_OID(instance->instance_oid.id)) {
|
||||
case 1: /* ifIndex */
|
||||
*value_s32 = netif_to_num(netif);
|
||||
value_len = sizeof(*value_s32);
|
||||
break;
|
||||
|
||||
case 2: /* ifDescr */
|
||||
value_len = sizeof(netif->name);
|
||||
MEMCPY(value, netif->name, value_len);
|
||||
break;
|
||||
|
||||
case 3: /* ifType */
|
||||
*value_s32 = netif->link_type;
|
||||
value_len = sizeof(*value_s32);
|
||||
break;
|
||||
|
||||
case 4: /* ifMtu */
|
||||
*value_s32 = netif->mtu;
|
||||
value_len = sizeof(*value_s32);
|
||||
break;
|
||||
|
||||
case 5: /* ifSpeed */
|
||||
*value_u32 = netif->link_speed;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
|
||||
case 6: /* ifPhysAddress */
|
||||
value_len = sizeof(netif->hwaddr);
|
||||
MEMCPY(value, &netif->hwaddr, value_len);
|
||||
break;
|
||||
|
||||
case 7: /* ifAdminStatus */
|
||||
if (netif_is_up(netif)) {
|
||||
*value_s32 = iftable_ifOperStatus_up;
|
||||
} else {
|
||||
*value_s32 = iftable_ifOperStatus_down;
|
||||
}
|
||||
|
||||
value_len = sizeof(*value_s32);
|
||||
break;
|
||||
|
||||
case 8: /* ifOperStatus */
|
||||
if (netif_is_up(netif)) {
|
||||
if (netif_is_link_up(netif)) {
|
||||
*value_s32 = iftable_ifAdminStatus_up;
|
||||
} else {
|
||||
*value_s32 = iftable_ifAdminStatus_lowerLayerDown;
|
||||
}
|
||||
} else {
|
||||
*value_s32 = iftable_ifAdminStatus_down;
|
||||
}
|
||||
|
||||
value_len = sizeof(*value_s32);
|
||||
break;
|
||||
|
||||
case 9: /* ifLastChange */
|
||||
*value_u32 = netif->ts;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
|
||||
case 10: /* ifInOctets */
|
||||
*value_u32 = netif->mib2_counters.ifinoctets;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
|
||||
case 11: /* ifInUcastPkts */
|
||||
*value_u32 = netif->mib2_counters.ifinucastpkts;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
|
||||
case 12: /* ifInNUcastPkts */
|
||||
*value_u32 = netif->mib2_counters.ifinnucastpkts;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
|
||||
case 13: /* ifInDiscards */
|
||||
*value_u32 = netif->mib2_counters.ifindiscards;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
|
||||
case 14: /* ifInErrors */
|
||||
*value_u32 = netif->mib2_counters.ifinerrors;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
|
||||
case 15: /* ifInUnkownProtos */
|
||||
*value_u32 = netif->mib2_counters.ifinunknownprotos;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
|
||||
case 16: /* ifOutOctets */
|
||||
*value_u32 = netif->mib2_counters.ifoutoctets;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
|
||||
case 17: /* ifOutUcastPkts */
|
||||
*value_u32 = netif->mib2_counters.ifoutucastpkts;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
|
||||
case 18: /* ifOutNUcastPkts */
|
||||
*value_u32 = netif->mib2_counters.ifoutnucastpkts;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
|
||||
case 19: /* ifOutDiscarts */
|
||||
*value_u32 = netif->mib2_counters.ifoutdiscards;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
|
||||
case 20: /* ifOutErrors */
|
||||
*value_u32 = netif->mib2_counters.ifouterrors;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
|
||||
case 21: /* ifOutQLen */
|
||||
*value_u32 = iftable_ifOutQLen;
|
||||
value_len = sizeof(*value_u32);
|
||||
break;
|
||||
|
||||
/** @note returning zeroDotZero (0.0) no media specific MIB support */
|
||||
case 22: /* ifSpecific */
|
||||
value_len = snmp_zero_dot_zero.len * sizeof(u32_t);
|
||||
MEMCPY(value, snmp_zero_dot_zero.id, value_len);
|
||||
break;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return value_len;
|
||||
return value_len;
|
||||
}
|
||||
|
||||
#if !SNMP_SAFE_REQUESTS
|
||||
|
||||
static snmp_err_t interfaces_Table_set_test(struct snmp_node_instance *instance, u16_t len, void *value)
|
||||
static snmp_err_t
|
||||
interfaces_Table_set_test(struct snmp_node_instance *instance, u16_t len, void *value)
|
||||
{
|
||||
s32_t *sint_ptr = (s32_t *)value;
|
||||
s32_t *sint_ptr = (s32_t *)value;
|
||||
|
||||
/* stack should never call this method for another column,
|
||||
because all other columns are set to readonly */
|
||||
LWIP_ASSERT("Invalid column", (SNMP_TABLE_GET_COLUMN_FROM_OID(instance->instance_oid.id) == 7));
|
||||
LWIP_UNUSED_ARG(len);
|
||||
/* stack should never call this method for another column,
|
||||
because all other columns are set to readonly */
|
||||
LWIP_ASSERT("Invalid column", (SNMP_TABLE_GET_COLUMN_FROM_OID(instance->instance_oid.id) == 7));
|
||||
LWIP_UNUSED_ARG(len);
|
||||
|
||||
if (*sint_ptr == 1 || *sint_ptr == 2) {
|
||||
return SNMP_ERR_NOERROR;
|
||||
}
|
||||
if (*sint_ptr == 1 || *sint_ptr == 2) {
|
||||
return SNMP_ERR_NOERROR;
|
||||
}
|
||||
|
||||
return SNMP_ERR_WRONGVALUE;
|
||||
return SNMP_ERR_WRONGVALUE;
|
||||
}
|
||||
|
||||
static snmp_err_t interfaces_Table_set_value(struct snmp_node_instance *instance, u16_t len, void *value)
|
||||
static snmp_err_t
|
||||
interfaces_Table_set_value(struct snmp_node_instance *instance, u16_t len, void *value)
|
||||
{
|
||||
struct netif *netif = (struct netif *)instance->reference.ptr;
|
||||
s32_t *sint_ptr = (s32_t *)value;
|
||||
struct netif *netif = (struct netif *)instance->reference.ptr;
|
||||
s32_t *sint_ptr = (s32_t *)value;
|
||||
|
||||
/* stack should never call this method for another column,
|
||||
because all other columns are set to readonly */
|
||||
LWIP_ASSERT("Invalid column", (SNMP_TABLE_GET_COLUMN_FROM_OID(instance->instance_oid.id) == 7));
|
||||
LWIP_UNUSED_ARG(len);
|
||||
/* stack should never call this method for another column,
|
||||
because all other columns are set to readonly */
|
||||
LWIP_ASSERT("Invalid column", (SNMP_TABLE_GET_COLUMN_FROM_OID(instance->instance_oid.id) == 7));
|
||||
LWIP_UNUSED_ARG(len);
|
||||
|
||||
if (*sint_ptr == 1) {
|
||||
netif_set_up(netif);
|
||||
} else if (*sint_ptr == 2) {
|
||||
netif_set_down(netif);
|
||||
}
|
||||
if (*sint_ptr == 1) {
|
||||
netif_set_up(netif);
|
||||
} else if (*sint_ptr == 2) {
|
||||
netif_set_down(netif);
|
||||
}
|
||||
|
||||
return SNMP_ERR_NOERROR;
|
||||
return SNMP_ERR_NOERROR;
|
||||
}
|
||||
|
||||
#endif /* SNMP_SAFE_REQUESTS */
|
||||
@ -334,44 +314,44 @@ static snmp_err_t interfaces_Table_set_value(struct snmp_node_instance *instance
|
||||
static const struct snmp_scalar_node interfaces_Number = SNMP_SCALAR_CREATE_NODE_READONLY(1, SNMP_ASN1_TYPE_INTEGER, interfaces_get_value);
|
||||
|
||||
static const struct snmp_table_col_def interfaces_Table_columns[] = {
|
||||
{ 1, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifIndex */
|
||||
{ 2, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifDescr */
|
||||
{ 3, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifType */
|
||||
{ 4, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifMtu */
|
||||
{ 5, SNMP_ASN1_TYPE_GAUGE, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifSpeed */
|
||||
{ 6, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifPhysAddress */
|
||||
{ 1, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifIndex */
|
||||
{ 2, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifDescr */
|
||||
{ 3, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifType */
|
||||
{ 4, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifMtu */
|
||||
{ 5, SNMP_ASN1_TYPE_GAUGE, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifSpeed */
|
||||
{ 6, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifPhysAddress */
|
||||
#if !SNMP_SAFE_REQUESTS
|
||||
{ 7, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_WRITE }, /* ifAdminStatus */
|
||||
{ 7, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_WRITE }, /* ifAdminStatus */
|
||||
#else
|
||||
{ 7, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifAdminStatus */
|
||||
{ 7, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifAdminStatus */
|
||||
#endif
|
||||
{ 8, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifOperStatus */
|
||||
{ 9, SNMP_ASN1_TYPE_TIMETICKS, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifLastChange */
|
||||
{ 10, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifInOctets */
|
||||
{ 11, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifInUcastPkts */
|
||||
{ 12, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifInNUcastPkts */
|
||||
{ 13, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifInDiscarts */
|
||||
{ 14, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifInErrors */
|
||||
{ 15, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifInUnkownProtos */
|
||||
{ 16, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifOutOctets */
|
||||
{ 17, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifOutUcastPkts */
|
||||
{ 18, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifOutNUcastPkts */
|
||||
{ 19, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifOutDiscarts */
|
||||
{ 20, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifOutErrors */
|
||||
{ 21, SNMP_ASN1_TYPE_GAUGE, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifOutQLen */
|
||||
{ 22, SNMP_ASN1_TYPE_OBJECT_ID, SNMP_NODE_INSTANCE_READ_ONLY } /* ifSpecific */
|
||||
{ 8, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifOperStatus */
|
||||
{ 9, SNMP_ASN1_TYPE_TIMETICKS, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifLastChange */
|
||||
{ 10, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifInOctets */
|
||||
{ 11, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifInUcastPkts */
|
||||
{ 12, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifInNUcastPkts */
|
||||
{ 13, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifInDiscarts */
|
||||
{ 14, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifInErrors */
|
||||
{ 15, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifInUnkownProtos */
|
||||
{ 16, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifOutOctets */
|
||||
{ 17, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifOutUcastPkts */
|
||||
{ 18, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifOutNUcastPkts */
|
||||
{ 19, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifOutDiscarts */
|
||||
{ 20, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifOutErrors */
|
||||
{ 21, SNMP_ASN1_TYPE_GAUGE, SNMP_NODE_INSTANCE_READ_ONLY }, /* ifOutQLen */
|
||||
{ 22, SNMP_ASN1_TYPE_OBJECT_ID, SNMP_NODE_INSTANCE_READ_ONLY } /* ifSpecific */
|
||||
};
|
||||
|
||||
#if !SNMP_SAFE_REQUESTS
|
||||
static const struct snmp_table_node interfaces_Table = SNMP_TABLE_CREATE(
|
||||
2, interfaces_Table_columns,
|
||||
interfaces_Table_get_cell_instance, interfaces_Table_get_next_cell_instance,
|
||||
interfaces_Table_get_value, interfaces_Table_set_test, interfaces_Table_set_value);
|
||||
2, interfaces_Table_columns,
|
||||
interfaces_Table_get_cell_instance, interfaces_Table_get_next_cell_instance,
|
||||
interfaces_Table_get_value, interfaces_Table_set_test, interfaces_Table_set_value);
|
||||
#else
|
||||
static const struct snmp_table_node interfaces_Table = SNMP_TABLE_CREATE(
|
||||
2, interfaces_Table_columns,
|
||||
interfaces_Table_get_cell_instance, interfaces_Table_get_next_cell_instance,
|
||||
interfaces_Table_get_value, NULL, NULL);
|
||||
2, interfaces_Table_columns,
|
||||
interfaces_Table_get_cell_instance, interfaces_Table_get_next_cell_instance,
|
||||
interfaces_Table_get_value, NULL, NULL);
|
||||
#endif
|
||||
|
||||
/* the following nodes access variables in LWIP stack from SNMP worker thread and must therefore be synced to LWIP (TCPIP) thread */
|
||||
@ -379,8 +359,8 @@ CREATE_LWIP_SYNC_NODE(1, interfaces_Number)
|
||||
CREATE_LWIP_SYNC_NODE(2, interfaces_Table)
|
||||
|
||||
static const struct snmp_node *const interface_nodes[] = {
|
||||
&SYNC_NODE_NAME(interfaces_Number).node.node,
|
||||
&SYNC_NODE_NAME(interfaces_Table).node.node
|
||||
&SYNC_NODE_NAME(interfaces_Number).node.node,
|
||||
&SYNC_NODE_NAME(interfaces_Table).node.node
|
||||
};
|
||||
|
||||
const struct snmp_tree_node snmp_mib2_interface_root = SNMP_CREATE_TREE_NODE(2, interface_nodes);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -45,212 +45,181 @@
|
||||
#define MIB2_AUTH_TRAPS_DISABLED 2
|
||||
|
||||
/* --- snmp .1.3.6.1.2.1.11 ----------------------------------------------------- */
|
||||
static s16_t snmp_get_value(const struct snmp_scalar_array_node_def *node, void *value)
|
||||
static s16_t
|
||||
snmp_get_value(const struct snmp_scalar_array_node_def *node, void *value)
|
||||
{
|
||||
u32_t *uint_ptr = (u32_t *)value;
|
||||
u32_t *uint_ptr = (u32_t *)value;
|
||||
switch (node->oid) {
|
||||
case 1: /* snmpInPkts */
|
||||
*uint_ptr = snmp_stats.inpkts;
|
||||
break;
|
||||
case 2: /* snmpOutPkts */
|
||||
*uint_ptr = snmp_stats.outpkts;
|
||||
break;
|
||||
case 3: /* snmpInBadVersions */
|
||||
*uint_ptr = snmp_stats.inbadversions;
|
||||
break;
|
||||
case 4: /* snmpInBadCommunityNames */
|
||||
*uint_ptr = snmp_stats.inbadcommunitynames;
|
||||
break;
|
||||
case 5: /* snmpInBadCommunityUses */
|
||||
*uint_ptr = snmp_stats.inbadcommunityuses;
|
||||
break;
|
||||
case 6: /* snmpInASNParseErrs */
|
||||
*uint_ptr = snmp_stats.inasnparseerrs;
|
||||
break;
|
||||
case 8: /* snmpInTooBigs */
|
||||
*uint_ptr = snmp_stats.intoobigs;
|
||||
break;
|
||||
case 9: /* snmpInNoSuchNames */
|
||||
*uint_ptr = snmp_stats.innosuchnames;
|
||||
break;
|
||||
case 10: /* snmpInBadValues */
|
||||
*uint_ptr = snmp_stats.inbadvalues;
|
||||
break;
|
||||
case 11: /* snmpInReadOnlys */
|
||||
*uint_ptr = snmp_stats.inreadonlys;
|
||||
break;
|
||||
case 12: /* snmpInGenErrs */
|
||||
*uint_ptr = snmp_stats.ingenerrs;
|
||||
break;
|
||||
case 13: /* snmpInTotalReqVars */
|
||||
*uint_ptr = snmp_stats.intotalreqvars;
|
||||
break;
|
||||
case 14: /* snmpInTotalSetVars */
|
||||
*uint_ptr = snmp_stats.intotalsetvars;
|
||||
break;
|
||||
case 15: /* snmpInGetRequests */
|
||||
*uint_ptr = snmp_stats.ingetrequests;
|
||||
break;
|
||||
case 16: /* snmpInGetNexts */
|
||||
*uint_ptr = snmp_stats.ingetnexts;
|
||||
break;
|
||||
case 17: /* snmpInSetRequests */
|
||||
*uint_ptr = snmp_stats.insetrequests;
|
||||
break;
|
||||
case 18: /* snmpInGetResponses */
|
||||
*uint_ptr = snmp_stats.ingetresponses;
|
||||
break;
|
||||
case 19: /* snmpInTraps */
|
||||
*uint_ptr = snmp_stats.intraps;
|
||||
break;
|
||||
case 20: /* snmpOutTooBigs */
|
||||
*uint_ptr = snmp_stats.outtoobigs;
|
||||
break;
|
||||
case 21: /* snmpOutNoSuchNames */
|
||||
*uint_ptr = snmp_stats.outnosuchnames;
|
||||
break;
|
||||
case 22: /* snmpOutBadValues */
|
||||
*uint_ptr = snmp_stats.outbadvalues;
|
||||
break;
|
||||
case 24: /* snmpOutGenErrs */
|
||||
*uint_ptr = snmp_stats.outgenerrs;
|
||||
break;
|
||||
case 25: /* snmpOutGetRequests */
|
||||
*uint_ptr = snmp_stats.outgetrequests;
|
||||
break;
|
||||
case 26: /* snmpOutGetNexts */
|
||||
*uint_ptr = snmp_stats.outgetnexts;
|
||||
break;
|
||||
case 27: /* snmpOutSetRequests */
|
||||
*uint_ptr = snmp_stats.outsetrequests;
|
||||
break;
|
||||
case 28: /* snmpOutGetResponses */
|
||||
*uint_ptr = snmp_stats.outgetresponses;
|
||||
break;
|
||||
case 29: /* snmpOutTraps */
|
||||
*uint_ptr = snmp_stats.outtraps;
|
||||
break;
|
||||
case 30: /* snmpEnableAuthenTraps */
|
||||
if (snmp_get_auth_traps_enabled() == SNMP_AUTH_TRAPS_DISABLED) {
|
||||
*uint_ptr = MIB2_AUTH_TRAPS_DISABLED;
|
||||
} else {
|
||||
*uint_ptr = MIB2_AUTH_TRAPS_ENABLED;
|
||||
}
|
||||
break;
|
||||
case 31: /* snmpSilentDrops */
|
||||
*uint_ptr = 0; /* not supported */
|
||||
break;
|
||||
case 32: /* snmpProxyDrops */
|
||||
*uint_ptr = 0; /* not supported */
|
||||
break;
|
||||
default:
|
||||
LWIP_DEBUGF(SNMP_MIB_DEBUG, ("snmp_get_value(): unknown id: %"S32_F"\n", node->oid));
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (node->oid) {
|
||||
case 1: /* snmpInPkts */
|
||||
*uint_ptr = snmp_stats.inpkts;
|
||||
break;
|
||||
|
||||
case 2: /* snmpOutPkts */
|
||||
*uint_ptr = snmp_stats.outpkts;
|
||||
break;
|
||||
|
||||
case 3: /* snmpInBadVersions */
|
||||
*uint_ptr = snmp_stats.inbadversions;
|
||||
break;
|
||||
|
||||
case 4: /* snmpInBadCommunityNames */
|
||||
*uint_ptr = snmp_stats.inbadcommunitynames;
|
||||
break;
|
||||
|
||||
case 5: /* snmpInBadCommunityUses */
|
||||
*uint_ptr = snmp_stats.inbadcommunityuses;
|
||||
break;
|
||||
|
||||
case 6: /* snmpInASNParseErrs */
|
||||
*uint_ptr = snmp_stats.inasnparseerrs;
|
||||
break;
|
||||
|
||||
case 8: /* snmpInTooBigs */
|
||||
*uint_ptr = snmp_stats.intoobigs;
|
||||
break;
|
||||
|
||||
case 9: /* snmpInNoSuchNames */
|
||||
*uint_ptr = snmp_stats.innosuchnames;
|
||||
break;
|
||||
|
||||
case 10: /* snmpInBadValues */
|
||||
*uint_ptr = snmp_stats.inbadvalues;
|
||||
break;
|
||||
|
||||
case 11: /* snmpInReadOnlys */
|
||||
*uint_ptr = snmp_stats.inreadonlys;
|
||||
break;
|
||||
|
||||
case 12: /* snmpInGenErrs */
|
||||
*uint_ptr = snmp_stats.ingenerrs;
|
||||
break;
|
||||
|
||||
case 13: /* snmpInTotalReqVars */
|
||||
*uint_ptr = snmp_stats.intotalreqvars;
|
||||
break;
|
||||
|
||||
case 14: /* snmpInTotalSetVars */
|
||||
*uint_ptr = snmp_stats.intotalsetvars;
|
||||
break;
|
||||
|
||||
case 15: /* snmpInGetRequests */
|
||||
*uint_ptr = snmp_stats.ingetrequests;
|
||||
break;
|
||||
|
||||
case 16: /* snmpInGetNexts */
|
||||
*uint_ptr = snmp_stats.ingetnexts;
|
||||
break;
|
||||
|
||||
case 17: /* snmpInSetRequests */
|
||||
*uint_ptr = snmp_stats.insetrequests;
|
||||
break;
|
||||
|
||||
case 18: /* snmpInGetResponses */
|
||||
*uint_ptr = snmp_stats.ingetresponses;
|
||||
break;
|
||||
|
||||
case 19: /* snmpInTraps */
|
||||
*uint_ptr = snmp_stats.intraps;
|
||||
break;
|
||||
|
||||
case 20: /* snmpOutTooBigs */
|
||||
*uint_ptr = snmp_stats.outtoobigs;
|
||||
break;
|
||||
|
||||
case 21: /* snmpOutNoSuchNames */
|
||||
*uint_ptr = snmp_stats.outnosuchnames;
|
||||
break;
|
||||
|
||||
case 22: /* snmpOutBadValues */
|
||||
*uint_ptr = snmp_stats.outbadvalues;
|
||||
break;
|
||||
|
||||
case 24: /* snmpOutGenErrs */
|
||||
*uint_ptr = snmp_stats.outgenerrs;
|
||||
break;
|
||||
|
||||
case 25: /* snmpOutGetRequests */
|
||||
*uint_ptr = snmp_stats.outgetrequests;
|
||||
break;
|
||||
|
||||
case 26: /* snmpOutGetNexts */
|
||||
*uint_ptr = snmp_stats.outgetnexts;
|
||||
break;
|
||||
|
||||
case 27: /* snmpOutSetRequests */
|
||||
*uint_ptr = snmp_stats.outsetrequests;
|
||||
break;
|
||||
|
||||
case 28: /* snmpOutGetResponses */
|
||||
*uint_ptr = snmp_stats.outgetresponses;
|
||||
break;
|
||||
|
||||
case 29: /* snmpOutTraps */
|
||||
*uint_ptr = snmp_stats.outtraps;
|
||||
break;
|
||||
|
||||
case 30: /* snmpEnableAuthenTraps */
|
||||
if (snmp_get_auth_traps_enabled() == SNMP_AUTH_TRAPS_DISABLED) {
|
||||
*uint_ptr = MIB2_AUTH_TRAPS_DISABLED;
|
||||
} else {
|
||||
*uint_ptr = MIB2_AUTH_TRAPS_ENABLED;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 31: /* snmpSilentDrops */
|
||||
*uint_ptr = 0; /* not supported */
|
||||
break;
|
||||
|
||||
case 32: /* snmpProxyDrops */
|
||||
*uint_ptr = 0; /* not supported */
|
||||
break;
|
||||
|
||||
default:
|
||||
LWIP_DEBUGF(SNMP_MIB_DEBUG, ("snmp_get_value(): unknown id: %" S32_F "\n", node->oid));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return sizeof(*uint_ptr);
|
||||
return sizeof(*uint_ptr);
|
||||
}
|
||||
|
||||
static snmp_err_t snmp_set_test(const struct snmp_scalar_array_node_def *node, u16_t len, void *value)
|
||||
static snmp_err_t
|
||||
snmp_set_test(const struct snmp_scalar_array_node_def *node, u16_t len, void *value)
|
||||
{
|
||||
snmp_err_t ret = SNMP_ERR_WRONGVALUE;
|
||||
LWIP_UNUSED_ARG(len);
|
||||
snmp_err_t ret = SNMP_ERR_WRONGVALUE;
|
||||
LWIP_UNUSED_ARG(len);
|
||||
|
||||
if (node->oid == 30) {
|
||||
/* snmpEnableAuthenTraps */
|
||||
s32_t *sint_ptr = (s32_t *)value;
|
||||
if (node->oid == 30) {
|
||||
/* snmpEnableAuthenTraps */
|
||||
s32_t *sint_ptr = (s32_t *)value;
|
||||
|
||||
/* we should have writable non-volatile mem here */
|
||||
if ((*sint_ptr == MIB2_AUTH_TRAPS_DISABLED) || (*sint_ptr == MIB2_AUTH_TRAPS_ENABLED)) {
|
||||
ret = SNMP_ERR_NOERROR;
|
||||
}
|
||||
/* we should have writable non-volatile mem here */
|
||||
if ((*sint_ptr == MIB2_AUTH_TRAPS_DISABLED) || (*sint_ptr == MIB2_AUTH_TRAPS_ENABLED)) {
|
||||
ret = SNMP_ERR_NOERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static snmp_err_t snmp_set_value(const struct snmp_scalar_array_node_def *node, u16_t len, void *value)
|
||||
static snmp_err_t
|
||||
snmp_set_value(const struct snmp_scalar_array_node_def *node, u16_t len, void *value)
|
||||
{
|
||||
LWIP_UNUSED_ARG(len);
|
||||
LWIP_UNUSED_ARG(len);
|
||||
|
||||
if (node->oid == 30) {
|
||||
/* snmpEnableAuthenTraps */
|
||||
s32_t *sint_ptr = (s32_t *)value;
|
||||
|
||||
if (*sint_ptr == MIB2_AUTH_TRAPS_DISABLED) {
|
||||
snmp_set_auth_traps_enabled(SNMP_AUTH_TRAPS_DISABLED);
|
||||
} else {
|
||||
snmp_set_auth_traps_enabled(SNMP_AUTH_TRAPS_ENABLED);
|
||||
}
|
||||
if (node->oid == 30) {
|
||||
/* snmpEnableAuthenTraps */
|
||||
s32_t *sint_ptr = (s32_t *)value;
|
||||
if (*sint_ptr == MIB2_AUTH_TRAPS_DISABLED) {
|
||||
snmp_set_auth_traps_enabled(SNMP_AUTH_TRAPS_DISABLED);
|
||||
} else {
|
||||
snmp_set_auth_traps_enabled(SNMP_AUTH_TRAPS_ENABLED);
|
||||
}
|
||||
}
|
||||
|
||||
return SNMP_ERR_NOERROR;
|
||||
return SNMP_ERR_NOERROR;
|
||||
}
|
||||
|
||||
/* the following nodes access variables in SNMP stack (snmp_stats) from SNMP worker thread -> OK, no sync needed */
|
||||
static const struct snmp_scalar_array_node_def snmp_nodes[] = {
|
||||
{ 1, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpInPkts */
|
||||
{ 2, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpOutPkts */
|
||||
{ 3, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpInBadVersions */
|
||||
{ 4, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpInBadCommunityNames */
|
||||
{ 5, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpInBadCommunityUses */
|
||||
{ 6, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpInASNParseErrs */
|
||||
{ 8, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpInTooBigs */
|
||||
{ 9, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpInNoSuchNames */
|
||||
{ 10, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpInBadValues */
|
||||
{ 11, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpInReadOnlys */
|
||||
{ 12, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpInGenErrs */
|
||||
{ 13, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpInTotalReqVars */
|
||||
{ 14, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpInTotalSetVars */
|
||||
{ 15, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpInGetRequests */
|
||||
{ 16, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpInGetNexts */
|
||||
{ 17, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpInSetRequests */
|
||||
{ 18, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpInGetResponses */
|
||||
{ 19, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpInTraps */
|
||||
{ 20, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpOutTooBigs */
|
||||
{ 21, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpOutNoSuchNames */
|
||||
{ 22, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpOutBadValues */
|
||||
{ 24, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpOutGenErrs */
|
||||
{ 25, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpOutGetRequests */
|
||||
{ 26, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpOutGetNexts */
|
||||
{ 27, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpOutSetRequests */
|
||||
{ 28, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpOutGetResponses */
|
||||
{ 29, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpOutTraps */
|
||||
{ 30, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_WRITE }, /* snmpEnableAuthenTraps */
|
||||
{ 31, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpSilentDrops */
|
||||
{ 32, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY } /* snmpProxyDrops */
|
||||
{ 1, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpInPkts */
|
||||
{ 2, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpOutPkts */
|
||||
{ 3, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpInBadVersions */
|
||||
{ 4, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpInBadCommunityNames */
|
||||
{ 5, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpInBadCommunityUses */
|
||||
{ 6, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpInASNParseErrs */
|
||||
{ 8, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpInTooBigs */
|
||||
{ 9, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpInNoSuchNames */
|
||||
{10, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpInBadValues */
|
||||
{11, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpInReadOnlys */
|
||||
{12, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpInGenErrs */
|
||||
{13, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpInTotalReqVars */
|
||||
{14, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpInTotalSetVars */
|
||||
{15, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpInGetRequests */
|
||||
{16, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpInGetNexts */
|
||||
{17, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpInSetRequests */
|
||||
{18, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpInGetResponses */
|
||||
{19, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpInTraps */
|
||||
{20, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpOutTooBigs */
|
||||
{21, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpOutNoSuchNames */
|
||||
{22, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpOutBadValues */
|
||||
{24, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpOutGenErrs */
|
||||
{25, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpOutGetRequests */
|
||||
{26, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpOutGetNexts */
|
||||
{27, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpOutSetRequests */
|
||||
{28, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpOutGetResponses */
|
||||
{29, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpOutTraps */
|
||||
{30, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_WRITE}, /* snmpEnableAuthenTraps */
|
||||
{31, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpSilentDrops */
|
||||
{32, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY} /* snmpProxyDrops */
|
||||
};
|
||||
|
||||
const struct snmp_scalar_array_node snmp_mib2_snmp_root = SNMP_SCALAR_CREATE_ARRAY_NODE(11, snmp_nodes, snmp_get_value, snmp_set_test, snmp_set_value);
|
||||
|
@ -46,9 +46,9 @@
|
||||
#if LWIP_SNMP && SNMP_LWIP_MIB2
|
||||
|
||||
#if SNMP_USE_NETCONN
|
||||
#define SYNC_NODE_NAME(node_name) node_name##_synced
|
||||
#define SYNC_NODE_NAME(node_name) node_name ## _synced
|
||||
#define CREATE_LWIP_SYNC_NODE(oid, node_name) \
|
||||
static const struct snmp_threadsync_node node_name##_synced = SNMP_CREATE_THREAD_SYNC_NODE(oid, &node_name.node, &snmp_mib2_lwip_locks);
|
||||
static const struct snmp_threadsync_node node_name ## _synced = SNMP_CREATE_THREAD_SYNC_NODE(oid, &node_name.node, &snmp_mib2_lwip_locks);
|
||||
#else
|
||||
#define SYNC_NODE_NAME(node_name) node_name
|
||||
#define CREATE_LWIP_SYNC_NODE(oid, node_name)
|
||||
@ -57,33 +57,33 @@
|
||||
/* --- system .1.3.6.1.2.1.1 ----------------------------------------------------- */
|
||||
|
||||
/** mib-2.system.sysDescr */
|
||||
static const u8_t sysdescr_default[] = SNMP_LWIP_MIB2_SYSDESC;
|
||||
static const u8_t *sysdescr = sysdescr_default;
|
||||
static const u16_t *sysdescr_len = NULL; /* use strlen for determining len */
|
||||
static const u8_t sysdescr_default[] = SNMP_LWIP_MIB2_SYSDESC;
|
||||
static const u8_t *sysdescr = sysdescr_default;
|
||||
static const u16_t *sysdescr_len = NULL; /* use strlen for determining len */
|
||||
|
||||
/** mib-2.system.sysContact */
|
||||
static const u8_t syscontact_default[] = SNMP_LWIP_MIB2_SYSCONTACT;
|
||||
static const u8_t *syscontact = syscontact_default;
|
||||
static const u16_t *syscontact_len = NULL; /* use strlen for determining len */
|
||||
static u8_t *syscontact_wr = NULL; /* if writable, points to the same buffer as syscontact (required for correct constness) */
|
||||
static u16_t *syscontact_wr_len = NULL; /* if writable, points to the same buffer as syscontact_len (required for correct constness) */
|
||||
static u16_t syscontact_bufsize = 0; /* 0=not writable */
|
||||
static const u8_t syscontact_default[] = SNMP_LWIP_MIB2_SYSCONTACT;
|
||||
static const u8_t *syscontact = syscontact_default;
|
||||
static const u16_t *syscontact_len = NULL; /* use strlen for determining len */
|
||||
static u8_t *syscontact_wr = NULL; /* if writable, points to the same buffer as syscontact (required for correct constness) */
|
||||
static u16_t *syscontact_wr_len = NULL; /* if writable, points to the same buffer as syscontact_len (required for correct constness) */
|
||||
static u16_t syscontact_bufsize = 0; /* 0=not writable */
|
||||
|
||||
/** mib-2.system.sysName */
|
||||
static const u8_t sysname_default[] = SNMP_LWIP_MIB2_SYSNAME;
|
||||
static const u8_t *sysname = sysname_default;
|
||||
static const u16_t *sysname_len = NULL; /* use strlen for determining len */
|
||||
static u8_t *sysname_wr = NULL; /* if writable, points to the same buffer as sysname (required for correct constness) */
|
||||
static u16_t *sysname_wr_len = NULL; /* if writable, points to the same buffer as sysname_len (required for correct constness) */
|
||||
static u16_t sysname_bufsize = 0; /* 0=not writable */
|
||||
static const u8_t sysname_default[] = SNMP_LWIP_MIB2_SYSNAME;
|
||||
static const u8_t *sysname = sysname_default;
|
||||
static const u16_t *sysname_len = NULL; /* use strlen for determining len */
|
||||
static u8_t *sysname_wr = NULL; /* if writable, points to the same buffer as sysname (required for correct constness) */
|
||||
static u16_t *sysname_wr_len = NULL; /* if writable, points to the same buffer as sysname_len (required for correct constness) */
|
||||
static u16_t sysname_bufsize = 0; /* 0=not writable */
|
||||
|
||||
/** mib-2.system.sysLocation */
|
||||
static const u8_t syslocation_default[] = SNMP_LWIP_MIB2_SYSLOCATION;
|
||||
static const u8_t *syslocation = syslocation_default;
|
||||
static const u16_t *syslocation_len = NULL; /* use strlen for determining len */
|
||||
static u8_t *syslocation_wr = NULL; /* if writable, points to the same buffer as syslocation (required for correct constness) */
|
||||
static u16_t *syslocation_wr_len = NULL; /* if writable, points to the same buffer as syslocation_len (required for correct constness) */
|
||||
static u16_t syslocation_bufsize = 0; /* 0=not writable */
|
||||
static const u8_t syslocation_default[] = SNMP_LWIP_MIB2_SYSLOCATION;
|
||||
static const u8_t *syslocation = syslocation_default;
|
||||
static const u16_t *syslocation_len = NULL; /* use strlen for determining len */
|
||||
static u8_t *syslocation_wr = NULL; /* if writable, points to the same buffer as syslocation (required for correct constness) */
|
||||
static u16_t *syslocation_wr_len = NULL; /* if writable, points to the same buffer as syslocation_len (required for correct constness) */
|
||||
static u16_t syslocation_bufsize = 0; /* 0=not writable */
|
||||
|
||||
/**
|
||||
* @ingroup snmp_mib2
|
||||
@ -92,12 +92,13 @@ static u16_t syslocation_bufsize = 0; /* 0=not writable */
|
||||
* @param str if non-NULL then copy str pointer
|
||||
* @param len points to string length, excluding zero terminator
|
||||
*/
|
||||
void snmp_mib2_set_sysdescr(const u8_t *str, const u16_t *len)
|
||||
void
|
||||
snmp_mib2_set_sysdescr(const u8_t *str, const u16_t *len)
|
||||
{
|
||||
if (str != NULL) {
|
||||
sysdescr = str;
|
||||
sysdescr_len = len;
|
||||
}
|
||||
if (str != NULL) {
|
||||
sysdescr = str;
|
||||
sysdescr_len = len;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -113,32 +114,35 @@ void snmp_mib2_set_sysdescr(const u8_t *str, const u16_t *len)
|
||||
* otherwise complete buffer is used for string.
|
||||
* if bufsize is set to 0, the value is regarded as read-only.
|
||||
*/
|
||||
void snmp_mib2_set_syscontact(u8_t *ocstr, u16_t *ocstrlen, u16_t bufsize)
|
||||
void
|
||||
snmp_mib2_set_syscontact(u8_t *ocstr, u16_t *ocstrlen, u16_t bufsize)
|
||||
{
|
||||
if (ocstr != NULL) {
|
||||
syscontact = ocstr;
|
||||
syscontact_wr = ocstr;
|
||||
syscontact_len = ocstrlen;
|
||||
syscontact_wr_len = ocstrlen;
|
||||
syscontact_bufsize = bufsize;
|
||||
}
|
||||
if (ocstr != NULL) {
|
||||
syscontact = ocstr;
|
||||
syscontact_wr = ocstr;
|
||||
syscontact_len = ocstrlen;
|
||||
syscontact_wr_len = ocstrlen;
|
||||
syscontact_bufsize = bufsize;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup snmp_mib2
|
||||
* see \ref snmp_mib2_set_syscontact but set pointer to readonly memory
|
||||
*/
|
||||
void snmp_mib2_set_syscontact_readonly(const u8_t *ocstr, const u16_t *ocstrlen)
|
||||
void
|
||||
snmp_mib2_set_syscontact_readonly(const u8_t *ocstr, const u16_t *ocstrlen)
|
||||
{
|
||||
if (ocstr != NULL) {
|
||||
syscontact = ocstr;
|
||||
syscontact_len = ocstrlen;
|
||||
syscontact_wr = NULL;
|
||||
syscontact_wr_len = NULL;
|
||||
syscontact_bufsize = 0;
|
||||
}
|
||||
if (ocstr != NULL) {
|
||||
syscontact = ocstr;
|
||||
syscontact_len = ocstrlen;
|
||||
syscontact_wr = NULL;
|
||||
syscontact_wr_len = NULL;
|
||||
syscontact_bufsize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup snmp_mib2
|
||||
* Initializes sysName pointers
|
||||
@ -152,30 +156,32 @@ void snmp_mib2_set_syscontact_readonly(const u8_t *ocstr, const u16_t *ocstrlen)
|
||||
* otherwise complete buffer is used for string.
|
||||
* if bufsize is set to 0, the value is regarded as read-only.
|
||||
*/
|
||||
void snmp_mib2_set_sysname(u8_t *ocstr, u16_t *ocstrlen, u16_t bufsize)
|
||||
void
|
||||
snmp_mib2_set_sysname(u8_t *ocstr, u16_t *ocstrlen, u16_t bufsize)
|
||||
{
|
||||
if (ocstr != NULL) {
|
||||
sysname = ocstr;
|
||||
sysname_wr = ocstr;
|
||||
sysname_len = ocstrlen;
|
||||
sysname_wr_len = ocstrlen;
|
||||
sysname_bufsize = bufsize;
|
||||
}
|
||||
if (ocstr != NULL) {
|
||||
sysname = ocstr;
|
||||
sysname_wr = ocstr;
|
||||
sysname_len = ocstrlen;
|
||||
sysname_wr_len = ocstrlen;
|
||||
sysname_bufsize = bufsize;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup snmp_mib2
|
||||
* see \ref snmp_mib2_set_sysname but set pointer to readonly memory
|
||||
*/
|
||||
void snmp_mib2_set_sysname_readonly(const u8_t *ocstr, const u16_t *ocstrlen)
|
||||
void
|
||||
snmp_mib2_set_sysname_readonly(const u8_t *ocstr, const u16_t *ocstrlen)
|
||||
{
|
||||
if (ocstr != NULL) {
|
||||
sysname = ocstr;
|
||||
sysname_len = ocstrlen;
|
||||
sysname_wr = NULL;
|
||||
sysname_wr_len = NULL;
|
||||
sysname_bufsize = 0;
|
||||
}
|
||||
if (ocstr != NULL) {
|
||||
sysname = ocstr;
|
||||
sysname_len = ocstrlen;
|
||||
sysname_wr = NULL;
|
||||
sysname_wr_len = NULL;
|
||||
sysname_bufsize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -191,188 +197,178 @@ void snmp_mib2_set_sysname_readonly(const u8_t *ocstr, const u16_t *ocstrlen)
|
||||
* otherwise complete buffer is used for string.
|
||||
* if bufsize is set to 0, the value is regarded as read-only.
|
||||
*/
|
||||
void snmp_mib2_set_syslocation(u8_t *ocstr, u16_t *ocstrlen, u16_t bufsize)
|
||||
void
|
||||
snmp_mib2_set_syslocation(u8_t *ocstr, u16_t *ocstrlen, u16_t bufsize)
|
||||
{
|
||||
if (ocstr != NULL) {
|
||||
syslocation = ocstr;
|
||||
syslocation_wr = ocstr;
|
||||
syslocation_len = ocstrlen;
|
||||
syslocation_wr_len = ocstrlen;
|
||||
syslocation_bufsize = bufsize;
|
||||
}
|
||||
if (ocstr != NULL) {
|
||||
syslocation = ocstr;
|
||||
syslocation_wr = ocstr;
|
||||
syslocation_len = ocstrlen;
|
||||
syslocation_wr_len = ocstrlen;
|
||||
syslocation_bufsize = bufsize;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup snmp_mib2
|
||||
* see \ref snmp_mib2_set_syslocation but set pointer to readonly memory
|
||||
*/
|
||||
void snmp_mib2_set_syslocation_readonly(const u8_t *ocstr, const u16_t *ocstrlen)
|
||||
void
|
||||
snmp_mib2_set_syslocation_readonly(const u8_t *ocstr, const u16_t *ocstrlen)
|
||||
{
|
||||
if (ocstr != NULL) {
|
||||
syslocation = ocstr;
|
||||
syslocation_len = ocstrlen;
|
||||
syslocation_wr = NULL;
|
||||
syslocation_wr_len = NULL;
|
||||
syslocation_bufsize = 0;
|
||||
}
|
||||
if (ocstr != NULL) {
|
||||
syslocation = ocstr;
|
||||
syslocation_len = ocstrlen;
|
||||
syslocation_wr = NULL;
|
||||
syslocation_wr_len = NULL;
|
||||
syslocation_bufsize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static s16_t system_get_value(const struct snmp_scalar_array_node_def *node, void *value)
|
||||
|
||||
static s16_t
|
||||
system_get_value(const struct snmp_scalar_array_node_def *node, void *value)
|
||||
{
|
||||
const u8_t *var = NULL;
|
||||
const s16_t *var_len;
|
||||
u16_t result;
|
||||
const u8_t *var = NULL;
|
||||
const s16_t *var_len;
|
||||
u16_t result;
|
||||
|
||||
switch (node->oid) {
|
||||
case 1: /* sysDescr */
|
||||
var = sysdescr;
|
||||
var_len = (const s16_t *)sysdescr_len;
|
||||
break;
|
||||
|
||||
case 2: /* sysObjectID */
|
||||
{
|
||||
const struct snmp_obj_id *dev_enterprise_oid = snmp_get_device_enterprise_oid();
|
||||
MEMCPY(value, dev_enterprise_oid->id, dev_enterprise_oid->len * sizeof(u32_t));
|
||||
return dev_enterprise_oid->len * sizeof(u32_t);
|
||||
}
|
||||
|
||||
case 3: /* sysUpTime */
|
||||
MIB2_COPY_SYSUPTIME_TO((u32_t *)value);
|
||||
return sizeof(u32_t);
|
||||
|
||||
case 4: /* sysContact */
|
||||
var = syscontact;
|
||||
var_len = (const s16_t *)syscontact_len;
|
||||
break;
|
||||
|
||||
case 5: /* sysName */
|
||||
var = sysname;
|
||||
var_len = (const s16_t *)sysname_len;
|
||||
break;
|
||||
|
||||
case 6: /* sysLocation */
|
||||
var = syslocation;
|
||||
var_len = (const s16_t *)syslocation_len;
|
||||
break;
|
||||
|
||||
case 7: /* sysServices */
|
||||
*(s32_t *)value = SNMP_SYSSERVICES;
|
||||
return sizeof(s32_t);
|
||||
|
||||
default:
|
||||
LWIP_DEBUGF(SNMP_MIB_DEBUG, ("system_get_value(): unknown id: %" S32_F "\n", node->oid));
|
||||
return 0;
|
||||
switch (node->oid) {
|
||||
case 1: /* sysDescr */
|
||||
var = sysdescr;
|
||||
var_len = (const s16_t *)sysdescr_len;
|
||||
break;
|
||||
case 2: { /* sysObjectID */
|
||||
const struct snmp_obj_id *dev_enterprise_oid = snmp_get_device_enterprise_oid();
|
||||
MEMCPY(value, dev_enterprise_oid->id, dev_enterprise_oid->len * sizeof(u32_t));
|
||||
return dev_enterprise_oid->len * sizeof(u32_t);
|
||||
}
|
||||
case 3: /* sysUpTime */
|
||||
MIB2_COPY_SYSUPTIME_TO((u32_t *)value);
|
||||
return sizeof(u32_t);
|
||||
case 4: /* sysContact */
|
||||
var = syscontact;
|
||||
var_len = (const s16_t *)syscontact_len;
|
||||
break;
|
||||
case 5: /* sysName */
|
||||
var = sysname;
|
||||
var_len = (const s16_t *)sysname_len;
|
||||
break;
|
||||
case 6: /* sysLocation */
|
||||
var = syslocation;
|
||||
var_len = (const s16_t *)syslocation_len;
|
||||
break;
|
||||
case 7: /* sysServices */
|
||||
*(s32_t *)value = SNMP_SYSSERVICES;
|
||||
return sizeof(s32_t);
|
||||
default:
|
||||
LWIP_DEBUGF(SNMP_MIB_DEBUG, ("system_get_value(): unknown id: %"S32_F"\n", node->oid));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* handle string values (OID 1,4,5 and 6) */
|
||||
LWIP_ASSERT("", (value != NULL));
|
||||
|
||||
if (var_len == NULL) {
|
||||
result = (s16_t)strlen((const char *)var);
|
||||
} else {
|
||||
result = *var_len;
|
||||
}
|
||||
|
||||
MEMCPY(value, var, result);
|
||||
return result;
|
||||
/* handle string values (OID 1,4,5 and 6) */
|
||||
LWIP_ASSERT("", (value != NULL));
|
||||
if (var_len == NULL) {
|
||||
result = (s16_t)strlen((const char *)var);
|
||||
} else {
|
||||
result = *var_len;
|
||||
}
|
||||
MEMCPY(value, var, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
static snmp_err_t system_set_test(const struct snmp_scalar_array_node_def *node, u16_t len, void *value)
|
||||
static snmp_err_t
|
||||
system_set_test(const struct snmp_scalar_array_node_def *node, u16_t len, void *value)
|
||||
{
|
||||
snmp_err_t ret = SNMP_ERR_WRONGVALUE;
|
||||
const u16_t *var_bufsize = NULL;
|
||||
const u16_t *var_wr_len;
|
||||
snmp_err_t ret = SNMP_ERR_WRONGVALUE;
|
||||
const u16_t *var_bufsize = NULL;
|
||||
const u16_t *var_wr_len;
|
||||
|
||||
LWIP_UNUSED_ARG(value);
|
||||
LWIP_UNUSED_ARG(value);
|
||||
|
||||
switch (node->oid) {
|
||||
case 4: /* sysContact */
|
||||
var_bufsize = &syscontact_bufsize;
|
||||
var_wr_len = syscontact_wr_len;
|
||||
break;
|
||||
|
||||
case 5: /* sysName */
|
||||
var_bufsize = &sysname_bufsize;
|
||||
var_wr_len = sysname_wr_len;
|
||||
break;
|
||||
|
||||
case 6: /* sysLocation */
|
||||
var_bufsize = &syslocation_bufsize;
|
||||
var_wr_len = syslocation_wr_len;
|
||||
break;
|
||||
|
||||
default:
|
||||
LWIP_DEBUGF(SNMP_MIB_DEBUG, ("system_set_test(): unknown id: %" S32_F "\n", node->oid));
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* check if value is writable at all */
|
||||
if (*var_bufsize > 0) {
|
||||
if (var_wr_len == NULL) {
|
||||
/* we have to take the terminating 0 into account */
|
||||
if (len < *var_bufsize) {
|
||||
ret = SNMP_ERR_NOERROR;
|
||||
}
|
||||
} else {
|
||||
if (len <= *var_bufsize) {
|
||||
ret = SNMP_ERR_NOERROR;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ret = SNMP_ERR_NOTWRITABLE;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static snmp_err_t system_set_value(const struct snmp_scalar_array_node_def *node, u16_t len, void *value)
|
||||
{
|
||||
u8_t *var_wr = NULL;
|
||||
u16_t *var_wr_len;
|
||||
|
||||
switch (node->oid) {
|
||||
case 4: /* sysContact */
|
||||
var_wr = syscontact_wr;
|
||||
var_wr_len = syscontact_wr_len;
|
||||
break;
|
||||
|
||||
case 5: /* sysName */
|
||||
var_wr = sysname_wr;
|
||||
var_wr_len = sysname_wr_len;
|
||||
break;
|
||||
|
||||
case 6: /* sysLocation */
|
||||
var_wr = syslocation_wr;
|
||||
var_wr_len = syslocation_wr_len;
|
||||
break;
|
||||
|
||||
default:
|
||||
LWIP_DEBUGF(SNMP_MIB_DEBUG, ("system_set_value(): unknown id: %" S32_F "\n", node->oid));
|
||||
return SNMP_ERR_GENERROR;
|
||||
}
|
||||
|
||||
/* no need to check size of target buffer, this was already done in set_test method */
|
||||
LWIP_ASSERT("", var_wr != NULL);
|
||||
MEMCPY(var_wr, value, len);
|
||||
switch (node->oid) {
|
||||
case 4: /* sysContact */
|
||||
var_bufsize = &syscontact_bufsize;
|
||||
var_wr_len = syscontact_wr_len;
|
||||
break;
|
||||
case 5: /* sysName */
|
||||
var_bufsize = &sysname_bufsize;
|
||||
var_wr_len = sysname_wr_len;
|
||||
break;
|
||||
case 6: /* sysLocation */
|
||||
var_bufsize = &syslocation_bufsize;
|
||||
var_wr_len = syslocation_wr_len;
|
||||
break;
|
||||
default:
|
||||
LWIP_DEBUGF(SNMP_MIB_DEBUG, ("system_set_test(): unknown id: %"S32_F"\n", node->oid));
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* check if value is writable at all */
|
||||
if (*var_bufsize > 0) {
|
||||
if (var_wr_len == NULL) {
|
||||
/* add terminating 0 */
|
||||
var_wr[len] = 0;
|
||||
/* we have to take the terminating 0 into account */
|
||||
if (len < *var_bufsize) {
|
||||
ret = SNMP_ERR_NOERROR;
|
||||
}
|
||||
} else {
|
||||
*var_wr_len = len;
|
||||
if (len <= *var_bufsize) {
|
||||
ret = SNMP_ERR_NOERROR;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ret = SNMP_ERR_NOTWRITABLE;
|
||||
}
|
||||
|
||||
return SNMP_ERR_NOERROR;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static snmp_err_t
|
||||
system_set_value(const struct snmp_scalar_array_node_def *node, u16_t len, void *value)
|
||||
{
|
||||
u8_t *var_wr = NULL;
|
||||
u16_t *var_wr_len;
|
||||
|
||||
switch (node->oid) {
|
||||
case 4: /* sysContact */
|
||||
var_wr = syscontact_wr;
|
||||
var_wr_len = syscontact_wr_len;
|
||||
break;
|
||||
case 5: /* sysName */
|
||||
var_wr = sysname_wr;
|
||||
var_wr_len = sysname_wr_len;
|
||||
break;
|
||||
case 6: /* sysLocation */
|
||||
var_wr = syslocation_wr;
|
||||
var_wr_len = syslocation_wr_len;
|
||||
break;
|
||||
default:
|
||||
LWIP_DEBUGF(SNMP_MIB_DEBUG, ("system_set_value(): unknown id: %"S32_F"\n", node->oid));
|
||||
return SNMP_ERR_GENERROR;
|
||||
}
|
||||
|
||||
/* no need to check size of target buffer, this was already done in set_test method */
|
||||
LWIP_ASSERT("", var_wr != NULL);
|
||||
MEMCPY(var_wr, value, len);
|
||||
|
||||
if (var_wr_len == NULL) {
|
||||
/* add terminating 0 */
|
||||
var_wr[len] = 0;
|
||||
} else {
|
||||
*var_wr_len = len;
|
||||
}
|
||||
|
||||
return SNMP_ERR_NOERROR;
|
||||
}
|
||||
|
||||
static const struct snmp_scalar_array_node_def system_nodes[] = {
|
||||
{ 1, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY }, /* sysDescr */
|
||||
{ 2, SNMP_ASN1_TYPE_OBJECT_ID, SNMP_NODE_INSTANCE_READ_ONLY }, /* sysObjectID */
|
||||
{ 3, SNMP_ASN1_TYPE_TIMETICKS, SNMP_NODE_INSTANCE_READ_ONLY }, /* sysUpTime */
|
||||
{ 4, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_WRITE }, /* sysContact */
|
||||
{ 5, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_WRITE }, /* sysName */
|
||||
{ 6, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_WRITE }, /* sysLocation */
|
||||
{ 7, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_ONLY } /* sysServices */
|
||||
{1, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY}, /* sysDescr */
|
||||
{2, SNMP_ASN1_TYPE_OBJECT_ID, SNMP_NODE_INSTANCE_READ_ONLY}, /* sysObjectID */
|
||||
{3, SNMP_ASN1_TYPE_TIMETICKS, SNMP_NODE_INSTANCE_READ_ONLY}, /* sysUpTime */
|
||||
{4, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_WRITE}, /* sysContact */
|
||||
{5, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_WRITE}, /* sysName */
|
||||
{6, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_WRITE}, /* sysLocation */
|
||||
{7, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_ONLY} /* sysServices */
|
||||
};
|
||||
|
||||
const struct snmp_scalar_array_node snmp_mib2_system_node = SNMP_SCALAR_CREATE_ARRAY_NODE(1, system_nodes, system_get_value, system_set_test, system_set_value);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -47,9 +47,9 @@
|
||||
#if LWIP_SNMP && SNMP_LWIP_MIB2 && LWIP_UDP
|
||||
|
||||
#if SNMP_USE_NETCONN
|
||||
#define SYNC_NODE_NAME(node_name) node_name##_synced
|
||||
#define SYNC_NODE_NAME(node_name) node_name ## _synced
|
||||
#define CREATE_LWIP_SYNC_NODE(oid, node_name) \
|
||||
static const struct snmp_threadsync_node node_name##_synced = SNMP_CREATE_THREAD_SYNC_NODE(oid, &node_name.node, &snmp_mib2_lwip_locks);
|
||||
static const struct snmp_threadsync_node node_name ## _synced = SNMP_CREATE_THREAD_SYNC_NODE(oid, &node_name.node, &snmp_mib2_lwip_locks);
|
||||
#else
|
||||
#define SYNC_NODE_NAME(node_name) node_name
|
||||
#define CREATE_LWIP_SYNC_NODE(oid, node_name)
|
||||
@ -57,169 +57,156 @@
|
||||
|
||||
/* --- udp .1.3.6.1.2.1.7 ----------------------------------------------------- */
|
||||
|
||||
static s16_t udp_get_value(struct snmp_node_instance *instance, void *value)
|
||||
static s16_t
|
||||
udp_get_value(struct snmp_node_instance *instance, void *value)
|
||||
{
|
||||
u32_t *uint_ptr = (u32_t *)value;
|
||||
u32_t *uint_ptr = (u32_t *)value;
|
||||
|
||||
switch (instance->node->oid) {
|
||||
case 1: /* udpInDatagrams */
|
||||
*uint_ptr = STATS_GET(mib2.udpindatagrams);
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 2: /* udpNoPorts */
|
||||
*uint_ptr = STATS_GET(mib2.udpnoports);
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 3: /* udpInErrors */
|
||||
*uint_ptr = STATS_GET(mib2.udpinerrors);
|
||||
return sizeof(*uint_ptr);
|
||||
|
||||
case 4: /* udpOutDatagrams */
|
||||
*uint_ptr = STATS_GET(mib2.udpoutdatagrams);
|
||||
return sizeof(*uint_ptr);
|
||||
switch (instance->node->oid) {
|
||||
case 1: /* udpInDatagrams */
|
||||
*uint_ptr = STATS_GET(mib2.udpindatagrams);
|
||||
return sizeof(*uint_ptr);
|
||||
case 2: /* udpNoPorts */
|
||||
*uint_ptr = STATS_GET(mib2.udpnoports);
|
||||
return sizeof(*uint_ptr);
|
||||
case 3: /* udpInErrors */
|
||||
*uint_ptr = STATS_GET(mib2.udpinerrors);
|
||||
return sizeof(*uint_ptr);
|
||||
case 4: /* udpOutDatagrams */
|
||||
*uint_ptr = STATS_GET(mib2.udpoutdatagrams);
|
||||
return sizeof(*uint_ptr);
|
||||
#if LWIP_HAVE_INT64
|
||||
|
||||
case 8: /* udpHCInDatagrams */
|
||||
{
|
||||
/* use the 32 bit counter for now... */
|
||||
u64_t val64 = STATS_GET(mib2.udpindatagrams);
|
||||
*((u64_t *)value) = val64;
|
||||
}
|
||||
|
||||
return sizeof(u64_t);
|
||||
|
||||
case 9: /* udpHCOutDatagrams */
|
||||
{
|
||||
/* use the 32 bit counter for now... */
|
||||
u64_t val64 = STATS_GET(mib2.udpoutdatagrams);
|
||||
*((u64_t *)value) = val64;
|
||||
}
|
||||
|
||||
return sizeof(u64_t);
|
||||
#endif
|
||||
|
||||
default:
|
||||
LWIP_DEBUGF(SNMP_MIB_DEBUG, ("udp_get_value(): unknown id: %" S32_F "\n", instance->node->oid));
|
||||
break;
|
||||
case 8: { /* udpHCInDatagrams */
|
||||
/* use the 32 bit counter for now... */
|
||||
u64_t val64 = STATS_GET(mib2.udpindatagrams);
|
||||
*((u64_t *)value) = val64;
|
||||
}
|
||||
return sizeof(u64_t);
|
||||
case 9: { /* udpHCOutDatagrams */
|
||||
/* use the 32 bit counter for now... */
|
||||
u64_t val64 = STATS_GET(mib2.udpoutdatagrams);
|
||||
*((u64_t *)value) = val64;
|
||||
}
|
||||
return sizeof(u64_t);
|
||||
#endif
|
||||
default:
|
||||
LWIP_DEBUGF(SNMP_MIB_DEBUG, ("udp_get_value(): unknown id: %"S32_F"\n", instance->node->oid));
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --- udpEndpointTable --- */
|
||||
|
||||
static snmp_err_t udp_endpointTable_get_cell_value_core(const u32_t *column, union snmp_variant_value *value)
|
||||
static snmp_err_t
|
||||
udp_endpointTable_get_cell_value_core(const u32_t *column, union snmp_variant_value *value)
|
||||
{
|
||||
/* all items except udpEndpointProcess are declared as not-accessible */
|
||||
switch (*column) {
|
||||
case 8: /* udpEndpointProcess */
|
||||
value->u32 = 0; /* not supported */
|
||||
break;
|
||||
/* all items except udpEndpointProcess are declared as not-accessible */
|
||||
switch (*column) {
|
||||
case 8: /* udpEndpointProcess */
|
||||
value->u32 = 0; /* not supported */
|
||||
break;
|
||||
default:
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
default:
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
return SNMP_ERR_NOERROR;
|
||||
return SNMP_ERR_NOERROR;
|
||||
}
|
||||
|
||||
static snmp_err_t udp_endpointTable_get_cell_value(const u32_t *column, const u32_t *row_oid, u8_t row_oid_len, union snmp_variant_value *value, u32_t *value_len)
|
||||
static snmp_err_t
|
||||
udp_endpointTable_get_cell_value(const u32_t *column, const u32_t *row_oid, u8_t row_oid_len, union snmp_variant_value *value, u32_t *value_len)
|
||||
{
|
||||
ip_addr_t local_ip, remote_ip;
|
||||
u16_t local_port, remote_port;
|
||||
struct udp_pcb *pcb;
|
||||
ip_addr_t local_ip, remote_ip;
|
||||
u16_t local_port, remote_port;
|
||||
struct udp_pcb *pcb;
|
||||
u8_t idx = 0;
|
||||
|
||||
LWIP_UNUSED_ARG(value_len);
|
||||
|
||||
/* udpEndpointLocalAddressType + udpEndpointLocalAddress + udpEndpointLocalPort */
|
||||
idx += snmp_oid_to_ip_port(&row_oid[idx], row_oid_len - idx, &local_ip, &local_port);
|
||||
if (idx == 0) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
/* udpEndpointRemoteAddressType + udpEndpointRemoteAddress + udpEndpointRemotePort */
|
||||
idx += snmp_oid_to_ip_port(&row_oid[idx], row_oid_len - idx, &remote_ip, &remote_port);
|
||||
if (idx == 0) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
/* udpEndpointInstance */
|
||||
if (row_oid_len < (idx + 1)) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
if (row_oid[idx] != 0) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
/* find udp_pcb with requested ip and port*/
|
||||
pcb = udp_pcbs;
|
||||
while (pcb != NULL) {
|
||||
if (ip_addr_cmp(&local_ip, &pcb->local_ip) &&
|
||||
(local_port == pcb->local_port) &&
|
||||
ip_addr_cmp(&remote_ip, &pcb->remote_ip) &&
|
||||
(remote_port == pcb->remote_port)) {
|
||||
/* fill in object properties */
|
||||
return udp_endpointTable_get_cell_value_core(column, value);
|
||||
}
|
||||
pcb = pcb->next;
|
||||
}
|
||||
|
||||
/* not found */
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
static snmp_err_t
|
||||
udp_endpointTable_get_next_cell_instance_and_value(const u32_t *column, struct snmp_obj_id *row_oid, union snmp_variant_value *value, u32_t *value_len)
|
||||
{
|
||||
struct udp_pcb *pcb;
|
||||
struct snmp_next_oid_state state;
|
||||
/* 1x udpEndpointLocalAddressType + 1x OID len + 16x udpEndpointLocalAddress + 1x udpEndpointLocalPort +
|
||||
* 1x udpEndpointRemoteAddressType + 1x OID len + 16x udpEndpointRemoteAddress + 1x udpEndpointRemotePort +
|
||||
* 1x udpEndpointInstance = 39
|
||||
*/
|
||||
u32_t result_temp[39];
|
||||
|
||||
LWIP_UNUSED_ARG(value_len);
|
||||
|
||||
/* init struct to search next oid */
|
||||
snmp_next_oid_init(&state, row_oid->id, row_oid->len, result_temp, LWIP_ARRAYSIZE(result_temp));
|
||||
|
||||
/* iterate over all possible OIDs to find the next one */
|
||||
pcb = udp_pcbs;
|
||||
while (pcb != NULL) {
|
||||
u32_t test_oid[LWIP_ARRAYSIZE(result_temp)];
|
||||
u8_t idx = 0;
|
||||
|
||||
LWIP_UNUSED_ARG(value_len);
|
||||
|
||||
/* udpEndpointLocalAddressType + udpEndpointLocalAddress + udpEndpointLocalPort */
|
||||
idx += snmp_oid_to_ip_port(&row_oid[idx], row_oid_len - idx, &local_ip, &local_port);
|
||||
|
||||
if (idx == 0) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
idx += snmp_ip_port_to_oid(&pcb->local_ip, pcb->local_port, &test_oid[idx]);
|
||||
|
||||
/* udpEndpointRemoteAddressType + udpEndpointRemoteAddress + udpEndpointRemotePort */
|
||||
idx += snmp_oid_to_ip_port(&row_oid[idx], row_oid_len - idx, &remote_ip, &remote_port);
|
||||
idx += snmp_ip_port_to_oid(&pcb->remote_ip, pcb->remote_port, &test_oid[idx]);
|
||||
|
||||
if (idx == 0) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
test_oid[idx] = 0; /* udpEndpointInstance */
|
||||
idx++;
|
||||
|
||||
/* udpEndpointInstance */
|
||||
if (row_oid_len < (idx + 1)) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
/* check generated OID: is it a candidate for the next one? */
|
||||
snmp_next_oid_check(&state, test_oid, idx, NULL);
|
||||
|
||||
if (row_oid[idx] != 0) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
/* find udp_pcb with requested ip and port*/
|
||||
pcb = udp_pcbs;
|
||||
|
||||
while (pcb != NULL) {
|
||||
if (ip_addr_cmp(&local_ip, &pcb->local_ip) &&
|
||||
(local_port == pcb->local_port) &&
|
||||
ip_addr_cmp(&remote_ip, &pcb->remote_ip) &&
|
||||
(remote_port == pcb->remote_port)) {
|
||||
/* fill in object properties */
|
||||
return udp_endpointTable_get_cell_value_core(column, value);
|
||||
}
|
||||
|
||||
pcb = pcb->next;
|
||||
}
|
||||
pcb = pcb->next;
|
||||
}
|
||||
|
||||
/* did we find a next one? */
|
||||
if (state.status == SNMP_NEXT_OID_STATUS_SUCCESS) {
|
||||
snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len);
|
||||
/* fill in object properties */
|
||||
return udp_endpointTable_get_cell_value_core(column, value);
|
||||
} else {
|
||||
/* not found */
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
static snmp_err_t udp_endpointTable_get_next_cell_instance_and_value(const u32_t *column, struct snmp_obj_id *row_oid, union snmp_variant_value *value, u32_t *value_len)
|
||||
{
|
||||
struct udp_pcb *pcb;
|
||||
struct snmp_next_oid_state state;
|
||||
/* 1x udpEndpointLocalAddressType + 1x OID len + 16x udpEndpointLocalAddress + 1x udpEndpointLocalPort +
|
||||
* 1x udpEndpointRemoteAddressType + 1x OID len + 16x udpEndpointRemoteAddress + 1x udpEndpointRemotePort +
|
||||
* 1x udpEndpointInstance = 39
|
||||
*/
|
||||
u32_t result_temp[39];
|
||||
|
||||
LWIP_UNUSED_ARG(value_len);
|
||||
|
||||
/* init struct to search next oid */
|
||||
snmp_next_oid_init(&state, row_oid->id, row_oid->len, result_temp, LWIP_ARRAYSIZE(result_temp));
|
||||
|
||||
/* iterate over all possible OIDs to find the next one */
|
||||
pcb = udp_pcbs;
|
||||
|
||||
while (pcb != NULL) {
|
||||
u32_t test_oid[LWIP_ARRAYSIZE(result_temp)];
|
||||
u8_t idx = 0;
|
||||
|
||||
/* udpEndpointLocalAddressType + udpEndpointLocalAddress + udpEndpointLocalPort */
|
||||
idx += snmp_ip_port_to_oid(&pcb->local_ip, pcb->local_port, &test_oid[idx]);
|
||||
|
||||
/* udpEndpointRemoteAddressType + udpEndpointRemoteAddress + udpEndpointRemotePort */
|
||||
idx += snmp_ip_port_to_oid(&pcb->remote_ip, pcb->remote_port, &test_oid[idx]);
|
||||
|
||||
test_oid[idx] = 0; /* udpEndpointInstance */
|
||||
idx++;
|
||||
|
||||
/* check generated OID: is it a candidate for the next one? */
|
||||
snmp_next_oid_check(&state, test_oid, idx, NULL);
|
||||
|
||||
pcb = pcb->next;
|
||||
}
|
||||
|
||||
/* did we find a next one? */
|
||||
if (state.status == SNMP_NEXT_OID_STATUS_SUCCESS) {
|
||||
snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len);
|
||||
/* fill in object properties */
|
||||
return udp_endpointTable_get_cell_value_core(column, value);
|
||||
} else {
|
||||
/* not found */
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* --- udpTable --- */
|
||||
@ -228,127 +215,125 @@ static snmp_err_t udp_endpointTable_get_next_cell_instance_and_value(const u32_t
|
||||
|
||||
/* list of allowed value ranges for incoming OID */
|
||||
static const struct snmp_oid_range udp_Table_oid_ranges[] = {
|
||||
{ 0, 0xff }, /* IP A */
|
||||
{ 0, 0xff }, /* IP B */
|
||||
{ 0, 0xff }, /* IP C */
|
||||
{ 0, 0xff }, /* IP D */
|
||||
{ 1, 0xffff } /* Port */
|
||||
{ 0, 0xff }, /* IP A */
|
||||
{ 0, 0xff }, /* IP B */
|
||||
{ 0, 0xff }, /* IP C */
|
||||
{ 0, 0xff }, /* IP D */
|
||||
{ 1, 0xffff } /* Port */
|
||||
};
|
||||
|
||||
static snmp_err_t udp_Table_get_cell_value_core(struct udp_pcb *pcb, const u32_t *column, union snmp_variant_value *value, u32_t *value_len)
|
||||
static snmp_err_t
|
||||
udp_Table_get_cell_value_core(struct udp_pcb *pcb, const u32_t *column, union snmp_variant_value *value, u32_t *value_len)
|
||||
{
|
||||
LWIP_UNUSED_ARG(value_len);
|
||||
LWIP_UNUSED_ARG(value_len);
|
||||
|
||||
switch (*column) {
|
||||
case 1: /* udpLocalAddress */
|
||||
/* set reference to PCB local IP and return a generic node that copies IP4 addresses */
|
||||
value->u32 = ip_2_ip4(&pcb->local_ip)->addr;
|
||||
break;
|
||||
switch (*column) {
|
||||
case 1: /* udpLocalAddress */
|
||||
/* set reference to PCB local IP and return a generic node that copies IP4 addresses */
|
||||
value->u32 = ip_2_ip4(&pcb->local_ip)->addr;
|
||||
break;
|
||||
case 2: /* udpLocalPort */
|
||||
/* set reference to PCB local port and return a generic node that copies u16_t values */
|
||||
value->u32 = pcb->local_port;
|
||||
break;
|
||||
default:
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
case 2: /* udpLocalPort */
|
||||
/* set reference to PCB local port and return a generic node that copies u16_t values */
|
||||
value->u32 = pcb->local_port;
|
||||
break;
|
||||
|
||||
default:
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
return SNMP_ERR_NOERROR;
|
||||
return SNMP_ERR_NOERROR;
|
||||
}
|
||||
|
||||
static snmp_err_t udp_Table_get_cell_value(const u32_t *column, const u32_t *row_oid, u8_t row_oid_len, union snmp_variant_value *value, u32_t *value_len)
|
||||
static snmp_err_t
|
||||
udp_Table_get_cell_value(const u32_t *column, const u32_t *row_oid, u8_t row_oid_len, union snmp_variant_value *value, u32_t *value_len)
|
||||
{
|
||||
ip4_addr_t ip;
|
||||
u16_t port;
|
||||
struct udp_pcb *pcb;
|
||||
ip4_addr_t ip;
|
||||
u16_t port;
|
||||
struct udp_pcb *pcb;
|
||||
|
||||
/* check if incoming OID length and if values are in plausible range */
|
||||
if (!snmp_oid_in_range(row_oid, row_oid_len, udp_Table_oid_ranges, LWIP_ARRAYSIZE(udp_Table_oid_ranges))) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
/* check if incoming OID length and if values are in plausible range */
|
||||
if (!snmp_oid_in_range(row_oid, row_oid_len, udp_Table_oid_ranges, LWIP_ARRAYSIZE(udp_Table_oid_ranges))) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
/* get IP and port from incoming OID */
|
||||
snmp_oid_to_ip4(&row_oid[0], &ip); /* we know it succeeds because of oid_in_range check above */
|
||||
port = (u16_t)row_oid[4];
|
||||
|
||||
/* find udp_pcb with requested ip and port*/
|
||||
pcb = udp_pcbs;
|
||||
while (pcb != NULL) {
|
||||
if (IP_IS_V4_VAL(pcb->local_ip)) {
|
||||
if (ip4_addr_cmp(&ip, ip_2_ip4(&pcb->local_ip)) && (port == pcb->local_port)) {
|
||||
/* fill in object properties */
|
||||
return udp_Table_get_cell_value_core(pcb, column, value, value_len);
|
||||
}
|
||||
}
|
||||
pcb = pcb->next;
|
||||
}
|
||||
|
||||
/* not found */
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
static snmp_err_t
|
||||
udp_Table_get_next_cell_instance_and_value(const u32_t *column, struct snmp_obj_id *row_oid, union snmp_variant_value *value, u32_t *value_len)
|
||||
{
|
||||
struct udp_pcb *pcb;
|
||||
struct snmp_next_oid_state state;
|
||||
u32_t result_temp[LWIP_ARRAYSIZE(udp_Table_oid_ranges)];
|
||||
|
||||
/* init struct to search next oid */
|
||||
snmp_next_oid_init(&state, row_oid->id, row_oid->len, result_temp, LWIP_ARRAYSIZE(udp_Table_oid_ranges));
|
||||
|
||||
/* iterate over all possible OIDs to find the next one */
|
||||
pcb = udp_pcbs;
|
||||
while (pcb != NULL) {
|
||||
u32_t test_oid[LWIP_ARRAYSIZE(udp_Table_oid_ranges)];
|
||||
|
||||
if (IP_IS_V4_VAL(pcb->local_ip)) {
|
||||
snmp_ip4_to_oid(ip_2_ip4(&pcb->local_ip), &test_oid[0]);
|
||||
test_oid[4] = pcb->local_port;
|
||||
|
||||
/* check generated OID: is it a candidate for the next one? */
|
||||
snmp_next_oid_check(&state, test_oid, LWIP_ARRAYSIZE(udp_Table_oid_ranges), pcb);
|
||||
}
|
||||
|
||||
/* get IP and port from incoming OID */
|
||||
snmp_oid_to_ip4(&row_oid[0], &ip); /* we know it succeeds because of oid_in_range check above */
|
||||
port = (u16_t)row_oid[4];
|
||||
|
||||
/* find udp_pcb with requested ip and port*/
|
||||
pcb = udp_pcbs;
|
||||
|
||||
while (pcb != NULL) {
|
||||
if (IP_IS_V4_VAL(pcb->local_ip)) {
|
||||
if (ip4_addr_cmp(&ip, ip_2_ip4(&pcb->local_ip)) && (port == pcb->local_port)) {
|
||||
/* fill in object properties */
|
||||
return udp_Table_get_cell_value_core(pcb, column, value, value_len);
|
||||
}
|
||||
}
|
||||
|
||||
pcb = pcb->next;
|
||||
}
|
||||
pcb = pcb->next;
|
||||
}
|
||||
|
||||
/* did we find a next one? */
|
||||
if (state.status == SNMP_NEXT_OID_STATUS_SUCCESS) {
|
||||
snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len);
|
||||
/* fill in object properties */
|
||||
return udp_Table_get_cell_value_core((struct udp_pcb *)state.reference, column, value, value_len);
|
||||
} else {
|
||||
/* not found */
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
static snmp_err_t udp_Table_get_next_cell_instance_and_value(const u32_t *column, struct snmp_obj_id *row_oid, union snmp_variant_value *value, u32_t *value_len)
|
||||
{
|
||||
struct udp_pcb *pcb;
|
||||
struct snmp_next_oid_state state;
|
||||
u32_t result_temp[LWIP_ARRAYSIZE(udp_Table_oid_ranges)];
|
||||
|
||||
/* init struct to search next oid */
|
||||
snmp_next_oid_init(&state, row_oid->id, row_oid->len, result_temp, LWIP_ARRAYSIZE(udp_Table_oid_ranges));
|
||||
|
||||
/* iterate over all possible OIDs to find the next one */
|
||||
pcb = udp_pcbs;
|
||||
|
||||
while (pcb != NULL) {
|
||||
u32_t test_oid[LWIP_ARRAYSIZE(udp_Table_oid_ranges)];
|
||||
|
||||
if (IP_IS_V4_VAL(pcb->local_ip)) {
|
||||
snmp_ip4_to_oid(ip_2_ip4(&pcb->local_ip), &test_oid[0]);
|
||||
test_oid[4] = pcb->local_port;
|
||||
|
||||
/* check generated OID: is it a candidate for the next one? */
|
||||
snmp_next_oid_check(&state, test_oid, LWIP_ARRAYSIZE(udp_Table_oid_ranges), pcb);
|
||||
}
|
||||
|
||||
pcb = pcb->next;
|
||||
}
|
||||
|
||||
/* did we find a next one? */
|
||||
if (state.status == SNMP_NEXT_OID_STATUS_SUCCESS) {
|
||||
snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len);
|
||||
/* fill in object properties */
|
||||
return udp_Table_get_cell_value_core((struct udp_pcb *)state.reference, column, value, value_len);
|
||||
} else {
|
||||
/* not found */
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* LWIP_IPV4 */
|
||||
|
||||
static const struct snmp_scalar_node udp_inDatagrams = SNMP_SCALAR_CREATE_NODE_READONLY(1, SNMP_ASN1_TYPE_COUNTER, udp_get_value);
|
||||
static const struct snmp_scalar_node udp_noPorts = SNMP_SCALAR_CREATE_NODE_READONLY(2, SNMP_ASN1_TYPE_COUNTER, udp_get_value);
|
||||
static const struct snmp_scalar_node udp_inErrors = SNMP_SCALAR_CREATE_NODE_READONLY(3, SNMP_ASN1_TYPE_COUNTER, udp_get_value);
|
||||
static const struct snmp_scalar_node udp_outDatagrams = SNMP_SCALAR_CREATE_NODE_READONLY(4, SNMP_ASN1_TYPE_COUNTER, udp_get_value);
|
||||
static const struct snmp_scalar_node udp_inDatagrams = SNMP_SCALAR_CREATE_NODE_READONLY(1, SNMP_ASN1_TYPE_COUNTER, udp_get_value);
|
||||
static const struct snmp_scalar_node udp_noPorts = SNMP_SCALAR_CREATE_NODE_READONLY(2, SNMP_ASN1_TYPE_COUNTER, udp_get_value);
|
||||
static const struct snmp_scalar_node udp_inErrors = SNMP_SCALAR_CREATE_NODE_READONLY(3, SNMP_ASN1_TYPE_COUNTER, udp_get_value);
|
||||
static const struct snmp_scalar_node udp_outDatagrams = SNMP_SCALAR_CREATE_NODE_READONLY(4, SNMP_ASN1_TYPE_COUNTER, udp_get_value);
|
||||
#if LWIP_HAVE_INT64
|
||||
static const struct snmp_scalar_node udp_HCInDatagrams = SNMP_SCALAR_CREATE_NODE_READONLY(8, SNMP_ASN1_TYPE_COUNTER64, udp_get_value);
|
||||
static const struct snmp_scalar_node udp_HCInDatagrams = SNMP_SCALAR_CREATE_NODE_READONLY(8, SNMP_ASN1_TYPE_COUNTER64, udp_get_value);
|
||||
static const struct snmp_scalar_node udp_HCOutDatagrams = SNMP_SCALAR_CREATE_NODE_READONLY(9, SNMP_ASN1_TYPE_COUNTER64, udp_get_value);
|
||||
#endif
|
||||
|
||||
#if LWIP_IPV4
|
||||
static const struct snmp_table_simple_col_def udp_Table_columns[] = {
|
||||
{ 1, SNMP_ASN1_TYPE_IPADDR, SNMP_VARIANT_VALUE_TYPE_U32 }, /* udpLocalAddress */
|
||||
{ 2, SNMP_ASN1_TYPE_INTEGER, SNMP_VARIANT_VALUE_TYPE_U32 } /* udpLocalPort */
|
||||
{ 1, SNMP_ASN1_TYPE_IPADDR, SNMP_VARIANT_VALUE_TYPE_U32 }, /* udpLocalAddress */
|
||||
{ 2, SNMP_ASN1_TYPE_INTEGER, SNMP_VARIANT_VALUE_TYPE_U32 } /* udpLocalPort */
|
||||
};
|
||||
static const struct snmp_table_simple_node udp_Table = SNMP_TABLE_CREATE_SIMPLE(5, udp_Table_columns, udp_Table_get_cell_value, udp_Table_get_next_cell_instance_and_value);
|
||||
#endif /* LWIP_IPV4 */
|
||||
|
||||
static const struct snmp_table_simple_col_def udp_endpointTable_columns[] = {
|
||||
/* all items except udpEndpointProcess are declared as not-accessible */
|
||||
{ 8, SNMP_ASN1_TYPE_UNSIGNED32, SNMP_VARIANT_VALUE_TYPE_U32 } /* udpEndpointProcess */
|
||||
/* all items except udpEndpointProcess are declared as not-accessible */
|
||||
{ 8, SNMP_ASN1_TYPE_UNSIGNED32, SNMP_VARIANT_VALUE_TYPE_U32 } /* udpEndpointProcess */
|
||||
};
|
||||
|
||||
static const struct snmp_table_simple_node udp_endpointTable = SNMP_TABLE_CREATE_SIMPLE(7, udp_endpointTable_columns, udp_endpointTable_get_cell_value, udp_endpointTable_get_next_cell_instance_and_value);
|
||||
@ -368,18 +353,18 @@ CREATE_LWIP_SYNC_NODE(9, udp_HCOutDatagrams)
|
||||
#endif
|
||||
|
||||
static const struct snmp_node *const udp_nodes[] = {
|
||||
&SYNC_NODE_NAME(udp_inDatagrams).node.node,
|
||||
&SYNC_NODE_NAME(udp_noPorts).node.node,
|
||||
&SYNC_NODE_NAME(udp_inErrors).node.node,
|
||||
&SYNC_NODE_NAME(udp_outDatagrams).node.node,
|
||||
&SYNC_NODE_NAME(udp_inDatagrams).node.node,
|
||||
&SYNC_NODE_NAME(udp_noPorts).node.node,
|
||||
&SYNC_NODE_NAME(udp_inErrors).node.node,
|
||||
&SYNC_NODE_NAME(udp_outDatagrams).node.node,
|
||||
#if LWIP_IPV4
|
||||
&SYNC_NODE_NAME(udp_Table).node.node,
|
||||
&SYNC_NODE_NAME(udp_Table).node.node,
|
||||
#endif /* LWIP_IPV4 */
|
||||
&SYNC_NODE_NAME(udp_endpointTable).node.node
|
||||
&SYNC_NODE_NAME(udp_endpointTable).node.node
|
||||
#if LWIP_HAVE_INT64
|
||||
,
|
||||
&SYNC_NODE_NAME(udp_HCInDatagrams).node.node,
|
||||
&SYNC_NODE_NAME(udp_HCOutDatagrams).node.node
|
||||
,
|
||||
&SYNC_NODE_NAME(udp_HCInDatagrams).node.node,
|
||||
&SYNC_NODE_NAME(udp_HCOutDatagrams).node.node
|
||||
#endif
|
||||
};
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -52,6 +52,7 @@
|
||||
#include "snmpv3_priv.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -62,104 +63,104 @@ extern "C" {
|
||||
#define SNMP_VERSION_3 3
|
||||
|
||||
struct snmp_varbind_enumerator {
|
||||
struct snmp_pbuf_stream pbuf_stream;
|
||||
u16_t varbind_count;
|
||||
struct snmp_pbuf_stream pbuf_stream;
|
||||
u16_t varbind_count;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
SNMP_VB_ENUMERATOR_ERR_OK = 0,
|
||||
SNMP_VB_ENUMERATOR_ERR_EOVB = 1,
|
||||
SNMP_VB_ENUMERATOR_ERR_ASN1ERROR = 2,
|
||||
SNMP_VB_ENUMERATOR_ERR_INVALIDLENGTH = 3
|
||||
SNMP_VB_ENUMERATOR_ERR_OK = 0,
|
||||
SNMP_VB_ENUMERATOR_ERR_EOVB = 1,
|
||||
SNMP_VB_ENUMERATOR_ERR_ASN1ERROR = 2,
|
||||
SNMP_VB_ENUMERATOR_ERR_INVALIDLENGTH = 3
|
||||
} snmp_vb_enumerator_err_t;
|
||||
|
||||
void snmp_vb_enumerator_init(struct snmp_varbind_enumerator *enumerator, struct pbuf *p, u16_t offset, u16_t length);
|
||||
snmp_vb_enumerator_err_t snmp_vb_enumerator_get_next(struct snmp_varbind_enumerator *enumerator, struct snmp_varbind *varbind);
|
||||
|
||||
struct snmp_request {
|
||||
/* Communication handle */
|
||||
void *handle;
|
||||
/* source IP address */
|
||||
const ip_addr_t *source_ip;
|
||||
/* source UDP port */
|
||||
u16_t source_port;
|
||||
/* incoming snmp version */
|
||||
u8_t version;
|
||||
/* community name (zero terminated) */
|
||||
u8_t community[SNMP_MAX_COMMUNITY_STR_LEN + 1];
|
||||
/* community string length (exclusive zero term) */
|
||||
u16_t community_strlen;
|
||||
/* request type */
|
||||
u8_t request_type;
|
||||
/* request ID */
|
||||
s32_t request_id;
|
||||
/* error status */
|
||||
s32_t error_status;
|
||||
/* error index */
|
||||
s32_t error_index;
|
||||
/* non-repeaters (getBulkRequest (SNMPv2c)) */
|
||||
s32_t non_repeaters;
|
||||
/* max-repetitions (getBulkRequest (SNMPv2c)) */
|
||||
s32_t max_repetitions;
|
||||
/* Communication handle */
|
||||
void *handle;
|
||||
/* source IP address */
|
||||
const ip_addr_t *source_ip;
|
||||
/* source UDP port */
|
||||
u16_t source_port;
|
||||
/* incoming snmp version */
|
||||
u8_t version;
|
||||
/* community name (zero terminated) */
|
||||
u8_t community[SNMP_MAX_COMMUNITY_STR_LEN + 1];
|
||||
/* community string length (exclusive zero term) */
|
||||
u16_t community_strlen;
|
||||
/* request type */
|
||||
u8_t request_type;
|
||||
/* request ID */
|
||||
s32_t request_id;
|
||||
/* error status */
|
||||
s32_t error_status;
|
||||
/* error index */
|
||||
s32_t error_index;
|
||||
/* non-repeaters (getBulkRequest (SNMPv2c)) */
|
||||
s32_t non_repeaters;
|
||||
/* max-repetitions (getBulkRequest (SNMPv2c)) */
|
||||
s32_t max_repetitions;
|
||||
|
||||
/* Usually response-pdu (2). When snmpv3 errors are detected report-pdu(8) */
|
||||
u8_t request_out_type;
|
||||
/* Usually response-pdu (2). When snmpv3 errors are detected report-pdu(8) */
|
||||
u8_t request_out_type;
|
||||
|
||||
#if LWIP_SNMP_V3
|
||||
s32_t msg_id;
|
||||
s32_t msg_max_size;
|
||||
u8_t msg_flags;
|
||||
s32_t msg_security_model;
|
||||
u8_t msg_authoritative_engine_id[SNMP_V3_MAX_ENGINE_ID_LENGTH];
|
||||
u8_t msg_authoritative_engine_id_len;
|
||||
s32_t msg_authoritative_engine_boots;
|
||||
s32_t msg_authoritative_engine_time;
|
||||
u8_t msg_user_name[SNMP_V3_MAX_USER_LENGTH];
|
||||
u8_t msg_user_name_len;
|
||||
u8_t msg_authentication_parameters[SNMP_V3_MAX_AUTH_PARAM_LENGTH];
|
||||
u8_t msg_authentication_parameters_len;
|
||||
u8_t msg_privacy_parameters[SNMP_V3_MAX_PRIV_PARAM_LENGTH];
|
||||
u8_t msg_privacy_parameters_len;
|
||||
u8_t context_engine_id[SNMP_V3_MAX_ENGINE_ID_LENGTH];
|
||||
u8_t context_engine_id_len;
|
||||
u8_t context_name[SNMP_V3_MAX_ENGINE_ID_LENGTH];
|
||||
u8_t context_name_len;
|
||||
s32_t msg_id;
|
||||
s32_t msg_max_size;
|
||||
u8_t msg_flags;
|
||||
s32_t msg_security_model;
|
||||
u8_t msg_authoritative_engine_id[SNMP_V3_MAX_ENGINE_ID_LENGTH];
|
||||
u8_t msg_authoritative_engine_id_len;
|
||||
s32_t msg_authoritative_engine_boots;
|
||||
s32_t msg_authoritative_engine_time;
|
||||
u8_t msg_user_name[SNMP_V3_MAX_USER_LENGTH];
|
||||
u8_t msg_user_name_len;
|
||||
u8_t msg_authentication_parameters[SNMP_V3_MAX_AUTH_PARAM_LENGTH];
|
||||
u8_t msg_authentication_parameters_len;
|
||||
u8_t msg_privacy_parameters[SNMP_V3_MAX_PRIV_PARAM_LENGTH];
|
||||
u8_t msg_privacy_parameters_len;
|
||||
u8_t context_engine_id[SNMP_V3_MAX_ENGINE_ID_LENGTH];
|
||||
u8_t context_engine_id_len;
|
||||
u8_t context_name[SNMP_V3_MAX_ENGINE_ID_LENGTH];
|
||||
u8_t context_name_len;
|
||||
#endif
|
||||
|
||||
struct pbuf *inbound_pbuf;
|
||||
struct snmp_varbind_enumerator inbound_varbind_enumerator;
|
||||
u16_t inbound_varbind_offset;
|
||||
u16_t inbound_varbind_len;
|
||||
u16_t inbound_padding_len;
|
||||
struct pbuf *inbound_pbuf;
|
||||
struct snmp_varbind_enumerator inbound_varbind_enumerator;
|
||||
u16_t inbound_varbind_offset;
|
||||
u16_t inbound_varbind_len;
|
||||
u16_t inbound_padding_len;
|
||||
|
||||
struct pbuf *outbound_pbuf;
|
||||
struct snmp_pbuf_stream outbound_pbuf_stream;
|
||||
u16_t outbound_pdu_offset;
|
||||
u16_t outbound_error_status_offset;
|
||||
u16_t outbound_error_index_offset;
|
||||
u16_t outbound_varbind_offset;
|
||||
struct pbuf *outbound_pbuf;
|
||||
struct snmp_pbuf_stream outbound_pbuf_stream;
|
||||
u16_t outbound_pdu_offset;
|
||||
u16_t outbound_error_status_offset;
|
||||
u16_t outbound_error_index_offset;
|
||||
u16_t outbound_varbind_offset;
|
||||
#if LWIP_SNMP_V3
|
||||
u16_t outbound_msg_global_data_offset;
|
||||
u16_t outbound_msg_global_data_end;
|
||||
u16_t outbound_msg_security_parameters_str_offset;
|
||||
u16_t outbound_msg_security_parameters_seq_offset;
|
||||
u16_t outbound_msg_security_parameters_end;
|
||||
u16_t outbound_msg_authentication_parameters_offset;
|
||||
u16_t outbound_scoped_pdu_seq_offset;
|
||||
u16_t outbound_scoped_pdu_string_offset;
|
||||
u16_t outbound_msg_global_data_offset;
|
||||
u16_t outbound_msg_global_data_end;
|
||||
u16_t outbound_msg_security_parameters_str_offset;
|
||||
u16_t outbound_msg_security_parameters_seq_offset;
|
||||
u16_t outbound_msg_security_parameters_end;
|
||||
u16_t outbound_msg_authentication_parameters_offset;
|
||||
u16_t outbound_scoped_pdu_seq_offset;
|
||||
u16_t outbound_scoped_pdu_string_offset;
|
||||
#endif
|
||||
|
||||
u8_t value_buffer[SNMP_MAX_VALUE_SIZE];
|
||||
u8_t value_buffer[SNMP_MAX_VALUE_SIZE];
|
||||
};
|
||||
|
||||
/** A helper struct keeping length information about varbinds */
|
||||
struct snmp_varbind_len {
|
||||
u8_t vb_len_len;
|
||||
u16_t vb_value_len;
|
||||
u8_t oid_len_len;
|
||||
u16_t oid_value_len;
|
||||
u8_t value_len_len;
|
||||
u16_t value_value_len;
|
||||
u8_t vb_len_len;
|
||||
u16_t vb_value_len;
|
||||
u8_t oid_len_len;
|
||||
u16_t oid_value_len;
|
||||
u8_t value_len_len;
|
||||
u16_t value_value_len;
|
||||
};
|
||||
|
||||
/** Agent community string */
|
||||
|
@ -45,75 +45,79 @@
|
||||
#include "lwip/prot/iana.h"
|
||||
|
||||
/** SNMP netconn API worker thread */
|
||||
static void snmp_netconn_thread(void *arg)
|
||||
static void
|
||||
snmp_netconn_thread(void *arg)
|
||||
{
|
||||
struct netconn *conn;
|
||||
struct netbuf *buf;
|
||||
err_t err;
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
struct netconn *conn;
|
||||
struct netbuf *buf;
|
||||
err_t err;
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
|
||||
/* Bind to SNMP port with default IP address */
|
||||
/* Bind to SNMP port with default IP address */
|
||||
#if LWIP_IPV6
|
||||
conn = netconn_new(NETCONN_UDP_IPV6);
|
||||
netconn_bind(conn, IP6_ADDR_ANY, LWIP_IANA_PORT_SNMP);
|
||||
conn = netconn_new(NETCONN_UDP_IPV6);
|
||||
netconn_bind(conn, IP6_ADDR_ANY, LWIP_IANA_PORT_SNMP);
|
||||
#else /* LWIP_IPV6 */
|
||||
conn = netconn_new(NETCONN_UDP);
|
||||
netconn_bind(conn, IP4_ADDR_ANY, LWIP_IANA_PORT_SNMP);
|
||||
conn = netconn_new(NETCONN_UDP);
|
||||
netconn_bind(conn, IP4_ADDR_ANY, LWIP_IANA_PORT_SNMP);
|
||||
#endif /* LWIP_IPV6 */
|
||||
LWIP_ERROR("snmp_netconn: invalid conn", (conn != NULL), return;);
|
||||
LWIP_ERROR("snmp_netconn: invalid conn", (conn != NULL), return;);
|
||||
|
||||
snmp_traps_handle = conn;
|
||||
snmp_traps_handle = conn;
|
||||
|
||||
do {
|
||||
err = netconn_recv(conn, &buf);
|
||||
do {
|
||||
err = netconn_recv(conn, &buf);
|
||||
|
||||
if (err == ERR_OK) {
|
||||
snmp_receive(conn, buf->p, &buf->addr, buf->port);
|
||||
}
|
||||
|
||||
if (buf != NULL) {
|
||||
netbuf_delete(buf);
|
||||
}
|
||||
} while (1);
|
||||
}
|
||||
|
||||
err_t snmp_sendto(void *handle, struct pbuf *p, const ip_addr_t *dst, u16_t port)
|
||||
{
|
||||
err_t result;
|
||||
struct netbuf buf;
|
||||
|
||||
memset(&buf, 0, sizeof(buf));
|
||||
buf.p = p;
|
||||
result = netconn_sendto((struct netconn *)handle, &buf, dst, port);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
u8_t snmp_get_local_ip_for_dst(void *handle, const ip_addr_t *dst, ip_addr_t *result)
|
||||
{
|
||||
struct netconn *conn = (struct netconn *)handle;
|
||||
struct netif *dst_if;
|
||||
const ip_addr_t *dst_ip;
|
||||
|
||||
LWIP_UNUSED_ARG(conn); /* unused in case of IPV4 only configuration */
|
||||
|
||||
ip_route_get_local_ip(&conn->pcb.udp->local_ip, dst, dst_if, dst_ip);
|
||||
|
||||
if ((dst_if != NULL) && (dst_ip != NULL)) {
|
||||
ip_addr_copy(*result, *dst_ip);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
if (err == ERR_OK) {
|
||||
snmp_receive(conn, buf->p, &buf->addr, buf->port);
|
||||
}
|
||||
|
||||
if (buf != NULL) {
|
||||
netbuf_delete(buf);
|
||||
}
|
||||
} while (1);
|
||||
}
|
||||
|
||||
err_t
|
||||
snmp_sendto(void *handle, struct pbuf *p, const ip_addr_t *dst, u16_t port)
|
||||
{
|
||||
err_t result;
|
||||
struct netbuf buf;
|
||||
|
||||
memset(&buf, 0, sizeof(buf));
|
||||
buf.p = p;
|
||||
result = netconn_sendto((struct netconn *)handle, &buf, dst, port);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
u8_t
|
||||
snmp_get_local_ip_for_dst(void *handle, const ip_addr_t *dst, ip_addr_t *result)
|
||||
{
|
||||
struct netconn *conn = (struct netconn *)handle;
|
||||
struct netif *dst_if;
|
||||
const ip_addr_t *dst_ip;
|
||||
|
||||
LWIP_UNUSED_ARG(conn); /* unused in case of IPV4 only configuration */
|
||||
|
||||
ip_route_get_local_ip(&conn->pcb.udp->local_ip, dst, dst_if, dst_ip);
|
||||
|
||||
if ((dst_if != NULL) && (dst_ip != NULL)) {
|
||||
ip_addr_copy(*result, *dst_ip);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts SNMP Agent.
|
||||
*/
|
||||
void snmp_init(void)
|
||||
void
|
||||
snmp_init(void)
|
||||
{
|
||||
LWIP_ASSERT_CORE_LOCKED();
|
||||
sys_thread_new("snmp_netconn", snmp_netconn_thread, NULL, SNMP_STACK_SIZE, SNMP_THREAD_PRIO);
|
||||
LWIP_ASSERT_CORE_LOCKED();
|
||||
sys_thread_new("snmp_netconn", snmp_netconn_thread, NULL, SNMP_STACK_SIZE, SNMP_THREAD_PRIO);
|
||||
}
|
||||
|
||||
#endif /* LWIP_SNMP && SNMP_USE_NETCONN */
|
||||
|
@ -43,108 +43,114 @@
|
||||
#include "lwip/def.h"
|
||||
#include <string.h>
|
||||
|
||||
err_t snmp_pbuf_stream_init(struct snmp_pbuf_stream *pbuf_stream, struct pbuf *p, u16_t offset, u16_t length)
|
||||
err_t
|
||||
snmp_pbuf_stream_init(struct snmp_pbuf_stream *pbuf_stream, struct pbuf *p, u16_t offset, u16_t length)
|
||||
{
|
||||
pbuf_stream->offset = offset;
|
||||
pbuf_stream->length = length;
|
||||
pbuf_stream->pbuf = p;
|
||||
pbuf_stream->offset = offset;
|
||||
pbuf_stream->length = length;
|
||||
pbuf_stream->pbuf = p;
|
||||
|
||||
return ERR_OK;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
err_t snmp_pbuf_stream_read(struct snmp_pbuf_stream *pbuf_stream, u8_t *data)
|
||||
err_t
|
||||
snmp_pbuf_stream_read(struct snmp_pbuf_stream *pbuf_stream, u8_t *data)
|
||||
{
|
||||
if (pbuf_stream->length == 0) {
|
||||
return ERR_BUF;
|
||||
}
|
||||
if (pbuf_stream->length == 0) {
|
||||
return ERR_BUF;
|
||||
}
|
||||
|
||||
if (pbuf_copy_partial(pbuf_stream->pbuf, data, 1, pbuf_stream->offset) == 0) {
|
||||
return ERR_BUF;
|
||||
}
|
||||
if (pbuf_copy_partial(pbuf_stream->pbuf, data, 1, pbuf_stream->offset) == 0) {
|
||||
return ERR_BUF;
|
||||
}
|
||||
|
||||
pbuf_stream->offset++;
|
||||
pbuf_stream->length--;
|
||||
pbuf_stream->offset++;
|
||||
pbuf_stream->length--;
|
||||
|
||||
return ERR_OK;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
err_t snmp_pbuf_stream_write(struct snmp_pbuf_stream *pbuf_stream, u8_t data)
|
||||
err_t
|
||||
snmp_pbuf_stream_write(struct snmp_pbuf_stream *pbuf_stream, u8_t data)
|
||||
{
|
||||
return snmp_pbuf_stream_writebuf(pbuf_stream, &data, 1);
|
||||
return snmp_pbuf_stream_writebuf(pbuf_stream, &data, 1);
|
||||
}
|
||||
|
||||
err_t snmp_pbuf_stream_writebuf(struct snmp_pbuf_stream *pbuf_stream, const void *buf, u16_t buf_len)
|
||||
err_t
|
||||
snmp_pbuf_stream_writebuf(struct snmp_pbuf_stream *pbuf_stream, const void *buf, u16_t buf_len)
|
||||
{
|
||||
if (pbuf_stream->length < buf_len) {
|
||||
return ERR_BUF;
|
||||
}
|
||||
if (pbuf_stream->length < buf_len) {
|
||||
return ERR_BUF;
|
||||
}
|
||||
|
||||
if (pbuf_take_at(pbuf_stream->pbuf, buf, buf_len, pbuf_stream->offset) != ERR_OK) {
|
||||
return ERR_BUF;
|
||||
}
|
||||
if (pbuf_take_at(pbuf_stream->pbuf, buf, buf_len, pbuf_stream->offset) != ERR_OK) {
|
||||
return ERR_BUF;
|
||||
}
|
||||
|
||||
pbuf_stream->offset += buf_len;
|
||||
pbuf_stream->length -= buf_len;
|
||||
pbuf_stream->offset += buf_len;
|
||||
pbuf_stream->length -= buf_len;
|
||||
|
||||
return ERR_OK;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
err_t snmp_pbuf_stream_writeto(struct snmp_pbuf_stream *pbuf_stream, struct snmp_pbuf_stream *target_pbuf_stream, u16_t len)
|
||||
err_t
|
||||
snmp_pbuf_stream_writeto(struct snmp_pbuf_stream *pbuf_stream, struct snmp_pbuf_stream *target_pbuf_stream, u16_t len)
|
||||
{
|
||||
if ((pbuf_stream == NULL) || (target_pbuf_stream == NULL)) {
|
||||
return ERR_ARG;
|
||||
|
||||
if ((pbuf_stream == NULL) || (target_pbuf_stream == NULL)) {
|
||||
return ERR_ARG;
|
||||
}
|
||||
if ((len > pbuf_stream->length) || (len > target_pbuf_stream->length)) {
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
if (len == 0) {
|
||||
len = LWIP_MIN(pbuf_stream->length, target_pbuf_stream->length);
|
||||
}
|
||||
|
||||
while (len > 0) {
|
||||
u16_t chunk_len;
|
||||
err_t err;
|
||||
u16_t target_offset;
|
||||
struct pbuf *pbuf = pbuf_skip(pbuf_stream->pbuf, pbuf_stream->offset, &target_offset);
|
||||
|
||||
if ((pbuf == NULL) || (pbuf->len == 0)) {
|
||||
return ERR_BUF;
|
||||
}
|
||||
|
||||
if ((len > pbuf_stream->length) || (len > target_pbuf_stream->length)) {
|
||||
return ERR_ARG;
|
||||
chunk_len = LWIP_MIN(len, pbuf->len);
|
||||
err = snmp_pbuf_stream_writebuf(target_pbuf_stream, &((u8_t *)pbuf->payload)[target_offset], chunk_len);
|
||||
if (err != ERR_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (len == 0) {
|
||||
len = LWIP_MIN(pbuf_stream->length, target_pbuf_stream->length);
|
||||
}
|
||||
pbuf_stream->offset += chunk_len;
|
||||
pbuf_stream->length -= chunk_len;
|
||||
len -= chunk_len;
|
||||
}
|
||||
|
||||
while (len > 0) {
|
||||
u16_t chunk_len;
|
||||
err_t err;
|
||||
u16_t target_offset;
|
||||
struct pbuf *pbuf = pbuf_skip(pbuf_stream->pbuf, pbuf_stream->offset, &target_offset);
|
||||
|
||||
if ((pbuf == NULL) || (pbuf->len == 0)) {
|
||||
return ERR_BUF;
|
||||
}
|
||||
|
||||
chunk_len = LWIP_MIN(len, pbuf->len);
|
||||
err = snmp_pbuf_stream_writebuf(target_pbuf_stream, &((u8_t *)pbuf->payload)[target_offset], chunk_len);
|
||||
|
||||
if (err != ERR_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
pbuf_stream->offset += chunk_len;
|
||||
pbuf_stream->length -= chunk_len;
|
||||
len -= chunk_len;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
err_t snmp_pbuf_stream_seek(struct snmp_pbuf_stream *pbuf_stream, s32_t offset)
|
||||
err_t
|
||||
snmp_pbuf_stream_seek(struct snmp_pbuf_stream *pbuf_stream, s32_t offset)
|
||||
{
|
||||
if ((offset < 0) || (offset > pbuf_stream->length)) {
|
||||
/* we cannot seek backwards or forward behind stream end */
|
||||
return ERR_ARG;
|
||||
}
|
||||
if ((offset < 0) || (offset > pbuf_stream->length)) {
|
||||
/* we cannot seek backwards or forward behind stream end */
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
pbuf_stream->offset += (u16_t)offset;
|
||||
pbuf_stream->length -= (u16_t)offset;
|
||||
pbuf_stream->offset += (u16_t)offset;
|
||||
pbuf_stream->length -= (u16_t)offset;
|
||||
|
||||
return ERR_OK;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
err_t snmp_pbuf_stream_seek_abs(struct snmp_pbuf_stream *pbuf_stream, u32_t offset)
|
||||
err_t
|
||||
snmp_pbuf_stream_seek_abs(struct snmp_pbuf_stream *pbuf_stream, u32_t offset)
|
||||
{
|
||||
s32_t rel_offset = offset - pbuf_stream->offset;
|
||||
return snmp_pbuf_stream_seek(pbuf_stream, rel_offset);
|
||||
s32_t rel_offset = offset - pbuf_stream->offset;
|
||||
return snmp_pbuf_stream_seek(pbuf_stream, rel_offset);
|
||||
}
|
||||
|
||||
#endif /* LWIP_SNMP */
|
||||
|
@ -50,9 +50,9 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
struct snmp_pbuf_stream {
|
||||
struct pbuf *pbuf;
|
||||
u16_t offset;
|
||||
u16_t length;
|
||||
struct pbuf *pbuf;
|
||||
u16_t offset;
|
||||
u16_t length;
|
||||
};
|
||||
|
||||
err_t snmp_pbuf_stream_init(struct snmp_pbuf_stream *pbuf_stream, struct pbuf *p, u16_t offset, u16_t length);
|
||||
|
@ -43,36 +43,39 @@
|
||||
#include "snmp_msg.h"
|
||||
|
||||
/* lwIP UDP receive callback function */
|
||||
static void snmp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
|
||||
static void
|
||||
snmp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
|
||||
{
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
|
||||
snmp_receive(pcb, p, addr, port);
|
||||
snmp_receive(pcb, p, addr, port);
|
||||
|
||||
pbuf_free(p);
|
||||
pbuf_free(p);
|
||||
}
|
||||
|
||||
err_t snmp_sendto(void *handle, struct pbuf *p, const ip_addr_t *dst, u16_t port)
|
||||
err_t
|
||||
snmp_sendto(void *handle, struct pbuf *p, const ip_addr_t *dst, u16_t port)
|
||||
{
|
||||
return udp_sendto((struct udp_pcb *)handle, p, dst, port);
|
||||
return udp_sendto((struct udp_pcb *)handle, p, dst, port);
|
||||
}
|
||||
|
||||
u8_t snmp_get_local_ip_for_dst(void *handle, const ip_addr_t *dst, ip_addr_t *result)
|
||||
u8_t
|
||||
snmp_get_local_ip_for_dst(void *handle, const ip_addr_t *dst, ip_addr_t *result)
|
||||
{
|
||||
struct udp_pcb *udp_pcb = (struct udp_pcb *)handle;
|
||||
struct netif *dst_if;
|
||||
const ip_addr_t *dst_ip;
|
||||
struct udp_pcb *udp_pcb = (struct udp_pcb *)handle;
|
||||
struct netif *dst_if;
|
||||
const ip_addr_t *dst_ip;
|
||||
|
||||
LWIP_UNUSED_ARG(udp_pcb); /* unused in case of IPV4 only configuration */
|
||||
LWIP_UNUSED_ARG(udp_pcb); /* unused in case of IPV4 only configuration */
|
||||
|
||||
ip_route_get_local_ip(&udp_pcb->local_ip, dst, dst_if, dst_ip);
|
||||
ip_route_get_local_ip(&udp_pcb->local_ip, dst, dst_if, dst_ip);
|
||||
|
||||
if ((dst_if != NULL) && (dst_ip != NULL)) {
|
||||
ip_addr_copy(*result, *dst_ip);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
if ((dst_if != NULL) && (dst_ip != NULL)) {
|
||||
ip_addr_copy(*result, *dst_ip);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,20 +83,21 @@ u8_t snmp_get_local_ip_for_dst(void *handle, const ip_addr_t *dst, ip_addr_t *re
|
||||
* Starts SNMP Agent.
|
||||
* Allocates UDP pcb and binds it to IP_ANY_TYPE port 161.
|
||||
*/
|
||||
void snmp_init(void)
|
||||
void
|
||||
snmp_init(void)
|
||||
{
|
||||
err_t err;
|
||||
err_t err;
|
||||
|
||||
struct udp_pcb *snmp_pcb = udp_new_ip_type(IPADDR_TYPE_ANY);
|
||||
LWIP_ERROR("snmp_raw: no PCB", (snmp_pcb != NULL), return;);
|
||||
struct udp_pcb *snmp_pcb = udp_new_ip_type(IPADDR_TYPE_ANY);
|
||||
LWIP_ERROR("snmp_raw: no PCB", (snmp_pcb != NULL), return;);
|
||||
|
||||
LWIP_ASSERT_CORE_LOCKED();
|
||||
LWIP_ASSERT_CORE_LOCKED();
|
||||
|
||||
snmp_traps_handle = snmp_pcb;
|
||||
snmp_traps_handle = snmp_pcb;
|
||||
|
||||
udp_recv(snmp_pcb, snmp_recv, NULL);
|
||||
err = udp_bind(snmp_pcb, IP_ANY_TYPE, LWIP_IANA_PORT_SNMP);
|
||||
LWIP_ERROR("snmp_raw: Unable to bind PCB", (err == ERR_OK), return;);
|
||||
udp_recv(snmp_pcb, snmp_recv, NULL);
|
||||
err = udp_bind(snmp_pcb, IP_ANY_TYPE, LWIP_IANA_PORT_SNMP);
|
||||
LWIP_ERROR("snmp_raw: Unable to bind PCB", (err == ERR_OK), return;);
|
||||
}
|
||||
|
||||
#endif /* LWIP_SNMP && SNMP_USE_RAW */
|
||||
|
@ -43,189 +43,190 @@
|
||||
#include "lwip/apps/snmp_core.h"
|
||||
|
||||
static s16_t snmp_scalar_array_get_value(struct snmp_node_instance *instance, void *value);
|
||||
static snmp_err_t snmp_scalar_array_set_test(struct snmp_node_instance *instance, u16_t value_len, void *value);
|
||||
static snmp_err_t snmp_scalar_array_set_value(struct snmp_node_instance *instance, u16_t value_len, void *value);
|
||||
static snmp_err_t snmp_scalar_array_set_test(struct snmp_node_instance *instance, u16_t value_len, void *value);
|
||||
static snmp_err_t snmp_scalar_array_set_value(struct snmp_node_instance *instance, u16_t value_len, void *value);
|
||||
|
||||
snmp_err_t snmp_scalar_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
|
||||
snmp_err_t
|
||||
snmp_scalar_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
|
||||
{
|
||||
const struct snmp_scalar_node *scalar_node = (const struct snmp_scalar_node *)(const void *)instance->node;
|
||||
const struct snmp_scalar_node *scalar_node = (const struct snmp_scalar_node *)(const void *)instance->node;
|
||||
|
||||
LWIP_UNUSED_ARG(root_oid);
|
||||
LWIP_UNUSED_ARG(root_oid_len);
|
||||
|
||||
/* scalar only has one dedicated instance: .0 */
|
||||
if ((instance->instance_oid.len != 1) || (instance->instance_oid.id[0] != 0)) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
instance->access = scalar_node->access;
|
||||
instance->asn1_type = scalar_node->asn1_type;
|
||||
instance->get_value = scalar_node->get_value;
|
||||
instance->set_test = scalar_node->set_test;
|
||||
instance->set_value = scalar_node->set_value;
|
||||
return SNMP_ERR_NOERROR;
|
||||
}
|
||||
|
||||
snmp_err_t snmp_scalar_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
|
||||
{
|
||||
/* because our only instance is .0 we can only return a next instance if no instance oid is passed */
|
||||
if (instance->instance_oid.len == 0) {
|
||||
instance->instance_oid.len = 1;
|
||||
instance->instance_oid.id[0] = 0;
|
||||
|
||||
return snmp_scalar_get_instance(root_oid, root_oid_len, instance);
|
||||
}
|
||||
LWIP_UNUSED_ARG(root_oid);
|
||||
LWIP_UNUSED_ARG(root_oid_len);
|
||||
|
||||
/* scalar only has one dedicated instance: .0 */
|
||||
if ((instance->instance_oid.len != 1) || (instance->instance_oid.id[0] != 0)) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
instance->access = scalar_node->access;
|
||||
instance->asn1_type = scalar_node->asn1_type;
|
||||
instance->get_value = scalar_node->get_value;
|
||||
instance->set_test = scalar_node->set_test;
|
||||
instance->set_value = scalar_node->set_value;
|
||||
return SNMP_ERR_NOERROR;
|
||||
}
|
||||
|
||||
snmp_err_t snmp_scalar_array_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
|
||||
snmp_err_t
|
||||
snmp_scalar_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
|
||||
{
|
||||
LWIP_UNUSED_ARG(root_oid);
|
||||
LWIP_UNUSED_ARG(root_oid_len);
|
||||
/* because our only instance is .0 we can only return a next instance if no instance oid is passed */
|
||||
if (instance->instance_oid.len == 0) {
|
||||
instance->instance_oid.len = 1;
|
||||
instance->instance_oid.id[0] = 0;
|
||||
|
||||
if ((instance->instance_oid.len == 2) && (instance->instance_oid.id[1] == 0)) {
|
||||
const struct snmp_scalar_array_node *array_node = (const struct snmp_scalar_array_node *)(const void *)instance->node;
|
||||
const struct snmp_scalar_array_node_def *array_node_def = array_node->array_nodes;
|
||||
u32_t i = 0;
|
||||
return snmp_scalar_get_instance(root_oid, root_oid_len, instance);
|
||||
}
|
||||
|
||||
while (i < array_node->array_node_count) {
|
||||
if (array_node_def->oid == instance->instance_oid.id[0]) {
|
||||
break;
|
||||
}
|
||||
|
||||
array_node_def++;
|
||||
i++;
|
||||
}
|
||||
|
||||
if (i < array_node->array_node_count) {
|
||||
instance->access = array_node_def->access;
|
||||
instance->asn1_type = array_node_def->asn1_type;
|
||||
instance->get_value = snmp_scalar_array_get_value;
|
||||
instance->set_test = snmp_scalar_array_set_test;
|
||||
instance->set_value = snmp_scalar_array_set_value;
|
||||
instance->reference.const_ptr = array_node_def;
|
||||
|
||||
return SNMP_ERR_NOERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
snmp_err_t snmp_scalar_array_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
|
||||
|
||||
snmp_err_t
|
||||
snmp_scalar_array_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
|
||||
{
|
||||
LWIP_UNUSED_ARG(root_oid);
|
||||
LWIP_UNUSED_ARG(root_oid_len);
|
||||
|
||||
if ((instance->instance_oid.len == 2) && (instance->instance_oid.id[1] == 0)) {
|
||||
const struct snmp_scalar_array_node *array_node = (const struct snmp_scalar_array_node *)(const void *)instance->node;
|
||||
const struct snmp_scalar_array_node_def *array_node_def = array_node->array_nodes;
|
||||
const struct snmp_scalar_array_node_def *result = NULL;
|
||||
u32_t i = 0;
|
||||
|
||||
LWIP_UNUSED_ARG(root_oid);
|
||||
LWIP_UNUSED_ARG(root_oid_len);
|
||||
while (i < array_node->array_node_count) {
|
||||
if (array_node_def->oid == instance->instance_oid.id[0]) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ((instance->instance_oid.len == 0) && (array_node->array_node_count > 0)) {
|
||||
/* return node with lowest OID */
|
||||
u16_t i = 0;
|
||||
array_node_def++;
|
||||
i++;
|
||||
}
|
||||
|
||||
if (i < array_node->array_node_count) {
|
||||
instance->access = array_node_def->access;
|
||||
instance->asn1_type = array_node_def->asn1_type;
|
||||
instance->get_value = snmp_scalar_array_get_value;
|
||||
instance->set_test = snmp_scalar_array_set_test;
|
||||
instance->set_value = snmp_scalar_array_set_value;
|
||||
instance->reference.const_ptr = array_node_def;
|
||||
|
||||
return SNMP_ERR_NOERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
snmp_err_t
|
||||
snmp_scalar_array_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
|
||||
{
|
||||
const struct snmp_scalar_array_node *array_node = (const struct snmp_scalar_array_node *)(const void *)instance->node;
|
||||
const struct snmp_scalar_array_node_def *array_node_def = array_node->array_nodes;
|
||||
const struct snmp_scalar_array_node_def *result = NULL;
|
||||
|
||||
LWIP_UNUSED_ARG(root_oid);
|
||||
LWIP_UNUSED_ARG(root_oid_len);
|
||||
|
||||
if ((instance->instance_oid.len == 0) && (array_node->array_node_count > 0)) {
|
||||
/* return node with lowest OID */
|
||||
u16_t i = 0;
|
||||
|
||||
result = array_node_def;
|
||||
array_node_def++;
|
||||
|
||||
for (i = 1; i < array_node->array_node_count; i++) {
|
||||
if (array_node_def->oid < result->oid) {
|
||||
result = array_node_def;
|
||||
}
|
||||
array_node_def++;
|
||||
}
|
||||
} else if (instance->instance_oid.len >= 1) {
|
||||
if (instance->instance_oid.len == 1) {
|
||||
/* if we have the requested OID we return its instance, otherwise we search for the next available */
|
||||
u16_t i = 0;
|
||||
while (i < array_node->array_node_count) {
|
||||
if (array_node_def->oid == instance->instance_oid.id[0]) {
|
||||
result = array_node_def;
|
||||
break;
|
||||
}
|
||||
|
||||
array_node_def++;
|
||||
|
||||
for (i = 1; i < array_node->array_node_count; i++) {
|
||||
if (array_node_def->oid < result->oid) {
|
||||
result = array_node_def;
|
||||
}
|
||||
|
||||
array_node_def++;
|
||||
}
|
||||
} else if (instance->instance_oid.len >= 1) {
|
||||
if (instance->instance_oid.len == 1) {
|
||||
/* if we have the requested OID we return its instance, otherwise we search for the next available */
|
||||
u16_t i = 0;
|
||||
|
||||
while (i < array_node->array_node_count) {
|
||||
if (array_node_def->oid == instance->instance_oid.id[0]) {
|
||||
result = array_node_def;
|
||||
break;
|
||||
}
|
||||
|
||||
array_node_def++;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (result == NULL) {
|
||||
u32_t oid_dist = 0xFFFFFFFFUL;
|
||||
u16_t i = 0;
|
||||
array_node_def = array_node->array_nodes; /* may be already at the end when if case before was executed without result -> reinitialize to start */
|
||||
|
||||
while (i < array_node->array_node_count) {
|
||||
if ((array_node_def->oid > instance->instance_oid.id[0]) &&
|
||||
((u32_t)(array_node_def->oid - instance->instance_oid.id[0]) < oid_dist)) {
|
||||
result = array_node_def;
|
||||
oid_dist = array_node_def->oid - instance->instance_oid.id[0];
|
||||
}
|
||||
|
||||
array_node_def++;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (result == NULL) {
|
||||
/* nothing to return */
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
u32_t oid_dist = 0xFFFFFFFFUL;
|
||||
u16_t i = 0;
|
||||
array_node_def = array_node->array_nodes; /* may be already at the end when if case before was executed without result -> reinitialize to start */
|
||||
while (i < array_node->array_node_count) {
|
||||
if ((array_node_def->oid > instance->instance_oid.id[0]) &&
|
||||
((u32_t)(array_node_def->oid - instance->instance_oid.id[0]) < oid_dist)) {
|
||||
result = array_node_def;
|
||||
oid_dist = array_node_def->oid - instance->instance_oid.id[0];
|
||||
}
|
||||
|
||||
array_node_def++;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
instance->instance_oid.len = 2;
|
||||
instance->instance_oid.id[0] = result->oid;
|
||||
instance->instance_oid.id[1] = 0;
|
||||
if (result == NULL) {
|
||||
/* nothing to return */
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
instance->access = result->access;
|
||||
instance->asn1_type = result->asn1_type;
|
||||
instance->get_value = snmp_scalar_array_get_value;
|
||||
instance->set_test = snmp_scalar_array_set_test;
|
||||
instance->set_value = snmp_scalar_array_set_value;
|
||||
instance->reference.const_ptr = result;
|
||||
instance->instance_oid.len = 2;
|
||||
instance->instance_oid.id[0] = result->oid;
|
||||
instance->instance_oid.id[1] = 0;
|
||||
|
||||
return SNMP_ERR_NOERROR;
|
||||
instance->access = result->access;
|
||||
instance->asn1_type = result->asn1_type;
|
||||
instance->get_value = snmp_scalar_array_get_value;
|
||||
instance->set_test = snmp_scalar_array_set_test;
|
||||
instance->set_value = snmp_scalar_array_set_value;
|
||||
instance->reference.const_ptr = result;
|
||||
|
||||
return SNMP_ERR_NOERROR;
|
||||
}
|
||||
|
||||
static s16_t snmp_scalar_array_get_value(struct snmp_node_instance *instance, void *value)
|
||||
static s16_t
|
||||
snmp_scalar_array_get_value(struct snmp_node_instance *instance, void *value)
|
||||
{
|
||||
s16_t result = -1;
|
||||
const struct snmp_scalar_array_node *array_node = (const struct snmp_scalar_array_node *)(const void *)instance->node;
|
||||
const struct snmp_scalar_array_node_def *array_node_def = (const struct snmp_scalar_array_node_def *)instance->reference.const_ptr;
|
||||
s16_t result = -1;
|
||||
const struct snmp_scalar_array_node *array_node = (const struct snmp_scalar_array_node *)(const void *)instance->node;
|
||||
const struct snmp_scalar_array_node_def *array_node_def = (const struct snmp_scalar_array_node_def *)instance->reference.const_ptr;
|
||||
|
||||
if (array_node->get_value != NULL) {
|
||||
result = array_node->get_value(array_node_def, value);
|
||||
}
|
||||
|
||||
return result;
|
||||
if (array_node->get_value != NULL) {
|
||||
result = array_node->get_value(array_node_def, value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static snmp_err_t snmp_scalar_array_set_test(struct snmp_node_instance *instance, u16_t value_len, void *value)
|
||||
static snmp_err_t
|
||||
snmp_scalar_array_set_test(struct snmp_node_instance *instance, u16_t value_len, void *value)
|
||||
{
|
||||
snmp_err_t result = SNMP_ERR_NOTWRITABLE;
|
||||
const struct snmp_scalar_array_node *array_node = (const struct snmp_scalar_array_node *)(const void *)instance->node;
|
||||
const struct snmp_scalar_array_node_def *array_node_def = (const struct snmp_scalar_array_node_def *)instance->reference.const_ptr;
|
||||
snmp_err_t result = SNMP_ERR_NOTWRITABLE;
|
||||
const struct snmp_scalar_array_node *array_node = (const struct snmp_scalar_array_node *)(const void *)instance->node;
|
||||
const struct snmp_scalar_array_node_def *array_node_def = (const struct snmp_scalar_array_node_def *)instance->reference.const_ptr;
|
||||
|
||||
if (array_node->set_test != NULL) {
|
||||
result = array_node->set_test(array_node_def, value_len, value);
|
||||
}
|
||||
|
||||
return result;
|
||||
if (array_node->set_test != NULL) {
|
||||
result = array_node->set_test(array_node_def, value_len, value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static snmp_err_t snmp_scalar_array_set_value(struct snmp_node_instance *instance, u16_t value_len, void *value)
|
||||
static snmp_err_t
|
||||
snmp_scalar_array_set_value(struct snmp_node_instance *instance, u16_t value_len, void *value)
|
||||
{
|
||||
snmp_err_t result = SNMP_ERR_NOTWRITABLE;
|
||||
const struct snmp_scalar_array_node *array_node = (const struct snmp_scalar_array_node *)(const void *)instance->node;
|
||||
const struct snmp_scalar_array_node_def *array_node_def = (const struct snmp_scalar_array_node_def *)instance->reference.const_ptr;
|
||||
snmp_err_t result = SNMP_ERR_NOTWRITABLE;
|
||||
const struct snmp_scalar_array_node *array_node = (const struct snmp_scalar_array_node *)(const void *)instance->node;
|
||||
const struct snmp_scalar_array_node_def *array_node_def = (const struct snmp_scalar_array_node_def *)instance->reference.const_ptr;
|
||||
|
||||
if (array_node->set_value != NULL) {
|
||||
result = array_node->set_value(array_node_def, value_len, value);
|
||||
}
|
||||
|
||||
return result;
|
||||
if (array_node->set_value != NULL) {
|
||||
result = array_node->set_value(array_node_def, value_len, value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif /* LWIP_SNMP */
|
||||
|
@ -18,7 +18,7 @@ Generated by LwipMibCompiler
|
||||
|
||||
#include <string.h>
|
||||
|
||||
const struct snmp_obj_id usmNoAuthProtocol = { 10, { 1, 3, 6, 1, 6, 3, 10, 1, 1, 1 } };
|
||||
const struct snmp_obj_id usmNoAuthProtocol = { 10, { 1, 3, 6, 1, 6, 3, 10, 1, 1, 1 } };
|
||||
const struct snmp_obj_id usmHMACMD5AuthProtocol = { 10, { 1, 3, 6, 1, 6, 3, 10, 1, 1, 2 } };
|
||||
const struct snmp_obj_id usmHMACSHAAuthProtocol = { 10, { 1, 3, 6, 1, 6, 3, 10, 1, 1, 3 } };
|
||||
/* .4 sha-224
|
||||
@ -27,7 +27,7 @@ const struct snmp_obj_id usmHMACSHAAuthProtocol = { 10, { 1, 3, 6, 1, 6, 3, 10,
|
||||
* .7 sha-512
|
||||
*/
|
||||
|
||||
const struct snmp_obj_id usmNoPrivProtocol = { 10, { 1, 3, 6, 1, 6, 3, 10, 1, 2, 1 } };
|
||||
const struct snmp_obj_id usmNoPrivProtocol = { 10, { 1, 3, 6, 1, 6, 3, 10, 1, 2, 1 } };
|
||||
const struct snmp_obj_id usmDESPrivProtocol = { 10, { 1, 3, 6, 1, 6, 3, 10, 1, 2, 2 } };
|
||||
/* .3 3des-ede */
|
||||
const struct snmp_obj_id usmAESPrivProtocol = { 10, { 1, 3, 6, 1, 6, 3, 10, 1, 2, 4 } };
|
||||
@ -42,53 +42,49 @@ const struct snmp_obj_id usmAESPrivProtocol = { 10, { 1, 3, 6, 1, 6, 3, 10, 1, 2
|
||||
/* --- snmpFrameworkMIBObjects 1.3.6.1.6.3.10.2 ----------------------------------------------------- */
|
||||
static s16_t snmpengine_scalars_get_value(const struct snmp_scalar_array_node_def *node, void *value)
|
||||
{
|
||||
const char *engineid;
|
||||
u8_t engineid_len;
|
||||
const char *engineid;
|
||||
u8_t engineid_len;
|
||||
|
||||
switch (node->oid) {
|
||||
case 1: /* snmpEngineID */
|
||||
snmpv3_get_engine_id(&engineid, &engineid_len);
|
||||
MEMCPY(value, engineid, engineid_len);
|
||||
return engineid_len;
|
||||
|
||||
case 2: /* snmpEngineBoots */
|
||||
*(s32_t *)value = snmpv3_get_engine_boots_internal();
|
||||
return sizeof(s32_t);
|
||||
|
||||
case 3: /* snmpEngineTime */
|
||||
*(s32_t *)value = snmpv3_get_engine_time_internal();
|
||||
return sizeof(s32_t);
|
||||
|
||||
case 4: /* snmpEngineMaxMessageSize */
|
||||
*(s32_t *)value = SNMP_FRAMEWORKMIB_SNMPENGINEMAXMESSAGESIZE;
|
||||
return sizeof(s32_t);
|
||||
|
||||
default:
|
||||
LWIP_DEBUGF(SNMP_MIB_DEBUG, ("snmpengine_scalars_get_value(): unknown id: %" S32_F "\n", node->oid));
|
||||
return 0;
|
||||
}
|
||||
switch (node->oid) {
|
||||
case 1: /* snmpEngineID */
|
||||
snmpv3_get_engine_id(&engineid, &engineid_len);
|
||||
MEMCPY(value, engineid, engineid_len);
|
||||
return engineid_len;
|
||||
case 2: /* snmpEngineBoots */
|
||||
*(s32_t *)value = snmpv3_get_engine_boots_internal();
|
||||
return sizeof(s32_t);
|
||||
case 3: /* snmpEngineTime */
|
||||
*(s32_t *)value = snmpv3_get_engine_time_internal();
|
||||
return sizeof(s32_t);
|
||||
case 4: /* snmpEngineMaxMessageSize */
|
||||
*(s32_t *)value = SNMP_FRAMEWORKMIB_SNMPENGINEMAXMESSAGESIZE;
|
||||
return sizeof(s32_t);
|
||||
default:
|
||||
LWIP_DEBUGF(SNMP_MIB_DEBUG, ("snmpengine_scalars_get_value(): unknown id: %"S32_F"\n", node->oid));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static const struct snmp_scalar_array_node_def snmpengine_scalars_nodes[] = {
|
||||
{ 1, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpEngineID */
|
||||
{ 2, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpEngineBoots */
|
||||
{ 3, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpEngineTime */
|
||||
{ 4, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_ONLY }, /* snmpEngineMaxMessageSize */
|
||||
{1, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpEngineID */
|
||||
{2, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpEngineBoots */
|
||||
{3, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpEngineTime */
|
||||
{4, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_ONLY}, /* snmpEngineMaxMessageSize */
|
||||
};
|
||||
static const struct snmp_scalar_array_node snmpengine_scalars = SNMP_SCALAR_CREATE_ARRAY_NODE(1, snmpengine_scalars_nodes, snmpengine_scalars_get_value, NULL, NULL);
|
||||
|
||||
static const struct snmp_node *const snmpframeworkmibobjects_subnodes[] = {
|
||||
&snmpengine_scalars.node.node
|
||||
&snmpengine_scalars.node.node
|
||||
};
|
||||
static const struct snmp_tree_node snmpframeworkmibobjects_treenode = SNMP_CREATE_TREE_NODE(2, snmpframeworkmibobjects_subnodes);
|
||||
|
||||
/* --- snmpFrameworkMIB ----------------------------------------------------- */
|
||||
static const struct snmp_node *const snmpframeworkmib_subnodes[] = {
|
||||
&snmpframeworkmibobjects_treenode.node
|
||||
&snmpframeworkmibobjects_treenode.node
|
||||
};
|
||||
static const struct snmp_tree_node snmpframeworkmib_root = SNMP_CREATE_TREE_NODE(10, snmpframeworkmib_subnodes);
|
||||
static const u32_t snmpframeworkmib_base_oid[] = { 1, 3, 6, 1, 6, 3, 10 };
|
||||
const struct snmp_mib snmpframeworkmib = { snmpframeworkmib_base_oid, LWIP_ARRAYSIZE(snmpframeworkmib_base_oid), &snmpframeworkmib_root.node };
|
||||
static const u32_t snmpframeworkmib_base_oid[] = {1, 3, 6, 1, 6, 3, 10};
|
||||
const struct snmp_mib snmpframeworkmib = {snmpframeworkmib_base_oid, LWIP_ARRAYSIZE(snmpframeworkmib_base_oid), &snmpframeworkmib_root.node};
|
||||
|
||||
/* --- snmpFrameworkMIB ----------------------------------------------------- */
|
||||
#endif /* LWIP_SNMP */
|
||||
|
@ -20,165 +20,140 @@ Generated by LwipMibCompiler
|
||||
/* --- usmUser 1.3.6.1.6.3.15.1.2 ----------------------------------------------------- */
|
||||
|
||||
static const struct snmp_oid_range usmUserTable_oid_ranges[] = {
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff },
|
||||
{ 0, 0xff }
|
||||
{ 0, 0xff }, { 0, 0xff }, { 0, 0xff }, { 0, 0xff },
|
||||
{ 0, 0xff }, { 0, 0xff }, { 0, 0xff }, { 0, 0xff },
|
||||
{ 0, 0xff }, { 0, 0xff }, { 0, 0xff }, { 0, 0xff },
|
||||
{ 0, 0xff }, { 0, 0xff }, { 0, 0xff }, { 0, 0xff },
|
||||
{ 0, 0xff }, { 0, 0xff }, { 0, 0xff }, { 0, 0xff },
|
||||
{ 0, 0xff }, { 0, 0xff }, { 0, 0xff }, { 0, 0xff },
|
||||
{ 0, 0xff }, { 0, 0xff }, { 0, 0xff }, { 0, 0xff },
|
||||
{ 0, 0xff }, { 0, 0xff }, { 0, 0xff }, { 0, 0xff }
|
||||
};
|
||||
|
||||
static void snmp_engineid_to_oid(const char *engineid, u32_t *oid, u32_t len)
|
||||
{
|
||||
u8_t i;
|
||||
u8_t i;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
oid[i] = engineid[i];
|
||||
}
|
||||
for (i = 0; i < len; i++) {
|
||||
oid[i] = engineid[i];
|
||||
}
|
||||
}
|
||||
|
||||
static void snmp_oid_to_name(char *name, const u32_t *oid, size_t len)
|
||||
{
|
||||
u8_t i;
|
||||
u8_t i;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
name[i] = (char)oid[i];
|
||||
}
|
||||
for (i = 0; i < len; i++) {
|
||||
name[i] = (char)oid[i];
|
||||
}
|
||||
}
|
||||
|
||||
static void snmp_name_to_oid(const char *name, u32_t *oid, size_t len)
|
||||
{
|
||||
u8_t i;
|
||||
u8_t i;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
oid[i] = name[i];
|
||||
}
|
||||
for (i = 0; i < len; i++) {
|
||||
oid[i] = name[i];
|
||||
}
|
||||
}
|
||||
|
||||
static const struct snmp_obj_id *snmp_auth_algo_to_oid(snmpv3_auth_algo_t algo)
|
||||
{
|
||||
if (algo == SNMP_V3_AUTH_ALGO_MD5) {
|
||||
return &usmHMACMD5AuthProtocol;
|
||||
} else if (algo == SNMP_V3_AUTH_ALGO_SHA) {
|
||||
return &usmHMACMD5AuthProtocol;
|
||||
}
|
||||
if (algo == SNMP_V3_AUTH_ALGO_MD5) {
|
||||
return &usmHMACMD5AuthProtocol;
|
||||
} else if (algo == SNMP_V3_AUTH_ALGO_SHA) {
|
||||
return &usmHMACMD5AuthProtocol;
|
||||
}
|
||||
|
||||
return &usmNoAuthProtocol;
|
||||
return &usmNoAuthProtocol;
|
||||
}
|
||||
|
||||
static const struct snmp_obj_id *snmp_priv_algo_to_oid(snmpv3_priv_algo_t algo)
|
||||
{
|
||||
if (algo == SNMP_V3_PRIV_ALGO_DES) {
|
||||
return &usmDESPrivProtocol;
|
||||
} else if (algo == SNMP_V3_PRIV_ALGO_AES) {
|
||||
return &usmAESPrivProtocol;
|
||||
}
|
||||
if (algo == SNMP_V3_PRIV_ALGO_DES) {
|
||||
return &usmDESPrivProtocol;
|
||||
} else if (algo == SNMP_V3_PRIV_ALGO_AES) {
|
||||
return &usmAESPrivProtocol;
|
||||
}
|
||||
|
||||
return &usmNoPrivProtocol;
|
||||
return &usmNoPrivProtocol;
|
||||
}
|
||||
|
||||
char username[32];
|
||||
|
||||
static snmp_err_t usmusertable_get_instance(const u32_t *column, const u32_t *row_oid, u8_t row_oid_len, struct snmp_node_instance *cell_instance)
|
||||
{
|
||||
const char *engineid;
|
||||
u8_t eid_len;
|
||||
const char *engineid;
|
||||
u8_t eid_len;
|
||||
|
||||
u32_t engineid_oid[SNMP_V3_MAX_ENGINE_ID_LENGTH];
|
||||
u32_t engineid_oid[SNMP_V3_MAX_ENGINE_ID_LENGTH];
|
||||
|
||||
u8_t name_len;
|
||||
u8_t engineid_len;
|
||||
u8_t name_len;
|
||||
u8_t engineid_len;
|
||||
|
||||
u8_t name_start;
|
||||
u8_t engineid_start;
|
||||
u8_t name_start;
|
||||
u8_t engineid_start;
|
||||
|
||||
LWIP_UNUSED_ARG(column);
|
||||
LWIP_UNUSED_ARG(column);
|
||||
|
||||
snmpv3_get_engine_id(&engineid, &eid_len);
|
||||
snmpv3_get_engine_id(&engineid, &eid_len);
|
||||
|
||||
engineid_len = (u8_t)row_oid[0];
|
||||
engineid_start = 1;
|
||||
engineid_len = (u8_t)row_oid[0];
|
||||
engineid_start = 1;
|
||||
|
||||
if (engineid_len != eid_len) {
|
||||
/* EngineID length does not match! */
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
if (engineid_len != eid_len) {
|
||||
/* EngineID length does not match! */
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
if (engineid_len > row_oid_len) {
|
||||
/* row OID doesn't contain enough data according to engineid_len.*/
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
if (engineid_len > row_oid_len) {
|
||||
/* row OID doesn't contain enough data according to engineid_len.*/
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
/* check if incoming OID length and if values are in plausible range */
|
||||
if (!snmp_oid_in_range(&row_oid[engineid_start], engineid_len, usmUserTable_oid_ranges, engineid_len)) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
/* check if incoming OID length and if values are in plausible range */
|
||||
if (!snmp_oid_in_range(&row_oid[engineid_start], engineid_len, usmUserTable_oid_ranges, engineid_len)) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
snmp_engineid_to_oid(engineid, engineid_oid, engineid_len);
|
||||
snmp_engineid_to_oid(engineid, engineid_oid, engineid_len);
|
||||
|
||||
/* Verify EngineID */
|
||||
if (snmp_oid_equal(&row_oid[engineid_start], engineid_len, engineid_oid, engineid_len)) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
/* Verify EngineID */
|
||||
if (snmp_oid_equal(&row_oid[engineid_start], engineid_len, engineid_oid, engineid_len)) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
name_len = (u8_t)row_oid[engineid_start + engineid_len];
|
||||
name_start = engineid_start + engineid_len + 1;
|
||||
name_len = (u8_t)row_oid[engineid_start + engineid_len];
|
||||
name_start = engineid_start + engineid_len + 1;
|
||||
|
||||
if (name_len > SNMP_V3_MAX_USER_LENGTH) {
|
||||
/* specified name is too long */
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
if (name_len > SNMP_V3_MAX_USER_LENGTH) {
|
||||
/* specified name is too long */
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
if (1 + engineid_len + 1 + name_len != row_oid_len) {
|
||||
/* Length of EngineID and name does not match row oid length. (+2 for length fields)*/
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
if (1 + engineid_len + 1 + name_len != row_oid_len) {
|
||||
/* Length of EngineID and name does not match row oid length. (+2 for length fields)*/
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
/* check if incoming OID length and if values are in plausible range */
|
||||
if (!snmp_oid_in_range(&row_oid[name_start], name_len, usmUserTable_oid_ranges, name_len)) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
/* check if incoming OID length and if values are in plausible range */
|
||||
if (!snmp_oid_in_range(&row_oid[name_start], name_len, usmUserTable_oid_ranges, name_len)) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
/* Verify if user exists */
|
||||
memset(username, 0, sizeof(username));
|
||||
snmp_oid_to_name(username, &row_oid[name_start], name_len);
|
||||
/* Verify if user exists */
|
||||
memset(username, 0, sizeof(username));
|
||||
snmp_oid_to_name(username, &row_oid[name_start], name_len);
|
||||
if (snmpv3_get_user(username, NULL, NULL, NULL, NULL) != ERR_OK) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
if (snmpv3_get_user(username, NULL, NULL, NULL, NULL) != ERR_OK) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
/* Save name in reference pointer to make it easier to handle later on */
|
||||
cell_instance->reference.ptr = username;
|
||||
cell_instance->reference_len = name_len;
|
||||
|
||||
/* Save name in reference pointer to make it easier to handle later on */
|
||||
cell_instance->reference.ptr = username;
|
||||
cell_instance->reference_len = name_len;
|
||||
|
||||
/* user was found */
|
||||
return SNMP_ERR_NOERROR;
|
||||
/* user was found */
|
||||
return SNMP_ERR_NOERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -194,217 +169,193 @@ static snmp_err_t usmusertable_get_instance(const u32_t *column, const u32_t *ro
|
||||
*/
|
||||
static snmp_err_t usmusertable_get_next_instance(const u32_t *column, struct snmp_obj_id *row_oid, struct snmp_node_instance *cell_instance)
|
||||
{
|
||||
const char *engineid;
|
||||
u8_t eid_len;
|
||||
const char *engineid;
|
||||
u8_t eid_len;
|
||||
|
||||
u32_t engineid_oid[SNMP_V3_MAX_ENGINE_ID_LENGTH];
|
||||
u32_t engineid_oid[SNMP_V3_MAX_ENGINE_ID_LENGTH];
|
||||
|
||||
u8_t name_len;
|
||||
u8_t engineid_len;
|
||||
u8_t name_len;
|
||||
u8_t engineid_len;
|
||||
|
||||
u8_t name_start;
|
||||
u8_t engineid_start = 1;
|
||||
u8_t i;
|
||||
u8_t name_start;
|
||||
u8_t engineid_start = 1;
|
||||
u8_t i;
|
||||
|
||||
struct snmp_next_oid_state state;
|
||||
struct snmp_next_oid_state state;
|
||||
|
||||
u32_t result_temp[LWIP_ARRAYSIZE(usmUserTable_oid_ranges)];
|
||||
u32_t result_temp[LWIP_ARRAYSIZE(usmUserTable_oid_ranges)];
|
||||
|
||||
LWIP_UNUSED_ARG(column);
|
||||
LWIP_UNUSED_ARG(column);
|
||||
|
||||
snmpv3_get_engine_id(&engineid, &eid_len);
|
||||
snmpv3_get_engine_id(&engineid, &eid_len);
|
||||
|
||||
/* If EngineID might be given */
|
||||
if (row_oid->len > 0) {
|
||||
engineid_len = (u8_t)row_oid->id[0];
|
||||
engineid_start = 1;
|
||||
/* If EngineID might be given */
|
||||
if (row_oid->len > 0) {
|
||||
engineid_len = (u8_t)row_oid->id[0];
|
||||
engineid_start = 1;
|
||||
|
||||
if (engineid_len != eid_len) {
|
||||
/* EngineID length does not match! */
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
if (engineid_len > row_oid->len) {
|
||||
/* Verify partial EngineID */
|
||||
snmp_engineid_to_oid(engineid, engineid_oid, row_oid->len - 1);
|
||||
|
||||
if (!snmp_oid_equal(&row_oid->id[engineid_start], row_oid->len - 1, engineid_oid, row_oid->len - 1)) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
} else {
|
||||
/* Verify complete EngineID */
|
||||
snmp_engineid_to_oid(engineid, engineid_oid, engineid_len);
|
||||
|
||||
if (!snmp_oid_equal(&row_oid->id[engineid_start], engineid_len, engineid_oid, engineid_len)) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
/* At this point, the given EngineID (partially) matches the local EngineID.*/
|
||||
|
||||
/* If name might also be given */
|
||||
if (row_oid->len > engineid_start + engineid_len) {
|
||||
name_len = (u8_t)row_oid->id[engineid_start + engineid_len];
|
||||
name_start = engineid_start + engineid_len + 1;
|
||||
|
||||
if (name_len > SNMP_V3_MAX_USER_LENGTH) {
|
||||
/* specified name is too long, max length is 32 according to mib file.*/
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
if (row_oid->len < engineid_len + name_len + 2) {
|
||||
/* Partial name given according to oid.*/
|
||||
u8_t tmplen = row_oid->len - engineid_len - 2;
|
||||
|
||||
if (!snmp_oid_in_range(&row_oid->id[name_start], tmplen, usmUserTable_oid_ranges, tmplen)) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
} else {
|
||||
/* Full name given according to oid. Also test for too much data.*/
|
||||
u8_t tmplen = row_oid->len - engineid_len - 2;
|
||||
|
||||
if (!snmp_oid_in_range(&row_oid->id[name_start], name_len, usmUserTable_oid_ranges, tmplen)) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
/* At this point the EngineID and (partial) UserName match the local EngineID and UserName.*/
|
||||
}
|
||||
if (engineid_len != eid_len) {
|
||||
/* EngineID length does not match! */
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
/* init struct to search next oid */
|
||||
snmp_next_oid_init(&state, row_oid->id, row_oid->len, result_temp, LWIP_ARRAYSIZE(usmUserTable_oid_ranges));
|
||||
|
||||
for (i = 0; i < snmpv3_get_amount_of_users(); i++) {
|
||||
u32_t test_oid[LWIP_ARRAYSIZE(usmUserTable_oid_ranges)];
|
||||
|
||||
test_oid[0] = eid_len;
|
||||
snmp_engineid_to_oid(engineid, &test_oid[1], eid_len);
|
||||
|
||||
snmpv3_get_username(username, i);
|
||||
|
||||
test_oid[1 + eid_len] = strlen(username);
|
||||
snmp_name_to_oid(username, &test_oid[2 + eid_len], strlen(username));
|
||||
|
||||
/* check generated OID: is it a candidate for the next one? */
|
||||
snmp_next_oid_check(&state, test_oid, (u8_t)(1 + eid_len + 1 + strlen(username)), LWIP_PTR_NUMERIC_CAST(void *, i));
|
||||
if (engineid_len > row_oid->len) {
|
||||
/* Verify partial EngineID */
|
||||
snmp_engineid_to_oid(engineid, engineid_oid, row_oid->len - 1);
|
||||
if (!snmp_oid_equal(&row_oid->id[engineid_start], row_oid->len - 1, engineid_oid, row_oid->len - 1)) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
} else {
|
||||
/* Verify complete EngineID */
|
||||
snmp_engineid_to_oid(engineid, engineid_oid, engineid_len);
|
||||
if (!snmp_oid_equal(&row_oid->id[engineid_start], engineid_len, engineid_oid, engineid_len)) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
/* did we find a next one? */
|
||||
if (state.status == SNMP_NEXT_OID_STATUS_SUCCESS) {
|
||||
snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len);
|
||||
/* store username for subsequent operations (get/test/set) */
|
||||
memset(username, 0, sizeof(username));
|
||||
snmpv3_get_username(username, LWIP_PTR_NUMERIC_CAST(u8_t, state.reference));
|
||||
cell_instance->reference.ptr = username;
|
||||
cell_instance->reference_len = strlen(username);
|
||||
return SNMP_ERR_NOERROR;
|
||||
}
|
||||
/* At this point, the given EngineID (partially) matches the local EngineID.*/
|
||||
|
||||
/* not found */
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
/* If name might also be given */
|
||||
if (row_oid->len > engineid_start + engineid_len) {
|
||||
name_len = (u8_t)row_oid->id[engineid_start + engineid_len];
|
||||
name_start = engineid_start + engineid_len + 1;
|
||||
|
||||
if (name_len > SNMP_V3_MAX_USER_LENGTH) {
|
||||
/* specified name is too long, max length is 32 according to mib file.*/
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
if (row_oid->len < engineid_len + name_len + 2) {
|
||||
/* Partial name given according to oid.*/
|
||||
u8_t tmplen = row_oid->len - engineid_len - 2;
|
||||
if (!snmp_oid_in_range(&row_oid->id[name_start], tmplen, usmUserTable_oid_ranges, tmplen)) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
} else {
|
||||
/* Full name given according to oid. Also test for too much data.*/
|
||||
u8_t tmplen = row_oid->len - engineid_len - 2;
|
||||
if (!snmp_oid_in_range(&row_oid->id[name_start], name_len, usmUserTable_oid_ranges, tmplen)) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
/* At this point the EngineID and (partial) UserName match the local EngineID and UserName.*/
|
||||
}
|
||||
}
|
||||
|
||||
/* init struct to search next oid */
|
||||
snmp_next_oid_init(&state, row_oid->id, row_oid->len, result_temp, LWIP_ARRAYSIZE(usmUserTable_oid_ranges));
|
||||
|
||||
for (i = 0; i < snmpv3_get_amount_of_users(); i++) {
|
||||
u32_t test_oid[LWIP_ARRAYSIZE(usmUserTable_oid_ranges)];
|
||||
|
||||
test_oid[0] = eid_len;
|
||||
snmp_engineid_to_oid(engineid, &test_oid[1], eid_len);
|
||||
|
||||
snmpv3_get_username(username, i);
|
||||
|
||||
test_oid[1 + eid_len] = strlen(username);
|
||||
snmp_name_to_oid(username, &test_oid[2 + eid_len], strlen(username));
|
||||
|
||||
/* check generated OID: is it a candidate for the next one? */
|
||||
snmp_next_oid_check(&state, test_oid, (u8_t)(1 + eid_len + 1 + strlen(username)), LWIP_PTR_NUMERIC_CAST(void *, i));
|
||||
}
|
||||
|
||||
/* did we find a next one? */
|
||||
if (state.status == SNMP_NEXT_OID_STATUS_SUCCESS) {
|
||||
snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len);
|
||||
/* store username for subsequent operations (get/test/set) */
|
||||
memset(username, 0, sizeof(username));
|
||||
snmpv3_get_username(username, LWIP_PTR_NUMERIC_CAST(u8_t, state.reference));
|
||||
cell_instance->reference.ptr = username;
|
||||
cell_instance->reference_len = strlen(username);
|
||||
return SNMP_ERR_NOERROR;
|
||||
}
|
||||
|
||||
/* not found */
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
static s16_t usmusertable_get_value(struct snmp_node_instance *cell_instance, void *value)
|
||||
{
|
||||
snmpv3_user_storagetype_t storage_type;
|
||||
snmpv3_user_storagetype_t storage_type;
|
||||
|
||||
switch (SNMP_TABLE_GET_COLUMN_FROM_OID(cell_instance->instance_oid.id)) {
|
||||
case 3: /* usmUserSecurityName */
|
||||
MEMCPY(value, cell_instance->reference.ptr, cell_instance->reference_len);
|
||||
return (s16_t)cell_instance->reference_len;
|
||||
|
||||
case 4: /* usmUserCloneFrom */
|
||||
MEMCPY(value, snmp_zero_dot_zero.id, snmp_zero_dot_zero.len * sizeof(u32_t));
|
||||
return snmp_zero_dot_zero.len * sizeof(u32_t);
|
||||
|
||||
case 5: /* usmUserAuthProtocol */
|
||||
{
|
||||
const struct snmp_obj_id *auth_algo;
|
||||
snmpv3_auth_algo_t auth_algo_val;
|
||||
snmpv3_get_user((const char *)cell_instance->reference.ptr, &auth_algo_val, NULL, NULL, NULL);
|
||||
auth_algo = snmp_auth_algo_to_oid(auth_algo_val);
|
||||
MEMCPY(value, auth_algo->id, auth_algo->len * sizeof(u32_t));
|
||||
return auth_algo->len * sizeof(u32_t);
|
||||
}
|
||||
|
||||
case 6: /* usmUserAuthKeyChange */
|
||||
return 0;
|
||||
|
||||
case 7: /* usmUserOwnAuthKeyChange */
|
||||
return 0;
|
||||
|
||||
case 8: /* usmUserPrivProtocol */
|
||||
{
|
||||
const struct snmp_obj_id *priv_algo;
|
||||
snmpv3_priv_algo_t priv_algo_val;
|
||||
snmpv3_get_user((const char *)cell_instance->reference.ptr, NULL, NULL, &priv_algo_val, NULL);
|
||||
priv_algo = snmp_priv_algo_to_oid(priv_algo_val);
|
||||
MEMCPY(value, priv_algo->id, priv_algo->len * sizeof(u32_t));
|
||||
return priv_algo->len * sizeof(u32_t);
|
||||
}
|
||||
|
||||
case 9: /* usmUserPrivKeyChange */
|
||||
return 0;
|
||||
|
||||
case 10: /* usmUserOwnPrivKeyChange */
|
||||
return 0;
|
||||
|
||||
case 11: /* usmUserPublic */
|
||||
/* TODO: Implement usmUserPublic */
|
||||
return 0;
|
||||
|
||||
case 12: /* usmUserStorageType */
|
||||
snmpv3_get_user_storagetype((const char *)cell_instance->reference.ptr, &storage_type);
|
||||
*(s32_t *)value = storage_type;
|
||||
return sizeof(s32_t);
|
||||
|
||||
case 13: /* usmUserStatus */
|
||||
*(s32_t *)value = 1; /* active */
|
||||
return sizeof(s32_t);
|
||||
|
||||
default:
|
||||
LWIP_DEBUGF(SNMP_MIB_DEBUG, ("usmusertable_get_value(): unknown id: %" S32_F "\n", SNMP_TABLE_GET_COLUMN_FROM_OID(cell_instance->instance_oid.id)));
|
||||
return 0;
|
||||
switch (SNMP_TABLE_GET_COLUMN_FROM_OID(cell_instance->instance_oid.id)) {
|
||||
case 3: /* usmUserSecurityName */
|
||||
MEMCPY(value, cell_instance->reference.ptr, cell_instance->reference_len);
|
||||
return (s16_t)cell_instance->reference_len;
|
||||
case 4: /* usmUserCloneFrom */
|
||||
MEMCPY(value, snmp_zero_dot_zero.id, snmp_zero_dot_zero.len * sizeof(u32_t));
|
||||
return snmp_zero_dot_zero.len * sizeof(u32_t);
|
||||
case 5: { /* usmUserAuthProtocol */
|
||||
const struct snmp_obj_id *auth_algo;
|
||||
snmpv3_auth_algo_t auth_algo_val;
|
||||
snmpv3_get_user((const char *)cell_instance->reference.ptr, &auth_algo_val, NULL, NULL, NULL);
|
||||
auth_algo = snmp_auth_algo_to_oid(auth_algo_val);
|
||||
MEMCPY(value, auth_algo->id, auth_algo->len * sizeof(u32_t));
|
||||
return auth_algo->len * sizeof(u32_t);
|
||||
}
|
||||
case 6: /* usmUserAuthKeyChange */
|
||||
return 0;
|
||||
case 7: /* usmUserOwnAuthKeyChange */
|
||||
return 0;
|
||||
case 8: { /* usmUserPrivProtocol */
|
||||
const struct snmp_obj_id *priv_algo;
|
||||
snmpv3_priv_algo_t priv_algo_val;
|
||||
snmpv3_get_user((const char *)cell_instance->reference.ptr, NULL, NULL, &priv_algo_val, NULL);
|
||||
priv_algo = snmp_priv_algo_to_oid(priv_algo_val);
|
||||
MEMCPY(value, priv_algo->id, priv_algo->len * sizeof(u32_t));
|
||||
return priv_algo->len * sizeof(u32_t);
|
||||
}
|
||||
case 9: /* usmUserPrivKeyChange */
|
||||
return 0;
|
||||
case 10: /* usmUserOwnPrivKeyChange */
|
||||
return 0;
|
||||
case 11: /* usmUserPublic */
|
||||
/* TODO: Implement usmUserPublic */
|
||||
return 0;
|
||||
case 12: /* usmUserStorageType */
|
||||
snmpv3_get_user_storagetype((const char *)cell_instance->reference.ptr, &storage_type);
|
||||
*(s32_t *)value = storage_type;
|
||||
return sizeof(s32_t);
|
||||
case 13: /* usmUserStatus */
|
||||
*(s32_t *)value = 1; /* active */
|
||||
return sizeof(s32_t);
|
||||
default:
|
||||
LWIP_DEBUGF(SNMP_MIB_DEBUG, ("usmusertable_get_value(): unknown id: %"S32_F"\n", SNMP_TABLE_GET_COLUMN_FROM_OID(cell_instance->instance_oid.id)));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* --- usmMIBObjects 1.3.6.1.6.3.15.1 ----------------------------------------------------- */
|
||||
static s16_t usmstats_scalars_get_value(const struct snmp_scalar_array_node_def *node, void *value)
|
||||
{
|
||||
u32_t *uint_ptr = (u32_t *)value;
|
||||
u32_t *uint_ptr = (u32_t *)value;
|
||||
switch (node->oid) {
|
||||
case 1: /* usmStatsUnsupportedSecLevels */
|
||||
*uint_ptr = snmp_stats.unsupportedseclevels;
|
||||
break;
|
||||
case 2: /* usmStatsNotInTimeWindows */
|
||||
*uint_ptr = snmp_stats.notintimewindows;
|
||||
break;
|
||||
case 3: /* usmStatsUnknownUserNames */
|
||||
*uint_ptr = snmp_stats.unknownusernames;
|
||||
break;
|
||||
case 4: /* usmStatsUnknownEngineIDs */
|
||||
*uint_ptr = snmp_stats.unknownengineids;
|
||||
break;
|
||||
case 5: /* usmStatsWrongDigests */
|
||||
*uint_ptr = snmp_stats.wrongdigests;
|
||||
break;
|
||||
case 6: /* usmStatsDecryptionErrors */
|
||||
*uint_ptr = snmp_stats.decryptionerrors;
|
||||
break;
|
||||
default:
|
||||
LWIP_DEBUGF(SNMP_MIB_DEBUG, ("usmstats_scalars_get_value(): unknown id: %"S32_F"\n", node->oid));
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (node->oid) {
|
||||
case 1: /* usmStatsUnsupportedSecLevels */
|
||||
*uint_ptr = snmp_stats.unsupportedseclevels;
|
||||
break;
|
||||
|
||||
case 2: /* usmStatsNotInTimeWindows */
|
||||
*uint_ptr = snmp_stats.notintimewindows;
|
||||
break;
|
||||
|
||||
case 3: /* usmStatsUnknownUserNames */
|
||||
*uint_ptr = snmp_stats.unknownusernames;
|
||||
break;
|
||||
|
||||
case 4: /* usmStatsUnknownEngineIDs */
|
||||
*uint_ptr = snmp_stats.unknownengineids;
|
||||
break;
|
||||
|
||||
case 5: /* usmStatsWrongDigests */
|
||||
*uint_ptr = snmp_stats.wrongdigests;
|
||||
break;
|
||||
|
||||
case 6: /* usmStatsDecryptionErrors */
|
||||
*uint_ptr = snmp_stats.decryptionerrors;
|
||||
break;
|
||||
|
||||
default:
|
||||
LWIP_DEBUGF(SNMP_MIB_DEBUG, ("usmstats_scalars_get_value(): unknown id: %" S32_F "\n", node->oid));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return sizeof(*uint_ptr);
|
||||
return sizeof(*uint_ptr);
|
||||
}
|
||||
|
||||
/* --- snmpUsmMIB ----------------------------------------------------- */
|
||||
@ -412,48 +363,48 @@ static s16_t usmstats_scalars_get_value(const struct snmp_scalar_array_node_def
|
||||
/* --- usmUser 1.3.6.1.6.3.15.1.2 ----------------------------------------------------- */
|
||||
|
||||
static const struct snmp_table_col_def usmusertable_columns[] = {
|
||||
{ 3, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY }, /* usmUserSecurityName */
|
||||
{ 4, SNMP_ASN1_TYPE_OBJECT_ID, SNMP_NODE_INSTANCE_READ_ONLY }, /* usmUserCloneFrom */
|
||||
{ 5, SNMP_ASN1_TYPE_OBJECT_ID, SNMP_NODE_INSTANCE_READ_ONLY }, /* usmUserAuthProtocol */
|
||||
{ 6, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY }, /* usmUserAuthKeyChange */
|
||||
{ 7, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY }, /* usmUserOwnAuthKeyChange */
|
||||
{ 8, SNMP_ASN1_TYPE_OBJECT_ID, SNMP_NODE_INSTANCE_READ_ONLY }, /* usmUserPrivProtocol */
|
||||
{ 9, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY }, /* usmUserPrivKeyChange */
|
||||
{ 10, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY }, /* usmUserOwnPrivKeyChange */
|
||||
{ 11, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY }, /* usmUserPublic */
|
||||
{ 12, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_ONLY }, /* usmUserStorageType */
|
||||
{ 13, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_ONLY }, /* usmUserStatus */
|
||||
{3, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmUserSecurityName */
|
||||
{4, SNMP_ASN1_TYPE_OBJECT_ID, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmUserCloneFrom */
|
||||
{5, SNMP_ASN1_TYPE_OBJECT_ID, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmUserAuthProtocol */
|
||||
{6, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmUserAuthKeyChange */
|
||||
{7, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmUserOwnAuthKeyChange */
|
||||
{8, SNMP_ASN1_TYPE_OBJECT_ID, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmUserPrivProtocol */
|
||||
{9, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmUserPrivKeyChange */
|
||||
{10, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmUserOwnPrivKeyChange */
|
||||
{11, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmUserPublic */
|
||||
{12, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmUserStorageType */
|
||||
{13, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmUserStatus */
|
||||
};
|
||||
static const struct snmp_table_node usmusertable = SNMP_TABLE_CREATE(2, usmusertable_columns, usmusertable_get_instance, usmusertable_get_next_instance, usmusertable_get_value, NULL, NULL);
|
||||
|
||||
static const struct snmp_node *const usmuser_subnodes[] = {
|
||||
&usmusertable.node.node
|
||||
&usmusertable.node.node
|
||||
};
|
||||
static const struct snmp_tree_node usmuser_treenode = SNMP_CREATE_TREE_NODE(2, usmuser_subnodes);
|
||||
|
||||
/* --- usmMIBObjects 1.3.6.1.6.3.15.1 ----------------------------------------------------- */
|
||||
static const struct snmp_scalar_array_node_def usmstats_scalars_nodes[] = {
|
||||
{ 1, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* usmStatsUnsupportedSecLevels */
|
||||
{ 2, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* usmStatsNotInTimeWindows */
|
||||
{ 3, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* usmStatsUnknownUserNames */
|
||||
{ 4, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* usmStatsUnknownEngineIDs */
|
||||
{ 5, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* usmStatsWrongDigests */
|
||||
{ 6, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY }, /* usmStatsDecryptionErrors */
|
||||
{1, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmStatsUnsupportedSecLevels */
|
||||
{2, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmStatsNotInTimeWindows */
|
||||
{3, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmStatsUnknownUserNames */
|
||||
{4, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmStatsUnknownEngineIDs */
|
||||
{5, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmStatsWrongDigests */
|
||||
{6, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmStatsDecryptionErrors */
|
||||
};
|
||||
static const struct snmp_scalar_array_node usmstats_scalars = SNMP_SCALAR_CREATE_ARRAY_NODE(1, usmstats_scalars_nodes, usmstats_scalars_get_value, NULL, NULL);
|
||||
|
||||
static const struct snmp_node *const usmmibobjects_subnodes[] = {
|
||||
&usmstats_scalars.node.node,
|
||||
&usmuser_treenode.node
|
||||
&usmstats_scalars.node.node,
|
||||
&usmuser_treenode.node
|
||||
};
|
||||
static const struct snmp_tree_node usmmibobjects_treenode = SNMP_CREATE_TREE_NODE(1, usmmibobjects_subnodes);
|
||||
|
||||
/* --- snmpUsmMIB ----------------------------------------------------- */
|
||||
static const struct snmp_node *const snmpusmmib_subnodes[] = {
|
||||
&usmmibobjects_treenode.node
|
||||
&usmmibobjects_treenode.node
|
||||
};
|
||||
static const struct snmp_tree_node snmpusmmib_root = SNMP_CREATE_TREE_NODE(15, snmpusmmib_subnodes);
|
||||
static const u32_t snmpusmmib_base_oid[] = { 1, 3, 6, 1, 6, 3, 15 };
|
||||
const struct snmp_mib snmpusmmib = { snmpusmmib_base_oid, LWIP_ARRAYSIZE(snmpusmmib_base_oid), &snmpusmmib_root.node };
|
||||
static const u32_t snmpusmmib_base_oid[] = {1, 3, 6, 1, 6, 3, 15};
|
||||
const struct snmp_mib snmpusmmib = {snmpusmmib_base_oid, LWIP_ARRAYSIZE(snmpusmmib_base_oid), &snmpusmmib_root.node};
|
||||
|
||||
#endif /* LWIP_SNMP */
|
||||
|
@ -45,307 +45,298 @@
|
||||
|
||||
snmp_err_t snmp_table_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
|
||||
{
|
||||
snmp_err_t ret = SNMP_ERR_NOSUCHINSTANCE;
|
||||
const struct snmp_table_node *table_node = (const struct snmp_table_node *)(const void *)instance->node;
|
||||
snmp_err_t ret = SNMP_ERR_NOSUCHINSTANCE;
|
||||
const struct snmp_table_node *table_node = (const struct snmp_table_node *)(const void *)instance->node;
|
||||
|
||||
LWIP_UNUSED_ARG(root_oid);
|
||||
LWIP_UNUSED_ARG(root_oid_len);
|
||||
LWIP_UNUSED_ARG(root_oid);
|
||||
LWIP_UNUSED_ARG(root_oid_len);
|
||||
|
||||
/* check min. length (fixed row entry definition, column, row instance oid with at least one entry */
|
||||
/* fixed row entry always has oid 1 */
|
||||
if ((instance->instance_oid.len >= 3) && (instance->instance_oid.id[0] == 1)) {
|
||||
/* search column */
|
||||
const struct snmp_table_col_def *col_def = table_node->columns;
|
||||
u16_t i = table_node->column_count;
|
||||
/* check min. length (fixed row entry definition, column, row instance oid with at least one entry */
|
||||
/* fixed row entry always has oid 1 */
|
||||
if ((instance->instance_oid.len >= 3) && (instance->instance_oid.id[0] == 1)) {
|
||||
/* search column */
|
||||
const struct snmp_table_col_def *col_def = table_node->columns;
|
||||
u16_t i = table_node->column_count;
|
||||
while (i > 0) {
|
||||
if (col_def->index == instance->instance_oid.id[1]) {
|
||||
break;
|
||||
}
|
||||
|
||||
while (i > 0) {
|
||||
if (col_def->index == instance->instance_oid.id[1]) {
|
||||
break;
|
||||
}
|
||||
|
||||
col_def++;
|
||||
i--;
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
/* everything may be overwritten by get_cell_instance_method() in order to implement special handling for single columns/cells */
|
||||
instance->asn1_type = col_def->asn1_type;
|
||||
instance->access = col_def->access;
|
||||
instance->get_value = table_node->get_value;
|
||||
instance->set_test = table_node->set_test;
|
||||
instance->set_value = table_node->set_value;
|
||||
|
||||
ret = table_node->get_cell_instance(
|
||||
&(instance->instance_oid.id[1]),
|
||||
&(instance->instance_oid.id[2]),
|
||||
instance->instance_oid.len - 2,
|
||||
instance);
|
||||
}
|
||||
col_def++;
|
||||
i--;
|
||||
}
|
||||
|
||||
return ret;
|
||||
if (i > 0) {
|
||||
/* everything may be overwritten by get_cell_instance_method() in order to implement special handling for single columns/cells */
|
||||
instance->asn1_type = col_def->asn1_type;
|
||||
instance->access = col_def->access;
|
||||
instance->get_value = table_node->get_value;
|
||||
instance->set_test = table_node->set_test;
|
||||
instance->set_value = table_node->set_value;
|
||||
|
||||
ret = table_node->get_cell_instance(
|
||||
&(instance->instance_oid.id[1]),
|
||||
&(instance->instance_oid.id[2]),
|
||||
instance->instance_oid.len - 2,
|
||||
instance);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
snmp_err_t snmp_table_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
|
||||
{
|
||||
const struct snmp_table_node *table_node = (const struct snmp_table_node *)(const void *)instance->node;
|
||||
const struct snmp_table_col_def *col_def;
|
||||
struct snmp_obj_id row_oid;
|
||||
u32_t column = 0;
|
||||
snmp_err_t result;
|
||||
const struct snmp_table_node *table_node = (const struct snmp_table_node *)(const void *)instance->node;
|
||||
const struct snmp_table_col_def *col_def;
|
||||
struct snmp_obj_id row_oid;
|
||||
u32_t column = 0;
|
||||
snmp_err_t result;
|
||||
|
||||
LWIP_UNUSED_ARG(root_oid);
|
||||
LWIP_UNUSED_ARG(root_oid_len);
|
||||
LWIP_UNUSED_ARG(root_oid);
|
||||
LWIP_UNUSED_ARG(root_oid_len);
|
||||
|
||||
/* check that first part of id is 0 or 1, referencing fixed row entry */
|
||||
if ((instance->instance_oid.len > 0) && (instance->instance_oid.id[0] > 1)) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
/* check that first part of id is 0 or 1, referencing fixed row entry */
|
||||
if ((instance->instance_oid.len > 0) && (instance->instance_oid.id[0] > 1)) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
if (instance->instance_oid.len > 1) {
|
||||
column = instance->instance_oid.id[1];
|
||||
}
|
||||
if (instance->instance_oid.len > 2) {
|
||||
snmp_oid_assign(&row_oid, &(instance->instance_oid.id[2]), instance->instance_oid.len - 2);
|
||||
} else {
|
||||
row_oid.len = 0;
|
||||
}
|
||||
|
||||
instance->get_value = table_node->get_value;
|
||||
instance->set_test = table_node->set_test;
|
||||
instance->set_value = table_node->set_value;
|
||||
|
||||
/* resolve column and value */
|
||||
do {
|
||||
u16_t i;
|
||||
const struct snmp_table_col_def *next_col_def = NULL;
|
||||
col_def = table_node->columns;
|
||||
|
||||
for (i = 0; i < table_node->column_count; i++) {
|
||||
if (col_def->index == column) {
|
||||
next_col_def = col_def;
|
||||
break;
|
||||
} else if ((col_def->index > column) && ((next_col_def == NULL) || (col_def->index < next_col_def->index))) {
|
||||
next_col_def = col_def;
|
||||
}
|
||||
col_def++;
|
||||
}
|
||||
|
||||
if (instance->instance_oid.len > 1) {
|
||||
column = instance->instance_oid.id[1];
|
||||
if (next_col_def == NULL) {
|
||||
/* no further column found */
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
if (instance->instance_oid.len > 2) {
|
||||
snmp_oid_assign(&row_oid, &(instance->instance_oid.id[2]), instance->instance_oid.len - 2);
|
||||
} else {
|
||||
row_oid.len = 0;
|
||||
instance->asn1_type = next_col_def->asn1_type;
|
||||
instance->access = next_col_def->access;
|
||||
|
||||
result = table_node->get_next_cell_instance(
|
||||
&next_col_def->index,
|
||||
&row_oid,
|
||||
instance);
|
||||
|
||||
if (result == SNMP_ERR_NOERROR) {
|
||||
col_def = next_col_def;
|
||||
break;
|
||||
}
|
||||
|
||||
instance->get_value = table_node->get_value;
|
||||
instance->set_test = table_node->set_test;
|
||||
instance->set_value = table_node->set_value;
|
||||
row_oid.len = 0; /* reset row_oid because we switch to next column and start with the first entry there */
|
||||
column = next_col_def->index + 1;
|
||||
} while (1);
|
||||
|
||||
/* resolve column and value */
|
||||
do {
|
||||
u16_t i;
|
||||
const struct snmp_table_col_def *next_col_def = NULL;
|
||||
col_def = table_node->columns;
|
||||
/* build resulting oid */
|
||||
instance->instance_oid.len = 2;
|
||||
instance->instance_oid.id[0] = 1;
|
||||
instance->instance_oid.id[1] = col_def->index;
|
||||
snmp_oid_append(&instance->instance_oid, row_oid.id, row_oid.len);
|
||||
|
||||
for (i = 0; i < table_node->column_count; i++) {
|
||||
if (col_def->index == column) {
|
||||
next_col_def = col_def;
|
||||
break;
|
||||
} else if ((col_def->index > column) && ((next_col_def == NULL) || (col_def->index < next_col_def->index))) {
|
||||
next_col_def = col_def;
|
||||
}
|
||||
|
||||
col_def++;
|
||||
}
|
||||
|
||||
if (next_col_def == NULL) {
|
||||
/* no further column found */
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
instance->asn1_type = next_col_def->asn1_type;
|
||||
instance->access = next_col_def->access;
|
||||
|
||||
result = table_node->get_next_cell_instance(
|
||||
&next_col_def->index,
|
||||
&row_oid,
|
||||
instance);
|
||||
|
||||
if (result == SNMP_ERR_NOERROR) {
|
||||
col_def = next_col_def;
|
||||
break;
|
||||
}
|
||||
|
||||
row_oid.len = 0; /* reset row_oid because we switch to next column and start with the first entry there */
|
||||
column = next_col_def->index + 1;
|
||||
} while (1);
|
||||
|
||||
/* build resulting oid */
|
||||
instance->instance_oid.len = 2;
|
||||
instance->instance_oid.id[0] = 1;
|
||||
instance->instance_oid.id[1] = col_def->index;
|
||||
snmp_oid_append(&instance->instance_oid, row_oid.id, row_oid.len);
|
||||
|
||||
return SNMP_ERR_NOERROR;
|
||||
return SNMP_ERR_NOERROR;
|
||||
}
|
||||
|
||||
|
||||
snmp_err_t snmp_table_simple_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
|
||||
{
|
||||
snmp_err_t ret = SNMP_ERR_NOSUCHINSTANCE;
|
||||
const struct snmp_table_simple_node *table_node = (const struct snmp_table_simple_node *)(const void *)instance->node;
|
||||
snmp_err_t ret = SNMP_ERR_NOSUCHINSTANCE;
|
||||
const struct snmp_table_simple_node *table_node = (const struct snmp_table_simple_node *)(const void *)instance->node;
|
||||
|
||||
LWIP_UNUSED_ARG(root_oid);
|
||||
LWIP_UNUSED_ARG(root_oid_len);
|
||||
LWIP_UNUSED_ARG(root_oid);
|
||||
LWIP_UNUSED_ARG(root_oid_len);
|
||||
|
||||
/* check min. length (fixed row entry definition, column, row instance oid with at least one entry */
|
||||
/* fixed row entry always has oid 1 */
|
||||
if ((instance->instance_oid.len >= 3) && (instance->instance_oid.id[0] == 1)) {
|
||||
ret = table_node->get_cell_value(
|
||||
/* check min. length (fixed row entry definition, column, row instance oid with at least one entry */
|
||||
/* fixed row entry always has oid 1 */
|
||||
if ((instance->instance_oid.len >= 3) && (instance->instance_oid.id[0] == 1)) {
|
||||
ret = table_node->get_cell_value(
|
||||
&(instance->instance_oid.id[1]),
|
||||
&(instance->instance_oid.id[2]),
|
||||
instance->instance_oid.len - 2,
|
||||
&instance->reference,
|
||||
&instance->reference_len);
|
||||
|
||||
if (ret == SNMP_ERR_NOERROR) {
|
||||
/* search column */
|
||||
const struct snmp_table_simple_col_def *col_def = table_node->columns;
|
||||
u32_t i = table_node->column_count;
|
||||
|
||||
while (i > 0) {
|
||||
if (col_def->index == instance->instance_oid.id[1]) {
|
||||
break;
|
||||
}
|
||||
|
||||
col_def++;
|
||||
i--;
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
instance->asn1_type = col_def->asn1_type;
|
||||
instance->access = SNMP_NODE_INSTANCE_READ_ONLY;
|
||||
instance->set_test = NULL;
|
||||
instance->set_value = NULL;
|
||||
|
||||
switch (col_def->data_type) {
|
||||
case SNMP_VARIANT_VALUE_TYPE_U32:
|
||||
instance->get_value = snmp_table_extract_value_from_u32ref;
|
||||
break;
|
||||
|
||||
case SNMP_VARIANT_VALUE_TYPE_S32:
|
||||
instance->get_value = snmp_table_extract_value_from_s32ref;
|
||||
break;
|
||||
|
||||
case SNMP_VARIANT_VALUE_TYPE_PTR: /* fall through */
|
||||
case SNMP_VARIANT_VALUE_TYPE_CONST_PTR:
|
||||
instance->get_value = snmp_table_extract_value_from_refconstptr;
|
||||
break;
|
||||
|
||||
default:
|
||||
LWIP_DEBUGF(SNMP_DEBUG, ("snmp_table_simple_get_instance(): unknown column data_type: %d\n", col_def->data_type));
|
||||
return SNMP_ERR_GENERROR;
|
||||
}
|
||||
|
||||
ret = SNMP_ERR_NOERROR;
|
||||
} else {
|
||||
ret = SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
if (ret == SNMP_ERR_NOERROR) {
|
||||
/* search column */
|
||||
const struct snmp_table_simple_col_def *col_def = table_node->columns;
|
||||
u32_t i = table_node->column_count;
|
||||
while (i > 0) {
|
||||
if (col_def->index == instance->instance_oid.id[1]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
col_def++;
|
||||
i--;
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
instance->asn1_type = col_def->asn1_type;
|
||||
instance->access = SNMP_NODE_INSTANCE_READ_ONLY;
|
||||
instance->set_test = NULL;
|
||||
instance->set_value = NULL;
|
||||
|
||||
switch (col_def->data_type) {
|
||||
case SNMP_VARIANT_VALUE_TYPE_U32:
|
||||
instance->get_value = snmp_table_extract_value_from_u32ref;
|
||||
break;
|
||||
case SNMP_VARIANT_VALUE_TYPE_S32:
|
||||
instance->get_value = snmp_table_extract_value_from_s32ref;
|
||||
break;
|
||||
case SNMP_VARIANT_VALUE_TYPE_PTR: /* fall through */
|
||||
case SNMP_VARIANT_VALUE_TYPE_CONST_PTR:
|
||||
instance->get_value = snmp_table_extract_value_from_refconstptr;
|
||||
break;
|
||||
default:
|
||||
LWIP_DEBUGF(SNMP_DEBUG, ("snmp_table_simple_get_instance(): unknown column data_type: %d\n", col_def->data_type));
|
||||
return SNMP_ERR_GENERROR;
|
||||
}
|
||||
|
||||
ret = SNMP_ERR_NOERROR;
|
||||
} else {
|
||||
ret = SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
snmp_err_t snmp_table_simple_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
|
||||
{
|
||||
const struct snmp_table_simple_node *table_node = (const struct snmp_table_simple_node *)(const void *)instance->node;
|
||||
const struct snmp_table_simple_col_def *col_def;
|
||||
struct snmp_obj_id row_oid;
|
||||
u32_t column = 0;
|
||||
snmp_err_t result;
|
||||
const struct snmp_table_simple_node *table_node = (const struct snmp_table_simple_node *)(const void *)instance->node;
|
||||
const struct snmp_table_simple_col_def *col_def;
|
||||
struct snmp_obj_id row_oid;
|
||||
u32_t column = 0;
|
||||
snmp_err_t result;
|
||||
|
||||
LWIP_UNUSED_ARG(root_oid);
|
||||
LWIP_UNUSED_ARG(root_oid_len);
|
||||
LWIP_UNUSED_ARG(root_oid);
|
||||
LWIP_UNUSED_ARG(root_oid_len);
|
||||
|
||||
/* check that first part of id is 0 or 1, referencing fixed row entry */
|
||||
if ((instance->instance_oid.len > 0) && (instance->instance_oid.id[0] > 1)) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
/* check that first part of id is 0 or 1, referencing fixed row entry */
|
||||
if ((instance->instance_oid.len > 0) && (instance->instance_oid.id[0] > 1)) {
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
if (instance->instance_oid.len > 1) {
|
||||
column = instance->instance_oid.id[1];
|
||||
}
|
||||
if (instance->instance_oid.len > 2) {
|
||||
snmp_oid_assign(&row_oid, &(instance->instance_oid.id[2]), instance->instance_oid.len - 2);
|
||||
} else {
|
||||
row_oid.len = 0;
|
||||
}
|
||||
|
||||
/* resolve column and value */
|
||||
do {
|
||||
u32_t i;
|
||||
const struct snmp_table_simple_col_def *next_col_def = NULL;
|
||||
col_def = table_node->columns;
|
||||
|
||||
for (i = 0; i < table_node->column_count; i++) {
|
||||
if (col_def->index == column) {
|
||||
next_col_def = col_def;
|
||||
break;
|
||||
} else if ((col_def->index > column) && ((next_col_def == NULL) ||
|
||||
(col_def->index < next_col_def->index))) {
|
||||
next_col_def = col_def;
|
||||
}
|
||||
col_def++;
|
||||
}
|
||||
|
||||
if (instance->instance_oid.len > 1) {
|
||||
column = instance->instance_oid.id[1];
|
||||
if (next_col_def == NULL) {
|
||||
/* no further column found */
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
if (instance->instance_oid.len > 2) {
|
||||
snmp_oid_assign(&row_oid, &(instance->instance_oid.id[2]), instance->instance_oid.len - 2);
|
||||
} else {
|
||||
row_oid.len = 0;
|
||||
result = table_node->get_next_cell_instance_and_value(
|
||||
&next_col_def->index,
|
||||
&row_oid,
|
||||
&instance->reference,
|
||||
&instance->reference_len);
|
||||
|
||||
if (result == SNMP_ERR_NOERROR) {
|
||||
col_def = next_col_def;
|
||||
break;
|
||||
}
|
||||
|
||||
/* resolve column and value */
|
||||
do {
|
||||
u32_t i;
|
||||
const struct snmp_table_simple_col_def *next_col_def = NULL;
|
||||
col_def = table_node->columns;
|
||||
row_oid.len = 0; /* reset row_oid because we switch to next column and start with the first entry there */
|
||||
column = next_col_def->index + 1;
|
||||
} while (1);
|
||||
|
||||
for (i = 0; i < table_node->column_count; i++) {
|
||||
if (col_def->index == column) {
|
||||
next_col_def = col_def;
|
||||
break;
|
||||
} else if ((col_def->index > column) && ((next_col_def == NULL) ||
|
||||
(col_def->index < next_col_def->index))) {
|
||||
next_col_def = col_def;
|
||||
}
|
||||
instance->asn1_type = col_def->asn1_type;
|
||||
instance->access = SNMP_NODE_INSTANCE_READ_ONLY;
|
||||
instance->set_test = NULL;
|
||||
instance->set_value = NULL;
|
||||
|
||||
col_def++;
|
||||
}
|
||||
switch (col_def->data_type) {
|
||||
case SNMP_VARIANT_VALUE_TYPE_U32:
|
||||
instance->get_value = snmp_table_extract_value_from_u32ref;
|
||||
break;
|
||||
case SNMP_VARIANT_VALUE_TYPE_S32:
|
||||
instance->get_value = snmp_table_extract_value_from_s32ref;
|
||||
break;
|
||||
case SNMP_VARIANT_VALUE_TYPE_PTR: /* fall through */
|
||||
case SNMP_VARIANT_VALUE_TYPE_CONST_PTR:
|
||||
instance->get_value = snmp_table_extract_value_from_refconstptr;
|
||||
break;
|
||||
default:
|
||||
LWIP_DEBUGF(SNMP_DEBUG, ("snmp_table_simple_get_instance(): unknown column data_type: %d\n", col_def->data_type));
|
||||
return SNMP_ERR_GENERROR;
|
||||
}
|
||||
|
||||
if (next_col_def == NULL) {
|
||||
/* no further column found */
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
/* build resulting oid */
|
||||
instance->instance_oid.len = 2;
|
||||
instance->instance_oid.id[0] = 1;
|
||||
instance->instance_oid.id[1] = col_def->index;
|
||||
snmp_oid_append(&instance->instance_oid, row_oid.id, row_oid.len);
|
||||
|
||||
result = table_node->get_next_cell_instance_and_value(
|
||||
&next_col_def->index,
|
||||
&row_oid,
|
||||
&instance->reference,
|
||||
&instance->reference_len);
|
||||
|
||||
if (result == SNMP_ERR_NOERROR) {
|
||||
col_def = next_col_def;
|
||||
break;
|
||||
}
|
||||
|
||||
row_oid.len = 0; /* reset row_oid because we switch to next column and start with the first entry there */
|
||||
column = next_col_def->index + 1;
|
||||
} while (1);
|
||||
|
||||
instance->asn1_type = col_def->asn1_type;
|
||||
instance->access = SNMP_NODE_INSTANCE_READ_ONLY;
|
||||
instance->set_test = NULL;
|
||||
instance->set_value = NULL;
|
||||
|
||||
switch (col_def->data_type) {
|
||||
case SNMP_VARIANT_VALUE_TYPE_U32:
|
||||
instance->get_value = snmp_table_extract_value_from_u32ref;
|
||||
break;
|
||||
|
||||
case SNMP_VARIANT_VALUE_TYPE_S32:
|
||||
instance->get_value = snmp_table_extract_value_from_s32ref;
|
||||
break;
|
||||
|
||||
case SNMP_VARIANT_VALUE_TYPE_PTR: /* fall through */
|
||||
case SNMP_VARIANT_VALUE_TYPE_CONST_PTR:
|
||||
instance->get_value = snmp_table_extract_value_from_refconstptr;
|
||||
break;
|
||||
|
||||
default:
|
||||
LWIP_DEBUGF(SNMP_DEBUG, ("snmp_table_simple_get_instance(): unknown column data_type: %d\n", col_def->data_type));
|
||||
return SNMP_ERR_GENERROR;
|
||||
}
|
||||
|
||||
/* build resulting oid */
|
||||
instance->instance_oid.len = 2;
|
||||
instance->instance_oid.id[0] = 1;
|
||||
instance->instance_oid.id[1] = col_def->index;
|
||||
snmp_oid_append(&instance->instance_oid, row_oid.id, row_oid.len);
|
||||
|
||||
return SNMP_ERR_NOERROR;
|
||||
return SNMP_ERR_NOERROR;
|
||||
}
|
||||
|
||||
s16_t snmp_table_extract_value_from_s32ref(struct snmp_node_instance *instance, void *value)
|
||||
|
||||
s16_t
|
||||
snmp_table_extract_value_from_s32ref(struct snmp_node_instance *instance, void *value)
|
||||
{
|
||||
s32_t *dst = (s32_t *)value;
|
||||
*dst = instance->reference.s32;
|
||||
return sizeof(*dst);
|
||||
s32_t *dst = (s32_t *)value;
|
||||
*dst = instance->reference.s32;
|
||||
return sizeof(*dst);
|
||||
}
|
||||
|
||||
s16_t snmp_table_extract_value_from_u32ref(struct snmp_node_instance *instance, void *value)
|
||||
s16_t
|
||||
snmp_table_extract_value_from_u32ref(struct snmp_node_instance *instance, void *value)
|
||||
{
|
||||
u32_t *dst = (u32_t *)value;
|
||||
*dst = instance->reference.u32;
|
||||
return sizeof(*dst);
|
||||
u32_t *dst = (u32_t *)value;
|
||||
*dst = instance->reference.u32;
|
||||
return sizeof(*dst);
|
||||
}
|
||||
|
||||
s16_t snmp_table_extract_value_from_refconstptr(struct snmp_node_instance *instance, void *value)
|
||||
s16_t
|
||||
snmp_table_extract_value_from_refconstptr(struct snmp_node_instance *instance, void *value)
|
||||
{
|
||||
MEMCPY(value, instance->reference.const_ptr, instance->reference_len);
|
||||
return (u16_t)instance->reference_len;
|
||||
MEMCPY(value, instance->reference.const_ptr, instance->reference_len);
|
||||
return (u16_t)instance->reference_len;
|
||||
}
|
||||
|
||||
#endif /* LWIP_SNMP */
|
||||
|
@ -41,177 +41,191 @@
|
||||
#include "lwip/sys.h"
|
||||
#include <string.h>
|
||||
|
||||
static void call_synced_function(struct threadsync_data *call_data, snmp_threadsync_called_fn fn)
|
||||
static void
|
||||
call_synced_function(struct threadsync_data *call_data, snmp_threadsync_called_fn fn)
|
||||
{
|
||||
sys_mutex_lock(&call_data->threadsync_node->instance->sem_usage_mutex);
|
||||
call_data->threadsync_node->instance->sync_fn(fn, call_data);
|
||||
sys_sem_wait(&call_data->threadsync_node->instance->sem);
|
||||
sys_mutex_unlock(&call_data->threadsync_node->instance->sem_usage_mutex);
|
||||
sys_mutex_lock(&call_data->threadsync_node->instance->sem_usage_mutex);
|
||||
call_data->threadsync_node->instance->sync_fn(fn, call_data);
|
||||
sys_sem_wait(&call_data->threadsync_node->instance->sem);
|
||||
sys_mutex_unlock(&call_data->threadsync_node->instance->sem_usage_mutex);
|
||||
}
|
||||
|
||||
static void threadsync_get_value_synced(void *ctx)
|
||||
static void
|
||||
threadsync_get_value_synced(void *ctx)
|
||||
{
|
||||
struct threadsync_data *call_data = (struct threadsync_data *)ctx;
|
||||
struct threadsync_data *call_data = (struct threadsync_data *)ctx;
|
||||
|
||||
if (call_data->proxy_instance.get_value != NULL) {
|
||||
call_data->retval.s16 = call_data->proxy_instance.get_value(&call_data->proxy_instance, call_data->arg1.value);
|
||||
} else {
|
||||
call_data->retval.s16 = -1;
|
||||
}
|
||||
if (call_data->proxy_instance.get_value != NULL) {
|
||||
call_data->retval.s16 = call_data->proxy_instance.get_value(&call_data->proxy_instance, call_data->arg1.value);
|
||||
} else {
|
||||
call_data->retval.s16 = -1;
|
||||
}
|
||||
|
||||
sys_sem_signal(&call_data->threadsync_node->instance->sem);
|
||||
sys_sem_signal(&call_data->threadsync_node->instance->sem);
|
||||
}
|
||||
|
||||
static s16_t threadsync_get_value(struct snmp_node_instance *instance, void *value)
|
||||
static s16_t
|
||||
threadsync_get_value(struct snmp_node_instance *instance, void *value)
|
||||
{
|
||||
struct threadsync_data *call_data = (struct threadsync_data *)instance->reference.ptr;
|
||||
struct threadsync_data *call_data = (struct threadsync_data *)instance->reference.ptr;
|
||||
|
||||
call_data->arg1.value = value;
|
||||
call_synced_function(call_data, threadsync_get_value_synced);
|
||||
call_data->arg1.value = value;
|
||||
call_synced_function(call_data, threadsync_get_value_synced);
|
||||
|
||||
return call_data->retval.s16;
|
||||
return call_data->retval.s16;
|
||||
}
|
||||
|
||||
static void threadsync_set_test_synced(void *ctx)
|
||||
static void
|
||||
threadsync_set_test_synced(void *ctx)
|
||||
{
|
||||
struct threadsync_data *call_data = (struct threadsync_data *)ctx;
|
||||
struct threadsync_data *call_data = (struct threadsync_data *)ctx;
|
||||
|
||||
if (call_data->proxy_instance.set_test != NULL) {
|
||||
call_data->retval.err = call_data->proxy_instance.set_test(&call_data->proxy_instance, call_data->arg2.len, call_data->arg1.value);
|
||||
} else {
|
||||
call_data->retval.err = SNMP_ERR_NOTWRITABLE;
|
||||
}
|
||||
if (call_data->proxy_instance.set_test != NULL) {
|
||||
call_data->retval.err = call_data->proxy_instance.set_test(&call_data->proxy_instance, call_data->arg2.len, call_data->arg1.value);
|
||||
} else {
|
||||
call_data->retval.err = SNMP_ERR_NOTWRITABLE;
|
||||
}
|
||||
|
||||
sys_sem_signal(&call_data->threadsync_node->instance->sem);
|
||||
sys_sem_signal(&call_data->threadsync_node->instance->sem);
|
||||
}
|
||||
|
||||
static snmp_err_t threadsync_set_test(struct snmp_node_instance *instance, u16_t len, void *value)
|
||||
static snmp_err_t
|
||||
threadsync_set_test(struct snmp_node_instance *instance, u16_t len, void *value)
|
||||
{
|
||||
struct threadsync_data *call_data = (struct threadsync_data *)instance->reference.ptr;
|
||||
struct threadsync_data *call_data = (struct threadsync_data *)instance->reference.ptr;
|
||||
|
||||
call_data->arg1.value = value;
|
||||
call_data->arg2.len = len;
|
||||
call_synced_function(call_data, threadsync_set_test_synced);
|
||||
call_data->arg1.value = value;
|
||||
call_data->arg2.len = len;
|
||||
call_synced_function(call_data, threadsync_set_test_synced);
|
||||
|
||||
return call_data->retval.err;
|
||||
return call_data->retval.err;
|
||||
}
|
||||
|
||||
static void threadsync_set_value_synced(void *ctx)
|
||||
static void
|
||||
threadsync_set_value_synced(void *ctx)
|
||||
{
|
||||
struct threadsync_data *call_data = (struct threadsync_data *)ctx;
|
||||
struct threadsync_data *call_data = (struct threadsync_data *)ctx;
|
||||
|
||||
if (call_data->proxy_instance.set_value != NULL) {
|
||||
call_data->retval.err = call_data->proxy_instance.set_value(&call_data->proxy_instance, call_data->arg2.len, call_data->arg1.value);
|
||||
} else {
|
||||
call_data->retval.err = SNMP_ERR_NOTWRITABLE;
|
||||
}
|
||||
if (call_data->proxy_instance.set_value != NULL) {
|
||||
call_data->retval.err = call_data->proxy_instance.set_value(&call_data->proxy_instance, call_data->arg2.len, call_data->arg1.value);
|
||||
} else {
|
||||
call_data->retval.err = SNMP_ERR_NOTWRITABLE;
|
||||
}
|
||||
|
||||
sys_sem_signal(&call_data->threadsync_node->instance->sem);
|
||||
sys_sem_signal(&call_data->threadsync_node->instance->sem);
|
||||
}
|
||||
|
||||
static snmp_err_t threadsync_set_value(struct snmp_node_instance *instance, u16_t len, void *value)
|
||||
static snmp_err_t
|
||||
threadsync_set_value(struct snmp_node_instance *instance, u16_t len, void *value)
|
||||
{
|
||||
struct threadsync_data *call_data = (struct threadsync_data *)instance->reference.ptr;
|
||||
struct threadsync_data *call_data = (struct threadsync_data *)instance->reference.ptr;
|
||||
|
||||
call_data->arg1.value = value;
|
||||
call_data->arg2.len = len;
|
||||
call_synced_function(call_data, threadsync_set_value_synced);
|
||||
call_data->arg1.value = value;
|
||||
call_data->arg2.len = len;
|
||||
call_synced_function(call_data, threadsync_set_value_synced);
|
||||
|
||||
return call_data->retval.err;
|
||||
return call_data->retval.err;
|
||||
}
|
||||
|
||||
static void threadsync_release_instance_synced(void *ctx)
|
||||
static void
|
||||
threadsync_release_instance_synced(void *ctx)
|
||||
{
|
||||
struct threadsync_data *call_data = (struct threadsync_data *)ctx;
|
||||
struct threadsync_data *call_data = (struct threadsync_data *)ctx;
|
||||
|
||||
call_data->proxy_instance.release_instance(&call_data->proxy_instance);
|
||||
call_data->proxy_instance.release_instance(&call_data->proxy_instance);
|
||||
|
||||
sys_sem_signal(&call_data->threadsync_node->instance->sem);
|
||||
sys_sem_signal(&call_data->threadsync_node->instance->sem);
|
||||
}
|
||||
|
||||
static void threadsync_release_instance(struct snmp_node_instance *instance)
|
||||
static void
|
||||
threadsync_release_instance(struct snmp_node_instance *instance)
|
||||
{
|
||||
struct threadsync_data *call_data = (struct threadsync_data *)instance->reference.ptr;
|
||||
struct threadsync_data *call_data = (struct threadsync_data *)instance->reference.ptr;
|
||||
|
||||
if (call_data->proxy_instance.release_instance != NULL) {
|
||||
call_synced_function(call_data, threadsync_release_instance_synced);
|
||||
}
|
||||
if (call_data->proxy_instance.release_instance != NULL) {
|
||||
call_synced_function(call_data, threadsync_release_instance_synced);
|
||||
}
|
||||
}
|
||||
|
||||
static void get_instance_synced(void *ctx)
|
||||
static void
|
||||
get_instance_synced(void *ctx)
|
||||
{
|
||||
struct threadsync_data *call_data = (struct threadsync_data *)ctx;
|
||||
const struct snmp_leaf_node *leaf = (const struct snmp_leaf_node *)(const void *)call_data->proxy_instance.node;
|
||||
struct threadsync_data *call_data = (struct threadsync_data *)ctx;
|
||||
const struct snmp_leaf_node *leaf = (const struct snmp_leaf_node *)(const void *)call_data->proxy_instance.node;
|
||||
|
||||
call_data->retval.err = leaf->get_instance(call_data->arg1.root_oid, call_data->arg2.root_oid_len, &call_data->proxy_instance);
|
||||
call_data->retval.err = leaf->get_instance(call_data->arg1.root_oid, call_data->arg2.root_oid_len, &call_data->proxy_instance);
|
||||
|
||||
sys_sem_signal(&call_data->threadsync_node->instance->sem);
|
||||
sys_sem_signal(&call_data->threadsync_node->instance->sem);
|
||||
}
|
||||
|
||||
static void get_next_instance_synced(void *ctx)
|
||||
static void
|
||||
get_next_instance_synced(void *ctx)
|
||||
{
|
||||
struct threadsync_data *call_data = (struct threadsync_data *)ctx;
|
||||
const struct snmp_leaf_node *leaf = (const struct snmp_leaf_node *)(const void *)call_data->proxy_instance.node;
|
||||
struct threadsync_data *call_data = (struct threadsync_data *)ctx;
|
||||
const struct snmp_leaf_node *leaf = (const struct snmp_leaf_node *)(const void *)call_data->proxy_instance.node;
|
||||
|
||||
call_data->retval.err = leaf->get_next_instance(call_data->arg1.root_oid, call_data->arg2.root_oid_len, &call_data->proxy_instance);
|
||||
call_data->retval.err = leaf->get_next_instance(call_data->arg1.root_oid, call_data->arg2.root_oid_len, &call_data->proxy_instance);
|
||||
|
||||
sys_sem_signal(&call_data->threadsync_node->instance->sem);
|
||||
sys_sem_signal(&call_data->threadsync_node->instance->sem);
|
||||
}
|
||||
|
||||
static snmp_err_t do_sync(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance, snmp_threadsync_called_fn fn)
|
||||
static snmp_err_t
|
||||
do_sync(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance, snmp_threadsync_called_fn fn)
|
||||
{
|
||||
const struct snmp_threadsync_node *threadsync_node = (const struct snmp_threadsync_node *)(const void *)instance->node;
|
||||
struct threadsync_data *call_data = &threadsync_node->instance->data;
|
||||
const struct snmp_threadsync_node *threadsync_node = (const struct snmp_threadsync_node *)(const void *)instance->node;
|
||||
struct threadsync_data *call_data = &threadsync_node->instance->data;
|
||||
|
||||
if (threadsync_node->node.node.oid != threadsync_node->target->node.oid) {
|
||||
LWIP_DEBUGF(SNMP_DEBUG, ("Sync node OID does not match target node OID"));
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
if (threadsync_node->node.node.oid != threadsync_node->target->node.oid) {
|
||||
LWIP_DEBUGF(SNMP_DEBUG, ("Sync node OID does not match target node OID"));
|
||||
return SNMP_ERR_NOSUCHINSTANCE;
|
||||
}
|
||||
|
||||
memset(&call_data->proxy_instance, 0, sizeof(call_data->proxy_instance));
|
||||
memset(&call_data->proxy_instance, 0, sizeof(call_data->proxy_instance));
|
||||
|
||||
instance->reference.ptr = call_data;
|
||||
snmp_oid_assign(&call_data->proxy_instance.instance_oid, instance->instance_oid.id, instance->instance_oid.len);
|
||||
instance->reference.ptr = call_data;
|
||||
snmp_oid_assign(&call_data->proxy_instance.instance_oid, instance->instance_oid.id, instance->instance_oid.len);
|
||||
|
||||
call_data->proxy_instance.node = &threadsync_node->target->node;
|
||||
call_data->threadsync_node = threadsync_node;
|
||||
call_data->proxy_instance.node = &threadsync_node->target->node;
|
||||
call_data->threadsync_node = threadsync_node;
|
||||
|
||||
call_data->arg1.root_oid = root_oid;
|
||||
call_data->arg2.root_oid_len = root_oid_len;
|
||||
call_synced_function(call_data, fn);
|
||||
call_data->arg1.root_oid = root_oid;
|
||||
call_data->arg2.root_oid_len = root_oid_len;
|
||||
call_synced_function(call_data, fn);
|
||||
|
||||
if (call_data->retval.err == SNMP_ERR_NOERROR) {
|
||||
instance->access = call_data->proxy_instance.access;
|
||||
instance->asn1_type = call_data->proxy_instance.asn1_type;
|
||||
instance->release_instance = threadsync_release_instance;
|
||||
instance->get_value = (call_data->proxy_instance.get_value != NULL) ? threadsync_get_value : NULL;
|
||||
instance->set_value = (call_data->proxy_instance.set_value != NULL) ? threadsync_set_value : NULL;
|
||||
instance->set_test = (call_data->proxy_instance.set_test != NULL) ? threadsync_set_test : NULL;
|
||||
snmp_oid_assign(&instance->instance_oid, call_data->proxy_instance.instance_oid.id, call_data->proxy_instance.instance_oid.len);
|
||||
}
|
||||
if (call_data->retval.err == SNMP_ERR_NOERROR) {
|
||||
instance->access = call_data->proxy_instance.access;
|
||||
instance->asn1_type = call_data->proxy_instance.asn1_type;
|
||||
instance->release_instance = threadsync_release_instance;
|
||||
instance->get_value = (call_data->proxy_instance.get_value != NULL) ? threadsync_get_value : NULL;
|
||||
instance->set_value = (call_data->proxy_instance.set_value != NULL) ? threadsync_set_value : NULL;
|
||||
instance->set_test = (call_data->proxy_instance.set_test != NULL) ? threadsync_set_test : NULL;
|
||||
snmp_oid_assign(&instance->instance_oid, call_data->proxy_instance.instance_oid.id, call_data->proxy_instance.instance_oid.len);
|
||||
}
|
||||
|
||||
return call_data->retval.err;
|
||||
return call_data->retval.err;
|
||||
}
|
||||
|
||||
snmp_err_t snmp_threadsync_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
|
||||
snmp_err_t
|
||||
snmp_threadsync_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
|
||||
{
|
||||
return do_sync(root_oid, root_oid_len, instance, get_instance_synced);
|
||||
return do_sync(root_oid, root_oid_len, instance, get_instance_synced);
|
||||
}
|
||||
|
||||
snmp_err_t snmp_threadsync_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
|
||||
snmp_err_t
|
||||
snmp_threadsync_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
|
||||
{
|
||||
return do_sync(root_oid, root_oid_len, instance, get_next_instance_synced);
|
||||
return do_sync(root_oid, root_oid_len, instance, get_next_instance_synced);
|
||||
}
|
||||
|
||||
/** Initializes thread synchronization instance */
|
||||
void snmp_threadsync_init(struct snmp_threadsync_instance *instance, snmp_threadsync_synchronizer_fn sync_fn)
|
||||
{
|
||||
err_t err = sys_mutex_new(&instance->sem_usage_mutex);
|
||||
LWIP_ASSERT("Failed to set up mutex", err == ERR_OK);
|
||||
err = sys_sem_new(&instance->sem, 0);
|
||||
LWIP_UNUSED_ARG(err); /* in case of LWIP_NOASSERT */
|
||||
LWIP_ASSERT("Failed to set up semaphore", err == ERR_OK);
|
||||
instance->sync_fn = sync_fn;
|
||||
err_t err = sys_mutex_new(&instance->sem_usage_mutex);
|
||||
LWIP_ASSERT("Failed to set up mutex", err == ERR_OK);
|
||||
err = sys_sem_new(&instance->sem, 0);
|
||||
LWIP_UNUSED_ARG(err); /* in case of LWIP_NOASSERT */
|
||||
LWIP_ASSERT("Failed to set up semaphore", err == ERR_OK);
|
||||
instance->sync_fn = sync_fn;
|
||||
}
|
||||
|
||||
#endif /* LWIP_SNMP */
|
||||
|
@ -52,28 +52,28 @@
|
||||
#include "snmp_core_priv.h"
|
||||
|
||||
struct snmp_msg_trap {
|
||||
/* source enterprise ID (sysObjectID) */
|
||||
const struct snmp_obj_id *enterprise;
|
||||
/* source IP address, raw network order format */
|
||||
ip_addr_t sip;
|
||||
/* generic trap code */
|
||||
u32_t gen_trap;
|
||||
/* specific trap code */
|
||||
u32_t spc_trap;
|
||||
/* timestamp */
|
||||
u32_t ts;
|
||||
/* snmp_version */
|
||||
u32_t snmp_version;
|
||||
/* source enterprise ID (sysObjectID) */
|
||||
const struct snmp_obj_id *enterprise;
|
||||
/* source IP address, raw network order format */
|
||||
ip_addr_t sip;
|
||||
/* generic trap code */
|
||||
u32_t gen_trap;
|
||||
/* specific trap code */
|
||||
u32_t spc_trap;
|
||||
/* timestamp */
|
||||
u32_t ts;
|
||||
/* snmp_version */
|
||||
u32_t snmp_version;
|
||||
|
||||
/* output trap lengths used in ASN encoding */
|
||||
/* encoding pdu length */
|
||||
u16_t pdulen;
|
||||
/* encoding community length */
|
||||
u16_t comlen;
|
||||
/* encoding sequence length */
|
||||
u16_t seqlen;
|
||||
/* encoding varbinds sequence length */
|
||||
u16_t vbseqlen;
|
||||
/* output trap lengths used in ASN encoding */
|
||||
/* encoding pdu length */
|
||||
u16_t pdulen;
|
||||
/* encoding community length */
|
||||
u16_t comlen;
|
||||
/* encoding sequence length */
|
||||
u16_t seqlen;
|
||||
/* encoding varbinds sequence length */
|
||||
u16_t vbseqlen;
|
||||
};
|
||||
|
||||
static u16_t snmp_trap_varbind_sum(struct snmp_msg_trap *trap, struct snmp_varbind *varbinds);
|
||||
@ -81,11 +81,11 @@ static u16_t snmp_trap_header_sum(struct snmp_msg_trap *trap, u16_t vb_len);
|
||||
static err_t snmp_trap_header_enc(struct snmp_msg_trap *trap, struct snmp_pbuf_stream *pbuf_stream);
|
||||
static err_t snmp_trap_varbind_enc(struct snmp_msg_trap *trap, struct snmp_pbuf_stream *pbuf_stream, struct snmp_varbind *varbinds);
|
||||
|
||||
#define BUILD_EXEC(code) \
|
||||
if ((code) != ERR_OK) { \
|
||||
LWIP_DEBUGF(SNMP_DEBUG, ("SNMP error during creation of outbound trap frame!")); \
|
||||
return ERR_ARG; \
|
||||
}
|
||||
#define BUILD_EXEC(code) \
|
||||
if ((code) != ERR_OK) { \
|
||||
LWIP_DEBUGF(SNMP_DEBUG, ("SNMP error during creation of outbound trap frame!")); \
|
||||
return ERR_ARG; \
|
||||
}
|
||||
|
||||
/** Agent community string for sending traps */
|
||||
extern const char *snmp_community_trap;
|
||||
@ -93,10 +93,10 @@ extern const char *snmp_community_trap;
|
||||
void *snmp_traps_handle;
|
||||
|
||||
struct snmp_trap_dst {
|
||||
/* destination IP address in network order */
|
||||
ip_addr_t dip;
|
||||
/* set to 0 when disabled, >0 when enabled */
|
||||
u8_t enable;
|
||||
/* destination IP address in network order */
|
||||
ip_addr_t dip;
|
||||
/* set to 0 when disabled, >0 when enabled */
|
||||
u8_t enable;
|
||||
};
|
||||
static struct snmp_trap_dst trap_dst[SNMP_TRAP_DESTINATIONS];
|
||||
|
||||
@ -108,13 +108,13 @@ static u8_t snmp_auth_traps_enabled = 0;
|
||||
* @param dst_idx index in 0 .. SNMP_TRAP_DESTINATIONS-1
|
||||
* @param enable switch if 0 destination is disabled >0 enabled.
|
||||
*/
|
||||
void snmp_trap_dst_enable(u8_t dst_idx, u8_t enable)
|
||||
void
|
||||
snmp_trap_dst_enable(u8_t dst_idx, u8_t enable)
|
||||
{
|
||||
LWIP_ASSERT_CORE_LOCKED();
|
||||
|
||||
if (dst_idx < SNMP_TRAP_DESTINATIONS) {
|
||||
trap_dst[dst_idx].enable = enable;
|
||||
}
|
||||
LWIP_ASSERT_CORE_LOCKED();
|
||||
if (dst_idx < SNMP_TRAP_DESTINATIONS) {
|
||||
trap_dst[dst_idx].enable = enable;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -123,33 +123,36 @@ void snmp_trap_dst_enable(u8_t dst_idx, u8_t enable)
|
||||
* @param dst_idx index in 0 .. SNMP_TRAP_DESTINATIONS-1
|
||||
* @param dst IPv4 address in host order.
|
||||
*/
|
||||
void snmp_trap_dst_ip_set(u8_t dst_idx, const ip_addr_t *dst)
|
||||
void
|
||||
snmp_trap_dst_ip_set(u8_t dst_idx, const ip_addr_t *dst)
|
||||
{
|
||||
LWIP_ASSERT_CORE_LOCKED();
|
||||
|
||||
if (dst_idx < SNMP_TRAP_DESTINATIONS) {
|
||||
ip_addr_set(&trap_dst[dst_idx].dip, dst);
|
||||
}
|
||||
LWIP_ASSERT_CORE_LOCKED();
|
||||
if (dst_idx < SNMP_TRAP_DESTINATIONS) {
|
||||
ip_addr_set(&trap_dst[dst_idx].dip, dst);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup snmp_traps
|
||||
* Enable/disable authentication traps
|
||||
*/
|
||||
void snmp_set_auth_traps_enabled(u8_t enable)
|
||||
void
|
||||
snmp_set_auth_traps_enabled(u8_t enable)
|
||||
{
|
||||
snmp_auth_traps_enabled = enable;
|
||||
snmp_auth_traps_enabled = enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup snmp_traps
|
||||
* Get authentication traps enabled state
|
||||
*/
|
||||
u8_t snmp_get_auth_traps_enabled(void)
|
||||
u8_t
|
||||
snmp_get_auth_traps_enabled(void)
|
||||
{
|
||||
return snmp_auth_traps_enabled;
|
||||
return snmp_auth_traps_enabled;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @ingroup snmp_traps
|
||||
* Sends a generic or enterprise specific trap message.
|
||||
@ -166,135 +169,137 @@ u8_t snmp_get_auth_traps_enabled(void)
|
||||
* and .iso.org.dod.internet.private.enterprises.yourenterprise
|
||||
* (sysObjectID) for specific traps.
|
||||
*/
|
||||
err_t snmp_send_trap(const struct snmp_obj_id *eoid, s32_t generic_trap, s32_t specific_trap, struct snmp_varbind *varbinds)
|
||||
err_t
|
||||
snmp_send_trap(const struct snmp_obj_id *eoid, s32_t generic_trap, s32_t specific_trap, struct snmp_varbind *varbinds)
|
||||
{
|
||||
struct snmp_msg_trap trap_msg;
|
||||
struct snmp_trap_dst *td;
|
||||
struct pbuf *p;
|
||||
u16_t i, tot_len;
|
||||
err_t err = ERR_OK;
|
||||
struct snmp_msg_trap trap_msg;
|
||||
struct snmp_trap_dst *td;
|
||||
struct pbuf *p;
|
||||
u16_t i, tot_len;
|
||||
err_t err = ERR_OK;
|
||||
|
||||
LWIP_ASSERT_CORE_LOCKED();
|
||||
LWIP_ASSERT_CORE_LOCKED();
|
||||
|
||||
trap_msg.snmp_version = 0;
|
||||
trap_msg.snmp_version = 0;
|
||||
|
||||
for (i = 0, td = &trap_dst[0]; i < SNMP_TRAP_DESTINATIONS; i++, td++) {
|
||||
if ((td->enable != 0) && !ip_addr_isany(&td->dip)) {
|
||||
/* lookup current source address for this dst */
|
||||
if (snmp_get_local_ip_for_dst(snmp_traps_handle, &td->dip, &trap_msg.sip)) {
|
||||
if (eoid == NULL) {
|
||||
trap_msg.enterprise = snmp_get_device_enterprise_oid();
|
||||
} else {
|
||||
trap_msg.enterprise = eoid;
|
||||
}
|
||||
|
||||
trap_msg.gen_trap = generic_trap;
|
||||
|
||||
if (generic_trap == SNMP_GENTRAP_ENTERPRISE_SPECIFIC) {
|
||||
trap_msg.spc_trap = specific_trap;
|
||||
} else {
|
||||
trap_msg.spc_trap = 0;
|
||||
}
|
||||
|
||||
MIB2_COPY_SYSUPTIME_TO(&trap_msg.ts);
|
||||
|
||||
/* pass 0, calculate length fields */
|
||||
tot_len = snmp_trap_varbind_sum(&trap_msg, varbinds);
|
||||
tot_len = snmp_trap_header_sum(&trap_msg, tot_len);
|
||||
|
||||
/* allocate pbuf(s) */
|
||||
p = pbuf_alloc(PBUF_TRANSPORT, tot_len, PBUF_RAM);
|
||||
|
||||
if (p != NULL) {
|
||||
struct snmp_pbuf_stream pbuf_stream;
|
||||
snmp_pbuf_stream_init(&pbuf_stream, p, 0, tot_len);
|
||||
|
||||
/* pass 1, encode packet into the pbuf(s) */
|
||||
snmp_trap_header_enc(&trap_msg, &pbuf_stream);
|
||||
snmp_trap_varbind_enc(&trap_msg, &pbuf_stream, varbinds);
|
||||
|
||||
snmp_stats.outtraps++;
|
||||
snmp_stats.outpkts++;
|
||||
|
||||
/** send to the TRAP destination */
|
||||
snmp_sendto(snmp_traps_handle, p, &td->dip, LWIP_IANA_PORT_SNMP_TRAP);
|
||||
pbuf_free(p);
|
||||
} else {
|
||||
err = ERR_MEM;
|
||||
}
|
||||
} else {
|
||||
/* routing error */
|
||||
err = ERR_RTE;
|
||||
}
|
||||
for (i = 0, td = &trap_dst[0]; i < SNMP_TRAP_DESTINATIONS; i++, td++) {
|
||||
if ((td->enable != 0) && !ip_addr_isany(&td->dip)) {
|
||||
/* lookup current source address for this dst */
|
||||
if (snmp_get_local_ip_for_dst(snmp_traps_handle, &td->dip, &trap_msg.sip)) {
|
||||
if (eoid == NULL) {
|
||||
trap_msg.enterprise = snmp_get_device_enterprise_oid();
|
||||
} else {
|
||||
trap_msg.enterprise = eoid;
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
trap_msg.gen_trap = generic_trap;
|
||||
if (generic_trap == SNMP_GENTRAP_ENTERPRISE_SPECIFIC) {
|
||||
trap_msg.spc_trap = specific_trap;
|
||||
} else {
|
||||
trap_msg.spc_trap = 0;
|
||||
}
|
||||
|
||||
MIB2_COPY_SYSUPTIME_TO(&trap_msg.ts);
|
||||
|
||||
/* pass 0, calculate length fields */
|
||||
tot_len = snmp_trap_varbind_sum(&trap_msg, varbinds);
|
||||
tot_len = snmp_trap_header_sum(&trap_msg, tot_len);
|
||||
|
||||
/* allocate pbuf(s) */
|
||||
p = pbuf_alloc(PBUF_TRANSPORT, tot_len, PBUF_RAM);
|
||||
if (p != NULL) {
|
||||
struct snmp_pbuf_stream pbuf_stream;
|
||||
snmp_pbuf_stream_init(&pbuf_stream, p, 0, tot_len);
|
||||
|
||||
/* pass 1, encode packet into the pbuf(s) */
|
||||
snmp_trap_header_enc(&trap_msg, &pbuf_stream);
|
||||
snmp_trap_varbind_enc(&trap_msg, &pbuf_stream, varbinds);
|
||||
|
||||
snmp_stats.outtraps++;
|
||||
snmp_stats.outpkts++;
|
||||
|
||||
/** send to the TRAP destination */
|
||||
snmp_sendto(snmp_traps_handle, p, &td->dip, LWIP_IANA_PORT_SNMP_TRAP);
|
||||
pbuf_free(p);
|
||||
} else {
|
||||
err = ERR_MEM;
|
||||
}
|
||||
} else {
|
||||
/* routing error */
|
||||
err = ERR_RTE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup snmp_traps
|
||||
* Send generic SNMP trap
|
||||
*/
|
||||
err_t snmp_send_trap_generic(s32_t generic_trap)
|
||||
err_t
|
||||
snmp_send_trap_generic(s32_t generic_trap)
|
||||
{
|
||||
static const struct snmp_obj_id oid = { 7, { 1, 3, 6, 1, 2, 1, 11 } };
|
||||
return snmp_send_trap(&oid, generic_trap, 0, NULL);
|
||||
static const struct snmp_obj_id oid = { 7, { 1, 3, 6, 1, 2, 1, 11 } };
|
||||
return snmp_send_trap(&oid, generic_trap, 0, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup snmp_traps
|
||||
* Send specific SNMP trap with variable bindings
|
||||
*/
|
||||
err_t snmp_send_trap_specific(s32_t specific_trap, struct snmp_varbind *varbinds)
|
||||
err_t
|
||||
snmp_send_trap_specific(s32_t specific_trap, struct snmp_varbind *varbinds)
|
||||
{
|
||||
return snmp_send_trap(NULL, SNMP_GENTRAP_ENTERPRISE_SPECIFIC, specific_trap, varbinds);
|
||||
return snmp_send_trap(NULL, SNMP_GENTRAP_ENTERPRISE_SPECIFIC, specific_trap, varbinds);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup snmp_traps
|
||||
* Send coldstart trap
|
||||
*/
|
||||
void snmp_coldstart_trap(void)
|
||||
void
|
||||
snmp_coldstart_trap(void)
|
||||
{
|
||||
snmp_send_trap_generic(SNMP_GENTRAP_COLDSTART);
|
||||
snmp_send_trap_generic(SNMP_GENTRAP_COLDSTART);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup snmp_traps
|
||||
* Send authentication failure trap (used internally by agent)
|
||||
*/
|
||||
void snmp_authfail_trap(void)
|
||||
void
|
||||
snmp_authfail_trap(void)
|
||||
{
|
||||
if (snmp_auth_traps_enabled != 0) {
|
||||
snmp_send_trap_generic(SNMP_GENTRAP_AUTH_FAILURE);
|
||||
}
|
||||
if (snmp_auth_traps_enabled != 0) {
|
||||
snmp_send_trap_generic(SNMP_GENTRAP_AUTH_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
static u16_t snmp_trap_varbind_sum(struct snmp_msg_trap *trap, struct snmp_varbind *varbinds)
|
||||
static u16_t
|
||||
snmp_trap_varbind_sum(struct snmp_msg_trap *trap, struct snmp_varbind *varbinds)
|
||||
{
|
||||
struct snmp_varbind *varbind;
|
||||
u16_t tot_len;
|
||||
u8_t tot_len_len;
|
||||
struct snmp_varbind *varbind;
|
||||
u16_t tot_len;
|
||||
u8_t tot_len_len;
|
||||
|
||||
tot_len = 0;
|
||||
varbind = varbinds;
|
||||
tot_len = 0;
|
||||
varbind = varbinds;
|
||||
while (varbind != NULL) {
|
||||
struct snmp_varbind_len len;
|
||||
|
||||
while (varbind != NULL) {
|
||||
struct snmp_varbind_len len;
|
||||
|
||||
if (snmp_varbind_length(varbind, &len) == ERR_OK) {
|
||||
tot_len += 1 + len.vb_len_len + len.vb_value_len;
|
||||
}
|
||||
|
||||
varbind = varbind->next;
|
||||
if (snmp_varbind_length(varbind, &len) == ERR_OK) {
|
||||
tot_len += 1 + len.vb_len_len + len.vb_value_len;
|
||||
}
|
||||
|
||||
trap->vbseqlen = tot_len;
|
||||
snmp_asn1_enc_length_cnt(trap->vbseqlen, &tot_len_len);
|
||||
tot_len += 1 + tot_len_len;
|
||||
varbind = varbind->next;
|
||||
}
|
||||
|
||||
return tot_len;
|
||||
trap->vbseqlen = tot_len;
|
||||
snmp_asn1_enc_length_cnt(trap->vbseqlen, &tot_len_len);
|
||||
tot_len += 1 + tot_len_len;
|
||||
|
||||
return tot_len;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -305,147 +310,149 @@ static u16_t snmp_trap_varbind_sum(struct snmp_msg_trap *trap, struct snmp_varbi
|
||||
* @param vb_len varbind-list length
|
||||
* @return the required length for encoding the trap header
|
||||
*/
|
||||
static u16_t snmp_trap_header_sum(struct snmp_msg_trap *trap, u16_t vb_len)
|
||||
static u16_t
|
||||
snmp_trap_header_sum(struct snmp_msg_trap *trap, u16_t vb_len)
|
||||
{
|
||||
u16_t tot_len;
|
||||
u16_t len;
|
||||
u8_t lenlen;
|
||||
u16_t tot_len;
|
||||
u16_t len;
|
||||
u8_t lenlen;
|
||||
|
||||
tot_len = vb_len;
|
||||
tot_len = vb_len;
|
||||
|
||||
snmp_asn1_enc_u32t_cnt(trap->ts, &len);
|
||||
snmp_asn1_enc_length_cnt(len, &lenlen);
|
||||
tot_len += 1 + len + lenlen;
|
||||
snmp_asn1_enc_u32t_cnt(trap->ts, &len);
|
||||
snmp_asn1_enc_length_cnt(len, &lenlen);
|
||||
tot_len += 1 + len + lenlen;
|
||||
|
||||
snmp_asn1_enc_s32t_cnt(trap->spc_trap, &len);
|
||||
snmp_asn1_enc_length_cnt(len, &lenlen);
|
||||
tot_len += 1 + len + lenlen;
|
||||
snmp_asn1_enc_s32t_cnt(trap->spc_trap, &len);
|
||||
snmp_asn1_enc_length_cnt(len, &lenlen);
|
||||
tot_len += 1 + len + lenlen;
|
||||
|
||||
snmp_asn1_enc_s32t_cnt(trap->gen_trap, &len);
|
||||
snmp_asn1_enc_length_cnt(len, &lenlen);
|
||||
tot_len += 1 + len + lenlen;
|
||||
snmp_asn1_enc_s32t_cnt(trap->gen_trap, &len);
|
||||
snmp_asn1_enc_length_cnt(len, &lenlen);
|
||||
tot_len += 1 + len + lenlen;
|
||||
|
||||
if (IP_IS_V6_VAL(trap->sip)) {
|
||||
if (IP_IS_V6_VAL(trap->sip)) {
|
||||
#if LWIP_IPV6
|
||||
len = sizeof(ip_2_ip6(&trap->sip)->addr);
|
||||
len = sizeof(ip_2_ip6(&trap->sip)->addr);
|
||||
#endif
|
||||
} else {
|
||||
} else {
|
||||
#if LWIP_IPV4
|
||||
len = sizeof(ip_2_ip4(&trap->sip)->addr);
|
||||
len = sizeof(ip_2_ip4(&trap->sip)->addr);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
snmp_asn1_enc_length_cnt(len, &lenlen);
|
||||
tot_len += 1 + len + lenlen;
|
||||
|
||||
snmp_asn1_enc_length_cnt(len, &lenlen);
|
||||
tot_len += 1 + len + lenlen;
|
||||
snmp_asn1_enc_oid_cnt(trap->enterprise->id, trap->enterprise->len, &len);
|
||||
snmp_asn1_enc_length_cnt(len, &lenlen);
|
||||
tot_len += 1 + len + lenlen;
|
||||
|
||||
snmp_asn1_enc_oid_cnt(trap->enterprise->id, trap->enterprise->len, &len);
|
||||
snmp_asn1_enc_length_cnt(len, &lenlen);
|
||||
tot_len += 1 + len + lenlen;
|
||||
trap->pdulen = tot_len;
|
||||
snmp_asn1_enc_length_cnt(trap->pdulen, &lenlen);
|
||||
tot_len += 1 + lenlen;
|
||||
|
||||
trap->pdulen = tot_len;
|
||||
snmp_asn1_enc_length_cnt(trap->pdulen, &lenlen);
|
||||
tot_len += 1 + lenlen;
|
||||
trap->comlen = (u16_t)LWIP_MIN(strlen(snmp_community_trap), 0xFFFF);
|
||||
snmp_asn1_enc_length_cnt(trap->comlen, &lenlen);
|
||||
tot_len += 1 + lenlen + trap->comlen;
|
||||
|
||||
trap->comlen = (u16_t)LWIP_MIN(strlen(snmp_community_trap), 0xFFFF);
|
||||
snmp_asn1_enc_length_cnt(trap->comlen, &lenlen);
|
||||
tot_len += 1 + lenlen + trap->comlen;
|
||||
snmp_asn1_enc_s32t_cnt(trap->snmp_version, &len);
|
||||
snmp_asn1_enc_length_cnt(len, &lenlen);
|
||||
tot_len += 1 + len + lenlen;
|
||||
|
||||
snmp_asn1_enc_s32t_cnt(trap->snmp_version, &len);
|
||||
snmp_asn1_enc_length_cnt(len, &lenlen);
|
||||
tot_len += 1 + len + lenlen;
|
||||
trap->seqlen = tot_len;
|
||||
snmp_asn1_enc_length_cnt(trap->seqlen, &lenlen);
|
||||
tot_len += 1 + lenlen;
|
||||
|
||||
trap->seqlen = tot_len;
|
||||
snmp_asn1_enc_length_cnt(trap->seqlen, &lenlen);
|
||||
tot_len += 1 + lenlen;
|
||||
|
||||
return tot_len;
|
||||
return tot_len;
|
||||
}
|
||||
|
||||
static err_t snmp_trap_varbind_enc(struct snmp_msg_trap *trap, struct snmp_pbuf_stream *pbuf_stream, struct snmp_varbind *varbinds)
|
||||
static err_t
|
||||
snmp_trap_varbind_enc(struct snmp_msg_trap *trap, struct snmp_pbuf_stream *pbuf_stream, struct snmp_varbind *varbinds)
|
||||
{
|
||||
struct snmp_asn1_tlv tlv;
|
||||
struct snmp_varbind *varbind;
|
||||
struct snmp_asn1_tlv tlv;
|
||||
struct snmp_varbind *varbind;
|
||||
|
||||
varbind = varbinds;
|
||||
varbind = varbinds;
|
||||
|
||||
SNMP_ASN1_SET_TLV_PARAMS(tlv, SNMP_ASN1_TYPE_SEQUENCE, 0, trap->vbseqlen);
|
||||
BUILD_EXEC(snmp_ans1_enc_tlv(pbuf_stream, &tlv));
|
||||
SNMP_ASN1_SET_TLV_PARAMS(tlv, SNMP_ASN1_TYPE_SEQUENCE, 0, trap->vbseqlen);
|
||||
BUILD_EXEC( snmp_ans1_enc_tlv(pbuf_stream, &tlv) );
|
||||
|
||||
while (varbind != NULL) {
|
||||
BUILD_EXEC(snmp_append_outbound_varbind(pbuf_stream, varbind));
|
||||
while (varbind != NULL) {
|
||||
BUILD_EXEC( snmp_append_outbound_varbind(pbuf_stream, varbind) );
|
||||
|
||||
varbind = varbind->next;
|
||||
}
|
||||
varbind = varbind->next;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes trap header from head to tail.
|
||||
*/
|
||||
static err_t snmp_trap_header_enc(struct snmp_msg_trap *trap, struct snmp_pbuf_stream *pbuf_stream)
|
||||
static err_t
|
||||
snmp_trap_header_enc(struct snmp_msg_trap *trap, struct snmp_pbuf_stream *pbuf_stream)
|
||||
{
|
||||
struct snmp_asn1_tlv tlv;
|
||||
struct snmp_asn1_tlv tlv;
|
||||
|
||||
/* 'Message' sequence */
|
||||
SNMP_ASN1_SET_TLV_PARAMS(tlv, SNMP_ASN1_TYPE_SEQUENCE, 0, trap->seqlen);
|
||||
BUILD_EXEC(snmp_ans1_enc_tlv(pbuf_stream, &tlv));
|
||||
/* 'Message' sequence */
|
||||
SNMP_ASN1_SET_TLV_PARAMS(tlv, SNMP_ASN1_TYPE_SEQUENCE, 0, trap->seqlen);
|
||||
BUILD_EXEC( snmp_ans1_enc_tlv(pbuf_stream, &tlv) );
|
||||
|
||||
/* version */
|
||||
SNMP_ASN1_SET_TLV_PARAMS(tlv, SNMP_ASN1_TYPE_INTEGER, 0, 0);
|
||||
snmp_asn1_enc_s32t_cnt(trap->snmp_version, &tlv.value_len);
|
||||
BUILD_EXEC(snmp_ans1_enc_tlv(pbuf_stream, &tlv));
|
||||
BUILD_EXEC(snmp_asn1_enc_s32t(pbuf_stream, tlv.value_len, trap->snmp_version));
|
||||
/* version */
|
||||
SNMP_ASN1_SET_TLV_PARAMS(tlv, SNMP_ASN1_TYPE_INTEGER, 0, 0);
|
||||
snmp_asn1_enc_s32t_cnt(trap->snmp_version, &tlv.value_len);
|
||||
BUILD_EXEC( snmp_ans1_enc_tlv(pbuf_stream, &tlv) );
|
||||
BUILD_EXEC( snmp_asn1_enc_s32t(pbuf_stream, tlv.value_len, trap->snmp_version) );
|
||||
|
||||
/* community */
|
||||
SNMP_ASN1_SET_TLV_PARAMS(tlv, SNMP_ASN1_TYPE_OCTET_STRING, 0, trap->comlen);
|
||||
BUILD_EXEC(snmp_ans1_enc_tlv(pbuf_stream, &tlv));
|
||||
BUILD_EXEC(snmp_asn1_enc_raw(pbuf_stream, (const u8_t *)snmp_community_trap, trap->comlen));
|
||||
/* community */
|
||||
SNMP_ASN1_SET_TLV_PARAMS(tlv, SNMP_ASN1_TYPE_OCTET_STRING, 0, trap->comlen);
|
||||
BUILD_EXEC( snmp_ans1_enc_tlv(pbuf_stream, &tlv) );
|
||||
BUILD_EXEC( snmp_asn1_enc_raw(pbuf_stream, (const u8_t *)snmp_community_trap, trap->comlen) );
|
||||
|
||||
/* 'PDU' sequence */
|
||||
SNMP_ASN1_SET_TLV_PARAMS(tlv, (SNMP_ASN1_CLASS_CONTEXT | SNMP_ASN1_CONTENTTYPE_CONSTRUCTED | SNMP_ASN1_CONTEXT_PDU_TRAP), 0, trap->pdulen);
|
||||
BUILD_EXEC(snmp_ans1_enc_tlv(pbuf_stream, &tlv));
|
||||
/* 'PDU' sequence */
|
||||
SNMP_ASN1_SET_TLV_PARAMS(tlv, (SNMP_ASN1_CLASS_CONTEXT | SNMP_ASN1_CONTENTTYPE_CONSTRUCTED | SNMP_ASN1_CONTEXT_PDU_TRAP), 0, trap->pdulen);
|
||||
BUILD_EXEC( snmp_ans1_enc_tlv(pbuf_stream, &tlv) );
|
||||
|
||||
/* object ID */
|
||||
SNMP_ASN1_SET_TLV_PARAMS(tlv, SNMP_ASN1_TYPE_OBJECT_ID, 0, 0);
|
||||
snmp_asn1_enc_oid_cnt(trap->enterprise->id, trap->enterprise->len, &tlv.value_len);
|
||||
BUILD_EXEC(snmp_ans1_enc_tlv(pbuf_stream, &tlv));
|
||||
BUILD_EXEC(snmp_asn1_enc_oid(pbuf_stream, trap->enterprise->id, trap->enterprise->len));
|
||||
/* object ID */
|
||||
SNMP_ASN1_SET_TLV_PARAMS(tlv, SNMP_ASN1_TYPE_OBJECT_ID, 0, 0);
|
||||
snmp_asn1_enc_oid_cnt(trap->enterprise->id, trap->enterprise->len, &tlv.value_len);
|
||||
BUILD_EXEC( snmp_ans1_enc_tlv(pbuf_stream, &tlv) );
|
||||
BUILD_EXEC( snmp_asn1_enc_oid(pbuf_stream, trap->enterprise->id, trap->enterprise->len) );
|
||||
|
||||
/* IP addr */
|
||||
if (IP_IS_V6_VAL(trap->sip)) {
|
||||
/* IP addr */
|
||||
if (IP_IS_V6_VAL(trap->sip)) {
|
||||
#if LWIP_IPV6
|
||||
SNMP_ASN1_SET_TLV_PARAMS(tlv, SNMP_ASN1_TYPE_IPADDR, 0, sizeof(ip_2_ip6(&trap->sip)->addr));
|
||||
BUILD_EXEC(snmp_ans1_enc_tlv(pbuf_stream, &tlv));
|
||||
BUILD_EXEC(snmp_asn1_enc_raw(pbuf_stream, (const u8_t *)&ip_2_ip6(&trap->sip)->addr, sizeof(ip_2_ip6(&trap->sip)->addr)));
|
||||
SNMP_ASN1_SET_TLV_PARAMS(tlv, SNMP_ASN1_TYPE_IPADDR, 0, sizeof(ip_2_ip6(&trap->sip)->addr));
|
||||
BUILD_EXEC( snmp_ans1_enc_tlv(pbuf_stream, &tlv) );
|
||||
BUILD_EXEC( snmp_asn1_enc_raw(pbuf_stream, (const u8_t *)&ip_2_ip6(&trap->sip)->addr, sizeof(ip_2_ip6(&trap->sip)->addr)) );
|
||||
#endif
|
||||
} else {
|
||||
} else {
|
||||
#if LWIP_IPV4
|
||||
SNMP_ASN1_SET_TLV_PARAMS(tlv, SNMP_ASN1_TYPE_IPADDR, 0, sizeof(ip_2_ip4(&trap->sip)->addr));
|
||||
BUILD_EXEC(snmp_ans1_enc_tlv(pbuf_stream, &tlv));
|
||||
BUILD_EXEC(snmp_asn1_enc_raw(pbuf_stream, (const u8_t *)&ip_2_ip4(&trap->sip)->addr, sizeof(ip_2_ip4(&trap->sip)->addr)));
|
||||
SNMP_ASN1_SET_TLV_PARAMS(tlv, SNMP_ASN1_TYPE_IPADDR, 0, sizeof(ip_2_ip4(&trap->sip)->addr));
|
||||
BUILD_EXEC( snmp_ans1_enc_tlv(pbuf_stream, &tlv) );
|
||||
BUILD_EXEC( snmp_asn1_enc_raw(pbuf_stream, (const u8_t *)&ip_2_ip4(&trap->sip)->addr, sizeof(ip_2_ip4(&trap->sip)->addr)) );
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* trap length */
|
||||
SNMP_ASN1_SET_TLV_PARAMS(tlv, SNMP_ASN1_TYPE_INTEGER, 0, 0);
|
||||
snmp_asn1_enc_s32t_cnt(trap->gen_trap, &tlv.value_len);
|
||||
BUILD_EXEC(snmp_ans1_enc_tlv(pbuf_stream, &tlv));
|
||||
BUILD_EXEC(snmp_asn1_enc_s32t(pbuf_stream, tlv.value_len, trap->gen_trap));
|
||||
/* trap length */
|
||||
SNMP_ASN1_SET_TLV_PARAMS(tlv, SNMP_ASN1_TYPE_INTEGER, 0, 0);
|
||||
snmp_asn1_enc_s32t_cnt(trap->gen_trap, &tlv.value_len);
|
||||
BUILD_EXEC( snmp_ans1_enc_tlv(pbuf_stream, &tlv) );
|
||||
BUILD_EXEC( snmp_asn1_enc_s32t(pbuf_stream, tlv.value_len, trap->gen_trap) );
|
||||
|
||||
/* specific trap */
|
||||
SNMP_ASN1_SET_TLV_PARAMS(tlv, SNMP_ASN1_TYPE_INTEGER, 0, 0);
|
||||
snmp_asn1_enc_s32t_cnt(trap->spc_trap, &tlv.value_len);
|
||||
BUILD_EXEC(snmp_ans1_enc_tlv(pbuf_stream, &tlv));
|
||||
BUILD_EXEC(snmp_asn1_enc_s32t(pbuf_stream, tlv.value_len, trap->spc_trap));
|
||||
/* specific trap */
|
||||
SNMP_ASN1_SET_TLV_PARAMS(tlv, SNMP_ASN1_TYPE_INTEGER, 0, 0);
|
||||
snmp_asn1_enc_s32t_cnt(trap->spc_trap, &tlv.value_len);
|
||||
BUILD_EXEC( snmp_ans1_enc_tlv(pbuf_stream, &tlv) );
|
||||
BUILD_EXEC( snmp_asn1_enc_s32t(pbuf_stream, tlv.value_len, trap->spc_trap) );
|
||||
|
||||
/* timestamp */
|
||||
SNMP_ASN1_SET_TLV_PARAMS(tlv, SNMP_ASN1_TYPE_TIMETICKS, 0, 0);
|
||||
snmp_asn1_enc_s32t_cnt(trap->ts, &tlv.value_len);
|
||||
BUILD_EXEC(snmp_ans1_enc_tlv(pbuf_stream, &tlv));
|
||||
BUILD_EXEC(snmp_asn1_enc_s32t(pbuf_stream, tlv.value_len, trap->ts));
|
||||
/* timestamp */
|
||||
SNMP_ASN1_SET_TLV_PARAMS(tlv, SNMP_ASN1_TYPE_TIMETICKS, 0, 0);
|
||||
snmp_asn1_enc_s32t_cnt(trap->ts, &tlv.value_len);
|
||||
BUILD_EXEC( snmp_ans1_enc_tlv(pbuf_stream, &tlv) );
|
||||
BUILD_EXEC( snmp_asn1_enc_s32t(pbuf_stream, tlv.value_len, trap->ts) );
|
||||
|
||||
return ERR_OK;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
#endif /* LWIP_SNMP */
|
||||
|
@ -46,9 +46,10 @@
|
||||
#define SNMP_MAX_TIME_BOOT 2147483647UL
|
||||
|
||||
/** Call this if engine has been changed. Has to reset boots, see below */
|
||||
void snmpv3_engine_id_changed(void)
|
||||
void
|
||||
snmpv3_engine_id_changed(void)
|
||||
{
|
||||
snmpv3_set_engine_boots(0);
|
||||
snmpv3_set_engine_boots(0);
|
||||
}
|
||||
|
||||
/** According to RFC3414 2.2.2.
|
||||
@ -57,15 +58,16 @@ void snmpv3_engine_id_changed(void)
|
||||
* (re-)initialized itself since snmpEngineID
|
||||
* was last configured.
|
||||
*/
|
||||
s32_t snmpv3_get_engine_boots_internal(void)
|
||||
s32_t
|
||||
snmpv3_get_engine_boots_internal(void)
|
||||
{
|
||||
if (snmpv3_get_engine_boots() == 0 ||
|
||||
snmpv3_get_engine_boots() < SNMP_MAX_TIME_BOOT) {
|
||||
return snmpv3_get_engine_boots();
|
||||
}
|
||||
|
||||
snmpv3_set_engine_boots(SNMP_MAX_TIME_BOOT);
|
||||
if (snmpv3_get_engine_boots() == 0 ||
|
||||
snmpv3_get_engine_boots() < SNMP_MAX_TIME_BOOT) {
|
||||
return snmpv3_get_engine_boots();
|
||||
}
|
||||
|
||||
snmpv3_set_engine_boots(SNMP_MAX_TIME_BOOT);
|
||||
return snmpv3_get_engine_boots();
|
||||
}
|
||||
|
||||
/** RFC3414 2.2.2.
|
||||
@ -73,19 +75,20 @@ s32_t snmpv3_get_engine_boots_internal(void)
|
||||
* Once the timer reaches 2147483647 it gets reset to zero and the
|
||||
* engine boot ups get incremented.
|
||||
*/
|
||||
s32_t snmpv3_get_engine_time_internal(void)
|
||||
s32_t
|
||||
snmpv3_get_engine_time_internal(void)
|
||||
{
|
||||
if (snmpv3_get_engine_time() >= SNMP_MAX_TIME_BOOT) {
|
||||
snmpv3_reset_engine_time();
|
||||
if (snmpv3_get_engine_time() >= SNMP_MAX_TIME_BOOT) {
|
||||
snmpv3_reset_engine_time();
|
||||
|
||||
if (snmpv3_get_engine_boots() < SNMP_MAX_TIME_BOOT - 1) {
|
||||
snmpv3_set_engine_boots(snmpv3_get_engine_boots() + 1);
|
||||
} else {
|
||||
snmpv3_set_engine_boots(SNMP_MAX_TIME_BOOT);
|
||||
}
|
||||
if (snmpv3_get_engine_boots() < SNMP_MAX_TIME_BOOT - 1) {
|
||||
snmpv3_set_engine_boots(snmpv3_get_engine_boots() + 1);
|
||||
} else {
|
||||
snmpv3_set_engine_boots(SNMP_MAX_TIME_BOOT);
|
||||
}
|
||||
}
|
||||
|
||||
return snmpv3_get_engine_time();
|
||||
return snmpv3_get_engine_time();
|
||||
}
|
||||
|
||||
#if LWIP_SNMP_V3_CRYPTO
|
||||
@ -97,38 +100,36 @@ s32_t snmpv3_get_engine_time_internal(void)
|
||||
*
|
||||
* @todo: This is a potential thread safety issue.
|
||||
*/
|
||||
err_t snmpv3_build_priv_param(u8_t *priv_param)
|
||||
err_t
|
||||
snmpv3_build_priv_param(u8_t *priv_param)
|
||||
{
|
||||
#ifdef LWIP_RAND /* Based on RFC3826 */
|
||||
static u8_t init;
|
||||
static u32_t priv1, priv2;
|
||||
static u8_t init;
|
||||
static u32_t priv1, priv2;
|
||||
|
||||
/* Lazy initialisation */
|
||||
if (init == 0) {
|
||||
init = 1;
|
||||
priv1 = LWIP_RAND();
|
||||
priv2 = LWIP_RAND();
|
||||
}
|
||||
/* Lazy initialisation */
|
||||
if (init == 0) {
|
||||
init = 1;
|
||||
priv1 = LWIP_RAND();
|
||||
priv2 = LWIP_RAND();
|
||||
}
|
||||
|
||||
SMEMCPY(&priv_param[0], &priv1, sizeof(priv1));
|
||||
SMEMCPY(&priv_param[4], &priv2, sizeof(priv2));
|
||||
|
||||
/* Emulate 64bit increment */
|
||||
priv1++;
|
||||
|
||||
if (!priv1) /* Overflow */
|
||||
{
|
||||
priv2++;
|
||||
}
|
||||
SMEMCPY(&priv_param[0], &priv1, sizeof(priv1));
|
||||
SMEMCPY(&priv_param[4], &priv2, sizeof(priv2));
|
||||
|
||||
/* Emulate 64bit increment */
|
||||
priv1++;
|
||||
if (!priv1) { /* Overflow */
|
||||
priv2++;
|
||||
}
|
||||
#else /* Based on RFC3414 */
|
||||
static u32_t ctr;
|
||||
u32_t boots = snmpv3_get_engine_boots_internal();
|
||||
SMEMCPY(&priv_param[0], &boots, 4);
|
||||
SMEMCPY(&priv_param[4], &ctr, 4);
|
||||
ctr++;
|
||||
static u32_t ctr;
|
||||
u32_t boots = snmpv3_get_engine_boots_internal();
|
||||
SMEMCPY(&priv_param[0], &boots, 4);
|
||||
SMEMCPY(&priv_param[4], &ctr, 4);
|
||||
ctr++;
|
||||
#endif
|
||||
return ERR_OK;
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif /* LWIP_SNMP_V3_CRYPTO */
|
||||
|
||||
|
@ -48,308 +48,295 @@
|
||||
#include "mbedtls/md5.h"
|
||||
#include "mbedtls/sha1.h"
|
||||
|
||||
err_t snmpv3_auth(struct snmp_pbuf_stream *stream, u16_t length,
|
||||
const u8_t *key, snmpv3_auth_algo_t algo, u8_t *hmac_out)
|
||||
err_t
|
||||
snmpv3_auth(struct snmp_pbuf_stream *stream, u16_t length,
|
||||
const u8_t *key, snmpv3_auth_algo_t algo, u8_t *hmac_out)
|
||||
{
|
||||
u32_t i;
|
||||
u8_t key_len;
|
||||
const mbedtls_md_info_t *md_info;
|
||||
mbedtls_md_context_t ctx;
|
||||
struct snmp_pbuf_stream read_stream;
|
||||
snmp_pbuf_stream_init(&read_stream, stream->pbuf, stream->offset, stream->length);
|
||||
u32_t i;
|
||||
u8_t key_len;
|
||||
const mbedtls_md_info_t *md_info;
|
||||
mbedtls_md_context_t ctx;
|
||||
struct snmp_pbuf_stream read_stream;
|
||||
snmp_pbuf_stream_init(&read_stream, stream->pbuf, stream->offset, stream->length);
|
||||
|
||||
if (algo == SNMP_V3_AUTH_ALGO_MD5) {
|
||||
md_info = mbedtls_md_info_from_type(MBEDTLS_MD_MD5);
|
||||
key_len = SNMP_V3_MD5_LEN;
|
||||
} else if (algo == SNMP_V3_AUTH_ALGO_SHA) {
|
||||
md_info = mbedtls_md_info_from_type(MBEDTLS_MD_SHA1);
|
||||
key_len = SNMP_V3_SHA_LEN;
|
||||
} else {
|
||||
return ERR_ARG;
|
||||
if (algo == SNMP_V3_AUTH_ALGO_MD5) {
|
||||
md_info = mbedtls_md_info_from_type(MBEDTLS_MD_MD5);
|
||||
key_len = SNMP_V3_MD5_LEN;
|
||||
} else if (algo == SNMP_V3_AUTH_ALGO_SHA) {
|
||||
md_info = mbedtls_md_info_from_type(MBEDTLS_MD_SHA1);
|
||||
key_len = SNMP_V3_SHA_LEN;
|
||||
} else {
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
mbedtls_md_init(&ctx);
|
||||
if (mbedtls_md_setup(&ctx, md_info, 1) != 0) {
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
if (mbedtls_md_hmac_starts(&ctx, key, key_len) != 0) {
|
||||
goto free_md;
|
||||
}
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
u8_t byte;
|
||||
|
||||
if (snmp_pbuf_stream_read(&read_stream, &byte)) {
|
||||
goto free_md;
|
||||
}
|
||||
|
||||
mbedtls_md_init(&ctx);
|
||||
|
||||
if (mbedtls_md_setup(&ctx, md_info, 1) != 0) {
|
||||
return ERR_ARG;
|
||||
if (mbedtls_md_hmac_update(&ctx, &byte, 1) != 0) {
|
||||
goto free_md;
|
||||
}
|
||||
}
|
||||
|
||||
if (mbedtls_md_hmac_starts(&ctx, key, key_len) != 0) {
|
||||
goto free_md;
|
||||
}
|
||||
if (mbedtls_md_hmac_finish(&ctx, hmac_out) != 0) {
|
||||
goto free_md;
|
||||
}
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
u8_t byte;
|
||||
|
||||
if (snmp_pbuf_stream_read(&read_stream, &byte)) {
|
||||
goto free_md;
|
||||
}
|
||||
|
||||
if (mbedtls_md_hmac_update(&ctx, &byte, 1) != 0) {
|
||||
goto free_md;
|
||||
}
|
||||
}
|
||||
|
||||
if (mbedtls_md_hmac_finish(&ctx, hmac_out) != 0) {
|
||||
goto free_md;
|
||||
}
|
||||
|
||||
mbedtls_md_free(&ctx);
|
||||
return ERR_OK;
|
||||
mbedtls_md_free(&ctx);
|
||||
return ERR_OK;
|
||||
|
||||
free_md:
|
||||
mbedtls_md_free(&ctx);
|
||||
return ERR_ARG;
|
||||
mbedtls_md_free(&ctx);
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
#if LWIP_SNMP_V3_CRYPTO
|
||||
|
||||
err_t snmpv3_crypt(struct snmp_pbuf_stream *stream, u16_t length,
|
||||
const u8_t *key, const u8_t *priv_param, const u32_t engine_boots,
|
||||
const u32_t engine_time, snmpv3_priv_algo_t algo, snmpv3_priv_mode_t mode)
|
||||
err_t
|
||||
snmpv3_crypt(struct snmp_pbuf_stream *stream, u16_t length,
|
||||
const u8_t *key, const u8_t *priv_param, const u32_t engine_boots,
|
||||
const u32_t engine_time, snmpv3_priv_algo_t algo, snmpv3_priv_mode_t mode)
|
||||
{
|
||||
size_t i;
|
||||
mbedtls_cipher_context_t ctx;
|
||||
const mbedtls_cipher_info_t *cipher_info;
|
||||
size_t i;
|
||||
mbedtls_cipher_context_t ctx;
|
||||
const mbedtls_cipher_info_t *cipher_info;
|
||||
|
||||
struct snmp_pbuf_stream read_stream;
|
||||
struct snmp_pbuf_stream write_stream;
|
||||
snmp_pbuf_stream_init(&read_stream, stream->pbuf, stream->offset, stream->length);
|
||||
snmp_pbuf_stream_init(&write_stream, stream->pbuf, stream->offset, stream->length);
|
||||
mbedtls_cipher_init(&ctx);
|
||||
struct snmp_pbuf_stream read_stream;
|
||||
struct snmp_pbuf_stream write_stream;
|
||||
snmp_pbuf_stream_init(&read_stream, stream->pbuf, stream->offset, stream->length);
|
||||
snmp_pbuf_stream_init(&write_stream, stream->pbuf, stream->offset, stream->length);
|
||||
mbedtls_cipher_init(&ctx);
|
||||
|
||||
if (algo == SNMP_V3_PRIV_ALGO_DES) {
|
||||
u8_t iv_local[8];
|
||||
u8_t out_bytes[8];
|
||||
size_t out_len;
|
||||
if (algo == SNMP_V3_PRIV_ALGO_DES) {
|
||||
u8_t iv_local[8];
|
||||
u8_t out_bytes[8];
|
||||
size_t out_len;
|
||||
|
||||
/* RFC 3414 mandates padding for DES */
|
||||
if ((length & 0x07) != 0) {
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
cipher_info = mbedtls_cipher_info_from_type(MBEDTLS_CIPHER_DES_CBC);
|
||||
|
||||
if (mbedtls_cipher_setup(&ctx, cipher_info) != 0) {
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
if (mbedtls_cipher_set_padding_mode(&ctx, MBEDTLS_PADDING_NONE) != 0) {
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
if (mbedtls_cipher_setkey(&ctx, key, 8 * 8, (mode == SNMP_V3_PRIV_MODE_ENCRYPT) ? MBEDTLS_ENCRYPT : MBEDTLS_DECRYPT) != 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Prepare IV */
|
||||
for (i = 0; i < LWIP_ARRAYSIZE(iv_local); i++) {
|
||||
iv_local[i] = priv_param[i] ^ key[i + 8];
|
||||
}
|
||||
|
||||
if (mbedtls_cipher_set_iv(&ctx, iv_local, LWIP_ARRAYSIZE(iv_local)) != 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
for (i = 0; i < length; i += 8) {
|
||||
size_t j;
|
||||
u8_t in_bytes[8];
|
||||
out_len = LWIP_ARRAYSIZE(out_bytes);
|
||||
|
||||
for (j = 0; j < LWIP_ARRAYSIZE(in_bytes); j++) {
|
||||
if (snmp_pbuf_stream_read(&read_stream, &in_bytes[j]) != ERR_OK) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
if (mbedtls_cipher_update(&ctx, in_bytes, LWIP_ARRAYSIZE(in_bytes), out_bytes, &out_len) != 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (snmp_pbuf_stream_writebuf(&write_stream, out_bytes, (u16_t)out_len) != ERR_OK) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
out_len = LWIP_ARRAYSIZE(out_bytes);
|
||||
|
||||
if (mbedtls_cipher_finish(&ctx, out_bytes, &out_len) != 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (snmp_pbuf_stream_writebuf(&write_stream, out_bytes, (u16_t)out_len) != ERR_OK) {
|
||||
goto error;
|
||||
}
|
||||
} else if (algo == SNMP_V3_PRIV_ALGO_AES) {
|
||||
u8_t iv_local[16];
|
||||
|
||||
cipher_info = mbedtls_cipher_info_from_type(MBEDTLS_CIPHER_AES_128_CFB128);
|
||||
|
||||
if (mbedtls_cipher_setup(&ctx, cipher_info) != 0) {
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
if (mbedtls_cipher_setkey(&ctx, key, 16 * 8, (mode == SNMP_V3_PRIV_MODE_ENCRYPT) ? MBEDTLS_ENCRYPT : MBEDTLS_DECRYPT) != 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
/*
|
||||
* IV is the big endian concatenation of boots,
|
||||
* uptime and priv param - see RFC3826.
|
||||
*/
|
||||
iv_local[0 + 0] = (engine_boots >> 24) & 0xFF;
|
||||
iv_local[0 + 1] = (engine_boots >> 16) & 0xFF;
|
||||
iv_local[0 + 2] = (engine_boots >> 8) & 0xFF;
|
||||
iv_local[0 + 3] = (engine_boots >> 0) & 0xFF;
|
||||
iv_local[4 + 0] = (engine_time >> 24) & 0xFF;
|
||||
iv_local[4 + 1] = (engine_time >> 16) & 0xFF;
|
||||
iv_local[4 + 2] = (engine_time >> 8) & 0xFF;
|
||||
iv_local[4 + 3] = (engine_time >> 0) & 0xFF;
|
||||
SMEMCPY(iv_local + 8, priv_param, 8);
|
||||
|
||||
if (mbedtls_cipher_set_iv(&ctx, iv_local, LWIP_ARRAYSIZE(iv_local)) != 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
u8_t in_byte;
|
||||
u8_t out_byte;
|
||||
size_t out_len = sizeof(out_byte);
|
||||
|
||||
if (snmp_pbuf_stream_read(&read_stream, &in_byte) != ERR_OK) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (mbedtls_cipher_update(&ctx, &in_byte, sizeof(in_byte), &out_byte, &out_len) != 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (snmp_pbuf_stream_write(&write_stream, out_byte) != ERR_OK) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return ERR_ARG;
|
||||
/* RFC 3414 mandates padding for DES */
|
||||
if ((length & 0x07) != 0) {
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
mbedtls_cipher_free(&ctx);
|
||||
return ERR_OK;
|
||||
cipher_info = mbedtls_cipher_info_from_type(MBEDTLS_CIPHER_DES_CBC);
|
||||
if (mbedtls_cipher_setup(&ctx, cipher_info) != 0) {
|
||||
return ERR_ARG;
|
||||
}
|
||||
if (mbedtls_cipher_set_padding_mode(&ctx, MBEDTLS_PADDING_NONE) != 0) {
|
||||
return ERR_ARG;
|
||||
}
|
||||
if (mbedtls_cipher_setkey(&ctx, key, 8 * 8, (mode == SNMP_V3_PRIV_MODE_ENCRYPT) ? MBEDTLS_ENCRYPT : MBEDTLS_DECRYPT) != 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Prepare IV */
|
||||
for (i = 0; i < LWIP_ARRAYSIZE(iv_local); i++) {
|
||||
iv_local[i] = priv_param[i] ^ key[i + 8];
|
||||
}
|
||||
if (mbedtls_cipher_set_iv(&ctx, iv_local, LWIP_ARRAYSIZE(iv_local)) != 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
for (i = 0; i < length; i += 8) {
|
||||
size_t j;
|
||||
u8_t in_bytes[8];
|
||||
out_len = LWIP_ARRAYSIZE(out_bytes) ;
|
||||
|
||||
for (j = 0; j < LWIP_ARRAYSIZE(in_bytes); j++) {
|
||||
if (snmp_pbuf_stream_read(&read_stream, &in_bytes[j]) != ERR_OK) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
if (mbedtls_cipher_update(&ctx, in_bytes, LWIP_ARRAYSIZE(in_bytes), out_bytes, &out_len) != 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (snmp_pbuf_stream_writebuf(&write_stream, out_bytes, (u16_t)out_len) != ERR_OK) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
out_len = LWIP_ARRAYSIZE(out_bytes);
|
||||
if (mbedtls_cipher_finish(&ctx, out_bytes, &out_len) != 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (snmp_pbuf_stream_writebuf(&write_stream, out_bytes, (u16_t)out_len) != ERR_OK) {
|
||||
goto error;
|
||||
}
|
||||
} else if (algo == SNMP_V3_PRIV_ALGO_AES) {
|
||||
u8_t iv_local[16];
|
||||
|
||||
cipher_info = mbedtls_cipher_info_from_type(MBEDTLS_CIPHER_AES_128_CFB128);
|
||||
if (mbedtls_cipher_setup(&ctx, cipher_info) != 0) {
|
||||
return ERR_ARG;
|
||||
}
|
||||
if (mbedtls_cipher_setkey(&ctx, key, 16 * 8, (mode == SNMP_V3_PRIV_MODE_ENCRYPT) ? MBEDTLS_ENCRYPT : MBEDTLS_DECRYPT) != 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
/*
|
||||
* IV is the big endian concatenation of boots,
|
||||
* uptime and priv param - see RFC3826.
|
||||
*/
|
||||
iv_local[0 + 0] = (engine_boots >> 24) & 0xFF;
|
||||
iv_local[0 + 1] = (engine_boots >> 16) & 0xFF;
|
||||
iv_local[0 + 2] = (engine_boots >> 8) & 0xFF;
|
||||
iv_local[0 + 3] = (engine_boots >> 0) & 0xFF;
|
||||
iv_local[4 + 0] = (engine_time >> 24) & 0xFF;
|
||||
iv_local[4 + 1] = (engine_time >> 16) & 0xFF;
|
||||
iv_local[4 + 2] = (engine_time >> 8) & 0xFF;
|
||||
iv_local[4 + 3] = (engine_time >> 0) & 0xFF;
|
||||
SMEMCPY(iv_local + 8, priv_param, 8);
|
||||
if (mbedtls_cipher_set_iv(&ctx, iv_local, LWIP_ARRAYSIZE(iv_local)) != 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
u8_t in_byte;
|
||||
u8_t out_byte;
|
||||
size_t out_len = sizeof(out_byte);
|
||||
|
||||
if (snmp_pbuf_stream_read(&read_stream, &in_byte) != ERR_OK) {
|
||||
goto error;
|
||||
}
|
||||
if (mbedtls_cipher_update(&ctx, &in_byte, sizeof(in_byte), &out_byte, &out_len) != 0) {
|
||||
goto error;
|
||||
}
|
||||
if (snmp_pbuf_stream_write(&write_stream, out_byte) != ERR_OK) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
mbedtls_cipher_free(&ctx);
|
||||
return ERR_OK;
|
||||
|
||||
error:
|
||||
mbedtls_cipher_free(&ctx);
|
||||
return ERR_OK;
|
||||
mbedtls_cipher_free(&ctx);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
#endif /* LWIP_SNMP_V3_CRYPTO */
|
||||
|
||||
/* A.2.1. Password to Key Sample Code for MD5 */
|
||||
void snmpv3_password_to_key_md5(
|
||||
const u8_t *password, /* IN */
|
||||
size_t passwordlen, /* IN */
|
||||
const u8_t *engineID, /* IN - pointer to snmpEngineID */
|
||||
u8_t engineLength, /* IN - length of snmpEngineID */
|
||||
u8_t *key) /* OUT - pointer to caller 16-octet buffer */
|
||||
void
|
||||
snmpv3_password_to_key_md5(
|
||||
const u8_t *password, /* IN */
|
||||
size_t passwordlen, /* IN */
|
||||
const u8_t *engineID, /* IN - pointer to snmpEngineID */
|
||||
u8_t engineLength,/* IN - length of snmpEngineID */
|
||||
u8_t *key) /* OUT - pointer to caller 16-octet buffer */
|
||||
{
|
||||
mbedtls_md5_context MD;
|
||||
u8_t *cp, password_buf[64];
|
||||
u32_t password_index = 0;
|
||||
u8_t i;
|
||||
u32_t count = 0;
|
||||
mbedtls_md5_context MD;
|
||||
u8_t *cp, password_buf[64];
|
||||
u32_t password_index = 0;
|
||||
u8_t i;
|
||||
u32_t count = 0;
|
||||
|
||||
mbedtls_md5_init(&MD); /* initialize MD5 */
|
||||
mbedtls_md5_starts(&MD);
|
||||
mbedtls_md5_init(&MD); /* initialize MD5 */
|
||||
mbedtls_md5_starts(&MD);
|
||||
|
||||
/**********************************************/
|
||||
/* Use while loop until we've done 1 Megabyte */
|
||||
/**********************************************/
|
||||
while (count < 1048576) {
|
||||
cp = password_buf;
|
||||
|
||||
for (i = 0; i < 64; i++) {
|
||||
/*************************************************/
|
||||
/* Take the next octet of the password, wrapping */
|
||||
/* to the beginning of the password as necessary.*/
|
||||
/*************************************************/
|
||||
*cp++ = password[password_index++ % passwordlen];
|
||||
}
|
||||
|
||||
mbedtls_md5_update(&MD, password_buf, 64);
|
||||
count += 64;
|
||||
/**********************************************/
|
||||
/* Use while loop until we've done 1 Megabyte */
|
||||
/**********************************************/
|
||||
while (count < 1048576) {
|
||||
cp = password_buf;
|
||||
for (i = 0; i < 64; i++) {
|
||||
/*************************************************/
|
||||
/* Take the next octet of the password, wrapping */
|
||||
/* to the beginning of the password as necessary.*/
|
||||
/*************************************************/
|
||||
*cp++ = password[password_index++ % passwordlen];
|
||||
}
|
||||
mbedtls_md5_update(&MD, password_buf, 64);
|
||||
count += 64;
|
||||
}
|
||||
mbedtls_md5_finish(&MD, key); /* tell MD5 we're done */
|
||||
|
||||
mbedtls_md5_finish(&MD, key); /* tell MD5 we're done */
|
||||
/*****************************************************/
|
||||
/* Now localize the key with the engineID and pass */
|
||||
/* through MD5 to produce final key */
|
||||
/* May want to ensure that engineLength <= 32, */
|
||||
/* otherwise need to use a buffer larger than 64 */
|
||||
/*****************************************************/
|
||||
SMEMCPY(password_buf, key, 16);
|
||||
MEMCPY(password_buf + 16, engineID, engineLength);
|
||||
SMEMCPY(password_buf + 16 + engineLength, key, 16);
|
||||
|
||||
/*****************************************************/
|
||||
/* Now localize the key with the engineID and pass */
|
||||
/* through MD5 to produce final key */
|
||||
/* May want to ensure that engineLength <= 32, */
|
||||
/* otherwise need to use a buffer larger than 64 */
|
||||
/*****************************************************/
|
||||
SMEMCPY(password_buf, key, 16);
|
||||
MEMCPY(password_buf + 16, engineID, engineLength);
|
||||
SMEMCPY(password_buf + 16 + engineLength, key, 16);
|
||||
mbedtls_md5_starts(&MD);
|
||||
mbedtls_md5_update(&MD, password_buf, 32 + engineLength);
|
||||
mbedtls_md5_finish(&MD, key);
|
||||
|
||||
mbedtls_md5_starts(&MD);
|
||||
mbedtls_md5_update(&MD, password_buf, 32 + engineLength);
|
||||
mbedtls_md5_finish(&MD, key);
|
||||
|
||||
mbedtls_md5_free(&MD);
|
||||
return;
|
||||
mbedtls_md5_free(&MD);
|
||||
return;
|
||||
}
|
||||
|
||||
/* A.2.2. Password to Key Sample Code for SHA */
|
||||
void snmpv3_password_to_key_sha(
|
||||
const u8_t *password, /* IN */
|
||||
size_t passwordlen, /* IN */
|
||||
const u8_t *engineID, /* IN - pointer to snmpEngineID */
|
||||
u8_t engineLength, /* IN - length of snmpEngineID */
|
||||
u8_t *key) /* OUT - pointer to caller 20-octet buffer */
|
||||
void
|
||||
snmpv3_password_to_key_sha(
|
||||
const u8_t *password, /* IN */
|
||||
size_t passwordlen, /* IN */
|
||||
const u8_t *engineID, /* IN - pointer to snmpEngineID */
|
||||
u8_t engineLength,/* IN - length of snmpEngineID */
|
||||
u8_t *key) /* OUT - pointer to caller 20-octet buffer */
|
||||
{
|
||||
mbedtls_sha1_context SH;
|
||||
u8_t *cp, password_buf[72];
|
||||
u32_t password_index = 0;
|
||||
u8_t i;
|
||||
u32_t count = 0;
|
||||
mbedtls_sha1_context SH;
|
||||
u8_t *cp, password_buf[72];
|
||||
u32_t password_index = 0;
|
||||
u8_t i;
|
||||
u32_t count = 0;
|
||||
|
||||
mbedtls_sha1_init(&SH); /* initialize SHA */
|
||||
mbedtls_sha1_starts(&SH);
|
||||
mbedtls_sha1_init(&SH); /* initialize SHA */
|
||||
mbedtls_sha1_starts(&SH);
|
||||
|
||||
/**********************************************/
|
||||
/* Use while loop until we've done 1 Megabyte */
|
||||
/**********************************************/
|
||||
while (count < 1048576) {
|
||||
cp = password_buf;
|
||||
|
||||
for (i = 0; i < 64; i++) {
|
||||
/*************************************************/
|
||||
/* Take the next octet of the password, wrapping */
|
||||
/* to the beginning of the password as necessary.*/
|
||||
/*************************************************/
|
||||
*cp++ = password[password_index++ % passwordlen];
|
||||
}
|
||||
|
||||
mbedtls_sha1_update(&SH, password_buf, 64);
|
||||
count += 64;
|
||||
/**********************************************/
|
||||
/* Use while loop until we've done 1 Megabyte */
|
||||
/**********************************************/
|
||||
while (count < 1048576) {
|
||||
cp = password_buf;
|
||||
for (i = 0; i < 64; i++) {
|
||||
/*************************************************/
|
||||
/* Take the next octet of the password, wrapping */
|
||||
/* to the beginning of the password as necessary.*/
|
||||
/*************************************************/
|
||||
*cp++ = password[password_index++ % passwordlen];
|
||||
}
|
||||
mbedtls_sha1_update(&SH, password_buf, 64);
|
||||
count += 64;
|
||||
}
|
||||
mbedtls_sha1_finish(&SH, key); /* tell SHA we're done */
|
||||
|
||||
mbedtls_sha1_finish(&SH, key); /* tell SHA we're done */
|
||||
/*****************************************************/
|
||||
/* Now localize the key with the engineID and pass */
|
||||
/* through SHA to produce final key */
|
||||
/* May want to ensure that engineLength <= 32, */
|
||||
/* otherwise need to use a buffer larger than 72 */
|
||||
/*****************************************************/
|
||||
SMEMCPY(password_buf, key, 20);
|
||||
MEMCPY(password_buf + 20, engineID, engineLength);
|
||||
SMEMCPY(password_buf + 20 + engineLength, key, 20);
|
||||
|
||||
/*****************************************************/
|
||||
/* Now localize the key with the engineID and pass */
|
||||
/* through SHA to produce final key */
|
||||
/* May want to ensure that engineLength <= 32, */
|
||||
/* otherwise need to use a buffer larger than 72 */
|
||||
/*****************************************************/
|
||||
SMEMCPY(password_buf, key, 20);
|
||||
MEMCPY(password_buf + 20, engineID, engineLength);
|
||||
SMEMCPY(password_buf + 20 + engineLength, key, 20);
|
||||
mbedtls_sha1_starts(&SH);
|
||||
mbedtls_sha1_update(&SH, password_buf, 40 + engineLength);
|
||||
mbedtls_sha1_finish(&SH, key);
|
||||
|
||||
mbedtls_sha1_starts(&SH);
|
||||
mbedtls_sha1_update(&SH, password_buf, 40 + engineLength);
|
||||
mbedtls_sha1_finish(&SH, key);
|
||||
|
||||
mbedtls_sha1_free(&SH);
|
||||
return;
|
||||
mbedtls_sha1_free(&SH);
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* LWIP_SNMP && LWIP_SNMP_V3 && LWIP_SNMP_V3_MBEDTLS */
|
||||
|
@ -43,18 +43,18 @@
|
||||
#include "snmp_pbuf_stream.h"
|
||||
|
||||
/* According to RFC 3411 */
|
||||
#define SNMP_V3_MAX_ENGINE_ID_LENGTH 32
|
||||
#define SNMP_V3_MAX_USER_LENGTH 32
|
||||
#define SNMP_V3_MAX_ENGINE_ID_LENGTH 32
|
||||
#define SNMP_V3_MAX_USER_LENGTH 32
|
||||
|
||||
#define SNMP_V3_MAX_AUTH_PARAM_LENGTH 12
|
||||
#define SNMP_V3_MAX_PRIV_PARAM_LENGTH 8
|
||||
#define SNMP_V3_MAX_AUTH_PARAM_LENGTH 12
|
||||
#define SNMP_V3_MAX_PRIV_PARAM_LENGTH 8
|
||||
|
||||
#define SNMP_V3_MD5_LEN 16
|
||||
#define SNMP_V3_SHA_LEN 20
|
||||
#define SNMP_V3_MD5_LEN 16
|
||||
#define SNMP_V3_SHA_LEN 20
|
||||
|
||||
typedef enum {
|
||||
SNMP_V3_PRIV_MODE_DECRYPT = 0,
|
||||
SNMP_V3_PRIV_MODE_ENCRYPT = 1
|
||||
SNMP_V3_PRIV_MODE_DECRYPT = 0,
|
||||
SNMP_V3_PRIV_MODE_ENCRYPT = 1
|
||||
} snmpv3_priv_mode_t;
|
||||
|
||||
s32_t snmpv3_get_engine_boots_internal(void);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -65,368 +65,360 @@
|
||||
#define TFTP_ERROR 5
|
||||
|
||||
enum tftp_error {
|
||||
TFTP_ERROR_FILE_NOT_FOUND = 1,
|
||||
TFTP_ERROR_ACCESS_VIOLATION = 2,
|
||||
TFTP_ERROR_DISK_FULL = 3,
|
||||
TFTP_ERROR_ILLEGAL_OPERATION = 4,
|
||||
TFTP_ERROR_UNKNOWN_TRFR_ID = 5,
|
||||
TFTP_ERROR_FILE_EXISTS = 6,
|
||||
TFTP_ERROR_NO_SUCH_USER = 7
|
||||
TFTP_ERROR_FILE_NOT_FOUND = 1,
|
||||
TFTP_ERROR_ACCESS_VIOLATION = 2,
|
||||
TFTP_ERROR_DISK_FULL = 3,
|
||||
TFTP_ERROR_ILLEGAL_OPERATION = 4,
|
||||
TFTP_ERROR_UNKNOWN_TRFR_ID = 5,
|
||||
TFTP_ERROR_FILE_EXISTS = 6,
|
||||
TFTP_ERROR_NO_SUCH_USER = 7
|
||||
};
|
||||
|
||||
#include <string.h>
|
||||
|
||||
struct tftp_state {
|
||||
const struct tftp_context *ctx;
|
||||
void *handle;
|
||||
struct pbuf *last_data;
|
||||
struct udp_pcb *upcb;
|
||||
ip_addr_t addr;
|
||||
u16_t port;
|
||||
int timer;
|
||||
int last_pkt;
|
||||
u16_t blknum;
|
||||
u8_t retries;
|
||||
u8_t mode_write;
|
||||
const struct tftp_context *ctx;
|
||||
void *handle;
|
||||
struct pbuf *last_data;
|
||||
struct udp_pcb *upcb;
|
||||
ip_addr_t addr;
|
||||
u16_t port;
|
||||
int timer;
|
||||
int last_pkt;
|
||||
u16_t blknum;
|
||||
u8_t retries;
|
||||
u8_t mode_write;
|
||||
};
|
||||
|
||||
static struct tftp_state tftp_state;
|
||||
|
||||
static void tftp_tmr(void *arg);
|
||||
|
||||
static void close_handle(void)
|
||||
static void
|
||||
close_handle(void)
|
||||
{
|
||||
tftp_state.port = 0;
|
||||
ip_addr_set_any(0, &tftp_state.addr);
|
||||
tftp_state.port = 0;
|
||||
ip_addr_set_any(0, &tftp_state.addr);
|
||||
|
||||
if (tftp_state.last_data != NULL) {
|
||||
pbuf_free(tftp_state.last_data);
|
||||
tftp_state.last_data = NULL;
|
||||
}
|
||||
if (tftp_state.last_data != NULL) {
|
||||
pbuf_free(tftp_state.last_data);
|
||||
tftp_state.last_data = NULL;
|
||||
}
|
||||
|
||||
sys_untimeout(tftp_tmr, NULL);
|
||||
sys_untimeout(tftp_tmr, NULL);
|
||||
|
||||
if (tftp_state.handle) {
|
||||
tftp_state.ctx->close(tftp_state.handle);
|
||||
tftp_state.handle = NULL;
|
||||
LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE, ("tftp: closing\n"));
|
||||
}
|
||||
if (tftp_state.handle) {
|
||||
tftp_state.ctx->close(tftp_state.handle);
|
||||
tftp_state.handle = NULL;
|
||||
LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE, ("tftp: closing\n"));
|
||||
}
|
||||
}
|
||||
|
||||
static void send_error(const ip_addr_t *addr, u16_t port, enum tftp_error code, const char *str)
|
||||
static void
|
||||
send_error(const ip_addr_t *addr, u16_t port, enum tftp_error code, const char *str)
|
||||
{
|
||||
int str_length = strlen(str);
|
||||
struct pbuf *p;
|
||||
u16_t *payload;
|
||||
int str_length = strlen(str);
|
||||
struct pbuf *p;
|
||||
u16_t *payload;
|
||||
|
||||
p = pbuf_alloc(PBUF_TRANSPORT, (u16_t)(TFTP_HEADER_LENGTH + str_length + 1), PBUF_RAM);
|
||||
p = pbuf_alloc(PBUF_TRANSPORT, (u16_t)(TFTP_HEADER_LENGTH + str_length + 1), PBUF_RAM);
|
||||
if (p == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (p == NULL) {
|
||||
return;
|
||||
}
|
||||
payload = (u16_t *) p->payload;
|
||||
payload[0] = PP_HTONS(TFTP_ERROR);
|
||||
payload[1] = lwip_htons(code);
|
||||
MEMCPY(&payload[2], str, str_length + 1);
|
||||
|
||||
payload = (u16_t *)p->payload;
|
||||
payload[0] = PP_HTONS(TFTP_ERROR);
|
||||
payload[1] = lwip_htons(code);
|
||||
MEMCPY(&payload[2], str, str_length + 1);
|
||||
udp_sendto(tftp_state.upcb, p, addr, port);
|
||||
pbuf_free(p);
|
||||
}
|
||||
|
||||
udp_sendto(tftp_state.upcb, p, addr, port);
|
||||
static void
|
||||
send_ack(u16_t blknum)
|
||||
{
|
||||
struct pbuf *p;
|
||||
u16_t *payload;
|
||||
|
||||
p = pbuf_alloc(PBUF_TRANSPORT, TFTP_HEADER_LENGTH, PBUF_RAM);
|
||||
if (p == NULL) {
|
||||
return;
|
||||
}
|
||||
payload = (u16_t *) p->payload;
|
||||
|
||||
payload[0] = PP_HTONS(TFTP_ACK);
|
||||
payload[1] = lwip_htons(blknum);
|
||||
udp_sendto(tftp_state.upcb, p, &tftp_state.addr, tftp_state.port);
|
||||
pbuf_free(p);
|
||||
}
|
||||
|
||||
static void
|
||||
resend_data(void)
|
||||
{
|
||||
struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, tftp_state.last_data->len, PBUF_RAM);
|
||||
if (p == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pbuf_copy(p, tftp_state.last_data) != ERR_OK) {
|
||||
pbuf_free(p);
|
||||
return;
|
||||
}
|
||||
|
||||
udp_sendto(tftp_state.upcb, p, &tftp_state.addr, tftp_state.port);
|
||||
pbuf_free(p);
|
||||
}
|
||||
|
||||
static void send_ack(u16_t blknum)
|
||||
static void
|
||||
send_data(void)
|
||||
{
|
||||
struct pbuf *p;
|
||||
u16_t *payload;
|
||||
u16_t *payload;
|
||||
int ret;
|
||||
|
||||
p = pbuf_alloc(PBUF_TRANSPORT, TFTP_HEADER_LENGTH, PBUF_RAM);
|
||||
if (tftp_state.last_data != NULL) {
|
||||
pbuf_free(tftp_state.last_data);
|
||||
}
|
||||
|
||||
if (p == NULL) {
|
||||
return;
|
||||
}
|
||||
tftp_state.last_data = pbuf_alloc(PBUF_TRANSPORT, TFTP_HEADER_LENGTH + TFTP_MAX_PAYLOAD_SIZE, PBUF_RAM);
|
||||
if (tftp_state.last_data == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
payload = (u16_t *)p->payload;
|
||||
payload = (u16_t *) tftp_state.last_data->payload;
|
||||
payload[0] = PP_HTONS(TFTP_DATA);
|
||||
payload[1] = lwip_htons(tftp_state.blknum);
|
||||
|
||||
payload[0] = PP_HTONS(TFTP_ACK);
|
||||
payload[1] = lwip_htons(blknum);
|
||||
udp_sendto(tftp_state.upcb, p, &tftp_state.addr, tftp_state.port);
|
||||
ret = tftp_state.ctx->read(tftp_state.handle, &payload[2], TFTP_MAX_PAYLOAD_SIZE);
|
||||
if (ret < 0) {
|
||||
send_error(&tftp_state.addr, tftp_state.port, TFTP_ERROR_ACCESS_VIOLATION, "Error occured while reading the file.");
|
||||
close_handle();
|
||||
return;
|
||||
}
|
||||
|
||||
pbuf_realloc(tftp_state.last_data, (u16_t)(TFTP_HEADER_LENGTH + ret));
|
||||
resend_data();
|
||||
}
|
||||
|
||||
static void
|
||||
recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
|
||||
{
|
||||
u16_t *sbuf = (u16_t *) p->payload;
|
||||
int opcode;
|
||||
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
LWIP_UNUSED_ARG(upcb);
|
||||
|
||||
if (((tftp_state.port != 0) && (port != tftp_state.port)) ||
|
||||
(!ip_addr_isany_val(tftp_state.addr) && !ip_addr_cmp(&tftp_state.addr, addr))) {
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Only one connection at a time is supported");
|
||||
pbuf_free(p);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static void resend_data(void)
|
||||
{
|
||||
struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, tftp_state.last_data->len, PBUF_RAM);
|
||||
opcode = sbuf[0];
|
||||
|
||||
if (p == NULL) {
|
||||
return;
|
||||
}
|
||||
tftp_state.last_pkt = tftp_state.timer;
|
||||
tftp_state.retries = 0;
|
||||
|
||||
if (pbuf_copy(p, tftp_state.last_data) != ERR_OK) {
|
||||
pbuf_free(p);
|
||||
return;
|
||||
}
|
||||
switch (opcode) {
|
||||
case PP_HTONS(TFTP_RRQ): /* fall through */
|
||||
case PP_HTONS(TFTP_WRQ): {
|
||||
const char tftp_null = 0;
|
||||
char filename[TFTP_MAX_FILENAME_LEN + 1];
|
||||
char mode[TFTP_MAX_MODE_LEN + 1];
|
||||
u16_t filename_end_offset;
|
||||
u16_t mode_end_offset;
|
||||
|
||||
udp_sendto(tftp_state.upcb, p, &tftp_state.addr, tftp_state.port);
|
||||
pbuf_free(p);
|
||||
}
|
||||
|
||||
static void send_data(void)
|
||||
{
|
||||
u16_t *payload;
|
||||
int ret;
|
||||
|
||||
if (tftp_state.last_data != NULL) {
|
||||
pbuf_free(tftp_state.last_data);
|
||||
}
|
||||
|
||||
tftp_state.last_data = pbuf_alloc(PBUF_TRANSPORT, TFTP_HEADER_LENGTH + TFTP_MAX_PAYLOAD_SIZE, PBUF_RAM);
|
||||
|
||||
if (tftp_state.last_data == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
payload = (u16_t *)tftp_state.last_data->payload;
|
||||
payload[0] = PP_HTONS(TFTP_DATA);
|
||||
payload[1] = lwip_htons(tftp_state.blknum);
|
||||
|
||||
ret = tftp_state.ctx->read(tftp_state.handle, &payload[2], TFTP_MAX_PAYLOAD_SIZE);
|
||||
|
||||
if (ret < 0) {
|
||||
send_error(&tftp_state.addr, tftp_state.port, TFTP_ERROR_ACCESS_VIOLATION, "Error occured while reading the file.");
|
||||
close_handle();
|
||||
return;
|
||||
}
|
||||
|
||||
pbuf_realloc(tftp_state.last_data, (u16_t)(TFTP_HEADER_LENGTH + ret));
|
||||
resend_data();
|
||||
}
|
||||
|
||||
static void recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
|
||||
{
|
||||
u16_t *sbuf = (u16_t *)p->payload;
|
||||
int opcode;
|
||||
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
LWIP_UNUSED_ARG(upcb);
|
||||
|
||||
if (((tftp_state.port != 0) && (port != tftp_state.port)) ||
|
||||
(!ip_addr_isany_val(tftp_state.addr) && !ip_addr_cmp(&tftp_state.addr, addr))) {
|
||||
if (tftp_state.handle != NULL) {
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Only one connection at a time is supported");
|
||||
pbuf_free(p);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
sys_timeout(TFTP_TIMER_MSECS, tftp_tmr, NULL);
|
||||
|
||||
/* find \0 in pbuf -> end of filename string */
|
||||
filename_end_offset = pbuf_memfind(p, &tftp_null, sizeof(tftp_null), 2);
|
||||
if ((u16_t)(filename_end_offset - 1) > sizeof(filename)) {
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Filename too long/not NULL terminated");
|
||||
break;
|
||||
}
|
||||
pbuf_copy_partial(p, filename, filename_end_offset - 1, 2);
|
||||
|
||||
/* find \0 in pbuf -> end of mode string */
|
||||
mode_end_offset = pbuf_memfind(p, &tftp_null, sizeof(tftp_null), filename_end_offset + 1);
|
||||
if ((u16_t)(mode_end_offset - filename_end_offset) > sizeof(mode)) {
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Mode too long/not NULL terminated");
|
||||
break;
|
||||
}
|
||||
pbuf_copy_partial(p, mode, mode_end_offset - filename_end_offset, filename_end_offset + 1);
|
||||
|
||||
tftp_state.handle = tftp_state.ctx->open(filename, mode, opcode == PP_HTONS(TFTP_WRQ));
|
||||
tftp_state.blknum = 1;
|
||||
|
||||
if (!tftp_state.handle) {
|
||||
send_error(addr, port, TFTP_ERROR_FILE_NOT_FOUND, "Unable to open requested file.");
|
||||
break;
|
||||
}
|
||||
|
||||
LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE, ("tftp: %s request from ", (opcode == PP_HTONS(TFTP_WRQ)) ? "write" : "read"));
|
||||
ip_addr_debug_print(TFTP_DEBUG | LWIP_DBG_STATE, addr);
|
||||
LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE, (" for '%s' mode '%s'\n", filename, mode));
|
||||
|
||||
ip_addr_copy(tftp_state.addr, *addr);
|
||||
tftp_state.port = port;
|
||||
|
||||
if (opcode == PP_HTONS(TFTP_WRQ)) {
|
||||
tftp_state.mode_write = 1;
|
||||
send_ack(0);
|
||||
} else {
|
||||
tftp_state.mode_write = 0;
|
||||
send_data();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
opcode = sbuf[0];
|
||||
case PP_HTONS(TFTP_DATA): {
|
||||
int ret;
|
||||
u16_t blknum;
|
||||
|
||||
tftp_state.last_pkt = tftp_state.timer;
|
||||
tftp_state.retries = 0;
|
||||
if (tftp_state.handle == NULL) {
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "No connection");
|
||||
break;
|
||||
}
|
||||
|
||||
switch (opcode) {
|
||||
case PP_HTONS(TFTP_RRQ): /* fall through */
|
||||
case PP_HTONS(TFTP_WRQ): {
|
||||
const char tftp_null = 0;
|
||||
char filename[TFTP_MAX_FILENAME_LEN + 1];
|
||||
char mode[TFTP_MAX_MODE_LEN + 1];
|
||||
u16_t filename_end_offset;
|
||||
u16_t mode_end_offset;
|
||||
if (tftp_state.mode_write != 1) {
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Not a write connection");
|
||||
break;
|
||||
}
|
||||
|
||||
if (tftp_state.handle != NULL) {
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Only one connection at a time is supported");
|
||||
break;
|
||||
}
|
||||
blknum = lwip_ntohs(sbuf[1]);
|
||||
if (blknum == tftp_state.blknum) {
|
||||
pbuf_remove_header(p, TFTP_HEADER_LENGTH);
|
||||
|
||||
sys_timeout(TFTP_TIMER_MSECS, tftp_tmr, NULL);
|
||||
|
||||
/* find \0 in pbuf -> end of filename string */
|
||||
filename_end_offset = pbuf_memfind(p, &tftp_null, sizeof(tftp_null), 2);
|
||||
|
||||
if ((u16_t)(filename_end_offset - 1) > sizeof(filename)) {
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Filename too long/not NULL terminated");
|
||||
break;
|
||||
}
|
||||
|
||||
pbuf_copy_partial(p, filename, filename_end_offset - 1, 2);
|
||||
|
||||
/* find \0 in pbuf -> end of mode string */
|
||||
mode_end_offset = pbuf_memfind(p, &tftp_null, sizeof(tftp_null), filename_end_offset + 1);
|
||||
|
||||
if ((u16_t)(mode_end_offset - filename_end_offset) > sizeof(mode)) {
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Mode too long/not NULL terminated");
|
||||
break;
|
||||
}
|
||||
|
||||
pbuf_copy_partial(p, mode, mode_end_offset - filename_end_offset, filename_end_offset + 1);
|
||||
|
||||
tftp_state.handle = tftp_state.ctx->open(filename, mode, opcode == PP_HTONS(TFTP_WRQ));
|
||||
tftp_state.blknum = 1;
|
||||
|
||||
if (!tftp_state.handle) {
|
||||
send_error(addr, port, TFTP_ERROR_FILE_NOT_FOUND, "Unable to open requested file.");
|
||||
break;
|
||||
}
|
||||
|
||||
LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE, ("tftp: %s request from ", (opcode == PP_HTONS(TFTP_WRQ)) ? "write" : "read"));
|
||||
ip_addr_debug_print(TFTP_DEBUG | LWIP_DBG_STATE, addr);
|
||||
LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE, (" for '%s' mode '%s'\n", filename, mode));
|
||||
|
||||
ip_addr_copy(tftp_state.addr, *addr);
|
||||
tftp_state.port = port;
|
||||
|
||||
if (opcode == PP_HTONS(TFTP_WRQ)) {
|
||||
tftp_state.mode_write = 1;
|
||||
send_ack(0);
|
||||
} else {
|
||||
tftp_state.mode_write = 0;
|
||||
send_data();
|
||||
}
|
||||
|
||||
break;
|
||||
ret = tftp_state.ctx->write(tftp_state.handle, p);
|
||||
if (ret < 0) {
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "error writing file");
|
||||
close_handle();
|
||||
} else {
|
||||
send_ack(blknum);
|
||||
}
|
||||
|
||||
case PP_HTONS(TFTP_DATA): {
|
||||
int ret;
|
||||
u16_t blknum;
|
||||
|
||||
if (tftp_state.handle == NULL) {
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "No connection");
|
||||
break;
|
||||
}
|
||||
|
||||
if (tftp_state.mode_write != 1) {
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Not a write connection");
|
||||
break;
|
||||
}
|
||||
|
||||
blknum = lwip_ntohs(sbuf[1]);
|
||||
|
||||
if (blknum == tftp_state.blknum) {
|
||||
pbuf_remove_header(p, TFTP_HEADER_LENGTH);
|
||||
|
||||
ret = tftp_state.ctx->write(tftp_state.handle, p);
|
||||
|
||||
if (ret < 0) {
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "error writing file");
|
||||
close_handle();
|
||||
} else {
|
||||
send_ack(blknum);
|
||||
}
|
||||
|
||||
if (p->tot_len < TFTP_MAX_PAYLOAD_SIZE) {
|
||||
close_handle();
|
||||
} else {
|
||||
tftp_state.blknum++;
|
||||
}
|
||||
} else if ((u16_t)(blknum + 1) == tftp_state.blknum) {
|
||||
/* retransmit of previous block, ack again (casting to u16_t to care for overflow) */
|
||||
send_ack(blknum);
|
||||
} else {
|
||||
send_error(addr, port, TFTP_ERROR_UNKNOWN_TRFR_ID, "Wrong block number");
|
||||
}
|
||||
|
||||
break;
|
||||
if (p->tot_len < TFTP_MAX_PAYLOAD_SIZE) {
|
||||
close_handle();
|
||||
} else {
|
||||
tftp_state.blknum++;
|
||||
}
|
||||
|
||||
case PP_HTONS(TFTP_ACK): {
|
||||
u16_t blknum;
|
||||
int lastpkt;
|
||||
|
||||
if (tftp_state.handle == NULL) {
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "No connection");
|
||||
break;
|
||||
}
|
||||
|
||||
if (tftp_state.mode_write != 0) {
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Not a read connection");
|
||||
break;
|
||||
}
|
||||
|
||||
blknum = lwip_ntohs(sbuf[1]);
|
||||
|
||||
if (blknum != tftp_state.blknum) {
|
||||
send_error(addr, port, TFTP_ERROR_UNKNOWN_TRFR_ID, "Wrong block number");
|
||||
break;
|
||||
}
|
||||
|
||||
lastpkt = 0;
|
||||
|
||||
if (tftp_state.last_data != NULL) {
|
||||
lastpkt = tftp_state.last_data->tot_len != (TFTP_MAX_PAYLOAD_SIZE + TFTP_HEADER_LENGTH);
|
||||
}
|
||||
|
||||
if (!lastpkt) {
|
||||
tftp_state.blknum++;
|
||||
send_data();
|
||||
} else {
|
||||
close_handle();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
send_error(addr, port, TFTP_ERROR_ILLEGAL_OPERATION, "Unknown operation");
|
||||
break;
|
||||
} else if ((u16_t)(blknum + 1) == tftp_state.blknum) {
|
||||
/* retransmit of previous block, ack again (casting to u16_t to care for overflow) */
|
||||
send_ack(blknum);
|
||||
} else {
|
||||
send_error(addr, port, TFTP_ERROR_UNKNOWN_TRFR_ID, "Wrong block number");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
pbuf_free(p);
|
||||
case PP_HTONS(TFTP_ACK): {
|
||||
u16_t blknum;
|
||||
int lastpkt;
|
||||
|
||||
if (tftp_state.handle == NULL) {
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "No connection");
|
||||
break;
|
||||
}
|
||||
|
||||
if (tftp_state.mode_write != 0) {
|
||||
send_error(addr, port, TFTP_ERROR_ACCESS_VIOLATION, "Not a read connection");
|
||||
break;
|
||||
}
|
||||
|
||||
blknum = lwip_ntohs(sbuf[1]);
|
||||
if (blknum != tftp_state.blknum) {
|
||||
send_error(addr, port, TFTP_ERROR_UNKNOWN_TRFR_ID, "Wrong block number");
|
||||
break;
|
||||
}
|
||||
|
||||
lastpkt = 0;
|
||||
|
||||
if (tftp_state.last_data != NULL) {
|
||||
lastpkt = tftp_state.last_data->tot_len != (TFTP_MAX_PAYLOAD_SIZE + TFTP_HEADER_LENGTH);
|
||||
}
|
||||
|
||||
if (!lastpkt) {
|
||||
tftp_state.blknum++;
|
||||
send_data();
|
||||
} else {
|
||||
close_handle();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
send_error(addr, port, TFTP_ERROR_ILLEGAL_OPERATION, "Unknown operation");
|
||||
break;
|
||||
}
|
||||
|
||||
pbuf_free(p);
|
||||
}
|
||||
|
||||
static void tftp_tmr(void *arg)
|
||||
static void
|
||||
tftp_tmr(void *arg)
|
||||
{
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
|
||||
tftp_state.timer++;
|
||||
tftp_state.timer++;
|
||||
|
||||
if (tftp_state.handle == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
sys_timeout(TFTP_TIMER_MSECS, tftp_tmr, NULL);
|
||||
|
||||
if ((tftp_state.timer - tftp_state.last_pkt) > (TFTP_TIMEOUT_MSECS / TFTP_TIMER_MSECS)) {
|
||||
if ((tftp_state.last_data != NULL) && (tftp_state.retries < TFTP_MAX_RETRIES)) {
|
||||
LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE, ("tftp: timeout, retrying\n"));
|
||||
resend_data();
|
||||
tftp_state.retries++;
|
||||
} else {
|
||||
LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE, ("tftp: timeout\n"));
|
||||
close_handle();
|
||||
}
|
||||
if (tftp_state.handle == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
sys_timeout(TFTP_TIMER_MSECS, tftp_tmr, NULL);
|
||||
|
||||
if ((tftp_state.timer - tftp_state.last_pkt) > (TFTP_TIMEOUT_MSECS / TFTP_TIMER_MSECS)) {
|
||||
if ((tftp_state.last_data != NULL) && (tftp_state.retries < TFTP_MAX_RETRIES)) {
|
||||
LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE, ("tftp: timeout, retrying\n"));
|
||||
resend_data();
|
||||
tftp_state.retries++;
|
||||
} else {
|
||||
LWIP_DEBUGF(TFTP_DEBUG | LWIP_DBG_STATE, ("tftp: timeout\n"));
|
||||
close_handle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @ingroup tftp
|
||||
* Initialize TFTP server.
|
||||
* @param ctx TFTP callback struct
|
||||
*/
|
||||
err_t tftp_init(const struct tftp_context *ctx)
|
||||
err_t
|
||||
tftp_init(const struct tftp_context *ctx)
|
||||
{
|
||||
err_t ret;
|
||||
err_t ret;
|
||||
|
||||
/* LWIP_ASSERT_CORE_LOCKED(); is checked by udp_new() */
|
||||
struct udp_pcb *pcb = udp_new_ip_type(IPADDR_TYPE_ANY);
|
||||
/* LWIP_ASSERT_CORE_LOCKED(); is checked by udp_new() */
|
||||
struct udp_pcb *pcb = udp_new_ip_type(IPADDR_TYPE_ANY);
|
||||
if (pcb == NULL) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
if (pcb == NULL) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
ret = udp_bind(pcb, IP_ANY_TYPE, TFTP_PORT);
|
||||
if (ret != ERR_OK) {
|
||||
udp_remove(pcb);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = udp_bind(pcb, IP_ANY_TYPE, TFTP_PORT);
|
||||
tftp_state.handle = NULL;
|
||||
tftp_state.port = 0;
|
||||
tftp_state.ctx = ctx;
|
||||
tftp_state.timer = 0;
|
||||
tftp_state.last_data = NULL;
|
||||
tftp_state.upcb = pcb;
|
||||
|
||||
if (ret != ERR_OK) {
|
||||
udp_remove(pcb);
|
||||
return ret;
|
||||
}
|
||||
udp_recv(pcb, recv, NULL);
|
||||
|
||||
tftp_state.handle = NULL;
|
||||
tftp_state.port = 0;
|
||||
tftp_state.ctx = ctx;
|
||||
tftp_state.timer = 0;
|
||||
tftp_state.last_data = NULL;
|
||||
tftp_state.upcb = pcb;
|
||||
|
||||
udp_recv(pcb, recv, NULL);
|
||||
|
||||
return ERR_OK;
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/** @ingroup tftp
|
||||
@ -434,10 +426,10 @@ err_t tftp_init(const struct tftp_context *ctx)
|
||||
*/
|
||||
void tftp_cleanup(void)
|
||||
{
|
||||
LWIP_ASSERT("Cleanup called on non-initialized TFTP", tftp_state.upcb != NULL);
|
||||
udp_remove(tftp_state.upcb);
|
||||
close_handle();
|
||||
memset(&tftp_state, 0, sizeof(tftp_state));
|
||||
LWIP_ASSERT("Cleanup called on non-initialized TFTP", tftp_state.upcb != NULL);
|
||||
udp_remove(tftp_state.upcb);
|
||||
close_handle();
|
||||
memset(&tftp_state, 0, sizeof(tftp_state));
|
||||
}
|
||||
|
||||
#endif /* LWIP_UDP */
|
||||
|
@ -135,47 +135,45 @@ extern const struct altcp_functions altcp_tcp_functions;
|
||||
struct altcp_pcb *
|
||||
altcp_alloc(void)
|
||||
{
|
||||
struct altcp_pcb *ret = (struct altcp_pcb *)memp_malloc(MEMP_ALTCP_PCB);
|
||||
|
||||
if (ret != NULL) {
|
||||
memset(ret, 0, sizeof(struct altcp_pcb));
|
||||
}
|
||||
|
||||
return ret;
|
||||
struct altcp_pcb *ret = (struct altcp_pcb *)memp_malloc(MEMP_ALTCP_PCB);
|
||||
if (ret != NULL) {
|
||||
memset(ret, 0, sizeof(struct altcp_pcb));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* For altcp layer implementations only: return a struct altcp_pcb to the pool
|
||||
*/
|
||||
void altcp_free(struct altcp_pcb *conn)
|
||||
void
|
||||
altcp_free(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn) {
|
||||
if (conn->fns && conn->fns->dealloc) {
|
||||
conn->fns->dealloc(conn);
|
||||
}
|
||||
|
||||
memp_free(MEMP_ALTCP_PCB, conn);
|
||||
if (conn) {
|
||||
if (conn->fns && conn->fns->dealloc) {
|
||||
conn->fns->dealloc(conn);
|
||||
}
|
||||
memp_free(MEMP_ALTCP_PCB, conn);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup altcp
|
||||
* altcp_new_ip6: @ref altcp_new for IPv6
|
||||
* altcp_new_ip6: @ref altcp_new for IPv6
|
||||
*/
|
||||
struct altcp_pcb *
|
||||
altcp_new_ip6(altcp_allocator_t *allocator)
|
||||
{
|
||||
return altcp_new_ip_type(allocator, IPADDR_TYPE_V6);
|
||||
return altcp_new_ip_type(allocator, IPADDR_TYPE_V6);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @ingroup altcp
|
||||
* altcp_new: @ref altcp_new for IPv4
|
||||
* altcp_new: @ref altcp_new for IPv4
|
||||
*/
|
||||
struct altcp_pcb *
|
||||
altcp_new(altcp_allocator_t *allocator)
|
||||
{
|
||||
return altcp_new_ip_type(allocator, IPADDR_TYPE_V4);
|
||||
return altcp_new_ip_type(allocator, IPADDR_TYPE_V4);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -190,97 +188,97 @@ altcp_new(altcp_allocator_t *allocator)
|
||||
struct altcp_pcb *
|
||||
altcp_new_ip_type(altcp_allocator_t *allocator, u8_t ip_type)
|
||||
{
|
||||
struct altcp_pcb *conn;
|
||||
|
||||
if (allocator == NULL) {
|
||||
/* no allocator given, create a simple TCP connection */
|
||||
return altcp_tcp_new_ip_type(ip_type);
|
||||
}
|
||||
|
||||
if (allocator->alloc == NULL) {
|
||||
/* illegal allocator */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
conn = allocator->alloc(allocator->arg, ip_type);
|
||||
|
||||
if (conn == NULL) {
|
||||
/* allocation failed */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return conn;
|
||||
struct altcp_pcb *conn;
|
||||
if (allocator == NULL) {
|
||||
/* no allocator given, create a simple TCP connection */
|
||||
return altcp_tcp_new_ip_type(ip_type);
|
||||
}
|
||||
if (allocator->alloc == NULL) {
|
||||
/* illegal allocator */
|
||||
return NULL;
|
||||
}
|
||||
conn = allocator->alloc(allocator->arg, ip_type);
|
||||
if (conn == NULL) {
|
||||
/* allocation failed */
|
||||
return NULL;
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup altcp
|
||||
* @see tcp_arg()
|
||||
*/
|
||||
void altcp_arg(struct altcp_pcb *conn, void *arg)
|
||||
void
|
||||
altcp_arg(struct altcp_pcb *conn, void *arg)
|
||||
{
|
||||
if (conn) {
|
||||
conn->arg = arg;
|
||||
}
|
||||
if (conn) {
|
||||
conn->arg = arg;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup altcp
|
||||
* @see tcp_accept()
|
||||
*/
|
||||
void altcp_accept(struct altcp_pcb *conn, altcp_accept_fn accept)
|
||||
void
|
||||
altcp_accept(struct altcp_pcb *conn, altcp_accept_fn accept)
|
||||
{
|
||||
if (conn != NULL) {
|
||||
conn->accept = accept;
|
||||
}
|
||||
if (conn != NULL) {
|
||||
conn->accept = accept;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup altcp
|
||||
* @see tcp_recv()
|
||||
*/
|
||||
void altcp_recv(struct altcp_pcb *conn, altcp_recv_fn recv)
|
||||
void
|
||||
altcp_recv(struct altcp_pcb *conn, altcp_recv_fn recv)
|
||||
{
|
||||
if (conn) {
|
||||
conn->recv = recv;
|
||||
}
|
||||
if (conn) {
|
||||
conn->recv = recv;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup altcp
|
||||
* @see tcp_sent()
|
||||
*/
|
||||
void altcp_sent(struct altcp_pcb *conn, altcp_sent_fn sent)
|
||||
void
|
||||
altcp_sent(struct altcp_pcb *conn, altcp_sent_fn sent)
|
||||
{
|
||||
if (conn) {
|
||||
conn->sent = sent;
|
||||
}
|
||||
if (conn) {
|
||||
conn->sent = sent;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup altcp
|
||||
* @see tcp_poll()
|
||||
*/
|
||||
void altcp_poll(struct altcp_pcb *conn, altcp_poll_fn poll, u8_t interval)
|
||||
void
|
||||
altcp_poll(struct altcp_pcb *conn, altcp_poll_fn poll, u8_t interval)
|
||||
{
|
||||
if (conn) {
|
||||
conn->poll = poll;
|
||||
conn->pollinterval = interval;
|
||||
|
||||
if (conn->fns && conn->fns->set_poll) {
|
||||
conn->fns->set_poll(conn, interval);
|
||||
}
|
||||
if (conn) {
|
||||
conn->poll = poll;
|
||||
conn->pollinterval = interval;
|
||||
if (conn->fns && conn->fns->set_poll) {
|
||||
conn->fns->set_poll(conn, interval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup altcp
|
||||
* @see tcp_err()
|
||||
*/
|
||||
void altcp_err(struct altcp_pcb *conn, altcp_err_fn err)
|
||||
void
|
||||
altcp_err(struct altcp_pcb *conn, altcp_err_fn err)
|
||||
{
|
||||
if (conn) {
|
||||
conn->err = err;
|
||||
}
|
||||
if (conn) {
|
||||
conn->err = err;
|
||||
}
|
||||
}
|
||||
|
||||
/* Generic functions calling the "virtual" ones */
|
||||
@ -289,37 +287,38 @@ void altcp_err(struct altcp_pcb *conn, altcp_err_fn err)
|
||||
* @ingroup altcp
|
||||
* @see tcp_recved()
|
||||
*/
|
||||
void altcp_recved(struct altcp_pcb *conn, u16_t len)
|
||||
void
|
||||
altcp_recved(struct altcp_pcb *conn, u16_t len)
|
||||
{
|
||||
if (conn && conn->fns && conn->fns->recved) {
|
||||
conn->fns->recved(conn, len);
|
||||
}
|
||||
if (conn && conn->fns && conn->fns->recved) {
|
||||
conn->fns->recved(conn, len);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup altcp
|
||||
* @see tcp_bind()
|
||||
*/
|
||||
err_t altcp_bind(struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port)
|
||||
err_t
|
||||
altcp_bind(struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port)
|
||||
{
|
||||
if (conn && conn->fns && conn->fns->bind) {
|
||||
return conn->fns->bind(conn, ipaddr, port);
|
||||
}
|
||||
|
||||
return ERR_VAL;
|
||||
if (conn && conn->fns && conn->fns->bind) {
|
||||
return conn->fns->bind(conn, ipaddr, port);
|
||||
}
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup altcp
|
||||
* @see tcp_connect()
|
||||
*/
|
||||
err_t altcp_connect(struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port, altcp_connected_fn connected)
|
||||
err_t
|
||||
altcp_connect(struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port, altcp_connected_fn connected)
|
||||
{
|
||||
if (conn && conn->fns && conn->fns->connect) {
|
||||
return conn->fns->connect(conn, ipaddr, port, connected);
|
||||
}
|
||||
|
||||
return ERR_VAL;
|
||||
if (conn && conn->fns && conn->fns->connect) {
|
||||
return conn->fns->connect(conn, ipaddr, port, connected);
|
||||
}
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -329,345 +328,354 @@ err_t altcp_connect(struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port,
|
||||
struct altcp_pcb *
|
||||
altcp_listen_with_backlog_and_err(struct altcp_pcb *conn, u8_t backlog, err_t *err)
|
||||
{
|
||||
if (conn && conn->fns && conn->fns->listen) {
|
||||
return conn->fns->listen(conn, backlog, err);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
if (conn && conn->fns && conn->fns->listen) {
|
||||
return conn->fns->listen(conn, backlog, err);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup altcp
|
||||
* @see tcp_abort()
|
||||
*/
|
||||
void altcp_abort(struct altcp_pcb *conn)
|
||||
void
|
||||
altcp_abort(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn && conn->fns && conn->fns->abort) {
|
||||
conn->fns->abort(conn);
|
||||
}
|
||||
if (conn && conn->fns && conn->fns->abort) {
|
||||
conn->fns->abort(conn);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup altcp
|
||||
* @see tcp_close()
|
||||
*/
|
||||
err_t altcp_close(struct altcp_pcb *conn)
|
||||
err_t
|
||||
altcp_close(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn && conn->fns && conn->fns->close) {
|
||||
return conn->fns->close(conn);
|
||||
}
|
||||
|
||||
return ERR_VAL;
|
||||
if (conn && conn->fns && conn->fns->close) {
|
||||
return conn->fns->close(conn);
|
||||
}
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup altcp
|
||||
* @see tcp_shutdown()
|
||||
*/
|
||||
err_t altcp_shutdown(struct altcp_pcb *conn, int shut_rx, int shut_tx)
|
||||
err_t
|
||||
altcp_shutdown(struct altcp_pcb *conn, int shut_rx, int shut_tx)
|
||||
{
|
||||
if (conn && conn->fns && conn->fns->shutdown) {
|
||||
return conn->fns->shutdown(conn, shut_rx, shut_tx);
|
||||
}
|
||||
|
||||
return ERR_VAL;
|
||||
if (conn && conn->fns && conn->fns->shutdown) {
|
||||
return conn->fns->shutdown(conn, shut_rx, shut_tx);
|
||||
}
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup altcp
|
||||
* @see tcp_write()
|
||||
*/
|
||||
err_t altcp_write(struct altcp_pcb *conn, const void *dataptr, u16_t len, u8_t apiflags)
|
||||
err_t
|
||||
altcp_write(struct altcp_pcb *conn, const void *dataptr, u16_t len, u8_t apiflags)
|
||||
{
|
||||
if (conn && conn->fns && conn->fns->write) {
|
||||
return conn->fns->write(conn, dataptr, len, apiflags);
|
||||
}
|
||||
|
||||
return ERR_VAL;
|
||||
if (conn && conn->fns && conn->fns->write) {
|
||||
return conn->fns->write(conn, dataptr, len, apiflags);
|
||||
}
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup altcp
|
||||
* @see tcp_output()
|
||||
*/
|
||||
err_t altcp_output(struct altcp_pcb *conn)
|
||||
err_t
|
||||
altcp_output(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn && conn->fns && conn->fns->output) {
|
||||
return conn->fns->output(conn);
|
||||
}
|
||||
|
||||
return ERR_VAL;
|
||||
if (conn && conn->fns && conn->fns->output) {
|
||||
return conn->fns->output(conn);
|
||||
}
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup altcp
|
||||
* @see tcp_mss()
|
||||
*/
|
||||
u16_t altcp_mss(struct altcp_pcb *conn)
|
||||
u16_t
|
||||
altcp_mss(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn && conn->fns && conn->fns->mss) {
|
||||
return conn->fns->mss(conn);
|
||||
}
|
||||
|
||||
return 0;
|
||||
if (conn && conn->fns && conn->fns->mss) {
|
||||
return conn->fns->mss(conn);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup altcp
|
||||
* @see tcp_sndbuf()
|
||||
*/
|
||||
u16_t altcp_sndbuf(struct altcp_pcb *conn)
|
||||
u16_t
|
||||
altcp_sndbuf(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn && conn->fns && conn->fns->sndbuf) {
|
||||
return conn->fns->sndbuf(conn);
|
||||
}
|
||||
|
||||
return 0;
|
||||
if (conn && conn->fns && conn->fns->sndbuf) {
|
||||
return conn->fns->sndbuf(conn);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup altcp
|
||||
* @see tcp_sndqueuelen()
|
||||
*/
|
||||
u16_t altcp_sndqueuelen(struct altcp_pcb *conn)
|
||||
u16_t
|
||||
altcp_sndqueuelen(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn && conn->fns && conn->fns->sndqueuelen) {
|
||||
return conn->fns->sndqueuelen(conn);
|
||||
}
|
||||
|
||||
return 0;
|
||||
if (conn && conn->fns && conn->fns->sndqueuelen) {
|
||||
return conn->fns->sndqueuelen(conn);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void altcp_nagle_disable(struct altcp_pcb *conn)
|
||||
void
|
||||
altcp_nagle_disable(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn && conn->fns && conn->fns->nagle_disable) {
|
||||
conn->fns->nagle_disable(conn);
|
||||
}
|
||||
if (conn && conn->fns && conn->fns->nagle_disable) {
|
||||
conn->fns->nagle_disable(conn);
|
||||
}
|
||||
}
|
||||
|
||||
void altcp_nagle_enable(struct altcp_pcb *conn)
|
||||
void
|
||||
altcp_nagle_enable(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn && conn->fns && conn->fns->nagle_enable) {
|
||||
conn->fns->nagle_enable(conn);
|
||||
}
|
||||
if (conn && conn->fns && conn->fns->nagle_enable) {
|
||||
conn->fns->nagle_enable(conn);
|
||||
}
|
||||
}
|
||||
|
||||
int altcp_nagle_disabled(struct altcp_pcb *conn)
|
||||
int
|
||||
altcp_nagle_disabled(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn && conn->fns && conn->fns->nagle_disabled) {
|
||||
return conn->fns->nagle_disabled(conn);
|
||||
}
|
||||
|
||||
return 0;
|
||||
if (conn && conn->fns && conn->fns->nagle_disabled) {
|
||||
return conn->fns->nagle_disabled(conn);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup altcp
|
||||
* @see tcp_setprio()
|
||||
*/
|
||||
void altcp_setprio(struct altcp_pcb *conn, u8_t prio)
|
||||
void
|
||||
altcp_setprio(struct altcp_pcb *conn, u8_t prio)
|
||||
{
|
||||
if (conn && conn->fns && conn->fns->setprio) {
|
||||
conn->fns->setprio(conn, prio);
|
||||
}
|
||||
if (conn && conn->fns && conn->fns->setprio) {
|
||||
conn->fns->setprio(conn, prio);
|
||||
}
|
||||
}
|
||||
|
||||
err_t altcp_get_tcp_addrinfo(struct altcp_pcb *conn, int local, ip_addr_t *addr, u16_t *port)
|
||||
err_t
|
||||
altcp_get_tcp_addrinfo(struct altcp_pcb *conn, int local, ip_addr_t *addr, u16_t *port)
|
||||
{
|
||||
if (conn && conn->fns && conn->fns->addrinfo) {
|
||||
return conn->fns->addrinfo(conn, local, addr, port);
|
||||
}
|
||||
|
||||
return ERR_VAL;
|
||||
if (conn && conn->fns && conn->fns->addrinfo) {
|
||||
return conn->fns->addrinfo(conn, local, addr, port);
|
||||
}
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
ip_addr_t *altcp_get_ip(struct altcp_pcb *conn, int local)
|
||||
ip_addr_t *
|
||||
altcp_get_ip(struct altcp_pcb *conn, int local)
|
||||
{
|
||||
if (conn && conn->fns && conn->fns->getip) {
|
||||
return conn->fns->getip(conn, local);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
if (conn && conn->fns && conn->fns->getip) {
|
||||
return conn->fns->getip(conn, local);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
u16_t altcp_get_port(struct altcp_pcb *conn, int local)
|
||||
u16_t
|
||||
altcp_get_port(struct altcp_pcb *conn, int local)
|
||||
{
|
||||
if (conn && conn->fns && conn->fns->getport) {
|
||||
return conn->fns->getport(conn, local);
|
||||
}
|
||||
|
||||
return 0;
|
||||
if (conn && conn->fns && conn->fns->getport) {
|
||||
return conn->fns->getport(conn, local);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
enum tcp_state altcp_dbg_get_tcp_state(struct altcp_pcb *conn)
|
||||
enum tcp_state
|
||||
altcp_dbg_get_tcp_state(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn && conn->fns && conn->fns->dbg_get_tcp_state) {
|
||||
return conn->fns->dbg_get_tcp_state(conn);
|
||||
}
|
||||
|
||||
return CLOSED;
|
||||
if (conn && conn->fns && conn->fns->dbg_get_tcp_state) {
|
||||
return conn->fns->dbg_get_tcp_state(conn);
|
||||
}
|
||||
return CLOSED;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Default implementations for the "virtual" functions */
|
||||
|
||||
void altcp_default_set_poll(struct altcp_pcb *conn, u8_t interval)
|
||||
void
|
||||
altcp_default_set_poll(struct altcp_pcb *conn, u8_t interval)
|
||||
{
|
||||
if (conn && conn->inner_conn) {
|
||||
altcp_poll(conn->inner_conn, conn->poll, interval);
|
||||
}
|
||||
if (conn && conn->inner_conn) {
|
||||
altcp_poll(conn->inner_conn, conn->poll, interval);
|
||||
}
|
||||
}
|
||||
|
||||
void altcp_default_recved(struct altcp_pcb *conn, u16_t len)
|
||||
void
|
||||
altcp_default_recved(struct altcp_pcb *conn, u16_t len)
|
||||
{
|
||||
if (conn && conn->inner_conn) {
|
||||
altcp_recved(conn->inner_conn, len);
|
||||
}
|
||||
if (conn && conn->inner_conn) {
|
||||
altcp_recved(conn->inner_conn, len);
|
||||
}
|
||||
}
|
||||
|
||||
err_t altcp_default_bind(struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port)
|
||||
err_t
|
||||
altcp_default_bind(struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port)
|
||||
{
|
||||
if (conn && conn->inner_conn) {
|
||||
return altcp_bind(conn->inner_conn, ipaddr, port);
|
||||
}
|
||||
|
||||
return ERR_VAL;
|
||||
if (conn && conn->inner_conn) {
|
||||
return altcp_bind(conn->inner_conn, ipaddr, port);
|
||||
}
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
err_t altcp_default_shutdown(struct altcp_pcb *conn, int shut_rx, int shut_tx)
|
||||
err_t
|
||||
altcp_default_shutdown(struct altcp_pcb *conn, int shut_rx, int shut_tx)
|
||||
{
|
||||
if (conn) {
|
||||
if (shut_rx && shut_tx && conn->fns && conn->fns->close) {
|
||||
/* default shutdown for both sides is close */
|
||||
return conn->fns->close(conn);
|
||||
}
|
||||
|
||||
if (conn->inner_conn) {
|
||||
return altcp_shutdown(conn->inner_conn, shut_rx, shut_tx);
|
||||
}
|
||||
if (conn) {
|
||||
if (shut_rx && shut_tx && conn->fns && conn->fns->close) {
|
||||
/* default shutdown for both sides is close */
|
||||
return conn->fns->close(conn);
|
||||
}
|
||||
|
||||
return ERR_VAL;
|
||||
if (conn->inner_conn) {
|
||||
return altcp_shutdown(conn->inner_conn, shut_rx, shut_tx);
|
||||
}
|
||||
}
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
err_t altcp_default_write(struct altcp_pcb *conn, const void *dataptr, u16_t len, u8_t apiflags)
|
||||
err_t
|
||||
altcp_default_write(struct altcp_pcb *conn, const void *dataptr, u16_t len, u8_t apiflags)
|
||||
{
|
||||
if (conn && conn->inner_conn) {
|
||||
return altcp_write(conn->inner_conn, dataptr, len, apiflags);
|
||||
}
|
||||
|
||||
return ERR_VAL;
|
||||
if (conn && conn->inner_conn) {
|
||||
return altcp_write(conn->inner_conn, dataptr, len, apiflags);
|
||||
}
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
err_t altcp_default_output(struct altcp_pcb *conn)
|
||||
err_t
|
||||
altcp_default_output(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn && conn->inner_conn) {
|
||||
return altcp_output(conn->inner_conn);
|
||||
}
|
||||
|
||||
return ERR_VAL;
|
||||
if (conn && conn->inner_conn) {
|
||||
return altcp_output(conn->inner_conn);
|
||||
}
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
u16_t altcp_default_mss(struct altcp_pcb *conn)
|
||||
u16_t
|
||||
altcp_default_mss(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn && conn->inner_conn) {
|
||||
return altcp_mss(conn->inner_conn);
|
||||
}
|
||||
|
||||
return 0;
|
||||
if (conn && conn->inner_conn) {
|
||||
return altcp_mss(conn->inner_conn);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
u16_t altcp_default_sndbuf(struct altcp_pcb *conn)
|
||||
u16_t
|
||||
altcp_default_sndbuf(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn && conn->inner_conn) {
|
||||
return altcp_sndbuf(conn->inner_conn);
|
||||
}
|
||||
|
||||
return 0;
|
||||
if (conn && conn->inner_conn) {
|
||||
return altcp_sndbuf(conn->inner_conn);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
u16_t altcp_default_sndqueuelen(struct altcp_pcb *conn)
|
||||
u16_t
|
||||
altcp_default_sndqueuelen(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn && conn->inner_conn) {
|
||||
return altcp_sndqueuelen(conn->inner_conn);
|
||||
}
|
||||
|
||||
return 0;
|
||||
if (conn && conn->inner_conn) {
|
||||
return altcp_sndqueuelen(conn->inner_conn);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void altcp_default_nagle_disable(struct altcp_pcb *conn)
|
||||
void
|
||||
altcp_default_nagle_disable(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn && conn->inner_conn) {
|
||||
altcp_nagle_disable(conn->inner_conn);
|
||||
}
|
||||
if (conn && conn->inner_conn) {
|
||||
altcp_nagle_disable(conn->inner_conn);
|
||||
}
|
||||
}
|
||||
|
||||
void altcp_default_nagle_enable(struct altcp_pcb *conn)
|
||||
void
|
||||
altcp_default_nagle_enable(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn && conn->inner_conn) {
|
||||
altcp_nagle_enable(conn->inner_conn);
|
||||
}
|
||||
if (conn && conn->inner_conn) {
|
||||
altcp_nagle_enable(conn->inner_conn);
|
||||
}
|
||||
}
|
||||
|
||||
int altcp_default_nagle_disabled(struct altcp_pcb *conn)
|
||||
int
|
||||
altcp_default_nagle_disabled(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn && conn->inner_conn) {
|
||||
return altcp_nagle_disabled(conn->inner_conn);
|
||||
}
|
||||
|
||||
return 0;
|
||||
if (conn && conn->inner_conn) {
|
||||
return altcp_nagle_disabled(conn->inner_conn);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void altcp_default_setprio(struct altcp_pcb *conn, u8_t prio)
|
||||
void
|
||||
altcp_default_setprio(struct altcp_pcb *conn, u8_t prio)
|
||||
{
|
||||
if (conn && conn->inner_conn) {
|
||||
altcp_setprio(conn->inner_conn, prio);
|
||||
}
|
||||
if (conn && conn->inner_conn) {
|
||||
altcp_setprio(conn->inner_conn, prio);
|
||||
}
|
||||
}
|
||||
|
||||
void altcp_default_dealloc(struct altcp_pcb *conn)
|
||||
void
|
||||
altcp_default_dealloc(struct altcp_pcb *conn)
|
||||
{
|
||||
LWIP_UNUSED_ARG(conn);
|
||||
/* nothing to do */
|
||||
LWIP_UNUSED_ARG(conn);
|
||||
/* nothing to do */
|
||||
}
|
||||
|
||||
err_t altcp_default_get_tcp_addrinfo(struct altcp_pcb *conn, int local, ip_addr_t *addr, u16_t *port)
|
||||
err_t
|
||||
altcp_default_get_tcp_addrinfo(struct altcp_pcb *conn, int local, ip_addr_t *addr, u16_t *port)
|
||||
{
|
||||
if (conn && conn->inner_conn) {
|
||||
return altcp_get_tcp_addrinfo(conn->inner_conn, local, addr, port);
|
||||
}
|
||||
|
||||
return ERR_VAL;
|
||||
if (conn && conn->inner_conn) {
|
||||
return altcp_get_tcp_addrinfo(conn->inner_conn, local, addr, port);
|
||||
}
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
ip_addr_t *altcp_default_get_ip(struct altcp_pcb *conn, int local)
|
||||
ip_addr_t *
|
||||
altcp_default_get_ip(struct altcp_pcb *conn, int local)
|
||||
{
|
||||
if (conn && conn->inner_conn) {
|
||||
return altcp_get_ip(conn->inner_conn, local);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
if (conn && conn->inner_conn) {
|
||||
return altcp_get_ip(conn->inner_conn, local);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
u16_t altcp_default_get_port(struct altcp_pcb *conn, int local)
|
||||
u16_t
|
||||
altcp_default_get_port(struct altcp_pcb *conn, int local)
|
||||
{
|
||||
if (conn && conn->inner_conn) {
|
||||
return altcp_get_port(conn->inner_conn, local);
|
||||
}
|
||||
|
||||
return 0;
|
||||
if (conn && conn->inner_conn) {
|
||||
return altcp_get_port(conn->inner_conn, local);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
enum tcp_state altcp_default_dbg_get_tcp_state(struct altcp_pcb *conn)
|
||||
enum tcp_state
|
||||
altcp_default_dbg_get_tcp_state(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn && conn->inner_conn) {
|
||||
return altcp_dbg_get_tcp_state(conn->inner_conn);
|
||||
}
|
||||
|
||||
return CLOSED;
|
||||
if (conn && conn->inner_conn) {
|
||||
return altcp_dbg_get_tcp_state(conn->inner_conn);
|
||||
}
|
||||
return CLOSED;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* LWIP_ALTCP */
|
||||
|
@ -60,22 +60,18 @@
|
||||
struct altcp_pcb *
|
||||
altcp_tls_new(struct altcp_tls_config *config, u8_t ip_type)
|
||||
{
|
||||
struct altcp_pcb *inner_conn, *ret;
|
||||
LWIP_UNUSED_ARG(ip_type);
|
||||
struct altcp_pcb *inner_conn, *ret;
|
||||
LWIP_UNUSED_ARG(ip_type);
|
||||
|
||||
inner_conn = altcp_tcp_new_ip_type(ip_type);
|
||||
|
||||
if (inner_conn == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = altcp_tls_wrap(config, inner_conn);
|
||||
|
||||
if (ret == NULL) {
|
||||
altcp_close(inner_conn);
|
||||
}
|
||||
|
||||
return ret;
|
||||
inner_conn = altcp_tcp_new_ip_type(ip_type);
|
||||
if (inner_conn == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
ret = altcp_tls_wrap(config, inner_conn);
|
||||
if (ret == NULL) {
|
||||
altcp_close(inner_conn);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** This standard allocator function creates an altcp pcb for
|
||||
@ -83,7 +79,7 @@ altcp_tls_new(struct altcp_tls_config *config, u8_t ip_type)
|
||||
struct altcp_pcb *
|
||||
altcp_tls_alloc(void *arg, u8_t ip_type)
|
||||
{
|
||||
return altcp_tls_new((struct altcp_tls_config *)arg, ip_type);
|
||||
return altcp_tls_new((struct altcp_tls_config *)arg, ip_type);
|
||||
}
|
||||
|
||||
#endif /* LWIP_ALTCP_TLS */
|
||||
|
@ -53,17 +53,14 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define ALTCP_TCP_ASSERT_CONN(conn) \
|
||||
do { \
|
||||
LWIP_ASSERT("conn->inner_conn == NULL", (conn)->inner_conn == NULL); \
|
||||
LWIP_UNUSED_ARG(conn); /* for LWIP_NOASSERT */ \
|
||||
} while (0)
|
||||
#define ALTCP_TCP_ASSERT_CONN_PCB(conn, tpcb) \
|
||||
do { \
|
||||
LWIP_ASSERT("pcb mismatch", (conn)->state == tpcb); \
|
||||
LWIP_UNUSED_ARG(tpcb); /* for LWIP_NOASSERT */ \
|
||||
ALTCP_TCP_ASSERT_CONN(conn); \
|
||||
} while (0)
|
||||
#define ALTCP_TCP_ASSERT_CONN(conn) do { \
|
||||
LWIP_ASSERT("conn->inner_conn == NULL", (conn)->inner_conn == NULL); \
|
||||
LWIP_UNUSED_ARG(conn); /* for LWIP_NOASSERT */ } while(0)
|
||||
#define ALTCP_TCP_ASSERT_CONN_PCB(conn, tpcb) do { \
|
||||
LWIP_ASSERT("pcb mismatch", (conn)->state == tpcb); \
|
||||
LWIP_UNUSED_ARG(tpcb); /* for LWIP_NOASSERT */ \
|
||||
ALTCP_TCP_ASSERT_CONN(conn); } while(0)
|
||||
|
||||
|
||||
/* Variable prototype, the actual declaration is at the end of this file
|
||||
since it contains pointers to static functions declared here */
|
||||
@ -72,153 +69,139 @@ extern const struct altcp_functions altcp_tcp_functions;
|
||||
static void altcp_tcp_setup(struct altcp_pcb *conn, struct tcp_pcb *tpcb);
|
||||
|
||||
/* callback functions for TCP */
|
||||
static err_t altcp_tcp_accept(void *arg, struct tcp_pcb *new_tpcb, err_t err)
|
||||
static err_t
|
||||
altcp_tcp_accept(void *arg, struct tcp_pcb *new_tpcb, err_t err)
|
||||
{
|
||||
struct altcp_pcb *listen_conn = (struct altcp_pcb *)arg;
|
||||
|
||||
if (listen_conn && listen_conn->accept) {
|
||||
/* create a new altcp_conn to pass to the next 'accept' callback */
|
||||
struct altcp_pcb *new_conn = altcp_alloc();
|
||||
|
||||
if (new_conn == NULL) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
altcp_tcp_setup(new_conn, new_tpcb);
|
||||
return listen_conn->accept(listen_conn->arg, new_conn, err);
|
||||
struct altcp_pcb *listen_conn = (struct altcp_pcb *)arg;
|
||||
if (listen_conn && listen_conn->accept) {
|
||||
/* create a new altcp_conn to pass to the next 'accept' callback */
|
||||
struct altcp_pcb *new_conn = altcp_alloc();
|
||||
if (new_conn == NULL) {
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
return ERR_ARG;
|
||||
altcp_tcp_setup(new_conn, new_tpcb);
|
||||
return listen_conn->accept(listen_conn->arg, new_conn, err);
|
||||
}
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
static err_t altcp_tcp_connected(void *arg, struct tcp_pcb *tpcb, err_t err)
|
||||
static err_t
|
||||
altcp_tcp_connected(void *arg, struct tcp_pcb *tpcb, err_t err)
|
||||
{
|
||||
struct altcp_pcb *conn = (struct altcp_pcb *)arg;
|
||||
|
||||
if (conn) {
|
||||
ALTCP_TCP_ASSERT_CONN_PCB(conn, tpcb);
|
||||
|
||||
if (conn->connected) {
|
||||
return conn->connected(conn->arg, conn, err);
|
||||
}
|
||||
struct altcp_pcb *conn = (struct altcp_pcb *)arg;
|
||||
if (conn) {
|
||||
ALTCP_TCP_ASSERT_CONN_PCB(conn, tpcb);
|
||||
if (conn->connected) {
|
||||
return conn->connected(conn->arg, conn, err);
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static err_t altcp_tcp_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
|
||||
static err_t
|
||||
altcp_tcp_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
|
||||
{
|
||||
struct altcp_pcb *conn = (struct altcp_pcb *)arg;
|
||||
|
||||
if (conn) {
|
||||
ALTCP_TCP_ASSERT_CONN_PCB(conn, tpcb);
|
||||
|
||||
if (conn->recv) {
|
||||
return conn->recv(conn->arg, conn, p, err);
|
||||
}
|
||||
struct altcp_pcb *conn = (struct altcp_pcb *)arg;
|
||||
if (conn) {
|
||||
ALTCP_TCP_ASSERT_CONN_PCB(conn, tpcb);
|
||||
if (conn->recv) {
|
||||
return conn->recv(conn->arg, conn, p, err);
|
||||
}
|
||||
|
||||
if (p != NULL) {
|
||||
/* prevent memory leaks */
|
||||
pbuf_free(p);
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
if (p != NULL) {
|
||||
/* prevent memory leaks */
|
||||
pbuf_free(p);
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static err_t altcp_tcp_sent(void *arg, struct tcp_pcb *tpcb, u16_t len)
|
||||
static err_t
|
||||
altcp_tcp_sent(void *arg, struct tcp_pcb *tpcb, u16_t len)
|
||||
{
|
||||
struct altcp_pcb *conn = (struct altcp_pcb *)arg;
|
||||
|
||||
if (conn) {
|
||||
ALTCP_TCP_ASSERT_CONN_PCB(conn, tpcb);
|
||||
|
||||
if (conn->sent) {
|
||||
return conn->sent(conn->arg, conn, len);
|
||||
}
|
||||
struct altcp_pcb *conn = (struct altcp_pcb *)arg;
|
||||
if (conn) {
|
||||
ALTCP_TCP_ASSERT_CONN_PCB(conn, tpcb);
|
||||
if (conn->sent) {
|
||||
return conn->sent(conn->arg, conn, len);
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static err_t altcp_tcp_poll(void *arg, struct tcp_pcb *tpcb)
|
||||
static err_t
|
||||
altcp_tcp_poll(void *arg, struct tcp_pcb *tpcb)
|
||||
{
|
||||
struct altcp_pcb *conn = (struct altcp_pcb *)arg;
|
||||
|
||||
if (conn) {
|
||||
ALTCP_TCP_ASSERT_CONN_PCB(conn, tpcb);
|
||||
|
||||
if (conn->poll) {
|
||||
return conn->poll(conn->arg, conn);
|
||||
}
|
||||
struct altcp_pcb *conn = (struct altcp_pcb *)arg;
|
||||
if (conn) {
|
||||
ALTCP_TCP_ASSERT_CONN_PCB(conn, tpcb);
|
||||
if (conn->poll) {
|
||||
return conn->poll(conn->arg, conn);
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static void altcp_tcp_err(void *arg, err_t err)
|
||||
static void
|
||||
altcp_tcp_err(void *arg, err_t err)
|
||||
{
|
||||
struct altcp_pcb *conn = (struct altcp_pcb *)arg;
|
||||
|
||||
if (conn) {
|
||||
conn->state = NULL; /* already freed */
|
||||
|
||||
if (conn->err) {
|
||||
conn->err(conn->arg, err);
|
||||
}
|
||||
|
||||
altcp_free(conn);
|
||||
struct altcp_pcb *conn = (struct altcp_pcb *)arg;
|
||||
if (conn) {
|
||||
conn->state = NULL; /* already freed */
|
||||
if (conn->err) {
|
||||
conn->err(conn->arg, err);
|
||||
}
|
||||
altcp_free(conn);
|
||||
}
|
||||
}
|
||||
|
||||
/* setup functions */
|
||||
|
||||
static void altcp_tcp_remove_callbacks(struct tcp_pcb *tpcb)
|
||||
static void
|
||||
altcp_tcp_remove_callbacks(struct tcp_pcb *tpcb)
|
||||
{
|
||||
tcp_arg(tpcb, NULL);
|
||||
tcp_recv(tpcb, NULL);
|
||||
tcp_sent(tpcb, NULL);
|
||||
tcp_err(tpcb, NULL);
|
||||
tcp_poll(tpcb, NULL, tpcb->pollinterval);
|
||||
tcp_arg(tpcb, NULL);
|
||||
tcp_recv(tpcb, NULL);
|
||||
tcp_sent(tpcb, NULL);
|
||||
tcp_err(tpcb, NULL);
|
||||
tcp_poll(tpcb, NULL, tpcb->pollinterval);
|
||||
}
|
||||
|
||||
static void altcp_tcp_setup_callbacks(struct altcp_pcb *conn, struct tcp_pcb *tpcb)
|
||||
static void
|
||||
altcp_tcp_setup_callbacks(struct altcp_pcb *conn, struct tcp_pcb *tpcb)
|
||||
{
|
||||
tcp_arg(tpcb, conn);
|
||||
tcp_recv(tpcb, altcp_tcp_recv);
|
||||
tcp_sent(tpcb, altcp_tcp_sent);
|
||||
tcp_err(tpcb, altcp_tcp_err);
|
||||
/* tcp_poll is set when interval is set by application */
|
||||
/* listen is set totally different :-) */
|
||||
tcp_arg(tpcb, conn);
|
||||
tcp_recv(tpcb, altcp_tcp_recv);
|
||||
tcp_sent(tpcb, altcp_tcp_sent);
|
||||
tcp_err(tpcb, altcp_tcp_err);
|
||||
/* tcp_poll is set when interval is set by application */
|
||||
/* listen is set totally different :-) */
|
||||
}
|
||||
|
||||
static void altcp_tcp_setup(struct altcp_pcb *conn, struct tcp_pcb *tpcb)
|
||||
static void
|
||||
altcp_tcp_setup(struct altcp_pcb *conn, struct tcp_pcb *tpcb)
|
||||
{
|
||||
altcp_tcp_setup_callbacks(conn, tpcb);
|
||||
conn->state = tpcb;
|
||||
conn->fns = &altcp_tcp_functions;
|
||||
altcp_tcp_setup_callbacks(conn, tpcb);
|
||||
conn->state = tpcb;
|
||||
conn->fns = &altcp_tcp_functions;
|
||||
}
|
||||
|
||||
struct altcp_pcb *
|
||||
altcp_tcp_new_ip_type(u8_t ip_type)
|
||||
{
|
||||
/* Allocate the tcp pcb first to invoke the priority handling code
|
||||
if we're out of pcbs */
|
||||
struct tcp_pcb *tpcb = tcp_new_ip_type(ip_type);
|
||||
|
||||
if (tpcb != NULL) {
|
||||
struct altcp_pcb *ret = altcp_alloc();
|
||||
|
||||
if (ret != NULL) {
|
||||
altcp_tcp_setup(ret, tpcb);
|
||||
return ret;
|
||||
} else {
|
||||
/* altcp_pcb allocation failed -> free the tcp_pcb too */
|
||||
tcp_close(tpcb);
|
||||
}
|
||||
/* Allocate the tcp pcb first to invoke the priority handling code
|
||||
if we're out of pcbs */
|
||||
struct tcp_pcb *tpcb = tcp_new_ip_type(ip_type);
|
||||
if (tpcb != NULL) {
|
||||
struct altcp_pcb *ret = altcp_alloc();
|
||||
if (ret != NULL) {
|
||||
altcp_tcp_setup(ret, tpcb);
|
||||
return ret;
|
||||
} else {
|
||||
/* altcp_pcb allocation failed -> free the tcp_pcb too */
|
||||
tcp_close(tpcb);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** altcp_tcp allocator function fitting to @ref altcp_allocator_t / @ref altcp_new.
|
||||
@ -228,347 +211,332 @@ altcp_tcp_new_ip_type(u8_t ip_type)
|
||||
struct altcp_pcb *
|
||||
altcp_tcp_alloc(void *arg, u8_t ip_type)
|
||||
{
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
return altcp_tcp_new_ip_type(ip_type);
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
return altcp_tcp_new_ip_type(ip_type);
|
||||
}
|
||||
|
||||
struct altcp_pcb *
|
||||
altcp_tcp_wrap(struct tcp_pcb *tpcb)
|
||||
{
|
||||
if (tpcb != NULL) {
|
||||
struct altcp_pcb *ret = altcp_alloc();
|
||||
|
||||
if (ret != NULL) {
|
||||
altcp_tcp_setup(ret, tpcb);
|
||||
return ret;
|
||||
}
|
||||
if (tpcb != NULL) {
|
||||
struct altcp_pcb *ret = altcp_alloc();
|
||||
if (ret != NULL) {
|
||||
altcp_tcp_setup(ret, tpcb);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* "virtual" functions calling into tcp */
|
||||
static void altcp_tcp_set_poll(struct altcp_pcb *conn, u8_t interval)
|
||||
static void
|
||||
altcp_tcp_set_poll(struct altcp_pcb *conn, u8_t interval)
|
||||
{
|
||||
if (conn != NULL) {
|
||||
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
tcp_poll(pcb, altcp_tcp_poll, interval);
|
||||
}
|
||||
}
|
||||
|
||||
static void altcp_tcp_recved(struct altcp_pcb *conn, u16_t len)
|
||||
{
|
||||
if (conn != NULL) {
|
||||
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
tcp_recved(pcb, len);
|
||||
}
|
||||
}
|
||||
|
||||
static err_t altcp_tcp_bind(struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port)
|
||||
{
|
||||
struct tcp_pcb *pcb;
|
||||
|
||||
if (conn == NULL) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
if (conn != NULL) {
|
||||
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
pcb = (struct tcp_pcb *)conn->state;
|
||||
return tcp_bind(pcb, ipaddr, port);
|
||||
tcp_poll(pcb, altcp_tcp_poll, interval);
|
||||
}
|
||||
}
|
||||
|
||||
static err_t altcp_tcp_connect(struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port, altcp_connected_fn connected)
|
||||
static void
|
||||
altcp_tcp_recved(struct altcp_pcb *conn, u16_t len)
|
||||
{
|
||||
struct tcp_pcb *pcb;
|
||||
|
||||
if (conn == NULL) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
if (conn != NULL) {
|
||||
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
conn->connected = connected;
|
||||
pcb = (struct tcp_pcb *)conn->state;
|
||||
return tcp_connect(pcb, ipaddr, port, altcp_tcp_connected);
|
||||
tcp_recved(pcb, len);
|
||||
}
|
||||
}
|
||||
|
||||
static struct altcp_pcb *altcp_tcp_listen(struct altcp_pcb *conn, u8_t backlog, err_t *err)
|
||||
static err_t
|
||||
altcp_tcp_bind(struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port)
|
||||
{
|
||||
struct tcp_pcb *pcb;
|
||||
struct tcp_pcb *lpcb;
|
||||
|
||||
if (conn == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
pcb = (struct tcp_pcb *)conn->state;
|
||||
lpcb = tcp_listen_with_backlog_and_err(pcb, backlog, err);
|
||||
|
||||
if (lpcb != NULL) {
|
||||
conn->state = lpcb;
|
||||
tcp_accept(lpcb, altcp_tcp_accept);
|
||||
return conn;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void altcp_tcp_abort(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn != NULL) {
|
||||
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
|
||||
if (pcb) {
|
||||
tcp_abort(pcb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static err_t altcp_tcp_close(struct altcp_pcb *conn)
|
||||
{
|
||||
struct tcp_pcb *pcb;
|
||||
|
||||
if (conn == NULL) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
pcb = (struct tcp_pcb *)conn->state;
|
||||
|
||||
if (pcb) {
|
||||
err_t err;
|
||||
tcp_poll_fn oldpoll = pcb->poll;
|
||||
altcp_tcp_remove_callbacks(pcb);
|
||||
err = tcp_close(pcb);
|
||||
|
||||
if (err != ERR_OK) {
|
||||
/* not closed, set up all callbacks again */
|
||||
altcp_tcp_setup_callbacks(conn, pcb);
|
||||
/* poll callback is not included in the above */
|
||||
tcp_poll(pcb, oldpoll, pcb->pollinterval);
|
||||
return err;
|
||||
}
|
||||
|
||||
conn->state = NULL; /* unsafe to reference pcb after tcp_close(). */
|
||||
}
|
||||
|
||||
altcp_free(conn);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static err_t altcp_tcp_shutdown(struct altcp_pcb *conn, int shut_rx, int shut_tx)
|
||||
{
|
||||
struct tcp_pcb *pcb;
|
||||
|
||||
if (conn == NULL) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
pcb = (struct tcp_pcb *)conn->state;
|
||||
return tcp_shutdown(pcb, shut_rx, shut_tx);
|
||||
}
|
||||
|
||||
static err_t altcp_tcp_write(struct altcp_pcb *conn, const void *dataptr, u16_t len, u8_t apiflags)
|
||||
{
|
||||
struct tcp_pcb *pcb;
|
||||
|
||||
if (conn == NULL) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
pcb = (struct tcp_pcb *)conn->state;
|
||||
return tcp_write(pcb, dataptr, len, apiflags);
|
||||
}
|
||||
|
||||
static err_t altcp_tcp_output(struct altcp_pcb *conn)
|
||||
{
|
||||
struct tcp_pcb *pcb;
|
||||
|
||||
if (conn == NULL) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
pcb = (struct tcp_pcb *)conn->state;
|
||||
return tcp_output(pcb);
|
||||
}
|
||||
|
||||
static u16_t altcp_tcp_mss(struct altcp_pcb *conn)
|
||||
{
|
||||
struct tcp_pcb *pcb;
|
||||
|
||||
if (conn == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
pcb = (struct tcp_pcb *)conn->state;
|
||||
return tcp_mss(pcb);
|
||||
}
|
||||
|
||||
static u16_t altcp_tcp_sndbuf(struct altcp_pcb *conn)
|
||||
{
|
||||
struct tcp_pcb *pcb;
|
||||
|
||||
if (conn == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
pcb = (struct tcp_pcb *)conn->state;
|
||||
return tcp_sndbuf(pcb);
|
||||
}
|
||||
|
||||
static u16_t altcp_tcp_sndqueuelen(struct altcp_pcb *conn)
|
||||
{
|
||||
struct tcp_pcb *pcb;
|
||||
|
||||
if (conn == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
pcb = (struct tcp_pcb *)conn->state;
|
||||
return tcp_sndqueuelen(pcb);
|
||||
}
|
||||
|
||||
static void altcp_tcp_nagle_disable(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn && conn->state) {
|
||||
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
tcp_nagle_disable(pcb);
|
||||
}
|
||||
}
|
||||
|
||||
static void altcp_tcp_nagle_enable(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn && conn->state) {
|
||||
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
tcp_nagle_enable(pcb);
|
||||
}
|
||||
}
|
||||
|
||||
static int altcp_tcp_nagle_disabled(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn && conn->state) {
|
||||
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
return tcp_nagle_disabled(pcb);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void altcp_tcp_setprio(struct altcp_pcb *conn, u8_t prio)
|
||||
{
|
||||
if (conn != NULL) {
|
||||
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
tcp_setprio(pcb, prio);
|
||||
}
|
||||
}
|
||||
|
||||
static void altcp_tcp_dealloc(struct altcp_pcb *conn)
|
||||
{
|
||||
LWIP_UNUSED_ARG(conn);
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
/* no private state to clean up */
|
||||
}
|
||||
|
||||
static err_t altcp_tcp_get_tcp_addrinfo(struct altcp_pcb *conn, int local, ip_addr_t *addr, u16_t *port)
|
||||
{
|
||||
if (conn) {
|
||||
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
return tcp_tcp_get_tcp_addrinfo(pcb, local, addr, port);
|
||||
}
|
||||
|
||||
struct tcp_pcb *pcb;
|
||||
if (conn == NULL) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
pcb = (struct tcp_pcb *)conn->state;
|
||||
return tcp_bind(pcb, ipaddr, port);
|
||||
}
|
||||
|
||||
static ip_addr_t *altcp_tcp_get_ip(struct altcp_pcb *conn, int local)
|
||||
static err_t
|
||||
altcp_tcp_connect(struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port, altcp_connected_fn connected)
|
||||
{
|
||||
if (conn) {
|
||||
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
|
||||
if (pcb) {
|
||||
if (local) {
|
||||
return &pcb->local_ip;
|
||||
} else {
|
||||
return &pcb->remote_ip;
|
||||
}
|
||||
}
|
||||
}
|
||||
struct tcp_pcb *pcb;
|
||||
if (conn == NULL) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
conn->connected = connected;
|
||||
pcb = (struct tcp_pcb *)conn->state;
|
||||
return tcp_connect(pcb, ipaddr, port, altcp_tcp_connected);
|
||||
}
|
||||
|
||||
static struct altcp_pcb *
|
||||
altcp_tcp_listen(struct altcp_pcb *conn, u8_t backlog, err_t *err)
|
||||
{
|
||||
struct tcp_pcb *pcb;
|
||||
struct tcp_pcb *lpcb;
|
||||
if (conn == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
pcb = (struct tcp_pcb *)conn->state;
|
||||
lpcb = tcp_listen_with_backlog_and_err(pcb, backlog, err);
|
||||
if (lpcb != NULL) {
|
||||
conn->state = lpcb;
|
||||
tcp_accept(lpcb, altcp_tcp_accept);
|
||||
return conn;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static u16_t altcp_tcp_get_port(struct altcp_pcb *conn, int local)
|
||||
static void
|
||||
altcp_tcp_abort(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn) {
|
||||
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
|
||||
if (pcb) {
|
||||
if (local) {
|
||||
return pcb->local_port;
|
||||
} else {
|
||||
return pcb->remote_port;
|
||||
}
|
||||
}
|
||||
if (conn != NULL) {
|
||||
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
if (pcb) {
|
||||
tcp_abort(pcb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static err_t
|
||||
altcp_tcp_close(struct altcp_pcb *conn)
|
||||
{
|
||||
struct tcp_pcb *pcb;
|
||||
if (conn == NULL) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
pcb = (struct tcp_pcb *)conn->state;
|
||||
if (pcb) {
|
||||
err_t err;
|
||||
tcp_poll_fn oldpoll = pcb->poll;
|
||||
altcp_tcp_remove_callbacks(pcb);
|
||||
err = tcp_close(pcb);
|
||||
if (err != ERR_OK) {
|
||||
/* not closed, set up all callbacks again */
|
||||
altcp_tcp_setup_callbacks(conn, pcb);
|
||||
/* poll callback is not included in the above */
|
||||
tcp_poll(pcb, oldpoll, pcb->pollinterval);
|
||||
return err;
|
||||
}
|
||||
conn->state = NULL; /* unsafe to reference pcb after tcp_close(). */
|
||||
}
|
||||
altcp_free(conn);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static err_t
|
||||
altcp_tcp_shutdown(struct altcp_pcb *conn, int shut_rx, int shut_tx)
|
||||
{
|
||||
struct tcp_pcb *pcb;
|
||||
if (conn == NULL) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
pcb = (struct tcp_pcb *)conn->state;
|
||||
return tcp_shutdown(pcb, shut_rx, shut_tx);
|
||||
}
|
||||
|
||||
static err_t
|
||||
altcp_tcp_write(struct altcp_pcb *conn, const void *dataptr, u16_t len, u8_t apiflags)
|
||||
{
|
||||
struct tcp_pcb *pcb;
|
||||
if (conn == NULL) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
pcb = (struct tcp_pcb *)conn->state;
|
||||
return tcp_write(pcb, dataptr, len, apiflags);
|
||||
}
|
||||
|
||||
static err_t
|
||||
altcp_tcp_output(struct altcp_pcb *conn)
|
||||
{
|
||||
struct tcp_pcb *pcb;
|
||||
if (conn == NULL) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
pcb = (struct tcp_pcb *)conn->state;
|
||||
return tcp_output(pcb);
|
||||
}
|
||||
|
||||
static u16_t
|
||||
altcp_tcp_mss(struct altcp_pcb *conn)
|
||||
{
|
||||
struct tcp_pcb *pcb;
|
||||
if (conn == NULL) {
|
||||
return 0;
|
||||
}
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
pcb = (struct tcp_pcb *)conn->state;
|
||||
return tcp_mss(pcb);
|
||||
}
|
||||
|
||||
static u16_t
|
||||
altcp_tcp_sndbuf(struct altcp_pcb *conn)
|
||||
{
|
||||
struct tcp_pcb *pcb;
|
||||
if (conn == NULL) {
|
||||
return 0;
|
||||
}
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
pcb = (struct tcp_pcb *)conn->state;
|
||||
return tcp_sndbuf(pcb);
|
||||
}
|
||||
|
||||
static u16_t
|
||||
altcp_tcp_sndqueuelen(struct altcp_pcb *conn)
|
||||
{
|
||||
struct tcp_pcb *pcb;
|
||||
if (conn == NULL) {
|
||||
return 0;
|
||||
}
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
pcb = (struct tcp_pcb *)conn->state;
|
||||
return tcp_sndqueuelen(pcb);
|
||||
}
|
||||
|
||||
static void
|
||||
altcp_tcp_nagle_disable(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn && conn->state) {
|
||||
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
tcp_nagle_disable(pcb);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
altcp_tcp_nagle_enable(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn && conn->state) {
|
||||
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
tcp_nagle_enable(pcb);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
altcp_tcp_nagle_disabled(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn && conn->state) {
|
||||
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
return tcp_nagle_disabled(pcb);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
altcp_tcp_setprio(struct altcp_pcb *conn, u8_t prio)
|
||||
{
|
||||
if (conn != NULL) {
|
||||
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
tcp_setprio(pcb, prio);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
altcp_tcp_dealloc(struct altcp_pcb *conn)
|
||||
{
|
||||
LWIP_UNUSED_ARG(conn);
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
/* no private state to clean up */
|
||||
}
|
||||
|
||||
static err_t
|
||||
altcp_tcp_get_tcp_addrinfo(struct altcp_pcb *conn, int local, ip_addr_t *addr, u16_t *port)
|
||||
{
|
||||
if (conn) {
|
||||
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
return tcp_tcp_get_tcp_addrinfo(pcb, local, addr, port);
|
||||
}
|
||||
return ERR_VAL;
|
||||
}
|
||||
|
||||
static ip_addr_t *
|
||||
altcp_tcp_get_ip(struct altcp_pcb *conn, int local)
|
||||
{
|
||||
if (conn) {
|
||||
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
if (pcb) {
|
||||
if (local) {
|
||||
return &pcb->local_ip;
|
||||
} else {
|
||||
return &pcb->remote_ip;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static u16_t
|
||||
altcp_tcp_get_port(struct altcp_pcb *conn, int local)
|
||||
{
|
||||
if (conn) {
|
||||
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
if (pcb) {
|
||||
if (local) {
|
||||
return pcb->local_port;
|
||||
} else {
|
||||
return pcb->remote_port;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
static enum tcp_state altcp_tcp_dbg_get_tcp_state(struct altcp_pcb *conn)
|
||||
static enum tcp_state
|
||||
altcp_tcp_dbg_get_tcp_state(struct altcp_pcb *conn)
|
||||
{
|
||||
if (conn) {
|
||||
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
|
||||
if (pcb) {
|
||||
return pcb->state;
|
||||
}
|
||||
if (conn) {
|
||||
struct tcp_pcb *pcb = (struct tcp_pcb *)conn->state;
|
||||
ALTCP_TCP_ASSERT_CONN(conn);
|
||||
if (pcb) {
|
||||
return pcb->state;
|
||||
}
|
||||
|
||||
return CLOSED;
|
||||
}
|
||||
return CLOSED;
|
||||
}
|
||||
#endif
|
||||
const struct altcp_functions altcp_tcp_functions = {
|
||||
altcp_tcp_set_poll,
|
||||
altcp_tcp_recved,
|
||||
altcp_tcp_bind,
|
||||
altcp_tcp_connect,
|
||||
altcp_tcp_listen,
|
||||
altcp_tcp_abort,
|
||||
altcp_tcp_close,
|
||||
altcp_tcp_shutdown,
|
||||
altcp_tcp_write,
|
||||
altcp_tcp_output,
|
||||
altcp_tcp_mss,
|
||||
altcp_tcp_sndbuf,
|
||||
altcp_tcp_sndqueuelen,
|
||||
altcp_tcp_nagle_disable,
|
||||
altcp_tcp_nagle_enable,
|
||||
altcp_tcp_nagle_disabled,
|
||||
altcp_tcp_setprio,
|
||||
altcp_tcp_dealloc,
|
||||
altcp_tcp_get_tcp_addrinfo,
|
||||
altcp_tcp_get_ip,
|
||||
altcp_tcp_get_port
|
||||
altcp_tcp_set_poll,
|
||||
altcp_tcp_recved,
|
||||
altcp_tcp_bind,
|
||||
altcp_tcp_connect,
|
||||
altcp_tcp_listen,
|
||||
altcp_tcp_abort,
|
||||
altcp_tcp_close,
|
||||
altcp_tcp_shutdown,
|
||||
altcp_tcp_write,
|
||||
altcp_tcp_output,
|
||||
altcp_tcp_mss,
|
||||
altcp_tcp_sndbuf,
|
||||
altcp_tcp_sndqueuelen,
|
||||
altcp_tcp_nagle_disable,
|
||||
altcp_tcp_nagle_enable,
|
||||
altcp_tcp_nagle_disabled,
|
||||
altcp_tcp_setprio,
|
||||
altcp_tcp_dealloc,
|
||||
altcp_tcp_get_tcp_addrinfo,
|
||||
altcp_tcp_get_ip,
|
||||
altcp_tcp_get_port
|
||||
#ifdef LWIP_DEBUG
|
||||
,
|
||||
altcp_tcp_dbg_get_tcp_state
|
||||
, altcp_tcp_dbg_get_tcp_state
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -72,9 +72,10 @@
|
||||
* @param n u16_t in host byte order
|
||||
* @return n in network byte order
|
||||
*/
|
||||
u16_t lwip_htons(u16_t n)
|
||||
u16_t
|
||||
lwip_htons(u16_t n)
|
||||
{
|
||||
return PP_HTONS(n);
|
||||
return PP_HTONS(n);
|
||||
}
|
||||
#endif /* lwip_htons */
|
||||
|
||||
@ -85,9 +86,10 @@ u16_t lwip_htons(u16_t n)
|
||||
* @param n u32_t in host byte order
|
||||
* @return n in network byte order
|
||||
*/
|
||||
u32_t lwip_htonl(u32_t n)
|
||||
u32_t
|
||||
lwip_htonl(u32_t n)
|
||||
{
|
||||
return PP_HTONL(n);
|
||||
return PP_HTONL(n);
|
||||
}
|
||||
#endif /* lwip_htonl */
|
||||
|
||||
@ -99,22 +101,20 @@ u32_t lwip_htonl(u32_t n)
|
||||
* lwIP default implementation for strnstr() non-standard function.
|
||||
* This can be \#defined to strnstr() depending on your platform port.
|
||||
*/
|
||||
char *lwip_strnstr(const char *buffer, const char *token, size_t n)
|
||||
char *
|
||||
lwip_strnstr(const char *buffer, const char *token, size_t n)
|
||||
{
|
||||
const char *p;
|
||||
size_t tokenlen = strlen(token);
|
||||
|
||||
if (tokenlen == 0) {
|
||||
return LWIP_CONST_CAST(char *, buffer);
|
||||
const char *p;
|
||||
size_t tokenlen = strlen(token);
|
||||
if (tokenlen == 0) {
|
||||
return LWIP_CONST_CAST(char *, buffer);
|
||||
}
|
||||
for (p = buffer; *p && (p + tokenlen <= buffer + n); p++) {
|
||||
if ((*p == *token) && (strncmp(p, token, tokenlen) == 0)) {
|
||||
return LWIP_CONST_CAST(char *, p);
|
||||
}
|
||||
|
||||
for (p = buffer; *p && (p + tokenlen <= buffer + n); p++) {
|
||||
if ((*p == *token) && (strncmp(p, token, tokenlen) == 0)) {
|
||||
return LWIP_CONST_CAST(char *, p);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -124,35 +124,32 @@ char *lwip_strnstr(const char *buffer, const char *token, size_t n)
|
||||
* lwIP default implementation for stricmp() non-standard function.
|
||||
* This can be \#defined to stricmp() depending on your platform port.
|
||||
*/
|
||||
int lwip_stricmp(const char *str1, const char *str2)
|
||||
int
|
||||
lwip_stricmp(const char *str1, const char *str2)
|
||||
{
|
||||
char c1, c2;
|
||||
char c1, c2;
|
||||
|
||||
do {
|
||||
c1 = *str1++;
|
||||
c2 = *str2++;
|
||||
|
||||
if (c1 != c2) {
|
||||
char c1_upc = c1 | 0x20;
|
||||
|
||||
if ((c1_upc >= 'a') && (c1_upc <= 'z')) {
|
||||
/* characters are not equal an one is in the alphabet range:
|
||||
downcase both chars and check again */
|
||||
char c2_upc = c2 | 0x20;
|
||||
|
||||
if (c1_upc != c2_upc) {
|
||||
/* still not equal */
|
||||
/* don't care for < or > */
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
/* characters are not equal but none is in the alphabet range */
|
||||
return 1;
|
||||
}
|
||||
do {
|
||||
c1 = *str1++;
|
||||
c2 = *str2++;
|
||||
if (c1 != c2) {
|
||||
char c1_upc = c1 | 0x20;
|
||||
if ((c1_upc >= 'a') && (c1_upc <= 'z')) {
|
||||
/* characters are not equal an one is in the alphabet range:
|
||||
downcase both chars and check again */
|
||||
char c2_upc = c2 | 0x20;
|
||||
if (c1_upc != c2_upc) {
|
||||
/* still not equal */
|
||||
/* don't care for < or > */
|
||||
return 1;
|
||||
}
|
||||
} while (c1 != 0);
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
/* characters are not equal but none is in the alphabet range */
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
} while (c1 != 0);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -162,37 +159,33 @@ int lwip_stricmp(const char *str1, const char *str2)
|
||||
* lwIP default implementation for strnicmp() non-standard function.
|
||||
* This can be \#defined to strnicmp() depending on your platform port.
|
||||
*/
|
||||
int lwip_strnicmp(const char *str1, const char *str2, size_t len)
|
||||
int
|
||||
lwip_strnicmp(const char *str1, const char *str2, size_t len)
|
||||
{
|
||||
char c1, c2;
|
||||
char c1, c2;
|
||||
|
||||
do {
|
||||
c1 = *str1++;
|
||||
c2 = *str2++;
|
||||
|
||||
if (c1 != c2) {
|
||||
char c1_upc = c1 | 0x20;
|
||||
|
||||
if ((c1_upc >= 'a') && (c1_upc <= 'z')) {
|
||||
/* characters are not equal an one is in the alphabet range:
|
||||
downcase both chars and check again */
|
||||
char c2_upc = c2 | 0x20;
|
||||
|
||||
if (c1_upc != c2_upc) {
|
||||
/* still not equal */
|
||||
/* don't care for < or > */
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
/* characters are not equal but none is in the alphabet range */
|
||||
return 1;
|
||||
}
|
||||
do {
|
||||
c1 = *str1++;
|
||||
c2 = *str2++;
|
||||
if (c1 != c2) {
|
||||
char c1_upc = c1 | 0x20;
|
||||
if ((c1_upc >= 'a') && (c1_upc <= 'z')) {
|
||||
/* characters are not equal an one is in the alphabet range:
|
||||
downcase both chars and check again */
|
||||
char c2_upc = c2 | 0x20;
|
||||
if (c1_upc != c2_upc) {
|
||||
/* still not equal */
|
||||
/* don't care for < or > */
|
||||
return 1;
|
||||
}
|
||||
|
||||
len--;
|
||||
} while ((len != 0) && (c1 != 0));
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
/* characters are not equal but none is in the alphabet range */
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
len--;
|
||||
} while ((len != 0) && (c1 != 0));
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -202,51 +195,46 @@ int lwip_strnicmp(const char *str1, const char *str2, size_t len)
|
||||
* lwIP default implementation for itoa() non-standard function.
|
||||
* This can be \#defined to itoa() or snprintf(result, bufsize, "%d", number) depending on your platform port.
|
||||
*/
|
||||
void lwip_itoa(char *result, size_t bufsize, int number)
|
||||
void
|
||||
lwip_itoa(char *result, size_t bufsize, int number)
|
||||
{
|
||||
char *res = result;
|
||||
char *tmp = result + bufsize - 1;
|
||||
int n = (number >= 0) ? number : -number;
|
||||
char *res = result;
|
||||
char *tmp = result + bufsize - 1;
|
||||
int n = (number >= 0) ? number : -number;
|
||||
|
||||
/* handle invalid bufsize */
|
||||
if (bufsize < 2) {
|
||||
if (bufsize == 1) {
|
||||
*result = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
/* handle invalid bufsize */
|
||||
if (bufsize < 2) {
|
||||
if (bufsize == 1) {
|
||||
*result = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* First, add sign */
|
||||
if (number < 0) {
|
||||
*res++ = '-';
|
||||
}
|
||||
|
||||
/* Then create the string from the end and stop if buffer full,
|
||||
and ensure output string is zero terminated */
|
||||
*tmp = 0;
|
||||
|
||||
while ((n != 0) && (tmp > res)) {
|
||||
char val = (char)('0' + (n % 10));
|
||||
tmp--;
|
||||
*tmp = val;
|
||||
n = n / 10;
|
||||
}
|
||||
|
||||
if (n) {
|
||||
/* buffer is too small */
|
||||
*result = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (*tmp == 0) {
|
||||
/* Nothing added? */
|
||||
*res++ = '0';
|
||||
*res++ = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
/* move from temporary buffer to output buffer (sign is not moved) */
|
||||
memmove(res, tmp, (size_t)((result + bufsize) - tmp));
|
||||
/* First, add sign */
|
||||
if (number < 0) {
|
||||
*res++ = '-';
|
||||
}
|
||||
/* Then create the string from the end and stop if buffer full,
|
||||
and ensure output string is zero terminated */
|
||||
*tmp = 0;
|
||||
while ((n != 0) && (tmp > res)) {
|
||||
char val = (char)('0' + (n % 10));
|
||||
tmp--;
|
||||
*tmp = val;
|
||||
n = n / 10;
|
||||
}
|
||||
if (n) {
|
||||
/* buffer is too small */
|
||||
*result = 0;
|
||||
return;
|
||||
}
|
||||
if (*tmp == 0) {
|
||||
/* Nothing added? */
|
||||
*res++ = '0';
|
||||
*res++ = 0;
|
||||
return;
|
||||
}
|
||||
/* move from temporary buffer to output buffer (sign is not moved) */
|
||||
memmove(res, tmp, (size_t)((result + bufsize) - tmp));
|
||||
}
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user