TR181-XPON  1.4.0
TR-181 PON manager.
dm_actions.c File Reference
#include "dm_actions.h"
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <amxc/amxc_macros.h>
#include <amxc/amxc.h>
#include <amxp/amxp.h>
#include <amxd/amxd_action.h>
#include <amxd/amxd_object.h>
#include "ani.h"
#include "object_intf_priv.h"
#include "onu_priv.h"
#include "password.h"
#include "pon_ctrl.h"
#include "utils_time.h"
#include "xpon_trace.h"

Go to the source code of this file.

Typedefs

typedef enum _private_data_type private_data_type_t
 

Enumerations

enum  _private_data_type { private_data_for_onu = 0 , private_data_for_object_interface }
 

Functions

void dm_actions_set_ignore_param_reads (bool ignore)
 
static bool process_param_value (const char *const param_name, const amxc_var_t *const ret, amxc_var_t *const retval)
 
amxd_status_t _read_trx_param (amxd_object_t *object, amxd_param_t *param, amxd_action_t reason, const amxc_var_t *const args, amxc_var_t *const retval, void *priv)
 
amxd_status_t _lastchange_on_read (amxd_object_t *const object, UNUSED amxd_param_t *const param, amxd_action_t reason, UNUSED const amxc_var_t *const args, amxc_var_t *const retval, UNUSED void *priv_unused)
 
amxd_status_t object_destroyed_common (amxd_object_t *object, amxd_action_t reason, private_data_type_t private_data_type)
 
amxd_status_t _onu_destroyed (amxd_object_t *object, UNUSED amxd_param_t *param, amxd_action_t reason, UNUSED const amxc_var_t *const args, UNUSED amxc_var_t *const retval, UNUSED void *priv_unused)
 
amxd_status_t _interface_object_destroyed (amxd_object_t *object, UNUSED amxd_param_t *param, amxd_action_t reason, UNUSED const amxc_var_t *const args, UNUSED amxc_var_t *const retval, UNUSED void *priv_unused)
 
amxd_status_t _check_password (amxd_object_t *object, UNUSED amxd_param_t *param, amxd_action_t reason, const amxc_var_t *const args, UNUSED amxc_var_t *const retval, UNUSED void *priv)
 

Variables

static bool s_ignore_param_reads = false
 

Typedef Documentation

◆ private_data_type_t

Enumeration Type Documentation

◆ _private_data_type

Enumerator
private_data_for_onu 
private_data_for_object_interface 

Definition at line 285 of file dm_actions.c.

