Sat Nov 25 00:46:14 2006

Asterisk developer's documentation


vmodem.h File Reference

Voice Modem Definitions. More...

#include "asterisk/frame.h"
#include "asterisk/channel.h"

Go to the source code of this file.

Data Structures

struct  ast_modem_driver
struct  ast_modem_pvt

Defines

#define AST_MAX_INIT_STR   256
#define CHAR_DC4   0x14
#define CHAR_DLE   0x10
#define CHAR_ETX   0x03
#define MODEM_DEV_HANDSET   9
#define MODEM_DEV_SPKRPHONE   6
#define MODEM_DEV_TELCO   0
#define MODEM_DEV_TELCO_SPK   4
#define MODEM_DTMF_AST   (1 << 1)
#define MODEM_DTMF_I4L   (1 << 2)
#define MODEM_DTMF_NONE   (1 << 0)
#define MODEM_MAX_BUF   MODEM_MAX_LEN * 16
#define MODEM_MAX_LEN   30
#define MODEM_MODE_IMMEDIATE   0
#define MODEM_MODE_WAIT_ANSWER   2
#define MODEM_MODE_WAIT_RING   1

Functions

int ast_modem_expect (struct ast_modem_pvt *p, char *result, int timeout)
ast_channelast_modem_new (struct ast_modem_pvt *i, int state)
int ast_modem_read_response (struct ast_modem_pvt *p, int timeout)
int ast_modem_send (struct ast_modem_pvt *p, char *cmd, int len)
void ast_modem_trim (char *s)
int ast_register_modem_driver (struct ast_modem_driver *mc)
int ast_unregister_modem_driver (struct ast_modem_driver *mc)


Detailed Description

Voice Modem Definitions.

Definition in file vmodem.h.


Define Documentation

#define AST_MAX_INIT_STR   256
 

Definition at line 46 of file vmodem.h.

#define CHAR_DC4   0x14
 

Definition at line 31 of file vmodem.h.

#define CHAR_DLE   0x10
 

Definition at line 29 of file vmodem.h.

Referenced by aopen_read(), bestdata_read(), i4l_dialdigit(), i4l_read(), and i4l_write().

#define CHAR_ETX   0x03
 

Definition at line 30 of file vmodem.h.

Referenced by aopen_handle_escape(), bestdata_handle_escape(), and i4l_handle_escape().

#define MODEM_DEV_HANDSET   9
 

Definition at line 36 of file vmodem.h.

Referenced by modem_call().

#define MODEM_DEV_SPKRPHONE   6
 

Definition at line 35 of file vmodem.h.

#define MODEM_DEV_TELCO   0
 

Definition at line 33 of file vmodem.h.

Referenced by i4l_setdev().

#define MODEM_DEV_TELCO_SPK   4
 

Definition at line 34 of file vmodem.h.

Referenced by i4l_setdev(), and modem_call().

#define MODEM_DTMF_AST   (1 << 1)
 

Definition at line 39 of file vmodem.h.

Referenced by i4l_answer(), i4l_dialdigit(), i4l_startrec(), and load_module().

#define MODEM_DTMF_I4L   (1 << 2)
 

Definition at line 40 of file vmodem.h.

Referenced by i4l_dialdigit(), and load_module().

#define MODEM_DTMF_NONE   (1 << 0)
 

Definition at line 38 of file vmodem.h.

Referenced by load_module().

#define MODEM_MAX_BUF   MODEM_MAX_LEN * 16
 

Definition at line 44 of file vmodem.h.

#define MODEM_MAX_LEN   30
 

Definition at line 43 of file vmodem.h.

#define MODEM_MODE_IMMEDIATE   0
 

Definition at line 74 of file vmodem.h.

Referenced by aopen_read(), bestdata_read(), and load_module().

#define MODEM_MODE_WAIT_ANSWER   2
 

Definition at line 76 of file vmodem.h.

Referenced by load_module().

#define MODEM_MODE_WAIT_RING   1
 

Definition at line 75 of file vmodem.h.

Referenced by load_module().


Function Documentation

int ast_modem_expect struct ast_modem_pvt p,
char *  result,
int  timeout
 

Wait for result to occur. Return non-zero if times out or error, last response is stored in p->response

Definition at line 345 of file chan_modem.c.

References ast_waitfor_n_fd(), ast_modem_pvt::f, ast_modem_pvt::fd, and ast_modem_pvt::response.

