freecwmp
[Top] [All Lists]

[PATCH] freecwmp: make cwmp version configurable

To: freecwmp@linux-mips.org
Subject: [PATCH] freecwmp: make cwmp version configurable
From: Kaspar Schleiser <kaspar@schleiser.de>
Date: Wed, 22 Feb 2012 14:23:45 +0100
Cc: Kaspar Schleiser <kaspar@schleiser.de>
Original-recipient: rfc822;freecwmp@linux-mips.org
Sender: freecwmp-bounce@linux-mips.org
Hey everybody,

currently, freecwmp hard-codes cwmp protocol version 1.2.

here's a patch that adds a configuration option for the server's cwmp version.
It also changes cwmp-urn and cwmp:ID handling according to the version 
specified by the user.

Currently "1.0" and "1.2" are being recognized.

Default is 1.2, so for upgraders nothing changes, missing option is no problem. 
Users of 1.0 servers can set "cwmp_version" to "1.0" and start rocking 
oldschool.

Kaspar

Signed-off-by: Kaspar Schleiser <kaspar@schleiser.de>
---
 src/config.c    |   18 ++++++++++++++++
 src/cwmp/acs.c  |   19 +++++++++++++++++
 src/cwmp/acs.h  |    5 ++++
 src/cwmp/cwmp.h |    6 +++++
 src/xml/xml.c   |   59 +++++++++++++++++++++++++++++-------------------------
 5 files changed, 80 insertions(+), 27 deletions(-)

diff --git a/src/config.c b/src/config.c
index ea73c51..20aa685 100644
--- a/src/config.c
+++ b/src/config.c
@@ -175,6 +175,24 @@ section_found:
                        n++;
                        goto next;
                }
+               
+        /* cwmp version */
+               status = strcmp((uci_to_option(e))->e.name, "cwmp_version");
+               if (status == FC_SUCCESS) {
+            char* c = uci_to_option(e)->v.string;
+            enum cwmp_version version = V1_2;
+
+            if (strcmp(c, "1.0") == 0) version = V1_0;
+            else if (strcmp(c, "1.2") == 0) version = V1_2;
+            else {
+                fprintf(stderr, "in section acs: cwmp_version has unknown 
value (\"1.0\" or \"1.2\" expected)");
+                goto error;
+            }
+
+            acs_set_cwmp_version(version);
+
+                       goto next;
+               }
 
 next:
                ;
diff --git a/src/cwmp/acs.c b/src/cwmp/acs.c
index 5330a1a..e379049 100644
--- a/src/cwmp/acs.c
+++ b/src/cwmp/acs.c
@@ -26,6 +26,7 @@ acs_init()
        acs.hostname = NULL;
        acs.port = 0;
        acs.path = NULL;
+    acs.cwmp_version = V1_2;
 
        FC_DEVEL_DEBUG("exit");
 }
@@ -48,6 +49,8 @@ acs_clean()
        acs.port = 0;
        if (acs.path) free(acs.path);
        acs.path = NULL;
+       
+    acs.cwmp_version = V1_2;
 
        FC_DEVEL_DEBUG("exit");
 }
@@ -164,3 +167,19 @@ acs_set_path(char *c)
        FC_DEVEL_DEBUG("exit");
 }
 
+enum cwmp_version
+acs_get_cwmp_version(void)
+{
+       FC_DEVEL_DEBUG("enter & exit");
+       return acs.cwmp_version;
+}
+
+void
+acs_set_cwmp_version(enum cwmp_version version)
+{
+       FC_DEVEL_DEBUG("enter");
+
+    acs.cwmp_version = version;
+
+       FC_DEVEL_DEBUG("exit");
+}
diff --git a/src/cwmp/acs.h b/src/cwmp/acs.h
index b502f72..3a51a46 100644
--- a/src/cwmp/acs.h
+++ b/src/cwmp/acs.h
@@ -11,6 +11,8 @@
 
 #include <stdint.h>
 
+#include "cwmp.h"
+
 struct acs
 {
        char *scheme;
@@ -19,6 +21,7 @@ struct acs
        char *hostname;
        uint16_t port;
        char *path;
+    enum cwmp_version cwmp_version;
 };
 
 void acs_init();
@@ -34,6 +37,8 @@ uint16_t acs_get_port(void);
 void acs_set_port(char *c);
 char * acs_get_path(void);
 void acs_set_path(char *c);
+enum cwmp_version acs_get_cwmp_version(void);
+void acs_set_cwmp_version(enum cwmp_version version);
 
 #endif
 
