ALSA: hda - Fix pop noises on reboot for Dell XPS 13 9333
[linux/fpc-iii.git] / net / irda / ircomm / ircomm_ttp.c
blobd362d711b79c8cb36283667387e142538b1e515a
1 /*********************************************************************
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.
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,
41 struct sk_buff *skb);
42 static void ircomm_ttp_connect_confirm(void *instance, void *sap,
43 struct qos_info *qos,
44 __u32 max_sdu_size,
45 __u8 max_header_size,
46 struct sk_buff *skb);
47 static void ircomm_ttp_connect_indication(void *instance, void *sap,
48 struct qos_info *qos,
49 __u32 max_sdu_size,
50 __u8 max_header_size,
51 struct sk_buff *skb);
52 static void ircomm_ttp_flow_indication(void *instance, void *sap,
53 LOCAL_FLOW cmd);
54 static void ircomm_ttp_disconnect_indication(void *instance, void *sap,
55 LM_REASON reason,
56 struct sk_buff *skb);
57 static int ircomm_ttp_data_request(struct ircomm_cb *self,
58 struct sk_buff *skb,
59 int clen);
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)
77 notify_t notify;
79 IRDA_DEBUG(4, "%s()\n", __func__ );
81 /* Register callbacks */
82 irda_notify_init(&notify);
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,
92 &notify);
93 if (!self->tsap) {
94 IRDA_DEBUG(0, "%sfailed to allocate tsap\n", __func__ );
95 return -1;
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;
107 return 0;
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)
120 int ret = 0;
122 IRDA_DEBUG(4, "%s()\n", __func__ );
124 /* Don't forget to refcount it - should be NULL anyway */
125 if(userdata)
126 skb_get(userdata);
128 ret = irttp_connect_request(self->tsap, info->dlsap_sel,
129 info->saddr, info->daddr, NULL,
130 TTP_SAR_DISABLE, userdata);
132 return ret;
136 * Function ircomm_ttp_connect_response (self, skb)
141 static int ircomm_ttp_connect_response(struct ircomm_cb *self,
142 struct sk_buff *userdata)
144 int ret;
146 IRDA_DEBUG(4, "%s()\n", __func__ );
148 /* Don't forget to refcount it - should be NULL anyway */
149 if(userdata)
150 skb_get(userdata);
152 ret = irttp_connect_response(self->tsap, TTP_SAR_DISABLE, userdata);
154 return ret;
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,
167 struct sk_buff *skb,
168 int clen)
170 int ret;
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() */
183 skb_get(skb);
185 skb_push(skb, IRCOMM_HEADER_SIZE);
187 skb->data[0] = clen;
189 ret = irttp_data_request(self->tsap, skb);
190 if (ret) {
191 IRDA_ERROR("%s(), failed\n", __func__);
192 /* irttp_data_request already free the packet */
195 return ret;
199 * Function ircomm_ttp_data_indication (instance, sap, skb)
201 * Incoming data
204 static int ircomm_ttp_data_indication(void *instance, void *sap,
205 struct sk_buff *skb)
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(). */
218 dev_kfree_skb(skb);
220 return 0;
223 static void ircomm_ttp_connect_confirm(void *instance, void *sap,
224 struct qos_info *qos,
225 __u32 max_sdu_size,
226 __u8 max_header_size,
227 struct sk_buff *skb)
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",
241 __func__);
242 goto out;
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;
248 info.qos = qos;
250 ircomm_do_event(self, IRCOMM_TTP_CONNECT_CONFIRM, skb, &info);
252 out:
253 /* Drop reference count - see ircomm_tty_connect_confirm(). */
254 dev_kfree_skb(skb);
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,
266 __u32 max_sdu_size,
267 __u8 max_header_size,
268 struct sk_buff *skb)
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",
282 __func__);
283 goto out;
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;
289 info.qos = qos;
291 ircomm_do_event(self, IRCOMM_TTP_CONNECT_INDICATION, skb, &info);
293 out:
294 /* Drop reference count - see ircomm_tty_connect_indication(). */
295 dev_kfree_skb(skb);
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)
308 int ret;
310 /* Don't forget to refcount it - should be NULL anyway */
311 if(userdata)
312 skb_get(userdata);
314 ret = irttp_disconnect_request(self->tsap, userdata, P_NORMAL);
316 return ret;
320 * Function ircomm_ttp_disconnect_indication (instance, sap, reason, skb)
325 static void ircomm_ttp_disconnect_indication(void *instance, void *sap,
326 LM_REASON reason,
327 struct sk_buff *skb)
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(). */
342 if(skb)
343 dev_kfree_skb(skb);
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,
353 LOCAL_FLOW cmd)
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);