Referenced by aopen_answer(), aopen_break(), aopen_dialdigit(), aopen_hangup(), aopen_identify(), aopen_init(), aopen_setdev(), aopen_startrec(), bestdata_answer(), bestdata_break(), bestdata_dialdigit(), bestdata_hangup(), bestdata_identify(), bestdata_init(), bestdata_startplay(), bestdata_startrec(), i4l_answer(), i4l_break(), i4l_hangup(), i4l_init(), i4l_setdev(), i4l_startrec(), and modem_setup().

00346 {
00347    int res = -1;
00348    timeout *= 1000;
00349    strncpy(p->response, "(No Response)", sizeof(p->response)-1);
00350    do {
00351       res = ast_waitfor_n_fd(&p->fd, 1, &timeout, NULL);
00352       if (res < 0) {
00353          return -1;
00354       }
00355       /* Read a response */
00356       fgets(p->response, sizeof(p->response), p->f);
00357       if (!strncasecmp(p->response, result, strlen(result))) 
00358          return 0;
00359    } while(timeout > 0);
00360    return -1;
00361 }

struct ast_channel* ast_modem_new struct ast_modem_pvt i,
int  state
 

Used by modem drivers to start up the PBX on a RING

Definition at line 560 of file chan_modem.c.

References ast_channel_alloc(), ast_hangup(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_pbx_start(), ast_setstate(), AST_STATE_DOWN, AST_STATE_RING, ast_strlen_zero(), ast_update_use_count(), ast_channel::cid, ast_callerid::cid_ani, ast_modem_pvt::cid_name, ast_callerid::cid_name, ast_modem_pvt::cid_num, ast_callerid::cid_num, ast_channel::context, ast_modem_pvt::context, ast_modem_pvt::dev, ast_modem_pvt::dnid, ast_channel::exten, ast_modem_pvt::fd, ast_channel::fds, ast_modem_driver::formats, ast_modem_pvt::language, ast_channel::language, LOG_WARNING, ast_modem_pvt::mc, modem_tech, ast_channel::name, ast_modem_driver::name, ast_channel::nativeformats, ast_modem_pvt::owner, ast_channel::rings, strdup, ast_channel::tech, ast_channel::tech_pvt, ast_channel::type, and usecnt_lock.

Referenced by modem_mini_packet(), and modem_request().

00561 {
00562    struct ast_channel *tmp;
00563    tmp = ast_channel_alloc(1);
00564    if (tmp) {
00565       tmp->tech = &modem_tech;
00566       snprintf(tmp->name, sizeof(tmp->name), "Modem[%s]/%s", i->mc->name, i->dev + 5);
00567       tmp->type = type;
00568       tmp->fds[0] = i->fd;
00569       tmp->nativeformats = i->mc->formats;
00570       ast_setstate(tmp, state);
00571       if (state == AST_STATE_RING)
00572          tmp->rings = 1;
00573       tmp->tech_pvt = i;
00574       strncpy(tmp->context, i->context, sizeof(tmp->context)-1);
00575 
00576       if (!ast_strlen_zero(i->cid_num)) {
00577          tmp->cid.cid_num = strdup(i->cid_num);
00578          tmp->cid.cid_ani = strdup(i->cid_num);
00579       }
00580       if (!ast_strlen_zero(i->cid_name))
00581          tmp->cid.cid_name = strdup(i->cid_name);
00582 
00583       if (!ast_strlen_zero(i->language))
00584          strncpy(tmp->language,i->language, sizeof(tmp->language)-1);
00585       if (!ast_strlen_zero(i->dnid))
00586          strncpy(tmp->exten, i->dnid, sizeof(tmp->exten) - 1);
00587       i->owner = tmp;
00588       ast_mutex_lock(&usecnt_lock);
00589       usecnt++;
00590       ast_mutex_unlock(&usecnt_lock);
00591       ast_update_use_count();
00592       if (state != AST_STATE_DOWN) {
00593          if (ast_pbx_start(tmp)) {
00594             ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
00595             ast_hangup(tmp);
00596             tmp = NULL;
00597          }
00598       }
00599    } else
00600       ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
00601    return tmp;
00602 }

int ast_modem_read_response struct ast_modem_pvt p,
int  timeout
 

Wait for result to occur. response is stored in p->response

Definition at line 296 of file chan_modem.c.

References ast_waitfor_n_fd(), ast_modem_pvt::f, ast_modem_pvt::fd, and ast_modem_pvt::response.

Referenced by aopen_break(), aopen_identify(), aopen_setdev(), bestdata_break(), bestdata_handle_escape(), bestdata_identify(), i4l_break(), i4l_setdev(), and modem_setup().

00297 {
00298    int res = -1,c,i;
00299    timeout *= 1000;
00300    p->response[0] = 0;
00301    c = i = 0;
00302    do {
00303       res = ast_waitfor_n_fd(&p->fd, 1, &timeout, NULL);
00304       if (res < 0) {
00305          strncpy(p->response, "(No Response)", sizeof(p->response)-1);
00306          return -1;
00307       }
00308         /* get no more then buffer length */
00309       while(i < sizeof(p->response) - 1)
00310       {
00311          c = fgetc(p->f);  /* get a char */
00312          if (c < 1) /* if error */
00313          {
00314               /* if nothing in buffer, go back into timeout stuff */
00315             if (errno == EWOULDBLOCK) break;
00316             /* return as error */
00317             strncpy(p->response, "(No Response)", sizeof(p->response)-1);
00318             return -1;
00319          }
00320            /* save char */
00321          p->response[i++] = c;
00322          p->response[i] = 0;        
00323            /* if end of input */
00324          if (c == '\n') break;
00325       }
00326       if (c >= 0)  /* if input terminated normally */
00327       {
00328            /* ignore just CR/LF */
00329          if (!strcmp(p->response,"\r\n"))
00330          {
00331               /* reset input buffer stuff */
00332             i = 0; 
00333             p->response[0] = 0;
00334          }
00335          else /* otherwise return with info in buffer */
00336          {
00337             return 0;
00338          }
00339       }
00340    } while(timeout > 0);
00341    strncpy(p->response, "(No Response)", sizeof(p->response)-1);
00342    return -1;
00343 }

int ast_modem_send struct ast_modem_pvt p,
char *  cmd,
int  len
 

Send the command cmd (length len, or 0 if pure ascii) on modem

Definition at line 272 of file chan_modem.c.

References ast_modem_pvt::f.

Referenced by aopen_answer(), aopen_break(), aopen_dial(), aopen_dialdigit(), aopen_handle_escape(), aopen_hangup(), aopen_identify(), aopen_init(), aopen_setdev(), aopen_startrec(), bestdata_answer(), bestdata_break(), bestdata_dialdigit(), bestdata_handle_escape(), bestdata_hangup(), bestdata_identify(), bestdata_init(), bestdata_startplay(), bestdata_startrec(), i4l_answer(), i4l_break(), i4l_dial(), i4l_handle_escape(), i4l_hangup(), i4l_init(), i4l_setdev(), i4l_startrec(), and modem_setup().

00273 {
00274    int i;
00275    usleep(5000);
00276    if (!len) {
00277       for(i = 0; cmd[i];)
00278          {
00279          if (fwrite(cmd + i,1,1,p->f) != 1)
00280             {
00281             if (errno == EWOULDBLOCK) continue;
00282             return -1;
00283             }
00284          i++;
00285          }
00286       tcdrain(fileno(p->f)); 
00287       fprintf(p->f,"\r\n");
00288       return 0;
00289    } else {
00290       if (fwrite(cmd, 1, len, p->f) < len)
00291          return -1;
00292       return 0;
00293    }
00294 }

void ast_modem_trim char *  s  ) 
 

