aboutsummaryrefslogtreecommitdiffstats
path: root/ncpd
diff options
context:
space:
mode:
Diffstat (limited to 'ncpd')
-rw-r--r--ncpd/channel.cc114
-rw-r--r--ncpd/channel.h114
-rw-r--r--ncpd/link.cc344
-rw-r--r--ncpd/linkchan.cc165
-rw-r--r--ncpd/linkchan.h80
-rw-r--r--ncpd/ncp.cc613
-rw-r--r--ncpd/ncp.h145
-rw-r--r--ncpd/socketchan.cc85
-rw-r--r--ncpd/socketchan.h4
9 files changed, 885 insertions, 779 deletions
diff --git a/ncpd/channel.cc b/ncpd/channel.cc
index d708cd9..e51b903 100644
--- a/ncpd/channel.cc
+++ b/ncpd/channel.cc
@@ -1,118 +1,146 @@
-// $Id$
-//
-// PLP - An implementation of the PSION link protocol
-//
-// Copyright (C) 1999 Philip Proudman
-// Modifications for plptools:
-// Copyright (C) 1999 Fritz Elfert <felfert@to.com>
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// e-mail philip.proudman@btinternet.com
-
-
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stream.h>
+#include <string>
#include "channel.h"
#include "ncp.h"
channel::channel(ncp * _ncpController)
{
- verbose = 0;
- ncpChannel = 0;
- ncpController = _ncpController;
- _terminate = false;
+ verbose = 0;
+ ncpChannel = 0;
+ connectName = 0;
+ ncpController = _ncpController;
+ _terminate = false;
+}
+
+channel::~channel()
+{
+ if (connectName)
+ free((void *)connectName);
}
void channel::
ncpSend(bufferStore & a)
{
- ncpController->send(ncpChannel, a);
+ ncpController->send(ncpChannel, a);
}
bool channel::
terminate()
{
- return _terminate;
+ return _terminate;
}
void channel::
terminateWhenAsked()
{
- _terminate = true;
+ _terminate = true;
}
void channel::
ncpConnect()
{
- ncpController->connect(this);
+ ncpController->connect(this);
}
void channel::
ncpRegister()
{
- ncpController->Register(this);
+ ncpController->Register(this);
}
void channel::
-ncpDoRegisterAck(int ch)
+ncpDoRegisterAck(int ch, const char *name)
{
- ncpController->RegisterAck(ch);
+ ncpController->RegisterAck(ch, name);
}
void channel::
ncpDisconnect()
{
- ncpController->disconnect(ncpChannel);
+ ncpController->disconnect(ncpChannel);
}
short int channel::
ncpProtocolVersion()
{
- return ncpController->getProtocolVersion();
+ return ncpController->getProtocolVersion();
}
void channel::
setNcpChannel(int chan)
{
- ncpChannel = chan;
+ ncpChannel = chan;
}
int channel::
getNcpChannel()
{
- return ncpChannel;
+ return ncpChannel;
}
void channel::
newNcpController(ncp * _ncpController)
{
- ncpController = _ncpController;
+ ncpController = _ncpController;
}
void channel::
setVerbose(short int _verbose)
{
- verbose = _verbose;
+ verbose = _verbose;
}
short int channel::
getVerbose()
{
- return verbose;
+ return verbose;
}
+
+const char * channel::
+getNcpConnectName()
+{
+ return connectName;
+}
+
+void channel::
+setNcpConnectName(const char *name)
+{
+ if (name) {
+ if (connectName)
+ free((void *)connectName);
+ connectName = strdup(name);
+ }
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/ncpd/channel.h b/ncpd/channel.h
index 90f08f6..585ef31 100644
--- a/ncpd/channel.h
+++ b/ncpd/channel.h
@@ -1,27 +1,26 @@
-// $Id$
-//
-// PLP - An implementation of the PSION link protocol
-//
-// Copyright (C) 1999 Philip Proudman
-// Modifications for plptools:
-// Copyright (C) 1999 Fritz Elfert <felfert@to.com>
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// e-mail philip.proudman@btinternet.com
-
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#ifndef _channel_h_
#define _channel_h_
@@ -34,39 +33,48 @@ class ncp;
class bufferStore;
class channel {
- public:
- channel(ncp *ncpController);
- virtual ~channel() {}
- void newNcpController(ncp *ncpController);
+public:
+ channel(ncp *ncpController);
+ virtual ~channel();
+ void newNcpController(ncp *ncpController);
- void setNcpChannel(int chan);
- int getNcpChannel(void);
- void ncpSend(bufferStore &a);
- void setVerbose(short int _verbose);
- short int getVerbose();
- virtual void ncpDataCallback(bufferStore &a) = NULL;
- virtual char *getNcpConnectName() = NULL;
- void ncpConnect();
- void ncpRegister();
- void ncpDoRegisterAck(int);
- virtual void ncpConnectAck() = NULL;
- virtual void ncpConnectTerminate() = NULL;
- virtual void ncpConnectNak() = NULL;
- virtual void ncpRegisterAck() = NULL;
- void ncpDisconnect();
- short int ncpProtocolVersion();
+ void setNcpChannel(int chan);
+ int getNcpChannel(void);
+ void ncpSend(bufferStore &a);
+ void setVerbose(short int _verbose);
+ short int getVerbose();
+ virtual void ncpDataCallback(bufferStore &a) = NULL;
+ virtual char *getNcpRegisterName() = NULL;
+ void ncpConnect();
+ void ncpRegister();
+ void ncpDoRegisterAck(int ch, const char *name);
+ virtual void ncpConnectAck() = NULL;
+ virtual void ncpConnectTerminate() = NULL;
+ virtual void ncpConnectNak() = NULL;
+ virtual void ncpRegisterAck() = NULL;
+ void ncpDisconnect();
+ short int ncpProtocolVersion();
+ const char *getNcpConnectName();
+ void setNcpConnectName(const char *);
- // The following two calls are used for destructing an instance
- virtual bool terminate(); // Mainloop will terminate this class if true
- void terminateWhenAsked();
+ // The following two calls are used for destructing an instance
+ virtual bool terminate(); // Mainloop will terminate this class if true
+ void terminateWhenAsked();
- protected:
- short int verbose;
+protected:
+ short int verbose;
+ const char *connectName;
- private:
- ncp *ncpController;
- int ncpChannel;
- bool _terminate;
+private:
+ ncp *ncpController;
+ int ncpChannel;
+ bool _terminate;
};
#endif
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/ncpd/link.cc b/ncpd/link.cc
index 90a7451..7612b93 100644
--- a/ncpd/link.cc
+++ b/ncpd/link.cc
@@ -1,27 +1,26 @@
-// $Id$
-//
-// PLP - An implementation of the PSION link protocol
-//
-// Copyright (C) 1999 Philip Proudman
-// Modifications for plptools:
-// Copyright (C) 1999 Fritz Elfert <felfert@to.com>
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// e-mail philip.proudman@btinternet.com
-
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@@ -37,199 +36,224 @@
link::link(const char *fname, int baud, IOWatch & iow, unsigned short _verbose)
{
- p = new packet(fname, baud, iow);
- verbose = _verbose;
- idSent = 0;
- idLastGot = -1;
- newLink = true;
- somethingToSend = false;
- timesSent = 0;
- failed = false;
+ p = new packet(fname, baud, iow);
+ verbose = _verbose;
+ idSent = 0;
+ idLastGot = -1;
+ newLink = true;
+ somethingToSend = false;
+ timesSent = 0;
+ failed = false;
}
link::~link()
{
- flush();
- delete p;
+ flush();
+ delete p;
}
void link::
reset() {
- idSent = 0;
- idLastGot = -1;
- newLink = true;
- somethingToSend = false;
- timesSent = 0;
- failed = false;
- // p->reset();
+ idSent = 0;
+ idLastGot = -1;
+ newLink = true;
+ somethingToSend = false;
+ timesSent = 0;
+ failed = false;
+ // p->reset();
}
short int link::
getVerbose()
{
- return verbose;
+ return verbose;
}
void link::
setVerbose(short int _verbose)
{
- verbose = _verbose;
+ verbose = _verbose;
}
short int link::
getPktVerbose()
{
- return p->getVerbose();
+ return p->getVerbose();
}
void link::
setPktVerbose(short int _verbose)
{
- p->setVerbose(_verbose);
+ p->setVerbose(_verbose);
}
void link::
send(const bufferStore & buff)
{
- if (buff.getLen() > 300)
- failed = true;
- else
- sendQueue += buff;
+ if (buff.getLen() > 300)
+ failed = true;
+ else
+ sendQueue += buff;
}
bufferArray link::
poll()
{
- bufferArray ret;
- bufferStore buff;
- unsigned char type;
-
- while (p->get(type, buff)) {
- int seq = type & 0x0f;
- bufferStore blank;
- type &= 0xf0;
- switch (type) {
- case 0x30:
- if (verbose & LNK_DEBUG_LOG) {
- cout << "link: << dat seq=" << seq ;
- if (verbose & LNK_DEBUG_DUMP)
- cout << " " << buff << endl;
- else
- cout << " len=" << buff.getLen() << endl;
- }
- // Send ack
- if (idLastGot != seq) {
- idLastGot = seq;
- ret += buff;
- } else {
- if (verbose & LNK_DEBUG_LOG)
- cout << "link: DUP\n";
- }
- if (verbose & LNK_DEBUG_LOG)
- cout << "link: >> ack seq=" << seq << endl;
- blank.init();
- p->send(seq, blank);
- break;
- case 0x00:
- // Ack
- if (seq == idSent) {
- if (verbose & LNK_DEBUG_LOG) {
- cout << "link: << ack seq=" << seq ;
- if (verbose & LNK_DEBUG_DUMP)
- cout << " " << buff;
- cout << endl;
- }
- somethingToSend = false;
- timesSent = 0;
- }
- break;
- case 0x20:
- // New link
- if (verbose & LNK_DEBUG_LOG) {
- cout << "link: << lrq seq=" << seq;
- if (verbose & LNK_DEBUG_DUMP)
- cout << " " << buff;
- cout << endl;
- }
- idLastGot = 0;
- if (verbose & LNK_DEBUG_LOG)
- cout << "link: >> lack seq=" << seq << endl;
- somethingToSend = false;
- blank.init();
- p->send(idLastGot, blank);
- break;
- case 0x10:
- // Disconnect
- if (verbose & LNK_DEBUG_LOG)
- cout << "link: << DISC" << endl;
- failed = true;
- return ret;
- }
+ bufferArray ret;
+ bufferStore buff;
+ unsigned char type;
+
+ // RX loop
+ while (p->get(type, buff)) {
+ int seq = type & 0x0f;
+ bufferStore blank;
+ type &= 0xf0;
+
+ // Support for incoming extended sequence numbers
+ if (seq & 0x08) {
+ int tseq = buff.getByte(0);
+ buff.discardFirstBytes(1);
+ seq = (tseq << 3) | (seq & 0x07);
}
- if (p->linkFailed()) {
+
+ switch (type) {
+ case 0x30:
+ // Normal data
+ if (verbose & LNK_DEBUG_LOG) {
+ cout << "link: << dat seq=" << seq ;
+ if (verbose & LNK_DEBUG_DUMP)
+ cout << " " << buff << endl;
+ else
+ cout << " len=" << buff.getLen() << endl;
+ }
+ // Send ack
+ if (idLastGot != seq) {
+ idLastGot = seq;
+ ret += buff;
+ } else {
+ if (verbose & LNK_DEBUG_LOG)
+ cout << "link: DUP\n";
+ }
+ if (verbose & LNK_DEBUG_LOG)
+ cout << "link: >> ack seq=" << seq << endl;
+ blank.init();
+
+ // Support for incoming extended sequence numbers
+ if (seq > 7) {
+ blank.addByte(seq >> 3);
+ seq &= 0x07;
+ seq |= 0x08;
+ }
+
+ p->send(seq, blank);
+ break;
+ case 0x00:
+ // Incoming ack
+ if (seq == idSent) {
+ if (verbose & LNK_DEBUG_LOG) {
+ cout << "link: << ack seq=" << seq ;
+ if (verbose & LNK_DEBUG_DUMP)
+ cout << " " << buff;
+ cout << endl;
+ }
+ somethingToSend = false;
+ timesSent = 0;
+ }
+ break;
+ case 0x20:
+ // New link
+ if (verbose & LNK_DEBUG_LOG) {
+ cout << "link: << lrq seq=" << seq;
+ if (verbose & LNK_DEBUG_DUMP)
+ cout << " " << buff;
+ cout << endl;
+ }
+ idLastGot = 0;
+ if (verbose & LNK_DEBUG_LOG)
+ cout << "link: >> lack seq=" << seq << endl;
+ somethingToSend = false;
+ blank.init();
+ p->send(idLastGot, blank);
+ break;
+ case 0x10:
+ // Disconnect
+ if (verbose & LNK_DEBUG_LOG)
+ cout << "link: << DISC" << endl;
failed = true;
return ret;
}
+ }
- if (!somethingToSend) {
- countToResend = 0;
- if (newLink) {
- somethingToSend = true;
- toSend.init();
- newLink = false;
- idSent = 0;
+ if (p->linkFailed()) {
+ failed = true;
+ return ret;
+ }
+
+ if (!somethingToSend) {
+ countToResend = 0;
+ if (newLink) {
+ somethingToSend = true;
+ toSend.init();
+ newLink = false;
+ idSent = 0;
+ } else {
+ if (!sendQueue.empty()) {
+ somethingToSend = true;
+ toSend = sendQueue.pop();
+ idSent++;
+ if (idSent > 7)
+ idSent = 0;
+ }
+ }
+ }
+ if (somethingToSend) {
+ if (countToResend == 0) {
+ timesSent++;
+ if (timesSent == 5) {
+ failed = true;
+ } else {
+ if (toSend.empty()) {
+ // Request for new link
+ if (verbose & LNK_DEBUG_LOG)
+ cout << "link: >> lrq seq=" << idSent << endl;
+ p->send(0x20 + idSent, toSend);
} else {
- if (!sendQueue.empty()) {
- somethingToSend = true;
- toSend = sendQueue.pop();
- idSent++;
- if (idSent > 7)
- idSent = 0;
- }
+ if (verbose & LNK_DEBUG_LOG) {
+ cout << "link: >> data seq=" << idSent;
+ if (verbose & LNK_DEBUG_DUMP)
+ cout << " " << toSend;
+ cout << endl;
+ }
+ p->send(0x30 + idSent, toSend);
}
- }
- if (somethingToSend) {
- if (countToResend == 0) {
- timesSent++;
- if (timesSent == 5) {
- failed = true;
- } else {
- if (toSend.empty()) {
- // Request for new link
- if (verbose & LNK_DEBUG_LOG)
- cout << "link: >> lrq seq=" << idSent << endl;
- p->send(0x20 + idSent, toSend);
- } else {
- if (verbose & LNK_DEBUG_LOG) {
- cout << "link: >> data seq=" << idSent;
- if (verbose & LNK_DEBUG_DUMP)
- cout << " " << toSend;
- cout << endl;
- }
- p->send(0x30 + idSent, toSend);
- }
- countToResend = 5;
- }
- } else
- countToResend--;
- }
- return ret;
+ countToResend = 5;
+ }
+ } else
+ countToResend--;
+ }
+ return ret;
}
void link::
flush() {
- while ((!failed) && stuffToSend())
- poll();
+ while ((!failed) && stuffToSend())
+ poll();
}
bool link::
stuffToSend()
{
- return (somethingToSend || !sendQueue.empty());
+ return (somethingToSend || !sendQueue.empty());
}
bool link::
hasFailed()
{
- return failed;
+ return failed;
}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/ncpd/linkchan.cc b/ncpd/linkchan.cc
index 21ec39f..b95ec64 100644
--- a/ncpd/linkchan.cc
+++ b/ncpd/linkchan.cc
@@ -1,29 +1,29 @@
-// $Id$
-//
-// PLP - An implementation of the PSION link protocol
-//
-// Copyright (C) 1999 Philip Proudman
-// Modifications for plptools:
-// Copyright (C) 1999 Fritz Elfert <felfert@to.com>
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// e-mail philip.proudman@btinternet.com
-
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#include <stream.h>
#include <iomanip>
+#include <string>
#include "linkchan.h"
#include "bufferstore.h"
@@ -31,90 +31,101 @@
linkChan::linkChan(ncp * _ncpController):channel(_ncpController)
{
- registerSer = 0x1234;
- ncpConnect();
+ registerSer = 0x1234;
+ ncpConnect();
}
void linkChan::
ncpDataCallback(bufferStore & a)
{
- int len = a.getLen();
- if (verbose & LINKCHAN_DEBUG_LOG) {
- cout << "linkchan: << msg ";
- if (verbose & LINKCHAN_DEBUG_DUMP)
- cout << a << endl;
- else
- cout << len << endl;
- }
- if ((len > 7) && (a.getByte(0) == 1)) {
- unsigned int ser = a.getWord(1);
- int res = a.getWord(3);
- // int dontknow = a.getWord(5);
- const char *srvName = a.getString(7);
- bufferArray newStack;
- bufferStore se;
+ int len = a.getLen();
+ if (verbose & LINKCHAN_DEBUG_LOG) {
+ cout << "linkchan: << msg ";
+ if (verbose & LINKCHAN_DEBUG_DUMP)
+ cout << a << endl;
+ else
+ cout << len << endl;
+ }
- if (verbose & LINKCHAN_DEBUG_LOG)
- cout << "linkchan: received registerAck: ser=0x" << hex << setw(4)
- << setfill(0) << ser << " res=" << res << " srvName=\""
- << srvName << "\"" << endl;
+ if ((len >= 5) && (a.getByte(0) == 1)) {
+ char srvName[20];
+ unsigned int ser = a.getWord(1);
+ int res = a.getWord(3);
+ // int dontknow = a.getWord(5);
+ bufferArray newStack;
+ bufferStore se;
+
+
+ strncpy(srvName, a.getString(7), 17);
+ if (verbose & LINKCHAN_DEBUG_LOG)
+ cout << "linkchan: received registerAck: ser=0x" << hex << setw(4)
+ << setfill(0) << ser << " res=" << res << " srvName=\""
+ << srvName << "\"" << endl;
- while (!registerStack.empty()) {
- se = registerStack.pop();
- if (se.getWord(0) == ser) {
- if (verbose & LINKCHAN_DEBUG_LOG)
- cout << "linkchan: found ser=0x" << hex << setw(4) <<
- setfill(0) << se.getWord(0) <<
- " on stack -> callBack to waiting chan" << endl;
- ncpDoRegisterAck((int)se.getWord(2));
- } else
- newStack += se;
- }
- registerStack = newStack;
- return;
+ while (!registerStack.empty()) {
+ se = registerStack.pop();
+ if (se.getWord(0) == ser) {
+ if (verbose & LINKCHAN_DEBUG_LOG)
+ cout << "linkchan: found ser=0x" << hex << setw(4) <<
+ setfill(0) << se.getWord(0) <<
+ " on stack -> callBack to waiting chan" << endl;
+ if (strlen(srvName) < 4)
+ strcat(srvName, ".*");
+ ncpDoRegisterAck((int)se.getWord(2), srvName);
+ } else
+ newStack += se;
}
- cerr << "linkchan: unknown message " << a.getByte(0) << endl;
+ registerStack = newStack;
+ return;
+ }
+ cerr << "linkchan: unknown message " << a.getByte(0) << endl;
}
char *linkChan::
-getNcpConnectName()
+getNcpRegisterName()
{
- return "LINK";
+ return "LINK";
}
void linkChan::
ncpConnectAck()
{
- if (verbose & LINKCHAN_DEBUG_LOG)
- cout << "linkchan: << cack" << endl;
+ if (verbose & LINKCHAN_DEBUG_LOG)
+ cout << "linkchan: << cack" << endl;
}
void linkChan::
ncpConnectTerminate()
{
- if (verbose & LINKCHAN_DEBUG_LOG)
- cout << "linkchan: << ctrm" << endl;
- terminateWhenAsked();
+ if (verbose & LINKCHAN_DEBUG_LOG)
+ cout << "linkchan: << ctrm" << endl;
+ terminateWhenAsked();
}
void linkChan::
ncpConnectNak()
{
- ncpConnectTerminate();
+ ncpConnectTerminate();
}
void linkChan::
Register(channel *ch)
{
- bufferStore a;
- bufferStore stack;
+ bufferStore a;
+ bufferStore stack;
- stack.addWord(registerSer);
- stack.addWord(ch->getNcpChannel());
- registerStack += stack;
- a.addByte(0);
- a.addWord(registerSer++);
- a.addString(ch->getNcpConnectName());
- a.addByte(0);
- ncpSend(a);
+ stack.addWord(registerSer);
+ stack.addWord(ch->getNcpChannel());
+ registerStack += stack;
+ a.addByte(0);
+ a.addWord(registerSer++);
+ a.addString(ch->getNcpRegisterName());
+ a.addByte(0);
+ ncpSend(a);
}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/ncpd/linkchan.h b/ncpd/linkchan.h
index 4be75d0..31df803 100644
--- a/ncpd/linkchan.h
+++ b/ncpd/linkchan.h
@@ -1,50 +1,54 @@
-// $Id$
-//
-// PLP - An implementation of the PSION link protocol
-//
-// Copyright (C) 1999 Philip Proudman
-// Modifications for plptools:
-// Copyright (C) 1999 Fritz Elfert <felfert@to.com>
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// e-mail philip.proudman@btinternet.com
-
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#ifndef _linkchan_h_
#define _linkchan_h_
#include "channel.h"
-#include "bufferarray.h"
+#include <bufferarray.h>
#define LINKCHAN_DEBUG_LOG 1
#define LINKCHAN_DEBUG_DUMP 2
class linkChan : public channel {
- public:
- linkChan(ncp *ncpController);
+public:
+ linkChan(ncp *ncpController);
- void ncpDataCallback(bufferStore &a);
- char *getNcpConnectName();
- void ncpConnectAck();
- void ncpConnectTerminate();
- void ncpConnectNak();
- void ncpRegisterAck() {}
- void Register(channel *);
- private:
- int registerSer;
- bufferArray registerStack;
+ void ncpDataCallback(bufferStore &a);
+ char *getNcpRegisterName();
+ void ncpConnectAck();
+ void ncpConnectTerminate();
+ void ncpConnectNak();
+ void ncpRegisterAck() {}
+ void Register(channel *);
+private:
+ int registerSer;
+ bufferArray registerStack;
};
-
#endif
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/ncpd/ncp.cc b/ncpd/ncp.cc
index bf99cac..31ce2c3 100644
--- a/ncpd/ncp.cc
+++ b/ncpd/ncp.cc
@@ -1,27 +1,26 @@
-// $Id$
-//
-// PLP - An implementation of the PSION link protocol
-//
-// Copyright (C) 1999 Philip Proudman
-// Modifications for plptools:
-// Copyright (C) 1999 Fritz Elfert <felfert@to.com>
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// e-mail philip.proudman@btinternet.com
-
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -32,400 +31,420 @@
#include "ncp.h"
#include "linkchan.h"
-#include "bufferstore.h"
+#include <bufferstore.h>
#include "link.h"
-#include "bufferarray.h"
+#include <bufferarray.h>
#define NCP_SENDLEN 250
ncp::ncp(const char *fname, int baud, IOWatch & iow)
{
- l = new link(fname, baud, iow);
- failed = false;
- verbose = 0;
- protocolVersion = PV_SERIES_5; // until detected on receipt of INFO
-
- // init channels
- for (int i = 0; i < MAX_CHANNEL; i++)
- channelPtr[i] = NULL;
+ l = new link(fname, baud, iow);
+ failed = false;
+ verbose = 0;
+ protocolVersion = PV_SERIES_5; // until detected on receipt of INFO
+
+ // init channels
+ for (int i = 0; i < MAX_CHANNEL; i++)
+ channelPtr[i] = NULL;
}
ncp::~ncp()
{
- bufferStore b;
- for (int i = 0; i < MAX_CHANNEL; i++) {
- if (channelPtr[i]) {
- bufferStore b2;
- b2.addByte(remoteChanList[i]);
- controlChannel(i, NCON_MSG_CHANNEL_DISCONNECT, b2);
- }
- channelPtr[i] = NULL;
+ bufferStore b;
+ for (int i = 0; i < MAX_CHANNEL; i++) {
+ if (channelPtr[i]) {
+ bufferStore b2;
+ b2.addByte(remoteChanList[i]);
+ controlChannel(i, NCON_MSG_CHANNEL_DISCONNECT, b2);
}
- controlChannel(0, NCON_MSG_NCP_END, b);
- delete l;
+ channelPtr[i] = NULL;
+ }
+ controlChannel(0, NCON_MSG_NCP_END, b);
+ delete l;
}
void ncp::
reset() {
- for (int i = 0; i < MAX_CHANNEL; i++) {
- if (channelPtr[i])
- channelPtr[i]->terminateWhenAsked();
- channelPtr[i] = NULL;
- }
- failed = false;
- lChan = NULL;
- protocolVersion = PV_SERIES_5; // until detected on receipt of INFO
- l->reset();
+ for (int i = 0; i < MAX_CHANNEL; i++) {
+ if (channelPtr[i])
+ channelPtr[i]->terminateWhenAsked();
+ channelPtr[i] = NULL;
+ }
+ failed = false;
+ lChan = NULL;
+ protocolVersion = PV_SERIES_5; // until detected on receipt of INFO
+ l->reset();
}
short int ncp::
getVerbose()
{
- return verbose;
+ return verbose;
}
void ncp::
setVerbose(short int _verbose)
{
- verbose = _verbose;
+ verbose = _verbose;
}
short int ncp::
getLinkVerbose()
{
- return l->getVerbose();
+ return l->getVerbose();
}
void ncp::
setLinkVerbose(short int _verbose)
{
- l->setVerbose(_verbose);
+ l->setVerbose(_verbose);
}
short int ncp::
getPktVerbose()
{
- return l->getPktVerbose();
+ return l->getPktVerbose();
}
void ncp::
setPktVerbose(short int _verbose)
{
- l->setPktVerbose(_verbose);
+ l->setPktVerbose(_verbose);
}
short int ncp::
getProtocolVersion()
{
- return protocolVersion;
+ return protocolVersion;
}
void ncp::
poll()
{
- bufferArray res(l->poll());
- if (!res.empty()) {
- do {
- bufferStore s = res.pop();
- if (s.getLen() > 1) {
- int channel = s.getByte(0);
- s.discardFirstBytes(1);
- if (channel == 0) {
- decodeControlMessage(s);
- } else {
- /* int remChan = */ s.getByte(0);
- int allData = s.getByte(1);
- s.discardFirstBytes(2);
- if (channelPtr[channel] == NULL) {
- cerr << "ncp: Got message for unknown channel\n";
- } else {
- messageList[channel].addBuff(s);
- if (allData == LAST_MESS) {
- channelPtr[channel]->ncpDataCallback(messageList[channel]);
- messageList[channel].init();
- } else if (allData != NOT_LAST_MESS) {
- cerr << "ncp: bizarre third byte!\n";
- }
- }
- }
- } else {
- cerr << "Got null message\n";
+ bufferArray res(l->poll());
+ if (!res.empty()) {
+ do {
+ bufferStore s = res.pop();
+ if (s.getLen() > 1) {
+ int channel = s.getByte(0);
+ s.discardFirstBytes(1);
+ if (channel == 0) {
+ decodeControlMessage(s);
+ } else {
+ /* int remChan = */ s.getByte(0);
+ int allData = s.getByte(1);
+ s.discardFirstBytes(2);
+ if (channelPtr[channel] == NULL) {
+ cerr << "ncp: Got message for unknown channel\n";
+ } else {
+ messageList[channel].addBuff(s);
+ if (allData == LAST_MESS) {
+ channelPtr[channel]->ncpDataCallback(messageList[channel]);
+ messageList[channel].init();
+ } else if (allData != NOT_LAST_MESS) {
+ cerr << "ncp: bizarre third byte!\n";
}
- } while (!res.empty());
- }
+ }
+ }
+ } else {
+ cerr << "Got null message\n";
+ }
+ } while (!res.empty());
+ }
}
void ncp::
controlChannel(int chan, enum interControllerMessageType t, bufferStore & command)
{
- bufferStore open;
- open.addByte(0); // control
-
- open.addByte(chan);
- open.addByte(t);
- open.addBuff(command);
- if (verbose & NCP_DEBUG_LOG)
- cout << "ncp: >> " << ctrlMsgName(t) << " " << chan << endl;
- l->send(open);
+ bufferStore open;
+ open.addByte(0); // control
+
+ open.addByte(chan);
+ open.addByte(t);
+ open.addBuff(command);
+ if (verbose & NCP_DEBUG_LOG)
+ cout << "ncp: >> " << ctrlMsgName(t) << " " << chan << endl;
+ l->send(open);
}
void ncp::
decodeControlMessage(bufferStore & buff)
{
- int remoteChan = buff.getByte(0);
- short int ver;
- interControllerMessageType imt = (interControllerMessageType) buff.getByte(1);
- buff.discardFirstBytes(2);
- if (verbose & NCP_DEBUG_LOG)
- cout << "ncp: << " << ctrlMsgName(imt) << " " << remoteChan;
- switch (imt) {
- case NCON_MSG_CONNECT_TO_SERVER:
- {
- if (verbose & NCP_DEBUG_LOG) {
- if (verbose & NCP_DEBUG_DUMP)
- cout << " [" << buff << "]";
- cout << endl;
- }
- int localChan;
- bufferStore b;
-
- // Ack with connect response
- localChan = getFirstUnusedChan();
- b.addByte(remoteChan);
- b.addByte(0x0);
- controlChannel(localChan, NCON_MSG_CONNECT_RESPONSE, b);
-
- // NOTE: we don't allow connections from the
- // Psion to any local "processes" other than
- // LINK.* - Matt might need to change this for
- // his NCP<->TCP/IP bridge code...
-
- if (!strcmp(buff.getString(0), "LINK.*")) {
- if (lChan)
- failed = true;
- if (verbose & NCP_DEBUG_LOG)
- cout << "ncp: Link UP" << endl;
- channelPtr[localChan] = lChan = new linkChan(this);
- lChan->setNcpChannel(localChan);
- lChan->ncpConnectAck();
- lChan->setVerbose(verbose);
- } else {
- if (verbose & NCP_DEBUG_LOG)
- cout << "ncp: Link DOWN" << endl;
- bufferStore b;
- b.addByte(remoteChan);
- controlChannel(localChan, NCON_MSG_CHANNEL_DISCONNECT, b);
- }
- }
- break;
- case NCON_MSG_CONNECT_RESPONSE:
- {
- int forChan = buff.getByte(0);
- if (verbose & NCP_DEBUG_LOG)
- cout << " ch=" << forChan << " stat=";
- if (buff.getByte(1) == 0) {
- if (verbose & NCP_DEBUG_LOG)
- cout << "OK" << endl;
- if (channelPtr[forChan]) {
- remoteChanList[forChan] = remoteChan;
- channelPtr[forChan]->ncpConnectAck();
- } else {
- if (verbose & NCP_DEBUG_LOG)
- cout << "ncp: message for unknown channel" << endl;
- }
- } else {
- if (verbose & NCP_DEBUG_LOG)
- cout << "Unknown " << (int) buff.getByte(1) << endl;
- channelPtr[forChan]->ncpConnectNak();
- }
- }
- break;
- case NCON_MSG_NCP_INFO:
- ver = buff.getByte(0);
- // Series 3c returns '3', as does mclink. PsiWin 1.1
- // returns version 2. We return whatever version we're
- // sent, which is rather crude, but works for Series 3
- // and probably 5. If Symbian have changed EPOC Connect
- // for the Series 5mx/7, this may need to change.
- //
- if (ver == PV_SERIES_5 || ver == PV_SERIES_3) {
- bufferStore b;
- protocolVersion = ver;
- if (verbose & NCP_DEBUG_LOG) {
- if (verbose & NCP_DEBUG_DUMP)
- cout << " [" << buff << "]";
- cout << endl;
- }
- // Fake NCP version 2 for a Series 3 (behave like PsiWin 1.1)
- if (ver == PV_SERIES_3)
- ver = 2;
- b.addByte(ver);
- // Do we send a time of 0 or a real time?
- // The Psion uses this to determine whether to
- // restart. (See protocol docs for details)
- // b.addDWord(0);
- b.addDWord(time(NULL));
- controlChannel(0, NCON_MSG_NCP_INFO, b);
- } else
- cout << "ALERT!!!! Unexpected Protocol Version!! (No Series 5/3?)!" << endl;
- break;
- case NCON_MSG_CHANNEL_DISCONNECT:
- if (verbose & NCP_DEBUG_LOG)
- cout << " ch=" << (int) buff.getByte(0) << endl;
- disconnect(buff.getByte(0));
- break;
- case NCON_MSG_DATA_XOFF:
- case NCON_MSG_DATA_XON:
- case NCON_MSG_CHANNEL_CLOSED:
- case NCON_MSG_NCP_END:
- default:
- if (verbose & NCP_DEBUG_LOG) {
- if (verbose & NCP_DEBUG_DUMP)
- cout << " [" << buff << "]";
- cout << endl;
- }
+ int remoteChan = buff.getByte(0);
+ short int ver;
+ interControllerMessageType imt = (interControllerMessageType) buff.getByte(1);
+ buff.discardFirstBytes(2);
+ if (verbose & NCP_DEBUG_LOG)
+ cout << "ncp: << " << ctrlMsgName(imt) << " " << remoteChan;
+ switch (imt) {
+ case NCON_MSG_CONNECT_TO_SERVER:
+ {
+ if (verbose & NCP_DEBUG_LOG) {
+ if (verbose & NCP_DEBUG_DUMP)
+ cout << " [" << buff << "]";
+ cout << endl;
+ }
+ int localChan;
+ bufferStore b;
+
+ // Ack with connect response
+ localChan = getFirstUnusedChan();
+ b.addByte(remoteChan);
+ b.addByte(0x0);
+ controlChannel(localChan, NCON_MSG_CONNECT_RESPONSE, b);
+
+ // NOTE: we don't allow connections from the
+ // Psion to any local "processes" other than
+ // LINK.* - Matt might need to change this for
+ // his NCP<->TCP/IP bridge code...
+
+ if (!strcmp(buff.getString(0), "LINK.*")) {
+ if (lChan)
+ failed = true;
+ if (verbose & NCP_DEBUG_LOG)
+ cout << "ncp: Link UP" << endl;
+ channelPtr[localChan] = lChan = new linkChan(this);
+ lChan->setNcpChannel(localChan);
+ lChan->ncpConnectAck();
+ lChan->setVerbose(verbose);
+ } else {
+ if (verbose & NCP_DEBUG_LOG)
+ cout << "ncp: Link DOWN" << endl;
+ bufferStore b;
+ b.addByte(remoteChan);
+ controlChannel(localChan, NCON_MSG_CHANNEL_DISCONNECT, b);
+ }
}
+ break;
+ case NCON_MSG_CONNECT_RESPONSE:
+ {
+ int forChan = buff.getByte(0);
+ if (verbose & NCP_DEBUG_LOG)
+ cout << " ch=" << forChan << " stat=";
+ if (buff.getByte(1) == 0) {
+ if (verbose & NCP_DEBUG_LOG)
+ cout << "OK" << endl;
+ if (channelPtr[forChan]) {
+ remoteChanList[forChan] = remoteChan;
+ channelPtr[forChan]->ncpConnectAck();
+ } else {
+ if (verbose & NCP_DEBUG_LOG)
+ cout << "ncp: message for unknown channel" << endl;
+ }
+ } else {
+ if (verbose & NCP_DEBUG_LOG)
+ cout << "Unknown " << (int) buff.getByte(1) << endl;
+ channelPtr[forChan]->ncpConnectNak();
+ }
+ }
+ break;
+ case NCON_MSG_NCP_INFO:
+ ver = buff.getByte(0);
+ // Series 3c returns '3', as does mclink. PsiWin 1.1
+ // returns version 2. We return whatever version we're
+ // sent, which is rather crude, but works for Series 3
+ // and probably 5. If Symbian have changed EPOC Connect
+ // for the Series 5mx/7, this may need to change.
+ //
+ if (ver == PV_SERIES_5 || ver == PV_SERIES_3) {
+ bufferStore b;
+ protocolVersion = ver;
+ if (verbose & NCP_DEBUG_LOG) {
+ if (verbose & NCP_DEBUG_DUMP)
+ cout << " [" << buff << "]";
+ cout << endl;
+ }
+ // Fake NCP version 2 for a Series 3 (behave like PsiWin 1.1)
+ if (ver == PV_SERIES_3)
+ ver = 2;
+ b.addByte(ver);
+ // Do we send a time of 0 or a real time?
+ // The Psion uses this to determine whether to
+ // restart. (See protocol docs for details)
+ // b.addDWord(0);
+ b.addDWord(time(NULL));
+ controlChannel(0, NCON_MSG_NCP_INFO, b);
+ } else
+ cout << "ALERT!!!! Unexpected Protocol Version!! (No Series 5/3?)!" << endl;
+ break;
+ case NCON_MSG_CHANNEL_DISCONNECT:
+ if (verbose & NCP_DEBUG_LOG)
+ cout << " ch=" << (int) buff.getByte(0) << endl;
+ disconnect(buff.getByte(0));
+ break;
+ case NCON_MSG_DATA_XOFF:
+ case NCON_MSG_DATA_XON:
+ case NCON_MSG_CHANNEL_CLOSED:
+ case NCON_MSG_NCP_END:
+ default:
+ if (verbose & NCP_DEBUG_LOG) {
+ if (verbose & NCP_DEBUG_DUMP)
+ cout << " [" << buff << "]";
+ cout << endl;
+ }
+ }
}
int ncp::
getFirstUnusedChan()
{
- for (int cNum = 1; cNum < MAX_CHANNEL; cNum++) {
- if (channelPtr[cNum] == NULL) {
- if (verbose & NCP_DEBUG_LOG)
- cout << "ncp: getFirstUnusedChan=" << cNum << endl;
- return cNum;
- }
+ for (int cNum = 1; cNum < MAX_CHANNEL; cNum++) {
+ if (channelPtr[cNum] == NULL) {
+ if (verbose & NCP_DEBUG_LOG)
+ cout << "ncp: getFirstUnusedChan=" << cNum << endl;
+ return cNum;
}
- return 0;
+ }
+ return 0;
}
void ncp::
-RegisterAck(int chan)
+RegisterAck(int chan, const char *name)
{
- if (verbose & NCP_DEBUG_LOG)
- cout << "ncp: RegisterAck: chan=" << chan << endl;
- for (int cNum = 1; cNum < MAX_CHANNEL; cNum++) {
- channel *ch = channelPtr[cNum];
- if (ch->getNcpChannel() == chan) {
- ch->ncpRegisterAck();
- return;
- }
+ if (verbose & NCP_DEBUG_LOG)
+ cout << "ncp: RegisterAck: chan=" << chan << endl;
+ for (int cNum = 1; cNum < MAX_CHANNEL; cNum++) {
+ channel *ch = channelPtr[cNum];
+ if (ch->getNcpChannel() == chan) {
+ ch->setNcpConnectName(name);
+ ch->ncpRegisterAck();
+ return;
}
- cerr << "ncp: RegisterAck: no channel to deliver" << endl;
+ }
+ cerr << "ncp: RegisterAck: no channel to deliver" << endl;
}
void ncp::
Register(channel * ch)
{
- if (lChan)
- lChan->Register(ch);
- else
- cerr << "ncp: Register without established lChan" << endl;
+ if (lChan) {
+ int cNum = ch->getNcpChannel();
+ if (cNum == 0)
+ cNum = getFirstUnusedChan();
+ if (cNum > 0) {
+ channelPtr[cNum] = ch;
+ ch->setNcpChannel(cNum);
+ lChan->Register(ch);
+ } else
+ cerr << "ncp: Out of channels in register" << endl;
+ } else
+ cerr << "ncp: Register without established lChan" << endl;
}
int ncp::
connect(channel * ch)
{
- // look for first unused chan
- int cNum = ch->getNcpChannel();
- if (cNum == 0)
- cNum = getFirstUnusedChan();
- if (cNum > 0) {
- channelPtr[cNum] = ch;
- ch->setNcpChannel(cNum);
- bufferStore b;
- b.addString(ch->getNcpConnectName());
- b.addString(".*");
- b.addByte(0);
- controlChannel(cNum, NCON_MSG_CONNECT_TO_SERVER, b);
- return cNum;
+ // look for first unused chan
+
+ int cNum = ch->getNcpChannel();
+ if (cNum == 0)
+ cNum = getFirstUnusedChan();
+ if (cNum > 0) {
+ channelPtr[cNum] = ch;
+ ch->setNcpChannel(cNum);
+ bufferStore b;
+ if (ch->getNcpConnectName())
+ b.addString(ch->getNcpConnectName());
+ else {
+ b.addString(ch->getNcpRegisterName());
+ b.addString(".*");
}
- return -1;
+ b.addByte(0);
+ controlChannel(cNum, NCON_MSG_CONNECT_TO_SERVER, b);
+ return cNum;
+ }
+ return -1;
}
void ncp::
send(int channel, bufferStore & a)
{
- bool last;
- do {
- last = true;
+ bool last;
+ do {
+ last = true;
- if (a.getLen() > NCP_SENDLEN)
- last = false;
+ if (a.getLen() > NCP_SENDLEN)
+ last = false;
- bufferStore out;
- out.addByte(remoteChanList[channel]);
- out.addByte(channel);
+ bufferStore out;
+ out.addByte(remoteChanList[channel]);
+ out.addByte(channel);
- if (last) {
- out.addByte(LAST_MESS);
- } else {
- out.addByte(NOT_LAST_MESS);
- }
+ if (last) {
+ out.addByte(LAST_MESS);
+ } else {
+ out.addByte(NOT_LAST_MESS);
+ }
- out.addBuff(a, NCP_SENDLEN);
- a.discardFirstBytes(NCP_SENDLEN);
- l->send(out);
- } while (!last);
+ out.addBuff(a, NCP_SENDLEN);
+ a.discardFirstBytes(NCP_SENDLEN);
+ l->send(out);
+ } while (!last);
}
void ncp::
disconnect(int channel)
{
- if (channelPtr[channel] == NULL) {
- cerr << "ncp: Ignored disconnect for unknown channel #" << channel << endl;
- return;
- }
- channelPtr[channel]->terminateWhenAsked();
- if (verbose & NCP_DEBUG_LOG)
- cout << "ncp: disconnect: channel=" << channel << endl;
- channelPtr[channel] = NULL;
- bufferStore b;
- b.addByte(remoteChanList[channel]);
- controlChannel(channel, NCON_MSG_CHANNEL_DISCONNECT, b);
+ if (channelPtr[channel] == NULL) {
+ cerr << "ncp: Ignored disconnect for unknown channel #" << channel << endl;
+ return;
+ }
+ channelPtr[channel]->terminateWhenAsked();
+ if (verbose & NCP_DEBUG_LOG)
+ cout << "ncp: disconnect: channel=" << channel << endl;
+ channelPtr[channel] = NULL;
+ bufferStore b;
+ b.addByte(remoteChanList[channel]);
+ controlChannel(channel, NCON_MSG_CHANNEL_DISCONNECT, b);
}
bool ncp::
stuffToSend()
{
- return l->stuffToSend();
+ return l->stuffToSend();
}
bool ncp::
hasFailed()
{
- if (failed)
- return true;
- return l->hasFailed();
+ if (failed)
+ return true;
+ return l->hasFailed();
}
bool ncp::
gotLinkChannel()
{
- return (lChan != NULL);
+ return (lChan != NULL);
}
char *ncp::
ctrlMsgName(unsigned char msgType)
{
- switch (msgType) {
- case NCON_MSG_DATA_XOFF:
- return "NCON_MSG_DATA_XOFF";
- case NCON_MSG_DATA_XON:
- return "NCON_MSG_DATA_XON";
- case NCON_MSG_CONNECT_TO_SERVER:
- return "NCON_MSG_CONNECT_TO_SERVER";
- case NCON_MSG_CONNECT_RESPONSE:
- return "NCON_MSG_CONNECT_RESPONSE";
- case NCON_MSG_CHANNEL_CLOSED:
- return "NCON_MSG_CHANNEL_CLOSED";
- case NCON_MSG_NCP_INFO:
- return "NCON_MSG_NCP_INFO";
- case NCON_MSG_CHANNEL_DISCONNECT:
- return "NCON_MSG_CHANNEL_DISCONNECT";
- case NCON_MSG_NCP_END:
- return "NCON_MSG_NCP_END";
- }
- return "NCON_MSG_UNKNOWN";
+ switch (msgType) {
+ case NCON_MSG_DATA_XOFF:
+ return "NCON_MSG_DATA_XOFF";
+ case NCON_MSG_DATA_XON:
+ return "NCON_MSG_DATA_XON";
+ case NCON_MSG_CONNECT_TO_SERVER:
+ return "NCON_MSG_CONNECT_TO_SERVER";
+ case NCON_MSG_CONNECT_RESPONSE:
+ return "NCON_MSG_CONNECT_RESPONSE";
+ case NCON_MSG_CHANNEL_CLOSED:
+ return "NCON_MSG_CHANNEL_CLOSED";
+ case NCON_MSG_NCP_INFO:
+ return "NCON_MSG_NCP_INFO";
+ case NCON_MSG_CHANNEL_DISCONNECT:
+ return "NCON_MSG_CHANNEL_DISCONNECT";
+ case NCON_MSG_NCP_END:
+ return "NCON_MSG_NCP_END";
+ }
+ return "NCON_MSG_UNKNOWN";
}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/ncpd/ncp.h b/ncpd/ncp.h
index 3b82ea8..1c4cbdc 100644
--- a/ncpd/ncp.h
+++ b/ncpd/ncp.h
@@ -1,27 +1,26 @@
-// $Id$
-//
-// PLP - An implementation of the PSION link protocol
-//
-// Copyright (C) 1999 Philip Proudman
-// Modifications for plptools:
-// Copyright (C) 1999 Fritz Elfert <felfert@to.com>
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// e-mail philip.proudman@btinternet.com
-
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#ifndef _ncp_h_
#define _ncp_h_
@@ -39,55 +38,61 @@ class IOWatch;
#define MAX_CHANNEL 8
class ncp {
- public:
- ncp(const char *fname, int baud, IOWatch &iow);
- ~ncp();
+public:
+ ncp(const char *fname, int baud, IOWatch &iow);
+ ~ncp();
- int connect(channel *c); // returns channel, or -1 if failure
- void Register(channel *c);
- void RegisterAck(int);
- void disconnect(int channel);
- void send(int channel, bufferStore &a);
- void poll();
- void reset();
- bool stuffToSend();
- bool hasFailed();
- bool gotLinkChannel();
- void setVerbose(short int);
- short int getVerbose();
- void setLinkVerbose(short int);
- short int getLinkVerbose();
- void setPktVerbose(short int);
- short int getPktVerbose();
- short int getProtocolVersion();
+ int connect(channel *c); // returns channel, or -1 if failure
+ void Register(channel *c);
+ void RegisterAck(int, const char *);
+ void disconnect(int channel);
+ void send(int channel, bufferStore &a);
+ void poll();
+ void reset();
+ bool stuffToSend();
+ bool hasFailed();
+ bool gotLinkChannel();
+ void setVerbose(short int);
+ short int getVerbose();
+ void setLinkVerbose(short int);
+ short int getLinkVerbose();
+ void setPktVerbose(short int);
+ short int getPktVerbose();
+ short int getProtocolVersion();
- private:
- enum c { MAX_LEN = 200, LAST_MESS = 1, NOT_LAST_MESS = 2 };
- enum interControllerMessageType {
- // Inter controller message types
- NCON_MSG_DATA_XOFF=1,
- NCON_MSG_DATA_XON=2,
- NCON_MSG_CONNECT_TO_SERVER=3,
- NCON_MSG_CONNECT_RESPONSE=4,
- NCON_MSG_CHANNEL_CLOSED=5,
- NCON_MSG_NCP_INFO=6,
- NCON_MSG_CHANNEL_DISCONNECT=7,
- NCON_MSG_NCP_END=8
- };
- enum protocolVersionType { PV_SERIES_5 = 6, PV_SERIES_3 = 3 };
- int getFirstUnusedChan();
- void decodeControlMessage(bufferStore &buff);
- void controlChannel(int chan, enum interControllerMessageType t, bufferStore &command);
- char * ctrlMsgName(unsigned char);
+private:
+ enum c { MAX_LEN = 200, LAST_MESS = 1, NOT_LAST_MESS = 2 };
+ enum interControllerMessageType {
+ // Inter controller message types
+ NCON_MSG_DATA_XOFF=1,
+ NCON_MSG_DATA_XON=2,
+ NCON_MSG_CONNECT_TO_SERVER=3,
+ NCON_MSG_CONNECT_RESPONSE=4,
+ NCON_MSG_CHANNEL_CLOSED=5,
+ NCON_MSG_NCP_INFO=6,
+ NCON_MSG_CHANNEL_DISCONNECT=7,
+ NCON_MSG_NCP_END=8
+ };
+ enum protocolVersionType { PV_SERIES_5 = 6, PV_SERIES_3 = 3 };
+ int getFirstUnusedChan();
+ void decodeControlMessage(bufferStore &buff);
+ void controlChannel(int chan, enum interControllerMessageType t, bufferStore &command);
+ char * ctrlMsgName(unsigned char);
- link *l;
- unsigned short verbose;
- channel *channelPtr[MAX_CHANNEL+1];
- bufferStore messageList[MAX_CHANNEL+1];
- int remoteChanList[MAX_CHANNEL+1];
- bool failed;
- short int protocolVersion;
- linkChan *lChan;
+ link *l;
+ unsigned short verbose;
+ channel *channelPtr[MAX_CHANNEL+1];
+ bufferStore messageList[MAX_CHANNEL+1];
+ int remoteChanList[MAX_CHANNEL+1];
+ bool failed;
+ short int protocolVersion;
+ linkChan *lChan;
};
#endif
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/ncpd/socketchan.cc b/ncpd/socketchan.cc
index dea883a..1eba086 100644
--- a/ncpd/socketchan.cc
+++ b/ncpd/socketchan.cc
@@ -1,44 +1,43 @@
-// $Id$
-//
-// PLP - An implementation of the PSION link protocol
-//
-// Copyright (C) 1999 Philip Proudman
-// Modifications for plptools:
-// Copyright (C) 1999 Fritz Elfert <felfert@to.com>
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// e-mail philip.proudman@btinternet.com
-
+/*-*-c++-*-
+ * $Id$
+ *
+ * This file is part of plptools.
+ *
+ * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
+ * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stream.h>
-#include "stdio.h"
-#include "string.h"
-#include "malloc.h"
+#include <stdio.h>
+#include <string.h>
+#include <malloc.h>
#include "socketchan.h"
#include "ncp.h"
-#include "ppsocket.h"
+#include <ppsocket.h>
socketChan:: socketChan(ppsocket * _skt, ncp * _ncpController):
channel(_ncpController)
{
skt = _skt;
- connectName = 0;
+ registerName = 0;
connectTry = 0;
connected = false;
}
@@ -47,23 +46,23 @@ socketChan::~socketChan()
{
skt->closeSocket();
delete skt;
- if (connectName)
- free(connectName);
+ if (registerName)
+ free(registerName);
}
void socketChan::
ncpDataCallback(bufferStore & a)
{
- if (connectName != 0) {
+ if (registerName != 0) {
skt->sendBufferStore(a);
} else
cerr << "socketchan: Connect without name!!!\n";
}
char *socketChan::
-getNcpConnectName()
+getNcpRegisterName()
{
- return connectName;
+ return registerName;
}
// NCP Command processing
@@ -145,7 +144,7 @@ ncpRegisterAck()
void socketChan::
ncpConnectNak()
{
- if (!connectName || (connectTry > 1))
+ if (!registerName || (connectTry > 1))
ncpConnectTerminate();
else {
connectTry++;
@@ -158,7 +157,7 @@ socketPoll()
{
int res;
- if (connectName == 0) {
+ if (registerName == 0) {
bufferStore a;
res = skt->getBufferStore(a, false);
switch (res) {
@@ -180,7 +179,7 @@ socketPoll()
// before any connection can be made.
//
// All commands begin with "NCP$".
-
+
// There is a magic process name called "NCP$INFO.*"
// which is announced by the rfsvfactory. This causes a
// response to be issued containing the NCP version
@@ -196,9 +195,17 @@ socketPoll()
}
// This isn't a command, it's a remote process. Connect.
- connectName = strdup(a.getString());
+ registerName = strdup(a.getString());
connectTry++;
- ncpConnect();
+
+ // If this is SYS$RFSV, we immediately connect. In all
+ // other cases, we first perform a registration. Connect
+ // is then triggered by RegisterAck and uses the name
+ // we received from the Psion.
+ if (strncmp(registerName, "SYS$RFSV", 8) == 0)
+ ncpConnect();
+ else
+ ncpRegister();
break;
case -1:
ncpConnectTerminate();
diff --git a/ncpd/socketchan.h b/ncpd/socketchan.h
index 7dde472..e90c27a 100644
--- a/ncpd/socketchan.h
+++ b/ncpd/socketchan.h
@@ -37,7 +37,7 @@ public:
virtual ~socketChan();
void ncpDataCallback(bufferStore& a);
- char* getNcpConnectName();
+ char* getNcpRegisterName();
void ncpConnectAck();
void ncpRegisterAck();
void ncpDoRegisterAck(int) {}
@@ -50,7 +50,7 @@ private:
enum protocolVersionType { PV_SERIES_5 = 6, PV_SERIES_3 = 3 };
bool ncpCommand(bufferStore &a);
ppsocket* skt;
- char* connectName;
+ char* registerName;
bool connected;
int connectTry;
};