Discussion:
Testing netnsh on Viewtool STM32F107 board
Alan Carvalho de Assis
2014-05-02 12:19:23 UTC
Permalink
Hi everybody,

I'm testing netnsh on Viewtool board and I'm facing some strange
behavior. I'm using the default viewtool netnsh configuration.

It is important to explain I'm connecting the Ethernet cable linking
the viewtool board with my computer directly, there is not a
router/hub/switch involved.

The development machine is running Linux (Ubuntu 12.04 LTS) and I
configured the Wired Connection to Share with other computers (it runs
some kind of DHCP server locally).

Ubuntu configures the eth0 interface with IP 10.42.0.1 then in NuttX I
configured eth0 with IP 10.42.0.2 (using serial console to configure
NuttX IP) :

nsh> ifconfig eth0 10.42.0.2 up
cmd_ifconfig: Host IP: 10.42.0.2
stm32_ifdown: Taking the network down
stm32_ifup: Bringing up: 10.42.0.2
stm32_phyinit: Duplex: FULL Speed: 100 MBps
cmd_ifconfig: Gateway: default
cmd_ifconfig: Netmask: Default


Then on Ubuntu I can ping the board correctly:

$ ping 10.42.0.2
PING 10.42.0.2 (10.42.0.2) 56(84) bytes of data.
64 bytes from 10.42.0.2: icmp_req=1 ttl=64 time=0.230 ms
64 bytes from 10.42.0.2: icmp_req=2 ttl=64 time=0.122 ms
64 bytes from 10.42.0.2: icmp_req=3 ttl=64 time=0.125 ms
64 bytes from 10.42.0.2: icmp_req=4 ttl=64 time=0.125 ms
64 bytes from 10.42.0.2: icmp_req=5 ttl=64 time=0.132 ms
64 bytes from 10.42.0.2: icmp_req=6 ttl=64 time=0.127 ms
^C
--- 10.42.0.2 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 4998ms
rtt min/avg/max/mdev = 0.122/0.143/0.230/0.040 ms

But then I try to connect using telnet it "connect", but doesn't enter
on telnet session:

$ telnet 10.42.0.2
Trying 10.42.0.2...
Connected to 10.42.0.2.
Escape character is '^]'.
nsh_telnetmain: Session [4] Started


This moment the NuttX session in the serial console became
unresponsive, I noticed it divides the typed characters in two parts
(even and odd characters position). For example, if I type "ifconfig"
it will create two command lines: icni and fofg:

nsh>
NuttShell (NSH)
nsh> ifconfignsh: fconfig: command not found
nsh> ifconfignsh: fconfig: command not found
nsh> ifconfignsh: iconfig: command not found
nsh> ifconfig
nsh: ifconfigifconfigifconfigifconfig: command not found
nsh> ifconfignsh: ifconfigifconfig: command not found
nsh> icni
nsh: ifconfigicni: command not found
nsh> nsh: fofg: command not found
nsh>
nsh> fofgnsh: icni: command not found
nsh>
nsh: fofg: command not found
nsh> nsh>
nsh> fcnfgnsh: icori: command not found
nsh> ifconfignsh: fconfig: command not found
nsh> ifconfignsh: fconfig: command not found
nsh>
nsh: fcnfgifconfigifconfig: command not found
nsh> nsh>
nsh> nsh>
nsh> fofgnsh: icni: command not found
nsh> icni
nsh: fofgicni: command not found
nsh> nsh: fofg: command not found
nsh>
nsh> fofgnsh: icni: command not found
nsh> insh>
nsh: fofgi: command not found
nsh> nsh>
nsh> nsh>
nsh>
nsh> nsh: a: command not found
nsh>
nsh>
nsh> nsh: a: command not found
nsh> icni
nsh: icni: command not found
nsh> nsh: fofg: command not found
nsh>
nsh> ifconfigeth0 HWaddr 00:e0:de:ad:be:ef at UP
IPaddr:10.42.0.2 DRaddr:10.42.0.1 Mask:255.255.255.0

