Codename Pineapple

Home page | Mailing list | Docs

Last updated: Sat Feb 3 05:01:43 2007

Asterisk developer's documentation :: Codename Pineapple


res_adsi.c File Reference


Detailed Description

ADSI support.

Author:
Mark Spencer <markster@digium.com>
Note:
this module is required by app_voicemail and app_getcpeid
Todo:
Move app_getcpeid into this module

Create a core layer so that app_voicemail does not require res_adsi to load

Definition in file res_adsi.c.

#include "asterisk.h"
#include <time.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <errno.h>
#include "asterisk/ulaw.h"
#include "asterisk/alaw.h"
#include "asterisk/callerid.h"
#include "asterisk/logger.h"
#include "asterisk/fskmodem.h"
#include "asterisk/channel.h"
#include "asterisk/adsi.h"
#include "asterisk/module.h"
#include "asterisk/config.h"
#include "asterisk/file.h"
#include "asterisk/options.h"

Include dependency graph for res_adsi.c:

Go to the source code of this file.

Defines

#define ADSI_FLAG_DATAMODE   (1 << 8)
#define ADSI_MAX_INTRO   20
#define ADSI_MAX_SPEED_DIAL   6
#define ADSI_SPEED_DIAL   10
#define DEFAULT_ADSI_MAX_RETRIES   3

Functions

static int __adsi_transmit_messages (struct ast_channel *chan, unsigned char **msg, int *msglen, int *msgtype)
static int adsi_careful_send (struct ast_channel *chan, unsigned char *buf, int len, int *remainder)
static int adsi_generate (unsigned char *buf, int msgtype, unsigned char *msg, int msglen, int msgnum, int last, int codec)
static void adsi_load (void)
int ast_adsi_available (struct ast_channel *chan)
int ast_adsi_begin_download (struct ast_channel *chan, char *service, unsigned char *fdn, unsigned char *sec, int version)
int ast_adsi_channel_restore (struct ast_channel *chan)
int ast_adsi_clear_screen (unsigned char *buf)
int ast_adsi_clear_soft_keys (unsigned char *buf)
int ast_adsi_connect_session (unsigned char *buf, unsigned char *fdn, int ver)
int ast_adsi_data_mode (unsigned char *buf)
int ast_adsi_disconnect_session (unsigned char *buf)
int ast_adsi_display (unsigned char *buf, int page, int line, int just, int wrap, char *col1, char *col2)
int ast_adsi_download_connect (unsigned char *buf, char *service, unsigned char *fdn, unsigned char *sec, int ver)
int ast_adsi_download_disconnect (unsigned char *buf)
int ast_adsi_end_download (struct ast_channel *chan)
int ast_adsi_get_cpeid (struct ast_channel *chan, unsigned char *cpeid, int voice)
int ast_adsi_get_cpeinfo (struct ast_channel *chan, int *width, int *height, int *buttons, int voice)
int ast_adsi_input_control (unsigned char *buf, int page, int line, int display, int format, int just)
int ast_adsi_input_format (unsigned char *buf, int num, int dir, int wrap, char *format1, char *format2)
int ast_adsi_load_session (struct ast_channel *chan, unsigned char *app, int ver, int data)
int ast_adsi_load_soft_key (unsigned char *buf, int key, const char *llabel, const char *slabel, const char *ret, int data)
int ast_adsi_print (struct ast_channel *chan, char **lines, int *aligns, int voice)
int ast_adsi_query_cpeid (unsigned char *buf)
int ast_adsi_query_cpeinfo (unsigned char *buf)
int ast_adsi_read_encoded_dtmf (struct ast_channel *chan, unsigned char *buf, int maxlen)
int ast_adsi_set_keys (unsigned char *buf, unsigned char *keys)
int ast_adsi_set_line (unsigned char *buf, int page, int line)
int ast_adsi_transmit_message (struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype)
int ast_adsi_transmit_message_full (struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype, int dowait)
int ast_adsi_unload_session (struct ast_channel *chan)
int ast_adsi_voice_mode (unsigned char *buf, int when)
 AST_MODULE_INFO (ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS,"ADSI Resource (not optional)",.load=load_module,.unload=unload_module,.reload=reload,)
static int ccopy (unsigned char *dst, const unsigned char *src, int max)
static void init_state (void)
static int load_module (void)
static int reload (void)
static int str2align (char *s)
static int unload_module (void)

Variables

static int alignment = 0
static int aligns [ADSI_MAX_INTRO]
static char intro [ADSI_MAX_INTRO][20]
static int maxretries = DEFAULT_ADSI_MAX_RETRIES
static char speeddial [ADSI_MAX_SPEED_DIAL][3][20]
static int speeds = 0
static int total = 0


Define Documentation

#define ADSI_FLAG_DATAMODE   (1 << 8)
 

Definition at line 62 of file res_adsi.c.

Referenced by __adsi_transmit_messages(), and ast_adsi_transmit_message_full().

#define ADSI_MAX_INTRO   20
 

Definition at line 59 of file res_adsi.c.

Referenced by adsi_load(), and init_state().

#define ADSI_MAX_SPEED_DIAL   6
 

Definition at line 60 of file res_adsi.c.

#define ADSI_SPEED_DIAL   10
 

Definition at line 67 of file res_adsi.c.

Referenced by ast_adsi_channel_restore().

#define DEFAULT_ADSI_MAX_RETRIES   3
 

Definition at line 57 of file res_adsi.c.


Function Documentation

static int __adsi_transmit_messages struct ast_channel chan,
unsigned char **  msg,
int *  msglen,
int *  msgtype
[static]
 

Definition at line 197 of file res_adsi.c.

References adsi_careful_send(), ADSI_FLAG_DATAMODE, ast_channel::adsicpe, AST_ADSI_AVAILABLE, AST_ADSI_UNAVAILABLE, AST_FORMAT_ULAW, AST_FRAME_DTMF, ast_frfree(), ast_gen_cas(), ast_log(), ast_read(), ast_waitfor(), ast_frame::frametype, LOG_DEBUG, LOG_WARNING, option_debug, and ast_frame::subclass.

Referenced by ast_adsi_transmit_message_full().

