Transport::Layer Class Reference

Class for handling Class 0 and Class 2 Transport. More...

#include <TPlayer.h>

Public Types

enum  State {
  CLOSED , WFNC , WFCR , WFCC ,
  WBCL , OPEN , CLOSING , WFTRESP
}
 

Public Member Functions

 Layer (int off)
 
void SetInbound ()
 Set as inbound Layer.
 
void SetLink (Provider *pp, Layer2Net *np)
 Set the links.
 
void Configure (unsigned maxt, unsigned cls)
 Configure.
 
EVENTSVC_DLL void Deliver (ConnectRequest *req)
 TCONreq.
 
EVENTSVC_DLL void Deliver (ConnectResponse *req)
 TCONresp.
 
EVENTSVC_DLL void Deliver (DataRequest *req)
 TDTreq/TEXreq.
 
EVENTSVC_DLL void Deliver (DisconnectRequest *data)
 TDISreq.
 
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 bool NetworkStatus (MSGstruct *msp)
 Network status indication.
 
EVENTSVC_DLL void GetSaveInfo (char *buffer, size_t buflen)
 Get save information from layer.
 
EVENTSVC_DLL bool SetSaveInfo (const char *buffer)
 Set state from save info.
 
EVENTSVC_DLL void SendConnectIndication ()
 Send TS user a connect indication.
 

Detailed Description

Class for handling Class 0 and Class 2 Transport.

Definition at line 153 of file TPlayer.h.

Member Enumeration Documentation

◆ State

Enumerator
WFNC 

Closed.

WFCR 

Wait for network Connect.

WFCC 

Wait for CR-TPDU.

WBCL 

Wait for CC-TPDU.

OPEN 

Wait before releasing.

CLOSING 

Transport connection is open.

WFTRESP 

Release in progress.

Wait for T-CONNECT response

Definition at line 155 of file TPlayer.h.

155 {
156 CLOSED,
157 WFNC,
158 WFCR,
159 WFCC,
160 WBCL,
161 OPEN,
162 CLOSING,
163 WFTRESP
164 };
@ WFCR
Wait for network Connect.
Definition TPlayer.h:158
@ WFTRESP
Release in progress.
Definition TPlayer.h:163
@ WFNC
Closed.
Definition TPlayer.h:157
@ WBCL
Wait for CC-TPDU.
Definition TPlayer.h:160
@ CLOSING
Transport connection is open.
Definition TPlayer.h:162
@ OPEN
Wait before releasing.
Definition TPlayer.h:161
@ WFCC
Wait for CR-TPDU.
Definition TPlayer.h:159

Constructor & Destructor Documentation

◆ Layer()

Transport::Layer::Layer ( int  off)
inline

Definition at line 288 of file TPlayer.h.

288 :
289 net(0), provider(0),
290 classes (TP_CLASS_0), maxtpdu(8192), offset(off),
291 useprefsize(false), state(CLOSED) {
292 pthread_mutex_lock (&refmutex);
293 ++refvalue;
294 if (refvalue > 0xFFFF)
295 refvalue = 1; // reset
296 srcref = refvalue;
297 pthread_mutex_unlock (&refmutex);
298 memset (&connect, 0, sizeof connect);
299 }
#define TP_CLASS_0
Provides a Class 0 and Class 2 interface layer.
Definition TPlayer.h:31

◆ ~Layer()

Transport::Layer::~Layer ( )

Definition at line 77 of file TPlayer.C.

78 {
79 free (connect.data);
80 }

Member Function Documentation

◆ SetInbound()

void Transport::Layer::SetInbound ( )
inline

Set as inbound Layer.

Definition at line 304 of file TPlayer.h.

304{ state = WFCR; }

References WFCR.

◆ SetLink()

void Transport::Layer::SetLink ( Provider *  pp,
Layer2Net np 
)
inline

Set the links.

Definition at line 307 of file TPlayer.h.

307 {
308 net = np;
309 provider = pp;
310 }

◆ Configure()

void Transport::Layer::Configure ( unsigned  maxt,
unsigned  cls 
)
inline

Configure.

Definition at line 313 of file TPlayer.h.

313 {
314 if ( maxtpdu != 0 )
315 maxtpdu = maxt;
316
317 if ( cls != 0 )
318 classes = cls & (TP_CLASS_0|TP_CLASS_2);
319 }

