File: dmx_dev.c

package info (click to toggle)
dmx4linux 2.5%2Bdfsg-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,660 kB
  • ctags: 2,835
  • sloc: ansic: 23,341; yacc: 918; asm: 846; makefile: 614; sh: 439
file content (998 lines) | stat: -rw-r--r-- 25,931 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
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
260
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
303
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
352
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
387
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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
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
572
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
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
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
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
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
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
/*
 * dev.c
 * Device-driver and registration module for dmx-devices
 *
 * Copyright (C) Michael Stickel <michael@cubic.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
/*
 * 1999/12/05  Stickel  removed bug that crops a write to 100 channels
 * 2000/01/10  Stickel  added support to access all universes upon minor 0
 * 2000/07/24  Stickel  removed old device stuff.
 */


#include <dmxdev/dmxdevP.h>
#include <dmx/dmxioctl.h>


#include <linux/module.h>
#include <linux/devfs_fs_kernel.h>


#include <linux/miscdevice.h>
#include <linux/init.h>
#include <linux/poll.h>
#include <linux/fs.h>


MODULE_AUTHOR("Michael Stickel, michael@cubic.org, http://llg.cubic.org/");
MODULE_DESCRIPTION("DMX4Linux " DMXVERSION " management module. Abstraction layer to filesystem. (C) Michael Stickel");
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,17)
MODULE_LICENSE("GPL");
#endif

#undef DEBUG

#ifdef DEBUG
#define DO_DEBUG(x...)  (x)
#else
#define DO_DEBUG(x...)
#endif

static unsigned char dmxbuffer[MAX_UNIVERSES*512];


/*
 * dmx_data_available
 *
 * returns 1 if data has changed since the last read access.
 */
static int  dmx_data_available (struct _DMXFileInfo *fi, uint start, uint size)
{
  if (size && start > sizeof(dmxbuffer)) /* eigentlich hier nicht notwendig */
	return -EINVAL;		/* out of range */
  if (fi->changed>0) return 1;
  return 0;
}

/*
 * dmxout_to_user
 *
 * copies the data from a dmx output universe to the userspace.
 */
static size_t dmxout_to_user (struct _DMXFileInfo *fi, unsigned char *buff, off_t offs, size_t size)
{
  if (offs > sizeof(dmxbuffer))
    return -EINVAL;

  if (offs+size > sizeof(dmxbuffer))
    size = sizeof(dmxbuffer) - offs;

  copy_to_user (buff, &dmxbuffer[offs], size);

  return size;
}


/*
 * check if there is data available from the inputs
 */
#if 0 /* seems to be not used yet */
static int  dmxin_data_available (struct _DMXFileInfo *fi, uint start, uint size)
{
  int i;
  uint _start = 0;
  uint _size = 0;

  /* Unspecified area.
   * => check all universes for availability of data.
   */
  if (size==0)
    {
      start = 0;
      size = sizeof(dmxbuffer);
    }

  _start = start%512;
  _size = size;

  for (i=start/512; i<=(start+size)/512; i++)
    {
      int stat = 0;
      DMXUniverse *inu = dmx_universe_by_index(1,i);
      if (inu && inu->data_available)
	{
	  stat = inu->data_available (inu, _start, (_size>512)?512:_size);
	  if (stat) return stat;
	}
      _size -= 512-_start;
      _start = 0;
    }
  return 0;
}
#endif


/*
 * dmxout_to_user
 *
 * copies the data from a dmx input universe to the userspace.
 */
