static int bestdata_break(struct ast_modem_pvt *p) { if (ast_modem_send(p, breakcmd, 2)) { ast_log(LOG_WARNING, "Failed to break\n"); return -1; } p->ministate = STATE_COMMAND; usleep(10000); /* Read any outstanding junk */ while(!ast_modem_read_response(p, 1)); if (ast_modem_send(p, "AT", 0)) { /* Modem might be stuck in some weird mode, try to get it out */ ast_modem_send(p, "+++", 3); if (ast_modem_expect(p, "OK", 10)) { ast_log(LOG_WARNING, "Modem is not responding\n"); return -1; } if (ast_modem_send(p, "AT", 0)) { ast_log(LOG_WARNING, "Modem is not responding\n"); return -1; } } if (ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Modem did not respond properly\n"); return -1; } return 0; }
static int i4l_break(struct ast_modem_pvt *p) { if (ast_modem_send(p, breakcmd, 2)) { ast_log(LOG_WARNING, "Failed to break\n"); return -1; } if (ast_modem_send(p, "\r\n", 2)) { ast_log(LOG_WARNING, "Failed to send enter?\n"); return -1; } #if 0 /* Read any outstanding junk */ while(!ast_modem_read_response(p, 1)); #endif if (ast_modem_send(p, "AT", 0)) { /* Modem might be stuck in some weird mode, try to get it out */ ast_modem_send(p, "+++", 3); if (ast_modem_expect(p, "OK", 10)) { ast_log(LOG_WARNING, "Modem is not responding\n"); return -1; } if (ast_modem_send(p, "AT", 0)) { ast_log(LOG_WARNING, "Modem is not responding\n"); return -1; } } if (ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Modem did not respond properly\n"); return -1; } return 0; }
static int i4l_dial(struct ast_modem_pvt *p, char *stuff) { char cmd[80]; char tmpmsn[255]; struct ast_channel *c = p->owner; /* Find callerid number first, to set the correct A number */ if (c && c->cid.cid_num && !(c->cid.cid_pres & 0x20)) { snprintf(tmpmsn, sizeof(tmpmsn), ",%s,", c->cid.cid_num); if(!ast_strlen_zero(p->outgoingmsn) && strstr(p->outgoingmsn,tmpmsn) != NULL) { /* Tell ISDN4Linux to use this as A number */ snprintf(cmd, sizeof(cmd), "AT&E%s\n", c->cid.cid_num); if (ast_modem_send(p, cmd, strlen(cmd))) { ast_log(LOG_WARNING, "Unable to set A number to %s\n", c->cid.cid_num); } } else { ast_log(LOG_WARNING, "Outgoing MSN %s not allowed (see outgoingmsn=%s in modem.conf)\n",c->cid.cid_num,p->outgoingmsn); } } snprintf(cmd, sizeof(cmd), "ATD%c %s\n", p->dialtype,stuff); if (ast_modem_send(p, cmd, strlen(cmd))) { ast_log(LOG_WARNING, "Unable to dial\n"); return -1; } return 0; }
static int i4l_startrec(struct ast_modem_pvt *p) { if (ast_modem_send(p, "AT+VRX+VTX", 0) || ast_modem_expect(p, "CONNECT", 5)) { ast_log(LOG_WARNING, "Unable to start recording\n"); return -1; } p->ministate = STATE_VOICE; /* let ast dsp detect dtmf */ if (p->dtmfmode & MODEM_DTMF_AST) { if (p->dsp) { ast_log(LOG_DEBUG, "Already have a dsp on %s?\n", p->dev); } else { p->dsp = ast_dsp_new(); if (p->dsp) { ast_log(LOG_DEBUG, "Detecting DTMF inband with sw DSP on %s\n",p->dev); ast_dsp_set_features(p->dsp, DSP_FEATURE_DTMF_DETECT|DSP_FEATURE_FAX_DETECT); ast_dsp_digitmode(p->dsp, DSP_DIGITMODE_DTMF | 0); } } } return 0; }
static int aopen_hangup(struct ast_modem_pvt *p) { if (aopen_break(p)) return -1; /* Hangup by switching to data, then back to voice */ if (ast_modem_send(p, "ATH", 0) || ast_modem_expect(p, "OK", 8)) { ast_log(LOG_WARNING, "Unable to set to data mode\n"); return -1; } if (ast_modem_send(p, "AT#CLS=8", 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set to voice mode\n"); return -1; } return 0; }
static struct ast_frame *aopen_handle_escape(struct ast_modem_pvt *p, char esc) { /* Handle escaped characters -- but sometimes we call it directly as a quick way to cause known responses */ p->fr.frametype = AST_FRAME_NULL; p->fr.subclass = 0; p->fr.data = NULL; p->fr.datalen = 0; p->fr.samples = 0; p->fr.offset = 0; p->fr.mallocd = 0; p->fr.delivery.tv_sec = 0; p->fr.delivery.tv_usec = 0; if (esc) ast_log(LOG_DEBUG, "Escaped character '%c'\n", esc); switch(esc) { case 'R': /* Pseudo ring */ p->fr.frametype = AST_FRAME_CONTROL; p->fr.subclass = AST_CONTROL_RING; return &p->fr; case 'X': /* Pseudo connect */ p->fr.frametype = AST_FRAME_CONTROL; p->fr.subclass = AST_CONTROL_RING; if (p->owner) ast_setstate(p->owner, AST_STATE_UP); if (aopen_startrec(p)) return NULL; return &p->fr; case 'b': /* Busy signal */ p->fr.frametype = AST_FRAME_CONTROL; p->fr.subclass = AST_CONTROL_BUSY; return &p->fr; case 'o': /* Overrun */ ast_log(LOG_WARNING, "Overflow on modem, flushing buffers\n"); if (ast_modem_send(p, "\0x10E", 2)) ast_log(LOG_WARNING, "Unable to flush buffers\n"); return &p->fr; case 'u': /* Underrun */ ast_log(LOG_WARNING, "Data underrun\n"); /* Fall Through */ case CHAR_ETX: /* End Transmission */ case 'd': /* Dialtone */ case 'c': /* Calling Tone */ case 'e': /* European version */ case 'a': /* Answer Tone */ case 'f': /* Bell Answer Tone */ case 'T': /* Timing mark */ case 't': /* Handset off hook */ case 'h': /* Handset hungup */ case 0: /* Pseudo signal */ /* Ignore */ return &p->fr; default: ast_log(LOG_DEBUG, "Unknown Escaped character '%c' (%d)\n", esc, esc); } return &p->fr; }
static int aopen_answer(struct ast_modem_pvt *p) { if (ast_modem_send(p, "ATA", 0) || ast_modem_expect(p, "VCON", 10)) { ast_log(LOG_WARNING, "Unable to answer: %s", p->response); return -1; } return 0; }
static int aopen_startrec(struct ast_modem_pvt *p) { if (ast_modem_send(p, "AT#VRX", 0) || ast_modem_expect(p, "CONNECT", 5)) { ast_log(LOG_WARNING, "Unable to start recording\n"); return -1; } p->ministate = STATE_VOICE; return 0; }
static int i4l_setdev(struct ast_modem_pvt *p, int dev) { char cmd[80]; if ((dev != MODEM_DEV_TELCO) && (dev != MODEM_DEV_TELCO_SPK)) { ast_log(LOG_WARNING, "ISDN4Linux only supports telco device, not %d.\n", dev); return -1; } else /* Convert DEV to our understanding of it */ dev = 2; if (ast_modem_send(p, "AT+VLS?", 0)) { ast_log(LOG_WARNING, "Unable to select current mode %d\n", dev); return -1; } if (ast_modem_read_response(p, 5)) { ast_log(LOG_WARNING, "Unable to select device %d\n", dev); return -1; } ast_modem_trim(p->response); strncpy(cmd, p->response, sizeof(cmd)-1); if (ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Modem did not respond properly\n"); return -1; } if (dev == atoi(cmd)) { /* We're already in the right mode, don't bother changing for fear of hanging up */ return 0; } snprintf(cmd, sizeof(cmd), "AT+VLS=%d", dev); if (ast_modem_send(p, cmd, 0)) { ast_log(LOG_WARNING, "Unable to select device %d\n", dev); return -1; } if (ast_modem_read_response(p, 5)) { ast_log(LOG_WARNING, "Unable to select device %d\n", dev); return -1; } ast_modem_trim(p->response); if (strcasecmp(p->response, "VCON") && strcasecmp(p->response, "OK")) { ast_log(LOG_WARNING, "Unexpected reply: %s\n", p->response); return -1; } return 0; }
static int aopen_dial(struct ast_modem_pvt *p, char *stuff) { char cmd[80]; snprintf(cmd, sizeof(cmd), "ATD%c %s", p->dialtype,stuff); if (ast_modem_send(p, cmd, 0)) { ast_log(LOG_WARNING, "Unable to dial\n"); return -1; } return 0; }
static int bestdata_answer(struct ast_modem_pvt *p) { p->ringt = 0; p->lastring = 0; if (ast_modem_send(p, "AT+VLS=1", 0) || ast_modem_expect(p, "OK", 10)) { ast_log(LOG_WARNING, "Unable to answer: %s", p->response); return -1; } return 0; }
static int aopen_dialdigit(struct ast_modem_pvt *p, char digit) { char cmd[80]; snprintf(cmd, sizeof(cmd), "AT#VTS=%c", digit); if (ast_modem_send(p, cmd, 0) || ast_modem_expect(p, "VCON", 10)) { ast_log(LOG_WARNING, "Unable to answer: %s", p->response); return -1; } return 0; }
static int bestdata_startplay(struct ast_modem_pvt *p) { if (p->ministate != STATE_COMMAND) bestdata_break(p); if (ast_modem_send(p, "AT+VTX", 0) || ast_modem_expect(p, "CONNECT", 5)) { ast_log(LOG_WARNING, "Unable to start recording\n"); return -1; } p->ministate = STATE_VOICEPLAY; return 0; }
static int aopen_init(struct ast_modem_pvt *p) { if (option_debug) ast_log(LOG_DEBUG, "aopen_init()\n"); if (aopen_break(p)) return -1; /* Force into command mode */ p->ministate = STATE_COMMAND; if (ast_modem_send(p, "AT#BDR=0", 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set to auto-baud\n"); return -1; } if (ast_modem_send(p, "AT#CLS=8", 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set to voice mode\n"); return -1; } if (ast_modem_send(p, "AT#VBS=8", 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set to 8-bit mode\n"); return -1; } if (ast_modem_send(p, "AT#VSR=8000", 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set to 8000 Hz sampling\n"); return -1; } if (ast_modem_send(p, "AT#VLS=0", 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set to telco interface\n"); return -1; } if (ast_modem_send(p, "AT#VRA=" VRA, 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set to 'ringback goes away' timer\n"); return -1; } if (ast_modem_send(p, "AT#VRN=" VRN, 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set to 'ringback never came timer'\n"); return -1; } if (ast_modem_send(p, "AT#VTD=3F,3F,3F", 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set to tone detection\n"); return -1; } return 0; }
static int bestdata_hangup(struct ast_modem_pvt *p) { if (bestdata_break(p)) return -1; /* Hangup by switching to data, then back to voice */ if (ast_modem_send(p, "ATH", 0) || ast_modem_expect(p, "OK", 8)) { ast_log(LOG_WARNING, "Unable to set to data mode\n"); return -1; } if (ast_modem_send(p, "AT+FCLASS=8", 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set to voice mode\n"); return -1; } p->gotclid = 0; p->ringt = 0; p->lastring = 0; p->dtmfrx = 0; return 0; }
static int bestdata_dialdigit(struct ast_modem_pvt *p, char digit) { char cmd[80]; if (p->ministate != STATE_COMMAND) bestdata_break(p); snprintf(cmd, sizeof(cmd), "AT+VTS=%c", digit); if (ast_modem_send(p, cmd, 0) || ast_modem_expect(p, "OK", 10)) { ast_log(LOG_WARNING, "Unable to answer: %s", p->response); return -1; } return 0; }
static int aopen_setdev(struct ast_modem_pvt *p, int dev) { char cmd[80]; if (ast_modem_send(p, "AT#VLS?", 0)) { ast_log(LOG_WARNING, "Unable to select current mode %d\n", dev); return -1; } if (ast_modem_read_response(p, 5)) { ast_log(LOG_WARNING, "Unable to select device %d\n", dev); return -1; } ast_modem_trim(p->response); strncpy(cmd, p->response, sizeof(cmd)-1); if (ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Modem did not respond properly\n"); return -1; } if (dev == atoi(cmd)) { /* We're already in the right mode, don't bother changing for fear of hanging up */ return 0; } snprintf(cmd, sizeof(cmd), "AT#VLS=%d", dev); if (ast_modem_send(p, cmd, 0)) { ast_log(LOG_WARNING, "Unable to select device %d\n", dev); return -1; } if (ast_modem_read_response(p, 5)) { ast_log(LOG_WARNING, "Unable to select device %d\n", dev); return -1; } ast_modem_trim(p->response); if (strcasecmp(p->response, "VCON") && strcasecmp(p->response, "OK")) { ast_log(LOG_WARNING, "Unexpected reply: %s\n", p->response); return -1; } return 0; }
static int i4l_answer(struct ast_modem_pvt *p) { if (ast_modem_send(p, "ATA\r", 4) || ast_modem_expect(p, "VCON", 10)) { ast_log(LOG_WARNING, "Unable to answer: %s", p->response); return -1; } #if 1 if (ast_modem_send(p, "AT+VDD=0,8", 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set to phone line interface\n"); return -1; } #endif if (ast_modem_send(p, "AT+VTX+VRX", 0) || ast_modem_expect(p, "CONNECT", 10)) { ast_log(LOG_WARNING, "Unable to answer: %s", p->response); return -1; } p->ministate = STATE_VOICE; /* let ast dsp detect dtmf */ if (p->dtmfmode & MODEM_DTMF_AST) { if (p->dsp) { ast_log(LOG_DEBUG, "Already have a dsp on %s?\n", p->dev); } else { p->dsp = ast_dsp_new(); if (p->dsp) { ast_log(LOG_DEBUG, "Detecting DTMF inband with sw DSP on %s\n",p->dev); ast_dsp_set_features(p->dsp, DSP_FEATURE_DTMF_DETECT|DSP_FEATURE_FAX_DETECT); ast_dsp_digitmode(p->dsp, DSP_DIGITMODE_DTMF | 0); } } } return 0; }
static char *aopen_identify(struct ast_modem_pvt *p) { char identity[256]; char mfr[80]; char mdl[80]; char rev[80]; ast_modem_send(p, "AT#MDL?", 0); ast_modem_read_response(p, 5); strncpy(mdl, p->response, sizeof(mdl)-1); ast_modem_trim(mdl); ast_modem_expect(p, "OK", 5); ast_modem_send(p, "AT#MFR?", 0); ast_modem_read_response(p, 5); strncpy(mfr, p->response, sizeof(mfr)-1); ast_modem_trim(mfr); ast_modem_expect(p, "OK", 5); ast_modem_send(p, "AT#REV?", 0); ast_modem_read_response(p, 5); strncpy(rev, p->response, sizeof(rev)-1); ast_modem_trim(rev); ast_modem_expect(p, "OK", 5); snprintf(identity, sizeof(identity), "%s Model %s Revision %s", mfr, mdl, rev); return strdup(identity); }
static int bestdata_init(struct ast_modem_pvt *p) { if (option_debug) ast_log(LOG_DEBUG, "bestdata_init()\n"); if (bestdata_break(p)) return -1; /* Force into command mode */ p->ministate = STATE_COMMAND; if (ast_modem_send(p, "AT+FCLASS=8", 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set to voice mode\n"); return -1; } if (ast_modem_send(p, "AT+VSM=1,8000,0,0", 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set to 8000 Hz sampling\n"); return -1; } if (ast_modem_send(p, "AT+VLS=0", 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set to telco interface\n"); return -1; } if (ast_modem_send(p, "AT+VRA=" VRA, 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set to 'ringback goes away' timer\n"); return -1; } if (ast_modem_send(p, "AT+VRN=" VRN, 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set to 'ringback never came timer'\n"); return -1; } if (ast_modem_send(p, "AT+VTD=63", 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set to tone detection\n"); return -1; } if (ast_modem_send(p, "AT+VCID=1", 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to enable Caller*ID\n"); return -1; } return 0; }
static int bestdata_dial(struct ast_modem_pvt *p, char *stuff) { char cmd[800] = "",a[20]=""; int i,j; if (p->ministate != STATE_COMMAND) { bestdata_break(p); strncpy(cmd, "AT+VTS=", sizeof(cmd) - 1); j = strlen(cmd); for(i = 0; stuff[i]; i++) { switch(stuff[i]) { case '!' : a[0] = stuff[i]; a[1] = 0; break; case ',': strncpy(a, "[,,100]", sizeof(a) - 1); break; default: snprintf(a, sizeof(a), "{%c,7}", stuff[i]); } if (stuff[i + 1]) strncat(a, ",", sizeof(a) - strlen(a) - 1); strncpy(cmd + j, a, sizeof(cmd) - j - 1); j += strlen(a); } } else { snprintf(cmd, sizeof(cmd), "ATD%c %s", p->dialtype,stuff); } if (ast_modem_send(p, cmd, 0)) { ast_log(LOG_WARNING, "Unable to dial\n"); return -1; } return 0; }
static int i4l_hangup(struct ast_modem_pvt *p) { char dummy[50]; int dtr = TIOCM_DTR; /* free the memory used by the DSP */ if (p->dsp) { ast_dsp_free(p->dsp); p->dsp = NULL; } /* down DTR to hangup modem */ ioctl(p->fd, TIOCMBIC, &dtr); /* Read anything outstanding */ while(read(p->fd, dummy, sizeof(dummy)) > 0); /* rise DTR to re-enable line */ ioctl(p->fd, TIOCMBIS, &dtr); /* Read anything outstanding */ while(read(p->fd, dummy, sizeof(dummy)) > 0); /* basically we're done, just to be sure */ write(p->fd, "\n\n", 2); read(p->fd, dummy, sizeof(dummy)); if (ast_modem_send(p, "ATH", 0)) { ast_log(LOG_WARNING, "Unable to hang up\n"); return -1; } if (ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Final 'OK' not received\n"); return -1; } return 0; }
static int i4l_init(struct ast_modem_pvt *p) { char cmd[256]; if (option_debug) ast_log(LOG_DEBUG, "i4l_init()\n"); if (i4l_break(p)) return -1; /* Force into command mode */ p->ministate = STATE_COMMAND; if (ast_modem_send(p, "AT+FCLASS=8", 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set to voice mode\n"); return -1; } if (!ast_strlen_zero(p->msn)) { snprintf(cmd, sizeof(cmd), "AT&E%s", p->msn); if (ast_modem_send(p, cmd, 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set MSN to %s\n", p->msn); return -1; } } if (!ast_strlen_zero(p->incomingmsn)) { char *q; snprintf(cmd, sizeof(cmd), "AT&L%s", p->incomingmsn); /* translate , into ; since that is the seperator I4L uses, but can't be directly */ /* put in the config file because it will interpret the rest of the line as comment. */ q = cmd+4; while (*q) { if (*q == ',') *q = ';'; ++q; } if (ast_modem_send(p, cmd, 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set Listen to %s\n", p->msn); return -1; } } if (ast_modem_send(p, "AT&D2", 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set to DTR disconnect mode\n"); return -1; } if (ast_modem_send(p, "ATS18=1", 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set to audio only mode\n"); return -1; } if (ast_modem_send(p, "ATS13.6=1", 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set to RUNG indication\n"); return -1; } if (ast_modem_send(p, "ATS14=4", 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set to transparent mode\n"); return -1; } if (ast_modem_send(p, "ATS23=9", 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set to transparent/ringing mode\n"); return -1; } if (ast_modem_send(p, "AT+VSM=6", 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set to muLAW mode\n"); return -1; } if (ast_modem_send(p, "AT+VLS=2", 0) || ast_modem_expect(p, "OK", 5)) { ast_log(LOG_WARNING, "Unable to set to phone line interface\n"); return -1; } p->escape = 0; return 0; }
static struct ast_frame *bestdata_handle_escape(struct ast_modem_pvt *p, char esc) { char name[30]="",nmbr[30]=""; time_t now; /* Handle escaped characters -- but sometimes we call it directly as a quick way to cause known responses */ p->fr.frametype = AST_FRAME_NULL; p->fr.subclass = 0; p->fr.data = NULL; p->fr.datalen = 0; p->fr.samples = 0; p->fr.offset = 0; p->fr.mallocd = 0; p->fr.delivery.tv_sec = 0; p->fr.delivery.tv_usec = 0; if (esc) ast_log(LOG_DEBUG, "Escaped character '%c'\n", esc); switch(esc) { case 'R': /* Pseudo ring */ time(&now); if (now > (p->lastring + (RINGT / 1000))) { /* if stale, treat as new */ p->gotclid = 0; } if (p->gotclid) { p->fr.frametype = AST_FRAME_CONTROL; p->fr.subclass = AST_CONTROL_RING; } p->ringt = RINGT; time(&p->lastring); return &p->fr; case 'X': /* Caller-ID Spill */ if (p->gotclid) return &p->fr; name[0] = nmbr[0] = 0; for(;;) { char res[1000]=""; if (ast_modem_read_response(p, 5)) break; strncpy(res, p->response, sizeof(res)-1); ast_modem_trim(res); if (!strncmp(res,"\020.",2)) break; if (!strncmp(res,"NAME",4)) strncpy(name,res + 7, sizeof(name) - 1); if (!strncmp(res,"NMBR",4)) strncpy(nmbr,res + 7, sizeof(nmbr) - 1); } p->gotclid = 1; if ((!strcmp(name,"O")) || (!strcmp(name,"P"))) name[0] = 0; if ((!strcmp(nmbr,"O")) || (!strcmp(nmbr,"P"))) nmbr[0] = 0; if ((name[0]) && (nmbr[0])) snprintf(p->cid,sizeof(p->cid), "\"%s\" <%s>",name,nmbr); else if (name[0]) snprintf(p->cid,sizeof(p->cid), "\"%s\"",name); else if (nmbr[0]) snprintf(p->cid,sizeof(p->cid), "%s",nmbr); if (p->owner) p->owner->callerid = strdup(p->cid); return &p->fr; case '@': /* response from "OK" in command mode */ if (p->owner) ast_setstate(p->owner, AST_STATE_UP); if (bestdata_startrec(p)) return NULL; p->fr.frametype = AST_FRAME_CONTROL; p->fr.subclass = AST_CONTROL_RING; return &p->fr; case 'b': /* Busy signal */ p->fr.frametype = AST_FRAME_CONTROL; p->fr.subclass = AST_CONTROL_BUSY; return &p->fr; case 'o': /* Overrun */ ast_log(LOG_WARNING, "Overflow on modem, flushing buffers\n"); if (ast_modem_send(p, "\0x10E", 2)) ast_log(LOG_WARNING, "Unable to flush buffers\n"); return &p->fr; case '0': /* All the DTMF characters */ case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '*': case '#': case 'A': case 'B': case 'C': case 'D': p->dtmfrx = esc; /* save this for when its done */ return &p->fr; case '/': /* Start of DTMF tone shielding */ p->dtmfrx = ' '; return &p->fr; case '~': /* DTMF transition to off */ if (p->dtmfrx > ' ') { p->fr.frametype = AST_FRAME_DTMF; p->fr.subclass = p->dtmfrx; } p->dtmfrx = 0; return &p->fr; case 'u': /* Underrun */ ast_log(LOG_WARNING, "Data underrun\n"); /* Fall Through */ case CHAR_ETX: /* End Transmission */ case 'd': /* Dialtone */ case 'c': /* Calling Tone */ case 'e': /* European version */ case 'a': /* Answer Tone */ case 'f': /* Bell Answer Tone */ case 'T': /* Timing mark */ case 't': /* Handset off hook */ case 'h': /* Handset hungup */ case 0: /* Pseudo signal */ /* Ignore */ return &p->fr; default: ast_log(LOG_DEBUG, "Unknown Escaped character '%c' (%d)\n", esc, esc); } return &p->fr; }