RK3288_IMEI

1# vi kernel/driver/char/Makefile

#add by for RK3288 IMEI
obj-$(CONFIG_JIANGDOU_RK_EMMC_IMEI)            += rk3288_imei/


2# vi kernel/driver/char/Kcong

#add by jiangdou for RK3288 IMEI
source "drivers/char/rk3288_imei/Kconfig"


3# vi kernel/driver/char/rk3288_imei/Makefile

#
# Makefile for RK_EMMC_IMEI
#

#  SPI testing only for (using spidev driver)
# \file  -> spi_test.c
  
#  \version     1.0.0
 
#  \date        2015年12月12日
  
#  \author      jiangdou  
 
# Copyright (c) 2015 jiangdou. All Rights Reserved.
 
obj-$(CONFIG_JIANGDOU_RK_EMMC_IMEI)	+= rk32-imei.o


4# vi kernel/driver/char/rk3288_imei/Kcong

#
# Kcong for RK_EMMC_IMEI
#

#  SPI testing only for (using spidev driver)
# \file  -> spi_test.c
  
#  \version     1.0.0
 
#  \date        2015年12月12日
  
#  \author      jiangdou  
 
# Copyright (c) 2015 jiangdou. All Rights Reserved.
config JIANGDOU_RK_EMMC_IMEI
	tristate "for RK3288 IMEI Driver by jiangdou"
	
	help
	  Say Y here if you want to support the RK3288_IMEI driver


5# vi kernel/driver/char/rk3288_imei/rk32-imei.c

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#include 
//linux/ctype.h

extern char GetSNSectorInfo(char * pbuf);
static struct class *rkimei_class; 
int imei_read_from_IDB(u8 *imei)
{
	int i;
	char *tempBuf = kmalloc(512, GFP_KERNEL);

	if(imei == NULL)
		return -EFAULT;

	GetSNSectorInfo(tempBuf);
#if 0
	for (i = 450; i < 467; i++) {
		//printk("jiangdou_%dst_%02x, ",i, tempBuf[i]);
		if(((i+1)%16) == 0) printk("\n");
	}
#endif
	for (i = 452; i <= 466; i++) {
		imei[i-452] = tempBuf[i];
	}

	kfree(tempBuf);

	return 0;
}

int rk3288_imei_idb(u8 *rk32_imei)
{
	int i;
	int err = 0;
	memset(rk32_imei, 0, 15);
	err = imei_read_from_IDB(rk32_imei);
	if(err)
		return -1;
	printk("Read the IMEI address from IDB:");
	for (i = 0; i < 14; i++)
		printk("%2.2x:", rk32_imei[i]);
	printk("%2.2x\n", rk32_imei[i]);

	return 0;
}



static int jiangdou_imei_drv_open(struct inode *inode, struct file *file)
{

		
	printk("RK3288 MIEI openi\n");
    return 0;
}


//ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
static ssize_t jiangdou_imei_drv_read(struct file *file, char __user *buf, size_t count, loff_t *f_pos)
{
    
	unsigned char *imei_buf;
	//ssize_t read_count = imei_count;
	int ret = 0;
	int i;
	unsigned char buff[15];
	imei_buf = buff;
	
	unsigned char tmp_buf[16];
	
	memset(imei_buf, 0, 15);
	memset(tmp_buf, 0, 15);
	ret = rk3288_imei_idb(imei_buf);
	
	if(ret)
		return -1;
	//printk("Read jiangdouimei from IDB:");
	for (i = 0; i < 15; i++){
		//tmp_buf[i]= (imei_buf[i] & 0x0f);
		//printk("%2.1x:", tmp_buf[i]);
		//tmp_buf[i]  = tmp_buf[i] + '0';
		tmp_buf[i]= imei_buf[i];
	}
	//printk("\n");
	
	tmp_buf[15] = '\n';
	ret = copy_to_user(buf, tmp_buf, sizeof(tmp_buf));
   
	if(ret < 0){
		printk("Read jiangdouimei from IDB .......fail....\n");
		return -EFAULT;
	}
	if(*f_pos ==0){
		*f_pos += sizeof(tmp_buf);
		return sizeof(tmp_buf);
	}else
		return 0;
	
	
	return 0;	
	
}

static struct file_operations jiangdou_imei_drv_fops = {
    .owner  =   THIS_MODULE,    
    .open   =   jiangdou_imei_drv_open,    
    .read  =   jiangdou_imei_drv_read,         
};

int major;

static int jiangdou_imei_drv_init(void)
{      

		 
	printk("by jiangdou for RK3288_IMEI  into init\n"); 
   
    major = register_chrdev(0, "jiangdou_imei", &jiangdou_imei_drv_fops);
    
    rkimei_class = class_create(THIS_MODULE,"jiangdou_imei");
    device_create(rkimei_class,NULL,MKDEV(major,0),NULL,"jiangdou_imei");
   
	printk("by jiangdou for RK3288_IMEI  register OK\n"); 
    return 0;
}

static void jiangdou_imei_drv_exit(void)
{
       
         unregister_chrdev(major, "jiangdou_imei");
        
         device_destroy(rkimei_class,MKDEV(major,0));
         class_destroy(rkimei_class);
         printk(KERN_ALERT "RK3288_IMEI unregister\n");
}


module_init(jiangdou_imei_drv_init);
module_exit(jiangdou_imei_drv_exit);

MODULE_AUTHOR("by jiangdou");
MODULE_LICENSE("GPL");
6# png
RK3288_IMEI_第1张图片

7#adb shell  TEST

root@rk3288:/# cat /dev/jiangdou_imei
359090044253312
root@rk3288:/# 


8#/framework/base/xxx   修改略!  

你可能感兴趣的:(rk30)