Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /********************************************************************* |
6819bc2e | 2 | * |
1da177e4 LT |
3 | * Filename: ircomm_param.c |
4 | * Version: 1.0 | |
5 | * Description: Parameter handling for the IrCOMM protocol | |
6 | * Status: Experimental. | |
7 | * Author: Dag Brattli <dagb@cs.uit.no> | |
8 | * Created at: Mon Jun 7 10:25:11 1999 | |
9 | * Modified at: Sun Jan 30 14:32:03 2000 | |
10 | * Modified by: Dag Brattli <dagb@cs.uit.no> | |
6819bc2e | 11 | * |
1da177e4 | 12 | * Copyright (c) 1999-2000 Dag Brattli, All Rights Reserved. |
6819bc2e YH |
13 | * |
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 | |
1da177e4 | 17 | * the License, or (at your option) any later version. |
6819bc2e | 18 | * |
1da177e4 LT |
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. | |
6819bc2e YH |
23 | * |
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, | |
1da177e4 | 27 | * MA 02111-1307 USA |
6819bc2e | 28 | * |
1da177e4 LT |
29 | ********************************************************************/ |
30 | ||
1da177e4 LT |
31 | #include <linux/workqueue.h> |
32 | #include <linux/interrupt.h> | |
33 | ||
34 | #include <net/irda/irda.h> | |
35 | #include <net/irda/parameters.h> | |
36 | ||
37 | #include <net/irda/ircomm_core.h> | |
38 | #include <net/irda/ircomm_tty_attach.h> | |
39 | #include <net/irda/ircomm_tty.h> | |
40 | ||
41 | #include <net/irda/ircomm_param.h> | |
42 | ||
6819bc2e | 43 | static int ircomm_param_service_type(void *instance, irda_param_t *param, |
1da177e4 | 44 | int get); |
6819bc2e | 45 | static int ircomm_param_port_type(void *instance, irda_param_t *param, |
1da177e4 | 46 | int get); |
6819bc2e | 47 | static int ircomm_param_port_name(void *instance, irda_param_t *param, |
1da177e4 | 48 | int get); |
6819bc2e | 49 | static int ircomm_param_service_type(void *instance, irda_param_t *param, |
1da177e4 | 50 | int get); |
6819bc2e | 51 | static int ircomm_param_data_rate(void *instance, irda_param_t *param, |
1da177e4 | 52 | int get); |
6819bc2e | 53 | static int ircomm_param_data_format(void *instance, irda_param_t *param, |
1da177e4 | 54 | int get); |
6819bc2e | 55 | static int ircomm_param_flow_control(void *instance, irda_param_t *param, |
1da177e4 LT |
56 | int get); |
57 | static int ircomm_param_xon_xoff(void *instance, irda_param_t *param, int get); | |
58 | static int ircomm_param_enq_ack(void *instance, irda_param_t *param, int get); | |
6819bc2e | 59 | static int ircomm_param_line_status(void *instance, irda_param_t *param, |
1da177e4 LT |
60 | int get); |
61 | static int ircomm_param_dte(void *instance, irda_param_t *param, int get); | |
62 | static int ircomm_param_dce(void *instance, irda_param_t *param, int get); | |
63 | static int ircomm_param_poll(void *instance, irda_param_t *param, int get); | |
64 | ||
65 | static pi_minor_info_t pi_minor_call_table_common[] = { | |
66 | { ircomm_param_service_type, PV_INT_8_BITS }, | |
67 | { ircomm_param_port_type, PV_INT_8_BITS }, | |
68 | { ircomm_param_port_name, PV_STRING } | |
69 | }; | |
70 | static pi_minor_info_t pi_minor_call_table_non_raw[] = { | |
71 | { ircomm_param_data_rate, PV_INT_32_BITS | PV_BIG_ENDIAN }, | |
72 | { ircomm_param_data_format, PV_INT_8_BITS }, | |
73 | { ircomm_param_flow_control, PV_INT_8_BITS }, | |
74 | { ircomm_param_xon_xoff, PV_INT_16_BITS }, | |
75 | { ircomm_param_enq_ack, PV_INT_16_BITS }, | |
76 | { ircomm_param_line_status, PV_INT_8_BITS } | |
77 | }; | |
78 | static pi_minor_info_t pi_minor_call_table_9_wire[] = { | |
79 | { ircomm_param_dte, PV_INT_8_BITS }, | |
80 | { ircomm_param_dce, PV_INT_8_BITS }, | |
81 | { ircomm_param_poll, PV_NO_VALUE }, | |
82 | }; | |
83 | ||
84 | static pi_major_info_t pi_major_call_table[] = { | |
85 | { pi_minor_call_table_common, 3 }, | |
86 | { pi_minor_call_table_non_raw, 6 }, | |
6819bc2e | 87 | { pi_minor_call_table_9_wire, 3 } |
1da177e4 LT |
88 | /* { pi_minor_call_table_centronics } */ |
89 | }; | |
90 | ||
91 | pi_param_info_t ircomm_param_info = { pi_major_call_table, 3, 0x0f, 4 }; | |
92 | ||
93 | /* | |
94 | * Function ircomm_param_request (self, pi, flush) | |
95 | * | |
96 | * Queue a parameter for the control channel | |
97 | * | |
98 | */ | |
99 | int ircomm_param_request(struct ircomm_tty_cb *self, __u8 pi, int flush) | |
100 | { | |
101 | struct tty_struct *tty; | |
102 | unsigned long flags; | |
103 | struct sk_buff *skb; | |
104 | int count; | |
105 | ||
0dc47877 | 106 | IRDA_DEBUG(2, "%s()\n", __func__ ); |
1da177e4 LT |
107 | |
108 | IRDA_ASSERT(self != NULL, return -1;); | |
109 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;); | |
110 | ||
111 | tty = self->tty; | |
112 | if (!tty) | |
113 | return 0; | |
114 | ||
115 | /* Make sure we don't send parameters for raw mode */ | |
116 | if (self->service_type == IRCOMM_3_WIRE_RAW) | |
117 | return 0; | |
118 | ||
119 | spin_lock_irqsave(&self->spinlock, flags); | |
120 | ||
6819bc2e | 121 | skb = self->ctrl_skb; |
1da177e4 | 122 | if (!skb) { |
485fb2c9 | 123 | skb = alloc_skb(256, GFP_ATOMIC); |
1da177e4 LT |
124 | if (!skb) { |
125 | spin_unlock_irqrestore(&self->spinlock, flags); | |
126 | return -ENOMEM; | |
127 | } | |
6819bc2e | 128 | |
1da177e4 LT |
129 | skb_reserve(skb, self->max_header_size); |
130 | self->ctrl_skb = skb; | |
131 | } | |
6819bc2e | 132 | /* |
1da177e4 | 133 | * Inserting is a little bit tricky since we don't know how much |
6819bc2e | 134 | * room we will need. But this should hopefully work OK |
1da177e4 | 135 | */ |
27a884dc ACM |
136 | count = irda_param_insert(self, pi, skb_tail_pointer(skb), |
137 | skb_tailroom(skb), &ircomm_param_info); | |
1da177e4 | 138 | if (count < 0) { |
0dc47877 | 139 | IRDA_WARNING("%s(), no room for parameter!\n", __func__); |
1da177e4 LT |
140 | spin_unlock_irqrestore(&self->spinlock, flags); |
141 | return -1; | |
142 | } | |
143 | skb_put(skb, count); | |
144 | ||
145 | spin_unlock_irqrestore(&self->spinlock, flags); | |
146 | ||
0dc47877 | 147 | IRDA_DEBUG(2, "%s(), skb->len=%d\n", __func__ , skb->len); |
1da177e4 LT |
148 | |
149 | if (flush) { | |
150 | /* ircomm_tty_do_softint will take care of the rest */ | |
151 | schedule_work(&self->tqueue); | |
152 | } | |
153 | ||
154 | return count; | |
155 | } | |
156 | ||
157 | /* | |
158 | * Function ircomm_param_service_type (self, buf, len) | |
159 | * | |
160 | * Handle service type, this function will both be called after the LM-IAS | |
161 | * query and then the remote device sends its initial parameters | |
162 | * | |
163 | */ | |
6819bc2e | 164 | static int ircomm_param_service_type(void *instance, irda_param_t *param, |
1da177e4 LT |
165 | int get) |
166 | { | |
167 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance; | |
168 | __u8 service_type = (__u8) param->pv.i; | |
169 | ||
170 | IRDA_ASSERT(self != NULL, return -1;); | |
171 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;); | |
172 | ||
173 | if (get) { | |
174 | param->pv.i = self->settings.service_type; | |
175 | return 0; | |
176 | } | |
177 | ||
178 | /* Find all common service types */ | |
179 | service_type &= self->service_type; | |
180 | if (!service_type) { | |
6819bc2e | 181 | IRDA_DEBUG(2, |
0dc47877 | 182 | "%s(), No common service type to use!\n", __func__ ); |
1da177e4 LT |
183 | return -1; |
184 | } | |
0dc47877 | 185 | IRDA_DEBUG(0, "%s(), services in common=%02x\n", __func__ , |
1da177e4 LT |
186 | service_type); |
187 | ||
188 | /* | |
189 | * Now choose a preferred service type of those available | |
190 | */ | |
191 | if (service_type & IRCOMM_CENTRONICS) | |
192 | self->settings.service_type = IRCOMM_CENTRONICS; | |
193 | else if (service_type & IRCOMM_9_WIRE) | |
194 | self->settings.service_type = IRCOMM_9_WIRE; | |
195 | else if (service_type & IRCOMM_3_WIRE) | |
196 | self->settings.service_type = IRCOMM_3_WIRE; | |
197 | else if (service_type & IRCOMM_3_WIRE_RAW) | |
198 | self->settings.service_type = IRCOMM_3_WIRE_RAW; | |
199 | ||
0dc47877 | 200 | IRDA_DEBUG(0, "%s(), resulting service type=0x%02x\n", __func__ , |
1da177e4 LT |
201 | self->settings.service_type); |
202 | ||
6819bc2e | 203 | /* |
1da177e4 | 204 | * Now the line is ready for some communication. Check if we are a |
6819bc2e | 205 | * server, and send over some initial parameters. |
1da177e4 LT |
206 | * Client do it in ircomm_tty_state_setup(). |
207 | * Note : we may get called from ircomm_tty_getvalue_confirm(), | |
208 | * therefore before we even have open any socket. And self->client | |
209 | * is initialised to TRUE only later. So, we check if the link is | |
210 | * really initialised. - Jean II | |
211 | */ | |
212 | if ((self->max_header_size != IRCOMM_TTY_HDR_UNINITIALISED) && | |
213 | (!self->client) && | |
214 | (self->settings.service_type != IRCOMM_3_WIRE_RAW)) | |
215 | { | |
216 | /* Init connection */ | |
217 | ircomm_tty_send_initial_parameters(self); | |
218 | ircomm_tty_link_established(self); | |
219 | } | |
220 | ||
221 | return 0; | |
222 | } | |
223 | ||
224 | /* | |
225 | * Function ircomm_param_port_type (self, param) | |
226 | * | |
227 | * The port type parameter tells if the devices are serial or parallel. | |
228 | * Since we only advertise serial service, this parameter should only | |
229 | * be equal to IRCOMM_SERIAL. | |
230 | */ | |
231 | static int ircomm_param_port_type(void *instance, irda_param_t *param, int get) | |
232 | { | |
233 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance; | |
234 | ||
235 | IRDA_ASSERT(self != NULL, return -1;); | |
236 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;); | |
6819bc2e | 237 | |
1da177e4 LT |
238 | if (get) |
239 | param->pv.i = IRCOMM_SERIAL; | |
240 | else { | |
241 | self->settings.port_type = (__u8) param->pv.i; | |
242 | ||
0dc47877 | 243 | IRDA_DEBUG(0, "%s(), port type=%d\n", __func__ , |
1da177e4 LT |
244 | self->settings.port_type); |
245 | } | |
246 | return 0; | |
247 | } | |
248 | ||
249 | /* | |
250 | * Function ircomm_param_port_name (self, param) | |
251 | * | |
252 | * Exchange port name | |
253 | * | |
254 | */ | |
255 | static int ircomm_param_port_name(void *instance, irda_param_t *param, int get) | |
256 | { | |
257 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance; | |
6819bc2e | 258 | |
1da177e4 LT |
259 | IRDA_ASSERT(self != NULL, return -1;); |
260 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;); | |
261 | ||
262 | if (get) { | |
0dc47877 | 263 | IRDA_DEBUG(0, "%s(), not imp!\n", __func__ ); |
1da177e4 | 264 | } else { |
0dc47877 | 265 | IRDA_DEBUG(0, "%s(), port-name=%s\n", __func__ , param->pv.c); |
1da177e4 LT |
266 | strncpy(self->settings.port_name, param->pv.c, 32); |
267 | } | |
268 | ||
269 | return 0; | |
270 | } | |
271 | ||
272 | /* | |
273 | * Function ircomm_param_data_rate (self, param) | |
274 | * | |
275 | * Exchange data rate to be used in this settings | |
276 | * | |
277 | */ | |
278 | static int ircomm_param_data_rate(void *instance, irda_param_t *param, int get) | |
279 | { | |
280 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance; | |
6819bc2e | 281 | |
1da177e4 LT |
282 | IRDA_ASSERT(self != NULL, return -1;); |
283 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;); | |
284 | ||
285 | if (get) | |
286 | param->pv.i = self->settings.data_rate; | |
287 | else | |
288 | self->settings.data_rate = param->pv.i; | |
6819bc2e | 289 | |
0dc47877 | 290 | IRDA_DEBUG(2, "%s(), data rate = %d\n", __func__ , param->pv.i); |
1da177e4 LT |
291 | |
292 | return 0; | |
293 | } | |
294 | ||
295 | /* | |
296 | * Function ircomm_param_data_format (self, param) | |
297 | * | |
298 | * Exchange data format to be used in this settings | |
299 | * | |
300 | */ | |
6819bc2e | 301 | static int ircomm_param_data_format(void *instance, irda_param_t *param, |
1da177e4 LT |
302 | int get) |
303 | { | |
304 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance; | |
305 | ||
306 | IRDA_ASSERT(self != NULL, return -1;); | |
307 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;); | |
308 | ||
309 | if (get) | |
310 | param->pv.i = self->settings.data_format; | |
311 | else | |
312 | self->settings.data_format = (__u8) param->pv.i; | |
6819bc2e | 313 | |
1da177e4 LT |
314 | return 0; |
315 | } | |
316 | ||
317 | /* | |
318 | * Function ircomm_param_flow_control (self, param) | |
319 | * | |
320 | * Exchange flow control settings to be used in this settings | |
321 | * | |
322 | */ | |
6819bc2e | 323 | static int ircomm_param_flow_control(void *instance, irda_param_t *param, |
1da177e4 LT |
324 | int get) |
325 | { | |
326 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance; | |
327 | ||
328 | IRDA_ASSERT(self != NULL, return -1;); | |
329 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;); | |
6819bc2e | 330 | |
1da177e4 LT |
331 | if (get) |
332 | param->pv.i = self->settings.flow_control; | |
333 | else | |
334 | self->settings.flow_control = (__u8) param->pv.i; | |
335 | ||
0dc47877 | 336 | IRDA_DEBUG(1, "%s(), flow control = 0x%02x\n", __func__ , (__u8) param->pv.i); |
1da177e4 LT |
337 | |
338 | return 0; | |
339 | } | |
340 | ||
341 | /* | |
342 | * Function ircomm_param_xon_xoff (self, param) | |
343 | * | |
344 | * Exchange XON/XOFF characters | |
345 | * | |
346 | */ | |
347 | static int ircomm_param_xon_xoff(void *instance, irda_param_t *param, int get) | |
348 | { | |
349 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance; | |
350 | ||
351 | IRDA_ASSERT(self != NULL, return -1;); | |
352 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;); | |
6819bc2e | 353 | |
1da177e4 LT |
354 | if (get) { |
355 | param->pv.i = self->settings.xonxoff[0]; | |
356 | param->pv.i |= self->settings.xonxoff[1] << 8; | |
357 | } else { | |
358 | self->settings.xonxoff[0] = (__u16) param->pv.i & 0xff; | |
359 | self->settings.xonxoff[1] = (__u16) param->pv.i >> 8; | |
360 | } | |
361 | ||
0dc47877 | 362 | IRDA_DEBUG(0, "%s(), XON/XOFF = 0x%02x,0x%02x\n", __func__ , |
1da177e4 LT |
363 | param->pv.i & 0xff, param->pv.i >> 8); |
364 | ||
365 | return 0; | |
366 | } | |
367 | ||
368 | /* | |
369 | * Function ircomm_param_enq_ack (self, param) | |
370 | * | |
371 | * Exchange ENQ/ACK characters | |
372 | * | |
373 | */ | |
374 | static int ircomm_param_enq_ack(void *instance, irda_param_t *param, int get) | |
375 | { | |
376 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance; | |
377 | ||
378 | IRDA_ASSERT(self != NULL, return -1;); | |
379 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;); | |
6819bc2e | 380 | |
1da177e4 LT |
381 | if (get) { |
382 | param->pv.i = self->settings.enqack[0]; | |
383 | param->pv.i |= self->settings.enqack[1] << 8; | |
384 | } else { | |
385 | self->settings.enqack[0] = (__u16) param->pv.i & 0xff; | |
386 | self->settings.enqack[1] = (__u16) param->pv.i >> 8; | |
387 | } | |
388 | ||
0dc47877 | 389 | IRDA_DEBUG(0, "%s(), ENQ/ACK = 0x%02x,0x%02x\n", __func__ , |
1da177e4 LT |
390 | param->pv.i & 0xff, param->pv.i >> 8); |
391 | ||
392 | return 0; | |
393 | } | |
394 | ||
395 | /* | |
396 | * Function ircomm_param_line_status (self, param) | |
397 | * | |
6819bc2e | 398 | * |
1da177e4 LT |
399 | * |
400 | */ | |
6819bc2e | 401 | static int ircomm_param_line_status(void *instance, irda_param_t *param, |
1da177e4 LT |
402 | int get) |
403 | { | |
0dc47877 | 404 | IRDA_DEBUG(2, "%s(), not impl.\n", __func__ ); |
1da177e4 LT |
405 | |
406 | return 0; | |
407 | } | |
408 | ||
409 | /* | |
410 | * Function ircomm_param_dte (instance, param) | |
411 | * | |
412 | * If we get here, there must be some sort of null-modem connection, and | |
413 | * we are probably working in server mode as well. | |
414 | */ | |
415 | static int ircomm_param_dte(void *instance, irda_param_t *param, int get) | |
416 | { | |
417 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance; | |
418 | __u8 dte; | |
419 | ||
420 | IRDA_ASSERT(self != NULL, return -1;); | |
421 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;); | |
422 | ||
423 | if (get) | |
424 | param->pv.i = self->settings.dte; | |
425 | else { | |
426 | dte = (__u8) param->pv.i; | |
427 | ||
428 | self->settings.dce = 0; | |
6819bc2e | 429 | |
1da177e4 LT |
430 | if (dte & IRCOMM_DELTA_DTR) |
431 | self->settings.dce |= (IRCOMM_DELTA_DSR| | |
432 | IRCOMM_DELTA_RI | | |
433 | IRCOMM_DELTA_CD); | |
434 | if (dte & IRCOMM_DTR) | |
435 | self->settings.dce |= (IRCOMM_DSR| | |
436 | IRCOMM_RI | | |
437 | IRCOMM_CD); | |
6819bc2e | 438 | |
1da177e4 LT |
439 | if (dte & IRCOMM_DELTA_RTS) |
440 | self->settings.dce |= IRCOMM_DELTA_CTS; | |
441 | if (dte & IRCOMM_RTS) | |
442 | self->settings.dce |= IRCOMM_CTS; | |
443 | ||
444 | /* Take appropriate actions */ | |
445 | ircomm_tty_check_modem_status(self); | |
446 | ||
447 | /* Null modem cable emulator */ | |
448 | self->settings.null_modem = TRUE; | |
449 | } | |
450 | ||
451 | return 0; | |
452 | } | |
453 | ||
454 | /* | |
455 | * Function ircomm_param_dce (instance, param) | |
456 | * | |
6819bc2e | 457 | * |
1da177e4 LT |
458 | * |
459 | */ | |
460 | static int ircomm_param_dce(void *instance, irda_param_t *param, int get) | |
461 | { | |
462 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance; | |
463 | __u8 dce; | |
464 | ||
0dc47877 | 465 | IRDA_DEBUG(1, "%s(), dce = 0x%02x\n", __func__ , (__u8) param->pv.i); |
1da177e4 LT |
466 | |
467 | dce = (__u8) param->pv.i; | |
468 | ||
469 | IRDA_ASSERT(self != NULL, return -1;); | |
470 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;); | |
471 | ||
472 | self->settings.dce = dce; | |
473 | ||
474 | /* Check if any of the settings have changed */ | |
475 | if (dce & 0x0f) { | |
476 | if (dce & IRCOMM_DELTA_CTS) { | |
0dc47877 | 477 | IRDA_DEBUG(2, "%s(), CTS \n", __func__ ); |
1da177e4 LT |
478 | } |
479 | } | |
480 | ||
481 | ircomm_tty_check_modem_status(self); | |
482 | ||
483 | return 0; | |
484 | } | |
485 | ||
486 | /* | |
487 | * Function ircomm_param_poll (instance, param) | |
488 | * | |
489 | * Called when the peer device is polling for the line settings | |
490 | * | |
491 | */ | |
492 | static int ircomm_param_poll(void *instance, irda_param_t *param, int get) | |
493 | { | |
494 | struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance; | |
495 | ||
496 | IRDA_ASSERT(self != NULL, return -1;); | |
497 | IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;); | |
498 | ||
cc53ded2 | 499 | /* Poll parameters are always of length 0 (just a signal) */ |
1da177e4 LT |
500 | if (!get) { |
501 | /* Respond with DTE line settings */ | |
502 | ircomm_param_request(self, IRCOMM_DTE, TRUE); | |
503 | } | |
504 | return 0; | |
505 | } | |
506 | ||
507 | ||
508 | ||
509 | ||
510 |