]> git.saurik.com Git - apple/xnu.git/blob - bsd/netat/ddp_sip.c
xnu-344.49.tar.gz
[apple/xnu.git] / bsd / netat / ddp_sip.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
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
13 * file.
14 *
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.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25
26 /*
27 * Copyright (c) 1988, 1989 Apple Computer, Inc.
28 *
29 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
30 */
31
32 #ifndef lint
33 /* static char sccsid[] = "@(#)sip.c: 2.0, 1.3; 10/18/93; Copyright 1988-89, Apple Computer, Inc."; */
34 #endif /* lint */
35
36 /****************************************************************/
37 /* */
38 /* */
39 /* S I P */
40 /* System Information Protocol */
41 /* */
42 /* */
43 /****************************************************************/
44
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.
50 *
51 * In A/UX implementation, this implies that /etc/appletalk program will
52 * register the node name on socket DDP_SOCKET_1st_DYNAMIC (128).
53 */
54
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>
61 #include <sys/proc.h>
62 #include <sys/filedesc.h>
63 #include <sys/fcntl.h>
64 #include <sys/mbuf.h>
65 #include <sys/ioctl.h>
66 #include <sys/malloc.h>
67 #include <sys/socket.h>
68 #include <sys/socketvar.h>
69
70 #include <net/if.h>
71
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>
79
80 #define SIP_SYSINFO_CMD 1
81 #define SIP_DATALINK_CMD 6
82
83 #define SIP_GOOD_RESPONSE 0x1
84 #define SIP_BAD_RESPONSE 0xff
85
86 #define SIP_DRIVER_VERSION 0x0001
87 #define SIP_RESPONDER_VERSION 0x0001
88
89 typedef struct {
90 u_char response;
91 u_char unused;
92 u_short responder_version;
93 } sip_userbytes_t;
94
95 void sip_input(mp, ifID)
96 gbuf_t *mp;
97 int *ifID; /* not used */
98 {
99 /* Packets arriving here are actually ATP packets, but since
100 * A/UX only send dummy responses, we're implementing responder as
101 * a DDP handler
102 */
103 register at_ddp_t *ddp;
104 register at_atp_t *atp;
105 register gbuf_t *tmp;
106 u_char *resp;
107 sip_userbytes_t ubytes;
108
109 ddp = (at_ddp_t *)gbuf_rptr(mp);
110
111 /* Make sure the packet we got is an ATP packet */
112 if (ddp->type != DDP_ATP) {
113 gbuf_freem(mp);
114 return;
115 }
116
117 /* assuming that the whole packet is in one contiguous buffer */
118 atp = (at_atp_t *)ddp->data;
119
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!!
126 */
127 if ((tmp = (gbuf_t *)ddp_growmsg(mp, 16)) == NULL) {
128 /* dont have buffers */
129 gbuf_freem(mp);
130 return;
131 }
132 if (tmp == mp)
133 /* extra space allocated on the same buffer block */
134 resp = atp->data;
135 else
136 resp = (u_char *)gbuf_rptr(tmp);
137 bzero(resp, 16);
138 *(u_short *)resp = SIP_DRIVER_VERSION;
139
140 ubytes.response = SIP_GOOD_RESPONSE;
141 ubytes.unused = 0;
142 ubytes.responder_version = SIP_RESPONDER_VERSION;
143 break;
144 case SIP_DATALINK_CMD :
145 /* In this case, the magic spell is to send 2 zeroes after
146 * the "AppleTalk driver version".
147 */
148 if ((tmp = (gbuf_t *)ddp_growmsg(mp, 4)) == NULL) {
149 /* dont have buffers */
150 gbuf_freem(mp);
151 return;
152 }
153 if (tmp == mp)
154 /* extra space allocated on the same buffer block */
155 resp = atp->data;
156 else
157 resp = (u_char *)gbuf_rptr(tmp);
158 bzero(resp, 16);
159 *(u_short *)resp = SIP_DRIVER_VERSION;
160
161 ubytes.response = SIP_GOOD_RESPONSE;
162 ubytes.unused = 0;
163 ubytes.responder_version = SIP_RESPONDER_VERSION;
164 break;
165 default :
166 /* bad request, send a bad command response back */
167 ubytes.response = SIP_BAD_RESPONSE;
168 ubytes.unused = 0;
169 ubytes.responder_version = SIP_RESPONDER_VERSION;
170 }
171
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;
177 atp->eom = 1;
178 atp->sts = 0;
179 atp->bitmap = 0;
180
181 (void)ddp_output(&mp, DDP_SOCKET_1st_DYNAMIC, FALSE);
182 return;
183 } /* sip_input */
184