File: /usr/src/linux/net/irda/ircomm/ircomm_ttp.c

1     /*********************************************************************
2      *                
3      * Filename:      ircomm_ttp.c
4      * Version:       1.0
5      * Description:   Interface between IrCOMM and IrTTP
6      * Status:        Stable
7      * Author:        Dag Brattli <dagb@cs.uit.no>
8      * Created at:    Sun Jun  6 20:48:27 1999
9      * Modified at:   Mon Dec 13 11:35:13 1999
10      * Modified by:   Dag Brattli <dagb@cs.uit.no>
11      * 
12      *     Copyright (c) 1999 Dag Brattli, All Rights Reserved.
13      *     
14      *     This program is free software; you can redistribute it and/or 
15      *     modify it under the terms of the GNU General Public License as 
16      *     published by the Free Software Foundation; either version 2 of 
17      *     the License, or (at your option) any later version.
18      * 
19      *     This program is distributed in the hope that it will be useful,
20      *     but WITHOUT ANY WARRANTY; without even the implied warranty of
21      *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22      *     GNU General Public License for more details.
23      * 
24      *     You should have received a copy of the GNU General Public License 
25      *     along with this program; if not, write to the Free Software 
26      *     Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
27      *     MA 02111-1307 USA
28      *     
29      ********************************************************************/
30     
31     #include <linux/sched.h>
32     #include <linux/init.h>
33     
34     #include <net/irda/irda.h>
35     #include <net/irda/irlmp.h>
36     #include <net/irda/iriap.h>
37     #include <net/irda/irttp.h>
38     
39     #include <net/irda/ircomm_event.h>
40     #include <net/irda/ircomm_ttp.h>
41     
42     /*
43      * Function ircomm_open_tsap (self)
44      *
45      *    
46      *
47      */
48     int ircomm_open_tsap(struct ircomm_cb *self)
49     {
50     	notify_t notify;
51     
52     	IRDA_DEBUG(4, __FUNCTION__ "()\n");
53     
54     	/* Register callbacks */
55     	irda_notify_init(&notify);
56     	notify.data_indication       = ircomm_ttp_data_indication;
57     	notify.connect_confirm       = ircomm_ttp_connect_confirm;
58     	notify.connect_indication    = ircomm_ttp_connect_indication;
59     	notify.flow_indication       = ircomm_ttp_flow_indication;
60     	notify.disconnect_indication = ircomm_ttp_disconnect_indication;
61     	notify.instance = self;
62     	strncpy(notify.name, "IrCOMM", NOTIFY_MAX_NAME);
63     
64     	self->tsap = irttp_open_tsap(LSAP_ANY, DEFAULT_INITIAL_CREDIT,
65     				     &notify);
66     	if (!self->tsap) {
67     		IRDA_DEBUG(0, __FUNCTION__"failed to allocate tsap\n");
68     		return -1;
69     	}
70     	self->slsap_sel = self->tsap->stsap_sel;
71     
72     	/*
73     	 *  Initialize the call-table for issuing commands
74     	 */
75     	self->issue.data_request       = ircomm_ttp_data_request;
76     	self->issue.connect_request    = ircomm_ttp_connect_request;
77     	self->issue.connect_response   = ircomm_ttp_connect_response;
78     	self->issue.disconnect_request = ircomm_ttp_disconnect_request;
79     
80     	return 0;
81     }
82     
83     /*
84      * Function ircomm_ttp_connect_request (self, userdata)
85      *
86      *    
87      *
88      */
89     int ircomm_ttp_connect_request(struct ircomm_cb *self, 
90     			       struct sk_buff *userdata, 
91     			       struct ircomm_info *info)
92     {
93     	int ret = 0;
94     
95     	IRDA_DEBUG(4, __FUNCTION__ "()\n");
96     
97     	ret = irttp_connect_request(self->tsap, info->dlsap_sel,
98     				    info->saddr, info->daddr, NULL, 
99     				    TTP_SAR_DISABLE, userdata); 
100     	return ret;
101     }	
102     
103     /*
104      * Function ircomm_ttp_connect_response (self, skb)
105      *
106      *    
107      *
108      */
109     int ircomm_ttp_connect_response(struct ircomm_cb *self, struct sk_buff *skb)
110     {
111     	int ret;
112     
113     	IRDA_DEBUG(4, __FUNCTION__"()\n");
114     	
115     	ret = irttp_connect_response(self->tsap, TTP_SAR_DISABLE, skb);
116     
117     	return ret;
118     }
119     
120     /*
121      * Function ircomm_ttp_data_request (self, userdata)
122      *
123      *    Send IrCOMM data to IrTTP layer. Currently we do not try to combine 
124      *    control data with pure data, so they will be sent as separate frames. 
125      *    Should not be a big problem though, since control frames are rare. But
126      *    some of them are sent after connection establishment, so this can 
127      *    increase the latency a bit.
128      */
129     int ircomm_ttp_data_request(struct ircomm_cb *self, struct sk_buff *skb, 
130     			    int clen)
131     {
132     	int ret;
133     
134     	ASSERT(skb != NULL, return -1;);
135     
136     	IRDA_DEBUG(2, __FUNCTION__"(), clen=%d\n", clen);
137     
138     	/* 
139     	 * Insert clen field, currently we either send data only, or control
140     	 * only frames, to make things easier and avoid queueing
141     	 */
142     	ASSERT(skb_headroom(skb) >= IRCOMM_HEADER_SIZE, return -1;);
143     	skb_push(skb, IRCOMM_HEADER_SIZE);
144     
145     	skb->data[0] = clen;
146     
147     	ret = irttp_data_request(self->tsap, skb);
148     	if (ret) {
149     		ERROR(__FUNCTION__ "(), failed\n");
150     		dev_kfree_skb(skb);
151     	}
152     
153     	return ret;
154     }
155     
156     /*
157      * Function ircomm_ttp_data_indication (instance, sap, skb)
158      *
159      *    Incoming data
160      *
161      */
162     int ircomm_ttp_data_indication(void *instance, void *sap,
163     			       struct sk_buff *skb)
164     {
165     	struct ircomm_cb *self = (struct ircomm_cb *) instance;
166     
167     	IRDA_DEBUG(4, __FUNCTION__"()\n");
168     	
169     	ASSERT(self != NULL, return -1;);
170     	ASSERT(self->magic == IRCOMM_MAGIC, return -1;);
171     	ASSERT(skb != NULL, return -1;);
172     
173     	ircomm_do_event(self, IRCOMM_TTP_DATA_INDICATION, skb, NULL);
174     
175     	return 0;
176     }
177     
178     void ircomm_ttp_connect_confirm(void *instance, void *sap,
179     				struct qos_info *qos, 
180     				__u32 max_sdu_size, 
181     				__u8 max_header_size,
182     				struct sk_buff *skb)
183     {
184     	struct ircomm_cb *self = (struct ircomm_cb *) instance;
185     	struct ircomm_info info;
186     
187     	IRDA_DEBUG(4, __FUNCTION__"()\n");
188     
189     	ASSERT(self != NULL, return;);
190     	ASSERT(self->magic == IRCOMM_MAGIC, return;);
191     	ASSERT(skb != NULL, return;);
192     	ASSERT(qos != NULL, return;);
193     
194     	if (max_sdu_size != TTP_SAR_DISABLE) {
195     		ERROR(__FUNCTION__ "(), SAR not allowed for IrCOMM!\n");
196     		dev_kfree_skb(skb);
197     		return;
198     	}
199     
200     	info.max_data_size = irttp_get_max_seg_size(self->tsap)
201     		- IRCOMM_HEADER_SIZE;
202     	info.max_header_size = max_header_size + IRCOMM_HEADER_SIZE;
203     	info.qos = qos;
204     
205     	ircomm_do_event(self, IRCOMM_TTP_CONNECT_CONFIRM, skb, &info);
206     }
207     
208     /*
209      * Function ircomm_ttp_connect_indication (instance, sap, qos, max_sdu_size,
210      *                                         max_header_size, skb)
211      *
212      *    
213      *
214      */
215     void ircomm_ttp_connect_indication(void *instance, void *sap,
216     				   struct qos_info *qos,
217     				   __u32 max_sdu_size,
218     				   __u8 max_header_size,
219     				   struct sk_buff *skb)
220     {
221     	struct ircomm_cb *self = (struct ircomm_cb *)instance;
222     	struct ircomm_info info;
223     
224     	IRDA_DEBUG(4, __FUNCTION__"()\n");
225     
226     	ASSERT(self != NULL, return;);
227     	ASSERT(self->magic == IRCOMM_MAGIC, return;);
228     	ASSERT(skb != NULL, return;);
229     	ASSERT(qos != NULL, return;);
230     
231     	if (max_sdu_size != TTP_SAR_DISABLE) {
232     		ERROR(__FUNCTION__ "(), SAR not allowed for IrCOMM!\n");
233     		dev_kfree_skb(skb);
234     		return;
235     	}
236     
237     	info.max_data_size = irttp_get_max_seg_size(self->tsap)
238     		- IRCOMM_HEADER_SIZE;
239     	info.max_header_size = max_header_size + IRCOMM_HEADER_SIZE;
240     	info.qos = qos;
241     
242     	ircomm_do_event(self, IRCOMM_TTP_CONNECT_INDICATION, skb, &info);
243     }
244     
245     /*
246      * Function ircomm_ttp_disconnect_request (self, userdata, info)
247      *
248      *    
249      *
250      */
251     int ircomm_ttp_disconnect_request(struct ircomm_cb *self, 
252     				  struct sk_buff *userdata, 
253     				  struct ircomm_info *info)
254     {
255     	int ret;
256     
257     	ret = irttp_disconnect_request(self->tsap, userdata, P_NORMAL);
258     
259     	return ret;
260     }
261     
262     /*
263      * Function ircomm_ttp_disconnect_indication (instance, sap, reason, skb)
264      *
265      *    
266      *
267      */
268     void ircomm_ttp_disconnect_indication(void *instance, void *sap, 
269     				      LM_REASON reason,
270     				      struct sk_buff *skb)
271     {
272     	struct ircomm_cb *self = (struct ircomm_cb *) instance;
273     	struct ircomm_info info;
274     
275     	IRDA_DEBUG(2, __FUNCTION__"()\n");
276     
277     	ASSERT(self != NULL, return;);
278     	ASSERT(self->magic == IRCOMM_MAGIC, return;);
279     
280     	info.reason = reason;
281     
282     	ircomm_do_event(self, IRCOMM_TTP_DISCONNECT_INDICATION, skb, &info);
283     }
284     
285     /*
286      * Function ircomm_ttp_flow_indication (instance, sap, cmd)
287      *
288      *    Layer below is telling us to start or stop the flow of data
289      *
290      */
291     void ircomm_ttp_flow_indication(void *instance, void *sap, LOCAL_FLOW cmd)
292     {
293     	struct ircomm_cb *self = (struct ircomm_cb *) instance;
294     
295     	IRDA_DEBUG(4, __FUNCTION__ "()\n");
296     
297     	ASSERT(self != NULL, return;);
298     	ASSERT(self->magic == IRCOMM_MAGIC, return;);
299     	
300     	if (self->notify.flow_indication)
301     		self->notify.flow_indication(self->notify.instance, self, cmd);
302     }
303     
304     
305