References TP_CLASS_0.

◆ Deliver() [1/4]

void Transport::Layer::Deliver ( ConnectRequest *  req)

TCONreq.

Definition at line 83 of file TPlayer.C.

84 {
85 if ( state != CLOSED ) {
86 // X.224 A.2.3 (a)
87 LOG_DEBUG (("TConreq in state %d - ignored", state));
88 return;
89 }
90
91 if ( provider->GetUser() == 0 ) {
92 InternalError (DR_nosession, "No user for CR");
93 return;
94 }
95
96 connect = *req; // struct copy
97
98 if ( req->data != 0 && req->cc > 0 ) {
99 connect.data = (char *) malloc (req->cc);
100 if ( connect.data != 0 )
101 memcpy (connect.data, req->data, req->cc);
102 } else {
103 connect.data = 0;
104 connect.cc = 0;
105 }
106
107 // Check details
108
109 DisconnectIndication disind;
110
111 // Need called network address
112 if ( connect.called.ta_addr.na_addrlen == 0 ) {
113 MSG_Tsap_NoNSAPAddress_SET (&disind.msg);
114 TDISind (disind);
115 return;
116 }
117
118 // Only support classes 0 and 2
119 // If none specified, then use class 0
120 if ( classes & ~(TP_CLASS_0|TP_CLASS_2) ) {
121 MSG_Tsap_Negotiation_SET (&disind.msg);
122 TDISind (disind);
123 return;
124 }
125
126 if ( classes == 0 )
127 classes = TP_CLASS_0;
128
129 if ( maxtpdu == 0 ) {
130 maxtpdu =
131 ( classes & TP_CLASS_2 ) ? MAXTPDU2 : MAXTPDU0;
132
133 } else {
134 // Can only set MAX TPDU in multiples of 128 bytes.
135 maxtpdu &= ~ 0x7FU;
136 }
137
138 if ( maxtpdu < MINMAXTPDU || maxtpdu > MAXTPDU2 ) {
139 MSG_Tsap_BadMaxTPDUsize_SET (&disind.msg, maxtpdu);
140 TDISind (disind);
141 return;
142 }
143
144 LOG_DEBUG (("TP %p: TCONreq -> WFNC", this));
145 state = WFNC;
146
147 net->ConnectRequest (connect.calling.ta_addr, connect.called.ta_addr);
148 }
virtual void ConnectRequest(struct NSAPaddr &calling, struct NSAPaddr &called)=0
Connect networks.

References Transport::Layer2Net::ConnectRequest(), TP_CLASS_0, and WFNC.

◆ Deliver() [2/4]

void Transport::Layer::Deliver ( ConnectResponse *  req)

TCONresp.

Definition at line 152 of file TPlayer.C.

153 {
154 if ( state != WFTRESP ) {
155 // X.224 A.2.3 (a)
156 LOG_DEBUG (("Ignoring TCONresp in state %d", state));
157 return;
158 }
159
160 // Must have dealt with any connect data by now.
161 free (connect.data);
162 connect.data = 0;
163 connect.cc = 0;
164
165 if ( req->responding.ta_selectlen > 0 ) {
166 memcpy (connect.called.ta_selector,
167 req->responding.ta_selector,
168 req->responding.ta_selectlen);
169 connect.called.ta_selectlen = req->responding.ta_selectlen;
170 }
171
172 LOG_DEBUG (("TP %p: TCONresp -> OPEN", this));
173 state = OPEN;
174 makeCC ();
175 }

References OPEN, and WFTRESP.

◆ Deliver() [3/4]

void Transport::Layer::Deliver ( DataRequest *  req)

TDTreq/TEXreq.

Definition at line 179 of file TPlayer.C.

180 {
181 if ( state != OPEN ) {
182 // X.224 A.2.3 (a)
183 LOG_DEBUG (("Ignoring TDTreq in state %d", state));
184 return;
185 }
186
187 // TEXreq not supported
188 if ( req->expedited ) {
189 InternalError (DR_protocol, "Expedited data not supported");
190 return;
191 }
192
193 makeDT (req->uv, req->eot);
194 }

References OPEN.

◆ Deliver() [4/4]

void Transport::Layer::Deliver ( DisconnectRequest *  data)

TDISreq.

Definition at line 198 of file TPlayer.C.

