PIVA::DELIVERY 8

script optimization
Voice parameters: AddObject/DeleteObject
Voice parameters: Vendor specific parameter

Concerning what we did in the optimization task:
1)  The main script  (freecwmp) is loaded only 1 time during the session. the load is done just before the start of the session. the function scripts are loaded within the load of the main script (freecwmp) only one time. The old behaviour consist to load the main script (freecwmp) and the function scripts for each parameter treatment. Core code (C) and Scripts are changed
2) Optimize the preparing of inform message. old script take ~30s and now it takes ~2s. Core code (C) and Scripts are changed
3) Execute only the function related to the parameter. For example if the requested parameter is "InternetGatewayDevice.ManagementServer.URL" then the main script freecwmp will execute only the related function of this parameter which is get_management_server(). The old behaviour consist to execute all get functions: get_wan_device(), get_lan_device(), get_device_info()...
4) Minimize the size of the script files: Replace some blocks o othe source code by a functions
This commit is contained in:
Mohamed Kallel 2013-07-24 16:05:32 +01:00
parent c4274242a5
commit 27b73d5af7
31 changed files with 2872 additions and 8090 deletions

View file

@ -3,10 +3,10 @@
* 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.
* Powered by Inteno Broadband Technology AB
*
* Copyright (C) 2013 Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Copyright (C) 2013 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2013 Inteno Broadband Technology AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
*
*/

View file

@ -3,10 +3,10 @@
* 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.
* Powered by Inteno Broadband Technology AB
*
* Copyright (C) 2013 Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Copyright (C) 2013 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2013 Inteno Broadband Technology AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
*
*/

View file

@ -58,3 +58,18 @@ config notifications
config cwmp
option parameter 'InternetGatewayDevice.DeviceInfo.SpecVersion'
option value '1.0'
config DeviceInfo
list function 'device_info'
config Services
list function 'voice_service'
config LANDevice
list function 'lan_device'
config ManagementServer
list function 'management_server'
config WANDevice
list function 'wan_device'

14
cwmp.c
View file

@ -3,10 +3,10 @@
* 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.
* Powered by Inteno Broadband Technology AB
*
* Copyright (C) 2013 Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Copyright (C) 2013 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2013 Inteno Broadband Technology AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
*
*/
@ -136,10 +136,12 @@ void cwmp_schedule_session (struct cwmp *cwmp)
CWMP_LOG(EMERG,"FATAL error in the mutex process in the session scheduler!");
exit(EXIT_FAILURE);
}
external_init();
CWMP_LOG (INFO,"Start session");
error = cwmp_schedule_rpc (cwmp,session);
CWMP_LOG (INFO,"End session");
run_session_end_func(session);
external_exit();
if (session->error == CWMP_RETRY_SESSION)
{
error = cwmp_move_session_to_session_queue (cwmp, session);
@ -440,20 +442,20 @@ 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_simple("end_session", NULL);
external_simple("end_session");
}
if (session->end_session & END_SESSION_FACTORY_RESET)
{
CWMP_LOG (INFO,"Executing factory reset: end session request");
external_simple("factory_reset", NULL);
external_simple("factory_reset");
exit(EXIT_SUCCESS);
}
if (session->end_session & END_SESSION_REBOOT)
{
CWMP_LOG (INFO,"Executing Reboot: end session request");
external_simple("reboot", NULL);
external_simple("reboot");
exit(EXIT_SUCCESS);
}

View file

@ -3,10 +3,10 @@
* 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.
* Powered by Inteno Broadband Technology AB
*
* Copyright (C) 2013 Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Copyright (C) 2013 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2013 Inteno Broadband Technology AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
*
*/

View file

@ -3,31 +3,38 @@
* 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.
* Contributed by Inteno Broadband Technology AB
*
* Copyright (C) 2013 Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Copyright (C) 2013 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2013 Inteno Broadband Technology AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2011 Luka Perkov <freecwmp@lukaperkov.net>
*/
#include <errno.h>
#include <malloc.h>
#include <poll.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <libubox/uloop.h>
#include <json/json.h>
#include "external.h"
#include "cwmp.h"
#include "log.h"
static struct uloop_process uproc;
static pthread_mutex_t external_mutex_exec = PTHREAD_MUTEX_INITIALIZER;
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);
@ -134,523 +141,259 @@ void external_fetch_delObjectResp (char **status, char **fault)
external_MethodFault = NULL;
}
static void external_action_jshn_parse(int fp, int external_handler(char *msg))
static void external_read_pipe_input(int (*external_handler)(char *msg))
{
char buf[1], *value = NULL, *c = NULL;
int i=0, len;
while(read(fp, buf, sizeof(buf))>0) {
struct pollfd fd = {
.fd = pfds_in[0],
.events = POLLIN
};
while(1) {
poll(&fd, 1, 500000);
if (!(fd.revents & POLLIN)) break;
if (read(pfds_in[0], buf, sizeof(buf))<=0) break;
if (buf[0]!='\n') {
if (value)
asprintf(&c,"%s%c",value,buf[0]);
else
asprintf(&c,"%c",buf[0]);
free(value);
FREE(value);
value = c;
} else {
if (!value) continue;
external_handler(value);
if (strcmp(value, "EOF")==0) break;
if(external_handler) external_handler(value);
FREE(value);
}
}
}
int external_get_action(char *action, char *name, char *arg, int external_handler(char *msg))
static void external_write_pipe_output(const char *msg)
{
char *value = NULL;
int i=0, len;
asprintf(&value, "%s\n", msg);
if (write(pfds_out[1], value, strlen(value)) == -1) {
CWMP_LOG(ERROR,"Error occured when trying to write to the pipe");
}
free(value);
}
static void json_obj_out_add(json_object *json_obj_out, char *name, char *val)
{
json_object *json_obj_tmp;
json_obj_tmp = json_object_new_string(val);
json_object_object_add(json_obj_out, name, json_obj_tmp);
}
void external_init()
{
if (pipe(pfds_in) < 0)
return;
if (pipe(pfds_out) < 0)
return;
if ((pid = fork()) == -1)
goto error;
if (pid == 0) {
/* child */
close(pfds_out[1]);
close(pfds_in[0]);
dup2(pfds_out[0], STDIN_FILENO);
dup2(pfds_in[1], STDOUT_FILENO);
const char *argv[5];
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);
close(pfds_out[0]);
close(pfds_in[1]);
exit(ESRCH);
}
close(pfds_in[1]);
close(pfds_out[0]);
external_read_pipe_input(NULL);
DD(INFO, "freecwmp script is listening");
return;
error:
CWMP_LOG(ERROR,"freecwmp script intialization failed");
exit(EXIT_FAILURE);
}
void external_exit()
{
int status;
json_object *json_obj_out;
json_obj_out = json_object_new_object();
json_obj_out_add(json_obj_out, "command", "exit");
external_write_pipe_output(json_object_to_json_string(json_obj_out));
json_object_put(json_obj_out);
while (wait(&status) != pid) {
DD(DEBUG, "waiting for child to exit");
}
close(pfds_in[0]);
close(pfds_out[1]);
}
int external_handle_action(int (*external_handler)(char *msg))
{
json_object *json_obj_out;
json_obj_out = json_object_new_object();
json_obj_out_add(json_obj_out, "command", "end");
external_write_pipe_output(json_object_to_json_string(json_obj_out));
json_object_put(json_obj_out);
external_read_pipe_input(external_handler);
return 0;
}
int external_get_action(char *action, char *name, char *next_level)
{
int pfds[2];
if (pipe(pfds) < 0)
return -1;
pthread_mutex_lock(&external_mutex_exec);
DD(INFO,"executing get %s '%s'", action, name);
if ((uproc.pid = fork()) == -1)
goto error;
json_object *json_obj_out;
if (uproc.pid == 0) {
/* child */
/* send data to the script */
json_obj_out = json_object_new_object();
const char *argv[8];
int i = 0;
argv[i++] = "/bin/sh";
argv[i++] = fc_script;
argv[i++] = "--json";
argv[i++] = "get";
argv[i++] = action;
argv[i++] = name;
if(arg) argv[i++] = arg;
argv[i++] = NULL;
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);
close(pfds[0]);
dup2(pfds[1], 1);
close(pfds[1]);
external_write_pipe_output(json_object_to_json_string(json_obj_out));
execvp(argv[0], (char **) argv);
exit(ESRCH);
json_object_put(json_obj_out);
} else if (uproc.pid < 0)
goto error;
/* parent */
close(pfds[1]);
int status;
while (wait(&status) != uproc.pid) {
DD(DEBUG,"waiting for child to exit");
}
external_action_jshn_parse(pfds[0], external_handler);
close(pfds[0]);
pthread_mutex_unlock(&external_mutex_exec);
return 0;
error:
close(pfds[0]);
pthread_mutex_unlock(&external_mutex_exec);
return -1;
}
int external_get_action_write(char *action, char *name, char *arg)
int external_set_action(char *action, char *name, char *value, char *change)
{
pthread_mutex_lock(&external_mutex_exec);
DD(INFO,"adding to get %s script '%s'", action, name);
DD(INFO,"executing set %s '%s'", action, name);
FILE *fp;
json_object *json_obj_out;
if (access(fc_script_actions, R_OK | W_OK | X_OK) != -1) {
fp = fopen(fc_script_actions, "a");
if (!fp) goto error;
} else {
fp = fopen(fc_script_actions, "w");
if (!fp) goto error;
/* send data to the script */
json_obj_out = json_object_new_object();
fprintf(fp, "#!/bin/sh\n");
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);
if (chmod(fc_script_actions,
strtol("0700", 0, 8)) < 0) {
goto error;
}
}
external_write_pipe_output(json_object_to_json_string(json_obj_out));
#ifdef DUMMY_MODE
fprintf(fp, "/bin/sh `pwd`/%s --json get %s %s %s\n", fc_script, action, name, arg?arg:"");
#else
fprintf(fp, "/bin/sh %s --json get %s %s %s\n", fc_script, action, name, arg?arg:"");
#endif
json_object_put(json_obj_out);
fclose(fp);
pthread_mutex_unlock(&external_mutex_exec);
return 0;
error:
pthread_mutex_unlock(&external_mutex_exec);
return -1;
}
int external_get_action_execute(int external_handler(char *msg))
int external_object_action(char *command, char *name)
{
int pfds[2];
if (pipe(pfds) < 0)
return -1;
DD(INFO,"executing %s object '%s'", action, name);
pthread_mutex_lock(&external_mutex_exec);
json_object *json_obj_out;
if (access(fc_script_actions, F_OK) == -1)
goto success;
/* send data to the script */
json_obj_out = json_object_new_object();
DD(INFO,"executing get script");
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 ((uproc.pid = fork()) == -1) {
goto error;
}
external_write_pipe_output(json_object_to_json_string(json_obj_out));
if (uproc.pid == 0) {
/* child */
json_object_put(json_obj_out);
const char *argv[3];
int i = 0;
argv[i++] = "/bin/sh";
argv[i++] = fc_script_actions;
argv[i++] = NULL;
close(pfds[0]);
dup2(pfds[1], 1);
close(pfds[1]);
execvp(argv[0], (char **) argv);
exit(ESRCH);
} else if (uproc.pid < 0)
goto error;
/* parent */
close(pfds[1]);
int status;
while (wait(&status) != uproc.pid) {
DD(DEBUG,"waiting for child to exit");
}
external_action_jshn_parse(pfds[0], external_handler);
remove(fc_script_actions);
success:
close(pfds[0]);
pthread_mutex_unlock(&external_mutex_exec);
return 0;
error:
close(pfds[0]);
pthread_mutex_unlock(&external_mutex_exec);
return -1;
}
int external_set_action_write(char *action, char *name, char *value, char *change)
int external_simple(char *command)
{
pthread_mutex_lock(&external_mutex_exec);
DD(INFO,"adding to set %s script '%s'", action, name);
DD(INFO,"executing %s request", command);
FILE *fp;
json_object *json_obj_out;
if (access(fc_script_actions, R_OK | W_OK | X_OK) != -1) {
fp = fopen(fc_script_actions, "a");
if (!fp) goto error;
} else {
fp = fopen(fc_script_actions, "w");
if (!fp) goto error;
/* send data to the script */
json_obj_out = json_object_new_object();
fprintf(fp, "#!/bin/sh\n");
json_obj_out_add(json_obj_out, "command", command);
if (chmod(fc_script_actions,
strtol("0700", 0, 8)) < 0) {
goto error;
}
}
#ifdef DUMMY_MODE
fprintf(fp, "/bin/sh `pwd`/%s --json set %s %s %s %s\n", fc_script, action, name, value, change ? change : "");
#else
fprintf(fp, "/bin/sh %s --json set %s %s %s %s\n", fc_script, action, name, value, change ? change : "");
#endif
external_write_pipe_output(json_object_to_json_string(json_obj_out));
json_object_put(json_obj_out);
fclose(fp);
pthread_mutex_unlock(&external_mutex_exec);
return 0;
error:
pthread_mutex_unlock(&external_mutex_exec);
return -1;
}
int external_set_action_execute(char *action, int external_handler(char *msg))
int external_download(char *url, char *size, char *type, char *user, char *pass)
{
int pfds[2];
if (pipe(pfds) < 0)
return -1;
pthread_mutex_lock(&external_mutex_exec);
DD(INFO,"executing set script");
FILE *fp;
if (access(fc_script_actions, R_OK | W_OK | F_OK) == -1)
goto error;
fp = fopen(fc_script_actions, "a");
if (!fp) goto error;
#ifdef DUMMY_MODE
fprintf(fp, "/bin/sh `pwd`/%s --json apply %s\n", fc_script, action);
#else
fprintf(fp, "/bin/sh %s --json apply %s\n", fc_script, action);
#endif
fclose(fp);
if ((uproc.pid = fork()) == -1) {
goto error;
}
if (uproc.pid == 0) {
/* child */
const char *argv[3];
int i = 0;
argv[i++] = "/bin/sh";
argv[i++] = fc_script_actions;
argv[i++] = NULL;
close(pfds[0]);
dup2(pfds[1], 1);
close(pfds[1]);
execvp(argv[0], (char **) argv);
exit(ESRCH);
} else if (uproc.pid < 0)
goto error;
/* parent */
close(pfds[1]);
int status;
while (wait(&status) != uproc.pid) {
DD(DEBUG,"waiting for child to exit");
}
external_action_jshn_parse(pfds[0], external_handler);
if (remove(fc_script_actions) != 0)
goto error;
close(pfds[0]);
pthread_mutex_unlock(&external_mutex_exec);
return 0;
error:
close(pfds[0]);
pthread_mutex_unlock(&external_mutex_exec);
return -1;
}
int external_object_action(char *action, char *name, int external_handler(char *msg))
{
int pfds[2];
if (pipe(pfds) < 0)
return -1;
pthread_mutex_lock(&external_mutex_exec);
DD(INFO,"executing object %s '%s'", action, name);
if ((uproc.pid = fork()) == -1)
goto error;
if (uproc.pid == 0) {
/* child */
const char *argv[8];
int i = 0;
argv[i++] = "/bin/sh";
argv[i++] = fc_script;
argv[i++] = "--json";
argv[i++] = action;
argv[i++] = "object";
argv[i++] = name;
argv[i++] = NULL;
close(pfds[0]);
dup2(pfds[1], 1);
close(pfds[1]);
execvp(argv[0], (char **) argv);
exit(ESRCH);
} else if (uproc.pid < 0)
goto error;
close(pfds[1]);
int status;
while (wait(&status) != uproc.pid) {
DD(DEBUG, "waiting for child to exit");
}
external_action_jshn_parse(pfds[0], external_handler);
close(pfds[0]);
pthread_mutex_unlock(&external_mutex_exec);
return 0;
error:
close(pfds[0]);
pthread_mutex_unlock(&external_mutex_exec);
return -1;
}
int external_simple(char *arg, int external_handler(char *msg))
{
int pfds[2];
if (pipe(pfds) < 0)
return -1;
pthread_mutex_lock(&external_mutex_exec);
DD(INFO,"executing %s request", arg);
if ((uproc.pid = fork()) == -1)
goto error;
if (uproc.pid == 0) {
/* child */
const char *argv[6];
int i = 0;
argv[i++] = "/bin/sh";
argv[i++] = fc_script;
argv[i++] = "--json";
argv[i++] = arg;
argv[i++] = NULL;
close(pfds[0]);
dup2(pfds[1], 1);
close(pfds[1]);
execvp(argv[0], (char **) argv);
exit(ESRCH);
} else if (uproc.pid < 0)
goto error;
/* parent */
close(pfds[1]);
int status;
while (wait(&status) != uproc.pid) {
DD(DEBUG,"waiting for child to exit");
}
if (external_handler)
external_action_jshn_parse(pfds[0], external_handler);
close(pfds[0]);
pthread_mutex_unlock(&external_mutex_exec);
return 0;
error:
close(pfds[0]);
pthread_mutex_unlock(&external_mutex_exec);
return -1;
}
int external_download(char *url, char *size, char *type, char *user, char *pass, int external_handler(char *msg))
{
int pfds[2];
if (pipe(pfds) < 0)
return -1;
pthread_mutex_lock(&external_mutex_exec);
DD(INFO,"executing download url '%s'", url);
if ((uproc.pid = fork()) == -1)
goto error;
json_object *json_obj_out;
if (uproc.pid == 0) {
/* child */
/* send data to the script */
json_obj_out = json_object_new_object();
const char *argv[20];
int i = 0;
argv[i++] = "/bin/sh";
argv[i++] = fc_script;
argv[i++] = "download";
argv[i++] = "--json";
argv[i++] = "--url";
argv[i++] = url;
argv[i++] = "--size";
argv[i++] = size;
argv[i++] = "--type";
argv[i++] = type;
if(user)
{
argv[i++] = "--user";
argv[i++] = user;
}
if(pass)
{
argv[i++] = "--pass";
argv[i++] = pass;
}
argv[i++] = NULL;
json_obj_out_add(json_obj_out, "command", "download");
json_obj_out_add(json_obj_out, "url", url);
json_obj_out_add(json_obj_out, "size", size);
json_obj_out_add(json_obj_out, "type", type);
if(user) json_obj_out_add(json_obj_out, "user", user);
if(pass) json_obj_out_add(json_obj_out, "pass", pass);
close(pfds[0]);
dup2(pfds[1], 1);
close(pfds[1]);
external_write_pipe_output(json_object_to_json_string(json_obj_out));
execvp(argv[0], (char **) argv);
exit(ESRCH);
json_object_put(json_obj_out);
} else if (uproc.pid < 0)
goto error;
/* parent */
close(pfds[1]);
int status;
while (wait(&status) != uproc.pid) {
DD(INFO,"waiting for child to exit");
}
external_action_jshn_parse(pfds[0], external_handler);
close(pfds[0]);
pthread_mutex_unlock(&external_mutex_exec);
return 0;
error:
close(pfds[0]);
pthread_mutex_unlock(&external_mutex_exec);
return -1;
}
int external_apply_download(char *type, int external_handler(char *msg))
int external_apply(char *action, char *type)
{
int pfds[2];
if (pipe(pfds) < 0)
return -1;
DD(INFO,"executing apply %s", action);
pthread_mutex_lock(&external_mutex_exec);
DD(INFO,"applying downloaded file");
json_object *json_obj_out;
if ((uproc.pid = fork()) == -1)
goto error;
/* send data to the script */
json_obj_out = json_object_new_object();
if (uproc.pid == 0) {
/* child */
json_obj_out_add(json_obj_out, "command", "apply");
json_obj_out_add(json_obj_out, "action", action);
if (type) json_obj_out_add(json_obj_out, "type", type);
const char *argv[8];
int i = 0;
argv[i++] = "/bin/sh";
argv[i++] = fc_script;
argv[i++] = "--json";
argv[i++] = "apply";
argv[i++] = "download";
argv[i++] = "--type";
argv[i++] = type;
argv[i++] = NULL;
external_write_pipe_output(json_object_to_json_string(json_obj_out));
close(pfds[0]);
dup2(pfds[1], 1);
close(pfds[1]);
json_object_put(json_obj_out);
execvp(argv[0], (char **) argv);
exit(ESRCH);
} else if (uproc.pid < 0)
goto error;
/* parent */
close(pfds[1]);
int status;
while (wait(&status) != uproc.pid) {
DD(INFO,"waiting for child to exit");
}
external_action_jshn_parse(pfds[0], external_handler);
close(pfds[0]);
pthread_mutex_unlock(&external_mutex_exec);
return 0;
error:
close(pfds[0]);
pthread_mutex_unlock(&external_mutex_exec);
return -1;
}

