static int set_hw_reason(int reason) { char filename[32] = ""; int hw_reason = reason; struct file *filp = NULL; ssize_t nread; int pnum = get_partition_num_by_name("misc"); if (pnum < 0) { pr_info("unknown partition number for misc partition\n"); return 0; } snprintf(filename, 32, "/dev/block/mmcblk0p%d", pnum); filp = filp_open(filename, O_RDWR, 0); if (IS_ERR(filp)) { pr_info("unable to open file: %s\n", filename); return PTR_ERR(filp); } filp->f_pos = 624; nread = kernel_write(filp, (char *)&hw_reason, sizeof(int), filp->f_pos); pr_info("wrire: %X (%d)\n", hw_reason, nread); if (filp) filp_close(filp, NULL); return 1; }
int htc_debug_read(char *page, char **start, off_t off, int count, int *eof, void *data) { int len=FLAG_LEN+3; char R_Buffer[FLAG_LEN+3]; char RfMisc[FLAG_LEN+3]; char filename[32] = ""; struct file *filp = NULL; ssize_t nread; int pnum; if (off > 0) { len = 0; } else { if(first_read){ pnum = get_partition_num_by_name("misc"); if (pnum < 0) { printk(KERN_ERR"unknown partition number for misc partition\n"); return 0; } snprintf(filename, 32, "/dev/block/mmcblk0p%d", pnum); filp = filp_open(filename, O_RDWR, 0); if (IS_ERR(filp)) { printk(KERN_ERR"unable to open file: %s\n", filename); return PTR_ERR(filp); } SECMSG("%s: offset :%d\n", __func__, offset); filp->f_pos = offset; memset(RfMisc,0,FLAG_LEN+3); nread = kernel_read(filp, filp->f_pos, RfMisc, FLAG_LEN+2); memset(htc_debug_flag,0,FLAG_LEN+1); memcpy(htc_debug_flag,RfMisc+2,FLAG_LEN); SECMSG("%s: RfMisc :%s (%zd)\n", __func__,RfMisc, nread); SECMSG("%s: htc_debug_flag:%s \n", __func__, htc_debug_flag); if (filp) filp_close(filp, NULL); first_read = 0; } memset(R_Buffer,0,FLAG_LEN+3); memcpy(R_Buffer,"0x",2); memcpy(R_Buffer+2,htc_debug_flag,FLAG_LEN); memcpy(page,R_Buffer,FLAG_LEN+3); } return len; }
static ssize_t htc_debug_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos) { char buf[FLAG_LEN+3]; char filename[32] = ""; struct file *filp = NULL; ssize_t nread; int pnum; SECMSG("%s called (count:%d)\n", __func__, (int)count); if (count != sizeof(buf)){ printk(KERN_ERR"count != sizeof(buf)\n"); return -EFAULT; } if (copy_from_user(buf, buffer, count)) return -EFAULT; memset(htc_debug_flag,0,FLAG_LEN+1); memcpy(htc_debug_flag,buf+2,FLAG_LEN); SECMSG("Receive :%s\n",buf); SECMSG("Flag :%s\n",htc_debug_flag); pnum = get_partition_num_by_name("misc"); if (pnum < 0) { printk(KERN_ERR"unknown partition number for misc partition\n"); return 0; } snprintf(filename, 32, "/dev/block/mmcblk0p%d", pnum); filp = filp_open(filename, O_RDWR, 0); if (IS_ERR(filp)) { printk(KERN_ERR"unable to open file: %s\n", filename); return PTR_ERR(filp); } SECMSG("%s: offset :%d\n", __func__, offset); filp->f_pos = offset; nread = kernel_write(filp, buf, FLAG_LEN+2, filp->f_pos); SECMSG("%s:wrire buf: %s (%zd)\n", __func__, buf, nread); if (filp) filp_close(filp, NULL); return count; }
static int htc_debug_read(struct seq_file *m, void *v) { char filename[32] = ""; char RfMisc[FLAG_LEN+3]={0}; struct file *filp = NULL; ssize_t nread; int pnum; if(first_read){ printk(KERN_ERR"%s: hdf init Start...\n", __func__); pnum = get_partition_num_by_name("misc"); if (pnum < 0) { printk(KERN_ERR"unknown partition number for misc partition\n"); return 0; } snprintf(filename, 32, "/dev/block/mmcblk0p%d", pnum); filp = filp_open(filename, O_RDWR, 0); if (IS_ERR(filp)) { printk(KERN_ERR"unable to open file: %s\n", filename); return PTR_ERR(filp); } SECMSG("%s: offset :%d\n", __func__, offset); filp->f_pos = offset; nread = kernel_read(filp, filp->f_pos, RfMisc, FLAG_LEN+2); memset(htc_debug_flag,0,FLAG_LEN+1); memcpy(htc_debug_flag,RfMisc+2,FLAG_LEN); SECMSG("%s: RfMisc :%s (%zd)\n", __func__,RfMisc, nread); SECMSG("%s: htc_debug_flag:%s \n", __func__, htc_debug_flag); seq_printf(m, "0X%s\n",htc_debug_flag); if (filp) filp_close(filp, NULL); first_read = 0; printk(KERN_ERR"%s: hdf :%s \n", __func__,htc_debug_flag); printk(KERN_ERR"%s: hdf init End...\n", __func__); }else seq_printf(m, "0X%s\n",htc_debug_flag); return 0; }