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@
23 * Copyright (c) 1995 Apple Computer, Inc.
26 * Created February 20, 1995 by Tuyen Nguyen
27 * Modified for MP, 1996 by Tuyen Nguyen
28 * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX.
31 #include <sys/errno.h>
32 #include <sys/types.h>
33 #include <sys/param.h>
34 #include <machine/spl.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
38 #include <sys/filedesc.h>
39 #include <sys/fcntl.h>
41 #include <sys/ioctl.h>
42 #include <sys/malloc.h>
43 #include <sys/socket.h>
44 #include <sys/socketvar.h>
48 #include <netat/appletalk.h>
49 #include <netat/sysglue.h>
50 #include <netat/at_pcb.h>
51 #include <netat/atp.h>
52 #include <netat/ddp.h>
53 #include <netat/asp.h>
54 #include <netat/at_var.h>
55 #include <netat/debug.h>
58 #define CHK_LOOP(str) { \
59 if (loop_cnt++ > 100) { \
65 #define atpBDSsize (sizeof(struct atpBDS)*ATP_TRESP_MAX)
66 #define aspCMDsize (atpBDSsize+sizeof(struct atp_set_default)+TOTAL_ATP_HDR_SIZE)
67 #define SCBS_PER_BLK 16
68 #define TICKS_PER_SEC HZ
69 #define SESS_TMO_RES 2
70 #define DEF_SESS_TMO 120
71 #define NEXT_SEQ_NUM(x) (x = (x == 65535) ? 0 : (x + 1))
73 #define BAD_REMADDR(addr) \
74 ( (*(long *)&scb->rem_addr != *(long *)&addr) \
75 && ((scb->rem_addr.net != addr.net) \
76 || (scb->rem_addr.node != addr.node)) )
84 void asp_clock_funnel();
89 StaticProc asp_scb_t
*asp_find_scb();
90 StaticProc asp_scb_t
*asp_scb_alloc();
92 StaticProc
void asp_putnext();
93 StaticProc
void asp_iocack();
94 StaticProc
void asp_iocnak();
95 StaticProc
void asp_dequeue_scb();
96 StaticProc
void asp_scb_free();
97 StaticProc
void asp_timout();
98 StaticProc
void asp_untimout();
99 StaticProc
void asp_hangup();
100 StaticProc
void asp_send_tickle();
101 StaticProc
void asp_send_tickle_funnel();
102 StaticProc
void asp_accept();
103 StaticProc
int asp_send_req();
105 extern at_ifaddr_t
*ifID_home
;
106 extern int atp_pidM
[];
107 extern gref_t
*atp_inputQ
[];
108 gbuf_t
*scb_resource_m
= 0;
109 unsigned char asp_inpC
[256];
110 asp_scb_t
*asp_scbQ
[256];
112 static at_retry_t asp_def_retry
= {2, -1, 1};
113 static unsigned char scb_tmo_cnt
;
114 asp_scb_t
*scb_used_list
;
115 static asp_scb_t
*scb_tmo_list
;
116 asp_scb_t
*scb_free_list
;
117 atlock_t aspall_lock
, asptmo_lock
;
123 return (((asp_scb_t
*)gref
->info
)->sess_ioc
? 1 : 0);
133 bzero(asp_inpC
, sizeof(asp_inpC
));
134 bzero(asp_scbQ
, sizeof(asp_scbQ
));
138 * the open routine allocates a state structure
147 * if no asp structure available, return failure
149 if ((scb
= asp_scb_alloc()) == 0)
153 * initialize the gref data structure
155 gref
->info
= (void *)scb
;
156 gref
->readable
= asp_readable
;
159 * initialize the scb data structure
162 scb
->magic_num
= 222;
163 scb
->state
= ASPSTATE_Idle
;
164 scb
->pid
= gref
->pid
;
166 scb
->session_timer
= DEF_SESS_TMO
;
167 scb
->cmd_retry
= asp_def_retry
;
168 ATDISABLE(s
, aspall_lock
);
169 if ((scb
->next_scb
= scb_used_list
) != 0)
170 scb
->next_scb
->prev_scb
= scb
;
172 ATENABLE(s
, aspall_lock
);
177 dPrintf(D_M_ASP
, D_L_INFO
, ("asp_open: pid=%d\n", scb
->pid
));
182 * the close routine frees all the data structures
189 unsigned char sock_num
;
190 asp_scb_t
*scb
, *new_scb
;
193 scb
= (asp_scb_t
*)gref
->info
;
194 dPrintf(D_M_ASP
, D_L_INFO
, ("asp_close: loc=%d\n",
195 scb
->loc_addr
.socket
));
197 if (scb
->pid
&& scb
->sess_ioc
&& (scb
->dflag
!= 1)) {
199 * send the CloseSess response to peer
201 if (gbuf_type(scb
->sess_ioc
) != MSG_PROTO
) {
202 ATDISABLE(s
, scb
->lock
);
204 scb
->sess_ioc
= gbuf_next(m
);
205 ATENABLE(s
, scb
->lock
);
206 atp_send_rsp(scb
->gref
, m
, TRUE
);
210 if (scb
->atp_state
) {
211 sock_num
= scb
->loc_addr
.socket
;
212 ATDISABLE(s
, aspall_lock
);
213 if ((scb
->dflag
!= 1) && scb
->stat_msg
) {
214 untimeout(atp_retry_req
, scb
->stat_msg
);
215 gbuf_freem(scb
->stat_msg
);
218 if (asp_scbQ
[sock_num
]->next_scb
== 0) {
219 asp_scbQ
[sock_num
] = 0;
220 asp_inpC
[sock_num
] = 0;
221 ATENABLE(s
, aspall_lock
);
222 dPrintf(D_M_ASP
, D_L_INFO
,
223 (" : atp_close(), loc=%d\n", scb
->loc_addr
.socket
));
226 asp_inpC
[sock_num
]--;
227 if (scb
== asp_scbQ
[sock_num
]) {
228 new_scb
= scb
->next_scb
;
229 new_scb
->prev_scb
= 0;
230 asp_scbQ
[sock_num
] = new_scb
;
231 new_scb
->atp_state
->atp_gref
= new_scb
->gref
;
232 new_scb
->atp_state
->pid
= new_scb
->pid
;
233 atp_inputQ
[sock_num
] = new_scb
->gref
;
235 if ((scb
->prev_scb
->next_scb
= scb
->next_scb
) != 0)
236 scb
->next_scb
->prev_scb
= scb
->prev_scb
;
239 ATENABLE(s
, aspall_lock
);
242 asp_dequeue_scb(scb
);
245 * free all allocated blocks if any
247 ATDISABLE(s
, scb
->lock
);
249 gbuf_freem(scb
->stat_msg
);
253 gbuf_freel(scb
->sess_ioc
);
257 gbuf_freel(scb
->req_msgq
);
261 scb
->rem_addr
.node
= 0;
262 ATENABLE(s
, scb
->lock
);
268 asp_untimout(asp_hangup
, scb
);
269 untimeout(asp_send_tickle_funnel
, (void *)scb
); /* added for 2225395 */
272 * free the asp session control block
274 scb
->state
= ASPSTATE_Close
;
279 static char *aspStateStr(state
)
282 return ((state
==ASPSTATE_Close
)? "Close":
283 (state
==ASPSTATE_Idle
)? "Idle":
284 (state
==ASPSTATE_WaitingForGetStatusRsp
)? "GetStatusRsp":
285 (state
==ASPSTATE_WaitingForOpenSessRsp
)? "OpenSessRsp":
286 (state
==ASPSTATE_WaitingForCommandRsp
)? "CmdRsp":
287 (state
==ASPSTATE_WaitingForWriteContinue
)? "WriteCont":
288 (state
==ASPSTATE_WaitingForWriteRsp
)? "WriteRsp":
289 (state
==ASPSTATE_WaitingForWriteContinueRsp
)? "WriteContRsp":
290 (state
==ASPSTATE_WaitingForCloseSessRsp
)? "CloseSessRsp":
294 static char *aspCmdStr(aspCmd
)
297 return ((aspCmd
==ASPFUNC_CloseSess
)? "CloseSess":
298 (aspCmd
==ASPFUNC_Command
)? "Command":
299 (aspCmd
==ASPFUNC_GetStatus
)? "GetStatus":
300 (aspCmd
==ASPFUNC_OpenSess
)? "OpenSess":
301 (aspCmd
==ASPFUNC_Tickle
)? "Tickle":
302 (aspCmd
==ASPFUNC_Write
)? "Write":
303 (aspCmd
==ASPFUNC_WriteContinue
)? "WriteContinue":
304 (aspCmd
==ASPFUNC_Attention
)? "Attention":
305 (aspCmd
==ASPFUNC_CmdReply
)? "CmdReply": "unknown");
308 static char *aspIOCStr(aspIOC
)
312 (aspIOC
==ASPIOC_ClientBind
)? "ClientBind":
313 (aspIOC
==ASPIOC_CloseSession
)? "CloseSession":
314 (aspIOC
==ASPIOC_GetLocEntity
)? "GetLocEntity":
315 (aspIOC
==ASPIOC_GetRemEntity
)? "GetRemEntity":
316 (aspIOC
==ASPIOC_GetSession
)? "GetSession":
317 (aspIOC
==ASPIOC_GetStatus
)? "GetStatus":
318 (aspIOC
==ASPIOC_ListenerBind
)? "ListenerBind":
319 (aspIOC
==ASPIOC_OpenSession
)? "OpenSession":
320 (aspIOC
==ASPIOC_StatusBlock
)? "StatusBlock":
321 (aspIOC
==ASPIOC_SetPid
)? "SetPid":
322 (aspIOC
==ASPIOC_GetSessId
)? "GetSessId":
323 (aspIOC
==ASPIOC_EnableSelect
)? "EnableSelect":
324 (aspIOC
==ASPIOC_Look
)? "Look":
331 static char mbuf_str
[100];
336 "dat = %d, prot = %d, ioc = %d, err = %d, hu = %d, ack = %d, nak = %d, ctl = %d",
338 "dat = %d, prot = %d, ioc = %d, ctl = %d",
339 mbstat
.m_mtypes
[MSG_DATA
], mbstat
.m_mtypes
[MSG_PROTO
], mbstat
.m_mtypes
[MSG_IOCTL
],
341 mbstat.m_mtypes[MSG_ERROR], mbstat.m_mtypes[MSG_HANGUP], mbstat.m_mtypes[MSG_IOCACK],
342 mbstat.m_mtypes[MSG_IOCNAK],
344 mbstat
.m_mtypes
[MSG_CTL
]);
345 return(&mbuf_str
[0]);
348 void trace_beg(str
, m
)
353 gbuf_t
*mdata
, *mchain
;
356 for (i
= 0, j
= 0, mdata
= m
, mchain
= m
; mdata
; i
++) {
357 mdata
= gbuf_cont(mdata
);
358 if (!mdata
&& mchain
) {
359 mdata
= gbuf_next(mchain
);
364 dPrintf(D_M_ASP
, D_L_TRACE
,
365 ("%s: %s, m# = %d, c# = %d\n", str
, mbuf_totals(), i
, j
));
371 dPrintf(D_M_ASP
, D_L_TRACE
,
372 (" %s: %s\n", str
, mbuf_totals()));
379 int asp_wput(gref
, m
)
384 unsigned char sockSav
, sock_num
;
385 gbuf_t
*mioc
, *mdata
;
387 asp_scb_t
*scb
, *server_scb
, *curr_scb
;
390 union asp_primitives
*primitives
;
391 asp_status_cmd_t
*status_cmd
;
392 asp_open_cmd_t
*open_cmd
;
395 scb
= (asp_scb_t
*)gref
->info
;
396 if (scb
->dflag
== 0) {
401 if (gbuf_type(m
) != MSG_IOCTL
) {
402 dPrintf(D_M_ASP
, D_L_WARNING
,
403 ("asp_wput: UNKNOWN message, type=%d\n",
410 iocbp
= (ioc_t
*)gbuf_rptr(mioc
);
412 dPrintf(D_M_ASP_LOW
, D_L_INFO
,
413 ("asp_wput: %s, loc=%d, state=%s\n",
414 aspIOCStr(iocbp
->ioc_cmd
), scb
->loc_addr
.socket
,
415 aspStateStr(scb
->state
)));
417 switch (iocbp
->ioc_cmd
) {
418 case ASPIOC_CloseSession
:
419 if ((scb
->state
== ASPSTATE_Close
) || (scb
->rem_addr
.node
== 0))
424 aw
.func
= ASPFUNC_CloseSess
;
425 aw
.param1
= scb
->sess_id
;
427 iocbp
->ioc_private
= (void *)scb
;
428 scb
->ioc_wait
= (unsigned char)(iocbp
->ioc_cmd
& 0xff);
429 iocbp
->ioc_cmd
= AT_ATP_ISSUE_REQUEST
;
430 asp_send_req(gref
, mioc
, &scb
->rem_addr
, &Retry
, &aw
,
431 0, ASPSTATE_WaitingForCloseSessRsp
, 0x01);
434 case ASPIOC_ClientBind
:
436 * open an ATP channel
438 if ((err
= atp_open(gref
, 0)) != 0) {
439 asp_iocnak(gref
, mioc
, err
);
442 scb
->atp_state
= (atp_state_t
*)gref
->info
;
443 scb
->atp_state
->pid
= scb
->pid
;
445 * bind to any available socket
448 sockSav
= scb
->dflag
;
449 if ((sock_num
= (at_socket
)atp_bind(gref
, 0, &sockSav
)) == 0) {
450 scb
->atp_state
= (atp_state_t
*)0;
452 gref
->info
= (void *)scb
;
453 asp_iocnak(gref
, mioc
, EINVAL
);
456 gref
->info
= (void *)scb
;
457 asp_dequeue_scb(scb
);
458 scb
->atp_state
->dflag
= scb
->dflag
;
459 scb
->loc_addr
.socket
= sock_num
;
460 asp_scbQ
[sock_num
] = scb
;
461 asp_inpC
[sock_num
]++;
462 atp_pidM
[sock_num
] = 0;
465 case ASPIOC_ListenerBind
:
467 * open an ATP channel
469 if ((err
= atp_open(gref
, 0)) != 0) {
470 asp_iocnak(gref
, mioc
, err
);
473 scb
->atp_state
= (atp_state_t
*)gref
->info
;
474 scb
->atp_state
->pid
= scb
->pid
;
476 * bind to any available socket
478 if ((sock_num
= (at_socket
)atp_bind(gref
, 0, 0)) == 0) {
479 scb
->atp_state
= (atp_state_t
*)0;
481 gref
->info
= (void *)scb
;
482 asp_iocnak(gref
, mioc
, EINVAL
);
485 gref
->info
= (void *)scb
;
486 asp_dequeue_scb(scb
);
487 scb
->atp_state
->dflag
= scb
->dflag
;
488 scb
->loc_addr
.socket
= sock_num
;
489 asp_scbQ
[sock_num
] = scb
;
490 asp_inpC
[sock_num
]++;
492 *(at_inet_t
*)gbuf_rptr(gbuf_cont(mioc
)) = scb
->loc_addr
;
495 case ASPIOC_GetLocEntity
:
496 if ((gbuf_cont(mioc
) == 0) || (scb
->atp_state
== 0)) {
497 asp_iocnak(gref
, mioc
, EPROTO
);
500 *(at_inet_t
*)gbuf_rptr(gbuf_cont(mioc
)) = scb
->loc_addr
;
503 case ASPIOC_GetRemEntity
:
504 if ((gbuf_cont(mioc
) == 0) || (scb
->atp_state
== 0)) {
505 asp_iocnak(gref
, mioc
, EPROTO
);
508 *(at_inet_t
*)gbuf_rptr(gbuf_cont(mioc
)) = scb
->rem_addr
;
511 case ASPIOC_GetSession
:
512 if ((mdata
= gbuf_cont(mioc
)) == 0) {
513 asp_iocnak(gref
, mioc
, EPROTO
);
516 addr
= (at_inet_t
*)gbuf_rptr(mdata
);
517 scb
->tickle_interval
= (unsigned short)addr
->node
;
518 scb
->session_timer
= addr
->net
;
519 server_scb
= asp_scbQ
[addr
->socket
];
520 /*### LD 10/28/97: changed to make sure we're not accessing a null server_scb */
521 if (server_scb
== 0) {
522 asp_iocnak(gref
, mioc
, EPROTO
);
525 if (server_scb
->sess_ioc
== 0) {
526 asp_iocnak(gref
, mioc
, EPROTO
);
531 * open an ATP channel
533 if ((err
= atp_open(gref
, 0)) != 0) {
534 gref
->info
= (void *)scb
;
535 asp_iocnak(gref
, mioc
, err
);
538 scb
->atp_state
= (atp_state_t
*)gref
->info
;
539 scb
->atp_state
->pid
= scb
->pid
;
541 * bind to any available socket
544 sockSav
= scb
->dflag
;
545 if ((sock_num
= (at_socket
)atp_bind(gref
, 0, &sockSav
)) == 0) {
547 asp_dequeue_scb(scb
);
548 ATDISABLE(s
, aspall_lock
);
550 scb
->loc_addr
.socket
= sock_num
;
551 for (curr_scb
= asp_scbQ
[sock_num
];
552 curr_scb
->next_scb
; curr_scb
= curr_scb
->next_scb
) ;
553 scb
->prev_scb
= curr_scb
;
554 curr_scb
->next_scb
= scb
;
555 scb
->atp_state
= curr_scb
->atp_state
;
556 ATENABLE(s
, aspall_lock
);
558 asp_dequeue_scb(scb
);
559 ATDISABLE(s
, aspall_lock
);
560 scb
->loc_addr
.socket
= sock_num
;
561 asp_scbQ
[sock_num
] = scb
;
562 scb
->atp_state
->dflag
= scb
->dflag
;
563 ATENABLE(s
, aspall_lock
);
565 gref
->info
= (void *)scb
;
566 asp_inpC
[sock_num
]++;
568 asp_accept(server_scb
, scb
, mdata
);
571 case ASPIOC_GetStatus
:
572 if ((mdata
= gbuf_cont(mioc
)) == 0) {
573 asp_iocnak(gref
, mioc
, EINVAL
);
577 status_cmd
= (asp_status_cmd_t
*)gbuf_rptr(mdata
);
578 aw
.func
= ASPFUNC_GetStatus
;
581 scb
->ioc_wait
= (unsigned char)(iocbp
->ioc_cmd
& 0xff);
582 iocbp
->ioc_cmd
= AT_ATP_ISSUE_REQUEST_DEF
;
583 asp_send_req(gref
, mioc
, &status_cmd
->SLSEntityIdentifier
,
584 &status_cmd
->Retry
, &aw
, 1, ASPSTATE_WaitingForGetStatusRsp
, 0xff);
588 case ASPIOC_OpenSession
:
589 if ((mdata
= gbuf_cont(mioc
)) == 0) {
590 asp_iocnak(gref
, mioc
, EINVAL
);
594 open_cmd
= (asp_open_cmd_t
*)gbuf_rptr(mdata
);
595 scb
->svc_addr
= open_cmd
->SLSEntityIdentifier
;
596 scb
->rem_addr
= scb
->svc_addr
;
597 scb
->rem_node
= scb
->rem_addr
.node
;
598 scb
->rem_addr
.node
= 0;
599 scb
->tickle_interval
= open_cmd
->TickleInterval
;
600 scb
->session_timer
= open_cmd
->SessionTimer
;
601 aw
.func
= ASPFUNC_OpenSess
;
602 aw
.param1
= scb
->loc_addr
.socket
;
603 aw
.param2
= ASP_Version
;
604 scb
->ioc_wait
= (unsigned char)(iocbp
->ioc_cmd
& 0xff);
605 iocbp
->ioc_cmd
= AT_ATP_ISSUE_REQUEST_DEF
;
606 asp_send_req(gref
, mioc
, &open_cmd
->SLSEntityIdentifier
,
607 &open_cmd
->Retry
, &aw
, 1, ASPSTATE_WaitingForOpenSessRsp
, 0x01);
611 case ASPIOC_StatusBlock
:
613 * save the server status block
616 gbuf_freem(scb
->stat_msg
);
617 scb
->stat_msg
= gbuf_cont(mioc
);
621 /* *** Does scb->pid get used in a packet header,
622 and if so is it in ASP, or in ATP?
623 If not, do we need this call for anything?
624 (cap does currently use it in _ANS code.)
627 if (gbuf_cont(mioc
) == 0) {
628 asp_iocnak(gref
, mioc
, EINVAL
);
631 scb
->pid
= *(int *)gbuf_rptr(gbuf_cont(mioc
));
634 case ASPIOC_GetSessId
:
635 if (gbuf_cont(mioc
) == 0) {
636 asp_iocnak(gref
, mioc
, EINVAL
);
639 *(gref_t
**)gbuf_rptr(gbuf_cont(mioc
)) = gref
;
643 if (gbuf_cont(mioc
) == 0) {
644 asp_iocnak(gref
, mioc
, EINVAL
);
648 primitives
= (union asp_primitives
*)gbuf_rptr(scb
->sess_ioc
);
649 if (primitives
->Primitive
== ASPFUNC_CmdReply
)
650 *(int *)gbuf_rptr(gbuf_cont(mioc
)) = 0;
652 *(int *)gbuf_rptr(gbuf_cont(mioc
)) = 1;
654 *(int *)gbuf_rptr(gbuf_cont(mioc
)) = -1;
657 case DDP_IOC_GET_CFG
:
659 struct atp_state
*atp
= (struct atp_state
*)gref
->info
;
663 if (gbuf_cont(mioc
) == 0) {
664 asp_iocnak(gref
, mioc
, EINVAL
);
667 /* *** borrowed from ddp_proto.c to handle DDP_IOC_GET_CFG
669 scb
->state
= ASPSTATE_Idle
;
671 /* *** was ddp_get_cfg() *** */
673 (ddp_addr_t
*)gbuf_rptr(gbuf_cont(mioc
));
674 cfgp
->inet
.net
= ifID_home
->ifThisNode
.s_net
;
675 cfgp
->inet
.node
= ifID_home
->ifThisNode
.s_node
;
676 cfgp
->inet
.socket
= atp
->atp_socket_no
;
677 cfgp
->ddptype
= DDP_ATP
;
679 gbuf_wset(gbuf_cont(mioc
), sizeof(at_inet_t
));
684 asp_iocnak(gref
, mioc
, EINVAL
);
688 asp_iocack(gref
, mioc
);
693 * send request routine
696 asp_send_req(gref
, mioc
, dest
, retry
, awp
, xo
, state
, bitmap
)
704 unsigned char bitmap
;
709 struct atp_set_default
*sd
;
712 struct atpBDS
*atpBDS
;
713 asp_scb_t
*scb
= (asp_scb_t
*)gref
->info
;
716 * allocate an ATP buffer for the request
718 if ((gbuf_cont(mioc
) = gbuf_alloc(aspCMDsize
, PRI_MED
)) == 0) {
719 if (awp
->func
== ASPFUNC_Tickle
)
722 asp_iocnak(gref
, mioc
, ENOBUFS
);
723 dPrintf(D_M_ASP
, D_L_WARNING
,
724 ("asp_send_req: ENOBUFS, loc=%d\n", scb
->loc_addr
.socket
));
728 mdata
= gbuf_cont(mioc
);
729 iocbp
= (ioc_t
*)gbuf_rptr(mioc
);
734 atpBDS
= (struct atpBDS
*)gbuf_rptr(mdata
);
735 gbuf_wset(mdata
,atpBDSsize
);
736 for (i
=0; i
< ATP_TRESP_MAX
; i
++) {
737 *(unsigned long *)atpBDS
[i
].bdsBuffAddr
= 1;
738 *(unsigned short *)atpBDS
[i
].bdsBuffSz
= ATP_DATA_SIZE
;
740 sd
= (struct atp_set_default
*)gbuf_wptr(mdata
);
741 gbuf_winc(mdata
,sizeof(struct atp_set_default
));
742 sd
->def_retries
= (retry
->retries
== -1) ?
743 ATP_INFINITE_RETRIES
: retry
->retries
;
744 sd
->def_rate
= retry
->interval
*TICKS_PER_SEC
;
745 sd
->def_BDSlen
= atpBDSsize
;
746 ddp
= (at_ddp_t
*)gbuf_wptr(mdata
);
747 NET_ASSIGN(ddp
->src_net
, scb
->loc_addr
.net
);
748 ddp
->src_node
= scb
->loc_addr
.node
;
749 NET_ASSIGN(ddp
->dst_net
, dest
->net
);
750 ddp
->dst_node
= dest
->node
;
751 ddp
->dst_socket
= dest
->socket
;
752 UAS_ASSIGN(ddp
->checksum
, 0);
753 atp
= ATP_ATP_HDR(gbuf_wptr(mdata
));
756 atp
->bitmap
= bitmap
;
757 gbuf_winc(mdata
,TOTAL_ATP_HDR_SIZE
);
758 *(asp_word_t
*)atp
->user_bytes
= *awp
;
759 iocbp
->ioc_count
= gbuf_len(mdata
);
766 dPrintf(D_M_ASP
, D_L_INFO
,
767 ("asp_send_req: %s, loc=%d, rem= %d, len=%d, state=%s\n",
768 aspCmdStr(awp
->func
),
769 scb
->loc_addr
.socket
, ddp
->dst_socket
, iocbp
->ioc_count
,
770 aspStateStr(scb
->state
)));
772 atp_send_req(gref
, mioc
);
777 * send tickle routine - funnelled version
780 asp_send_tickle_funnel(scb
)
783 thread_funnel_set(network_flock
, TRUE
);
784 asp_send_tickle(scb
);
785 thread_funnel_set(network_flock
, FALSE
);
790 * send tickle routine
803 * make sure the connection is still there
805 if (scb
->rem_addr
.node
== 0) {
809 if ((mioc
= gbuf_alloc(sizeof(ioc_t
), PRI_HI
)) == 0) {
810 dPrintf(D_M_ASP
, D_L_WARNING
,
811 ("asp_send_tickle: ENOBUFS 0, loc=%d, rem=%d\n",
812 scb
->loc_addr
.socket
,scb
->rem_addr
.socket
));
813 timeout(asp_send_tickle_funnel
, (void *)scb
, 10);
816 gbuf_wset(mioc
,sizeof(ioc_t
));
817 gbuf_set_type(mioc
, MSG_IOCTL
);
819 dest
= scb
->svc_addr
.node
?
820 (at_inet_t
*)&scb
->svc_addr
: (at_inet_t
*)&scb
->rem_addr
;
821 retry
.interval
= scb
->tickle_interval
;
824 aw
.func
= ASPFUNC_Tickle
;
825 aw
.param1
= scb
->sess_id
;
827 ((ioc_t
*)gbuf_rptr(mioc
))->ioc_cr
= (void *)scb
;
828 ((ioc_t
*)gbuf_rptr(mioc
))->ioc_cmd
= AT_ATP_ISSUE_REQUEST_TICKLE
;
830 if (asp_send_req(scb
->gref
, mioc
, dest
, &retry
, &aw
, 0, scb
->state
, 0)) {
831 dPrintf(D_M_ASP
, D_L_WARNING
,
832 ("asp_send_tickle: ENOBUFS 1, loc=%d, rem=%d\n",
833 scb
->loc_addr
.socket
,scb
->rem_addr
.socket
));
835 timeout(asp_send_tickle_funnel
, (void *)scb
, 10);
841 * accept connection routine
844 asp_accept(scb
, sess_scb
, m
)
856 mdata
= scb
->sess_ioc
;
857 ddp
= (at_ddp_t
*)gbuf_rptr(mdata
);
858 atp
= (at_atp_t
*)(gbuf_rptr(mdata
) + DDP_X_HDR_SIZE
);
859 rem_addr
.net
= NET_VALUE(ddp
->src_net
);
860 rem_addr
.node
= ddp
->src_node
;
861 rem_addr
.socket
= ddp
->src_socket
;
862 awp
= (asp_word_t
*)atp
->user_bytes
;
864 sess_scb
->loc_addr
.net
= NET_VALUE(ddp
->dst_net
);
865 sess_scb
->loc_addr
.node
= ddp
->dst_node
;
866 NET_ASSIGN(ddp
->src_net
, sess_scb
->loc_addr
.net
);
867 ddp
->src_node
= sess_scb
->loc_addr
.node
;
868 NET_ASSIGN(ddp
->dst_net
, rem_addr
.net
);
869 ddp
->dst_node
= rem_addr
.node
;
870 ddp
->dst_socket
= rem_addr
.socket
;
872 sess_scb
->sess_id
= sess_scb
->loc_addr
.socket
;
873 sess_scb
->rem_socket
= rem_addr
.socket
;
874 sess_scb
->rem_addr
= rem_addr
;
875 sess_scb
->rem_addr
.socket
= awp
->param1
;
876 sess_scb
->reply_socket
= sess_scb
->rem_addr
.socket
;
877 awp
->func
= sess_scb
->loc_addr
.socket
;
878 awp
->param1
= sess_scb
->sess_id
;
881 ATDISABLE(s
, scb
->lock
);
882 scb
->sess_ioc
= gbuf_next(mdata
);
883 ATENABLE(s
, scb
->lock
);
884 gbuf_next(mdata
) = 0;
885 asp_timout(asp_hangup
, sess_scb
, sess_scb
->session_timer
);
886 atp_send_rsp(scb
->gref
, mdata
, TRUE
);
887 asp_send_tickle(sess_scb
);
888 dPrintf(D_M_ASP
, D_L_INFO
,
889 ("asp_accept: ACCEPT connect request, loc=%d, rem=%x.%x.%d\n",
890 sess_scb
->loc_addr
.socket
,
891 sess_scb
->rem_addr
.net
,
892 sess_scb
->rem_addr
.node
,sess_scb
->rem_addr
.socket
));
896 * timer routine - funneled version
898 void asp_clock_funnel(arg
)
901 thread_funnel_set(network_flock
, TRUE
);
903 thread_funnel_set(network_flock
, FALSE
);
916 ATDISABLE(s
, asptmo_lock
);
918 scb_tmo_list
->tmo_delta
--;
919 while (((scb
= scb_tmo_list
) != 0) && (scb_tmo_list
->tmo_delta
== 0)) {
920 if ((scb_tmo_list
= scb
->next_tmo
) != 0)
921 scb_tmo_list
->prev_tmo
= 0;
922 if ((tmo_func
= scb
->tmo_func
) != 0) {
924 ATENABLE(s
, asptmo_lock
);
926 ATDISABLE(s
, asptmo_lock
);
929 ATENABLE(s
, asptmo_lock
);
931 if (++scb_tmo_cnt
== 0) scb_tmo_cnt
++;
932 timeout(asp_clock_funnel
, (void *)arg
, (1<<SESS_TMO_RES
)*TICKS_PER_SEC
);
940 asp_ack_reply(gref
, mioc
)
941 register gref_t
*gref
;
942 register gbuf_t
*mioc
;
945 int len
, msize
, nbds
;
946 register gbuf_t
*mdata
, *m
, *mx
;
947 struct atpBDS
*atpBDS
;
950 register asp_scb_t
*scb
, *sess_scb
;
951 register ioc_t
*iocbp
;
952 register asp_word_t
*awp
;
953 register asp_command_ind_t
*command_ind
;
954 register asp_cmdreply_ind_t
*cmdreply_ind
;
957 iocbp
= (ioc_t
*)gbuf_rptr(mioc
);
959 if (iocbp
->ioc_cmd
== AT_ATP_ISSUE_REQUEST_TICKLE
) {
961 * ignore the ack for the tickle request
963 scb
= (asp_scb_t
*)iocbp
->ioc_cr
;
964 scb
->tickle_tid
= (unsigned short)iocbp
->ioc_rval
;
969 scb
= (asp_scb_t
*)gref
->info
;
975 if (iocbp
->ioc_cmd
== AT_ATP_GET_POLL
) {
977 * if no data, just drop the request
979 if ((mdata
= gbuf_cont(mioc
)) == 0) {
984 gbuf_set_type(mioc
, MSG_IOCTL
);
985 ddp
= (at_ddp_t
*)gbuf_rptr(mdata
);
986 gbuf_rinc(mdata
,DDP_X_HDR_SIZE
);
987 atp
= (at_atp_t
*)gbuf_rptr(mdata
);
988 gbuf_rinc(mdata
,ATP_HDR_SIZE
);
989 rem_addr
.net
= NET_VALUE(ddp
->src_net
);
990 rem_addr
.node
= ddp
->src_node
;
991 rem_addr
.socket
= ddp
->src_socket
;
992 awp
= (asp_word_t
*)atp
->user_bytes
;
996 * find the responsible scb
998 if ((scb
= asp_find_scb(scb
->loc_addr
.socket
, &rem_addr
)) == 0) {
1003 dPrintf(D_M_ASP
, D_L_INFO
,
1004 ("asp_ack_reply: %s, loc=%d, rem=%x.%x.%d\n",
1005 aspCmdStr(awp
->func
),scb
->loc_addr
.socket
,
1006 NET_VALUE(ddp
->src_net
) ,ddp
->src_node
,ddp
->src_socket
));
1008 if (scb
->rem_addr
.node
)
1009 asp_untimout(asp_hangup
, scb
);
1011 switch (awp
->func
) {
1012 case ASPFUNC_GetStatus
:
1014 * ignore if this is not a server socket
1017 if ((scb
->dflag
!= 1) || (scb
->stat_msg
1018 && ((mx
= gbuf_dupb(scb
->stat_msg
)) == 0)))
1023 * send the status block
1025 if (gbuf_cont(mdata
)) {
1026 gbuf_freem(gbuf_cont(mdata
));
1027 gbuf_cont(mdata
) = 0;
1029 gbuf_rdec(mdata
,TOTAL_ATP_HDR_SIZE
);
1030 if ((m
= gbuf_alloc( (TOTAL_ATP_HDR_SIZE
+atpBDSsize
), PRI_MED
)) == 0) {
1035 bcopy(gbuf_rptr(mdata
), gbuf_rptr(m
), TOTAL_ATP_HDR_SIZE
);
1038 ddp
= (at_ddp_t
*)gbuf_rptr(mdata
);
1039 gbuf_wset(mdata
,DDP_X_HDR_SIZE
);
1040 atp
= (at_atp_t
*)gbuf_wptr(mdata
);
1041 gbuf_winc(mdata
,ATP_HDR_SIZE
);
1042 awp
= (asp_word_t
*)atp
->user_bytes
;
1043 NET_NET(ddp
->src_net
, ddp
->dst_net
);
1044 ddp
->src_node
= ddp
->dst_node
;
1045 NET_ASSIGN(ddp
->dst_net
, rem_addr
.net
);
1046 ddp
->dst_node
= rem_addr
.node
;
1047 ddp
->dst_socket
= rem_addr
.socket
;
1048 UAS_ASSIGN(ddp
->checksum
, 0);
1049 atpBDS
= (struct atpBDS
*)gbuf_wptr(mdata
);
1050 msize
= mx
? gbuf_msgsize(mx
) : 0;
1051 for (nbds
=0; (nbds
< ATP_TRESP_MAX
) && (msize
> 0); nbds
++) {
1052 len
= msize
< ATP_DATA_SIZE
? msize
: ATP_DATA_SIZE
;
1053 msize
-= ATP_DATA_SIZE
;
1054 *(long *)atpBDS
[nbds
].bdsUserData
= 0;
1055 UAL_ASSIGN(atpBDS
[nbds
].bdsBuffAddr
, 1);
1056 UAS_ASSIGN(atpBDS
[nbds
].bdsBuffSz
, len
);
1058 UAS_ASSIGN(atpBDS
[0].bdsDataSz
, nbds
);
1059 gbuf_winc(mdata
,atpBDSsize
);
1060 gbuf_cont(mdata
) = mx
;
1061 atp_send_rsp(gref
, mdata
, FALSE
);
1064 case ASPFUNC_OpenSess
:
1066 * ignore if server is not ready
1068 if ((scb
->dflag
!= 1) || (scb
->stat_msg
== 0))
1072 if (gbuf_cont(mdata
)) {
1073 gbuf_freem(gbuf_cont(mdata
));
1074 gbuf_cont(mdata
) = 0;
1076 gbuf_rdec(mdata
,TOTAL_ATP_HDR_SIZE
);
1077 gbuf_wset(mdata
,TOTAL_ATP_HDR_SIZE
);
1078 if (awp
->param2
!= ASP_Version
) {
1080 * bad version number, send the OpenSession response
1084 awp
->param2
= (unsigned short)ASPERR_BadVersNum
;
1085 dPrintf(D_M_ASP
, D_L_INFO
,
1087 ASPERR_BadVersNum
));
1089 NET_NET(ddp
->src_net
, ddp
->dst_net
);
1090 ddp
->src_node
= ddp
->dst_node
;
1091 NET_ASSIGN(ddp
->dst_net
, rem_addr
.net
);
1092 ddp
->dst_node
= rem_addr
.node
;
1093 ddp
->dst_socket
= rem_addr
.socket
;
1094 atp_send_rsp(gref
, mdata
, FALSE
);
1099 * queue the connection request
1101 ATDISABLE(s
, scb
->lock
);
1102 gbuf_next(mdata
) = 0;
1103 if ((m
= scb
->sess_ioc
) == 0) {
1104 scb
->sess_ioc
= mdata
;
1106 thread_wakeup(&scb
->event
);
1108 atalk_notify_sel(gref
);
1110 while (gbuf_next(m
))
1112 gbuf_next(m
) = mdata
;
1114 ATENABLE(s
, scb
->lock
);
1115 dPrintf(D_M_ASP
, D_L_INFO
,
1116 (" : QUEUE connect request\n"));
1120 case ASPFUNC_Command
:
1122 if ( (scb
->sess_id
!= awp
->param1
)
1123 || (scb
->rcv_seq_num
!= awp
->param2
)
1124 || BAD_REMADDR(rem_addr
) ) {
1126 sprintf(era
,"%d.%d", scb
->rem_addr
.node
,scb
->rem_addr
.socket
);
1127 sprintf(ra
,"%d.%d", rem_addr
.node
,rem_addr
.socket
);
1128 dPrintf(D_M_ASP
, D_L_WARNING
,
1129 (" : DROP, id=%d,esn=%d,sn=%d,erem=%s,rem=%s\n",
1130 scb
->sess_id
,scb
->rcv_seq_num
,awp
->param2
,era
,ra
));
1131 gbuf_cont(mioc
) = 0;
1132 gbuf_rdec(mdata
,TOTAL_ATP_HDR_SIZE
);
1133 atp_drop_req(gref
, mdata
);
1136 scb
->reply_socket
= rem_addr
.socket
;
1137 if (awp
->func
== ASPFUNC_Write
)
1138 scb
->wrt_seq_num
= scb
->rcv_seq_num
;
1139 NEXT_SEQ_NUM(scb
->rcv_seq_num
);
1140 gbuf_set_type(mioc
, MSG_PROTO
);
1141 gbuf_wset(mioc
,sizeof(asp_command_ind_t
));
1142 command_ind
= (asp_command_ind_t
*)gbuf_rptr(mioc
);
1143 command_ind
->Primitive
= (int)awp
->func
;
1144 command_ind
->ReqRefNum
=
1145 *(unsigned short *)atp
->tid
;
1146 command_ind
->ReqType
= awp
->func
;
1148 mdata
= gbuf_strip(mdata
);
1149 gbuf_cont(mioc
) = mdata
;
1150 ATDISABLE(s
, scb
->lock
);
1151 if (scb
->req_flag
) {
1152 if ((mx
= scb
->req_msgq
) != 0) {
1153 while (gbuf_next(mx
))
1155 gbuf_next(mx
) = mioc
;
1157 scb
->req_msgq
= mioc
;
1158 ATENABLE(s
, scb
->lock
);
1161 ATENABLE(s
, scb
->lock
);
1162 asp_putnext(scb
->gref
, mioc
);
1166 case ASPFUNC_WriteContinue
:
1167 if ( (scb
->sess_id
!= awp
->param1
)
1168 || (scb
->snd_seq_num
!= awp
->param2
)
1169 || BAD_REMADDR(rem_addr
) ) {
1172 scb
->reply_socket
= rem_addr
.socket
;
1173 gbuf_set_type(mioc
, MSG_PROTO
);
1174 gbuf_wset(mioc
,sizeof(asp_command_ind_t
));
1175 command_ind
= (asp_command_ind_t
*)gbuf_rptr(mioc
);
1176 command_ind
->Primitive
= (int)awp
->func
;
1177 command_ind
->ReqRefNum
=
1178 *(unsigned short *)atp
->tid
;
1179 command_ind
->ReqType
= awp
->func
;
1181 mdata
= gbuf_strip(mdata
);
1182 gbuf_cont(mioc
) = mdata
;
1183 asp_putnext(scb
->gref
, mioc
);
1186 case ASPFUNC_Tickle
:
1187 if (scb
->stat_msg
) {
1188 sess_scb
= asp_scbQ
[awp
->param1
];
1189 if (sess_scb
&& sess_scb
->next_scb
)
1190 sess_scb
= asp_find_scb(
1191 sess_scb
->loc_addr
.socket
, &rem_addr
);
1193 if (sess_scb
->rem_addr
.node
)
1194 asp_untimout(asp_hangup
, sess_scb
);
1195 if (sess_scb
->rem_addr
.node
)
1196 asp_timout(asp_hangup
, sess_scb
, sess_scb
->session_timer
);
1199 dPrintf(D_M_ASP
, D_L_INFO
,
1200 (" : Tickle, %d -> %d, id=%d\n",
1201 ddp
->src_socket
,ddp
->dst_socket
,awp
->param1
));
1204 case ASPFUNC_CloseSess
:
1205 if ( (scb
->sess_id
!= awp
->param1
)
1206 || (scb
->state
== ASPSTATE_Close
)
1207 || (scb
->state
== ASPSTATE_WaitingForCloseSessRsp
)
1208 || (scb
->rem_addr
.net
!= rem_addr
.net
)
1209 || (scb
->rem_addr
.node
!= rem_addr
.node
) ) {
1210 dPrintf(D_M_ASP
, D_L_INFO
,
1211 (" : CLOSE retry, loc=%d, rem=%x.%x.%d\n",
1212 scb
->loc_addr
.socket
,
1215 scb
->rem_addr
.socket
));
1222 * build the CloseSess response to be sent to peer
1223 * when the session is closed by the user.
1225 if (gbuf_cont(mdata
)) {
1226 gbuf_freem(gbuf_cont(mdata
));
1227 gbuf_cont(mdata
) = 0;
1229 gbuf_rdec(mdata
,TOTAL_ATP_HDR_SIZE
);
1230 gbuf_wset(mdata
,TOTAL_ATP_HDR_SIZE
);
1231 NET_NET(ddp
->src_net
, ddp
->dst_net
);
1232 ddp
->src_node
= ddp
->dst_node
;
1233 NET_ASSIGN(ddp
->dst_net
, rem_addr
.net
);
1234 ddp
->dst_node
= rem_addr
.node
;
1235 ddp
->dst_socket
= rem_addr
.socket
;
1239 dPrintf(D_M_ASP
,D_L_INFO
,
1240 (" : CLOSE, loc=%d, rem=%x.%x.%d\n",
1241 scb
->loc_addr
.socket
,
1244 scb
->rem_addr
.socket
));
1246 gbuf_next(mdata
) = 0;
1247 ATDISABLE(s
, scb
->lock
);
1249 gbuf_freel(scb
->sess_ioc
);
1250 scb
->sess_ioc
= mdata
;
1251 scb
->state
= ASPSTATE_Close
;
1252 ATENABLE(s
, scb
->lock
);
1255 * notify upstream of the CloseSess from peer
1260 case ASPFUNC_Attention
:
1261 if ( (scb
->sess_id
!= awp
->param1
)
1262 || (scb
->rem_addr
.net
!= rem_addr
.net
)
1263 || (scb
->rem_addr
.node
!= rem_addr
.node
) ) {
1266 gbuf_set_type(mioc
, MSG_PROTO
);
1267 gbuf_wset(mioc
,sizeof(asp_command_ind_t
));
1268 command_ind
= (asp_command_ind_t
*)gbuf_rptr(mioc
);
1269 command_ind
->Primitive
= (int)awp
->func
;
1270 command_ind
->ReqRefNum
=
1271 *(unsigned short *)atp
->tid
;
1272 command_ind
->ReqType
= awp
->func
;
1273 scb
->attn_tid
= *(unsigned short *)atp
->tid
;
1275 gbuf_rdec(mdata
,2); /* attention code */
1277 mdata
= gbuf_strip(mdata
);
1278 gbuf_cont(mioc
) = mdata
;
1279 asp_putnext(scb
->gref
, mioc
);
1283 dPrintf(D_M_ASP
, D_L_WARNING
,
1284 (" : UNKNOWN func, func=%d\n",
1291 else if (iocbp
->ioc_cmd
== AT_ATP_REQUEST_COMPLETE
) {
1292 if (scb
->next_scb
) {
1294 * find the responsible scb
1296 scb
= (asp_scb_t
*)iocbp
->ioc_private
;
1297 if ((scb
== 0) || (scb
->magic_num
!= 222)) {
1298 dPrintf(D_M_ASP
, D_L_ERROR
,
1299 ("asp_ack_reply: CAN'T find scb 1\n"));
1304 dPrintf(D_M_ASP
, D_L_INFO
,
1305 ("asp_ack_reply: RSP, loc=%d, rem=%x.%x.%d, state=%s\n",
1306 scb
->loc_addr
.socket
,
1309 scb
->rem_addr
.socket
,
1310 aspStateStr(scb
->state
)));
1312 switch (scb
->state
) {
1313 case ASPSTATE_Close
:
1315 scb
->rem_addr
.node
= 0;
1317 ATDISABLE(s
, scb
->lock
);
1319 thread_wakeup(&scb
->event
);
1321 atalk_notify_sel(gref
);
1322 ATENABLE(s
, scb
->lock
);
1325 case ASPSTATE_WaitingForGetStatusRsp
:
1327 scb
->state
= ASPSTATE_Idle
;
1328 mx
= gbuf_cont(mioc
);
1329 gbuf_cont(mioc
) = 0;
1330 mdata
= gbuf_cont(mx
);
1332 iocbp
->ioc_cmd
= ASPIOC_GetStatus
;
1333 iocbp
->ioc_count
= 0;
1334 iocbp
->ioc_rval
= mdata
? gbuf_msgsize(mdata
) : 0;
1336 atalk_putnext(gref
, mioc
);
1337 atalk_putnext(gref
, mdata
);
1340 case ASPSTATE_WaitingForOpenSessRsp
:
1342 scb
->state
= ASPSTATE_Idle
;
1343 mx
= gbuf_cont(mioc
);
1344 gbuf_cont(mioc
) = 0;
1345 if (gbuf_cont(mx
)) {
1346 gbuf_freem(gbuf_cont(mx
));
1349 iocbp
->ioc_cmd
= ASPIOC_OpenSession
;
1350 iocbp
->ioc_rval
= 0;
1351 iocbp
->ioc_count
= 0;
1352 atpBDS
= (struct atpBDS
*)gbuf_rptr(mx
);
1353 awp
= (asp_word_t
*)atpBDS
->bdsUserData
;
1356 asp_iocnak(gref
, mioc
, ECONNREFUSED
);
1358 scb
->rem_addr
.node
= scb
->rem_node
;
1359 scb
->rem_addr
.socket
= awp
->func
;
1360 scb
->sess_id
= awp
->param1
;
1362 atalk_putnext(gref
, mioc
);
1363 asp_timout(asp_hangup
, scb
, scb
->session_timer
);
1364 asp_send_tickle(scb
);
1365 dPrintf(D_M_ASP
, D_L_INFO
,
1366 ("asp_ack_reply: CONNECT, loc=%d, rem=%x.%x.%d\n",
1367 scb
->loc_addr
.socket
,
1370 scb
->rem_addr
.socket
));
1374 case ASPSTATE_WaitingForCommandRsp
:
1375 case ASPSTATE_WaitingForWriteRsp
:
1376 case ASPSTATE_WaitingForWriteContinueRsp
:
1377 if (scb
->rem_addr
.node
)
1378 asp_untimout(asp_hangup
, scb
);
1379 NEXT_SEQ_NUM(scb
->snd_seq_num
);
1380 scb
->state
= ASPSTATE_Idle
;
1381 gbuf_set_type(mioc
, MSG_PROTO
);
1382 mx
= gbuf_cont(mioc
);
1383 mdata
= gbuf_cont(mx
);
1384 gbuf_cont(mioc
) = mdata
;
1385 atpBDS
= (struct atpBDS
*)gbuf_rptr(mx
);
1386 cmdreply_ind
= (asp_cmdreply_ind_t
*)gbuf_rptr(mioc
);
1387 cmdreply_ind
->Primitive
= ASPFUNC_CmdReply
;
1388 cmdreply_ind
->CmdResult
= *(int *)atpBDS
->bdsUserData
;
1389 gbuf_wset(mioc
,sizeof(asp_cmdreply_ind_t
));
1391 asp_putnext(scb
->gref
, mioc
);
1394 case ASPSTATE_WaitingForCloseSessRsp
:
1396 scb
->state
= ASPSTATE_Close
;
1397 scb
->rem_addr
.node
= 0;
1398 iocbp
->ioc_cmd
= ASPIOC_CloseSession
;
1399 iocbp
->ioc_rval
= 0;
1400 if (gbuf_cont(mioc
)) {
1401 gbuf_freem(gbuf_cont(mioc
));
1402 gbuf_cont(mioc
) = 0;
1404 atalk_putnext(scb
->gref
, mioc
);
1405 atp_cancel_req(scb
->gref
, (unsigned int)scb
->tickle_tid
);
1406 scb
->tickle_tid
= 0;
1410 dPrintf(D_M_ASP
, D_L_WARNING
,
1411 (" : UNKNOWN state, state=%s\n",
1412 aspStateStr(scb
->state
)));
1418 if (scb
->next_scb
) {
1420 * find the responsible scb
1422 scb
= (asp_scb_t
*)iocbp
->ioc_cr
;
1423 if ((scb
== 0) || (scb
->magic_num
!= 222)) {
1424 dPrintf(D_M_ASP
, D_L_ERROR
,
1425 ("asp_ack_reply: CAN'T find scb 2\n"));
1431 switch (scb
->state
) {
1432 case ASPSTATE_Close
:
1433 scb
->rem_addr
.node
= 0;
1442 if (scb
->rem_addr
.node
)
1443 asp_timout(asp_hangup
, scb
, scb
->session_timer
);
1444 } /* asp_ack_reply */
1450 asp_nak_reply(gref
, mioc
)
1451 register gref_t
*gref
;
1452 register gbuf_t
*mioc
;
1454 register asp_scb_t
*scb
;
1455 register ioc_t
*iocbp
;
1457 iocbp
= (ioc_t
*)gbuf_rptr(mioc
);
1459 if (iocbp
->ioc_cmd
== AT_ATP_ISSUE_REQUEST_TICKLE
) {
1461 * no tickle, close session
1463 scb
= (asp_scb_t
*)iocbp
->ioc_cr
;
1466 dPrintf(D_M_ASP
, D_L_WARNING
,
1467 ("tickle_nak: loc=%d, rem=%x.%x.%d, state=%s\n",
1468 scb
->loc_addr
.socket
,
1471 scb
->rem_addr
.socket
,
1472 aspStateStr(scb
->state
)));
1477 scb
= (asp_scb_t
*)gref
->info
;
1483 if (iocbp
->ioc_cmd
== AT_ATP_REQUEST_COMPLETE
) {
1484 if (scb
->next_scb
) {
1486 * find the responsible scb
1488 scb
= (asp_scb_t
*)iocbp
->ioc_private
;
1489 if ((scb
== 0) || (scb
->magic_num
!= 222)) {
1490 dPrintf(D_M_ASP
, D_L_ERROR
,
1491 ("asp_nak_reply: CAN'T find scb 1\n"));
1496 dPrintf(D_M_ASP
, D_L_WARNING
,
1497 ("asp_nak_reply: RSP, loc=%d, rem=%x.%x.%d, state=%s\n",
1498 scb
->loc_addr
.socket
,
1501 scb
->rem_addr
.socket
,
1502 aspStateStr(scb
->state
)));
1504 switch (scb
->state
) {
1505 case ASPSTATE_WaitingForGetStatusRsp
:
1506 iocbp
->ioc_cmd
= ASPIOC_GetStatus
;
1509 case ASPSTATE_WaitingForOpenSessRsp
:
1510 iocbp
->ioc_cmd
= ASPIOC_OpenSession
;
1513 case ASPSTATE_WaitingForCommandRsp
:
1514 case ASPSTATE_WaitingForWriteRsp
:
1515 case ASPSTATE_WaitingForWriteContinueRsp
:
1516 scb
->state
= ASPSTATE_Idle
;
1518 /* last remaining use of MSG_ERROR */
1519 gbuf_set_type(mioc
, MSG_ERROR
);
1520 *gbuf_rptr(mioc
) = (u_char
)EPROTO
;
1522 if (gbuf_cont(mioc
)) {
1523 gbuf_freem(gbuf_cont(mioc
));
1524 gbuf_cont(mioc
) = 0;
1527 asp_putnext(scb
->gref
, mioc
);
1530 case ASPSTATE_WaitingForCloseSessRsp
:
1531 scb
->state
= ASPSTATE_Close
;
1533 case ASPSTATE_Close
: /* new for PR-2296832 */
1534 scb
->rem_addr
.node
= 0;
1535 iocbp
->ioc_cmd
= ASPIOC_CloseSession
;
1536 iocbp
->ioc_rval
= 0;
1537 if (gbuf_cont(mioc
)) {
1538 gbuf_freem(gbuf_cont(mioc
));
1539 gbuf_cont(mioc
) = 0;
1541 gbuf_set_type(mioc
, MSG_IOCACK
);
1542 atalk_putnext(scb
->gref
, mioc
);
1549 scb
->state
= ASPSTATE_Idle
;
1550 atalk_putnext(gref
, mioc
);
1554 if (scb
->next_scb
) {
1556 * find the responsible scb
1558 scb
= (asp_scb_t
*)iocbp
->ioc_cr
;
1559 if ((scb
== 0) || (scb
->magic_num
!= 222)) {
1560 dPrintf(D_M_ASP
, D_L_ERROR
,
1561 ("asp_nak_reply: CAN'T find scb 2\n"));
1567 switch (scb
->state
) {
1568 case ASPSTATE_Close
:
1569 scb
->rem_addr
.node
= 0;
1575 } /* asp_nak_reply */
1578 * delete scb from the use list
1581 asp_dequeue_scb(scb
)
1586 ATDISABLE(s
, aspall_lock
);
1587 if (scb
== scb_used_list
) {
1588 if ((scb_used_list
= scb
->next_scb
) != 0)
1589 scb
->next_scb
->prev_scb
= 0;
1591 if ((scb
->prev_scb
->next_scb
= scb
->next_scb
) != 0)
1592 scb
->next_scb
->prev_scb
= scb
->prev_scb
;
1594 ATENABLE(s
, aspall_lock
);
1603 StaticProc asp_scb_t
*
1604 asp_find_scb(sock_num
, rem_addr
)
1605 unsigned char sock_num
;
1606 at_inet_t
*rem_addr
;
1610 asp_scb_t
*alt_scb
= 0;
1612 ATDISABLE(s
, aspall_lock
);
1613 for (scb
= asp_scbQ
[sock_num
]; scb
; scb
= scb
->next_scb
) {
1614 if ((scb
->rem_addr
.net
== rem_addr
->net
)
1615 && (scb
->rem_addr
.node
== rem_addr
->node
)) {
1616 if ((scb
->rem_addr
.socket
== rem_addr
->socket
)
1617 || (scb
->rem_socket
== rem_addr
->socket
))
1619 else if (alt_scb
== 0)
1624 if ((scb
== 0) && ((scb
= alt_scb
) == 0)) {
1625 dPrintf(D_M_ASP
, D_L_ERROR
,
1626 ("asp_find_scb: CAN'T find scb, loc=%d, rem=%x.%x.%d\n",
1632 ATENABLE(s
, aspall_lock
);
1641 asp_timout(func
, scb
, seconds
)
1643 register asp_scb_t
*scb
;
1648 register asp_scb_t
*curr_scb
, *prev_scb
;
1653 scb
->tmo_func
= func
;
1654 scb
->tmo_delta
= (seconds
>>SESS_TMO_RES
);
1655 scb
->tmo_cnt
= scb_tmo_cnt
;
1657 ATDISABLE(s
, asptmo_lock
);
1658 if (scb_tmo_list
== 0) {
1659 scb
->next_tmo
= scb
->prev_tmo
= 0;
1661 ATENABLE(s
, asptmo_lock
);
1666 curr_scb
= scb_tmo_list
;
1670 sum
+= curr_scb
->tmo_delta
;
1671 if (sum
> scb
->tmo_delta
) {
1672 sum
-= curr_scb
->tmo_delta
;
1673 scb
->tmo_delta
-= sum
;
1674 curr_scb
->tmo_delta
-= scb
->tmo_delta
;
1677 prev_scb
= curr_scb
;
1678 if ((curr_scb
= curr_scb
->next_tmo
) == 0) {
1679 scb
->tmo_delta
-= sum
;
1685 scb
->prev_tmo
= prev_scb
;
1686 if ((scb
->next_tmo
= prev_scb
->next_tmo
) != 0)
1687 prev_scb
->next_tmo
->prev_tmo
= scb
;
1688 prev_scb
->next_tmo
= scb
;
1691 scb
->next_tmo
= scb_tmo_list
;
1692 scb_tmo_list
->prev_tmo
= scb
;
1695 ATENABLE(s
, asptmo_lock
);
1702 asp_untimout(func
, scb
)
1704 register asp_scb_t
*scb
;
1708 if ((scb
->tmo_cnt
== scb_tmo_cnt
) || (scb
->tmo_func
== 0))
1711 ATDISABLE(s
, asptmo_lock
);
1712 if (scb_tmo_list
== scb
) {
1713 if ((scb_tmo_list
= scb
->next_tmo
) != 0) {
1714 scb_tmo_list
->prev_tmo
= 0;
1715 scb
->next_tmo
->tmo_delta
+= scb
->tmo_delta
;
1717 } else if (scb
->prev_tmo
) {
1718 if ((scb
->prev_tmo
->next_tmo
= scb
->next_tmo
) != 0) {
1719 scb
->next_tmo
->prev_tmo
= scb
->prev_tmo
;
1720 scb
->next_tmo
->tmo_delta
+= scb
->tmo_delta
;
1725 ATENABLE(s
, asptmo_lock
);
1738 * set the state to Close
1740 ATDISABLE(s
, scb
->lock
);
1741 scb
->state
= ASPSTATE_Close
;
1742 if (scb
->tickle_tid
) {
1743 atp_cancel_req(scb
->gref
, (unsigned int)scb
->tickle_tid
);
1744 scb
->tickle_tid
= 0;
1748 * notify upstream of the hangup
1750 if (scb
->rem_addr
.node
) {
1751 if (scb
->get_wait
) {
1752 thread_wakeup(&scb
->event
);
1753 ATENABLE(s
, scb
->lock
);
1755 ATENABLE(s
, scb
->lock
);
1756 atalk_notify_sel(scb
->gref
);
1759 ATENABLE(s
, scb
->lock
);
1763 asp_iocack(gref
, mioc
)
1767 if (gbuf_cont(mioc
))
1768 ((ioc_t
*)gbuf_rptr(mioc
))->ioc_count
= gbuf_msgsize(gbuf_cont(mioc
));
1770 ((ioc_t
*)gbuf_rptr(mioc
))->ioc_count
= 0;
1772 gbuf_set_type(mioc
, MSG_IOCACK
);
1773 atalk_putnext(gref
, mioc
);
1777 asp_iocnak(gref
, mioc
, err
)
1782 ((ioc_t
*)gbuf_rptr(mioc
))->ioc_count
= 0;
1785 ((ioc_t
*)gbuf_rptr(mioc
))->ioc_error
= err
;
1786 ((ioc_t
*)gbuf_rptr(mioc
))->ioc_rval
= -1;
1787 if (gbuf_cont(mioc
)) {
1788 gbuf_freem(gbuf_cont(mioc
));
1789 gbuf_cont(mioc
) = 0;
1792 gbuf_set_type(mioc
, MSG_IOCNAK
);
1793 atalk_putnext(gref
, mioc
);
1797 * the alloc scb routine
1799 StaticProc asp_scb_t
*
1804 asp_scb_t
*scb
, *scb_array
;
1806 ATDISABLE(s
, aspall_lock
);
1807 if (scb_free_list
== 0) {
1808 if ((m
= gbuf_alloc(SCBS_PER_BLK
*sizeof(asp_scb_t
), PRI_MED
)) == 0)
1810 ATENABLE(s
, aspall_lock
);
1811 return (asp_scb_t
*)0;
1813 bzero((char *)gbuf_rptr(m
), SCBS_PER_BLK
*sizeof(asp_scb_t
));
1814 gbuf_cont(m
) = scb_resource_m
;
1816 scb_array
= (asp_scb_t
*)gbuf_rptr(m
);
1817 for (i
=0; i
< SCBS_PER_BLK
-1; i
++)
1818 scb_array
[i
].next_scb
= (asp_scb_t
*)&scb_array
[i
+1];
1819 scb_array
[i
].next_scb
= 0;
1820 scb_free_list
= (asp_scb_t
*)&scb_array
[0];
1823 scb
= scb_free_list
;
1824 scb_free_list
= scb
->next_scb
;
1825 ATENABLE(s
, aspall_lock
);
1826 ATLOCKINIT(scb
->lock
);
1827 ATLOCKINIT(scb
->delay_lock
);
1828 ATEVENTINIT(scb
->event
);
1829 ATEVENTINIT(scb
->delay_event
);
1835 * the free scb routine
1843 bzero((char *)scb
, sizeof(asp_scb_t
));
1844 ATDISABLE(s
, aspall_lock
);
1845 scb
->next_scb
= scb_free_list
;
1846 scb_free_list
= scb
;
1847 ATENABLE(s
, aspall_lock
);
1851 * routine to pass up receive data
1854 asp_putnext(gref
, mproto
)
1862 scb
= (asp_scb_t
*)gref
->info
;
1865 * queue the message.
1867 ATDISABLE(s
, scb
->lock
);
1868 gbuf_next(mproto
) = 0;
1869 if ((m
= scb
->sess_ioc
) == 0)
1870 scb
->sess_ioc
= mproto
;
1872 while (gbuf_next(m
))
1874 gbuf_next(m
) = mproto
;
1877 if (scb
->rcv_cnt
>= MAX_RCV_CNT
)
1880 if (scb
->get_wait
) {
1881 thread_wakeup(&scb
->event
);
1882 ATENABLE(s
, scb
->lock
);
1883 } else if (mproto
== scb
->sess_ioc
) {
1884 ATENABLE(s
, scb
->lock
);
1885 atalk_notify_sel(gref
);
1887 ATENABLE(s
, scb
->lock
);
1891 * The following two routines are direct entries from system
1892 * calls to allow fast sending and recving of ASP data.
1895 /* in ASPputmsg we expect:
1901 ASPFUNC_WriteContinue
1904 int ASPputmsg(gref
, ctlptr
, datptr
, flags
, errp
)
1912 gbuf_t
*mioc
, *mdata
, *mx
;
1917 int nbds
, result
, msize
, Primitive
;
1918 unsigned char *wptr
;
1919 struct atp_set_default
*sd
;
1922 struct atpBDS
*atpBDS
;
1924 union asp_primitives
*primitives
;
1927 if ((scb
= (asp_scb_t
*)gref
->info
) == 0) {
1928 dPrintf(D_M_ASP
, D_L_ERROR
,
1929 ("ASPputmsg: stale handle=0x%x, pid=%d\n",
1930 (u_int
) gref
, gref
->pid
));
1936 if (scb
->state
== ASPSTATE_Close
)
1938 if (scb
->snd_stop
) {
1944 * copy in the control and data info
1946 if ((err
= copyin((caddr_t
)ctlptr
,
1947 (caddr_t
)&ctlbuf
, sizeof(ctlbuf
))) != 0)
1949 if ((err
= copyin((caddr_t
)datptr
,
1950 (caddr_t
)&datbuf
, sizeof(datbuf
))) != 0)
1954 * allocate buffer and copy in the control content
1956 if (!(mioc
= gbuf_alloc_wait(ctlbuf
.len
, TRUE
))) {
1957 /* error return should not be possible */
1961 gbuf_set_type(mioc
, MSG_IOCTL
); /* for later, in ATP */
1962 gbuf_wset(mioc
, ctlbuf
.len
);
1963 if ((err
= copyin((caddr_t
)ctlbuf
.buf
,
1964 (caddr_t
)gbuf_rptr(mioc
), ctlbuf
.len
)) != 0) {
1969 iocbp
= (ioc_t
*)gbuf_rptr(mioc
);
1970 primitives
= (union asp_primitives
*)gbuf_rptr(mioc
);
1971 Primitive
= primitives
->Primitive
;
1972 dPrintf(D_M_ASP
, D_L_INFO
,
1973 ("ASPputmsg: %s\n", aspCmdStr(Primitive
)));
1976 * allocate buffer and copy in the data content
1978 len
= (Primitive
== ASPFUNC_CmdReply
) ? 0 : aspCMDsize
;
1979 if (!(mdata
= gbuf_alloc_wait(datbuf
.len
+len
, TRUE
))) {
1980 /* error return should not be possible */
1985 gbuf_wset(mdata
,(datbuf
.len
+len
));
1986 gbuf_cont(mioc
) = mdata
;
1987 if ((err
= copyin((caddr_t
)datbuf
.buf
,
1988 (caddr_t
)(gbuf_rptr(mdata
)+len
), datbuf
.len
)) != 0) {
1993 switch (Primitive
) {
1995 case ASPFUNC_Command
:
1997 case ASPFUNC_WriteContinue
:
1998 case ASPFUNC_Attention
:
2000 * build the command/write/write_continue request
2002 wptr
= gbuf_rptr(mdata
);
2003 atpBDS
= (struct atpBDS
*)wptr
;
2005 for (i
=0; i
< ATP_TRESP_MAX
; i
++) {
2006 *(unsigned long *)atpBDS
[i
].bdsBuffAddr
= 1;
2007 *(unsigned short *)atpBDS
[i
].bdsBuffSz
= ATP_DATA_SIZE
;
2009 sd
= (struct atp_set_default
*)wptr
;
2010 wptr
+= sizeof(struct atp_set_default
);
2011 sd
->def_retries
= (scb
->cmd_retry
.retries
== -1) ?
2012 ATP_INFINITE_RETRIES
: scb
->cmd_retry
.retries
;
2013 sd
->def_rate
= scb
->cmd_retry
.interval
*TICKS_PER_SEC
;
2014 sd
->def_BDSlen
= atpBDSsize
;
2015 ddp
= (at_ddp_t
*)wptr
;
2016 NET_ASSIGN(ddp
->src_net
, scb
->loc_addr
.net
);
2017 ddp
->src_node
= scb
->loc_addr
.node
;
2018 NET_ASSIGN(ddp
->dst_net
, scb
->rem_addr
.net
);
2019 ddp
->dst_node
= scb
->rem_addr
.node
;
2020 ddp
->dst_socket
= scb
->rem_addr
.socket
;
2021 UAS_ASSIGN(ddp
->checksum
, 0);
2022 atp
= ATP_ATP_HDR(wptr
);
2023 wptr
+= TOTAL_ATP_HDR_SIZE
;
2027 awp
= (asp_word_t
*)atp
->user_bytes
;
2028 awp
->func
= (unsigned char)Primitive
;
2029 awp
->param1
= scb
->sess_id
;
2030 awp
->param2
= scb
->snd_seq_num
;
2031 iocbp
->ioc_private
= (void *)scb
;
2032 iocbp
->ioc_count
= gbuf_len(mdata
);
2033 iocbp
->ioc_rval
= 0;
2034 iocbp
->ioc_cmd
= AT_ATP_ISSUE_REQUEST_DEF
;
2037 * send the command/write/write_continue/attention request
2039 ATDISABLE(s
, scb
->lock
);
2040 switch (awp
->func
) {
2041 case ASPFUNC_Command
:
2042 scb
->state
= ASPSTATE_WaitingForCommandRsp
;
2045 scb
->state
= ASPSTATE_WaitingForWriteRsp
;
2047 case ASPFUNC_WriteContinue
:
2048 scb
->state
= ASPSTATE_WaitingForWriteContinueRsp
;
2049 awp
->param2
= scb
->wrt_seq_num
;
2051 case ASPFUNC_Attention
:
2052 scb
->state
= ASPSTATE_WaitingForCommandRsp
;
2057 awp
->param2
= *(unsigned short *)gbuf_wptr(mdata
);
2060 ATENABLE(s
, scb
->lock
);
2061 dPrintf(D_M_ASP
,D_L_INFO
,
2062 ("ASPputmsg: %s, loc=%d, rem=%x.%x.%d\n",
2063 (awp
->func
== ASPFUNC_Command
? "CommandReq" :
2064 awp
->func
== ASPFUNC_Write
? "WriteReq" :
2065 awp
->func
== ASPFUNC_WriteContinue
? "WriteContinue" :
2066 "AttentionReq"),scb
->loc_addr
.socket
,
2067 NET_VALUE(ddp
->dst_net
),ddp
->dst_node
,ddp
->dst_socket
));
2068 atp_send_req(gref
, mioc
);
2071 case ASPFUNC_CmdReply
:
2073 ATDISABLE(s
, scb
->lock
);
2074 if (scb
->req_msgq
) {
2076 scb
->req_msgq
= gbuf_next(mx
);
2078 ATENABLE(s
, scb
->lock
);
2079 asp_putnext(scb
->gref
, mx
);
2082 ATENABLE(s
, scb
->lock
);
2084 result
= primitives
->CmdReplyReq
.CmdResult
;
2085 tid
= primitives
->CmdReplyReq
.ReqRefNum
;
2087 /* Re-use the original mioc mbuf to send the response. */
2088 gbuf_rinc(mioc
,sizeof(void *));
2090 ddp
= (at_ddp_t
*)gbuf_wptr(mioc
);
2091 gbuf_winc(mioc
,DDP_X_HDR_SIZE
);
2092 atp
= (at_atp_t
*)gbuf_wptr(mioc
);
2093 gbuf_winc(mioc
,ATP_HDR_SIZE
);
2094 NET_ASSIGN(ddp
->src_net
, scb
->loc_addr
.net
);
2095 ddp
->src_node
= scb
->loc_addr
.node
;
2096 NET_ASSIGN(ddp
->dst_net
, scb
->rem_addr
.net
);
2097 ddp
->dst_node
= scb
->rem_addr
.node
;
2098 ddp
->dst_socket
= scb
->reply_socket
;
2099 ddp
->type
= DDP_ATP
;
2100 UAS_ASSIGN(ddp
->checksum
, 0);
2101 UAS_ASSIGN(atp
->tid
, tid
);
2102 if (scb
->attn_flag
&& (tid
== scb
->attn_tid
)) {
2110 atpBDS
= (struct atpBDS
*)gbuf_wptr(mioc
);
2111 msize
= mdata
? gbuf_msgsize(mdata
) : 0;
2112 for (nbds
=0; (nbds
< ATP_TRESP_MAX
) && (msize
> 0); nbds
++) {
2113 len
= msize
< ATP_DATA_SIZE
? msize
: ATP_DATA_SIZE
;
2114 msize
-= ATP_DATA_SIZE
;
2115 *(long *)atpBDS
[nbds
].bdsUserData
= 0;
2116 UAL_ASSIGN(atpBDS
[nbds
].bdsBuffAddr
, 1);
2117 UAS_ASSIGN(atpBDS
[nbds
].bdsBuffSz
, len
);
2119 UAS_ASSIGN(atpBDS
[0].bdsDataSz
, nbds
);
2120 *(long *)atpBDS
[0].bdsUserData
= (long)result
;
2121 *(long *)atp
->user_bytes
= (long)result
;
2122 gbuf_winc(mioc
,atpBDSsize
);
2123 dPrintf(D_M_ASP
, D_L_INFO
,
2124 ("ASPputmsg: ATP CmdReplyReq, loc=%d, state=%s, msgsize = %d, result = %d, tid = %d\n",
2125 scb
->loc_addr
.socket
, aspStateStr(scb
->state
),
2126 (mdata
? gbuf_msgsize(mdata
) : 0), result
, tid
));
2127 atp_send_rsp(gref
, mioc
, TRUE
);
2131 /* Not an expected ASPFUNC */
2141 ASPgetmsg(gref
, ctlptr
, datptr
, flags
, errp
)
2148 int err
, s
, len
, sum
, rval
;
2149 gbuf_t
*mproto
, *mdata
;
2153 unsigned char get_wait
;
2155 if ((scb
= (asp_scb_t
*)gref
->info
) == 0) {
2156 dPrintf(D_M_ASP
, D_L_ERROR
,
2157 ("ASPgetmsg: stale handle=0x%x, pid=%d\n",
2158 (u_int
) gref
, gref
->pid
));
2164 ATDISABLE(s
, scb
->lock
);
2165 if (scb
->state
== ASPSTATE_Close
) {
2166 ATENABLE(s
, scb
->lock
);
2173 while ((mproto
= scb
->sess_ioc
) == 0) {
2175 err
= tsleep(&scb
->event
, PSOCK
| PCATCH
, "aspgetmsg", 0);
2178 ATENABLE(s
, scb
->lock
);
2182 if (scb
->state
== ASPSTATE_Close
) {
2184 ATENABLE(s
, scb
->lock
);
2188 get_wait
= scb
->get_wait
;
2190 if ((ctlptr
== 0) && (datptr
== 0)) {
2191 ATENABLE(s
, scb
->lock
);
2194 scb
->sess_ioc
= gbuf_next(mproto
);
2195 mdata
= gbuf_cont(mproto
);
2196 ATENABLE(s
, scb
->lock
);
2198 /* last remaining use of MSG_ERROR */
2199 if (gbuf_type(mproto
) == MSG_ERROR
) {
2200 err
= (int)gbuf_rptr(mproto
)[0];
2205 * copy in the control and data info
2207 if ((err
= copyin((caddr_t
)ctlptr
,
2208 (caddr_t
)&ctlbuf
, sizeof(ctlbuf
))) != 0)
2210 if ((err
= copyin((caddr_t
)datptr
,
2211 (caddr_t
)&datbuf
, sizeof(datbuf
))) != 0)
2213 if ((datbuf
.maxlen
< 0) || (datbuf
.maxlen
< gbuf_msgsize(mdata
))) {
2214 ATDISABLE(s
, scb
->lock
);
2215 gbuf_next(mproto
) = scb
->sess_ioc
;
2216 scb
->sess_ioc
= mproto
;
2217 ATENABLE(s
, scb
->lock
);
2221 if (get_wait
== 0) {
2223 * this is a hack to support the select() call.
2224 * we're not supposed to dequeue messages in the Streams
2225 * head's read queue this way; but there is no better way.
2227 ATDISABLE(s
, scb
->lock
);
2228 if (scb
->sess_ioc
== 0) {
2229 ATENABLE(s
, scb
->lock
);
2231 ATENABLE(s
, scb
->lock
);
2232 atalk_notify_sel(gref
);
2237 * copy out the control content and info
2239 ctlbuf
.len
= gbuf_len(mproto
);
2240 if ((err
= copyout((caddr_t
)gbuf_rptr(mproto
),
2241 (caddr_t
)ctlbuf
.buf
, ctlbuf
.len
)) != 0)
2243 if ((err
= copyout((caddr_t
)&ctlbuf
,
2244 (caddr_t
)ctlptr
, sizeof(ctlbuf
))) != 0)
2248 * copy out the data content and info
2250 for (rval
=0, sum
=0; mdata
&& (rval
== 0); mdata
= gbuf_cont(mdata
)) {
2251 len
= gbuf_len(mdata
);
2253 if ((len
+ sum
) > datbuf
.maxlen
) {
2254 len
= datbuf
.maxlen
- sum
;
2257 if ((err
= copyout((caddr_t
)gbuf_rptr(mdata
),
2258 (caddr_t
)&datbuf
.buf
[sum
], len
)) != 0)
2264 if ((err
= copyout((caddr_t
)&datbuf
,
2265 (caddr_t
)datptr
, sizeof(datbuf
))) != 0)
2268 #ifdef APPLETALK_DEBUG
2270 kprintf("ASPgetmsg: null mproto!!!\n");
2275 ATDISABLE(s
, scb
->lock
);
2282 ATENABLE(s
, scb
->lock
);
2286 dPrintf(D_M_ASP
, D_L_ERROR
,
2287 ("ASPgetmsg: err=%d, loc=%d, rem=%x.%x.%d, state=%s\n",
2288 err
, scb
->loc_addr
.socket
,
2290 scb
->rem_addr
.node
, scb
->rem_addr
.socket
,
2291 aspStateStr(scb
->state
)));
2292 ATDISABLE(s
, scb
->lock
);
2293 gbuf_next(mproto
) = scb
->sess_ioc
;
2294 scb
->sess_ioc
= mproto
;
2295 ATENABLE(s
, scb
->lock
);