int AST_OPTIONAL_API_NAME(ast_adsi_get_cpeid)(struct ast_channel *chan, unsigned char *cpeid, int voice) { unsigned char buf[256] = ""; int bytes = 0, res; bytes += ast_adsi_data_mode(buf); ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0); bytes = 0; bytes += ast_adsi_query_cpeid(buf); ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0); /* Get response */ res = ast_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 += ast_adsi_voice_mode(buf, 0); ast_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 _ast_adsi_get_cpeinfo(struct ast_channel *chan, int *width, int *height, int *buttons, int voice) { unsigned char buf[256] = ""; int bytes = 0, res; bytes += ast_adsi_data_mode(buf); ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DISPLAY, 0); bytes = 0; bytes += ast_adsi_query_cpeinfo(buf); ast_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 += ast_adsi_voice_mode(buf, 0); ast_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 _ast_adsi_load_session(struct ast_channel *chan, unsigned char *app, int ver, int data) { unsigned char dsp[256] = ""; int bytes = 0, res; char resp[2]; /* Connect to session */ bytes += ast_adsi_connect_session(dsp + bytes, app, ver); if (data) bytes += ast_adsi_data_mode(dsp + bytes); /* Prepare key setup messages */ if (ast_adsi_transmit_message_full(chan, dsp, bytes, ADSI_MSG_DISPLAY, 0)) return -1; if (app) { if ((res = ast_readstring(chan, resp, 1, 1200, 1200, "")) < 0) return -1; if (res) { ast_debug(1, "No response from CPE about version. Assuming not there.\n"); return 0; } if (!strcmp(resp, "B")) { ast_debug(1, "CPE has script '%s' version %d already loaded\n", app, ver); return 1; } else if (!strcmp(resp, "A")) { ast_debug(1, "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 _ast_adsi_end_download(struct ast_channel *chan) { int bytes = 0; unsigned char buf[256]; /* Setup the resident soft key stuff, a piece at a time */ /* Upload what scripts we can for voicemail ahead of time */ bytes += ast_adsi_download_disconnect(buf + bytes); if (ast_adsi_transmit_message_full(chan, buf, bytes, ADSI_MSG_DOWNLOAD, 0)) return -1; return 0; }
static int _ast_adsi_unload_session(struct ast_channel *chan) { unsigned char dsp[256] = ""; int bytes = 0; /* Connect to session */ bytes += ast_adsi_disconnect_session(dsp + bytes); bytes += ast_adsi_voice_mode(dsp + bytes, 0); /* Prepare key setup messages */ if (ast_adsi_transmit_message_full(chan, dsp, bytes, ADSI_MSG_DISPLAY, 0)) return -1; return 0; }
static int _ast_adsi_print(struct ast_channel *chan, char **lines, int *aligns, int voice) { unsigned char buf[4096]; int bytes = 0, res, x; for(x = 0; lines[x]; x++) bytes += ast_adsi_display(buf + bytes, ADSI_INFO_PAGE, x+1, aligns[x], 0, lines[x], ""); bytes += ast_adsi_set_line(buf + bytes, ADSI_INFO_PAGE, 1); if (voice) bytes += ast_adsi_voice_mode(buf + bytes, 0); res = ast_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; }
static int _ast_adsi_begin_download(struct ast_channel *chan, char *service, unsigned char *fdn, unsigned char *sec, int version) { int bytes = 0; unsigned char buf[256]; char ack[2]; /* Setup the resident soft key stuff, a piece at a time */ /* Upload what scripts we can for voicemail ahead of time */ bytes += ast_adsi_download_connect(buf + bytes, service, fdn, sec, version); if (ast_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_debug(1, "Download was denied by CPE\n"); return -1; }
static int _ast_adsi_channel_restore(struct ast_channel *chan) { unsigned char dsp[256] = "", keyd[6] = ""; int bytes, x; /* Start with initial display setup */ bytes = 0; bytes += ast_adsi_set_line(dsp + bytes, ADSI_INFO_PAGE, 1); /* Prepare key setup messages */ if (speeds) { for (x = 0; x < speeds; x++) keyd[x] = ADSI_SPEED_DIAL + x; bytes += ast_adsi_set_keys(dsp + bytes, keyd); } ast_adsi_transmit_message_full(chan, dsp, bytes, ADSI_MSG_DISPLAY, 0); return 0; }
int AST_OPTIONAL_API_NAME(ast_adsi_transmit_message)(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype) { return ast_adsi_transmit_message_full(chan, msg, msglen, msgtype, 1); }
static int _ast_adsi_transmit_message(struct ast_channel *chan, unsigned char *msg, int msglen, int msgtype) { return ast_adsi_transmit_message_full(chan, msg, msglen, msgtype, 1); }