static void nas_watchdog(bcm_timer_id td, nas_t *nas) { nas_sta_t *sta; int i; #ifdef BCMDBG char eabuf[ETHER_ADDR_STR_LEN]; #endif for (i = 0; i < MAX_SUPPLICANTS; i ++) { for (sta = nas->sta_hashed[i]; sta; sta = sta->next) { #ifdef BCMDBG if (nas->auth_blockout_time) { if (sta->pae.flags & PAE_FLAG_RADIUS_ACCESS_REJECT) dbg(nas, "blocking %s, time remaining = %d", ether_etoa((uchar *)&sta->ea, eabuf), sta->quiet_while); } #endif /* check for time out */ switch (sta->pae.state) { case AUTHENTICATED: if (!sta->pae.ssnto) break; sta->pae.ssnto--; /* timed out */ if (sta->pae.ssnto) continue; /* send Identity Request */ dbg(nas, "ID req to %s\n", ether_etoa((uchar *)&sta->ea, eabuf)); send_identity_req(nas, sta); break; case HELD: if (sta->quiet_while && --sta->quiet_while == 0) pae_state(nas, sta, CONNECTING); break; case CONNECTING: if (sta->tx_when && --sta->tx_when == 0) { if (sta->rxauths > STA_REAUTH_MAX) pae_state(nas, sta, DISCONNECTED); else pae_state(nas, sta, CONNECTING); } break; case AUTHENTICATING: if (sta->auth_while && --sta->auth_while == 0) { pae_state(nas, sta, ABORTING); pae_state(nas, sta, CONNECTING); } break; default: break; } } } }
void start_sysinit(void) { char buf[PATH_MAX]; struct stat tmp_stat; time_t tm = 0; eval("/bin/tar", "-xzf", "/dev/mtdblock/2", "-C", "/"); FILE *in = fopen("/tmp/nvram/nvram.db", "rb"); if (in != NULL) { fclose(in); eval("/usr/sbin/convertnvram"); eval("/sbin/mtd", "erase", "nvram"); nvram_commit(); } if (!nvram_match("disable_watchdog", "1")) eval("watchdog"); /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); int brand = getRouterBrand(); /* * network drivers */ detect_wireless_devices(); struct ifreq ifr; int s; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); close(s); } /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); return; }
void cleanup_sta(nas_t *nas, nas_sta_t *sta, int reason, int driver_signal) { unsigned char toss = 1; #ifdef BCMDBG char eabuf[ETHER_ADDR_STR_LEN]; #endif if (sta == NULL) { dbg(nas, "called with NULL STA ponter"); return; } /* De-Authenticate supplicant only once, and ignore further * response from supplicant. We put supplicant in DISCONNECTED * state, till we either receive handshake from supplicant or the * wds_td initiator timer expires, either of the events put * supplicant sta back in START state. * Cleanup of supplicant sta is not required in case of WDS, * Because, Removing WDS config leades to rc restart anyway, which * restarts the whole NAS story. */ if ((nas->flags & NAS_FLAG_WDS) && (nas->flags & NAS_FLAG_AUTHENTICATOR)) { if (!driver_signal && (sta->suppl.state != WPA_DISCONNECTED)) sta->suppl.state = WPA_DISCONNECTED; if (!driver_signal && (sta->suppl.state == WPA_DISCONNECTED)) driver_signal = 1; /* Dont toss supplicant sta in case of WDS, the initiator * timer will trigger fake assoc. */ toss = 0; } /* If this is because of a driver message, telling the driver again * is unnecessary (and could loop). */ if (!driver_signal) { dbg(nas, "deauthenticating %s", ether_etoa((uchar *)&sta->ea, eabuf)); nas_deauthenticate(nas, &sta->ea, reason); } /* Be careful not to leak timer descriptors. */ wpa_stop_retx(sta); /* Respect the PMK caching if the STA is associate and Authenticated with WPA2 AKM */ if ((sta->mode & WPA2) && (sta->pae.state == AUTHENTICATED) && sta->pae.ssnto) { dbg(nas, "keep STA %s", ether_etoa((uchar *)&sta->ea, eabuf)); sta->suppl.state = WPA_PTKSTART; return; } if (toss) toss_sta(nas, sta, 0, 1); return; }
int get_wlname_by_mac(unsigned char *mac, char *wlname) { char eabuf[18]; char tmptr[] = "wlXXXXX_hwaddr"; char *wl_hw; int i, j; ether_etoa(mac, eabuf); /* find out the wl name from mac */ for (i = 0; i < WLIFU_MAX_NO_BRIDGE; i++) { sprintf(wlname, "wl%d", i); sprintf(tmptr, "wl%d_hwaddr", i); wl_hw = nvram_get(tmptr); if (wl_hw) { if (!strncasecmp(wl_hw, eabuf, sizeof(eabuf))) return 0; } for (j = 1; j < WL_MAXBSSCFG; j++) { sprintf(wlname, "wl%d.%d", i, j); sprintf(tmptr, "wl%d.%d_hwaddr", i, j); wl_hw = nvram_get(tmptr); if (wl_hw) { if (!strncasecmp(wl_hw, eabuf, sizeof(eabuf))) return 0; } } } return -1; }
static void toss_sta(nas_t *nas, nas_sta_t *sta, int reason, int driver_signal) { nas_sta_t *sta_list; uint hash; #ifdef BCMDBG char eabuf[ETHER_ADDR_STR_LEN]; #endif if (sta == NULL) { dbg(nas, "called with NULL STA ponter"); return; } /* If this is because of a driver message, telling the driver again * is unnecessary (and could loop). */ if (!driver_signal) { dbg(nas, "deauthenticating %s", ether_etoa((uchar *)&sta->ea, eabuf)); nas_deauthenticate(nas, &sta->ea, reason); } /* Be careful not to leak timer descriptors. */ wpa_stop_retx(sta); dbg(nas, "cleanup STA %s", ether_etoa((uchar *)&sta->ea, eabuf)); /* Remove this one from its hashed list. */ hash = pae_hash(&sta->ea); sta_list = nas->sta_hashed[hash]; if (sta_list == sta) { /* It was the head, so its next is the new head. */ nas->sta_hashed[hash] = sta->next; } else { /* Find the one that points to it and change the pointer. */ while ((sta_list != NULL) && (sta_list->next != sta)) sta_list = sta_list->next; if (sta_list == NULL) { dbg(nas, "sta %s not in hash list", ether_etoa((uchar *)&sta->ea, eabuf)); } else { sta_list->next = sta->next; } } sta->used = FALSE; return; }
/* * write default .nvm and .pib to flash */ int default_plc_write_to_flash(void) { FILE *fp; int len, i; char cmd[64], buf[64]; char mac[18], dak[48], nmk[48]; unsigned char emac[ETHER_ADDR_LEN], enmk[PLC_KEY_LEN]; doSystem("cp %s %s", DEFAULT_NVM_PATH, BOOT_NVM_PATH); doSystem("cp %s %s", DEFAULT_PIB_PATH, BOOT_PIB_PATH); // modify .pib // MAC if (!__getPLC_para(emac, OFFSET_PLC_MAC)) { _dprintf("READ PLC MAC: Out of scope\n"); } else { if (emac[0] != 0xff) { if (ether_etoa(emac, mac)) doSystem("/usr/local/bin/modpib %s -M %s", BOOT_PIB_PATH, mac); // DAK if (__getPLC_PWD(emac, buf)) { sprintf(cmd, "/usr/local/bin/hpavkey -D %s", buf); fp = popen(cmd, "r"); if (fp) { len = fread(buf, 1, sizeof(buf), fp); pclose(fp); if (len > 1) { buf[len - 1] = '\0'; for (i = 0; i < PLC_KEY_LEN; i++) { if (i == 0) sprintf(dak, "%c%c", buf[0], buf[1]); else sprintf(dak, "%s:%c%c", dak, buf[i*2], buf[i*2+1]); } doSystem("/usr/local/bin/modpib %s -D %s", BOOT_PIB_PATH, dak); } } } } } // NMK if (!__getPLC_para(enmk, OFFSET_PLC_NMK)) _dprintf("READ PLC NMK: Out of scope\n"); else { if (enmk[0] != 0xff && enmk[1] != 0xff && enmk[2] != 0xff) { if (key_etoa(enmk, nmk)) doSystem("/usr/local/bin/modpib %s -N %s", BOOT_PIB_PATH, nmk); } } return plc_write_to_flash(BOOT_NVM_PATH, BOOT_PIB_PATH); }
void start_sysinit(void) { char buf[PATH_MAX]; struct stat tmp_stat; time_t tm = 0; if (!nvram_match("disable_watchdog", "1")) eval("watchdog"); /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); int brand = getRouterBrand(); /* * network drivers */ insmod("ag7100_mod"); int s; struct ifreq ifr; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); char macaddr[32]; strcpy(macaddr, ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr", macaddr); nvram_set("et0macaddr_safe", macaddr); close(s); } #ifdef HAVE_MADWIFI_MIMO // insmod("ath_pci", "autocreate=none"); insmod("ath_mimo_pci"); #endif // eval ("ifconfig", "wifi0", "up"); /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); return; cprintf("done\n"); }
int write_pControlClientMac(int action, u_char *var_val, u_char var_val_type, size_t var_val_len, u_char *statP, oid *name, size_t name_len) { long index; char macaddr[18]; switch ( action ) { case RESERVE1: if (var_val_type != ASN_OCTET_STR) { fprintf(stderr, "write to parentalControl not ASN_OCTET_STR\n"); return SNMP_ERR_WRONGTYPE; } break; case RESERVE2: break; case FREE: /* Release any resources that have been allocated */ break; case ACTION: /* * The variable has been stored in 'value' for you to use, * and you have just been asked to do something with it. * Note that anything done here must be reversable in the UNDO case */ memset(tmpstr, 0x0, SPRINT_MAX_LEN); index = name[name_len-1] -1; ether_etoa(var_val, macaddr); set_pc_client_mac(index, macaddr); pc_list_flag = 0; break; case UNDO: /* Back out any changes made in the ACTION case */ break; case COMMIT: /* * Things are working well, so it's now safe to make the change * permanently. Make sure that anything done here can't fail! */ break; } return SNMP_ERR_NOERROR; }
/* * get PLC MAC from factory partition */ int getPLC_MAC(char *abuf) { unsigned char ebuf[ETHER_ADDR_LEN]; if (__getPLC_para(ebuf, OFFSET_PLC_MAC)) { memset(abuf, 0, sizeof(abuf)); if (ether_etoa(ebuf, abuf)) return 1; } return 0; }
void nas_start(nas_t *nas) { nas_sta_t *sta; /* reset all STAs */ bzero((void *)nas->sta, sizeof(nas->sta)); bzero((void *)nas->sta_hashed, sizeof(nas->sta_hashed)); nas->MIC_failures = 0; nas->MIC_countermeasures = 0; nas->prev_MIC_error = 0; /* start session count down timer */ if (CHECK_RADIUS(nas->mode)) nas_start_watchdog(nas); /* initiate/request pairwise key exchange */ if (!(nas->flags & NAS_FLAG_WDS)) return; sta = lookup_sta(nas, (struct ether_addr *)nas->remote, SEARCH_ENTER); if (!sta) { #ifdef BCMDBG char eabuf[ETHER_ADDR_STR_LEN]; #endif dbg(nas, "sta %s not available", ether_etoa(nas->remote, eabuf)); return; } /* Assume the peer use the same cipher and akm */ if (CHECK_PSK(nas->mode)) { sta->suppl.pmk_len = nas->wpa->pmk_len; bcopy(nas->wpa->pmk, sta->suppl.pmk, nas->wpa->pmk_len); } /* * There is no beacon/proberesp/assocreq across WDS, therefore * we have no way to know what cipher and akm the peer is configured * for. But assuming the peer uses the same configuration seems * reasonable. No WEP when doing WPA over WDS. */ wpa_set_suppl(nas->wpa, sta, nas->mode, nas->wsec, CRYPTO_ALGO_OFF); #ifdef BCMSUPPL if (nas->flags & NAS_FLAG_SUPPLICANT) wpa_request(nas->wpa, sta); #endif if (nas->flags & NAS_FLAG_AUTHENTICATOR) wpa_start(nas->wpa, sta); }
void eapol_sup_dispatch(nas_t *nas, eapol_header_t *eapol) { nas_sta_t *sta; #ifdef BCMDBG char eabuf[ETHER_ADDR_STR_LEN]; #endif if (!eapol) { dbg(nas, "Missing EAPOL header"); return; } sta = lookup_sta(nas, (struct ether_addr *) eapol->eth.ether_shost, SEARCH_ENTER); if (!sta) { dbg(nas, "No STA struct available"); return; } dbg(nas, "%s message from %s", eapol_msg_type_name(eapol->type), ether_etoa((uchar *)&sta->ea, eabuf)); if (eapol->version < sta->eapol_version) { dbg(nas, "EAPOL version %d packet received, current version is %d", eapol->version, sta->eapol_version); } /* If this is a WPA key pkt then process it accordingly */ if ((eapol->type == EAPOL_KEY) && (CHECK_EAPOL_KEY(eapol->body[0]))) { /* Expect to do this only for WPA_PSK or for WPA either very * early or after RADIUS acceptance. */ if ((CHECK_NAS(sta->mode)) && ((sta->pae.state == AUTHENTICATED) || (sta->pae.state == INITIALIZE))) { /* process WPA key pkt */ if (process_sup_wpa(nas->wpa, eapol, sta)) { /* Something wrong in WPA. Lose this pae. */ cleanup_sta(nas, sta, DOT11_RC_8021X_AUTH_FAIL, 0); } return; } } err(nas, "unknown EAPOL type %d", eapol->type); }
// dummy TBD int getUptime_ath9k(char *ifname, unsigned char *mac) { unsigned char rmac[32]; ether_etoa(mac, rmac); struct mac80211_info *mac80211_info; struct wifi_client_info *wc; mac80211_info = mac80211_assoclist(ifname); for (wc = mac80211_info->wci; wc; wc = wc->next) { if (!strcmp(wc->mac, rmac)) { free_wifi_clients(mac80211_info->wci); free(mac80211_info); return wc->uptime; } } free_wifi_clients(mac80211_info->wci); free(mac80211_info); return 0; }
/* * ATE get/set PLC parameter from/to factory partition, e.g. MAC, NMK */ int getPLC_para(int addr) { char abuf[64], ebuf[16]; if (__getPLC_para(ebuf, addr)) { memset(abuf, 0, sizeof(abuf)); if (addr == OFFSET_PLC_MAC) ether_etoa(ebuf, abuf); else key_etoa(ebuf, abuf); puts(abuf); } else return 0; return 1; }
void start_sysinit(void) { time_t tm = 0; if (!nvram_match("disable_watchdog", "1")) eval("watchdog"); /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); /* * network drivers */ fprintf(stderr, "load ATH Ethernet Driver\n"); system("insmod ag71xx || insmod ag7240_mod"); insmod("ledtrig-netdev"); FILE *fp = fopen("/dev/mtdblock/0", "rb"); char mac[32]; if (fp) { unsigned char buf2[256]; fseek(fp, 0x1fc00, SEEK_SET); fread(buf2, 256, 1, fp); fclose(fp); unsigned int copy[256]; int i; for (i = 0; i < 256; i++) copy[i] = buf2[i] & 0xff; sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); fprintf(stderr, "configure eth0 to %s\n", mac); MAC_SUB(mac); eval("ifconfig", "eth0", "hw", "ether", mac); MAC_ADD(mac); MAC_ADD(mac); fprintf(stderr, "configure eth1 to %s\n", mac); eval("ifconfig", "eth1", "hw", "ether", mac); #ifndef HAVE_ATH9K MAC_SUB(mac); #endif } eval("ifconfig", "eth0", "up"); eval("ifconfig", "eth1", "up"); #ifdef HAVE_SWCONFIG #ifdef HAVE_WDR2543 system("swconfig dev switch0 set reset 1"); system("swconfig dev switch0 set enable_vlan 1"); system("swconfig dev switch0 vlan 1 set ports \"1 2 3 4 9t\""); system("swconfig dev switch0 vlan 2 set ports \"0 9t\""); system("swconfig dev switch0 set apply"); eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD"); eval("vconfig", "add", "eth0", "1"); eval("vconfig", "add", "eth0", "2"); #else system("swconfig dev eth1 set reset 1"); system("swconfig dev eth1 set enable_vlan 0"); system("swconfig dev eth1 vlan 1 set ports \"0 1 2 3 4\""); system("swconfig dev eth1 set apply"); setEthLED(17,"eth0"); setSwitchLED(13,0x2); setSwitchLED(14,0x4); setSwitchLED(15,0x8); setSwitchLED(16,0x10); #endif #endif struct ifreq ifr; int s; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); close(s); } detect_wireless_devices(); #ifndef HAVE_ATH9K fprintf(stderr, "configure wifi0 to %s\n", mac); eval("ifconfig", "wifi0", "hw", "ether", mac); #endif //enable wlan led (card gpio based) #if defined(HAVE_WR841v7) || defined(HAVE_WR842) || defined(HAVE_MR3420) setWirelessLedPhy0(0); #else setWirelessLedPhy0(1); #endif led_control(LED_POWER, LED_ON); led_control(LED_SES, LED_OFF); led_control(LED_SES2, LED_OFF); led_control(LED_DIAG, LED_OFF); led_control(LED_BRIDGE, LED_OFF); led_control(LED_WLAN0, LED_OFF); led_control(LED_WLAN1, LED_OFF); led_control(LED_CONNECTED, LED_OFF); /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); return; cprintf("done\n"); }
void start_sysinit(void) { char buf[PATH_MAX]; struct stat tmp_stat; time_t tm = 0; eval("mknod", "/dev/gpio", "c", "127", "0"); if (!nvram_match("disable_watchdog", "1")) eval("watchdog"); /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); int brand = getRouterBrand(); /* * network drivers */ insmod("gemini_negmac"); #ifdef HAVE_WBD222 insmod("libata"); insmod("pata_gemini"); #endif eval("ifconfig", "eth0", "up"); #ifdef HAVE_WBD222 eval("ifconfig", "eth1", "up"); #endif struct ifreq ifr; int s; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); close(s); } detect_wireless_devices(); /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); //disable led's eval("gpio", "disable", "1"); eval("gpio", "disable", "2"); eval("gpio", "disable", "3"); eval("gpio", "disable", "5"); eval("hwclock", "-s"); return; cprintf("done\n"); }
void start_sysinit(void) { char buf[PATH_MAX]; struct stat tmp_stat; time_t tm = 0; mknod("/dev/mmc", S_IFBLK | 0660, makedev(126, 0)); mknod("/dev/mmc0", S_IFBLK | 0660, makedev(126, 1)); mknod("/dev/mmc1", S_IFBLK | 0660, makedev(126, 2)); mknod("/dev/mmc2", S_IFBLK | 0660, makedev(126, 3)); mknod("/dev/mmc3", S_IFBLK | 0660, makedev(126, 4)); eval("/bin/tar", "-xzf", "/dev/mtdblock/3", "-C", "/"); FILE *in = fopen("/tmp/nvram/nvram.db", "rb"); if (in != NULL) { fclose(in); eval("/usr/sbin/convertnvram"); eval("/sbin/mtd", "erase", "nvram"); nvram_commit(); } if (!nvram_match("disable_watchdog", "1")) eval("watchdog"); /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); #ifdef HAVE_RTG32 insmod("slhc"); insmod("ppp_generic"); insmod("ppp_async"); insmod("ppp_synctty"); insmod("ppp_mppe_mppc "); insmod("pppox"); insmod("pppoe"); #endif /* * network drivers */ #ifdef HAVE_HOTPLUG2 insmod("ar231x"); #else insmod("ar2313"); #endif detect_wireless_devices(); eval("ifconfig", "eth0", "up"); // wan system("swconfig dev eth0 set reset 1"); system("swconfig dev eth0 set enable_vlan 1"); #ifdef HAVE_RTG32 system("swconfig dev eth0 vlan 1 set ports \"0t 1 2 3 4\""); system("swconfig dev eth0 vlan 2 set ports \"0t 5\""); #else system("swconfig dev eth0 vlan 1 set ports \"0t 2 3 4 5\""); system("swconfig dev eth0 vlan 2 set ports \"0t 1\""); #endif system("swconfig dev eth0 set apply"); eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD"); eval("vconfig", "add", "eth0", "1"); eval("vconfig", "add", "eth0", "2"); struct ifreq ifr; int s; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); char macaddr[32]; strcpy(macaddr, ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr", macaddr); MAC_ADD(macaddr); ether_atoe(macaddr, (unsigned char *)ifr.ifr_hwaddr.sa_data); strncpy(ifr.ifr_name, "vlan2", IFNAMSIZ); ioctl(s, SIOCSIFHWADDR, &ifr); close(s); } eval("gpio", "enable", "1"); #ifdef HAVE_RTG32 writeproc("/proc/sys/dev/wifi0/ledpin", "7"); writeproc("/proc/sys/dev/wifi0/softled", "1"); #else writeproc("/proc/sys/dev/wifi0/ledpin", "0"); writeproc("/proc/sys/dev/wifi0/softled", "1"); #endif /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); return; }
void init_syspara(void) { unsigned char buffer[16]; unsigned char *dst; unsigned int bytes; int i; char macaddr[]="00:11:22:33:44:55"; char macaddr2[]="00:11:22:33:44:58"; char country_code[3]; char pin[9]; char productid[13]; char fwver[8]; char blver[20]; unsigned char txbf_para[33]; char ea[ETHER_ADDR_LEN]; nvram_set("buildno", rt_serialno); nvram_set("extendno", rt_extendno); nvram_set("buildinfo", rt_buildinfo); nvram_set("swpjverno", rt_swpjverno); /* /dev/mtd/2, RF parameters, starts from 0x40000 */ dst = buffer; bytes = 6; memset(buffer, 0, sizeof(buffer)); memset(country_code, 0, sizeof(country_code)); memset(pin, 0, sizeof(pin)); memset(productid, 0, sizeof(productid)); memset(fwver, 0, sizeof(fwver)); memset(txbf_para, 0, sizeof(txbf_para)); if (FRead(dst, OFFSET_MAC_ADDR, bytes)<0) { _dprintf("READ MAC address: Out of scope\n"); } else { if (buffer[0]!=0xff) ether_etoa(buffer, macaddr); } #if !defined(RTN14U) // single band if (FRead(dst, OFFSET_MAC_ADDR_2G, bytes)<0) { _dprintf("READ MAC address 2G: Out of scope\n"); } else { if (buffer[0]!=0xff) ether_etoa(buffer, macaddr2); } #endif #if defined(RTN14U) // single band if (!mssid_mac_validate(macaddr)) #else if (!mssid_mac_validate(macaddr) || !mssid_mac_validate(macaddr2)) #endif nvram_set("wl_mssid", "0"); else nvram_set("wl_mssid", "1"); #if defined(RTN14U) // single band nvram_set("et0macaddr", macaddr); nvram_set("et1macaddr", macaddr); #else //TODO: separate for different chipset solution nvram_set("et0macaddr", macaddr); nvram_set("et1macaddr", macaddr2); #endif if (FRead(dst, OFFSET_MAC_GMAC0, bytes)<0) dbg("READ MAC address GMAC0: Out of scope\n"); else { if (buffer[0]==0xff) { if (ether_atoe(macaddr, ea)) FWrite(ea, OFFSET_MAC_GMAC0, 6); } } if (FRead(dst, OFFSET_MAC_GMAC2, bytes)<0) dbg("READ MAC address GMAC2: Out of scope\n"); else { if (buffer[0]==0xff) { if (ether_atoe(macaddr2, ea)) FWrite(ea, OFFSET_MAC_GMAC2, 6); } } /* reserved for Ralink. used as ASUS country code. */ #if ! defined(RTCONFIG_NEW_REGULATION_DOMAIN) dst = (unsigned char*) country_code; bytes = 2; if (FRead(dst, OFFSET_COUNTRY_CODE, bytes)<0) { _dprintf("READ ASUS country code: Out of scope\n"); nvram_set("wl_country_code", ""); } else { chk_valid_country_code(country_code); nvram_set("wl_country_code", country_code); nvram_set("wl0_country_code", country_code); nvram_set("wl1_country_code", country_code); } #else /* ! RTCONFIG_NEW_REGULATION_DOMAIN */ dst = buffer; bytes = MAX_REGSPEC_LEN; memset(dst, 0, MAX_REGSPEC_LEN+1); if(FRead(dst, REGSPEC_ADDR, bytes) < 0) nvram_set("reg_spec", "FCC"); // DEFAULT else { for (i=(MAX_REGSPEC_LEN-1);i>=0;i--) { if ((dst[i]==0xff) || (dst[i]=='\0')) dst[i]='\0'; } if (dst[0]!=0x00) nvram_set("reg_spec", dst); else nvram_set("reg_spec", "FCC"); // DEFAULT } if (FRead(dst, REG2G_EEPROM_ADDR, MAX_REGDOMAIN_LEN)<0 || memcmp(dst,"2G_CH", 5) != 0) { _dprintf("READ ASUS country code: Out of scope\n"); nvram_set("wl_country_code", ""); nvram_set("wl0_country_code", "DB"); nvram_set("wl_reg_2g", "2G_CH14"); } else { for(i = 0; i < MAX_REGDOMAIN_LEN; i++) if(dst[i] == 0xff || dst[i] == 0) break; dst[i] = 0; nvram_set("wl_reg_2g", dst); if (strcmp(dst, "2G_CH11") == 0) nvram_set("wl0_country_code", "US"); else if (strcmp(dst, "2G_CH13") == 0) nvram_set("wl0_country_code", "GB"); else if (strcmp(dst, "2G_CH14") == 0) nvram_set("wl0_country_code", "DB"); else nvram_set("wl0_country_code", "DB"); } if (FRead(dst, REG5G_EEPROM_ADDR, MAX_REGDOMAIN_LEN)<0 || memcmp(dst,"5G_", 3) != 0) { _dprintf("READ ASUS country code: Out of scope\n"); nvram_set("wl_country_code", ""); nvram_set("wl1_country_code", "DB"); nvram_set("wl_reg_5g", "5G_ALL"); } else { for(i = 0; i < MAX_REGDOMAIN_LEN; i++) if(dst[i] == 0xff || dst[i] == 0) break; dst[i] = 0; nvram_set("wl_reg_5g", dst); if (strcmp(dst, "5G_BAND1") == 0) nvram_set("wl1_country_code", "GB"); else if (strcmp(dst, "5G_BAND123") == 0) nvram_set("wl1_country_code", "GB"); else if (strcmp(dst, "5G_BAND14") == 0) nvram_set("wl1_country_code", "US"); else if (strcmp(dst, "5G_BAND24") == 0) nvram_set("wl1_country_code", "TW"); else if (strcmp(dst, "5G_BAND4") == 0) nvram_set("wl1_country_code", "CN"); else nvram_set("wl1_country_code", "DB"); } #endif /* ! RTCONFIG_NEW_REGULATION_DOMAIN */ #if defined(RTN56U) || defined(RTCONFIG_DSL) if (nvram_match("wl_country_code", "BR")) { nvram_set("wl_country_code", "UZ"); nvram_set("wl0_country_code", "UZ"); nvram_set("wl1_country_code", "UZ"); } #endif if (nvram_match("wl_country_code", "HK") && nvram_match("preferred_lang", "")) nvram_set("preferred_lang", "TW"); /* reserved for Ralink. used as ASUS pin code. */ dst = (char*)pin; bytes = 8; if (FRead(dst, OFFSET_PIN_CODE, bytes)<0) { _dprintf("READ ASUS pin code: Out of scope\n"); nvram_set("wl_pin_code", ""); } else { if ((unsigned char)pin[0]!=0xff) nvram_set("secret_code", pin); else nvram_set("secret_code", "12345670"); } dst = buffer; bytes = 16; if (linuxRead(dst, 0x20, bytes)<0) /* The "linux" MTD partition, offset 0x20. */ { fprintf(stderr, "READ firmware header: Out of scope\n"); nvram_set("productid", "unknown"); nvram_set("firmver", "unknown"); } else { strncpy(productid, buffer + 4, 12); productid[12] = 0; sprintf(fwver, "%d.%d.%d.%d", buffer[0], buffer[1], buffer[2], buffer[3]); nvram_set("productid", trim_r(productid)); nvram_set("firmver", trim_r(fwver)); } memset(buffer, 0, sizeof(buffer)); FRead(buffer, OFFSET_BOOT_VER, 4); // sprintf(blver, "%c.%c.%c.%c", buffer[0], buffer[1], buffer[2], buffer[3]); sprintf(blver, "%s-0%c-0%c-0%c-0%c", trim_r(productid), buffer[0], buffer[1], buffer[2], buffer[3]); nvram_set("blver", trim_r(blver)); _dprintf("bootloader version: %s\n", nvram_safe_get("blver")); _dprintf("firmware version: %s\n", nvram_safe_get("firmver")); dst = txbf_para; int count_0xff = 0; if (FRead(dst, OFFSET_TXBF_PARA, 33) < 0) { fprintf(stderr, "READ TXBF PARA address: Out of scope\n"); } else { for (i = 0; i < 33; i++) { if (txbf_para[i] == 0xff) count_0xff++; /* if ((i % 16) == 0) fprintf(stderr, "\n"); fprintf(stderr, "%02x ", (unsigned char) txbf_para[i]); */ } /* fprintf(stderr, "\n"); fprintf(stderr, "TxBF parameter 0xFF count: %d\n", count_0xff); */ } if (count_0xff == 33) nvram_set("wl1_txbf_en", "0"); else nvram_set("wl1_txbf_en", "1"); #if defined (RTCONFIG_WLMODULE_RT3352_INIC_MII) #define EEPROM_INIC_SIZE (512) #define EEPROM_INIT_ADDR 0x48000 #define EEPROM_INIT_FILE "/etc/Wireless/iNIC/iNIC_e2p.bin" { char eeprom[EEPROM_INIC_SIZE]; if(FRead(eeprom, EEPROM_INIT_ADDR, sizeof(eeprom)) < 0) { fprintf(stderr, "FRead(eeprom, 0x%08x, 0x%x) failed\n", EEPROM_INIT_ADDR, sizeof(eeprom)); } else { FILE *fp; char *filepath = EEPROM_INIT_FILE; system("mkdir -p /etc/Wireless/iNIC/"); if((fp = fopen(filepath, "w")) == NULL) { fprintf(stderr, "fopen(%s) failed!!\n", filepath); } else { if(fwrite(eeprom, sizeof(eeprom), 1, fp) < 1) { perror("fwrite(eeprom)"); } fclose(fp); } } } #endif #ifdef RA_SINGLE_SKU #if defined(RTAC52U) { char *reg_spec; reg_spec = nvram_safe_get("reg_spec"); create_SingleSKU("/etc/Wireless/RT2860", "", reg_spec); create_SingleSKU("/etc/Wireless/iNIC", "_5G", reg_spec); } #endif /* RTAC52U */ #endif /* RA_SINGLE_SKU */ { #ifdef RTCONFIG_ODMPID char modelname[16]; FRead(modelname, OFFSET_ODMPID, sizeof(modelname)); modelname[sizeof(modelname)-1] = '\0'; if(modelname[0] != 0 && (unsigned char)(modelname[0]) != 0xff && is_valid_hostname(modelname) && strcmp(modelname, "ASUS")) { nvram_set("odmpid", modelname); } else #endif nvram_unset("odmpid"); } nvram_set("firmver", rt_version); nvram_set("productid", rt_buildname); }
void start_sysinit(void) { char buf[PATH_MAX]; struct stat tmp_stat; time_t tm = 0; cprintf("sysinit() proc\n"); /* * /proc */ mknod("/dev/mmc",S_IFBLK|0660,makedev(126,0)); mknod("/dev/mmc0",S_IFBLK|0660,makedev(126,1)); mknod("/dev/mmc1",S_IFBLK|0660,makedev(126,2)); mknod("/dev/mmc2",S_IFBLK|0660,makedev(126,3)); mknod("/dev/mmc3",S_IFBLK|0660,makedev(126,4)); mkdir("/dev/mtd",0700); mknod("/dev/mtd/0",S_IFCHR|0644,makedev(90,0)); mknod("/dev/mtd/0ro",S_IFCHR|0644,makedev(90,1)); mknod("/dev/mtd/1",S_IFCHR|0644,makedev(90,2)); mknod("/dev/mtd/1ro",S_IFCHR|0644,makedev(90,3)); mknod("/dev/mtd/2",S_IFCHR|0644,makedev(90,4)); mknod("/dev/mtd/2ro",S_IFCHR|0644,makedev(90,5)); mknod("/dev/mtd/3",S_IFCHR|0644,makedev(90,6)); mknod("/dev/mtd/3ro",S_IFCHR|0644,makedev(90,7)); mknod("/dev/mtd/4",S_IFCHR|0644,makedev(90,8)); mknod("/dev/mtd/4ro",S_IFCHR|0644,makedev(90,9)); cprintf("sysinit() setup console\n"); /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); /* * load some netfilter stuff */ #ifndef HAVE_WP54G #ifndef HAVE_NP28G insmod("nf_conntrack_ftp"); insmod("nf_conntrack_irc"); insmod("nf_conntrack_netbios_ns"); insmod("nf_conntrack_pptp"); insmod("nf_conntrack_proto_gre"); insmod("nf_conntrack_proto_udplite"); insmod("nf_conntrack_tftp"); insmod("xt_CLASSIFY"); insmod("xt_MARK"); insmod("xt_TCPMSS"); insmod("xt_length"); insmod("xt_limit"); insmod("xt_multiport"); insmod("xt_pkttype"); insmod("xt_state"); insmod("xt_tcpmss"); insmod("xt_u32"); insmod("iptable_filter"); insmod("iptable_mangle"); insmod("nf_nat"); insmod("iptable_nat"); insmod("nf_nat_ftp"); insmod("nf_nat_irc"); insmod("nf_nat_pptp"); insmod("nf_nat_proto_gre"); insmod("nf_nat_tftp"); insmod("ipt_LOG"); insmod("ipt_MASQUERADE"); insmod("ipt_REDIRECT"); insmod("ipt_REJECT"); insmod("ipt_ULOG"); insmod("ipt_TRIGGER"); insmod("ipt_iprange"); insmod("ipt_ipp2p"); insmod("ipt_layer7"); insmod("ipt_webstr"); // ppp drivers insmod("slhc"); insmod("ppp_generic"); insmod("ppp_async"); insmod("ppp_synctty"); insmod("ppp_mppe_mppc"); insmod("pppox"); insmod("pppoe"); #endif #endif insmod("adm5120_wdt"); insmod("adm5120sw"); if (getRouterBrand() != ROUTER_BOARD_WP54G && getRouterBrand() != ROUTER_BOARD_NP28G) { unsigned char mac[6]; char eabuf[32]; char mtdpath[32]; memset(mac, 0, 6); FILE *fp; int mtd = getMTD("boot"); int foundmac = 0; sprintf(mtdpath, "/dev/mtdblock/%d", mtd); fp = fopen(mtdpath, "rb"); if (fp != NULL) { //check for osbridge fseek(fp, 0xff90 - 2, SEEK_SET); unsigned char os[32]; fread(os, 32, 1, fp); if (strcmp(os, "OSBRiDGE 5XLi") == 0) { foundmac = 1; fprintf(stderr, "found OSBRiDGE 5XLi\n"); nvram_set("DD_BOARD", "OSBRiDGE 5LXi"); fseek(fp, 0xff82, SEEK_SET); fread(os, 12, 1, fp); int i; int count = 0; if (memcmp(os, "0050fc488130", 12) == 0) { //force change mac fclose(fp); start_change_mac(); sys_reboot(); } for (i = 0; i < 6; i++) { mac[i] = toNumeric(os[count++]) * 16; mac[i] |= toNumeric(os[count++]); } struct ifreq ifr; int s; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); memcpy((unsigned char *)ifr.ifr_hwaddr. sa_data, mac, 6); ioctl(s, SIOCSIFHWADDR, &ifr); close(s); } if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *) ifr. ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr", ether_etoa((unsigned char *) ifr. ifr_hwaddr.sa_data, eabuf)); close(s); } } if (!foundmac) { int s = searchfor(fp, "mgmc", 0x20000 - 5); if (s != -1) { fread(mac, 6, 1, fp); struct ifreq ifr; int s; foundmac = 1; fprintf(stderr, "found Tonze-AP120\n"); if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); memcpy((unsigned char *) ifr.ifr_hwaddr.sa_data, mac, 6); ioctl(s, SIOCSIFHWADDR, &ifr); close(s); } if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *) ifr.ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr", ether_etoa((unsigned char *) ifr.ifr_hwaddr.sa_data, eabuf)); close(s); } } } if (foundmac == 0) { fprintf(stderr, "error: no valid mac address found for eth0\n"); } fclose(fp); } } else { struct mylo_board_params params; char mtdpath[32]; FILE *fp; int mtd = getMTD("boot"); int foundmac = 0; struct ifreq ifr; int s; char eabuf[32]; sprintf(mtdpath, "/dev/mtdblock/%d", mtd); fp = fopen(mtdpath, "rb"); if (fp != NULL) { fseek(fp, 0xf800, SEEK_SET); fread(¶ms, sizeof(params), 1, fp); fclose(fp); if (params.magic == 0x20021103) { fprintf(stderr, "Found compex board magic!\n"); if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); memcpy((unsigned char *)ifr.ifr_hwaddr. sa_data, params.addr[0].mac, 6); ioctl(s, SIOCSIFHWADDR, &ifr); close(s); } if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { strncpy(ifr.ifr_name, "eth1", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); memcpy((unsigned char *)ifr.ifr_hwaddr. sa_data, params.addr[1].mac, 6); ioctl(s, SIOCSIFHWADDR, &ifr); close(s); } if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *) ifr. ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr", ether_etoa((unsigned char *) ifr. ifr_hwaddr.sa_data, eabuf)); close(s); } } } } /* * network drivers */ detect_wireless_devices(); if (!nvram_match("disable_watchdog", "1")) eval("watchdog"); #ifdef HAVE_WP54G writeproc("/proc/sys/dev/wifi0/ledpin","6"); writeproc("/proc/sys/dev/wifi0/softled","1"); #endif /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); return; }
void vlan_init(int portmask) { int phyUnit; unsigned int phyBase; unsigned int phyReg; unsigned int phyAddr; int i; int numports = 5; for (i = 0; i < numports - 1; i++) // last one will be wan port { ipPhyInfo[i].VLANTableSetting = IP_LAN_PORT_VLAN; } ipPhyInfo[i++].VLANTableSetting = IP_WAN_PORT_VLAN; ipPhyInfo[i].VLANTableSetting = IP_LAN_PORT_VLAN; ipPhyInfo[i].isEnetPort = FALSE; ipPhyInfo[i].isPhyAlive = TRUE; ipPhyInfo[i++].phyAddr = 0x0; numports = i; fprintf(stderr, "Reset ICPLUS Phy\n"); for (phyUnit = 0; phyUnit < numports; phyUnit++) { if (((1 << phyUnit) & portmask)) { phyAddr = IP_PHYADDR(phyUnit); setPhy(phyAddr, IP_PHY_CONTROL, IP_CTRL_SOFTWARE_RESET); } } sleep(1); fprintf(stderr, "Start Autonegotiation\n"); for (phyUnit = 0; phyUnit < numports; phyUnit++) { if (((1 << phyUnit) & portmask)) { phyAddr = IP_PHYADDR(phyUnit); setPhy(phyAddr, IP_AUTONEG_ADVERT, IP_ADVERTISE_ALL); setPhy(phyAddr, IP_PHY_CONTROL, IP_CTRL_AUTONEGOTIATION_ENABLE | IP_CTRL_START_AUTONEGOTIATION); } } int timeout = 5; for (phyUnit = 0; (phyUnit < numports); phyUnit++) { if (((1 << phyUnit) & portmask)) { for (;;) { phyAddr = IP_PHYADDR(phyUnit); int phyHwStatus = getPhy(phyAddr, IP_PHY_STATUS); if (IP_AUTONEG_DONE(phyHwStatus)) { fprintf(stderr, "Port %d, Neg Success\n", phyUnit); break; } if (timeout == 0) { fprintf(stderr, "Port %d, Negogiation timeout\n", phyUnit); break; } if (--timeout == 0) { fprintf(stderr, "Port %d, Negogiation timeout\n", phyUnit); break; } usleep(150); } } } fprintf(stderr, "Setup VLANS\n"); /* * setPhy(29,24,0); setPhy(29,25,0); setPhy(29,26,0); setPhy(29,27,0); * setPhy(29,28,2); setPhy(29,30,0); setPhy(29,23,0x07c2); * setPhy(30,1,0x002f); setPhy(30,2,0x0030); setPhy(30,9,0x1089); */ unsigned int phy1Reg = 0; unsigned int phy2Reg = 0; unsigned int phy23Reg = 0; unsigned int phy9Reg = 0; for (phyUnit = 0; phyUnit < numports; phyUnit++) { if (((1 << phyUnit) & portmask)) { setPhy(IP_GLOBAL_PHY29_ADDR, IP_GLOBAL_PHY29_24_REG + ((phyUnit == 5) ? (phyUnit + 1) : phyUnit), IP_VLAN_TABLE_SETTING(phyUnit)); fprintf(stderr, "write register %d, addr %d with %X\n", IP_GLOBAL_PHY29_ADDR, IP_GLOBAL_PHY29_24_REG + ((phyUnit == 5) ? (phyUnit + 1) : phyUnit), IP_VLAN_TABLE_SETTING(phyUnit)); if (IP_IS_ENET_PORT(phyUnit)) { if (IP_IS_WAN_PORT(phyUnit)) { phy2Reg |= ((1 << phyUnit) << IP_VLAN2_OUTPUT_PORT_MASK_S); } else { phy1Reg |= ((1 << phyUnit) << IP_VLAN0_OUTPUT_PORT_MASK_S); } phy23Reg = phy23Reg | ((1 << phyUnit) << IP_PORTX_REMOVE_TAG_S); phy23Reg = phy23Reg & ~((1 << phyUnit) << IP_PORTX_ADD_TAG_S); } else { phy1Reg |= ((1 << phyUnit) << IP_VLAN0_OUTPUT_PORT_MASK_S); phy2Reg |= ((1 << phyUnit) << IP_VLAN2_OUTPUT_PORT_MASK_S); phy23Reg = phy23Reg | (1 << IP_PORT5_ADD_TAG_S); phy23Reg = phy23Reg & ~(1 << IP_PORT5_REMOVE_TAG_S); } } } phy9Reg = 0; //getPhy(IP_GLOBAL_PHY30_ADDR,IP_GLOBAL_PHY30_9_REG); phy9Reg = phy9Reg | TAG_VLAN_ENABLE; phy9Reg = phy9Reg & ~VID_INDX_SEL_M; phy9Reg = phy9Reg | 1; //1 vlan group used for lan phy9Reg = phy9Reg | 1 << 3; //enable smart mac phy9Reg = phy9Reg | 1 << 12; //port 4 is a wan port (required for smart mac) fprintf(stderr, "write register %d, addr %d with %X\n", IP_GLOBAL_PHY29_ADDR, IP_GLOBAL_PHY29_23_REG, phy23Reg); fprintf(stderr, "write register %d, addr %d with %X\n", IP_GLOBAL_PHY30_ADDR, IP_GLOBAL_PHY30_1_REG, phy1Reg); fprintf(stderr, "write register %d, addr %d with %X\n", IP_GLOBAL_PHY30_ADDR, IP_GLOBAL_PHY30_2_REG, phy2Reg); fprintf(stderr, "write register %d, addr %d with %X\n", IP_GLOBAL_PHY30_ADDR, IP_GLOBAL_PHY30_9_REG, phy9Reg); setPhy(IP_GLOBAL_PHY29_ADDR, IP_GLOBAL_PHY29_23_REG, phy23Reg); setPhy(IP_GLOBAL_PHY30_ADDR, IP_GLOBAL_PHY30_1_REG, phy1Reg); setPhy(IP_GLOBAL_PHY30_ADDR, IP_GLOBAL_PHY30_2_REG, phy2Reg); setPhy(IP_GLOBAL_PHY30_ADDR, IP_GLOBAL_PHY30_9_REG, phy9Reg); // // echo "echo \"WRITE 29 23 07c2\" > ".$mii_dev."\n"; // // echo "echo \"WRITE 29 24 0\" > ".$mii_dev."\n"; /* PORT0 Default VLAN ID */ // echo "echo \"WRITE 29 25 0\" > ".$mii_dev."\n"; /* PORT1 Default VLAN ID */ // echo "echo \"WRITE 29 26 0\" > ".$mii_dev."\n"; /* PORT2 Default VLAN ID */ // echo "echo \"WRITE 29 27 0\" > ".$mii_dev."\n"; /* PORT3 Default VLAN ID */ // echo "echo \"WRITE 29 28 2\" > ".$mii_dev."\n"; /* PORT4 Default VLAN ID */ // echo "echo \"WRITE 29 30 0\" > ".$mii_dev."\n"; /* PORT5 Default VLAN ID (CPU) */ // echo "echo \"WRITE 29 23 07c2\" > ".$mii_dev."\n"; // echo "echo \"WRITE 30 1 002f\" > ".$mii_dev."\n"; /* Port 5,3,2,1,0 = VLAN 0 */ // echo "echo \"WRITE 30 2 0030\" > ".$mii_dev."\n"; /* Port 5,4 = VLAN 2 */ // echo "echo \"WRITE 30 9 1089\" > ".$mii_dev."\n"; eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD"); eval("vconfig", "add", "eth0", "0"); eval("vconfig", "add", "eth0", "2"); struct ifreq ifr; int s; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); char macaddr[32]; strcpy(macaddr, ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr", macaddr); // MAC_ADD (macaddr); ether_atoe(macaddr, (unsigned char *)ifr.ifr_hwaddr.sa_data); strncpy(ifr.ifr_name, "vlan2", IFNAMSIZ); ioctl(s, SIOCSIFHWADDR, &ifr); close(s); } eval("ifconfig", "vlan0", "promisc"); eval("ifconfig", "vlan2", "promisc"); }
int ej_active_wireless_if(webs_t wp, int argc, char_t ** argv, char *iface, char *visible, int cnt) { int rssi = 0, noise = 0; FILE *fp2; char *mode; char mac[30]; char line[80]; int macmask; macmask = atoi(argv[0]); if (!ifexists(iface)) return cnt; unlink(RSSI_TMP); char wlmode[32]; sprintf(wlmode, "%s_mode", visible); mode = nvram_safe_get(wlmode); unsigned char buf[WLC_IOCTL_MAXLEN]; memset(buf, 0, WLC_IOCTL_MAXLEN); // get_wdev int r = getassoclist(iface, buf); if (r < 0) return cnt; struct maclist *maclist = (struct maclist *)buf; int i; for (i = 0; i < maclist->count; i++) { ether_etoa((uint8 *) & maclist->ea[i], mac); rssi = 0; noise = 0; // get rssi value if (strcmp(mode, "ap") && strcmp(mode, "apsta") && strcmp(mode, "apstawet")) sysprintf("wl -i %s rssi > %s", iface, RSSI_TMP); else sysprintf("wl -i %s rssi \"%s\" > %s", iface, mac, RSSI_TMP); // get noise value if not ap mode // if (strcmp (mode, "ap")) // snprintf (cmd, sizeof (cmd), "wl -i %s noise >> %s", iface, // RSSI_TMP); // system2 (cmd); // get RSSI value for mac fp2 = fopen(RSSI_TMP, "r"); if (fgets(line, sizeof(line), fp2) != NULL) { // get rssi if (sscanf(line, "%d", &rssi) != 1) continue; noise = getNoise(iface, NULL); /* * if (strcmp (mode, "ap") && fgets (line, sizeof (line), fp2) != * NULL && sscanf (line, "%d", &noise) != 1) continue; */ // get noise for client/wet mode fclose(fp2); } if (nvram_match("maskmac", "1") && macmask) { mac[0] = 'x'; mac[1] = 'x'; mac[3] = 'x'; mac[4] = 'x'; mac[6] = 'x'; mac[7] = 'x'; mac[9] = 'x'; mac[10] = 'x'; } if (cnt) websWrite(wp, ","); cnt++; int rxrate[32]; int txrate[32]; int time[32]; strcpy(rxrate, "N/A"); strcpy(txrate, "N/A"); strcpy(time, "N/A"); #ifndef WL_STA_SCBSTATS #define WL_STA_SCBSTATS 0x4000 /* Per STA debug stats */ #endif sta_info_compat_t *sta; sta_info_compat_old_t *staold; char *param; int buflen; char buf[WLC_IOCTL_MEDLEN]; strcpy(buf, "sta_info"); buflen = strlen(buf) + 1; param = (char *)(buf + buflen); memcpy(param, (char *)&maclist->ea[i], ETHER_ADDR_LEN); if (!wl_ioctl(iface, WLC_GET_VAR, &buf[0], WLC_IOCTL_MEDLEN)) { /* display the sta info */ sta = (sta_info_compat_t *) buf; if (sta->ver == 2) { staold = (sta_info_compat_old_t *) buf; if (staold->flags & WL_STA_SCBSTATS) { int tx = staold->tx_rate; int rx = staold->rx_rate; if (tx > 0) sprintf(txrate, "%dM", tx / 1000); if (rx > 0) sprintf(rxrate, "%dM", rx / 1000); strcpy(time, UPTIME(staold->in)); } } else { // sta->ver == 3 if (sta->flags & WL_STA_SCBSTATS) { int tx = sta->tx_rate; int rx = sta->rx_rate; if (tx > 0) sprintf(txrate, "%dM", tx / 1000); if (rx > 0) sprintf(rxrate, "%dM", rx / 1000); strcpy(time, UPTIME(sta->in)); } } } /* * if (!strcmp (mode, "ap")) { noise = getNoise(iface,NULL); // null * only for broadcom } */ int qual = rssi * 124 + 11600; qual /= 10; websWrite(wp, "'%s','%s','%s','%s','%s','%d','%d','%d','%d'", mac, iface, time, txrate, rxrate, rssi, noise, rssi - noise, qual); } unlink(RSSI_TMP); return cnt; }
static void psta_keepalive() { char tmp[NVRAM_BUFSIZE], prefix[] = "wlXXXXXXXXXX_"; char *name = NULL; struct maclist *mac_list = NULL; int mac_list_size, i, unit; int psta = 0; struct ether_addr bssid; unsigned char bssid_null[6] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; char macaddr[18]; unit = nvram_get_int("wlc_band"); snprintf(prefix, sizeof(prefix), "wl%d_", unit); if (!nvram_match(strcat_r(prefix, "mode", tmp), "psta")) goto PSTA_ERR; name = nvram_safe_get(strcat_r(prefix, "ifname", tmp)); if (wl_ioctl(name, WLC_GET_BSSID, &bssid, ETHER_ADDR_LEN) != 0) goto PSTA_ERR; else if (!memcmp(&bssid, bssid_null, 6)) goto PSTA_ERR; /* buffers and length */ mac_list_size = sizeof(mac_list->count) + MAX_STA_COUNT * sizeof(struct ether_addr); mac_list = malloc(mac_list_size); if (!mac_list) goto PSTA_ERR; /* query wl for authenticated sta list */ strcpy((char*)mac_list, "authe_sta_list"); if (wl_ioctl(name, WLC_GET_VAR, mac_list, mac_list_size)) { free(mac_list); goto PSTA_ERR; } /* query sta_info for each STA and output one table row each */ if (mac_list->count) { if (nvram_match(strcat_r(prefix, "akm", tmp), "")) psta = 1; else for (i = 0; i < mac_list->count; i++) { if (wl_autho(name, &mac_list->ea[i])) { psta = 1; break; } } } PSTA_ERR: if (psta) { count_bss_down = 0; ether_etoa((const unsigned char *) &bssid, macaddr); if (psta_debug) dbg("psta send keepalive nulldata to %s\n", macaddr); eval("wl", "-i", name, "send_nulldata", macaddr); #ifdef PSTA_DEBUG count = (count + 1) % 10; if (!count) check_wl_rate(name); #endif } else { if (psta_debug) dbg("psta disconnected\n"); if (++count_bss_down > 9) { count_bss_down = 0; if (wl_scan(unit)) { eval("wlconf", name, "down"); eval("wlconf", name, "up"); eval("wlconf", name, "start"); } } else { eval("wl", "-i", name, "bss", "down"); eval("wl", "-i", name, "down"); eval("wl", "-i", name, "up"); eval("wl", "-i", name, "bss", "up"); } } if (mac_list) free(mac_list); }
void start_sysinit(void) { time_t tm = 0; if (!nvram_match("disable_watchdog", "1")) eval("watchdog"); /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); /* * network drivers */ fprintf(stderr, "load ATH Ethernet Driver\n"); system("insmod ag71xx || insmod ag7240_mod"); FILE *fp = fopen("/dev/mtdblock/6", "rb"); if (fp) { // fseek(fp, 0xFF0000, SEEK_SET); fseek(fp, DDMACOFFSET, SEEK_SET); unsigned char buf[20]; fread(&buf[0], 6, 1, fp); char mac[20]; int i; unsigned int copy[20]; for (i = 0; i < 12; i++) copy[i] = buf[i] & 0xff; sprintf(mac, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); fprintf(stderr, "configure ETH0 to %s\n", mac); nvram_set("et0macaddr_safe", mac); nvram_set("et0macaddr", mac); eval("ifconfig", "eth0", "hw", "ether", mac); fread(&buf[6], 6, 1, fp); for (i = 0; i < 12; i++) copy[i] = buf[i] & 0xff; sprintf(mac, "%02X:%02X:%02X:%02X:%02X:%02X", copy[6], copy[7], copy[8], copy[9], copy[10], copy[11]); fprintf(stderr, "configure ETH1 to %s\n", mac); eval("ifconfig", "eth1", "hw", "ether", mac); fclose(fp); } // eval("ifconfig", "eth0", "up"); // eval("ifconfig", "eth1", "up"); struct ifreq ifr; int s; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); close(s); } detect_wireless_devices(); led_control(LED_POWER, LED_ON); led_control(LED_SES, LED_OFF); led_control(LED_DIAG, LED_OFF); led_control(LED_BRIDGE, LED_OFF); led_control(LED_WLAN0, LED_OFF); led_control(LED_CONNECTED, LED_OFF); system2("echo 1 >/proc/sys/dev/wifi0/ledpin"); system2("echo 1 >/proc/sys/dev/wifi0/softled"); /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); return; cprintf("done\n"); }
void vlan_init(int numports) { int phyUnit; UINT16 phyHwStatus; UINT16 timeout; int liveLinks = 0; UINT32 phyBase = 0; BOOL foundPhy = FALSE; UINT32 phyAddr; UINT32 reg = 0; /* * Reset PHYs */ for (phyUnit = 0; phyUnit < ADM_PHY_MAX; phyUnit++) { if (!ADM_IS_ETHUNIT(phyUnit, 0)) { continue; } phyAddr = ADM_PHYADDR(phyUnit); setPhy(phyAddr, ADM_PHY_CONTROL, ADM_CTRL_SOFTWARE_RESET); } /* * After the phy is reset, it takes a little while before * it can respond properly. */ sleep(1); /* * Verify that the switch is what we think it is, and that it's ready */ adm_verifyReady(0); /* * LAN SETTING: enable Auto-MDIX */ phyAddr = ADM_SW_PHY_PORT0_REG / ADM_PHY_BASE_REG_NUM; reg = getPhy(phyAddr, ADM_SW_PHY_PORT0_REG); reg |= ADM_SW_AUTO_MDIX_EN; setPhy(phyAddr, ADM_SW_PHY_PORT0_REG, reg); phyAddr = ADM_SW_PHY_PORT1_REG / ADM_PHY_BASE_REG_NUM; reg = getPhy(phyAddr, ADM_SW_PHY_PORT1_REG); reg |= ADM_SW_AUTO_MDIX_EN; setPhy(phyAddr, ADM_SW_PHY_PORT1_REG, reg); phyAddr = ADM_SW_PHY_PORT2_REG / ADM_PHY_BASE_REG_NUM; getPhy(phyAddr, ADM_SW_PHY_PORT2_REG); reg |= ADM_SW_AUTO_MDIX_EN; setPhy(phyAddr, ADM_SW_PHY_PORT2_REG, reg); phyAddr = ADM_SW_PHY_PORT3_REG / ADM_PHY_BASE_REG_NUM; reg = getPhy(phyAddr, ADM_SW_PHY_PORT3_REG); reg |= ADM_SW_AUTO_MDIX_EN; setPhy(phyAddr, ADM_SW_PHY_PORT3_REG, reg); phyAddr = ADM_SW_PHY_PORT4_REG / ADM_PHY_BASE_REG_NUM; reg = getPhy(phyAddr, ADM_SW_PHY_PORT4_REG); reg |= ADM_SW_AUTO_MDIX_EN; setPhy(phyAddr, ADM_SW_PHY_PORT4_REG, reg); phyAddr = ADM_SW_PHY_PORT5_REG / ADM_PHY_BASE_REG_NUM; reg = getPhy(phyAddr, ADM_SW_PHY_PORT5_REG); reg |= ADM_SW_AUTO_MDIX_EN; setPhy(phyAddr, ADM_SW_PHY_PORT5_REG, reg); /* * See if there's any configuration data for this enet */ for (phyUnit = 0; phyUnit < ADM_PHY_MAX; phyUnit++) { if (ADM_ETHUNIT(phyUnit) != 0) { continue; } foundPhy = TRUE; break; } if (!foundPhy) { return FALSE; /* No PHY's configured for this ethUnit */ } /* * start auto negogiation on each phy */ for (phyUnit = 0; phyUnit < ADM_PHY_MAX; phyUnit++) { if (!ADM_IS_ETHUNIT(phyUnit, 0)) { continue; } phyAddr = ADM_PHYADDR(phyUnit); setPhy(phyAddr, ADM_AUTONEG_ADVERT, ADM_ADVERTISE_ALL); setPhy(phyAddr, ADM_PHY_CONTROL, ADM_CTRL_AUTONEGOTIATION_ENABLE | ADM_CTRL_START_AUTONEGOTIATION); } /* * Wait up to .75 seconds for ALL associated PHYs to finish * autonegotiation. The only way we get out of here sooner is * if ALL PHYs are connected AND finish autonegotiation. */ timeout = 15; for (phyUnit = 0; (phyUnit < ADM_PHY_MAX) /* && (timeout > 0) */ ; phyUnit++) { if (!ADM_IS_ETHUNIT(phyUnit, 0)) { continue; } for (;;) { phyAddr = ADM_PHYADDR(phyUnit); phyHwStatus = getPhy(phyAddr, ADM_PHY_STATUS); if (ADM_AUTONEG_DONE(phyHwStatus)) { fprintf(stderr, "Port %d, Negotiation Success\n", phyUnit); break; } if (timeout == 0) { fprintf(stderr, "Port %d, Negotiation timeout\n", phyUnit); break; } if (--timeout == 0) { fprintf(stderr, "Port %d, Negotiation timeout\n", phyUnit); break; } usleep(75); } } /* * All PHYs have had adequate time to autonegotiate. * Now initialize software status. * * It's possible that some ports may take a bit longer * to autonegotiate; but we can't wait forever. They'll * get noticed by mv_phyCheckStatusChange during regular * polling activities. */ for (phyUnit = 0; phyUnit < ADM_PHY_MAX; phyUnit++) { if (adm_phyIsLinkAlive(phyUnit)) { liveLinks++; ADM_IS_PHY_ALIVE(phyUnit) = TRUE; } else { ADM_IS_PHY_ALIVE(phyUnit) = FALSE; } fprintf(stderr, "adm_phySetup: eth%d phy%d: Phy Status=%4.4x\n", 0, phyUnit, getPhy(ADM_PHYADDR(phyUnit), ADM_PHY_STATUS)); } config_vlan(); eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD"); eval("vconfig", "add", "eth0", "1"); eval("vconfig", "add", "eth0", "2"); struct ifreq ifr; int s; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); char macaddr[32]; strcpy(macaddr, ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr", macaddr); MAC_ADD(macaddr); ether_atoe(macaddr, (unsigned char *)ifr.ifr_hwaddr.sa_data); strncpy(ifr.ifr_name, "vlan2", IFNAMSIZ); ioctl(s, SIOCSIFHWADDR, &ifr); close(s); } }
void start_sysinit(void) { time_t tm = 0; if (!nvram_match("disable_watchdog", "1")) eval("watchdog"); /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); /* * network drivers */ fprintf(stderr, "load ag71xx or ag7100_mod Ethernet Driver\n"); system("insmod ag71xx || insmod ag7100_mod || insmod ag7240_mod"); char mac1[32]; char mac2[32]; char wmac[32]; FILE *fp = fopen("/dev/mtdblock/7", "rb"); if (fp) { char mactmp[6]; int copy[6]; int i; #ifdef HAVE_WNDR3700 system("swconfig dev rtl8366s set reset 1"); system("swconfig dev rtl8366s set enable_vlan 0"); system("swconfig dev rtl8366s set blinkrate 2"); system("swconfig dev rtl8366s port 1 set led 9"); system("swconfig dev rtl8366s port 2 set led 6"); system("swconfig dev rtl8366s port 5 set led 2"); system("swconfig dev rtl8366s set apply"); #ifdef HAVE_WNDR3700V2 fseek(fp, 0xff0000, SEEK_SET); #else fseek(fp, 0x7f0000, SEEK_SET); #endif fread(mactmp, 6, 1, fp); for (i = 0; i < 6; i++) copy[i] = mactmp[i]; for (i = 0; i < 6; i++) copy[i] &= 0xff; sprintf(mac1, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); fread(mactmp, 6, 1, fp); for (i = 0; i < 6; i++) copy[i] = mactmp[i]; for (i = 0; i < 6; i++) copy[i] &= 0xff; sprintf(mac2, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); fread(mactmp, 6, 1, fp); fclose(fp); for (i = 0; i < 6; i++) copy[i] = mactmp[i]; for (i = 0; i < 6; i++) copy[i] &= 0xff; sprintf(wmac, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); #elif HAVE_WZRHPAG300NH system("swconfig dev eth0 set reset 1"); system("swconfig dev eth0 set enable_vlan 0"); system("swconfig dev eth0 vlan 1 set ports \"0 1 2 3 4\""); system("swconfig dev eth0 set apply"); fseek(fp, 0x5120C, SEEK_SET); fread(mactmp, 6, 1, fp); fclose(fp); for (i = 0; i < 6; i++) copy[i] = mactmp[i]; for (i = 0; i < 6; i++) copy[i] &= 0xff; sprintf(mac1, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); sprintf(mac2, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); MAC_ADD(mac2); // eval("gpio","enable","2"); #elif HAVE_WZRG300NH2 #ifndef HAVE_WZR300HP sysprintf("startservice bootloader_check"); #endif fseek(fp, 0x5120C, SEEK_SET); fread(mactmp, 6, 1, fp); fclose(fp); for (i = 0; i < 6; i++) copy[i] = mactmp[i]; for (i = 0; i < 6; i++) copy[i] &= 0xff; sprintf(mac1, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); sprintf(mac2, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); // eval("gpio","enable","13"); #ifdef HAVE_SWCONFIG system("swconfig dev eth0 set reset 1"); system("swconfig dev eth0 set enable_vlan 1"); if(nvram_match("wan_proto", "disabled") && nvram_match("fullswitch", "1")) { system("swconfig dev eth0 vlan 1 set ports \"0t 1 2 3 4 5\""); } else { system("swconfig dev eth0 vlan 1 set ports \"0t 1 3 4 5\""); system("swconfig dev eth0 vlan 2 set ports \"0t 2\""); } system("swconfig dev eth0 set apply"); #endif fprintf(stderr, "configure eth0 to %s\n", mac2); eval("ifconfig", "eth0", "hw", "ether", mac2); eval("ifconfig", "eth0", "up"); eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD"); eval("vconfig", "add", "eth0", "1"); eval("vconfig", "add", "eth0", "2"); fprintf(stderr, "configure vlan1 to %s\n", mac2); eval("ifconfig", "vlan1", "hw", "ether", mac2); fprintf(stderr, "configure vlan2 to %s\n", mac2); eval("ifconfig", "vlan2", "hw", "ether", mac2); #elif HAVE_WZRG450 fseek(fp, 0x51002, SEEK_SET); //osprey eeprom mac location fread(mactmp, 6, 1, fp); fclose(fp); for (i = 0; i < 6; i++) copy[i] = mactmp[i]; for (i = 0; i < 6; i++) copy[i] &= 0xff; sprintf(mac1, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); sprintf(mac2, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); // mac1[0] |= 0x02; // add private bit // mac2[0] |= 0x02; // eval("gpio","disable","16"); #ifdef HAVE_SWCONFIG system("swconfig dev switch0 set reset 1"); system("swconfig dev switch0 set enable_vlan 1"); if(nvram_match("wan_proto", "disabled") && nvram_match("fullswitch", "1")) { system("swconfig dev switch0 vlan 1 set ports \"0t 1 2 3 4 5\""); } else { system("swconfig dev switch0 vlan 1 set ports \"0t 2 3 4 5\""); system("swconfig dev switch0 vlan 2 set ports \"0t 1\""); } system("swconfig dev switch0 set apply"); #endif fprintf(stderr, "configure eth0 to %s\n", mac2); eval("ifconfig", "eth0", "hw", "ether", mac2); eval("ifconfig", "eth0", "up"); eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD"); eval("vconfig", "add", "eth0", "1"); eval("vconfig", "add", "eth0", "2"); fprintf(stderr, "configure vlan1 to %s\n", mac2); eval("ifconfig", "vlan1", "hw", "ether", mac2); fprintf(stderr, "configure vlan2 to %s\n", mac2); eval("ifconfig", "vlan2", "hw", "ether", mac2); #else system("swconfig dev eth0 set reset 1"); system("swconfig dev eth0 set enable_vlan 0"); system("swconfig dev eth0 vlan 1 set ports \"0 1 2 3 4\""); system("swconfig dev eth0 set apply"); fseek(fp, 0x7f120c, SEEK_SET); fread(mactmp, 6, 1, fp); fclose(fp); for (i = 5; i >= 3; i--) if (++mactmp[i] != 0x00) break; // dont know what this is for (i = 0; i < 6; i++) copy[i] = mactmp[i]; for (i = 0; i < 6; i++) copy[i] &= 0xff; sprintf(mac1, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); sprintf(mac2, "%02X:%02X:%02X:%02X:%02X:%02X", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); MAC_ADD(mac2); #endif } else { sprintf(mac1, "00:11:22:33:44:55"); sprintf(mac2, "00:11:22:33:44:66"); } #ifndef HAVE_WZRG450 eval("ifconfig", "eth0", "hw", "ether", mac1); eval("ifconfig", "eth0", "up"); eval("ifconfig", "eth1", "hw", "ether", mac2); eval("ifconfig", "eth1", "up"); #else eval("ifconfig", "eth0", "hw", "ether", mac2); eval("ifconfig", "eth0", "up"); #endif struct ifreq ifr; int s; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); close(s); } detect_wireless_devices(); #ifdef HAVE_WZRHPAG300NH // eval("ifconfig", "wifi1", "hw", "ether", wmac); setWirelessLedPhy0(1); setWirelessLedPhy1(5); #else #ifndef HAVE_WNDR3700 #ifdef HAVE_WZRG300NH2 setWirelessLedPhy0(5); #else #ifndef HAVE_WZRG450 setWirelessLedGeneric(0,6); setWirelessLedGeneric(1,6); #endif #endif #else eval("ifconfig", "wifi0", "hw", "ether", mac1); eval("ifconfig", "wifi1", "hw", "ether", wmac); setWirelessLedPhy0(5); setWirelessLedPhy1(5); #endif #endif led_control(LED_POWER, LED_ON); led_control(LED_SES, LED_OFF); led_control(LED_SES2, LED_OFF); led_control(LED_DIAG, LED_OFF); led_control(LED_BRIDGE, LED_OFF); led_control(LED_WLAN0, LED_OFF); led_control(LED_WLAN1, LED_OFF); led_control(LED_CONNECTED, LED_OFF); getRouterBrand(); // restore some default settings if (!nvram_get("ath0_rxantenna")) nvram_set("ath0_rxantenna", "3"); if (!nvram_get("ath0_txantenna")) nvram_set("ath0_txantenna", "3"); if (!nvram_get("ath1_rxantenna")) nvram_set("ath1_rxantenna", "3"); if (!nvram_get("ath1_txantenna")) nvram_set("ath1_txantenna", "3"); /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); return; cprintf("done\n"); }
void init_syspara(void) { unsigned char buffer[16]; unsigned int *src; char *dst; unsigned int bytes; int i; char macaddr[]="00:11:22:33:44:55"; char macaddr2[]="00:11:22:33:44:58"; char country_code[3]; char pin[9]; char productid[13]; char fwver[8]; char blver[20]; unsigned char txbf_para[33]; char ea[ETHER_ADDR_LEN]; nvram_set("buildno", rt_serialno); nvram_set("extendno", rt_extendno); nvram_set("buildinfo", rt_buildinfo); /* /dev/mtd/2, RF parameters, starts from 0x40000 */ dst = buffer; bytes = 6; memset(buffer, 0, sizeof(buffer)); memset(country_code, 0, sizeof(country_code)); memset(pin, 0, sizeof(pin)); memset(productid, 0, sizeof(productid)); memset(fwver, 0, sizeof(fwver)); memset(txbf_para, 0, sizeof(txbf_para)); if (FRead(dst, OFFSET_MAC_ADDR, bytes)<0) { _dprintf("READ MAC address: Out of scope\n"); } else { if (buffer[0]!=0xff) ether_etoa(buffer, macaddr); } if (FRead(dst, OFFSET_MAC_ADDR_2G, bytes)<0) { _dprintf("READ MAC address 2G: Out of scope\n"); } else { if (buffer[0]!=0xff) ether_etoa(buffer, macaddr2); } if (!ralink_mssid_mac_validate(macaddr) || !ralink_mssid_mac_validate(macaddr2)) nvram_set("wl_mssid", "0"); else nvram_set("wl_mssid", "1"); //TODO: separate for different chipset solution nvram_set("et0macaddr", macaddr); nvram_set("et1macaddr", macaddr2); if (FRead(dst, OFFSET_MAC_GMAC0, bytes)<0) dbg("READ MAC address GMAC0: Out of scope\n"); else { if (buffer[0]==0xff) { if (ether_atoe(macaddr, ea)) FWrite(ea, OFFSET_MAC_GMAC0, 6); } } if (FRead(dst, OFFSET_MAC_GMAC2, bytes)<0) dbg("READ MAC address GMAC2: Out of scope\n"); else { if (buffer[0]==0xff) { if (ether_atoe(macaddr2, ea)) FWrite(ea, OFFSET_MAC_GMAC2, 6); } } /* reserved for Ralink. used as ASUS country code. */ dst = country_code; bytes = 2; if (FRead(dst, OFFSET_COUNTRY_CODE, bytes)<0) { _dprintf("READ ASUS country code: Out of scope\n"); nvram_set("wl_country_code", ""); } else { if ((unsigned char)country_code[0]!=0xff) { //for specific power if (country_code[0] ==0x5a && country_code[1] == 0x31) { country_code[0]='U'; country_code[1]='S'; } else if (country_code[0] ==0x5a && country_code[1] == 0x32) { country_code[0]='G'; country_code[1]='B'; } else if (country_code[0] ==0x5a && country_code[1] == 0x33) { country_code[0]='T'; country_code[1]='W'; } else if (country_code[0] ==0x5a && country_code[1] == 0x34) { country_code[0]='C'; country_code[1]='N'; } nvram_set("wl_country_code", country_code); nvram_set("wl0_country_code", country_code); nvram_set("wl1_country_code", country_code); } else { nvram_set("wl_country_code", "DB"); nvram_set("wl0_country_code", "DB"); nvram_set("wl1_country_code", "DB"); } if (!strcasecmp(nvram_safe_get("wl_country_code"), "BR")) { nvram_set("wl_country_code", "UZ"); nvram_set("wl0_country_code", "UZ"); nvram_set("wl1_country_code", "UZ"); } if (nvram_match("wl_country_code", "HK") && nvram_match("preferred_lang", "")) nvram_set("preferred_lang", "TW"); } /* reserved for Ralink. used as ASUS pin code. */ dst = (char*)pin; bytes = 8; if (FRead(dst, OFFSET_PIN_CODE, bytes)<0) { _dprintf("READ ASUS pin code: Out of scope\n"); nvram_set("wl_pin_code", ""); } else { if ((unsigned char)pin[0]!=0xff) nvram_set("secret_code", pin); else nvram_set("secret_code", "12345670"); } src = (unsigned int*) 0x50020; /* /dev/mtd/3, firmware, starts from 0x50000 */ dst = buffer; bytes = 16; if (FRead(dst, (int)src, bytes)<0) { fprintf(stderr, "READ firmware header: Out of scope\n"); nvram_set("productid", "unknown"); nvram_set("firmver", "unknown"); } else { strncpy(productid, buffer + 4, 12); productid[12] = 0; sprintf(fwver, "%d.%d.%d.%d", buffer[0], buffer[1], buffer[2], buffer[3]); nvram_set("productid", trim_r(productid)); nvram_set("firmver", trim_r(fwver)); } memset(buffer, 0, sizeof(buffer)); FRead(buffer, OFFSET_BOOT_VER, 4); // sprintf(blver, "%c.%c.%c.%c", buffer[0], buffer[1], buffer[2], buffer[3]); sprintf(blver, "%s-0%c-0%c-0%c-0%c", trim_r(productid), buffer[0], buffer[1], buffer[2], buffer[3]); nvram_set("blver", trim_r(blver)); _dprintf("bootloader version: %s\n", nvram_safe_get("blver")); _dprintf("firmware version: %s\n", nvram_safe_get("firmver")); dst = txbf_para; int count_0xff = 0; if (FRead(dst, OFFSET_TXBF_PARA, 33) < 0) { fprintf(stderr, "READ TXBF PARA address: Out of scope\n"); } else { for (i = 0; i < 33; i++) { if (txbf_para[i] == 0xff) count_0xff++; /* if ((i % 16) == 0) fprintf(stderr, "\n"); fprintf(stderr, "%02x ", (unsigned char) txbf_para[i]); */ } /* fprintf(stderr, "\n"); fprintf(stderr, "TxBF parameter 0xFF count: %d\n", count_0xff); */ } if (count_0xff == 33) nvram_set("wl1_txbf_en", "0"); else nvram_set("wl1_txbf_en", "1"); #if defined (RTCONFIG_WLMODULE_RT3352_INIC_MII) #define EEPROM_INIC_SIZE (512) #define EEPROM_INIT_ADDR 0x48000 #define EEPROM_INIT_FILE "/etc/Wireless/iNIC/iNIC_e2p.bin" { char eeprom[EEPROM_INIC_SIZE]; if(FRead(eeprom, EEPROM_INIT_ADDR, sizeof(eeprom)) < 0) { fprintf(stderr, "FRead(eeprom, 0x%08x, 0x%x) failed\n", EEPROM_INIT_ADDR, sizeof(eeprom)); } else { FILE *fp; char *filepath = EEPROM_INIT_FILE; system("mkdir -p /etc/Wireless/iNIC/"); if((fp = fopen(filepath, "w")) == NULL) { fprintf(stderr, "fopen(%s) failed!!\n", filepath); } else { if(fwrite(eeprom, sizeof(eeprom), 1, fp) < 1) { perror("fwrite(eeprom)"); } fclose(fp); } } } #endif { #ifdef RTCONFIG_ODMPID char modelname[16]; FRead(modelname, OFFSET_ODMPID, sizeof(modelname)); modelname[sizeof(modelname)-1] = '\0'; if(modelname[0] != 0 && (unsigned char)(modelname[0]) != 0xff && is_valid_hostname(modelname)) { nvram_set("odmpid", modelname); } else #endif nvram_unset("odmpid"); } nvram_set("firmver", rt_version); nvram_set("productid", rt_buildname); }
void getsyspara(void) { unsigned char buffer[32]; int i; char macaddr[]="00:11:22:33:44:55"; char macaddr2[]="00:11:22:33:44:56"; char macaddr3[]="001122334457"; char macaddr4[]="001122334458"; char ea[ETHER_ADDR_LEN]; char country_code[3]; char pin[9]; char productid[13]; char fwver[8], fwver_sub[16]; char blver[20]; unsigned char txbf_para[33]; /* /dev/mtd/2, RF parameters, starts from 0x40000 */ memset(buffer, 0, sizeof(buffer)); memset(country_code, 0, sizeof(country_code)); memset(pin, 0, sizeof(pin)); memset(productid, 0, sizeof(productid)); memset(fwver, 0, sizeof(fwver)); memset(fwver_sub, 0, sizeof(fwver_sub)); memset(txbf_para, 0, sizeof(txbf_para)); if (FRead(buffer, OFFSET_MAC_ADDR, 6)<0) { dbg("READ MAC address: Out of scope\n"); } else { if (buffer[0]!=0xff) { ether_etoa(buffer, macaddr); ether_etoa2(buffer, macaddr3); } } if (FRead(buffer, OFFSET_MAC_ADDR_2G, 6)<0) { dbg("READ MAC address 2G: Out of scope\n"); } else { if (buffer[0]!=0xff) { ether_etoa(buffer, macaddr2); ether_etoa2(buffer, macaddr4); } } nvram_set("il0macaddr", macaddr); nvram_set("il1macaddr", macaddr2); nvram_set("et0macaddr", macaddr); nvram_set("br0hexaddr", macaddr3); nvram_set("wanhexaddr", macaddr4); if (FRead(buffer, OFFSET_MAC_GMAC0, 6)<0) { dbg("READ MAC address GMAC0: Out of scope\n"); } else { if (buffer[0]==0xff) { if (ether_atoe(macaddr, ea)) FWrite(ea, OFFSET_MAC_GMAC0, 6); } } if (FRead(buffer, OFFSET_MAC_GMAC2, 6)<0) { dbg("READ MAC address GMAC2: Out of scope\n"); } else { if (buffer[0]==0xff) { if (ether_atoe(macaddr2, ea)) FWrite(ea, OFFSET_MAC_GMAC2, 6); } } /* reserved for Ralink. used as ASUS country code. */ if (FRead(country_code, OFFSET_COUNTRY_CODE, 2)<0) { dbg("READ ASUS country code: Out of scope\n"); strcpy(country_code, "GB"); } else { country_code[2] = 0; if ((unsigned char)country_code[0]==0xff) strcpy(country_code, "GB"); } if (strlen(nvram_safe_get("rt_country_code")) == 0) { nvram_set("rt_country_code", country_code); } if (strlen(nvram_safe_get("wl_country_code")) == 0) { nvram_set("wl_country_code", country_code); } if (!strcasecmp(nvram_safe_get("wl_country_code"), "BR")) nvram_set("wl_country_code", "UZ"); /* reserved for Ralink. used as ASUS pin code. */ if (FRead(pin, OFFSET_PIN_CODE, 8)<0) { dbg("READ ASUS pin code: Out of scope\n"); nvram_set("wl_pin_code", ""); } else { if ((unsigned char)pin[0]!=0xff) nvram_set("secret_code", pin); else nvram_set("secret_code", "12345670"); } #if defined(USE_RT3352_MII) #define EEPROM_INIC_SIZE (512) #define EEPROM_INIT_ADDR 0x48000 { char eeprom[EEPROM_INIC_SIZE]; if(FRead(eeprom, EEPROM_INIT_ADDR, sizeof(eeprom)) < 0) { dbg("READ iNIC EEPROM: Out of scope!\n"); } else { FILE *fp; if((fp = fopen("/etc/Wireless/iNIC/iNIC_e2p.bin", "w"))) { fwrite(eeprom, sizeof(eeprom), 1, fp); fclose(fp); } } } #endif /* /dev/mtd/3, firmware, starts from 0x50000 */ if (FRead(buffer, 0x50020, sizeof(buffer))<0) { dbg("READ firmware header: Out of scope\n"); nvram_set("productid", "unknown"); nvram_set("firmver", "unknown"); } else { strncpy(productid, buffer + 4, 12); productid[12] = 0; if(valid_subver(buffer[27])) sprintf(fwver_sub, "%d.%d.%d.%d%c", buffer[0], buffer[1], buffer[2], buffer[3], buffer[27]); else sprintf(fwver_sub, "%d.%d.%d.%d", buffer[0], buffer[1], buffer[2], buffer[3]); #if defined(FWBLDSTR) sprintf(fwver_sub, "%s-%s", fwver_sub, FWBLDSTR); #endif sprintf(fwver, "%d.%d.%d.%d", buffer[0], buffer[1], buffer[2], buffer[3]); nvram_set("productid", trim_r(productid)); nvram_set("firmver", trim_r(fwver)); nvram_set("firmver_sub", trim_r(fwver_sub)); } memset(buffer, 0, sizeof(buffer)); FRead(buffer, OFFSET_BOOT_VER, 4); sprintf(blver, "%s-0%c-0%c-0%c-0%c", trim_r(productid), buffer[0], buffer[1], buffer[2], buffer[3]); nvram_set("blver", trim_r(blver)); int count_0xff = 0; if (FRead(txbf_para, OFFSET_TXBF_PARA, 33) < 0) { dbg("READ TXBF PARA address: Out of scope\n"); } else { for (i = 0; i < 33; i++) { if (txbf_para[i] == 0xff) count_0xff++; } } if (count_0xff == 33) nvram_set("wl_txbf_en", "0"); else nvram_set("wl_txbf_en", "1"); }
void start_sysinit(void) { time_t tm = 0; eval("/bin/tar", "-xzf", "/dev/mtdblock/3", "-C", "/"); FILE *in = fopen("/tmp/nvram/nvram.db", "rb"); if (in != NULL) { fclose(in); eval("/usr/sbin/convertnvram"); eval("/sbin/mtd", "erase", "nvram"); nvram_commit(); } if (!nvram_match("disable_watchdog", "1")) eval("watchdog"); /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); /* * network drivers */ #ifdef HAVE_HOTPLUG2 insmod("ar231x"); #else insmod("ar2313"); #endif detect_wireless_devices(); int s; struct ifreq ifr; if (getRouterBrand() == ROUTER_BOARD_RDAT81) { writeproc("/proc/sys/dev/wifi0/ledpin","7"); writeproc("/proc/sys/dev/wifi0/softled","1"); writeproc("/proc/sys/dev/wifi1/ledpin","5"); writeproc("/proc/sys/dev/wifi1/softled","1"); } if (getRouterBrand() == ROUTER_BOARD_RCAA01) { insmod("mvswitch"); // eval("ifconfig", "eth0", "up", "promisc"); // required for vlan config eval("/sbin/vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD"); eval("/sbin/vconfig", "add", "eth0", "0"); eval("/sbin/vconfig", "add", "eth0", "1"); if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); char macaddr[32]; strcpy(macaddr, ether_etoa((unsigned char *)ifr.ifr_hwaddr. sa_data, eabuf)); nvram_set("et0macaddr", macaddr); // MAC_ADD( macaddr ); ether_atoe(macaddr, (unsigned char *)ifr.ifr_hwaddr.sa_data); strncpy(ifr.ifr_name, "vlan1", IFNAMSIZ); ioctl(s, SIOCSIFHWADDR, &ifr); close(s); } writeproc("/proc/sys/dev/wifi0/ledpin","4"); writeproc("/proc/sys/dev/wifi0/softled","1"); writeproc("/proc/sys/dev/wifi1/ledpin","5"); writeproc("/proc/sys/dev/wifi1/softled","1"); } if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); char macaddr[32]; strcpy(macaddr, ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr", macaddr); nvram_set("et0macaddr_safe", macaddr); close(s); } /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); return; cprintf("done\n"); }
void start_sysinit(void) { char buf[PATH_MAX]; struct stat tmp_stat; time_t tm = 0; if (!nvram_match("disable_watchdog", "1")) { insmod("cns3xxx_wdt"); eval("watchdog"); } /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); int brand = getRouterBrand(); //for extension board struct ifreq ifr; int s; fprintf(stderr, "try modules for ethernet adapters\n"); nvram_set("intel_eth", "0"); insmod("cns3xxx_eth"); if (detect_ethernet_devices()) nvram_set("intel_eth", "1"); //load mmc drivers insmod("mmc_core"); eval("insmod", "sdhci", "debug_quirks=1"); // workaround for mmc detection issue. // insmod("sdhci"); insmod("sdhci-pltfm"); insmod("sdhci-cns3xxx"); insmod("mmc_block"); //sata drivers insmod("scsi_mod"); insmod("scsi_wait_scan"); insmod("scsi_sd_mod"); insmod("libata"); insmod("libahci"); insmod("ahci"); insmod("cns3xxx_ahci"); /* * network drivers */ detect_wireless_devices(); if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); close(s); } /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ath0"); eval("hwclock", "-s"); if (!strcmp(nvram_safe_get("DD_BOARD"), "Gateworks Laguna GW2391") || !strcmp(nvram_safe_get("DD_BOARD2"), "Gateworks Laguna GW2391") ) sysprintf("gsp_updater -f /etc/gsc_2391_v35.txt"); if (!strcmp(nvram_safe_get("DD_BOARD"), "Gateworks Laguna GW2389") || !strcmp(nvram_safe_get("DD_BOARD2"), "Gateworks Laguna GW2389") ) sysprintf("gsp_updater -f /etc/gsc_2388_v35.txt"); if (!strcmp(nvram_safe_get("DD_BOARD"), "Gateworks Laguna GW2388") || !strcmp(nvram_safe_get("DD_BOARD2"), "Gateworks Laguna GW2388") ) sysprintf("gsp_updater -f /etc/gsc_2388_v35.txt"); if (!strcmp(nvram_safe_get("DD_BOARD"), "Gateworks Laguna GW2387") || !strcmp(nvram_safe_get("DD_BOARD2"), "Gateworks Laguna GW2387") ) sysprintf("gsp_updater -f /etc/gsc_2387_v35.txt"); if (!strcmp(nvram_safe_get("DD_BOARD"), "Gateworks Laguna GW2386") || !strcmp(nvram_safe_get("DD_BOARD2"), "Gateworks Laguna GW2386") ) sysprintf("gsp_updater -f /etc/gsc_2386_v35.txt"); if (!strcmp(nvram_safe_get("DD_BOARD"), "Gateworks Laguna GW2384") || !strcmp(nvram_safe_get("DD_BOARD2"), "Gateworks Laguna GW2384") ) sysprintf("gsp_updater -f /etc/gsc_2384_v35.txt"); if (!strcmp(nvram_safe_get("DD_BOARD"), "Gateworks Laguna GW2383") || !strcmp(nvram_safe_get("DD_BOARD2"), "Gateworks Laguna GW2383") ) sysprintf("gsp_updater -f /etc/gsc_2383_v35.txt"); if (!strcmp(nvram_safe_get("DD_BOARD"), "Gateworks Laguna GW2382") || !strcmp(nvram_safe_get("DD_BOARD2"), "Gateworks Laguna GW2382") ) sysprintf("gsp_updater -f /etc/gsc_2382_v35.txt"); if (!strcmp(nvram_safe_get("DD_BOARD"), "Gateworks Laguna GW2380") || !strcmp(nvram_safe_get("DD_BOARD2"), "Gateworks Laguna GW2380") ) sysprintf("gsp_updater -f /etc/gsc_2380_v35.txt"); writeproc("/proc/irq/51/smp_affinity","2"); //use second core for ethernet interrupts. this should increase performance a little bit return; }
void start_sysinit(void) { char buf[PATH_MAX]; struct stat tmp_stat; time_t tm = 0; mknod("/dev/mmc", S_IFBLK | 0660, makedev(126, 0)); mknod("/dev/mmc0", S_IFBLK | 0660, makedev(126, 1)); mknod("/dev/mmc1", S_IFBLK | 0660, makedev(126, 2)); mknod("/dev/mmc2", S_IFBLK | 0660, makedev(126, 3)); mknod("/dev/mmc3", S_IFBLK | 0660, makedev(126, 4)); mknod("/dev/gpio", S_IFCHR | 0644, makedev(252, 0)); /* * Setup console */ cprintf("sysinit() klogctl\n"); klogctl(8, NULL, atoi(nvram_safe_get("console_loglevel"))); cprintf("sysinit() get router\n"); /* * load some netfilter stuff */ // eval( "watchdog" ); /* * Set a sane date */ stime(&tm); nvram_set("wl0_ifname", "ra0"); insmod("rt2860v2_ap"); insmod("RTPCI_ap"); insmod("raeth"); #ifdef HAVE_WHR300HP2 insmod("rt2880_wdt"); FILE *in = fopen("/dev/mtdblock/2", "rb"); unsigned char mac[32]; if (in != NULL) { fseek(in, 4, SEEK_SET); fread(mac, 6, 1, in); fclose(in); unsigned int copy[6]; int i; for (i = 0; i < 6; i++) copy[i] = mac[i] & 0xff; sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); fprintf(stderr,"configure mac address to %s\n",mac); if (!strcmp(mac, "ff:ff:ff:ff:ff:ff")) eval("ifconfig", "eth0", "hw", "ether", "00:11:22:33:44:55"); else eval("ifconfig", "eth0", "hw", "ether", mac); } /* system("swconfig dev eth0 set reset 1"); system("swconfig dev eth0 set enable_vlan 1"); system("swconfig dev eth0 vlan 1 set ports \"0 1 2 3 6t\""); system("swconfig dev eth0 vlan 2 set ports \"4 6t\""); system("swconfig dev eth0 set apply");*/ //LAN/WAN ports as security mode sysprintf("switch reg w 2004 ff0003"); sysprintf("switch reg w 2104 ff0003"); sysprintf("switch reg w 2204 ff0003"); sysprintf("switch reg w 2304 ff0003"); sysprintf("switch reg w 2404 ff0003"); sysprintf("switch reg w 2504 ff0003"); //LAN/WAN ports as transparent port sysprintf("switch reg w 2010 810000c0"); sysprintf("switch reg w 2110 810000c0"); sysprintf("switch reg w 2210 810000c0"); sysprintf("switch reg w 2310 810000c0"); sysprintf("switch reg w 2410 810000c0"); sysprintf("switch reg w 2510 810000c0"); //set CPU/P7 port as user port sysprintf("switch reg w 2610 81000000"); sysprintf("switch reg w 2710 81000000"); sysprintf("switch reg w 2604 20ff0003");// #port6, Egress VLAN Tag Attribution=tagged sysprintf("switch reg w 2704 20ff0003");// #port7, Egress VLAN Tag Attribution=tagged sysprintf("switch reg w 2014 10001"); sysprintf("switch reg w 2114 10001"); sysprintf("switch reg w 2214 10001"); sysprintf("switch reg w 2314 10001"); sysprintf("switch reg w 2414 10002"); sysprintf("switch reg w 2514 10001"); //VLAN member port sysprintf("switch vlan set 0 1 11110111"); sysprintf("switch vlan set 1 2 00001011"); sysprintf("switch clear"); eval("ifconfig", "eth0", "up"); eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD"); eval("vconfig", "add", "eth0", "1"); //LAN eval("vconfig", "add", "eth0", "2"); //WAN struct ifreq ifr; int s; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); close(s); } #else #if defined(HAVE_DIR600) && !defined(HAVE_ALL02310N) writeproc("/proc/rt3052/mii/ctrl", "write 0 0 0x3300"); writeproc("/proc/rt3052/mii/ctrl", "write 1 0 0x3300"); writeproc("/proc/rt3052/mii/ctrl", "write 2 0 0x3300"); writeproc("/proc/rt3052/mii/ctrl", "write 3 0 0x3300"); #endif #if defined(HAVE_RT10N) || defined(HAVE_F5D8235) || defined(HAVE_RT15N) || defined(HAVE_WCRGN) && !defined(HAVE_HAMEA15) FILE *in = fopen("/dev/mtdblock/2", "rb"); unsigned char mac[32]; if (in != NULL) { fseek(in, 4, SEEK_SET); fread(mac, 6, 1, in); fclose(in); unsigned int copy[6]; int i; for (i = 0; i < 6; i++) copy[i] = mac[i] & 0xff; sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x", copy[0], copy[1], copy[2], copy[3], copy[4], copy[5]); if (!strcmp(mac, "ff:ff:ff:ff:ff:ff")) eval("ifconfig", "eth2", "hw", "ether", "00:11:22:33:44:55"); else eval("ifconfig", "eth2", "hw", "ether", mac); } #endif #ifdef HAVE_HAMEA15 FILE *in = fopen("/dev/mtdblock/1", "rb"); if (in != NULL) { unsigned char *config = malloc(65536); memset(config, 0, 65536); fread(config, 65536, 1, in); int len = strlen("WAN_MAC_ADDR="); int i; for (i = 0; i < 65535 - (len + 18); i++) { if (!strncmp(&config[i], "WAN_MAC_ADDR=", len)) { char *mac = &config[i + len]; if (mac[0] == '"') mac++; mac[17] = 0; eval("ifconfig", "eth2", "hw", "ether", mac); nvram_set("et0macaddr_safe", mac); nvram_set("et0macaddr", mac); break; } } free(config); fclose(in); } #endif #if (defined(HAVE_DIR600) || defined(HAVE_AR670W) || defined(HAVE_EAP9550) || defined(HAVE_AR690W)) && !defined(HAVE_ALL02310N) FILE *in = fopen("/dev/mtdblock/1", "rb"); if (in != NULL) { unsigned char *config = malloc(65536); memset(config, 0, 65536); fread(config, 65536, 1, in); #if defined(HAVE_AR670W) || defined(HAVE_AR690W) int len = strlen("lanmac="); #else int len = strlen("ethaddr="); #endif int i; for (i = 0; i < 65535 - (18 + len); i++) { #if defined(HAVE_AR670W) || defined(HAVE_AR690W) if (!strncmp(&config[i], "lanmac=", 7)) #else if (!strncmp(&config[i], "ethaddr=", 8)) #endif { char *mac = &config[i + len]; if (mac[0] == '"') mac++; mac[17] = 0; eval("ifconfig", "eth2", "hw", "ether", mac); nvram_set("et0macaddr_safe", mac); nvram_set("et0macaddr", mac); break; } } free(config); fclose(in); } #endif /* switch config */ if (getRouterBrand() != ROUTER_BOARD_ECB9750 && getRouterBrand() != ROUTER_BOARD_TECHNAXX3G) // lets load { eval("ifconfig", "eth2", "up"); #ifndef HAVE_EAP9550 eval("vconfig", "set_name_type", "VLAN_PLUS_VID_NO_PAD"); eval("vconfig", "add", "eth2", "1"); //LAN eval("vconfig", "add", "eth2", "2"); //WAN #ifdef HAVE_RT10N MAC_ADD(mac); eval("ifconfig", "vlan2", "hw", "ether", mac); #endif #endif #if defined(HAVE_ALLNET11N) || defined(HAVE_ESR6650) || defined(HAVE_WR5422) || defined(HAVE_RT10N) || \ defined(HAVE_ACXNR22) || defined(HAVE_W502U) || defined(HAVE_ESR9752) || defined(HAVE_ALL02310N) sysprintf("switch reg w 14 405555"); sysprintf("switch reg w 50 2001"); sysprintf("switch reg w 90 7f7f"); sysprintf("switch reg w 98 7f3f"); sysprintf("switch reg w e4 3f"); sysprintf("switch reg w 40 1002"); sysprintf("switch reg w 44 1001"); sysprintf("switch reg w 48 1001"); sysprintf("switch reg w 70 ffff417e"); #ifdef HAVE_ESR9752 sysprintf("switch reg w c8 3f502b28"); #endif #elif HAVE_AR670W sysprintf("mii_mgr -s -p 29 -r 23 -v 0x07c2"); sysprintf("mii_mgr -s -p 29 -r 22 -v 0x8420"); sysprintf("mii_mgr -s -p 29 -r 24 -v 0x1"); sysprintf("mii_mgr -s -p 29 -r 25 -v 0x1"); sysprintf("mii_mgr -s -p 29 -r 26 -v 0x1"); sysprintf("mii_mgr -s -p 29 -r 27 -v 0x1"); sysprintf("mii_mgr -s -p 29 -r 28 -v 0x2"); sysprintf("mii_mgr -s -p 30 -r 9 -v 0x1089"); sysprintf("mii_mgr -s -p 30 -r 1 -v 0x2f00"); sysprintf("mii_mgr -s -p 30 -r 2 -v 0x0030"); #elif HAVE_AR690W #elif HAVE_RT15N #elif HAVE_BR6574N #elif HAVE_F5D8235 sysprintf("switch reg w 14 405555"); sysprintf("switch reg w 50 2001"); sysprintf("switch reg w 90 7f7f"); sysprintf("switch reg w 98 7f40"); sysprintf("switch reg w e4 20"); sysprintf("switch reg w 40 1001"); sysprintf("switch reg w 44 1001"); sysprintf("switch reg w 48 1001"); sysprintf("switch reg w 4c 1"); sysprintf("switch reg w 70 ffffffff"); #elif HAVE_EAP9550 sysprintf("switch reg w 14 5555"); sysprintf("switch reg w 40 1001"); sysprintf("switch reg w 44 1001"); sysprintf("switch reg w 48 1001"); sysprintf("switch reg w 4c 1"); sysprintf("switch reg w 50 2001"); sysprintf("switch reg w 70 ffffffff"); sysprintf("switch reg w 90 7f7f"); sysprintf("switch reg w 98 7f7f"); sysprintf("switch reg w e4 7f"); #else sysprintf("switch reg w 14 405555"); sysprintf("switch reg w 50 2001"); sysprintf("switch reg w 90 7f7f"); sysprintf("switch reg w 98 7f3f"); sysprintf("switch reg w e4 3f"); sysprintf("switch reg w 40 1001"); sysprintf("switch reg w 44 1001"); sysprintf("switch reg w 48 1002"); sysprintf("switch reg w 70 ffff506f"); #endif } struct ifreq ifr; int s; if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW))) { char eabuf[32]; strncpy(ifr.ifr_name, "eth2", IFNAMSIZ); ioctl(s, SIOCGIFHWADDR, &ifr); nvram_set("et0macaddr_safe", ether_etoa((unsigned char *)ifr.ifr_hwaddr.sa_data, eabuf)); close(s); } #endif led_control(LED_POWER, LED_ON); led_control(LED_SES, LED_OFF); led_control(LED_SES2, LED_OFF); led_control(LED_DIAG, LED_OFF); led_control(LED_BRIDGE, LED_OFF); led_control(LED_WLAN0, LED_OFF); led_control(LED_WLAN1, LED_OFF); led_control(LED_CONNECTED, LED_OFF); #ifdef HAVE_WCRGN set_gpio(0,1); set_gpio(10,1); #endif if (!nvram_match("disable_watchdog", "1")) { eval("watchdog"); } return; }
static int wl_scan(int unit) { wl_scan_results_t *list = (wl_scan_results_t*)scan_result; wl_bss_info_t *bi; wl_bss_info_107_t *old_bi; uint i, ap_count = 0; char ssid_str[128], macstr[18]; if (wl_get_scan_results(unit) == NULL) return 0; memset(ap_list, 0, sizeof(ap_list)); if (list->count == 0) return 0; else if (list->version != WL_BSS_INFO_VERSION && list->version != LEGACY_WL_BSS_INFO_VERSION && list->version != LEGACY2_WL_BSS_INFO_VERSION) { /* fprintf(stderr, "Sorry, your driver has bss_info_version %d " "but this program supports only version %d.\n", list->version, WL_BSS_INFO_VERSION); */ return 0; } bi = list->bss_info; for (i = 0; i < list->count; i++) { /* Convert version 107 to 109 */ if (dtoh32(bi->version) == LEGACY_WL_BSS_INFO_VERSION) { old_bi = (wl_bss_info_107_t *)bi; bi->chanspec = CH20MHZ_CHSPEC(old_bi->channel); bi->ie_length = old_bi->ie_length; bi->ie_offset = sizeof(wl_bss_info_107_t); } if (bi->ie_length) { if (ap_count < WLC_MAX_AP_SCAN_LIST_LEN){ ap_list[ap_count].used = TRUE; memcpy(ap_list[ap_count].BSSID, (uint8 *)&bi->BSSID, 6); strncpy((char *)ap_list[ap_count].ssid, (char *)bi->SSID, bi->SSID_len); ap_list[ap_count].ssid[bi->SSID_len] = '\0'; ap_list[ap_count].ssidLen= bi->SSID_len; ap_list[ap_count].ie_buf = (uint8 *)(((uint8 *)bi) + bi->ie_offset); ap_list[ap_count].ie_buflen = bi->ie_length; ap_list[ap_count].channel = (uint8)(bi->chanspec & WL_CHANSPEC_CHAN_MASK); ap_list[ap_count].wep = bi->capability & DOT11_CAP_PRIVACY; ap_count++; } } bi = (wl_bss_info_t*)((int8*)bi + bi->length); } if (ap_count) { if (psta_debug) dbg("%-4s%-33s%-18s\n", "Ch", "SSID", "BSSID"); for (i = 0; i < ap_count; i++) { memset(ssid_str, 0, sizeof(ssid_str)); char_to_ascii(ssid_str, (const char *) trim_r(ap_list[i].ssid)); ether_etoa((const unsigned char *) &ap_list[i].BSSID, macstr); if (psta_debug) dbg("%-4d%-33s%-18s\n", ap_list[i].channel, ap_list[i].ssid, macstr ); } } return ap_count; }