Exemple #1
0
static double
get_freq_number(void *arg)
{
	double freq;

	if (iw_get_ext(skfd, arg, SIOCGIWFREQ, &wrq) < 0) {
		xsg_debug("get_freq_number: UNKNOWN");
		return DNAN;
	}

	freq = iw_freq2float(&(wrq.u.freq));

	if (freq < KILO) {
		if (iw_get_range_info(skfd, arg, &range) >= 0) {
			iw_channel_to_freq((int) freq, &freq, &range);
		}
	}

	xsg_debug("get_freq_number: %f", freq);
	return freq;
}
/*
 * Print on the screen in a neat fashion all the info we have collected
 * on a device.
 */
static void
display_info(struct wireless_info *	info,
	     char *			ifname)
{
  char		buffer[128];	/* Temporary buffer */

  /* One token is more of less 5 characters, 14 tokens per line */
  int	tokens = 3;	/* For name */

  /* Display device name and wireless name (name of the protocol used) */
  printf("%-8.16s  %s  ", ifname, info->b.name);

  /* Display ESSID (extended network), if any */
  if(info->b.has_essid)
    {
      if(info->b.essid_on)
	{
	  /* Does it have an ESSID index ? */
	  if((info->b.essid_on & IW_ENCODE_INDEX) > 1)
	    printf("ESSID:\"%s\" [%d]  ", info->b.essid,
		   (info->b.essid_on & IW_ENCODE_INDEX));
	  else
	    printf("ESSID:\"%s\"  ", info->b.essid);
	}
      else
	printf("ESSID:off/any  ");
    }

#ifndef WE_ESSENTIAL
  /* Display NickName (station name), if any */
  if(info->has_nickname)
    printf("Nickname:\"%s\"", info->nickname);
#endif	/* WE_ESSENTIAL */

  /* Formatting */
  if(info->b.has_essid || info->has_nickname)
    {
      printf("\n          ");
      tokens = 0;
    }

#ifndef WE_ESSENTIAL
  /* Display Network ID */
  if(info->b.has_nwid)
    {
      /* Note : should display proper number of digits according to info
       * in range structure */
      if(info->b.nwid.disabled)
	printf("NWID:off/any  ");
      else
	printf("NWID:%X  ", info->b.nwid.value);
      tokens +=2;
    }
#endif	/* WE_ESSENTIAL */

  /* Display the current mode of operation */
  if(info->b.has_mode)
    {
      printf("Mode:%s  ", iw_operation_mode[info->b.mode]);
      tokens +=3;
    }

  /* Display frequency / channel */
  if(info->b.has_freq)
    {
      double		freq = info->b.freq;	/* Frequency/channel */
      int		channel = -1;		/* Converted to channel */
      /* Some drivers insist of returning channel instead of frequency.
       * This fixes them up. Note that, driver should still return
       * frequency, because other tools depend on it. */
      if(info->has_range && (freq < KILO))
	channel = iw_channel_to_freq((int) freq, &freq, &info->range);
      /* Display */
      iw_print_freq(buffer, sizeof(buffer), freq, -1, info->b.freq_flags);
      printf("%s  ", buffer);
      tokens +=4;
    }

  /* Display the address of the current Access Point */
  if(info->has_ap_addr)
    {
      /* A bit of clever formatting */
      if(tokens > 8)
	{
	  printf("\n          ");
	  tokens = 0;
	}
      tokens +=6;

      /* Oups ! No Access Point in Ad-Hoc mode */
      if((info->b.has_mode) && (info->b.mode == IW_MODE_ADHOC))
	printf("Cell:");
      else
	printf("Access Point:");
      printf(" %s   ", iw_sawap_ntop(&info->ap_addr, buffer));
    }

  /* Display the currently used/set bit-rate */
  if(info->has_bitrate)
    {
      /* A bit of clever formatting */
      if(tokens > 11)
	{
	  printf("\n          ");
	  tokens = 0;
	}
      tokens +=3;

      /* Display it */
      iw_print_bitrate(buffer, sizeof(buffer), info->bitrate.value);
      printf("Bit Rate%c%s   ", (info->bitrate.fixed ? '=' : ':'), buffer);
    }

#ifndef WE_ESSENTIAL
  /* Display the Transmit Power */
  if(info->has_txpower)
    {
      /* A bit of clever formatting */
      if(tokens > 11)
	{
	  printf("\n          ");
	  tokens = 0;
	}
      tokens +=3;

      /* Display it */
      iw_print_txpower(buffer, sizeof(buffer), &info->txpower);
      printf("Tx-Power%c%s   ", (info->txpower.fixed ? '=' : ':'), buffer);
    }

  /* Display sensitivity */
  if(info->has_sens)
    {
      /* A bit of clever formatting */
      if(tokens > 10)
	{
	  printf("\n          ");
	  tokens = 0;
	}
      tokens +=4;

      /* Fixed ? */
      printf("Sensitivity%c", info->sens.fixed ? '=' : ':');

      if(info->has_range)
	/* Display in dBm ? */
	if(info->sens.value < 0)
	  printf("%d dBm  ", info->sens.value);
	else
	  printf("%d/%d  ", info->sens.value, info->range.sensitivity);
      else
	printf("%d  ", info->sens.value);
    }
#endif	/* WE_ESSENTIAL */

  printf("\n          ");
  tokens = 0;

#ifndef WE_ESSENTIAL
  /* Display retry limit/lifetime information */
  if(info->has_retry)
    { 
      printf("Retry");
      /* Disabled ? */
      if(info->retry.disabled)
	printf(":off");
      else
	{
	  /* Let's check the value and its type */
	  if(info->retry.flags & IW_RETRY_TYPE)
	    {
	      iw_print_retry_value(buffer, sizeof(buffer),
				   info->retry.value, info->retry.flags,
				   info->range.we_version_compiled);
	      printf("%s", buffer);
	    }

	  /* Let's check if nothing (simply on) */
	  if(info->retry.flags == IW_RETRY_ON)
	    printf(":on");
 	}
      printf("   ");
      tokens += 5;	/* Between 3 and 5, depend on flags */
    }

  /* Display the RTS threshold */
  if(info->has_rts)
    {
      /* Disabled ? */
      if(info->rts.disabled)
	printf("RTS thr:off   ");
      else
	{
	  /* Fixed ? */
	  printf("RTS thr%c%d B   ",
		 info->rts.fixed ? '=' : ':',
		 info->rts.value);
	}
      tokens += 3;
    }

  /* Display the fragmentation threshold */
  if(info->has_frag)
    {
      /* A bit of clever formatting */
      if(tokens > 10)
	{
	  printf("\n          ");
	  tokens = 0;
	}
      tokens +=4;

      /* Disabled ? */
      if(info->frag.disabled)
	printf("Fragment thr:off");
      else
	{
	  /* Fixed ? */
	  printf("Fragment thr%c%d B   ",
		 info->frag.fixed ? '=' : ':',
		 info->frag.value);
	}
    }

  /* Formating */
  if(tokens > 0)
    printf("\n          ");
#endif	/* WE_ESSENTIAL */

  /* Display encryption information */
  /* Note : we display only the "current" key, use iwlist to list all keys */
  if(info->b.has_key)
    {
      printf("Encryption key:");
      if((info->b.key_flags & IW_ENCODE_DISABLED) || (info->b.key_size == 0))
	printf("off");
      else
	{
	  /* Display the key */
	  iw_print_key(buffer, sizeof(buffer),
		       info->b.key, info->b.key_size, info->b.key_flags);
	  printf("%s", buffer);

	  /* Other info... */
	  if((info->b.key_flags & IW_ENCODE_INDEX) > 1)
	    printf(" [%d]", info->b.key_flags & IW_ENCODE_INDEX);
	  if(info->b.key_flags & IW_ENCODE_RESTRICTED)
	    printf("   Security mode:restricted");
	  if(info->b.key_flags & IW_ENCODE_OPEN)
	    printf("   Security mode:open");
 	}
      printf("\n          ");
    }

  /* Display Power Management information */
  /* Note : we display only one parameter, period or timeout. If a device
   * (such as HiperLan) has both, the user need to use iwlist... */
  if(info->has_power)	/* I hope the device has power ;-) */
    { 
      printf("Power Management");
      /* Disabled ? */
      if(info->power.disabled)
	printf(":off");
      else
	{
	  /* Let's check the value and its type */
	  if(info->power.flags & IW_POWER_TYPE)
	    {
	      iw_print_pm_value(buffer, sizeof(buffer),
				info->power.value, info->power.flags,
				info->range.we_version_compiled);
	      printf("%s  ", buffer);
	    }

	  /* Let's check the mode */
	  iw_print_pm_mode(buffer, sizeof(buffer), info->power.flags);
	  printf("%s", buffer);

	  /* Let's check if nothing (simply on) */
	  if(info->power.flags == IW_POWER_ON)
	    printf(":on");
 	}
      printf("\n          ");
    }

  /* Display statistics */
  if(info->has_stats)
    {
      iw_print_stats(buffer, sizeof(buffer),
		     &info->stats.qual, &info->range, info->has_range);
      printf("Link %s\n", buffer);

      if(info->range.we_version_compiled > 11)
	printf("          Rx invalid nwid:%d  Rx invalid crypt:%d  Rx invalid frag:%d\n          Tx excessive retries:%d  Invalid misc:%d   Missed beacon:%d\n",
	       info->stats.discard.nwid,
	       info->stats.discard.code,
	       info->stats.discard.fragment,
	       info->stats.discard.retries,
	       info->stats.discard.misc,
	       info->stats.miss.beacon);
      else
	printf("          Rx invalid nwid:%d  invalid crypt:%d  invalid misc:%d\n",
	       info->stats.discard.nwid,
	       info->stats.discard.code,
	       info->stats.discard.misc);
    }

  printf("\n");
}
Exemple #3
0
/*
 * Print one element from the scanning results
 */
