2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
32 * Copyright (c) 1988, 1989 Apple Computer, Inc.
34 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
38 /* static char sccsid[] = "@(#)sip.c: 2.0, 1.3; 10/18/93; Copyright 1988-89, Apple Computer, Inc."; */
41 /****************************************************************/
45 /* System Information Protocol */
48 /****************************************************************/
50 /* System Information Protocol -- implemented to handle Responder
51 * Queries. The queries are ATP requests, but the ATP responses are faked
52 * here in a DDP level handler routine. The responder socket is always
53 * the 1st socket in the dynamic socket range (128) and it is assumed
54 * that the node will be registered on that socket.
56 * In A/UX implementation, this implies that /etc/appletalk program will
57 * register the node name on socket DDP_SOCKET_1st_DYNAMIC (128).
60 #include <sys/errno.h>
61 #include <sys/types.h>
62 #include <sys/param.h>
63 #include <machine/spl.h>
64 #include <sys/systm.h>
65 #include <sys/kernel.h>
67 #include <sys/filedesc.h>
68 #include <sys/fcntl.h>
70 #include <sys/ioctl.h>
71 #include <sys/malloc.h>
72 #include <sys/socket.h>
73 #include <sys/socketvar.h>
77 #include <netat/appletalk.h>
78 #include <netat/ddp.h>
79 #include <netat/sysglue.h> /* nbp.h needs the gbuf definiton */
80 #include <netat/nbp.h>
81 #include <netat/at_pcb.h>
82 #include <netat/at_var.h>
83 #include <netat/atp.h>
85 #define SIP_SYSINFO_CMD 1
86 #define SIP_DATALINK_CMD 6
88 #define SIP_GOOD_RESPONSE 0x1
89 #define SIP_BAD_RESPONSE 0xff
91 #define SIP_DRIVER_VERSION 0x0001
92 #define SIP_RESPONDER_VERSION 0x0001
97 u_short responder_version
;
100 void sip_input(mp
, ifID
)
102 int *ifID
; /* not used */
104 /* Packets arriving here are actually ATP packets, but since
105 * A/UX only send dummy responses, we're implementing responder as
108 register at_ddp_t
*ddp
;
109 register at_atp_t
*atp
;
110 register gbuf_t
*tmp
;
112 sip_userbytes_t ubytes
;
114 ddp
= (at_ddp_t
*)gbuf_rptr(mp
);
116 /* Make sure the packet we got is an ATP packet */
117 if (ddp
->type
!= DDP_ATP
) {
122 /* assuming that the whole packet is in one contiguous buffer */
123 atp
= (at_atp_t
*)ddp
->data
;
125 switch(UAL_VALUE(atp
->user_bytes
)) {
126 case SIP_SYSINFO_CMD
:
127 /* Sending a response with "AppleTalk driver version" (u_short)
128 * followed by 14 zeros will pacify the interpoll.
129 * What? You don't understand what it means to send 14 zeroes?
130 * Tsk, tsk, look up SIP protocol specs for details!!
132 if ((tmp
= (gbuf_t
*)ddp_growmsg(mp
, 16)) == NULL
) {
133 /* dont have buffers */
138 /* extra space allocated on the same buffer block */
141 resp
= (u_char
*)gbuf_rptr(tmp
);
143 *(u_short
*)resp
= SIP_DRIVER_VERSION
;
145 ubytes
.response
= SIP_GOOD_RESPONSE
;
147 ubytes
.responder_version
= SIP_RESPONDER_VERSION
;
149 case SIP_DATALINK_CMD
:
150 /* In this case, the magic spell is to send 2 zeroes after
151 * the "AppleTalk driver version".
153 if ((tmp
= (gbuf_t
*)ddp_growmsg(mp
, 4)) == NULL
) {
154 /* dont have buffers */
159 /* extra space allocated on the same buffer block */
162 resp
= (u_char
*)gbuf_rptr(tmp
);
164 *(u_short
*)resp
= SIP_DRIVER_VERSION
;
166 ubytes
.response
= SIP_GOOD_RESPONSE
;
168 ubytes
.responder_version
= SIP_RESPONDER_VERSION
;
171 /* bad request, send a bad command response back */
172 ubytes
.response
= SIP_BAD_RESPONSE
;
174 ubytes
.responder_version
= SIP_RESPONDER_VERSION
;
177 NET_NET(ddp
->dst_net
, ddp
->src_net
);
178 ddp
->dst_node
= ddp
->src_node
;
179 ddp
->dst_socket
= ddp
->src_socket
;
180 bcopy((caddr_t
) &ubytes
, (caddr_t
) atp
->user_bytes
, sizeof(ubytes
));
181 atp
->cmd
= ATP_CMD_TRESP
;
186 (void)ddp_output(&mp
, DDP_SOCKET_1st_DYNAMIC
, FALSE
);