Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set baudrate from Client? #239

Open
igittigitt opened this issue Jan 4, 2017 · 11 comments
Open

How to set baudrate from Client? #239

igittigitt opened this issue Jan 4, 2017 · 11 comments
Labels

Comments

@igittigitt
Copy link
Contributor

igittigitt commented Jan 4, 2017

How can a client set/change the baudrate of esp-link?
I am using a virtual COM port driver from http://www.hw-group.com/products/hw_vsp/index_en.html to create a local COM on the client. On the other side it connects through the esp-link Telnet port.
As far as i know, i can only change baud in webgui of esp.

@igittigitt
Copy link
Contributor Author

igittigitt commented Jan 6, 2017

As i found in serial/serbridge.c there must be some kind of NVT implementation (RFC 2217). Can you provide some examples for this? I played around a bit, but not success :-(

Tried to set the baudrate with this sequence:
FF FA 2C 01 00 00 01 2C FF F0

As seen in RFC document:
IAC SB COM-PORT-OPTION SET-BAUD <value(4)> IAC SE

IAC = 0xFF
SB  = 0xFA
COM-PORT-OPTION = 0x2C
SET-BAUD = 0x01
SE = 0xF0

@tve
Copy link
Member

tve commented Jan 6, 2017

The setting of the baud rate should work, as you describe, but I have to admit I'm not sure I've actually tested the baud rate setting specifically. I tested the other ones for sure 'cause I use them, but I may have missed the baud rate one.
This being said, there is a peculiarity to all this, which is that the client MUST send IAC and WILL or DO as the first two characters on the connection for the telnet escapes to be enabled. If the client doesn't, the telnet escapes are not enabled.

@tve
Copy link
Member

tve commented Jan 6, 2017

BTW, the debug log should print stuff about telnet, such as os_printf("telnet mode\n"); when it's enabled on a connection and os_printf("telnet mode\n"); when setting the baud rate.

@igittigitt
Copy link
Contributor Author

igittigitt commented Jan 6, 2017

You're right. First, one need to send a "WILL" command first, as you said:
FF FB 2C
next, sending the baudrate (here 300 Baud) command:
FF FA 2C 01 00 00 01 2C FF F0
This will produce the desired log output and result in change of baud!

BUT: there is an issue with it, tough. If i send the command again, the rates will mix up:

 56011> telnet mode
 56012> UART 600 baud
 56122> Telnet: 600 baud
 87541> Accept port 23, conn=0x3fff7448, pool slot 0
 87549> telnet mode
 87549> UART 892 baud

I think the problem is here, in serial/serbridge.c line 177:
tn_baud |= ((uint32_t)c) << (24-8*tn_baudCnt);
Because 'tn_baud' is not initialized and global:
static uint32_t tn_baud; // shared across all sockets, thus possible race condition
So simply adding a baud init somewhere, e.g. in line 112, could do the job:
case SetBaud: state = TN_setBaud; tn_baudCnt = 0; tn_baud=0; break;

@tve
Copy link
Member

tve commented Jan 6, 2017

Ugh, thanks for flagging the issue. I'll apply your fix!

@tve tve added the bug label Jan 6, 2017
@igittigitt
Copy link
Contributor Author

Great! Thank you for the fast support. Is there an official documentation (wiki) to tell about the NVT feature and give examples how to use it? If any help is needed here, i would be proud to help.

igittigitt pushed a commit to igittigitt/esp-link that referenced this issue Jan 11, 2017
According to jeelabs#239 this commit
fixes a bug, when setting baudrate from Telnet control commands (NVT)
more than once.
tve added a commit that referenced this issue Jan 12, 2017
Bugfix for issue #239 (setting baudrate via NVT)
@igittigitt
Copy link
Contributor Author

igittigitt commented Jan 12, 2017

Well, i am still issing some userland documentation about the Telnet command features. Where abd how could this bin done? Is there a "official" homepage/wiki for this project?

@igittigitt
Copy link
Contributor Author

I've tried to setup esp-link with HW-Group Virtual COM driver. It supports some of RFC2217 Telnet commands. It refuse to work because esp-link expects IAC WILL COM-PORT-OPTION as the first bytes after a Telnet connection is established. Otherwise it will fallback to transparent bridge mode.
Well, for some reason HW-Group's driver does not send this but begin with FF FA 2C 01 00 00 00 00 FF F0 to query the current baudrate of the terminal.
For now i did not test other drivers, like com2tcp or such, how they behave.
Just two questions about this:
1.) Would'nt it be better to enable/disable Telnet commands in the Web-GUI of esp-link, instead of "magically" inspect and decide by incomming datastream? I'm not shure if Telnet commands must always identify itself first and not later in the stream. Normally, if a device supports Telnet commands it must handle escaped 0xFF's.
2.) It's not clean, but to support such faulty drivers, i would like to have option 1.) with a dropdown-list which driver to support, e.g. "RFC2271-Support" having optins like "Disabled", "Enabled", "HW-Group VCP"

@tve
Copy link
Member

tve commented Jun 17, 2017

Ooops, I never saw your further comments. I agree with you, PR welcome ;-)

@zalexua
Copy link

zalexua commented Sep 1, 2022

Let me mention that that is another driver which potentially might be used
https://github.com/rchovan/npreal2

@uzi18
Copy link
Contributor

uzi18 commented Sep 7, 2022

@zalexua not maintained anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants