📄 kwifimanager_kcmodule.cpp
字号:
wrq.u.frag.value = -1; wrq.u.frag.fixed = 1; wrq.u.frag.disabled = 0; if (!strcasecmp (args[i], "off")) wrq.u.frag.disabled = 1; /* i.e. max size */ else if (!strcasecmp (args[i], "auto")) wrq.u.frag.fixed = 0; else { if (!strcasecmp (args[i], "fixed")) { /* Get old fragmentation threshold */ if (ioctl (skfd, SIOCGIWFRAG, &wrq) < 0) { fprintf (stderr, "SIOCGIWFRAG: %s\n", strerror (errno)); return (-1); } strncpy (wrq.ifr_name, ifname, IFNAMSIZ); wrq.u.frag.fixed = 1; } else /* Should be a numeric value */ if (sscanf (args[i], "%ld", (unsigned long *) &(wrq.u.frag.value)) != 1) iw_usage (); } if (ioctl (skfd, SIOCSIWFRAG, &wrq) < 0) { fprintf (stderr, "SIOCSIWFRAG: %s\n", strerror (errno)); return (-1); } continue; } /* ---------- Set operation mode ---------- */ if (!strcmp (args[i], "mode")) { int k; i++; if (i >= count) iw_usage (); if (sscanf (args[i], "%d", &k) != 1) { k = 0; while (k < 6 && strncasecmp (args[i], operation_mode[k], 3)) k++; } if ((k > 5) || (k < 0)) iw_usage (); wrq.u.mode = k; if (ioctl (skfd, SIOCSIWMODE, &wrq) < 0) { fprintf (stderr, "SIOCSIWMODE: %s\n", strerror (errno)); return (-1); } continue; } /* ---------- Set Power Management ---------- */ if (!strncmp (args[i], "power", 3)) { if (++i >= count) iw_usage (); if (!strcasecmp (args[i], "off")) wrq.u.power.disabled = 1; /* i.e. max size */ else if (!strcasecmp (args[i], "on")) { /* Get old Power info */ if (ioctl (skfd, SIOCGIWPOWER, &wrq) < 0) { fprintf (stderr, "SIOCGIWPOWER: %s\n", strerror (errno)); return (-1); } strncpy (wrq.ifr_name, ifname, IFNAMSIZ); wrq.u.power.disabled = 0; } else { double temp; int gotone = 0; /* Default - nope */ wrq.u.power.flags = IW_POWER_ON; wrq.u.power.disabled = 0; /* Check value modifier */ if (!strcasecmp (args[i], "min")) { wrq.u.power.flags |= IW_POWER_MIN; if (++i >= count) iw_usage (); } else if (!strcasecmp (args[i], "max")) { wrq.u.power.flags |= IW_POWER_MAX; if (++i >= count) iw_usage (); } /* Check value type */ if (!strcasecmp (args[i], "period")) { wrq.u.power.flags |= IW_POWER_PERIOD; if (++i >= count) iw_usage (); } else if (!strcasecmp (args[i], "timeout")) { wrq.u.power.flags |= IW_POWER_TIMEOUT; if (++i >= count) iw_usage (); } /* Is there any value to grab ? */ if (sscanf (args[i], "%lg", &(temp)) == 1) { temp *= MEGA; /* default = s */ if (index (args[i], 'u')) temp /= MEGA; if (index (args[i], 'm')) temp /= KILO; wrq.u.power.value = (long) temp; if ((wrq.u.power.flags & IW_POWER_TYPE) == 0) wrq.u.power.flags |= IW_POWER_PERIOD; ++i; gotone = 1; } /* Now, check the mode */ if (i < count) { if (!strcasecmp (args[i], "all")) wrq.u.power.flags |= IW_POWER_ALL_R; if (!strncasecmp (args[i], "unicast", 4)) wrq.u.power.flags |= IW_POWER_UNICAST_R; if (!strncasecmp (args[i], "multicast", 5)) wrq.u.power.flags |= IW_POWER_MULTICAST_R; if (!strncasecmp (args[i], "force", 5)) wrq.u.power.flags |= IW_POWER_FORCE_S; if (!strcasecmp (args[i], "repeat")) wrq.u.power.flags |= IW_POWER_REPEATER; if (wrq.u.power.flags & IW_POWER_MODE) { ++i; gotone = 1; } } if (!gotone) iw_usage (); --i; } if (ioctl (skfd, SIOCSIWPOWER, &wrq) < 0) { fprintf (stderr, "SIOCSIWPOWER(%d): %s\n", errno, strerror (errno)); return (-1); } continue; }#if WIRELESS_EXT > 9 /* ---------- Set Transmit-Power ---------- */ if (!strncmp (args[i], "txpower", 3)) { struct iw_range range; if (++i >= count) iw_usage (); /* Extract range info */ if (iw_get_range_info (skfd, ifname, &range) < 0) memset (&range, 0, sizeof (range)); /* Prepare the request */ strncpy (wrq.ifr_name, ifname, IFNAMSIZ); wrq.u.txpower.value = -1; wrq.u.txpower.fixed = 1; wrq.u.txpower.disabled = 0; wrq.u.data.flags = IW_TXPOW_DBM; if (!strcasecmp (args[i], "off")) wrq.u.txpower.disabled = 1; /* i.e. turn radio off */ else if (!strcasecmp (args[i], "auto")) wrq.u.txpower.fixed = 0; /* i.e. use power control */ else { if (!strcasecmp (args[i], "fixed")) { /* Get old tx-power */ if (ioctl (skfd, SIOCGIWTXPOW, &wrq) < 0) { fprintf (stderr, "SIOCGIWTXPOW: %s\n", strerror (errno)); return (-1); } strncpy (wrq.ifr_name, ifname, IFNAMSIZ); wrq.u.txpower.fixed = 1; } else /* Should be a numeric value */ { int power; int ismwatt = 0; /* Get the value */ if (sscanf (args[i], "%ld", (unsigned long *) &(power)) != 1) iw_usage (); /* Check if milliwatt */ ismwatt = (index (args[i], 'm') != NULL); /* Convert */ if (!ismwatt && (range.txpower_capa & IW_TXPOW_MWATT)) { power = iw_dbm2mwatt (power); wrq.u.data.flags = IW_TXPOW_MWATT; } if (ismwatt && !(range.txpower_capa & IW_TXPOW_MWATT)) power = iw_mwatt2dbm (power); wrq.u.bitrate.value = power; /* Check for an additional argument */ if (((i + 1) < count) && (!strcasecmp (args[i + 1], "auto"))) { wrq.u.txpower.fixed = 0; ++i; } if (((i + 1) < count) && (!strcasecmp (args[i + 1], "fixed"))) { wrq.u.txpower.fixed = 1; ++i; } } } if (ioctl (skfd, SIOCSIWTXPOW, &wrq) < 0) { fprintf (stderr, "SIOCSIWTXPOW: %s\n", strerror (errno)); return (-1); } continue; }#endif#if WIRELESS_EXT > 10 /* ---------- Set Power Management ---------- */ if (!strncmp (args[i], "retry", 3)) { double temp; int gotone = 0; if (++i >= count) iw_usage (); /* Default - nope */ wrq.u.retry.flags = IW_RETRY_LIMIT; wrq.u.retry.disabled = 0; /* Check value modifier */ if (!strcasecmp (args[i], "min")) { wrq.u.retry.flags |= IW_RETRY_MIN; if (++i >= count) iw_usage (); } else if (!strcasecmp (args[i], "max")) { wrq.u.retry.flags |= IW_RETRY_MAX; if (++i >= count) iw_usage (); } /* Check value type */ if (!strcasecmp (args[i], "limit")) { wrq.u.retry.flags |= IW_RETRY_LIMIT; if (++i >= count) iw_usage (); } else if (!strncasecmp (args[i], "lifetime", 4)) { wrq.u.retry.flags |= IW_RETRY_LIFETIME; if (++i >= count) iw_usage (); } /* Is there any value to grab ? */ if (sscanf (args[i], "%lg", &(temp)) == 1) { /* Limit is absolute, on the other hand lifetime is seconds */ if (!(wrq.u.retry.flags & IW_RETRY_LIMIT)) { /* Normalise lifetime */ temp *= MEGA; /* default = s */ if (index (args[i], 'u')) temp /= MEGA; if (index (args[i], 'm')) temp /= KILO; } wrq.u.retry.value = (long) temp; ++i; gotone = 1; } if (!gotone) iw_usage (); --i; if (ioctl (skfd, SIOCSIWRETRY, &wrq) < 0) { fprintf (stderr, "SIOCSIWRETRY(%d): %s\n", errno, strerror (errno)); return (-1); } continue; }#endif /* WIRELESS_EXT > 10 */ /* ---------- Other ---------- */ /* Here we have an unrecognised arg... */ fprintf (stderr, "Invalid argument : %s\n", args[i]); iw_usage (); return (-1); } /* for(index ... */ return (0);}voidiw_usage (void){};QString KWifimanager_KCModule::interface_to_use = "";KWifimanager_KCModule::KWifimanager_KCModule (QWidget * parent=0L, const char *name=0L, const QStringList unnuetz):KCModule (parent, name,unnuetz){ std::cerr << "hier"; load (); setButtons (127); QVBoxLayout *stupidlayout = new QVBoxLayout (this); configwindow = new QTabWidget (this); config1 = new KWifimanager_ConfigWidget (1, configwindow, "configwindow1"); config2 = new KWifimanager_ConfigWidget (2, configwindow, "configwindow2"); config3 = new KWifimanager_ConfigWidget (3, configwindow, "configwindow3"); config4 = new KWifimanager_ConfigWidget (4, configwindow, "configwindow4"); config_gen = new KWifimanager_ConfigWidget2 (this, "general_setup"); configwindow->addTab (config1, i18n ("Config &1")); configwindow->addTab (config2, i18n ("Config &2")); configwindow->addTab (config3, i18n ("Config &3")); configwindow->addTab (config4, i18n ("Config &4")); configwindow->setFixedSize (configwindow->sizeHint ()); stupidlayout->addWidget (configwindow, 0, Qt::AlignLeft | Qt::AlignTop); stupidlayout->addWidget (config_gen, 0, Qt::AlignLeft | Qt::AlignTop); connect (config1, SIGNAL (changed ()), this, SLOT (configChanged ())); connect (config2, SIGNAL (changed ()), this, SLOT (configChanged ())); connect (config3, SIGNAL (changed ()), this, SLOT (configChanged ())); connect (config4, SIGNAL (changed ()), this, SLOT (configChanged ())); connect (config_gen, SIGNAL (changed ()), this, SLOT (configChanged ())); this->show ();};KWifimanager_KCModule::~KWifimanager_KCModule (){}voidKWifimanager_KCModule::changeConfig (int x, int skfd, QString used_interface){ KProcess ifcon; ifcon << "ifconfig"; ifcon << used_interface.latin1 () << "down"; std::cerr << "Shutting down interface via ifconfig\n"; ifcon.start (KProcess::Block); const char *temp[3] = { "essid", configs->net_name[x].latin1 () != 0 ? configs->net_name[x].latin1 () : "", "" }; QString temp2; (configs->managed[x] == true) ? temp2 = "managed" : temp2 = "ad-hoc"; std::cerr << "Applying new settings:\nNetwork: " << configs->net_name[x].latin1 () << "\n"; set_info (skfd, temp, 2, used_interface.latin1 ()); temp[0] = "mode"; temp[1] = temp2.latin1 (); std::cerr << "Mode: " << temp2 << "\n"; set_info (skfd, temp, 2, used_interface.latin1 ()); temp[0] = "key"; if (configs->crypto_enabled[x] == true) { temp2 = ""; if (configs->crypto_is_string1[x] == true) temp2 += "s:"; temp2 += configs->crypto1[x]; temp[2] = "[1]"; temp[1] = temp2.latin1 (); std::cerr << "Crypto key 1: " << temp[1] << "\n"; set_info (skfd, temp, 3, used_interface.latin1 ()); temp2 = ""; if (configs->crypto_is_string2[x] == true) temp2 += "s:"; temp2 += configs->crypto2[x]; temp[2] = "[2]"; temp[1] = temp2.latin1 (); std::cerr << "Crypto key 2: " << temp[1] << "\n"; set_info (skfd, temp, 3, used_interface.latin1 ()); temp2 = ""; if (configs->crypto_is_string3[x] == true) temp2 += "s:"; temp2 += configs->crypto3[x]; temp[2] = "[3]"; temp[1] = temp2.latin1 (); std::cerr << "Crypto key 3: " << temp[1] << "\n"; set_info (skfd, temp, 3, used_interface.latin1 ()); temp2 = ""; if (configs->crypto_is_string4[x] == true)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -