Annotation of XNU/bsd/netat/ddp_sip.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * The contents of this file constitute Original Code as defined in and
        !             7:  * are subject to the Apple Public Source License Version 1.1 (the
        !             8:  * "License").  You may not use this file except in compliance with the
        !             9:  * License.  Please obtain a copy of the License at
        !            10:  * http://www.apple.com/publicsource and read it before using this file.
        !            11:  * 
        !            12:  * This Original Code and all software distributed under the License are
        !            13:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            14:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            15:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            16:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            17:  * License for the specific language governing rights and limitations
        !            18:  * under the License.
        !            19:  * 
        !            20:  * @APPLE_LICENSE_HEADER_END@
        !            21:  */
        !            22: 
        !            23: /*
        !            24:  *     Copyright (c) 1988, 1989 Apple Computer, Inc. 
        !            25:  *
        !            26:  *   Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
        !            27:  */
        !            28: 
        !            29: #ifndef lint
        !            30: /* static char sccsid[] = "@(#)sip.c: 2.0, 1.3; 10/18/93; Copyright 1988-89, Apple Computer, Inc."; */
        !            31: #endif  /* lint */
        !            32: 
        !            33: /****************************************************************/
        !            34: /*                                                             */
        !            35: /*                                                             */
        !            36: /*                             S I P                           */
        !            37: /*                     System Information Protocol             */
        !            38: /*                                                             */
        !            39: /*                                                             */
        !            40: /****************************************************************/
        !            41: 
        !            42: /* System Information Protocol -- implemented to handle Responder
        !            43:  * Queries.  The queries are ATP requests, but the ATP responses are faked
        !            44:  * here in a DDP level handler routine.  The responder socket is always
        !            45:  * the 1st socket in the dynamic socket range (128) and it is assumed
        !            46:  * that the node will be registered on that socket.
        !            47:  * 
        !            48:  * In A/UX implementation, this implies that /etc/appletalk program will
        !            49:  * register the node name on socket DDP_SOCKET_1st_DYNAMIC (128).
        !            50:  */
        !            51: 
        !            52: #include <sys/errno.h>
        !            53: #include <sys/types.h>
        !            54: #include <sys/param.h>
        !            55: #include <machine/spl.h>
        !            56: #include <sys/systm.h>
        !            57: #include <sys/kernel.h>
        !            58: #include <sys/proc.h>
        !            59: #include <sys/filedesc.h>
        !            60: #include <sys/fcntl.h>
        !            61: #include <sys/mbuf.h>
        !            62: #include <sys/ioctl.h>
        !            63: #include <sys/malloc.h>
        !            64: #include <sys/socket.h>
        !            65: #include <sys/socketvar.h>
        !            66: 
        !            67: #include <net/if.h>
        !            68: 
        !            69: #include <netat/appletalk.h>
        !            70: #include <netat/ddp.h>
        !            71: #include <netat/sysglue.h>  /* nbp.h needs the gbuf definiton */
        !            72: #include <netat/nbp.h>
        !            73: #include <netat/at_pcb.h>
        !            74: #include <netat/at_var.h>
        !            75: #include <netat/atp.h>
        !            76: 
        !            77: #define        SIP_SYSINFO_CMD         1
        !            78: #define        SIP_DATALINK_CMD        6
        !            79: 
        !            80: #define        SIP_GOOD_RESPONSE       0x1
        !            81: #define        SIP_BAD_RESPONSE        0xff
        !            82: 
        !            83: #define        SIP_DRIVER_VERSION      0x0001
        !            84: #define        SIP_RESPONDER_VERSION   0x0001
        !            85: 
        !            86: typedef        struct {
        !            87:        u_char  response;
        !            88:        u_char  unused;
        !            89:        u_short responder_version;
        !            90: } sip_userbytes_t;
        !            91: 
        !            92: void sip_input(mp, ifID)
        !            93:      gbuf_t    *mp;
        !            94:      int       *ifID; /* not used */
        !            95: {
        !            96:        /* Packets arriving here are actually ATP packets, but since
        !            97:         * A/UX only send dummy responses, we're implementing responder as
        !            98:         * a DDP handler
        !            99:         */
        !           100:        register at_ddp_t       *ddp;
        !           101:        register at_atp_t       *atp;
        !           102:        register gbuf_t         *tmp;
        !           103:        u_char          *resp;
        !           104:        sip_userbytes_t ubytes;
        !           105: 
        !           106:        ddp = (at_ddp_t *)gbuf_rptr(mp);
        !           107: 
        !           108:        /* Make sure the packet we got is an ATP packet */
        !           109:        if (ddp->type != DDP_ATP) {
        !           110:                gbuf_freem(mp);
        !           111:                return;
        !           112:        }
        !           113:        
        !           114:        /* assuming that the whole packet is in one contiguous buffer */
        !           115:        atp = (at_atp_t *)ddp->data;
        !           116:        
        !           117:        switch(UAL_VALUE(atp->user_bytes)) {
        !           118:        case SIP_SYSINFO_CMD :
        !           119:                /* Sending a response with "AppleTalk driver version" (u_short)
        !           120:                 * followed by 14 zeros will pacify the interpoll.
        !           121:                 * What?  You don't understand what it means to send 14 zeroes?
        !           122:                 * Tsk, tsk, look up SIP protocol specs for details!!
        !           123:                 */
        !           124:                if ((tmp = (gbuf_t *)ddp_growmsg(mp, 16)) == NULL) {
        !           125:                        /* dont have buffers */
        !           126:                        gbuf_freem(mp);
        !           127:                        return;
        !           128:                }
        !           129:                if (tmp == mp) 
        !           130:                        /* extra space allocated on the same buffer block */
        !           131:                        resp = atp->data;
        !           132:                else
        !           133:                        resp = (u_char *)gbuf_rptr(tmp);
        !           134:                bzero(resp, 16);
        !           135:                *(u_short *)resp = SIP_DRIVER_VERSION;
        !           136: 
        !           137:                ubytes.response = SIP_GOOD_RESPONSE;
        !           138:                ubytes.unused = 0;
        !           139:                ubytes.responder_version = SIP_RESPONDER_VERSION;
        !           140:                break;
        !           141:        case SIP_DATALINK_CMD :
        !           142:                /* In this case, the magic spell is to send 2 zeroes after
        !           143:                 * the "AppleTalk driver version".
        !           144:                 */
        !           145:                if ((tmp = (gbuf_t *)ddp_growmsg(mp, 4)) == NULL) {
        !           146:                        /* dont have buffers */
        !           147:                        gbuf_freem(mp);
        !           148:                        return;
        !           149:                }
        !           150:                if (tmp == mp) 
        !           151:                        /* extra space allocated on the same buffer block */
        !           152:                        resp = atp->data;
        !           153:                else
        !           154:                        resp = (u_char *)gbuf_rptr(tmp);
        !           155:                bzero(resp, 16);
        !           156:                *(u_short *)resp = SIP_DRIVER_VERSION;
        !           157: 
        !           158:                ubytes.response = SIP_GOOD_RESPONSE;
        !           159:                ubytes.unused = 0;
        !           160:                ubytes.responder_version = SIP_RESPONDER_VERSION;
        !           161:                break;
        !           162:        default :
        !           163:                /* bad request, send a bad command response back */
        !           164:                ubytes.response = SIP_BAD_RESPONSE;
        !           165:                ubytes.unused = 0;
        !           166:                ubytes.responder_version = SIP_RESPONDER_VERSION;
        !           167:        }
        !           168: 
        !           169:        NET_NET(ddp->dst_net, ddp->src_net);
        !           170:        ddp->dst_node = ddp->src_node;
        !           171:        ddp->dst_socket = ddp->src_socket;
        !           172:        bcopy((caddr_t) &ubytes, (caddr_t) atp->user_bytes, sizeof(ubytes));
        !           173:        atp->cmd = ATP_CMD_TRESP;
        !           174:        atp->eom = 1;
        !           175:        atp->sts = 0;
        !           176:        atp->bitmap = 0;
        !           177: 
        !           178:        (void)ddp_output(&mp, DDP_SOCKET_1st_DYNAMIC, FALSE);
        !           179:        return;
        !           180: } /* sip_input */
        !           181: 

unix.superglobalmegacorp.com

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