00198 {
00199    /* msglen must be no more than 256 bits, each */
00200    unsigned char buf[24000 * 5];
00201    int pos = 0, res;
00202    int x;
00203    int start=0;
00204    int retries = 0;
00205 
00206    char ack[3];
00207 
00208    /* Wait up to 500 ms for initial ACK */
00209    int waittime;
00210    struct ast_frame *f;
00211    int rem = 0;
00212    int def;
00213 
00214    if (chan->adsicpe == AST_ADSI_UNAVAILABLE) {
00215       /* Don't bother if we know they don't support ADSI */
00216       errno = ENOSYS;
00217       return -1;
00218    }
00219 
00220    while(retries < maxretries) {
00221       if (!(chan->adsicpe & ADSI_FLAG_DATAMODE)) {
00222          /* Generate CAS (no SAS) */
00223          ast_gen_cas(buf, 0, 680, AST_FORMAT_ULAW);
00224       
00225          /* Send CAS */
00226          if (adsi_careful_send(chan, buf, 680, NULL)) {
00227             ast_log(LOG_WARNING, "Unable to send CAS\n");
00228          }
00229          /* Wait For DTMF result */
00230          waittime = 500;
00231          for(;;) {
00232             if (((res = ast_waitfor(chan, waittime)) < 1)) {
00233                /* Didn't get back DTMF A in time */
00234                if (option_debug)
00235                   ast_log(LOG_DEBUG, "No ADSI CPE detected (%d)\n", res);
00236                if (!chan->adsicpe)
00237                   chan->adsicpe = AST_ADSI_UNAVAILABLE;
00238                errno = ENOSYS;
00239                return -1;
00240             }
00241             waittime = res;
00242             f = ast_read(chan);
00243             if (!f) {
00244                if (option_debug)
00245                   ast_log(LOG_DEBUG, "Hangup in ADSI\n");
00246                return -1;
00247             }
00248             if (f->frametype == AST_FRAME_DTMF) {
00249                if (f->subclass == 'A') {
00250                   /* Okay, this is an ADSI CPE.  Note this for future reference, too */
00251                   if (!chan->adsicpe)
00252                      chan->adsicpe = AST_ADSI_AVAILABLE;
00253                   break;
00254                } else {
00255                   if (f->subclass == 'D')  {
00256                      if (option_debug)
00257                         ast_log(LOG_DEBUG, "Off-hook capable CPE only, not ADSI\n");
00258                   } else
00259                      ast_log(LOG_WARNING, "Unknown ADSI response '%c'\n", f->subclass);
00260                   if (!chan->adsicpe)
00261                      chan->adsicpe = AST_ADSI_UNAVAILABLE;
00262                   errno =  ENOSYS;
00263                   return -1;
00264                }
00265             }
00266             ast_frfree(f);
00267          }
00268 
00269          if (option_debug)
00270             ast_log(LOG_DEBUG, "ADSI Compatible CPE Detected\n");
00271       } else {
00272          if (option_debug)
00273             ast_log(LOG_DEBUG, "Already in data mode\n");
00274       }
00275 
00276       x = 0;
00277       pos = 0;
00278 #if 1
00279       def= ast_channel_defer_dtmf(chan);
00280 #endif
00281       while((x < 6) && msg[x]) {
00282          res = adsi_generate(buf + pos, msgtype[x], msg[x], msglen[x], x+1 - start, (x == 5) || !msg[x+1], AST_FORMAT_ULAW);
00283          if (res < 0) {
00284             ast_log(LOG_WARNING, "Failed to generate ADSI message %d on channel %s\n", x + 1, chan->name);
00285             return -1;
00286          }
00287          if (option_debug)
00288             ast_log(LOG_DEBUG, "Message %d, of %d input bytes, %d output bytes\n", 
00289                   x + 1, msglen[x], res);
00290          pos += res; 
00291          x++;
00292       }
00293 
00294 
00295       rem = 0;
00296       res = adsi_careful_send(chan, buf, pos, &rem); 
00297       if (!def)
00298          ast_channel_undefer_dtmf(chan);
00299       if (res)
00300          return -1;
00301 
00302       if (option_debug)
00303          ast_log(LOG_DEBUG, "Sent total spill of %d bytes\n", pos);
00304 
00305       memset(ack, 0, sizeof(ack));
00306       /* Get real result */
00307       res = ast_readstring(chan, ack, 2, 1000, 1000, "");
00308       /* Check for hangup */
00309       if (res < 0)
00310          return -1;
00311       if (ack[0] == 'D') {
00312          if (option_debug)
00313             ast_log(LOG_DEBUG, "Acked up to message %d\n", atoi(ack + 1));
00314          start += atoi(ack + 1);
00315          if (start >= x)
00316             break;
00317          else {
00318             retries++;
00319             if (option_debug)
00320                ast_log(LOG_DEBUG, "Retransmitting (%d), from %d\n", retries, start + 1);
00321          }
00322       } else {
00323          retries++;
00324          ast_log(LOG_WARNING, "Unexpected response to ack: %s (retry %d)\n", ack, retries);
00325       } 
00326    }
00327    if (retries >= maxretries) {
00328       ast_log(LOG_WARNING, "Maximum ADSI Retries (%d) exceeded\n", maxretries);
00329       errno = ETIMEDOUT;
00330       return -1;
00331    }
00332    return 0;
00333    
00334 }

static int adsi_careful_send struct ast_channel chan,
unsigned char *  buf,
int  len,
int *  remainder
[static]
 

Definition at line 126 of file res_adsi.c.

References AST_FORMAT_ULAW, AST_FRAME_VOICE, ast_frfree(), ast_log(), ast_read(), ast_waitfor(), ast_write(), ast_frame::datalen, ast_frame::frametype, LOG_WARNING, and ast_frame::subclass.

Referenced by __adsi_transmit_messages().

00127 {
00128    /* Sends carefully on a full duplex channel by using reading for
00129       timing */
00130    struct ast_frame *inf, outf;
00131    int amt;
00132 
00133    /* Zero out our outgoing frame */
00134    memset(&outf, 0, sizeof(outf));
00135 
00136    if (remainder && *remainder) {
00137       amt = len;
00138 
00139       /* Send remainder if provided */
00140       if (amt > *remainder)
00141          amt = *remainder;
00142       else
00143          *remainder = *remainder - amt;
00144       outf.frametype = AST_FRAME_VOICE;
00145       outf.subclass = AST_FORMAT_ULAW;
00146       outf.data = buf;
00147       outf.datalen = amt;
00148       outf.samples = amt;
00149       if (ast_write(chan, &outf)) {
00150          ast_log(LOG_WARNING, "Failed to carefully write frame\n");
00151          return -1;
00152       }
00153       /* Update pointers and lengths */
00154       buf += amt;
00155       len -= amt;
00156    }
00157 
00158    while(len) {
00159       amt = len;
00160       /* If we don't get anything at all back in a second, forget
00161          about it */
00162       if (ast_waitfor(chan, 1000) < 1)
00163          return -1;
00164       inf = ast_read(chan);
00165       /* Detect hangup */
00166       if (!inf)
00167          return -1;
00168       if (inf->frametype == AST_FRAME_VOICE) {
00169          /* Read a voice frame */
00170          if (inf->subclass != AST_FORMAT_ULAW) {
00171             ast_log(LOG_WARNING, "Channel not in ulaw?\n");
00172             return -1;
00173          }
00174          /* Send no more than they sent us */
00175          if (amt > inf->datalen)
00176             amt = inf->datalen;
00177          else if (remainder)
00178             *remainder = inf->datalen - amt;
00179          outf.frametype = AST_FRAME_VOICE;
00180          outf.subclass = AST_FORMAT_ULAW;
00181          outf.data = buf;
00182          outf.datalen = amt;
00183          outf.samples = amt;
00184          if (ast_write(chan, &outf)) {
00185             ast_log(LOG_WARNING, "Failed to carefully write frame\n");
00186             return -1;
00187          }
00188          /* Update pointers and lengths */
00189          buf += amt;
00190          len -= amt;
00191       }
00192       ast_frfree(inf);
00193    }
00194    return 0;
00195 }

