Annotation of 43BSDReno/contrib/isode-beta/psap2-lpp/psaprespond.c, revision 1.1

1.1     ! root        1: /* psaprespond.c - PPM: responder */
        !             2: 
        !             3: #ifndef        lint
        !             4: static char *rcsid = "$Header: /f/osi/psap2-lpp/RCS/psaprespond.c,v 7.1 90/07/01 21:05:32 mrose Exp $";
        !             5: #endif
        !             6: 
        !             7: /* 
        !             8:  * $Header: /f/osi/psap2-lpp/RCS/psaprespond.c,v 7.1 90/07/01 21:05:32 mrose Exp $
        !             9:  *
        !            10:  * Contributed by The Wollongong Group, Inc.
        !            11:  *
        !            12:  *
        !            13:  * $Log:       psaprespond.c,v $
        !            14:  * Revision 7.1  90/07/01  21:05:32  mrose
        !            15:  * pepsy
        !            16:  * 
        !            17:  * Revision 7.0  89/11/23  22:15:58  mrose
        !            18:  * Release 6.0
        !            19:  * 
        !            20:  */
        !            21: 
        !            22: /*
        !            23:  *                               NOTICE
        !            24:  *
        !            25:  *    Acquisition, use, and distribution of this module and related
        !            26:  *    materials are subject to the restrictions of a license agreement.
        !            27:  *    Consult the Preface in the User's Manual for the full terms of
        !            28:  *    this agreement.
        !            29:  *
        !            30:  */
        !            31: 
        !            32: 
        !            33: /* LINTLIBRARY */
        !            34: 
        !            35: #include <stdio.h>
        !            36: #define        LPP
        !            37: #include "PS-types.h"
        !            38: #include "ppkt.h"
        !            39: #include "tailor.h"
        !            40: 
        !            41: 
        !            42: #define        AC_ASN          "acse pci version 1"
        !            43: 
        !            44: /*    P-CONNECT.INDICATION */
        !            45: 
        !            46: int    PInit (vecp, vec, ps, pi)
        !            47: int    vecp;
        !            48: char  **vec;
        !            49: struct PSAPstart *ps;
        !            50: struct PSAPindication *pi;
        !            51: {
        !            52:     register struct psapblk *pb;
        !            53: 
        !            54:     isodetailor (NULLCP, 0);
        !            55: 
        !            56:     if (vecp < 2)
        !            57:        return psaplose (pi, PC_PARAMETER, NULLCP,
        !            58:                         "bad initialization vector");
        !            59:     missingP (vec);
        !            60:     missingP (ps);
        !            61:     missingP (pi);
        !            62: 
        !            63:     if ((pb = newpblk ()) == NULL)
        !            64:        return psaplose (pi, PC_CONGEST, NULLCP, "out of memory");
        !            65: 
        !            66:     vec++, vecp--;
        !            67:     switch (*vec[0]) {
        !            68:        case PT_TCP:
        !            69:            if (tcprestore (pb, vec[0] + 1, pi) == NOTOK)
        !            70:                goto out;
        !            71:            break;      
        !            72: 
        !            73:        case PT_UDP:
        !            74:            if (udprestore (pb, vec[0] + 1, pi) == NOTOK)
        !            75:                goto out;
        !            76:            break;      
        !            77: 
        !            78:        default:
        !            79:            (void) psaplose (pi, PC_PARAMETER, NULLCP,
        !            80:                             "unknown transport type: 0x%x (%c)",
        !            81:                             *vec[0], *vec[0]);
        !            82:            goto out;
        !            83:     }
        !            84:     *vec = NULL;
        !            85:     if (PInitAux (pb, ++vec, --vecp, ps, pi) == NOTOK)
        !            86:        goto out;
        !            87: 
        !            88:     return OK;
        !            89: 
        !            90: out: ;
        !            91:     freepblk (pb);
        !            92: 
        !            93:     return NOTOK;
        !            94: }
        !            95: 
        !            96: /*  */
        !            97: 
        !            98: /* ARGSUSED */
        !            99: 
        !           100: static int  PInitAux (pb, vec, vecp, ps, pi)
        !           101: register struct psapblk *pb;
        !           102: char  **vec;
        !           103: int    vecp;
        !           104: struct PSAPstart *ps;
        !           105: struct PSAPindication *pi;
        !           106: {
        !           107:     int            result;
        !           108:     PE     pe;
        !           109:     OID            oid;
        !           110:     register struct PSAPcontext *pp;
        !           111:     struct type_PS_PDUs *pdu;
        !           112:     register struct type_PS_ConnectRequest__PDU *cr;
        !           113:     register struct TSAPaddr *ta;
        !           114: 
        !           115:     if ((pe = ps2pe (pb -> pb_stream)) == NULLPE)
        !           116:        return pslose (pi, pb -> pb_stream -> ps_errno);
        !           117: 
        !           118:     pdu = NULL;
        !           119:     oid = NULLOID;
        !           120:     result = decode_PS_PDUs (pe, 1, NULLIP, NULLVP, &pdu);
        !           121: 
        !           122: #ifdef DEBUG
        !           123:     if (result == OK && (psap2_log -> ll_events & LLOG_PDUS))
        !           124:        pvpdu (psap2_log, print_PS_PDUs_P, pe, "PDU", 1);
        !           125: #endif
        !           126: 
        !           127:     pe_free (pe);
        !           128: 
        !           129:     if (result == NOTOK) {
        !           130:        (void) ppktlose (pb, pi, PC_UNRECOGNIZED, NULLRF, NULLCP,
        !           131:                         "error decoding PDU: %s", PY_pepy);
        !           132:        goto out;
        !           133:     }
        !           134: 
        !           135:     if (pdu -> offset != type_PS_PDUs_connectRequest) {
        !           136:        /* this works 'cause the "reference" is always the FIRST element */
        !           137:        if (pdu -> offset != type_PS_PDUs_abort)
        !           138:            result = ppktlose (pb, pi, PC_SESSION,
        !           139:                               pdu -> un.connectResponse -> reference, NULLCP,
        !           140:                               "unexpected PDU %d", pdu -> offset);
        !           141:        else
        !           142:            result = psaplose (pi, PC_SESSION, NULLCP, "unexpected PDU %d",
        !           143:                               pdu -> offset);
        !           144:        goto out;
        !           145:     }
        !           146: 
        !           147:     cr = pdu -> un.connectRequest;
        !           148: 
        !           149:     if ((oid = ode2oid (AC_ASN)) == NULL) {
        !           150:        result = ppktlose (pb, pi, PC_PARAMETER, cr -> reference, NULLCP,
        !           151:                           "%s: unknown", AC_ASN);
        !           152:        goto out;
        !           153:     }
        !           154:     if ((oid = oid_cpy (oid)) == NULL) {
        !           155:        result = ppktlose (pb, pi, PC_CONGEST, cr -> reference, NULLCP,
        !           156:                           NULLCP);
        !           157:        goto out;
        !           158:     }
        !           159: 
        !           160:     pb -> pb_reference = cr -> reference, cr -> reference = NULL;
        !           161:     pe = cr -> user__data, cr -> user__data = NULLPE;
        !           162: 
        !           163: /* should check version number here... */
        !           164: 
        !           165:     bzero ((char *) ps, sizeof *ps);
        !           166: 
        !           167:     ps -> ps_sd = pb -> pb_fd;
        !           168: 
        !           169:     ta = &ps -> ps_calling.pa_addr.sa_addr;
        !           170:     ta -> ta_naddr = 1;
        !           171:     ta -> ta_addrs[0] = pb -> pb_initiating;   /* struct copy */
        !           172:     pdu2sel (ps -> ps_calling.pa_selector,
        !           173:             &ps -> ps_calling.pa_selectlen,
        !           174:             sizeof ps -> ps_calling.pa_selector,
        !           175:             cr -> calling);
        !           176: 
        !           177:     ta = &pb -> pb_responding.pa_addr.sa_addr;
        !           178:     ta -> ta_naddr = 1;
        !           179:     ta -> ta_addrs[0] = pb -> pb_initiating;   /* struct copy */
        !           180:     pdu2sel (pb -> pb_responding.pa_selector,
        !           181:             &pb -> pb_responding.pa_selectlen,
        !           182:             sizeof pb -> pb_responding.pa_selector,
        !           183:             cr -> called);
        !           184:     ps -> ps_called = pb -> pb_responding;     /* struct copy */
        !           185: 
        !           186:     ps -> ps_ctxlist.pc_nctx = 2;
        !           187:     pp = ps -> ps_ctxlist.pc_ctx;
        !           188: 
        !           189:     pp -> pc_id = PCI_ROSE;
        !           190:     pp -> pc_asn = cr -> asn;
        !           191:     pp -> pc_result = PC_ACCEPT;
        !           192:     cr -> asn = NULLOID, pp++;
        !           193: 
        !           194:     pp -> pc_id = PCI_ACSE;
        !           195:     pp -> pc_asn = oid, oid = NULLOID;
        !           196:     pp -> pc_result = PC_ACCEPT;
        !           197: 
        !           198:     ps -> ps_defctxresult = PC_ACCEPT;
        !           199: 
        !           200:     ps -> ps_prequirements = PR_KERNEL;
        !           201:     ps -> ps_srequirements = SR_DUPLEX;
        !           202: 
        !           203:     ps -> ps_isn = SERIAL_NONE;
        !           204: 
        !           205:     ps -> ps_connect = *pdu2ref (pb -> pb_reference);  /* struct copy */
        !           206: 
        !           207:     ps -> ps_qos.qos_reliability = pb -> pb_reliability;
        !           208:     ps -> ps_qos.qos_sversion = 2;
        !           209: 
        !           210:     (ps -> ps_info[0] = pe) -> pe_context = PCI_ACSE;
        !           211:     ps -> ps_ninfo = 1;
        !           212: 
        !           213:     result = OK;
        !           214: 
        !           215: out: ;
        !           216:     if (pdu)
        !           217:        free_PS_PDUs (pdu);
        !           218:     if (oid)
        !           219:        oid_free (oid);
        !           220: 
        !           221:     return result;
        !           222: }
        !           223: 
        !           224: /*    P-CONNECT.RESPONSE */
        !           225: 
        !           226: int    PConnResponse (sd, status, responding, ctxlist, defctxresult,
        !           227:        prequirements, srequirements, isn, settings, ref, data, ndata, pi)
        !           228: int    sd;
        !           229: struct PSAPaddr *responding;
        !           230: int    status,
        !           231:        prequirements,
        !           232:        srequirements,
        !           233:        settings,
        !           234:        ndata;
        !           235: long   isn;
        !           236: struct PSAPctxlist *ctxlist;
        !           237: int    defctxresult;
        !           238: struct SSAPref *ref;
        !           239: PE     *data;
        !           240: struct PSAPindication *pi;
        !           241: {
        !           242:     int            result;
        !           243:     PE     pe;
        !           244:     PS     ps;
        !           245:     register struct psapblk *pb;
        !           246:     register struct type_PS_ConnectResponse__PDU *pdu;
        !           247: 
        !           248:     if ((pb = findpblk (sd)) == NULL || (pb -> pb_flags & PB_CONN))
        !           249:        return psaplose (pi, PC_PARAMETER, NULLCP,
        !           250:                         "invalid presentation descriptor");
        !           251: #ifdef notdef
        !           252:     missingP (responding);
        !           253: #endif
        !           254:     switch (status) {
        !           255:        case PC_ACCEPT:
        !           256:        case PC_REJECTED:
        !           257:            break;
        !           258: 
        !           259:         default:
        !           260:            return psaplose (pi, PC_PARAMETER, NULLCP,
        !           261:                             "bad value for status parameter");
        !           262:     }
        !           263:     if (ctxlist != NULL) {
        !           264:        register int    i;
        !           265:        register struct PSAPcontext *pp;
        !           266: 
        !           267:        i = ctxlist -> pc_nctx - 1;
        !           268:        for (pp = ctxlist -> pc_ctx; i >= 0; i--, pp++) {
        !           269:            switch (pp -> pc_id) {
        !           270:                case PCI_ACSE:
        !           271:                case PCI_ROSE:
        !           272:                    break;
        !           273: 
        !           274:                default:
        !           275:                    return psaplose (pi, PC_PARAMETER, NULLCP,
        !           276:                                     "illegal value for PCI (%d)",
        !           277:                                     pp -> pc_id);
        !           278:            }
        !           279:            if (pp -> pc_result != PC_ACCEPT)
        !           280:                return psaplose (pi, PC_PARAMETER, NULLCP,
        !           281:                                 "must accept PCI %d", pp -> pc_id);
        !           282:        }
        !           283:     }
        !           284:     if (defctxresult != PC_ACCEPT)
        !           285:        return psaplose (pi, PC_PARAMETER, NULLCP,
        !           286:                         "must accept non-existant default context");
        !           287:     if (prequirements != PR_KERNEL)
        !           288:        return psaplose (pi, PC_PARAMETER, NULLCP,
        !           289:                         "presentation requirements settings not supported");
        !           290:     if (srequirements != SR_DUPLEX)
        !           291:        return psaplose (pi, PC_PARAMETER, NULLCP,
        !           292:                         "session requirements settings not supported");
        !           293:     if (isn != SERIAL_NONE)
        !           294:        return psaplose (pi, PC_PARAMETER, NULLCP,
        !           295:                         "initial serial number not permitted");
        !           296:     if (settings != 0) /* not really an accurate test... */
        !           297:        return psaplose (pi, PC_PARAMETER, NULLCP,
        !           298:                         "initial token settings not permitted");
        !           299:     missingP (ref);
        !           300:     if (ref -> sr_ulen > SREF_USER_SIZE
        !           301:            || ref -> sr_clen > SREF_COMM_SIZE
        !           302:            || ref -> sr_alen > SREF_ADDT_SIZE
        !           303:            || ref -> sr_vlen > 0)
        !           304:        return psaplose (pi, PC_PARAMETER, NULLCP, "bad format for reference");
        !           305:     if (data == NULL || ndata <= 0 || data[0] == NULLPE || ndata > NPDATA_PS)
        !           306:        return psaplose (pi, PC_PARAMETER, NULLCP, "bad initial user data");
        !           307:     if (data[0] -> pe_context != PCI_ACSE)
        !           308:        return psaplose (pi, PC_PARAMETER, NULLCP,
        !           309:                         "wrong context for initial user data");
        !           310:     missingP (pi);
        !           311: 
        !           312:     if ((pdu = (struct type_PS_ConnectResponse__PDU *) malloc (sizeof *pdu))
        !           313:            == NULL) {
        !           314: no_mem: ;
        !           315:        (void) psaplose (pi, PC_CONGEST, NULLCP, "out of memory");
        !           316:        goto out2;
        !           317:     }
        !           318: 
        !           319:     pdu -> reference = pb -> pb_reliability == LOW_QUALITY ? pb -> pb_reference
        !           320:                                                           : NULLRF;
        !           321: 
        !           322:     if (responding && responding -> pa_selectlen > 0) {
        !           323:        if ((pdu -> responding = str2qb (responding -> pa_selector,
        !           324:                                     responding -> pa_selectlen, 1)) == NULL)
        !           325:        goto no_mem;
        !           326:     }
        !           327:     else
        !           328:         pdu -> responding = NULL;
        !           329: 
        !           330:     if (status == PC_REJECTED) {
        !           331:        if ((pdu -> reason = (struct type_PS_Rejection__reason *)
        !           332:                        malloc (sizeof (struct type_PS_Rejection__reason)))
        !           333:                == NULL)
        !           334:            goto no_mem;
        !           335: 
        !           336:        pdu -> reason -> parm =
        !           337:                            int_PS_Rejection__reason_rejected__by__responder;
        !           338:     }
        !           339:     else
        !           340:        pdu -> reason = NULL;
        !           341: 
        !           342:     pdu -> user__data = data[0];
        !           343: 
        !           344:     pe = NULLPE;
        !           345:     result = encode_PS_ConnectResponse__PDU (&pe, 1, 0, NULLCP, pdu);
        !           346: 
        !           347:     pdu -> reference = NULL;
        !           348:     pdu -> user__data = NULLPE;
        !           349:     free_PS_ConnectResponse__PDU (pdu);
        !           350:     pdu = NULL;
        !           351: 
        !           352:     if (result == NOTOK) {
        !           353:        (void) psaplose (pi, PC_CONGEST, NULLCP, "error encoding PDU: %s",
        !           354:                         PY_pepy);
        !           355:        goto out2;
        !           356:     }
        !           357: 
        !           358:     PLOGP (psap2_log,PS_PDUs, pe, "ConnectResponse-PDU", 0);
        !           359: 
        !           360:     result = pe2ps (ps = pb -> pb_stream, pe);
        !           361: 
        !           362:     pe_free (pe);
        !           363: 
        !           364:     if (result == NOTOK) {
        !           365:        result = pslose (pi, ps -> ps_errno);
        !           366:        goto out1;
        !           367:     }
        !           368: 
        !           369:     if (status == PC_ACCEPT)
        !           370:        pb -> pb_flags |= PB_CONN;
        !           371:     else
        !           372:        freepblk (pb);
        !           373: 
        !           374:     return OK;
        !           375: 
        !           376: out2: ;
        !           377:     if (pdu) {
        !           378:        pdu -> reference = NULL;
        !           379:        pdu -> user__data = NULLPE;
        !           380:        free_PS_ConnectResponse__PDU (pdu);
        !           381:     }
        !           382:     if (pe)
        !           383:        pe_free (pe);
        !           384: 
        !           385: out1: ;
        !           386:     freepblk (pb);
        !           387: 
        !           388:     return NOTOK;
        !           389: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.