如何确定wlan usb设备使用的驱动程序

时间:2012-01-26 10:14:18

标签: c posix wifi driver ioctl

简短:是否有一种posix方法来检查某些USB设备使用的驱动程序,例如使用ioctl()

现在,为什么我需要它:

我有一个wlan扫描应用程序(专用于使用USB wlan加密狗的设备),它来自iwlist并使用iwlib。

我简短,用这样的东西初始化扫描是什么:

struct iwreq wrq;
ioctl(skfd, SIOCSIWSCAN, &wrq);

等待存储在wrq.u.data.pointer的结果,然后使用iw_extract_event_stream进行解析,将数据标记为struct iw_event iwe令牌,其中包含有关检测到的网络的信息。

这是背景,现在我的真正问题就开始了。为了获得信号质量,我们需要找到标记为IWEVQUAL的标记,然后从iwe.u.qual.qual读取值。不幸的是,对于某些驱动程序和系统架构而言,这个值始终是错误的。因为某些原因我不能/不想更改驱动程序,我必须实现一些使用信号级别计算信号质量的解决方法:

case IWEVQUAL:
{
  const int lvl_max = (0.9) * (range.max_qual.level?range.max_qual.level : 255);
  const int lvl_min = lvl_max * 0.6; //we assume that signal below this sevel is not received
  int lvl = (iwe.u.qual.level > lvl_min)?iwe.u.qual.level : lvl_min; //however it might happen, since our assumption is very weak
  int lvl_scaled;

  (lvl > lvl_max)?(lvl=lvl_max):0;//it may also happen that actual level is higher that the max we assumed 
  lvl_scaled = ((lvl - lvl_min) * lvl_max) / (lvl_max - lvl_min);

  if(ap_info == NULL) break;
  ap_info->ubRssi = (100 * lvl_scaled) / lvl_max;
}

如您所见,基于许多任意假设,这是非常脏的方式,因此最好尽可能使用iwe.u.qual.qual中的原始值。因此,我想检查当前插入的设备使用的驱动程序是否可以使用标准方式,或者我应该使用上述hocus pocus。

0 个答案:

没有答案