summaryrefslogtreecommitdiff
path: root/v4l_experimental/firesat/firesat-ci.c
blob: 3d005cb56349ace9afb1d7e80e3fc5fd419d489b (plain)
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
#include "firesat-ci.h"
#include "firesat.h"
#include "avc_api.h"

#include <linux/dvb/ca.h>

#include "dvbdev.h"

static int firesat_ca_do_ioctl(struct inode *inode, struct file *file, unsigned int cmd, void *parg) {
	struct firesat *firesat = (struct firesat*)((struct dvb_device*)file->private_data)->priv;
	int err;

//	printk(KERN_INFO "%s: ioctl %d\n",__FUNCTION__,cmd);

	switch(cmd) {
	case CA_RESET:
		err = AVCResetTPDU(firesat);
//		if(err==0)
			mdelay(3000);
		break;
	case CA_GET_CAP: {
		ca_caps_t *cap=(ca_caps_t*)parg;
		cap->slot_num = 1;
		cap->slot_type = CA_CI_LINK;
		cap->descr_num = 1;
		cap->descr_type = CA_DSS; // ### peter fragen!

		err = 0;
		break;
	}
	case CA_GET_SLOT_INFO: {
		ca_slot_info_t *slot=(ca_slot_info_t*)parg;
		if(slot->num == 0) {
			slot->type = CA_CI | CA_CI_LINK | CA_DESCR;
			slot->flags = CA_CI_MODULE_PRESENT | CA_CI_MODULE_READY;
		} else {
			slot->type = 0;
			slot->flags = 0;
		}
		err = 0;
		break;
	}
	default:
			err=-EINVAL;
	}
	return err;
}

static int firesat_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) {
	return dvb_usercopy(inode, file, cmd, arg, firesat_ca_do_ioctl);
}

static ssize_t firesat_ca_io_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) {
	struct firesat *firesat = (struct firesat*)((struct dvb_device*)file->private_data)->priv;
	char *data=kmalloc(count,GFP_KERNEL);
//	printk(KERN_INFO "%s: count = %d\n",__FUNCTION__, count);
	copy_from_user(data,buf,count);
	int r=AVCWriteTPDU(firesat, data, count);
	kfree(data);
	if(!r)
		return count;
	printk("%s: failed writing data\n",__FUNCTION__);
	return 0;
}

static ssize_t firesat_ca_io_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) {
	struct firesat *firesat = (struct firesat*)((struct dvb_device*)file->private_data)->priv;
	char *data=kmalloc(count,GFP_KERNEL);
//	printk(KERN_INFO "%s: count = %d\n",__FUNCTION__,count);
	int r=AVCReadTPDU(firesat, data, &count);
	if(!r) {
		copy_to_user(buf,data,count);
		kfree(data);
		return count;
	}
	kfree(data);
	return 0;
}

static int firesat_ca_io_open(struct inode *inode, struct file *file) {
	printk(KERN_INFO "%s!\n",__FUNCTION__);
	return dvb_generic_open(inode, file);
}

static int firesat_ca_io_release(struct inode *inode, struct file *file) {
	printk(KERN_INFO "%s!\n",__FUNCTION__);
	return dvb_generic_release(inode, file);
}

static unsigned int firesat_ca_io_poll(struct file *file, poll_table *wait) {
//	printk(KERN_INFO "%s!\n",__FUNCTION__);
	return POLLIN;
}

static struct file_operations firesat_ca_fops = {
	.owner = THIS_MODULE,
	.read = firesat_ca_io_read,
	.write = firesat_ca_io_write,
	.ioctl = firesat_ca_ioctl,
	.open = firesat_ca_io_open,
	.release = firesat_ca_io_release,
	.poll = firesat_ca_io_poll,
};

static struct dvb_device firesat_ca = {
	.priv = NULL,
	.users = 1,
	.readers = 1,
	.writers = 1,
	.fops = &firesat_ca_fops,
};

int firesat_ca_init(struct firesat *firesat) {
	int ret = dvb_register_device(firesat->adapter, &firesat->cadev, &firesat_ca, firesat, DVB_DEVICE_CA);
	if(ret) return ret;
	AVCResetTPDU(firesat);
	// avoid unnecessary delays, we're not talking to the CI yet anyways
	return 0;
}

void firesat_ca_release(struct firesat *firesat) {
	dvb_unregister_device(firesat->cadev);
}