如何移植wireless tool到Android

代码下载地址:http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/wireless_tools.29.tar.gz

  1. 首先将解压的目录改名为wireless-tools,并放到external/wireless-tools

  2. 添加Android.mk

LOCAL_PATH:=$(call my-dir)

# iwlib
include $(CLEAR_VARS)

LOCAL_SRC_FILES := iwlib.c

LOCAL_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 libm

LOCAL_MODULE := libiw
LOCAL_MODULE_TAGS :=optional

include $(BUILD_STATIC_LIBRARY)

# iwconfig
include $(CLEAR_VARS)

LOCAL_SRC_FILES := iwconfig.c

LOCAL_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 libm libiw
LOCAL_FORCE_STATIC_EXECUTABLE := true

LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)  # install to system/xbin

LOCAL_MODULE:= iwconfig
LOCAL_MODULE_TAGS :=optional

include $(BUILD_EXECUTABLE)

# iwevent
include $(CLEAR_VARS)

LOCAL_SRC_FILES := iwevent.c

LOCAL_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 libm libiw
LOCAL_FORCE_STATIC_EXECUTABLE := true

LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)  # install to system/xbin

LOCAL_MODULE:= iwevent
LOCAL_MODULE_TAGS :=optional

include $(BUILD_EXECUTABLE)

# iwgetid
include $(CLEAR_VARS)

LOCAL_SRC_FILES := iwgetid.c

LOCAL_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 libm libiw
LOCAL_FORCE_STATIC_EXECUTABLE := true

LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)  # install to system/xbin

LOCAL_MODULE:= iwgetid
LOCAL_MODULE_TAGS :=optional

include $(BUILD_EXECUTABLE)

# iwlist
include $(CLEAR_VARS)

LOCAL_SRC_FILES := iwlist.c

LOCAL_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 libm libiw
LOCAL_FORCE_STATIC_EXECUTABLE := true

LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)  # install to system/xbin

LOCAL_MODULE:= iwlist
LOCAL_MODULE_TAGS :=optional

include $(BUILD_EXECUTABLE)

# iwpriv
include $(CLEAR_VARS)

LOCAL_SRC_FILES := iwpriv.c

LOCAL_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 libm libiw
LOCAL_FORCE_STATIC_EXECUTABLE := true

LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)  # install to system/xbin

LOCAL_MODULE:= iwpriv
LOCAL_MODULE_TAGS :=optional

include $(BUILD_EXECUTABLE)


# iwspy
include $(CLEAR_VARS)
LOCAL_SRC_FILES := iwspy.c

LOCAL_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 libm libiw
LOCAL_FORCE_STATIC_EXECUTABLE := true

LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)  # install to system/xbin

LOCAL_MODULE:= iwspy
LOCAL_MODULE_TAGS :=optional

include $(BUILD_EXECUTABLE)
  1. 将wireless.22.h改名为wireless.h

4.修改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 or explicitly provide a declaration for 'bzero'

这是因为bzero函数包含在头文件,而iwlib.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

你可能感兴趣的:(如何移植wireless tool到Android)