static int adsi_generate unsigned char *  buf,
int  msgtype,
unsigned char *  msg,
int  msglen,
int  msgnum,
int  last,
int  codec
[static]
 

Definition at line 76 of file res_adsi.c.

References PUT_CLID, and PUT_CLID_MARKMS.

00077 {
00078    int sum;
00079    int x;   
00080    int bytes=0;
00081    /* Initial carrier (imaginary) */
00082    float cr = 1.0;
00083    float ci = 0.0;
00084    float scont = 0.0;
00085 
00086    if (msglen > 255)
00087       msglen = 255;
00088 
00089    /* If first message, Send 150ms of MARK's */
00090    if (msgnum == 1) {
00091       for (x=0;x<150;x++)  /* was 150 */
00092          PUT_CLID_MARKMS;
00093    }
00094    /* Put message type */
00095    PUT_CLID(msgtype);
00096    sum = msgtype;
00097 
00098    /* Put message length (plus one  for the message number) */
00099    PUT_CLID(msglen + 1);
00100    sum += msglen + 1;
00101 
00102    /* Put message number */
00103    PUT_CLID(msgnum);
00104    sum += msgnum;
00105 
00106    /* Put actual message */
00107    for (x=0;x<msglen;x++) {
00108       PUT_CLID(msg[x]);
00109       sum += msg[x];
00110    }
00111 
00112    /* Put 2's compliment of sum */
00113    PUT_CLID(256-(sum & 0xff));
00114 
00115 #if 0
00116    if (last) {
00117       /* Put trailing marks */
00118       for (x=0;x<50;x++)
00119          PUT_CLID_MARKMS;
00120    }
00121 #endif
00122    return bytes;
00123 
00124 }

static void adsi_load void   )  [static]
 

Definition at line 1083 of file res_adsi.c.

References ADSI_MAX_INTRO, ast_config_load(), ast_variable_browse(), init_state(), ast_variable::name, name, ast_variable::next, str2align(), and ast_variable::value.

Referenced by load_module(), and reload().

01084 {
01085    int x;
01086    struct ast_config *conf;
01087    struct ast_variable *v;
01088    char *name, *sname;
01089    init_state();
01090    conf = ast_config_load("adsi.conf");
01091    if (conf) {
01092       x=0;
01093       for (v = ast_variable_browse(conf, "intro"); v; v = v->next) {
01094          if (!strcasecmp(v->name, "alignment"))
01095             alignment = str2align(v->value);
01096          else if (!strcasecmp(v->name, "greeting")) {
01097             if (x < ADSI_MAX_INTRO) {
01098                aligns[x] = alignment;
01099                ast_copy_string(intro[x], v->value, sizeof(intro[x]));
01100                x++;
01101             }
01102          } else if (!strcasecmp(v->name, "maxretries")) {
01103             if (atoi(v->value) > 0)
01104                maxretries = atoi(v->value);
01105          }
01106       }
01107       if (x)
01108          total = x;
01109       x = 0;
01110       for (v = ast_variable_browse(conf, "speeddial"); v; v = v->next) {
01111          char *stringp = v->value;
01112          name = strsep(&stringp, ",");
01113          sname = strsep(&stringp, ",");
01114          if (!sname) 
01115             sname = name;
01116          if (x < ADSI_MAX_SPEED_DIAL) {
01117             ast_copy_string(speeddial[x][0], v->name, sizeof(speeddial[x][0]));
01118             ast_copy_string(speeddial[x][1], name, 18);
01119             ast_copy_string(speeddial[x][2], sname, 7);
01120             x++;
01121          }
01122       }
01123       if (x)
01124          speeds = x;
01125       ast_config_destroy(conf);
01126    }
01127 }

int ast_adsi_available struct ast_channel chan  ) 
 

Parameters:
chan Channel to check

Definition at line 787 of file res_adsi.c.

References ast_channel::adsicpe, AST_ADSI_AVAILABLE, and AST_ADSI_UNKNOWN.

00788 {
00789    int cpe = chan->adsicpe & 0xff;
00790    if ((cpe == AST_ADSI_AVAILABLE) ||
00791        (cpe == AST_ADSI_UNKNOWN))
00792       return 1;
00793    return 0;
00794 }

int ast_adsi_begin_download struct ast_channel chan,
char *  service,
unsigned char *  fdn,
unsigned char *  sec,
int  version
 

Definition at line 336 of file res_adsi.c.

References ADSI_MSG_DOWNLOAD, ast_adsi_download_connect(), ast_adsi_transmit_message_full(), ast_log(), ast_readstring(), and option_debug.

00337 {
00338    int bytes;
00339    unsigned char buf[256];
00340    char ack[2];
00341    bytes = 0;
00342    /* Setup the resident soft key stuff, a piece at a time */
00343    /* Upload what scripts we can for voicemail ahead of time */
00344    bytes += ast_adsi_download_connect(buf + bytes, service, fdn, sec, version);
00345    if (ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DOWNLOAD, 0))
00346       return -1;
00347    if (ast_readstring(chan, ack, 1, 10000, 10000, ""))
00348       return -1;
00349    if (ack[0] == 'B')
00350       return 0;
00351    if (option_debug)
00352       ast_log(LOG_DEBUG, "Download was denied by CPE\n");
00353    return -1;
00354 }

int ast_adsi_channel_restore struct ast_channel chan  ) 
 

Parameters:
chan Channel to restore
Returns 0 on success (or adsi unavailable) and -1 on hangup

Definition at line 945 of file res_adsi.c.

References ADSI_INFO_PAGE, ADSI_SPEED_DIAL, ast_adsi_set_keys(), and ast_adsi_set_line().

00946 {
00947    unsigned char dsp[256];
00948    int bytes;
00949    int x;
00950    unsigned char keyd[6];
00951 
00952    memset(dsp, 0, sizeof(dsp));
00953 
00954    /* Start with initial display setup */
00955    bytes = 0;
00956    bytes += ast_adsi_set_line(dsp + bytes, ADSI_INFO_PAGE, 1);
00957 
00958    /* Prepare key setup messages */
00959 
00960    if (speeds) {
00961       memset(keyd, 0, sizeof(keyd));
00962       for (x=0;x<speeds;x++) {
00963          keyd[x] = ADSI_SPEED_DIAL + x;
00964       }
00965       bytes += ast_adsi_set_keys(dsp + bytes, keyd);
00966    }
00967    ast_adsi_transmit_message_full(chan, dsp, bytes, ADSI_MSG_DISPLAY, 0);
00968    return 0;
00969 
00970 }

int ast_adsi_clear_screen unsigned char *  buf  ) 
 

Definition at line 755 of file res_adsi.c.

References ADSI_CLEAR_SCREEN.

