Skip to content

Commit

Permalink
Merge pull request knxd#616 from dallmair/fix/485-606-ft12-startup-se…
Browse files Browse the repository at this point in the history
…gfault

Fix FT 1.2 segmentation fault and make FT 1.2 and NCN5120 compatible with more USB-to-serial adapters
  • Loading branch information
smurfix authored Jan 5, 2025
2 parents e092537 + fc2a93e commit d76d818
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .mailmap
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Stefan Hoffmeister <[email protected]>
Michael Markstaller <[email protected]>
Michael Markstaller <[email protected]> <[email protected]>
Joerg Mattiello <[email protected]> <[email protected]>
Patrik Pfaffenbauer <[email protected]> <[email protected]>
Timo Wingender <[email protected]>
Expand Down
1 change: 0 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ Harald Leithner <[email protected]>
Tobias Lorenz <[email protected]>
MagicBear <[email protected]>
Michael Markstaller <[email protected]>
Michael Markstaller <[email protected]>
Joerg Mattiello <[email protected]>
Race666 <[email protected]>
Sebastian <[email protected]>
Expand Down
11 changes: 7 additions & 4 deletions src/backend/ft12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class FT12serial : public LLserial
void termios_settings (struct termios &t1)
{
t1.c_cflag = CS8 | CLOCAL | CREAD | PARENB;
t1.c_iflag = IGNBRK | INPCK | ISIG;
t1.c_iflag = IGNBRK | ISIG;
t1.c_oflag = 0;
t1.c_lflag = 0;
t1.c_cc[VTIME] = 1;
Expand Down Expand Up @@ -120,7 +120,8 @@ FT12wrap::setup()
ERRORPRINTF (t, E_ERROR | 5, "Don't specify both device and IP options!");
return false;
}
iface = new FT12serial(this, cfg);
ll_serial = new FT12serial(this, cfg);
iface = ll_serial;
}
else
{
Expand Down Expand Up @@ -325,6 +326,10 @@ FT12wrap::process_read(bool is_timeout)
const uint8_t reset[1] = { 0xA0 };
CArray c = CArray (reset, sizeof (reset));
t->TracePacket (0, "RecvReset", c);
if (ll_serial != nullptr)
{
ll_serial->enable_input_parity_check();
}
LowLevelFilter::recv_Data (c);
}
akt.deletepart (0, 4);
Expand Down Expand Up @@ -444,5 +449,3 @@ FT12CEMIDriver::cmdOpen()
const uint8_t t1[] = { 0xF6, 0x00, 0x08, 0x01, 0x34, 0x10, 0x01, 0x00 };
send_Local (CArray (t1, sizeof (t1)),1);
}


4 changes: 4 additions & 0 deletions src/backend/ft12.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "iobuf.h"
#include "lowlevel.h"
#include "llserial.h"
#include "emi_common.h"
#include "lowlatency.h"
#include "link.h"
Expand Down Expand Up @@ -125,6 +126,9 @@ class FT12wrap : public LowLevelFilter
void do_send_Local (CArray& l, int raw = 0);

void sendReset();

private:
LLserial *ll_serial = nullptr;
};

#endif
10 changes: 4 additions & 6 deletions src/backend/ncn5120.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class NCN5120wrap : public TPUARTwrap
void setstate(enum TSTATE state);

void RecvLPDU (const uint8_t * data, int len);
virtual FDdriver * create_serial(LowLevelIface* parent, IniSectionPtr& s);
virtual LLserial * create_serial(LowLevelIface* parent, IniSectionPtr& s);
};

class NCN5120serial : public LLserial
Expand All @@ -54,7 +54,7 @@ class NCN5120serial : public LLserial
void termios_settings(struct termios &t1)
{
t1.c_cflag = CS8 | CLOCAL | CREAD;
t1.c_iflag = IGNBRK | INPCK | ISIG;
t1.c_iflag = IGNBRK | ISIG;
t1.c_oflag = 0;
t1.c_lflag = 0;
t1.c_cc[VTIME] = 1;
Expand All @@ -69,11 +69,10 @@ NCN5120::create_wrapper(LowLevelIface* parent, IniSectionPtr& s, LowLevelDriver*
}


FDdriver *
LLserial *
NCN5120wrap::create_serial(LowLevelIface* parent, IniSectionPtr& s)
{
fd_driver = new NCN5120serial(parent,s);
return fd_driver;
return new NCN5120serial(parent, s);
}

void NCN5120wrap::RecvLPDU (const uint8_t * data, int len)
Expand All @@ -94,4 +93,3 @@ NCN5120wrap::setstate(enum TSTATE new_state)
}
TPUARTwrap::setstate(new_state);
}

35 changes: 8 additions & 27 deletions src/backend/tpuart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@ TPUART::create_wrapper(LowLevelIface* parent, IniSectionPtr& s, LowLevelDriver*
return new TPUARTwrap(parent,s, i);
}

