Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / Really tired of wasting questions and receiving wrong answers

Really tired of wasting questions and receiving wrong answers

Computer Science

Really tired of wasting questions and receiving wrong answers. I just need help with this code. Gives me error because can not read the makefile. How can I fix it?  Please understand my frustration with this service... I will rate/thumbs up if it's correct (which 75% of the time Course Hero is incorrect) and comment if it's not correct... So please don't answer if you're going to spam or give me wrong answers or not answer/follow up if I comment about one part being wrong. This is the 10 time I'm posting this question now. Can whomever please answer every requirement to this question and provide correct answers?  Also please stop keep bring the question from the Chegg!! That answer is not correct! Thank you. ASAP??!!!  

Instructions: 

Background:

The Linux operating system consists of the Kernel some other minor components and then a large number of Device Drivers. Device drivers are the key to how various hardware devices interface with the computer.

Task:

Develop a device driver that can be loaded and run in Linux. Then add some functionality to the device driver such as the user/application passing in a string to the device driver and the device driver returns an encrypted version of the string or passes in the excrypted string and returns the original string. Include a document on how to build, load and interact with the device driver along with screen shots of output.

Requirements: It must be written in C. It must be a valid an loadable device driver with at least some user/application functionality. That includes an open, release, read, write, and at least one ioctl command. It must also be able to be unloaded, and indicate that it has unloaded from the system. Make use of the printk and copy_to_user functions. The read and write functions should follow the concept of linux files and be relevent to reading or writing.

Part of the grading of the driver will be based on the functionality you choose to implement. It can not be trivial functionality.

This must be run in the linux virtual machine.

You must also write a user application that utilizes your device driver.

There are TWO directories in your GitHub: The first is Module that has your kernel module. The second is Test that will have your test user application.

The writeup should have a detailed description of what your device driver does and clear instructions on how to build your kernel module and your test program and how to install the kernel module and how to use your test program.

Example: Encrypt data, read and write a string, use ioctl to determine to encrypt or decrypt and to set an key. If ioctl set to encrypt, write a string, then read back the encrypted data. Switch ioctl to decrypt then write the encrypted string and read back the original message (decrypted).

NOTE: No basic calculator or palindrome allowed!

The code:

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/ioctl.h>
#include <linux/kdev_t.h>
#include <linux/cdev.h>
#include <linux/device.h>
#include<linux/slab.h>                
#include<linux/uaccess.h>            

 
 
#define WRITEVALUE _IOW('a','a',int32_t*)
#define READVALUE _IOR('a','b',int32_t*)
 
static int isOpen = 0;
int num_bytes = 0; 
int32_t value = 0;
dev_t dev = 0;

static char message [1024];

static struct class *mydevice_class;
static struct cdev mydevice_cdev;


//definition of device driver functions
static int      mydevice_open(struct inode *inode, struct file *filep);
static ssize_t  mydevice_read(struct file *filep, char __user *outb, size_t nbytes,loff_t * offset);
static ssize_t  mydevice_write(struct file *filep, const char *inpb, size_t nbytes, loff_t * offset);
static long     mydevice_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
static int      mydevice_release(struct inode *inode, struct file *filep);
static int      __init mydevice_start(void);
static void     __exit mydevice_end(void);


//file operation structure
static struct file_operations fops =
{

        .open           = mydevice_open,
        .read           = mydevice_read,
        .write          = mydevice_write,
        .unlocked_ioctl = mydevice_ioctl,
        .release        = mydevice_release,
};


//function for opening the device file
static int mydevice_open(struct inode *inode, struct file *filep)
{
        if (isOpen == 1) { //if file is open value is 1 else 0
	  printk(KERN_INFO "Error: device already opened n");	
	  return -EBUSY; //return negative 
	}
	isOpen = 1; //file open
        printk(KERN_INFO "tDevice Driver File Openedn");
        return 0;
}



//function for reading from device driver
static ssize_t mydevice_read(struct file *filep, char __user *outb, size_t nbytes, loff_t *offset)
{
        int bytesread = 0;

	if (*offset == NULL)
	return -EINVAL;
	if (*offset >= num_bytes)
	return 0;

	while ((bytesread < nbytes) && (*offset < num_bytes)) {
		__user(message [*offset], outb[bytesread]);
	*offset++;
	bytesread++;
	}
        printk(KERN_INFO "tRead Device filen");
	return bytesread;
        return 0;
}


//function for writing to device driver
static ssize_t mydevice_write(struct file *filep, const char __user *inpb, size_t nbytes, loff_t *offset)
{
        int byteswritten = 0;
	if (*offset == NULL)
		return -EINVAL;
	if (*offset >= num_bytes)
		return -EINVAL;
	
	while ((byteswritten < nbytes) && (*offset < num_bytes)) {
			__user(message [*offset], inpb[byteswritten]);
		*offset++;
		byteswritten++;
		}
                printk(KERN_INFO "tWrite to Device Drivern");
		return byteswritten;	
        return 0;
}



//function for IOCTL operation in device file
static long mydevice_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
{
         switch(cmd) {
                case WRITEVALUE:
                        copy_from_user(&value ,(int32_t*) arg, sizeof(value));
                        printk(KERN_INFO "IO Value : %dn", value);
                        break;
                case READVALUE:
                        copy_to_user((int32_t*) arg, &value, sizeof(value));
                        break;
        }
        return 0;
}

