Linux 2.6.19-rc6
[cris-mirror.git] / net / irda / ircomm / ircomm_ttp.c
blobd98bf3570d290691ef8d9bb373da996f4725b20c
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>
12 * Copyright (c) 1999 Dag Brattli, All Rights Reserved.
13 * Copyright (c) 2000-2003 Jean Tourrilhes <jt@hpl.hp.com>
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.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * MA 02111-1307 USA
30 ********************************************************************/
32 #include <linux/sched.h>
33 #include <linux/init.h>
35 #include <net/irda/irda.h>
36 #include <net/irda/irlmp.h>
37 #include <net/irda/iriap.h>
38 #include <net/irda/irttp.h>
40 #include <net/irda/ircomm_event.h>
41 #include <net/irda/ircomm_ttp.h>
43 static int ircomm_ttp_data_indication(void *instance, void *sap,
44 struct sk_buff *skb);
45 static void ircomm_ttp_connect_confirm(void *instance, void *sap,
46 struct qos_info *qos,
47 __u32 max_sdu_size,
48 __u8 max_header_size,
49 struct sk_buff *skb);
50 static void ircomm_ttp_connect_indication(void *instance, void *sap,
51 struct qos_info *qos,
52 __u32 max_sdu_size,
53 __u8 max_header_size,
54 struct sk_buff *skb);
55 static void ircomm_ttp_flow_indication(void *instance, void *sap,
56 LOCAL_FLOW cmd);
57 static void ircomm_ttp_disconnect_indication(void *instance, void *sap,
58 LM_REASON reason,
59 struct sk_buff *skb);
60 static int ircomm_ttp_data_request(struct ircomm_cb *self,
61 struct sk_buff *skb,
62 int clen);
63 static int ircomm_ttp_connect_request(struct ircomm_cb *self,
64 struct sk_buff *userdata,
65 struct ircomm_info *info);
66 static int ircomm_ttp_connect_response(struct ircomm_cb *self,
67 struct sk_buff *userdata);
68 static int ircomm_ttp_disconnect_request(struct ircomm_cb *self,
69 struct sk_buff *userdata,
70 struct ircomm_info *info);
73 * Function ircomm_open_tsap (self)
78 int ircomm_open_tsap(struct ircomm_cb *self)
80 notify_t notify;
82 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
84 /* Register callbacks */
85 irda_notify_init(&notify);
86 notify.data_indication = ircomm_ttp_data_indication;
87 notify.connect_confirm = ircomm_ttp_connect_confirm;
88 notify.connect_indication = ircomm_ttp_connect_indication;
89 notify.flow_indication = ircomm_ttp_flow_indication;
90 notify.disconnect_indication = ircomm_ttp_disconnect_indication;
91 notify.instance = self;
92 strlcpy(notify.name, "IrCOMM", sizeof(notify.name));
94 self->tsap = irttp_open_tsap(LSAP_ANY, DEFAULT_INITIAL_CREDIT,
95 &notify);
96 if (!self->tsap) {
97 IRDA_DEBUG(0, "%sfailed to allocate tsap\n", __FUNCTION__ );
98 return -1;
100 self->slsap_sel = self->tsap->stsap_sel;
103 * Initialize the call-table for issuing commands
105 self->issue.data_request = ircomm_ttp_data_request;
106 self->issue.connect_request = ircomm_ttp_connect_request;
107 self->issue.connect_response = ircomm_ttp_connect_response;
108 self->issue.disconnect_request = ircomm_ttp_disconnect_request;
110 return 0;
114 * Function ircomm_ttp_connect_request (self, userdata)
119 static int ircomm_ttp_connect_request(struct ircomm_cb *self,
120 struct sk_buff *userdata,
121 struct ircomm_info *info)
123 int ret = 0;
125 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
127 /* Don't forget to refcount it - should be NULL anyway */
128 if(userdata)
129 skb_get(userdata);
131 ret = irttp_connect_request(self->tsap, info->dlsap_sel,
132 info->saddr, info->daddr, NULL,
133 TTP_SAR_DISABLE, userdata);
135 return ret;
139 * Function ircomm_ttp_connect_response (self, skb)
144 static int ircomm_ttp_connect_response(struct ircomm_cb *self,
145 struct sk_buff *userdata)
147 int ret;
149 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
151 /* Don't forget to refcount it - should be NULL anyway */
152 if(userdata)
153 skb_get(userdata);
155 ret = irttp_connect_response(self->tsap, TTP_SAR_DISABLE, userdata);
157 return ret;
161 * Function ircomm_ttp_data_request (self, userdata)
163 * Send IrCOMM data to IrTTP layer. Currently we do not try to combine
164 * control data with pure data, so they will be sent as separate frames.
165 * Should not be a big problem though, since control frames are rare. But
166 * some of them are sent after connection establishment, so this can
167 * increase the latency a bit.
169 static int ircomm_ttp_data_request(struct ircomm_cb *self,
170 struct sk_buff *skb,
171 int clen)
173 int ret;
175 IRDA_ASSERT(skb != NULL, return -1;);
177 IRDA_DEBUG(2, "%s(), clen=%d\n", __FUNCTION__ , clen);
180 * Insert clen field, currently we either send data only, or control
181 * only frames, to make things easier and avoid queueing
183 IRDA_ASSERT(skb_headroom(skb) >= IRCOMM_HEADER_SIZE, return -1;);
185 /* Don't forget to refcount it - see ircomm_tty_do_softint() */
186 skb_get(skb);
188 skb_push(skb, IRCOMM_HEADER_SIZE);
190 skb->data[0] = clen;
192 ret = irttp_data_request(self->tsap, skb);
193 if (ret) {
194 IRDA_ERROR("%s(), failed\n", __FUNCTION__);
195 /* irttp_data_request already free the packet */
198 return ret;
202 * Function ircomm_ttp_data_indication (instance, sap, skb)
204 * Incoming data
207 static int ircomm_ttp_data_indication(void *instance, void *sap,
208 struct sk_buff *skb)
210 struct ircomm_cb *self = (struct ircomm_cb *) instance;
212 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
214 IRDA_ASSERT(self != NULL, return -1;);
215 IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return -1;);
216 IRDA_ASSERT(skb != NULL, return -1;);
218 ircomm_do_event(self, IRCOMM_TTP_DATA_INDICATION, skb, NULL);
220 /* Drop reference count - see ircomm_tty_data_indication(). */
221 dev_kfree_skb(skb);
223 return 0;
226 static void ircomm_ttp_connect_confirm(void *instance, void *sap,
227 struct qos_info *qos,
228 __u32 max_sdu_size,
229 __u8 max_header_size,
230 struct sk_buff *skb)
232 struct ircomm_cb *self = (struct ircomm_cb *) instance;
233 struct ircomm_info info;
235 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
237 IRDA_ASSERT(self != NULL, return;);
238 IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return;);
239 IRDA_ASSERT(skb != NULL, return;);
240 IRDA_ASSERT(qos != NULL, goto out;);
242 if (max_sdu_size != TTP_SAR_DISABLE) {
243 IRDA_ERROR("%s(), SAR not allowed for IrCOMM!\n",
244 __FUNCTION__);
245 goto out;
248 info.max_data_size = irttp_get_max_seg_size(self->tsap)
249 - IRCOMM_HEADER_SIZE;
250 info.max_header_size = max_header_size + IRCOMM_HEADER_SIZE;
251 info.qos = qos;
253 ircomm_do_event(self, IRCOMM_TTP_CONNECT_CONFIRM, skb, &info);
255 out:
256 /* Drop reference count - see ircomm_tty_connect_confirm(). */
257 dev_kfree_skb(skb);
261 * Function ircomm_ttp_connect_indication (instance, sap, qos, max_sdu_size,
262 * max_header_size, skb)
267 static void ircomm_ttp_connect_indication(void *instance, void *sap,
268 struct qos_info *qos,
269 __u32 max_sdu_size,
270 __u8 max_header_size,
271 struct sk_buff *skb)
273 struct ircomm_cb *self = (struct ircomm_cb *)instance;
274 struct ircomm_info info;
276 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
278 IRDA_ASSERT(self != NULL, return;);
279 IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return;);
280 IRDA_ASSERT(skb != NULL, return;);
281 IRDA_ASSERT(qos != NULL, goto out;);
283 if (max_sdu_size != TTP_SAR_DISABLE) {
284 IRDA_ERROR("%s(), SAR not allowed for IrCOMM!\n",
285 __FUNCTION__);
286 goto out;
289 info.max_data_size = irttp_get_max_seg_size(self->tsap)
290 - IRCOMM_HEADER_SIZE;
291 info.max_header_size = max_header_size + IRCOMM_HEADER_SIZE;
292 info.qos = qos;
294 ircomm_do_event(self, IRCOMM_TTP_CONNECT_INDICATION, skb, &info);
296 out:
297 /* Drop reference count - see ircomm_tty_connect_indication(). */
298 dev_kfree_skb(skb);
302 * Function ircomm_ttp_disconnect_request (self, userdata, info)
307 static int ircomm_ttp_disconnect_request(struct ircomm_cb *self,
308 struct sk_buff *userdata,
309 struct ircomm_info *info)
311 int ret;
313 /* Don't forget to refcount it - should be NULL anyway */
314 if(userdata)
315 skb_get(userdata);
317 ret = irttp_disconnect_request(self->tsap, userdata, P_NORMAL);
319 return ret;
323 * Function ircomm_ttp_disconnect_indication (instance, sap, reason, skb)
328 static void ircomm_ttp_disconnect_indication(void *instance, void *sap,
329 LM_REASON reason,
330 struct sk_buff *skb)
332 struct ircomm_cb *self = (struct ircomm_cb *) instance;
333 struct ircomm_info info;
335 IRDA_DEBUG(2, "%s()\n", __FUNCTION__ );
337 IRDA_ASSERT(self != NULL, return;);
338 IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return;);
340 info.reason = reason;
342 ircomm_do_event(self, IRCOMM_TTP_DISCONNECT_INDICATION, skb, &info);
344 /* Drop reference count - see ircomm_tty_disconnect_indication(). */
345 if(skb)
346 dev_kfree_skb(skb);
350 * Function ircomm_ttp_flow_indication (instance, sap, cmd)
352 * Layer below is telling us to start or stop the flow of data
355 static void ircomm_ttp_flow_indication(void *instance, void *sap,
356 LOCAL_FLOW cmd)
358 struct ircomm_cb *self = (struct ircomm_cb *) instance;
360 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
362 IRDA_ASSERT(self != NULL, return;);
363 IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return;);
365 if (self->notify.flow_indication)
366 self->notify.flow_indication(self->notify.instance, self, cmd);