6
http.c
View file

@ -3,10 +3,10 @@
* 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.
* Contributed by Inteno Broadband Technology AB
*
* Copyright (C) 2013 Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Copyright (C) 2013 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2013 Inteno Broadband Technology AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2011-2012 Luka Perkov <freecwmp@lukaperkov.net>
*/

View file

@ -3,10 +3,10 @@
* 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.
* Powered by Inteno Broadband Technology AB
*
* Copyright (C) 2013 Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Copyright (C) 2013 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2013 Inteno Broadband Technology AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
*
*/

View file

@ -3,10 +3,10 @@
* 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.
* Powered by Inteno Broadband Technology AB
*
* Copyright (C) 2013 Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Copyright (C) 2013 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2013 Inteno Broadband Technology AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
*
*/

View file

@ -3,10 +3,10 @@
* 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.
* Contributed by Inteno Broadband Technology AB
*
* Copyright (C) 2013 Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Copyright (C) 2013 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2013 Inteno Broadband Technology AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2011 Luka Perkov <freecwmp@lukaperkov.net>
*
*/
@ -20,7 +20,6 @@ static char *fc_script = "./ext/openwrt/scripts/freecwmp.sh";
#else
static char *fc_script = "/usr/sbin/freecwmp";
#endif
static char *fc_script_actions = "/tmp/freecwmp_action.sh";
extern pthread_mutex_t external_mutex_value_change;
extern struct list_head external_list_value_change;
@ -36,17 +35,17 @@ 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 *arg, int external_handler(char *msg));
int external_get_action_write(char *action, char *name, char *arg);
int external_get_action_execute(int external_handler(char *msg));
int external_set_action_write(char *action, char *name, char *value, char *change);
int external_set_action_execute(char *action, int external_handler(char *msg));
int external_object_action(char *action, char *name, int external_handler(char *msg));
int external_simple(char *arg, int external_handler(char *msg));
int external_download(char *url, char *size, char *type, char *user, char *pass, int external_handler(char *msg));
int external_apply_download(char *type, int external_handler(char *msg));
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);
int external_simple(char *command);
int external_download(char *url, char *size, char *type, char *user, char *pass);
int external_apply(char *action, char *type);
int external_handle_action(int (*external_handler)(char *msg));
void external_add_list_paramameter(char *param_name, char *param_data, char *param_type, char *fault_code);
void external_free_list_parameter();
void external_init();
void external_exit();
#endif