static size_t dmxin_to_user (struct _DMXFileInfo *fi, unsigned char *buff, off_t offs, size_t size)
{
  int consumed=0;
  while(consumed<size)
    {
      DMXUniverse *inu;
      const int universum=offs/512;
      const int universum_start=offs%512;
      int len=512-universum_start;
      if(consumed+len > size)
	len=size-consumed;

      inu = dmx_universe_by_index(1, universum);
      if (inu && inu->read_slots)
	{
	  int readlen;
	  unsigned char tbuff[512];
          memset(tbuff, 0, sizeof(tbuff));

	  readlen = inu->read_slots (inu, universum_start, tbuff, len);
          if (readlen > 0 && readlen<=len)
	    copy_to_user(buff, tbuff, readlen);
	}
      buff+=len;
      consumed+=len;
      offs+=len;
    }
  return size;
}

/*
 *  Write to an output universe
 */
static void dmx_write_to_universe (loff_t start, size_t size)
{
  unsigned  char *buf=dmxbuffer+start;
  const size_t end = start + size;
  while(start<end)
    {
      const int universe=start/512;
      const int s=start%512;
      const int len=512-s;
      DMXUniverse *uni = dmx_universe_by_index (0, universe);
      if(uni && uni->write_slots)
	uni->write_slots (uni, s, buf, len);
      start+=len;
      buf+=len;
    }
}

/*-----------------------------------------------------------------
 * name    : DMXDev_read
 * function: This function is called by the read-system-call
 */
static ssize_t DMXDev_read (struct file *file, char *buf, size_t size, loff_t *pos)
{
  int minor = FILE_MINOR (file);

  if (!file)   return -EINVAL;
  if (!buf)    return -EINVAL;
  if (size<=0) return -EINVAL;

  if (IS_MINOR_DMXOUT(minor))
    {
      DMXFileInfo *info = (DMXFileInfo *)file->private_data;
      if (file->f_pos+size > sizeof(dmxbuffer))
	size = sizeof(dmxbuffer) - file->f_pos;
      if (info && !verify_area(VERIFY_WRITE, buf, size))
	{
          int n;

          if (info->block)
            {
	      int stat = info->data_available(info, file->f_pos, size);
	      if (stat<0)
                {
                  printk (KERN_INFO "dmxdev.read:/dev/dmx/:error while data_available\n");
                  return stat;
                }
	      if (!stat)
	        {
	          info->flags |= DMXFI_F_REQUEST;
	          info->request.start = file->f_pos;
	          info->request.size = size;
	          interruptible_sleep_on (&info->read_wait_queue);
	          info->flags &= ~DMXFI_F_REQUEST;
	        }
            }
	  info->changed = 0;
	  n = copy_to_user (buf, &dmxbuffer[file->f_pos], size);
          if (n>0)
            file->f_pos += size;
   	  return size;
	}
    }

  /* read dmx-in is the same as read dmx-mod with exception
   * of the data that is read. dmx-in comes from input universes
   * but dmx-mon comes from userspace (data written to outputs.
   * data_available and copy_to_user are different for dmx-in and dmx-mon.
   */
  else if (IS_MINOR_DMXIN(minor))
    {
      DMXFileInfo *info = (DMXFileInfo *)file->private_data;
      if (info && !verify_area(VERIFY_WRITE, buf, size))
	{
          int n=0;
          if (info->block)
            {
	      int stat = info->data_available(info, file->f_pos, size);
	      if (stat<0)
                {
                  printk (KERN_INFO "dmxdev.read:/dev/dmxmon,/dev/dmxout: error while data_available\n");
                  return stat;
                }
	      if (!stat)
	        {
	          info->flags |= DMXFI_F_REQUEST;
	          info->request.start = file->f_pos;
	          info->request.size = size;
	          interruptible_sleep_on (&info->read_wait_queue);
	          info->flags &= ~DMXFI_F_REQUEST;
	        }
            }
	  info->changed = 0;
	  n = info->to_user (info, buf, file->f_pos, size);
          if (IS_MINOR_DMXIN(minor) && n>0)
            file->f_pos += n;
          return n;
	}
    }
  return -EINVAL;
}


/*
 * Signals a process that data is available.
 * All process that have requested a select and
 * all processes that have requested a read within
 * the area that has changed are signaled.
 *
 * <u> is a refference to the universe that has changed.
 * if size is 0 all processes that have a pending read
 * will be signalled.
 * !!!!! HAS TO BE MOVED ELSEWHERE !!!!!
 */
int  dmx_universe_signal_changed (DMXUniverse *u, uint start, uint size)
{
  int i;
  DMXFileInfo *info = NULL;

  DO_DEBUG(printk (KERN_INFO "dmx_universe_signal_changed(%p, %u, %u)\n", u, start, size));

  for (i=0; (info = dmx_fileinfo_by_index(i)); i++)
    {
      if (info->target==DMXFI_DMXIN)
	{
	  if (info->flags & DMXFI_F_POLL)
	    {
	      DO_DEBUG(printk (KERN_INFO "signal_changed: DMX_FI_POLL:info %p signaled\n", info));
	      info->flags &= ~DMXFI_F_POLL;
	      wake_up (&info->read_wait_queue);
	    }

	  if (info->flags & DMXFI_F_REQUEST)
	    {
	      if (!size || (start <= info->request.start+info->request.size &&
			    start+size >= info->request.start))
		{
		  DO_DEBUG(printk (KERN_INFO "signal_changed: DMXFI_F_REQUEST:info %p signaled\n", info));
		  wake_up (&info->read_wait_queue);
		}
	    }
	  info->changed = 1;
#if 0
          if (info->async_queue)
            KILL_FASYNC((struct fasync_struct *)(info->async_queue), SIGIO, POLL_IN);
#endif
	}
      else if (info->target==DMXFI_DMXOUT)
        {
	  info->changed = 1;
#if 1
          if (info->async_queue)
            KILL_FASYNC((struct fasync_struct *)(info->async_queue), SIGIO, POLL_IN);
#endif
        }
    }
  return 0;
}




/*--------------------------------------------------------------
 * name    : DMXDev_write
 * function: This function is called by the write-system-call
 */
static ssize_t DMXDev_write (struct file *file, const char *buf, size_t size, loff_t *pos)
{
  int minor = FILE_MINOR (file);

  DO_DEBUG(printk (KERN_INFO "DMXDev_write()\n"));

  if (IS_MINOR_DMXOUT(minor))
    {
      int i;
      DMXFileInfo *info = NULL;

      if (file->f_pos+size > sizeof(dmxbuffer))
	size = sizeof(dmxbuffer) - file->f_pos;
      if (!verify_area(VERIFY_READ, buf, size))
	{
	  copy_from_user (&dmxbuffer[file->f_pos], buf, size);

          DO_DEBUG(printk (KERN_INFO "DMXDev_write: about to call dmx_write_to_universe\n"));
	  dmx_write_to_universe (file->f_pos, size);

	  /*
	   * wake up all universes which are waiting for
	   * data to be written to the output.
	   */
	  for (i=0; (info = dmx_fileinfo_by_index(i)); i++)
	    {
	      if (info->target==DMXFI_DMXOUT)
		{
		  if (info->flags & DMXFI_F_POLL)
		    {
		      info->flags &= ~DMXFI_F_POLL;
		      wake_up (&info->read_wait_queue);
		    }

		  if (info->flags & DMXFI_F_REQUEST)
		    {
		      if (file->f_pos <= info->request.start+info->request.size &&
			  file->f_pos+size >= info->request.start)
			wake_up (&info->read_wait_queue);
		    }
		  info->changed = 1;
		}
	    }
          file->f_pos += size;
   	  return size;
	}
    }

  else if (IS_MINOR_DMXIN(minor))
    {
      DO_DEBUG(printk (KERN_INFO "I am not able to write to DMX-IN\n"));
      file->f_pos += size;
      return size;
    }

  else
    {
      DO_DEBUG(printk (KERN_INFO "dmxdev::write request for unused minor %d\n", minor));
      file->f_pos += size;
      return size;
    }
  return -EINVAL;
}




