Wed Jan 8 2020 09:50:13

Asterisk developer's documentation


iax2-provision.h File Reference

IAX2 Provisioning protocol. More...

#include "iax2-parser.h"

Go to the source code of this file.

Macros

#define PROV_FLAG_DEBUG   (1 << 3)
 
#define PROV_FLAG_DIS_CALLERID   (1 << 4) /* Caller-ID Disabled */
 
#define PROV_FLAG_DIS_CALLWAIT   (1 << 5) /* Caller-ID / Call Waiting Disable */
 
#define PROV_FLAG_DIS_CIDCW   (1 << 6) /* CID/CW Disabled */
 
#define PROV_FLAG_DIS_THREEWAY   (1 << 7) /* Three-way calling, transfer disabled */
 
#define PROV_FLAG_HEARTBEAT   (1 << 2)
 
#define PROV_FLAG_REGISTER   (1 << 0)
 
#define PROV_FLAG_SECURE   (1 << 1)
 
#define PROV_IE_AESKEY   14 /* 128-bits */
 
#define PROV_IE_ALTSERVER   19 /* 32-bits */
 
#define PROV_IE_FLAGS   12 /* 32-bits */
 
#define PROV_IE_FORMAT   13 /* 32-bits */
 
#define PROV_IE_GATEWAY   4 /* 32-bit */
 
#define PROV_IE_IPADDR   2 /* 32-bit */
 
#define PROV_IE_LANG   10 /* < 10 bytes */
 
#define PROV_IE_NEWAESKEY   17 /* 128-bits */
 
#define PROV_IE_PASS   7 /* < 20 bytes */
 
#define PROV_IE_PORTNO   5 /* 16-bit */
 
#define PROV_IE_PROVVER   18 /* 32-bits */
 
#define PROV_IE_SERVERIP   15 /* 32-bits */
 
#define PROV_IE_SERVERPASS   9 /* < 20 bytes */
 
#define PROV_IE_SERVERPORT   16 /* 16-bits */
 
#define PROV_IE_SERVERUSER   8 /* < 20 bytes */
 
#define PROV_IE_SUBNET   3 /* 32-bit */
 
#define PROV_IE_TOS   11 /* 8-bits */
 
#define PROV_IE_USEDHCP   1 /* Presense only */
 
#define PROV_IE_USER   6 /* < 20 bytes */
 

Functions

char * iax_prov_complete_template (const char *line, const char *word, int pos, int state)
 
char * iax_provflags2str (char *buf, int buflen, unsigned int flags)
 
int iax_provision_build (struct iax_ie_data *provdata, unsigned int *signature, const char *template, int force)
 
int iax_provision_reload (int reload)
 
int iax_provision_unload (void)
 
int iax_provision_version (unsigned int *signature, const char *template, int force)
 

Detailed Description

IAX2 Provisioning protocol.

Definition in file iax2-provision.h.

Macro Definition Documentation

#define PROV_FLAG_DEBUG   (1 << 3)

Definition at line 41 of file iax2-provision.h.

#define PROV_FLAG_DIS_CALLERID   (1 << 4) /* Caller-ID Disabled */

Definition at line 43 of file iax2-provision.h.

#define PROV_FLAG_DIS_CALLWAIT   (1 << 5) /* Caller-ID / Call Waiting Disable */

Definition at line 44 of file iax2-provision.h.

#define PROV_FLAG_DIS_CIDCW   (1 << 6) /* CID/CW Disabled */

Definition at line 45 of file iax2-provision.h.

#define PROV_FLAG_DIS_THREEWAY   (1 << 7) /* Three-way calling, transfer disabled */

Definition at line 46 of file iax2-provision.h.

#define PROV_FLAG_HEARTBEAT   (1 << 2)

Definition at line 40 of file iax2-provision.h.

#define PROV_FLAG_REGISTER   (1 << 0)

Definition at line 38 of file iax2-provision.h.

#define PROV_FLAG_SECURE   (1 << 1)

Definition at line 39 of file iax2-provision.h.

#define PROV_IE_AESKEY   14 /* 128-bits */

Definition at line 31 of file iax2-provision.h.

#define PROV_IE_ALTSERVER   19 /* 32-bits */

Definition at line 36 of file iax2-provision.h.

Referenced by iax_provision_build().

#define PROV_IE_FLAGS   12 /* 32-bits */

Definition at line 29 of file iax2-provision.h.

Referenced by iax_provision_build().

#define PROV_IE_FORMAT   13 /* 32-bits */

Definition at line 30 of file iax2-provision.h.

