Work in progrsss.

FossilOrigin-Name: efb7fb1dc204a4d673f899994eb72005a6cdead3dff43ecab63f1ed4ca8e61ba
This commit is contained in:
7u83@mail.ru 2014-09-14 20:46:14 +00:00
parent 8677fe1a1e
commit 4f7def25f2
16 changed files with 214 additions and 61 deletions

View File

@ -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

View File

@ -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;

View File

@ -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 \

View File

@ -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);

View File

@ -18,29 +18,35 @@
#include "capwap.h"
#include <stdio.h>
/*
* 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 (i<len);
callback(arg, type, msgelems + i + 4, elen);
i += elen + 4;
} while (i < len);
return 1;
}

View File

@ -24,7 +24,7 @@
void cwmsg_addelem_ac_timestamp(struct cwmsg *msg)
{
time_t t = time(NULL);
uint32_t ntpt = t+2398291200;
uint32_t ntpt = t+(uint32_t)2398291200LL;
uint8_t c[4];
*((uint32_t*)c)= htonl(ntpt);
cwmsg_addelem(msg,CWMSGELEM_AC_TIMESTAMP,c,4);

View File

@ -4,13 +4,16 @@
#include "capwap.h"
static inline int wtpdesc_addsubelem(uint8_t * dst,uint8_t type,uint32_t vendorid,uint8_t * str)
static inline int wtpdesc_addsubelem(uint8_t * dst,uint8_t type,uint32_t vendorid,uint8_t * str,int len)
{
// printf("add subelem\n");
int l;
*((uint32_t*)(dst))=htonl(vendorid);
// printf("htonl done\n");
l=strlen((char*)str);
if (len==-1)
l=strlen((char*)str);
else
l=len;
// printf("strlne got %d\n",l);
*((uint32_t*)(dst+4))=htonl((type<<16)|l);
// printf("memcopy str %d\n",l);
@ -29,28 +32,38 @@ void cwmsg_addelem_wtp_descriptor(struct cwmsg * cwmsg, struct wtpinfo * wtpinfo
len=2;
/* number of encryption elemnts */
*(d+len)=1;
// *(d+len)=1;
// len+=1;
*(d+len)=0;
len+=1;
/* encryption elements */
*(d+len)=CWTH_WBID_IEEE80211;
/* *(d+len)=CWTH_WBID_IEEE80211;
uint16_t val = 0;
*((uint16_t*)(d+len+1))=htons(val);
len+=3;
*/
uint8_t hww[2];
hww[0]=0x1c;
hww[1]=0;
/* hardware subelem*/
// len+=wtpdesc_addsubelem(d+len,CWMSGSUBELEM_WTP_DESCRIPTOR_HARDWARE_VERSION,
// wtpinfo->hardware_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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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";

View File

@ -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)

View File

@ -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;

View File

@ -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()

View File

@ -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;
}

View File

@ -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; i<conf_ac_list_len; i++){

View File

@ -1,4 +1,5 @@
#include "wtpdrv.h"
#include "nlt.h"
wpa_printf()
@ -68,7 +69,7 @@ static int nlCallback(struct nl_msg *msg, void *arg)
struct nlattr *nla;
nla_for_each_attr(nla,head,alen,rem){
printf("ATR Type: %d\n",nla->nla_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();