Lines Matching +full:single +full:- +full:mux +full:- +full:ctrl
1 // SPDX-License-Identifier: GPL-2.0
10 * tty -> DLCI fifo -> scheduler -> GSM MUX data queue ---o-> ldisc
11 * control message -> GSM MUX control queue --´
14 * ldisc -> gsm_queue() -o--> tty
15 * `-> gsm_control_response()
25 * Review the locking/move to refcounts more (mux now moved to an
30 * Do we need a 'which mux are you' ioctl to correlate mux and tty sets
96 * Semi-arbitrary buffer size limits. 0710 is normally run with 32-64 byte
102 /* SOF, ADDR, CTRL, LEN1, LEN2, ..., FCS, EOF */
107 * struct gsm_mux_net - network interface
125 u8 ctrl; /* Control byte + flags */ member
148 * complexity right now these are only ever freed up when the mux is
151 * At the moment we don't free DLCI objects until the mux is torn down
175 bool dead; /* Refuse re-open */
261 * Each GSM mux we have is represented by this structure. If we are
264 * to the gsm mux array. For now we don't free DLCI objects that
265 * have been instantiated until the mux itself is terminated.
267 * To consider further: tty open versus mux shutdown.
304 bool dead; /* Has the mux been shut down */
324 /* Keep-alive */
325 struct timer_list ka_timer; /* Keep-alive response timer */
326 u8 ka_num; /* Keep-alive match pattern */
327 signed int ka_retries; /* Keep-alive retry counter, -1 if not yet initialized */
333 unsigned int t3; /* Power wake-up timer in seconds. */
337 u32 keep_alive; /* Control channel keep-alive in 10ms */
350 * Mux objects - needed so that we can translate a tty index into the
351 * relevant mux and DLCI.
457 u8 ctrl);
464 * gsm_fcs_add - update FCS
478 * gsm_fcs_add_block - update FCS for a block
489 while (len--) in gsm_fcs_add_block()
495 * gsm_read_ea - read a byte into an EA
513 * gsm_read_ea_val - read a value until EA
525 for (; dlen > 0; dlen--) { in gsm_read_ea_val()
534 * gsm_encode_modem - encode modem data bits
545 if (dlci->throttled) in gsm_encode_modem()
547 if (dlci->modem_tx & TIOCM_DTR) in gsm_encode_modem()
549 if (dlci->modem_tx & TIOCM_RTS) in gsm_encode_modem()
551 if (dlci->modem_tx & TIOCM_RI) in gsm_encode_modem()
553 if (dlci->modem_tx & TIOCM_CD || dlci->gsm->initiator) in gsm_encode_modem()
556 if (dlci->modem_tx & TIOCM_OUT1) in gsm_encode_modem()
558 if (dlci->modem_tx & TIOCM_OUT2) in gsm_encode_modem()
583 * gsm_encode_params - encode DLCI parameters
593 const struct gsm_mux *gsm = dlci->gsm; in gsm_encode_params()
596 switch (dlci->ftype) { in gsm_encode_params()
604 pr_debug("unsupported frame type %d\n", dlci->ftype); in gsm_encode_params()
605 return -EINVAL; in gsm_encode_params()
608 switch (dlci->adaption) { in gsm_encode_params()
616 pr_debug("unsupported adaption %d\n", dlci->adaption); in gsm_encode_params()
617 return -EINVAL; in gsm_encode_params()
620 params->d_bits = FIELD_PREP(PN_D_FIELD_DLCI, dlci->addr); in gsm_encode_params()
622 params->i_cl_bits = FIELD_PREP(PN_I_CL_FIELD_FTYPE, i) | in gsm_encode_params()
624 params->p_bits = FIELD_PREP(PN_P_FIELD_PRIO, dlci->prio); in gsm_encode_params()
625 params->t_bits = FIELD_PREP(PN_T_FIELD_T1, gsm->t1); in gsm_encode_params()
626 params->n_bits = cpu_to_le16(FIELD_PREP(PN_N_FIELD_N1, dlci->mtu)); in gsm_encode_params()
627 params->na_bits = FIELD_PREP(PN_NA_FIELD_N2, gsm->n2); in gsm_encode_params()
628 params->k_bits = FIELD_PREP(PN_K_FIELD_K, dlci->k); in gsm_encode_params()
634 * gsm_register_devices - register all tty devices for a given mux index
637 * @index: the mux number is used to calculate the minor numbers of the
638 * ttys for this mux and may differ from the position in the
639 * mux array.
648 return -EINVAL; in gsm_register_devices()
652 /* Don't register device 0 - this is the control channel in gsm_register_devices()
660 for (i--; i >= 1; i--) in gsm_register_devices()
670 * gsm_unregister_devices - unregister all tty devices for a given mux index
673 * @index: the mux number is used to calculate the minor numbers of the
674 * ttys for this mux and may differ from the position in the
675 * mux array.
688 /* Don't unregister device 0 - this is the control in gsm_unregister_devices()
696 * gsm_print_packet - display a frame for debug
705 * style is based on amateur radio LAP-B dump display.
772 * gsm_stuff_frame - bytestuff a packet
785 while (len--) { in gsm_stuff_frame()
800 * gsm_send - send a control frame
801 * @gsm: our GSM mux
818 return -ENOMEM; in gsm_send()
821 ocr = cr ^ (gsm->initiator ? 0 : 1); in gsm_send()
823 msg->data -= 3; in gsm_send()
824 dp = msg->data; in gsm_send()
828 if (gsm->encoding == GSM_BASIC_OPT) in gsm_send()
831 *dp = 0xFF - gsm_fcs_add_block(INIT_FCS, msg->data, dp - msg->data); in gsm_send()
832 msg->len = (dp - msg->data) + 1; in gsm_send()
834 gsm_print_packet("Q->", addr, cr, control, NULL, 0); in gsm_send()
836 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_send()
837 list_add_tail(&msg->list, &gsm->tx_ctrl_list); in gsm_send()
838 gsm->tx_bytes += msg->len; in gsm_send()
839 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_send()
846 * gsm_dlci_clear_queues - remove outstanding data for a DLCI
847 * @gsm: mux
855 int addr = dlci->addr; in gsm_dlci_clear_queues()
859 spin_lock_irqsave(&dlci->lock, flags); in gsm_dlci_clear_queues()
860 kfifo_reset(&dlci->fifo); in gsm_dlci_clear_queues()
861 spin_unlock_irqrestore(&dlci->lock, flags); in gsm_dlci_clear_queues()
863 /* Clear data packets in MUX write queue */ in gsm_dlci_clear_queues()
864 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_dlci_clear_queues()
865 list_for_each_entry_safe(msg, nmsg, &gsm->tx_data_list, list) { in gsm_dlci_clear_queues()
866 if (msg->addr != addr) in gsm_dlci_clear_queues()
868 gsm->tx_bytes -= msg->len; in gsm_dlci_clear_queues()
869 list_del(&msg->list); in gsm_dlci_clear_queues()
872 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_dlci_clear_queues()
876 * gsm_response - send a control response
877 * @gsm: our GSM mux
890 * gsm_command - send a control command
891 * @gsm: our GSM mux
905 #define HDR_LEN 6 /* ADDR CTRL [LEN.2] DATA FCS */
908 * gsm_data_alloc - allocate data frame
909 * @gsm: GSM mux
912 * @ctrl: control byte
920 u8 ctrl) in gsm_data_alloc() argument
926 m->data = m->buffer + HDR_LEN - 1; /* Allow for FCS */ in gsm_data_alloc()
927 m->len = len; in gsm_data_alloc()
928 m->addr = addr; in gsm_data_alloc()
929 m->ctrl = ctrl; in gsm_data_alloc()
930 INIT_LIST_HEAD(&m->list); in gsm_data_alloc()
935 * gsm_send_packet - sends a single packet
936 * @gsm: GSM Mux
947 if (gsm->encoding == GSM_BASIC_OPT) { in gsm_send_packet()
948 gsm->txframe[0] = GSM0_SOF; in gsm_send_packet()
949 memcpy(gsm->txframe + 1, msg->data, msg->len); in gsm_send_packet()
950 gsm->txframe[msg->len + 1] = GSM0_SOF; in gsm_send_packet()
951 len = msg->len + 2; in gsm_send_packet()
953 gsm->txframe[0] = GSM1_SOF; in gsm_send_packet()
954 len = gsm_stuff_frame(msg->data, gsm->txframe + 1, msg->len); in gsm_send_packet()
955 gsm->txframe[len + 1] = GSM1_SOF; in gsm_send_packet()
960 gsm_hex_dump_bytes(__func__, gsm->txframe, len); in gsm_send_packet()
961 gsm_print_packet("-->", msg->addr, gsm->initiator, msg->ctrl, msg->data, in gsm_send_packet()
962 msg->len); in gsm_send_packet()
964 ret = gsmld_output(gsm, gsm->txframe, len); in gsm_send_packet()
968 gsm->tx_bytes -= msg->len; in gsm_send_packet()
974 * gsm_is_flow_ctrl_msg - checks if flow control message
984 if (msg->addr > 0) in gsm_is_flow_ctrl_msg()
987 switch (msg->ctrl & ~PF) { in gsm_is_flow_ctrl_msg()
991 if (gsm_read_ea_val(&cmd, msg->data + 2, msg->len - 2) < 1) in gsm_is_flow_ctrl_msg()
1005 * gsm_data_kick - poke the queue
1006 * @gsm: GSM Mux
1010 * If we have been flow-stopped by a CMD_FCOFF, then we can only
1020 clear_bit(TTY_DO_WRITE_WAKEUP, &gsm->tty->flags); in gsm_data_kick()
1023 list_for_each_entry_safe(msg, nmsg, &gsm->tx_ctrl_list, list) { in gsm_data_kick()
1024 if (gsm->constipated && !gsm_is_flow_ctrl_msg(msg)) in gsm_data_kick()
1028 case -ENOSPC: in gsm_data_kick()
1029 return -ENOSPC; in gsm_data_kick()
1030 case -ENODEV: in gsm_data_kick()
1032 gsm->tx_bytes -= msg->len; in gsm_data_kick()
1033 list_del(&msg->list); in gsm_data_kick()
1038 list_del(&msg->list); in gsm_data_kick()
1045 if (gsm->constipated) in gsm_data_kick()
1046 return -EAGAIN; in gsm_data_kick()
1049 if (list_empty(&gsm->tx_data_list)) in gsm_data_kick()
1051 list_for_each_entry_safe(msg, nmsg, &gsm->tx_data_list, list) { in gsm_data_kick()
1052 dlci = gsm->dlci[msg->addr]; in gsm_data_kick()
1054 if (dlci->state != DLCI_OPEN) { in gsm_data_kick()
1055 gsm->tx_bytes -= msg->len; in gsm_data_kick()
1056 list_del(&msg->list); in gsm_data_kick()
1062 case -ENOSPC: in gsm_data_kick()
1063 return -ENOSPC; in gsm_data_kick()
1064 case -ENODEV: in gsm_data_kick()
1066 gsm->tx_bytes -= msg->len; in gsm_data_kick()
1067 list_del(&msg->list); in gsm_data_kick()
1072 list_del(&msg->list); in gsm_data_kick()
1083 * __gsm_data_queue - queue a UI or UIH frame
1088 * out of the mux tty if not already doing so. The Caller must hold
1094 struct gsm_mux *gsm = dlci->gsm; in __gsm_data_queue()
1095 u8 *dp = msg->data; in __gsm_data_queue()
1096 u8 *fcs = dp + msg->len; in __gsm_data_queue()
1099 if (gsm->encoding == GSM_BASIC_OPT) { in __gsm_data_queue()
1100 if (msg->len < 128) in __gsm_data_queue()
1101 *--dp = (msg->len << 1) | EA; in __gsm_data_queue()
1103 *--dp = (msg->len >> 7); /* bits 7 - 15 */ in __gsm_data_queue()
1104 *--dp = (msg->len & 127) << 1; /* bits 0 - 6 */ in __gsm_data_queue()
1108 *--dp = msg->ctrl; in __gsm_data_queue()
1109 if (gsm->initiator) in __gsm_data_queue()
1110 *--dp = (msg->addr << 2) | CR | EA; in __gsm_data_queue()
1112 *--dp = (msg->addr << 2) | EA; in __gsm_data_queue()
1113 *fcs = gsm_fcs_add_block(INIT_FCS, dp , msg->data - dp); in __gsm_data_queue()
1115 if (msg->ctrl == UI || msg->ctrl == (UI|PF)) in __gsm_data_queue()
1116 *fcs = gsm_fcs_add_block(*fcs, msg->data, msg->len); in __gsm_data_queue()
1117 *fcs = 0xFF - *fcs; in __gsm_data_queue()
1119 gsm_print_packet("Q> ", msg->addr, gsm->initiator, msg->ctrl, in __gsm_data_queue()
1120 msg->data, msg->len); in __gsm_data_queue()
1124 msg->len += (msg->data - dp) + 1; in __gsm_data_queue()
1125 msg->data = dp; in __gsm_data_queue()
1128 switch (msg->ctrl & ~PF) { in __gsm_data_queue()
1131 if (msg->addr > 0) { in __gsm_data_queue()
1132 list_add_tail(&msg->list, &gsm->tx_data_list); in __gsm_data_queue()
1137 list_add_tail(&msg->list, &gsm->tx_ctrl_list); in __gsm_data_queue()
1140 gsm->tx_bytes += msg->len; in __gsm_data_queue()
1143 mod_timer(&gsm->kick_timer, jiffies + 10 * gsm->t1 * HZ / 100); in __gsm_data_queue()
1147 * gsm_data_queue - queue a UI or UIH frame
1152 * out of the mux tty if not already doing so. Take the
1159 spin_lock_irqsave(&dlci->gsm->tx_lock, flags); in gsm_data_queue()
1161 spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags); in gsm_data_queue()
1165 * gsm_dlci_data_output - try and push data out of a DLCI
1166 * @gsm: mux
1170 * is data. Keep to the MRU of the mux. This path handles the usual tty
1173 * Caller must hold the tx_lock of the mux.
1183 h = ((dlci->adaption == 1) ? 0 : 1); in gsm_dlci_data_output()
1185 len = kfifo_len(&dlci->fifo); in gsm_dlci_data_output()
1190 if ((len + h) > dlci->mtu) in gsm_dlci_data_output()
1191 len = dlci->mtu - h; in gsm_dlci_data_output()
1195 msg = gsm_data_alloc(gsm, dlci->addr, size, dlci->ftype); in gsm_dlci_data_output()
1197 return -ENOMEM; in gsm_dlci_data_output()
1198 dp = msg->data; in gsm_dlci_data_output()
1199 switch (dlci->adaption) { in gsm_dlci_data_output()
1209 dlci->adaption); in gsm_dlci_data_output()
1213 WARN_ON(len != kfifo_out_locked(&dlci->fifo, dp, len, in gsm_dlci_data_output()
1214 &dlci->lock)); in gsm_dlci_data_output()
1217 tty_port_tty_wakeup(&dlci->port); in gsm_dlci_data_output()
1225 * gsm_dlci_data_output_framed - try and push data out of a DLCI
1226 * @gsm: mux
1230 * is data. Keep to the MRU of the mux. This path handles framed data
1233 * Caller must hold the tx_lock of the mux.
1246 if (dlci->adaption == 4) in gsm_dlci_data_output_framed()
1249 /* dlci->skb is locked by tx_lock */ in gsm_dlci_data_output_framed()
1250 if (dlci->skb == NULL) { in gsm_dlci_data_output_framed()
1251 dlci->skb = skb_dequeue_tail(&dlci->skb_list); in gsm_dlci_data_output_framed()
1252 if (dlci->skb == NULL) in gsm_dlci_data_output_framed()
1256 len = dlci->skb->len + overhead; in gsm_dlci_data_output_framed()
1259 if (len > dlci->mtu) { in gsm_dlci_data_output_framed()
1260 if (dlci->adaption == 3) { in gsm_dlci_data_output_framed()
1262 dev_kfree_skb_any(dlci->skb); in gsm_dlci_data_output_framed()
1263 dlci->skb = NULL; in gsm_dlci_data_output_framed()
1266 len = dlci->mtu; in gsm_dlci_data_output_framed()
1271 msg = gsm_data_alloc(gsm, dlci->addr, size, dlci->ftype); in gsm_dlci_data_output_framed()
1273 skb_queue_tail(&dlci->skb_list, dlci->skb); in gsm_dlci_data_output_framed()
1274 dlci->skb = NULL; in gsm_dlci_data_output_framed()
1275 return -ENOMEM; in gsm_dlci_data_output_framed()
1277 dp = msg->data; in gsm_dlci_data_output_framed()
1279 if (dlci->adaption == 4) { /* Interruptible framed (Packetised Data) */ in gsm_dlci_data_output_framed()
1282 len--; in gsm_dlci_data_output_framed()
1284 memcpy(dp, dlci->skb->data, len); in gsm_dlci_data_output_framed()
1285 skb_pull(dlci->skb, len); in gsm_dlci_data_output_framed()
1288 dev_kfree_skb_any(dlci->skb); in gsm_dlci_data_output_framed()
1289 dlci->skb = NULL; in gsm_dlci_data_output_framed()
1295 * gsm_dlci_modem_output - try and push modem status out of a DLCI
1296 * @gsm: mux
1303 * Caller must hold the tx_lock of the mux.
1314 switch (dlci->adaption) { in gsm_dlci_modem_output()
1324 dlci->adaption); in gsm_dlci_modem_output()
1325 return -EINVAL; in gsm_dlci_modem_output()
1328 msg = gsm_data_alloc(gsm, dlci->addr, size, dlci->ftype); in gsm_dlci_modem_output()
1331 return -ENOMEM; in gsm_dlci_modem_output()
1333 dp = msg->data; in gsm_dlci_modem_output()
1334 switch (dlci->adaption) { in gsm_dlci_modem_output()
1355 * gsm_dlci_data_sweep - look for data to send
1356 * @gsm: the GSM mux
1358 * Sweep the GSM mux channels in priority order looking for ones with
1374 while (gsm->tx_bytes < TX_THRESH_HI) { in gsm_dlci_data_sweep()
1376 dlci = gsm->dlci[i]; in gsm_dlci_data_sweep()
1378 if (!dlci || dlci->constipated) in gsm_dlci_data_sweep()
1381 if (dlci->state != DLCI_OPEN) in gsm_dlci_data_sweep()
1384 if (dlci->adaption < 3 && !dlci->net) in gsm_dlci_data_sweep()
1407 * gsm_dlci_data_kick - transmit if possible
1420 if (dlci->constipated) in gsm_dlci_data_kick()
1423 spin_lock_irqsave(&dlci->gsm->tx_lock, flags); in gsm_dlci_data_kick()
1425 sweep = (dlci->gsm->tx_bytes < TX_THRESH_LO); in gsm_dlci_data_kick()
1426 if (dlci->gsm->tx_bytes == 0) { in gsm_dlci_data_kick()
1427 if (dlci->net) in gsm_dlci_data_kick()
1428 gsm_dlci_data_output_framed(dlci->gsm, dlci); in gsm_dlci_data_kick()
1430 gsm_dlci_data_output(dlci->gsm, dlci); in gsm_dlci_data_kick()
1433 gsm_dlci_data_sweep(dlci->gsm); in gsm_dlci_data_kick()
1434 spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags); in gsm_dlci_data_kick()
1443 * gsm_control_command - send a command frame to a control
1455 struct gsm_dlci *dlci = gsm->dlci[0]; in gsm_control_command()
1457 msg = gsm_data_alloc(gsm, 0, dlen + 2, dlci->ftype); in gsm_control_command()
1459 return -ENOMEM; in gsm_control_command()
1461 msg->data[0] = (cmd << 1) | CR | EA; /* Set C/R */ in gsm_control_command()
1462 msg->data[1] = (dlen << 1) | EA; in gsm_control_command()
1463 memcpy(msg->data + 2, data, dlen); in gsm_control_command()
1470 * gsm_control_reply - send a response frame to a control
1483 struct gsm_dlci *dlci = gsm->dlci[0]; in gsm_control_reply()
1485 msg = gsm_data_alloc(gsm, 0, dlen + 2, dlci->ftype); in gsm_control_reply()
1488 msg->data[0] = (cmd & 0xFE) << 1 | EA; /* Clear C/R */ in gsm_control_reply()
1489 msg->data[1] = (dlen << 1) | EA; in gsm_control_reply()
1490 memcpy(msg->data + 2, data, dlen); in gsm_control_reply()
1495 * gsm_process_modem - process received modem status
1514 * section 5.4.6.3.7 of the 07.10 mux spec. in gsm_process_modem()
1526 if (fc && !dlci->constipated) { in gsm_process_modem()
1528 dlci->constipated = true; in gsm_process_modem()
1529 } else if (!fc && dlci->constipated) { in gsm_process_modem()
1530 dlci->constipated = false; in gsm_process_modem()
1544 /* Carrier drop -> hangup */ in gsm_process_modem()
1546 if ((mlines & TIOCM_CD) == 0 && (dlci->modem_rx & TIOCM_CD)) in gsm_process_modem()
1551 tty_insert_flip_char(&dlci->port, 0, TTY_BREAK); in gsm_process_modem()
1552 dlci->modem_rx = mlines; in gsm_process_modem()
1553 wake_up_interruptible(&dlci->gsm->event); in gsm_process_modem()
1557 * gsm_process_negotiation - process received parameters
1570 struct gsm_dlci *dlci = gsm->dlci[addr]; in gsm_process_negotiation()
1573 i = FIELD_GET(PN_I_CL_FIELD_FTYPE, params->i_cl_bits); in gsm_process_negotiation()
1574 adaption = FIELD_GET(PN_I_CL_FIELD_ADAPTION, params->i_cl_bits) + 1; in gsm_process_negotiation()
1575 prio = FIELD_GET(PN_P_FIELD_PRIO, params->p_bits); in gsm_process_negotiation()
1576 n1 = FIELD_GET(PN_N_FIELD_N1, get_unaligned_le16(¶ms->n_bits)); in gsm_process_negotiation()
1577 k = FIELD_GET(PN_K_FIELD_K, params->k_bits); in gsm_process_negotiation()
1582 return -EINVAL; in gsm_process_negotiation()
1596 gsm->unsupported++; in gsm_process_negotiation()
1597 return -EINVAL; in gsm_process_negotiation()
1601 return -EINVAL; in gsm_process_negotiation()
1604 if (!cr && gsm->initiator) { in gsm_process_negotiation()
1605 if (adaption != dlci->adaption) { in gsm_process_negotiation()
1609 return -EINVAL; in gsm_process_negotiation()
1611 if (prio != dlci->prio) { in gsm_process_negotiation()
1615 return -EINVAL; in gsm_process_negotiation()
1617 if (n1 > gsm->mru || n1 > dlci->mtu) { in gsm_process_negotiation()
1625 return -EINVAL; in gsm_process_negotiation()
1627 dlci->mtu = n1; in gsm_process_negotiation()
1628 if (ftype != dlci->ftype) { in gsm_process_negotiation()
1631 return -EINVAL; in gsm_process_negotiation()
1633 if (ftype != UI && ftype != UIH && k > dlci->k) { in gsm_process_negotiation()
1636 return -EINVAL; in gsm_process_negotiation()
1638 dlci->k = k; in gsm_process_negotiation()
1639 } else if (cr && !gsm->initiator) { in gsm_process_negotiation()
1645 return -EINVAL; in gsm_process_negotiation()
1647 dlci->adaption = adaption; in gsm_process_negotiation()
1648 if (n1 > gsm->mru) { in gsm_process_negotiation()
1650 dlci->mtu = gsm->mru; in gsm_process_negotiation()
1653 dlci->mtu = MAX_MTU; in gsm_process_negotiation()
1655 dlci->mtu = n1; in gsm_process_negotiation()
1657 dlci->prio = prio; in gsm_process_negotiation()
1658 dlci->ftype = ftype; in gsm_process_negotiation()
1659 dlci->k = k; in gsm_process_negotiation()
1661 return -EINVAL; in gsm_process_negotiation()
1668 * gsm_control_modem - modem status received
1674 * the GSM mux protocol to pass virtual modem line status and optionally
1695 if (addr == 0 || addr >= NUM_DLCI || gsm->dlci[addr] == NULL) in gsm_control_modem()
1697 dlci = gsm->dlci[addr]; in gsm_control_modem()
1700 if ((cl - len) < 1) in gsm_control_modem()
1704 cl -= len; in gsm_control_modem()
1711 tty = tty_port_tty_get(&dlci->port); in gsm_control_modem()
1721 * gsm_control_negotiation - parameter negotiation received
1728 * the GSM mux protocol to configure protocol parameters for a new DLCI.
1739 gsm->open_error++; in gsm_control_negotiation()
1745 addr = FIELD_GET(PN_D_FIELD_DLCI, params->d_bits); in gsm_control_negotiation()
1746 if (addr == 0 || addr >= NUM_DLCI || !gsm->dlci[addr]) { in gsm_control_negotiation()
1747 gsm->open_error++; in gsm_control_negotiation()
1750 dlci = gsm->dlci[addr]; in gsm_control_negotiation()
1753 if ((!cr && dlci->state == DLCI_OPENING) || dlci->state == DLCI_OPEN) { in gsm_control_negotiation()
1754 gsm->open_error++; in gsm_control_negotiation()
1763 gsm->open_error++; in gsm_control_negotiation()
1775 } else if (dlci->state == DLCI_CONFIGURE) { in gsm_control_negotiation()
1777 dlci->state = DLCI_OPENING; in gsm_control_negotiation()
1778 gsm_command(gsm, dlci->addr, SABM|PF); in gsm_control_negotiation()
1779 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_control_negotiation()
1783 gsm->open_error++; in gsm_control_negotiation()
1788 * gsm_control_rls - remote line status
1807 len--; in gsm_control_rls()
1812 len--; in gsm_control_rls()
1817 if (addr == 0 || addr >= NUM_DLCI || gsm->dlci[addr] == NULL) in gsm_control_rls()
1824 port = &gsm->dlci[addr]->port; in gsm_control_rls()
1841 * gsm_control_message - DLCI 0 control processing
1842 * @gsm: our GSM mux
1859 struct gsm_dlci *dlci = gsm->dlci[0]; in gsm_control_message()
1862 dlci->dead = true; in gsm_control_message()
1863 gsm->dead = true; in gsm_control_message()
1874 gsm->constipated = false; in gsm_control_message()
1881 gsm->constipated = true; in gsm_control_message()
1904 gsm->unsupported++; in gsm_control_message()
1915 * gsm_control_response - process a response to our control
1916 * @gsm: our GSM mux
1921 * Process a response to an outstanding command. We only allow a single
1930 struct gsm_control *ctrl; in gsm_control_response() local
1934 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_response()
1936 ctrl = gsm->pending_cmd; in gsm_control_response()
1937 dlci = gsm->dlci[0]; in gsm_control_response()
1940 if (ctrl != NULL && (command == ctrl->cmd || command == CMD_NSC)) { in gsm_control_response()
1942 del_timer(&gsm->t2_timer); in gsm_control_response()
1943 gsm->pending_cmd = NULL; in gsm_control_response()
1946 ctrl->error = -EOPNOTSUPP; in gsm_control_response()
1947 ctrl->done = 1; in gsm_control_response()
1948 wake_up(&gsm->event); in gsm_control_response()
1953 } else if (command == CMD_TEST && clen == 1 && *data == gsm->ka_num) { in gsm_control_response()
1954 gsm->ka_retries = -1; /* trigger new keep-alive message */ in gsm_control_response()
1955 if (dlci && !dlci->dead) in gsm_control_response()
1956 mod_timer(&gsm->ka_timer, jiffies + gsm->keep_alive * HZ / 100); in gsm_control_response()
1958 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_response()
1962 * gsm_control_keep_alive - check timeout or start keep-alive
1965 * Called off the keep-alive timer expiry signaling that our link
1975 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_keep_alive()
1976 if (gsm->ka_num && gsm->ka_retries == 0) { in gsm_control_keep_alive()
1977 /* Keep-alive expired -> close the link */ in gsm_control_keep_alive()
1979 pr_debug("%s keep-alive timed out\n", __func__); in gsm_control_keep_alive()
1980 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_keep_alive()
1981 if (gsm->dlci[0]) in gsm_control_keep_alive()
1982 gsm_dlci_begin_close(gsm->dlci[0]); in gsm_control_keep_alive()
1984 } else if (gsm->keep_alive && gsm->dlci[0] && !gsm->dlci[0]->dead) { in gsm_control_keep_alive()
1985 if (gsm->ka_retries > 0) { in gsm_control_keep_alive()
1986 /* T2 expired for keep-alive -> resend */ in gsm_control_keep_alive()
1987 gsm->ka_retries--; in gsm_control_keep_alive()
1989 /* Start keep-alive timer */ in gsm_control_keep_alive()
1990 gsm->ka_num++; in gsm_control_keep_alive()
1991 if (!gsm->ka_num) in gsm_control_keep_alive()
1992 gsm->ka_num++; in gsm_control_keep_alive()
1993 gsm->ka_retries = (signed int)gsm->n2; in gsm_control_keep_alive()
1995 gsm_control_command(gsm, CMD_TEST, &gsm->ka_num, in gsm_control_keep_alive()
1996 sizeof(gsm->ka_num)); in gsm_control_keep_alive()
1997 mod_timer(&gsm->ka_timer, in gsm_control_keep_alive()
1998 jiffies + gsm->t2 * HZ / 100); in gsm_control_keep_alive()
2000 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_keep_alive()
2004 * gsm_control_transmit - send control packet
2005 * @gsm: gsm mux
2006 * @ctrl: frame to send
2011 static void gsm_control_transmit(struct gsm_mux *gsm, struct gsm_control *ctrl) in gsm_control_transmit() argument
2013 gsm_control_command(gsm, ctrl->cmd, ctrl->data, ctrl->len); in gsm_control_transmit()
2017 * gsm_control_retransmit - retransmit a control frame
2024 * gsm->pending_cmd will be NULL and we just let the timer expire.
2030 struct gsm_control *ctrl; in gsm_control_retransmit() local
2032 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_retransmit()
2033 ctrl = gsm->pending_cmd; in gsm_control_retransmit()
2034 if (ctrl) { in gsm_control_retransmit()
2035 if (gsm->cretries == 0 || !gsm->dlci[0] || gsm->dlci[0]->dead) { in gsm_control_retransmit()
2036 gsm->pending_cmd = NULL; in gsm_control_retransmit()
2037 ctrl->error = -ETIMEDOUT; in gsm_control_retransmit()
2038 ctrl->done = 1; in gsm_control_retransmit()
2039 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_retransmit()
2040 wake_up(&gsm->event); in gsm_control_retransmit()
2043 gsm->cretries--; in gsm_control_retransmit()
2044 gsm_control_transmit(gsm, ctrl); in gsm_control_retransmit()
2045 mod_timer(&gsm->t2_timer, jiffies + gsm->t2 * HZ / 100); in gsm_control_retransmit()
2047 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_retransmit()
2051 * gsm_control_send - send a control frame on DLCI 0
2065 struct gsm_control *ctrl = kzalloc(sizeof(struct gsm_control), in gsm_control_send() local
2068 if (ctrl == NULL) in gsm_control_send()
2071 wait_event(gsm->event, gsm->pending_cmd == NULL); in gsm_control_send()
2072 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_send()
2073 if (gsm->pending_cmd != NULL) { in gsm_control_send()
2074 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_send()
2077 ctrl->cmd = command; in gsm_control_send()
2078 ctrl->data = data; in gsm_control_send()
2079 ctrl->len = clen; in gsm_control_send()
2080 gsm->pending_cmd = ctrl; in gsm_control_send()
2083 if (gsm->dlci[0]->mode == DLCI_MODE_ADM) in gsm_control_send()
2084 gsm->cretries = 0; in gsm_control_send()
2086 gsm->cretries = gsm->n2; in gsm_control_send()
2088 mod_timer(&gsm->t2_timer, jiffies + gsm->t2 * HZ / 100); in gsm_control_send()
2089 gsm_control_transmit(gsm, ctrl); in gsm_control_send()
2090 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_send()
2091 return ctrl; in gsm_control_send()
2095 * gsm_control_wait - wait for a control to finish
2096 * @gsm: GSM mux
2107 wait_event(gsm->event, control->done == 1); in gsm_control_wait()
2108 err = control->error; in gsm_control_wait()
2123 * gsm_dlci_close - a DLCI has closed
2132 del_timer(&dlci->t1); in gsm_dlci_close()
2134 pr_debug("DLCI %d goes closed.\n", dlci->addr); in gsm_dlci_close()
2135 dlci->state = DLCI_CLOSED; in gsm_dlci_close()
2137 dlci->constipated = true; in gsm_dlci_close()
2138 if (dlci->addr != 0) { in gsm_dlci_close()
2139 tty_port_tty_hangup(&dlci->port, false); in gsm_dlci_close()
2140 gsm_dlci_clear_queues(dlci->gsm, dlci); in gsm_dlci_close()
2142 tty_port_set_initialized(&dlci->port, false); in gsm_dlci_close()
2143 wake_up_interruptible(&dlci->port.open_wait); in gsm_dlci_close()
2145 del_timer(&dlci->gsm->ka_timer); in gsm_dlci_close()
2146 dlci->gsm->dead = true; in gsm_dlci_close()
2148 /* A DLCI 0 close is a MUX termination so we need to kick that in gsm_dlci_close()
2151 wake_up_all(&dlci->gsm->event); in gsm_dlci_close()
2155 * gsm_dlci_open - a DLCI has opened
2163 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_open()
2166 open -> open */ in gsm_dlci_open()
2167 del_timer(&dlci->t1); in gsm_dlci_open()
2169 dlci->state = DLCI_OPEN; in gsm_dlci_open()
2170 dlci->constipated = false; in gsm_dlci_open()
2172 pr_debug("DLCI %d goes open.\n", dlci->addr); in gsm_dlci_open()
2174 if (dlci->addr) { in gsm_dlci_open()
2177 /* Start keep-alive control */ in gsm_dlci_open()
2178 gsm->ka_num = 0; in gsm_dlci_open()
2179 gsm->ka_retries = -1; in gsm_dlci_open()
2180 mod_timer(&gsm->ka_timer, in gsm_dlci_open()
2181 jiffies + gsm->keep_alive * HZ / 100); in gsm_dlci_open()
2184 wake_up(&dlci->gsm->event); in gsm_dlci_open()
2188 * gsm_dlci_negotiate - start parameter negotiation
2196 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_negotiate()
2214 * gsm_dlci_t1 - T1 timer expiry
2231 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_t1()
2233 switch (dlci->state) { in gsm_dlci_t1()
2235 if (dlci->retries && gsm_dlci_negotiate(dlci) == 0) { in gsm_dlci_t1()
2236 dlci->retries--; in gsm_dlci_t1()
2237 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_t1()
2239 gsm->open_error++; in gsm_dlci_t1()
2244 if (dlci->retries) { in gsm_dlci_t1()
2245 dlci->retries--; in gsm_dlci_t1()
2246 gsm_command(dlci->gsm, dlci->addr, SABM|PF); in gsm_dlci_t1()
2247 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_t1()
2248 } else if (!dlci->addr && gsm->control == (DM | PF)) { in gsm_dlci_t1()
2251 dlci->addr); in gsm_dlci_t1()
2252 dlci->mode = DLCI_MODE_ADM; in gsm_dlci_t1()
2255 gsm->open_error++; in gsm_dlci_t1()
2261 if (dlci->retries) { in gsm_dlci_t1()
2262 dlci->retries--; in gsm_dlci_t1()
2263 gsm_command(dlci->gsm, dlci->addr, DISC|PF); in gsm_dlci_t1()
2264 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_t1()
2269 pr_debug("%s: unhandled state: %d\n", __func__, dlci->state); in gsm_dlci_t1()
2275 * gsm_dlci_begin_open - start channel open procedure
2287 struct gsm_mux *gsm = dlci ? dlci->gsm : NULL; in gsm_dlci_begin_open()
2293 if (dlci->addr != 0) { in gsm_dlci_begin_open()
2294 if (gsm->adaption != 1 || gsm->adaption != dlci->adaption) in gsm_dlci_begin_open()
2296 if (dlci->prio != (roundup(dlci->addr + 1, 8) - 1)) in gsm_dlci_begin_open()
2298 if (gsm->ftype != dlci->ftype) in gsm_dlci_begin_open()
2302 switch (dlci->state) { in gsm_dlci_begin_open()
2306 dlci->retries = gsm->n2; in gsm_dlci_begin_open()
2308 dlci->state = DLCI_OPENING; in gsm_dlci_begin_open()
2309 gsm_command(gsm, dlci->addr, SABM|PF); in gsm_dlci_begin_open()
2312 dlci->state = DLCI_CONFIGURE; in gsm_dlci_begin_open()
2318 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_begin_open()
2326 * gsm_dlci_set_opening - change state to opening
2334 switch (dlci->state) { in gsm_dlci_set_opening()
2338 dlci->state = DLCI_OPENING; in gsm_dlci_set_opening()
2346 * gsm_dlci_set_wait_config - wait for channel configuration
2353 switch (dlci->state) { in gsm_dlci_set_wait_config()
2356 dlci->state = DLCI_WAITING_CONFIG; in gsm_dlci_set_wait_config()
2364 * gsm_dlci_begin_close - start channel open procedure
2376 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_begin_close()
2377 if (dlci->state == DLCI_CLOSED || dlci->state == DLCI_CLOSING) in gsm_dlci_begin_close()
2379 dlci->retries = gsm->n2; in gsm_dlci_begin_close()
2380 dlci->state = DLCI_CLOSING; in gsm_dlci_begin_close()
2381 gsm_command(dlci->gsm, dlci->addr, DISC|PF); in gsm_dlci_begin_close()
2382 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_begin_close()
2383 wake_up_interruptible(&gsm->event); in gsm_dlci_begin_close()
2387 * gsm_dlci_data - data arrived
2400 struct tty_port *port = &dlci->port; in gsm_dlci_data()
2407 switch (dlci->adaption) { in gsm_dlci_data()
2425 clen -= len; in gsm_dlci_data()
2435 * gsm_dlci_command - data arrived on control channel
2455 len -= dlen; in gsm_dlci_command()
2460 len -= dlen; in gsm_dlci_command()
2465 dlci->gsm->malformed++; in gsm_dlci_command()
2470 gsm_control_message(dlci->gsm, command, data, clen); in gsm_dlci_command()
2472 gsm_control_response(dlci->gsm, command, data, clen); in gsm_dlci_command()
2476 * gsm_kick_timer - transmit if possible
2489 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_kick_timer()
2491 if (gsm->tx_bytes < TX_THRESH_LO) in gsm_kick_timer()
2493 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_kick_timer()
2500 * gsm_dlci_copy_config_values - copy DLCI configuration
2507 dc->channel = (u32)dlci->addr; in gsm_dlci_copy_config_values()
2508 dc->adaption = (u32)dlci->adaption; in gsm_dlci_copy_config_values()
2509 dc->mtu = (u32)dlci->mtu; in gsm_dlci_copy_config_values()
2510 dc->priority = (u32)dlci->prio; in gsm_dlci_copy_config_values()
2511 if (dlci->ftype == UIH) in gsm_dlci_copy_config_values()
2512 dc->i = 1; in gsm_dlci_copy_config_values()
2514 dc->i = 2; in gsm_dlci_copy_config_values()
2515 dc->k = (u32)dlci->k; in gsm_dlci_copy_config_values()
2519 * gsm_dlci_config - configure DLCI from configuration
2535 for (i = 0; i < ARRAY_SIZE(dc->reserved); i++) in gsm_dlci_config()
2536 if (dc->reserved[i]) in gsm_dlci_config()
2537 return -EINVAL; in gsm_dlci_config()
2540 return -EINVAL; in gsm_dlci_config()
2541 gsm = dlci->gsm; in gsm_dlci_config()
2543 /* Stuff we don't support yet - I frame transport */ in gsm_dlci_config()
2544 if (dc->adaption != 1 && dc->adaption != 2) in gsm_dlci_config()
2545 return -EOPNOTSUPP; in gsm_dlci_config()
2546 if (dc->mtu > MAX_MTU || dc->mtu < MIN_MTU || dc->mtu > gsm->mru) in gsm_dlci_config()
2547 return -EINVAL; in gsm_dlci_config()
2548 if (dc->priority >= 64) in gsm_dlci_config()
2549 return -EINVAL; in gsm_dlci_config()
2550 if (dc->i == 0 || dc->i > 2) /* UIH and UI only */ in gsm_dlci_config()
2551 return -EINVAL; in gsm_dlci_config()
2552 if (dc->k > 7) in gsm_dlci_config()
2553 return -EINVAL; in gsm_dlci_config()
2554 if (dc->flags & ~GSM_FL_RESTART) /* allow future extensions */ in gsm_dlci_config()
2555 return -EINVAL; in gsm_dlci_config()
2561 if (dc->adaption != dlci->adaption) in gsm_dlci_config()
2563 if (dc->mtu != dlci->mtu) in gsm_dlci_config()
2565 if (dc->i != dlci->ftype) in gsm_dlci_config()
2568 if (dc->priority != dlci->prio) in gsm_dlci_config()
2570 if (dc->flags & GSM_FL_RESTART) in gsm_dlci_config()
2573 if ((open && gsm->wait_config) || need_restart) in gsm_dlci_config()
2575 if (dlci->state == DLCI_WAITING_CONFIG) { in gsm_dlci_config()
2586 wait_event_interruptible(gsm->event, dlci->state == DLCI_CLOSED); in gsm_dlci_config()
2588 return -EINTR; in gsm_dlci_config()
2593 dlci->adaption = (int)dc->adaption; in gsm_dlci_config()
2595 if (dc->mtu) in gsm_dlci_config()
2596 dlci->mtu = (unsigned int)dc->mtu; in gsm_dlci_config()
2598 dlci->mtu = gsm->mtu; in gsm_dlci_config()
2600 if (dc->priority) in gsm_dlci_config()
2601 dlci->prio = (u8)dc->priority; in gsm_dlci_config()
2603 dlci->prio = roundup(dlci->addr + 1, 8) - 1; in gsm_dlci_config()
2605 if (dc->i == 1) in gsm_dlci_config()
2606 dlci->ftype = UIH; in gsm_dlci_config()
2607 else if (dc->i == 2) in gsm_dlci_config()
2608 dlci->ftype = UI; in gsm_dlci_config()
2610 if (dc->k) in gsm_dlci_config()
2611 dlci->k = (u8)dc->k; in gsm_dlci_config()
2613 dlci->k = gsm->k; in gsm_dlci_config()
2616 if (gsm->initiator) in gsm_dlci_config()
2630 * gsm_dlci_alloc - allocate a DLCI
2631 * @gsm: GSM mux
2634 * Allocate and install a new DLCI object into the GSM mux.
2644 spin_lock_init(&dlci->lock); in gsm_dlci_alloc()
2645 mutex_init(&dlci->mutex); in gsm_dlci_alloc()
2646 if (kfifo_alloc(&dlci->fifo, TX_SIZE, GFP_KERNEL) < 0) { in gsm_dlci_alloc()
2651 skb_queue_head_init(&dlci->skb_list); in gsm_dlci_alloc()
2652 timer_setup(&dlci->t1, gsm_dlci_t1, 0); in gsm_dlci_alloc()
2653 tty_port_init(&dlci->port); in gsm_dlci_alloc()
2654 dlci->port.ops = &gsm_port_ops; in gsm_dlci_alloc()
2655 dlci->gsm = gsm; in gsm_dlci_alloc()
2656 dlci->addr = addr; in gsm_dlci_alloc()
2657 dlci->adaption = gsm->adaption; in gsm_dlci_alloc()
2658 dlci->mtu = gsm->mtu; in gsm_dlci_alloc()
2660 dlci->prio = 0; in gsm_dlci_alloc()
2662 dlci->prio = roundup(addr + 1, 8) - 1; in gsm_dlci_alloc()
2663 dlci->ftype = gsm->ftype; in gsm_dlci_alloc()
2664 dlci->k = gsm->k; in gsm_dlci_alloc()
2665 dlci->state = DLCI_CLOSED; in gsm_dlci_alloc()
2667 dlci->data = gsm_dlci_data; in gsm_dlci_alloc()
2669 dlci->constipated = true; in gsm_dlci_alloc()
2671 dlci->data = gsm_dlci_command; in gsm_dlci_alloc()
2673 gsm->dlci[addr] = dlci; in gsm_dlci_alloc()
2678 * gsm_dlci_free - free DLCI
2689 timer_shutdown_sync(&dlci->t1); in gsm_dlci_free()
2690 dlci->gsm->dlci[dlci->addr] = NULL; in gsm_dlci_free()
2691 kfifo_free(&dlci->fifo); in gsm_dlci_free()
2692 while ((dlci->skb = skb_dequeue(&dlci->skb_list))) in gsm_dlci_free()
2693 dev_kfree_skb(dlci->skb); in gsm_dlci_free()
2699 tty_port_get(&dlci->port); in dlci_get()
2704 tty_port_put(&dlci->port); in dlci_put()
2710 * gsm_dlci_release - release DLCI
2714 * mux is closed or tty is closed - whichever is last.
2720 struct tty_struct *tty = tty_port_tty_get(&dlci->port); in gsm_dlci_release()
2722 mutex_lock(&dlci->mutex); in gsm_dlci_release()
2724 mutex_unlock(&dlci->mutex); in gsm_dlci_release()
2728 * queue release_one_tty() -> NULL pointer panic in in gsm_dlci_release()
2733 tty_port_tty_set(&dlci->port, NULL); in gsm_dlci_release()
2736 dlci->state = DLCI_CLOSED; in gsm_dlci_release()
2745 * gsm_queue - a GSM frame is ready to process
2746 * @gsm: pointer to our gsm mux
2760 if (gsm->fcs != GOOD_FCS) { in gsm_queue()
2761 gsm->bad_fcs++; in gsm_queue()
2763 pr_debug("BAD FCS %02x\n", gsm->fcs); in gsm_queue()
2766 address = gsm->address >> 1; in gsm_queue()
2770 cr = gsm->address & 1; /* C/R bit */ in gsm_queue()
2771 cr ^= gsm->initiator ? 0 : 1; /* Flip so 1 always means command */ in gsm_queue()
2773 gsm_print_packet("<--", address, cr, gsm->control, gsm->buf, gsm->len); in gsm_queue()
2775 dlci = gsm->dlci[address]; in gsm_queue()
2777 switch (gsm->control) { in gsm_queue()
2780 gsm->open_error++; in gsm_queue()
2786 gsm->open_error++; in gsm_queue()
2789 if (dlci->dead) in gsm_queue()
2799 if (dlci == NULL || dlci->state == DLCI_CLOSED) { in gsm_queue()
2810 switch (dlci->state) { in gsm_queue()
2819 dlci->state); in gsm_queue()
2835 if (dlci == NULL || dlci->state != DLCI_OPEN) { in gsm_queue()
2839 dlci->data(dlci, gsm->buf, gsm->len); in gsm_queue()
2846 gsm->malformed++; in gsm_queue()
2852 * gsm0_receive - perform processing for non-transparency
2863 switch (gsm->state) { in gsm0_receive()
2866 gsm->state = GSM_ADDRESS; in gsm0_receive()
2867 gsm->address = 0; in gsm0_receive()
2868 gsm->len = 0; in gsm0_receive()
2869 gsm->fcs = INIT_FCS; in gsm0_receive()
2873 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2874 if (gsm_read_ea(&gsm->address, c)) in gsm0_receive()
2875 gsm->state = GSM_CONTROL; in gsm0_receive()
2878 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2879 gsm->control = c; in gsm0_receive()
2880 gsm->state = GSM_LEN0; in gsm0_receive()
2883 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2884 if (gsm_read_ea(&gsm->len, c)) { in gsm0_receive()
2885 if (gsm->len > gsm->mru) { in gsm0_receive()
2886 gsm->bad_size++; in gsm0_receive()
2887 gsm->state = GSM_SEARCH; in gsm0_receive()
2890 gsm->count = 0; in gsm0_receive()
2891 if (!gsm->len) in gsm0_receive()
2892 gsm->state = GSM_FCS; in gsm0_receive()
2894 gsm->state = GSM_DATA; in gsm0_receive()
2897 gsm->state = GSM_LEN1; in gsm0_receive()
2900 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2902 gsm->len |= len << 7; in gsm0_receive()
2903 if (gsm->len > gsm->mru) { in gsm0_receive()
2904 gsm->bad_size++; in gsm0_receive()
2905 gsm->state = GSM_SEARCH; in gsm0_receive()
2908 gsm->count = 0; in gsm0_receive()
2909 if (!gsm->len) in gsm0_receive()
2910 gsm->state = GSM_FCS; in gsm0_receive()
2912 gsm->state = GSM_DATA; in gsm0_receive()
2915 gsm->buf[gsm->count++] = c; in gsm0_receive()
2916 if (gsm->count == gsm->len) { in gsm0_receive()
2918 if ((gsm->control & ~PF) != UIH) { in gsm0_receive()
2919 gsm->fcs = gsm_fcs_add_block(gsm->fcs, gsm->buf, in gsm0_receive()
2920 gsm->count); in gsm0_receive()
2922 gsm->state = GSM_FCS; in gsm0_receive()
2926 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2927 gsm->state = GSM_SSOF; in gsm0_receive()
2930 gsm->state = GSM_SEARCH; in gsm0_receive()
2934 gsm->bad_size++; in gsm0_receive()
2937 pr_debug("%s: unhandled state: %d\n", __func__, gsm->state); in gsm0_receive()
2943 * gsm1_receive - perform processing for non-transparency
2954 gsm->constipated = true; in gsm1_receive()
2957 gsm->constipated = false; in gsm1_receive()
2964 if (gsm->state == GSM_DATA) { in gsm1_receive()
2965 if (gsm->count < 1) { in gsm1_receive()
2967 gsm->malformed++; in gsm1_receive()
2968 gsm->state = GSM_START; in gsm1_receive()
2972 gsm->count--; in gsm1_receive()
2973 if ((gsm->control & ~PF) != UIH) { in gsm1_receive()
2977 gsm->fcs = gsm_fcs_add_block(gsm->fcs, gsm->buf, in gsm1_receive()
2978 gsm->count); in gsm1_receive()
2981 gsm->fcs = gsm_fcs_add(gsm->fcs, gsm->buf[gsm->count]); in gsm1_receive()
2982 gsm->len = gsm->count; in gsm1_receive()
2984 gsm->state = GSM_START; in gsm1_receive()
2988 if (gsm->state != GSM_START) { in gsm1_receive()
2989 if (gsm->state != GSM_SEARCH) in gsm1_receive()
2990 gsm->malformed++; in gsm1_receive()
2991 gsm->state = GSM_START; in gsm1_receive()
2999 gsm->escape = true; in gsm1_receive()
3004 if (gsm->state == GSM_SEARCH) in gsm1_receive()
3007 if (gsm->escape) { in gsm1_receive()
3009 gsm->escape = false; in gsm1_receive()
3011 switch (gsm->state) { in gsm1_receive()
3013 gsm->address = 0; in gsm1_receive()
3014 gsm->state = GSM_ADDRESS; in gsm1_receive()
3015 gsm->fcs = INIT_FCS; in gsm1_receive()
3018 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm1_receive()
3019 if (gsm_read_ea(&gsm->address, c)) in gsm1_receive()
3020 gsm->state = GSM_CONTROL; in gsm1_receive()
3023 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm1_receive()
3024 gsm->control = c; in gsm1_receive()
3025 gsm->count = 0; in gsm1_receive()
3026 gsm->state = GSM_DATA; in gsm1_receive()
3029 if (gsm->count > gsm->mru) { /* Allow one for the FCS */ in gsm1_receive()
3030 gsm->state = GSM_OVERRUN; in gsm1_receive()
3031 gsm->bad_size++; in gsm1_receive()
3033 gsm->buf[gsm->count++] = c; in gsm1_receive()
3035 case GSM_OVERRUN: /* Over-long - eg a dropped SOF */ in gsm1_receive()
3038 pr_debug("%s: unhandled state: %d\n", __func__, gsm->state); in gsm1_receive()
3044 * gsm_error - handle tty error
3055 gsm->state = GSM_SEARCH; in gsm_error()
3056 gsm->io_error++; in gsm_error()
3060 * gsm_cleanup_mux - generic GSM protocol cleanup
3061 * @gsm: our mux
3064 * Clean up the bits of the mux which are the same for all framing
3065 * protocols. Remove the mux from the mux table, stop all the timers
3075 gsm->dead = true; in gsm_cleanup_mux()
3076 mutex_lock(&gsm->mutex); in gsm_cleanup_mux()
3078 dlci = gsm->dlci[0]; in gsm_cleanup_mux()
3080 if (disc && dlci->state != DLCI_CLOSED) { in gsm_cleanup_mux()
3082 wait_event(gsm->event, dlci->state == DLCI_CLOSED); in gsm_cleanup_mux()
3084 dlci->dead = true; in gsm_cleanup_mux()
3088 del_timer_sync(&gsm->kick_timer); in gsm_cleanup_mux()
3089 del_timer_sync(&gsm->t2_timer); in gsm_cleanup_mux()
3090 del_timer_sync(&gsm->ka_timer); in gsm_cleanup_mux()
3093 flush_work(&gsm->tx_work); in gsm_cleanup_mux()
3096 if (gsm->has_devices) { in gsm_cleanup_mux()
3097 gsm_unregister_devices(gsm_tty_driver, gsm->num); in gsm_cleanup_mux()
3098 gsm->has_devices = false; in gsm_cleanup_mux()
3100 for (i = NUM_DLCI - 1; i >= 0; i--) in gsm_cleanup_mux()
3101 if (gsm->dlci[i]) in gsm_cleanup_mux()
3102 gsm_dlci_release(gsm->dlci[i]); in gsm_cleanup_mux()
3103 mutex_unlock(&gsm->mutex); in gsm_cleanup_mux()
3105 tty_ldisc_flush(gsm->tty); in gsm_cleanup_mux()
3106 list_for_each_entry_safe(txq, ntxq, &gsm->tx_ctrl_list, list) in gsm_cleanup_mux()
3108 INIT_LIST_HEAD(&gsm->tx_ctrl_list); in gsm_cleanup_mux()
3109 list_for_each_entry_safe(txq, ntxq, &gsm->tx_data_list, list) in gsm_cleanup_mux()
3111 INIT_LIST_HEAD(&gsm->tx_data_list); in gsm_cleanup_mux()
3115 * gsm_activate_mux - generic GSM setup
3116 * @gsm: our mux
3118 * Set up the bits of the mux which are the same for all framing
3119 * protocols. Add the mux to the mux table so it can be opened and
3130 return -ENOMEM; in gsm_activate_mux()
3132 if (gsm->encoding == GSM_BASIC_OPT) in gsm_activate_mux()
3133 gsm->receive = gsm0_receive; in gsm_activate_mux()
3135 gsm->receive = gsm1_receive; in gsm_activate_mux()
3137 ret = gsm_register_devices(gsm_tty_driver, gsm->num); in gsm_activate_mux()
3141 gsm->has_devices = true; in gsm_activate_mux()
3142 gsm->dead = false; /* Tty opens are now permissible */ in gsm_activate_mux()
3147 * gsm_free_mux - free up a mux
3148 * @gsm: mux to free
3150 * Dispose of allocated resources for a dead mux
3162 mutex_destroy(&gsm->mutex); in gsm_free_mux()
3163 kfree(gsm->txframe); in gsm_free_mux()
3164 kfree(gsm->buf); in gsm_free_mux()
3169 * gsm_free_muxr - free up a mux
3170 * @ref: kreference to the mux to free
3172 * Dispose of allocated resources for a dead mux
3185 kref_get(&gsm->ref); in mux_get()
3194 kref_put(&gsm->ref, gsm_free_muxr); in mux_put()
3200 return gsm->num * NUM_DLCI; in mux_num_to_base()
3209 * gsm_alloc_mux - allocate a mux
3211 * Creates a new mux ready for activation.
3220 gsm->buf = kmalloc(MAX_MRU + 1, GFP_KERNEL); in gsm_alloc_mux()
3221 if (gsm->buf == NULL) { in gsm_alloc_mux()
3225 gsm->txframe = kmalloc(2 * (MAX_MTU + PROT_OVERHEAD - 1), GFP_KERNEL); in gsm_alloc_mux()
3226 if (gsm->txframe == NULL) { in gsm_alloc_mux()
3227 kfree(gsm->buf); in gsm_alloc_mux()
3231 spin_lock_init(&gsm->lock); in gsm_alloc_mux()
3232 mutex_init(&gsm->mutex); in gsm_alloc_mux()
3233 kref_init(&gsm->ref); in gsm_alloc_mux()
3234 INIT_LIST_HEAD(&gsm->tx_ctrl_list); in gsm_alloc_mux()
3235 INIT_LIST_HEAD(&gsm->tx_data_list); in gsm_alloc_mux()
3236 timer_setup(&gsm->kick_timer, gsm_kick_timer, 0); in gsm_alloc_mux()
3237 timer_setup(&gsm->t2_timer, gsm_control_retransmit, 0); in gsm_alloc_mux()
3238 timer_setup(&gsm->ka_timer, gsm_control_keep_alive, 0); in gsm_alloc_mux()
3239 INIT_WORK(&gsm->tx_work, gsmld_write_task); in gsm_alloc_mux()
3240 init_waitqueue_head(&gsm->event); in gsm_alloc_mux()
3241 spin_lock_init(&gsm->control_lock); in gsm_alloc_mux()
3242 spin_lock_init(&gsm->tx_lock); in gsm_alloc_mux()
3244 gsm->t1 = T1; in gsm_alloc_mux()
3245 gsm->t2 = T2; in gsm_alloc_mux()
3246 gsm->t3 = T3; in gsm_alloc_mux()
3247 gsm->n2 = N2; in gsm_alloc_mux()
3248 gsm->k = K; in gsm_alloc_mux()
3249 gsm->ftype = UIH; in gsm_alloc_mux()
3250 gsm->adaption = 1; in gsm_alloc_mux()
3251 gsm->encoding = GSM_ADV_OPT; in gsm_alloc_mux()
3252 gsm->mru = 64; /* Default to encoding 1 so these should be 64 */ in gsm_alloc_mux()
3253 gsm->mtu = 64; in gsm_alloc_mux()
3254 gsm->dead = true; /* Avoid early tty opens */ in gsm_alloc_mux()
3255 gsm->wait_config = false; /* Disabled */ in gsm_alloc_mux()
3256 gsm->keep_alive = 0; /* Disabled */ in gsm_alloc_mux()
3258 /* Store the instance to the mux array or abort if no space is in gsm_alloc_mux()
3265 gsm->num = i; in gsm_alloc_mux()
3271 mutex_destroy(&gsm->mutex); in gsm_alloc_mux()
3272 kfree(gsm->txframe); in gsm_alloc_mux()
3273 kfree(gsm->buf); in gsm_alloc_mux()
3285 c->adaption = gsm->adaption; in gsm_copy_config_values()
3286 c->encapsulation = gsm->encoding; in gsm_copy_config_values()
3287 c->initiator = gsm->initiator; in gsm_copy_config_values()
3288 c->t1 = gsm->t1; in gsm_copy_config_values()
3289 c->t2 = gsm->t2; in gsm_copy_config_values()
3290 c->t3 = gsm->t3; in gsm_copy_config_values()
3291 c->n2 = gsm->n2; in gsm_copy_config_values()
3292 if (gsm->ftype == UIH) in gsm_copy_config_values()
3293 c->i = 1; in gsm_copy_config_values()
3295 c->i = 2; in gsm_copy_config_values()
3296 pr_debug("Ftype %d i %d\n", gsm->ftype, c->i); in gsm_copy_config_values()
3297 c->mru = gsm->mru; in gsm_copy_config_values()
3298 c->mtu = gsm->mtu; in gsm_copy_config_values()
3299 c->k = gsm->k; in gsm_copy_config_values()
3307 /* Stuff we don't support yet - UI or I frame transport */ in gsm_config()
3308 if (c->adaption != 1 && c->adaption != 2) in gsm_config()
3309 return -EOPNOTSUPP; in gsm_config()
3311 if (c->mru < MIN_MTU || c->mtu < MIN_MTU) in gsm_config()
3312 return -EINVAL; in gsm_config()
3313 if (c->mru > MAX_MRU || c->mtu > MAX_MTU) in gsm_config()
3314 return -EINVAL; in gsm_config()
3315 if (c->t3 > MAX_T3) in gsm_config()
3316 return -EINVAL; in gsm_config()
3317 if (c->n2 > 255) in gsm_config()
3318 return -EINVAL; in gsm_config()
3319 if (c->encapsulation > 1) /* Basic, advanced, no I */ in gsm_config()
3320 return -EINVAL; in gsm_config()
3321 if (c->initiator > 1) in gsm_config()
3322 return -EINVAL; in gsm_config()
3323 if (c->k > MAX_WINDOW_SIZE) in gsm_config()
3324 return -EINVAL; in gsm_config()
3325 if (c->i == 0 || c->i > 2) /* UIH and UI only */ in gsm_config()
3326 return -EINVAL; in gsm_config()
3332 if (c->t1 != 0 && c->t1 != gsm->t1) in gsm_config()
3334 if (c->t2 != 0 && c->t2 != gsm->t2) in gsm_config()
3336 if (c->encapsulation != gsm->encoding) in gsm_config()
3338 if (c->adaption != gsm->adaption) in gsm_config()
3341 if (c->initiator != gsm->initiator) in gsm_config()
3343 if (c->mru != gsm->mru) in gsm_config()
3345 if (c->mtu != gsm->mtu) in gsm_config()
3356 gsm->initiator = c->initiator; in gsm_config()
3357 gsm->mru = c->mru; in gsm_config()
3358 gsm->mtu = c->mtu; in gsm_config()
3359 gsm->encoding = c->encapsulation ? GSM_ADV_OPT : GSM_BASIC_OPT; in gsm_config()
3360 gsm->adaption = c->adaption; in gsm_config()
3361 gsm->n2 = c->n2; in gsm_config()
3363 if (c->i == 1) in gsm_config()
3364 gsm->ftype = UIH; in gsm_config()
3365 else if (c->i == 2) in gsm_config()
3366 gsm->ftype = UI; in gsm_config()
3368 if (c->t1) in gsm_config()
3369 gsm->t1 = c->t1; in gsm_config()
3370 if (c->t2) in gsm_config()
3371 gsm->t2 = c->t2; in gsm_config()
3372 if (c->t3) in gsm_config()
3373 gsm->t3 = c->t3; in gsm_config()
3374 if (c->k) in gsm_config()
3375 gsm->k = c->k; in gsm_config()
3379 * and removing from the mux array in gsm_config()
3381 if (gsm->dead) { in gsm_config()
3385 if (gsm->initiator) in gsm_config()
3386 gsm_dlci_begin_open(gsm->dlci[0]); in gsm_config()
3395 ce->wait_config = gsm->wait_config ? 1 : 0; in gsm_copy_config_ext_values()
3396 ce->keep_alive = gsm->keep_alive; in gsm_copy_config_ext_values()
3408 for (i = 0; i < ARRAY_SIZE(ce->reserved); i++) in gsm_config_ext()
3409 if (ce->reserved[i]) in gsm_config_ext()
3410 return -EINVAL; in gsm_config_ext()
3411 if (ce->flags & ~GSM_FL_RESTART) in gsm_config_ext()
3412 return -EINVAL; in gsm_config_ext()
3415 if (ce->flags & GSM_FL_RESTART) in gsm_config_ext()
3429 gsm->wait_config = ce->wait_config ? true : false; in gsm_config_ext()
3430 gsm->keep_alive = ce->keep_alive; in gsm_config_ext()
3432 if (gsm->dead) { in gsm_config_ext()
3436 if (gsm->initiator) in gsm_config_ext()
3437 gsm_dlci_begin_open(gsm->dlci[0]); in gsm_config_ext()
3444 * gsmld_output - write to link
3445 * @gsm: our mux
3449 * Write a block of data from the GSM mux to the data channel. This
3455 if (tty_write_room(gsm->tty) < len) { in gsmld_output()
3456 set_bit(TTY_DO_WRITE_WAKEUP, &gsm->tty->flags); in gsmld_output()
3457 return -ENOSPC; in gsmld_output()
3461 return gsm->tty->ops->write(gsm->tty, data, len); in gsmld_output()
3466 * gsmld_write_trigger - schedule ldisc write task
3467 * @gsm: our mux
3471 if (!gsm || !gsm->dlci[0] || gsm->dlci[0]->dead) in gsmld_write_trigger()
3473 schedule_work(&gsm->tx_work); in gsmld_write_trigger()
3478 * gsmld_write_task - ldisc write task
3482 * avoid dead-locking. This returns if no space or data is left for output.
3493 ret = -ENODEV; in gsmld_write_task()
3494 spin_lock_irqsave(&gsm->tx_lock, flags); in gsmld_write_task()
3495 if (gsm->tty) in gsmld_write_task()
3497 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsmld_write_task()
3501 if (gsm->dlci[i]) in gsmld_write_task()
3502 tty_port_tty_wakeup(&gsm->dlci[i]->port); in gsmld_write_task()
3506 * gsmld_attach_gsm - mode set up
3508 * @gsm: our mux
3510 * Set up the MUX for basic mode and commence connecting to the
3517 gsm->tty = tty_kref_get(tty); in gsmld_attach_gsm()
3519 gsm->old_c_iflag = tty->termios.c_iflag; in gsmld_attach_gsm()
3520 tty->termios.c_iflag &= (IXON | IXOFF); in gsmld_attach_gsm()
3524 * gsmld_detach_gsm - stop doing 0710 mux
3525 * @tty: tty attached to the mux
3526 * @gsm: mux
3533 WARN_ON(tty != gsm->tty); in gsmld_detach_gsm()
3535 gsm->tty->termios.c_iflag = gsm->old_c_iflag; in gsmld_detach_gsm()
3536 tty_kref_put(gsm->tty); in gsmld_detach_gsm()
3537 gsm->tty = NULL; in gsmld_detach_gsm()
3543 struct gsm_mux *gsm = tty->disc_data; in gsmld_receive_buf()
3549 for (; count; count--, cp++) { in gsmld_receive_buf()
3554 if (gsm->receive) in gsmld_receive_buf()
3555 gsm->receive(gsm, *cp); in gsmld_receive_buf()
3574 * gsmld_flush_buffer - clean input queue
3587 * gsmld_close - close the ldisc for this tty
3598 struct gsm_mux *gsm = tty->disc_data; in gsmld_close()
3614 * gsmld_open - open an ldisc
3628 return -EPERM; in gsmld_open()
3630 if (tty->ops->write == NULL) in gsmld_open()
3631 return -EINVAL; in gsmld_open()
3636 return -ENOMEM; in gsmld_open()
3638 tty->disc_data = gsm; in gsmld_open()
3639 tty->receive_room = 65536; in gsmld_open()
3644 /* The mux will not be activated yet, we wait for correct in gsmld_open()
3647 if (gsm->encoding == GSM_BASIC_OPT) in gsmld_open()
3648 gsm->receive = gsm0_receive; in gsmld_open()
3650 gsm->receive = gsm1_receive; in gsmld_open()
3656 * gsmld_write_wakeup - asynchronous I/O notifier
3666 struct gsm_mux *gsm = tty->disc_data; in gsmld_write_wakeup()
3673 * gsmld_read - read function for tty
3692 return -EOPNOTSUPP; in gsmld_read()
3696 * gsmld_write - write function for tty
3704 * as-is and must be properly framed and checksummed as appropriate
3712 struct gsm_mux *gsm = tty->disc_data; in gsmld_write()
3718 return -ENODEV; in gsmld_write()
3720 ret = -ENOBUFS; in gsmld_write()
3721 spin_lock_irqsave(&gsm->tx_lock, flags); in gsmld_write()
3724 ret = tty->ops->write(tty, buf, nr); in gsmld_write()
3726 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in gsmld_write()
3727 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsmld_write()
3733 * gsmld_poll - poll method for N_GSM0710
3743 * Called without the kernel lock held - fine
3750 struct gsm_mux *gsm = tty->disc_data; in gsmld_poll()
3752 poll_wait(file, &tty->read_wait, wait); in gsmld_poll()
3753 poll_wait(file, &tty->write_wait, wait); in gsmld_poll()
3755 if (gsm->dead) in gsmld_poll()
3759 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) in gsmld_poll()
3772 struct gsm_mux *gsm = tty->disc_data; in gsmld_ioctl()
3780 return -EFAULT; in gsmld_ioctl()
3784 return -EFAULT; in gsmld_ioctl()
3792 return -EFAULT; in gsmld_ioctl()
3796 return -EFAULT; in gsmld_ioctl()
3800 return -EFAULT; in gsmld_ioctl()
3802 return -EINVAL; in gsmld_ioctl()
3804 dlci = gsm->dlci[addr]; in gsmld_ioctl()
3808 return -ENOMEM; in gsmld_ioctl()
3812 return -EFAULT; in gsmld_ioctl()
3816 return -EFAULT; in gsmld_ioctl()
3818 return -EINVAL; in gsmld_ioctl()
3820 dlci = gsm->dlci[addr]; in gsmld_ioctl()
3824 return -ENOMEM; in gsmld_ioctl()
3852 if (!dlci->net) { in dlci_net_free()
3856 dlci->adaption = dlci->prev_adaption; in dlci_net_free()
3857 dlci->data = dlci->prev_data; in dlci_net_free()
3858 free_netdev(dlci->net); in dlci_net_free()
3859 dlci->net = NULL; in dlci_net_free()
3867 dlci = mux_net->dlci; in net_free()
3869 if (dlci->net) { in net_free()
3870 unregister_netdev(dlci->net); in net_free()
3877 kref_get(&mux_net->ref); in muxnet_get()
3882 kref_put(&mux_net->ref, net_free); in muxnet_put()
3889 struct gsm_dlci *dlci = mux_net->dlci; in gsm_mux_net_start_xmit()
3892 skb_queue_head(&dlci->skb_list, skb); in gsm_mux_net_start_xmit()
3893 net->stats.tx_packets++; in gsm_mux_net_start_xmit()
3894 net->stats.tx_bytes += skb->len; in gsm_mux_net_start_xmit()
3906 dev_dbg(&net->dev, "Tx timed out.\n"); in gsm_mux_net_tx_timeout()
3909 net->stats.tx_errors++; in gsm_mux_net_tx_timeout()
3914 struct net_device *net = dlci->net; in gsm_mux_rx_netchar()
3923 net->stats.rx_dropped++; in gsm_mux_rx_netchar()
3930 skb->dev = net; in gsm_mux_rx_netchar()
3931 skb->protocol = htons(ETH_P_IP); in gsm_mux_rx_netchar()
3937 net->stats.rx_packets++; in gsm_mux_rx_netchar()
3938 net->stats.rx_bytes += size; in gsm_mux_rx_netchar()
3952 net->netdev_ops = &gsm_netdev_ops; in gsm_mux_net_init()
3955 net->watchdog_timeo = GSM_NET_TX_TIMEOUT; in gsm_mux_net_init()
3956 net->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST; in gsm_mux_net_init()
3957 net->type = ARPHRD_NONE; in gsm_mux_net_init()
3958 net->tx_queue_len = 10; in gsm_mux_net_init()
3968 if (!dlci->net) in gsm_destroy_network()
3970 mux_net = netdev_priv(dlci->net); in gsm_destroy_network()
3984 return -EPERM; in gsm_create_network()
3987 if (dlci->adaption > 2) in gsm_create_network()
3988 return -EBUSY; in gsm_create_network()
3990 if (nc->protocol != htons(ETH_P_IP)) in gsm_create_network()
3991 return -EPROTONOSUPPORT; in gsm_create_network()
3993 if (nc->adaption != 3 && nc->adaption != 4) in gsm_create_network()
3994 return -EPROTONOSUPPORT; in gsm_create_network()
3999 if (nc->if_name[0] != '\0') in gsm_create_network()
4000 netname = nc->if_name; in gsm_create_network()
4005 return -ENOMEM; in gsm_create_network()
4007 net->mtu = dlci->mtu; in gsm_create_network()
4008 net->min_mtu = MIN_MTU; in gsm_create_network()
4009 net->max_mtu = dlci->mtu; in gsm_create_network()
4011 mux_net->dlci = dlci; in gsm_create_network()
4012 kref_init(&mux_net->ref); in gsm_create_network()
4013 strncpy(nc->if_name, net->name, IFNAMSIZ); /* return net name */ in gsm_create_network()
4016 dlci->prev_adaption = dlci->adaption; in gsm_create_network()
4017 dlci->prev_data = dlci->data; in gsm_create_network()
4018 dlci->adaption = nc->adaption; in gsm_create_network()
4019 dlci->data = gsm_mux_rx_netchar; in gsm_create_network()
4020 dlci->net = net; in gsm_create_network()
4029 return net->ifindex; /* return network index */ in gsm_create_network()
4053 * gsm_modem_upd_via_data - send modem bits via convergence layer
4063 struct gsm_mux *gsm = dlci->gsm; in gsm_modem_upd_via_data()
4066 if (dlci->state != DLCI_OPEN || dlci->adaption != 2) in gsm_modem_upd_via_data()
4069 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_modem_upd_via_data()
4071 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_modem_upd_via_data()
4075 * gsm_modem_upd_via_msc - send modem bits via control frame
4083 struct gsm_control *ctrl; in gsm_modem_upd_via_msc() local
4086 if (dlci->gsm->encoding != GSM_BASIC_OPT) in gsm_modem_upd_via_msc()
4089 modembits[0] = (dlci->addr << 2) | 2 | EA; /* DLCI, Valid, EA */ in gsm_modem_upd_via_msc()
4097 ctrl = gsm_control_send(dlci->gsm, CMD_MSC, modembits, len); in gsm_modem_upd_via_msc()
4098 if (ctrl == NULL) in gsm_modem_upd_via_msc()
4099 return -ENOMEM; in gsm_modem_upd_via_msc()
4100 return gsm_control_wait(dlci->gsm, ctrl); in gsm_modem_upd_via_msc()
4104 * gsm_modem_update - send modem status line state
4111 if (dlci->gsm->dead) in gsm_modem_update()
4112 return -EL2HLT; in gsm_modem_update()
4113 if (dlci->adaption == 2) { in gsm_modem_update()
4117 } else if (dlci->gsm->encoding == GSM_BASIC_OPT) { in gsm_modem_update()
4123 return -EPROTONOSUPPORT; in gsm_modem_update()
4127 * gsm_wait_modem_change - wait for modem status line change
4132 * - any given modem status line bit changed
4133 * - the wait event function got interrupted (e.g. by a signal)
4134 * - the underlying DLCI was closed
4135 * - the underlying ldisc device was removed
4139 struct gsm_mux *gsm = dlci->gsm; in gsm_wait_modem_change()
4140 u32 old = dlci->modem_rx; in gsm_wait_modem_change()
4143 ret = wait_event_interruptible(gsm->event, gsm->dead || in gsm_wait_modem_change()
4144 dlci->state != DLCI_OPEN || in gsm_wait_modem_change()
4145 (old ^ dlci->modem_rx) & mask); in gsm_wait_modem_change()
4146 if (gsm->dead) in gsm_wait_modem_change()
4147 return -ENODEV; in gsm_wait_modem_change()
4148 if (dlci->state != DLCI_OPEN) in gsm_wait_modem_change()
4149 return -EL2NSYNC; in gsm_wait_modem_change()
4156 struct gsm_mux *gsm = dlci->gsm; in gsm_carrier_raised()
4159 if (dlci->state != DLCI_OPEN) in gsm_carrier_raised()
4168 if (gsm->encoding == GSM_BASIC_OPT && in gsm_carrier_raised()
4169 gsm->dlci[0]->mode == DLCI_MODE_ADM && !dlci->modem_rx) in gsm_carrier_raised()
4172 return dlci->modem_rx & TIOCM_CD; in gsm_carrier_raised()
4178 unsigned int modem_tx = dlci->modem_tx; in gsm_dtr_rts()
4183 if (modem_tx != dlci->modem_tx) { in gsm_dtr_rts()
4184 dlci->modem_tx = modem_tx; in gsm_dtr_rts()
4199 unsigned int line = tty->index; in gsmtty_install()
4200 unsigned int mux = mux_line_to_num(line); in gsmtty_install() local
4206 if (mux >= MAX_MUX) in gsmtty_install()
4207 return -ENXIO; in gsmtty_install()
4209 if (gsm_mux[mux] == NULL) in gsmtty_install()
4210 return -EUNATCH; in gsmtty_install()
4212 return -ECHRNG; in gsmtty_install()
4213 gsm = gsm_mux[mux]; in gsmtty_install()
4214 if (gsm->dead) in gsmtty_install()
4215 return -EL2HLT; in gsmtty_install()
4220 mutex_lock(&gsm->mutex); in gsmtty_install()
4221 if (gsm->dlci[0] && gsm->dlci[0]->state != DLCI_OPEN) { in gsmtty_install()
4222 mutex_unlock(&gsm->mutex); in gsmtty_install()
4223 return -EL2NSYNC; in gsmtty_install()
4225 dlci = gsm->dlci[line]; in gsmtty_install()
4231 mutex_unlock(&gsm->mutex); in gsmtty_install()
4232 return -ENOMEM; in gsmtty_install()
4234 ret = tty_port_install(&dlci->port, driver, tty); in gsmtty_install()
4238 mutex_unlock(&gsm->mutex); in gsmtty_install()
4243 dlci_get(gsm->dlci[0]); in gsmtty_install()
4245 tty->driver_data = dlci; in gsmtty_install()
4246 mutex_unlock(&gsm->mutex); in gsmtty_install()
4253 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_open()
4254 struct tty_port *port = &dlci->port; in gsmtty_open()
4256 port->count++; in gsmtty_open()
4259 dlci->modem_rx = 0; in gsmtty_open()
4260 /* We could in theory open and close before we wait - eg if we get in gsmtty_open()
4264 if (!dlci->gsm->wait_config) { in gsmtty_open()
4266 if (dlci->gsm->initiator) in gsmtty_open()
4279 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_close()
4283 if (dlci->state == DLCI_CLOSED) in gsmtty_close()
4285 mutex_lock(&dlci->mutex); in gsmtty_close()
4287 mutex_unlock(&dlci->mutex); in gsmtty_close()
4288 if (tty_port_close_start(&dlci->port, tty, filp) == 0) in gsmtty_close()
4291 if (tty_port_initialized(&dlci->port) && C_HUPCL(tty)) in gsmtty_close()
4292 tty_port_lower_dtr_rts(&dlci->port); in gsmtty_close()
4293 tty_port_close_end(&dlci->port, tty); in gsmtty_close()
4294 tty_port_tty_set(&dlci->port, NULL); in gsmtty_close()
4300 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_hangup()
4301 if (dlci->state == DLCI_CLOSED) in gsmtty_hangup()
4303 tty_port_hangup(&dlci->port); in gsmtty_hangup()
4310 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_write()
4311 if (dlci->state == DLCI_CLOSED) in gsmtty_write()
4312 return -EINVAL; in gsmtty_write()
4314 sent = kfifo_in_locked(&dlci->fifo, buf, len, &dlci->lock); in gsmtty_write()
4322 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_write_room()
4323 if (dlci->state == DLCI_CLOSED) in gsmtty_write_room()
4325 return kfifo_avail(&dlci->fifo); in gsmtty_write_room()
4330 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_chars_in_buffer()
4331 if (dlci->state == DLCI_CLOSED) in gsmtty_chars_in_buffer()
4333 return kfifo_len(&dlci->fifo); in gsmtty_chars_in_buffer()
4338 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_flush_buffer()
4341 if (dlci->state == DLCI_CLOSED) in gsmtty_flush_buffer()
4347 spin_lock_irqsave(&dlci->lock, flags); in gsmtty_flush_buffer()
4348 kfifo_reset(&dlci->fifo); in gsmtty_flush_buffer()
4349 spin_unlock_irqrestore(&dlci->lock, flags); in gsmtty_flush_buffer()
4362 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_tiocmget()
4363 if (dlci->state == DLCI_CLOSED) in gsmtty_tiocmget()
4364 return -EINVAL; in gsmtty_tiocmget()
4365 return dlci->modem_rx; in gsmtty_tiocmget()
4371 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_tiocmset()
4372 unsigned int modem_tx = dlci->modem_tx; in gsmtty_tiocmset()
4374 if (dlci->state == DLCI_CLOSED) in gsmtty_tiocmset()
4375 return -EINVAL; in gsmtty_tiocmset()
4379 if (modem_tx != dlci->modem_tx) { in gsmtty_tiocmset()
4380 dlci->modem_tx = modem_tx; in gsmtty_tiocmset()
4390 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_ioctl()
4395 if (dlci->state == DLCI_CLOSED) in gsmtty_ioctl()
4396 return -EINVAL; in gsmtty_ioctl()
4400 return -EFAULT; in gsmtty_ioctl()
4401 nc.if_name[IFNAMSIZ-1] = '\0'; in gsmtty_ioctl()
4403 mutex_lock(&dlci->mutex); in gsmtty_ioctl()
4405 mutex_unlock(&dlci->mutex); in gsmtty_ioctl()
4407 return -EFAULT; in gsmtty_ioctl()
4411 return -EPERM; in gsmtty_ioctl()
4412 mutex_lock(&dlci->mutex); in gsmtty_ioctl()
4414 mutex_unlock(&dlci->mutex); in gsmtty_ioctl()
4418 return -EFAULT; in gsmtty_ioctl()
4419 if (dc.channel != dlci->addr) in gsmtty_ioctl()
4420 return -EPERM; in gsmtty_ioctl()
4423 return -EFAULT; in gsmtty_ioctl()
4427 return -EFAULT; in gsmtty_ioctl()
4429 return -EINVAL; in gsmtty_ioctl()
4430 if (dc.channel != 0 && dc.channel != dlci->addr) in gsmtty_ioctl()
4431 return -EPERM; in gsmtty_ioctl()
4436 return -ENOIOCTLCMD; in gsmtty_ioctl()
4443 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_set_termios()
4444 if (dlci->state == DLCI_CLOSED) in gsmtty_set_termios()
4451 tty_termios_copy_hw(&tty->termios, old); in gsmtty_set_termios()
4456 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_throttle()
4457 if (dlci->state == DLCI_CLOSED) in gsmtty_throttle()
4460 dlci->modem_tx &= ~TIOCM_RTS; in gsmtty_throttle()
4461 dlci->throttled = true; in gsmtty_throttle()
4468 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_unthrottle()
4469 if (dlci->state == DLCI_CLOSED) in gsmtty_unthrottle()
4472 dlci->modem_tx |= TIOCM_RTS; in gsmtty_unthrottle()
4473 dlci->throttled = false; in gsmtty_unthrottle()
4480 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_break_ctl()
4482 if (dlci->state == DLCI_CLOSED) in gsmtty_break_ctl()
4483 return -EINVAL; in gsmtty_break_ctl()
4485 if (state == -1) /* "On indefinitely" - we can't encode this in gsmtty_break_ctl()
4498 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_cleanup()
4499 struct gsm_mux *gsm = dlci->gsm; in gsmtty_cleanup()
4502 dlci_put(gsm->dlci[0]); in gsmtty_cleanup()
4546 gsm_tty_driver->driver_name = "gsmtty"; in gsm_init()
4547 gsm_tty_driver->name = "gsmtty"; in gsm_init()
4548 gsm_tty_driver->major = 0; /* Dynamic */ in gsm_init()
4549 gsm_tty_driver->minor_start = 0; in gsm_init()
4550 gsm_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; in gsm_init()
4551 gsm_tty_driver->subtype = SERIAL_TYPE_NORMAL; in gsm_init()
4552 gsm_tty_driver->init_termios = tty_std_termios; in gsm_init()
4554 gsm_tty_driver->init_termios.c_lflag &= ~ECHO; in gsm_init()
4559 status = -EBUSY; in gsm_init()
4563 gsm_tty_driver->major, gsm_tty_driver->minor_start); in gsm_init()