static inline int
print_event_token(struct iw_event *	event,		/* Extracted token */
		  struct iw_range *	iw_range,	/* Range info */
		  int			has_range)
{
  char		buffer[128];	/* Temporary buffer */
  char		buffer2[30];	/* Temporary buffer */
  char *	prefix = (IW_IS_GET(event->cmd) ? "New" : "Set");

  /* Now, let's decode the event */
  switch(event->cmd)
    {
      /* ----- set events ----- */
      /* Events that result from a "SET XXX" operation by the user */
    case SIOCSIWNWID:
      if(event->u.nwid.disabled)
	printf("Set NWID:off/any\n");
      else
	printf("Set NWID:%X\n", event->u.nwid.value);
      break;
    case SIOCSIWFREQ:
    case SIOCGIWFREQ:
      {
	double		freq;			/* Frequency/channel */
	int		channel = -1;		/* Converted to channel */
	freq = iw_freq2float(&(event->u.freq));
	if(has_range)
	  {
	    if(freq < KILO)
	      /* Convert channel to frequency if possible */
	      channel = iw_channel_to_freq((int) freq, &freq, iw_range);
	    else
	      /* Convert frequency to channel if possible */
	      channel = iw_freq_to_channel(freq, iw_range);
	  }
	iw_print_freq(buffer, sizeof(buffer),
		      freq, channel, event->u.freq.flags);
	printf("%s %s\n", prefix, buffer);
      }
      break;
    case SIOCSIWMODE:
      printf("Set Mode:%s\n",
	     iw_operation_mode[event->u.mode]);
      break;
    case SIOCSIWESSID:
    case SIOCGIWESSID:
      {
	char essid[IW_ESSID_MAX_SIZE+1];
	memset(essid, '\0', sizeof(essid));
	if((event->u.essid.pointer) && (event->u.essid.length))
	  memcpy(essid, event->u.essid.pointer, event->u.essid.length);
	if(event->u.essid.flags)
	  {
	    /* Does it have an ESSID index ? */
	    if((event->u.essid.flags & IW_ENCODE_INDEX) > 1)
	      printf("%s ESSID:\"%s\" [%d]\n", prefix, essid,
		     (event->u.essid.flags & IW_ENCODE_INDEX));
	    else
	      printf("%s ESSID:\"%s\"\n", prefix, essid);
	  }
	else
	  printf("%s ESSID:off/any\n", prefix);
      }
      break;
    case SIOCSIWENCODE:
      {
	unsigned char	key[IW_ENCODING_TOKEN_MAX];
	if(event->u.data.pointer)
	  memcpy(key, event->u.data.pointer, event->u.data.length);
	else
	  event->u.data.flags |= IW_ENCODE_NOKEY;
	printf("Set Encryption key:");
	if(event->u.data.flags & IW_ENCODE_DISABLED)
	  printf("off\n");
	else
	  {
	    /* Display the key */
	    iw_print_key(buffer, sizeof(buffer), key, event->u.data.length,
			 event->u.data.flags);
	    printf("%s", buffer);

	    /* Other info... */
	    if((event->u.data.flags & IW_ENCODE_INDEX) > 1)
	      printf(" [%d]", event->u.data.flags & IW_ENCODE_INDEX);
	    if(event->u.data.flags & IW_ENCODE_RESTRICTED)
	      printf("   Security mode:restricted");
	    if(event->u.data.flags & IW_ENCODE_OPEN)
	      printf("   Security mode:open");
	    printf("\n");
	  }
      }
      break;
      /* ----- driver events ----- */
      /* Events generated by the driver when something important happens */
    case SIOCGIWAP:
      printf("New Access Point/Cell address:%s\n",
	     iw_sawap_ntop(&event->u.ap_addr, buffer));
      break;
    case SIOCGIWSCAN:
      printf("Scan request completed\n");
      break;
    case IWEVTXDROP:
      printf("Tx packet dropped:%s\n",
	     iw_saether_ntop(&event->u.addr, buffer));
      break;
    case IWEVCUSTOM:
      {
	char custom[IW_CUSTOM_MAX+1];
	memset(custom, '\0', sizeof(custom));
	if((event->u.data.pointer) && (event->u.data.length))
	  memcpy(custom, event->u.data.pointer, event->u.data.length);
	printf("Custom driver event:%s\n", custom);
      }
      break;
    case IWEVREGISTERED:
      printf("Registered node:%s\n",
	     iw_saether_ntop(&event->u.addr, buffer));
      break;
    case IWEVEXPIRED:
      printf("Expired node:%s\n",
	     iw_saether_ntop(&event->u.addr, buffer));
      break;
    case SIOCGIWTHRSPY:
      {
	struct iw_thrspy	threshold;
	if((event->u.data.pointer) && (event->u.data.length))
	  {
	    memcpy(&threshold, event->u.data.pointer,
		   sizeof(struct iw_thrspy));
	    printf("Spy threshold crossed on address:%s\n",
		   iw_saether_ntop(&threshold.addr, buffer));
	    iw_print_stats(buffer, sizeof(buffer),
			   &threshold.qual, iw_range, has_range);
	    printf("                            Link %s\n", buffer);
	  }
	else
	  printf("Invalid Spy Threshold event\n");
      }
      break;
      /* ----- driver WPA events ----- */
      /* Events generated by the driver, used for WPA operation */
    case IWEVMICHAELMICFAILURE:
      if(event->u.data.length >= sizeof(struct iw_michaelmicfailure))
	{
	  struct iw_michaelmicfailure mf;
	  memcpy(&mf, event->u.data.pointer, sizeof(mf));
	  printf("Michael MIC failure flags:0x%X src_addr:%s tsc:%s\n",
		 mf.flags,
		 iw_saether_ntop(&mf.src_addr, buffer2),
		 iw_hexdump(buffer, sizeof(buffer),
			    mf.tsc, IW_ENCODE_SEQ_MAX_SIZE));
	}
      break;
    case IWEVASSOCREQIE:
      printf("Association Request IEs:%s\n",
	     iw_hexdump(buffer, sizeof(buffer),
			event->u.data.pointer, event->u.data.length));
      break;
    case IWEVASSOCRESPIE:
      printf("Association Response IEs:%s\n",
	     iw_hexdump(buffer, sizeof(buffer),
			event->u.data.pointer, event->u.data.length));
      break;
    case IWEVPMKIDCAND:
      if(event->u.data.length >= sizeof(struct iw_pmkid_cand))
	{
	  struct iw_pmkid_cand cand;
	  memcpy(&cand, event->u.data.pointer, sizeof(cand));
	  printf("PMKID candidate flags:0x%X index:%d bssid:%s\n",
		 cand.flags, cand.index,
		 iw_saether_ntop(&cand.bssid, buffer));
	}
      break;
      /* ----- junk ----- */
      /* other junk not currently in use */
    case SIOCGIWRATE:
      iw_print_bitrate(buffer, sizeof(buffer), event->u.bitrate.value);
      printf("New Bit Rate:%s\n", buffer);
      break;
    case SIOCGIWNAME:
      printf("Protocol:%-1.16s\n", event->u.name);
      break;
    case IWEVQUAL:
      {
	event->u.qual.updated = 0x0;	/* Not that reliable, disable */
	iw_print_stats(buffer, sizeof(buffer),
		       &event->u.qual, iw_range, has_range);
	printf("Link %s\n", buffer);
	break;
      }
    default:
      printf("(Unknown Wireless event 0x%04X)\n", event->cmd);
    }	/* switch(event->cmd) */

  return(0);
}
Exemple #4
0
/* ------------------------------------------------------------------ WirelessInterface_ScanItem */
static int WirelessInterface_ScanItem(wifacesd* data, iwevent* event, iwrange* range, int has_range)
{
	static char buf[128];

	memset(data, 0, sizeof(wifacesd));

	switch (event->cmd) {
	case SIOCGIWAP: {
		iw_ether_ntop((const struct ether_addr*)(event->u.ap_addr.sa_data), buf);

		data->keys[0] = IWSCAN_KE_BSSID;
		data->objs[0] = Py_BuildValue("s", buf);
		data->num     = 1;

		return 1;
	}

	case SIOCGIWFREQ: {
		double freq = iw_freq2float(&(event->u.freq));
		int channel;

		if (freq <= 14.0)
			channel = iw_channel_to_freq((int)(freq), &freq, range);
		else
			channel = iw_freq_to_channel(freq, range);

		iw_print_freq_value(buf, sizeof(buf), freq);

		data->keys[0] = IWSCAN_KE_FREQUENCY;
		data->keys[1] = IWSCAN_KE_CHANNEL;
		data->objs[0] = Py_BuildValue("s", buf);
		data->objs[1] = Py_BuildValue("i", channel);
		data->num     = 2;

		return 0;
	}

	case SIOCGIWMODE: {
		data->keys[0] = IWSCAN_KE_MODE;
		data->objs[0] = Py_BuildValue("s", iw_operation_mode[event->u.mode]);
		data->num     = 1;

		return 0;
	}

	case SIOCGIWNAME: {
		data->keys[0] = IWSCAN_KE_PROTOCOL;
		data->objs[0] = Py_BuildValue("s", event->u.name);
		data->num     = 1;

		return 0;
	}

	case SIOCGIWESSID: {
		memcpy(buf, event->u.essid.pointer, event->u.essid.length);
		buf[event->u.essid.length] = 0x0;

		data->keys[0] = IWSCAN_KE_ESSID;
		data->objs[0] = Py_BuildValue("s", buf);
		data->num     = 1;

		return 0;
	}

	case SIOCGIWENCODE: {
		PyObject* pybool;

		if (event->u.data.flags & IW_ENCODE_DISABLED) pybool = Py_False;
		else pybool = Py_True;

		Py_INCREF(pybool);

		data->keys[0] = IWSCAN_KE_ENC;
		data->objs[0] = pybool;
		data->num     = 1;

		return 0;
	}

	case SIOCGIWRATE: {
		iw_print_bitrate(buf, sizeof(buf), event->u.bitrate.value);

		data->keys[0] = IWSCAN_KE_BITRATE;
		data->objs[0] = Py_BuildValue("s", buf);
		data->num     = 1;

		return 0;
	}

	case IWEVQUAL: {
		iw_print_stats(buf, sizeof(buf), &event->u.qual, range, has_range);

		data->keys[0] = IWSCAN_KE_QUAL;
		data->keys[1] = IWSCAN_KE_STATS;
		data->objs[0] = Py_BuildValue("i", event->u.qual.qual);
		data->objs[1] = Py_BuildValue("s", buf);
		data->num     = 2;

		return 0;
	}

	case IWEVGENIE: {
		unsigned char* buffer = event->u.data.pointer;
		int buflen = event->u.data.length;
		int offset = 0;

		data->keys[0] = IWSCAN_KE_IE;

		//PyObject* ie_list = PyList_New(0);
		//data->objs[0] = ie_list;
		while (offset <= (buflen - 2)) {
			//PyList_Append(ie_list, WirelessInterface_ScanIe(buffer + offset, buflen));
			data->objs[0] = WirelessInterface_ScanIe(buffer + offset, buflen);
			offset += buffer[offset + 1] + 2;
		}

		data->num = 1;

		return 0;
	}

	default:
		return 0;
	}
}