00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __YATESIG_H
00026 #define __YATESIG_H
00027
00028 #include <yateclass.h>
00029
00030 #ifdef _WINDOWS
00031
00032 #ifdef LIBYSIG_EXPORTS
00033 #define YSIG_API __declspec(dllexport)
00034 #else
00035 #ifndef LIBYSIG_STATIC
00036 #define YSIG_API __declspec(dllimport)
00037 #endif
00038 #endif
00039
00040 #endif
00041
00042 #ifndef YSIG_API
00043 #define YSIG_API
00044 #endif
00045
00049 namespace TelEngine {
00050
00051
00052 class SignallingDumper;
00053 class SignallingTimer;
00054 class SignallingCounter;
00055 class SignallingFactory;
00056 class SignallingComponent;
00057 class SignallingEngine;
00058 class SignallingThreadPrivate;
00059 class SignallingMessage;
00060 class SignallingCallControl;
00061 class SignallingCall;
00062 class SignallingEvent;
00063 class SignallingCircuitEvent;
00064 class SignallingCircuit;
00065 class SignallingCircuitRange;
00066 class SignallingCircuitGroup;
00067 class SignallingCircuitSpan;
00068 class SignallingInterface;
00069 class SignallingReceiver;
00070 struct SignallingFlags;
00071 class SignallingUtils;
00072
00073 class AnalogLine;
00074 class AnalogLineEvent;
00075 class AnalogLineGroup;
00076
00077 class SS7PointCode;
00078 class SS7Label;
00079 class SS7MSU;
00080 class SIGTRAN;
00081 class ASPUser;
00082 class SCCP;
00083 class SCCPUser;
00084 class TCAPUser;
00085 class SS7L2User;
00086 class SS7Layer2;
00087 class SS7L3User;
00088 class SS7Layer3;
00089 class SS7Layer4;
00090 class SS7Route;
00091 class SS7Router;
00092 class SS7M2PA;
00093 class SS7M2UA;
00094 class SS7M3UA;
00095 class SS7MTP2;
00096 class SS7MTP3;
00097 class SS7MsgSNM;
00098 class SS7MsgMTN;
00099 class SS7MsgISUP;
00100 class SS7Management;
00101 class SS7Maintenance;
00102 class SS7ISUPCall;
00103 class SS7ISUP;
00104 class SS7BICC;
00105 class SS7TUP;
00106 class SS7SCCP;
00107 class SS7SUA;
00108 class SS7ASP;
00109 class SS7TCAP;
00110
00111 class ISDNLayer2;
00112 class ISDNLayer3;
00113 class ISDNFrame;
00114 class ISDNQ921;
00115 class ISDNQ921Pasive;
00116 class ISDNIUA;
00117 class ISDNQ931IE;
00118 class ISDNQ931Message;
00119 class ISDNQ931IEData;
00120 class ISDNQ931State;
00121 class ISDNQ931Call;
00122 class ISDNQ931CallMonitor;
00123 class ISDNQ931ParserData;
00124 class ISDNQ931;
00125 class ISDNQ931Monitor;
00126
00127
00128 #define YSIGFACTORY(clas,iface) \
00129 class clas ## Factory : public SignallingFactory \
00130 { \
00131 protected: \
00132 virtual void* create(const String& type, const NamedList& name) \
00133 { return (type == #clas) ? static_cast<iface*>(new clas) : 0; } \
00134 }; \
00135 static clas ## Factory s_ ## clas ## Factory
00136
00137
00138 #define YSIGFACTORY2(clas,iface) \
00139 class clas ## Factory : public SignallingFactory \
00140 { \
00141 protected: \
00142 virtual void* create(const String& type, const NamedList& name) \
00143 { return clas::create(type,name); } \
00144 }; \
00145 static clas ## Factory s_ ## clas ## Factory
00146
00151 class YSIG_API SignallingDumper
00152 {
00153 public:
00157 enum Type {
00158 Hexa,
00159 Hdlc,
00160 Mtp2,
00161 Mtp3,
00162 };
00163
00168 SignallingDumper(Type type = Hexa);
00169
00173 ~SignallingDumper();
00174
00179 inline Type type() const
00180 { return m_type; }
00181
00186 bool active() const;
00187
00191 void terminate();
00192
00197 void setStream(Stream* stream = 0);
00198
00207 bool dump(void* buf, unsigned int len, bool sent = false, int link = 0);
00208
00216 inline bool dump(const DataBlock& data, bool sent = false, int link = 0)
00217 { return dump(data.data(),data.length(),sent,link); }
00218
00228 static SignallingDumper* create(DebugEnabler* dbg, const char* filename, Type type,
00229 bool create = true, bool append = false);
00230
00231 private:
00232 void head();
00233 Type m_type;
00234 Stream* m_output;
00235 };
00236
00241 class YSIG_API SignallingTimer
00242 {
00243 public:
00249 inline SignallingTimer(u_int64_t interval, u_int64_t time = 0)
00250 : m_interval(interval), m_timeout(0) {
00251 if (time)
00252 start(time);
00253 }
00254
00259 inline void interval(u_int64_t value)
00260 { m_interval = value; }
00261
00272 inline void interval(const NamedList& params, const char* param,
00273 unsigned int minVal, unsigned int defVal, bool allowDisable, bool sec = false) {
00274 m_interval = (u_int64_t)params.getIntValue(param,defVal);
00275 if (m_interval) {
00276 if (m_interval < minVal)
00277 m_interval = minVal;
00278 }
00279 else if (!allowDisable)
00280 m_interval = minVal;
00281 if (sec)
00282 m_interval *= 1000;
00283 }
00284
00289 inline u_int64_t interval() const
00290 { return m_interval; }
00291
00296 inline void start(u_int64_t time = Time::msecNow()) {
00297 if (m_interval)
00298 m_timeout = time + m_interval;
00299 }
00300
00304 inline void stop()
00305 { m_timeout = 0; }
00306
00311 inline bool started()
00312 { return m_timeout > 0; }
00313
00319 inline bool timeout(u_int64_t time = Time::msecNow())
00320 { return started() && (m_timeout < time); }
00321
00322 private:
00323 u_int64_t m_interval;
00324 u_int64_t m_timeout;
00325 };
00326
00331 class YSIG_API SignallingCounter
00332 {
00333 public:
00338 inline SignallingCounter(u_int32_t maxVal)
00339 : m_max(maxVal), m_count(0)
00340 {}
00341
00346 inline void maxVal(u_int32_t value)
00347 { m_max = value; }
00348
00353 inline u_int32_t maxVal() const
00354 { return m_max; }
00355
00360 inline u_int32_t count() const
00361 { return m_count; }
00362
00367 inline void reset(bool down = true)
00368 { m_count = down ? 0 : m_max; }
00369
00374 inline bool inc() {
00375 if (full())
00376 return false;
00377 m_count++;
00378 return true;
00379 }
00380
00385 inline bool dec() {
00386 if (empty())
00387 return false;
00388 m_count--;
00389 return true;
00390 }
00391
00396 inline bool empty() const
00397 { return m_count == 0; }
00398
00403 inline bool full() const
00404 { return m_count == maxVal(); }
00405
00406 private:
00407 u_int32_t m_max;
00408 u_int32_t m_count;
00409 };
00410
00415 class YSIG_API SignallingFactory : public GenObject
00416 {
00417 public:
00421 SignallingFactory();
00422
00426 virtual ~SignallingFactory();
00427
00434 static void* build(const String& type, const NamedList* name = 0);
00435
00436 protected:
00443 virtual void* create(const String& type, const NamedList& name) = 0;
00444 };
00445
00451 class YSIG_API SignallingComponent : public GenObject, public DebugEnabler
00452 {
00453 friend class SignallingEngine;
00454 public:
00458 virtual ~SignallingComponent();
00459
00464 virtual const String& toString() const;
00465
00470 inline SignallingEngine* engine() const
00471 { return m_engine; }
00472
00473 protected:
00478 inline SignallingComponent(const char* name = 0)
00479 : m_engine(0), m_name(name)
00480 { }
00481
00487 void insert(SignallingComponent* component);
00488
00495 virtual void detach();
00496
00501 virtual void timerTick(const Time& when);
00502
00507 void setName(const char* name);
00508
00509 private:
00510 SignallingEngine* m_engine;
00511 String m_name;
00512 };
00513
00519 class YSIG_API SignallingEngine : public DebugEnabler, public Mutex
00520 {
00521 friend class SignallingComponent;
00522 friend class SignallingThreadPrivate;
00523 public:
00528 SignallingEngine(const char* name = "signalling");
00529
00533 virtual ~SignallingEngine();
00534
00539 void insert(SignallingComponent* component);
00540
00545 void remove(SignallingComponent* component);
00546
00552 bool remove(const String& name);
00553
00559 SignallingComponent* find(const String& name);
00560
00566 bool find(const SignallingComponent* component);
00567
00575 bool start(const char* name = "Signalling", Thread::Priority prio = Thread::Normal, unsigned long usec = 1000);
00576
00580 void stop();
00581
00586 Thread* thread() const;
00587
00588 protected:
00593 virtual void timerTick(const Time& when);
00594
00598 ObjList m_components;
00599
00600 private:
00601 SignallingThreadPrivate* m_thread;
00602 bool m_listChanged;
00603 };
00604
00609 class YSIG_API SignallingMessage : public RefObject
00610 {
00611 public:
00616 inline SignallingMessage(const char* name = 0)
00617 : m_params(name)
00618 {}
00619
00624 inline const char* name() const
00625 { return m_params.c_str(); }
00626
00631 inline NamedList& params()
00632 { return m_params; }
00633
00634 protected:
00638 NamedList m_params;
00639 };
00640
00645 class YSIG_API SignallingCallControl : public Mutex
00646 {
00647 friend class SignallingCall;
00648 friend class SS7ISUPCall;
00649 friend class ISDNQ931Call;
00650 friend class ISDNQ931CallMonitor;
00651 public:
00658 SignallingCallControl(const NamedList& params, const char* msgPrefix = 0);
00659
00663 virtual ~SignallingCallControl();
00664
00668 inline void setExiting()
00669 { m_exiting = true; }
00670
00675 inline bool exiting() const
00676 { return m_exiting; }
00677
00682 inline bool verify() {
00683 Lock lock(this);
00684 if (!m_verifyEvent)
00685 return false;
00686 m_verifyEvent = false;
00687 return true;
00688 }
00689
00695 inline const String& msgPrefix() const
00696 { return m_msgPrefix; }
00697
00702 inline SignallingCircuitGroup* circuits() const
00703 { return m_circuits; }
00704
00712 void attach(SignallingCircuitGroup* circuits);
00713
00730 bool reserveCircuit(SignallingCircuit*& cic, const char* range = 0, int checkLock = -1,
00731 const String* list = 0, bool mandatory = true, bool reverseRestrict = false);
00732
00740 bool releaseCircuit(SignallingCircuit*& cic, bool sync = false);
00741
00749 bool releaseCircuit(unsigned int code, bool sync = false);
00750
00755 virtual void cleanup(const char* reason = "offline")
00756 {}
00757
00763 virtual SignallingEvent* getEvent(const Time& when);
00764
00771 virtual SignallingCall* call(SignallingMessage* msg, String& reason)
00772 { reason = "not-implemented"; return 0; }
00773
00778 virtual void buildVerifyEvent(NamedList& params)
00779 {}
00780
00785 void setDumper(SignallingDumper* dumper = 0);
00786
00787 protected:
00792 inline int strategy() const
00793 { return m_strategy; }
00794
00802 virtual bool processEvent(SignallingEvent* event)
00803 { return false; }
00804
00811 virtual SignallingEvent* processCircuitEvent(SignallingCircuitEvent& event,
00812 SignallingCall* call = 0)
00813 { return 0; }
00814
00818 void clearCalls();
00819
00825 void removeCall(SignallingCall* call, bool del = false);
00826
00835 inline bool dump(const DataBlock& data, bool sent = false, int link = 0) {
00836 Lock lock(this);
00837 return (m_dumper && m_dumper->dump(data.data(),data.length(),sent,link));
00838 }
00839
00843 ObjList m_calls;
00844
00849 String m_msgPrefix;
00850
00855 bool m_verifyEvent;
00856
00860 SignallingTimer m_verifyTimer;
00861
00862 private:
00863 SignallingCircuitGroup* m_circuits;
00864 int m_strategy;
00865 bool m_exiting;
00866 SignallingDumper* m_dumper;
00867 };
00868
00873 class YSIG_API SignallingCall : public RefObject
00874 {
00875 public:
00882 SignallingCall(SignallingCallControl* controller, bool outgoing, bool signalOnly = false);
00883
00887 virtual ~SignallingCall();
00888
00893 inline bool outgoing() const
00894 { return m_outgoing; }
00895
00899 inline SignallingCallControl* controller() const
00900 { return m_controller; }
00901
00906 inline void userdata(void* data)
00907 { m_private = data; }
00908
00913 inline void* userdata() const
00914 { return m_private; }
00915
00920 inline bool signalOnly() const
00921 { return m_signalOnly; }
00922
00928 virtual bool sendEvent(SignallingEvent* event)
00929 { return false; }
00930
00937 virtual SignallingEvent* getEvent(const Time& when) = 0;
00938
00945 virtual void eventTerminated(SignallingEvent* event);
00946
00947 protected:
00953 void enqueue(SignallingMessage* msg);
00954
00961 SignallingMessage* dequeue(bool remove = true);
00962
00966 void clearQueue() {
00967 Lock lock(m_inMsgMutex);
00968 m_inMsg.clear();
00969 }
00970
00974 Mutex m_callMutex;
00975
00979 SignallingEvent* m_lastEvent;
00980
00981 private:
00982 SignallingCallControl* m_controller;
00983 bool m_outgoing;
00984 bool m_signalOnly;
00985 ObjList m_inMsg;
00986 Mutex m_inMsgMutex;
00987 void* m_private;
00988 };
00989
00994 class YSIG_API SignallingEvent
00995 {
00996 public:
01000 enum Type {
01001 Unknown = 0,
01002 Generic,
01003
01004 NewCall,
01005 Accept,
01006 Connect,
01007 Complete,
01008 Progress,
01009 Ringing,
01010 Answer,
01011 Transfer,
01012 Suspend,
01013 Resume,
01014 Release,
01015 Info,
01016
01017 Message,
01018 Facility,
01019
01020 Enable,
01021 Disable,
01022 Reset,
01023 Verify,
01024 };
01025
01032 SignallingEvent(Type type, SignallingMessage* message, SignallingCall* call);
01033
01040 SignallingEvent(Type type, SignallingMessage* message, SignallingCallControl* controller = 0);
01041
01045 virtual ~SignallingEvent();
01046
01051 inline const char* name() const
01052 { return typeName(type()); }
01053
01058 inline Type type() const
01059 { return m_type; }
01060
01064 inline SignallingCall* call() const
01065 { return m_call; }
01066
01070 inline SignallingMessage* message() const
01071 { return m_message; }
01072
01076 inline SignallingCallControl* controller() const
01077 { return m_controller; }
01078
01084 static inline const char* typeName(Type t)
01085 { return lookup(t,s_types,0); }
01086
01087 private:
01088 Type m_type;
01089 SignallingMessage* m_message;
01090 SignallingCall* m_call;
01091 SignallingCallControl* m_controller;
01092 static TokenDict s_types[];
01093 };
01094
01099 class YSIG_API SignallingCircuitEvent : public NamedList
01100 {
01101 public:
01105 enum Type {
01106 Unknown = 0,
01107 Dtmf = 1,
01108
01109 Timeout = 10,
01110 Polarity = 11,
01111 StartLine = 15,
01112 LineStarted = 16,
01113 DialComplete = 17,
01114 OnHook = 20,
01115 OffHook = 21,
01116 RingBegin = 22,
01117 RingEnd = 23,
01118 RingerOn = 30,
01119 RingerOff = 31,
01120 Wink = 32,
01121 Flash = 33,
01122 PulseStart = 40,
01123 PulseDigit = 41,
01124
01125 Alarm = 100,
01126 NoAlarm = 101,
01127 };
01128
01135 SignallingCircuitEvent(SignallingCircuit* cic, Type type, const char* name = 0);
01136
01140 virtual ~SignallingCircuitEvent();
01141
01146 inline Type type() const
01147 { return m_type; }
01148
01153 inline SignallingCircuit* circuit()
01154 { return m_circuit; }
01155
01156 private:
01157 SignallingCircuit* m_circuit;
01158 Type m_type;
01159 };
01160
01165 class YSIG_API SignallingCircuit : public RefObject
01166 {
01167 friend class SignallingCircuitGroup;
01168 friend class SignallingCircuitEvent;
01169 public:
01173 enum Type {
01174 Unknown = 0,
01175 Local,
01176 TDM,
01177 RTP,
01178 IAX,
01179 };
01180
01184 enum Status {
01185 Missing = 0,
01186 Disabled,
01187 Idle,
01188 Reserved,
01189 Starting,
01190 Stopping,
01191 Connected,
01192 };
01193
01197 enum LockFlags {
01198 LockLocalHWFail = 0x0001,
01199 LockLocalMaint = 0x0002,
01200 LockLocalHWFailChg = 0x0010,
01201 LockLocalMaintChg = 0x0020,
01202 LockRemoteHWFail = 0x0100,
01203 LockRemoteMaint = 0x0200,
01204 LockRemoteHWFailChg = 0x1000,
01205 LockRemoteMaintChg = 0x2000,
01206
01207 LockLocal = LockLocalHWFail | LockLocalMaint,
01208 LockRemote = LockRemoteHWFail | LockRemoteMaint,
01209 LockLocked = LockLocal | LockRemote,
01210 LockLocalChg = LockLocalHWFailChg | LockLocalMaintChg,
01211 LockRemoteChg = LockRemoteHWFailChg | LockRemoteMaintChg,
01212 LockChanged = LockLocalChg | LockRemoteChg,
01213 };
01214
01218 virtual ~SignallingCircuit();
01219
01226 virtual bool status(Status newStat, bool sync = false)
01227 { m_status = newStat; return true; }
01228
01233 inline Type type() const
01234 { return m_type; }
01235
01240 inline Status status() const
01241 { return m_status; }
01242
01248 inline int locked(int flags = -1) const
01249 { return (m_lock & flags); }
01250
01255 inline void setLock(int flags)
01256 { m_lock |= flags; }
01257
01262 inline void resetLock(int flags)
01263 { m_lock &= ~flags; }
01264
01271 virtual bool updateFormat(const char* format, int direction)
01272 { return false; }
01273
01280 virtual bool setParam(const String& param, const String& value)
01281 { return false; }
01282
01289 virtual bool getParam(const String& param, String& value) const
01290 { return false; }
01291
01296 inline SignallingCircuitGroup* group()
01297 { return m_group; }
01298
01303 inline SignallingCircuitSpan* span()
01304 { return m_span; }
01305
01310 inline const SignallingCircuitGroup* group() const
01311 { return m_group; }
01312
01317 inline unsigned int code() const
01318 { return m_code; }
01319
01324 inline bool available() const
01325 { return m_status == Idle; }
01326
01331 inline bool connected() const
01332 { return m_status == Connected; }
01333
01338 inline bool reserve()
01339 { return available() && status(Reserved,true); }
01340
01346 inline bool connect(const char* format = 0)
01347 { updateFormat(format,0); return status(Connected,true); }
01348
01353 inline bool disconnect()
01354 { return status() == Connected && status(Reserved,true); }
01355
01360 inline bool disable()
01361 { return status(Disabled,true); }
01362
01371 bool hwLock(bool set, bool remote, bool changed = false, bool setChanged = false);
01372
01381 bool maintLock(bool set, bool remote, bool changed = false, bool setChanged = false);
01382
01388 void addEvent(SignallingCircuitEvent* event);
01389
01396 SignallingCircuitEvent* getEvent(const Time& when);
01397
01404 virtual bool sendEvent(SignallingCircuitEvent::Type type, NamedList* params = 0);
01405
01411 static const char* lookupType(int type);
01412
01418 static const char* lookupStatus(int status);
01419
01423 static TokenDict s_lockNames[];
01424
01425 protected:
01429 SignallingCircuit(Type type, unsigned int code, SignallingCircuitGroup* group = 0,
01430 SignallingCircuitSpan* span = 0);
01431
01435 SignallingCircuit(Type type, unsigned int code, Status status,
01436 SignallingCircuitGroup* group = 0, SignallingCircuitSpan* span = 0);
01437
01442 virtual void clearEvents();
01443
01448 void eventTerminated(SignallingCircuitEvent* event);
01449
01453 Mutex m_mutex;
01454
01455 private:
01456 SignallingCircuitGroup* m_group;
01457 SignallingCircuitSpan* m_span;
01458 unsigned int m_code;
01459 Type m_type;
01460 Status m_status;
01461 int m_lock;
01462 ObjList m_events;
01463 SignallingCircuitEvent* m_lastEvent;
01464 };
01465
01473 class YSIG_API SignallingCircuitRange : public String
01474 {
01475 friend class SignallingCircuitGroup;
01476 public:
01483 SignallingCircuitRange(const String& rangeStr, const char* name = 0,
01484 int strategy = -1);
01485
01489 virtual ~SignallingCircuitRange()
01490 { clear(); }
01491
01496 inline unsigned int count() const
01497 { return m_count; }
01498
01503 inline const unsigned int* range() const
01504 { return (const unsigned int*)m_range.data(); }
01505
01510 inline void clear()
01511 { m_range.clear(); m_count = 0; }
01512
01518 inline unsigned int operator[](unsigned int index)
01519 { return range()[index]; }
01520
01526 inline bool set(const String& rangeStr) {
01527 clear();
01528 return add(rangeStr);
01529 }
01530
01536 bool add(const String& rangeStr);
01537
01543 void add(unsigned int* codes, unsigned int len);
01544
01549 inline void add(unsigned int code)
01550 { add(&code,1); }
01551
01556 void remove(unsigned int code);
01557
01563 bool find(unsigned int code);
01564
01568 virtual void destruct() {
01569 clear();
01570 String::destruct();
01571 }
01572
01573 protected:
01574 void updateLast();
01575
01576 DataBlock m_range;
01577 unsigned int m_count;
01578 unsigned int m_last;
01579 int m_strategy;
01580 unsigned int m_used;
01581 };
01582
01587 class YSIG_API SignallingCircuitGroup : public SignallingComponent, public Mutex
01588 {
01589 friend class SignallingCircuit;
01590 friend class SignallingCallControl;
01591 friend class SS7ISUP;
01592 friend class ISDNQ931;
01593 public:
01597 enum Strategy {
01598 Other = 0,
01599
01600 Increment = 0x0001,
01601 Decrement = 0x0002,
01602 Lowest = 0x0003,
01603 Highest = 0x0004,
01604 Random = 0x0005,
01605
01606 OnlyEven = 0x1000,
01607 OnlyOdd = 0x2000,
01608
01609 Fallback = 0x4000,
01610 };
01611
01618 SignallingCircuitGroup(unsigned int base = 0, int strategy = Increment,
01619 const char* name = "circgroup");
01620
01624 ~SignallingCircuitGroup();
01625
01630 inline unsigned int count() const
01631 { return m_circuits.count(); }
01632
01637 inline unsigned int base() const
01638 { return m_base; }
01639
01644 inline unsigned int last() const
01645 { return m_range.m_last; }
01646
01651 inline int strategy() const
01652 { return m_range.m_strategy; }
01653
01658 inline void setStrategy(int strategy)
01659 { Lock lock(this); m_range.m_strategy = strategy; }
01660
01664 inline ObjList& circuits()
01665 { return m_circuits; }
01666
01671 void getCicList(String& dest);
01672
01678 bool insert(SignallingCircuit* circuit);
01679
01684 void remove(SignallingCircuit* circuit);
01685
01691 bool insertSpan(SignallingCircuitSpan* span);
01692
01700 void insertRange(SignallingCircuitSpan* span, const char* name,
01701 int strategy = -1);
01702
01711 void insertRange(const String& range, const char* name,
01712 int strategy = -1);
01713
01720 void removeSpan(SignallingCircuitSpan* span, bool delCics = true, bool delSpan = false);
01721
01726 void removeSpanCircuits(SignallingCircuitSpan* span);
01727
01734 SignallingCircuit* find(unsigned int cic, bool local = false);
01735
01741 SignallingCircuitRange* findRange(const char* name);
01742
01748 SignallingCircuit::Status status(unsigned int cic);
01749
01757 bool status(unsigned int cic, SignallingCircuit::Status newStat, bool sync = false);
01758
01766 SignallingCircuit* reserve(int checkLock = -1, int strategy = -1,
01767 SignallingCircuitRange* range = 0);
01768
01780 SignallingCircuit* reserve(const String& list, bool mandatory,
01781 int checkLock = -1, int strategy = -1, SignallingCircuitRange* range = 0);
01782
01789 inline bool release(SignallingCircuit* cic, bool sync = false)
01790 { return cic && cic->status(SignallingCircuit::Idle,sync); }
01791
01795 virtual void destruct() {
01796 clearAll();
01797 SignallingComponent::destruct();
01798 }
01799
01806 static int str2strategy(const char* name, int def = Increment)
01807 { return lookup(name,s_strategy,def); }
01808
01812 static TokenDict s_strategy[];
01813
01814 private:
01815 unsigned int advance(unsigned int n, int strategy, SignallingCircuitRange& range);
01816 void clearAll();
01817
01818 ObjList m_circuits;
01819 ObjList m_spans;
01820 ObjList m_ranges;
01821 SignallingCircuitRange m_range;
01822 unsigned int m_base;
01823 };
01824
01829 class YSIG_API SignallingCircuitSpan : public GenObject
01830 {
01831 public:
01837 SignallingCircuitSpan(const char* id = 0, SignallingCircuitGroup* group = 0);
01838
01842 virtual ~SignallingCircuitSpan();
01843
01848 inline SignallingCircuitGroup* group() const
01849 { return m_group; }
01850
01855 inline const String& id() const
01856 { return m_id; }
01857
01858 protected:
01862 SignallingCircuitGroup* m_group;
01863
01864 private:
01865 String m_id;
01866 };
01867
01872 class YSIG_API SignallingInterface : virtual public SignallingComponent
01873 {
01874 friend class SignallingReceiver;
01875 public:
01879 enum Operation {
01880 Specific = 0,
01881 EnableTx = 0x01,
01882 EnableRx = 0x02,
01883 Enable = 0x03,
01884 DisableTx = 0x04,
01885 DisableRx = 0x08,
01886 Disable = 0x0c,
01887 FlushTx = 0x10,
01888 FlushRx = 0x20,
01889 Flush = 0x30,
01890 QueryTx = 0x40,
01891 QueryRx = 0x80,
01892 Query = 0xc0
01893 };
01894
01898 enum Notification {
01899 LinkUp = 0,
01900 LinkDown,
01901 HardwareError,
01902 TxClockError,
01903 RxClockError,
01904 AlignError,
01905 CksumError,
01906 TxOversize,
01907 RxOversize,
01908 TxOverflow,
01909 RxOverflow,
01910 TxUnderrun,
01911 RxUnderrun,
01912 };
01913
01917 enum PacketType {
01918 Unknown = 0,
01919 SS7Fisu,
01920 SS7Lssu,
01921 SS7Msu,
01922 Q921
01923 };
01924
01928 inline SignallingInterface()
01929 : m_recvMutex(true), m_receiver(0)
01930 {}
01931
01935 virtual ~SignallingInterface();
01936
01941 virtual void attach(SignallingReceiver* receiver);
01942
01947 inline SignallingReceiver* receiver() const
01948 { return m_receiver; }
01949
01959 virtual bool control(Operation oper, NamedList* params = 0);
01960
01964 static TokenDict s_notifName[];
01965
01966 protected:
01975 virtual bool transmitPacket(const DataBlock& packet, bool repeat, PacketType type) = 0;
01976
01982 bool receivedPacket(const DataBlock& packet);
01983
01989 bool notify(Notification event);
01990
01991 private:
01992 Mutex m_recvMutex;
01993 SignallingReceiver* m_receiver;
01994 };
01995
02000 class YSIG_API SignallingReceiver : virtual public SignallingComponent
02001 {
02002 friend class SignallingInterface;
02003 public:
02007 inline SignallingReceiver()
02008 : m_ifaceMutex(true), m_interface(0)
02009 {}
02010
02014 virtual ~SignallingReceiver();
02015
02020 virtual void attach(SignallingInterface* iface);
02021
02026 inline SignallingInterface* iface() const
02027 { return m_interface; }
02028
02036 inline bool control(SignallingInterface::Operation oper, NamedList* params = 0) {
02037 Lock lock(m_ifaceMutex);
02038 return m_interface && m_interface->control(oper,params);
02039 }
02040
02041 protected:
02050 inline bool transmitPacket(const DataBlock& packet, bool repeat,
02051 SignallingInterface::PacketType type = SignallingInterface::Unknown) {
02052 Lock lock(m_ifaceMutex);
02053 return m_interface && m_interface->transmitPacket(packet,repeat,type);
02054 }
02055
02060 virtual bool receivedPacket(const DataBlock& packet) = 0;
02061
02067 virtual bool notify(SignallingInterface::Notification event);
02068
02069 private:
02070 Mutex m_ifaceMutex;
02071 SignallingInterface* m_interface;
02072 };
02073
02074
02079 struct SignallingFlags
02080 {
02084 unsigned int mask;
02085
02089 unsigned int value;
02090
02094 const char* name;
02095 };
02096
02101 class YSIG_API SignallingUtils
02102 {
02103 public:
02108 static const TokenDict* codings();
02109
02114 static const TokenDict* locations();
02115
02127 static inline const TokenDict* dict(unsigned int index, unsigned char coding = 0) {
02128 if (index > 4)
02129 return 0;
02130 return (!coding ? s_dictCCITT[index] : 0);
02131 }
02132
02140 static bool hasFlag(const NamedList& list, const char* param, const char* flag);
02141
02148 static bool removeFlag(String& flags, const char* flag);
02149
02157 static void addKeyword(NamedList& list, const char* param,
02158 const TokenDict* tokens, unsigned int val);
02159
02169 static void dumpData(const SignallingComponent* comp, NamedList& list, const char* param,
02170 const unsigned char* buf, unsigned int len, char sep = ' ');
02171
02184 static unsigned int dumpDataExt(const SignallingComponent* comp, NamedList& list, const char* param,
02185 const unsigned char* buf, unsigned int len, char sep = ' ');
02186
02198 static bool decodeFlags(const SignallingComponent* comp, NamedList& list, const char* param,
02199 const SignallingFlags* flags, const unsigned char* buf, unsigned int len);
02200
02211 static bool decodeCause(const SignallingComponent* comp, NamedList& list, const unsigned char* buf,
02212 unsigned int len, const char* prefix, bool isup);
02213
02224 static bool decodeCaps(const SignallingComponent* comp, NamedList& list, const unsigned char* buf,
02225 unsigned int len, const char* prefix, bool isup);
02226
02236 static void encodeFlags(const SignallingComponent* comp, int& dest, const String& flags,
02237 TokenDict* dict);
02238
02250 static bool encodeCause(const SignallingComponent* comp, DataBlock& buf, const NamedList& params,
02251 const char* prefix, bool isup, bool fail = false);
02252
02262 static bool encodeCaps(const SignallingComponent* comp, DataBlock& buf, const NamedList& params,
02263 const char* prefix, bool isup);
02264
02277 static unsigned int* parseUIntArray(const String& source, unsigned int minVal, unsigned int maxVal,
02278 unsigned int& count, bool discardDup);
02279
02280 private:
02281 static TokenDict* s_dictCCITT[5];
02282 };
02283
02289 class YSIG_API AnalogLine : public RefObject, public Mutex
02290 {
02291 friend class AnalogLineGroup;
02292 public:
02296 enum Type {
02297 FXO,
02298 FXS,
02299 Recorder,
02300 Monitor,
02301 Unknown
02302 };
02303
02307 enum State {
02308 OutOfService = -1,
02309 Idle = 0,
02310 Dialing = 1,
02311 DialComplete = 2,
02312 Ringing = 3,
02313 Answered = 4,
02314 CallEnded = 5,
02315 OutOfOrder = 6,
02316 };
02317
02321 enum CallSetupInfo {
02322 After,
02323 Before,
02324 NoCallSetup
02325 };
02326
02334 AnalogLine(AnalogLineGroup* grp, unsigned int cic, const NamedList& params);
02335
02339 virtual ~AnalogLine();
02340
02345 inline Type type() const
02346 { return m_type; }
02347
02352 inline State state() const
02353 { return m_state; }
02354
02359 inline AnalogLineGroup* group()
02360 { return m_group; }
02361
02366 inline AnalogLine* getPeer()
02367 { return m_peer; }
02368
02374 void setPeer(AnalogLine* line = 0, bool sync = true);
02375
02380 inline SignallingCircuit* circuit()
02381 { return m_circuit; }
02382
02387 inline const char* address() const
02388 { return m_address; }
02389
02394 inline bool outbandDtmf() const
02395 { return !m_inband; }
02396
02401 inline bool answerOnPolarity() const
02402 { return m_answerOnPolarity; }
02403
02408 inline bool hangupOnPolarity() const
02409 { return m_hangupOnPolarity; }
02410
02415 inline bool polarityControl() const
02416 { return m_polarityControl; }
02417
02422 inline CallSetupInfo callSetup() const
02423 { return m_callSetup; }
02424
02429 inline u_int64_t callSetupTimeout() const
02430 { return m_callSetupTimeout; }
02431
02436 inline u_int64_t noRingTimeout() const
02437 { return m_noRingTimeout; }
02438
02443 inline u_int64_t alarmTimeout() const
02444 { return m_alarmTimeout; }
02445
02450 inline u_int64_t delayDial() const
02451 { return m_delayDial; }
02452
02457 inline void acceptPulseDigit(bool ok)
02458 { m_acceptPulseDigit = ok; }
02459
02464 inline void* userdata() const
02465 { return m_private; }
02466
02472 inline void userdata(void* data, bool sync = true) {
02473 Lock lock(this);
02474 m_private = data;
02475 if (sync && m_peer)
02476 m_peer->userdata(data,false);
02477 }
02478
02483 virtual const String& toString() const
02484 { return m_address; }
02485
02490 void resetEcho(bool train);
02491
02496 inline bool resetCircuit()
02497 { return state() != OutOfService && m_circuit && m_circuit->reserve(); }
02498
02505 inline bool setCircuitParam(const char* param, const char* value = 0)
02506 { return m_circuit && m_circuit->setParam(param,value); }
02507
02513 bool connect(bool sync);
02514
02520 bool disconnect(bool sync);
02521
02528 bool sendEvent(SignallingCircuitEvent::Type type, NamedList* params = 0);
02529
02537 inline bool sendEvent(SignallingCircuitEvent::Type type, State newState,
02538 NamedList* params = 0) {
02539 if (!sendEvent(type,params))
02540 return false;
02541 changeState(newState,false);
02542 return true;
02543 }
02544
02550 virtual AnalogLineEvent* getEvent(const Time& when);
02551
02557 virtual AnalogLineEvent* getMonitorEvent(const Time& when);
02558
02563 virtual void checkTimeouts(const Time& when)
02564 {}
02565
02572 bool changeState(State newState, bool sync = false);
02573
02582 bool enable(bool ok, bool sync, bool connectNow = true);
02583
02587 static const TokenDict* typeNames();
02588
02592 static const TokenDict* stateNames();
02593
02597 static const TokenDict* csNames();
02598
02599 protected:
02603 virtual void destroyed();
02604
02605 private:
02606 Type m_type;
02607 State m_state;
02608 bool m_inband;
02609 int m_echocancel;
02610 bool m_acceptPulseDigit;
02611 bool m_answerOnPolarity;
02612 bool m_hangupOnPolarity;
02613 bool m_polarityControl;
02614 CallSetupInfo m_callSetup;
02615 u_int64_t m_callSetupTimeout;
02616 u_int64_t m_noRingTimeout;
02617 u_int64_t m_alarmTimeout;
02618 u_int64_t m_delayDial;
02619 AnalogLineGroup* m_group;
02620 SignallingCircuit* m_circuit;
02621 String m_address;
02622 void* m_private;
02623
02624 AnalogLine* m_peer;
02625 bool m_getPeerEvent;
02626 };
02627
02632 class YSIG_API AnalogLineEvent : public GenObject
02633 {
02634 public:
02640 AnalogLineEvent(AnalogLine* line, SignallingCircuitEvent* event)
02641 : m_line(0), m_event(event) {
02642 if (line && line->ref())
02643 m_line = line;
02644 }
02645
02649 virtual ~AnalogLineEvent() {
02650 TelEngine::destruct(m_line);
02651 TelEngine::destruct(m_event);
02652 }
02653
02658 inline AnalogLine* line()
02659 { return m_line; }
02660
02665 inline SignallingCircuitEvent* event()
02666 { return m_event; }
02667
02671 virtual void destruct() {
02672 TelEngine::destruct(m_line);
02673 TelEngine::destruct(m_event);
02674 GenObject::destruct();
02675 }
02676
02677 private:
02678 AnalogLine* m_line;
02679 SignallingCircuitEvent* m_event;
02680 };
02681
02687 class YSIG_API AnalogLineGroup : public SignallingCircuitGroup
02688 {
02689 public:
02696 AnalogLineGroup(AnalogLine::Type type, const char* name, bool slave = false);
02697
02704 AnalogLineGroup(const char* name, AnalogLineGroup* fxo);
02705
02709 virtual ~AnalogLineGroup();
02710
02715 inline AnalogLine::Type type() const
02716 { return m_type; }
02717
02722 inline ObjList& lines()
02723 { return m_lines; }
02724
02729 inline AnalogLineGroup* fxo()
02730 { return m_fxo; }
02731
02736 inline bool slave()
02737 { return m_slave; }
02738
02745 bool appendLine(AnalogLine* line, bool destructOnFail = true);
02746
02751 void removeLine(unsigned int cic);
02752
02757 void removeLine(AnalogLine* line);
02758
02764 AnalogLine* findLine(unsigned int cic);
02765
02771 AnalogLine* findLine(const String& address);
02772
02778 virtual AnalogLineEvent* getEvent(const Time& when);
02779
02783 virtual void destruct();
02784
02785 protected:
02789 ObjList m_lines;
02790
02791 private:
02792 AnalogLine::Type m_type;
02793 AnalogLineGroup* m_fxo;
02794 bool m_slave;
02795 };
02796
02801 class YSIG_API SS7PointCode : public GenObject
02802 {
02803 public:
02807 enum Type {
02808 Other = 0,
02809 ITU = 1,
02810 ANSI = 2,
02811 ANSI8 = 3,
02812 China = 4,
02813 Japan = 5,
02814 Japan5 = 6,
02815
02816 DefinedTypes
02817 };
02818
02825 inline SS7PointCode(unsigned char network = 0, unsigned char cluster = 0, unsigned char member = 0)
02826 : m_network(network), m_cluster(cluster), m_member(member)
02827 { }
02828
02834 inline SS7PointCode(Type type, unsigned int packed)
02835 : m_network(0), m_cluster(0), m_member(0)
02836 { unpack(type,packed); }
02837
02842 inline SS7PointCode(const SS7PointCode& original)
02843 : m_network(original.network()), m_cluster(original.cluster()), m_member(original.member())
02844 { }
02845
02849 inline ~SS7PointCode()
02850 { }
02851
02856 inline unsigned char network() const
02857 { return m_network; }
02858
02863 inline unsigned char cluster() const
02864 { return m_cluster; }
02865
02870 inline unsigned char member() const
02871 { return m_member; }
02872
02879 inline void assign(unsigned char network, unsigned char cluster, unsigned char member)
02880 { m_network = network; m_cluster = cluster; m_member = member; }
02881
02887 bool assign(const String& src);
02888
02897 bool assign(Type type, const unsigned char* src, int len = -1, unsigned char* spare = 0);
02898
02903 inline SS7PointCode& operator=(const SS7PointCode& original)
02904 { assign(original.network(),original.cluster(),original.member()); return *this; }
02905
02910 inline bool operator==(const SS7PointCode& original) const
02911 { return m_network == original.network() && m_cluster == original.cluster() && m_member == original.member(); }
02912
02917 bool compatible(Type type) const;
02918
02924 unsigned int pack(Type type) const;
02925
02932 bool unpack(Type type, unsigned int packed);
02933
02941 bool store(Type type, unsigned char* dest, unsigned char spare = 0) const;
02942
02948 static unsigned char size(Type type);
02949
02955 static unsigned char length(Type type);
02956
02962 static Type lookup(const char* text)
02963 { return (Type)TelEngine::lookup(text,s_names,(int)Other); }
02964
02970 static const char* lookup(Type type)
02971 { return TelEngine::lookup((int)type,s_names); }
02972
02973 private:
02974 static TokenDict s_names[];
02975 unsigned char m_network;
02976 unsigned char m_cluster;
02977 unsigned char m_member;
02978 };
02979
02980
02981 #define YSS7_PCTYPE_COUNT (SS7PointCode::DefinedTypes-1)
02982
02988 String& operator<<(String& str, const SS7PointCode& cp);
02989
02994 class YSIG_API SS7Label
02995 {
02996 public:
03000 SS7Label();
03001
03006 SS7Label(const SS7Label& original);
03007
03014 SS7Label(const SS7Label& original, unsigned char sls, unsigned char spare = 0);
03015
03024 SS7Label(SS7PointCode::Type type, const SS7PointCode& dpc,
03025 const SS7PointCode& opc, unsigned char sls, unsigned char spare = 0);
03026
03035 SS7Label(SS7PointCode::Type type, unsigned int dpc,
03036 unsigned int opc, unsigned char sls, unsigned char spare = 0);
03037
03043 SS7Label(SS7PointCode::Type type, const SS7MSU& msu);
03044
03053 void assign(SS7PointCode::Type type, const SS7PointCode& dpc,
03054 const SS7PointCode& opc, unsigned char sls, unsigned char spare = 0);
03055
03064 void assign(SS7PointCode::Type type, unsigned int dpc,
03065 unsigned int opc, unsigned char sls, unsigned char spare = 0);
03066
03073 bool assign(SS7PointCode::Type type, const SS7MSU& msu);
03074
03082 bool assign(SS7PointCode::Type type, const unsigned char* src, int len = -1);
03083
03089 bool store(unsigned char* dest) const;
03090
03095 bool compatible(SS7PointCode::Type type) const;
03096
03101 inline SS7PointCode::Type type() const
03102 { return m_type; }
03103
03108 inline const SS7PointCode& dpc() const
03109 { return m_dpc; }
03110
03115 inline SS7PointCode& dpc()
03116 { return m_dpc; }
03117
03122 inline const SS7PointCode& opc() const
03123 { return m_opc; }
03124
03129 inline SS7PointCode& opc()
03130 { return m_opc; }
03131
03136 inline unsigned char sls() const
03137 { return m_sls; }
03138
03143 inline void setSls(unsigned char sls)
03144 { m_sls = sls; }
03145
03150 inline unsigned char spare() const
03151 { return m_spare; }
03152
03157 inline void setSpare(unsigned char spare)
03158 { m_spare = spare; }
03159
03164 inline unsigned int length() const
03165 { return length(m_type); }
03166
03172 static unsigned int length(SS7PointCode::Type type);
03173
03178 inline unsigned char size() const
03179 { return size(m_type); }
03180
03186 static unsigned char size(SS7PointCode::Type type);
03187
03188 private:
03189 SS7PointCode::Type m_type;
03190 SS7PointCode m_dpc;
03191 SS7PointCode m_opc;
03192 unsigned char m_sls;
03193 unsigned char m_spare;
03194 };
03195
03201 String& operator<<(String& str, const SS7Label& label);
03202
03207 class YSIG_API SS7MSU : public DataBlock
03208 {
03209 public:
03213 enum Services {
03214
03215 SNM = 0,
03216
03217 MTN = 1,
03218
03219 MTNS = 2,
03220
03221 SCCP = 3,
03222
03223 TUP = 4,
03224
03225 ISUP = 5,
03226
03227 DUP_C = 6,
03228
03229 DUP_F = 7,
03230
03231 MTP_T = 8,
03232
03233 BISUP = 9,
03234
03235 SISUP = 10,
03236
03237 AAL2 = 12,
03238
03239 BICC = 13,
03240
03241 GCP = 14,
03242 };
03243
03247 enum Priority {
03248 Regular = 0x00,
03249 Special = 0x10,
03250 Circuit = 0x20,
03251 Facility = 0x30
03252 };
03253
03257 enum NetIndicator {
03258 International = 0x00,
03259 SpareInternational = 0x40,
03260 National = 0x80,
03261 ReservedNational = 0xc0
03262 };
03263
03267 inline SS7MSU()
03268 { }
03269
03274 inline SS7MSU(const SS7MSU& value)
03275 : DataBlock(value)
03276 { }
03277
03282 inline SS7MSU(const DataBlock& value)
03283 : DataBlock(value)
03284 { }
03285
03292 inline SS7MSU(void* value, unsigned int len, bool copyData = true)
03293 : DataBlock(value,len,copyData)
03294 { }
03295
03303 SS7MSU(unsigned char sio, const SS7Label label, void* value = 0, unsigned int len = 0);
03304
03313 SS7MSU(unsigned char sif, unsigned char ssf, const SS7Label label, void* value = 0, unsigned int len = 0);
03314
03318 virtual ~SS7MSU();
03319
03325 inline SS7MSU& operator=(const SS7MSU& value)
03326 { DataBlock::operator=(value); return *this; }
03327
03333 inline SS7MSU& operator=(const DataBlock& value)
03334 { DataBlock::operator=(value); return *this; }
03335
03340 bool valid() const;
03341
03348 inline unsigned char* getData(unsigned int offs, unsigned int len = 1)
03349 { return (offs+len <= length()) ? offs + (unsigned char*)data() : 0; }
03350
03357 inline const unsigned char* getData(unsigned int offs, unsigned int len = 1) const
03358 { return (offs+len <= length()) ? offs + (const unsigned char*)data() : 0; }
03359
03366 inline unsigned char* getData(const SS7Label& label, unsigned int len = 1)
03367 { return getData(label.length()+1,len); }
03368
03375 inline const unsigned char* getData(const SS7Label& label, unsigned int len = 1) const
03376 { return getData(label.length()+1,len); }
03377
03382 inline int getSIO() const
03383 { return null() ? -1 : *(const unsigned char*)data(); }
03384
03389 inline int getSIF() const
03390 { return null() ? -1 : 0x0f & *(const unsigned char*)data(); }
03391
03396 inline int getSSF() const
03397 { return null() ? -1 : 0xf0 & *(const unsigned char*)data(); }
03398
03403 inline int getPrio() const
03404 { return null() ? -1 : 0x30 & *(const unsigned char*)data(); }
03405
03410 inline int getNI() const
03411 { return null() ? -1 : 0xc0 & *(const unsigned char*)data(); }
03412
03417 const char* getServiceName() const;
03418
03423 const char* getPriorityName() const;
03424
03429 const char* getIndicatorName() const;
03430
03437 static unsigned char getPriority(const char* name, unsigned char defVal = Regular);
03438
03445 static unsigned char getNetIndicator(const char* name, unsigned char defVal = National);
03446 };
03447
03452 class YSIG_API SIGTRAN
03453 {
03454 public:
03458 enum Transport {
03459 None = 0,
03460 Sctp,
03461 Tcp,
03462 Unix,
03463 };
03464
03468 SIGTRAN();
03469
03473 virtual ~SIGTRAN();
03474
03478 virtual void terminate();
03479
03480 protected:
03487 virtual bool attach(Socket* socket, Transport trans);
03488
03497 virtual bool processMSG(unsigned char msgVersion, unsigned char msgClass,
03498 unsigned char msgType, const DataBlock& msg) = 0;
03499
03500 private:
03501 Transport m_trans;
03502 Socket* m_socket;
03503 DataBlock m_part;
03504 };
03505
03510 class YSIG_API ASPUser
03511 {
03512 };
03513
03518 class YSIG_API SCCP
03519 {
03520 public:
03524 virtual ~SCCP();
03525
03530 virtual void attach(SCCPUser* user);
03531
03532 protected:
03533 ObjList m_users;
03534 };
03535
03540 class YSIG_API SCCPUser
03541 {
03542 public:
03546 virtual ~SCCPUser();
03547
03552 virtual void attach(SCCP* sccp);
03553
03558 inline SCCP* sccp() const
03559 { return m_sccp; }
03560
03561 private:
03562 SCCP* m_sccp;
03563 };
03564
03569 class YSIG_API TCAPUser
03570 {
03571 public:
03575 virtual ~TCAPUser();
03576
03581 virtual void attach(SS7TCAP* tcap);
03582
03587 inline SS7TCAP* tcap() const
03588 { return m_tcap; }
03589
03590 private:
03591 SS7TCAP* m_tcap;
03592 };
03593
03598 class YSIG_API SS7L2User : virtual public SignallingComponent
03599 {
03600 friend class SS7Layer2;
03601 public:
03606 virtual void attach(SS7Layer2* link) = 0;
03607
03612 virtual void detach(SS7Layer2* link) = 0;
03613
03614 protected:
03622 virtual bool receivedMSU(const SS7MSU& msu, SS7Layer2* link, int sls) = 0;
03623
03629 virtual void notify(SS7Layer2* link) = 0;
03630 };
03631
03636 class YSIG_API SS7Layer2 : virtual public SignallingComponent
03637 {
03638 public:
03642 enum LinkStatus {
03643 OutOfAlignment = 0,
03644 NormalAlignment = 1,
03645 EmergencyAlignment = 2,
03646 OutOfService = 3,
03647 ProcessorOutage = 4,
03648 Busy = 5,
03649
03650 O = OutOfAlignment,
03651 N = NormalAlignment,
03652 E = EmergencyAlignment,
03653 OS = OutOfService,
03654 PO = ProcessorOutage,
03655 B = Busy,
03656 };
03657
03661 enum Operation {
03662
03663 Pause = 0x100,
03664
03665 Resume = 0x200,
03666
03667 Align = 0x300,
03668
03669 Status = 0x400,
03670 };
03671
03677 virtual bool transmitMSU(const SS7MSU& msu) = 0;
03678
03683 virtual ObjList* recoverMSU() = 0;
03684
03689 virtual unsigned int status() const;
03690
03697 virtual const char* statusName(unsigned int status, bool brief) const;
03698
03704 inline const char* statusName(bool brief = false) const
03705 { return statusName(status(),brief); }
03706
03711 virtual bool operational() const = 0;
03712
03717 void attach(SS7L2User* l2user);
03718
03723 inline SS7L2User* user() const
03724 { return m_l2user; }
03725
03730 inline int sls() const
03731 { return m_sls; }
03732
03737 inline void sls(int linkSel)
03738 { if ((m_sls < 0) || !m_l2user) m_sls = linkSel; }
03739
03748 virtual bool control(Operation oper, NamedList* params = 0);
03749
03750 protected:
03754 inline SS7Layer2()
03755 : m_l2userMutex(true), m_l2user(0), m_sls(-1)
03756 { setName("ss7l2"); }
03757
03763 inline bool receivedMSU(const SS7MSU& msu) {
03764 m_l2userMutex.lock();
03765 SS7L2User* tmp = m_l2user;
03766 m_l2userMutex.unlock();
03767 return tmp && tmp->receivedMSU(msu,this,m_sls);
03768 }
03769
03773 inline void notify() {
03774 m_l2userMutex.lock();
03775 SS7L2User* tmp = m_l2user;
03776 m_l2userMutex.unlock();
03777 if (tmp)
03778 tmp->notify(this);
03779 }
03780
03781 private:
03782 Mutex m_l2userMutex;
03783 SS7L2User* m_l2user;
03784 int m_sls;
03785 };
03786
03791 class YSIG_API SS7L3User : virtual public SignallingComponent
03792 {
03793 friend class SS7Layer3;
03794 friend class SS7Router;
03795 public:
03800 virtual void attach(SS7Layer3* network) = 0;
03801
03802 protected:
03811 virtual bool receivedMSU(const SS7MSU& msu, const SS7Label& label, SS7Layer3* network, int sls) = 0;
03812
03818 virtual void notify(SS7Layer3* link, int sls);
03819 };
03820
03825 class YSIG_API SS7Layer3 : virtual public SignallingComponent
03826 {
03827 friend class SS7Router;
03828 public:
03832 virtual ~SS7Layer3()
03833 { attach(0); }
03834
03842 virtual int transmitMSU(const SS7MSU& msu, const SS7Label& label, int sls = -1) = 0;
03843
03849 virtual bool operational(int sls = -1) const = 0;
03850
03856 void attach(SS7L3User* l3user);
03857
03862 inline SS7L3User* user() const
03863 { return m_l3user; }
03864
03870 SS7PointCode::Type type(unsigned char netType) const;
03871
03877 void setType(SS7PointCode::Type type, unsigned char netType);
03878
03883 void setType(SS7PointCode::Type type);
03884
03891 bool buildRoutes(const NamedList& params);
03892
03900 unsigned int getRoutePriority(SS7PointCode::Type type, unsigned int packedPC);
03901
03905 void printRoutes();
03906
03907 protected:
03912 inline SS7Layer3(SS7PointCode::Type type = SS7PointCode::Other)
03913 : m_l3userMutex(true), m_l3user(0), m_routeMutex(true)
03914 { setName("ss7l3"); setType(type); }
03915
03923 inline bool receivedMSU(const SS7MSU& msu, const SS7Label& label, int sls) {
03924 Lock lock(m_l3userMutex);
03925 return m_l3user && m_l3user->receivedMSU(msu,label,this,sls);
03926 }
03927
03932 inline void notify(int sls = -1) {
03933 Lock lock(m_l3userMutex);
03934 if (m_l3user)
03935 m_l3user->notify(this,sls);
03936 }
03937
03945 virtual bool maintenance(const SS7MSU& msu, const SS7Label& label, int sls);
03946
03954 virtual bool management(const SS7MSU& msu, const SS7Label& label, int sls);
03955
03964 virtual bool unavailable(const SS7MSU& msu, const SS7Label& label, int sls, unsigned char cause = 0);
03965
03973 SS7Route* findRoute(SS7PointCode::Type type, unsigned int packed);
03974
03980 void updateRoutes(SS7Layer3* network);
03981
03988 void removeRoutes(SS7Layer3* network);
03989
03990 private:
03991 Mutex m_l3userMutex;
03992 SS7L3User* m_l3user;
03993 SS7PointCode::Type m_cpType[4];
03994 Mutex m_routeMutex;
03995 ObjList m_route[YSS7_PCTYPE_COUNT];
03996
03997 };
03998
04003 class YSIG_API SS7Layer4 : public SS7L3User
04004 {
04005 public:
04010 virtual void attach(SS7Layer3* network);
04011
04016 inline SS7Layer3* network() const
04017 { return m_layer3; }
04018
04019 protected:
04023 SS7Layer4();
04024
04032 inline int transmitMSU(const SS7MSU& msu, const SS7Label& label, int sls = -1) {
04033 Lock lock(m_l3Mutex);
04034 return m_layer3 ? m_layer3->transmitMSU(msu,label,sls) : -1;
04035 }
04036
04037 private:
04038 Mutex m_l3Mutex;
04039 SS7Layer3* m_layer3;
04040 };
04041
04047 class YSIG_API SS7Route : public GenObject
04048 {
04049 friend class SS7Layer3;
04050 public:
04056 inline SS7Route(unsigned int packed, unsigned int priority = 0)
04057 : m_packed(packed), m_priority(priority), m_listMutex(true)
04058 { m_networks.setDelete(false); }
04059
04063 virtual ~SS7Route()
04064 {}
04065
04072 void attach(SS7Layer3* network, SS7PointCode::Type type);
04073
04080 bool detach(SS7Layer3* network);
04081
04091 int transmitMSU(const SS7Router* router, const SS7MSU& msu, const SS7Label& label, int sls);
04092
04093 private:
04094 unsigned int m_packed;
04095 unsigned int m_priority;
04096 Mutex m_listMutex;
04097 ObjList m_networks;
04098 };
04099
04105 class YSIG_API SS7Router : public SS7L3User, public SS7Layer3, public Mutex
04106 {
04107 public:
04112 SS7Router(const NamedList& params);
04113
04121 virtual int transmitMSU(const SS7MSU& msu, const SS7Label& label, int sls = -1);
04122
04128 virtual bool operational(int sls = -1) const;
04129
04134 virtual void attach(SS7Layer3* network);
04135
04140 virtual void detach(SS7Layer3* network);
04141
04146 void attach(SS7Layer4* service);
04147
04152 void detach(SS7Layer4* service);
04153
04159 virtual void* getObject(const String& name) const;
04160
04161 protected:
04170 virtual bool receivedMSU(const SS7MSU& msu, const SS7Label& label, SS7Layer3* network, int sls);
04171
04178 virtual void notify(SS7Layer3* network, int sls);
04179
04180 ObjList m_layer3;
04181 ObjList m_layer4;
04182 };
04183
04190 class YSIG_API SS7M2PA : public SS7Layer2, public SIGTRAN
04191 {
04192 };
04193
04200 class YSIG_API SS7M2UA : public SS7Layer2, public SIGTRAN
04201 {
04202 };
04203
04210 class YSIG_API SS7M3UA : public SS7Layer3, public SIGTRAN
04211 {
04212 };
04213
04218 class YSIG_API SS7MTP2 : public SS7Layer2, public SignallingReceiver, public Mutex
04219 {
04220 public:
04224 enum ErrorCorrection {
04225 Basic,
04226 Preventive,
04227 Adaptive,
04228 };
04229
04235 SS7MTP2(const NamedList& params, unsigned int status = OutOfService);
04236
04240 virtual ~SS7MTP2();
04241
04247 virtual bool transmitMSU(const SS7MSU& msu);
04248
04253 virtual ObjList* recoverMSU();
04254
04259 virtual unsigned int status() const;
04260
04266 virtual bool aligned() const;
04267
04272 virtual bool operational() const;
04273
04282 virtual bool control(Operation oper, NamedList* params = 0);
04283
04289 virtual bool notify(SignallingInterface::Notification event);
04290
04294 virtual void destruct() {
04295 SS7Layer2::attach(0);
04296 SignallingReceiver::attach(0);
04297 GenObject::destruct();
04298 }
04299
04300 protected:
04305 virtual void timerTick(const Time& when);
04306
04311 virtual bool receivedPacket(const DataBlock& packet);
04312
04316 virtual void processFISU();
04317
04322 virtual void processLSSU(unsigned int status);
04323
04329 bool transmitLSSU(unsigned int status);
04330
04335 inline bool transmitLSSU()
04336 { return transmitLSSU(m_status); }
04337
04342 bool transmitFISU();
04343
04348 void startAlignment(bool emergency = false);
04349
04353 void abortAlignment();
04354
04359 bool startProving();
04360
04365 void setDumper(SignallingDumper* dumper = 0);
04366
04367 private:
04368 bool txPacket(const DataBlock& packet, bool repeat, SignallingInterface::PacketType type = SignallingInterface::Unknown);
04369 void setLocalStatus(unsigned int status);
04370 void setRemoteStatus(unsigned int status);
04371
04372 ObjList m_queue;
04373
04374 unsigned int m_status, m_lStatus, m_rStatus;
04375
04376 u_int64_t m_interval;
04377
04378 u_int64_t m_resend;
04379
04380 u_int64_t m_abort;
04381
04382 bool m_congestion;
04383
04384 unsigned char m_bsn, m_fsn;
04385
04386 bool m_bib, m_fib;
04387
04388 unsigned char m_lastBsn;
04389
04390 bool m_lastBib;
04391
04392 int m_errors;
04393
04394 unsigned int m_resendMs;
04395
04396 unsigned int m_abortMs;
04397
04398 SignallingDumper* m_dumper;
04399 };
04400
04405 class YSIG_API SS7MTP3 : public SS7Layer3, public SS7L2User, public Mutex
04406 {
04407 public:
04412 SS7MTP3(const NamedList& params);
04413
04417 virtual ~SS7MTP3();
04418
04426 virtual int transmitMSU(const SS7MSU& msu, const SS7Label& label, int sls = -1);
04427
04433 virtual bool operational(int sls = -1) const;
04434
04439 virtual void attach(SS7Layer2* link);
04440
04445 virtual void detach(SS7Layer2* link);
04446
04450 virtual void destruct();
04451
04456 inline unsigned int linksTotal() const
04457 { return m_total; }
04458
04463 inline unsigned int linksActive() const
04464 { return m_active; }
04465
04466 protected:
04474 virtual bool receivedMSU(const SS7MSU& msu, SS7Layer2* link, int sls);
04475
04481 virtual void notify(SS7Layer2* link);
04482
04487 unsigned int countLinks();
04488
04493 void setDumper(SignallingDumper* dumper = 0);
04494
04495 private:
04496 ObjList m_links;
04497
04498 unsigned int m_total;
04499
04500 unsigned int m_active;
04501
04502 SignallingDumper* m_dumper;
04503 };
04504
04509 class YSIG_API SS7MsgSNM : public SignallingMessage
04510 {
04511 public:
04515 enum Type {
04516 Unknown = 0,
04517 COO = 0x11,
04518 ECO = 0x12,
04519 RCT = 0x13,
04520 TFP = 0x14,
04521 RST = 0x15,
04522 RSP = RST,
04523 LIN = 0x16,
04524 TRA = 0x17,
04525 DLC = 0x18,
04526 UPU = 0x1a,
04527 COA = 0x21,
04528 ECA = 0x22,
04529 TFC = 0x23,
04530 TCP = 0x24,
04531 TFPA = TCP,
04532 RSR = 0x25,
04533 LUN = 0x26,
04534 TRW = 0x27,
04535 CSS = 0x28,
04536 TFR = 0x34,
04537 RCP = 0x35,
04538 LIA = 0x36,
04539 CNS = 0x38,
04540 TCR = 0x44,
04541 RCR = 0x45,
04542 LUA = 0x46,
04543 CNP = 0x48,
04544 CBD = 0x51,
04545 TFA = 0x54,
04546 LID = 0x56,
04547 CBA = 0x61,
04548 TCA = 0x64,
04549 TFAA = TCA,
04550 LFU = 0x66,
04551 LLT = 0x76,
04552 LLI = LLT,
04553 LRT = 0x86,
04554 LRI = LRT,
04555 };
04556
04560 enum Group {
04561 CHM = 0x01,
04562 ECM = 0x02,
04563 FCM = 0x03,
04564 TFM = 0x04,
04565 RSM = 0x05,
04566 MIM = 0x06,
04567 TRM = 0x07,
04568 DLM = 0x08,
04569 UFC = 0x0a,
04570 };
04571
04576 SS7MsgSNM(unsigned char type);
04577
04582 inline unsigned char type() const
04583 { return m_type; }
04584
04589 inline unsigned char group() const
04590 { return m_type & 0x0f; }
04591
04598 void toString(String& dest, const SS7Label& label, bool params) const;
04599
04609 static SS7MsgSNM* parse(SS7Management* receiver, unsigned char type,
04610 SS7PointCode::Type pcType,
04611 const unsigned char* buf, unsigned int len);
04612
04616 static const TokenDict* names();
04617
04624 static inline const char* lookup(Type type, const char* defvalue = 0)
04625 { return TelEngine::lookup(type,names(),defvalue); }
04626
04633 static inline Type lookup(const char* name, Type defvalue = Unknown)
04634 { return static_cast<Type>(TelEngine::lookup(name,names(),defvalue)); }
04635
04636 private:
04637 unsigned char m_type;
04638 };
04639
04644 class YSIG_API SS7MsgMTN
04645 {
04646 public:
04650 enum Type {
04651 Unknown = 0,
04652 SLTM = 0x11,
04653 SLTA = 0x21,
04654 };
04655
04656 static const TokenDict* names();
04657
04664 static inline const char* lookup(Type type, const char* defvalue = 0)
04665 { return TelEngine::lookup(type,names(),defvalue); }
04666
04673 static inline Type lookup(const char* name, Type defvalue = Unknown)
04674 { return static_cast<Type>(TelEngine::lookup(name,names(),defvalue)); }
04675 };
04676
04681 class YSIG_API SS7MsgISUP : public SignallingMessage
04682 {
04683 friend class SS7ISUPCall;
04684 public:
04688 enum Type {
04689 Unknown = 0,
04690 IAM = 0x01,
04691 SAM = 0x02,
04692 INR = 0x03,
04693 INF = 0x04,
04694 COT = 0x05,
04695 ACM = 0x06,
04696 CON = 0x07,
04697 FOT = 0x08,
04698 ANM = 0x09,
04699 REL = 0x0c,
04700 SUS = 0x0d,
04701 RES = 0x0e,
04702 RLC = 0x10,
04703 CCR = 0x11,
04704 RSC = 0x12,
04705 BLK = 0x13,
04706 UBL = 0x14,
04707 BLA = 0x15,
04708 UBA = 0x16,
04709 GRS = 0x17,
04710 CGB = 0x18,
04711 CGU = 0x19,
04712 CGA = 0x1a,
04713 CGBA = CGA,
04714 CUA = 0x1b,
04715 CMR = 0x1c,
04716 CMC = 0x1d,
04717 CMRJ = 0x1e,
04718 FACR = 0x1f,
04719 FAA = 0x20,
04720 FRJ = 0x21,
04721 FAD = 0x22,
04722 FAI = 0x23,
04723 LPA = 0x24,
04724 CSVR = 0x25,
04725 CSVS = 0x26,
04726 DRS = 0x27,
04727 PAM = 0x28,
04728 GRA = 0x29,
04729 CQM = 0x2a,
04730 CQR = 0x2b,
04731 CPR = 0x2c,
04732 CPG = CPR,
04733 USR = 0x2d,
04734 UEC = 0x2e,
04735 UCIC = UEC,
04736 CNF = 0x2f,
04737 OLM = 0x30,
04738 CRG = 0x31,
04739 NRM = 0x32,
04740 FAC = 0x33,
04741 UPT = 0x34,
04742 UPA = 0x35,
04743 IDR = 0x36,
04744 IRS = 0x37,
04745 SGM = 0x38,
04746 LOP = 0x40,
04747 APM = 0x41,
04748 PRI = 0x42,
04749 SDN = 0x43,
04750 CRA = 0xe9,
04751 CRM = 0xea,
04752 CVR = 0xeb,
04753 CVT = 0xec,
04754 EXM = 0xed,
04755 };
04756
04760 enum Parameters {
04761 EndOfParameters = 0,
04762 CallReference = 0x01,
04763 TransmissionMediumRequirement = 0x02,
04764 AccessTransport = 0x03,
04765 CalledPartyNumber = 0x04,
04766 SubsequentNumber = 0x05,
04767 NatureOfConnectionIndicators = 0x06,
04768 ForwardCallIndicators = 0x07,
04769 OptionalForwardCallIndicators = 0x08,
04770 CallingPartyCategory = 0x09,
04771 CallingPartyNumber = 0x0a,
04772 RedirectingNumber = 0x0b,
04773 RedirectionNumber = 0x0c,
04774 ConnectionRequest = 0x0d,
04775 InformationRequestIndicators = 0x0e,
04776 InformationIndicators = 0x0f,
04777 ContinuityIndicators = 0x10,
04778 BackwardCallIndicators = 0x11,
04779 CauseIndicators = 0x12,
04780 RedirectionInformation = 0x13,
04781 GroupSupervisionTypeIndicator = 0x15,
04782 RangeAndStatus = 0x16,
04783 CallModificationIndicators = 0x17,
04784 FacilityIndicator = 0x18,
04785 FacilityInformationIndicators = 0x19,
04786 CUG_InterlockCode = 0x1a,
04787 Index = 0x1b,
04788 CUG_CheckResponseIndicators = 0x1c,
04789 UserServiceInformation = 0x1d,
04790 SignallingPointCode = 0x1e,
04791 UserToUserInformation = 0x20,
04792 ConnectedNumber = 0x21,
04793 SuspendResumeIndicators = 0x22,
04794 TransitNetworkSelection = 0x23,
04795 EventInformation = 0x24,
04796 CircuitAssignmentMap = 0x25,
04797 CircuitStateIndicator = 0x26,
04798 AutomaticCongestionLevel = 0x27,
04799 OriginalCalledNumber = 0x28,
04800 OptionalBackwardCallIndicators = 0x29,
04801 UserToUserIndicators = 0x2a,
04802 OriginationISCPointCode = 0x2b,
04803 GenericNotification = 0x2c,
04804 CallHistoryInformation = 0x2d,
04805 AccessDeliveryInformation = 0x2e,
04806 NetworkSpecificFacilities = 0x2f,
04807 UserServiceInformationPrime = 0x30,
04808 PropagationDelayCounter = 0x31,
04809 RemoteOperations = 0x32,
04810 ServiceActivation = 0x33,
04811 UserTeleserviceInformation = 0x34,
04812 TransmissionMediumUsed = 0x35,
04813 CallDiversionInformation = 0x36,
04814 EchoControlInformation = 0x37,
04815 MessageCompatInformation = 0x38,
04816 ParameterCompatInformation = 0x39,
04817 MLPP_Precedence = 0x3a,
04818 Precedence = MLPP_Precedence,
04819 MCID_RequestIndicator = 0x3b,
04820 MCID_ResponseIndicator = 0x3c,
04821 HopCounter = 0x3d,
04822 TransMediumRequirementPrime = 0x3e,
04823 LocationNumber = 0x3f,
04824 RedirectionNumberRestriction = 0x40,
04825 FreephoneIndicators = 0x41,
04826 GenericReference = 0x42,
04827 ApplicationTransport = 0x78,
04828 GenericNumber = 0xc0,
04829 GenericAddress = GenericNumber,
04830 GenericDigits = 0xc1,
04831 OperatorServicesInformation = 0xc2,
04832 Egress = 0xc3,
04833 Jurisdiction = 0xc4,
04834 CarrierIdentification = 0xc5,
04835 BusinessGroup = 0xc6,
04836 GenericName = 0xc7,
04837 NotificationIndicator = 0xe1,
04838 TransactionRequest = 0xe3,
04839 CircuitGroupCharactIndicator = 0xe5,
04840 CircuitValidationRespIndicator = 0xe6,
04841 OutgoingTrunkGroupNumber = 0xe7,
04842 CircuitIdentificationName = 0xe8,
04843 CommonLanguage = 0xe9,
04844 OriginatingLineInformation = 0xea,
04845 ChargeNumber = 0xeb,
04846 ServiceCodeIndicator = 0xec,
04847 SpecialProcessingRequest = 0xed,
04848 CarrierSelectionInformation = 0xee,
04849 NetworkTransport = 0xef,
04850 };
04851
04857 inline SS7MsgISUP(Type type, unsigned int cic)
04858 : SignallingMessage(lookup(type,"Unknown")), m_type(type), m_cic(cic)
04859 {}
04860
04864 virtual ~SS7MsgISUP()
04865 {}
04866
04871 inline Type type() const
04872 { return m_type; }
04873
04878 inline unsigned int cic() const
04879 { return m_cic; }
04880
04887 void toString(String& dest, const SS7Label& label, bool params) const;
04888
04894 virtual void* getObject(const String& name) const;
04895
04900 static const TokenDict* names();
04901
04908 static inline const char* lookup(Type type, const char* defvalue = 0)
04909 { return TelEngine::lookup(type,names(),defvalue); }
04910
04917 static inline Type lookup(const char* name, Type defvalue = Unknown)
04918 { return static_cast<Type>(TelEngine::lookup(name,names(),defvalue)); }
04919
04920 private:
04921 Type m_type;
04922 unsigned int m_cic;
04923 };
04924
04929 class YSIG_API SS7Management : public SS7Layer4
04930 {
04931 public:
04935 inline SS7Management()
04936 { setName("ss7snm"); }
04937
04938 protected:
04947 virtual bool receivedMSU(const SS7MSU& msu, const SS7Label& label, SS7Layer3* network, int sls);
04948
04955 virtual void notify(SS7Layer3* link, int sls);
04956 };
04957
04962 class YSIG_API SS7Maintenance : public SS7Layer4
04963 {
04964 public:
04968 inline SS7Maintenance()
04969 { setName("ss7mtn"); }
04970
04971 protected:
04980 virtual bool receivedMSU(const SS7MSU& msu, const SS7Label& label, SS7Layer3* network, int sls);
04981
04988 virtual void notify(SS7Layer3* link, int sls);
04989 };
04990
04995 class YSIG_API SS7ISUPCall : public SignallingCall
04996 {
04997 friend class SS7ISUP;
04998 public:
05002 enum State {
05003
05004 Null = 0,
05005 Setup = 1,
05006 Accepted = 2,
05007 Ringing = 3,
05008 Answered = 4,
05009 Releasing = 5,
05010 Released = 6
05011 };
05012
05017 virtual ~SS7ISUPCall();
05018
05023 inline State state() const
05024 { return m_state; }
05025
05030 inline const String& cicRange() const
05031 { return m_cicRange; }
05032
05037 inline unsigned int id() const
05038 { return m_circuit ? m_circuit->code() : 0; }
05039
05046 virtual SignallingEvent* getEvent(const Time& when);
05047
05053 virtual bool sendEvent(SignallingEvent* event);
05054
05060 inline void setTerminate(bool gracefully, const char* reason = 0) {
05061 Lock lock(m_callMutex);
05062 m_terminate = true;
05063 m_gracefully = gracefully;
05064 setReason(reason,0);
05065 }
05066
05072 virtual void* getObject(const String& name) const;
05073
05074 protected:
05085 SS7ISUPCall(SS7ISUP* controller, SignallingCircuit* cic,
05086 const SS7PointCode& local, const SS7PointCode& remote, bool outgoing,
05087 int sls = -1, const char* range = 0);
05088
05098 SignallingEvent* releaseComplete(bool final, SS7MsgISUP* msg = 0, const char* reason = 0);
05099
05109 bool replaceCircuit(SignallingCircuit* circuit);
05110
05116 void stopWaitSegment(bool discard);
05117
05118 private:
05119
05120
05121
05122
05123 bool copyParamIAM(SS7MsgISUP* msg, bool outgoing = false, SignallingMessage* sigMsg = 0);
05124
05125
05126
05127 bool release(SignallingEvent* event = 0);
05128
05129 void setReason(const char* reason, SignallingMessage* msg);
05130
05131 bool validMsgState(bool send, SS7MsgISUP::Type type);
05132
05133 bool connectCircuit();
05134
05135 bool transmitIAM();
05136
05137
05138
05139
05140
05141 SignallingEvent* processSegmented(SS7MsgISUP* sgm = 0, bool timeout = false);
05142
05143 inline bool transmitMessage(SS7MsgISUP* msg);
05144
05145 inline SS7ISUP* isup();
05146
05147 State m_state;
05148 SignallingCircuit* m_circuit;
05149 String m_cicRange;
05150 SS7Label m_label;
05151 bool m_terminate;
05152 bool m_gracefully;
05153 bool m_circuitChanged;
05154 String m_format;
05155 String m_reason;
05156 SS7MsgISUP* m_iamMsg;
05157 SS7MsgISUP* m_sgmMsg;
05158
05159 SignallingTimer m_relTimer;
05160 SignallingTimer m_iamTimer;
05161 SignallingTimer m_sgmRecvTimer;
05162 };
05163
05168 class YSIG_API SS7ISUP : public SignallingCallControl, public SS7Layer4
05169 {
05170 friend class SS7ISUPCall;
05171 public:
05176 SS7ISUP(const NamedList& params);
05177
05181 virtual ~SS7ISUP();
05182
05187 unsigned int cicLen() const
05188 { return m_cicLen; }
05189
05194 const String& format() const
05195 { return m_format; }
05196
05205 bool setPointCode(SS7PointCode* pc, bool def);
05206
05212 SS7PointCode* hasPointCode(const SS7PointCode& pc);
05213
05221 inline void setLabel(SS7Label& label, const SS7PointCode& opc, const SS7PointCode& dpc,
05222 unsigned char sls = 255)
05223 { label.assign(m_type,dpc,opc,sls); }
05224
05234 virtual SS7MSU* createMSU(SS7MsgISUP::Type type, unsigned char ssf,
05235 const SS7Label& label, unsigned int cic, const NamedList* params = 0) const;
05236
05244 virtual SignallingCall* call(SignallingMessage* msg, String& reason);
05245
05256 int transmitMessage(SS7MsgISUP* msg, const SS7Label& label, bool recvLbl, int sls = -1);
05257
05263 virtual void cleanup(const char* reason = "offline");
05264
05270 virtual void* getObject(const String& name) const;
05271
05275 virtual void destruct();
05276
05286 bool decodeMessage(NamedList& msg, SS7MsgISUP::Type msgType, SS7PointCode::Type pcType,
05287 const unsigned char* paramPtr, unsigned int paramLen);
05288
05299 bool encodeMessage(DataBlock& buf, SS7MsgISUP::Type msgType, SS7PointCode::Type pcType,
05300 const NamedList& params, unsigned int* cic = 0);
05301
05302 protected:
05307 virtual void timerTick(const Time& when);
05308
05314 virtual void notify(SS7Layer3* link, int sls);
05315
05325 SS7MSU* buildMSU(SS7MsgISUP::Type type, unsigned char sio,
05326 const SS7Label& label, unsigned int cic, const NamedList* params) const;
05327
05336 virtual bool receivedMSU(const SS7MSU& msu, const SS7Label& label, SS7Layer3* network, int sls);
05337
05349 virtual bool processMSU(SS7MsgISUP::Type type, unsigned int cic,
05350 const unsigned char* paramPtr, unsigned int paramLen,
05351 const SS7Label& label, SS7Layer3* network, int sls);
05352
05359 virtual SignallingEvent* processCircuitEvent(SignallingCircuitEvent& event,
05360 SignallingCall* call = 0);
05361
05365 unsigned int m_cicLen;
05366
05367 private:
05368
05369
05370
05371
05372 void processCallMsg(SS7MsgISUP* msg, const SS7Label& label, int sls);
05373
05374
05375
05376
05377 void processControllerMsg(SS7MsgISUP* msg, const SS7Label& label, int sls);
05378
05379
05380
05381 bool resetCircuit(unsigned int cic, bool remote, bool checkCall);
05382
05383
05384 bool blockCircuit(unsigned int cic, bool block, bool remote, bool hwFail,
05385 bool changed, bool changedState);
05386
05387 SS7ISUPCall* findCall(unsigned int cic);
05388
05389
05390 bool sendLocalLock(u_int64_t when = Time::msecNow());
05391
05392 SS7PointCode::Type m_type;
05393 ObjList m_pointCodes;
05394 SS7PointCode* m_defPoint;
05395 SS7PointCode* m_remotePoint;
05396 unsigned char m_priossf;
05397 unsigned char m_sls;
05398 bool m_inn;
05399 String m_numPlan;
05400 String m_numType;
05401 String m_numPresentation;
05402 String m_numScreening;
05403 String m_callerCat;
05404 String m_format;
05405 bool m_l3LinkUp;
05406
05407 SignallingTimer m_uptTimer;
05408 bool m_userPartAvail;
05409 unsigned int m_uptCicCode;
05410
05411 SignallingTimer m_rscTimer;
05412 SignallingCircuit* m_rscCic;
05413
05414 SignallingTimer m_lockTimer;
05415 bool m_lockNeed;
05416 bool m_hwFailReq;
05417 bool m_blockReq;
05418 unsigned int m_lockCicCode;
05419 String m_lockMap;
05420 };
05421
05426 class YSIG_API SS7BICC : public SS7ISUP
05427 {
05428 public:
05433 SS7BICC(const NamedList& params);
05434
05439 virtual ~SS7BICC();
05440
05450 virtual SS7MSU* createMSU(SS7MsgISUP::Type type, unsigned char ssf,
05451 const SS7Label& label, unsigned int cic, const NamedList* params = 0) const;
05452
05458 virtual void* getObject(const String& name) const;
05459
05460 protected:
05469 virtual bool receivedMSU(const SS7MSU& msu, const SS7Label& label, SS7Layer3* network, int sls);
05470 };
05471
05476 class YSIG_API SS7TUP : public SignallingCallControl, public SS7Layer4
05477 {
05478 public:
05479 SS7TUP(const NamedList& params);
05480 virtual ~SS7TUP();
05481 };
05482
05487 class YSIG_API SS7SCCP : public SS7Layer4, public SCCP
05488 {
05489 };
05490
05497 class YSIG_API SS7SUA : public SIGTRAN, public SCCP
05498 {
05499 };
05500
05505 class YSIG_API SS7ASP : public SCCPUser, virtual public SignallingComponent
05506 {
05507 protected:
05508 ObjList m_sccps;
05509 };
05510
05515 class YSIG_API SS7TCAP : public ASPUser, virtual public SignallingComponent
05516 {
05521 void attach(TCAPUser* user);
05522
05523 protected:
05524 ObjList m_users;
05525 };
05526
05527
05528
05529
05534 class YSIG_API ISDNLayer2 : virtual public SignallingComponent
05535 {
05536 public:
05540 enum State {
05541 Released,
05542 WaitEstablish,
05543 Established,
05544 WaitRelease,
05545 };
05546
05550 virtual ~ISDNLayer2();
05551
05556 inline State state() const
05557 { return m_state; }
05558
05563 inline bool network() const
05564 { return m_network; }
05565
05570 inline bool detectType() const
05571 { return m_detectType; }
05572
05577 inline u_int8_t sapi() const
05578 { return m_sapi; }
05579
05584 inline u_int8_t tei() const
05585 { return m_tei; }
05586
05591 inline u_int32_t maxUserData() const
05592 { return m_maxUserData; }
05593
05598 inline bool teiAssigned() const
05599 { return m_teiAssigned; }
05600
05605 inline bool allowUnack() const
05606 { return m_allowUnack; }
05607
05612 inline bool autoRestart() const
05613 { return m_autoRestart; }
05614
05623 virtual bool multipleFrame(bool establish, bool force)
05624 { return false; }
05625
05633 virtual bool sendData(const DataBlock& data, bool ack)
05634 { return false; }
05635
05640 virtual void cleanup() = 0;
05641
05648 virtual void attach(ISDNLayer3* layer3);
05649
05655 static inline const char* stateName(State s)
05656 { return lookup((int)s,m_states); }
05657
05658 protected:
05665 ISDNLayer2(const NamedList& params, const char* name = 0);
05666
05674 void multipleFrameEstablished(bool confirm, bool timeout);
05675
05683 void multipleFrameReleased(bool confirm, bool timeout);
05684
05694 void dataLinkState(bool cmd, bool value);
05695
05700 void idleTimeout();
05701
05708 void receiveData(const DataBlock& data, bool ack);
05709
05715 void teiAssigned(bool status);
05716
05722 void changeState(State newState);
05723
05728 bool changeType();
05729
05730 private:
05731 ISDNLayer3* m_layer3;
05732 Mutex m_interfaceMutex;
05733 Mutex m_layer3Mutex;
05734 State m_state;
05735 bool m_network;
05736 bool m_detectType;
05737 u_int8_t m_sapi;
05738 u_int8_t m_tei;
05739 bool m_teiAssigned;
05740 bool m_allowUnack;
05741 bool m_autoRestart;
05742 u_int32_t m_maxUserData;
05743 static TokenDict m_states[];
05744 };
05745
05750 class YSIG_API ISDNLayer3 : virtual public SignallingComponent
05751 {
05752 public:
05761 virtual void multipleFrameEstablished(bool confirm, bool timeout, ISDNLayer2* layer2)
05762 {}
05763
05772 virtual void multipleFrameReleased(bool confirm, bool timeout, ISDNLayer2* layer2)
05773 {}
05774
05785 virtual void dataLinkState(bool cmd, bool value, ISDNLayer2* layer2)
05786 {}
05787
05793 virtual void idleTimeout(ISDNLayer2* layer2)
05794 {}
05795
05804 virtual void receiveData(const DataBlock& data, bool ack, ISDNLayer2* layer2) = 0;
05805
05810 virtual void attach(ISDNLayer2* layer2)
05811 {}
05812
05813 protected:
05819 inline ISDNLayer3(const char* name = 0)
05820 : SignallingComponent(name)
05821 {}
05822 };
05823
05828 class YSIG_API ISDNFrame : public RefObject
05829 {
05830 friend class ISDNQ921;
05831 public:
05835 enum Type {
05836 DISC = 1,
05837 DM = 2,
05838 FRMR = 3,
05839 I = 4,
05840 REJ = 5,
05841 RNR = 6,
05842 RR = 7,
05843 SABME = 8,
05844 UA = 9,
05845 UI = 10,
05846 XID = 11,
05847
05848 Invalid = 100,
05849 ErrUnknownCR = 101,
05850 ErrHdrLength = 102,
05851 ErrDataLength = 103,
05852 ErrRxSeqNo = 104,
05853 ErrTxSeqNo = 105,
05854 ErrInvalidEA = 106,
05855 ErrInvalidAddress = 107,
05856 ErrUnsupported = 108,
05857 ErrInvalidCR = 109,
05858 };
05859
05863 enum Category {
05864 Data,
05865 Supervisory,
05866 Unnumbered,
05867 Error
05868 };
05869
05873 virtual ~ISDNFrame();
05874
05879 inline Type type() const
05880 { return m_type; }
05881
05886 inline Type error() const
05887 { return m_error; }
05888
05893 inline Category category()
05894 { return m_category; }
05895
05900 inline bool command() const
05901 { return m_command; }
05902
05907 inline u_int8_t sapi() const
05908 { return m_sapi; }
05909
05914 inline u_int8_t tei() const
05915 { return m_tei; }
05916
05921 inline bool poll() const
05922 { return m_poll; }
05923
05928 inline u_int8_t ns() const
05929 { return m_ns; }
05930
05935 inline u_int8_t nr() const
05936 { return m_nr; }
05937
05942 inline u_int8_t headerLength() const
05943 { return m_headerLength; }
05944
05949 inline u_int32_t dataLength() const
05950 { return m_dataLength; }
05951
05956 inline const DataBlock& buffer() const
05957 { return m_buffer; }
05958
05963 inline bool sent() const
05964 { return m_sent; }
05965
05969 inline void sent(bool value)
05970 { m_sent = value; }
05971
05976 inline const char* name() const
05977 { return typeName(type()); }
05978
05984 void update(u_int8_t* ns = 0, u_int8_t* nr = 0);
05985
05990 inline void getData(DataBlock& dest) const
05991 { dest.assign((u_int8_t*)m_buffer.data() + m_headerLength,m_dataLength); }
05992
05998 void toString(String& dest, bool extendedDebug) const;
05999
06006 static ISDNFrame* parse(const DataBlock& data, ISDNLayer2* receiver);
06007
06014 static inline bool commandBit(bool network)
06015 { return network ? true : false; }
06016
06023 static inline bool responseBit(bool network)
06024 { return network ? false : true; }
06025
06032 static inline bool isCommand(u_int8_t cr, bool senderNetwork) {
06033 if (cr)
06034 return senderNetwork ? true : false;
06035 return senderNetwork ? false : true;
06036 }
06037
06043 static inline const char* typeName(Type type)
06044 { return lookup(type,s_types,"Invalid frame"); }
06045
06049 static TokenDict s_types[];
06050
06051 protected:
06057 ISDNFrame(Type type = Invalid);
06058
06072 ISDNFrame(Type type, bool command, bool senderNetwork,
06073 u_int8_t sapi, u_int8_t tei, bool pf, u_int8_t nr = 0);
06074
06087 ISDNFrame(bool ack, bool senderNetwork, u_int8_t sapi, u_int8_t tei,
06088 bool pf, const DataBlock& data);
06089
06090 private:
06091 Type m_type;
06092 Type m_error;
06093 Category m_category;
06094
06095 bool m_command;
06096 bool m_senderNetwork;
06097 u_int8_t m_sapi;
06098 u_int8_t m_tei;
06099
06100 bool m_poll;
06101 u_int8_t m_ns;
06102 u_int8_t m_nr;
06103
06104 u_int8_t m_headerLength;
06105 u_int32_t m_dataLength;
06106 DataBlock m_buffer;
06107
06108 bool m_sent;
06109 };
06110
06115 class YSIG_API ISDNQ921 : public ISDNLayer2, public SignallingReceiver
06116 {
06117 public:
06124 ISDNQ921(const NamedList& params, const char* name = 0);
06125
06129 virtual ~ISDNQ921();
06130
06135 inline u_int64_t dataTimeout() const
06136 { return m_retransTimer.interval() * m_n200.maxVal(); }
06137
06147 virtual bool multipleFrame(bool establish, bool force);
06148
06157 virtual bool sendData(const DataBlock& data, bool ack);
06158
06164 virtual void cleanup();
06165
06171 virtual void* getObject(const String& name) const;
06172
06176 virtual void destruct() {
06177 ISDNLayer2::attach(0);
06178 SignallingReceiver::attach(0);
06179 GenObject::destruct();
06180 }
06181
06187 inline void setDebug(bool printFrames, bool extendedDebug) {
06188 m_printFrames = printFrames;
06189 m_extendedDebug = m_printFrames && extendedDebug;
06190 }
06191
06196 void setDumper(SignallingDumper* dumper = 0);
06197
06198 protected:
06204 virtual void timerTick(const Time& when);
06205
06212 virtual bool receivedPacket(const DataBlock& packet);
06213
06220 virtual bool notify(SignallingInterface::Notification event);
06221
06226 void reset();
06227
06228 private:
06229
06230
06231 bool ackOutgoingFrames(const ISDNFrame* frame);
06232
06233
06234
06235 bool processDataFrame(const ISDNFrame* frame, bool ack);
06236
06237
06238 bool processSFrame(const ISDNFrame* frame);
06239
06240
06241
06242
06243
06244 bool processUFrame(const ISDNFrame* frame, State& newState,
06245 bool& confirmation);
06246
06247
06248
06249
06250 bool acceptFrame(ISDNFrame* frame, bool& reject);
06251
06252 void rejectFrame(const ISDNFrame* frame, const char* reason = 0);
06253
06254 void dropFrame(const ISDNFrame* frame, const char* reason = 0);
06255
06256 bool sendUFrame(ISDNFrame::Type type, bool command, bool pf,
06257 bool retrans = false);
06258
06259 bool sendSFrame(ISDNFrame::Type type, bool command, bool pf);
06260
06261
06262
06263 bool sendFrame(const ISDNFrame* frame);
06264
06265
06266
06267
06268 bool sendOutgoingData(bool retrans = false);
06269
06270
06271
06272
06273
06274 void timer(bool start, bool t203, u_int64_t time = 0);
06275
06276
06277 bool m_remoteBusy;
06278 bool m_timerRecovery;
06279 bool m_rejectSent;
06280 bool m_pendingDMSabme;
06281 bool m_lastPFBit;
06282 u_int8_t m_vs;
06283 u_int8_t m_va;
06284 u_int8_t m_vr;
06285
06286 Mutex m_layer;
06287
06288 SignallingTimer m_retransTimer;
06289 SignallingTimer m_idleTimer;
06290 SignallingCounter m_window;
06291 SignallingCounter m_n200;
06292
06293 ObjList m_outFrames;
06294
06295 u_int32_t m_txFrames;
06296 u_int32_t m_txFailFrames;
06297 u_int32_t m_rxFrames;
06298 u_int32_t m_rxRejectedFrames;
06299 u_int32_t m_rxDroppedFrames;
06300 u_int32_t m_hwErrors;
06301
06302 SignallingDumper* m_dumper;
06303
06304 bool m_printFrames;
06305 bool m_extendedDebug;
06306
06307 bool m_errorSend;
06308 bool m_errorReceive;
06309 };
06310
06315 class YSIG_API ISDNQ921Pasive : public ISDNLayer2, public SignallingReceiver
06316 {
06317 public:
06324 ISDNQ921Pasive(const NamedList& params, const char* name = 0);
06325
06329 virtual ~ISDNQ921Pasive();
06330
06336 virtual void cleanup();
06337
06343 virtual void* getObject(const String& name) const;
06344
06348 virtual void destruct() {
06349 ISDNLayer2::attach(0);
06350 SignallingReceiver::attach(0);
06351 GenObject::destruct();
06352 }
06353
06359 inline void setDebug(bool printFrames, bool extendedDebug) {
06360 m_printFrames = printFrames;
06361 m_extendedDebug = m_printFrames && extendedDebug;
06362 }
06363
06368 void setDumper(SignallingDumper* dumper = 0);
06369
06370 protected:
06376 virtual void timerTick(const Time& when);
06377
06384 virtual bool receivedPacket(const DataBlock& packet);
06385
06392 virtual bool notify(SignallingInterface::Notification event);
06393
06394 private:
06395
06396
06397
06398 bool acceptFrame(ISDNFrame* frame, bool& cmd, bool& value);
06399
06400 bool dropFrame(const ISDNFrame* frame, const char* reason = 0);
06401
06402 Mutex m_layer;
06403 bool m_checkLinkSide;
06404 SignallingTimer m_idleTimer;
06405 u_int8_t m_lastFrame;
06406 u_int32_t m_rxFrames;
06407 u_int32_t m_rxRejectedFrames;
06408 u_int32_t m_rxDroppedFrames;
06409 u_int32_t m_hwErrors;
06410 SignallingDumper* m_dumper;
06411 bool m_printFrames;
06412 bool m_extendedDebug;
06413 bool m_errorReceive;
06414 };
06415
06422 class YSIG_API ISDNIUA : public ISDNLayer2, public SIGTRAN
06423 {
06424 protected:
06431 inline ISDNIUA(const NamedList& params, const char* name = 0)
06432 : ISDNLayer2(params,name)
06433 {}
06434
06438 virtual ~ISDNIUA()
06439 {}
06440 };
06441
06446 class YSIG_API ISDNQ931IE : public NamedList
06447 {
06448 friend class ISDNQ931Message;
06449 public:
06453 enum Type {
06454
06455 Shift = 0x90,
06456 MoreData = 0xa0,
06457 SendComplete = 0xa1,
06458 Congestion = 0xb0,
06459 Repeat = 0xd0,
06460
06461 Segmented = 0x00,
06462 BearerCaps = 0x04,
06463 Cause = 0x08,
06464 CallIdentity = 0x10,
06465 CallState = 0x14,
06466 ChannelID = 0x18,
06467 Progress = 0x1e,
06468 NetFacility = 0x20,
06469 Notification = 0x27,
06470 Display = 0x28,
06471 DateTime = 0x29,
06472 Keypad = 0x2c,
06473 Signal = 0x34,
06474 ConnectedNo = 0x4c,
06475 CallingNo = 0x6c,
06476 CallingSubAddr = 0x6d,
06477 CalledNo = 0x70,
06478 CalledSubAddr = 0x71,
06479 NetTransit = 0x78,
06480 Restart = 0x79,
06481 LoLayerCompat = 0x7c,
06482 HiLayerCompat = 0x7d,
06483
06484 UserUser = 0x7e,
06485 Escape = 0x7f,
06486 };
06487
06493 ISDNQ931IE(u_int16_t type);
06494
06498 virtual ~ISDNQ931IE();
06499
06504 inline u_int8_t type() const
06505 { return (u_int8_t)m_type; }
06506
06512 inline void addParamPrefix(const char* name, const char* value)
06513 { addParam(*this+"."+name,value); }
06514
06522 void toString(String& dest, bool extendedDebug, const char* before = 0);
06523
06530 static inline const char* typeName(int type, const char* defVal = 0)
06531 { return lookup(type,s_type,defVal); }
06532
06536 static TokenDict s_type[];
06537
06541 DataBlock m_buffer;
06542
06543 private:
06544 u_int16_t m_type;
06545 };
06546
06551 class YSIG_API ISDNQ931Message : public SignallingMessage
06552 {
06553 public:
06557 enum Type {
06558 Alerting = 0x01,
06559 Proceeding = 0x02,
06560 Connect = 0x07,
06561 ConnectAck = 0x0f,
06562 Progress = 0x03,
06563 Setup = 0x05,
06564 SetupAck = 0x0d,
06565 Resume = 0x26,
06566 ResumeAck = 0x2e,
06567 ResumeRej = 0x22,
06568 Suspend = 0x25,
06569 SuspendAck = 0x2d,
06570 SuspendRej = 0x21,
06571 UserInfo = 0x20,
06572 Disconnect = 0x45,
06573 Release = 0x4d,
06574 ReleaseComplete = 0x5a,
06575 Restart = 0x46,
06576 RestartAck = 0x4e,
06577 Segment = 0x60,
06578 CongestionCtrl = 0x79,
06579 Info = 0x7b,
06580 Notify = 0x6e,
06581 Status = 0x7d,
06582 StatusEnquiry = 0x75,
06583 };
06584
06593 ISDNQ931Message(Type type, bool initiator, u_int32_t callRef, u_int8_t callRefLen);
06594
06600 ISDNQ931Message(Type type);
06601
06608 ISDNQ931Message(Type type, ISDNQ931Call* call);
06609
06613 virtual ~ISDNQ931Message();
06614
06619 inline Type type() const
06620 { return m_type; }
06621
06626 inline bool initiator() const
06627 { return m_initiator; }
06628
06633 inline u_int32_t callRef() const
06634 { return m_callRef; }
06635
06640 inline u_int8_t callRefLen() const
06641 { return m_callRefLen; }
06642
06647 inline bool dummyCallRef() const
06648 { return m_dummy; }
06649
06654 inline bool unknownMandatory() const
06655 { return m_unkMandatory; }
06656
06660 inline void setUnknownMandatory()
06661 { m_unkMandatory = true; }
06662
06667 inline ObjList* ieList()
06668 { return &m_ie; }
06669
06676 ISDNQ931IE* getIE(ISDNQ931IE::Type type, ISDNQ931IE* base = 0);
06677
06684 ISDNQ931IE* removeIE(ISDNQ931IE::Type type, ISDNQ931IE* base = 0);
06685
06693 inline const char* getIEValue(ISDNQ931IE::Type type, const char* param,
06694 const char* defVal = 0) {
06695 ISDNQ931IE* ie = getIE(type);
06696 return (ie ? ie->getValue(param?param:ie->c_str(),defVal) : defVal);
06697 }
06698
06706 inline ISDNQ931IE* appendIEValue(ISDNQ931IE::Type type, const char* param,
06707 const char* value) {
06708 ISDNQ931IE* ie = new ISDNQ931IE(type);
06709 ie->addParam(param?param:ie->c_str(),value);
06710 appendSafe(ie);
06711 return ie;
06712 }
06713
06719 inline bool append(ISDNQ931IE* ie)
06720 { return 0 != m_ie.append(ie); }
06721
06728 bool appendSafe(ISDNQ931IE* ie);
06729
06737 void toString(String& dest, bool extendedDebug, const char* indent = 0) const;
06738
06744 virtual void* getObject(const String& name) const;
06745
06756 u_int8_t encode(ISDNQ931ParserData& parserData, ObjList& dest);
06757
06767 static ISDNQ931Message* parse(ISDNQ931ParserData& parserData,
06768 const DataBlock& buffer, DataBlock* segData);
06769
06775 static inline const char* typeName(int t)
06776 { return lookup(t,s_type,"Unknown"); }
06777
06781 static TokenDict s_type[];
06782
06786 DataBlock m_buffer;
06787
06788 private:
06789 Type m_type;
06790 bool m_initiator;
06791 u_int32_t m_callRef;
06792 u_int8_t m_callRefLen;
06793 bool m_unkMandatory;
06794 bool m_dummy;
06795 ObjList m_ie;
06796 };
06797
06802 class YSIG_API ISDNQ931IEData
06803 {
06804 friend class ISDNQ931Call;
06805 friend class ISDNQ931CallMonitor;
06806 friend class ISDNQ931;
06807 friend class ISDNQ931Monitor;
06808 private:
06809
06810 ISDNQ931IEData();
06811
06812
06813
06814
06815 bool processBearerCaps(ISDNQ931Message* msg, bool add, ISDNQ931ParserData* data = 0);
06816 bool processCause(ISDNQ931Message* msg, bool add, ISDNQ931ParserData* data = 0);
06817 bool processDisplay(ISDNQ931Message* msg, bool add, ISDNQ931ParserData* data = 0);
06818 bool processKeypad(ISDNQ931Message* msg, bool add, ISDNQ931ParserData* data = 0);
06819 bool processChannelID(ISDNQ931Message* msg, bool add, ISDNQ931ParserData* data = 0);
06820 bool processProgress(ISDNQ931Message* msg, bool add, ISDNQ931ParserData* data = 0);
06821 bool processRestart(ISDNQ931Message* msg, bool add, ISDNQ931ParserData* data = 0);
06822 bool processNotification(ISDNQ931Message* msg, bool add, ISDNQ931ParserData* data = 0);
06823 bool processCalledNo(ISDNQ931Message* msg, bool add, ISDNQ931ParserData* data = 0);
06824 bool processCallingNo(ISDNQ931Message* msg, bool add, ISDNQ931ParserData* data = 0);
06825
06826
06827 String m_display;
06828 String m_callerNo;
06829 String m_callerType;
06830 String m_callerPlan;
06831 String m_callerPres;
06832 String m_callerScreening;
06833 String m_calledNo;
06834 String m_calledType;
06835 String m_calledPlan;
06836 String m_transferCapability;
06837 String m_transferMode;
06838 String m_transferRate;
06839 String m_format;
06840 String m_reason;
06841 String m_keypad;
06842 String m_progress;
06843 String m_notification;
06844 bool m_bri;
06845 bool m_channelMandatory;
06846 bool m_channelByNumber;
06847 String m_channelType;
06848 String m_channelSelect;
06849 String m_channels;
06850 String m_restart;
06851 };
06852
06857 class YSIG_API ISDNQ931State
06858 {
06859 public:
06863 enum State {
06864
06865 Null = 0x00,
06866
06867 CallInitiated = 0x01,
06868 OverlapSend = 0x02,
06869 OutgoingProceeding = 0x03,
06870 CallDelivered = 0x04,
06871 CallPresent = 0x06,
06872 CallReceived = 0x07,
06873 ConnectReq = 0x08,
06874 IncomingProceeding = 0x09,
06875 Active = 0x0a,
06876 DisconnectReq = 0x0b,
06877 DisconnectIndication = 0x0c,
06878 SuspendReq = 0x0f,
06879 ResumeReq = 0x11,
06880 ReleaseReq = 0x13,
06881 CallAbort = 0x16,
06882 OverlapRecv = 0x19,
06883
06884 RestartReq = 0x3d,
06885 Restart = 0x3e,
06886 };
06887
06891 inline ISDNQ931State() : m_state(Null)
06892 {}
06893
06898 inline State state() const
06899 { return m_state; }
06900
06906 static const char* stateName(u_int8_t s)
06907 { return lookup(s,s_states,0); }
06908
06912 static TokenDict s_states[];
06913
06914 protected:
06921 bool checkStateRecv(int type, bool* retrans);
06922
06928 bool checkStateSend(int type);
06929
06933 State m_state;
06934
06935 };
06936
06941 class YSIG_API ISDNQ931Call : public ISDNQ931State, public SignallingCall
06942 {
06943 friend class ISDNQ931;
06944 public:
06948 virtual ~ISDNQ931Call();
06949
06954 inline u_int32_t callRef() const
06955 { return m_callRef; }
06956
06961 inline u_int32_t callRefLen() const
06962 { return m_callRefLen; }
06963
06968 inline SignallingCircuit* circuit()
06969 { return m_circuit; }
06970
06977 void setTerminate(bool destroy, const char* reason);
06978
06985 virtual bool sendEvent(SignallingEvent* event);
06986
06993 virtual SignallingEvent* getEvent(const Time& when);
06994
07000 void dataLinkState(bool up);
07001
07007 virtual void* getObject(const String& name) const;
07008
07009 protected:
07017 ISDNQ931Call(ISDNQ931* controller, bool outgoing, u_int32_t callRef,
07018 u_int8_t callRefLen);
07019
07028 SignallingEvent* releaseComplete(const char* reason = 0, const char* diag = 0);
07029
07035 SignallingEvent* getCircuitEvent(const Time& when);
07036
07037 private:
07038
07039 bool reserveCircuit();
07040
07041
07042 SignallingEvent* processTerminate(ISDNQ931Message* msg = 0);
07043
07044 SignallingEvent* checkTimeout(u_int64_t time);
07045
07046
07047 bool checkMsgRecv(ISDNQ931Message* msg, bool status);
07048
07049
07050 SignallingEvent* processMsgAlerting(ISDNQ931Message* msg);
07051 SignallingEvent* processMsgCallProceeding(ISDNQ931Message* msg);
07052 SignallingEvent* processMsgConnect(ISDNQ931Message* msg);
07053 SignallingEvent* processMsgConnectAck(ISDNQ931Message* msg);
07054 SignallingEvent* processMsgDisconnect(ISDNQ931Message* msg);
07055 SignallingEvent* processMsgInfo(ISDNQ931Message* msg);
07056 SignallingEvent* processMsgNotify(ISDNQ931Message* msg);
07057 SignallingEvent* processMsgProgress(ISDNQ931Message* msg);
07058 SignallingEvent* processMsgRelease(ISDNQ931Message* msg);
07059 SignallingEvent* processMsgSetup(ISDNQ931Message* msg);
07060 SignallingEvent* processMsgSetupAck(ISDNQ931Message* msg);
07061 SignallingEvent* processMsgStatus(ISDNQ931Message* msg);
07062 SignallingEvent* processMsgStatusEnquiry(ISDNQ931Message* msg);
07063
07064
07065 bool sendAlerting(SignallingMessage* sigMsg);
07066 bool sendCallProceeding(SignallingMessage* sigMsg);
07067 bool sendConnect(SignallingMessage* sigMsg);
07068 bool sendConnectAck(SignallingMessage* sigMsg);
07069 bool sendDisconnect(SignallingMessage* sigMsg);
07070 bool sendInfo(SignallingMessage* sigMsg);
07071 bool sendProgress(SignallingMessage* sigMsg);
07072 bool sendRelease(const char* reason = 0, SignallingMessage* sigMsg = 0);
07073 bool sendReleaseComplete(const char* reason = 0, const char* diag = 0);
07074 bool sendSetup(SignallingMessage* sigMsg);
07075 bool sendSuspendRej(const char* reason = 0, SignallingMessage* sigMsg = 0);
07076
07077
07078
07079 SignallingEvent* errorNoIE(ISDNQ931Message* msg, ISDNQ931IE::Type type, bool release);
07080 SignallingEvent* errorWrongIE(ISDNQ931Message* msg, ISDNQ931IE::Type type, bool release);
07081
07082 void changeState(State newState);
07083
07084 void removeFromController();
07085
07086 inline ISDNQ931* q931();
07087
07088
07089 u_int32_t m_callRef;
07090 u_int32_t m_callRefLen;
07091 SignallingCircuit* m_circuit;
07092 bool m_circuitChange;
07093 bool m_channelIDSent;
07094 bool m_rspBearerCaps;
07095 ISDNQ931IEData m_data;
07096 ObjList m_inMsg;
07097
07098 SignallingTimer m_discTimer;
07099 SignallingTimer m_relTimer;
07100 SignallingTimer m_conTimer;
07101
07102 bool m_terminate;
07103 bool m_destroy;
07104 bool m_destroyed;
07105 };
07106
07111 class YSIG_API ISDNQ931CallMonitor : public ISDNQ931State, public SignallingCall
07112 {
07113 friend class ISDNQ931Monitor;
07114 public:
07118 virtual ~ISDNQ931CallMonitor();
07119
07124 inline bool netInit() const
07125 { return m_netInit; }
07126
07133 virtual SignallingEvent* getEvent(const Time& when);
07134
07140 void setTerminate(const char* reason);
07141
07147 virtual void* getObject(const String& name) const;
07148
07149 protected:
07156 ISDNQ931CallMonitor(ISDNQ931Monitor* controller, u_int32_t callRef, bool netInit);
07157
07164 SignallingEvent* releaseComplete(const char* reason = 0);
07165
07166 private:
07167
07168 SignallingEvent* getCircuitEvent(const Time& when);
07169
07170 SignallingEvent* processMsgSetup(ISDNQ931Message* msg);
07171
07172 SignallingEvent* processMsgResponse(ISDNQ931Message* msg);
07173
07174 SignallingEvent* processMsgTerminate(ISDNQ931Message* msg);
07175
07176 SignallingEvent* processMsgInfo(ISDNQ931Message* msg);
07177
07178 bool reserveCircuit();
07179 void releaseCircuit();
07180
07181 bool connectCircuit(bool caller);
07182
07183 void changeState(State newState);
07184
07185 void removeFromController();
07186
07187 inline ISDNQ931Monitor* q931();
07188
07189 u_int32_t m_callRef;
07190 SignallingCircuit* m_callerCircuit;
07191 SignallingCircuit* m_calledCircuit;
07192 SignallingCircuit* m_eventCircuit;
07193 bool m_netInit;
07194 bool m_circuitChange;
07195 ISDNQ931IEData m_data;
07196 bool m_terminate;
07197 String m_terminator;
07198 ObjList m_inMsg;
07199 };
07200
07205 class YSIG_API ISDNQ931ParserData
07206 {
07207 public:
07213 ISDNQ931ParserData(const NamedList& params, DebugEnabler* dbg = 0);
07214
07220 inline bool flag(int mask)
07221 { return (0 != (m_flags & mask)); }
07222
07223 DebugEnabler* m_dbg;
07224 u_int32_t m_maxMsgLen;
07225 int m_flags;
07226 int m_flagsOrig;
07227 u_int8_t m_maxDisplay;
07228 bool m_allowSegment;
07229 u_int8_t m_maxSegments;
07230 bool m_extendedDebug;
07231 };
07232
07237 class YSIG_API ISDNQ931 : public SignallingCallControl, public ISDNLayer3
07238 {
07239 friend class ISDNQ931Call;
07240 public:
07245 enum BehaviourFlags {
07246
07247
07248
07249 SendNonIsdnSource = 0x00000001,
07250
07251
07252 IgnoreNonIsdnDest = 0x00000002,
07253
07254
07255 ForcePresNetProv = 0x00000004,
07256
07257 Translate31kAudio = 0x00000008,
07258
07259
07260
07261 URDITransferCapsOnly = 0x00000010,
07262
07263
07264 NoLayer1Caps = 0x00000020,
07265
07266 IgnoreNonLockedIE = 0x00000040,
07267
07268
07269
07270 NoDisplayIE = 0x00000080,
07271
07272 NoDisplayCharset = 0x00000100,
07273
07274 ForceSendComplete = 0x00000200,
07275
07276
07277
07278 NoActiveOnConnect = 0x00000400,
07279
07280 CheckNotifyInd = 0x00000800,
07281 };
07282
07286 enum SwitchType {
07287 Unknown = 0,
07288
07289 EuroIsdnE1 = ForceSendComplete|CheckNotifyInd|NoDisplayCharset|URDITransferCapsOnly,
07290
07291 EuroIsdnT1 = ForceSendComplete|CheckNotifyInd,
07292
07293 NationalIsdn = SendNonIsdnSource,
07294
07295 Dms100 = ForcePresNetProv|IgnoreNonIsdnDest,
07296
07297 Lucent5e = IgnoreNonLockedIE,
07298
07299 Att4ess = ForcePresNetProv|IgnoreNonLockedIE|Translate31kAudio|NoLayer1Caps,
07300
07301 QSIG = NoActiveOnConnect|NoDisplayIE|NoDisplayCharset
07302 };
07303
07304
07311 ISDNQ931(const NamedList& params, const char* name = 0);
07312
07317 virtual ~ISDNQ931();
07318
07323 inline const ISDNLayer2* layer2() const
07324 { return m_q921; }
07325
07330 inline bool primaryRate() const
07331 { return m_primaryRate; }
07332
07337 inline bool transferModeCircuit() const
07338 { return m_transferModeCircuit; }
07339
07344 inline ISDNQ931ParserData& parserData()
07345 { return m_parserData; }
07346
07351 inline const String& numPlan() const
07352 { return m_numPlan; }
07353
07358 inline const String& numType() const
07359 { return m_numType; }
07360
07365 inline const String& numPresentation() const
07366 { return m_numPresentation; }
07367
07372 inline const String& numScreening() const
07373 { return m_numScreening; }
07374
07379 inline const String& format() const
07380 { return m_format; }
07381
07388 bool sendMessage(ISDNQ931Message* msg, String* reason = 0);
07389
07397 virtual void multipleFrameEstablished(bool confirm, bool timeout, ISDNLayer2* layer2);
07398
07406 virtual void multipleFrameReleased(bool confirm, bool timeout, ISDNLayer2* layer2);
07407
07414 virtual void receiveData(const DataBlock& data, bool ack, ISDNLayer2* layer2);
07415
07421 virtual void attach(ISDNLayer2* q921);
07422
07429 SignallingCall* call(SignallingMessage* msg, String& reason);
07430
07436 bool restart(const char* circuits);
07437
07446 inline bool sendStatus(ISDNQ931Call* call, const char* cause,
07447 const char* display = 0, const char* diagnostic = 0) {
07448 if (!call)
07449 return false;
07450 return sendStatus(cause,call->callRefLen(),call->callRef(),
07451 call->outgoing(),call->state(),display,diagnostic);
07452 }
07453
07464 inline bool sendRelease(ISDNQ931Call* call, bool release, const char* cause,
07465 const char* diag = 0, const char* display = 0, const char* signal = 0) {
07466 if (!call)
07467 return false;
07468 return sendRelease(release,call->callRefLen(),call->callRef(),
07469 call->outgoing(),cause,diag,display,signal);
07470 }
07471
07477 virtual void cleanup(const char* reason = "offline");
07478
07485 void setInterval(SignallingTimer& timer, int id);
07486
07492 virtual void* getObject(const String& name) const;
07493
07497 virtual void destruct() {
07498 attach(0);
07499 SignallingCallControl::attach(0);
07500 ISDNLayer3::destruct();
07501 }
07502
07508 inline void setDebug(bool printMsg, bool extendedDebug) {
07509 m_printMsg = printMsg;
07510 m_extendedDebug = m_printMsg && extendedDebug;
07511 m_parserData.m_extendedDebug = m_extendedDebug;
07512 }
07513
07517 static TokenDict s_flags[];
07518
07522 static TokenDict s_swType[];
07523
07524 protected:
07530 virtual void timerTick(const Time& when);
07531
07538 ISDNQ931Call* findCall(u_int32_t callRef, bool outgoing);
07539
07545 ISDNQ931Call* findCall(unsigned int circuit);
07546
07552 void terminateCalls(ObjList* list, const char* reason);
07553
07560 bool acceptNewCall(bool outgoing, String& reason);
07561
07567 ISDNQ931Message* getMsg(const DataBlock& data);
07568
07576 ISDNQ931Message* endReceiveSegment(const char* reason = 0);
07577
07582 void processGlobalMsg(ISDNQ931Message* msg);
07583
07588 void processMsgRestart(ISDNQ931Message* msg);
07589
07594 void processInvalidMsg(ISDNQ931Message* msg);
07595
07603 void sendRestart(u_int64_t time = Time::msecNow(), bool retrans = false);
07604
07612 void endRestart(bool restart, u_int64_t time, bool timeout = false);
07613
07625 bool sendStatus(const char* cause, u_int8_t callRefLen, u_int32_t callRef = 0,
07626 bool initiator = false, ISDNQ931Call::State state = ISDNQ931Call::Null,
07627 const char* display = 0, const char* diagnostic = 0);
07628
07641 bool sendRelease(bool release, u_int8_t callRefLen, u_int32_t callRef,
07642 bool initiator, const char* cause, const char* diag = 0,
07643 const char* display = 0, const char* signal = 0);
07644 private:
07645 Mutex m_layer;
07646 ISDNLayer2* m_q921;
07647 bool m_q921Up;
07648
07649 bool m_primaryRate;
07650 bool m_transferModeCircuit;
07651 u_int32_t m_callRef;
07652 u_int8_t m_callRefLen;
07653 u_int32_t m_callRefMask;
07654 ISDNQ931ParserData m_parserData;
07655 ISDNQ931IEData m_data;
07656
07657 SignallingTimer m_l2DownTimer;
07658 SignallingTimer m_recvSgmTimer;
07659 SignallingTimer m_syncCicTimer;
07660 SignallingCounter m_syncCicCounter;
07661 SignallingTimer m_callDiscTimer;
07662 SignallingTimer m_callRelTimer;
07663 SignallingTimer m_callConTimer;
07664
07665 String m_numPlan;
07666 String m_numType;
07667 String m_numPresentation;
07668 String m_numScreening;
07669 String m_format;
07670
07671 SignallingCircuit* m_restartCic;
07672 unsigned int m_lastRestart;
07673 SignallingTimer m_syncGroupTimer;
07674
07675 DataBlock m_segmentData;
07676 ISDNQ931Message* m_segmented;
07677 u_int8_t m_remaining;
07678
07679 bool m_printMsg;
07680 bool m_extendedDebug;
07681
07682 bool m_flagQ921Down;
07683 bool m_flagQ921Invalid;
07684 };
07685
07690 class YSIG_API ISDNQ931Monitor : public SignallingCallControl, public ISDNLayer3
07691 {
07692 friend class ISDNQ931CallMonitor;
07693 public:
07700 ISDNQ931Monitor(const NamedList& params, const char* name = 0);
07701
07706 virtual ~ISDNQ931Monitor();
07707
07717 virtual void dataLinkState(bool cmd, bool value, ISDNLayer2* layer2);
07718
07723 virtual void idleTimeout(ISDNLayer2* layer2);
07724
07732 virtual void receiveData(const DataBlock& data, bool ack, ISDNLayer2* layer2);
07733
07740 virtual void attach(ISDNQ921Pasive* q921, bool net);
07741
07748 virtual void attach(SignallingCircuitGroup* circuits, bool net);
07749
07755 virtual void* getObject(const String& name) const;
07756
07760 virtual void destruct() {
07761 SignallingCallControl::attach(0);
07762 attach((ISDNQ921Pasive*)0,true);
07763 attach((ISDNQ921Pasive*)0,false);
07764 attach((SignallingCircuitGroup*)0,true);
07765 attach((SignallingCircuitGroup*)0,false);
07766 ISDNLayer3::destruct();
07767 }
07768
07774 inline void setDebug(bool printMsg, bool extendedDebug) {
07775 m_printMsg = printMsg;
07776 m_extendedDebug = m_printMsg && extendedDebug;
07777 m_parserData.m_extendedDebug = m_extendedDebug;
07778 }
07779
07785 virtual void cleanup(const char* reason = "offline")
07786 { terminateMonitor(0,reason); }
07787
07794 void terminateMonitor(ISDNQ931CallMonitor* mon, const char* reason);
07795
07796 protected:
07802 virtual void timerTick(const Time& when);
07803
07815 bool reserveCircuit(unsigned int code, bool netInit,
07816 SignallingCircuit** caller, SignallingCircuit** called);
07817
07824 bool releaseCircuit(SignallingCircuit* circuit);
07825
07831 void processMsgRestart(ISDNQ931Message* msg);
07832
07833 private:
07834
07835
07836 ISDNQ931CallMonitor* findMonitor(unsigned int value, bool byCallRef);
07837
07838 bool dropMessage(const ISDNQ931Message* msg);
07839
07840 Mutex m_layer;
07841 ISDNQ921Pasive* m_q921Net;
07842 ISDNQ921Pasive* m_q921Cpe;
07843 SignallingCircuitGroup* m_cicNet;
07844 SignallingCircuitGroup* m_cicCpe;
07845 ISDNQ931ParserData m_parserData;
07846 ISDNQ931IEData m_data;
07847
07848 bool m_printMsg;
07849 bool m_extendedDebug;
07850 };
07851
07852 }
07853
07854 #endif
07855
07856