Esempio n. 1
0
int SdtpClent::sendData(unsigned char *buffer, int lenth)
{
	/*int len = 0;
	int totalLen = lenth;
	unsigned char *buf = buffer;

	pkthdr_set_plen((pkt_hdr*)buffer, lenth);*/

	if (adapter_ && buffer)
	{
		adapter_write(adapter_, buffer, lenth);
	}

	//++(adap_out.pkts);
	//adap_out.bytes += totalLen;

	/*while (totalLen > 0)
	{
	len = adapter_write(adapter_, buf, totalLen);
	if ( len < 0)
	{
	SLEEP_MS(5);
	continue;
	}

	totalLen -= len;
	buf = buf + len;
	}*/

	return 0;
}
Esempio n. 2
0
void MergeXdr::sendData()
{
	//int len = 0;
	int totalLen = bufLen_;
	unsigned char *buf = buffer_;

	pkthdr_set_plen((pkt_hdr*)buffer_, bufLen_);
	pkthdr_set_sync((pkt_hdr*)buffer_);
	pkthdr_set_type((pkt_hdr*)buffer_, PKTTYPE_XDR);


	if (NULL == adap_out.adap)
	{
		LOGERROR("MergeXdr : sendData sdtp_client is null");
		return;
	}

	++(adap_out.pkts);
	adap_out.bytes += totalLen;

	adapter_write(adap_out.adap, buf, totalLen);

	/*while (totalLen > 0)
	{
	len = adapter_write(adap_out.adap, buf, totalLen);
	if ( len < 0)
	{
	SLEEP_MS(5);
	continue;
	}

	totalLen -= len;
	buf = buf + len;
	}*/
}
Esempio n. 3
0
static int itf_sd_run(long argc, unsigned long data)
{
	pkt_hdr *ph = NULL;
	Pkt rec;
	struct pktrec tmp;
	int i = 0;

	if (itf_sd_init() < 0) {
		itf_sd_exit();
		return -1;
	}

	while (ap_is_running()) {
		if (++i == 5000) {
			timer_mgr_run_timerlist(NULL, g_timer, 0, 0);
			i = 0;
		}
		if ((ph = ReadDbus()) == NULL) {
			SLEEP_US(5000);
			continue;
		}

		if ((pkthdr_get_type(ph) != PKTTYPE_CDR) &&
				(pkthdr_get_type(ph) != PKTTYPE_EVENT)) {
			LGWRERROR(ph, pkthdr_get_plen(ph), "Wrong cdr received, type %u, subtype %u.",
					pkthdr_get_type(ph), pkthdr_get_subtype(ph));
			free(ph);
			continue;
		}
		if ((pkthdr_get_subtype(ph) != PKTTYPE_CDR_BSSAP /* PKTTYPE_EVENT_BSSAP */) &&
				(pkthdr_get_subtype(ph) != PKTTYPE_CDR_IUCS /* PKTTYPE_EVENT_IUCS */)) {
			LGWRERROR(ph, pkthdr_get_plen(ph), "Wrong subtype of cdr/event");
			free(ph);
			continue;
		}
		if (rec.Decode((char *)ph, pkthdr_get_plen(ph)) < 0) {
			LGWRERROR(ph, pkthdr_get_plen(ph), "Failed to decode packet:");
			free(ph);
			continue;
		}

		++g_recieve_msg;
		tmp.rec = (Pkt *)&rec;
		pkthdr_set_sync(&(tmp.hdr));
		pkthdr_set_ts(&(tmp.hdr), rec.u32ReportTimeS, rec.u32ReportTimeNS);

		switch (rec.u8Type)
		{
		case PKTTYPE_CDR:
			if (rec.tdata.cdrbssap.u16LAC == 0) {
				std::map<unsigned int, unsigned int>::iterator it;

				it = ci2lac.find((unsigned int)rec.tdata.cdrbssap.u16CI);
				if (it != ci2lac.end()) {
					rec.tdata.cdrbssap.u16LAC = it->second;
					LOGDEBUG("LAC updated to %u for CI %u",
							it->second, it->first);
				}
				else {
					LOGDEBUG("LAC unknown for CI %u", rec.tdata.cdrbssap.u16CI);
				}
			}
			switch (rec.tdata.cdrbssap.u8CDRType) {
				case 1:
				case 2:
					/* 通话 */
					adapter_write(call_adap_to, &tmp, sizeof(rec));
					++g_call_msg;
					break;
				case 4:
				case 5:
					/* 开关机 */
					++g_power_msg;
					adapter_write(power_adap_to, &tmp, sizeof(rec));
					break;
				case 6:
				case 7:
					/* 正常/周期位置更新 */
					++g_location_msg;
					adapter_write(location_adap_to, &tmp, sizeof(rec));
					break;
				case 12:
				case 13:
					/* SMS */
					++g_sms_msg;
					adapter_write(sms_adap_to, &tmp, sizeof(rec));
					break;
			}
			break;

		case PKTTYPE_EVENT:
			if (rec.tdata.eventbssap.u16FromLAC == 0) {
				std::map<unsigned int, unsigned int>::iterator it;

				it = ci2lac.find((unsigned int)rec.tdata.eventbssap.u16ToCI);
				if (it != ci2lac.end()) {
					rec.tdata.eventbssap.u16FromLAC = it->second;
					LOGDEBUG("LAC updated to %u for CI %u",
							it->second, it->first);
				}
				else {
					LOGDEBUG("LAC unknown for CI %u", rec.tdata.eventbssap.u16ToCI);
				}
			}
			switch (rec.u8Protocol) {
				case 1:
				case 2:
					/* 内部切换事件及成功切出事件 */
					++g_switch_msg;
					adapter_write(switch_adap_to, &tmp, sizeof(rec));
					break;
				default:
					break;
			}
			break;

		default:
			LOGERROR("Unknown subtype %u", pkthdr_get_subtype(ph));
			break;
		}

		free(ph);
	}

	TimerCallback(0, 0, NULL, NULL);
	itf_sd_exit();
	return 0;
}
Esempio n. 4
0
/**
 * Write zone to output adapter.
 *
 */
