From 4f7def25f2634ad291797d780284dd7906b25c1d Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Sun, 14 Sep 2014 20:46:14 +0000 Subject: [PATCH] Work in progrsss. FossilOrigin-Name: efb7fb1dc204a4d673f899994eb72005a6cdead3dff43ecab63f1ed4ca8e61ba --- src/Config.mak | 11 ++- src/ac/wtpman.c | 2 +- src/capwap/Makefile | 5 +- src/capwap/conn_send_cwmsg.c | 3 +- src/capwap/cw_foreach_msgelem.c | 30 +++++---- src/capwap/cwmsg_addelem_ac_timestamp.c | 2 +- src/capwap/cwmsg_addelem_wtp_descriptor.c | 27 ++++++-- src/capwap/cwmsg_send.c | 4 +- src/capwap/cwsend_discovery_request.c | 31 +++++++-- src/capwap/cwsend_discovery_response.c | 2 +- src/wtp/Makefile | 30 +++++++-- src/wtp/conf_uci.c | 7 +- src/wtp/wtp_conf.c | 11 +-- src/wtp/wtp_interface.c | 16 ++--- src/wtp/wtp_main.c | 12 ++-- src/wtp/wtpdrv.c | 82 ++++++++++++++++++++++- 16 files changed, 214 insertions(+), 61 deletions(-) diff --git a/src/Config.mak b/src/Config.mak index 1ebf2e86..013b4a37 100644 --- a/src/Config.mak +++ b/src/Config.mak @@ -7,6 +7,13 @@ USE_CONTRIB_OPENSSL=1 CONF_LIBRARY=UCI -USE_CONTRIB_UCI=1 +USE_CONTRIB_UCI=0 + +#CC=clang + + +#CC=mips-openwrt-linux-uclibc-gcc +#LD=mips-openwrt-linux-uclibc-ld +#AR=mips-openwrt-linux-uclibc-ar + -CC=clang diff --git a/src/ac/wtpman.c b/src/ac/wtpman.c index 01ace1c6..59f78533 100644 --- a/src/ac/wtpman.c +++ b/src/ac/wtpman.c @@ -371,7 +371,7 @@ static void wtpman_run_discovery(void *arg) wtpinfo_print(wtpinfostr,&wtpman->wtpinfo); cw_dbg(DBG_CW_INFO,"Discovery request gave us the follwing WTP Info:\n%s",wtpinfostr); -exit(0); +//exit(0); struct radioinfo radioinfo; diff --git a/src/capwap/Makefile b/src/capwap/Makefile index 93d8a313..14194bad 100644 --- a/src/capwap/Makefile +++ b/src/capwap/Makefile @@ -1,4 +1,3 @@ -CC=clang ifndef CC CC=gcc endif @@ -139,8 +138,8 @@ DTLSOBJS= dtls_openssl.o \ dtls_openssl_connect.o \ dtls_openssl_get_cipher.o \ dtls_openssl_bio.o \ - dtls_gnutls.o \ - dtls_gnutls_accept.o \ +# dtls_gnutls.o \ +# dtls_gnutls_accept.o \ CONNOBJS= conn.o \ diff --git a/src/capwap/conn_send_cwmsg.c b/src/capwap/conn_send_cwmsg.c index 072a81d5..eba8ea06 100644 --- a/src/capwap/conn_send_cwmsg.c +++ b/src/capwap/conn_send_cwmsg.c @@ -28,7 +28,8 @@ int conn_send_cwmsg(struct conn * conn, struct cwmsg * cwmsg) uint32_t val; /* second dword of message control header */ - val = (cwmsg->seqnum<<24)|((cwmsg->pos+3)<<8); +//orig val = (cwmsg->seqnum<<24)|((cwmsg->pos+3)<<8); + val = (cwmsg->seqnum<<24)|((cwmsg->pos)<<8); *((uint32_t*)(cwmsg->ctrlhdr+4))=htonl(val); diff --git a/src/capwap/cw_foreach_msgelem.c b/src/capwap/cw_foreach_msgelem.c index 7aeadf87..30149ded 100644 --- a/src/capwap/cw_foreach_msgelem.c +++ b/src/capwap/cw_foreach_msgelem.c @@ -18,29 +18,35 @@ #include "capwap.h" +#include + /* * for each capwap message element in msgelems call the callback function */ -int cw_foreach_msgelem(uint8_t * msgelems, int len, - int (*callback)(void*,int,uint8_t*,int),void *arg ) +int cw_foreach_msgelem(uint8_t * msgelems, int len, + int (*callback) (void *, int, uint8_t *, int), + void *arg) { uint32_t val; int type; int elen; - int i=0; + int i = 0; do { - val = ntohl(*(uint32_t*)(msgelems+i)); - type=(val>>16) & 0xFFFF; + val = ntohl(*(uint32_t *) (msgelems + i)); + type = (val >> 16) & 0xFFFF; elen = val & 0xffff; - if (i+elen+4>len) { + if (i + elen + 4 > len) { + +printf("***************************************************************************\n"); +printf("Type: %d\n",type); +printf("Bumm %d %d\n",i+elen+4,len); + return 0; } - - callback(arg,type,msgelems+i+4,elen); - i+=elen+4; - } while (ihardware_vendor_id,wtpinfo->hardware_version,2); len+=wtpdesc_addsubelem(d+len,CWMSGSUBELEM_WTP_DESCRIPTOR_HARDWARE_VERSION, - wtpinfo->hardware_vendor_id,wtpinfo->hardware_version); + wtpinfo->hardware_vendor_id,hww,2); /* software subelem*/ len+=wtpdesc_addsubelem(d+len,CWMSGSUBELEM_WTP_DESCRIPTOR_SOFTWARE_VERSION, - wtpinfo->software_vendor_id,wtpinfo->software_version); + wtpinfo->software_vendor_id,wtpinfo->software_version,-1); /* bootloader subelem*/ len+=wtpdesc_addsubelem(d+len,CWMSGSUBELEM_WTP_DESCRIPTOR_BOOTLOADER_VERSION, - wtpinfo->bootloader_vendor_id,wtpinfo->bootloader_version); + wtpinfo->bootloader_vendor_id,wtpinfo->bootloader_version,-1); cwmsg_addelem(cwmsg,CWMSGELEM_WTP_DESCRIPTOR,d,len); diff --git a/src/capwap/cwmsg_send.c b/src/capwap/cwmsg_send.c index a2935bea..9203ff5c 100644 --- a/src/capwap/cwmsg_send.c +++ b/src/capwap/cwmsg_send.c @@ -28,7 +28,9 @@ int __old_cwmsg_send(struct cwmsg * cwmsg, int seqnum, int rid, struct conn * co uint32_t val; /* second dword of message control header */ - val = (seqnum<<24)|((cwmsg->pos+3)<<8); +//orig val = (seqnum<<24)|((cwmsg->pos+3)<<8); +val = (seqnum<<24)|((cwmsg->pos)<<8); + *((uint32_t*)(cwmsg->ctrlhdr+4))=htonl(val); diff --git a/src/capwap/cwsend_discovery_request.c b/src/capwap/cwsend_discovery_request.c index 18dee2c8..2c110ce7 100644 --- a/src/capwap/cwsend_discovery_request.c +++ b/src/capwap/cwsend_discovery_request.c @@ -25,15 +25,38 @@ int cwsend_discovery_request(struct conn * conn,struct radioinfo * radioinfo,str uint8_t buffer[CWMSG_MAX_SIZE]; struct cwmsg cwmsg; - cwmsg_init(&cwmsg,buffer,CWMSG_DISCOVERY_REQUEST,conn_get_next_seqnum(conn),radioinfo); + cwmsg_init(&cwmsg,buffer,CWMSG_DISCOVERY_REQUEST,conn_get_next_seqnum(conn),NULL /*radioinfo*/); cwmsg_addelem(&cwmsg,CWMSGELEM_DISCOVERY_TYPE,&wtpinfo->discovery_type,sizeof(uint8_t)); - cwmsg_addelem_wtp_board_data(&cwmsg,wtpinfo); +// cwmsg_addelem_wtp_board_data(&cwmsg,wtpinfo); cwmsg_addelem_wtp_descriptor(&cwmsg,wtpinfo); cwmsg_addelem(&cwmsg,CWMSGELEM_WTP_FRAME_TUNNEL_MODE,&wtpinfo->frame_tunnel_mode,sizeof(uint8_t)); cwmsg_addelem(&cwmsg,CWMSGELEM_WTP_MAC_TYPE,&wtpinfo->mac_type,sizeof(uint8_t)); - cwmsg_addelem_wtp_radio_infos(&cwmsg,wtpinfo->radioinfo); - cwmsg_addelem_mtu_discovery_padding(&cwmsg,conn); + +//cwmsg_addelem(&cwmsg,CWMSGELEM_CAPWAP_LOCAL_IPV4_ADDRESS); +cwmsg_addelem_cw_local_ip_addr(&cwmsg,conn); + +// cwmsg_addelem_wtp_radio_infos(&cwmsg,wtpinfo->radioinfo); +// cwmsg_addelem_mtu_discovery_padding(&cwmsg,conn); + + +//uint8_t zven[] = {0xBF, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,0x66,0x69,0x73,0x68,0x00,0x02,0xFC,0xF5,0x28,0xCA,0xAE,0xE4,0x00,0x03,0x10,0x10, +//0x04, 0x10, 0x00,0x00,0x10,0x00,0x00,0x06,0xFC,0xF5,0x28,0xCA,0xAE,0xE5,0xC4,0x2E,0xC4,0x2E,0xC4,0x2E,0xC4,0x2E,0xC4,0x2E, +//0xC4,0x2E,0xC4,0x2E,0xC4,0x2E,0xC4,0x2E }; + + +uint8_t zven [] = { + // 0x00, 00 03 7A 00 02 + 0x22, 0xE0, 00, 00, 00, 00, 00, 00, 00, 0x01, 0x66, 0x69, 0x73,0x68,0x00,0x02,0xFC,0xF5,0x28,0xCA,0xAE,0xE4,0x00,0x03,0x10,0x10 , + 0x04,0x10,0x00, 00, 0x10, 00, 00,0x06,0xFC,0xF5,0x28,0xCA,0xAE,0xE5,0xAB,0x37,0xAB,0x37,0xAB,0x37,0xAB,0x37,0xAB,0x37,0xAB,0x37,0xAB,0x37,0xAB,0x37,0xAB,0x37, + 00, 0x07, 00, 00, 0x27,0x11,0x00,0x08,0x00,0x00 }; + + + + + + cwmsg_addelem_vendor_specific_payload(&cwmsg,890,2,zven,sizeof(zven)); + return conn_send_cwmsg(conn,&cwmsg); } diff --git a/src/capwap/cwsend_discovery_response.c b/src/capwap/cwsend_discovery_response.c index 9d80e247..ac16b8ac 100644 --- a/src/capwap/cwsend_discovery_response.c +++ b/src/capwap/cwsend_discovery_response.c @@ -46,7 +46,7 @@ void cwsend_discovery_response(struct conn * conn,int seqnum, struct radioinfo * cwmsg_addelem_ctrl_ip_addrs(cwmsg,acinfo); - cwmsg_addelem_vendor_cisco_ap_timesync(cwmsg); + //cwmsg_addelem_vendor_cisco_ap_timesync(cwmsg); // uint8_t buffer[]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; diff --git a/src/wtp/Makefile b/src/wtp/Makefile index bcee7104..f25025a0 100644 --- a/src/wtp/Makefile +++ b/src/wtp/Makefile @@ -1,3 +1,5 @@ +include ../WtpConfig.mak + ifndef CC CC=gcc endif @@ -38,14 +40,17 @@ CFLAGS += -O2 -Wall -g #endif LDFLAGS += -L../../src/capwap/$(ARCH) -LDFLAGS += -L/usr/local/lib +#LDFLAGS += -L/usr/local/lib LDFLAGS += -luci +#LDFLAGS += -L../capwap LDFLAGS += $(XLIB) + #LDFLAGS += -lpthread #LDFLAGS += -lrt LIBS+=-lcapwap -#LIBS+=-liw +LIBS+=-liw +LIBS+=-lnl-tiny LIBS+=-lssl LIBS+=-lcrypto #LIBS+=-lrt @@ -55,11 +60,20 @@ else LIBS+=-lconfuse endif +#HA_FILES += ../contrib/hostap/src/drivers/driver_nl80211.o -CFLAGS += -I../src -CFLAGS += -I../src/utils +HA_INCS += -I$(INCLUDE_DIR)/libnl-tiny +HA_INCS += -I../contrib/hostap/src/utils +HA_INCS += -I../contrib/hostap/src + +CFLAGS += $(HA_INCS) + + +#CFLAGS += -I../src +#CFLAGS += -I../src/utils CFLAGS += -I../../src -CFLAGS += -I/usr/local/include + +#CFLAGS += -I/usr/local/include @@ -75,6 +89,7 @@ OBJS += wtp_main.o #OBJS += wtp_conf.o + OBJS += discovery.o OBJS += wtp_interface.o OBJS += wtpdrv.o @@ -84,6 +99,11 @@ OBJS += sulking.o OBJS += configure.o OBJS += $(CONFOBJS) + +OBJS += nlt_attrnames.o + +#OBJS += $(HA_FILES) + ALL=wtp all: $(ALL) diff --git a/src/wtp/conf_uci.c b/src/wtp/conf_uci.c index a4175ceb..60a9c2e8 100644 --- a/src/wtp/conf_uci.c +++ b/src/wtp/conf_uci.c @@ -82,12 +82,7 @@ int read_config(const char * filename){ const char *str; str = uci_lookup_option_string(ctx,section,"name"); - - - - - - printf("Option string: %s\n",str); + conf_wtpname = strdup(str); return 1; diff --git a/src/wtp/wtp_conf.c b/src/wtp/wtp_conf.c index 81714814..c2468004 100644 --- a/src/wtp/wtp_conf.c +++ b/src/wtp/wtp_conf.c @@ -19,6 +19,8 @@ #include "capwap/sock.h" +#include "capwap/cw_log.h" + char * conf_primary_if=0; char * conf_wtpname=0; @@ -78,7 +80,7 @@ int wtpconf_primary_if() return 0; }; - cw_log_debug0("Primary interfac: %s, mac address: %s.", + cw_dbg(DBG_CW_INFO, "Primary interface: %s, mac address: %s.", conf_primary_if, sock_hwaddr2str(conf_macaddress,conf_macaddress_len) ); @@ -100,7 +102,7 @@ int wtpconf_name() if (!conf_wtpname) return 0; - cw_log_debug0("Using self assigned wtp name: %s",conf_wtpname); + cw_dbg(DBG_CW_INFO,"Using self assigned wtp name: %s",conf_wtpname); return 1; } @@ -112,8 +114,9 @@ int wtpconf_name() char * default_ac_list[] = { - "255.255.255.255", - "224.0.1.140", + "192.168.0.255", +// "255.255.255.255", +// "224.0.1.140", }; int wtpconf_ac_list() diff --git a/src/wtp/wtp_interface.c b/src/wtp/wtp_interface.c index a551cf9d..f175c082 100644 --- a/src/wtp/wtp_interface.c +++ b/src/wtp/wtp_interface.c @@ -31,26 +31,26 @@ struct wtpinfo * get_wtpinfo() wtpinfo->model_no="WNDR 3700"; - wtpinfo->bootloader_version="1.0"; - wtpinfo->bootloader_vendor_id=12345; + wtpinfo->bootloader_version=""; + wtpinfo->bootloader_vendor_id=890; - wtpinfo->hardware_version="2.5"; - wtpinfo->hardware_vendor_id=909090; + wtpinfo->hardware_version="\0\0"; + wtpinfo->hardware_vendor_id=890; - wtpinfo->software_version="2.0"; - wtpinfo->software_vendor_id=11591; + wtpinfo->software_version="2.23(UJA.6)"; + wtpinfo->software_vendor_id=890; wtpinfo->macaddress=conf_macaddress; wtpinfo->macaddress_len=conf_macaddress_len; - wtpinfo->mac_type=1; + wtpinfo->mac_type=0; wtpinfo->session_id = malloc(8); wtpinfo->session_id_len = cw_rand(wtpinfo->session_id,8); - wtpinfo->frame_tunnel_mode=0; + wtpinfo->frame_tunnel_mode=1; return wtpinfo; } diff --git a/src/wtp/wtp_main.c b/src/wtp/wtp_main.c index 9ea9b8fd..7ed374d2 100644 --- a/src/wtp/wtp_main.c +++ b/src/wtp/wtp_main.c @@ -19,7 +19,6 @@ - struct wtpinfo wtpinfo; //int conf_rids[2]; @@ -58,6 +57,8 @@ const char * interfaces[]={ int main() { + gr(); + exit(0); wtp_main(); } @@ -92,15 +93,19 @@ int do_connect(void *priv,void *data) int wtp_main(const char *ad) { + cw_dbg_opt_level = DBG_DTLS | DBG_CW_INFO | DBG_ALL; wtpconf_preinit(); - if (!read_config("wtp.conf")){ + if (!read_config("./wtpconf")){ return 1; } wtpconf_init(); + + + // cw_log_debug_level=6; //conf_debug_level; conf_dtls_psk="Tube"; @@ -110,7 +115,6 @@ int wtp_main(const char *ad) // conf_sslkeypass="7u83"; - cw_dbg_opt_level = DBG_DTLS; #ifdef WITH_DTLS dtls_init(); @@ -123,7 +127,7 @@ int wtp_main(const char *ad) ACIPLIST * aciplist=0; int i; - cw_log_debug0("Entering discovery state"); + cw_dbg(DBG_CW_INFO,"Entering discovery state"); do { for (i=0; inla_type); + printf("ATR Type: %d - %s\n",nla->nla_type,nlt_get_attrname(nla->nla_type)); } @@ -98,6 +99,72 @@ static int nlCallback(struct nl_msg *msg, void *arg) } +void make_if(struct nl_sock * sk) +{ + /* allocate a message */ + struct nl_msg *msg = nlmsg_alloc(); + if (!msg) + return; + + /* init message */ + genlmsg_put(msg, 0, NL_AUTO_SEQ, family_id, 0, 0, + NL80211_CMD_NEW_INTERFACE, 0); + + NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, 0); + NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE,NL80211_IFTYPE_AP); + NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME,"wulan0"); + + int ret = nl_send_auto_complete(sk, msg); + printf("IF Send ret %d\n",ret); + + int nlr = nl_recvmsgs_default(sk); + printf("NLR = %d\n",nlr); + + + + nla_put_failure: + nlmsg_free(msg); + return 1; +} + + +void start_ap(struct nl_sock * sk) +{ + /* allocate a message */ + struct nl_msg *msg = nlmsg_alloc(); + if (!msg) + return; + /* init message */ + genlmsg_put(msg, 0, NL_AUTO_SEQ, family_id, 0, 0, + NL80211_CMD_START_AP, 0); + +printf("Set bi\n"); + + NLA_PUT_U16(msg, NL80211_ATTR_BEACON_INTERVAL, 500); + +printf("Sot biu\n"); + + const char *ssid = "HelloWorld"; + NLA_PUT(msg,NL80211_ATTR_SSID,strlen(ssid),ssid); +// nla_put(msg,NL80211_ATTR_SSID,ssid,strlen(ssid)); +printf("Sot ssid\n"); + + + int ret = nl_send_auto_complete(sk, msg); + printf("AP IF Send ret %d\n",ret); + + int nlr = nl_recvmsgs_default(sk); + printf("AP NLR = %d\n",nlr); + + nla_put_failure: +printf("Bau\n"); + nlmsg_free(msg); + return 1; + + +} + + void gr() { @@ -113,6 +180,19 @@ void gr() nl_socket_modify_cb(sk, NL_CB_VALID, NL_CB_CUSTOM, nlCallback, NULL); + +printf("Mak If\n"); +make_if(sk); +printf("made if\n"); +start_ap(sk); + + +sleep(100); + + +return; + + //allocate a message struct nl_msg *msg = nlmsg_alloc();