blob: 8fd72ff9436e12039abf43575d7cf17181132258 [file] [log] [blame]
David Sterba099dc4f2008-02-07 10:57:12 +01001/*
2 * IPWireless 3G PCMCIA Network Driver
3 *
4 * Original code
5 * by Stephen Blackheath <stephen@blacksapphire.com>,
6 * Ben Martel <benm@symmetric.co.nz>
7 *
8 * Copyrighted as follows:
9 * Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
10 *
11 * Various driver changes and rewrites, port to new kernels
12 * Copyright (C) 2006-2007 Jiri Kosina
13 *
14 * Misc code cleanups and updates
15 * Copyright (C) 2007 David Sterba
16 */
17
18#include <linux/init.h>
19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/mutex.h>
22#include <linux/ppp_defs.h>
23#include <linux/if.h>
Paul Mackerras4b32da2b2012-03-04 12:56:55 +000024#include <linux/ppp-ioctl.h>
David Sterba099dc4f2008-02-07 10:57:12 +010025#include <linux/sched.h>
26#include <linux/serial.h>
27#include <linux/slab.h>
28#include <linux/tty.h>
29#include <linux/tty_driver.h>
30#include <linux/tty_flip.h>
31#include <linux/uaccess.h>
David Sterba099dc4f2008-02-07 10:57:12 +010032
33#include "tty.h"
34#include "network.h"
35#include "hardware.h"
36#include "main.h"
37
38#define IPWIRELESS_PCMCIA_START (0)
39#define IPWIRELESS_PCMCIA_MINORS (24)
40#define IPWIRELESS_PCMCIA_MINOR_RANGE (8)
41
42#define TTYTYPE_MODEM (0)
43#define TTYTYPE_MONITOR (1)
44#define TTYTYPE_RAS_RAW (2)
45
46struct ipw_tty {
Jiri Slaby7393af82012-04-02 13:54:33 +020047 struct tty_port port;
David Sterba099dc4f2008-02-07 10:57:12 +010048 int index;
49 struct ipw_hardware *hardware;
50 unsigned int channel_idx;
51 unsigned int secondary_channel_idx;
52 int tty_type;
53 struct ipw_network *network;
David Sterba099dc4f2008-02-07 10:57:12 +010054 unsigned int control_lines;
55 struct mutex ipw_tty_mutex;
56 int tx_bytes_queued;
57 int closing;
58};
59
60static struct ipw_tty *ttys[IPWIRELESS_PCMCIA_MINORS];
61
62static struct tty_driver *ipw_tty_driver;
63
64static char *tty_type_name(int tty_type)
65{
66 static char *channel_names[] = {
67 "modem",
68 "monitor",
69 "RAS-raw"
70 };
71
72 return channel_names[tty_type];
73}
74
Jiri Slabyecaa3bd2012-03-05 14:52:02 +010075static struct ipw_tty *get_tty(int index)
David Sterba099dc4f2008-02-07 10:57:12 +010076{
Jiri Slabyecaa3bd2012-03-05 14:52:02 +010077 /*
78 * The 'ras_raw' channel is only available when 'loopback' mode
79 * is enabled.
80 * Number of minor starts with 16 (_RANGE * _RAS_RAW).
81 */
82 if (!ipwireless_loopback && index >=
83 IPWIRELESS_PCMCIA_MINOR_RANGE * TTYTYPE_RAS_RAW)
David Sterba099dc4f2008-02-07 10:57:12 +010084 return NULL;
David Sterba099dc4f2008-02-07 10:57:12 +010085
Jiri Slabyecaa3bd2012-03-05 14:52:02 +010086 return ttys[index];
David Sterba099dc4f2008-02-07 10:57:12 +010087}
88
89static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
90{
Jiri Slabyecaa3bd2012-03-05 14:52:02 +010091 struct ipw_tty *tty = get_tty(linux_tty->index);
David Sterba099dc4f2008-02-07 10:57:12 +010092
93 if (!tty)
94 return -ENODEV;
95
96 mutex_lock(&tty->ipw_tty_mutex);
97
98 if (tty->closing) {
99 mutex_unlock(&tty->ipw_tty_mutex);
100 return -ENODEV;
101 }
Jiri Slaby7393af82012-04-02 13:54:33 +0200102 if (tty->port.count == 0)
David Sterba099dc4f2008-02-07 10:57:12 +0100103 tty->tx_bytes_queued = 0;
104
Jiri Slaby7393af82012-04-02 13:54:33 +0200105 tty->port.count++;
David Sterba099dc4f2008-02-07 10:57:12 +0100106
Jiri Slaby19ef1b72012-04-02 13:54:34 +0200107 tty->port.tty = linux_tty;
David Sterba099dc4f2008-02-07 10:57:12 +0100108 linux_tty->driver_data = tty;
Jiri Slabyd6c53c02013-01-03 15:53:05 +0100109 tty->port.low_latency = 1;
David Sterba099dc4f2008-02-07 10:57:12 +0100110
111 if (tty->tty_type == TTYTYPE_MODEM)
112 ipwireless_ppp_open(tty->network);
113
114 mutex_unlock(&tty->ipw_tty_mutex);
115
116 return 0;
117}
118
119static void do_ipw_close(struct ipw_tty *tty)
120{
Jiri Slaby7393af82012-04-02 13:54:33 +0200121 tty->port.count--;
David Sterba099dc4f2008-02-07 10:57:12 +0100122
Jiri Slaby7393af82012-04-02 13:54:33 +0200123 if (tty->port.count == 0) {
Jiri Slaby19ef1b72012-04-02 13:54:34 +0200124 struct tty_struct *linux_tty = tty->port.tty;
David Sterba099dc4f2008-02-07 10:57:12 +0100125
126 if (linux_tty != NULL) {
Jiri Slaby19ef1b72012-04-02 13:54:34 +0200127 tty->port.tty = NULL;
David Sterba099dc4f2008-02-07 10:57:12 +0100128 linux_tty->driver_data = NULL;
129
130 if (tty->tty_type == TTYTYPE_MODEM)
131 ipwireless_ppp_close(tty->network);
132 }
133 }
134}
135
136static void ipw_hangup(struct tty_struct *linux_tty)
137{
138 struct ipw_tty *tty = linux_tty->driver_data;
139
140 if (!tty)
141 return;
142
143 mutex_lock(&tty->ipw_tty_mutex);
Jiri Slaby7393af82012-04-02 13:54:33 +0200144 if (tty->port.count == 0) {
David Sterba099dc4f2008-02-07 10:57:12 +0100145 mutex_unlock(&tty->ipw_tty_mutex);
146 return;
147 }
148
149 do_ipw_close(tty);
150
151 mutex_unlock(&tty->ipw_tty_mutex);
152}
153
154static void ipw_close(struct tty_struct *linux_tty, struct file *filp)
155{
156 ipw_hangup(linux_tty);
157}
158
159/* Take data received from hardware, and send it out the tty */
160void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
161 unsigned int length)
162{
David Sterba099dc4f2008-02-07 10:57:12 +0100163 int work = 0;
164
165 mutex_lock(&tty->ipw_tty_mutex);
David Sterba099dc4f2008-02-07 10:57:12 +0100166
Jiri Slaby7393af82012-04-02 13:54:33 +0200167 if (!tty->port.count) {
David Sterba099dc4f2008-02-07 10:57:12 +0100168 mutex_unlock(&tty->ipw_tty_mutex);
169 return;
170 }
171 mutex_unlock(&tty->ipw_tty_mutex);
172
Jiri Slaby05c7cd32013-01-03 15:53:04 +0100173 work = tty_insert_flip_string(&tty->port, data, length);
David Sterba099dc4f2008-02-07 10:57:12 +0100174
175 if (work != length)
176 printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
177 ": %d chars not inserted to flip buffer!\n",
178 length - work);
179
180 /*
181 * This may sleep if ->low_latency is set
182 */
183 if (work)
Jiri Slaby2e124b42013-01-03 15:53:06 +0100184 tty_flip_buffer_push(&tty->port);
David Sterba099dc4f2008-02-07 10:57:12 +0100185}
186
187static void ipw_write_packet_sent_callback(void *callback_data,
188 unsigned int packet_length)
189{
190 struct ipw_tty *tty = callback_data;
191
192 /*
193 * Packet has been sent, so we subtract the number of bytes from our
194 * tally of outstanding TX bytes.
195 */
196 tty->tx_bytes_queued -= packet_length;
197}
198
199static int ipw_write(struct tty_struct *linux_tty,
200 const unsigned char *buf, int count)
201{
202 struct ipw_tty *tty = linux_tty->driver_data;
203 int room, ret;
204
205 if (!tty)
206 return -ENODEV;
207
208 mutex_lock(&tty->ipw_tty_mutex);
Jiri Slaby7393af82012-04-02 13:54:33 +0200209 if (!tty->port.count) {
David Sterba099dc4f2008-02-07 10:57:12 +0100210 mutex_unlock(&tty->ipw_tty_mutex);
211 return -EINVAL;
212 }
213
214 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
215 if (room < 0)
216 room = 0;
217 /* Don't allow caller to write any more than we have room for */
218 if (count > room)
219 count = room;
220
221 if (count == 0) {
222 mutex_unlock(&tty->ipw_tty_mutex);
223 return 0;
224 }
225
226 ret = ipwireless_send_packet(tty->hardware, IPW_CHANNEL_RAS,
David Sterbaff3e9902008-07-28 16:53:11 +0200227 buf, count,
David Sterba099dc4f2008-02-07 10:57:12 +0100228 ipw_write_packet_sent_callback, tty);
229 if (ret == -1) {
230 mutex_unlock(&tty->ipw_tty_mutex);
231 return 0;
232 }
233
234 tty->tx_bytes_queued += count;
235 mutex_unlock(&tty->ipw_tty_mutex);
236
237 return count;
238}
239
240static int ipw_write_room(struct tty_struct *linux_tty)
241{
242 struct ipw_tty *tty = linux_tty->driver_data;
243 int room;
244
Alan Cox5aaa70a2008-10-13 10:38:07 +0100245 /* FIXME: Exactly how is the tty object locked here .. */
David Sterba099dc4f2008-02-07 10:57:12 +0100246 if (!tty)
247 return -ENODEV;
248
Jiri Slaby7393af82012-04-02 13:54:33 +0200249 if (!tty->port.count)
David Sterba099dc4f2008-02-07 10:57:12 +0100250 return -EINVAL;
251
252 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
253 if (room < 0)
254 room = 0;
255
256 return room;
257}
258
259static int ipwireless_get_serial_info(struct ipw_tty *tty,
260 struct serial_struct __user *retinfo)
261{
262 struct serial_struct tmp;
263
264 if (!retinfo)
265 return (-EFAULT);
266
267 memset(&tmp, 0, sizeof(tmp));
268 tmp.type = PORT_UNKNOWN;
269 tmp.line = tty->index;
270 tmp.port = 0;
271 tmp.irq = 0;
272 tmp.flags = 0;
273 tmp.baud_base = 115200;
274 tmp.close_delay = 0;
275 tmp.closing_wait = 0;
276 tmp.custom_divisor = 0;
277 tmp.hub6 = 0;
278 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
279 return -EFAULT;
280
281 return 0;
282}
283
284static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
285{
286 struct ipw_tty *tty = linux_tty->driver_data;
287
288 if (!tty)
Alan Cox23198fd2009-07-20 16:05:27 +0100289 return 0;
David Sterba099dc4f2008-02-07 10:57:12 +0100290
Jiri Slaby7393af82012-04-02 13:54:33 +0200291 if (!tty->port.count)
Alan Cox23198fd2009-07-20 16:05:27 +0100292 return 0;
David Sterba099dc4f2008-02-07 10:57:12 +0100293
294 return tty->tx_bytes_queued;
295}
296
297static int get_control_lines(struct ipw_tty *tty)
298{
299 unsigned int my = tty->control_lines;
300 unsigned int out = 0;
301
302 if (my & IPW_CONTROL_LINE_RTS)
303 out |= TIOCM_RTS;
304 if (my & IPW_CONTROL_LINE_DTR)
305 out |= TIOCM_DTR;
306 if (my & IPW_CONTROL_LINE_CTS)
307 out |= TIOCM_CTS;
308 if (my & IPW_CONTROL_LINE_DSR)
309 out |= TIOCM_DSR;
310 if (my & IPW_CONTROL_LINE_DCD)
311 out |= TIOCM_CD;
312
313 return out;
314}
315
316static int set_control_lines(struct ipw_tty *tty, unsigned int set,
317 unsigned int clear)
318{
319 int ret;
320
321 if (set & TIOCM_RTS) {
322 ret = ipwireless_set_RTS(tty->hardware, tty->channel_idx, 1);
323 if (ret)
324 return ret;
325 if (tty->secondary_channel_idx != -1) {
326 ret = ipwireless_set_RTS(tty->hardware,
327 tty->secondary_channel_idx, 1);
328 if (ret)
329 return ret;
330 }
331 }
332 if (set & TIOCM_DTR) {
333 ret = ipwireless_set_DTR(tty->hardware, tty->channel_idx, 1);
334 if (ret)
335 return ret;
336 if (tty->secondary_channel_idx != -1) {
337 ret = ipwireless_set_DTR(tty->hardware,
338 tty->secondary_channel_idx, 1);
339 if (ret)
340 return ret;
341 }
342 }
343 if (clear & TIOCM_RTS) {
344 ret = ipwireless_set_RTS(tty->hardware, tty->channel_idx, 0);
345 if (tty->secondary_channel_idx != -1) {
346 ret = ipwireless_set_RTS(tty->hardware,
347 tty->secondary_channel_idx, 0);
348 if (ret)
349 return ret;
350 }
351 }
352 if (clear & TIOCM_DTR) {
353 ret = ipwireless_set_DTR(tty->hardware, tty->channel_idx, 0);
354 if (tty->secondary_channel_idx != -1) {
355 ret = ipwireless_set_DTR(tty->hardware,
356 tty->secondary_channel_idx, 0);
357 if (ret)
358 return ret;
359 }
360 }
361 return 0;
362}
363
Alan Cox60b33c12011-02-14 16:26:14 +0000364static int ipw_tiocmget(struct tty_struct *linux_tty)
David Sterba099dc4f2008-02-07 10:57:12 +0100365{
366 struct ipw_tty *tty = linux_tty->driver_data;
Alan Cox5aaa70a2008-10-13 10:38:07 +0100367 /* FIXME: Exactly how is the tty object locked here .. */
David Sterba099dc4f2008-02-07 10:57:12 +0100368
369 if (!tty)
370 return -ENODEV;
371
Jiri Slaby7393af82012-04-02 13:54:33 +0200372 if (!tty->port.count)
David Sterba099dc4f2008-02-07 10:57:12 +0100373 return -EINVAL;
374
375 return get_control_lines(tty);
376}
377
378static int
Alan Cox20b9d172011-02-14 16:26:50 +0000379ipw_tiocmset(struct tty_struct *linux_tty,
David Sterba099dc4f2008-02-07 10:57:12 +0100380 unsigned int set, unsigned int clear)
381{
382 struct ipw_tty *tty = linux_tty->driver_data;
Alan Cox5aaa70a2008-10-13 10:38:07 +0100383 /* FIXME: Exactly how is the tty object locked here .. */
David Sterba099dc4f2008-02-07 10:57:12 +0100384
385 if (!tty)
386 return -ENODEV;
387
Jiri Slaby7393af82012-04-02 13:54:33 +0200388 if (!tty->port.count)
David Sterba099dc4f2008-02-07 10:57:12 +0100389 return -EINVAL;
390
391 return set_control_lines(tty, set, clear);
392}
393
Alan Cox6caa76b2011-02-14 16:27:22 +0000394static int ipw_ioctl(struct tty_struct *linux_tty,
David Sterba099dc4f2008-02-07 10:57:12 +0100395 unsigned int cmd, unsigned long arg)
396{
397 struct ipw_tty *tty = linux_tty->driver_data;
398
399 if (!tty)
400 return -ENODEV;
401
Jiri Slaby7393af82012-04-02 13:54:33 +0200402 if (!tty->port.count)
David Sterba099dc4f2008-02-07 10:57:12 +0100403 return -EINVAL;
404
Alan Cox5aaa70a2008-10-13 10:38:07 +0100405 /* FIXME: Exactly how is the tty object locked here .. */
406
David Sterba099dc4f2008-02-07 10:57:12 +0100407 switch (cmd) {
408 case TIOCGSERIAL:
409 return ipwireless_get_serial_info(tty, (void __user *) arg);
410
411 case TIOCSSERIAL:
412 return 0; /* Keeps the PCMCIA scripts happy. */
413 }
414
415 if (tty->tty_type == TTYTYPE_MODEM) {
416 switch (cmd) {
417 case PPPIOCGCHAN:
418 {
419 int chan = ipwireless_ppp_channel_index(
420 tty->network);
421
422 if (chan < 0)
423 return -ENODEV;
424 if (put_user(chan, (int __user *) arg))
425 return -EFAULT;
426 }
427 return 0;
428
429 case PPPIOCGUNIT:
430 {
431 int unit = ipwireless_ppp_unit_number(
432 tty->network);
433
434 if (unit < 0)
435 return -ENODEV;
436 if (put_user(unit, (int __user *) arg))
437 return -EFAULT;
438 }
439 return 0;
440
David Sterba099dc4f2008-02-07 10:57:12 +0100441 case FIONREAD:
442 {
443 int val = 0;
444
445 if (put_user(val, (int __user *) arg))
446 return -EFAULT;
447 }
448 return 0;
Alan Cox5aaa70a2008-10-13 10:38:07 +0100449 case TCFLSH:
450 return tty_perform_flush(linux_tty, arg);
David Sterba099dc4f2008-02-07 10:57:12 +0100451 }
452 }
Alan Cox6caa76b2011-02-14 16:27:22 +0000453 return -ENOIOCTLCMD;
David Sterba099dc4f2008-02-07 10:57:12 +0100454}
455
Dominik Brodowskib498ada2010-03-20 19:43:26 +0100456static int add_tty(int j,
David Sterba099dc4f2008-02-07 10:57:12 +0100457 struct ipw_hardware *hardware,
458 struct ipw_network *network, int channel_idx,
459 int secondary_channel_idx, int tty_type)
460{
461 ttys[j] = kzalloc(sizeof(struct ipw_tty), GFP_KERNEL);
462 if (!ttys[j])
463 return -ENOMEM;
464 ttys[j]->index = j;
465 ttys[j]->hardware = hardware;
466 ttys[j]->channel_idx = channel_idx;
467 ttys[j]->secondary_channel_idx = secondary_channel_idx;
468 ttys[j]->network = network;
469 ttys[j]->tty_type = tty_type;
470 mutex_init(&ttys[j]->ipw_tty_mutex);
Jiri Slaby7393af82012-04-02 13:54:33 +0200471 tty_port_init(&ttys[j]->port);
David Sterba099dc4f2008-02-07 10:57:12 +0100472
Jiri Slaby734cc172012-08-07 21:47:47 +0200473 tty_port_register_device(&ttys[j]->port, ipw_tty_driver, j, NULL);
David Sterba099dc4f2008-02-07 10:57:12 +0100474 ipwireless_associate_network_tty(network, channel_idx, ttys[j]);
475
476 if (secondary_channel_idx != -1)
477 ipwireless_associate_network_tty(network,
478 secondary_channel_idx,
479 ttys[j]);
Jiri Slabye6df3cc2012-04-02 13:54:32 +0200480 /* check if we provide raw device (if loopback is enabled) */
481 if (get_tty(j))
482 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
483 ": registering %s device ttyIPWp%d\n",
484 tty_type_name(tty_type), j);
485
David Sterba099dc4f2008-02-07 10:57:12 +0100486 return 0;
487}
488
489struct ipw_tty *ipwireless_tty_create(struct ipw_hardware *hardware,
Dominik Brodowskib498ada2010-03-20 19:43:26 +0100490 struct ipw_network *network)
David Sterba099dc4f2008-02-07 10:57:12 +0100491{
492 int i, j;
493
494 for (i = 0; i < IPWIRELESS_PCMCIA_MINOR_RANGE; i++) {
495 int allfree = 1;
496
497 for (j = i; j < IPWIRELESS_PCMCIA_MINORS;
498 j += IPWIRELESS_PCMCIA_MINOR_RANGE)
499 if (ttys[j] != NULL) {
500 allfree = 0;
501 break;
502 }
503
504 if (allfree) {
505 j = i;
506
Dominik Brodowskib498ada2010-03-20 19:43:26 +0100507 if (add_tty(j, hardware, network,
David Sterba099dc4f2008-02-07 10:57:12 +0100508 IPW_CHANNEL_DIALLER, IPW_CHANNEL_RAS,
509 TTYTYPE_MODEM))
510 return NULL;
511
512 j += IPWIRELESS_PCMCIA_MINOR_RANGE;
Dominik Brodowskib498ada2010-03-20 19:43:26 +0100513 if (add_tty(j, hardware, network,
David Sterba099dc4f2008-02-07 10:57:12 +0100514 IPW_CHANNEL_DIALLER, -1,
515 TTYTYPE_MONITOR))
516 return NULL;
517
518 j += IPWIRELESS_PCMCIA_MINOR_RANGE;
Dominik Brodowskib498ada2010-03-20 19:43:26 +0100519 if (add_tty(j, hardware, network,
David Sterba099dc4f2008-02-07 10:57:12 +0100520 IPW_CHANNEL_RAS, -1,
521 TTYTYPE_RAS_RAW))
522 return NULL;
523
David Sterba099dc4f2008-02-07 10:57:12 +0100524 return ttys[i];
525 }
526 }
527 return NULL;
528}
529
530/*
531 * Must be called before ipwireless_network_free().
532 */
533void ipwireless_tty_free(struct ipw_tty *tty)
534{
535 int j;
536 struct ipw_network *network = ttys[tty->index]->network;
537
538 for (j = tty->index; j < IPWIRELESS_PCMCIA_MINORS;
539 j += IPWIRELESS_PCMCIA_MINOR_RANGE) {
540 struct ipw_tty *ttyj = ttys[j];
541
542 if (ttyj) {
543 mutex_lock(&ttyj->ipw_tty_mutex);
Jiri Slabye6df3cc2012-04-02 13:54:32 +0200544 if (get_tty(j))
545 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
546 ": deregistering %s device ttyIPWp%d\n",
547 tty_type_name(ttyj->tty_type), j);
David Sterba099dc4f2008-02-07 10:57:12 +0100548 ttyj->closing = 1;
Jiri Slaby19ef1b72012-04-02 13:54:34 +0200549 if (ttyj->port.tty != NULL) {
David Sterba099dc4f2008-02-07 10:57:12 +0100550 mutex_unlock(&ttyj->ipw_tty_mutex);
Jiri Slaby19ef1b72012-04-02 13:54:34 +0200551 tty_vhangup(ttyj->port.tty);
Alan Cox5aaa70a2008-10-13 10:38:07 +0100552 /* FIXME: Exactly how is the tty object locked here
553 against a parallel ioctl etc */
Jiri Slabyde3a60a2012-04-02 13:54:31 +0200554 /* FIXME2: hangup does not mean all processes
555 * are gone */
David Sterba099dc4f2008-02-07 10:57:12 +0100556 mutex_lock(&ttyj->ipw_tty_mutex);
557 }
Jiri Slaby7393af82012-04-02 13:54:33 +0200558 while (ttyj->port.count)
David Sterba099dc4f2008-02-07 10:57:12 +0100559 do_ipw_close(ttyj);
560 ipwireless_disassociate_network_ttys(network,
561 ttyj->channel_idx);
562 tty_unregister_device(ipw_tty_driver, j);
Jiri Slaby191c5f12012-11-15 09:49:56 +0100563 tty_port_destroy(&ttyj->port);
David Sterba099dc4f2008-02-07 10:57:12 +0100564 ttys[j] = NULL;
565 mutex_unlock(&ttyj->ipw_tty_mutex);
566 kfree(ttyj);
567 }
568 }
569}
570
Alexey Dobriyan1cceefd2009-10-03 00:12:06 +0400571static const struct tty_operations tty_ops = {
David Sterba099dc4f2008-02-07 10:57:12 +0100572 .open = ipw_open,
573 .close = ipw_close,
574 .hangup = ipw_hangup,
575 .write = ipw_write,
576 .write_room = ipw_write_room,
577 .ioctl = ipw_ioctl,
578 .chars_in_buffer = ipw_chars_in_buffer,
579 .tiocmget = ipw_tiocmget,
580 .tiocmset = ipw_tiocmset,
581};
582
583int ipwireless_tty_init(void)
584{
585 int result;
586
587 ipw_tty_driver = alloc_tty_driver(IPWIRELESS_PCMCIA_MINORS);
588 if (!ipw_tty_driver)
589 return -ENOMEM;
590
David Sterba099dc4f2008-02-07 10:57:12 +0100591 ipw_tty_driver->driver_name = IPWIRELESS_PCCARD_NAME;
592 ipw_tty_driver->name = "ttyIPWp";
593 ipw_tty_driver->major = 0;
594 ipw_tty_driver->minor_start = IPWIRELESS_PCMCIA_START;
595 ipw_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
596 ipw_tty_driver->subtype = SERIAL_TYPE_NORMAL;
597 ipw_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
598 ipw_tty_driver->init_termios = tty_std_termios;
599 ipw_tty_driver->init_termios.c_cflag =
600 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
601 ipw_tty_driver->init_termios.c_ispeed = 9600;
602 ipw_tty_driver->init_termios.c_ospeed = 9600;
603 tty_set_operations(ipw_tty_driver, &tty_ops);
604 result = tty_register_driver(ipw_tty_driver);
605 if (result) {
606 printk(KERN_ERR IPWIRELESS_PCCARD_NAME
607 ": failed to register tty driver\n");
608 put_tty_driver(ipw_tty_driver);
609 return result;
610 }
611
612 return 0;
613}
614
615void ipwireless_tty_release(void)
616{
617 int ret;
618
619 ret = tty_unregister_driver(ipw_tty_driver);
620 put_tty_driver(ipw_tty_driver);
621 if (ret != 0)
622 printk(KERN_ERR IPWIRELESS_PCCARD_NAME
623 ": tty_unregister_driver failed with code %d\n", ret);
624}
625
626int ipwireless_tty_is_modem(struct ipw_tty *tty)
627{
628 return tty->tty_type == TTYTYPE_MODEM;
629}
630
631void
632ipwireless_tty_notify_control_line_change(struct ipw_tty *tty,
633 unsigned int channel_idx,
634 unsigned int control_lines,
635 unsigned int changed_mask)
636{
637 unsigned int old_control_lines = tty->control_lines;
638
639 tty->control_lines = (tty->control_lines & ~changed_mask)
640 | (control_lines & changed_mask);
641
642 /*
643 * If DCD is de-asserted, we close the tty so pppd can tell that we
644 * have gone offline.
645 */
646 if ((old_control_lines & IPW_CONTROL_LINE_DCD)
647 && !(tty->control_lines & IPW_CONTROL_LINE_DCD)
Jiri Slaby19ef1b72012-04-02 13:54:34 +0200648 && tty->port.tty) {
649 tty_hangup(tty->port.tty);
David Sterba099dc4f2008-02-07 10:57:12 +0100650 }
651}
652