From 5b517514538aa1390d30a00d423a0a12d278f6bf Mon Sep 17 00:00:00 2001
From: "7u83@mail.ru" <7u83@mail.ru@noemail.net>
Date: Fri, 10 Apr 2015 15:16:33 +0000
Subject: [PATCH] Inital ...
FossilOrigin-Name: e6352b425bf6574bdaacc571723f7b54394e235d8b64bbaa504c9b7e529b7535
---
src/capwap/acpriolist.c | 65 +++++++++++++++++++
src/capwap/acpriolist.h | 31 +++++++++
src/capwap/capwap_80211_actions.h | 13 ++++
src/capwap/capwap_80211_actions_wtp.c | 39 +++++++++++
src/capwap/capwap_strings_elem80211.c | 11 ++++
src/capwap/capwap_strings_result.c | 14 ++++
src/capwap/cw_in_ac_descriptor.c | 9 +++
.../cw_in_capwap_control_ipv4_address.c | 43 ++++++++++++
src/capwap/cw_in_check_join_resp.c | 37 +++++++++++
src/capwap/send.c | 44 +++++++++++++
10 files changed, 306 insertions(+)
create mode 100644 src/capwap/acpriolist.c
create mode 100644 src/capwap/acpriolist.h
create mode 100644 src/capwap/capwap_80211_actions.h
create mode 100644 src/capwap/capwap_80211_actions_wtp.c
create mode 100644 src/capwap/capwap_strings_elem80211.c
create mode 100644 src/capwap/capwap_strings_result.c
create mode 100644 src/capwap/cw_in_ac_descriptor.c
create mode 100644 src/capwap/cw_in_capwap_control_ipv4_address.c
create mode 100644 src/capwap/cw_in_check_join_resp.c
create mode 100644 src/capwap/send.c
diff --git a/src/capwap/acpriolist.c b/src/capwap/acpriolist.c
new file mode 100644
index 00000000..6a7934ef
--- /dev/null
+++ b/src/capwap/acpriolist.c
@@ -0,0 +1,65 @@
+/*
+ This file is part of libcapwap.
+
+ libcapwap is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ libcapwap is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Foobar. If not, see .
+
+*/
+
+
+#include
+#include
+
+#include
+#include
+
+#include "acpriolist.h"
+
+
+static int acprio_cmp(const void *x1, const void *x2)
+{
+ cw_acprio_t * p1 = (cw_acprio_t*)x1;
+ cw_acprio_t * p2 = (cw_acprio_t*)x2;
+ return strcmp (p1->name,p2->name);
+
+}
+
+static void acprio_del(void *d)
+{
+ cw_acprio_t *p = (cw_acprio_t*)d;
+ if ( p->name )
+ free (p->name);
+ free(d);
+}
+
+cw_acpriolist_t cw_acpriolist_create()
+{
+ return avltree_create(acprio_cmp, acprio_del);
+}
+
+cw_acprio_t * cw_acpriolist_add(cw_acpriolist_t l, const char *name,int name_len, uint8_t prio)
+{
+
+ cw_acprio_t * s=malloc(sizeof(cw_acprio_t));
+ if (!s)
+ return 0;
+ s->name=strndup(name,name_len);
+ s->prio=prio;
+
+ cw_acpriolist_del(l,s);
+ return avltree_add(l,s);
+
+}
+
+
+
diff --git a/src/capwap/acpriolist.h b/src/capwap/acpriolist.h
new file mode 100644
index 00000000..60a95068
--- /dev/null
+++ b/src/capwap/acpriolist.h
@@ -0,0 +1,31 @@
+#ifndef __ACIPRIORITYLIST_H
+#define __ACIPRIORITYLIST_H
+
+
+#include "avltree.h"
+
+struct cw_acprio{
+ char *name;
+ uint8_t prio;
+};
+
+typedef struct cw_acprio cw_acprio_t;
+typedef struct avltree * cw_acpriolist_t;
+
+extern cw_acpriolist_t cw_acpriolist_create();
+cw_acprio_t * cw_acpriolist_add(cw_acpriolist_t l, const char *name,int name_len, uint8_t prio);
+
+static inline int cw_acpriolist_get(cw_acpriolist_t l, char * acname){
+ cw_acprio_t ps,*pf;
+ ps.name=acname;
+
+ pf=avltree_get(l,&ps);
+ if (!pf)
+ return 256;
+ return pf->prio;
+}
+
+#define cw_acpriolist_del(l,s) avltree_del(l,s)
+#define cw_acpriolist_set(l,n,nl,p) cw_acpriolist_add(l,n,nl,p)
+
+#endif
diff --git a/src/capwap/capwap_80211_actions.h b/src/capwap/capwap_80211_actions.h
new file mode 100644
index 00000000..22bf95c7
--- /dev/null
+++ b/src/capwap/capwap_80211_actions.h
@@ -0,0 +1,13 @@
+
+
+#include "capwap_80211.h"
+#include "capwap_items.h"
+
+#define CW_ACTION_IN_80211_WTP_RADIO_INFORMATION \
+ CW_ELEM80211_WTP_RADIO_INFORMATION, /* Element ID*/ \
+ cw_in_generic, 0, /* start/end callback */ \
+ CW_ITEMTYPE_STR, /* 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
new file mode 100644
index 00000000..e8e45352
--- /dev/null
+++ b/src/capwap/capwap_80211_actions_wtp.c
@@ -0,0 +1,39 @@
+
+
+#include "action.h"
+#include "capwap_80211_actions.h"
+#include "capwap.h"
+
+
+
+
+
+
+cw_action_in_t capwap_80211_actions_wtp_in[] = {
+
+
+ {0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_RESPONSE,
+ CW_ACTION_IN_80211_WTP_RADIO_INFORMATION, 1}
+ ,
+
+
+ {0, 0, 0}
+};
+
+
+int cw_register_actions_capwap_80211_wtp(struct cw_actiondef *def)
+{
+
+ cw_actionlist_in_register_actions(def->in, capwap_80211_actions_wtp_in);
+// cw_actionlist_out_register_actions(def->out, capwap_actions_wtp_out);
+
+ int rc;
+ rc = cw_strheap_register_strings(def->strelem, capwap_strings_elem80211);
+ printf("80211 Registerd %d\n",rc);
+ /*rc += cw_strheap_register_strings(def->strelem, capwap_strings_elem);
+*/
+
+
+ return 1;
+}
+
diff --git a/src/capwap/capwap_strings_elem80211.c b/src/capwap/capwap_strings_elem80211.c
new file mode 100644
index 00000000..dd72f44c
--- /dev/null
+++ b/src/capwap/capwap_strings_elem80211.c
@@ -0,0 +1,11 @@
+#include "capwap_80211.h"
+
+
+struct cw_str capwap_strings_elem80211[] = {
+
+ {CW_ELEM80211_WTP_RADIO_INFORMATION, "802.11 WTP Radio Information"},
+ {CW_STR_STOP,"Unknown"}
+
+
+};
+
diff --git a/src/capwap/capwap_strings_result.c b/src/capwap/capwap_strings_result.c
new file mode 100644
index 00000000..2af810e6
--- /dev/null
+++ b/src/capwap/capwap_strings_result.c
@@ -0,0 +1,14 @@
+#include "capwap.h"
+
+
+struct cw_str capwap_strings_result[] = {
+
+ {CW_RESULT_SUCCESS,"Success"}, /* 0 */
+ {CW_RESULT_MISSING_AC_LIST,"AC List Message Element MUST be Present"}, /* 1 */
+ {CW_RESULT_SUCCESS_NAT,"Success - NAT Detected"}, /* 2 */
+ {CW_RESULT_MISSING_MAND_ELEM,"Missing Mandatory Message Element"}, /* 20 */
+
+ {CW_STR_STOP,"Unknown Result Code"}
+
+};
+
diff --git a/src/capwap/cw_in_ac_descriptor.c b/src/capwap/cw_in_ac_descriptor.c
new file mode 100644
index 00000000..b97e78a7
--- /dev/null
+++ b/src/capwap/cw_in_ac_descriptor.c
@@ -0,0 +1,9 @@
+
+
+
+int cw_in_ac_descriptor(struct conn *conn,struct cw_action_in * a,uint8_t *data,int len)
+{
+
+
+}
+
diff --git a/src/capwap/cw_in_capwap_control_ipv4_address.c b/src/capwap/cw_in_capwap_control_ipv4_address.c
new file mode 100644
index 00000000..5c3667aa
--- /dev/null
+++ b/src/capwap/cw_in_capwap_control_ipv4_address.c
@@ -0,0 +1,43 @@
+
+#include
+
+#include "action.h"
+#include "cw_log.h"
+#include "itemstore.h"
+#include "capwap.h"
+#include "capwap_items.h"
+#include "aciplist.h"
+#include "sock.h"
+
+
+
+int cw_in_capwap_control_ipv4_address(struct conn *conn, struct cw_action_in *a,
+ uint8_t * data, int len)
+{
+ cw_aciplist_t list =
+ cw_itemstore_get_avltree_c(conn->incomming,a->item_id,cw_aciplist_create);
+
+ if (!list) {
+ cw_log(LOG_ERR, "Error: Can't allocate CAWAP IP Adress List");
+ return -1;
+ }
+
+ cw_acip_t * acip;
+ acip = malloc(sizeof(cw_acip_t));
+ if (!acip) {
+ cw_log(LOG_ERR,"Can't allocate memory for acv4ip: %s",strerror(errno));
+ return 1;
+ }
+
+ struct sockaddr_in addr;
+ memcpy(&addr.sin_addr,data,4);
+ addr.sin_family=AF_INET;
+ sock_setport((struct sockaddr*)&addr,CAPWAP_CONTROL_PORT);
+ memcpy(&acip->ip,&addr,sizeof(addr));
+
+ acip->wtp_count = cw_get_word(data+4);
+ cw_aciplist_replace(list,acip);
+
+
+ return 0;
+}
diff --git a/src/capwap/cw_in_check_join_resp.c b/src/capwap/cw_in_check_join_resp.c
new file mode 100644
index 00000000..dc00793c
--- /dev/null
+++ b/src/capwap/cw_in_check_join_resp.c
@@ -0,0 +1,37 @@
+
+#include
+
+#include "capwap.h"
+#include "intavltree.h"
+#include "dbg.h"
+#include "cw_log.h"
+#include "capwap_items.h"
+
+int cw_in_check_join_resp(struct conn *conn, struct cw_action_in *a, uint8_t * data,
+ int len)
+{
+
+ cw_action_in_t * mlist[60];
+
+ /* Check for mandatory elements */
+ int n = cw_check_missing_mand(mlist,conn,a);
+ if (n) {
+ cw_dbg_missing_mand(DBG_ELEM,conn,mlist,n,a);
+ conn->capwap_state=CW_STATE_JOIN;
+ errno=EAGAIN;
+ return -1; //CW_RESULT_MISSING_MAND_ELEM;
+ }
+
+
+
+ cw_item_t * jresult = cw_itemstore_get(conn->incomming, CW_ITEM_RESULT_CODE);
+
+ if ( jresult ) {
+ return jresult->dword;
+ }
+
+ /* set result code to ok and change to configure state */
+// cw_itemstore_set_dword(conn->outgoing,CW_ITEM_RESULT_CODE,0);
+
+ return 0;
+}
diff --git a/src/capwap/send.c b/src/capwap/send.c
new file mode 100644
index 00000000..f66cefa2
--- /dev/null
+++ b/src/capwap/send.c
@@ -0,0 +1,44 @@
+#include
+
+#include "conn.h"
+#include "capwap.h"
+#include "cw_log.h"
+#include "sock.h"
+
+int cw_send_request(struct conn *conn,int msg_id)
+{
+ cw_init_request(conn, msg_id);
+ if ( cw_put_msg(conn, conn->req_buffer) == -1 )
+ return 0;
+ conn_send_msg(conn, conn->req_buffer);
+
+
+
+
+ int i;
+ int rc=-1;
+ for (i=0; imax_retransmit && rc<0; i++){
+ time_t timer = cw_timer_start(conn->retransmit_interval);
+ while (!cw_timer_timeout(timer) && rc<0){
+
+ rc =cw_read_messages(conn);
+ if(rc<0){
+ if (errno!=EAGAIN)
+ break;
+ }
+
+ }
+ if (rc<0){
+ if(errno!=EAGAIN)
+ break;
+
+ }
+
+ }
+
+ if ( rc <0 ) {
+ cw_log(LOG_ERR,"Error reading from %s:%s",sock_addr2str(&conn->addr),strerror(errno));
+ }
+
+ return rc;
+}