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, see <http://www.gnu.org/licenses/>.
28 ********************************************************************/
30 #include <linux/init.h>
32 #include <net/irda/irda.h>
33 #include <net/irda/irlmp.h>
34 #include <net/irda/iriap.h>
35 #include <net/irda/irttp.h>
37 #include <net/irda/ircomm_event.h>
38 #include <net/irda/ircomm_ttp.h>
40 static int ircomm_ttp_data_indication(void *instance
, void *sap
,
42 static void ircomm_ttp_connect_confirm(void *instance
, void *sap
,
47 static void ircomm_ttp_connect_indication(void *instance
, void *sap
,
52 static void ircomm_ttp_flow_indication(void *instance
, void *sap
,
54 static void ircomm_ttp_disconnect_indication(void *instance
, void *sap
,
57 static int ircomm_ttp_data_request(struct ircomm_cb
*self
,
60 static int ircomm_ttp_connect_request(struct ircomm_cb
*self
,
61 struct sk_buff
*userdata
,
62 struct ircomm_info
*info
);
63 static int ircomm_ttp_connect_response(struct ircomm_cb
*self
,
64 struct sk_buff
*userdata
);
65 static int ircomm_ttp_disconnect_request(struct ircomm_cb
*self
,
66 struct sk_buff
*userdata
,
67 struct ircomm_info
*info
);
70 * Function ircomm_open_tsap (self)
75 int ircomm_open_tsap(struct ircomm_cb
*self
)
79 IRDA_DEBUG(4, "%s()\n", __func__
);
81 /* Register callbacks */
82 irda_notify_init(¬ify
);
83 notify
.data_indication
= ircomm_ttp_data_indication
;
84 notify
.connect_confirm
= ircomm_ttp_connect_confirm
;
85 notify
.connect_indication
= ircomm_ttp_connect_indication
;
86 notify
.flow_indication
= ircomm_ttp_flow_indication
;
87 notify
.disconnect_indication
= ircomm_ttp_disconnect_indication
;
88 notify
.instance
= self
;
89 strlcpy(notify
.name
, "IrCOMM", sizeof(notify
.name
));
91 self
->tsap
= irttp_open_tsap(LSAP_ANY
, DEFAULT_INITIAL_CREDIT
,
94 IRDA_DEBUG(0, "%sfailed to allocate tsap\n", __func__
);
97 self
->slsap_sel
= self
->tsap
->stsap_sel
;
100 * Initialize the call-table for issuing commands
102 self
->issue
.data_request
= ircomm_ttp_data_request
;
103 self
->issue
.connect_request
= ircomm_ttp_connect_request
;
104 self
->issue
.connect_response
= ircomm_ttp_connect_response
;
105 self
->issue
.disconnect_request
= ircomm_ttp_disconnect_request
;
111 * Function ircomm_ttp_connect_request (self, userdata)
116 static int ircomm_ttp_connect_request(struct ircomm_cb
*self
,
117 struct sk_buff
*userdata
,
118 struct ircomm_info
*info
)
122 IRDA_DEBUG(4, "%s()\n", __func__
);
124 /* Don't forget to refcount it - should be NULL anyway */
128 ret
= irttp_connect_request(self
->tsap
, info
->dlsap_sel
,
129 info
->saddr
, info
->daddr
, NULL
,
130 TTP_SAR_DISABLE
, userdata
);
136 * Function ircomm_ttp_connect_response (self, skb)
141 static int ircomm_ttp_connect_response(struct ircomm_cb
*self
,
142 struct sk_buff
*userdata
)
146 IRDA_DEBUG(4, "%s()\n", __func__
);
148 /* Don't forget to refcount it - should be NULL anyway */
152 ret
= irttp_connect_response(self
->tsap
, TTP_SAR_DISABLE
, userdata
);
158 * Function ircomm_ttp_data_request (self, userdata)
160 * Send IrCOMM data to IrTTP layer. Currently we do not try to combine
161 * control data with pure data, so they will be sent as separate frames.
162 * Should not be a big problem though, since control frames are rare. But
163 * some of them are sent after connection establishment, so this can
164 * increase the latency a bit.
166 static int ircomm_ttp_data_request(struct ircomm_cb
*self
,
172 IRDA_ASSERT(skb
!= NULL
, return -1;);
174 IRDA_DEBUG(2, "%s(), clen=%d\n", __func__
, clen
);
177 * Insert clen field, currently we either send data only, or control
178 * only frames, to make things easier and avoid queueing
180 IRDA_ASSERT(skb_headroom(skb
) >= IRCOMM_HEADER_SIZE
, return -1;);
182 /* Don't forget to refcount it - see ircomm_tty_do_softint() */
185 skb_push(skb
, IRCOMM_HEADER_SIZE
);
189 ret
= irttp_data_request(self
->tsap
, skb
);
191 IRDA_ERROR("%s(), failed\n", __func__
);
192 /* irttp_data_request already free the packet */
199 * Function ircomm_ttp_data_indication (instance, sap, skb)
204 static int ircomm_ttp_data_indication(void *instance
, void *sap
,
207 struct ircomm_cb
*self
= (struct ircomm_cb
*) instance
;
209 IRDA_DEBUG(4, "%s()\n", __func__
);
211 IRDA_ASSERT(self
!= NULL
, return -1;);
212 IRDA_ASSERT(self
->magic
== IRCOMM_MAGIC
, return -1;);
213 IRDA_ASSERT(skb
!= NULL
, return -1;);
215 ircomm_do_event(self
, IRCOMM_TTP_DATA_INDICATION
, skb
, NULL
);
217 /* Drop reference count - see ircomm_tty_data_indication(). */
223 static void ircomm_ttp_connect_confirm(void *instance
, void *sap
,
224 struct qos_info
*qos
,
226 __u8 max_header_size
,
229 struct ircomm_cb
*self
= (struct ircomm_cb
*) instance
;
230 struct ircomm_info info
;
232 IRDA_DEBUG(4, "%s()\n", __func__
);
234 IRDA_ASSERT(self
!= NULL
, return;);
235 IRDA_ASSERT(self
->magic
== IRCOMM_MAGIC
, return;);
236 IRDA_ASSERT(skb
!= NULL
, return;);
237 IRDA_ASSERT(qos
!= NULL
, goto out
;);
239 if (max_sdu_size
!= TTP_SAR_DISABLE
) {
240 IRDA_ERROR("%s(), SAR not allowed for IrCOMM!\n",
245 info
.max_data_size
= irttp_get_max_seg_size(self
->tsap
)
246 - IRCOMM_HEADER_SIZE
;
247 info
.max_header_size
= max_header_size
+ IRCOMM_HEADER_SIZE
;
250 ircomm_do_event(self
, IRCOMM_TTP_CONNECT_CONFIRM
, skb
, &info
);
253 /* Drop reference count - see ircomm_tty_connect_confirm(). */
258 * Function ircomm_ttp_connect_indication (instance, sap, qos, max_sdu_size,
259 * max_header_size, skb)
264 static void ircomm_ttp_connect_indication(void *instance
, void *sap
,
265 struct qos_info
*qos
,
267 __u8 max_header_size
,
270 struct ircomm_cb
*self
= (struct ircomm_cb
*)instance
;
271 struct ircomm_info info
;
273 IRDA_DEBUG(4, "%s()\n", __func__
);
275 IRDA_ASSERT(self
!= NULL
, return;);
276 IRDA_ASSERT(self
->magic
== IRCOMM_MAGIC
, return;);
277 IRDA_ASSERT(skb
!= NULL
, return;);
278 IRDA_ASSERT(qos
!= NULL
, goto out
;);
280 if (max_sdu_size
!= TTP_SAR_DISABLE
) {
281 IRDA_ERROR("%s(), SAR not allowed for IrCOMM!\n",
286 info
.max_data_size
= irttp_get_max_seg_size(self
->tsap
)
287 - IRCOMM_HEADER_SIZE
;
288 info
.max_header_size
= max_header_size
+ IRCOMM_HEADER_SIZE
;
291 ircomm_do_event(self
, IRCOMM_TTP_CONNECT_INDICATION
, skb
, &info
);
294 /* Drop reference count - see ircomm_tty_connect_indication(). */
299 * Function ircomm_ttp_disconnect_request (self, userdata, info)
304 static int ircomm_ttp_disconnect_request(struct ircomm_cb
*self
,
305 struct sk_buff
*userdata
,
306 struct ircomm_info
*info
)
310 /* Don't forget to refcount it - should be NULL anyway */
314 ret
= irttp_disconnect_request(self
->tsap
, userdata
, P_NORMAL
);
320 * Function ircomm_ttp_disconnect_indication (instance, sap, reason, skb)
325 static void ircomm_ttp_disconnect_indication(void *instance
, void *sap
,
329 struct ircomm_cb
*self
= (struct ircomm_cb
*) instance
;
330 struct ircomm_info info
;
332 IRDA_DEBUG(2, "%s()\n", __func__
);
334 IRDA_ASSERT(self
!= NULL
, return;);
335 IRDA_ASSERT(self
->magic
== IRCOMM_MAGIC
, return;);
337 info
.reason
= reason
;
339 ircomm_do_event(self
, IRCOMM_TTP_DISCONNECT_INDICATION
, skb
, &info
);
341 /* Drop reference count - see ircomm_tty_disconnect_indication(). */
347 * Function ircomm_ttp_flow_indication (instance, sap, cmd)
349 * Layer below is telling us to start or stop the flow of data
352 static void ircomm_ttp_flow_indication(void *instance
, void *sap
,
355 struct ircomm_cb
*self
= (struct ircomm_cb
*) instance
;
357 IRDA_DEBUG(4, "%s()\n", __func__
);
359 IRDA_ASSERT(self
!= NULL
, return;);
360 IRDA_ASSERT(self
->magic
== IRCOMM_MAGIC
, return;);
362 if (self
->notify
.flow_indication
)
363 self
->notify
.flow_indication(self
->notify
.instance
, self
, cmd
);