FDdriver *
LLserial *
TPUARTwrap::create_serial(LowLevelIface* parent, IniSectionPtr& s)
{
fd_driver = new TPUARTserial(parent,s);
return fd_driver;
return new TPUARTserial(parent, s);
}


Expand Down Expand Up @@ -136,7 +135,8 @@ TPUARTwrap::setup()
ERRORPRINTF (t, E_ERROR | 25, "Don't specify both device and IP options!");
return false;
}
iface = create_serial(this, cfg);
ll_serial = create_serial(this, cfg);
iface = ll_serial;
}
else
{
Expand Down Expand Up @@ -363,36 +363,17 @@ TPUARTwrap::timer_cb(ev::timer &, int)
}

int
TPUARTwrap::enableInputParityCheck()
TPUARTwrap::enable_input_parity_check()
{
struct termios t1;

if (fd_driver == nullptr)
if (ll_serial == nullptr)
{
// Not possible and not necessary to enable on TCP connections, so just continue.
return 0;
}

TRACEPRINTF (t, 8, "Enabling input parity check on fd %d\n", fd_driver->get_fd());

if (tcgetattr (fd_driver->get_fd(), &t1))
{
ERRORPRINTF (t, E_ERROR | 70, "tcgetattr failed: %s", strerror(errno));
return -1;
}

t1.c_iflag = t1.c_iflag | INPCK;

if (tcsetattr (fd_driver->get_fd(), TCSANOW, &t1))
{
ERRORPRINTF (t, E_ERROR | 70, "tcsetattr failed: %s", strerror(errno));
return -2;
}

return 0;
return ll_serial->enable_input_parity_check();
}


void
TPUARTwrap::in_check()
{
Expand Down Expand Up @@ -479,7 +460,7 @@ TPUARTwrap::recv_Data(CArray &c)
if (state == T_in_reset)
{
TRACEPRINTF (t, 8, "RESET_ACK");
if (enableInputParityCheck()>=0)
if (enable_input_parity_check() >= 0)
setstate(T_in_setaddr);
// else time out
}
Expand Down
7 changes: 4 additions & 3 deletions src/backend/tpuart.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "link.h"
#include "lpdu.h"
#include "lowlevel.h"
#include "llserial.h"

// also update SN() in tpuart.cpp
enum TSTATE
Expand Down Expand Up @@ -107,11 +108,11 @@ class TPUARTwrap : public LowLevelFilter
void send_L_Data (LDataPtr l);

protected:
virtual FDdriver * create_serial(LowLevelIface* parent, IniSectionPtr& s);
FDdriver *fd_driver = NULL;
virtual LLserial * create_serial(LowLevelIface* parent, IniSectionPtr& s);

private:
int enableInputParityCheck();
LLserial *ll_serial = nullptr;
int enable_input_parity_check();
};

#endif
1 change: 1 addition & 0 deletions src/libserver/emi2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ EMI2Driver::EMI2Driver (LowLevelIface* c, IniSectionPtr& s, LowLevelDriver *i) :
{
t->setAuxName("EMI2");
sendLocal_done.set<EMI2Driver,&EMI2Driver::sendLocal_done_cb>(this);
reset_timer.set<EMI2Driver,&EMI2Driver::reset_timer_cb>(this);
}

void
Expand Down
23 changes: 23 additions & 0 deletions src/libserver/llserial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,26 @@ LLserial::stop(bool err)
FDdriver::stop(err);
}

int
LLserial::enable_input_parity_check()
{
struct termios t1;

TRACEPRINTF (t, 8, "Enabling input parity check on fd %d\n", fd);

if (tcgetattr (fd, &t1))
{
ERRORPRINTF (t, E_ERROR | 70, "tcgetattr failed: %s", strerror(errno));
return -1;
}

t1.c_iflag = t1.c_iflag | INPCK;

if (tcsetattr (fd, TCSANOW, &t1))
{
ERRORPRINTF (t, E_ERROR | 70, "tcsetattr failed: %s", strerror(errno));
return -2;
}

return 0;
}
1 change: 1 addition & 0 deletions src/libserver/llserial.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class LLserial:public FDdriver
bool setup();
void start();
void stop(bool err);
int enable_input_parity_check();

private:
low_latency_save sold;
Expand Down
5 changes: 0 additions & 5 deletions src/libserver/lowlevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,3 @@ HWBusDriver::setup()
return false;
return true;
}

int FDdriver::get_fd()
{
return fd;
}
1 change: 0 additions & 1 deletion src/libserver/lowlevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ class FDdriver:public LowLevelDriver
bool setup();
void start();
void stop(bool err);
int get_fd();

protected:
/** device connection */
Expand Down

0 comments on commit d76d818

Please sign in to comment.