Beispiel #1
0
//
// Create a loop of rx descriptors.
// Return the address of the first one.
//
int LinkRxLoopCreate(int many)
{
    int it;
	unsigned int dr[MDESCRIPTOR];
	unsigned int descriptorNext;

    many=LinkRxLoopMany;                // we ignore the suggested queue size
//	MemoryLayout(1024);
    /*
     * create a few descriptors linked in a loop 
	 * OSPREY requires that the memory buffer directly follow the descriptor. Older chip sets
	 * include a pointer to the buffer in the descriptor. This code does both.
     */
	for(it=0; it<many; it++)
	{
		LinkRxLoopDescriptor[it] = MemoryLayout(RxDescriptorSize()+MPACKETSIZEBUFFER);
		if(LinkRxLoopDescriptor[it]==0) 
		{
			UserPrint( "Device Number %d:rxDataSetup: unable to allocate memory for %d descriptors\n", 0, many);
			return -1;
		}
		LinkRxLoopBuffer[it]=LinkRxLoopDescriptor[it]+RxDescriptorSize();
	}
	//
	// fill in the descriptors
	//
    for (it = 0; it < many; it++)
	{
		//
		// figure out next pointer, last one loops back to first
		//
        if (it == many - 1) 
		{ 
            descriptorNext = LinkRxLoopDescriptor[0];
        }
        else 
		{
            descriptorNext = LinkRxLoopDescriptor[it+1];	//descriptor + RxDescriptorSize();	
        }
        //
		// make the descriptor
		//
//		UserPrint("%2d: %8x %8x %8x\n",it,LinkRxLoopDescriptor[it],LinkRxLoopBuffer[it],descriptorNext);
        RxDescriptorSetup(dr,descriptorNext,LinkRxLoopBuffer[it],MPACKETSIZE);
		//
		// copy it to the shared memory
		//
		MyMemoryWrite(LinkRxLoopDescriptor[it],dr,RxDescriptorSize());

//        memset(dr, 0x55, RxDescriptorSize());
//		MyMemoryWrite(LinkRxLoopDescriptor[it]+48,dr,RxDescriptorSize());
	}

//	LinkRxLoopMany=many;

	return 0;
}
Beispiel #2
0
void LinkRxComplete(int timeout, 
	int ndump, unsigned char *dataPattern, int dataPatternLength, int (*done)())
{
    unsigned int startTime, endTime, ctime;
	int it;
	int notdone;
	int stop;
	int behind;
	int scount;
	unsigned int mDescriptor;			// address of descriptor in shared memory
#ifdef MEMORYREAD
	unsigned int descriptor[MDESCRIPTOR+30];	// private copy of current descriptor
#else
    unsigned int *descriptor;
#endif
	int pass;
    int dsize;
	int isdone;

	pass=0;
	dataPatternLength=0;
	dataPattern=0;
	scount=0;
    dsize=RxDescriptorSize();
    //
	// Loop timeout condition.
	// This number can be large since it is only used for
	// catastrophic failure of cart. The normal terminating
	// condition is a message from cart saying STOP.
	//
    startTime=TimeMillisecond();
	ctime=startTime;
//	if(timeout<=0)
//	{
//		timeout=60*60*1000;             // one hour
//	}
	endTime=startTime+timeout;		
	//
	// set pointer to first descriptor
	//
//    mDescriptor = LinkRxLoopFirst(0);
	//
	// keep track of how many times we look and the descriptor is not done
	// this is used to control the sleep interval
	//
	notdone=0;
	stop=0;
	behind=0;
	//
	// loop looking for descriptors with received packets.
	//
	for(it = 0; ; it++) 
	{
		mDescriptor=LinkRxLoopDescriptor[it%LinkRxLoopMany];
#ifdef MEMORYREAD
        //
		// read the next descriptor
		//
        MyMemoryRead(mDescriptor, descriptor, dsize);		
#else
        descriptor=(unsigned int *)MyMemoryPtr(mDescriptor);
#endif
        //
		// descriptor is ready, we have a new packet
		//
        if(RxDescriptorDone(descriptor)) 
		{
#ifdef MEMORYREAD
            //
		    // read the next descriptor
		    //
            MyMemoryRead(mDescriptor, descriptor, dsize);
#endif

		
			notdone=0;
			behind++;
			scount=0;
#ifdef FASTER
			if((it%100)==0)
			{
				UserPrint(" %d",it);
			}
#endif         
            //
			// dump packet contents
			//
            if(ndump>0) 
			{
				UserPrint("\n");
                LinkRxDump(descriptor, ndump, it%LinkRxLoopMany);
            }
			//
			// extract stats
			//
			LinkRxStatExtract(descriptor,it);
			//
			// reset the descriptor so that we can use it again
			//
			RxDescriptorReset(descriptor);
#ifdef MEMORYREAD
			//
			// copy it back to the shared memory
			//
			MyMemoryWrite(mDescriptor,descriptor,dsize);
#endif
			//
			// need to queue the descriptor with the hardware
			//
            if(LinkRxDescriptorFifo)
            {
	            DeviceReceiveDescriptorPointer(mDescriptor);
            }
        } 
		//
		// descriptor not ready
		//
		else 
		{
			if(stop)
			{
				scount++;
				if(scount>200)
				{
				    break;
				}
			}
			it--;
			//
			// sleep every other time, need to keep up with fast rates
			//
			if(notdone>100)
			{
			    UserPrint(".");
//			    MyDelay(1);
				notdone=0;
			}
			else
			{
				notdone=1;      // this makes sure we never sleep
			}
        }
		//
		// check for message from cart telling us to stop
		// this is the normal terminating condition
		//
		pass++;
		if(pass>100)
		{
			if(done!=0)
			{
				isdone=(*done)();
				if(isdone!=0)
				{
					UserPrint(" %d Stop",it);
					if(stop==0)
					{
						stop=1;
						scount=0;
						behind=0;
					}
					//
					// immediate stop
					//
					if(isdone==2)
					{
						break;
					}
	//				break;
				}
			}
			pass=0;
		    //
		    // check for timeout
		    // rare terminating condition when cart crashes or disconnects
		    //
		    ctime=TimeMillisecond();
		    if(timeout>0 && ((endTime>startTime && (ctime>endTime || ctime<startTime)) || (endTime<startTime && ctime>endTime && ctime<startTime)))
		    {
			    UserPrint("%d Timeout",it);
			    break;
		    }
		}
    } 
    //
	// cleanup
	//
	DeviceReceiveDisable();

	LinkRxLoopDestroy(0);

    //
	// do data verify if requested
	//
	UserPrint(" %d\n",it);

	LinkRxStatFinish();

    return;
}
//
// creates a block acknowledgement request (BAR) 802.11 message.
// return the size of the message
//
int LinkTxBarCreate(unsigned char *source, unsigned char *destination)
{
//	int it;
//	int nwrite;
//    unsigned int pPktAddr;             
    unsigned int pPkt[24];
    WLAN_BAR_CONTROL_MAC_HEADER  *pPktHeader;
//	unsigned char *pBody;
//	int pPktSize;
    //
    // how big is the packet?
	//
    pPktHeader=(WLAN_BAR_CONTROL_MAC_HEADER *)pPkt;
	_LinkTxBarBufferSize = sizeof(WLAN_BAR_CONTROL_MAC_HEADER);		// should be 20;
    //
	// create the packet Header, all fields are listed here to enable easy changing
	//
    pPktHeader->frameControl.protoVer = 0;
    pPktHeader->frameControl.fType = FRAME_CTRL;
    pPktHeader->frameControl.fSubtype = SUBT_QOS;
    pPktHeader->frameControl.ToDS = 0;
    pPktHeader->frameControl.FromDS = 0;
    pPktHeader->frameControl.moreFrag = 0;
    pPktHeader->frameControl.retry = 0;
    pPktHeader->frameControl.pwrMgt = 0;
    pPktHeader->frameControl.moreData = 0;
    pPktHeader->frameControl.wep = 0;
    pPktHeader->frameControl.order = 0;
// Swap the bytes of the frameControl
#if 0
//#ifdef ARCH_BIG_ENDIAN
    {
        unsigned short* ptr;

        ptr = (unsigned short *)(&(pPktHeader->frameControl));
        *ptr = btol_s(*ptr);
    }
#endif
//  pPktHeader->durationNav.clearBit = 0;
//  pPktHeader->durationNav.duration = 0;
    pPktHeader->durationNav = 0;  // aman redefined the struct to be just unsigned short
// Swap the bytes of the durationNav
#if 0
//#ifdef ARCH_BIG_ENDIAN
    {
        unsigned short* ptr;

        ptr = (unsigned short *)(&(pPktHeader->durationNav));
        *ptr = btol_s(*ptr);
    }
#endif
	//
	// set the address fields
	//
    memcpy(pPktHeader->address1.octets, destination, WLAN_MAC_ADDR_SIZE);
    memcpy(pPktHeader->address2.octets, source, WLAN_MAC_ADDR_SIZE);
	//
	// set the bar control 
	// should define the fields in a bit map
	//
	pPktHeader->barControl = 0x7ff00005;
	//
	// reserve a block in the shared memory
	//
    _LinkTxBarBuffer = MemoryLayout(_LinkTxBarBufferSize);
    if(_LinkTxBarBuffer==0) 
	{
        UserPrint("createTransmitPacket: unable to allocate memory for BAR buffer\n");
        return 0;
    }
    // 
	// write the packet to physical memory
    //
	MyMemoryWrite(_LinkTxBarBuffer, pPkt, _LinkTxBarBufferSize);
//	UserPrint("bar = %x %d\n",_LinkTxBarBuffer,_LinkTxBarBufferSize);

//	for(it=0; it<_LinkTxBarBufferSize; it++)
//	{
//		UserPrint("02x ",pPkt[it]);
//	}
//	UserPrint("\n");

    return _LinkTxBarBufferSize;
}
Beispiel #4
0
// Added VSG sync detection 
void LinkRxComplete_vsgSync(int timeout, 
	int ndump, unsigned char *dataPattern, int dataPatternLength, int (*done)(), int chainMask)
{
    unsigned int startTime, endTime, ctime;
	int it, ii;
	int notdone;
	int stop;
	int behind;
	int scount;
	unsigned int mDescriptor;			// address of descriptor in shared memory
#ifdef MEMORYREAD
	unsigned int descriptor[MDESCRIPTOR+30];	// private copy of current descriptor
#else
    unsigned int *descriptor;
#endif
	int pass;
    int dsize;
	int isdone;

    int ss; 
    int rssic[MCHAIN], rssie[MCHAIN], rssi; 
    #define MSPECTRUM 1024 
    int nspectrum,spectrum[MSPECTRUM]; 
    int ndata; 
    unsigned char data[MBUFFER]; 
    int sscount=0; 
    unsigned int vsgSync = 0;

	pass=0;
	dataPatternLength=0;
	dataPattern=0;
	scount=0;
    dsize=RxDescriptorSize();
    //
	// Loop timeout condition.
	// This number can be large since it is only used for
	// catastrophic failure of cart. The normal terminating
	// condition is a message from cart saying STOP.
	//
    startTime=TimeMillisecond();
	ctime=startTime;
	if(timeout<=0)
	{
		timeout=2*60*1000;             // 2 mins
	}
	endTime=startTime+timeout;		
	//
	// set pointer to first descriptor
	//
//    mDescriptor = LinkRxLoopFirst(0);
	//
	// keep track of how many times we look and the descriptor is not done
	// this is used to control the sleep interval
	//
	notdone=0;
	stop=0;
	behind=0;
	//
	// loop looking for descriptors with received packets.
	//
	for(it = 0; ; it++) 
	{
		mDescriptor=LinkRxLoopDescriptor[it%LinkRxLoopMany];
#ifdef MEMORYREAD
        //
		// read the next descriptor
		//
        MyMemoryRead(mDescriptor, descriptor, dsize);		

#else
        descriptor=(unsigned int *)MyMemoryPtr(mDescriptor);
#endif
        //
		// descriptor is ready, we have a new packet
		//
       
        if(RxDescriptorDone(descriptor)) 
		{
#ifdef MEMORYREAD
            //
		    // read the next descriptor
		    //
            MyMemoryRead(mDescriptor, descriptor, dsize);
#endif
			notdone=0;
			behind++;
			scount=0;
#ifdef FASTER
			if((it%SASAMPLINGS)==0)   
			{
				UserPrint(" %d",it);
			}
#endif         

            if(_LinkRxSpectralScan) 
            { 
                ss=Ar9300RxDescriptorSpectralScan(descriptor); 
                if(ss) 
                { 
                    // 
                    // extract rssi and evm measurements. we need these for both good and bad packets 
                    // 
                    rssi=RxDescriptorRssiCombined(descriptor); 
                    if(rssi&0x80) 
                    { 
                        rssi|=0xffffff00; 
                    } 
                    rssic[0]=RxDescriptorRssiAnt00(descriptor); 
                    rssic[1]=RxDescriptorRssiAnt01(descriptor); 
                    rssic[2]=RxDescriptorRssiAnt02(descriptor); 
                    rssie[0]=RxDescriptorRssiAnt10(descriptor); 
                    rssie[1]=RxDescriptorRssiAnt11(descriptor); 
                    rssie[2]=RxDescriptorRssiAnt12(descriptor); 


                    for(ii=0; ii<3; ii++) 
                    { 
                        if(rssic[ii]&0x80) 
                        { 
                           rssic[ii]|=0xffffff00; 
                        } 
                        if(rssie[ii]&0x80) 
                        { 
                            rssie[ii]|=0xffffff00; 
                        } 
                    }

                    ndata=RxDescriptorDataLen(descriptor); 
                    MyMemoryRead(LinkRxLoopBuffer[it%LinkRxLoopMany], (unsigned int *)data, ndata); 
                    nspectrum=Ar9300SpectralScanProcess(data,ndata,spectrum,MSPECTRUM); 

                    if(_LinkRxSpectralScanFunction!=0) 
                    { 
                        (*_LinkRxSpectralScanFunction)(rssi,rssic,rssie,MCHAIN,spectrum,nspectrum); 
                    }
                    // 
                    // extract stats 

                    if (!vsgSync)
                    {
                        vsgSync = ((rssic[0] >= ISSM80DBM_THRESHOLD) && (chainMask & (1 << 0)) || 
                                   (rssic[1] >= ISSM80DBM_THRESHOLD) && (chainMask & (1 << 1)) ||
                                   (rssic[2] >= ISSM80DBM_THRESHOLD) && (chainMask & (1 << 2)) );
                    }
                    else
                    {
                        LinkRxStatSpectralScanExtract(descriptor,it); 
                    
                        sscount++; 
	                //UserPrint("ss_cnt:rssic:mask %d, %d, %d, %d\n",sscount, rssic[0], rssic[1], chainMask);
                    }

                    if(sscount >= SASAMPLINGS)   
                    { 
                        break; 
                    } 
                } 
            } 
            else 
            { 
                // dump packet contents
	    		//
                if(ndump>0) 
			    {
				    UserPrint("\n");
                    LinkRxDump(descriptor, ndump, it%LinkRxLoopMany);
                }
			    //
			    // extract stats
			    //
			    LinkRxStatExtract(descriptor,it);

            }
			//
			// reset the descriptor so that we can use it again
			//
			RxDescriptorReset(descriptor);
#ifdef MEMORYREAD
			//
			// copy it back to the shared memory
			//
			MyMemoryWrite(mDescriptor,descriptor,dsize);
#endif
			//
			// need to queue the descriptor with the hardware
			//
            if(LinkRxDescriptorFifo)
            {
	            DeviceReceiveDescriptorPointer(mDescriptor);
            }
        } 
		//
		// descriptor not ready
		//
		else 
		{
			if(stop)
			{
				scount++;
				if(scount>200)
				{
				    break;
				}
			}
			it--;
			//
			// sleep every other time, need to keep up with fast rates
			//
			if(notdone>100)
			{
			    UserPrint(".");
//			    MyDelay(1);
				notdone=0;
			}
			else
			{
				notdone=1;      // this makes sure we never sleep
			}
        }
		//
		// check for message from cart telling us to stop
		// this is the normal terminating condition
		//
		pass++;
		if(pass>100)
		{
			if(done!=0)
			{
				isdone=(*done)();
				if(isdone!=0)
				{
					UserPrint(" %d Stop",it);
					if(stop==0)
					{
						stop=1;
						scount=0;
						behind=0;
					}
					//
					// immediate stop
					//
					if(isdone==2)
					{
						break;
					}
	//				break;
				}
			}
			pass=0;
		    //
		    // check for timeout
		    // rare terminating condition when cart crashes or disconnects
		    //
		    ctime=TimeMillisecond();

#if 1
            if( timeout>0 && ((endTime>startTime && (ctime>endTime || ctime<startTime)) || (endTime<startTime && ctime>endTime && ctime<startTime)))
		    {

			    UserPrint("%d Timeout",it);
			    break;
		    }
#endif
		}
    } 
    //
	// cleanup
	//

    if(_LinkRxSpectralScan) 
    { 
        //DeviceSpectralScanDisable(); 
        Ar9300SpectralScanDisable();
    } 

	DeviceReceiveDisable();

	LinkRxLoopDestroy(0);

    //
	// do data verify if requested
	//
	UserPrint(" %d\n",it);

	LinkRxStatFinish();

    return;
}
/**************************************************************************
* createTransmitPacket - create packet for transmission
*
*/
int LinkTxPacketCreate(
    unsigned int dataBodyLength,
    unsigned char *dataPattern,
    unsigned int dataPatternLength,
    unsigned char *bssid, unsigned char *source, unsigned char *destination,
	int specialTx100Pkt,
    int wepEnable)
{
	int it;
    unsigned char pPkt[MPACKET];
    WLAN_DATA_MAC_HEADER3  *pPktHeader;
	unsigned char *pBody;
    int agg;

    agg=0;
    //
    // how big is the packet?
	//
	//    802.11 header (not for tx100)
	//    IV (only if WEP enabled)
	//    packet body
	//
    pPktHeader=(WLAN_DATA_MAC_HEADER3 *)pPkt;
	_LinkTxLoopBufferSize[agg] = dataBodyLength;
	pBody=pPkt;
    if(!specialTx100Pkt) 
	{
        _LinkTxLoopBuffer[agg] += sizeof(WLAN_DATA_MAC_HEADER3);
        pBody += sizeof(WLAN_DATA_MAC_HEADER3);
        dataBodyLength-=sizeof(WLAN_DATA_MAC_HEADER);
	}
#ifdef UNUSED
    if(wepEnable) 
	{
        _LinkTxLoopBuffer[agg] += (WEP_IV_FIELD + 2);
        pBody += (WEP_IV_FIELD + 2);
    }
#else
	wepEnable=0;
#endif
    //
    // fill in the 802.11 packet header (including the IV field if wep enabled)
	//
	LinkTxPacketHeader(pPktHeader, wepEnable, bssid, source, destination, agg);
    //
	// fill in the packet body with the specified pattern
	//
	LinkTxPacketBody(pBody,dataBodyLength,dataPattern,dataPatternLength);
	//
	// reserve a block in the shared memory
	//
    _LinkTxLoopBuffer[agg] = MemoryLayout(_LinkTxLoopBufferSize[agg]);
    if(_LinkTxLoopBuffer[agg]==0) 
	{
        UserPrint("createTransmitPacket: unable to allocate memory for transmit buffer\n");
        return 0;
    }
    // 
	// write the packet to physical memory
    //
    MyMemoryWrite(_LinkTxLoopBuffer[agg], (unsigned int *)pPkt, _LinkTxLoopBufferSize[agg]);
//	UserPrint("buffer[%d] = %x %d\n",agg,_LinkTxLoopBuffer[agg],_LinkTxLoopBufferSize[agg]);

			UserPrint("Packet: ");
			for(it=0; it<60; it++)
			{
				UserPrint("%2x ",pPkt[it]);
			}
			UserPrint("\n");

    return _LinkTxLoopBufferSize[agg];
}