00756 {
00757    int bytes=0;
00758 
00759    /* Message type */
00760    buf[bytes++] = ADSI_CLEAR_SCREEN;
00761 
00762    /* Reserve space for length */
00763    bytes++;
00764 
00765    buf[1] = bytes - 2;
00766    return bytes;
00767 
00768 }

int ast_adsi_clear_soft_keys unsigned char *  buf  ) 
 

Definition at line 740 of file res_adsi.c.

References ADSI_CLEAR_SOFTKEY.

00741 {
00742    int bytes=0;
00743 
00744    /* Message type */
00745    buf[bytes++] = ADSI_CLEAR_SOFTKEY;
00746 
00747    /* Reserve space for length */
00748    bytes++;
00749 
00750    buf[1] = bytes - 2;
00751    return bytes;
00752 
00753 }

int ast_adsi_connect_session unsigned char *  buf,
unsigned char *  fdn,
int  ver
 

Parameters:
buf Character buffer to create parameter in (must have at least 256 free)
fdn Optional 4 byte Feature Download Number (for loading soft keys)
ver Optional version number (0-255, or -1 to omit)
Returns number of bytes added to buffer or -1 on error.

Definition at line 505 of file res_adsi.c.

References ADSI_CONNECT_SESSION.

Referenced by ast_adsi_load_session().

00506 {
00507    int bytes=0;
00508    int x;
00509 
00510    /* Message type */
00511    buf[bytes++] = ADSI_CONNECT_SESSION;
00512 
00513    /* Reserve space for length */
00514    bytes++;
00515 
00516    if (fdn) {
00517       for (x=0;x<4;x++)
00518          buf[bytes++] = fdn[x];
00519       if (ver > -1)
00520          buf[bytes++] = ver & 0xff;
00521    }
00522 
00523    buf[1] = bytes - 2;
00524    return bytes;
00525 
00526 }

int ast_adsi_data_mode unsigned char *  buf  ) 
 

Parameters:
buf Character buffer to create parameter in (must have at least 256 free)
Returns number of bytes added to buffer or -1 on error.

Definition at line 725 of file res_adsi.c.

References ADSI_SWITCH_TO_DATA.

Referenced by ast_adsi_get_cpeid(), ast_adsi_get_cpeinfo(), and ast_adsi_load_session().

00726 {
00727    int bytes=0;
00728 
00729    /* Message type */
00730    buf[bytes++] = ADSI_SWITCH_TO_DATA;
00731 
00732    /* Reserve space for length */
00733    bytes++;
00734 
00735    buf[1] = bytes - 2;
00736    return bytes;
00737 
00738 }

int ast_adsi_disconnect_session unsigned char *  buf  ) 
 

Parameters:
buf Character buffer to create parameter in (must have at least 256 free)
Returns number of bytes added to buffer or -1 on error.

Definition at line 558 of file res_adsi.c.

References ADSI_DISC_SESSION.

Referenced by ast_adsi_unload_session().

00559 {
00560    int bytes=0;
00561 
00562    /* Message type */
00563    buf[bytes++] = ADSI_DISC_SESSION;
00564 
00565    /* Reserve space for length */
00566    bytes++;
00567 
00568    buf[1] = bytes - 2;
00569    return bytes;
00570 
00571 }

int ast_adsi_display unsigned char *  buf,
int  page,
int  line,
int  just,
int  wrap,
char *  col1,
char *  col2
 

Parameters:
buf Character buffer to create parameter in (must have at least 256 free)
page Page to load (ADSI_COMM_PAGE or ADSI_INFO_PAGE)
line Line number to load (1-4 for Comm page, 1-33 for info page)
just Line justification (ADSI_JUST_LEFT, ADSI_JUST_RIGHT, ADSI_JUST_CENT, ADSI_JUST_IND)
wrap Wrap (1 = yes, 0 = no)
col1 Text to place in first column
col2 Text to place in second column
Returns number of bytes added to buffer or -1 on error.

Definition at line 811 of file res_adsi.c.

References ADSI_LOAD_VIRTUAL_DISP, and ccopy().

Referenced by ast_adsi_print().

00813 {
00814    int bytes=0;
00815 
00816    /* Sanity check line number */
00817 
00818    if (page) {
00819       if (line > 4) return -1;
00820    } else {
00821       if (line > 33) return -1;
00822    }
00823 
00824    if (line < 1)
00825       return -1;
00826    /* Parameter type */
00827    buf[bytes++] = ADSI_LOAD_VIRTUAL_DISP;
00828    
00829    /* Reserve space for size */
00830    bytes++;
00831 
00832    /* Page and wrap indicator */
00833    buf[bytes++] = ((page & 0x1) << 7) | ((wrap & 0x1) << 6) | (line & 0x3f);
00834 
00835    /* Justification */
00836    buf[bytes++] = (just & 0x3) << 5;
00837 
00838    /* Omit highlight mode definition */
00839    buf[bytes++] = 0xff;
00840 
00841    /* Primary column */
00842    bytes+= ccopy(buf + bytes, (unsigned char *)col1, 20);
00843 
00844    /* Delimiter */
00845    buf[bytes++] = 0xff;
00846    
00847    /* Secondary column */
00848    bytes += ccopy(buf + bytes, (unsigned char *)col2, 20);
00849 
00850    /* Update length */
00851    buf[1] = bytes - 2;
00852    
00853    return bytes;
00854 
00855 }

int ast_adsi_download_connect unsigned char *  buf,
char *  service,
unsigned char *  fdn,
unsigned char *  sec,
int  ver
 

Parameters:
buf Character buffer to create parameter in (must have at least 256 free)
service a 1-18 byte name of the feature
fdn 4 byte Feature Download Number (for loading soft keys)
sec 4 byte vendor security code
ver version number (0-255, or -1 to omit)
Returns number of bytes added to buffer or -1 on error.

Definition at line 528 of file res_adsi.c.

References ADSI_DOWNLOAD_CONNECT, and ccopy().

Referenced by ast_adsi_begin_download().

00529 {
00530    int bytes=0;
00531    int x;
00532 
00533    /* Message type */
00534    buf[bytes++] = ADSI_DOWNLOAD_CONNECT;
00535 
00536    /* Reserve space for length */
00537    bytes++;
00538 
00539    /* Primary column */
00540    bytes+= ccopy(buf + bytes, (unsigned char *)service, 18);
00541 
00542    /* Delimiter */
00543    buf[bytes++] = 0xff;
00544    
00545    for (x=0;x<4;x++) {
00546       buf[bytes++] = fdn[x];
00547    }
00548    for (x=0;x<4;x++)
00549       buf[bytes++] = sec[x];
00550    buf[bytes++] = ver & 0xff;
00551 
00552    buf[1] = bytes - 2;
00553 
00554    return bytes;
00555 
00556 }

int ast_adsi_download_disconnect unsigned char *  buf  ) 
 

Parameters:
buf Character buffer to create parameter in (must have at least 256 free)
Returns number of bytes added to buffer or -1 on error.

Definition at line 796 of file res_adsi.c.

References ADSI_DOWNLOAD_DISC.

