Ok. I didn't make 2.4.0 in 2000. Tough. I tried, but we had some
[davej-history.git] / net / irda / ircomm / ircomm_ttp.c
blob642b8416afeeb7e01488755c69728d6d74ad47f4
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.
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 * MA 02111-1307 USA
29 ********************************************************************/
31 #include <linux/sched.h>
32 #include <linux/init.h>
34 #include <net/irda/irda.h>
35 #include <net/irda/irlmp.h>
36 #include <net/irda/iriap.h>
37 #include <net/irda/irttp.h>
39 #include <net/irda/ircomm_event.h>
40 #include <net/irda/ircomm_ttp.h>
43 * Function ircomm_open_tsap (self)
48 int ircomm_open_tsap(struct ircomm_cb *self)
50 notify_t notify;
52 IRDA_DEBUG(4, __FUNCTION__ "()\n");
54 /* Register callbacks */
55 irda_notify_init(&notify);
56 notify.data_indication = ircomm_ttp_data_indication;
57 notify.connect_confirm = ircomm_ttp_connect_confirm;
58 notify.connect_indication = ircomm_ttp_connect_indication;
59 notify.flow_indication = ircomm_ttp_flow_indication;
60 notify.disconnect_indication = ircomm_ttp_disconnect_indication;
61 notify.instance = self;
62 strncpy(notify.name, "IrCOMM", NOTIFY_MAX_NAME);
64 self->tsap = irttp_open_tsap(LSAP_ANY, DEFAULT_INITIAL_CREDIT,
65 &notify);
66 if (!self->tsap) {
67 IRDA_DEBUG(0, __FUNCTION__"failed to allocate tsap\n");
68 return -1;
70 self->slsap_sel = self->tsap->stsap_sel;
73 * Initialize the call-table for issuing commands
75 self->issue.data_request = ircomm_ttp_data_request;
76 self->issue.connect_request = ircomm_ttp_connect_request;
77 self->issue.connect_response = ircomm_ttp_connect_response;
78 self->issue.disconnect_request = ircomm_ttp_disconnect_request;
80 return 0;
84 * Function ircomm_ttp_connect_request (self, userdata)
89 int ircomm_ttp_connect_request(struct ircomm_cb *self,
90 struct sk_buff *userdata,
91 struct ircomm_info *info)
93 int ret = 0;
95 IRDA_DEBUG(4, __FUNCTION__ "()\n");
97 ret = irttp_connect_request(self->tsap, info->dlsap_sel,
98 info->saddr, info->daddr, NULL,
99 TTP_SAR_DISABLE, userdata);
100 return ret;
104 * Function ircomm_ttp_connect_response (self, skb)
109 int ircomm_ttp_connect_response(struct ircomm_cb *self, struct sk_buff *skb)
111 int ret;
113 IRDA_DEBUG(4, __FUNCTION__"()\n");
115 ret = irttp_connect_response(self->tsap, TTP_SAR_DISABLE, skb);
117 return ret;
121 * Function ircomm_ttp_data_request (self, userdata)
123 * Send IrCOMM data to IrTTP layer. Currently we do not try to combine
124 * control data with pure data, so they will be sent as separate frames.
125 * Should not be a big problem though, since control frames are rare. But
126 * some of them are sent after connection establishment, so this can
127 * increase the latency a bit.
129 int ircomm_ttp_data_request(struct ircomm_cb *self, struct sk_buff *skb,
130 int clen)
132 int ret;
134 ASSERT(skb != NULL, return -1;);
136 IRDA_DEBUG(2, __FUNCTION__"(), clen=%d\n", clen);
139 * Insert clen field, currently we either send data only, or control
140 * only frames, to make things easier and avoid queueing
142 ASSERT(skb_headroom(skb) >= IRCOMM_HEADER_SIZE, return -1;);
143 skb_push(skb, IRCOMM_HEADER_SIZE);
145 skb->data[0] = clen;
147 ret = irttp_data_request(self->tsap, skb);
148 if (ret) {
149 ERROR(__FUNCTION__ "(), failed\n");
150 dev_kfree_skb(skb);
153 return ret;
157 * Function ircomm_ttp_data_indication (instance, sap, skb)
159 * Incomming data
162 int ircomm_ttp_data_indication(void *instance, void *sap,
163 struct sk_buff *skb)
165 struct ircomm_cb *self = (struct ircomm_cb *) instance;
167 IRDA_DEBUG(4, __FUNCTION__"()\n");
169 ASSERT(self != NULL, return -1;);
170 ASSERT(self->magic == IRCOMM_MAGIC, return -1;);
171 ASSERT(skb != NULL, return -1;);
173 ircomm_do_event(self, IRCOMM_TTP_DATA_INDICATION, skb, NULL);
175 return 0;
178 void ircomm_ttp_connect_confirm(void *instance, void *sap,
179 struct qos_info *qos,
180 __u32 max_sdu_size,
181 __u8 max_header_size,
182 struct sk_buff *skb)
184 struct ircomm_cb *self = (struct ircomm_cb *) instance;
185 struct ircomm_info info;
187 IRDA_DEBUG(4, __FUNCTION__"()\n");
189 ASSERT(self != NULL, return;);
190 ASSERT(self->magic == IRCOMM_MAGIC, return;);
191 ASSERT(skb != NULL, return;);
192 ASSERT(qos != NULL, return;);
194 if (max_sdu_size != TTP_SAR_DISABLE) {
195 ERROR(__FUNCTION__ "(), SAR not allowed for IrCOMM!\n");
196 dev_kfree_skb(skb);
197 return;
200 info.max_data_size = irttp_get_max_seg_size(self->tsap)
201 - IRCOMM_HEADER_SIZE;
202 info.max_header_size = max_header_size + IRCOMM_HEADER_SIZE;
203 info.qos = qos;
205 ircomm_do_event(self, IRCOMM_TTP_CONNECT_CONFIRM, skb, &info);
209 * Function ircomm_ttp_connect_indication (instance, sap, qos, max_sdu_size,
210 * max_header_size, skb)
215 void ircomm_ttp_connect_indication(void *instance, void *sap,
216 struct qos_info *qos,
217 __u32 max_sdu_size,
218 __u8 max_header_size,
219 struct sk_buff *skb)
221 struct ircomm_cb *self = (struct ircomm_cb *)instance;
222 struct ircomm_info info;
224 IRDA_DEBUG(4, __FUNCTION__"()\n");
226 ASSERT(self != NULL, return;);
227 ASSERT(self->magic == IRCOMM_MAGIC, return;);
228 ASSERT(skb != NULL, return;);
229 ASSERT(qos != NULL, return;);
231 if (max_sdu_size != TTP_SAR_DISABLE) {
232 ERROR(__FUNCTION__ "(), SAR not allowed for IrCOMM!\n");
233 dev_kfree_skb(skb);
234 return;
237 info.max_data_size = irttp_get_max_seg_size(self->tsap)
238 - IRCOMM_HEADER_SIZE;
239 info.max_header_size = max_header_size + IRCOMM_HEADER_SIZE;
240 info.qos = qos;
242 ircomm_do_event(self, IRCOMM_TTP_CONNECT_INDICATION, skb, &info);
246 * Function ircomm_ttp_disconnect_request (self, userdata, info)
251 int ircomm_ttp_disconnect_request(struct ircomm_cb *self,
252 struct sk_buff *userdata,
253 struct ircomm_info *info)
255 int ret;
257 ret = irttp_disconnect_request(self->tsap, userdata, P_NORMAL);
259 return ret;
263 * Function ircomm_ttp_disconnect_indication (instance, sap, reason, skb)
268 void ircomm_ttp_disconnect_indication(void *instance, void *sap,
269 LM_REASON reason,
270 struct sk_buff *skb)
272 struct ircomm_cb *self = (struct ircomm_cb *) instance;
273 struct ircomm_info info;
275 IRDA_DEBUG(2, __FUNCTION__"()\n");
277 ASSERT(self != NULL, return;);
278 ASSERT(self->magic == IRCOMM_MAGIC, return;);
280 info.reason = reason;
282 ircomm_do_event(self, IRCOMM_TTP_DISCONNECT_INDICATION, skb, &info);
286 * Function ircomm_ttp_flow_indication (instance, sap, cmd)
288 * Layer below is telling us to start or stop the flow of data
291 void ircomm_ttp_flow_indication(void *instance, void *sap, LOCAL_FLOW cmd)
293 struct ircomm_cb *self = (struct ircomm_cb *) instance;
295 IRDA_DEBUG(4, __FUNCTION__ "()\n");
297 ASSERT(self != NULL, return;);
298 ASSERT(self->magic == IRCOMM_MAGIC, return;);
300 if (self->notify.flow_indication)
301 self->notify.flow_indication(self->notify.instance, self, cmd);