diff options
Diffstat (limited to 'packages/linux/linux-ezx-2.6.21/mux_cli.patch')
| -rw-r--r-- | packages/linux/linux-ezx-2.6.21/mux_cli.patch | 5395 |
1 files changed, 5395 insertions, 0 deletions
diff --git a/packages/linux/linux-ezx-2.6.21/mux_cli.patch b/packages/linux/linux-ezx-2.6.21/mux_cli.patch new file mode 100644 index 0000000000..2964f24fd2 --- /dev/null +++ b/packages/linux/linux-ezx-2.6.21/mux_cli.patch @@ -0,0 +1,5395 @@ +Index: linux-2.6.21/drivers/char/Kconfig +=================================================================== +--- linux-2.6.21.orig/drivers/char/Kconfig 2007-04-26 20:07:19.000000000 +0200 ++++ linux-2.6.21/drivers/char/Kconfig 2007-04-26 20:09:29.000000000 +0200 +@@ -1071,5 +1071,17 @@ + /sys/devices/platform/telco_clock, with a number of files for + controlling the behavior of this hardware. + ++config TS0710_MUX ++ tristate "GSM TS 07.10 Multiplex driver" ++ help ++ This implements the GSM 07.10 multiplex. ++ ++config TS0710_MUX_USB ++ tristate "Motorola USB support for TS 07.10 Multiplex driver" ++ depends on TS0710_MUX ++ help ++ This ads support for TS 07.10 over USB, as found in motorola ++ Smartphones. ++ + endmenu + +Index: linux-2.6.21/drivers/char/Makefile +=================================================================== +--- linux-2.6.21.orig/drivers/char/Makefile 2007-04-26 20:07:19.000000000 +0200 ++++ linux-2.6.21/drivers/char/Makefile 2007-04-26 20:09:29.000000000 +0200 +@@ -104,6 +104,9 @@ + obj-$(CONFIG_HANGCHECK_TIMER) += hangcheck-timer.o + obj-$(CONFIG_TCG_TPM) += tpm/ + ++obj-$(CONFIG_TS0710_MUX) += ts0710_mux.o ts0710_mux_usb.o ++ ++ + # Files generated that shall be removed upon make clean + clean-files := consolemap_deftbl.c defkeymap.c + +Index: linux-2.6.21/drivers/char/ts0710.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ linux-2.6.21/drivers/char/ts0710.h 2007-04-26 20:09:29.000000000 +0200 +@@ -0,0 +1,368 @@ ++/* ++ * File: ts0710.h ++ * ++ * Portions derived from rfcomm.c, original header as follows: ++ * ++ * Copyright (C) 2000, 2001 Axis Communications AB ++ * ++ * Author: Mats Friden <mats.friden@axis.com> ++ * ++ * This program is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU General Public License ++ * as published by the Free Software Foundation; either version 2 ++ * of the License, or (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ++ * ++ * Exceptionally, Axis Communications AB grants discretionary and ++ * conditional permissions for additional use of the text contained ++ * in the company's release of the AXIS OpenBT Stack under the ++ * provisions set forth hereunder. ++ * ++ * Provided that, if you use the AXIS OpenBT Stack with other files, ++ * that do not implement functionality as specified in the Bluetooth ++ * System specification, to produce an executable, this does not by ++ * itself cause the resulting executable to be covered by the GNU ++ * General Public License. Your use of that executable is in no way ++ * restricted on account of using the AXIS OpenBT Stack code with it. ++ * ++ * This exception does not however invalidate any other reasons why ++ * the executable file might be covered by the provisions of the GNU ++ * General Public License. ++ * ++ */ ++/* ++ * Copyright (C) 2002 Motorola ++ * ++ * 07/28/2002 Initial version based on rfcomm.c ++ * 11/18/2002 Modified ++ */ ++ ++#include <linux/config.h> ++#include <linux/module.h> ++ ++#include <linux/errno.h> ++#include <linux/sched.h> ++#include <linux/interrupt.h> ++#include <linux/tty.h> ++#include <linux/tty_flip.h> ++#include <linux/fcntl.h> ++#include <linux/string.h> ++#include <linux/major.h> ++#include <linux/mm.h> ++#include <linux/init.h> ++#include <linux/devfs_fs_kernel.h> ++ ++#include <asm/uaccess.h> ++#include <asm/system.h> ++#include <asm/bitops.h> ++ ++#include <asm/byteorder.h> ++#include <asm/types.h> ++ ++#define TS0710_MAX_CHN 14 ++ ++#define SET_PF(ctr) ((ctr) | (1 << 4)) ++#define CLR_PF(ctr) ((ctr) & 0xef) ++#define GET_PF(ctr) (((ctr) >> 4) & 0x1) ++ ++#define GET_PN_MSG_FRAME_SIZE(pn) ( ((pn)->frame_sizeh << 8) | ((pn)->frame_sizel)) ++#define SET_PN_MSG_FRAME_SIZE(pn, size) ({ (pn)->frame_sizel = (size) & 0xff; \ ++ (pn)->frame_sizeh = (size) >> 8; }) ++ ++#define GET_LONG_LENGTH(a) ( ((a).h_len << 7) | ((a).l_len) ) ++#define SET_LONG_LENGTH(a, length) ({ (a).ea = 0; \ ++ (a).l_len = length & 0x7F; \ ++ (a).h_len = (length >> 7) & 0xFF; }) ++ ++#define SHORT_CRC_CHECK 3 ++#define LONG_CRC_CHECK 4 ++ ++/* FIXME: Should thsi one be define here? */ ++#define SHORT_PAYLOAD_SIZE 127 ++ ++#define EA 1 ++#define FCS_SIZE 1 ++#define FLAG_SIZE 2 ++ ++#define TS0710_MAX_HDR_SIZE 5 ++#define DEF_TS0710_MTU 256 ++ ++#define TS0710_BASIC_FLAG 0xF9 ++/* the control field */ ++#define SABM 0x2f ++#define SABM_SIZE 4 ++#define UA 0x63 ++#define UA_SIZE 4 ++#define DM 0x0f ++#define DISC 0x43 ++#define UIH 0xef ++ ++/* the type field in a multiplexer command packet */ ++#define TEST 0x8 ++#define FCON 0x28 ++#define FCOFF 0x18 ++#define MSC 0x38 ++#define RPN 0x24 ++#define RLS 0x14 ++#define PN 0x20 ++#define NSC 0x4 ++ ++/* V.24 modem control signals */ ++#define FC 0x2 ++#define RTC 0x4 ++#define RTR 0x8 ++#define IC 0x40 ++#define DV 0x80 ++ ++#define CTRL_CHAN 0 /* The control channel is defined as DLCI 0 */ ++#define MCC_CMD 1 /* Multiplexer command cr */ ++#define MCC_RSP 0 /* Multiplexer response cr */ ++ ++#ifdef __LITTLE_ENDIAN_BITFIELD ++ ++typedef struct { ++ __u8 ea:1; ++ __u8 cr:1; ++ __u8 d:1; ++ __u8 server_chn:5; ++} __attribute__ ((packed)) address_field; ++ ++typedef struct { ++ __u8 ea:1; ++ __u8 len:7; ++} __attribute__ ((packed)) short_length; ++ ++typedef struct { ++ __u8 ea:1; ++ __u8 l_len:7; ++ __u8 h_len; ++} __attribute__ ((packed)) long_length; ++ ++typedef struct { ++ address_field addr; ++ __u8 control; ++ short_length length; ++} __attribute__ ((packed)) short_frame_head; ++ ++typedef struct { ++ short_frame_head h; ++ __u8 data[0]; ++} __attribute__ ((packed)) short_frame; ++ ++typedef struct { ++ address_field addr; ++ __u8 control; ++ long_length length; ++ __u8 data[0]; ++} __attribute__ ((packed)) long_frame_head; ++ ++typedef struct { ++ long_frame_head h; ++ __u8 data[0]; ++} __attribute__ ((packed)) long_frame; ++ ++/* Typedefinitions for structures used for the multiplexer commands */ ++typedef struct { ++ __u8 ea:1; ++ __u8 cr:1; ++ __u8 type:6; ++} __attribute__ ((packed)) mcc_type; ++ ++typedef struct { ++ mcc_type type; ++ short_length length; ++ __u8 value[0]; ++} __attribute__ ((packed)) mcc_short_frame_head; ++ ++typedef struct { ++ mcc_short_frame_head h; ++ __u8 value[0]; ++} __attribute__ ((packed)) mcc_short_frame; ++ ++typedef struct { ++ mcc_type type; ++ long_length length; ++ __u8 value[0]; ++} __attribute__ ((packed)) mcc_long_frame_head; ++ ++typedef struct { ++ mcc_long_frame_head h; ++ __u8 value[0]; ++} __attribute__ ((packed)) mcc_long_frame; ++ ++/* MSC-command */ ++typedef struct { ++ __u8 ea:1; ++ __u8 fc:1; ++ __u8 rtc:1; ++ __u8 rtr:1; ++ __u8 reserved:2; ++ __u8 ic:1; ++ __u8 dv:1; ++} __attribute__ ((packed)) v24_sigs; ++ ++typedef struct { ++ __u8 ea:1; ++ __u8 b1:1; ++ __u8 b2:1; ++ __u8 b3:1; ++ __u8 len:4; ++} __attribute__ ((packed)) brk_sigs; ++ ++typedef struct { ++ short_frame_head s_head; ++ mcc_short_frame_head mcc_s_head; ++ address_field dlci; ++ __u8 v24_sigs; ++ //brk_sigs break_signals; ++ __u8 fcs; ++} __attribute__ ((packed)) msc_msg; ++ ++#if 0 ++/* conflict with termios.h */ ++/* RPN command */ ++#define B2400 0 ++#define B4800 1 ++#define B7200 2 ++#define B9600 3 ++#define B19200 4 ++#define B38400 5 ++#define B57600 6 ++#define B115200 7 ++#define D230400 8 ++#endif ++ ++/* ++typedef struct{ ++ __u8 bit_rate:1; ++ __u8 data_bits:1; ++ __u8 stop_bit:1; ++ __u8 parity:1; ++ __u8 parity_type:1; ++ __u8 xon_u8:1; ++ __u8 xoff_u8:1; ++ __u8 res1:1; ++ __u8 xon_input:1; ++ __u8 xon_output:1; ++ __u8 rtr_input:1; ++ __u8 rtr_output:1; ++ __u8 rtc_input:1; ++ __u8 rtc_output:1; ++ __u8 res2:2; ++} __attribute__((packed)) parameter_mask; ++ ++typedef struct{ ++ __u8 bit_rate; ++ __u8 data_bits:2; ++ __u8 stop_bit:1; ++ __u8 parity:1; ++ __u8 parity_type:2; ++ __u8 res1:2; ++ __u8 xon_input:1; ++ __u8 xon_output:1; ++ __u8 rtr_input:1; ++ __u8 rtr_output:1; ++ __u8 rtc_input:1; ++ __u8 rtc_output:1; ++ __u8 res2:2; ++ __u8 xon_u8; ++ __u8 xoff_u8; ++ parameter_mask pm; ++} __attribute__((packed)) rpn_values; ++ ++typedef struct{ ++ short_frame_head s_head; ++ mcc_short_frame_head mcc_s_head; ++ address_field dlci; ++ rpn_values rpn_val; ++ __u8 fcs; ++} __attribute__((packed)) rpn_msg; ++*/ ++ ++/* RLS-command */ ++/* ++typedef struct{ ++ short_frame_head s_head; ++ mcc_short_frame_head mcc_s_head; ++ address_field dlci; ++ __u8 error:4; ++ __u8 res:4; ++ __u8 fcs; ++} __attribute__((packed)) rls_msg; ++*/ ++ ++/* PN-command */ ++typedef struct { ++ short_frame_head s_head; ++ mcc_short_frame_head mcc_s_head; ++ __u8 dlci:6; ++ __u8 res1:2; ++ __u8 frame_type:4; ++ __u8 credit_flow:4; ++ __u8 prior:6; ++ __u8 res2:2; ++ __u8 ack_timer; ++ __u8 frame_sizel; ++ __u8 frame_sizeh; ++ __u8 max_nbrof_retrans; ++ __u8 credits; ++ __u8 fcs; ++} __attribute__ ((packed)) pn_msg; ++ ++/* NSC-command */ ++typedef struct { ++ short_frame_head s_head; ++ mcc_short_frame_head mcc_s_head; ++ mcc_type command_type; ++ __u8 fcs; ++} __attribute__ ((packed)) nsc_msg; ++ ++#else ++#error Only littel-endianess supported now! ++#endif ++ ++enum { ++ REJECTED = 0, ++ DISCONNECTED, ++ CONNECTING, ++ NEGOTIATING, ++ CONNECTED, ++ DISCONNECTING, ++ FLOW_STOPPED ++}; ++ ++enum ts0710_events { ++ CONNECT_IND, ++ CONNECT_CFM, ++ DISCONN_CFM ++}; ++ ++typedef struct { ++ volatile __u8 state; ++ volatile __u8 flow_control; ++ volatile __u8 initiated; ++ volatile __u8 initiator; ++ volatile __u16 mtu; ++ wait_queue_head_t open_wait; ++ wait_queue_head_t close_wait; ++} dlci_struct; ++ ++/* user space interfaces */ ++typedef struct { ++ volatile __u8 initiator; ++ volatile __u8 c_dlci; ++ volatile __u16 mtu; ++ volatile __u8 be_testing; ++ volatile __u32 test_errs; ++ wait_queue_head_t test_wait; ++ ++ dlci_struct dlci[TS0710_MAX_CHN]; ++} ts0710_con; +Index: linux-2.6.21/drivers/char/ts0710_mux.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ linux-2.6.21/drivers/char/ts0710_mux.c 2007-04-26 20:09:29.000000000 +0200 +@@ -0,0 +1,3966 @@ ++/* ++ * File: mux_driver.c ++ * ++ * Portions derived from rfcomm.c, original header as follows: ++ * ++ * Copyright (C) 2000, 2001 Axis Communications AB ++ * ++ * Author: Mats Friden <mats.friden@axis.com> ++ * ++ * This program is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU General Public License ++ * as published by the Free Software Foundation; either version 2 ++ * of the License, or (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ++ * ++ * Exceptionally, Axis Communications AB grants discretionary and ++ * conditional permissions for additional use of the text contained ++ * in the company's release of the AXIS OpenBT Stack under the ++ * provisions set forth hereunder. ++ * ++ * Provided that, if you use the AXIS OpenBT Stack with other files, ++ * that do not implement functionality as specified in the Bluetooth ++ * System specification, to produce an executable, this does not by ++ * itself cause the resulting executable to be covered by the GNU ++ * General Public License. Your use of that executable is in no way ++ * restricted on account of using the AXIS OpenBT Stack code with it. ++ * ++ * This exception does not however invalidate any other reasons why ++ * the executable file might be covered by the provisions of the GNU ++ * General Public License. ++ * ++ */ ++/* ++ * Copyright (C) 2002-2004 Motorola ++ * Copyright (C) 2006 Harald Welte <laforge@openezx.org> ++ * ++ * 07/28/2002 Initial version ++ * 11/18/2002 Second version ++ * 04/21/2004 Add GPRS PROC ++ */ ++#include <linux/config.h> ++#include <linux/module.h> ++#include <linux/types.h> ++ ++#include <linux/kernel.h> ++#include <linux/proc_fs.h> ++ ++#define USB_FOR_MUX ++ ++#ifndef USB_FOR_MUX ++#include <linux/serial.h> ++#endif ++ ++#include <linux/errno.h> ++#include <linux/sched.h> ++#include <linux/interrupt.h> ++#include <linux/tty.h> ++#include <linux/tty_flip.h> ++#include <linux/fcntl.h> ++#include <linux/string.h> ++#include <linux/major.h> ++#include <linux/mm.h> ++#include <linux/slab.h> ++#include <linux/init.h> ++#include <linux/devfs_fs_kernel.h> ++//#include <syslog.h> ++ ++#include <asm/uaccess.h> ++#include <asm/system.h> ++#include <asm/bitops.h> ++ ++#ifdef USB_FOR_MUX ++//#include <linux/usb.h> ++#include "ts0710_mux_usb.h" ++#endif ++ ++#include "ts0710.h" ++#include "ts0710_mux.h" ++ ++#define TS0710MUX_GPRS_SESSION_MAX 2 ++#define TS0710MUX_MAJOR 250 ++#define TS0710MUX_MINOR_START 0 ++#define NR_MUXS 16 ++ ++ /*#define TS0710MUX_TIME_OUT 30 *//* 300ms */ ++#define TS0710MUX_TIME_OUT 250 /* 2500ms, for BP UART hardware flow control AP UART */ ++ ++#define TS0710MUX_IO_DLCI_FC_ON 0x54F2 ++#define TS0710MUX_IO_DLCI_FC_OFF 0x54F3 ++#define TS0710MUX_IO_FC_ON 0x54F4 ++#define TS0710MUX_IO_FC_OFF 0x54F5 ++ ++#define TS0710MUX_MAX_BUF_SIZE 2048 ++ ++#define TS0710MUX_SEND_BUF_OFFSET 10 ++#define TS0710MUX_SEND_BUF_SIZE (DEF_TS0710_MTU + TS0710MUX_SEND_BUF_OFFSET + 34) ++#define TS0710MUX_RECV_BUF_SIZE TS0710MUX_SEND_BUF_SIZE ++ ++/*For BP UART problem Begin*/ ++#ifdef TS0710SEQ2 ++#define ACK_SPACE 66 /* 6 * 11(ACK frame size) */ ++#else ++#define ACK_SPACE 42 /* 6 * 7(ACK frame size) */ ++#endif ++/*For BP UART problem End*/ ++ ++ /*#define TS0710MUX_SERIAL_BUF_SIZE (DEF_TS0710_MTU + TS0710_MAX_HDR_SIZE)*//* For BP UART problem */ ++#define TS0710MUX_SERIAL_BUF_SIZE (DEF_TS0710_MTU + TS0710_MAX_HDR_SIZE + ACK_SPACE) /* For BP UART problem: ACK_SPACE */ ++ ++#define TS0710MUX_MAX_TOTAL_FRAME_SIZE (DEF_TS0710_MTU + TS0710_MAX_HDR_SIZE + FLAG_SIZE) ++#define TS0710MUX_MAX_CHARS_IN_BUF 65535 ++#define TS0710MUX_THROTTLE_THRESHOLD DEF_TS0710_MTU ++ ++#define TEST_PATTERN_SIZE 250 ++ ++#define CMDTAG 0x55 ++#define DATATAG 0xAA ++ ++#define ACK 0x4F /*For BP UART problem */ ++ ++/*For BP UART problem Begin*/ ++#ifdef TS0710SEQ2 ++#define FIRST_BP_SEQ_OFFSET 1 /*offset from start flag */ ++#define SECOND_BP_SEQ_OFFSET 2 /*offset from start flag */ ++#define FIRST_AP_SEQ_OFFSET 3 /*offset from start flag */ ++#define SECOND_AP_SEQ_OFFSET 4 /*offset from start flag */ ++#define SLIDE_BP_SEQ_OFFSET 5 /*offset from start flag */ ++#define SEQ_FIELD_SIZE 5 ++#else ++#define SLIDE_BP_SEQ_OFFSET 1 /*offset from start flag */ ++#define SEQ_FIELD_SIZE 1 ++#endif ++ ++#define ADDRESS_FIELD_OFFSET (1 + SEQ_FIELD_SIZE) /*offset from start flag */ ++/*For BP UART problem End*/ ++ ++#ifndef UNUSED_PARAM ++#define UNUSED_PARAM(v) (void)(v) ++#endif ++ ++#define TS0710MUX_GPRS1_DLCI 7 ++#define TS0710MUX_GPRS2_DLCI 8 ++ ++#define TS0710MUX_GPRS1_RECV_COUNT_IDX 0 ++#define TS0710MUX_GPRS1_SEND_COUNT_IDX 1 ++#define TS0710MUX_GPRS2_RECV_COUNT_IDX 2 ++#define TS0710MUX_GPRS2_SEND_COUNT_IDX 3 ++#define TS0710MUX_COUNT_MAX_IDX 3 ++#define TS0710MUX_COUNT_IDX_NUM (TS0710MUX_COUNT_MAX_IDX + 1) ++ ++static volatile int mux_data_count[TS0710MUX_COUNT_IDX_NUM] = { 0, 0, 0, 0 }; ++static volatile int mux_data_count2[TS0710MUX_COUNT_IDX_NUM] = { 0, 0, 0, 0 }; ++static struct semaphore mux_data_count_mutex[TS0710MUX_COUNT_IDX_NUM]; ++static volatile __u8 post_recv_count_flag = 0; ++ ++/*PROC file*/ ++struct proc_dir_entry *gprs_proc_file = NULL; ++ssize_t file_proc_read(struct file *file, char *buf, size_t size, ++ loff_t * ppos); ++ssize_t file_proc_write(struct file *file, const char *buf, size_t count, ++ loff_t * ppos); ++struct file_operations file_proc_operations = { ++ read:file_proc_read, ++ write:file_proc_write, ++}; ++typedef struct { ++ int recvBytes; ++ int sentBytes; ++} gprs_bytes; ++ ++static __u8 tty2dlci[NR_MUXS] = ++ { 1, 2, 3, 4, 5, 6, 7, 8, 6, 7, 8, 9, 10, 11, 12, 13 }; ++static __u8 iscmdtty[NR_MUXS] = ++ { 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 }; ++typedef struct { ++ __u8 cmdtty; ++ __u8 datatty; ++} dlci_tty; ++static dlci_tty dlci2tty[] = { {0, 0}, /* DLCI 0 */ ++{0, 0}, /* DLCI 1 */ ++{1, 1}, /* DLCI 2 */ ++{2, 2}, /* DLCI 3 */ ++{3, 3}, /* DLCI 4 */ ++{4, 4}, /* DLCI 5 */ ++{5, 8}, /* DLCI 6 */ ++{6, 9}, /* DLCI 7 */ ++{7, 10}, /* DLCI 8 */ ++{11, 11}, /* DLCI 9 */ ++{12, 12}, /* DLCI 10 */ ++{13, 13}, /* DLCI 11 */ ++{14, 14}, /* DLCI 12 */ ++{15, 15} ++}; /* DLCI 13 */ ++ ++typedef struct { ++ volatile __u8 buf[TS0710MUX_SEND_BUF_SIZE]; ++ volatile __u8 *frame; ++ unsigned long flags; ++ volatile __u16 length; ++ volatile __u8 filled; ++ volatile __u8 dummy; /* Allignment to 4*n bytes */ ++} mux_send_struct; ++ ++/* Bit number in flags of mux_send_struct */ ++#define BUF_BUSY 0 ++ ++struct mux_recv_packet_tag { ++ __u8 *data; ++ __u32 length; ++ struct mux_recv_packet_tag *next; ++}; ++typedef struct mux_recv_packet_tag mux_recv_packet; ++ ++struct mux_recv_struct_tag { ++ __u8 data[TS0710MUX_RECV_BUF_SIZE]; ++ __u32 length; ++ __u32 total; ++ mux_recv_packet *mux_packet; ++ struct mux_recv_struct_tag *next; ++ int no_tty; ++ volatile __u8 post_unthrottle; ++}; ++typedef struct mux_recv_struct_tag mux_recv_struct; ++ ++#define RECV_RUNNING 0 ++static unsigned long mux_recv_flags = 0; ++ ++static mux_send_struct *mux_send_info[NR_MUXS]; ++static volatile __u8 mux_send_info_flags[NR_MUXS]; ++static volatile __u8 mux_send_info_idx = NR_MUXS; ++ ++static mux_recv_struct *mux_recv_info[NR_MUXS]; ++static volatile __u8 mux_recv_info_flags[NR_MUXS]; ++static mux_recv_struct *mux_recv_queue = NULL; ++ ++static struct tty_driver mux_driver; ++ ++#ifdef USB_FOR_MUX ++#define COMM_FOR_MUX_DRIVER usb_for_mux_driver ++#define COMM_FOR_MUX_TTY usb_for_mux_tty ++#define COMM_MUX_DISPATCHER usb_mux_dispatcher ++#define COMM_MUX_SENDER usb_mux_sender ++#else ++#define COMM_FOR_MUX_DRIVER serial_for_mux_driver ++#define COMM_FOR_MUX_TTY serial_for_mux_tty ++#define COMM_MUX_DISPATCHER serial_mux_dispatcher ++#define COMM_MUX_SENDER serial_mux_sender ++ ++extern struct list_head *tq_serial_for_mux; ++#endif ++ ++extern struct tty_driver *COMM_FOR_MUX_DRIVER; ++extern struct tty_struct *COMM_FOR_MUX_TTY; ++extern void (*COMM_MUX_DISPATCHER) (struct tty_struct * tty); ++extern void (*COMM_MUX_SENDER) (void); ++ ++static struct work_struct send_tqueue; ++static struct work_struct receive_tqueue; ++static struct work_struct post_recv_tqueue; ++ ++static struct tty_struct *mux_table[NR_MUXS]; ++static struct termios *mux_termios[NR_MUXS]; ++static struct termios *mux_termios_locked[NR_MUXS]; ++static volatile short int mux_tty[NR_MUXS]; ++ ++#ifdef min ++#undef min ++#define min(a,b) ( (a)<(b) ? (a):(b) ) ++#endif ++ ++static int get_count(__u8 idx); ++static int set_count(__u8 idx, int count); ++static int add_count(__u8 idx, int count); ++ ++static int send_ua(ts0710_con * ts0710, __u8 dlci); ++static int send_dm(ts0710_con * ts0710, __u8 dlci); ++static int send_sabm(ts0710_con * ts0710, __u8 dlci); ++static int send_disc(ts0710_con * ts0710, __u8 dlci); ++static void queue_uih(mux_send_struct * send_info, __u16 len, ++ ts0710_con * ts0710, __u8 dlci); ++static int send_pn_msg(ts0710_con * ts0710, __u8 prior, __u32 frame_size, ++ __u8 credit_flow, __u8 credits, __u8 dlci, __u8 cr); ++static int send_nsc_msg(ts0710_con * ts0710, mcc_type cmd, __u8 cr); ++static void set_uih_hdr(short_frame * uih_pkt, __u8 dlci, __u32 len, __u8 cr); ++ ++static __u32 crc_check(__u8 * data, __u32 length, __u8 check_sum); ++static __u8 crc_calc(__u8 * data, __u32 length); ++static void create_crctable(__u8 table[]); ++ ++static void mux_sched_send(void); ++ ++static __u8 crctable[256]; ++ ++static ts0710_con ts0710_connection; ++/* ++static rpn_values rpn_val; ++*/ ++ ++static int valid_dlci(__u8 dlci) ++{ ++ if ((dlci < TS0710_MAX_CHN) && (dlci > 0)) ++ return 1; ++ else ++ return 0; ++} ++ ++#ifdef TS0710DEBUG ++ ++#ifdef PRINT_OUTPUT_PRINTK ++#define TS0710_DEBUG(fmt, arg...) printk(KERN_INFO "MUX " __FUNCTION__ ": " fmt "\n" , ## arg) ++#else ++#include "ezxlog.h" ++static __u8 strDebug[256]; ++#define TS0710_DEBUG(fmt, arg...) ({ snprintf(strDebug, sizeof(strDebug), "MUX " __FUNCTION__ ": " fmt "\n" , ## arg); \ ++ /*printk("%s", strDebug)*/ezxlogk("MX", strDebug, strlen(strDebug)); }) ++#endif /* End #ifdef PRINT_OUTPUT_PRINTK */ ++ ++#else ++#define TS0710_DEBUG(fmt...) ++#endif /* End #ifdef TS0710DEBUG */ ++ ++#ifdef TS0710LOG ++static unsigned char g_tbuf[TS0710MUX_MAX_BUF_SIZE]; ++#ifdef PRINT_OUTPUT_PRINTK ++#define TS0710_LOG(fmt, arg...) printk(fmt, ## arg) ++#define TS0710_PRINTK(fmt, arg...) printk(fmt, ## arg) ++#else ++#include "ezxlog.h" ++static __u8 strLog[256]; ++#define TS0710_LOG(fmt, arg...) ({ snprintf(strLog, sizeof(strLog), fmt, ## arg); \ ++ /*printk("%s", strLog)*/ezxlogk("MX", strLog, strlen(strLog)); }) ++#define TS0710_PRINTK(fmt, arg...) ({ printk(fmt, ## arg); \ ++ TS0710_LOG(fmt, ## arg); }) ++#endif /* End #ifdef PRINT_OUTPUT_PRINTK */ ++ ++#else ++#define TS0710_LOG(fmt...) ++#define TS0710_PRINTK(fmt, arg...) printk(fmt, ## arg) ++#endif /* End #ifdef TS0710LOG */ ++ ++#ifdef TS0710DEBUG ++static void TS0710_DEBUGHEX(__u8 * buf, int len) ++{ ++ static unsigned char tbuf[TS0710MUX_MAX_BUF_SIZE]; ++ ++ int i; ++ int c; ++ ++ if (len <= 0) { ++ return; ++ } ++ ++ c = 0; ++ for (i = 0; (i < len) && (c < (TS0710MUX_MAX_BUF_SIZE - 3)); i++) { ++ sprintf(&tbuf[c], "%02x ", buf[i]); ++ c += 3; ++ } ++ tbuf[c] = 0; ++ ++#ifdef PRINT_OUTPUT_PRINTK ++ TS0710_DEBUG("%s", tbuf); ++#else ++ /*printk("%s\n", tbuf) */ ezxlogk("MX", tbuf, c); ++#endif ++} ++static void TS0710_DEBUGSTR(__u8 * buf, int len) ++{ ++ static unsigned char tbuf[TS0710MUX_MAX_BUF_SIZE]; ++ ++ if (len <= 0) { ++ return; ++ } ++ ++ if (len > (TS0710MUX_MAX_BUF_SIZE - 1)) { ++ len = (TS0710MUX_MAX_BUF_SIZE - 1); ++ } ++ ++ memcpy(tbuf, buf, len); ++ tbuf[len] = 0; ++ ++#ifdef PRINT_OUTPUT_PRINTK ++ /* 0x00 byte in the string pointed by tbuf may truncate the print result */ ++ TS0710_DEBUG("%s", tbuf); ++#else ++ /*printk("%s\n", tbuf) */ ezxlogk("MX", tbuf, len); ++#endif ++} ++#else ++#define TS0710_DEBUGHEX(buf, len) ++#define TS0710_DEBUGSTR(buf, len) ++#endif /* End #ifdef TS0710DEBUG */ ++ ++#ifdef TS0710LOG ++static void TS0710_LOGSTR_FRAME(__u8 send, __u8 * data, int len) ++{ ++ short_frame *short_pkt; ++ long_frame *long_pkt; ++ __u8 *uih_data_start; ++ __u32 uih_len; ++ __u8 dlci; ++ int pos; ++ ++ if (len <= 0) { ++ return; ++ } ++ ++ pos = 0; ++ if (send) { ++ pos += sprintf(&g_tbuf[pos], "<"); ++ short_pkt = (short_frame *) (data + 1); /*For BP UART problem */ ++ } else { ++ /*For BP UART problem */ ++ /*pos += sprintf(&g_tbuf[pos], ">"); */ ++ pos += sprintf(&g_tbuf[pos], ">%d ", *(data + SLIDE_BP_SEQ_OFFSET)); /*For BP UART problem */ ++ ++#ifdef TS0710SEQ2 ++ pos += sprintf(&g_tbuf[pos], "%02x %02x %02x %02x ", *(data + FIRST_BP_SEQ_OFFSET), *(data + SECOND_BP_SEQ_OFFSET), *(data + FIRST_AP_SEQ_OFFSET), *(data + SECOND_AP_SEQ_OFFSET)); /*For BP UART problem */ ++#endif ++ ++ short_pkt = (short_frame *) (data + ADDRESS_FIELD_OFFSET); /*For BP UART problem */ ++ } ++ ++ /*For BP UART problem */ ++ /*short_pkt = (short_frame *)(data + 1); */ ++ ++ dlci = short_pkt->h.addr.server_chn << 1 | short_pkt->h.addr.d; ++ switch (CLR_PF(short_pkt->h.control)) { ++ case SABM: ++ pos += sprintf(&g_tbuf[pos], "C SABM %d ::", dlci); ++ break; ++ case UA: ++ pos += sprintf(&g_tbuf[pos], "C UA %d ::", dlci); ++ break; ++ case DM: ++ pos += sprintf(&g_tbuf[pos], "C DM %d ::", dlci); ++ break; ++ case DISC: ++ pos += sprintf(&g_tbuf[pos], "C DISC %d ::", dlci); ++ break; ++ ++ /*For BP UART problem Begin */ ++ case ACK: ++ pos += sprintf(&g_tbuf[pos], "C ACK %d ", short_pkt->data[0]); ++ ++#ifdef TS0710SEQ2 ++ pos += sprintf(&g_tbuf[pos], "%02x %02x %02x %02x ", short_pkt->data[1], short_pkt->data[2], short_pkt->data[3], short_pkt->data[4]); /*For BP UART problem */ ++#endif ++ ++ pos += sprintf(&g_tbuf[pos], "::"); ++ break; ++ /*For BP UART problem End */ ++ ++ case UIH: ++ if (!dlci) { ++ pos += sprintf(&g_tbuf[pos], "C MCC %d ::", dlci); ++ } else { ++ ++ if ((short_pkt->h.length.ea) == 0) { ++ long_pkt = (long_frame *) short_pkt; ++ uih_len = GET_LONG_LENGTH(long_pkt->h.length); ++ uih_data_start = long_pkt->h.data; ++ } else { ++ uih_len = short_pkt->h.length.len; ++ uih_data_start = short_pkt->data; ++ } ++ switch (*uih_data_start) { ++ case CMDTAG: ++ pos += ++ sprintf(&g_tbuf[pos], "I %d A %d ::", dlci, ++ uih_len); ++ break; ++ case DATATAG: ++ default: ++ pos += ++ sprintf(&g_tbuf[pos], "I %d D %d ::", dlci, ++ uih_len); ++ break; ++ } ++ ++ } ++ break; ++ default: ++ pos += sprintf(&g_tbuf[pos], "N!!! %d ::", dlci); ++ break; ++ } ++ ++ if (len > (sizeof(g_tbuf) - pos - 1)) { ++ len = (sizeof(g_tbuf) - pos - 1); ++ } ++ ++ memcpy(&g_tbuf[pos], data, len); ++ pos += len; ++ g_tbuf[pos] = 0; ++ ++#ifdef PRINT_OUTPUT_PRINTK ++ /* 0x00 byte in the string pointed by g_tbuf may truncate the print result */ ++ TS0710_LOG("%s\n", g_tbuf); ++#else ++ /*printk("%s\n", g_tbuf) */ ezxlogk("MX", g_tbuf, pos); ++#endif ++} ++#else ++#define TS0710_LOGSTR_FRAME(send, data, len) ++#endif ++ ++#ifdef TS0710SIG ++#define my_for_each_task(p) \ ++ for ((p) = current; ((p) = (p)->next_task) != current; ) ++ ++static void TS0710_SIG2APLOGD(void) ++{ ++ struct task_struct *p; ++ static __u8 sig = 0; ++ ++ if (sig) { ++ return; ++ } ++ ++ read_lock(&tasklist_lock); ++ my_for_each_task(p) { ++ if (strncmp(p->comm, "aplogd", 6) == 0) { ++ sig = 1; ++ if (send_sig(SIGUSR2, p, 1) == 0) { ++ TS0710_PRINTK ++ ("MUX: success to send SIGUSR2 to aplogd!\n"); ++ } else { ++ TS0710_PRINTK ++ ("MUX: failure to send SIGUSR2 to aplogd!\n"); ++ } ++ break; ++ } ++ } ++ read_unlock(&tasklist_lock); ++ ++ if (!sig) { ++ TS0710_PRINTK("MUX: not found aplogd!\n"); ++ } ++} ++#else ++#define TS0710_SIG2APLOGD() ++#endif ++ ++static int basic_write(ts0710_con * ts0710, __u8 * buf, int len) ++{ ++ int res; ++ ++ UNUSED_PARAM(ts0710); ++ ++ buf[0] = TS0710_BASIC_FLAG; ++ buf[len + 1] = TS0710_BASIC_FLAG; ++ ++ if ((COMM_FOR_MUX_DRIVER == 0) || (COMM_FOR_MUX_TTY == 0)) { ++ TS0710_PRINTK ++ ("MUX basic_write: (COMM_FOR_MUX_DRIVER == 0) || (COMM_FOR_MUX_TTY == 0)\n"); ++ ++#ifndef USB_FOR_MUX ++ TS0710_PRINTK ++ ("MUX basic_write: tapisrv might be down!!! (serial_for_mux_driver == 0) || (serial_for_mux_tty == 0)\n"); ++ TS0710_SIG2APLOGD(); ++#endif ++ ++ return -1; ++ } ++ ++ TS0710_LOGSTR_FRAME(1, buf, len + 2); ++ TS0710_DEBUGHEX(buf, len + 2); ++ ++ res = COMM_FOR_MUX_DRIVER->write(COMM_FOR_MUX_TTY, buf, len + 2); ++ ++ if (res != len + 2) { ++ TS0710_PRINTK("MUX basic_write: Write Error!\n"); ++ return -1; ++ } ++ ++ return len + 2; ++} ++ ++/* Functions for the crc-check and calculation */ ++ ++#define CRC_VALID 0xcf ++ ++static __u32 crc_check(__u8 * data, __u32 length, __u8 check_sum) ++{ ++ __u8 fcs = 0xff; ++ ++ while (length--) { ++ fcs = crctable[fcs ^ *data++]; ++ } ++ fcs = crctable[fcs ^ check_sum]; ++ TS0710_DEBUG("fcs : %d\n", fcs); ++ if (fcs == (uint) 0xcf) { /*CRC_VALID) */ ++ TS0710_DEBUG("crc_check: CRC check OK\n"); ++ return 0; ++ } else { ++ TS0710_PRINTK("MUX crc_check: CRC check failed\n"); ++ return 1; ++ } ++} ++ ++/* Calculates the checksum according to the ts0710 specification */ ++ ++static __u8 crc_calc(__u8 * data, __u32 length) ++{ ++ __u8 fcs = 0xff; ++ ++ while (length--) { ++ fcs = crctable[fcs ^ *data++]; ++ } ++ ++ return 0xff - fcs; ++} ++ ++/* Calulates a reversed CRC table for the FCS check */ ++ ++static void create_crctable(__u8 table[]) ++{ ++ int i, j; ++ ++ __u8 data; ++ __u8 code_word = (__u8) 0xe0; ++ __u8 sr = (__u8) 0; ++ ++ for (j = 0; j < 256; j++) { ++ data = (__u8) j; ++ ++ for (i = 0; i < 8; i++) { ++ if ((data & 0x1) ^ (sr & 0x1)) { ++ sr >>= 1; ++ sr ^= code_word; ++ } else { ++ sr >>= 1; ++ } ++ ++ data >>= 1; ++ sr &= 0xff; ++ } ++ ++ table[j] = sr; ++ sr = 0; ++ } ++} ++ ++static void ts0710_reset_dlci(__u8 j) ++{ ++ if (j >= TS0710_MAX_CHN) ++ return; ++ ++ ts0710_connection.dlci[j].state = DISCONNECTED; ++ ts0710_connection.dlci[j].flow_control = 0; ++ ts0710_connection.dlci[j].mtu = DEF_TS0710_MTU; ++ ts0710_connection.dlci[j].initiated = 0; ++ ts0710_connection.dlci[j].initiator = 0; ++ init_waitqueue_head(&ts0710_connection.dlci[j].open_wait); ++ init_waitqueue_head(&ts0710_connection.dlci[j].close_wait); ++} ++ ++static void ts0710_reset_con(void) ++{ ++ __u8 j; ++ ++ ts0710_connection.initiator = 0; ++ ts0710_connection.mtu = DEF_TS0710_MTU + TS0710_MAX_HDR_SIZE; ++ ts0710_connection.be_testing = 0; ++ ts0710_connection.test_errs = 0; ++ init_waitqueue_head(&ts0710_connection.test_wait); ++ ++ for (j = 0; j < TS0710_MAX_CHN; j++) { ++ ts0710_reset_dlci(j); ++ } ++} ++ ++static void ts0710_init(void) ++{ ++ create_crctable(crctable); ++ ++ ts0710_reset_con(); ++ ++ /* Set the values in the rpn octets */ ++/* ++ rpn_val.bit_rate = 7; ++ rpn_val.data_bits = 3; ++ rpn_val.stop_bit = 0; ++ rpn_val.parity = 0; ++ rpn_val.parity_type = 0; ++ rpn_val.res1 = 0; ++ rpn_val.xon_input = 0; ++ rpn_val.xon_output = 0; ++ rpn_val.rtr_input = 0; ++ rpn_val.rtr_output = 0; ++ rpn_val.rtc_input = 0; ++ rpn_val.rtc_output = 0; ++ rpn_val.res2 = 0; ++ rpn_val.xon_u8 = 0x11; ++ rpn_val.xoff_u8 = 0x13; ++ memset(&rpn_val.pm, 0 , 2); *//* Set the mask to zero */ ++} ++ ++static void ts0710_upon_disconnect(void) ++{ ++ ts0710_con *ts0710 = &ts0710_connection; ++ __u8 j; ++ ++ for (j = 0; j < TS0710_MAX_CHN; j++) { ++ ts0710->dlci[j].state = DISCONNECTED; ++ wake_up_interruptible(&ts0710->dlci[j].open_wait); ++ wake_up_interruptible(&ts0710->dlci[j].close_wait); ++ } ++ ts0710->be_testing = 0; ++ wake_up_interruptible(&ts0710->test_wait); ++ ts0710_reset_con(); ++} ++ ++/* Sending packet functions */ ++ ++/* Creates a UA packet and puts it at the beginning of the pkt pointer */ ++ ++static int send_ua(ts0710_con * ts0710, __u8 dlci) ++{ ++ __u8 buf[sizeof(short_frame) + FCS_SIZE + FLAG_SIZE]; ++ short_frame *ua; ++ ++ TS0710_DEBUG("send_ua: Creating UA packet to DLCI %d\n", dlci); ++ ++ ua = (short_frame *) (buf + 1); ++ ua->h.addr.ea = 1; ++ ua->h.addr.cr = ((~(ts0710->initiator)) & 0x1); ++ ua->h.addr.d = (dlci) & 0x1; ++ ua->h.addr.server_chn = (dlci) >> 0x1; ++ ua->h.control = SET_PF(UA); ++ ua->h.length.ea = 1; ++ ua->h.length.len = 0; ++ ua->data[0] = crc_calc((__u8 *) ua, SHORT_CRC_CHECK); ++ ++ return basic_write(ts0710, buf, sizeof(short_frame) + FCS_SIZE); ++} ++ ++/* Creates a DM packet and puts it at the beginning of the pkt pointer */ ++ ++static int send_dm(ts0710_con * ts0710, __u8 dlci) ++{ ++ __u8 buf[sizeof(short_frame) + FCS_SIZE + FLAG_SIZE]; ++ short_frame *dm; ++ ++ TS0710_DEBUG("send_dm: Creating DM packet to DLCI %d\n", dlci); ++ ++ dm = (short_frame *) (buf + 1); ++ dm->h.addr.ea = 1; ++ dm->h.addr.cr = ((~(ts0710->initiator)) & 0x1); ++ dm->h.addr.d = dlci & 0x1; ++ dm->h.addr.server_chn = dlci >> 0x1; ++ dm->h.control = SET_PF(DM); ++ dm->h.length.ea = 1; ++ dm->h.length.len = 0; ++ dm->data[0] = crc_calc((__u8 *) dm, SHORT_CRC_CHECK); ++ ++ return basic_write(ts0710, buf, sizeof(short_frame) + FCS_SIZE); ++} ++ ++static int send_sabm(ts0710_con * ts0710, __u8 dlci |
