Exemplo n.º 1
0
syscall rtRecv(struct packet *pkt)
{
    irqmask im;

    /* Error check pointers */
    if (NULL == pkt)
    {
        return SYSERR;
    }

    /* If route queue is full, then drop packet */
    im = disable();
    if (mailboxCount(rtqueue) >= RT_NQUEUE)
    {
        restore(im);
        RT_TRACE("Route queue full");
        netFreebuf(pkt);
        return OK;
    }

    /* Place packet in queue */
    if (SYSERR == mailboxSend(rtqueue, (int)pkt))
    {
        restore(im);
        RT_TRACE("Failed to enqueue packet");
        netFreebuf(pkt);
        return SYSERR;
    }

    restore(im);
    RT_TRACE("Enqueued packet for routing");
    return OK;
}
Exemplo n.º 2
0
int sendMessage(int argc, char **argv) {
	if(argc != 1) {
		printf("%s: invalid arguments\r\n", argv[0]);
		return -1;
	}
	unsigned int message = strtol(argv[1], 0, 16);
	
	mailboxSend(message);
	printf("%08x\r\n", mailboxRecv());
	return 0;
}
Exemplo n.º 3
0
/**
 * @ingroup icmp
 *
 * Processes an incoming ICMP packet.
 * @param pkt pointer to the incoming packet
 * return OK if packet was processed succesfully, otherwise SYSERR
 */
syscall icmpRecv(struct packet *pkt)
{
    struct icmpPkt *icmp;
    struct icmpEcho *echo;
    int id;

    /* Error check pointers */
    if (NULL == pkt)
    {
        return SYSERR;
    }

    icmp = (struct icmpPkt *)pkt->curr;

    switch (icmp->type)
    {
    case ICMP_ECHOREPLY:
        ICMP_TRACE("Received Echo Reply");
        echo = (struct icmpEcho *)icmp->data;
        id = net2hs(echo->id);
        if ((id >= 0) && (id < NTHREAD))
        {
            int i;
            irqmask im;

            im = disable();

            echo->arrivcyc = clkcount();
            echo->arrivtic = clkticks;
            echo->arrivsec = clktime;

            for (i = 0; i < NPINGQUEUE; i++)
            {
                struct icmpEchoQueue *eq;

                eq = &echotab[i];
                if (id == eq->tid)
                {
                    ICMP_TRACE("Ping matches queue %d", i);
                    if (((eq->head + 1) % NPINGHOLD) == eq->tail)
                    {
                        ICMP_TRACE("Queue full, discarding");
                        restore(im);
                        netFreebuf(pkt);
                        return SYSERR;
                    }
                    eq->pkts[eq->head] = pkt;
                    eq->head = ((eq->head + 1) % NPINGHOLD);
                    send(id, (message)pkt);
                    restore(im);
                    return OK;
                }
            }
            restore(im);
        }
        ICMP_TRACE("Reply id %d does not correspond to ping queue", id);
        netFreebuf(pkt);
        return SYSERR;

    case ICMP_ECHO:
        ICMP_TRACE("Enqueued Echo Request for daemon to reply");
        mailboxSend(icmpqueue, (int)pkt);
        return OK;

    case ICMP_UNREACH:
    case ICMP_SRCQNCH:
    case ICMP_REDIRECT:
    case ICMP_TIMEEXCD:
    case ICMP_PARAMPROB:
    case ICMP_TMSTMP:
    case ICMP_TMSTMPREPLY:
    case ICMP_INFORQST:
    case ICMP_INFOREPLY:
    case ICMP_TRACEROUTE:
        ICMP_TRACE("ICMP message type %d not handled", icmp->type);
        break;

    default:
        ICMP_TRACE("ICMP message type %d unknown", icmp->type);
        break;
    }

    netFreebuf(pkt);
    return OK;
}