View file

@ -3,10 +3,10 @@
* 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.
* Powered by Inteno Broadband Technology AB
*
* Copyright (C) 2013 Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Copyright (C) 2013 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2013 Inteno Broadband Technology AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
*
*/

View file

@ -3,10 +3,10 @@
* 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.
* Powered by Inteno Broadband Technology AB
*
* Copyright (C) 2013 Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Copyright (C) 2013 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2013 Inteno Broadband Technology AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
*
*/

View file

@ -3,10 +3,10 @@
* 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.
* Contributed by Inteno Broadband Technology AB
*
* Copyright (C) 2013 Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Copyright (C) 2013 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2013 Inteno Broadband Technology AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2011 Luka Perkov <freecwmp@lukaperkov.net>
*
*/

View file

@ -66,17 +66,17 @@ check_dhcp() {
done
fi
}
set_wan_interface()
{
local device=""
set_wan_interface() {
local l3_device=""
local default_wan_interface=""
config_load cwmp
config_get default_wan_interface cpe default_wan_interface
json_load "$(ifstatus $default_wan_interface)"
json_get_var device device
uci_set cwmp cpe interface "$device"
json_get_var l3_device l3_device
if [ "$l3_device" != "" ];then
uci_set cwmp cpe interface "$l3_device"
uci_commit
fi
}
start_msg="Start cwmpd ..."
@ -104,15 +104,6 @@ boot() {
}
start() {
local default_wan_interface
config_load cwmp
config_get default_wan_interface cpe default_wan_interface
json_load "$(ifstatus $default_wan_interface)"
json_get_var device device
if [ "$device" != "" ];then
uci -q set cwmp.cpe.interface="$device"
uci commit -q
fi
run=$(ps aux|grep /usr/sbin/cwmpd|grep -v grep|grep -v rc.common)
if [ "$run" = "" ]
then
@ -141,19 +132,11 @@ stop() {
pids="`ps aux|grep /usr/sbin/cwmpd|sed 's/^ \+//g'|sed 's/ \+/:/g'|grep -v \" Z \"|grep -v grep|cut -f1 -d:|tr '\n' ' '`"
done
pids="`ps aux|grep /tmp/freecwmp_action.sh|sed 's/^ \+//g'|sed 's/ \+/:/g'|grep -v grep|cut -f1 -d:|tr '\n' ' '`"
while [ "_$pids" != "_" ];do
kill -9 $pids 2> /dev/null
pids="`ps aux|grep /tmp/freecwmp_action.sh|sed 's/^ \+//g'|sed 's/ \+/:/g'|grep -v grep|cut -f1 -d:|tr '\n' ' '`"
done
pids="`ps aux|grep /usr/sbin/freecwmp|sed 's/^ \+//g'|sed 's/ \+/:/g'|grep -v grep|cut -f1 -d:|tr '\n' ' '`"
while [ "_$pids" != "_" ];do
kill -9 $pids 2> /dev/null
pids="`ps aux|grep /usr/sbin/freecwmp|sed 's/^ \+//g'|sed 's/ \+/:/g'|grep -v grep|cut -f1 -d:|tr '\n' ' '`"
done
rm -f /tmp/freecwmp_action.sh
}
restart() {

6
jshn.c
View file

@ -3,10 +3,10 @@
* 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.
* Contributed by Inteno Broadband Technology AB
*
* Copyright (C) 2013 Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Copyright (C) 2013 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2013 Inteno Broadband Technology AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2012 Luka Perkov <freecwmp@lukaperkov.net>
*/

9
log.c
View file

@ -3,10 +3,10 @@
* 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.
* Powered by Inteno Broadband Technology AB
*
* Copyright (C) 2013 Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Copyright (C) 2013 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2013 Inteno Broadband Technology AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
*
*/
@ -108,14 +108,13 @@ void puts_log(int severity, const char *fmt, ...)
gettimeofday(&tv, 0);
t = time((time_t*)NULL);
Tm= localtime(&tv.tv_sec);
i = sprintf(buf,"%02d-%02d-%4d, %02d:%02d:%02d.%03d %s ",
i = sprintf(buf,"%02d-%02d-%4d, %02d:%02d:%02d %s ",
Tm->tm_mday,
Tm->tm_mon+1,
Tm->tm_year+1900,
Tm->tm_hour,
Tm->tm_min,
Tm->tm_sec,
(int)tv.tv_usec%1000,
SEVERITY_NAMES[severity]);
if(strlen(log_file_name) == 0)

View file

@ -3,10 +3,10 @@
* 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.
* Contributed by Inteno Broadband Technology AB
*
* Copyright (C) 2013 Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Copyright (C) 2013 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2013 Inteno Broadband Technology AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2011-2012 Luka Perkov <freecwmp@lukaperkov.net>
*
*/

View file

@ -1,6 +1,8 @@
#!/bin/sh
# Copyright (C) 2011-2012 Luka Perkov <freecwmp@lukaperkov.net>
# Copyright (C) 2012 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
# Copyright (C) 2013 Inteno Broadband Technology AB
# Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
. /lib/functions.sh
. /usr/share/libubox/jshn.sh
@ -10,17 +12,12 @@
# 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 ubus' 'j'
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'
DEFINE_string 'url' '' 'file to download [download only]' 'u'
DEFINE_string 'size' '' 'size of file to download [download only]' 's'
DEFINE_string 'type' '' 'type of file to download [download only]' 't'
DEFINE_string 'user' '' 'username for downloading file [download only]' 'U'
DEFINE_string 'pass' '' 'password for downloading file [download only]' 'P'
FLAGS_HELP=`cat << EOF
USAGE: $0 [flags] command [parameter] [values]
@ -28,11 +25,15 @@ command:
get [value|notification|tags|name|all]
set [value|notification|tag]
apply [value|notification|download]
add [object]
delete [object]
download
factory_reset
reboot
notify
end_session
inform
json_continuous_input
EOF`
FLAGS "$@" || exit 1
@ -90,6 +91,11 @@ case "$1" in
fi
;;
download)
__arg1="$2"
__arg2="$3"
__arg3="$4"
__arg4="$5"
__arg5="$6"
action="download"
;;
factory_reset)
@ -104,28 +110,19 @@ case "$1" in
elif [ "$2" = "value" ]; then
action="apply_value"
elif [ "$2" = "download" ]; then
__arg1="$3"
action="apply_download"
else
action="apply_value"
fi
;;
add)
if [ "$2" = "object" ]; then
action="add_object"
__arg1="$3"
else
action="add_object"
__arg1="$3"
fi
;;
delete)
if [ "$2" = "object" ]; then
action="delete_object"
__arg1="$3"
else
action="delete_object"
__arg1="$3"
fi
;;
inform)
action="inform"
@ -139,6 +136,15 @@ case "$1" in
end_session)
action="end_session"
;;
json_continuous_input)
action="json_continuous_input"
;;
end)
echo "EOF"
;;
exit)
exit 0
;;
esac
if [ -z "$action" ]; then
@ -181,6 +187,8 @@ handle_scripts() {
config_load cwmp
config_foreach handle_scripts "scripts"
# load instance number for TR104
load_voice
# Fault code
@ -205,6 +213,7 @@ FAULT_CPE_DOWNLOAD_FAIL_COMPLETE_DOWNLOAD="17"
FAULT_CPE_DOWNLOAD_FAIL_FILE_CORRUPTED="18"
FAULT_CPE_DOWNLOAD_FAIL_FILE_AUTHENTICATION="19"
handle_action() {
if [ "$action" = "get_value" -o "$action" = "get_all" ]; then
if [ ${FLAGS_force} -eq ${FLAGS_FALSE} ]; then
__tmp_arg="Device."
@ -436,15 +445,15 @@ fi
if [ "$action" = "download" ]; then
local fault_code="9000"
if [ "${FLAGS_user}" = "" -o "${FLAGS_pass}" = "" ];then
wget -O /tmp/freecwmp_download "${FLAGS_url}" > /dev/null
if [ "$__arg4" = "" -o "$__arg5" = "" ];then
wget -O /tmp/freecwmp_download "$__arg1" > /dev/null
if [ "$?" != "0" ];then
let fault_code=$fault_code+$FAULT_CPE_DOWNLOAD_FAILURE
freecwmp_fault_output "" "$fault_code"
exit 1
fi
else
local url="http://${FLAGS_user}:${FLAGS_pass}@`echo ${FLAGS_url}|sed 's/http:\/\///g'`"
local url="http://$__arg4:$__arg5@`echo $__arg1|sed 's/http:\/\///g'`"
wget -O /tmp/freecwmp_download "$url" > /dev/null
if [ "$?" != "0" ];then
let fault_code=$fault_code+$FAULT_CPE_DOWNLOAD_FAILURE
@ -455,12 +464,12 @@ if [ "$action" = "download" ]; then
local flashsize="`freecwmp_check_flash_size`"
local filesize=`ls -l /tmp/freecwmp_download | awk '{ print $5 }'`
if [ $flashsize -gt 0 -a $flashsize -lt ${FLAGS_size} ]; then
if [ $flashsize -gt 0 -a $flashsize -lt $__arg2 ]; then
let fault_code=$fault_code+$FAULT_CPE_DOWNLOAD_FAILURE
rm /tmp/freecwmp_download 2> /dev/null
freecwmp_fault_output "" "$fault_code"
else
if [ "${FLAGS_type}" = "1" ];then
if [ "$__arg3" = "1" ];then
mv /tmp/freecwmp_download /tmp/firmware_upgrade_image 2> /dev/null
freecwmp_check_image
if [ "$?" = "0" ];then
@ -478,10 +487,10 @@ if [ "$action" = "download" ]; then
rm /tmp/firmware_upgrade_image 2> /dev/null
freecwmp_fault_output "" "$fault_code"
fi
elif [ "${FLAGS_type}" = "2" ];then
elif [ "$__arg3" = "2" ];then
mv /tmp/freecwmp_download /tmp/web_content.ipk 2> /dev/null
freecwmp_fault_output "" "$FAULT_CPE_NO_FAULT"
elif [ "${FLAGS_type}" = "3" ];then
elif [ "$__arg3" = "3" ];then
mv /tmp/freecwmp_download /tmp/vendor_configuration_file.cfg 2> /dev/null
freecwmp_fault_output "" "$FAULT_CPE_NO_FAULT"
else
@ -493,7 +502,7 @@ if [ "$action" = "download" ]; then
fi
if [ "$action" = "apply_download" ]; then
case "${FLAGS_type}" in
case "$__arg1" in
1) freecwmp_apply_firmware ;;
2) freecwmp_apply_web_content ;;
3) freecwmp_apply_vendor_configuration ;;
@ -580,6 +589,106 @@ 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" = "json_continuous_input" ]; then
echo "EOF"
while read CMD; do
[ -z "$CMD" ] && continue
result=""
json_init
json_load "$CMD"
json_get_var command command
json_get_var action action
case "$command" in
set)
if [ "$action" = "notification" ]; then
json_get_var __arg1 parameter
json_get_var __arg2 value
json_get_var __arg3 change
action="set_notification"
elif [ "$action" = "value" ]; then
json_get_var __arg1 parameter
json_get_var __arg2 value
action="set_value"
else
json_get_var __arg1 parameter
json_get_var __arg2 value
action="set_value"
fi
;;
get)
if [ "$action" = "notification" ]; then
json_get_var __arg1 parameter
action="get_notification"
elif [ "$action" = "value" ]; then
json_get_var __arg1 parameter
action="get_value"
elif [ "$action" = "name" ]; then
json_get_var __arg1 parameter
json_get_var __arg2 next_level
action="get_name"
else
json_get_var __arg1 parameter
action="get_value"
fi
;;
download)
json_get_var __arg1 url
json_get_var __arg2 size
json_get_var __arg3 type
json_get_var __arg4 user
json_get_var __arg5 pass
action="download"
;;
factory_reset)
action="factory_reset"
;;
reboot)
action="reboot"
;;
apply)
if [ "$action" = "notification" ]; then
action="apply_notification"
elif [ "$action" = "value" ]; then
action="apply_value"
elif [ "$action" = "download" ]; then
json_get_var __arg1 type
action="apply_download"
else
action="apply_value"
fi
;;
add)
json_get_var __arg1 parameter
action="add_object"
;;
delete)
json_get_var __arg1 parameter
action="delete_object"
;;
inform)
action="inform"
;;
end_session)
action="end_session"
;;
end)
echo "EOF"
;;
exit)
exit 0
;;
*)
continue
;;
esac
handle_action
done
exit 0;
fi
}
handle_action
if [ ${FLAGS_debug} -eq ${FLAGS_TRUE} ]; then
echo "[debug] exited at \"`date`\""

