ardtweeno 0.0.2 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +179 -1
  3. data/COPYING +4 -3
  4. data/Gemfile +29 -0
  5. data/Gemfile.lock +76 -0
  6. data/INSTALL +12 -0
  7. data/Procfile +1 -0
  8. data/README.md +26 -2
  9. data/Rakefile +14 -7
  10. data/lib/ardtweeno/api.rb +542 -0
  11. data/lib/ardtweeno/configreader.rb +65 -0
  12. data/lib/ardtweeno/db.rb +51 -0
  13. data/lib/ardtweeno/dispatcher.rb +538 -0
  14. data/lib/ardtweeno/exceptions.rb +33 -0
  15. data/lib/ardtweeno/node.rb +117 -0
  16. data/lib/ardtweeno/nodemanager.rb +300 -0
  17. data/lib/ardtweeno/packet.rb +98 -0
  18. data/lib/ardtweeno/restapi.rb +266 -0
  19. data/lib/ardtweeno/serialparser.rb +221 -0
  20. data/lib/ardtweeno.rb +120 -1
  21. data/public/glossy_green_button.svg +123 -0
  22. data/public/glossy_red_button.svg +75 -0
  23. data/public/main.css +129 -0
  24. data/public/raspberrypi.jpg +0 -0
  25. data/resources/conf.yaml +41 -0
  26. data/resources/nodelist.yaml +26 -0
  27. data/resources/serialparser.js +84 -0
  28. data/test/api_test.rb +255 -0
  29. data/test/dispatcher_test.rb +115 -0
  30. data/test/node_test.rb +105 -0
  31. data/test/nodemanager_test.rb +167 -0
  32. data/test/packet_test.rb +75 -0
  33. data/test/parser_test.rb +147 -0
  34. data/test/post_watch +11 -0
  35. data/test/rest_api_test.rb +248 -0
  36. data/test/run_mock +17 -0
  37. data/test/run_packet_push +14 -0
  38. data/test/serialport_mock.rb +43 -0
  39. data/test/test_helper.rb +15 -0
  40. data/test/tty0tty-1.1/AUTHORS +1 -0
  41. data/test/tty0tty-1.1/COPYING +340 -0
  42. data/test/tty0tty-1.1/INSTALL +18 -0
  43. data/test/tty0tty-1.1/README +52 -0
  44. data/test/tty0tty-1.1/THANKS +4 -0
  45. data/test/tty0tty-1.1/TODO +3 -0
  46. data/test/tty0tty-1.1/VERSION +4 -0
  47. data/test/tty0tty-1.1/module/Makefile +41 -0
  48. data/{bin/ardtweeno → test/tty0tty-1.1/module/Module.symvers} +0 -0
  49. data/test/tty0tty-1.1/module/modules.order +1 -0
  50. data/test/tty0tty-1.1/module/tty0tty.c +678 -0
  51. data/test/tty0tty-1.1/module/tty0tty.ko +0 -0
  52. data/test/tty0tty-1.1/module/tty0tty.mod.c +51 -0
  53. data/test/tty0tty-1.1/module/tty0tty.mod.o +0 -0
  54. data/test/tty0tty-1.1/module/tty0tty.o +0 -0
  55. data/test/tty0tty-1.1/pts/Makefile +10 -0
  56. data/test/tty0tty-1.1/pts/tty0tty +0 -0
  57. data/test/tty0tty-1.1/pts/tty0tty.c +222 -0
  58. data/views/createpost.erb +45 -0
  59. data/views/home.erb +59 -0
  60. metadata +89 -37
  61. data/README +0 -1
  62. data/test/Rakefile +0 -6
  63. data/test/features/ardtweeno.feature +0 -14
  64. data/test/features/step_definitions/ardtweeno_steps.rb +0 -24