199 {
200 switch ( state ) {
201 case CLOSED:
202 case CLOSING:
203 case WFCR:
204 case WBCL:
205 // X.224 A.2.3 (a)
206 LOG_DEBUG (("Ignoring TDISreq in state %d", state));
207 break;
208
209 case WFNC:
210 state = CLOSED;
211 break;
212
213 case WFCC:
214 if ( classes & TP_CLASS_0 ) {
215 net->DisconnectRequest();
216 state = CLOSED;
217 } else {
218 state = WBCL;
219 }
220 break;
221
222 case WFTRESP:
223 makeDR (data->reason, data->data, data->cc);
224 state = CLOSED;
225 break;
226
227 case OPEN:
228 if ( classes & TP_CLASS_0 ) {
229 net->DisconnectRequest();
230 state = CLOSED;
231 } else {
232 makeDR (data->reason, data->data, data->cc);
233 state = CLOSING;
234 }
235 break;
236 }
237 // Tell the TSuser that we will not send it anything else
238 DisconnectIndication disind;
239 MSG_Tsap_NormalDisconnect_SET (&disind.msg);
240 TDISind (disind);
241 }
virtual void DisconnectRequest(bool force=true)=0
Disconnect Network connection.

References CLOSING, Transport::Layer2Net::DisconnectRequest(), OPEN, TP_CLASS_0, WBCL, WFCC, WFCR, WFNC, and WFTRESP.

◆ NetworkConnect()

void Transport::Layer::NetworkConnect ( NSAPaddr &  calling,
NSAPaddr &  called 
)
inline

Initialize from network connection for inbound connection.

Definition at line 334 of file TPlayer.h.

334 {
335 connect.calling.ta_addr = calling;
336 connect.called.ta_addr = called;
337 }

◆ NetworkRead()

void Transport::Layer::NetworkRead ( struct qbuf *  qb)

Handle data from network.

Definition at line 244 of file TPlayer.C.

245 {
246 const u_char *dp = reinterpret_cast<const u_char *>(qb->qb_data);
247
248 LOG_DEBUG (("NetworkRead: %ld (%d)", (long)qb->qb_len, *dp));
249
250 // Check fixed + variable part is within the overall length
251 // (Note: the LI field does not include itself)
252 if ( *dp >= qb->qb_len || *dp < 2 ) {
253 MSG_Tsap_RejectUnspecified_LOG ("Bad length field in TPKT");
254 ProtocolError (qb, 1, Reject_NotSpecified);
255 return;
256 }
257
258 // Only the top 4 bits determine TPDU type
259 switch ( dp[1] & 0xF0 ) {
260 case 0xF0: // DT
261 getDT (qb);
262 return; // As getDT is responsible for qbuf
263
264 case PDU_CR:
265 getCR (qb);
266 break;
267
268 case PDU_CC:
269 getCC (qb);
270 break;
271
272 case PDU_DR:
273 getDR (qb);
274 break;
275
276 case PDU_DC:
277 getDC (qb);
278 break;
279
280 case PDU_ED:
281 getED (qb);
282 return; // As getED is responsible for qbuf
283
284 case PDU_ER:
285 getER (qb);
286 break;
287
288 case PDU_AK:
289 case PDU_EA:
290 case PDU_RJ:
291 // Ignore known but irrelevant TPDUs
292 LOG_DEBUG (("Ignoring TPDU with type 0x%2.2X", dp[1]));
293 break;
294
295 default:
296 // Unknown TPDU, protocol error
297 MSG_Tsap_RejectBadType_LOG (dp[1]);
298 ProtocolError (qb, 2, Reject_InvalidTPDUtype);
299 break;
300 }
301
302 qb_free (qb);
303 }

◆ NetworkStatus()

bool Transport::Layer::NetworkStatus ( MSGstruct *  msp)

Network status indication.

Definition at line 306 of file TPlayer.C.

