hostapd移植(2.6版本為例)


Hostapd的移植,依賴:libnl openssl  

下載地址:

  Hostapd-2.6:http://w1.fi/releases/hostapd-2.6.tar.gz

  Libnl:             http://www.infradead.org/~tgr/libnl/files/

  Openssl:     https://www.openssl.org/source/old/1.0.1/

 

Libnl: 交叉編譯 (選擇的版本是libnl-1.1.tar.gz)

解壓安裝包,建一個__install文件夾用來保存安裝的庫文件

# mkdir __install

#./configure CC=arm-fullhan-linux-uclibcgnueabi-gcc --prefix=$PWD/__install --host=arm

#make & make install

可以看到__install/lib/ 下面有生成的libnl動態庫

 

如果希望能生成靜態庫,對lib/Makefile做如下修改:

#vim lib/Makefile

 

 修改好的 lib/Makefile

 

 1 #
 2 # lib/Makefile
 3 #
 4 #     This library is free software; you can redistribute it and/or
 5 #    modify it under the terms of the GNU Lesser General Public
 6 #    License as published by the Free Software Foundation version 2.1
 7 #    of the License.
 8 #
 9 # Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
10 #
11 
12 ifeq ($(shell [ ! -r ../Makefile.opts ] && echo 1),)
13     include ../Makefile.opts
14 endif
15 
16 # Core
17 CIN      := $(wildcard *.c)
18 # NETLINK_ROUTE
19 CIN      += $(wildcard route/*.c)
20 # Schedulers
21 CIN      += $(wildcard route/sch/*.c)
22 # Classifiers
23 CIN      += $(wildcard route/cls/*.c)
24 # Link Info Modules
25 CIN      += $(wildcard route/link/*.c)
26 # NETLINK_GENERIC
27 CIN      += $(wildcard genl/*.c)
28 # fib lookup
29 CIN      += $(wildcard fib_lookup/*.c)
30 # Netfilter
31 CIN      += $(wildcard netfilter/*.c)
32 
33 DEPS     := $(CIN:%.c=%.d)
34 OBJ      := $(CIN:%.c=%.o)
35 CFLAGS   += -fPIC
36 OUT_LIB  := $(PACKAGE_NAME).a
37 OUT_SLIB := $(PACKAGE_NAME).so.$(PACKAGE_VERSION)
38 LN_SLIB  := $(PACKAGE_NAME).so
39 LN1_SLIB := $(LN_SLIB).1
40 
41 export
42 
43 .PHONY: all clean install librtn.a $(OUT_SLIB)
44 
45 
46 all:
47     @echo "  MAKE $(OUT_LIB)"; \
48     $(MAKE) $(OUT_LIB)
49     @echo "  MAKE $(OUT_SLIB)"; \
50     $(MAKE) $(OUT_SLIB)
51 
52 $(OUT_LIB): ../Makefile.opts $(OBJ)
53     @echo "  LD $(OUT_LIB)"; \
54     echo $(AR) rs $(OUT_LIB) $(OBJ)
55     $(AR) rs $(OUT_LIB) $(OBJ)
56     
57 $(OUT_SLIB): ../Makefile.opts $(OBJ)
58     @echo "  LD $(OUT_SLIB)"; \
59     $(CC) -shared -Wl,-soname,libnl.so.1 -o $(OUT_SLIB) $(OBJ) $(LIBNL_LIB) -lc
60     @echo "  LN $(OUT_SLIB) $(LN1_SLIB)"; \
61     rm -f $(LN1_SLIB) ; $(LN) -s $(OUT_SLIB) $(LN1_SLIB)
62     @echo "  LN $(LN1_SLIB) $(LN_SLIB)"; \
63     rm -f $(LN_SLIB) ; $(LN) -s $(LN1_SLIB) $(LN_SLIB)
64 
65 clean:
66     @echo "  CLEAN lib"; \
67     $(RM) -f $(OBJ) $(OUT_LIB) $(OUT_SLIB) $(LN_SLIB) $(LN1_SLIB); \
68     $(RM) -f $(DEPS) $(OUT_LIB) $(OUT_SLIB) $(LN_SLIB) $(LN1_SLIB)
69 
70 distclean:
71     @echo "  DISTCLEAN lib"; \
72     $(RM) -f $(DEPS)
73 
74 install:
75     mkdir -p $(DESTDIR)$(libdir)/
76     install -m 0644 $(OUT_SLIB) $(DESTDIR)$(libdir)
77     install -m 0644 $(OUT_LIB) $(DESTDIR)$(libdir)
78     rm -f $(DESTDIR)$(libdir)/$(LN1_SLIB)
79     $(LN) -s $(OUT_SLIB) $(DESTDIR)$(libdir)/$(LN1_SLIB)
80     rm -f $(DESTDIR)$(libdir)/$(LN_SLIB)
81     $(LN) -s $(LN1_SLIB) $(DESTDIR)$(libdir)/$(LN_SLIB)
82 
83 $(DEPS): ../Makefile.opts
84 
85 include ../Makefile.rules

 

 

 

保存退出,make& make install 就可以生成libnl.a 靜態庫了。

 

 

 

 

Openssl交叉編譯:(選擇的版本是openssl-1.1.1.tar.gz)

 解壓安裝包,建一個__install文件夾用來保存安裝的庫文件

# mkdir __install

# ./config no-asm no-shared no-async --prefix=$PWD/__install

注意:如果不加入no-async,會出現以下錯誤:

       ./libcrypto.a(b_sock.o): In function `BIO_gethostbyname':

b_sock.c:(.text+0x4a8): warning: gethostbyname is obsolescent, use getnameinfo() instead.

./libcrypto.a(async_posix.o): In function `ASYNC_is_capable':

async_posix.c:(.text+0x48): undefined reference to `getcontext'

./libcrypto.a(async_posix.o): In function `async_fibre_makecontext':

async_posix.c:(.text+0x7c): undefined reference to `getcontext'

async_posix.c:(.text+0xec): undefined reference to `makecontext'

./libcrypto.a(async.o): In function `async_fibre_swapcontext':

async.c:(.text+0x28c): undefined reference to `setcontext'

collect2: ld returned 1 exit status

make[1]: *** [apps/openssl] Error 1

make[1]: Leaving directory `/test/hostapd_test/openssl-1.1.1'

make: *** [all] Error 2

 

修改Makefile

 #PLATFORM=linux-x86

PLATFORM=linux-armv7

#CROSS_COMPILE

CROSS_COMPILE=arm-fullhan-linux-uclibcgnueabi-

刪除所有的 -m32 -m64選項

保存退出,make clean

Make & make install

在__install 里面就可以看到靜態庫了:

 

 

 

Hostapd的編譯:(選擇的版本是hostapd-2.6.tar.gz)

解壓hostapd-2.6安裝包,進入

# cp defconfig .config

修改Makefile

CC=arm-fullhan-linux-uclibcgnueabi-gcc

CFLAGS += -I /test/hostapd_test/libnl-1.1/__install/include

LIBS += -L /test/hostapd_test/libnl-1.1/__install/lib -lnl

CFLAGS += -I /test/hostapd_test/openssl-1.1.1/__install/include

LIBS += -L /test/hostapd_test/openssl-1.1.1/__install/lib -lcrypto -lssl

BINDIR := ./__install/bin

LDFLAGS += -lpthread

LDFLAGS += -lm

 

注意:

Libnl 和 libopenssl 為上述步驟編譯生成的。此處的包含路徑可以選擇絕對路徑。

如果不加入LDFLAGS += -lpthread ,LDFLAGS += -lm 兩個選項會出現如下錯誤:

install/lib/libnl-1.1.a(utils.o): In function `nl_prob2int':

libnl-1.1.1/lib/utils.c:392: undefined reference to `rint'

collect2: ld returned 1 exit status

保存;

#make & make install

就可以在__install/bin 下面生成hostapd命令了。

 

 

 注意:因為libnl和libopenssl都是編譯成靜態庫形式,所以hostapd在開發板上可以直接運行,不需要將libxxx.so 拷貝到/lib/下面

 

 上述編譯是在fuhan平台的;

 

海思平台遇到的問題:

  1.  /test/hostapd_test/openssl-1.1.1/__install/lib/libcrypto.a(b_sock.o): In function `BIO_gethostbyname':
b_sock.c:(.text+0x54): warning: gethostbyname is obsolescent, use getnameinfo() instead.
/opt/hisi-linux/x86-arm/arm-himix100-linux/host_bin/../lib/gcc/arm-linux-uclibceabi/6.3.0/../../../../arm-linux-uclibceabi/bin/ld: /opt/hisi-linux/x86-arm/arm-himix100-linux/host_bin/../target/lib/libpthread.so.0: undefined reference to symbol 'dlclose'
/opt/hisi-linux/x86-arm/arm-himix100-linux/host_bin/../target/lib/libdl.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Makefile:1077: recipe for target 'hostapd' failed
make: *** [hostapd] Error 1

解決方法:

  在hostapd的Makefile 中加入:LDFLAGS += -ldl

        

  2. 另外hostapd2.5版本,在編譯的時候,出現如下錯誤:

  CC  ../src/crypto/tls_openssl.c
../src/crypto/crypto_openssl.c: In function 'openssl_digest_vector':
../src/crypto/crypto_openssl.c:68:13: error: storage size of 'ctx' isn't known
  EVP_MD_CTX ctx;
             ^~~
../src/crypto/crypto_openssl.c: In function 'rc4_skip':
../src/crypto/crypto_openssl.c:132:17: error: storage size of 'ctx' isn't known
  EVP_CIPHER_CTX ctx;
                 ^~~
In file included from /test/hostapd_test/hostapd-2.5/src/utils/common.h:12:0,
                 from ../src/crypto/crypto_openssl.c:26:
../src/crypto/crypto_openssl.c: In function 'aes_encrypt_init':
../src/crypto/crypto_openssl.c:213:25: error: dereferencing pointer to incomplete type 'EVP_CIPHER_CTX {aka struct evp_cipher_ctx_st}'
  ctx = os_malloc(sizeof(*ctx));
                         ^~
/test/hostapd_test/hostapd-2.5/src/utils/os.h:485:30: note: in definition of macro 'os_malloc'
 #define os_malloc(s) malloc((s))
                              ^
../src/crypto/crypto_openssl.c: In function 'aes_128_cbc_encrypt':
../src/crypto/crypto_openssl.c:341:17: error: storage size of 'ctx' isn't known
  EVP_CIPHER_CTX ctx;
                 ^~~
../src/crypto/crypto_openssl.c: In function 'aes_128_cbc_decrypt':
../src/crypto/crypto_openssl.c:366:17: error: storage size of 'ctx' isn't known
  EVP_CIPHER_CTX ctx;
                 ^~~
../src/crypto/crypto_openssl.c: At top level:
../src/crypto/crypto_openssl.c:428:17: error: field 'enc' has incomplete type
  EVP_CIPHER_CTX enc;
                 ^~~
../src/crypto/crypto_openssl.c:429:17: error: field 'dec' has incomplete type
  EVP_CIPHER_CTX dec;

解決方法:

   降低openssl的版本,因為openssl1.1.1的版本中,ctx結構體的定義有改變,導致出錯。建議降低至openssl1.0.1c

另加上openssl1.0.1c的編譯過程:

版本是openssl1.0.1c.tar.gz

 解壓安裝包,建一個__install文件夾用來保存安裝的庫文件

# mkdir __install

# ./config no-asm no-shared no-async --prefix=$PWD/__install

 

修改Makefile

#CC= gcc
CC= arm-himix100-linux-gcc
#CFLAG= -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -m64 -DL_ENDIAN -DTERMIO -O3 -Wall
#DEPFLAG= -DOPENSSL_NO_EC_NISTP_64_GCC_128 -DOPENSSL_NO_GMP -DOPENSSL_NO_JPAKE -DOPENSSL_NO_MD2 -DOPENSSL_NO_RC5 -DOPENSSL_NO_RFC3779 -DOPENSSL_NO_SCTP -DOPENSSL_NO_STORE
CFLAG= -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -march=armv5 -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -Wall
DEPFLAG= -DOPENSSL_NO_EC_NISTP_64_GCC_128 -DOPENSSL_NO_GMP -DOPENSSL_NO_JPAKE -DOPENSSL_NO_MD2 -DOPENSSL_NO_RC5 -DOPENSSL_NO_RFC3779 -DOPENSSL_NO_SCTP -DOPENSSL_NO_STORE


PEX_LIBS=
EX_LIBS= -ldl
EXE_EXT=
ARFLAGS=
#AR= ar $(ARFLAGS) r
AR= arm-himix100-linux-ar $(ARFLAGS) r

#RANLIB= /usr/bin/ranlib
RANLIB= arm-himix100-linux-ranlib

#NM= nm
NM= arm-himix100-linux-nm
PERL= /usr/bin/perl
TAR= tar
TARFLAGS= --no-recursion
MAKEDEPPROG= gcc
LIBDIR=lib

保存退出,make clean

Make & make install

在__install 里面就可以看到靜態庫了:

 

 

 

 

參考:https://blog.csdn.net/u013286409/article/details/51355433

 

WiFi模塊經常用到hostapd啟軟AP,換個平台,又得重新編譯一遍,所以自己整理下,下次找也方便。借鑒了上述文章,還請不吝賜教,若侵權,聯系即刪。

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM