//TODO: move this into an "ideal-mac" directory, and use the
//	same interfaces we use for sift/smac/etc. to channel
//	data over devnet_xmit, using the idealized MAC layer
int
mac_xmit(uchar *ear_dst_addr, uchar *ear_hdr, int hdrlen, uchar *data, int datalen)
{
//fprintf(stderr, "mac_xmit(), ear_dst_addr=[%s]\n", ear_dst_addr);

	return devnet_xmit(ear_dst_addr, PROTO_EAR, ear_hdr, hdrlen, 0);
}
void
dam_broadcast(Dampkt *p)
{
	uchar	data[4 + 2*(DAM_ID_LEN+1) + 2*8];

	memmove(&data[0],  &(p->timestamp), 4);
	memmove(&data[4], p->transID, DAM_ID_LEN+1);
	memmove(&data[4 + DAM_ID_LEN+1],  p->maxID, DAM_ID_LEN+1);
	memmove(&data[4 + 2*(DAM_ID_LEN+1)],  &(p->maxPr), 8);
	memmove(&data[4 + 2*(DAM_ID_LEN+1) + 8],  &(p->transPr), 8);

NETTRACEMARK(4);
LOGMARK(8);
	devnet_xmit("::1", PROTO_DAM_INTERNAL, data, 4 + 2*(DAM_ID_LEN+1) + 2*8, 0);
LOGMARK(9);
NETTRACEMARK(5);

	return;
}
void
startup(void)
{
        /*      Monitor code is @ 0x8001000     */
        void    	(*fptr)() = (void *)0x8001000;
	int		frames_rcvd = 0, addrchars, i;
	uchar		demod_dst[16+1];
	LPFData		lpf_data;


	/*	If we are the clone of someone, my_id is already set, keep it, for timeslot stuff	*/
	if (my_id == -1)
	{
		addrchars = strlen((char *)NIC_OUI);

		my_id = 0;

		for (i = addrchars-1; i >= 0; i--)
		{
			my_id +=  (*(NIC_OUI+i) - '0') * pow10(addrchars - 1 - i);
		}
	}
	sprint(&demod_dst[0], "%d", my_id+1);

	hdlr_install();

	/*	Power up both RX interfaces	*/
	devnet_ctl(NIC_NCR_WRITE, NIC_CMD_POWERUP, 0);
	devnet_ctl(NIC_NCR_WRITE, NIC_CMD_POWERUP, 1);

	print("swradio-lpf [%d] installing vector code...\n", my_id);



	/*	Make sure we're talking on regular segment		*/
	/*	uncommenmt if doing segmented network	*/
	sample_flag = 0;
	syn_sent = 0;

	fb1.rpos = fb1.rlen = 0;
	fb2.rpos = fb2.rlen = 0;
	init_lpf_data(&lpf_data, CUTOFF_FREQUENCY, NUM_TAPS, DECIMATION);

	/*	LPF needs at least NUM_TAPS+1 inputs; get_floats is fine.	*/
	while (!sample_flag)
	{
		sleep();
	}
	run_lpf((void *)&fb1, (void *)&fb2, &lpf_data);
	sample_flag = 0;

	/*									*/
	/*	run_demod needs 1 input, OK here. run_equalizer needs 51 	*/
	/*	inputs (same reason as for LPF).  This means running the 	*/
	/*	pipeline up to demod 50 times in advance: 			*/
	/*									*/
	while (frames_rcvd < NUM_TAPS)
	{
		while (!sample_flag)
		{
			sleep();
		}

		frames_rcvd++;
		sample_flag = 0;
		run_lpf((void *)&fb1, (void *)&fb2, &lpf_data);

			/*
			print("swradio-lpf (node [%d]) sending [%d] bytes to DEMOD (node [%s])\n",
				my_id, sizeof(fb1), demod_dst);
			print("fb2.rpos = [%d], fb2.rlen = [%d]\n", fb2.rpos, fb2.rlen);
			*/

		devnet_xmit((uchar *)&demod_dst, 0, (uchar *)&fb2, sizeof(fb2), 1);
		/*									*/
		/*	Since we are doing Call-By-Value, we must make this change 	*/
		/*	here. The corresponding calculation in run_demod is a No-op	*/
		/*									*/
		fb2.rpos++;
	}

	/*	Wait till intr_hdlr is done	*/
	done_flag = 0;
	while (!done_flag)
	{
		if (sample_flag)
		{
			run_lpf((void *)&fb1, (void *)&fb2, &lpf_data);

			
			/*
			print("swradio-lpf (node [%d]) sending [%d] bytes to DEMOD (node [%s])\n",
				my_id, sizeof(fb1), demod_dst);
			print("fb2.rpos = [%d], fb2.rlen = [%d]\n", fb2.rpos, fb2.rlen);
			*/


			/*	Now send fb2 to be Demod'd. We dont re-xmit	*/
			devnet_xmit((uchar *)&demod_dst, 0, (uchar *)&fb2, sizeof(fb2), 1);
			/*									*/
			/*	Since we are doing Call-By-Value, we must make this change 	*/
			/*	here. The corresponding calculation in run_demod is a No-op	*/
			/*									*/
			fb2.rpos++;

			sample_flag = 0;
		}

		sleep();
	}

	/*	Forcefully go to monitor	*/
	fptr();


	return;		
}
Example #4
0
int devnet_xmit(uchar *dst, uchar proto, uchar *data, int nbytes, int whichifc)
{
    int framesize;
    int n = 0, i;
    uchar *tptr;
    ulong ifc_shift_offset = (whichifc & 0xFFF) << 4;
    ulong savedSR;

    //@@printf("in devnet_xmit, sending [%d] bytes to [%s], proto [%d], via ifc [%d]\n", nbytes, dst, proto, whichifc);

    /*	Save SR, then disable intrs:	*/
    savedSR = getpsr();
    splhi();

    /*	Save the dst for future use	*/
    for (i = 0; i < 16; i++)
    {
        *(NIC_DST + ifc_shift_offset + i) = *(dst + i);
    }

    /*	Write 16 byte src_addr	    	*/
    for (i = 0; i < 16; i++)
    {
        *(NIC_TDR + ifc_shift_offset) = *(NIC_OUI + i);
    }
    n += 16;

    /*	Write 16 byte dst_addr	    	*/
    for (i = 0; i < 16; i++)
    {
        *(NIC_TDR + ifc_shift_offset) = *(dst + i);
        //printf("devnet_xmit(), *(dst+i) = [%d]\n", *(dst+i));
    }
    n += 16;

    /*	Write 4 byte payloadlen	    	*/
    *(NIC_TDR + ifc_shift_offset) = (nbytes >> 24) & 0xFF;
    *(NIC_TDR + ifc_shift_offset) = (nbytes >> 16) & 0xFF;
    *(NIC_TDR + ifc_shift_offset) = (nbytes >> 8) & 0xFF;
    *(NIC_TDR + ifc_shift_offset) = (nbytes >> 0) & 0xFF;
    n += 4;

    /*	Write 1 byte nexthdr		*/
    *(NIC_TDR + ifc_shift_offset) = proto;
    n += 1;

    /*					*/
    /*	The 32 bit cksum added by hw	*/
    /*	is not counted as part of fsz	*/
    /*					*/
    framesize = devnet_getmaxfsz(whichifc);

    /*	Write data	    	*/
    tptr = data;
    for (i = 0; (i < nbytes) && (n < framesize); i++)
    {
        *(NIC_TDR + ifc_shift_offset) = *tptr++;
        n++;
    }

    /*	if nbytes+header size was more than a frame, recurse	*/
    if (nbytes + 16 + 16 + 4 + 1 > framesize)
    {
        printf(
                "Warning!!! devnet_xmit recursing: nbytes+header = %d, framesize = %d\n",
                nbytes + 16 + 16 + 4 + 1, framesize);
        devnet_xmit(dst, proto, tptr, nbytes - i, whichifc);
    } else
        while (n < framesize)
        {
            /*	Send padding	*/
            *(NIC_TDR + ifc_shift_offset) = 0;
            n++;
        }

    /*	Restore SR	*/
    spldone(savedSR);

    /*					*/
    /*    If frame could'nt be sent, LSB	*/
    /*    of NIC_NSR will be 1, return -1	*/
    /*					*/
    return -((*(NIC_NSR + ifc_shift_offset)) & 0x1);
}