Referenced by iax_provision_build().

#define PROV_IE_GATEWAY   4 /* 32-bit */

Definition at line 21 of file iax2-provision.h.

#define PROV_IE_IPADDR   2 /* 32-bit */

Definition at line 19 of file iax2-provision.h.

#define PROV_IE_LANG   10 /* < 10 bytes */

Definition at line 27 of file iax2-provision.h.

Referenced by iax_provision_build().

#define PROV_IE_NEWAESKEY   17 /* 128-bits */

Definition at line 34 of file iax2-provision.h.

#define PROV_IE_PASS   7 /* < 20 bytes */

Definition at line 24 of file iax2-provision.h.

Referenced by iax_provision_build().

#define PROV_IE_PORTNO   5 /* 16-bit */

Definition at line 22 of file iax2-provision.h.

Referenced by iax_provision_build().

#define PROV_IE_PROVVER   18 /* 32-bits */

Definition at line 35 of file iax2-provision.h.

Referenced by iax_provision_build().

#define PROV_IE_SERVERIP   15 /* 32-bits */

Definition at line 32 of file iax2-provision.h.

Referenced by iax_provision_build().

#define PROV_IE_SERVERPASS   9 /* < 20 bytes */

Definition at line 26 of file iax2-provision.h.

#define PROV_IE_SERVERPORT   16 /* 16-bits */

Definition at line 33 of file iax2-provision.h.

Referenced by iax_provision_build().

#define PROV_IE_SERVERUSER   8 /* < 20 bytes */

Definition at line 25 of file iax2-provision.h.

#define PROV_IE_SUBNET   3 /* 32-bit */

Definition at line 20 of file iax2-provision.h.

#define PROV_IE_TOS   11 /* 8-bits */

Definition at line 28 of file iax2-provision.h.

Referenced by iax_provision_build().

#define PROV_IE_USEDHCP   1 /* Presense only */

Definition at line 18 of file iax2-provision.h.

#define PROV_IE_USER   6 /* < 20 bytes */

Definition at line 23 of file iax2-provision.h.

Referenced by iax_provision_build().

Function Documentation

char* iax_prov_complete_template ( const char *  line,
const char *  word,
int  pos,
int  state 
)

Definition at line 178 of file iax2-provision.c.

References AST_LIST_TRAVERSE, ast_mutex_lock, ast_mutex_unlock, ast_strdup, iax_template::list, iax_template::name, and provlock.

Referenced by handle_cli_iax2_provision(), and iax_show_provisioning().

179 {
180  struct iax_template *c;
181  int which=0;
182  char *ret = NULL;
183  int wordlen = strlen(word);
184 
185  if (pos == 3) {
188  if (!strncasecmp(word, c->name, wordlen) && ++which > state) {
189  ret = ast_strdup(c->name);
190  break;
191  }
192  }
194  }
195  return ret;
196 }
static ast_mutex_t provlock
#define ast_strdup(a)
Definition: astmm.h:109
char name[80]
#define ast_mutex_lock(a)
Definition: lock.h:155
Definition: ael.tab.c:203
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
struct iax_template::@117 list
#define ast_mutex_unlock(a)
Definition: lock.h:156
char* iax_provflags2str ( char *  buf,
int  buflen,
unsigned int  flags 
)

Definition at line 89 of file iax2-provision.c.

References ARRAY_LEN, ast_strlen_zero(), iax_flags, iax_template::name, and value.

Referenced by dump_prov_flags(), and iax_show_provisioning().