//function to release the device driver
static int mydevice_release(struct inode *inode, struct file *filep)
{
        if (isOpen == 0 ) { //if device not opened
	  printk(KERN_INFO "ERROR: device was not opened n");
	  return -EBUSY;
	}

        printk(KERN_INFO "tDevice Driver File Closedn");
        isOpen = 0; //keeping track of device file
        return 0;
}
 
//function to startialize the device driver
//allocates and validates major number
//creates device structure and adds to system
//creates struct class and device 
static int __init mydevice_start(void)
{
        if((alloc_chrdev_region(&dev, 0, 1, "mydevice_Dev")) <0){
                printk(KERN_INFO "ERROR: major number allocation failed! n");
                return -EINVAL;
        }
        printk(KERN_INFO "Major = %d Minor = %d n",MAJOR(dev), MINOR(dev));
 
        cdev_init(&mydevice_cdev,&fops);
 
        if((cdev_add(&mydevice_cdev,dev,1)) < 0){
            printk(KERN_INFO "ERROR: could not add to driver.n");
            goto r_class;
        }
 
        if((mydevice_class = class_create(THIS_MODULE,"mydevice_class")) == NULL){
            printk(KERN_INFO "ERROR: could not create struct classn");
            goto r_class;
        }
 
        if((device_create(mydevice_class,NULL,dev,NULL,"mydevice_device")) == NULL){
            printk(KERN_INFO "ERROR: could not create Device Drivern");
            goto r_device;
        }
        printk(KERN_INFO "tDevice Driver Installation Succeed.n");
        return 0;
 
r_device:
        class_destroy(mydevice_class);
r_class:
        unregister_chrdev_region(dev,1);
        return -EINVAL;
}

//function to end the device driver
static void __exit mydevice_end(void)
{
        device_destroy(mydevice_class,dev);
        class_destroy(mydevice_class);
        cdev_del(&mydevice_cdev);
        unregister_chrdev_region(dev, 1);
        printk(KERN_INFO "tDevice Driver Removed Success.n");
}
 
module_init(mydevice_start);
module_exit(mydevice_end);

application.c

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include<sys/ioctl.h>

 
#define WRITEVALUE _IOW('a','a',int32_t*)
#define READVALUE _IOR('a','b',int32_t*)
 
int main()
{
        int fd;
        int32_t value;
        int32_t num;
        
        printf("t--Device Driver Application Test --n");

 
        printf("nt -- Opening Device Driver --n");
        fd = open("/home/student/Desktop/mydevice", O_RDONLY);
        if(fd < 0) {
                printf("ERROR! File open failed!n");
                return 0;
        }
 
        printf("nEnter Number to Send to Device Driver: ");
        scanf("%d",&num);
        printf("nt-- Writing Entered Number to Device Driver --n");
        printf("...n");
        ioctl(fd, WRITEVALUE, (int32_t*) &num); 
 
        printf("nt -- Reading Number from Devie Driver --n");
        printf("...n");
        ioctl(fd, READVALUE, (int32_t*) &value);
        printf("nNumber Written and Read from Device Driver is: %dn", value);
 
        printf("nt-- Closing Device Driver Driver --n");
	printf("success.n");

        close(fd);
}

 

mydevice.mod.c

#include <linux/build-salt.h>
#include <linux/module.h>
#include <linux/vermagic.h>
#include <linux/compiler.h>

BUILD_SALT;

MODULE_INFO(vermagic, VERMAGIC_STRING);
MODULE_INFO(name, KBUILD_MODNAME);

__visible struct module __this_module
__section(.gnu.linkonce.this_module) = {
	.name = KBUILD_MODNAME,
	.init = init_module,
#ifdef CONFIG_MODULE_UNLOAD
	.exit = cleanup_module,
#endif
	.arch = MODULE_ARCH_INIT,
};

#ifdef CONFIG_RETPOLINE
MODULE_INFO(retpoline, "Y");
#endif

MODULE_INFO(depends, "");


MODULE_INFO(srcversion, "CC0BAA2CA34EF6DF972BE0B");

Makefile

KERNELDIR=/lib/modules/`uname -r`/build

# This the the Makefile for the device driver (not your demonstration program)

#Change the base name here to your module file name - no extension
BASENAME=helloworld


MODULES = $(BASENAME).ko 
obj-m += $(BASENAME).o 

all:
	make -C $(KERNELDIR) M=$(PWD) modules

clean:
	make -C $(KERNELDIR) M=$(PWD) clean

install:	
	make -C $(KERNELDIR) M=$(PWD) modules_install

quickInstall:
	cp $(MODULES) /lib/modules/`uname -r`/extra

MakefileTest:

FIRSTNAME=
LASTNAME=

ROOTNAME=$()_$()_HW
HW=6
FOPTION=_main
RUNOPTIONS=
CC=gcc
CFLAGS= -g -I.
LIBS =-l pthread
DEPS = 
OBJ = $(ROOTNAME)$(HW)$(FOPTION).o

%.o: %.c $(DEPS)
	$(CC) -c -o $@ $< $(CFLAGS) 

$(ROOTNAME)$(HW)$(FOPTION): $(OBJ)
	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)

clean:
	rm *.o $(ROOTNAME)$(HW)$(FOPTION)

run: $(ROOTNAME)$(HW)$(FOPTION)
	./$(ROOTNAME)$(HW)$(FOPTION) $(RUNOPTIONS)

vrun: $(ROOTNAME)$(HW)$(FOPTION)
	valgrind ./$(ROOTNAME)$(HW)$(FOPTION) $(RUNOPTIONS)

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Related Questions