TR181-XPON  1.4.0
TR-181 PON manager.
pon_ctrl.c
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** SPDX-License-Identifier: BSD-2-Clause-Patent
4 **
5 ** SPDX-FileCopyrightText: Copyright (c) 2022 SoftAtHome
6 **
7 ** Redistribution and use in source and binary forms, with or
8 ** without modification, are permitted provided that the following
9 ** conditions are met:
10 **
11 ** 1. Redistributions of source code must retain the above copyright
12 ** notice, this list of conditions and the following disclaimer.
13 **
14 ** 2. Redistributions in binary form must reproduce the above
15 ** copyright notice, this list of conditions and the following
16 ** disclaimer in the documentation and/or other materials provided
17 ** with the distribution.
18 **
19 ** Subject to the terms and conditions of this license, each
20 ** copyright holder and contributor hereby grants to those receiving
21 ** rights under this license a perpetual, worldwide, non-exclusive,
22 ** no-charge, royalty-free, irrevocable (except for failure to
23 ** satisfy the conditions of this license) patent license to make,
24 ** have made, use, offer to sell, sell, import, and otherwise
25 ** transfer this software, where such license applies only to those
26 ** patent claims, already acquired or hereafter acquired, licensable
27 ** by such copyright holder or contributor that are necessarily
28 ** infringed by:
29 **
30 ** (a) their Contribution(s) (the licensed copyrights of copyright
31 ** holders and non-copyrightable additions of contributors, in
32 ** source or binary form) alone; or
33 **
34 ** (b) combination of their Contribution(s) with the work of
35 ** authorship to which such Contribution(s) was added by such
36 ** copyright holder or contributor, if, at the time the Contribution
37 ** is added, such addition causes such combination to be necessarily
38 ** infringed. The patent license shall not apply to any other
39 ** combinations which include the Contribution.
40 **
41 ** Except as expressly stated above, no rights or licenses from any
42 ** copyright holder or contributor is granted under this license,
43 ** whether expressly, by implication, estoppel or otherwise.
44 **
45 ** DISCLAIMER
46 **
47 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
48 ** CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
49 ** INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
50 ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
51 ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
52 ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
53 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
54 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
55 ** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
56 ** AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
58 ** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
59 ** POSSIBILITY OF SUCH DAMAGE.
60 **
61 ****************************************************************************/
62 
63 /* Related header */
64 #include "pon_ctrl.h"
65 
66 /* Other libraries' headers */
67 #include <amxc/amxc_macros.h>
68 #include <amxc/amxc.h>
69 #include <amxm/amxm.h>
70 
71 /* Own headers */
72 #include "module_mgmt.h" /* mod_get_vendor_module_loaded() */
73 #include "xpon_trace.h"
74 
75 static const char* const MOD_PON_CTRL = "pon_ctrl";
76 
77 static const char* const SET_MAX_NR_OF_ONUS = "set_max_nr_of_onus";
78 static const char* const SET_ENABLE = "set_enable";
79 static const char* const GET_LIST_OF_INSTANCES = "get_list_of_instances";
80 static const char* const GET_OBJECT_CONTENT = "get_object_content";
81 static const char* const GET_PARAM_VALUES = "get_param_values";
82 static const char* const HANDLE_FILE_DESCRIPTOR = "handle_file_descriptor";
83 static const char* const SET_PASSWORD = "set_password";
84 
85 static int call_pon_ctrl_function_common(const char* const func_name,
86  amxc_var_t* args,
87  amxc_var_t* ret) {
88 
89  int rc = -1;
90  amxc_var_t* ret_dummy = NULL;
91 
92  when_null_trace(args, exit, ERROR, "args is NULL");
93 
94  const char* const so_name = mod_get_vendor_module_loaded(); /* shared_object_name */
95  when_null_trace(so_name, exit, ERROR, "No vendor module loaded");
96 
97  if(NULL == ret) {
98  if(amxc_var_new(&ret_dummy)) {
99  SAH_TRACEZ_ERROR(ME, "Failed to allocate memory");
100  goto exit;
101  }
102  }
103 
104  rc = amxm_execute_function(so_name, MOD_PON_CTRL, func_name, args,
105  ret ? ret : ret_dummy);
106  if(rc) {
107  SAH_TRACEZ_ERROR(ME, "%s.%s.%s() failed: rc=%d", so_name, MOD_PON_CTRL,
108  func_name, rc);
109  }
110 
111 exit:
112  if(ret_dummy != NULL) {
113  amxc_var_delete(&ret_dummy);
114  }
115  return rc;
116 }
117 
118 
122 static void set_max_nr_of_onus(void) {
123  amxc_var_t args;
124  amxc_var_init(&args);
125  amxc_var_set(uint32_t, &args, MAX_NR_OF_ONUS);
126 
128  SAH_TRACEZ_ERROR(ME, "Failed to set max nr of ONUs");
129  }
130 
131  amxc_var_clean(&args);
132 }
133 
142 void pon_ctrl_init(void) {
144 }
145 
153 void pon_ctrl_set_enable(const char* const path, bool enable) {
154 
155  amxc_var_t args;
156  amxc_var_init(&args);
157 
158  SAH_TRACEZ_DEBUG(ME, "path='%s' enable=%d", path, enable);
159 
160  amxc_var_set_type(&args, AMXC_VAR_ID_HTABLE);
161 
162  amxc_var_add_key(cstring_t, &args, "path", path);
163  amxc_var_add_key(bool, &args, "enable", enable);
164 
165  if(call_pon_ctrl_function_common(SET_ENABLE, &args, NULL)) {
166  SAH_TRACEZ_ERROR(ME, "path='%s' enable=%d: %s() failed",
167  path, enable, SET_ENABLE);
168  }
169 
170  amxc_var_clean(&args);
171 }
172 
187 int pon_ctrl_get_list_of_instances(const char* const path, amxc_var_t* ret) {
188 
189  amxc_var_t args;
190  amxc_var_init(&args);
191  amxc_var_set(cstring_t, &args, path);
192 
193  const int rc =
195 
196  amxc_var_clean(&args);
197  return rc;
198 }
199 
216 int pon_ctrl_get_object_content(const char* const path, uint32_t index, amxc_var_t* ret) {
217 
218  amxc_var_t args;
219  amxc_var_init(&args);
220 
221  amxc_var_set_type(&args, AMXC_VAR_ID_HTABLE);
222  amxc_var_add_key(cstring_t, &args, "path", path);
223  if(index) {
224  amxc_var_add_key(uint32_t, &args, "index", index);
225  }
226 
227  const int rc = call_pon_ctrl_function_common(GET_OBJECT_CONTENT, &args, ret);
228 
229  amxc_var_clean(&args);
230  return rc;
231 }
232 
248 int pon_ctrl_get_param_values(const char* const path,
249  const char* const names,
250  amxc_var_t* ret) {
251 
252  amxc_var_t args;
253  amxc_var_init(&args);
254 
255  amxc_var_set_type(&args, AMXC_VAR_ID_HTABLE);
256  amxc_var_add_key(cstring_t, &args, "path", path);
257  amxc_var_add_key(cstring_t, &args, "names", names);
258 
259  SAH_TRACEZ_DEBUG(ME, "path='%s' names='%s'", path, names);
260  const int rc = call_pon_ctrl_function_common(GET_PARAM_VALUES, &args, ret);
261 
262  amxc_var_clean(&args);
263  return rc;
264 }
265 
278 
279  amxc_var_t var;
280  amxc_var_init(&var);
281  amxc_var_set(fd_t, &var, fd);
283  amxc_var_clean(&var);
284 }
285 
295 void pon_ctrl_set_password(const char* const ani_path,
296  const char* const password,
297  bool hex) {
298  amxc_var_t args;
299  amxc_var_init(&args);
300 
301  amxc_var_set_type(&args, AMXC_VAR_ID_HTABLE);
302  amxc_var_add_key(cstring_t, &args, "ani_path", ani_path);
303  amxc_var_add_key(cstring_t, &args, "password", password);
304  amxc_var_add_key(bool, &args, "is_hexadecimal_password", hex);
305 
306  SAH_TRACEZ_DEBUG(ME, "ani_path='%s' password='%s' hex=%d", ani_path, password, hex);
308  amxc_var_clean(&args);
309 }
310 
const char * mod_get_vendor_module_loaded(void)
Definition: module_mgmt.c:326
static const char *const GET_LIST_OF_INSTANCES
Definition: pon_ctrl.c:79
static const char *const MOD_PON_CTRL
Definition: pon_ctrl.c:75
static const char *const SET_PASSWORD
Definition: pon_ctrl.c:83
int pon_ctrl_get_param_values(const char *const path, const char *const names, amxc_var_t *ret)
Definition: pon_ctrl.c:248
void pon_ctrl_init(void)
Definition: pon_ctrl.c:142
void pon_ctrl_set_password(const char *const ani_path, const char *const password, bool hex)
Definition: pon_ctrl.c:295
static const char *const GET_PARAM_VALUES
Definition: pon_ctrl.c:81
void pon_ctrl_set_enable(const char *const path, bool enable)
Definition: pon_ctrl.c:153
static int call_pon_ctrl_function_common(const char *const func_name, amxc_var_t *args, amxc_var_t *ret)
Definition: pon_ctrl.c:85
int pon_ctrl_get_object_content(const char *const path, uint32_t index, amxc_var_t *ret)
Definition: pon_ctrl.c:216
int pon_ctrl_get_list_of_instances(const char *const path, amxc_var_t *ret)
Definition: pon_ctrl.c:187
void pon_ctrl_handle_file_descriptor(int fd)
Definition: pon_ctrl.c:277
static const char *const HANDLE_FILE_DESCRIPTOR
Definition: pon_ctrl.c:82
static const char *const GET_OBJECT_CONTENT
Definition: pon_ctrl.c:80
static const char *const SET_MAX_NR_OF_ONUS
Definition: pon_ctrl.c:77
static void set_max_nr_of_onus(void)
Definition: pon_ctrl.c:122
static const char *const SET_ENABLE
Definition: pon_ctrl.c:78
#define SAH_TRACEZ_DEBUG(zone, format,...)
Definition: xpon_trace.h:115
#define ME
Definition: xpon_trace.h:78