int dhd_write_macaddr(struct ether_addr *mac) { char *filepath_data = MACINFO; char *filepath_efs = MACINFO_EFS; struct file *fp_mac = NULL; char buf[18] = {0}; mm_segment_t oldfs = {0}; int ret = -1; int retry_count = 0; startwrite: sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X\n", mac->octet[0], mac->octet[1], mac->octet[2], mac->octet[3], mac->octet[4], mac->octet[5]); /* File will be created /data/.mac.info. */ fp_mac = filp_open(filepath_data, O_RDWR | O_CREAT, 0666); if (IS_ERR(fp_mac)) { DHD_ERROR(("[WIFI] %s: File open error\n", filepath_data)); return -1; } else { oldfs = get_fs(); set_fs(get_ds()); if (fp_mac->f_mode & FMODE_WRITE) { ret = fp_mac->f_op->write(fp_mac, (const char *)buf, sizeof(buf), &fp_mac->f_pos); if (ret < 0) DHD_ERROR(("[WIFI] Mac address [%s] Failed to" " write into File: %s\n", buf, filepath_data)); else DHD_INFO(("[WIFI] Mac address [%s] written" " into File: %s\n", buf, filepath_data)); } set_fs(oldfs); filp_close(fp_mac, NULL); } /* check .mac.info file is 0 byte */ fp_mac = filp_open(filepath_data, O_RDONLY, 0); ret = kernel_read(fp_mac, 0, buf, 18); if ((ret == 0) && (retry_count++ < 3)) { filp_close(fp_mac, NULL); goto startwrite; } filp_close(fp_mac, NULL); /* end of /data/.mac.info */ if (filepath_efs == NULL) { DHD_ERROR(("[WIFI]%s : no efs filepath", __func__)); return 0; } /* File will be created /efs/wifi/.mac.info. */ fp_mac = filp_open(filepath_efs, O_RDWR | O_CREAT, 0666); if (IS_ERR(fp_mac)) { DHD_ERROR(("[WIFI] %s: File open error\n", filepath_efs)); return -1; } else { oldfs = get_fs(); set_fs(get_ds()); if (fp_mac->f_mode & FMODE_WRITE) { ret = fp_mac->f_op->write(fp_mac, (const char *)buf, sizeof(buf), &fp_mac->f_pos); if (ret < 0) DHD_ERROR(("[WIFI] Mac address [%s] Failed to" " write into File: %s\n", buf, filepath_efs)); else DHD_INFO(("[WIFI] Mac address [%s] written" " into File: %s\n", buf, filepath_efs)); } set_fs(oldfs); filp_close(fp_mac, NULL); } /* check .mac.info file is 0 byte */ fp_mac = filp_open(filepath_efs, O_RDONLY, 0); ret = kernel_read(fp_mac, 0, buf, 18); if ((ret == 0) && (retry_count++ < 3)) { filp_close(fp_mac, NULL); goto startwrite; } filp_close(fp_mac, NULL); return 0; }
int logger_write(const enum logidx index, const unsigned char prio, const char __kernel * const tag, const char __kernel * const fmt, ...) { int ret = 0; va_list vargs; struct file *filp = (struct file *)-ENOENT; mm_segment_t oldfs; struct iovec vec[3]; int tag_bytes = strlen(tag) + 1, msg_bytes; char *msg; va_start(vargs, fmt); msg = kvasprintf(GFP_ATOMIC, fmt, vargs); va_end(vargs); if (!msg) return -ENOMEM; if (in_interrupt()) { /* we have no choice since aio_write may be blocked */ printk(KERN_ALERT "%s", msg); goto out_free_message; } msg_bytes = strlen(msg) + 1; if (msg_bytes <= 1) /* empty message? */ goto out_free_message; /* don't bother, then */ if ((msg_bytes + tag_bytes + 1) > 2048) { ret = -E2BIG; goto out_free_message; } vec[0].iov_base = (unsigned char *) &prio; vec[0].iov_len = 1; vec[1].iov_base = (void *) tag; vec[1].iov_len = strlen(tag) + 1; vec[2].iov_base = (void *) msg; vec[2].iov_len = strlen(msg) + 1; oldfs = get_fs(); set_fs(KERNEL_DS); do { filp = filp_open("/dev/log/main", O_WRONLY, S_IRUSR); if (IS_ERR(filp) || !filp->f_op) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: filp_open /dev/log/main error\n", __FUNCTION__)); ret = -ENOENT; break; } if (filp->f_op->aio_write) { int nr_segs = sizeof(vec) / sizeof(vec[0]); int len = vec[0].iov_len + vec[1].iov_len + vec[2].iov_len; struct kiocb kiocb; init_sync_kiocb(&kiocb, filp); kiocb.ki_pos = 0; kiocb.ki_left = len; kiocb.ki_nbytes = len; ret = filp->f_op->aio_write(&kiocb, vec, nr_segs, kiocb.ki_pos); } } while (0); if (!IS_ERR(filp)) { filp_close(filp, NULL); } set_fs(oldfs); out_free_message: if (msg) { kfree(msg); } return ret; }
static int proximity_do_calibrate(struct gp2a_data *data, bool do_calib, bool thresh_set) { struct file *cal_filp; int err; int xtalk_avg = 0; int offset_change = 0; uint16_t thrd = 0; u8 reg; mm_segment_t old_fs; if (do_calib) { if (thresh_set) { /* for proximity_thresh_store */ data->offset_value = data->threshold_high - (gp2a_reg[6][1] << 8 | gp2a_reg[5][1]); } else { /* tap offset button */ /* get offset value */ xtalk_avg = proximity_adc_read(data); offset_change = (gp2a_reg[6][1] << 8 | gp2a_reg[5][1]) - DEFAULT_HI_THR; if (xtalk_avg < offset_change) { /* do not need calibration */ data->cal_result = 0; err = 0; goto no_cal; } data->offset_value = xtalk_avg - offset_change; } /* update threshold */ thrd = (gp2a_reg[4][1] << 8 | gp2a_reg[3][1]) + (data->offset_value); THR_REG_LSB(thrd, reg); gp2a_i2c_write(data, gp2a_reg[3][0], ®); THR_REG_MSB(thrd, reg); gp2a_i2c_write(data, gp2a_reg[4][0], ®); thrd = (gp2a_reg[4][1] << 8 | gp2a_reg[5][1]) +(data->offset_value); THR_REG_LSB(thrd, reg); gp2a_i2c_write(data, gp2a_reg[5][0], ®); THR_REG_MSB(thrd, reg); gp2a_i2c_write(data, gp2a_reg[6][0], ®); /* calibration result */ if (!thresh_set) data->cal_result = 1; } else { /* tap reset button */ data->offset_value = 0; /* update threshold */ gp2a_i2c_write(data, gp2a_reg[3][0], &gp2a_reg[3][1]); gp2a_i2c_write(data, gp2a_reg[4][0], &gp2a_reg[4][1]); gp2a_i2c_write(data, gp2a_reg[5][0], &gp2a_reg[5][1]); gp2a_i2c_write(data, gp2a_reg[6][0], &gp2a_reg[6][1]); /* calibration result */ data->cal_result = 2; } old_fs = get_fs(); set_fs(KERNEL_DS); cal_filp = filp_open(data->pdata->prox_cal_path, O_CREAT | O_TRUNC | O_WRONLY | O_SYNC, S_IRUGO | S_IWUSR | S_IWGRP); if (IS_ERR(cal_filp)) { pr_err("%s: Can't open calibration file\n", __func__); set_fs(old_fs); err = PTR_ERR(cal_filp); goto done; } err = cal_filp->f_op->write(cal_filp, (char *)&data->offset_value, sizeof(int), &cal_filp->f_pos); if (err != sizeof(int)) { pr_err("%s: Can't write the cal data to file\n", __func__); err = -EIO; } filp_close(cal_filp, current->files); done: set_fs(old_fs); no_cal: return err; }
int dhd_write_rdwr_korics_macaddr(struct dhd_info *dhd, struct ether_addr *mac) { struct file *fp = NULL; char macbuffer[18] = {0}; mm_segment_t oldfs = {0}; char randommac[3] = {0}; char buf[18] = {0}; char *filepath_efs = MACINFO_EFS; int is_zeromac = 0; int ret = 0; /* MAC address copied from efs/wifi.mac.info */ fp = filp_open(filepath_efs, O_RDONLY, 0); if (IS_ERR(fp)) { /* File Doesn't Exist. Create and write mac addr. */ fp = filp_open(filepath_efs, O_RDWR | O_CREAT, 0666); if (IS_ERR(fp)) { DHD_ERROR(("[WIFI] %s: File open error\n", filepath_efs)); return -1; } oldfs = get_fs(); set_fs(get_ds()); /* Generating the Random Bytes for * 3 last octects of the MAC address */ get_random_bytes(randommac, 3); sprintf(macbuffer, "%02X:%02X:%02X:%02X:%02X:%02X\n", 0x60, 0xd0, 0xa9, randommac[0], randommac[1], randommac[2]); DHD_ERROR(("[WIFI] The Random Generated MAC ID : %s\n", macbuffer)); if (fp->f_mode & FMODE_WRITE) { ret = fp->f_op->write(fp, (const char *)macbuffer, sizeof(macbuffer), &fp->f_pos); if (ret < 0) DHD_ERROR(("[WIFI] Mac address [%s]" " Failed to write into File:" " %s\n", macbuffer, filepath_efs)); else DHD_ERROR(("[WIFI] Mac address [%s]" " written into File: %s\n", macbuffer, filepath_efs)); } set_fs(oldfs); } else { /* Reading the MAC Address from .mac.info file * (the existed file or just created file) */ ret = kernel_read(fp, 0, buf, 18); /* to prevent abnormal string display when mac address * is displayed on the screen. */ buf[17] = '\0'; /* Remove security log */ /* DHD_ERROR(("Read MAC : [%s] [%d] \r\n", buf, * strncmp(buf, "00:00:00:00:00:00", 17))); */ if ((buf[0] == '\0') || (strncmp(buf, "00:00:00:00:00:00", 17) == 0)) { is_zeromac = 1; } } if (ret) sscanf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", (unsigned int *)&(mac->octet[0]), (unsigned int *)&(mac->octet[1]), (unsigned int *)&(mac->octet[2]), (unsigned int *)&(mac->octet[3]), (unsigned int *)&(mac->octet[4]), (unsigned int *)&(mac->octet[5])); else DHD_INFO(("dhd_bus_start: Reading from the" " '%s' returns 0 bytes\n", filepath_efs)); if (fp) filp_close(fp, NULL); if (!is_zeromac) { /* Writing Newly generated MAC ID to the Dongle */ if (_dhd_set_mac_address(dhd, 0, mac) == 0) DHD_INFO(("dhd_bus_start: MACID is overwritten\n")); else DHD_ERROR(("dhd_bus_start: _dhd_set_mac_address() " "failed\n")); } else { DHD_ERROR(("dhd_bus_start:Is ZeroMAC BypassWrite.mac.info!\n")); } return 0; }
static int accel_do_calibrate(struct ssp_data *data, int iEnable) { int iSum[3] = { 0, }; int iRet = 0, iCount; struct file *cal_filp = NULL; mm_segment_t old_fs; int max_accel_1g = 0; max_accel_1g = MAX_ACCEL_1G; if (iEnable) { data->accelcal.x = 0; data->accelcal.y = 0; data->accelcal.z = 0; set_accel_cal(data); iRet = enable_accel_for_cal(data); msleep(300); for (iCount = 0; iCount < CALIBRATION_DATA_AMOUNT; iCount++) { iSum[0] += data->buf[ACCELEROMETER_SENSOR].x; iSum[1] += data->buf[ACCELEROMETER_SENSOR].y; iSum[2] += data->buf[ACCELEROMETER_SENSOR].z; mdelay(10); } disable_accel_for_cal(data, iRet); data->accelcal.x = (iSum[0] / CALIBRATION_DATA_AMOUNT); data->accelcal.y = (iSum[1] / CALIBRATION_DATA_AMOUNT); data->accelcal.z = (iSum[2] / CALIBRATION_DATA_AMOUNT); if (data->accelcal.z > 0) data->accelcal.z -= max_accel_1g; else if (data->accelcal.z < 0) data->accelcal.z += max_accel_1g; } else { data->accelcal.x = 0; data->accelcal.y = 0; data->accelcal.z = 0; } ssp_dbg("[SSP]: %s - %d, %d, %d\n", __func__, data->accelcal.x, data->accelcal.y, data->accelcal.z); old_fs = get_fs(); set_fs(KERNEL_DS); cal_filp = filp_open(CALIBRATION_FILE_PATH, O_CREAT | O_TRUNC | O_WRONLY, 0666); if (IS_ERR(cal_filp)) { pr_err("[SSP]: %s - Can't open calibration file\n", __func__); set_fs(old_fs); iRet = PTR_ERR(cal_filp); return iRet; } iRet = cal_filp->f_op->write(cal_filp, (char *)&data->accelcal, 3 * sizeof(int), &cal_filp->f_pos); if (iRet != 3 * sizeof(int)) { pr_err("[SSP]: %s - Can't write the accelcal to file\n", __func__); iRet = -EIO; } filp_close(cal_filp, current->files); set_fs(old_fs); set_accel_cal(data); return iRet; }
#define REBOOT_RECOVERY_STR "boot-recovery" #define REBOOT_UPGRADEBOOTLOADER_STR "update-radio/hboot" static int recovery_sys_notify_reboot(struct notifier_block *this, unsigned long code, void *x) { if(x && strlen((char*) x)) { mm_segment_t old_fs; loff_t off; old_fs = get_fs(); set_fs(KERNEL_DS); //printk(KERN_ERR "reboot cmd %s\n", (char*)x); #ifdef CONFIG_WRITE_TO_ANDROID_MISC_EMMC //EMMC struct file *fd = filp_open("/dev/block/mmcblk0p1", O_RDWR, 0); if(fd) { off = 0; size_t t = vfs_write(fd, REBOOT_RECOVERY_STR, strlen(REBOOT_RECOVERY_STR)+1, &off); printk(KERN_ERR "write to \"/dev/block/mmcblk0p1\" %ld bytes\n", t); vfs_fsync(fd, 0); filp_close(fd, NULL); } else { printk(KERN_ERR "open \"/dev/block/mmcblk0p1\" failed\n"); } #elif CONFIG_WRITE_TO_ANDROID_MISC_NAND //NAND #if 1
void sec_control_pm(dhd_pub_t *dhd, uint *power_mode) { struct file *fp = NULL; char *filepath = PSMINFO; mm_segment_t oldfs = {0}; char power_val = 0; char iovbuf[WL_EVENTING_MASK_LEN + 12]; g_pm_control = FALSE; fp = filp_open(filepath, O_RDONLY, 0); if (IS_ERR(fp)) { /* Enable PowerSave Mode */ dhd_wl_ioctl_cmd(dhd, WLC_SET_PM, (char *)power_mode, sizeof(uint), TRUE, 0); fp = filp_open(filepath, O_RDWR | O_CREAT, 0666); if (IS_ERR(fp) || (fp == NULL)) { DHD_ERROR(("[%s, %d] /data/.psm.info open failed\n", __FUNCTION__, __LINE__)); return; } else { oldfs = get_fs(); set_fs(get_ds()); if (fp->f_mode & FMODE_WRITE) { power_val = '1'; fp->f_op->write(fp, (const char *)&power_val, sizeof(char), &fp->f_pos); } set_fs(oldfs); } } else { if (fp == NULL) { DHD_ERROR(("[%s, %d] /data/.psm.info open failed\n", __FUNCTION__, __LINE__)); return; } kernel_read(fp, fp->f_pos, &power_val, 1); DHD_ERROR(("POWER_VAL = %c \r\n", power_val)); if (power_val == '0') { #ifdef ROAM_ENABLE uint roamvar = 1; #endif *power_mode = PM_OFF; /* Disable PowerSave Mode */ dhd_wl_ioctl_cmd(dhd, WLC_SET_PM, (char *)power_mode, sizeof(uint), TRUE, 0); /* Turn off MPC in AP mode */ bcm_mkiovar("mpc", (char *)power_mode, 4, iovbuf, sizeof(iovbuf)); dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0); g_pm_control = TRUE; #ifdef ROAM_ENABLE /* Roaming off of dongle */ bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf, sizeof(iovbuf)); dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, sizeof(iovbuf), TRUE, 0); #endif } else { dhd_wl_ioctl_cmd(dhd, WLC_SET_PM, (char *)power_mode, sizeof(uint), TRUE, 0); } } if (fp) filp_close(fp, NULL); }
static int param_get_dev_path(void) { #define DEFAULT_GPT_ENTRIES 128 #define MMCBLK_PART_INFO_PATH_LEN 128 #define PARTITION_NAME_LEN 128 struct file* p_file; mm_segment_t s_Old_FS; char a_part_info_path[MMCBLK_PART_INFO_PATH_LEN] = { 0, }; char a_partition_name[PARTITION_NAME_LEN] = { 0, }; int v_index; memset( sa_Param_dev_path, 0x0, PARAM_DEV_PATH_LEN ); for( v_index = 0; v_index < DEFAULT_GPT_ENTRIES; v_index++ ) { memset( a_part_info_path, 0x0, MMCBLK_PART_INFO_PATH_LEN ); snprintf( a_part_info_path, MMCBLK_PART_INFO_PATH_LEN, "/sys/block/mmcblk0/mmcblk0p%d/partition_name", v_index + 1 ); p_file = filp_open( a_part_info_path, O_RDONLY, NULL ); if( IS_ERR(p_file) ) { PARAM_LOG( KERN_ERR "[%s] %s file open was failed!: %ld\n", __FUNCTION__, a_part_info_path, PTR_ERR(p_file) ); } else { s_Old_FS = get_fs(); set_fs( get_ds() ); memset( a_partition_name, 0x0, PARTITION_NAME_LEN ); p_file->f_op->read( p_file, a_partition_name, PARTITION_NAME_LEN, &p_file->f_pos ); set_fs( s_Old_FS ); filp_close( p_file, NULL ); /*** Use the "strncmp" function to avoid following garbage character ***/ if( !strncmp( PARAM_PART_NAME, a_partition_name, strlen(PARAM_PART_NAME) ) ) { snprintf( sa_Param_dev_path, PARAM_DEV_PATH_LEN, "/dev/block/mmcblk0p%d", v_index + 1 ); PARAM_LOG( KERN_INFO "SEC_PARAM : %s device was found\n", sa_Param_dev_path ); break; } } } if( sa_Param_dev_path[0] != 0x0 ) { return NULL; } else { return -EFAULT; } }
static void hifi_dump_dsp(DUMP_DSP_INDEX index) { int ret = 0; mm_segment_t fs = 0; struct file *fp = NULL; int file_flag = O_RDWR; struct kstat file_stat; int write_size = 0; unsigned int err_no = 0xFFFFFFFF; char tmp_buf[64] = {0}; unsigned long tmp_len = 0; struct rtc_time cur_tm; struct timespec now; char* file_name = s_dsp_dump_info[index].file_name; char* data_addr = NULL; unsigned int data_len = s_dsp_dump_info[index].data_len; char* is_panic = "i'm panic.\n"; char* is_exception = "i'm exception.\n"; char* not_panic = "i'm ok.\n"; if ((index != NORMAL_LOG) && (index != PANIC_LOG) && g_om_data.is_watchdog_coming) { logi("watchdog is coming,so don't dump %s\n", file_name); return; } if (rdr_nv_get_value(RDR_NV_HIFI) != 1) { loge("do not save hifi log in nv config \n"); return; } if (down_interruptible(&g_om_data.dsp_dump_sema) < 0) { loge("acquire the semaphore error.\n"); return; } IN_FUNCTION; hifi_get_log_signal(); g_om_data.dsp_log_addr = (char*)ioremap_wc(DRV_DSP_UART_TO_MEM, DRV_DSP_UART_TO_MEM_SIZE); if (NULL == g_om_data.dsp_log_addr) { loge("dsp log ioremap_wc fail.\n"); goto END; } s_dsp_dump_info[NORMAL_LOG].data_addr = g_om_data.dsp_log_addr + DRV_DSP_UART_TO_MEM_RESERVE_SIZE; s_dsp_dump_info[PANIC_LOG].data_addr = g_om_data.dsp_log_addr + DRV_DSP_UART_TO_MEM_RESERVE_SIZE; if(index == OCRAM_BIN) { s_dsp_dump_info[index].data_addr = (unsigned char*)ioremap_wc(HIFI_OCRAM_BASE_ADDR, HIFI_IMAGE_OCRAMBAK_SIZE); } if(index == TCM_BIN) { s_dsp_dump_info[index].data_addr = (unsigned char*)ioremap_wc(HIFI_TCM_BASE_ADDR, HIFI_IMAGE_TCMBAK_SIZE); } if (NULL == s_dsp_dump_info[index].data_addr) { loge("dsp log ioremap_wc fail.\n"); goto END; } data_addr = s_dsp_dump_info[index].data_addr; fs = get_fs(); set_fs(KERNEL_DS); ret = hifi_create_dir(HIFI_LOG_PATH_PARENT); if (0 != ret) { goto END; } ret = hifi_create_dir(HIFI_LOG_PATH); if (0 != ret) { goto END; } ret = vfs_stat(file_name, &file_stat); if (ret < 0) { logi("there isn't a dsp log file:%s, and need to create.\n", file_name); file_flag |= O_CREAT; } fp = filp_open(file_name, file_flag, 0664); if (IS_ERR(fp)) { loge("open file fail: %s.\n", file_name); fp = NULL; goto END; } /*write from file start*/ vfs_llseek(fp, 0, SEEK_SET); /*write file head*/ if (DUMP_DSP_LOG == s_dsp_dump_info[index].dump_type) { /*write dump log time*/ now = current_kernel_time(); rtc_time_to_tm(now.tv_sec, &cur_tm); memset(tmp_buf, 0, 64); tmp_len = sprintf(tmp_buf, "%04d-%02d-%02d %02d:%02d:%02d.\n", cur_tm.tm_year+1900, cur_tm.tm_mon+1, cur_tm.tm_mday, cur_tm.tm_hour, cur_tm.tm_min, cur_tm.tm_sec); vfs_write(fp, tmp_buf, tmp_len, &fp->f_pos); /*write exception no*/ memset(tmp_buf, 0, 64); err_no = (unsigned int)(*(g_om_data.dsp_exception_no)); if (err_no != 0xFFFFFFFF) { tmp_len = sprintf(tmp_buf, "the exception no: %u.\n", err_no); } else { tmp_len = sprintf(tmp_buf, "%s", "hifi is fine, just dump log.\n"); } vfs_write(fp, tmp_buf, tmp_len, &fp->f_pos); /*write error type*/ if (0xdeadbeaf == *g_om_data.dsp_panic_mark) { vfs_write(fp, is_panic, strlen(is_panic), &fp->f_pos); } else if(0xbeafdead == *g_om_data.dsp_panic_mark){ vfs_write(fp, is_exception, strlen(is_exception), &fp->f_pos); } else { vfs_write(fp, not_panic, strlen(not_panic), &fp->f_pos); } } /*write dsp info*/ if((write_size = vfs_write(fp, data_addr, data_len, &fp->f_pos)) < 0) { loge("write file fail.\n"); } logi("write file size: %d.\n", write_size); END: if (fp) { filp_close(fp, 0); } set_fs(fs); if (NULL != g_om_data.dsp_log_addr) { iounmap(g_om_data.dsp_log_addr); g_om_data.dsp_log_addr = NULL; } if((index == OCRAM_BIN || index == TCM_BIN) && (NULL != s_dsp_dump_info[index].data_addr)) { iounmap(s_dsp_dump_info[index].data_addr); s_dsp_dump_info[index].data_addr = NULL; } hifi_release_log_signal(); up(&g_om_data.dsp_dump_sema); OUT_FUNCTION; return; }
static int load_ums_fw_bootmode(struct i2c_client *client, const char *pFn) { const u8 *buff = NULL; char fw_path[BL_UMS_FW_PATH+1]; unsigned int uFrameSize; unsigned int uFSize = 0, uNRead = 0; unsigned int uPos = 0; int iRet = SUCCESS; int iCheckFrameCrcError = 0; int iCheckWatingFrameDataError = 0; int count = 0; struct file *fp = NULL; mm_segment_t old_fs = get_fs(); struct ssp_data *data = i2c_get_clientdata(client); pr_info("[SSP] ssp_load_ums_fw start!!!\n"); old_fs = get_fs(); set_fs(get_ds()); snprintf(fw_path, BL_UMS_FW_PATH, "/sdcard/ssp/%s", pFn); fp = filp_open(fw_path, O_RDONLY, 0); if (IS_ERR(fp)) { iRet = ERROR; pr_err("file %s open error:%d\n", fw_path, (s32)fp); goto err_open; } uFSize = (unsigned int)fp->f_path.dentry->d_inode->i_size; pr_info("ssp_load_ums firmware size: %u\n", uFSize); buff = kzalloc((size_t)uFSize, GFP_KERNEL); if (!buff) { iRet = ERROR; pr_err("fail to alloc buffer for fw\n"); goto err_alloc; } uNRead = (unsigned int)vfs_read(fp, (char __user *)buff, (unsigned int)uFSize, &fp->f_pos); if (uNRead != uFSize) { iRet = ERROR; pr_err("fail to read file %s (nread = %u)\n", fw_path, uNRead); goto err_fw_size; } /* Unlock bootloader */ iRet = unlock_bootloader(client); if (iRet < 0) { pr_err("[SSP] %s - unlock_bootloader failed! %d\n", __func__, iRet); goto out; } while (uPos < uFSize) { if (data->ssp_changes == SSP_MCU_L5) { iRet = ssp_wait_for_chg(data); if (iRet < 0) { pr_err("[SSP] %s - ssp_wait_for_chg failed! %d\n", __func__, iRet); goto out; } } if (check_bootloader(client, BL_WAITING_FRAME_DATA)) { iCheckWatingFrameDataError++; if (iCheckWatingFrameDataError > 10) { iRet = ERROR; pr_err("[SSP]: %s - F/W update fail\n", __func__); goto out; } else { pr_err("[SSP]: %s - F/W data_error %d, retry\n", __func__, iCheckWatingFrameDataError); continue; } } uFrameSize = (unsigned int)((*(buff + uPos) << 8) | *(buff + uPos + 1)); /* We should add 2 at frame size as the the firmware data is not * included the CRC bytes. */ uFrameSize += 2; /* Write one frame to device */ fw_write(client, buff + uPos, uFrameSize); if (data->ssp_changes == SSP_MCU_L5) { iRet = ssp_wait_for_chg(data); if (iRet < 0) { pr_err("[SSP] %s - ssp_wait_for_chg failed! %d\n", __func__, iRet); goto out; } } if (check_bootloader(client, BL_FRAME_CRC_PASS)) { iCheckFrameCrcError++; if (iCheckFrameCrcError > 10) { iRet = ERROR; pr_err("[SSP]: %s - F/W Update Fail. crc err\n", __func__); goto out; } else { pr_err("[SSP]: %s - F/W crc_error %d, retry\n", __func__, iCheckFrameCrcError); continue; } } uPos += uFrameSize; if (count++ == 100) { pr_info("[SSP] Updated %u bytes / %u bytes\n", uPos, uFSize); count = 0; } mdelay(1); } out: err_fw_size: kfree(buff); err_alloc: filp_close(fp, NULL); err_open: set_fs(old_fs); return iRet; }
static inline int s5k5bbgx_read(struct i2c_client *client, u16 subaddr, u16 *data) { u8 buf[2]; int err = 0; struct i2c_msg msg = { .addr = client->addr, .flags = 0, .len = 2, .buf = buf, }; *(u16 *)buf = cpu_to_be16(subaddr); /* printk("\n\n\n%X %X\n\n\n", buf[0], buf[1]);*/ err = i2c_transfer(client->adapter, &msg, 1); if (unlikely(err < 0)) cam_err("ERR: %d register read fail\n", __LINE__); msg.flags = I2C_M_RD; err = i2c_transfer(client->adapter, &msg, 1); if (unlikely(err < 0)) cam_err("ERR: %d register read fail\n", __LINE__); /*printk("\n\n\n%X %X\n\n\n", buf[0], buf[1]);*/ *data = ((buf[0] << 8) | buf[1]); return err; } /* * s5k6aafx sensor i2c write routine * <start>--<Device address><2Byte Subaddr><2Byte Value>--<stop> */ #ifdef CONFIG_LOAD_FILE static int loadFile(void) { struct file *fp = NULL; struct test *nextBuf = NULL; u8 *nBuf = NULL; size_t file_size = 0, max_size = 0, testBuf_size = 0; size_t nread = 0; s32 check = 0, starCheck = 0; s32 tmp_large_file = 0; s32 i = 0; int ret = 0; loff_t pos; mm_segment_t fs = get_fs(); set_fs(get_ds()); BUG_ON(testBuf); fp = filp_open("/mnt/sdcard/external_sd/s5k5bbgx_setfile.h", O_RDONLY, 0); if (IS_ERR(fp)) { cam_err("file open error\n"); return PTR_ERR(fp); } file_size = (size_t) fp->f_path.dentry->d_inode->i_size; max_size = file_size; cam_dbg("file_size = %d\n", file_size); nBuf = kmalloc(file_size, GFP_ATOMIC); if (nBuf == NULL) { cam_dbg("Fail to 1st get memory\n"); nBuf = vmalloc(file_size); if (nBuf == NULL) { cam_err("ERR: nBuf Out of Memory\n"); ret = -ENOMEM; goto error_out; } tmp_large_file = 1; } testBuf_size = sizeof(struct test) * file_size; if (tmp_large_file) { testBuf = (struct test *)vmalloc(testBuf_size); large_file = 1; } else { testBuf = kmalloc(testBuf_size, GFP_ATOMIC); if (testBuf == NULL) { cam_dbg("Fail to get mem(%d bytes)\n", testBuf_size); testBuf = (struct test *)vmalloc(testBuf_size); large_file = 1; } } if (testBuf == NULL) { cam_err("ERR: Out of Memory\n"); ret = -ENOMEM; goto error_out; } pos = 0; memset(nBuf, 0, file_size); memset(testBuf, 0, file_size * sizeof(struct test)); nread = vfs_read(fp, (char __user *)nBuf, file_size, &pos); if (nread != file_size) { cam_err("failed to read file ret = %d\n", nread); ret = -1; goto error_out; } set_fs(fs); i = max_size; printk("i = %d\n", i); while (i) { testBuf[max_size - i].data = *nBuf; if (i != 1) { testBuf[max_size - i].nextBuf = &testBuf[max_size - i + 1]; } else { testBuf[max_size - i].nextBuf = NULL; break; } i--; nBuf++; } i = max_size; nextBuf = &testBuf[0]; #if 1 while (i - 1) { if (!check && !starCheck) { if (testBuf[max_size - i].data == '/') { if (testBuf[max_size-i].nextBuf != NULL) { if (testBuf[max_size-i].nextBuf->data == '/') { check = 1;/* when find '//' */ i--; } else if (testBuf[max_size-i].nextBuf->data == '*') { starCheck = 1;/* when find '/ *' */ i--; } } else break; } if (!check && !starCheck) { /* ignore '\t' */ if (testBuf[max_size - i].data != '\t') { nextBuf->nextBuf = &testBuf[max_size-i]; nextBuf = &testBuf[max_size - i]; } } } else if (check && !starCheck) { if (testBuf[max_size - i].data == '/') { if(testBuf[max_size-i].nextBuf != NULL) { if (testBuf[max_size-i].nextBuf->data == '*') { starCheck = 1; /* when find '/ *' */ check = 0; i--; } } else break; } /* when find '\n' */ if (testBuf[max_size - i].data == '\n' && check) { check = 0; nextBuf->nextBuf = &testBuf[max_size - i]; nextBuf = &testBuf[max_size - i]; } } else if (!check && starCheck) { if (testBuf[max_size - i].data == '*') { if (testBuf[max_size-i].nextBuf != NULL) { if (testBuf[max_size-i].nextBuf->data == '/') { starCheck = 0; /* when find '* /' */ i--; } } else break; } } i--; if (i < 2) { nextBuf = NULL; break; } if (testBuf[max_size - i].nextBuf == NULL) { nextBuf = NULL; break; } } #endif #if 0 // for print printk("i = %d\n", i); nextBuf = &testBuf[0]; while (1) { //printk("sdfdsf\n"); if (nextBuf->nextBuf == NULL) break; printk("%c", nextBuf->data); nextBuf = nextBuf->nextBuf; } #endif error_out: if (nBuf) tmp_large_file ? vfree(nBuf) : kfree(nBuf); if (fp) filp_close(fp, current->files); return ret; } #endif static inline int s5k5bbgx_write(struct i2c_client *client, u32 packet) { u8 buf[4]; int err = 0, retry_count = 5; struct i2c_msg msg = { .addr = client->addr, .flags = 0, .buf = buf, .len = 4, }; if (!client->adapter) { cam_err("ERR - can't search i2c client adapter\n"); return -EIO; } while (retry_count--) { *(u32 *)buf = cpu_to_be32(packet); err = i2c_transfer(client->adapter, &msg, 1); if (likely(err == 1)) break; mdelay(10); } if (unlikely(err < 0)) { cam_err("ERR - 0x%08x write failed err=%d\n", (u32)packet, err); return err; } return (err != 1) ? -1 : 0; } #ifdef CONFIG_LOAD_FILE static int s5k5bbgx_write_regs_from_sd(struct v4l2_subdev *sd, u8 s_name[]) { struct i2c_client *client = v4l2_get_subdevdata(sd); struct test *tempData = NULL; int ret = -EAGAIN; u32 temp; u32 delay = 0; u8 data[11]; s32 searched = 0; size_t size = strlen(s_name); s32 i; cam_dbg("E size = %d, string = %s\n", size, s_name); tempData = &testBuf[0]; while (!searched) { searched = 1; for (i = 0; i < size; i++) { if (tempData->data != s_name[i]) { searched = 0; break; } tempData = tempData->nextBuf; } tempData = tempData->nextBuf; } /* structure is get..*/ while (1) { if (tempData->data == '{') break; else tempData = tempData->nextBuf; } while (1) { searched = 0; while (1) { if (tempData->data == 'x') { /* get 10 strings.*/ data[0] = '0'; for (i = 1; i < 11; i++) { data[i] = tempData->data; tempData = tempData->nextBuf; } /*cam_dbg("%s\n", data);*/ temp = simple_strtoul(data, NULL, 16); break; } else if (tempData->data == '}') { searched = 1; break; } else tempData = tempData->nextBuf; if (tempData->nextBuf == NULL) return -1; } if (searched) break; if ((temp & S5K5BBGX_DELAY) == S5K5BBGX_DELAY) { delay = temp & 0xFFFF; cam_info("line(%d):delay(0x%x, %d)\n", __LINE__, delay, delay); msleep(delay); continue; } ret = s5k5bbgx_write(client, temp); /* In error circumstances */ /* Give second shot */ if (unlikely(ret)) { dev_info(&client->dev, "s5k5bbgx i2c retry one more time\n"); ret = s5k5bbgx_write(client, temp); /* Give it one more shot */ if (unlikely(ret)) { dev_info(&client->dev, "s5k5bbgx i2c retry twice\n"); ret = s5k5bbgx_write(client, temp); } } } return ret; } #endif /* * Read a register. */ static int s5k5bbgx_read_reg(struct v4l2_subdev *sd, u16 page, u16 addr, u16 *val) { struct i2c_client *client = v4l2_get_subdevdata(sd); u32 page_cmd = (0x002C << 16) | page; u32 addr_cmd = (0x002E << 16) | addr; int err = 0; cam_dbg("page_cmd=0x%X, addr_cmd=0x%X\n", page_cmd, addr_cmd); err = s5k5bbgx_write(client, page_cmd); CHECK_ERR(err); err = s5k5bbgx_write(client, addr_cmd); CHECK_ERR(err); err = s5k5bbgx_read(client, 0x0F12, val); CHECK_ERR(err); return 0; } /* program multiple registers */ static int s5k5bbgx_write_regs(struct v4l2_subdev *sd, const u32 *packet, u32 num) { struct s5k5bbgx_state *state = to_state(sd); struct i2c_client *client = v4l2_get_subdevdata(sd); int ret = -EAGAIN; u32 temp = 0; u16 delay = 0; while (num--) { temp = *packet++; if ((temp & S5K5BBGX_DELAY) == S5K5BBGX_DELAY) { delay = temp & 0xFFFF; cam_dbg("line(%d):delay(0x%x):delay(%d)\n", __LINE__, delay, delay); msleep(delay); continue; } ret = s5k5bbgx_write(client, temp); /* In error circumstances *Give second shot */ if (unlikely(ret)) { cam_warn("i2c retry one more time\n"); ret = s5k5bbgx_write(client, temp); /* Give it one more shot */ if (unlikely(ret)) { cam_warn("i2c retry twice\n"); ret = s5k5bbgx_write(client, temp); break; } } #ifdef S5K5BBGX_USLEEP if (unlikely(state->vt_mode)) if (!(num%200)) s5k5bbgx_usleep(3); #endif } if (unlikely(ret < 0)) { cam_err("fail to write registers!!\n"); return -EIO; } return 0; } static int s5k5bbgx_get_exif(struct v4l2_subdev *sd) { struct s5k5bbgx_state *state = to_state(sd); u16 iso_gain_table[] = {10, 18, 23, 28}; u16 iso_table[] = {0, 50, 100, 200, 400}; u16 gain = 0, val = 0; s32 index = 0; state->exif.shutter_speed = 0; state->exif.iso = 0; /* Get shutter speed */ s5k5bbgx_read_reg(sd, REG_PAGE_SHUTTER, REG_ADDR_SHUTTER, &val); state->exif.shutter_speed = 1000 / (val / 400); cam_dbg("val = %d\n", val); /* Get ISO */ val = 0; s5k5bbgx_read_reg(sd, REG_PAGE_ISO, REG_ADDR_ISO, &val); cam_dbg("val = %d\n", val); gain = val * 10 / 256; for (index = 0; index < sizeof(iso_gain_table); index++) { if (gain < iso_gain_table[index]) break; } state->exif.iso = iso_table[index]; cam_dbg("gain=%d, Shutter speed=%d, ISO=%d\n", gain, state->exif.shutter_speed, state->exif.iso); return 0; } static int s5k5bbgx_check_dataline(struct v4l2_subdev *sd, s32 val) { int err = 0; cam_info("DTP %s\n", val ? "ON" : "OFF"); #ifdef CONFIG_LOAD_FILE if (val) err = s5k5bbgx_write_regs_from_sd(sd, "s5k5bbgx_pattern_on"); else err = s5k5bbgx_write_regs_from_sd(sd, "s5k5bbgx_pattern_off"); #else if (val) { err = s5k5bbgx_write_regs(sd, s5k5bbgx_pattern_on, sizeof(s5k5bbgx_pattern_on) / \ sizeof(s5k5bbgx_pattern_on[0])); } else { err = s5k5bbgx_write_regs(sd, s5k5bbgx_pattern_off, sizeof(s5k5bbgx_pattern_off) / \ sizeof(s5k5bbgx_pattern_off[0])); } #endif if (unlikely(err)) { cam_err("fail to DTP setting\n"); return err; } return 0; }
static int fsg_lun_open(struct fsg_lun *curlun, const char *filename) { int ro; struct file *filp = NULL; int rc = -EINVAL; struct inode *inode = NULL; loff_t size; loff_t num_sectors; loff_t min_sectors; unsigned int blkbits; unsigned int blksize; /* R/W if we can, R/O if we must */ ro = curlun->initially_ro; if (!ro) { filp = filp_open(filename, O_RDWR | O_LARGEFILE, 0); if (PTR_ERR(filp) == -EROFS || PTR_ERR(filp) == -EACCES) ro = 1; } if (ro) filp = filp_open(filename, O_RDONLY | O_LARGEFILE, 0); if (IS_ERR(filp)) { LINFO(curlun, "unable to open backing file: %s\n", filename); return PTR_ERR(filp); } if (!(filp->f_mode & FMODE_WRITE)) ro = 1; inode = file_inode(filp); if ((!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode))) { LINFO(curlun, "invalid file type: %s\n", filename); goto out; } /* * If we can't read the file, it's no good. * If we can't write the file, use it read-only. */ if (!(filp->f_op->read || filp->f_op->aio_read)) { LINFO(curlun, "file not readable: %s\n", filename); goto out; } if (!(filp->f_op->write || filp->f_op->aio_write)) ro = 1; size = i_size_read(inode->i_mapping->host); if (size < 0) { LINFO(curlun, "unable to find file size: %s\n", filename); rc = (int) size; goto out; } if (curlun->cdrom) { blksize = 2048; blkbits = 11; } else if (inode->i_bdev) { blksize = bdev_logical_block_size(inode->i_bdev); blkbits = blksize_bits(blksize); } else { blksize = 512; blkbits = 9; } num_sectors = size >> blkbits; /* File size in logic-block-size blocks */ min_sectors = 1; if (curlun->cdrom) { min_sectors = 300; /* Smallest track is 300 frames */ if (num_sectors >= 256*60*75) { num_sectors = 256*60*75 - 1; LINFO(curlun, "file too big: %s\n", filename); LINFO(curlun, "using only first %d blocks\n", (int) num_sectors); } } if (num_sectors < min_sectors) { LINFO(curlun, "file too small: %s\n", filename); rc = -ETOOSMALL; goto out; } if (fsg_lun_is_open(curlun)) fsg_lun_close(curlun); curlun->blksize = blksize; curlun->blkbits = blkbits; curlun->ro = ro; curlun->filp = filp; curlun->file_length = size; curlun->num_sectors = num_sectors; LDBG(curlun, "open backing file: %s\n", filename); return 0; out: fput(filp); return rc; }
void *crt_file_open(char *path) { return filp_open(path, O_APPEND|O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR); }
//============================================================ // // Main Download furnction // // 1. Run mcsdl_download( pBinary[IdxNum], nBinary_length[IdxNum], IdxNum); // IdxNum : 0 (Master Chip Download) // IdxNum : 1 (2Chip Download) // // //============================================================ int mcsdl_download_binary_data(UINT8 master_dl_retry) { #if 0 //barring update int nRet; #ifdef FW_FROM_FILE struct file *filp; spinlock_t lock; loff_t pos; int ret = 0; long fw1_size = 0; long fw2_size = 0; mm_segment_t oldfs; unsigned char *fw_data1; unsigned char *fw_data2; oldfs = get_fs(); set_fs(get_ds()); filp = filp_open(MELFAS_FW1, O_RDONLY, 0); if (IS_ERR(filp)) { pr_err("file open error:%d\n", (s32)filp); return -1; } fw1_size = filp->f_path.dentry->d_inode->i_size; pr_info("Size of the file : %ld(bytes)\n", fw1_size); fw_data1 = kmalloc(fw1_size, GFP_KERNEL); memset(fw_data1, 0, fw1_size); pos = 0; memset(fw_data1, 0, fw1_size); ret = vfs_read(filp, (char __user *)fw_data1, fw1_size, &pos); if(ret != fw1_size) { pr_err("Failed to read file %s (ret = %d)\n", MELFAS_FW1, ret); kfree(fw_data1); filp_close(filp, current->files); return -1; } filp_close(filp, current->files); filp = filp_open(MELFAS_FW2, O_RDONLY, 0); if (IS_ERR(filp)) { pr_err("file open error:%d\n", (s32)filp); return -1; } fw2_size = filp->f_path.dentry->d_inode->i_size; pr_info("Size of the file : %ld(bytes)\n", fw2_size); fw_data2 = kmalloc(fw2_size, GFP_KERNEL); memset(fw_data2, 0, fw2_size); pos = 0; memset(fw_data2, 0, fw2_size); ret = vfs_read(filp, (char __user *)fw_data2, fw2_size, &pos); if(ret != fw2_size) { pr_err("Failed to read file %s (ret = %d)\n", MELFAS_FW2, ret); kfree(fw_data2); filp_close(filp, current->files); return -1; } filp_close(filp, current->files); set_fs(oldfs); spin_lock_init(&lock); spin_lock(&lock); #endif #if (CONFIG_MACH_JENA_HWREV == 0x0) MELFAS_binary = MELFAS_binary_HW00; MELFAS_binary_nLength = MELFAS_binary_nLength_HW00; #else if (board_hw_revision == 1) { MELFAS_binary = MELFAS_binary_HW01; MELFAS_binary_nLength = MELFAS_binary_nLength_HW01; } else { MELFAS_binary = MELFAS_binary_HW02; MELFAS_binary_nLength = MELFAS_binary_nLength_HW02; } #endif #if MELFAS_USE_PROTOCOL_COMMAND_FOR_DOWNLOAD melfas_send_download_enable_command(); mcsdl_delay(MCSDL_DELAY_100US); #endif MELFAS_DISABLE_BASEBAND_ISR(); // Disable Baseband touch interrupt ISR. MELFAS_DISABLE_WATCHDOG_TIMER_RESET(); // Disable Baseband watchdog timer //------------------------ // Run Download //------------------------ #ifdef FW_FROM_FILE if(MELFAS_ISP_DOWNLOAD || master_dl_retry) { nRet = mcsdl_download( (const UINT8*) fw_data1, (const UINT16)fw1_size, 0); if (nRet) goto fw_error; } #if MELFAS_2CHIP_DOWNLOAD_ENABLE nRet = mcsdl_download( (const UINT8*) fw_data2, (const UINT16)fw2_size, 1); if (nRet) goto fw_error; spin_unlock(&lock); #endif #else if(MELFAS_ISP_DOWNLOAD || master_dl_retry) { nRet = mcsdl_download( (const UINT8*) MELFAS_binary, (const UINT16)MELFAS_binary_nLength , 0); if (nRet) goto fw_error; } #if MELFAS_2CHIP_DOWNLOAD_ENABLE nRet = mcsdl_download( (const UINT8*) MELFAS_binary_2, (const UINT16)MELFAS_binary_nLength_2, 1); // Slave Binary data download if (nRet) goto fw_error; #endif #endif MELFAS_ROLLBACK_BASEBAND_ISR(); // Roll-back Baseband touch interrupt ISR. MELFAS_ROLLBACK_WATCHDOG_TIMER_RESET(); // Roll-back Baseband watchdog timer return 0; fw_error: mcsdl_erase_flash(0); mcsdl_erase_flash(1); #ifdef FW_FROM_FILE spin_unlock(&lock); #endif return nRet; #endif }
int dhd_customer_set_country(dhd_pub_t *dhd) { struct file *fp = NULL; char *filepath = "/data/.ccode.info"; char iovbuf[WL_EVENTING_MASK_LEN + 12] = {0}; char buffer[10] = {0}; int ret = 0; wl_country_t cspec; int buf_len = 0; char country_code[WLC_CNTRY_BUF_SZ]; int country_rev; int country_offset; int country_code_size; char country_rev_buf[WLC_CNTRY_BUF_SZ]; fp = filp_open(filepath, O_RDONLY, 0); if (IS_ERR(fp)) { DHD_ERROR(("%s: %s open failed\n", __FUNCTION__, filepath)); return -1; } else { if (kernel_read(fp, 0, buffer, sizeof(buffer))) { memset(&cspec, 0, sizeof(cspec)); memset(country_code, 0, sizeof(country_code)); memset(country_rev_buf, 0, sizeof(country_rev_buf)); country_offset = strcspn(buffer, " "); country_code_size = country_offset; if (country_offset != 0) { strncpy(country_code, buffer, country_offset); strncpy(country_rev_buf, buffer+country_offset+1, strlen(buffer) - country_code_size + 1); country_rev = bcm_atoi(country_rev_buf); buf_len = bcm_mkiovar("country", (char *)&cspec, sizeof(cspec), iovbuf, sizeof(iovbuf)); ret = dhd_wl_ioctl_cmd(dhd, WLC_GET_VAR, iovbuf, buf_len, FALSE, 0); memcpy((void *)&cspec, iovbuf, sizeof(cspec)); if (!ret) { DHD_ERROR(("%s: get country ccode:%s" " country_abrev:%s rev:%d \n", __FUNCTION__, cspec.ccode, cspec.country_abbrev, cspec.rev)); if ((strncmp(country_code, cspec.ccode, WLC_CNTRY_BUF_SZ) != 0) || (cspec.rev != country_rev)) { strncpy(cspec.country_abbrev, country_code, country_code_size); strncpy(cspec.ccode, country_code, country_code_size); cspec.rev = country_rev; DHD_ERROR(("%s: set country ccode:%s" "country_abrev:%s rev:%d\n", __FUNCTION__, cspec.ccode, cspec.country_abbrev, cspec.rev)); buf_len = bcm_mkiovar("country", (char *)&cspec, sizeof(cspec), iovbuf, sizeof(iovbuf)); ret = dhd_wl_ioctl_cmd(dhd, WLC_SET_VAR, iovbuf, buf_len, TRUE, 0); } } } else { DHD_ERROR(("%s: set country %s failed code \n", __FUNCTION__, country_code)); ret = -1; } } else { DHD_ERROR(("%s: Reading from the '%s' returns 0 bytes \n", __FUNCTION__, filepath)); ret = -1; } } if (fp) filp_close(fp, NULL); return ret; }
int fimc_is_ois_open_fw(struct fimc_is_core *core, char *name, u8 **buf) { int ret = 0; u32 size = 0; const struct firmware *fw_blob = NULL; static char fw_name[100]; struct file *fp = NULL; mm_segment_t old_fs; long nread; int fw_requested = 1; int retry_count = 0; fw_sdcard = false; old_fs = get_fs(); set_fs(KERNEL_DS); snprintf(fw_name, sizeof(fw_name), "%s%s", FIMC_IS_OIS_SDCARD_PATH, name); fp = filp_open(fw_name, O_RDONLY, 0); if (IS_ERR_OR_NULL(fp)) { err("failed to open SDCARD fw!!!"); goto request_fw; } fw_requested = 0; size = fp->f_path.dentry->d_inode->i_size; pr_info("start read sdcard, file path %s, size %d Bytes\n", fw_name, size); *buf = vmalloc(size); if (!(*buf)) { err("failed to allocate memory"); ret = -ENOMEM; goto p_err; } nread = vfs_read(fp, (char __user *)(*buf), size, &fp->f_pos); if (nread != size) { err("failed to read firmware file, %ld Bytes\n", nread); ret = -EIO; goto p_err; } memcpy(ois_pinfo.header_ver, *buf + OIS_BIN_HEADER, OIS_FW_HEADER_SIZE); memcpy(bootCode, *buf, OIS_BOOT_FW_SIZE); memcpy(progCode, *buf + OIS_BIN_LEN - OIS_PROG_FW_SIZE, OIS_PROG_FW_SIZE); fw_sdcard = true; if (OIS_BIN_LEN >= nread) { not_crc_bin = true; err("ois fw binary size = %ld.\n", nread); } request_fw: if (fw_requested) { snprintf(fw_name, sizeof(fw_name), "%s", name); set_fs(old_fs); retry_count = 3; ret = request_firmware(&fw_blob, fw_name, &core->companion->pdev->dev); while (--retry_count && ret == -EAGAIN) { err("request_firmware retry(count:%d)", retry_count); ret = request_firmware(&fw_blob, fw_name, &core->companion->pdev->dev); } if (ret) { err("request_firmware is fail(ret:%d)", ret); ret = -EINVAL; goto p_err; } if (!fw_blob) { err("fw_blob is NULL"); ret = -EINVAL; goto p_err; } if (!fw_blob->data) { err("fw_blob->data is NULL"); ret = -EINVAL; goto p_err; } size = fw_blob->size; *buf = vmalloc(size); if (!(*buf)) { err("failed to allocate memory"); ret = -ENOMEM; goto p_err; } memcpy((void *)(*buf), fw_blob->data, size); memcpy(ois_pinfo.header_ver, *buf + OIS_BIN_HEADER, OIS_FW_HEADER_SIZE); memcpy(bootCode, *buf, OIS_BOOT_FW_SIZE); memcpy(progCode, *buf + OIS_BIN_LEN - OIS_PROG_FW_SIZE, OIS_PROG_FW_SIZE); if (OIS_BIN_LEN >= size) { not_crc_bin = true; err("ois fw binary size = 0x%08x.\n", size); } pr_info("OIS firmware is loaded from Phone binary.\n"); } p_err: if (!fw_requested) { if (!IS_ERR_OR_NULL(fp)) { filp_close(fp, current->files); } set_fs(old_fs); } else { if (!IS_ERR_OR_NULL(fw_blob)) { release_firmware(fw_blob); } } return ret; }
int dhd_read_macaddr(struct dhd_info *dhd, struct ether_addr *mac) { struct file *fp = NULL; char macbuffer[18] = {0}; mm_segment_t oldfs = {0}; char randommac[3] = {0}; char buf[18] = {0}; char *filepath_efs = MACINFO_EFS; #ifdef CONFIG_TARGET_LOCALE_VZW char *nvfilepath = "/data/misc/wifi/.nvmac.info"; #else char *nvfilepath = NVMACINFO; #endif int ret = 0; fp = filp_open(filepath_efs, O_RDONLY, 0); if (IS_ERR(fp)) { start_readmac: /* File Doesn't Exist. Create and write mac addr. */ fp = filp_open(filepath_efs, O_RDWR | O_CREAT, 0666); if (IS_ERR(fp)) { DHD_ERROR(("[WIFI] %s: File open error\n", filepath_efs)); return -1; } oldfs = get_fs(); set_fs(get_ds()); /* Generating the Random Bytes for 3 last octects of the MAC address */ get_random_bytes(randommac, 3); sprintf(macbuffer, "%02X:%02X:%02X:%02X:%02X:%02X\n", 0x00, 0x12, 0x34, randommac[0], randommac[1], randommac[2]); DHD_ERROR(("[WIFI]The Random Generated MAC ID: %s\n", macbuffer)); if (fp->f_mode & FMODE_WRITE) { ret = fp->f_op->write(fp, (const char *)macbuffer, sizeof(macbuffer), &fp->f_pos); if (ret < 0) DHD_ERROR(("[WIFI]MAC address [%s] Failed to write into File: %s\n", macbuffer, filepath_efs)); else DHD_ERROR(("[WIFI]MAC address [%s] written into File: %s\n", macbuffer, filepath_efs)); } set_fs(oldfs); /* Reading the MAC Address from .mac.info file ( the existed file or just created file) */ ret = kernel_read(fp, 0, buf, 18); } else { /* Reading the MAC Address from .mac.info file( the existed file or just created file) */ ret = kernel_read(fp, 0, buf, 18); /* to prevent abnormal string display when mac address is displayed on the screen. */ buf[17] = '\0'; if (strncmp(buf, "00:00:00:00:00:00", 17) < 1) { DHD_ERROR(("goto start_readmac \r\n")); filp_close(fp, NULL); goto start_readmac; } } if (ret) sscanf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", (unsigned int *)&(mac->octet[0]), (unsigned int *)&(mac->octet[1]), (unsigned int *)&(mac->octet[2]), (unsigned int *)&(mac->octet[3]), (unsigned int *)&(mac->octet[4]), (unsigned int *)&(mac->octet[5])); else DHD_ERROR(("dhd_bus_start: Reading from the '%s' returns 0 bytes\n", filepath_efs)); if (fp) filp_close(fp, NULL); /* Writing Newly generated MAC ID to the Dongle */ if (_dhd_set_mac_address(dhd, 0, mac) == 0) DHD_INFO(("dhd_bus_start: MACID is overwritten\n")); else DHD_ERROR(("dhd_bus_start: _dhd_set_mac_address() failed\n")); return 0; }
static void _DumpCommand( IN gckCOMMAND Command, IN gctPOINTER Pointer, IN gctSIZE_T Bytes ) { gctUINT32_PTR data = (gctUINT32_PTR) Pointer; gctUINT32 address; #ifdef MRVL_DUMP_COMMAND struct file* pDump_Cmd = 0; mm_segment_t old_fs; pDump_Cmd = filp_open("./dump_cmd.bin",O_WRONLY | O_CREAT | O_APPEND,0644); if (pDump_Cmd == 0) { gcmkPRINT("open file dump_cmd.bin failed!\n"); return; } old_fs = get_fs(); set_fs(KERNEL_DS); pDump_Cmd->f_op->write(pDump_Cmd,Pointer,Bytes,&pDump_Cmd->f_pos); set_fs(old_fs); filp_close(pDump_Cmd,0); return; #endif gckOS_GetPhysicalAddress(Command->os, Pointer, &address); gcmkPRINT("@[kernel.command %08X %08X", address, Bytes); while (Bytes >= 8*4) { gcmkPRINT(" %08X %08X %08X %08X %08X %08X %08X %08X", data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]); data += 8; Bytes -= 32; } switch (Bytes) { case 7*4: gcmkPRINT(" %08X %08X %08X %08X %08X %08X %08X", data[0], data[1], data[2], data[3], data[4], data[5], data[6]); break; case 6*4: gcmkPRINT(" %08X %08X %08X %08X %08X %08X", data[0], data[1], data[2], data[3], data[4], data[5]); break; case 5*4: gcmkPRINT(" %08X %08X %08X %08X %08X", data[0], data[1], data[2], data[3], data[4]); break; case 4*4: gcmkPRINT(" %08X %08X %08X %08X", data[0], data[1], data[2], data[3]); break; case 3*4: gcmkPRINT(" %08X %08X %08X", data[0], data[1], data[2]); break; case 2*4: gcmkPRINT(" %08X %08X", data[0], data[1]); break; case 1*4: gcmkPRINT(" %08X", data[0]); break; } gcmkPRINT("] -- command"); }
int dhd_write_rdwr_macaddr(struct ether_addr *mac) { char *filepath_data = MACINFO; char *filepath_efs = MACINFO_EFS; struct file *fp_mac = NULL; char buf[18] = {0}; mm_segment_t oldfs = {0}; int ret = -1; if ((g_imac_flag != MACADDR_COB) && (g_imac_flag != MACADDR_MOD)) return 0; sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X\n", mac->octet[0], mac->octet[1], mac->octet[2], mac->octet[3], mac->octet[4], mac->octet[5]); /* /data/.mac.info will be created */ fp_mac = filp_open(filepath_data, O_RDWR | O_CREAT, 0666); if (IS_ERR(fp_mac)) { DHD_ERROR(("[WIFI] %s: File open error\n", filepath_data)); return -1; } else { oldfs = get_fs(); set_fs(get_ds()); if (fp_mac->f_mode & FMODE_WRITE) { ret = fp_mac->f_op->write(fp_mac, (const char *)buf, sizeof(buf), &fp_mac->f_pos); if (ret < 0) DHD_ERROR(("[WIFI] Mac address [%s] Failed" " to write into File: %s\n", buf, filepath_data)); else DHD_INFO(("[WIFI] Mac address [%s] written" " into File: %s\n", buf, filepath_data)); } set_fs(oldfs); filp_close(fp_mac, NULL); } /* /efs/wifi/.mac.info will be created */ fp_mac = filp_open(filepath_efs, O_RDWR | O_CREAT, 0666); if (IS_ERR(fp_mac)) { DHD_ERROR(("[WIFI] %s: File open error\n", filepath_efs)); return -1; } else { oldfs = get_fs(); set_fs(get_ds()); if (fp_mac->f_mode & FMODE_WRITE) { ret = fp_mac->f_op->write(fp_mac, (const char *)buf, sizeof(buf), &fp_mac->f_pos); if (ret < 0) DHD_ERROR(("[WIFI] Mac address [%s] Failed" " to write into File: %s\n", buf, filepath_efs)); else DHD_INFO(("[WIFI] Mac address [%s] written" " into File: %s\n", buf, filepath_efs)); } set_fs(oldfs); filp_close(fp_mac, NULL); } return 0; }
static irqreturn_t chrif_int(int irq, void *dev_id) { int err; RING_IDX rc, rp; int more_to_do, notify; chrif_request_t req; chrif_response_t resp; printk(KERN_INFO "\n------------------------------start response-------------------------------------"); printk(KERN_DEBUG "\nxen: Dom0: chrif_int called with dev_id=%x info=%x", (unsigned int)dev_id, (unsigned int) &info); rc = info.ring.req_cons; rp = info.ring.sring->req_prod; printk(KERN_DEBUG "\nxen: Dom0: rc = %d rp = %d", rc, rp); while (rc != rp) { if (RING_REQUEST_CONS_OVERFLOW(&info.ring, rc)) break; memcpy(&req, RING_GET_REQUEST(&info.ring, rc), sizeof(req)); resp.id = req.id; resp.operation = req.operation; resp.status = req.status + 1; printk(KERN_DEBUG "\nxen: Dom0: Recvd at IDX-%d: id = %d, op=%d, status=%d", rc, req.id, req.operation, req.status); info.ring.req_cons = ++rc; barrier(); printk(KERN_DEBUG "\nxen: Dom0: operation: %s", op_name(resp.operation)); switch(resp.operation) { case CHRIF_OP_OPEN: info.chrif_filp = filp_open(DEVICE_PATH, O_RDWR, 0); printk(KERN_DEBUG "\nxen: dom0: response open"); break; case CHRIF_OP_READ:{ int cnt; resp.rdwr.len = req.rdwr.len; cnt = resp.rdwr.len/4096; printk(KERN_DEBUG "\nxen: dom0: read %d times", cnt); memset(op_page->addr, 0, 4096); if(rd_time == 0){ old_fs = get_fs(); set_fs(get_ds()); //read data from device to page err =info.chrif_filp->f_op->read(info.chrif_filp, block_buf, resp.rdwr.len, &info.chrif_filp->f_pos); set_fs(old_fs); if(err < 0) printk(KERN_DEBUG "\nxen: Dom0: read %u bytes error", resp.rdwr.len); } memcpy(op_page->addr, block_buf+rd_time*4096, 4096); rd_time++; if(rd_time == cnt){ rd_time = 0; memset(block_buf, 0, resp.rdwr.len); } printk(KERN_DEBUG "\nxen: dom0: response read"); break; } case CHRIF_OP_WRITE:{ int count; resp.rdwr.len = req.rdwr.len; count = resp.rdwr.len/4096; printk(KERN_DEBUG "\nxen: dom0: write %d times", count); //if(count == 0){ block_buf = (char *)kmalloc(resp.rdwr.len, GFP_KERNEL);} memcpy(block_buf+wr_time*4096, op_page->addr, 4096); wr_time++; if(wr_time == count){ old_fs = get_fs(); set_fs(get_ds()); //write data from page to device err = info.chrif_filp->f_op->write(info.chrif_filp, block_buf, resp.rdwr.len, &info.chrif_filp->f_pos); set_fs(old_fs); wr_time = 0; if(err < 0) printk(KERN_DEBUG "\nxen: Dom0: write %u bytes error", resp.rdwr.len); memset(block_buf, 0, resp.rdwr.len); } //kfree(block_buf); printk(KERN_DEBUG "\nxen: dom0: response write"); break; } case CHRIF_OP_IOCTL:{ resp.ioc_parm.cmd = req.ioc_parm.cmd; switch(resp.ioc_parm.cmd){ case PDMA_IOC_START_DMA:{ old_fs = get_fs(); set_fs(get_ds()); err = info.chrif_filp->f_op->unlocked_ioctl(info.chrif_filp, PDMA_IOC_START_DMA, NULL); set_fs(old_fs); if(err){ printk(KERN_DEBUG "\nxen: Dom0: start-dma ioctl failed"); resp.status = 0; }else printk(KERN_DEBUG "\nxen: Dom0: start-dma ioctl success"); //err = call_ioctl(info.chrif_filp, PDMA_IOC_START_DMA, NULL); get_block_info(); break; } case PDMA_IOC_STOP_DMA:{ //err = call_ioctl(info.chrif_filp, PDMA_IOC_STOP_DMA, NULL); old_fs = get_fs(); set_fs(get_ds()); err = info.chrif_filp->f_op->unlocked_ioctl(info.chrif_filp, PDMA_IOC_STOP_DMA, NULL); set_fs(old_fs); if(err){ printk(KERN_DEBUG "\nxen: Dom0: stop-dma ioctl failed"); resp.status = 0; }else printk(KERN_DEBUG "\nxen: Dom0: stop-dma ioctl success"); break; } case PDMA_IOC_INFO:{ struct pdma_info pdma_info; //err = call_ioctl(info.chrif_filp, PDMA_IOC_INFO, (unsigned long)&pdma_info); old_fs = get_fs(); set_fs(get_ds()); err = info.chrif_filp->f_op->unlocked_ioctl(info.chrif_filp, PDMA_IOC_INFO, (unsigned long)&pdma_info); set_fs(old_fs); if(err){ printk(KERN_DEBUG "\nxen: Dom0: info ioctl failed"); resp.status = 0; }else printk(KERN_DEBUG "\nxen: Dom0: info ioctl success"); resp.ioc_parm.info = pdma_info; break; } case PDMA_IOC_STAT:{ struct pdma_stat pdma_stat; //err = call_ioctl(info.chrif_filp, PDMA_IOC_STAT, (unsigned long)&pdma_stat); old_fs = get_fs(); set_fs(get_ds()); err = info.chrif_filp->f_op->unlocked_ioctl(info.chrif_filp, PDMA_IOC_STAT, (unsigned long)&pdma_stat); set_fs(old_fs); if(err){ printk(KERN_DEBUG "\nxen: Dom0: stat ioctl failed"); resp.status = 0; }else printk(KERN_DEBUG "\nxen: Dom0: stat ioctl success"); resp.ioc_parm.stat = pdma_stat; break; } case PDMA_IOC_RW_REG:{ struct pdma_rw_reg ctrl = req.ioc_parm.ctrl; //err = call_ioctl(info.chrif_filp, PDMA_IOC_RW_REG, (unsigned long)&ctrl); old_fs = get_fs(); set_fs(get_ds()); err = info.chrif_filp->f_op->unlocked_ioctl(info.chrif_filp, PDMA_IOC_RW_REG, (unsigned long)&ctrl); set_fs(old_fs); if(err){ printk(KERN_DEBUG "\nxen: Dom0: rw-reg ioctl failed"); resp.status = 0; }else printk(KERN_DEBUG "\nxen: Dom0: rw-reg ioctl success"); resp.ioc_parm.ctrl = ctrl; break; } default: printk(KERN_DEBUG "\nxen: Dom0: unknow the operation"); break; } printk(KERN_INFO "\nxen: Dom0: response ioctl"); break; } case CHRIF_OP_CLOSE: filp_close(info.chrif_filp, NULL); printk(KERN_INFO "\nxen: Dom0: response close"); break; default: printk(KERN_DEBUG "\nxen: Dom0: unknow the operation"); break; } memcpy(RING_GET_RESPONSE(&info.ring, info.ring.rsp_prod_pvt), &resp, sizeof(resp)); info.ring.rsp_prod_pvt++; //put response and check whether or not notify domU RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&info.ring, notify); if (info.ring.rsp_prod_pvt == info.ring.req_cons) { RING_FINAL_CHECK_FOR_REQUESTS(&info.ring, more_to_do); } else if (RING_HAS_UNCONSUMED_REQUESTS(&info.ring)) { more_to_do = 1; } if (notify) { printk(KERN_DEBUG "\nxen:dom0:send notify to domu"); notify_remote_via_irq(info.irq); } } return IRQ_HANDLED; }
int dhd_check_rdwr_macaddr(struct dhd_info *dhd, dhd_pub_t *dhdp, struct ether_addr *mac) { struct file *fp_mac = NULL; struct file *fp_nvm = NULL; char macbuffer[18] = {0}; char randommac[3] = {0}; char buf[18] = {0}; char *filepath_data = MACINFO; char *filepath_efs = MACINFO_EFS; #ifdef CONFIG_TARGET_LOCALE_NA char *nvfilepath = "/data/misc/wifi/.nvmac.info"; #else char *nvfilepath = NVMACINFO; #endif char cur_mac[128] = {0}; char dummy_mac[ETHER_ADDR_LEN] = {0x00, 0x90, 0x4C, 0xC5, 0x12, 0x38}; char cur_macbuffer[18] = {0}; int ret = -1; g_imac_flag = MACADDR_NONE; fp_nvm = filp_open(nvfilepath, O_RDONLY, 0); if (IS_ERR(fp_nvm)) { /* file does not exist */ /* Create the .nvmac.info */ fp_nvm = filp_open(nvfilepath, O_RDWR | O_CREAT, 0666); if (!IS_ERR(fp_nvm)) filp_close(fp_nvm, NULL); /* read MAC Address */ strcpy(cur_mac, "cur_etheraddr"); ret = dhd_wl_ioctl_cmd(dhdp, WLC_GET_VAR, cur_mac, sizeof(cur_mac), 0, 0); if (ret < 0) { DHD_ERROR(("Current READ MAC error \r\n")); memset(cur_mac, 0, ETHER_ADDR_LEN); return -1; } else { DHD_ERROR(("MAC (OTP) : " "[%02X:%02X:%02X:%02X:%02X:%02X] \r\n", cur_mac[0], cur_mac[1], cur_mac[2], cur_mac[3], cur_mac[4], cur_mac[5])); } sprintf(cur_macbuffer, "%02X:%02X:%02X:%02X:%02X:%02X\n", cur_mac[0], cur_mac[1], cur_mac[2], cur_mac[3], cur_mac[4], cur_mac[5]); fp_mac = filp_open(filepath_data, O_RDONLY, 0); if (IS_ERR(fp_mac)) { /* file does not exist */ /* read mac is the dummy mac (00:90:4C:C5:12:38) */ if (memcmp(cur_mac, dummy_mac, ETHER_ADDR_LEN) == 0) g_imac_flag = MACADDR_MOD_RANDOM; else if (strncmp(buf, "00:00:00:00:00:00", 17) == 0) g_imac_flag = MACADDR_MOD_RANDOM; else g_imac_flag = MACADDR_MOD; } else { int is_zeromac; ret = kernel_read(fp_mac, 0, buf, 18); filp_close(fp_mac, NULL); buf[17] = '\0'; is_zeromac = strncmp(buf, "00:00:00:00:00:00", 17); DHD_ERROR(("MAC (FILE): [%s] [%d] \r\n", buf, is_zeromac)); if (is_zeromac == 0) { DHD_ERROR(("Zero MAC detected." " Trying Random MAC.\n")); g_imac_flag = MACADDR_MOD_RANDOM; } else { sscanf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", (unsigned int *)&(mac->octet[0]), (unsigned int *)&(mac->octet[1]), (unsigned int *)&(mac->octet[2]), (unsigned int *)&(mac->octet[3]), (unsigned int *)&(mac->octet[4]), (unsigned int *)&(mac->octet[5])); /* current MAC address is same as previous one */ if (memcmp(cur_mac, mac->octet, ETHER_ADDR_LEN) == 0) { g_imac_flag = MACADDR_NONE; } else { /* change MAC address */ if (_dhd_set_mac_address(dhd, 0, mac) == 0) { DHD_INFO(("%s: MACID is" " overwritten\n", __FUNCTION__)); g_imac_flag = MACADDR_MOD; } else { DHD_ERROR(("%s: " "_dhd_set_mac_address()" " failed\n", __FUNCTION__)); g_imac_flag = MACADDR_NONE; } } } } fp_mac = filp_open(filepath_efs, O_RDONLY, 0); if (IS_ERR(fp_mac)) { /* file does not exist */ /* read mac is the dummy mac (00:90:4C:C5:12:38) */ if (memcmp(cur_mac, dummy_mac, ETHER_ADDR_LEN) == 0) g_imac_flag = MACADDR_MOD_RANDOM; else if (strncmp(buf, "00:00:00:00:00:00", 17) == 0) g_imac_flag = MACADDR_MOD_RANDOM; else g_imac_flag = MACADDR_MOD; } else { int is_zeromac; ret = kernel_read(fp_mac, 0, buf, 18); filp_close(fp_mac, NULL); buf[17] = '\0'; is_zeromac = strncmp(buf, "00:00:00:00:00:00", 17); DHD_ERROR(("MAC (FILE): [%s] [%d] \r\n", buf, is_zeromac)); if (is_zeromac == 0) { DHD_ERROR(("Zero MAC detected." " Trying Random MAC.\n")); g_imac_flag = MACADDR_MOD_RANDOM; } else { sscanf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", (unsigned int *)&(mac->octet[0]), (unsigned int *)&(mac->octet[1]), (unsigned int *)&(mac->octet[2]), (unsigned int *)&(mac->octet[3]), (unsigned int *)&(mac->octet[4]), (unsigned int *)&(mac->octet[5])); /* current MAC address is same as previous one */ if (memcmp(cur_mac, mac->octet, ETHER_ADDR_LEN) == 0) { g_imac_flag = MACADDR_NONE; } else { /* change MAC address */ if (_dhd_set_mac_address(dhd, 0, mac) == 0) { DHD_INFO(("%s: MACID is" " overwritten\n", __FUNCTION__)); g_imac_flag = MACADDR_MOD; } else { DHD_ERROR(("%s: " "_dhd_set_mac_address()" " failed\n", __FUNCTION__)); g_imac_flag = MACADDR_NONE; } } } } } else { /* COB type. only COB. */ /* Reading the MAC Address from .nvmac.info file * (the existed file or just created file) */ ret = kernel_read(fp_nvm, 0, buf, 18); /* to prevent abnormal string display when mac address * is displayed on the screen. */ buf[17] = '\0'; DHD_ERROR(("Read MAC : [%s] [%d] \r\n", buf, strncmp(buf, "00:00:00:00:00:00", 17))); if ((buf[0] == '\0') || (strncmp(buf, "00:00:00:00:00:00", 17) == 0)) { g_imac_flag = MACADDR_COB_RANDOM; } else { sscanf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", (unsigned int *)&(mac->octet[0]), (unsigned int *)&(mac->octet[1]), (unsigned int *)&(mac->octet[2]), (unsigned int *)&(mac->octet[3]), (unsigned int *)&(mac->octet[4]), (unsigned int *)&(mac->octet[5])); /* Writing Newly generated MAC ID to the Dongle */ if (_dhd_set_mac_address(dhd, 0, mac) == 0) { DHD_INFO(("%s: MACID is overwritten\n", __FUNCTION__)); g_imac_flag = MACADDR_COB; } else { DHD_ERROR(("%s: _dhd_set_mac_address()" " failed\n", __FUNCTION__)); } } filp_close(fp_nvm, NULL); } if ((g_imac_flag == MACADDR_COB_RANDOM) || (g_imac_flag == MACADDR_MOD_RANDOM)) { get_random_bytes(randommac, 3); sprintf(macbuffer, "%02X:%02X:%02X:%02X:%02X:%02X\n", 0x60, 0xd0, 0xa9, randommac[0], randommac[1], randommac[2]); DHD_ERROR(("[WIFI] The Random Generated MAC ID : %s\n", macbuffer)); sscanf(macbuffer, "%02X:%02X:%02X:%02X:%02X:%02X", (unsigned int *)&(mac->octet[0]), (unsigned int *)&(mac->octet[1]), (unsigned int *)&(mac->octet[2]), (unsigned int *)&(mac->octet[3]), (unsigned int *)&(mac->octet[4]), (unsigned int *)&(mac->octet[5])); if (_dhd_set_mac_address(dhd, 0, mac) == 0) { DHD_INFO(("%s: MACID is overwritten\n", __FUNCTION__)); g_imac_flag = MACADDR_COB; } else { DHD_ERROR(("%s: _dhd_set_mac_address() failed\n", __FUNCTION__)); } } return 0; }
void ssp_dump_task(struct work_struct *work) { #if CONFIG_SEC_DEBUG struct ssp_big *big; struct file *dump_file; struct ssp_msg *msg; char *buffer; char strFilePath[100]; struct timeval cur_time; mm_segment_t fs; int buf_len, packet_len, residue; int iRet = 0, index = 0, iRetTrans = 0, iRetWrite = 0; big = container_of(work, struct ssp_big, work); ssp_errf("start ssp dumping (%d)(%d)", big->data->bMcuDumpMode, big->data->uDumpCnt); big->data->uDumpCnt++; wake_lock(&big->data->ssp_wake_lock); fs = get_fs(); set_fs(get_ds()); if (big->data->bMcuDumpMode == true) { do_gettimeofday(&cur_time); #ifdef CONFIG_SENSORS_SSP_ENG snprintf(strFilePath, sizeof(strFilePath), "%s%d.dump", DUMP_FILE_PATH, (int)cur_time.tv_sec); dump_file = filp_open(strFilePath, O_RDWR | O_CREAT | O_APPEND, 0660); #else snprintf(strFilePath, sizeof(strFilePath), "%s.dump", DUMP_FILE_PATH); dump_file = filp_open(strFilePath, O_RDWR | O_CREAT | O_TRUNC, 0660); #endif if (IS_ERR(dump_file)) { ssp_errf("Can't open dump file"); set_fs(fs); iRet = PTR_ERR(dump_file); wake_unlock(&big->data->ssp_wake_lock); kfree(big); return; } } else { dump_file = NULL; } buf_len = big->length > DATA_PACKET_SIZE ? DATA_PACKET_SIZE : big->length; buffer = kzalloc(buf_len, GFP_KERNEL); residue = big->length; while (residue > 0) { packet_len = residue > DATA_PACKET_SIZE ? DATA_PACKET_SIZE : residue; msg = kzalloc(sizeof(*msg), GFP_KERNEL); msg->cmd = MSG2SSP_AP_GET_BIG_DATA; msg->length = packet_len; msg->options = AP2HUB_READ | (index++ << SSP_INDEX); msg->data = big->addr; msg->buffer = buffer; msg->free_buffer = 0; iRetTrans = ssp_spi_sync(big->data, msg, 1000); if (iRetTrans != SUCCESS) { ssp_errf("Fail to receive data %d (%d)", iRetTrans, residue); break; } if (big->data->bMcuDumpMode == true) { iRetWrite = vfs_write(dump_file, (char __user *)buffer, packet_len, &dump_file->f_pos); if (iRetWrite < 0) { ssp_errf("Can't write dump to file"); break; } } residue -= packet_len; } if (big->data->bMcuDumpMode == true) { if (iRetTrans != SUCCESS || iRetWrite < 0) { /* error case */ char FAILSTRING[100]; snprintf(FAILSTRING, sizeof(FAILSTRING), "FAIL OCCURED(%d)(%d)(%d)", iRetTrans, iRetWrite, big->length); vfs_write(dump_file, (char __user *)FAILSTRING, strlen(FAILSTRING), &dump_file->f_pos); } filp_close(dump_file, current->files); } big->data->bDumping = false; set_fs(fs); wake_unlock(&big->data->ssp_wake_lock); kfree(buffer); kfree(big); #endif ssp_errf("done"); }
/* * Function definition for sys_xcrypt. * This function encrypts/decrypts files using AES Block Cipher algorithm using CBC mode. */ asmlinkage int sys_xcrypt( const char * const infile, const char * const opfile, const char * const keybuf, const int keylen, const short int flags ) { const char algo[] = "cbc(aes)"; char *ipBuf = NULL, *opBuf = NULL, *iv = NULL, *inFile = NULL, *opFile = NULL, *keyBuf = NULL; int errno = 0, ret = 0; int actReadLen = 0, actWriteLen = 0, padLen = 0, blkSiz = 0, ipFileLen = 0, opFileLen = 0, keyLen = 0; int delOpFile = 0, prmbLen = 0, idx = 0; unsigned int fileSize = 0, factor = 1; struct file *inFilePtr = NULL, *opFilePtr = NULL; struct crypto_blkcipher *tfm = NULL; struct blkcipher_desc desc; struct scatterlist sg[2]; struct dentry *tmpDentry; struct inode *tmpInode = NULL; mm_segment_t oldfs; /* Check for NULL pointers or invalid values */ if( ( NULL == infile ) || ( NULL == opfile ) || ( NULL == keybuf ) || ( ( _FLAG_ENCRYPT_ != flags ) && ( _FLAG_DECRYPT_ != flags ) ) ) { printk( KERN_ALERT "Invalid I/P" ); errno = -EINVAL; goto OUT_OK; } /* Verify if all the pointers belong to the user's own address space */ ret = access_ok( VERIFY_READ, infile, 0 ); if( !ret ) { printk( KERN_ALERT "Invalid pointer to I/P file passed as argument" ); errno = -EFAULT; goto OUT_OK; } ret = access_ok( VERIFY_READ, opfile, 0 ); if( !ret ) { printk( KERN_ALERT "Invalid pointer to O/P file passed as argument" ); errno = -EFAULT; goto OUT_OK; } ret = access_ok( VERIFY_READ, keybuf, 0 ); if( !ret ) { printk( KERN_ALERT "Invalid pointer to Password passed as argument" ); errno = -EFAULT; goto OUT_OK; } /* Find out the length of the i/p buffers */ ipFileLen = strlen_user( infile ); opFileLen = strlen_user( opfile ); keyLen = strlen_user( keybuf ); /* Allocate buffers to copy i/p arguments from user space to kernel space */ inFile = kmalloc( ipFileLen, GFP_KERNEL ); if( NULL == inFile ) { errno = -ENOMEM; goto OUT_OK; } else { ret = strncpy_from_user( inFile, infile, ipFileLen ); if( ret < 0 ) { errno = ret; goto OUT_IP; } } opFile = kmalloc( opFileLen, GFP_KERNEL ); if( NULL == opFile ) { errno = -ENOMEM; goto OUT_IP; } else { ret = strncpy_from_user( opFile, opfile, opFileLen ); if( ret < 0 ) { errno = ret; goto OUT_IP; } } keyBuf = kmalloc( keyLen, GFP_KERNEL ); if( NULL == keyBuf ) { errno = -ENOMEM; goto OUT_IP; } else { ret = strncpy_from_user( keyBuf, keybuf, keyLen ); if( ret < 0 ) { errno = ret; goto OUT_IP; } } /* Open I/P file. It will report error in case of non-existing file and bad permissions but not bad owner */ inFilePtr = filp_open( inFile, O_RDONLY, 0 ); if ( !inFilePtr || IS_ERR( inFilePtr ) ) { errno = (int)PTR_ERR( inFilePtr ); printk( KERN_ALERT "Error opening i/p file: %d\n", errno ); inFilePtr = NULL; goto OUT_IP; } /* Check if the file is a regular file or not */ if( !S_ISREG( inFilePtr->f_path.dentry->d_inode->i_mode ) ) { printk( KERN_ALERT "Error as file is not a regular one" ); errno = -EBADF; goto OUT_FILE; } /* Check if the I/p file and the process owner match */ if( ( current->real_cred->uid != inFilePtr->f_path.dentry->d_inode->i_uid ) && ( current->real_cred->uid != 0 ) ) { printk( KERN_ALERT "Error as owner of file and process does not match" ); errno = -EACCES; goto OUT_FILE; } /* Open O/P file with error handling */ opFilePtr = filp_open( opFile, O_WRONLY | O_CREAT | O_EXCL, 0 ); if ( !opFilePtr || IS_ERR( opFilePtr ) ) { errno = (int)PTR_ERR( opFilePtr ); printk( KERN_ALERT "Error opening o/p file: %d\n", errno ); opFilePtr = NULL; goto OUT_FILE; } /* * Check if the infile and opfile point to the same file * If they reside on the different file partition and have same name then it should be allowed else not */ if( ( inFilePtr->f_path.dentry->d_inode->i_sb == opFilePtr->f_path.dentry->d_inode->i_sb ) && ( inFilePtr->f_path.dentry->d_inode->i_ino == opFilePtr->f_path.dentry->d_inode->i_ino ) ) { printk( KERN_ALERT "I/p and O/p file cannot be same" ); errno = -EINVAL; goto OUT_FILE; } /* Set the o/p file permission to i/p file */ opFilePtr->f_path.dentry->d_inode->i_mode = inFilePtr->f_path.dentry->d_inode->i_mode; /* Set the file position to the beginning of the file */ inFilePtr->f_pos = 0; opFilePtr->f_pos = 0; /* Allocate buffer to read data into and to write data to. For performance reasons, set its size equal to PAGE_SIZE */ ipBuf = kmalloc( PAGE_SIZE, GFP_KERNEL ); if( NULL == ipBuf ) { errno = -ENOMEM; goto OUT_FILE; } memset( ipBuf, _NULL_CHAR_, PAGE_SIZE ); opBuf = kmalloc( PAGE_SIZE, GFP_KERNEL ); if( NULL == opBuf ) { errno = -ENOMEM; goto OUT_DATA_PAGE; } memset( opBuf, _NULL_CHAR_, PAGE_SIZE ); /* Allocate tfm */ tfm = crypto_alloc_blkcipher( algo, 0, CRYPTO_ALG_ASYNC ); if ( NULL == tfm ) { printk( KERN_ALERT "Failed to load transform for %s: %ld\n", algo, PTR_ERR( tfm ) ); errno = -EINVAL; goto OUT_DATA_PAGE; } /* Initialize desc */ desc.tfm = tfm; desc.flags = 0; ret = crypto_blkcipher_setkey( tfm, keybuf, keylen ); if( ret ) { printk( "Setkey() failed. Flags=%x\n", crypto_blkcipher_get_flags( tfm ) ); errno = -EINVAL; goto OUT_CIPHER; } /* Initialize sg structure */ FILL_SG( &sg[0], ipBuf, PAGE_SIZE ); FILL_SG( &sg[1], opBuf, PAGE_SIZE ); /* Get the block size */ blkSiz = ((tfm->base).__crt_alg)->cra_blocksize; /* Initialize IV */ iv = kmalloc( blkSiz, GFP_KERNEL ); if( NULL == iv ) { errno = -ENOMEM; goto OUT_CIPHER; } memset( iv, _NULL_CHAR_, blkSiz ); crypto_blkcipher_set_iv( tfm, iv, crypto_blkcipher_ivsize( tfm ) ); /* Store the key and file size in encrypted form in the preamble */ switch( flags ) { case _FLAG_ENCRYPT_: memcpy( ipBuf, keybuf, keylen ); prmbLen = keylen; fileSize = (unsigned int)inFilePtr->f_path.dentry->d_inode->i_size; while( fileSize ) { ipBuf[ prmbLen + idx ] = fileSize % 10; fileSize /= 10; ++idx; } prmbLen += idx; #ifdef _DEBUG_ printk( KERN_ALERT "idx=%d prmbLen=%d\n", idx, prmbLen ); #endif memset( ipBuf + prmbLen, _ETX_, _UL_MAX_SIZE_ - idx ); prmbLen += ( _UL_MAX_SIZE_ - idx ); #ifdef _DEBUG_ printk( KERN_ALERT "prmbLen=%d\n", prmbLen ); #endif padLen = blkSiz - ( prmbLen % blkSiz ); memset( ipBuf + prmbLen, _ETX_, padLen ); prmbLen += padLen; #ifdef _DEBUG_ printk( KERN_ALERT "padLen=%d prmbLen=%d\n", padLen, prmbLen ); #endif ret = crypto_blkcipher_encrypt( &desc, &sg[1], &sg[0], prmbLen ); if (ret) { printk( KERN_ALERT "Encryption failed. Flags=0x%x\n", tfm->base.crt_flags ); delOpFile = 1; goto OUT_IV; } oldfs = get_fs(); set_fs( KERNEL_DS ); opFilePtr->f_op->write( opFilePtr, opBuf, prmbLen, &opFilePtr->f_pos ); /* Reset the address space to user one */ set_fs( oldfs ); break; case _FLAG_DECRYPT_: /* Set the address space to kernel one */ oldfs = get_fs(); set_fs( KERNEL_DS ); prmbLen = keylen + _UL_MAX_SIZE_; padLen = blkSiz - ( prmbLen % blkSiz ); prmbLen += padLen; #ifdef _DEBUG_ printk( KERN_ALERT "padLen=%d prmbLen=%d\n", padLen, prmbLen ); #endif actReadLen = inFilePtr->f_op->read( inFilePtr, ipBuf, prmbLen, &inFilePtr->f_pos ); if( actReadLen != prmbLen ) { printk( KERN_ALERT "Requested number of bytes for preamble are lesser" ); delOpFile = 1; goto OUT_IV; } #ifdef _DEBUG_ printk( KERN_ALERT "actReadLen=%d\n", actReadLen ); #endif /* Reset the address space to user one */ set_fs( oldfs ); ret = crypto_blkcipher_decrypt( &desc, &sg[1], &sg[0], prmbLen ); if (ret) { printk( KERN_ALERT "Decryption failed. Flags=0x%x\n", tfm->base.crt_flags ); delOpFile = 1; goto OUT_IV; } ret = memcmp( keybuf, opBuf, keylen ); if( ret ) { printk( "Wrong password entered." ); errno = -EKEYREJECTED; goto OUT_IV; } idx = 0; fileSize = 0; while( opBuf[ keylen + idx ] != _ETX_ ) { fileSize += opBuf[ keylen + idx ] * factor; factor *= 10; ++idx; } #ifdef _DEBUG_ printk( KERN_ALERT "idx=%d fileSize=%u\n", idx, fileSize ); #endif break; } /* Read file till the file pointer reaches to the EOF */ while( inFilePtr->f_pos < inFilePtr->f_path.dentry->d_inode->i_size ) { /* Initialize it to NULL char */ memset( ipBuf, _NULL_CHAR_, PAGE_SIZE ); memset( opBuf, _NULL_CHAR_, PAGE_SIZE ); /* Set the address space to kernel one */ oldfs = get_fs(); set_fs( KERNEL_DS ); actReadLen = inFilePtr->f_op->read( inFilePtr, ipBuf, PAGE_SIZE, &inFilePtr->f_pos ); /* Reset the address space to user one */ set_fs( oldfs ); /* As per the i/p flag, do encryption/decryption */ switch( flags ) { case _FLAG_ENCRYPT_: /* For encryption ensure padding as per the block size */ #ifdef _DEBUG_ printk( KERN_ALERT "Bytes read from I/P file ::%d::\n", actReadLen ); #endif if( actReadLen % blkSiz ) { padLen = blkSiz - ( actReadLen % blkSiz ); memset( ipBuf + actReadLen, _ETX_, padLen ); actReadLen += padLen; } #ifdef _DEBUG_ printk( KERN_ALERT "Pad Length ::%d::\n", padLen ); printk( KERN_ALERT "Data read from I/P file ::%s::\n", ipBuf ); #endif /* Encrypt the data */ ret = crypto_blkcipher_encrypt( &desc, &sg[1], &sg[0], PAGE_SIZE ); if (ret) { printk( KERN_ALERT "Encryption failed. Flags=0x%x\n", tfm->base.crt_flags ); delOpFile = 1; goto OUT_IV; } break; case _FLAG_DECRYPT_: /* Decrypt the data */ ret = crypto_blkcipher_decrypt( &desc, &sg[1], &sg[0], PAGE_SIZE ); if (ret) { printk( KERN_ALERT "Decryption failed. Flags=0x%x\n", tfm->base.crt_flags ); delOpFile = 1; goto OUT_IV; } #ifdef _DEBUG_ printk( KERN_ALERT "Bytes read from I/P file ::%d::\n", actReadLen ); #endif while( _ETX_ == opBuf[ actReadLen - 1 ] ) { opBuf[ actReadLen - 1 ] = _NULL_CHAR_; --actReadLen; } #ifdef _DEBUG_ printk( KERN_ALERT "Bytes read from I/P file ::%d::\n", actReadLen ); printk( KERN_ALERT "Data read from I/P file ::%s::\n", opBuf ); #endif break; } /* * Start writing to the o/p file * Set the address space to kernel one */ oldfs = get_fs(); set_fs( KERNEL_DS ); actWriteLen = opFilePtr->f_op->write( opFilePtr, opBuf, actReadLen, &opFilePtr->f_pos ); /* Reset the address space to user one */ set_fs( oldfs ); #ifdef _DEBUG_ printk( KERN_ALERT "Bytes written to O/P file ::%d::\n", actWriteLen ); #endif } /* Free iv */ OUT_IV: kfree( iv ); iv = NULL; printk( KERN_ALERT "Memory for IV freed ..." ); /* Free tfm */ OUT_CIPHER: crypto_free_blkcipher( tfm ); printk( KERN_ALERT "Encryption Transform freed ..." ); /* Free i/p and o/p buffers */ OUT_DATA_PAGE: if( ipBuf ) { kfree( ipBuf ); ipBuf = NULL; } if( opBuf ) { kfree( opBuf ); opBuf = NULL; } printk( KERN_ALERT "Memory for encrption/decryption freed ..." ); /* Close any open files */ OUT_FILE: if( inFilePtr ) { filp_close( inFilePtr, NULL ); inFilePtr = NULL; printk( KERN_ALERT "I/p file closed ..." ); } if( opFilePtr ) { filp_close( opFilePtr, NULL ); opFilePtr = NULL; printk( KERN_ALERT "O/p file closed ..." ); } if( delOpFile ) { opFilePtr = filp_open( opFile, O_WRONLY , 0 ); if ( !opFilePtr || IS_ERR( opFilePtr ) ) { opFilePtr = NULL; goto OUT_IP; } tmpDentry = opFilePtr->f_path.dentry; tmpInode = tmpDentry->d_parent->d_inode; filp_close( opFilePtr, NULL ); vfs_unlink( tmpInode, tmpDentry ); printk( KERN_ALERT "O/p file deleted ..." ); } OUT_IP: if( inFile ) { kfree( inFile ); inFile = NULL; } if( opFile ) { kfree( opFile ); opFile = NULL; } if( keyBuf ) { kfree( keyBuf ); keyBuf = NULL; } printk( KERN_ALERT "Memory for I/P parameters freed ..." ); /* Return final status */ OUT_OK: printk( KERN_ALERT "Exiting function sys_xcrypt ..." ); return errno; }