Version 0 of the Data Model in C

This commit is contained in:
Imen Bhiri 2015-08-06 17:39:44 +01:00
parent e792ada566
commit 7a4426fc80
66 changed files with 8698 additions and 8926 deletions

View file

@ -442,8 +442,8 @@ void load_queue_event(mxml_node_t *tree,struct cwmp *cwmp)
{
if(event_container_save != NULL)
{
parameter_container_add(&(event_container_save->head_parameter_container),
c->value.text.string, NULL, NULL, NULL);
add_dm_parameter_tolist(&(event_container_save->head_dm_parameter),
c->value.text.string, NULL, NULL);
}
}
}

View file

@ -1,5 +1,5 @@
bin_PROGRAMS = cwmpd
CWMP_VERSION = 2.2
CWMP_VERSION = 3.0
cwmpd_SOURCES = \
../backupSession.c \
@ -15,7 +15,20 @@ cwmpd_SOURCES = \
../netlink.c \
../time.c \
../ubus.c \
../xml.c
../xml.c \
../dm/dmcwmp.c \
../dm/dmentry.c \
../dm/dmmem.c \
../dm/dmubus.c \
../dm/dmuci.c \
../dm/dmcommon.c \
../dm/wepkey.c \
../dm/dmtree/deviceinfo.c \
../dm/dmtree/landevice.c \
../dm/dmtree/root.c \
../dm/dmtree/wandevice.c \
../dm/dmtree/x_inteno_se_power_mgmt.c \
../dm/dmtree/managementserver.c
cwmpd_CFLAGS = \
$(AM_CFLAGS) \
@ -44,11 +57,14 @@ cwmpd_LDADD = \
$(LIBCURL_LIBS) \
$(LIBZSTREAM_LIBS) \
$(LIBPTHREAD_LIBS) \
$(LIBJSON_LIBS)
$(LIBJSON_LIBS) \
$(LBLOBMSG_LIBS)
cwmpd_CFLAGS+=-DCWMP_VERSION=\"$(CWMP_VERSION)\"
cwmpd_LDFLAGS+=-DCWMP_VERSION=\"$(CWMP_VERSION)\"
CWMP_BKP_FILE=/etc/cwmpd/.cwmpd_backup_session.xml
cwmpd_CFLAGS+=-DCWMP_BKP_FILE=\"$(CWMP_BKP_FILE)\"
cwmpd_CFLAGS+=-I../inc
cwmpd_CFLAGS+=-I../inc
cwmpd_CFLAGS+=-I../dm/
cwmpd_CFLAGS+=-I../dm/dmtree

View file

@ -21,6 +21,8 @@
#include "backupSession.h"
#include "xml.h"
#include "log.h"
#include "dmentry.h"
#include "deviceinfo.h"
typedef enum uci_config_action {
CMD_SET,
@ -33,6 +35,8 @@ void show_help()
{
fprintf(stdout, "\nUsage: cwmpd [option]\n");
fprintf(stdout, "-b: this option should be added only in the load phase\n");
fprintf(stdout, "-m: execute data model commands\n");
fprintf(stdout, "-w: generate wep keys\n");
fprintf(stdout, "-g: send GetRPCMethods to ACS\n");
fprintf(stdout, "-v: show the application version\n");
fprintf(stdout, "-h: show this help\n\n");
@ -679,6 +683,14 @@ int global_env_init (int argc, char** argv, struct env *env)
case 'g':
env->periodic = CWMP_START_PERIODIC;
break;
case 'm':
dm_entry_cli(argc, argv);
exit(EXIT_SUCCESS);
break;
case 'w':
wepkey_cli(argc, argv);
exit(EXIT_SUCCESS);
break;
case 'v':
show_version();
exit(EXIT_SUCCESS);
@ -718,6 +730,17 @@ int save_acs_bkp_config(struct cwmp *cwmp)
return CWMP_OK;
}
int cwmp_get_deviceid(struct cwmp *cwmp) {
dm_global_init();
cwmp->deviceid.manufacturer = strdup(get_deviceid_manufacturer()); //TODO free
cwmp->deviceid.serialnumber = strdup(get_deviceid_serialnumber());
cwmp->deviceid.productclass = strdup(get_deviceid_productclass());
cwmp->deviceid.oui = strdup(get_deviceid_manufactureroui());
cwmp->deviceid.softwareversion = strdup(get_softwareversion());
dm_global_clean();
return CWMP_OK;
}
int cwmp_init(int argc, char** argv,struct cwmp *cwmp)
{
int error;
@ -751,6 +774,7 @@ int cwmp_init(int argc, char** argv,struct cwmp *cwmp)
{
return error;
}
cwmp_get_deviceid(cwmp);
return CWMP_OK;
}

View file

@ -24,7 +24,6 @@ config 'cwmp' 'cpe'
option 'passwd' 'cpeinteno'
option 'port' '7547'
option 'ubus_socket' '/var/run/ubus.sock'
option provisioning_code ''
option specversion '1.0'
config cwmp
option parameter 'InternetGatewayDevice.DeviceInfo.SpecVersion'
option value '1.0'

View file

@ -77,6 +77,9 @@ AC_SUBST([LIBUBUS_LDFLAGS])
LIBUBUS_LIBS='-lubus'
AC_SUBST([LIBUBUS_LIBS])
LBLOBMSG_LIBS='-lblobmsg_json'
AC_SUBST([LBLOBMSG_LIBS])
AM_COND_IF([HTTP_CURL], [
AC_DEFINE(HTTP_CURL)
PKG_CHECK_MODULES(LIBCURL, [libcurl])

20
cwmp.c
View file

@ -18,6 +18,8 @@
#include "xml.h"
#include "log.h"
#include "external.h"
#include "dmentry.h"
#include "ubus.h"
struct cwmp cwmp_main = {0};
@ -91,13 +93,13 @@ int cwmp_get_retry_interval (struct cwmp *cwmp)
static void cwmp_prepare_value_change (struct cwmp *cwmp, struct session *session)
{
struct event_container *event_container;
if (external_list_value_change.next == &(external_list_value_change))
if (list_value_change.next == &(list_value_change))
return;
pthread_mutex_lock(&(cwmp->mutex_session_queue));
event_container = cwmp_add_event_container (cwmp, EVENT_IDX_4VALUE_CHANGE, "");
if (!event_container) goto end;
pthread_mutex_lock(&(external_mutex_value_change));
list_splice_init(&(external_list_value_change), &(event_container->head_parameter_container));
list_splice_init(&(list_value_change), &(event_container->head_dm_parameter));
pthread_mutex_unlock(&(external_mutex_value_change));
cwmp_save_event_container (cwmp,event_container);
@ -140,12 +142,12 @@ void cwmp_schedule_session (struct cwmp *cwmp)
cwmp->session_status.last_start_time = time(NULL);
cwmp->session_status.last_status = SESSION_RUNNING;
cwmp->session_status.next_retry = 0;
external_init();
dm_global_init();
CWMP_LOG (INFO,"Start session");
error = cwmp_schedule_rpc (cwmp,session);
CWMP_LOG (INFO,"End session");
run_session_end_func(session);
external_exit();
dm_global_clean();
if (session->error == CWMP_RETRY_SESSION)
{
error = cwmp_move_session_to_session_queue (cwmp, session);
@ -362,8 +364,8 @@ int cwmp_move_session_to_session_queue (struct cwmp *cwmp, struct session *sessi
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
return CWMP_MEM_ERR;
}
list_splice_init(&(event_container_old->head_parameter_container),
&(event_container_new->head_parameter_container));
list_splice_init(&(event_container_old->head_dm_parameter),
&(event_container_new->head_dm_parameter));
cwmp_save_event_container (cwmp,event_container_new);
}
session_queue = list_entry(cwmp->head_event_container,struct session, head_event_container);
@ -457,20 +459,26 @@ int run_session_end_func (struct session *session)
if (session->end_session & END_SESSION_EXTERNAL_ACTION)
{
CWMP_LOG (INFO,"Executing external commands: end session request");
external_init();
external_simple("end_session", NULL);
external_exit();
}
if (session->end_session & END_SESSION_FACTORY_RESET)
{
CWMP_LOG (INFO,"Executing factory reset: end session request");
external_init();
external_simple("factory_reset", NULL);
external_exit();
exit(EXIT_SUCCESS);
}
if (session->end_session & END_SESSION_REBOOT)
{
CWMP_LOG (INFO,"Executing Reboot: end session request");
external_init();
external_simple("reboot", NULL);
external_exit();
exit(EXIT_SUCCESS);
}

27
dm/dmcommon.c Normal file
View file

@ -0,0 +1,27 @@
/*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2012-2014 PIVA SOFTWARE (www.pivasoftware.com)
* Author: Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author: Feten Besbes <feten.besbes@pivasoftware.com>
*/
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
char *cut_fx(char *str, char *delimiter, int occurence)
{
int i = 1;
char *pch;
pch = strtok (str, delimiter);
while (pch != NULL && i<occurence) {
i++;
pch = strtok(NULL, delimiter);
}
return pch;
}

24
dm/dmcommon.h Normal file
View file

@ -0,0 +1,24 @@
/*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2015 PIVA SOFTWARE (www.pivasoftware.com)
* Author: Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author: Feten Besbes <feten.besbes@pivasoftware.com>
*/
#ifndef __DM_COMMON_H
#define __DM_COMMON_H
#define DM_ASSERT(X, Y) \
do { \
if(!(X)) { \
Y; \
return -1; \
} \
} while(0)
char *cut_fx(char *str, char *delimiter, int occurence);
#endif

892
dm/dmcwmp.c Normal file
View file

@ -0,0 +1,892 @@
/*
*
* Copyright (C) 2015 Inteno Broadband Technology AB
* Author MOHAMED Kallel <mohamed.kallel@pivasoftware.com>
* Author Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author Feten Besbes <feten.besbes@pivasoftware.com>
*
*/
#include <uci.h>
#include "dmuci.h"
#include "dmcwmp.h"
#include "root.h"
#include "landevice.h"
#include "wandevice.h"
#include "deviceinfo.h"
#include "managementserver.h"
#include "x_inteno_se_power_mgmt.h"
static char *get_parameter_notification (char *param);
static int remove_parameter_notification(char *param);
static int set_parameter_notification(char *param, char *value);
static int check_param_prefix (struct dmctx *ctx);
static int check_obj_is_nl1(char *refparam, char *inparam, int ndot);
static int get_value_obj(DMOBJECT_API_ARGS);
static int get_value_inparam_isobj_check_obj(DMOBJECT_API_ARGS);
static int get_value_inparam_isparam_check_obj(DMOBJECT_API_ARGS);
static int get_value_param(DMPARAM_API_ARGS);
static int get_value_inparam_isparam_check_param(DMPARAM_API_ARGS);
static int get_value_inparam_isobj_check_param(DMPARAM_API_ARGS);
static int get_name_obj(DMOBJECT_API_ARGS);
static int get_name_inparam_isparam_check_obj(DMOBJECT_API_ARGS);
static int get_name_inparam_isobj_check_obj(DMOBJECT_API_ARGS);
static int get_name_emptyin_nl1_obj(DMOBJECT_API_ARGS);
static int get_name_param(DMPARAM_API_ARGS);
static int get_name_inparam_isparam_check_param(DMPARAM_API_ARGS);
static int get_name_inparam_isobj_check_param(DMPARAM_API_ARGS);
static int get_name_emptyin_nl1_param(DMPARAM_API_ARGS);
static int get_notification_obj(DMOBJECT_API_ARGS);
static int get_notification_inparam_isparam_check_obj(DMOBJECT_API_ARGS);
static int get_notification_inparam_isobj_check_obj(DMOBJECT_API_ARGS);
static int get_notification_param(DMPARAM_API_ARGS);
static int get_notification_inparam_isparam_check_param(DMPARAM_API_ARGS);
static int get_notification_inparam_isobj_check_param(DMPARAM_API_ARGS);
static int inform_check_obj(DMOBJECT_API_ARGS);
static int inform_check_param(DMPARAM_API_ARGS);
static int add_object_obj(DMOBJECT_API_ARGS);
static int add_object_param(DMPARAM_API_ARGS);
static int delete_object_obj(DMOBJECT_API_ARGS);
static int delete_object_param(DMPARAM_API_ARGS);
static int set_value_check_obj(DMOBJECT_API_ARGS);
static int set_value_check_param(DMPARAM_API_ARGS);
static int set_notification_check_obj(DMOBJECT_API_ARGS);
static int set_notification_check_param(DMPARAM_API_ARGS);
struct notification notifications[] = {
[0] = {"0", "disabled"},
[1] = {"1", "passive"},
[2] = {"2", "active"}
};
const struct prefix_method prefix_methods[] = {
{ DMROOT, 1, &entry_method_root },
{ DMROOT"DeviceInfo.", 1, &entry_method_root_DeviceInfo },
{ DMROOT"ManagementServer.", 1, &entry_method_root_ManagementServer },
{ DMROOT"X_INTENO_SE_PowerManagement.", 0, &entry_method_root_X_INTENO_SE_PowerManagement },
{ DMROOT"LANDevice.", 0, &entry_method_root_LANDevice },
{ DMROOT"WANDevice.", 1, &entry_method_root_WANDevice },
//{ DMROOT"Layer2Bridging.", &entry_method_root_Layer2Bridging },
};
char *update_instance(struct uci_section *s, char *last_inst, char *inst_opt)
{
char *instance;
char buf[8] = {0};
dmuci_get_value_by_section_string(s, inst_opt, &instance);
if (instance[0] == '\0') {
if (last_inst == NULL)
sprintf(buf, "%d", 1);
else
sprintf(buf, "%d", atoi(last_inst)+1);
dmfree(instance); //TODO MEM
instance = dmuci_set_value_by_section(s, inst_opt, buf);
instance = dmstrdup(instance);
}
return instance;
}
int get_empty(char *refparam, struct dmctx *args, char **value)
{
*value = dmstrdup("");
return 0;
}
void add_list_paramameter(struct dmctx *ctx, char *param_name, char *param_data, char *param_type)
{
struct dm_parameter *dm_parameter;
struct list_head *ilist;
list_for_each(ilist, &ctx->list_parameter) {
dm_parameter = list_entry(ilist, struct dm_parameter, list);
int cmp = strcmp(dm_parameter->name, param_name);
if (cmp == 0) {
return;
} else if (cmp>0) {
break;
}
}
dm_parameter = dmcalloc(1, sizeof(struct dm_parameter));
_list_add(&dm_parameter->list, ilist->prev, ilist);
dm_parameter->name = param_name;
dm_parameter->data = param_data ? param_data : dmstrdup(""); //allocate memory in function
dm_parameter->type = param_type;
}
void del_list_parameter(struct dm_parameter *dm_parameter)
{
list_del(&dm_parameter->list);
dmfree(dm_parameter->name);
dmfree(dm_parameter->data);
dmfree(dm_parameter);
}
void free_all_list_parameter(struct dmctx *ctx)
{
struct dm_parameter *dm_parameter;
while (ctx->list_parameter.next != &ctx->list_parameter) {
dm_parameter = list_entry(ctx->list_parameter.next, struct dm_parameter, list);
del_list_parameter(dm_parameter);
}
}
void add_set_list_tmp(struct dmctx *ctx, char *param, char *value)
{
struct set_tmp *set_tmp;
set_tmp = dmcalloc(1, sizeof(struct set_tmp));
list_add_tail(&set_tmp->list, &ctx->set_list_tmp);
set_tmp->name = dmstrdup(param);
set_tmp->value = dmstrdup(value);
}
void del_set_list_tmp(struct set_tmp *set_tmp)
{
list_del(&set_tmp->list);
dmfree(set_tmp->name);
dmfree(set_tmp->value);
dmfree(set_tmp);
}
void free_all_set_list_tmp(struct dmctx *ctx)
{
struct set_tmp *set_tmp;
while (ctx->set_list_tmp.next != &ctx->set_list_tmp) {
set_tmp = list_entry(ctx->set_list_tmp.next, struct set_tmp, list);
del_set_list_tmp(set_tmp);
}
}
void add_list_fault_param(struct dmctx *ctx, char *param, int fault)
{
struct param_fault *param_fault;
if (param == NULL) param = "";
param_fault = dmcalloc(1, sizeof(struct param_fault));
list_add_tail(&param_fault->list, &ctx->list_fault_param);
param_fault->name = dmstrdup(param);
param_fault->fault = fault;
}
void del_list_fault_param(struct param_fault *param_fault)
{
list_del(&param_fault->list);
dmfree(param_fault->name);
dmfree(param_fault);
}
void free_all_list_fault_param(struct dmctx *ctx)
{
struct param_fault *param_fault;
while (ctx->list_fault_param.next != &ctx->list_fault_param) {
param_fault = list_entry(ctx->list_fault_param.next, struct param_fault, list);
del_list_fault_param(param_fault);
}
}
static char *get_parameter_notification (char *param)
{
int i, maxlen = 0, len;
struct uci_list *list_notif;
char *pch;
char *notification = "0";
struct uci_element *e;
for (i = (ARRAY_SIZE(notifications) - 1); i >= 0; i--) {
dmuci_get_option_value_list("cwmp", "@notifications[0]", notifications[i].type, &list_notif);
if (list_notif) {
uci_foreach_element(list_notif, e) {
pch = e->name;
if (strcmp(pch, param) == 0) {
notification = notifications[i].value;
return notification;
}
len = strlen(pch);
if (pch[len-1] == '.') {
if (strstr(param, pch)) {
if (len > maxlen )
{
notification = notifications[i].value;
maxlen = len;
}
}
}
}
}
}
return notification;
}
static int remove_parameter_notification(char *param)
{
unsigned int i;
struct uci_list *list_notif;
struct uci_element *e;
char *pch;
for (i = (ARRAY_SIZE(notifications) - 1); i >= 0; i--) {
if (param[strlen(param)-1] == '.') {
dmuci_get_option_value_list("cwmp", "@notifications[0]", notifications[i].type, &list_notif);
if (list_notif) {
uci_foreach_element(list_notif, e) {
pch = e->name;
if (strstr(pch, param) == 0) {
dmuci_del_list_value("cwmp", "@notifications[0]", notifications[i].type, pch);
}
}
}
} else {
dmuci_del_list_value("cwmp", "@notifications[0]", notifications[i].type, param);
}
}
return 0;
}
static int set_parameter_notification(char *param, char *value)
{
char *tmp = NULL, *buf = NULL, *pch;
char *notification = NULL;
struct uci_section *s;
dmuci_get_section_type("cwmp", "@notifications[0]", &tmp);
if (!tmp || tmp[0] == '\0') {
dmuci_add_section("cwmp", "notifications", &s, &buf);
dmfree(buf);
} else {
remove_parameter_notification(param);
}
dmfree(tmp);
notification = get_parameter_notification(param);
if (strcmp(notification, value) == 0) {
return 0;
}
if (strcmp(value, "1") == 0) {
dmuci_add_list_value("cwmp", "@notifications[0]", "passive", param);
} else if (strcmp(value, "2") == 0) {
dmuci_add_list_value("cwmp", "@notifications[0]", "active", param);
} else if (strcmp(value, "0") == 0) {
struct uci_list *list_notif;
struct uci_element *e;
int i, len;
for (i = (ARRAY_SIZE(notifications) - 1); i >= 1; i--) {
dmuci_get_option_value_list("cwmp", "@notifications[0]", notifications[i].type, &list_notif);
if (list_notif) {
uci_foreach_element(list_notif, e) {
pch = e->name;
len = strlen(pch);
if (pch[len-1] == '.' && strstr(param, pch)) {
dmuci_add_list_value("cwmp", "@notifications[0]", "disabled", param);
return 0;
}
}
}
}
} else {
return -1;
}
return 0;
}
static int check_param_prefix (struct dmctx *ctx)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(prefix_methods); i++) {
if (strcmp(ctx->in_param, prefix_methods[i].prefix_name) == 0) {
return 0;
}
}
return -1;
}
static int check_obj_is_nl1(char *refparam, char *inparam, int ndot)
{
unsigned int len, i;
len = strlen(refparam);
for (i = len - 1; i >= 0; i--) {
if (refparam[i] == '.') {
if (--ndot == 0)
break;
}
}
i++;
if (strlen(inparam) == i)
return 0;
return -1;
}
int string_to_bool(char *v, bool *b)
{
if (v[0] == '1' && v[1] == '\0') {
*b = true;
return 0;
}
if (v[0] == '0' && v[1] == '\0') {
*b = false;
return 0;
}
if (strcasecmp(v, "true") == 0) {
*b = true;
return 0;
}
if (strcasecmp(v, "false") == 0) {
*b = false;
return 0;
}
*b = false;
return -1;
}
/* **********
* get value
* **********/
int dm_entry_get_value(struct dmctx *ctx)
{
int i;
ctx->faultcode = FAULT_9005;
if (ctx->in_param[0] == '\0' || check_param_prefix(ctx) == 0) {
ctx->method_obj=&get_value_obj;
ctx->method_param=&get_value_param;
ctx->faultcode = 0;
} else if (ctx->in_param[strlen(ctx->in_param)-1] == '.') {
ctx->method_obj=&get_value_inparam_isobj_check_obj;
ctx->method_param=&get_value_inparam_isobj_check_param;
} else {
ctx->method_obj=&get_value_inparam_isparam_check_obj;
ctx->method_param=&get_value_inparam_isparam_check_param;
}
for (i = 0; i < ARRAY_SIZE(prefix_methods); i++) {
int ret = prefix_methods[i].method(ctx);
if (ctx->stop)
return ret;
}
return ctx->faultcode;
}
static int get_value_obj(DMOBJECT_API_ARGS)
{
return 0;
}
static int get_value_inparam_isobj_check_obj(DMOBJECT_API_ARGS)
{
if (strstr(ctx->current_obj, ctx->in_param)) {
ctx->faultcode = 0;
return 0;
}
return FAULT_9005;
}
static int get_value_inparam_isparam_check_obj(DMOBJECT_API_ARGS)
{
return FAULT_9005;
}
static int get_value_param(DMPARAM_API_ARGS)
{
char *full_param;
char *value = NULL;
dmastrcat(&full_param, ctx->current_obj, lastname);
(get_cmd)(full_param, ctx, &value);
add_list_paramameter(ctx, full_param, value, type ? type : "xsd:string");
return 0;
}
static int get_value_inparam_isparam_check_param(DMPARAM_API_ARGS)
{
char *full_param;
char *value = NULL;
dmastrcat(&full_param, ctx->current_obj, lastname);
if (strcmp(ctx->in_param, full_param) != 0) {
dmfree(full_param);
return FAULT_9005;
}
(get_cmd)(full_param, ctx, &value);
add_list_paramameter(ctx, full_param, value, type ? type : "xsd:string");
ctx->stop = true;
return 0;
}
static int get_value_inparam_isobj_check_param(DMPARAM_API_ARGS)
{
char *full_param;
char *value = NULL;
dmastrcat(&full_param, ctx->current_obj, lastname);
if (strstr(full_param, ctx->in_param)) {
(get_cmd)(full_param, ctx, &value);
add_list_paramameter(ctx, full_param, value, type ? type : "xsd:string");
ctx->faultcode = 0;
return 0;
}
dmfree(full_param);
return FAULT_9005;
}
/* **********
* get name
* **********/
int dm_entry_get_name(struct dmctx *ctx)
{
int i;
ctx->faultcode = FAULT_9005;
if (ctx->in_param[0] == '\0' && ctx->nextlevel == 1) {
ctx->method_obj=&get_name_emptyin_nl1_obj;
ctx->method_param=&get_name_emptyin_nl1_param;
entry_method_root(ctx);
return 0;
}
if ( ctx->in_param[0] == '\0' || check_param_prefix(ctx) == 0) {
if (ctx->nextlevel == 0) {
ctx->method_obj=&get_name_obj;
ctx->method_param=&get_name_param;
ctx->faultcode = 0;
} else {
ctx->method_obj=&get_name_inparam_isobj_check_obj;
ctx->method_param=&get_name_inparam_isobj_check_param;
}
} else if (ctx->in_param[strlen(ctx->in_param)-1] == '.') {
ctx->method_obj=&get_name_inparam_isobj_check_obj;
ctx->method_param=&get_name_inparam_isobj_check_param;
} else {
ctx->method_obj=&get_name_inparam_isparam_check_obj;
ctx->method_param=&get_name_inparam_isparam_check_param;
}
for (i = 0; i < ARRAY_SIZE(prefix_methods); i++) {
int ret = prefix_methods[i].method(ctx);
if (ctx->stop == 1)
return ret;
}
return ctx->faultcode;
}
static int get_name_obj(DMOBJECT_API_ARGS)
{
char *obj = dmstrdup(ctx->current_obj);
char *p = dmstrdup(permission);
add_list_paramameter(ctx, obj, p, NULL);
return 0;
}
static int get_name_inparam_isparam_check_obj(DMOBJECT_API_ARGS)
{
return FAULT_9005;
}
static int get_name_inparam_isobj_check_obj(DMOBJECT_API_ARGS)
{
if (strstr(ctx->current_obj, ctx->in_param)) {
ctx->faultcode = 0;
if (ctx->nextlevel == 0 || check_obj_is_nl1(ctx->current_obj, ctx->in_param, 2) == 0 ) {
char *obj = dmstrdup(ctx->current_obj);
char *p = dmstrdup(permission);
add_list_paramameter(ctx, obj, p, NULL);
return 0;
}
return 0;
}
return FAULT_9005;
}
static int get_name_emptyin_nl1_obj(DMOBJECT_API_ARGS)
{
char *obj = dmstrdup(ctx->current_obj);
char *p = dmstrdup(permission);
add_list_paramameter(ctx, obj, p, NULL);
return 0;
}
static int get_name_param(DMPARAM_API_ARGS)
{
char *full_param;
char *p = dmstrdup(permission);
dmastrcat(&full_param, ctx->current_obj, lastname);
add_list_paramameter(ctx, full_param, p, NULL);
return 0;
}
static int get_name_inparam_isparam_check_param(DMPARAM_API_ARGS)
{
char *full_param;
dmastrcat(&full_param, ctx->current_obj, lastname);
if (strcmp(full_param, ctx->in_param) != 0) {
dmfree(full_param);
return FAULT_9005;
}
if (ctx->nextlevel == 1) {
dmfree(full_param);
ctx->stop = 1;
return FAULT_9003;
}
char *p = dmstrdup(permission);
add_list_paramameter(ctx, full_param, p, NULL);
ctx->stop = 1;
return 0;
}
static int get_name_inparam_isobj_check_param(DMPARAM_API_ARGS)
{
char *full_param;
dmastrcat(&full_param, ctx->current_obj, lastname);
if (strstr(full_param, ctx->in_param)) {
ctx->faultcode = 0;
if (ctx->nextlevel == 0 || check_obj_is_nl1(full_param, ctx->in_param, 1) == 0 ) {
char *p = dmstrdup(permission);
add_list_paramameter(ctx, full_param, p, NULL);
return 0;
}
dmfree(full_param);
return 0;
}
dmfree(full_param);
return FAULT_9005;
}
static int get_name_emptyin_nl1_param(DMPARAM_API_ARGS)
{
return 0;
}
/* ********************
* get notification
* ********************/
int dm_entry_get_notification(struct dmctx *ctx)
{
int i;
ctx->faultcode = FAULT_9005;
if (ctx->in_param[0] == '\0' || check_param_prefix(ctx) == 0) {
ctx->method_obj=&get_notification_obj;
ctx->method_param=&get_notification_param;
ctx->faultcode = 0;
} else if ( ctx->in_param[strlen(ctx->in_param)-1] == '.') {
ctx->method_obj=&get_notification_inparam_isobj_check_obj;
ctx->method_param=&get_notification_inparam_isobj_check_param;
} else {
ctx->method_obj=&get_notification_inparam_isparam_check_obj;
ctx->method_param=&get_notification_inparam_isparam_check_param;
}
for (i = 0; i < ARRAY_SIZE(prefix_methods); i++) {
int ret = prefix_methods[i].method(ctx);
if (ctx->stop == 1)
return ret;
}
return ctx->faultcode;
}
static int get_notification_obj(DMOBJECT_API_ARGS)
{
return 0;
}
static int get_notification_inparam_isparam_check_obj(DMOBJECT_API_ARGS)
{
return FAULT_9005;
}
static int get_notification_inparam_isobj_check_obj(DMOBJECT_API_ARGS)
{
if (strstr(ctx->current_obj, ctx->in_param)) {
ctx->faultcode = 0;
return 0;
}
return FAULT_9005;
}
static int get_notification_param(DMPARAM_API_ARGS)
{
char *full_param;
char *notification;
dmastrcat(&full_param, ctx->current_obj, lastname);
if (forced_notify == UNDEF) {
notification = get_parameter_notification(full_param);
notification = dmstrdup(notification);
} else {
notification = dmstrdup(notifications[forced_notify].value);
}
add_list_paramameter(ctx, full_param, notification, NULL);
return 0;
}
static int get_notification_inparam_isparam_check_param(DMPARAM_API_ARGS)
{
char *full_param;
char *notification;
dmastrcat(&full_param, ctx->current_obj, lastname);
if (strcmp(full_param, ctx->in_param) != 0) {
dmfree(full_param);
return FAULT_9005;
}
if (forced_notify == UNDEF) {
notification = get_parameter_notification(full_param);
notification = dmstrdup(notification);
} else {
notification = dmstrdup(notifications[forced_notify].value);
}
add_list_paramameter(ctx, full_param, notification, NULL);
ctx->stop = true;
return 0;
}
static int get_notification_inparam_isobj_check_param(DMPARAM_API_ARGS)
{
char *full_param;
char *notification;
dmastrcat(&full_param, ctx->current_obj, lastname);
if (strstr(full_param, ctx->in_param)) {
if (forced_notify == UNDEF) {
notification = get_parameter_notification(full_param);
notification = dmstrdup(notification);
} else {
notification = dmstrdup(notifications[forced_notify].value);
}
add_list_paramameter(ctx, full_param, notification, NULL);
ctx->faultcode = 0;
return 0;
}
dmfree(full_param);
return FAULT_9005;
}
/***************
* inform
***************/
int dm_entry_inform(struct dmctx *ctx)
{
int i;
ctx->method_obj = &inform_check_obj;
ctx->method_param = &inform_check_param;
for (i = 0; i < ARRAY_SIZE(prefix_methods); i++) {
if (prefix_methods[i].forced_inform)
prefix_methods[i].method(ctx);
}
return 0;
}
static int inform_check_obj(DMOBJECT_API_ARGS)
{
return FAULT_9005;
}
static int inform_check_param(DMPARAM_API_ARGS)
{
if (!forced_inform)
return FAULT_9005;
char *full_param;
char *value = NULL;
dmastrcat(&full_param, ctx->current_obj, lastname);
(get_cmd)(full_param, ctx, &value);
add_list_paramameter(ctx, full_param, value, type ? type : "xsd:string");
return 0;
}
/* **************
* add object
* **************/
int dm_entry_add_object(struct dmctx *ctx)
{
int i;
if (ctx->tree)
return FAULT_9005;
ctx->method_obj=&add_object_obj;
ctx->method_param=&add_object_param;
for (i = 0; i < ARRAY_SIZE(prefix_methods); i++) {
int ret = prefix_methods[i].method(ctx);
if (ctx->stop)
return ret;
}
return FAULT_9005;
}
static int add_object_obj(DMOBJECT_API_ARGS)
{
char *instance;
if (strcmp(ctx->current_obj, ctx->in_param) != 0)
return FAULT_9005;
ctx->stop = true;
if (addobj == NULL)
return FAULT_9005;
int fault = (addobj)(ctx, &instance);
if (fault)
return fault;
ctx->addobj_instance = instance;
char *objinst;
dmastrcat(&objinst, ctx->current_obj, instance);
set_parameter_notification(objinst, "0");
dmfree(objinst);
return 0;
}
static int add_object_param(DMPARAM_API_ARGS)
{
return FAULT_9005;
}
/* **************
* del object
* **************/
int dm_entry_delete_object(struct dmctx *ctx)
{
int i;
if (ctx->tree == 1)
return FAULT_9005;
ctx->method_obj=&delete_object_obj;
ctx->method_param=&delete_object_param;
for (i = 0; i < ARRAY_SIZE(prefix_methods); i++) {
int ret = prefix_methods[i].method(ctx);
if (ctx->stop)
return ret;
}
return FAULT_9005;
}
static int delete_object_obj(DMOBJECT_API_ARGS)
{
if (strcmp(ctx->current_obj, ctx->in_param) != 0)
return FAULT_9005;
ctx->stop = true;
if (delobj == NULL)
return FAULT_9005;
int fault = (delobj)(ctx);
return fault;
}
static int delete_object_param(DMPARAM_API_ARGS)
{
return FAULT_9005;
}
/* **************
* set value
* **************/
int dm_entry_set_value(struct dmctx *ctx)
{
int i;
if (ctx->in_param[0] == '\0' || ctx->in_param[strlen(ctx->in_param)-1] == '.' ) {
return FAULT_9005;
} else {
ctx->method_obj=&set_value_check_obj;
ctx->method_param=&set_value_check_param;
}
for (i = 0; i < ARRAY_SIZE(prefix_methods); i++) {
int ret = prefix_methods[i].method(ctx);
if (ctx->stop)
return ret;
}
return FAULT_9005;
}
static int set_value_check_obj(DMOBJECT_API_ARGS)
{
return FAULT_9005;
}
static int set_value_check_param(DMPARAM_API_ARGS)
{
char *full_param;
dmastrcat(&full_param, ctx->current_obj, lastname);
if (strcmp(ctx->in_param, full_param) != 0) {
dmfree(full_param);
return FAULT_9005;
}
ctx->stop = true;
if (ctx->setaction == VALUECHECK) {
if (permission[0] != '1' || set_cmd == NULL) {
dmfree(full_param);
return FAULT_9008;
}
int fault = (set_cmd)(full_param, ctx, VALUECHECK, ctx->in_value);
if (fault) {
dmfree(full_param);
return fault;
}
add_set_list_tmp(ctx, ctx->in_param, ctx->in_value);
}
else if (ctx->setaction == VALUESET) {
(set_cmd)(full_param, ctx, VALUESET, ctx->in_value);
}
dmfree(full_param);
return 0;
}
/* ****************
* set notification
* ****************/
int dm_entry_set_notification(struct dmctx *ctx)
{
int i;
if (ctx->in_param[0] == '\0') {
return FAULT_9009;
} else {
ctx->method_obj=&set_notification_check_obj;
ctx->method_param=&set_notification_check_param;
}
for (i = 0; i < ARRAY_SIZE(prefix_methods); i++) {
int ret = prefix_methods[i].method(ctx);
if (ctx->stop)
return ret;
}
return FAULT_9005;
}
static int set_notification_check_obj(DMOBJECT_API_ARGS)
{
if (strcmp(ctx->in_param, ctx->current_obj) != 0)
return FAULT_9005;
ctx->stop = true;
if (ctx->setaction == VALUECHECK) {
if (!notif_permission)
return FAULT_9009;
add_set_list_tmp(ctx, ctx->in_param, ctx->in_notification);
} else if (ctx->setaction == VALUESET) {
set_parameter_notification(ctx->in_param, ctx->in_notification);
}
return 0;
}
static int set_notification_check_param(DMPARAM_API_ARGS)
{
char *full_param;
dmastrcat(&full_param, ctx->current_obj, lastname);
if (strcmp(ctx->in_param, full_param) != 0) {
dmfree(full_param);
return FAULT_9005;
}
ctx->stop = true;
if (ctx->setaction == VALUECHECK) {
if (!notif_permission) {
dmfree(full_param);
return FAULT_9009;
}
add_set_list_tmp(ctx, ctx->in_param, ctx->in_notification);
} else if (ctx->setaction == VALUESET) {
set_parameter_notification(ctx->in_param, ctx->in_notification);
}
dmfree(full_param);
return 0;
}

225
dm/dmcwmp.h Normal file
View file

@ -0,0 +1,225 @@
/*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2015 Inteno Broadband Technology AB
* Author MOHAMED Kallel <mohamed.kallel@pivasoftware.com>
* Author Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author Feten Besbes <feten.besbes@pivasoftware.com>
*
*/
#ifndef __DMCWMP_H__
#define __DMCWMP_H__
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>
#include <libubox/list.h>
#include "dmuci.h"
#include "dmmem.h"
#define DMROOT "InternetGatewayDevice."
#ifdef UNDEF
#undef UNDEF
#endif
#define UNDEF -1
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#endif
#define IF_MATCH(ctx, prefix, ...) \
(ctx)->match = (ctx)->tree; \
if (!(ctx)->tree) { \
sprintf((ctx)->current_obj, prefix, ##__VA_ARGS__); \
if (strstr((ctx)->in_param, (ctx)->current_obj) || strstr((ctx)->current_obj, (ctx)->in_param)) { \
(ctx)->match = true; \
} \
} \
if ((ctx)->match)
#define DMOBJECT(name, ctx, permission, notif_permission, addobj, delobj, linker, ...) { \
sprintf((ctx)->current_obj, name, ##__VA_ARGS__); \
int error = ctx->method_obj(ctx, permission, notif_permission, addobj, delobj, linker); \
if ((ctx)->stop) return error; \
}
#define DMPARAM(lastname, ctx, permission, get_cmd, set_cmd, type, forced_inform, notif_permission, forced_notify, linker) { \
int error = ctx->method_param(lastname, ctx, permission, get_cmd, set_cmd, type, forced_inform, notif_permission, forced_notify, linker); \
if ((ctx)->stop) return error; \
}
#define SUBENTRY(f, ctx, ...) { \
int error = f(ctx, ## __VA_ARGS__); \
if ((ctx)->stop) return error; \
}
#define DMPARAM_API_ARGS \
char *lastname, \
struct dmctx *ctx, \
char *permission, \
int (*get_cmd)(char *refparam, struct dmctx *ctx, char **value), \
int (*set_cmd)(char *refparam, struct dmctx *ctx, int action, char *value), \
char *type, \
bool forced_inform, \
bool notif_permission, \
int forced_notify, \
char *linker
#define DMOBJECT_API_ARGS \
struct dmctx *ctx, \
char *permission, \
bool notif_permission, \
int (*addobj)(struct dmctx *ctx, char **instance), \
int (*delobj)(struct dmctx *ctx), \
char *linker
#define TAILLE_MAX 1024
struct set_tmp {
struct list_head list;
char *name;
char *value;
};
struct param_fault {
struct list_head list;
char *name;
int fault;
};
struct dm_parameter {
struct list_head list;
char *name;
char *data;
char *type;
};
struct dmctx
{
bool stop;
bool tree;
bool match;
int (*method_param)(DMPARAM_API_ARGS);
int (*method_obj)(DMOBJECT_API_ARGS);
void *args;
struct list_head list_parameter;
struct list_head set_list_tmp;
struct list_head list_fault_param;
bool nextlevel;
int faultcode;
int setaction;
char *in_param;
char *in_notification;
char *in_value;
char *addobj_instance;
char current_obj[512];
};
struct prefix_method {
const char *prefix_name;
bool forced_inform;
int (*method)(struct dmctx *ctx);
};
struct notification {
char *value;
char *type;
};
enum set_value_action {
VALUECHECK,
VALUESET
};
enum {
CMD_GET_VALUE,
CMD_GET_NAME,
CMD_GET_NOTIFICATION,
CMD_SET_VALUE,
CMD_SET_NOTIFICATION,
CMD_ADD_OBJECT,
CMD_DEL_OBJECT,
CMD_INFORM,
};
enum fault_code {
FAULT_9000 = 9000,// Method not supported
FAULT_9001,// Request denied
FAULT_9002,// Internal error
FAULT_9003,// Invalid arguments
FAULT_9004,// Resources exceeded
FAULT_9005,// Invalid parameter name
FAULT_9006,// Invalid parameter type
FAULT_9007,// Invalid parameter value
FAULT_9008,// Attempt to set a non-writable parameter
FAULT_9009,// Notification request rejected
FAULT_9010,// Download failure
FAULT_9011,// Upload failure
FAULT_9012,// File transfer server authentication failure
FAULT_9013,// Unsupported protocol for file transfer
FAULT_9014,// Download failure: unable to join multicast group
FAULT_9015,// Download failure: unable to contact file server
FAULT_9016,// Download failure: unable to access file
FAULT_9017,// Download failure: unable to complete download
FAULT_9018,// Download failure: file corrupted
FAULT_9019,// Download failure: file authentication failure
__FAULT_MAX
};
char *update_instance(struct uci_section *s, char *last_inst, char *inst_opt);
int get_empty(char *refparam, struct dmctx *args, char **value);
void add_list_paramameter(struct dmctx *ctx, char *param_name, char *param_data, char *param_type);
void del_list_parameter(struct dm_parameter *dm_parameter);
void free_all_list_parameter(struct dmctx *ctx);
void add_set_list_tmp(struct dmctx *ctx, char *param, char *value);
void del_set_list_tmp(struct set_tmp *set_tmp);
void free_all_set_list_tmp(struct dmctx *ctx);
void add_list_fault_param(struct dmctx *ctx, char *param, int fault);
void del_list_fault_param(struct param_fault *param_fault);
void free_all_list_fault_param(struct dmctx *ctx);
int string_to_bool(char *v, bool *b);
int dm_entry_get_value(struct dmctx *ctx);
int dm_entry_get_name(struct dmctx *ctx);
int dm_entry_get_notification(struct dmctx *ctx);
int dm_entry_inform(struct dmctx *ctx);
int dm_entry_add_object(struct dmctx *ctx);
int dm_entry_delete_object(struct dmctx *ctx);
int dm_entry_set_value(struct dmctx *ctx);
int dm_entry_set_notification(struct dmctx *ctx);
#ifndef TRACE
#define TRACE_TYPE 0
static inline void trace_empty_func()
{
}
#if TRACE_TYPE == 2
#define TRACE(MESSAGE,args...) do { \
const char *A[] = {MESSAGE}; \
printf("TRACE: %s %s %d\n",__FUNCTION__,__FILE__,__LINE__); fflush(stdout);\
if(sizeof(A) > 0) \
printf(*A,##args); \
} while(0)
#elif TRACE_TYPE == 1
#define TRACE(MESSAGE, ...) printf(MESSAGE, ## __VA_ARGS__)
#else
#define TRACE(MESSAGE, ...) trace_empty_func()
#endif
#endif
#ifndef DETECT_CRASH
#define DETECT_CRASH(MESSAGE,args...) { \
const char *A[] = {MESSAGE}; \
printf("DETECT_CRASH: %s %s %d\n",__FUNCTION__,__FILE__,__LINE__); fflush(stdout);\
if(sizeof(A) > 0) \
printf(*A,##args); \
sleep(1); \
}
#endif
#endif

363
dm/dmentry.c Normal file
View file

@ -0,0 +1,363 @@
/*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2015 Inteno Broadband Technology AB
* Author MOHAMED Kallel <mohamed.kallel@pivasoftware.com>
* Author Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author Feten Besbes <feten.besbes@pivasoftware.com>
*
*/
#include "dmcwmp.h"
#include "dmubus.h"
#include "dmuci.h"
#include "dmentry.h"
LIST_HEAD(head_package_change);
int dm_global_init(void)
{
memset(&dmubus_ctx, 0, sizeof(struct dmubus_ctx));
INIT_LIST_HEAD(&dmubus_ctx.obj_head);
uci_ctx = uci_alloc_context();
return 0;
}
int dm_global_clean(void)
{
if (uci_ctx) uci_free_context(uci_ctx);
uci_ctx= NULL;
dmubus_ctx_free(&dmubus_ctx);
dmcleanmem();
return 0;
}
int dm_ctx_init(struct dmctx *ctx)
{
INIT_LIST_HEAD(&ctx->list_parameter);
INIT_LIST_HEAD(&ctx->set_list_tmp);
INIT_LIST_HEAD(&ctx->list_fault_param);
return 0;
}
int dm_ctx_clean(struct dmctx *ctx)
{
free_all_list_parameter(ctx);
free_all_set_list_tmp(ctx);
free_all_list_fault_param(ctx);
DMFREE(ctx->addobj_instance);
return 0;
}
int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1, char *arg2)
{
int fault = 0;
bool setnotif = true;
if (!inparam) inparam = "";
ctx->in_param = inparam;
if (ctx->in_param[0] == '\0' || strcmp(ctx->in_param, DMROOT) == 0) {
ctx->tree = true;
} else {
ctx->tree = false;
}
switch(cmd) {
case CMD_GET_VALUE:
fault = dm_entry_get_value(ctx);
break;
case CMD_GET_NAME:
if (arg1 && string_to_bool(arg1, &ctx->nextlevel) == 0){
fault = dm_entry_get_name(ctx);
} else {
fault = FAULT_9003;
}
break;
case CMD_GET_NOTIFICATION:
fault = dm_entry_get_notification(ctx);
break;
case CMD_SET_VALUE:
ctx->in_value = arg1 ? arg1 : "";
ctx->setaction = VALUECHECK;
fault = dm_entry_set_value(ctx);
if (fault)
add_list_fault_param(ctx, ctx->in_param, fault);
break;
case CMD_SET_NOTIFICATION:
if (arg2)
string_to_bool(arg2, &setnotif);
if (setnotif && arg1 &&
(strcmp(arg1, "0") == 0 ||
strcmp(arg1, "1") == 0 ||
strcmp(arg1, "2") == 0)) {
ctx->in_notification = arg1;
ctx->setaction = VALUECHECK;
fault = dm_entry_set_notification(ctx);
} else {
fault = FAULT_9003;
}
break;
case CMD_INFORM:
dm_entry_inform(ctx);
break;
case CMD_ADD_OBJECT:
fault = dm_entry_add_object(ctx);
if (!fault) {
dmuci_set_value("cwmp", "acs", "ParameterKey", arg1 ? arg1 : "");
}
break;
case CMD_DEL_OBJECT:
fault = dm_entry_delete_object(ctx);
if (!fault) {
dmuci_set_value("cwmp", "acs", "ParameterKey", arg1 ? arg1 : "");
}
break;
}
dmuci_commit();
return fault;
}
int dm_entry_apply(struct dmctx *ctx, int cmd, char *arg1, char *arg2)
{
int fault = 0;
struct set_tmp *n, *p;
switch(cmd) {
case CMD_SET_VALUE:
ctx->setaction = VALUESET;
ctx->tree = false;
list_for_each_entry_safe(n, p, &ctx->set_list_tmp, list) {
ctx->in_param = n->name;
ctx->in_value = n->value ? n->value : "";
fault = dm_entry_set_value(ctx);
del_set_list_tmp(n);
if (fault) break;
}
if (fault) {
//Should not happen
dmuci_revert();
add_list_fault_param(ctx, ctx->in_param, fault);
} else {
dmuci_set_value("cwmp", "acs", "ParameterKey", arg1 ? arg1 : "");
dmuci_change_packages(&head_package_change);
dmuci_commit();
}
break;
case CMD_SET_NOTIFICATION:
ctx->setaction = VALUESET;
ctx->tree = false;
list_for_each_entry_safe(n, p, &ctx->set_list_tmp, list) {
ctx->in_param = n->name;
ctx->in_notification = n->value ? n->value : "0";
fault = dm_entry_set_notification(ctx);
del_set_list_tmp(n);
if (fault) break;
}
if (fault) {
//Should not happen
dmuci_revert();
} else {
dmuci_commit();
}
break;
}
return fault;
}
int cli_output_dm_result(struct dmctx *dmctx, int fault, int cmd, int out)
{
if (!out) return 0;
if (dmctx->list_fault_param.next != &dmctx->list_fault_param) {
struct param_fault *p;
list_for_each_entry(p, &dmctx->list_fault_param, list) {
fprintf (stdout, "{ \"parameter\": \"%s\", \"fault\": \"%d\" }\n", p->name, p->fault);
}
goto end;
}
if (fault) {
fprintf (stdout, "{ \"fault\": \"%d\" }\n", fault);
goto end;
}
if (cmd == CMD_ADD_OBJECT) {
if (dmctx->addobj_instance) {
fprintf (stdout, "{ \"status\": \"1\", \"instance\": \"%s\" }\n", dmctx->addobj_instance);
goto end;
} else {
fprintf (stdout, "{ \"fault\": \"%d\" }\n", FAULT_9002);
goto end;
}
}
if (cmd == CMD_DEL_OBJECT || cmd == CMD_SET_VALUE) {
fprintf (stdout, "{ \"status\": \"1\" }\n");
goto end;
}
if (cmd == CMD_SET_NOTIFICATION) {
fprintf (stdout, "{ \"status\": \"0\" }\n");
goto end;
}
struct dm_parameter *n;
if (cmd == CMD_GET_NAME) {
list_for_each_entry(n, &dmctx->list_parameter, list) {
fprintf (stdout, "{ \"parameter\": \"%s\", \"writable\": \"%s\" }\n", n->name, n->data);
}
}
else if (cmd == CMD_GET_NOTIFICATION) {
list_for_each_entry(n, &dmctx->list_parameter, list) {
fprintf (stdout, "{ \"parameter\": \"%s\", \"notification\": \"%s\" }\n", n->name, n->data);
}
}
else if (cmd == CMD_GET_VALUE || cmd == CMD_INFORM) {
list_for_each_entry(n, &dmctx->list_parameter, list) {
fprintf (stdout, "{ \"parameter\": \"%s\", \"value\": \"%s\", \"type\": \"%s\" }\n", n->name, n->data, n->type);
}
}
end:
return 0;
}
void dm_entry_cli(int argc, char** argv)
{
struct dmctx cli_dmctx = {0};
int output = 1;
dm_global_init();
dm_ctx_init(&cli_dmctx);
if (argc < 4) goto invalid_arguments;
output = atoi(argv[2]);
char *cmd = argv[3];
char *param, *next_level, *parameter_key, *value;
int fault = 0, status = -1;
/* GET NAME */
if (strcmp(cmd, "get_name") == 0) {
if (argc < 6) goto invalid_arguments;
param =argv[4];
next_level =argv[5];
fault = dm_entry_param_method(&cli_dmctx, CMD_GET_NAME, param, next_level, NULL);
cli_output_dm_result(&cli_dmctx, fault, CMD_GET_NAME, output);
}
/* GET VALUE */
else if (strcmp(cmd, "get_value") == 0) {
if (argc < 5) goto invalid_arguments;
param =argv[4];
fault = dm_entry_param_method(&cli_dmctx, CMD_GET_VALUE, param, NULL, NULL);
cli_output_dm_result(&cli_dmctx, fault, CMD_GET_VALUE, output);
}
/* GET NOTIFICATION */
else if (strcmp(cmd, "get_notification") == 0) {
if (argc < 5) goto invalid_arguments;
param =argv[4];
fault = dm_entry_param_method(&cli_dmctx, CMD_GET_NOTIFICATION, param, NULL, NULL);
cli_output_dm_result(&cli_dmctx, fault, CMD_GET_NOTIFICATION, output);
}
/* SET VALUE */
else if (strcmp(cmd, "set_value") == 0) {
if (argc < 7 || (argc % 2) == 0) goto invalid_arguments;
int i;
for (i=5; i<argc; i++) {
param = argv[i];
value = argv[i+1];
dm_entry_param_method(&cli_dmctx, CMD_SET_VALUE, param, value, NULL);
}
parameter_key = argv[4];
fault = dm_entry_apply(&cli_dmctx, CMD_SET_VALUE, parameter_key, NULL);
cli_output_dm_result(&cli_dmctx, fault, CMD_SET_VALUE, output);
}
/* SET NOTIFICATION */
else if (strcmp(cmd, "set_notification") == 0) {
if (argc < 6 || (argc % 2) != 0) goto invalid_arguments;
int i;
for (i=4; i<argc; i++) {
param = argv[i];
value = argv[i+1];
dm_entry_param_method(&cli_dmctx, CMD_SET_NOTIFICATION, param, value, "1");
}
fault = dm_entry_apply(&cli_dmctx, CMD_SET_NOTIFICATION, NULL, NULL);
cli_output_dm_result(&cli_dmctx, fault, CMD_SET_NOTIFICATION, output);
}
/* ADD OBJECT */
else if (strcmp(cmd, "add_object") == 0) {
if (argc < 6) goto invalid_arguments;
param =argv[5];
parameter_key =argv[4];
fault = dm_entry_param_method(&cli_dmctx, CMD_ADD_OBJECT, param, parameter_key, NULL);
cli_output_dm_result(&cli_dmctx, fault, CMD_ADD_OBJECT, output);
}
/* DEL OBJECT */
else if (strcmp(cmd, "delete_object") == 0) {
if (argc < 6) goto invalid_arguments;
param =argv[5];
parameter_key =argv[4];
fault = dm_entry_param_method(&cli_dmctx, CMD_DEL_OBJECT, param, parameter_key, NULL);
cli_output_dm_result(&cli_dmctx, fault, CMD_DEL_OBJECT, output);
}
/* INFORM */
else if (strcmp(cmd, "inform") == 0) {
fault = dm_entry_param_method(&cli_dmctx, CMD_INFORM, "", NULL, NULL);
cli_output_dm_result(&cli_dmctx, fault, CMD_INFORM, output);
}
else {
goto invalid_arguments;
}
dm_ctx_clean(&cli_dmctx);
dm_global_clean();
return;
invalid_arguments:
dm_ctx_clean(&cli_dmctx);
dm_global_clean();
fprintf(stdout, "Invalid arguments!\n");;
}
int cli_output_wepkey64(char strk64[4][11])
{
fprintf(stdout, "%s\n%s\n%s\n%s\n", strk64[0], strk64[1], strk64[2], strk64[3]);
return 0;
}
int cli_output_wepkey128(char strk128[27])
{
fprintf(stdout, "%s\n", strk128);
return 0;
}
void wepkey_cli(int argc, char** argv)
{
if (argc < 4) goto invalid_arguments;
char *strength = argv[2];
char *passphrase = argv[3];
if (!strength || !passphrase || passphrase[0] == '\0')
goto invalid_arguments;
if (strcmp(strength, "64") == 0) {
char strk64[4][11];
wepkey64(passphrase, strk64);
cli_output_wepkey64(strk64);
}
else if (strcmp(strength, "128") == 0) {
char strk128[27];
wepkey128(passphrase, strk128);
cli_output_wepkey128(strk128);
}
else {
goto invalid_arguments;
}
return;
invalid_arguments:
fprintf(stdout, "Invalid arguments!\n");;
}

14
dm/dmentry.h Normal file
View file

@ -0,0 +1,14 @@
#ifndef __DMENTRY_H__
#define __DMENTRY_H__
#include "dmcwmp.h"
extern struct list_head head_package_change;
int dm_global_init(void);
int dm_ctx_init(struct dmctx *ctx);
int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1, char *arg2);
int dm_entry_apply(struct dmctx *ctx, int cmd, char *arg1, char *arg2);
int dm_ctx_clean(struct dmctx *ctx);
int dm_global_clean(void);
void dm_entry_cli(int argc, char** argv);
void wepkey_cli(int argc, char** argv);
#endif

128
dm/dmmem.c Normal file
View file

@ -0,0 +1,128 @@
#include "dmmem.h"
#ifdef WITH_MEMLEACKSEC
LIST_HEAD(memhead);
inline void *__dmmalloc
(
#ifdef WITH_MEMTRACK
const char *file, const char *func, int line,
#endif /*WITH_MEMTRACK*/
size_t size
)
{
struct dmmem *m = malloc(sizeof(struct dmmem) + size);
if (m == NULL) return NULL;
list_add(&m->list, &memhead);
#ifdef WITH_MEMTRACK
m->file = (char *)file;
m->func = (char *)func;
m->line = line;
#endif /*WITH_MEMTRACK*/
return (void *)m->mem;
}
inline void *__dmcalloc
(
#ifdef WITH_MEMTRACK
const char *file, const char *func, int line,
#endif /*WITH_MEMTRACK*/
int n, size_t size
)
{
struct dmmem *m = calloc(n, sizeof(struct dmmem) + size);
if (m == NULL) return NULL;
list_add(&m->list, &memhead);
#ifdef WITH_MEMTRACK
m->file = (char *)file;
m->func = (char *)func;
m->line = line;
#endif /*WITH_MEMTRACK*/
return (void *)m->mem;
}
inline void dmfree(void *m)
{
if (m == NULL) return;
struct dmmem *rm;
rm = container_of(m, struct dmmem, mem);
list_del(&rm->list);
free(rm);
}
void dmcleanmem()
{
struct dmmem *dmm;
while (memhead.next != &memhead) {
dmm = list_entry(memhead.next, struct dmmem, list);
#ifdef WITH_MEMTRACK
fprintf(stderr, "Allocated memory in {%s, %s(), line %d} is not freed\n", dmm->file, dmm->func, dmm->line);
#endif /*WITH_MEMTRACK*/
list_del(&dmm->list);
free(dmm);
}
}
char *__dmstrdup
(
#ifdef WITH_MEMTRACK
const char *file, const char *func, int line,
#endif /*WITH_MEMTRACK*/
const char *s
)
{
size_t len = strlen(s) + 1;
#ifdef WITH_MEMTRACK
void *new = __dmmalloc(file, func, line, len);
#else
void *new = __dmmalloc(len);
#endif /*WITH_MEMTRACK*/
if (new == NULL) return NULL;
return (char *) memcpy(new, s, len);
}
#endif /*WITH_MEMLEACKSEC*/
int __dmasprintf
(
#ifdef WITH_MEMTRACK
const char *file, const char *func, int line,
#endif /*WITH_MEMTRACK*/
char **s, const char *format, ...
)
{
char buf[512];
va_list arg;
int ret;
va_start(arg,format);
ret = vsprintf(buf, format, arg);
va_end(arg);
#ifdef WITH_MEMTRACK
*s = __dmstrdup(file, func, line, buf);
#else
*s = __dmstrdup(buf);
#endif /*WITH_MEMTRACK*/
if (*s == NULL) return -1;
return 0;
}
int __dmastrcat
(
#ifdef WITH_MEMTRACK
const char *file, const char *func, int line,
#endif /*WITH_MEMTRACK*/
char **s, char *obj, char *lastname
)
{
char buf[512];
int olen = strlen(obj);
memcpy(buf, obj, olen);
int llen = strlen(lastname) + 1;
memcpy(buf + olen, lastname, llen);
#ifdef WITH_MEMTRACK
*s = __dmstrdup(file, func, line, buf);
#else
*s = __dmstrdup(buf);
#endif /*WITH_MEMTRACK*/
if (*s == NULL) return -1;
return 0;
}

99
dm/dmmem.h Normal file
View file

@ -0,0 +1,99 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <libubox/list.h>
#ifndef __DMMEM_H
#define __DMMEM_H
static inline void dm_empty_func()
{
}
#define WITH_MEMLEACKSEC 1
//#define WITH_MEMTRACK 1
#ifndef WITH_MEMLEACKSEC
#undef WITH_MEMTRACK
#endif
#ifdef WITH_MEMLEACKSEC
struct dmmem {
struct list_head list;
#ifdef WITH_MEMTRACK
char *file;
char *func;
int line;
#endif /*WITH_MEMTRACK*/
char mem[0];
};
inline void *__dmmalloc
(
#ifdef WITH_MEMTRACK
const char *file, const char *func, int line,
#endif /*WITH_MEMTRACK*/
size_t size
);
inline void *__dmcalloc
(
#ifdef WITH_MEMTRACK
const char *file, const char *func, int line,
#endif /*WITH_MEMTRACK*/
int n, size_t size
);
char *__dmstrdup
(
#ifdef WITH_MEMTRACK
const char *file, const char *func, int line,
#endif /*WITH_MEMTRACK*/
const char *s
);
inline void dmfree(void *m);
void dmcleanmem();
#endif /*WITH_MEMLEACKSEC*/
int __dmasprintf
(
#ifdef WITH_MEMTRACK
const char *file, const char *func, int line,
#endif /*WITH_MEMTRACK*/
char **s, const char *format, ...
);
int __dmastrcat
(
#ifdef WITH_MEMTRACK
const char *file, const char *func, int line,
#endif /*WITH_MEMTRACK*/
char **s, char *obj, char *lastname
);
#ifdef WITH_MEMLEACKSEC
#ifdef WITH_MEMTRACK
#define dmmalloc(x) __dmmalloc(__FILE__, __func__, __LINE__, x)
#define dmcalloc(n, x) __dmcalloc(__FILE__, __func__, __LINE__, n, x)
#define dmstrdup(x) __dmstrdup(__FILE__, __func__, __LINE__, x)
#define dmasprintf(s, format, ...) __dmasprintf(__FILE__, __func__, __LINE__, s, format, ## __VA_ARGS__)
#define dmastrcat(s, b, m) __dmastrcat(__FILE__, __func__, __LINE__, s, b, m)
#else
#define dmmalloc(x) __dmmalloc(x)
#define dmcalloc(n, x) __dmcalloc(n, x)
#define dmstrdup(x) __dmstrdup(x)
#define dmasprintf(s, format, ...) __dmasprintf(s, format, ## __VA_ARGS__)
#define dmastrcat(s, b, m) __dmastrcat(s, b, m)
#endif /*WITH_MEMTRACK*/
#else
#define dmmalloc(x) malloc(x)
#define dmcalloc(n, x) calloc(n, x)
#define __dmstrdup(x) strdup(x)
#define dmstrdup(x) strdup(x)
#define dmasprintf(s, format, ...) __dmasprintf(s, format, ## __VA_ARGS__)
#define dmastrcat(s, b, m) __dmastrcat(s, b, m)
#define dmfree(x) free(x)
#define dmcleanmem() dm_empty_func()
#endif /*WITH_MEMLEACKSEC*/
#define DMFREE(x) do { dmfree(x); x = NULL; } while (0);
#endif

237
dm/dmtree/deviceinfo.c Normal file
View file

@ -0,0 +1,237 @@
/*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2012-2014 PIVA SOFTWARE (www.pivasoftware.com)
* Author: Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author: Feten Besbes <feten.besbes@pivasoftware.com>
*/
#include <ctype.h>
#include <uci.h>
#include <stdio.h>
#include "dmcwmp.h"
#include "dmuci.h"
#include "dmubus.h"
#include "dmcommon.h"
#include "deviceinfo.h"
char *get_deviceid_manufacturer()
{
char *v;
dmuci_get_option_value_string("cwmp","cpe","manufacturer", &v);
return v;
}
char *get_deviceid_manufactureroui()
{
FILE* f = NULL;
char *v;
char str[TAILLE_MAX];
f = fopen(BASE_MAC_ADDR, "r");
if (f != NULL)
{
fgets(str, TAILLE_MAX, f);
size_t ln = strlen(str);
if (ln<9) goto not_found;
str[2] = str[3];
str[3] = str[4];
str[4] = str[6];
str[5] = str[7];
str[6] = '\0';
v = dmstrdup(str);
fclose(f);
return v;
}
not_found:
v = dmstrdup("");
return v;
}
char *get_deviceid_productclass()
{
char *v;
db_get_value_string("hw", "board", "iopVersion", &v);
return v;
}
char *get_deviceid_serialnumber()
{
char *v;
db_get_value_string("hw", "board", "serialNumber", &v);
return v;
}
char *get_softwareversion()
{
char *v;
db_get_value_string("hw", "board", "iopVersion", &v);
return v;
}
int get_device_manufacturer(char *refparam, struct dmctx *ctx, char **value)
{
*value = get_deviceid_manufacturer();
return 0;
}
int get_device_manufactureroui(char *refparam, struct dmctx *ctx, char **value)
{
*value = get_deviceid_manufactureroui();
return 0;
}
int get_device_productclass(char *refparam, struct dmctx *ctx, char **value)
{
*value = get_deviceid_productclass();
return 0;
}
int get_device_serialnumber(char *refparam, struct dmctx *ctx, char **value)
{
*value = get_deviceid_serialnumber();
return 0;
}
int get_device_softwareversion(char *refparam, struct dmctx *ctx, char **value)
{
*value = get_softwareversion();
return 0;
}
int get_device_hardwareversion(char *refparam, struct dmctx *ctx, char **value)
{
db_get_value_string("hw", "board", "hardwareVersion", value);
return 0;
}
int get_device_routermodel(char *refparam, struct dmctx *ctx, char **value)
{
db_get_value_string("hw", "board", "routerModel", value);
return 0;
}
int get_device_info_uptime(char *refparam, struct dmctx *ctx, char **value)
{
FILE* fp = NULL;
char wpakey[TAILLE_MAX];
fp = fopen("UPTIME", "r");
if (fp != NULL) {
fgets(wpakey, TAILLE_MAX, fp);
*value = dmstrdup(cut_fx(wpakey, ".", 1));
fclose(fp);
}
return 0;
}
int get_device_devicelog (char *refparam, struct dmctx *ctx, char **value)
{
*value = dmstrdup("TOCODE");
return 0;
}
int get_device_specversion(char *refparam, struct dmctx *ctx, char **value)
{
TRACE();
dmuci_get_option_value_string("cwmp", "cpe", "specversion", value);
TRACE();
if ((*value)[0] == '\0') {
dmfree(*value);
*value = dmstrdup("1.0");
}
return 0;
}
int get_device_provisioningcode(char *refparam, struct dmctx *ctx, char **value)
{
dmuci_get_option_value_string("cwmp", "cpe", "provisioning_code", value);
return 0;
}
int set_device_provisioningcode(char *refparam, struct dmctx *ctx, int action, char *value)
{
bool b;
switch (action) {
VALUECHECK:
if (string_to_bool(value, &b))
return FAULT_9007;
return 0;
VALUESET:
dmuci_set_value("cwmp", "cpe", "provisioning_code", value);
}
return 0;
}
int get_base_mac_addr(char *refparam, struct dmctx *ctx, char **value)
{
json_object *res;
dmubus_call("router", "info", UBUS_ARGS{{}}, 0, &res);
DM_ASSERT(res, *value = dmstrdup(""));
json_select(res, "system", 0, "basemac", value, NULL);
return 0;
}
int get_catv_enabled(char *refparam, struct dmctx *ctx, char **value)
{
char *catv;
dmuci_get_option_value_string("catv", "catv", "enable", &catv);
if (strcmp(catv, "on") == 0) {
dmfree(catv);
*value = dmstrdup("1");
}
else if (strcmp(catv, "off") == 0) {
dmfree(catv);
*value = dmstrdup("0");
}
else
*value = dmstrdup("");
return 0;
}
int set_device_catvenabled(char *refparam, struct dmctx *ctx, int action, char *value)
{
bool b;
char *stat = "";
switch (action) {
VALUECHECK:
if (string_to_bool(value, &b))
return FAULT_9007;
return 0;
VALUESET:
if (value[0] != '\0') {
if (value[0] == '1')
stat = dmstrdup("on");
else
stat = dmstrdup("off");
}
dmuci_set_value("catv", "catv", "enable", stat);
//delay_service restart "catv" "1"
}
return 0;
}
int entry_method_root_DeviceInfo(struct dmctx *ctx)
{
IF_MATCH(ctx, DMROOT"DeviceInfo.") {
DMOBJECT(DMROOT"DeviceInfo.", ctx, "0", 0, NULL, NULL, NULL);
DMPARAM("Manufacturer", ctx, "0", get_device_manufacturer, NULL, "", 1, 0, UNDEF, NULL);
DMPARAM("ManufacturerOUI", ctx, "0", get_device_manufactureroui, NULL, "", 1, 0, UNDEF, NULL);
DMPARAM("ModelName", ctx, "0", get_device_routermodel, NULL, "", 1, 0, UNDEF, NULL);
DMPARAM("ProductClass", ctx, "0", get_device_productclass, NULL, "xsd:boolean", 1, 0, UNDEF, NULL);
DMPARAM("SerialNumber", ctx, "0", get_device_serialnumber, NULL, "", 1, 0, UNDEF, NULL);
DMPARAM("HardwareVersion", ctx, "0", get_device_hardwareversion, NULL, "xsd:boolean", 1, 0, UNDEF, NULL);
DMPARAM("SoftwareVersion", ctx, "0", get_device_softwareversion, NULL, "xsd:boolean", 1, 0, UNDEF, NULL);
DMPARAM("UpTime", ctx, "0", get_device_info_uptime, NULL, "", 1, 0, UNDEF, NULL);
DMPARAM("DeviceLog", ctx, "0", get_device_devicelog, NULL, "", 1, 0, UNDEF, NULL);
DMPARAM("SpecVersion", ctx, "0", get_device_specversion, NULL, "", 1, 0, UNDEF, NULL);
DMPARAM("ProvisioningCode", ctx, "1", get_device_provisioningcode, set_device_provisioningcode, "", 1, 0, UNDEF, NULL);
DMPARAM("X_INTENO_SE_BaseMacAddr", ctx, "0", get_base_mac_addr, NULL, "", 1, 0, UNDEF, NULL);
DMPARAM("X_INTENO_SE_CATVEnabled", ctx, "1", get_catv_enabled, set_device_catvenabled, "", 1, 0, UNDEF, NULL);
return 0;
}
return FAULT_9005;
}

43
dm/dmtree/deviceinfo.h Normal file
View file

@ -0,0 +1,43 @@
/*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2012-2014 PIVA SOFTWARE (www.pivasoftware.com)
* Author: Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author: Feten Besbes <feten.besbes@pivasoftware.com>
* Author: Anis Ellouze <anis.ellouze@pivasoftware.com>
*/
#ifndef __DEVICE_INFO_H
#define __DEVICE_INFO_H
#include "dmcwmp.h"
#define BASE_MAC_ADDR "/proc/nvram/BaseMacAddr"
#define UPTIME "/proc/uptime"
char *get_deviceid_manufacturer();
char *get_deviceid_manufactureroui();
char *get_deviceid_productclass();
char *get_deviceid_serialnumber();
char *get_softwareversion();
int get_spec_version(char *refparam, struct dmctx *ctx, char **value);
int get_device_manufacturer(char *refparam, struct dmctx *ctx, char **value);
int get_device_manufactureroui(char *refparam, struct dmctx *ctx, char **value);
int get_device_routermodel(char *refparam, struct dmctx *ctx, char **value);
int get_device_productclass(char *refparam, struct dmctx *ctx, char **value);
int get_device_serialnumber(char *refparam, struct dmctx *ctx, char **value);
int get_device_hardwareversion(char *refparam, struct dmctx *ctx, char **value);
int get_device_softwareversion(char *refparam, struct dmctx *ctx, char **value);
int get_device_info_uptime(char *refparam, struct dmctx *ctx, char **value);
int get_device_devicelog (char *refparam, struct dmctx *ctx, char **value);
int get_device_specversion(char *refparam, struct dmctx *ctx, char **value);
int get_device_provisioningcode(char *refparam, struct dmctx *ctx, char **value);
int set_device_provisioningcode(char *refparam, struct dmctx *ctx, int action, char *value);
int get_base_mac_addr(char *refparam, struct dmctx *ctx, char **value);
int get_catv_enabled(char *refparam, struct dmctx *ctx, char **value);
int set_device_catvenabled(char *refparam, struct dmctx *ctx, int action, char *value);
int entry_method_root_DeviceInfo(struct dmctx *ctx);
#endif

2636
dm/dmtree/landevice.c Normal file

File diff suppressed because it is too large Load diff

146
dm/dmtree/landevice.h Normal file
View file

@ -0,0 +1,146 @@
/*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2012-2014 PIVA SOFTWARE (www.pivasoftware.com)
* Author: Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author: Feten Besbes <feten.besbes@pivasoftware.com>
*/
#ifndef __LAN_DEVICE_H
#define __LAN_DEVICE_H
#include <libubox/blobmsg_json.h>
#include <json/json.h>
#define NVRAM_FILE "/proc/nvram/WpaKey"
inline int init_ldargs_dhcp(struct dmctx *ctx, struct uci_section *s);
inline int init_ldargs_wlan(struct dmctx *ctx, struct uci_section *s, int wlctl_num, char *wunit, int pki);
inline int init_ldargs_eth_cfg(struct dmctx *ctx, char *eth);
inline int init_ldargs_ip(struct dmctx *ctx, struct uci_section *s);
inline int init_ldargs_lan(struct dmctx *ctx, struct uci_section *s);
int ip_to_int(char *address);
int reset_wlan(struct uci_section *s);
int get_lan_dns(char *refparam, struct dmctx *ctx, char **value);
int set_lan_dns(char *refparam, struct dmctx *ctx, int action, char *value);
int get_lan_dhcp_server_configurable(char *refparam, struct dmctx *ctx, char **value);
int set_lan_dhcp_server_configurable(char *refparam, struct dmctx *ctx, int action, char *value);
int get_lan_dhcp_server_enable(char *refparam, struct dmctx *ctx, char **value);
int set_lan_dhcp_server_enable(char *refparam, struct dmctx *ctx, int action, char *value);
int get_lan_dhcp_interval_address_start(char *refparam, struct dmctx *ctx, char **value);
int set_lan_dhcp_address_start(char *refparam, struct dmctx *ctx, int action, char *value);
int get_lan_dhcp_interval_address_end(char *refparam, struct dmctx *ctx, char **value);
int set_lan_dhcp_address_end(char *refparam, struct dmctx *ctx, int action, char *value);
int get_lan_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, char **value);
int set_lan_dhcp_reserved_addresses(char *refparam, struct dmctx *ctx, int action, char *value);
int get_lan_dhcp_subnetmask(char *refparam, struct dmctx *ctx, char **value);
int set_lan_dhcp_subnetmask(char *refparam, struct dmctx *ctx, int action, char *value);
int get_lan_dhcp_iprouters(char *refparam, struct dmctx *ctx, char **value);
int set_lan_dhcp_iprouters(char *refparam, struct dmctx *ctx, int action, char *value);
int get_lan_dhcp_leasetime(char *refparam, struct dmctx *ctx, char **value);
int set_lan_dhcp_leasetime(char *refparam, struct dmctx *ctx, int action, char *value);
int get_lan_dhcp_domainname(char *refparam, struct dmctx *ctx, char **value);
int set_lan_dhcp_domainname(char *refparam, struct dmctx *ctx, int action, char *value);
int get_lan_host_nbr_entries(char *refparam, struct dmctx *ctx, char **value);
int filter_lan_device_interface(struct uci_section *s, void *v);
int filter_lan_ip_interface(struct uci_section *ss, void *v);
int filter_is_dhcp_interface(struct uci_section *s, char *str); ////SEE IF USED
/**landevice_lanhostconfigmanagement_ipinterface**/
char *json_parse_string(json_object *jobj, char *key_val);
int get_interface_enable_ubus (char *refparam, struct dmctx *ctx, char **value);
int set_interface_enable_ubus(char *refparam, struct dmctx *ctx, int action, char *value);
int get_interface_firewall_enabled(char *refparam, struct dmctx *ctx, char **value);
struct uci_section *create_firewall_zone_config(char *fwl, char *iface, char *input, char *forward, char *output);
int set_interface_firewall_enabled(char *refparam, struct dmctx *ctx, int action, char *value);
int get_interface_ipaddress (char *refparam, struct dmctx *ctx, char **value);
int set_interface_ipaddress(char *refparam, struct dmctx *ctx, int action, char *value);
int get_interface_subnetmask (char *refparam, struct dmctx *ctx, char **value);
int set_interface_subnetmask(char *refparam, struct dmctx *ctx, int action, char *value);
int get_interface_addressingtype (char *refparam, struct dmctx *ctx, char **value);
int set_interface_addressingtype(char *refparam, struct dmctx *ctx, int action, char *value);
int get_dhcpstaticaddress_enable (char *refparam, struct dmctx *ctx, char **value);
int set_dhcpstaticaddress_enable(char *refparam, struct dmctx *ctx, int action, char *value);
int get_dhcpstaticaddress_chaddr(char *refparam, struct dmctx *ctx, char **value);
int set_dhcpstaticaddress_chaddr(char *refparam, struct dmctx *ctx, int action, char *value);
int get_dhcpstaticaddress_yiaddr(char *refparam, struct dmctx *ctx, char **value);
int set_dhcpstaticaddress_yiaddr(char *refparam, struct dmctx *ctx, int action, char *value);
int entry_method_root_LANDevice(struct dmctx *ctx);
int get_wlan_enable (char *refparam, struct dmctx *ctx, char **value);
int set_wlan_enable(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wlan_status (char *refparam, struct dmctx *ctx, char **value);
int get_wlan_bssid (char *refparam, struct dmctx *ctx, char **value);
int get_wlan_max_bit_rate (char *refparam, struct dmctx *ctx, char **value);
int set_wlan_max_bit_rate(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wlan_channel(char *refparam, struct dmctx *ctx, char **value);
int set_wlan_channel(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wlan_auto_channel_enable(char *refparam, struct dmctx *ctx, char **value);
int set_wlan_auto_channel_enable(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wlan_ssid(char *refparam, struct dmctx *ctx, char **value);
int set_wlan_ssid(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wlan_beacon_type(char *refparam, struct dmctx *ctx, char **value);
int set_wlan_beacon_type(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wlan_mac_control_enable(char *refparam, struct dmctx *ctx, char **value);
int set_wlan_mac_control_enable(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wlan_standard(char *refparam, struct dmctx *ctx, char **value);
int set_wlan_standard(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wlan_wep_key_index(char *refparam, struct dmctx *ctx, char **value);
int set_wlan_wep_key_index(char *refparam, struct dmctx *ctx, int action, char *value);
int set_wlan_key_passphrase(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wlan_wep_encryption_level(char *refparam, struct dmctx *ctx, char **value);
int get_wlan_basic_encryption_modes(char *refparam, struct dmctx *ctx, char **value);
int set_wlan_basic_encryption_modes(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wlan_basic_authentication_mode(char *refparam, struct dmctx *ctx, char **value);
int set_wlan_basic_authentication_mode(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wlan_wpa_encryption_modes(char *refparam, struct dmctx *ctx, char **value);
int set_wlan_wpa_encryption_modes(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wlan_wpa_authentication_mode(char *refparam, struct dmctx *ctx, char **value);
int set_wlan_wpa_authentication_mode(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wlan_ieee_11i_encryption_modes(char *refparam, struct dmctx *ctx, char **value);
int set_wlan_ieee_11i_encryption_modes(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wlan_ieee_11i_authentication_mode(char *refparam, struct dmctx *ctx, char **value);
int set_wlan_ieee_11i_authentication_mode(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wlan_radio_enabled(char *refparam, struct dmctx *ctx, char **value);
int set_wlan_radio_enabled(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wlan_device_operation_mode(char *refparam, struct dmctx *ctx, char **value);
int set_wlan_device_operation_mode(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wlan_authentication_service_mode(char *refparam, struct dmctx *ctx, char **value);
int set_wlan_authentication_service_mode(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wlan_total_associations(char *refparam, struct dmctx *ctx, char **value);
int get_wlan_devstatus_statistics_tx_bytes(char *refparam, struct dmctx *ctx, char **value);
int get_wlan_devstatus_statistics_rx_bytes(char *refparam, struct dmctx *ctx, char **value);
int get_wlan_devstatus_statistics_tx_packets(char *refparam, struct dmctx *ctx, char **value);
int get_wlan_devstatus_statistics_rx_packets(char *refparam, struct dmctx *ctx, char **value);
int get_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, char **value);
int set_wlan_ssid_advertisement_enable(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wlan_wps_enable(char *refparam, struct dmctx *ctx, char **value);
int set_wlan_wps_enable(char *refparam, struct dmctx *ctx, int action, char *value);
int get_x_inteno_se_channelmode(char *refparam, struct dmctx *ctx, char **value);
int set_x_inteno_se_channelmode(char *refparam, struct dmctx *ctx, int action, char *value);
int get_x_inteno_se_supported_standard(char *refparam, struct dmctx *ctx, char **value);
int get_x_inteno_se_operating_channel_bandwidth(char *refparam, struct dmctx *ctx, char **value);
int set_x_inteno_se_operating_channel_bandwidth(char *refparam, struct dmctx *ctx, int action, char *value);
int get_x_inteno_se_maxssid(char *refparam, struct dmctx *ctx, char **value);
int set_x_inteno_se_maxssid(char *refparam, struct dmctx *ctx, int action, char *value);
int set_wlan_wep_key(char *refparam, struct dmctx *ctx, int action, char *value);
inline int get_landevice_lanhostconfigmanagement_ipinterface (struct dmctx *ctx, char *idev, char *ilan);
inline int get_landevice_lanhostconfigmanagement_dhcpstaticaddress(struct dmctx *ctx, char *idev, char *idhcp);
inline int get_landevice_wlanconfiguration_generic(struct dmctx *ctx, char *idev,char *iwlan);
/**landevice_wlanconfiguration_presharedkey**/
inline int get_landevice_wlanconfiguration_presharedkey(struct dmctx *ctx, int pki, char *idev, char *iwlan);
int set_wlan_pre_shared_key(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wlan_psk_assoc_MACAddress(char *refparam, struct dmctx *ctx, char **value);
//*get_landevice_ethernet_interface_config **/
int get_lan_ethernet_interfaces(char *ndev, char *iface[], int taille, int *length);
int get_lan_eth_iface_cfg_enable(char *refparam, struct dmctx *ctx, char **value);
int set_lan_eth_iface_cfg_enable(char *refparam, struct dmctx *ctx, int action, char *value);
int get_lan_eth_iface_cfg_status(char *refparam, struct dmctx *ctx, char **value);
int get_lan_eth_iface_cfg_maxbitrate(char *refparam, struct dmctx *ctx, char **value);
int set_lan_eth_iface_cfg_maxbitrate(char *refparam, struct dmctx *ctx, int action, char *value);
int get_lan_eth_iface_cfg_duplexmode(char *refparam, struct dmctx *ctx, char **value);
int set_lan_eth_iface_cfg_duplexmode(char *refparam, struct dmctx *ctx, int action, char *value);
int get_lan_eth_iface_cfg_stats_tx_bytes(char *refparam, struct dmctx *ctx, char **value);
int get_lan_eth_iface_cfg_stats_rx_bytes(char *refparam, struct dmctx *ctx, char **value);
int get_lan_eth_iface_cfg_stats_tx_packets(char *refparam, struct dmctx *ctx, char **value);
int get_lan_eth_iface_cfg_stats_rx_packets(char *refparam, struct dmctx *ctx, char **value);
inline int get_landevice_ethernet_interface_config( struct dmctx *ctx, char *idev, char *ieth);
#endif

View file

@ -0,0 +1,399 @@
/*
* Copyright (C) 2013-2015 Inteno Broadband Technology AB
* Author: Anis Ellouze <anis.ellouze@pivasoftware.com>
*/
#include "dmcwmp.h"
#include "dmuci.h"
#include "dmmem.h"
#include "dmubus.h"
#include "dmcommon.h"
#include "layer_2_bridging.h"
#include <libubox/blobmsg_json.h>
#include <json/json.h>
struct wan_interface
{
int instance;
char *name;
char *package;
char *section;
};
struct args_layer2
{
struct uci_section *layer2section;
char *interface_type;
char *oface;
char *key;
};
struct wan_interface wan_interface_tab[3] = {
{1,"ethernet", "layer2_interface_ethernet", "ethernet_interface"},
{2,"adsl", "layer2_interface_adsl", "atm_bridge"},
{3,"vdsl", "layer2_interface_vdsl", "vdsl_interface"}
};
struct args_layer2 cur_args = {0};
inline void init_args_layer2(struct dmctx *ctx, struct uci_section *s, char *interface_type, char *key, char *oface) {
struct args_layer2 *args = &cur_args;
ctx->args = (void *)args;
args->layer2section = s;
args->interface_type = interface_type;
args->key = key;
args->oface = oface;
return ;
}
void remove_substring(char *s,const char *str_remove) {
while( s=strstr(s,str_remove) )
memmove(s,s+strlen(str_remove),1+strlen(s+strlen(str_remove)));
}
int get_marking_bridge_reference(char *refparam, struct dmctx *ctx, char **value) {
struct args_layer2 *args = (struct args_layer2 *)ctx->args;
dmuci_get_value_by_section_string(args->layer2section, "bridgekey", value);
return 0;
}
int set_marking_bridge_reference(char *refparam, struct dmctx *ctx, int action, char *value) {
char *old_bridge_key, *baseifname, *br_instance, *ifname,*vb=NULL;
struct uci_section *s = NULL;
struct args_layer2 *args = (struct args_layer2 *)ctx->args;
dmuci_get_value_by_section_string(args->layer2section, "bridgekey", &old_bridge_key);
dmuci_set_value_by_section(args->layer2section, "bridgekey", value);
dmuci_get_value_by_section_string(args->layer2section, "baseifname", &baseifname);
if(!strcmp(strndup(baseifname,3), "cfg")) {
uci_foreach_sections("network", "interface", s) {
dmuci_get_value_by_section_string(s, "bridge_instance", &br_instance);
if(!strcmp(br_instance, old_bridge_key)) {
dmuci_set_value("wireless", "baseifname", "network", s->e.name);
}
}
}
if(!strcmp(strndup(baseifname,3),"eth")) {
if(strcmp(baseifname+3,"0")) {
uci_foreach_sections("network", "interface", s) {
dmuci_get_value_by_section_string(args->layer2section, "bridge_instance", &br_instance);
if(!strcmp(br_instance, old_bridge_key)) {
dmuci_get_value_by_section_string(args->layer2section, "ifname", &ifname);
remove_substring(ifname, baseifname);
dmuci_set_value_by_section(s, "ifname", ifname);
}
}
}
else {
return;
}
}
return 0;
}
int get_marking_interface_key(char *refparam, struct dmctx *ctx, char **value) {
struct args_layer2 *args = (struct args_layer2 *)ctx->args;
dmuci_get_value_by_section_string(args->layer2section, "interfacekey", value);
return 0;
}
int set_marking_interface_key(char *refparam, struct dmctx *ctx, int action, char *value) {
struct args_layer2 *args = (struct args_layer2 *)ctx->args;
dmuci_set_value_by_section(args->layer2section, "interfacekey", value);
return 0;
}
int get_bridge_vlan_enable(char *refparam,struct dmctx *ctx, char **value) {
struct args_layer2 *args = (struct args_layer2 *)ctx->args;
dmuci_get_value_by_section_string(args->layer2section, "enable", value);
return 0;
}
int set_bridge_vlan_enable(char *refparam, struct dmctx *ctx, int action, char *value) {
char *vb=NULL;
bool b;
struct args_layer2 *args = (struct args_layer2 *)ctx->args;
dmuci_set_value_by_section(args->layer2section, "enable", value);
return 0;
}
int get_bridge_vlan_name(char *refparam, struct dmctx *ctx, char **value) {
struct args_layer2 *args = (struct args_layer2 *)ctx->args;
dmuci_get_value_by_section_string(args->layer2section, "name", value);
return 0;
}
int set_bridge_vlan_name(char *refparam, struct dmctx *ctx, int action, char *value) {
struct args_layer2 *args = (struct args_layer2 *)ctx->args;
dmuci_set_value_by_section(args->layer2section, "name", value);
return 0;
}
int get_bridge_vlan_vid(char *refparam, struct dmctx *ctx, char **value) {
struct args_layer2 *args = (struct args_layer2 *)ctx->args;
dmuci_get_value_by_section_string(args->layer2section, "vid", value);
return 0;
}
int set_bridge_vlan_vid(char *refparam, struct dmctx *ctx, int action, char **value) {
struct args_layer2 *args = (struct args_layer2 *)ctx->args;
dmuci_get_value_by_section_string(args->layer2section, "vid", value);
return 0;
}
int get_bridge_status(char *refparam, struct dmctx *ctx, char **value) {
#if 0
json_object *res;
struct args_layer2 *args = (struct args_layer2 *)ctx->args;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(args->layer2section)}}, 1, &res);
json_select(res, "up", 0, NULL, value, NULL);
#endif
*value = dmstrdup("up");
return 0;
}
int set_bridge_status(char *refparam, struct dmctx *ctx, int action, char *value) {
return 0;
}
int get_bridge_key(char *refparam, struct dmctx *ctx, char **value) {
struct args_layer2 *args = (struct args_layer2 *)ctx->args;
dmuci_get_value_by_section_string(args->layer2section, "bridge_instance", value);
return 0;
}
void set_bridge_key(char *refparam, struct dmctx *ctx, int action, char *value) {
return ;
}
int get_bridge_name(char *refparam, struct dmctx *ctx, char **value) {
struct args_layer2 *args = (struct args_layer2 *)ctx->args;
*value=dmstrdup(section_name(args->layer2section));
return 0;
}
int set_bridge_name(char *refparam, struct dmctx *ctx, int action, char *value) {
return 0;
}
int get_bridge_vlanid(char *refparam, struct dmctx *ctx, char **value) {
struct args_layer2 *args = (struct args_layer2 *)ctx->args;
*value = dmstrdup("");
return 0;
}
int set_bridge_vlanid(char *refparam, struct dmctx *ctx, int action, char *value) {
char **bridge_key;
char *instance=NULL;
char *vlan_bridge;
struct args_layer2 *args = (struct args_layer2 *)ctx->args;
if (instance == "") {
dmuci_set_value("dmmap", vlan_bridge, "bridgekey",value);
dmuci_set_value("dmmap", vlan_bridge,"dname",value);
}else {
return 0;
}
}
void get_associated_interfaces(char *refparam, struct dmctx *ctx, char **value) {
struct args_layer2 *args = (struct args_layer2 *)ctx->args;
dmuci_get_value_by_section_string(args->layer2section, "ifname", value);
}
void set_associated_interfaces(char *refparam, struct dmctx *ctx, int action, char *value) {
struct args_layer2 *args = (struct args_layer2 *)ctx->args;
dmuci_set_value_by_section(args->layer2section, "ifname", value);
}
int get_available_interface_key(char *refparam, struct dmctx *ctx, char **value) {
dmuci_get_option_value_string("dmmap", "available-bridge", "key", value);
return 0;
}
void set_available_interface_key() {
return;
}
int get_interface_reference(char *refparam, struct dmctx *ctx, char **value) {
struct args_layer2 *args = (struct args_layer2 *)ctx->args;
*value = dmstrdup(args->oface);
return 0;
}
void set_interface_reference(char *refparam, struct dmctx *ctx, int action, char *value) {
return;
}
int get_interface_type(char *refparam, struct dmctx *ctx, char **value) {
struct args_layer2 *args = (struct args_layer2 *)ctx->args;
*value = dmstrdup(args->interface_type);
return 0;
}
void set_interface_type(char *refparam, struct dmctx *ctx, int action, char *value) {
return;
}
int update_availableinterface_list(char *iface, char **value) {
struct uci_section *s = NULL;
char *key;
int key_int;
int new_key=0;
char *new_key_str;
uci_foreach_option_eq("dmmap", "available-bridge", "baseifname", iface, s) {
if (s != NULL) {
dmuci_get_value_by_section_string(s, "instance", value);
return 0;
}
}
uci_foreach_sections("dmmap", "available-bridge",s) {
if (s != NULL) {
dmuci_get_value_by_section_string(s, "instance", value);
key=strdup(*value);
if(key=="")
new_key=1;
else {
int key_int=atoi(key);
if(key_int>new_key)
new_key=key_int;
}
}
}
dmasprintf(value,"%d",new_key+1);
return 0;
}
void update_instances(char *package, char *stype, char *inst_opt, char *last_inst, struct uci_section *s, char **value) {
dmuci_get_value_by_section_string(s, inst_opt, value);
char buf[8] = {0};
if (*value[0] == '\0') {
if (last_inst == NULL)
sprintf(buf, "%d", 1);
else
sprintf(buf, "%d", atoi(last_inst)+1);
dmfree(*value);
*value = dmuci_set_value_by_section(s, inst_opt, buf);
}
return ;
}
inline int get_marking_bridge(struct dmctx *ctx, char *marking_br, char *marking_br_instance) {
DMOBJECT(DMROOT"Layer2Bridging.Marking.%s.", ctx, "1", NULL, NULL, NULL, NULL, marking_br_instance);
DMPARAM("MarkingBridgeReference", ctx, "1", get_marking_bridge_reference, set_marking_bridge_reference, "xsd:boolean", "0", 0, 0, NULL);
DMPARAM("MarkingInterface", ctx, "1", get_marking_interface_key, set_marking_interface_key, "xsd:boolean", "0", 0, 0, NULL);
return 0;
}
inline int get_bridge_vlan(struct dmctx *ctx,char *bridge_instance, char *vlan_instance , char *section_name) {
DMOBJECT(DMROOT"InternetGatewayDevice.Layer2Bridging.Bridge.%s.VLAN.%s.", ctx, "0", NULL, NULL, NULL, NULL, bridge_instance, vlan_instance);
DMPARAM("VLANEnable", ctx, "1", get_bridge_vlan_enable, set_bridge_vlan_enable, "xsd:boolean", "0", 0, 0,NULL);
DMPARAM("VLANName", ctx, "1", get_bridge_vlan_name, set_bridge_vlan_name, "xsd:boolean", "0", 0, 0,NULL);
DMPARAM("VLANID", ctx, "1", get_bridge_vlan_vid, set_bridge_vlan_vid, "xsd:boolean", "0", 0, 0,NULL);
return 0;
}
inline int get_bridge_interface(struct dmctx *ctx, char *bridge_instance, char *interface) {
struct uci_section *s = NULL;
char *bridgekey, *vlan_instance;
DMOBJECT(DMROOT"Layer2Bridging.Bridge.%s.", ctx, "1", NULL, NULL, NULL, NULL, bridge_instance);
DMPARAM("BridgeEnable", ctx, "1", get_bridge_status, set_bridge_status, "xsd:boolean", "0", 0, 0,NULL);
DMPARAM("BridgeKey", ctx, "0", get_bridge_key, set_bridge_key, "xsd:boolean", "0", 0, 0,NULL);
DMPARAM("BridgeName", ctx, "1", get_bridge_name, set_bridge_name, "xsd:boolean", "0", 0, 0,NULL);
DMPARAM("VLANID", ctx, "1", get_bridge_vlanid, set_bridge_vlanid, "xsd:boolean", "0", 0, 0,NULL);
DMPARAM("X_INTENO_COM_AssociatedInterfaces", ctx, "1", get_associated_interfaces, set_associated_interfaces, "xsd:boolean", "0", 0, 0,NULL);
DMOBJECT(DMROOT"Layer2Bridging.Bridge.%s.VLAN.", ctx, "0", NULL, NULL, NULL, NULL, bridge_instance);
uci_foreach_sections("dmmap", "vlan_bridge", s) {
dmuci_get_value_by_section_string(s, "bridgekey", &bridgekey);
if(!strcmp(bridgekey, bridge_instance)){
dmuci_get_value_by_section_string(s, "instance", &vlan_instance);
init_args_layer2(ctx, s, strdup(""), strdup(""), strdup(""));
SUBENTRY(get_bridge_vlan, ctx, bridge_instance, vlan_instance+2 , s->e.name);
}
}
return 0;
}
inline int get_available_interface(struct dmctx *ctx, int available_int_inst, char *oface, char *interface_type) {
DMOBJECT(DMROOT"Layer2Bridging.AvailableInterface.%d.", ctx, "0", NULL, NULL, NULL, NULL, available_int_inst);
DMPARAM("AvailableInterfaceKey", ctx, "0", get_available_interface_key, set_available_interface_key, "xsd:boolean", "0", 0, 0,NULL);
DMPARAM("InterfaceReference", ctx, "0", get_interface_reference, set_interface_reference, "xsd:boolean", "0", 0, 0,NULL);
DMPARAM("InterfaceType", ctx, "0", get_interface_type, set_interface_type, "xsd:boolean", "0", 0, 0,NULL);
return 0;
}
int entry_method_root_Layer2Bridging(struct dmctx *ctx) {
int i=0, available_int_inst, instance, er;
char *oface, *phy_interface, *ch_ptr, *bridge_type, *cur_idev=NULL, *bridge_instance;
char *base_ifname, *marking_instance, *available_inst=NULL;
struct uci_section *s = NULL;
uci_ctx = uci_alloc_context();
IF_MATCH(ctx, DMROOT"Layer2Bridging.") {
DMOBJECT(DMROOT"Layer2Bridging.", ctx, "0", NULL, NULL, NULL, NULL);
DMOBJECT(DMROOT"Layer2Bridging.AvailableInterface.", ctx, "0", NULL, NULL, NULL, NULL);
for (i=0; i<3; i++) {
uci_foreach_sections(wan_interface_tab[i].package, wan_interface_tab[i].section, s) {
if (s != NULL) {
dmuci_get_value_by_section_string(s,"baseifname", &base_ifname);
instance=atoi(base_ifname+3);
dmasprintf(&oface,"InternetGatewayDevice.WANDevice.%d.WANConnectionDevice.%d.",wan_interface_tab[i].instance, ++instance);
update_availableinterface_list(base_ifname, &available_inst);
available_int_inst=atoi(available_inst);
init_args_layer2(ctx, s, dmstrdup("WANInterface"), available_inst, oface);
SUBENTRY(get_available_interface, ctx, available_int_inst, oface, dmstrdup("WANInterface"));
}
else {
break;
}
}
}
db_get_value_string("hw", "board", "ethernetLanPorts", &phy_interface);
ch_ptr = strtok (phy_interface," ");
while (ch_ptr != NULL)
{
dmasprintf(&oface,"InternetGatewayDevice.LANInterfaces.LANEthernetInterfaceConfig.%s.",ch_ptr+3);
update_availableinterface_list(ch_ptr, &available_inst);
available_int_inst=atoi(available_inst);
init_args_layer2(ctx, s, dmstrdup("LANInterface"), available_inst, oface);
SUBENTRY(get_available_interface, ctx, available_int_inst, oface, strdup("LANInterface"));
ch_ptr = strtok (NULL, " ");
}
int wi_instance=0;
uci_foreach_sections("wireless", "wifi-iface", s) {
dmasprintf(&oface,"InternetGatewayDevice.LANInterfaces.WLANConfiguration.%d.",++wi_instance);
update_availableinterface_list(s->e.name, &available_inst);// section_name
available_int_inst=atoi(available_inst);
init_args_layer2(ctx, s, dmstrdup("LANInterface"), available_inst, oface);
SUBENTRY(get_available_interface, ctx, available_int_inst, oface, strdup("LANInterface"));
}
DMOBJECT(DMROOT"Layer2Bridging.Bridge.", ctx, "1", NULL, NULL, NULL, NULL);
uci_foreach_sections("network", "interface", s) {
dmuci_get_value_by_section_string(s, "type", &bridge_type);
if(!strcmp(bridge_type, "bridge"))
{
update_instances("network", "interface", "bridge_instance", cur_idev, s, &bridge_instance);
init_args_layer2(ctx, s, strdup(""), strdup(""), strdup(""));
SUBENTRY(get_bridge_interface, ctx, bridge_instance, s->e.name);
cur_idev = dmstrdup(bridge_instance);
}
}
DMOBJECT(DMROOT"Layer2Bridging.Marking.", ctx, "1", NULL, NULL, NULL, NULL);
uci_foreach_sections("dmmap", "marking-bridge", s) {
dmuci_get_value_by_section_string(s, "instance", &marking_instance);
init_args_layer2(ctx, s, strdup(""), strdup(""), strdup(""));
SUBENTRY(get_marking_bridge, ctx, s->e.name, marking_instance);
}
dmfree(cur_idev);
dmfree(bridge_instance);
dmfree(oface);
return 0;
}
return FAULT_9005;
}

View file

@ -0,0 +1,17 @@
/*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2012-2014 PIVA SOFTWARE (www.pivasoftware.com)
* Author: Anis Ellouze <anis.ellouze@pivasoftware.com>
*
*/
#ifndef __Layer_2_bridging_H
#define __Layer_2_bridging_H
int entry_method_root_Layer2Bridging(struct dmctx *ctx);
#endif

View file

@ -0,0 +1,191 @@
/*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2012-2014 PIVA SOFTWARE (www.pivasoftware.com)
* Author: Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author: Feten Besbes <feten.besbes@pivasoftware.com>
*/
#include <ctype.h>
#include <uci.h>
#include <stdio.h>
#include "dmcwmp.h"
#include "dmuci.h"
#include "dmubus.h"
#include "managementserver.h"
#include "dmcommon.h"
int get_management_server_url(char *refparam, struct dmctx *ctx, char **value)
{
dmuci_get_option_value_string("cwmp", "acs", "url", value);
return 0;
}
int set_management_server()
{
return 0;
}
int set_management_server_url(char *refparam, struct dmctx *ctx, int action, char *value)
{
bool b;
char *stat = "";
switch (action) {
VALUECHECK:
if (string_to_bool(value, &b))
return FAULT_9007;
return 0;
VALUESET:
dmuci_set_value("cwmp", "acs", "dhcp_discovery", "disable");
set_management_server(); //TODO BY IBH
return 0;
}
return 0;
}
int get_management_server_username(char *refparam, struct dmctx *ctx, char **value)
{
dmuci_get_option_value_string("cwmp", "acs", "userid", value);
return 0;
}
int set_management_server_username(char *refparam, struct dmctx *ctx, int action, char *value)
{
set_management_server(); //TODO BY IBH
return 0;
}
int set_management_server_passwd(char *refparam, struct dmctx *ctx, int action, char *value)
{
set_management_server(); //TODO BY IBH
return 0;
}
int get_management_server_key(char *refparam, struct dmctx *ctx, char **value)
{
dmuci_get_option_value_string("cwmp", "acs", "ParameterKey", value);
return 0;
}
int set_management_server_key(char *refparam, struct dmctx *ctx, int action, char *value)
{
set_management_server(); //TODO BY IBH
return 0;
}
int get_management_server_periodic_inform_enable(char *refparam, struct dmctx *ctx, char **value)
{
dmuci_get_option_value_string("cwmp", "acs", "periodic_inform_enable", value);
return 0;
}
int set_management_server_periodic_inform_enable(char *refparam, struct dmctx *ctx, int action, char *value)
{
set_management_server();//TODO BY IBH
return 0;
}
int get_management_server_periodic_inform_interval(char *refparam, struct dmctx *ctx, char **value)
{
dmuci_get_option_value_string("cwmp", "acs", "periodic_inform_interval", value);
return 0;
}
int set_management_server_periodic_inform_interval(char *refparam, struct dmctx *ctx, int action, char *value)
{
set_management_server();//TODO BY IBH
return 0;
}
/*get_management_server_periodic_inform_time() {
local val=""
val=`$UCI_GET cwmp.acs.periodic_inform_time`
if [ "$val" != "0" -a "$val" != "" ];then
val=`date -d @$val +"%Y-%m-%dT%H:%M:%S.000Z"`
else
val="0001-01-01T00:00:00Z"
fi
echo "$val"
}
*/
int get_management_server_periodic_inform_time(char *refparam, struct dmctx *ctx, char **value)
{
dmuci_get_option_value_string("cwmp", "acs", "periodic_inform_time", value);
if ((*value)[0] != '0' && (*value)[0] != '\0') {
*value = dmstrdup("TOCODE");
}
else {
dmfree(*value);
*value = dmstrdup("0001-01-01T00:00:00Z");
}
return 0;
}
int set_management_server_periodic_inform_time(char *refparam, struct dmctx *ctx, int action, char *value)
{
set_management_server(); //TODO BY IBH
return 0;
}
//TODO
int get_management_server_connection_request_url(char *refparam, struct dmctx *ctx, char **value)
{
*value = dmstrdup("TOCODE");
return 0;
}
int get_management_server_connection_request_username(char *refparam, struct dmctx *ctx, char **value)
{
dmuci_get_option_value_string("cwmp", "cpe", "userid", value);
return 0;
}
int set_management_server_connection_request_username(char *refparam, struct dmctx *ctx, int action, char *value)
{
set_management_server();//TODO BY IBH
return 0;
}
int set_management_server_connection_request_passwd(char *refparam, struct dmctx *ctx, int action, char *value)
{
set_management_server();//TODO BY IBH
return 0;
}
/*
get_cache_InternetGatewayDevice_ManagementServer() {
get_object_cache_generic "InternetGatewayDevice.ManagementServer." "0" "0"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.URL" "1" "\$UCI_GET cwmp.acs.url" "set_management_server_url \$val" "" "cwmp.acs.url"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.Username" "1" "\$UCI_GET cwmp.acs.userid" "set_management_server cwmp.acs.userid \$val" "" "cwmp.acs.userid"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.Password" "1" "" "set_management_server cwmp.acs.passwd \$val" "" "" "" "" "" "" "1"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.ParameterKey" "1" "\$UCI_GET cwmp.acs.ParameterKey" "set_management_server cwmp.acs.ParameterKey \$val" "" "cwmp.acs.ParameterKey" "" "0" "1"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.PeriodicInformEnable" "1" "\$UCI_GET cwmp.acs.periodic_inform_enable" "set_management_server cwmp.acs.periodic_inform_enable \$val" "" "cwmp.acs.periodic_inform_enable" "xsd:boolean"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.PeriodicInformInterval" "1" "\$UCI_GET cwmp.acs.periodic_inform_interval" "set_management_server cwmp.acs.periodic_inform_interval \$val" "" "cwmp.acs.periodic_inform_interval" "xsd:unsignedInt"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.PeriodicInformTime" "1" "get_management_server_periodic_inform_time" "set_management_server_periodic_inform_time \$val" "" "cwmp.acs.periodic_inform_time" "xsd:dateTime"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.ConnectionRequestURL" "0" "get_management_server_connection_request_url" "" "1" "" "" "0" "1" "2"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.ConnectionRequestUsername" "1" "\$UCI_GET cwmp.cpe.userid" "set_management_server cwmp.cpe.userid \$val" "" "cwmp.cpe.userid"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.ConnectionRequestPassword" "1" "" "set_management_server cwmp.cpe.passwd \$val" "" "" "" "" "" "" "1"
}
*/
int entry_method_root_ManagementServer(struct dmctx *ctx)
{
IF_MATCH(ctx, DMROOT"ManagementServer.") {
DMOBJECT(DMROOT"ManagementServer.", ctx, "0", 0, NULL, NULL, NULL);
DMPARAM("URL", ctx, "1", get_management_server_url, set_management_server_url, "xsd:boolean", 0, 0, UNDEF, NULL);
DMPARAM("Username", ctx, "1", get_management_server_username, set_management_server_username, "xsd:boolean", 0, 0, UNDEF, NULL);
DMPARAM("Password", ctx, "1", get_empty, set_management_server_passwd, "xsd:boolean", 0, 0, UNDEF, NULL);
DMPARAM("ParameterKey", ctx, "1", get_management_server_key, set_management_server_key, "", 1, 0, UNDEF, NULL);
DMPARAM("PeriodicInformEnable", ctx, "1", get_management_server_periodic_inform_enable, set_management_server_periodic_inform_enable, "xsd:boolean", 0, 0, UNDEF, NULL);
DMPARAM("PeriodicInformInterval", ctx, "1", get_management_server_periodic_inform_interval, set_management_server_periodic_inform_interval, "xsd:boolean", 0, 0, UNDEF, NULL);
DMPARAM("PeriodicInformTime", ctx, "1", get_management_server_periodic_inform_time, set_management_server_periodic_inform_time, "xsd:boolean", 0, 0, UNDEF, NULL);
DMPARAM("ConnectionRequestURL", ctx, "0", get_management_server_connection_request_url, NULL, "", 1, 0, UNDEF, NULL);
DMPARAM("ConnectionRequestUsername", ctx, "1", get_management_server_connection_request_username, set_management_server_connection_request_username, "xsd:boolean", 0, 0, UNDEF, NULL);
DMPARAM("ConnectionRequestPassword", ctx, "1", get_empty, set_management_server_connection_request_passwd, "xsd:boolean", 0, 0, UNDEF, NULL);
return 0;
}
return FAULT_9005;
}

View file

@ -0,0 +1,33 @@
/*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2012-2014 PIVA SOFTWARE (www.pivasoftware.com)
* Author: Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author: Feten Besbes <feten.besbes@pivasoftware.com>
*/
#ifndef __MANAGEMENT_SERVER_H
#define __MANAGEMENT_SERVER_H
int get_management_server_url(char *refparam, struct dmctx *ctx, char **value);
int set_management_server();
int set_management_server_url(char *refparam, struct dmctx *ctx, int action, char *value);
int get_management_server_username(char *refparam, struct dmctx *ctx, char **value);
int set_management_server_username(char *refparam, struct dmctx *ctx, int action, char *value);
int set_management_server_passwd(char *refparam, struct dmctx *ctx, int action, char *value);
int get_management_server_key(char *refparam, struct dmctx *ctx, char **value);
int set_management_server_key(char *refparam, struct dmctx *ctx, int action, char *value);
int get_management_server_periodic_inform_enable(char *refparam, struct dmctx *ctx, char **value);
int set_management_server_periodic_inform_enable(char *refparam, struct dmctx *ctx, int action, char *value);
int get_management_server_periodic_inform_interval(char *refparam, struct dmctx *ctx, char **value);
int set_management_server_periodic_inform_interval(char *refparam, struct dmctx *ctx, int action, char *value);
int get_management_server_periodic_inform_time(char *refparam, struct dmctx *ctx, char **value);
int set_management_server_periodic_inform_time(char *refparam, struct dmctx *ctx, int action, char *value);
int get_management_server_connection_request_url(char *refparam, struct dmctx *ctx, char **value);
int get_management_server_connection_request_username(char *refparam, struct dmctx *ctx, char **value);
int set_management_server_connection_request_username(char *refparam, struct dmctx *ctx, int action, char *value);
int set_management_server_connection_request_passwd(char *refparam, struct dmctx *ctx, int action, char *value);
int entry_method_root_ManagementServer(struct dmctx *ctx);
#endif

26
dm/dmtree/root.c Normal file
View file

@ -0,0 +1,26 @@
/*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2015 Inteno Broadband Technology AB
* Author MOHAMED Kallel <mohamed.kallel@pivasoftware.com>
* Author Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author Feten Besbes <feten.besbes@pivasoftware.com>
*
*/
#include "dmuci.h"
#include "dmcwmp.h"
#include "root.h"
int entry_method_root(struct dmctx *ctx)
{
char *val = NULL;
IF_MATCH(ctx, DMROOT) {
DMOBJECT(DMROOT, ctx, "0", 0, NULL, NULL, NULL);
return 0;
}
return FAULT_9005;
}

18
dm/dmtree/root.h Normal file
View file

@ -0,0 +1,18 @@
/*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2015 Inteno Broadband Technology AB
* Author MOHAMED Kallel <mohamed.kallel@pivasoftware.com>
* Author Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author Feten Besbes <feten.besbes@pivasoftware.com>
*
*/
#ifndef __ROOT_H
#define __ROOT_H
#include "dmcwmp.h"
int entry_method_root(struct dmctx *ctx);
#endif

1452
dm/dmtree/wandevice.c Normal file

File diff suppressed because it is too large Load diff

114
dm/dmtree/wandevice.h Normal file
View file

@ -0,0 +1,114 @@
/*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2015 PIVA SOFTWARE (www.pivasoftware.com)
* Author: Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author: Feten Besbes <feten.besbes@pivasoftware.com>
*/
#ifndef __WAN_DEVICE_H
#define __WAN_DEVICE_H
#include <libubox/blobmsg_json.h>
#include <json/json.h>
inline int init_wanargs(struct dmctx *ctx, char *idev, char *fdev);
inline int init_wancprotoargs(struct dmctx *ctx, struct uci_section *s);
inline int init_wancdevargs(struct dmctx *ctx, char *fwan);
char *get_wan_device_wan_dsl_traffic();
int check_multiwan_interface(struct uci_section *s);
int network_get_ipaddr(char **value, char *iface);
/**************************************************************************
**** **** function related to get_wandevice_wandevice_parameters **** ****
***************************************************************************/
int get_wan_device_wan_access_type(char *refparam, struct dmctx *ctx, char **value);
int get_wan_device_wan_dsl_interface_config_status(char *refparam, struct dmctx *ctx, char **value);
int get_wan_device_wan_dsl_interface_config_modulation_type(char *refparam, struct dmctx *ctx, char **value);
int get_wan_device_dsl_datapath(char *refparam, struct dmctx *ctx, char **value);
int get_wan_device_dsl_downstreamcurrrate(char *refparam, struct dmctx *ctx, char **value);
int get_wan_device_dsl_downstreammaxrate(char *refparam, struct dmctx *ctx, char **value);
int get_wan_device_dsl_downstreamattenuation(char *refparam, struct dmctx *ctx, char **value);
int get_wan_device_dsl_downstreamnoisemargin(char *refparam, struct dmctx *ctx, char **value);
int get_wan_device_dsl_upstreamcurrrate(char *refparam, struct dmctx *ctx, char **value);
int get_wan_device_dsl_upstreammaxrate(char *refparam, struct dmctx *ctx, char **value);
int get_wan_device_dsl_upstreamattenuation(char *refparam, struct dmctx *ctx, char **value);
int get_wan_device_dsl_upstreamnoisemargin(char *refparam, struct dmctx *ctx, char **value);
int get_annexm_status(char *refparam, struct dmctx *ctx, char **value);
int set_annexm_enable(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wan_eth_intf_enable(char *refparam, struct dmctx *ctx, char **value);
int set_wan_eth_intf_enable(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wan_eth_intf_status(char *refparam, struct dmctx *ctx, char **value);
int get_wan_eth_intf_mac(char *refparam, struct dmctx *ctx, char **value);
int get_wan_eth_intf_stats_tx_bytes(char *refparam, struct dmctx *ctx, char **value);
int get_wan_eth_intf_stats_rx_bytes(char *refparam, struct dmctx *ctx, char **value);
int get_wan_eth_intf_stats_tx_packets(char *refparam, struct dmctx *ctx, char **value);
int get_wan_eth_intf_stats_rx_packets(char *refparam, struct dmctx *ctx, char **value);
int get_wandevice_wandevice_parameters(struct dmctx *ctx, char *dev, char *fdev);
/*****/
int entry_method_root_WANDevice(struct dmctx *ctx);
/**************************************************************************
**** **** function related to get_wandevice_wanconnectiondevice_parameters **** ****
***************************************************************************/
int get_wan_dsl_link_config_enable(char *refparam, struct dmctx *ctx, char **value);
int get_wan_dsl_link_config_destination_address(char *refparam, struct dmctx *ctx, char **value);
int set_wan_dsl_link_config_destination_address(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wan_dsl_link_config_atm_encapsulation(char *refparam, struct dmctx *ctx, char **value);
int set_wan_dsl_link_config_atm_encapsulation(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wandevice_wanconnectiondevice_parameters(struct dmctx *ctx, char *idev, char *iwan);
/**************************************************************************
**** **** function related to get_wandevice_wanprotoclconnection_parameters **** ****
***************************************************************************/
int get_wandevice_wanprotoclconnection_parameters(struct dmctx *ctx, char *idev, char *iwan, char *iconp, char *proto);
int get_wan_device_mng_status(char *refparam, struct dmctx *ctx, char **value);
int get_wan_device_mng_interface_ip(char *refparam, struct dmctx *ctx, char **value);
int get_wan_ip_link_connection_connection_type(char *refparam, struct dmctx *ctx, char **value);
int set_wan_ip_link_connection_connection_type(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wan_ip_link_connection_addressing_type(char *refparam, struct dmctx *ctx, char **value);
int set_wan_ip_link_connection_addressing_type(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wan_ip_link_connection_nat_enabled(char *refparam, struct dmctx *ctx, char **value);
int set_wan_ip_link_connection_nat_enabled(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wan_igmp_rule_idx(char *iface, struct uci_section **rule, struct uci_section **zone, char **enable);
int get_wan_ip_link_connection_igmp_enabled(char *refparam, struct dmctx *ctx, char **value);
int set_wan_ip_link_connection_igmp_enabled(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wan_ip_link_connection_dns_enabled(char *refparam, struct dmctx *ctx, char **value);
int set_wan_ip_link_connection_dns_enabled(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wan_device_ppp_status(char *refparam, struct dmctx *ctx, char **value);
int get_wan_device_ppp_interface_ip(char *refparam, struct dmctx *ctx, char **value);
int get_wan_device_mng_interface_mac(char *refparam, struct dmctx *ctx, char **value);
int get_wan_device_ppp_username(char *refparam, struct dmctx *ctx, char **value);
int set_wan_device_username(char *refparam, struct dmctx *ctx, int action, char *value);
int set_wan_device_password(char *refparam, struct dmctx *ctx, int action, char *value);
//OLD
int get_wan_device_wan_dsl_interface_config_status(char *refparam, struct dmctx *ctx, char **value);
int get_wan_device_wan_dsl_interface_config_modulation_type(char *refparam, struct dmctx *ctx, char **value);
int get_wan_device_dsl_datapath(char *refparam, struct dmctx *ctx, char **value);
int get_wan_device_dsl_downstreamcurrrate(char *refparam, struct dmctx *ctx, char **value);
int get_wan_device_dsl_downstreammaxrate(char *refparam, struct dmctx *ctx, char **value);
int get_wan_device_dsl_downstreamattenuation(char *refparam, struct dmctx *ctx, char **value);
int get_wan_device_dsl_downstreamnoisemargin(char *refparam, struct dmctx *ctx, char **value);
int get_wan_device_dsl_upstreamcurrrate(char *refparam, struct dmctx *ctx, char **value);
int get_wan_device_dsl_upstreammaxrate(char *refparam, struct dmctx *ctx, char **value);
int get_wan_device_dsl_upstreamattenuation(char *refparam, struct dmctx *ctx, char **value);
int get_wan_device_dsl_upstreamnoisemargin(char *refparam, struct dmctx *ctx, char **value);
int get_annexm_status(char *refparam, struct dmctx *ctx, char **value);
int set_annexm_enable(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wan_eth_intf_enable(char *refparam, struct dmctx *ctx, char **value);
int set_wan_eth_intf_enable(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wan_eth_intf_status(char *refparam, struct dmctx *ctx, char **value);
int get_wan_eth_intf_mac(char *refparam, struct dmctx *ctx, char **value);
int get_wan_eth_intf_stats_tx_bytes(char *refparam, struct dmctx *ctx, char **value);
int get_wan_eth_intf_stats_rx_bytes(char *refparam, struct dmctx *ctx, char **value);
int get_wan_eth_intf_stats_tx_packets(char *refparam, struct dmctx *ctx, char **value);
int get_wan_eth_intf_stats_rx_packets(char *refparam, struct dmctx *ctx, char **value);
int get_wandevice_wandevice_parameters (struct dmctx *ctx, char *dev, char *fdev);
int entry_method_root_WANDevice(struct dmctx *ctx);
int get_wan_dsl_link_config_enable(char *refparam, struct dmctx *ctx, char **value);
int set_wan_dsl_link_config_destination_address(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wan_dsl_link_config_atm_encapsulation(char *refparam, struct dmctx *ctx, char **value);
int set_wan_dsl_link_config_atm_encapsulation(char *refparam, struct dmctx *ctx, int action, char *value);
int get_wandevice_wanconnectiondevice_parameters(struct dmctx *ctx, char *idev, char *iwan);
#endif

View file

@ -0,0 +1,64 @@
/*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2012-2014 PIVA SOFTWARE (www.pivasoftware.com)
* Author: Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author: Feten Besbes <feten.besbes@pivasoftware.com>
* Author: Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author: Anis Ellouze <anis.ellouze@pivasoftware.com>
*/
#include "dmcwmp.h"
#include "dmuci.h"
int get_pwr_mgmt_value_ethapd(char *refparam, struct dmctx *ctx, char **value)
{
dmuci_get_option_value_string("power_mgmt", "power_mgmt", "ethapd", value);
return 0;
}
int get_pwr_mgmt_value_eee(char *refparam, struct dmctx *ctx, char **value)
{
dmuci_get_option_value_string("power_mgmt", "power_mgmt", "eee", value);
return 0;
}
int get_pwr_nbr_interfaces_up(char *refparam, struct dmctx *ctx, char **value)
{
*value = dmstrdup("TOCODE");
return 0;
}
int get_pwr_nbr_interfaces_down(char *refparam, struct dmctx *ctx, char **value)
{
*value = dmstrdup("TOCODE");
return 0;
}
int set_power_mgmt_param_ethapd(char *refparam, struct dmctx *ctx, int action, char *value)
{
dmuci_set_value("power_mgmt", "power_mgmt", "ethapd", value);
return 0;
}
int set_power_mgmt_param_eee(char *refparam, struct dmctx *ctx, int action, char *value)
{
dmuci_set_value("power_mgmt", "power_mgmt", "eee", value);
return 0;
}
int entry_method_root_X_INTENO_SE_PowerManagement(struct dmctx *ctx)
{
IF_MATCH(ctx, DMROOT"X_INTENO_SE_PowerManagement.") {
DMOBJECT(DMROOT"X_INTENO_SE_PowerManagement.", ctx, "0", 1, NULL, NULL, NULL);
DMPARAM("EthernetAutoPowerDownEnable", ctx, "1", get_pwr_mgmt_value_ethapd, set_power_mgmt_param_ethapd, "xsd:boolean", 0, 1, UNDEF, NULL);
DMPARAM("EnergyEfficientEthernetEnable", ctx, "1", get_pwr_mgmt_value_eee, set_power_mgmt_param_eee, "xsd:boolean", 0, 1, UNDEF, NULL);
DMPARAM("NumberOfEthernetInterfacesPoweredUp", ctx, "0", get_pwr_nbr_interfaces_up, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL);
DMPARAM("NumberOfEthernetInterfacesPoweredDown", ctx, "0", get_pwr_nbr_interfaces_down, NULL, "xsd:unsignedInt", 0, 1, UNDEF, NULL);
return 0;
}
return FAULT_9005;
}

View file

@ -0,0 +1,22 @@
/*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2012-2014 PIVA SOFTWARE (www.pivasoftware.com)
* Author: Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author: Feten Besbes <feten.besbes@pivasoftware.com>
*/
#ifndef __POWER_MGMT_H
#define __POWER_MGMT_H
int get_pwr_mgmt_value_ethapd(char *refparam, struct dmctx *ctx, char **value);
int get_pwr_mgmt_value_eee(char *refparam, struct dmctx *ctx, char **value);
int get_pwr_nbr_interfaces_up(char *refparam, struct dmctx *ctx, char **value);
int get_pwr_nbr_interfaces_down(char *refparam, struct dmctx *ctx, char **value);
int set_power_mgmt_param_ethapd(char *refparam, struct dmctx *ctx, int action, char *value);
int set_power_mgmt_param_eee(char *refparam, struct dmctx *ctx, int action, char *value);
int entry_method_root_X_INTENO_SE_PowerManagement(struct dmctx *ctx);
#endif

313
dm/dmubus.c Normal file
View file

@ -0,0 +1,313 @@
/*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2012-2014 PIVA SOFTWARE (www.pivasoftware.com)
* Author: Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author: Feten Besbes <feten.besbes@pivasoftware.com>
* Author: Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author: Anis Ellouze <anis.ellouze@pivasoftware.com>
*/
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <libubus.h>
#include <libubox/blobmsg_json.h>
#include <json/json.h>
#include <stdio.h>
#include "dmubus.h"
#include "dmmem.h"
#define DELIMITOR ","
struct dmubus_ctx dmubus_ctx;
struct ubus_context *ubus_ctx;
static int timeout = 1000;
const char *ubus_socket = NULL;
json_object *json_res = NULL;
static inline bool dmblobmsg_add_object(struct blob_buf *b, json_object *obj)
{
json_object_object_foreach(obj, key, val) {
if (!blobmsg_add_json_element(b, key, val))
return false;
}
return true;
}
static inline bool dmblobmsg_json_object_from_uargs(struct blob_buf *b, char *key, char *val)
{
bool status;
json_object *jobj = json_object_new_object();
json_object *jstring = json_object_new_string(val);
json_object_object_add(jobj,key, jstring);
status = dmblobmsg_add_object(b, jobj);
json_object_put(jobj);
return status;
}
static inline int ubus_arg_cmp(struct ubus_arg *src_args, int src_size, struct ubus_arg dst_args[], int dst_size)
{
if (src_size != dst_size)
return -1;
int i;
for (i = 0; i < src_size; i++) {
if (strcmp( src_args[i].key, dst_args[i].key) != 0 || strcmp( src_args[i].val, dst_args[i].val) != 0)
return -1;
}
return 0;
}
static void receive_call_result_data(struct ubus_request *req, int type, struct blob_attr *msg)
{
if (!msg)
return;
char *str = blobmsg_format_json_indent(msg, true, -1);
if (!str) {
json_res = NULL;
return;
}
json_res = json_tokener_parse((const char *)str);
if (json_res != NULL && (is_error(json_res))) {
json_object_put(json_res);
json_res = NULL;
}
//TODO The str should be freed some where. Not sure if it's possible before getting values from json obj
}
static inline json_object *ubus_call_req(char *obj, char *method, struct ubus_arg u_args[], int u_args_size)
{
struct blob_buf b = {0};
uint32_t id;
int ret;
json_res = NULL;
ubus_ctx = ubus_connect(ubus_socket);
if (!ubus_ctx)
return NULL;
blob_buf_init(&b, 0);
int i=0;
for (i = 0; i < u_args_size; i++) {
if (!dmblobmsg_json_object_from_uargs(&b, u_args[i].key, u_args[i].val))
goto end_error;
}
ret = ubus_lookup_id(ubus_ctx, obj, &id);
ubus_invoke(ubus_ctx, id, method, b.head, receive_call_result_data, NULL, timeout);
blob_buf_free(&b);
return json_res;
end_error:
blob_buf_free(&b);
return NULL;
}
int dmubus_call(char *obj, char *method, struct ubus_arg u_args[], int u_args_size, json_object **req_res)
{
struct ubus_obj *i = NULL;
struct ubus_meth *j = NULL;
struct ubus_msg *k = NULL;
json_object **jr;
bool found = false;
*req_res = NULL;
list_for_each_entry(i, &dmubus_ctx.obj_head, list) {
if (strcmp(obj, i->name) == 0) {
found = true;
break;
}
}
if (!found) {
i = dmcalloc(1, sizeof(struct ubus_obj));
//init method head
INIT_LIST_HEAD(&i->method_head);
i->name = obj;
list_add(&i->list, &dmubus_ctx.obj_head);
}
found = false;
list_for_each_entry(j, &i->method_head, list) {
if (strcmp(method, j->name) == 0) {
*req_res = j->res;
found = true;
break;
}
}
if (!found) {
j = dmcalloc(1, sizeof(struct ubus_meth));
//init message head
INIT_LIST_HEAD(&j->msg_head);
j->name = method;
list_add(&j->list, &i->method_head);
jr = &j->res;
}
// Arguments
if (u_args_size != 0) {
found = false;
int n=0;
list_for_each_entry(k, &j->msg_head, list) {
if (ubus_arg_cmp(k->ug, k->ug_size, u_args, u_args_size) == 0) {
*req_res = k->res;
found = true;
break;
}
}
if (!found) {
k = dmcalloc(1, sizeof(struct ubus_msg));
list_add(&k->list, &j->msg_head);
k->ug = dmcalloc(u_args_size, sizeof(struct ubus_arg));
k->ug_size = u_args_size;
jr = &k->res;
int c;
for (c = 0; c < u_args_size; c++) {
k->ug[c].key = dmstrdup(u_args[c].key);
k->ug[c].val = dmstrdup(u_args[c].val);
}
}
}
if (!found) {
*jr = ubus_call_req(obj, method, u_args, u_args_size);
*req_res = *jr;
}
return 0;
}
void dmubus_ctx_free(struct dmubus_ctx *ctx)
{
struct ubus_obj *i, *_i;
struct ubus_meth *j, *_j;
struct ubus_msg *k, *_k;
list_for_each_entry_safe(i, _i, &ctx->obj_head, list) {
list_for_each_entry_safe(j, _j, &i->method_head, list) {
list_for_each_entry_safe(k, _k, &j->msg_head, list) {
if(k->ug_size != 0) {
int c;
for (c = 0; c < k->ug_size; c++) {
dmfree(k->ug[c].key);
dmfree(k->ug[c].val);
}
dmfree(k->ug);
}
list_del(&k->list);
if(k->res)
json_object_put(k->res);
dmfree(k);
}
list_del(&j->list);
if(j->res)
json_object_put(j->res);
dmfree(j);
}
list_del(&i->list);
dmfree(i);
}
}
/*printing the value corresponding to boolean, double, integer and strings*/
void print_json_value(json_object *jobj, char **value)
{
enum json_type type;
type = json_object_get_type(jobj); /*Getting the type of the json object*/
switch (type) {
case json_type_boolean:
*value = dmstrdup(json_object_get_boolean(jobj)? "true": "false");
break;
case json_type_double:
dmasprintf(value, "%lf", json_object_get_double(jobj));
break;
case json_type_int:
dmasprintf(value, "%d", json_object_get_int(jobj));
break;
case json_type_string:
*value = dmstrdup(json_object_get_string(jobj));
break;
}
}
void json_parse_array( json_object *jobj, char *key, int index, char *next_key, char **value)
{
enum json_type type;
int i;
int len;
char val[512] = {0};
json_object *jarray = jobj;/*Simply get the array*/
if(key) {
jarray = json_object_object_get(jobj, key);/*Getting the array if it is a key value pair*/
}
int arraylen = json_object_array_length(jarray);/*Getting the length of the array*/
json_object *jvalue;
//read all tab
if (index == -1) {
for (i=0; i< arraylen; i++) {
//jvalue = json_object_array_get_idx(jarray, i); /*Getting the array element at position i*/
json_parse_array( jarray, NULL, i, NULL, value);
//CONCAT
len = strlen(val);
if (len != 0) {
memcpy(val + len, DELIMITOR, sizeof(DELIMITOR));
strcpy(val + len + sizeof(DELIMITOR) - 1, *value);
}
else
strcpy(val, *value);
}
*value = dmstrdup(val);
} else if (index < arraylen) {
jvalue = json_object_array_get_idx(jarray, index);/*Getting the array element at position i*/
type = json_object_get_type(jvalue);
if (type == json_type_array) {
json_parse_array(jvalue, NULL, index, NULL, value);
}
else if (type == 0) {
*value = strdup("");
}
else if (type != json_type_object) {
print_json_value(jvalue, value);
}
else {
json_select(jvalue, next_key, index, next_key, value, NULL);
}
}
else {
*value = strdup(""); //CHECK IF IT IS NECESSAR
}
}
/*Parsing the json object*/
int json_select(json_object *jobj, char *search, int index, char *next_key, char **value, json_object **jobjres)
{
enum json_type type;
json_object *jobj1 = NULL;
json_object_object_foreach(jobj, key, val) {
if (strcmp(key, search) == 0) {
type = json_object_get_type(val);
switch (type) {
case json_type_boolean:
case json_type_double:
case json_type_int:
case json_type_string:
print_json_value(val, value);
return 0;
case json_type_object:
jobj1 = json_object_object_get(jobj, key);
if (next_key == NULL) {
*jobjres = json_object_object_get(jobj, key);
return 0;
}
else {
json_select(jobj1, next_key, index, NULL, value, jobjres);
return 0;
}
case json_type_array:
jobj1 = json_object_object_get(jobj, key);
json_parse_array(jobj1, NULL, index, next_key, value);
return 0;
}
return 0;
}
}
return -1;
}

63
dm/dmubus.h Normal file
View file

@ -0,0 +1,63 @@
/*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2012-2014 PIVA SOFTWARE (www.pivasoftware.com)
* Author: Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author: Feten Besbes <feten.besbes@pivasoftware.com>
* Author: Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author: Anis Ellouze <anis.ellouze@pivasoftware.com>
*/
#ifndef __UBUS_H
#define __UBUS_H
#include <libubox/list.h>
#include <libubox/blobmsg_json.h>
#include <json/json.h>
#define UBUS_ARGS (struct ubus_arg[])
#define SIMPLE_OUTPUT -1
#define INDENT_OUTPUT 0
#define JSON_OUTPUT SIMPLE_OUTPUT
struct dmubus_ctx {
struct list_head obj_head;
};
struct ubus_obj {
struct list_head list;
struct list_head method_head;
char *name;
};
struct ubus_meth {
struct list_head list;
struct list_head msg_head;
char *name;
json_object *res;
};
struct ubus_msg {
struct list_head list;
struct ubus_arg *ug; // ubus method param
int ug_size;
json_object *res;
};
struct ubus_arg{
char *key;
char *val;
};
extern struct dmubus_ctx dmubus_ctx;
extern struct ubus_context *ubus_ctx;
int dmubus_call(char *obj, char *method, struct ubus_arg u_args[], int u_args_size, json_object **req_res);
void dmubus_ctx_free(struct dmubus_ctx *ctx);
void print_json_value(json_object *jobj, char **value);
void json_parse_array( json_object *jobj, char *key, int index, char *next_key, char **value);
int json_select(json_object *jobj, char *search, int index, char *next_key, char **value, json_object **jobjres);
#endif

585
dm/dmuci.c Normal file
View file

@ -0,0 +1,585 @@
/*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2015 Inteno Broadband Technology AB
* Author MOHAMED Kallel <mohamed.kallel@pivasoftware.com>
* Author Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author Feten Besbes <feten.besbes@pivasoftware.com>
*
*/
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <uci.h>
#include "dmuci.h"
#include "dmmem.h"
struct uci_context *uci_ctx;
char *dmuci_list_to_string(struct uci_list *list, char *delimitor)
{
struct uci_element *e = NULL;
char val[512] = {0};
int del_len = strlen(delimitor);
if (list) {
uci_foreach_element(list, e)
{
int len = strlen(val);
if (len != 0) {
memcpy(val + len, delimitor, del_len);
strcpy(val + len + del_len, e->name);
}
else
strcpy(val, e->name);
}
return (dmstrdup(val));
}
else
{
return dmstrdup("");
}
}
static inline bool check_section_name(const char *str, bool name)
{
if (!*str)
return false;
for (; *str; str++) {
unsigned char c = *str;
if (isalnum(c) || c == '_')
continue;
if (name || (c < 33) || (c > 126))
return false;
}
return true;
}
//////////////////////////////
void add_list_package_change(struct list_head *clist, char *package)
{
struct package_change *pc;
list_for_each_entry(pc, clist, list) {
if (strcmp(pc->package, package) == 0)
return;
}
pc = calloc(1, sizeof(struct package_change));//TODO !!!!! Do not use dmcalloc here
list_add_tail(&pc->list, clist);
pc->package = strdup(package); //TODO !!!!! Do not use dmstrdup here
}
void free_all_list_package_change(struct list_head *clist)
{
struct package_change *pc;
while (clist->next != clist) {
pc = list_entry(clist->next, struct package_change, list);
list_del(&pc->list);
free(pc->package);//TODO !!!!! Do not use dmfree here
free(pc);//TODO !!!!! Do not use dmfree here
}
}
///////////////////////////
/**** UCI LOOKUP ****/
int dmuci_lookup_ptr(struct uci_context *ctx, struct uci_ptr *ptr, char *package, char *section, char *option, char *value)
{
/*package*/
if (!package && !package[0])
return -1;
ptr->package = package;
/*section*/
if (!section || !section[0]) {
ptr->target = UCI_TYPE_PACKAGE;
goto lookup;
}
ptr->section = section;
if (ptr->section && !check_section_name(ptr->section , true))
ptr->flags |= UCI_LOOKUP_EXTENDED;
/*option*/
if (!option || !option[0]) {
ptr->target = UCI_TYPE_SECTION;
goto lookup;
}
ptr->target = UCI_TYPE_OPTION;
ptr->option = option;
/*value*/
if (!value || !value[0]) {
goto lookup;
}
ptr->value = value;
lookup:
if (uci_lookup_ptr(ctx, ptr, NULL, true) != UCI_OK || !UCI_LOOKUP_COMPLETE) {
return -1;
}
return 0;
}
/**** UCI GET *****/
int dmuci_get_section_type(char *package, char *section,char **value)
{
struct uci_element *e;
struct uci_ptr ptr = {0};
if (dmuci_lookup_ptr(uci_ctx, &ptr, package, section, NULL, NULL)) {
*value = dmstrdup("");
return -1;
}
if (ptr.s) {
*value = dmstrdup(ptr.s->type);
} else {
*value = dmstrdup("");
return -1;
}
return 0;
}
int dmuci_get_option_value_string(char *package, char *section, char *option, char **value)
{
struct uci_element *e;
struct uci_ptr ptr = {0};
if (dmuci_lookup_ptr(uci_ctx, &ptr, package, section, option, NULL)) {
*value = dmstrdup("");
return -1;
}
if (ptr.o) {
*value = dmstrdup(ptr.o->v.string);
} else {
*value = dmstrdup("");
return -1;
}
return 0;
}
int dmuci_get_option_value_list(char *package, char *section, char *option, struct uci_list **value)
{
struct uci_element *e;
struct uci_ptr ptr = {0};
*value = NULL;
if (dmuci_lookup_ptr(uci_ctx, &ptr, package, section, option, NULL)) {
return -1;
}
if (ptr.o) {
*value = &ptr.o->v.list;
} else {
return -1;
}
return 0;
}
struct uci_option *dmuci_get_option_ptr(char *cfg_path, char *package, char *section, char *option)
{
int ret;
struct uci_option *o = NULL;
struct uci_element *e;
struct uci_ptr ptr = {0};
char *oconfdir;
oconfdir = uci_ctx->confdir;
uci_ctx->confdir = cfg_path;
if (dmuci_lookup_ptr(uci_ctx, &ptr, package, section, option, NULL)) {
goto end;
}
e = ptr.last;
switch(e->type) {
case UCI_TYPE_OPTION:
o = ptr.o;
default:
break;
}
end:
uci_ctx->confdir = oconfdir;
return o;
}
int db_get_value_string(char *package, char *section, char *option, char **value)
{
struct uci_option *o;
o = dmuci_get_option_ptr(DB_CONFIG, package, section, option);
if (o) {
*value = dmstrdup(o->v.string);
} else {
*value = dmstrdup("");
return -1;
}
return 0;
}
int db_get_value_list(char *package, char *section, char *option, struct uci_list **value)
{
struct uci_option *o;
*value = NULL;
o = dmuci_get_option_ptr(DB_CONFIG, package, section, option);
if (o) {
*value = &o->v.list;
} else {
return -1;
}
return 0;
}
/**** UCI Commit *****/
int dmuci_commit_package(char *package)
{
struct uci_ptr ptr = {0};
if (uci_lookup_ptr(uci_ctx, &ptr, package, true) != UCI_OK) {
return -1;
}
if (uci_commit(uci_ctx, &ptr.p, false) != UCI_OK) {
return -1;
}
return 0;
}
int dmuci_commit(void)
{
char **configs = NULL;
char **p;
if ((uci_list_configs(uci_ctx, &configs) != UCI_OK) || !configs) {
return -1;
}
for (p = configs; *p; p++) {
dmuci_commit_package(*p);
}
return 0;
}
/**** UCI REVERT *****/
int dmuci_revert_package(char *package)
{
struct uci_ptr ptr = {0};
if (uci_lookup_ptr(uci_ctx, &ptr, package, true) != UCI_OK) {
return -1;
}
if (uci_revert(uci_ctx, &ptr) != UCI_OK) {
return -1;
}
return 0;
}
int dmuci_revert(void)
{
char **configs = NULL;
char **p;
if ((uci_list_configs(uci_ctx, &configs) != UCI_OK) || !configs) {
return -1;
}
for (p = configs; *p; p++) {
dmuci_revert_package(*p);
}
return 0;
}
/**** UCI CHANGES PACKAGES *****/
int dmuci_change_packages(struct list_head *clist)
{
char **configs = NULL;
char **p;
if ((uci_list_configs(uci_ctx, &configs) != UCI_OK) || !configs) {
return -1;
}
for (p = configs; *p; p++) {
struct uci_ptr ptr = {0};
if (uci_lookup_ptr(uci_ctx, &ptr, *p, true) != UCI_OK) {
continue;
}
if (ptr.p->saved_delta.next == &ptr.p->saved_delta)
continue;
add_list_package_change(clist, *p);
}
return 0;
}
/**** UCI SET *****/
char *dmuci_set_value(char *package, char *section, char *option, char *value)
{
struct uci_ptr ptr = {0};
if (dmuci_lookup_ptr(uci_ctx, &ptr, package, section, option, value)) {
return "";
}
if (uci_set(uci_ctx, &ptr) != UCI_OK) {
return "";
}
if (ptr.o) {
return ptr.o->v.string;
}
return "";
}
/**** UCI ADD LIST *****/
int dmuci_add_list_value(char *package, char *section, char *option, char *value)
{
struct uci_ptr ptr = {0};
if (dmuci_lookup_ptr(uci_ctx, &ptr, package, section, option, value))
return -1;
if (uci_add_list(uci_ctx, &ptr) != UCI_OK)
return -1;
return 0;
}
/**** UCI DEL LIST *****/
int dmuci_del_list_value(char *package, char *section, char *option, char *value)
{
struct uci_ptr ptr = {0};
if (dmuci_lookup_ptr(uci_ctx, &ptr, package, section, option, value))
return -1;
if (uci_del_list(uci_ctx, &ptr) != UCI_OK)
return -1;
return 0;
}
/****** UCI ADD *******/
int dmuci_add_section(char *package, char *stype, struct uci_section **s, char **value)
{
struct uci_ptr ptr = {0};
*s = NULL;
if (dmuci_lookup_ptr(uci_ctx, &ptr, package, NULL, NULL, NULL)) {
*value = dmstrdup("");
return -1;
}
if (uci_add_section(uci_ctx, ptr.p, stype, s) != UCI_OK) {
*value = dmstrdup("");
return -1;
}
*value = dmstrdup((*s)->e.name);
return 0;
}
/**** UCI DELETE *****/
int dmuci_delete(char *package, char *section, char *option, char *value)
{
struct uci_ptr ptr = {0};
if (dmuci_lookup_ptr(uci_ctx, &ptr, package, section, option, NULL))
return -1;
if (uci_delete(uci_ctx, &ptr) != UCI_OK)
return -1;
return 0;
}
/**** UCI LOOKUP by section pointer ****/
int dmuci_lookup_ptr_by_section(struct uci_context *ctx, struct uci_ptr *ptr, struct uci_section *s, char *option, char *value)
{
struct uci_element *e;
ptr->flags |= UCI_LOOKUP_DONE;
/*package*/
ptr->package = s->package->e.name;
ptr->p = s->package;
/* section */
ptr->section = s->e.name;
ptr->s = s;
ptr->last = e;
/*option*/
if (!option || !option[0]) {
ptr->target = UCI_TYPE_SECTION;
goto lookup;
}
ptr->target = UCI_TYPE_OPTION;
ptr->option = option;
/*value*/
if (!value || !value[0]) {
goto lookup;
}
ptr->value = value;
lookup:
if (ptr->option) {
uci_foreach_element(&ptr->s->options, e) {
if (strcmp(e->name, ptr->option) == 0) {
ptr->o = uci_to_option(e);
ptr->last = e;
break;
}
}
}
ptr->flags |= UCI_LOOKUP_COMPLETE;
return 0;
}
/**** UCI GET by section pointer*****/
int dmuci_get_value_by_section_string(struct uci_section *s, char *option, char **value)
{
struct uci_element *e;
struct uci_option *o;
uci_foreach_element(&s->options, e) {
o = (uci_to_option(e));
if (!strcmp(o->e.name, option)) {
*value = dmstrdup(o->v.string);
return 0;
}
}
*value = dmstrdup("");
return -1;
}
int dmuci_get_value_by_section_list(struct uci_section *s, char *option, struct uci_list **value)
{
struct uci_element *e;
struct uci_option *o;
uci_foreach_element(&s->options, e) {
o = (uci_to_option(e));
if (!strcmp(o->e.name, option)) {
*value = &o->v.list;
return 0;
}
}
*value = NULL;
return -1;
}
/**** UCI SET by section pointer ****/
char *dmuci_set_value_by_section(struct uci_section *s, char *option, char *value)
{
struct uci_ptr up = {0};
dmuci_lookup_ptr_by_section(uci_ctx, &up, s, option, value);
if (uci_set(uci_ctx, &up) != UCI_OK)
return "";
if (up.o) {
return up.o->v.string;
}
return "";
}
/**** UCI DELETE by section pointer *****/
int dmuci_delete_by_section(struct uci_section *s, char *option, char *value)
{
struct uci_ptr up = {0};
dmuci_lookup_ptr_by_section(uci_ctx, &up, s, option, value);
if (uci_delete(uci_ctx, &up) != UCI_OK)
return -1;
return 0;
}
/**** UCI ADD LIST by section pointer *****/
int dmuci_add_list_value_by_section(struct uci_section *s, char *option, char *value)
{
struct uci_ptr up = {0};
dmuci_lookup_ptr_by_section(uci_ctx, &up, s, option, value);
if (uci_add_list(uci_ctx, &up) != UCI_OK)
return -1;
return 0;
}
/**** UCI DEL LIST by section pointer *****/
int dmuci_del_list_value_by_section(struct uci_section *s, char *option, char *value)
{
struct uci_ptr up = {0};
dmuci_lookup_ptr_by_section(uci_ctx, &up, s, option, value);
if (uci_del_list(uci_ctx, &up) != UCI_OK)
return -1;
return 0;
}
/**** UCI WALK SECTIONS *****/
struct uci_section *dmuci_walk_section (char *package, char *stype, void *arg1, void *arg2, int cmp , int (*filter)(struct uci_section *s, void *value), struct uci_section *prev_section, int walk) {
struct uci_section *s = NULL;
struct uci_element *e, *m;
char *value;
struct uci_list *list_value, *list_section;
struct uci_ptr ptr = {0};
if (walk == GET_FIRST_SECTION) {
if (dmuci_lookup_ptr(uci_ctx, &ptr, package, NULL, NULL, NULL) != UCI_OK) {
goto end;
}
list_section = &(ptr.p)->sections;
e = list_to_element(list_section->next);
}
else {
list_section = &prev_section->package->sections;
e = list_to_element(prev_section->e.list.next);
}
while(&e->list != list_section) {
s = uci_to_section(e);
if (strcmp(s->type, stype) == 0) {
switch(cmp) {
case CMP_SECTION:
goto end;
case CMP_OPTION_EQUAL:
dmuci_get_value_by_section_string(s, (char *)arg1, &value);
if (strcmp(value, (char *)arg2) == 0)
goto end;
break;
case CMP_OPTION_CONTAINING:
dmuci_get_value_by_section_string(s, (char *)arg1, &value);
if (strstr(value, (char *)arg2)) {
goto end;
}
break;
case CMP_OPTION_CONT_WORD:
dmuci_get_value_by_section_string(s, (char *)arg1, &value);
char *pch = strtok(value, " ");
while (pch != NULL) {
if (strcmp((char *)arg2, pch) == 0) {
goto end;
}
pch = strtok(NULL, " ");
}
break;
case CMP_LIST_CONTAINING:
dmuci_get_value_by_section_list(s, (char *)arg1, &list_value);
if (list_value != NULL) {
uci_foreach_element(list_value, m) {
if (strcmp(m->name, (char *)arg2) == 0)
goto end;
}
}
break;
case CMP_FILTER_FUNC:
if (filter(s, arg1) == 0)
goto end;
break;
default:
break;
}
}
e = list_to_element(e->list.next);
s = NULL;
}
end:
return s;
}

108
dm/dmuci.h Normal file
View file

@ -0,0 +1,108 @@
/*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2015 Inteno Broadband Technology AB
* Author MOHAMED Kallel <mohamed.kallel@pivasoftware.com>
* Author Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author Feten Besbes <feten.besbes@pivasoftware.com>
*
*/
#ifndef __DMUCI_H
#define __DMUCI_H
#include "uci_config.h"
#include <stdbool.h>
#include <setjmp.h>
#include <stdio.h>
#include <stdint.h>
#include <uci.h>
#include <libubox/list.h>
#define DB_CONFIG "/lib/db/config"
extern struct uci_context *uci_ctx;
enum dm_uci_cmp {
CMP_SECTION,
CMP_OPTION_EQUAL,
CMP_OPTION_REGEX,
CMP_OPTION_CONTAINING,
CMP_OPTION_CONT_WORD,
CMP_LIST_CONTAINING,
CMP_FILTER_FUNC
};
enum dm_uci_walk {
GET_FIRST_SECTION,
GET_NEXT_SECTION
};
struct package_change {
struct list_head list;
char *package;
};
#define uci_foreach_sections(package, stype, section) \
for (section = dmuci_walk_section(package, stype, NULL, NULL, CMP_SECTION, NULL, NULL, GET_FIRST_SECTION); \
section != NULL; \
section = dmuci_walk_section(package, stype, NULL, NULL, CMP_SECTION, NULL, section, GET_NEXT_SECTION))
#define uci_foreach_option_eq(package, stype, option, val, section) \
for (section = dmuci_walk_section(package, stype, option, val, CMP_OPTION_EQUAL, NULL, NULL, GET_FIRST_SECTION); \
section != NULL; \
section = dmuci_walk_section(package, stype, option, val, CMP_OPTION_EQUAL, NULL, section, GET_NEXT_SECTION))
#define uci_foreach_option_cont(package, stype, option, val, section) \
for (section = dmuci_walk_section(package, stype, option, val, CMP_OPTION_CONTAINING, NULL, NULL, GET_FIRST_SECTION); \
section != NULL; \
section = dmuci_walk_section(package, stype, option, val, CMP_OPTION_CONTAINING, NULL, section, GET_NEXT_SECTION))
#define uci_foreach_option_cont_word(package, stype, option, val, section) \
for (section = dmuci_walk_section(package, stype, option, val, CMP_OPTION_CONT_WORD, NULL, NULL, GET_FIRST_SECTION); \
section != NULL; \
section = dmuci_walk_section(package, stype, option, val, CMP_OPTION_CONT_WORD, NULL, section, GET_NEXT_SECTION))
#define uci_foreach_list_cont(package, stype, option, val, section) \
for (section = dmuci_walk_section(package, stype, option, val, CMP_LIST_CONTAINING, NULL, NULL, GET_FIRST_SECTION); \
section != NULL; \
section = dmuci_walk_section(package, stype, option, val, CMP_LIST_CONTAINING, NULL, section, GET_NEXT_SECTION))
#define uci_foreach_filter_func(package, stype, arg, func, section) \
for (section = dmuci_walk_section(package, stype, arg, NULL, CMP_FILTER_FUNC, func, NULL, GET_FIRST_SECTION); \
section != NULL; \
section = dmuci_walk_section(package, stype, arg, NULL, CMP_FILTER_FUNC, func, section, GET_NEXT_SECTION))
#define section_name(s) (s)->e.name
char *dmuci_list_to_string(struct uci_list *list, char *delimitor);
void add_list_package_change(struct list_head *clist, char *package);
void free_all_list_package_change(struct list_head *clist);
int dmuci_lookup_ptr(struct uci_context *ctx, struct uci_ptr *ptr, char *package, char *section, char *option, char *value);
int dmuci_get_section_type(char *package, char *section,char **value);
int dmuci_get_option_value_string(char *package, char *section, char *option, char **value);
int dmuci_get_option_value_list(char *package, char *section, char *option, struct uci_list **value);
struct uci_option *dmuci_get_option_ptr(char *cfg_path, char *package, char *section, char *option);
int db_get_value_string(char *package, char *section, char *option, char **value);
int db_get_value_list(char *package, char *section, char *option, struct uci_list **value);
int dmuci_commit_package(char *package);
int dmuci_commit(void);
int dmuci_revert_package(char *package);
int dmuci_revert(void);
int dmuci_change_packages(struct list_head *clist);
char *dmuci_set_value(char *package, char *section, char *option, char *value);
int dmuci_add_list_value(char *package, char *section, char *option, char *value);
int dmuci_del_list_value(char *package, char *section, char *option, char *value);
int dmuci_add_section(char *package, char *stype, struct uci_section **s, char **value);
int dmuci_delete(char *package, char *section, char *option, char *value);
int dmuci_lookup_ptr_by_section(struct uci_context *ctx, struct uci_ptr *ptr, struct uci_section *s, char *option, char *value);
int dmuci_get_value_by_section_string(struct uci_section *s, char *option, char **value);
int dmuci_get_value_by_section_list(struct uci_section *s, char *option, struct uci_list **value);
char *dmuci_set_value_by_section(struct uci_section *s, char *option, char *value);
int dmuci_delete_by_section(struct uci_section *s, char *option, char *value);
int dmuci_add_list_value_by_section(struct uci_section *s, char *option, char *value);
int dmuci_del_list_value_by_section(struct uci_section *s, char *option, char *value);
struct uci_section *dmuci_walk_section (char *package, char *stype, void *arg1, void *arg2, int cmp , int (*filter)(struct uci_section *s, void *value), struct uci_section *prev_section, int walk);
#endif

50
dm/wepkey.c Normal file
View file

@ -0,0 +1,50 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "wepkey.h"
void wepkey64(char *passphrase, char strk64[4][11])
{
unsigned char k64[4][5];
unsigned char pseed[4] = {0};
unsigned int randNumber, tmp;
int i, j;
for(i = 0; i < strlen(passphrase); i++)
{
pseed[i%4] ^= (unsigned char) passphrase[i];
}
randNumber = pseed[0] | (pseed[1] << 8) | (pseed[2] << 16) | (pseed[3] << 24);
for (i = 0; i < 4; i++)
{
for (j = 0; j < 5; j++)
{
randNumber = (randNumber * 0x343fd + 0x269ec3) & 0xffffffff;
tmp = (randNumber >> 16) & 0xff;
k64[i][j] = (unsigned char) tmp;
}
sprintf(strk64[i], "%02X%02X%02X%02X%02X", k64[i][0], k64[i][1], k64[i][2], k64[i][3], k64[i][4]);
}
}
void wepkey128(char *passphrase, char strk128[27])
{
int i=0;
char dup[65] = {0};
unsigned char out[MD5_DIGEST_SIZE];
struct MD5Context c;
while (i<64) {
strncpy(dup + i, passphrase, 64 - i);
i = strlen(dup);
}
MD5Init(&c);
MD5Update(&c, dup, 64);
MD5Final(out, &c);
for(i=0; i<13; i++)
sprintf(strk128 + 2 * i, "%02X", out[i]);
}

6
dm/wepkey.h Normal file
View file

@ -0,0 +1,6 @@
#ifndef __WEPKEY_H__
#define __WEPKEY_H__
#include "md5.h"
void wepkey64(char *passphrase, char strk64[4][11]);
void wepkey128(char *passphrase, char strk128[27]);
#endif /*__WEPKEY_H__*/

74
event.c
View file

@ -17,6 +17,10 @@
#include "log.h"
#include "jshn.h"
#include "external.h"
#include "dmcwmp.h"
#include "deviceinfo.h"
LIST_HEAD(list_value_change);
const struct EVENT_CONST_STRUCT EVENT_CONST [] = {
[EVENT_IDX_0BOOTSTRAP] = {"0 BOOTSTRAP", EVENT_TYPE_SINGLE, EVENT_RETRY_AFTER_TRANSMIT_FAIL|EVENT_RETRY_AFTER_REBOOT},
@ -39,7 +43,7 @@ const struct EVENT_CONST_STRUCT EVENT_CONST [] = {
void cwmp_save_event_container (struct cwmp *cwmp,struct event_container *event_container)
{
struct list_head *ilist;
struct parameter_container *parameter_container;
struct dm_parameter *dm_parameter;
char section[256];
mxml_node_t *b;
@ -47,10 +51,10 @@ void cwmp_save_event_container (struct cwmp *cwmp,struct event_container *event_
{
b = bkp_session_insert_event(event_container->code, event_container->command_key, event_container->id, "queue");
list_for_each(ilist,&(event_container->head_parameter_container))
list_for_each(ilist,&(event_container->head_dm_parameter))
{
parameter_container = list_entry(ilist, struct parameter_container, list);
bkp_session_insert_parameter(b, parameter_container->name);
dm_parameter = list_entry(ilist, struct dm_parameter, list);
bkp_session_insert_parameter(b, dm_parameter->name);
}
bkp_session_save();
}
@ -93,7 +97,7 @@ struct event_container *cwmp_add_event_container (struct cwmp *cwmp, int event_c
{
return NULL;
}
INIT_LIST_HEAD (&(event_container->head_parameter_container));
INIT_LIST_HEAD (&(event_container->head_dm_parameter));
list_add (&(event_container->list), ilist->prev);
event_container->code = event_code;
event_container->command_key = strdup(command_key);
@ -106,44 +110,41 @@ struct event_container *cwmp_add_event_container (struct cwmp *cwmp, int event_c
return event_container;
}
void parameter_container_add(struct list_head *head, char *param_name, char *param_data, char *param_type, char *fault_code)
void add_dm_parameter_tolist(struct list_head *head, char *param_name, char *param_data, char *param_type)
{
struct parameter_container *parameter_container;
struct dm_parameter *dm_parameter;
struct list_head *ilist;
int cmp;
list_for_each (ilist, head) {
parameter_container = list_entry(ilist, struct parameter_container, list);
cmp = strcmp(parameter_container->name, param_name);
dm_parameter = list_entry(ilist, struct dm_parameter, list);
cmp = strcmp(dm_parameter->name, param_name);
if (cmp == 0) {
return;
} else if (cmp > 0) {
break;
}
}
parameter_container = calloc(1, sizeof(struct parameter_container));
_list_add(&parameter_container->list, ilist->prev, ilist);
if (param_name) parameter_container->name = strdup(param_name);
if (param_data) parameter_container->data = strdup(param_data);
if (param_type) parameter_container->type = strdup(param_type);
if (fault_code) parameter_container->fault_code = strdup(fault_code);
dm_parameter = calloc(1, sizeof(struct dm_parameter));
_list_add(&dm_parameter->list, ilist->prev, ilist);
if (param_name) dm_parameter->name = strdup(param_name);
if (param_data) dm_parameter->data = strdup(param_data);
if (param_type) dm_parameter->type = param_type ? param_type : "xsd:string";
}
void parameter_container_delete(struct parameter_container *parameter_container)
void delete_dm_parameter_fromlist(struct dm_parameter *dm_parameter)
{
list_del(&parameter_container->list);
free(parameter_container->name);
free(parameter_container->data);
free(parameter_container->type);
free(parameter_container->fault_code);
free(parameter_container);
list_del(&dm_parameter->list);
free(dm_parameter->name);
free(dm_parameter->data);
free(dm_parameter);
}
void parameter_container_delete_all(struct list_head *list)
void free_dm_parameter_all_fromlist(struct list_head *list)
{
struct parameter_container *parameter_container;
struct dm_parameter *dm_parameter;
while (list->next!=list) {
parameter_container = list_entry(list->next, struct parameter_container, list);
parameter_container_delete(parameter_container);
dm_parameter = list_entry(list->next, struct dm_parameter, list);
delete_dm_parameter_fromlist(dm_parameter);
}
}
@ -192,14 +193,14 @@ int cwmp_root_cause_event_boot (struct cwmp *cwmp)
int event_remove_all_event_container(struct session *session, int rem_from)
{
struct event_container *event_container;
struct parameter_container *parameter_container;
struct dm_parameter *dm_parameter;
while (session->head_event_container.next!=&(session->head_event_container))
{
event_container = list_entry(session->head_event_container.next, struct event_container, list);
bkp_session_delete_event(event_container->id, rem_from?"send":"queue");
free (event_container->command_key);
parameter_container_delete_all(&(event_container->head_parameter_container));
free_dm_parameter_all_fromlist(&(event_container->head_dm_parameter));
list_del(&(event_container->list));
free (event_container);
}
@ -253,8 +254,8 @@ int cwmp_root_cause_event_bootstrap (struct cwmp *cwmp)
pthread_mutex_unlock (&(cwmp->mutex_session_queue));
return CWMP_MEM_ERR;
}
parameter_container_add(&(event_container->head_parameter_container),
"InternetGatewayDevice.ManagementServer.URL", NULL, NULL, NULL);
add_dm_parameter_tolist(&(event_container->head_dm_parameter),
DMROOT".ManagementServer.URL", NULL, NULL);
cwmp_save_event_container (cwmp,event_container);
save_acs_bkp_config (cwmp);
cwmp_scheduleInform_remove_all();
@ -427,23 +428,12 @@ int cwmp_root_cause_event_periodic (struct cwmp *cwmp)
void sotfware_version_value_change(struct cwmp *cwmp, struct transfer_complete *p)
{
struct parameter_container *parameter_container;
char *current_software_version = NULL;
if (!p->old_software_version || p->old_software_version[0] == 0)
return;
external_init();
external_get_action("value", DM_SOFTWARE_VERSION_PATH, NULL);
external_handle_action(cwmp_handle_getParamValues);
parameter_container = list_entry(external_list_parameter.next, struct parameter_container, list);
if ((!parameter_container->fault_code || parameter_container->fault_code[0] != '9') &&
strcmp(parameter_container->name, DM_SOFTWARE_VERSION_PATH) == 0)
{
current_software_version = strdup(parameter_container->data);
}
external_free_list_parameter();
external_exit();
current_software_version = cwmp->deviceid.softwareversion;
if (p->old_software_version && current_software_version &&
strcmp(p->old_software_version, current_software_version) != 0) {
pthread_mutex_lock (&(cwmp->mutex_session_queue));

View file

@ -35,36 +35,17 @@ static int pid;
static json_object *json_obj_in;
static int pfds_in[2], pfds_out[2];
static FILE *fpipe;
LIST_HEAD(external_list_parameter);
LIST_HEAD(external_list_value_change);
pthread_mutex_t external_mutex_value_change = PTHREAD_MUTEX_INITIALIZER;
char *external_MethodStatus = NULL;
char *external_MethodFault = NULL;
char *external_ObjectInstance = NULL;
inline void external_add_list_parameter(char *param_name, char *param_data, char *param_type, char *fault_code)
{
parameter_container_add(&external_list_parameter, param_name, param_data, param_type, fault_code);
}
pthread_mutex_t external_mutex_value_change = PTHREAD_MUTEX_INITIALIZER;
inline void external_add_list_value_change(char *param_name, char *param_data, char *param_type)
{
pthread_mutex_lock(&(external_mutex_value_change));
parameter_container_add(&external_list_value_change, param_name, param_data, param_type, NULL);
add_dm_parameter_tolist(&list_value_change, param_name, param_data, param_type);
pthread_mutex_unlock(&(external_mutex_value_change));
}
inline void external_free_list_parameter()
{
parameter_container_delete_all(&external_list_parameter);
}
inline void external_free_list_value_change()
{
parameter_container_delete_all(&external_list_value_change);
}
void external_downloadFaultResp (char *fault_code)
{
FREE(external_MethodFault);
@ -77,70 +58,6 @@ void external_fetch_downloadFaultResp (char **fault)
external_MethodFault = NULL;
}
void external_setParamValRespStatus (char *status)
{
FREE(external_MethodStatus);
external_MethodStatus = status ? strdup(status) : NULL;
}
void external_fetch_setParamValRespStatus (char **status)
{
*status = external_MethodStatus;
external_MethodStatus = NULL;
}
void external_setParamAttrResp (char *status, char *fault)
{
FREE(external_MethodStatus);
external_MethodStatus = status ? strdup(status) : NULL;
FREE(external_MethodFault);
external_MethodFault = fault ? strdup(fault) : NULL;
}
void external_fetch_setParamAttrResp (char **status, char **fault)
{
*status = external_MethodStatus;
external_MethodStatus = NULL;
*fault = external_MethodFault;
external_MethodFault = NULL;
}
void external_addObjectResp (char *instance, char *status, char *fault)
{
FREE(external_MethodStatus);
FREE(external_ObjectInstance);
FREE(external_MethodFault);
external_MethodStatus = status ? strdup(status) : NULL;
external_ObjectInstance = instance ? strdup(instance) : NULL;
external_MethodFault = fault ? strdup(fault) : NULL;
}
void external_fetch_addObjectResp (char **instance, char **status, char **fault)
{
*instance = external_ObjectInstance;
*status = external_MethodStatus;
*fault = external_MethodFault;
external_ObjectInstance = NULL;
external_MethodStatus = NULL;
external_MethodFault = NULL;
}
void external_delObjectResp (char *status, char *fault)
{
FREE(external_MethodStatus);
FREE(external_MethodFault);
if (status) external_MethodStatus = strdup(status);
if (fault) external_MethodFault = strdup(fault);
}
void external_fetch_delObjectResp (char **status, char **fault)
{
*status = external_MethodStatus;
*fault = external_MethodFault;
external_MethodStatus = NULL;
external_MethodFault = NULL;
}
static void external_read_pipe_input(int (*external_handler)(char *msg))
{
char buf[1], *value = NULL, *c = NULL;
@ -163,7 +80,7 @@ static void external_read_pipe_input(int (*external_handler)(char *msg))
value = c;
} else {
if (!value) continue;
if (strcmp(value, "EOF")==0) {
if (strcmp(value, "cwmp>")==0) {
FREE(value);
break;
}
@ -217,7 +134,6 @@ void external_init()
int i = 0;
argv[i++] = "/bin/sh";
argv[i++] = fc_script;
argv[i++] = "--json";
argv[i++] = "json_continuous_input";
argv[i++] = NULL;
execvp(argv[0], (char **) argv);
@ -278,71 +194,6 @@ int external_handle_action(int (*external_handler)(char *msg))
return 0;
}
int external_get_action(char *action, char *name, char *next_level)
{
DD(INFO,"executing get %s '%s'", action, name);
json_object *json_obj_out;
/* send data to the script */
json_obj_out = json_object_new_object();
json_obj_out_add(json_obj_out, "command", "get");
json_obj_out_add(json_obj_out, "action", action);
json_obj_out_add(json_obj_out, "parameter", name);
if (next_level) json_obj_out_add(json_obj_out, "next_level", next_level);
external_write_pipe_output(json_object_to_json_string(json_obj_out));
json_object_put(json_obj_out);
return 0;
}
int external_set_action(char *action, char *name, char *value, char *change)
{
DD(INFO,"executing set %s '%s'", action, name);
json_object *json_obj_out;
/* send data to the script */
json_obj_out = json_object_new_object();
json_obj_out_add(json_obj_out, "command", "set");
json_obj_out_add(json_obj_out, "action", action);
json_obj_out_add(json_obj_out, "parameter", name);
json_obj_out_add(json_obj_out, "value", value);
if (change) json_obj_out_add(json_obj_out, "change", change);
external_write_pipe_output(json_object_to_json_string(json_obj_out));
json_object_put(json_obj_out);
return 0;
}
int external_object_action(char *command, char *name, char *parameter_key)
{
DD(INFO,"executing %s object '%s'", command, name);
json_object *json_obj_out;
/* send data to the script */
json_obj_out = json_object_new_object();
json_obj_out_add(json_obj_out, "command", command);
json_obj_out_add(json_obj_out, "action", "object");
json_obj_out_add(json_obj_out, "parameter", name);
if (parameter_key) json_obj_out_add(json_obj_out, "parameter_key", parameter_key);
external_write_pipe_output(json_object_to_json_string(json_obj_out));
json_object_put(json_obj_out);
return 0;
}
int external_simple(char *command, char *arg)
{
DD(INFO,"executing %s request", command);

2
http.c
View file

@ -201,7 +201,9 @@ http_send_message(struct cwmp *cwmp, char *msg_out, char **msg_in)
if (!ip_acs || strcmp(ip_acs, ip) != 0) {
FREE(ip_acs);
ip_acs = strdup(ip);
external_init();
external_simple("allow_cr_ip", ip_acs);
external_exit();
}
}

View file

@ -50,8 +50,6 @@
#define UCI_CPE_LOG_MAX_SIZE "cwmp.cpe.log_max_size"
#define UCI_CPE_ENABLE_STDOUT_LOG "cwmp.cpe.log_to_console"
#define UCI_CPE_ENABLE_FILE_LOG "cwmp.cpe.log_to_file"
#define DM_SOFTWARE_VERSION_PATH "InternetGatewayDevice.DeviceInfo.SoftwareVersion"
enum end_session {
END_SESSION_REBOOT = 1,
@ -107,18 +105,10 @@ typedef struct event_container {
struct list_head list;
int code; /* required element of type xsd:string */
char *command_key;
struct list_head head_parameter_container;
struct list_head head_dm_parameter;
int id;
} event_container;
typedef struct parameter_container {
struct list_head list;
char *name;
char *data;
char *type;
char *fault_code;
} parameter_container;
typedef struct EVENT_CONST_STRUCT
{
char *CODE;
@ -171,9 +161,18 @@ enum enum_session_status {
SESSION_SUCCESS
};
struct deviceid {
char *manufacturer;
char *oui;
char *serialnumber;
char *productclass;
char *softwareversion;
};
typedef struct cwmp {
struct env env;
struct config conf;
struct deviceid deviceid;
struct list_head head_session_queue;
pthread_mutex_t mutex_session_queue;
struct session *session_send;
@ -209,6 +208,7 @@ typedef struct rpc {
struct list_head list;
int type;
void *extra_data;
struct list_head *list_set_value_fault;
} rpc;
#define ARRAYSIZEOF(a) (sizeof(a) / sizeof((a)[0]))
@ -216,6 +216,7 @@ typedef struct rpc {
extern struct cwmp cwmp_main;
extern const struct EVENT_CONST_STRUCT EVENT_CONST [__EVENT_IDX_MAX];
extern struct list_head list_value_change;
struct rpc *cwmp_add_session_rpc_cpe (struct session *session, int type);
struct session *cwmp_add_queue_session (struct cwmp *cwmp);
@ -231,5 +232,6 @@ char * mix_get_time_of(time_t t_time);
void *thread_exit_program (void *v);
void connection_request_ip_value_change(struct cwmp *cwmp);
void connection_request_port_value_change(struct cwmp *cwmp, int port);
void add_dm_parameter_tolist(struct list_head *head, char *param_name, char *param_data, char *param_type);
#endif /* _CWMP_H__ */

View file

@ -22,22 +22,9 @@ static char *fc_script = "/usr/sbin/freecwmp";
#endif
extern pthread_mutex_t external_mutex_value_change;
extern struct list_head external_list_value_change;
extern struct list_head external_list_parameter;
void external_downloadFaultResp (char *fault_code);
void external_fetch_downloadFaultResp (char **fault_code);
void external_setParamValRespStatus (char *status);
void external_fetch_setParamValRespStatus (char **status);
void external_setParamAttrResp (char *status, char *fault);
void external_fetch_setParamAttrResp (char **status, char **fault);
void external_addObjectResp (char *instance, char *status, char *fault);
void external_fetch_addObjectResp (char **instance, char **status, char **fault);
void external_delObjectResp (char *status, char *fault);
void external_fetch_delObjectResp (char **status, char **fault);
int external_get_action(char *action, char *name, char *next_level);
int external_set_action(char *action, char *name, char *value, char *change);
int external_object_action(char *command, char *name, char *parameter_key);
int external_simple(char *command, char *arg);
int external_download(char *url, char *size, char *type, char *user, char *pass);
int external_apply(char *action, char *arg);

View file

@ -44,18 +44,33 @@ enum log_severity_enum {
# define DD(SEV,MESSAGE,args...)
#endif
#ifndef DETECT_CRASH
#define DETECT_CRASH(MESSAGE,args...) { \
const char *A[] = {MESSAGE}; \
printf("step: %s %s %d\n",__FUNCTION__,__FILE__,__LINE__); fflush(stdout); sleep(1);\
if(sizeof(A) > 0) \
printf(*A,##args); \
const char *A[] = {MESSAGE}; \
printf("DETECT_CRASH: %s %s %d\n",__FUNCTION__,__FILE__,__LINE__); fflush(stdout);\
if(sizeof(A) > 0) \
printf(*A,##args); \
sleep(1); \
}
#endif
#define TRACE(MESSAGE,args...) { \
const char *A[] = {MESSAGE}; \
printf("step: %s %s %d\n",__FUNCTION__,__FILE__,__LINE__); fflush(stdout);\
if(sizeof(A) > 0) \
printf(*A,##args); \
#ifndef TRACE
#define TRACE_TYPE 0
static inline void trace_empty_func()
{
}
#if TRACE_TYPE == 2
#define TRACE(MESSAGE,args...) do { \
const char *A[] = {MESSAGE}; \
printf("TRACE: %s %s %d\n",__FUNCTION__,__FILE__,__LINE__); fflush(stdout);\
if(sizeof(A) > 0) \
printf(*A,##args); \
} while(0)
#elif TRACE_TYPE == 1
#define TRACE(MESSAGE, ...) printf(MESSAGE, ## __VA_ARGS__)
#else
#define TRACE(MESSAGE, ...) trace_empty_func()
#endif
#endif
#endif /* _LOG_H_ */

View file

@ -11,7 +11,6 @@
#ifndef _FREECWMP_UBUS_H__
#define _FREECWMP_UBUS_H__
int ubus_init(struct cwmp *cwmp);
void ubus_exit(void);

View file

@ -102,6 +102,7 @@ struct rpc_acs_method {
typedef struct FAULT_CPE
{
char *CODE;
int ICODE;
int TYPE;
char *DESCRIPTION;
} FAULT_CPE;
@ -166,7 +167,7 @@ int cwmp_rpc_acs_destroy_data_transfer_complete(struct session *session, struct
int xml_handle_message(struct session *session);
int xml_prepare_msg_out(struct session *session);
int cwmp_create_fault_message(struct session *session, struct rpc *rpc_cpe, int fault_code);
int cwmp_get_fault_code (char *fault_code);
int cwmp_get_fault_code (int fault_code);
int cwmp_scheduleInform_remove_all();
int cwmp_scheduledDownload_remove_all();
struct transfer_complete *cwmp_set_data_rpc_acs_transferComplete();

View file

@ -104,7 +104,6 @@ run() {
boot() {
touch /etc/cwmpd/.cwmpd_boot
/bin/sh /usr/sbin/freecwmp clean cache
local scron=`crontab -l | grep "/usr/sbin/watchcwmpd"`
if [ "$scron" != "" ]; then
crontab -l | sed "/\/usr\/sbin\/watchcwmpd/d" | crontab -
@ -114,9 +113,6 @@ boot() {
start_cwmpd() {
run=$(ps | grep /usr/sbin/cwmpd | grep -v grep | grep -v rc.common)
if [ "$run" = "" ];then
stop_freecwmp_cache
echo "Check if the whole cache is built. Wait if the whole cache is not built yet..."
/bin/sh /usr/sbin/freecwmp wait cache
printf "\033[A"
if [ "$1" = "GetRPCMethods" ];then
run "GetRPCMethods"
@ -176,21 +172,6 @@ pidof_freecwmp() {
echo "$pids"
}
stop_freecwmp_cache() {
local pid_list="" pid="" pids="" p name state ppid rest cmd
pid_list="`pidof_freecwmp`"
for pid in $pid_list; do
read p name state ppid rest < /proc/$pid/stat
cmd=`cat /proc/$ppid/cmdline | grep /etc/init.d/cwmpd`
if [ "_$cmd" = "_" ]; then
continue
fi
kill_process_childs "$ppid"
[ "$ppid" != "" ] && kill -9 "$ppid"
done
}
stop_cwmpd() {
echo $stop_msg;printf "\033[A"
local pid_list="" pids="" str=""
@ -203,7 +184,6 @@ stop_cwmpd() {
kill -9 $pid_list
fi
fi
stop_freecwmp_cache
}
start() {

292
jshn.c
View file

@ -85,295 +85,3 @@ error:
jshn_message_delete();
return -1;
}
enum getParamValues {
GETPARAMVALUES_PARAM,
GETPARAMVALUES_VALUE,
GETPARAMVALUES_TYPE,
GETPARAMVALUES_FAULT,
__GETPARAMVALUES_MAX
};
char *getParamValues_policy[] = {
[GETPARAMVALUES_PARAM] = "parameter",
[GETPARAMVALUES_VALUE] = "value",
[GETPARAMVALUES_TYPE] = "type",
[GETPARAMVALUES_FAULT] = "fault_code",
};
int
cwmp_handle_getParamValues(char *msg)
{
char *tb[__GETPARAMVALUES_MAX] = {0};
jshn_message_parse(getParamValues_policy, ARRAYSIZEOF(getParamValues_policy), tb, msg);
if (!tb[GETPARAMVALUES_PARAM])
goto error;
DD(INFO, "triggered handle get parameter value of: %s",
tb[GETPARAMVALUES_PARAM]);
external_add_list_parameter(tb[GETPARAMVALUES_PARAM],
tb[GETPARAMVALUES_VALUE],
(tb[GETPARAMVALUES_TYPE] && (tb[GETPARAMVALUES_TYPE])[0])? tb[GETPARAMVALUES_TYPE] : "xsd:string",
tb[GETPARAMVALUES_FAULT]);
jshn_message_delete();
return 0;
error:
jshn_message_delete();
return -1;
}
enum getParamNames {
GETPARAMNAMES_PARAM,
GETPARAMNAMES_WRITABLE,
GETPARAMNAMES_FAULT,
__GETPARAMNAMES_MAX
};
char *getParamNames_policy[] = {
[GETPARAMNAMES_PARAM] = "parameter",
[GETPARAMNAMES_WRITABLE] = "writable",
[GETPARAMNAMES_FAULT] = "fault_code",
};
int
cwmp_handle_getParamNames(char *msg)
{
char *tb[__GETPARAMNAMES_MAX] = {0};
jshn_message_parse(getParamNames_policy, ARRAYSIZEOF(getParamNames_policy), tb, msg);
if (!tb[GETPARAMNAMES_PARAM])
goto error;
DD(INFO, "triggered handle get parameter name of: %s",
tb[GETPARAMNAMES_PARAM]);
external_add_list_parameter(tb[GETPARAMNAMES_PARAM],
tb[GETPARAMNAMES_WRITABLE],
NULL,
tb[GETPARAMNAMES_FAULT]);
jshn_message_delete();
return 0;
error:
jshn_message_delete();
return -1;
}
enum getParamAttributes {
GETPARAMATTRIBUTES_PARAM,
GETPARAMATTRIBUTES_NOTIF,
GETPARAMATTRIBUTES_FAULT,
__GETPARAMATTRIBUTES_MAX
};
char *getParamAttributes_policy[] = {
[GETPARAMATTRIBUTES_PARAM] = "parameter",
[GETPARAMATTRIBUTES_NOTIF] = "notification",
[GETPARAMATTRIBUTES_FAULT] = "fault_code",
};
int
cwmp_handle_getParamAttributes(char *msg)
{
char *tb[__GETPARAMATTRIBUTES_MAX] = {0};
jshn_message_parse(getParamAttributes_policy, ARRAYSIZEOF(getParamAttributes_policy), tb, msg);
if (!tb[GETPARAMATTRIBUTES_PARAM])
goto error;
DD(INFO, "triggered handle get parameter attribute of: %s",
tb[GETPARAMATTRIBUTES_PARAM]);
external_add_list_parameter(tb[GETPARAMATTRIBUTES_PARAM],
tb[GETPARAMATTRIBUTES_NOTIF],
NULL,
tb[GETPARAMATTRIBUTES_FAULT]);
jshn_message_delete();
return 0;
error:
jshn_message_delete();
return -1;
}
enum setParamAttributes {
SETPARAMATTRIBUTES_SUCCESS,
SETPARAMATTRIBUTES_FAULT,
__SETPARAMATTRIBUTES_MAX
};
char *setParamAttributes_policy[] = {
[SETPARAMATTRIBUTES_SUCCESS] = "success",
[SETPARAMATTRIBUTES_FAULT] = "fault_code",
};
int
cwmp_handle_setParamAttributes(char *msg)
{
char *tb[__SETPARAMATTRIBUTES_MAX] = {0};
jshn_message_parse(setParamAttributes_policy, ARRAYSIZEOF(setParamAttributes_policy), tb, msg);
DD(INFO, "triggered handle set parameter attribute");
external_setParamAttrResp(tb[SETPARAMATTRIBUTES_SUCCESS],
tb[SETPARAMATTRIBUTES_FAULT]);
jshn_message_delete();
return 0;
}
enum setParamValuesFault {
SETPARAMVALUESFAULT_PARAM,
SETPARAMVALUESFAULT_FAULT,
__SETPARAMVALUESFAULT_MAX
};
char *setParamValuesFault_policy[] = {
[SETPARAMVALUESFAULT_PARAM] = "parameter",
[SETPARAMVALUESFAULT_FAULT] = "fault_code",
};
static int
cwmp_handle_setParamValuesFault(char *msg)
{
char *tb[__SETPARAMVALUESFAULT_MAX] = {0};
jshn_message_parse(setParamValuesFault_policy, ARRAYSIZEOF(setParamValuesFault_policy), tb, msg);
if (!tb[SETPARAMVALUESFAULT_PARAM])
goto error;
if (!tb[SETPARAMVALUESFAULT_FAULT])
goto error;
DD(INFO, "triggered handle set parameter value fault (%s) of: %s",
tb[SETPARAMVALUESFAULT_FAULT],
tb[SETPARAMVALUESFAULT_PARAM]);
external_add_list_parameter(tb[SETPARAMVALUESFAULT_PARAM],
NULL,
NULL,
tb[SETPARAMVALUESFAULT_FAULT]);
jshn_message_delete();
return 0;
error:
jshn_message_delete();
return -1;
}
enum setParamValuesStatus {
SETPARAMVALUESSTATUS_STATUS,
__SETPARAMVALUESSTATUS_MAX
};
char *setParamValuesStatus_policy[] = {
[SETPARAMVALUESSTATUS_STATUS] = "status",
};
static int
cwmp_handle_setParamValuesStatus(char *msg)
{
char *tb[__SETPARAMVALUESSTATUS_MAX] = {0};
jshn_message_parse(setParamValuesStatus_policy, ARRAYSIZEOF(setParamValuesStatus_policy), tb, msg);
if (!tb[SETPARAMVALUESSTATUS_STATUS])
goto error;
DD(INFO, "triggered handle set parameter value status");
external_setParamValRespStatus(tb[SETPARAMVALUESSTATUS_STATUS]);
jshn_message_delete();
return 0;
error:
jshn_message_delete();
return -1;
}
int
cwmp_handle_setParamValues(char *msg)
{
if (!cwmp_handle_setParamValuesFault(msg))
return 0;
if(cwmp_handle_setParamValuesStatus(msg))
return -1;
return 0;
}
enum addObject {
ADDOBJECT_INSTANCE,
ADDOBJECT_STATUS,
ADDOBJECT_FAULT,
__ADDOBJECT_MAX
};
char *addObject_policy[] = {
[ADDOBJECT_INSTANCE] = "instance",
[ADDOBJECT_STATUS] = "status",
[ADDOBJECT_FAULT] = "fault_code",
};
int
cwmp_handle_addObject(char *msg)
{
char *tb[__ADDOBJECT_MAX] = {0};
DD(INFO, "triggered handle add object");
jshn_message_parse(addObject_policy, ARRAYSIZEOF(addObject_policy), tb, msg);
external_addObjectResp(tb[ADDOBJECT_INSTANCE],
tb[ADDOBJECT_STATUS],
tb[ADDOBJECT_FAULT]);
jshn_message_delete();
return 0;
}
enum delObject {
DELOBJECT_STATUS,
DELOBJECT_FAULT,
__DELOBJECT_MAX
};
char *delObject_policy[] = {
[DELOBJECT_STATUS] = "status",
[DELOBJECT_FAULT] = "fault_code",
};
int
cwmp_handle_delObject(char *msg)
{
char *tb[__DELOBJECT_MAX] = {0};
DD(INFO, "triggered handle delete object");
jshn_message_parse(delObject_policy, ARRAYSIZEOF(delObject_policy), tb, msg);
external_delObjectResp(tb[DELOBJECT_STATUS],
tb[DELOBJECT_FAULT]);
jshn_message_delete();
return 0;
}

View file

@ -4,73 +4,28 @@
# Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
. /lib/functions.sh
. /usr/share/libubox/jshn.sh
. /usr/share/shflags/shflags.sh
. /usr/share/freecwmp/defaults
#TODO help message
# define a 'name' command-line string flag
DEFINE_boolean 'newline' false 'do not output the trailing newline' 'n'
DEFINE_boolean 'value' false 'output values only' 'v'
DEFINE_boolean 'json' false 'send values using json' 'j'
DEFINE_boolean 'empty' false 'output empty parameters' 'e'
DEFINE_boolean 'last' false 'output only last line ; for parameters that tend to have huge output' 'l'
DEFINE_boolean 'debug' false 'give debug output' 'd'
DEFINE_boolean 'dummy' false 'echo system commands' 'D'
DEFINE_boolean 'force' false 'force getting values for certain parameters' 'f'
FLAGS_HELP=`cat << EOF
USAGE: $0 [flags] command [parameter] [values]
command:
get [value|notification|name|cache]
set [value|notification]
apply [value|notification|download]
add [object]
delete [object]
download
factory_reset
reboot
notify
end_session
inform
wait [cache [status]]
clean [cache]
json_continuous_input
EOF`
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
if [ ${FLAGS_help} -eq ${FLAGS_TRUE} ]; then
exit 1
fi
if [ ${FLAGS_newline} -eq ${FLAGS_TRUE} ]; then
ECHO_newline='-n'
fi
UCI_GET="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get -q"
UCI_SET="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set -q"
UCI_BATCH="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} batch -q"
UCI_ADD="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} add -q"
UCI_ADD_LIST="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} add_list -q"
UCI_GET_VARSTATE="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state get -q"
UCI_SHOW="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} show -q"
UCI_DELETE="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} delete -q"
UCI_DEL_LIST="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} del_list -q"
UCI_COMMIT="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} commit -q"
UCI_RENAME="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} rename -q"
NEW_LINE='\n'
SERVICE_RESTART="SERVICE_RESTART"
cache_path="/etc/cwmpd/.cache"
tmp_cache="/tmp/.freecwmp_dm"
set_tmp_file="/tmp/.set_tmp_file"
set_fault_tmp_file="/tmp/.set_fault_tmp_file"
cache_linker_dynamic="/etc/cwmpd/.cache_linker_dynamic"
mkdir -p $cache_path
rm -f "$cache_path/"*"_dynamic"
CWMP_PROMPT="cwmp>"
UCI_GET="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get -q"
UCI_SHOW="/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} show -q"
TMP_SET_VALUE="/tmp/.tmp_set_value"
TMP_SET_NOTIFICATION="/tmp/.tmp_set_notification"
# Fault codes
FAULT_CPE_NO_FAULT="0"
FAULT_CPE_INTERNAL_ERROR="2"
FAULT_CPE_DOWNLOAD_FAILURE="10"
FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED="18"
for ffile in `ls /usr/share/freecwmp/functions/`; do
. /usr/share/freecwmp/functions/$ffile
done
case "$1" in
set)
if [ "$2" = "notification" ]; then
@ -99,9 +54,6 @@ case "$1" in
__arg1="$3"
__arg2="$4"
action="get_name"
elif [ "$2" = "cache" ]; then
__arg1="$3"
action="get_cache"
else
__arg1="$2"
action="get_value"
@ -148,15 +100,6 @@ case "$1" in
inform)
action="inform"
;;
notify)
action="notify"
__arg1="$2"
__arg2="$3"
__arg3="$4"
;;
end_session)
action="end_session"
;;
allow_cr_ip)
action="allow_cr_ip"
__arg1="$2"
@ -165,21 +108,7 @@ case "$1" in
action="json_continuous_input"
;;
end)
echo "EOF"
;;
wait)
if [ "$2" = "cache" ]; then
if [ "$3" = "status" ]; then
action="wait_cache_status"
else
action="wait_cache"
fi
fi
;;
clean)
if [ "$2" = "cache" ]; then
action="clean_cache"
fi
echo "$CWMP_PROMPT"
;;
exit)
exit 0
@ -191,257 +120,67 @@ if [ -z "$action" ]; then
exit 1
fi
if [ ${FLAGS_debug} -eq ${FLAGS_TRUE} ]; then
echo "[debug] started at \"`date`\""
fi
prefix_list=""
prefix_list_skip_wait_cache=""
. /lib/functions/network.sh
for ffile in `ls /usr/share/freecwmp/functions/`; do
. /usr/share/freecwmp/functions/$ffile
done
config_load cwmp
# Fault code
FAULT_CPE_NO_FAULT="0"
FAULT_CPE_REQUEST_DENIED="1"
FAULT_CPE_INTERNAL_ERROR="2"
FAULT_CPE_INVALID_ARGUMENTS="3"
FAULT_CPE_RESOURCES_EXCEEDED="4"
FAULT_CPE_INVALID_PARAMETER_NAME="5"
FAULT_CPE_INVALID_PARAMETER_TYPE="6"
FAULT_CPE_INVALID_PARAMETER_VALUE="7"
FAULT_CPE_NON_WRITABLE_PARAMETER="8"
FAULT_CPE_NOTIFICATION_REJECTED="9"
FAULT_CPE_DOWNLOAD_FAILURE="10"
FAULT_CPE_UPLOAD_FAILURE="11"
FAULT_CPE_FILE_TRANSFER_AUTHENTICATION_FAILURE="12"
FAULT_CPE_FILE_TRANSFER_UNSUPPORTED_PROTOCOL="13"
FAULT_CPE_DOWNLOAD_FAIL_MULTICAST_GROUP="14"
FAULT_CPE_DOWNLOAD_FAIL_CONTACT_SERVER="15"
FAULT_CPE_DOWNLOAD_FAIL_ACCESS_FILE="16"
FAULT_CPE_DOWNLOAD_FAIL_COMPLETE_DOWNLOAD="17"
FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED="18"
FAULT_CPE_DOWNLOAD_FAIL_FILE_AUTHENTICATION="19"
handle_get_cache() {
local param="$1"
local exact="$2"
local pid=""
local ls_cache=`ls $tmp_cache`
for pid in $ls_cache; do
if [ ! -d /proc/$pid ]; then
rm -rf "$tmp_cache/$pid"
fi
done
pid="$$"
mkdir -p "$tmp_cache/$pid"
for prefix in $prefix_list; do
case $prefix in $param*)
if [ "$exact" = "1" -a "$param" != "$prefix" ]; then continue; fi
local f=${prefix%.}
f=${f//./_}
f="get_cache_""$f"
$f > "$tmp_cache/$pid/$prefix"
mv "$tmp_cache/$pid/$prefix" "$cache_path/$prefix"
;;
esac
done
rm -rf "$tmp_cache/$pid"
ls_cache=`ls $tmp_cache`
for pid in $ls_cache; do
if [ ! -d /proc/$pid ]; then
rm -rf "$tmp_cache/$pid"
fi
done
ls_cache=`ls $tmp_cache`
if [ "_$ls_cache" = "_" ]; then
rm -rf "$tmp_cache"
fi
}
handle_action() {
local fault_code=$FAULT_CPE_NO_FAULT
if [ "$action" = "get_cache" ]; then
if [ "$__arg1" != "" ]; then
local found=0
for prefix in $prefix_list; do
if [ "$prefix" = "$__arg1" ]; then
found=1
break
fi
done
if [ "$found" != "1" ]; then
echo "Invalid object argument"
return
fi
fi
handle_get_cache "$__arg1"
fi
if [ "$action" = "wait_cache" ]; then
local found=0
handle_get_cache "InternetGatewayDevice." "1"
handle_get_cache "InternetGatewayDevice.ManagementServer."
handle_get_cache "InternetGatewayDevice.DeviceInfo."
handle_get_cache "InternetGatewayDevice.X_INTENO_SE_LoginCfg."
local ls_cache=""
while [ "$found" = "0" ]; do
ls_prefix=`ls $cache_path`
for prefix in $prefix_list; do
[ "${prefix_list_skip_wait_cache/$prefix/}" != "$prefix_list_skip_wait_cache" ] && continue
found=0
for ls_p in $ls_prefix; do
if [ "$prefix" = "$ls_p" ]; then
found=1
break
fi
done
if [ "$found" = "0" ]; then
sleep 1
break
fi
done
if [ "$found" = "1" ]; then
local cache_running=1
while [ "$cache_running" = "1" ]; do
ls_cache=`ls $tmp_cache`
cache_running=0
for pid in $ls_cache; do
if [ -d /proc/$pid ]; then
cache_running=1
sleep 1
break
fi
done
done
fi
done
fi
if [ "$action" = "wait_cache_status" ]; then
local ls_cache=""
ls_prefix=" `ls $cache_path` "
ls_prefix=${ls_prefix//$'\n'/ }
local tmpskip=" $prefix_list_skip_wait_cache "
for ls_p in $prefix_list; do
if [ "${tmpskip/ $ls_p /}" != "$tmpskip" ]; then
echo "skipped $ls_p"
elif [ "${ls_prefix/ $ls_p /}" != "$ls_prefix" ]; then
echo "done $ls_p"
else
local cache_running=0
if [ -d $tmp_cache ]; then
ls_cache=`ls $tmp_cache`
for pid in $ls_cache; do
ls_pid=" `ls $tmp_cache/$pid` "
ls_pid=${ls_pid//$'\n'/ }
if [ "${ls_pid/ $ls_p /}" != "$ls_pid" -a -d "/proc/$pid" ]; then
echo "running $ls_p"
cache_running=1
break
fi
done
fi
if [ "$cache_running" = "0" ]; then
echo "waiting $ls_p"
fi
fi
done
fi
if [ "$action" = "clean_cache" ]; then
rm -rf "$cache_path/"*
fi
if [ "$action" = "get_value" ]; then
get_param_value_generic "$__arg1"
fault_code="$?"
if [ "$fault_code" != "0" ]; then
let fault_code=$fault_code+9000
freecwmp_output "$__arg1" "" "" "" "" "$fault_code"
fi
if [ "$action" = "get_value" -o "$action" = "get_notification" ]; then
/usr/sbin/cwmpd -m 1 $action "$__arg1"
fi
if [ "$action" = "get_name" ]; then
__arg2=`echo $__arg2|tr '[A-Z]' '[a-z]'`
if [ "$__arg2" = "true" ]; then
__arg2=1
elif [ "$__arg2" = "false" ]; then
__arg2=0
fi
if [ "$__arg2" != "0" -a "$__arg2" != "1" ]; then
fault_code="$FAULT_CPE_INVALID_ARGUMENTS"
else
get_param_name_generic "$__arg1" "$__arg2"
fault_code="$?"
fi
if [ "$fault_code" != "0" ]; then
let fault_code=$fault_code+9000
freecwmp_output "$__arg1" "" "" "" "" "$fault_code"
fi
/usr/sbin/cwmpd -m 1 get_name "$__arg1" "$__arg2"
fi
if [ "$action" = "get_notification" ]; then
get_param_notification_generic "$__arg1"
fault_code="$?"
if [ "$fault_code" != "0" ]; then
let fault_code=$fault_code+9000
freecwmp_output "$__arg1" "" "" "" "" "$fault_code"
fi
if [ "$action" = "set_value" ]; then
json_init
json_add_string "parameter" "$__arg1"
json_add_string "value" "$__arg2"
json_dump >> $TMP_SET_VALUE
json_close_object
fi
if [ "$action" = "set_value" ]; then
set_param_value_generic "$__arg1" "$__arg2"
fault_code="$?"
if [ "$fault_code" != "0" ]; then
let fault_code=$fault_code+9000
freecwmp_set_parameter_fault "$__arg1" "$fault_code"
fi
fi
if [ "$action" = "set_notification" ]; then
__arg3=`echo $__arg3|tr '[A-Z]' '[a-z]'`
if [ "$__arg3" = "true" ]; then
__arg3=1
fi
if [ "$__arg3" = "1" ]; then
set_param_notification_generic "$__arg1" "$__arg2"
fault_code="$?"
if [ "$fault_code" != "0" ]; then
let fault_code=$fault_code+9000
freecwmp_set_parameter_fault "$__arg1" "$fault_code"
fi
fi
json_init
json_add_string "parameter" "$__arg1"
json_add_string "value" "$__arg2"
json_dump >> $TMP_SET_NOTIFICATION
json_close_object
fi
if [ "$action" = "apply_value" ]; then
local svargs="-m 1 set_value \"$__arg1\""
local svp svv
while read line; do
json_init
json_load "$line"
json_get_var svp parameter
json_get_var svv value
svargs="$svargs \"$svp\" \"$svv\""
done < $TMP_SET_VALUE
eval "/usr/sbin/cwmpd $svargs"
rm -f $TMP_SET_VALUE
fi
if [ "$action" = "apply_notification" ]; then
local snargs="-m 1 set_notification"
local snp snv
while read line; do
json_init
json_load "$line"
json_get_var snp parameter
json_get_var snv value
snargs="$snargs \"$snp\" \"$snv\""
done < $TMP_SET_NOTIFICATION
eval "/usr/sbin/cwmpd $snargs"
rm -f $TMP_SET_NOTIFICATION
fi
if [ "$action" = "add_object" ]; then
object_fn_generic "$__arg1"
fault_code="$?"
if [ "$fault_code" != "0" ]; then
let fault_code=$fault_code+9000
freecwmp_output "" "" "" "" "" "$fault_code"
else
$UCI_SET cwmp.acs.ParameterKey=$__arg2
$UCI_COMMIT
fi
if [ "$action" = "add_object" -o "$action" = "delete_object" ]; then
/usr/sbin/cwmpd -m 1 get_value "$__arg2" "$__arg1"
fi
if [ "$action" = "delete_object" ]; then
object_fn_generic "$__arg1"
fault_code="$?"
if [ "$fault_code" != "0" ]; then
let fault_code=$fault_code+9000
freecwmp_output "" "" "" "" "" "$fault_code"
else
$UCI_SET cwmp.acs.ParameterKey=$__arg2
$UCI_COMMIT
fi
if [ "$action" = "inform" ]; then
/usr/sbin/cwmpd -m 1 "inform"
fi
if [ "$action" = "download" ]; then
@ -511,140 +250,17 @@ handle_action() {
fi
if [ "$action" = "factory_reset" ]; then
if [ ${FLAGS_dummy} -eq ${FLAGS_TRUE} ]; then
echo "# factory_reset"
else
jffs2_mark_erase "rootfs_data"
sync
ACTION=add INTERFACE=resetbutton /sbin/hotplug-call button
reboot
fi
jffs2_mark_erase "rootfs_data"
sync
ACTION=add INTERFACE=resetbutton /sbin/hotplug-call button
reboot
fi
if [ "$action" = "reboot" ]; then
if [ ${FLAGS_dummy} -eq ${FLAGS_TRUE} ]; then
echo "# reboot"
else
sync
reboot
fi
sync
reboot
fi
if [ "$action" = "apply_notification" -o "$action" = "apply_value" ]; then
if [ ! -f $set_fault_tmp_file ]; then
# applying
local prefix=""
local filename=""
local max_len=0
local len=0
case $action in
apply_notification)
cat $set_tmp_file | while read line; do
json_init
json_load "$line"
json_get_var parameter parameter
json_get_var notification notification
max_len=0
for prefix in $prefix_list; do
case "$parameter" in "$prefix"*)
len=${#prefix}
if [ $len -gt $max_len ]; then
max_len=$len
filename="$prefix"
fi
esac
done
local l=${#parameter}
let l--
if [ "${parameter:$l:1}" != "." ]; then
sed -i "/\<$parameter\>/s%.*%$line%" $cache_path/$filename
else
cat $cache_path/$filename|grep "$parameter"|grep "\"notification\""| while read line; do
json_init
json_load "$line"
json_get_var parameter_name parameter
json_add_string "notification" "$notification"
json_close_object
param=`json_dump`
sed -i "/\<$parameter_name\>/s%.*%$param%" $cache_path/$filename
done
fi
done
freecwmp_output "" "" "" "" "" "" "" "" "0"
;;
apply_value)
local val
local param
cat $set_tmp_file | while read line; do
json_init
json_load "$line"
json_get_var param parameter
json_get_var val value
json_get_var secret_value secret_value
json_get_var notification notification
json_get_var type type
json_get_var set_cmd set_cmd
eval "$set_cmd"
max_len=0
for prefix in $prefix_list; do
case "$param" in "$prefix"*)
len=${#prefix}
if [ $len -gt $max_len ]; then
max_len=$len
filename="$prefix"
fi
esac
done
if [ "$secret_value" != "1" ]; then
sed -i "/\<$param\>/s%.*%$line%" $cache_path/$filename
fi
done
$UCI_SET cwmp.acs.ParameterKey=$__arg1
freecwmp_output "" "" "" "" "" "" "1"
;;
esac
$UCI_COMMIT
else
if [ "$action" = "apply_notification" ]; then
cat $set_fault_tmp_file | head -1
else
cat $set_fault_tmp_file
fi
rm -f $set_fault_tmp_file
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q revert cwmp
fi
rm -f $set_tmp_file
fi
if [ "$action" = "inform" ]; then
rm -f "$cache_linker_dynamic"
rm -f "$cache_path/"*"_dynamic"
get_dynamic_InternetGatewayDevice_WANDevice > "$cache_path/InternetGatewayDevice.WANDevice_dynamic"
local forced_param=`cat "$cache_path/"* | grep "\"forced_inform\""`
echo "$forced_param" | grep "\"value\"" | grep -v "\"dynamic_val\""
echo "$forced_param" | grep "\"dynamic_val\"" | while read line; do
json_init
json_load "$line"
json_get_var exec_get_cmd get_cmd
json_get_var param parameter
json_get_var type type
val=`eval "$exec_get_cmd"`
freecwmp_output "$param" "$val" "" "" "$type"
done
rm -f "$cache_linker_dynamic"
rm -f "$cache_path/"*"_dynamic"
fi
if [ "$action" = "notify" ]; then
freecwmp_notify "$__arg1" "$__arg2"
fi
if [ "$action" = "end_session" ]; then
echo 'rm -f /tmp/end_session.sh' >> /tmp/end_session.sh
/bin/sh /tmp/end_session.sh
fi
if [ "$action" = "allow_cr_ip" ]; then
local port=`$UCI_GET cwmp.cpe.port`
local if_wan=`$UCI_GET cwmp.cpe.default_wan_interface`
@ -657,7 +273,7 @@ handle_action() {
fi
if [ "$action" = "json_continuous_input" ]; then
echo "EOF"
echo "$CWMP_PROMPT"
while read CMD; do
[ -z "$CMD" ] && continue
result=""
@ -683,10 +299,7 @@ handle_action() {
fi
;;
get)
if [ "$action" = "cache" ]; then
json_get_var __arg1 parameter
action="get_cache"
elif [ "$action" = "notification" ]; then
if [ "$action" = "notification" ]; then
json_get_var __arg1 parameter
action="get_notification"
elif [ "$action" = "value" ]; then
@ -742,15 +355,12 @@ handle_action() {
inform)
action="inform"
;;
end_session)
action="end_session"
;;
allow_cr_ip)
action="allow_cr_ip"
json_get_var __arg1 arg
;;
end)
echo "EOF"
echo "$CWMP_PROMPT"
;;
exit)
exit 0
@ -768,6 +378,3 @@ handle_action() {
handle_action 2> /dev/null
if [ ${FLAGS_debug} -eq ${FLAGS_TRUE} ]; then
echo "[debug] exited at \"`date`\""
fi

View file

@ -4,344 +4,12 @@
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
# Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
common_get_cfg_section_ref() {
$UCI_SHOW -X $1 |grep "$1\.[^=.]\+=$2" | sed "$(($3+1))""q;d" | awk -F'[=.]' '{print $2}'
}
ip_to_int() {
local naddr
local ip="$1"
local ip1=${ip%%.*}; ip=${ip#*.}
local ip2=${ip%%.*}; ip=${ip#*.}
local ip3=${ip%%.*}; ip=${ip#*.}
local ip4=${ip%%.*}
let naddr=$ip1*256*256*256+$ip2*256*256+$ip3*256+$ip4 2>/dev/null
echo ${naddr:-0}
}
netmask2cidr ()
{
local x=${1##*255.}
set -- 0^^^128^192^224^240^248^252^254^ $(( (${#1} - ${#x})*2 )) ${x%%.*}
x=${1%%$3*}
echo $(( $2 + (${#x}/4) ))
}
cidr2netmask ()
{
set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0
[ $1 -gt 1 ] && shift $1 || shift
echo ${1-0}.${2-0}.${3-0}.${4-0}
}
get_parameter_by_linker() {
local linker="$1"
local param=""
jmsg=`cat "$cache_path/"* $cache_linker_dynamic | grep "\"linker\"" | grep "\"$linker\"" | head -1`
[ "$jmsg" = "" ] && return
json_load "$jmsg"
json_get_var param parameter
echo "$param"
}
get_linker_by_parameter() {
local param="$1"
local linker=""
jmsg=`cat "$cache_path/"* $cache_linker_dynamic | grep "\"linker\"" | grep "\"$param\"" | head -1`
[ "$jmsg" = "" ] && return
json_load "$jmsg"
json_get_var linker linker
echo "$linker"
}
get_interface_enable_ubus() {
local val=""
local intf="$1"
json_load "$(ifstatus $intf)"
json_get_var val up
echo $val
}
set_interface_enable_ubus() {
local intf="$1"
local val="$2"
val=`echo $val|tr '[A-Z]' '[a-z]'`
if [ "$val" = "true" -o "$val" = "1" ]; then
ubus call network.interface.$intf up '{}' &
elif [ "$val" = "false" -o "$val" = "0" ]; then
ubus call network.interface.$intf down '{}' &
fi
}
create_firewall_zone_config() {
local pfx="$1"
local iface="$2"
local input=${3:-ACCEPT}
local forward=${4:-ACCEPT}
local output=${5:-ACCEPT}
local obj=`$UCI_ADD firewall zone`
$UCI_SET firewall.$obj.name="$pfx"_"$iface"
$UCI_SET firewall.$obj.input=$input
$UCI_SET firewall.$obj.forward=$forward
$UCI_SET firewall.$obj.output=$output
$UCI_SET firewall.$obj.network=$iface
echo $obj
}
get_interface_firewall_enabled() {
local iface="$1"
local i=0
while [ "`$UCI_GET firewall.@zone[$i]`" != "" ]; do
if [ "`$UCI_GET firewall.@zone[$i].network| grep $iface`" != "" ]; then
if [ "`$UCI_GET firewall.@zone[$i].input`" != "ACCEPT" -a "`$UCI_GET firewall.@zone[$i].forward`" != "ACCEPT" ]; then
echo 1; return
fi
fi
let i++
done
echo "0"
}
set_interface_firewall_enabled() {
local iface="$1"
local val="$2"
val=`echo $val|tr '[A-Z]' '[a-z]'`
if [ "$val" = "true" -o "$val" = "1" ]; then
val="DROP"
elif [ "$val" = "false" -o "$val" = "0" ]; then
val="ACCEPT"
else
return
fi
local i=0 cnt=0
while [ "`$UCI_GET firewall.@zone[$i]`" != "" ]; do
if [ "`$UCI_GET firewall.@zone[$i].network| grep $iface`" != "" ]; then
$UCI_SET firewall.@zone[$i].input=$val
$UCI_SET firewall.@zone[$i].forward=$val
let cnt++
fi
let i++
done
if [ "$cnt" = "0" -a "$val" = "DROP" ]; then
local zone=`create_firewall_zone_config "fwl" "$iface" "DROP" "DROP"`
fi
delay_service reload "firewall" "1"
}
get_config_with_enum() {
local path=$1
local enum=$2
local val=`$UCI_GET $path`
local tmp=${enum%%:$val/*}
tmp=${tmp##*/}
if [ "$tmp" = "$enum" -o "$tmp" = "" ]; then
echo $val
else
echo $tmp
fi
}
set_config_with_enum() {
local path=$1
local enum=$2
local val=$3
local tmp=${enum#* $val:}
tmp=${tmp%% *}
if [ "$tmp" != "$enum" -a "$tmp" != "" ]; then
val=$tmp
fi
$UCI_SET $path=$val
}
add_bridge_vlan_interface() {
local dev="$1"
local vid="$2"
local tmp
for tmp in `$UCI_SHOW layer2_interface_vlan | grep "layer2_interface_vlan\.[^.]\+\.vlan8021q=$vid[^0-9]*" | cut -f2 -d.`; do
if [ "`$UCI_GET layer2_interface_vlan.$tmp.baseifname`" = "$dev" ]; then
echo "`$UCI_GET layer2_interface_vlan.$tmp.ifname`"
return
fi
done
tmp=`$UCI_ADD layer2_interface_vlan vlan_interface`
$UCI_SET layer2_interface_vlan.$tmp.baseifname=$dev
$UCI_SET layer2_interface_vlan.$tmp.bridge=1
$UCI_SET layer2_interface_vlan.$tmp.ifname="$dev.$vid"
$UCI_SET layer2_interface_vlan.$tmp.name="vlan_$dev""_$vid"
$UCI_SET layer2_interface_vlan.$tmp.vlan8021p=0
$UCI_SET layer2_interface_vlan.$tmp.vlan8021q=$vid
echo "$dev.$vid"
}
# TODO: merge this one somewhere in OpenWrt
uci_remove_list_element() {
local option="$1"
local value="$2"
local list="$(/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q get $option)"
local elem
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q delete $option
for elem in $list; do
if [ "$elem" != "$value" ]; then
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q add_list $option=$elem
fi
done
}
freecwmp_output() {
local MSG=""
local parameter="$1"
local value="$2"
local permissions="$3"
local notification="$4"
local type="$5"
local fault_code="$6"
local status="$7"
local instance="$8"
local success="$9"
case "$action" in
get_value|inform)
json_init
json_add_string "parameter" "$parameter"
json_add_string "value" "$value"
json_add_string "fault_code" "$fault_code"
if [ "$type" != "" ]; then json_add_string "type" "$type"; fi
json_close_object
MSG=`json_dump`
;;
get_name)
json_init
json_add_string "parameter" "$parameter"
json_add_string "writable" "$permissions"
json_add_string "fault_code" "$fault_code"
json_close_object
MSG=`json_dump`
;;
get_notification)
json_init
json_add_string "parameter" "$parameter"
if [ "$notification" != "" ]; then json_add_string "notification" "$notification"; fi
json_add_string "fault_code" "$fault_code"
json_close_object
MSG=`json_dump`
;;
add_object)
json_init
json_add_string "instance" "$instance"
json_add_string "status" "$status"
json_add_string "fault_code" "$fault_code"
json_close_object
MSG=`json_dump`
;;
delete_object)
json_init
json_add_string "status" "$status"
json_add_string "fault_code" "$fault_code"
json_close_object
MSG=`json_dump`
;;
apply_value)
json_init
json_add_string "status" "$status"
json_close_object
MSG=`json_dump`
;;
apply_notification)
json_init
json_add_string "success" "$success"
json_add_string "fault_code" "$fault_code"
json_close_object
MSG=`json_dump`
;;
esac
echo "$MSG"
}
freecwmp_cache_output_param() {
local MSG=""
local parameter="$1"
local value="$2"
local permission="$3"
local notification="$4"
local type="$5"
local set_cmd="$6"
local get_cmd="$7"
local notif_permission="$8"
local forced_inform="$9"
local secret_value="$10"
local linker="$11"
local dynamic_val="$12"
local change_key="$13"
echo | {
json_init
json_add_string "parameter" "$parameter"
json_add_string "writable" "$permission"
json_add_string "value" "$value"
json_add_string "notification" "$notification"
[ "$type" != "" ] && json_add_string "type" "$type"
[ "$get_cmd" != "" ] && json_add_string "get_cmd" "$get_cmd"
[ "$set_cmd" != "" -a "$permission" = "1" ] && json_add_string "set_cmd" "$set_cmd"
[ "$notif_permission" != "" ] && json_add_string "notif_permission" "$notif_permission"
[ "$forced_inform" != "" ] && json_add_string "forced_inform" "$forced_inform"
[ "$secret_value" != "" ] && json_add_string "secret_value" "$secret_value"
[ "$linker" != "" ] && json_add_string "linker" "$linker"
[ "$dynamic_val" != "" ] && json_add_string "dynamic_val" "$dynamic_val"
[ "$change_key" != "" ] && json_add_string "change_key" "$change_key"
json_close_object
MSG=`json_dump`
echo "$MSG"
}
}
freecwmp_cache_output_obj() {
local MSG=""
local parameter="$1"
local permission="$2"
local notif_permission="$3"
local linker="$4"
local change_key="$5"
echo | {
json_init
json_add_string "parameter" "$parameter"
json_add_string "writable" "$permission"
[ "$notif_permission" != "" ] && json_add_string "notif_permission" "$notif_permission"
[ "$linker" != "" ] && json_add_string "linker" "$linker"
[ "$change_key" != "" ] && json_add_string "change_key" "$change_key"
json_close_object
MSG=`json_dump`
echo "$MSG"
}
}
freecwmp_fault_output() {
local MSG=""
local parameter="$1"
local fault_code="$2"
local success="$3"
case "$action" in
set_value|apply_value)
json_init
json_add_string "parameter" "$parameter"
json_add_string "fault_code" "$fault_code"
json_close_object
MSG=`json_dump`
;;
set_notification|apply_notification)
json_init
json_add_string "success" "$success"
json_add_string "fault_code" "$fault_code"
json_close_object
MSG=`json_dump`
;;
*download)
json_init
json_add_string "fault_code" "$fault_code"
@ -353,267 +21,6 @@ freecwmp_fault_output() {
echo "$MSG"
}
freecwmp_parse_formated_parameter() {
local parameter="$1"
local pattern="$2"
local p="" q=""
local _values="" n=""
local i
local j=0
while [ true ]; do
if [ "_" = "_$parameter" -o "_" = "_$pattern" ]; then
if [ "_$parameter" != "_$pattern" ]; then
eval "export -- \"$3=-1\""
return
else
break
fi
fi
split_param=${parameter%%.*}
split_pattr=${pattern%%.*}
p="$parameter"; q="$pattern"
parameter=${parameter#*.}
pattern=${pattern#*.}
if [ "$p" = "$parameter" -o "$q" = "$pattern" ]; then
if [ "$parameter" != "$pattern" -a "_$pattern" != "_{i}" ]; then
eval "export -- \"$3=-1\""
return
else
break
fi
fi
if [ "_$split_pattr" = "_{i}" ]; then
let n=$split_param-1
if [ $n -lt 0 ]; then
eval "export -- \"$3=-1\""
return
fi
if [ "_$_values" == "_" ]; then
_values="$split_param"
else
_values="$_values $split_param"
fi
elif [ "_$split_param" != "_$split_pattr" ]; then
eval "export -- \"$3=-1\""
return
fi
done
eval "export -- \"$3=0\""
eval "export -- \"$4=\"\"$_values\"\"\""
}
freecwmp_config_cwmp() {
config_get __parameter "$1" "parameter"
config_get __value "$1" "value"
config_get __tags "$1" "tag"
if [ "$__parameter" = "$4" ]; then
if [ "get" = "$2" ]; then
if [ "value" = "$3" ]; then
eval "export -- \"$5=\"\"$__value\"\"\""
fi
if [ "tags" = "$3" ]; then
eval "export -- \"$5=\"\"$__tags\"\"\""
fi
elif [ "set" = "$2" ]; then
if [ "value" = "$3" ]; then
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q set cwmp.$1.value=$5 2> /dev/null
fi
elif [ "check" = "$2" ]; then
if [ "parameter" = "$3" ]; then
eval "export -- \"$5=\"$1\"\""
fi
fi
fi
}
freecwmp_config_notifications() {
config_get __active "$1" "active"
config_get __passive "$1" "passive"
config_get __disabled "$1" "disabled"
local length="0"
for item in $__disabled
do
if [ "$item" = "$3" ]; then
eval "export -- \"$4=0\""
return 0
elif [ "`echo $3|grep $item`" = "$3" -a "`echo $item|grep '\.$'`" != "" ]; then
if [ $length -lt ${#item} ]; then
eval "export -- \"$4=0\""
length="${#item}"
fi
fi
done
for item in $__active
do
if [ "$item" = "$3" ]; then
eval "export -- \"$4=2\""
return 0
elif [ "`echo $3|grep $item`" = "$3" -a "`echo $item|grep '\.$'`" != "" ]; then
if [ $length -lt ${#item} ]; then
eval "export -- \"$4=2\""
length="${#item}"
fi
fi
done
for item in $__passive
do
if [ "$item" = "$3" ]; then
eval "export -- \"$4=1\""
return 0
elif [ "`echo $3|grep $item`" = "$3" -a "`echo $item|grep '\.$'`" != "" ]; then
if [ $length -lt ${#item} ]; then
eval "export -- \"$4=1\""
length="${#item}"
fi
fi
done
return 0
}
freecwmp_get_parameter_value() {
local _parm="$1"
local _val
config_foreach freecwmp_config_cwmp "cwmp" "get" "value" "$_parm" "_val"
echo "$_val"
}
freecwmp_set_parameter_value() {
local _parm="$1"
local _val="$2"
config_foreach freecwmp_config_cwmp "cwmp" "check" "parameter" "$_parm" "_section"
if [ ! "$_section" = "" ]; then
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q set cwmp.$_section.value=$_val 2> /dev/null
else
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q batch << EOF 2>&1 >/dev/null
add cwmp cwmp
set cwmp.@cwmp[-1].parameter="$_parm"
set cwmp.@cwmp[-1].value="$_val"
EOF
fi
}
freecwmp_get_parameter_notification() {
local _dest="$1"
local _parm="$2"
local _val
local _parent
config_foreach freecwmp_config_notifications "notifications" "get" "$_parm" "_val"
if [ "$_val" = "" ]; then
if [ "`echo $_parm|grep '\.$'`" = "" ]; then
_parent="${_parm%.*}."
config_foreach freecwmp_config_notifications "notifications" "get" "$_parent" "_val"
else
_parent="${_parm%.*.}."
config_foreach freecwmp_config_notifications "notifications" "get" "$_parent" "_val"
fi
fi
if [ "$_val" = "" ];then _val="0" ;fi
eval "export -- \"$_dest=$_val\""
}
freecwmp_notify() {
local parm="$1"
local val="$2"
local attribute="$3"
local type="$4"
local param_check="$parm"
if [ "_$attribute" = "_" ]; then
json_msg=`get_param_notification_generic "$parm" | head -1`
json_init
json_load "$json_msg"
json_get_var attribute notification
json_get_var param_check parameter
json_get_var type type
fi
if [ "$param_check" = "$parm" -a "_$attribute" != "_0" ]; then
ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 notify '{ "parameter": "'$parm'", "value": "'$val'", "attribute": "'$attribute'", "type": "'$type'" }' &
fi
}
freecwmp_update_notification() {
local list="$1"
local __parm="$2"
for i in $(/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q get cwmp.@notifications[0].$list);do
if [ "`echo $i|grep $__parm`" != "" ];then
uci_remove_list_element "cwmp.@notifications[0].$list" "$i" 2>/dev/null
fi
done
}
freecwmp_set_parameter_notification() {
local _parm="$1"
local _val="$2"
local tmp=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q get cwmp.@notifications[0] 2>/dev/null`
if [ "$tmp" = "" ]; then
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q add cwmp notifications 2>&1 >/dev/null
else
uci_remove_list_element "cwmp.@notifications[0].passive" "$_parm" 2>/dev/null
uci_remove_list_element "cwmp.@notifications[0].active" "$_parm" 2>/dev/null
uci_remove_list_element "cwmp.@notifications[0].disabled" "$_parm" 2>/dev/null
freecwmp_update_notification "passive" "$_parm" 2>/dev/null
freecwmp_update_notification "active" "$_parm" 2>/dev/null
freecwmp_update_notification "disabled" "$_parm" 2>/dev/null
fi
if [ "`echo $_parm|grep '\.$'`" = "" ]; then
_parent="${_parm%.*}."
config_foreach freecwmp_config_notifications "notifications" "get" "$_parent" "_val_p"
else
_parent="${_parm%.*.}."
config_foreach freecwmp_config_notifications "notifications" "get" "$_parent" "_val_p"
fi
if [ "$_val" -eq "1" ]; then
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q add_list cwmp.@notifications[0].passive="$_parm" 2>&1 >/dev/null
elif [ "$_val" -eq "2" ]; then
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q add_list cwmp.@notifications[0].active="$_parm" 2>&1 >/dev/null
elif [ "$_val" -eq "0" -a "$_val_p" != "" -a "$_val_p" != "0" ]; then
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q add_list cwmp.@notifications[0].disabled="$_parm" 2>&1 >/dev/null
fi
}
delay_service() {
local action="$1"
local service="$2"
local delay="$3"
if [ ! -f /tmp/end_session.sh ];then
ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 command '{ "command": "action_end_session" }' &> /dev/null &
echo '#!/bin/sh' > /tmp/end_session.sh
chmod +x /tmp/end_session.sh
else
check="`cat /tmp/end_session.sh|grep /etc/init.d/$service`"
if [ "$check" != "" ];then
return 0
fi
fi
if [ "$action" = "restart" ]; then
cat << EOF >> /tmp/end_session.sh
/etc/init.d/$service stop &> /dev/null
sleep $delay
/etc/init.d/$service start &> /dev/null
EOF
fi
if [ "$action" = "reload" ]; then
cat << EOF >> /tmp/end_session.sh
sleep $delay
/etc/init.d/$service reload &> /dev/null
EOF
fi
}
freecwmp_set_parameter_fault() {
local parm="$1"
local fault="$2"
freecwmp_fault_output "$parm" "$fault" >> $set_fault_tmp_file
}
freecwmp_check_image()
{
@ -705,373 +112,3 @@ freecwmp_apply_vendor_configuration()
fi
}
get_param_cache_generic() {
local param="$1"
local permission="$2"
local get_cmd="$3"
local set_cmd="$4"
local dynamic_val="$5"
local change_key="$6"
local type="$7"
local notif_permission="$8"
local forced_inform="$9"
local forced_notify="$10"
local secret_value="$11"
local linker="$12"
local val=""
local notification="0"
case "$action" in
get_value|inform)
if [ "$get_cmd" != "" ]; then
val=`eval "$get_cmd"`
fi
dynamic_val=""
;;
get_notification|notify)
if [ "_$forced_notify" = "_" ]; then
freecwmp_get_parameter_notification "notification" $param
else
notification="$forced_notify"
fi
;;
get_linker)
if [ "_$linker" = "_" ]; then
return;
fi
;;
get_cache|wait_cache|add_object)
if [ "$get_cmd" != "" ]; then
val=`eval "$get_cmd"`
fi
if [ "_$forced_notify" = "_" ]; then
freecwmp_get_parameter_notification "notification" $param
else
notification="$forced_notify"
fi
;;
esac
freecwmp_cache_output_param "$param" "$val" "$permission" "$notification" "$type" "$set_cmd" "$get_cmd" "$notif_permission" "$forced_inform" "$secret_value" "$linker" "$dynamic_val" "$change_key"
}
get_object_cache_generic() {
local param=$1
local permission=$2
local notif_permission=$3
local linker=$4
local local change_key=$5
freecwmp_cache_output_obj "$param" "$permission" "$notif_permission" "$linker" "$change_key"
}
get_generic_dynamic() {
local found_prefix="$1"
local param="$2"
local prefix="" get_func="" get_func_link=""
for prefix in $prefix_list; do
case "$prefix" in "$found_prefix"*)
get_func=${prefix%.}
get_func=${get_func//./_}
get_func_link="get_dynamic_linker_""$get_func"
get_func="get_dynamic_""$get_func"
$get_func_link "$param" >>"$cache_linker_dynamic"
$get_func "$param" >"$cache_path/$prefix""_dynamic"
esac
done
}
cat_cache_filter_param() {
cat "$1"* | grep -F "$2"
}
get_param_prefix() {
local parameter="$1"
local max_len=0
local found="" prefix="" len=0
if [ "$parameter" != "" ]; then
for prefix in $prefix_list; do
case "$parameter" in "$prefix"*)
if [ "$parameter" = "$prefix"]; then
found="$prefix"
break
fi
len=${#prefix}
if [ $len -gt $max_len ]; then
max_len=$len
found="$prefix"
fi
esac
done
if [ "$found" = "" ]; then
return $FAULT_CPE_INVALID_PARAMETER_NAME
fi
fi
eval "export -- $2='$found'"
return $FAULT_CPE_NO_FAULT
}
get_generic_cmd() {
local parameter="$1"
local found="$2"
local msgs="" command=""
if [ "$parameter" != "" -a "$parameter" != "$found" ]; then
msgs=`cat "$cache_path/$found"* | grep "\"$parameter\""`
if [ "$msgs" = "" ]; then
return $FAULT_CPE_INVALID_PARAMETER_NAME
fi
l=${#parameter}
let l--
if [ "${parameter:$l:1}" != "." ]; then
command="echo $msgs"
else
command="cat_cache_filter_param $cache_path/$found $parameter"
fi
else
command="cat $cache_path/$found*"
fi
eval "export -- $3='$command'"
return $FAULT_CPE_NO_FAULT
}
get_param_value_generic() {
local parameter=$1
local param="" val="" type="" found_prefix="" cmd=""
get_param_prefix "$parameter" "found_prefix"
local ret="$?"
if [ "$ret" != $FAULT_CPE_NO_FAULT ]; then
return "$ret"
fi
rm -f "$cache_path/"*"_dynamic"
rm -f "$cache_linker_dynamic"
get_generic_dynamic "$found_prefix" "$parameter"
get_generic_cmd "$parameter" "$found_prefix" "cmd"
ret="$?"
if [ "$ret" = $FAULT_CPE_NO_FAULT ]; then
eval '$cmd' | grep "\"value\"" | grep -v "\"dynamic_val\""
eval '$cmd' | grep "\"dynamic_val\"" | while read line; do
json_init
json_load "$line"
json_get_var param parameter
json_get_var val value
json_get_var type type
if [ "$val" = "" ]; then
json_get_var exec_get_cmd get_cmd
val=`eval "$exec_get_cmd"`
fi
freecwmp_output "$param" "$val" "" "" "$type"
done
fi
rm -f "$cache_linker_dynamic"
rm -f "$cache_path/"*"_dynamic"
return "$ret"
}
get_param_name_generic() {
local parameter=$1
local next_level=$2
local found_prefix="" cmd=""
get_param_prefix "$parameter" "found_prefix"
local ret="$?"
if [ "$ret" != $FAULT_CPE_NO_FAULT ]; then
return "$ret"
fi
rm -f "$cache_path/"*"_dynamic"
get_generic_dynamic "$found_prefix" "$parameter"
get_generic_cmd "$parameter" "$found_prefix" "cmd"
ret="$?"
if [ "$ret" = "$FAULT_CPE_NO_FAULT" ]; then
if [ "$next_level" = "0" ]; then
eval '$cmd'
else
if [ "$parameter" != "" ]; then
local len=${#parameter}
let len--
if [ "${parameter:$len:1}" != "." ]; then
return $FAULT_CPE_INVALID_ARGUMENTS
fi
eval '$cmd' | grep -v "$parameter[A-Za-z_0-9]\+\.[A-Za-z_0-9]" | grep -v "\"$parameter\""
else
eval '$cmd' | grep -v "$parameter[A-Za-z_0-9]\+\.[A-Za-z_0-9]"
fi
fi
fi
rm -f "$cache_path/"*"_dynamic"
return $ret
}
get_param_notification_generic() {
local parameter=$1
local found_prefix="" cmd=""
get_param_prefix "$parameter" "found_prefix"
local ret="$?"
if [ "$ret" != $FAULT_CPE_NO_FAULT ]; then
return "$ret"
fi
rm -f "$cache_path/"*"_dynamic"
get_generic_dynamic "$found_prefix" "$parameter"
get_generic_cmd "$parameter" "$found_prefix" "cmd"
ret="$?"
if [ "$ret" = "$FAULT_CPE_NO_FAULT" ]; then
eval '$cmd' | grep "\"notification\""
fi
rm -f "$cache_path/"*"_dynamic"
return $ret
}
set_param_value_generic() {
local param="$1"
local val="$2"
local max_len=0
local found_prefix="" msgs="" prefix="" len="" permission="" set_cmd=""
if [ "$param" = "" ]; then
return $FAULT_CPE_INVALID_PARAMETER_NAME
fi
for prefix in $prefix_list; do
case "$param" in "$prefix"*)
if [ "$param" = "$prefix" ]; then
return $FAULT_CPE_INVALID_PARAMETER_NAME
fi
len=${#prefix}
if [ $len -gt $max_len ]; then
max_len=$len
found_prefix="$prefix"
fi
esac
done
if [ "$found_prefix" = "" ]; then
return $FAULT_CPE_INVALID_PARAMETER_NAME
fi
rm -f "$cache_path/"*"_dynamic"
get_generic_dynamic "$found_prefix" "$param"
msgs=`cat "$cache_path/$found_prefix"* | grep "\"$param\"" | grep "\"value\"" | head -1`
rm -f "$cache_path/"*"_dynamic"
if [ "$msgs" = "" ]; then
return $FAULT_CPE_INVALID_PARAMETER_NAME
fi
json_init
json_load "$msgs"
json_get_var writable writable
if [ "$writable" != "1" ];then
return $FAULT_CPE_NON_WRITABLE_PARAMETER
fi
json_add_string "value" "$val"
json_close_object
echo "`json_dump`" >> $set_tmp_file
return $FAULT_CPE_NO_FAULT
}
set_param_notification_generic() {
local param="$1"
local notification="$2"
local max_len=0
local same="0"
local found_prefix="" msgs="" cmd="" prefix="" len="" line="" notif_permission=""
if [ "$param" != "" ]; then
for prefix in $prefix_list; do
case "$param" in "$prefix"*)
if [ "$param" = "$prefix"]; then
same="1"
found_prefix="$prefix"
break
fi
len=${#prefix}
if [ $len -gt $max_len ]; then
max_len=$len
found_prefix="$prefix"
fi
esac
done
if [ "$found_prefix" = "" ]; then
return $FAULT_CPE_INVALID_PARAMETER_NAME
fi
rm -f "$cache_path/"*"_dynamic"
get_generic_dynamic "$found_prefix" "$param"
msgs=`cat "$cache_path/$found_prefix"* | grep "\"$param\""`
rm -f "$cache_path/"*"_dynamic"
if [ "$msgs" = "" ]; then
return $FAULT_CPE_INVALID_PARAMETER_NAME
fi
else
rm -f "$cache_path/"*"_dynamic"
get_generic_dynamic "$found_prefix" "$param"
msgs=`cat "$cache_path/"* | grep "\"[A-Za-z_0-9]\+\.\""`
rm -f "$cache_path/"*"_dynamic"
fi
echo "$msgs" | while read line; do
json_init
json_load "$line"
json_get_var notif_permission notif_permission
if [ "$notif_permission" = "0" ]; then
return $FAULT_CPE_NOTIFICATION_REJECTED
fi
json_get_var param parameter
freecwmp_set_parameter_notification "$param" "$notification"
json_add_string "notification" "$notification"
json_close_object
echo "`json_dump`" >> $set_tmp_file
done
return $?
}
object_fn_generic() {
local object="$1"
local prefix=""
local found=""
local max_len=0
local len=0
for prefix in $prefix_list; do
case "$object" in "$prefix"*)
len=${#prefix}
if [ $len -gt $max_len ]; then
max_len=$len
found="$prefix"
fi
esac
done
if [ "$found" = "" ];then
return $FAULT_CPE_INVALID_PARAMETER_NAME
fi
local fn=${found%.}
fn=${fn//./_}
local f="$action"_"$fn"
$f "$1" "$found"
return $?
}

View file

@ -1,88 +0,0 @@
#!/bin/sh
# Copyright (C) 2011-2012 Luka Perkov <freecwmp@lukaperkov.net>
# Copyright (C) 2013 Inteno Broadband Technology AB
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
# Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
prefix_list="$prefix_list InternetGatewayDevice.DeviceInfo."
get_device_manufactureroui() {
local val=""
val=`cat /proc/nvram/BaseMacAddr | awk '{ print \$1\$2\$3}' 2> /dev/null`
echo "$val"
}
get_device_info_hardware_version() {
local val=""
local dslAnnex=""
dslAnnex=`cat /proc/nvram/dslAnnex 2> /dev/null`
val=`cat /etc/iop_version | cut -d'-' -f1 | sed s/$/"$dslAnnex"/ 2> /dev/null`
echo "$val"
}
get_device_info_uptime() {
local val=""
val=`cat /proc/uptime | cut -f1 -d'.'`
echo "$val"
}
get_base_mac_addr() {
json_load "$(ubus call router info)"
json_select system
local mac
json_get_var mac basemac
echo "$mac"
}
get_catv_enabled () {
local val=""
val=`$UCI_GET catv.catv.enable`
case "$val" in
on) echo 1;;
off) echo 0;;
esac
}
set_catv_enabled () {
local val="$1"
local stat=""
case "$val" in
1) stat="on";;
0) stat="off";;
esac
$UCI_SET catv.catv.enable="$stat"
delay_service restart "catv" "1"
}
get_cache_InternetGatewayDevice_DeviceInfo() {
get_object_cache_generic "InternetGatewayDevice.DeviceInfo." "0" "0"
get_param_cache_generic "InternetGatewayDevice.DeviceInfo.Manufacturer" "0" "\$UCI_GET cwmp.cpe.manufacturer" "" "" "cwmp.cpe.manufacturer" "" "" "1"
get_param_cache_generic "InternetGatewayDevice.DeviceInfo.ManufacturerOUI" "0" "get_device_manufactureroui" "" "" "" "" "" "1"
get_param_cache_generic "InternetGatewayDevice.DeviceInfo.ModelName" "0" "db get hw.board.routerModel" "" "" "" "" "" "1"
get_param_cache_generic "InternetGatewayDevice.DeviceInfo.ProductClass" "0" "db get hw.board.iopVersion | cut -d'_' -f1" "" "" "" "" "" "1"
get_param_cache_generic "InternetGatewayDevice.DeviceInfo.SerialNumber" "0" "db get hw.board.serialNumber" "" "" "" "" "" "1"
get_param_cache_generic "InternetGatewayDevice.DeviceInfo.HardwareVersion" "0" "db get hw.board.hardwareVersion" "" "" "" "" "" "1"
get_param_cache_generic "InternetGatewayDevice.DeviceInfo.SoftwareVersion" "0" "db get hw.board.iopVersion | cut -d'_' -f2" "" "" "" "" "0" "1" "2"
get_param_cache_generic "InternetGatewayDevice.DeviceInfo.UpTime" "0" "get_device_info_uptime" "" "1" "" "xsd:unsignedInt"
get_param_cache_generic "InternetGatewayDevice.DeviceInfo.DeviceLog" "0" "dmesg | tail -n5" "" "1"
get_param_cache_generic "InternetGatewayDevice.DeviceInfo.SpecVersion" "0" "freecwmp_get_parameter_value \$param" "" "" "" "" "" "1"
get_param_cache_generic "InternetGatewayDevice.DeviceInfo.ProvisioningCode" "1" "freecwmp_get_parameter_value \$param" "freecwmp_set_parameter_value \$param \$val" "" "cwmp.cpe.provisioning_code" "" "0" "1" "2"
get_param_cache_generic "InternetGatewayDevice.DeviceInfo.X_INTENO_SE_BaseMacAddr" "0" "get_base_mac_addr"
get_param_cache_generic "InternetGatewayDevice.DeviceInfo.X_INTENO_SE_CATVEnabled" "1" "get_catv_enabled" "set_catv_enabled \$val"
}
get_dynamic_InternetGatewayDevice_DeviceInfo() {
return $FAULT_CPE_NO_FAULT
}
get_dynamic_linker_InternetGatewayDevice_DeviceInfo() {
return $FAULT_CPE_NO_FAULT
}
add_object_InternetGatewayDevice_DeviceInfo() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
delete_object_InternetGatewayDevice_DeviceInfo() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}

File diff suppressed because it is too large Load diff

View file

@ -1,50 +0,0 @@
#!/bin/sh
# Copyright (C) 2013-2015 Inteno Broadband Technology AB
# Author Anis Ellouze <anis.ellouze@pivasoftware.com>
prefix_list="$prefix_list InternetGatewayDevice.LANInterfaces."
get_lan_ethernet_interface_number() {
local nbr=`db get hw.board.ethernetLanPorts | wc -w`
echo ${nbr:-0}
}
get_lan_wlan_configuration_number() {
local nbr=`uci show wireless |grep "wireless.@wifi-iface\[[0-9]\]\+=wifi-iface" | awk -F '[][]' '{print $2}' | wc -l`
echo ${nbr:-0}
}
get_cache_InternetGatewayDevice_LANInterfaces() {
local ei wi=0
get_object_cache_generic "InternetGatewayDevice.LANInterfaces." "0"
get_param_cache_generic "InternetGatewayDevice.LANInterfaces.LANEthernetInterfaceNumberOfEntries" "0" "get_lan_ethernet_interface_number" "" "" "" "xsd:unsignedInt"
get_param_cache_generic "InternetGatewayDevice.LANInterfaces.LANWLANConfigurationNumberOfEntries" "0" "get_lan_wlan_configuration_number" "" "" "" "xsd:unsignedInt"
get_object_cache_generic "InternetGatewayDevice.LANInterfaces.LANEthernetInterfaceConfig." "0"
for ei in `db get hw.board.ethernetLanPorts`; do
local li=${ei#eth}
get_object_cache_generic "InternetGatewayDevice.LANInterfaces.LANEthernetInterfaceConfig.$li." "0"
get_param_cache_generic "InternetGatewayDevice.LANInterfaces.LANEthernetInterfaceConfig.$li.X_INTENO_COM_EthName" "0" "echo $ei"
done
get_object_cache_generic "InternetGatewayDevice.LANInterfaces.WLANConfiguration." "0"
local nwi=`get_lan_wlan_configuration_number`
while [ $((wi++)) -lt $nwi ]; do
get_object_cache_generic "InternetGatewayDevice.LANInterfaces.WLANConfiguration.$wi." "0"
done
}
add_object_InternetGatewayDevice_LANInterfaces() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
delete_object_InternetGatewayDevice_LANInterfaces() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
get_dynamic_InternetGatewayDevice_LANInterfaces() {
return $FAULT_CPE_NO_FAULT
}
get_dynamic_linker_InternetGatewayDevice_LANInterfaces() {
return $FAULT_CPE_NO_FAULT
}

View file

@ -1,795 +0,0 @@
#!/bin/sh
# Copyright (C) 2013-2015 Inteno Broadband Technology AB
# Author Feten Besbes <feten.besbes@pivasoftware.com>
# Author: Anis Ellouze <anis.ellouze@pivasoftware.com>
prefix_list="$prefix_list InternetGatewayDevice.Layer2Bridging."
set_bridge_bridgename() {
$UCI_RENAME network.$1=$2
delay_service reload "network" "1"
}
get_bridge_vlanid() {
local bridge="$1"
local bkey=`$UCI_GET network.$bridge.bridge_instance`
local inst=`$UCI_SHOW dmmap |sed -n "s/dmmap\.[^.]\+\.instance=$bkey\.//p" | sort -n | head -n1`
[ "$inst" = "" ] && return
local vb=`$UCI_SHOW dmmap | grep "dmmap\.@vlan_bridge\[[0-9]\+\]\.instance=$bkey\.$inst" | cut -f2 -d.`
$UCI_GET dmmap.$vb.vid
}
set_bridge_vlanid() {
local bridge="$1"
local val="$2"
local bkey=`$UCI_GET network.$bridge.bridge_instance`
local inst=`$UCI_SHOW dmmap |sed -n "s/dmmap\.[^.]\+\.instance=$bkey\.//p" | sort -n | head -n1`
if [ "$inst" = "" ]; then
local vb=`$UCI_ADD dmmap vlan_bridge`
local iv=`update_bridge_vlan_instance $vb $bkey`
$UCI_SET dmmap.$vb.bridgekey=$bkey
$UCI_SET dmmap.$vb.name="vlan_$bkey.$iv"
$UCI_SET dmmap.$vb.enable=0
$UCI_SET dmmap.$vb.vid=$val
delay_service reload "network" "1"
else
local vb=`$UCI_SHOW dmmap | grep "dmmap\.@vlan_bridge\[[0-9]\+\]\.instance=$bkey\.$inst" | cut -f2 -d.`
set_bridgevlan_vid "$vb" "$val"
fi
}
set_bridgevlan_enable() {
local vb="$1"
local val="$2"
local vid=`$UCI_GET dmmap.$vb.vid`
vid=`printf '%d' $vid`
local bkey=`$UCI_GET dmmap.$vb.bridgekey`
local cval=`$UCI_GET dmmap.$vb.enable`
val=`echo $val|tr '[A-Z]' '[a-z]'`
if [ "$val" = "true" -o "$val" = "1" ] && [ "$cval" != "1" ]; then
$UCI_SET dmmap.$vb.enable=1
[ $vid -le 0 ] && return
update_add_vlan_interfaces "$bkey" "$vid"
update_add_vlan_to_bridge_interface "$bkey" "$vb"
elif [ "$val" = "false" -o "$val" = "0" ] && [ "$cval" != "0" ]; then
$UCI_SET dmmap.$vb.enable=0
[ $vid -le 0 ] && return
update_remove_vlan_from_bridge_interface "$bkey" "$vb"
else
return
fi
delay_service reload "network" "1"
}
set_bridgevlan_vid() {
local vb="$1"
local val="$2"
local cval=`$UCI_GET dmmap.$vb.vid`
val=`printf '%d' $val`
[ "$val" = "$cval" -o $val -le 0 ] && return
local enable=`$UCI_GET dmmap.$vb.enable`
if [ "$enable" = "1" ]; then
local bkey=`$UCI_GET dmmap.$vb.bridgekey`
update_remove_vlan_from_bridge_interface "$bkey" "$vb"
$UCI_SET dmmap.$vb.vid=$val
update_add_vlan_interfaces "$bkey" "$val"
update_add_vlan_to_bridge_interface "$bkey" "$vb"
delay_service reload "network" "1"
else
$UCI_SET dmmap.$vb.vid=$val
fi
}
set_marking_bridgekey() {
local mb="$1"
local val="$2"
[ "$val" = "" ] && return
local bkey
local obkey=`$UCI_GET dmmap.$mb.bridgekey`
$UCI_SET dmmap.$mb.bridgekey=$val
local baseifname=`$UCI_GET dmmap.$mb.baseifname`
case $baseifname in
cfg*)
bkey=$val
bridge=`$UCI_SHOW network | grep "network\.[^.]\+\.bridge_instance=$bkey" | cut -f2 -d.`
[ "$bridge" = "" ] && return
$UCI_SET wireless.$baseifname.network=$bridge
delay_service reload "network" "1"
;;
eth[1-9])
local bridge
if [ -n "$obkey" ]; then
bridge=`$UCI_SHOW network | grep "network\.[^.]\+\.bridge_instance=$obkey" | cut -f2 -d.`
[ "$bridge" = "" ] && return
local bifname=" `$UCI_GET network.$bridge.ifname` "
bifname=${bifname/ $baseifname / }
bifname=${bifname# }; bifname=${bifname% }
$UCI_SET network.$bridge.ifname="$bifname"
fi
bkey=$val
bridge=`$UCI_SHOW network | grep "network\.[^.]\+\.bridge_instance=$bkey" | cut -f2 -d.`
[ "$bridge" = "" ] && return
bifname="`$UCI_GET network.$bridge.ifname`"
bifname="$bifname $baseifname"
$UCI_SET network.$bridge.ifname="${bifname# }"
delay_service reload "network" "1"
;;
eth0|atm*|ptm*)
bkey=$obkey
local found=0
local cmb cmbs=`$UCI_SHOW dmmap | grep "dmmap\.@marking-bridge\[[0-9]\+\]\.baseifname=$baseifname" | cut -f2 -d.`
for cmb in $cmbs; do
[ "`$UCI_GET dmmap.$cmb.bridgekey`" = "$bkey" ] && { found=1; break; }
done
if [ "$found" = "0" ]; then
local vb vbs=`$UCI_SHOW dmmap | grep "dmmap\.@vlan_bridge\[[0-9]\+\]\.bridgekey=$bkey" | cut -f2 -d.`
for vb in $vbs; do
local vid=`$UCI_GET dmmap.$vb.vid`
[ "$vid" = "" ] && continue
local bridge=`$UCI_SHOW network | grep "network\.[^.]\+\.bridge_instance=$bkey" | cut -f2 -d.`
[ "$bridge" = "" ] && return
local bifname="`$UCI_GET network.$bridge.ifname` "
bifname=${bifname//$baseifname.$vid[^0-9]/}
bifname=${bifname// / }; bifname=${bifname// / }
$UCI_SET network.$bridge.ifname="${bifname% }"
done
fi
bkey=$val
local vb vbs=`$UCI_SHOW dmmap | grep "dmmap\.@vlan_bridge\[[0-9]\+\]\.bridgekey=$bkey" | cut -f2 -d.`
for vb in $vbs; do
local vid=`$UCI_GET dmmap.$vb.vid`
[ "$vid" = "" ] && continue
local enable=`$UCI_GET dmmap.$vb.enable `
[ "$enable" = "" -o "$enable" = "0" ] && continue
update_remove_vlan_from_bridge_interface $bkey $vb
update_add_vlan_interfaces "$bkey" "$vid"
update_add_vlan_to_bridge_interface $bkey $vb
done
delay_service reload "network" "1"
;;
esac
}
set_marking_interfacekey() {
local mb="$1"
local val="$2"
[ "$val" = "" ] && return
local ab=`$UCI_SHOW dmmap | grep "dmmap\.@available-bridge\[[0-9]\+\]\.key=$val" | cut -f2 -d'.' | head -n1`
[ "$ab" = "" ] && return
local bifname=`$UCI_GET dmmap.$ab.baseifname`
local bridge bkey=`$UCI_GET dmmap.$mb.bridgekey`
if [ -n "$bkey" ]; then
bridge=`$UCI_SHOW network | grep "network\.[^.]\+\.bridge_instance=$bkey" | cut -f2 -d.`
if [ -n "$bridge" ]; then
local obifname=`$UCI_GET dmmap.$mb.baseifname`
local instance=`$UCI_GET dmmap.$mb.instance`
if [ -n "$obifname" ]; then
remove_config_interfaces "$obifname" "$bkey" "$bridge" "$instance"
fi
fi
fi
case $bifname in
cfg*)
local tmp=`$UCI_SHOW dmmap | grep "dmmap\.@marking-bridge\[[0-9]\+\]\.baseifname=$bifname"`
[ -n "$tmp" ] && return
$UCI_SET dmmap.$mb.interfacekey=$val
$UCI_SET dmmap.$mb.baseifname=$bifname
[ "$bkey" = "" -o "$bridge" = "" ] && return
$UCI_SET wireless.$bifname.network=$bridge
;;
eth[1-9])
local tmp=`$UCI_SHOW dmmap | grep "dmmap\.@marking-bridge\[[0-9]\+\]\.baseifname=$bifname"`
[ -n "$tmp" ] && return
$UCI_SET dmmap.$mb.interfacekey=$val
$UCI_SET dmmap.$mb.baseifname=$bifname
[ "$bkey" = "" -o "$bridge" = "" ] && return
local brgifname="`$UCI_GET network.$bridge.ifname`"
brgifname="$brgifname $bifname"
$UCI_SET network.$bridge.ifname="${brgifname# }"
delay_service reload "network" "1"
;;
eth0|atm*|ptm*)
$UCI_SET dmmap.$mb.interfacekey=$val
$UCI_SET dmmap.$mb.baseifname=$bifname
[ "$bkey" = "" ] && return
local vb vbs=`$UCI_SHOW dmmap | grep "dmmap\.@vlan_bridge\[[0-9]\+\]\.bridgekey=$bkey" | cut -f2 -d.`
for vb in $vbs; do
local vid=`$UCI_GET dmmap.$vb.vid`
[ "$vid" = "" ] && continue
local enable=`$UCI_GET dmmap.$vb.enable `
[ "$enable" = "" -o "$enable" = "0" ] && continue
update_remove_vlan_from_bridge_interface $bkey $vb
update_add_vlan_interfaces "$bkey" "$vid"
update_add_vlan_to_bridge_interface $bkey $vb
done
delay_service reload "network" "1"
;;
esac
}
update_remove_vlan_from_bridge_interface() {
local bkey="$1"
local vb="$2"
local bridge=`$UCI_SHOW network | grep "network\.[^.]\+\.bridge_instance=$bkey" | cut -f2 -d.`
[ "$bridge" = "" ] && return
local vid=`$UCI_GET dmmap.$vb.vid`
local bifname="`$UCI_GET network.$bridge.ifname` "
bifname=${bifname//[aep]t[mh][0-9].$vid[^0-9]/}
bifname=${bifname// / }; bifname=${bifname// / }
$UCI_SET network.$bridge.ifname="${bifname% }"
}
update_add_vlan_to_bridge_interface() {
local bkey="$1"
local vb="$2"
local bridge=`$UCI_SHOW network | grep "network\.[^.]\+\.bridge_instance=$bkey" | cut -f2 -d.`
[ "$bridge" = "" ] && return
local vid=`$UCI_GET dmmap.$vb.vid`
[ "$vid" = "" ] && return
local bifname="`$UCI_GET network.$bridge.ifname` "
local ifname vifname=""
local mb mbs=`$UCI_SHOW dmmap | grep "dmmap\.@marking-bridge\[[0-9]\+\]\.bridgekey=$bkey" | cut -f2 -d'.'`
for mb in $mbs; do
ifname=`$UCI_GET dmmap.$mb.baseifname`
case "$ifname" in
eth0|atm*|ptm*)
ifname="$ifname.$vid"
[ "${bifname/$ifname[^0-9]/}" != "$bifname" ] && continue
bifname="$bifname$ifname "
;;
esac
done
bifname=${bifname% }; bifname=${bifname# }
$UCI_SET network.$bridge.ifname="${bifname% }"
}
update_add_vlan_interfaces() {
local bkey="$1"
local vid="$2"
local ifname mb mbs=`$UCI_SHOW dmmap | grep "dmmap\.@marking-bridge\[[0-9]\+\]\.bridgekey=$bkey" | cut -f2 -d'.'`
for mb in $mbs; do
ifname=`$UCI_GET dmmap.$mb.baseifname`
local vif=`$UCI_SHOW layer2_interface_vlan | grep "layer2_interface_vlan\.@vlan_interface\[[0-9]\+\]\.ifname=$ifname.$vid" | cut -f2 -d.`
if [ "$vif" = "" ]; then
case "$ifname" in
eth0|atm*|ptm*)
vif=`$UCI_ADD layer2_interface_vlan vlan_interface`
$UCI_SET layer2_interface_vlan.$vif.baseifname=$ifname
$UCI_SET layer2_interface_vlan.$vif.bridge=1
$UCI_SET layer2_interface_vlan.$vif.ifname=$ifname.$vid
$UCI_SET layer2_interface_vlan.$vif.name=$ifname.$vid
$UCI_SET layer2_interface_vlan.$vif.vlan8021q=$vid
;;
esac
fi
done
}
update_bridge_instance() {
local iface="$1"
local inst=`$UCI_GET network.$iface.bridge_instance`
if [ "$inst" != "" ]; then
echo "$inst"
else
local inst=`$UCI_SHOW network |sed -n "s/network\.[^.]\+\.bridge_instance=//p" | sort -rn | head -n1`
inst=${inst:-0}
$UCI_SET network.$iface.bridge_instance="$((++inst))"
$UCI_COMMIT
echo $inst
fi
}
update_bridge_vlan_instance() {
local bvlan="$1"
local ib="$2"
local inst=`$UCI_GET dmmap.$bvlan.instance`
if [ "$inst" != "" ]; then
echo "${inst#.}"
else
inst=`$UCI_SHOW dmmap |sed -n "s/dmmap\.[^.]\+\.instance=$ib\.//p" | sort -rn | head -n1`
inst=${inst:-0}
$UCI_SET dmmap.$bvlan.instance="$ib.$((++inst))"
$UCI_COMMIT
echo $inst
fi
}
update_bridge_all_vlan_config_bybridge() {
local bridge="$1"
local bkey="$2"
local ifname ifnames=`$UCI_GET network.$bridge.ifname`
for ifname in $ifnames; do
case "$ifname" in
eth0*|atm*|ptm*)
local vid=${ifname#*.}
local vlan=`$UCI_SHOW layer2_interface_vlan | grep "layer2_interface_vlan\.@vlan_interface\[[0-9]\+\]\.ifname=$ifname" | cut -f2 -d.`
[ "$vlan" = "" ] && continue
update_bridge_vlan_config "$bridge" "$bkey" "$vid" "$vlan"
;;
esac
done
$UCI_COMMIT
}
update_bridge_vlan_config() {
local bridge="$1"
local bkey="$2"
local vid="$3"
local vlan="$4"
local cbridgevlan=`$UCI_SHOW dmmap | grep "dmmap\.@vlan_bridge\[[0-9]\+\]\.vid=$vid" | cut -f2 -d.`
if [ "$cbridgevlan" = "" ]; then
cbridgevlan=`$UCI_ADD dmmap vlan_bridge`
local iv=`update_bridge_vlan_instance "$cbridgevlan" "$bkey"`
$UCI_SET dmmap.$cbridgevlan.bridgekey=$bkey
$UCI_SET dmmap.$cbridgevlan.vid=$vid
$UCI_SET dmmap.$cbridgevlan.name=vlan_$bkey.$iv
fi
}
update_availableinterface_list() {
local iface="$1"
local key
local ciface=`$UCI_SHOW dmmap | grep "dmmap\.@available-bridge\[[0-9]\+\]\.baseifname=$iface" | cut -f2 -d'.' | head -n1`
if [ "$ciface" != "" ]; then
$UCI_GET dmmap.$ciface.key
return
fi
key=`$UCI_SHOW dmmap |sed -n "s/dmmap\.@available-bridge\[[0-9]\+\]\.key=//p" | sort -rn | head -n1`
key=${key:-0}
ciface=`$UCI_ADD dmmap available-bridge`
$UCI_SET dmmap.$ciface.baseifname=$iface
$UCI_SET dmmap.$ciface.key=$((++key))
$UCI_COMMIT
echo $key
}
update_markinginterface_list() {
local bkey="$1"
local iface="$2"
local found ifname ifnames=`$UCI_GET network.$iface.ifname`
for ifname in $ifnames; do
found=0
ifname=${ifname%.*}
local mb mbs=`$UCI_SHOW dmmap | grep "dmmap\.@marking-bridge\[[0-9]\+\]\.baseifname=$ifname" | cut -f2 -d'.'`
for mb in $mbs; do
[ "`$UCI_GET dmmap.$mb.bridgekey`" = "$bkey" ] && { found=1; break; }
done
[ "$found" = "1" ] && continue
local ciface=`$UCI_SHOW dmmap | grep "dmmap\.@available-bridge\[[0-9]\+\]\.baseifname=$ifname" | cut -f2 -d'.' | head -n1`
local interfacekey=`$UCI_GET dmmap.$ciface.key`
local inst=`$UCI_SHOW dmmap |sed -n "s/dmmap\.@marking-bridge\[[0-9]\+\]\.instance=//p" | sort -rn | head -n1`
inst=${inst:-0}
mb=`$UCI_ADD dmmap marking-bridge`
$UCI_SET dmmap.$mb.baseifname=$ifname
$UCI_SET dmmap.$mb.bridgekey=$bkey
$UCI_SET dmmap.$mb.interfacekey=$interfacekey
$UCI_SET dmmap.$mb.instance="$((++inst))"
done
local wifi wifis=`$UCI_SHOW -X wireless | grep "wireless\.[^.=]\+=wifi-iface" | awk -F'[.=]' '{print $2}'`
for wifi in $wifis; do
[ "`$UCI_GET wireless.$wifi.network`" != "$iface" ] && continue
ifname="$wifi"
found=0
local mb mbs=`$UCI_SHOW dmmap | grep "dmmap\.@marking-bridge\[[0-9]\+\]\.baseifname=$ifname" | cut -f2 -d'.'`
for mb in $mbs; do
[ "`$UCI_GET dmmap.$mb.bridgekey`" = "$bkey" ] && { found=1; break; }
done
[ "$found" = "1" ] && continue
local ciface=`$UCI_SHOW dmmap | grep "dmmap\.@available-bridge\[[0-9]\+\]\.baseifname=$ifname" | cut -f2 -d'.' | head -n1`
local interfacekey=`$UCI_GET dmmap.$ciface.key`
local inst=`$UCI_SHOW dmmap |sed -n "s/dmmap\.@marking-bridge\[[0-9]\+\]\.instance=//p" | sort -rn | head -n1`
inst=${inst:-0}
mb=`$UCI_ADD dmmap marking-bridge`
$UCI_SET dmmap.$mb.baseifname=$ifname
$UCI_SET dmmap.$mb.bridgekey=$bkey
$UCI_SET dmmap.$mb.interfacekey=$interfacekey
$UCI_SET dmmap.$mb.instance="$((++inst))"
done
$UCI_COMMIT
}
set_associated_interfaces() {
local iface=$1
shift
local val="$*"
$UCI_SET network.$iface.ifname="$val"
delay_service reload "network" "1"
}
get_cache_object_bridge_vlan() {
local ib="$1"
local vb="$2"
local iv="$3"
get_object_cache_generic "InternetGatewayDevice.Layer2Bridging.Bridge.$ib.VLAN.$iv." "1"
get_param_cache_generic "InternetGatewayDevice.Layer2Bridging.Bridge.$ib.VLAN.$iv.VLANEnable" "1" "\$UCI_GET dmmap.$vb.enable" "set_bridgevlan_enable $vb \$val" "" "" "xsd:boolean"
get_param_cache_generic "InternetGatewayDevice.Layer2Bridging.Bridge.$ib.VLAN.$iv.VLANName" "1" "\$UCI_GET dmmap.$vb.name" "\$UCI_SET dmmap.$vb.name=\$val"
get_param_cache_generic "InternetGatewayDevice.Layer2Bridging.Bridge.$ib.VLAN.$iv.VLANID" "1" "\$UCI_GET dmmap.$vb.vid" "set_bridgevlan_vid $vb \$val" "" "" "xsd:unsignedInt"
}
get_cache_object_bridge() {
local iface="$1"
local ib="$2"
get_object_cache_generic "InternetGatewayDevice.Layer2Bridging.Bridge.$ib." "1"
get_param_cache_generic "InternetGatewayDevice.Layer2Bridging.Bridge.$ib.BridgeEnable" "1" "get_interface_enable_ubus $iface" "set_interface_enable_ubus $iface \$val" "1" "" "xsd:boolean"
get_param_cache_generic "InternetGatewayDevice.Layer2Bridging.Bridge.$ib.BridgeKey" "0" "echo $ib" "" "" "" "xsd:unsignedInt"
get_param_cache_generic "InternetGatewayDevice.Layer2Bridging.Bridge.$ib.BridgeName" "1" "echo $iface" "set_bridge_bridgename $iface \$val"
get_param_cache_generic "InternetGatewayDevice.Layer2Bridging.Bridge.$ib.VLANID" "1" "get_bridge_vlanid $iface" "set_bridge_vlanid $iface \$val" "" "" "xsd:unsignedInt"
get_param_cache_generic "InternetGatewayDevice.Layer2Bridging.Bridge.$ib.X_INTENO_COM_AssociatedInterfaces" "1" "\$UCI_GET network.$iface.ifname" "set_associated_interfaces $iface \$val"
get_object_cache_generic "InternetGatewayDevice.Layer2Bridging.Bridge.$ib.VLAN." "1"
update_bridge_all_vlan_config_bybridge $iface $ib
local vb vbs=`$UCI_SHOW dmmap | grep "dmmap\.@vlan_bridge\[[0-9]\+\]\.bridgekey=$ib" | awk -F'[][]' '{print $2}'`
for vb in $vbs; do
local xvb=`$UCI_SHOW -X dmmap |grep "dmmap\.[^=.]\+=vlan_bridge" | sed "$((vb+1))""q;d" | awk -F'[=.]' '{print $2}'`
if [ "$xvb" != "" ]; then
local iv=`$UCI_GET dmmap.$xvb.instance`
get_cache_object_bridge_vlan "$ib" "$xvb" "${iv#*.}"
fi
done
}
get_cache_object_availableinterface() {
local ia="$1"
local oface="$2"
local key="$3"
local type="$4"
get_object_cache_generic "InternetGatewayDevice.Layer2Bridging.AvailableInterface.$ia." "0"
get_param_cache_generic "InternetGatewayDevice.Layer2Bridging.AvailableInterface.$ia.AvailableInterfaceKey" "0" "echo $key" "" "" "" "xsd:unsignedInt"
get_param_cache_generic "InternetGatewayDevice.Layer2Bridging.AvailableInterface.$ia.InterfaceReference" "0" "echo $oface"
get_param_cache_generic "InternetGatewayDevice.Layer2Bridging.AvailableInterface.$ia.InterfaceType" "0" "echo $type"
}
get_cache_object_marking() {
local im="$1"
local mb="$2"
get_object_cache_generic "InternetGatewayDevice.Layer2Bridging.Marking.$im." "1"
get_param_cache_generic "InternetGatewayDevice.Layer2Bridging.Marking.$im.MarkingBridgeReference" "1" "\$UCI_GET dmmap.$mb.bridgekey" "set_marking_bridgekey $mb \$val" "" "" "xsd:int"
get_param_cache_generic "InternetGatewayDevice.Layer2Bridging.Marking.$im.MarkingInterface" "1" "\$UCI_GET dmmap.$mb.interfacekey" "set_marking_interfacekey $mb \$val"
}
get_cache_InternetGatewayDevice_Layer2Bridging() {
local ib=0 iface
get_object_cache_generic "InternetGatewayDevice.Layer2Bridging." "0"
get_object_cache_generic "InternetGatewayDevice.Layer2Bridging.AvailableInterface." "0"
local adev idev cdev ia
for adev in "$WAN_INST_ETH:ethernet" "$WAN_INST_ATM:adsl" "$WAN_INST_PTM:vdsl";do
idev=${adev%:*}
cdev=${adev#*:}
local fwan wans=`$UCI_SHOW layer2_interface_$cdev | sed -n "s/layer2_interface_$cdev\.[^.]\+\.baseifname=//p" | sort -u`
for fwan in $wans; do
local iwan=${fwan##*[hm]};
local oface="InternetGatewayDevice.WANDevice.$idev.WANConnectionDevice.$((++iwan))."
ia=`update_availableinterface_list "$fwan"`
get_cache_object_availableinterface "$ia" "$oface" "$ia" "WANInterface"
done
done
local eth eths=`db get hw.board.ethernetLanPorts`
for eth in $eths; do
local ieth=${eth#eth}
local oface="InternetGatewayDevice.LANInterfaces.LANEthernetInterfaceConfig.$ieth."
ia=`update_availableinterface_list "$eth"`
get_cache_object_availableinterface "$ia" "$oface" "$ia" "LANInterface"
done
local wi=0
local wifi wifis=`$UCI_SHOW -X wireless | grep "wireless\.[^.=]\+=wifi-iface" | awk -F'[.=]' '{print $2}'`
for wifi in $wifis; do
local oface="InternetGatewayDevice.LANInterfaces.WLANConfiguration.$((++wi))."
ia=`update_availableinterface_list "$wifi"`
get_cache_object_availableinterface "$ia" "$oface" "$ia" "LANInterface"
done
get_object_cache_generic "InternetGatewayDevice.Layer2Bridging.Bridge." "1"
local ifaces=`$UCI_SHOW network | grep "network\.[^=]\+=interface" | cut -d. -f2 | cut -d= -f1`
for iface in $ifaces; do
if [ "`$UCI_GET network.$iface.type`" = "bridge" ]; then
ib=`update_bridge_instance $iface`
update_markinginterface_list "$ib" "$iface"
get_cache_object_bridge "$iface" "$ib"
fi
done
get_object_cache_generic "InternetGatewayDevice.Layer2Bridging.Marking." "1"
local mb mbs=`$UCI_SHOW dmmap | grep "dmmap\.@marking-bridge\[[0-9]\+\]\.instance=" | awk -F'[][]' '{print $2}'`
for mb in $mbs; do
local xmb=`$UCI_SHOW -X dmmap |grep "dmmap\.[^=.]\+=marking-bridge" | sed "$((mb+1))""q;d" | awk -F'[=.]' '{print $2}'`
local im=`$UCI_GET dmmap.$xmb.instance`
get_cache_object_marking "$im" "$xmb"
done
}
add_layer2bridging_bridge() {
local filename="$1"
local ib=`$UCI_SHOW network |sed -n "s/network\.[^.]\+\.bridge_instance=//p" | sort -rn | head -n1`
ib=${ib:-0}
iface="bridge_0_$((++ib))"
$UCI_SET network.$iface=interface
$UCI_SET network.$iface.bridge_instance=$ib
$UCI_SET network.$iface.type=bridge
$UCI_SET network.$iface.proto=dhcp
$UCI_COMMIT
delay_service reload "network" "1"
get_cache_object_bridge "$iface" "$ib" >> $cache_path/$filename
freecwmp_output "" "" "" "" "" "" "1" "$ib"
return $FAULT_CPE_NO_FAULT
}
delete_layer2bridging_bridge() {
local instance="$2"
local filename="$3"
local tmp=`$UCI_SHOW network |grep "network\.[^.]\+\.bridge_instance=$instance[^0-9]*" | cut -d. -f2`
if [ "$tmp" = "" ]; then return $FAULT_CPE_INVALID_PARAMETER_NAME; fi
$UCI_SET network.$tmp.type=
$UCI_SET network.$tmp.bridge_instance=
local vb vbs=`$UCI_SHOW dmmap | grep "dmmap\.@vlan_bridge\[[0-9]\+\]\.bridgekey=$instance" | cut -f2 -d.`
for vb in $vbs; do
$UCI_DELETE dmmap.$vb
done
$UCI_COMMIT
delay_service reload "network" "1"
freecwmp_output "" "" "" "" "" "" "1"
sed -i "/$1/d" $cache_path/$filename
return $FAULT_CPE_NO_FAULT
}
delete_layer2bridging_bridge_all() {
local filename="$3"
local bridge bridge_list=`$UCI_SHOW network |grep "network\.[^.]\+\.bridge_instance=" | cut -d. -f2`
for bridge in $bridge_list; do
$UCI_SET network.$bridge.type=
$UCI_SET network.$bridge.bridge_instance=
done
local ivb ivbs=`$UCI_SHOW dmmap | grep "dmmap\.@vlan_bridge\[[0-9]\+\]\.bridgekey=" | awk -F '[][]' '{print $2}' | sort -rn`
for ivb in $ivbs; do
$UCI_DELETE dmmap.@vlan_bridge[$ivb]
done
$UCI_COMMIT
delay_service reload "network" "1"
freecwmp_output "" "" "" "" "" "" "1"
sed -i "/$1[0-9]\+\./d" $cache_path/$filename
return $FAULT_CPE_NO_FAULT
}
add_layer2bridging_marking() {
local filename="$1"
local inst=`$UCI_SHOW dmmap |sed -n "s/dmmap\.@marking-bridge\[[0-9]\+\]\.instance=//p" | sort -rn | head -n1`
inst=${inst:-0}
mb=`$UCI_ADD dmmap marking-bridge`
$UCI_SET dmmap.$mb.instance="$((++inst))"
$UCI_COMMIT
get_cache_object_marking "$inst" "$mb" >> $cache_path/$filename
freecwmp_output "" "" "" "" "" "" "1" "$inst"
return $FAULT_CPE_NO_FAULT
}
remove_config_interfaces(){
local baseifname="$1"
local bkey="$2"
local bridge="$3"
local mbi="$4"
case $baseifname in
cfg*)
$UCI_SET wireless.$baseifname.network=
;;
eth[1-9])
local bifname=" `$UCI_GET network.$bridge.ifname` "
bifname=${bifname// $baseifname / }
bifname=${bifname# }; bifname=${bifname% };
$UCI_SET network.$bridge.ifname="$bifname"
;;
eth0|atm*|ptm*)
local found=0
local cmb cmbs=`$UCI_SHOW dmmap | grep "dmmap\.@marking-bridge\[[0-9]\+\]\.baseifname=$baseifname" | cut -f2 -d.`
for cmb in $cmbs; do
[ "`$UCI_GET dmmap.$cmb.bridgekey`" = "$bkey" -a "`$UCI_GET dmmap.$cmb.instance`" != "$mbi" ] && { found=1; break; }
done
if [ "$found" = "0" ]; then
local vb vbs=`$UCI_SHOW dmmap | grep "dmmap\.@vlan_bridge\[[0-9]\+\]\.bridgekey=$bkey" | cut -f2 -d.`
for vb in $vbs; do
local vid=`$UCI_GET dmmap.$vb.vid`
[ "$vid" = "" ] && continue
local bifname=" `$UCI_GET network.$bridge.ifname` "
bifname=${bifname// $baseifname.$vid / }
bifname=${bifname# }; bifname=${bifname% };
$UCI_SET network.$bridge.ifname="$bifname"
done
fi
;;
esac
}
delete_layer2bridging_marking() {
local instance="$2"
local filename="$3"
local tmp=`$UCI_SHOW dmmap |grep "dmmap\.@marking-bridge\[[0-9]\+\]\.instance=$instance" | cut -d. -f2`
if [ "$tmp" = "" ]; then return $FAULT_CPE_INVALID_PARAMETER_NAME; fi
local bkey=`$UCI_GET dmmap.$tmp.bridgekey`
local baseifname=`$UCI_GET dmmap.$tmp.baseifname`
$UCI_DELETE dmmap.$tmp
[ -z "$bkey" ] && return
local bridge=`$UCI_SHOW network | grep "network\.[^.]\+\.bridge_instance=$bkey" | cut -f2 -d.`
[ "$bridge" = "" ] && return
remove_config_interfaces "$baseifname" "$bkey" "$bridge"
$UCI_COMMIT
delay_service reload "network" "1"
freecwmp_output "" "" "" "" "" "" "1"
sed -i "/$1/d" $cache_path/$filename
return $FAULT_CPE_NO_FAULT
}
delete_layer2bridging_marking_all() {
local filename="$3"
local mb mbs=`$UCI_SHOW dmmap |grep "dmmap\.@marking-bridge\[[0-9]\+\]\.instance" | awk -F '[][]' '{print $2}' | sort -rn`
for mb in $mbs; do
local bkey=`$UCI_GET dmmap.@marking-bridge[$mb].bridgekey`
local baseifname=`$UCI_GET dmmap.@marking-bridge[$mb].baseifname`
$UCI_DELETE dmmap.@marking-bridge[$mb]
[ -z "$bkey" ] && continue
local bridge=`$UCI_SHOW network | grep "network\.[^.]\+\.bridge_instance=$bkey" | cut -f2 -d.`
[ "$bridge" = "" ] && continue
remove_config_interfaces "$baseifname" "$bkey" "$bridge"
done
$UCI_COMMIT
delay_service reload "network" "1"
freecwmp_output "" "" "" "" "" "" "1"
sed -i "/$1[0-9]\+\./d" $cache_path/$filename
return $FAULT_CPE_NO_FAULT
}
add_layer2bridging_bridge_vlan() {
local ibridge="$1"
local filename="$2"
local bridge=`$UCI_SHOW network | grep "network\.[^.]\+\.bridge_instance=$ibridge" | cut -f2 -d.`
[ "$bridge" = "" ] && return $FAULT_CPE_INVALID_PARAMETER_NAME;
local vb=`$UCI_ADD dmmap vlan_bridge`
local iv=`update_bridge_vlan_instance $vb $ibridge`
$UCI_SET dmmap.$vb.bridgekey=$ibridge
$UCI_SET dmmap.$vb.name="vlan_$ibridge.$iv"
$UCI_SET dmmap.$vb.enable=0
$UCI_COMMIT
get_cache_object_bridge_vlan "$ibridge" "$vb" "$iv" >> $cache_path/$filename
freecwmp_output "" "" "" "" "" "" "1" "$iv"
return $FAULT_CPE_NO_FAULT
}
delete_layer2bridging_bridge_vlan() {
local instances="$2"
local filename="$3"
instances=${instances// /.}
local vb=`$UCI_SHOW dmmap | grep "dmmap\.@vlan_bridge\[[0-9]\+\]\.instance=$instances" | cut -f2 -d'.' | head -n1`
[ "$vb" = "" ] && return $FAULT_CPE_INVALID_PARAMETER_NAME
local bridge=`$UCI_SHOW network | grep "network\.[^.]\+\.bridge_instance=${instances%.*}" | cut -f2 -d.`
[ "$bridge" = "" ] && return $FAULT_CPE_INTERNAL_ERROR
local vid=`$UCI_GET dmmap.$vb.vid`
local bifname="`$UCI_GET network.$bridge.ifname` "
bifname=${bifname// [aep]t[mh][0-9].$vid / }
bifname=${bifname# }; bifname=${bifname% }
$UCI_SET network.$bridge.ifname="$bifname"
$UCI_DELETE dmmap.$vb
$UCI_COMMIT
delay_service reload "network" "1"
freecwmp_output "" "" "" "" "" "" "1"
sed -i "/$1/d" $cache_path/$filename
return $FAULT_CPE_NO_FAULT
}
delete_layer2bridging_bridge_vlan_all() {
local instances="$2"
local filename="$3"
local bridge=`$UCI_SHOW network | grep "network\.[^.]\+\.bridge_instance=${instances}" | cut -f2 -d.`
[ "$bridge" = "" ] && return $FAULT_CPE_INVALID_PARAMETER_NAME
local ivb ivbs=`$UCI_SHOW dmmap | grep "dmmap\.@vlan_bridge\[[0-9]\+\]\.instance=$instances\." | awk -F '[][]' '{print $2}' | sort -rn`
for ivb in $ivbs; do
local vid=`$UCI_GET dmmap.@vlan_bridge[$ivb].vid`
local bifname=" `$UCI_GET network.$bridge.ifname` "
bifname=${bifname// [aep]t[mh][0-9].$vid / }
bifname=${bifname# }; bifname=${bifname% }
$UCI_SET network.$bridge.ifname="$bifname"
$UCI_DELETE dmmap.@vlan_bridge[$ivb]
done
$UCI_COMMIT
delay_service reload "network" "1"
freecwmp_output "" "" "" "" "" "" "1"
sed -i "/$1[0-9]\+\./d" $cache_path/$filename
return $FAULT_CPE_NO_FAULT
}
add_object_InternetGatewayDevice_Layer2Bridging() {
local filename="$2"
local fault_code
case $1 in
InternetGatewayDevice.Layer2Bridging.Bridge.[1-9]*.VLAN.)
freecwmp_parse_formated_parameter "$1" "InternetGatewayDevice.Layer2Bridging.Bridge.{i}.VLAN." "rc" "ibridge"
if [ "$rc" != "0" ]; then
return $FAULT_CPE_INVALID_PARAMETER_NAME;
fi
add_layer2bridging_bridge_vlan "$ibridge" "$filename"
fault_code="$?"
return $fault_code
;;
InternetGatewayDevice.Layer2Bridging.Bridge.)
add_layer2bridging_bridge "$filename"
fault_code="$?"
return $fault_code
;;
InternetGatewayDevice.Layer2Bridging.Marking.)
add_layer2bridging_marking "$filename"
fault_code="$?"
return $fault_code
;;
esac
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
delete_object_InternetGatewayDevice_Layer2Bridging() {
local filename="$2"
local fault_code instances
case $1 in
InternetGatewayDevice.Layer2Bridging.Bridge.[1-9]*.VLAN.[1-9]*.)
freecwmp_parse_formated_parameter "$1" "InternetGatewayDevice.Layer2Bridging.Bridge.{i}.VLAN.{i}." "rc" "instances"
if [ "$rc" != "0" ]; then return $FAULT_CPE_INVALID_PARAMETER_NAME; fi
delete_layer2bridging_bridge_vlan "$1" "$instances" "$filename"
fault_code="$?"
return $fault_code
;;
InternetGatewayDevice.Layer2Bridging.Bridge.[1-9]*.VLAN.)
freecwmp_parse_formated_parameter "$1" "InternetGatewayDevice.Layer2Bridging.Bridge.{i}.VLAN." "rc" "instances"
if [ "$rc" != "0" ]; then return $FAULT_CPE_INVALID_PARAMETER_NAME; fi
delete_layer2bridging_bridge_vlan_all "$1" "$instances" "$filename"
fault_code="$?"
return $fault_code
;;
InternetGatewayDevice.Layer2Bridging.Bridge.[1-9]*.)
freecwmp_parse_formated_parameter "$1" "InternetGatewayDevice.Layer2Bridging.Bridge.{i}." "rc" "instances"
if [ "$rc" != "0" ]; then return $FAULT_CPE_INVALID_PARAMETER_NAME; fi
delete_layer2bridging_bridge "$1" "$instances" "$filename"
fault_code="$?"
return $fault_code
;;
InternetGatewayDevice.Layer2Bridging.Bridge.)
delete_layer2bridging_bridge_all "$1" "" "$filename"
fault_code="$?"
return $fault_code
;;
InternetGatewayDevice.Layer2Bridging.Marking.[1-9]*.)
freecwmp_parse_formated_parameter "$1" "InternetGatewayDevice.Layer2Bridging.Marking.{i}." "rc" "instances"
if [ "$rc" != "0" ]; then return $FAULT_CPE_INVALID_PARAMETER_NAME; fi
delete_layer2bridging_marking "$1" "$instances" "$filename"
fault_code="$?"
return $fault_code
;;
InternetGatewayDevice.Layer2Bridging.Marking.)
delete_layer2bridging_marking_all "$1" "" "$filename"
fault_code="$?"
return $fault_code
;;
esac
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
get_dynamic_InternetGatewayDevice_Layer2Bridging() {
return $FAULT_CPE_NO_FAULT
}
get_dynamic_linker_InternetGatewayDevice_Layer2Bridging() {
return $FAULT_CPE_NO_FAULT
}

View file

@ -1,391 +0,0 @@
#!/bin/sh
# Copyright (C) 2014 Inteno Broadband Technology AB
# Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
prefix_list="$prefix_list InternetGatewayDevice.Layer3Forwarding."
hex_to_ip() {
local hex="$1"
printf "%d.%d.%d.%d" 0x${hex:0:2} 0x${hex:2:2} 0x${hex:4:2} 0x${hex:6:2}
}
ip_to_hex() {
local ip="$1"
local ip1=${ip%%.*}; ip=${ip#*.}
local ip2=${ip%%.*}; ip=${ip#*.}
local ip3=${ip%%.*}; ip=${ip#*.}
local ip4=${ip%%.*}
printf "%02X%02X%02X%02X" $ip1 $ip2 $ip3 $ip4
}
proc_get_route_var_by_conf() {
local route="$1"
local varn="$2"
local dest=`$UCI_GET network.$route.target`
dest=`ip_to_hex $dest`
local mask=`$UCI_GET network.$route.netmask`
mask=${mask:-255.255.255.255}
mask=`ip_to_hex $mask`
awk '$2=="'"$dest"'" && $8=="'"$mask"'"{print $'"$varn"'}' /proc/net/route
}
set_layer3_def_conn_serv() {
local val="$1"
local linker=`get_linker_by_parameter "$val"`
local interface=${linker#*:}
[ "$interface" = "" ] && return
$UCI_SET cwmp.cpe.default_wan_interface=$interface
delay_service reload "network" "1"
}
get_layer3_nbr_entry() {
local pr=`cat /proc/net/route | wc -l`
local proute ln=0 pr=0
while read proute; do
[ "$ln" = "0" ] && { let ln++; continue; }
local found="0"
local dest=`echo $proute | awk '{print $2}'`; dest=`hex_to_ip $dest`
local mask=`echo $proute | awk '{print $8}'`; mask=`hex_to_ip $mask`
local route routes=`$UCI_SHOW network | grep "network\.@route[^=]\+=route" | cut -d. -f2 | cut -d= -f1`
for route in $routes; do
cdest=`$UCI_GET network.$route.target`; cdest=${cdest:-0.0.0.0}
cmask=`$UCI_GET network.$route.netmask`;cmask=${cmask:-255.255.255.255}
if [ "$cdest" = "$dest" -a "$cmask" = "$mask" ]; then
found="1"
break
fi
done
[ "$found" = "0" ] && let pr++
done < /proc/net/route
local dr=`$UCI_SHOW network | grep "network\.@route_disabled\[[0-9]\+\]=route_disabled" | wc -l`
local cr=`$UCI_SHOW network | grep "network\.@route\[[0-9]\+\]=route" | wc -l`
echo $((pr+dr+cr))
}
get_layer3_enable() {
local route="$1"
case $route in
cfg[0-9]*)
if [ "`$UCI_GET network.$route`" = "route_disabled" ]; then
echo 0
else
[ "`proc_get_route_var_by_conf $route 1`" = "" ] && echo 0 || echo 1
fi
;;
*)
echo 1
;;
esac
}
set_layer3_enable() {
local route="$1"
local val="$2"
local droute sroute="$route"
local enable=`$UCI_GET network.$route`
val=`echo $val|tr '[A-Z]' '[a-z]'`
if [ "$val" = "true" -o "$val" = "1" ]; then
[ "`$enable" = "route_disabled" ] && droute="route" || return
elif [ "$val" = "false" -o "$val" = "0" ]; then
[ "`$enable" = "route_disabled" ] && droute="route_disabled" || return
else
return
fi
local rc rconfigs=`$UCI_SHOW network.$sroute |sed -n "s/network\.[^.]\+\.//p"`
route=`$UCI_ADD network $droute`
for rc in $rconfigs; do
$UCI_SET network.$route.$rc
done
$UCI_DELETE network.$sroute
delay_service reload "network" "1"
}
get_layer3_status() {
local eb=`get_layer3_enable "$1"`
[ "$eb" = "1" ] && echo "Enabled" || echo "Disabled"
}
get_layer3_type() {
local route="$1"
local val
case "$route" in
cfg[0-9]*)
val=`$UCI_GET network.$route.netmask`
;;
*)
val=`echo $route | awk '{print $8}'`
val=`hex_to_ip $val`
;;
esac
[ "$val" = "255.255.255.255" -o "$val" = "" ] && echo "Host" || echo "Network"
}
get_layer3_destip() {
local route="$1"
local val
case "$route" in
cfg[0-9]*)
val=`$UCI_GET network.$route.target`
;;
*)
val=`echo $route | awk '{print $2}'`
val=`hex_to_ip $val`
;;
esac
[ "$val" = "" ] && echo "0.0.0.0" || echo "$val"
}
set_layer3_destip() {
local route="$1"
local val="$2"
$UCI_SET network.$route.target=$val
delay_service reload "network" "1"
}
get_layer3_destmask() {
local route="$1"
local val
case "$route" in
cfg[0-9]*)
val=`$UCI_GET network.$route.netmask`
;;
*)
val=`echo $route | awk '{print $8}'`
val=`hex_to_ip $val`
;;
esac
[ "$val" = "" ] && echo "255.255.255.255" || echo "$val"
}
set_layer3_destmask() {
local route="$1"
local val="$2"
$UCI_SET network.$route.netmask=$val
delay_service reload "network" "1"
}
get_layer3_gatewayip() {
local route="$1"
local val
case "$route" in
cfg[0-9]*)
val=`$UCI_GET network.$route.gateway`
;;
*)
val=`echo $route | awk '{print $3}'`
val=`hex_to_ip $val`
;;
esac
[ "$val" = "" ] && echo "0.0.0.0" || echo "$val"
}
set_layer3_gatewayip() {
local route="$1"
local val="$2"
$UCI_SET network.$route.gateway=$val
delay_service reload "network" "1"
}
get_layer3_interface() {
local route="$1"
local val=""
case "$route" in
cfg[0-9]*)
val=`$UCI_GET network.$route.interface`
;;
*)
bval=`echo $route | awk '{print $1}'`
local val=${bval/br-/}
if [ "$bval" = "$val" ]; then
local device iface ifaces=`$UCI_SHOW network | grep "network\.[^.]\+\.ifname=.*$val" | cut -f2 -d.`
for iface in $ifaces; do
json_load "$(ifstatus $iface)"
json_get_var device device
if [ "$device" = "$val" ]; then
val="$iface"
break
fi
done
fi
;;
esac
echo "$val"
}
get_layer3_interface_linker_parameter() {
local iface="$1"
local val=""
[ "$iface" = "" ] && return
val="$(get_parameter_by_linker linker_interface:$iface)"
echo $val
}
set_layer3_interface_linker_parameter() {
local route="$1"
local val="$2"
local linker=`get_linker_by_parameter "$val"`
local interface=${linker#*:}
[ "$interface" = "" ] && return
$UCI_SET network.$route.interface=$interface
delay_service reload "network" "1"
}
get_layer3_metric() {
local route="$1"
local val
case "$route" in
cfg[0-9]*)
val=`$UCI_GET network.$route.metric`
;;
*)
val=`echo $route | awk '{print $7}'`
;;
esac
val=${val:-0}
echo "$val"
}
set_layer3_metric() {
local route="$1"
local val="$2"
$UCI_SET network.$route.metric=$val
delay_service reload "network" "1"
}
get_layer3_mtu() {
local route="$1"
local val
case "$route" in
cfg[0-9]*)
val=`$UCI_GET network.$route.mtu`
;;
*)
val=`echo $route | awk '{print $9}'`
;;
esac
val=${val:-1500}
echo "$val"
}
set_layer3_mtu() {
local route="$1"
local val="$2"
$UCI_SET network.$route.mtu=$val
delay_service reload "network" "1"
}
update_layer3_instance() {
local route="$1"
local inst=`$UCI_GET network.$route.layer3_instance`
if [ "$inst" != "" ]; then
echo "$inst"
else
local inst=`$UCI_SHOW network |sed -n "s/network\.@route[^.]\+\.layer3_instance=//p" | sort -rn | head -n1`
inst=${inst:-0}
$UCI_SET network.$route.layer3_instance="$((++inst))"
$UCI_COMMIT
echo $inst
fi
}
get_cache_object_layer3() {
local route="$1"
local il="$2"
local p="$3"
get_object_cache_generic "InternetGatewayDevice.Layer3Forwarding.Forwarding.$il." "0"
get_param_cache_generic "InternetGatewayDevice.Layer3Forwarding.Forwarding.$il.Enable" "$p" "get_layer3_enable \"$route\"" "set_layer3_enable $route \$val" "" "$([ $p = 1 ] && echo network.$route)" "xsd:boolean"
get_param_cache_generic "InternetGatewayDevice.Layer3Forwarding.Forwarding.$il.Status" "0" "get_layer3_status \"$route\"" "" "" "$([ $p = 1 ] && echo network.$route)"
get_param_cache_generic "InternetGatewayDevice.Layer3Forwarding.Forwarding.$il.Type" "0" "get_layer3_type \"$route\"" "" "" "$([ $p = 1 ] && echo network.$route.netmask)"
get_param_cache_generic "InternetGatewayDevice.Layer3Forwarding.Forwarding.$il.DestIPAddress" "$p" "get_layer3_destip \"$route\"" "set_layer3_destip $route \$val" "" "$([ $p = 1 ] && echo network.$route.target)"
get_param_cache_generic "InternetGatewayDevice.Layer3Forwarding.Forwarding.$il.DestSubnetMask" "$p" "get_layer3_destmask \"$route\"" "set_layer3_destmask $route \$val" "" "$([ $p = 1 ] && echo network.$route.netmask)"
get_param_cache_generic "InternetGatewayDevice.Layer3Forwarding.Forwarding.$il.SourceIPAddress" "0" "echo 0.0.0.0"
get_param_cache_generic "InternetGatewayDevice.Layer3Forwarding.Forwarding.$il.SourceSubnetMask" "0" "echo 0.0.0.0"
get_param_cache_generic "InternetGatewayDevice.Layer3Forwarding.Forwarding.$il.GatewayIPAddress" "$p" "get_layer3_gatewayip \"$route\"" "set_layer3_gatewayip $route \$val" "" "$([ $p = 1 ] && echo network.$route.gateway)"
get_param_cache_generic "InternetGatewayDevice.Layer3Forwarding.Forwarding.$il.Interface" "$p" "get_layer3_interface_linker_parameter $(get_layer3_interface "$route")" "set_layer3_interface_linker_parameter $route \$val" "1" "$([ $p = 1 ] && echo network.$route.interface)"
get_param_cache_generic "InternetGatewayDevice.Layer3Forwarding.Forwarding.$il.ForwardingMetric" "$p" "get_layer3_metric \"$route\"" "set_layer3_metric $route \$val" "" "$([ $p = 1 ] && echo network.$route.metric)"
get_param_cache_generic "InternetGatewayDevice.Layer3Forwarding.Forwarding.$il.MTU" "$p" "get_layer3_mtu \"$route\"" "set_layer3_mtu $route \$val" "" "$([ $p = 1 ] && echo network.$route.mtu)"
}
get_cache_InternetGatewayDevice_Layer3Forwarding() {
local il=0 route
get_object_cache_generic "InternetGatewayDevice.Layer3Forwarding." "0"
get_object_cache_generic "InternetGatewayDevice.Layer3Forwarding.Forwarding." "0"
get_param_cache_generic "InternetGatewayDevice.Layer3Forwarding.DefaultConnectionService" "1" "get_parameter_by_linker linker_interface:\$default_wan" "set_layer3_def_conn_serv \$val" "1"
get_param_cache_generic "InternetGatewayDevice.Layer3Forwarding.ForwardNumberOfEntries" "0" "get_layer3_nbr_entry" "" "1" "" "xsd:unsignedInt"
local route routes=`$UCI_SHOW network | grep "network\.@route[^=]\+=route" | cut -d. -f2 | cut -d= -f1`
for route in $routes; do
local xroute=`common_get_cfg_section_ref "route" "route" "$route"`
il=`update_layer3_instance $xroute`
get_cache_object_layer3 "$xroute" "$il" "1"
done
}
get_dynamic_InternetGatewayDevice_Layer3Forwarding() {
case "$1" in
""|\
InternetGatewayDevice.|\
InternetGatewayDevice.Layer3Forwarding.|\
InternetGatewayDevice.Layer3Forwarding.Forwarding.|\
InternetGatewayDevice.Layer3Forwarding.Forwarding.[1-9].|\
InternetGatewayDevice.Layer3Forwarding.Forwarding.[1-9].*|\
InternetGatewayDevice.Layer3Forwarding.Forwarding.[1-9][0-9].|\
InternetGatewayDevice.Layer3Forwarding.Forwarding.[1-9][0-9].*|\
InternetGatewayDevice.Layer3Forwarding.Forwarding.[1-9][0-9][0-9].|\
InternetGatewayDevice.Layer3Forwarding.Forwarding.[1-9][0-9][0-9].*)
local inst=`$UCI_SHOW network |sed -n "s/network\.@route[^.]\+\.layer3_instance=//p" | sort -rn | head -n1`
inst=${inst:-0}
local proute
cat /proc/net/route | tail -n+2 | while read proute; do
local found="0"
local dest=`echo $proute | awk '{print $2}'`; dest=`hex_to_ip $dest`
local mask=`echo $proute | awk '{print $8}'`; mask=`hex_to_ip $mask`
local route routes=`$UCI_SHOW network | grep "network\.@route[^=]\+=route" | cut -d. -f2 | cut -d= -f1`
for route in $routes; do
cdest=`$UCI_GET network.$route.target`; cdest=${cdest:-0.0.0.0}
cmask=`$UCI_GET network.$route.netmask`;cmask=${cmask:-255.255.255.255}
if [ "$cdest" = "$dest" -a "$cmask" = "$mask" ]; then
found="1"
break
fi
done
if [ "$found" = "0" ]; then
get_cache_object_layer3 "$proute" "$((++inst))" "0"
fi
done
esac
return $FAULT_CPE_NO_FAULT
}
get_dynamic_linker_InternetGatewayDevice_Layer3Forwarding() {
case "$action" in
get_value|set_value)
case "$1" in
""|\
InternetGatewayDevice.|\
InternetGatewayDevice.Layer3Forwarding.|\
InternetGatewayDevice.Layer3Forwarding.DefaultConnectionService|\
InternetGatewayDevice.Layer3Forwarding.Forwarding.|\
InternetGatewayDevice.Layer3Forwarding.Forwarding.[1-9].|\
InternetGatewayDevice.Layer3Forwarding.Forwarding.[1-9][0-9].|\
InternetGatewayDevice.Layer3Forwarding.Forwarding.[1-9][0-9][0-9].|\
InternetGatewayDevice.Layer3Forwarding.Forwarding.[1-9]*.Interface)
local current_action="$action"
action="get_linker"
get_dynamic_InternetGatewayDevice_WANDevice
action="$current_action"
;;
esac
;;
esac
return $FAULT_CPE_NO_FAULT
}
add_object_InternetGatewayDevice_Layer3Forwarding() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
delete_object_InternetGatewayDevice_Layer3Forwarding() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}

View file

@ -1,96 +0,0 @@
#!/bin/sh
# Copyright (C) 2011-2012 Luka Perkov <freecwmp@lukaperkov.net>
# Copyright (C) 2013 Inteno Broadband Technology AB
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
# Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
prefix_list="$prefix_list InternetGatewayDevice.ManagementServer."
get_management_server_connection_request_url() {
local val
if [ -z "$default_management_server_connection_request_url" ]; then
local tmp_value=${FLAGS_value}
FLAGS_value=${FLAGS_TRUE}
local tmp_json=${FLAGS_json}
FLAGS_json=${FLAGS_FALSE}
local ip=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q -P /var/state get cwmp.cpe.ip`
local port=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q -P /var/state get cwmp.cpe.port`
FLAGS_value=$tmp_value
FLAGS_json=$tmp_json
if [ -n "$ip" -a -n "$port" ]; then
val="http://$ip:$port/"
fi
else
val=$default_management_server_connection_request_url
fi
echo $val
}
get_management_server_periodic_inform_time() {
local val=""
val=`$UCI_GET cwmp.acs.periodic_inform_time`
if [ "$val" != "0" -a "$val" != "" ];then
val=`date -d @$val +"%Y-%m-%dT%H:%M:%S.000Z"`
else
val="0001-01-01T00:00:00Z"
fi
echo "$val"
}
set_management_server_periodic_inform_time() {
local val="$1"
if [ "$val" != "0001-01-01T00:00:00Z" ];then
val=`echo $val|sed 's/Z//g'`
val=`echo $val|sed 's/T/ /g'`
val=${val%%.*}
val=`date -d "$val" "+%s"`
else
val=0
fi
$UCI_SET cwmp.acs.periodic_inform_time="$val"
ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 command '{ "command": "reload_end_session" }' &> /dev/null &
}
set_management_server_url() {
local val=$1
$UCI_SET cwmp.acs.dhcp_discovery="disable"
set_management_server "cwmp.acs.url" "$val"
}
set_management_server() {
local uci_name=$1
local val=$2
$UCI_SET $uci_name="$val"
ubus ${UBUS_SOCKET:+-s $UBUS_SOCKET} call tr069 command '{ "command": "reload_end_session" }' &> /dev/null &
}
get_cache_InternetGatewayDevice_ManagementServer() {
get_object_cache_generic "InternetGatewayDevice.ManagementServer." "0" "0"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.URL" "1" "\$UCI_GET cwmp.acs.url" "set_management_server_url \$val" "" "cwmp.acs.url"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.Username" "1" "\$UCI_GET cwmp.acs.userid" "set_management_server cwmp.acs.userid \$val" "" "cwmp.acs.userid"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.Password" "1" "" "set_management_server cwmp.acs.passwd \$val" "" "" "" "" "" "" "1"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.ParameterKey" "1" "\$UCI_GET cwmp.acs.ParameterKey" "set_management_server cwmp.acs.ParameterKey \$val" "" "cwmp.acs.ParameterKey" "" "0" "1"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.PeriodicInformEnable" "1" "\$UCI_GET cwmp.acs.periodic_inform_enable" "set_management_server cwmp.acs.periodic_inform_enable \$val" "" "cwmp.acs.periodic_inform_enable" "xsd:boolean"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.PeriodicInformInterval" "1" "\$UCI_GET cwmp.acs.periodic_inform_interval" "set_management_server cwmp.acs.periodic_inform_interval \$val" "" "cwmp.acs.periodic_inform_interval" "xsd:unsignedInt"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.PeriodicInformTime" "1" "get_management_server_periodic_inform_time" "set_management_server_periodic_inform_time \$val" "" "cwmp.acs.periodic_inform_time" "xsd:dateTime"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.ConnectionRequestURL" "0" "get_management_server_connection_request_url" "" "1" "" "" "0" "1" "2"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.ConnectionRequestUsername" "1" "\$UCI_GET cwmp.cpe.userid" "set_management_server cwmp.cpe.userid \$val" "" "cwmp.cpe.userid"
get_param_cache_generic "InternetGatewayDevice.ManagementServer.ConnectionRequestPassword" "1" "" "set_management_server cwmp.cpe.passwd \$val" "" "" "" "" "" "" "1"
}
get_dynamic_InternetGatewayDevice_ManagementServer() {
return $FAULT_CPE_NO_FAULT
}
get_dynamic_linker_InternetGatewayDevice_ManagementServer() {
return $FAULT_CPE_NO_FAULT
}
add_object_InternetGatewayDevice_ManagementServer() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
delete_object_InternetGatewayDevice_ManagementServer() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}

View file

@ -1,30 +0,0 @@
#!/bin/sh
# Copyright (C) 2013 Inteno Broadband Technology AB
# Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
#InternetGatewayDevice.
prefix_list="InternetGatewayDevice. $prefix_list"
get_cache_InternetGatewayDevice() {
get_object_cache_generic "InternetGatewayDevice." "0" "0"
}
get_dynamic_InternetGatewayDevice() {
return $FAULT_CPE_NO_FAULT
}
get_dynamic_linker_InternetGatewayDevice() {
return $FAULT_CPE_NO_FAULT
}
add_object_InternetGatewayDevice() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
delete_object_InternetGatewayDevice() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
#Device.
#To be added

View file

@ -1,85 +0,0 @@
#!/bin/sh
# Copyright (C) 2013 Inteno Broadband Technology AB
# Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
# Author Feten Besbes <feten.besbes@pivasoftware.com>
prefix_list="$prefix_list InternetGatewayDevice.Time."
get_time_ntpserver() {
local ntp_num="$1"
local val=`$UCI_GET system.ntp.server | awk -F ' ' -v var=$ntp_num '{print $var}'`
[ "$val" = "none" ] && val=""
echo $val
}
set_time_ntpserver() {
local ntp_num="$1"
local val="$2"
local ntp_servers serv
local count=1
[ "$val" = "" ] && val="none"
ntp_servers=`$UCI_GET system.ntp.server`
$UCI_DELETE system.ntp.server
for serv in $ntp_servers; do
if [ "$count" -eq "$ntp_num" ]; then
$UCI_ADD_LIST system.ntp.server="$val"
else
$UCI_ADD_LIST system.ntp.server="$serv"
fi
let count++
done
while [ $count -le $ntp_num ]; do
if [ "$count" = "$ntp_num" ]; then
$UCI_ADD_LIST system.ntp.server="$val"
else
$UCI_ADD_LIST system.ntp.server="none"
fi
let count++
done
if [ -f /etc/rc.d/*sysntpd ]; then delay_service restart "sysntpd" "1"; fi
}
get_time_enable() {
if [ -f /etc/rc.d/*sysntpd ]; then echo "true"
else echo "false"; fi
echo $val
}
set_time_enable() {
local val="$1"
val=`echo $val|tr '[A-Z]' '[a-z]'`
if [ "$val" = "true" -o "$val" = "1" ]; then
delay_service restart "sysntpd" "1"
/etc/init.d/sysntpd enable
elif [ "$val" = "false" -o "$val" = "0" ]; then
if [ "`pidof ntpd`" != "" ]; then /etc/init.d/sysntpd stop; fi
/etc/init.d/sysntpd disable
fi
}
get_cache_InternetGatewayDevice_Time() {
get_object_cache_generic "InternetGatewayDevice.Time." "0"
get_param_cache_generic "InternetGatewayDevice.Time.Enable" "1" "get_time_enable" "set_time_enable \$val" "1" "" "xsd:boolean"
get_param_cache_generic "InternetGatewayDevice.Time.NTPServer1" "1" "get_time_ntpserver 1" "set_time_ntpserver 1 \$val" "" "system.ntp.server"
get_param_cache_generic "InternetGatewayDevice.Time.NTPServer2" "1" "get_time_ntpserver 2" "set_time_ntpserver 2 \$val" "" "system.ntp.server"
get_param_cache_generic "InternetGatewayDevice.Time.NTPServer3" "1" "get_time_ntpserver 3" "set_time_ntpserver 3 \$val" "" "system.ntp.server"
get_param_cache_generic "InternetGatewayDevice.Time.NTPServer4" "1" "get_time_ntpserver 4" "set_time_ntpserver 4 \$val" "" "system.ntp.server"
get_param_cache_generic "InternetGatewayDevice.Time.NTPServer5" "1" "get_time_ntpserver 5" "set_time_ntpserver 5 \$val" "" "system.ntp.server"
}
get_dynamic_InternetGatewayDevice_Time() {
return $FAULT_CPE_NO_FAULT
}
get_dynamic_linker_InternetGatewayDevice_Time() {
return $FAULT_CPE_NO_FAULT
}
add_object_InternetGatewayDevice_Time() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
delete_object_InternetGatewayDevice_Time() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}

View file

@ -1,52 +0,0 @@
#!/bin/sh
# Copyright (C) 2014 Inteno Broadband Technology AB
# Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
prefix_list="$prefix_list InternetGatewayDevice.UPnP."
get_upnp_enable() {
local val=`$UCI_GET upnpd.config.enabled`
echo ${val:-1}
}
set_upnp_enable() {
local val="$1"
val=`echo $val|tr '[A-Z]' '[a-z]'`
if [ "$val" = "true" -o "$val" = "1" ]; then
$UCI_SET upnpd.config.enabled=1
elif [ "$val" = "false" -o "$val" = "0" ]; then
$UCI_SET upnpd.config.enabled=
else
return
fi
delay_service restart "miniupnpd" "1"
}
get_upnp_status() {
local val=`pidof miniupnpd`
[ "$val" = "" ] && echo "Down" || echo "Up"
}
get_cache_InternetGatewayDevice_UPnP() {
get_object_cache_generic "InternetGatewayDevice.UPnP." "0"
get_object_cache_generic "InternetGatewayDevice.UPnP.Device." "0"
get_param_cache_generic "InternetGatewayDevice.UPnP.Device.Enable" "1" "get_upnp_enable" "set_upnp_enable \$val" "" "upnpd.config.enable_upnp" "xsd:boolean"
get_param_cache_generic "InternetGatewayDevice.UPnP.Device.X_INTENO_SE_Status" "0" "get_upnp_status" "" "1"
}
get_dynamic_InternetGatewayDevice_UPnP() {
return $FAULT_CPE_NO_FAULT
}
get_dynamic_linker_InternetGatewayDevice_UPnP() {
return $FAULT_CPE_NO_FAULT
}
add_object_InternetGatewayDevice_UPnP() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
delete_object_InternetGatewayDevice_UPnP() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,70 +0,0 @@
#!/bin/sh
# Copyright (C) 2014 Inteno Broadband Technology AB
prefix_list="$prefix_list InternetGatewayDevice.X_INTENO_SE_ICE."
get_ice_cloud_enable() {
case "$($UCI_GET ice.cloud.enabled)" in
1|"true"|"yes"|"on")
echo "true" ;;
0|"false"|"no"|"off")
echo "false" ;;
*) ;;
esac
}
# SET function which restarts the ice-client service
set_ice_cloud_enable() {
local lower=$(echo $1 | tr '[A-Z]' '[a-z]')
case "$lower" in
"true"|1)
$UCI_SET ice.cloud.enabled=1 ;;
"false"|0)
$UCI_SET ice.cloud.enabled=0 ;;
*) return ;;
esac
if [ -f /etc/rc.d/*ice-client ]
then
delay_service restart "ice-client" "1"
fi
}
get_ice_cloud_server() {
echo $($UCI_GET ice.cloud.server)
}
set_ice_cloud_server() {
[ "$1" = "" ] && return
$UCI_SET ice.cloud.server=$1
if [ -f /etc/rc.d/*ice-client ]
then
delay_service restart "ice-client" "1"
fi
}
# First specify the root object,
# then map leaves to the getter and setter functions, defined above.
get_cache_InternetGatewayDevice_X_INTENO_SE_ICE() {
get_object_cache_generic "InternetGatewayDevice.X_INTENO_SE_ICE." "0"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_ICE.Enable" "1" "get_ice_cloud_enable" "set_ice_cloud_enable \$val" "" "ice.cloud.enabled" "xsd:boolean"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_ICE.Server" "1" "get_ice_cloud_server" "set_ice_cloud_server \$val" "" "ice.cloud.server"
}
get_dynamic_InternetGatewayDevice_X_INTENO_SE_ICE() {
return $FAULT_CPE_NO_FAULT
}
get_dynamic_linker_InternetGatewayDevice_X_INTENO_SE_ICE() {
return $FAULT_CPE_NO_FAULT
}
add_object_InternetGatewayDevice_X_INTENO_SE_ICE() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
delete_object_InternetGatewayDevice_X_INTENO_SE_ICE() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}

View file

@ -1,99 +0,0 @@
#!/bin/sh
# Copyright (C) 2015 Inteno Broadband Technology AB
# Author Feten Besbes <feten.besbes@pivasoftware.com>
prefix_list="$prefix_list InternetGatewayDevice.X_INTENO_SE_IGMP."
get_igmp_param_value() {
local param="$1"
$UCI_GET mcpd.mcpd.$param
}
get_igmp_param_status () {
local param="$1"
local val=`$UCI_GET mcpd.mcpd.$param`
echo ${val:-0}
}
set_igmp_param_value() {
local param="$1"
local value="$2"
$UCI_SET mcpd.mcpd.$param="$value"
delay_service restart "mcpd" "1"
}
set_igmp_param_status() {
local param="$1"
local status="$2"
if [ "$status" = "true" -o "$status" = "1" ]; then
$UCI_SET mcpd.mcpd.$param="1"
elif [ "$status" = "false" -o "$status" = "0" ]; then
$UCI_SET mcpd.mcpd.$param=
else
return
fi
delay_service restart "mcpd" "1"
}
get_igmp_proxy_interface(){
local value=`$UCI_GET mcpd.mcpd.igmp_proxy_interfaces`
echo ${value// /,}
}
set_igmp_proxy_interface(){
local value="$*"
values=${value//,/ }
[ "$values" = "" ] && return
$UCI_SET mcpd.mcpd.igmp_proxy_interfaces="${values// / }"
delay_service restart "mcpd" "1"
}
get_igmp_snooping_interface(){
local value=`$UCI_GET mcpd.mcpd.igmp_snooping_interfaces`
echo ${value// /,}
}
set_igmp_snooping_interface(){
local value="$*"
values=${value//,/ }
[ "$values" = "" ] && return
$UCI_SET mcpd.mcpd.igmp_snooping_interfaces="${values// / }"
delay_service restart "mcpd" "1"
}
get_cache_InternetGatewayDevice_X_INTENO_SE_IGMP() {
local val
get_object_cache_generic "InternetGatewayDevice.X_INTENO_SE_IGMP." "0"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IGMP.DifferentiateService" "1" "get_igmp_param_value igmp_dscp_mark" "set_igmp_param_value igmp_dscp_mark \$val" "" "mcpd.mcpd.igmp_dscp_mark"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IGMP.ProxyInterface" "1" "get_igmp_proxy_interface" "set_igmp_proxy_interface \$val" "" "mcpd.mcpd.igmp_proxy_interfaces"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IGMP.DefaultVersion" "1" "get_igmp_param_value igmp_default_version" "set_igmp_param_value igmp_default_version \$val" "" "mcpd.mcpd.igmp_default_version"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IGMP.QueryInterval" "1" "get_igmp_param_value igmp_query_interval" "set_igmp_param_value igmp_query_interval \$val" "" "mcpd.mcpd.igmp_query_interval" "xsd:unsignedInt"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IGMP.QueryResponseInterval" "1" "get_igmp_param_value igmp_query_response_interval" "set_igmp_param_value igmp_query_response_interval \$val" "" "mcpd.mcpd.igmp_query_response_interval" "xsd:unsignedInt"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IGMP.LastMemberQueryInterval" "1" "get_igmp_param_value igmp_last_member_query_interval" "set_igmp_param_value igmp_last_member_query_interval \$val" "" "mcpd.mcpd.igmp_last_member_query_interval" "xsd:unsignedInt"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IGMP.RobustnessValue" "1" "get_igmp_param_value igmp_robustness_value" "set_igmp_param_value igmp_robustness_value \$val" "" "mcpd.mcpd.igmp_robustness_value" "xsd:int"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IGMP.LanToLanMulticastEnable" "1" "get_igmp_param_status igmp_lan_to_lan_multicast" "set_igmp_param_status igmp_lan_to_lan_multicast \$val" "" "mcpd.mcpd.igmp_lan_to_lan_multicast" "xsd:boolean"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IGMP.MaxGroup" "1" "get_igmp_param_value igmp_max_groups" "set_igmp_param_value igmp_max_groups \$val" "" "mcpd.mcpd.igmp_max_groups" "xsd:unsignedInt"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IGMP.MaxSources" "1" "get_igmp_param_value igmp_max_sources" "set_igmp_param_value igmp_max_sources \$val" "" "mcpd.mcpd.igmp_max_sources" "xsd:unsignedInt"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IGMP.MaxMembers" "1" "get_igmp_param_value igmp_max_members" "set_igmp_param_value igmp_max_members \$val" "" "mcpd.mcpd.igmp_max_members" "xsd:unsignedInt"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IGMP.FastLeaveEnable" "1" "get_igmp_param_status igmp_fast_leave" "set_igmp_param_status igmp_fast_leave \$val" "" "mcpd.mcpd.igmp_fast_leave" "xsd:boolean"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IGMP.JoinImmediateEnable" "1" "get_igmp_param_status igmp_join_immediate" "set_igmp_param_status igmp_join_immediate \$val" "" "mcpd.mcpd.igmp_join_immediate" "xsd:boolean"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IGMP.ProxyEnable" "1" "get_igmp_param_status igmp_proxy_enable" "set_igmp_param_status igmp_proxy_enable \$val" "" "mcpd.mcpd.igmp_proxy_enable" "xsd:boolean"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IGMP.SnoopingMode" "1" "get_igmp_param_value igmp_snooping_enable" "set_igmp_param_value igmp_snooping_enable \$val" "" "mcpd.mcpd.igmp_snooping_enable"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IGMP.SnoopingInterfaces" "1" "get_igmp_snooping_interface" "set_igmp_snooping_interface \$val" "" "mcpd.mcpd.igmp_snooping_interfaces"
}
get_dynamic_InternetGatewayDevice_X_INTENO_SE_IGMP() {
return $FAULT_CPE_NO_FAULT
}
get_dynamic_linker_InternetGatewayDevice_X_INTENO_SE_IGMP() {
return $FAULT_CPE_NO_FAULT
}
add_object_InternetGatewayDevice_X_INTENO_SE_IGMP() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
delete_object_InternetGatewayDevice_X_INTENO_SE_IGMP() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}

View file

@ -1,286 +0,0 @@
#!/bin/sh
# Copyright (C) 2013-2015 Inteno Broadband Technology AB
# Author Feten Besbes <feten.besbes@pivasoftware.com>
# Author Anis Ellouze <anis.ellouze@pivasoftware.com>
prefix_list="$prefix_list InternetGatewayDevice.X_INTENO_SE_IpAccCfg."
get_firewall_rules() {
local i=0
local rule
rule=`$UCI_SHOW firewall |grep "firewall\.@rule\[[0-9]\+\]=" | wc -l`
if [ "$rule" != "" ]; then seq 1 $rule; fi
}
get_x_inteno_cfgobj_address_netmask() {
local xrule=$1
ip=`$UCI_GET firewall.$xrule.src_ip`
ip=${ip// /,}
if [ "$ip" = "" ]; then ip="0.0.0.0/0"; fi
echo $ip
}
set_x_inteno_cfgobj_address_netmask() {
local xrule=$1
local val=$2
val=${val//,/ }
$UCI_SET firewall.$xrule.src_ip=""
local src_ip
for src_ip in $val; do
$UCI_ADD_LIST firewall.$xrule.src_ip="$src_ip"
done
delay_service restart "firewall" "0"
}
get_x_bcm_com_ip_acc_list_cfgobj_acc_port() {
local xrule=$1
port=`$UCI_GET firewall.$xrule.dest_port`
echo $port
}
set_x_bcm_com_ip_acc_list_cfgobj_acc_port() {
local xrule=$1
local val=$2
$UCI_SET firewall.$xrule.dest_port=$val
delay_service restart "firewall" "0"
}
get_x_bcm_com_ip_acc_list_cfgobj_enable() {
local xrule=$1
local enable=`$UCI_GET firewall.$xrule.enabled`
echo ${enable:-1}
}
set_x_bcm_com_ip_acc_list_cfgobj_enable() {
local xrule=$1
local val=$2
val=`echo $val|tr '[A-Z]' '[a-z]'`
if [ "$val" = "true" -o "$val" = "1" ]; then
val=""
elif [ "$val" = "false" -o "$val" = "0" ]; then
val="0"
else
return
fi
$UCI_SET firewall.$xrule.enabled=$val
delay_service restart "firewall" "0"
}
get_port_forwarding_value() {
local option="$1"
local xcfg="$2"
$UCI_GET firewall.$xcfg.$option
}
set_port_forwarding_value() {
local option="$1"
local xcfg="$2"
shift 2
local val="$*"
$UCI_SET firewall.$xcfg.$option="$val"
delay_service restart "firewall" "1"
}
get_port_forwarding_value_default_any() {
local option="$1"
local xcfg="$2"
local val=`$UCI_GET firewall.$xcfg.$option`
echo ${val:-any}
}
set_port_forwarding_value_default_any() {
local option="$1"
local xcfg="$2"
shift 2
local val="$*"
val2=`echo $val|tr '[A-Z]' '[a-z]'`
[ "$val2" = "any" ] && val=""
$UCI_SET firewall.$xcfg.$option="$val"
delay_service restart "firewall" "1"
}
get_PortForwarding_enable_value() {
local option="$1"
local xcfg="$2"
local val=`$UCI_GET firewall.$xcfg.$option`
echo ${val:-1}
}
set_PortForwarding_enable_value() {
local option="$1"
local xcfg="$2"
local status="$3"
status=`echo $status|tr '[A-Z]' '[a-z]'`
if [ "$status" = "true" -o "$status" = "1" ]; then
$UCI_SET firewall.$xcfg.$option=
elif [ "$status" = "false" -o "$status" = "0" ]; then
$UCI_SET firewall.$xcfg.$option="0"
else
return
fi
delay_service reload "firewall" "1"
}
set_port_forwarding_src_mac() {
local xcfg="$1"
shift
local val="$*"
$UCI_DELETE firewall.$xcfg.src_mac
local mac
for mac in $val; do
$UCI_ADD_LIST firewall.$xcfg.src_mac=$mac
done
delay_service reload "firewall" "1"
}
update_port_forwarding_instance() {
local xcfg="$1"
local inst=`$UCI_GET firewall.$xcfg.port_forwarding_instance`
if [ "$inst" != "" ]; then
echo "$inst"
else
local inst=`$UCI_SHOW firewall |sed -n "s/firewall\.@redirect\[[0-9]\+\]\.port_forwarding_instance=//p" | sort -rn | head -n1`
inst=${inst:-0}
$UCI_SET firewall.$xcfg.port_forwarding_instance="$((++inst))"
$UCI_COMMIT
echo $inst
fi
}
get_cache_object_ip_acc_list_cfgobj() {
local instance="$1"
local xrule="$2"
get_object_cache_generic "InternetGatewayDevice.X_INTENO_SE_IpAccCfg.X_INTENO_SE_IpAccListCfgObj.$instance." "0"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IpAccCfg.X_INTENO_SE_IpAccListCfgObj.$instance.Enable" "1" "get_x_bcm_com_ip_acc_list_cfgobj_enable $xrule" "set_x_bcm_com_ip_acc_list_cfgobj_enable $xrule \$val" "" "" "xsd:boolean"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IpAccCfg.X_INTENO_SE_IpAccListCfgObj.$instance.AccAddressAndNetMask" "1" "get_x_inteno_cfgobj_address_netmask $xrule" "set_x_inteno_cfgobj_address_netmask $xrule \$val"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IpAccCfg.X_INTENO_SE_IpAccListCfgObj.$instance.AccPort" "1" "get_x_bcm_com_ip_acc_list_cfgobj_acc_port $xrule" "set_x_bcm_com_ip_acc_list_cfgobj_acc_port $xrule \$val"
}
get_cache_object_port_forwarding() {
local xcfg="$1"
local ic="$2"
get_object_cache_generic "InternetGatewayDevice.X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.$ic." "0"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.$ic.Name" "1" "get_port_forwarding_value name $xcfg" "set_port_forwarding_value name $xcfg \$val"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.$ic.Enable" "1" "get_PortForwarding_enable_value enabled $xcfg" "set_PortForwarding_enable_value enabled $xcfg \$val" "" "" "xsd:boolean"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.$ic.EnalbeNatLoopback" "1" "get_PortForwarding_enable_value reflection $xcfg" "set_PortForwarding_enable_value reflection $xcfg \$val" "" "" "xsd:boolean"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.$ic.Protocol" "1" "get_port_forwarding_value proto $xcfg" "set_port_forwarding_value proto $xcfg \$val"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.$ic.ExternalZone" "1" "get_port_forwarding_value src $xcfg" "set_port_forwarding_value src $xcfg \$val"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.$ic.InternalZone" "1" "get_port_forwarding_value dest $xcfg" "set_port_forwarding_value dest $xcfg \$val"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.$ic.ExternalPort" "1" "get_port_forwarding_value src_dport $xcfg" "set_port_forwarding_value src_dport $xcfg \$val"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.$ic.InternalPort" "1" "get_port_forwarding_value_default_any dest_port $xcfg" "set_port_forwarding_value_default_any dest_port $xcfg \$val"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.$ic.SourcePort" "1" "get_port_forwarding_value_default_any src_port $xcfg" "set_port_forwarding_value_default_any dest_port $xcfg \$val"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.$ic.InternalIpAddress" "1" "get_port_forwarding_value src_ip $xcfg" "set_port_forwarding_value dest_ip $xcfg \$val"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.$ic.ExternalIpAddress" "1" "get_port_forwarding_value_default_any src_dip $xcfg" "set_port_forwarding_value_default_any src_dip $xcfg \$val"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.$ic.SourceIpAddress" "1" "get_port_forwarding_value_default_any src_ip $xcfg" "set_port_forwarding_value_default_any src_dip $xcfg \$val"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.$ic.SourceMacAddress" "1" "get_port_forwarding_value src_mac $xcfg" "set_port_forwarding_src_mac $xcfg \$val"
}
get_cache_InternetGatewayDevice_X_INTENO_SE_IpAccCfg() {
local ic=0
local val
local instance index
get_object_cache_generic "InternetGatewayDevice.X_INTENO_SE_IpAccCfg." "0"
get_object_cache_generic "InternetGatewayDevice.X_INTENO_SE_IpAccCfg.X_INTENO_SE_IpAccListCfgObj." "0"
get_object_cache_generic "InternetGatewayDevice.X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding." "1"
for instance in `get_firewall_rules`; do
index=$(($instance-1))
local xrule=`common_get_cfg_section_ref "firewall" "rule" "$index"`
get_cache_object_ip_acc_list_cfgobj "$instance" "$xrule"
done
local cfg cfgs=`$UCI_SHOW firewall | grep "firewall\.@redirect\[[0-9]\+\]\.target=DNAT" | awk -F'[][]' '{print $2}'`
for cfg in $cfgs; do
local xcfg=`$UCI_SHOW -X firewall |grep "firewall\.[^=.]\+=redirect" | sed "$((cfg+1))""q;d" | awk -F'[=.]' '{print $2}'`
ic=`update_port_forwarding_instance $xcfg`
get_cache_object_port_forwarding "$xcfg" "$ic"
done
}
add_ipacccfg_port_forwarding() {
local filename="$1"
local inst=`$UCI_SHOW firewall |sed -n "s/firewall\.@redirect\[[0-9]\+\]\.port_forwarding_instance=//p" | sort -rn | head -n1`
inst=${inst:-0}
local xcfg=`$UCI_ADD firewall redirect`
$UCI_SET firewall.$xcfg.port_forwarding_instance="$((++inst))"
$UCI_SET firewall.$xcfg.enabled=0
$UCI_SET firewall.$xcfg.target=DNAT
$UCI_SET firewall.$xcfg.proto="tcp udp"
$UCI_COMMIT
get_cache_object_port_forwarding "$xcfg" "$inst" >> $cache_path/$filename
freecwmp_output "" "" "" "" "" "" "1" "$inst"
return $FAULT_CPE_NO_FAULT
}
delete_ipacccfg_port_forwarding() {
local instance="$2"
local filename="$3"
local xcfg=`$UCI_SHOW firewall |grep "firewall\.@redirect\[[0-9]\+\]\.port_forwarding_instance=$instance$" | cut -d. -f2`
if [ "$xcfg" = "" ]; then return $FAULT_CPE_INVALID_PARAMETER_NAME; fi
$UCI_DELETE firewall.$xcfg
$UCI_COMMIT
delay_service reload "firewall" "1"
freecwmp_output "" "" "" "" "" "" "1"
sed -i "/$1/d" $cache_path/$filename
return $FAULT_CPE_NO_FAULT
}
delete_ipacccfg_port_forwarding_all() {
local filename="$3"
local uci_num uci_nums=`$UCI_SHOW firewall |grep "firewall\.@redirect\[[0-9]\+\]\.port_forwarding_instance" | awk -F'[][]' '{print $2}' | sort -rn`
for uci_num in $uci_nums; do
$UCI_DELETE firewall.@redirect[$uci_num]
done
$UCI_COMMIT
delay_service reload "firewall" "1"
freecwmp_output "" "" "" "" "" "" "1"
sed -i "/$1[0-9]\+\./d" $cache_path/$filename
return $FAULT_CPE_NO_FAULT
}
add_object_InternetGatewayDevice_X_INTENO_SE_IpAccCfg() {
local filename="$2"
local fault_code
case $1 in
InternetGatewayDevice.X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.)
add_ipacccfg_port_forwarding "$filename"
fault_code="$?"
return $fault_code
;;
esac
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
delete_object_InternetGatewayDevice_X_INTENO_SE_IpAccCfg() {
local filename="$2"
local fault_code instances
case $1 in
InternetGatewayDevice.X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.[1-9]*.)
freecwmp_parse_formated_parameter "$1" "InternetGatewayDevice.X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.{i}." "rc" "instances"
if [ "$rc" != "0" ]; then return $FAULT_CPE_INVALID_PARAMETER_NAME; fi
delete_ipacccfg_port_forwarding "$1" "$instances" "$filename"
fault_code="$?"
return $fault_code
;;
InternetGatewayDevice.X_INTENO_SE_IpAccCfg.X_INTENO_SE_PortForwarding.)
delete_ipacccfg_port_forwarding_all "$1" "" "$filename"
fault_code="$?"
return $fault_code
;;
esac
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
get_dynamic_InternetGatewayDevice_X_INTENO_SE_IpAccCfg() {
return $FAULT_CPE_NO_FAULT
}
get_dynamic_linker_InternetGatewayDevice_X_INTENO_SE_IpAccCfg() {
return $FAULT_CPE_NO_FAULT
}

View file

@ -1,39 +0,0 @@
#!/bin/sh
# Copyright (C) 2011-2012 Luka Perkov <freecwmp@lukaperkov.net>
# Copyright (C) 2013 Inteno Broadband Technology AB
# Author Feten Besbes <feten.besbes@pivasoftware.com>
prefix_list="$prefix_list InternetGatewayDevice.X_INTENO_SE_LoginCfg."
set_x_bcm_password() {
local usr_type=$1
local new_pwd=$2
passwd $usr_type <<EOF > /dev/null
$new_pwd
$new_pwd
EOF
}
get_cache_InternetGatewayDevice_X_INTENO_SE_LoginCfg() {
get_object_cache_generic "InternetGatewayDevice.X_INTENO_SE_LoginCfg." "0"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_LoginCfg.AdminPassword" "1" "" "set_x_bcm_password admin \$val" "" "" "" "" "" "" "1"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_LoginCfg.SupportPassword" "1" "" "set_x_bcm_password support \$val" "" "" "" "" "" "" "1"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_LoginCfg.UserPassword" "1" "" "set_x_bcm_password user \$val" "" "" "" "" "" "" "1"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_LoginCfg.RootPassword" "1" "" "set_x_bcm_password root \$val" "" "" "" "" "" "" "1"
}
get_dynamic_InternetGatewayDevice_X_INTENO_SE_LoginCfg() {
return $FAULT_CPE_NO_FAULT
}
get_dynamic_linker_InternetGatewayDevice_X_INTENO_SE_LoginCfg() {
return $FAULT_CPE_NO_FAULT
}
add_object_InternetGatewayDevice_X_INTENO_SE_LoginCfg() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
delete_object_InternetGatewayDevice_X_INTENO_SE_LoginCfg() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}

View file

@ -1,63 +0,0 @@
#!/bin/sh
# Copyright (C) 2015 Inteno Broadband Technology AB
# Author Anis Ellouze <anis.ellouze@pivasoftware.com>
# Author Simon Kers <simon.kers@inteno.se>
local service="/etc/init.d/power_mgmt"
local object="InternetGatewayDevice.X_INTENO_SE_PowerManagement."
# Add TR-069 object to cache if there is a service
if [ -e $service ]
then
prefix_list="$prefix_list $object"
fi
get_power_mgmt_value() {
local power_type="$1"
local val=`$UCI_GET power_mgmt.power_mgmt.$power_type`
echo ${val:-0}
}
set_power_mgmt_param_value() {
local power_type="$1"
local status="$2"
if [ "$status" = "true" -o "$status" = "1" ]; then
$UCI_SET power_mgmt.power_mgmt.$power_type="1"
elif [ "$status" = "false" -o "$status" = "0" ]; then
$UCI_SET power_mgmt.power_mgmt.$power_type="0"
else
return
fi
delay_service restart "power_mgmt" "1"
}
get_power_mgmt_nbr_interfaces() {
local status="$1"
local val=`pwrctl show |awk '$1=="Powered" && $2=="'$status':" {print $3}'`
echo $val
}
get_cache_InternetGatewayDevice_X_INTENO_SE_PowerManagement() {
local val
get_object_cache_generic "InternetGatewayDevice.X_INTENO_SE_PowerManagement." "0"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_PowerManagement.EthernetAutoPowerDownEnable" "1" "get_power_mgmt_value ethapd" "set_power_mgmt_param_value ethapd \$val" "" "power_mgmt.power_mgmt.ethapd" "xsd:boolean"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_PowerManagement.EnergyEfficientEthernetEnable" "1" "get_power_mgmt_value eee" "set_power_mgmt_param_value eee \$val" "" "power_mgmt.power_mgmt.eee" "xsd:boolean"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_PowerManagement.NumberOfEthernetInterfacesPoweredUp" "0" "get_power_mgmt_nbr_interfaces up" "" "1" "" "xsd:unsignedInt"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_PowerManagement.NumberOfEthernetInterfacesPoweredDown" "0" "get_power_mgmt_nbr_interfaces down" "" "1" "" "xsd:unsignedInt"
}
get_dynamic_InternetGatewayDevice_X_INTENO_SE_PowerManagement() {
return $FAULT_CPE_NO_FAULT
}
get_dynamic_linker_InternetGatewayDevice_X_INTENO_SE_PowerManagement() {
return $FAULT_CPE_NO_FAULT
}
add_object_InternetGatewayDevice_X_INTENO_SE_PowerManagement() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
delete_object_InternetGatewayDevice_X_INTENO_SE_PowerManagement() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}

View file

@ -1,56 +0,0 @@
#!/bin/sh
# Copyright (C) 2015 Inteno Broadband Technology AB
# Author Feten Besbes <feten.besbes@pivasoftware.com>
local object="InternetGatewayDevice.X_INTENO_SE_Wifi."
prefix_list="$prefix_list $object"
get_wifi_frequency () {
local wlctl="$1"
local val=`wlctl -i $wlctl status |awk '$1=="Chanspec:" {print$2}'`
echo "$val"
}
get_wifi_maxassoc () {
local wlctl="$1"
local val=`$UCI_GET wireless.$wlctl.maxassoc`
echo $val
}
set_wifi_maxassoc () {
local wlctl="$1"
local val="$2"
$UCI_SET wireless.$wlctl.maxassoc=$val
delay_service reload "network" "1"
}
get_cache_InternetGatewayDevice_X_INTENO_SE_Wifi() {
local val
local idev
get_object_cache_generic "InternetGatewayDevice.X_INTENO_SE_Wifi." "0"
get_object_cache_generic "InternetGatewayDevice.X_INTENO_SE_Wifi.Radio" "0"
for wlctl_num in `$UCI_SHOW wireless|grep "wireless\.wl[0-9]\+=wifi-device" | awk -F '[.=]' '{print $2}'`; do
wnum=${wlctl_num#wl*}
let "wnum = $wnum + 1"
get_object_cache_generic "InternetGatewayDevice.X_INTENO_SE_Wifi.Radio.$wnum" "0"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_Wifi.Radio.$wnum.Frequency" "0" "get_wifi_frequency $wlctl_num"
get_param_cache_generic "InternetGatewayDevice.X_INTENO_SE_Wifi.Radio.$wnum.MaxAssociations" "1" "get_wifi_maxassoc $wlctl_num" "set_wifi_maxassoc $wlctl_num \$val"
done
}
get_dynamic_InternetGatewayDevice_X_INTENO_SE_Wifi() {
return $FAULT_CPE_NO_FAULT
}
get_dynamic_linker_InternetGatewayDevice_X_INTENO_SE_Wifi() {
return $FAULT_CPE_NO_FAULT
}
add_object_InternetGatewayDevice_X_INTENO_SE_Wifi() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}
delete_object_InternetGatewayDevice_X_INTENO_SE_Wifi() {
return $FAULT_CPE_INVALID_PARAMETER_NAME
}

View file

@ -1,5 +1,5 @@
#!/usr/sbin/bash
# Copyright (C) 2013 Inteno Broadband Technology AB
# Copyright (C) 2013-2015 Inteno Broadband Technology AB
# Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
usage()
{
@ -9,51 +9,6 @@ usage()
echo "$0 -h display this help"
}
wepkey128()
{
dup="$1"
while [ ${#dup} -lt 64 ]
do
dup="$dup$1"
done
dup="${dup:0:64}"
key=`echo -n $dup | md5sum`
echo "${key:0:26}"
}
wepkey64()
{
pass=$1
pseed=" 0 0 0 0"
i=0
while [ $i -lt ${#pass} ]
do
let n=$i%4
let j=$n*3
let h=$j+3
code=`printf '%d' "'${pass:$i:1}"`
let "oxor=$code^${pseed:$j:3}"
oxor=`printf '%3d' $oxor`
pseed=${pseed:0:$j}$oxor${pseed:$h}
let "i++"
done
let "randNumber=${pseed:0:3}|(${pseed:3:3}<<8)|(${pseed:6:3}<<16)|(${pseed:9}<<24)"
k64=""
for i in 0 1 2 3
do
for j in 0 1 2 3 4
do
let "randNumber=($randNumber * $((0x343fd)) + $((0x269ec3))) & $((0xffffffff))"
let "tmp=($randNumber>>16)&$((0xff))"
k64=$k64`printf '%02x' $tmp`
done
k64=$k64"\n"
done
printf "$k64"
}
if [ "_$1" = "-h" ]; then
usage;
exit 0;
@ -67,8 +22,4 @@ if [ _$strength != "_64" -a _$strength != "_128" ] || [ _$passphrase = "_" ]; th
exit 0;
fi
if [ $strength = "128" ]; then
wepkey128 $passphrase
else
wepkey64 $passphrase
fi
/usr/sbin/cwmpd -w "$strength" "$passphrase"

4
ubus.c
View file

@ -19,6 +19,8 @@
#include "external.h"
#include "xml.h"
#include "log.h"
#include "wepkey.h"
#include "dmentry.h"
static struct ubus_context *ctx = NULL;
static struct blob_buf b;
@ -289,7 +291,7 @@ ubus_init(struct cwmp *cwmp)
ubus_add_uloop(ctx);
if (ubus_add_object(ctx, &main_object)) return -1;
uloop_run();
//uloop_run(); //TODO the uloop_run cause a freeze when used with dm ubus c commands. should be fixed
return 0;
}

413
xml.c
View file

@ -22,6 +22,8 @@
#include "backupSession.h"
#include "log.h"
#include "jshn.h"
#include "dmentry.h"
#include "deviceinfo.h"
LIST_HEAD(list_download);
static pthread_mutex_t mutex_download = PTHREAD_MUTEX_INITIALIZER;
@ -50,26 +52,26 @@ const static char *cwmp_urls[] = {
NULL };
struct FAULT_CPE FAULT_CPE_ARRAY [] = {
[FAULT_CPE_METHOD_NOT_SUPPORTED] = {"9000",FAULT_CPE_TYPE_SERVER, "Method not supported"},
[FAULT_CPE_REQUEST_DENIED] = {"9001",FAULT_CPE_TYPE_SERVER, "Request denied (no reason specified)"},
[FAULT_CPE_INTERNAL_ERROR] = {"9002",FAULT_CPE_TYPE_SERVER, "Internal error"},
[FAULT_CPE_INVALID_ARGUMENTS] = {"9003",FAULT_CPE_TYPE_CLIENT, "Invalid arguments"},
[FAULT_CPE_RESOURCES_EXCEEDED] = {"9004",FAULT_CPE_TYPE_SERVER, "Resources exceeded"},
[FAULT_CPE_INVALID_PARAMETER_NAME] = {"9005",FAULT_CPE_TYPE_CLIENT, "Invalid parameter name"},
[FAULT_CPE_INVALID_PARAMETER_TYPE] = {"9006",FAULT_CPE_TYPE_CLIENT, "Invalid parameter type"},
[FAULT_CPE_INVALID_PARAMETER_VALUE] = {"9007",FAULT_CPE_TYPE_CLIENT, "Invalid parameter value"},
[FAULT_CPE_NON_WRITABLE_PARAMETER] = {"9008",FAULT_CPE_TYPE_CLIENT, "Attempt to set a non-writable parameter"},
[FAULT_CPE_NOTIFICATION_REJECTED] = {"9009",FAULT_CPE_TYPE_SERVER, "Notification request rejected"},
[FAULT_CPE_DOWNLOAD_FAILURE] = {"9010",FAULT_CPE_TYPE_SERVER, "Download failure"},
[FAULT_CPE_UPLOAD_FAILURE] = {"9011",FAULT_CPE_TYPE_SERVER, "Upload failure"},
[FAULT_CPE_FILE_TRANSFER_AUTHENTICATION_FAILURE]= {"9012",FAULT_CPE_TYPE_SERVER, "File transfer server authentication failure"},
[FAULT_CPE_FILE_TRANSFER_UNSUPPORTED_PROTOCOL] = {"9013",FAULT_CPE_TYPE_SERVER, "Unsupported protocol for file transfer"},
[FAULT_CPE_DOWNLOAD_FAIL_MULTICAST_GROUP] = {"9014",FAULT_CPE_TYPE_SERVER, "Download failure: unable to join multicast group"},
[FAULT_CPE_DOWNLOAD_FAIL_CONTACT_SERVER] = {"9015",FAULT_CPE_TYPE_SERVER, "Download failure: unable to contact file server"},
[FAULT_CPE_DOWNLOAD_FAIL_ACCESS_FILE] = {"9016",FAULT_CPE_TYPE_SERVER, "Download failure: unable to access file"},
[FAULT_CPE_DOWNLOAD_FAIL_COMPLETE_DOWNLOAD] = {"9017",FAULT_CPE_TYPE_SERVER, "Download failure: unable to complete download"},
[FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED] = {"9018",FAULT_CPE_TYPE_SERVER, "Download failure: file corrupted"},
[FAULT_CPE_DOWNLOAD_FAIL_FILE_AUTHENTICATION] = {"9019",FAULT_CPE_TYPE_SERVER, "Download failure: file authentication failure"}
[FAULT_CPE_METHOD_NOT_SUPPORTED] = {"9000", FAULT_9000, FAULT_CPE_TYPE_SERVER, "Method not supported"},
[FAULT_CPE_REQUEST_DENIED] = {"9001", FAULT_9001, FAULT_CPE_TYPE_SERVER, "Request denied (no reason specified)"},
[FAULT_CPE_INTERNAL_ERROR] = {"9002", FAULT_9002, FAULT_CPE_TYPE_SERVER, "Internal error"},
[FAULT_CPE_INVALID_ARGUMENTS] = {"9003", FAULT_9003, FAULT_CPE_TYPE_CLIENT, "Invalid arguments"},
[FAULT_CPE_RESOURCES_EXCEEDED] = {"9004", FAULT_9004, FAULT_CPE_TYPE_SERVER, "Resources exceeded"},
[FAULT_CPE_INVALID_PARAMETER_NAME] = {"9005", FAULT_9005, FAULT_CPE_TYPE_CLIENT, "Invalid parameter name"},
[FAULT_CPE_INVALID_PARAMETER_TYPE] = {"9006", FAULT_9006, FAULT_CPE_TYPE_CLIENT, "Invalid parameter type"},
[FAULT_CPE_INVALID_PARAMETER_VALUE] = {"9007", FAULT_9007, FAULT_CPE_TYPE_CLIENT, "Invalid parameter value"},
[FAULT_CPE_NON_WRITABLE_PARAMETER] = {"9008", FAULT_9008, FAULT_CPE_TYPE_CLIENT, "Attempt to set a non-writable parameter"},
[FAULT_CPE_NOTIFICATION_REJECTED] = {"9009", FAULT_9009, FAULT_CPE_TYPE_SERVER, "Notification request rejected"},
[FAULT_CPE_DOWNLOAD_FAILURE] = {"9010", FAULT_9010, FAULT_CPE_TYPE_SERVER, "Download failure"},
[FAULT_CPE_UPLOAD_FAILURE] = {"9011", FAULT_9011, FAULT_CPE_TYPE_SERVER, "Upload failure"},
[FAULT_CPE_FILE_TRANSFER_AUTHENTICATION_FAILURE]= {"9012", FAULT_9012, FAULT_CPE_TYPE_SERVER, "File transfer server authentication failure"},
[FAULT_CPE_FILE_TRANSFER_UNSUPPORTED_PROTOCOL] = {"9013", FAULT_9013, FAULT_CPE_TYPE_SERVER, "Unsupported protocol for file transfer"},
[FAULT_CPE_DOWNLOAD_FAIL_MULTICAST_GROUP] = {"9014", FAULT_9014, FAULT_CPE_TYPE_SERVER, "Download failure: unable to join multicast group"},
[FAULT_CPE_DOWNLOAD_FAIL_CONTACT_SERVER] = {"9015", FAULT_9015, FAULT_CPE_TYPE_SERVER, "Download failure: unable to contact file server"},
[FAULT_CPE_DOWNLOAD_FAIL_ACCESS_FILE] = {"9016", FAULT_9016, FAULT_CPE_TYPE_SERVER, "Download failure: unable to access file"},
[FAULT_CPE_DOWNLOAD_FAIL_COMPLETE_DOWNLOAD] = {"9017", FAULT_9017, FAULT_CPE_TYPE_SERVER, "Download failure: unable to complete download"},
[FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED] = {"9018", FAULT_9018, FAULT_CPE_TYPE_SERVER, "Download failure: file corrupted"},
[FAULT_CPE_DOWNLOAD_FAIL_FILE_AUTHENTICATION] = {"9019", FAULT_9019, FAULT_CPE_TYPE_SERVER, "Download failure: file authentication failure"}
};
const struct rpc_cpe_method rpc_cpe_methods[] = {
@ -94,13 +96,6 @@ const struct rpc_acs_method rpc_acs_methods[] = {
[RPC_ACS_TRANSFER_COMPLETE] = {"TransferComplete", cwmp_rpc_acs_prepare_transfer_complete, NULL, cwmp_rpc_acs_destroy_data_transfer_complete}
};
const struct DEVICE_ID_STRUCT DEVICE_ID_CONST [] = {
{ "OUI", "InternetGatewayDevice.DeviceInfo.ManufacturerOUI" },
{ "ProductClass", "InternetGatewayDevice.DeviceInfo.ProductClass" },
{ "SerialNumber", "InternetGatewayDevice.DeviceInfo.SerialNumber" },
{ "Manufacturer", "InternetGatewayDevice.DeviceInfo.Manufacturer" }
};
static int xml_recreate_namespace(mxml_node_t *tree)
{
const char *cwmp_urn;
@ -464,34 +459,31 @@ error:
return -1;
}
static int xml_prepare_parameters_inform(struct parameter_container *parameter_container, mxml_node_t *parameter_list, int *size)
static int xml_prepare_parameters_inform(struct dmctx *dmctx, struct dm_parameter *dm_parameter, mxml_node_t *parameter_list, int *size)
{
mxml_node_t *node, *b;
int found;
if (parameter_container->fault_code && parameter_container->fault_code[0]=='9')
return -1;
b = mxmlFindElementText(parameter_list, parameter_list, parameter_container->name, MXML_DESCEND);
if(b && parameter_container->data != NULL)
b = mxmlFindElementText(parameter_list, parameter_list, dm_parameter->name, MXML_DESCEND);
if(b && dm_parameter->data != NULL)
{
node = b->parent->parent;
b = mxmlFindElement(node, node, "Value", NULL, NULL, MXML_DESCEND_FIRST);
if(!b) return 0;
if (b->child && strcmp(parameter_container->data, b->child->value.text.string)==0)
if (b->child && strcmp(dm_parameter->data, b->child->value.text.string)==0)
return 0;
mxmlDelete(b);
(*size)--;
goto create_value;
}
else if (b && parameter_container->data == NULL)
else if (b && dm_parameter->data == NULL)
{
return 0;
}
else if (!b && parameter_container->data == NULL)
else if (!b && dm_parameter->data == NULL)
{
external_get_action("value", parameter_container->name, NULL);
dm_entry_param_method(dmctx, CMD_GET_VALUE, dm_parameter->name, NULL, NULL);
return 0;
}
node = mxmlNewElement (parameter_list, "ParameterValueStruct");
@ -500,7 +492,7 @@ static int xml_prepare_parameters_inform(struct parameter_container *parameter_c
b = mxmlNewElement(node, "Name");
if (!b) return -1;
b = mxmlNewText(b, 0, parameter_container->name);
b = mxmlNewText(b, 0, dm_parameter->name);
if (!b) return -1;
create_value:
@ -508,9 +500,9 @@ create_value:
if (!b) return -1;
#ifdef ACS_MULTI
mxmlElementSetAttr(b, "xsi:type", (parameter_container->type && parameter_container->type[0] != '\0')? parameter_container->type : "xsd:string");
mxmlElementSetAttr(b, "xsi:type", (dm_parameter->type && dm_parameter->type[0] != '\0')? dm_parameter->type : "xsd:string");
#endif
b = mxmlNewText(b, 0, parameter_container->data);
b = mxmlNewText(b, 0, dm_parameter->data);
if (!b) return -1;
(*size)++;
@ -519,12 +511,15 @@ create_value:
int cwmp_rpc_acs_prepare_message_inform (struct cwmp *cwmp, struct session *session, struct rpc *this)
{
struct parameter_container *parameter_container;
struct dm_parameter *dm_parameter;
struct event_container *event_container;
mxml_node_t *tree, *b, *node, *parameter_list;
char *c = NULL;
int size = 0, i, error;
struct list_head *ilist,*jlist;
struct dmctx dmctx = {0};
dm_ctx_init(&dmctx);
if (session==NULL || this==NULL)
{
@ -562,40 +557,41 @@ int cwmp_rpc_acs_prepare_message_inform (struct cwmp *cwmp, struct session *sess
list_for_each(ilist, &(session->head_event_container))
{
event_container = list_entry(ilist, struct event_container, list);
list_for_each(jlist, &(event_container->head_parameter_container))
list_for_each(jlist, &(event_container->head_dm_parameter))
{
parameter_container = list_entry(jlist, struct parameter_container, list);
if (xml_prepare_parameters_inform(parameter_container, parameter_list, &size))
dm_parameter = list_entry(jlist, struct dm_parameter, list);
if (xml_prepare_parameters_inform(&dmctx, dm_parameter, parameter_list, &size))
goto error;
}
}
external_simple("inform", NULL);
b = mxmlFindElement(tree, tree, "OUI", NULL, NULL, MXML_DESCEND);
if (!b) goto error;
b = mxmlNewText(b, 0, cwmp->deviceid.oui ? cwmp->deviceid.oui : "");
if (!b) goto error;
external_handle_action(cwmp_handle_getParamValues);
b = mxmlFindElement(tree, tree, "Manufacturer", NULL, NULL, MXML_DESCEND);
if (!b) goto error;
b = mxmlNewText(b, 0, cwmp->deviceid.manufacturer ? cwmp->deviceid.manufacturer : "");
if (!b) goto error;
list_for_each(ilist, &(external_list_parameter)) {
parameter_container = list_entry(ilist, struct parameter_container, list);
for (i=0; i<ARRAYSIZEOF(DEVICE_ID_CONST); i++)
{
if(strcmp(DEVICE_ID_CONST[i].parameter_name, parameter_container->name)==0) {
if (parameter_container->fault_code && parameter_container->fault_code[0]=='9')
goto error;
b = mxmlFindElement(tree, tree, DEVICE_ID_CONST[i].device_id_name, NULL, NULL, MXML_DESCEND);
if (!b) goto error;
b = mxmlFindElement(tree, tree, "ProductClass", NULL, NULL, MXML_DESCEND);
if (!b) goto error;
b = mxmlNewText(b, 0, cwmp->deviceid.productclass ? cwmp->deviceid.productclass : "");
if (!b) goto error;
b = mxmlNewText(b, 0, parameter_container->data? parameter_container->data : "");
if (!b) goto error;
}
}
}
b = mxmlFindElement(tree, tree, "SerialNumber", NULL, NULL, MXML_DESCEND);
if (!b) goto error;
b = mxmlNewText(b, 0, cwmp->deviceid.serialnumber ? cwmp->deviceid.serialnumber : "");
if (!b) goto error;
while (external_list_parameter.next!=&external_list_parameter) {
dm_entry_param_method(&dmctx, CMD_INFORM, NULL, NULL, NULL);
parameter_container = list_entry(external_list_parameter.next, struct parameter_container, list);
if (xml_prepare_parameters_inform(parameter_container, parameter_list, &size))
while (dmctx.list_parameter.next != &dmctx.list_parameter) {
dm_parameter = list_entry(dmctx.list_parameter.next, struct dm_parameter, list);
if (xml_prepare_parameters_inform(&dmctx, dm_parameter, parameter_list, &size))
goto error;
parameter_container_delete(parameter_container);
del_list_parameter(dm_parameter);
}
if (asprintf(&c, "cwmp:ParameterValueStruct[%d]", size) == -1)
@ -607,10 +603,11 @@ int cwmp_rpc_acs_prepare_message_inform (struct cwmp *cwmp, struct session *sess
free(c);
session->tree_out = tree;
dm_ctx_clean(&dmctx);
return 0;
error:
external_free_list_parameter();
dm_ctx_clean(&dmctx);
return -1;
}
@ -764,11 +761,14 @@ int cwmp_rpc_acs_destroy_data_transfer_complete(struct session *session, struct
int cwmp_handle_rpc_cpe_get_parameter_values(struct session *session, struct rpc *rpc)
{
mxml_node_t *n, *parameter_list, *b;
struct parameter_container *parameter_container;
struct dm_parameter *dm_parameter;
char *parameter_name = NULL;
char *parameter_value = NULL;
char *c = NULL;
int counter = 0, fault_code = FAULT_CPE_INTERNAL_ERROR;
struct dmctx dmctx = {0};
dm_ctx_init(&dmctx);
b = session->body_in;
n = mxmlFindElement(session->tree_out, session->tree_out, "soap_env:Body",
@ -798,31 +798,26 @@ int cwmp_handle_rpc_cpe_get_parameter_values(struct session *session, struct rpc
parameter_name = "";
}
if (parameter_name) {
if (external_get_action("value", parameter_name, NULL))
int e = dm_entry_param_method(&dmctx, CMD_GET_VALUE, parameter_name, NULL, NULL);
if (e) {
fault_code = cwmp_get_fault_code(e);
goto fault;
}
}
b = mxmlWalkNext(b, session->body_in, MXML_DESCEND);
parameter_name = NULL;
}
external_handle_action(cwmp_handle_getParamValues);
while (dmctx.list_parameter.next != &dmctx.list_parameter) {
dm_parameter = list_entry(dmctx.list_parameter.next, struct dm_parameter, list);
while (external_list_parameter.next!=&external_list_parameter) {
parameter_container = list_entry(external_list_parameter.next, struct parameter_container, list);
if (parameter_container->fault_code && parameter_container->fault_code[0]=='9')
{
fault_code = cwmp_get_fault_code(parameter_container->fault_code);
goto fault;
}
n = mxmlNewElement(parameter_list, "ParameterValueStruct");
n = mxmlNewElement(parameter_list, "ParameterValueStruct");
if (!n) goto fault;
n = mxmlNewElement(n, "Name");
if (!n) goto fault;
n = mxmlNewText(n, 0, parameter_container->name);
n = mxmlNewText(n, 0, dm_parameter->name);
if (!n) goto fault;
n = n->parent->parent;
@ -830,14 +825,14 @@ int cwmp_handle_rpc_cpe_get_parameter_values(struct session *session, struct rpc
if (!n) goto fault;
#ifdef ACS_MULTI
mxmlElementSetAttr(n, "xsi:type", parameter_container->type);
mxmlElementSetAttr(n, "xsi:type", dm_parameter->type);
#endif
n = mxmlNewText(n, 0, parameter_container->data? parameter_container->data : "");
n = mxmlNewText(n, 0, dm_parameter->data? dm_parameter->data : "");
if (!n) goto fault;
counter++;
parameter_container_delete(parameter_container);
del_list_parameter(dm_parameter);
}
#ifdef ACS_MULTI
b = mxmlFindElement(session->tree_out, session->tree_out, "ParameterList",
@ -851,16 +846,17 @@ int cwmp_handle_rpc_cpe_get_parameter_values(struct session *session, struct rpc
FREE(c);
#endif
dm_ctx_clean(&dmctx);
return 0;
fault:
if (cwmp_create_fault_message(session, rpc, fault_code))
goto error;
external_free_list_parameter();
dm_ctx_clean(&dmctx);
return 0;
error:
external_free_list_parameter();
dm_ctx_clean(&dmctx);
return -1;
}
@ -871,11 +867,14 @@ error:
int cwmp_handle_rpc_cpe_get_parameter_names(struct session *session, struct rpc *rpc)
{
mxml_node_t *n, *parameter_list, *b = session->body_in;
struct parameter_container *parameter_container;
struct dm_parameter *dm_parameter;
char *parameter_name = NULL;
char *NextLevel = NULL;
char *c;
int counter = 0, fault_code = FAULT_CPE_INTERNAL_ERROR;
struct dmctx dmctx = {0};
dm_ctx_init(&dmctx);
n = mxmlFindElement(session->tree_out, session->tree_out, "soap_env:Body",
NULL, NULL, MXML_DESCEND);
@ -912,21 +911,15 @@ int cwmp_handle_rpc_cpe_get_parameter_names(struct session *session, struct rpc
b = mxmlWalkNext(b, session->body_in, MXML_DESCEND);
}
if (parameter_name && NextLevel) {
if (external_get_action("name", parameter_name, NextLevel))
goto fault;
}
external_handle_action(cwmp_handle_getParamNames);
while (external_list_parameter.next!=&external_list_parameter) {
parameter_container = list_entry(external_list_parameter.next, struct parameter_container, list);
if (parameter_container->fault_code && parameter_container->fault_code[0]=='9')
{
fault_code = cwmp_get_fault_code(parameter_container->fault_code);
int e = dm_entry_param_method(&dmctx, CMD_GET_NAME, parameter_name, NextLevel, NULL);
if (e) {
fault_code = cwmp_get_fault_code(e);
goto fault;
}
}
while (dmctx.list_parameter.next != &dmctx.list_parameter) {
dm_parameter = list_entry(dmctx.list_parameter.next, struct dm_parameter, list);
n = mxmlNewElement(parameter_list, "ParameterInfoStruct");
if (!n) goto fault;
@ -934,19 +927,19 @@ int cwmp_handle_rpc_cpe_get_parameter_names(struct session *session, struct rpc
n = mxmlNewElement(n, "Name");
if (!n) goto fault;
n = mxmlNewText(n, 0, parameter_container->name);
n = mxmlNewText(n, 0, dm_parameter->name);
if (!n) goto fault;
n = n->parent->parent;
n = mxmlNewElement(n, "Writable");
if (!n) goto fault;
n = mxmlNewText(n, 0, parameter_container->data);
n = mxmlNewText(n, 0, dm_parameter->data);
if (!n) goto fault;
counter++;
parameter_container_delete(parameter_container);
del_list_parameter(dm_parameter);
}
#ifdef ACS_MULTI
@ -961,16 +954,17 @@ int cwmp_handle_rpc_cpe_get_parameter_names(struct session *session, struct rpc
FREE(c);
#endif
dm_ctx_clean(&dmctx);
return 0;
fault:
if (cwmp_create_fault_message(session, rpc, fault_code))
goto error;
external_free_list_parameter();
dm_ctx_clean(&dmctx);
return 0;
error:
external_free_list_parameter();
dm_ctx_clean(&dmctx);
return -1;
}
@ -981,10 +975,13 @@ error:
int cwmp_handle_rpc_cpe_get_parameter_attributes(struct session *session, struct rpc *rpc)
{
mxml_node_t *n, *parameter_list, *b;
struct parameter_container *parameter_container;
struct dm_parameter *dm_parameter;
char *parameter_name = NULL;
char *c=NULL;
int counter = 0, fault_code = FAULT_CPE_INTERNAL_ERROR;
struct dmctx dmctx = {0};
dm_ctx_init(&dmctx);
b = session->body_in;
n = mxmlFindElement(session->tree_out, session->tree_out, "soap_env:Body",
@ -1014,23 +1011,18 @@ int cwmp_handle_rpc_cpe_get_parameter_attributes(struct session *session, struct
parameter_name = "";
}
if (parameter_name) {
if (external_get_action("notification",parameter_name, NULL))
int e = dm_entry_param_method(&dmctx, CMD_GET_NOTIFICATION, parameter_name, NULL, NULL);
if (e) {
fault_code = cwmp_get_fault_code(e);
goto fault;
}
}
b = mxmlWalkNext(b, session->body_in, MXML_DESCEND);
parameter_name = NULL;
}
external_handle_action(cwmp_handle_getParamAttributes);
while (external_list_parameter.next!=&external_list_parameter) {
parameter_container = list_entry(external_list_parameter.next, struct parameter_container, list);
if (parameter_container->fault_code && parameter_container->fault_code[0]=='9')
{
fault_code = cwmp_get_fault_code(parameter_container->fault_code);
goto fault;
}
while (dmctx.list_parameter.next != &dmctx.list_parameter) {
dm_parameter = list_entry(dmctx.list_parameter.next, struct dm_parameter, list);
n = mxmlNewElement(parameter_list, "ParameterAttributeStruct");
if (!n) goto fault;
@ -1038,14 +1030,14 @@ int cwmp_handle_rpc_cpe_get_parameter_attributes(struct session *session, struct
n = mxmlNewElement(n, "Name");
if (!n) goto fault;
n = mxmlNewText(n, 0, parameter_container->name);
n = mxmlNewText(n, 0, dm_parameter->name);
if (!n) goto fault;
n = n->parent->parent;
n = mxmlNewElement(n, "Notification");
if (!n) goto fault;
n = mxmlNewText(n, 0, parameter_container->data);
n = mxmlNewText(n, 0, dm_parameter->data);
if (!n) goto fault;
n = n->parent->parent;
@ -1057,7 +1049,7 @@ int cwmp_handle_rpc_cpe_get_parameter_attributes(struct session *session, struct
counter++;
parameter_container_delete(parameter_container);
del_list_parameter(dm_parameter);
}
#ifdef ACS_MULTI
b = mxmlFindElement(session->tree_out, session->tree_out, "ParameterList",
@ -1071,16 +1063,17 @@ int cwmp_handle_rpc_cpe_get_parameter_attributes(struct session *session, struct
FREE(c);
#endif
dm_ctx_clean(&dmctx);
return 0;
fault:
if (cwmp_create_fault_message(session, rpc, fault_code))
goto error;
external_free_list_parameter();
dm_ctx_clean(&dmctx);
return 0;
error:
external_free_list_parameter();
dm_ctx_clean(&dmctx);
return -1;
}
@ -1106,7 +1099,6 @@ static int is_duplicated_parameter(mxml_node_t *param_node, struct session *sess
int cwmp_handle_rpc_cpe_set_parameter_values(struct session *session, struct rpc *rpc)
{
mxml_node_t *b, *n;
struct parameter_container *parameter_container;
char *parameter_name = NULL;
char *parameter_value = NULL;
char *parameter_key = NULL;
@ -1114,7 +1106,9 @@ int cwmp_handle_rpc_cpe_set_parameter_values(struct session *session, struct rpc
char *v, *c = NULL;
char buf[128];
int fault_code = FAULT_CPE_INTERNAL_ERROR;
struct dmctx dmctx = {0};
dm_ctx_init(&dmctx);
b = mxmlFindElement(session->body_in, session->body_in, "ParameterList", NULL, NULL, MXML_DESCEND);
if(!b) {
@ -1164,14 +1158,20 @@ int cwmp_handle_rpc_cpe_set_parameter_values(struct session *session, struct rpc
parameter_value = strdup("");
}
if (parameter_name && parameter_value) {
if (external_set_action("value", parameter_name, parameter_value, NULL))
goto fault;
int e = dm_entry_param_method(&dmctx, CMD_SET_VALUE, parameter_name, parameter_value, NULL);
if (e) {
fault_code = FAULT_CPE_INVALID_ARGUMENTS;
}
parameter_name = NULL;
FREE(parameter_value);
}
b = mxmlWalkNext(b, session->body_in, MXML_DESCEND);
}
if (fault_code == FAULT_CPE_INVALID_ARGUMENTS) {
goto fault;
}
b = mxmlFindElement(session->body_in, session->body_in, "ParameterKey", NULL, NULL, MXML_DESCEND);
if(!b) {
fault_code = FAULT_CPE_REQUEST_DENIED;
@ -1182,26 +1182,12 @@ int cwmp_handle_rpc_cpe_set_parameter_values(struct session *session, struct rpc
if (b && b->type == MXML_TEXT && b->value.text.string)
parameter_key = b->value.text.string;
if (external_apply("value", parameter_key ? parameter_key : ""))
int f = dm_entry_apply(&dmctx, CMD_SET_VALUE, parameter_key ? parameter_key : "", NULL);
if (f) {
fault_code = cwmp_get_fault_code(f);
goto fault;
external_handle_action(cwmp_handle_setParamValues);
while (external_list_parameter.next != &external_list_parameter) {
parameter_container = list_entry(external_list_parameter.next, struct parameter_container, list);
if (parameter_container->fault_code && parameter_container->fault_code[0]=='9')
{
fault_code = FAULT_CPE_INVALID_ARGUMENTS;
goto fault;
}
}
external_fetch_setParamValRespStatus(&status);
if(!status)
goto fault;
b = mxmlFindElement(session->tree_out, session->tree_out, "soap_env:Body",
NULL, NULL, MXML_DESCEND);
if (!b) goto fault;
@ -1212,22 +1198,22 @@ int cwmp_handle_rpc_cpe_set_parameter_values(struct session *session, struct rpc
b = mxmlNewElement(b, "Status");
if (!b) goto fault;
b = mxmlNewText(b, 0, status);
b = mxmlNewText(b, 0, "1");
if (!b) goto fault;
success:
free(status);
dm_ctx_clean(&dmctx);
return 0;
fault:
rpc->list_set_value_fault = &dmctx.list_fault_param;
if (cwmp_create_fault_message(session, rpc, fault_code))
goto error;
external_free_list_parameter();
goto success;
dm_ctx_clean(&dmctx);
return 0;
error:
external_free_list_parameter();
free(status);
dm_ctx_clean(&dmctx);
return -1;
}
@ -1238,8 +1224,11 @@ error:
int cwmp_handle_rpc_cpe_set_parameter_attributes(struct session *session, struct rpc *rpc)
{
mxml_node_t *n, *b = session->body_in;
char *c, *parameter_name = NULL, *parameter_notification = NULL, *attr_notification_update = NULL, *success=NULL, *fault=NULL;
char *c, *parameter_name = NULL, *parameter_notification = NULL, *attr_notification_update = NULL;
int fault_code = FAULT_CPE_INTERNAL_ERROR;
struct dmctx dmctx = {0};
dm_ctx_init(&dmctx);
/* handle cwmp:SetParameterAttributes */
if (asprintf(&c, "%s:%s", ns.cwmp, "SetParameterAttributes") == -1)
@ -1292,9 +1281,11 @@ int cwmp_handle_rpc_cpe_set_parameter_attributes(struct session *session, struct
parameter_notification = "";
}
if (attr_notification_update && parameter_name && parameter_notification) {
if (external_set_action("notification", parameter_name,
parameter_notification, attr_notification_update))
int e = dm_entry_param_method(&dmctx, CMD_SET_NOTIFICATION, parameter_name, parameter_notification, attr_notification_update);
if (e) {
fault_code = cwmp_get_fault_code(e);
goto fault;
}
attr_notification_update = NULL;
parameter_name = NULL;
parameter_notification = NULL;
@ -1302,22 +1293,12 @@ int cwmp_handle_rpc_cpe_set_parameter_attributes(struct session *session, struct
b = mxmlWalkNext(b, n, MXML_DESCEND);
}
if (external_apply("notification", NULL))
goto fault;
external_handle_action(cwmp_handle_setParamAttributes);
external_fetch_setParamAttrResp(&success, &fault);
if (fault && fault[0]=='9')
{
fault_code = cwmp_get_fault_code(fault);
int f = dm_entry_apply(&dmctx, CMD_SET_NOTIFICATION, NULL, NULL);
if (f) {
fault_code = cwmp_get_fault_code(f);
goto fault;
}
if(!success)
goto fault;
b = mxmlFindElement(session->tree_out, session->tree_out, "soap_env:Body", NULL, NULL, MXML_DESCEND);
if (!b) goto fault;
@ -1325,18 +1306,17 @@ int cwmp_handle_rpc_cpe_set_parameter_attributes(struct session *session, struct
if (!b) goto fault;
end_success:
free(success);
free(fault);
dm_ctx_clean(&dmctx);
return 0;
fault:
if (cwmp_create_fault_message(session, rpc, fault_code))
goto error;
goto end_success;
dm_ctx_clean(&dmctx);
return 0;
error:
free(success);
free(fault);
dm_ctx_clean(&dmctx);
return -1;
}
@ -1351,8 +1331,10 @@ int cwmp_handle_rpc_cpe_add_object(struct session *session, struct rpc *rpc)
char buf[128];
char *object_name = NULL;
char *parameter_key = NULL;
char *status = NULL, *instance = NULL, *fault = NULL;
int fault_code = FAULT_CPE_INTERNAL_ERROR;
struct dmctx dmctx = {0};
dm_ctx_init(&dmctx);
b = session->body_in;
while (b) {
@ -1372,25 +1354,16 @@ int cwmp_handle_rpc_cpe_add_object(struct session *session, struct rpc *rpc)
}
if (object_name) {
if (external_object_action("add", object_name, parameter_key ? parameter_key : ""))
int e = dm_entry_param_method(&dmctx, CMD_ADD_OBJECT, object_name, parameter_key ? parameter_key : "", NULL);
if (e) {
fault_code = cwmp_get_fault_code(e);
goto fault;
}
} else {
fault_code = FAULT_CPE_INVALID_PARAMETER_NAME;
goto fault;
}
external_handle_action(cwmp_handle_addObject);
external_fetch_addObjectResp(&instance, &status, &fault);
if (fault && fault[0]=='9')
{
fault_code = cwmp_get_fault_code(fault);
goto fault;
}
if (instance == NULL || status == NULL)
goto fault;
b = mxmlFindElement(session->tree_out, session->tree_out, "soap_env:Body",
NULL, NULL, MXML_DESCEND);
if (!b) goto fault;
@ -1401,31 +1374,28 @@ int cwmp_handle_rpc_cpe_add_object(struct session *session, struct rpc *rpc)
b = mxmlNewElement(b, "InstanceNumber");
if (!b) goto fault;
b = mxmlNewText(b, 0, instance);
b = mxmlNewText(b, 0, dmctx.addobj_instance);
if (!b) goto fault;
b = b->parent->parent;
b = mxmlNewElement(b, "Status");
if (!b) goto fault;
b = mxmlNewText(b, 0, status);
b = mxmlNewText(b, 0, "1");
if (!b) goto fault;
success:
free(instance);
free(fault);
free(status);
dm_ctx_clean(&dmctx);
return 0;
fault:
if (cwmp_create_fault_message(session, rpc, fault_code))
goto error;
goto success;
dm_ctx_clean(&dmctx);
return 0;
error:
free(instance);
free(fault);
free(status);
dm_ctx_clean(&dmctx);
return -1;
}
@ -1439,8 +1409,10 @@ int cwmp_handle_rpc_cpe_delete_object(struct session *session, struct rpc *rpc)
char buf[128];
char *object_name = NULL;
char *parameter_key = NULL;
char *status = NULL, *fault = NULL;
int fault_code = FAULT_CPE_INTERNAL_ERROR;
struct dmctx dmctx = {0};
dm_ctx_init(&dmctx);
b = session->body_in;
while (b) {
@ -1460,25 +1432,16 @@ int cwmp_handle_rpc_cpe_delete_object(struct session *session, struct rpc *rpc)
}
if (object_name) {
if (external_object_action("delete", object_name, parameter_key ? parameter_key : ""))
int e = dm_entry_param_method(&dmctx, CMD_DEL_OBJECT, object_name, parameter_key ? parameter_key : "", NULL);
if (e) {
fault_code = cwmp_get_fault_code(e);
goto fault;
}
} else {
fault_code = FAULT_CPE_INVALID_PARAMETER_NAME;
goto fault;
}
external_handle_action(cwmp_handle_delObject);
external_fetch_delObjectResp(&status, &fault);
if (fault && fault[0]=='9')
{
fault_code = cwmp_get_fault_code(fault);
goto fault;
}
if (status == NULL)
goto fault;
b = mxmlFindElement(session->tree_out, session->tree_out, "soap_env:Body",
NULL, NULL, MXML_DESCEND);
@ -1490,22 +1453,21 @@ int cwmp_handle_rpc_cpe_delete_object(struct session *session, struct rpc *rpc)
b = mxmlNewElement(b, "Status");
if (!b) goto fault;
b = mxmlNewText(b, 0, status);
b = mxmlNewText(b, 0, "1");
if (!b) goto fault;
success:
free(fault);
free(status);
dm_ctx_clean(&dmctx);
return 0;
fault:
if (cwmp_create_fault_message(session, rpc, fault_code))
goto error;
goto success;
dm_ctx_clean(&dmctx);
return 0;
error:
free(fault);
free(status);
dm_ctx_clean(&dmctx);
return -1;
}
@ -1910,7 +1872,6 @@ void *thread_cwmp_rpc_cpe_download (void *v)
struct transfer_complete *ptransfer_complete;
long int time_of_grace = 3600,timeout;
char *fault_code;
struct parameter_container *parameter_container;
for(;;)
{
@ -1962,15 +1923,7 @@ void *thread_cwmp_rpc_cpe_download (void *v)
else
{
if (pdownload->file_type[0] == '1') {
external_get_action("value", DM_SOFTWARE_VERSION_PATH, NULL);
external_handle_action(cwmp_handle_getParamValues);
parameter_container = list_entry(external_list_parameter.next, struct parameter_container, list);
if ((!parameter_container->fault_code || parameter_container->fault_code[0] != '9') &&
strcmp(parameter_container->name, DM_SOFTWARE_VERSION_PATH) == 0)
{
ptransfer_complete->old_software_version = strdup(parameter_container->data);
}
external_free_list_parameter();
ptransfer_complete->old_software_version = cwmp->deviceid.softwareversion;
}
bkp_session_insert_transfer_complete(ptransfer_complete);
bkp_session_save();
@ -2254,7 +2207,7 @@ int cwmp_handle_rpc_cpe_download(struct session *session, struct rpc *rpc)
}
pthread_mutex_unlock (&mutex_download);
pthread_cond_signal(&threshold_download);
pthread_cond_signal(&threshold_download);
}
return 0;
@ -2276,7 +2229,7 @@ error:
int cwmp_handle_rpc_cpe_fault(struct session *session, struct rpc *rpc)
{
mxml_node_t *b, *t, *u, *body;
struct parameter_container *parameter_container;
struct param_fault *param_fault;
int idx;
body = mxmlFindElement(session->tree_out, session->tree_out, "soap_env:Body",
@ -2317,12 +2270,12 @@ int cwmp_handle_rpc_cpe_fault(struct session *session, struct rpc *rpc)
if (!u) return -1;
if (rpc->type == RPC_CPE_SET_PARAMETER_VALUES) {
while (external_list_parameter.next != &external_list_parameter) {
parameter_container = list_entry(external_list_parameter.next, struct parameter_container, list);
while (rpc->list_set_value_fault->next != rpc->list_set_value_fault) {
param_fault = list_entry(rpc->list_set_value_fault->next, struct param_fault, list);
if (parameter_container->fault_code && parameter_container->fault_code[0]=='9')
if (param_fault->fault)
{
idx = cwmp_get_fault_code(parameter_container->fault_code);
idx = cwmp_get_fault_code(param_fault->fault);
t = mxmlNewElement(b, "SetParameterValuesFault");
if (!t) return -1;
@ -2330,7 +2283,7 @@ int cwmp_handle_rpc_cpe_fault(struct session *session, struct rpc *rpc)
u = mxmlNewElement(t, "ParameterName");
if (!u) return -1;
u = mxmlNewText(u, 0, parameter_container->name);
u = mxmlNewText(u, 0, param_fault->name);
if (!u) return -1;
u = mxmlNewElement(t, "FaultCode");
@ -2345,20 +2298,20 @@ int cwmp_handle_rpc_cpe_fault(struct session *session, struct rpc *rpc)
u = mxmlNewText(u, 0, FAULT_CPE_ARRAY[idx].DESCRIPTION);
if (!u) return -1;
}
parameter_container_delete(parameter_container);
del_list_fault_param(param_fault);
}
}
return 0;
}
int cwmp_get_fault_code (char *fault_code)
int cwmp_get_fault_code (int fault_code)
{
int i;
for (i=1; i<__FAULT_CPE_MAX; i++)
{
if (strcmp(FAULT_CPE_ARRAY[i].CODE, fault_code) == 0)
if (FAULT_CPE_ARRAY[i].ICODE == fault_code)
break;
}