2  * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 
   4  * @APPLE_LICENSE_HEADER_START@ 
   6  * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved. 
   8  * This file contains Original Code and/or Modifications of Original Code 
   9  * as defined in and that are subject to the Apple Public Source License 
  10  * Version 2.0 (the 'License'). You may not use this file except in 
  11  * compliance with the License. Please obtain a copy of the License at 
  12  * http://www.opensource.apple.com/apsl/ and read it before using this 
  15  * The Original Code and all software distributed under the License are 
  16  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  17  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  18  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 
  19  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  20  * Please see the License for the specific language governing rights and 
  21  * limitations under the License. 
  23  * @APPLE_LICENSE_HEADER_END@ 
  27  *      Copyright (c) 1988, 1989 Apple Computer, Inc.  
  29  *   Modified, March 17, 1997 by Tuyen Nguyen for MacOSX. 
  33 /* static char sccsid[] = "@(#)sip.c: 2.0, 1.3; 10/18/93; Copyright 1988-89, Apple Computer, Inc."; */ 
  36 /****************************************************************/ 
  40 /*                      System Information Protocol             */ 
  43 /****************************************************************/ 
  45 /* System Information Protocol -- implemented to handle Responder 
  46  * Queries.  The queries are ATP requests, but the ATP responses are faked 
  47  * here in a DDP level handler routine.  The responder socket is always 
  48  * the 1st socket in the dynamic socket range (128) and it is assumed 
  49  * that the node will be registered on that socket. 
  51  * In A/UX implementation, this implies that /etc/appletalk program will 
  52  * register the node name on socket DDP_SOCKET_1st_DYNAMIC (128). 
  55 #include <sys/errno.h> 
  56 #include <sys/types.h> 
  57 #include <sys/param.h> 
  58 #include <machine/spl.h> 
  59 #include <sys/systm.h> 
  60 #include <sys/kernel.h> 
  62 #include <sys/filedesc.h> 
  63 #include <sys/fcntl.h> 
  65 #include <sys/ioctl.h> 
  66 #include <sys/malloc.h> 
  67 #include <sys/socket.h> 
  68 #include <sys/socketvar.h> 
  72 #include <netat/appletalk.h> 
  73 #include <netat/ddp.h> 
  74 #include <netat/sysglue.h>  /* nbp.h needs the gbuf definiton */ 
  75 #include <netat/nbp.h> 
  76 #include <netat/at_pcb.h> 
  77 #include <netat/at_var.h> 
  78 #include <netat/atp.h> 
  80 #define SIP_SYSINFO_CMD         1 
  81 #define SIP_DATALINK_CMD        6 
  83 #define SIP_GOOD_RESPONSE       0x1 
  84 #define SIP_BAD_RESPONSE        0xff 
  86 #define SIP_DRIVER_VERSION      0x0001 
  87 #define SIP_RESPONDER_VERSION   0x0001 
  92         u_short responder_version
; 
  95 void sip_input(mp
, ifID
) 
  97      int        *ifID
; /* not used */ 
  99         /* Packets arriving here are actually ATP packets, but since 
 100          * A/UX only send dummy responses, we're implementing responder as 
 103         register at_ddp_t       
*ddp
; 
 104         register at_atp_t       
*atp
; 
 105         register gbuf_t         
*tmp
; 
 107         sip_userbytes_t ubytes
; 
 109         ddp 
= (at_ddp_t 
*)gbuf_rptr(mp
); 
 111         /* Make sure the packet we got is an ATP packet */ 
 112         if (ddp
->type 
!= DDP_ATP
) { 
 117         /* assuming that the whole packet is in one contiguous buffer */ 
 118         atp 
= (at_atp_t 
*)ddp
->data
; 
 120         switch(UAL_VALUE(atp
->user_bytes
)) { 
 121         case SIP_SYSINFO_CMD 
: 
 122                 /* Sending a response with "AppleTalk driver version" (u_short) 
 123                  * followed by 14 zeros will pacify the interpoll. 
 124                  * What?  You don't understand what it means to send 14 zeroes? 
 125                  * Tsk, tsk, look up SIP protocol specs for details!! 
 127                 if ((tmp 
= (gbuf_t 
*)ddp_growmsg(mp
, 16)) == NULL
) { 
 128                         /* dont have buffers */ 
 133                         /* extra space allocated on the same buffer block */ 
 136                         resp 
= (u_char 
*)gbuf_rptr(tmp
); 
 138                 *(u_short 
*)resp 
= SIP_DRIVER_VERSION
; 
 140                 ubytes
.response 
= SIP_GOOD_RESPONSE
; 
 142                 ubytes
.responder_version 
= SIP_RESPONDER_VERSION
; 
 144         case SIP_DATALINK_CMD 
: 
 145                 /* In this case, the magic spell is to send 2 zeroes after 
 146                  * the "AppleTalk driver version". 
 148                 if ((tmp 
= (gbuf_t 
*)ddp_growmsg(mp
, 4)) == NULL
) { 
 149                         /* dont have buffers */ 
 154                         /* extra space allocated on the same buffer block */ 
 157                         resp 
= (u_char 
*)gbuf_rptr(tmp
); 
 159                 *(u_short 
*)resp 
= SIP_DRIVER_VERSION
; 
 161                 ubytes
.response 
= SIP_GOOD_RESPONSE
; 
 163                 ubytes
.responder_version 
= SIP_RESPONDER_VERSION
; 
 166                 /* bad request, send a bad command response back */ 
 167                 ubytes
.response 
= SIP_BAD_RESPONSE
; 
 169                 ubytes
.responder_version 
= SIP_RESPONDER_VERSION
; 
 172         NET_NET(ddp
->dst_net
, ddp
->src_net
); 
 173         ddp
->dst_node 
= ddp
->src_node
; 
 174         ddp
->dst_socket 
= ddp
->src_socket
; 
 175         bcopy((caddr_t
) &ubytes
, (caddr_t
) atp
->user_bytes
, sizeof(ubytes
)); 
 176         atp
->cmd 
= ATP_CMD_TRESP
; 
 181         (void)ddp_output(&mp
, DDP_SOCKET_1st_DYNAMIC
, FALSE
);