//  ==========================================================================
//  
//  @(#) $Id: L3_Codec.C,v 1.4 2000/10/19 03:21:57 brian Exp $
//  
//  --------------------------------------------------------------------------
//  
//  Copyright (C) 1997-2000  Brian Bidulock <bidulock@dallas.net>
//  
//  All Rights Reserved.
//  
//  This library is free software; you can redistribute it and/or modify it
//  under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation; either version 2.1 of the License, or (at
//  your option) any later version.
//  
//  This library is distributed in the hope that it will be useful, but
//  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
//  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser Public License
//  for more details.
//  
//  You should have received a copy of the GNU Lesser General Public License
//  along with this library; if not, write to the Free Software Foundation,
//  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// 
//  Last Modified $Date: 2000/10/19 03:21:57 $ by $Author: brian $
// 
//  --------------------------------------------------------------------------
// 
//  $Log: L3_Codec.C,v $
//  Revision 1.4  2000/10/19 03:21:57  brian
//  Whoops, messed up when adding headers.
//
//  Revision 1.3  2000/10/13 15:45:51  brian
//  First public release.
//
//  ==========================================================================

static char const ident[] = "$Id: L3_Codec.C,v 1.4 2000/10/19 03:21:57 brian Exp $";

#pragma implementation

#include "L3_Codec.H"
#include <iostream.h>

Codec_UP::Codec_UP(char* l,char* t) :
    Content(l,t,-1,1,0,(Codec**)&PDU) {
    PDU = new OctetString(l,t,-1);
};

Codec_RL::Codec_RL(char* l,char* t) :
    Parameter(l,t,variant==ansi?56:32,3,0,(Codec**)&OPC) {
    if (variant==ansi) {
        OPC = new Codec_PC("OPC","Originating Point Code",8,8,8,0);
        DPC = new Codec_PC("DPC","Destination Point Code",8,8,8,0);
        SLS = new Field("SLS","Sig Link Selection",5,3);
    } else {
        OPC = new Codec_PC("OPC","Originating Point Code",4,6,4,0);
        DPC = new Codec_PC("DPC","Destination Point Code",4,6,4,0);
        SLS = new Field("SLS","Sig Link Selection",4,0);
    }
};

Codec_SDLI::Codec_SDLI(char* l,char* t) :
    Parameter(l,t,variant==ansi?24:16,variant==ansi?2:1,0,(Codec**)(variant==ansi?&SLC:&SDLI)) {
    if (variant==ansi) {
        SLC  = new Field("SLC","Signalling link code",4,0);
        SDLI = new Field("SDLI","Signalling Data Link ID",14,6);
    } else {
        SLC  = NULL;
        SDLI = new Field("SDLI","Signalling Data Link ID",12,4);
    }
};

Codec_DEST::Codec_DEST(char* l,char* t) :
    Parameter(l,t,variant==ansi?24:16,1,0,(Codec**)&DEST) {
    if (variant==ansi)
        DEST = new Codec_PC("DEST","Destination Point Code",4,6,4,2);
    else
        DEST = new Codec_PC("DEST","Destination Point Code",8,8,8,0);
};

Codec_DS::Codec_DS(char* l,char* t) :
    Parameter(l,t,variant==ansi?32:16,2,0,(Codec**)&DEST) {
    if (variant==ansi) {
        DEST = new Codec_PC("DEST","Destination Point Code",8,8,8,0);
        STAT = new Field("STAT","Status",2,6);
    } else {
        DEST = new Codec_PC("DEST","Destination Point Code",4,6,4,0);
        STAT = new Field("STAT","Status",2,0);
    }
};

Codec_FSNL::Codec_FSNL(char* l,char* t) :
    Parameter(l,t,variant==ansi?16:8,variant==ansi?2:1,0,(Codec**)(variant==ansi?&SLC:&FSNL)) {
    if (variant==ansi) {
        SLC  = new Field("SLC","Signalling link code",4,0);
        FSNL = new Field("FSNL","FSN of last MSU",7,5);
    } else {
        SLC  = NULL;
        FSNL = new Field("FSNL","FSN of last MSU",7,1);
    }
};

