TR181-XPON  1.4.0
TR-181 PON manager.
password.h File Reference
#include <stdbool.h>

Go to the source code of this file.

Functions

bool passwd_check_password (const char *const ani_auth_path, const char *const password)
 
void passwd_set_password (const char *const ani_auth_path, const char *const password)
 
void passwd_restore_password (const char *const ani_path)
 

Detailed Description

Functions related to the PON password.

Definition in file password.h.

Function Documentation

◆ passwd_check_password()

bool passwd_check_password ( const char *const  ani_path,
const char *const  password 
)

Return true if the password is valid, else return false.

Parameters
[in]ani_pathpath to ANI instance, e.g. "XPON.ONU.1.ANI.1"
[in]passwordpossible new value for the parameter Password of the ANI instance referred to by ani_path.

The function looks at other parameters of the ANI referred to by ani_path to determine if the password is valid. E.g. if ani_path is "XPON.ONU.1.ANI.1", it looks at:

  • XPON.ONU.1.ANI.1.PONMode
  • XPON.ONU.1.ANI.1.TC.Authentication.HexadecimalPassword
Returns
true if password is valid, else false

Definition at line 99 of file password.c.

99  {
100 
101  bool rv = false;
102  size_t i;
103 
104  SAH_TRACEZ_DEBUG(ME, "ani_path='%s' password='%s'", ani_path, password);
105 
106  bool is_hex = false;
107  if(!dm_is_hex_password(ani_path, &is_hex)) {
108  SAH_TRACEZ_ERROR(ME, "Failed to determine if password is in hex");
109  goto exit;
110  }
111 
112  const size_t len = strlen(password);
113  if(is_hex) {
114  if((len % 2) != 0) {
115  SAH_TRACEZ_ERROR(ME, "hex password does not have even number of chars");
116  goto exit;
117  }
118  for(i = 0; i < len; i++) {
119  if(!isxdigit(password[i])) {
120  SAH_TRACEZ_ERROR(ME, "hex password has non-hexadecimal digit");
121  goto exit;
122  }
123  }
124  }
125 
126  pon_mode_t pon_mode = pon_mode_unknown;
127  if(!dm_get_ani_pon_mode(ani_path, &pon_mode)) {
128  SAH_TRACEZ_ERROR(ME, "Failed to get PON mode");
129  goto exit;
130  }
131  when_true_trace(pon_mode_unknown == pon_mode, exit, ERROR,
132  "Unknown PON mode");
133 
134  size_t maxlen =
135  (pon_mode_gpon == pon_mode) ?
137 
138  if(is_hex) {
139  maxlen *= 2; /* hex value is twice the size of an ASCII value */
140  if(len != maxlen) {
141  SAH_TRACEZ_ERROR(ME, "Length of password = %zd != %zd [mode='%s', hex=1]",
142  len, maxlen, pon_mode_to_string(pon_mode));
143  goto exit;
144  }
145  } else if(len > maxlen) {
146  SAH_TRACEZ_ERROR(ME, "Length of password = %zd > %zd [mode='%s', hex=0]",
147  len, maxlen, pon_mode_to_string(pon_mode));
148  goto exit;
149  }
150 
151  rv = true;
152 
153 exit:
154  return rv;
155 }
bool dm_is_hex_password(const char *const ani_path, bool *is_hex)
Definition: data_model.c:1236
bool dm_get_ani_pon_mode(const char *const ani_path, pon_mode_t *pon_mode)
Definition: data_model.c:1280
#define MAX_XPON_PASSWORD_LEN
#define MAX_GPON_PASSWORD_LEN
enum _pon_mode pon_mode_t
const char * pon_mode_to_string(pon_mode_t mode)
Definition: pon_mode.c:70
@ pon_mode_unknown
Definition: pon_mode.h:67
@ pon_mode_gpon
Definition: pon_mode.h:68
#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:
Here is the caller graph for this function:

◆ passwd_restore_password()

void passwd_restore_password ( const char *const  ani_path)

Restore the PON password for an ANI: in DM and towards vendor module.

Parameters
[in]ani_pathpath to ANI instance, e.g. "XPON.ONU.1.ANI.1"

Check if there is a saved PON password for the ANI. If there is, update its Password parameter (and its HexadecimalPassword parameter) in the DM. The update in the DM causes the Ambiorix framework to call the same functions as when another component or user updates the Password parameter: _check_password() and _password_changed(). The latter function call among others forwards the password to the vendor module.

Definition at line 237 of file password.c.

237  {
238 
239  SAH_TRACEZ_DEBUG(ME, "ani_path='%s'", ani_path);
240  char password[MAX_PASSWORD_LEN_PLUS_ONE] = { 0 };
241  bool hex = false;
242  if(!upgr_persistency_get_password(ani_path, password, &hex)) {
243  SAH_TRACEZ_ERROR(ME, "ani='%s': failed to get password", ani_path);
244  goto exit;
245  }
246  when_true(strlen(password) == 0, exit); /* nothing to do */
247 
248  update_password_in_dm(ani_path, password, hex);
249 
250 exit:
251  return;
252 }
static void update_password_in_dm(const char *const ani_path, const char *const password, bool hex)
Definition: password.c:189
#define MAX_PASSWORD_LEN_PLUS_ONE
bool upgr_persistency_get_password(const char *const ani_path, char *const password, bool *hex)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ passwd_set_password()

void passwd_set_password ( const char *const  ani_path,
const char *const  password 
)

Set the password of an ANI instance.

Parameters
[in]ani_pathpath to ANI instance, e.g. "XPON.ONU.1.ANI.1"
[in]passwordnew value for the parameter Password of the ANI referred to by ani_path

The function forwards the value to:

  • the vendor module
  • the part of this plugin responsible for the upgrade persistent settings

Definition at line 168 of file password.c.

169  {
170 
171  SAH_TRACEZ_DEBUG(ME, "ani_path='%s' password='%s'", ani_path, password);
172 
173  bool is_hex = false;
174  if(strlen(password) != 0) {
175  if(!dm_is_hex_password(ani_path, &is_hex)) {
176  SAH_TRACEZ_ERROR(ME, "%s: failed to determine if password is in "
177  "hex", ani_path);
178  goto exit;
179  }
180  }
181 
182  upgr_persistency_set_password(ani_path, password, is_hex);
183  pon_ctrl_set_password(ani_path, password, is_hex);
184 
185 exit:
186  return;
187 }
void pon_ctrl_set_password(const char *const ani_path, const char *const password, bool hex)
Definition: pon_ctrl.c:295
void upgr_persistency_set_password(const char *const ani_path, const char *const password, bool hex)
Here is the call graph for this function:
Here is the caller graph for this function: