2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1988, 1989 Apple Computer, Inc.
27 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
31 /* static char sccsid[] = "@(#)sip.c: 2.0, 1.3; 10/18/93; Copyright 1988-89, Apple Computer, Inc."; */
34 /****************************************************************/
38 /* System Information Protocol */
41 /****************************************************************/
43 /* System Information Protocol -- implemented to handle Responder
44 * Queries. The queries are ATP requests, but the ATP responses are faked
45 * here in a DDP level handler routine. The responder socket is always
46 * the 1st socket in the dynamic socket range (128) and it is assumed
47 * that the node will be registered on that socket.
49 * In A/UX implementation, this implies that /etc/appletalk program will
50 * register the node name on socket DDP_SOCKET_1st_DYNAMIC (128).
53 #include <sys/errno.h>
54 #include <sys/types.h>
55 #include <sys/param.h>
56 #include <machine/spl.h>
57 #include <sys/systm.h>
58 #include <sys/kernel.h>
60 #include <sys/filedesc.h>
61 #include <sys/fcntl.h>
63 #include <sys/ioctl.h>
64 #include <sys/malloc.h>
65 #include <sys/socket.h>
66 #include <sys/socketvar.h>
70 #include <netat/appletalk.h>
71 #include <netat/ddp.h>
72 #include <netat/sysglue.h> /* nbp.h needs the gbuf definiton */
73 #include <netat/nbp.h>
74 #include <netat/at_pcb.h>
75 #include <netat/at_var.h>
76 #include <netat/atp.h>
78 #define SIP_SYSINFO_CMD 1
79 #define SIP_DATALINK_CMD 6
81 #define SIP_GOOD_RESPONSE 0x1
82 #define SIP_BAD_RESPONSE 0xff
84 #define SIP_DRIVER_VERSION 0x0001
85 #define SIP_RESPONDER_VERSION 0x0001
90 u_short responder_version
;
93 void sip_input(mp
, ifID
)
95 int *ifID
; /* not used */
97 /* Packets arriving here are actually ATP packets, but since
98 * A/UX only send dummy responses, we're implementing responder as
101 register at_ddp_t
*ddp
;
102 register at_atp_t
*atp
;
103 register gbuf_t
*tmp
;
105 sip_userbytes_t ubytes
;
107 ddp
= (at_ddp_t
*)gbuf_rptr(mp
);
109 /* Make sure the packet we got is an ATP packet */
110 if (ddp
->type
!= DDP_ATP
) {
115 /* assuming that the whole packet is in one contiguous buffer */
116 atp
= (at_atp_t
*)ddp
->data
;
118 switch(UAL_VALUE(atp
->user_bytes
)) {
119 case SIP_SYSINFO_CMD
:
120 /* Sending a response with "AppleTalk driver version" (u_short)
121 * followed by 14 zeros will pacify the interpoll.
122 * What? You don't understand what it means to send 14 zeroes?
123 * Tsk, tsk, look up SIP protocol specs for details!!
125 if ((tmp
= (gbuf_t
*)ddp_growmsg(mp
, 16)) == NULL
) {
126 /* dont have buffers */
131 /* extra space allocated on the same buffer block */
134 resp
= (u_char
*)gbuf_rptr(tmp
);
136 *(u_short
*)resp
= SIP_DRIVER_VERSION
;
138 ubytes
.response
= SIP_GOOD_RESPONSE
;
140 ubytes
.responder_version
= SIP_RESPONDER_VERSION
;
142 case SIP_DATALINK_CMD
:
143 /* In this case, the magic spell is to send 2 zeroes after
144 * the "AppleTalk driver version".
146 if ((tmp
= (gbuf_t
*)ddp_growmsg(mp
, 4)) == NULL
) {
147 /* dont have buffers */
152 /* extra space allocated on the same buffer block */
155 resp
= (u_char
*)gbuf_rptr(tmp
);
157 *(u_short
*)resp
= SIP_DRIVER_VERSION
;
159 ubytes
.response
= SIP_GOOD_RESPONSE
;
161 ubytes
.responder_version
= SIP_RESPONDER_VERSION
;
164 /* bad request, send a bad command response back */
165 ubytes
.response
= SIP_BAD_RESPONSE
;
167 ubytes
.responder_version
= SIP_RESPONDER_VERSION
;
170 NET_NET(ddp
->dst_net
, ddp
->src_net
);
171 ddp
->dst_node
= ddp
->src_node
;
172 ddp
->dst_socket
= ddp
->src_socket
;
173 bcopy((caddr_t
) &ubytes
, (caddr_t
) atp
->user_bytes
, sizeof(ubytes
));
174 atp
->cmd
= ATP_CMD_TRESP
;
179 (void)ddp_output(&mp
, DDP_SOCKET_1st_DYNAMIC
, FALSE
);