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; }
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; }