37 #include <linux/types.h>
39 #include <linux/errno.h>
40 #include <linux/signal.h>
41 #include <linux/fcntl.h>
42 #include <linux/sched.h>
44 #include <linux/tty.h>
45 #include <linux/ctype.h>
47 #include <linux/string.h>
48 #include <linux/slab.h>
49 #include <linux/poll.h>
50 #include <linux/bitops.h>
53 #include <linux/module.h>
57 #include <linux/serial.h>
62 #include <linux/netdevice.h>
87 #define GSM_NET_TX_TIMEOUT (HZ*10)
102 #define STATS(net) (((struct gsm_mux_net *)netdev_priv(net))->stats)
133 #define DLCI_CLOSED 0
134 #define DLCI_OPENING 1
136 #define DLCI_CLOSING 3
211 #define GSM_ADDRESS 2
212 #define GSM_CONTROL 3
216 #define GSM_OVERRUN 7
246 #define TX_THRESH_HI 8192
247 #define TX_THRESH_LO 2048
305 #define CMD_TEST 0x11
308 #define CMD_FCOFF 0x31
311 #define CMD_FCON 0x51
323 #define GSM0_SOF 0xF9
324 #define GSM1_SOF 0x7E
325 #define GSM1_ESCAPE 0x7D
326 #define GSM1_ESCAPE_BITS 0x20
336 static const u8 gsm_fcs8[256] = {
337 0x00, 0x91, 0xE3, 0x72, 0x07, 0x96, 0xE4, 0x75,
338 0x0E, 0x9F, 0xED, 0x7C, 0x09, 0x98, 0xEA, 0x7B,
339 0x1C, 0x8D, 0xFF, 0x6E, 0x1B, 0x8A, 0xF8, 0x69,
340 0x12, 0x83, 0xF1, 0x60, 0x15, 0x84, 0xF6, 0x67,
341 0x38, 0xA9, 0xDB, 0x4A, 0x3F, 0xAE, 0xDC, 0x4D,
342 0x36, 0xA7, 0xD5, 0x44, 0x31, 0xA0, 0xD2, 0x43,
343 0x24, 0xB5, 0xC7, 0x56, 0x23, 0xB2, 0xC0, 0x51,
344 0x2A, 0xBB, 0xC9, 0x58, 0x2D, 0xBC, 0xCE, 0x5F,
345 0x70, 0xE1, 0x93, 0x02, 0x77, 0xE6, 0x94, 0x05,
346 0x7E, 0xEF, 0x9D, 0x0C, 0x79, 0xE8, 0x9A, 0x0B,
347 0x6C, 0xFD, 0x8F, 0x1E, 0x6B, 0xFA, 0x88, 0x19,
348 0x62, 0xF3, 0x81, 0x10, 0x65, 0xF4, 0x86, 0x17,
349 0x48, 0xD9, 0xAB, 0x3A, 0x4F, 0xDE, 0xAC, 0x3D,
350 0x46, 0xD7, 0xA5, 0x34, 0x41, 0xD0, 0xA2, 0x33,
351 0x54, 0xC5, 0xB7, 0x26, 0x53, 0xC2, 0xB0, 0x21,
352 0x5A, 0xCB, 0xB9, 0x28, 0x5D, 0xCC, 0xBE, 0x2F,
353 0xE0, 0x71, 0x03, 0x92, 0xE7, 0x76, 0x04, 0x95,
354 0xEE, 0x7F, 0x0D, 0x9C, 0xE9, 0x78, 0x0A, 0x9B,
355 0xFC, 0x6D, 0x1F, 0x8E, 0xFB, 0x6A, 0x18, 0x89,
356 0xF2, 0x63, 0x11, 0x80, 0xF5, 0x64, 0x16, 0x87,
357 0xD8, 0x49, 0x3B, 0xAA, 0xDF, 0x4E, 0x3C, 0xAD,
358 0xD6, 0x47, 0x35, 0xA4, 0xD1, 0x40, 0x32, 0xA3,
359 0xC4, 0x55, 0x27, 0xB6, 0xC3, 0x52, 0x20, 0xB1,
360 0xCA, 0x5B, 0x29, 0xB8, 0xCD, 0x5C, 0x2E, 0xBF,
361 0x90, 0x01, 0x73, 0xE2, 0x97, 0x06, 0x74, 0xE5,
362 0x9E, 0x0F, 0x7D, 0xEC, 0x99, 0x08, 0x7A, 0xEB,
363 0x8C, 0x1D, 0x6F, 0xFE, 0x8B, 0x1A, 0x68, 0xF9,
364 0x82, 0x13, 0x61, 0xF0, 0x85, 0x14, 0x66, 0xF7,
365 0xA8, 0x39, 0x4B, 0xDA, 0xAF, 0x3E, 0x4C, 0xDD,
366 0xA6, 0x37, 0x45, 0xD4, 0xA1, 0x30, 0x42, 0xD3,
367 0xB4, 0x25, 0x57, 0xC6, 0xB3, 0x22, 0x50, 0xC1,
368 0xBA, 0x2B, 0x59, 0xC8, 0xBD, 0x2C, 0x5E, 0xCF
371 #define INIT_FCS 0xFF
372 #define GOOD_FCS 0xCF
385 return gsm_fcs8[fcs ^
c];
398 static inline u8 gsm_fcs_add_block(
u8 fcs,
u8 *
c,
int len)
401 fcs = gsm_fcs8[fcs ^ *c++];
414 static int gsm_read_ea(
unsigned int *
val,
u8 c)
461 static void gsm_print_packet(
const char *
hdr,
int addr,
int cr,
467 pr_info(
"%s %d) %c: ", hdr, addr,
"RC"[cr]);
469 switch (control & ~
PF) {
489 if (!(control & 0x01)) {
491 (control & 0x0E) >> 1, (control & 0xE0) >> 5);
492 }
else switch (control & 0x0F) {
494 pr_cont(
"RR(%d)", (control & 0xE0) >> 5);
497 pr_cont(
"RNR(%d)", (control & 0xE0) >> 5);
500 pr_cont(
"REJ(%d)", (control & 0xE0) >> 5);
542 static int gsm_stuff_frame(
const u8 *
input,
u8 *output,
int len)
547 || *input ==
XON || *input ==
XOFF) {
552 *output++ = *input++;
572 static void gsm_send(
struct gsm_mux *gsm,
int addr,
int cr,
int control)
581 cbuf[1] = (addr << 2) | (cr << 1) |
EA;
584 cbuf[4] = 0xFF - gsm_fcs_add_block(
INIT_FCS, cbuf + 1, 3);
591 ibuf[0] = (addr << 2) | (cr << 1) |
EA;
593 ibuf[2] = 0xFF - gsm_fcs_add_block(
INIT_FCS, ibuf, 2);
595 len = gsm_stuff_frame(ibuf, cbuf + 1, 3);
606 gsm->
output(gsm, cbuf, len);
607 gsm_print_packet(
"-->", addr, cr, control,
NULL, 0);
619 static inline void gsm_response(
struct gsm_mux *gsm,
int addr,
int control)
621 gsm_send(gsm, addr, 0, control);
633 static inline void gsm_command(
struct gsm_mux *gsm,
int addr,
int control)
635 gsm_send(gsm, addr, 1, control);
654 static struct gsm_msg *gsm_data_alloc(
struct gsm_mux *gsm,
u8 addr,
int len,
665 INIT_LIST_HEAD(&m->
list);
681 static void gsm_data_kick(
struct gsm_mux *gsm)
692 len = gsm_stuff_frame(msg->
data,
704 print_hex_dump_bytes(
"gsm_data_kick: ",
732 static void __gsm_data_queue(
struct gsm_dlci *dlci,
struct gsm_msg *msg)
734 struct gsm_mux *gsm = dlci->
gsm;
736 u8 *fcs = dp + msg->
len;
741 *--dp = (msg->
len << 1) |
EA;
743 *--dp = (msg->
len >> 7);
744 *--dp = (msg->
len & 127) << 1;
750 *--dp = (msg->
addr << 2) | 2 |
EA;
752 *--dp = (msg->
addr << 2) |
EA;
753 *fcs = gsm_fcs_add_block(
INIT_FCS, dp , msg->
data - dp);
756 *fcs = gsm_fcs_add_block(*fcs, msg->
data, msg->
len);
787 __gsm_data_queue(dlci, msg);
788 spin_unlock_irqrestore(&dlci->
gsm->tx_lock, flags);
803 static int gsm_dlci_data_output(
struct gsm_mux *gsm,
struct gsm_dlci *dlci)
822 msg = gsm_data_alloc(gsm, dlci->
addr, size, gsm->
ftype);
833 *dp++ = gsm_encode_modem(dlci);
837 __gsm_data_queue(dlci, msg);
856 static int gsm_dlci_data_output_framed(
struct gsm_mux *gsm,
876 len = dlci->
skb->len + overhead;
879 if (len > gsm->
mtu) {
890 size = len + overhead;
891 msg = gsm_data_alloc(gsm, dlci->
addr, size, gsm->
ftype);
904 *dp++ = last << 7 |
first << 6 | 1;
909 __gsm_data_queue(dlci, msg);
930 static void gsm_dlci_data_sweep(
struct gsm_mux *gsm)
947 len = gsm_dlci_data_output(gsm, dlci);
949 len = gsm_dlci_data_output_framed(gsm, dlci);
967 static void gsm_dlci_data_kick(
struct gsm_dlci *dlci)
978 if (dlci->
gsm->tx_bytes == 0) {
980 gsm_dlci_data_output_framed(dlci->
gsm, dlci);
982 gsm_dlci_data_output(dlci->
gsm, dlci);
985 gsm_dlci_data_sweep(dlci->
gsm);
986 spin_unlock_irqrestore(&dlci->
gsm->tx_lock, flags);
1004 static void gsm_control_reply(
struct gsm_mux *gsm,
int cmd,
u8 *data,
1008 msg = gsm_data_alloc(gsm, 0, dlen + 2, gsm->
ftype);
1011 msg->
data[0] = (cmd & 0xFE) << 1 |
EA;
1012 msg->
data[1] = (dlen << 1) |
EA;
1014 gsm_data_queue(gsm->
dlci[0], msg);
1040 modem = modem & 0x7f;
1043 modem = (modem >> 7) & 0x7f;
1053 gsm_dlci_data_kick(dlci);
1059 if (modem & MDM_RTR)
1069 if (!(tty->termios.c_cflag &
CLOCAL))
1072 tty_insert_flip_char(tty, 0,
TTY_BREAK);
1089 static void gsm_control_modem(
struct gsm_mux *gsm,
u8 *data,
int clen)
1091 unsigned int addr = 0;
1092 unsigned int modem = 0;
1098 while (gsm_read_ea(&addr, *dp++) == 0) {
1114 while (gsm_read_ea(&modem, *dp++) == 0) {
1120 gsm_process_modem(tty, dlci, modem, clen);
1125 gsm_control_reply(gsm,
CMD_MSC, data, clen);
1139 static void gsm_control_rls(
struct gsm_mux *gsm,
u8 *data,
int clen)
1142 unsigned int addr = 0 ;
1147 while (gsm_read_ea(&addr, *dp++) == 0) {
1162 if ((bits & 1) == 0)
1173 tty_insert_flip_char(tty, 0,
TTY_FRAME);
1177 gsm_control_reply(gsm,
CMD_RLS, data, clen);
1180 static void gsm_dlci_begin_close(
struct gsm_dlci *dlci);
1194 static void gsm_control_message(
struct gsm_mux *gsm,
unsigned int command,
1198 unsigned long flags;
1207 gsm_dlci_begin_close(dlci);
1213 gsm_control_reply(gsm,
CMD_TEST, data, clen);
1222 spin_unlock_irqrestore(&gsm->
tx_lock, flags);
1231 gsm_control_modem(gsm, data, clen);
1235 gsm_control_rls(gsm, data, clen);
1248 gsm_control_reply(gsm,
CMD_NSC, buf, 1);
1266 static void gsm_control_response(
struct gsm_mux *gsm,
unsigned int command,
1270 unsigned long flags;
1277 if (ctrl !=
NULL && (command == ctrl->
cmd || command ==
CMD_NSC)) {
1298 static void gsm_control_transmit(
struct gsm_mux *gsm,
struct gsm_control *ctrl)
1300 struct gsm_msg *msg = gsm_data_alloc(gsm, 0, ctrl->
len + 1, gsm->
ftype);
1303 msg->
data[0] = (ctrl->
cmd << 1) | 2 |
EA;
1305 gsm_data_queue(gsm->
dlci[0], msg);
1319 static void gsm_control_retransmit(
unsigned long data)
1321 struct gsm_mux *gsm = (
struct gsm_mux *)data;
1323 unsigned long flags;
1336 gsm_control_transmit(gsm, ctrl);
1354 static struct gsm_control *gsm_control_send(
struct gsm_mux *gsm,
1355 unsigned int command,
u8 *data,
int clen)
1359 unsigned long flags;
1375 gsm_control_transmit(gsm, ctrl);
1390 static int gsm_control_wait(
struct gsm_mux *gsm,
struct gsm_control *control)
1394 err = control->
error;
1416 static void gsm_dlci_close(
struct gsm_dlci *dlci)
1422 if (dlci->
addr != 0) {
1430 dlci->
gsm->dead = 1;
1443 static void gsm_dlci_open(
struct gsm_dlci *dlci)
1466 static void gsm_dlci_t1(
unsigned long data)
1469 struct gsm_mux *gsm = dlci->
gsm;
1471 switch (dlci->
state) {
1478 gsm_dlci_close(dlci);
1486 gsm_dlci_close(dlci);
1501 static void gsm_dlci_begin_open(
struct gsm_dlci *dlci)
1503 struct gsm_mux *gsm = dlci->
gsm;
1523 static void gsm_dlci_begin_close(
struct gsm_dlci *dlci)
1525 struct gsm_mux *gsm = dlci->
gsm;
1545 static void gsm_dlci_data(
struct gsm_dlci *dlci,
u8 *data,
int clen)
1550 unsigned int modem = 0;
1554 pr_debug(
"%d bytes for tty %p\n", len, tty);
1566 while (gsm_read_ea(&modem, *data++) == 0) {
1571 gsm_process_modem(tty, dlci, modem, clen);
1575 tty_insert_flip_string(tty, data, len);
1594 static void gsm_dlci_command(
struct gsm_dlci *dlci,
u8 *data,
int len)
1597 unsigned int command = 0;
1599 if (gsm_read_ea(&command, *data++) == 1) {
1608 gsm_control_message(dlci->
gsm, command,
1611 gsm_control_response(dlci->
gsm, command,
1632 static struct gsm_dlci *gsm_dlci_alloc(
struct gsm_mux *gsm,
int addr)
1638 kref_init(&dlci->
ref);
1646 skb_queue_head_init(&dlci->
skb_list);
1648 dlci->
t1.function = gsm_dlci_t1;
1649 dlci->
t1.data = (
unsigned long)dlci;
1651 dlci->
port.ops = &gsm_port_ops;
1657 dlci->
data = gsm_dlci_data;
1659 dlci->
data = gsm_dlci_command;
1672 static void gsm_dlci_free(
struct kref *
ref)
1680 dev_kfree_skb(dlci->
skb);
1684 static inline void dlci_get(
struct gsm_dlci *dlci)
1686 kref_get(&dlci->
ref);
1689 static inline void dlci_put(
struct gsm_dlci *dlci)
1691 kref_put(&dlci->
ref, gsm_dlci_free);
1703 static void gsm_dlci_release(
struct gsm_dlci *dlci)
1727 static void gsm_queue(
struct gsm_mux *gsm)
1736 gsm->
fcs = gsm_fcs_add_block(gsm->
fcs, gsm->
buf, gsm->
len);
1755 gsm_print_packet(
"<--", address, cr, gsm->
control, gsm->
buf, gsm->
len);
1765 dlci = gsm_dlci_alloc(gsm, address);
1769 gsm_response(gsm, address,
DM);
1771 gsm_response(gsm, address,
UA);
1772 gsm_dlci_open(dlci);
1779 gsm_response(gsm, address,
DM);
1783 gsm_response(gsm, address,
UA);
1784 gsm_dlci_close(dlci);
1788 if (cr == 0 || dlci ==
NULL)
1790 switch (dlci->
state) {
1792 gsm_dlci_close(dlci);
1795 gsm_dlci_open(dlci);
1805 gsm_dlci_close(dlci);
1816 gsm_command(gsm, address,
DM|PF);
1839 static void gsm0_receive(
struct gsm_mux *gsm,
unsigned char c)
1843 switch (gsm->
state) {
1853 gsm->
fcs = gsm_fcs_add(gsm->
fcs, c);
1854 if (gsm_read_ea(&gsm->
address, c))
1858 gsm->
fcs = gsm_fcs_add(gsm->
fcs, c);
1863 gsm->
fcs = gsm_fcs_add(gsm->
fcs, c);
1864 if (gsm_read_ea(&gsm->
len, c)) {
1865 if (gsm->
len > gsm->
mru) {
1880 gsm->
fcs = gsm_fcs_add(gsm->
fcs, c);
1882 gsm->
len |= len << 7;
1883 if (gsm->
len > gsm->
mru) {
1921 static void gsm1_receive(
struct gsm_mux *gsm,
unsigned char c)
1958 switch (gsm->
state) {
1965 gsm->
fcs = gsm_fcs_add(gsm->
fcs, c);
1966 if (gsm_read_ea(&gsm->
address, c))
1970 gsm->
fcs = gsm_fcs_add(gsm->
fcs, c);
1999 static void gsm_error(
struct gsm_mux *gsm,
2000 unsigned char data,
unsigned char flag)
2024 spin_lock(&gsm_mux_lock);
2025 for (i = 0; i <
MAX_MUX; i++) {
2026 if (gsm_mux[i] == gsm) {
2031 spin_unlock(&gsm_mux_lock);
2039 gsm_control_wait(gsm, gc);
2045 gsm_dlci_begin_close(dlci);
2052 gsm_dlci_release(gsm->
dlci[i]);
2056 INIT_LIST_HEAD(&gsm->
tx_list);
2075 gsm->
t2_timer.function = gsm_control_retransmit;
2085 gsm->
error = gsm_error;
2087 spin_lock(&gsm_mux_lock);
2088 for (i = 0; i <
MAX_MUX; i++) {
2089 if (gsm_mux[i] ==
NULL) {
2095 spin_unlock(&gsm_mux_lock);
2099 dlci = gsm_dlci_alloc(gsm, 0);
2127 static void gsm_free_muxr(
struct kref *ref)
2129 struct gsm_mux *gsm =
container_of(ref,
struct gsm_mux, ref);
2133 static inline void mux_get(
struct gsm_mux *gsm)
2135 kref_get(&gsm->
ref);
2138 static inline void mux_put(
struct gsm_mux *gsm)
2140 kref_put(&gsm->
ref, gsm_free_muxr);
2151 struct gsm_mux *gsm = kzalloc(
sizeof(
struct gsm_mux),
GFP_KERNEL);
2166 kref_init(&gsm->
ref);
2167 INIT_LIST_HEAD(&gsm->
tx_list);
2193 static int gsmld_output(
struct gsm_mux *gsm,
u8 *data,
int len)
2202 gsm->
tty->ops->write(gsm->
tty, data, len);
2216 static int gsmld_attach_gsm(
struct tty_struct *tty,
struct gsm_mux *gsm)
2221 gsm->
tty = tty_kref_get(tty);
2222 gsm->
output = gsmld_output;
2244 static void gsmld_detach_gsm(
struct tty_struct *tty,
struct gsm_mux *gsm)
2247 int base = gsm->
num << 6;
2257 static void gsmld_receive_buf(
struct tty_struct *tty,
const unsigned char *
cp,
2261 const unsigned char *
dp;
2271 for (i = count, dp = cp, f = fp;
i; i--, dp++) {
2281 gsm->
error(gsm, *dp, flags);
2317 static void gsmld_flush_buffer(
struct tty_struct *tty)
2331 static void gsmld_close(
struct tty_struct *tty)
2335 gsmld_detach_gsm(tty, gsm);
2337 gsmld_flush_buffer(tty);
2352 static int gsmld_open(
struct tty_struct *tty)
2354 struct gsm_mux *gsm;
2369 return gsmld_attach_gsm(tty, gsm);
2381 static void gsmld_write_wakeup(
struct tty_struct *tty)
2384 unsigned long flags;
2391 gsm_dlci_data_sweep(gsm);
2393 spin_unlock_irqrestore(&gsm->
tx_lock, flags);
2412 unsigned char __user *buf,
size_t nr)
2432 const unsigned char *buf,
size_t nr)
2436 return tty->
ops->write(tty, buf, nr);
2455 static unsigned int gsmld_poll(
struct tty_struct *tty,
struct file *file,
2458 unsigned int mask = 0;
2472 static int gsmld_config(
struct tty_struct *tty,
struct gsm_mux *gsm,
2476 int need_restart = 0;
2490 if (c->
i == 0 || c->
i > 2)
2497 if (c->
t1 != 0 && c->
t1 != gsm->
t1)
2499 if (c->
t2 != 0 && c->
t2 != gsm->
t2)
2518 if (need_close || need_restart) {
2519 gsm_dlci_begin_close(gsm->
dlci[0]);
2551 gsm_dlci_begin_open(gsm->
dlci[0]);
2555 static int gsmld_ioctl(
struct tty_struct *tty,
struct file *file,
2556 unsigned int cmd,
unsigned long arg)
2563 memset(&c, 0,
sizeof(c));
2585 return gsmld_config(tty, gsm, &c);
2599 netif_start_queue(net);
2605 netif_stop_queue(net);
2613 static void dlci_net_free(
struct gsm_dlci *dlci)
2624 static void net_free(
struct kref *ref)
2630 dlci = mux_net->
dlci;
2634 dlci_net_free(dlci);
2638 static inline void muxnet_get(
struct gsm_mux_net *mux_net)
2640 kref_get(&mux_net->
ref);
2643 static inline void muxnet_put(
struct gsm_mux_net *mux_net)
2645 kref_put(&mux_net->
ref, net_free);
2648 static int gsm_mux_net_start_xmit(
struct sk_buff *
skb,
2653 muxnet_get(mux_net);
2656 STATS(net).tx_packets++;
2658 gsm_dlci_data_kick(dlci);
2661 muxnet_put(mux_net);
2666 static void gsm_mux_net_tx_timeout(
struct net_device *net)
2672 STATS(net).tx_errors++;
2675 static void gsm_mux_rx_netchar(
struct gsm_dlci *dlci,
2676 unsigned char *in_buf,
int size)
2681 muxnet_get(mux_net);
2687 STATS(net).rx_dropped++;
2688 muxnet_put(mux_net);
2701 STATS(net).rx_packets++;
2703 muxnet_put(mux_net);
2710 if ((new_mtu < 8) || (new_mtu > mux_net->
dlci->gsm->mtu))
2716 static void gsm_mux_net_init(
struct net_device *net)
2720 .ndo_stop = gsm_mux_net_close,
2721 .ndo_start_xmit = gsm_mux_net_start_xmit,
2722 .ndo_tx_timeout = gsm_mux_net_tx_timeout,
2723 .ndo_get_stats = gsm_mux_net_get_stats,
2738 static void gsm_destroy_network(
struct gsm_dlci *dlci)
2742 pr_debug(
"destroy network interface");
2746 muxnet_put(mux_net);
2771 pr_debug(
"create network interface");
2780 pr_err(
"alloc_netdev failed");
2783 net->
mtu = dlci->
gsm->mtu;
2786 kref_init(&mux_net->
ref);
2793 dlci->
data = gsm_mux_rx_netchar;
2799 pr_err(
"network register fail %d\n", retval);
2800 dlci_net_free(dlci);
2812 .close = gsmld_close,
2813 .flush_buffer = gsmld_flush_buffer,
2814 .chars_in_buffer = gsmld_chars_in_buffer,
2816 .write = gsmld_write,
2817 .ioctl = gsmld_ioctl,
2819 .receive_buf = gsmld_receive_buf,
2820 .write_wakeup = gsmld_write_wakeup
2829 static int gsmtty_modem_update(
struct gsm_dlci *dlci,
u8 brk)
2838 modembits[0] = len << 1 |
EA;
2839 modembits[1] = dlci->
addr << 2 | 3;
2840 modembits[2] = gsm_encode_modem(dlci) << 1 |
EA;
2842 modembits[3] = brk << 4 | 2 |
EA;
2843 ctrl = gsm_control_send(dlci->
gsm,
CMD_MSC, modembits, len + 1);
2846 return gsm_control_wait(dlci->
gsm, ctrl);
2849 static int gsm_carrier_raised(
struct tty_port *port)
2870 gsmtty_modem_update(dlci, 0);
2875 .carrier_raised = gsm_carrier_raised,
2876 .dtr_rts = gsm_dtr_rts,
2881 struct gsm_mux *gsm;
2884 unsigned int mux = line >> 6;
2893 if (gsm_mux[mux] ==
NULL)
2895 if (line == 0 || line > 61)
2904 dlci = gsm->
dlci[line];
2907 dlci = gsm_dlci_alloc(gsm, line);
2923 static int gsmtty_open(
struct tty_struct *tty,
struct file *filp)
2930 dlci_get(dlci->
gsm->dlci[0]);
2939 gsm_dlci_begin_open(dlci);
2944 static void gsmtty_close(
struct tty_struct *tty,
struct file *filp)
2947 struct gsm_mux *gsm;
2952 gsm_destroy_network(dlci);
2957 gsm_dlci_begin_close(dlci);
2962 dlci_put(gsm->
dlci[0]);
2966 static void gsmtty_hangup(
struct tty_struct *tty)
2970 gsm_dlci_begin_close(dlci);
2973 static int gsmtty_write(
struct tty_struct *tty,
const unsigned char *buf,
2980 gsm_dlci_data_kick(dlci);
2984 static int gsmtty_write_room(
struct tty_struct *tty)
2990 static int gsmtty_chars_in_buffer(
struct tty_struct *tty)
2996 static void gsmtty_flush_buffer(
struct tty_struct *tty)
3007 static void gsmtty_wait_until_sent(
struct tty_struct *tty,
int timeout)
3014 static int gsmtty_tiocmget(
struct tty_struct *tty)
3020 static int gsmtty_tiocmset(
struct tty_struct *tty,
3021 unsigned int set,
unsigned int clear)
3024 unsigned int modem_tx = dlci->
modem_tx;
3031 return gsmtty_modem_update(dlci, 0);
3037 static int gsmtty_ioctl(
struct tty_struct *tty,
3038 unsigned int cmd,
unsigned long arg)
3051 index = gsm_create_network(dlci, &nc);
3060 gsm_destroy_network(dlci);
3078 static void gsmtty_throttle(
struct tty_struct *tty)
3081 if (tty->termios.c_cflag &
CRTSCTS)
3085 gsmtty_modem_update(dlci, 0);
3088 static void gsmtty_unthrottle(
struct tty_struct *tty)
3091 if (tty->termios.c_cflag &
CRTSCTS)
3095 gsmtty_modem_update(dlci, 0);
3106 else if (state > 0) {
3107 encode = state / 200;
3111 return gsmtty_modem_update(dlci, encode);
3117 .install = gsmtty_install,
3118 .open = gsmtty_open,
3119 .close = gsmtty_close,
3120 .write = gsmtty_write,
3121 .write_room = gsmtty_write_room,
3122 .chars_in_buffer = gsmtty_chars_in_buffer,
3123 .flush_buffer = gsmtty_flush_buffer,
3124 .ioctl = gsmtty_ioctl,
3125 .throttle = gsmtty_throttle,
3126 .unthrottle = gsmtty_unthrottle,
3127 .set_termios = gsmtty_set_termios,
3128 .hangup = gsmtty_hangup,
3129 .wait_until_sent = gsmtty_wait_until_sent,
3130 .tiocmget = gsmtty_tiocmget,
3131 .tiocmset = gsmtty_tiocmset,
3132 .break_ctl = gsmtty_break_ctl,
3137 static int __init gsm_init(
void)
3142 pr_err(
"n_gsm: can't register line discipline (err = %d)\n",
3147 gsm_tty_driver = alloc_tty_driver(256);
3148 if (!gsm_tty_driver) {
3150 pr_err(
"gsm_init: tty allocation failed.\n");
3154 gsm_tty_driver->
name =
"gsmtty";
3155 gsm_tty_driver->
major = 0;
3171 pr_err(
"gsm_init: tty registration failed.\n");
3174 pr_debug(
"gsm_init: loaded as %d,%d.\n",
3179 static void __exit gsm_exit(
void)
3183 pr_err(
"n_gsm: can't unregister line discipline (err = %d)\n",