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#define DEFAULT_INITIAL_CREDIT 14
46
47#define TTP_LOW_THRESHOLD       4
48#define TTP_HIGH_THRESHOLD     10
49#define TTP_MAX_QUEUE          14
50
51/* Some priorities for disconnect requests */
52#define P_NORMAL    0
53#define P_HIGH      1
54
55#define TTP_SAR_DISABLE 0
56#define TTP_SAR_UNBOUND 0xffffffff
57
58/* Parameters */
59#define TTP_MAX_SDU_SIZE 0x01
60
61/*
62 *  This structure contains all data assosiated with one instance of a TTP
63 *  connection.
64 */
65struct tsap_cb {
66	irda_queue_t q;            /* Must be first */
67	magic_t magic;        /* Just in case */
68
69	__u8 stsap_sel;       /* Source TSAP */
70	__u8 dtsap_sel;       /* Destination TSAP */
71
72	struct lsap_cb *lsap; /* Corresponding LSAP to this TSAP */
73
74	__u8 connected;       /* TSAP connected */
75
76	__u8 initial_credit;  /* Initial credit to give peer */
77
78        int avail_credit;    /* Available credit to return to peer */
79	int remote_credit;   /* Credit held by peer TTP entity */
80	int send_credit;     /* Credit held by local TTP entity */
81
82	struct sk_buff_head tx_queue; /* Frames to be transmitted */
83	struct sk_buff_head rx_queue; /* Received frames */
84	struct sk_buff_head rx_fragments;
85	int tx_queue_lock;
86	int rx_queue_lock;
87	spinlock_t lock;
88
89	notify_t notify;       /* Callbacks to client layer */
90
91	struct net_device_stats stats;
92	struct timer_list todo_timer;
93
94	__u32 max_seg_size;     /* Max data that fit into an IrLAP frame */
95	__u8  max_header_size;
96
97	int   rx_sdu_busy;     /* RxSdu.busy */
98	__u32 rx_sdu_size;     /* Current size of a partially received frame */
99	__u32 rx_max_sdu_size; /* Max receive user data size */
100
101	int tx_sdu_busy;       /* TxSdu.busy */
102	__u32 tx_max_sdu_size; /* Max transmit user data size */
103
104	int close_pend;        /* Close, but disconnect_pend */
105	int disconnect_pend;   /* Disconnect, but still data to send */
106	struct sk_buff *disconnect_skb;
107};
108
109struct irttp_cb {
110	magic_t    magic;
111	hashbin_t *tsaps;
112};
113
114int  irttp_init(void);
115void irttp_cleanup(void);
116
117struct tsap_cb *irttp_open_tsap(__u8 stsap_sel, int credit, notify_t *notify);
118int irttp_close_tsap(struct tsap_cb *self);
119
120int irttp_data_request(struct tsap_cb *self, struct sk_buff *skb);
121int irttp_udata_request(struct tsap_cb *self, struct sk_buff *skb);
122
123int irttp_connect_request(struct tsap_cb *self, __u8 dtsap_sel,
124			  __u32 saddr, __u32 daddr,
125			  struct qos_info *qos, __u32 max_sdu_size,
126			  struct sk_buff *userdata);
127int irttp_connect_response(struct tsap_cb *self, __u32 max_sdu_size,
128			    struct sk_buff *userdata);
129int irttp_disconnect_request(struct tsap_cb *self, struct sk_buff *skb,
130			     int priority);
131void irttp_flow_request(struct tsap_cb *self, LOCAL_FLOW flow);
132void irttp_status_indication(void *instance,
133			     LINK_STATUS link, LOCK_STATUS lock);
134struct tsap_cb *irttp_dup(struct tsap_cb *self, void *instance);
135
136static __inline __u32 irttp_get_saddr(struct tsap_cb *self)
137{
138	return irlmp_get_saddr(self->lsap);
139}
140
141static __inline __u32 irttp_get_daddr(struct tsap_cb *self)
142{
143	return irlmp_get_daddr(self->lsap);
144}
145
146static __inline __u32 irttp_get_max_seg_size(struct tsap_cb *self)
147{
148	return self->max_seg_size;
149}
150
151/* After doing a irttp_dup(), this get one of the two socket back into
152 * a state where it's waiting incomming connections.
153 * Note : this can be used *only* if the socket is not yet connected
154 * (i.e. NO irttp_connect_response() done on this socket).
155 * - Jean II */
156static inline void irttp_listen(struct tsap_cb *self)
157{
158	irlmp_listen(self->lsap);
159	self->dtsap_sel = LSAP_ANY;
160}
161
162extern struct irttp_cb *irttp;
163
164#endif /* IRTTP_H */
165