Lines Matching +full:single +full:- +full:mux +full:- +full:ctrl
1 // SPDX-License-Identifier: GPL-2.0
9 * tty -> DLCI fifo -> scheduler -> GSM MUX data queue ---o-> ldisc
10 * control message -> GSM MUX control queue --´
13 * ldisc -> gsm_queue() -o--> tty
14 * `-> gsm_control_response()
24 * Review the locking/move to refcounts more (mux now moved to an
29 * Do we need a 'which mux are you' ioctl to correlate mux and tty sets
95 * Semi-arbitrary buffer size limits. 0710 is normally run with 32-64 byte
101 /* SOF, ADDR, CTRL, LEN1, LEN2, ..., FCS, EOF */
106 * struct gsm_mux_net - network interface
124 u8 ctrl; /* Control byte + flags */ member
147 * complexity right now these are only ever freed up when the mux is
150 * At the moment we don't free DLCI objects until the mux is torn down
174 bool dead; /* Refuse re-open */
260 * Each GSM mux we have is represented by this structure. If we are
263 * to the gsm mux array. For now we don't free DLCI objects that
264 * have been instantiated until the mux itself is terminated.
266 * To consider further: tty open versus mux shutdown.
303 bool dead; /* Has the mux been shut down */
323 /* Keep-alive */
324 struct timer_list ka_timer; /* Keep-alive response timer */
325 u8 ka_num; /* Keep-alive match pattern */
326 signed int ka_retries; /* Keep-alive retry counter, -1 if not yet initialized */
332 unsigned int t3; /* Power wake-up timer in seconds. */
336 u32 keep_alive; /* Control channel keep-alive in 10ms */
349 * Mux objects - needed so that we can translate a tty index into the
350 * relevant mux and DLCI.
456 u8 ctrl);
463 * gsm_fcs_add - update FCS
477 * gsm_fcs_add_block - update FCS for a block
488 while (len--) in gsm_fcs_add_block()
494 * gsm_read_ea - read a byte into an EA
512 * gsm_read_ea_val - read a value until EA
524 for (; dlen > 0; dlen--) { in gsm_read_ea_val()
533 * gsm_encode_modem - encode modem data bits
544 if (dlci->throttled) in gsm_encode_modem()
546 if (dlci->modem_tx & TIOCM_DTR) in gsm_encode_modem()
548 if (dlci->modem_tx & TIOCM_RTS) in gsm_encode_modem()
550 if (dlci->modem_tx & TIOCM_RI) in gsm_encode_modem()
552 if (dlci->modem_tx & TIOCM_CD || dlci->gsm->initiator) in gsm_encode_modem()
555 if (dlci->modem_tx & TIOCM_OUT1) in gsm_encode_modem()
557 if (dlci->modem_tx & TIOCM_OUT2) in gsm_encode_modem()
582 * gsm_encode_params - encode DLCI parameters
592 const struct gsm_mux *gsm = dlci->gsm; in gsm_encode_params()
595 switch (dlci->ftype) { in gsm_encode_params()
603 pr_debug("unsupported frame type %d\n", dlci->ftype); in gsm_encode_params()
604 return -EINVAL; in gsm_encode_params()
607 switch (dlci->adaption) { in gsm_encode_params()
615 pr_debug("unsupported adaption %d\n", dlci->adaption); in gsm_encode_params()
616 return -EINVAL; in gsm_encode_params()
619 params->d_bits = FIELD_PREP(PN_D_FIELD_DLCI, dlci->addr); in gsm_encode_params()
621 params->i_cl_bits = FIELD_PREP(PN_I_CL_FIELD_FTYPE, i) | in gsm_encode_params()
623 params->p_bits = FIELD_PREP(PN_P_FIELD_PRIO, dlci->prio); in gsm_encode_params()
624 params->t_bits = FIELD_PREP(PN_T_FIELD_T1, gsm->t1); in gsm_encode_params()
625 params->n_bits = cpu_to_le16(FIELD_PREP(PN_N_FIELD_N1, dlci->mtu)); in gsm_encode_params()
626 params->na_bits = FIELD_PREP(PN_NA_FIELD_N2, gsm->n2); in gsm_encode_params()
627 params->k_bits = FIELD_PREP(PN_K_FIELD_K, dlci->k); in gsm_encode_params()
633 * gsm_register_devices - register all tty devices for a given mux index
636 * @index: the mux number is used to calculate the minor numbers of the
637 * ttys for this mux and may differ from the position in the
638 * mux array.
647 return -EINVAL; in gsm_register_devices()
651 /* Don't register device 0 - this is the control channel in gsm_register_devices()
659 for (i--; i >= 1; i--) in gsm_register_devices()
669 * gsm_unregister_devices - unregister all tty devices for a given mux index
672 * @index: the mux number is used to calculate the minor numbers of the
673 * ttys for this mux and may differ from the position in the
674 * mux array.
687 /* Don't unregister device 0 - this is the control in gsm_unregister_devices()
695 * gsm_print_packet - display a frame for debug
704 * style is based on amateur radio LAP-B dump display.
771 * gsm_stuff_frame - bytestuff a packet
784 while (len--) { in gsm_stuff_frame()
799 * gsm_send - send a control frame
800 * @gsm: our GSM mux
817 return -ENOMEM; in gsm_send()
820 ocr = cr ^ (gsm->initiator ? 0 : 1); in gsm_send()
822 msg->data -= 3; in gsm_send()
823 dp = msg->data; in gsm_send()
827 if (gsm->encoding == GSM_BASIC_OPT) in gsm_send()
830 *dp = 0xFF - gsm_fcs_add_block(INIT_FCS, msg->data, dp - msg->data); in gsm_send()
831 msg->len = (dp - msg->data) + 1; in gsm_send()
833 gsm_print_packet("Q->", addr, cr, control, NULL, 0); in gsm_send()
835 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_send()
836 list_add_tail(&msg->list, &gsm->tx_ctrl_list); in gsm_send()
837 gsm->tx_bytes += msg->len; in gsm_send()
838 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_send()
845 * gsm_dlci_clear_queues - remove outstanding data for a DLCI
846 * @gsm: mux
854 int addr = dlci->addr; in gsm_dlci_clear_queues()
858 spin_lock_irqsave(&dlci->lock, flags); in gsm_dlci_clear_queues()
859 kfifo_reset(&dlci->fifo); in gsm_dlci_clear_queues()
860 spin_unlock_irqrestore(&dlci->lock, flags); in gsm_dlci_clear_queues()
862 /* Clear data packets in MUX write queue */ in gsm_dlci_clear_queues()
863 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_dlci_clear_queues()
864 list_for_each_entry_safe(msg, nmsg, &gsm->tx_data_list, list) { in gsm_dlci_clear_queues()
865 if (msg->addr != addr) in gsm_dlci_clear_queues()
867 gsm->tx_bytes -= msg->len; in gsm_dlci_clear_queues()
868 list_del(&msg->list); in gsm_dlci_clear_queues()
871 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_dlci_clear_queues()
875 * gsm_response - send a control response
876 * @gsm: our GSM mux
889 * gsm_command - send a control command
890 * @gsm: our GSM mux
904 #define HDR_LEN 6 /* ADDR CTRL [LEN.2] DATA FCS */
907 * gsm_data_alloc - allocate data frame
908 * @gsm: GSM mux
911 * @ctrl: control byte
919 u8 ctrl) in gsm_data_alloc() argument
925 m->data = m->buffer + HDR_LEN - 1; /* Allow for FCS */ in gsm_data_alloc()
926 m->len = len; in gsm_data_alloc()
927 m->addr = addr; in gsm_data_alloc()
928 m->ctrl = ctrl; in gsm_data_alloc()
929 INIT_LIST_HEAD(&m->list); in gsm_data_alloc()
934 * gsm_send_packet - sends a single packet
935 * @gsm: GSM Mux
946 if (gsm->encoding == GSM_BASIC_OPT) { in gsm_send_packet()
947 gsm->txframe[0] = GSM0_SOF; in gsm_send_packet()
948 memcpy(gsm->txframe + 1, msg->data, msg->len); in gsm_send_packet()
949 gsm->txframe[msg->len + 1] = GSM0_SOF; in gsm_send_packet()
950 len = msg->len + 2; in gsm_send_packet()
952 gsm->txframe[0] = GSM1_SOF; in gsm_send_packet()
953 len = gsm_stuff_frame(msg->data, gsm->txframe + 1, msg->len); in gsm_send_packet()
954 gsm->txframe[len + 1] = GSM1_SOF; in gsm_send_packet()
959 gsm_hex_dump_bytes(__func__, gsm->txframe, len); in gsm_send_packet()
960 gsm_print_packet("-->", msg->addr, gsm->initiator, msg->ctrl, msg->data, in gsm_send_packet()
961 msg->len); in gsm_send_packet()
963 ret = gsmld_output(gsm, gsm->txframe, len); in gsm_send_packet()
967 gsm->tx_bytes -= msg->len; in gsm_send_packet()
973 * gsm_is_flow_ctrl_msg - checks if flow control message
983 if (msg->addr > 0) in gsm_is_flow_ctrl_msg()
986 switch (msg->ctrl & ~PF) { in gsm_is_flow_ctrl_msg()
990 if (gsm_read_ea_val(&cmd, msg->data + 2, msg->len - 2) < 1) in gsm_is_flow_ctrl_msg()
1004 * gsm_data_kick - poke the queue
1005 * @gsm: GSM Mux
1009 * If we have been flow-stopped by a CMD_FCOFF, then we can only
1019 clear_bit(TTY_DO_WRITE_WAKEUP, &gsm->tty->flags); in gsm_data_kick()
1022 list_for_each_entry_safe(msg, nmsg, &gsm->tx_ctrl_list, list) { in gsm_data_kick()
1023 if (gsm->constipated && !gsm_is_flow_ctrl_msg(msg)) in gsm_data_kick()
1027 case -ENOSPC: in gsm_data_kick()
1028 return -ENOSPC; in gsm_data_kick()
1029 case -ENODEV: in gsm_data_kick()
1031 gsm->tx_bytes -= msg->len; in gsm_data_kick()
1032 list_del(&msg->list); in gsm_data_kick()
1037 list_del(&msg->list); in gsm_data_kick()
1044 if (gsm->constipated) in gsm_data_kick()
1045 return -EAGAIN; in gsm_data_kick()
1048 if (list_empty(&gsm->tx_data_list)) in gsm_data_kick()
1050 list_for_each_entry_safe(msg, nmsg, &gsm->tx_data_list, list) { in gsm_data_kick()
1051 dlci = gsm->dlci[msg->addr]; in gsm_data_kick()
1053 if (dlci->state != DLCI_OPEN) { in gsm_data_kick()
1054 gsm->tx_bytes -= msg->len; in gsm_data_kick()
1055 list_del(&msg->list); in gsm_data_kick()
1061 case -ENOSPC: in gsm_data_kick()
1062 return -ENOSPC; in gsm_data_kick()
1063 case -ENODEV: in gsm_data_kick()
1065 gsm->tx_bytes -= msg->len; in gsm_data_kick()
1066 list_del(&msg->list); in gsm_data_kick()
1071 list_del(&msg->list); in gsm_data_kick()
1082 * __gsm_data_queue - queue a UI or UIH frame
1087 * out of the mux tty if not already doing so. The Caller must hold
1093 struct gsm_mux *gsm = dlci->gsm; in __gsm_data_queue()
1094 u8 *dp = msg->data; in __gsm_data_queue()
1095 u8 *fcs = dp + msg->len; in __gsm_data_queue()
1098 if (gsm->encoding == GSM_BASIC_OPT) { in __gsm_data_queue()
1099 if (msg->len < 128) in __gsm_data_queue()
1100 *--dp = (msg->len << 1) | EA; in __gsm_data_queue()
1102 *--dp = (msg->len >> 7); /* bits 7 - 15 */ in __gsm_data_queue()
1103 *--dp = (msg->len & 127) << 1; /* bits 0 - 6 */ in __gsm_data_queue()
1107 *--dp = msg->ctrl; in __gsm_data_queue()
1108 if (gsm->initiator) in __gsm_data_queue()
1109 *--dp = (msg->addr << 2) | CR | EA; in __gsm_data_queue()
1111 *--dp = (msg->addr << 2) | EA; in __gsm_data_queue()
1112 *fcs = gsm_fcs_add_block(INIT_FCS, dp , msg->data - dp); in __gsm_data_queue()
1114 if (msg->ctrl == UI || msg->ctrl == (UI|PF)) in __gsm_data_queue()
1115 *fcs = gsm_fcs_add_block(*fcs, msg->data, msg->len); in __gsm_data_queue()
1116 *fcs = 0xFF - *fcs; in __gsm_data_queue()
1118 gsm_print_packet("Q> ", msg->addr, gsm->initiator, msg->ctrl, in __gsm_data_queue()
1119 msg->data, msg->len); in __gsm_data_queue()
1123 msg->len += (msg->data - dp) + 1; in __gsm_data_queue()
1124 msg->data = dp; in __gsm_data_queue()
1127 switch (msg->ctrl & ~PF) { in __gsm_data_queue()
1130 if (msg->addr > 0) { in __gsm_data_queue()
1131 list_add_tail(&msg->list, &gsm->tx_data_list); in __gsm_data_queue()
1136 list_add_tail(&msg->list, &gsm->tx_ctrl_list); in __gsm_data_queue()
1139 gsm->tx_bytes += msg->len; in __gsm_data_queue()
1142 mod_timer(&gsm->kick_timer, jiffies + 10 * gsm->t1 * HZ / 100); in __gsm_data_queue()
1146 * gsm_data_queue - queue a UI or UIH frame
1151 * out of the mux tty if not already doing so. Take the
1158 spin_lock_irqsave(&dlci->gsm->tx_lock, flags); in gsm_data_queue()
1160 spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags); in gsm_data_queue()
1164 * gsm_dlci_data_output - try and push data out of a DLCI
1165 * @gsm: mux
1169 * is data. Keep to the MRU of the mux. This path handles the usual tty
1172 * Caller must hold the tx_lock of the mux.
1182 h = ((dlci->adaption == 1) ? 0 : 1); in gsm_dlci_data_output()
1184 len = kfifo_len(&dlci->fifo); in gsm_dlci_data_output()
1189 if ((len + h) > dlci->mtu) in gsm_dlci_data_output()
1190 len = dlci->mtu - h; in gsm_dlci_data_output()
1194 msg = gsm_data_alloc(gsm, dlci->addr, size, dlci->ftype); in gsm_dlci_data_output()
1196 return -ENOMEM; in gsm_dlci_data_output()
1197 dp = msg->data; in gsm_dlci_data_output()
1198 switch (dlci->adaption) { in gsm_dlci_data_output()
1208 dlci->adaption); in gsm_dlci_data_output()
1212 WARN_ON(len != kfifo_out_locked(&dlci->fifo, dp, len, in gsm_dlci_data_output()
1213 &dlci->lock)); in gsm_dlci_data_output()
1216 tty_port_tty_wakeup(&dlci->port); in gsm_dlci_data_output()
1224 * gsm_dlci_data_output_framed - try and push data out of a DLCI
1225 * @gsm: mux
1229 * is data. Keep to the MRU of the mux. This path handles framed data
1232 * Caller must hold the tx_lock of the mux.
1245 if (dlci->adaption == 4) in gsm_dlci_data_output_framed()
1248 /* dlci->skb is locked by tx_lock */ in gsm_dlci_data_output_framed()
1249 if (dlci->skb == NULL) { in gsm_dlci_data_output_framed()
1250 dlci->skb = skb_dequeue_tail(&dlci->skb_list); in gsm_dlci_data_output_framed()
1251 if (dlci->skb == NULL) in gsm_dlci_data_output_framed()
1255 len = dlci->skb->len + overhead; in gsm_dlci_data_output_framed()
1258 if (len > dlci->mtu) { in gsm_dlci_data_output_framed()
1259 if (dlci->adaption == 3) { in gsm_dlci_data_output_framed()
1261 dev_kfree_skb_any(dlci->skb); in gsm_dlci_data_output_framed()
1262 dlci->skb = NULL; in gsm_dlci_data_output_framed()
1265 len = dlci->mtu; in gsm_dlci_data_output_framed()
1270 msg = gsm_data_alloc(gsm, dlci->addr, size, dlci->ftype); in gsm_dlci_data_output_framed()
1272 skb_queue_tail(&dlci->skb_list, dlci->skb); in gsm_dlci_data_output_framed()
1273 dlci->skb = NULL; in gsm_dlci_data_output_framed()
1274 return -ENOMEM; in gsm_dlci_data_output_framed()
1276 dp = msg->data; in gsm_dlci_data_output_framed()
1278 if (dlci->adaption == 4) { /* Interruptible framed (Packetised Data) */ in gsm_dlci_data_output_framed()
1281 len--; in gsm_dlci_data_output_framed()
1283 memcpy(dp, dlci->skb->data, len); in gsm_dlci_data_output_framed()
1284 skb_pull(dlci->skb, len); in gsm_dlci_data_output_framed()
1287 dev_kfree_skb_any(dlci->skb); in gsm_dlci_data_output_framed()
1288 dlci->skb = NULL; in gsm_dlci_data_output_framed()
1294 * gsm_dlci_modem_output - try and push modem status out of a DLCI
1295 * @gsm: mux
1302 * Caller must hold the tx_lock of the mux.
1313 switch (dlci->adaption) { in gsm_dlci_modem_output()
1323 dlci->adaption); in gsm_dlci_modem_output()
1324 return -EINVAL; in gsm_dlci_modem_output()
1327 msg = gsm_data_alloc(gsm, dlci->addr, size, dlci->ftype); in gsm_dlci_modem_output()
1330 return -ENOMEM; in gsm_dlci_modem_output()
1332 dp = msg->data; in gsm_dlci_modem_output()
1333 switch (dlci->adaption) { in gsm_dlci_modem_output()
1354 * gsm_dlci_data_sweep - look for data to send
1355 * @gsm: the GSM mux
1357 * Sweep the GSM mux channels in priority order looking for ones with
1373 while (gsm->tx_bytes < TX_THRESH_HI) { in gsm_dlci_data_sweep()
1375 dlci = gsm->dlci[i]; in gsm_dlci_data_sweep()
1377 if (!dlci || dlci->constipated) in gsm_dlci_data_sweep()
1380 if (dlci->state != DLCI_OPEN) in gsm_dlci_data_sweep()
1383 if (dlci->adaption < 3 && !dlci->net) in gsm_dlci_data_sweep()
1406 * gsm_dlci_data_kick - transmit if possible
1419 if (dlci->constipated) in gsm_dlci_data_kick()
1422 spin_lock_irqsave(&dlci->gsm->tx_lock, flags); in gsm_dlci_data_kick()
1424 sweep = (dlci->gsm->tx_bytes < TX_THRESH_LO); in gsm_dlci_data_kick()
1425 if (dlci->gsm->tx_bytes == 0) { in gsm_dlci_data_kick()
1426 if (dlci->net) in gsm_dlci_data_kick()
1427 gsm_dlci_data_output_framed(dlci->gsm, dlci); in gsm_dlci_data_kick()
1429 gsm_dlci_data_output(dlci->gsm, dlci); in gsm_dlci_data_kick()
1432 gsm_dlci_data_sweep(dlci->gsm); in gsm_dlci_data_kick()
1433 spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags); in gsm_dlci_data_kick()
1442 * gsm_control_command - send a command frame to a control
1454 struct gsm_dlci *dlci = gsm->dlci[0]; in gsm_control_command()
1456 msg = gsm_data_alloc(gsm, 0, dlen + 2, dlci->ftype); in gsm_control_command()
1458 return -ENOMEM; in gsm_control_command()
1460 msg->data[0] = (cmd << 1) | CR | EA; /* Set C/R */ in gsm_control_command()
1461 msg->data[1] = (dlen << 1) | EA; in gsm_control_command()
1462 memcpy(msg->data + 2, data, dlen); in gsm_control_command()
1469 * gsm_control_reply - send a response frame to a control
1482 struct gsm_dlci *dlci = gsm->dlci[0]; in gsm_control_reply()
1484 msg = gsm_data_alloc(gsm, 0, dlen + 2, dlci->ftype); in gsm_control_reply()
1487 msg->data[0] = (cmd & 0xFE) << 1 | EA; /* Clear C/R */ in gsm_control_reply()
1488 msg->data[1] = (dlen << 1) | EA; in gsm_control_reply()
1489 memcpy(msg->data + 2, data, dlen); in gsm_control_reply()
1494 * gsm_process_modem - process received modem status
1513 * section 5.4.6.3.7 of the 07.10 mux spec. in gsm_process_modem()
1525 if (fc && !dlci->constipated) { in gsm_process_modem()
1527 dlci->constipated = true; in gsm_process_modem()
1528 } else if (!fc && dlci->constipated) { in gsm_process_modem()
1529 dlci->constipated = false; in gsm_process_modem()
1543 /* Carrier drop -> hangup */ in gsm_process_modem()
1545 if ((mlines & TIOCM_CD) == 0 && (dlci->modem_rx & TIOCM_CD)) in gsm_process_modem()
1550 tty_insert_flip_char(&dlci->port, 0, TTY_BREAK); in gsm_process_modem()
1551 dlci->modem_rx = mlines; in gsm_process_modem()
1552 wake_up_interruptible(&dlci->gsm->event); in gsm_process_modem()
1556 * gsm_process_negotiation - process received parameters
1569 struct gsm_dlci *dlci = gsm->dlci[addr]; in gsm_process_negotiation()
1572 i = FIELD_GET(PN_I_CL_FIELD_FTYPE, params->i_cl_bits); in gsm_process_negotiation()
1573 adaption = FIELD_GET(PN_I_CL_FIELD_ADAPTION, params->i_cl_bits) + 1; in gsm_process_negotiation()
1574 prio = FIELD_GET(PN_P_FIELD_PRIO, params->p_bits); in gsm_process_negotiation()
1575 n1 = FIELD_GET(PN_N_FIELD_N1, get_unaligned_le16(¶ms->n_bits)); in gsm_process_negotiation()
1576 k = FIELD_GET(PN_K_FIELD_K, params->k_bits); in gsm_process_negotiation()
1581 return -EINVAL; in gsm_process_negotiation()
1595 gsm->unsupported++; in gsm_process_negotiation()
1596 return -EINVAL; in gsm_process_negotiation()
1600 return -EINVAL; in gsm_process_negotiation()
1603 if (!cr && gsm->initiator) { in gsm_process_negotiation()
1604 if (adaption != dlci->adaption) { in gsm_process_negotiation()
1608 return -EINVAL; in gsm_process_negotiation()
1610 if (prio != dlci->prio) { in gsm_process_negotiation()
1614 return -EINVAL; in gsm_process_negotiation()
1616 if (n1 > gsm->mru || n1 > dlci->mtu) { in gsm_process_negotiation()
1624 return -EINVAL; in gsm_process_negotiation()
1626 dlci->mtu = n1; in gsm_process_negotiation()
1627 if (ftype != dlci->ftype) { in gsm_process_negotiation()
1630 return -EINVAL; in gsm_process_negotiation()
1632 if (ftype != UI && ftype != UIH && k > dlci->k) { in gsm_process_negotiation()
1635 return -EINVAL; in gsm_process_negotiation()
1637 dlci->k = k; in gsm_process_negotiation()
1638 } else if (cr && !gsm->initiator) { in gsm_process_negotiation()
1644 return -EINVAL; in gsm_process_negotiation()
1646 dlci->adaption = adaption; in gsm_process_negotiation()
1647 if (n1 > gsm->mru) { in gsm_process_negotiation()
1649 dlci->mtu = gsm->mru; in gsm_process_negotiation()
1652 dlci->mtu = MAX_MTU; in gsm_process_negotiation()
1654 dlci->mtu = n1; in gsm_process_negotiation()
1656 dlci->prio = prio; in gsm_process_negotiation()
1657 dlci->ftype = ftype; in gsm_process_negotiation()
1658 dlci->k = k; in gsm_process_negotiation()
1660 return -EINVAL; in gsm_process_negotiation()
1667 * gsm_control_modem - modem status received
1673 * the GSM mux protocol to pass virtual modem line status and optionally
1694 if (addr == 0 || addr >= NUM_DLCI || gsm->dlci[addr] == NULL) in gsm_control_modem()
1696 dlci = gsm->dlci[addr]; in gsm_control_modem()
1699 if ((cl - len) < 1) in gsm_control_modem()
1703 cl -= len; in gsm_control_modem()
1710 tty = tty_port_tty_get(&dlci->port); in gsm_control_modem()
1720 * gsm_control_negotiation - parameter negotiation received
1727 * the GSM mux protocol to configure protocol parameters for a new DLCI.
1738 gsm->open_error++; in gsm_control_negotiation()
1744 addr = FIELD_GET(PN_D_FIELD_DLCI, params->d_bits); in gsm_control_negotiation()
1745 if (addr == 0 || addr >= NUM_DLCI || !gsm->dlci[addr]) { in gsm_control_negotiation()
1746 gsm->open_error++; in gsm_control_negotiation()
1749 dlci = gsm->dlci[addr]; in gsm_control_negotiation()
1752 if ((!cr && dlci->state == DLCI_OPENING) || dlci->state == DLCI_OPEN) { in gsm_control_negotiation()
1753 gsm->open_error++; in gsm_control_negotiation()
1762 gsm->open_error++; in gsm_control_negotiation()
1774 } else if (dlci->state == DLCI_CONFIGURE) { in gsm_control_negotiation()
1776 dlci->state = DLCI_OPENING; in gsm_control_negotiation()
1777 gsm_command(gsm, dlci->addr, SABM|PF); in gsm_control_negotiation()
1778 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_control_negotiation()
1782 gsm->open_error++; in gsm_control_negotiation()
1787 * gsm_control_rls - remote line status
1806 len--; in gsm_control_rls()
1811 len--; in gsm_control_rls()
1816 if (addr == 0 || addr >= NUM_DLCI || gsm->dlci[addr] == NULL) in gsm_control_rls()
1823 port = &gsm->dlci[addr]->port; in gsm_control_rls()
1840 * gsm_control_message - DLCI 0 control processing
1841 * @gsm: our GSM mux
1858 struct gsm_dlci *dlci = gsm->dlci[0]; in gsm_control_message()
1861 dlci->dead = true; in gsm_control_message()
1862 gsm->dead = true; in gsm_control_message()
1873 gsm->constipated = false; in gsm_control_message()
1880 gsm->constipated = true; in gsm_control_message()
1903 gsm->unsupported++; in gsm_control_message()
1914 * gsm_control_response - process a response to our control
1915 * @gsm: our GSM mux
1920 * Process a response to an outstanding command. We only allow a single
1929 struct gsm_control *ctrl; in gsm_control_response() local
1933 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_response()
1935 ctrl = gsm->pending_cmd; in gsm_control_response()
1936 dlci = gsm->dlci[0]; in gsm_control_response()
1939 if (ctrl != NULL && (command == ctrl->cmd || command == CMD_NSC)) { in gsm_control_response()
1941 del_timer(&gsm->t2_timer); in gsm_control_response()
1942 gsm->pending_cmd = NULL; in gsm_control_response()
1945 ctrl->error = -EOPNOTSUPP; in gsm_control_response()
1946 ctrl->done = 1; in gsm_control_response()
1947 wake_up(&gsm->event); in gsm_control_response()
1952 } else if (command == CMD_TEST && clen == 1 && *data == gsm->ka_num) { in gsm_control_response()
1953 gsm->ka_retries = -1; /* trigger new keep-alive message */ in gsm_control_response()
1954 if (dlci && !dlci->dead) in gsm_control_response()
1955 mod_timer(&gsm->ka_timer, jiffies + gsm->keep_alive * HZ / 100); in gsm_control_response()
1957 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_response()
1961 * gsm_control_keep_alive - check timeout or start keep-alive
1964 * Called off the keep-alive timer expiry signaling that our link
1974 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_keep_alive()
1975 if (gsm->ka_num && gsm->ka_retries == 0) { in gsm_control_keep_alive()
1976 /* Keep-alive expired -> close the link */ in gsm_control_keep_alive()
1978 pr_debug("%s keep-alive timed out\n", __func__); in gsm_control_keep_alive()
1979 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_keep_alive()
1980 if (gsm->dlci[0]) in gsm_control_keep_alive()
1981 gsm_dlci_begin_close(gsm->dlci[0]); in gsm_control_keep_alive()
1983 } else if (gsm->keep_alive && gsm->dlci[0] && !gsm->dlci[0]->dead) { in gsm_control_keep_alive()
1984 if (gsm->ka_retries > 0) { in gsm_control_keep_alive()
1985 /* T2 expired for keep-alive -> resend */ in gsm_control_keep_alive()
1986 gsm->ka_retries--; in gsm_control_keep_alive()
1988 /* Start keep-alive timer */ in gsm_control_keep_alive()
1989 gsm->ka_num++; in gsm_control_keep_alive()
1990 if (!gsm->ka_num) in gsm_control_keep_alive()
1991 gsm->ka_num++; in gsm_control_keep_alive()
1992 gsm->ka_retries = (signed int)gsm->n2; in gsm_control_keep_alive()
1994 gsm_control_command(gsm, CMD_TEST, &gsm->ka_num, in gsm_control_keep_alive()
1995 sizeof(gsm->ka_num)); in gsm_control_keep_alive()
1996 mod_timer(&gsm->ka_timer, in gsm_control_keep_alive()
1997 jiffies + gsm->t2 * HZ / 100); in gsm_control_keep_alive()
1999 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_keep_alive()
2003 * gsm_control_transmit - send control packet
2004 * @gsm: gsm mux
2005 * @ctrl: frame to send
2010 static void gsm_control_transmit(struct gsm_mux *gsm, struct gsm_control *ctrl) in gsm_control_transmit() argument
2012 gsm_control_command(gsm, ctrl->cmd, ctrl->data, ctrl->len); in gsm_control_transmit()
2016 * gsm_control_retransmit - retransmit a control frame
2023 * gsm->pending_cmd will be NULL and we just let the timer expire.
2029 struct gsm_control *ctrl; in gsm_control_retransmit() local
2031 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_retransmit()
2032 ctrl = gsm->pending_cmd; in gsm_control_retransmit()
2033 if (ctrl) { in gsm_control_retransmit()
2034 if (gsm->cretries == 0 || !gsm->dlci[0] || gsm->dlci[0]->dead) { in gsm_control_retransmit()
2035 gsm->pending_cmd = NULL; in gsm_control_retransmit()
2036 ctrl->error = -ETIMEDOUT; in gsm_control_retransmit()
2037 ctrl->done = 1; in gsm_control_retransmit()
2038 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_retransmit()
2039 wake_up(&gsm->event); in gsm_control_retransmit()
2042 gsm->cretries--; in gsm_control_retransmit()
2043 gsm_control_transmit(gsm, ctrl); in gsm_control_retransmit()
2044 mod_timer(&gsm->t2_timer, jiffies + gsm->t2 * HZ / 100); in gsm_control_retransmit()
2046 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_retransmit()
2050 * gsm_control_send - send a control frame on DLCI 0
2064 struct gsm_control *ctrl = kzalloc(sizeof(struct gsm_control), in gsm_control_send() local
2067 if (ctrl == NULL) in gsm_control_send()
2070 wait_event(gsm->event, gsm->pending_cmd == NULL); in gsm_control_send()
2071 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_send()
2072 if (gsm->pending_cmd != NULL) { in gsm_control_send()
2073 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_send()
2076 ctrl->cmd = command; in gsm_control_send()
2077 ctrl->data = data; in gsm_control_send()
2078 ctrl->len = clen; in gsm_control_send()
2079 gsm->pending_cmd = ctrl; in gsm_control_send()
2082 if (gsm->dlci[0]->mode == DLCI_MODE_ADM) in gsm_control_send()
2083 gsm->cretries = 0; in gsm_control_send()
2085 gsm->cretries = gsm->n2; in gsm_control_send()
2087 mod_timer(&gsm->t2_timer, jiffies + gsm->t2 * HZ / 100); in gsm_control_send()
2088 gsm_control_transmit(gsm, ctrl); in gsm_control_send()
2089 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_send()
2090 return ctrl; in gsm_control_send()
2094 * gsm_control_wait - wait for a control to finish
2095 * @gsm: GSM mux
2106 wait_event(gsm->event, control->done == 1); in gsm_control_wait()
2107 err = control->error; in gsm_control_wait()
2122 * gsm_dlci_close - a DLCI has closed
2131 del_timer(&dlci->t1); in gsm_dlci_close()
2133 pr_debug("DLCI %d goes closed.\n", dlci->addr); in gsm_dlci_close()
2134 dlci->state = DLCI_CLOSED; in gsm_dlci_close()
2136 dlci->constipated = true; in gsm_dlci_close()
2137 if (dlci->addr != 0) { in gsm_dlci_close()
2138 tty_port_tty_hangup(&dlci->port, false); in gsm_dlci_close()
2139 gsm_dlci_clear_queues(dlci->gsm, dlci); in gsm_dlci_close()
2141 tty_port_set_initialized(&dlci->port, false); in gsm_dlci_close()
2142 wake_up_interruptible(&dlci->port.open_wait); in gsm_dlci_close()
2144 del_timer(&dlci->gsm->ka_timer); in gsm_dlci_close()
2145 dlci->gsm->dead = true; in gsm_dlci_close()
2147 /* A DLCI 0 close is a MUX termination so we need to kick that in gsm_dlci_close()
2150 wake_up_all(&dlci->gsm->event); in gsm_dlci_close()
2154 * gsm_dlci_open - a DLCI has opened
2162 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_open()
2165 open -> open */ in gsm_dlci_open()
2166 del_timer(&dlci->t1); in gsm_dlci_open()
2168 dlci->state = DLCI_OPEN; in gsm_dlci_open()
2169 dlci->constipated = false; in gsm_dlci_open()
2171 pr_debug("DLCI %d goes open.\n", dlci->addr); in gsm_dlci_open()
2173 if (dlci->addr) { in gsm_dlci_open()
2176 /* Start keep-alive control */ in gsm_dlci_open()
2177 gsm->ka_num = 0; in gsm_dlci_open()
2178 gsm->ka_retries = -1; in gsm_dlci_open()
2179 mod_timer(&gsm->ka_timer, in gsm_dlci_open()
2180 jiffies + gsm->keep_alive * HZ / 100); in gsm_dlci_open()
2183 wake_up(&dlci->gsm->event); in gsm_dlci_open()
2187 * gsm_dlci_negotiate - start parameter negotiation
2195 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_negotiate()
2213 * gsm_dlci_t1 - T1 timer expiry
2230 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_t1()
2232 switch (dlci->state) { in gsm_dlci_t1()
2234 if (dlci->retries && gsm_dlci_negotiate(dlci) == 0) { in gsm_dlci_t1()
2235 dlci->retries--; in gsm_dlci_t1()
2236 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_t1()
2238 gsm->open_error++; in gsm_dlci_t1()
2243 if (dlci->retries) { in gsm_dlci_t1()
2244 dlci->retries--; in gsm_dlci_t1()
2245 gsm_command(dlci->gsm, dlci->addr, SABM|PF); in gsm_dlci_t1()
2246 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_t1()
2247 } else if (!dlci->addr && gsm->control == (DM | PF)) { in gsm_dlci_t1()
2250 dlci->addr); in gsm_dlci_t1()
2251 dlci->mode = DLCI_MODE_ADM; in gsm_dlci_t1()
2254 gsm->open_error++; in gsm_dlci_t1()
2260 if (dlci->retries) { in gsm_dlci_t1()
2261 dlci->retries--; in gsm_dlci_t1()
2262 gsm_command(dlci->gsm, dlci->addr, DISC|PF); in gsm_dlci_t1()
2263 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_t1()
2268 pr_debug("%s: unhandled state: %d\n", __func__, dlci->state); in gsm_dlci_t1()
2274 * gsm_dlci_begin_open - start channel open procedure
2286 struct gsm_mux *gsm = dlci ? dlci->gsm : NULL; in gsm_dlci_begin_open()
2292 if (dlci->addr != 0) { in gsm_dlci_begin_open()
2293 if (gsm->adaption != 1 || gsm->adaption != dlci->adaption) in gsm_dlci_begin_open()
2295 if (dlci->prio != (roundup(dlci->addr + 1, 8) - 1)) in gsm_dlci_begin_open()
2297 if (gsm->ftype != dlci->ftype) in gsm_dlci_begin_open()
2301 switch (dlci->state) { in gsm_dlci_begin_open()
2305 dlci->retries = gsm->n2; in gsm_dlci_begin_open()
2307 dlci->state = DLCI_OPENING; in gsm_dlci_begin_open()
2308 gsm_command(gsm, dlci->addr, SABM|PF); in gsm_dlci_begin_open()
2311 dlci->state = DLCI_CONFIGURE; in gsm_dlci_begin_open()
2317 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_begin_open()
2325 * gsm_dlci_set_opening - change state to opening
2333 switch (dlci->state) { in gsm_dlci_set_opening()
2337 dlci->state = DLCI_OPENING; in gsm_dlci_set_opening()
2345 * gsm_dlci_set_wait_config - wait for channel configuration
2352 switch (dlci->state) { in gsm_dlci_set_wait_config()
2355 dlci->state = DLCI_WAITING_CONFIG; in gsm_dlci_set_wait_config()
2363 * gsm_dlci_begin_close - start channel open procedure
2375 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_begin_close()
2376 if (dlci->state == DLCI_CLOSED || dlci->state == DLCI_CLOSING) in gsm_dlci_begin_close()
2378 dlci->retries = gsm->n2; in gsm_dlci_begin_close()
2379 dlci->state = DLCI_CLOSING; in gsm_dlci_begin_close()
2380 gsm_command(dlci->gsm, dlci->addr, DISC|PF); in gsm_dlci_begin_close()
2381 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_begin_close()
2382 wake_up_interruptible(&gsm->event); in gsm_dlci_begin_close()
2386 * gsm_dlci_data - data arrived
2399 struct tty_port *port = &dlci->port; in gsm_dlci_data()
2406 switch (dlci->adaption) { in gsm_dlci_data()
2424 clen -= len; in gsm_dlci_data()
2434 * gsm_dlci_command - data arrived on control channel
2454 len -= dlen; in gsm_dlci_command()
2459 len -= dlen; in gsm_dlci_command()
2464 dlci->gsm->malformed++; in gsm_dlci_command()
2469 gsm_control_message(dlci->gsm, command, data, clen); in gsm_dlci_command()
2471 gsm_control_response(dlci->gsm, command, data, clen); in gsm_dlci_command()
2475 * gsm_kick_timer - transmit if possible
2488 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_kick_timer()
2490 if (gsm->tx_bytes < TX_THRESH_LO) in gsm_kick_timer()
2492 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_kick_timer()
2499 * gsm_dlci_copy_config_values - copy DLCI configuration
2506 dc->channel = (u32)dlci->addr; in gsm_dlci_copy_config_values()
2507 dc->adaption = (u32)dlci->adaption; in gsm_dlci_copy_config_values()
2508 dc->mtu = (u32)dlci->mtu; in gsm_dlci_copy_config_values()
2509 dc->priority = (u32)dlci->prio; in gsm_dlci_copy_config_values()
2510 if (dlci->ftype == UIH) in gsm_dlci_copy_config_values()
2511 dc->i = 1; in gsm_dlci_copy_config_values()
2513 dc->i = 2; in gsm_dlci_copy_config_values()
2514 dc->k = (u32)dlci->k; in gsm_dlci_copy_config_values()
2518 * gsm_dlci_config - configure DLCI from configuration
2534 for (i = 0; i < ARRAY_SIZE(dc->reserved); i++) in gsm_dlci_config()
2535 if (dc->reserved[i]) in gsm_dlci_config()
2536 return -EINVAL; in gsm_dlci_config()
2539 return -EINVAL; in gsm_dlci_config()
2540 gsm = dlci->gsm; in gsm_dlci_config()
2542 /* Stuff we don't support yet - I frame transport */ in gsm_dlci_config()
2543 if (dc->adaption != 1 && dc->adaption != 2) in gsm_dlci_config()
2544 return -EOPNOTSUPP; in gsm_dlci_config()
2545 if (dc->mtu > MAX_MTU || dc->mtu < MIN_MTU || dc->mtu > gsm->mru) in gsm_dlci_config()
2546 return -EINVAL; in gsm_dlci_config()
2547 if (dc->priority >= 64) in gsm_dlci_config()
2548 return -EINVAL; in gsm_dlci_config()
2549 if (dc->i == 0 || dc->i > 2) /* UIH and UI only */ in gsm_dlci_config()
2550 return -EINVAL; in gsm_dlci_config()
2551 if (dc->k > 7) in gsm_dlci_config()
2552 return -EINVAL; in gsm_dlci_config()
2553 if (dc->flags & ~GSM_FL_RESTART) /* allow future extensions */ in gsm_dlci_config()
2554 return -EINVAL; in gsm_dlci_config()
2560 if (dc->adaption != dlci->adaption) in gsm_dlci_config()
2562 if (dc->mtu != dlci->mtu) in gsm_dlci_config()
2564 if (dc->i != dlci->ftype) in gsm_dlci_config()
2567 if (dc->priority != dlci->prio) in gsm_dlci_config()
2569 if (dc->flags & GSM_FL_RESTART) in gsm_dlci_config()
2572 if ((open && gsm->wait_config) || need_restart) in gsm_dlci_config()
2574 if (dlci->state == DLCI_WAITING_CONFIG) { in gsm_dlci_config()
2585 wait_event_interruptible(gsm->event, dlci->state == DLCI_CLOSED); in gsm_dlci_config()
2587 return -EINTR; in gsm_dlci_config()
2592 dlci->adaption = (int)dc->adaption; in gsm_dlci_config()
2594 if (dc->mtu) in gsm_dlci_config()
2595 dlci->mtu = (unsigned int)dc->mtu; in gsm_dlci_config()
2597 dlci->mtu = gsm->mtu; in gsm_dlci_config()
2599 if (dc->priority) in gsm_dlci_config()
2600 dlci->prio = (u8)dc->priority; in gsm_dlci_config()
2602 dlci->prio = roundup(dlci->addr + 1, 8) - 1; in gsm_dlci_config()
2604 if (dc->i == 1) in gsm_dlci_config()
2605 dlci->ftype = UIH; in gsm_dlci_config()
2606 else if (dc->i == 2) in gsm_dlci_config()
2607 dlci->ftype = UI; in gsm_dlci_config()
2609 if (dc->k) in gsm_dlci_config()
2610 dlci->k = (u8)dc->k; in gsm_dlci_config()
2612 dlci->k = gsm->k; in gsm_dlci_config()
2615 if (gsm->initiator) in gsm_dlci_config()
2629 * gsm_dlci_alloc - allocate a DLCI
2630 * @gsm: GSM mux
2633 * Allocate and install a new DLCI object into the GSM mux.
2643 spin_lock_init(&dlci->lock); in gsm_dlci_alloc()
2644 mutex_init(&dlci->mutex); in gsm_dlci_alloc()
2645 if (kfifo_alloc(&dlci->fifo, TX_SIZE, GFP_KERNEL) < 0) { in gsm_dlci_alloc()
2650 skb_queue_head_init(&dlci->skb_list); in gsm_dlci_alloc()
2651 timer_setup(&dlci->t1, gsm_dlci_t1, 0); in gsm_dlci_alloc()
2652 tty_port_init(&dlci->port); in gsm_dlci_alloc()
2653 dlci->port.ops = &gsm_port_ops; in gsm_dlci_alloc()
2654 dlci->gsm = gsm; in gsm_dlci_alloc()
2655 dlci->addr = addr; in gsm_dlci_alloc()
2656 dlci->adaption = gsm->adaption; in gsm_dlci_alloc()
2657 dlci->mtu = gsm->mtu; in gsm_dlci_alloc()
2659 dlci->prio = 0; in gsm_dlci_alloc()
2661 dlci->prio = roundup(addr + 1, 8) - 1; in gsm_dlci_alloc()
2662 dlci->ftype = gsm->ftype; in gsm_dlci_alloc()
2663 dlci->k = gsm->k; in gsm_dlci_alloc()
2664 dlci->state = DLCI_CLOSED; in gsm_dlci_alloc()
2666 dlci->data = gsm_dlci_data; in gsm_dlci_alloc()
2668 dlci->constipated = true; in gsm_dlci_alloc()
2670 dlci->data = gsm_dlci_command; in gsm_dlci_alloc()
2672 gsm->dlci[addr] = dlci; in gsm_dlci_alloc()
2677 * gsm_dlci_free - free DLCI
2688 timer_shutdown_sync(&dlci->t1); in gsm_dlci_free()
2689 dlci->gsm->dlci[dlci->addr] = NULL; in gsm_dlci_free()
2690 kfifo_free(&dlci->fifo); in gsm_dlci_free()
2691 while ((dlci->skb = skb_dequeue(&dlci->skb_list))) in gsm_dlci_free()
2692 dev_kfree_skb(dlci->skb); in gsm_dlci_free()
2698 tty_port_get(&dlci->port); in dlci_get()
2703 tty_port_put(&dlci->port); in dlci_put()
2709 * gsm_dlci_release - release DLCI
2713 * mux is closed or tty is closed - whichever is last.
2719 struct tty_struct *tty = tty_port_tty_get(&dlci->port); in gsm_dlci_release()
2721 mutex_lock(&dlci->mutex); in gsm_dlci_release()
2723 mutex_unlock(&dlci->mutex); in gsm_dlci_release()
2727 * queue release_one_tty() -> NULL pointer panic in in gsm_dlci_release()
2732 tty_port_tty_set(&dlci->port, NULL); in gsm_dlci_release()
2735 dlci->state = DLCI_CLOSED; in gsm_dlci_release()
2744 * gsm_queue - a GSM frame is ready to process
2745 * @gsm: pointer to our gsm mux
2759 if (gsm->fcs != GOOD_FCS) { in gsm_queue()
2760 gsm->bad_fcs++; in gsm_queue()
2762 pr_debug("BAD FCS %02x\n", gsm->fcs); in gsm_queue()
2765 address = gsm->address >> 1; in gsm_queue()
2769 cr = gsm->address & 1; /* C/R bit */ in gsm_queue()
2770 cr ^= gsm->initiator ? 0 : 1; /* Flip so 1 always means command */ in gsm_queue()
2772 gsm_print_packet("<--", address, cr, gsm->control, gsm->buf, gsm->len); in gsm_queue()
2774 dlci = gsm->dlci[address]; in gsm_queue()
2776 switch (gsm->control) { in gsm_queue()
2779 gsm->open_error++; in gsm_queue()
2785 gsm->open_error++; in gsm_queue()
2788 if (dlci->dead) in gsm_queue()
2798 if (dlci == NULL || dlci->state == DLCI_CLOSED) { in gsm_queue()
2809 switch (dlci->state) { in gsm_queue()
2818 dlci->state); in gsm_queue()
2834 if (dlci == NULL || dlci->state != DLCI_OPEN) { in gsm_queue()
2838 dlci->data(dlci, gsm->buf, gsm->len); in gsm_queue()
2845 gsm->malformed++; in gsm_queue()
2851 * gsm0_receive - perform processing for non-transparency
2862 switch (gsm->state) { in gsm0_receive()
2865 gsm->state = GSM_ADDRESS; in gsm0_receive()
2866 gsm->address = 0; in gsm0_receive()
2867 gsm->len = 0; in gsm0_receive()
2868 gsm->fcs = INIT_FCS; in gsm0_receive()
2872 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2873 if (gsm_read_ea(&gsm->address, c)) in gsm0_receive()
2874 gsm->state = GSM_CONTROL; in gsm0_receive()
2877 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2878 gsm->control = c; in gsm0_receive()
2879 gsm->state = GSM_LEN0; in gsm0_receive()
2882 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2883 if (gsm_read_ea(&gsm->len, c)) { in gsm0_receive()
2884 if (gsm->len > gsm->mru) { in gsm0_receive()
2885 gsm->bad_size++; in gsm0_receive()
2886 gsm->state = GSM_SEARCH; in gsm0_receive()
2889 gsm->count = 0; in gsm0_receive()
2890 if (!gsm->len) in gsm0_receive()
2891 gsm->state = GSM_FCS; in gsm0_receive()
2893 gsm->state = GSM_DATA; in gsm0_receive()
2896 gsm->state = GSM_LEN1; in gsm0_receive()
2899 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2901 gsm->len |= len << 7; in gsm0_receive()
2902 if (gsm->len > gsm->mru) { in gsm0_receive()
2903 gsm->bad_size++; in gsm0_receive()
2904 gsm->state = GSM_SEARCH; in gsm0_receive()
2907 gsm->count = 0; in gsm0_receive()
2908 if (!gsm->len) in gsm0_receive()
2909 gsm->state = GSM_FCS; in gsm0_receive()
2911 gsm->state = GSM_DATA; in gsm0_receive()
2914 gsm->buf[gsm->count++] = c; in gsm0_receive()
2915 if (gsm->count == gsm->len) { in gsm0_receive()
2917 if ((gsm->control & ~PF) != UIH) { in gsm0_receive()
2918 gsm->fcs = gsm_fcs_add_block(gsm->fcs, gsm->buf, in gsm0_receive()
2919 gsm->count); in gsm0_receive()
2921 gsm->state = GSM_FCS; in gsm0_receive()
2925 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2926 gsm->state = GSM_SSOF; in gsm0_receive()
2929 gsm->state = GSM_SEARCH; in gsm0_receive()
2933 gsm->bad_size++; in gsm0_receive()
2936 pr_debug("%s: unhandled state: %d\n", __func__, gsm->state); in gsm0_receive()
2942 * gsm1_receive - perform processing for non-transparency
2953 gsm->constipated = true; in gsm1_receive()
2956 gsm->constipated = false; in gsm1_receive()
2963 if (gsm->state == GSM_DATA) { in gsm1_receive()
2964 if (gsm->count < 1) { in gsm1_receive()
2966 gsm->malformed++; in gsm1_receive()
2967 gsm->state = GSM_START; in gsm1_receive()
2971 gsm->count--; in gsm1_receive()
2972 if ((gsm->control & ~PF) != UIH) { in gsm1_receive()
2976 gsm->fcs = gsm_fcs_add_block(gsm->fcs, gsm->buf, in gsm1_receive()
2977 gsm->count); in gsm1_receive()
2980 gsm->fcs = gsm_fcs_add(gsm->fcs, gsm->buf[gsm->count]); in gsm1_receive()
2981 gsm->len = gsm->count; in gsm1_receive()
2983 gsm->state = GSM_START; in gsm1_receive()
2987 if (gsm->state != GSM_START) { in gsm1_receive()
2988 if (gsm->state != GSM_SEARCH) in gsm1_receive()
2989 gsm->malformed++; in gsm1_receive()
2990 gsm->state = GSM_START; in gsm1_receive()
2998 gsm->escape = true; in gsm1_receive()
3003 if (gsm->state == GSM_SEARCH) in gsm1_receive()
3006 if (gsm->escape) { in gsm1_receive()
3008 gsm->escape = false; in gsm1_receive()
3010 switch (gsm->state) { in gsm1_receive()
3012 gsm->address = 0; in gsm1_receive()
3013 gsm->state = GSM_ADDRESS; in gsm1_receive()
3014 gsm->fcs = INIT_FCS; in gsm1_receive()
3017 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm1_receive()
3018 if (gsm_read_ea(&gsm->address, c)) in gsm1_receive()
3019 gsm->state = GSM_CONTROL; in gsm1_receive()
3022 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm1_receive()
3023 gsm->control = c; in gsm1_receive()
3024 gsm->count = 0; in gsm1_receive()
3025 gsm->state = GSM_DATA; in gsm1_receive()
3028 if (gsm->count > gsm->mru) { /* Allow one for the FCS */ in gsm1_receive()
3029 gsm->state = GSM_OVERRUN; in gsm1_receive()
3030 gsm->bad_size++; in gsm1_receive()
3032 gsm->buf[gsm->count++] = c; in gsm1_receive()
3034 case GSM_OVERRUN: /* Over-long - eg a dropped SOF */ in gsm1_receive()
3037 pr_debug("%s: unhandled state: %d\n", __func__, gsm->state); in gsm1_receive()
3043 * gsm_error - handle tty error
3054 gsm->state = GSM_SEARCH; in gsm_error()
3055 gsm->io_error++; in gsm_error()
3059 * gsm_cleanup_mux - generic GSM protocol cleanup
3060 * @gsm: our mux
3063 * Clean up the bits of the mux which are the same for all framing
3064 * protocols. Remove the mux from the mux table, stop all the timers
3074 gsm->dead = true; in gsm_cleanup_mux()
3075 mutex_lock(&gsm->mutex); in gsm_cleanup_mux()
3077 dlci = gsm->dlci[0]; in gsm_cleanup_mux()
3079 if (disc && dlci->state != DLCI_CLOSED) { in gsm_cleanup_mux()
3081 wait_event(gsm->event, dlci->state == DLCI_CLOSED); in gsm_cleanup_mux()
3083 dlci->dead = true; in gsm_cleanup_mux()
3087 del_timer_sync(&gsm->kick_timer); in gsm_cleanup_mux()
3088 del_timer_sync(&gsm->t2_timer); in gsm_cleanup_mux()
3089 del_timer_sync(&gsm->ka_timer); in gsm_cleanup_mux()
3092 flush_work(&gsm->tx_work); in gsm_cleanup_mux()
3095 if (gsm->has_devices) { in gsm_cleanup_mux()
3096 gsm_unregister_devices(gsm_tty_driver, gsm->num); in gsm_cleanup_mux()
3097 gsm->has_devices = false; in gsm_cleanup_mux()
3099 for (i = NUM_DLCI - 1; i >= 0; i--) in gsm_cleanup_mux()
3100 if (gsm->dlci[i]) in gsm_cleanup_mux()
3101 gsm_dlci_release(gsm->dlci[i]); in gsm_cleanup_mux()
3102 mutex_unlock(&gsm->mutex); in gsm_cleanup_mux()
3104 tty_ldisc_flush(gsm->tty); in gsm_cleanup_mux()
3105 list_for_each_entry_safe(txq, ntxq, &gsm->tx_ctrl_list, list) in gsm_cleanup_mux()
3107 INIT_LIST_HEAD(&gsm->tx_ctrl_list); in gsm_cleanup_mux()
3108 list_for_each_entry_safe(txq, ntxq, &gsm->tx_data_list, list) in gsm_cleanup_mux()
3110 INIT_LIST_HEAD(&gsm->tx_data_list); in gsm_cleanup_mux()
3114 * gsm_activate_mux - generic GSM setup
3115 * @gsm: our mux
3117 * Set up the bits of the mux which are the same for all framing
3118 * protocols. Add the mux to the mux table so it can be opened and
3129 return -ENOMEM; in gsm_activate_mux()
3131 if (gsm->encoding == GSM_BASIC_OPT) in gsm_activate_mux()
3132 gsm->receive = gsm0_receive; in gsm_activate_mux()
3134 gsm->receive = gsm1_receive; in gsm_activate_mux()
3136 ret = gsm_register_devices(gsm_tty_driver, gsm->num); in gsm_activate_mux()
3140 gsm->has_devices = true; in gsm_activate_mux()
3141 gsm->dead = false; /* Tty opens are now permissible */ in gsm_activate_mux()
3146 * gsm_free_mux - free up a mux
3147 * @gsm: mux to free
3149 * Dispose of allocated resources for a dead mux
3161 mutex_destroy(&gsm->mutex); in gsm_free_mux()
3162 kfree(gsm->txframe); in gsm_free_mux()
3163 kfree(gsm->buf); in gsm_free_mux()
3168 * gsm_free_muxr - free up a mux
3169 * @ref: kreference to the mux to free
3171 * Dispose of allocated resources for a dead mux
3184 kref_get(&gsm->ref); in mux_get()
3193 kref_put(&gsm->ref, gsm_free_muxr); in mux_put()
3199 return gsm->num * NUM_DLCI; in mux_num_to_base()
3208 * gsm_alloc_mux - allocate a mux
3210 * Creates a new mux ready for activation.
3219 gsm->buf = kmalloc(MAX_MRU + 1, GFP_KERNEL); in gsm_alloc_mux()
3220 if (gsm->buf == NULL) { in gsm_alloc_mux()
3224 gsm->txframe = kmalloc(2 * (MAX_MTU + PROT_OVERHEAD - 1), GFP_KERNEL); in gsm_alloc_mux()
3225 if (gsm->txframe == NULL) { in gsm_alloc_mux()
3226 kfree(gsm->buf); in gsm_alloc_mux()
3230 spin_lock_init(&gsm->lock); in gsm_alloc_mux()
3231 mutex_init(&gsm->mutex); in gsm_alloc_mux()
3232 kref_init(&gsm->ref); in gsm_alloc_mux()
3233 INIT_LIST_HEAD(&gsm->tx_ctrl_list); in gsm_alloc_mux()
3234 INIT_LIST_HEAD(&gsm->tx_data_list); in gsm_alloc_mux()
3235 timer_setup(&gsm->kick_timer, gsm_kick_timer, 0); in gsm_alloc_mux()
3236 timer_setup(&gsm->t2_timer, gsm_control_retransmit, 0); in gsm_alloc_mux()
3237 timer_setup(&gsm->ka_timer, gsm_control_keep_alive, 0); in gsm_alloc_mux()
3238 INIT_WORK(&gsm->tx_work, gsmld_write_task); in gsm_alloc_mux()
3239 init_waitqueue_head(&gsm->event); in gsm_alloc_mux()
3240 spin_lock_init(&gsm->control_lock); in gsm_alloc_mux()
3241 spin_lock_init(&gsm->tx_lock); in gsm_alloc_mux()
3243 gsm->t1 = T1; in gsm_alloc_mux()
3244 gsm->t2 = T2; in gsm_alloc_mux()
3245 gsm->t3 = T3; in gsm_alloc_mux()
3246 gsm->n2 = N2; in gsm_alloc_mux()
3247 gsm->k = K; in gsm_alloc_mux()
3248 gsm->ftype = UIH; in gsm_alloc_mux()
3249 gsm->adaption = 1; in gsm_alloc_mux()
3250 gsm->encoding = GSM_ADV_OPT; in gsm_alloc_mux()
3251 gsm->mru = 64; /* Default to encoding 1 so these should be 64 */ in gsm_alloc_mux()
3252 gsm->mtu = 64; in gsm_alloc_mux()
3253 gsm->dead = true; /* Avoid early tty opens */ in gsm_alloc_mux()
3254 gsm->wait_config = false; /* Disabled */ in gsm_alloc_mux()
3255 gsm->keep_alive = 0; /* Disabled */ in gsm_alloc_mux()
3257 /* Store the instance to the mux array or abort if no space is in gsm_alloc_mux()
3264 gsm->num = i; in gsm_alloc_mux()
3270 mutex_destroy(&gsm->mutex); in gsm_alloc_mux()
3271 kfree(gsm->txframe); in gsm_alloc_mux()
3272 kfree(gsm->buf); in gsm_alloc_mux()
3284 c->adaption = gsm->adaption; in gsm_copy_config_values()
3285 c->encapsulation = gsm->encoding; in gsm_copy_config_values()
3286 c->initiator = gsm->initiator; in gsm_copy_config_values()
3287 c->t1 = gsm->t1; in gsm_copy_config_values()
3288 c->t2 = gsm->t2; in gsm_copy_config_values()
3289 c->t3 = gsm->t3; in gsm_copy_config_values()
3290 c->n2 = gsm->n2; in gsm_copy_config_values()
3291 if (gsm->ftype == UIH) in gsm_copy_config_values()
3292 c->i = 1; in gsm_copy_config_values()
3294 c->i = 2; in gsm_copy_config_values()
3295 pr_debug("Ftype %d i %d\n", gsm->ftype, c->i); in gsm_copy_config_values()
3296 c->mru = gsm->mru; in gsm_copy_config_values()
3297 c->mtu = gsm->mtu; in gsm_copy_config_values()
3298 c->k = gsm->k; in gsm_copy_config_values()
3306 /* Stuff we don't support yet - UI or I frame transport */ in gsm_config()
3307 if (c->adaption != 1 && c->adaption != 2) in gsm_config()
3308 return -EOPNOTSUPP; in gsm_config()
3310 if (c->mru < MIN_MTU || c->mtu < MIN_MTU) in gsm_config()
3311 return -EINVAL; in gsm_config()
3312 if (c->mru > MAX_MRU || c->mtu > MAX_MTU) in gsm_config()
3313 return -EINVAL; in gsm_config()
3314 if (c->t3 > MAX_T3) in gsm_config()
3315 return -EINVAL; in gsm_config()
3316 if (c->n2 > 255) in gsm_config()
3317 return -EINVAL; in gsm_config()
3318 if (c->encapsulation > 1) /* Basic, advanced, no I */ in gsm_config()
3319 return -EINVAL; in gsm_config()
3320 if (c->initiator > 1) in gsm_config()
3321 return -EINVAL; in gsm_config()
3322 if (c->k > MAX_WINDOW_SIZE) in gsm_config()
3323 return -EINVAL; in gsm_config()
3324 if (c->i == 0 || c->i > 2) /* UIH and UI only */ in gsm_config()
3325 return -EINVAL; in gsm_config()
3331 if (c->t1 != 0 && c->t1 != gsm->t1) in gsm_config()
3333 if (c->t2 != 0 && c->t2 != gsm->t2) in gsm_config()
3335 if (c->encapsulation != gsm->encoding) in gsm_config()
3337 if (c->adaption != gsm->adaption) in gsm_config()
3340 if (c->initiator != gsm->initiator) in gsm_config()
3342 if (c->mru != gsm->mru) in gsm_config()
3344 if (c->mtu != gsm->mtu) in gsm_config()
3355 gsm->initiator = c->initiator; in gsm_config()
3356 gsm->mru = c->mru; in gsm_config()
3357 gsm->mtu = c->mtu; in gsm_config()
3358 gsm->encoding = c->encapsulation ? GSM_ADV_OPT : GSM_BASIC_OPT; in gsm_config()
3359 gsm->adaption = c->adaption; in gsm_config()
3360 gsm->n2 = c->n2; in gsm_config()
3362 if (c->i == 1) in gsm_config()
3363 gsm->ftype = UIH; in gsm_config()
3364 else if (c->i == 2) in gsm_config()
3365 gsm->ftype = UI; in gsm_config()
3367 if (c->t1) in gsm_config()
3368 gsm->t1 = c->t1; in gsm_config()
3369 if (c->t2) in gsm_config()
3370 gsm->t2 = c->t2; in gsm_config()
3371 if (c->t3) in gsm_config()
3372 gsm->t3 = c->t3; in gsm_config()
3373 if (c->k) in gsm_config()
3374 gsm->k = c->k; in gsm_config()
3378 * and removing from the mux array in gsm_config()
3380 if (gsm->dead) { in gsm_config()
3384 if (gsm->initiator) in gsm_config()
3385 gsm_dlci_begin_open(gsm->dlci[0]); in gsm_config()
3394 ce->wait_config = gsm->wait_config ? 1 : 0; in gsm_copy_config_ext_values()
3395 ce->keep_alive = gsm->keep_alive; in gsm_copy_config_ext_values()
3407 for (i = 0; i < ARRAY_SIZE(ce->reserved); i++) in gsm_config_ext()
3408 if (ce->reserved[i]) in gsm_config_ext()
3409 return -EINVAL; in gsm_config_ext()
3410 if (ce->flags & ~GSM_FL_RESTART) in gsm_config_ext()
3411 return -EINVAL; in gsm_config_ext()
3414 if (ce->flags & GSM_FL_RESTART) in gsm_config_ext()
3428 gsm->wait_config = ce->wait_config ? true : false; in gsm_config_ext()
3429 gsm->keep_alive = ce->keep_alive; in gsm_config_ext()
3431 if (gsm->dead) { in gsm_config_ext()
3435 if (gsm->initiator) in gsm_config_ext()
3436 gsm_dlci_begin_open(gsm->dlci[0]); in gsm_config_ext()
3443 * gsmld_output - write to link
3444 * @gsm: our mux
3448 * Write a block of data from the GSM mux to the data channel. This
3454 if (tty_write_room(gsm->tty) < len) { in gsmld_output()
3455 set_bit(TTY_DO_WRITE_WAKEUP, &gsm->tty->flags); in gsmld_output()
3456 return -ENOSPC; in gsmld_output()
3460 return gsm->tty->ops->write(gsm->tty, data, len); in gsmld_output()
3465 * gsmld_write_trigger - schedule ldisc write task
3466 * @gsm: our mux
3470 if (!gsm || !gsm->dlci[0] || gsm->dlci[0]->dead) in gsmld_write_trigger()
3472 schedule_work(&gsm->tx_work); in gsmld_write_trigger()
3477 * gsmld_write_task - ldisc write task
3481 * avoid dead-locking. This returns if no space or data is left for output.
3492 ret = -ENODEV; in gsmld_write_task()
3493 spin_lock_irqsave(&gsm->tx_lock, flags); in gsmld_write_task()
3494 if (gsm->tty) in gsmld_write_task()
3496 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsmld_write_task()
3500 if (gsm->dlci[i]) in gsmld_write_task()
3501 tty_port_tty_wakeup(&gsm->dlci[i]->port); in gsmld_write_task()
3505 * gsmld_attach_gsm - mode set up
3507 * @gsm: our mux
3509 * Set up the MUX for basic mode and commence connecting to the
3516 gsm->tty = tty_kref_get(tty); in gsmld_attach_gsm()
3518 gsm->old_c_iflag = tty->termios.c_iflag; in gsmld_attach_gsm()
3519 tty->termios.c_iflag &= (IXON | IXOFF); in gsmld_attach_gsm()
3523 * gsmld_detach_gsm - stop doing 0710 mux
3524 * @tty: tty attached to the mux
3525 * @gsm: mux
3532 WARN_ON(tty != gsm->tty); in gsmld_detach_gsm()
3534 gsm->tty->termios.c_iflag = gsm->old_c_iflag; in gsmld_detach_gsm()
3535 tty_kref_put(gsm->tty); in gsmld_detach_gsm()
3536 gsm->tty = NULL; in gsmld_detach_gsm()
3542 struct gsm_mux *gsm = tty->disc_data; in gsmld_receive_buf()
3548 for (; count; count--, cp++) { in gsmld_receive_buf()
3553 if (gsm->receive) in gsmld_receive_buf()
3554 gsm->receive(gsm, *cp); in gsmld_receive_buf()
3573 * gsmld_flush_buffer - clean input queue
3586 * gsmld_close - close the ldisc for this tty
3597 struct gsm_mux *gsm = tty->disc_data; in gsmld_close()
3613 * gsmld_open - open an ldisc
3627 return -EPERM; in gsmld_open()
3629 if (tty->ops->write == NULL) in gsmld_open()
3630 return -EINVAL; in gsmld_open()
3635 return -ENOMEM; in gsmld_open()
3637 tty->disc_data = gsm; in gsmld_open()
3638 tty->receive_room = 65536; in gsmld_open()
3643 /* The mux will not be activated yet, we wait for correct in gsmld_open()
3646 if (gsm->encoding == GSM_BASIC_OPT) in gsmld_open()
3647 gsm->receive = gsm0_receive; in gsmld_open()
3649 gsm->receive = gsm1_receive; in gsmld_open()
3655 * gsmld_write_wakeup - asynchronous I/O notifier
3665 struct gsm_mux *gsm = tty->disc_data; in gsmld_write_wakeup()
3672 * gsmld_read - read function for tty
3691 return -EOPNOTSUPP; in gsmld_read()
3695 * gsmld_write - write function for tty
3703 * as-is and must be properly framed and checksummed as appropriate
3711 struct gsm_mux *gsm = tty->disc_data; in gsmld_write()
3717 return -ENODEV; in gsmld_write()
3719 ret = -ENOBUFS; in gsmld_write()
3720 spin_lock_irqsave(&gsm->tx_lock, flags); in gsmld_write()
3723 ret = tty->ops->write(tty, buf, nr); in gsmld_write()
3725 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in gsmld_write()
3726 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsmld_write()
3732 * gsmld_poll - poll method for N_GSM0710
3742 * Called without the kernel lock held - fine
3749 struct gsm_mux *gsm = tty->disc_data; in gsmld_poll()
3751 poll_wait(file, &tty->read_wait, wait); in gsmld_poll()
3752 poll_wait(file, &tty->write_wait, wait); in gsmld_poll()
3754 if (gsm->dead) in gsmld_poll()
3758 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) in gsmld_poll()
3771 struct gsm_mux *gsm = tty->disc_data; in gsmld_ioctl()
3779 return -EFAULT; in gsmld_ioctl()
3783 return -EFAULT; in gsmld_ioctl()
3791 return -EFAULT; in gsmld_ioctl()
3795 return -EFAULT; in gsmld_ioctl()
3799 return -EFAULT; in gsmld_ioctl()
3801 return -EINVAL; in gsmld_ioctl()
3803 dlci = gsm->dlci[addr]; in gsmld_ioctl()
3807 return -ENOMEM; in gsmld_ioctl()
3811 return -EFAULT; in gsmld_ioctl()
3815 return -EFAULT; in gsmld_ioctl()
3817 return -EINVAL; in gsmld_ioctl()
3819 dlci = gsm->dlci[addr]; in gsmld_ioctl()
3823 return -ENOMEM; in gsmld_ioctl()
3851 if (!dlci->net) { in dlci_net_free()
3855 dlci->adaption = dlci->prev_adaption; in dlci_net_free()
3856 dlci->data = dlci->prev_data; in dlci_net_free()
3857 free_netdev(dlci->net); in dlci_net_free()
3858 dlci->net = NULL; in dlci_net_free()
3866 dlci = mux_net->dlci; in net_free()
3868 if (dlci->net) { in net_free()
3869 unregister_netdev(dlci->net); in net_free()
3876 kref_get(&mux_net->ref); in muxnet_get()
3881 kref_put(&mux_net->ref, net_free); in muxnet_put()
3888 struct gsm_dlci *dlci = mux_net->dlci; in gsm_mux_net_start_xmit()
3891 skb_queue_head(&dlci->skb_list, skb); in gsm_mux_net_start_xmit()
3892 net->stats.tx_packets++; in gsm_mux_net_start_xmit()
3893 net->stats.tx_bytes += skb->len; in gsm_mux_net_start_xmit()
3905 dev_dbg(&net->dev, "Tx timed out.\n"); in gsm_mux_net_tx_timeout()
3908 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()