Referenced by ast_adsi_end_download().

00797 {
00798    int bytes=0;
00799 
00800    /* Message type */
00801    buf[bytes++] = ADSI_DOWNLOAD_DISC;
00802 
00803    /* Reserve space for length */
00804    bytes++;
00805 
00806    buf[1] = bytes - 2;
00807    return bytes;
00808 
00809 }

int ast_adsi_end_download struct ast_channel chan  ) 
 

Definition at line 356 of file res_adsi.c.

References ADSI_MSG_DOWNLOAD, ast_adsi_download_disconnect(), and ast_adsi_transmit_message_full().

00357 {
00358    int bytes;
00359    unsigned char buf[256];
00360         bytes = 0;
00361         /* Setup the resident soft key stuff, a piece at a time */
00362         /* Upload what scripts we can for voicemail ahead of time */
00363         bytes += ast_adsi_download_disconnect(buf + bytes);
00364    if (ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DOWNLOAD, 0))
00365       return -1;
00366    return 0;
00367 }

int ast_adsi_get_cpeid struct ast_channel chan,
unsigned char *  cpeid,
int  voice
 

Returns 1 on success, storing 4 bytes of CPE ID at buf or -1 on hangup, or 0 if there was no hangup but it failed to find the device ID. Returns to voice mode if "voice" is non-zero.

Definition at line 628 of file res_adsi.c.

References ADSI_MSG_DISPLAY, ast_adsi_data_mode(), ast_adsi_query_cpeid(), ast_adsi_read_encoded_dtmf(), ast_adsi_transmit_message_full(), ast_adsi_voice_mode(), ast_log(), ast_waitfordigit(), and LOG_WARNING.

00629 {
00630    unsigned char buf[256];
00631    int bytes = 0;
00632    int res;
00633    bytes += ast_adsi_data_mode(buf);
00634    ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0);
00635 
00636    bytes = 0;
00637    bytes += ast_adsi_query_cpeid(buf);
00638    ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0);
00639 
00640    /* Get response */
00641    memset(buf, 0, sizeof(buf));
00642    res = ast_adsi_read_encoded_dtmf(chan, cpeid, 4);
00643    if (res != 4) {
00644       ast_log(LOG_WARNING, "Got %d bytes back of encoded DTMF, expecting 4\n", res);
00645       res = 0;
00646    } else {
00647       res = 1;
00648    }
00649 
00650    if (voice) {
00651       bytes = 0;
00652       bytes += ast_adsi_voice_mode(buf, 0);
00653       ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0);
00654       /* Ignore the resulting DTMF B announcing it's in voice mode */
00655       ast_waitfordigit(chan, 1000);
00656    }
00657    return res;
00658 }

int ast_adsi_get_cpeinfo struct ast_channel chan,
int *  width,
int *  height,
int *  buttons,
int  voice
 

Definition at line 660 of file res_adsi.c.

References ADSI_MSG_DISPLAY, ast_adsi_data_mode(), ast_adsi_query_cpeinfo(), ast_adsi_transmit_message_full(), ast_adsi_voice_mode(), ast_log(), ast_readstring(), ast_waitfordigit(), and LOG_WARNING.

00661 {
00662    unsigned char buf[256];
00663    int bytes = 0;
00664    int res;
00665    bytes += ast_adsi_data_mode(buf);
00666    ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0);
00667 
00668    bytes = 0;
00669    bytes += ast_adsi_query_cpeinfo(buf);
00670    ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0);
00671 
00672    /* Get width */
00673    memset(buf, 0, sizeof(buf));
00674    res = ast_readstring(chan, (char *)buf, 2, 1000, 500, "");
00675    if (res < 0)
00676       return res;
00677    if (strlen((char *)buf) != 2) {
00678       ast_log(LOG_WARNING, "Got %d bytes of width, expecting 2\n", res);
00679       res = 0;
00680    } else {
00681       res = 1;
00682    }
00683    if (width)
00684       *width = atoi((char *)buf);
00685    /* Get height */
00686    memset(buf, 0, sizeof(buf));
00687    if (res) {
00688       res = ast_readstring(chan, (char *)buf, 2, 1000, 500, "");
00689       if (res < 0)
00690          return res;
00691       if (strlen((char *)buf) != 2) {
00692          ast_log(LOG_WARNING, "Got %d bytes of height, expecting 2\n", res);
00693          res = 0;
00694       } else {
00695          res = 1;
00696       }  
00697       if (height)
00698          *height= atoi((char *)buf);
00699    }
00700    /* Get buttons */
00701    memset(buf, 0, sizeof(buf));
00702    if (res) {
00703       res = ast_readstring(chan, (char *)buf, 1, 1000, 500, "");
00704       if (res < 0)
00705          return res;
00706       if (strlen((char *)buf) != 1) {
00707          ast_log(LOG_WARNING, "Got %d bytes of buttons, expecting 1\n", res);
00708          res = 0;
00709       } else {
00710          res = 1;
00711       }  
00712       if (buttons)
00713          *buttons = atoi((char *)buf);
00714    }
00715    if (voice) {
00716       bytes = 0;
00717       bytes += ast_adsi_voice_mode(buf, 0);
00718       ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0);
00719       /* Ignore the resulting DTMF B announcing it's in voice mode */
00720       ast_waitfordigit(chan, 1000);
00721    }
00722    return res;
00723 }

int ast_adsi_input_control unsigned char *  buf,
int  page,
int  line,
int  display,
int  format,
int  just
 

Parameters:
buf Character buffer to create parameter in (must have at least 256 free)
page Which page to input on (ADSI_COMM_PAGE or ADSI_INFO_PAGE)
line Line number to input on
display Set to zero to obscure input, or 1 to leave visible
format Format number to use (0-7)
just Justification (left, right center, indent)
Returns number of bytes added to buffer or -1 on error.

Definition at line 857 of file res_adsi.c.

References ADSI_INPUT_CONTROL.

00858 {
00859    int bytes=0;
00860 
00861    if (page) {
00862       if (line > 4) return -1;
00863    } else {
00864       if (line > 33) return -1;
00865    }
00866 
00867    if (line < 1)
00868       return -1;
00869 
00870    buf[bytes++] = ADSI_INPUT_CONTROL;
00871    bytes++;
00872    buf[bytes++] = ((page & 1) << 7) | (line & 0x3f);
00873    buf[bytes++] = ((display & 1) << 7) | ((just & 0x3) << 4) | (format & 0x7);
00874    
00875    buf[1] = bytes - 2;
00876    return bytes;
00877 
00878 }

int ast_adsi_input_format unsigned char *  buf,
int  num,
int  dir,
int  wrap,
char *  format1,
char *  format2
 

Parameters:
buf Character buffer to create parameter in (must have at least 256 free)
num Which format we are setting
dir Which direction (ADSI_DIR_FROM_LEFT or ADSI_DIR_FROM_RIGHT)
wrap Set to 1 to permit line wrap, or 0 if not
format1 Format for column 1
format2 Format for column 2
Returns number of bytes added to buffer or -1 on error.

