function check_qos_setting($path) { $enable = query($path . "/device/qos/enable"); $auto = query($path . "/device/qos/autobandwidth"); if ($enable == "1") { if ($auto == "0") { if (isdigit(query($path . "/inf/bandwidth/upstream")) == "0" || query($path . "/inf/bandwidth/upstream") > 102400 || query($path . "/inf/bandwidth/upstream") < 1) { set_result("FAILED", $path . "/inf/bandwidth/upstream", i18n("The input uplink speed is invalid.")); return "FAILED"; } else { // Remove the leading zeros. $upstream_dec = strtoul(query($path . "/inf/bandwidth/upstream"), 10); set($path . "/inf/bandwidth/upstream", $upstream_dec); } } else { set($path . "/device/qos/autobandwidth", "1"); } $type = query($path . "/inf/bandwidth/type"); if ($type == "AUTO" || $type == "ADSL" || $type == "CABLE") { } else { set_result("FAILED", $path . "/inf/bandwidth/type", i18n("Unsupported Connection type be assigned.")); return "FAILED"; } } else { set($path . "/device/qos/enable", "0"); } return "OK"; }
function dhcpc6setup($inf) { $hlp = "/var/servd/" . $inf . "-dhcp6c.sh"; $pid = "/var/servd/" . $inf . "-dhcp6c.pid"; $cfg = "/var/servd/" . $inf . "-dhcp6c.cfg"; /* DHCP over PPP session ? */ //$previnf = XNODE_get_var($inf."_PREVINF"); //XNODE_del_var($inf."_PREVINF"); $infp = XNODE_getpathbytarget("", "inf", "uid", $inf, 0); $previnf = query($infp . "/infprevious"); $phyinf = query($infp . "/phyinf"); $inet = query($infp . "/inet"); $inetp = XNODE_getpathbytarget("/inet", "entry", "uid", $inet, 0); $devnam = PHYINF_getifname($phyinf); /* dslite ? */ $nextinf = query($infp . "/infnext"); //if ($mode=="PPPDHCP" && $_GLOBALS["PREVINF"]!="") //msg("mode is ".$mode.", previnf is ".$previnf); startcmd('# dhcpc6setup(' . $inf . ',' . $inetp . ')'); startcmd("previnf is " . $previnf . ", nextinf is " . $nextinf); //if ($mode=="PPPDHCP" && $previnf!="") //{ // $pppdev = PHYINF_getruntimeifname($previnf); // if ($pppdev=="") return error("no PPP device."); //} /* Gererate DHCP-IAID from 32-bit of mac address*/ $mac = PHYINF_getphymac($inf); $mac1 = cut($mac, 3, ":"); $mac2 = cut($mac, 0, ":"); $mac3 = cut($mac, 1, ":"); $mac4 = cut($mac, 2, ":"); $iaidstr = $mac1 . $mac2 . $mac3 . $mac4; $iaid = strtoul($iaidstr, 16); /* Generate configuration file. */ $send = "\tinformation-only;\n"; $idas = ""; //if($mode=="PPPDHCP") $dname = $pppdev; //else $dname = $devnam; $dname = $devnam; $nextinfp = XNODE_getpathbytarget("", "inf", "uid", $nextinf, 0); $nextinet = query($nextinfp . "/inet"); $nextinetp = XNODE_getpathbytarget("inet", "entry", "uid", $nextinet, 0); $nextmode = query($nextinetp . "/ipv4/ipv4in6/mode"); if ($nextinf != "" && $nextmode == "dslite") { $rqstmsg = "\trequest aftr-server-domain-name;\n"; } else { $rqstmsg = ""; } fwrite(w, $cfg, "interface " . $dname . " {\n" . $send . $rqstmsg . "\tscript \"" . $hlp . "\";\n" . "};\n" . $idas); /* generate callback script */ fwrite(w, $hlp, "#!/bin/sh\n" . "phpsh /etc/services/INET/inet6_dhcpc_helper.php" . " INF=" . $inf . " MODE=INFOONLY" . " DEVNAM=" . $dname . " GATEWAY=" . "" . " DHCPOPT=" . "" . ' "NAMESERVERS=$new_domain_name_servers"' . ' "NEW_ADDR=$new_addr"' . ' "NEW_PD_PREFIX=$new_pd_prefix"' . ' "NEW_PD_PLEN=$new_pd_plen"' . ' "DNS=' . "" . '"' . ' "NEW_AFTR_NAME=$new_aftr_name"' . ' "NTPSERVER=$new_ntp_servers"' . "\n"); /* Start DHCP client */ startcmd("chmod +x " . $hlp); //if ($pppdev=="") startcmd("dhcp6c -c " . $cfg . " -p " . $pid . " -t LL " . $devnam); //else startcmd("dhcp6c -c ".$cfg." -p ".$pid." -t LL -o ".$devnam." ".$pppdev); stopcmd("/etc/scripts/killpid.sh /var/servd/" . $inf . "-dhcp6c.pid"); }
function calcute_ds_port() { $ds_port = 48820; $inffp = XNODE_getpathbytarget("/runtime", "inf", "uid", "LAN-1"); $phy = query($inffp . "/phyinf"); $phyfp = XNODE_getpathbytarget("/runtime", "phyinf", "uid", $phy); $mac = query($phyfp . "/macaddr"); //use last two part of mac calcute a 4-digit number if ($mac != "") { $count = cut_count($mac, ":"); $mac_cut = cut($mac, $count - 2, ":") . cut($mac, $count - 1, ":"); $tmp = strtoul($mac_cut, 16) % 10000; $ds_port = 40000 + $tmp; } return $ds_port; }
function PHYINF_validmacaddr($macaddr) { if (cut_count($macaddr, ":") == 6) { $delimiter = ":"; } else { return 0; } $i = 0; while ($i < 6) { $v = cut($macaddr, $i, $delimiter); if (strlen($v) != 2 || isxdigit($v) != 1) { return 0; } if ($i == 0) { //hendry : check for multicast mac $val = strtoul($v, 16); $ismulti = $val % 2; if ($ismulti == 1) { return 0; } } $i++; } if (toupper($macaddr) == "FF:FF:FF:FF:FF:FF" || $macaddr == "01:11:11:11:11:11" || $macaddr == "00:00:00:00:00:00") { return 0; } return 1; }
function INET_addr_strip0($ip) { $new_ip = ""; if (cut_count($ip, ".") != 4) { return $ip; } $i = 0; while ($i < 4) { $part = cut($ip, $i, "."); if (isdigit($part) == 0) { return $ip; } $dec = strtoul($part, 10); if ($i == 0) { $new_ip = $dec; } else { $new_ip = $new_ip . "." . $dec; } $i++; } return $new_ip; }
function get_mssid_mac($host_mac, $offset) { $index = 5; $mssid_mac = ""; $carry = 0; //loop from low byte to high byte //ex: 00:01:02:03:04:05 //05 -> 04 -> 03 -> 02 -> 01 -> 00 while ($index >= 0) { $field = cut($host_mac, $index, ":"); //check mac format if ($field == "") { return ""; } //to value $value = strtoul($field, 16); if ($value == "") { return ""; } if ($index == 5) { $value = $value + $offset; } //need carry? $value = $value + $carry; if ($value > 255) { $carry = 1; $value = $value % 256; } else { $carry = 0; } //from dec to hex $hex_value = dec2strf("%02X", $value); if ($mssid_mac == "") { $mssid_mac = $hex_value; } else { $mssid_mac = $hex_value . ":" . $mssid_mac; } $index = $index - 1; } return $mssid_mac; }
function dhcp_client($mode, $inf, $devnam, $opt, $router, $dns) { $hlp = "/var/servd/" . $inf . "-dhcp6c.sh"; $pid = "/var/servd/" . $inf . "-dhcp6c.pid"; $cfg = "/var/servd/" . $inf . "-dhcp6c.cfg"; /* DHCP over PPP session ? */ $previnf = XNODE_get_var($inf . "_PREVINF"); XNODE_del_var($inf . "_PREVINF"); /* dslite ? */ $nextinf = XNODE_get_var($inf . "_NEXTINF"); XNODE_del_var($inf . "_NEXTINF"); //if ($mode=="PPPDHCP" && $_GLOBALS["PREVINF"]!="") //msg("mode is ".$mode.", previnf is ".$previnf); msg("mode is " . $mode . ", previnf is " . $previnf . ", nextinf is " . $nextinf); if ($mode == "PPPDHCP" && $previnf != "") { //$pppdev = PHYINF_getruntimeifname($_GLOBALS["PREVINF"]); $pppdev = PHYINF_getruntimeifname($previnf); if ($pppdev == "") { return error("no PPP device."); } msg("PPP device = " . $pppdev); } msg("dhcpopt: " . $opt); /* Gererate DHCP-IAID from 32-bit of mac address*/ $mac = PHYINF_getphymac($inf); $mac1 = cut($mac, 3, ":"); $mac2 = cut($mac, 0, ":"); $mac3 = cut($mac, 1, ":"); $mac4 = cut($mac, 2, ":"); $iaidstr = $mac1 . $mac2 . $mac3 . $mac4; $iaid = strtoul($iaidstr, 16); /* Generate configuration file. */ if ($mode == "INFOONLY") { $send = "\tinformation-only;\n"; $idas = ""; } else { //check if we have pd hint $stsp = XNODE_getpathbytarget("/runtime", "inf", "uid", $inf, 0); $pdhint_enable = query($stsp . "/pdhint/enable"); $pdhintmsg = "\n"; if ($pdhint_enable == "1") { $pdhint_network = query($stsp . "/pdhint/network"); $pdhint_prefix = query($stsp . "/pdhint/prefix"); $pdhint_plft = query($stsp . "/pdhint/preferlft"); $pdhint_vlft = query($stsp . "/pdhint/validlft"); if ($pdhint_vlft != "") { $pdhintmsg = "\tprefix " . $pdhint_network . "/" . $pdhint_prefix . " " . $pdhint_plft . " " . $pdhint_vlft . ";\n"; } else { $pdhintmsg = "\tprefix " . $pdhint_network . "/" . $pdhint_prefix . " " . $pdhint_plft . ";\n"; } } //check if we got the prefix before //++++ $pre_pd_network = query("/runtime/ipv6/pre_pdnetwork"); if ($pre_pd_network != "") { $pre_pd_prefix = query("/runtime/ipv6/pre_pdprefix"); $pre_pd_plft = query("/runtime/ipv6/pre_pdplft"); $pre_pd_vlft = query("/runtime/ipv6/pre_pdvlft"); if ($pre_pd_vlft != "") { $pdhintmsg = "\tprefix " . $pre_pd_network . "/" . $pre_pd_prefix . " " . $pre_pd_plft . " " . $pre_pd_vlft . ";\n"; } else { $pdhintmsg = "\tprefix " . $pre_pd_network . "/" . $pre_pd_prefix . " " . $pre_pd_plft . ";\n"; } } else { $pdhintmsg = "\tprefix ::/56 0 0;\n"; } //---- //if (strstr($opt,"IA-NA")!="") {$send=$send."\tsend ia-na 0;\n"; $idas=$idas."id-assoc na {\n};\n";} if (strstr($opt, "IA-NA") != "") { $send = $send . "\tsend ia-na " . $iaid . ";\n"; $idas = $idas . "id-assoc na " . $iaid . "{\n};\n"; } //if (strstr($opt,"IA-PD")!="") {$send=$send."\tsend ia-pd 0;\n"; $idas=$idas."id-assoc pd {\n};\n";} if (strstr($opt, "IA-PD") != "") { $send = $send . "\tsend ia-pd 0;\n"; $idas = $idas . "id-assoc pd {\n" . $pdhintmsg . "};\n"; } } if ($mode == "PPPDHCP") { $dname = $pppdev; } else { $dname = $devnam; } $nextinfp = XNODE_getpathbytarget("", "inf", "uid", $nextinf, 0); $nextinet = query($nextinfp . "/inet"); $nextinetp = XNODE_getpathbytarget("inet", "entry", "uid", $nextinet, 0); $nextmode = query($nextinetp . "/ipv4/ipv4in6/mode"); if ($nextinf != "" && $nextmode == "dslite") { $rqstmsg = "\trequest aftr-server-domain-name;\n"; } else { $rqstmsg = ""; } fwrite(w, $cfg, "interface " . $dname . " {\n" . $send . "\trequest domain-name-servers;\n" . "\trequest domain-name;\n" . "\trequest ntp-servers;\n" . $rqstmsg . "\tscript \"" . $hlp . "\";\n" . "};\n" . $idas); /* generate callback script */ fwrite(w, $hlp, "#!/bin/sh\n" . 'if [ $new_addr != "" ] || [ $new_pd_prefix != "" ]; then\\n' . "\techo [\$0]: [{$new_addr}] [{$new_pd_prefix}] [{$new_pd_plen}] [{$new_pd_pltime}] [{$new_pd_vltime}] > /dev/console\n" . "else\n" . "\texit 0\n" . "fi\n" . "phpsh /etc/services/INET/inet6_dhcpc_helper.php" . " INF=" . $inf . " MODE=" . $mode . " DEVNAM=" . $dname . " GATEWAY=" . $router . " DHCPOPT=" . $opt . ' "NAMESERVERS=$new_domain_name_servers"' . ' "DOMAIN=$new_domain_name"' . ' "NEW_ADDR=$new_addr"' . ' "NEW_PD_PREFIX=$new_pd_prefix"' . ' "NEW_PD_PLEN=$new_pd_plen"' . ' "NEW_PD_PLTIME=$new_pd_pltime"' . ' "NEW_PD_VLTIME=$new_pd_vltime"' . ' "DNS=' . $dns . '"' . ' "NEW_AFTR_NAME=$new_aftr_name"' . ' "NTPSERVER=$new_ntp_servers"' . "\n"); /* Start DHCP client */ cmd("chmod +x " . $hlp); if ($pppdev == "") { cmd("dhcp6c -c " . $cfg . " -p " . $pid . " -t LL -n " . $inf . " " . $devnam); } else { cmd("dhcp6c -c " . $cfg . " -p " . $pid . " -t LL -o " . $devnam . " -n " . $inf . " " . $pppdev); } return 0; }
function setup_txpower($uid) { $phypsts = XNODE_getpathbytarget("/runtime", "phyinf", "uid", $uid, 0); $dev = devname($uid); if ($phypsts != "") { $ccka = query($phypsts . "/txpower/ccka"); $cckb = query($phypsts . "/txpower/cckb"); $sa = query($phypsts . "/txpower/ht401sa"); $sb = query($phypsts . "/txpower/ht401sb"); $sa_5G = query($phypsts . "/txpower/ht401sa_5G"); $sb_5G = query($phypsts . "/txpower/ht401sb_5G"); } else { return; } $phyp = XNODE_getpathbytarget("", "phyinf", "uid", $uid, 0); $txpower = query($phyp . "/media/txpower"); if ($txpower == "70") { $tx_value = 3; } else { if ($txpower == "50") { $tx_value = 6; } else { if ($txpower == "25") { $tx_value = 9; } else { $tx_value = 17; } } } $max_num_24G_ch = 14 * 2; $max_num_5G_ch = 196 * 2; if ($ccka != "" && $cckb != "" && $sa != "" && $sb != "") { $index = 0; while ($index < $max_num_24G_ch) { $ccka_value = substr($ccka, $index, 2); $ccka_value = strtoul($ccka_value, 16); if ($ccka_value - $tx_value >= 1) { $ccka_value = $ccka_value - $tx_value; } else { $ccka_value = 1; } $ccka_value = dec2strf("%02x", $ccka_value); $pwrlevelCCK_A = $pwrlevelCCK_A . $ccka_value; $cckb_value = substr($cckb, $index, 2); $cckb_value = strtoul($cckb_value, 16); if ($cckb_value - $tx_value >= 1) { $cckb_value = $cckb_value - $tx_value; } else { $cckb_value = 1; } $cckb_value = dec2strf("%02x", $cckb_value); $pwrlevelCCK_B = $pwrlevelCCK_B . $cckb_value; $sa_value = substr($sa, $index, 2); $sa_value = strtoul($sa_value, 16); if ($sa_value - $tx_value >= 1) { $sa_value = $sa_value - $tx_value; } else { $sa_value = 1; } $sa_value = dec2strf("%02x", $sa_value); $pwrlevelHT40_1S_A = $pwrlevelHT40_1S_A . $sa_value; $sb_value = substr($sb, $index, 2); $sb_value = strtoul($sb_value, 16); if ($sb_value - $tx_value >= 1) { $sb_value = $sb_value - $tx_value; } else { $sb_value = 1; } $sb_value = dec2strf("%02x", $sb_value); $pwrlevelHT40_1S_B = $pwrlevelHT40_1S_B . $sb_value; $index = $index + 2; } fwrite("a", $_GLOBALS["START"], 'iwpriv ' . $dev . ' set_mib pwrlevelCCK_A=' . $pwrlevelCCK_A . '\\n'); fwrite("a", $_GLOBALS["START"], 'iwpriv ' . $dev . ' set_mib pwrlevelCCK_B=' . $pwrlevelCCK_B . '\\n'); fwrite("a", $_GLOBALS["START"], 'iwpriv ' . $dev . ' set_mib pwrlevelHT40_1S_A=' . $pwrlevelHT40_1S_A . '\\n'); fwrite("a", $_GLOBALS["START"], 'iwpriv ' . $dev . ' set_mib pwrlevelHT40_1S_B=' . $pwrlevelHT40_1S_B . '\\n'); } if ($sa_5G != "" && $sb_5G != "") { $index = 0; while ($index < $max_num_5G_ch) { $sa_value = substr($sa_5G, $index, 2); $sa_value = strtoul($sa_value, 16); if ($sa_value - $tx_value >= 1) { $sa_value = $sa_value - $tx_value; } else { $sa_value = 1; } $sa_value = dec2strf("%02x", $sa_value); $pwrlevel5GHT40_1S_A = $pwrlevel5GHT40_1S_A . $sa_value; $sb_value = substr($sb_5G, $index, 2); $sb_value = strtoul($sb_value, 16); if ($sb_value - $tx_value >= 1) { $sb_value = $sb_value - $tx_value; } else { $sb_value = 1; } $sb_value = dec2strf("%02x", $sb_value); $pwrlevel5GHT40_1S_B = $pwrlevel5GHT40_1S_B . $sb_value; $index = $index + 2; } fwrite("a", $_GLOBALS["START"], 'iwpriv ' . $dev . ' set_mib pwrlevel5GHT40_1S_A=' . $pwrlevel5GHT40_1S_A . '\\n'); fwrite("a", $_GLOBALS["START"], 'iwpriv ' . $dev . ' set_mib pwrlevel5GHT40_1S_B=' . $pwrlevel5GHT40_1S_B . '\\n'); } }
$cckb2 = substr($cckb, 6, 2); $cckb2 = strtoul($cckb2, 16); $cckb3 = substr($cckb, 18, 2); $cckb3 = strtoul($cckb3, 16); $sa1 = substr($sa, 0, 2); $sa1 = strtoul($sa1, 16); $sa2 = substr($sa, 6, 2); $sa2 = strtoul($sa2, 16); $sa3 = substr($sa, 18, 2); $sa3 = strtoul($sa3, 16); $sb1 = substr($sb, 0, 2); $sb1 = strtoul($sb1, 16); $sb2 = substr($sb, 6, 2); $sb2 = strtoul($sb2, 16); $sb3 = substr($sb, 18, 2); $sb3 = strtoul($sb3, 16); if ($txpower == "70") { if ($ccka1 > 3) { $ccka1 = $ccka1 - 3; $ccka1 = dec2strf("%02x", $ccka1); } else { $ccka1 = 1; $ccka1 = dec2strf("%02x", $ccka1); } if ($ccka2 > 3) { $ccka2 = $ccka2 - 3; $ccka2 = dec2strf("%02x", $ccka2); } else { $ccka2 = 1; $ccka2 = dec2strf("%02x", $ccka2); }