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
30 #include <sys/types.h>
36 #include <netinet/in.h>
37 #include <netatalk/at.h>
38 #include <netatalk/endian.h>
40 #include <atalk/netddp.h>
41 #include <atalk/atp.h>
42 #include <atalk/util.h>
44 #include "atp_internals.h"
47 atp_sreq( ah, atpb, respcount, flags )
48 ATP ah; /* open atp handle */
49 struct atp_block *atpb; /* parameter block */
50 int respcount; /* buffers available for response */
51 u_int8_t flags; /* ATP_XO, ATP_TREL?? */
53 struct atpbuf *req_buf;
57 atp_print_bufuse( ah, "atp_sreq" );
62 if ( atpb->atp_sreqdlen < 4 || atpb->atp_sreqdlen > ATP_MAXDATA
63 || ( respcount < 0 ) || ( respcount > 8 )
64 || ( atpb->atp_sreqto < 0 ) || (( atpb->atp_sreqtries < 1 )
65 && ( atpb->atp_sreqtries != ATP_TRIES_INFINITE ))) {
69 /* clean up any packet fragments left from last request
71 for ( i = 0; i < 8; ++i ) {
72 if ( ah->atph_resppkt[ i ] != NULL ) {
73 atp_free_buf( ah->atph_resppkt[ i ] );
74 ah->atph_resppkt[ i ] = NULL;
78 /* generate bitmap, tid and ctrlinfo
80 atpb->atp_bitmap = ( 1 << respcount ) - 1;
82 /* allocate a new buffer and build request packet
84 if (( req_buf = atp_alloc_buf()) == NULL ) {
87 atp_build_req_packet( req_buf, ah->atph_tid++, flags | ATP_TREQ, atpb );
88 memcpy( &req_buf->atpbuf_addr, atpb->atp_saddr,
89 sizeof( struct sockaddr_at ));
91 /* send the initial request
94 printf( "\n<%d> atp_sreq: sending a %d byte packet ", getpid(),
95 req_buf->atpbuf_dlen );
96 atp_print_addr( " to", atpb->atp_saddr );
98 bprint( req_buf->atpbuf_info.atpbuf_data, req_buf->atpbuf_dlen );
101 gettimeofday( &ah->atph_reqtv, (struct timezone *)0 );
103 if (( random() % 3 ) != 2 ) {
105 if ( netddp_sendto( ah->atph_socket, req_buf->atpbuf_info.atpbuf_data,
106 req_buf->atpbuf_dlen, 0, (struct sockaddr *) atpb->atp_saddr,
107 sizeof( struct sockaddr_at )) != req_buf->atpbuf_dlen ) {
108 atp_free_buf( req_buf );
112 } else printf( "<%d> atp_sreq: dropped request\n", getpid() );
115 if ( atpb->atp_sreqto != 0 ) {
116 if ( ah->atph_reqpkt != NULL ) {
117 atp_free_buf( ah->atph_reqpkt );
119 ah->atph_reqto = atpb->atp_sreqto;
120 if ( atpb->atp_sreqtries == ATP_TRIES_INFINITE ) {
121 ah->atph_reqtries = ATP_TRIES_INFINITE;
123 /* we already sent one */
124 ah->atph_reqtries = atpb->atp_sreqtries - 1;
126 ah->atph_reqpkt = req_buf;
127 ah->atph_rbitmap = ( 1 << respcount ) - 1;
128 ah->atph_rrespcount = respcount;
130 atp_free_buf( req_buf );
131 ah->atph_rrespcount = 0;