2 * Copyright (c) 1990,1991 Regents of The University of Michigan.
5 * Permission to use, copy, modify, and distribute this software and
6 * its documentation for any purpose and without fee is hereby granted,
7 * provided that the above copyright notice appears in all copies and
8 * that both that copyright notice and this permission notice appear
9 * in supporting documentation, and that the name of The University
10 * of Michigan not be used in advertising or publicity pertaining to
11 * distribution of the software without specific, written prior
12 * permission. This software is supplied as is without expressed or
13 * implied warranties of any kind.
15 * Research Systems Unix Group
16 * The University of Michigan
18 * 535 W. William Street
21 * netatalk@itd.umich.edu
26 #include <sys/types.h>
32 #include <netinet/in.h>
33 #include <netatalk/at.h>
34 #include <netatalk/endian.h>
36 #include <atalk/netddp.h>
37 #include <atalk/atp.h>
38 #include <atalk/util.h>
40 #include "atp_internals.h"
43 atp_sreq( ah, atpb, respcount, flags )
44 ATP ah; /* open atp handle */
45 struct atp_block *atpb; /* parameter block */
46 int respcount; /* buffers available for response */
47 u_int8_t flags; /* ATP_XO, ATP_TREL?? */
49 struct atpbuf *req_buf;
53 atp_print_bufuse( ah, "atp_sreq" );
58 if ( atpb->atp_sreqdlen < 4 || atpb->atp_sreqdlen > ATP_MAXDATA
59 || ( respcount < 0 ) || ( respcount > 8 )
60 || ( atpb->atp_sreqto < 0 ) || (( atpb->atp_sreqtries < 1 )
61 && ( atpb->atp_sreqtries != ATP_TRIES_INFINITE ))) {
65 /* clean up any packet fragments left from last request
67 for ( i = 0; i < 8; ++i ) {
68 if ( ah->atph_resppkt[ i ] != NULL ) {
69 atp_free_buf( ah->atph_resppkt[ i ] );
70 ah->atph_resppkt[ i ] = NULL;
74 /* generate bitmap, tid and ctrlinfo
76 atpb->atp_bitmap = ( 1 << respcount ) - 1;
78 /* allocate a new buffer and build request packet
80 if (( req_buf = atp_alloc_buf()) == NULL ) {
83 atp_build_req_packet( req_buf, ah->atph_tid++, flags | ATP_TREQ, atpb );
84 memcpy( &req_buf->atpbuf_addr, atpb->atp_saddr,
85 sizeof( struct sockaddr_at ));
87 /* send the initial request
90 printf( "\n<%d> atp_sreq: sending a %d byte packet ", getpid(),
91 req_buf->atpbuf_dlen );
92 atp_print_addr( " to", atpb->atp_saddr );
94 bprint( req_buf->atpbuf_info.atpbuf_data, req_buf->atpbuf_dlen );
97 gettimeofday( &ah->atph_reqtv, (struct timezone *)0 );
99 if (( random() % 3 ) != 2 ) {
101 if ( netddp_sendto( ah->atph_socket, req_buf->atpbuf_info.atpbuf_data,
102 req_buf->atpbuf_dlen, 0, (struct sockaddr *) atpb->atp_saddr,
103 sizeof( struct sockaddr_at )) != req_buf->atpbuf_dlen ) {
104 atp_free_buf( req_buf );
108 } else printf( "<%d> atp_sreq: dropped request\n", getpid() );
111 if ( atpb->atp_sreqto != 0 ) {
112 if ( ah->atph_reqpkt != NULL ) {
113 atp_free_buf( ah->atph_reqpkt );
115 ah->atph_reqto = atpb->atp_sreqto;
116 if ( atpb->atp_sreqtries == ATP_TRIES_INFINITE ) {
117 ah->atph_reqtries = ATP_TRIES_INFINITE;
119 /* we already sent one */
120 ah->atph_reqtries = atpb->atp_sreqtries - 1;
122 ah->atph_reqpkt = req_buf;
123 ah->atph_rbitmap = ( 1 << respcount ) - 1;
124 ah->atph_rrespcount = respcount;
126 atp_free_buf( req_buf );
127 ah->atph_rrespcount = 0;