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>
44 * Function ircomm_open_tsap (self)
49 int ircomm_open_tsap(struct ircomm_cb
*self
)
53 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
55 /* Register callbacks */
56 irda_notify_init(¬ify
);
57 notify
.data_indication
= ircomm_ttp_data_indication
;
58 notify
.connect_confirm
= ircomm_ttp_connect_confirm
;
59 notify
.connect_indication
= ircomm_ttp_connect_indication
;
60 notify
.flow_indication
= ircomm_ttp_flow_indication
;
61 notify
.disconnect_indication
= ircomm_ttp_disconnect_indication
;
62 notify
.instance
= self
;
63 strlcpy(notify
.name
, "IrCOMM", sizeof(notify
.name
));
65 self
->tsap
= irttp_open_tsap(LSAP_ANY
, DEFAULT_INITIAL_CREDIT
,
68 IRDA_DEBUG(0, "%sfailed to allocate tsap\n", __FUNCTION__
);
71 self
->slsap_sel
= self
->tsap
->stsap_sel
;
74 * Initialize the call-table for issuing commands
76 self
->issue
.data_request
= ircomm_ttp_data_request
;
77 self
->issue
.connect_request
= ircomm_ttp_connect_request
;
78 self
->issue
.connect_response
= ircomm_ttp_connect_response
;
79 self
->issue
.disconnect_request
= ircomm_ttp_disconnect_request
;
85 * Function ircomm_ttp_connect_request (self, userdata)
90 int ircomm_ttp_connect_request(struct ircomm_cb
*self
,
91 struct sk_buff
*userdata
,
92 struct ircomm_info
*info
)
96 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
98 /* Don't forget to refcount it - should be NULL anyway */
102 ret
= irttp_connect_request(self
->tsap
, info
->dlsap_sel
,
103 info
->saddr
, info
->daddr
, NULL
,
104 TTP_SAR_DISABLE
, userdata
);
110 * Function ircomm_ttp_connect_response (self, skb)
115 int ircomm_ttp_connect_response(struct ircomm_cb
*self
,
116 struct sk_buff
*userdata
)
120 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
122 /* Don't forget to refcount it - should be NULL anyway */
126 ret
= irttp_connect_response(self
->tsap
, TTP_SAR_DISABLE
, userdata
);
132 * Function ircomm_ttp_data_request (self, userdata)
134 * Send IrCOMM data to IrTTP layer. Currently we do not try to combine
135 * control data with pure data, so they will be sent as separate frames.
136 * Should not be a big problem though, since control frames are rare. But
137 * some of them are sent after connection establishment, so this can
138 * increase the latency a bit.
140 int ircomm_ttp_data_request(struct ircomm_cb
*self
,
146 ASSERT(skb
!= NULL
, return -1;);
148 IRDA_DEBUG(2, "%s(), clen=%d\n", __FUNCTION__
, clen
);
151 * Insert clen field, currently we either send data only, or control
152 * only frames, to make things easier and avoid queueing
154 ASSERT(skb_headroom(skb
) >= IRCOMM_HEADER_SIZE
, return -1;);
156 /* Don't forget to refcount it - see ircomm_tty_do_softint() */
159 skb_push(skb
, IRCOMM_HEADER_SIZE
);
163 ret
= irttp_data_request(self
->tsap
, skb
);
165 ERROR("%s(), failed\n", __FUNCTION__
);
166 /* irttp_data_request already free the packet */
173 * Function ircomm_ttp_data_indication (instance, sap, skb)
178 int ircomm_ttp_data_indication(void *instance
, void *sap
,
181 struct ircomm_cb
*self
= (struct ircomm_cb
*) instance
;
183 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
185 ASSERT(self
!= NULL
, return -1;);
186 ASSERT(self
->magic
== IRCOMM_MAGIC
, return -1;);
187 ASSERT(skb
!= NULL
, return -1;);
189 ircomm_do_event(self
, IRCOMM_TTP_DATA_INDICATION
, skb
, NULL
);
191 /* Drop reference count - see ircomm_tty_data_indication(). */
197 void ircomm_ttp_connect_confirm(void *instance
, void *sap
,
198 struct qos_info
*qos
,
200 __u8 max_header_size
,
203 struct ircomm_cb
*self
= (struct ircomm_cb
*) instance
;
204 struct ircomm_info info
;
206 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
208 ASSERT(self
!= NULL
, return;);
209 ASSERT(self
->magic
== IRCOMM_MAGIC
, return;);
210 ASSERT(skb
!= NULL
, return;);
211 ASSERT(qos
!= NULL
, goto out
;);
213 if (max_sdu_size
!= TTP_SAR_DISABLE
) {
214 ERROR("%s(), SAR not allowed for IrCOMM!\n", __FUNCTION__
);
218 info
.max_data_size
= irttp_get_max_seg_size(self
->tsap
)
219 - IRCOMM_HEADER_SIZE
;
220 info
.max_header_size
= max_header_size
+ IRCOMM_HEADER_SIZE
;
223 ircomm_do_event(self
, IRCOMM_TTP_CONNECT_CONFIRM
, skb
, &info
);
226 /* Drop reference count - see ircomm_tty_connect_confirm(). */
231 * Function ircomm_ttp_connect_indication (instance, sap, qos, max_sdu_size,
232 * max_header_size, skb)
237 void ircomm_ttp_connect_indication(void *instance
, void *sap
,
238 struct qos_info
*qos
,
240 __u8 max_header_size
,
243 struct ircomm_cb
*self
= (struct ircomm_cb
*)instance
;
244 struct ircomm_info info
;
246 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
248 ASSERT(self
!= NULL
, return;);
249 ASSERT(self
->magic
== IRCOMM_MAGIC
, return;);
250 ASSERT(skb
!= NULL
, return;);
251 ASSERT(qos
!= NULL
, goto out
;);
253 if (max_sdu_size
!= TTP_SAR_DISABLE
) {
254 ERROR("%s(), SAR not allowed for IrCOMM!\n", __FUNCTION__
);
258 info
.max_data_size
= irttp_get_max_seg_size(self
->tsap
)
259 - IRCOMM_HEADER_SIZE
;
260 info
.max_header_size
= max_header_size
+ IRCOMM_HEADER_SIZE
;
263 ircomm_do_event(self
, IRCOMM_TTP_CONNECT_INDICATION
, skb
, &info
);
266 /* Drop reference count - see ircomm_tty_connect_indication(). */
271 * Function ircomm_ttp_disconnect_request (self, userdata, info)
276 int ircomm_ttp_disconnect_request(struct ircomm_cb
*self
,
277 struct sk_buff
*userdata
,
278 struct ircomm_info
*info
)
282 /* Don't forget to refcount it - should be NULL anyway */
286 ret
= irttp_disconnect_request(self
->tsap
, userdata
, P_NORMAL
);
292 * Function ircomm_ttp_disconnect_indication (instance, sap, reason, skb)
297 void ircomm_ttp_disconnect_indication(void *instance
, void *sap
,
301 struct ircomm_cb
*self
= (struct ircomm_cb
*) instance
;
302 struct ircomm_info info
;
304 IRDA_DEBUG(2, "%s()\n", __FUNCTION__
);
306 ASSERT(self
!= NULL
, return;);
307 ASSERT(self
->magic
== IRCOMM_MAGIC
, return;);
309 info
.reason
= reason
;
311 ircomm_do_event(self
, IRCOMM_TTP_DISCONNECT_INDICATION
, skb
, &info
);
313 /* Drop reference count - see ircomm_tty_disconnect_indication(). */
319 * Function ircomm_ttp_flow_indication (instance, sap, cmd)
321 * Layer below is telling us to start or stop the flow of data
324 void ircomm_ttp_flow_indication(void *instance
, void *sap
, LOCAL_FLOW cmd
)
326 struct ircomm_cb
*self
= (struct ircomm_cb
*) instance
;
328 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
330 ASSERT(self
!= NULL
, return;);
331 ASSERT(self
->magic
== IRCOMM_MAGIC
, return;);
333 if (self
->notify
.flow_indication
)
334 self
->notify
.flow_indication(self
->notify
.instance
, self
, cmd
);