/*--------------------------------------------------------------
 * name    : DMXDev_poll
 * function:
 */
static unsigned int DMXDev_poll (struct file *file, poll_table * wait)
{
  DMXFileInfo *info = (DMXFileInfo *)file->private_data;
  unsigned int mask = 0;
  int          stat=0;

  DO_DEBUG(printk (KERN_INFO "DMXDev_poll(%p,%p)\n", file, wait));

  if (!info)
    return POLLERR;

  DO_DEBUG(printk (KERN_INFO "select on file %p with info %p\n", file, info));

  poll_wait (file, &info->read_wait_queue, wait);

  stat = info->data_available(info, 0, 0);
  if (stat<0)
    return POLLERR;

  if (stat)
    mask |= POLLIN | POLLRDNORM;
  else
    info->flags |= DMXFI_F_POLL;  /* tell writer that someone polls for data */

  /*  mask |= POLLOUT | POLLWRNORM; */
  return mask;
}



/*---------------------------------------------------------
 * name    : DMXDev_lseek
 * function: This function is calles by the lseek-system-call
*/
static long long DMXDev_lseek (struct file *file, long long offset, int orig)
{
  switch (orig)
    {
    case 0:
      file->f_pos = offset;
      return file->f_pos;
    case 1:
      file->f_pos += offset;
      return file->f_pos;
    default:
      return -EINVAL;
    }
}



