Blame view
drivers/tty/n_gsm.c
79 KB
e3b3d0f54 tty: add SPDX ide... |
1 |
// SPDX-License-Identifier: GPL-2.0 |
e1eaea46b tty: n_gsm line d... |
2 3 4 5 |
/* * n_gsm.c GSM 0710 tty multiplexor * Copyright (c) 2009/10 Intel Corporation * |
e1eaea46b tty: n_gsm line d... |
6 7 8 9 |
* * THIS IS A DEVELOPMENT SNAPSHOT IT IS NOT A FINAL RELEASE * * * TO DO: * Mostly done: ioctls for setting modes/timing |
5f9a31d63 n_gsm: clean up p... |
10 |
* Partly done: hooks so you can pull off frames to non tty devs |
e1eaea46b tty: n_gsm line d... |
11 |
* Restart DLCI 0 when it closes ? |
e1eaea46b tty: n_gsm line d... |
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
* Improve the tx engine * Resolve tx side locking by adding a queue_head and routing * all control traffic via it * General tidy/document * Review the locking/move to refcounts more (mux now moved to an * alloc/free model ready) * Use newest tty open/close port helpers and install hooks * What to do about power functions ? * Termios setting and negotiation * Do we need a 'which mux are you' ioctl to correlate mux and tty sets * */ #include <linux/types.h> #include <linux/major.h> #include <linux/errno.h> #include <linux/signal.h> #include <linux/fcntl.h> |
174cd4b1e sched/headers: Pr... |
30 |
#include <linux/sched/signal.h> |
e1eaea46b tty: n_gsm line d... |
31 32 |
#include <linux/interrupt.h> #include <linux/tty.h> |
e1eaea46b tty: n_gsm line d... |
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
#include <linux/ctype.h> #include <linux/mm.h> #include <linux/string.h> #include <linux/slab.h> #include <linux/poll.h> #include <linux/bitops.h> #include <linux/file.h> #include <linux/uaccess.h> #include <linux/module.h> #include <linux/timer.h> #include <linux/tty_flip.h> #include <linux/tty_driver.h> #include <linux/serial.h> #include <linux/kfifo.h> #include <linux/skbuff.h> |
bcd5abe28 tty: n_gsm: Add r... |
48 49 50 51 |
#include <net/arp.h> #include <linux/ip.h> #include <linux/netdevice.h> #include <linux/etherdevice.h> |
e1eaea46b tty: n_gsm line d... |
52 53 54 55 |
#include <linux/gsmmux.h> static int debug; module_param(debug, int, 0600); |
a8d12007c n_gsm: Fix timings |
56 57 58 59 60 |
/* Defaults: these are from the specification */ #define T1 10 /* 100mS */ #define T2 34 /* 333mS */ #define N2 3 /* Retry 3 times */ |
e1eaea46b tty: n_gsm line d... |
61 62 63 |
/* Use long timers for testing at low speed with debug on */ #ifdef DEBUG_TIMING |
a8d12007c n_gsm: Fix timings |
64 65 |
#define T1 100 #define T2 200 |
e1eaea46b tty: n_gsm line d... |
66 |
#endif |
5f9a31d63 n_gsm: clean up p... |
67 |
/* |
25985edce Fix common misspe... |
68 |
* Semi-arbitrary buffer size limits. 0710 is normally run with 32-64 byte |
5f9a31d63 n_gsm: clean up p... |
69 70 |
* limits so this is plenty */ |
bcd5abe28 tty: n_gsm: Add r... |
71 72 73 74 75 76 |
#define MAX_MRU 1500 #define MAX_MTU 1500 #define GSM_NET_TX_TIMEOUT (HZ*10) /** * struct gsm_mux_net - network interface |
bcd5abe28 tty: n_gsm: Add r... |
77 78 |
* * Created when net interface is initialized. |
724ac070f tty: ldiscs, fix ... |
79 |
*/ |
bcd5abe28 tty: n_gsm: Add r... |
80 81 82 |
struct gsm_mux_net { struct kref ref; struct gsm_dlci *dlci; |
bcd5abe28 tty: n_gsm: Add r... |
83 |
}; |
e1eaea46b tty: n_gsm line d... |
84 85 |
/* * Each block of data we have queued to go out is in the form of |
25985edce Fix common misspe... |
86 |
* a gsm_msg which holds everything we need in a link layer independent |
e1eaea46b tty: n_gsm line d... |
87 88 89 90 |
* format */ struct gsm_msg { |
b4338e1ef n_gsm: avoid acce... |
91 |
struct list_head list; |
e1eaea46b tty: n_gsm line d... |
92 93 94 95 |
u8 addr; /* DLCI address + flags */ u8 ctrl; /* Control byte + flags */ unsigned int len; /* Length of data block (can be zero) */ unsigned char *data; /* Points into buffer but not at the start */ |
2f202d03a tty: n_gsm: Repla... |
96 |
unsigned char buffer[]; |
e1eaea46b tty: n_gsm line d... |
97 |
}; |
72ae8cc19 n_gsm: introduce ... |
98 99 100 101 102 103 |
enum gsm_dlci_state { DLCI_CLOSED, DLCI_OPENING, /* Sending SABM not seen UA */ DLCI_OPEN, /* SABM/UA complete */ DLCI_CLOSING, /* Sending DISC not seen UA/DM */ }; |
e1785996f n_gsm: introduce ... |
104 105 106 107 |
enum gsm_dlci_mode { DLCI_MODE_ABM, /* Normal Asynchronous Balanced Mode */ DLCI_MODE_ADM, /* Asynchronous Disconnected Mode */ }; |
e1eaea46b tty: n_gsm line d... |
108 109 110 111 112 113 114 115 116 117 118 119 120 |
/* * Each active data link has a gsm_dlci structure associated which ties * the link layer to an optional tty (if the tty side is open). To avoid * complexity right now these are only ever freed up when the mux is * shut down. * * At the moment we don't free DLCI objects until the mux is torn down * this avoid object life time issues but might be worth review later. */ struct gsm_dlci { struct gsm_mux *gsm; int addr; |
72ae8cc19 n_gsm: introduce ... |
121 |
enum gsm_dlci_state state; |
bcd5abe28 tty: n_gsm: Add r... |
122 |
struct mutex mutex; |
e1eaea46b tty: n_gsm line d... |
123 124 |
/* Link layer */ |
e1785996f n_gsm: introduce ... |
125 |
enum gsm_dlci_mode mode; |
e1eaea46b tty: n_gsm line d... |
126 127 128 129 130 |
spinlock_t lock; /* Protects the internal state */ struct timer_list t1; /* Retransmit timer for SABM and UA */ int retries; /* Uplink tty if active */ struct tty_port port; /* The tty bound to this DLCI if there is one */ |
036bca1fc n_gsm: drop unnee... |
131 |
struct kfifo fifo; /* Queue fifo for the DLCI */ |
e1eaea46b tty: n_gsm line d... |
132 |
int adaption; /* Adaption layer in use */ |
bcd5abe28 tty: n_gsm: Add r... |
133 |
int prev_adaption; |
e1eaea46b tty: n_gsm line d... |
134 135 |
u32 modem_rx; /* Our incoming virtual modem lines */ u32 modem_tx; /* Our outgoing modem lines */ |
5677fcf37 n_gsm: switch dea... |
136 |
bool dead; /* Refuse re-open */ |
e1eaea46b tty: n_gsm line d... |
137 |
/* Flow control */ |
e9360b9a0 n_gsm: switch thr... |
138 |
bool throttled; /* Private copy of throttle state */ |
7a9ed9c06 n_gsm: switch con... |
139 |
bool constipated; /* Throttle status for outgoing */ |
e1eaea46b tty: n_gsm line d... |
140 141 142 143 |
/* Packetised I/O */ struct sk_buff *skb; /* Frame being sent */ struct sk_buff_head skb_list; /* Queued frames */ /* Data handling callback */ |
4feb7a4a1 n_gsm: Constify u... |
144 145 |
void (*data)(struct gsm_dlci *dlci, const u8 *data, int len); void (*prev_data)(struct gsm_dlci *dlci, const u8 *data, int len); |
bcd5abe28 tty: n_gsm: Add r... |
146 |
struct net_device *net; /* network interface, if created */ |
e1eaea46b tty: n_gsm line d... |
147 |
}; |
c33eecc7a tty: Spelling s/r... |
148 |
/* DLCI 0, 62/63 are special or reserved see gsmtty_open */ |
e1eaea46b tty: n_gsm line d... |
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
#define NUM_DLCI 64 /* * DLCI 0 is used to pass control blocks out of band of the data * flow (and with a higher link priority). One command can be outstanding * at a time and we use this structure to manage them. They are created * and destroyed by the user context, and updated by the receive paths * and timers */ struct gsm_control { u8 cmd; /* Command we are issuing */ u8 *data; /* Data for the command in case we retransmit */ int len; /* Length of block for retransmission */ int done; /* Done flag */ int error; /* Error if any */ }; |
329aa6e6e n_gsm: introduce ... |
167 168 169 170 171 172 173 174 175 176 177 178 179 |
enum gsm_mux_state { GSM_SEARCH, GSM_START, GSM_ADDRESS, GSM_CONTROL, GSM_LEN, GSM_DATA, GSM_FCS, GSM_OVERRUN, GSM_LEN0, GSM_LEN1, GSM_SSOF, }; |
e1eaea46b tty: n_gsm line d... |
180 181 182 183 184 185 186 187 188 189 190 191 192 |
/* * Each GSM mux we have is represented by this structure. If we are * operating as an ldisc then we use this structure as our ldisc * state. We need to sort out lifetimes and locking with respect * to the gsm mux array. For now we don't free DLCI objects that * have been instantiated until the mux itself is terminated. * * To consider further: tty open versus mux shutdown. */ struct gsm_mux { struct tty_struct *tty; /* The tty our ldisc is bound to */ spinlock_t lock; |
dfabf7ffa n_gsm: race betwe... |
193 |
struct mutex mutex; |
d50f6dcaf tty: n_gsm: expos... |
194 |
unsigned int num; |
6ab8fba7f tty: n_gsm: Added... |
195 |
struct kref ref; |
e1eaea46b tty: n_gsm line d... |
196 197 198 199 200 201 202 203 |
/* Events on the GSM channel */ wait_queue_head_t event; /* Bits for GSM mode decoding */ /* Framing Layer */ unsigned char *buf; |
329aa6e6e n_gsm: introduce ... |
204 |
enum gsm_mux_state state; |
e1eaea46b tty: n_gsm line d... |
205 206 207 |
unsigned int len; unsigned int address; unsigned int count; |
c50704bde n_gsm: switch esc... |
208 |
bool escape; |
e1eaea46b tty: n_gsm line d... |
209 210 211 |
int encoding; u8 control; u8 fcs; |
c2f2f0000 n_gsm: Fix suppor... |
212 |
u8 received_fcs; |
e1eaea46b tty: n_gsm line d... |
213 |
u8 *txframe; /* TX framing buffer */ |
a579767c1 tty: n_gsm, elimi... |
214 |
/* Method for the receiver side */ |
e1eaea46b tty: n_gsm line d... |
215 |
void (*receive)(struct gsm_mux *gsm, u8 ch); |
e1eaea46b tty: n_gsm line d... |
216 217 218 219 220 |
/* Link Layer */ unsigned int mru; unsigned int mtu; int initiator; /* Did we initiate connection */ |
5677fcf37 n_gsm: switch dea... |
221 |
bool dead; /* Has the mux been shut down */ |
e1eaea46b tty: n_gsm line d... |
222 |
struct gsm_dlci *dlci[NUM_DLCI]; |
7a9ed9c06 n_gsm: switch con... |
223 |
bool constipated; /* Asked by remote to shut up */ |
e1eaea46b tty: n_gsm line d... |
224 225 226 227 228 |
spinlock_t tx_lock; unsigned int tx_bytes; /* TX data outstanding */ #define TX_THRESH_HI 8192 #define TX_THRESH_LO 2048 |
b4338e1ef n_gsm: avoid acce... |
229 |
struct list_head tx_list; /* Pending data packets */ |
e1eaea46b tty: n_gsm line d... |
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
/* Control messages */ struct timer_list t2_timer; /* Retransmit timer for commands */ int cretries; /* Command retry counter */ struct gsm_control *pending_cmd;/* Our current pending command */ spinlock_t control_lock; /* Protects the pending command */ /* Configuration */ int adaption; /* 1 or 2 supported */ u8 ftype; /* UI or UIH */ int t1, t2; /* Timers in 1/100th of a sec */ int n2; /* Retry count */ /* Statistics (not currently exposed) */ unsigned long bad_fcs; unsigned long malformed; unsigned long io_error; unsigned long bad_size; unsigned long unsupported; }; /* * Mux objects - needed so that we can translate a tty index into the * relevant mux and DLCI. */ #define MAX_MUX 4 /* 256 minors */ static struct gsm_mux *gsm_mux[MAX_MUX]; /* GSM muxes */ static spinlock_t gsm_mux_lock; |
d50f6dcaf tty: n_gsm: expos... |
260 |
static struct tty_driver *gsm_tty_driver; |
e1eaea46b tty: n_gsm line d... |
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
/* * This section of the driver logic implements the GSM encodings * both the basic and the 'advanced'. Reliable transport is not * supported. */ #define CR 0x02 #define EA 0x01 #define PF 0x10 /* I is special: the rest are ..*/ #define RR 0x01 #define UI 0x03 #define RNR 0x05 #define REJ 0x09 #define DM 0x0F #define SABM 0x2F #define DISC 0x43 #define UA 0x63 #define UIH 0xEF /* Channel commands */ #define CMD_NSC 0x09 #define CMD_TEST 0x11 #define CMD_PSC 0x21 #define CMD_RLS 0x29 #define CMD_FCOFF 0x31 #define CMD_PN 0x41 #define CMD_RPN 0x49 #define CMD_FCON 0x51 #define CMD_CLD 0x61 #define CMD_SNC 0x69 #define CMD_MSC 0x71 /* Virtual modem bits */ #define MDM_FC 0x01 #define MDM_RTC 0x02 #define MDM_RTR 0x04 #define MDM_IC 0x20 #define MDM_DV 0x40 #define GSM0_SOF 0xF9 |
5f9a31d63 n_gsm: clean up p... |
303 |
#define GSM1_SOF 0x7E |
e1eaea46b tty: n_gsm line d... |
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
#define GSM1_ESCAPE 0x7D #define GSM1_ESCAPE_BITS 0x20 #define XON 0x11 #define XOFF 0x13 static const struct tty_port_operations gsm_port_ops; /* * CRC table for GSM 0710 */ static const u8 gsm_fcs8[256] = { 0x00, 0x91, 0xE3, 0x72, 0x07, 0x96, 0xE4, 0x75, 0x0E, 0x9F, 0xED, 0x7C, 0x09, 0x98, 0xEA, 0x7B, 0x1C, 0x8D, 0xFF, 0x6E, 0x1B, 0x8A, 0xF8, 0x69, 0x12, 0x83, 0xF1, 0x60, 0x15, 0x84, 0xF6, 0x67, 0x38, 0xA9, 0xDB, 0x4A, 0x3F, 0xAE, 0xDC, 0x4D, 0x36, 0xA7, 0xD5, 0x44, 0x31, 0xA0, 0xD2, 0x43, 0x24, 0xB5, 0xC7, 0x56, 0x23, 0xB2, 0xC0, 0x51, 0x2A, 0xBB, 0xC9, 0x58, 0x2D, 0xBC, 0xCE, 0x5F, 0x70, 0xE1, 0x93, 0x02, 0x77, 0xE6, 0x94, 0x05, 0x7E, 0xEF, 0x9D, 0x0C, 0x79, 0xE8, 0x9A, 0x0B, 0x6C, 0xFD, 0x8F, 0x1E, 0x6B, 0xFA, 0x88, 0x19, 0x62, 0xF3, 0x81, 0x10, 0x65, 0xF4, 0x86, 0x17, 0x48, 0xD9, 0xAB, 0x3A, 0x4F, 0xDE, 0xAC, 0x3D, 0x46, 0xD7, 0xA5, 0x34, 0x41, 0xD0, 0xA2, 0x33, 0x54, 0xC5, 0xB7, 0x26, 0x53, 0xC2, 0xB0, 0x21, 0x5A, 0xCB, 0xB9, 0x28, 0x5D, 0xCC, 0xBE, 0x2F, 0xE0, 0x71, 0x03, 0x92, 0xE7, 0x76, 0x04, 0x95, 0xEE, 0x7F, 0x0D, 0x9C, 0xE9, 0x78, 0x0A, 0x9B, 0xFC, 0x6D, 0x1F, 0x8E, 0xFB, 0x6A, 0x18, 0x89, 0xF2, 0x63, 0x11, 0x80, 0xF5, 0x64, 0x16, 0x87, 0xD8, 0x49, 0x3B, 0xAA, 0xDF, 0x4E, 0x3C, 0xAD, 0xD6, 0x47, 0x35, 0xA4, 0xD1, 0x40, 0x32, 0xA3, 0xC4, 0x55, 0x27, 0xB6, 0xC3, 0x52, 0x20, 0xB1, 0xCA, 0x5B, 0x29, 0xB8, 0xCD, 0x5C, 0x2E, 0xBF, 0x90, 0x01, 0x73, 0xE2, 0x97, 0x06, 0x74, 0xE5, 0x9E, 0x0F, 0x7D, 0xEC, 0x99, 0x08, 0x7A, 0xEB, 0x8C, 0x1D, 0x6F, 0xFE, 0x8B, 0x1A, 0x68, 0xF9, 0x82, 0x13, 0x61, 0xF0, 0x85, 0x14, 0x66, 0xF7, 0xA8, 0x39, 0x4B, 0xDA, 0xAF, 0x3E, 0x4C, 0xDD, 0xA6, 0x37, 0x45, 0xD4, 0xA1, 0x30, 0x42, 0xD3, 0xB4, 0x25, 0x57, 0xC6, 0xB3, 0x22, 0x50, 0xC1, 0xBA, 0x2B, 0x59, 0xC8, 0xBD, 0x2C, 0x5E, 0xCF }; #define INIT_FCS 0xFF #define GOOD_FCS 0xCF |
a579767c1 tty: n_gsm, elimi... |
352 |
static int gsmld_output(struct gsm_mux *gsm, u8 *data, int len); |
e1eaea46b tty: n_gsm line d... |
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
/** * gsm_fcs_add - update FCS * @fcs: Current FCS * @c: Next data * * Update the FCS to include c. Uses the algorithm in the specification * notes. */ static inline u8 gsm_fcs_add(u8 fcs, u8 c) { return gsm_fcs8[fcs ^ c]; } /** * gsm_fcs_add_block - update FCS for a block * @fcs: Current FCS * @c: buffer of data * @len: length of buffer * * Update the FCS to include c. Uses the algorithm in the specification * notes. */ static inline u8 gsm_fcs_add_block(u8 fcs, u8 *c, int len) { while (len--) fcs = gsm_fcs8[fcs ^ *c++]; return fcs; } /** * gsm_read_ea - read a byte into an EA * @val: variable holding value |
724ac070f tty: ldiscs, fix ... |
387 |
* @c: byte going into the EA |
e1eaea46b tty: n_gsm line d... |
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 |
* * Processes one byte of an EA. Updates the passed variable * and returns 1 if the EA is now completely read */ static int gsm_read_ea(unsigned int *val, u8 c) { /* Add the next 7 bits into the value */ *val <<= 7; *val |= c >> 1; /* Was this the last byte of the EA 1 = yes*/ return c & EA; } /** * gsm_encode_modem - encode modem data bits * @dlci: DLCI to encode from * * Returns the correct GSM encoded modem status bits (6 bit field) for * the current status of the DLCI and attached tty object */ static u8 gsm_encode_modem(const struct gsm_dlci *dlci) { u8 modembits = 0; /* FC is true flow control not modem bits */ if (dlci->throttled) modembits |= MDM_FC; if (dlci->modem_tx & TIOCM_DTR) modembits |= MDM_RTC; if (dlci->modem_tx & TIOCM_RTS) modembits |= MDM_RTR; if (dlci->modem_tx & TIOCM_RI) modembits |= MDM_IC; if (dlci->modem_tx & TIOCM_CD) modembits |= MDM_DV; return modembits; } /** * gsm_print_packet - display a frame for debug * @hdr: header to print before decode * @addr: address EA from the frame * @cr: C/R bit from the frame * @control: control including PF bit * @data: following data bytes * @dlen: length of data * * Displays a packet in human readable format for debugging purposes. The * style is based on amateur radio LAP-B dump display. */ static void gsm_print_packet(const char *hdr, int addr, int cr, u8 control, const u8 *data, int dlen) { if (!(debug & 1)) return; |
5f9a31d63 n_gsm: clean up p... |
445 |
pr_info("%s %d) %c: ", hdr, addr, "RC"[cr]); |
e1eaea46b tty: n_gsm line d... |
446 447 448 |
switch (control & ~PF) { case SABM: |
5f9a31d63 n_gsm: clean up p... |
449 |
pr_cont("SABM"); |
e1eaea46b tty: n_gsm line d... |
450 451 |
break; case UA: |
5f9a31d63 n_gsm: clean up p... |
452 |
pr_cont("UA"); |
e1eaea46b tty: n_gsm line d... |
453 454 |
break; case DISC: |
5f9a31d63 n_gsm: clean up p... |
455 |
pr_cont("DISC"); |
e1eaea46b tty: n_gsm line d... |
456 457 |
break; case DM: |
5f9a31d63 n_gsm: clean up p... |
458 |
pr_cont("DM"); |
e1eaea46b tty: n_gsm line d... |
459 460 |
break; case UI: |
5f9a31d63 n_gsm: clean up p... |
461 |
pr_cont("UI"); |
e1eaea46b tty: n_gsm line d... |
462 463 |
break; case UIH: |
5f9a31d63 n_gsm: clean up p... |
464 |
pr_cont("UIH"); |
e1eaea46b tty: n_gsm line d... |
465 466 467 |
break; default: if (!(control & 0x01)) { |
5f9a31d63 n_gsm: clean up p... |
468 |
pr_cont("I N(S)%d N(R)%d", |
47fdd641c tty: n_gsm: Fix i... |
469 |
(control & 0x0E) >> 1, (control & 0xE0) >> 5); |
e1eaea46b tty: n_gsm line d... |
470 |
} else switch (control & 0x0F) { |
5f9a31d63 n_gsm: clean up p... |
471 472 473 474 475 476 477 478 479 480 481 |
case RR: pr_cont("RR(%d)", (control & 0xE0) >> 5); break; case RNR: pr_cont("RNR(%d)", (control & 0xE0) >> 5); break; case REJ: pr_cont("REJ(%d)", (control & 0xE0) >> 5); break; default: pr_cont("[%02X]", control); |
e1eaea46b tty: n_gsm line d... |
482 483 484 485 |
} } if (control & PF) |
5f9a31d63 n_gsm: clean up p... |
486 |
pr_cont("(P)"); |
e1eaea46b tty: n_gsm line d... |
487 |
else |
5f9a31d63 n_gsm: clean up p... |
488 |
pr_cont("(F)"); |
e1eaea46b tty: n_gsm line d... |
489 |
|
57626ff1c tty: n_gsm: Remov... |
490 |
print_hex_dump_bytes("", DUMP_PREFIX_NONE, data, dlen); |
e1eaea46b tty: n_gsm line d... |
491 492 493 494 495 496 497 498 499 |
} /* * Link level transmission side */ /** * gsm_stuff_packet - bytestuff a packet |
724ac070f tty: ldiscs, fix ... |
500 501 |
* @input: input buffer * @output: output buffer |
e1eaea46b tty: n_gsm line d... |
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 |
* @len: length of input * * Expand a buffer by bytestuffing it. The worst case size change * is doubling and the caller is responsible for handing out * suitable sized buffers. */ static int gsm_stuff_frame(const u8 *input, u8 *output, int len) { int olen = 0; while (len--) { if (*input == GSM1_SOF || *input == GSM1_ESCAPE || *input == XON || *input == XOFF) { *output++ = GSM1_ESCAPE; *output++ = *input++ ^ GSM1_ESCAPE_BITS; olen++; } else *output++ = *input++; olen++; } return olen; } |
e1eaea46b tty: n_gsm line d... |
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 |
/** * gsm_send - send a control frame * @gsm: our GSM mux * @addr: address for control frame * @cr: command/response bit * @control: control byte including PF bit * * Format up and transmit a control frame. These do not go via the * queueing logic as they should be transmitted ahead of data when * they are needed. * * FIXME: Lock versus data TX path */ static void gsm_send(struct gsm_mux *gsm, int addr, int cr, int control) { int len; u8 cbuf[10]; u8 ibuf[3]; switch (gsm->encoding) { case 0: cbuf[0] = GSM0_SOF; cbuf[1] = (addr << 2) | (cr << 1) | EA; cbuf[2] = control; cbuf[3] = EA; /* Length of data = 0 */ cbuf[4] = 0xFF - gsm_fcs_add_block(INIT_FCS, cbuf + 1, 3); cbuf[5] = GSM0_SOF; len = 6; break; case 1: case 2: /* Control frame + packing (but not frame stuffing) in mode 1 */ ibuf[0] = (addr << 2) | (cr << 1) | EA; ibuf[1] = control; ibuf[2] = 0xFF - gsm_fcs_add_block(INIT_FCS, ibuf, 2); /* Stuffing may double the size worst case */ len = gsm_stuff_frame(ibuf, cbuf + 1, 3); /* Now add the SOF markers */ cbuf[0] = GSM1_SOF; cbuf[len + 1] = GSM1_SOF; /* FIXME: we can omit the lead one in many cases */ len += 2; break; default: WARN_ON(1); return; } |
a579767c1 tty: n_gsm, elimi... |
572 |
gsmld_output(gsm, cbuf, len); |
e1eaea46b tty: n_gsm line d... |
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 |
gsm_print_packet("-->", addr, cr, control, NULL, 0); } /** * gsm_response - send a control response * @gsm: our GSM mux * @addr: address for control frame * @control: control byte including PF bit * * Format up and transmit a link level response frame. */ static inline void gsm_response(struct gsm_mux *gsm, int addr, int control) { gsm_send(gsm, addr, 0, control); } /** * gsm_command - send a control command * @gsm: our GSM mux * @addr: address for control frame * @control: control byte including PF bit * * Format up and transmit a link level command frame. */ static inline void gsm_command(struct gsm_mux *gsm, int addr, int control) { gsm_send(gsm, addr, 1, control); } /* Data transmission */ #define HDR_LEN 6 /* ADDR CTRL [LEN.2] DATA FCS */ /** * gsm_data_alloc - allocate data frame * @gsm: GSM mux * @addr: DLCI address * @len: length excluding header and FCS * @ctrl: control byte * * Allocate a new data buffer for sending frames with data. Space is left * at the front for header bytes but that is treated as an implementation * detail and not for the high level code to use */ static struct gsm_msg *gsm_data_alloc(struct gsm_mux *gsm, u8 addr, int len, u8 ctrl) { struct gsm_msg *m = kmalloc(sizeof(struct gsm_msg) + len + HDR_LEN, GFP_ATOMIC); if (m == NULL) return NULL; m->data = m->buffer + HDR_LEN - 1; /* Allow for FCS */ m->len = len; m->addr = addr; m->ctrl = ctrl; |
b4338e1ef n_gsm: avoid acce... |
631 |
INIT_LIST_HEAD(&m->list); |
e1eaea46b tty: n_gsm line d... |
632 633 634 635 636 637 638 639 640 |
return m; } /** * gsm_data_kick - poke the queue * @gsm: GSM Mux * * The tty device has called us to indicate that room has appeared in * the transmit queue. Ram more data into the pipe if we have any |
c01af4fec n_gsm : Flow cont... |
641 642 |
* If we have been flow-stopped by a CMD_FCOFF, then we can only * send messages on DLCI0 until CMD_FCON |
e1eaea46b tty: n_gsm line d... |
643 644 645 |
* * FIXME: lock against link layer control transmissions */ |
01dbb362f tty: n_gsm: Fix w... |
646 |
static void gsm_data_kick(struct gsm_mux *gsm, struct gsm_dlci *dlci) |
e1eaea46b tty: n_gsm line d... |
647 |
{ |
b4338e1ef n_gsm: avoid acce... |
648 |
struct gsm_msg *msg, *nmsg; |
e1eaea46b tty: n_gsm line d... |
649 |
int len; |
e1eaea46b tty: n_gsm line d... |
650 |
|
b4338e1ef n_gsm: avoid acce... |
651 652 |
list_for_each_entry_safe(msg, nmsg, &gsm->tx_list, list) { if (gsm->constipated && msg->addr) |
c01af4fec n_gsm : Flow cont... |
653 |
continue; |
e1eaea46b tty: n_gsm line d... |
654 655 656 657 658 659 660 661 662 663 664 665 |
if (gsm->encoding != 0) { gsm->txframe[0] = GSM1_SOF; len = gsm_stuff_frame(msg->data, gsm->txframe + 1, msg->len); gsm->txframe[len + 1] = GSM1_SOF; len += 2; } else { gsm->txframe[0] = GSM0_SOF; memcpy(gsm->txframe + 1 , msg->data, msg->len); gsm->txframe[msg->len + 1] = GSM0_SOF; len = msg->len + 2; } |
0a77c4f9d n_gsm: Use print_... |
666 667 668 669 |
if (debug & 4) print_hex_dump_bytes("gsm_data_kick: ", DUMP_PREFIX_OFFSET, gsm->txframe, len); |
a579767c1 tty: n_gsm, elimi... |
670 |
if (gsmld_output(gsm, gsm->txframe, len) < 0) |
e1eaea46b tty: n_gsm line d... |
671 672 |
break; /* FIXME: Can eliminate one SOF in many more cases */ |
e1eaea46b tty: n_gsm line d... |
673 |
gsm->tx_bytes -= msg->len; |
c01af4fec n_gsm : Flow cont... |
674 |
|
b4338e1ef n_gsm: avoid acce... |
675 676 |
list_del(&msg->list); kfree(msg); |
01dbb362f tty: n_gsm: Fix w... |
677 678 679 680 681 |
if (dlci) { tty_port_tty_wakeup(&dlci->port); } else { int i = 0; |
4dd31f1ff tty: n_gsm: Fix b... |
682 683 684 |
for (i = 0; i < NUM_DLCI; i++) if (gsm->dlci[i]) tty_port_tty_wakeup(&gsm->dlci[i]->port); |
01dbb362f tty: n_gsm: Fix w... |
685 |
} |
e1eaea46b tty: n_gsm line d... |
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 |
} } /** * __gsm_data_queue - queue a UI or UIH frame * @dlci: DLCI sending the data * @msg: message queued * * Add data to the transmit queue and try and get stuff moving * out of the mux tty if not already doing so. The Caller must hold * the gsm tx lock. */ static void __gsm_data_queue(struct gsm_dlci *dlci, struct gsm_msg *msg) { struct gsm_mux *gsm = dlci->gsm; u8 *dp = msg->data; u8 *fcs = dp + msg->len; /* Fill in the header */ if (gsm->encoding == 0) { if (msg->len < 128) *--dp = (msg->len << 1) | EA; else { |
be7a7411d n_gsm: Fix messag... |
710 711 |
*--dp = (msg->len >> 7); /* bits 7 - 15 */ *--dp = (msg->len & 127) << 1; /* bits 0 - 6 */ |
e1eaea46b tty: n_gsm line d... |
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 |
} } *--dp = msg->ctrl; if (gsm->initiator) *--dp = (msg->addr << 2) | 2 | EA; else *--dp = (msg->addr << 2) | EA; *fcs = gsm_fcs_add_block(INIT_FCS, dp , msg->data - dp); /* Ugly protocol layering violation */ if (msg->ctrl == UI || msg->ctrl == (UI|PF)) *fcs = gsm_fcs_add_block(*fcs, msg->data, msg->len); *fcs = 0xFF - *fcs; gsm_print_packet("Q> ", msg->addr, gsm->initiator, msg->ctrl, msg->data, msg->len); /* Move the header back and adjust the length, also allow for the FCS now tacked on the end */ msg->len += (msg->data - dp) + 1; msg->data = dp; /* Add to the actual output queue */ |
b4338e1ef n_gsm: avoid acce... |
735 |
list_add_tail(&msg->list, &gsm->tx_list); |
e1eaea46b tty: n_gsm line d... |
736 |
gsm->tx_bytes += msg->len; |
01dbb362f tty: n_gsm: Fix w... |
737 |
gsm_data_kick(gsm, dlci); |
e1eaea46b tty: n_gsm line d... |
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 |
} /** * gsm_data_queue - queue a UI or UIH frame * @dlci: DLCI sending the data * @msg: message queued * * Add data to the transmit queue and try and get stuff moving * out of the mux tty if not already doing so. Take the * the gsm tx lock and dlci lock. */ static void gsm_data_queue(struct gsm_dlci *dlci, struct gsm_msg *msg) { unsigned long flags; spin_lock_irqsave(&dlci->gsm->tx_lock, flags); __gsm_data_queue(dlci, msg); spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags); } /** * gsm_dlci_data_output - try and push data out of a DLCI * @gsm: mux * @dlci: the DLCI to pull data from * * Pull data from a DLCI and send it into the transmit queue if there * is data. Keep to the MRU of the mux. This path handles the usual tty * interface which is a byte stream with optional modem data. * * Caller must hold the tx_lock of the mux. */ static int gsm_dlci_data_output(struct gsm_mux *gsm, struct gsm_dlci *dlci) { struct gsm_msg *msg; u8 *dp; |
268e526b9 tty/n_gsm: avoid ... |
774 |
int len, total_size, size; |
e1eaea46b tty: n_gsm line d... |
775 |
int h = dlci->adaption - 1; |
268e526b9 tty/n_gsm: avoid ... |
776 |
total_size = 0; |
f3c909b42 Drivers: tty: n_g... |
777 |
while (1) { |
036bca1fc n_gsm: drop unnee... |
778 |
len = kfifo_len(&dlci->fifo); |
268e526b9 tty/n_gsm: avoid ... |
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 |
if (len == 0) return total_size; /* MTU/MRU count only the data bits */ if (len > gsm->mtu) len = gsm->mtu; size = len + h; msg = gsm_data_alloc(gsm, dlci->addr, size, gsm->ftype); /* FIXME: need a timer or something to kick this so it can't get stuck with no work outstanding and no buffer free */ if (msg == NULL) return -ENOMEM; dp = msg->data; switch (dlci->adaption) { case 1: /* Unstructured */ break; |
f3c909b42 Drivers: tty: n_g... |
797 798 |
case 2: /* Unstructed with modem bits. Always one byte as we never send inline break data */ |
268e526b9 tty/n_gsm: avoid ... |
799 800 801 |
*dp++ = gsm_encode_modem(dlci); break; } |
036bca1fc n_gsm: drop unnee... |
802 |
WARN_ON(kfifo_out_locked(&dlci->fifo, dp , len, &dlci->lock) != len); |
268e526b9 tty/n_gsm: avoid ... |
803 804 |
__gsm_data_queue(dlci, msg); total_size += size; |
e1eaea46b tty: n_gsm line d... |
805 |
} |
e1eaea46b tty: n_gsm line d... |
806 |
/* Bytes of data we used up */ |
268e526b9 tty/n_gsm: avoid ... |
807 |
return total_size; |
e1eaea46b tty: n_gsm line d... |
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 |
} /** * gsm_dlci_data_output_framed - try and push data out of a DLCI * @gsm: mux * @dlci: the DLCI to pull data from * * Pull data from a DLCI and send it into the transmit queue if there * is data. Keep to the MRU of the mux. This path handles framed data * queued as skbuffs to the DLCI. * * Caller must hold the tx_lock of the mux. */ static int gsm_dlci_data_output_framed(struct gsm_mux *gsm, struct gsm_dlci *dlci) { struct gsm_msg *msg; u8 *dp; int len, size; int last = 0, first = 0; int overhead = 0; /* One byte per frame is used for B/F flags */ if (dlci->adaption == 4) overhead = 1; /* dlci->skb is locked by tx_lock */ if (dlci->skb == NULL) { |
88ed2a606 n_gsm: memory lea... |
837 |
dlci->skb = skb_dequeue_tail(&dlci->skb_list); |
e1eaea46b tty: n_gsm line d... |
838 839 840 841 842 843 844 845 846 847 |
if (dlci->skb == NULL) return 0; first = 1; } len = dlci->skb->len + overhead; /* MTU/MRU count only the data bits */ if (len > gsm->mtu) { if (dlci->adaption == 3) { /* Over long frame, bin it */ |
329e56780 n_gsm: replace kf... |
848 |
dev_kfree_skb_any(dlci->skb); |
e1eaea46b tty: n_gsm line d... |
849 850 851 852 853 854 855 856 857 858 859 860 |
dlci->skb = NULL; return 0; } len = gsm->mtu; } else last = 1; size = len + overhead; msg = gsm_data_alloc(gsm, dlci->addr, size, gsm->ftype); /* FIXME: need a timer or something to kick this so it can't get stuck with no work outstanding and no buffer free */ |
88ed2a606 n_gsm: memory lea... |
861 862 863 |
if (msg == NULL) { skb_queue_tail(&dlci->skb_list, dlci->skb); dlci->skb = NULL; |
e1eaea46b tty: n_gsm line d... |
864 |
return -ENOMEM; |
88ed2a606 n_gsm: memory lea... |
865 |
} |
e1eaea46b tty: n_gsm line d... |
866 867 868 869 870 871 872 |
dp = msg->data; if (dlci->adaption == 4) { /* Interruptible framed (Packetised Data) */ /* Flag byte to carry the start/end info */ *dp++ = last << 7 | first << 6 | 1; /* EA */ len--; } |
57f2104f3 tty: n_gsm: impro... |
873 874 |
memcpy(dp, dlci->skb->data, len); skb_pull(dlci->skb, len); |
e1eaea46b tty: n_gsm line d... |
875 |
__gsm_data_queue(dlci, msg); |
bcd5abe28 tty: n_gsm: Add r... |
876 |
if (last) { |
329e56780 n_gsm: replace kf... |
877 |
dev_kfree_skb_any(dlci->skb); |
e1eaea46b tty: n_gsm line d... |
878 |
dlci->skb = NULL; |
bcd5abe28 tty: n_gsm: Add r... |
879 |
} |
e1eaea46b tty: n_gsm line d... |
880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 |
return size; } /** * gsm_dlci_data_sweep - look for data to send * @gsm: the GSM mux * * Sweep the GSM mux channels in priority order looking for ones with * data to send. We could do with optimising this scan a bit. We aim * to fill the queue totally or up to TX_THRESH_HI bytes. Once we hit * TX_THRESH_LO we get called again * * FIXME: We should round robin between groups and in theory you can * renegotiate DLCI priorities with optional stuff. Needs optimising. */ static void gsm_dlci_data_sweep(struct gsm_mux *gsm) { int len; /* Priority ordering: We should do priority with RR of the groups */ int i = 1; |
e1eaea46b tty: n_gsm line d... |
901 |
|
e1eaea46b tty: n_gsm line d... |
902 903 904 905 906 907 908 909 910 911 |
while (i < NUM_DLCI) { struct gsm_dlci *dlci; if (gsm->tx_bytes > TX_THRESH_HI) break; dlci = gsm->dlci[i]; if (dlci == NULL || dlci->constipated) { i++; continue; } |
bcd5abe28 tty: n_gsm: Add r... |
912 |
if (dlci->adaption < 3 && !dlci->net) |
e1eaea46b tty: n_gsm line d... |
913 914 915 916 |
len = gsm_dlci_data_output(gsm, dlci); else len = gsm_dlci_data_output_framed(gsm, dlci); if (len < 0) |
e73790a57 drivers/char/n_gs... |
917 |
break; |
e1eaea46b tty: n_gsm line d... |
918 919 920 921 |
/* DLCI empty - try the next */ if (len == 0) i++; } |
e1eaea46b tty: n_gsm line d... |
922 923 924 925 926 927 928 929 930 931 932 933 934 935 |
} /** * gsm_dlci_data_kick - transmit if possible * @dlci: DLCI to kick * * Transmit data from this DLCI if the queue is empty. We can't rely on * a tty wakeup except when we filled the pipe so we need to fire off * new data ourselves in other cases. */ static void gsm_dlci_data_kick(struct gsm_dlci *dlci) { unsigned long flags; |
192b6041e n_gsm: uplink SKB... |
936 |
int sweep; |
e1eaea46b tty: n_gsm line d... |
937 |
|
f3c909b42 Drivers: tty: n_g... |
938 |
if (dlci->constipated) |
c01af4fec n_gsm : Flow cont... |
939 |
return; |
c01af4fec n_gsm : Flow cont... |
940 |
|
e1eaea46b tty: n_gsm line d... |
941 942 |
spin_lock_irqsave(&dlci->gsm->tx_lock, flags); /* If we have nothing running then we need to fire up */ |
192b6041e n_gsm: uplink SKB... |
943 |
sweep = (dlci->gsm->tx_bytes < TX_THRESH_LO); |
bcd5abe28 tty: n_gsm: Add r... |
944 945 946 947 948 |
if (dlci->gsm->tx_bytes == 0) { if (dlci->net) gsm_dlci_data_output_framed(dlci->gsm, dlci); else gsm_dlci_data_output(dlci->gsm, dlci); |
192b6041e n_gsm: uplink SKB... |
949 950 |
} if (sweep) |
f3c909b42 Drivers: tty: n_g... |
951 |
gsm_dlci_data_sweep(dlci->gsm); |
e1eaea46b tty: n_gsm line d... |
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 |
spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags); } /* * Control message processing */ /** * gsm_control_reply - send a response frame to a control * @gsm: gsm channel * @cmd: the command to use * @data: data to follow encoded info * @dlen: length of data * * Encode up and queue a UI/UIH frame containing our response. */ |
4feb7a4a1 n_gsm: Constify u... |
969 |
static void gsm_control_reply(struct gsm_mux *gsm, int cmd, const u8 *data, |
e1eaea46b tty: n_gsm line d... |
970 971 972 973 |
int dlen) { struct gsm_msg *msg; msg = gsm_data_alloc(gsm, 0, dlen + 2, gsm->ftype); |
093d80461 n_gsm: gsm_data_a... |
974 975 |
if (msg == NULL) return; |
e1eaea46b tty: n_gsm line d... |
976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 |
msg->data[0] = (cmd & 0xFE) << 1 | EA; /* Clear C/R */ msg->data[1] = (dlen << 1) | EA; memcpy(msg->data + 2, data, dlen); gsm_data_queue(gsm->dlci[0], msg); } /** * gsm_process_modem - process received modem status * @tty: virtual tty bound to the DLCI * @dlci: DLCI to affect * @modem: modem bits (full EA) * * Used when a modem control message or line state inline in adaption * layer 2 is processed. Sort out the local modem state and throttles */ static void gsm_process_modem(struct tty_struct *tty, struct gsm_dlci *dlci, |
7263287af tty: n_gsm: Fixed... |
993 |
u32 modem, int clen) |
e1eaea46b tty: n_gsm line d... |
994 995 |
{ int mlines = 0; |
7263287af tty: n_gsm: Fixed... |
996 |
u8 brk = 0; |
c01af4fec n_gsm : Flow cont... |
997 |
int fc; |
7263287af tty: n_gsm: Fixed... |
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 |
/* The modem status command can either contain one octet (v.24 signals) or two octets (v.24 signals + break signals). The length field will either be 2 or 3 respectively. This is specified in section 5.4.6.3.7 of the 27.010 mux spec. */ if (clen == 2) modem = modem & 0x7f; else { brk = modem & 0x7f; modem = (modem >> 7) & 0x7f; |
c01af4fec n_gsm : Flow cont... |
1009 |
} |
e1eaea46b tty: n_gsm line d... |
1010 1011 |
/* Flow control/ready to communicate */ |
c01af4fec n_gsm : Flow cont... |
1012 1013 |
fc = (modem & MDM_FC) || !(modem & MDM_RTR); if (fc && !dlci->constipated) { |
e1eaea46b tty: n_gsm line d... |
1014 |
/* Need to throttle our output on this device */ |
7a9ed9c06 n_gsm: switch con... |
1015 |
dlci->constipated = true; |
c01af4fec n_gsm : Flow cont... |
1016 |
} else if (!fc && dlci->constipated) { |
7a9ed9c06 n_gsm: switch con... |
1017 |
dlci->constipated = false; |
e1eaea46b tty: n_gsm line d... |
1018 1019 |
gsm_dlci_data_kick(dlci); } |
c01af4fec n_gsm : Flow cont... |
1020 |
|
e1eaea46b tty: n_gsm line d... |
1021 |
/* Map modem bits */ |
c01af4fec n_gsm : Flow cont... |
1022 1023 |
if (modem & MDM_RTC) mlines |= TIOCM_DSR | TIOCM_DTR; |
e1eaea46b tty: n_gsm line d... |
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 |
if (modem & MDM_RTR) mlines |= TIOCM_RTS | TIOCM_CTS; if (modem & MDM_IC) mlines |= TIOCM_RI; if (modem & MDM_DV) mlines |= TIOCM_CD; /* Carrier drop -> hangup */ if (tty) { if ((mlines & TIOCM_CD) == 0 && (dlci->modem_rx & TIOCM_CD)) |
9db276f8f tty: Use termios ... |
1034 |
if (!C_CLOCAL(tty)) |
e1eaea46b tty: n_gsm line d... |
1035 |
tty_hangup(tty); |
e1eaea46b tty: n_gsm line d... |
1036 |
} |
92a19f9ce TTY: switch tty_i... |
1037 1038 |
if (brk & 0x01) tty_insert_flip_char(&dlci->port, 0, TTY_BREAK); |
e1eaea46b tty: n_gsm line d... |
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 |
dlci->modem_rx = mlines; } /** * gsm_control_modem - modem status received * @gsm: GSM channel * @data: data following command * @clen: command length * * We have received a modem status control message. This is used by * the GSM mux protocol to pass virtual modem line status and optionally * to indicate break signals. Unpack it, convert to Linux representation * and if need be stuff a break message down the tty. */ |
4feb7a4a1 n_gsm: Constify u... |
1053 |
static void gsm_control_modem(struct gsm_mux *gsm, const u8 *data, int clen) |
e1eaea46b tty: n_gsm line d... |
1054 1055 1056 |
{ unsigned int addr = 0; unsigned int modem = 0; |
3ac06b905 tty: n_gsm: Fix f... |
1057 |
unsigned int brk = 0; |
e1eaea46b tty: n_gsm line d... |
1058 1059 |
struct gsm_dlci *dlci; int len = clen; |
4feb7a4a1 n_gsm: Constify u... |
1060 |
const u8 *dp = data; |
e1eaea46b tty: n_gsm line d... |
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 |
struct tty_struct *tty; while (gsm_read_ea(&addr, *dp++) == 0) { len--; if (len == 0) return; } /* Must be at least one byte following the EA */ len--; if (len <= 0) return; addr >>= 1; /* Closed port, or invalid ? */ if (addr == 0 || addr >= NUM_DLCI || gsm->dlci[addr] == NULL) return; dlci = gsm->dlci[addr]; while (gsm_read_ea(&modem, *dp++) == 0) { len--; if (len == 0) return; } |
3ac06b905 tty: n_gsm: Fix f... |
1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 |
len--; if (len > 0) { while (gsm_read_ea(&brk, *dp++) == 0) { len--; if (len == 0) return; } modem <<= 7; modem |= (brk & 0x7f); } |
e1eaea46b tty: n_gsm line d... |
1094 |
tty = tty_port_tty_get(&dlci->port); |
7263287af tty: n_gsm: Fixed... |
1095 |
gsm_process_modem(tty, dlci, modem, clen); |
e1eaea46b tty: n_gsm line d... |
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 |
if (tty) { tty_wakeup(tty); tty_kref_put(tty); } gsm_control_reply(gsm, CMD_MSC, data, clen); } /** * gsm_control_rls - remote line status * @gsm: GSM channel * @data: data bytes * @clen: data length * * The modem sends us a two byte message on the control channel whenever * it wishes to send us an error state from the virtual link. Stuff * this into the uplink tty if present */ |
4feb7a4a1 n_gsm: Constify u... |
1113 |
static void gsm_control_rls(struct gsm_mux *gsm, const u8 *data, int clen) |
e1eaea46b tty: n_gsm line d... |
1114 |
{ |
92a19f9ce TTY: switch tty_i... |
1115 |
struct tty_port *port; |
f3c909b42 Drivers: tty: n_g... |
1116 |
unsigned int addr = 0; |
e1eaea46b tty: n_gsm line d... |
1117 1118 |
u8 bits; int len = clen; |
4feb7a4a1 n_gsm: Constify u... |
1119 |
const u8 *dp = data; |
e1eaea46b tty: n_gsm line d... |
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 |
while (gsm_read_ea(&addr, *dp++) == 0) { len--; if (len == 0) return; } /* Must be at least one byte following ea */ len--; if (len <= 0) return; addr >>= 1; /* Closed port, or invalid ? */ if (addr == 0 || addr >= NUM_DLCI || gsm->dlci[addr] == NULL) return; /* No error ? */ bits = *dp; if ((bits & 1) == 0) return; |
e1eaea46b tty: n_gsm line d... |
1138 |
|
92a19f9ce TTY: switch tty_i... |
1139 1140 1141 1142 1143 1144 1145 1146 |
port = &gsm->dlci[addr]->port; if (bits & 2) tty_insert_flip_char(port, 0, TTY_OVERRUN); if (bits & 4) tty_insert_flip_char(port, 0, TTY_PARITY); if (bits & 8) tty_insert_flip_char(port, 0, TTY_FRAME); |
2e124b4a3 TTY: switch tty_f... |
1147 |
tty_flip_buffer_push(port); |
e1eaea46b tty: n_gsm line d... |
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 |
gsm_control_reply(gsm, CMD_RLS, data, clen); } static void gsm_dlci_begin_close(struct gsm_dlci *dlci); /** * gsm_control_message - DLCI 0 control processing * @gsm: our GSM mux * @command: the command EA * @data: data beyond the command/length EAs * @clen: length * * Input processor for control messages from the other end of the link. * Processes the incoming request and queues a response frame or an * NSC response if not supported */ static void gsm_control_message(struct gsm_mux *gsm, unsigned int command, |
4feb7a4a1 n_gsm: Constify u... |
1166 |
const u8 *data, int clen) |
e1eaea46b tty: n_gsm line d... |
1167 1168 |
{ u8 buf[1]; |
5e44708f7 n_gsm: added inte... |
1169 |
unsigned long flags; |
e1eaea46b tty: n_gsm line d... |
1170 1171 1172 1173 1174 |
switch (command) { case CMD_CLD: { struct gsm_dlci *dlci = gsm->dlci[0]; /* Modem wishes to close down */ if (dlci) { |
5677fcf37 n_gsm: switch dea... |
1175 1176 |
dlci->dead = true; gsm->dead = true; |
e1eaea46b tty: n_gsm line d... |
1177 1178 1179 1180 1181 1182 1183 1184 1185 |
gsm_dlci_begin_close(dlci); } } break; case CMD_TEST: /* Modem wishes to test, reply with the data */ gsm_control_reply(gsm, CMD_TEST, data, clen); break; case CMD_FCON: |
e1eaea46b tty: n_gsm line d... |
1186 |
/* Modem can accept data again */ |
7a9ed9c06 n_gsm: switch con... |
1187 |
gsm->constipated = false; |
c01af4fec n_gsm : Flow cont... |
1188 |
gsm_control_reply(gsm, CMD_FCON, NULL, 0); |
e1eaea46b tty: n_gsm line d... |
1189 |
/* Kick the link in case it is idling */ |
5e44708f7 n_gsm: added inte... |
1190 |
spin_lock_irqsave(&gsm->tx_lock, flags); |
01dbb362f tty: n_gsm: Fix w... |
1191 |
gsm_data_kick(gsm, NULL); |
5e44708f7 n_gsm: added inte... |
1192 |
spin_unlock_irqrestore(&gsm->tx_lock, flags); |
e1eaea46b tty: n_gsm line d... |
1193 |
break; |
c01af4fec n_gsm : Flow cont... |
1194 1195 |
case CMD_FCOFF: /* Modem wants us to STFU */ |
7a9ed9c06 n_gsm: switch con... |
1196 |
gsm->constipated = true; |
c01af4fec n_gsm : Flow cont... |
1197 1198 |
gsm_control_reply(gsm, CMD_FCOFF, NULL, 0); break; |
e1eaea46b tty: n_gsm line d... |
1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 |
case CMD_MSC: /* Out of band modem line change indicator for a DLCI */ gsm_control_modem(gsm, data, clen); break; case CMD_RLS: /* Out of band error reception for a DLCI */ gsm_control_rls(gsm, data, clen); break; case CMD_PSC: /* Modem wishes to enter power saving state */ gsm_control_reply(gsm, CMD_PSC, NULL, 0); break; /* Optional unsupported commands */ case CMD_PN: /* Parameter negotiation */ |
25985edce Fix common misspe... |
1213 1214 |
case CMD_RPN: /* Remote port negotiation */ case CMD_SNC: /* Service negotiation command */ |
e1eaea46b tty: n_gsm line d... |
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 |
default: /* Reply to bad commands with an NSC */ buf[0] = command; gsm_control_reply(gsm, CMD_NSC, buf, 1); break; } } /** * gsm_control_response - process a response to our control * @gsm: our GSM mux * @command: the command (response) EA * @data: data beyond the command/length EA * @clen: length * * Process a response to an outstanding command. We only allow a single * control message in flight so this is fairly easy. All the clean up * is done by the caller, we just update the fields, flag it as done * and return */ static void gsm_control_response(struct gsm_mux *gsm, unsigned int command, |
4feb7a4a1 n_gsm: Constify u... |
1237 |
const u8 *data, int clen) |
e1eaea46b tty: n_gsm line d... |
1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 |
{ struct gsm_control *ctrl; unsigned long flags; spin_lock_irqsave(&gsm->control_lock, flags); ctrl = gsm->pending_cmd; /* Does the reply match our command */ command |= 1; if (ctrl != NULL && (command == ctrl->cmd || command == CMD_NSC)) { /* Our command was replied to, kill the retry timer */ del_timer(&gsm->t2_timer); gsm->pending_cmd = NULL; /* Rejected by the other end */ if (command == CMD_NSC) ctrl->error = -EOPNOTSUPP; ctrl->done = 1; wake_up(&gsm->event); } spin_unlock_irqrestore(&gsm->control_lock, flags); } /** |
5f9a31d63 n_gsm: clean up p... |
1261 |
* gsm_control_transmit - send control packet |
e1eaea46b tty: n_gsm line d... |
1262 1263 1264 1265 1266 1267 1268 1269 |
* @gsm: gsm mux * @ctrl: frame to send * * Send out a pending control command (called under control lock) */ static void gsm_control_transmit(struct gsm_mux *gsm, struct gsm_control *ctrl) { |
ed43b47b2 n_gsm: fix UIH co... |
1270 |
struct gsm_msg *msg = gsm_data_alloc(gsm, 0, ctrl->len + 1, gsm->ftype); |
e1eaea46b tty: n_gsm line d... |
1271 1272 1273 1274 1275 1276 1277 1278 1279 |
if (msg == NULL) return; msg->data[0] = (ctrl->cmd << 1) | 2 | EA; /* command */ memcpy(msg->data + 1, ctrl->data, ctrl->len); gsm_data_queue(gsm->dlci[0], msg); } /** * gsm_control_retransmit - retransmit a control frame |
724ac070f tty: ldiscs, fix ... |
1280 |
* @t: timer contained in our gsm object |
e1eaea46b tty: n_gsm line d... |
1281 1282 1283 1284 1285 1286 1287 |
* * Called off the T2 timer expiry in order to retransmit control frames * that have been lost in the system somewhere. The control_lock protects * us from colliding with another sender or a receive completion event. * In that situation the timer may still occur in a small window but * gsm->pending_cmd will be NULL and we just let the timer expire. */ |
e99e88a9d treewide: setup_t... |
1288 |
static void gsm_control_retransmit(struct timer_list *t) |
e1eaea46b tty: n_gsm line d... |
1289 |
{ |
e99e88a9d treewide: setup_t... |
1290 |
struct gsm_mux *gsm = from_timer(gsm, t, t2_timer); |
e1eaea46b tty: n_gsm line d... |
1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 |
struct gsm_control *ctrl; unsigned long flags; spin_lock_irqsave(&gsm->control_lock, flags); ctrl = gsm->pending_cmd; if (ctrl) { gsm->cretries--; if (gsm->cretries == 0) { gsm->pending_cmd = NULL; ctrl->error = -ETIMEDOUT; ctrl->done = 1; spin_unlock_irqrestore(&gsm->control_lock, flags); wake_up(&gsm->event); return; } gsm_control_transmit(gsm, ctrl); mod_timer(&gsm->t2_timer, jiffies + gsm->t2 * HZ / 100); } spin_unlock_irqrestore(&gsm->control_lock, flags); } /** * gsm_control_send - send a control frame on DLCI 0 * @gsm: the GSM channel * @command: command to send including CR bit * @data: bytes of data (must be kmalloced) |
724ac070f tty: ldiscs, fix ... |
1316 |
* @clen: length of the block to send |
e1eaea46b tty: n_gsm line d... |
1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 |
* * Queue and dispatch a control command. Only one command can be * active at a time. In theory more can be outstanding but the matching * gets really complicated so for now stick to one outstanding. */ static struct gsm_control *gsm_control_send(struct gsm_mux *gsm, unsigned int command, u8 *data, int clen) { struct gsm_control *ctrl = kzalloc(sizeof(struct gsm_control), GFP_KERNEL); unsigned long flags; if (ctrl == NULL) return NULL; retry: wait_event(gsm->event, gsm->pending_cmd == NULL); spin_lock_irqsave(&gsm->control_lock, flags); if (gsm->pending_cmd != NULL) { spin_unlock_irqrestore(&gsm->control_lock, flags); goto retry; } ctrl->cmd = command; ctrl->data = data; ctrl->len = clen; gsm->pending_cmd = ctrl; |
e9ec22547 tty: n_gsm: Fix l... |
1342 1343 1344 1345 1346 1347 |
/* If DLCI0 is in ADM mode skip retries, it won't respond */ if (gsm->dlci[0]->mode == DLCI_MODE_ADM) gsm->cretries = 1; else gsm->cretries = gsm->n2; |
e1eaea46b tty: n_gsm line d... |
1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 |
mod_timer(&gsm->t2_timer, jiffies + gsm->t2 * HZ / 100); gsm_control_transmit(gsm, ctrl); spin_unlock_irqrestore(&gsm->control_lock, flags); return ctrl; } /** * gsm_control_wait - wait for a control to finish * @gsm: GSM mux * @control: control we are waiting on * * Waits for the control to complete or time out. Frees any used * resources and returns 0 for success, or an error if the remote * rejected or ignored the request. */ static int gsm_control_wait(struct gsm_mux *gsm, struct gsm_control *control) { int err; wait_event(gsm->event, control->done == 1); err = control->error; kfree(control); return err; } /* * DLCI level handling: Needs krefs */ /* * State transitions and timers */ /** * gsm_dlci_close - a DLCI has closed * @dlci: DLCI that closed * * Perform processing when moving a DLCI into closed state. If there * is an attached tty this is hung up */ static void gsm_dlci_close(struct gsm_dlci *dlci) { del_timer(&dlci->t1); if (debug & 8) |
5f9a31d63 n_gsm: clean up p... |
1394 1395 |
pr_debug("DLCI %d goes closed. ", dlci->addr); |
e1eaea46b tty: n_gsm line d... |
1396 1397 |
dlci->state = DLCI_CLOSED; if (dlci->addr != 0) { |
aa27a094e TTY: add tty_port... |
1398 |
tty_port_tty_hangup(&dlci->port, false); |
036bca1fc n_gsm: drop unnee... |
1399 |
kfifo_reset(&dlci->fifo); |
e1eaea46b tty: n_gsm line d... |
1400 |
} else |
5677fcf37 n_gsm: switch dea... |
1401 |
dlci->gsm->dead = true; |
e1eaea46b tty: n_gsm line d... |
1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 |
wake_up(&dlci->gsm->event); /* A DLCI 0 close is a MUX termination so we need to kick that back to userspace somehow */ } /** * gsm_dlci_open - a DLCI has opened * @dlci: DLCI that opened * * Perform processing when moving a DLCI into open state. */ static void gsm_dlci_open(struct gsm_dlci *dlci) { /* Note that SABM UA .. SABM UA first UA lost can mean that we go open -> open */ del_timer(&dlci->t1); /* This will let a tty open continue */ dlci->state = DLCI_OPEN; if (debug & 8) |
5f9a31d63 n_gsm: clean up p... |
1422 1423 |
pr_debug("DLCI %d goes open. ", dlci->addr); |
e1eaea46b tty: n_gsm line d... |
1424 1425 1426 1427 1428 |
wake_up(&dlci->gsm->event); } /** * gsm_dlci_t1 - T1 timer expiry |
724ac070f tty: ldiscs, fix ... |
1429 |
* @t: timer contained in the DLCI that opened |
e1eaea46b tty: n_gsm line d... |
1430 1431 1432 1433 1434 1435 |
* * The T1 timer handles retransmits of control frames (essentially of * SABM and DISC). We resend the command until the retry count runs out * in which case an opening port goes back to closed and a closing port * is simply put into closed state (any further frames from the other * end will get a DM response) |
ea3d8465a tty: n_gsm: Allow... |
1436 1437 1438 1439 |
* * Some control dlci can stay in ADM mode with other dlci working just * fine. In that case we can just keep the control dlci open after the * DLCI_OPENING retries time out. |
e1eaea46b tty: n_gsm line d... |
1440 |
*/ |
e99e88a9d treewide: setup_t... |
1441 |
static void gsm_dlci_t1(struct timer_list *t) |
e1eaea46b tty: n_gsm line d... |
1442 |
{ |
e99e88a9d treewide: setup_t... |
1443 |
struct gsm_dlci *dlci = from_timer(dlci, t, t1); |
e1eaea46b tty: n_gsm line d... |
1444 1445 1446 1447 1448 1449 1450 1451 |
struct gsm_mux *gsm = dlci->gsm; switch (dlci->state) { case DLCI_OPENING: dlci->retries--; if (dlci->retries) { gsm_command(dlci->gsm, dlci->addr, SABM|PF); mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); |
ea3d8465a tty: n_gsm: Allow... |
1452 1453 1454 1455 1456 |
} else if (!dlci->addr && gsm->control == (DM | PF)) { if (debug & 8) pr_info("DLCI %d opening in ADM mode. ", dlci->addr); |
e9ec22547 tty: n_gsm: Fix l... |
1457 |
dlci->mode = DLCI_MODE_ADM; |
ea3d8465a tty: n_gsm: Allow... |
1458 1459 |
gsm_dlci_open(dlci); } else { |
e1eaea46b tty: n_gsm line d... |
1460 |
gsm_dlci_close(dlci); |
ea3d8465a tty: n_gsm: Allow... |
1461 |
} |
e1eaea46b tty: n_gsm line d... |
1462 1463 1464 1465 1466 1467 1468 1469 1470 |
break; case DLCI_CLOSING: dlci->retries--; if (dlci->retries) { gsm_command(dlci->gsm, dlci->addr, DISC|PF); mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); } else gsm_dlci_close(dlci); break; |
72ae8cc19 n_gsm: introduce ... |
1471 1472 1473 1474 |
default: pr_debug("%s: unhandled state: %d ", __func__, dlci->state); break; |
e1eaea46b tty: n_gsm line d... |
1475 1476 1477 1478 1479 1480 1481 1482 |
} } /** * gsm_dlci_begin_open - start channel open procedure * @dlci: DLCI to open * * Commence opening a DLCI from the Linux side. We issue SABM messages |
ea3d8465a tty: n_gsm: Allow... |
1483 1484 |
* to the modem which should then reply with a UA or ADM, at which point * we will move into open state. Opening is done asynchronously with retry |
e1eaea46b tty: n_gsm line d... |
1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 |
* running off timers and the responses. */ static void gsm_dlci_begin_open(struct gsm_dlci *dlci) { struct gsm_mux *gsm = dlci->gsm; if (dlci->state == DLCI_OPEN || dlci->state == DLCI_OPENING) return; dlci->retries = gsm->n2; dlci->state = DLCI_OPENING; gsm_command(dlci->gsm, dlci->addr, SABM|PF); mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); } /** * gsm_dlci_begin_close - start channel open procedure * @dlci: DLCI to open * * Commence closing a DLCI from the Linux side. We issue DISC messages * to the modem which should then reply with a UA, at which point we * will move into closed state. Closing is done asynchronously with retry * off timers. We may also receive a DM reply from the other end which * indicates the channel was already closed. */ static void gsm_dlci_begin_close(struct gsm_dlci *dlci) { struct gsm_mux *gsm = dlci->gsm; if (dlci->state == DLCI_CLOSED || dlci->state == DLCI_CLOSING) return; dlci->retries = gsm->n2; dlci->state = DLCI_CLOSING; gsm_command(dlci->gsm, dlci->addr, DISC|PF); mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); } /** * gsm_dlci_data - data arrived * @dlci: channel * @data: block of bytes received |
724ac070f tty: ldiscs, fix ... |
1525 |
* @clen: length of received block |
e1eaea46b tty: n_gsm line d... |
1526 1527 1528 1529 1530 |
* * A UI or UIH frame has arrived which contains data for a channel * other than the control channel. If the relevant virtual tty is * open we shovel the bits down it, if not we drop them. */ |
4feb7a4a1 n_gsm: Constify u... |
1531 |
static void gsm_dlci_data(struct gsm_dlci *dlci, const u8 *data, int clen) |
e1eaea46b tty: n_gsm line d... |
1532 1533 1534 |
{ /* krefs .. */ struct tty_port *port = &dlci->port; |
2e124b4a3 TTY: switch tty_f... |
1535 |
struct tty_struct *tty; |
e1eaea46b tty: n_gsm line d... |
1536 |
unsigned int modem = 0; |
7263287af tty: n_gsm: Fixed... |
1537 |
int len = clen; |
e1eaea46b tty: n_gsm line d... |
1538 1539 |
if (debug & 16) |
2e124b4a3 TTY: switch tty_f... |
1540 1541 1542 1543 |
pr_debug("%d bytes for tty ", len); switch (dlci->adaption) { /* Unsupported types */ |
3e913eebd tty: n_gsm: Mark ... |
1544 |
case 4: /* Packetised interruptible data */ |
2e124b4a3 TTY: switch tty_f... |
1545 |
break; |
3e913eebd tty: n_gsm: Mark ... |
1546 |
case 3: /* Packetised uininterruptible voice/data */ |
2e124b4a3 TTY: switch tty_f... |
1547 |
break; |
3e913eebd tty: n_gsm: Mark ... |
1548 |
case 2: /* Asynchronous serial with line state in each frame */ |
2e124b4a3 TTY: switch tty_f... |
1549 1550 1551 1552 1553 1554 1555 |
while (gsm_read_ea(&modem, *data++) == 0) { len--; if (len == 0) return; } tty = tty_port_tty_get(port); if (tty) { |
7263287af tty: n_gsm: Fixed... |
1556 |
gsm_process_modem(tty, dlci, modem, clen); |
2e124b4a3 TTY: switch tty_f... |
1557 |
tty_kref_put(tty); |
e1eaea46b tty: n_gsm line d... |
1558 |
} |
df561f668 treewide: Use fal... |
1559 |
fallthrough; |
3e913eebd tty: n_gsm: Mark ... |
1560 |
case 1: /* Line state will go via DLCI 0 controls only */ |
2e124b4a3 TTY: switch tty_f... |
1561 1562 1563 |
default: tty_insert_flip_string(port, data, len); tty_flip_buffer_push(port); |
e1eaea46b tty: n_gsm line d... |
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 |
} } /** * gsm_dlci_control - data arrived on control channel * @dlci: channel * @data: block of bytes received * @len: length of received block * * A UI or UIH frame has arrived which contains data for DLCI 0 the * control channel. This should contain a command EA followed by * control data bytes. The command EA contains a command/response bit * and we divide up the work accordingly. */ |
4feb7a4a1 n_gsm: Constify u... |
1578 |
static void gsm_dlci_command(struct gsm_dlci *dlci, const u8 *data, int len) |
e1eaea46b tty: n_gsm line d... |
1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 |
{ /* See what command is involved */ unsigned int command = 0; while (len-- > 0) { if (gsm_read_ea(&command, *data++) == 1) { int clen = *data++; len--; /* FIXME: this is properly an EA */ clen >>= 1; /* Malformed command ? */ if (clen > len) return; if (command & 1) gsm_control_message(dlci->gsm, command, data, clen); else gsm_control_response(dlci->gsm, command, data, clen); return; } } } /* * Allocate/Free DLCI channels */ /** * gsm_dlci_alloc - allocate a DLCI * @gsm: GSM mux * @addr: address of the DLCI * * Allocate and install a new DLCI object into the GSM mux. * * FIXME: review locking races */ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr) { struct gsm_dlci *dlci = kzalloc(sizeof(struct gsm_dlci), GFP_ATOMIC); if (dlci == NULL) return NULL; spin_lock_init(&dlci->lock); |
bcd5abe28 tty: n_gsm: Add r... |
1622 |
mutex_init(&dlci->mutex); |
036bca1fc n_gsm: drop unnee... |
1623 |
if (kfifo_alloc(&dlci->fifo, 4096, GFP_KERNEL) < 0) { |
e1eaea46b tty: n_gsm line d... |
1624 1625 1626 1627 1628 |
kfree(dlci); return NULL; } skb_queue_head_init(&dlci->skb_list); |
e99e88a9d treewide: setup_t... |
1629 |
timer_setup(&dlci->t1, gsm_dlci_t1, 0); |
e1eaea46b tty: n_gsm line d... |
1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 |
tty_port_init(&dlci->port); dlci->port.ops = &gsm_port_ops; dlci->gsm = gsm; dlci->addr = addr; dlci->adaption = gsm->adaption; dlci->state = DLCI_CLOSED; if (addr) dlci->data = gsm_dlci_data; else dlci->data = gsm_dlci_command; gsm->dlci[addr] = dlci; return dlci; } /** |
6ab8fba7f tty: n_gsm: Added... |
1645 |
* gsm_dlci_free - free DLCI |
724ac070f tty: ldiscs, fix ... |
1646 |
* @port: tty port for DLCI to free |
6ab8fba7f tty: n_gsm: Added... |
1647 1648 1649 1650 1651 |
* * Free up a DLCI. * * Can sleep. */ |
9a8e62bc6 TTY: n_gsm, use k... |
1652 |
static void gsm_dlci_free(struct tty_port *port) |
6ab8fba7f tty: n_gsm: Added... |
1653 |
{ |
9a8e62bc6 TTY: n_gsm, use k... |
1654 |
struct gsm_dlci *dlci = container_of(port, struct gsm_dlci, port); |
6ab8fba7f tty: n_gsm: Added... |
1655 1656 1657 |
del_timer_sync(&dlci->t1); dlci->gsm->dlci[dlci->addr] = NULL; |
036bca1fc n_gsm: drop unnee... |
1658 |
kfifo_free(&dlci->fifo); |
6ab8fba7f tty: n_gsm: Added... |
1659 |
while ((dlci->skb = skb_dequeue(&dlci->skb_list))) |
329e56780 n_gsm: replace kf... |
1660 |
dev_kfree_skb(dlci->skb); |
6ab8fba7f tty: n_gsm: Added... |
1661 1662 1663 1664 1665 |
kfree(dlci); } static inline void dlci_get(struct gsm_dlci *dlci) { |
9a8e62bc6 TTY: n_gsm, use k... |
1666 |
tty_port_get(&dlci->port); |
6ab8fba7f tty: n_gsm: Added... |
1667 1668 1669 1670 |
} static inline void dlci_put(struct gsm_dlci *dlci) { |
9a8e62bc6 TTY: n_gsm, use k... |
1671 |
tty_port_put(&dlci->port); |
6ab8fba7f tty: n_gsm: Added... |
1672 |
} |
4d9b10906 tty: Prevent dead... |
1673 |
static void gsm_destroy_network(struct gsm_dlci *dlci); |
6ab8fba7f tty: n_gsm: Added... |
1674 1675 |
/** * gsm_dlci_release - release DLCI |
e1eaea46b tty: n_gsm line d... |
1676 1677 |
* @dlci: DLCI to destroy * |
6ab8fba7f tty: n_gsm: Added... |
1678 1679 |
* Release a DLCI. Actual free is deferred until either * mux is closed or tty is closed - whichever is last. |
e1eaea46b tty: n_gsm line d... |
1680 1681 1682 |
* * Can sleep. */ |
6ab8fba7f tty: n_gsm: Added... |
1683 |
static void gsm_dlci_release(struct gsm_dlci *dlci) |
e1eaea46b tty: n_gsm line d... |
1684 1685 1686 |
{ struct tty_struct *tty = tty_port_tty_get(&dlci->port); if (tty) { |
4d9b10906 tty: Prevent dead... |
1687 1688 1689 |
mutex_lock(&dlci->mutex); gsm_destroy_network(dlci); mutex_unlock(&dlci->mutex); |
7030082a7 tty: n_gsm: avoid... |
1690 |
tty_hangup(tty); |
be7065725 TTY/n_gsm: Removi... |
1691 |
|
4d9b10906 tty: Prevent dead... |
1692 |
tty_port_tty_set(&dlci->port, NULL); |
e1eaea46b tty: n_gsm line d... |
1693 1694 |
tty_kref_put(tty); } |
4d9b10906 tty: Prevent dead... |
1695 |
dlci->state = DLCI_CLOSED; |
6ab8fba7f tty: n_gsm: Added... |
1696 |
dlci_put(dlci); |
e1eaea46b tty: n_gsm line d... |
1697 |
} |
e1eaea46b tty: n_gsm line d... |
1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 |
/* * LAPBish link layer logic */ /** * gsm_queue - a GSM frame is ready to process * @gsm: pointer to our gsm mux * * At this point in time a frame has arrived and been demangled from * the line encoding. All the differences between the encodings have * been handled below us and the frame is unpacked into the structures. * The fcs holds the header FCS but any data FCS must be added here. */ static void gsm_queue(struct gsm_mux *gsm) { struct gsm_dlci *dlci; u8 cr; int address; /* We have to sneak a look at the packet body to do the FCS. A somewhat layering violation in the spec */ if ((gsm->control & ~PF) == UI) gsm->fcs = gsm_fcs_add_block(gsm->fcs, gsm->buf, gsm->len); |
f3c909b42 Drivers: tty: n_g... |
1722 1723 1724 1725 1726 |
if (gsm->encoding == 0) { /* WARNING: gsm->received_fcs is used for gsm->encoding = 0 only. In this case it contain the last piece of data required to generate final CRC */ |
9db4e4381 tty/n_gsm: fix bu... |
1727 1728 |
gsm->fcs = gsm_fcs_add(gsm->fcs, gsm->received_fcs); } |
e1eaea46b tty: n_gsm line d... |
1729 1730 1731 |
if (gsm->fcs != GOOD_FCS) { gsm->bad_fcs++; if (debug & 4) |
5f9a31d63 n_gsm: clean up p... |
1732 1733 |
pr_debug("BAD FCS %02x ", gsm->fcs); |
e1eaea46b tty: n_gsm line d... |
1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 |
return; } address = gsm->address >> 1; if (address >= NUM_DLCI) goto invalid; cr = gsm->address & 1; /* C/R bit */ gsm_print_packet("<--", address, cr, gsm->control, gsm->buf, gsm->len); cr ^= 1 - gsm->initiator; /* Flip so 1 always means command */ dlci = gsm->dlci[address]; switch (gsm->control) { case SABM|PF: if (cr == 0) goto invalid; if (dlci == NULL) dlci = gsm_dlci_alloc(gsm, address); if (dlci == NULL) return; if (dlci->dead) gsm_response(gsm, address, DM); else { gsm_response(gsm, address, UA); gsm_dlci_open(dlci); } break; case DISC|PF: if (cr == 0) goto invalid; if (dlci == NULL || dlci->state == DLCI_CLOSED) { gsm_response(gsm, address, DM); return; } /* Real close complete */ gsm_response(gsm, address, UA); gsm_dlci_close(dlci); break; case UA: case UA|PF: if (cr == 0 || dlci == NULL) break; switch (dlci->state) { case DLCI_CLOSING: gsm_dlci_close(dlci); break; case DLCI_OPENING: gsm_dlci_open(dlci); break; |
72ae8cc19 n_gsm: introduce ... |
1784 1785 1786 1787 1788 |
default: pr_debug("%s: unhandled state: %d ", __func__, dlci->state); break; |
e1eaea46b tty: n_gsm line d... |
1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 |
} break; case DM: /* DM can be valid unsolicited */ case DM|PF: if (cr) goto invalid; if (dlci == NULL) return; gsm_dlci_close(dlci); break; case UI: case UI|PF: case UIH: case UIH|PF: #if 0 if (cr) goto invalid; #endif if (dlci == NULL || dlci->state != DLCI_OPEN) { gsm_command(gsm, address, DM|PF); return; } dlci->data(dlci, gsm->buf, gsm->len); break; default: goto invalid; } return; invalid: gsm->malformed++; return; } /** * gsm0_receive - perform processing for non-transparency * @gsm: gsm data for this ldisc instance * @c: character * * Receive bytes in gsm mode 0 */ static void gsm0_receive(struct gsm_mux *gsm, unsigned char c) { |
c2f2f0000 n_gsm: Fix suppor... |
1833 |
unsigned int len; |
e1eaea46b tty: n_gsm line d... |
1834 1835 1836 1837 1838 1839 1840 1841 |
switch (gsm->state) { case GSM_SEARCH: /* SOF marker */ if (c == GSM0_SOF) { gsm->state = GSM_ADDRESS; gsm->address = 0; gsm->len = 0; gsm->fcs = INIT_FCS; } |
c2f2f0000 n_gsm: Fix suppor... |
1842 1843 |
break; case GSM_ADDRESS: /* Address EA */ |
e1eaea46b tty: n_gsm line d... |
1844 1845 1846 1847 1848 1849 1850 |
gsm->fcs = gsm_fcs_add(gsm->fcs, c); if (gsm_read_ea(&gsm->address, c)) gsm->state = GSM_CONTROL; break; case GSM_CONTROL: /* Control Byte */ gsm->fcs = gsm_fcs_add(gsm->fcs, c); gsm->control = c; |
c2f2f0000 n_gsm: Fix suppor... |
1851 |
gsm->state = GSM_LEN0; |
e1eaea46b tty: n_gsm line d... |
1852 |
break; |
c2f2f0000 n_gsm: Fix suppor... |
1853 |
case GSM_LEN0: /* Length EA */ |
e1eaea46b tty: n_gsm line d... |
1854 1855 1856 1857 1858 1859 1860 1861 |
gsm->fcs = gsm_fcs_add(gsm->fcs, c); if (gsm_read_ea(&gsm->len, c)) { if (gsm->len > gsm->mru) { gsm->bad_size++; gsm->state = GSM_SEARCH; break; } gsm->count = 0; |
c2f2f0000 n_gsm: Fix suppor... |
1862 1863 1864 1865 1866 |
if (!gsm->len) gsm->state = GSM_FCS; else gsm->state = GSM_DATA; break; |
e1eaea46b tty: n_gsm line d... |
1867 |
} |
c2f2f0000 n_gsm: Fix suppor... |
1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 |
gsm->state = GSM_LEN1; break; case GSM_LEN1: gsm->fcs = gsm_fcs_add(gsm->fcs, c); len = c; gsm->len |= len << 7; if (gsm->len > gsm->mru) { gsm->bad_size++; gsm->state = GSM_SEARCH; break; |
e1eaea46b tty: n_gsm line d... |
1878 |
} |
c2f2f0000 n_gsm: Fix suppor... |
1879 1880 1881 1882 1883 |
gsm->count = 0; if (!gsm->len) gsm->state = GSM_FCS; else gsm->state = GSM_DATA; |
e1eaea46b tty: n_gsm line d... |
1884 1885 1886 1887 1888 1889 1890 |
break; case GSM_DATA: /* Data */ gsm->buf[gsm->count++] = c; if (gsm->count == gsm->len) gsm->state = GSM_FCS; break; case GSM_FCS: /* FCS follows the packet */ |
c2f2f0000 n_gsm: Fix suppor... |
1891 |
gsm->received_fcs = c; |
e1eaea46b tty: n_gsm line d... |
1892 |
gsm_queue(gsm); |
c2f2f0000 n_gsm: Fix suppor... |
1893 1894 1895 1896 1897 1898 1899 |
gsm->state = GSM_SSOF; break; case GSM_SSOF: if (c == GSM0_SOF) { gsm->state = GSM_SEARCH; break; } |
e1eaea46b tty: n_gsm line d... |
1900 |
break; |
329aa6e6e n_gsm: introduce ... |
1901 1902 1903 1904 |
default: pr_debug("%s: unhandled state: %d ", __func__, gsm->state); break; |
e1eaea46b tty: n_gsm line d... |
1905 1906 1907 1908 |
} } /** |
c2f2f0000 n_gsm: Fix suppor... |
1909 |
* gsm1_receive - perform processing for non-transparency |
e1eaea46b tty: n_gsm line d... |
1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 |
* @gsm: gsm data for this ldisc instance * @c: character * * Receive bytes in mode 1 (Advanced option) */ static void gsm1_receive(struct gsm_mux *gsm, unsigned char c) { if (c == GSM1_SOF) { /* EOF is only valid in frame if we have got to the data state and received at least one byte (the FCS) */ if (gsm->state == GSM_DATA && gsm->count) { /* Extract the FCS */ gsm->count--; gsm->fcs = gsm_fcs_add(gsm->fcs, gsm->buf[gsm->count]); gsm->len = gsm->count; gsm_queue(gsm); gsm->state = GSM_START; return; } /* Any partial frame was a runt so go back to start */ if (gsm->state != GSM_START) { gsm->malformed++; gsm->state = GSM_START; } /* A SOF in GSM_START means we are still reading idling or framing bytes */ return; } if (c == GSM1_ESCAPE) { |
c50704bde n_gsm: switch esc... |
1941 |
gsm->escape = true; |
e1eaea46b tty: n_gsm line d... |
1942 1943 1944 1945 1946 1947 1948 1949 1950 |
return; } /* Only an unescaped SOF gets us out of GSM search */ if (gsm->state == GSM_SEARCH) return; if (gsm->escape) { c ^= GSM1_ESCAPE_BITS; |
c50704bde n_gsm: switch esc... |
1951 |
gsm->escape = false; |
e1eaea46b tty: n_gsm line d... |
1952 1953 1954 1955 1956 1957 |
} switch (gsm->state) { case GSM_START: /* First byte after SOF */ gsm->address = 0; gsm->state = GSM_ADDRESS; gsm->fcs = INIT_FCS; |
df561f668 treewide: Use fal... |
1958 |
fallthrough; |
e1eaea46b tty: n_gsm line d... |
1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 |
case GSM_ADDRESS: /* Address continuation */ gsm->fcs = gsm_fcs_add(gsm->fcs, c); if (gsm_read_ea(&gsm->address, c)) gsm->state = GSM_CONTROL; break; case GSM_CONTROL: /* Control Byte */ gsm->fcs = gsm_fcs_add(gsm->fcs, c); gsm->control = c; gsm->count = 0; gsm->state = GSM_DATA; break; case GSM_DATA: /* Data */ |
5f9a31d63 n_gsm: clean up p... |
1971 |
if (gsm->count > gsm->mru) { /* Allow one for the FCS */ |
e1eaea46b tty: n_gsm line d... |
1972 1973 1974 1975 1976 1977 1978 |
gsm->state = GSM_OVERRUN; gsm->bad_size++; } else gsm->buf[gsm->count++] = c; break; case GSM_OVERRUN: /* Over-long - eg a dropped SOF */ break; |
329aa6e6e n_gsm: introduce ... |
1979 1980 1981 1982 |
default: pr_debug("%s: unhandled state: %d ", __func__, gsm->state); break; |
e1eaea46b tty: n_gsm line d... |
1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 |
} } /** * gsm_error - handle tty error * @gsm: ldisc data * @data: byte received (may be invalid) * @flag: error received * * Handle an error in the receipt of data for a frame. Currently we just * go back to hunting for a SOF. * * FIXME: better diagnostics ? */ static void gsm_error(struct gsm_mux *gsm, unsigned char data, unsigned char flag) { gsm->state = GSM_SEARCH; gsm->io_error++; } |
71e077915 tty: n_gsm: do no... |
2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 |
static int gsm_disconnect(struct gsm_mux *gsm) { struct gsm_dlci *dlci = gsm->dlci[0]; struct gsm_control *gc; if (!dlci) return 0; /* In theory disconnecting DLCI 0 is sufficient but for some modems this is apparently not the case. */ gc = gsm_control_send(gsm, CMD_CLD, NULL, 0); if (gc) gsm_control_wait(gsm, gc); del_timer_sync(&gsm->t2_timer); /* Now we are sure T2 has stopped */ gsm_dlci_begin_close(dlci); wait_event_interruptible(gsm->event, dlci->state == DLCI_CLOSED); if (signal_pending(current)) return -EINTR; return 0; } |
e1eaea46b tty: n_gsm line d... |
2030 2031 2032 2033 2034 2035 2036 2037 |
/** * gsm_cleanup_mux - generic GSM protocol cleanup * @gsm: our mux * * Clean up the bits of the mux which are the same for all framing * protocols. Remove the mux from the mux table, stop all the timers * and then shut down each device hanging up the channels as we go. */ |
54af58363 drivers: tty: Mar... |
2038 |
static void gsm_cleanup_mux(struct gsm_mux *gsm) |
e1eaea46b tty: n_gsm line d... |
2039 2040 2041 |
{ int i; struct gsm_dlci *dlci = gsm->dlci[0]; |
329e56780 n_gsm: replace kf... |
2042 |
struct gsm_msg *txq, *ntxq; |
e1eaea46b tty: n_gsm line d... |
2043 |
|
5677fcf37 n_gsm: switch dea... |
2044 |
gsm->dead = true; |
e1eaea46b tty: n_gsm line d... |
2045 2046 2047 2048 2049 2050 2051 2052 2053 |
spin_lock(&gsm_mux_lock); for (i = 0; i < MAX_MUX; i++) { if (gsm_mux[i] == gsm) { gsm_mux[i] = NULL; break; } } spin_unlock(&gsm_mux_lock); |
d175feca8 TTY: n_gsm, fix f... |
2054 2055 2056 |
/* open failed before registering => nothing to do */ if (i == MAX_MUX) return; |
e1eaea46b tty: n_gsm line d... |
2057 2058 2059 |
del_timer_sync(&gsm->t2_timer); /* Now we are sure T2 has stopped */ |
71e077915 tty: n_gsm: do no... |
2060 |
if (dlci) |
5677fcf37 n_gsm: switch dea... |
2061 |
dlci->dead = true; |
71e077915 tty: n_gsm: do no... |
2062 |
|
e1eaea46b tty: n_gsm line d... |
2063 |
/* Free up any link layer users */ |
dfabf7ffa n_gsm: race betwe... |
2064 |
mutex_lock(&gsm->mutex); |
e1eaea46b tty: n_gsm line d... |
2065 2066 |
for (i = 0; i < NUM_DLCI; i++) if (gsm->dlci[i]) |
6ab8fba7f tty: n_gsm: Added... |
2067 |
gsm_dlci_release(gsm->dlci[i]); |
dfabf7ffa n_gsm: race betwe... |
2068 |
mutex_unlock(&gsm->mutex); |
e1eaea46b tty: n_gsm line d... |
2069 |
/* Now wipe the queues */ |
b4338e1ef n_gsm: avoid acce... |
2070 |
list_for_each_entry_safe(txq, ntxq, &gsm->tx_list, list) |
e1eaea46b tty: n_gsm line d... |
2071 |
kfree(txq); |
b4338e1ef n_gsm: avoid acce... |
2072 |
INIT_LIST_HEAD(&gsm->tx_list); |
e1eaea46b tty: n_gsm line d... |
2073 |
} |
e1eaea46b tty: n_gsm line d... |
2074 2075 2076 2077 2078 2079 2080 2081 2082 |
/** * gsm_activate_mux - generic GSM setup * @gsm: our mux * * Set up the bits of the mux which are the same for all framing * protocols. Add the mux to the mux table so it can be opened and * finally kick off connecting to DLCI 0 on the modem. */ |
54af58363 drivers: tty: Mar... |
2083 |
static int gsm_activate_mux(struct gsm_mux *gsm) |
e1eaea46b tty: n_gsm line d... |
2084 2085 2086 |
{ struct gsm_dlci *dlci; int i = 0; |
e99e88a9d treewide: setup_t... |
2087 |
timer_setup(&gsm->t2_timer, gsm_control_retransmit, 0); |
e1eaea46b tty: n_gsm line d... |
2088 2089 2090 2091 2092 2093 2094 2095 |
init_waitqueue_head(&gsm->event); spin_lock_init(&gsm->control_lock); spin_lock_init(&gsm->tx_lock); if (gsm->encoding == 0) gsm->receive = gsm0_receive; else gsm->receive = gsm1_receive; |
e1eaea46b tty: n_gsm line d... |
2096 2097 2098 2099 |
spin_lock(&gsm_mux_lock); for (i = 0; i < MAX_MUX; i++) { if (gsm_mux[i] == NULL) { |
d50f6dcaf tty: n_gsm: expos... |
2100 |
gsm->num = i; |
e1eaea46b tty: n_gsm line d... |
2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 |
gsm_mux[i] = gsm; break; } } spin_unlock(&gsm_mux_lock); if (i == MAX_MUX) return -EBUSY; dlci = gsm_dlci_alloc(gsm, 0); if (dlci == NULL) return -ENOMEM; |
5677fcf37 n_gsm: switch dea... |
2112 |
gsm->dead = false; /* Tty opens are now permissible */ |
e1eaea46b tty: n_gsm line d... |
2113 2114 |
return 0; } |
e1eaea46b tty: n_gsm line d... |
2115 2116 2117 |
/** * gsm_free_mux - free up a mux |
724ac070f tty: ldiscs, fix ... |
2118 |
* @gsm: mux to free |
e1eaea46b tty: n_gsm line d... |
2119 |
* |
6ab8fba7f tty: n_gsm: Added... |
2120 |
* Dispose of allocated resources for a dead mux |
e1eaea46b tty: n_gsm line d... |
2121 |
*/ |
54af58363 drivers: tty: Mar... |
2122 |
static void gsm_free_mux(struct gsm_mux *gsm) |
e1eaea46b tty: n_gsm line d... |
2123 2124 2125 2126 2127 |
{ kfree(gsm->txframe); kfree(gsm->buf); kfree(gsm); } |
e1eaea46b tty: n_gsm line d... |
2128 2129 |
/** |
6ab8fba7f tty: n_gsm: Added... |
2130 |
* gsm_free_muxr - free up a mux |
724ac070f tty: ldiscs, fix ... |
2131 |
* @ref: kreference to the mux to free |
6ab8fba7f tty: n_gsm: Added... |
2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 |
* * Dispose of allocated resources for a dead mux */ static void gsm_free_muxr(struct kref *ref) { struct gsm_mux *gsm = container_of(ref, struct gsm_mux, ref); gsm_free_mux(gsm); } static inline void mux_get(struct gsm_mux *gsm) { kref_get(&gsm->ref); } static inline void mux_put(struct gsm_mux *gsm) { kref_put(&gsm->ref, gsm_free_muxr); } |
43a9e710c tty: n_gsm: add h... |
2150 2151 2152 2153 2154 2155 2156 2157 2158 |
static inline unsigned int mux_num_to_base(struct gsm_mux *gsm) { return gsm->num * NUM_DLCI; } static inline unsigned int mux_line_to_num(unsigned int line) { return line / NUM_DLCI; } |
6ab8fba7f tty: n_gsm: Added... |
2159 |
/** |
e1eaea46b tty: n_gsm line d... |
2160 2161 2162 2163 |
* gsm_alloc_mux - allocate a mux * * Creates a new mux ready for activation. */ |
54af58363 drivers: tty: Mar... |
2164 |
static struct gsm_mux *gsm_alloc_mux(void) |
e1eaea46b tty: n_gsm line d... |
2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 |
{ struct gsm_mux *gsm = kzalloc(sizeof(struct gsm_mux), GFP_KERNEL); if (gsm == NULL) return NULL; gsm->buf = kmalloc(MAX_MRU + 1, GFP_KERNEL); if (gsm->buf == NULL) { kfree(gsm); return NULL; } gsm->txframe = kmalloc(2 * MAX_MRU + 2, GFP_KERNEL); if (gsm->txframe == NULL) { kfree(gsm->buf); kfree(gsm); return NULL; } spin_lock_init(&gsm->lock); |
dfabf7ffa n_gsm: race betwe... |
2181 |
mutex_init(&gsm->mutex); |
6ab8fba7f tty: n_gsm: Added... |
2182 |
kref_init(&gsm->ref); |
b4338e1ef n_gsm: avoid acce... |
2183 |
INIT_LIST_HEAD(&gsm->tx_list); |
e1eaea46b tty: n_gsm line d... |
2184 2185 2186 2187 2188 |
gsm->t1 = T1; gsm->t2 = T2; gsm->n2 = N2; gsm->ftype = UIH; |
e1eaea46b tty: n_gsm line d... |
2189 2190 2191 2192 |
gsm->adaption = 1; gsm->encoding = 1; gsm->mru = 64; /* Default to encoding 1 so these should be 64 */ gsm->mtu = 64; |
5677fcf37 n_gsm: switch dea... |
2193 |
gsm->dead = true; /* Avoid early tty opens */ |
e1eaea46b tty: n_gsm line d... |
2194 2195 2196 |
return gsm; } |
e1eaea46b tty: n_gsm line d... |
2197 |
|
338410408 tty: n_gsm: Add c... |
2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 |
static void gsm_copy_config_values(struct gsm_mux *gsm, struct gsm_config *c) { memset(c, 0, sizeof(*c)); c->adaption = gsm->adaption; c->encapsulation = gsm->encoding; c->initiator = gsm->initiator; c->t1 = gsm->t1; c->t2 = gsm->t2; c->t3 = 0; /* Not supported */ c->n2 = gsm->n2; if (gsm->ftype == UIH) c->i = 1; else c->i = 2; pr_debug("Ftype %d i %d ", gsm->ftype, c->i); c->mru = gsm->mru; c->mtu = gsm->mtu; c->k = 0; } static int gsm_config(struct gsm_mux *gsm, struct gsm_config *c) { int need_close = 0; int need_restart = 0; /* Stuff we don't support yet - UI or I frame transport, windowing */ if ((c->adaption != 1 && c->adaption != 2) || c->k) return -EOPNOTSUPP; /* Check the MRU/MTU range looks sane */ if (c->mru > MAX_MRU || c->mtu > MAX_MTU || c->mru < 8 || c->mtu < 8) return -EINVAL; if (c->n2 < 3) return -EINVAL; if (c->encapsulation > 1) /* Basic, advanced, no I */ return -EINVAL; if (c->initiator > 1) return -EINVAL; if (c->i == 0 || c->i > 2) /* UIH and UI only */ return -EINVAL; /* * See what is needed for reconfiguration */ /* Timing fields */ if (c->t1 != 0 && c->t1 != gsm->t1) need_restart = 1; if (c->t2 != 0 && c->t2 != gsm->t2) need_restart = 1; if (c->encapsulation != gsm->encoding) need_restart = 1; if (c->adaption != gsm->adaption) need_restart = 1; /* Requires care */ if (c->initiator != gsm->initiator) need_close = 1; if (c->mru != gsm->mru) need_restart = 1; if (c->mtu != gsm->mtu) need_restart = 1; /* * Close down what is needed, restart and initiate the new * configuration */ if (need_close || need_restart) { int ret; ret = gsm_disconnect(gsm); if (ret) return ret; } if (need_restart) gsm_cleanup_mux(gsm); gsm->initiator = c->initiator; gsm->mru = c->mru; gsm->mtu = c->mtu; gsm->encoding = c->encapsulation; gsm->adaption = c->adaption; gsm->n2 = c->n2; if (c->i == 1) gsm->ftype = UIH; else if (c->i == 2) gsm->ftype = UI; if (c->t1) gsm->t1 = c->t1; if (c->t2) gsm->t2 = c->t2; /* * FIXME: We need to separate activation/deactivation from adding * and removing from the mux array */ if (need_restart) gsm_activate_mux(gsm); if (gsm->initiator && need_close) gsm_dlci_begin_open(gsm->dlci[0]); return 0; } |
e1eaea46b tty: n_gsm line d... |
2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 |
/** * gsmld_output - write to link * @gsm: our mux * @data: bytes to output * @len: size * * Write a block of data from the GSM mux to the data channel. This * will eventually be serialized from above but at the moment isn't. */ static int gsmld_output(struct gsm_mux *gsm, u8 *data, int len) { if (tty_write_room(gsm->tty) < len) { set_bit(TTY_DO_WRITE_WAKEUP, &gsm->tty->flags); return -ENOSPC; } |
0a77c4f9d n_gsm: Use print_... |
2319 2320 2321 |
if (debug & 4) print_hex_dump_bytes("gsmld_output: ", DUMP_PREFIX_OFFSET, data, len); |
e1eaea46b tty: n_gsm line d... |
2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 |
gsm->tty->ops->write(gsm->tty, data, len); return len; } /** * gsmld_attach_gsm - mode set up * @tty: our tty structure * @gsm: our mux * * Set up the MUX for basic mode and commence connecting to the * modem. Currently called from the line discipline set up but * will need moving to an ioctl path. */ static int gsmld_attach_gsm(struct tty_struct *tty, struct gsm_mux *gsm) { |
43a9e710c tty: n_gsm: add h... |
2338 2339 |
unsigned int base; int ret, i; |
e1eaea46b tty: n_gsm line d... |
2340 2341 |
gsm->tty = tty_kref_get(tty); |
e1eaea46b tty: n_gsm line d... |
2342 2343 2344 |
ret = gsm_activate_mux(gsm); if (ret != 0) tty_kref_put(gsm->tty); |
d50f6dcaf tty: n_gsm: expos... |
2345 2346 2347 |
else { /* Don't register device 0 - this is the control channel and not a usable tty interface */ |
43a9e710c tty: n_gsm: add h... |
2348 |
base = mux_num_to_base(gsm); /* Base for this MUX */ |
d50f6dcaf tty: n_gsm: expos... |
2349 2350 2351 |
for (i = 1; i < NUM_DLCI; i++) tty_register_device(gsm_tty_driver, base + i, NULL); } |
e1eaea46b tty: n_gsm line d... |
2352 2353 2354 2355 2356 2357 |
return ret; } /** * gsmld_detach_gsm - stop doing 0710 mux |
70f23fd66 treewide: fix a f... |
2358 |
* @tty: tty attached to the mux |
e1eaea46b tty: n_gsm line d... |
2359 2360 2361 2362 2363 2364 2365 |
* @gsm: mux * * Shutdown and then clean up the resources used by the line discipline */ static void gsmld_detach_gsm(struct tty_struct *tty, struct gsm_mux *gsm) { |
43a9e710c tty: n_gsm: add h... |
2366 |
unsigned int base = mux_num_to_base(gsm); /* Base for this MUX */ |
d50f6dcaf tty: n_gsm: expos... |
2367 |
int i; |
d50f6dcaf tty: n_gsm: expos... |
2368 |
|
e1eaea46b tty: n_gsm line d... |
2369 |
WARN_ON(tty != gsm->tty); |
d50f6dcaf tty: n_gsm: expos... |
2370 2371 |
for (i = 1; i < NUM_DLCI; i++) tty_unregister_device(gsm_tty_driver, base + i); |
e1eaea46b tty: n_gsm line d... |
2372 2373 2374 2375 |
gsm_cleanup_mux(gsm); tty_kref_put(gsm->tty); gsm->tty = NULL; } |
55db4c64e Revert "tty: make... |
2376 2377 |
static void gsmld_receive_buf(struct tty_struct *tty, const unsigned char *cp, char *fp, int count) |
e1eaea46b tty: n_gsm line d... |
2378 2379 2380 2381 2382 |
{ struct gsm_mux *gsm = tty->disc_data; const unsigned char *dp; char *f; int i; |
82f91fe09 tty: Always handl... |
2383 |
char flags = TTY_NORMAL; |
e1eaea46b tty: n_gsm line d... |
2384 |
|
0a77c4f9d n_gsm: Use print_... |
2385 2386 2387 |
if (debug & 4) print_hex_dump_bytes("gsmld_receive: ", DUMP_PREFIX_OFFSET, cp, count); |
e1eaea46b tty: n_gsm line d... |
2388 2389 |
for (i = count, dp = cp, f = fp; i; i--, dp++) { |
82f91fe09 tty: Always handl... |
2390 2391 |
if (f) flags = *f++; |
e1eaea46b tty: n_gsm line d... |
2392 2393 2394 2395 2396 2397 2398 2399 |
switch (flags) { case TTY_NORMAL: gsm->receive(gsm, *dp); break; case TTY_OVERRUN: case TTY_BREAK: case TTY_PARITY: case TTY_FRAME: |
a579767c1 tty: n_gsm, elimi... |
2400 |
gsm_error(gsm, *dp, flags); |
e1eaea46b tty: n_gsm line d... |
2401 2402 |
break; default: |
c01af4fec n_gsm : Flow cont... |
2403 2404 |
WARN_ONCE(1, "%s: unknown flag %d ", |
429b47499 tty: remove buf p... |
2405 |
tty_name(tty), flags); |
e1eaea46b tty: n_gsm line d... |
2406 2407 2408 2409 2410 2411 2412 2413 |
break; } } /* FASYNC if needed ? */ /* If clogged call tty_throttle(tty); */ } /** |
e1eaea46b tty: n_gsm line d... |
2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 |
* gsmld_flush_buffer - clean input queue * @tty: terminal device * * Flush the input buffer. Called when the line discipline is * being closed, when the tty layer wants the buffer flushed (eg * at hangup). */ static void gsmld_flush_buffer(struct tty_struct *tty) { } /** * gsmld_close - close the ldisc for this tty * @tty: device * * Called from the terminal layer when this line discipline is * being shut down, either because of a close or becsuse of a * discipline change. The function will not be called while other * ldisc methods are in progress. */ static void gsmld_close(struct tty_struct *tty) { struct gsm_mux *gsm = tty->disc_data; gsmld_detach_gsm(tty, gsm); gsmld_flush_buffer(tty); /* Do other clean up here */ |
6ab8fba7f tty: n_gsm: Added... |
2444 |
mux_put(gsm); |
e1eaea46b tty: n_gsm line d... |
2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 |
} /** * gsmld_open - open an ldisc * @tty: terminal to open * * Called when this line discipline is being attached to the * terminal device. Can sleep. Called serialized so that no * other events will occur in parallel. No further open will occur * until a close. */ static int gsmld_open(struct tty_struct *tty) { struct gsm_mux *gsm; |
5a6409670 tty/n_gsm.c: fix ... |
2460 |
int ret; |
e1eaea46b tty: n_gsm line d... |
2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 |
if (tty->ops->write == NULL) return -EINVAL; /* Attach our ldisc data */ gsm = gsm_alloc_mux(); if (gsm == NULL) return -ENOMEM; tty->disc_data = gsm; tty->receive_room = 65536; /* Attach the initial passive connection */ gsm->encoding = 1; |
5a6409670 tty/n_gsm.c: fix ... |
2475 2476 2477 2478 2479 2480 2481 |
ret = gsmld_attach_gsm(tty, gsm); if (ret != 0) { gsm_cleanup_mux(gsm); mux_put(gsm); } return ret; |
e1eaea46b tty: n_gsm line d... |
2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 |
} /** * gsmld_write_wakeup - asynchronous I/O notifier * @tty: tty device * * Required for the ptys, serial driver etc. since processes * that attach themselves to the master and rely on ASYNC * IO must be woken up */ static void gsmld_write_wakeup(struct tty_struct *tty) { struct gsm_mux *gsm = tty->disc_data; |
328be395a TTY/n_gsm: potent... |
2496 |
unsigned long flags; |
e1eaea46b tty: n_gsm line d... |
2497 2498 2499 |
/* Queue poll */ clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); |
5e44708f7 n_gsm: added inte... |
2500 |
spin_lock_irqsave(&gsm->tx_lock, flags); |
01dbb362f tty: n_gsm: Fix w... |
2501 |
gsm_data_kick(gsm, NULL); |
328be395a TTY/n_gsm: potent... |
2502 |
if (gsm->tx_bytes < TX_THRESH_LO) { |
e1eaea46b tty: n_gsm line d... |
2503 |
gsm_dlci_data_sweep(gsm); |
328be395a TTY/n_gsm: potent... |
2504 |
} |
5e44708f7 n_gsm: added inte... |
2505 |
spin_unlock_irqrestore(&gsm->tx_lock, flags); |
e1eaea46b tty: n_gsm line d... |
2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 |
} /** * gsmld_read - read function for tty * @tty: tty device * @file: file object * @buf: userspace buffer pointer * @nr: size of I/O * * Perform reads for the line discipline. We are guaranteed that the * line discipline will not be closed under us but we may get multiple * parallel readers and must handle this ourselves. We may also get * a hangup. Always called in user context, may sleep. * * This code must be sure never to sleep through a hangup. */ static ssize_t gsmld_read(struct tty_struct *tty, struct file *file, unsigned char __user *buf, size_t nr) { return -EOPNOTSUPP; } /** * gsmld_write - write function for tty * @tty: tty device * @file: file object * @buf: userspace buffer pointer * @nr: size of I/O * * Called when the owner of the device wants to send a frame * itself (or some other control data). The data is transferred * as-is and must be properly framed and checksummed as appropriate * by userspace. Frames are either sent whole or not at all as this * avoids pain user side. */ static ssize_t gsmld_write(struct tty_struct *tty, struct file *file, const unsigned char *buf, size_t nr) { int space = tty_write_room(tty); if (space >= nr) return tty->ops->write(tty, buf, nr); set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); return -ENOBUFS; } /** * gsmld_poll - poll method for N_GSM0710 * @tty: terminal device * @file: file accessing it * @wait: poll table * * Called when the line discipline is asked to poll() for data or * for special events. This code is not serialized with respect to * other events save open/close. * * This code must be sure never to sleep through a hangup. * Called without the kernel lock held - fine */ |
afc9a42b7 the rest of drive... |
2566 |
static __poll_t gsmld_poll(struct tty_struct *tty, struct file *file, |
e1eaea46b tty: n_gsm line d... |
2567 2568 |
poll_table *wait) { |
afc9a42b7 the rest of drive... |
2569 |
__poll_t mask = 0; |
e1eaea46b tty: n_gsm line d... |
2570 2571 2572 2573 2574 |
struct gsm_mux *gsm = tty->disc_data; poll_wait(file, &tty->read_wait, wait); poll_wait(file, &tty->write_wait, wait); if (tty_hung_up_p(file)) |
a9a08845e vfs: do bulk POLL... |
2575 |
mask |= EPOLLHUP; |
e1eaea46b tty: n_gsm line d... |
2576 |
if (!tty_is_writelocked(tty) && tty_write_room(tty) > 0) |
a9a08845e vfs: do bulk POLL... |
2577 |
mask |= EPOLLOUT | EPOLLWRNORM; |
e1eaea46b tty: n_gsm line d... |
2578 |
if (gsm->dead) |
a9a08845e vfs: do bulk POLL... |
2579 |
mask |= EPOLLHUP; |
e1eaea46b tty: n_gsm line d... |
2580 2581 |
return mask; } |
e1eaea46b tty: n_gsm line d... |
2582 2583 2584 2585 2586 |
static int gsmld_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) { struct gsm_config c; struct gsm_mux *gsm = tty->disc_data; |
a7b121b4b tty: n_gsm: add i... |
2587 |
unsigned int base; |
e1eaea46b tty: n_gsm line d... |
2588 2589 2590 |
switch (cmd) { case GSMIOC_GETCONF: |
338410408 tty: n_gsm: Add c... |
2591 |
gsm_copy_config_values(gsm, &c); |
edd05a735 n_gsm: add missin... |
2592 |
if (copy_to_user((void __user *)arg, &c, sizeof(c))) |
e1eaea46b tty: n_gsm line d... |
2593 2594 2595 |
return -EFAULT; return 0; case GSMIOC_SETCONF: |
edd05a735 n_gsm: add missin... |
2596 |
if (copy_from_user(&c, (void __user *)arg, sizeof(c))) |
e1eaea46b tty: n_gsm line d... |
2597 |
return -EFAULT; |
338410408 tty: n_gsm: Add c... |
2598 |
return gsm_config(gsm, &c); |
a7b121b4b tty: n_gsm: add i... |
2599 2600 2601 |
case GSMIOC_GETFIRST: base = mux_num_to_base(gsm); return put_user(base + 1, (__u32 __user *)arg); |
e1eaea46b tty: n_gsm line d... |
2602 2603 2604 2605 |
default: return n_tty_ioctl_helper(tty, file, cmd, arg); } } |
bcd5abe28 tty: n_gsm: Add r... |
2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 |
/* * Network interface * */ static int gsm_mux_net_open(struct net_device *net) { pr_debug("%s called ", __func__); netif_start_queue(net); return 0; } static int gsm_mux_net_close(struct net_device *net) { netif_stop_queue(net); return 0; } |
bcd5abe28 tty: n_gsm: Add r... |
2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 |
static void dlci_net_free(struct gsm_dlci *dlci) { if (!dlci->net) { WARN_ON(1); return; } dlci->adaption = dlci->prev_adaption; dlci->data = dlci->prev_data; free_netdev(dlci->net); dlci->net = NULL; } static void net_free(struct kref *ref) { struct gsm_mux_net *mux_net; struct gsm_dlci *dlci; mux_net = container_of(ref, struct gsm_mux_net, ref); dlci = mux_net->dlci; if (dlci->net) { unregister_netdev(dlci->net); dlci_net_free(dlci); } } |
6ab8fba7f tty: n_gsm: Added... |
2648 2649 2650 2651 2652 2653 2654 2655 2656 |
static inline void muxnet_get(struct gsm_mux_net *mux_net) { kref_get(&mux_net->ref); } static inline void muxnet_put(struct gsm_mux_net *mux_net) { kref_put(&mux_net->ref, net_free); } |
2468b3e4a tty: n_gsm: fix g... |
2657 |
static netdev_tx_t gsm_mux_net_start_xmit(struct sk_buff *skb, |
bcd5abe28 tty: n_gsm: Add r... |
2658 2659 |
struct net_device *net) { |
5dbc32a88 n_gsm: Drop unnee... |
2660 |
struct gsm_mux_net *mux_net = netdev_priv(net); |
bcd5abe28 tty: n_gsm: Add r... |
2661 |
struct gsm_dlci *dlci = mux_net->dlci; |
6ab8fba7f tty: n_gsm: Added... |
2662 |
muxnet_get(mux_net); |
bcd5abe28 tty: n_gsm: Add r... |
2663 2664 |
skb_queue_head(&dlci->skb_list, skb); |
47baf1ad8 tty: n_gsm: Use n... |
2665 2666 |
net->stats.tx_packets++; net->stats.tx_bytes += skb->len; |
bcd5abe28 tty: n_gsm: Add r... |
2667 2668 |
gsm_dlci_data_kick(dlci); /* And tell the kernel when the last transmit started. */ |
860e9538a treewide: replace... |
2669 |
netif_trans_update(net); |
6ab8fba7f tty: n_gsm: Added... |
2670 |
muxnet_put(mux_net); |
bcd5abe28 tty: n_gsm: Add r... |
2671 2672 2673 2674 |
return NETDEV_TX_OK; } /* called when a packet did not ack after watchdogtimeout */ |
0290bd291 netdev: pass the ... |
2675 |
static void gsm_mux_net_tx_timeout(struct net_device *net, unsigned int txqueue) |
bcd5abe28 tty: n_gsm: Add r... |
2676 2677 2678 2679 2680 2681 |
{ /* Tell syslog we are hosed. */ dev_dbg(&net->dev, "Tx timed out. "); /* Update statistics */ |
47baf1ad8 tty: n_gsm: Use n... |
2682 |
net->stats.tx_errors++; |
bcd5abe28 tty: n_gsm: Add r... |
2683 2684 2685 |
} static void gsm_mux_rx_netchar(struct gsm_dlci *dlci, |
4feb7a4a1 n_gsm: Constify u... |
2686 |
const unsigned char *in_buf, int size) |
bcd5abe28 tty: n_gsm: Add r... |
2687 2688 2689 |
{ struct net_device *net = dlci->net; struct sk_buff *skb; |
5dbc32a88 n_gsm: Drop unnee... |
2690 |
struct gsm_mux_net *mux_net = netdev_priv(net); |
6ab8fba7f tty: n_gsm: Added... |
2691 |
muxnet_get(mux_net); |
bcd5abe28 tty: n_gsm: Add r... |
2692 2693 2694 2695 2696 |
/* Allocate an sk_buff */ skb = dev_alloc_skb(size + NET_IP_ALIGN); if (!skb) { /* We got no receive buffer. */ |
47baf1ad8 tty: n_gsm: Use n... |
2697 |
net->stats.rx_dropped++; |
6ab8fba7f tty: n_gsm: Added... |
2698 |
muxnet_put(mux_net); |
bcd5abe28 tty: n_gsm: Add r... |
2699 2700 2701 |
return; } skb_reserve(skb, NET_IP_ALIGN); |
59ae1d127 networking: intro... |
2702 |
skb_put_data(skb, in_buf, size); |
bcd5abe28 tty: n_gsm: Add r... |
2703 2704 |
skb->dev = net; |
75406b3b1 tty: Convert use ... |
2705 |
skb->protocol = htons(ETH_P_IP); |
bcd5abe28 tty: n_gsm: Add r... |
2706 2707 2708 2709 2710 |
/* Ship it off to the kernel */ netif_rx(skb); /* update out statistics */ |
47baf1ad8 tty: n_gsm: Use n... |
2711 2712 |
net->stats.rx_packets++; net->stats.rx_bytes += size; |
6ab8fba7f tty: n_gsm: Added... |
2713 |
muxnet_put(mux_net); |
bcd5abe28 tty: n_gsm: Add r... |
2714 2715 |
return; } |
bcd5abe28 tty: n_gsm: Add r... |
2716 2717 2718 2719 2720 2721 2722 |
static void gsm_mux_net_init(struct net_device *net) { static const struct net_device_ops gsm_netdev_ops = { .ndo_open = gsm_mux_net_open, .ndo_stop = gsm_mux_net_close, .ndo_start_xmit = gsm_mux_net_start_xmit, .ndo_tx_timeout = gsm_mux_net_tx_timeout, |
bcd5abe28 tty: n_gsm: Add r... |
2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 |
}; net->netdev_ops = &gsm_netdev_ops; /* fill in the other fields */ net->watchdog_timeo = GSM_NET_TX_TIMEOUT; net->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST; net->type = ARPHRD_NONE; net->tx_queue_len = 10; } /* caller holds the dlci mutex */ static void gsm_destroy_network(struct gsm_dlci *dlci) { struct gsm_mux_net *mux_net; |
d8ca4ecf8 n_gsm: add missin... |
2739 2740 |
pr_debug("destroy network interface "); |
bcd5abe28 tty: n_gsm: Add r... |
2741 2742 |
if (!dlci->net) return; |
5dbc32a88 n_gsm: Drop unnee... |
2743 |
mux_net = netdev_priv(dlci->net); |
6ab8fba7f tty: n_gsm: Added... |
2744 |
muxnet_put(mux_net); |
bcd5abe28 tty: n_gsm: Add r... |
2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 |
} /* caller holds the dlci mutex */ static int gsm_create_network(struct gsm_dlci *dlci, struct gsm_netconfig *nc) { char *netname; int retval = 0; struct net_device *net; struct gsm_mux_net *mux_net; if (!capable(CAP_NET_ADMIN)) return -EPERM; /* Already in a non tty mode */ if (dlci->adaption > 2) return -EBUSY; if (nc->protocol != htons(ETH_P_IP)) return -EPROTONOSUPPORT; if (nc->adaption != 3 && nc->adaption != 4) return -EPROTONOSUPPORT; |
d8ca4ecf8 n_gsm: add missin... |
2768 2769 |
pr_debug("create network interface "); |
bcd5abe28 tty: n_gsm: Add r... |
2770 2771 2772 2773 |
netname = "gsm%d"; if (nc->if_name[0] != '\0') netname = nc->if_name; |
c835a6773 net: set name_ass... |
2774 2775 |
net = alloc_netdev(sizeof(struct gsm_mux_net), netname, NET_NAME_UNKNOWN, gsm_mux_net_init); |
bcd5abe28 tty: n_gsm: Add r... |
2776 |
if (!net) { |
d8ca4ecf8 n_gsm: add missin... |
2777 2778 |
pr_err("alloc_netdev failed "); |
bcd5abe28 tty: n_gsm: Add r... |
2779 2780 2781 |
return -ENOMEM; } net->mtu = dlci->gsm->mtu; |
9c22b4a34 net: use core MTU... |
2782 2783 |
net->min_mtu = 8; net->max_mtu = dlci->gsm->mtu; |
5dbc32a88 n_gsm: Drop unnee... |
2784 |
mux_net = netdev_priv(net); |
bcd5abe28 tty: n_gsm: Add r... |
2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 |
mux_net->dlci = dlci; kref_init(&mux_net->ref); strncpy(nc->if_name, net->name, IFNAMSIZ); /* return net name */ /* reconfigure dlci for network */ dlci->prev_adaption = dlci->adaption; dlci->prev_data = dlci->data; dlci->adaption = nc->adaption; dlci->data = gsm_mux_rx_netchar; dlci->net = net; |
d8ca4ecf8 n_gsm: add missin... |
2795 2796 |
pr_debug("register netdev "); |
bcd5abe28 tty: n_gsm: Add r... |
2797 2798 2799 2800 2801 2802 2803 2804 2805 |
retval = register_netdev(net); if (retval) { pr_err("network register fail %d ", retval); dlci_net_free(dlci); return retval; } return net->ifindex; /* return network index */ } |
e1eaea46b tty: n_gsm line d... |
2806 2807 |
/* Line discipline for real tty */ |
d3157b2ca tty/n_gsm: fix sp... |
2808 |
static struct tty_ldisc_ops tty_ldisc_packet = { |
e1eaea46b tty: n_gsm line d... |
2809 2810 2811 2812 2813 2814 |
.owner = THIS_MODULE, .magic = TTY_LDISC_MAGIC, .name = "n_gsm", .open = gsmld_open, .close = gsmld_close, .flush_buffer = gsmld_flush_buffer, |
e1eaea46b tty: n_gsm line d... |
2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 |
.read = gsmld_read, .write = gsmld_write, .ioctl = gsmld_ioctl, .poll = gsmld_poll, .receive_buf = gsmld_receive_buf, .write_wakeup = gsmld_write_wakeup }; /* * Virtual tty side */ #define TX_SIZE 512 static int gsmtty_modem_update(struct gsm_dlci *dlci, u8 brk) { u8 modembits[5]; struct gsm_control *ctrl; int len = 2; if (brk) len++; modembits[0] = len << 1 | EA; /* Data bytes */ modembits[1] = dlci->addr << 2 | 3; /* DLCI, EA, 1 */ modembits[2] = gsm_encode_modem(dlci) << 1 | EA; if (brk) modembits[3] = brk << 4 | 2 | EA; /* Valid, EA */ ctrl = gsm_control_send(dlci->gsm, CMD_MSC, modembits, len + 1); if (ctrl == NULL) return -ENOMEM; return gsm_control_wait(dlci->gsm, ctrl); } static int gsm_carrier_raised(struct tty_port *port) { struct gsm_dlci *dlci = container_of(port, struct gsm_dlci, port); |
b2d89ad9c tty: n_gsm: Fix D... |
2852 |
struct gsm_mux *gsm = dlci->gsm; |
e1eaea46b tty: n_gsm line d... |
2853 2854 2855 2856 2857 |
/* Not yet open so no carrier info */ if (dlci->state != DLCI_OPEN) return 0; if (debug & 2) return 1; |
b2d89ad9c tty: n_gsm: Fix D... |
2858 2859 2860 2861 2862 2863 2864 2865 |
/* * Basic mode with control channel in ADM mode may not respond * to CMD_MSC at all and modem_rx is empty. */ if (gsm->encoding == 0 && gsm->dlci[0]->mode == DLCI_MODE_ADM && !dlci->modem_rx) return 1; |
e1eaea46b tty: n_gsm line d... |
2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 |
return dlci->modem_rx & TIOCM_CD; } static void gsm_dtr_rts(struct tty_port *port, int onoff) { struct gsm_dlci *dlci = container_of(port, struct gsm_dlci, port); unsigned int modem_tx = dlci->modem_tx; if (onoff) modem_tx |= TIOCM_DTR | TIOCM_RTS; else modem_tx &= ~(TIOCM_DTR | TIOCM_RTS); if (modem_tx != dlci->modem_tx) { dlci->modem_tx = modem_tx; gsmtty_modem_update(dlci, 0); } } static const struct tty_port_operations gsm_port_ops = { .carrier_raised = gsm_carrier_raised, .dtr_rts = gsm_dtr_rts, |
9a8e62bc6 TTY: n_gsm, use k... |
2886 |
.destruct = gsm_dlci_free, |
e1eaea46b tty: n_gsm line d... |
2887 |
}; |
86176ed90 TTY: n_gsm, use t... |
2888 |
static int gsmtty_install(struct tty_driver *driver, struct tty_struct *tty) |
e1eaea46b tty: n_gsm line d... |
2889 2890 2891 |
{ struct gsm_mux *gsm; struct gsm_dlci *dlci; |
e1eaea46b tty: n_gsm line d... |
2892 |
unsigned int line = tty->index; |
43a9e710c tty: n_gsm: add h... |
2893 |
unsigned int mux = mux_line_to_num(line); |
86176ed90 TTY: n_gsm, use t... |
2894 2895 |
bool alloc = false; int ret; |
e1eaea46b tty: n_gsm line d... |
2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 |
line = line & 0x3F; if (mux >= MAX_MUX) return -ENXIO; /* FIXME: we need to lock gsm_mux for lifetimes of ttys eventually */ if (gsm_mux[mux] == NULL) return -EUNATCH; if (line == 0 || line > 61) /* 62/63 reserved */ return -ECHRNG; gsm = gsm_mux[mux]; if (gsm->dead) return -EL2HLT; |
f3c909b42 Drivers: tty: n_g... |
2909 2910 2911 2912 |
/* If DLCI 0 is not yet fully open return an error. This is ok from a locking perspective as we don't have to worry about this if DLCI0 is lost */ |
dfabf7ffa n_gsm: race betwe... |
2913 2914 2915 |
mutex_lock(&gsm->mutex); if (gsm->dlci[0] && gsm->dlci[0]->state != DLCI_OPEN) { mutex_unlock(&gsm->mutex); |
7e8ac7b23 n_gsm.c: Implemen... |
2916 |
return -EL2NSYNC; |
dfabf7ffa n_gsm: race betwe... |
2917 |
} |
e1eaea46b tty: n_gsm line d... |
2918 |
dlci = gsm->dlci[line]; |
86176ed90 TTY: n_gsm, use t... |
2919 2920 |
if (dlci == NULL) { alloc = true; |
e1eaea46b tty: n_gsm line d... |
2921 |
dlci = gsm_dlci_alloc(gsm, line); |
86176ed90 TTY: n_gsm, use t... |
2922 |
} |
dfabf7ffa n_gsm: race betwe... |
2923 2924 |
if (dlci == NULL) { mutex_unlock(&gsm->mutex); |
e1eaea46b tty: n_gsm line d... |
2925 |
return -ENOMEM; |
dfabf7ffa n_gsm: race betwe... |
2926 |
} |
86176ed90 TTY: n_gsm, use t... |
2927 2928 2929 2930 |
ret = tty_port_install(&dlci->port, driver, tty); if (ret) { if (alloc) dlci_put(dlci); |
dfabf7ffa n_gsm: race betwe... |
2931 |
mutex_unlock(&gsm->mutex); |
86176ed90 TTY: n_gsm, use t... |
2932 2933 |
return ret; } |
dfabf7ffa n_gsm: race betwe... |
2934 2935 2936 |
dlci_get(dlci); dlci_get(gsm->dlci[0]); mux_get(gsm); |
e1eaea46b tty: n_gsm line d... |
2937 |
tty->driver_data = dlci; |
dfabf7ffa n_gsm: race betwe... |
2938 |
mutex_unlock(&gsm->mutex); |
86176ed90 TTY: n_gsm, use t... |
2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 |
return 0; } static int gsmtty_open(struct tty_struct *tty, struct file *filp) { struct gsm_dlci *dlci = tty->driver_data; struct tty_port *port = &dlci->port; port->count++; |
e1eaea46b tty: n_gsm line d... |
2949 2950 2951 2952 2953 |
tty_port_tty_set(port, tty); dlci->modem_rx = 0; /* We could in theory open and close before we wait - eg if we get a DM straight back. This is ok as that will have caused a hangup */ |
d41861ca1 tty: Replace ASYN... |
2954 |
tty_port_set_initialized(port, 1); |
e1eaea46b tty: n_gsm line d... |
2955 2956 2957 2958 2959 2960 2961 2962 2963 |
/* Start sending off SABM messages */ gsm_dlci_begin_open(dlci); /* And wait for virtual carrier */ return tty_port_block_til_ready(port, tty, filp); } static void gsmtty_close(struct tty_struct *tty, struct file *filp) { struct gsm_dlci *dlci = tty->driver_data; |
6ab8fba7f tty: n_gsm: Added... |
2964 |
|
e1eaea46b tty: n_gsm line d... |
2965 2966 |
if (dlci == NULL) return; |
4d9b10906 tty: Prevent dead... |
2967 2968 |
if (dlci->state == DLCI_CLOSED) return; |
bcd5abe28 tty: n_gsm: Add r... |
2969 2970 2971 |
mutex_lock(&dlci->mutex); gsm_destroy_network(dlci); mutex_unlock(&dlci->mutex); |
e1eaea46b tty: n_gsm line d... |
2972 |
if (tty_port_close_start(&dlci->port, tty, filp) == 0) |
dfabf7ffa n_gsm: race betwe... |
2973 |
return; |
e1eaea46b tty: n_gsm line d... |
2974 |
gsm_dlci_begin_close(dlci); |
d41861ca1 tty: Replace ASYN... |
2975 2976 |
if (tty_port_initialized(&dlci->port) && C_HUPCL(tty)) tty_port_lower_dtr_rts(&dlci->port); |
e1eaea46b tty: n_gsm line d... |
2977 2978 |
tty_port_close_end(&dlci->port, tty); tty_port_tty_set(&dlci->port, NULL); |
dfabf7ffa n_gsm: race betwe... |
2979 |
return; |
e1eaea46b tty: n_gsm line d... |
2980 2981 2982 2983 2984 |
} static void gsmtty_hangup(struct tty_struct *tty) { struct gsm_dlci *dlci = tty->driver_data; |
4d9b10906 tty: Prevent dead... |
2985 2986 |
if (dlci->state == DLCI_CLOSED) return; |
e1eaea46b tty: n_gsm line d... |
2987 2988 2989 2990 2991 2992 2993 |
tty_port_hangup(&dlci->port); gsm_dlci_begin_close(dlci); } static int gsmtty_write(struct tty_struct *tty, const unsigned char *buf, int len) { |
4d9b10906 tty: Prevent dead... |
2994 |
int sent; |
e1eaea46b tty: n_gsm line d... |
2995 |
struct gsm_dlci *dlci = tty->driver_data; |
4d9b10906 tty: Prevent dead... |
2996 2997 |
if (dlci->state == DLCI_CLOSED) return -EINVAL; |
e1eaea46b tty: n_gsm line d... |
2998 |
/* Stuff the bytes into the fifo queue */ |
036bca1fc n_gsm: drop unnee... |
2999 |
sent = kfifo_in_locked(&dlci->fifo, buf, len, &dlci->lock); |
e1eaea46b tty: n_gsm line d... |
3000 3001 3002 3003 3004 3005 3006 3007 |
/* Need to kick the channel */ gsm_dlci_data_kick(dlci); return sent; } static int gsmtty_write_room(struct tty_struct *tty) { struct gsm_dlci *dlci = tty->driver_data; |
4d9b10906 tty: Prevent dead... |
3008 3009 |
if (dlci->state == DLCI_CLOSED) return -EINVAL; |
036bca1fc n_gsm: drop unnee... |
3010 |
return TX_SIZE - kfifo_len(&dlci->fifo); |
e1eaea46b tty: n_gsm line d... |
3011 3012 3013 3014 3015 |
} static int gsmtty_chars_in_buffer(struct tty_struct *tty) { struct gsm_dlci *dlci = tty->driver_data; |
4d9b10906 tty: Prevent dead... |
3016 3017 |
if (dlci->state == DLCI_CLOSED) return -EINVAL; |
036bca1fc n_gsm: drop unnee... |
3018 |
return kfifo_len(&dlci->fifo); |
e1eaea46b tty: n_gsm line d... |
3019 3020 3021 3022 3023 |
} static void gsmtty_flush_buffer(struct tty_struct *tty) { struct gsm_dlci *dlci = tty->driver_data; |
4d9b10906 tty: Prevent dead... |
3024 3025 |
if (dlci->state == DLCI_CLOSED) return; |
e1eaea46b tty: n_gsm line d... |
3026 3027 3028 3029 |
/* Caution needed: If we implement reliable transport classes then the data being transmitted can't simply be junked once it has first hit the stack. Until then we can just blow it away */ |
036bca1fc n_gsm: drop unnee... |
3030 |
kfifo_reset(&dlci->fifo); |
e1eaea46b tty: n_gsm line d... |
3031 3032 3033 3034 3035 3036 3037 3038 3039 |
/* Need to unhook this DLCI from the transmit queue logic */ } static void gsmtty_wait_until_sent(struct tty_struct *tty, int timeout) { /* The FIFO handles the queue so the kernel will do the right thing waiting on chars_in_buffer before calling us. No work to do here */ } |
60b33c133 tiocmget: kill of... |
3040 |
static int gsmtty_tiocmget(struct tty_struct *tty) |
e1eaea46b tty: n_gsm line d... |
3041 3042 |
{ struct gsm_dlci *dlci = tty->driver_data; |
4d9b10906 tty: Prevent dead... |
3043 3044 |
if (dlci->state == DLCI_CLOSED) return -EINVAL; |
e1eaea46b tty: n_gsm line d... |
3045 3046 |
return dlci->modem_rx; } |
20b9d1771 tiocmset: kill th... |
3047 |
static int gsmtty_tiocmset(struct tty_struct *tty, |
e1eaea46b tty: n_gsm line d... |
3048 3049 3050 3051 |
unsigned int set, unsigned int clear) { struct gsm_dlci *dlci = tty->driver_data; unsigned int modem_tx = dlci->modem_tx; |
4d9b10906 tty: Prevent dead... |
3052 3053 |
if (dlci->state == DLCI_CLOSED) return -EINVAL; |
cf16807b6 tty/n_gsm: fix bu... |
3054 |
modem_tx &= ~clear; |
e1eaea46b tty: n_gsm line d... |
3055 3056 3057 3058 3059 3060 3061 3062 |
modem_tx |= set; if (modem_tx != dlci->modem_tx) { dlci->modem_tx = modem_tx; return gsmtty_modem_update(dlci, 0); } return 0; } |
6caa76b77 tty: now phase ou... |
3063 |
static int gsmtty_ioctl(struct tty_struct *tty, |
e1eaea46b tty: n_gsm line d... |
3064 3065 |
unsigned int cmd, unsigned long arg) { |
bcd5abe28 tty: n_gsm: Add r... |
3066 3067 3068 |
struct gsm_dlci *dlci = tty->driver_data; struct gsm_netconfig nc; int index; |
4d9b10906 tty: Prevent dead... |
3069 3070 |
if (dlci->state == DLCI_CLOSED) return -EINVAL; |
bcd5abe28 tty: n_gsm: Add r... |
3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 |
switch (cmd) { case GSMIOC_ENABLE_NET: if (copy_from_user(&nc, (void __user *)arg, sizeof(nc))) return -EFAULT; nc.if_name[IFNAMSIZ-1] = '\0'; /* return net interface index or error code */ mutex_lock(&dlci->mutex); index = gsm_create_network(dlci, &nc); mutex_unlock(&dlci->mutex); if (copy_to_user((void __user *)arg, &nc, sizeof(nc))) return -EFAULT; return index; case GSMIOC_DISABLE_NET: if (!capable(CAP_NET_ADMIN)) return -EPERM; mutex_lock(&dlci->mutex); gsm_destroy_network(dlci); mutex_unlock(&dlci->mutex); return 0; default: return -ENOIOCTLCMD; } |
e1eaea46b tty: n_gsm line d... |
3093 3094 3095 3096 |
} static void gsmtty_set_termios(struct tty_struct *tty, struct ktermios *old) { |
4d9b10906 tty: Prevent dead... |
3097 3098 3099 |
struct gsm_dlci *dlci = tty->driver_data; if (dlci->state == DLCI_CLOSED) return; |
e1eaea46b tty: n_gsm line d... |
3100 3101 3102 3103 3104 |
/* For the moment its fixed. In actual fact the speed information for the virtual channel can be propogated in both directions by the RPN control message. This however rapidly gets nasty as we then have to remap modem signals each way according to whether our virtual cable is null modem etc .. */ |
adc8d746c tty: move the ter... |
3105 |
tty_termios_copy_hw(&tty->termios, old); |
e1eaea46b tty: n_gsm line d... |
3106 3107 3108 3109 3110 |
} static void gsmtty_throttle(struct tty_struct *tty) { struct gsm_dlci *dlci = tty->driver_data; |
4d9b10906 tty: Prevent dead... |
3111 3112 |
if (dlci->state == DLCI_CLOSED) return; |
9db276f8f tty: Use termios ... |
3113 |
if (C_CRTSCTS(tty)) |
e1eaea46b tty: n_gsm line d... |
3114 |
dlci->modem_tx &= ~TIOCM_DTR; |
e9360b9a0 n_gsm: switch thr... |
3115 |
dlci->throttled = true; |
e1eaea46b tty: n_gsm line d... |
3116 3117 3118 3119 3120 3121 3122 |
/* Send an MSC with DTR cleared */ gsmtty_modem_update(dlci, 0); } static void gsmtty_unthrottle(struct tty_struct *tty) { struct gsm_dlci *dlci = tty->driver_data; |
4d9b10906 tty: Prevent dead... |
3123 3124 |
if (dlci->state == DLCI_CLOSED) return; |
9db276f8f tty: Use termios ... |
3125 |
if (C_CRTSCTS(tty)) |
e1eaea46b tty: n_gsm line d... |
3126 |
dlci->modem_tx |= TIOCM_DTR; |
e9360b9a0 n_gsm: switch thr... |
3127 |
dlci->throttled = false; |
e1eaea46b tty: n_gsm line d... |
3128 3129 3130 3131 3132 3133 3134 3135 |
/* Send an MSC with DTR set */ gsmtty_modem_update(dlci, 0); } static int gsmtty_break_ctl(struct tty_struct *tty, int state) { struct gsm_dlci *dlci = tty->driver_data; int encode = 0; /* Off */ |
4d9b10906 tty: Prevent dead... |
3136 3137 |
if (dlci->state == DLCI_CLOSED) return -EINVAL; |
e1eaea46b tty: n_gsm line d... |
3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 |
if (state == -1) /* "On indefinitely" - we can't encode this properly */ encode = 0x0F; else if (state > 0) { encode = state / 200; /* mS to encoding */ if (encode > 0x0F) encode = 0x0F; /* Best effort */ } return gsmtty_modem_update(dlci, encode); } |
8f9cfeed3 tty/n_gsm.c: fix ... |
3149 |
static void gsmtty_cleanup(struct tty_struct *tty) |
dfabf7ffa n_gsm: race betwe... |
3150 3151 3152 3153 3154 3155 3156 |
{ struct gsm_dlci *dlci = tty->driver_data; struct gsm_mux *gsm = dlci->gsm; dlci_put(dlci); dlci_put(gsm->dlci[0]); mux_put(gsm); |
dfabf7ffa n_gsm: race betwe... |
3157 |
} |
e1eaea46b tty: n_gsm line d... |
3158 3159 3160 |
/* Virtual ttys for the demux */ static const struct tty_operations gsmtty_ops = { |
86176ed90 TTY: n_gsm, use t... |
3161 |
.install = gsmtty_install, |
e1eaea46b tty: n_gsm line d... |
3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 |
.open = gsmtty_open, .close = gsmtty_close, .write = gsmtty_write, .write_room = gsmtty_write_room, .chars_in_buffer = gsmtty_chars_in_buffer, .flush_buffer = gsmtty_flush_buffer, .ioctl = gsmtty_ioctl, .throttle = gsmtty_throttle, .unthrottle = gsmtty_unthrottle, .set_termios = gsmtty_set_termios, .hangup = gsmtty_hangup, .wait_until_sent = gsmtty_wait_until_sent, .tiocmget = gsmtty_tiocmget, .tiocmset = gsmtty_tiocmset, .break_ctl = gsmtty_break_ctl, |
8f9cfeed3 tty/n_gsm.c: fix ... |
3177 |
.cleanup = gsmtty_cleanup, |
e1eaea46b tty: n_gsm line d... |
3178 3179 3180 3181 3182 3183 3184 3185 3186 |
}; static int __init gsm_init(void) { /* Fill in our line protocol discipline, and register it */ int status = tty_register_ldisc(N_GSM0710, &tty_ldisc_packet); if (status != 0) { |
5f9a31d63 n_gsm: clean up p... |
3187 3188 3189 |
pr_err("n_gsm: can't register line discipline (err = %d) ", status); |
e1eaea46b tty: n_gsm line d... |
3190 3191 3192 3193 3194 3195 |
return status; } gsm_tty_driver = alloc_tty_driver(256); if (!gsm_tty_driver) { tty_unregister_ldisc(N_GSM0710); |
5f9a31d63 n_gsm: clean up p... |
3196 3197 |
pr_err("gsm_init: tty allocation failed. "); |
e1eaea46b tty: n_gsm line d... |
3198 3199 |
return -EINVAL; } |
e1eaea46b tty: n_gsm line d... |
3200 3201 3202 3203 3204 3205 3206 |
gsm_tty_driver->driver_name = "gsmtty"; gsm_tty_driver->name = "gsmtty"; gsm_tty_driver->major = 0; /* Dynamic */ gsm_tty_driver->minor_start = 0; gsm_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; gsm_tty_driver->subtype = SERIAL_TYPE_NORMAL; gsm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV |
5f9a31d63 n_gsm: clean up p... |
3207 |
| TTY_DRIVER_HARDWARE_BREAK; |
e1eaea46b tty: n_gsm line d... |
3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 |
gsm_tty_driver->init_termios = tty_std_termios; /* Fixme */ gsm_tty_driver->init_termios.c_lflag &= ~ECHO; tty_set_operations(gsm_tty_driver, &gsmtty_ops); spin_lock_init(&gsm_mux_lock); if (tty_register_driver(gsm_tty_driver)) { put_tty_driver(gsm_tty_driver); tty_unregister_ldisc(N_GSM0710); |
5f9a31d63 n_gsm: clean up p... |
3218 3219 |
pr_err("gsm_init: tty registration failed. "); |
e1eaea46b tty: n_gsm line d... |
3220 3221 |
return -EBUSY; } |
5f9a31d63 n_gsm: clean up p... |
3222 3223 3224 |
pr_debug("gsm_init: loaded as %d,%d. ", gsm_tty_driver->major, gsm_tty_driver->minor_start); |
e1eaea46b tty: n_gsm line d... |
3225 3226 3227 3228 3229 3230 3231 |
return 0; } static void __exit gsm_exit(void) { int status = tty_unregister_ldisc(N_GSM0710); if (status != 0) |
5f9a31d63 n_gsm: clean up p... |
3232 3233 3234 |
pr_err("n_gsm: can't unregister line discipline (err = %d) ", status); |
e1eaea46b tty: n_gsm line d... |
3235 3236 |
tty_unregister_driver(gsm_tty_driver); put_tty_driver(gsm_tty_driver); |
e1eaea46b tty: n_gsm line d... |
3237 3238 3239 3240 3241 3242 3243 3244 |
} module_init(gsm_init); module_exit(gsm_exit); MODULE_LICENSE("GPL"); MODULE_ALIAS_LDISC(N_GSM0710); |