Definition at line 880 of file res_adsi.c.

References ADSI_INPUT_FORMAT, and ccopy().

00881 {
00882    int bytes = 0;
00883 
00884    if (!strlen((char *)format1))
00885       return -1;
00886 
00887    buf[bytes++] = ADSI_INPUT_FORMAT;
00888    bytes++;
00889    buf[bytes++] = ((dir & 1) << 7) | ((wrap & 1) << 6) | (num & 0x7);
00890    bytes += ccopy(buf + bytes, (unsigned char *)format1, 20);
00891    buf[bytes++] = 0xff;
00892    if (format2 && strlen((char *)format2)) {
00893       bytes += ccopy(buf + bytes, (unsigned char *)format2, 20);
00894    }
00895    buf[1] = bytes - 2;
00896    return bytes;
00897 }

int ast_adsi_load_session struct ast_channel chan,
unsigned char *  app,
int  ver,
int  data
 

Parameters:
chan Channel to test for loaded app
app Four character app name (must be unique to your application)
ver optional version number
data Non-zero if you want to be put in data mode
Returns 0 if scripts is not loaded or not an ADSI CPE. Returns -1 on hangup. Returns 1 if script already loaded.

Definition at line 992 of file res_adsi.c.

References ADSI_MSG_DISPLAY, ast_adsi_connect_session(), ast_adsi_data_mode(), ast_adsi_transmit_message_full(), ast_log(), ast_readstring(), LOG_DEBUG, LOG_WARNING, and option_debug.

Referenced by adsi_announce_park().

00993 {
00994    unsigned char dsp[256];
00995    int bytes;
00996    int res;
00997    char resp[2];
00998 
00999    memset(dsp, 0, sizeof(dsp));
01000 
01001    /* Connect to session */
01002    bytes = 0;
01003    bytes += ast_adsi_connect_session(dsp + bytes, app, ver);
01004 
01005    if (data)
01006       bytes += ast_adsi_data_mode(dsp + bytes);
01007 
01008    /* Prepare key setup messages */
01009    if (ast_adsi_transmit_message_full(chan, dsp, bytes, ADSI_MSG_DISPLAY, 0))
01010       return -1;
01011    if (app) {
01012       res = ast_readstring(chan, resp, 1, 1200, 1200, "");
01013       if (res < 0)
01014          return -1;
01015       if (res) {
01016          if (option_debug)
01017             ast_log(LOG_DEBUG, "No response from CPE about version.  Assuming not there.\n");
01018          return 0;
01019       }
01020       if (!strcmp(resp, "B")) {
01021          if (option_debug)
01022             ast_log(LOG_DEBUG, "CPE has script '%s' version %d already loaded\n", app, ver);
01023          return 1;
01024       } else if (!strcmp(resp, "A")) {
01025          if (option_debug)
01026             ast_log(LOG_DEBUG, "CPE hasn't script '%s' version %d already loaded\n", app, ver);
01027       } else {
01028          ast_log(LOG_WARNING, "Unexpected CPE response to script query: %s\n", resp);
01029       }
01030    } else
01031       return 1;
01032    return 0;
01033 
01034 }

int ast_adsi_load_soft_key unsigned char *  buf,
int  key,
const char *  llabel,
const char *  slabel,
const char *  ret,
int  data
 

Parameters:
buf Character buffer to create parameter in (must have at least 256 free)
key Key code from 2 to 33, for which key we are loading
llabel Long label for key (1-18 bytes)
slabel Short label for key (1-7 bytes)
ret Optional return sequence (NULL for none)
data whether to put CPE in data mode before sending digits
Returns number of bytes added to buffer or -1 on error.

Definition at line 466 of file res_adsi.c.

References ADSI_LOAD_SOFTKEY, ADSI_SWITCH_TO_DATA2, and ccopy().

00467 {
00468    int bytes=0;
00469 
00470    /* Abort if invalid key specified */
00471    if ((key < 2) || (key > 33))
00472       return -1;
00473    buf[bytes++] = ADSI_LOAD_SOFTKEY;
00474    /* Reserve for length */
00475    bytes++;
00476    /* Which key */
00477    buf[bytes++] = key;
00478 
00479    /* Carefully copy long label */
00480    bytes += ccopy(buf + bytes, (const unsigned char *)llabel, 18);
00481 
00482    /* Place delimiter */
00483    buf[bytes++] = 0xff;
00484 
00485    /* Short label */
00486    bytes += ccopy(buf + bytes, (const unsigned char *)slabel, 7);
00487 
00488 
00489    /* If specified, copy return string */
00490    if (ret) {
00491       /* Place delimiter */
00492       buf[bytes++] = 0xff;
00493       if (data)
00494          buf[bytes++] = ADSI_SWITCH_TO_DATA2;
00495       /* Carefully copy return string */
00496       bytes += ccopy(buf + bytes, (const unsigned char *)ret, 20);
00497 
00498    }
00499    /* Replace parameter length */
00500    buf[1] = bytes - 2;
00501    return bytes;
00502    
00503 }

int ast_adsi_print struct ast_channel chan,
char **  lines,
int *  align,
int  voice
 

Parameters:
chan Channel to display on
lines NULL-terminated list of things to print (no more than 4 recommended)
align list of alignments to use (ADSI_JUST_LEFT, ADSI_JUST_RIGHT, ADSI_JUST_CEN, etc..)
voice whether to jump into voice mode when finished
Return 0 on success (or adsi unavailable) and -1 on hangup

Definition at line 972 of file res_adsi.c.

References ADSI_INFO_PAGE, ADSI_MSG_DISPLAY, ast_adsi_display(), ast_adsi_set_line(), ast_adsi_transmit_message_full(), ast_adsi_voice_mode(), and ast_waitfordigit().

Referenced by adsi_announce_park().

00973 {
00974    unsigned char buf[4096];
00975    int bytes=0;
00976    int res;
00977    int x;
00978    for(x=0;lines[x];x++) 
00979       bytes += ast_adsi_display(buf + bytes, ADSI_INFO_PAGE, x+1, aligns[x], 0, lines[x], "");
00980    bytes += ast_adsi_set_line(buf + bytes, ADSI_INFO_PAGE, 1);
00981    if (voice) {
00982       bytes += ast_adsi_voice_mode(buf + bytes, 0);
00983    }
00984    res = ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0);
00985    if (voice) {
00986       /* Ignore the resulting DTMF B announcing it's in voice mode */
00987       ast_waitfordigit(chan, 1000);
00988    }
00989    return res;
00990 }

int ast_adsi_query_cpeid unsigned char *  buf  ) 
 

Returns number of bytes added to message

Definition at line 573 of file res_adsi.c.

References ADSI_QUERY_CPEID.

Referenced by ast_adsi_get_cpeid().

00574 {
00575    int bytes = 0;
00576    buf[bytes++] = ADSI_QUERY_CPEID;
00577    /* Reserve space for length */
00578    bytes++;
00579    buf[1] = bytes - 2;
00580    return bytes;
00581 }

