65 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
67 #include <linux/kernel.h>
68 #include <linux/errno.h>
71 #include <linux/tty.h>
74 #include <linux/module.h>
81 #ifndef CONFIG_USB_SERIAL_SAFE_PADDED
82 #define CONFIG_USB_SERIAL_SAFE_PADDED 0
89 #define DRIVER_DESC "USB Safe Encapsulated Serial"
108 #define CDC_DEVICE_CLASS 0x02
110 #define CDC_INTERFACE_CLASS 0x02
111 #define CDC_INTERFACE_SUBCLASS 0x06
113 #define LINEO_INTERFACE_CLASS 0xff
115 #define LINEO_INTERFACE_SUBCLASS_SAFENET 0x01
116 #define LINEO_SAFENET_CRC 0x01
117 #define LINEO_SAFENET_CRC_PADDED 0x02
119 #define LINEO_INTERFACE_SUBCLASS_SAFESERIAL 0x02
120 #define LINEO_SAFESERIAL_CRC 0x01
121 #define LINEO_SAFESERIAL_CRC_PADDED 0x02
124 #define MY_USB_DEVICE(vend, prod, dc, ic, isc) \
125 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
126 USB_DEVICE_ID_MATCH_DEV_CLASS | \
127 USB_DEVICE_ID_MATCH_INT_CLASS | \
128 USB_DEVICE_ID_MATCH_INT_SUBCLASS, \
129 .idVendor = (vend), \
130 .idProduct = (prod),\
131 .bDeviceClass = (dc),\
132 .bInterfaceClass = (ic), \
133 .bInterfaceSubClass = (isc),
150 static const __u16 crc10_table[256] = {
151 0x000, 0x233, 0x255, 0x066, 0x299, 0x0aa, 0x0cc, 0x2ff,
152 0x301, 0x132, 0x154, 0x367, 0x198, 0x3ab, 0x3cd, 0x1fe,
153 0x031, 0x202, 0x264, 0x057, 0x2a8, 0x09b, 0x0fd, 0x2ce,
154 0x330, 0x103, 0x165, 0x356, 0x1a9, 0x39a, 0x3fc, 0x1cf,
155 0x062, 0x251, 0x237, 0x004, 0x2fb, 0x0c8, 0x0ae, 0x29d,
156 0x363, 0x150, 0x136, 0x305, 0x1fa, 0x3c9, 0x3af, 0x19c,
157 0x053, 0x260, 0x206, 0x035, 0x2ca, 0x0f9, 0x09f, 0x2ac,
158 0x352, 0x161, 0x107, 0x334, 0x1cb, 0x3f8, 0x39e, 0x1ad,
159 0x0c4, 0x2f7, 0x291, 0x0a2, 0x25d, 0x06e, 0x008, 0x23b,
160 0x3c5, 0x1f6, 0x190, 0x3a3, 0x15c, 0x36f, 0x309, 0x13a,
161 0x0f5, 0x2c6, 0x2a0, 0x093, 0x26c, 0x05f, 0x039, 0x20a,
162 0x3f4, 0x1c7, 0x1a1, 0x392, 0x16d, 0x35e, 0x338, 0x10b,
163 0x0a6, 0x295, 0x2f3, 0x0c0, 0x23f, 0x00c, 0x06a, 0x259,
164 0x3a7, 0x194, 0x1f2, 0x3c1, 0x13e, 0x30d, 0x36b, 0x158,
165 0x097, 0x2a4, 0x2c2, 0x0f1, 0x20e, 0x03d, 0x05b, 0x268,
166 0x396, 0x1a5, 0x1c3, 0x3f0, 0x10f, 0x33c, 0x35a, 0x169,
167 0x188, 0x3bb, 0x3dd, 0x1ee, 0x311, 0x122, 0x144, 0x377,
168 0x289, 0x0ba, 0x0dc, 0x2ef, 0x010, 0x223, 0x245, 0x076,
169 0x1b9, 0x38a, 0x3ec, 0x1df, 0x320, 0x113, 0x175, 0x346,
170 0x2b8, 0x08b, 0x0ed, 0x2de, 0x021, 0x212, 0x274, 0x047,
171 0x1ea, 0x3d9, 0x3bf, 0x18c, 0x373, 0x140, 0x126, 0x315,
172 0x2eb, 0x0d8, 0x0be, 0x28d, 0x072, 0x241, 0x227, 0x014,
173 0x1db, 0x3e8, 0x38e, 0x1bd, 0x342, 0x171, 0x117, 0x324,
174 0x2da, 0x0e9, 0x08f, 0x2bc, 0x043, 0x270, 0x216, 0x025,
175 0x14c, 0x37f, 0x319, 0x12a, 0x3d5, 0x1e6, 0x180, 0x3b3,
176 0x24d, 0x07e, 0x018, 0x22b, 0x0d4, 0x2e7, 0x281, 0x0b2,
177 0x17d, 0x34e, 0x328, 0x11b, 0x3e4, 0x1d7, 0x1b1, 0x382,
178 0x27c, 0x04f, 0x029, 0x21a, 0x0e5, 0x2d6, 0x2b0, 0x083,
179 0x12e, 0x31d, 0x37b, 0x148, 0x3b7, 0x184, 0x1e2, 0x3d1,
180 0x22f, 0x01c, 0x07a, 0x249, 0x0b6, 0x285, 0x2e3, 0x0d0,
181 0x11f, 0x32c, 0x34a, 0x179, 0x386, 0x1b5, 0x1d3, 0x3e0,
182 0x21e, 0x02d, 0x04b, 0x278, 0x087, 0x2b4, 0x2d2, 0x0e1,
185 #define CRC10_INITFCS 0x000
186 #define CRC10_GOODFCS 0x000
187 #define CRC10_FCS(fcs, c) ((((fcs) << 8) & 0x3ff) ^ crc10_table[((fcs) >> 2) & 0xff] ^ (c))
200 for (; len-- > 0; fcs =
CRC10_FCS(fcs, *sp++));
204 static void safe_process_read_urb(
struct urb *
urb)
207 unsigned char *
data = urb->transfer_buffer;
208 unsigned char length = urb->actual_length;
225 dev_err(&port->
dev,
"%s - bad CRC %x\n", __func__, fcs);
229 actual_length = data[length - 2] >> 2;
230 if (actual_length > (length - 2)) {
231 dev_err(&port->
dev,
"%s - inconsistent lengths %d:%d\n",
232 __func__, actual_length, length);
235 dev_info(&urb->dev->dev,
"%s - actual: %d\n", __func__, actual_length);
236 length = actual_length;
238 tty_insert_flip_string(tty, data, length);
253 trailer_len =
safe ? 2 : 0;
263 memset(buf + count,
'0', pkt_len - count - trailer_len);
265 pkt_len = count + trailer_len;
269 buf[pkt_len - 2] = count << 2;
270 buf[pkt_len - 1] = 0;
274 buf[pkt_len - 2] |= fcs >> 8;
275 buf[pkt_len - 1] |= fcs & 0xff;
282 switch (serial->
interface->cur_altsetting->desc.bInterfaceProtocol) {
297 .name =
"safe_serial",
301 .process_read_urb = safe_process_read_urb,
302 .prepare_write_buffer = safe_prepare_write_buffer,
303 .attach = safe_startup,
310 static int __init safe_init(
void)
319 if (!id_table[i].idVendor && !id_table[i].idProduct) {
330 static void __exit safe_exit(
void)