コード例 #1
0
ファイル: zaptel.c プロジェクト: commshare/squeezeterisk
int setdevname_zaptel(const char *cp)
{
    int ret;
    int chan;

    /* If already set, forgoe */
    if (strlen(devnam))
	return 1;


    if (strcmp(cp, "stdin")) {
	ret = sscanf(cp, "%d", &chan);
	if (ret != 1) {
		fatal("Zaptel: Invalid channel: '%s'\n", cp);
		return -1;
	}
    }

    zap_copy_string(devnam, cp, sizeof(devnam));

    info("Using zaptel device '%s'\n", devnam);

    ret = 1;

    if( ret == 1 && the_channel != &zaptel_channel ){

	the_channel = &zaptel_channel;

	modem = 0;

	lcp_allowoptions[0].neg_accompression = 0;
	lcp_wantoptions[0].neg_accompression = 0;

	lcp_allowoptions[0].neg_pcompression = 0;
	lcp_wantoptions[0].neg_pcompression = 0;

	ccp_allowoptions[0].deflate = 0 ;
	ccp_wantoptions[0].deflate = 0 ;

	ipcp_allowoptions[0].neg_vj=0;
	ipcp_wantoptions[0].neg_vj=0;

	ccp_allowoptions[0].bsd_compress = 0;
	ccp_wantoptions[0].bsd_compress = 0;

	lcp_allowoptions[0].neg_asyncmap = 0;
	lcp_wantoptions[0].neg_asyncmap = 0;

    }
    return ret;
}
コード例 #2
0
ファイル: ozmod_wanpipe.c プロジェクト: jart/freeswitch
/**
 * \brief Initialises a range of wanpipe channels
 * \param span Openzap span
 * \param spanno Wanpipe span number
 * \param start Initial wanpipe channel number
 * \param end Final wanpipe channel number
 * \param type Openzap channel type
 * \param name Openzap span name
 * \param number Openzap span number
 * \param cas_bits CAS bits
 * \return number of spans configured
 */
static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, unsigned end, zap_chan_type_t type, char *name, char *number, unsigned char cas_bits)
{
    unsigned configured = 0, x;
#ifdef LIBSANGOMA_VERSION
    sangoma_status_t sangstatus;
    sangoma_wait_obj_t *sangoma_wait_obj;
#endif

    if (type == ZAP_CHAN_TYPE_CAS) {
        zap_log(ZAP_LOG_DEBUG, "Configuring Wanpipe CAS channels with abcd == 0x%X\n", cas_bits);
    }
    for(x = start; x < end; x++) {
        zap_channel_t *chan;
        zap_socket_t sockfd = ZAP_INVALID_SOCKET;
        const char *dtmf = "none";
        if (!strncasecmp(span->name, "smg_prid_nfas", 8) && span->trunk_type == ZAP_TRUNK_T1 && x == 24) {
#ifdef LIBSANGOMA_VERSION
            sockfd = __tdmv_api_open_span_chan(spanno, x);
#else
            zap_log(ZAP_LOG_ERROR, "span %d channel %d cannot be configured as smg_prid_nfas, you need to compile openzap with newer libsangoma\n", spanno, x);
#endif
        } else {
            sockfd = tdmv_api_open_span_chan(spanno, x);
        }

        if (sockfd == ZAP_INVALID_SOCKET) {
            zap_log(ZAP_LOG_ERROR, "Failed to open wanpipe device span %d channel %d\n", spanno, x);
            continue;
        }

        if (zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) {
            wanpipe_tdm_api_t tdm_api;
            memset(&tdm_api, 0, sizeof(tdm_api));
#ifdef LIBSANGOMA_VERSION
            sangstatus = sangoma_wait_obj_create(&sangoma_wait_obj, sockfd, SANGOMA_DEVICE_WAIT_OBJ);
            if (sangstatus != SANG_STATUS_SUCCESS) {
                zap_log(ZAP_LOG_ERROR, "failure create waitable object for s%dc%d\n", spanno, x);
                continue;
            }
            chan->mod_data = sangoma_wait_obj;
#endif

            chan->physical_span_id = spanno;
            chan->physical_chan_id = x;
            chan->rate = 8000;

            if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO || type == ZAP_CHAN_TYPE_B) {
                int err;

                dtmf = "software";

                /* FIXME: Handle Error Condition Check for return code */
                err = sangoma_tdm_get_hw_coding(chan->sockfd, &tdm_api);

                if (tdm_api.wp_tdm_cmd.hw_tdm_coding) {
                    chan->native_codec = chan->effective_codec = ZAP_CODEC_ALAW;
                } else {
                    chan->native_codec = chan->effective_codec = ZAP_CODEC_ULAW;
                }

                err = sangoma_tdm_get_hw_dtmf(chan->sockfd, &tdm_api);
                if (err > 0) {
                    err = sangoma_tdm_enable_dtmf_events(chan->sockfd, &tdm_api);
                    if (err == 0) {
                        zap_channel_set_feature(chan, ZAP_CHANNEL_FEATURE_DTMF_DETECT);
                        dtmf = "hardware";
                    }
                }
            }

#ifdef LIBSANGOMA_VERSION
            if (type == ZAP_CHAN_TYPE_FXS) {
                if (sangoma_tdm_disable_ring_trip_detect_events(chan->sockfd, &tdm_api)) {
                    /* we had problems of on-hook/off-hook detection due to how ring trip events were handled
                     * if this fails, I believe we will still work ok as long as we dont handle them incorrectly */
                    zap_log(ZAP_LOG_WARNING, "Failed to disable ring trip events in channel s%dc%d\n", spanno, x);
                }
            }
#endif
#if 0
            if (type == ZAP_CHAN_TYPE_FXS || type == ZAP_CHAN_TYPE_FXO) {
                /* Enable FLASH/Wink Events */
                int err=sangoma_set_rm_rxflashtime(chan->sockfd, &tdm_api, wp_globals.flash_ms);
                if (err == 0) {
                    zap_log(ZAP_LOG_ERROR, "flash enabled s%dc%d\n", spanno, x);
                } else {
                    zap_log(ZAP_LOG_ERROR, "flash disabled s%dc%d\n", spanno, x);
                }
            }
#endif

            if (type == ZAP_CHAN_TYPE_CAS || type == ZAP_CHAN_TYPE_EM) {
#ifdef LIBSANGOMA_VERSION
                sangoma_tdm_write_rbs(chan->sockfd,&tdm_api,chan->physical_chan_id, wanpipe_swap_bits(cas_bits));

                /* this should probably be done for old libsangoma but I am not sure if the API is available and I'm lazy to check,
                   The poll rate is hard coded to 100 per second (done in the driver, is the max rate of polling allowed by wanpipe)
                 */
                if (sangoma_tdm_enable_rbs_events(chan->sockfd, &tdm_api, 100)) {
                    zap_log(ZAP_LOG_ERROR, "Failed to enable RBS/CAS events in device %d:%d fd:%d\n", chan->span_id, chan->chan_id, sockfd);
                    continue;
                }
                /* probably done by the driver but lets write defensive code this time */
                sangoma_flush_bufs(chan->sockfd, &tdm_api);
#else
                /*
                 * With wanpipe 3.4.4.2 I get failure even though the events are enabled, /var/log/messages said:
                 * wanpipe4: WARNING: Event type 9 is already pending!
                 * wanpipe4: Failed to add new fe event 09 ch_map=FFFFFFFF!
                 * may be we should not send an error until that is fixed in the driver
                 */
                if (sangoma_tdm_enable_rbs_events(chan->sockfd, &tdm_api, 100)) {
                    zap_log(ZAP_LOG_ERROR, "Failed to enable RBS/CAS events in device %d:%d fd:%d\n", chan->span_id, chan->chan_id, sockfd);
                }
                /* probably done by the driver but lets write defensive code this time */
                sangoma_tdm_flush_bufs(chan->sockfd, &tdm_api);
                sangoma_tdm_write_rbs(chan->sockfd,&tdm_api, wanpipe_swap_bits(cas_bits));
#endif
            }

            if (!zap_strlen_zero(name)) {
                zap_copy_string(chan->chan_name, name, sizeof(chan->chan_name));
            }

            if (!zap_strlen_zero(number)) {
                zap_copy_string(chan->chan_number, number, sizeof(chan->chan_number));
            }
            configured++;
            zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d DTMF: %s\n",
                    spanno, x, chan->span_id, chan->chan_id, sockfd, dtmf);

        } else {
            zap_log(ZAP_LOG_ERROR, "zap_span_add_channel failed for wanpipe span %d channel %d\n", spanno, x);
        }
    }

    return configured;
}