2 * $Id: atp_sreq.c,v 1.3 2001-06-29 14:14:46 rufustfirefly Exp $
4 * Copyright (c) 1990,1991 Regents of The University of Michigan.
7 * Permission to use, copy, modify, and distribute this software and
8 * its documentation for any purpose and without fee is hereby granted,
9 * provided that the above copyright notice appears in all copies and
10 * that both that copyright notice and this permission notice appear
11 * in supporting documentation, and that the name of The University
12 * of Michigan not be used in advertising or publicity pertaining to
13 * distribution of the software without specific, written prior
14 * permission. This software is supplied as is without expressed or
15 * implied warranties of any kind.
17 * Research Systems Unix Group
18 * The University of Michigan
20 * 535 W. William Street
23 * netatalk@itd.umich.edu
28 #endif /* HAVE_CONFIG_H */
32 #include <sys/types.h>
38 #include <netinet/in.h>
39 #include <netatalk/at.h>
40 #include <netatalk/endian.h>
42 #include <atalk/netddp.h>
43 #include <atalk/atp.h>
44 #include <atalk/util.h>
46 #include "atp_internals.h"
49 atp_sreq( ah, atpb, respcount, flags )
50 ATP ah; /* open atp handle */
51 struct atp_block *atpb; /* parameter block */
52 int respcount; /* buffers available for response */
53 u_int8_t flags; /* ATP_XO, ATP_TREL?? */
55 struct atpbuf *req_buf;
59 atp_print_bufuse( ah, "atp_sreq" );
64 if ( atpb->atp_sreqdlen < 4 || atpb->atp_sreqdlen > ATP_MAXDATA
65 || ( respcount < 0 ) || ( respcount > 8 )
66 || ( atpb->atp_sreqto < 0 ) || (( atpb->atp_sreqtries < 1 )
67 && ( atpb->atp_sreqtries != ATP_TRIES_INFINITE ))) {
71 /* clean up any packet fragments left from last request
73 for ( i = 0; i < 8; ++i ) {
74 if ( ah->atph_resppkt[ i ] != NULL ) {
75 atp_free_buf( ah->atph_resppkt[ i ] );
76 ah->atph_resppkt[ i ] = NULL;
80 /* generate bitmap, tid and ctrlinfo
82 atpb->atp_bitmap = ( 1 << respcount ) - 1;
84 /* allocate a new buffer and build request packet
86 if (( req_buf = atp_alloc_buf()) == NULL ) {
89 atp_build_req_packet( req_buf, ah->atph_tid++, flags | ATP_TREQ, atpb );
90 memcpy( &req_buf->atpbuf_addr, atpb->atp_saddr,
91 sizeof( struct sockaddr_at ));
93 /* send the initial request
96 printf( "\n<%d> atp_sreq: sending a %d byte packet ", getpid(),
97 req_buf->atpbuf_dlen );
98 atp_print_addr( " to", atpb->atp_saddr );
100 bprint( req_buf->atpbuf_info.atpbuf_data, req_buf->atpbuf_dlen );
103 gettimeofday( &ah->atph_reqtv, (struct timezone *)0 );
105 if (( random() % 3 ) != 2 ) {
106 #endif /* DROPPACKETS */
107 if ( netddp_sendto( ah->atph_socket, req_buf->atpbuf_info.atpbuf_data,
108 req_buf->atpbuf_dlen, 0, (struct sockaddr *) atpb->atp_saddr,
109 sizeof( struct sockaddr_at )) != req_buf->atpbuf_dlen ) {
110 atp_free_buf( req_buf );
114 } else printf( "<%d> atp_sreq: dropped request\n", getpid() );
115 #endif /* DROPPACKETS */
117 if ( atpb->atp_sreqto != 0 ) {
118 if ( ah->atph_reqpkt != NULL ) {
119 atp_free_buf( ah->atph_reqpkt );
121 ah->atph_reqto = atpb->atp_sreqto;
122 if ( atpb->atp_sreqtries == ATP_TRIES_INFINITE ) {
123 ah->atph_reqtries = ATP_TRIES_INFINITE;
125 /* we already sent one */
126 ah->atph_reqtries = atpb->atp_sreqtries - 1;
128 ah->atph_reqpkt = req_buf;
129 ah->atph_rbitmap = ( 1 << respcount ) - 1;
130 ah->atph_rrespcount = respcount;
132 atp_free_buf( req_buf );
133 ah->atph_rrespcount = 0;