static int adsi_get_cpeid(struct ast_channel *chan, unsigned char *cpeid, int voice) { unsigned char buf[256] = ""; int bytes = 0, res; bytes += adsi_data_mode(buf); adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0); bytes = 0; bytes += adsi_query_cpeid(buf); adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0); /* Get response */ res = adsi_read_encoded_dtmf(chan, cpeid, 4); if (res != 4) { ast_log(LOG_WARNING, "Got %d bytes back of encoded DTMF, expecting 4\n", res); res = 0; } else { res = 1; } if (voice) { bytes = 0; bytes += adsi_voice_mode(buf, 0); adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0); /* Ignore the resulting DTMF B announcing it's in voice mode */ ast_waitfordigit(chan, 1000); } return res; }
int adsi_channel_restore(struct ast_channel *chan) { unsigned char dsp[256]; int bytes; int x; unsigned char keyd[6]; memset(dsp, 0, sizeof(dsp)); /* Start with initial display setup */ bytes = 0; bytes += adsi_set_line(dsp + bytes, ADSI_INFO_PAGE, 1); /* Prepare key setup messages */ if (speeds) { memset(keyd, 0, sizeof(keyd)); for (x=0;x<speeds;x++) { keyd[x] = ADSI_SPEED_DIAL + x; } bytes += adsi_set_keys(dsp + bytes, keyd); } adsi_transmit_message_full(chan, dsp, bytes, ADSI_MSG_DISPLAY, 0); return 0; }
int adsi_end_download(struct ast_channel *chan) { int bytes; unsigned char buf[256]; bytes = 0; /* Setup the resident soft key stuff, a piece at a time */ /* Upload what scripts we can for voicemail ahead of time */ bytes += adsi_download_disconnect(buf + bytes); if (adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DOWNLOAD, 0)) return -1; return 0; }
static int adsi_unload_session(struct ast_channel *chan) { unsigned char dsp[256] = ""; int bytes = 0; /* Connect to session */ bytes += adsi_disconnect_session(dsp + bytes); bytes += adsi_voice_mode(dsp + bytes, 0); /* Prepare key setup messages */ if (adsi_transmit_message_full(chan, dsp, bytes, ADSI_MSG_DISPLAY, 0)) { return -1; } return 0; }
int adsi_begin_download(struct ast_channel *chan, char *service, unsigned char *fdn, unsigned char *sec, int version) { int bytes; unsigned char buf[256]; char ack[2]; bytes = 0; /* Setup the resident soft key stuff, a piece at a time */ /* Upload what scripts we can for voicemail ahead of time */ bytes += adsi_download_connect(buf + bytes, service, fdn, sec, version); if (adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DOWNLOAD, 0)) return -1; if (ast_readstring(chan, ack, 1, 10000, 10000, "")) return -1; if (ack[0] == 'B') return 0; ast_log(LOG_DEBUG, "Download was denied by CPE\n"); return -1; }
static int adsi_print(struct ast_channel *chan, char **lines, int *alignments, int voice) { unsigned char buf[4096]; int bytes = 0, res, x; for (x = 0; lines[x]; x++) { bytes += adsi_display(buf + bytes, ADSI_INFO_PAGE, x+1, alignments[x], 0, lines[x], ""); } bytes += adsi_set_line(buf + bytes, ADSI_INFO_PAGE, 1); if (voice) { bytes += adsi_voice_mode(buf + bytes, 0); } res = adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0); if (voice) { /* Ignore the resulting DTMF B announcing it's in voice mode */ ast_waitfordigit(chan, 1000); } return res; }
int adsi_load_session(struct ast_channel *chan, unsigned char *app, int ver, int data) { unsigned char dsp[256]; int bytes; int res; char resp[2]; memset(dsp, 0, sizeof(dsp)); /* Connect to session */ bytes = 0; bytes += adsi_connect_session(dsp + bytes, app, ver); if (data) bytes += adsi_data_mode(dsp + bytes); /* Prepare key setup messages */ if (adsi_transmit_message_full(chan, dsp, bytes, ADSI_MSG_DISPLAY, 0)) return -1; if (app) { res = ast_readstring(chan, resp, 1, 1200, 1200, ""); if (res < 0) return -1; if (res) { ast_log(LOG_DEBUG, "No response from CPE about version. Assuming not there.\n"); return 0; } if (!strcmp(resp, "B")) { ast_log(LOG_DEBUG, "CPE has script '%s' version %d already loaded\n", app, ver); return 1; } else if (!strcmp(resp, "A")) { ast_log(LOG_DEBUG, "CPE hasn't script '%s' version %d already loaded\n", app, ver); } else { ast_log(LOG_WARNING, "Unexpected CPE response to script query: %s\n", resp); } } else return 1; return 0; }
static int adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *height, int *buttons, int voice) { unsigned char buf[256] = ""; int bytes = 0, res; bytes += adsi_data_mode(buf); adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0); bytes = 0; bytes += adsi_query_cpeinfo(buf); adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0); /* Get width */ if ((res = ast_readstring(chan, (char *) buf, 2, 1000, 500, "")) < 0) { return res; } if (strlen((char *) buf) != 2) { ast_log(LOG_WARNING, "Got %d bytes of width, expecting 2\n", res); res = 0; } else { res = 1; } if (width) { *width = atoi((char *) buf); } /* Get height */ memset(buf, 0, sizeof(buf)); if (res) { if ((res = ast_readstring(chan, (char *) buf, 2, 1000, 500, "")) < 0) { return res; } if (strlen((char *) buf) != 2) { ast_log(LOG_WARNING, "Got %d bytes of height, expecting 2\n", res); res = 0; } else { res = 1; } if (height) { *height = atoi((char *) buf); } } /* Get buttons */ memset(buf, 0, sizeof(buf)); if (res) { if ((res = ast_readstring(chan, (char *) buf, 1, 1000, 500, "")) < 0) { return res; } if (strlen((char *) buf) != 1) { ast_log(LOG_WARNING, "Got %d bytes of buttons, expecting 1\n", res); res = 0; } else { res = 1; } if (buttons) { *buttons = atoi((char *) buf); } } if (voice) { bytes = 0; bytes += adsi_voice_mode(buf, 0); adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0); /* Ignore the resulting DTMF B announcing it's in voice mode */ ast_waitfordigit(chan, 1000); } return res; }
static int adsi_transmit_message(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype) { return adsi_transmit_message_full(chan, msg, msglen, msgtype, 1); }