diff --git a/src/cwmp/cwmp.h b/src/cwmp/cwmp.h
index 6bca6b8..c3d980e 100644
--- a/src/cwmp/cwmp.h
+++ b/src/cwmp/cwmp.h
@@ -12,6 +12,12 @@
 
 #include <libubox/uloop.h>
 
+enum cwmp_version
+{
+    V1_0 = 0,
+    V1_2
+};
+
 enum cwmp_event_code 
 { 
        BOOTSTRAP = 0, 
diff --git a/src/xml/xml.c b/src/xml/xml.c
index f0e7aa7..1972fd1 100644
--- a/src/xml/xml.c
+++ b/src/xml/xml.c
@@ -88,12 +88,12 @@ xml_init(void)
 
        c = "http://www.w3.org/2001/XMLSchema-instance";;
        ns.xsi_url = strdup(c);
-       
-       /* TODO: this works on ACS HDM, might want to chage for other ACS 
servers */
-//     c = "urn:dslforum-org:cwmp-1-2";
 
-    /* Use this for Motorola nbbs5 */
-    c = "urn:dslforum-org:cwmp-1-0";
+    if (acs_get_cwmp_version() == V1_2) {
+        c = "urn:dslforum-org:cwmp-1-2";
+    } else {
+        c = "urn:dslforum-org:cwmp-1-0";
+    }
        ns.cwmp_url = strdup(c);
 
        status = FC_SUCCESS;
@@ -440,6 +440,9 @@ xml_handle_message(char *msg_in, char **msg_out)
        char *c, *parameter_name, *parameter_value, *download_url, 
*download_size;
        uint8_t status, len;
        uint16_t att_cnt;
+    enum cwmp_version cwmp_version;
+
+    cwmp_version = acs_get_cwmp_version();
 
 #ifdef DUMMY_MODE
        FILE *fp;
@@ -458,29 +461,31 @@ xml_handle_message(char *msg_in, char **msg_out)
        if (!tree_in)                                      
                goto error;
 
-       /* handle cwmp:ID */
-/*     len = snprintf(NULL, 0, "%s:%s", ns.cwmp, "ID");
-       c = (char *) calloc((len + 1), sizeof(char));
-       if (!c)
-               goto error;
-       snprintf(c, (len + 1), "%s:%s\0", ns.cwmp, "ID");
+    if (cwmp_version == V1_2) {
+        /* handle cwmp:ID */
+        len = snprintf(NULL, 0, "%s:%s", ns.cwmp, "ID");
+        c = (char *) calloc((len + 1), sizeof(char));
+        if (!c)
+            goto error;
+        snprintf(c, (len + 1), "%s:%s\0", ns.cwmp, "ID");
+
+        busy_node = mxmlFindElement(tree_in, tree_in, c, NULL, NULL, 
MXML_DESCEND);
+        free(c); c = NULL;
+        if (!busy_node)
+            goto error;
+
+        busy_node = mxmlWalkNext(busy_node, tree_in, MXML_DESCEND_FIRST);
+        if (!busy_node || !busy_node->value.text.string)
+            goto error;
+        tmp_node = busy_node;
+        busy_node = mxmlFindElement(tree_out, tree_out, "cwmp:ID", NULL, NULL, 
MXML_DESCEND);
+        if (!busy_node)
+            goto error;
+        busy_node = mxmlNewText(busy_node, 0, tmp_node->value.text.string);
+        if (!busy_node)
+            goto error;
+    }
 
-       busy_node = mxmlFindElement(tree_in, tree_in, c, NULL, NULL, 
MXML_DESCEND);
-       free(c); c = NULL;
-       if (!busy_node)
-               goto error;
-
-       busy_node = mxmlWalkNext(busy_node, tree_in, MXML_DESCEND_FIRST);
-       if (!busy_node || !busy_node->value.text.string)
-               goto error;
-       tmp_node = busy_node;
-       busy_node = mxmlFindElement(tree_out, tree_out, "cwmp:ID", NULL, NULL, 
MXML_DESCEND);
-       if (!busy_node)
-               goto error;
-       busy_node = mxmlNewText(busy_node, 0, tmp_node->value.text.string);
-       if (!busy_node)
-               goto error;
-*/
 set_parameter:
        /* handle cwmp:SetParameterValues */
        len = snprintf(NULL, 0, "%s:%s", ns.cwmp, "SetParameterValues");
-- 
1.7.9


<Prev in Thread] Current Thread [Next in Thread>