Merge remote-tracking branch 'nuttx_bitbucket/master'
This commit is contained in:
commit
9b288de266
@ -960,6 +960,13 @@ examples/nettest
|
|||||||
CONFIG_EXAMPLES_NETTEST=y - Enables the nettest example
|
CONFIG_EXAMPLES_NETTEST=y - Enables the nettest example
|
||||||
CONFIG_EXAMPLES_NETLIB=y - The networking library in needed.
|
CONFIG_EXAMPLES_NETLIB=y - The networking library in needed.
|
||||||
|
|
||||||
|
Configurations:
|
||||||
|
|
||||||
|
- Server on target hardware; client on host
|
||||||
|
- Client on target hardware; Server on host
|
||||||
|
- Server and Client on different targets.
|
||||||
|
- Loopback configuration with both client and server on the same target.
|
||||||
|
|
||||||
See also examples/tcpecho
|
See also examples/tcpecho
|
||||||
|
|
||||||
examples/nrf24l01_term
|
examples/nrf24l01_term
|
||||||
@ -2106,6 +2113,12 @@ examples/udp
|
|||||||
|
|
||||||
CONFIG_NETUTILS_NETLIB=y
|
CONFIG_NETUTILS_NETLIB=y
|
||||||
|
|
||||||
|
Possible configurations:
|
||||||
|
|
||||||
|
- Server on target hardware; client on host
|
||||||
|
- Client on target hardware; Server on host
|
||||||
|
- Server and Client on different targets.
|
||||||
|
|
||||||
examples/udpblaster
|
examples/udpblaster
|
||||||
^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* apps/examples/cc3000/shell.c
|
* apps/examples/cc3000/shell.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2013, 2017 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* This is a leverage of similar logic from uIP:
|
* This is a leverage of similar logic from uIP:
|
||||||
@ -217,6 +217,7 @@ int shell_main(int argc, char *argv[])
|
|||||||
/* Configure the telnet daemon */
|
/* Configure the telnet daemon */
|
||||||
|
|
||||||
config.d_port = HTONS(23);
|
config.d_port = HTONS(23);
|
||||||
|
config.d_family = AF_INET;
|
||||||
config.d_priority = CONFIG_EXAMPLES_TELNETD_DAEMONPRIO;
|
config.d_priority = CONFIG_EXAMPLES_TELNETD_DAEMONPRIO;
|
||||||
config.d_stacksize = CONFIG_EXAMPLES_TELNETD_DAEMONSTACKSIZE;
|
config.d_stacksize = CONFIG_EXAMPLES_TELNETD_DAEMONSTACKSIZE;
|
||||||
config.t_priority = CONFIG_EXAMPLES_TELNETD_CLIENTPRIO;
|
config.t_priority = CONFIG_EXAMPLES_TELNETD_CLIENTPRIO;
|
||||||
|
@ -12,20 +12,28 @@ config EXAMPLES_NETTEST
|
|||||||
|
|
||||||
if EXAMPLES_NETTEST
|
if EXAMPLES_NETTEST
|
||||||
|
|
||||||
config EXAMPLES_NETTEST_PROGNAME
|
config EXAMPLES_NETTEST_SENDSIZE
|
||||||
string "Program name"
|
int "Payload size"
|
||||||
|
default 4096
|
||||||
|
---help---
|
||||||
|
The test client sends well-known packets to ther server. The server
|
||||||
|
will receive and verfity those packets. This setting determines
|
||||||
|
size of each packet.
|
||||||
|
|
||||||
|
config EXAMPLES_NETTEST_PROGNAME1
|
||||||
|
string "Target1 program name"
|
||||||
default "nettest"
|
default "nettest"
|
||||||
depends on BUILD_KERNEL
|
depends on BUILD_KERNEL
|
||||||
---help---
|
---help---
|
||||||
This is the name of the program that will be use when the Nettest
|
This is the name of the program that will be use when the Nettest
|
||||||
program is installed.
|
program is installed.
|
||||||
|
|
||||||
config EXAMPLES_NETTEST_STACKSIZE
|
config EXAMPLES_NETTEST_STACKSIZE1
|
||||||
int "Nettest stack size"
|
int "Target1 stack size"
|
||||||
default 2048
|
default 2048
|
||||||
|
|
||||||
config EXAMPLES_NETTEST_PRIORITY
|
config EXAMPLES_NETTEST_PRIORITY1
|
||||||
int "Nettest priority"
|
int "Target1 priority"
|
||||||
default 100
|
default 100
|
||||||
|
|
||||||
config EXAMPLES_NETTEST_LOOPBACK
|
config EXAMPLES_NETTEST_LOOPBACK
|
||||||
@ -36,26 +44,66 @@ config EXAMPLES_NETTEST_LOOPBACK
|
|||||||
Perform the test using the local loopback device. In this case,
|
Perform the test using the local loopback device. In this case,
|
||||||
both the client and the server reside on the target.
|
both the client and the server reside on the target.
|
||||||
|
|
||||||
if EXAMPLES_NETTEST_LOOPBACK
|
# No server if loopback; No second target if loopback
|
||||||
|
|
||||||
config EXAMPLES_NETTEST_SERVER_STACKSIZE
|
if !EXAMPLES_NETTEST_LOOPBACK
|
||||||
int "Server stack size"
|
|
||||||
default 2048
|
|
||||||
|
|
||||||
config EXAMPLES_NETTEST_SERVER_PRIORITY
|
config EXAMPLES_NETTEST_SERVER1
|
||||||
int "Server priority"
|
bool "Target1 is server"
|
||||||
default 100
|
|
||||||
|
|
||||||
endif # EXAMPLES_NETTEST_LOOPBACK
|
|
||||||
|
|
||||||
config EXAMPLES_NETTEST_SERVER
|
|
||||||
bool "Target is server"
|
|
||||||
default n
|
default n
|
||||||
depends on !EXAMPLES_NETTEST_LOOPBACK
|
depends on !EXAMPLES_NETTEST_LOOPBACK
|
||||||
---help---
|
---help---
|
||||||
Select to use the host as the client side of the test. Default: The
|
Select to use the host as the client side of the test. Default: The
|
||||||
target is the client side of the test
|
target is the client side of the test
|
||||||
|
|
||||||
|
config EXAMPLES_NETTEST_TARGET2
|
||||||
|
bool "Second endpoint is a target"
|
||||||
|
default n
|
||||||
|
---help---
|
||||||
|
By default, the host PC is configured as the second endpoint of the
|
||||||
|
NETTEST. If this option is selected, then the second endpoint
|
||||||
|
will be built into the FLASH image as well. This means that you
|
||||||
|
can use two target boards to run the test with no host PC
|
||||||
|
involvement.
|
||||||
|
|
||||||
|
if EXAMPLES_NETTEST_TARGET2
|
||||||
|
|
||||||
|
config EXAMPLES_NETTEST_PROGNAME2
|
||||||
|
string "Target2 program name"
|
||||||
|
default "tcpserver" if !EXAMPLES_NETTEST_SERVER2
|
||||||
|
default "tcpclient" if EXAMPLES_NETTEST_SERVER2
|
||||||
|
depends on BUILD_KERNEL
|
||||||
|
---help---
|
||||||
|
This is the name of the Target2 program that will be use when the
|
||||||
|
NSH ELF program is installed.
|
||||||
|
|
||||||
|
config EXAMPLES_NETTEST_PRIORITY2
|
||||||
|
int "Target2 task priority"
|
||||||
|
default 100
|
||||||
|
|
||||||
|
config EXAMPLES_NETTEST_STACKSIZE2
|
||||||
|
int "Target2 stack size"
|
||||||
|
default 2048
|
||||||
|
|
||||||
|
endif # EXAMPLES_NETTEST_TARGET2
|
||||||
|
endif # !EXAMPLES_NETTEST_LOOPBACK
|
||||||
|
|
||||||
|
if EXAMPLES_NETTEST_LOOPBACK
|
||||||
|
config EXAMPLES_NETTEST_DAEMON_STACKSIZE
|
||||||
|
int "Server daemon stack size"
|
||||||
|
default 2048
|
||||||
|
|
||||||
|
config EXAMPLES_NETTEST_DAEMON_PRIORITY
|
||||||
|
int "Server daemon priority"
|
||||||
|
default 100
|
||||||
|
#endif
|
||||||
|
|
||||||
|
endif # EXAMPLES_NETTEST_LOOPBACK
|
||||||
|
|
||||||
|
config EXAMPLES_NETTEST_DEVNAME
|
||||||
|
string "Network device"
|
||||||
|
default "eth0"
|
||||||
|
|
||||||
config EXAMPLES_NETTEST_PERFORMANCE
|
config EXAMPLES_NETTEST_PERFORMANCE
|
||||||
bool "Test for Performance"
|
bool "Test for Performance"
|
||||||
default n
|
default n
|
||||||
@ -78,6 +126,8 @@ config EXAMPLES_NETTEST_IPv6
|
|||||||
|
|
||||||
endchoice # IP Domain
|
endchoice # IP Domain
|
||||||
|
|
||||||
|
# No hardware initialization if loopback
|
||||||
|
|
||||||
config EXAMPLES_NETTEST_INIT
|
config EXAMPLES_NETTEST_INIT
|
||||||
bool "Initialize network"
|
bool "Initialize network"
|
||||||
default n if NSH_BUILTIN_APPS
|
default n if NSH_BUILTIN_APPS
|
||||||
@ -114,17 +164,19 @@ config EXAMPLES_NETTEST_NETMASK
|
|||||||
|
|
||||||
endif # EXAMPLES_NETTEST_INIT
|
endif # EXAMPLES_NETTEST_INIT
|
||||||
|
|
||||||
|
# No server if loopback
|
||||||
|
|
||||||
if !EXAMPLES_NETTEST_LOOPBACK
|
if !EXAMPLES_NETTEST_LOOPBACK
|
||||||
|
|
||||||
config EXAMPLES_NETTEST_CLIENTIP
|
config EXAMPLES_NETTEST_SERVERIP
|
||||||
hex "Client IP Address"
|
hex "Server IP Address"
|
||||||
default 0x0a000001 if !EXAMPLES_NETTEST_SERVER
|
default 0x0a000001 if !EXAMPLES_NETTEST_SERVER
|
||||||
default 0x0a000002 if EXAMPLES_NETTEST_SERVER
|
default 0x0a000002 if EXAMPLES_NETTEST_SERVER
|
||||||
---help---
|
---help---
|
||||||
IP address of the client. If the target is the client, then
|
IP address of the server. If the target is the server, then
|
||||||
EXAMPLES_NETTEST_CLIENTIP should be the same as
|
EXAMPLES_NETTEST_SERVERIP should be the same as
|
||||||
EXAMPLES_NETTEST_IPADDR (default). If the target is the server,
|
EXAMPLES_NETTEST_IPADDR (default). If the target is the client,
|
||||||
then the default value of EXAMPLES_NETTEST_CLIENTIP is set to the
|
then the default value of EXAMPLES_NETTEST_SERVERIP is set to the
|
||||||
host PC IP address (possibly the gateway address,
|
host PC IP address (possibly the gateway address,
|
||||||
EXAMPLES_NETTEST_DRIPADDR?).
|
EXAMPLES_NETTEST_DRIPADDR?).
|
||||||
|
|
||||||
@ -385,19 +437,21 @@ config EXAMPLES_NETTEST_IPv6NETMASK_8
|
|||||||
endif # NET_ICMPv6_AUTOCONF
|
endif # NET_ICMPv6_AUTOCONF
|
||||||
endif # EXAMPLES_NETTEST_INIT
|
endif # EXAMPLES_NETTEST_INIT
|
||||||
|
|
||||||
|
# Addresses are well known if loopback is used.
|
||||||
|
|
||||||
if !EXAMPLES_NETTEST_LOOPBACK || !NET_LOOPBACK
|
if !EXAMPLES_NETTEST_LOOPBACK || !NET_LOOPBACK
|
||||||
|
|
||||||
comment "Client IPv6 address"
|
comment "Server IPv6 address"
|
||||||
|
|
||||||
config EXAMPLES_NETTEST_CLIENTIPv6ADDR_1
|
config EXAMPLES_NETTEST_SERVERIPv6ADDR_1
|
||||||
hex "[0]"
|
hex "[0]"
|
||||||
default 0xfc00
|
default 0xfc00
|
||||||
range 0x0 0xffff
|
range 0x0 0xffff
|
||||||
---help---
|
---help---
|
||||||
IP address of the client. If the target is the client, then
|
IP address of the server. If the target is the server, then
|
||||||
EXAMPLES_NETTEST_CLIENTIP should be the same as
|
EXAMPLES_NETTEST_SERVERIP should be the same as
|
||||||
EXAMPLES_NETTEST_IPADDR (default). If the target is the server,
|
EXAMPLES_NETTEST_IPADDR (default). If the target is the cleint,
|
||||||
then the default value of EXAMPLES_NETTEST_CLIENTIP is set to the
|
then the default value of EXAMPLES_NETTEST_SERVERIP is set to the
|
||||||
host PC IP address (possibly the gateway address,
|
host PC IP address (possibly the gateway address,
|
||||||
EXAMPLES_NETTEST_DRIPADDR?).
|
EXAMPLES_NETTEST_DRIPADDR?).
|
||||||
|
|
||||||
@ -405,15 +459,15 @@ config EXAMPLES_NETTEST_CLIENTIPv6ADDR_1
|
|||||||
values forming the full IP address must be specified individually.
|
values forming the full IP address must be specified individually.
|
||||||
This is the first of the 8-values.
|
This is the first of the 8-values.
|
||||||
|
|
||||||
config EXAMPLES_NETTEST_CLIENTIPv6ADDR_2
|
config EXAMPLES_NETTEST_SERVERIPv6ADDR_2
|
||||||
hex "[1]"
|
hex "[1]"
|
||||||
default 0x0000
|
default 0x0000
|
||||||
range 0x0 0xffff
|
range 0x0 0xffff
|
||||||
---help---
|
---help---
|
||||||
IP address of the client. If the target is the client, then
|
IP address of the server. If the target is the server, then
|
||||||
EXAMPLES_NETTEST_CLIENTIP should be the same as
|
EXAMPLES_NETTEST_SERVERIP should be the same as
|
||||||
EXAMPLES_NETTEST_IPADDR (default). If the target is the server,
|
EXAMPLES_NETTEST_IPADDR (default). If the target is the client,
|
||||||
then the default value of EXAMPLES_NETTEST_CLIENTIP is set to the
|
then the default value of EXAMPLES_NETTEST_SERVERIP is set to the
|
||||||
host PC IP address (possibly the gateway address,
|
host PC IP address (possibly the gateway address,
|
||||||
EXAMPLES_NETTEST_DRIPADDR?).
|
EXAMPLES_NETTEST_DRIPADDR?).
|
||||||
|
|
||||||
@ -421,15 +475,15 @@ config EXAMPLES_NETTEST_CLIENTIPv6ADDR_2
|
|||||||
values forming the full IP address must be specified individually.
|
values forming the full IP address must be specified individually.
|
||||||
This is the second of the 8-values.
|
This is the second of the 8-values.
|
||||||
|
|
||||||
config EXAMPLES_NETTEST_CLIENTIPv6ADDR_3
|
config EXAMPLES_NETTEST_SERVERIPv6ADDR_3
|
||||||
hex "[2]"
|
hex "[2]"
|
||||||
default 0x0000
|
default 0x0000
|
||||||
range 0x0 0xffff
|
range 0x0 0xffff
|
||||||
---help---
|
---help---
|
||||||
IP address of the client. If the target is the client, then
|
IP address of the server. If the target is the server, then
|
||||||
EXAMPLES_NETTEST_CLIENTIP should be the same as
|
EXAMPLES_NETTEST_SERVERIP should be the same as
|
||||||
EXAMPLES_NETTEST_IPADDR (default). If the target is the server,
|
EXAMPLES_NETTEST_IPADDR (default). If the target is the client,
|
||||||
then the default value of EXAMPLES_NETTEST_CLIENTIP is set to the
|
then the default value of EXAMPLES_NETTEST_SERVERIP is set to the
|
||||||
host PC IP address (possibly the gateway address,
|
host PC IP address (possibly the gateway address,
|
||||||
EXAMPLES_NETTEST_DRIPADDR?).
|
EXAMPLES_NETTEST_DRIPADDR?).
|
||||||
|
|
||||||
@ -437,15 +491,15 @@ config EXAMPLES_NETTEST_CLIENTIPv6ADDR_3
|
|||||||
values forming the full IP address must be specified individually.
|
values forming the full IP address must be specified individually.
|
||||||
This is the Third of the 8-values.
|
This is the Third of the 8-values.
|
||||||
|
|
||||||
config EXAMPLES_NETTEST_CLIENTIPv6ADDR_4
|
config EXAMPLES_NETTEST_SERVERIPv6ADDR_4
|
||||||
hex "[3]"
|
hex "[3]"
|
||||||
default 0x0000
|
default 0x0000
|
||||||
range 0x0 0xffff
|
range 0x0 0xffff
|
||||||
---help---
|
---help---
|
||||||
IP address of the client. If the target is the client, then
|
IP address of the server. If the target is the server, then
|
||||||
EXAMPLES_NETTEST_CLIENTIP should be the same as
|
EXAMPLES_NETTEST_SERVERIP should be the same as
|
||||||
EXAMPLES_NETTEST_IPADDR (default). If the target is the server,
|
EXAMPLES_NETTEST_IPADDR (default). If the target is the client,
|
||||||
then the default value of EXAMPLES_NETTEST_CLIENTIP is set to the
|
then the default value of EXAMPLES_NETTEST_SERVERIP is set to the
|
||||||
host PC IP address (possibly the gateway address,
|
host PC IP address (possibly the gateway address,
|
||||||
EXAMPLES_NETTEST_DRIPADDR?).
|
EXAMPLES_NETTEST_DRIPADDR?).
|
||||||
|
|
||||||
@ -453,15 +507,15 @@ config EXAMPLES_NETTEST_CLIENTIPv6ADDR_4
|
|||||||
values forming the full IP address must be specified individually.
|
values forming the full IP address must be specified individually.
|
||||||
This is the fourth of the 8-values.
|
This is the fourth of the 8-values.
|
||||||
|
|
||||||
config EXAMPLES_NETTEST_CLIENTIPv6ADDR_5
|
config EXAMPLES_NETTEST_SERVERIPv6ADDR_5
|
||||||
hex "[4]"
|
hex "[4]"
|
||||||
default 0x0000
|
default 0x0000
|
||||||
range 0x0 0xffff
|
range 0x0 0xffff
|
||||||
---help---
|
---help---
|
||||||
IP address of the client. If the target is the client, then
|
IP address of the server. If the target is the server, then
|
||||||
EXAMPLES_NETTEST_CLIENTIP should be the same as
|
EXAMPLES_NETTEST_SERVERIP should be the same as
|
||||||
EXAMPLES_NETTEST_IPADDR (default). If the target is the server,
|
EXAMPLES_NETTEST_IPADDR (default). If the target is the client,
|
||||||
then the default value of EXAMPLES_NETTEST_CLIENTIP is set to the
|
then the default value of EXAMPLES_NETTEST_SERVERIP is set to the
|
||||||
host PC IP address (possibly the gateway address,
|
host PC IP address (possibly the gateway address,
|
||||||
EXAMPLES_NETTEST_DRIPADDR?).
|
EXAMPLES_NETTEST_DRIPADDR?).
|
||||||
|
|
||||||
@ -469,15 +523,15 @@ config EXAMPLES_NETTEST_CLIENTIPv6ADDR_5
|
|||||||
values forming the full IP address must be specified individually.
|
values forming the full IP address must be specified individually.
|
||||||
This is the fifth of the 8-values.
|
This is the fifth of the 8-values.
|
||||||
|
|
||||||
config EXAMPLES_NETTEST_CLIENTIPv6ADDR_6
|
config EXAMPLES_NETTEST_SERVERIPv6ADDR_6
|
||||||
hex "[5]"
|
hex "[5]"
|
||||||
default 0x0000
|
default 0x0000
|
||||||
range 0x0 0xffff
|
range 0x0 0xffff
|
||||||
---help---
|
---help---
|
||||||
IP address of the client. If the target is the client, then
|
IP address of the server. If the target is the server, then
|
||||||
EXAMPLES_NETTEST_CLIENTIP should be the same as
|
EXAMPLES_NETTEST_SERVERIP should be the same as
|
||||||
EXAMPLES_NETTEST_IPADDR (default). If the target is the server,
|
EXAMPLES_NETTEST_IPADDR (default). If the target is the client,
|
||||||
then the default value of EXAMPLES_NETTEST_CLIENTIP is set to the
|
then the default value of EXAMPLES_NETTEST_SERVERIP is set to the
|
||||||
host PC IP address (possibly the gateway address,
|
host PC IP address (possibly the gateway address,
|
||||||
EXAMPLES_NETTEST_DRIPADDR?).
|
EXAMPLES_NETTEST_DRIPADDR?).
|
||||||
|
|
||||||
@ -485,15 +539,15 @@ config EXAMPLES_NETTEST_CLIENTIPv6ADDR_6
|
|||||||
values forming the full IP address must be specified individually.
|
values forming the full IP address must be specified individually.
|
||||||
This is the sixth of the 8-values.
|
This is the sixth of the 8-values.
|
||||||
|
|
||||||
config EXAMPLES_NETTEST_CLIENTIPv6ADDR_7
|
config EXAMPLES_NETTEST_SERVERIPv6ADDR_7
|
||||||
hex "[6]"
|
hex "[6]"
|
||||||
default 0x0000
|
default 0x0000
|
||||||
range 0x0 0xffff
|
range 0x0 0xffff
|
||||||
---help---
|
---help---
|
||||||
IP address of the client. If the target is the client, then
|
IP address of the server. If the target is the server, then
|
||||||
EXAMPLES_NETTEST_CLIENTIP should be the same as
|
EXAMPLES_NETTEST_SERVERIP should be the same as
|
||||||
EXAMPLES_NETTEST_IPADDR (default). If the target is the server,
|
EXAMPLES_NETTEST_IPADDR (default). If the target is the client,
|
||||||
then the default value of EXAMPLES_NETTEST_CLIENTIP is set to the
|
then the default value of EXAMPLES_NETTEST_SERVERIP is set to the
|
||||||
host PC IP address (possibly the gateway address,
|
host PC IP address (possibly the gateway address,
|
||||||
EXAMPLES_NETTEST_DRIPADDR?).
|
EXAMPLES_NETTEST_DRIPADDR?).
|
||||||
|
|
||||||
@ -501,16 +555,16 @@ config EXAMPLES_NETTEST_CLIENTIPv6ADDR_7
|
|||||||
values forming the full IP address must be specified individually.
|
values forming the full IP address must be specified individually.
|
||||||
This is the seventh of the 8-values.
|
This is the seventh of the 8-values.
|
||||||
|
|
||||||
config EXAMPLES_NETTEST_CLIENTIPv6ADDR_8
|
config EXAMPLES_NETTEST_SERVERIPv6ADDR_8
|
||||||
hex "[7]"
|
hex "[7]"
|
||||||
default 0x0001 if !EXAMPLES_NETTEST_SERVER
|
default 0x0001 if !EXAMPLES_NETTEST_SERVER
|
||||||
default 0x0002 if EXAMPLES_NETTEST_SERVER
|
default 0x0002 if EXAMPLES_NETTEST_SERVER
|
||||||
range 0x0 0xffff
|
range 0x0 0xffff
|
||||||
---help---
|
---help---
|
||||||
IP address of the client. If the target is the client, then
|
IP address of the server. If the target is the server, then
|
||||||
EXAMPLES_NETTEST_CLIENTIP should be the same as
|
EXAMPLES_NETTEST_SERVERIP should be the same as
|
||||||
EXAMPLES_NETTEST_IPADDR (default). If the target is the server,
|
EXAMPLES_NETTEST_IPADDR (default). If the target is the client,
|
||||||
then the default value of EXAMPLES_NETTEST_CLIENTIP is set to the
|
then the default value of EXAMPLES_NETTEST_SERVERIP is set to the
|
||||||
host PC IP address (possibly the gateway address,
|
host PC IP address (possibly the gateway address,
|
||||||
EXAMPLES_NETTEST_DRIPADDR?).
|
EXAMPLES_NETTEST_DRIPADDR?).
|
||||||
|
|
||||||
@ -520,4 +574,9 @@ config EXAMPLES_NETTEST_CLIENTIPv6ADDR_8
|
|||||||
|
|
||||||
endif # !EXAMPLES_NETTEST_LOOPBACK
|
endif # !EXAMPLES_NETTEST_LOOPBACK
|
||||||
endif # EXAMPLES_NETTEST_IPv6
|
endif # EXAMPLES_NETTEST_IPv6
|
||||||
|
|
||||||
|
config EXAMPLES_NETTEST_SERVER_PORTNO
|
||||||
|
int "Server port number"
|
||||||
|
default 5471
|
||||||
|
|
||||||
endif # EXAMPLES_NETTEST
|
endif # EXAMPLES_NETTEST
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
############################################################################
|
############################################################################
|
||||||
# examples/nettest/Makefile
|
# examples/nettest/Makefile
|
||||||
#
|
#
|
||||||
# Copyright (C) 2007-2008, 2010-2012 Gregory Nutt. All rights reserved.
|
# Copyright (C) 2007-2008, 2010-2012, 2017 Gregory Nutt. All rights reserved.
|
||||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
@ -39,27 +39,94 @@ include $(APPDIR)/Make.defs
|
|||||||
|
|
||||||
# Basic TCP networking test
|
# Basic TCP networking test
|
||||||
|
|
||||||
TARG_ASRCS =
|
TARGCMN_CSRCS = nettest_cmdline.c
|
||||||
TARG_AOBJS = $(TARG_ASRCS:.S=$(OBJEXT))
|
ifeq ($(CONFIG_EXAMPLES_NETTEST_INIT),y)
|
||||||
|
TARGCMN_CSRCS += nettest_netinit.c
|
||||||
TARG_CSRCS =
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y)
|
|
||||||
TARG_CSRCS += nettest_server.c nettest_client.c
|
|
||||||
else ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER),y)
|
|
||||||
TARG_CSRCS += nettest_server.c
|
|
||||||
else
|
|
||||||
TARG_CSRCS += nettest_client.c
|
|
||||||
endif
|
endif
|
||||||
TARG_MAINSRC = nettest.c
|
|
||||||
|
|
||||||
TARG_COBJS = $(TARG_CSRCS:.c=$(OBJEXT))
|
TARGCMN_COBJS = $(TARGCMN_CSRCS:.c=$(OBJEXT))
|
||||||
TARG_MAINOBJ = $(TARG_MAINSRC:.c=$(OBJEXT))
|
|
||||||
|
|
||||||
TARG_SRCS = $(TARG_ASRCS) $(TARG_CSRCS) $(TARG_CSRCS)
|
# Target 1 Files
|
||||||
TARG_OBJS = $(TARG_AOBJS) $(TARG_COBJS)
|
|
||||||
|
TARG1_CSRCS =
|
||||||
|
ifeq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y)
|
||||||
|
TARG1_CSRCS += nettest_server.c nettest_client.c
|
||||||
|
else ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER),y)
|
||||||
|
TARG1_CSRCS += nettest_server.c
|
||||||
|
else
|
||||||
|
TARG1_CSRCS += nettest_client.c
|
||||||
|
endif
|
||||||
|
TARG1_MAINSRC = nettest_target1.c
|
||||||
|
|
||||||
|
TARG1_COBJS = $(TARG1_CSRCS:.c=$(OBJEXT))
|
||||||
|
TARG1_MAINOBJ = $(TARG1_MAINSRC:.c=$(OBJEXT))
|
||||||
|
|
||||||
|
TARG_CSRCS = $(TARG1_CSRCS) $(TARG1_CSRCS) $(TARGCMN_CSRCS)
|
||||||
|
TARG_OBJS = $(TARG1_COBJS) $(TARGCMN_COBJS)
|
||||||
|
|
||||||
|
# Target 1 Application Info
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER1),y)
|
||||||
|
CONFIG_EXAMPLES_NETTEST_PROGNAME1 ?= tcpserver
|
||||||
|
APPNAME1 = tcpserver
|
||||||
|
else
|
||||||
|
CONFIG_EXAMPLES_NETTEST_PROGNAME1 ?= tcpclient
|
||||||
|
APPNAME1 = tcpclient
|
||||||
|
endif
|
||||||
|
CONFIG_EXAMPLES_NETTEST_PRIORITY1 ?= 100
|
||||||
|
CONFIG_EXAMPLES_NETTEST_STACKSIZE1 ?= 2048
|
||||||
|
|
||||||
|
PROGNAME1 = $(CONFIG_EXAMPLES_NETTEST_PROGNAME1)
|
||||||
|
PRIORITY1 = $(CONFIG_EXAMPLES_NETTEST_PRIORITY1)
|
||||||
|
STACKSIZE1 = $(CONFIG_EXAMPLES_NETTEST_STACKSIZE1)
|
||||||
|
|
||||||
|
# Target 2
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_EXAMPLES_NETTEST_TARGET2),y)
|
||||||
|
|
||||||
|
TARG2_CSRCS =
|
||||||
|
ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER1),y)
|
||||||
|
TARG2_CSRCS += nettest_client.c
|
||||||
|
else
|
||||||
|
TARG2_CSRCS += nettest_server.c
|
||||||
|
endif
|
||||||
|
TARG2_MAINSRC = nettest_target2.c
|
||||||
|
|
||||||
|
TARG2_COBJS = $(TARG2_CSRCS:.c=$(OBJEXT))
|
||||||
|
TARG2_MAINOBJ = $(TARG2_MAINSRC:.c=$(OBJEXT))
|
||||||
|
|
||||||
|
# Target 2 Application Info
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER1),y)
|
||||||
|
CONFIG_EXAMPLES_NETTEST_PROGNAME2 ?= tcpclient
|
||||||
|
APPNAME2 = tcpclient
|
||||||
|
else
|
||||||
|
CONFIG_EXAMPLES_NETTEST_PROGNAME2 ?= tcpserver
|
||||||
|
APPNAME2 = tcpserver
|
||||||
|
endif
|
||||||
|
CONFIG_EXAMPLES_NETTEST_PRIORITY2 ?= 100
|
||||||
|
CONFIG_EXAMPLES_NETTEST_STACKSIZE2 ?= 2048
|
||||||
|
|
||||||
|
PROGNAME2 = $(CONFIG_EXAMPLES_NETTEST_PROGNAME2)
|
||||||
|
PRIORITY2 = $(CONFIG_EXAMPLES_NETTEST_PRIORITY2)
|
||||||
|
STACKSIZE2 = $(CONFIG_EXAMPLES_NETTEST_STACKSIZE2)
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
|
# All targets
|
||||||
|
|
||||||
|
TARG_SRCS = $(TARG1_CRCS) $(TARG1_MAINSRC) $(TARG2_CSRCS) $(TARG2_MAINSRC) $(TARGCMN_CSRCS)
|
||||||
|
TARG_OBJS = $(TARG1_COBJS) $(TARG2_COBJS) $(TARGCMN_COBJS)
|
||||||
|
|
||||||
ifneq ($(CONFIG_BUILD_KERNEL),y)
|
ifneq ($(CONFIG_BUILD_KERNEL),y)
|
||||||
TARG_OBJS += $(TARG_MAINOBJ)
|
TARG_OBJS += $(TARG1_MAINOBJ) $(TARG2_MAINOBJ)
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_EXAMPLES_NETTEST_TARGET2),y)
|
||||||
|
MAINNAME1 = nettest1_main
|
||||||
|
MAINNAME2 = nettest2_main
|
||||||
|
else
|
||||||
|
MAINNAME1 = nettest_main
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||||
@ -72,25 +139,32 @@ else
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# Host
|
||||||
|
|
||||||
|
ifneq ($(CONFIG_EXAMPLES_NETTEST_TARGET2),y)
|
||||||
ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y)
|
ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y)
|
||||||
|
|
||||||
HOSTCFLAGS += -DNETTEST_HOST=1
|
HOSTCFLAGS += -DNETTEST_HOST=1
|
||||||
ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER),y)
|
ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER),y)
|
||||||
HOSTCFLAGS += -DCONFIG_EXAMPLES_NETTEST_SERVER=1 -DCONFIG_EXAMPLES_NETTEST_CLIENTIP="$(CONFIG_EXAMPLES_NETTEST_CLIENTIP)"
|
HOSTCFLAGS += -DCONFIG_EXAMPLES_NETTEST_SERVER=1 -DCONFIG_EXAMPLES_NETTEST_SERVERIP="$(CONFIG_EXAMPLES_NETTEST_SERVERIP)"
|
||||||
endif
|
endif
|
||||||
ifeq ($(CONFIG_EXAMPLES_NETTEST_PERFORMANCE),y)
|
ifeq ($(CONFIG_EXAMPLES_NETTEST_PERFORMANCE),y)
|
||||||
HOSTCFLAGS += -DCONFIG_EXAMPLES_NETTEST_PERFORMANCE=1
|
HOSTCFLAGS += -DCONFIG_EXAMPLES_NETTEST_PERFORMANCE=1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
HOST_SRCS = host.c
|
HOST_SRCS = nettest_host.c
|
||||||
ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER),y)
|
ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER),y)
|
||||||
HOST_SRCS += nettest_client.c
|
HOST_SRCS += nettest_client.c
|
||||||
|
HOST_BIN = tcpclient$(EXEEXT)
|
||||||
else
|
else
|
||||||
HOST_SRCS += nettest_server.c
|
HOST_SRCS += nettest_server.c
|
||||||
|
HOST_BIN = tcpserver$(EXEEXT)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
HOSTOBJEXT ?= .hobj
|
HOSTOBJEXT ?= hobj
|
||||||
HOST_OBJS = $(HOST_SRCS:.c=$(HOSTOBJEXT))
|
HOST_OBJS = $(HOST_SRCS:.c=.$(HOSTOBJEXT))
|
||||||
HOST_BIN = host
|
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(WINTOOL),y)
|
ifeq ($(WINTOOL),y)
|
||||||
@ -101,45 +175,38 @@ endif
|
|||||||
|
|
||||||
ROOTDEPPATH = --dep-path .
|
ROOTDEPPATH = --dep-path .
|
||||||
|
|
||||||
# NET test built-in application info
|
|
||||||
|
|
||||||
CONFIG_EXAMPLES_NETTEST_STACKSIZE ?= 2048
|
|
||||||
CONFIG_EXAMPLES_NETTEST_PRIORITY ?= 100
|
|
||||||
|
|
||||||
APPNAME = nettest
|
|
||||||
PRIORITY = $(CONFIG_EXAMPLES_NETTEST_PRIORITY)
|
|
||||||
STACKSIZE = $(CONFIG_EXAMPLES_NETTEST_STACKSIZE)
|
|
||||||
|
|
||||||
CONFIG_EXAMPLES_NETTEST_PROGNAME ?= nettest$(EXEEXT)
|
|
||||||
PROGNAME = $(CONFIG_EXAMPLES_HELLO_PROGNAME)
|
|
||||||
|
|
||||||
# Common build
|
# Common build
|
||||||
|
|
||||||
VPATH =
|
VPATH =
|
||||||
|
|
||||||
all: .built $(HOST_BIN)
|
all: .built $(HOST_BIN)
|
||||||
.PHONY: clean depend distclean
|
.PHONY: clean depend distclean preconfig
|
||||||
|
|
||||||
$(TARG_AOBJS): %$(OBJEXT): %.S
|
$(TARG1_COBJS) $(TARG1_MAINOBJ) $(TARG2_COBJS) $(TARG2_MAINOBJ) $(TARGCMN_COBJS) : %$(OBJEXT): %.c
|
||||||
$(call ASSEMBLE, $<, $@)
|
|
||||||
|
|
||||||
$(TARG_COBJS) $(TARG_MAINOBJ): %$(OBJEXT): %.c
|
|
||||||
$(call COMPILE, $<, $@)
|
$(call COMPILE, $<, $@)
|
||||||
|
|
||||||
|
ifneq ($(CONFIG_EXAMPLES_NETTEST_TARGET2),y)
|
||||||
ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y)
|
ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y)
|
||||||
$(HOST_OBJS): %$(HOSTOBJEXT): %.c
|
|
||||||
|
$(HOST_OBJS): %.$(HOSTOBJEXT): %.c
|
||||||
@echo "CC: $<"
|
@echo "CC: $<"
|
||||||
$(Q) $(HOSTCC) -c $(HOSTCFLAGS) $< -o $@
|
$(Q) $(HOSTCC) -c $(HOSTCFLAGS) $< -o $@
|
||||||
|
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
config.h: $(TOPDIR)/include/nuttx/config.h
|
config.h: $(TOPDIR)/include/nuttx/config.h
|
||||||
@echo "CP: $<"
|
@echo "CP: $<"
|
||||||
$(Q) cp $< $@
|
$(Q) cp $< $@
|
||||||
|
|
||||||
|
ifneq ($(CONFIG_EXAMPLES_NETTEST_TARGET2),y)
|
||||||
ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y)
|
ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y)
|
||||||
|
|
||||||
$(HOST_BIN): config.h $(HOST_OBJS)
|
$(HOST_BIN): config.h $(HOST_OBJS)
|
||||||
@echo "LD: $@"
|
@echo "LD: $@"
|
||||||
$(Q) $(HOSTCC) $(HOSTLDFLAGS) $(HOST_OBJS) -o $@
|
$(Q) $(HOSTCC) $(HOSTLDFLAGS) $(HOST_OBJS) -o $@
|
||||||
|
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
.built: config.h $(TARG_OBJS)
|
.built: config.h $(TARG_OBJS)
|
||||||
@ -147,12 +214,12 @@ endif
|
|||||||
$(Q) touch .built
|
$(Q) touch .built
|
||||||
|
|
||||||
ifeq ($(CONFIG_BUILD_KERNEL),y)
|
ifeq ($(CONFIG_BUILD_KERNEL),y)
|
||||||
$(BIN_DIR)$(DELIM)$(PROGNAME): $(OBJS) $(TARG_MAINOBJ)
|
$(BIN_DIR)$(DELIM)$(PROGNAME1): $(OBJS) $(TARG1_MAINOBJ)
|
||||||
@echo "LD: $(PROGNAME)"
|
@echo "LD: $(PROGNAME1)"
|
||||||
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(PROGNAME) $(ARCHCRT0OBJ) $(TARG_MAINOBJ) $(LDLIBS)
|
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(PROGNAME1) $(ARCHCRT0OBJ) $(TARG1_MAINOBJ) $(LDLIBS)
|
||||||
$(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(PROGNAME)
|
$(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(PROGNAME1)
|
||||||
|
|
||||||
install: $(BIN_DIR)$(DELIM)$(PROGNAME)
|
install: $(BIN_DIR)$(DELIM)$(PROGNAME1)
|
||||||
|
|
||||||
else
|
else
|
||||||
install:
|
install:
|
||||||
@ -160,24 +227,34 @@ install:
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME1)_main.bdat: $(DEPCONFIG) Makefile
|
||||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
$(call REGISTER,$(APPNAME1),$(PRIORITY1),$(STACKSIZE1),$(MAINNAME1))
|
||||||
|
|
||||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
ifeq ($(CONFIG_EXAMPLES_NETTEST_TARGET2),y)
|
||||||
|
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME2)_main.bdat: $(DEPCONFIG) Makefile
|
||||||
|
$(call REGISTER,$(APPNAME2),$(PRIORITY2),$(STACKSIZE2),$(MAINNAME2))
|
||||||
|
|
||||||
|
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME1)_main.bdat \
|
||||||
|
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME2)_main.bdat
|
||||||
|
else
|
||||||
|
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME1)_main.bdat
|
||||||
|
endif
|
||||||
else
|
else
|
||||||
context:
|
context:
|
||||||
endif
|
endif
|
||||||
|
|
||||||
.depend: Makefile config.h $(TARG_SRCS)
|
.depend: Makefile config.h $(TARG_CSRCS)
|
||||||
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(TARG_SRCS) >Make.dep
|
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(TARG_CSRCS) >Make.dep
|
||||||
@touch $@
|
@touch $@
|
||||||
|
|
||||||
depend: .depend
|
depend: .depend
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
ifneq ($(CONFIG_EXAMPLES_NETTEST_TARGET2),y)
|
||||||
ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y)
|
ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y)
|
||||||
$(call DELFILE, *$(HOSTOBJEXT))
|
$(call DELFILE, *.$(HOSTOBJEXT))
|
||||||
$(call DELFILE, $(HOST_BIN))
|
$(call DELFILE, $(HOST_BIN))
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
$(call DELFILE, .built)
|
$(call DELFILE, .built)
|
||||||
$(call DELFILE, *.dSYM)
|
$(call DELFILE, *.dSYM)
|
||||||
@ -188,7 +265,6 @@ distclean: clean
|
|||||||
$(call DELFILE, Make.dep)
|
$(call DELFILE, Make.dep)
|
||||||
$(call DELFILE, .depend)
|
$(call DELFILE, .depend)
|
||||||
|
|
||||||
-include Make.dep
|
|
||||||
|
|
||||||
.PHONY: preconfig
|
|
||||||
preconfig:
|
preconfig:
|
||||||
|
|
||||||
|
-include Make.dep
|
||||||
|
@ -77,14 +77,36 @@
|
|||||||
# define PF_INETX PF_INET
|
# define PF_INETX PF_INET
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define PORTNO 5471
|
#ifndef CONFIG_EXAMPLES_NETTEST_SERVER_PORTNO
|
||||||
#define SENDSIZE 4096
|
# define CONFIG_EXAMPLES_NETTEST_SERVER_PORTNO 5471
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLES_NETTEST_SENDSIZE
|
||||||
|
# define SENDSIZE CONFIG_EXAMPLES_NETTEST_SENDSIZE
|
||||||
|
#else
|
||||||
|
# define SENDSIZE 4096
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLES_NETTEST_IPv6
|
||||||
|
uint16_t g_nettestserver_ipv6[8];
|
||||||
|
#else
|
||||||
|
uint32_t g_nettestserver_ipv4;
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Function Prototypes
|
* Public Function Prototypes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
extern void send_client(void);
|
#ifdef CONFIG_EXAMPLES_NETTEST_INIT
|
||||||
extern void recv_server(void);
|
void nettest_initialize(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void nettest_cmdline(int argc, char **argv);
|
||||||
|
extern void nettest_client(void);
|
||||||
|
extern void nettest_server(void);
|
||||||
|
|
||||||
#endif /* __EXAMPLES_NETTEST_H */
|
#endif /* __EXAMPLES_NETTEST_H */
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* examples/nettest/nettest-client.c
|
* examples/nettest/nettest_client.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007, 2011-2012, 2015 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007, 2011-2012, 2015 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
@ -56,12 +56,12 @@
|
|||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void send_client(void)
|
void nettest_client(void)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_EXAMPLES_NETTEST_IPv6
|
#ifdef CONFIG_EXAMPLES_NETTEST_IPv6
|
||||||
struct sockaddr_in6 myaddr;
|
struct sockaddr_in6 server;
|
||||||
#else
|
#else
|
||||||
struct sockaddr_in myaddr;
|
struct sockaddr_in server;
|
||||||
#endif
|
#endif
|
||||||
char *outbuf;
|
char *outbuf;
|
||||||
#ifndef CONFIG_EXAMPLES_NETTEST_PERFORMANCE
|
#ifndef CONFIG_EXAMPLES_NETTEST_PERFORMANCE
|
||||||
@ -100,56 +100,29 @@ void send_client(void)
|
|||||||
goto errout_with_buffers;
|
goto errout_with_buffers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Connect the socket to the server */
|
/* Set up the server address */
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_NETTEST_IPv6
|
#ifdef CONFIG_EXAMPLES_NETTEST_IPv6
|
||||||
myaddr.sin6_family = AF_INET6;
|
server.sin6_family = AF_INET6;
|
||||||
myaddr.sin6_port = HTONS(PORTNO);
|
server.sin6_port = HTONS(CONFIG_EXAMPLES_NETTEST_SERVER_PORTNO);
|
||||||
|
memcpy(server.sin6_addr.s6_addr16, g_nettestserver_ipv6, 8 * sizeof(uint16_t));
|
||||||
|
addrlen = sizeof(struct sockaddr_in6);
|
||||||
|
|
||||||
#if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK) && defined(NET_LOOPBACK)
|
printf("Connecting to IPv6 Address: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
|
||||||
myaddr.sin6_addr.s6_addr16[0] = 0; /* Use the loopback address */
|
g_nettestserver_ipv6[0], g_nettestserver_ipv6[1], g_nettestserver_ipv6[2], g_nettestserver_ipv6[3],
|
||||||
myaddr.sin6_addr.s6_addr16[1] = 0;
|
g_nettestserver_ipv6[4], g_nettestserver_ipv6[5], g_nettestserver_ipv6[6], g_nettestserver_ipv6[7]);
|
||||||
myaddr.sin6_addr.s6_addr16[2] = 0;
|
|
||||||
myaddr.sin6_addr.s6_addr16[3] = 0;
|
|
||||||
myaddr.sin6_addr.s6_addr16[4] = 0;
|
|
||||||
myaddr.sin6_addr.s6_addr16[5] = 0;
|
|
||||||
myaddr.sin6_addr.s6_addr16[6] = 0;
|
|
||||||
myaddr.sin6_addr.s6_addr16[7] = HTONS(1);
|
|
||||||
#else
|
#else
|
||||||
myaddr.sin6_addr.s6_addr16[0] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_1);
|
server.sin_family = AF_INET;
|
||||||
myaddr.sin6_addr.s6_addr16[1] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_2);
|
server.sin_port = HTONS(CONFIG_EXAMPLES_NETTEST_SERVER_PORTNO);
|
||||||
myaddr.sin6_addr.s6_addr16[2] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_3);
|
server.sin_addr.s_addr = (in_addr_t)g_nettestserver_ipv4;
|
||||||
myaddr.sin6_addr.s6_addr16[3] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_4);
|
addrlen = sizeof(struct sockaddr_in);
|
||||||
myaddr.sin6_addr.s6_addr16[4] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_5);
|
|
||||||
myaddr.sin6_addr.s6_addr16[5] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_6);
|
printf("Connecting to IPv4 Address: %08lx\n", (unsigned long)g_nettestserver_ipv4);
|
||||||
myaddr.sin6_addr.s6_addr16[6] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_7);
|
|
||||||
myaddr.sin6_addr.s6_addr16[7] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_8);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
printf("IPv6 Address: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
|
/* Connect the socket to the server */
|
||||||
myaddr.sin6_addr.s6_addr16[0], myaddr.sin6_addr.s6_addr16[1],
|
|
||||||
myaddr.sin6_addr.s6_addr16[2], myaddr.sin6_addr.s6_addr16[3],
|
|
||||||
myaddr.sin6_addr.s6_addr16[4], myaddr.sin6_addr.s6_addr16[5],
|
|
||||||
myaddr.sin6_addr.s6_addr16[6], myaddr.sin6_addr.s6_addr16[7]);
|
|
||||||
|
|
||||||
addrlen = sizeof(struct sockaddr_in6);
|
if (connect( sockfd, (struct sockaddr*)&server, addrlen) < 0)
|
||||||
#else
|
|
||||||
myaddr.sin_family = AF_INET;
|
|
||||||
myaddr.sin_port = HTONS(PORTNO);
|
|
||||||
|
|
||||||
#if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK) && defined(NET_LOOPBACK)
|
|
||||||
myaddr.sin_addr.s_addr = HTONL(0x7f000001);
|
|
||||||
#else
|
|
||||||
myaddr.sin_addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_CLIENTIP);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
printf("IPv4 Address: %08x\n", myaddr.sin_addr.s_addr);
|
|
||||||
|
|
||||||
addrlen = sizeof(struct sockaddr_in);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
printf("client: Connecting...\n");
|
|
||||||
if (connect( sockfd, (struct sockaddr*)&myaddr, addrlen) < 0)
|
|
||||||
{
|
{
|
||||||
printf("client: connect failure: %d\n", errno);
|
printf("client: connect failure: %d\n", errno);
|
||||||
goto errout_with_socket;
|
goto errout_with_socket;
|
||||||
@ -240,6 +213,7 @@ void send_client(void)
|
|||||||
goto errout_with_socket;
|
goto errout_with_socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("client: Terminating\n");
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
free(outbuf);
|
free(outbuf);
|
||||||
#ifndef CONFIG_EXAMPLES_NETTEST_PERFORMANCE
|
#ifndef CONFIG_EXAMPLES_NETTEST_PERFORMANCE
|
||||||
|
137
examples/nettest/nettest_cmdline.c
Normal file
137
examples/nettest/nettest_cmdline.c
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* examples/nettest/netest_cmdline.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
#include "nettest.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLES_NETTEST_IPv6
|
||||||
|
|
||||||
|
uint16_t g_nettestserver_ipv6[8] =
|
||||||
|
{
|
||||||
|
#if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK) && defined(NET_LOOPBACK)
|
||||||
|
0 /* Use the loopback address */
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
HTONS(1);
|
||||||
|
#else
|
||||||
|
HTONS(CONFIG_EXAMPLES_NETTEST_SERVERIPv6ADDR_1),
|
||||||
|
HTONS(CONFIG_EXAMPLES_NETTEST_SERVERIPv6ADDR_2),
|
||||||
|
HTONS(CONFIG_EXAMPLES_NETTEST_SERVERIPv6ADDR_3),
|
||||||
|
HTONS(CONFIG_EXAMPLES_NETTEST_SERVERIPv6ADDR_4),
|
||||||
|
HTONS(CONFIG_EXAMPLES_NETTEST_SERVERIPv6ADDR_5),
|
||||||
|
HTONS(CONFIG_EXAMPLES_NETTEST_SERVERIPv6ADDR_6),
|
||||||
|
HTONS(CONFIG_EXAMPLES_NETTEST_SERVERIPv6ADDR_7),
|
||||||
|
HTONS(CONFIG_EXAMPLES_NETTEST_SERVERIPv6ADDR_8)
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK) && defined(NET_LOOPBACK)
|
||||||
|
uint32_t g_nettestserver_ipv4 = HTONL(0x7f000001);
|
||||||
|
#else
|
||||||
|
uint32_t g_nettestserver_ipv4 = HTONL(CONFIG_EXAMPLES_NETTEST_SERVERIP);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* show_usage
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static void show_usage(FAR const char *progname)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "USAGE: %s [<server-addr>]\n", progname);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* nettest_cmdline
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void nettest_cmdline(int argc, char **argv)
|
||||||
|
{
|
||||||
|
/* Currently only a single command line option is supported: The server
|
||||||
|
* IP address.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (argc == 2)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* Convert the <server-addr> argument into a binary address */
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLES_NETTEST_IPv6
|
||||||
|
ret = inet_pton(AF_INET6, argv[1], g_nettestserver_ipv6);
|
||||||
|
#else
|
||||||
|
ret = inet_pton(AF_INET, argv[1], &g_nettestserver_ipv4);
|
||||||
|
#endif
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: <server-addr> is invalid\n");
|
||||||
|
show_usage(argv[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (argc != 1)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: Too many arguments\n");
|
||||||
|
show_usage(argv[0]);
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* examples/nettest/host.c
|
* examples/nettest/nettest_host.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
@ -55,9 +55,9 @@
|
|||||||
int main(int argc, char **argv, char **envp)
|
int main(int argc, char **argv, char **envp)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_EXAMPLES_NETTEST_SERVER
|
#ifdef CONFIG_EXAMPLES_NETTEST_SERVER
|
||||||
send_client();
|
nettest_client();
|
||||||
#else
|
#else
|
||||||
recv_server();
|
nettest_server();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* examples/nettest/nettest.c
|
* examples/nettest/nettest_netinit.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007, 2009-2011, 2015 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007, 2009-2011, 2015, 2017 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -38,28 +38,31 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
//#include <nuttx/config.h>
|
|
||||||
|
|
||||||
#include <sys/wait.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <sched.h>
|
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
#include <net/if.h>
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
#include "netutils/netlib.h"
|
#include "netutils/netlib.h"
|
||||||
|
|
||||||
#include "nettest.h"
|
#include "nettest.h"
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLES_NETTEST_INIT
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLES_NETTEST_DEVNAME
|
||||||
|
# define DEVNAME CONFIG_EXAMPLES_NETTEST_DEVNAME
|
||||||
|
#else
|
||||||
|
# define DEVNAME "eth0"
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Data
|
* Private Data
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -111,11 +114,10 @@ static const uint16_t g_ipv6_netmask[8] =
|
|||||||
#endif /* CONFIG_EXAMPLES_NETTEST_INIT && CONFIG_EXAMPLES_NETTEST_IPv6 && !CONFIG_NET_ICMPv6_AUTOCONF */
|
#endif /* CONFIG_EXAMPLES_NETTEST_INIT && CONFIG_EXAMPLES_NETTEST_IPv6 && !CONFIG_NET_ICMPv6_AUTOCONF */
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_NETTEST_INIT
|
void nettest_initialize(void)
|
||||||
static void netest_initialize(void)
|
|
||||||
{
|
{
|
||||||
#ifndef CONFIG_EXAMPLES_NETTEST_IPv6
|
#ifndef CONFIG_EXAMPLES_NETTEST_IPv6
|
||||||
struct in_addr addr;
|
struct in_addr addr;
|
||||||
@ -133,37 +135,37 @@ static void netest_initialize(void)
|
|||||||
mac[3] = 0xad;
|
mac[3] = 0xad;
|
||||||
mac[4] = 0xbe;
|
mac[4] = 0xbe;
|
||||||
mac[5] = 0xef;
|
mac[5] = 0xef;
|
||||||
netlib_setmacaddr("eth0", mac);
|
netlib_setmacaddr(DEVNAME, mac);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_NETTEST_IPv6
|
#ifdef CONFIG_EXAMPLES_NETTEST_IPv6
|
||||||
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
|
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
|
||||||
/* Perform ICMPv6 auto-configuration */
|
/* Perform ICMPv6 auto-configuration */
|
||||||
|
|
||||||
netlib_icmpv6_autoconfiguration("eth0");
|
netlib_icmpv6_autoconfiguration(DEVNAME);
|
||||||
|
|
||||||
#else /* CONFIG_NET_ICMPv6_AUTOCONF */
|
#else /* CONFIG_NET_ICMPv6_AUTOCONF */
|
||||||
|
|
||||||
/* Set up our fixed host address */
|
/* Set up our fixed host address */
|
||||||
|
|
||||||
netlib_set_ipv6addr("eth0",
|
netlib_set_ipv6addr(DEVNAME,
|
||||||
(FAR const struct in6_addr *)g_ipv6_hostaddr);
|
(FAR const struct in6_addr *)g_ipv6_hostaddr);
|
||||||
|
|
||||||
/* Set up the default router address */
|
/* Set up the default router address */
|
||||||
|
|
||||||
netlib_set_dripv6addr("eth0",
|
netlib_set_dripv6addr(DEVNAME,
|
||||||
(FAR const struct in6_addr *)g_ipv6_draddr);
|
(FAR const struct in6_addr *)g_ipv6_draddr);
|
||||||
|
|
||||||
/* Setup the subnet mask */
|
/* Setup the subnet mask */
|
||||||
|
|
||||||
netlib_set_ipv6netmask("eth0",
|
netlib_set_ipv6netmask(DEVNAME,
|
||||||
(FAR const struct in6_addr *)g_ipv6_netmask);
|
(FAR const struct in6_addr *)g_ipv6_netmask);
|
||||||
|
|
||||||
/* New versions of netlib_set_ipvXaddr will not bring the network up,
|
/* New versions of netlib_set_ipvXaddr will not bring the network up,
|
||||||
* So ensure the network is really up at this point.
|
* So ensure the network is really up at this point.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
netlib_ifup("eth0");
|
netlib_ifup(DEVNAME);
|
||||||
|
|
||||||
#endif /* CONFIG_NET_ICMPv6_AUTOCONF */
|
#endif /* CONFIG_NET_ICMPv6_AUTOCONF */
|
||||||
#else /* CONFIG_EXAMPLES_NETTEST_IPv6 */
|
#else /* CONFIG_EXAMPLES_NETTEST_IPv6 */
|
||||||
@ -171,88 +173,20 @@ static void netest_initialize(void)
|
|||||||
/* Set up our host address */
|
/* Set up our host address */
|
||||||
|
|
||||||
addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_IPADDR);
|
addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_IPADDR);
|
||||||
netlib_set_ipv4addr("eth0", &addr);
|
netlib_set_ipv4addr(DEVNAME, &addr);
|
||||||
|
|
||||||
/* Set up the default router address */
|
/* Set up the default router address */
|
||||||
|
|
||||||
addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_DRIPADDR);
|
addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_DRIPADDR);
|
||||||
netlib_set_dripv4addr("eth0", &addr);
|
netlib_set_dripv4addr(DEVNAME, &addr);
|
||||||
|
|
||||||
/* Setup the subnet mask */
|
/* Setup the subnet mask */
|
||||||
|
|
||||||
addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_NETMASK);
|
addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_NETMASK);
|
||||||
netlib_set_ipv4netmask("eth0", &addr);
|
netlib_set_ipv4netmask(DEVNAME, &addr);
|
||||||
|
|
||||||
#endif /* CONFIG_EXAMPLES_NETTEST_IPv6 */
|
#endif /* CONFIG_EXAMPLES_NETTEST_IPv6 */
|
||||||
}
|
}
|
||||||
#endif /*CONFIG_EXAMPLES_NETTEST_INIT */
|
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_NETTEST_LOOPBACK
|
#endif /* CONFIG_EXAMPLES_NETTEST_INIT */
|
||||||
static int server_child(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
recv_server();
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* nettest_main
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#ifdef CONFIG_BUILD_KERNEL
|
|
||||||
int main(int argc, FAR char *argv[])
|
|
||||||
#else
|
|
||||||
int nettest_main(int argc, char *argv[])
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
#ifdef CONFIG_EXAMPLES_NETTEST_LOOPBACK
|
|
||||||
pid_t child;
|
|
||||||
#ifdef CONFIG_SCHED_WAITPID
|
|
||||||
int statloc;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_NETTEST_INIT
|
|
||||||
/* Initialize the network */
|
|
||||||
|
|
||||||
netest_initialize();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK)
|
|
||||||
/* Then perform the server side of the test on a child task */
|
|
||||||
|
|
||||||
child = task_create("Nettest Child", CONFIG_EXAMPLES_NETTEST_SERVER_PRIORITY,
|
|
||||||
CONFIG_EXAMPLES_NETTEST_SERVER_STACKSIZE, server_child,
|
|
||||||
NULL);
|
|
||||||
if (child < 0)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "ERROR: Failed to server daemon\n");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
usleep(500*1000);
|
|
||||||
|
|
||||||
#elif defined(CONFIG_EXAMPLES_NETTEST_SERVER)
|
|
||||||
/* Then perform the server side of the test on this thread */
|
|
||||||
|
|
||||||
recv_server();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(CONFIG_EXAMPLES_NETTEST_SERVER) || \
|
|
||||||
defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK)
|
|
||||||
/* Then perform the client side of the test on this thread */
|
|
||||||
|
|
||||||
send_client();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK) && defined(CONFIG_SCHED_WAITPID)
|
|
||||||
printf("main: Waiting for the server to exit\n");
|
|
||||||
(void)waitpid(child, &statloc, 0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
@ -57,7 +57,7 @@
|
|||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void recv_server(void)
|
void nettest_server(void)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_EXAMPLES_NETTEST_IPv6
|
#ifdef CONFIG_EXAMPLES_NETTEST_IPv6
|
||||||
struct sockaddr_in6 myaddr;
|
struct sockaddr_in6 myaddr;
|
||||||
@ -112,33 +112,32 @@ void recv_server(void)
|
|||||||
#ifdef CONFIG_EXAMPLES_NETTEST_IPv6
|
#ifdef CONFIG_EXAMPLES_NETTEST_IPv6
|
||||||
|
|
||||||
myaddr.sin6_family = AF_INET6;
|
myaddr.sin6_family = AF_INET6;
|
||||||
myaddr.sin6_port = HTONS(PORTNO);
|
myaddr.sin6_port = HTONS(CONFIG_EXAMPLES_NETTEST_SERVER_PORTNO);
|
||||||
|
|
||||||
#if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK) && !defined(NET_LOOPBACK)
|
#if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK) && !defined(NET_LOOPBACK)
|
||||||
myaddr.sin6_addr.s6_addr16[0] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_1);
|
memcpy(myaddr.sin6_addr.s6_addr16, g_nettestserver_ipv6, 8 * sizeof(uint16_t));
|
||||||
myaddr.sin6_addr.s6_addr16[1] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_2);
|
|
||||||
myaddr.sin6_addr.s6_addr16[2] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_3);
|
|
||||||
myaddr.sin6_addr.s6_addr16[3] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_4);
|
|
||||||
myaddr.sin6_addr.s6_addr16[4] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_5);
|
|
||||||
myaddr.sin6_addr.s6_addr16[5] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_6);
|
|
||||||
myaddr.sin6_addr.s6_addr16[6] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_7);
|
|
||||||
myaddr.sin6_addr.s6_addr16[7] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_8);
|
|
||||||
#else
|
#else
|
||||||
memset(&myaddr.sin6_addr, 0, sizeof(struct in6_addr));
|
memset(myaddr.sin6_addr.s6_addr16, 0, 8 * sizeof(uint16_t));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
addrlen = sizeof(struct sockaddr_in6);
|
addrlen = sizeof(struct sockaddr_in6);
|
||||||
|
|
||||||
|
printf("Binding to IPv6 Address: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
|
||||||
|
myaddr.sin6_addr.s6_addr16[0], myaddr.sin6_addr.s6_addr16[1],
|
||||||
|
myaddr.sin6_addr.s6_addr16[2], myaddr.sin6_addr.s6_addr16[3],
|
||||||
|
myaddr.sin6_addr.s6_addr16[4], myaddr.sin6_addr.s6_addr16[5],
|
||||||
|
myaddr.sin6_addr.s6_addr16[6], myaddr.sin6_addr.s6_addr16[7]);
|
||||||
#else
|
#else
|
||||||
myaddr.sin_family = AF_INET;
|
myaddr.sin_family = AF_INET;
|
||||||
myaddr.sin_port = HTONS(PORTNO);
|
myaddr.sin_port = HTONS(CONFIG_EXAMPLES_NETTEST_SERVER_PORTNO);
|
||||||
|
|
||||||
#if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK) && !defined(NET_LOOPBACK)
|
#if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK) && !defined(NET_LOOPBACK)
|
||||||
myaddr.sin_addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_CLIENTIP);
|
myaddr.sin_addr.s_addr = (in_addr_t)g_nettestserver_ipv4;
|
||||||
#else
|
#else
|
||||||
myaddr.sin_addr.s_addr = INADDR_ANY;
|
myaddr.sin_addr.s_addr = INADDR_ANY;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
addrlen = sizeof(struct sockaddr_in);
|
addrlen = sizeof(struct sockaddr_in);
|
||||||
|
|
||||||
|
printf("Binding to IPv4 Address: %08lx\n",
|
||||||
|
(unsigned long)myaddr.sin_addr.s_addr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (bind(listensd, (struct sockaddr*)&myaddr, addrlen) < 0)
|
if (bind(listensd, (struct sockaddr*)&myaddr, addrlen) < 0)
|
||||||
@ -157,7 +156,8 @@ void recv_server(void)
|
|||||||
|
|
||||||
/* Accept only one connection */
|
/* Accept only one connection */
|
||||||
|
|
||||||
printf("server: Accepting connections on port %d\n", PORTNO);
|
printf("server: Accepting connections on port %d\n",
|
||||||
|
CONFIG_EXAMPLES_NETTEST_SERVER_PORTNO);
|
||||||
acceptsd = accept(listensd, (struct sockaddr*)&myaddr, &addrlen);
|
acceptsd = accept(listensd, (struct sockaddr*)&myaddr, &addrlen);
|
||||||
if (acceptsd < 0)
|
if (acceptsd < 0)
|
||||||
{
|
{
|
||||||
|
130
examples/nettest/nettest_target1.c
Normal file
130
examples/nettest/nettest_target1.c
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* examples/nettest/nettest_target1.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007, 2009-2011, 2015, 2017 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sched.h>
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
|
#include "nettest.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLES_NETTEST_LOOPBACK
|
||||||
|
static int server_child(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
nettest_server();
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* nettest_main
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#if defined(CONFIG_BUILD_KERNEL)
|
||||||
|
int main(int argc, FAR char *argv[])
|
||||||
|
#elif defined(CONFIG_EXAMPLES_NETTEST_TARGET2)
|
||||||
|
int nettest1_main(int argc, char *argv[])
|
||||||
|
#else
|
||||||
|
int nettest_main(int argc, char *argv[])
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
#ifdef CONFIG_EXAMPLES_NETTEST_LOOPBACK
|
||||||
|
pid_t child;
|
||||||
|
#ifdef CONFIG_SCHED_WAITPID
|
||||||
|
int statloc;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Parse any command line options */
|
||||||
|
|
||||||
|
nettest_cmdline(argc, argv);
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLES_NETTEST_INIT
|
||||||
|
/* Initialize the network */
|
||||||
|
|
||||||
|
nettest_initialize();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK)
|
||||||
|
/* Then perform the server side of the test on a child task */
|
||||||
|
|
||||||
|
child = task_create("Nettest Child", CONFIG_EXAMPLES_NETTEST_DAEMON_PRIORITY,
|
||||||
|
CONFIG_EXAMPLES_NETTEST_DAEMON_STACKSIZE, server_child,
|
||||||
|
NULL);
|
||||||
|
if (child < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: Failed to server daemon\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
usleep(500*1000);
|
||||||
|
|
||||||
|
#elif defined(CONFIG_EXAMPLES_NETTEST_SERVER)
|
||||||
|
/* Then perform the server side of the test on this thread */
|
||||||
|
|
||||||
|
nettest_server();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(CONFIG_EXAMPLES_NETTEST_SERVER) || \
|
||||||
|
defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK)
|
||||||
|
/* Then perform the client side of the test on this thread */
|
||||||
|
|
||||||
|
nettest_client();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK) && defined(CONFIG_SCHED_WAITPID)
|
||||||
|
printf("main: Waiting for the server to exit\n");
|
||||||
|
(void)waitpid(child, &statloc, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
75
examples/nettest/nettest_target2.c
Normal file
75
examples/nettest/nettest_target2.c
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* examples/nettest/nettest_target2.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007, 2009-2011, 2015, 2017 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "nettest.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* nettest_main
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_BUILD_KERNEL
|
||||||
|
int main(int argc, FAR char *argv[])
|
||||||
|
#else
|
||||||
|
int nettest2_main(int argc, char *argv[])
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
/* Parse any command line options */
|
||||||
|
|
||||||
|
nettest_cmdline(argc, argv);
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLES_NETTEST_INIT
|
||||||
|
/* Initialize the network */
|
||||||
|
|
||||||
|
nettest_initialize();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(CONFIG_EXAMPLES_NETTEST_SERVER)
|
||||||
|
/* Then perform the client side of the test on this thread */
|
||||||
|
|
||||||
|
nettest_client();
|
||||||
|
#else
|
||||||
|
/* Then perform the server side of the test on this thread */
|
||||||
|
|
||||||
|
nettest_server();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
@ -73,6 +73,16 @@
|
|||||||
# undef CONFIG_NSH_TELNET
|
# undef CONFIG_NSH_TELNET
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* If Telnet is used and both IPv6 and IPv4 are enabled, then we need to
|
||||||
|
* pick one.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef CONFIG_NET_IPv6
|
||||||
|
# define ADDR_FAMILY AF_INET6
|
||||||
|
#else
|
||||||
|
# define ADDR_FAMILY AF_INET
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Types
|
* Private Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -153,11 +163,14 @@ int nsh_main(int argc, char *argv[])
|
|||||||
nsh_initialize();
|
nsh_initialize();
|
||||||
|
|
||||||
/* If the Telnet console is selected as a front-end, then start the
|
/* If the Telnet console is selected as a front-end, then start the
|
||||||
* Telnet daemon.
|
* Telnet daemon UNLESS network initialization is deferred via
|
||||||
|
* CONFIG_NSH_NETLOCAL. In that case, the telnet daemon must be
|
||||||
|
* started manually with the telnetd command after the network has
|
||||||
|
* been initialized
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef CONFIG_NSH_TELNET
|
#if defined(CONFIG_NSH_TELNET) && !defined(CONFIG_NSH_NETLOCAL)
|
||||||
ret = nsh_telnetstart();
|
ret = nsh_telnetstart(ADDR_FAMILY);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
/* The daemon is NOT running. Report the error then fail...
|
/* The daemon is NOT running. Report the error then fail...
|
||||||
|
@ -71,6 +71,26 @@
|
|||||||
|
|
||||||
#include "nxterm_internal.h"
|
#include "nxterm_internal.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* The NSH telnet console requires networking support (and TCP/IP) */
|
||||||
|
|
||||||
|
#ifndef CONFIG_NET
|
||||||
|
# undef CONFIG_NSH_TELNET
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* If Telnet is used and both IPv6 and IPv4 are enabled, then we need to
|
||||||
|
* pick one.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef CONFIG_NET_IPv6
|
||||||
|
# define ADDR_FAMILY AF_INET6
|
||||||
|
#else
|
||||||
|
# define ADDR_FAMILY AF_INET
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Data
|
* Public Data
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -234,7 +254,7 @@ int nxterm_main(int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef CONFIG_NSH_TELNET
|
#ifdef CONFIG_NSH_TELNET
|
||||||
ret = nsh_telnetstart();
|
ret = nsh_telnetstart(ADDR_FAMILY);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
/* The daemon is NOT running. Report the error then fail...
|
/* The daemon is NOT running. Report the error then fail...
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* examples/telnetd/telnetd.c
|
* examples/telnetd/telnetd.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2012, 2017 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* This is a leverage of similar logic from uIP:
|
* This is a leverage of similar logic from uIP:
|
||||||
@ -53,10 +53,6 @@
|
|||||||
|
|
||||||
#include "telnetd.h"
|
#include "telnetd.h"
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Pre-processor Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Types
|
* Private Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -247,6 +243,7 @@ int telnetd_main(int argc, char *argv[])
|
|||||||
/* Configure the telnet daemon */
|
/* Configure the telnet daemon */
|
||||||
|
|
||||||
config.d_port = HTONS(23);
|
config.d_port = HTONS(23);
|
||||||
|
config.d_family = AF_INET;
|
||||||
config.d_priority = CONFIG_EXAMPLES_TELNETD_DAEMONPRIO;
|
config.d_priority = CONFIG_EXAMPLES_TELNETD_DAEMONPRIO;
|
||||||
config.d_stacksize = CONFIG_EXAMPLES_TELNETD_DAEMONSTACKSIZE;
|
config.d_stacksize = CONFIG_EXAMPLES_TELNETD_DAEMONSTACKSIZE;
|
||||||
config.t_priority = CONFIG_EXAMPLES_TELNETD_CLIENTPRIO;
|
config.t_priority = CONFIG_EXAMPLES_TELNETD_CLIENTPRIO;
|
||||||
|
@ -42,7 +42,7 @@ config EXAMPLES_UDP_TARGET2
|
|||||||
By default, the host PC is configured as the second endpoint of the
|
By default, the host PC is configured as the second endpoint of the
|
||||||
UDP test. If this option is selected, then the second endpoint
|
UDP test. If this option is selected, then the second endpoint
|
||||||
will be built into the FLASH image as well. This means that you
|
will be built into the FLASH image as well. This means that you
|
||||||
can use two target boards to run the test with not host PC
|
can use two target boards to run the test with no host PC
|
||||||
involvement.
|
involvement.
|
||||||
|
|
||||||
if EXAMPLES_UDP_TARGET2
|
if EXAMPLES_UDP_TARGET2
|
||||||
@ -512,11 +512,11 @@ config EXAMPLES_UDP_SERVERIPv6ADDR_8
|
|||||||
|
|
||||||
endif # EXAMPLES_UDP_IPv6
|
endif # EXAMPLES_UDP_IPv6
|
||||||
|
|
||||||
config EXAMPLES_SERVER_PORTNO
|
config EXAMPLES_UDP_SERVER_PORTNO
|
||||||
int "Server port number"
|
int "Server port number"
|
||||||
default 5471
|
default 5471
|
||||||
|
|
||||||
config EXAMPLES_CLIENT_PORTNO
|
config EXAMPLES_UDP_CLIENT_PORTNO
|
||||||
int "Client port number"
|
int "Client port number"
|
||||||
default 5472
|
default 5472
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
############################################################################
|
############################################################################
|
||||||
# apps/examples/udp/Makefile
|
# apps/examples/udp/Makefile
|
||||||
#
|
#
|
||||||
# Copyright (C) 2007-2008, 2011-2012, 2014 Gregory Nutt. All rights reserved.
|
# Copyright (C) 2007-2008, 2011-2012, 2014, 2017 Gregory Nutt. All rights reserved.
|
||||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
#
|
#
|
||||||
# Redistribution and use in source and binary forms, with or without
|
# Redistribution and use in source and binary forms, with or without
|
||||||
@ -41,8 +41,9 @@ include $(APPDIR)/Make.defs
|
|||||||
|
|
||||||
TARGCMN_CSRCS = udp_cmdline.c
|
TARGCMN_CSRCS = udp_cmdline.c
|
||||||
ifeq ($(CONFIG_EXAMPLES_UDP_NETINIT),y)
|
ifeq ($(CONFIG_EXAMPLES_UDP_NETINIT),y)
|
||||||
TARGCMN_CSRCS += target_netinit.c
|
TARGCMN_CSRCS += udp_netinit.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
TARGCMN_COBJS = $(TARGCMN_CSRCS:.c=$(OBJEXT))
|
TARGCMN_COBJS = $(TARGCMN_CSRCS:.c=$(OBJEXT))
|
||||||
|
|
||||||
# Target 1
|
# Target 1
|
||||||
@ -53,7 +54,7 @@ TARG1_CRCS += udp_server.c
|
|||||||
else
|
else
|
||||||
TARG1_CRCS += udp_client.c
|
TARG1_CRCS += udp_client.c
|
||||||
endif
|
endif
|
||||||
TARG1_MAINSRC = target1.c
|
TARG1_MAINSRC = udp_target1.c
|
||||||
|
|
||||||
TARG1_COBJS = $(TARG1_CRCS:.c=$(OBJEXT))
|
TARG1_COBJS = $(TARG1_CRCS:.c=$(OBJEXT))
|
||||||
TARG1_MAINOBJ = $(TARG1_MAINSRC:.c=$(OBJEXT))
|
TARG1_MAINOBJ = $(TARG1_MAINSRC:.c=$(OBJEXT))
|
||||||
@ -76,15 +77,15 @@ STACKSIZE1 = $(CONFIG_EXAMPLES_UDP_STACKSIZE1)
|
|||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_UDP_TARGET2),y)
|
ifeq ($(CONFIG_EXAMPLES_UDP_TARGET2),y)
|
||||||
|
|
||||||
TARG2_CRCS =
|
TARG2_CSRCS =
|
||||||
ifeq ($(CONFIG_EXAMPLES_UDP_SERVER1),y)
|
ifeq ($(CONFIG_EXAMPLES_UDP_SERVER1),y)
|
||||||
TARG2_CRCS += udp_client.c
|
TARG2_CSRCS += udp_client.c
|
||||||
else
|
else
|
||||||
TARG2_CRCS += udp_server.c
|
TARG2_CSRCS += udp_server.c
|
||||||
endif
|
endif
|
||||||
TARG2_MAINSRC = target2.c
|
TARG2_MAINSRC = udp_target2.c
|
||||||
|
|
||||||
TARG2_COBJS = $(TARG2_CRCS:.c=$(OBJEXT))
|
TARG2_COBJS = $(TARG2_CSRCS:.c=$(OBJEXT))
|
||||||
TARG2_MAINOBJ = $(TARG2_MAINSRC:.c=$(OBJEXT))
|
TARG2_MAINOBJ = $(TARG2_MAINSRC:.c=$(OBJEXT))
|
||||||
|
|
||||||
ifeq ($(CONFIG_EXAMPLES_UDP_SERVER1),y)
|
ifeq ($(CONFIG_EXAMPLES_UDP_SERVER1),y)
|
||||||
@ -103,7 +104,7 @@ STACKSIZE2 = $(CONFIG_EXAMPLES_UDP_STACKSIZE2)
|
|||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
TARG_SRCS = $(TARG1_CRCS) $(TARG1_MAINSRC) $(TARG2_CRCS) $(TARG2_MAINSRC) $(TARGCMN_CSRCS)
|
TARG_SRCS = $(TARG1_CRCS) $(TARG1_MAINSRC) $(TARG2_CSRCS) $(TARG2_MAINSRC) $(TARGCMN_CSRCS)
|
||||||
TARG_OBJS = $(TARG1_COBJS) $(TARG2_COBJS) $(TARGCMN_COBJS)
|
TARG_OBJS = $(TARG1_COBJS) $(TARG2_COBJS) $(TARGCMN_COBJS)
|
||||||
|
|
||||||
ifneq ($(CONFIG_BUILD_KERNEL),y)
|
ifneq ($(CONFIG_BUILD_KERNEL),y)
|
||||||
@ -115,18 +116,18 @@ endif
|
|||||||
ifneq ($(CONFIG_EXAMPLES_UDP_TARGET2),y)
|
ifneq ($(CONFIG_EXAMPLES_UDP_TARGET2),y)
|
||||||
|
|
||||||
HOSTCFLAGS += -DEXAMPLES_UDP_HOST=1
|
HOSTCFLAGS += -DEXAMPLES_UDP_HOST=1
|
||||||
HOSTOBJSEXT ?= o1
|
HOSTOBJSEXT ?= hobj
|
||||||
|
|
||||||
HOST_SRCS = host.c udp_cmdline.c
|
HOST_SRCS = udp_host.c udp_cmdline.c
|
||||||
ifeq ($(CONFIG_EXAMPLES_UDP_SERVER1),y)
|
ifeq ($(CONFIG_EXAMPLES_UDP_SERVER1),y)
|
||||||
HOST_SRCS += udp_client.c
|
HOST_SRCS += udp_client.c
|
||||||
|
HOST_BIN = udpclient$(EXEEXT)
|
||||||
else
|
else
|
||||||
HOST_SRCS += udp_server.c
|
HOST_SRCS += udp_server.c
|
||||||
|
HOST_BIN = udpserver$(EXEEXT)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
HOST_OBJS = $(HOST_SRCS:.c=.$(HOSTOBJSEXT))
|
HOST_OBJS = $(HOST_SRCS:.c=.$(HOSTOBJSEXT))
|
||||||
HOST_BIN = host$(EXEEXT)
|
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||||
@ -161,7 +162,7 @@ VPATH =
|
|||||||
all: .built
|
all: .built
|
||||||
.PHONY: clean depend distclean preconfig
|
.PHONY: clean depend distclean preconfig
|
||||||
|
|
||||||
$(TARG1_COBJS) $(TARG1_MAINOBJ)$(TARG2_COBJS) $(TARG2_MAINOBJ) $(TARGCMN_COBJS): %$(OBJEXT): %.c
|
$(TARG1_COBJS) $(TARG1_MAINOBJ) $(TARG2_COBJS) $(TARG2_MAINOBJ) $(TARGCMN_COBJS): %$(OBJEXT): %.c
|
||||||
$(call COMPILE, $<, $@)
|
$(call COMPILE, $<, $@)
|
||||||
|
|
||||||
$(TARG_BIN): $(TARG_OBJS) $(HOST_BIN)
|
$(TARG_BIN): $(TARG_OBJS) $(HOST_BIN)
|
||||||
|
@ -83,12 +83,12 @@
|
|||||||
# define PF_INETX PF_INET
|
# define PF_INETX PF_INET
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_SERVER_PORTNO
|
#ifndef CONFIG_EXAMPLES_UDP_SERVER_PORTNO
|
||||||
# define CONFIG_EXAMPLES_SERVER_PORTNO 5471
|
# define CONFIG_EXAMPLES_UDP_SERVER_PORTNO 5471
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_CLIENT_PORTNO
|
#ifndef CONFIG_EXAMPLES_UDP_CLIENT_PORTNO
|
||||||
# define CONFIG_EXAMPLES_CLIENT_PORTNO 5472
|
# define CONFIG_EXAMPLES_UDP_CLIENT_PORTNO 5472
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ASCIISIZE (0x7f - 0x20)
|
#define ASCIISIZE (0x7f - 0x20)
|
||||||
@ -99,9 +99,9 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_UDP_IPv6
|
#ifdef CONFIG_EXAMPLES_UDP_IPv6
|
||||||
uint16_t g_server_ipv6[8];
|
uint16_t g_udpserver_ipv6[8];
|
||||||
#else
|
#else
|
||||||
uint32_t g_server_ipv4;
|
uint32_t g_udpserver_ipv4;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -109,11 +109,11 @@ uint32_t g_server_ipv4;
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_UDP_NETINIT
|
#ifdef CONFIG_EXAMPLES_UDP_NETINIT
|
||||||
int target_netinit(void);
|
int udp_netinit(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void parse_cmdline(int argc, char **argv);
|
void udp_cmdline(int argc, char **argv);
|
||||||
void send_client(void);
|
void udp_client(void);
|
||||||
void recv_server(void);
|
void udp_server(void);
|
||||||
|
|
||||||
#endif /* __EXAMPLES_UDP_UDP_H */
|
#endif /* __EXAMPLES_UDP_UDP_H */
|
||||||
|
@ -77,7 +77,7 @@ static int create_socket(void)
|
|||||||
/* Bind the UDP socket to a IPv4 port */
|
/* Bind the UDP socket to a IPv4 port */
|
||||||
|
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_port = HTONS(CONFIG_EXAMPLES_CLIENT_PORTNO);
|
addr.sin_port = HTONS(CONFIG_EXAMPLES_UDP_CLIENT_PORTNO);
|
||||||
addr.sin_addr.s_addr = HTONL(INADDR_ANY);
|
addr.sin_addr.s_addr = HTONL(INADDR_ANY);
|
||||||
addrlen = sizeof(struct sockaddr_in);
|
addrlen = sizeof(struct sockaddr_in);
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ static int create_socket(void)
|
|||||||
/* Bind the UDP socket to a IPv6 port */
|
/* Bind the UDP socket to a IPv6 port */
|
||||||
|
|
||||||
addr.sin6_family = AF_INET6;
|
addr.sin6_family = AF_INET6;
|
||||||
addr.sin6_port = HTONS(CONFIG_EXAMPLES_CLIENT_PORTNO);
|
addr.sin6_port = HTONS(CONFIG_EXAMPLES_UDP_CLIENT_PORTNO);
|
||||||
memset(addr.sin6_addr.s6_addr, 0, sizeof(struct in6_addr));
|
memset(addr.sin6_addr.s6_addr, 0, sizeof(struct in6_addr));
|
||||||
addrlen = sizeof(struct sockaddr_in6);
|
addrlen = sizeof(struct sockaddr_in6);
|
||||||
#endif
|
#endif
|
||||||
@ -130,7 +130,7 @@ static inline void fill_buffer(unsigned char *buf, int offset)
|
|||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void send_client(void)
|
void udp_client(void)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_EXAMPLES_UDP_IPv6
|
#ifdef CONFIG_EXAMPLES_UDP_IPv6
|
||||||
struct sockaddr_in6 server;
|
struct sockaddr_in6 server;
|
||||||
@ -164,13 +164,13 @@ void send_client(void)
|
|||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_UDP_IPv6
|
#ifdef CONFIG_EXAMPLES_UDP_IPv6
|
||||||
server.sin6_family = AF_INET6;
|
server.sin6_family = AF_INET6;
|
||||||
server.sin6_port = HTONS(CONFIG_EXAMPLES_SERVER_PORTNO);
|
server.sin6_port = HTONS(CONFIG_EXAMPLES_UDP_SERVER_PORTNO);
|
||||||
memcpy(server.sin6_addr.s6_addr16, g_server_ipv6, 8 * sizeof(uint16_t));
|
memcpy(server.sin6_addr.s6_addr16, g_udpserver_ipv6, 8 * sizeof(uint16_t));
|
||||||
addrlen = sizeof(struct sockaddr_in6);
|
addrlen = sizeof(struct sockaddr_in6);
|
||||||
#else
|
#else
|
||||||
server.sin_family = AF_INET;
|
server.sin_family = AF_INET;
|
||||||
server.sin_port = HTONS(CONFIG_EXAMPLES_SERVER_PORTNO);
|
server.sin_port = HTONS(CONFIG_EXAMPLES_UDP_SERVER_PORTNO);
|
||||||
server.sin_addr.s_addr = (in_addr_t)g_server_ipv4;
|
server.sin_addr.s_addr = (in_addr_t)g_udpserver_ipv4;
|
||||||
addrlen = sizeof(struct sockaddr_in);
|
addrlen = sizeof(struct sockaddr_in);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_UDP_IPv6
|
#ifdef CONFIG_EXAMPLES_UDP_IPv6
|
||||||
uint16_t g_server_ipv6[8] =
|
uint16_t g_udpserver_ipv6[8] =
|
||||||
{
|
{
|
||||||
HTONS(CONFIG_EXAMPLES_UDP_SERVERIPv6ADDR_1),
|
HTONS(CONFIG_EXAMPLES_UDP_SERVERIPv6ADDR_1),
|
||||||
HTONS(CONFIG_EXAMPLES_UDP_SERVERIPv6ADDR_2),
|
HTONS(CONFIG_EXAMPLES_UDP_SERVERIPv6ADDR_2),
|
||||||
@ -62,7 +62,7 @@ uint16_t g_server_ipv6[8] =
|
|||||||
HTONS(CONFIG_EXAMPLES_UDP_SERVERIPv6ADDR_8)
|
HTONS(CONFIG_EXAMPLES_UDP_SERVERIPv6ADDR_8)
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
uint32_t g_server_ipv4 = HTONL(CONFIG_EXAMPLES_UDP_SERVERIP);
|
uint32_t g_udpserver_ipv4 = HTONL(CONFIG_EXAMPLES_UDP_SERVERIP);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -84,10 +84,10 @@ static void show_usage(FAR const char *progname)
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* parse_cmdline
|
* udp_cmdline
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void parse_cmdline(int argc, char **argv)
|
void udp_cmdline(int argc, char **argv)
|
||||||
{
|
{
|
||||||
/* Currently only a single command line option is supported: The server
|
/* Currently only a single command line option is supported: The server
|
||||||
* IP address.
|
* IP address.
|
||||||
@ -100,9 +100,9 @@ void parse_cmdline(int argc, char **argv)
|
|||||||
/* Convert the <server-addr> argument into a binary address */
|
/* Convert the <server-addr> argument into a binary address */
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_UDP_IPv6
|
#ifdef CONFIG_EXAMPLES_UDP_IPv6
|
||||||
ret = inet_pton(AF_INET6, argv[1], g_server_ipv6);
|
ret = inet_pton(AF_INET6, argv[1], g_udpserver_ipv6);
|
||||||
#else
|
#else
|
||||||
ret = inet_pton(AF_INET, argv[1], &g_server_ipv4);
|
ret = inet_pton(AF_INET, argv[1], &g_udpserver_ipv4);
|
||||||
#endif
|
#endif
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* examples/udp/host.c
|
* examples/udp/udp_host.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
@ -56,14 +56,14 @@ int main(int argc, char **argv, char **envp)
|
|||||||
{
|
{
|
||||||
/* Parse any command line options */
|
/* Parse any command line options */
|
||||||
|
|
||||||
parse_cmdline(argc, argv);
|
udp_cmdline(argc, argv);
|
||||||
|
|
||||||
/* Run the server or client, depending upon how target1 was configured */
|
/* Run the server or client, depending upon how target1 was configured */
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_UDP_SERVER1
|
#ifdef CONFIG_EXAMPLES_UDP_SERVER1
|
||||||
send_client();
|
udp_client();
|
||||||
#else
|
#else
|
||||||
recv_server();
|
udp_server();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* examples/udp/target_netinit.c
|
* examples/udp/udp_netinit.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007, 2011, 2015, 2017 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007, 2011, 2015, 2017 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
@ -117,10 +117,10 @@ static bool g_initialized;
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* target_netinit
|
* udp_netinit
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int target_netinit(void)
|
int udp_netinit(void)
|
||||||
{
|
{
|
||||||
if (!g_initialized)
|
if (!g_initialized)
|
||||||
{
|
{
|
@ -84,7 +84,7 @@ static inline int check_buffer(unsigned char *buf)
|
|||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void recv_server(void)
|
void udp_server(void)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_EXAMPLES_UDP_IPv6
|
#ifdef CONFIG_EXAMPLES_UDP_IPv6
|
||||||
struct sockaddr_in6 server;
|
struct sockaddr_in6 server;
|
||||||
@ -124,13 +124,13 @@ void recv_server(void)
|
|||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_UDP_IPv6
|
#ifdef CONFIG_EXAMPLES_UDP_IPv6
|
||||||
server.sin6_family = AF_INET6;
|
server.sin6_family = AF_INET6;
|
||||||
server.sin6_port = HTONS(CONFIG_EXAMPLES_SERVER_PORTNO);
|
server.sin6_port = HTONS(CONFIG_EXAMPLES_UDP_SERVER_PORTNO);
|
||||||
memset(&server.sin6_addr, 0, sizeof(struct in6_addr));
|
memset(&server.sin6_addr, 0, sizeof(struct in6_addr));
|
||||||
|
|
||||||
addrlen = sizeof(struct sockaddr_in6);
|
addrlen = sizeof(struct sockaddr_in6);
|
||||||
#else
|
#else
|
||||||
server.sin_family = AF_INET;
|
server.sin_family = AF_INET;
|
||||||
server.sin_port = HTONS(CONFIG_EXAMPLES_SERVER_PORTNO);
|
server.sin_port = HTONS(CONFIG_EXAMPLES_UDP_SERVER_PORTNO);
|
||||||
server.sin_addr.s_addr = HTONL(INADDR_ANY);
|
server.sin_addr.s_addr = HTONL(INADDR_ANY);
|
||||||
|
|
||||||
addrlen = sizeof(struct sockaddr_in);
|
addrlen = sizeof(struct sockaddr_in);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* examples/udp/target1.c
|
* examples/udp/udp_target1.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007, 2011, 2015, 2017 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007, 2011, 2015, 2017 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
@ -58,20 +58,20 @@ int udp_main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
/* Parse any command line options */
|
/* Parse any command line options */
|
||||||
|
|
||||||
parse_cmdline(argc, argv);
|
udp_cmdline(argc, argv);
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_UDP_NETINIT
|
#ifdef CONFIG_EXAMPLES_UDP_NETINIT
|
||||||
/* Initialize the network */
|
/* Initialize the network */
|
||||||
|
|
||||||
(void)target_netinit();
|
(void)udp_netinit();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Run the server or client, depending upon how we are configured */
|
/* Run the server or client, depending upon how we are configured */
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_UDP_SERVER1
|
#ifdef CONFIG_EXAMPLES_UDP_SERVER1
|
||||||
recv_server();
|
udp_server();
|
||||||
#else
|
#else
|
||||||
send_client();
|
udp_client();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* examples/udp/target2.c
|
* examples/udp/udp_target2.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
@ -56,20 +56,20 @@ int udp2_main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
/* Parse any command line options */
|
/* Parse any command line options */
|
||||||
|
|
||||||
parse_cmdline(argc, argv);
|
udp_cmdline(argc, argv);
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_UDP_NETINIT
|
#ifdef CONFIG_EXAMPLES_UDP_NETINIT
|
||||||
/* Initialize the network */
|
/* Initialize the network */
|
||||||
|
|
||||||
(void)target_netinit();
|
(void)udp_netinit();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Run the server or client, depending upon how target1 was configured */
|
/* Run the server or client, depending upon how target1 was configured */
|
||||||
|
|
||||||
#ifdef CONFIG_EXAMPLES_UDP_SERVER1
|
#ifdef CONFIG_EXAMPLES_UDP_SERVER1
|
||||||
send_client();
|
udp_client();
|
||||||
#else
|
#else
|
||||||
recv_server();
|
udp_server();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
850
include/netutils/telnetc.h
Normal file
850
include/netutils/telnetc.h
Normal file
@ -0,0 +1,850 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* apps/netutils/telnetc/telnetc.c
|
||||||
|
*
|
||||||
|
* Leveraged from libtelnet, https://github.com/seanmiddleditch/libtelnet.
|
||||||
|
* Modified and re-released under the BSD license:
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* The original authors of libtelnet are listed below. Per their licesne,
|
||||||
|
* "The author or authors of this code dedicate any and all copyright
|
||||||
|
* interest in this code to the public domain. We make this dedication for
|
||||||
|
* the benefit of the public at large and to the detriment of our heirs and
|
||||||
|
* successors. We intend this dedication to be an overt act of
|
||||||
|
* relinquishment in perpetuity of all present and future rights to this
|
||||||
|
* code under copyright law."
|
||||||
|
*
|
||||||
|
* Author: Sean Middleditch <sean@sourcemud.org>
|
||||||
|
* (Also listed in the AUTHORS file are Jack Kelly <endgame.dos@gmail.com>
|
||||||
|
* and Katherine Flavel <kate@elide.org>)
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* libtelnet - TELNET protocol handling library
|
||||||
|
*
|
||||||
|
* SUMMARY:
|
||||||
|
*
|
||||||
|
* libtelnet is a library for handling the TELNET protocol. It includes
|
||||||
|
* routines for parsing incoming data from a remote peer as well as formatting
|
||||||
|
* data to send to the remote peer.
|
||||||
|
*
|
||||||
|
* libtelnet uses a callback-oriented API, allowing application-specific
|
||||||
|
* handling of various events. The callback system is also used for buffering
|
||||||
|
* outgoing protocol data, allowing the application to maintain control over
|
||||||
|
* the actual socket connection.
|
||||||
|
*
|
||||||
|
* Features supported include the full TELNET protocol, Q-method option
|
||||||
|
* negotiation, ZMP, MCCP2, MSSP, and NEW-ENVIRON.
|
||||||
|
*
|
||||||
|
* CONFORMS TO:
|
||||||
|
*
|
||||||
|
* RFC854 - http://www.faqs.org/rfcs/rfc854.html
|
||||||
|
* RFC855 - http://www.faqs.org/rfcs/rfc855.html
|
||||||
|
* RFC1091 - http://www.faqs.org/rfcs/rfc1091.html
|
||||||
|
* RFC1143 - http://www.faqs.org/rfcs/rfc1143.html
|
||||||
|
* RFC1408 - http://www.faqs.org/rfcs/rfc1408.html
|
||||||
|
* RFC1572 - http://www.faqs.org/rfcs/rfc1572.html
|
||||||
|
*
|
||||||
|
* LICENSE:
|
||||||
|
*
|
||||||
|
* The author or authors of this code dedicate any and all copyright interest
|
||||||
|
* in this code to the public domain. We make this dedication for the benefit
|
||||||
|
* of the public at large and to the detriment of our heirs and successors. We
|
||||||
|
* intend this dedication to be an overt act of relinquishment in perpetuity of
|
||||||
|
* all present and future rights to this code under copyright law.
|
||||||
|
*
|
||||||
|
* Author: Sean Middleditch <sean@sourcemud.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __APPS_INCLUDE_NETUTILS_TELNETC_H
|
||||||
|
#define __APPS_INCLUDE_NETUTILS_TELNETC_H 1
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
/* C++ support */
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-proecessor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* Telnet commands and special values. */
|
||||||
|
|
||||||
|
#define TELNET_IAC 255
|
||||||
|
#define TELNET_DONT 254
|
||||||
|
#define TELNET_DO 253
|
||||||
|
#define TELNET_WONT 252
|
||||||
|
#define TELNET_WILL 251
|
||||||
|
#define TELNET_SB 250
|
||||||
|
#define TELNET_GA 249
|
||||||
|
#define TELNET_EL 248
|
||||||
|
#define TELNET_EC 247
|
||||||
|
#define TELNET_AYT 246
|
||||||
|
#define TELNET_AO 245
|
||||||
|
#define TELNET_IP 244
|
||||||
|
#define TELNET_BREAK 243
|
||||||
|
#define TELNET_DM 242
|
||||||
|
#define TELNET_NOP 241
|
||||||
|
#define TELNET_SE 240
|
||||||
|
#define TELNET_EOR 239
|
||||||
|
#define TELNET_ABORT 238
|
||||||
|
#define TELNET_SUSP 237
|
||||||
|
#define TELNET_EOF 236
|
||||||
|
|
||||||
|
/* Telnet options. */
|
||||||
|
|
||||||
|
#define TELNET_TELOPT_BINARY 0
|
||||||
|
#define TELNET_TELOPT_ECHO 1
|
||||||
|
#define TELNET_TELOPT_RCP 2
|
||||||
|
#define TELNET_TELOPT_SGA 3
|
||||||
|
#define TELNET_TELOPT_NAMS 4
|
||||||
|
#define TELNET_TELOPT_STATUS 5
|
||||||
|
#define TELNET_TELOPT_TM 6
|
||||||
|
#define TELNET_TELOPT_RCTE 7
|
||||||
|
#define TELNET_TELOPT_NAOL 8
|
||||||
|
#define TELNET_TELOPT_NAOP 9
|
||||||
|
#define TELNET_TELOPT_NAOCRD 10
|
||||||
|
#define TELNET_TELOPT_NAOHTS 11
|
||||||
|
#define TELNET_TELOPT_NAOHTD 12
|
||||||
|
#define TELNET_TELOPT_NAOFFD 13
|
||||||
|
#define TELNET_TELOPT_NAOVTS 14
|
||||||
|
#define TELNET_TELOPT_NAOVTD 15
|
||||||
|
#define TELNET_TELOPT_NAOLFD 16
|
||||||
|
#define TELNET_TELOPT_XASCII 17
|
||||||
|
#define TELNET_TELOPT_LOGOUT 18
|
||||||
|
#define TELNET_TELOPT_BM 19
|
||||||
|
#define TELNET_TELOPT_DET 20
|
||||||
|
#define TELNET_TELOPT_SUPDUP 21
|
||||||
|
#define TELNET_TELOPT_SUPDUPOUTPUT 22
|
||||||
|
#define TELNET_TELOPT_SNDLOC 23
|
||||||
|
#define TELNET_TELOPT_TTYPE 24
|
||||||
|
#define TELNET_TELOPT_EOR 25
|
||||||
|
#define TELNET_TELOPT_TUID 26
|
||||||
|
#define TELNET_TELOPT_OUTMRK 27
|
||||||
|
#define TELNET_TELOPT_TTYLOC 28
|
||||||
|
#define TELNET_TELOPT_3270REGIME 29
|
||||||
|
#define TELNET_TELOPT_X3PAD 30
|
||||||
|
#define TELNET_TELOPT_NAWS 31
|
||||||
|
#define TELNET_TELOPT_TSPEED 32
|
||||||
|
#define TELNET_TELOPT_LFLOW 33
|
||||||
|
#define TELNET_TELOPT_LINEMODE 34
|
||||||
|
#define TELNET_TELOPT_XDISPLOC 35
|
||||||
|
#define TELNET_TELOPT_ENVIRON 36
|
||||||
|
#define TELNET_TELOPT_AUTHENTICATION 37
|
||||||
|
#define TELNET_TELOPT_ENCRYPT 38
|
||||||
|
#define TELNET_TELOPT_NEW_ENVIRON 39
|
||||||
|
#define TELNET_TELOPT_MSSP 70
|
||||||
|
#define TELNET_TELOPT_COMPRESS 85
|
||||||
|
#define TELNET_TELOPT_COMPRESS2 86
|
||||||
|
#define TELNET_TELOPT_ZMP 93
|
||||||
|
#define TELNET_TELOPT_EXOPL 255
|
||||||
|
|
||||||
|
#define TELNET_TELOPT_MCCP2 86
|
||||||
|
|
||||||
|
/* TERMINAL-TYPE codes. */
|
||||||
|
|
||||||
|
#define TELNET_TTYPE_IS 0
|
||||||
|
#define TELNET_TTYPE_SEND 1
|
||||||
|
|
||||||
|
/* NEW-ENVIRON/ENVIRON codes. */
|
||||||
|
|
||||||
|
#define TELNET_ENVIRON_IS 0
|
||||||
|
#define TELNET_ENVIRON_SEND 1
|
||||||
|
#define TELNET_ENVIRON_INFO 2
|
||||||
|
#define TELNET_ENVIRON_VAR 0
|
||||||
|
#define TELNET_ENVIRON_VALUE 1
|
||||||
|
#define TELNET_ENVIRON_ESC 2
|
||||||
|
#define TELNET_ENVIRON_USERVAR 3
|
||||||
|
|
||||||
|
/* MSSP codes. */
|
||||||
|
|
||||||
|
#define TELNET_MSSP_VAR 1
|
||||||
|
#define TELNET_MSSP_VAL 2
|
||||||
|
|
||||||
|
/* Telnet state tracker flags. */
|
||||||
|
|
||||||
|
#define TELNET_FLAG_PROXY (1 << 0)
|
||||||
|
#define TELNET_PFLAG_DEFLATE (1 << 7)
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* Error codes */
|
||||||
|
|
||||||
|
enum telnet_error_u
|
||||||
|
{
|
||||||
|
TELNET_EOK = 0, /* No error */
|
||||||
|
TELNET_EBADVAL, /* Invalid parameter, or API misuse */
|
||||||
|
TELNET_ENOMEM, /* Memory allocation failure */
|
||||||
|
TELNET_EOVERFLOW, /* Data exceeds buffer size */
|
||||||
|
TELNET_EPROTOCOL, /* Invalid sequence of special bytes */
|
||||||
|
TELNET_ECOMPRESS /* Error handling compressed streams */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Event codes */
|
||||||
|
|
||||||
|
enum telnet_event_type_e
|
||||||
|
{
|
||||||
|
TELNET_EV_DATA = 0, /* Raw text data has been received */
|
||||||
|
TELNET_EV_SEND, /* Data needs to be sent to the peer */
|
||||||
|
TELNET_EV_IAC, /* Generic IAC code received */
|
||||||
|
TELNET_EV_WILL, /* WILL option negotiation received */
|
||||||
|
TELNET_EV_WONT, /* WONT option neogitation received */
|
||||||
|
TELNET_EV_DO, /* DO option negotiation received */
|
||||||
|
TELNET_EV_DONT, /* DONT option negotiation received */
|
||||||
|
TELNET_EV_SUBNEGOTIATION, /* Sub-negotiation data received */
|
||||||
|
TELNET_EV_COMPRESS, /* Compression has been enabled */
|
||||||
|
TELNET_EV_ZMP, /* ZMP command has been received */
|
||||||
|
TELNET_EV_TTYPE, /* TTYPE command has been received */
|
||||||
|
TELNET_EV_ENVIRON, /* ENVIRON command has been received */
|
||||||
|
TELNET_EV_MSSP, /* MSSP command has been received */
|
||||||
|
TELNET_EV_WARNING, /* Recoverable error has occured */
|
||||||
|
TELNET_EV_ERROR /* Non-recoverable error has occured */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Environ/MSSP command information */
|
||||||
|
|
||||||
|
struct telnet_environ_s
|
||||||
|
{
|
||||||
|
unsigned char type; /* either TELNET_ENVIRON_VAR or
|
||||||
|
* TELNET_ENVIRON_USERVAR */
|
||||||
|
char *var; /* Name of the variable being set */
|
||||||
|
char *value; /* value of variable being set; empty string
|
||||||
|
* if no value */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* State tracker -- private data structure */
|
||||||
|
|
||||||
|
struct telnet_s; /* Forward reference */
|
||||||
|
|
||||||
|
/* Event information */
|
||||||
|
|
||||||
|
union telnet_event_u
|
||||||
|
{
|
||||||
|
/* Event type The type field will determine which of the other
|
||||||
|
* event structure fields have been filled in. For instance, if the
|
||||||
|
* event type is TELNET_EV_ZMP, then the zmp event field (and ONLY the
|
||||||
|
* zmp event field) will be filled in.
|
||||||
|
*/
|
||||||
|
|
||||||
|
enum telnet_event_type_e type;
|
||||||
|
|
||||||
|
/* Data event: for DATA and SEND events */
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
enum telnet_event_type_e _type; /* Alias for type */
|
||||||
|
const char *buffer; /* Byte buffer */
|
||||||
|
size_t size; /* Number of bytes in buffer */
|
||||||
|
} data;
|
||||||
|
|
||||||
|
/* WARNING and ERROR events */
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
enum telnet_event_type_e _type; /* Alias for type */
|
||||||
|
const char *file; /* File the error occured in */
|
||||||
|
const char *func; /* Function the error occured in */
|
||||||
|
const char *msg; /* Error message string */
|
||||||
|
int line; /* Line of file error occured on */
|
||||||
|
enum telnet_error_u errcode; /* Error code */
|
||||||
|
} error;
|
||||||
|
|
||||||
|
/* Command event: for IAC */
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
enum telnet_event_type_e _type; /* Alias for type */
|
||||||
|
unsigned char cmd; /* Telnet command received */
|
||||||
|
} iac;
|
||||||
|
|
||||||
|
/* Negotiation event: WILL, WONT, DO, DONT */
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
enum telnet_event_type_e _type; /* Alias for type */
|
||||||
|
unsigned char telopt; /* Option being negotiated */
|
||||||
|
} neg;
|
||||||
|
|
||||||
|
/* Subnegotiation event */
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
enum telnet_event_type_e _type; /* Alias for type */
|
||||||
|
const char *buffer; /* Data of sub-negotiation */
|
||||||
|
size_t size; /* Number of bytes in buffer */
|
||||||
|
unsigned char telopt; /* Option code for negotiation */
|
||||||
|
} sub;
|
||||||
|
|
||||||
|
/* ZMP event */
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
enum telnet_event_type_e _type; /* Alias for type */
|
||||||
|
const char **argv; /* Array of argument string */
|
||||||
|
size_t argc; /* Number of elements in argv */
|
||||||
|
} zmp;
|
||||||
|
|
||||||
|
/* TTYPE event */
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
enum telnet_event_type_e _type; /* Alias for type */
|
||||||
|
unsigned char cmd; /* TELNET_TTYPE_IS or TELNET_TTYPE_SEND */
|
||||||
|
const char *name; /* Terminal type name (IS only) */
|
||||||
|
} ttype;
|
||||||
|
|
||||||
|
/* COMPRESS event */
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
enum telnet_event_type_e _type; /* Alias for type */
|
||||||
|
unsigned char state; /* 1 if compression is enabled, 0 if
|
||||||
|
* disabled */
|
||||||
|
} compress;
|
||||||
|
|
||||||
|
/* ENVIRON/NEW-ENVIRON event */
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
enum telnet_event_type_e _type; /* Alias for type */
|
||||||
|
const struct telnet_environ_s *values; /* Array of variable values */
|
||||||
|
size_t size; /* Number of elements in values */
|
||||||
|
unsigned char cmd; /* SEND, IS, or INFO */
|
||||||
|
} envevent;
|
||||||
|
|
||||||
|
/* MSSP event */
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
enum telnet_event_type_e _type; /* Alias for type */
|
||||||
|
const struct telnet_environ_s *values; /* Array of variable values */
|
||||||
|
size_t size; /* Number of elements in values */
|
||||||
|
} mssp;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Name: telnet_event_handler_t
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* This is the type of function that must be passed to
|
||||||
|
* telnet_init() when creating a new telnet object. The
|
||||||
|
* function will be invoked once for every event generated
|
||||||
|
* by the libtelnet protocol parser.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* telnet The telnet object that generated the event
|
||||||
|
* event Event structure with details about the event
|
||||||
|
* user_data User-supplied pointer
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef void (*telnet_event_handler_t)(struct telnet_s *telnet,
|
||||||
|
union telnet_event_u *event,
|
||||||
|
void *user_data);
|
||||||
|
|
||||||
|
/* telopt support table element; use telopt of -1 for end marker */
|
||||||
|
|
||||||
|
struct telnet_telopt_s
|
||||||
|
{
|
||||||
|
short telopt; /* One of the TELOPT codes or -1 */
|
||||||
|
unsigned char us; /* TELNET_WILL or TELNET_WONT */
|
||||||
|
unsigned char him; /* TELNET_DO or TELNET_DONT */
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: telnet_init
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize a telnet state tracker.
|
||||||
|
*
|
||||||
|
* This function initializes a new state tracker, which is used for all
|
||||||
|
* other libtelnet functions. Each connection must have its own
|
||||||
|
* telnet state tracker object.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* telopts Table of TELNET options the application supports.
|
||||||
|
* eh Event handler function called for every event.
|
||||||
|
* flags 0 or TELNET_FLAG_PROXY.
|
||||||
|
* user_data Optional data pointer that will be passsed to eh.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Telent state tracker object.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
struct telnet_s *telnet_init(const struct telnet_telopt_s *telopts,
|
||||||
|
telnet_event_handler_t eh, unsigned char flags,
|
||||||
|
void *user_data);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: telnet_free
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Free up any memory allocated by a state tracker.
|
||||||
|
*
|
||||||
|
* This function must be called when a telnet state tracker is no
|
||||||
|
* longer needed (such as after the connection has been closed) to
|
||||||
|
* release any memory resources used by the state tracker.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* telnet Telnet state tracker object.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void telnet_free(struct telnet_s *telnet);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: telnet_recv
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Push a byte buffer into the state tracker.
|
||||||
|
*
|
||||||
|
* Passes one or more bytes to the telnet state tracker for
|
||||||
|
* protocol parsing. The byte buffer is most often going to be
|
||||||
|
* the buffer that recv() was called for while handling the
|
||||||
|
* connection.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* telnet Telnet state tracker object.
|
||||||
|
* buffer Pointer to byte buffer.
|
||||||
|
* size Number of bytes pointed to by buffer.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void telnet_recv(struct telnet_s *telnet, const char *buffer, size_t size);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: telnet_iac
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Send a telnet command.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* telnet Telnet state tracker object.
|
||||||
|
* cmd Command to send.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void telnet_iac(struct telnet_s *telnet, unsigned char cmd);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: telnet_negotiate
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Send negotiation command.
|
||||||
|
*
|
||||||
|
* Internally, libtelnet uses RFC1143 option negotiation rules.
|
||||||
|
* The negotiation commands sent with this function may be ignored
|
||||||
|
* if they are determined to be redundant.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* telnet Telnet state tracker object.
|
||||||
|
* cmd TELNET_WILL, TELNET_WONT, TELNET_DO, or TELNET_DONT.
|
||||||
|
* opt One of the TELNET_TELOPT_* values.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void telnet_negotiate(struct telnet_s *telnet, unsigned char cmd,
|
||||||
|
unsigned char opt);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: telnet_send
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Send non-command data (escapes IAC bytes).
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* telnet Telnet state tracker object.
|
||||||
|
* buffer Buffer of bytes to send.
|
||||||
|
* size Number of bytes to send.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void telnet_send(struct telnet_s *telnet, const char *buffer, size_t size);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: telnet_begin_sb
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Begin a sub-negotiation command.
|
||||||
|
*
|
||||||
|
* Sends IAC SB followed by the telopt code. All following data sent
|
||||||
|
* will be part of the sub-negotiation, until telnet_finish_sb() is
|
||||||
|
* called.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* telnet Telnet state tracker object.
|
||||||
|
* telopt One of the TELNET_TELOPT_* values.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void telnet_begin_sb(struct telnet_s *telnet, unsigned char telopt);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: telnet_finish_sb
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Finish a sub-negotiation command.
|
||||||
|
*
|
||||||
|
* This must be called after a call to telnet_begin_sb() to finish a
|
||||||
|
* sub-negotiation command.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* telnet Telnet state tracker object.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#define telnet_finish_sb(telnet) telnet_iac((telnet), TELNET_SE)
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: telnet_subnegotiation
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Send a complete subnegotiation buffer.
|
||||||
|
*
|
||||||
|
* Equivalent to:
|
||||||
|
* telnet_begin_sb(telnet, telopt);
|
||||||
|
* telnet_send(telnet, buffer, size);
|
||||||
|
* telnet_finish_sb(telnet);
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* telnet Telnet state tracker format.
|
||||||
|
* telopt One of the TELNET_TELOPT_* values.
|
||||||
|
* buffer Byte buffer for sub-negotiation data.
|
||||||
|
* size Number of bytes to use for sub-negotiation data.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void telnet_subnegotiation(struct telnet_s *telnet, unsigned char telopt,
|
||||||
|
const char *buffer, size_t size);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: telnet_begin_compress2
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Begin sending compressed data.
|
||||||
|
*
|
||||||
|
* This function will begein sending data using the COMPRESS2 option,
|
||||||
|
* which enables the use of zlib to compress data sent to the client.
|
||||||
|
* The client must offer support for COMPRESS2 with option negotiation,
|
||||||
|
* and zlib support must be compiled into libtelnet.
|
||||||
|
*
|
||||||
|
* Only the server may call this command.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* telnet Telnet state tracker object.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void telnet_begin_compress2(struct telnet_s *telnet);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: telnet_printf
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Send formatted data.
|
||||||
|
*
|
||||||
|
* This function is a wrapper around telnet_send(). It allows using
|
||||||
|
* printf-style formatting.
|
||||||
|
*
|
||||||
|
* Additionally, this function will translate \\r to the CR NUL construct
|
||||||
|
* and \\n with CR LF, as well as automatically escaping IAC bytes like
|
||||||
|
* telnet_send().
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* telnet Telnet state tracker object.
|
||||||
|
* fmt Format string.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Number of bytes sent.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int telnet_printf(struct telnet_s *telnet, const char *fmt, ...);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: telnet_vprintf
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Send formatted data with \r and \n translation in addition to IAC IAC
|
||||||
|
*
|
||||||
|
* See telnet_printf().
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int telnet_vprintf(struct telnet_s *telnet, const char *fmt, va_list va);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: telnet_raw_printf
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Send formatted data (no newline escaping).
|
||||||
|
*
|
||||||
|
* This behaves identically to telnet_printf(), except that the \\r and \\n
|
||||||
|
* characters are not translated. The IAC byte is still escaped as normal
|
||||||
|
* with telnet_send().
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* telnet Telnet state tracker object.
|
||||||
|
* fmt Format string.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Number of bytes sent.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int telnet_raw_printf(struct telnet_s *telnet, const char *fmt, ...);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: telnet_raw_vprintf
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Send formatted data (no newline escaping).
|
||||||
|
*
|
||||||
|
* See telnet_raw_printf().
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int telnet_raw_vprintf(struct telnet_s *telnet, const char *fmt, va_list va);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: telnet_begin_newenviron
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Begin a new set of NEW-ENVIRON values to request or send.
|
||||||
|
*
|
||||||
|
* This function will begin the sub-negotiation block for sending or
|
||||||
|
* requesting NEW-ENVIRON values.
|
||||||
|
*
|
||||||
|
* The telnet_finish_newenviron() macro must be called after this
|
||||||
|
* function to terminate the NEW-ENVIRON command.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* telnet Telnet state tracker object.
|
||||||
|
* type One of TELNET_ENVIRON_SEND, TELNET_ENVIRON_IS, or
|
||||||
|
* TELNET_ENVIRON_INFO.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void telnet_begin_newenviron(struct telnet_s *telnet, unsigned char type);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: telnet_newenviron_value
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Send a NEW-ENVIRON variable name or value.
|
||||||
|
*
|
||||||
|
* This can only be called between calls to telnet_begin_newenviron() and
|
||||||
|
* telnet_finish_newenviron().
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* telnet Telnet state tracker object.
|
||||||
|
* type One of TELNET_ENVIRON_VAR, TELNET_ENVIRON_USERVAR, or
|
||||||
|
* TELNET_ENVIRON_VALUE.
|
||||||
|
* string Variable name or value.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void telnet_newenviron_value(struct telnet_s *telnet, unsigned char type,
|
||||||
|
const char *string);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: telnet_finish_newenviron
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Finish a NEW-ENVIRON command.
|
||||||
|
*
|
||||||
|
* This must be called after a call to telnet_begin_newenviron() to finish a
|
||||||
|
* NEW-ENVIRON variable list.
|
||||||
|
*
|
||||||
|
* telnet Telnet state tracker object.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#define telnet_finish_newenviron(telnet) telnet_finish_sb((telnet))
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: telnet_ttype_send
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Send the TERMINAL-TYPE SEND command.
|
||||||
|
*
|
||||||
|
* Sends the sequence IAC TERMINAL-TYPE SEND.
|
||||||
|
*
|
||||||
|
* telnet Telnet state tracker object.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void telnet_ttype_send(struct telnet_s * telnet);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: telnet_ttype_is
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Send the TERMINAL-TYPE IS command.
|
||||||
|
*
|
||||||
|
* Sends the sequence IAC TERMINAL-TYPE IS "string".
|
||||||
|
*
|
||||||
|
* According to the RFC, the recipient of a TERMINAL-TYPE SEND shall
|
||||||
|
* send the next possible terminal-type the client supports. Upon sending
|
||||||
|
* the type, the client should switch modes to begin acting as the terminal
|
||||||
|
* type is just sent.
|
||||||
|
*
|
||||||
|
* The server may continue sending TERMINAL-TYPE IS until it receives a
|
||||||
|
* terminal type is understands. To indicate to the server that it has
|
||||||
|
* reached the end of the available optoins, the client must send the last
|
||||||
|
* terminal type a second time. When the server receives the same terminal
|
||||||
|
* type twice in a row, it knows it has seen all available terminal types.
|
||||||
|
*
|
||||||
|
* After the last terminal type is sent, if the client receives another
|
||||||
|
* TERMINAL-TYPE SEND command, it must begin enumerating the available
|
||||||
|
* terminal types from the very beginning. This allows the server to
|
||||||
|
* scan the available types for a preferred terminal type and, if none
|
||||||
|
* is found, to then ask the client to switch to an acceptable
|
||||||
|
* alternative.
|
||||||
|
*
|
||||||
|
* Note that if the client only supports a single terminal type, then
|
||||||
|
* simply sending that one type in response to every SEND will satisfy
|
||||||
|
* the behavior requirements.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* telnet Telnet state tracker object.
|
||||||
|
* ttype Name of the terminal-type being sent.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void telnet_ttype_is(struct telnet_s * telnet, const char *ttype);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: telnet_send_zmp
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Send a ZMP command.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* telnet Telnet state tracker object.
|
||||||
|
* argc Number of ZMP commands being sent.
|
||||||
|
* argv Array of argument strings.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void telnet_send_zmp(struct telnet_s * telnet, size_t argc,
|
||||||
|
const char **argv);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: telnet_send_zmpv
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Send a ZMP command.
|
||||||
|
*
|
||||||
|
* Arguments are listed out in var-args style. After the last argument, a
|
||||||
|
* NULL pointer must be passed in as a sentinel value.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* telnet Telnet state tracker object.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void telnet_send_zmpv(struct telnet_s * telnet, ...);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: telnet_send_vzmpv
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Send a ZMP command.
|
||||||
|
*
|
||||||
|
* See telnet_send_zmpv().
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void telnet_send_vzmpv(struct telnet_s * telnet, va_list va);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: telnet_begin_zmp
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Begin sending a ZMP command
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* telnet Telnet state tracker object.
|
||||||
|
* cmd The first argument (command name) for the ZMP command.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void telnet_begin_zmp(struct telnet_s * telnet, const char *cmd);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: telnet_zmp_arg
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Send a ZMP command argument.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* telnet Telnet state tracker object.
|
||||||
|
* arg Telnet argument string.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void telnet_zmp_arg(struct telnet_s * telnet, const char *arg);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: telnet_finish_zmp
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Finish a ZMP command.
|
||||||
|
*
|
||||||
|
* This must be called after a call to telnet_begin_zmp() to finish a
|
||||||
|
* ZMP argument list.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* telnet Telnet state tracker object.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#define telnet_finish_zmp(telnet) telnet_finish_sb((telnet))
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __APPS_INCLUDE_NETUTILS_TELNETC_H */
|
@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* apps/include/netutils/telnetd.h
|
* apps/include/netutils/telnetd.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007, 2011-2012, 2015 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007, 2011-2012, 2015, 2017 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -61,18 +61,22 @@ struct telnetd_config_s
|
|||||||
{
|
{
|
||||||
/* These fields describe the telnet daemon */
|
/* These fields describe the telnet daemon */
|
||||||
|
|
||||||
int d_port; /* The port to listen on (in network byte order) */
|
uint8_t d_priority; /* The execution priority of the Telnet daemon task */
|
||||||
int d_priority; /* The execution priority of the Telnet daemon task */
|
size_t d_stacksize; /* The stack size needed by the Telnet daemon task */
|
||||||
int d_stacksize; /* The stack size needed by the Telnet daemon task */
|
|
||||||
|
/* These fields describe the network connection */
|
||||||
|
|
||||||
|
uint16_t d_port; /* The port to listen on (in network byte order) */
|
||||||
|
sa_family_t d_family; /* Address family */
|
||||||
|
|
||||||
/* These fields describe the priority of each thread created by the Telnet
|
/* These fields describe the priority of each thread created by the Telnet
|
||||||
* daemon.
|
* daemon.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int t_priority; /* The execution priority of the spawned task, */
|
uint8_t t_priority; /* The execution priority of the spawned task, */
|
||||||
int t_stacksize; /* The stack size needed by the spawned task */
|
size_t t_stacksize; /* The stack size needed by the spawned task */
|
||||||
main_t t_entry; /* The entrypoint of the task to spawn when a new
|
main_t t_entry; /* The entrypoint of the task to spawn when a new
|
||||||
* connection is accepted. */
|
* connection is accepted. */
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* apps/include/nshlib/nshlib.h
|
* apps/include/nshlib/nshlib.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 2011, 2013, 2016 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2011, 2013, 2016-2017 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -147,8 +147,12 @@ int nsh_consolemain(int argc, char *argv[]);
|
|||||||
* the daemon has been started.
|
* the daemon has been started.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* None. All of the properties of the Telnet daemon are controlled by
|
* family - Provides the IP family to use by the server. May be either
|
||||||
* NuttX configuration setting.
|
* AF_INET or AF_INET6. This is needed because both both may be
|
||||||
|
* enabled in the configuration.
|
||||||
|
*
|
||||||
|
* All of the other properties of the Telnet daemon are controlled by
|
||||||
|
* NuttX configuration settings.
|
||||||
*
|
*
|
||||||
* Returned Values:
|
* Returned Values:
|
||||||
* The task ID of the Telnet daemon was successfully started. A negated
|
* The task ID of the Telnet daemon was successfully started. A negated
|
||||||
@ -156,7 +160,7 @@ int nsh_consolemain(int argc, char *argv[]);
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int nsh_telnetstart(void);
|
int nsh_telnetstart(sa_family_t family);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: platform_motd
|
* Name: platform_motd
|
||||||
|
@ -216,11 +216,7 @@ ssize_t readline(FAR char *buf, int buflen, FILE *instream, FILE *outstream);
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#if CONFIG_NFILE_STREAMS > 0
|
#define std_readline(b,s) readline(b,s,stdin,stdout)
|
||||||
# define std_readline(b,s) readline(b,s,stdin,stdout)
|
|
||||||
#else
|
|
||||||
ssize_t std_readline(FAR char *buf, int buflen);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -98,6 +98,10 @@ int ieee802154_getsaddr(int fd, FAR uint8_t *saddr);
|
|||||||
int ieee802154_seteaddr(int fd, FAR const uint8_t *eaddr);
|
int ieee802154_seteaddr(int fd, FAR const uint8_t *eaddr);
|
||||||
int ieee802154_geteaddr(int fd, FAR uint8_t *eaddr);
|
int ieee802154_geteaddr(int fd, FAR uint8_t *eaddr);
|
||||||
|
|
||||||
|
int ieee802154_getcoordsaddr(int fd, FAR uint8_t *saddr);
|
||||||
|
|
||||||
|
int ieee802154_getcoordeaddr(int fd, FAR uint8_t *eaddr);
|
||||||
|
|
||||||
int ieee802154_setpromisc(int fd, bool promisc);
|
int ieee802154_setpromisc(int fd, bool promisc);
|
||||||
int ieee802154_getpromisc(int fd, FAR bool *promisc);
|
int ieee802154_getpromisc(int fd, FAR bool *promisc);
|
||||||
|
|
||||||
@ -112,6 +116,8 @@ int ieee802154_getcca(int fd, FAR struct ieee802154_cca_s *cca);
|
|||||||
|
|
||||||
int ieee802154_getdevmode(int fd, FAR enum ieee802154_devmode_e *devmode);
|
int ieee802154_getdevmode(int fd, FAR enum ieee802154_devmode_e *devmode);
|
||||||
|
|
||||||
|
int ieee802154_setassocpermit(int fd, bool assocpermit);
|
||||||
|
|
||||||
#ifdef CONFIG_NET_6LOWPAN
|
#ifdef CONFIG_NET_6LOWPAN
|
||||||
/* Netork driver IOCTL helpers */
|
/* Netork driver IOCTL helpers */
|
||||||
|
|
||||||
|
@ -55,6 +55,12 @@ highly influenced by uIP) include:
|
|||||||
and adapted for NuttX by Darcy Gong.
|
and adapted for NuttX by Darcy Gong.
|
||||||
tftpc - TFTP client. See apps/include/netutils/tftp.h
|
tftpc - TFTP client. See apps/include/netutils/tftp.h
|
||||||
for interface information.
|
for interface information.
|
||||||
|
telnetc - This is a port of libtelnet to NuttX. This is a public domain
|
||||||
|
Telnet client library available from
|
||||||
|
https://github.com/seanmiddleditch/libtelnet modified for use
|
||||||
|
with NuttX. Original Authors: Sean Middleditch <sean@sourcemud.org>,
|
||||||
|
Jack Kelly <endgame.dos@gmail.com>, and Katherine Flavel
|
||||||
|
<kate@elide.org>
|
||||||
telnetd - TELNET server. This is the Telnet logic adapted from
|
telnetd - TELNET server. This is the Telnet logic adapted from
|
||||||
uIP and generalized for use as the front end to any
|
uIP and generalized for use as the front end to any
|
||||||
shell. The telnet daemon creates sessions that are
|
shell. The telnet daemon creates sessions that are
|
||||||
|
6
netutils/telnetc/.gitignore
vendored
Normal file
6
netutils/telnetc/.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
/.built
|
||||||
|
/.depend
|
||||||
|
/Make.dep
|
||||||
|
/*.src
|
||||||
|
/*.obj
|
||||||
|
/*.lst
|
20
netutils/telnetc/Kconfig
Normal file
20
netutils/telnetc/Kconfig
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#
|
||||||
|
# For a description of the syntax of this configuration file,
|
||||||
|
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||||
|
#
|
||||||
|
|
||||||
|
config NETUTILS_TELNETC
|
||||||
|
bool "Telnet client library"
|
||||||
|
default n
|
||||||
|
depends on NET && NET_TCP
|
||||||
|
---help---
|
||||||
|
Enable support for the libtelnet. This is a public domain
|
||||||
|
Telnet client library available from https://github.com/seanmiddleditch/libtelnet
|
||||||
|
modified for use with NuttX. Original Authors:
|
||||||
|
|
||||||
|
Sean Middleditch <sean@sourcemud.org>
|
||||||
|
Jack Kelly <endgame.dos@gmail.com>
|
||||||
|
Katherine Flavel <kate@elide.org>
|
||||||
|
|
||||||
|
if NETUTILS_TELNETC
|
||||||
|
endif
|
39
netutils/telnetc/Make.defs
Normal file
39
netutils/telnetc/Make.defs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
# apps/netutils/telnetc/Make.defs
|
||||||
|
# Adds selected applications to apps/ build
|
||||||
|
#
|
||||||
|
# Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||||
|
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
#
|
||||||
|
# Redistribution and use in source and binary forms, with or without
|
||||||
|
# modification, are permitted provided that the following conditions
|
||||||
|
# are met:
|
||||||
|
#
|
||||||
|
# 1. Redistributions of source code must retain the above copyright
|
||||||
|
# notice, this list of conditions and the following disclaimer.
|
||||||
|
# 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
# notice, this list of conditions and the following disclaimer in
|
||||||
|
# the documentation and/or other materials provided with the
|
||||||
|
# distribution.
|
||||||
|
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
# used to endorse or promote products derived from this software
|
||||||
|
# without specific prior written permission.
|
||||||
|
#
|
||||||
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
#
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_NETUTILS_TELNETC),y)
|
||||||
|
CONFIGURED_APPS += netutils/telnetc
|
||||||
|
endif
|
||||||
|
|
104
netutils/telnetc/Makefile
Normal file
104
netutils/telnetc/Makefile
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
############################################################################
|
||||||
|
# apps/netutils/telnetc/Makefile
|
||||||
|
#
|
||||||
|
# Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||||
|
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
#
|
||||||
|
# Redistribution and use in source and binary forms, with or without
|
||||||
|
# modification, are permitted provided that the following conditions
|
||||||
|
# are met:
|
||||||
|
#
|
||||||
|
# 1. Redistributions of source code must retain the above copyright
|
||||||
|
# notice, this list of conditions and the following disclaimer.
|
||||||
|
# 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
# notice, this list of conditions and the following disclaimer in
|
||||||
|
# the documentation and/or other materials provided with the
|
||||||
|
# distribution.
|
||||||
|
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
# used to endorse or promote products derived from this software
|
||||||
|
# without specific prior written permission.
|
||||||
|
#
|
||||||
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
#
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
-include $(TOPDIR)/.config
|
||||||
|
-include $(TOPDIR)/Make.defs
|
||||||
|
include $(APPDIR)/Make.defs
|
||||||
|
|
||||||
|
# Telnet daemon
|
||||||
|
|
||||||
|
ASRCS =
|
||||||
|
CSRCS =
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_NET_TCP),y)
|
||||||
|
CSRCS += telnetc.c
|
||||||
|
endif
|
||||||
|
|
||||||
|
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||||
|
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||||
|
|
||||||
|
SRCS = $(ASRCS) $(CSRCS)
|
||||||
|
OBJS = $(AOBJS) $(COBJS)
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||||
|
BIN = ..\..\libapps$(LIBEXT)
|
||||||
|
else
|
||||||
|
ifeq ($(WINTOOL),y)
|
||||||
|
BIN = ..\\..\\libapps$(LIBEXT)
|
||||||
|
else
|
||||||
|
BIN = ../../libapps$(LIBEXT)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ROOTDEPPATH = --dep-path .
|
||||||
|
|
||||||
|
# Common build
|
||||||
|
|
||||||
|
VPATH =
|
||||||
|
|
||||||
|
all: .built
|
||||||
|
.PHONY: context depend clean distclean preconfig
|
||||||
|
|
||||||
|
$(AOBJS): %$(OBJEXT): %.S
|
||||||
|
$(call ASSEMBLE, $<, $@)
|
||||||
|
|
||||||
|
$(COBJS): %$(OBJEXT): %.c
|
||||||
|
$(call COMPILE, $<, $@)
|
||||||
|
|
||||||
|
.built: $(OBJS)
|
||||||
|
$(call ARCHIVE, $(BIN), $(OBJS))
|
||||||
|
$(Q) touch .built
|
||||||
|
|
||||||
|
install:
|
||||||
|
|
||||||
|
context:
|
||||||
|
|
||||||
|
.depend: Makefile $(SRCS)
|
||||||
|
$(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||||
|
$(Q) touch $@
|
||||||
|
|
||||||
|
depend: .depend
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(call DELFILE, .built)
|
||||||
|
$(call CLEAN)
|
||||||
|
|
||||||
|
distclean: clean
|
||||||
|
$(call DELFILE, Make.dep)
|
||||||
|
$(call DELFILE, .depend)
|
||||||
|
|
||||||
|
preconfig:
|
||||||
|
|
||||||
|
-include Make.dep
|
2410
netutils/telnetc/telnetc.c
Normal file
2410
netutils/telnetc/telnetc.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* netutils/telnetd/telnetd_daemon.c
|
* netutils/telnetd/telnetd_daemon.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2012, 2017 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -48,6 +48,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <string.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
@ -72,9 +73,10 @@
|
|||||||
|
|
||||||
struct telnetd_s
|
struct telnetd_s
|
||||||
{
|
{
|
||||||
int port; /* The port to listen on (in network byte order) */
|
uint16_t port; /* The port to listen on (in network byte order) */
|
||||||
int priority; /* The execution priority of the spawned task, */
|
sa_family_t family; /* Address family */
|
||||||
int stacksize; /* The stack size needed by the spawned task */
|
uint8_t priority; /* The execution priority of the spawned task, */
|
||||||
|
size_t stacksize; /* The stack size needed by the spawned task */
|
||||||
main_t entry; /* The entrypoint of the task to spawn when a new
|
main_t entry; /* The entrypoint of the task to spawn when a new
|
||||||
* connection is accepted. */
|
* connection is accepted. */
|
||||||
};
|
};
|
||||||
@ -126,7 +128,16 @@ static struct telnetd_common_s g_telnetdcommon;
|
|||||||
static int telnetd_daemon(int argc, char *argv[])
|
static int telnetd_daemon(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
FAR struct telnetd_s *daemon;
|
FAR struct telnetd_s *daemon;
|
||||||
struct sockaddr_in myaddr;
|
union
|
||||||
|
{
|
||||||
|
struct sockaddr generic;
|
||||||
|
#ifdef CONFIG_NET_IPv4
|
||||||
|
struct sockaddr_in ipv4;
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_NET_IPv6
|
||||||
|
struct sockaddr_in6 ipv6;
|
||||||
|
#endif
|
||||||
|
} addr;
|
||||||
struct telnet_session_s session;
|
struct telnet_session_s session;
|
||||||
#ifdef CONFIG_NET_SOLINGER
|
#ifdef CONFIG_NET_SOLINGER
|
||||||
struct linger ling;
|
struct linger ling;
|
||||||
@ -187,11 +198,12 @@ static int telnetd_daemon(int argc, char *argv[])
|
|||||||
|
|
||||||
/* Create a new TCP socket to use to listen for connections */
|
/* Create a new TCP socket to use to listen for connections */
|
||||||
|
|
||||||
listensd = socket(PF_INET, SOCK_STREAM, 0);
|
listensd = socket(daemon->family, SOCK_STREAM, 0);
|
||||||
if (listensd < 0)
|
if (listensd < 0)
|
||||||
{
|
{
|
||||||
int errval = errno;
|
int errval = errno;
|
||||||
nerr("ERROR: socket failure: %d\n", errval);
|
nerr("ERROR: socket() failed for family %u: %d\n",
|
||||||
|
daemon->family, errval);
|
||||||
return -errval;
|
return -errval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,11 +220,33 @@ static int telnetd_daemon(int argc, char *argv[])
|
|||||||
|
|
||||||
/* Bind the socket to a local address */
|
/* Bind the socket to a local address */
|
||||||
|
|
||||||
myaddr.sin_family = AF_INET;
|
#ifdef CONFIG_NET_IPv4
|
||||||
myaddr.sin_port = daemon->port;
|
if (daemon->family == AF_INET)
|
||||||
myaddr.sin_addr.s_addr = INADDR_ANY;
|
{
|
||||||
|
addr.ipv4.sin_family = AF_INET;
|
||||||
|
addr.ipv4.sin_port = daemon->port;
|
||||||
|
addr.ipv4.sin_addr.s_addr = INADDR_ANY;
|
||||||
|
addrlen = sizeof(struct sockaddr_in);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_NET_IPv6
|
||||||
|
if (daemon->family == AF_INET6)
|
||||||
|
{
|
||||||
|
addr.ipv6.sin6_family = AF_INET6;
|
||||||
|
addr.ipv6.sin6_port = daemon->port;
|
||||||
|
addrlen = sizeof(struct sockaddr_in6);
|
||||||
|
|
||||||
if (bind(listensd, (struct sockaddr*)&myaddr, sizeof(struct sockaddr_in)) < 0)
|
memset(addr.ipv6.sin6_addr.s6_addr, 0, addrlen);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
nerr("ERROR: Unsupported address family: %u", daemon->family);
|
||||||
|
goto errout_with_socket;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bind(listensd, &addr.generic, addrlen) < 0)
|
||||||
{
|
{
|
||||||
nerr("ERROR: bind failure: %d\n", errno);
|
nerr("ERROR: bind failure: %d\n", errno);
|
||||||
goto errout_with_socket;
|
goto errout_with_socket;
|
||||||
@ -240,8 +274,8 @@ static int telnetd_daemon(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
ninfo("Accepting connections on port %d\n", ntohs(daemon->port));
|
ninfo("Accepting connections on port %d\n", ntohs(daemon->port));
|
||||||
|
|
||||||
addrlen = sizeof(struct sockaddr_in);
|
socklen_t accptlen = sizeof(addr);
|
||||||
acceptsd = accept(listensd, (struct sockaddr*)&myaddr, &addrlen);
|
acceptsd = accept(listensd, &addr.generic, &accptlen);
|
||||||
if (acceptsd < 0)
|
if (acceptsd < 0)
|
||||||
{
|
{
|
||||||
/* Accept failed */
|
/* Accept failed */
|
||||||
@ -390,6 +424,7 @@ int telnetd_start(FAR struct telnetd_config_s *config)
|
|||||||
/* Initialize the daemon structure */
|
/* Initialize the daemon structure */
|
||||||
|
|
||||||
daemon->port = config->d_port;
|
daemon->port = config->d_port;
|
||||||
|
daemon->family = config->d_family;
|
||||||
daemon->priority = config->t_priority;
|
daemon->priority = config->t_priority;
|
||||||
daemon->stacksize = config->t_stacksize;
|
daemon->stacksize = config->t_stacksize;
|
||||||
daemon->entry = config->t_entry;
|
daemon->entry = config->t_entry;
|
||||||
|
@ -483,6 +483,11 @@ config NSH_DISABLE_TEST
|
|||||||
bool "Disable test"
|
bool "Disable test"
|
||||||
default n
|
default n
|
||||||
|
|
||||||
|
config NSH_DISABLE_TELNETD
|
||||||
|
bool "Disable telnetd"
|
||||||
|
default n if !NSH_NETLOCAL
|
||||||
|
default y if NSH_NETLOCAL
|
||||||
|
|
||||||
config NSH_DISABLE_UMOUNT
|
config NSH_DISABLE_UMOUNT
|
||||||
bool "Disable umount"
|
bool "Disable umount"
|
||||||
default n
|
default n
|
||||||
|
@ -1080,6 +1080,21 @@ o sleep <sec>
|
|||||||
|
|
||||||
Pause execution (sleep) of <sec> seconds.
|
Pause execution (sleep) of <sec> seconds.
|
||||||
|
|
||||||
|
o telnetd
|
||||||
|
|
||||||
|
The Telnet daemon may be started either programmatically by calling
|
||||||
|
nsh_telnetstart() or it may be started from the NSH command line using
|
||||||
|
this telnetd command.
|
||||||
|
|
||||||
|
Normally this command would be suppressed with CONFIG_NSH_DISABLE_TELNETD
|
||||||
|
because the Telnet daemon is automatically started in nsh_main.c. The
|
||||||
|
exception is when CONFIG_NSH_NETLOCAL is selected. IN that case, the
|
||||||
|
network is not enabled at initialization but rather must be enabled from
|
||||||
|
the NSH command line or via other applications.
|
||||||
|
|
||||||
|
In that case, calling nsh_telnetstart() before the the network is
|
||||||
|
initialized will fail.
|
||||||
|
|
||||||
o time "<command>"
|
o time "<command>"
|
||||||
|
|
||||||
Perform command timing. This command will execute the following <command>
|
Perform command timing. This command will execute the following <command>
|
||||||
@ -1274,6 +1289,7 @@ Command Dependencies on Configuration Settings
|
|||||||
shutdown CONFIG_BOARDCTL_POWEROFF || CONFIG_BOARDCTL_RESET
|
shutdown CONFIG_BOARDCTL_POWEROFF || CONFIG_BOARDCTL_RESET
|
||||||
sleep !CONFIG_DISABLE_SIGNALS
|
sleep !CONFIG_DISABLE_SIGNALS
|
||||||
test !CONFIG_NSH_DISABLESCRIPT
|
test !CONFIG_NSH_DISABLESCRIPT
|
||||||
|
telnetd CONFIG_NSH_TELNET && !CONFIG_NSH_DISABLE_TELNETD
|
||||||
time ---
|
time ---
|
||||||
umount !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_READABLE
|
umount !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_READABLE
|
||||||
uname !CONFIG_NSH_DISABLE_UNAME
|
uname !CONFIG_NSH_DISABLE_UNAME
|
||||||
|
@ -1187,6 +1187,11 @@ int cmd_lsmod(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
|||||||
int cmd_wget(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
int cmd_wget(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
|
# if defined(CONFIG_NSH_TELNET)
|
||||||
|
# ifndef CONFIG_NSH_DISABLE_TELNETD
|
||||||
|
int cmd_telnetd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
#endif /* CONFIG_NET */
|
#endif /* CONFIG_NET */
|
||||||
|
|
||||||
#if defined(CONFIG_LIBC_NETDB) && defined(CONFIG_NETDB_DNSCLIENT) && \
|
#if defined(CONFIG_LIBC_NETDB) && defined(CONFIG_NETDB_DNSCLIENT) && \
|
||||||
|
@ -472,6 +472,14 @@ static const struct cmdmap_s g_cmdmap[] =
|
|||||||
{ "test", cmd_test, 3, CONFIG_NSH_MAXARGUMENTS, "<expression>" },
|
{ "test", cmd_test, 3, CONFIG_NSH_MAXARGUMENTS, "<expression>" },
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(CONFIG_NSH_TELNET) && !defined(CONFIG_NSH_DISABLE_TELNETD)
|
||||||
|
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
|
||||||
|
{"telnetd", cmd_telnetd, 2, 2, [ipv4|ipv6] },
|
||||||
|
#else
|
||||||
|
{"telnetd", cmd_telnetd, 1, 1, NULL },
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_NSH_DISABLE_TIME
|
#ifndef CONFIG_NSH_DISABLE_TIME
|
||||||
{ "time", cmd_time, 2, 2, "\"<command>\"" },
|
{ "time", cmd_time, 2, 2, "\"<command>\"" },
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* apps/nshlib/nsh_telnetd.c
|
* apps/nshlib/nsh_telnetd.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007-2013, 2016 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2007-2013, 2016-2017 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -40,6 +40,8 @@
|
|||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <assert.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
@ -51,6 +53,17 @@
|
|||||||
|
|
||||||
#ifdef CONFIG_NSH_TELNET
|
#ifdef CONFIG_NSH_TELNET
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
enum telnetd_state_e
|
||||||
|
{
|
||||||
|
TELNETD_NOTRUNNING = 0,
|
||||||
|
TELNETD_STARTED,
|
||||||
|
TELNETD_RUNNING
|
||||||
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -167,8 +180,12 @@ static int nsh_telnetmain(int argc, char *argv[])
|
|||||||
* the daemon has been started.
|
* the daemon has been started.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* None. All of the properties of the Telnet daemon are controlled by
|
* family - Provides the IP family to use by the server. May be either
|
||||||
* NuttX configuration setting.
|
* AF_INET or AF_INET6. This is needed because both both may be
|
||||||
|
* enabled in the configuration.
|
||||||
|
*
|
||||||
|
* All of the other properties of the Telnet daemon are controlled by
|
||||||
|
* NuttX configuration settings.
|
||||||
*
|
*
|
||||||
* Returned Values:
|
* Returned Values:
|
||||||
* The task ID of the Telnet daemon was successfully started. A negated
|
* The task ID of the Telnet daemon was successfully started. A negated
|
||||||
@ -176,39 +193,104 @@ static int nsh_telnetmain(int argc, char *argv[])
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int nsh_telnetstart(void)
|
int nsh_telnetstart(sa_family_t family)
|
||||||
{
|
{
|
||||||
struct telnetd_config_s config;
|
static enum telnetd_state_e state = TELNETD_NOTRUNNING;
|
||||||
int ret;
|
int ret = OK;
|
||||||
|
|
||||||
/* Initialize any USB tracing options that were requested. If standard
|
if (state == TELNETD_NOTRUNNING)
|
||||||
* console is also defined, then we will defer this step to the standard
|
{
|
||||||
* console.
|
struct telnetd_config_s config;
|
||||||
*/
|
|
||||||
|
/* There is a tiny race condition here if two tasks were to try to
|
||||||
|
* start the Telnet daemon concurrently.
|
||||||
|
*/
|
||||||
|
|
||||||
|
state = TELNETD_STARTED;
|
||||||
|
|
||||||
|
/* Initialize any USB tracing options that were requested. If
|
||||||
|
* standard console is also defined, then we will defer this step to
|
||||||
|
* the standard console.
|
||||||
|
*/
|
||||||
|
|
||||||
#if defined(CONFIG_NSH_USBDEV_TRACE) && !defined(CONFIG_NSH_CONSOLE)
|
#if defined(CONFIG_NSH_USBDEV_TRACE) && !defined(CONFIG_NSH_CONSOLE)
|
||||||
usbtrace_enable(TRACE_BITSET);
|
usbtrace_enable(TRACE_BITSET);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Configure the telnet daemon */
|
/* Configure the telnet daemon */
|
||||||
|
|
||||||
config.d_port = HTONS(CONFIG_NSH_TELNETD_PORT);
|
config.d_port = HTONS(CONFIG_NSH_TELNETD_PORT);
|
||||||
config.d_priority = CONFIG_NSH_TELNETD_DAEMONPRIO;
|
config.d_family = family;
|
||||||
config.d_stacksize = CONFIG_NSH_TELNETD_DAEMONSTACKSIZE;
|
config.d_priority = CONFIG_NSH_TELNETD_DAEMONPRIO;
|
||||||
config.t_priority = CONFIG_NSH_TELNETD_CLIENTPRIO;
|
config.d_stacksize = CONFIG_NSH_TELNETD_DAEMONSTACKSIZE;
|
||||||
config.t_stacksize = CONFIG_NSH_TELNETD_CLIENTSTACKSIZE;
|
config.t_priority = CONFIG_NSH_TELNETD_CLIENTPRIO;
|
||||||
config.t_entry = nsh_telnetmain;
|
config.t_stacksize = CONFIG_NSH_TELNETD_CLIENTSTACKSIZE;
|
||||||
|
config.t_entry = nsh_telnetmain;
|
||||||
|
|
||||||
/* Start the telnet daemon */
|
/* Start the telnet daemon */
|
||||||
|
|
||||||
_info("Starting the Telnet daemon\n");
|
_info("Starting the Telnet daemon\n");
|
||||||
ret = telnetd_start(&config);
|
|
||||||
if (ret < 0)
|
ret = telnetd_start(&config);
|
||||||
{
|
if (ret < 0)
|
||||||
_err("ERROR: Failed to tart the Telnet daemon: %d\n", ret);
|
{
|
||||||
|
_err("ERROR: Failed to tart the Telnet daemon: %d\n", ret);
|
||||||
|
state = TELNETD_NOTRUNNING;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
state = TELNETD_RUNNING;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: cmd_telnetd
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* The Telnet daemon may be started either programmatically by calling
|
||||||
|
* nsh_telnetstart() or it may be started from the NSH command line using
|
||||||
|
* this telnetd command.
|
||||||
|
*
|
||||||
|
* Normally this command would be suppressed with CONFIG_NSH_DISABLE_TELNETD
|
||||||
|
* because the Telnet daemon is automatically started in nsh_main.c. The
|
||||||
|
* exception is when CONFIG_NSH_NETLOCAL is selected. IN that case, the
|
||||||
|
* network is not enabled at initialization but rather must be enabled from
|
||||||
|
* the NSH command line or via other applications.
|
||||||
|
*
|
||||||
|
* In that case, calling nsh_telnetstart() before the the network is
|
||||||
|
* initialized will fail.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None. All of the properties of the Telnet daemon are controlled by
|
||||||
|
* NuttX configuration setting.
|
||||||
|
*
|
||||||
|
* Returned Values:
|
||||||
|
* OK is returned on success; ERROR is return on failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef CONFIG_NSH_DISABLE_TELNETD
|
||||||
|
int cmd_telnetd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||||
|
{
|
||||||
|
sa_family_t family;
|
||||||
|
|
||||||
|
/* If both IPv6 nd IPv4 are enabled, then the address family must
|
||||||
|
* be specified on the command line.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
|
||||||
|
family = (strcmp(argv[1], "ipv6") == 0) ? AF_INET6 : AF_INET;
|
||||||
|
#elif defined(CONFIG_NET_IPv6)
|
||||||
|
family = AF_INET6;
|
||||||
|
#else /* if defined(CONFIG_NET_IPv4) */
|
||||||
|
family = AF_INET;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return nsh_telnetstart(family) < 0 ? ERROR : OK;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* CONFIG_NSH_TELNET */
|
#endif /* CONFIG_NSH_TELNET */
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||||
#
|
#
|
||||||
|
|
||||||
config SYSTEM_DHCPC
|
config SYSTEM_DHCPC_RENEW
|
||||||
bool "DHCP Address Renewal"
|
bool "DHCP Address Renewal"
|
||||||
default n
|
default n
|
||||||
select NETUTILS_DHCPC
|
select NETUTILS_DHCPC
|
||||||
@ -11,9 +11,9 @@ config SYSTEM_DHCPC
|
|||||||
---help---
|
---help---
|
||||||
Enble the DHCP client 'renew' command
|
Enble the DHCP client 'renew' command
|
||||||
|
|
||||||
if SYSTEM_DHCPC
|
if SYSTEM_DHCPC_RENEW
|
||||||
|
|
||||||
config SYSTEM_DHCPC_PROGNAME
|
config DHCPC_RENEW_PROGNAME
|
||||||
string "Program name"
|
string "Program name"
|
||||||
default "renew"
|
default "renew"
|
||||||
depends on BUILD_KERNEL
|
depends on BUILD_KERNEL
|
||||||
@ -21,11 +21,11 @@ config SYSTEM_DHCPC_PROGNAME
|
|||||||
This is the name of the program that will be use when the NSH ELF
|
This is the name of the program that will be use when the NSH ELF
|
||||||
program is installed.
|
program is installed.
|
||||||
|
|
||||||
config SYSTEM_DHCPC_PRIORITY
|
config DHCPC_RENEW_PRIORITY
|
||||||
int "DHCPC task priority"
|
int "DHCPC task priority"
|
||||||
default 100
|
default 100
|
||||||
|
|
||||||
config SYSTEM_DHCPC_STACKSIZE
|
config DHCPC_RENEW_STACKSIZE
|
||||||
int "DHCPC stack size"
|
int "DHCPC stack size"
|
||||||
default 2048
|
default 2048
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
#
|
#
|
||||||
############################################################################
|
############################################################################
|
||||||
|
|
||||||
ifeq ($(CONFIG_SYSTEM_DHCPC),y)
|
ifeq ($(CONFIG_SYSTEM_DHCPC_RENEW),y)
|
||||||
CONFIGURED_APPS += system/dhcpc
|
CONFIGURED_APPS += system/dhcpc
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -39,31 +39,31 @@ include $(APPDIR)/Make.defs
|
|||||||
|
|
||||||
# DHCPC address renewal built-in application info
|
# DHCPC address renewal built-in application info
|
||||||
|
|
||||||
CONFIG_SYSTEM_DHCPC_PRIORITY ?= SCHED_PRIORITY_DEFAULT
|
CONFIG_DHCPC_RENEW_PRIORITY ?= SCHED_PRIORITY_DEFAULT
|
||||||
CONFIG_SYSTEM_DHCPC_STACKSIZE ?= 2048
|
CONFIG_DHCPC_RENEW_STACKSIZE ?= 2048
|
||||||
|
|
||||||
APPNAME = renew
|
RENEW_APPNAME = renew
|
||||||
PRIORITY = $(CONFIG_SYSTEM_DHCPC_PRIORITY)
|
RENEW_PRIORITY = $(CONFIG_DHCPC_RENEW_PRIORITY)
|
||||||
STACKSIZE = $(CONFIG_SYSTEM_DHCPC_STACKSIZE)
|
RENEW_STACKSIZE = $(CONFIG_DHCPC_RENEW_STACKSIZE)
|
||||||
|
|
||||||
CONFIG_SYSTEM_DHCPC_PROGNAME ?= renew$(EXEEXT)
|
CONFIG_DHCPC_RENEW_PROGNAME ?= renew$(EXEEXT)
|
||||||
PROGNAME = $(CONFIG_SYSTEM_DHCPC_PROGNAME)
|
RENEW_PROGNAME = $(CONFIG_DHCPC_RENEW_PROGNAME)
|
||||||
|
|
||||||
# DHCPC address renewal
|
# DHCPC address renewal
|
||||||
|
|
||||||
ASRCS =
|
RENEW_SRCS =
|
||||||
CSRCS =
|
RENEW_MAINSRC = renew_main.c
|
||||||
MAINSRC = dhcpc_main.c
|
|
||||||
|
|
||||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
RENEW_OBJS = $(RENEW_SRCS:.c=$(OBJEXT))
|
||||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
RENEW_MAINOBJ = $(RENEW_MAINSRC:.c=$(OBJEXT))
|
||||||
MAINOBJ = $(MAINSRC:.c=$(OBJEXT))
|
|
||||||
|
|
||||||
SRCS = $(ASRCS) $(CSRCS) $(MAINSRC)
|
# Other DHCPC commands go here
|
||||||
OBJS = $(AOBJS) $(COBJS)
|
|
||||||
|
SRCS = $(RENEW_SRCS) $(RENEW_MAINSRC)
|
||||||
|
OBJS = $(RENEW_OBJS)
|
||||||
|
|
||||||
ifneq ($(CONFIG_BUILD_KERNEL),y)
|
ifneq ($(CONFIG_BUILD_KERNEL),y)
|
||||||
OBJS += $(MAINOBJ)
|
OBJS += $(RENEW_MAINOBJ)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||||
@ -91,10 +91,7 @@ VPATH =
|
|||||||
all: .built
|
all: .built
|
||||||
.PHONY: clean depend distclean
|
.PHONY: clean depend distclean
|
||||||
|
|
||||||
$(AOBJS): %$(OBJEXT): %.S
|
$(OBJS) $(RENEW_MAINOBJ): %$(OBJEXT): %.c
|
||||||
$(call ASSEMBLE, $<, $@)
|
|
||||||
|
|
||||||
$(COBJS) $(MAINOBJ): %$(OBJEXT): %.c
|
|
||||||
$(call COMPILE, $<, $@)
|
$(call COMPILE, $<, $@)
|
||||||
|
|
||||||
.built: $(OBJS)
|
.built: $(OBJS)
|
||||||
@ -102,12 +99,12 @@ $(COBJS) $(MAINOBJ): %$(OBJEXT): %.c
|
|||||||
@touch .built
|
@touch .built
|
||||||
|
|
||||||
ifeq ($(CONFIG_BUILD_KERNEL),y)
|
ifeq ($(CONFIG_BUILD_KERNEL),y)
|
||||||
$(BIN_DIR)$(DELIM)$(PROGNAME): $(OBJS) $(MAINOBJ)
|
$(BIN_DIR)$(DELIM)$(RENEW_PROGNAME): $(OBJS) $(RENEW_MAINOBJ)
|
||||||
@echo "LD: $(PROGNAME)"
|
@echo "LD: $(RENEW_PROGNAME)"
|
||||||
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(PROGNAME) $(ARCHCRT0OBJ) $(MAINOBJ) $(LDLIBS)
|
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(RENEW_PROGNAME) $(ARCHCRT0OBJ) $(RENEW_MAINOBJ) $(LDLIBS)
|
||||||
$(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(PROGNAME)
|
$(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(RENEW_PROGNAME)
|
||||||
|
|
||||||
install: $(BIN_DIR)$(DELIM)$(PROGNAME)
|
install: $(BIN_DIR)$(DELIM)$(RENEW_PROGNAME)
|
||||||
|
|
||||||
else
|
else
|
||||||
install:
|
install:
|
||||||
@ -115,10 +112,10 @@ install:
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
$(BUILTIN_REGISTRY)$(DELIM)$(RENEW_APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
$(call REGISTER,$(RENEW_APPNAME),$(RENEW_PRIORITY),$(RENEW_STACKSIZE),$(RENEW_APPNAME)_main)
|
||||||
|
|
||||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
context: $(BUILTIN_REGISTRY)$(DELIM)$(RENEW_APPNAME)_main.bdat
|
||||||
else
|
else
|
||||||
context:
|
context:
|
||||||
endif
|
endif
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* system/dhcpc/dhcpc_main.c
|
* system/dhcpc/renew_main.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
@ -66,13 +66,13 @@ static void dhcpc_showusage(FAR const char *progname, int exitcode)
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* dhcpc_main
|
* renew_main
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_BUILD_KERNEL
|
#ifdef CONFIG_BUILD_KERNEL
|
||||||
int main(int argc, FAR char *argv[])
|
int main(int argc, FAR char *argv[])
|
||||||
#else
|
#else
|
||||||
int dhcpc_main(int argc, char *argv[])
|
int renew_main(int argc, char *argv[])
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
FAR const char *devname;
|
FAR const char *devname;
|
11
system/telnet/.gitignore
vendored
Normal file
11
system/telnet/.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
/Make.dep
|
||||||
|
/.depend
|
||||||
|
/.built
|
||||||
|
/*.asm
|
||||||
|
/*.obj
|
||||||
|
/*.rel
|
||||||
|
/*.lst
|
||||||
|
/*.sym
|
||||||
|
/*.adb
|
||||||
|
/*.lib
|
||||||
|
/*.src
|
61
system/telnet/Kconfig
Normal file
61
system/telnet/Kconfig
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#
|
||||||
|
# For a description of the syntax of this configuration file,
|
||||||
|
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||||
|
#
|
||||||
|
|
||||||
|
menuconfig SYSTEM_TELNET_CHATD
|
||||||
|
bool "Telnet chat deamon"
|
||||||
|
default n
|
||||||
|
depends on NET && NET_TCP && !DISABLE_POLL
|
||||||
|
select NETUTILS_TELNETC
|
||||||
|
---help---
|
||||||
|
Enable the Telnet Chat daemon.
|
||||||
|
|
||||||
|
if SYSTEM_TELNET_CHATD
|
||||||
|
|
||||||
|
config SYSTEM_TELNET_CHATD_PROGNAME
|
||||||
|
string "Chat daemon program name"
|
||||||
|
default "chatd"
|
||||||
|
depends on BUILD_KERNEL
|
||||||
|
|
||||||
|
if NSH_BUILTIN_APPS
|
||||||
|
|
||||||
|
config SYSTEM_TELNET_CHATD_STACKSIZE
|
||||||
|
int "Chat daemon stacksize"
|
||||||
|
default 2048
|
||||||
|
|
||||||
|
config SYSTEM_TELNET_CHATD_PRIORITY
|
||||||
|
int "Chat daemon priority"
|
||||||
|
default 100
|
||||||
|
|
||||||
|
endif # NSH_BUILTIN_APPS
|
||||||
|
endif # SYSTEM_TELNET_CHATD
|
||||||
|
|
||||||
|
menuconfig SYSTEM_TELNET_CLIENT
|
||||||
|
bool "Telnet client"
|
||||||
|
default n
|
||||||
|
depends on NET && NET_TCP && !DISABLE_POLL
|
||||||
|
select NETUTILS_TELNETC
|
||||||
|
select SYSTEM_READLINE
|
||||||
|
---help---
|
||||||
|
Enable the Telnet client program.
|
||||||
|
|
||||||
|
if SYSTEM_TELNET_CLIENT
|
||||||
|
|
||||||
|
config SYSTEM_TELNET_CLIENT_PROGNAME
|
||||||
|
string "Telnet client program name"
|
||||||
|
default "chatd"
|
||||||
|
depends on BUILD_KERNEL
|
||||||
|
|
||||||
|
if NSH_BUILTIN_APPS
|
||||||
|
|
||||||
|
config SYSTEM_TELNET_CLIENT_STACKSIZE
|
||||||
|
int "Telnet client stacksize"
|
||||||
|
default 2048
|
||||||
|
|
||||||
|
config SYSTEM_TELNET_CLIENT_PRIORITY
|
||||||
|
int "Telnet client priority"
|
||||||
|
default 100
|
||||||
|
|
||||||
|
endif # NSH_BUILTIN_APPS
|
||||||
|
endif # SYSTEM_TELNET_CLIENT
|
41
system/telnet/Make.defs
Normal file
41
system/telnet/Make.defs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
############################################################################
|
||||||
|
# apps/system/usbmsc/Make.defs
|
||||||
|
# Adds selected applications to apps/ build
|
||||||
|
#
|
||||||
|
# Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
||||||
|
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
#
|
||||||
|
# Redistribution and use in source and binary forms, with or without
|
||||||
|
# modification, are permitted provided that the following conditions
|
||||||
|
# are met:
|
||||||
|
#
|
||||||
|
# 1. Redistributions of source code must retain the above copyright
|
||||||
|
# notice, this list of conditions and the following disclaimer.
|
||||||
|
# 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
# notice, this list of conditions and the following disclaimer in
|
||||||
|
# the documentation and/or other materials provided with the
|
||||||
|
# distribution.
|
||||||
|
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
# used to endorse or promote products derived from this software
|
||||||
|
# without specific prior written permission.
|
||||||
|
#
|
||||||
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
#
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_SYSTEM_TELNET_CHATD),y)
|
||||||
|
CONFIGURED_APPS += system/telnet
|
||||||
|
else ifeq ($(CONFIG_SYSTEM_TELNET_CLIENT),y)
|
||||||
|
CONFIGURED_APPS += system/telnet
|
||||||
|
endif
|
205
system/telnet/Makefile
Normal file
205
system/telnet/Makefile
Normal file
@ -0,0 +1,205 @@
|
|||||||
|
############################################################################
|
||||||
|
# apps/system/telnet/Makefile
|
||||||
|
#
|
||||||
|
# Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||||
|
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
#
|
||||||
|
# Redistribution and use in source and binary forms, with or without
|
||||||
|
# modification, are permitted provided that the following conditions
|
||||||
|
# are met:
|
||||||
|
#
|
||||||
|
# 1. Redistributions of source code must retain the above copyright
|
||||||
|
# notice, this list of conditions and the following disclaimer.
|
||||||
|
# 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
# notice, this list of conditions and the following disclaimer in
|
||||||
|
# the documentation and/or other materials provided with the
|
||||||
|
# distribution.
|
||||||
|
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
# used to endorse or promote products derived from this software
|
||||||
|
# without specific prior written permission.
|
||||||
|
#
|
||||||
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
#
|
||||||
|
############################################################################
|
||||||
|
|
||||||
|
-include $(TOPDIR)/.config
|
||||||
|
-include $(TOPDIR)/Make.defs
|
||||||
|
include $(APPDIR)/Make.defs
|
||||||
|
|
||||||
|
# Telnet Programs
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_SYSTEM_TELNET_CHATD),y)
|
||||||
|
|
||||||
|
# Chatd files
|
||||||
|
|
||||||
|
CHATD_CSRCS =
|
||||||
|
CHATD_MAINSRC = telnet_chatd.c
|
||||||
|
|
||||||
|
CHATD_COBJS = $(CHATD_CSRCS:.c=$(OBJEXT))
|
||||||
|
CHATD_MAINOBJ = $(CHATD_MAINSRC:.c=$(OBJEXT))
|
||||||
|
|
||||||
|
# Chatd Application Info
|
||||||
|
|
||||||
|
CONFIG_SYSTEM_TELNET_CHATD_PROGNAME ?= chatd
|
||||||
|
CONFIG_SYSTEM_TELNET_CHATD_PRIORITY ?= 100
|
||||||
|
CONFIG_SYSTEM_TELNET_CHATD_STACKSIZE ?= 2048
|
||||||
|
|
||||||
|
CHATD_MAINNAME = chatd_main
|
||||||
|
CHATD_APPNAME = chatd
|
||||||
|
CHATD_PROGNAME = $(CONFIG_SYSTEM_TELNET_CHATD_PROGNAME)
|
||||||
|
CHATD_PRIORITY = $(CONFIG_SYSTEM_TELNET_CHATD_PRIORITY)
|
||||||
|
CHATD_STACKSIZE = $(CONFIG_SYSTEM_TELNET_CHATD_STACKSIZE)
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_SYSTEM_TELNET_CLIENT),y)
|
||||||
|
|
||||||
|
# Telnet client files
|
||||||
|
|
||||||
|
CLIENT_CSRCS =
|
||||||
|
CLIENT_MAINSRC = telnet_client.c
|
||||||
|
|
||||||
|
CLIENT_COBJS = $(CLIENT_CSRCS:.c=$(OBJEXT))
|
||||||
|
CLIENT_MAINOBJ = $(CLIENT_MAINSRC:.c=$(OBJEXT))
|
||||||
|
|
||||||
|
# Telnet client Application Info
|
||||||
|
|
||||||
|
CONFIG_SYSTEM_TELNET_CLIENT_PROGNAME ?= tcpclient
|
||||||
|
CONFIG_SYSTEM_TELNET_CLIENT_PRIORITY ?= 100
|
||||||
|
CONFIG_SYSTEM_TELNET_CLIENT_STACKSIZE ?= 2048
|
||||||
|
|
||||||
|
CLIENT_MAINNAME = telnet_main
|
||||||
|
CLIENT_APPNAME = telnet
|
||||||
|
CLIENT_PROGNAME = $(CONFIG_SYSTEM_TELNET_CLIENT_PROGNAME)
|
||||||
|
CLIENT_PRIORITY = $(CONFIG_SYSTEM_TELNET_CLIENT_PRIORITY)
|
||||||
|
CLIENT_STACKSIZE = $(CONFIG_SYSTEM_TELNET_CLIENT_STACKSIZE)
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
|
# All programns
|
||||||
|
|
||||||
|
TARG_SRCS = $(CHATD_CRCS) $(CHATD_MAINSRC) $(CLIENT_CSRCS) $(CLIENT_MAINSRC)
|
||||||
|
TARG_OBJS = $(CHATD_COBJS) $(CLIENT_COBJS)
|
||||||
|
|
||||||
|
ifneq ($(CONFIG_BUILD_KERNEL),y)
|
||||||
|
TARG_OBJS += $(CHATD_MAINOBJ) $(CLIENT_MAINOBJ)
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||||
|
TARG_BIN = ..\..\libapps$(LIBEXT)
|
||||||
|
else
|
||||||
|
ifeq ($(WINTOOL),y)
|
||||||
|
TARG_BIN = ..\\..\\libapps$(LIBEXT)
|
||||||
|
else
|
||||||
|
TARG_BIN = ../../libapps$(LIBEXT)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(WINTOOL),y)
|
||||||
|
INSTALL_DIR = "${shell cygpath -w $(BIN_DIR)}"
|
||||||
|
else
|
||||||
|
INSTALL_DIR = $(BIN_DIR)
|
||||||
|
endif
|
||||||
|
|
||||||
|
ROOTDEPPATH = --dep-path .
|
||||||
|
|
||||||
|
# Common build
|
||||||
|
|
||||||
|
VPATH =
|
||||||
|
|
||||||
|
all: .built
|
||||||
|
.PHONY: clean depend distclean preconfig
|
||||||
|
|
||||||
|
$(CHATD_COBJS) $(CHATD_MAINOBJ) $(CLIENT_COBJS) $(CLIENT_MAINOBJ) : %$(OBJEXT): %.c
|
||||||
|
$(call COMPILE, $<, $@)
|
||||||
|
|
||||||
|
.built: $(TARG_OBJS)
|
||||||
|
$(call ARCHIVE, $(TARG_BIN), $(TARG_OBJS))
|
||||||
|
$(Q) touch .built
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_BUILD_KERNEL),y)
|
||||||
|
ifeq ($(CONFIG_SYSTEM_TELNET_CHATD),y)
|
||||||
|
|
||||||
|
$(BIN_DIR)$(DELIM)$(CHATD_PROGNAME): $(OBJS) $(CHATD_MAINOBJ)
|
||||||
|
@echo "LD: $(CHATD_PROGNAME)"
|
||||||
|
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(CHATD_PROGNAME) $(ARCHCRT0OBJ) $(CHATD_MAINOBJ) $(LDLIBS)
|
||||||
|
$(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(CHATD_PROGNAME)
|
||||||
|
|
||||||
|
chatd_install: $(BIN_DIR)$(DELIM)$(CHATD_PROGNAME)
|
||||||
|
else
|
||||||
|
chatd_install:
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_SYSTEM_TELNET_CLIENT),y)
|
||||||
|
|
||||||
|
$(BIN_DIR)$(DELIM)$(CLIENT_PROGNAME): $(OBJS) $(CLIENT_MAINOBJ)
|
||||||
|
@echo "LD: $(CLIENT_PROGNAME)"
|
||||||
|
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(CLIENT_PROGNAME) $(ARCHCRT0OBJ) $(CLIENT_MAINOBJ) $(LDLIBS)
|
||||||
|
$(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(CLIENT_PROGNAME)
|
||||||
|
|
||||||
|
client_install: $(BIN_DIR)$(DELIM)$(CLIENT_PROGNAME)
|
||||||
|
else
|
||||||
|
client_install:
|
||||||
|
endif
|
||||||
|
|
||||||
|
install: chatd_install client_install
|
||||||
|
|
||||||
|
else
|
||||||
|
install:
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||||
|
ifeq ($(CONFIG_SYSTEM_TELNET_CHATD),y)
|
||||||
|
|
||||||
|
$(BUILTIN_REGISTRY)$(DELIM)$(CHATD_APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||||
|
$(call REGISTER,$(CHATD_APPNAME),$(CHATD_PRIORITY),$(CHATD_STACKSIZE),$(CHATD_MAINNAME))
|
||||||
|
|
||||||
|
chatd_register: $(BUILTIN_REGISTRY)$(DELIM)$(CHATD_APPNAME)_main.bdat
|
||||||
|
else
|
||||||
|
chatd_register:
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_SYSTEM_TELNET_CLIENT),y)
|
||||||
|
$(BUILTIN_REGISTRY)$(DELIM)$(CLIENT_APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||||
|
$(call REGISTER,$(CLIENT_APPNAME),$(CLIENT_PRIORITY),$(CLIENT_STACKSIZE),$(CLIENT_MAINNAME))
|
||||||
|
|
||||||
|
client_register: $(BUILTIN_REGISTRY)$(DELIM)$(CLIENT_APPNAME)_main.bdat
|
||||||
|
else
|
||||||
|
client_register:
|
||||||
|
endif
|
||||||
|
|
||||||
|
context: chatd_register client_register
|
||||||
|
else
|
||||||
|
context:
|
||||||
|
endif
|
||||||
|
|
||||||
|
.depend: Makefile $(TARG_CSRCS)
|
||||||
|
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(TARG_CSRCS) >Make.dep
|
||||||
|
@touch $@
|
||||||
|
|
||||||
|
depend: .depend
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(call DELFILE, .built)
|
||||||
|
$(call DELFILE, *.dSYM)
|
||||||
|
$(call CLEAN)
|
||||||
|
|
||||||
|
distclean: clean
|
||||||
|
$(call DELFILE, Make.dep)
|
||||||
|
$(call DELFILE, .depend)
|
||||||
|
|
||||||
|
preconfig:
|
||||||
|
|
||||||
|
-include Make.dep
|
518
system/telnet/telnet_chatd.c
Normal file
518
system/telnet/telnet_chatd.c
Normal file
@ -0,0 +1,518 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* apps/system/telnet/telnet_chatd.c
|
||||||
|
*
|
||||||
|
* Leveraged from libtelnet, https://github.com/seanmiddleditch/libtelnet.
|
||||||
|
* Modified and re-released under the BSD license:
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* The original authors of libtelnet are listed below. Per their licesne,
|
||||||
|
* "The author or authors of this code dedicate any and all copyright
|
||||||
|
* interest in this code to the public domain. We make this dedication for
|
||||||
|
* the benefit of the public at large and to the detriment of our heirs and
|
||||||
|
* successors. We intend this dedication to be an overt act of
|
||||||
|
* relinquishment in perpetuity of all present and future rights to this
|
||||||
|
* code under copyright law."
|
||||||
|
*
|
||||||
|
* Author: Sean Middleditch <sean@sourcemud.org>
|
||||||
|
* (Also listed in the AUTHORS file are Jack Kelly <endgame.dos@gmail.com>
|
||||||
|
* and Katherine Flavel <kate@elide.org>)
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <poll.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
#include "netutils/telnetc.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#define MAX_USERS 64
|
||||||
|
#define LINEBUFFER_SIZE 256
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
struct user_s
|
||||||
|
{
|
||||||
|
char *name;
|
||||||
|
int sock;
|
||||||
|
struct telnet_s *telnet;
|
||||||
|
char linebuf[256];
|
||||||
|
int linepos;
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static const struct telnet_telopt_s g_telopts[] =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
TELNET_TELOPT_COMPRESS2, TELNET_WILL, TELNET_DONT
|
||||||
|
},
|
||||||
|
{
|
||||||
|
-1, 0, 0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct user_s g_users[MAX_USERS];
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static void linebuffer_push(char *buffer, size_t size, int *linepos,
|
||||||
|
char ch, void (*cb) (const char *line, int overflow,
|
||||||
|
void *ud), void *ud)
|
||||||
|
{
|
||||||
|
/* CRLF -- line terminator */
|
||||||
|
|
||||||
|
if (ch == '\n' && *linepos > 0 && buffer[*linepos - 1] == '\r')
|
||||||
|
{
|
||||||
|
/* NUL terminate (replaces \r in buffer), notify app, clear */
|
||||||
|
|
||||||
|
buffer[*linepos - 1] = 0;
|
||||||
|
cb(buffer, 0, ud);
|
||||||
|
*linepos = 0;
|
||||||
|
|
||||||
|
/* CRNUL -- just a CR */
|
||||||
|
}
|
||||||
|
else if (ch == 0 && *linepos > 0 && buffer[*linepos - 1] == '\r')
|
||||||
|
{
|
||||||
|
/* So nothing, the CR is already in the buffer */
|
||||||
|
|
||||||
|
/* Anything else (including technically invalid CR followed by anything
|
||||||
|
* besides LF or NUL -- just buffer if we have room \r
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
else if (*linepos != size)
|
||||||
|
{
|
||||||
|
buffer[(*linepos)++] = ch;
|
||||||
|
|
||||||
|
/* Buffer overflow */
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Terminate (NOTE: eats a byte), notify app, clear buffer */
|
||||||
|
|
||||||
|
buffer[size - 1] = 0;
|
||||||
|
cb(buffer, size - 1, ud);
|
||||||
|
*linepos = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _message(const char *from, const char *msg)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i != MAX_USERS; ++i)
|
||||||
|
{
|
||||||
|
if (g_users[i].sock != -1)
|
||||||
|
{
|
||||||
|
telnet_printf(g_users[i].telnet, "%s: %s\n", from, msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _send(int sock, const char *buffer, unsigned int size)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* Ignore on invalid socket */
|
||||||
|
|
||||||
|
if (sock == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Send data */
|
||||||
|
|
||||||
|
while (size > 0)
|
||||||
|
{
|
||||||
|
if ((ret = send(sock, buffer, size, 0)) == -1)
|
||||||
|
{
|
||||||
|
if (errno != EINTR && errno != ECONNRESET)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "send() failed: %d\n", errno);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (ret == 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "send() unexpectedly returned 0\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Update pointer and size to see if we've got more to send */
|
||||||
|
|
||||||
|
buffer += ret;
|
||||||
|
size -= ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Process input line */
|
||||||
|
|
||||||
|
static void _online(const char *line, int overflow, void *ud)
|
||||||
|
{
|
||||||
|
struct user_s *user = (struct user_s *)ud;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* If the user has no name, this is his "login" */
|
||||||
|
|
||||||
|
if (user->name == 0)
|
||||||
|
{
|
||||||
|
/* Must not be empty, must be at least 32 chars */
|
||||||
|
|
||||||
|
if (strlen(line) == 0 || strlen(line) > 32)
|
||||||
|
{
|
||||||
|
telnet_printf(user->telnet, "Invalid name.\nEnter name: ");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Must not already be in use */
|
||||||
|
|
||||||
|
for (i = 0; i != MAX_USERS; ++i)
|
||||||
|
{
|
||||||
|
if (g_users[i].name != 0 && strcmp(g_users[i].name, line) == 0)
|
||||||
|
{
|
||||||
|
telnet_printf(user->telnet, "Name in use.\nEnter name: ");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Keep name */
|
||||||
|
|
||||||
|
user->name = strdup(line);
|
||||||
|
telnet_printf(user->telnet, "Welcome, %s!\n", line);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If line is "quit" then, well, quit */
|
||||||
|
|
||||||
|
if (strcmp(line, "quit") == 0)
|
||||||
|
{
|
||||||
|
close(user->sock);
|
||||||
|
user->sock = -1;
|
||||||
|
_message(user->name, "** HAS QUIT **");
|
||||||
|
free(user->name);
|
||||||
|
user->name = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Just a message -- send to all users */
|
||||||
|
|
||||||
|
_message(user->name, line);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _input(struct user_s *user, const char *buffer, unsigned int size)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
for (i = 0; i != size; ++i)
|
||||||
|
{
|
||||||
|
linebuffer_push(user->linebuf, sizeof(user->linebuf), &user->linepos,
|
||||||
|
(char)buffer[i], _online, user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _event_handler(struct telnet_s *telnet,
|
||||||
|
union telnet_event_u *ev, void *user_data)
|
||||||
|
{
|
||||||
|
struct user_s *user = (struct user_s *)user_data;
|
||||||
|
|
||||||
|
switch (ev->type)
|
||||||
|
{
|
||||||
|
/* Data received */
|
||||||
|
|
||||||
|
case TELNET_EV_DATA:
|
||||||
|
_input(user, ev->data.buffer, ev->data.size);
|
||||||
|
telnet_negotiate(telnet, TELNET_WONT, TELNET_TELOPT_ECHO);
|
||||||
|
telnet_negotiate(telnet, TELNET_WILL, TELNET_TELOPT_ECHO);
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Data must be sent */
|
||||||
|
|
||||||
|
case TELNET_EV_SEND:
|
||||||
|
_send(user->sock, ev->data.buffer, ev->data.size);
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Enable compress2 if accepted by client */
|
||||||
|
|
||||||
|
case TELNET_EV_DO:
|
||||||
|
if (ev->neg.telopt == TELNET_TELOPT_COMPRESS2)
|
||||||
|
{
|
||||||
|
telnet_begin_compress2(telnet);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Error */
|
||||||
|
|
||||||
|
case TELNET_EV_ERROR:
|
||||||
|
close(user->sock);
|
||||||
|
user->sock = -1;
|
||||||
|
if (user->name != 0)
|
||||||
|
{
|
||||||
|
_message(user->name, "** HAS HAD AN ERROR **");
|
||||||
|
free(user->name);
|
||||||
|
user->name = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
telnet_free(user->telnet);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
/* Ignore */
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_BUILD_KERNEL
|
||||||
|
int main(int argc, FAR char *argv[])
|
||||||
|
#else
|
||||||
|
int chatd_main(int argc, char *argv[])
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
char buffer[512];
|
||||||
|
short listen_port;
|
||||||
|
int listen_sock;
|
||||||
|
int ret;
|
||||||
|
int i;
|
||||||
|
struct sockaddr_in addr;
|
||||||
|
socklen_t addrlen;
|
||||||
|
struct pollfd pfd[MAX_USERS + 1];
|
||||||
|
|
||||||
|
/* Check usage */
|
||||||
|
|
||||||
|
if (argc != 2)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Usage:\n %s <port>\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initialize data structures */
|
||||||
|
|
||||||
|
memset(&pfd, 0, sizeof(pfd));
|
||||||
|
memset(g_users, 0, sizeof(g_users));
|
||||||
|
|
||||||
|
for (i = 0; i != MAX_USERS; ++i)
|
||||||
|
{
|
||||||
|
g_users[i].sock = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Parse listening port */
|
||||||
|
|
||||||
|
listen_port = (short)strtol(argv[1], 0, 10);
|
||||||
|
|
||||||
|
/* Create listening socket */
|
||||||
|
|
||||||
|
if ((listen_sock = socket(AF_INET, SOCK_STREAM, 0)) == -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "socket() failed: %d\n", errno);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Reuse address option */
|
||||||
|
|
||||||
|
ret = 1;
|
||||||
|
setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, (void *)&ret, sizeof(ret));
|
||||||
|
|
||||||
|
/* Bind to listening addr/port */
|
||||||
|
|
||||||
|
memset(&addr, 0, sizeof(addr));
|
||||||
|
addr.sin_family = AF_INET;
|
||||||
|
addr.sin_addr.s_addr = INADDR_ANY;
|
||||||
|
addr.sin_port = htons(listen_port);
|
||||||
|
if (bind(listen_sock, (struct sockaddr *)&addr, sizeof(addr)) == -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "bind() failed: %d\n", errno);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Listen for clients */
|
||||||
|
|
||||||
|
if (listen(listen_sock, 5) == -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "listen() failed: %d\n", errno);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("LISTENING ON PORT %d\n", listen_port);
|
||||||
|
|
||||||
|
/* Initialize listening descriptors */
|
||||||
|
|
||||||
|
pfd[MAX_USERS].fd = listen_sock;
|
||||||
|
pfd[MAX_USERS].events = POLLIN;
|
||||||
|
|
||||||
|
/* Loop for ever */
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
/* Prepare for poll */
|
||||||
|
|
||||||
|
for (i = 0; i != MAX_USERS; ++i)
|
||||||
|
{
|
||||||
|
if (g_users[i].sock != -1)
|
||||||
|
{
|
||||||
|
pfd[i].fd = g_users[i].sock;
|
||||||
|
pfd[i].events = POLLIN;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pfd[i].fd = -1;
|
||||||
|
pfd[i].events = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Poll */
|
||||||
|
|
||||||
|
ret = poll(pfd, MAX_USERS + 1, -1);
|
||||||
|
if (ret == -1 && errno != EINTR)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "poll() failed: %d\n", errno);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* New connection */
|
||||||
|
|
||||||
|
if (pfd[MAX_USERS].revents & POLLIN)
|
||||||
|
{
|
||||||
|
/* Accept the sock */
|
||||||
|
|
||||||
|
addrlen = sizeof(addr);
|
||||||
|
if ((ret = accept(listen_sock, (struct sockaddr *)&addr,
|
||||||
|
&addrlen)) == -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "accept() failed: %d\n", errno);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Connection received.\n");
|
||||||
|
|
||||||
|
/* Find a free user */
|
||||||
|
|
||||||
|
for (i = 0; i != MAX_USERS; ++i)
|
||||||
|
{
|
||||||
|
if (g_users[i].sock == -1)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == MAX_USERS)
|
||||||
|
{
|
||||||
|
printf(" rejected (too many users)\n");
|
||||||
|
_send(ret, "Too many users.\r\n", 14);
|
||||||
|
close(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Init, welcome */
|
||||||
|
|
||||||
|
g_users[i].sock = ret;
|
||||||
|
g_users[i].telnet = telnet_init(g_telopts, _event_handler, 0, &g_users[i]);
|
||||||
|
telnet_negotiate(g_users[i].telnet, TELNET_WILL,
|
||||||
|
TELNET_TELOPT_COMPRESS2);
|
||||||
|
telnet_printf(g_users[i].telnet, "Enter name: ");
|
||||||
|
|
||||||
|
telnet_negotiate(g_users[i].telnet, TELNET_WILL, TELNET_TELOPT_ECHO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read from client */
|
||||||
|
|
||||||
|
for (i = 0; i != MAX_USERS; ++i)
|
||||||
|
{
|
||||||
|
/* Skip users that aren't actually connected */
|
||||||
|
|
||||||
|
if (g_users[i].sock == -1)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pfd[i].revents & POLLIN)
|
||||||
|
{
|
||||||
|
if ((ret = recv(g_users[i].sock, buffer, sizeof(buffer), 0)) > 0)
|
||||||
|
{
|
||||||
|
telnet_recv(g_users[i].telnet, buffer, ret);
|
||||||
|
}
|
||||||
|
else if (ret == 0)
|
||||||
|
{
|
||||||
|
printf("Connection closed.\n");
|
||||||
|
close(g_users[i].sock);
|
||||||
|
if (g_users[i].name != 0)
|
||||||
|
{
|
||||||
|
_message(g_users[i].name, "** HAS DISCONNECTED **");
|
||||||
|
free(g_users[i].name);
|
||||||
|
g_users[i].name = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
telnet_free(g_users[i].telnet);
|
||||||
|
g_users[i].sock = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (errno != EINTR)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "recv(client) failed: %d\n", errno);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Not that we can reach this, but GCC will cry if it's not here */
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
457
system/telnet/telnet_client.c
Normal file
457
system/telnet/telnet_client.c
Normal file
@ -0,0 +1,457 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* apps/system/telnet/telnet_client.c
|
||||||
|
*
|
||||||
|
* Leveraged from libtelnet, https://github.com/seanmiddleditch/libtelnet.
|
||||||
|
* Modified and re-released under the BSD license:
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* The original authors of libtelnet are listed below. Per their licesne,
|
||||||
|
* "The author or authors of this code dedicate any and all copyright
|
||||||
|
* interest in this code to the public domain. We make this dedication for
|
||||||
|
* the benefit of the public at large and to the detriment of our heirs and
|
||||||
|
* successors. We intend this dedication to be an overt act of
|
||||||
|
* relinquishment in perpetuity of all present and future rights to this
|
||||||
|
* code under copyright law."
|
||||||
|
*
|
||||||
|
* Author: Sean Middleditch <sean@sourcemud.org>
|
||||||
|
* (Also listed in the AUTHORS file are Jack Kelly <endgame.dos@gmail.com>
|
||||||
|
* and Katherine Flavel <kate@elide.org>)
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <poll.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_ZLIB
|
||||||
|
# include "zlib.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "system/readline.h"
|
||||||
|
#include "netutils/telnetc.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_NSH_TELNETD_PORT
|
||||||
|
# define DEFAULT_PORT CONFIG_NSH_TELNETD_PORT
|
||||||
|
#else
|
||||||
|
# define DEFAULT_PORT 23
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static struct telnet_s *g_telnet;
|
||||||
|
static int g_echo;
|
||||||
|
|
||||||
|
static const struct telnet_telopt_s g_telopts[] =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
TELNET_TELOPT_ECHO, TELNET_WONT, TELNET_DO
|
||||||
|
},
|
||||||
|
{
|
||||||
|
TELNET_TELOPT_TTYPE, TELNET_WILL, TELNET_DONT
|
||||||
|
},
|
||||||
|
{
|
||||||
|
TELNET_TELOPT_COMPRESS2, TELNET_WONT, TELNET_DO
|
||||||
|
},
|
||||||
|
{
|
||||||
|
TELNET_TELOPT_MSSP, TELNET_WONT, TELNET_DO
|
||||||
|
},
|
||||||
|
{
|
||||||
|
-1, 0, 0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static void send_local_input(char *buffer, int size)
|
||||||
|
{
|
||||||
|
static char crlf[] = { '\r', '\n' };
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i != size; ++i)
|
||||||
|
{
|
||||||
|
/* If we got a CR or LF, replace with CRLF NOTE that usually you'd get a
|
||||||
|
* CR in UNIX, but in raw mode we get LF instead (not sure why).
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (buffer[i] == '\r' || buffer[i] == '\n')
|
||||||
|
{
|
||||||
|
if (g_echo)
|
||||||
|
{
|
||||||
|
printf("\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
telnet_send(g_telnet, crlf, 2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (g_echo)
|
||||||
|
{
|
||||||
|
putchar(buffer[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
telnet_send(g_telnet, buffer + i, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void telnet_ev_send(int sock, const char *buffer, size_t size)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* Send data */
|
||||||
|
|
||||||
|
while (size > 0)
|
||||||
|
{
|
||||||
|
if ((ret = send(sock, buffer, size, 0)) == -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "send() failed: %d\n", errno);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
else if (ret == 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "send() unexpectedly returned 0\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Update pointer and size to see if we've got more to send */
|
||||||
|
|
||||||
|
buffer += ret;
|
||||||
|
size -= ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _event_handler(struct telnet_s *telnet,
|
||||||
|
union telnet_event_u *ev, void *user_data)
|
||||||
|
{
|
||||||
|
int sock = *(int *)user_data;
|
||||||
|
|
||||||
|
switch (ev->type)
|
||||||
|
{
|
||||||
|
/* Data received */
|
||||||
|
|
||||||
|
case TELNET_EV_DATA:
|
||||||
|
printf("%.*s", (int)ev->data.size, ev->data.buffer);
|
||||||
|
fflush(stdout);
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Data must be sent */
|
||||||
|
|
||||||
|
case TELNET_EV_SEND:
|
||||||
|
telnet_ev_send(sock, ev->data.buffer, ev->data.size);
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Request to enable remote feature (or receipt) */
|
||||||
|
|
||||||
|
case TELNET_EV_WILL:
|
||||||
|
/* We'll agree to turn off our echo if server wants us to stop */
|
||||||
|
|
||||||
|
if (ev->neg.telopt == TELNET_TELOPT_ECHO)
|
||||||
|
{
|
||||||
|
g_echo = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Notification of disabling remote feature (or receipt) */
|
||||||
|
|
||||||
|
case TELNET_EV_WONT:
|
||||||
|
if (ev->neg.telopt == TELNET_TELOPT_ECHO)
|
||||||
|
{
|
||||||
|
g_echo = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Request to enable local feature (or receipt) */
|
||||||
|
|
||||||
|
case TELNET_EV_DO:
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Demand to disable local feature (or receipt) */
|
||||||
|
|
||||||
|
case TELNET_EV_DONT:
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Respond to TTYPE commands */
|
||||||
|
|
||||||
|
case TELNET_EV_TTYPE:
|
||||||
|
/* Respond with our terminal type, if requested */
|
||||||
|
|
||||||
|
if (ev->ttype.cmd == TELNET_TTYPE_SEND)
|
||||||
|
{
|
||||||
|
telnet_ttype_is(telnet, getenv("TERM"));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Respond to particular subnegotiations */
|
||||||
|
|
||||||
|
case TELNET_EV_SUBNEGOTIATION:
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Error */
|
||||||
|
|
||||||
|
case TELNET_EV_ERROR:
|
||||||
|
fprintf(stderr, "ERROR: %s\n", ev->error.msg);
|
||||||
|
exit(1);
|
||||||
|
|
||||||
|
default:
|
||||||
|
/* Ignore */
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void show_usage(const char *progname, int exitcode)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Usage:\n");
|
||||||
|
fprintf(stderr, "\t%s <server-IP-addr> [<port>]\n", progname);
|
||||||
|
fprintf(stderr, "Where:\n");
|
||||||
|
fprintf(stderr, "\t<server-IP-addr> is the address of the Telnet server. Either\n");
|
||||||
|
fprintf(stderr, "\t\tIPv4 form: ddd.ddd.ddd.ddd\n");
|
||||||
|
fprintf(stderr, "\t\tIPv6 form: xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx\n");
|
||||||
|
fprintf(stderr, "\t<port> is the (optional) listening port of the Telnet server.\n");
|
||||||
|
fprintf(stderr, "\t\tDefault: %u\n", DEFAULT_PORT);
|
||||||
|
exit(exitcode) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_BUILD_KERNEL
|
||||||
|
int main(int argc, FAR char *argv[])
|
||||||
|
#else
|
||||||
|
int telnet_main(int argc, char *argv[])
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
char buffer[512];
|
||||||
|
union
|
||||||
|
{
|
||||||
|
struct sockaddr generic;
|
||||||
|
#ifdef CONFIG_NET_IPv6
|
||||||
|
struct sockaddr_in6 ipv6;
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_NET_IPv4
|
||||||
|
struct sockaddr_in ipv4;
|
||||||
|
#endif
|
||||||
|
} server;
|
||||||
|
union
|
||||||
|
{
|
||||||
|
#ifdef CONFIG_NET_IPv6
|
||||||
|
struct sockaddr_in6 ipv6;
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_NET_IPv4
|
||||||
|
struct sockaddr_in ipv4;
|
||||||
|
#endif
|
||||||
|
} local;
|
||||||
|
struct pollfd pfd[2];
|
||||||
|
sa_family_t family;
|
||||||
|
uint16_t addrlen;
|
||||||
|
int portno;
|
||||||
|
int sock;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* Check usage */
|
||||||
|
|
||||||
|
if (argc < 2 || argc > 3)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Invalid number of arguments\n");
|
||||||
|
show_usage(argv[0], 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert the port number to binary if provided */
|
||||||
|
|
||||||
|
if (argc == 3)
|
||||||
|
{
|
||||||
|
portno = atoi(argv[2]);
|
||||||
|
if (portno < 0 || portno > UINT16_MAX)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Invalid port number\n");
|
||||||
|
show_usage(argv[0], 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
portno = DEFAULT_PORT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert the <server-IP-addr> argument into a binary address */
|
||||||
|
|
||||||
|
memset(&local, 0, sizeof(local));
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLES_NETTEST_IPv6
|
||||||
|
addrlen = sizeof(struct sockaddr_in6);
|
||||||
|
family = AF_INET6;
|
||||||
|
|
||||||
|
local.ipv6.sin6_family = AF_INET6;
|
||||||
|
server.ipv6.sin6_family = AF_INET6;
|
||||||
|
server.ipv6.sin6_port = htons(portno);
|
||||||
|
|
||||||
|
ret = inet_pton(AF_INET6, argv[1], server.ipv6.sin6_addr.s6_addr);
|
||||||
|
if (ret < 0)
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_EXAMPLES_NETTEST_IPv
|
||||||
|
{
|
||||||
|
addrlen = sizeof(struct sockaddr_in);
|
||||||
|
family = AF_INET;
|
||||||
|
|
||||||
|
local.ipv4.sin_family = AF_INET;
|
||||||
|
server.ipv4.sin_family = AF_INET;
|
||||||
|
server.ipv4.sin_port = htons(portno);
|
||||||
|
|
||||||
|
ret = inet_pton(AF_INET, argv[1], &server.ipv4.sin_addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret < 0)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: <server-IP-addr> is invalid\n");
|
||||||
|
show_usage(argv[0], 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create server socket */
|
||||||
|
|
||||||
|
sock = socket(family, SOCK_STREAM, 0);
|
||||||
|
if (sock < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "socket() failed: %d\n", errno);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Bind server socket */
|
||||||
|
|
||||||
|
ret = bind(sock, (struct sockaddr *)&local, addrlen);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "bind() failed: %d\n", errno);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Connect */
|
||||||
|
|
||||||
|
ret = connect(sock, &server.generic, addrlen);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "connect() failed: %d\n", errno);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set input echoing on by default */
|
||||||
|
|
||||||
|
g_echo = 1;
|
||||||
|
|
||||||
|
/* Initialize telnet box */
|
||||||
|
|
||||||
|
g_telnet = telnet_init(g_telopts, _event_handler, 0, &sock);
|
||||||
|
|
||||||
|
/* Initialize poll descriptors */
|
||||||
|
|
||||||
|
memset(pfd, 0, sizeof(pfd));
|
||||||
|
pfd[0].fd = 1;
|
||||||
|
pfd[0].events = POLLIN;
|
||||||
|
pfd[1].fd = sock;
|
||||||
|
pfd[1].events = POLLIN;
|
||||||
|
|
||||||
|
/* Loop while both connections are open */
|
||||||
|
|
||||||
|
while (poll(pfd, 2, -1) != -1)
|
||||||
|
{
|
||||||
|
/* Read from stdin */
|
||||||
|
|
||||||
|
if (pfd[0].revents & POLLIN)
|
||||||
|
{
|
||||||
|
ret = std_readline(buffer, sizeof(buffer));
|
||||||
|
if (ret > 0)
|
||||||
|
{
|
||||||
|
send_local_input(buffer, ret);
|
||||||
|
}
|
||||||
|
else if (ret == 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "recv(server) failed: %d\n", errno);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read from client */
|
||||||
|
|
||||||
|
if (pfd[1].revents & POLLIN)
|
||||||
|
{
|
||||||
|
if ((ret = recv(sock, buffer, sizeof(buffer), 0)) > 0)
|
||||||
|
{
|
||||||
|
telnet_recv(g_telnet, buffer, ret);
|
||||||
|
}
|
||||||
|
else if (ret == 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(stderr, "recv(client) failed: %d\n", errno);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Clean up */
|
||||||
|
|
||||||
|
telnet_free(g_telnet);
|
||||||
|
close(sock);
|
||||||
|
return 0;
|
||||||
|
}
|
@ -47,8 +47,9 @@ STACKSIZE = 4096
|
|||||||
# IEEE 802.15.4 SAK (Swiss Army Knife)
|
# IEEE 802.15.4 SAK (Swiss Army Knife)
|
||||||
|
|
||||||
ASRCS =
|
ASRCS =
|
||||||
CSRCS = i8sak_acceptassoc.c i8sak_assoc.c i8sak_blaster.c i8sak_poll.c
|
CSRCS = i8sak_acceptassoc.c i8sak_assoc.c i8sak_scan.c i8sak_blaster.c i8sak_poll.c
|
||||||
CSRCS += i8sak_sniffer.c i8sak_startpan.c i8sak_tx.c wpanlistener.c
|
CSRCS += i8sak_sniffer.c i8sak_startpan.c i8sak_tx.c i8sak_chan.c i8sak_coordinfo.c
|
||||||
|
CSRCS += wpanlistener.c
|
||||||
MAINSRC = i8sak_main.c
|
MAINSRC = i8sak_main.c
|
||||||
|
|
||||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||||
|
@ -99,7 +99,14 @@
|
|||||||
/* /dev/ is 5 characters */
|
/* /dev/ is 5 characters */
|
||||||
#define I8SAK_DAEMONNAME_FMTLEN (6 + (I8SAK_MAX_DEVNAME-5) + 1)
|
#define I8SAK_DAEMONNAME_FMTLEN (6 + (I8SAK_MAX_DEVNAME-5) + 1)
|
||||||
|
|
||||||
|
/* Helper Macros *************************************************************/
|
||||||
|
|
||||||
|
#define PRINT_COORDEADDR(eaddr) \
|
||||||
|
printf(" Coordinator EADDR: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n", \
|
||||||
|
eaddr[0], eaddr[1], eaddr[2], eaddr[3], eaddr[4], eaddr[5], eaddr[6], eaddr[7]);
|
||||||
|
|
||||||
|
#define PRINT_COORDSADDR(saddr) \
|
||||||
|
printf(" Coordinator SADDR: %02X:%02X\n", saddr[0], saddr[1]);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Types
|
* Public Types
|
||||||
@ -146,7 +153,7 @@ struct i8sak_s
|
|||||||
|
|
||||||
/* Settings */
|
/* Settings */
|
||||||
|
|
||||||
uint8_t chnum;
|
uint8_t chan;
|
||||||
uint8_t chpage;
|
uint8_t chpage;
|
||||||
struct ieee802154_addr_s addr;
|
struct ieee802154_addr_s addr;
|
||||||
struct ieee802154_addr_s ep;
|
struct ieee802154_addr_s ep;
|
||||||
@ -154,6 +161,9 @@ struct i8sak_s
|
|||||||
uint8_t payload[IEEE802154_MAX_MAC_PAYLOAD_SIZE];
|
uint8_t payload[IEEE802154_MAX_MAC_PAYLOAD_SIZE];
|
||||||
uint16_t payload_len;
|
uint16_t payload_len;
|
||||||
int blasterperiod;
|
int blasterperiod;
|
||||||
|
|
||||||
|
struct ieee802154_pandesc_s pandescs[CONFIG_MAC802154_NPANDESC];
|
||||||
|
uint8_t npandesc;
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -175,10 +185,13 @@ bool i8sak_str2bool(FAR const char *str);
|
|||||||
void i8sak_startpan_cmd (FAR struct i8sak_s *i8sak, int argc, FAR char *argv[]);
|
void i8sak_startpan_cmd (FAR struct i8sak_s *i8sak, int argc, FAR char *argv[]);
|
||||||
void i8sak_acceptassoc_cmd (FAR struct i8sak_s *i8sak, int argc, FAR char *argv[]);
|
void i8sak_acceptassoc_cmd (FAR struct i8sak_s *i8sak, int argc, FAR char *argv[]);
|
||||||
void i8sak_assoc_cmd (FAR struct i8sak_s *i8sak, int argc, FAR char *argv[]);
|
void i8sak_assoc_cmd (FAR struct i8sak_s *i8sak, int argc, FAR char *argv[]);
|
||||||
|
void i8sak_scan_cmd (FAR struct i8sak_s *i8sak, int argc, FAR char *argv[]);
|
||||||
void i8sak_tx_cmd (FAR struct i8sak_s *i8sak, int argc, FAR char *argv[]);
|
void i8sak_tx_cmd (FAR struct i8sak_s *i8sak, int argc, FAR char *argv[]);
|
||||||
void i8sak_poll_cmd (FAR struct i8sak_s *i8sak, int argc, FAR char *argv[]);
|
void i8sak_poll_cmd (FAR struct i8sak_s *i8sak, int argc, FAR char *argv[]);
|
||||||
void i8sak_sniffer_cmd (FAR struct i8sak_s *i8sak, int argc, FAR char *argv[]);
|
void i8sak_sniffer_cmd (FAR struct i8sak_s *i8sak, int argc, FAR char *argv[]);
|
||||||
void i8sak_blaster_cmd (FAR struct i8sak_s *i8sak, int argc, FAR char *argv[]);
|
void i8sak_blaster_cmd (FAR struct i8sak_s *i8sak, int argc, FAR char *argv[]);
|
||||||
|
void i8sak_chan_cmd (FAR struct i8sak_s *i8sak, int argc, FAR char *argv[]);
|
||||||
|
void i8sak_coordinfo_cmd (FAR struct i8sak_s *i8sak, int argc, FAR char *argv[]);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Inline Functions
|
* Inline Functions
|
||||||
|
@ -76,6 +76,7 @@ void i8sak_acceptassoc_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[]
|
|||||||
bool acceptall = true; /* start off assuming we are going to allow all connections */
|
bool acceptall = true; /* start off assuming we are going to allow all connections */
|
||||||
int option;
|
int option;
|
||||||
int optcnt;
|
int optcnt;
|
||||||
|
int fd;
|
||||||
|
|
||||||
optcnt = 0;
|
optcnt = 0;
|
||||||
while ((option = getopt(argc, argv, ":he:")) != ERROR)
|
while ((option = getopt(argc, argv, ":he:")) != ERROR)
|
||||||
@ -115,6 +116,15 @@ void i8sak_acceptassoc_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[]
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fd = open(i8sak->devname, O_RDWR);
|
||||||
|
if (fd < 0)
|
||||||
|
{
|
||||||
|
printf("cannot open %s, errno=%d\n", i8sak->devname, errno);
|
||||||
|
i8sak_cmd_error(i8sak);
|
||||||
|
}
|
||||||
|
|
||||||
|
ieee802154_setassocpermit(fd, true);
|
||||||
|
|
||||||
if (!optcnt)
|
if (!optcnt)
|
||||||
{
|
{
|
||||||
i8sak->acceptall = acceptall;
|
i8sak->acceptall = acceptall;
|
||||||
|
@ -79,10 +79,12 @@ void i8sak_assoc_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
|
|||||||
{
|
{
|
||||||
struct ieee802154_assoc_req_s assocreq;
|
struct ieee802154_assoc_req_s assocreq;
|
||||||
struct wpanlistener_eventfilter_s filter;
|
struct wpanlistener_eventfilter_s filter;
|
||||||
|
FAR struct ieee802154_pandesc_s *pandesc;
|
||||||
int fd;
|
int fd;
|
||||||
int option;
|
int option;
|
||||||
int optcnt;
|
int optcnt;
|
||||||
int ret;
|
int ret;
|
||||||
|
uint8_t resindex;
|
||||||
|
|
||||||
/* If the addresses has never been automatically or manually set before, set
|
/* If the addresses has never been automatically or manually set before, set
|
||||||
* it assuming that we are the default device address and the endpoint is the
|
* it assuming that we are the default device address and the endpoint is the
|
||||||
@ -96,7 +98,7 @@ void i8sak_assoc_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
optcnt = 0;
|
optcnt = 0;
|
||||||
while ((option = getopt(argc, argv, ":hs:e:")) != ERROR)
|
while ((option = getopt(argc, argv, ":hr:s:e:")) != ERROR)
|
||||||
{
|
{
|
||||||
optcnt++;
|
optcnt++;
|
||||||
switch (option)
|
switch (option)
|
||||||
@ -105,12 +107,31 @@ void i8sak_assoc_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
|
|||||||
fprintf(stderr, "Requests association with endpoint\n"
|
fprintf(stderr, "Requests association with endpoint\n"
|
||||||
"Usage: %s [-h]\n"
|
"Usage: %s [-h]\n"
|
||||||
" -h = this help menu\n"
|
" -h = this help menu\n"
|
||||||
|
" -r = use scan result index\n"
|
||||||
, argv[0]);
|
, argv[0]);
|
||||||
|
|
||||||
/* Must manually reset optind if we are going to exit early */
|
/* Must manually reset optind if we are going to exit early */
|
||||||
|
|
||||||
optind = -1;
|
optind = -1;
|
||||||
return;
|
return;
|
||||||
|
case 'r':
|
||||||
|
resindex = i8sak_str2luint8(optarg);
|
||||||
|
|
||||||
|
if (resindex >= i8sak->npandesc)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: missing argument\n");
|
||||||
|
/* Must manually reset optind if we are going to exit early */
|
||||||
|
|
||||||
|
optind = -1;
|
||||||
|
i8sak_cmd_error(i8sak); /* This exits for us */
|
||||||
|
}
|
||||||
|
|
||||||
|
pandesc = &i8sak->pandescs[resindex];
|
||||||
|
|
||||||
|
i8sak->chan = pandesc->chan;
|
||||||
|
i8sak->chpage = pandesc->chpage;
|
||||||
|
memcpy(&i8sak->ep, &pandesc->coordaddr, sizeof(struct ieee802154_addr_s));
|
||||||
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
/* Parse extended address and put it into the i8sak instance */
|
/* Parse extended address and put it into the i8sak instance */
|
||||||
@ -158,15 +179,6 @@ void i8sak_assoc_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
|
|||||||
i8sak_cmd_error(i8sak);
|
i8sak_cmd_error(i8sak);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc < 2)
|
|
||||||
{
|
|
||||||
/* TODO: Perform a scan operation here, to determine addressing information
|
|
||||||
* of coordinator.
|
|
||||||
*/
|
|
||||||
|
|
||||||
fprintf(stderr, "i8sak: scan not implemented. Using default values\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Register new callback for receiving the association notifications */
|
/* Register new callback for receiving the association notifications */
|
||||||
|
|
||||||
memset(&filter, 0, sizeof(struct wpanlistener_eventfilter_s));
|
memset(&filter, 0, sizeof(struct wpanlistener_eventfilter_s));
|
||||||
@ -177,7 +189,7 @@ void i8sak_assoc_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
|
|||||||
|
|
||||||
printf("i8sak: issuing ASSOC. request\n");
|
printf("i8sak: issuing ASSOC. request\n");
|
||||||
|
|
||||||
assocreq.chnum = i8sak->chnum;
|
assocreq.chan = i8sak->chan;
|
||||||
assocreq.chpage = i8sak->chpage;
|
assocreq.chpage = i8sak->chpage;
|
||||||
|
|
||||||
memcpy(&assocreq.coordaddr, &i8sak->ep, sizeof(struct ieee802154_addr_s));
|
memcpy(&assocreq.coordaddr, &i8sak->ep, sizeof(struct ieee802154_addr_s));
|
||||||
|
139
wireless/ieee802154/i8sak/i8sak_chan.c
Normal file
139
wireless/ieee802154/i8sak/i8sak_chan.c
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* apps/wireless/ieee802154/i8sak/i8sak_chan.c
|
||||||
|
* IEEE 802.15.4 Swiss Army Knife
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017 Verge Inc. All rights reserved.
|
||||||
|
* Author: Anthony Merlino <anthony@vergeaero.com>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <nuttx/fs/ioctl.h>
|
||||||
|
|
||||||
|
#include "i8sak.h"
|
||||||
|
|
||||||
|
#include <nuttx/wireless/ieee802154/ieee802154_ioctl.h>
|
||||||
|
#include <nuttx/wireless/ieee802154/ieee802154_mac.h>
|
||||||
|
#include "wireless/ieee802154.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name : i8sak_chan_cmd
|
||||||
|
*
|
||||||
|
* Description :
|
||||||
|
* Try and extract data from the coordinator
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void i8sak_chan_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
|
||||||
|
{
|
||||||
|
int option;
|
||||||
|
int fd;
|
||||||
|
int argind;
|
||||||
|
bool getchan = false;
|
||||||
|
uint8_t channel;
|
||||||
|
|
||||||
|
argind = 1;
|
||||||
|
while ((option = getopt(argc, argv, ":hg")) != ERROR)
|
||||||
|
{
|
||||||
|
switch (option)
|
||||||
|
{
|
||||||
|
argind++;
|
||||||
|
case 'h':
|
||||||
|
fprintf(stderr, "Polls coordinator for data\n"
|
||||||
|
"Usage: %s [-h]\n"
|
||||||
|
" -h = this help menu\n"
|
||||||
|
, argv[0]);
|
||||||
|
/* Must manually reset optind if we are going to exit early */
|
||||||
|
|
||||||
|
optind = -1;
|
||||||
|
return;
|
||||||
|
case 'g':
|
||||||
|
getchan = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ':':
|
||||||
|
fprintf(stderr, "ERROR: missing argument\n");
|
||||||
|
/* Must manually reset optind if we are going to exit early */
|
||||||
|
|
||||||
|
optind = -1;
|
||||||
|
i8sak_cmd_error(i8sak); /* This exits for us */
|
||||||
|
case '?':
|
||||||
|
fprintf(stderr, "ERROR: unknown argument\n");
|
||||||
|
/* Must manually reset optind if we are going to exit early */
|
||||||
|
|
||||||
|
optind = -1;
|
||||||
|
i8sak_cmd_error(i8sak); /* This exits for us */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!getchan)
|
||||||
|
{
|
||||||
|
if (argc < argind + 1)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: missing channel\n");
|
||||||
|
i8sak_cmd_error(i8sak); /* This exits for us */
|
||||||
|
}
|
||||||
|
|
||||||
|
channel = i8sak_str2luint8(argv[argind]);
|
||||||
|
}
|
||||||
|
|
||||||
|
fd = open(i8sak->devname, O_RDWR);
|
||||||
|
if (fd < 0)
|
||||||
|
{
|
||||||
|
printf("cannot open %s, errno=%d\n", i8sak->devname, errno);
|
||||||
|
i8sak_cmd_error(i8sak);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getchan)
|
||||||
|
{
|
||||||
|
ieee802154_getchan(fd, &channel);
|
||||||
|
printf("i8sak: Channel: %d\n", (int)channel);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("i8sak: Setting Channel: %d\n", (int)channel);
|
||||||
|
ieee802154_setchan(fd, channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
}
|
141
wireless/ieee802154/i8sak/i8sak_coordinfo.c
Normal file
141
wireless/ieee802154/i8sak/i8sak_coordinfo.c
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* apps/wireless/ieee802154/i8sak/i8sak_coordinfo.c
|
||||||
|
* IEEE 802.15.4 Swiss Army Knife
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017 Verge Inc. All rights reserved.
|
||||||
|
* Author: Anthony Merlino <anthony@vergeaero.com>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <nuttx/fs/ioctl.h>
|
||||||
|
|
||||||
|
#include "i8sak.h"
|
||||||
|
|
||||||
|
#include <nuttx/wireless/ieee802154/ieee802154_ioctl.h>
|
||||||
|
#include <nuttx/wireless/ieee802154/ieee802154_mac.h>
|
||||||
|
#include "wireless/ieee802154.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name : i8sak_coordinfo_cmd
|
||||||
|
*
|
||||||
|
* Description :
|
||||||
|
* Print various coordinator attributes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void i8sak_coordinfo_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
|
||||||
|
{
|
||||||
|
int option;
|
||||||
|
int fd;
|
||||||
|
int argind;
|
||||||
|
bool geteaddr = false;
|
||||||
|
bool getsaddr = false;
|
||||||
|
uint8_t eaddr[IEEE802154_EADDRSIZE];
|
||||||
|
uint8_t saddr[IEEE802154_SADDRSIZE];
|
||||||
|
|
||||||
|
argind = 1;
|
||||||
|
while ((option = getopt(argc, argv, ":haes")) != ERROR)
|
||||||
|
{
|
||||||
|
switch (option)
|
||||||
|
{
|
||||||
|
argind++;
|
||||||
|
case 'h':
|
||||||
|
fprintf(stderr, "Prints coordinator attributes\n"
|
||||||
|
"Usage: %s [-h]\n"
|
||||||
|
" -h = this help menu\n"
|
||||||
|
, argv[0]);
|
||||||
|
/* Must manually reset optind if we are going to exit early */
|
||||||
|
|
||||||
|
optind = -1;
|
||||||
|
return;
|
||||||
|
|
||||||
|
case 'a':
|
||||||
|
geteaddr = true;
|
||||||
|
getsaddr = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'e':
|
||||||
|
geteaddr = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 's':
|
||||||
|
getsaddr = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ':':
|
||||||
|
fprintf(stderr, "ERROR: missing argument\n");
|
||||||
|
/* Must manually reset optind if we are going to exit early */
|
||||||
|
|
||||||
|
optind = -1;
|
||||||
|
i8sak_cmd_error(i8sak); /* This exits for us */
|
||||||
|
case '?':
|
||||||
|
fprintf(stderr, "ERROR: unknown argument\n");
|
||||||
|
/* Must manually reset optind if we are going to exit early */
|
||||||
|
|
||||||
|
optind = -1;
|
||||||
|
i8sak_cmd_error(i8sak); /* This exits for us */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fd = open(i8sak->devname, O_RDWR);
|
||||||
|
if (fd < 0)
|
||||||
|
{
|
||||||
|
printf("cannot open %s, errno=%d\n", i8sak->devname, errno);
|
||||||
|
i8sak_cmd_error(i8sak);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (geteaddr)
|
||||||
|
{
|
||||||
|
ieee802154_getcoordeaddr(fd, eaddr);
|
||||||
|
PRINT_COORDEADDR(eaddr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getsaddr)
|
||||||
|
{
|
||||||
|
ieee802154_getcoordsaddr(fd, saddr);
|
||||||
|
PRINT_COORDSADDR(saddr);
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
}
|
@ -104,10 +104,13 @@ static const struct i8sak_command_s g_i8sak_commands[] =
|
|||||||
{"startpan", (CODE void *)i8sak_startpan_cmd},
|
{"startpan", (CODE void *)i8sak_startpan_cmd},
|
||||||
{"acceptassoc", (CODE void *)i8sak_acceptassoc_cmd},
|
{"acceptassoc", (CODE void *)i8sak_acceptassoc_cmd},
|
||||||
{"assoc", (CODE void *)i8sak_assoc_cmd},
|
{"assoc", (CODE void *)i8sak_assoc_cmd},
|
||||||
|
{"scan", (CODE void *)i8sak_scan_cmd},
|
||||||
{"tx", (CODE void *)i8sak_tx_cmd},
|
{"tx", (CODE void *)i8sak_tx_cmd},
|
||||||
{"poll", (CODE void *)i8sak_poll_cmd},
|
{"poll", (CODE void *)i8sak_poll_cmd},
|
||||||
{"sniffer", (CODE void *)i8sak_sniffer_cmd},
|
{"sniffer", (CODE void *)i8sak_sniffer_cmd},
|
||||||
{"blaster", (CODE void *)i8sak_blaster_cmd},
|
{"blaster", (CODE void *)i8sak_blaster_cmd},
|
||||||
|
{"chan", (CODE void *)i8sak_chan_cmd},
|
||||||
|
{"coordinfo", (CODE void *)i8sak_coordinfo_cmd},
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NCOMMANDS (sizeof(g_i8sak_commands) / sizeof(struct i8sak_command_s))
|
#define NCOMMANDS (sizeof(g_i8sak_commands) / sizeof(struct i8sak_command_s))
|
||||||
@ -559,7 +562,7 @@ static int i8sak_setup(FAR struct i8sak_s *i8sak, FAR const char *devname)
|
|||||||
i8sak->daemon_started = false;
|
i8sak->daemon_started = false;
|
||||||
i8sak->daemon_shutdown = false;
|
i8sak->daemon_shutdown = false;
|
||||||
|
|
||||||
i8sak->chnum = CONFIG_IEEE802154_I8SAK_CHNUM;
|
i8sak->chan = CONFIG_IEEE802154_I8SAK_CHNUM;
|
||||||
i8sak->chpage = CONFIG_IEEE802154_I8SAK_CHPAGE;
|
i8sak->chpage = CONFIG_IEEE802154_I8SAK_CHPAGE;
|
||||||
|
|
||||||
if (strlen(devname) > I8SAK_MAX_DEVNAME)
|
if (strlen(devname) > I8SAK_MAX_DEVNAME)
|
||||||
@ -730,11 +733,14 @@ static int i8sak_showusage(FAR const char *progname, int exitcode)
|
|||||||
fprintf(stderr, "Usage: %s\n"
|
fprintf(stderr, "Usage: %s\n"
|
||||||
" startpan [-h]\n"
|
" startpan [-h]\n"
|
||||||
" acceptassoc [-h|e <eaddr>]\n"
|
" acceptassoc [-h|e <eaddr>]\n"
|
||||||
" assoc [-h] [<panid>] \n"
|
" scan [-h|p|a|e] minch-maxch\n"
|
||||||
|
" assoc [-h] [<panid>]\n"
|
||||||
" tx [-h|d] <hex-payload>\n"
|
" tx [-h|d] <hex-payload>\n"
|
||||||
" poll [-h]\n"
|
" poll [-h]\n"
|
||||||
" blaster [-h|q|f <hex payload>|p <period_ms>]\n"
|
" blaster [-h|q|f <hex payload>|p <period_ms>]\n"
|
||||||
" sniffer [-h|q]\n"
|
" sniffer [-h|q]\n"
|
||||||
|
" chan [-h|g] [<chan>]\n"
|
||||||
|
" coordinfo [-h|a|e|s]\n"
|
||||||
, progname);
|
, progname);
|
||||||
exit(exitcode);
|
exit(exitcode);
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,6 @@ void i8sak_poll_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
|
|||||||
int fd;
|
int fd;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = OK;
|
|
||||||
while ((option = getopt(argc, argv, ":h")) != ERROR)
|
while ((option = getopt(argc, argv, ":h")) != ERROR)
|
||||||
{
|
{
|
||||||
switch (option)
|
switch (option)
|
||||||
@ -112,11 +111,6 @@ void i8sak_poll_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret != OK)
|
|
||||||
{
|
|
||||||
i8sak_cmd_error(i8sak);
|
|
||||||
}
|
|
||||||
|
|
||||||
fd = open(i8sak->devname, O_RDWR);
|
fd = open(i8sak->devname, O_RDWR);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
|
243
wireless/ieee802154/i8sak/i8sak_scan.c
Normal file
243
wireless/ieee802154/i8sak/i8sak_scan.c
Normal file
@ -0,0 +1,243 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* apps/wireless/ieee802154/i8sak/i8sak_scan.c
|
||||||
|
* IEEE 802.15.4 Swiss Army Knife
|
||||||
|
*
|
||||||
|
* Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved.
|
||||||
|
* Copyright (C) 2017 Verge Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* Author: Anthony Merlino <anthony@vergeaero.com>
|
||||||
|
* Author: Gregory Nuttx <gnutt@nuttx.org>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <nuttx/fs/ioctl.h>
|
||||||
|
|
||||||
|
#include "i8sak.h"
|
||||||
|
|
||||||
|
#include <nuttx/wireless/ieee802154/ieee802154_ioctl.h>
|
||||||
|
#include <nuttx/wireless/ieee802154/ieee802154_mac.h>
|
||||||
|
#include "wireless/ieee802154.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static void scan_eventcb(FAR struct ieee802154_notif_s *notif, FAR void *arg);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name : i8sak_scan_cmd
|
||||||
|
*
|
||||||
|
* Description :
|
||||||
|
* Request association with the Coordinator
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void i8sak_scan_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
|
||||||
|
{
|
||||||
|
struct ieee802154_scan_req_s scan;
|
||||||
|
struct wpanlistener_eventfilter_s filter;
|
||||||
|
int fd;
|
||||||
|
int option;
|
||||||
|
int argind;
|
||||||
|
int i;
|
||||||
|
int minchannel;
|
||||||
|
int maxchannel;
|
||||||
|
|
||||||
|
scan.type = IEEE802154_SCANTYPE_PASSIVE;
|
||||||
|
|
||||||
|
argind = 1;
|
||||||
|
while ((option = getopt(argc, argv, ":hpae")) != ERROR)
|
||||||
|
{
|
||||||
|
argind++;
|
||||||
|
switch (option)
|
||||||
|
{
|
||||||
|
case 'h':
|
||||||
|
fprintf(stderr, "Requests association with endpoint\n"
|
||||||
|
"Usage: %s [-h|p|a|e] minCh-maxCh\n"
|
||||||
|
" -h = this help menu\n"
|
||||||
|
" -p = passive scan (default)\n"
|
||||||
|
" -a = active scan\n"
|
||||||
|
" -e = energy scan\n"
|
||||||
|
, argv[0]);
|
||||||
|
|
||||||
|
/* Must manually reset optind if we are going to exit early */
|
||||||
|
|
||||||
|
optind = -1;
|
||||||
|
return;
|
||||||
|
|
||||||
|
case 'p':
|
||||||
|
scan.type = IEEE802154_SCANTYPE_PASSIVE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'a':
|
||||||
|
scan.type = IEEE802154_SCANTYPE_ACTIVE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'e':
|
||||||
|
scan.type = IEEE802154_SCANTYPE_ED;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ':':
|
||||||
|
fprintf(stderr, "ERROR: missing argument\n");
|
||||||
|
/* Must manually reset optind if we are going to exit early */
|
||||||
|
|
||||||
|
optind = -1;
|
||||||
|
i8sak_cmd_error(i8sak); /* This exits for us */
|
||||||
|
|
||||||
|
case '?':
|
||||||
|
fprintf(stderr, "ERROR: unknown argument\n");
|
||||||
|
/* Must manually reset optind if we are going to exit early */
|
||||||
|
|
||||||
|
optind = -1;
|
||||||
|
i8sak_cmd_error(i8sak); /* This exits for us */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* There should always be one argument after the list option argument */
|
||||||
|
|
||||||
|
if (argc != argind + 1)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: invalid channel list\n");
|
||||||
|
i8sak_cmd_error(i8sak);
|
||||||
|
}
|
||||||
|
|
||||||
|
scan.duration = 5;
|
||||||
|
scan.chpage = i8sak->chpage;
|
||||||
|
|
||||||
|
/* Parse channel list */
|
||||||
|
|
||||||
|
sscanf(argv[argind], "%d-%d", &minchannel, &maxchannel);
|
||||||
|
|
||||||
|
scan.numchan = maxchannel - minchannel + 1;
|
||||||
|
|
||||||
|
if (scan.numchan > 15)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: too many channels\n");
|
||||||
|
i8sak_cmd_error(i8sak);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < scan.numchan; i++)
|
||||||
|
{
|
||||||
|
scan.channels[i] = minchannel + i;
|
||||||
|
}
|
||||||
|
|
||||||
|
fd = open(i8sak->devname, O_RDWR);
|
||||||
|
if (fd < 0)
|
||||||
|
{
|
||||||
|
printf("i8sak: cannot open %s, errno=%d\n", i8sak->devname, errno);
|
||||||
|
i8sak_cmd_error(i8sak);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Register new callback for receiving the scan confirmation notification */
|
||||||
|
|
||||||
|
memset(&filter, 0, sizeof(struct wpanlistener_eventfilter_s));
|
||||||
|
filter.confevents.scan = true;
|
||||||
|
|
||||||
|
wpanlistener_add_eventreceiver(&i8sak->wpanlistener, scan_eventcb, &filter,
|
||||||
|
(FAR void *)i8sak, true);
|
||||||
|
|
||||||
|
printf("i8sak: starting scan\n");
|
||||||
|
|
||||||
|
ieee802154_scan_req(fd, &scan);
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static void scan_eventcb(FAR struct ieee802154_notif_s *notif, FAR void *arg)
|
||||||
|
{
|
||||||
|
FAR struct i8sak_s *i8sak = (FAR struct i8sak_s *)arg;
|
||||||
|
FAR struct ieee802154_scan_conf_s *scan = ¬if->u.scanconf;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
printf("\n\ni8sak: Scan complete: %s\n",
|
||||||
|
IEEE802154_STATUS_STRING[scan->status]);
|
||||||
|
|
||||||
|
printf("Scan type: ");
|
||||||
|
|
||||||
|
switch (scan->type)
|
||||||
|
{
|
||||||
|
case IEEE802154_SCANTYPE_ACTIVE:
|
||||||
|
printf("Active\n");
|
||||||
|
break;
|
||||||
|
case IEEE802154_SCANTYPE_PASSIVE:
|
||||||
|
printf("Passive\n");
|
||||||
|
break;
|
||||||
|
case IEEE802154_SCANTYPE_ED:
|
||||||
|
printf("Energy\n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("Unknown\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Copy the results from the notification */
|
||||||
|
|
||||||
|
i8sak->npandesc = scan->numdesc;
|
||||||
|
memcpy(i8sak->pandescs, scan->pandescs,
|
||||||
|
sizeof(struct ieee802154_pandesc_s) * i8sak->npandesc);
|
||||||
|
|
||||||
|
printf("Scan results: \n");
|
||||||
|
|
||||||
|
for (i = 0; i < scan->numdesc; i++)
|
||||||
|
{
|
||||||
|
printf("Result %d\n", i);
|
||||||
|
printf(" Channel: %u\n", scan->pandescs[i].chan);
|
||||||
|
printf(" PAN ID: %02X:%02X\n",
|
||||||
|
scan->pandescs[i].coordaddr.panid[0],
|
||||||
|
scan->pandescs[i].coordaddr.panid[1]);
|
||||||
|
|
||||||
|
if (scan->pandescs[i].coordaddr.mode == IEEE802154_ADDRMODE_SHORT)
|
||||||
|
{
|
||||||
|
PRINT_COORDSADDR(scan->pandescs[i].coordaddr.saddr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PRINT_COORDEADDR(scan->pandescs[i].coordaddr.eaddr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -73,11 +73,12 @@ void i8sak_startpan_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
|
|||||||
{
|
{
|
||||||
struct ieee802154_reset_req_s resetreq;
|
struct ieee802154_reset_req_s resetreq;
|
||||||
struct ieee802154_start_req_s startreq;
|
struct ieee802154_start_req_s startreq;
|
||||||
|
bool beaconenabled = false;
|
||||||
int option;
|
int option;
|
||||||
int fd;
|
int fd;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
while ((option = getopt(argc, argv, ":h")) != ERROR)
|
while ((option = getopt(argc, argv, ":hb")) != ERROR)
|
||||||
{
|
{
|
||||||
switch (option)
|
switch (option)
|
||||||
{
|
{
|
||||||
@ -85,11 +86,15 @@ void i8sak_startpan_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
|
|||||||
fprintf(stderr, "Starts PAN as PAN Coordinator\n"
|
fprintf(stderr, "Starts PAN as PAN Coordinator\n"
|
||||||
"Usage: %s [-h]\n"
|
"Usage: %s [-h]\n"
|
||||||
" -h = this help menu\n"
|
" -h = this help menu\n"
|
||||||
|
" -b = start beacon-enabled PAN\n"
|
||||||
, argv[0]);
|
, argv[0]);
|
||||||
/* Must manually reset optind if we are going to exit early */
|
/* Must manually reset optind if we are going to exit early */
|
||||||
|
|
||||||
optind = -1;
|
optind = -1;
|
||||||
return;
|
return;
|
||||||
|
case 'b':
|
||||||
|
beaconenabled = true;
|
||||||
|
break;
|
||||||
case ':':
|
case ':':
|
||||||
fprintf(stderr, "ERROR: missing argument\n");
|
fprintf(stderr, "ERROR: missing argument\n");
|
||||||
/* Must manually reset optind if we are going to exit early */
|
/* Must manually reset optind if we are going to exit early */
|
||||||
@ -184,11 +189,22 @@ void i8sak_startpan_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
|
|||||||
printf("i8sak: starting PAN\n");
|
printf("i8sak: starting PAN\n");
|
||||||
|
|
||||||
IEEE802154_PANIDCOPY(startreq.panid, i8sak->addr.panid);
|
IEEE802154_PANIDCOPY(startreq.panid, i8sak->addr.panid);
|
||||||
startreq.chnum = i8sak->chnum;
|
startreq.chan = i8sak->chan;
|
||||||
startreq.chpage = i8sak->chpage;
|
startreq.chpage = i8sak->chpage;
|
||||||
startreq.beaconorder = 15;
|
|
||||||
startreq.pancoord = true;
|
if (beaconenabled)
|
||||||
|
{
|
||||||
|
startreq.beaconorder = 6;
|
||||||
|
startreq.superframeorder = 5;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
startreq.beaconorder = 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
startreq.pancoord = true;
|
||||||
startreq.coordrealign = false;
|
startreq.coordrealign = false;
|
||||||
|
startreq.battlifeext = false;
|
||||||
|
|
||||||
ieee802154_start_req(fd, &startreq);
|
ieee802154_start_req(fd, &startreq);
|
||||||
|
|
||||||
|
@ -126,15 +126,11 @@ void i8sak_tx_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
|
|||||||
case '?':
|
case '?':
|
||||||
fprintf(stderr, "ERROR: unknown argument\n");
|
fprintf(stderr, "ERROR: unknown argument\n");
|
||||||
ret = ERROR;
|
ret = ERROR;
|
||||||
break;
|
optind = -1;
|
||||||
|
i8sak_cmd_error(i8sak);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret != OK)
|
|
||||||
{
|
|
||||||
i8sak_cmd_error(i8sak);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argc == argind + 1)
|
if (argc == argind + 1)
|
||||||
{
|
{
|
||||||
i8sak->payload_len = i8sak_str2payload(argv[1], &i8sak->payload[0]);
|
i8sak->payload_len = i8sak_str2payload(argv[1], &i8sak->payload[0]);
|
||||||
|
@ -55,6 +55,9 @@ CSRCS += ieee802154_setpromisc.c ieee802154_getpromisc.c
|
|||||||
CSRCS += ieee802154_setrxonidle.c ieee802154_getrxonidle.c
|
CSRCS += ieee802154_setrxonidle.c ieee802154_getrxonidle.c
|
||||||
CSRCS += ieee802154_settxpwr.c ieee802154_gettxpwr.c
|
CSRCS += ieee802154_settxpwr.c ieee802154_gettxpwr.c
|
||||||
CSRCS += ieee802154_getdevmode.c
|
CSRCS += ieee802154_getdevmode.c
|
||||||
|
CSRCS += ieee802154_setassocpermit.c
|
||||||
|
CSRCS += ieee802154_getcoordsaddr.c
|
||||||
|
CSRCS += ieee802154_getcoordeaddr.c
|
||||||
|
|
||||||
ifeq ($(CONFIG_NET_6LOWPAN),y)
|
ifeq ($(CONFIG_NET_6LOWPAN),y)
|
||||||
# Add Get/Set Attribute helpers
|
# Add Get/Set Attribute helpers
|
||||||
|
@ -58,10 +58,10 @@ int ieee802154_getchan(int fd, FAR uint8_t *chan)
|
|||||||
struct ieee802154_get_req_s req;
|
struct ieee802154_get_req_s req;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
req.attr = IEEE802154_ATTR_PHY_CURRENT_CHANNEL;
|
req.attr = IEEE802154_ATTR_PHY_CHAN;
|
||||||
ret = ieee802154_get_req(fd, &req);
|
ret = ieee802154_get_req(fd, &req);
|
||||||
|
|
||||||
*chan = req.attrval.phy.channel;
|
*chan = req.attrval.phy.chan;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
67
wireless/ieee802154/libmac/ieee802154_getcoordeaddr.c
Normal file
67
wireless/ieee802154/libmac/ieee802154_getcoordeaddr.c
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* apps/wireless/ieee802154/libmac/ieee802154_getcoordeaddr.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017 Verge Inc. All rights reserved.
|
||||||
|
* Author: Anthony Merlino <anthony@vergeaero.com>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <nuttx/wireless/ieee802154/ieee802154_mac.h>
|
||||||
|
|
||||||
|
#include "wireless/ieee802154.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int ieee802154_getcoordeaddr(int fd, FAR uint8_t *eaddr)
|
||||||
|
{
|
||||||
|
struct ieee802154_get_req_s req;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
req.attr = IEEE802154_ATTR_MAC_COORD_EADDR;
|
||||||
|
ret = ieee802154_get_req(fd, &req);
|
||||||
|
|
||||||
|
IEEE802154_EADDRCOPY(eaddr, req.attrval.mac.eaddr);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
66
wireless/ieee802154/libmac/ieee802154_getcoordsaddr.c
Normal file
66
wireless/ieee802154/libmac/ieee802154_getcoordsaddr.c
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* apps/wireless/ieee802154/libmac/ieee802154_getcoordsaddr.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017 Verge Inc. All rights reserved.
|
||||||
|
* Author: Anthony Merlino <anthony@vergeaero.com>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <nuttx/wireless/ieee802154/ieee802154_mac.h>
|
||||||
|
|
||||||
|
#include "wireless/ieee802154.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int ieee802154_getcoordsaddr(int fd, FAR uint8_t *saddr)
|
||||||
|
{
|
||||||
|
struct ieee802154_get_req_s req;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
req.attr = IEEE802154_ATTR_MAC_COORD_SADDR;
|
||||||
|
ret = ieee802154_get_req(fd, &req);
|
||||||
|
|
||||||
|
IEEE802154_SADDRCOPY(saddr, req.attrval.mac.saddr);
|
||||||
|
return ret;
|
||||||
|
}
|
@ -58,7 +58,7 @@ int ieee802154_geteaddr(int fd, FAR uint8_t *eaddr)
|
|||||||
struct ieee802154_get_req_s req;
|
struct ieee802154_get_req_s req;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
req.attr = IEEE802154_ATTR_MAC_EXTENDED_ADDR;
|
req.attr = IEEE802154_ATTR_MAC_EADDR;
|
||||||
ret = ieee802154_get_req(fd, &req);
|
ret = ieee802154_get_req(fd, &req);
|
||||||
|
|
||||||
IEEE802154_EADDRCOPY(eaddr, req.attrval.mac.eaddr);
|
IEEE802154_EADDRCOPY(eaddr, req.attrval.mac.eaddr);
|
||||||
|
@ -58,7 +58,7 @@ int ieee802154_getsaddr(int fd, FAR uint8_t *saddr)
|
|||||||
struct ieee802154_get_req_s req;
|
struct ieee802154_get_req_s req;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
req.attr = IEEE802154_ATTR_MAC_SHORT_ADDRESS;
|
req.attr = IEEE802154_ATTR_MAC_SADDR;
|
||||||
ret = ieee802154_get_req(fd, &req);
|
ret = ieee802154_get_req(fd, &req);
|
||||||
|
|
||||||
IEEE802154_SADDRCOPY(saddr, req.attrval.mac.saddr);
|
IEEE802154_SADDRCOPY(saddr, req.attrval.mac.saddr);
|
||||||
|
64
wireless/ieee802154/libmac/ieee802154_setassocpermit.c
Normal file
64
wireless/ieee802154/libmac/ieee802154_setassocpermit.c
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* apps/wireless/ieee802154/libmac/ieee802154_assocpermit.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017 Verge Inc. All rights reserved.
|
||||||
|
* Author: Anthony Merlino <anthony@vergeaero.com>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <nuttx/wireless/ieee802154/ieee802154_mac.h>
|
||||||
|
|
||||||
|
#include "wireless/ieee802154.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int ieee802154_setassocpermit(int fd, bool assocpermit)
|
||||||
|
{
|
||||||
|
struct ieee802154_set_req_s req;
|
||||||
|
|
||||||
|
req.attr = IEEE802154_ATTR_MAC_ASSOCIATION_PERMIT;
|
||||||
|
req.attrval.mac.assocpermit = assocpermit;
|
||||||
|
|
||||||
|
return ieee802154_set_req(fd, &req);
|
||||||
|
}
|
@ -57,8 +57,8 @@ int ieee802154_setchan(int fd, uint8_t chan)
|
|||||||
{
|
{
|
||||||
struct ieee802154_set_req_s req;
|
struct ieee802154_set_req_s req;
|
||||||
|
|
||||||
req.attr = IEEE802154_ATTR_PHY_CURRENT_CHANNEL;
|
req.attr = IEEE802154_ATTR_PHY_CHAN;
|
||||||
req.attrval.phy.channel = chan;
|
req.attrval.phy.chan = chan;
|
||||||
|
|
||||||
return ieee802154_set_req(fd, &req);
|
return ieee802154_set_req(fd, &req);
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ int ieee802154_seteaddr(int fd, FAR const uint8_t *eaddr)
|
|||||||
{
|
{
|
||||||
struct ieee802154_set_req_s req;
|
struct ieee802154_set_req_s req;
|
||||||
|
|
||||||
req.attr = IEEE802154_ATTR_MAC_EXTENDED_ADDR;
|
req.attr = IEEE802154_ATTR_MAC_EADDR;
|
||||||
IEEE802154_EADDRCOPY(req.attrval.mac.eaddr, eaddr);
|
IEEE802154_EADDRCOPY(req.attrval.mac.eaddr, eaddr);
|
||||||
|
|
||||||
return ieee802154_set_req(fd, &req);
|
return ieee802154_set_req(fd, &req);
|
||||||
|
@ -58,7 +58,7 @@ int ieee802154_setsaddr(int fd, FAR const uint8_t *saddr)
|
|||||||
{
|
{
|
||||||
struct ieee802154_set_req_s req;
|
struct ieee802154_set_req_s req;
|
||||||
|
|
||||||
req.attr = IEEE802154_ATTR_MAC_SHORT_ADDRESS;
|
req.attr = IEEE802154_ATTR_MAC_SADDR;
|
||||||
IEEE802154_SADDRCOPY(req.attrval.mac.saddr, saddr);
|
IEEE802154_SADDRCOPY(req.attrval.mac.saddr, saddr);
|
||||||
|
|
||||||
return ieee802154_set_req(fd, &req);
|
return ieee802154_set_req(fd, &req);
|
||||||
|
@ -58,10 +58,10 @@ int sixlowpan_getchan(int sock, FAR const char *ifname, FAR uint8_t *chan)
|
|||||||
struct ieee802154_get_req_s req;
|
struct ieee802154_get_req_s req;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
req.attr = IEEE802154_ATTR_PHY_CURRENT_CHANNEL;
|
req.attr = IEEE802154_ATTR_PHY_CHAN;
|
||||||
ret = sixlowpan_get_req(sock, ifname, &req);
|
ret = sixlowpan_get_req(sock, ifname, &req);
|
||||||
|
|
||||||
*chan = req.attrval.phy.channel;
|
*chan = req.attrval.phy.chan;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ int sixlowpan_geteaddr(int sock, FAR const char *ifname, FAR uint8_t *eaddr)
|
|||||||
struct ieee802154_get_req_s req;
|
struct ieee802154_get_req_s req;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
req.attr = IEEE802154_ATTR_MAC_EXTENDED_ADDR;
|
req.attr = IEEE802154_ATTR_MAC_EADDR;
|
||||||
ret = sixlowpan_get_req(sock, ifname, &req);
|
ret = sixlowpan_get_req(sock, ifname, &req);
|
||||||
|
|
||||||
IEEE802154_EADDRCOPY(eaddr, req.attrval.mac.eaddr);
|
IEEE802154_EADDRCOPY(eaddr, req.attrval.mac.eaddr);
|
||||||
|
@ -58,7 +58,7 @@ int sixlowpan_getsaddr(int sock, FAR const char *ifname, FAR uint8_t *saddr)
|
|||||||
struct ieee802154_get_req_s req;
|
struct ieee802154_get_req_s req;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
req.attr = IEEE802154_ATTR_MAC_SHORT_ADDRESS;
|
req.attr = IEEE802154_ATTR_MAC_SADDR;
|
||||||
ret = sixlowpan_get_req(sock, ifname, &req);
|
ret = sixlowpan_get_req(sock, ifname, &req);
|
||||||
|
|
||||||
IEEE802154_SADDRCOPY(saddr, req.attrval.mac.saddr);
|
IEEE802154_SADDRCOPY(saddr, req.attrval.mac.saddr);
|
||||||
|
@ -57,8 +57,8 @@ int sixlowpan_setchan(int sock, FAR const char *ifname, uint8_t chan)
|
|||||||
{
|
{
|
||||||
struct ieee802154_set_req_s req;
|
struct ieee802154_set_req_s req;
|
||||||
|
|
||||||
req.attr = IEEE802154_ATTR_PHY_CURRENT_CHANNEL;
|
req.attr = IEEE802154_ATTR_PHY_CHAN;
|
||||||
req.attrval.phy.channel = chan;
|
req.attrval.phy.chan = chan;
|
||||||
|
|
||||||
return sixlowpan_set_req(sock, ifname, &req);
|
return sixlowpan_set_req(sock, ifname, &req);
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ int sixlowpan_seteaddr(int sock, FAR const char *ifname, FAR const uint8_t *eadd
|
|||||||
{
|
{
|
||||||
struct ieee802154_set_req_s req;
|
struct ieee802154_set_req_s req;
|
||||||
|
|
||||||
req.attr = IEEE802154_ATTR_MAC_EXTENDED_ADDR;
|
req.attr = IEEE802154_ATTR_MAC_EADDR;
|
||||||
IEEE802154_EADDRCOPY(req.attrval.mac.eaddr, eaddr);
|
IEEE802154_EADDRCOPY(req.attrval.mac.eaddr, eaddr);
|
||||||
|
|
||||||
return sixlowpan_set_req(sock, ifname, &req);
|
return sixlowpan_set_req(sock, ifname, &req);
|
||||||
|
@ -57,7 +57,7 @@ int sixlowpan_setsaddr(int sock, FAR const char *ifname, FAR const uint8_t *sadd
|
|||||||
{
|
{
|
||||||
struct ieee802154_set_req_s req;
|
struct ieee802154_set_req_s req;
|
||||||
|
|
||||||
req.attr = IEEE802154_ATTR_MAC_SHORT_ADDRESS;
|
req.attr = IEEE802154_ATTR_MAC_SADDR;
|
||||||
IEEE802154_SADDRCOPY(req.attrval.mac.saddr, saddr);
|
IEEE802154_SADDRCOPY(req.attrval.mac.saddr, saddr);
|
||||||
|
|
||||||
return sixlowpan_set_req(sock, ifname, &req);
|
return sixlowpan_set_req(sock, ifname, &req);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user