/*----------------------------------------------------------
 * name    : DMXDev_ioctl
 * function: This function will later be called by the ioctl-system-call
*/
static int DMXDev_ioctl (struct inode *node, struct file *file, unsigned int cmd, unsigned long arg)
{
  int minor = FILE_MINOR (file);

  printk(KERN_INFO "ioctl(%d,%lu)\n", cmd, arg);

  /* u_char *DevBuffer = DMXBuffer(minor); */
  switch (cmd)
    {
      /*
       * set all channels to 0.
       */
    case DMX_IOCTL_BLACKOUT: /* set all channels to 0 */
      if (IS_MINOR_DMXOUT(minor))
	{
	  DO_DEBUG(printk (KERN_INFO "ioctl(DMX_IOCTL_BLACKOUT)\n"));
	  memset (dmxbuffer, 0, sizeof(dmxbuffer));
	  dmx_write_to_universe (0, sizeof(dmxbuffer));
	  return 0;
	}
      break;

      /*
       * Get some global information from dmx4linux as:
       * => dmx4linux version.
       * => number of max universes supported
       * => number of output-universes used.
       * => number of input-universes used.
       * => number of drivers currently loaded.
       * => names of the drivers currently loaded.
       *
       */
    case DMX_IOCTL_GET_INFO:
      if (arg && verify_area(VERIFY_READ, (void *)arg, sizeof(struct dmx_info))==0)
	{
	  struct dmx_info  info;
	  size_t           remain_size = sizeof(info.family_names);
	  char           * buffer = info.family_names;
	  DMXFamily      *f = NULL;

	  info.version_major = VERSIONMAJOR;
	  info.version_minor = VERSIONMINOR;
	  info.max_out_universes  = MAX_UNIVERSES;
	  info.max_in_universes   = MAX_UNIVERSES;
	  info.used_in_universes  = number_input_universes();
	  info.used_out_universes = number_output_universes();
	  info.num_entries = 0;
	  info.num_families = 0;

	  /*
	   * Collect all possible driver names.
	   */
	  f = dmx_get_root_family ();
	  while (f)
	    {
	      size_t namelen = f->name ? (strlen(f->name)+1) : 0;
	      if (f->name && namelen < remain_size)
		{
		  strcpy (buffer, f->name);
		  buffer += namelen;
		  remain_size -= namelen;
		  info.num_entries++;
		}
	      info.num_families++;
	      f = f->next;
	    }

	  copy_to_user ((void *)arg, &info, sizeof(info));

	  return 0;
	}
      else
	return -EMSGSIZE;
      break;

    case DMX_IOCTL_GET_DRIVERS:
      if (arg && verify_area(VERIFY_READ|VERIFY_WRITE, (void *)arg, sizeof(struct dmx_family_info))==0)
	{
	  DMXFamily *f = NULL;
	  struct dmx_family_info info;
	  size_t                 remain_size = sizeof(info.driver_names);
	  char                 * buffer      = info.driver_names;

	  copy_from_user (&info, (void *)arg, sizeof(info));

	  info.num_entries = 0;
	  info.num_drivers = 0;

	  f = dmx_find_family (info.familyname);
	  if (f)
	    {
	      int offset = info.offset;
	      DMXDriver *d = f->drivers;

	      /*
	       * skip unwhanted names.
	       */
	      while (d && offset > 0)
		{
		  info.num_drivers++;
		  offset--;
		  d = d->next;
		}

	      while (d)
		{
		  size_t namelen = d->name ? (strlen(d->name)+1) : 0;
		  if (d->name && namelen < remain_size)
		    {
		      strcpy (buffer, d->name);
		      buffer += namelen;
		      remain_size -= namelen;
		      info.num_entries++;
		    }
		  info.num_drivers++;
		  d = d->next;
		}
	    }
	  else
	    printk("failed to find family %s\n", info.familyname);
	  copy_to_user ((void *)arg, &info, sizeof(info));

	  return 0;
	}
      else
	return -EMSGSIZE;
      break;

      /*
       *
       *
       */
    case DMX_IOCTL_GET_CAP:
      if (arg && !verify_area(VERIFY_WRITE, (void *)arg, sizeof(struct dmx_capabilities)))
	{
	  struct dmx_capabilities  cap;
	  DMXUniverse  *uni = NULL;
	  DMXProperty  *p = NULL;

	  if (!arg || verify_area(VERIFY_READ, (void *)arg, sizeof(struct dmx_capabilities)))
	    return -EMSGSIZE;

	  copy_from_user (&cap, (void *)arg, sizeof(cap));

	  uni = dmx_universe_by_index(cap.direction, cap.universe);
	  if (uni)
	    {
	      strcpy (cap.family,    uni->interface->driver->family->name);
	      strcpy (cap.driver,    uni->interface->driver->name);
	      strcpy (cap.connector, uni->connector);
	      cap.conn_id = uni->conn_id;

	      if ((p = uni->findprop (uni, "slots")))
		{
		  long slots = 512L;
		  p->get_long (p, &slots);
		  cap.maxSlots = slots;
		}
	      else
		cap.maxSlots = 512;

	      cap.mabsize   = DMX_UNDEFINED; /* multible of 1/10 uS */
	      cap.breaksize = DMX_UNDEFINED;
	      copy_to_user ((void *)arg, &cap, sizeof(cap));
	      return 0;
	    }
	  else
	    return -EAGAIN;
#if 0
	  { /* fill with defaults */
	    strcpy (cap.family,    "unused");
	    strcpy (cap.driver,    "unused");
	    strcpy (cap.connector, "unknown");
	    cap.conn_id  = DMX_UNDEFINED;
	    cap.maxSlots = 0;
	    cap.mabsize   = DMX_UNDEFINED;
	    cap.breaksize = DMX_UNDEFINED;
	  }
#endif
	}
      else
	return -EMSGSIZE;
      break;


      /*
       *
       */
    case DMX_IOCTL_SET_CONF:
    case DMX_IOCTL_GET_CONF:
      return -EINVAL;
      break;


      /*
       * Get and set parameters.
       */
    case DMX_IOCTL_GET_PARM:
    case DMX_IOCTL_SET_PARM:
      {
	struct dmx_parameter val;
	DMXUniverse *u   = NULL;

	if (!arg || verify_area(VERIFY_READ, (void *)arg, sizeof(struct dmx_parameter)))
	  return -EMSGSIZE;

	if (cmd==DMX_IOCTL_SET_PARM && verify_area(VERIFY_WRITE, (void *)arg, sizeof(struct dmx_parameter)))
	  return -EMSGSIZE;

	copy_from_user (&val, (void *)arg, sizeof(val));

	u = dmx_universe_by_index(val.direction, val.universe);
	if (u->props)
	  {
	    DMXProperty *prop = u->props->find (u->props, val.name);
	    if (!prop && u->interface && u->interface->props)
	      prop = u->interface->props->find (u->interface->props, val.name);
	    if (prop)
	      {
		int stat=0;
		if (cmd==DMX_IOCTL_SET_PARM)
		  stat=prop->set_string(prop, val.value);
		else
		  {
		    stat=prop->get_string(prop, val.value, sizeof(val.value));
		    copy_to_user ((void *)arg, &val, sizeof(val));
		  }
		if (stat >= 0)
		  return 0;
	      }
	  }
	return -EAGAIN;
      }
      break;


    case DMX_IOCTL_GET_PARM_NAMES:
      {
	DMXUniverse *u = NULL;
	struct dmx_parm_names  names;

	if (!arg || verify_area(VERIFY_READ | VERIFY_WRITE, (void *)arg, sizeof(struct dmx_parm_names)))
	  return -EMSGSIZE;
	copy_from_user (&names, (void *)arg, sizeof(names));

	names.size = 0;
	names.num_names = 0;

	u = dmx_universe_by_index(names.direction, names.universe);
	if (u)
	  {
	    size_t sizeused = 0;
	    printk("try to get names\n");

	    if (u->props && u->props->size)
	      names.size += u->props->size (u->props);

	    if (u->interface->props && u->interface->props->size)
	      names.size += u->interface->props->size (u->props);

	    names.num_names = u->props->names (u->props, names.names, sizeof(names.names), &sizeused);
	    if (names.num_names>=0)
	      names.num_names += u->interface->props->names (u->interface->props, names.names+sizeused, sizeof(names.names)-sizeused, NULL);

	    copy_to_user ((void *)arg, &names, sizeof(names));
	    printk("copied to userspace\n");
	    return 0;
	  }
	return -EINVAL;
      }
      break;


    case DMX_IOCTL_CREATE_INTERFACE:
      {
	DMXDriver *driver = NULL;
	struct dmx_createinterface_parm parm;

	if (!arg || verify_area(VERIFY_WRITE | VERIFY_READ, (void *)arg, sizeof(parm)))
	  return -EMSGSIZE;
	copy_from_user (&parm, (void *)arg, sizeof(parm));

	driver = dmx_find_familydriver (parm.name);
	if (driver)
	  {
	    DMXInterface * dmxif = driver->create_interface(driver, dmxproplist_vacreate(parm.properties));
	    if (dmxif)
	      {
		/* ...... */
		return 0;
	      }
	  }
      }
      break;

    case DMX_IOCTL_DELETE_INTERFACE:
      {
      }
      break;

    case DMX_IOCTL_CREATE_UNIVERSE:
      {
#if 0
	DMXInterface *dmxif = NULL;
	struct dmx_createuniverse_parm parm;

	if (!arg || verify_area(VERIFY_WRITE | VERIFY_READ, (void *)arg, sizeof(parm)))
	  return -EINVAL;
	copy_from_user (&parm, (void *)arg, sizeof(parm));

	dmxif = find_interface (...);
	if (dmxif)
	  {
	    DMXUniverse *universe = dmxif->create_universe (dmxif, parm.direction, dmxproplist_vacreate(parm.properties));
	    if (universe)
	      {
		/* .... */
	      }
	  }
#endif
      }
      break;


    case DMX_IOCTL_DELETE_UNIVERSE:
      {
	struct dmx_deleteuniverse_parm parm;
	DMXUniverse *univ = NULL;

	if (!arg || verify_area(VERIFY_WRITE, (void *)arg, sizeof(parm)))
	  return -EMSGSIZE;
	copy_from_user (&parm, (void *)arg, sizeof(parm));

	univ = dmx_universe_by_index(parm.direction, parm.id);
	if (univ)
	  {
	    univ->delete(univ);
	    return 0;
	  }
      }
      break;

    default:
      DO_DEBUG(printk (KERN_INFO "DMXout.ioctl currently not implemented\n"));
    }

  return -EINVAL;
}


