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