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 /* Register callbacks */
80 irda_notify_init(¬ify
);
81 notify
.data_indication
= ircomm_ttp_data_indication
;
82 notify
.connect_confirm
= ircomm_ttp_connect_confirm
;
83 notify
.connect_indication
= ircomm_ttp_connect_indication
;
84 notify
.flow_indication
= ircomm_ttp_flow_indication
;
85 notify
.disconnect_indication
= ircomm_ttp_disconnect_indication
;
86 notify
.instance
= self
;
87 strlcpy(notify
.name
, "IrCOMM", sizeof(notify
.name
));
89 self
->tsap
= irttp_open_tsap(LSAP_ANY
, DEFAULT_INITIAL_CREDIT
,
92 pr_debug("%sfailed to allocate tsap\n", __func__
);
95 self
->slsap_sel
= self
->tsap
->stsap_sel
;
98 * Initialize the call-table for issuing commands
100 self
->issue
.data_request
= ircomm_ttp_data_request
;
101 self
->issue
.connect_request
= ircomm_ttp_connect_request
;
102 self
->issue
.connect_response
= ircomm_ttp_connect_response
;
103 self
->issue
.disconnect_request
= ircomm_ttp_disconnect_request
;
109 * Function ircomm_ttp_connect_request (self, userdata)
114 static int ircomm_ttp_connect_request(struct ircomm_cb
*self
,
115 struct sk_buff
*userdata
,
116 struct ircomm_info
*info
)
120 /* Don't forget to refcount it - should be NULL anyway */
124 ret
= irttp_connect_request(self
->tsap
, info
->dlsap_sel
,
125 info
->saddr
, info
->daddr
, NULL
,
126 TTP_SAR_DISABLE
, userdata
);
132 * Function ircomm_ttp_connect_response (self, skb)
137 static int ircomm_ttp_connect_response(struct ircomm_cb
*self
,
138 struct sk_buff
*userdata
)
142 /* Don't forget to refcount it - should be NULL anyway */
146 ret
= irttp_connect_response(self
->tsap
, TTP_SAR_DISABLE
, userdata
);
152 * Function ircomm_ttp_data_request (self, userdata)
154 * Send IrCOMM data to IrTTP layer. Currently we do not try to combine
155 * control data with pure data, so they will be sent as separate frames.
156 * Should not be a big problem though, since control frames are rare. But
157 * some of them are sent after connection establishment, so this can
158 * increase the latency a bit.
160 static int ircomm_ttp_data_request(struct ircomm_cb
*self
,
166 IRDA_ASSERT(skb
!= NULL
, return -1;);
168 pr_debug("%s(), clen=%d\n", __func__
, clen
);
171 * Insert clen field, currently we either send data only, or control
172 * only frames, to make things easier and avoid queueing
174 IRDA_ASSERT(skb_headroom(skb
) >= IRCOMM_HEADER_SIZE
, return -1;);
176 /* Don't forget to refcount it - see ircomm_tty_do_softint() */
179 skb_push(skb
, IRCOMM_HEADER_SIZE
);
183 ret
= irttp_data_request(self
->tsap
, skb
);
185 net_err_ratelimited("%s(), failed\n", __func__
);
186 /* irttp_data_request already free the packet */
193 * Function ircomm_ttp_data_indication (instance, sap, skb)
198 static int ircomm_ttp_data_indication(void *instance
, void *sap
,
201 struct ircomm_cb
*self
= (struct ircomm_cb
*) instance
;
203 IRDA_ASSERT(self
!= NULL
, return -1;);
204 IRDA_ASSERT(self
->magic
== IRCOMM_MAGIC
, return -1;);
205 IRDA_ASSERT(skb
!= NULL
, return -1;);
207 ircomm_do_event(self
, IRCOMM_TTP_DATA_INDICATION
, skb
, NULL
);
209 /* Drop reference count - see ircomm_tty_data_indication(). */
215 static void ircomm_ttp_connect_confirm(void *instance
, void *sap
,
216 struct qos_info
*qos
,
218 __u8 max_header_size
,
221 struct ircomm_cb
*self
= (struct ircomm_cb
*) instance
;
222 struct ircomm_info info
;
224 IRDA_ASSERT(self
!= NULL
, return;);
225 IRDA_ASSERT(self
->magic
== IRCOMM_MAGIC
, return;);
226 IRDA_ASSERT(skb
!= NULL
, return;);
227 IRDA_ASSERT(qos
!= NULL
, goto out
;);
229 if (max_sdu_size
!= TTP_SAR_DISABLE
) {
230 net_err_ratelimited("%s(), SAR not allowed for IrCOMM!\n",
235 info
.max_data_size
= irttp_get_max_seg_size(self
->tsap
)
236 - IRCOMM_HEADER_SIZE
;
237 info
.max_header_size
= max_header_size
+ IRCOMM_HEADER_SIZE
;
240 ircomm_do_event(self
, IRCOMM_TTP_CONNECT_CONFIRM
, skb
, &info
);
243 /* Drop reference count - see ircomm_tty_connect_confirm(). */
248 * Function ircomm_ttp_connect_indication (instance, sap, qos, max_sdu_size,
249 * max_header_size, skb)
254 static void ircomm_ttp_connect_indication(void *instance
, void *sap
,
255 struct qos_info
*qos
,
257 __u8 max_header_size
,
260 struct ircomm_cb
*self
= (struct ircomm_cb
*)instance
;
261 struct ircomm_info info
;
263 IRDA_ASSERT(self
!= NULL
, return;);
264 IRDA_ASSERT(self
->magic
== IRCOMM_MAGIC
, return;);
265 IRDA_ASSERT(skb
!= NULL
, return;);
266 IRDA_ASSERT(qos
!= NULL
, goto out
;);
268 if (max_sdu_size
!= TTP_SAR_DISABLE
) {
269 net_err_ratelimited("%s(), SAR not allowed for IrCOMM!\n",
274 info
.max_data_size
= irttp_get_max_seg_size(self
->tsap
)
275 - IRCOMM_HEADER_SIZE
;
276 info
.max_header_size
= max_header_size
+ IRCOMM_HEADER_SIZE
;
279 ircomm_do_event(self
, IRCOMM_TTP_CONNECT_INDICATION
, skb
, &info
);
282 /* Drop reference count - see ircomm_tty_connect_indication(). */
287 * Function ircomm_ttp_disconnect_request (self, userdata, info)
292 static int ircomm_ttp_disconnect_request(struct ircomm_cb
*self
,
293 struct sk_buff
*userdata
,
294 struct ircomm_info
*info
)
298 /* Don't forget to refcount it - should be NULL anyway */
302 ret
= irttp_disconnect_request(self
->tsap
, userdata
, P_NORMAL
);
308 * Function ircomm_ttp_disconnect_indication (instance, sap, reason, skb)
313 static void ircomm_ttp_disconnect_indication(void *instance
, void *sap
,
317 struct ircomm_cb
*self
= (struct ircomm_cb
*) instance
;
318 struct ircomm_info info
;
320 IRDA_ASSERT(self
!= NULL
, return;);
321 IRDA_ASSERT(self
->magic
== IRCOMM_MAGIC
, return;);
323 info
.reason
= reason
;
325 ircomm_do_event(self
, IRCOMM_TTP_DISCONNECT_INDICATION
, skb
, &info
);
327 /* Drop reference count - see ircomm_tty_disconnect_indication(). */
333 * Function ircomm_ttp_flow_indication (instance, sap, cmd)
335 * Layer below is telling us to start or stop the flow of data
338 static void ircomm_ttp_flow_indication(void *instance
, void *sap
,
341 struct ircomm_cb
*self
= (struct ircomm_cb
*) instance
;
343 IRDA_ASSERT(self
!= NULL
, return;);
344 IRDA_ASSERT(self
->magic
== IRCOMM_MAGIC
, return;);
346 if (self
->notify
.flow_indication
)
347 self
->notify
.flow_indication(self
->notify
.instance
, self
, cmd
);