Asterisk - The Open Source Telephony Project  18.5.0
Functions
firmware.h File Reference

IAX Firmware Support header file. More...

#include "parser.h"
Include dependency graph for firmware.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int iax_firmware_append (struct iax_ie_data *ie_data, const char *device_name, unsigned int block_desc)
 
int iax_firmware_get_version (const char *device_name, uint16_t *version)
 
void iax_firmware_reload (void)
 
void iax_firmware_traverse (const char *prefix, int(*callback)(struct ast_iax2_firmware_header *header, void *user_data), void *user_data)
 
void iax_firmware_unload (void)
 

Detailed Description

IAX Firmware Support header file.

Definition in file firmware.h.

Function Documentation

◆ iax_firmware_append()

int iax_firmware_append ( struct iax_ie_data ie_data,
const char *  device_name,
unsigned int  block_desc 
)

Definition at line 283 of file firmware.c.

References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_strlen_zero, bs, ast_iax2_firmware_header::data, ast_iax2_firmware_header::datalen, ast_iax2_firmware_header::devname, iax_firmware::fwh, iax_ie_append(), iax_ie_append_int(), iax_ie_append_raw(), IAX_IE_FWBLOCKDATA, IAX_IE_FWBLOCKDESC, and iax_firmware::list.

Referenced by socket_process_helper().

284 {
285  int res = -1;
286  unsigned int bs = desc & 0xff;
287  unsigned int start = (desc >> 8) & 0xffffff;
288  unsigned int bytes;
289  struct iax_firmware *cur;
290 
291  if (ast_strlen_zero((char *)dev) || !bs)
292  return -1;
293 
294  start *= bs;
295 
298  if (strcmp(dev, (const char *) cur->fwh->devname))
299  continue;
301  if (start < ntohl(cur->fwh->datalen)) {
302  bytes = ntohl(cur->fwh->datalen) - start;
303  if (bytes > bs)
304  bytes = bs;
305  iax_ie_append_raw(ied, IAX_IE_FWBLOCKDATA, cur->fwh->data + start, bytes);
306  } else {
307  bytes = 0;
309  }
310  if (bytes == bs)
311  res = 0;
312  else
313  res = 1;
314  break;
315  }
317 
318  return res;
319 }
unsigned char data[0]
Definition: iax2.h:299
unsigned int datalen
Definition: iax2.h:297
int iax_ie_append_int(struct iax_ie_data *ied, unsigned char ie, unsigned int value)
Definition: parser.c:755
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
static const char desc[]
Definition: cdr_mysql.c:73
int iax_ie_append_raw(struct iax_ie_data *ied, unsigned char ie, const void *data, int datalen)
Definition: parser.c:725
char * bs
Definition: eagi_proxy.c:73
#define ast_strlen_zero(foo)
Definition: strings.h:52
int iax_ie_append(struct iax_ie_data *ied, unsigned char ie)
Definition: parser.c:779
struct iax_firmware::@155 list
unsigned char devname[16]
Definition: iax2.h:296
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define IAX_IE_FWBLOCKDESC
Definition: iax2.h:165
#define IAX_IE_FWBLOCKDATA
Definition: iax2.h:166
struct ast_iax2_firmware_header * fwh
Definition: firmware.c:54

◆ iax_firmware_get_version()

int iax_firmware_get_version ( const char *  device_name,
uint16_t *  version 
)

Definition at line 263 of file firmware.c.

References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_strlen_zero, ast_iax2_firmware_header::devname, iax_firmware::fwh, iax_firmware::list, NULL, and ast_iax2_firmware_header::version.

Referenced by update_registry().

264 {
265  struct iax_firmware *cur = NULL;
266 
267  if (ast_strlen_zero(dev))
268  return 0;
269 
272  if (!strcmp(dev, (const char *) cur->fwh->devname)) {
273  *version = ntohs(cur->fwh->version);
275  return 1;
276  }
277  }
279 
280  return 0;
281 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
unsigned short version
Definition: iax2.h:295
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct iax_firmware::@155 list
unsigned char devname[16]
Definition: iax2.h:296
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
static char version[AST_MAX_EXTENSION]
Definition: chan_ooh323.c:391
struct ast_iax2_firmware_header * fwh
Definition: firmware.c:54

◆ iax_firmware_reload()

void iax_firmware_reload ( void  )

Definition at line 206 of file firmware.c.

References ast_config_AST_DATA_DIR, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_log, ast_verb, iax_firmware::dead, destroy_firmware(), errno, IAX_FIRMWARE_SUBDIR, iax_firmware::list, LOG_WARNING, NULL, PATH_MAX, and try_firmware().

Referenced by load_module(), and reload_config().

207 {
208  struct iax_firmware *cur = NULL;
209  DIR *fwd;
210  struct dirent *de;
211  char fn[PATH_MAX + sizeof(IAX_FIRMWARE_SUBDIR) + sizeof(de->d_name)];
212 
214 
215  /* Mark all as dead */
216  AST_LIST_TRAVERSE(&firmwares, cur, list) {
217  cur->dead = 1;
218  }
219 
220  /* Now that we have marked them dead... load new ones */
221  snprintf(fn, sizeof(fn), "%s%s", ast_config_AST_DATA_DIR, IAX_FIRMWARE_SUBDIR);
222  fwd = opendir(fn);
223  if (fwd) {
224  while((de = readdir(fwd))) {
225  if (de->d_name[0] != '.') {
226  snprintf(fn, sizeof(fn), "%s%s/%s",
228  if (!try_firmware(fn)) {
229  ast_verb(2, "Loaded firmware '%s'\n", de->d_name);
230  }
231  }
232  }
233  closedir(fwd);
234  } else {
235  ast_log(LOG_WARNING, "Error opening firmware directory '%s': %s\n", fn, strerror(errno));
236  }
237 
238  /* Clean up leftovers */
240  if (!cur->dead)
241  continue;
243  destroy_firmware(cur);
244  }
246 
248 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
#define LOG_WARNING
Definition: logger.h:274
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
static int try_firmware(char *s)
Definition: firmware.c:60
#define NULL
Definition: resample.c:96
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:614
#define ast_verb(level,...)
Definition: logger.h:463
#define ast_log
Definition: astobj2.c:42
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556
static void destroy_firmware(struct iax_firmware *cur)
Definition: firmware.c:196
const char * ast_config_AST_DATA_DIR
Definition: options.c:158
int errno
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
#define PATH_MAX
Definition: asterisk.h:40
#define IAX_FIRMWARE_SUBDIR
Definition: firmware.c:47

◆ iax_firmware_traverse()

void iax_firmware_traverse ( const char *  prefix,
int(*)(struct ast_iax2_firmware_header *header, void *user_data)  callback,
void *  user_data 
)

◆ iax_firmware_unload()

void iax_firmware_unload ( void  )

Definition at line 250 of file firmware.c.

References AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, destroy_firmware(), iax_firmware::list, and NULL.

Referenced by __unload_module().

251 {
252  struct iax_firmware *cur = NULL;
253 
257  destroy_firmware(cur);
258  }
261 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
#define NULL
Definition: resample.c:96
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:614
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556
static void destroy_firmware(struct iax_firmware *cur)
Definition: firmware.c:196
struct iax_firmware::@155 list
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528