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