diff --git a/src/ac/ac_main.c b/src/ac/ac_main.c index 503a0fbd..e7ef34e0 100644 --- a/src/ac/ac_main.c +++ b/src/ac/ac_main.c @@ -163,6 +163,7 @@ int main (int argc, const char * argv[]) DBGX("Attention! %s","DBGX is ON!"); cw_register_actions_cipwap_ac(&capwap_actions); + cw_register_actions_capwap_80211_ac(&capwap_actions); //cw_register_actions_capwap_80211_ac(&capwap_actions); diff --git a/src/ac/wtpman.c b/src/ac/wtpman.c index ebb9b0ca..b8c4f459 100644 --- a/src/ac/wtpman.c +++ b/src/ac/wtpman.c @@ -114,6 +114,8 @@ conn->strict_capwap=0; conn->strict_hdr=1; conn->capwap_mode=CW_MODE_CIPWAP; +conn->config = mbag_create(); +conn->radios = mbag_create(); time_t timer = cw_timer_start(10); @@ -378,62 +380,11 @@ static int wtpman_send_image_file(struct wtpman *wtpman, struct cwrmsg *cwrmsg) } */ -static void wtpman_run(void *arg) + +static void wtpman_image_data(struct wtpman *wtpman) { - struct wtpman *wtpman = (struct wtpman *) arg; - struct cwrmsg *cwrmsg; // = conn_get_message(wtpman->conn); + struct conn * conn = wtpman->conn; - wtpman->conn->seqnum = 0; - - /* reject connections to our multi- or broadcast sockets */ - if (socklist[wtpman->socklistindex].type != SOCKLIST_UNICAST_SOCKET) { - cw_dbg(DBG_DTLS, "Dropping connection from %s to non-unicast socket.", - CLIENT_IP); - wtpman_remove(wtpman); - return; - } - - - time_t timer = cw_timer_start(wtpman->conn->wait_dtls); - - /* establish dtls session */ - if (!wtpman_establish_dtls(wtpman)) { - wtpman_remove(wtpman); - return; - } - - - /* dtls is established, goto join state */ - if (!wtpman_join(wtpman, timer)) { - wtpman_remove(wtpman); - return; - } - - - - - /* here the WTP has joined, now we assume an image data request - or an configuration status request. Nothing else. - */ - - int rc = 0; - while (!cw_timer_timeout(timer) - && wtpman->conn->capwap_state == CW_STATE_CONFIGURE) { - rc = cw_read_messages(wtpman->conn); - if (rc < 0) { - if (errno != EAGAIN) - break; - } - } - - if (!rc) { - cw_dbg(DBG_INFO, "WTP Problem: %s", cw_strrc(rc)); - - } - - struct conn *conn = wtpman->conn; - - if (conn->capwap_state == CW_STATE_IMAGE_DATA) { /* Image upload */ const char *filename = mbag_get_str(conn->outgoing, CW_ITEM_IMAGE_FILENAME,NULL); @@ -480,6 +431,84 @@ static void wtpman_run(void *arg) wtpman_remove(wtpman); +} + +static void wtpman_run(void *arg) +{ + + + struct wtpman *wtpman = (struct wtpman *) arg; + struct cwrmsg *cwrmsg; // = conn_get_message(wtpman->conn); + + wtpman->conn->seqnum = 0; + struct conn *conn = wtpman->conn; + + + /* reject connections to our multi- or broadcast sockets */ + if (socklist[wtpman->socklistindex].type != SOCKLIST_UNICAST_SOCKET) { + cw_dbg(DBG_DTLS, "Dropping connection from %s to non-unicast socket.", + CLIENT_IP); + wtpman_remove(wtpman); + return; + } + + + time_t timer = cw_timer_start(wtpman->conn->wait_dtls); + + /* establish dtls session */ + if (!wtpman_establish_dtls(wtpman)) { + wtpman_remove(wtpman); + return; + } + + + /* dtls is established, goto join state */ + if (!wtpman_join(wtpman, timer)) { + wtpman_remove(wtpman); + return; + } + + + + + /* here the WTP has joined, now we assume an image data request + or an configuration status request. Nothing else. + */ + + int rc = 0; + while (!cw_timer_timeout(timer) + && wtpman->conn->capwap_state == CW_STATE_CONFIGURE) { + rc = cw_read_messages(wtpman->conn); + if (rc < 0) { + if (errno != EAGAIN) + break; + } + } + + if (!cw_rcok(rc)) { + cw_dbg(DBG_INFO, "WTP Problem: %s", cw_strrc(rc)); + wtpman_remove(wtpman); + return; + + } + + + if (conn->capwap_state == CW_STATE_IMAGE_DATA) { + wtpman_image_data(wtpman); + return; + } + + + conn->capwap_state=CW_STATE_RUN; + + rc = 0; + while (!cw_timer_timeout(timer) + && wtpman->conn->capwap_state == CW_STATE_RUN) { + rc = cw_read_messages(wtpman->conn); + if (rc < 0) { + if (errno != EAGAIN) + break; + } } diff --git a/src/capwap/Makefile b/src/capwap/Makefile index 37b6cfbb..2bd5b5d5 100644 --- a/src/capwap/Makefile +++ b/src/capwap/Makefile @@ -322,6 +322,7 @@ CWACTION=action.o \ capwap_actions_ac.o \ capwap_actions_wtp.o \ capwap_80211_actions_wtp.o \ + capwap_80211_actions_ac.o \ cw_in_generic.o \ cw_in_wtp_descriptor.o \ cw_out_wtp_board_data.o \ diff --git a/src/capwap/action.h b/src/capwap/action.h index 4eefa2dd..e5ddd934 100644 --- a/src/capwap/action.h +++ b/src/capwap/action.h @@ -45,12 +45,13 @@ struct cw_action_in{ uint16_t elem_id; int (*start)(struct conn *conn,struct cw_action_in *a,uint8_t*data,int len,struct sockaddr *from); int (*end)(struct conn *conn,struct cw_action_in *a,uint8_t*elem,int len,struct sockaddr *from); -// uint8_t itemtype; const struct mbag_typedef * itemtype; uint16_t item_id; uint16_t min_len; uint16_t max_len; uint8_t mand; +// mbag_t (*target)(struct conn *conn,struct cw_action_in *a); + }; typedef int(*cw_action_fun_t)(struct conn *,struct cw_action_in *,uint8_t*,int ,struct sockaddr *); @@ -92,7 +93,7 @@ struct cw_action_out{ struct mbag_typedef * itemtype; void *defval; - int xopt; +// int xopt; }; diff --git a/src/capwap/capwap.h b/src/capwap/capwap.h index cff49b6c..bd98ba8e 100644 --- a/src/capwap/capwap.h +++ b/src/capwap/capwap.h @@ -1114,5 +1114,7 @@ int cw_out_radio_administrative_states(struct conn *conn, struct cw_action_out * int cw_in_radio_administrative_state(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len, struct sockaddr *from); +int cw_in_radio_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len, + struct sockaddr *from); #endif diff --git a/src/capwap/capwap_80211.h b/src/capwap/capwap_80211.h index 329089d2..6aed0ff1 100644 --- a/src/capwap/capwap_80211.h +++ b/src/capwap/capwap_80211.h @@ -91,6 +91,8 @@ int cw_out_radio_infos(struct conn *conn, struct cw_action_out *a, uint8_t * dst extern int cw_register_actions_capwap_80211_wtp(struct cw_actiondef *def); extern struct cw_str capwap_strings_elem80211[]; +extern int cw_register_actions_capwap_80211_ac(struct cw_actiondef *def); + diff --git a/src/capwap/capwap_80211_actions.h b/src/capwap/capwap_80211_actions.h index ed41f82d..1c5af01f 100644 --- a/src/capwap/capwap_80211_actions.h +++ b/src/capwap/capwap_80211_actions.h @@ -5,8 +5,8 @@ #define CW_ACTION_IN_80211_WTP_RADIO_INFORMATION \ CW_ELEM80211_WTP_RADIO_INFORMATION, /* Element ID*/ \ - cw_in_generic, 0, /* start/end callback */ \ - MBAG_STR, /* Type of element */ \ + cw_in_radio_generic, 0, /* start/end callback */ \ + MBAG_DWORD, /* Type of element */ \ CW_ITEM_LOCATION_DATA, /* ID to use store */ \ 5, 5 /* min/max length */ diff --git a/src/capwap/capwap_80211_actions_wtp.c b/src/capwap/capwap_80211_actions_wtp.c index 3d73fcab..7d8220a9 100644 --- a/src/capwap/capwap_80211_actions_wtp.c +++ b/src/capwap/capwap_80211_actions_wtp.c @@ -28,7 +28,21 @@ cw_action_in_t capwap_80211_actions_wtp_in[] = { cw_action_out_t capwap_80211_actions_wtp_out[]={ - /* Session ID */ + + /* -------------------------------------------------------- + * Discovery Resquest + */ + + /* 802.11 Radio Information */ + {CW_MSG_DISCOVERY_REQUEST, CW_ELEM80211_WTP_RADIO_INFORMATION, 0, + CW_ELEM80211_WTP_RADIO_INFORMATION, NULL,cw_out_radio_infos, NULL,1} + , + + /* -------------------------------------------------------- + * Join Resquest + */ + + /* 802.11 Radio Information */ {CW_MSG_JOIN_REQUEST, CW_ELEM80211_WTP_RADIO_INFORMATION, 0, CW_ELEM80211_WTP_RADIO_INFORMATION, NULL,cw_out_radio_infos, NULL,1} diff --git a/src/capwap/capwap_action_helpers.c b/src/capwap/capwap_action_helpers.c index 6a03acda..cda9203b 100644 --- a/src/capwap/capwap_action_helpers.c +++ b/src/capwap/capwap_action_helpers.c @@ -4,7 +4,6 @@ - int cw_in_set_state_none(struct conn *conn,struct cw_action_in * a,uint8_t *data,int len) { conn->capwap_state=CW_STATE_NONE; diff --git a/src/capwap/capwap_actions_ac.c b/src/capwap/capwap_actions_ac.c index 1f3df3a3..eb67b998 100644 --- a/src/capwap/capwap_actions_ac.c +++ b/src/capwap/capwap_actions_ac.c @@ -233,9 +233,9 @@ cw_action_out_t capwap_actions_ac_out[] = { , /* Result Code */ - {CW_MSG_CONFIGURATION_STATUS_RESPONSE, CW_ITEM_RESULT_CODE, 0, - CW_ELEM_RESULT_CODE, NULL,cw_out_generic, cw_out_get_outgoing, 1} - , +// {CW_MSG_CONFIGURATION_STATUS_RESPONSE, CW_ITEM_RESULT_CODE, 0, +// CW_ELEM_RESULT_CODE, NULL,cw_out_generic, cw_out_get_outgoing, 1} +// , diff --git a/src/capwap/conn.h b/src/capwap/conn.h index cbbe68a2..104d2b3e 100644 --- a/src/capwap/conn.h +++ b/src/capwap/conn.h @@ -56,6 +56,7 @@ struct conn { mbag_t local; mbag_t radios; + uint8_t radio_create; mbag_t config; @@ -256,6 +257,8 @@ extern int cw_read_messages(struct conn *conn); extern int conn_recvfrom_packet(struct conn *conn, uint8_t * buf, int len, struct sockaddr_storage *from); +int conn_send_msg(struct conn * conn, uint8_t *rawmsg); +int cw_read_from(struct conn * conn); diff --git a/src/capwap/conn_process_packet.c b/src/capwap/conn_process_packet.c index 4cbb111d..bda5f521 100644 --- a/src/capwap/conn_process_packet.c +++ b/src/capwap/conn_process_packet.c @@ -247,7 +247,7 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,struct if (!af) { cw_dbg(DBG_ELEM_ERR, "Element %d (%s) not allowed in msg of type %d (%s), ignoring.", - as.elem_id, cw_strelem(as.elem_id), as.msg_id, + as.elem_id, cw_strelemp(conn->actions,as.elem_id), as.msg_id, cw_strmsg(as.msg_id)); continue; } diff --git a/src/capwap/cw_in_generic.c b/src/capwap/cw_in_generic.c index e02fd178..2acc2aab 100644 --- a/src/capwap/cw_in_generic.c +++ b/src/capwap/cw_in_generic.c @@ -6,9 +6,8 @@ #include "capwap.h" - -int cw_in_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len, - struct sockaddr *from) +int static check_len(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len, + struct sockaddr *from) { if (len < a->min_len) { cw_dbg(DBG_ELEM_ERR, @@ -24,8 +23,13 @@ int cw_in_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data, int return 0; } + return 1; +} - mbag_t itemstore = conn->incomming; + +int static do_save(mbag_t itemstore, struct conn *conn, struct cw_action_in *a, + uint8_t * data, int len, struct sockaddr *from) +{ if (a->itemtype == MBAG_BYTE) { mbag_set_byte(itemstore, a->item_id, *data); @@ -60,7 +64,7 @@ int cw_in_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data, int */ if (a->itemtype == MBAG_VENDORSTR) { mbag_set_vendorstr(itemstore, a->item_id, - cw_get_dword(data), data + 4, len - 4); + cw_get_dword(data), data + 4, len - 4); return 1; } @@ -70,6 +74,49 @@ int cw_in_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data, int return 0; +} + +int cw_in_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len, + struct sockaddr *from) +{ + + if (!check_len(conn, a, data, len, from)) + return 0; + + + mbag_t itemstore; +/// if (!a->target) + itemstore = conn->incomming; +// else +// itemstore = a->target(conn, a); + + + return do_save(itemstore, conn, a, data, len, from); + + + +} + + +int cw_in_radio_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data, + int len, struct sockaddr *from) +{ + if (!check_len(conn, a, data, len, from)) + return 0; + + int rid = cw_get_byte(data); + mbag_t radio = mbag_get_mbag(conn->radios, rid, NULL); + if (!radio) { + if (a->vendor_id != 0 + || ( (a->vendor_id == 0) && (a->msg_id != CW_MSG_DISCOVERY_REQUEST + && a->msg_id != CW_MSG_JOIN_REQUEST) )) { + cw_dbg(DBG_ELEM_ERR, "Radio not found %d", rid); + return 0; + } + mbag_set_mbag(conn->radios,rid,mbag_create()); + } + + return 1; } diff --git a/src/wtp/Makefile b/src/wtp/Makefile index 7a42a1d6..8491e668 100644 --- a/src/wtp/Makefile +++ b/src/wtp/Makefile @@ -20,8 +20,8 @@ ifndef ARCH endif -#CFLAGS += -O0 -Wall -g -CFLAGS += -Os -Wall +CFLAGS += -O0 -Werror -g +#CFLAGS += -Os -Wall LDFLAGS += -L../contrib/jsmn -L../../src/capwap/$(ARCH) diff --git a/src/wtp/cfg.c b/src/wtp/cfg.c index fb85485f..9e822a85 100644 --- a/src/wtp/cfg.c +++ b/src/wtp/cfg.c @@ -193,7 +193,7 @@ int cfg_json_get_ac_ip_list(struct mbag_itemdef *idef, char *js, jsmntok_t * t, } - + return 0; } @@ -430,7 +430,9 @@ struct mbag_itemdef board_data_cfg[] = { struct mbag_itemdef radio_cfg[] = { - {CW_RADIO_ADMIN_STATE, "admin_state", cfg_json_get_byte, cfg_json_put_byte} + {CW_RADIO_ADMIN_STATE, "admin_state", cfg_json_get_byte, cfg_json_put_byte}, + {CW_RADIO_TYPE, "radio_type", cfg_json_get_dword, cfg_json_put_dword}, + {0,0,0} }; @@ -699,7 +701,7 @@ int cfg_json_save() ////printf("DST:%s\n",dst); //exit(0); cw_save_file("cfg.json", dst, n); - + return 1; } struct mbag_itemdef *get_cfg(struct mbag_itemdef *cfg, const char *key) diff --git a/src/wtp/cfg.json b/src/wtp/cfg.json index 57fc3eb1..ee100edc 100644 --- a/src/wtp/cfg.json +++ b/src/wtp/cfg.json @@ -27,10 +27,12 @@ "wtp_board_data_options":".x00010000", "radios":{ "0":{ - "admin_state":"2" + "admin_state":"2", + "radio_type":"0" }, "1":{ - "admin_state":"2" + "admin_state":"2", + "radio_type":"0" } }, "bssid":"" diff --git a/src/wtp/changestate.c b/src/wtp/changestate.c index 753b4877..9ce76b04 100644 --- a/src/wtp/changestate.c +++ b/src/wtp/changestate.c @@ -12,8 +12,9 @@ int changestate() if ( !cw_rcok(rc) ) { cw_strresult(rc); + return 0; } - + return 1; } diff --git a/src/wtp/configure.c b/src/wtp/configure.c index fc04d2bc..d91dfbee 100644 --- a/src/wtp/configure.c +++ b/src/wtp/configure.c @@ -27,6 +27,6 @@ int configure() printf("Got change resp %p\n",cwrmsg); */ - + return 0; } diff --git a/src/wtp/discovery.c b/src/wtp/discovery.c index 200d2445..bdab2f0d 100644 --- a/src/wtp/discovery.c +++ b/src/wtp/discovery.c @@ -161,7 +161,7 @@ static int run_discovery(struct conn *conn) mbag_set_avltree(conn->local,CW_ITEM_CAPWAP_CONTROL_IP_ADDRESS_LIST,list); - return 0; + return 1; } @@ -228,5 +228,5 @@ int discovery() struct conn *conn = get_conn(); cw_run_discovery(conn, "255.255.255.255"); conn->capwap_state=CW_STATE_JOIN; - return 0; + return 1; } diff --git a/src/wtp/dot11.c b/src/wtp/dot11.c index 7cd2c724..07ead4fc 100644 --- a/src/wtp/dot11.c +++ b/src/wtp/dot11.c @@ -20,7 +20,7 @@ #include "dot11.h" - +/* uint8_t * mk_frame( uint8_t *b) { @@ -70,7 +70,7 @@ int dot11_get_beacon_head(struct apdata *ap, uint8_t *dst, int *len) printf("t1\n"); - /* set-up head */ + // set-up head struct dot11_mgmt_head head; memset (&head,0,sizeof(head)); @@ -79,11 +79,11 @@ printf("t2\n"); head.frame_control = htole16 (DOT11_FTYPE_MGMT | DOT11_STYPE_BEACON); head.duration = htole16(0); - /* destination address */ + // destination address memset(head.da, 0xff, sizeof(head.da)); printf("t3\n"); - /* source address */ + // source address memcpy (head.sa , ap->mac,6); memcpy (head.bssid , ap->mac,6); b += add_bytes(b,&head,sizeof(head)); @@ -140,8 +140,9 @@ add_supp_rates_ie(uint8_t *buf,uint32_t * rates, int num_rates) return b-buf; } +*/ - +/* dot11_get_beacon_data(struct apdata *ap,struct beacon_data *bd) { bd->head = malloc(256); @@ -165,5 +166,5 @@ printf ("done\n"); return 0; } - +*/ diff --git a/src/wtp/dot11.h b/src/wtp/dot11.h index a7a7457f..65a14ca1 100644 --- a/src/wtp/dot11.h +++ b/src/wtp/dot11.h @@ -319,7 +319,7 @@ struct beacon_data{ }; -dot11_get_beacon_data(struct apdata *ap,struct beacon_data *bd); +int dot11_get_beacon_data(struct apdata *ap,struct beacon_data *bd); diff --git a/src/wtp/nlt.c b/src/wtp/nlt.c index 3233bfe0..430cb0b6 100644 --- a/src/wtp/nlt.c +++ b/src/wtp/nlt.c @@ -10,7 +10,7 @@ #include "nlt.h" - +/* static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, void *arg) { @@ -362,3 +362,6 @@ int nlt_get_wiphy_list(struct nl_sock *sk) } } + + +*/ diff --git a/src/wtp/run.c b/src/wtp/run.c index fcd2452b..f87a7480 100644 --- a/src/wtp/run.c +++ b/src/wtp/run.c @@ -80,7 +80,7 @@ int run() // cw_strresult(rc); // } - + return 0; } diff --git a/src/wtp/wtp.h b/src/wtp/wtp.h index 27e70225..8be7032b 100644 --- a/src/wtp/wtp.h +++ b/src/wtp/wtp.h @@ -10,6 +10,10 @@ extern int join(); extern int discovery(); extern int image_update(); extern int setup_conf(struct conn * conn); +extern int configure(); +extern int run(); +extern int changestate(); + struct conn * get_conn(); diff --git a/src/wtp/wtp_conf.c b/src/wtp/wtp_conf.c index de509453..40264f69 100644 --- a/src/wtp/wtp_conf.c +++ b/src/wtp/wtp_conf.c @@ -220,6 +220,7 @@ int wtpconf_preinit() conf_board_id = bstr_create_from_cfgstr(CONF_DEFAULT_BOARD_ID); conf_board_revision = bstr_create_from_cfgstr(CONF_DEFAULT_BOARD_REVISION); + return 0; } int wtpconf_init() diff --git a/src/wtp/wtp_main.c b/src/wtp/wtp_main.c index c82bb154..3b1a8210 100644 --- a/src/wtp/wtp_main.c +++ b/src/wtp/wtp_main.c @@ -21,7 +21,7 @@ #include "jsmn.h" - +#include "cfg.h" @@ -168,9 +168,12 @@ cw_set_msg_end_callback(conn,CW_STATE_CONFIGURE,CW_MSG_CONFIGURATION_STATUS_RESP - the_conn->strict_capwap=0; - discovery(); - join(); +the_conn->strict_capwap=1; + if (!discovery()) + return -1; + if (!join()) + return -1; + mavl_destroy(conn->incomming); conn->incomming=conn->config; configure(); diff --git a/src/wtp/wtpdrv.c b/src/wtp/wtpdrv.c index 9afcdee8..c3538c5d 100644 --- a/src/wtp/wtpdrv.c +++ b/src/wtp/wtpdrv.c @@ -4,8 +4,8 @@ -#include "wtpdrv.h" -#include "nlt.h" +//#include "wtpdrv.h" +//#include "nlt.h" #include "capwap/log.h" @@ -14,6 +14,7 @@ #include "capwap/capwap_80211.h" #include "capwap/dbg.h" +/* int wpa_printf() { } @@ -32,6 +33,7 @@ int wpa_hexdump() #include #include "nl80211.h" +*/ /* typedef uint16_t u16; @@ -46,7 +48,7 @@ typedef signed char s8; typedef __le16 le16 */ - +/* #include #include @@ -66,8 +68,10 @@ struct wiphydata { const char * name; }; +*/ +/* static struct wiphydata * wiphydata[31]; static int ack_handler(struct nl_msg *msg, void *arg) @@ -98,1197 +102,5 @@ printf("Err: %d\n",*ret); } - - -int nlt_send_and_recvmsg(struct nl_sock *sk, struct nl_msg *msg) -{ - volatile int err=NLE_NOMEM; - - - struct nl_cb * cb = nl_socket_get_cb(sk); - if (!cb) - goto errX; - - cb = nl_cb_clone(cb); - if (!cb) - goto errX; - - - err = nl_send_auto_complete(sk, msg); - if (err < 0) - goto errX; - - - nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); - nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); - nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); - - err=1; - - while (err==1) { - int rc = nl_recvmsgs(sk, cb); - printf("Weil rc %d\n",rc); - if (rc < 0) { - cw_log(LOG_ERR,"nl_recvmsg failed: %d %d",rc,nl_geterror(rc)); - } - } - - -errX: - printf ("Returning Err XXX %d\n",err); - - return err; -} - - - -int interface_up(const char * ifname) -{ - int sockfd; - struct ifreq ifr; - - sockfd = socket(AF_INET, SOCK_DGRAM, 0); - if (sockfd < 0) - return 0; - - memset(&ifr, 0, sizeof ifr); - - strncpy(ifr.ifr_name, ifname, IFNAMSIZ); - - ifr.ifr_flags |= IFF_UP; - ioctl(sockfd, SIOCSIFFLAGS, &ifr); -} - - - - - -int get_ifhwaddr(const char *ifname, uint8_t *addr) -{ - struct ifreq ifr; - - int sockfd = socket(AF_INET, SOCK_DGRAM, 0); - if (sockfd < 0) - return 0; - - - memset(&ifr, 0, sizeof(ifr)); - strcpy(ifr.ifr_name, ifname); //, IFNAMSIZ); - if (ioctl(sockfd, SIOCGIFHWADDR, &ifr)) { - return -1; - } - - if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) { - return -1; - } - memcpy(addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN); - return 0; -} - - - - -struct hostapd_freq_params { - int mode; - int freq; - int channel; - /* for HT */ - int ht_enabled; - int sec_channel_offset; /* 0 = HT40 disabled, -1 = HT40 enabled, - * secondary channel below primary, 1 = HT40 - * enabled, secondary channel above primary */ - - /* for VHT */ - int vht_enabled; - - /* valid for both HT and VHT, center_freq2 is non-zero - * only for bandwidth 80 and an 80+80 channel */ - int center_freq1, center_freq2; - int bandwidth; -}; - - - - - - - - -static int nlt_put_freq_params(struct nl_msg *msg, - struct hostapd_freq_params *freq) -{ - NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq); - if (freq->vht_enabled) { - switch (freq->bandwidth) { - case 20: - NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, - NL80211_CHAN_WIDTH_20); - break; - case 40: - NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, - NL80211_CHAN_WIDTH_40); - break; - case 80: - if (freq->center_freq2) - NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, - NL80211_CHAN_WIDTH_80P80); - else - NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, - NL80211_CHAN_WIDTH_80); - break; - case 160: - NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH, - NL80211_CHAN_WIDTH_160); - break; - default: - return -EINVAL; - } - NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ1, freq->center_freq1); - if (freq->center_freq2) - NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ2, - freq->center_freq2); - } else if (freq->ht_enabled) { - switch (freq->sec_channel_offset) { - case -1: - NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, - NL80211_CHAN_HT40MINUS); - break; - case 1: - NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, - NL80211_CHAN_HT40PLUS); - break; - default: - NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, - NL80211_CHAN_HT20); - break; - } - } - return 0; - -nla_put_failure: - return -ENOBUFS; -} - - -/* -static int set_channel( struct hostapd_freq_params *freq, int set_chan) -{ - struct nl_msg *msg; - - msg = nlmsg_alloc(); - if (!msg) - return -1; - - nl80211_cmd(drv, msg, 0, set_chan ? NL80211_CMD_SET_CHANNEL : - NL80211_CMD_SET_WIPHY); - - genlmsg_put(msg, 0, NL_AUTO_SEQ, family_id, 0, 0, - NL80211_CMD_SET_WIPHY, 0); - - - NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); - if (nl80211_put_freq_params(msg, freq) < 0) - goto nla_put_failure; - - ret = send_and_recv_msgs(drv, msg, NULL, NULL); - msg = NULL; - if (ret == 0) { - bss->freq = freq->freq; - return 0; - } -nla_put_failure: - nlmsg_free(msg); - return -1; -} */ - - - - - - - - - -static int family_id; - -static int add_interface_data(struct nlattr* msgattribs[NL80211_ATTR_MAX+1]) -{ - printf("Add interface_data\n"); - printf("--------------------------------------------------------------------------\n"); - int i; - for (i=0; iname){ - w->name = strdup( nla_get_string(msgattribs[NL80211_ATTR_WIPHY_NAME])); - } - - - - printf ("Got data for wiphy index %d\n",index); - return 0; - - - if (msgattribs[NL80211_ATTR_WIPHY_BANDS]){ - printf("Yea band\n"); -// struct nlattr *nla=msgattribs[NL80211_ATTR_WIPHY_BANDS]; -// struct nla_attr * cnla; -// int rem_nla; - - /* TODO parse bands */ -/* nla_for_each_nested(cnla, nla, rem_nla) { - int band = nla_get_u16(cnla); - printf("Band found: %d\n",band); - } -*/ - - - - - - } - - if (msgattribs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]){ - int tr = nla_get_u32( msgattribs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD] ); - printf("Frag threshold: %d\n",tr); - - } - - if (msgattribs[NL80211_ATTR_SUPPORTED_IFTYPES]){ - printf("IFTYPES -.\n"); - -// struct nlattr *nla=msgattribs[NL80211_ATTR_SUPPORTED_IFTYPES]; -// struct nla_attr * cnla; -// int rem_nla; - - /* TODO parse bands */ -/* nla_for_each_nested(cnla, nla, rem_nla) { - int t = nla_type(cnla); - printf("IFTYPE: %d\n",t); - } -*/ - - } - - - - int i; - for (i=0; icmd; - cw_dbg(DBG_DRV,"NL Callback, cmd=%d - %s",cmd,nlt_get_cmdname(cmd)); - - switch(cmd){ - case NL80211_CMD_NEW_WIPHY: - add_wiphy_data(msgattribs); - break; - case NL80211_CMD_NEW_INTERFACE: - add_interface_data(msgattribs); - - default: - printf("Default\n"); - - - - } - - return NL_OK; - -} - - - - - - - - - - - - - - -static int xnlCallback(struct nl_msg *msg, void *arg) -{ - - printf("NLCallback\n"); - - struct nlmsghdr *ret_hdr = nlmsg_hdr(msg); - struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; - -// printf("AMAX = %d\n",NL80211_ATTR_MAX); -// printf("WIPI = %d\n",NL80211_ATTR_WIPHY_NAME); - - int ii; - for (ii = 0; ii < NL80211_ATTR_MAX; ii++) { - tb_msg[ii] = 0; - } - if (!tb_msg[NL80211_ATTR_WIPHY_NAME]) { -// printf("still no mame\n"); - } else { -// printf("a name her????\n"); - } - - - - if (ret_hdr->nlmsg_type != family_id) { - printf("Wrong family\n"); - // what is this?? - return NL_STOP; - } - - struct genlmsghdr *gnlh = - (struct genlmsghdr *) nlmsg_data(ret_hdr); - - int cmd = gnlh->cmd; - - printf("CMD: %d - %s\n", cmd, nlt_get_cmdname(cmd)); - - struct nlattr *head = genlmsg_attrdata(gnlh, 0); - int alen = genlmsg_attrlen(gnlh, 0); - int rem; - - struct nlattr *nla; - nla_for_each_attr(nla, head, alen, rem) { - - switch (nla->nla_type) { - case NL80211_ATTR_IFINDEX: - { - int idx = nla_get_u32(nla); - printf("IF IFXC = %d\n", idx); - break; - } - case NL80211_ATTR_IFNAME: - { - const char * nam = nla_get_string(nla); - printf("IF iNAM = %s\n", nam); - break; - } - } - - - - - - //printf("ATR Type: %d - %s\n",nla->nla_type,nlt_get_attrname(nla->nla_type)); - - if (nla->nla_type == NL80211_ATTR_SUPPORTED_COMMANDS) { - - printf("Supported commands found, len = %d\n", - nla->nla_len); - struct nlattr *nl_cmd; - int rem_cmd; - nla_for_each_nested(nl_cmd, nla, rem_cmd) { - int cmd = nla_get_u32(nl_cmd); - const char *n = nlt_get_cmdname(cmd); - printf("Supported command: %d, %s\n", cmd, - n); - } - - - - - } - - - - } - - -/* - nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), - genlmsg_attrlen(gnlh, 0), NULL); - - - if (tb_msg[NL80211_ATTR_WIPHY_NAME]) { -// int type = nla_get_u32(tb_msg[NL80211_ATTR_IFTYPE]); - -// printf("Type: %d\n", type); - struct nlattr * a = tb_msg[NL80211_ATTR_WIPHY_NAME]; - - printf ("ATTR %p\n",a); - - - char * str = nla_get_string(a); - - printf("Has namei %s\n",str); - } -*/ - return NL_OK; - -} - - -struct ifindex_cb_data{ - const char * ifname; - int index; - int type; -}; - -static int get_ifindex_cb(struct nl_msg *msg, void *arg) -{ - struct ifindex_cb_data * cb_data = (struct ifindex_cb_data *)arg; - - printf("Yeaaaaaaaaaa! The ifindex callback is here\n"); - struct nlmsghdr *msghdr = nlmsg_hdr(msg); - struct nlattr *msgattribs[NL80211_ATTR_MAX + 1]; - - struct genlmsghdr *ghdr = - (struct genlmsghdr *) nlmsg_data(msghdr); - - int rc; - rc = nla_parse(msgattribs, NL80211_ATTR_MAX, genlmsg_attrdata(ghdr, 0), - genlmsg_attrlen(ghdr, 0), NULL); - - if (rc<0){ - cw_dbg(DBG_DRV_ERR,"nla_parse failed: %d %d",rc,nl_geterror(rc)); - return NL_SKIP; - } - - int cmd = ghdr->cmd; - cw_dbg(DBG_DRV,"NL Callback, cmd=%d - %s",cmd,nlt_get_cmdname(cmd)); - - if (cmd == NL80211_CMD_NEW_INTERFACE){ - if (msgattribs[NL80211_ATTR_IFNAME]){ - - printf ("IFNAME = %s\n",nla_get_string(msgattribs[NL80211_ATTR_IFNAME])); - - cb_data->index = nla_get_u32(msgattribs[NL80211_ATTR_IFINDEX]); - cb_data->type = nla_get_u32(msgattribs[NL80211_ATTR_IFTYPE]); - - - } - - } - -} - -int get_ifindex(const char *ifname) -{ - int index = -1; - struct nl_msg *msg = nlmsg_alloc(); - if (!msg) - return -1; - - int flags = NLM_F_DUMP; - - - genlmsg_put(msg, 0, NL_AUTO_SEQ, family_id, 0, flags, - NL80211_CMD_GET_INTERFACE, 0); - - NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, 0); - int rc = nl_send_auto_complete(sk, msg); - - - printf ("AC C %d\n",rc); - - - struct ifindex_cb_data cb_data; - - cb_data.ifname=ifname; - cb_data.index=-1; - - - int err; - - struct nl_bc * nl_cb = nl_cb_alloc(NL_CB_CUSTOM); - nl_cb_set(nl_cb,NL_CB_VALID,NL_CB_CUSTOM, get_ifindex_cb,&cb_data); - nl_cb_err(nl_cb,NL_CB_CUSTOM, error_handler, &err); - - - int nlr; - do { - nl_recvmsgs(sk,nl_cb); - }while(cb_data.index==-1); - - //int nlr = nl_recvmsgs_default(sk); - cw_log(LOG_ERR,"iGet if index: Make if %d - %s",nlr,nl_geterror(nlr)); - - - if (cb_data.index!=-1){ - index=cb_data.index; - } - - printf("The mode %d\n",cb_data.type); - -printf ("TTTTTTTTTTTTTTTHe index: %d\n",index); - nla_put_failure: - nlmsg_free(msg); - return index; - -} - -int del_if(const char * name) -{ - int index = get_ifindex(name); - if (index==-1) - return -1; - - struct nl_msg *msg = nlmsg_alloc(); - if (!msg) - return 0; - - genlmsg_put(msg, 0, NL_AUTO_SEQ, family_id, 0, 0, - NL80211_CMD_DEL_INTERFACE, 0); - - NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, index); - - int nlr = nl_send_sync(sk, msg); - if (nlr){ - cw_log(LOG_ERR,"Error deleting interface %s(%d): %d - %s",name,index,nlr,nl_geterror(nlr)); - return nlr; - } - - return 0; - - - nla_put_failure: - nlmsg_free(msg); - return 1; - -} - - -int create_interface(const char * ifname) -{ - struct nl_msg *msg = nlmsg_alloc(); - if (!msg) - return 0; - - genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, family_id, 0, NLM_F_REQUEST | NLM_F_REPLACE, - 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, ifname); - - int nlr = nl_send_sync(sk,msg); - if (nlr){ - cw_log(LOG_ERR,"Fatal: Make if %d - %s",nlr,nl_geterror(nlr)); - } - - sleep(1); - return 0; - - nla_put_failure: - nlmsg_free(msg); - return 1; -} - - -int start_ap(struct nl_sock *sk) -{ - - - - - - - - - /* allocate a message */ - struct nl_msg *msg = nlmsg_alloc(); - if (!msg) - return 0; - - - - /* init message */ - genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, family_id, 0, NLM_F_REQUEST, - NL80211_CMD_START_AP, 0); -// genlmsg_put(msg, 0, NL_AUTO_SEQ, family_id, 0, 0, -// NL80211_CMD_SET_BEACON, 0); - - - -/* - struct dot11_mgmt *head = NULL; - - head = malloc(256); - uint8_t * tail; - - head->frame_control = htole16 (DOT11_FTYPE_MGMT | DOT11_STYPE_BEACON) ; - - head->duration = htole16(0); - - memset(head->da, 0xff, sizeof(head->da)); - memcpy (head->sa , rd.mac,6); - memcpy (head->bssid , rd.mac,6); - - head->u.beacon.beacon_int=htole16(100); - head->u.beacon.capab_info=0; - memset (head->u.beacon.timestamp,0,8); - - - - int hs = sizeof(struct dot11_mgmt_head); - printf("HEAD SIZE: %d\n",hs); - - hs += sizeof( head->u.beacon); - printf("Head size is now %d\n",hs); -*/ - - struct beacon_data bd; - - const char *ssid = "xTatort88"; - - struct apdata * ap = &rd; - ap->ssid=ssid; - -printf("Get Beacon Data \n"); - dot11_get_beacon_data(ap,&bd); -printf("Got Beaqcon Fata\n"); -printf("headlen %d\n",bd.head_len); - - NLA_PUT(msg, NL80211_ATTR_BEACON_HEAD, bd.head_len, bd.head); - - -printf ("Coter\n"); - { - for (int i=0; irid=rid; - //uint8_t rm[8]="12345600"; -// uint8_t rm[8]={0x00,0x19,0xdb,0xe0,0x93,0x27}; -// uint8_t rm[8]={0x00,0x3a,0x99,0x02,0xfa,0xc0}; - uint8_t rm[8]={0x00,0x4a,0x99,0x02,0xfa,0xc0}; -// uint8_t rm[8]={0x68,0x67,0x65,0x64,0x63,0x62}; - - radioinfo->rmac = bstr_create(rm,6); - - - radioinfo->type|=rid+1; //CW_80211_RADIO_TYPE_B; //CWRADIO_TYPE_N; - radioinfo->regDomain=1; - - strcpy(radioinfo->country_str,"DE "); - strcpy(radioinfo->country_str2,"DE "); - - -/* - struct wpa_driver_ops * drv = wpa_drivers[0]; - - struct hostapd_hw_modes * hwm; - uint16_t nummodes; - uint16_t fl; - - radioinfo->rid=rid; - - hwm = drv->get_hw_feature_data(drv_priv[rid-1],&nummodes,&fl); - - int i; - for (i=0; itype|=CWRADIO_TYPE_B; - printf("Mode B\n"); - break; - case HOSTAPD_MODE_IEEE80211G: - radioinfo->type|=CWRADIO_TYPE_G; - printf("Mode G\n"); - break; - case HOSTAPD_MODE_IEEE80211A: - radioinfo->type|=CWRADIO_TYPE_A; - printf("Mode A\n"); - break; - case NUM_HOSTAPD_MODES: - printf("NIMA AP MODES\n"); - break; - - } - if (hwm[i].ht_capab) - radioinfo->type|=CWRADIO_TYPE_N; - - printf ("ht_capab: %d\n",hwm[i].ht_capab); - printf ("flags: %d\n",hwm[i].flags); - printf("\n"); - } - - - -////////////// printf("hem %p\n",hwm); - -// drv - -*/ - -} - -