2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
24 * Copyright (c) 1988, 1989 Apple Computer, Inc.
26 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
30 /* static char sccsid[] = "@(#)sip.c: 2.0, 1.3; 10/18/93; Copyright 1988-89, Apple Computer, Inc."; */
33 /****************************************************************/
37 /* System Information Protocol */
40 /****************************************************************/
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.
48 * In A/UX implementation, this implies that /etc/appletalk program will
49 * register the node name on socket DDP_SOCKET_1st_DYNAMIC (128).
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>
59 #include <sys/filedesc.h>
60 #include <sys/fcntl.h>
62 #include <sys/ioctl.h>
63 #include <sys/malloc.h>
64 #include <sys/socket.h>
65 #include <sys/socketvar.h>
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>
77 #define SIP_SYSINFO_CMD 1
78 #define SIP_DATALINK_CMD 6
80 #define SIP_GOOD_RESPONSE 0x1
81 #define SIP_BAD_RESPONSE 0xff
83 #define SIP_DRIVER_VERSION 0x0001
84 #define SIP_RESPONDER_VERSION 0x0001
89 u_short responder_version
;
92 void sip_input(mp
, ifID
)
94 int *ifID
; /* not used */
96 /* Packets arriving here are actually ATP packets, but since
97 * A/UX only send dummy responses, we're implementing responder as
100 register at_ddp_t
*ddp
;
101 register at_atp_t
*atp
;
102 register gbuf_t
*tmp
;
104 sip_userbytes_t ubytes
;
106 ddp
= (at_ddp_t
*)gbuf_rptr(mp
);
108 /* Make sure the packet we got is an ATP packet */
109 if (ddp
->type
!= DDP_ATP
) {
114 /* assuming that the whole packet is in one contiguous buffer */
115 atp
= (at_atp_t
*)ddp
->data
;
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!!
124 if ((tmp
= (gbuf_t
*)ddp_growmsg(mp
, 16)) == NULL
) {
125 /* dont have buffers */
130 /* extra space allocated on the same buffer block */
133 resp
= (u_char
*)gbuf_rptr(tmp
);
135 *(u_short
*)resp
= SIP_DRIVER_VERSION
;
137 ubytes
.response
= SIP_GOOD_RESPONSE
;
139 ubytes
.responder_version
= SIP_RESPONDER_VERSION
;
141 case SIP_DATALINK_CMD
:
142 /* In this case, the magic spell is to send 2 zeroes after
143 * the "AppleTalk driver version".
145 if ((tmp
= (gbuf_t
*)ddp_growmsg(mp
, 4)) == NULL
) {
146 /* dont have buffers */
151 /* extra space allocated on the same buffer block */
154 resp
= (u_char
*)gbuf_rptr(tmp
);
156 *(u_short
*)resp
= SIP_DRIVER_VERSION
;
158 ubytes
.response
= SIP_GOOD_RESPONSE
;
160 ubytes
.responder_version
= SIP_RESPONDER_VERSION
;
163 /* bad request, send a bad command response back */
164 ubytes
.response
= SIP_BAD_RESPONSE
;
166 ubytes
.responder_version
= SIP_RESPONDER_VERSION
;
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
;
178 (void)ddp_output(&mp
, DDP_SOCKET_1st_DYNAMIC
, FALSE
);