Codec_CBC::Codec_CBC(char* l,char* t) :
    Parameter(l,t,variant==ansi?16:8,variant==ansi?2:1,0,(Codec**)(variant==ansi?&SLC:&CBC)) {
    if (variant==ansi) {
        SLC = new Field("SLC","Signalling link code",4,0);
        CBC = new Field("CBC","Changeback Code",8,4);
    } else {
        SLC = NULL;
        CBC = new Field("CBC","Changeback Code",8,0);
    }
};

Codec_SLC::Codec_SLC(char* l,char* t) :
    Parameter(l,t,variant==ansi?8:0,variant==ansi?1:0,0,(Codec**)(variant==ansi?&SLC:NULL)) {
    if (variant==ansi)
        SLC = new Field("SLC","Signalling link code",4,4);
    else
        SLC = NULL;
};

Codec_TMSG::Codec_TMSG(char* l,char* t) :
    Parameter(l,t,-1,variant==ansi?3:2,0,(Codec**)(variant==ansi?&SLC:&TLI)) {
    if (variant==ansi) {
        SLC  = new Field("SLC","Signalling link code",4,0);
        TLI  = new Field("TLI","Test Message Length Indicator",4,0);
    } else {
        SLC  = NULL;
        TLI  = new Field("TLI","Test Message Length Indicator",4,4);
    }
    TMSG = new OctetString("TMSG","Test Message",-1);
};

Codec_DUPI::Codec_DUPI(char* l,char* t) :
    Parameter(l,t,variant==ansi?32:24,2,0,(Codec**)&DEST) {
    if (variant==ansi)
        DEST = new Codec_PC("DEST","Destination Point Code",4,6,4,2);
    else
        DEST = new Codec_PC("DEST","Destination Point Code",8,8,8,0);
    UPI = new Set("UPI","User Part Identity",4,4,
                    "SCCP", 3,  "Signalling Connection Control Part",
                    "TUP",  4,  "Telephony User Part",
                    "ISUP", 5,  "ISDN User Part",
                    "DUP1", 6,  "Data User Part (Call & Circuit)",
                    "DUP2", 7,  "Data User Part (Facility Reg & Canc)",
                    "MTUP", 8,  "Maintenance and Test User Part",
                    NULL);
};

Codec_UFC::Codec_UFC(char* l,char* t) :
    Content(l,t,variant==ansi?36:28,2,3,(Codec**)&H1) {
    H1    = new Field("H1","Header 1",4,0);
    UPU   = new Codec_DUPI("UPU","User part unavailable signal");
    UPA   = new Codec_DUPI("UPA","User part available signal");
    UPT   = new Codec_DUPI("UPT","User part test signal");
    H1_B  = new Bra("H1:","H1 Branch",(Codec*)H1,
                    UPU,1, UPA,2, UPT,3, NULL);
};

Codec_DLM::Codec_DLM(char* l,char* t) :
    Content(l,t,variant==ansi?12:4,2,4,(Codec**)&H1) {
    H1    = new Field("H1","Header 1",4,0);
    DLC   = new Codec_SDLI("DLC","Sig-data-link-connection-order signal");
    CSS   = new Codec_SLC ("CSS","Connection-successful signal");
    CNS   = new Codec_SLC ("CNS","Connection-not-successful signal");
    CNP   = new Codec_SLC ("CNP","Connection-not-possible signal");
    H1_B  = new Bra("H1:","H1 Branch",(Codec*)H1,
                    DLC,1, CSS,2, CNS,3, CNP,4, NULL);
};

Codec_TRM::Codec_TRM(char* l,char* t) :
    Content(l,t,4,2,2,(Codec**)&H1) {
    H1    = new Field("H1","Header 1",4,0);
    TRA   = new Codec_NULL("TRA","Traffic restart allowed signal");
    TRW   = new Codec_NULL("TRW","Traffic restart waiting signal");
    H1_B  = new Bra("H1:","H1 Branch",(Codec*)H1,
                    TRA,1, TRW,2, NULL);
};

