24#include "../include/cdecl.h"
25#include <isode/asn1/asn1.h>
26#include <isode/ll/TSinterface.h>
27#include <isode/messages/base.h>
28#include <isode/base/util.h>
32#define TP_CLASS_2 (1<<2)
37 EVENTSVC_DLL
void TSnotify (
const User_ptr_t notifier);
41 static const unsigned TPBINC = 128;
51 static TPbuffer *GetNew (
unsigned offset) {
53 (malloc (TPBINC +
sizeof (*newbp)));
58 newbp->
dsize = TPBINC;
69 if (
dfd > 0 ) close (
dfd);
80 unsigned newlen = bufp->
doff + bufp->
dlen + len;
82 if ( bufp->
dsize < newlen ) {
83 unsigned newsize = bufp->
dsize + TPBINC;
84 if ( newsize < newlen )
85 newsize = newlen + TPBINC;
88 (realloc (bufp,
sizeof (*bufp) + newsize));
91 MSG_Base_Nomem_LOG (
sizeof (*bufp) + newsize);
97 bufp->
dsize = newsize;
100 memcpy (bufp->
data + bufp->
doff + bufp->
dlen, bytes, len);
116 void Init (Provider *p) {
120 virtual void Deliver () {
121 provider->Deliver (
this);
124 void Send (
int secs) {
126 Event::Manager::GetManager()->QueueAt (
this, 1000*secs);
128 Event::Manager::GetManager()->Queue (
this);
140 struct NSAPaddr &calling,
141 struct NSAPaddr &called) = 0;
167 static EVENTSVC_DLL pthread_mutex_t refmutex;
168 static EVENTSVC_DLL
unsigned refvalue;
173 ConnectRequest connect;
186 void TDISind (DisconnectIndication &disind) {
187 if ( provider->GetUser () ) {
188 TSnotify (provider->GetUser()->Deliver (&disind));
189 provider->ClearUser();
194 TPbuffer *GetBuffer () {
195 TPbuffer *bufp = TPbuffer::GetNew (offset);
197 InternalError (DR_congestion,
"out of memory");
205 void WritePDU (TPbuffer *bufp) {
208 Layer2Net *tmpn = net;
209 if ( state != CLOSED && tmpn != 0 )
226 void makeDR (
enum DRreason reason,
234 void makeDT (
const struct udvec *uv,
bool eot);
237 void makeED (
const u_char *data,
unsigned len);
241 Reject_NotSpecified = 0,
242 Reject_InvalidParameterCode = 1,
243 Reject_InvalidTPDUtype = 2,
244 Reject_InvalidParameterValue = 3
248 void makeER (
enum RejectCause cause,
249 const u_char *tpdu,
unsigned len);
252 void getCR (
struct qbuf *qb);
253 void getCC (
struct qbuf *qb);
254 void getDR (
struct qbuf *qb);
255 void getDC (
struct qbuf *qb);
256 void getDT (
struct qbuf *qb);
257 void getED (
struct qbuf *qb);
258 void getER (
struct qbuf *qb);
261 void ProtocolError (
struct qbuf *qb,
263 enum RejectCause cause);
266 void InternalError (
enum DRreason reason,
const char *text);
269 void SendUserDR (
enum DRreason reason,
const char *text);
272 bool DstRefOK (
struct qbuf *qb) {
273 uint16_t ref = ((qb->qb_data[2] &0xFF)<<8)|(qb->qb_data[3]&0xFF);
274 if ( ref == srcref )
return true;
275 InternalError (DR_reference,
"Invalid DST-REF in TPDU");
280 void CloseNetwork () {
281 if ( net == 0 )
return;
290 classes (
TP_CLASS_0), maxtpdu(8192), offset(off),
291 useprefsize(false), state(CLOSED) {
292 pthread_mutex_lock (&refmutex);
294 if (refvalue > 0xFFFF)
297 pthread_mutex_unlock (&refmutex);
298 memset (&connect, 0,
sizeof connect);
301 EVENTSVC_DLL ~Layer();
322 EVENTSVC_DLL
void Deliver (ConnectRequest *req);
325 EVENTSVC_DLL
void Deliver (ConnectResponse *req);
328 EVENTSVC_DLL
void Deliver (DataRequest *req);
331 EVENTSVC_DLL
void Deliver (DisconnectRequest *data);
335 connect.calling.ta_addr = calling;
336 connect.called.ta_addr = called;
347 EVENTSVC_DLL
void GetSaveInfo (
char *buffer,
size_t buflen);
351 EVENTSVC_DLL
bool SetSaveInfo (
const char *buffer);
EVENTSVC_DLL void TSnotify(const User_ptr_t notifier)
Send a notification to the transport service used via the Event Manager.
#define TP_CLASS_0
Provides a Class 0 and Class 2 interface layer.
Class giving interface from Layer to Network interface.
virtual void ConnectRequest(struct NSAPaddr &calling, struct NSAPaddr &called)=0
Connect networks.
virtual void Deliver(TPbuffer **data)=0
Write NSDU.
virtual void DisconnectRequest(bool force=true)=0
Disconnect Network connection.
Class for handling Class 0 and Class 2 Transport.
EVENTSVC_DLL void Deliver(ConnectRequest *req)
TCONreq.
void NetworkConnect(NSAPaddr &calling, NSAPaddr &called)
Initialize from network connection for inbound connection.
EVENTSVC_DLL void NetworkRead(struct qbuf *qb)
Handle data from network.
EVENTSVC_DLL void GetSaveInfo(char *buffer, size_t buflen)
Get save information from layer.
void Configure(unsigned maxt, unsigned cls)
Configure.
@ WFCR
Wait for network Connect.
@ WFTRESP
Release in progress.
@ CLOSING
Transport connection is open.
@ OPEN
Wait before releasing.
EVENTSVC_DLL bool NetworkStatus(MSGstruct *msp)
Network status indication.
void SetInbound()
Set as inbound Layer.
EVENTSVC_DLL bool SetSaveInfo(const char *buffer)
Set state from save info.
void SetLink(Provider *pp, Layer2Net *np)
Set the links.
EVENTSVC_DLL void SendConnectIndication()
Send TS user a connect indication.
Extensible buffer, used to prepare outgoing TPDUs.
unsigned doff
Offset at which Layer starts writing.
u_char data[1]
Data, actually extensible.
unsigned dsize
Total size of buffer.
static TPbuffer * Add(TPbuffer *bufp, const u_char *bytes, unsigned len)
Add bytes to buffer.
unsigned dlen
Current length of data from doff.
int dfd
FD of backing file, or -1 if none.
unsigned mlen
Length of mmapped data (if any)
void * mdata
Start address of mmapped data (if any)