Trim off trailing mess

Definition at line 363 of file chan_modem.c.

Referenced by aopen_identify(), aopen_read(), aopen_setdev(), bestdata_handle_escape(), bestdata_identify(), bestdata_read(), i4l_read(), i4l_setdev(), and modem_setup().

00364 {
00365    int x;
00366    x = strlen(s) - 1;
00367    while(x >= 0) {
00368       if ((s[x] != '\r') && (s[x] != '\n') && (s[x] != ' '))
00369          break;
00370       s[x] = '\0';
00371       x--;
00372    }
00373 }

int ast_register_modem_driver struct ast_modem_driver mc  ) 
 

Register a driver

Definition at line 194 of file chan_modem.c.

References drivers, and ast_modem_driver::next.

Referenced by load_module().

00195 {
00196    mc->next = drivers;
00197    drivers = mc;
00198    return 0;
00199 }

int ast_unregister_modem_driver struct ast_modem_driver mc  ) 
 

Unregister a driver

Definition at line 201 of file chan_modem.c.

References drivers, last, and ast_modem_driver::next.

Referenced by unload_module().

00202 {
00203    struct ast_modem_driver *last = NULL, *cur;
00204    cur = drivers;
00205    while(cur) {
00206       if (cur == mc) {
00207          if (last)
00208             last->next = mc->next;
00209          else
00210             drivers = mc->next;
00211          return 0;
00212       }
00213       cur = cur->next;
00214    }
00215    return -1;
00216 }


Generated on Sat Nov 25 00:46:14 2006 for Asterisk - the Open Source PBX by  doxygen 1.4.6