/*-------------------------------------------------------
 * name    : DMXDev_open
 * function: This function is called by the open-system-call
*/
static int DMXDev_open (struct inode *inode, struct file *file)
{
/*  int  ret = 0; */
  int minor = FILE_MINOR (file);

  DO_DEBUG(printk (KERN_INFO "%s: open (minor=%d, inodeptr=%p,fileptr=%p)\n", MODULE_NAME, minor, inode, file));

  file->private_data = NULL;

  if (IS_MINOR_DMXOUT(minor))
    {
      DMXFileInfo *fi = dmx_fileinfo_create (file);
      if (!fi)
        {
          printk (KERN_INFO "dmxdev: Error while open: creation of fileinfo failed");
	  return -EBUSY;
        }
      printk (KERN_INFO "dmxdev: opening as DMXFI_DMXOUT\n");
      fi->target = DMXFI_DMXOUT;
      fi->data_available = dmx_data_available;
      fi->to_user = dmxout_to_user;
      fi->block = !(file->f_flags & O_NONBLOCK);
      return 0;
    }
  else if (IS_MINOR_DMXIN(minor))
    {
      DMXFileInfo *fi = dmx_fileinfo_create (file);
      if (!fi)
        {
          printk (KERN_INFO "dmxdev: Error while open: creation of fileinfo failed");
	  return -EBUSY;
        }
      printk (KERN_INFO "dmxdev: opening as DMXFI_DMXIN\n");
      fi->target = DMXFI_DMXIN;
      /*      fi->data_available = dmxin_data_available; */
      fi->data_available = dmx_data_available;
      fi->to_user = dmxin_to_user;
      fi->block = !(file->f_flags & O_NONBLOCK);
      return 0;
    }

  return -ENODEV;
}


