谷动谷力

 找回密码
 立即注册
查看: 1354|回复: 0
打印 上一主题 下一主题
收起左侧

【OpenWrt智能路由器】c代码iwinfo库使用方法

[复制链接]
跳转到指定楼层
楼主
发表于 2022-6-28 23:18:17 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
【OpenWrt智能路由器】c代码iwinfo库使用方法

在路由开发过程中一些开发者都是直接用管道调用命令工具的方式来获取一些无线信息,这里快速介绍一下怎么使用c代码调用iwinfo库获取相应的信息。

iwinfo封装了nl80211、madwifi、qcawifi、wl_ops等驱动接口,然后将这些接口整合出一套统一的API层。
其中重要的结构如下:
  1. struct iwinfo_ops {
  2.     int (*mode)(const char *, int *);
  3.     int (*channel)(const char *, int *);
  4.     int (*frequency)(const char *, int *);
  5.     int (*frequency_offset)(const char *, int *);
  6.     int (*txpower)(const char *, int *);
  7.     int (*txpower_offset)(const char *, int *);
  8.     int (*bitrate)(const char *, int *);
  9.     int (*signal)(const char *, int *);
  10.     int (*noise)(const char *, int *);
  11.     int (*quality)(const char *, int *);
  12.     int (*quality_max)(const char *, int *);
  13.     int (*mbssid_support)(const char *, int *);
  14.     int (*hwmodelist)(const char *, int *);
  15.     int (*ssid)(const char *, char *);
  16.     int (*bssid)(const char *, char *);
  17.     int (*country)(const char *, char *);
  18.     int (*hardware_id)(const char *, char *);
  19.     int (*hardware_name)(const char *, char *);
  20.     int (*encryption)(const char *, char *);
  21.     int (*assoclist)(const char *, char *, int *);
  22.     int (*txpwrlist)(const char *, char *, int *);
  23.     int (*scanlist)(const char *, char *, int *);
  24.     int (*freqlist)(const char *, char *, int *);
  25.     int (*countrylist)(const char *, char *, int *);
  26.     int (*beacon_int)(const char *, int *);
  27.     void (*close)(void);
  28. };
复制代码

初始化的时候该结构指针就会指向对应驱动的结构,从而调用对应的处理方法。

函数:
  1. const struct iwinfo_ops * iwinfo_backend(const char *ifname); //参数传入网卡名称,返回对应的消息iwinfo_ops结构指针
  2. void iwinfo_finish(void); //关闭socket
复制代码

使用方法:
1. 调用iwinfo_backend()函数来初始化并获取对应驱动的iwinfo_ops结构指针
2. 调用iwinfo_ops中的方法来获取相应的信息
如:获取”ath0”网卡ssid名,信道…
  1. #include "iwinfo.h" iw = iwinfo_backend("ath0");
  2. iw->channel("ath0", &val);//返回值存放在val中iw->ssid("ath0", buf);//返回字符串存放在buf中
复制代码

+10
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|深圳市光明谷科技有限公司|光明谷商城|Sunshine Silicon Corpporation ( 粤ICP备14060730号|Sitemap

GMT+8, 2024-5-19 13:48 , Processed in 0.085647 second(s), 37 queries .

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表