Codec_MIM::Codec_MIM(char* l,char* t) :
    Content(l,t,variant==ansi?12:4,2,8,(Codec**)&H1) {
    H1    = new Field("H1","Header 1",4,0);
    LIN   = new Codec_SLC("LIN","Link inhibit signal");
    LUN   = new Codec_SLC("LUN","Link uninhibit signal");
    LIA   = new Codec_SLC("LIA","Link inhibit acknowledgement signal");
    LUA   = new Codec_SLC("LUA","Link uninhibited acknowledgement signal");
    LID   = new Codec_SLC("LID","Link inhibit denied signal");
    LFU   = new Codec_SLC("LFU","Link force uninhibit signal");
    LLT   = new Codec_SLC("LLT","Link local inhibit test signal");
    LRT   = new Codec_SLC("LRT","Link remote inhibit test signal");
    H1_B  = new Bra("H1:","H1 Branch",(Codec*)H1,
                    LIN,1, LUN,2, LIA,3, LUA,4, LID,5, LFU,6, LLT,7, LRT,8, NULL);
};

Codec_RSM::Codec_RSM(char* l,char* t) :
    Content(l,t,variant==ansi?28:22,2,4,(Codec**)&H1) {
    H1    = new Field("H1","Header 1",4,0);
    RST   = new Codec_DEST("RST","Sig-route-set-test prohibited signal");
    RSR   = new Codec_DEST("RSR","Sig-route-set-test restricted signal");
    RCP   = new Codec_DEST("RCP","Sig-route-set-test cluster prohibited");
    RCR   = new Codec_DEST("RCR","Sig-route-set-test cluster restricted");
    H1_B  = new Bra("H1:","H1 Branch",(Codec*)H1,
                    RST,1, RSR,2, RCP,3, RCR,4, NULL);
};

Codec_TFM::Codec_TFM(char* l,char* t) :
    Content(l,t,variant==ansi?28:22,2,6,(Codec**)&H1) {
    H1    = new Field("H1","Header 1",4,0);
    TFP   = new Codec_DEST("TFP","Transfer-prohibited signal");
    TCP   = new Codec_DEST("TCP","Transfer-cluster-prohibited signal");
    TFR   = new Codec_DEST("TFR","Transfer-restricted signal");
    TCR   = new Codec_DEST("TCR","Transfer-cluster-restricted signal");
    TFA   = new Codec_DEST("TFA","Transfer-allowed signal");
    TCA   = new Codec_DEST("TCA","Transfer-cluster-allowed signal");
    H1_B  = new Bra("H1:","H1 Branch",(Codec*)H1,
                    TFP,1, TCP,2, TFR,3, TCR,4, TFA,5, TCA,6, NULL);
};

Codec_FCM::Codec_FCM(char* l,char* t) :
    Content(l,t,4,2,2,(Codec**)&H1) {
    H1    = new Field("H1","Header 1",4,0);
    RCT   = new Codec_NULL("RCT","Signalling-route-set-congestion-test msg");
    TFC   = new Codec_DS  ("TFC","Transfer-controlled signal");
    H1_B  = new Bra("H1:","H1 Branch",(Codec*)H1,
                    RCT,1, TFC,2, NULL);
};

Codec_ECM::Codec_ECM(char* l,char* t) :
    Content(l,t,variant==ansi?12:4,2,2,(Codec**)&H1) {
    H1    = new Field("H1","Header 1",4,0);
    ECO   = new Codec_SLC("ECO","Emergency-changeover-order signal");
    ECA   = new Codec_SLC("ECA","Emergency-changeover-acknowledgement sig");
    H1_B  = new Bra("H1:","H1 Branch",(Codec*)H1,
                    ECO,1, ECA,2, NULL);
};

Codec_CHM::Codec_CHM(char* l,char* t) :
    Content(l,t,variant==ansi?20:12,2,4,(Codec**)&H1) {
    H1    = new Field("H1","Header 1",4,0);
    COO   = new Codec_FSNL("COO","Changeover-order signal");
    COA   = new Codec_FSNL("COA","Changeover-acknoledgement signal");
    CBD   = new Codec_CBC ("CBD","Changeback-declaration signal");
    CBA   = new Codec_CBC ("CBA","Changeback-acknowledgement signal");
    H1_B  = new Bra("H1:","H1 Branch",(Codec*)H1,
                    COO,1, COA,2, CBD,5, CBA,6, NULL);
};