/*------------------------------------------------------
 * name    : DMXDev_close
 * function: This function is called by the close-system-call.
*/
static int DMXDev_close (struct inode *inode, struct file *file)
{
  int minor = FILE_MINOR (file);

  DO_DEBUG(printk (KERN_INFO "%s: close (minor=%d)\n", MODULE_NAME, minor));

  if (IS_MINOR_DMXOUT(minor) || IS_MINOR_DMXIN(minor))
    {
      if (file->private_data)
	dmx_fileinfo_delete ((DMXFileInfo *)file->private_data);
      return 0;
    }

  return -EBUSY;
}

/*------------------------------------------------------
 * name		: DMXDev_fasync
*/
int DMXDev_fasync (int fd, struct file *filp, int mode)
{
  DMXFileInfo *info = (DMXFileInfo *)filp->private_data;
  return info?fasync_helper (fd, filp, mode, &info->async_queue):-EINVAL;
}

/* these are the file operations for the DMX-devices */
static struct file_operations dmxdev_fops =
{
	llseek:	DMXDev_lseek,
	read:	DMXDev_read,
	write:	DMXDev_write,
	poll:	DMXDev_poll,    /* no select, will be used to signal received frame */
	ioctl:	DMXDev_ioctl,	/* no ioctl, will follow for configuration */
	open:	DMXDev_open,
	release:DMXDev_close,

	fasync:	DMXDev_fasync,
};