307 {
308 switch (MSG2LEVEL(msp)) {
309 case MSGLEVEL_CRITICAL:
310 case MSGLEVEL_FATAL:
311 case MSGLEVEL_ERROR:
312 // NRSTind (in effect)
313 // Will pass network layer error upwards
314 break;
315
316 case MSGLEVEL_NOTICE:
317 switch ( MSG2msgid_err (msp) ) {
318 case MSG_IOevent_ConnectionClosed:
319 // NDISind
320 if ( classes & TP_CLASS_0 )
321 MSG_Tsap_NormalDisconnect_SET (msp);
322 else
323 MSG_Tsap_NotSpecified_SET(msp);
324 break;
325
326 default:
327 LOGmessage (msp);
328 return false;
329 }
330 break;
331
332 case MSGLEVEL_SUCCESS:
333 switch ( MSG2msgid_err (msp) ) {
334 case MSG_IOevent_Connected:
335 // NCONconf
336 if ( state == WFNC ) {
337 LOG_DEBUG (("TP %p NCONconf -> WFCC", this));
338 state = WFCC;
339 makeCR();
340
341 } // else ignore it
342 return false;
343
344 default:
345 LOGmessage (msp);
346 return false;
347 }
348
349 default:
350 LOGmessage (msp);
351 return false;
352 }
353
354 // Closing down
355 if ( provider->GetUser() ) {
356 switch ( state ) {
357 default:
358 {
359 DisconnectIndication disind;
360 disind.msg = *msp;
361 TDISind (disind);
362 break;
363 }
364
365 case WFCR:
366 // Inbound connection failed before being set up
367 // User is listener so will not call Done()
368 LOGmessage (msp);
369 provider->Done();
370 break;
371
372
373 case WBCL:
374 case CLOSING:
375 // User should know that closing
376 break;
377 }
378
379 } else {
380 LOGmessage (msp);
381 }
382
383 // network should already be closed
384 net = 0;
385
386 state = CLOSED;
387
388 return true;
389 }

References CLOSING, TP_CLASS_0, WBCL, WFCC, WFCR, and WFNC.

◆ GetSaveInfo()

void Transport::Layer::GetSaveInfo ( char *  buffer,
size_t  buflen 
)

Get save information from layer.

Definition at line 524 of file TPlayer.C.

525 {
526 char callingsel[2*TSSIZE+1];
527 char callingadd[2*NASIZE+1];
528 char calledsel[2*TSSIZE+1];
529 char calledadd[2*NASIZE+1];
530
531 SaveAddr (connect.calling, callingsel, callingadd);
532 SaveAddr (connect.called, calledsel, calledadd);
533
534 if ( snprintf (buffer, buflen,
535 "%u:%u:%u:%u:%d:%d:%s.%s:%s.%s",
536 classes, maxtpdu, srcref, dstref,
537 useprefsize, state,
538 callingsel, callingadd,
539 calledsel, calledadd) < 0 )
540 // buffer filled on Windows; thus not NUL terminated
541 buffer[buflen-1] = '\0';
542 }

◆ SetSaveInfo()

bool Transport::Layer::SetSaveInfo ( const char *  buffer)

Set state from save info.

Definition at line 545 of file TPlayer.C.

546 {
547 int istate;
548 int iuse;
549
550 char callingsel[2*TSSIZE+1];
551 char callingadd[2*NASIZE+1];
552 char calledsel[2*TSSIZE+1];
553 char calledadd[2*NASIZE+1];
554
555 if ( sscanf (buffer, "%u:%u:%u:%u:%d:%d"
556 ":%[0-9A-Fa-f].%[0-9A-Fa-f]"
557 ":%[0-9A-Fa-f].%[0-9A-Fa-f]",
558 &classes, &maxtpdu, &srcref, &dstref,
559 &iuse, &istate,
560 callingsel, callingadd,
561 calledsel, calledadd) != 10 )
562 return false;
563
564 RestoreAddr (connect.calling, callingsel, callingadd);
565 RestoreAddr (connect.called, calledsel, calledadd);
566
567 state = static_cast<State>(istate);
568 useprefsize = (iuse != 0);
569
570 return true;
571 }

◆ SendConnectIndication()

void Transport::Layer::SendConnectIndication ( )

Send TS user a connect indication.

Definition at line 752 of file TPlayer.C.

752 {
753 ConnectIndication conind;
754
755 conind.newprovider = provider;
756 conind.calling = connect.calling;
757 conind.called = connect.called;
758 conind.expedited = false;
759 conind.tsdusize = maxtpdu - ((classes & TP_CLASS_0) ? 3 : 5);
760
761 // No user data at the moment
762 conind.cc = 0;
763 conind.data = 0;
764
765 provider->GetUser()->Deliver (&conind);
766 }

References TP_CLASS_0.


The documentation for this class was generated from the following files:

All rights reserved © 2002 - 2024 Isode Ltd.