Lines Matching +full:mux +full:- +full:int +full:- +full:port
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
27 * Use newest tty open/close port helpers and install hooks
30 * Do we need a 'which mux are you' ioctl to correlate mux and tty sets
67 static int debug;
68 module_param(debug, int, 0600);
96 * Semi-arbitrary buffer size limits. 0710 is normally run with 32-64 byte
107 * struct gsm_mux_net - network interface
126 unsigned int len; /* Length of data block (can be zero) */
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
157 int addr;
165 int retries;
167 struct tty_port port; /* The tty bound to this DLCI if there is one */ member
170 int adaption; /* Adaption layer in use */
171 int prev_adaption;
174 unsigned int mtu;
175 bool dead; /* Refuse re-open */
187 void (*data)(struct gsm_dlci *dlci, const u8 *data, int len);
188 void (*prev_data)(struct gsm_dlci *dlci, const u8 *data, int len);
236 int len; /* Length of block for retransmission */
237 int done; /* Done flag */
238 int error; /* Error if any */
263 * Each GSM mux we have is represented by this structure. If we are
266 * to the gsm mux array. For now we don't free DLCI objects that
267 * have been instantiated until the mux itself is terminated.
269 * To consider further: tty open versus mux shutdown.
276 unsigned int num;
290 unsigned int len;
291 unsigned int address;
292 unsigned int count;
303 unsigned int mru;
304 unsigned int mtu;
305 int initiator; /* Did we initiate connection */
306 bool dead; /* Has the mux been shut down */
308 int old_c_iflag; /* termios c_iflag value before attach */
313 unsigned int tx_bytes; /* TX data outstanding */
322 int cretries; /* Command retry counter */
326 /* Keep-alive */
327 struct timer_list ka_timer; /* Keep-alive response timer */
328 u8 ka_num; /* Keep-alive match pattern */
329 signed int ka_retries; /* Keep-alive retry counter, -1 if not yet initialized */
332 int adaption; /* 1 or 2 supported */
334 int t1, t2; /* Timers in 1/100th of a sec */
335 unsigned int t3; /* Power wake-up timer in seconds. */
336 int n2; /* Retry count */
339 u32 keep_alive; /* Control channel keep-alive in 10ms */
352 * Mux objects - needed so that we can translate a tty index into the
353 * relevant mux and DLCI.
456 static int gsmld_output(struct gsm_mux *gsm, u8 *data, int len);
457 static int gsm_modem_update(struct gsm_dlci *dlci, u8 brk);
458 static struct gsm_msg *gsm_data_alloc(struct gsm_mux *gsm, u8 addr, int len,
460 static int gsm_send_packet(struct gsm_mux *gsm, struct gsm_msg *msg);
461 static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr);
466 * gsm_fcs_add - update FCS
480 * gsm_fcs_add_block - update FCS for a block
489 static inline u8 gsm_fcs_add_block(u8 fcs, u8 *c, int len) in gsm_fcs_add_block()
491 while (len--) in gsm_fcs_add_block()
497 * gsm_read_ea - read a byte into an EA
505 static int gsm_read_ea(unsigned int *val, u8 c) in gsm_read_ea()
515 * gsm_read_ea_val - read a value until EA
523 static unsigned int gsm_read_ea_val(unsigned int *val, const u8 *data, int dlen) in gsm_read_ea_val()
525 unsigned int len = 0; in gsm_read_ea_val()
527 for (; dlen > 0; dlen--) { in gsm_read_ea_val()
536 * gsm_encode_modem - encode modem data bits
547 if (dlci->throttled) in gsm_encode_modem()
549 if (dlci->modem_tx & TIOCM_DTR) in gsm_encode_modem()
551 if (dlci->modem_tx & TIOCM_RTS) in gsm_encode_modem()
553 if (dlci->modem_tx & TIOCM_RI) in gsm_encode_modem()
555 if (dlci->modem_tx & TIOCM_CD || dlci->gsm->initiator) in gsm_encode_modem()
558 if (dlci->modem_tx & TIOCM_OUT1) in gsm_encode_modem()
560 if (dlci->modem_tx & TIOCM_OUT2) in gsm_encode_modem()
585 * gsm_encode_params - encode DLCI parameters
592 static int gsm_encode_params(const struct gsm_dlci *dlci, in gsm_encode_params()
595 const struct gsm_mux *gsm = dlci->gsm; in gsm_encode_params()
596 unsigned int i, cl; in gsm_encode_params()
598 switch (dlci->ftype) { in gsm_encode_params()
606 pr_debug("unsupported frame type %d\n", dlci->ftype); in gsm_encode_params()
607 return -EINVAL; in gsm_encode_params()
610 switch (dlci->adaption) { in gsm_encode_params()
618 pr_debug("unsupported adaption %d\n", dlci->adaption); in gsm_encode_params()
619 return -EINVAL; in gsm_encode_params()
622 params->d_bits = FIELD_PREP(PN_D_FIELD_DLCI, dlci->addr); in gsm_encode_params()
624 params->i_cl_bits = FIELD_PREP(PN_I_CL_FIELD_FTYPE, i) | in gsm_encode_params()
626 params->p_bits = FIELD_PREP(PN_P_FIELD_PRIO, dlci->prio); in gsm_encode_params()
627 params->t_bits = FIELD_PREP(PN_T_FIELD_T1, gsm->t1); in gsm_encode_params()
628 params->n_bits = cpu_to_le16(FIELD_PREP(PN_N_FIELD_N1, dlci->mtu)); in gsm_encode_params()
629 params->na_bits = FIELD_PREP(PN_NA_FIELD_N2, gsm->n2); in gsm_encode_params()
630 params->k_bits = FIELD_PREP(PN_K_FIELD_K, dlci->k); in gsm_encode_params()
636 * gsm_register_devices - register all tty devices for a given mux index
639 * @index: the mux number is used to calculate the minor numbers of the
640 * ttys for this mux and may differ from the position in the
641 * mux array.
643 static int gsm_register_devices(struct tty_driver *driver, unsigned int index) in gsm_register_devices()
646 int i; in gsm_register_devices()
647 unsigned int base; in gsm_register_devices()
650 return -EINVAL; in gsm_register_devices()
654 /* Don't register device 0 - this is the control channel in gsm_register_devices()
662 for (i--; i >= 1; i--) in gsm_register_devices()
672 * gsm_unregister_devices - unregister all tty devices for a given mux index
675 * @index: the mux number is used to calculate the minor numbers of the
676 * ttys for this mux and may differ from the position in the
677 * mux array.
680 unsigned int index) in gsm_unregister_devices()
682 int i; in gsm_unregister_devices()
683 unsigned int base; in gsm_unregister_devices()
690 /* Don't unregister device 0 - this is the control in gsm_unregister_devices()
698 * gsm_print_packet - display a frame for debug
707 * style is based on amateur radio LAP-B dump display.
710 static void gsm_print_packet(const char *hdr, int addr, int cr, in gsm_print_packet()
711 u8 control, const u8 *data, int dlen) in gsm_print_packet()
774 * gsm_stuff_frame - bytestuff a packet
784 static int gsm_stuff_frame(const u8 *input, u8 *output, int len) in gsm_stuff_frame()
786 int olen = 0; in gsm_stuff_frame()
787 while (len--) { in gsm_stuff_frame()
802 * gsm_send - send a control frame
803 * @gsm: our GSM mux
811 static int gsm_send(struct gsm_mux *gsm, int addr, int cr, int control) in gsm_send()
815 int ocr; in gsm_send()
820 return -ENOMEM; in gsm_send()
823 ocr = cr ^ (gsm->initiator ? 0 : 1); in gsm_send()
825 msg->data -= 3; in gsm_send()
826 dp = msg->data; in gsm_send()
830 if (gsm->encoding == GSM_BASIC_OPT) in gsm_send()
833 *dp = 0xFF - gsm_fcs_add_block(INIT_FCS, msg->data, dp - msg->data); in gsm_send()
834 msg->len = (dp - msg->data) + 1; in gsm_send()
836 gsm_print_packet("Q->", addr, cr, control, NULL, 0); in gsm_send()
838 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_send()
839 list_add_tail(&msg->list, &gsm->tx_ctrl_list); in gsm_send()
840 gsm->tx_bytes += msg->len; in gsm_send()
841 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_send()
848 * gsm_dlci_clear_queues - remove outstanding data for a DLCI
849 * @gsm: mux
857 int addr = dlci->addr; in gsm_dlci_clear_queues()
861 spin_lock_irqsave(&dlci->lock, flags); in gsm_dlci_clear_queues()
862 kfifo_reset(&dlci->fifo); in gsm_dlci_clear_queues()
863 spin_unlock_irqrestore(&dlci->lock, flags); in gsm_dlci_clear_queues()
865 /* Clear data packets in MUX write queue */ in gsm_dlci_clear_queues()
866 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_dlci_clear_queues()
867 list_for_each_entry_safe(msg, nmsg, &gsm->tx_data_list, list) { in gsm_dlci_clear_queues()
868 if (msg->addr != addr) in gsm_dlci_clear_queues()
870 gsm->tx_bytes -= msg->len; in gsm_dlci_clear_queues()
871 list_del(&msg->list); in gsm_dlci_clear_queues()
874 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_dlci_clear_queues()
878 * gsm_response - send a control response
879 * @gsm: our GSM mux
886 static inline void gsm_response(struct gsm_mux *gsm, int addr, int control) in gsm_response()
892 * gsm_command - send a control command
893 * @gsm: our GSM mux
900 static inline void gsm_command(struct gsm_mux *gsm, int addr, int control) in gsm_command()
910 * gsm_data_alloc - allocate data frame
911 * @gsm: GSM mux
921 static struct gsm_msg *gsm_data_alloc(struct gsm_mux *gsm, u8 addr, int len, in gsm_data_alloc()
928 m->data = m->buffer + HDR_LEN - 1; /* Allow for FCS */ in gsm_data_alloc()
929 m->len = len; in gsm_data_alloc()
930 m->addr = addr; in gsm_data_alloc()
931 m->ctrl = ctrl; in gsm_data_alloc()
932 INIT_LIST_HEAD(&m->list); in gsm_data_alloc()
937 * gsm_send_packet - sends a single packet
938 * @gsm: GSM Mux
944 static int gsm_send_packet(struct gsm_mux *gsm, struct gsm_msg *msg) in gsm_send_packet()
946 int len, ret; in gsm_send_packet()
949 if (gsm->encoding == GSM_BASIC_OPT) { in gsm_send_packet()
950 gsm->txframe[0] = GSM0_SOF; in gsm_send_packet()
951 memcpy(gsm->txframe + 1, msg->data, msg->len); in gsm_send_packet()
952 gsm->txframe[msg->len + 1] = GSM0_SOF; in gsm_send_packet()
953 len = msg->len + 2; in gsm_send_packet()
955 gsm->txframe[0] = GSM1_SOF; in gsm_send_packet()
956 len = gsm_stuff_frame(msg->data, gsm->txframe + 1, msg->len); in gsm_send_packet()
957 gsm->txframe[len + 1] = GSM1_SOF; in gsm_send_packet()
962 gsm_hex_dump_bytes(__func__, gsm->txframe, len); in gsm_send_packet()
963 gsm_print_packet("-->", msg->addr, gsm->initiator, msg->ctrl, msg->data, in gsm_send_packet()
964 msg->len); in gsm_send_packet()
966 ret = gsmld_output(gsm, gsm->txframe, len); in gsm_send_packet()
970 gsm->tx_bytes -= msg->len; in gsm_send_packet()
976 * gsm_is_flow_ctrl_msg - checks if flow control message
984 unsigned int cmd; in gsm_is_flow_ctrl_msg()
986 if (msg->addr > 0) in gsm_is_flow_ctrl_msg()
989 switch (msg->ctrl & ~PF) { in gsm_is_flow_ctrl_msg()
993 if (gsm_read_ea_val(&cmd, msg->data + 2, msg->len - 2) < 1) in gsm_is_flow_ctrl_msg()
1007 * gsm_data_kick - poke the queue
1008 * @gsm: GSM Mux
1012 * If we have been flow-stopped by a CMD_FCOFF, then we can only
1016 static int gsm_data_kick(struct gsm_mux *gsm) in gsm_data_kick()
1020 int ret; in gsm_data_kick()
1022 clear_bit(TTY_DO_WRITE_WAKEUP, &gsm->tty->flags); in gsm_data_kick()
1025 list_for_each_entry_safe(msg, nmsg, &gsm->tx_ctrl_list, list) { in gsm_data_kick()
1026 if (gsm->constipated && !gsm_is_flow_ctrl_msg(msg)) in gsm_data_kick()
1030 case -ENOSPC: in gsm_data_kick()
1031 return -ENOSPC; in gsm_data_kick()
1032 case -ENODEV: in gsm_data_kick()
1034 gsm->tx_bytes -= msg->len; in gsm_data_kick()
1035 list_del(&msg->list); in gsm_data_kick()
1040 list_del(&msg->list); in gsm_data_kick()
1047 if (gsm->constipated) in gsm_data_kick()
1048 return -EAGAIN; in gsm_data_kick()
1051 if (list_empty(&gsm->tx_data_list)) in gsm_data_kick()
1053 list_for_each_entry_safe(msg, nmsg, &gsm->tx_data_list, list) { in gsm_data_kick()
1054 dlci = gsm->dlci[msg->addr]; in gsm_data_kick()
1056 if (dlci->state != DLCI_OPEN) { in gsm_data_kick()
1057 gsm->tx_bytes -= msg->len; in gsm_data_kick()
1058 list_del(&msg->list); in gsm_data_kick()
1064 case -ENOSPC: in gsm_data_kick()
1065 return -ENOSPC; in gsm_data_kick()
1066 case -ENODEV: in gsm_data_kick()
1068 gsm->tx_bytes -= msg->len; in gsm_data_kick()
1069 list_del(&msg->list); in gsm_data_kick()
1074 list_del(&msg->list); in gsm_data_kick()
1085 * __gsm_data_queue - queue a UI or UIH frame
1090 * out of the mux tty if not already doing so. The Caller must hold
1096 struct gsm_mux *gsm = dlci->gsm; in __gsm_data_queue()
1097 u8 *dp = msg->data; in __gsm_data_queue()
1098 u8 *fcs = dp + msg->len; in __gsm_data_queue()
1101 if (gsm->encoding == GSM_BASIC_OPT) { in __gsm_data_queue()
1102 if (msg->len < 128) in __gsm_data_queue()
1103 *--dp = (msg->len << 1) | EA; in __gsm_data_queue()
1105 *--dp = (msg->len >> 7); /* bits 7 - 15 */ in __gsm_data_queue()
1106 *--dp = (msg->len & 127) << 1; /* bits 0 - 6 */ in __gsm_data_queue()
1110 *--dp = msg->ctrl; in __gsm_data_queue()
1111 if (gsm->initiator) in __gsm_data_queue()
1112 *--dp = (msg->addr << 2) | CR | EA; in __gsm_data_queue()
1114 *--dp = (msg->addr << 2) | EA; in __gsm_data_queue()
1115 *fcs = gsm_fcs_add_block(INIT_FCS, dp , msg->data - dp); in __gsm_data_queue()
1117 if (msg->ctrl == UI || msg->ctrl == (UI|PF)) in __gsm_data_queue()
1118 *fcs = gsm_fcs_add_block(*fcs, msg->data, msg->len); in __gsm_data_queue()
1119 *fcs = 0xFF - *fcs; in __gsm_data_queue()
1121 gsm_print_packet("Q> ", msg->addr, gsm->initiator, msg->ctrl, in __gsm_data_queue()
1122 msg->data, msg->len); in __gsm_data_queue()
1126 msg->len += (msg->data - dp) + 1; in __gsm_data_queue()
1127 msg->data = dp; in __gsm_data_queue()
1130 switch (msg->ctrl & ~PF) { in __gsm_data_queue()
1133 if (msg->addr > 0) { in __gsm_data_queue()
1134 list_add_tail(&msg->list, &gsm->tx_data_list); in __gsm_data_queue()
1139 list_add_tail(&msg->list, &gsm->tx_ctrl_list); in __gsm_data_queue()
1142 gsm->tx_bytes += msg->len; in __gsm_data_queue()
1145 mod_timer(&gsm->kick_timer, jiffies + 10 * gsm->t1 * HZ / 100); in __gsm_data_queue()
1149 * gsm_data_queue - queue a UI or UIH frame
1154 * out of the mux tty if not already doing so. Take the
1161 spin_lock_irqsave(&dlci->gsm->tx_lock, flags); in gsm_data_queue()
1163 spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags); in gsm_data_queue()
1167 * gsm_dlci_data_output - try and push data out of a DLCI
1168 * @gsm: mux
1172 * is data. Keep to the MRU of the mux. This path handles the usual tty
1175 * Caller must hold the tx_lock of the mux.
1178 static int gsm_dlci_data_output(struct gsm_mux *gsm, struct gsm_dlci *dlci) in gsm_dlci_data_output()
1182 int h, len, size; in gsm_dlci_data_output()
1185 h = ((dlci->adaption == 1) ? 0 : 1); in gsm_dlci_data_output()
1187 len = kfifo_len(&dlci->fifo); in gsm_dlci_data_output()
1192 if ((len + h) > dlci->mtu) in gsm_dlci_data_output()
1193 len = dlci->mtu - h; in gsm_dlci_data_output()
1197 msg = gsm_data_alloc(gsm, dlci->addr, size, dlci->ftype); in gsm_dlci_data_output()
1199 return -ENOMEM; in gsm_dlci_data_output()
1200 dp = msg->data; in gsm_dlci_data_output()
1201 switch (dlci->adaption) { in gsm_dlci_data_output()
1211 dlci->adaption); in gsm_dlci_data_output()
1215 WARN_ON(len != kfifo_out_locked(&dlci->fifo, dp, len, in gsm_dlci_data_output()
1216 &dlci->lock)); in gsm_dlci_data_output()
1219 tty_port_tty_wakeup(&dlci->port); in gsm_dlci_data_output()
1227 * gsm_dlci_data_output_framed - try and push data out of a DLCI
1228 * @gsm: mux
1232 * is data. Keep to the MRU of the mux. This path handles framed data
1235 * Caller must hold the tx_lock of the mux.
1238 static int gsm_dlci_data_output_framed(struct gsm_mux *gsm, in gsm_dlci_data_output_framed()
1243 int len, size; in gsm_dlci_data_output_framed()
1244 int last = 0, first = 0; in gsm_dlci_data_output_framed()
1245 int overhead = 0; in gsm_dlci_data_output_framed()
1248 if (dlci->adaption == 4) in gsm_dlci_data_output_framed()
1251 /* dlci->skb is locked by tx_lock */ in gsm_dlci_data_output_framed()
1252 if (dlci->skb == NULL) { in gsm_dlci_data_output_framed()
1253 dlci->skb = skb_dequeue_tail(&dlci->skb_list); in gsm_dlci_data_output_framed()
1254 if (dlci->skb == NULL) in gsm_dlci_data_output_framed()
1258 len = dlci->skb->len + overhead; in gsm_dlci_data_output_framed()
1261 if (len > dlci->mtu) { in gsm_dlci_data_output_framed()
1262 if (dlci->adaption == 3) { in gsm_dlci_data_output_framed()
1264 dev_kfree_skb_any(dlci->skb); in gsm_dlci_data_output_framed()
1265 dlci->skb = NULL; in gsm_dlci_data_output_framed()
1268 len = dlci->mtu; in gsm_dlci_data_output_framed()
1273 msg = gsm_data_alloc(gsm, dlci->addr, size, dlci->ftype); in gsm_dlci_data_output_framed()
1275 skb_queue_tail(&dlci->skb_list, dlci->skb); in gsm_dlci_data_output_framed()
1276 dlci->skb = NULL; in gsm_dlci_data_output_framed()
1277 return -ENOMEM; in gsm_dlci_data_output_framed()
1279 dp = msg->data; in gsm_dlci_data_output_framed()
1281 if (dlci->adaption == 4) { /* Interruptible framed (Packetised Data) */ in gsm_dlci_data_output_framed()
1284 len--; in gsm_dlci_data_output_framed()
1286 memcpy(dp, dlci->skb->data, len); in gsm_dlci_data_output_framed()
1287 skb_pull(dlci->skb, len); in gsm_dlci_data_output_framed()
1290 dev_kfree_skb_any(dlci->skb); in gsm_dlci_data_output_framed()
1291 dlci->skb = NULL; in gsm_dlci_data_output_framed()
1297 * gsm_dlci_modem_output - try and push modem status out of a DLCI
1298 * @gsm: mux
1305 * Caller must hold the tx_lock of the mux.
1308 static int gsm_dlci_modem_output(struct gsm_mux *gsm, struct gsm_dlci *dlci, in gsm_dlci_modem_output()
1313 int size = 0; in gsm_dlci_modem_output()
1316 switch (dlci->adaption) { in gsm_dlci_modem_output()
1326 dlci->adaption); in gsm_dlci_modem_output()
1327 return -EINVAL; in gsm_dlci_modem_output()
1330 msg = gsm_data_alloc(gsm, dlci->addr, size, dlci->ftype); in gsm_dlci_modem_output()
1333 return -ENOMEM; in gsm_dlci_modem_output()
1335 dp = msg->data; in gsm_dlci_modem_output()
1336 switch (dlci->adaption) { in gsm_dlci_modem_output()
1357 * gsm_dlci_data_sweep - look for data to send
1358 * @gsm: the GSM mux
1360 * Sweep the GSM mux channels in priority order looking for ones with
1369 static int gsm_dlci_data_sweep(struct gsm_mux *gsm) in gsm_dlci_data_sweep()
1372 int i, len, ret = 0; in gsm_dlci_data_sweep()
1376 while (gsm->tx_bytes < TX_THRESH_HI) { in gsm_dlci_data_sweep()
1378 dlci = gsm->dlci[i]; in gsm_dlci_data_sweep()
1380 if (!dlci || dlci->constipated) in gsm_dlci_data_sweep()
1383 if (dlci->state != DLCI_OPEN) in gsm_dlci_data_sweep()
1386 if (dlci->adaption < 3 && !dlci->net) in gsm_dlci_data_sweep()
1409 * gsm_dlci_data_kick - transmit if possible
1420 int sweep; in gsm_dlci_data_kick()
1422 if (dlci->constipated) in gsm_dlci_data_kick()
1425 spin_lock_irqsave(&dlci->gsm->tx_lock, flags); in gsm_dlci_data_kick()
1427 sweep = (dlci->gsm->tx_bytes < TX_THRESH_LO); in gsm_dlci_data_kick()
1428 if (dlci->gsm->tx_bytes == 0) { in gsm_dlci_data_kick()
1429 if (dlci->net) in gsm_dlci_data_kick()
1430 gsm_dlci_data_output_framed(dlci->gsm, dlci); in gsm_dlci_data_kick()
1432 gsm_dlci_data_output(dlci->gsm, dlci); in gsm_dlci_data_kick()
1435 gsm_dlci_data_sweep(dlci->gsm); in gsm_dlci_data_kick()
1436 spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags); in gsm_dlci_data_kick()
1445 * gsm_control_command - send a command frame to a control
1453 static int gsm_control_command(struct gsm_mux *gsm, int cmd, const u8 *data, in gsm_control_command()
1454 int dlen) in gsm_control_command()
1457 struct gsm_dlci *dlci = gsm->dlci[0]; in gsm_control_command()
1459 msg = gsm_data_alloc(gsm, 0, dlen + 2, dlci->ftype); in gsm_control_command()
1461 return -ENOMEM; in gsm_control_command()
1463 msg->data[0] = (cmd << 1) | CR | EA; /* Set C/R */ in gsm_control_command()
1464 msg->data[1] = (dlen << 1) | EA; in gsm_control_command()
1465 memcpy(msg->data + 2, data, dlen); in gsm_control_command()
1472 * gsm_control_reply - send a response frame to a control
1481 static void gsm_control_reply(struct gsm_mux *gsm, int cmd, const u8 *data, in gsm_control_reply()
1482 int dlen) in gsm_control_reply()
1485 struct gsm_dlci *dlci = gsm->dlci[0]; in gsm_control_reply()
1487 msg = gsm_data_alloc(gsm, 0, dlen + 2, dlci->ftype); in gsm_control_reply()
1490 msg->data[0] = (cmd & 0xFE) << 1 | EA; /* Clear C/R */ in gsm_control_reply()
1491 msg->data[1] = (dlen << 1) | EA; in gsm_control_reply()
1492 memcpy(msg->data + 2, data, dlen); in gsm_control_reply()
1497 * gsm_process_modem - process received modem status
1508 u32 modem, int slen) in gsm_process_modem()
1510 int mlines = 0; in gsm_process_modem()
1512 int fc; in gsm_process_modem()
1516 * section 5.4.6.3.7 of the 07.10 mux spec. in gsm_process_modem()
1528 if (fc && !dlci->constipated) { in gsm_process_modem()
1530 dlci->constipated = true; in gsm_process_modem()
1531 } else if (!fc && dlci->constipated) { in gsm_process_modem()
1532 dlci->constipated = false; in gsm_process_modem()
1546 /* Carrier drop -> hangup */ in gsm_process_modem()
1548 if ((mlines & TIOCM_CD) == 0 && (dlci->modem_rx & TIOCM_CD)) in gsm_process_modem()
1553 tty_insert_flip_char(&dlci->port, 0, TTY_BREAK); in gsm_process_modem()
1554 dlci->modem_rx = mlines; in gsm_process_modem()
1555 wake_up_interruptible(&dlci->gsm->event); in gsm_process_modem()
1559 * gsm_process_negotiation - process received parameters
1568 static int gsm_process_negotiation(struct gsm_mux *gsm, unsigned int addr, in gsm_process_negotiation()
1569 unsigned int cr, in gsm_process_negotiation()
1572 struct gsm_dlci *dlci = gsm->dlci[addr]; in gsm_process_negotiation()
1573 unsigned int ftype, i, adaption, prio, n1, k; in gsm_process_negotiation()
1575 i = FIELD_GET(PN_I_CL_FIELD_FTYPE, params->i_cl_bits); in gsm_process_negotiation()
1576 adaption = FIELD_GET(PN_I_CL_FIELD_ADAPTION, params->i_cl_bits) + 1; in gsm_process_negotiation()
1577 prio = FIELD_GET(PN_P_FIELD_PRIO, params->p_bits); in gsm_process_negotiation()
1578 n1 = FIELD_GET(PN_N_FIELD_N1, get_unaligned_le16(¶ms->n_bits)); in gsm_process_negotiation()
1579 k = FIELD_GET(PN_K_FIELD_K, params->k_bits); in gsm_process_negotiation()
1584 return -EINVAL; in gsm_process_negotiation()
1598 gsm->unsupported++; in gsm_process_negotiation()
1599 return -EINVAL; in gsm_process_negotiation()
1603 return -EINVAL; in gsm_process_negotiation()
1606 if (!cr && gsm->initiator) { in gsm_process_negotiation()
1607 if (adaption != dlci->adaption) { in gsm_process_negotiation()
1611 return -EINVAL; in gsm_process_negotiation()
1613 if (prio != dlci->prio) { in gsm_process_negotiation()
1617 return -EINVAL; in gsm_process_negotiation()
1619 if (n1 > gsm->mru || n1 > dlci->mtu) { in gsm_process_negotiation()
1627 return -EINVAL; in gsm_process_negotiation()
1629 dlci->mtu = n1; in gsm_process_negotiation()
1630 if (ftype != dlci->ftype) { in gsm_process_negotiation()
1633 return -EINVAL; in gsm_process_negotiation()
1635 if (ftype != UI && ftype != UIH && k > dlci->k) { in gsm_process_negotiation()
1638 return -EINVAL; in gsm_process_negotiation()
1640 dlci->k = k; in gsm_process_negotiation()
1641 } else if (cr && !gsm->initiator) { in gsm_process_negotiation()
1647 return -EINVAL; in gsm_process_negotiation()
1649 dlci->adaption = adaption; in gsm_process_negotiation()
1650 if (n1 > gsm->mru) { in gsm_process_negotiation()
1652 dlci->mtu = gsm->mru; in gsm_process_negotiation()
1655 dlci->mtu = MAX_MTU; in gsm_process_negotiation()
1657 dlci->mtu = n1; in gsm_process_negotiation()
1659 dlci->prio = prio; in gsm_process_negotiation()
1660 dlci->ftype = ftype; in gsm_process_negotiation()
1661 dlci->k = k; in gsm_process_negotiation()
1663 return -EINVAL; in gsm_process_negotiation()
1670 * gsm_control_modem - modem status received
1676 * the GSM mux protocol to pass virtual modem line status and optionally
1681 static void gsm_control_modem(struct gsm_mux *gsm, const u8 *data, int clen) in gsm_control_modem()
1683 unsigned int addr = 0; in gsm_control_modem()
1684 unsigned int modem = 0; in gsm_control_modem()
1686 int len = clen; in gsm_control_modem()
1687 int cl = clen; in gsm_control_modem()
1696 /* Closed port, or invalid ? */ in gsm_control_modem()
1697 if (addr == 0 || addr >= NUM_DLCI || gsm->dlci[addr] == NULL) in gsm_control_modem()
1699 dlci = gsm->dlci[addr]; in gsm_control_modem()
1702 if ((cl - len) < 1) in gsm_control_modem()
1706 cl -= len; in gsm_control_modem()
1713 tty = tty_port_tty_get(&dlci->port); in gsm_control_modem()
1723 * gsm_control_negotiation - parameter negotiation received
1730 * the GSM mux protocol to configure protocol parameters for a new DLCI.
1732 static void gsm_control_negotiation(struct gsm_mux *gsm, unsigned int cr, in gsm_control_negotiation()
1733 const u8 *data, unsigned int dlen) in gsm_control_negotiation()
1735 unsigned int addr; in gsm_control_negotiation()
1741 gsm->open_error++; in gsm_control_negotiation()
1747 addr = FIELD_GET(PN_D_FIELD_DLCI, params->d_bits); in gsm_control_negotiation()
1748 if (addr == 0 || addr >= NUM_DLCI || !gsm->dlci[addr]) { in gsm_control_negotiation()
1749 gsm->open_error++; in gsm_control_negotiation()
1752 dlci = gsm->dlci[addr]; in gsm_control_negotiation()
1755 if ((!cr && dlci->state == DLCI_OPENING) || dlci->state == DLCI_OPEN) { in gsm_control_negotiation()
1756 gsm->open_error++; in gsm_control_negotiation()
1765 gsm->open_error++; in gsm_control_negotiation()
1777 } else if (dlci->state == DLCI_CONFIGURE) { in gsm_control_negotiation()
1779 dlci->state = DLCI_OPENING; in gsm_control_negotiation()
1780 gsm_command(gsm, dlci->addr, SABM|PF); in gsm_control_negotiation()
1781 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_control_negotiation()
1785 gsm->open_error++; in gsm_control_negotiation()
1790 * gsm_control_rls - remote line status
1800 static void gsm_control_rls(struct gsm_mux *gsm, const u8 *data, int clen) in gsm_control_rls()
1802 struct tty_port *port; in gsm_control_rls() local
1803 unsigned int addr = 0; in gsm_control_rls()
1805 int len = clen; in gsm_control_rls()
1809 len--; in gsm_control_rls()
1814 len--; in gsm_control_rls()
1818 /* Closed port, or invalid ? */ in gsm_control_rls()
1819 if (addr == 0 || addr >= NUM_DLCI || gsm->dlci[addr] == NULL) in gsm_control_rls()
1826 port = &gsm->dlci[addr]->port; in gsm_control_rls()
1829 tty_insert_flip_char(port, 0, TTY_OVERRUN); in gsm_control_rls()
1831 tty_insert_flip_char(port, 0, TTY_PARITY); in gsm_control_rls()
1833 tty_insert_flip_char(port, 0, TTY_FRAME); in gsm_control_rls()
1835 tty_flip_buffer_push(port); in gsm_control_rls()
1843 * gsm_control_message - DLCI 0 control processing
1844 * @gsm: our GSM mux
1854 static void gsm_control_message(struct gsm_mux *gsm, unsigned int command, in gsm_control_message()
1855 const u8 *data, int clen) in gsm_control_message()
1861 struct gsm_dlci *dlci = gsm->dlci[0]; in gsm_control_message()
1864 dlci->dead = true; in gsm_control_message()
1865 gsm->dead = true; in gsm_control_message()
1876 gsm->constipated = false; in gsm_control_message()
1883 gsm->constipated = true; in gsm_control_message()
1904 case CMD_RPN: /* Remote port negotiation */ in gsm_control_message()
1906 gsm->unsupported++; in gsm_control_message()
1917 * gsm_control_response - process a response to our control
1918 * @gsm: our GSM mux
1929 static void gsm_control_response(struct gsm_mux *gsm, unsigned int command, in gsm_control_response()
1930 const u8 *data, int clen) in gsm_control_response()
1936 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_response()
1938 ctrl = gsm->pending_cmd; in gsm_control_response()
1939 dlci = gsm->dlci[0]; in gsm_control_response()
1942 if (ctrl != NULL && (command == ctrl->cmd || command == CMD_NSC)) { in gsm_control_response()
1944 del_timer(&gsm->t2_timer); in gsm_control_response()
1945 gsm->pending_cmd = NULL; in gsm_control_response()
1948 ctrl->error = -EOPNOTSUPP; in gsm_control_response()
1949 ctrl->done = 1; in gsm_control_response()
1950 wake_up(&gsm->event); in gsm_control_response()
1955 } else if (command == CMD_TEST && clen == 1 && *data == gsm->ka_num) { in gsm_control_response()
1956 gsm->ka_retries = -1; /* trigger new keep-alive message */ in gsm_control_response()
1957 if (dlci && !dlci->dead) in gsm_control_response()
1958 mod_timer(&gsm->ka_timer, jiffies + gsm->keep_alive * HZ / 100); in gsm_control_response()
1960 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_response()
1964 * gsm_control_keep_alive - check timeout or start keep-alive
1967 * Called off the keep-alive timer expiry signaling that our link
1977 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_keep_alive()
1978 if (gsm->ka_num && gsm->ka_retries == 0) { in gsm_control_keep_alive()
1979 /* Keep-alive expired -> close the link */ in gsm_control_keep_alive()
1981 pr_debug("%s keep-alive timed out\n", __func__); in gsm_control_keep_alive()
1982 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_keep_alive()
1983 if (gsm->dlci[0]) in gsm_control_keep_alive()
1984 gsm_dlci_begin_close(gsm->dlci[0]); in gsm_control_keep_alive()
1986 } else if (gsm->keep_alive && gsm->dlci[0] && !gsm->dlci[0]->dead) { in gsm_control_keep_alive()
1987 if (gsm->ka_retries > 0) { in gsm_control_keep_alive()
1988 /* T2 expired for keep-alive -> resend */ in gsm_control_keep_alive()
1989 gsm->ka_retries--; in gsm_control_keep_alive()
1991 /* Start keep-alive timer */ in gsm_control_keep_alive()
1992 gsm->ka_num++; in gsm_control_keep_alive()
1993 if (!gsm->ka_num) in gsm_control_keep_alive()
1994 gsm->ka_num++; in gsm_control_keep_alive()
1995 gsm->ka_retries = (signed int)gsm->n2; in gsm_control_keep_alive()
1997 gsm_control_command(gsm, CMD_TEST, &gsm->ka_num, in gsm_control_keep_alive()
1998 sizeof(gsm->ka_num)); in gsm_control_keep_alive()
1999 mod_timer(&gsm->ka_timer, in gsm_control_keep_alive()
2000 jiffies + gsm->t2 * HZ / 100); in gsm_control_keep_alive()
2002 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_keep_alive()
2006 * gsm_control_transmit - send control packet
2007 * @gsm: gsm mux
2015 gsm_control_command(gsm, ctrl->cmd, ctrl->data, ctrl->len); in gsm_control_transmit()
2019 * gsm_control_retransmit - retransmit a control frame
2026 * gsm->pending_cmd will be NULL and we just let the timer expire.
2034 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_retransmit()
2035 ctrl = gsm->pending_cmd; in gsm_control_retransmit()
2037 if (gsm->cretries == 0 || !gsm->dlci[0] || gsm->dlci[0]->dead) { in gsm_control_retransmit()
2038 gsm->pending_cmd = NULL; in gsm_control_retransmit()
2039 ctrl->error = -ETIMEDOUT; in gsm_control_retransmit()
2040 ctrl->done = 1; in gsm_control_retransmit()
2041 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_retransmit()
2042 wake_up(&gsm->event); in gsm_control_retransmit()
2045 gsm->cretries--; in gsm_control_retransmit()
2047 mod_timer(&gsm->t2_timer, jiffies + gsm->t2 * HZ / 100); in gsm_control_retransmit()
2049 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_retransmit()
2053 * gsm_control_send - send a control frame on DLCI 0
2065 unsigned int command, u8 *data, int clen) in gsm_control_send()
2073 wait_event(gsm->event, gsm->pending_cmd == NULL); in gsm_control_send()
2074 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_send()
2075 if (gsm->pending_cmd != NULL) { in gsm_control_send()
2076 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_send()
2079 ctrl->cmd = command; in gsm_control_send()
2080 ctrl->data = data; in gsm_control_send()
2081 ctrl->len = clen; in gsm_control_send()
2082 gsm->pending_cmd = ctrl; in gsm_control_send()
2085 if (gsm->dlci[0]->mode == DLCI_MODE_ADM) in gsm_control_send()
2086 gsm->cretries = 0; in gsm_control_send()
2088 gsm->cretries = gsm->n2; in gsm_control_send()
2090 mod_timer(&gsm->t2_timer, jiffies + gsm->t2 * HZ / 100); in gsm_control_send()
2092 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_send()
2097 * gsm_control_wait - wait for a control to finish
2098 * @gsm: GSM mux
2106 static int gsm_control_wait(struct gsm_mux *gsm, struct gsm_control *control) in gsm_control_wait()
2108 int err; in gsm_control_wait()
2109 wait_event(gsm->event, control->done == 1); in gsm_control_wait()
2110 err = control->error; in gsm_control_wait()
2125 * gsm_dlci_close - a DLCI has closed
2134 del_timer(&dlci->t1); in gsm_dlci_close()
2136 pr_debug("DLCI %d goes closed.\n", dlci->addr); in gsm_dlci_close()
2137 dlci->state = DLCI_CLOSED; in gsm_dlci_close()
2139 dlci->constipated = true; in gsm_dlci_close()
2140 if (dlci->addr != 0) { in gsm_dlci_close()
2141 tty_port_tty_hangup(&dlci->port, false); in gsm_dlci_close()
2142 gsm_dlci_clear_queues(dlci->gsm, dlci); in gsm_dlci_close()
2144 tty_port_set_initialized(&dlci->port, false); in gsm_dlci_close()
2145 wake_up_interruptible(&dlci->port.open_wait); in gsm_dlci_close()
2147 del_timer(&dlci->gsm->ka_timer); in gsm_dlci_close()
2148 dlci->gsm->dead = true; in gsm_dlci_close()
2150 /* A DLCI 0 close is a MUX termination so we need to kick that in gsm_dlci_close()
2153 wake_up_all(&dlci->gsm->event); in gsm_dlci_close()
2157 * gsm_dlci_open - a DLCI has opened
2165 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_open()
2168 open -> open */ in gsm_dlci_open()
2169 del_timer(&dlci->t1); in gsm_dlci_open()
2171 dlci->state = DLCI_OPEN; in gsm_dlci_open()
2172 dlci->constipated = false; in gsm_dlci_open()
2174 pr_debug("DLCI %d goes open.\n", dlci->addr); in gsm_dlci_open()
2176 if (dlci->addr) { in gsm_dlci_open()
2179 /* Start keep-alive control */ in gsm_dlci_open()
2180 gsm->ka_num = 0; in gsm_dlci_open()
2181 gsm->ka_retries = -1; in gsm_dlci_open()
2182 mod_timer(&gsm->ka_timer, in gsm_dlci_open()
2183 jiffies + gsm->keep_alive * HZ / 100); in gsm_dlci_open()
2186 wake_up(&dlci->gsm->event); in gsm_dlci_open()
2190 * gsm_dlci_negotiate - start parameter negotiation
2196 static int gsm_dlci_negotiate(struct gsm_dlci *dlci) in gsm_dlci_negotiate()
2198 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_negotiate()
2200 int ret; in gsm_dlci_negotiate()
2216 * gsm_dlci_t1 - T1 timer expiry
2221 * in which case an opening port goes back to closed and a closing port
2233 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_t1()
2235 switch (dlci->state) { in gsm_dlci_t1()
2237 if (dlci->retries && gsm_dlci_negotiate(dlci) == 0) { in gsm_dlci_t1()
2238 dlci->retries--; in gsm_dlci_t1()
2239 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_t1()
2241 gsm->open_error++; in gsm_dlci_t1()
2246 if (dlci->retries) { in gsm_dlci_t1()
2247 dlci->retries--; in gsm_dlci_t1()
2248 gsm_command(dlci->gsm, dlci->addr, SABM|PF); in gsm_dlci_t1()
2249 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_t1()
2250 } else if (!dlci->addr && gsm->control == (DM | PF)) { in gsm_dlci_t1()
2253 dlci->addr); in gsm_dlci_t1()
2254 dlci->mode = DLCI_MODE_ADM; in gsm_dlci_t1()
2257 gsm->open_error++; in gsm_dlci_t1()
2263 if (dlci->retries) { in gsm_dlci_t1()
2264 dlci->retries--; in gsm_dlci_t1()
2265 gsm_command(dlci->gsm, dlci->addr, DISC|PF); in gsm_dlci_t1()
2266 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_t1()
2271 pr_debug("%s: unhandled state: %d\n", __func__, dlci->state); in gsm_dlci_t1()
2277 * gsm_dlci_begin_open - start channel open procedure
2289 struct gsm_mux *gsm = dlci ? dlci->gsm : NULL; in gsm_dlci_begin_open()
2295 if (dlci->addr != 0) { in gsm_dlci_begin_open()
2296 if (gsm->adaption != 1 || gsm->adaption != dlci->adaption) in gsm_dlci_begin_open()
2298 if (dlci->prio != (roundup(dlci->addr + 1, 8) - 1)) in gsm_dlci_begin_open()
2300 if (gsm->ftype != dlci->ftype) in gsm_dlci_begin_open()
2304 switch (dlci->state) { in gsm_dlci_begin_open()
2308 dlci->retries = gsm->n2; in gsm_dlci_begin_open()
2310 dlci->state = DLCI_OPENING; in gsm_dlci_begin_open()
2311 gsm_command(gsm, dlci->addr, SABM|PF); in gsm_dlci_begin_open()
2314 dlci->state = DLCI_CONFIGURE; in gsm_dlci_begin_open()
2320 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_begin_open()
2328 * gsm_dlci_set_opening - change state to opening
2336 switch (dlci->state) { in gsm_dlci_set_opening()
2340 dlci->state = DLCI_OPENING; in gsm_dlci_set_opening()
2348 * gsm_dlci_set_wait_config - wait for channel configuration
2355 switch (dlci->state) { in gsm_dlci_set_wait_config()
2358 dlci->state = DLCI_WAITING_CONFIG; in gsm_dlci_set_wait_config()
2366 * gsm_dlci_begin_close - start channel open procedure
2378 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_begin_close()
2379 if (dlci->state == DLCI_CLOSED || dlci->state == DLCI_CLOSING) in gsm_dlci_begin_close()
2381 dlci->retries = gsm->n2; in gsm_dlci_begin_close()
2382 dlci->state = DLCI_CLOSING; in gsm_dlci_begin_close()
2383 gsm_command(dlci->gsm, dlci->addr, DISC|PF); in gsm_dlci_begin_close()
2384 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_begin_close()
2385 wake_up_interruptible(&gsm->event); in gsm_dlci_begin_close()
2389 * gsm_dlci_data - data arrived
2399 static void gsm_dlci_data(struct gsm_dlci *dlci, const u8 *data, int clen) in gsm_dlci_data()
2402 struct tty_port *port = &dlci->port; in gsm_dlci_data() local
2404 unsigned int modem = 0; in gsm_dlci_data()
2405 int len; in gsm_dlci_data()
2409 switch (dlci->adaption) { in gsm_dlci_data()
2419 tty = tty_port_tty_get(port); in gsm_dlci_data()
2427 clen -= len; in gsm_dlci_data()
2431 tty_insert_flip_string(port, data, clen); in gsm_dlci_data()
2432 tty_flip_buffer_push(port); in gsm_dlci_data()
2437 * gsm_dlci_command - data arrived on control channel
2448 static void gsm_dlci_command(struct gsm_dlci *dlci, const u8 *data, int len) in gsm_dlci_command()
2451 unsigned int command = 0; in gsm_dlci_command()
2452 unsigned int clen = 0; in gsm_dlci_command()
2453 unsigned int dlen; in gsm_dlci_command()
2457 len -= dlen; in gsm_dlci_command()
2462 len -= dlen; in gsm_dlci_command()
2467 dlci->gsm->malformed++; in gsm_dlci_command()
2472 gsm_control_message(dlci->gsm, command, data, clen); in gsm_dlci_command()
2474 gsm_control_response(dlci->gsm, command, data, clen); in gsm_dlci_command()
2478 * gsm_kick_timer - transmit if possible
2489 int sent = 0; in gsm_kick_timer()
2491 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_kick_timer()
2493 if (gsm->tx_bytes < TX_THRESH_LO) in gsm_kick_timer()
2495 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_kick_timer()
2502 * gsm_dlci_copy_config_values - copy DLCI configuration
2509 dc->channel = (u32)dlci->addr; in gsm_dlci_copy_config_values()
2510 dc->adaption = (u32)dlci->adaption; in gsm_dlci_copy_config_values()
2511 dc->mtu = (u32)dlci->mtu; in gsm_dlci_copy_config_values()
2512 dc->priority = (u32)dlci->prio; in gsm_dlci_copy_config_values()
2513 if (dlci->ftype == UIH) in gsm_dlci_copy_config_values()
2514 dc->i = 1; in gsm_dlci_copy_config_values()
2516 dc->i = 2; in gsm_dlci_copy_config_values()
2517 dc->k = (u32)dlci->k; in gsm_dlci_copy_config_values()
2521 * gsm_dlci_config - configure DLCI from configuration
2526 static int gsm_dlci_config(struct gsm_dlci *dlci, struct gsm_dlci_config *dc, int open) in gsm_dlci_config()
2531 unsigned int i; in gsm_dlci_config()
2537 for (i = 0; i < ARRAY_SIZE(dc->reserved); i++) in gsm_dlci_config()
2538 if (dc->reserved[i]) in gsm_dlci_config()
2539 return -EINVAL; in gsm_dlci_config()
2542 return -EINVAL; in gsm_dlci_config()
2543 gsm = dlci->gsm; in gsm_dlci_config()
2545 /* Stuff we don't support yet - I frame transport */ in gsm_dlci_config()
2546 if (dc->adaption != 1 && dc->adaption != 2) in gsm_dlci_config()
2547 return -EOPNOTSUPP; in gsm_dlci_config()
2548 if (dc->mtu > MAX_MTU || dc->mtu < MIN_MTU || dc->mtu > gsm->mru) in gsm_dlci_config()
2549 return -EINVAL; in gsm_dlci_config()
2550 if (dc->priority >= 64) in gsm_dlci_config()
2551 return -EINVAL; in gsm_dlci_config()
2552 if (dc->i == 0 || dc->i > 2) /* UIH and UI only */ in gsm_dlci_config()
2553 return -EINVAL; in gsm_dlci_config()
2554 if (dc->k > 7) in gsm_dlci_config()
2555 return -EINVAL; in gsm_dlci_config()
2556 if (dc->flags & ~GSM_FL_RESTART) /* allow future extensions */ in gsm_dlci_config()
2557 return -EINVAL; in gsm_dlci_config()
2563 if (dc->adaption != dlci->adaption) in gsm_dlci_config()
2565 if (dc->mtu != dlci->mtu) in gsm_dlci_config()
2567 if (dc->i != dlci->ftype) in gsm_dlci_config()
2570 if (dc->priority != dlci->prio) in gsm_dlci_config()
2572 if (dc->flags & GSM_FL_RESTART) in gsm_dlci_config()
2575 if ((open && gsm->wait_config) || need_restart) in gsm_dlci_config()
2577 if (dlci->state == DLCI_WAITING_CONFIG) { in gsm_dlci_config()
2588 wait_event_interruptible(gsm->event, dlci->state == DLCI_CLOSED); in gsm_dlci_config()
2590 return -EINTR; in gsm_dlci_config()
2595 dlci->adaption = (int)dc->adaption; in gsm_dlci_config()
2597 if (dc->mtu) in gsm_dlci_config()
2598 dlci->mtu = (unsigned int)dc->mtu; in gsm_dlci_config()
2600 dlci->mtu = gsm->mtu; in gsm_dlci_config()
2602 if (dc->priority) in gsm_dlci_config()
2603 dlci->prio = (u8)dc->priority; in gsm_dlci_config()
2605 dlci->prio = roundup(dlci->addr + 1, 8) - 1; in gsm_dlci_config()
2607 if (dc->i == 1) in gsm_dlci_config()
2608 dlci->ftype = UIH; in gsm_dlci_config()
2609 else if (dc->i == 2) in gsm_dlci_config()
2610 dlci->ftype = UI; in gsm_dlci_config()
2612 if (dc->k) in gsm_dlci_config()
2613 dlci->k = (u8)dc->k; in gsm_dlci_config()
2615 dlci->k = gsm->k; in gsm_dlci_config()
2618 if (gsm->initiator) in gsm_dlci_config()
2632 * gsm_dlci_alloc - allocate a DLCI
2633 * @gsm: GSM mux
2636 * Allocate and install a new DLCI object into the GSM mux.
2641 static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr) in gsm_dlci_alloc()
2646 spin_lock_init(&dlci->lock); in gsm_dlci_alloc()
2647 mutex_init(&dlci->mutex); in gsm_dlci_alloc()
2648 if (kfifo_alloc(&dlci->fifo, TX_SIZE, GFP_KERNEL) < 0) { in gsm_dlci_alloc()
2653 skb_queue_head_init(&dlci->skb_list); in gsm_dlci_alloc()
2654 timer_setup(&dlci->t1, gsm_dlci_t1, 0); in gsm_dlci_alloc()
2655 tty_port_init(&dlci->port); in gsm_dlci_alloc()
2656 dlci->port.ops = &gsm_port_ops; in gsm_dlci_alloc()
2657 dlci->gsm = gsm; in gsm_dlci_alloc()
2658 dlci->addr = addr; in gsm_dlci_alloc()
2659 dlci->adaption = gsm->adaption; in gsm_dlci_alloc()
2660 dlci->mtu = gsm->mtu; in gsm_dlci_alloc()
2662 dlci->prio = 0; in gsm_dlci_alloc()
2664 dlci->prio = roundup(addr + 1, 8) - 1; in gsm_dlci_alloc()
2665 dlci->ftype = gsm->ftype; in gsm_dlci_alloc()
2666 dlci->k = gsm->k; in gsm_dlci_alloc()
2667 dlci->state = DLCI_CLOSED; in gsm_dlci_alloc()
2669 dlci->data = gsm_dlci_data; in gsm_dlci_alloc()
2671 dlci->constipated = true; in gsm_dlci_alloc()
2673 dlci->data = gsm_dlci_command; in gsm_dlci_alloc()
2675 gsm->dlci[addr] = dlci; in gsm_dlci_alloc()
2680 * gsm_dlci_free - free DLCI
2681 * @port: tty port for DLCI to free
2687 static void gsm_dlci_free(struct tty_port *port) in gsm_dlci_free() argument
2689 struct gsm_dlci *dlci = container_of(port, struct gsm_dlci, port); in gsm_dlci_free()
2691 timer_shutdown_sync(&dlci->t1); in gsm_dlci_free()
2692 dlci->gsm->dlci[dlci->addr] = NULL; in gsm_dlci_free()
2693 kfifo_free(&dlci->fifo); in gsm_dlci_free()
2694 while ((dlci->skb = skb_dequeue(&dlci->skb_list))) in gsm_dlci_free()
2695 dev_kfree_skb(dlci->skb); in gsm_dlci_free()
2701 tty_port_get(&dlci->port); in dlci_get()
2706 tty_port_put(&dlci->port); in dlci_put()
2712 * gsm_dlci_release - release DLCI
2716 * mux is closed or tty is closed - whichever is last.
2722 struct tty_struct *tty = tty_port_tty_get(&dlci->port); in gsm_dlci_release()
2724 mutex_lock(&dlci->mutex); in gsm_dlci_release()
2726 mutex_unlock(&dlci->mutex); in gsm_dlci_release()
2730 * queue release_one_tty() -> NULL pointer panic in in gsm_dlci_release()
2735 tty_port_tty_set(&dlci->port, NULL); in gsm_dlci_release()
2738 dlci->state = DLCI_CLOSED; in gsm_dlci_release()
2747 * gsm_queue - a GSM frame is ready to process
2748 * @gsm: pointer to our gsm mux
2760 int address; in gsm_queue()
2762 if (gsm->fcs != GOOD_FCS) { in gsm_queue()
2763 gsm->bad_fcs++; in gsm_queue()
2765 pr_debug("BAD FCS %02x\n", gsm->fcs); in gsm_queue()
2768 address = gsm->address >> 1; in gsm_queue()
2772 cr = gsm->address & 1; /* C/R bit */ in gsm_queue()
2773 cr ^= gsm->initiator ? 0 : 1; /* Flip so 1 always means command */ in gsm_queue()
2775 gsm_print_packet("<--", address, cr, gsm->control, gsm->buf, gsm->len); in gsm_queue()
2777 dlci = gsm->dlci[address]; in gsm_queue()
2779 switch (gsm->control) { in gsm_queue()
2782 gsm->open_error++; in gsm_queue()
2788 gsm->open_error++; in gsm_queue()
2791 if (dlci->dead) in gsm_queue()
2801 if (dlci == NULL || dlci->state == DLCI_CLOSED) { in gsm_queue()
2812 switch (dlci->state) { in gsm_queue()
2821 dlci->state); in gsm_queue()
2837 if (dlci == NULL || dlci->state != DLCI_OPEN) { in gsm_queue()
2841 dlci->data(dlci, gsm->buf, gsm->len); in gsm_queue()
2848 gsm->malformed++; in gsm_queue()
2853 * gsm0_receive_state_check_and_fix - check and correct receive state
2861 switch (gsm->state) { in gsm0_receive_state_check_and_fix()
2872 gsm->state = GSM_SEARCH; in gsm0_receive_state_check_and_fix()
2878 * gsm0_receive - perform processing for non-transparency
2887 unsigned int len; in gsm0_receive()
2890 switch (gsm->state) { in gsm0_receive()
2893 gsm->state = GSM0_ADDRESS; in gsm0_receive()
2894 gsm->address = 0; in gsm0_receive()
2895 gsm->len = 0; in gsm0_receive()
2896 gsm->fcs = INIT_FCS; in gsm0_receive()
2900 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2901 if (gsm_read_ea(&gsm->address, c)) in gsm0_receive()
2902 gsm->state = GSM0_CONTROL; in gsm0_receive()
2905 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2906 gsm->control = c; in gsm0_receive()
2907 gsm->state = GSM0_LEN0; in gsm0_receive()
2910 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2911 if (gsm_read_ea(&gsm->len, c)) { in gsm0_receive()
2912 if (gsm->len > gsm->mru) { in gsm0_receive()
2913 gsm->bad_size++; in gsm0_receive()
2914 gsm->state = GSM_SEARCH; in gsm0_receive()
2917 gsm->count = 0; in gsm0_receive()
2918 if (!gsm->len) in gsm0_receive()
2919 gsm->state = GSM0_FCS; in gsm0_receive()
2921 gsm->state = GSM0_DATA; in gsm0_receive()
2924 gsm->state = GSM0_LEN1; in gsm0_receive()
2927 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2929 gsm->len |= len << 7; in gsm0_receive()
2930 if (gsm->len > gsm->mru) { in gsm0_receive()
2931 gsm->bad_size++; in gsm0_receive()
2932 gsm->state = GSM_SEARCH; in gsm0_receive()
2935 gsm->count = 0; in gsm0_receive()
2936 if (!gsm->len) in gsm0_receive()
2937 gsm->state = GSM0_FCS; in gsm0_receive()
2939 gsm->state = GSM0_DATA; in gsm0_receive()
2942 gsm->buf[gsm->count++] = c; in gsm0_receive()
2943 if (gsm->count >= MAX_MRU) { in gsm0_receive()
2944 gsm->bad_size++; in gsm0_receive()
2945 gsm->state = GSM_SEARCH; in gsm0_receive()
2946 } else if (gsm->count >= gsm->len) { in gsm0_receive()
2948 if ((gsm->control & ~PF) != UIH) { in gsm0_receive()
2949 gsm->fcs = gsm_fcs_add_block(gsm->fcs, gsm->buf, in gsm0_receive()
2950 gsm->count); in gsm0_receive()
2952 gsm->state = GSM0_FCS; in gsm0_receive()
2956 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2957 gsm->state = GSM0_SSOF; in gsm0_receive()
2960 gsm->state = GSM_SEARCH; in gsm0_receive()
2964 gsm->bad_size++; in gsm0_receive()
2967 pr_debug("%s: unhandled state: %d\n", __func__, gsm->state); in gsm0_receive()
2973 * gsm1_receive_state_check_and_fix - check and correct receive state
2981 switch (gsm->state) { in gsm1_receive_state_check_and_fix()
2990 gsm->state = GSM_SEARCH; in gsm1_receive_state_check_and_fix()
2996 * gsm1_receive - perform processing for non-transparency
3008 gsm->constipated = true; in gsm1_receive()
3011 gsm->constipated = false; in gsm1_receive()
3018 if (gsm->state == GSM1_DATA) { in gsm1_receive()
3019 if (gsm->count < 1) { in gsm1_receive()
3021 gsm->malformed++; in gsm1_receive()
3022 gsm->state = GSM1_START; in gsm1_receive()
3026 gsm->count--; in gsm1_receive()
3027 if ((gsm->control & ~PF) != UIH) { in gsm1_receive()
3031 gsm->fcs = gsm_fcs_add_block(gsm->fcs, gsm->buf, in gsm1_receive()
3032 gsm->count); in gsm1_receive()
3035 gsm->fcs = gsm_fcs_add(gsm->fcs, gsm->buf[gsm->count]); in gsm1_receive()
3036 gsm->len = gsm->count; in gsm1_receive()
3038 gsm->state = GSM1_START; in gsm1_receive()
3042 if (gsm->state != GSM1_START) { in gsm1_receive()
3043 if (gsm->state != GSM_SEARCH) in gsm1_receive()
3044 gsm->malformed++; in gsm1_receive()
3045 gsm->state = GSM1_START; in gsm1_receive()
3053 gsm->escape = true; in gsm1_receive()
3058 if (gsm->state == GSM_SEARCH) in gsm1_receive()
3061 if (gsm->escape) { in gsm1_receive()
3063 gsm->escape = false; in gsm1_receive()
3065 switch (gsm->state) { in gsm1_receive()
3067 gsm->address = 0; in gsm1_receive()
3068 gsm->state = GSM1_ADDRESS; in gsm1_receive()
3069 gsm->fcs = INIT_FCS; in gsm1_receive()
3072 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm1_receive()
3073 if (gsm_read_ea(&gsm->address, c)) in gsm1_receive()
3074 gsm->state = GSM1_CONTROL; in gsm1_receive()
3077 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm1_receive()
3078 gsm->control = c; in gsm1_receive()
3079 gsm->count = 0; in gsm1_receive()
3080 gsm->state = GSM1_DATA; in gsm1_receive()
3083 if (gsm->count > gsm->mru || gsm->count > MAX_MRU) { /* Allow one for the FCS */ in gsm1_receive()
3084 gsm->state = GSM1_OVERRUN; in gsm1_receive()
3085 gsm->bad_size++; in gsm1_receive()
3087 gsm->buf[gsm->count++] = c; in gsm1_receive()
3089 case GSM1_OVERRUN: /* Over-long - eg a dropped SOF */ in gsm1_receive()
3092 pr_debug("%s: unhandled state: %d\n", __func__, gsm->state); in gsm1_receive()
3098 * gsm_error - handle tty error
3109 gsm->state = GSM_SEARCH; in gsm_error()
3110 gsm->io_error++; in gsm_error()
3114 * gsm_cleanup_mux - generic GSM protocol cleanup
3115 * @gsm: our mux
3118 * Clean up the bits of the mux which are the same for all framing
3119 * protocols. Remove the mux from the mux table, stop all the timers
3125 int i; in gsm_cleanup_mux()
3129 gsm->dead = true; in gsm_cleanup_mux()
3130 mutex_lock(&gsm->mutex); in gsm_cleanup_mux()
3132 dlci = gsm->dlci[0]; in gsm_cleanup_mux()
3134 if (disc && dlci->state != DLCI_CLOSED) { in gsm_cleanup_mux()
3136 wait_event(gsm->event, dlci->state == DLCI_CLOSED); in gsm_cleanup_mux()
3138 dlci->dead = true; in gsm_cleanup_mux()
3142 del_timer_sync(&gsm->kick_timer); in gsm_cleanup_mux()
3143 del_timer_sync(&gsm->t2_timer); in gsm_cleanup_mux()
3144 del_timer_sync(&gsm->ka_timer); in gsm_cleanup_mux()
3147 flush_work(&gsm->tx_work); in gsm_cleanup_mux()
3150 if (gsm->has_devices) { in gsm_cleanup_mux()
3151 gsm_unregister_devices(gsm_tty_driver, gsm->num); in gsm_cleanup_mux()
3152 gsm->has_devices = false; in gsm_cleanup_mux()
3154 for (i = NUM_DLCI - 1; i >= 0; i--) in gsm_cleanup_mux()
3155 if (gsm->dlci[i]) in gsm_cleanup_mux()
3156 gsm_dlci_release(gsm->dlci[i]); in gsm_cleanup_mux()
3157 mutex_unlock(&gsm->mutex); in gsm_cleanup_mux()
3159 tty_ldisc_flush(gsm->tty); in gsm_cleanup_mux()
3161 guard(spinlock_irqsave)(&gsm->tx_lock); in gsm_cleanup_mux()
3162 list_for_each_entry_safe(txq, ntxq, &gsm->tx_ctrl_list, list) in gsm_cleanup_mux()
3164 INIT_LIST_HEAD(&gsm->tx_ctrl_list); in gsm_cleanup_mux()
3165 list_for_each_entry_safe(txq, ntxq, &gsm->tx_data_list, list) in gsm_cleanup_mux()
3167 INIT_LIST_HEAD(&gsm->tx_data_list); in gsm_cleanup_mux()
3171 * gsm_activate_mux - generic GSM setup
3172 * @gsm: our mux
3174 * Set up the bits of the mux which are the same for all framing
3175 * protocols. Add the mux to the mux table so it can be opened and
3179 static int gsm_activate_mux(struct gsm_mux *gsm) in gsm_activate_mux()
3182 int ret; in gsm_activate_mux()
3186 return -ENOMEM; in gsm_activate_mux()
3188 if (gsm->encoding == GSM_BASIC_OPT) in gsm_activate_mux()
3189 gsm->receive = gsm0_receive; in gsm_activate_mux()
3191 gsm->receive = gsm1_receive; in gsm_activate_mux()
3193 ret = gsm_register_devices(gsm_tty_driver, gsm->num); in gsm_activate_mux()
3197 gsm->has_devices = true; in gsm_activate_mux()
3198 gsm->dead = false; /* Tty opens are now permissible */ in gsm_activate_mux()
3203 * gsm_free_mux - free up a mux
3204 * @gsm: mux to free
3206 * Dispose of allocated resources for a dead mux
3210 int i; in gsm_free_mux()
3218 mutex_destroy(&gsm->mutex); in gsm_free_mux()
3219 kfree(gsm->txframe); in gsm_free_mux()
3220 kfree(gsm->buf); in gsm_free_mux()
3225 * gsm_free_muxr - free up a mux
3226 * @ref: kreference to the mux to free
3228 * Dispose of allocated resources for a dead mux
3241 kref_get(&gsm->ref); in mux_get()
3250 kref_put(&gsm->ref, gsm_free_muxr); in mux_put()
3254 static inline unsigned int mux_num_to_base(struct gsm_mux *gsm) in mux_num_to_base()
3256 return gsm->num * NUM_DLCI; in mux_num_to_base()
3259 static inline unsigned int mux_line_to_num(unsigned int line) in mux_line_to_num()
3265 * gsm_alloc_mux - allocate a mux
3267 * Creates a new mux ready for activation.
3272 int i; in gsm_alloc_mux()
3276 gsm->buf = kmalloc(MAX_MRU + 1, GFP_KERNEL); in gsm_alloc_mux()
3277 if (gsm->buf == NULL) { in gsm_alloc_mux()
3281 gsm->txframe = kmalloc(2 * (MAX_MTU + PROT_OVERHEAD - 1), GFP_KERNEL); in gsm_alloc_mux()
3282 if (gsm->txframe == NULL) { in gsm_alloc_mux()
3283 kfree(gsm->buf); in gsm_alloc_mux()
3287 spin_lock_init(&gsm->lock); in gsm_alloc_mux()
3288 mutex_init(&gsm->mutex); in gsm_alloc_mux()
3289 kref_init(&gsm->ref); in gsm_alloc_mux()
3290 INIT_LIST_HEAD(&gsm->tx_ctrl_list); in gsm_alloc_mux()
3291 INIT_LIST_HEAD(&gsm->tx_data_list); in gsm_alloc_mux()
3292 timer_setup(&gsm->kick_timer, gsm_kick_timer, 0); in gsm_alloc_mux()
3293 timer_setup(&gsm->t2_timer, gsm_control_retransmit, 0); in gsm_alloc_mux()
3294 timer_setup(&gsm->ka_timer, gsm_control_keep_alive, 0); in gsm_alloc_mux()
3295 INIT_WORK(&gsm->tx_work, gsmld_write_task); in gsm_alloc_mux()
3296 init_waitqueue_head(&gsm->event); in gsm_alloc_mux()
3297 spin_lock_init(&gsm->control_lock); in gsm_alloc_mux()
3298 spin_lock_init(&gsm->tx_lock); in gsm_alloc_mux()
3300 gsm->t1 = T1; in gsm_alloc_mux()
3301 gsm->t2 = T2; in gsm_alloc_mux()
3302 gsm->t3 = T3; in gsm_alloc_mux()
3303 gsm->n2 = N2; in gsm_alloc_mux()
3304 gsm->k = K; in gsm_alloc_mux()
3305 gsm->ftype = UIH; in gsm_alloc_mux()
3306 gsm->adaption = 1; in gsm_alloc_mux()
3307 gsm->encoding = GSM_ADV_OPT; in gsm_alloc_mux()
3308 gsm->mru = 64; /* Default to encoding 1 so these should be 64 */ in gsm_alloc_mux()
3309 gsm->mtu = 64; in gsm_alloc_mux()
3310 gsm->dead = true; /* Avoid early tty opens */ in gsm_alloc_mux()
3311 gsm->wait_config = false; /* Disabled */ in gsm_alloc_mux()
3312 gsm->keep_alive = 0; /* Disabled */ in gsm_alloc_mux()
3314 /* Store the instance to the mux array or abort if no space is in gsm_alloc_mux()
3321 gsm->num = i; in gsm_alloc_mux()
3327 mutex_destroy(&gsm->mutex); in gsm_alloc_mux()
3328 kfree(gsm->txframe); in gsm_alloc_mux()
3329 kfree(gsm->buf); in gsm_alloc_mux()
3341 c->adaption = gsm->adaption; in gsm_copy_config_values()
3342 c->encapsulation = gsm->encoding; in gsm_copy_config_values()
3343 c->initiator = gsm->initiator; in gsm_copy_config_values()
3344 c->t1 = gsm->t1; in gsm_copy_config_values()
3345 c->t2 = gsm->t2; in gsm_copy_config_values()
3346 c->t3 = gsm->t3; in gsm_copy_config_values()
3347 c->n2 = gsm->n2; in gsm_copy_config_values()
3348 if (gsm->ftype == UIH) in gsm_copy_config_values()
3349 c->i = 1; in gsm_copy_config_values()
3351 c->i = 2; in gsm_copy_config_values()
3352 pr_debug("Ftype %d i %d\n", gsm->ftype, c->i); in gsm_copy_config_values()
3353 c->mru = gsm->mru; in gsm_copy_config_values()
3354 c->mtu = gsm->mtu; in gsm_copy_config_values()
3355 c->k = gsm->k; in gsm_copy_config_values()
3358 static int gsm_config(struct gsm_mux *gsm, struct gsm_config *c) in gsm_config()
3360 int need_close = 0; in gsm_config()
3361 int need_restart = 0; in gsm_config()
3363 /* Stuff we don't support yet - UI or I frame transport */ in gsm_config()
3364 if (c->adaption != 1 && c->adaption != 2) in gsm_config()
3365 return -EOPNOTSUPP; in gsm_config()
3367 if (c->mru < MIN_MTU || c->mtu < MIN_MTU) in gsm_config()
3368 return -EINVAL; in gsm_config()
3369 if (c->mru > MAX_MRU || c->mtu > MAX_MTU) in gsm_config()
3370 return -EINVAL; in gsm_config()
3371 if (c->t3 > MAX_T3) in gsm_config()
3372 return -EINVAL; in gsm_config()
3373 if (c->n2 > 255) in gsm_config()
3374 return -EINVAL; in gsm_config()
3375 if (c->encapsulation > 1) /* Basic, advanced, no I */ in gsm_config()
3376 return -EINVAL; in gsm_config()
3377 if (c->initiator > 1) in gsm_config()
3378 return -EINVAL; in gsm_config()
3379 if (c->k > MAX_WINDOW_SIZE) in gsm_config()
3380 return -EINVAL; in gsm_config()
3381 if (c->i == 0 || c->i > 2) /* UIH and UI only */ in gsm_config()
3382 return -EINVAL; in gsm_config()
3388 if (c->t1 != 0 && c->t1 != gsm->t1) in gsm_config()
3390 if (c->t2 != 0 && c->t2 != gsm->t2) in gsm_config()
3392 if (c->encapsulation != gsm->encoding) in gsm_config()
3394 if (c->adaption != gsm->adaption) in gsm_config()
3397 if (c->initiator != gsm->initiator) in gsm_config()
3399 if (c->mru != gsm->mru) in gsm_config()
3401 if (c->mtu != gsm->mtu) in gsm_config()
3412 gsm->initiator = c->initiator; in gsm_config()
3413 gsm->mru = c->mru; in gsm_config()
3414 gsm->mtu = c->mtu; in gsm_config()
3415 gsm->encoding = c->encapsulation ? GSM_ADV_OPT : GSM_BASIC_OPT; in gsm_config()
3416 gsm->adaption = c->adaption; in gsm_config()
3417 gsm->n2 = c->n2; in gsm_config()
3419 if (c->i == 1) in gsm_config()
3420 gsm->ftype = UIH; in gsm_config()
3421 else if (c->i == 2) in gsm_config()
3422 gsm->ftype = UI; in gsm_config()
3424 if (c->t1) in gsm_config()
3425 gsm->t1 = c->t1; in gsm_config()
3426 if (c->t2) in gsm_config()
3427 gsm->t2 = c->t2; in gsm_config()
3428 if (c->t3) in gsm_config()
3429 gsm->t3 = c->t3; in gsm_config()
3430 if (c->k) in gsm_config()
3431 gsm->k = c->k; in gsm_config()
3435 * and removing from the mux array in gsm_config()
3437 if (gsm->dead) { in gsm_config()
3438 int ret = gsm_activate_mux(gsm); in gsm_config()
3441 if (gsm->initiator) in gsm_config()
3442 gsm_dlci_begin_open(gsm->dlci[0]); in gsm_config()
3451 ce->wait_config = gsm->wait_config ? 1 : 0; in gsm_copy_config_ext_values()
3452 ce->keep_alive = gsm->keep_alive; in gsm_copy_config_ext_values()
3455 static int gsm_config_ext(struct gsm_mux *gsm, struct gsm_config_ext *ce) in gsm_config_ext()
3458 unsigned int i; in gsm_config_ext()
3464 for (i = 0; i < ARRAY_SIZE(ce->reserved); i++) in gsm_config_ext()
3465 if (ce->reserved[i]) in gsm_config_ext()
3466 return -EINVAL; in gsm_config_ext()
3467 if (ce->flags & ~GSM_FL_RESTART) in gsm_config_ext()
3468 return -EINVAL; in gsm_config_ext()
3471 if (ce->flags & GSM_FL_RESTART) in gsm_config_ext()
3485 gsm->wait_config = ce->wait_config ? true : false; in gsm_config_ext()
3486 gsm->keep_alive = ce->keep_alive; in gsm_config_ext()
3488 if (gsm->dead) { in gsm_config_ext()
3489 int ret = gsm_activate_mux(gsm); in gsm_config_ext()
3492 if (gsm->initiator) in gsm_config_ext()
3493 gsm_dlci_begin_open(gsm->dlci[0]); in gsm_config_ext()
3500 * gsmld_output - write to link
3501 * @gsm: our mux
3505 * Write a block of data from the GSM mux to the data channel. This
3509 static int gsmld_output(struct gsm_mux *gsm, u8 *data, int len) in gsmld_output()
3511 if (tty_write_room(gsm->tty) < len) { in gsmld_output()
3512 set_bit(TTY_DO_WRITE_WAKEUP, &gsm->tty->flags); in gsmld_output()
3513 return -ENOSPC; in gsmld_output()
3517 return gsm->tty->ops->write(gsm->tty, data, len); in gsmld_output()
3522 * gsmld_write_trigger - schedule ldisc write task
3523 * @gsm: our mux
3527 if (!gsm || !gsm->dlci[0] || gsm->dlci[0]->dead) in gsmld_write_trigger()
3529 schedule_work(&gsm->tx_work); in gsmld_write_trigger()
3534 * gsmld_write_task - ldisc write task
3538 * avoid dead-locking. This returns if no space or data is left for output.
3544 int i, ret; in gsmld_write_task()
3549 ret = -ENODEV; in gsmld_write_task()
3550 spin_lock_irqsave(&gsm->tx_lock, flags); in gsmld_write_task()
3551 if (gsm->tty) in gsmld_write_task()
3553 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsmld_write_task()
3557 if (gsm->dlci[i]) in gsmld_write_task()
3558 tty_port_tty_wakeup(&gsm->dlci[i]->port); in gsmld_write_task()
3562 * gsmld_attach_gsm - mode set up
3564 * @gsm: our mux
3566 * Set up the MUX for basic mode and commence connecting to the
3573 gsm->tty = tty_kref_get(tty); in gsmld_attach_gsm()
3575 gsm->old_c_iflag = tty->termios.c_iflag; in gsmld_attach_gsm()
3576 tty->termios.c_iflag &= (IXON | IXOFF); in gsmld_attach_gsm()
3580 * gsmld_detach_gsm - stop doing 0710 mux
3581 * @tty: tty attached to the mux
3582 * @gsm: mux
3589 WARN_ON(tty != gsm->tty); in gsmld_detach_gsm()
3591 gsm->tty->termios.c_iflag = gsm->old_c_iflag; in gsmld_detach_gsm()
3592 tty_kref_put(gsm->tty); in gsmld_detach_gsm()
3593 gsm->tty = NULL; in gsmld_detach_gsm()
3599 struct gsm_mux *gsm = tty->disc_data; in gsmld_receive_buf()
3605 for (; count; count--, cp++) { in gsmld_receive_buf()
3610 if (gsm->receive) in gsmld_receive_buf()
3611 gsm->receive(gsm, *cp); in gsmld_receive_buf()
3630 * gsmld_flush_buffer - clean input queue
3643 * gsmld_close - close the ldisc for this tty
3654 struct gsm_mux *gsm = tty->disc_data; in gsmld_close()
3656 /* The ldisc locks and closes the port before calling our close. This in gsmld_close()
3670 * gsmld_open - open an ldisc
3679 static int gsmld_open(struct tty_struct *tty) in gsmld_open()
3684 return -EPERM; in gsmld_open()
3686 if (tty->ops->write == NULL) in gsmld_open()
3687 return -EINVAL; in gsmld_open()
3692 return -ENOMEM; in gsmld_open()
3694 tty->disc_data = gsm; in gsmld_open()
3695 tty->receive_room = 65536; in gsmld_open()
3700 /* The mux will not be activated yet, we wait for correct in gsmld_open()
3703 if (gsm->encoding == GSM_BASIC_OPT) in gsmld_open()
3704 gsm->receive = gsm0_receive; in gsmld_open()
3706 gsm->receive = gsm1_receive; in gsmld_open()
3712 * gsmld_write_wakeup - asynchronous I/O notifier
3722 struct gsm_mux *gsm = tty->disc_data; in gsmld_write_wakeup()
3729 * gsmld_read - read function for tty
3748 return -EOPNOTSUPP; in gsmld_read()
3752 * gsmld_write - write function for tty
3760 * as-is and must be properly framed and checksummed as appropriate
3768 struct gsm_mux *gsm = tty->disc_data; in gsmld_write()
3771 int ret; in gsmld_write()
3774 return -ENODEV; in gsmld_write()
3776 ret = -ENOBUFS; in gsmld_write()
3777 spin_lock_irqsave(&gsm->tx_lock, flags); in gsmld_write()
3780 ret = tty->ops->write(tty, buf, nr); in gsmld_write()
3782 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in gsmld_write()
3783 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsmld_write()
3789 * gsmld_poll - poll method for N_GSM0710
3799 * Called without the kernel lock held - fine
3806 struct gsm_mux *gsm = tty->disc_data; in gsmld_poll()
3808 poll_wait(file, &tty->read_wait, wait); in gsmld_poll()
3809 poll_wait(file, &tty->write_wait, wait); in gsmld_poll()
3811 if (gsm->dead) in gsmld_poll()
3815 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) in gsmld_poll()
3822 static int gsmld_ioctl(struct tty_struct *tty, unsigned int cmd, in gsmld_ioctl()
3828 struct gsm_mux *gsm = tty->disc_data; in gsmld_ioctl()
3829 unsigned int base, addr; in gsmld_ioctl()
3836 return -EFAULT; in gsmld_ioctl()
3840 return -EFAULT; in gsmld_ioctl()
3848 return -EFAULT; in gsmld_ioctl()
3852 return -EFAULT; in gsmld_ioctl()
3856 return -EFAULT; in gsmld_ioctl()
3858 return -EINVAL; in gsmld_ioctl()
3860 dlci = gsm->dlci[addr]; in gsmld_ioctl()
3864 return -ENOMEM; in gsmld_ioctl()
3868 return -EFAULT; in gsmld_ioctl()
3872 return -EFAULT; in gsmld_ioctl()
3874 return -EINVAL; in gsmld_ioctl()
3876 dlci = gsm->dlci[addr]; in gsmld_ioctl()
3880 return -ENOMEM; in gsmld_ioctl()
3893 static int gsm_mux_net_open(struct net_device *net) in gsm_mux_net_open()
3900 static int gsm_mux_net_close(struct net_device *net) in gsm_mux_net_close()
3908 if (!dlci->net) { in dlci_net_free()
3912 dlci->adaption = dlci->prev_adaption; in dlci_net_free()
3913 dlci->data = dlci->prev_data; in dlci_net_free()
3914 free_netdev(dlci->net); in dlci_net_free()
3915 dlci->net = NULL; in dlci_net_free()
3923 dlci = mux_net->dlci; in net_free()
3925 if (dlci->net) { in net_free()
3926 unregister_netdev(dlci->net); in net_free()
3933 kref_get(&mux_net->ref); in muxnet_get()
3938 kref_put(&mux_net->ref, net_free); in muxnet_put()
3945 struct gsm_dlci *dlci = mux_net->dlci; in gsm_mux_net_start_xmit()
3948 skb_queue_head(&dlci->skb_list, skb); in gsm_mux_net_start_xmit()
3949 net->stats.tx_packets++; in gsm_mux_net_start_xmit()
3950 net->stats.tx_bytes += skb->len; in gsm_mux_net_start_xmit()
3959 static void gsm_mux_net_tx_timeout(struct net_device *net, unsigned int txqueue) in gsm_mux_net_tx_timeout()
3962 dev_dbg(&net->dev, "Tx timed out.\n"); in gsm_mux_net_tx_timeout()
3965 net->stats.tx_errors++; in gsm_mux_net_tx_timeout()
3968 static void gsm_mux_rx_netchar(struct gsm_dlci *dlci, const u8 *in_buf, int size) in gsm_mux_rx_netchar()
3970 struct net_device *net = dlci->net; in gsm_mux_rx_netchar()
3979 net->stats.rx_dropped++; in gsm_mux_rx_netchar()
3986 skb->dev = net; in gsm_mux_rx_netchar()
3987 skb->protocol = htons(ETH_P_IP); in gsm_mux_rx_netchar()
3993 net->stats.rx_packets++; in gsm_mux_rx_netchar()
3994 net->stats.rx_bytes += size; in gsm_mux_rx_netchar()
4008 net->netdev_ops = &gsm_netdev_ops; in gsm_mux_net_init()
4011 net->watchdog_timeo = GSM_NET_TX_TIMEOUT; in gsm_mux_net_init()
4012 net->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST; in gsm_mux_net_init()
4013 net->type = ARPHRD_NONE; in gsm_mux_net_init()
4014 net->tx_queue_len = 10; in gsm_mux_net_init()
4024 if (!dlci->net) in gsm_destroy_network()
4026 mux_net = netdev_priv(dlci->net); in gsm_destroy_network()
4032 static int gsm_create_network(struct gsm_dlci *dlci, struct gsm_netconfig *nc) in gsm_create_network()
4035 int retval = 0; in gsm_create_network()
4040 return -EPERM; in gsm_create_network()
4043 if (dlci->adaption > 2) in gsm_create_network()
4044 return -EBUSY; in gsm_create_network()
4046 if (nc->protocol != htons(ETH_P_IP)) in gsm_create_network()
4047 return -EPROTONOSUPPORT; in gsm_create_network()
4049 if (nc->adaption != 3 && nc->adaption != 4) in gsm_create_network()
4050 return -EPROTONOSUPPORT; in gsm_create_network()
4055 if (nc->if_name[0] != '\0') in gsm_create_network()
4056 netname = nc->if_name; in gsm_create_network()
4061 return -ENOMEM; in gsm_create_network()
4063 net->mtu = dlci->mtu; in gsm_create_network()
4064 net->min_mtu = MIN_MTU; in gsm_create_network()
4065 net->max_mtu = dlci->mtu; in gsm_create_network()
4067 mux_net->dlci = dlci; in gsm_create_network()
4068 kref_init(&mux_net->ref); in gsm_create_network()
4069 strscpy(nc->if_name, net->name); /* return net name */ in gsm_create_network()
4072 dlci->prev_adaption = dlci->adaption; in gsm_create_network()
4073 dlci->prev_data = dlci->data; in gsm_create_network()
4074 dlci->adaption = nc->adaption; in gsm_create_network()
4075 dlci->data = gsm_mux_rx_netchar; in gsm_create_network()
4076 dlci->net = net; in gsm_create_network()
4085 return net->ifindex; /* return network index */ in gsm_create_network()
4109 * gsm_modem_upd_via_data - send modem bits via convergence layer
4119 struct gsm_mux *gsm = dlci->gsm; in gsm_modem_upd_via_data()
4122 if (dlci->state != DLCI_OPEN || dlci->adaption != 2) in gsm_modem_upd_via_data()
4125 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_modem_upd_via_data()
4127 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_modem_upd_via_data()
4131 * gsm_modem_upd_via_msc - send modem bits via control frame
4136 static int gsm_modem_upd_via_msc(struct gsm_dlci *dlci, u8 brk) in gsm_modem_upd_via_msc()
4140 int len = 2; in gsm_modem_upd_via_msc()
4142 if (dlci->gsm->encoding != GSM_BASIC_OPT) in gsm_modem_upd_via_msc()
4145 modembits[0] = (dlci->addr << 2) | 2 | EA; /* DLCI, Valid, EA */ in gsm_modem_upd_via_msc()
4153 ctrl = gsm_control_send(dlci->gsm, CMD_MSC, modembits, len); in gsm_modem_upd_via_msc()
4155 return -ENOMEM; in gsm_modem_upd_via_msc()
4156 return gsm_control_wait(dlci->gsm, ctrl); in gsm_modem_upd_via_msc()
4160 * gsm_modem_update - send modem status line state
4165 static int gsm_modem_update(struct gsm_dlci *dlci, u8 brk) in gsm_modem_update()
4167 if (dlci->gsm->dead) in gsm_modem_update()
4168 return -EL2HLT; in gsm_modem_update()
4169 if (dlci->adaption == 2) { in gsm_modem_update()
4173 } else if (dlci->gsm->encoding == GSM_BASIC_OPT) { in gsm_modem_update()
4179 return -EPROTONOSUPPORT; in gsm_modem_update()
4183 * gsm_wait_modem_change - wait for modem status line change
4188 * - any given modem status line bit changed
4189 * - the wait event function got interrupted (e.g. by a signal)
4190 * - the underlying DLCI was closed
4191 * - the underlying ldisc device was removed
4193 static int gsm_wait_modem_change(struct gsm_dlci *dlci, u32 mask) in gsm_wait_modem_change()
4195 struct gsm_mux *gsm = dlci->gsm; in gsm_wait_modem_change()
4196 u32 old = dlci->modem_rx; in gsm_wait_modem_change()
4197 int ret; in gsm_wait_modem_change()
4199 ret = wait_event_interruptible(gsm->event, gsm->dead || in gsm_wait_modem_change()
4200 dlci->state != DLCI_OPEN || in gsm_wait_modem_change()
4201 (old ^ dlci->modem_rx) & mask); in gsm_wait_modem_change()
4202 if (gsm->dead) in gsm_wait_modem_change()
4203 return -ENODEV; in gsm_wait_modem_change()
4204 if (dlci->state != DLCI_OPEN) in gsm_wait_modem_change()
4205 return -EL2NSYNC; in gsm_wait_modem_change()
4209 static bool gsm_carrier_raised(struct tty_port *port) in gsm_carrier_raised() argument
4211 struct gsm_dlci *dlci = container_of(port, struct gsm_dlci, port); in gsm_carrier_raised()
4212 struct gsm_mux *gsm = dlci->gsm; in gsm_carrier_raised()
4215 if (dlci->state != DLCI_OPEN) in gsm_carrier_raised()
4224 if (gsm->encoding == GSM_BASIC_OPT && in gsm_carrier_raised()
4225 gsm->dlci[0]->mode == DLCI_MODE_ADM && !dlci->modem_rx) in gsm_carrier_raised()
4228 return dlci->modem_rx & TIOCM_CD; in gsm_carrier_raised()
4231 static void gsm_dtr_rts(struct tty_port *port, bool active) in gsm_dtr_rts() argument
4233 struct gsm_dlci *dlci = container_of(port, struct gsm_dlci, port); in gsm_dtr_rts()
4234 unsigned int modem_tx = dlci->modem_tx; in gsm_dtr_rts()
4239 if (modem_tx != dlci->modem_tx) { in gsm_dtr_rts()
4240 dlci->modem_tx = modem_tx; in gsm_dtr_rts()
4251 static int gsmtty_install(struct tty_driver *driver, struct tty_struct *tty) in gsmtty_install()
4255 unsigned int line = tty->index; in gsmtty_install()
4256 unsigned int mux = mux_line_to_num(line); in gsmtty_install() local
4258 int ret; in gsmtty_install()
4262 if (mux >= MAX_MUX) in gsmtty_install()
4263 return -ENXIO; in gsmtty_install()
4265 if (gsm_mux[mux] == NULL) in gsmtty_install()
4266 return -EUNATCH; in gsmtty_install()
4268 return -ECHRNG; in gsmtty_install()
4269 gsm = gsm_mux[mux]; in gsmtty_install()
4270 if (gsm->dead) in gsmtty_install()
4271 return -EL2HLT; in gsmtty_install()
4276 mutex_lock(&gsm->mutex); in gsmtty_install()
4277 if (gsm->dlci[0] && gsm->dlci[0]->state != DLCI_OPEN) { in gsmtty_install()
4278 mutex_unlock(&gsm->mutex); in gsmtty_install()
4279 return -EL2NSYNC; in gsmtty_install()
4281 dlci = gsm->dlci[line]; in gsmtty_install()
4287 mutex_unlock(&gsm->mutex); in gsmtty_install()
4288 return -ENOMEM; in gsmtty_install()
4290 ret = tty_port_install(&dlci->port, driver, tty); in gsmtty_install()
4294 mutex_unlock(&gsm->mutex); in gsmtty_install()
4299 dlci_get(gsm->dlci[0]); in gsmtty_install()
4301 tty->driver_data = dlci; in gsmtty_install()
4302 mutex_unlock(&gsm->mutex); in gsmtty_install()
4307 static int gsmtty_open(struct tty_struct *tty, struct file *filp) in gsmtty_open()
4309 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_open()
4310 struct tty_port *port = &dlci->port; in gsmtty_open() local
4312 port->count++; in gsmtty_open()
4313 tty_port_tty_set(port, tty); in gsmtty_open()
4315 dlci->modem_rx = 0; in gsmtty_open()
4316 /* We could in theory open and close before we wait - eg if we get in gsmtty_open()
4318 tty_port_set_initialized(port, true); in gsmtty_open()
4320 if (!dlci->gsm->wait_config) { in gsmtty_open()
4322 if (dlci->gsm->initiator) in gsmtty_open()
4330 return tty_port_block_til_ready(port, tty, filp); in gsmtty_open()
4335 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_close()
4339 if (dlci->state == DLCI_CLOSED) in gsmtty_close()
4341 mutex_lock(&dlci->mutex); in gsmtty_close()
4343 mutex_unlock(&dlci->mutex); in gsmtty_close()
4344 if (tty_port_close_start(&dlci->port, tty, filp) == 0) in gsmtty_close()
4347 if (tty_port_initialized(&dlci->port) && C_HUPCL(tty)) in gsmtty_close()
4348 tty_port_lower_dtr_rts(&dlci->port); in gsmtty_close()
4349 tty_port_close_end(&dlci->port, tty); in gsmtty_close()
4350 tty_port_tty_set(&dlci->port, NULL); in gsmtty_close()
4356 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_hangup()
4357 if (dlci->state == DLCI_CLOSED) in gsmtty_hangup()
4359 tty_port_hangup(&dlci->port); in gsmtty_hangup()
4365 int sent; in gsmtty_write()
4366 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_write()
4367 if (dlci->state == DLCI_CLOSED) in gsmtty_write()
4368 return -EINVAL; in gsmtty_write()
4370 sent = kfifo_in_locked(&dlci->fifo, buf, len, &dlci->lock); in gsmtty_write()
4376 static unsigned int gsmtty_write_room(struct tty_struct *tty) in gsmtty_write_room()
4378 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_write_room()
4379 if (dlci->state == DLCI_CLOSED) in gsmtty_write_room()
4381 return kfifo_avail(&dlci->fifo); in gsmtty_write_room()
4384 static unsigned int gsmtty_chars_in_buffer(struct tty_struct *tty) in gsmtty_chars_in_buffer()
4386 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_chars_in_buffer()
4387 if (dlci->state == DLCI_CLOSED) in gsmtty_chars_in_buffer()
4389 return kfifo_len(&dlci->fifo); in gsmtty_chars_in_buffer()
4394 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_flush_buffer()
4397 if (dlci->state == DLCI_CLOSED) in gsmtty_flush_buffer()
4403 spin_lock_irqsave(&dlci->lock, flags); in gsmtty_flush_buffer()
4404 kfifo_reset(&dlci->fifo); in gsmtty_flush_buffer()
4405 spin_unlock_irqrestore(&dlci->lock, flags); in gsmtty_flush_buffer()
4409 static void gsmtty_wait_until_sent(struct tty_struct *tty, int timeout) in gsmtty_wait_until_sent()
4416 static int gsmtty_tiocmget(struct tty_struct *tty) in gsmtty_tiocmget()
4418 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_tiocmget()
4419 if (dlci->state == DLCI_CLOSED) in gsmtty_tiocmget()
4420 return -EINVAL; in gsmtty_tiocmget()
4421 return dlci->modem_rx; in gsmtty_tiocmget()
4424 static int gsmtty_tiocmset(struct tty_struct *tty, in gsmtty_tiocmset()
4425 unsigned int set, unsigned int clear) in gsmtty_tiocmset()
4427 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_tiocmset()
4428 unsigned int modem_tx = dlci->modem_tx; in gsmtty_tiocmset()
4430 if (dlci->state == DLCI_CLOSED) in gsmtty_tiocmset()
4431 return -EINVAL; in gsmtty_tiocmset()
4435 if (modem_tx != dlci->modem_tx) { in gsmtty_tiocmset()
4436 dlci->modem_tx = modem_tx; in gsmtty_tiocmset()
4443 static int gsmtty_ioctl(struct tty_struct *tty, in gsmtty_ioctl()
4444 unsigned int cmd, unsigned long arg) in gsmtty_ioctl()
4446 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_ioctl()
4449 int index; in gsmtty_ioctl()
4451 if (dlci->state == DLCI_CLOSED) in gsmtty_ioctl()
4452 return -EINVAL; in gsmtty_ioctl()
4456 return -EFAULT; in gsmtty_ioctl()
4457 nc.if_name[IFNAMSIZ-1] = '\0'; in gsmtty_ioctl()
4459 mutex_lock(&dlci->mutex); in gsmtty_ioctl()
4461 mutex_unlock(&dlci->mutex); in gsmtty_ioctl()
4463 return -EFAULT; in gsmtty_ioctl()
4467 return -EPERM; in gsmtty_ioctl()
4468 mutex_lock(&dlci->mutex); in gsmtty_ioctl()
4470 mutex_unlock(&dlci->mutex); in gsmtty_ioctl()
4474 return -EFAULT; in gsmtty_ioctl()
4475 if (dc.channel != dlci->addr) in gsmtty_ioctl()
4476 return -EPERM; in gsmtty_ioctl()
4479 return -EFAULT; in gsmtty_ioctl()
4483 return -EFAULT; in gsmtty_ioctl()
4485 return -EINVAL; in gsmtty_ioctl()
4486 if (dc.channel != 0 && dc.channel != dlci->addr) in gsmtty_ioctl()
4487 return -EPERM; in gsmtty_ioctl()
4492 return -ENOIOCTLCMD; in gsmtty_ioctl()
4499 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_set_termios()
4500 if (dlci->state == DLCI_CLOSED) in gsmtty_set_termios()
4507 tty_termios_copy_hw(&tty->termios, old); in gsmtty_set_termios()
4512 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_throttle()
4513 if (dlci->state == DLCI_CLOSED) in gsmtty_throttle()
4516 dlci->modem_tx &= ~TIOCM_RTS; in gsmtty_throttle()
4517 dlci->throttled = true; in gsmtty_throttle()
4524 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_unthrottle()
4525 if (dlci->state == DLCI_CLOSED) in gsmtty_unthrottle()
4528 dlci->modem_tx |= TIOCM_RTS; in gsmtty_unthrottle()
4529 dlci->throttled = false; in gsmtty_unthrottle()
4534 static int gsmtty_break_ctl(struct tty_struct *tty, int state) in gsmtty_break_ctl()
4536 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_break_ctl()
4537 int encode = 0; /* Off */ in gsmtty_break_ctl()
4538 if (dlci->state == DLCI_CLOSED) in gsmtty_break_ctl()
4539 return -EINVAL; in gsmtty_break_ctl()
4541 if (state == -1) /* "On indefinitely" - we can't encode this in gsmtty_break_ctl()
4554 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_cleanup()
4555 struct gsm_mux *gsm = dlci->gsm; in gsmtty_cleanup()
4558 dlci_put(gsm->dlci[0]); in gsmtty_cleanup()
4585 static int __init gsm_init(void) in gsm_init()
4588 int status = tty_register_ldisc(&tty_ldisc_packet); in gsm_init()
4602 gsm_tty_driver->driver_name = "gsmtty"; in gsm_init()
4603 gsm_tty_driver->name = "gsmtty"; in gsm_init()
4604 gsm_tty_driver->major = 0; /* Dynamic */ in gsm_init()
4605 gsm_tty_driver->minor_start = 0; in gsm_init()
4606 gsm_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; in gsm_init()
4607 gsm_tty_driver->subtype = SERIAL_TYPE_NORMAL; in gsm_init()
4608 gsm_tty_driver->init_termios = tty_std_termios; in gsm_init()
4610 gsm_tty_driver->init_termios.c_lflag &= ~ECHO; in gsm_init()
4615 status = -EBUSY; in gsm_init()
4619 gsm_tty_driver->major, gsm_tty_driver->minor_start); in gsm_init()