int nvram_set(const char *name, const char *value) { unsigned long flags; int ret; struct nvram_header *header; spin_lock_irqsave(&nvram_lock, flags); #ifdef CFE_UPDATE //write back to default sector as well, Chen-I if(strncmp(name, CFE_NVRAM_PREFIX, strlen(CFE_NVRAM_PREFIX))==0) { if(strcmp(name, CFE_NVRAM_COMMIT)==0) { #ifdef CONFIG_MTD_NFLASH spin_unlock_irqrestore(&nvram_lock, flags); return cfe_commit(); #else cfe_commit(); #endif } else if(strcmp(name, "asuscfe_dump") == 0) ret = cfe_dump(); else if(strcmp(name, CFE_NVRAM_WATCHDOG)==0) { bcm947xx_watchdog_disable(); } else { cfe_update(name+strlen(CFE_NVRAM_PREFIX), value); _nvram_set(name+strlen(CFE_NVRAM_PREFIX), value); } } else #endif if ((ret = _nvram_set(name, value))) { printk( KERN_INFO "nvram: consolidating space!\n"); /* Consolidate space and try again */ if ((header = kmalloc(nvram_space, GFP_ATOMIC))) { if (_nvram_commit(header) == 0) ret = _nvram_set(name, value); kfree(header); } } spin_unlock_irqrestore(&nvram_lock, flags); return ret; }
int nvram_unset(const char *name) { unsigned long flags; int ret; spin_lock_irqsave(&nvram_lock, flags); #ifdef CFE_UPDATE //unset variable in embedded nvram if(strncmp(name, CFE_NVRAM_PREFIX, strlen(CFE_NVRAM_PREFIX))==0) { if((ret = cfe_update(name+strlen(CFE_NVRAM_PREFIX), NULL)) == 0) { ret = _nvram_unset(name+strlen(CFE_NVRAM_PREFIX)); } } else #endif ret = _nvram_unset(name); spin_unlock_irqrestore(&nvram_lock, flags); return ret; }
int _nvram_read(char *buf) { struct nvram_header *header = (struct nvram_header *) buf; size_t len; int offset = 0; if (nvram_mtd) { #ifdef NFLASH_SUPPORT if (nvram_mtd->type == MTD_NANDFLASH) offset = 0; else #endif offset = nvram_mtd->size - nvram_space; } #ifdef RTN66U_NVRAM_64K_SUPPORT /*Only for RT-N66U upgrade from nvram 32K -> 64K*/ if (nvram_32_reset==1 || !nvram_mtd || nvram_mtd->read(nvram_mtd, offset, nvram_space, &len, buf) || len != nvram_space || header->magic != NVRAM_MAGIC) { nvram_32_reset=0; #else if (nvram_inram || !nvram_mtd || nvram_mtd->read(nvram_mtd, offset, nvram_space, &len, buf) || len != nvram_space || header->magic != NVRAM_MAGIC) { #endif /* Maybe we can recover some data from early initialization */ if (nvram_inram) printk("Sourcing NVRAM from ram\n"); memcpy(buf, nvram_buf, nvram_space); } return 0; } struct nvram_tuple * _nvram_realloc(struct nvram_tuple *t, const char *name, const char *value) { if ((nvram_offset + strlen(value) + 1) > nvram_space) return NULL; if (!t) { if (!(t = kmalloc(sizeof(struct nvram_tuple) + strlen(name) + 1, GFP_ATOMIC))) return NULL; /* Copy name */ t->name = (char *) &t[1]; strcpy(t->name, name); t->value = NULL; } /* Copy value */ if (!t->value || strcmp(t->value, value)) { t->value = &nvram_buf[nvram_offset]; strcpy(t->value, value); nvram_offset += strlen(value) + 1; } return t; } void _nvram_free(struct nvram_tuple *t) { if (!t) nvram_offset = 0; else kfree(t); } int nvram_init(void *sih) { return 0; } int nvram_set(const char *name, const char *value) { unsigned long flags; int ret; struct nvram_header *header; spin_lock_irqsave(&nvram_lock, flags); #ifdef CFE_UPDATE //write back to default sector as well, Chen-I if(strncmp(name, CFE_NVRAM_PREFIX, strlen(CFE_NVRAM_PREFIX))==0) { if(strcmp(name, CFE_NVRAM_COMMIT)==0) cfe_commit(); else if(strcmp(name, "asuscfe_dump") == 0) ret = cfe_dump(); else if(strcmp(name, CFE_NVRAM_WATCHDOG)==0) { bcm947xx_watchdog_disable(); } else { cfe_update(name+strlen(CFE_NVRAM_PREFIX), value); _nvram_set(name+strlen(CFE_NVRAM_PREFIX), value); } } else #endif if ((ret = _nvram_set(name, value))) { /* Consolidate space and try again */ if ((header = kmalloc(nvram_space, GFP_ATOMIC))) { if (_nvram_commit(header) == 0) ret = _nvram_set(name, value); kfree(header); } } spin_unlock_irqrestore(&nvram_lock, flags); return ret; }
int nvram_set(const char *name, const char *value) { unsigned long flags; int ret; struct nvram_header *header; #if WPS char wps_name[32]; int wep_len; #endif spin_lock_irqsave(&nvram_lock, flags); //printk("nvram_set: name = %s, value = %s!\n", name, value); #ifdef CFE_UPDATE // write back to default sector as well, Chen-I if(strncmp(name, CFE_NVRAM_PREFIX, strlen(CFE_NVRAM_PREFIX))==0) { if(strcmp(name, CFE_NVRAM_COMMIT)==0) cfe_commit(); else if(strcmp(name, "asuscfe_dump") == 0) ret = cfe_dump(); else if(strcmp(name, CFE_NVRAM_WATCHDOG)==0) { bcm947xx_watchdog_disable(); } else { cfe_update(name+strlen(CFE_NVRAM_PREFIX), value); _nvram_set(name+strlen(CFE_NVRAM_PREFIX), value); } } else #endif /* CFE_UPDATE */ #if WPS if (strncmp(name, "wlx_", 4) == 0) { memset(wps_name, 0, sizeof(wps_name)); sprintf(wps_name, "wl0_%s", name+4); ret = _nvram_set(wps_name, value); spin_unlock_irqrestore(&nvram_lock, flags); return ret; } if (strncmp(name, "wl0_", 4) == 0) { /* Authentication mode */ if (strncmp(name, "wl0_akm", 7) == 0) { if (strncmp(value, "psk2", 4) == 0) { // WPA2-Personal _nvram_set("wl_auth_mode", "psk"); _nvram_set("wl_wpa_mode", "2"); } else if (strncmp(value, "psk ", 4) == 0) { // WPA-Auto-Personal _nvram_set("wl_auth_mode", "psk"); _nvram_set("wl_wpa_mode", "0"); } else if (strncmp(value, "psk", 3) == 0) { // WPA-Personal _nvram_set("wl_auth_mode", "psk"); _nvram_set("wl_wpa_mode", "1"); } else if (strncmp(value, "wpa2", 4) == 0) { // WPA2-Enterprise _nvram_set("wl_auth_mode", "wpa2"); } else if (strncmp(value, "wpa ", 4) == 0) { // WPA-Auto-Enterprise _nvram_set("wl_wpa_mode", "4"); _nvram_set("wl_auth_mode", "wpa"); } else if (strncmp(value, "wpa", 3) == 0) { // WPA-Enterprise _nvram_set("wl_wpa_mode", "3"); _nvram_set("wl_auth_mode", "wpa"); } _nvram_set("wl_akm", value); } /* WPS KEY*/ else if (strcmp(name, "wl0_wpa_psk") == 0) { _nvram_set("wl_wpa_psk", value); } /* WEP type */ #if 1 else if ((strncmp(name, "wl0_key", 7) == 0 )) { wep_len = strlen (value); memset(wps_name, 0, sizeof(wps_name)); if ((wep_len == 5) || (wep_len == 10)) { /* wl0_key1~4*/ // _nvram_set ("wl0_wep_x", "1"); _nvram_set ("wl_wep_x", "1"); sprintf(wps_name, "wl_%s", name+4); } else if ((wep_len == 13) || (wep_len == 26)) { // _nvram_set ("wl0_wep_x", "2"); _nvram_set ("wl_wep_x", "2"); sprintf(wps_name, "wl_%s", name+4); } else { /* wl0_key index */ sprintf(wps_name, "wl_%s", name+4); } _nvram_set(wps_name, value); } #endif else if (strcmp(name, "wl0_ssid") == 0) { // _nvram_set("wl0_ssid2", value); // _nvram_set("wl_ssid2", value); _nvram_set("wl_ssid", value); } else if (strcmp(name, "wl0_crypto") == 0) { _nvram_set("wl_crypto", value); } else if (strncmp(name, "wl0_wps", 7) == 0) { memset(wps_name, 0, sizeof(wps_name)); sprintf(wps_name, "wl_%s", name+4); _nvram_set(wps_name, value); } } else if (strncmp(name, "wps_random_ssid_prefix", 22) == 0) { memset(wps_name, 0, sizeof(wps_name)); sprintf(wps_name, "ASUS_"); ret = _nvram_set("wps_random_ssid_prefix", wps_name); spin_unlock_irqrestore(&nvram_lock, flags); return ret; } if ((strcmp(name, "wl_wps_config_state") == 0) || (strcmp(name, "wl0_wps_config_state") == 0)) _nvram_set("wps_config_state", value); // else if ((strncmp(name, "wps_proc_status", 15) == 0 ) && (strcmp(value, "4"))) /* WPS success*/ // _nvram_set("wps_config_state", "1"); #if 0 if(!strcmp(name, "wl0_ssid")) _nvram_set("wl_ssid", value); if(!strcmp(name, "wl0_ssid")) _nvram_set("wl_ssid", value); /* Set Wireless encryption */ if (!strcmp(name, "wl0_akm")) { _nvram_set("wl_auth_mode", "psk"); _nvram_set("wl_wpa_mode", "1"); } else if (!strcmp("wl0_akm", "psk2")) { _nvram_set("wl_auth_mode", "psk"); _nvram_set("wl_wpa_mode", "2"); } else if (nvram_match("wl0_akm", "wpa")) { _nvram_set("wl_auth_mode", "wpa"); _nvram_set("wl_wpa_mode", "3"); } else if (nvram_match("wl0_akm", "wpa2")) { _nvram_set("wl_auth_mode", "wpa2"); } else _nvram_set("wl_auth_mode", nvram_get("wl0_auth_mode")); #endif #endif /* WPS */ if ((ret = _nvram_set(name, value))) { /* Consolidate space and try again */ if ((header = kmalloc(NVRAM_SPACE, GFP_ATOMIC))) { if (_nvram_commit(header) == 0) ret = _nvram_set(name, value); kfree(header); } } spin_unlock_irqrestore(&nvram_lock, flags); return ret; }