Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
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 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 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;
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
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;
}
Ejemplo n.º 11
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;
}
Ejemplo n.º 12
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;
}
Ejemplo n.º 13
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);
}
Ejemplo n.º 15
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;
}
Ejemplo n.º 16
0
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 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;
}
Ejemplo n.º 18
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;
}
Ejemplo n.º 19
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;
}