Results 1 to 1 of 1
hi all,
I am currently developing a User Space Device Driver for a USB Deivce....My code goes like this....
kernel_space.c
#include<linux/config.h>
#include<linux/kernel.h>
#include<linux/errno.h>
#include<linux/init.h>
#include<linux/slab.h>
#include<linux/module.h>
#include<linux/kref.h>
#include<linux/smp_lock.h>
#include<linux/usb.h>
#include<linux/device.h>
...
- 04-24-2008 #1Just Joined!
- Join Date
- Apr 2008
- Posts
- 11
Problem : User Space Device Drivers
hi all,
I am currently developing a User Space Device Driver for a USB Deivce....My code goes like this....
kernel_space.c
#include<linux/config.h>
#include<linux/kernel.h>
#include<linux/errno.h>
#include<linux/init.h>
#include<linux/slab.h>
#include<linux/module.h>
#include<linux/kref.h>
#include<linux/smp_lock.h>
#include<linux/usb.h>
#include<linux/device.h>
#include<linux/sched.h>
#include<asm/current.h>
#include<linux/moduleparam.h>
#include<linux/stat.h>
#include<linux/mod_devicetable.h>
#include<asm-i386/uaccess.h>
#include<linux/fs.h>
#include<asm/segment.h>
static struct usb_device_id usb_test_table[] = {
{ USB_DEVICE(0xffff,0x9999) },
{}
};
MODULE_DEVICE_TABLE (usb,usb_test_table);
#define TEST_MINOR_BASE 192
static int test_open(struct inode *inode, struct file *file)
{
printk(KERN_ALERT "INSIDE OPEN FUNCTION\n");
return 1;
}
static int test_release(struct inode *inode, struct file *file)
{
printk(KERN_ALERT "INSIDE RELEASE FUNCTION\n");
return 0;
}
static ssize_t test_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
{
printk(KERN_ALERT "INSIDE READ FUNCTION\n");
return 1;
}
static ssize_t test_write(struct file *file, const char __user *user_buffer, size_t count, loff_t *ppos)
{
printk(KERN_ALERT "INSIDE WRITE FUNCTION\n");
return 1;
}
static struct file_operations test_fops = {
.owner = THIS_MODULE,
.open = test_open,
.read = test_read,
.write = test_write,
.release = test_release,
};
static struct usb_class_driver test_class = {
.name = "USB_DEVICE",
.fops = &test_fops,
//.mode = S_IRUSR | S_IWUSR,
.minor_base = TEST_MINOR_BASE,
};
static int usb_test_probe(struct usb_interface *test_int,const struct usb_device_id *test_id)
{
int chk_reg_dev = 0;
struct usb_device *t_usb_dev;
printk(KERN_ALERT "THE NAME %s\n",test_class.name);
if(!test_int){
printk(KERN_ALERT "INTERFACE NOT FOUND\n");
return -1;
}
if(!test_id){
printk(KERN_ALERT "TEST_ID NOT FOUND\n");
return -1;
}
chk_reg_dev = usb_register_dev(test_int,&test_class);
if(chk_reg_dev){
printk(KERN_ALERT "Not able to get a minor for this device.\n");
usb_set_intfdata(test_int, NULL);
return -1;
}
printk(KERN_ALERT "INSIDE PROBE FUNCTION\n");
return 0;
}
static void usb_test_disconnect(struct usb_interface *test_interface)
{
printk(KERN_ALERT "INSIDE DISCONNECT FUNCTION\n");
usb_deregister_dev(test_interface,&test_class);
}
static struct usb_driver usb_test_driver = {
.owner = THIS_MODULE,
.name = "USB_DRIVER",
.id_table = usb_test_table,
.probe = usb_test_probe,
.disconnect = usb_test_disconnect,
};
static int __init usb_test_init(void)
{
int result;
/*-------- REGISTERING THE DRIVER --------*/
result = usb_register(&usb_test_driver);
/*------- IF DURING REGISTRATION SOME ERROR OCCURS THEN IT WILL RETURN SOME -ve VALUE ----------------*/
/*------- OTHERWISE IT WILL RETURN 0 --------------------*/
if(result) //----- IF SOME ERROR OCCURED -----------
err("usb_register FAILED,---ERROR NUMBER %d---\n",result);
//--------- ELSE-----------------
return result;
}
static void __exit usb_test_exit(void)
{
usb_deregister(&usb_test_driver);
}
module_init(usb_test_init);
module_exit(usb_test_exit);
//MODULE_LICENSE("GPL");
Now the PROBLEM is that when this DEVICE is REGISTERED its entry is made in the /dev/.......but when I try to access this file through the User Space Code the whole SYSTEM CRASHES.......
Please help me.......this thing is making me go crazy .......
regards
Ameya Verma


Reply With Quote