@@ -0,0 +1,678 @@
1
+ /* ########################################################################
2
+
3
+ tty0tty - linux null modem emulator (module) for kernel > 3.0
4
+
5
+ ########################################################################
6
+
7
+ Copyright (c) : 2012 Luis Claudio Gambôa Lopes
8
+
9
+ Based in Tiny TTY driver - Copyright (C) 2002-2004 Greg Kroah-Hartman (greg@kroah.com)
10
+
11
+ This program is free software; you can redistribute it and/or modify
12
+ it under the terms of the GNU General Public License as published by
13
+ the Free Software Foundation; either version 2, or (at your option)
14
+ any later version.
15
+
16
+ This program is distributed in the hope that it will be useful,
17
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ GNU General Public License for more details.
20
+
21
+ You should have received a copy of the GNU General Public License
22
+ along with this program; if not, write to the Free Software
23
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24
+
25
+ For e-mail suggestions : lcgamboa@yahoo.com
26
+ ######################################################################## */
27
+
28
+
29
+
30
+ #include <linux/kernel.h>
31
+ #include <linux/errno.h>
32
+ #include <linux/init.h>
33
+ #include <linux/module.h>
34
+ #include <linux/slab.h>
35
+ #include <linux/wait.h>
36
+ #include <linux/tty.h>
37
+ #include <linux/tty_driver.h>
38
+ #include <linux/tty_flip.h>
39
+ #include <linux/serial.h>
40
+ #include <linux/sched.h>
41
+ #include <asm/uaccess.h>
42
+
43
+
44
+ #define DRIVER_VERSION "v1.1"
45
+ #define DRIVER_AUTHOR "Luis Claudio Gamboa Lopes <lcgamboa@yahoo.com>"
46
+ #define DRIVER_DESC "tty0tty null modem driver"
47
+
48
+ /* Module information */
49
+ MODULE_AUTHOR( DRIVER_AUTHOR );
50
+ MODULE_DESCRIPTION( DRIVER_DESC );
51
+ MODULE_LICENSE("GPL");
52
+
53
+
54
+ #define TINY_TTY_MAJOR 240 /* experimental range */
55
+ #define TINY_TTY_MINORS 8 /* device number, always even*/
56
+
57
+ /* fake UART values */
58
+ //out
59
+ #define MCR_DTR 0x01
60
+ #define MCR_RTS 0x02
61
+ #define MCR_LOOP 0x04
62
+ //in
63
+ #define MSR_CTS 0x10
64
+ #define MSR_CD 0x20
65
+ #define MSR_DSR 0x40
66
+ #define MSR_RI 0x80
67
+
68
+ struct tty0tty_serial {
69
+ struct tty_struct *tty; /* pointer to the tty for this device */
70
+ int open_count; /* number of times this port has been opened */
71
+ struct semaphore sem; /* locks this structure */
72
+
73
+ /* for tiocmget and tiocmset functions */
74
+ int msr; /* MSR shadow */
75
+ int mcr; /* MCR shadow */
76
+
77
+ /* for ioctl fun */
78
+ struct serial_struct serial;
79
+ wait_queue_head_t wait;
80
+ struct async_icount icount;
81
+ };
82
+
83
+ static struct tty0tty_serial *tty0tty_table[TINY_TTY_MINORS]; /* initially all NULL */
84
+
85
+
86
+ static int tty0tty_open(struct tty_struct *tty, struct file *file)
87
+ {
88
+ struct tty0tty_serial *tty0tty;
89
+ int index;
90
+ int msr=0;
91
+ int mcr=0;
92
+
93
+ #ifdef SCULL_DEBUG
94
+ printk(KERN_DEBUG "%s - \n", __FUNCTION__);
95
+ #endif
96
+ /* initialize the pointer in case something fails */
97
+ tty->driver_data = NULL;
98
+
99
+ /* get the serial object associated with this tty pointer */
100
+ index = tty->index;
101
+ tty0tty = tty0tty_table[index];
102
+ if (tty0tty == NULL) {
103
+ /* first time accessing this device, let's create it */
104
+ tty0tty = kmalloc(sizeof(*tty0tty), GFP_KERNEL);
105
+ if (!tty0tty)
106
+ return -ENOMEM;
107
+
108
+ sema_init(&tty0tty->sem,1);
109
+ tty0tty->open_count = 0;
110
+
111
+ tty0tty_table[index] = tty0tty;
112
+
113
+ init_waitqueue_head(&tty0tty->wait);
114
+
115
+ }
116
+
117
+ if( (index % 2) == 0)
118
+ {
119
+ if(tty0tty_table[index+1] != NULL)
120
+ if (tty0tty_table[index+1]->open_count > 0)
121
+ mcr=tty0tty_table[index+1]->mcr;
122
+ }
123
+ else
124
+ {
125
+ if(tty0tty_table[index-1] != NULL)
126
+ if (tty0tty_table[index-1]->open_count > 0)
127
+ mcr=tty0tty_table[index-1]->mcr;
128
+ }
129
+
130
+ //null modem connection
131
+
132
+ if( (mcr & MCR_RTS) == MCR_RTS )
133
+ {
134
+ msr |= MSR_CTS;
135
+ }
136
+
137
+ if( (mcr & MCR_DTR) == MCR_DTR )
138
+ {
139
+ msr |= MSR_DSR;
140
+ msr |= MSR_CD;
141
+ }
142
+
143
+ tty0tty->msr = msr;
144
+ tty0tty->mcr = 0;
145
+
146
+ down(&tty0tty->sem);
147
+
148
+ /* save our structure within the tty structure */
149
+ tty->driver_data = tty0tty;
150
+ tty0tty->tty = tty;
151
+
152
+ ++tty0tty->open_count;
153
+
154
+ up(&tty0tty->sem);
155
+ return 0;
156
+ }
157
+
158
+ static void do_close(struct tty0tty_serial *tty0tty)
159
+ {
160
+ unsigned int msr=0;
161
+
162
+ #ifdef SCULL_DEBUG
163
+ printk(KERN_DEBUG "%s - \n", __FUNCTION__);
164
+ #endif
165
+ if( (tty0tty->tty->index % 2) == 0)
166
+ {
167
+ if(tty0tty_table[tty0tty->tty->index+1] != NULL)
168
+ if (tty0tty_table[tty0tty->tty->index+1]->open_count > 0)
169
+ tty0tty_table[tty0tty->tty->index+1]->msr=msr;
170
+ }
171
+ else
172
+ {
173
+ if(tty0tty_table[tty0tty->tty->index-1] != NULL)
174
+ if (tty0tty_table[tty0tty->tty->index-1]->open_count > 0)
175
+ tty0tty_table[tty0tty->tty->index-1]->msr=msr;
176
+ }
177
+
178
+ down(&tty0tty->sem);
179
+ if (!tty0tty->open_count) {
180
+ /* port was never opened */
181
+ goto exit;
182
+ }
183
+
184
+ --tty0tty->open_count;
185
+ exit:
186
+ up(&tty0tty->sem);
187
+
188
+
189
+ return;
190
+ }
191
+
192
+ static void tty0tty_close(struct tty_struct *tty, struct file *file)
193
+ {
194
+ struct tty0tty_serial *tty0tty = tty->driver_data;
195
+
196
+ #ifdef SCULL_DEBUG
197
+ printk(KERN_DEBUG "%s - \n", __FUNCTION__);
198
+ #endif
199
+ if (tty0tty)
200
+ do_close(tty0tty);
201
+ }
202
+
203
+ static int tty0tty_write(struct tty_struct *tty, const unsigned char *buffer, int count)
204
+ {
205
+ struct tty0tty_serial *tty0tty = tty->driver_data;
206
+ int retval = -EINVAL;
207
+ struct tty_struct *ttyx = NULL;
208
+
209
+ if (!tty0tty)
210
+ return -ENODEV;
211
+
212
+ down(&tty0tty->sem);
213
+
214
+ if (!tty0tty->open_count)
215
+ /* port was not opened */
216
+ goto exit;
217
+
218
+ if( (tty0tty->tty->index % 2) == 0)
219
+ {
220
+ if(tty0tty_table[tty0tty->tty->index+1] != NULL)
221
+ if (tty0tty_table[tty0tty->tty->index+1]->open_count > 0)
222
+ ttyx=tty0tty_table[tty0tty->tty->index+1]->tty;
223
+ }
224
+ else
225
+ {
226
+ if(tty0tty_table[tty0tty->tty->index-1] != NULL)
227
+ if (tty0tty_table[tty0tty->tty->index-1]->open_count > 0)
228
+ ttyx=tty0tty_table[tty0tty->tty->index-1]->tty;
229
+ }
230
+
231
+ // tty->low_latency=1;
232
+
233
+ if(ttyx != NULL)
234
+ {
235
+ tty_insert_flip_string(ttyx, buffer, count);
236
+ tty_flip_buffer_push(ttyx);
237
+ retval=count;
238
+ }
239
+
240
+ exit:
241
+ up(&tty0tty->sem);
242
+ return retval;
243
+ }
244
+
245
+ static int tty0tty_write_room(struct tty_struct *tty)
246
+ {
247
+ struct tty0tty_serial *tty0tty = tty->driver_data;
248
+ int room = -EINVAL;
249
+
250
+ if (!tty0tty)
251
+ return -ENODEV;
252
+
253
+ down(&tty0tty->sem);
254
+
255
+ if (!tty0tty->open_count) {
256
+ /* port was not opened */
257
+ goto exit;
258
+ }
259
+
260
+ /* calculate how much room is left in the device */
261
+ room = 255;
262
+
263
+ exit:
264
+ up(&tty0tty->sem);
265
+ return room;
266
+ }
267
+
268
+ #define RELEVANT_IFLAG(iflag) ((iflag) & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
269
+
270
+ static void tty0tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
271
+ {
272
+ unsigned int cflag;
273
+
274
+ #ifdef SCULL_DEBUG
275
+ printk(KERN_DEBUG "%s - \n", __FUNCTION__);
276
+ #endif
277
+ cflag = tty->termios->c_cflag;
278
+
279
+ /* check that they really want us to change something */
280
+ if (old_termios) {
281
+ if ((cflag == old_termios->c_cflag) &&
282
+ (RELEVANT_IFLAG(tty->termios->c_iflag) ==
283
+ RELEVANT_IFLAG(old_termios->c_iflag))) {
284
+ #ifdef SCULL_DEBUG
285
+ printk(KERN_DEBUG " - nothing to change...\n");
286
+ #endif
287
+ return;
288
+ }
289
+ }
290
+
291
+ #ifdef SCULL_DEBUG
292
+ /* get the byte size */
293
+ switch (cflag & CSIZE) {
294
+ case CS5:
295
+ printk(KERN_DEBUG " - data bits = 5\n");
296
+ break;
297
+ case CS6:
298
+ printk(KERN_DEBUG " - data bits = 6\n");
299
+ break;
300
+ case CS7:
301
+ printk(KERN_DEBUG " - data bits = 7\n");
302
+ break;
303
+ default:
304
+ case CS8:
305
+ printk(KERN_DEBUG " - data bits = 8\n");
306
+ break;
307
+ }
308
+
309
+ /* determine the parity */
310
+ if (cflag & PARENB)
311
+ if (cflag & PARODD)
312
+ printk(KERN_DEBUG " - parity = odd\n");
313
+ else
314
+ printk(KERN_DEBUG " - parity = even\n");
315
+ else
316
+ printk(KERN_DEBUG " - parity = none\n");
317
+
318
+ /* figure out the stop bits requested */
319
+ if (cflag & CSTOPB)
320
+ printk(KERN_DEBUG " - stop bits = 2\n");
321
+ else
322
+ printk(KERN_DEBUG " - stop bits = 1\n");
323
+
324
+ /* figure out the hardware flow control settings */
325
+ if (cflag & CRTSCTS)
326
+ printk(KERN_DEBUG " - RTS/CTS is enabled\n");
327
+ else
328
+ printk(KERN_DEBUG " - RTS/CTS is disabled\n");
329
+
330
+ /* determine software flow control */
331
+ /* if we are implementing XON/XOFF, set the start and
332
+ * stop character in the device */
333
+ if (I_IXOFF(tty) || I_IXON(tty)) {
334
+ unsigned char stop_char = STOP_CHAR(tty);
335
+ unsigned char start_char = START_CHAR(tty);
336
+
337
+ /* if we are implementing INBOUND XON/XOFF */
338
+ if (I_IXOFF(tty))
339
+ printk(KERN_DEBUG " - INBOUND XON/XOFF is enabled, "
340
+ "XON = %2x, XOFF = %2x\n", start_char, stop_char);
341
+ else
342
+ printk(KERN_DEBUG" - INBOUND XON/XOFF is disabled\n");
343
+
344
+ /* if we are implementing OUTBOUND XON/XOFF */
345
+ if (I_IXON(tty))
346
+ printk(KERN_DEBUG" - OUTBOUND XON/XOFF is enabled, "
347
+ "XON = %2x, XOFF = %2x\n", start_char, stop_char);
348
+ else
349
+ printk(KERN_DEBUG" - OUTBOUND XON/XOFF is disabled\n");
350
+ }
351
+
352
+ /* get the baud rate wanted */
353
+ printk(KERN_DEBUG " - baud rate = %d\n", tty_get_baud_rate(tty));
354
+ #endif
355
+ }
356
+
357
+
358
+ //static int tty0tty_tiocmget(struct tty_struct *tty, struct file *file)
359
+ static int tty0tty_tiocmget(struct tty_struct *tty)
360
+ {
361
+ struct tty0tty_serial *tty0tty = tty->driver_data;
362
+
363
+ unsigned int result = 0;
364
+ unsigned int msr = tty0tty->msr;
365
+ unsigned int mcr = tty0tty->mcr;
366
+
367
+ #ifdef SCULL_DEBUG
368
+ printk(KERN_DEBUG "%s - \n", __FUNCTION__);
369
+ #endif
370
+
371
+
372
+ result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0) | /* DTR is set */
373
+ ((mcr & MCR_RTS) ? TIOCM_RTS : 0) | /* RTS is set */
374
+ ((mcr & MCR_LOOP) ? TIOCM_LOOP : 0) | /* LOOP is set */
375
+ ((msr & MSR_CTS) ? TIOCM_CTS : 0) | /* CTS is set */
376
+ ((msr & MSR_CD) ? TIOCM_CAR : 0) | /* Carrier detect is set*/
377
+ ((msr & MSR_RI) ? TIOCM_RI : 0) | /* Ring Indicator is set */
378
+ ((msr & MSR_DSR) ? TIOCM_DSR : 0); /* DSR is set */
379
+
380
+ return result;
381
+ }
382
+
383
+
384
+
385
+
386
+
387
+ //static int tty0tty_tiocmset(struct tty_struct *tty, struct file *file,
388
+ static int tty0tty_tiocmset(struct tty_struct *tty,
389
+ unsigned int set, unsigned int clear)
390
+ {
391
+ struct tty0tty_serial *tty0tty = tty->driver_data;
392
+ unsigned int mcr = tty0tty->mcr;
393
+ unsigned int msr=0;
394
+
395
+ #ifdef SCULL_DEBUG
396
+ printk(KERN_DEBUG "%s - \n", __FUNCTION__);
397
+ #endif
398
+
399
+ if( (tty0tty->tty->index % 2) == 0)
400
+ {
401
+ if(tty0tty_table[tty0tty->tty->index+1] != NULL)
402
+ if (tty0tty_table[tty0tty->tty->index+1]->open_count > 0)
403
+ msr=tty0tty_table[tty0tty->tty->index+1]->msr;
404
+ }
405
+ else
406
+ {
407
+ if(tty0tty_table[tty0tty->tty->index-1] != NULL)
408
+ if (tty0tty_table[tty0tty->tty->index-1]->open_count > 0)
409
+ msr=tty0tty_table[tty0tty->tty->index-1]->msr;
410
+ }
411
+
412
+ //null modem connection
413
+
414
+ if (set & TIOCM_RTS)
415
+ {
416
+ mcr |= MCR_RTS;
417
+ msr |= MSR_CTS;
418
+ }
419
+
420
+ if (set & TIOCM_DTR)
421
+ {
422
+ mcr |= MCR_DTR;
423
+ msr |= MSR_DSR;
424
+ msr |= MSR_CD;
425
+ }
426
+
427
+ if (clear & TIOCM_RTS)
428
+ {
429
+ mcr &= ~MCR_RTS;
430
+ msr &= ~MSR_CTS;
431
+ }
432
+
433
+ if (clear & TIOCM_DTR)
434
+ {
435
+ mcr &= ~MCR_DTR;
436
+ msr &= ~MSR_DSR;
437
+ msr &= ~MSR_CD;
438
+ }
439
+
440
+
441
+ /* set the new MCR value in the device */
442
+ tty0tty->mcr = mcr;
443
+
444
+ if( (tty0tty->tty->index % 2) == 0)
445
+ {
446
+ if(tty0tty_table[tty0tty->tty->index+1] != NULL)
447
+ if (tty0tty_table[tty0tty->tty->index+1]->open_count > 0)
448
+ tty0tty_table[tty0tty->tty->index+1]->msr=msr;
449
+ }
450
+ else
451
+ {
452
+ if(tty0tty_table[tty0tty->tty->index-1] != NULL)
453
+ if (tty0tty_table[tty0tty->tty->index-1]->open_count > 0)
454
+ tty0tty_table[tty0tty->tty->index-1]->msr=msr;
455
+ }
456
+ return 0;
457
+ }
458
+
459
+
460
+ static int tty0tty_ioctl_tiocgserial(struct tty_struct *tty,
461
+ unsigned int cmd, unsigned long arg)
462
+ {
463
+ struct tty0tty_serial *tty0tty = tty->driver_data;
464
+
465
+ #ifdef SCULL_DEBUG
466
+ printk(KERN_DEBUG "%s - \n", __FUNCTION__);
467
+ #endif
468
+ if (cmd == TIOCGSERIAL) {
469
+ struct serial_struct tmp;
470
+
471
+ if (!arg)
472
+ return -EFAULT;
473
+
474
+ memset(&tmp, 0, sizeof(tmp));
475
+
476
+ tmp.type = tty0tty->serial.type;
477
+ tmp.line = tty0tty->serial.line;
478
+ tmp.port = tty0tty->serial.port;
479
+ tmp.irq = tty0tty->serial.irq;
480
+ tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
481
+ tmp.xmit_fifo_size = tty0tty->serial.xmit_fifo_size;
482
+ tmp.baud_base = tty0tty->serial.baud_base;
483
+ tmp.close_delay = 5*HZ;
484
+ tmp.closing_wait = 30*HZ;
485
+ tmp.custom_divisor = tty0tty->serial.custom_divisor;
486
+ tmp.hub6 = tty0tty->serial.hub6;
487
+ tmp.io_type = tty0tty->serial.io_type;
488
+
489
+ if (copy_to_user((void __user *)arg, &tmp, sizeof(struct serial_struct)))
490
+ return -EFAULT;
491
+ return 0;
492
+ }
493
+ return -ENOIOCTLCMD;
494
+ }
495
+
496
+ static int tty0tty_ioctl_tiocmiwait(struct tty_struct *tty,
497
+ unsigned int cmd, unsigned long arg)
498
+ {
499
+ struct tty0tty_serial *tty0tty = tty->driver_data;
500
+
501
+ #ifdef SCULL_DEBUG
502
+ printk(KERN_DEBUG "%s -\n", __FUNCTION__);
503
+ #endif
504
+ if (cmd == TIOCMIWAIT) {
505
+ DECLARE_WAITQUEUE(wait, current);
506
+ struct async_icount cnow;
507
+ struct async_icount cprev;
508
+
509
+ cprev = tty0tty->icount;
510
+ while (1) {
511
+ add_wait_queue(&tty0tty->wait, &wait);
512
+ set_current_state(TASK_INTERRUPTIBLE);
513
+ schedule();
514
+ remove_wait_queue(&tty0tty->wait, &wait);
515
+
516
+ /* see if a signal woke us up */
517
+ if (signal_pending(current))
518
+ return -ERESTARTSYS;
519
+
520
+ cnow = tty0tty->icount;
521
+ if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
522
+ cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
523
+ return -EIO; /* no change => error */
524
+ if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
525
+ ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
526
+ ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
527
+ ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
528
+ return 0;
529
+ }
530
+ cprev = cnow;
531
+ }
532
+
533
+ }
534
+ return -ENOIOCTLCMD;
535
+ }
536
+
537
+ static int tty0tty_ioctl_tiocgicount(struct tty_struct *tty,
538
+ unsigned int cmd, unsigned long arg)
539
+ {
540
+ struct tty0tty_serial *tty0tty = tty->driver_data;
541
+
542
+ #ifdef SCULL_DEBUG
543
+ printk(KERN_DEBUG "%s - \n", __FUNCTION__);
544
+ #endif
545
+ if (cmd == TIOCGICOUNT) {
546
+ struct async_icount cnow = tty0tty->icount;
547
+ struct serial_icounter_struct icount;
548
+
549
+ icount.cts = cnow.cts;
550
+ icount.dsr = cnow.dsr;
551
+ icount.rng = cnow.rng;
552
+ icount.dcd = cnow.dcd;
553
+ icount.rx = cnow.rx;
554
+ icount.tx = cnow.tx;
555
+ icount.frame = cnow.frame;
556
+ icount.overrun = cnow.overrun;
557
+ icount.parity = cnow.parity;
558
+ icount.brk = cnow.brk;
559
+ icount.buf_overrun = cnow.buf_overrun;
560
+
561
+ if (copy_to_user((void __user *)arg, &icount, sizeof(icount)))
562
+ return -EFAULT;
563
+ return 0;
564
+ }
565
+ return -ENOIOCTLCMD;
566
+ }
567
+
568
+ static int tty0tty_ioctl(struct tty_struct *tty,
569
+ unsigned int cmd, unsigned long arg)
570
+ {
571
+ #ifdef SCULL_DEBUG
572
+ printk(KERN_DEBUG "%s - %04X \n", __FUNCTION__,cmd);
573
+ #endif
574
+ switch (cmd) {
575
+ case TIOCGSERIAL:
576
+ return tty0tty_ioctl_tiocgserial(tty, cmd, arg);
577
+ case TIOCMIWAIT:
578
+ return tty0tty_ioctl_tiocmiwait(tty, cmd, arg);
579
+ case TIOCGICOUNT:
580
+ return tty0tty_ioctl_tiocgicount(tty, cmd, arg);
581
+
582
+ case TCGETS:
583
+ return tty0tty_tiocmget(tty);
584
+ case TCSETS:
585
+ return tty0tty_tiocmset(tty, cmd, arg);
586
+ }
587
+
588
+ return -ENOIOCTLCMD;
589
+ }
590
+
591
+ static struct tty_operations serial_ops = {
592
+ .open = tty0tty_open,
593
+ .close = tty0tty_close,
594
+ .write = tty0tty_write,
595
+ .write_room = tty0tty_write_room,
596
+ .set_termios = tty0tty_set_termios,
597
+ .tiocmget = tty0tty_tiocmget,
598
+ .tiocmset = tty0tty_tiocmset,
599
+ .ioctl = tty0tty_ioctl,
600
+ };
601
+
602
+ static struct tty_driver *tty0tty_tty_driver;
603
+
604
+ static int __init tty0tty_init(void)
605
+ {
606
+
607
+ int retval;
608
+ #ifdef SCULL_DEBUG
609
+ printk(KERN_DEBUG "%s - \n", __FUNCTION__);
610
+ #endif
611
+ /* allocate the tty driver */
612
+ tty0tty_tty_driver = alloc_tty_driver(TINY_TTY_MINORS);
613
+ if (!tty0tty_tty_driver)
614
+ return -ENOMEM;
615
+
616
+ /* initialize the tty driver */
617
+ tty0tty_tty_driver->owner = THIS_MODULE;
618
+ tty0tty_tty_driver->driver_name = "tty0tty";
619
+ tty0tty_tty_driver->name = "tnt";
620
+ /* no more devfs subsystem */
621
+ tty0tty_tty_driver->major = TINY_TTY_MAJOR;
622
+ tty0tty_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
623
+ tty0tty_tty_driver->subtype = SERIAL_TYPE_NORMAL;
624
+ tty0tty_tty_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW ;
625
+ /* no more devfs subsystem */
626
+ tty0tty_tty_driver->init_termios = tty_std_termios;
627
+ tty0tty_tty_driver->init_termios.c_iflag = 0;
628
+ tty0tty_tty_driver->init_termios.c_oflag = 0;
629
+ tty0tty_tty_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
630
+ tty0tty_tty_driver->init_termios.c_lflag = 0;
631
+ tty0tty_tty_driver->init_termios.c_ispeed = 38400;
632
+ tty0tty_tty_driver->init_termios.c_ospeed = 38400;
633
+
634
+
635
+ tty_set_operations(tty0tty_tty_driver, &serial_ops);
636
+
637
+
638
+ /* register the tty driver */
639
+ retval = tty_register_driver(tty0tty_tty_driver);
640
+ if (retval) {
641
+ printk(KERN_ERR "failed to register tty0tty tty driver");
642
+ put_tty_driver(tty0tty_tty_driver);
643
+ return retval;
644
+ }
645
+
646
+ printk(KERN_INFO DRIVER_DESC " " DRIVER_VERSION "\n");
647
+ return retval;
648
+ }
649
+
650
+ static void __exit tty0tty_exit(void)
651
+ {
652
+ struct tty0tty_serial *tty0tty;
653
+ int i;
654
+
655
+ #ifdef SCULL_DEBUG
656
+ printk(KERN_DEBUG "%s - \n", __FUNCTION__);
657
+ #endif
658
+ for (i = 0; i < TINY_TTY_MINORS; ++i)
659
+ tty_unregister_device(tty0tty_tty_driver, i);
660
+ tty_unregister_driver(tty0tty_tty_driver);
661
+
662
+ /* shut down all of the timers and free the memory */
663
+ for (i = 0; i < TINY_TTY_MINORS; ++i) {
664
+ tty0tty = tty0tty_table[i];
665
+ if (tty0tty) {
666
+ /* close the port */
667
+ while (tty0tty->open_count)
668
+ do_close(tty0tty);
669
+
670
+ /* shut down our timer and free the memory */
671
+ kfree(tty0tty);
672
+ tty0tty_table[i] = NULL;
673
+ }
674
+ }
675
+ }
676
+
677
+ module_init(tty0tty_init);
678
+ module_exit(tty0tty_exit);
Binary file