nsh>
eth0 HWaddr 00:e0:de:ad:be:ef at UP
IPaddr:10.42.0.2 DRaddr:10.42.0.1 Mask:255.255.255.0

nsh>

Finally I realized it and typed iiffccoonnffiigg, although as you can
see only 1 letter of each appeared in the last typed command, but when
I pressed enter again it executed the second line.

I enabled Network debug in NuttX, but didn't realize what is wrong.

Did you already face this kind of issue? How to track this issue to
find a solution?

Best Regards,

Alan


------------------------------------

Yahoo Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/nuttx/

<*> Your email settings:
Individual Email | Traditional

<*> To change settings online go to:
http://groups.yahoo.com/group/nuttx/join
(Yahoo! ID required)

<*> To change settings via email:
nuttx-digest-***@public.gmane.org
nuttx-fullfeatured-***@public.gmane.org

<*> To unsubscribe from this group, send an email to:
nuttx-unsubscribe-***@public.gmane.org

<*> Your use of Yahoo Groups is subject to:
https://info.yahoo.com/legal/us/yahoo/utos/terms/
Alan Carvalho de Assis
2014-05-02 12:43:31 UTC
Permalink
Post by Alan Carvalho de Assis
Hi everybody,
I'm testing netnsh on Viewtool board and I'm facing some strange
behavior. I'm using the default viewtool netnsh configuration.
It is important to explain I'm connecting the Ethernet cable linking
the viewtool board with my computer directly, there is not a
router/hub/switch involved.
The development machine is running Linux (Ubuntu 12.04 LTS) and I
configured the Wired Connection to Share with other computers (it runs
some kind of DHCP server locally).
Ubuntu configures the eth0 interface with IP 10.42.0.1 then in NuttX I
configured eth0 with IP 10.42.0.2 (using serial console to configure
nsh> ifconfig eth0 10.42.0.2 up
cmd_ifconfig: Host IP: 10.42.0.2
stm32_ifdown: Taking the network down
stm32_ifup: Bringing up: 10.42.0.2
stm32_phyinit: Duplex: FULL Speed: 100 MBps
cmd_ifconfig: Gateway: default
cmd_ifconfig: Netmask: Default
$ ping 10.42.0.2
PING 10.42.0.2 (10.42.0.2) 56(84) bytes of data.
64 bytes from 10.42.0.2: icmp_req=1 ttl=64 time=0.230 ms
64 bytes from 10.42.0.2: icmp_req=2 ttl=64 time=0.122 ms
64 bytes from 10.42.0.2: icmp_req=3 ttl=64 time=0.125 ms
64 bytes from 10.42.0.2: icmp_req=4 ttl=64 time=0.125 ms
64 bytes from 10.42.0.2: icmp_req=5 ttl=64 time=0.132 ms
64 bytes from 10.42.0.2: icmp_req=6 ttl=64 time=0.127 ms
^C
--- 10.42.0.2 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 4998ms
rtt min/avg/max/mdev = 0.122/0.143/0.230/0.040 ms
But then I try to connect using telnet it "connect", but doesn't enter
$ telnet 10.42.0.2
Trying 10.42.0.2...
Connected to 10.42.0.2.
Escape character is '^]'.
nsh_telnetmain: Session [4] Started
This moment the NuttX session in the serial console became
unresponsive, I noticed it divides the typed characters in two parts
(even and odd characters position). For example, if I type "ifconfig"
nsh>
NuttShell (NSH)
nsh> ifconfignsh: fconfig: command not found
nsh> ifconfignsh: fconfig: command not found
nsh> ifconfignsh: iconfig: command not found
nsh> ifconfig
nsh: ifconfigifconfigifconfigifconfig: command not found
nsh> ifconfignsh: ifconfigifconfig: command not found
nsh> icni
nsh: ifconfigicni: command not found
nsh> nsh: fofg: command not found
nsh>
nsh> fofgnsh: icni: command not found
nsh>
nsh: fofg: command not found
nsh> nsh>
nsh> fcnfgnsh: icori: command not found
nsh> ifconfignsh: fconfig: command not found
nsh> ifconfignsh: fconfig: command not found
nsh>
nsh: fcnfgifconfigifconfig: command not found
nsh> nsh>
nsh> nsh>
nsh> fofgnsh: icni: command not found
nsh> icni
nsh: fofgicni: command not found
nsh> nsh: fofg: command not found
nsh>
nsh> fofgnsh: icni: command not found
nsh> insh>
nsh: fofgi: command not found
nsh> nsh>
nsh> nsh>
nsh>
nsh> nsh: a: command not found
nsh>
nsh>
nsh> nsh: a: command not found
nsh> icni
nsh: icni: command not found
nsh> nsh: fofg: command not found
nsh>
nsh> ifconfigeth0 HWaddr 00:e0:de:ad:be:ef at UP
IPaddr:10.42.0.2 DRaddr:10.42.0.1 Mask:255.255.255.0
nsh>
eth0 HWaddr 00:e0:de:ad:be:ef at UP
IPaddr:10.42.0.2 DRaddr:10.42.0.1 Mask:255.255.255.0
nsh>
Finally I realized it and typed iiffccoonnffiigg, although as you can
see only 1 letter of each appeared in the last typed command, but when
I pressed enter again it executed the second line.
I connected the viewtool board on my wireless router and configured IP
to right range:

nsh> ifconfig eth0 192.168.0.99
cmd_ifconfig: Host IP: 192.168.0.99
stm32_ifdown: Taking the network down
stm32_ifup: Bringing up: 192.168.0.99
stm32_phyinit: Duplex: FULL Speed: 100 MBps
cmd_ifconfig: Gateway: default
cmd_ifconfig: Netmask: Default
nsh> ifconfig
eth0 HWaddr 00:e0:de:ad:be:ef at UP
IPaddr:192.168.0.99 DRaddr:192.168.0.1 Mask:255.255.255.0

nsh> ls
/:
dev/
nsh> uip_udpinput: No listener on UDP port
uip_udpinput: No listener on UDP port

Then from Ubuntu machine I tried to connect to nuttx board:

$ telnet 192.168.0.99
Trying 192.168.0.99...
Connected to 192.168.0.99.
Escape character is '^]'.

This time I *cannot* see the debug message:
nsh_telnetmain: Session [4] Started

Also these messages appeared:
uip_udpinput: No listener on UDP port

I think it is related to DHCP, but I'm not sure. The dhcpc is selected
on nuttx. Is there some way to force eth0 to get DHCP address on
NuttX?

Other thing I noticed: the serial console is working correctly, it
doesn't become unresponsive as previously.

BR,

Alan


------------------------------------

Yahoo Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/nuttx/

<*> Your email settings:
Individual Email | Traditional

<*> To change settings online go to:
http://groups.yahoo.com/group/nuttx/join
(Yahoo! ID required)

<*> To change settings via email:
nuttx-digest-***@public.gmane.org
nuttx-fullfeatured-***@public.gmane.org

<*> To unsubscribe from this group, send an email to:
nuttx-unsubscribe-***@public.gmane.org

<*> Your use of Yahoo Groups is subject to:
https://info.yahoo.com/legal/us/yahoo/utos/terms/
s***@public.gmane.org
2014-05-02 13:11:46 UTC
Permalink
I think it is related to DHCP, but I'm not sure. The dhcpc is selected on nuttx. Is there some way to force eth0 to get DHCP address on NuttX?
I haven't used DHCPC in a long time. But to configure it you should need only:

CONFIG_NET_UDP
CONFIG_NET_BROADCAST
CONFIG_NETUTILS_DHCPC

And I think that is all.

Regarding the Telnet issue. My hunch would be that there is some screw-up in setting up stdin for the Telnet NSH session. The way that this supposed to work is that the logic in apps/netutils/telnetd listens for telnet connections, sets up a Telnet serial driver, redirects stdin, stdout, and stderr to the Telnet serial driver, and starts the new NSH session.

But it appears that stdin was not setup correctly and continues to use /dev/console for stdin. That would explain why you see no console output after the host Telnet connection and it would also explain why you have to enter each character twice: One goes to the "Telnet" session and one goes to the /dev/console session.

So the first place that would look is in apps/netutils/telnetd. There are many places there where stdin, stdout, and stderr are not available but you should still be able to use the API lowsyslog() to get debug output.

Greg
s***@public.gmane.org
2014-05-02 12:52:22 UTC
Permalink
Hi, Alan,

Yes, I saw that exact same behavior on a SAM4E-EK just this week I assumed it was some configuration problem and did not go back to analyze it. I really can't imagine how a telenet connection could affect the serial session, but the fact that you are seeing the same issue suggests that something has been broken recently.

I am taking some vacation time on the beach so I won't be able to examine this further now. I will be check email but won't be back until Monday. If you do not solve the problem before then, I will try to look into it then.

Greg
Alan Carvalho de Assis
2014-05-02 13:18:34 UTC
Permalink
Hi Greg,

Sorry to bother you during your vacation.

I noticed the number of each letter you need to type on serial console
is equal the number of telnet connected sessions + 1. Then I assume it
is equal to all sessions existent in the system (1 serial console
session + # of telnet session).

Other thing I noticed: it is possible to exit from a session and type
normally the NuttX commands, but the typed characters will not appear:

(First I type "ls", but only "l" will appear)
NuttShell (NSH)
nsh> l
nsh: l: command not found

(Then I know the "s" in hidden in the next command, now I type
"eexxiitt")
nsh> exitnsh: sexit: command not found

(note that the first "exit" doesn't execute because there was already
a "s", then pressing Enter again will execute next "exit" command
correctly)
nsh>

(it exited from a session, now I can type any nuttx command only once,
but it doesn't appear)
(typed ls)
nsh> /:
dev/

(typed help)
nsh> help usage: help [-v] [<cmd>]

[ echo ifconfig mkfifo rm usleep
? exec ifdown mh rmdir wget
break exit ifup mv set xd
cat false kill mw sh
cd free losetup ping sleep
cp get ls ps test
cmp help mb put true
dd hexdump mkdir pwd unset

Builtin Apps:
nsh>

I will do some nuttx regression (bisect) to find out which patch
introduced this issue.

BR,

Alan
Post by s***@public.gmane.org
Hi, Alan,
Yes, I saw that exact same behavior on a SAM4E-EK just this week I assumed
it was some configuration problem and did not go back to analyze it. I
really can't imagine how a telenet connection could affect the serial
session, but the fact that you are seeing the same issue suggests that
something has been broken recently.
I am taking some vacation time on the beach so I won't be able to examine
this further now. I will be check email but won't be back until Monday. If
you do not solve the problem before then, I will try to look into it then.
Greg
------------------------------------

Yahoo Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/nuttx/

<*> Your email settings:
Individual Email | Traditional

<*> To change settings online go to:
http://groups.yahoo.com/group/nuttx/join
(Yahoo! ID required)

<*> To change settings via email:
nuttx-digest-***@public.gmane.org
nuttx-fullfeatured-***@public.gmane.org

<*> To unsubscribe from this group, send an email to:
nuttx-unsubscribe-***@public.gmane.org

<*> Your use of Yahoo Groups is subject to:
https://info.yahoo.com/legal/us/yahoo/utos/terms/
s***@public.gmane.org
2014-05-02 13:28:28 UTC
Permalink
Post by Alan Carvalho de Assis
I noticed the number of each letter you need to type on serial console
is equal the number of telnet connected sessions + 1. Then I assume it
is equal to all sessions existent in the system (1 serial console
session + # of telnet session).
This is 100% consistent with my hunch that stdin is no being redirected properly. The /devconsole appears to be being shared by every NSH session. So if you have three sessions, the /dev/console session would get only one of three characters input.

Oddly, this same behavior is not occurring with stdout.
Post by Alan Carvalho de Assis
I will do some nuttx regression (bisect) to find out which patch introduced this issue.
That might be helpful. I am told that 'git bisect' does this very well.

Greg
Alan Carvalho de Assis
2014-05-02 13:51:16 UTC
Permalink
Post by s***@public.gmane.org
Post by Alan Carvalho de Assis
I will do some nuttx regression (bisect) to find out which patch introduced this issue.
That might be helpful. I am told that 'git bisect' does this very well.
Yes, I'm using git bisect!

BR,

Alan


------------------------------------

Yahoo Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/nuttx/

<*> Your email settings:
Individual Email | Traditional

<*> To change settings online go to:
http://groups.yahoo.com/group/nuttx/join
(Yahoo! ID required)

<*> To change settings via email:
nuttx-digest-***@public.gmane.org
nuttx-fullfeatured-***@public.gmane.org

<*> To unsubscribe from this group, send an email to:
nuttx-unsubscribe-***@public.gmane.org

<*> Your use of Yahoo Groups is subject to:
https://info.yahoo.com/legal/us/yahoo/utos/terms/
Alan Carvalho de Assis
2014-05-03 23:08:03 UTC
Permalink
<*>[Attachment(s) from Alan Carvalho de Assis included below]

Hi Greg,
Post by s***@public.gmane.org
Yes, I saw that exact same behavior on a SAM4E-EK just this week I assumed
it was some configuration problem and did not go back to analyze it.
In fact this issue is triggered by a configuration parameter. During
the bisection I noticed the issue was not related to file version, but
to some configuration.

If I just execute "./configure.sh viewtool-stm32f107/netnsh" and
compile it the issue doesn't happen, but if I execute "make
menuconfig" the issue appears.

Comparing the config files I discovered it was caused when defining:
CONFIG_NSH_CONDEV="/dev/console"

Although just removing this definition in the config file "fixes" the
issue I think it is not the definitive fix, because some people could
want to use console redirection and telnet at same time.

I found a fix to redirect the output correctly, now when I execute
"llss" the first command's output appear in the serial console and the
result of second command appears in the telnet session. Same works if
I open more telnet sessions.

I still looking for a fix to the input redirect issue.

Best Regards,

Alan


<*>Attachment(s) from Alan Carvalho de Assis:


<*> 1 of 1 File(s) https://groups.yahoo.com/neo/groups/nuttx/attachments/560225140;_ylc=X3oDMTJyNzd1ZDgzBF9TAzk3MzU5NzE0BGdycElkAzIzMzg5MDcwBGdycHNwSWQDMTcwNTAwNjU1OQRzZWMDYXR0YWNobWVudARzbGsDdmlld09uV2ViBHN0aW1lAzEzOTkxNTg0ODU-
<*> 0001-Fix-telnet-output-when-CONFIG_NSH_CONDEV-is-defined.patch

------------------------------------

Yahoo Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/nuttx/

<*> Your email settings:
Individual Email | Traditional

<*> To change settings online go to:
http://groups.yahoo.com/group/nuttx/join
(Yahoo! ID required)

<*> To change settings via email:
nuttx-digest-***@public.gmane.org
nuttx-fullfeatured-***@public.gmane.org

<*> To unsubscribe from this group, send an email to:
nuttx-unsubscribe-***@public.gmane.org

<*> Your use of Yahoo Groups is subject to:
https://info.yahoo.com/legal/us/yahoo/utos/terms/
s***@public.gmane.org
2014-05-04 13:40:04 UTC
Permalink
Post by Alan Carvalho de Assis
CONFIG_NSH_CONDEV="/dev/console"
This is probably because of this fix to the Kconfig file. The fix is "correct" but now CONFIG_NSH_CONDEV is defined by default. It should not be defined. That will force all NSH sessions to use /dev/console I think.
Post by Alan Carvalho de Assis
Although just removing this definition in the config file "fixes" the
issue I think it is not the definitive fix, because some people could
want to use console redirection and telnet at same time.
I found a fix to redirect the output correctly, now when I execute
"llss" the first command's output appear in the serial console and the
result of second command appears in the telnet session. Same works if
I open more telnet sessions.
I still looking for a fix to the input redirect issue.
I will look at the fix when I get back. But this is primarily an issue with apps/nshlib/Kconfig. CONFIG_NSH_CONDEV should not be defined unless you want that behavior.

Thanks for taking the time to track this down.

Greg
Alan Carvalho de Assis
2014-05-04 18:24:26 UTC
Permalink
Hi Greg,
Post by s***@public.gmane.org
Post by Alan Carvalho de Assis
CONFIG_NSH_CONDEV="/dev/console"
This is probably because of this fix to the Kconfig file. The fix is
"correct" but now CONFIG_NSH_CONDEV is defined by default. It should not be
defined. That will force all NSH sessions to use /dev/console I think.
Sure, by default CONFIG_NSH_CONDEV shouldn't be defined. But if it was
defined manually the issue will happen.
Post by s***@public.gmane.org
I will look at the fix when I get back. But this is primarily an issue with
apps/nshlib/Kconfig. CONFIG_NSH_CONDEV should not be defined unless you
want that behavior.
I think now I have a better understanding why this issue happen:

- When NSH_CONDEV is defined the macros INSTREAM(p) and OUTSTREAM(p)
will return a pointer to console device ((p)->cn_constream) instead of
stdin and stdout respectively:

# ifdef CONFIG_NSH_CONDEV
# define INFD(p) ((p)->cn_confd)
# define INSTREAM(p) ((p)->cn_constream)
# define OUTFD(p) ((p)->cn_confd)
# define OUTSTREAM(p) ((p)->cn_constream)

- When telnetd daemon is started it creates a telnetd_driver char
device and "dup2" it to stdin, stdout and stderr (0, 1, 2).

Then INSTREAM(p) and OUTSTREAM(p) always will point to NSH_CONDEV
instead of point to telnetd char device.

If I force it to always point to stdin/stdout the nsh console and
telnet session will work:

diff --git a/apps/nshlib/nsh_console.h b/apps/nshlib/nsh_console.h
index c78362f..9c065af 100644
--- a/apps/nshlib/nsh_console.h
+++ b/apps/nshlib/nsh_console.h
@@ -77,9 +77,9 @@
#if CONFIG_NFILE_STREAMS > 0
# ifdef CONFIG_NSH_CONDEV
# define INFD(p) ((p)->cn_confd)
-# define INSTREAM(p) ((p)->cn_constream)
+# define INSTREAM(p) stdin
# define OUTFD(p) ((p)->cn_confd)
-# define OUTSTREAM(p) ((p)->cn_constream)
+# define OUTSTREAM(p) stdout
# else
# define INFD(p) 0
# define INSTREAM(p) stdin

Unfortunately it is not a solution, because it will break NSH_CONDEV
functionality (although in my tests it still working when defined to
/dev/console or /dev/ttyS0).

I think when NSH_CONDEV is defined, telnetd daemon shouldn't dup2 the
telned char device to std[in,out], but just register the /dev/telnetXd
as a new console (at nsh_newconsole()).
Post by s***@public.gmane.org
Thanks for taking the time to track this down.
I glad to help improving NuttX!

BR,

Alan


------------------------------------

Yahoo Groups Links

<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/nuttx/

<*> Your email settings:
Individual Email | Traditional

<*> To change settings online go to:
http://groups.yahoo.com/group/nuttx/join
(Yahoo! ID required)

<*> To change settings via email:
nuttx-digest-***@public.gmane.org
nuttx-fullfeatured-***@public.gmane.org

<*> To unsubscribe from this group, send an email to:
nuttx-unsubscribe-***@public.gmane.org

<*> Your use of Yahoo Groups is subject to:
https://info.yahoo.com/legal/us/yahoo/utos/terms/

Loading...