diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /net/irda/ircomm/ircomm_ttp.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'net/irda/ircomm/ircomm_ttp.c')
-rw-r--r-- | net/irda/ircomm/ircomm_ttp.c | 369 |
1 files changed, 369 insertions, 0 deletions
diff --git a/net/irda/ircomm/ircomm_ttp.c b/net/irda/ircomm/ircomm_ttp.c new file mode 100644 index 000000000000..d98bf3570d29 --- /dev/null +++ b/net/irda/ircomm/ircomm_ttp.c | |||
@@ -0,0 +1,369 @@ | |||
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> | ||
11 | * | ||
12 | * Copyright (c) 1999 Dag Brattli, All Rights Reserved. | ||
13 | * Copyright (c) 2000-2003 Jean Tourrilhes <jt@hpl.hp.com> | ||
14 | * | ||
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. | ||
19 | * | ||
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. | ||
24 | * | ||
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, | ||
28 | * MA 02111-1307 USA | ||
29 | * | ||
30 | ********************************************************************/ | ||
31 | |||
32 | #include <linux/sched.h> | ||
33 | #include <linux/init.h> | ||
34 | |||
35 | #include <net/irda/irda.h> | ||
36 | #include <net/irda/irlmp.h> | ||
37 | #include <net/irda/iriap.h> | ||
38 | #include <net/irda/irttp.h> | ||
39 | |||
40 | #include <net/irda/ircomm_event.h> | ||
41 | #include <net/irda/ircomm_ttp.h> | ||
42 | |||
43 | static int ircomm_ttp_data_indication(void *instance, void *sap, | ||
44 | struct sk_buff *skb); | ||
45 | static void ircomm_ttp_connect_confirm(void *instance, void *sap, | ||
46 | struct qos_info *qos, | ||
47 | __u32 max_sdu_size, | ||
48 | __u8 max_header_size, | ||
49 | struct sk_buff *skb); | ||
50 | static void ircomm_ttp_connect_indication(void *instance, void *sap, | ||
51 | struct qos_info *qos, | ||
52 | __u32 max_sdu_size, | ||
53 | __u8 max_header_size, | ||
54 | struct sk_buff *skb); | ||
55 | static void ircomm_ttp_flow_indication(void *instance, void *sap, | ||
56 | LOCAL_FLOW cmd); | ||
57 | static void ircomm_ttp_disconnect_indication(void *instance, void *sap, | ||
58 | LM_REASON reason, | ||
59 | struct sk_buff *skb); | ||
60 | static int ircomm_ttp_data_request(struct ircomm_cb *self, | ||
61 | struct sk_buff *skb, | ||
62 | int clen); | ||
63 | static int ircomm_ttp_connect_request(struct ircomm_cb *self, | ||
64 | struct sk_buff *userdata, | ||
65 | struct ircomm_info *info); | ||
66 | static int ircomm_ttp_connect_response(struct ircomm_cb *self, | ||
67 | struct sk_buff *userdata); | ||
68 | static int ircomm_ttp_disconnect_request(struct ircomm_cb *self, | ||
69 | struct sk_buff *userdata, | ||
70 | struct ircomm_info *info); | ||
71 | |||
72 | /* | ||
73 | * Function ircomm_open_tsap (self) | ||
74 | * | ||
75 | * | ||
76 | * | ||
77 | */ | ||
78 | int ircomm_open_tsap(struct ircomm_cb *self) | ||
79 | { | ||
80 | notify_t notify; | ||
81 | |||
82 | IRDA_DEBUG(4, "%s()\n", __FUNCTION__ ); | ||
83 | |||
84 | /* Register callbacks */ | ||
85 | irda_notify_init(¬ify); | ||
86 | notify.data_indication = ircomm_ttp_data_indication; | ||
87 | notify.connect_confirm = ircomm_ttp_connect_confirm; | ||
88 | notify.connect_indication = ircomm_ttp_connect_indication; | ||
89 | notify.flow_indication = ircomm_ttp_flow_indication; | ||
90 | notify.disconnect_indication = ircomm_ttp_disconnect_indication; | ||
91 | notify.instance = self; | ||
92 | strlcpy(notify.name, "IrCOMM", sizeof(notify.name)); | ||
93 | |||
94 | self->tsap = irttp_open_tsap(LSAP_ANY, DEFAULT_INITIAL_CREDIT, | ||
95 | ¬ify); | ||
96 | if (!self->tsap) { | ||
97 | IRDA_DEBUG(0, "%sfailed to allocate tsap\n", __FUNCTION__ ); | ||
98 | return -1; | ||
99 | } | ||
100 | self->slsap_sel = self->tsap->stsap_sel; | ||
101 | |||
102 | /* | ||
103 | * Initialize the call-table for issuing commands | ||
104 | */ | ||
105 | self->issue.data_request = ircomm_ttp_data_request; | ||
106 | self->issue.connect_request = ircomm_ttp_connect_request; | ||
107 | self->issue.connect_response = ircomm_ttp_connect_response; | ||
108 | self->issue.disconnect_request = ircomm_ttp_disconnect_request; | ||
109 | |||
110 | return 0; | ||
111 | } | ||
112 | |||
113 | /* | ||
114 | * Function ircomm_ttp_connect_request (self, userdata) | ||
115 | * | ||
116 | * | ||
117 | * | ||
118 | */ | ||
119 | static int ircomm_ttp_connect_request(struct ircomm_cb *self, | ||
120 | struct sk_buff *userdata, | ||
121 | struct ircomm_info *info) | ||
122 | { | ||
123 | int ret = 0; | ||
124 | |||
125 | IRDA_DEBUG(4, "%s()\n", __FUNCTION__ ); | ||
126 | |||
127 | /* Don't forget to refcount it - should be NULL anyway */ | ||
128 | if(userdata) | ||
129 | skb_get(userdata); | ||
130 | |||
131 | ret = irttp_connect_request(self->tsap, info->dlsap_sel, | ||
132 | info->saddr, info->daddr, NULL, | ||
133 | TTP_SAR_DISABLE, userdata); | ||
134 | |||
135 | return ret; | ||
136 | } | ||
137 | |||
138 | /* | ||
139 | * Function ircomm_ttp_connect_response (self, skb) | ||
140 | * | ||
141 | * | ||
142 | * | ||
143 | */ | ||
144 | static int ircomm_ttp_connect_response(struct ircomm_cb *self, | ||
145 | struct sk_buff *userdata) | ||
146 | { | ||
147 | int ret; | ||
148 | |||
149 | IRDA_DEBUG(4, "%s()\n", __FUNCTION__ ); | ||
150 | |||
151 | /* Don't forget to refcount it - should be NULL anyway */ | ||
152 | if(userdata) | ||
153 | skb_get(userdata); | ||
154 | |||
155 | ret = irttp_connect_response(self->tsap, TTP_SAR_DISABLE, userdata); | ||
156 | |||
157 | return ret; | ||
158 | } | ||
159 | |||
160 | /* | ||
161 | * Function ircomm_ttp_data_request (self, userdata) | ||
162 | * | ||
163 | * Send IrCOMM data to IrTTP layer. Currently we do not try to combine | ||
164 | * control data with pure data, so they will be sent as separate frames. | ||
165 | * Should not be a big problem though, since control frames are rare. But | ||
166 | * some of them are sent after connection establishment, so this can | ||
167 | * increase the latency a bit. | ||
168 | */ | ||
169 | static int ircomm_ttp_data_request(struct ircomm_cb *self, | ||
170 | struct sk_buff *skb, | ||
171 | int clen) | ||
172 | { | ||
173 | int ret; | ||
174 | |||
175 | IRDA_ASSERT(skb != NULL, return -1;); | ||
176 | |||
177 | IRDA_DEBUG(2, "%s(), clen=%d\n", __FUNCTION__ , clen); | ||
178 | |||
179 | /* | ||
180 | * Insert clen field, currently we either send data only, or control | ||
181 | * only frames, to make things easier and avoid queueing | ||
182 | */ | ||
183 | IRDA_ASSERT(skb_headroom(skb) >= IRCOMM_HEADER_SIZE, return -1;); | ||
184 | |||
185 | /* Don't forget to refcount it - see ircomm_tty_do_softint() */ | ||
186 | skb_get(skb); | ||
187 | |||
188 | skb_push(skb, IRCOMM_HEADER_SIZE); | ||
189 | |||
190 | skb->data[0] = clen; | ||
191 | |||
192 | ret = irttp_data_request(self->tsap, skb); | ||
193 | if (ret) { | ||
194 | IRDA_ERROR("%s(), failed\n", __FUNCTION__); | ||
195 | /* irttp_data_request already free the packet */ | ||
196 | } | ||
197 | |||
198 | return ret; | ||
199 | } | ||
200 | |||
201 | /* | ||
202 | * Function ircomm_ttp_data_indication (instance, sap, skb) | ||
203 | * | ||
204 | * Incoming data | ||
205 | * | ||
206 | */ | ||
207 | static int ircomm_ttp_data_indication(void *instance, void *sap, | ||
208 | struct sk_buff *skb) | ||
209 | { | ||
210 | struct ircomm_cb *self = (struct ircomm_cb *) instance; | ||
211 | |||
212 | IRDA_DEBUG(4, "%s()\n", __FUNCTION__ ); | ||
213 | |||
214 | IRDA_ASSERT(self != NULL, return -1;); | ||
215 | IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return -1;); | ||
216 | IRDA_ASSERT(skb != NULL, return -1;); | ||
217 | |||
218 | ircomm_do_event(self, IRCOMM_TTP_DATA_INDICATION, skb, NULL); | ||
219 | |||
220 | /* Drop reference count - see ircomm_tty_data_indication(). */ | ||
221 | dev_kfree_skb(skb); | ||
222 | |||
223 | return 0; | ||
224 | } | ||
225 | |||
226 | static void ircomm_ttp_connect_confirm(void *instance, void *sap, | ||
227 | struct qos_info *qos, | ||
228 | __u32 max_sdu_size, | ||
229 | __u8 max_header_size, | ||
230 | struct sk_buff *skb) | ||
231 | { | ||
232 | struct ircomm_cb *self = (struct ircomm_cb *) instance; | ||
233 | struct ircomm_info info; | ||
234 | |||
235 | IRDA_DEBUG(4, "%s()\n", __FUNCTION__ ); | ||
236 | |||
237 | IRDA_ASSERT(self != NULL, return;); | ||
238 | IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return;); | ||
239 | IRDA_ASSERT(skb != NULL, return;); | ||
240 | IRDA_ASSERT(qos != NULL, goto out;); | ||
241 | |||
242 | if (max_sdu_size != TTP_SAR_DISABLE) { | ||
243 | IRDA_ERROR("%s(), SAR not allowed for IrCOMM!\n", | ||
244 | __FUNCTION__); | ||
245 | goto out; | ||
246 | } | ||
247 | |||
248 | info.max_data_size = irttp_get_max_seg_size(self->tsap) | ||
249 | - IRCOMM_HEADER_SIZE; | ||
250 | info.max_header_size = max_header_size + IRCOMM_HEADER_SIZE; | ||
251 | info.qos = qos; | ||
252 | |||
253 | ircomm_do_event(self, IRCOMM_TTP_CONNECT_CONFIRM, skb, &info); | ||
254 | |||
255 | out: | ||
256 | /* Drop reference count - see ircomm_tty_connect_confirm(). */ | ||
257 | dev_kfree_skb(skb); | ||
258 | } | ||
259 | |||
260 | /* | ||
261 | * Function ircomm_ttp_connect_indication (instance, sap, qos, max_sdu_size, | ||
262 | * max_header_size, skb) | ||
263 | * | ||
264 | * | ||
265 | * | ||
266 | */ | ||
267 | static void ircomm_ttp_connect_indication(void *instance, void *sap, | ||
268 | struct qos_info *qos, | ||
269 | __u32 max_sdu_size, | ||
270 | __u8 max_header_size, | ||
271 | struct sk_buff *skb) | ||
272 | { | ||
273 | struct ircomm_cb *self = (struct ircomm_cb *)instance; | ||
274 | struct ircomm_info info; | ||
275 | |||
276 | IRDA_DEBUG(4, "%s()\n", __FUNCTION__ ); | ||
277 | |||
278 | IRDA_ASSERT(self != NULL, return;); | ||
279 | IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return;); | ||
280 | IRDA_ASSERT(skb != NULL, return;); | ||
281 | IRDA_ASSERT(qos != NULL, goto out;); | ||
282 | |||
283 | if (max_sdu_size != TTP_SAR_DISABLE) { | ||
284 | IRDA_ERROR("%s(), SAR not allowed for IrCOMM!\n", | ||
285 | __FUNCTION__); | ||
286 | goto out; | ||
287 | } | ||
288 | |||
289 | info.max_data_size = irttp_get_max_seg_size(self->tsap) | ||
290 | - IRCOMM_HEADER_SIZE; | ||
291 | info.max_header_size = max_header_size + IRCOMM_HEADER_SIZE; | ||
292 | info.qos = qos; | ||
293 | |||
294 | ircomm_do_event(self, IRCOMM_TTP_CONNECT_INDICATION, skb, &info); | ||
295 | |||
296 | out: | ||
297 | /* Drop reference count - see ircomm_tty_connect_indication(). */ | ||
298 | dev_kfree_skb(skb); | ||
299 | } | ||
300 | |||
301 | /* | ||
302 | * Function ircomm_ttp_disconnect_request (self, userdata, info) | ||
303 | * | ||
304 | * | ||
305 | * | ||
306 | */ | ||
307 | static int ircomm_ttp_disconnect_request(struct ircomm_cb *self, | ||
308 | struct sk_buff *userdata, | ||
309 | struct ircomm_info *info) | ||
310 | { | ||
311 | int ret; | ||
312 | |||
313 | /* Don't forget to refcount it - should be NULL anyway */ | ||
314 | if(userdata) | ||
315 | skb_get(userdata); | ||
316 | |||
317 | ret = irttp_disconnect_request(self->tsap, userdata, P_NORMAL); | ||
318 | |||
319 | return ret; | ||
320 | } | ||
321 | |||
322 | /* | ||
323 | * Function ircomm_ttp_disconnect_indication (instance, sap, reason, skb) | ||
324 | * | ||
325 | * | ||
326 | * | ||
327 | */ | ||
328 | static void ircomm_ttp_disconnect_indication(void *instance, void *sap, | ||
329 | LM_REASON reason, | ||
330 | struct sk_buff *skb) | ||
331 | { | ||
332 | struct ircomm_cb *self = (struct ircomm_cb *) instance; | ||
333 | struct ircomm_info info; | ||
334 | |||
335 | IRDA_DEBUG(2, "%s()\n", __FUNCTION__ ); | ||
336 | |||
337 | IRDA_ASSERT(self != NULL, return;); | ||
338 | IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return;); | ||
339 | |||
340 | info.reason = reason; | ||
341 | |||
342 | ircomm_do_event(self, IRCOMM_TTP_DISCONNECT_INDICATION, skb, &info); | ||
343 | |||
344 | /* Drop reference count - see ircomm_tty_disconnect_indication(). */ | ||
345 | if(skb) | ||
346 | dev_kfree_skb(skb); | ||
347 | } | ||
348 | |||
349 | /* | ||
350 | * Function ircomm_ttp_flow_indication (instance, sap, cmd) | ||
351 | * | ||
352 | * Layer below is telling us to start or stop the flow of data | ||
353 | * | ||
354 | */ | ||
355 | static void ircomm_ttp_flow_indication(void *instance, void *sap, | ||
356 | LOCAL_FLOW cmd) | ||
357 | { | ||
358 | struct ircomm_cb *self = (struct ircomm_cb *) instance; | ||
359 | |||
360 | IRDA_DEBUG(4, "%s()\n", __FUNCTION__ ); | ||
361 | |||
362 | IRDA_ASSERT(self != NULL, return;); | ||
363 | IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return;); | ||
364 | |||
365 | if (self->notify.flow_indication) | ||
366 | self->notify.flow_indication(self->notify.instance, self, cmd); | ||
367 | } | ||
368 | |||
369 | |||