TR181-XPON  1.4.0
TR-181 PON manager.
dm_events.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 
78 /* System headers */
79 #include <amxc/amxc.h> /* amxc_var_t */
80 #include <amxc/amxc_macros.h> /* UNUSED */
81 
82 /* Own headers */
83 #include "ani.h" /* ani_strip_tc_authentication() */
84 #include "object_intf_priv.h" /* oipriv_attach_private_data() */
85 #include "password.h" /* passwd_set_password() */
86 #include "persistency.h" /* persistency_enable() */
87 #include "pon_ctrl.h" /* pon_ctrl_set_enable() */
88 #include "restore_to_hal.h" /* rth_disable() */
89 #include "xpon_trace.h"
90 
91 static int isdot(int c) {
92  return (c == '.') ? 1 : 0;
93 }
94 
107 static void onu_or_ani_enable_changed(const amxc_var_t* const event_data, bool onu) {
108 
109  const char* const path = GETP_CHAR(event_data, "path");
110  const bool enable = GETP_BOOL(event_data, "parameters.Enable.to");
111 
112  when_null_trace(path, exit, ERROR, "path is NULL");
113 
114  SAH_TRACEZ_INFO(ME, "path='%s' enable=%d", path, enable);
115 
116  amxc_string_t path_no_dot; /* path with dot at the end trimmed */
117  amxc_string_init(&path_no_dot, 0);
118  amxc_string_set(&path_no_dot, path);
119  amxc_string_trimr(&path_no_dot, isdot);
120 
121  const char* const path_no_dot_cstr = amxc_string_get(&path_no_dot, 0);
122 
128  if(enable && onu) {
129  rth_schedule_enable(path_no_dot_cstr);
130  } else {
131  pon_ctrl_set_enable(path_no_dot_cstr, enable);
132  }
133  persistency_enable(path_no_dot_cstr, enable);
134 
139  if(!enable) {
140  rth_disable(path_no_dot_cstr);
141  }
142 
143  amxc_string_clean(&path_no_dot);
144 
145 exit:
146  return;
147 }
148 
149 
156 void _onu_enable_changed(UNUSED const char* const event_name,
157  const amxc_var_t* const event_data,
158  UNUSED void* const priv) {
159 
160  onu_or_ani_enable_changed(event_data, /*onu=*/ true);
161 }
162 
169 void _ani_enable_changed(UNUSED const char* const event_name,
170  const amxc_var_t* const event_data,
171  UNUSED void* const priv) {
172 
173  onu_or_ani_enable_changed(event_data, /*onu=*/ false);
174 }
175 
184 void _interface_object_added(UNUSED const char* const event_name,
185  const amxc_var_t* const event_data,
186  UNUSED void* const priv) {
187  oipriv_attach_private_data(event_data);
188 }
189 
198 void _status_changed(UNUSED const char* const event_name,
199  const amxc_var_t* const event_data,
200  UNUSED void* const priv) {
201 
202  oipriv_update_last_change(event_data);
203 }
204 
219 void _password_changed(UNUSED const char* const event_name,
220  const amxc_var_t* const event_data,
221  UNUSED void* const priv) {
222 
223  amxc_string_t path_no_dot; /* path with dot at the end trimmed */
224  amxc_string_t ani_instance;
225  amxc_string_init(&path_no_dot, 0);
226  amxc_string_init(&ani_instance, 0);
227 
228  const char* const path = GETP_CHAR(event_data, "path");
229  const char* const password = GETP_CHAR(event_data, "parameters.Password.to");
230 
231  when_null_trace(path, exit, ERROR, "path is NULL");
232  when_null_trace(password, exit, ERROR, "password is NULL");
233 
234  SAH_TRACEZ_DEBUG(ME, "path='%s' password='%s'", path, password);
235 
236  amxc_string_set(&path_no_dot, path);
237  amxc_string_trimr(&path_no_dot, isdot);
238 
239  const char* const path_no_dot_cstr = amxc_string_get(&path_no_dot, 0);
240 
241  if(!ani_strip_tc_authentication(path_no_dot_cstr, &ani_instance)) {
242  SAH_TRACEZ_ERROR(ME, "%s: failed to check password", path_no_dot_cstr);
243  goto exit;
244  }
245 
246  const char* const ani_instance_cstr = amxc_string_get(&ani_instance, 0);
247  passwd_set_password(ani_instance_cstr, password);
248 
249 exit:
250  amxc_string_clean(&path_no_dot);
251  amxc_string_clean(&ani_instance);
252 }
253 
bool ani_strip_tc_authentication(const char *const ani_auth_path, amxc_string_t *const ani_path)
Definition: ani.c:86
void _interface_object_added(UNUSED const char *const event_name, const amxc_var_t *const event_data, UNUSED void *const priv)
Definition: dm_events.c:184
static void onu_or_ani_enable_changed(const amxc_var_t *const event_data, bool onu)
Definition: dm_events.c:107
void _status_changed(UNUSED const char *const event_name, const amxc_var_t *const event_data, UNUSED void *const priv)
Definition: dm_events.c:198
void _password_changed(UNUSED const char *const event_name, const amxc_var_t *const event_data, UNUSED void *const priv)
Definition: dm_events.c:219
static int isdot(int c)
Definition: dm_events.c:91
void _onu_enable_changed(UNUSED const char *const event_name, const amxc_var_t *const event_data, UNUSED void *const priv)
Definition: dm_events.c:156
void _ani_enable_changed(UNUSED const char *const event_name, const amxc_var_t *const event_data, UNUSED void *const priv)
Definition: dm_events.c:169
void oipriv_update_last_change(const amxc_var_t *const data)
void oipriv_attach_private_data(const amxc_var_t *const data)
void passwd_set_password(const char *const ani_auth_path, const char *const password)
Definition: password.c:168
void persistency_enable(const char *const object, bool enable)
Definition: persistency.c:248
void pon_ctrl_set_enable(const char *const path, bool enable)
Definition: pon_ctrl.c:153
void rth_schedule_enable(const char *const object)
void rth_disable(const char *const object)
#define SAH_TRACEZ_DEBUG(zone, format,...)
Definition: xpon_trace.h:115
#define ME
Definition: xpon_trace.h:78