90 {
91  int x;
92 
93  if (!buf || buflen < 1)
94  return NULL;
95 
96  buf[0] = '\0';
97 
98  for (x = 0; x < ARRAY_LEN(iax_flags); x++) {
99  if (flags & iax_flags[x].value){
100  strncat(buf, iax_flags[x].name, buflen - strlen(buf) - 1);
101  strncat(buf, ",", buflen - strlen(buf) - 1);
102  }
103  }
104 
105  if (!ast_strlen_zero(buf))
106  buf[strlen(buf) - 1] = '\0';
107  else
108  strncpy(buf, "none", buflen - 1);
109 
110  return buf;
111 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int value
Definition: syslog.c:39
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
unsigned int flags
static const char name[]
static struct iax_flag iax_flags[]
int iax_provision_build ( struct iax_ie_data provdata,
unsigned int *  signature,
const char *  template,
int  force 
)

Definition at line 208 of file iax2-provision.c.

References iax_template::altserver, ast_db_put(), ast_mutex_lock, ast_mutex_unlock, iax_template::flags, iax_template::format, iax_ie_append_byte(), iax_ie_append_int(), iax_ie_append_short(), iax_ie_append_str(), iax_template_find(), iax_template::lang, iax_template::pass, iax_template::port, PROV_IE_ALTSERVER, PROV_IE_FLAGS, PROV_IE_FORMAT, PROV_IE_LANG, PROV_IE_PASS, PROV_IE_PORTNO, PROV_IE_PROVVER, PROV_IE_SERVERIP, PROV_IE_SERVERPORT, PROV_IE_TOS, PROV_IE_USER, prov_ver_calc(), provlock, iax_template::server, iax_template::serverport, iax_template::tos, and iax_template::user.

Referenced by iax2_provision(), and iax_provision_version().

209 {
210  struct iax_template *cur;
211  unsigned int sig;
212  char tmp[40];
213  memset(provdata, 0, sizeof(*provdata));
215  cur = iax_template_find(template, 1);
216  /* If no match, try searching for '*' */
217  if (!cur)
218  cur = iax_template_find("*", 1);
219  if (cur) {
220  /* found it -- add information elements as appropriate */
221  if (force || strlen(cur->user))
222  iax_ie_append_str(provdata, PROV_IE_USER, cur->user);
223  if (force || strlen(cur->pass))
224  iax_ie_append_str(provdata, PROV_IE_PASS, cur->pass);
225  if (force || strlen(cur->lang))
226  iax_ie_append_str(provdata, PROV_IE_LANG, cur->lang);
227  if (force || cur->port)
228  iax_ie_append_short(provdata, PROV_IE_PORTNO, cur->port);
229  if (force || cur->server)
230  iax_ie_append_int(provdata, PROV_IE_SERVERIP, cur->server);
231  if (force || cur->serverport)
233  if (force || cur->altserver)
235  if (force || cur->flags)
236  iax_ie_append_int(provdata, PROV_IE_FLAGS, cur->flags);
237  if (force || cur->format)
238  iax_ie_append_int(provdata, PROV_IE_FORMAT, cur->format);
239  if (force || cur->tos)
240  iax_ie_append_byte(provdata, PROV_IE_TOS, cur->tos);
241 
242  /* Calculate checksum of message so far */
243  sig = prov_ver_calc(provdata);
244  if (signature)
245  *signature = sig;
246  /* Store signature */
247  iax_ie_append_int(provdata, PROV_IE_PROVVER, sig);
248  /* Cache signature for later verification so we need not recalculate all this */
249  snprintf(tmp, sizeof(tmp), "v0x%08x", sig);
250  ast_db_put("iax/provisioning/cache", template, tmp);
251  } else
252  ast_db_put("iax/provisioning/cache", template, "u");
254  return cur ? 0 : -1;
255 }
static ast_mutex_t provlock
#define PROV_IE_FORMAT
#define PROV_IE_PASS
unsigned int format
char lang[10]
#define ast_mutex_lock(a)
Definition: lock.h:155
unsigned int altserver
#define PROV_IE_PROVVER
unsigned short port
#define PROV_IE_FLAGS
int iax_ie_append_short(struct iax_ie_data *ied, unsigned char ie, unsigned short value)
Definition: iax2-parser.c:730
unsigned short serverport
#define PROV_IE_SERVERPORT
#define PROV_IE_SERVERIP
char user[20]
char pass[20]
unsigned int flags
unsigned int server
#define PROV_IE_LANG
#define PROV_IE_ALTSERVER
static struct iax_template * iax_template_find(const char *s, int allowdead)
static unsigned int prov_ver_calc(struct iax_ie_data *provdata)
unsigned int tos
int iax_ie_append_int(struct iax_ie_data *ied, unsigned char ie, unsigned int value)
Definition: iax2-parser.c:723
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
Definition: db.c:260
int iax_ie_append_byte(struct iax_ie_data *ied, unsigned char ie, unsigned char dat)
Definition: iax2-parser.c:742
#define PROV_IE_PORTNO
int iax_ie_append_str(struct iax_ie_data *ied, unsigned char ie, const char *str)
Definition: iax2-parser.c:737
#define PROV_IE_USER
#define PROV_IE_TOS
#define ast_mutex_unlock(a)
Definition: lock.h:156
int iax_provision_reload ( int  reload)

Definition at line 526 of file iax2-provision.c.

References ast_category_browse(), ast_config_destroy(), ast_config_load2(), ast_db_deltree(), AST_LIST_TRAVERSE, ast_log(), ast_verb, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, iax_template::dead, iax_process_template(), iax_provision_free_templates(), iax_provision_init(), iax_template::list, and LOG_NOTICE.

Referenced by load_module(), and reload_config().

527 {
528  struct ast_config *cfg;
529  struct iax_template *cur;
530  char *cat;
531  int found = 0;
532  struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
533  if (!provinit)
535 
536  cfg = ast_config_load2("iaxprov.conf", "chan_iax2", config_flags);
537  if (cfg != NULL && cfg != CONFIG_STATUS_FILEUNCHANGED && cfg != CONFIG_STATUS_FILEINVALID) {
538  /* Mark all as dead. No need for locking */
539  AST_LIST_TRAVERSE(&templates, cur, list) {
540  cur->dead = 1;
541  }
542 
543  /* Load as appropriate */
544  cat = ast_category_browse(cfg, NULL);
545  while(cat) {
546  if (strcasecmp(cat, "general")) {
547  iax_process_template(cfg, cat, found ? "default" : NULL);
548  found++;
549  ast_verb(3, "Loaded provisioning template '%s'\n", cat);
550  }
551  cat = ast_category_browse(cfg, cat);
552  }
553  ast_config_destroy(cfg);
554  } else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
555  return 0;
556  else
557  ast_log(LOG_NOTICE, "No IAX provisioning configuration found, IAX provisioning disabled.\n");
558 
559  iax_provision_free_templates(1 /* remove only marked as dead */);
560 
561  /* Purge cached signature DB entries */
562  ast_db_deltree("iax/provisioning/cache", NULL);
563  return 0;
564 }
static int iax_provision_init(void)
static int iax_process_template(struct ast_config *cfg, char *s, char *def)
static void iax_provision_free_templates(int dead)
static int provinit
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
Definition: config.c:2499
#define ast_verb(level,...)
Definition: logger.h:243
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: config.c:1037
char * ast_category_browse(struct ast_config *config, const char *prev)
Goes through categories.
Definition: config.c:810
static int reload(void)
Definition: app_amd.c:497
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define LOG_NOTICE
Definition: logger.h:133
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
Structure used to handle boolean flags.
Definition: utils.h:200
#define CONFIG_STATUS_FILEINVALID
Definition: config.h:52
int ast_db_deltree(const char *family, const char *keytree)
Delete one or more entries in astdb If both parameters are NULL, the entire database will be purged...
Definition: db.c:241
#define CONFIG_STATUS_FILEUNCHANGED
Definition: config.h:51
int iax_provision_unload ( void  )

Definition at line 517 of file iax2-provision.c.

References ast_cli_unregister_multiple(), cli_iax2_provision, and iax_provision_free_templates().

Referenced by __unload_module().

518 {
519  provinit = 0;
521  iax_provision_free_templates(0 /* Remove all templates. */);
522 
523  return 0;
524 }
static void iax_provision_free_templates(int dead)
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: cli.c:2177
descriptor for a cli entry.
Definition: cli.h:165
static int provinit
static struct ast_cli_entry cli_iax2_provision[]
int iax_provision_version ( unsigned int *  signature,
const char *  template,
int  force 
)

Definition at line 257 of file iax2-provision.c.

References ast_db_get(), ast_debug, ast_log(), ast_mutex_lock, ast_mutex_unlock, iax_provision_build(), LOG_ERROR, and provlock.

Referenced by check_provisioning().

258 {
259  char tmp[80] = "";
260  struct iax_ie_data ied;
261  int ret=0;
262  memset(&ied, 0, sizeof(ied));
263 
265  if (ast_db_get("iax/provisioning/cache", template, tmp, sizeof(tmp))) {
266  ast_log(LOG_ERROR, "ast_db_get failed to retrieve iax/provisioning/cache/%s\n", template);
267  }
268  if (sscanf(tmp, "v%30x", version) != 1) {
269  if (strcmp(tmp, "u")) {
270  ret = iax_provision_build(&ied, version, template, force);
271  if (ret)
272  ast_debug(1, "Unable to create provisioning packet for '%s'\n", template);
273  } else
274  ret = -1;
275  } else
276  ast_debug(1, "Retrieved cached version '%s' = '%08x'\n", tmp, *version);
278  return ret;
279 }
static ast_mutex_t provlock
uint32_t version
int iax_provision_build(struct iax_ie_data *provdata, unsigned int *signature, const char *template, int force)
int ast_db_get(const char *family, const char *key, char *out, int outlen)
Get key value specified by family/key.
Definition: db.c:348
#define ast_mutex_lock(a)
Definition: lock.h:155
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define ast_mutex_unlock(a)
Definition: lock.h:156