1 /*********************************************************************
3 * Filename: ircomm_ttp.c
5 * Description: Interface between IrCOMM and IrTTP
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,
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,
45 static void ircomm_ttp_connect_confirm(void *instance, void *sap,
50 static void ircomm_ttp_connect_indication(void *instance, void *sap,
55 static void ircomm_ttp_flow_indication(void *instance, void *sap,
57 static void ircomm_ttp_disconnect_indication(void *instance, void *sap,
60 static int ircomm_ttp_data_request(struct ircomm_cb *self,
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)
82 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
84 /* Register callbacks */
85 irda_notify_init(¬ify);
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,
97 IRDA_DEBUG(0, "%sfailed to allocate tsap\n", __FUNCTION__ );
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;
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)
125 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
127 /* Don't forget to refcount it - should be NULL anyway */
131 ret = irttp_connect_request(self->tsap, info->dlsap_sel,
132 info->saddr, info->daddr, NULL,
133 TTP_SAR_DISABLE, userdata);
139 * Function ircomm_ttp_connect_response (self, skb)
144 static int ircomm_ttp_connect_response(struct ircomm_cb *self,
145 struct sk_buff *userdata)
149 IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
151 /* Don't forget to refcount it - should be NULL anyway */
155 ret = irttp_connect_response(self->tsap, TTP_SAR_DISABLE, userdata);
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,
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() */
188 skb_push(skb, IRCOMM_HEADER_SIZE);
192 ret = irttp_data_request(self->tsap, skb);
194 IRDA_ERROR("%s(), failed\n", __FUNCTION__);
195 /* irttp_data_request already free the packet */
202 * Function ircomm_ttp_data_indication (instance, sap, skb)
207 static int ircomm_ttp_data_indication(void *instance, void *sap,
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(). */
226 static void ircomm_ttp_connect_confirm(void *instance, void *sap,
227 struct qos_info *qos,
229 __u8 max_header_size,
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",
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;
253 ircomm_do_event(self, IRCOMM_TTP_CONNECT_CONFIRM, skb, &info);
256 /* Drop reference count - see ircomm_tty_connect_confirm(). */
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,
270 __u8 max_header_size,
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",
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;
294 ircomm_do_event(self, IRCOMM_TTP_CONNECT_INDICATION, skb, &info);
297 /* Drop reference count - see ircomm_tty_connect_indication(). */
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)
313 /* Don't forget to refcount it - should be NULL anyway */
317 ret = irttp_disconnect_request(self->tsap, userdata, P_NORMAL);
323 * Function ircomm_ttp_disconnect_indication (instance, sap, reason, skb)
328 static void ircomm_ttp_disconnect_indication(void *instance, void *sap,
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(). */
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,
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);