Beispiel #1
0
void print_mem(void)
{
    oncli_send_msg("Heap Entry\n");
    xdump((UInt8*) &heap_entry[0], sizeof(heap_entry));
    oncli_send_msg("Heap Buffer\n");
    xdump((UInt8*) &heap_buffer[0], ONE_NET_HEAP_SIZE);
}
Beispiel #2
0
static int
_do_madrpc(int port_id, void *sndbuf, void *rcvbuf, int agentid, int len,
	   int timeout)
{
	uint32_t trid; /* only low 32 bits */
	int retries;
	int length, status;

	if (!timeout)
		timeout = def_madrpc_timeout;

	if (ibdebug > 1) {
		IBWARN(">>> sending: len %d pktsz %zu", len, umad_size() + len);
		xdump(stderr, "send buf\n", sndbuf, umad_size() + len);
	}

	if (save_mad) {
		memcpy(save_mad, umad_get_mad(sndbuf),
		       save_mad_len < len ? save_mad_len : len);
		save_mad = 0;
	}

	trid = mad_get_field64(umad_get_mad(sndbuf), 0, IB_MAD_TRID_F);

	for (retries = 0; retries < madrpc_retries; retries++) {
		if (retries) {
			ERRS("retry %d (timeout %d ms)", retries, timeout);
		}

		length = len;
		if (umad_send(port_id, agentid, sndbuf, length, timeout, 0) < 0) {
			IBWARN("send failed; %s", strerror(errno));
			return -1;
		}

		/* Use same timeout on receive side just in case */
		/* send packet is lost somewhere. */
		do {
			if (umad_recv(port_id, rcvbuf, &length, timeout) < 0) {
				IBWARN("recv failed: %s", strerror(errno));
				return -1;
			}

			if (ibdebug > 1) {
				IBWARN("rcv buf:");
				xdump(stderr, "rcv buf\n", umad_get_mad(rcvbuf), IB_MAD_SIZE);
			}
		} while ((uint32_t)mad_get_field64(umad_get_mad(rcvbuf), 0, IB_MAD_TRID_F) != trid);

		status = umad_status(rcvbuf);
		if (!status)
			return length;		/* done */
		if (status == ENOMEM)
			return length;
	}

	ERRS("timeout after %d retries, %d ms", retries, timeout * retries);
	return -1;
}
Beispiel #3
0
static int directfb_init(void)
{
	memregs = mmap_phys(0xac009000, 1);
	if (memregs == NULL)
	{
		lprintf("can't access hw regs\n");
		return -1;
	}

	// fake lock
	Framework2D_LockBuffer(1);

	// 0xAC00905C
	directfb_addrs[0] = memregs[0x5c>>2];
	lprintf("fb0 is at %08x\n", directfb_addrs[0]);

	Framework2D_UnlockBuffer();

	directfb_ptrs[0] = mmap_phys(directfb_addrs[0], (321*240*2+PAGE_SIZE-1) / PAGE_SIZE);
	if (directfb_ptrs[0] == NULL)
	{
		lprintf("failed to map fb0\n");
		goto fail0;
	}

	// use directx to discover other buffer
	xdump();
	Framework2D_Flip();
	lprintf("---\n");
	xdump();
	exit(1);
	//Framework2D_LockBuffer(1);

	directfb_addrs[1] = memregs[0x5c>>2] + 0x30000;
	lprintf("fb1 is at %08x\n", directfb_addrs[1]);

	//Framework2D_UnlockBuffer();

	directfb_ptrs[1] = mmap_phys(directfb_addrs[1], (321*240*2+PAGE_SIZE-1) / PAGE_SIZE);
	if (directfb_ptrs[1] == NULL)
	{
		lprintf("failed to map fb1\n");
		goto fail1;
	}

	directfb_initialized = 1;
	directfb_sel = 1;
	return 0;

fail1:
	munmap_phys(directfb_ptrs[0]);
fail0:
	munmap_phys((void *)memregs);
	return -1;
}
Beispiel #4
0
char *
check_switch(ib_portid_t *portid, int *nports, uint64_t *guid,
	     uint8_t *sw, char *nd)
{
	uint8_t ni[IB_SMP_DATA_SIZE] = {0};
	int type;

	DEBUG("checking node type");
	if (!smp_query(ni, portid, IB_ATTR_NODE_INFO, 0, 0)) {
		xdump(stderr, "nodeinfo\n", ni, sizeof ni);
		return "node info failed: valid addr?";
	}

	if (!smp_query(nd, portid, IB_ATTR_NODE_DESC, 0, 0))
		return "node desc failed";

	mad_decode_field(ni, IB_NODE_TYPE_F, &type);
	if (type != IB_NODE_SWITCH)
		return "not a switch";

	DEBUG("Gathering information about switch");
	mad_decode_field(ni, IB_NODE_NPORTS_F, nports);
	mad_decode_field(ni, IB_NODE_GUID_F, guid);

	if (!smp_query(sw, portid, IB_ATTR_SWITCH_INFO, 0, 0))
		return "switch info failed: is a switch node?";

	return 0;
}
Beispiel #5
0
int
netsnmp_transport_send(netsnmp_transport *t, void *packet, int length,
                       void **opaque, int *olength)
{
    int dumpPacket, debugLength;

    if ((NULL == t) || (NULL == t->f_send)) {
        DEBUGMSGTL(("transport:pkt:send", "NULL transport or send function\n"));
        return SNMPERR_GENERR;
    }

    dumpPacket = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID,
                                        NETSNMP_DS_LIB_DUMP_PACKET);
    debugLength = (SNMPERR_SUCCESS ==
                   debug_is_token_registered("transport:send"));

    if (dumpPacket | debugLength) {
        char *str = netsnmp_transport_peer_string(t,
                    opaque ? *opaque : NULL,
                    olength ? *olength : 0);
        if (debugLength)
            DEBUGMSGT_NC(("transport:send","%lu bytes to %s\n",
                          (unsigned long)length, str));
        if (dumpPacket)
            snmp_log(LOG_DEBUG, "\nSending %lu bytes to %s\n",
                     (unsigned long)length, str);
        SNMP_FREE(str);
    }
    if (dumpPacket)
        xdump(packet, length, "");

    return t->f_send(t, packet, length, opaque, olength);
}
Beispiel #6
0
void
dump_lb()
{
	printk("===== Dump the LB regs =====\n");
	xdump((long long *)0xc0000a0001e00000, 1);
	xdump((long long *)0xc0000a0001e04000, 13);
	xdump((long long *)0xc0000a0001e04100, 2);
	xdump((long long *)0xc0000a0001e04200, 2);
	xdump((long long *)0xc0000a0001e08000, 5);
	xdump((long long *)0xc0000a0001e08040, 2);
	xdump((long long *)0xc0000a0001e08050, 3);
	xdump((long long *)0xc0000a0001e0c000, 3);
	xdump((long long *)0xc0000a0001e0c020, 4);
}
Beispiel #7
0
void *
mad_rpc_rmpp(const void *port_id, ib_rpc_t *rpc, ib_portid_t *dport,
	     ib_rmpp_hdr_t *rmpp, void *data)
{
	const struct ibmad_port *p = port_id;
	int status, len;
	uint8_t sndbuf[1024], rcvbuf[1024], *mad;

	memset(sndbuf, 0, umad_size() + IB_MAD_SIZE);

	DEBUG("rmpp %p data %p", rmpp, data);

	if ((len = mad_build_pkt(sndbuf, rpc, dport, rmpp, data)) < 0)
		return 0;

	if ((len = _do_madrpc(p->port_id, sndbuf, rcvbuf,
			      p->class_agents[rpc->mgtclass],
			      len, rpc->timeout)) < 0) {
		IBWARN("_do_madrpc failed; dport (%s)", portid2str(dport));
		return 0;
	}

	mad = umad_get_mad(rcvbuf);

	if ((status = mad_get_field(mad, 0, IB_MAD_STATUS_F)) != 0) {
		ERRS("MAD completed with error status 0x%x; dport (%s)",
			status, portid2str(dport));
		return 0;
	}

	if (ibdebug) {
		IBWARN("data offs %d sz %d", rpc->dataoffs, rpc->datasz);
		xdump(stderr, "rmpp mad data\n", mad + rpc->dataoffs,
		      rpc->datasz);
	}

	if (rmpp) {
		rmpp->flags = mad_get_field(mad, 0, IB_SA_RMPP_FLAGS_F);
		if ((rmpp->flags & 0x3) &&
		    mad_get_field(mad, 0, IB_SA_RMPP_VERS_F) != 1) {
			IBWARN("bad rmpp version");
			return 0;
		}
		rmpp->type = mad_get_field(mad, 0, IB_SA_RMPP_TYPE_F);
		rmpp->status = mad_get_field(mad, 0, IB_SA_RMPP_STATUS_F);
		DEBUG("rmpp type %d status %d", rmpp->type, rmpp->status);
		rmpp->d1.u = mad_get_field(mad, 0, IB_SA_RMPP_D1_F);
		rmpp->d2.u = mad_get_field(mad, 0, IB_SA_RMPP_D2_F);
	}

	if (data)
		memcpy(data, mad + rpc->dataoffs, rpc->datasz);

	rpc->recsz = mad_get_field(mad, 0, IB_SA_ATTROFFS_F);

	return data;
}
Beispiel #8
0
static void TcpdSock_Event(int alist_idx, unsigned char *buf)
{
#if 0
    int retval;
    common_tcpmsg_t *mpmsg = (common_tcpmsg_t *)buf;
#if 0
    xdump(FMS_HST | FMS_LOOKS, (unsigned char *)mpmsg, 20, "1111 TcpRecv ");
    xdump(FMS_HST | FMS_LOOKS, (unsigned char *)buf, NBO_NTOHS(mpmsg->MsgSize) + DEFAULT_TCP_COMHDR_LENGTH, "GUI RECV-1");
#endif

    TCP_MSG_NTOH(mpmsg);

    if (((mpmsg->MsgType > GUI_COMMAND_BASE) && (mpmsg->MsgType < GUI_REPORT_BASE)) ||
        (mpmsg->MsgType == SYSTEM_INFO_REQ) ||
        (mpmsg->MsgType == CCS_REGISTER_REQ) ||
        (mpmsg->MsgType == DSG_REGISTER_REQ) ||
        (mpmsg->MsgType == SDM_REGISTER_REQ) ||
        (mpmsg->MsgType == CTS_REGISTER_REQ) ||
        (mpmsg->MsgType == DBS_REGISTER_REQ) ||
        (mpmsg->MsgType == SFM_REGISTER_REQ)) {

        retval = tcp_PutFifo(FIFO_TYPE_REGCTRL, mpmsg, alist_idx, (unsigned char *)(buf + DEFAULT_TCP_COMHDR_LENGTH));

    } else {
        retval = tcp_PutFifo(FIFO_TYPE_ACTION, mpmsg, alist_idx, (unsigned char *)(buf + DEFAULT_TCP_COMHDR_LENGTH));
    }

    if (retval < 0) {
        xprint(FMS_HST | FMS_ERROR, "%s(%d) : tcp_PutFifo failed.\n", __func__, __LINE__);
    }
#else
    int retval;
    common_tcpmsg_t *mpmsg = (common_tcpmsg_t *)buf;

    TCP_MSG_NTOH(mpmsg);

    retval = tcp_PutFifo(mpmsg, alist_idx, (unsigned char *)(buf + DEFAULT_TCP_COMHDR_LENGTH));
    if (retval < 0) {
        xprint(FMS_HST | FMS_ERROR, "%s(%d) : tcp_PutFifo failed.\n", __func__, __LINE__);
    }
#endif

    return;
}
Beispiel #9
0
static int server_respond(void *umad, int size)
{
	ib_rpc_t rpc = { 0 };
	ib_rmpp_hdr_t rmpp = { 0 };
	ib_portid_t rport;
	uint8_t *mad = umad_get_mad(umad);
	ib_mad_addr_t *mad_addr;

	if (!(mad_addr = umad_get_mad_addr(umad)))
		return -1;

	memset(&rport, 0, sizeof(rport));

	rport.lid = ntohs(mad_addr->lid);
	rport.qp = ntohl(mad_addr->qpn);
	rport.qkey = ntohl(mad_addr->qkey);
	rport.sl = mad_addr->sl;
	if (!rport.qkey && rport.qp == 1)
		rport.qkey = IB_DEFAULT_QP1_QKEY;

	rpc.mgtclass = mad_get_field(mad, 0, IB_MAD_MGMTCLASS_F);
	rpc.method = IB_MAD_METHOD_GET | IB_MAD_RESPONSE;
	rpc.attr.id = mad_get_field(mad, 0, IB_MAD_ATTRID_F);
	rpc.attr.mod = mad_get_field(mad, 0, IB_MAD_ATTRMOD_F);
	rpc.oui = mad_get_field(mad, 0, IB_VEND2_OUI_F);
	rpc.trid = mad_get_field64(mad, 0, IB_MAD_TRID_F);

	if (size > IB_MAD_SIZE)
		rmpp.flags = IB_RMPP_FLAG_ACTIVE;

	DEBUG("responding %d bytes to %s, attr 0x%x mod 0x%x qkey %x",
	      size, portid2str(&rport), rpc.attr.id, rpc.attr.mod, rport.qkey);

	if (mad_build_pkt(umad, &rpc, &rport, &rmpp, 0) < 0)
		return -1;

	if (ibdebug > 1)
		xdump(stderr, "mad respond pkt\n", mad, IB_MAD_SIZE);

	if (umad_send(mad_rpc_portid(srcport),
		      mad_rpc_class_agent(srcport, rpc.mgtclass), umad, size,
		      rpc.timeout, 0) < 0) {
		DEBUG("send failed; %m");
		return -1;
	}

	return 0;
}
Beispiel #10
0
void *
mad_rpc(const void *port_id, ib_rpc_t *rpc, ib_portid_t *dport, void *payload,
	void *rcvdata)
{
	const struct ibmad_port *p = port_id;
	int status, len;
	uint8_t sndbuf[1024], rcvbuf[1024], *mad;

	len = 0;
	memset(sndbuf, 0, umad_size() + IB_MAD_SIZE);

	if ((len = mad_build_pkt(sndbuf, rpc, dport, 0, payload)) < 0)
		return 0;

	if ((len = _do_madrpc(p->port_id, sndbuf, rcvbuf,
			      p->class_agents[rpc->mgtclass],
			      len, rpc->timeout)) < 0) {
		IBWARN("_do_madrpc failed; dport (%s)", portid2str(dport));
		return 0;
	}

	mad = umad_get_mad(rcvbuf);

	if ((status = mad_get_field(mad, 0, IB_DRSMP_STATUS_F)) != 0) {
		ERRS("MAD completed with error status 0x%x; dport (%s)",
			status, portid2str(dport));
		return 0;
	}

	if (ibdebug) {
		IBWARN("data offs %d sz %d", rpc->dataoffs, rpc->datasz);
		xdump(stderr, "mad data\n", mad + rpc->dataoffs, rpc->datasz);
	}

	if (rcvdata)
		memcpy(rcvdata, mad + rpc->dataoffs, rpc->datasz);

	return rcvdata;
}
Beispiel #11
0
static void
dump_ii(void)
{
	printk("===== Dump the II regs =====\n");
	xdump((long long *)0xc0000a0001c00000, 2);
	xdump((long long *)0xc0000a0001c00020, 1);
	xdump((long long *)0xc0000a0001c00100, 37);
	xdump((long long *)0xc0000a0001c00300, 98);
	xdump((long long *)0xc0000a0001c10000, 6);
	xdump((long long *)0xc0000a0001c20000, 6);
	xdump((long long *)0xc0000a0001c30000, 2);

	xdump((long long *)0xc0000a0000000000, 1);
	xdump((long long *)0xc0000a0001000000, 1);
	xdump((long long *)0xc0000a0002000000, 1);
	xdump((long long *)0xc0000a0003000000, 1);
	xdump((long long *)0xc0000a0004000000, 1);
	xdump((long long *)0xc0000a0005000000, 1);
	xdump((long long *)0xc0000a0006000000, 1);
	xdump((long long *)0xc0000a0007000000, 1);
	xdump((long long *)0xc0000a0008000000, 1);
	xdump((long long *)0xc0000a0009000000, 1);
	xdump((long long *)0xc0000a000a000000, 1);
	xdump((long long *)0xc0000a000b000000, 1);
	xdump((long long *)0xc0000a000c000000, 1);
	xdump((long long *)0xc0000a000d000000, 1);
	xdump((long long *)0xc0000a000e000000, 1);
	xdump((long long *)0xc0000a000f000000, 1);
}
Beispiel #12
0
static void
clear_ii_error(void)
{
	volatile long long *tmp;

	printk("... WSTAT ");
	xdump((long long *)0xc0000a0001c00008, 1);
	printk("... WCTRL ");
	xdump((long long *)0xc0000a0001c00020, 1);
	printk("... WLCSR ");
	xdump((long long *)0xc0000a0001c00128, 1);
	printk("... IIDSR ");
	xdump((long long *)0xc0000a0001c00138, 1);
        printk("... IOPRBs ");
	xdump((long long *)0xc0000a0001c00198, 9);
	printk("... IXSS ");
	xdump((long long *)0xc0000a0001c00210, 1);
	printk("... IBLS0 ");
	xdump((long long *)0xc0000a0001c10000, 1);
	printk("... IBLS1 ");
	xdump((long long *)0xc0000a0001c20000, 1);

        /* Write IOERR clear to clear the CRAZY bit in the status */
        tmp = (long long *)0xc0000a0001c001f8; *tmp = (long long)0xffffffff;

	/* dump out local block error registers */
	printk("... ");
	xdump((long long *)0xc0000a0001e04040, 1);	/* LB_ERROR_BITS */
	printk("... ");
	xdump((long long *)0xc0000a0001e04050, 1);	/* LB_ERROR_HDR1 */
	printk("... ");
	xdump((long long *)0xc0000a0001e04058, 1);	/* LB_ERROR_HDR2 */
	/* and clear the LB_ERROR_BITS */
	tmp = (long long *)0xc0000a0001e04040; *tmp = 0x0;
	printk("clr: ");
	xdump((long long *)0xc0000a0001e04040, 1);	/* LB_ERROR_BITS */
	tmp = (long long *)0xc0000a0001e04050; *tmp = 0x0;
	tmp = (long long *)0xc0000a0001e04058; *tmp = 0x0;
}
Beispiel #13
0
int main(int argc, char *argv[]) {
    struct cache **cache;
    struct list_entry **access_list;
    char *filename;
    FILE *program;
    char buffer[33];
    char operation;
    unsigned int address;

    int i, j;
    int opt;
    int tmp;

    int capacity;
    int way;
    int blocksize;
    int set;
    int words;
    int index_size;

    int cache_config_set = 0;
    int cache_dump_set = 0;

    int total_reads = 0;
    int total_writes = 0;
    int write_backs = 0;
    int reads_hits = 0;
    int write_hits = 0;
    int reads_misses = 0;
    int write_misses = 0;

    // Argument check
    if (argc < 2) {
        usage(argv[0]);
    }

    while ((opt = getopt(argc, argv, "c:x")) != -1) {
        switch (opt) {
            case 'c':
                cache_config_set = 1;
                if (sscanf(optarg, "%d:%d:%d",
                            &capacity, &way, &blocksize) != 3) {
                    usage(argv[0]);
                }
                if (capacity < 4 || capacity > 8192) {
                    printf("Capacity should be between 4B and 8KB.\n");
                    exit(1);
                }
                if (way < 1 || way > 16) {
                    printf("Associativity should be between 1 and 16.\n");
                    exit(1);
                }
                if (blocksize < 4 || blocksize > 32) {
                    printf("Block size should be between 4B and 32B.\n");
                    exit(1);
                }
                set = capacity / way / blocksize;
                words = blocksize / BYTES_PER_WORD;

                tmp = set / 2;
                index_size = 0;
                while (tmp > 0) {
                    index_size++;
                    tmp >>= 1;
                }
                break;
            case 'x':
                cache_dump_set = 1;
                break;
            case '?':
                usage(argv[0]);
        }
    }
    if (!cache_config_set) {
        printf("The cache parameters are specified with \"-c\" option.\n");
        exit(1);
    }
    if (argc == optind) {
        usage(argv[0]);
    }
    filename = argv[optind];

    // allocate
    cache = (struct cache **) malloc(sizeof(struct cache *) * set);
    access_list = (struct list_entry **)
        malloc(sizeof(struct list_entry *) * set);
    for (i = 0; i < set; i++) {
        struct list_entry *entry;
        struct list_entry *prev_entry = NULL;

        cache[i] = (struct cache *) malloc(sizeof(struct cache) * way);
        for (j = 0; j < way; j++) {
            cache[i][j].valid = 0;
            cache[i][j].dirty = 0;
            cache[i][j].content = 0x0;
        }

        entry = (struct list_entry *) malloc(sizeof(struct list_entry));
        entry->way = 0;
        entry->prev = prev_entry;
        access_list[i] = entry;
        for (j = 1; j < way; j++) {
            entry->next =
                (struct list_entry *) malloc(sizeof(struct list_entry));
            prev_entry = entry;
            entry = entry->next;
            entry->way = j;
            entry->prev = prev_entry;
        }
        entry->next = NULL;
    }

    // Open program file.
    program = fopen(filename, "r");
    if (program == NULL) {
        printf("Error: Can't open program file \"%s\"\n", filename);
        exit(-1);
    }

    while (fgets(buffer, 33, program) != NULL) {
        unsigned int entry;
        unsigned int index;
        int _way;
        struct cache *result_cache;
        struct list_entry *list_item;
        int hit;
        int invalid_exist;

        sscanf(buffer, "%c %x", &operation, &address);

        entry = address & ~(blocksize - 1);
        index = (address / blocksize) & ((1 << index_size) - 1);
        hit = 0;
        for (i = 0; i < way; i++) {
            if (cache[index][i].valid && cache[index][i].content == entry) {
                hit = 1;
                _way = i;
                result_cache = &cache[index][i];

                list_item = access_list[index];
                while (list_item->way != i) {
                    list_item = list_item->next;
                }
                if (list_item->prev != NULL) {
                    list_item->prev->next = list_item->next;
                    if (list_item->next != NULL) {
                        list_item->next->prev = list_item->prev;
                    }
                    access_list[index]->prev = list_item;
                    list_item->prev = NULL;
                    list_item->next = access_list[index];
                    access_list[index] = list_item;
                }
                break;
            }
        }
        if (!hit) {
            struct cache *evict_cache;

            list_item = access_list[index];
            invalid_exist = 0;
            for (i = 0; i < way; i++) {
                if (!cache[index][i].valid) {
                    invalid_exist = 1;
                    evict_cache = &cache[index][i];
                    _way = i;
                    while (list_item->way != i) {
                        list_item = list_item->next;
                    }
                    break;
                }
            }
            if (!invalid_exist) {
                for (i = 1; i < way; i++) {
                    list_item = list_item->next;
                }
                evict_cache = &cache[index][list_item->way];
                _way = list_item->way;
            }
            if (evict_cache->dirty) {
                write_backs++;
            }
            evict_cache->valid = 1;
            evict_cache->dirty = 0;
            evict_cache->content = entry;
            result_cache = evict_cache;

            if (list_item->prev != NULL) {
                list_item->prev->next = list_item->next;
                if (list_item->next != NULL) {
                    list_item->next->prev = list_item->prev;
                }
                access_list[index]->prev = list_item;
                list_item->prev = NULL;
                list_item->next = access_list[index];
                access_list[index] = list_item;
            }
        }

        switch (operation) {
            case 'R':
                total_reads++;
                hit ? reads_hits++ : reads_misses++;
                break;
            case 'W':
                result_cache->dirty = 1;
                total_writes++;
                hit ? write_hits++ : write_misses++;
                break;
        }
    }

    cdump(capacity, way, blocksize);
    sdump(total_reads, total_writes, write_backs,
            reads_hits, write_hits, reads_misses, write_misses);
    if (cache_dump_set) {
        xdump(set, way, cache);
    }

    for (i = 0; i < set; i++) {
        free(cache[i]);
    }
    free(cache);

    return 0;
}
Beispiel #14
0
int
snmp_read_packet(int sd)
{
    struct sockaddr_in	from;
    int length, out_length, fromlength;
    u_char  packet[1500], outpacket[1500];
#ifdef USE_LIBWRAP
    char *addr_string;
#endif
    fromlength = sizeof from;
    length = recvfrom(sd, (char *) packet, 1500, 0, (struct sockaddr *)&from,
		      &fromlength);
    if (length == -1)
	perror("recvfrom");

#ifdef USE_LIBWRAP
	addr_string = inet_ntoa(from.sin_addr);

	if(!addr_string) {
          addr_string = STRING_UNKNOWN;
	}
	if(hosts_ctl("snmpd", addr_string, addr_string, STRING_UNKNOWN)) {
          syslog(allow_severity, "Connection from %s", addr_string);
	} else {
          syslog(deny_severity, "Connection from %s refused", addr_string);
          return(0);
	}
#endif

#ifdef USING_MIBII_SNMP_MIB_MODULE       
    snmp_inpkts++;
#endif
    if (snmp_dump_packet){
	printf("\nreceived %d bytes from %s:\n", length,
	       inet_ntoa(from.sin_addr));
	xdump(packet, length, "");
	printf("\n");
        fflush(stdout);
    } else if (log_addresses){
	int count;
	
	for(count = 0; count < ADDRCACHE; count++){
	    if (addrCache[count].status > UNUSED /* used or old */
		&& from.sin_addr.s_addr == addrCache[count].addr)
		break;
	}
	if (count >= ADDRCACHE || verbose){
	    printf("%s Received SNMP packet(s) from %s\n",
		   sprintf_stamp(NULL), inet_ntoa(from.sin_addr));
	    for(count = 0; count < ADDRCACHE; count++){
		if (addrCache[count].status == UNUSED){
		    addrCache[count].addr = from.sin_addr.s_addr;
		    addrCache[count].status = USED;
		    break;
		}
	    }
	} else {
	    addrCache[count].status = USED;
	}
    }
    out_length = 1500;
    if (snmp_agent_parse(packet, length, outpacket, &out_length,
			 from.sin_addr.s_addr)){
	if (snmp_dump_packet){
	    printf("\nsent %d bytes to %s:\n", out_length,
		   inet_ntoa(from.sin_addr));
	    xdump(outpacket, out_length, "");
	    printf("\n");
            fflush(stdout);
	}
#ifdef USING_MIBII_SNMP_MIB_MODULE       
	snmp_outpkts++;
#endif
	if (sendto(sd, (char *)outpacket, out_length, 0,
		   (struct sockaddr *)&from, sizeof(from)) < 0){
	    perror("sendto");
	    return 0;
	}

    }
    return 1;
}
Beispiel #15
0
UInt8 tal_write_packet(const UInt8 * data, const UInt8 len)
{
    #ifdef UART
    BOOL uart_pause_needed = FALSE;
    #endif
    
    #ifdef DEBUGGING_TOOLS
    if(pause || ratchet || write_pause)
    {
        proceed = FALSE;
        synchronize_last_tick();
        
        #if DEBUG_VERBOSE_LEVEL > 2
        if(verbose_level > 2)
        {
            oncli_send_msg("\n\n%lu sending %u bytes:\n",
              TICK_TO_MS(get_tick_count()), len);
        }
        #endif
        
        #if DEBUG_VERBOSE_LEVEL > 5
        if(verbose_level > 5)
        {
            display_pkt(data, len, NULL, 0, NULL, 0);
        }
        #endif
        #if DEBUG_VERBOSE_LEVEL > 2
        if(verbose_level <= 5 && verbose_level > 2)
        {
            xdump(data, len);
        }
        #endif
        #if DEBUG_VERBOSE_LEVEL > 1
        if(verbose_level == 2)
        {
            UInt16 raw_pid;
            if(get_raw_pid(&data[ON_ENCODED_PID_IDX], &raw_pid))
            {
                oncli_send_msg("\n\nWrite Raw PID 0x%02X\n", raw_pid);
            }            
        }
        #endif
    }
    
    while(pausing = (pause || (ratchet && !proceed)))
    {
        synchronize_last_tick();
        oncli();
    }
    proceed = FALSE;
    
    if(write_pause > 0)
    {
        pausing = TRUE;
        ont_set_timer(WRITE_PAUSE_TIMER, write_pause);
        
        while(!ont_inactive_or_expired(WRITE_PAUSE_TIMER))
        {
            oncli();  // alow the user to enter commands while pausing
        }
        #if DEBUG_VERBOSE_LEVEL > 1
        if(verbose_level > 1)
        {
            oncli_send_msg("Pause done\n");
        }
        #endif
        pausing = FALSE;
    }
    #endif    
    
    #ifdef WRITE_PAUSE
        #if WRITE_PAUSE_FACTOR > 0
        {
            tick_t write_tick = get_tick_count() + MS_TO_TICK(WRITE_PAUSE_FACTOR);
            while(get_tick_count() < write_tick)
            {
            }
        }
        #endif
    #endif
    
    
    tx_rf_idx = 0;
    tx_rf_data = data;
    tx_rf_len = len;

    #ifdef UART
    while(cb_bytes_queued(&uart_tx_cb))
    {
        uart_pause_needed = TRUE;
    }
    if(uart_pause_needed)
    {
        #ifdef DEBUGGING_TOOLS
        pausing = TRUE;
        #endif
        delay_ms(2); // slight pause to let the uart clear so nothing
                     // gets garbled.
        #ifdef DEBUGGING_TOOLS
        pausing = FALSE;
        #endif
    }
    #endif //  if UART is enabled //

    tal_turn_on_transmitter();
    ENABLE_TX_BIT_INTERRUPTS();

    return len;
} // tal_write_packet //