1 /*********************************************************************
3 * Filename: ircomm_param.c
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>
12 * Copyright (c) 1999-2000 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,
29 ********************************************************************/
31 #include <linux/sched.h>
32 #include <linux/interrupt.h>
34 #include <net/irda/irda.h>
35 #include <net/irda/parameters.h>
37 #include <net/irda/ircomm_core.h>
38 #include <net/irda/ircomm_tty_attach.h>
39 #include <net/irda/ircomm_tty.h>
41 #include <net/irda/ircomm_param.h>
43 static int ircomm_param_service_type(void *instance
, irda_param_t
*param
,
45 static int ircomm_param_port_type(void *instance
, irda_param_t
*param
,
47 static int ircomm_param_port_name(void *instance
, irda_param_t
*param
,
49 static int ircomm_param_service_type(void *instance
, irda_param_t
*param
,
51 static int ircomm_param_data_rate(void *instance
, irda_param_t
*param
,
53 static int ircomm_param_data_format(void *instance
, irda_param_t
*param
,
55 static int ircomm_param_flow_control(void *instance
, irda_param_t
*param
,
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
);
59 static int ircomm_param_line_status(void *instance
, irda_param_t
*param
,
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
);
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
}
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
}
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
},
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 },
87 { pi_minor_call_table_9_wire
, 3 }
88 /* { pi_minor_call_table_centronics } */
91 pi_param_info_t ircomm_param_info
= { pi_major_call_table
, 3, 0x0f, 4 };
94 * Function ircomm_param_flush (self)
96 * Flush (send) out all queued parameters
99 int ircomm_param_flush(struct ircomm_tty_cb
*self
)
101 if (self
->ctrl_skb
) {
102 ircomm_control_request(self
->ircomm
, self
->ctrl_skb
);
103 self
->ctrl_skb
= NULL
;
109 * Function ircomm_param_request (self, pi, flush)
111 * Queue a parameter for the control channel
114 int ircomm_param_request(struct ircomm_tty_cb
*self
, __u8 pi
, int flush
)
116 struct tty_struct
*tty
;
121 IRDA_DEBUG(2, __FUNCTION__
"()\n");
123 ASSERT(self
!= NULL
, return -1;);
124 ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return -1;);
130 /* Make sure we don't send parameters for raw mode */
131 if (self
->service_type
== IRCOMM_3_WIRE_RAW
)
137 skb
= self
->ctrl_skb
;
139 skb
= dev_alloc_skb(256);
141 restore_flags(flags
);
145 skb_reserve(skb
, self
->max_header_size
);
146 self
->ctrl_skb
= skb
;
149 * Inserting is a little bit tricky since we don't know how much
150 * room we will need. But this should hopefully work OK
152 count
= irda_param_insert(self
, pi
, skb
->tail
, skb_tailroom(skb
),
155 WARNING(__FUNCTION__
"(), no room for parameter!\n");
156 restore_flags(flags
);
161 restore_flags(flags
);
163 IRDA_DEBUG(2, __FUNCTION__
"(), skb->len=%d\n", skb
->len
);
166 /* ircomm_tty_do_softint will take care of the rest */
167 queue_task(&self
->tqueue
, &tq_immediate
);
168 mark_bh(IMMEDIATE_BH
);
175 * Function ircomm_param_service_type (self, buf, len)
177 * Handle service type, this function will both be called after the LM-IAS
178 * query and then the remote device sends its initial paramters
181 static int ircomm_param_service_type(void *instance
, irda_param_t
*param
,
184 struct ircomm_tty_cb
*self
= (struct ircomm_tty_cb
*) instance
;
185 __u8 service_type
= param
->pv
.b
; /* We know it's a one byte integer */
187 ASSERT(self
!= NULL
, return -1;);
188 ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return -1;);
191 param
->pv
.b
= self
->settings
.service_type
;
195 /* Find all common service types */
196 service_type
&= self
->service_type
;
198 IRDA_DEBUG(2, __FUNCTION__
199 "(), No common service type to use!\n");
202 IRDA_DEBUG(0, __FUNCTION__
"(), services in common=%02x\n",
206 * Now choose a preferred service type of those available
208 if (service_type
& IRCOMM_CENTRONICS
)
209 self
->settings
.service_type
= IRCOMM_CENTRONICS
;
210 else if (service_type
& IRCOMM_9_WIRE
)
211 self
->settings
.service_type
= IRCOMM_9_WIRE
;
212 else if (service_type
& IRCOMM_3_WIRE
)
213 self
->settings
.service_type
= IRCOMM_3_WIRE
;
214 else if (service_type
& IRCOMM_3_WIRE_RAW
)
215 self
->settings
.service_type
= IRCOMM_3_WIRE_RAW
;
217 IRDA_DEBUG(0, __FUNCTION__
"(), resulting service type=0x%02x\n",
218 self
->settings
.service_type
);
221 * Now the line is ready for some communication. Check if we are a
222 * server, and send over some initial parameters
224 if (!self
->client
&& (self
->settings
.service_type
!= IRCOMM_3_WIRE_RAW
))
226 /* Init connection */
227 ircomm_tty_send_initial_parameters(self
);
228 ircomm_tty_link_established(self
);
235 * Function ircomm_param_port_type (self, param)
237 * The port type parameter tells if the devices are serial or parallel.
238 * Since we only advertise serial service, this parameter should only
239 * be equal to IRCOMM_SERIAL.
241 static int ircomm_param_port_type(void *instance
, irda_param_t
*param
, int get
)
243 struct ircomm_tty_cb
*self
= (struct ircomm_tty_cb
*) instance
;
245 ASSERT(self
!= NULL
, return -1;);
246 ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return -1;);
249 param
->pv
.b
= IRCOMM_SERIAL
;
251 self
->settings
.port_type
= param
->pv
.b
;
253 IRDA_DEBUG(0, __FUNCTION__
"(), port type=%d\n",
254 self
->settings
.port_type
);
260 * Function ircomm_param_port_name (self, param)
265 static int ircomm_param_port_name(void *instance
, irda_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;);
273 IRDA_DEBUG(0, __FUNCTION__
"(), not imp!\n");
275 IRDA_DEBUG(0, __FUNCTION__
"(), port-name=%s\n", param
->pv
.c
);
276 strncpy(self
->settings
.port_name
, param
->pv
.c
, 32);
283 * Function ircomm_param_data_rate (self, param)
285 * Exchange data rate to be used in this settings
288 static int ircomm_param_data_rate(void *instance
, irda_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;);
296 param
->pv
.i
= self
->settings
.data_rate
;
298 self
->settings
.data_rate
= param
->pv
.i
;
300 IRDA_DEBUG(2, __FUNCTION__
"(), data rate = %d\n", param
->pv
.i
);
306 * Function ircomm_param_data_format (self, param)
308 * Exchange data format to be used in this settings
311 static int ircomm_param_data_format(void *instance
, irda_param_t
*param
,
314 struct ircomm_tty_cb
*self
= (struct ircomm_tty_cb
*) instance
;
316 ASSERT(self
!= NULL
, return -1;);
317 ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return -1;);
320 param
->pv
.b
= self
->settings
.data_format
;
322 self
->settings
.data_format
= param
->pv
.b
;
328 * Function ircomm_param_flow_control (self, param)
330 * Exchange flow control settings to be used in this settings
333 static int ircomm_param_flow_control(void *instance
, irda_param_t
*param
,
336 struct ircomm_tty_cb
*self
= (struct ircomm_tty_cb
*) instance
;
338 ASSERT(self
!= NULL
, return -1;);
339 ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return -1;);
342 param
->pv
.b
= self
->settings
.flow_control
;
344 self
->settings
.flow_control
= param
->pv
.b
;
346 IRDA_DEBUG(1, __FUNCTION__
"(), flow control = 0x%02x\n", param
->pv
.b
);
352 * Function ircomm_param_xon_xoff (self, param)
354 * Exchange XON/XOFF characters
357 static int ircomm_param_xon_xoff(void *instance
, irda_param_t
*param
, int get
)
359 struct ircomm_tty_cb
*self
= (struct ircomm_tty_cb
*) instance
;
361 ASSERT(self
!= NULL
, return -1;);
362 ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return -1;);
365 param
->pv
.s
= self
->settings
.xonxoff
[0];
366 param
->pv
.s
|= self
->settings
.xonxoff
[1] << 8;
368 self
->settings
.xonxoff
[0] = param
->pv
.s
& 0xff;
369 self
->settings
.xonxoff
[1] = param
->pv
.s
>> 8;
372 IRDA_DEBUG(0, __FUNCTION__
"(), XON/XOFF = 0x%02x,0x%02x\n",
373 param
->pv
.s
& 0xff, param
->pv
.s
>> 8);
379 * Function ircomm_param_enq_ack (self, param)
381 * Exchange ENQ/ACK characters
384 static int ircomm_param_enq_ack(void *instance
, irda_param_t
*param
, int get
)
386 struct ircomm_tty_cb
*self
= (struct ircomm_tty_cb
*) instance
;
388 ASSERT(self
!= NULL
, return -1;);
389 ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return -1;);
392 param
->pv
.s
= self
->settings
.enqack
[0];
393 param
->pv
.s
|= self
->settings
.enqack
[1] << 8;
395 self
->settings
.enqack
[0] = param
->pv
.s
& 0xff;
396 self
->settings
.enqack
[1] = param
->pv
.s
>> 8;
399 IRDA_DEBUG(0, __FUNCTION__
"(), ENQ/ACK = 0x%02x,0x%02x\n",
400 param
->pv
.s
& 0xff, param
->pv
.s
>> 8);
406 * Function ircomm_param_line_status (self, param)
411 static int ircomm_param_line_status(void *instance
, irda_param_t
*param
,
414 IRDA_DEBUG(2, __FUNCTION__
"(), not impl.\n");
420 * Function ircomm_param_dte (instance, param)
422 * If we get here, there must be some sort of null-modem connection, and
423 * we are probably working in server mode as well.
425 static int ircomm_param_dte(void *instance
, irda_param_t
*param
, int get
)
427 struct ircomm_tty_cb
*self
= (struct ircomm_tty_cb
*) instance
;
430 ASSERT(self
!= NULL
, return -1;);
431 ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return -1;);
434 param
->pv
.b
= self
->settings
.dte
;
438 if (dte
& IRCOMM_DELTA_DTR
)
439 self
->settings
.dce
|= (IRCOMM_DELTA_DSR
|
442 if (dte
& IRCOMM_DTR
)
443 self
->settings
.dce
|= (IRCOMM_DSR
|
447 if (dte
& IRCOMM_DELTA_RTS
)
448 self
->settings
.dce
|= IRCOMM_DELTA_CTS
;
449 if (dte
& IRCOMM_RTS
)
450 self
->settings
.dce
|= IRCOMM_CTS
;
452 /* Take appropriate actions */
453 ircomm_tty_check_modem_status(self
);
455 /* Null modem cable emulator */
456 self
->settings
.null_modem
= TRUE
;
463 * Function ircomm_param_dce (instance, param)
468 static int ircomm_param_dce(void *instance
, irda_param_t
*param
, int get
)
470 struct ircomm_tty_cb
*self
= (struct ircomm_tty_cb
*) instance
;
473 IRDA_DEBUG(1, __FUNCTION__
"(), dce = 0x%02x\n", param
->pv
.b
);
477 ASSERT(self
!= NULL
, return -1;);
478 ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return -1;);
480 self
->settings
.dce
= dce
;
482 /* Check if any of the settings have changed */
484 if (dce
& IRCOMM_DELTA_CTS
) {
485 IRDA_DEBUG(2, __FUNCTION__
"(), CTS \n");
489 ircomm_tty_check_modem_status(self
);
495 * Function ircomm_param_poll (instance, param)
497 * Called when the peer device is polling for the line settings
500 static int ircomm_param_poll(void *instance
, irda_param_t
*param
, int get
)
502 struct ircomm_tty_cb
*self
= (struct ircomm_tty_cb
*) instance
;
504 ASSERT(self
!= NULL
, return -1;);
505 ASSERT(self
->magic
== IRCOMM_TTY_MAGIC
, return -1;);
507 /* Poll parameters are always of lenght 0 (just a signal) */
509 /* Respond with DTE line settings */
510 ircomm_param_request(self
, IRCOMM_DTE
, TRUE
);