285  {
enum _private_data_type private_data_type_t
@ private_data_for_object_interface
Definition: dm_actions.c:287
@ private_data_for_onu
Definition: dm_actions.c:286

Function Documentation

◆ _check_password()

amxd_status_t _check_password ( amxd_object_t *  object,
UNUSED amxd_param_t *  param,
amxd_action_t  reason,
const amxc_var_t *const  args,
UNUSED amxc_var_t *const  retval,
UNUSED void *  priv 
)

Called if Password parameter of an ANI instance is changed.

Parameters
[in]objectthe TC.Authentication object of an ANI instance whose Password parameter is changed
[in]reasonthis must be 'action_param_validate'
[in]argsvariant with cstring_t value for the Password
Returns
amxd_status_ok (=0) upon success, another value in case of an error

Definition at line 394 of file dm_actions.c.

399  {
400  amxd_status_t status = amxd_status_unknown_error;
401  const char* password = NULL;
402  char* path = NULL;
403  amxc_string_t ani_path;
404  amxc_string_init(&ani_path, 0);
405 
406  when_null_status(object, exit, status = amxd_status_invalid_function_argument);
407  when_null_status(args, exit, status = amxd_status_invalid_function_argument);
408 
409  when_true_status(reason != action_param_validate, exit,
410  status = amxd_status_function_not_implemented);
411 
412  password = amxc_var_constcast(cstring_t, args);
413  when_null_trace(password, exit, ERROR, "password is NULL");
414 
415  if(strlen(password) != 0) {
416 
417  path = amxd_object_get_path(object, AMXD_OBJECT_INDEXED);
418  when_null_trace(path, exit, ERROR, "path is NULL");
419  if(!ani_strip_tc_authentication(path, &ani_path)) {
420  SAH_TRACEZ_ERROR(ME, "%s: failed to check password", path);
421  goto exit;
422  }
423 
424  SAH_TRACEZ_DEBUG(ME, "path='%s' password='%s'", path, password);
425 
426  const char* const ani_path_cstr = amxc_string_get(&ani_path, 0);
427  if(!passwd_check_password(ani_path_cstr, password)) {
428  status = amxd_status_invalid_value;
429  goto exit;
430  }
431  }
432 
433  status = amxd_status_ok;
434 
435 exit:
436  if(path) {
437  free(path);
438  }
439  amxc_string_clean(&ani_path);
440  return status;
441 }
bool ani_strip_tc_authentication(const char *const ani_auth_path, amxc_string_t *const ani_path)
Definition: ani.c:86
bool passwd_check_password(const char *const ani_auth_path, const char *const password)
Definition: password.c:99
#define SAH_TRACEZ_DEBUG(zone, format,...)
Definition: xpon_trace.h:115
#define ME
Definition: xpon_trace.h:78
Here is the call graph for this function:

◆ _interface_object_destroyed()

amxd_status_t _interface_object_destroyed ( amxd_object_t *  object,
UNUSED amxd_param_t *  param,
amxd_action_t  reason,
UNUSED const amxc_var_t *const  args,
UNUSED amxc_var_t *const  retval,
UNUSED void *  priv_unused 
)

Called if an instance of an object interface is destroyed.

Parameters
[in]objectthe object/instance being destroyed
[in]reasonthis must be 'action_object_destroy'

The function deletes the private data attached to the instance.

Returns
amxd_status_ok (=0) upon success, another value in case of an error

Definition at line 372 of file dm_actions.c.

377  {
378 
379  return object_destroyed_common(object, reason,
381 }
amxd_status_t object_destroyed_common(amxd_object_t *object, amxd_action_t reason, private_data_type_t private_data_type)
Definition: dm_actions.c:302
Here is the call graph for this function:

◆ _lastchange_on_read()

amxd_status_t _lastchange_on_read ( amxd_object_t *const  object,
UNUSED amxd_param_t *const  param,
amxd_action_t  reason,
UNUSED const amxc_var_t *const  args,
amxc_var_t *const  retval,
UNUSED void *  priv_unused 
)

Called if a LastChange parameter is read.

Parameters
[in]objectobject whose LastChange parameter is read
[in]actionthis must be 'action_param_read'
[in,out]retvalthe function returns the value for the LastChange parameter via this 'retval' parameter
Returns
amxd_status_ok (=0) upon success, another value in case of an error

This function is called when the object with the LastChange parameter is is being created. Then 'object->priv' is still NULL. Therefore do not log an error if 'object->priv' is NULL.

Definition at line 241 of file dm_actions.c.

246  {
247  amxd_status_t rv = amxd_status_unknown_error;
248  object_intf_priv_t* priv = NULL;
249  uint32_t since_change = 0;
250  uint32_t uptime = 0;
251  char* path = NULL;
252 
253  if(reason != action_param_read) {
254  SAH_TRACEZ_WARNING(ME, "wrong reason, expected action_param_read(%d) got %d",
255  action_param_read, reason);
256  rv = amxd_status_invalid_action;
257  goto exit;
258  }
259 
260  when_null_trace(object, skip, ERROR, "object can not be NULL");
261  path = amxd_object_get_path(object, AMXD_OBJECT_INDEXED);
267  when_null_trace(object->priv, skip, DEBUG, "object %s has no private data", path);
268  priv = (object_intf_priv_t*) object->priv;
269  uptime = time_get_system_uptime();
270  when_true_trace(uptime < priv->last_change, skip, ERROR,
271  "uptime is smaller than LastChange");
272  since_change = uptime - priv->last_change;
273  rv = amxd_status_ok;
274 
275 skip:
276  when_failed_trace(amxc_var_set_uint32_t(retval, since_change),
277  exit, ERROR, "Failed to set parameter LastChange");
278 exit:
279  if(path) {
280  free(path);
281  }
282  return rv;
283 }
uint32_t time_get_system_uptime(void)
Definition: utils_time.c:75
Here is the call graph for this function:

◆ _onu_destroyed()

amxd_status_t _onu_destroyed ( amxd_object_t *  object,
UNUSED amxd_param_t *  param,
amxd_action_t  reason,
UNUSED const amxc_var_t *const  args,
UNUSED amxc_var_t *const  retval,
UNUSED void *  priv_unused 
)

Called if an ONU instance is destroyed.

Parameters
[in]objectthe object/instance being destroyed
[in]reasonthis must be 'action_object_destroy'

The function deletes the private data attached to the instance.

Returns
amxd_status_ok (=0) upon success, another value in case of an error

Definition at line 351 of file dm_actions.c.

356  {
357 
358  return object_destroyed_common(object, reason, private_data_for_onu);
359 }
Here is the call graph for this function:

◆ _read_trx_param()

amxd_status_t _read_trx_param ( amxd_object_t *  object,
amxd_param_t *  param,
amxd_action_t  reason,
const amxc_var_t *const  args,
amxc_var_t *const  retval,
void *  priv 
)

Read a parameter value.

The Ambiorix framework calls this function every time a parameter is read which has this function as custom read handler.

The function has 'trx' in its name because for now it's only used to query the values of the volatile params of an XPON.ONU.{i}.ANI.1.Transceiver.{i} instance. But the function is generic in the sense that it can be used for other parameters (of other objects) in the future.

Go to 'exit' if function is called for a template object.

It does not make sense to read the param values of a template object. Only read them for a singleton or an instance.

See also: ST-826 - [amx] custom param read handler called more often than expected

Definition at line 162 of file dm_actions.c.

167  {
168 
169  amxd_status_t rv = amxd_status_unknown_error;
170 
171  SAH_TRACEZ_DEBUG2(ME, "called");
172 
173  when_null_status(object, exit, rv = amxd_status_invalid_function_argument);
174  when_null_status(param, exit, rv = amxd_status_invalid_function_argument);
175  when_null_status(retval, exit, rv = amxd_status_invalid_function_argument);
176 
177  rv = amxd_action_param_read(object, param, reason, args, retval, priv);
178 
179  when_failed_trace(rv, exit, ERROR, "amxd_action_param_read() failed");
180 
181  when_true(s_ignore_param_reads, exit);
182 
192  const amxd_object_type_t type = amxd_object_get_type(object);
193  when_true(amxd_object_template == type, exit);
194 
195  const char* const param_name = amxd_param_get_name(param);
196  when_null_trace(param_name, exit, ERROR, "param_name is NULL");
197 
198  char* path = amxd_object_get_path(object, AMXD_OBJECT_INDEXED);
199  when_null_trace(path, exit, ERROR, "path is NULL");
200 
201  SAH_TRACEZ_DEBUG(ME, "path=%s param=%s", path, param_name);
202 
203  amxc_var_t ret;
204  amxc_var_init(&ret);
205 
206  if(pon_ctrl_get_param_values(path, param_name, &ret) != 0) {
207  SAH_TRACEZ_ERROR(ME, "Failed to query %s.%s", path, param_name);
208  goto exit_cleanup;
209  }
210 
211 #ifdef _DEBUG_
212  printf("tr181-xpon: read_trx_param():\n");
213  amxc_var_dump(&ret, STDOUT_FILENO);
214 #endif
215 
216  /* Extract the parameter value from 'ret' and assign it to 'retval'. */
217  if(!process_param_value(param_name, &ret, retval)) {
218  goto exit_cleanup;
219  }
220 
221  rv = 0;
222 
223 exit_cleanup:
224  free(path);
225  amxc_var_clean(&ret);
226 
227 exit:
228  return rv;
229 }
static bool process_param_value(const char *const param_name, const amxc_var_t *const ret, amxc_var_t *const retval)
Definition: dm_actions.c:128
static bool s_ignore_param_reads
Definition: dm_actions.c:117
int pon_ctrl_get_param_values(const char *const path, const char *const names, amxc_var_t *ret)
Definition: pon_ctrl.c:248
#define SAH_TRACEZ_DEBUG2(zone, format,...)
Definition: xpon_trace.h:127
Here is the call graph for this function:

◆ dm_actions_set_ignore_param_reads()

void dm_actions_set_ignore_param_reads ( bool  ignore)

Set 's_ignore_param_reads' to ignore.

See doc in front of s_ignore_param_reads.

Definition at line 124 of file dm_actions.c.

124  {
125  s_ignore_param_reads = ignore;
126 }
Here is the caller graph for this function:

◆ object_destroyed_common()

amxd_status_t object_destroyed_common ( amxd_object_t *  object,
amxd_action_t  reason,
private_data_type_t  private_data_type 
)

Helper function called when certain instances are deleted.

Parameters
[in]objectthe object/instance being destroyed
[in]reasonthis must be 'action_object_destroy'
[in]private_data_typetype of the private data to be destroyed

The function deletes the private data attached to the instance.

Returns
amxd_status_ok (=0) upon success, another value in case of an error

Definition at line 302 of file dm_actions.c.

304  {
305 
306  amxd_status_t rv = amxd_status_unknown_error;
307  char* path = NULL;
308 
309  if(reason != action_object_destroy) {
310  SAH_TRACEZ_WARNING(ME, "Wrong reason, expected action_object_destroy(%d) got %d",
311  action_object_destroy, reason);
312  rv = amxd_status_invalid_action;
313  goto exit;
314  }
315 
316  when_null_trace(object, exit, ERROR, "object is NULL");
317  path = amxd_object_get_path(object, AMXD_OBJECT_INDEXED);
318  when_null_trace(object->priv, exit, WARNING,
319  "object %s has no private data", path);
320  SAH_TRACEZ_DEBUG(ME, "Delete private data of %s", path);
321  switch(private_data_type) {
323  onu_priv_delete_private_data((onu_priv_t*) object->priv);
324  break;
327  break;
328  default:
329  break;
330  }
331  object->priv = NULL;
332  rv = amxd_status_ok;
333 
334 exit:
335  if(path) {
336  free(path);
337  }
338  return rv;
339 }
void oipriv_delete_private_data(object_intf_priv_t *priv)
void onu_priv_delete_private_data(onu_priv_t *priv)
Definition: onu_priv.c:89
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_param_value()

static bool process_param_value ( const char *const  param_name,
const amxc_var_t *const  ret,
amxc_var_t *const  retval 
)
static

Definition at line 128 of file dm_actions.c.

130  {
131  bool rv = false;
132 
133  const amxc_var_t* const params =
134  amxc_var_get_key(ret, "parameters", AMXC_VAR_FLAG_DEFAULT);
135  when_null_trace(params, exit, ERROR, "Failed to extract 'parameters'");
136 
137  const amxc_var_t* const param_value =
138  amxc_var_get_key(params, param_name, AMXC_VAR_FLAG_DEFAULT);
139  when_null_trace(param_value, exit, ERROR, "Failed to get value for '%s'", param_name);
140 
141  const int rc = amxc_var_copy(retval, param_value);
142  when_failed_trace(rc, exit, ERROR, "Failed to copy value for '%s'", param_name);
143 
144  rv = true;
145 
146 exit:
147  return rv;
148 }
Here is the caller graph for this function:

Variable Documentation

◆ s_ignore_param_reads

bool s_ignore_param_reads = false
static

Do not ask vendor module for param value if this setting is true.

When deleting a Transceiver instance, the custom read handler _read_trx_param() is called many times for the parameters RxPower, TxPower, etc. This seems not ok. It does not make sense to query the parameters of an instance being deleted. See:

ST-826 - [amx] custom param read handler called more often than expected

If the vendor module calls dm_remove_instance() to delete a Transceiver instance, the plugin querying the parameter values in the vendor module when deleting the instance causes errors: the vendor module already considers the Transceiver instance deleted.

To avoid those errors, the plugin sets s_ignore_param_reads to true just before deleting an instance, and sets it back to false immediately afterwards. The plugin still calls the custom read handler while deleting a Transceiver instance, but the handler will not query the value in the vendor module.

The plugin sets s_ignore_param_reads to true for each instance it deletes, not only for Transceiver instances. This makes the code more future proof. We might reuse _read_trx_param() in the future for the volatile parameters of other template objects.

Definition at line 117 of file dm_actions.c.