View file

@ -1,6 +1,7 @@
#!/bin/sh
# Copyright (C) 2011-2012 Luka Perkov <freecwmp@lukaperkov.net>
# Copyright (C) 2012 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
# Copyright (C) 2013 Inteno Broadband Technology AB
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
# TODO: merge this one somewhere in OpenWrt
uci_remove_list_element() {
@ -293,7 +294,7 @@ freecwmp_config_notifications() {
if [ "$item" = "$3" ]; then
eval "export -- \"$4=0\""
return 0
elif [ "`echo $3|grep $item`" = "$3" ]; then
elif [ "`echo $3|grep $item`" = "$3" -a "`echo $item|grep '\.$'`" != "" ]; then
if [ $length -lt ${#item} ]; then
eval "export -- \"$4=0\""
length="${#item}"
@ -305,7 +306,7 @@ freecwmp_config_notifications() {
if [ "$item" = "$3" ]; then
eval "export -- \"$4=2\""
return 0
elif [ "`echo $3|grep $item`" = "$3" ]; then
elif [ "`echo $3|grep $item`" = "$3" -a "`echo $item|grep '\.$'`" != "" ]; then
if [ $length -lt ${#item} ]; then
eval "export -- \"$4=2\""
length="${#item}"
@ -317,7 +318,7 @@ freecwmp_config_notifications() {
if [ "$item" = "$3" ]; then
eval "export -- \"$4=1\""
return 0
elif [ "`echo $3|grep $item`" = "$3" ]; then
elif [ "`echo $3|grep $item`" = "$3" -a "`echo $item|grep '\.$'`" != "" ]; then
if [ $length -lt ${#item} ]; then
eval "export -- \"$4=1\""
length="${#item}"
@ -385,6 +386,16 @@ freecwmp_notify() {
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"
@ -395,13 +406,24 @@ freecwmp_set_parameter_notification() {
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" ]; then
#/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q add_list cwmp.@notifications[0].disabled="$_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
}
@ -521,6 +543,9 @@ freecwmp_execute_functions()
for function_name in $function_list
do
func=$(echo "$arg1" | cut -d "." -f 2)
func_config=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get -q cwmp.@$func[0].function`
if [ "`echo $function_name|grep \"$func_config\"`" != "" -o "$func" = "" ];then
$function_name "$arg1" "$arg2" "$arg3"
fault_code="$?"
if [ "$fault_code" = "0" ]; then
@ -529,6 +554,7 @@ freecwmp_execute_functions()
if [ "$fault_code" != "0" -a "$fault_code" != "$FAULT_CPE_INVALID_PARAMETER_NAME" ]; then
return $fault_code
fi
fi
done
if [ "$no_fault" = "1" ]; then fault_code="0"; fi
return $fault_code

View file

@ -1,6 +1,7 @@
#!/bin/sh
# Copyright (C) 2012 Luka Perkov <freecwmp@lukaperkov.net>
# Copyright (C) 2012 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
# Copyright (C) 2013 Inteno Broadband Technology AB
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
get_device_hosts_number_of_leases() {
local _static=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} show dhcp 2> /dev/null | fgrep 'dhcp.' | fgrep '.mac=' | wc -l`

View file

@ -1,6 +1,7 @@
#!/bin/sh
# Copyright (C) 2011-2012 Luka Perkov <freecwmp@lukaperkov.net>
# Copyright (C) 2012 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
# Copyright (C) 2013 Inteno Broadband Technology AB
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
get_device_info_manufacturer() {
local val=""
@ -108,6 +109,7 @@ freecwmp_output "InternetGatewayDevice.DeviceInfo.SoftwareVersion" "$val" "$perm
get_device_info_uptime() {
local val=""
local permissions=""
local type="xsd:unsignedInt"
case "$action" in
get_value)
val=`cat /proc/uptime | awk -F "." '{ print $1 }'`
@ -119,7 +121,7 @@ case "$action" in
freecwmp_get_parameter_notification "val" "InternetGatewayDevice.DeviceInfo.UpTime"
;;
esac
freecwmp_output "InternetGatewayDevice.DeviceInfo.UpTime" "$val" "$permissions"
freecwmp_output "InternetGatewayDevice.DeviceInfo.UpTime" "$val" "$permissions" "$type"
}
get_device_info_device_log() {

View file

@ -1,6 +1,7 @@
#!/bin/sh
# Copyright (C) 2012 Luka Perkov <freecwmp@lukaperkov.net>
# Copyright (C) 2012 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
# Copyright (C) 2013 Inteno Broadband Technology AB
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
# TODO: LIMITATIONS: we only handle one device router at the moment

View file

@ -1,6 +1,7 @@
#!/bin/sh
# Copyright (C) 2012 Luka Perkov <freecwmp@lukaperkov.net>
# Copyright (C) 2012 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
# Copyright (C) 2013 Inteno Broadband Technology AB
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
get_device_users() {
local parameter="$1"

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,7 @@
#!/bin/sh
# Copyright (C) 2011-2012 Luka Perkov <freecwmp@lukaperkov.net>
# Copyright (C) 2012 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
# Copyright (C) 2013 Inteno Broadband Technology AB
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
get_management_server_url() {
local tmp=${FLAGS_value}
@ -78,7 +79,8 @@ local permissions=""
local parm="InternetGatewayDevice.ManagementServer.Password"
case "$action" in
get_value)
val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q get cwmp.acs.passwd 2> /dev/null`
# returned value must be empty
val=""
;;
get_name)
permissions="1"
@ -275,7 +277,8 @@ local parm="InternetGatewayDevice.ManagementServer.ConnectionRequestPassword"
local permissions=""
case "$action" in
get_value)
val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q get cwmp.cpe.passwd 2> /dev/null`
# returned value must be empty
val=""
;;
get_name)
permissions="1"

View file

@ -1,6 +1,7 @@
#!/bin/sh
# Copyright (C) 2012 Luka Perkov <freecwmp@lukaperkov.net>
# Copyright (C) 2012 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
# Copyright (C) 2013 Inteno Broadband Technology AB
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
get_misc_cpu_usage() {
local val=`uptime | awk -F'average: ' '{ print $2 }' | awk -F',' '{ print $1 }' | awk -F'.' '{ print $2 }'`

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,7 @@
#!/bin/sh
# Copyright (C) 2011-2012 Luka Perkov <freecwmp@lukaperkov.net>
# Copyright (C) 2012 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
# Copyright (C) 2013 Inteno Broadband Technology AB
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
get_wan_logical_intf() {
local intf="$1"
@ -86,6 +87,41 @@ for intf in $list_interface;do
$populate "$parameter" "InternetGatewayDevice.WANDevice.$dev." "get_wan_device_object_name" "" "$value" "$notification" "$next_level" "$iface"
$populate "$parameter" "InternetGatewayDevice.WANDevice.$dev.WANConnectionDevice." "get_wan_device_object_name" "" "$value" "$notification" "$next_level" "$iface"
$populate "$parameter" "InternetGatewayDevice.WANDevice.$dev.WANConnectionDevice.$wan." "get_wan_device_object_name" "" "$value" "$notification" "$next_level" "$iface"
$populate "$parameter" "InternetGatewayDevice.WANDevice.$dev.WANCommonInterfaceConfig." "get_wan_device_object_ro_name" "" "$value" "$notification" "$next_level" "$iface"
$populate "$parameter" "InternetGatewayDevice.WANDevice.$dev.WANCommonInterfaceConfig.WANAccessType" "get_wan_device_wan_access_type" "" "$value" "$notification" "$next_level" "$iface"
fault_code="$?"
if [ "$fault_code" = "$FAULT_CPE_NO_FAULT" ];then
fault_err=$FAULT_CPE_NO_FAULT
fi
if [ \( "`echo $parameter|grep '\.$'`" = "" -o "$populate" = "get_pop_inform" \) -a "$fault_code" = "$FAULT_CPE_NO_FAULT" ];then
return $fault_code
elif [ "$fault_code" != "$FAULT_CPE_INVALID_PARAMETER_NAME" -a "$fault_code" != "$FAULT_CPE_NO_FAULT" ];then
return $fault_code
fi
$populate "$parameter" "InternetGatewayDevice.WANDevice.$dev.WANDSLInterfaceConfig." "get_wan_device_object_ro_name" "" "$value" "$notification" "$next_level" "$iface"
$populate "$parameter" "InternetGatewayDevice.WANDevice.$dev.WANDSLInterfaceConfig.Status" "get_wan_device_wan_dsl_interface_config_status" "" "$value" "$notification" "$next_level" "$iface"
fault_code="$?"
if [ "$fault_code" = "$FAULT_CPE_NO_FAULT" ];then
fault_err=$FAULT_CPE_NO_FAULT
fi
if [ \( "`echo $parameter|grep '\.$'`" = "" -o "$populate" = "get_pop_inform" \) -a "$fault_code" = "$FAULT_CPE_NO_FAULT" ];then
return $fault_code
elif [ "$fault_code" != "$FAULT_CPE_INVALID_PARAMETER_NAME" -a "$fault_code" != "$FAULT_CPE_NO_FAULT" ];then
return $fault_code
fi
$populate "$parameter" "InternetGatewayDevice.WANDevice.$dev.WANDSLInterfaceConfig.ModulationType" "get_wan_device_wan_dsl_interface_config_modulation_type" "" "$value" "$notification" "$next_level" "$iface"
fault_code="$?"
if [ "$fault_code" = "$FAULT_CPE_NO_FAULT" ];then
fault_err=$FAULT_CPE_NO_FAULT
fi
if [ \( "`echo $parameter|grep '\.$'`" = "" -o "$populate" = "get_pop_inform" \) -a "$fault_code" = "$FAULT_CPE_NO_FAULT" ];then
return $fault_code
elif [ "$fault_code" != "$FAULT_CPE_INVALID_PARAMETER_NAME" -a "$fault_code" != "$FAULT_CPE_NO_FAULT" ];then
return $fault_code
fi
if [ "$proto" = "dhcp" -o "$proto" = "static" ];then
$populate "$parameter" "InternetGatewayDevice.WANDevice.$dev.WANConnectionDevice.$wan.WANIPConnection." "get_wan_device_object_name" "" "$value" "$notification" "$next_level" "$iface"
fault_code="$?"
@ -228,6 +264,109 @@ done
return $fault_err
}
get_wan_device_wan_access_type() {
local val=""
local type="xsd:string"
local parm="$1"
local permissions=""
local intf="$2"
case "$action" in
get_value)
json_load "$(ifstatus $intf)"
json_get_var device device
if [ "${device:0:3}" = "eth" ];then
val="Ethernet"
elif [ "${device:0:3}" = "atm" -o "${device:3:3}" = "ptm" ];then
val="DSL"
fi
;;
get_name)
permissions="0"
;;
get_notification)
freecwmp_get_parameter_notification "val" "$parm"
;;
esac
freecwmp_output "$parm" "$val" "$permissions" "$type"
}
get_wan_device_wan_dsl_interface_config_status() {
local val=""
local type="xsd:string"
local parm="$1"
local permissions=""
local intf="$2"
case "$action" in
get_value)
adsl_shown=`adsl info --stats|grep "^Status:"|cut -f2 -d:|sed 's/\t*//g'|sed 's/^ *//g'|sed 's/ *$//g'`
case "$adsl_shown" in
"Showtime")
val="Up"
;;
"Training")
val="Initializing"
;;
"Channel Analysis")
val="EstablishingLink"
;;
"Disabled")
val="Disabled"
;;
esac
;;
get_name)
permissions="0"
;;
get_notification)
freecwmp_get_parameter_notification "val" "$parm"
;;
esac
freecwmp_output "$parm" "$val" "$permissions" "$type"
}
get_wan_device_wan_dsl_interface_config_modulation_type() {
local val=""
local type="xsd:string"
local parm="$1"
local permissions=""
local intf="$2"
case "$action" in
get_value)
adsl_shown=`adsl info --stats|grep "Mode:"|cut -f2 -d:|sed 's/\t*//g'|sed 's/^ *//g'|cut -f1 -d ' '`
case "$adsl_shown" in
G.Dmt)
val="ADSL_G.dmt"
;;
G.lite)
val="ADSL_G.lite"
;;
T1.413)
val="ADSL_ANSI_T1 .413"
;;
ADSL2)
val="ADSL_G.dmt.bis"
;;
AnnexL)
val="ADSL_re-adsl"
;;
ADSL2+)
val="ADSL_2plus"
;;
*)
val="$adsl_shown"
;;
esac
;;
get_name)
permissions="0"
;;
get_notification)
freecwmp_get_parameter_notification "val" "$parm"
;;
esac
freecwmp_output "$parm" "$val" "$permissions" "$type"
}
get_wan_device_wan_mng_enable() {
local val=""
local type="xsd:boolean"
@ -286,7 +425,7 @@ case "$action" in
fi
if [ $uptime -gt 0 ];then
val="Connected"
elif [ $pending = 1 ];then
elif [ "$pending" = "1" ];then
val="Pending Disconnect"
else
val="Disconnected"
@ -486,7 +625,8 @@ local permissions=""
local intf="$2"
case "$action" in
get_value)
val=`/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q get network.$intf.password 2> /dev/null`
# returned value must be empty
val=""
;;
get_name)
permissions="1"
@ -534,6 +674,11 @@ freecwmp_output "$parm" "" "1"
return $FAULT_CPE_NO_FAULT
}
get_wan_device_object_ro_name() {
local parm="$1"
freecwmp_output "$parm" "" "0"
return $FAULT_CPE_NO_FAULT
}
get_pop_inform() {
local parameter="$1"
local parm="$2"

View file

@ -1,4 +1,6 @@
#!/usr/sbin/bash
# Copyright (C) 2013 Inteno Broadband Technology AB
# Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
usage()
{
echo "Usage: $0 <strength> <passphrase>"

6
ubus.c
View file

@ -3,10 +3,10 @@
* 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.
* Contributed by Inteno Broadband Technology AB
*
* Copyright (C) 2013 Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Copyright (C) 2013 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2013 Inteno Broadband Technology AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2012 Luka Perkov <freecwmp@lukaperkov.net>
*/

97
xml.c
View file

@ -3,10 +3,10 @@
* 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.
* Contributed by Inteno Broadband Technology AB
*
* Copyright (C) 2013 Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Copyright (C) 2013 Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2013 Inteno Broadband Technology AB
* Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
* Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
* Copyright (C) 2011-2012 Luka Perkov <freecwmp@lukaperkov.net>
* Copyright (C) 2012 Jonas Gorski <jonas.gorski@gmail.com>
*/
@ -450,7 +450,7 @@ static int xml_prepare_parameters_inform(struct parameter_container *parameter_c
}
else if (!b && parameter_container->data == NULL)
{
external_get_action_write("value", parameter_container->name, NULL);
external_get_action("value", parameter_container->name, NULL);
return 0;
}
node = mxmlNewElement (parameter_list, "ParameterValueStruct");
@ -506,28 +506,6 @@ int cwmp_rpc_acs_prepare_message_inform (struct cwmp *cwmp, struct session *sess
b = mxmlNewInteger(b, cwmp->retry_count_session);
if (!b) goto error;
remove(fc_script_actions);
for (i=0; i<ARRAYSIZEOF(DEVICE_ID_CONST); i++)
if (external_get_action_write("value",DEVICE_ID_CONST[i].parameter_name, NULL)) return -1;
if (external_get_action_execute(cwmp_handle_getParamValues)) return -1;
while (external_list_parameter.next!=&external_list_parameter) {
parameter_container = list_entry(external_list_parameter.next, 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 = mxmlNewText(b, 0, parameter_container->data? parameter_container->data : "");
if (!b) goto error;
}
}
parameter_container_delete(parameter_container);
}
if (xml_prepare_events_inform(session, tree))
goto error;
@ -551,8 +529,25 @@ int cwmp_rpc_acs_prepare_message_inform (struct cwmp *cwmp, struct session *sess
}
}
external_get_action_execute(cwmp_handle_getParamValues);
external_simple("inform", cwmp_handle_getParamValues);
external_simple("inform");
external_handle_action(cwmp_handle_getParamValues);
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 = mxmlNewText(b, 0, parameter_container->data? parameter_container->data : "");
if (!b) goto error;
}
}
}
while (external_list_parameter.next!=&external_list_parameter) {
@ -760,14 +755,14 @@ int cwmp_handle_rpc_cpe_get_parameter_values(struct session *session, struct rpc
parameter_name = "";
}
if (parameter_name) {
if (external_get_action_write("value",parameter_name, NULL))
if (external_get_action("value", parameter_name, NULL))
goto fault;
}
b = mxmlWalkNext(b, session->body_in, MXML_DESCEND);
parameter_name = NULL;
}
if (external_get_action_execute(cwmp_handle_getParamValues))
goto fault;
external_handle_action(cwmp_handle_getParamValues);
while (external_list_parameter.next!=&external_list_parameter) {
parameter_container = list_entry(external_list_parameter.next, struct parameter_container, list);
@ -874,10 +869,12 @@ 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, cwmp_handle_getParamNames))
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);
@ -974,14 +971,14 @@ int cwmp_handle_rpc_cpe_get_parameter_attributes(struct session *session, struct
parameter_name = "";
}
if (parameter_name) {
if (external_get_action_write("notification",parameter_name, NULL))
if (external_get_action("notification",parameter_name, NULL))
goto fault;
}
b = mxmlWalkNext(b, session->body_in, MXML_DESCEND);
parameter_name = NULL;
}
if (external_get_action_execute(cwmp_handle_getParamAttributes))
goto fault;
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);
@ -1102,8 +1099,7 @@ int cwmp_handle_rpc_cpe_set_parameter_values(struct session *session, struct rpc
}
if (parameter_name && parameter_value) {
if (external_set_action_write("value",
parameter_name, parameter_value,NULL))
if (external_set_action("value", parameter_name, parameter_value, NULL))
goto fault;
parameter_name = NULL;
parameter_value = NULL;
@ -1121,9 +1117,11 @@ int cwmp_handle_rpc_cpe_set_parameter_values(struct session *session, struct rpc
if (b && b->value.text.string)
parameter_key = b->value.text.string;
if (external_set_action_execute("value",cwmp_handle_setParamValues))
if (external_apply("value", NULL))
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);
@ -1220,8 +1218,8 @@ int cwmp_handle_rpc_cpe_set_parameter_attributes(struct session *session, struct
parameter_notification = b->value.text.string;
}
if (attr_notification_update && parameter_name && parameter_notification) {
if (external_set_action_write("notification",
parameter_name, parameter_notification, attr_notification_update))
if (external_set_action("notification", parameter_name,
parameter_notification, attr_notification_update))
goto fault;
attr_notification_update = NULL;
parameter_name = NULL;
@ -1230,9 +1228,11 @@ int cwmp_handle_rpc_cpe_set_parameter_attributes(struct session *session, struct
b = mxmlWalkNext(b, n, MXML_DESCEND);
}
if (external_set_action_execute("notification", cwmp_handle_setParamAttributes))
if (external_apply("notification", NULL))
goto fault;
external_handle_action(cwmp_handle_setParamAttributes);
external_fetch_setParamAttrResp(&success, &fault);
if (fault && fault[0]=='9')
@ -1298,13 +1298,15 @@ int cwmp_handle_rpc_cpe_add_object(struct session *session, struct rpc *rpc)
}
if (object_name) {
if (external_object_action("add", object_name, cwmp_handle_addObject))
if (external_object_action("add", object_name))
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')
@ -1391,13 +1393,15 @@ int cwmp_handle_rpc_cpe_delete_object(struct session *session, struct rpc *rpc)
}
if (object_name) {
if (external_object_action("delete", object_name, cwmp_handle_delObject))
if (external_object_action("delete", object_name))
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')
@ -1798,8 +1802,8 @@ int cwmp_launch_download(struct download *pdownload, struct transfer_complete **
sprintf(file_size,"%d",pdownload->file_size);
external_download(pdownload->url, file_size, pdownload->file_type,
pdownload->username, pdownload->password,
cwmp_handle_downloadFault);
pdownload->username, pdownload->password);
external_handle_action(cwmp_handle_downloadFault);
external_fetch_downloadFaultResp(&fault_code);
if(fault_code != NULL)
@ -1895,7 +1899,8 @@ void *thread_cwmp_rpc_cpe_download (void *v)
else
{
bkp_session_save();
external_apply_download(pdownload->file_type, cwmp_handle_downloadFault);
external_apply("download", pdownload->file_type);
external_handle_action(cwmp_handle_downloadFault);
external_fetch_downloadFaultResp(&fault_code);
if(fault_code != NULL)
{