plptools
Loading...
Searching...
No Matches
ncp.h
Go to the documentation of this file.
1/*
2 * This file is part of plptools.
3 *
4 * Copyright (C) 1999 Philip Proudman <philip.proudman@btinternet.com>
5 * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
6 * Copyright (C) 2026 Jason Morley <hello@jbmorley.co.uk>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * along with this program; if not, see <https://www.gnu.org/licenses/>.
20 *
21 */
22#pragma once
23
24#include "config.h"
25
26#include <vector>
27
28#include "bufferstore.h"
29#include "linkchannel.h"
30#include "ncpstatuscallback.h"
31#include "tcpsocket.h"
32
33#define MAX_CHANNELS_PSION 256
34#define MAX_CHANNELS_SIBO 8
35#define NCP_SENDLEN 250
36
37class Link;
38class Channel;
39
44class PcServer {
45public:
46 PcServer(TCPSocket *, std::string _name) { name = _name; }
48 bool clientConnect(int, int) { return false; }
49 std::string getName() { return name; }
50 PcServer *self() { return this; }
51private:
52 std::string name;
53};
54
55class NCP {
56public:
57 NCP(const char *fname,
58 int baud,
59 bool noDSRCheck,
60 unsigned short verbose,
61 const int cancellationFd,
62 NCPStatusCallback statusCallback,
63 void *context);
64 ~NCP();
65
66 int connect(Channel *c); // returns channel, or -1 if failure
67 void Register(Channel *c);
68 void RegisterAck(int, const char *);
69 void disconnect(int channel);
70 void send(int channel, BufferStore &a);
71 void reset();
72 int maxLinks();
73 bool stuffToSend();
74 bool hasFailed();
75 bool gotLinkChannel();
76
77 PcServer *findPcServer(const char *name);
78 void registerPcServer(TCPSocket *skt, const char *name);
79 void unregisterPcServer(PcServer *server);
80
81 short int getProtocolVersion();
82 int getSpeed();
83
84private:
85 friend class Link;
86
87 enum c { MAX_LEN = 200, LAST_MESS = 1, NOT_LAST_MESS = 2 };
89 // Inter controller message types
98 };
100 void receive(BufferStore s);
101 int getFirstUnusedChan();
102 bool isValidChannel(int);
104 void controlChannel(int chan, enum interControllerMessageType t, BufferStore &command);
105 const char * ctrlMsgName(unsigned char);
106
108 unsigned short verbose;
112 bool failed = false;
116 std::vector<PcServer> pcServers;
120};
A generic container for an array of bytes.
Definition: bufferstore.h:36
Definition: ncp.h:55
c
Definition: ncp.h:87
@ LAST_MESS
Definition: ncp.h:87
@ MAX_LEN
Definition: ncp.h:87
@ NOT_LAST_MESS
Definition: ncp.h:87
const char * ctrlMsgName(unsigned char)
Definition: ncp.cc:486
bool failed
Definition: ncp.h:112
int * remoteChanList
Definition: ncp.h:111
protocolVersionType
Definition: ncp.h:99
@ PV_SERIES_3
Definition: ncp.h:99
@ PV_SERIES_5
Definition: ncp.h:99
void registerPcServer(TCPSocket *skt, const char *name)
Definition: ncp.cc:160
PcServer * findPcServer(const char *name)
Definition: ncp.cc:150
void unregisterPcServer(PcServer *server)
Definition: ncp.cc:164
BufferStore * messageList
Definition: ncp.h:110
bool isValidChannel(int)
Definition: ncp.cc:359
int maxLinks()
Definition: ncp.cc:85
int lastSentChannel
Definition: ncp.h:117
bool hasFailed()
Definition: ncp.cc:458
interControllerMessageType
Definition: ncp.h:88
@ NCON_MSG_NCP_END
Definition: ncp.h:97
@ NCON_MSG_DATA_XOFF
Definition: ncp.h:90
@ NCON_MSG_NCP_INFO
Definition: ncp.h:95
@ NCON_MSG_CONNECT_TO_SERVER
Definition: ncp.h:92
@ NCON_MSG_CHANNEL_DISCONNECT
Definition: ncp.h:96
@ NCON_MSG_CHANNEL_CLOSED
Definition: ncp.h:94
@ NCON_MSG_CONNECT_RESPONSE
Definition: ncp.h:93
@ NCON_MSG_DATA_XON
Definition: ncp.h:91
LinkChannel * lChan
Definition: ncp.h:114
void decodeControlMessage(BufferStore &buff)
Definition: ncp.cc:175
void Register(Channel *c)
Definition: ncp.cc:377
Link * l
Definition: ncp.h:107
void controlChannel(int chan, enum interControllerMessageType t, BufferStore &command)
Definition: ncp.cc:138
int maxChannels
Definition: ncp.h:115
bool gotLinkChannel()
Definition: ncp.cc:478
void reset()
Definition: ncp.cc:89
Channel ** channelPtr
Definition: ncp.h:109
int getFirstUnusedChan()
Definition: ncp.cc:347
NCPStatusCallback statusCallback_
Definition: ncp.h:118
int getSpeed()
Definition: ncp.cc:482
void send(int channel, BufferStore &a)
Definition: ncp.cc:415
int connect(Channel *c)
Definition: ncp.cc:392
unsigned short verbose
Definition: ncp.h:108
short int getProtocolVersion()
Definition: ncp.cc:103
bool stuffToSend()
Definition: ncp.cc:454
~NCP()
Definition: ncp.cc:68
short int protocolVersion
Definition: ncp.h:113
void disconnect(int channel)
Definition: ncp.cc:440
std::vector< PcServer > pcServers
Definition: ncp.h:116
void * callbackContext_
Definition: ncp.h:119
void receive(BufferStore s)
Definition: ncp.cc:108
void RegisterAck(int, const char *)
Definition: ncp.cc:363
Representation of a server process on the PC A dummy which does not allow connects for now.
Definition: ncp.h:44
PcServer * self()
Definition: ncp.h:50
std::string getName()
Definition: ncp.h:49
~PcServer()
Definition: ncp.h:47
bool clientConnect(int, int)
Definition: ncp.h:48
PcServer(TCPSocket *, std::string _name)
Definition: ncp.h:46
std::string name
Definition: ncp.h:52
A class for dealing with sockets.
Definition: tcpsocket.h:37
void(* NCPStatusCallback)(void *context, bool isConnected, int protocolVersion)
static RFSV * a
Definition: main.cc:55