ods_status
tools_output(zone_type* zone, engine_type* engine)
{
    ods_status status = ODS_STATUS_OK;
    ods_log_assert(engine);
    ods_log_assert(engine->config);
    ods_log_assert(zone);
    ods_log_assert(zone->db);
    ods_log_assert(zone->name);
    ods_log_assert(zone->signconf);
    ods_log_assert(zone->adoutbound);
    /* prepare */
    if (zone->stats) {
        pthread_mutex_lock(&zone->stats->stats_lock);
        if (zone->stats->sort_done == 0 &&
            (zone->stats->sig_count <= zone->stats->sig_soa_count)) {
            ods_log_verbose("[%s] skip write zone %s serial %u (zone not "
                "changed)", tools_str, zone->name?zone->name:"(null)",
                zone->db->intserial);
            stats_clear(zone->stats);
            pthread_mutex_unlock(&zone->stats->stats_lock);
            zone->db->intserial =
                zone->db->outserial;
            return ODS_STATUS_OK;
        }
        pthread_mutex_unlock(&zone->stats->stats_lock);
    }
    /* Output Adapter */
    status = adapter_write((void*)zone);
    if (status != ODS_STATUS_OK) {
        ods_log_error("[%s] unable to write zone %s: adapter failed (%s)",
            tools_str, zone->name, ods_status2str(status));
        return status;
    }
    zone->db->outserial = zone->db->intserial;
    zone->db->is_initialized = 1;
    zone->db->have_serial = 1;
    pthread_mutex_lock(&zone->ixfr->ixfr_lock);
    ixfr_purge(zone->ixfr, zone->name);
    pthread_mutex_unlock(&zone->ixfr->ixfr_lock);
    /* kick the nameserver */
    if (zone->notify_ns) {
	int pid_status;
        pid_t pid, wpid;
        ods_log_verbose("[%s] notify nameserver: %s", tools_str,
            zone->notify_ns);
	/** fork */
        switch ((pid = fork())) {
            case -1: /* error */
                ods_log_error("[%s] notify nameserver failed: unable to fork "
                    "(%s)", tools_str, strerror(errno));
                return ODS_STATUS_FORK_ERR;
            case 0: /* child */
                /** close fds */
		ods_closeall(0);
                /** execv */
                execvp(zone->notify_ns, zone->notify_args);
                /** error */
                ods_log_error("[%s] notify nameserver failed: execv() failed "
                    "(%s)", tools_str, strerror(errno));
                exit(1);
                break;
            default: /* parent */
                ods_log_debug("[%s] notify nameserver process forked",
                    tools_str);
                /** wait for completion  */
                while((wpid = waitpid(pid, &pid_status, 0)) <= 0) {
                    if (errno != EINTR) {
                        break;
                    }
                }
                if (wpid == -1) {
                    ods_log_error("[%s] notify nameserver failed: waitpid() "
                        "failed (%s)", tools_str, strerror(errno));
                } else if (!WIFEXITED(pid_status)) {
                    ods_log_error("[%s] notify nameserver failed: notify "
                        "command did not terminate normally", tools_str);
                } else {
                    ods_log_verbose("[%s] notify nameserver ok", tools_str);
                }
                break;
        }
    }
    /* log stats */
    if (zone->stats) {
        pthread_mutex_lock(&zone->stats->stats_lock);
        zone->stats->end_time = time(NULL);
        ods_log_debug("[%s] log stats for zone %s serial %u", tools_str,
            zone->name?zone->name:"(null)", (unsigned) zone->db->outserial);
        stats_log(zone->stats, zone->name, zone->db->outserial,
            zone->signconf->nsec_type);
        stats_clear(zone->stats);
        pthread_mutex_unlock(&zone->stats->stats_lock);
    }
    if (engine->dnshandler) {
        ods_log_debug("[%s] forward a notify", tools_str);
        dnshandler_fwd_notify(engine->dnshandler, (uint8_t*) ODS_SE_NOTIFY_CMD,
            strlen(ODS_SE_NOTIFY_CMD));
    }
    return status;
}