|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24:
25: /*
26: * Copyright (c) 1996 Apple Computer, Inc.
27: *
28: * The information contained herein is subject to change without
29: * notice and should not be construed as a commitment by Apple
30: * Computer, Inc. Apple Computer, Inc. assumes no responsibility
31: * for any errors that may appear.
32: *
33: * Confidential and Proprietary to Apple Computer, Inc.
34: *
35: * File: open.c
36: */
37: #include <sysglue.h>
38: #include <at/appletalk.h>
39: #include <lap.h>
40: #include <routing_tables.h>
41: #define _AURP
42: #include <at_aurp.h>
43: #include <at/aurp.h>
44:
45: /* */
46: void AURPsndOpenReq(state)
47: aurp_state_t *state;
48: {
49: int msize;
50: gbuf_t *m;
51: aurp_hdr_t *hdrp;
52: char *datp;
53:
54: if (aurp_gref == 0)
55: return;
56: if (state->rcv_retry && (state->rcv_state != AURPSTATE_WaitingForOpenRsp))
57: return;
58:
59: /* stop trying if the retry count exceeds the maximum value */
60: if (++state->rcv_retry > AURP_MaxRetry) {
61: dPrintf(D_M_AURP, D_L_WARNING,
62: ("AURPsndOpenReq: no response, %d\n", state->rem_node));
63: state->rcv_state = AURPSTATE_Unconnected;
64: state->rcv_tmo = 0;
65: state->rcv_retry = 0;
66: return;
67: }
68:
69: msize = sizeof(aurp_hdr_t) + 3;
70: if ((m = (gbuf_t *)gbuf_alloc(msize, PRI_MED)) != 0) {
71: gbuf_wset(m,msize);
72:
73: /* construct the open request packet */
74: hdrp = (aurp_hdr_t *)gbuf_rptr(m);
75: if (state->rcv_retry > 1)
76: hdrp->connection_id = state->rcv_connection_id;
77: else {
78: if (++rcv_connection_id == 0)
79: rcv_connection_id = 1;
80: hdrp->connection_id = rcv_connection_id;
81: }
82: hdrp->sequence_number = 0;
83: hdrp->command_code = AURPCMD_OpenReq;
84: hdrp->flags = (AURPFLG_NA | AURPFLG_ND | AURPFLG_NDC | AURPFLG_ZC);
85: *(short *)(hdrp+1) = AURP_Version;
86: ((char *)(hdrp+1))[2] = 0; /* option count */
87:
88: /* update state info */
89: state->rcv_connection_id = hdrp->connection_id;
90: state->rcv_state = AURPSTATE_WaitingForOpenRsp;
91:
92: /* send the packet */
93: AURPsend(m, AUD_AURP, state->rem_node);
94: }
95:
96: /* start the retry timer */
97: state->rcv_tmo = (void *)atalk_timeout(
98: AURPsndOpenReq, state, AURP_RetryInterval*HZ);
99: }
100:
101: /* */
102: void AURPrcvOpenReq(state, m)
103: aurp_state_t *state;
104: gbuf_t *m;
105: {
106: short rc, version;
107: aurp_hdr_t *hdrp = (aurp_hdr_t *)gbuf_rptr(m);
108: unsigned short sui = hdrp->flags;
109:
110: /* make sure we're in a valid state to accept it */
111: if ((update_tmo == 0) || ((state->snd_state != AURPSTATE_Unconnected) &&
112: (state->snd_state != AURPSTATE_Connected))) {
113: dPrintf(D_M_AURP, D_L_WARNING,
114: ("AURPrcvOpenReq: unexpected request\n"));
115: gbuf_freem(m);
116: return;
117: }
118:
119: /* check for the correct version number */
120: version = *(short *)(hdrp+1);
121: if (version != AURP_Version) {
122: dPrintf(D_M_AURP, D_L_WARNING,
123: ("AURPrcvOpenReq: invalid version number %d\n"));
124: rc = AURPERR_InvalidVersionNumber;
125: } else
126: rc = (short)AURP_UpdateRate;
127:
128: /* construct the open response packet */
129: gbuf_wset(m,sizeof(aurp_hdr_t)+sizeof(short));
130: hdrp->command_code = AURPCMD_OpenRsp;
131: hdrp->flags = 0;
132: *(short *)(hdrp+1) = rc;
133: ((char *)(hdrp+1))[2] = 0; /* option count */
134:
135: /*
136: * reset if we're in the Connected state and this is
137: * a completely new open request
138: */
139: if ((state->snd_state == AURPSTATE_Connected) &&
140: ((state->snd_connection_id != hdrp->connection_id) ||
141: (state->snd_sequence_number != AURP_FirstSeqNum))) {
142: extern void AURPsndTickle();
143: if (state->rcv_state == AURPSTATE_Connected) {
144: state->rcv_state = AURPSTATE_Unconnected;
145: atalk_untimeout(AURPsndTickle, state, 0);
146: }
147: state->snd_state = AURPSTATE_Unconnected;
148: AURPcleanup(state);
149: AURPpurgeri(state->rem_node);
150: }
151:
152: /* update state info */
153: if (state->snd_state == AURPSTATE_Unconnected) {
154: state->snd_state = AURPSTATE_Connected;
155: state->snd_sui = sui;
156: state->snd_connection_id = hdrp->connection_id;
157: state->snd_sequence_number = AURP_FirstSeqNum;
158: }
159:
160: /* send the packet */
161: AURPsend(m, AUD_AURP, state->rem_node);
162:
163: /* open connection for the data receiver side if not yet connected */
164: if (state->rcv_state == AURPSTATE_Unconnected) {
165: state->rcv_retry = 0;
166: state->tickle_retry = 0;
167: state->rcv_sequence_number = 0;
168: AURPsndOpenReq(state);
169: }
170: }
171:
172: /* */
173: void AURPrcvOpenRsp(state, m)
174: aurp_state_t *state;
175: gbuf_t *m;
176: {
177: extern void AURPsndTickle();
178: short rc;
179: aurp_hdr_t *hdrp = (aurp_hdr_t *)gbuf_rptr(m);
180:
181: /* make sure we're in a valid state to accept it */
182: if (state->rcv_state != AURPSTATE_WaitingForOpenRsp) {
183: dPrintf(D_M_AURP, D_L_WARNING,
184: ("AURPrcvOpenRsp: unexpected response\n"));
185: gbuf_freem(m);
186: return;
187: }
188:
189: /* check for the correct connection id */
190: if (hdrp->connection_id != state->rcv_connection_id) {
191: dPrintf(D_M_AURP, D_L_WARNING,
192: ("AURPrcvOpenRsp: invalid connection id, r=%d, m=%d\n",
193: hdrp->connection_id, state->rcv_connection_id));
194: gbuf_freem(m);
195: return;
196: }
197:
198: /* cancel the retry timer */
199: atalk_untimeout(AURPsndOpenReq, state, state->rcv_tmo);
200: state->rcv_tmo = 0;
201: state->rcv_retry = 0;
202:
203: /* update state info */
204: state->rcv_sequence_number = AURP_FirstSeqNum;
205: state->rcv_env = hdrp->flags;
206:
207: /* check for error */
208: rc = *(short *)(hdrp+1);
209: gbuf_freem(m);
210: if (rc < 0) {
211: dPrintf(D_M_AURP, D_L_WARNING,
212: ("AURPrcvOpenRsp: error=%d\n", rc));
213: return;
214: }
215:
216: /* update state info */
217: state->rcv_update_rate = (unsigned short)rc;
218: state->rcv_state = AURPSTATE_Connected;
219:
220: /* start tickle */
221: atalk_timeout(AURPsndTickle, state, AURP_TickleRetryInterval*HZ);
222:
223: /* get routing info */
224: AURPsndRIReq(state);
225: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.