1 /*********************************************************************
2 *
3 * Filename: irttp.h
4 * Version: 1.0
5 * Description: Tiny Transport Protocol (TTP) definitions
6 * Status: Experimental.
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Sun Aug 31 20:14:31 1997
9 * Modified at: Sun Dec 12 13:09:07 1999
10 * Modified by: Dag Brattli <dagb@cs.uit.no>
11 *
12 * Copyright (c) 1998-1999 Dag Brattli <dagb@cs.uit.no>,
13 * All Rights Reserved.
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
19 *
20 * Neither Dag Brattli nor University of Troms� admit liability nor
21 * provide warranty for any of this software. This material is
22 * provided "AS-IS" and at no charge.
23 *
24 ********************************************************************/
25
26 #ifndef IRTTP_H
27 #define IRTTP_H
28
29 #include <linux/types.h>
30 #include <linux/skbuff.h>
31 #include <linux/spinlock.h>
32
33 #include <net/irda/irda.h>
34 #include <net/irda/irlmp.h>
35 #include <net/irda/qos.h>
36 #include <net/irda/irqueue.h>
37
38 #define TTP_MAX_CONNECTIONS LM_MAX_CONNECTIONS
39 #define TTP_HEADER 1
40 #define TTP_MAX_HEADER (TTP_HEADER + LMP_MAX_HEADER)
41 #define TTP_SAR_HEADER 5
42 #define TTP_PARAMETERS 0x80
43 #define TTP_MORE 0x80
44
45 /* Transmission queue sizes */
46 /* Worst case scenario, two window of data - Jean II */
47 #define TTP_TX_MAX_QUEUE 14
48 /* We need to keep at least 5 frames to make sure that we can refill
49 * appropriately the LAP layer. LAP keeps only two buffers, and we need
50 * to have 7 to make a full window - Jean II */
51 #define TTP_TX_LOW_THRESHOLD 5
52 /* Most clients are synchronous with respect to flow control, so we can
53 * keep a low number of Tx buffers in TTP - Jean II */
54 #define TTP_TX_HIGH_THRESHOLD 7
55
56 /* Receive queue sizes */
57 /* Minimum of credit that the peer should hold.
58 * If the peer has less credits than 9 frames, we will explicitely send
59 * him some credits (through irttp_give_credit() and a specific frame).
60 * Note that when we give credits it's likely that it won't be sent in
61 * this LAP window, but in the next one. So, we make sure that the peer
62 * has something to send while waiting for credits (one LAP window == 7
63 * + 1 frames while he process the credits). - Jean II */
64 #define TTP_RX_MIN_CREDIT 8
65 /* This is the default maximum number of credits held by the peer, so the
66 * default maximum number of frames he can send us before needing flow
67 * control answer from us (this may be negociated differently at TSAP setup).
68 * We want to minimise the number of times we have to explicitely send some
69 * credit to the peer, hoping we can piggyback it on the return data. In
70 * particular, it doesn't make sense for us to send credit more than once
71 * per LAP window.
72 * Moreover, giving credits has some latency, so we need strictly more than
73 * a LAP window, otherwise we may already have credits in our Tx queue.
74 * But on the other hand, we don't want to keep too many Rx buffer here
75 * before starting to flow control the other end, so make it exactly one
76 * LAP window + 1 + MIN_CREDITS. - Jean II */
77 #define TTP_RX_DEFAULT_CREDIT 16
78 /* Maximum number of credits we can allow the peer to have, and therefore
79 * maximum Rx queue size.
80 * Note that we try to deliver packets to the higher layer every time we
81 * receive something, so in normal mode the Rx queue will never contains
82 * more than one or two packets. - Jean II */
83 #define TTP_RX_MAX_CREDIT 21
84
85 /* What clients should use when calling ttp_open_tsap() */
86 #define DEFAULT_INITIAL_CREDIT TTP_RX_DEFAULT_CREDIT
87
88 /* Some priorities for disconnect requests */
89 #define P_NORMAL 0
90 #define P_HIGH 1
91
92 #define TTP_SAR_DISABLE 0
93 #define TTP_SAR_UNBOUND 0xffffffff
94
95 /* Parameters */
96 #define TTP_MAX_SDU_SIZE 0x01
97
98 /*
99 * This structure contains all data assosiated with one instance of a TTP
100 * connection.
101 */
102 struct tsap_cb {
103 irda_queue_t q; /* Must be first */
104 magic_t magic; /* Just in case */
105
106 __u8 stsap_sel; /* Source TSAP */
107 __u8 dtsap_sel; /* Destination TSAP */
108
109 struct lsap_cb *lsap; /* Corresponding LSAP to this TSAP */
110
111 __u8 connected; /* TSAP connected */
112
113 __u8 initial_credit; /* Initial credit to give peer */
114
115 int avail_credit; /* Available credit to return to peer */
116 int remote_credit; /* Credit held by peer TTP entity */
117 int send_credit; /* Credit held by local TTP entity */
118
119 struct sk_buff_head tx_queue; /* Frames to be transmitted */
120 struct sk_buff_head rx_queue; /* Received frames */
121 struct sk_buff_head rx_fragments;
122 int tx_queue_lock;
123 int rx_queue_lock;
124 spinlock_t lock;
125
126 notify_t notify; /* Callbacks to client layer */
127
128 struct net_device_stats stats;
129 struct timer_list todo_timer;
130
131 __u32 max_seg_size; /* Max data that fit into an IrLAP frame */
132 __u8 max_header_size;
133
134 int rx_sdu_busy; /* RxSdu.busy */
135 __u32 rx_sdu_size; /* Current size of a partially received frame */
136 __u32 rx_max_sdu_size; /* Max receive user data size */
137
138 int tx_sdu_busy; /* TxSdu.busy */
139 __u32 tx_max_sdu_size; /* Max transmit user data size */
140
141 int close_pend; /* Close, but disconnect_pend */
142 int disconnect_pend; /* Disconnect, but still data to send */
143 struct sk_buff *disconnect_skb;
144 };
145
146 struct irttp_cb {
147 magic_t magic;
148 hashbin_t *tsaps;
149 };
150
151 int irttp_init(void);
152 void irttp_cleanup(void);
153
154 struct tsap_cb *irttp_open_tsap(__u8 stsap_sel, int credit, notify_t *notify);
155 int irttp_close_tsap(struct tsap_cb *self);
156
157 int irttp_data_request(struct tsap_cb *self, struct sk_buff *skb);
158 int irttp_udata_request(struct tsap_cb *self, struct sk_buff *skb);
159
160 int irttp_connect_request(struct tsap_cb *self, __u8 dtsap_sel,
161 __u32 saddr, __u32 daddr,
162 struct qos_info *qos, __u32 max_sdu_size,
163 struct sk_buff *userdata);
164 int irttp_connect_response(struct tsap_cb *self, __u32 max_sdu_size,
165 struct sk_buff *userdata);
166 int irttp_disconnect_request(struct tsap_cb *self, struct sk_buff *skb,
167 int priority);
168 void irttp_flow_request(struct tsap_cb *self, LOCAL_FLOW flow);
169 void irttp_status_indication(void *instance,
170 LINK_STATUS link, LOCK_STATUS lock);
171 void irttp_flow_indication(void *instance, void *sap, LOCAL_FLOW flow);
172 struct tsap_cb *irttp_dup(struct tsap_cb *self, void *instance);
173
irttp_get_saddr(struct tsap_cb * self)174 static __inline __u32 irttp_get_saddr(struct tsap_cb *self)
175 {
176 return irlmp_get_saddr(self->lsap);
177 }
178
irttp_get_daddr(struct tsap_cb * self)179 static __inline __u32 irttp_get_daddr(struct tsap_cb *self)
180 {
181 return irlmp_get_daddr(self->lsap);
182 }
183
irttp_get_max_seg_size(struct tsap_cb * self)184 static __inline __u32 irttp_get_max_seg_size(struct tsap_cb *self)
185 {
186 return self->max_seg_size;
187 }
188
189 /* After doing a irttp_dup(), this get one of the two socket back into
190 * a state where it's waiting incomming connections.
191 * Note : this can be used *only* if the socket is not yet connected
192 * (i.e. NO irttp_connect_response() done on this socket).
193 * - Jean II */
irttp_listen(struct tsap_cb * self)194 static inline void irttp_listen(struct tsap_cb *self)
195 {
196 irlmp_listen(self->lsap);
197 self->dtsap_sel = LSAP_ANY;
198 }
199
200 /* Return TRUE if the node is in primary mode (i.e. master)
201 * - Jean II */
irttp_is_primary(struct tsap_cb * self)202 static inline int irttp_is_primary(struct tsap_cb *self)
203 {
204 if ((self == NULL) ||
205 (self->lsap == NULL) ||
206 (self->lsap->lap == NULL) ||
207 (self->lsap->lap->irlap == NULL))
208 return -2;
209 return(irlap_is_primary(self->lsap->lap->irlap));
210 }
211
212 #endif /* IRTTP_H */
213