linux环境下网络配置的相关命令
ifconfig 可以列出当前网络信息,如ip地址网卡驱动等
ifconfig 网卡名 IP地址 netmask 子网掩码 配置固定ip地址和子网掩码地址
eg:ifconfig eth0 10.84.1.98 netmask 255.255.0.0
设置网关
route add default gw 10.84.1.1
设置dns
Linux下查看网关gateway方法:
1、route -n
2、ip route show
3、traceroute www.baidu.com -s 100 【第一行就是自己的网关】
4、netstat -r
5、more /etc/network/interfaces 【Debian/Ubuntu Linux】
6、more /etc/sysconfig/network-scripts/ifcfg-eth0 【Red Hat Linux】
iw命令的学习
要想使用一个无线网卡,首先要打开网卡
Ifconfig 网卡名 up 打开网卡
Ifconfig 网卡名 down 关闭网卡
Iw dev wlan0 scan 扫描 wlan0网卡名
Iw wlan0 connect xxx 连接到SSID为xxx的AP,这里xxx网络没有密码
Iw dev wlan0 link 查看wlan0连接状态
Ifconfig wlan0 ip netmask 子网掩码 设置固定ip地址和子网掩码
Ping www.baidu.com
Iw wlan0 disconnect 断开wifi链接
# iw help # 帮助
# iw list # 获得所有设备的功能,如带宽信息(2.4GHz,和5GHz),和802.11n的信息
# iw dev wlan0 scan # 扫描
# iw event # 监听事件
# iw dev wlan0 link # 获得链路状态
# iw wlan0 connect foo # 连接到已禁用加密的AP,这里它的SSID是foo
# iw wlan0 connect foo 2432 # 假设你有两个AP SSID 都是 foo,你知道你要连接的是 在 2432 频道
# iw wlan0 connect foo keys 0:abcde d:1:0011223344 # 连接到使用WEP的AP
# iw dev wlan1 station dump # 获取station 的统计信息
# iw dev wlan1 station get # 获得station对应的peer统计信息
# iw wlan0 set bitrates legacy-2.4 12 18 24 # 修改传输比特率
# iw dev wlan0 set bitrates mcs-5 4 # 修改tx HT MCS的比特率
# iw dev wlan0 set bitrates mcs-2.4 10
# iw dev wlan0 set bitrates mcs-5 # 清除所有 tx 比特率和设置的东西来恢复正常
# iw dev set txpower [] #设置传输功率
# iw phy set txpower [] #设置传输功率
# iw dev wlan0 set power_save on #设置省电模式
# iw dev wlan0 get power_save #查询当前的节电设定
# iw phy phy0 interface add moni0 type monitor #添加一个 monitor 接口
您可以设定用于使用某些传统的比特率传输的性能。 例如:
iw wlan0 set bitrates legacy-2.4 12 18 24
以下是如何使能一些人所说的“Purge G”来禁用802.11b 关联:
iw wlan0 set bitrates legacy-2.4 6 12 24
修改tx HT MCS的比特率
设置使用MCS率传输的能力是通过让你指定频段和MCS率来实现。 注意,是否该设备实际上监听你的请求将根据设备驱动程序和固件的配合而变化。 例如:
iw dev wlan0 set bitrates mcs-5 4
iw dev wlan0 set bitrates mcs-2.4 10
清除所有 tx 比特率和设置的东西来恢复正常:
iw dev wlan0 set bitrates mcs-2.4
iw dev wlan0 set bitrates mcs-5
设置传输功率
可以通过使用各自的phy的任一设备接口名称来设置 txpower 。
iw dev <devname> set txpower <auto|fixed|limit> [<tx power in mBm>]
iw phy <phyname> set txpower <auto|fixed|limit> [<tx power in mBm>]
wireless tools工具
代码下载地址:http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/wireless_tools.29.tar.gz
首先将解压的目录改名为wireless-tools,并放到external/wireless-tools
添加Android.mk
LOCAL_PATH:=$(call my-dir)# iwlib
include $(CLEAR_VARS)LOCAL_SRC_FILES := iwlib.cLOCAL_CFLAGS += -Wno-parentheses-equality -Wno-tautological-compare -Wno-self-assign \-Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wpointer-arith -Wcast-qual \-Winline -MMD -fPIC
LOCAL_STATIC_LIBRARIES := libcutils libc libmLOCAL_MODULE := libiw
LOCAL_MODULE_TAGS :=optionalinclude $(BUILD_STATIC_LIBRARY)# iwconfig
include $(CLEAR_VARS)LOCAL_SRC_FILES := iwconfig.cLOCAL_CFLAGS += -Wno-parentheses-equality -Wno-tautological-compare -Wno-self-assign \-Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wpointer-arith -Wcast-qual \-Winline -MMD -fPICLOCAL_STATIC_LIBRARIES := libcutils libc libm libiw
LOCAL_FORCE_STATIC_EXECUTABLE := trueLOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) # install to system/xbinLOCAL_MODULE:= iwconfig
LOCAL_MODULE_TAGS :=optionalinclude $(BUILD_EXECUTABLE)# iwevent
include $(CLEAR_VARS)LOCAL_SRC_FILES := iwevent.cLOCAL_CFLAGS += -Wno-parentheses-equality -Wno-tautological-compare -Wno-self-assign \-Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wpointer-arith -Wcast-qual \-Winline -MMD -fPICLOCAL_STATIC_LIBRARIES := libcutils libc libm libiw
LOCAL_FORCE_STATIC_EXECUTABLE := trueLOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) # install to system/xbinLOCAL_MODULE:= iwevent
LOCAL_MODULE_TAGS :=optionalinclude $(BUILD_EXECUTABLE)# iwgetid
include $(CLEAR_VARS)LOCAL_SRC_FILES := iwgetid.cLOCAL_CFLAGS += -Wno-parentheses-equality -Wno-tautological-compare -Wno-self-assign \-Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wpointer-arith -Wcast-qual \-Winline -MMD -fPICLOCAL_STATIC_LIBRARIES := libcutils libc libm libiw
LOCAL_FORCE_STATIC_EXECUTABLE := trueLOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) # install to system/xbinLOCAL_MODULE:= iwgetid
LOCAL_MODULE_TAGS :=optionalinclude $(BUILD_EXECUTABLE)# iwlist
include $(CLEAR_VARS)LOCAL_SRC_FILES := iwlist.cLOCAL_CFLAGS += -Wno-parentheses-equality -Wno-tautological-compare -Wno-self-assign \-Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wpointer-arith -Wcast-qual \-Winline -MMD -fPICLOCAL_STATIC_LIBRARIES := libcutils libc libm libiw
LOCAL_FORCE_STATIC_EXECUTABLE := trueLOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) # install to system/xbinLOCAL_MODULE:= iwlist
LOCAL_MODULE_TAGS :=optionalinclude $(BUILD_EXECUTABLE)# iwpriv
include $(CLEAR_VARS)LOCAL_SRC_FILES := iwpriv.cLOCAL_CFLAGS += -Wno-parentheses-equality -Wno-tautological-compare -Wno-self-assign \-Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wpointer-arith -Wcast-qual \-Winline -MMD -fPICLOCAL_STATIC_LIBRARIES := libcutils libc libm libiw
LOCAL_FORCE_STATIC_EXECUTABLE := trueLOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) # install to system/xbinLOCAL_MODULE:= iwpriv
LOCAL_MODULE_TAGS :=optionalinclude $(BUILD_EXECUTABLE)# iwspy
include $(CLEAR_VARS)
LOCAL_SRC_FILES := iwspy.cLOCAL_CFLAGS += -Wno-parentheses-equality -Wno-tautological-compare -Wno-self-assign \-Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wpointer-arith -Wcast-qual \-Winline -MMD -fPICLOCAL_STATIC_LIBRARIES := libcutils libc libm libiw
LOCAL_FORCE_STATIC_EXECUTABLE := trueLOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) # install to system/xbinLOCAL_MODULE:= iwspy
LOCAL_MODULE_TAGS :=optionalinclude $(BUILD_EXECUTABLE)
LOCAL_FORCE_STATIC_EXECUTABLE:如果编译时候需要链接的动态库库存在静态库形式,那么在这个编译变量等于true的情况下,将会链接到对应的静态库而不是动态库。比如上面列出的libm,libz,libc,libcutils,libutils,liblog等动静态库都存在,那么在该变量被置true的时候,将会链接对应的静态库。当然对于本来就是静态库的libHWrecog.a来说,该变量值不会影响它是被静态链接的。所以可以想到这个参数的设置是和前面用gcc编译时候指定-static参数一样的效果, 推荐只是编译特殊ELF文件才用。
将wireless.22.h改名为wireless.h
修改iwlib.h
#endif /* IW_EV_LCP_PK_LEN */
放到
#define IW_EV_POINT_PK_LEN (IW_EV_LCP_PK_LEN + 4)
后面
Android 7.0及以上 编译的时候可能会报错
iwlib.c:478:6: error: implicitly declaring library function 'bzero' with type 'void (void *, unsigned long)' [-Werror,-Wimplicit-function-declaration]
bzero(&newtio, sizeof( newtio ));
^
iwlib.c:478:6: note: include the header <strings.h> or explicitly provide a declaration for 'bzero'
这是因为bzero函数包含在<strings.h>头文件,而iwlib.h只包含了<string.h>
并且在POSIX.1-2001标准里面,bzero函数被标记为了遗留函数而不推荐使用。在POSIX.1-2008标准里已经没有bzero函数了。推荐使用memset替代bzero。
所以可以在iwlib.h里定义一个宏函数
#define bzero(buffer, size) memset(buffer, 0, size)
external/wireless-tools/iwconfig.c:484:8: error: explicitly assigning value of variable of type 'char **' to itself [-Werror,-Wself-assign]
移植过程中出现上述错误,这是因为
print_info(int skfd,char * ifname,char * args[],int count)
{struct wireless_info info;int rc;/* Avoid "Unused parameter" warning */args = args; count = count;
代码中为了避免Unused报错,将形参赋值给了自己,导致编译报错
解决方法,在Android.mk中加上下面的flags
LOCAL_CFLAGS += -Wno-parentheses-equality -Wno-tautological-compare -Wno-self-assign
代码生成位置:
iwgetid (ou...sdm660_64/obj/EXECUTABLES/iwgetid_intermediates/iwgetid)
iwpriv (out...t/sdm660_64/obj/EXECUTABLES/iwpriv_intermediates/iwpriv)
iwlist (out...t/sdm660_64/obj/EXECUTABLES/iwlist_intermediates/iwlist)
iwevent (ou...sdm660_64/obj/EXECUTABLES/iwevent_intermediates/iwevent)
iwspy (out/...uct/sdm660_64/obj/EXECUTABLES/iwspy_intermediates/iwspy)
iwconfig (o...m660_64/obj/EXECUTABLES/iwconfig_intermediates/iwconfig)
生成的所有可执行文件都可以在这里找到
out\target\product\sdm660_64\system\xbin