* added 0.99 linux version
[mascara-docs.git] / i386 / linux / linux-2.3.21 / net / irda / ircomm / ircomm_param.c
blob4294dbdb2027d153d8b2ccc07c557dce7f725710
1 /*********************************************************************
2 *
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: Fri Sep 3 09:28:20 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 <net/irda/irda.h>
32 #include <net/irda/parameters.h>
34 #include <net/irda/ircomm_core.h>
35 #include <net/irda/ircomm_tty_attach.h>
36 #include <net/irda/ircomm_tty.h>
38 #include <net/irda/ircomm_param.h>
40 static int ircomm_param_service_type(void *instance, param_t *param, int get);
41 static int ircomm_param_port_type(void *instance, param_t *param, int get);
42 static int ircomm_param_port_name(void *instance, param_t *param, int get);
43 static int ircomm_param_service_type(void *instance, param_t *param, int get);
44 static int ircomm_param_data_rate(void *instance, param_t *param, int get);
45 static int ircomm_param_data_format(void *instance, param_t *param, int get);
46 static int ircomm_param_flow_control(void *instance, param_t *param, int get);
47 static int ircomm_param_xon_xoff(void *instance, param_t *param, int get);
48 static int ircomm_param_enq_ack(void *instance, param_t *param, int get);
49 static int ircomm_param_line_status(void *instance, param_t *param, int get);
50 static int ircomm_param_dte(void *instance, param_t *param, int get);
51 static int ircomm_param_dce(void *instance, param_t *param, int get);
52 static int ircomm_param_poll(void *instance, param_t *param, int get);
54 static pi_minor_info_t pi_minor_call_table_common[] = {
55 { ircomm_param_service_type, PV_INT_8_BITS },
56 { ircomm_param_port_type, PV_INT_8_BITS },
57 { ircomm_param_port_name, PV_STRING }
59 static pi_minor_info_t pi_minor_call_table_non_raw[] = {
60 { ircomm_param_data_rate, PV_INT_32_BITS | PV_BIG_ENDIAN },
61 { ircomm_param_data_format, PV_INT_8_BITS },
62 { ircomm_param_flow_control, PV_INT_8_BITS },
63 { ircomm_param_xon_xoff, PV_INT_16_BITS },
64 { ircomm_param_enq_ack, PV_INT_16_BITS },
65 { ircomm_param_line_status, PV_INT_8_BITS }
67 static pi_minor_info_t pi_minor_call_table_9_wire[] = {
68 { ircomm_param_dte, PV_INT_8_BITS },
69 { ircomm_param_dce, PV_INT_8_BITS },
70 { ircomm_param_poll, PV_INT_8_BITS },
73 static pi_major_info_t pi_major_call_table[] = {
74 { pi_minor_call_table_common, 3 },
75 { pi_minor_call_table_non_raw, 6 },
76 { pi_minor_call_table_9_wire, 3 }
77 /* { pi_minor_call_table_centronics } */
80 pi_param_info_t ircomm_param_info = { pi_major_call_table, 3, 0x0f, 4 };
83 * Function ircomm_param_flush (self)
85 * Flush (send) out all queued parameters
88 int ircomm_param_flush(struct ircomm_tty_cb *self)
90 if (self->ctrl_skb) {
91 ircomm_control_request(self->ircomm, self->ctrl_skb);
92 self->ctrl_skb = NULL;
94 return 0;
98 * Function ircomm_param_request (self, pi, flush)
100 * Queue a parameter for the control channel
103 int ircomm_param_request(struct ircomm_tty_cb *self, __u8 pi, int flush)
105 unsigned long flags;
106 struct sk_buff *skb;
107 int count;
109 DEBUG(2, __FUNCTION__ "()\n");
111 ASSERT(self != NULL, return -1;);
112 ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
114 if (self->state != IRCOMM_TTY_READY) {
115 DEBUG(2, __FUNCTION__ "(), not ready yet!\n");
116 return 0;
119 /* Make sure we don't send parameters for raw mode */
120 if (self->service_type == IRCOMM_3_WIRE_RAW)
121 return 0;
123 save_flags(flags);
124 cli();
126 skb = self->ctrl_skb;
127 if (!skb) {
128 skb = dev_alloc_skb(256);
129 if (!skb) {
130 restore_flags(flags);
131 return -ENOMEM;
134 skb_reserve(skb, self->max_header_size);
136 self->ctrl_skb = skb;
139 * Inserting is a little bit tricky since we don't know how much
140 * room we will need. But this should hopefully work OK
142 count = irda_param_insert(self, pi, skb->tail, skb_tailroom(skb),
143 &ircomm_param_info);
144 if (count < 0) {
145 DEBUG(0, __FUNCTION__ "(), no room for parameter!\n");
146 restore_flags(flags);
147 return -1;
149 skb_put(skb, count);
150 restore_flags(flags);
152 if (flush) {
153 ircomm_control_request(self->ircomm, skb);
154 self->ctrl_skb = NULL;
156 return count;
160 * Function ircomm_param_service_type (self, buf, len)
162 * Handle service type, this function will both be called after the LM-IAS
163 * query and then the remote device sends its initial paramters
166 static int ircomm_param_service_type(void *instance, param_t *param, int get)
168 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
169 __u8 service_type = param->pv.b; /* We know it's a one byte integer */
171 ASSERT(self != NULL, return -1;);
172 ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
174 if (get) {
175 param->pv.b = self->session.service_type;
176 return 0;
180 * Now choose a preferred service type of those available
182 if (service_type & IRCOMM_3_WIRE_RAW) {
183 DEBUG(2, __FUNCTION__ "(), peer supports 3 wire raw\n");
184 self->session.service_type |= IRCOMM_3_WIRE_RAW;
186 if (service_type & IRCOMM_3_WIRE) {
187 DEBUG(2, __FUNCTION__ "(), peer supports 3 wire\n");
188 self->session.service_type |= IRCOMM_3_WIRE;
190 if (service_type & IRCOMM_9_WIRE) {
191 DEBUG(2, __FUNCTION__ "(), peer supports 9 wire\n");
192 self->session.service_type |= IRCOMM_9_WIRE;
194 if (service_type & IRCOMM_CENTRONICS) {
195 DEBUG(2, __FUNCTION__ "(), peer supports Centronics\n");
196 self->session.service_type |= IRCOMM_CENTRONICS;
199 self->session.service_type &= self->service_type;
200 if (!self->session.service_type) {
201 DEBUG(2, __FUNCTION__"(), No common service type to use!\n");
202 return -1;
205 DEBUG(2, __FUNCTION__ "(), resulting service type=0x%02x\n",
206 self->session.service_type);
208 return 0;
212 * Function ircomm_param_port_type (self, param)
214 * The port type parameter tells if the devices are serial or parallel.
215 * Since we only advertise serial service, this parameter should only
216 * be equal to IRCOMM_SERIAL.
218 static int ircomm_param_port_type(void *instance, param_t *param, int get)
220 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
222 ASSERT(self != NULL, return -1;);
223 ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
225 if (get)
226 param->pv.b = IRCOMM_SERIAL;
227 else {
228 self->session.port_type = param->pv.b;
230 DEBUG(0, __FUNCTION__ "(), port type=%d\n",
231 self->session.port_type);
233 return 0;
237 * Function ircomm_param_port_name (self, param)
242 static int ircomm_param_port_name(void *instance, param_t *param, int get)
244 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
246 ASSERT(self != NULL, return -1;);
247 ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
249 if (get) {
250 DEBUG(0, __FUNCTION__ "(), not imp!\n");
251 } else {
252 DEBUG(0, __FUNCTION__ "(), port-name=%s\n", param->pv.c);
253 strncpy(self->session.port_name, param->pv.c, 32);
256 return 0;
260 * Function ircomm_param_data_rate (self, param)
265 static int ircomm_param_data_rate(void *instance, param_t *param, int get)
267 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
269 ASSERT(self != NULL, return -1;);
270 ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
272 if (get)
273 param->pv.i = self->session.data_rate;
274 else
275 self->session.data_rate = param->pv.i;
277 DEBUG(2, __FUNCTION__ "(), data rate = %d\n", param->pv.i);
279 return 0;
283 * Function ircomm_param_data_format (self, param)
288 static int ircomm_param_data_format(void *instance, param_t *param, int get)
290 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
292 ASSERT(self != NULL, return -1;);
293 ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
295 if (get)
296 param->pv.b = self->session.data_format;
297 else
298 self->session.data_format = param->pv.b;
300 return 0;
304 * Function ircomm_param_flow_control (self, param)
309 static int ircomm_param_flow_control(void *instance, param_t *param, int get)
311 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
313 ASSERT(self != NULL, return -1;);
314 ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
316 if (get)
317 param->pv.b = self->session.flow_control;
318 else
319 self->session.flow_control = param->pv.b;
321 DEBUG(1, __FUNCTION__ "(), flow control = 0x%02x\n", param->pv.b);
323 return 0;
327 * Function ircomm_param_xon_xoff (self, param)
332 static int ircomm_param_xon_xoff(void *instance, param_t *param, int get)
334 DEBUG(2, __FUNCTION__ "(), not impl.\n");
336 return 0;
340 * Function ircomm_param_enq_ack (self, param)
345 static int ircomm_param_enq_ack(void *instance, param_t *param, int get)
347 DEBUG(2, __FUNCTION__ "(), not impl.\n");
349 return 0;
353 * Function ircomm_param_line_status (self, param)
358 static int ircomm_param_line_status(void *instance, param_t *param, int get)
360 DEBUG(2, __FUNCTION__ "(), not impl.\n");
362 return 0;
366 * Function ircomm_param_dte (instance, param)
368 * If we get here, there must be some sort of null-modem connection, and
369 * we are probably working in server mode as well.
371 static int ircomm_param_dte(void *instance, param_t *param, int get)
373 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
374 __u8 dte;
376 ASSERT(self != NULL, return -1;);
377 ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
379 if (get)
380 param->pv.b = self->session.dte;
381 else {
382 dte = param->pv.b;
384 if (dte & IRCOMM_DELTA_DTR)
385 self->session.dce |= (IRCOMM_DELTA_DSR|
386 IRCOMM_DELTA_RI |
387 IRCOMM_DELTA_CD);
388 if (dte & IRCOMM_DTR)
389 self->session.dce |= (IRCOMM_DSR|
390 IRCOMM_RI |
391 IRCOMM_CD);
393 if (dte & IRCOMM_DELTA_RTS)
394 self->session.dce |= IRCOMM_DELTA_CTS;
395 if (dte & IRCOMM_RTS)
396 self->session.dce |= IRCOMM_CTS;
398 /* Take appropriate actions */
399 ircomm_tty_check_modem_status(self);
401 /* Null modem cable emulator */
402 self->session.null_modem = TRUE;
405 return 0;
409 * Function ircomm_param_dce (instance, param)
414 static int ircomm_param_dce(void *instance, param_t *param, int get)
416 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
417 __u8 dce;
419 DEBUG(1, __FUNCTION__ "(), dce = 0x%02x\n", param->pv.b);
421 dce = param->pv.b;
423 ASSERT(self != NULL, return -1;);
424 ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
426 self->session.dce = dce;
428 /* Check if any of the settings have changed */
429 if (dce & 0x0f) {
430 if (dce & IRCOMM_DELTA_CTS) {
431 DEBUG(2, __FUNCTION__ "(), CTS \n");
435 ircomm_tty_check_modem_status(self);
437 return 0;
441 * Function ircomm_param_poll (instance, param)
443 * Called when the peer device is polling for the line settings
446 static int ircomm_param_poll(void *instance, param_t *param, int get)
448 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
450 ASSERT(self != NULL, return -1;);
451 ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
453 /* Poll parameters are always of lenght 0 (just a signal) */
454 if (!get) {
455 /* Respond with DTE line settings */
456 ircomm_param_request(self, IRCOMM_DTE, TRUE);
459 return 0;