Browse Source

Detect ipw2100 and ipw2200 hardware kill switches, and warn the user if

they're enabled (Ubuntu bug #1877).

r27540
tags/1.09
Colin Watson 16 years ago
parent
commit
fd21ef7f3e
5 changed files with 91 additions and 0 deletions
  1. +2
    -0
      debian/changelog
  2. +9
    -0
      debian/netcfg-common.templates
  3. +61
    -0
      netcfg-common.c
  4. +17
    -0
      netcfg.c
  5. +2
    -0
      netcfg.h

+ 2
- 0
debian/changelog View File

@@ -14,6 +14,8 @@ netcfg (1.09) UNRELEASED; urgency=low
says: "A numeric host address string is not a 'name', and thus does
not have a 'canonical name' form; no address to host name translation
is performed." Use getnameinfo() instead.
- Detect ipw2100 and ipw2200 hardware kill switches, and warn the user
if they're enabled (Ubuntu bug #1877).
-- Christian Perrier <bubulle@debian.org> Wed, 16 Mar 2005 20:12:48 +0100



+ 9
- 0
debian/netcfg-common.templates View File

@@ -104,6 +104,15 @@ _Description: No network interfaces detected
You may need to load a specific module for your network card, if you have
one. For this, go back to the network hardware detection step.

Template: netcfg/kill_switch_enabled
Type: note
# A "kill switch" is a physical switch found on some network cards that
# disables the card.
_Description: Kill switch enabled on ${iface}
${iface} appears to have been disabled by means of a physical "kill
switch". If you intend to use this interface, please switch it on before
continuing.

Template: netcfg/wireless_adhoc_managed
Type: select
Default: Infrastructure (Managed) network


+ 61
- 0
netcfg-common.c View File

@@ -111,6 +111,67 @@ void open_sockets (void)
skfd = socket (AF_INET, SOCK_DGRAM, 0);
}

#define SYSCLASSNET "/sys/class/net/"

/* Returns non-zero if this interface has an enabled kill switch, otherwise
* zero.
*/
int check_kill_switch(const char *iface)
{
char *temp, *linkbuf;
const char *killname;
char killstate;
size_t len;
int linklen, killlen;
int fd = -1;
int ret = 0;

/* longest string we need */
len = strlen(SYSCLASSNET) + strlen(iface) + strlen("/device/rf_kill") + 1;

temp = malloc(len);
snprintf(temp, len, SYSCLASSNET "%s/driver", iface);
linkbuf = malloc(1024); /* probably OK ... I hate readlink() */
linklen = readlink(temp, linkbuf, 1024);
if (linklen < 0)
goto out;

if (strncmp(linkbuf + linklen - 8, "/ipw2100", 8) == 0)
killname = "rf_kill";
else if (strncmp(linkbuf + linklen - 8, "/ipw2200", 8) == 0)
killname = "rf_kill";
else
goto out;

snprintf(temp, len, SYSCLASSNET "%s/device/%s", iface, killname);
di_info("Checking RF kill switch: %s", temp);
fd = open(temp, O_RDONLY);
if (fd == -1)
goto out;
killlen = read(fd, &killstate, 1);
if (killlen < 0) {
di_error("Failed to read RF kill state: %s", strerror(errno));
goto out;
} else if (killlen == 0) {
di_warning("RF kill state file empty");
goto out;
}

if (killstate == '2') {
di_info("RF kill switch enabled");
ret = 1;
}

out:
free(temp);
free(linkbuf);
if (fd != -1)
close(fd);
return ret;
}

#undef SYSCLASSNET

int is_interface_up(char *inter)
{
struct ifreq ifr;


+ 17
- 0
netcfg.c View File

@@ -98,6 +98,20 @@ int main(int argc, char *argv[])
{
while (*ifaces)
{
if (check_kill_switch(*ifaces)) {
debconf_subst(client, "netcfg/kill_switch_enabled", "iface", *ifaces);
debconf_input(client, "high", "netcfg/kill_switch_enabled");
if (debconf_go(client) == 30) {
state = BACKUP;
break;
}
/* Is it still enabled? */
if (check_kill_switch(*ifaces)) {
ifaces++;
continue;
}
}

interface_up(*ifaces);
usleep(250);
@@ -150,6 +164,9 @@ int main(int argc, char *argv[])
}
}
if (state == BACKUP)
break;

if (!defiface && defwireless)
defiface = defwireless;



+ 2
- 0
netcfg.h View File

@@ -67,6 +67,8 @@ extern char *essid, *wepkey;
extern wifimode_t mode;

/* common functions */
extern int check_kill_switch (const char *iface);

extern int is_interface_up (char *inter);

extern void get_name (char *name, char *p);


Loading…
Cancel
Save