static struct miscdevice dmxout_misc =
{
  minor:	DMXOUTMINOR,
  name:		"dmx",
  fops:		&dmxdev_fops, /* should be something else */
};

static struct miscdevice dmxin_misc =
{
  minor:	DMXINMINOR,
  name:		"dmxin",
  fops:		&dmxdev_fops, /* should be something else */
};

/*
 *  And now the modules code and kernel interface.
 */


/* This func. is called when the module is loaded */
static int __init dmx_dev_init(void)
{
  printk (KERN_INFO MODULE_NAME " " DMXVERSION " compiled for Linux " UTS_RELEASE " Copyright (c) 1998-2005 by Michael Stickel\n");

  dmxdev_fops.owner = THIS_MODULE;

  dmx_fileinfo_init ();

  printk (KERN_INFO "%s: %d universes for input / %d universes for output\n", MODULE_NAME, MAX_UNIVERSES, MAX_UNIVERSES);

  if (!misc_register (&dmxout_misc))
    {
#ifdef CONFIG_DEVFS_FS
      if(devfs_set_flags (dmxout_misc.devfs_handle, DEVFS_FL_AUTO_OWNER) < 0)
	printk(KERN_ERR MODULE_NAME ": could not set flags on %s\n", dmxout_misc.name);
#endif
      printk (KERN_INFO "%s: registration of %s succeded\n", MODULE_NAME, dmxout_misc.name);
      if (!misc_register (&dmxin_misc))
        {
#ifdef CONFIG_DEVFS_FS
	  if(devfs_set_flags (dmxin_misc.devfs_handle, DEVFS_FL_AUTO_OWNER) < 0)
	    printk(KERN_ERR MODULE_NAME ": could not set flags on %s\n", dmxout_misc.name);
#endif
          printk (KERN_INFO "%s: registration of %s succeded\n", MODULE_NAME, dmxin_misc.name);

          if (DMXProcInit () >= 0)
            return 0;
          else
            printk (KERN_INFO "%s: unable to create proc entries\n", MODULE_NAME);

          misc_deregister(&dmxin_misc);
        }
      else
        printk (KERN_INFO "%s: misc_register(%s) failed\n", MODULE_NAME, dmxin_misc.name);

      misc_deregister(&dmxout_misc);
    }
  else
    printk (KERN_INFO "%s: misc_register(%s) failed\n", MODULE_NAME, dmxout_misc.name);

  return -EBUSY;
}


/* This is called when the module should be unloaded */
static void __exit dmx_dev_exit(void)
{
  if (dmx_get_root_family ())
    printk (KERN_INFO "dmxdev: cleanup_module: There are some families\n");

  printk (KERN_INFO "%s: cleanup_module called\n", MODULE_NAME);

  DMXProcCleanup ();
  printk (KERN_INFO "%s: proc entries removed\n", MODULE_NAME);

  if (misc_deregister(&dmxin_misc))
    printk (KERN_INFO "%s: deregistration of %s failed\n", MODULE_NAME, dmxin_misc.name);
  else
    printk (KERN_INFO "%s: deregistration of %s succeded\n", MODULE_NAME, dmxin_misc.name);

  if (misc_deregister(&dmxout_misc))
    printk (KERN_INFO "%s: deregistration of %s failed\n", MODULE_NAME, dmxout_misc.name);
  else
    printk (KERN_INFO "%s: deregistration of %s succeded\n", MODULE_NAME, dmxout_misc.name);
}

module_init(dmx_dev_init);
module_exit(dmx_dev_exit);

#ifdef EXPORT_SYMTAB
EXPORT_SYMBOL(dmx_create_family);
EXPORT_SYMBOL(dmx_find_driver);
EXPORT_SYMBOL(dmxprop_create_long);
EXPORT_SYMBOL(dmxprop_user_long);
EXPORT_SYMBOL(dmxproplist_create);
EXPORT_SYMBOL(dmxproplist_vacreate);
#endif