int ast_adsi_query_cpeinfo unsigned char *  buf  ) 
 

Definition at line 583 of file res_adsi.c.

References ADSI_QUERY_CONFIG.

Referenced by ast_adsi_get_cpeinfo().

00584 {
00585    int bytes = 0;
00586    buf[bytes++] = ADSI_QUERY_CONFIG;
00587    /* Reserve space for length */
00588    bytes++;
00589    buf[1] = bytes - 2;
00590    return bytes;
00591 }

int ast_adsi_read_encoded_dtmf struct ast_channel chan,
unsigned char *  buf,
int  maxlen
 

Returns number of bytes received

Definition at line 593 of file res_adsi.c.

References ast_waitfordigit().

Referenced by ast_adsi_get_cpeid().

00594 {
00595    int bytes = 0;
00596    int res;
00597    unsigned char current = 0;
00598    int gotstar = 0;
00599    int pos = 0;
00600    memset(buf, 0, sizeof(buf));
00601    while(bytes <= maxlen) {
00602       /* Wait up to a second for a digit */
00603       res = ast_waitfordigit(chan, 1000);
00604       if (!res)
00605          break;
00606       if (res == '*') {
00607          gotstar = 1;   
00608          continue;
00609       }
00610       /* Ignore anything other than a digit */
00611       if ((res < '0') || (res > '9'))
00612          continue;
00613       res -= '0';
00614       if (gotstar)
00615          res += 9;
00616       if (pos)  {
00617          pos = 0;
00618          buf[bytes++] = (res << 4) | current;
00619       } else {
00620          pos = 1;
00621          current = res;
00622       }
00623       gotstar = 0;
00624    }
00625    return bytes;
00626 }

int ast_adsi_set_keys unsigned char *  buf,
unsigned char *  keys
 

Parameters:
buf Character buffer to create parameter in (must have at least 256 free)
keys Array of 8 unsigned chars with the key numbers, may be OR'd with ADSI_KEY_HILITE But remember, the last two keys aren't real keys, they're for scrolling
Returns number of bytes added to buffer or -1 on error.

Definition at line 899 of file res_adsi.c.

References ADSI_INIT_SOFTKEY_LINE.

Referenced by ast_adsi_channel_restore().

00900 {
00901    int bytes=0;
00902    int x;
00903    /* Message type */
00904    buf[bytes++] = ADSI_INIT_SOFTKEY_LINE;
00905    /* Space for size */
00906    bytes++;
00907    /* Key definitions */
00908    for (x=0;x<6;x++)
00909       buf[bytes++] = (keys[x] & 0x3f) ? keys[x] : (keys[x] | 0x1);
00910    buf[1] = bytes - 2;
00911    return bytes;
00912 }

int ast_adsi_set_line unsigned char *  buf,
int  page,
int  line
 

Parameters:
buf Character buffer to create parameter in (must have at least 256 free)
page Which page (ADSI_COMM_PAGE or ADSI_INFO_PAGE)
line Line number (1-33 for info page, 1-4 for comm page)
Returns number of bytes added to buffer or -1 on error.

Definition at line 914 of file res_adsi.c.

References ADSI_LINE_CONTROL.

Referenced by ast_adsi_channel_restore(), and ast_adsi_print().

00915 {
00916    int bytes=0;
00917 
00918    /* Sanity check line number */
00919 
00920    if (page) {
00921       if (line > 4) return -1;
00922    } else {
00923       if (line > 33) return -1;
00924    }
00925 
00926    if (line < 1)
00927       return -1;
00928    /* Parameter type */
00929    buf[bytes++] = ADSI_LINE_CONTROL;
00930    
00931    /* Reserve space for size */
00932    bytes++;
00933 
00934    /* Page and line */
00935    buf[bytes++] = ((page & 0x1) << 7) | (line & 0x3f);
00936 
00937    buf[1] = bytes - 2;
00938    return bytes;
00939 
00940 };

int ast_adsi_transmit_message struct ast_channel chan,
unsigned char *  msg,
int  msglen,
int  msgtype
 

Definition at line 450 of file res_adsi.c.

References ast_adsi_transmit_message_full().

00451 {
00452    return ast_adsi_transmit_message_full(chan, msg, msglen, msgtype, 1);
00453 }

int ast_adsi_transmit_message_full struct ast_channel chan,
unsigned char *  msg,
int  msglen,
int  msgtype,
int  dowait
 

Definition at line 369 of file res_adsi.c.

References __adsi_transmit_messages(), ADSI_FLAG_DATAMODE, ADSI_SWITCH_TO_DATA, ADSI_SWITCH_TO_VOICE, ast_channel::adsicpe, AST_FORMAT_ULAW, ast_log(), ast_safe_sleep(), ast_set_read_format(), ast_set_write_format(), ast_stopstream(), ast_waitfordigit(), LOG_WARNING, option_debug, ast_channel::readformat, and ast_channel::writeformat.

Referenced by ast_adsi_begin_download(), ast_adsi_end_download(), ast_adsi_get_cpeid(), ast_adsi_get_cpeinfo(), ast_adsi_load_session(), ast_adsi_print(), ast_adsi_transmit_message(), and ast_adsi_unload_session().

00370 {
00371    unsigned char *msgs[5] = { NULL, NULL, NULL, NULL, NULL };
00372    int msglens[5];
00373    int msgtypes[5];
00374    int newdatamode;
00375    int res;
00376    int x;
00377    int writeformat, readformat;
00378    int waitforswitch = 0;
00379 
00380    writeformat = chan->writeformat;
00381    readformat = chan->readformat;
00382 
00383    newdatamode = chan->adsicpe & ADSI_FLAG_DATAMODE;
00384 
00385    for (x=0;x<msglen;x+=(msg[x+1]+2)) {
00386       if (msg[x] == ADSI_SWITCH_TO_DATA) {
00387          if (option_debug)
00388             ast_log(LOG_DEBUG, "Switch to data is sent!\n");
00389          waitforswitch++;
00390          newdatamode = ADSI_FLAG_DATAMODE;
00391       }
00392       
00393       if (msg[x] == ADSI_SWITCH_TO_VOICE) {
00394          if (option_debug)
00395             ast_log(LOG_DEBUG, "Switch to voice is sent!\n");
00396          waitforswitch++;
00397          newdatamode = 0;
00398       }
00399    }
00400    msgs[0] = msg;
00401 
00402    msglens[0] = msglen;
00403    msgtypes[0] = msgtype;
00404 
00405    if (msglen > 253) {
00406       ast_log(LOG_WARNING, "Can't send ADSI message of %d bytes, too large\n", msglen);
00407       return -1;
00408    }
00409 
00410    ast_stopstream(chan);
00411 
00412    if (ast_set_write_format(chan, AST_FORMAT_ULAW)) {
00413       ast_log(LOG_WARNING, "Unable to set write format to ULAW\n");
00414       return -1;
00415    }
00416 
00417    if (ast_set_read_format(chan, AST_FORMAT_ULAW)) {
00418       ast_log(LOG_WARNING, "Unable to set read format to ULAW\n");
00419       if (writeformat) {
00420          if (ast_set_write_format(chan, writeformat)) 
00421             ast_log(LOG_WARNING, "Unable to restore write format to %d\n", writeformat);
00422       }
00423       return -1;
00424    }
00425    res = __adsi_transmit_messages(chan, msgs, msglens, msgtypes);
00426 
00427    if (dowait) {
00428       if (option_debug)
00429          ast_log(LOG_DEBUG, "Wait for switch is '%d'\n", waitforswitch);
00430       while (waitforswitch-- && ((res = ast_waitfordigit(chan, 1000)) > 0)) { 
00431          res = 0; 
00432          if (option_debug)
00433             ast_log(LOG_DEBUG, "Waiting for 'B'...\n");
00434       }
00435    }
00436    
00437    if (!res)
00438       chan->adsicpe = (chan->adsicpe & ~ADSI_FLAG_DATAMODE) | newdatamode;
00439 
00440    if (writeformat)
00441       ast_set_write_format(chan, writeformat);
00442    if (readformat)
00443       ast_set_read_format(chan, readformat);
00444 
00445    if (!res)
00446       res = ast_safe_sleep(chan, 100 );
00447    return res;
00448 }

