]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_OSREFERENCE_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. 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 | |
14 | * agreement. | |
15 | * | |
16 | * Please obtain a copy of the License at | |
17 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
18 | * file. | |
19 | * | |
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. | |
27 | * | |
28 | * @APPLE_LICENSE_OSREFERENCE_HEADER_END@ | |
29 | */ | |
30 | ||
31 | /* | |
32 | * Copyright (c) 1988, 1989 Apple Computer, Inc. | |
33 | * | |
34 | * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX. | |
35 | */ | |
36 | ||
37 | #ifndef lint | |
38 | /* static char sccsid[] = "@(#)sip.c: 2.0, 1.3; 10/18/93; Copyright 1988-89, Apple Computer, Inc."; */ | |
39 | #endif /* lint */ | |
40 | ||
41 | /****************************************************************/ | |
42 | /* */ | |
43 | /* */ | |
44 | /* S I P */ | |
45 | /* System Information Protocol */ | |
46 | /* */ | |
47 | /* */ | |
48 | /****************************************************************/ | |
49 | ||
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. | |
55 | * | |
56 | * In A/UX implementation, this implies that /etc/appletalk program will | |
57 | * register the node name on socket DDP_SOCKET_1st_DYNAMIC (128). | |
58 | */ | |
59 | ||
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> | |
66 | #include <sys/proc.h> | |
67 | #include <sys/filedesc.h> | |
68 | #include <sys/fcntl.h> | |
69 | #include <sys/mbuf.h> | |
70 | #include <sys/ioctl.h> | |
71 | #include <sys/malloc.h> | |
72 | #include <sys/socket.h> | |
73 | #include <sys/socketvar.h> | |
74 | ||
75 | #include <net/if.h> | |
76 | ||
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> | |
84 | ||
85 | #define SIP_SYSINFO_CMD 1 | |
86 | #define SIP_DATALINK_CMD 6 | |
87 | ||
88 | #define SIP_GOOD_RESPONSE 0x1 | |
89 | #define SIP_BAD_RESPONSE 0xff | |
90 | ||
91 | #define SIP_DRIVER_VERSION 0x0001 | |
92 | #define SIP_RESPONDER_VERSION 0x0001 | |
93 | ||
94 | typedef struct { | |
95 | u_char response; | |
96 | u_char unused; | |
97 | u_short responder_version; | |
98 | } sip_userbytes_t; | |
99 | ||
100 | void sip_input(mp, ifID) | |
101 | gbuf_t *mp; | |
102 | int *ifID; /* not used */ | |
103 | { | |
104 | /* Packets arriving here are actually ATP packets, but since | |
105 | * A/UX only send dummy responses, we're implementing responder as | |
106 | * a DDP handler | |
107 | */ | |
108 | register at_ddp_t *ddp; | |
109 | register at_atp_t *atp; | |
110 | register gbuf_t *tmp; | |
111 | u_char *resp; | |
112 | sip_userbytes_t ubytes; | |
113 | ||
114 | ddp = (at_ddp_t *)gbuf_rptr(mp); | |
115 | ||
116 | /* Make sure the packet we got is an ATP packet */ | |
117 | if (ddp->type != DDP_ATP) { | |
118 | gbuf_freem(mp); | |
119 | return; | |
120 | } | |
121 | ||
122 | /* assuming that the whole packet is in one contiguous buffer */ | |
123 | atp = (at_atp_t *)ddp->data; | |
124 | ||
125 | switch(UAL_VALUE_NTOH(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!! | |
131 | */ | |
132 | if ((tmp = (gbuf_t *)ddp_growmsg(mp, 16)) == NULL) { | |
133 | /* dont have buffers */ | |
134 | gbuf_freem(mp); | |
135 | return; | |
136 | } | |
137 | if (tmp == mp) | |
138 | /* extra space allocated on the same buffer block */ | |
139 | resp = atp->data; | |
140 | else | |
141 | resp = (u_char *)gbuf_rptr(tmp); | |
142 | bzero(resp, 16); | |
143 | *(u_short *)resp = htons(SIP_DRIVER_VERSION); | |
144 | ||
145 | ubytes.response = SIP_GOOD_RESPONSE; | |
146 | ubytes.unused = 0; | |
147 | ubytes.responder_version = htons(SIP_RESPONDER_VERSION); | |
148 | break; | |
149 | case SIP_DATALINK_CMD : | |
150 | /* In this case, the magic spell is to send 2 zeroes after | |
151 | * the "AppleTalk driver version". | |
152 | */ | |
153 | if ((tmp = (gbuf_t *)ddp_growmsg(mp, 4)) == NULL) { | |
154 | /* dont have buffers */ | |
155 | gbuf_freem(mp); | |
156 | return; | |
157 | } | |
158 | if (tmp == mp) | |
159 | /* extra space allocated on the same buffer block */ | |
160 | resp = atp->data; | |
161 | else | |
162 | resp = (u_char *)gbuf_rptr(tmp); | |
163 | bzero(resp, 16); | |
164 | *(u_short *)resp = htons(SIP_DRIVER_VERSION); | |
165 | ||
166 | ubytes.response = SIP_GOOD_RESPONSE; | |
167 | ubytes.unused = 0; | |
168 | ubytes.responder_version = htons(SIP_RESPONDER_VERSION); | |
169 | break; | |
170 | default : | |
171 | /* bad request, send a bad command response back */ | |
172 | ubytes.response = SIP_BAD_RESPONSE; | |
173 | ubytes.unused = 0; | |
174 | ubytes.responder_version = htons(SIP_RESPONDER_VERSION); | |
175 | } | |
176 | ||
177 | NET_NET(ddp->dst_net, ddp->src_net); | |
178 | ddp->dst_node = ddp->src_node; | |
179 | ddp->dst_socket = ddp->src_socket; | |
180 | UAL_ASSIGN_HTON(atp->user_bytes, &ubytes); | |
181 | atp->cmd = ATP_CMD_TRESP; | |
182 | atp->eom = 1; | |
183 | atp->sts = 0; | |
184 | atp->bitmap = 0; | |
185 | ||
186 | (void)ddp_output(&mp, DDP_SOCKET_1st_DYNAMIC, FALSE); | |
187 | return; | |
188 | } /* sip_input */ | |
189 |