Codec_TM::Codec_TM(char* l,char* t) :
    Content(l,t,-1,2,2,(Codec**)&H1) {
    H1    = new Field("H1","Header 1",4,0);
    SLTM  = new Codec_TMSG("SLTM","Signalling Link Test Message");
    SLTA  = new Codec_TMSG("SLTA","Signalling Link Test Acknowledge");
    H1_B  = new Bra("H1:","H1 Branch",(Codec*)H1,
                    SLTM,1, SLTA,2, NULL);
};

Codec_SNSM::Codec_SNSM(char* l,char* t) :       // ansi only
    Content(l,t,4,2,1,(Codec**)&H0) {
    H0    = new Field("H0","Header 0",4,0);
    TM    = new Codec_TM("TM","Special Test Message");
    H0_B  = new Bra("H0:","H0 Branch",(Codec*)H0,
                    TM,1, NULL);
};

Codec_SNTM::Codec_SNTM(char* l,char* t) :
    Content(l,t,4,2,1,(Codec**)&H0) {
    H0    = new Field("H0","Header 0",4,0);
    TM    = new Codec_TM("TM","Test Message");
    H0_B  = new Bra("H0:","H0 Branch",(Codec*)H0,
                    TM,1, NULL);
};

Codec_SNMM::Codec_SNMM(char* l,char* t) :
    Content(l,t,4,2,9,(Codec**)&H0) {
    H0    = new Field("H0","Header 0",4,0);
    CHM   = new Codec_CHM("CHM","Changover and changeback messages");
    ECM   = new Codec_ECM("ECM","Emergency-changeover message");
    FCM   = new Codec_FCM("FCM","Signalling-traffic-flow control message");
    TFM   = new Codec_TFM("TFM","Transfer-prohibit, -allow, -restrict message");
    RSM   = new Codec_RSM("RSM","Signalling-route-set-test message");
    MIM   = new Codec_MIM("MIM","Management inhibit message");
    TRM   = new Codec_TRM("TRM","Traffic restart allowed message");
    DLM   = new Codec_DLM("DLM","Signalling-data-link-connect-order message");
    UFC   = new Codec_UFC("UFC","User part flow control message");
    H0_B  = new Bra("H0:","H0 Branch",(Codec*)H0,
                    CHM, 1, ECM, 2, FCM, 3, TFM, 4, RSM, 5, MIM, 6, TRM, 7,
                    DLM, 8, UFC,10, NULL);
};

Codec_L3::Codec_L3() :
    Header("MSU","Message Signal Unit",-1,5,8,(Codec**)&SI) {
    SI = new Field("SI","Service Indicator",4,0);
    MP = new Set("MP","Message Priority",2,0,
        "P0",   0,  "Message Priority 0",
        "P1",   1,  "Message Priority 1",
        "P2",   2,  "Message Priority 2",
        "P3",   3,  "Message Priority 3",
        NULL);
    NI = new Set("NI", "Network Indicator",2,0,
        "INT",  0,  "International Network",
        "INS",  1,  "International Spare",
        "NAT",  2,  "National Network",
        "NAS",  3,  "National Spare",
        NULL);
    RL = new Codec_RL("RL","Routing Label");
    SNMM = new Codec_SNMM("SNMM","Signalling Network Management Msg"  );
    SNTM = new Codec_SNTM("SNTM","Signalling Network Test&Maint Msg"  );
    SNSM = new Codec_SNSM("SNSM","Signalling Ntwk Test&Maint Spec Msg");
    SCCP = new Codec_UP  ("SCCP","SCCP Message"          );
    TUP  = new Codec_UP  ("TUP", "Telephone User Part Mg");
    ISUP = new Codec_UP  ("ISUP","ISDN User Part Msg"    );
    DUP1 = new Codec_UP  ("DUP1","Data User Part Msg (1)");
    DUP2 = new Codec_UP  ("DUP2","Data User Part Msg (2)");
    MTUP = new Codec_UP  ("MTUP","MTP Test User Part Msg");
    SI_B = new Bra("SI:","SI Branch",(Codec*)SI,
                    SNMM,0, SNTM,1, SNSM,2, SCCP,3, TUP ,4, ISUP,5, DUP1,6,
                    DUP2,7, MTUP,8, NULL);
};