int ast_adsi_unload_session struct ast_channel chan  ) 
 

Definition at line 1036 of file res_adsi.c.

References ADSI_MSG_DISPLAY, ast_adsi_disconnect_session(), ast_adsi_transmit_message_full(), and ast_adsi_voice_mode().

01037 {
01038    unsigned char dsp[256];
01039    int bytes;
01040 
01041    memset(dsp, 0, sizeof(dsp));
01042 
01043    /* Connect to session */
01044    bytes = 0;
01045    bytes += ast_adsi_disconnect_session(dsp + bytes);
01046    bytes += ast_adsi_voice_mode(dsp + bytes, 0);
01047 
01048    /* Prepare key setup messages */
01049    if (ast_adsi_transmit_message_full(chan, dsp, bytes, ADSI_MSG_DISPLAY, 0))
01050       return -1;
01051    return 0;
01052 }

int ast_adsi_voice_mode unsigned char *  buf,
int  when
 

Parameters:
buf Character buffer to create parameter in (must have at least 256 free)
when (a time in seconds) to make the switch
Returns number of bytes added to buffer or -1 on error.

Definition at line 770 of file res_adsi.c.

References ADSI_SWITCH_TO_VOICE.

Referenced by ast_adsi_get_cpeid(), ast_adsi_get_cpeinfo(), ast_adsi_print(), and ast_adsi_unload_session().

00771 {
00772    int bytes=0;
00773 
00774    /* Message type */
00775    buf[bytes++] = ADSI_SWITCH_TO_VOICE;
00776 
00777    /* Reserve space for length */
00778    bytes++;
00779 
00780    buf[bytes++] = when & 0x7f;
00781 
00782    buf[1] = bytes - 2;
00783    return bytes;
00784 
00785 }

AST_MODULE_INFO ASTERISK_GPL_KEY  ,
AST_MODFLAG_GLOBAL_SYMBOLS  ,
"ADSI Resource (not optional)"  ,
load = load_module,
unload = unload_module,
reload = reload
 

static int ccopy unsigned char *  dst,
const unsigned char *  src,
int  max
[inline, static]
 

Definition at line 455 of file res_adsi.c.

Referenced by ast_adsi_display(), ast_adsi_download_connect(), ast_adsi_input_format(), and ast_adsi_load_soft_key().

00456 {
00457    int x=0;
00458    /* Carefully copy the requested data */
00459    while ((x < max) && src[x] && (src[x] != 0xff)) {
00460       dst[x] = src[x];
00461       x++;
00462    }
00463    return x;
00464 }

static void init_state void   )  [static]
 

Definition at line 1066 of file res_adsi.c.

References ADSI_JUST_CENT, ADSI_MAX_INTRO, speeds, and total.

Referenced by adsi_load().

01067 {
01068    int x;
01069 
01070    for (x=0;x<ADSI_MAX_INTRO;x++)
01071       aligns[x] = ADSI_JUST_CENT;
01072    ast_copy_string(intro[0], "Welcome to the", sizeof(intro[0]));
01073    ast_copy_string(intro[1], "Asterisk", sizeof(intro[1]));
01074    ast_copy_string(intro[2], "Open Source PBX", sizeof(intro[2]));
01075    total = 3;
01076    speeds = 0;
01077    for (x=3;x<ADSI_MAX_INTRO;x++)
01078       intro[x][0] = '\0';
01079    memset(speeddial, 0, sizeof(speeddial));
01080    alignment = ADSI_JUST_CENT;
01081 }

static int load_module void   )  [static]
 

Definition at line 1135 of file res_adsi.c.

References adsi_load().

01136 {
01137    adsi_load();
01138    return 0;
01139 }

static int reload void   )  [static]
 

Definition at line 1129 of file res_adsi.c.

References adsi_load().

01130 {
01131    adsi_load();
01132    return 0;
01133 }

static int str2align char *  s  )  [static]
 

Definition at line 1054 of file res_adsi.c.

References ADSI_JUST_CENT, ADSI_JUST_IND, ADSI_JUST_LEFT, and ADSI_JUST_RIGHT.

Referenced by adsi_load().

01055 {
01056    if (!strncasecmp(s, "l", 1))
01057       return ADSI_JUST_LEFT;
01058    else if (!strncasecmp(s, "r", 1))
01059       return ADSI_JUST_RIGHT;
01060    else if (!strncasecmp(s, "i", 1))
01061       return ADSI_JUST_IND;
01062    else
01063       return ADSI_JUST_CENT;
01064 }

static int unload_module void   )  [static]
 

Definition at line 1141 of file res_adsi.c.

01142 {
01143    /* Can't unload this once we're loaded */
01144    return -1;
01145 }


Variable Documentation

int alignment = 0 [static]
 

Definition at line 74 of file res_adsi.c.

int aligns[ADSI_MAX_INTRO] [static]
 

Definition at line 70 of file res_adsi.c.

char intro[ADSI_MAX_INTRO][20] [static]
 

Definition at line 69 of file res_adsi.c.

int maxretries = DEFAULT_ADSI_MAX_RETRIES [static]
 

Definition at line 64 of file res_adsi.c.

Referenced by ast_ivr_menu_run_internal().

char speeddial[ADSI_MAX_SPEED_DIAL][3][20] [static]
 

Definition at line 72 of file res_adsi.c.

int speeds = 0 [static]
 

Definition at line 943 of file res_adsi.c.

Referenced by init_state().

int total = 0 [static]
 

Definition at line 942 of file res_adsi.c.

Referenced by ast_cdr_serialize_variables(), init_state(), manager_sip_show_devices(), manager_sip_show_peers(), pbx_builtin_serialize_variables(), and send_sound().


Asterisk is a trademark for Digium, inc.. | Edvina.net | Asterisk.org | This documentation was generated with Doxygen