diff --git a/config.h b/config.h index 46cff15..b406ec6 100644 --- a/config.h +++ b/config.h @@ -26,83 +26,4 @@ #define E_FAILURE 0 #define E_SUCCESS 1 -// Default paths for NVRAM default values. -#define NVRAM_DEFAULTS_PATH \ - /* "DIR-505L_FIRMWARE_1.01.ZIP" (10497) */ \ - PATH("/var/etc/nvram.default") \ - /* "DIR-615_REVE_FIRMWARE_5.11.ZIP" (9753) */ \ - PATH("/etc/nvram.default") \ - /* "DGL-5500_REVA_FIRMWARE_1.12B05.ZIP" (9469) */ \ - TABLE(router_defaults) \ - PATH("/etc/nvram.conf") \ - PATH("/etc/nvram.deft") \ - PATH("/etc/nvram.update") \ - TABLE(Nvrams) \ - PATH("/etc/wlan/nvram_params") \ - PATH("/etc/system_nvram_defaults") \ - FIRMAE_PATH("/image/mnt/nvram_ap.default") \ - /* "DCS-931L_FIRMWARE_1.04B1.ZIP" by SR */\ - FIRMAE_PATH("/etc_ro/Wireless/RT2860AP/RT2860_default_vlan") \ - FIRMAE_PATH("/etc_ro/Wireless/RT2860AP/RT2860_default_novlan") \ - /* "DGN3500-V1.1.00.30_NA.zip" */\ - FIRMAE_PATH2("/usr/etc/default") \ - /* "JR6150-R6050-V1.0.0.22.zip" by SR */ \ - FIRMAE_PATH("/image/mnt/nvram_whp.default") \ - FIRMAE_PATH("/image/mnt/nvram_rt.default") \ - FIRMAE_PATH("/image/mnt/nvram_rpt.default") \ - FIRMAE_PATH("/image/mnt/nvram.default") - -// Default values for NVRAM. -#define NVRAM_DEFAULTS \ - /* Linux kernel log level, used by "WRT54G3G_2.11.05_ETSI_code.bin" (305) */ \ - ENTRY("console_loglevel", nvram_set, "7") \ - /* Reset NVRAM to default at bootup, used by "WNR3500v2-V1.0.2.10_23.0.70NA.chk" (1018) */ \ - ENTRY("restore_defaults", nvram_set, "1") \ - ENTRY("sku_name", nvram_set, "") \ - ENTRY("wla_wlanstate", nvram_set, "") \ - ENTRY("lan_if", nvram_set, "br0") \ - ENTRY("lan_ipaddr", nvram_set, "192.168.0.50") \ - ENTRY("lan_bipaddr", nvram_set, "192.168.0.255") \ - ENTRY("lan_netmask", nvram_set, "255.255.255.0") \ - /* Set default timezone, required by multiple images */ \ - ENTRY("time_zone", nvram_set, "PST8PDT") \ - /* Set default WAN MAC address, used by "NBG-416N_V1.00(USA.7)C0.zip" (12786) */ \ - ENTRY("wan_hwaddr_def", nvram_set, "01:23:45:67:89:ab") \ - /* Attempt to define LAN/WAN interfaces */ \ - ENTRY("wan_ifname", nvram_set, "eth0") \ - ENTRY("lan_ifnames", nvram_set, "eth1 eth2 eth3 eth4") \ - /* Used by "TEW-638v2%201.1.5.zip" (12898) to prevent crash in 'goahead' */ \ - ENTRY("ethConver", nvram_set, "1") \ - /* Used by "Firmware_TEW-411BRPplus_2.07_EU.zip" (13649) to prevent crash in 'init' */ \ - ENTRY("lan_proto", nvram_set, "dhcp") \ - ENTRY("wan_ipaddr", nvram_set, "0.0.0.0") \ - ENTRY("wan_netmask", nvram_set, "255.255.255.0") \ - ENTRY("wanif", nvram_set, "eth0") \ - /* Used by "DGND3700 Firmware Version 1.0.0.17(NA).zip" (3425) to prevent crashes */ \ - ENTRY("time_zone_x", nvram_set, "0") \ - ENTRY("rip_multicast", nvram_set, "0") \ - ENTRY("bs_trustedip_enable", nvram_set, "0") \ - /* Set default MAC address, used by "linux-lzma(550A)" by SR */ \ - FIRMAE_ENTRY("et0macaddr", nvram_set, "01:23:45:67:89:ab")\ - /* Used by "AC1450-V1.0.0.34_10.0.16.zip" to prevent crashes by SR */ \ - FIRMAE_ENTRY("filter_rule_tbl", nvram_set, "") \ - /* Used by Netgear "R6200V2-V1.0.1.14_1.0.14.zip" by SR */ \ - FIRMAE_ENTRY("pppoe2_schedule_config", nvram_set, "127:0:0:23:59") \ - FIRMAE_ENTRY("schedule_config", nvram_set, "127:0:0:23:59") \ - /* Used by Netgear WNDR3400v3, WNDR3500v3 "WNR3500L-V1.2.0.18_40.0.67" to prevent crashes due to following "atoi" func by SR */ \ - FIRMAE_ENTRY("access_control_mode", nvram_set, "0") \ - FIRMAE_ENTRY("fwpt_df_count", nvram_set, "0") \ - FIRMAE_ENTRY("static_if_status", nvram_set, "1") \ - /* R8500 patch to prevent crashes in httpd */ \ - FIRMAE_ENTRY("www_relocation", nvram_set, "") \ - FIRMAE_FOR_ENTRY("usb_info_dev%d", nvram_set, "A200396E0402FF83@1@14.4G@U@1@USB_Storage;U:;0;0@", 0, 101) \ - /* R6200V2, R6250-V1, R6300v2, R6400, R6700-V1, R7000-V1, R7900, R8000, R8500 patch to prevent crashes in httpd */ \ - FIRMAE_FOR_ENTRY("wla_ap_isolate_%d", nvram_set, "", 1, 5) \ - /* R6200V1 patch to prevent crashes in httpd */ \ - FIRMAE_FOR_ENTRY("wlg_ap_isolate_%d", nvram_set, "", 1, 5) \ - FIRMAE_FOR_ENTRY("wlg_allow_access_%d", nvram_set, "", 1, 5) \ - /* R6400-V1, R7900-V1, R8000, R8500 patch to prevent crashes in httpd */ \ - FIRMAE_FOR_ENTRY("%d:macaddr", nvram_set, "01:23:45:67:89:ab", 0, 3) \ - FIRMAE_FOR_ENTRY("lan%d_ifnames", nvram_set, "", 1, 10) - -#endif +#endif \ No newline at end of file diff --git a/nvram.c b/nvram.c index 4cbb138..2e96544 100644 --- a/nvram.c +++ b/nvram.c @@ -23,20 +23,9 @@ #include "config.h" #include "strings.h" -/* Generate variable declarations for external NVRAM data. */ -#define NATIVE(a, b) -#define PATH(a) -#define FIRMAE_PATH(a) -#define FIRMAE_PATH2(a) -#define TABLE(a) \ - extern const char *a[] __attribute__((weak)); - - NVRAM_DEFAULTS_PATH -#undef TABLE -#undef FIRMAE_PATH2 -#undef FIRMAE_PATH -#undef PATH -#undef NATIVE +// Two left-over weak symbols from the original code +extern const char *router_defaults[] __attribute__((weak)); +extern const char *Nvrams[] __attribute__((weak)); // https://lkml.org/lkml/2007/3/9/10 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + sizeof(typeof(int[1 - 2 * !!__builtin_types_compatible_p(typeof(arr), typeof(&arr[0]))])) * 0) @@ -555,105 +544,17 @@ int nvram_set_int(const char *key, const int val) { } int nvram_set_default(void) { - int ret = nvram_set_default_builtin(); - PRINT_MSG("Loading built-in default values = %d!\n", ret); if (!is_load_env) firmae_load_env(); -#define NATIVE(a, b) \ - if (!system(a)) { \ - PRINT_MSG("Executing native call to built-in function: %s (%p) = %d!\n", #b, b, b); \ + if (router_defaults) { + PRINT_MSG("Loading from native built-in table: %s (%p) = %d!\n", "router_defaults", router_defaults, nvram_set_default_table(router_defaults)); } - -#define TABLE(a) \ - PRINT_MSG("Checking for symbol \"%s\"...\n", #a); \ - if (a) { \ - PRINT_MSG("Loading from native built-in table: %s (%p) = %d!\n", #a, a, nvram_set_default_table(a)); \ - } - -#define PATH(a) \ - if (!access(a, R_OK)) { \ - PRINT_MSG("Loading from default configuration file: %s = %d!\n", a, foreach_nvram_from(a, (void (*)(const char *, const char *, void *)) nvram_set, NULL)); \ - } -#define FIRMAE_PATH(a) \ - if (firmae_nvram && !access(a, R_OK)) { \ - PRINT_MSG("Loading from default configuration file: %s = %d!\n", a, foreach_nvram_from(a, (void (*)(const char *, const char *, void *)) nvram_set, NULL)); \ - } -#define FIRMAE_PATH2(a) \ - if (firmae_nvram && !access(a, R_OK)) { \ - PRINT_MSG("Loading from default configuration file: %s = %d!\n", a, parse_nvram_from_file(a)); \ - } - - NVRAM_DEFAULTS_PATH -#undef FIRMAE_PATH2 -#undef FIRMAE_PATH -#undef PATH -#undef NATIVE -#undef TABLE - - // /usr/etc/default in DGN3500-V1.1.00.30_NA.zip - FILE *file; - if (firmae_nvram && - !access("/firmadyne/nvram_files", R_OK) && - (file = fopen("/firmadyne/nvram_files", "r"))) - { - char line[256]; - char *nvram_file; - char *file_type; - while (fgets(line, sizeof line, file) != NULL) - { - line[strlen(line) - 1] = '\0'; - nvram_file = strtok(line, " "); - file_type = strtok(NULL, " "); - file_type = strtok(NULL, " "); - - if (access(nvram_file, R_OK) == -1) - continue; - - if (strstr(file_type, "ELF") == NULL) - PRINT_MSG("Loading from default configuration file: %s = %d!\n", nvram_file, parse_nvram_from_file(nvram_file)); - } + if (Nvrams) { + PRINT_MSG("Loading from native built-in table: %s (%p) = %d!\n", "Nvrams", Nvrams, nvram_set_default_table(Nvrams)); } - return nvram_set_default_image(); } -static int nvram_set_default_builtin(void) { - int ret = E_SUCCESS; - char nvramKeyBuffer[100]=""; - int index=0; - if (!is_load_env) firmae_load_env(); - - PRINT_MSG("%s\n", "Setting built-in default values!"); - -#define ENTRY(a, b, c) \ - if (b(a, c) != E_SUCCESS) { \ - PRINT_MSG("Unable to initialize built-in NVRAM value %s!\n", a); \ - ret = E_FAILURE; \ - } - -#define FIRMAE_ENTRY(a, b, c) \ - if (firmae_nvram && b(a, c) != E_SUCCESS) { \ - PRINT_MSG("Unable to initialize built-in NVRAM value %s!\n", a); \ - ret = E_FAILURE; \ - } - -#define FIRMAE_FOR_ENTRY(a, b, c, d, e) \ - index = d; \ - if (firmae_nvram) { \ - while (index != e) { \ - snprintf(nvramKeyBuffer, 0x1E, a, index++); \ - ENTRY(nvramKeyBuffer, b, c) \ - } \ - } - - NVRAM_DEFAULTS -#undef FIRMAE_FOR_ENTRY -#undef FIRMAE_ENTRY -#undef ENTRY - - return ret; -} - static int nvram_set_default_image(void) { int dirfd; PRINT_MSG("%s\n", "Copying overrides from defaults folder!"); diff --git a/nvram.h b/nvram.h index f495298..2b6f002 100644 --- a/nvram.h +++ b/nvram.h @@ -6,8 +6,6 @@ static int dir_lock(); // Unlocks the nvram directory. static void dir_unlock(int dirfd); -// Sets default NVRAM values using the built-in NVRAM_DEFAULTS table. -static int nvram_set_default_builtin(void); // Sets default NVRAM values using the override values from OVERRIDE_POINT. Will hold lock. static int nvram_set_default_image(void); // Sets default NVRAM values from external table defined in NVRAM_DEFAULTS_PATH.