/** * @brief uap setting proc write function * * @param f file pointer * @param buf pointer to data buffer * @param cnt data number to write * @param data data to write * @return number of data */ static int woal_setting_write(struct file *f, const char *buf, unsigned long cnt, void *data) { char databuf[100]; char *line; struct net_device *netdev = data; moal_private *priv = (moal_private *) netdev_priv(netdev); t_u32 config_data = 0; MODULE_GET; if (cnt > sizeof(databuf)) { MODULE_PUT; return cnt; } memset(databuf, 0, sizeof(databuf)); if (copy_from_user(databuf, buf, cnt)) { MODULE_PUT; return 0; } line = databuf; if (!strncmp(databuf, "bss_start", strlen("bss_start"))) { line += strlen("bss_start") + 1; config_data = (t_u32) woal_string_to_number(line); if (config_data == 1) { PRINTM(MINFO, "bss_start: %d\n", (int) config_data); woal_bss_start(priv, MOAL_PROC_WAIT, NULL); } else if (config_data == 0) { PRINTM(MINFO, "bss_stop: %d\n", (int) config_data); woal_disconnect(priv, MOAL_PROC_WAIT, NULL); } } MODULE_PUT; return cnt; }
/* * @brief Parse cmd52 string * * @param buffer A pointer user buffer * @param len Length user buffer * @param func Parsed func number * @param reg Parsed reg value * @param val Parsed value to set * @return BT_STATUS_SUCCESS */ static int parse_cmd52_string(const char __user * buffer, size_t len, int *func, int *reg, int *val) { int ret = MLAN_STATUS_SUCCESS; char *string = NULL; char *pos = NULL; ENTER(); string = (char *) kmalloc(CMD52_STR_LEN, GFP_KERNEL); memset(string, 0, CMD52_STR_LEN); memcpy(string, buffer + strlen("sdcmd52rw="), MIN((CMD52_STR_LEN - 1), (len - strlen("sdcmd52rw=")))); string = strstrip(string); *func = -1; *reg = -1; *val = -1; /* Get func */ pos = strsep(&string, " \t"); if (pos) { *func = woal_string_to_number(pos); } /* Get reg */ pos = strsep(&string, " \t"); if (pos) { *reg = woal_string_to_number(pos); } /* Get val (optional) */ pos = strsep(&string, " \t"); if (pos) { *val = woal_string_to_number(pos); } if (string) kfree(string); LEAVE(); return ret; }
/** * @brief config proc write function * * @param f file pointer * @param buf pointer to data buffer * @param cnt data number to write * @param data data to write * @return number of data */ static int woal_config_write(struct file *f, const char *buf, unsigned long cnt, void *data) { char databuf[100]; char *line; t_u32 config_data = 0; moal_handle *handle = (moal_handle *) data; MODULE_GET; if (cnt > sizeof(databuf)) { MODULE_PUT; return cnt; } memset(databuf, 0, sizeof(databuf)); if (copy_from_user(databuf, buf, cnt)) { MODULE_PUT; return 0; } line = databuf; if (!strncmp(databuf, "soft_reset", strlen("soft_reset"))) { line += strlen("soft_reset") + 1; config_data = (t_u32) woal_string_to_number(line); PRINTM(MINFO, "soft_reset: %d\n", (int) config_data); woal_request_soft_reset(handle); handle->hardware_status = HardwareStatusReset; } if (!strncmp(databuf, "drv_mode", strlen("drv_mode"))) { line += strlen("drv_mode") + 1; config_data = (t_u32) woal_string_to_number(line); PRINTM(MINFO, "drv_mode: %d\n", (int) config_data); if (config_data != (t_u32) drv_mode) woal_switch_drv_mode(handle, config_data); } MODULE_PUT; return cnt; }
/** * @brief Proc write function * * @param f File pointer * @param buf Pointer to data buffer * @param cnt Data number to write * @param data Data to write * * @return Number of data or MLAN_STATUS_FAILURE */ static int woal_debug_write(struct file *f, const char *buf, unsigned long cnt, void *data) { int r, i; char *pdata; char *p; char *p0; char *p1; char *p2; struct debug_data *d = ((struct debug_data_priv *) data)->items; moal_private *priv = ((struct debug_data_priv *) data)->priv; #ifdef DEBUG_LEVEL1 t_u32 last_drvdbg = drvdbg; #endif ENTER(); if (MODULE_GET == 0) { LEAVE(); return MLAN_STATUS_FAILURE; } pdata = (char *) kmalloc(cnt, GFP_KERNEL); if (pdata == NULL) { MODULE_PUT; LEAVE(); return 0; } if (copy_from_user(pdata, buf, cnt)) { PRINTM(MERROR, "Copy from user failed\n"); kfree(pdata); MODULE_PUT; LEAVE(); return 0; } if (woal_get_debug_info(priv, MOAL_PROC_WAIT, &info)) { kfree(pdata); MODULE_PUT; LEAVE(); return 0; } p0 = pdata; for (i = 0; i < ((struct debug_data_priv *) data)->num_of_items; i++) { do { p = strstr(p0, d[i].name); if (p == NULL) break; p1 = strchr(p, '\n'); if (p1 == NULL) break; p0 = p1++; p2 = strchr(p, '='); if (!p2) break; p2++; r = woal_string_to_number(p2); if (d[i].size == 1) *((t_u8 *) d[i].addr) = (t_u8) r; else if (d[i].size == 2) *((t_u16 *) d[i].addr) = (t_u16) r; else if (d[i].size == 4) *((t_ptr *) d[i].addr) = (t_ptr) r; break; } while (MTRUE); } kfree(pdata); #ifdef DEBUG_LEVEL1 if (last_drvdbg != drvdbg) { woal_set_drvdbg(priv, drvdbg); } #endif /* Set debug information */ if (woal_set_debug_info(priv, MOAL_PROC_WAIT, &info)) { MODULE_PUT; LEAVE(); return 0; } MODULE_PUT; LEAVE(); return cnt; }
/** * @brief config proc write function * * @param f file pointer * @param buf pointer to data buffer * @param cnt data number to write * @param data data to write * @return number of data */ static int woal_config_write(struct file *f, const char *buf, unsigned long cnt, void *data) { char databuf[101]; char *line; t_u32 config_data = 0; moal_handle *handle = (moal_handle *) data; int func, reg, val; int copy_len; moal_private *priv = NULL; ENTER(); if (!MODULE_GET) { LEAVE(); return 0; } if (cnt >= sizeof(databuf)) { MODULE_PUT; LEAVE(); return (int) cnt; } memset(databuf, 0, sizeof(databuf)); copy_len = MIN((sizeof(databuf) - 1), cnt); if (copy_from_user(databuf, buf, copy_len)) { MODULE_PUT; LEAVE(); return 0; } line = databuf; if (!strncmp(databuf, "soft_reset", strlen("soft_reset"))) { line += strlen("soft_reset") + 1; config_data = (t_u32) woal_string_to_number(line); PRINTM(MINFO, "soft_reset: %d\n", (int) config_data); if (woal_request_soft_reset(handle) == MLAN_STATUS_SUCCESS) { handle->hardware_status = HardwareStatusReset; } else { PRINTM(MERROR, "Could not perform soft reset\n"); } } if (!strncmp(databuf, "drv_mode", strlen("drv_mode"))) { line += strlen("drv_mode") + 1; config_data = (t_u32) woal_string_to_number(line); PRINTM(MINFO, "drv_mode: %d\n", (int) config_data); if (config_data != (t_u32) drv_mode) if (woal_switch_drv_mode(handle, config_data) != MLAN_STATUS_SUCCESS) { PRINTM(MERROR, "Could not switch drv mode\n"); } } if (!strncmp(databuf, "sdcmd52rw=", strlen("sdcmd52rw="))) { parse_cmd52_string(databuf, (size_t) cnt, &func, ®, &val); woal_sdio_read_write_cmd52(handle, func, reg, val); } if (!strncmp(databuf, "debug_dump", strlen("debug_dump"))) { priv = woal_get_priv(handle, MLAN_BSS_ROLE_ANY); if (priv) { woal_mlan_debug_info(priv); woal_moal_debug_info(priv, NULL, MFALSE); woal_dump_firmware_info(priv); } } MODULE_PUT; LEAVE(); return (int) cnt; }