Beispiel #1
0
FINL
HRESULT ModulateACK11 ( MAC_ADDRESS Address, PVOID AckBuffer[], ULONG AckSize, ULONG* sample_size) 
{
    DOT11_MAC_ACK_FRAME AckFrame	= {0};
    AckFrame.FrameControl.Subtype	= SUBT_ACK;
    AckFrame.FrameControl.Type		= FRAME_CTRL;
    AckFrame.RecvAddress			= Address;
    AckFrame.Duration				= 0;

    bool bRet;
    if ( gPHYMode == PHY_802_11A ) {
        bRet = ModBuffer11a ((uchar*)&AckFrame, sizeof(AckFrame)-4, NULL, 0,
                                    (ushort) gDataRateK, 
                                    (COMPLEX8*)AckBuffer[0], AckSize, sample_size);
        PlotText ( "ack event", "ACK crc %8X", BB11aModCtx.CF_11aTxVector::crc32() );
    } else if ( gPHYMode == PHY_802_11B ) {
        // printf ( "modulate 11b ack size %d\n", sizeof(AckFrame)-4 );
        bRet = ModBuffer11b ((uchar*)&AckFrame, sizeof(AckFrame)-4, NULL, 0,
                                    (ushort) gDataRateK, 
                                    (COMPLEX8*)AckBuffer[0], AckSize, sample_size);
        PlotText ( "ack event", "ACK crc %8X", BB11bModCtx.CF_11bTxVector::crc32() );
    } else {
        bRet = ModBuffer11n ((uchar*)&AckFrame, sizeof(AckFrame)-4, NULL, 0,
                                    (ushort) gDataRateK, 
                                    (COMPLEX16**)AckBuffer, AckSize, sample_size);
        PlotText ( "ack event", "ACK crc %8X", BB11nModCtx.CF_11nTxVector::crc32() );
    }

    if ( bRet ) return S_OK;
    else return E_FAIL;
}
Beispiel #2
0
void plot_model_name(struct Plot *plot,
                    float xoff,float yoff,
	            char *dir,char *mag,
                    unsigned int color,unsigned char mask,
                    char *fontname,float fontsize,
                    void *txtdata) {

  char txt[256];
  float txbox[3];
  float lhgt;

  sprintf(txt,"Xy");
  txtbox(fontname,fontsize,strlen(txt),txt,txbox,txtdata);
  lhgt=4+txbox[2]-txbox[1];

  sprintf(txt,"APL MODEL");
  txtbox(fontname,fontsize,strlen(txt),txt,txbox,txtdata);
 
  PlotText(plot,NULL,fontname,fontsize,xoff-txbox[0]/2,yoff,
            strlen(txt),txt,color,mask,1);

  txtbox(fontname,fontsize,strlen(mag),mag,txbox,txtdata);
  PlotText(plot,NULL,fontname,fontsize,xoff-txbox[0]/2,yoff+lhgt,
            strlen(mag),mag,color,mask,1);

  txtbox(fontname,fontsize,strlen(dir),dir,txbox,txtdata);
  PlotText(plot,NULL,fontname,fontsize,xoff-txbox[0]/2,yoff+2*lhgt,
            strlen(dir),dir,color,mask,1);
}
Beispiel #3
0
void plot_time(struct Plot *plot,
               float xoff,float yoff,float wdt,float hgt,
               double stime,double etime,
               unsigned int color,unsigned char mask,
               char *fontname,float fontsize,
               void *txtdata) {
  int i;
  char txt[256];
  float txbox[3];
  char *month[]={"Jan","Feb","Mar","Apr","May","Jun",
               "Jul","Aug","Sep","Oct","Nov","Dec",0};
  char *tmeA="00:00:00 UT";
  char *tmeB="00:00:00 - 00:00:00 UT";
  char *tmeC="0";
  float cwdt;
  float x,y;
  int yr,mo,dy,shr,smt,ssc,ehr,emt,esc;
  double sec;

  txtbox(fontname,fontsize,strlen(tmeC),tmeC,txbox,txtdata);
  cwdt=txbox[0];

  TimeEpochToYMDHMS(etime,&yr,&mo,&dy,&ehr,&emt,&sec);
  esc=sec;
  TimeEpochToYMDHMS(stime,&yr,&mo,&dy,&shr,&smt,&sec);
  ssc=sec;

  sprintf(txt,"%.2d %s %d",dy,month[mo-1],yr);
  txtbox(fontname,fontsize,strlen(txt),txt,txbox,txtdata);
  x=xoff;
  y=yoff+txbox[2];
  for (i=0;txt[i] !=0;i++) {
    txtbox(fontname,fontsize,1,txt+i,txbox,txtdata);
    PlotText(plot,NULL,fontname,fontsize,x,
              y,1,txt+i,color,mask,1);
    if (isdigit(txt[i])) x+=cwdt;
    else x+=txbox[0];
  }

  if (stime==etime) sprintf(txt,"%.2d:%.2d:%.2d UT",shr,smt,ssc);
  else sprintf(txt,"%.2d:%.2d:%.2d - %.2d:%.2d:%.2d UT",
               shr,smt,ssc,ehr,emt,esc);

  if (stime==etime) txtbox(fontname,fontsize,strlen(tmeA),tmeA,txbox,txtdata);
  else txtbox(fontname,fontsize,strlen(tmeB),tmeB,txbox,txtdata);

  x=xoff+wdt-txbox[0];
  y=yoff+txbox[2];
  for (i=0;txt[i] !=0;i++) {
    txtbox(fontname,fontsize,1,txt+i,txbox,txtdata);
    PlotText(plot,NULL,fontname,fontsize,x,
              y,1,txt+i,color,mask,1);
    if (isdigit(txt[i])) x+=cwdt;
    else x+=txbox[0];
  }
}
Beispiel #4
0
int NCursesFrontend::PrintMessage(Message& msg, int row, int maxLines)
{
	const char* messageType[] = { "INFO    ", "WARNING ", "ERROR   ", "DEBUG   ", "DETAIL  "};
	const int messageTypeColor[] = { NCURSES_COLORPAIR_INFO, NCURSES_COLORPAIR_WARNING,
		NCURSES_COLORPAIR_ERROR, NCURSES_COLORPAIR_DEBUG, NCURSES_COLORPAIR_DETAIL };

	CString text;

	if (m_showTimestamp)
	{
		time_t rawtime = msg.GetTime() + g_Options->GetTimeCorrection();
		text.Format("%s - %s", *Util::FormatTime(rawtime), msg.GetText());
	}
	else
	{
		text = msg.GetText();
	}

	// replace some special characters with spaces
	for (char* p = (char*)text; *p; p++)
	{
		if (*p == '\n' || *p == '\r' || *p == '\b')
		{
			*p = ' ';
		}
	}

	int len = strlen(text);
	int winWidth = m_screenWidth - 8;
	int msgLines = len / winWidth;
	if (len % winWidth > 0)
	{
		msgLines++;
	}

	int lines = 0;
	for (int i = msgLines - 1; i >= 0 && lines < maxLines; i--)
	{
		int r = row - msgLines + i + 1;
		PlotLine(text + winWidth * i, r, 8, NCURSES_COLORPAIR_TEXT);
		if (i == 0)
		{
			PlotText(messageType[msg.GetKind()], r, 0, messageTypeColor[msg.GetKind()], false);
		}
		else
		{
			PlotText("        ", r, 0, messageTypeColor[msg.GetKind()], false);
		}
		lines++;
	}

	return lines;
}
Beispiel #5
0
int __cdecl main()
{
	HRESULT hr = S_OK;

	hr = DebugPlotInit();
	if (FAILED(hr))
		return -1;

	int count = 0;
	
	while(1)
	{
		WaitForViewer(INFINITE);

		for (int i = 0; i < BUF_SIZE; i++)
		{
			double phase = PI_2 * (count++) / PERIOD;
			double re = AMP * sin(phase);
			double im = AMP * cos(phase); 

			dataBuf[i].re = reBuf[i] = short(re);
			dataBuf[i].im = imBuf[i] = short(im);
		}
		
		PlotLine("real", reBuf, BUF_SIZE);
		PlotLine("imaginary", imBuf, BUF_SIZE);
		PlotDots("constellation", dataBuf, BUF_SIZE);
		PlotText("sample count", "%d\n", count);
	}

	DebugPlotDeinit();

	return 0;
}
Beispiel #6
0
FINL
HRESULT DataFrameAck11(PDOT11RFC1042ENCAP pWlanHeader, ULONG frameBufSize) {
    HRESULT hr;
    hr = E_FAIL;
    MAC2TxID* find;
    ULONG sample_size;
    
    find = MAC2TxID_Find(Root, pWlanHeader->MacHeader.Address2);	
    if (!find) {
        hr = ModulateACK11 (pWlanHeader->MacHeader.Address2, AckBuffer, AckSize, &sample_size);
        
        if (SUCCEEDED(hr)) {
            PACKETxID tid;
            memset(&tid, 0, sizeof(tid));
            hr = TransferBuffers(&tid, AckBuffer, GetNStream(), sample_size);

            if (SUCCEEDED(hr)) {
                find = MAC2TxID_Chain(&Root, pWlanHeader->MacHeader.Address2, &tid);
            }
            
            /*printf ( "ack modulated %d - %d (%02x:%02x:%02x:%02x:%02x:%02x)\n", 
                sample_size,
                TxID,
                pWlanHeader->MacHeader.Address2.Address[0], 
                pWlanHeader->MacHeader.Address2.Address[1],
                pWlanHeader->MacHeader.Address2.Address[2], 
                pWlanHeader->MacHeader.Address2.Address[3],
                pWlanHeader->MacHeader.Address2.Address[4], 
                pWlanHeader->MacHeader.Address2.Address[5]	);
            */
            PlotText ( "mac event", "missing ack cache......................" );

        }
    }else {
        hr = SoraURadioMimoTx(find->m_tid.m_radiono, find->m_tid.m_txid, find->m_tid.m_count);
    }

    PlotText ( "mac event", "Send ACK to (%02x:%02x:%02x:%02x:%02x:%02x)\n", 
                pWlanHeader->MacHeader.Address2.Address[0], 
                pWlanHeader->MacHeader.Address2.Address[1],
                pWlanHeader->MacHeader.Address2.Address[2], 
                pWlanHeader->MacHeader.Address2.Address[3],
                pWlanHeader->MacHeader.Address2.Address[4], 
                pWlanHeader->MacHeader.Address2.Address[5] );
    return hr;
}
Beispiel #7
0
void NCursesFrontend::PlotLine(const char * string, int row, int pos, int colorPair)
{
	BString<1024> buffer("%-*s", m_screenWidth, string);
	int len = buffer.Length();
	if (len > m_screenWidth - pos && m_screenWidth - pos < MAX_SCREEN_WIDTH)
	{
		buffer[m_screenWidth - pos] = '\0';
	}

	PlotText(buffer, row, pos, colorPair, false);
}
Beispiel #8
0
void plot_time_label(struct Plot *plot,
	             float xoff,float yoff,float wdt,float hgt,
                     float pole,int flip,char *sfx,float tme_shft,
	             float rad,float tick,
  	             unsigned int color,unsigned char mask,
                     char *fontname,float fontsize,
                     void *txtdata) {

  char txt[256];
  float txbox[3];
  float lon;
  float x,y,xtxt,ytxt,px,py;
  int i;
  
  if (flip==1) pole=-pole;

  for (i=0;i<24;i+=6) {  
 
     if ((i==0) || (i==12)) sprintf(txt,"%.2d %s",i,sfx);
     else sprintf(txt,"%.2d",i);
   

     lon=15*i-tme_shft;
     if (pole<0) lon=-lon;

     x=sin(lon*PI/180.0);
     y=cos(lon*PI/180.0);

 
     txtbox(fontname,fontsize,strlen(txt),txt,txbox,txtdata);
     xtxt=0;
     ytxt=0; 

     if (pole>0) {
         if (i==0) ytxt=txbox[2];
         else if (i==12) ytxt=txbox[1];
         else if (i==18) xtxt=txbox[0]; 
     } else {
         if (i==0) ytxt=txbox[2];
         else if (i==6) xtxt=txbox[0]; 
         else if (i==12) ytxt=txbox[1];     
     }     

     px=(xoff+wdt/2)+x*(rad+tick+2+xtxt);
     py=(yoff+hgt/2)+y*(rad+tick+2+ytxt); 

     if ((i % 12)==0) px=px-txbox[0]/2;
     else py=py+(txbox[2]-txbox[1])/2; 

     PlotText(plot,NULL,fontname,fontsize,px,py,
               strlen(txt),txt,color,mask,1);
  }
}
Beispiel #9
0
int TestTut1(bool bBlock, bool bPrint)
{
	HRESULT hr = S_OK;
	const int PRINT_COUNT = 64*1024;


	hr = DebugPlotInit();
	if (FAILED(hr))
		return -1;

	int count = 0;

	while(1)
	{
		bPrint = count % PRINT_COUNT == 0;

		if (bPrint)
			printf("Running %d\n", count);

		if (bBlock)
		{
			WaitForViewer(INFINITE);
			if (bPrint)
				printf("After WaitForViewer\n");
		}

		for (int i = 0; i < BUF_SIZE; i++)
		{
			double phase = PI_2 * (count++) / PERIOD;
			double re = AMP * sin(phase);
			double im = AMP * cos(phase); 

			dataBuf[i].re = reBuf[i] = short(re);
			dataBuf[i].im = imBuf[i] = short(im);
		}
		
		PlotLine("real", reBuf, BUF_SIZE);
		PlotLine("imaginary", imBuf, BUF_SIZE);
		PlotDots("constellation", dataBuf, BUF_SIZE);
		PlotText("sample count", "%d\n", count);

		if (bPrint)
			printf("After plot\n");
	}

	DebugPlotDeinit();

	return 0;
}
Beispiel #10
0
void plot_extra(struct Plot *plot,
                float xoff,float yoff,
	        struct CnvMapData *ptr,
                unsigned int color,unsigned char mask,
                char *fontname,float fontsize,
                void *txtdata) {

  char txt[256];
  float txbox[3];
  float lhgt;

  sprintf(txt,"Xy");
  txtbox(fontname,fontsize,strlen(txt),txt,txbox,txtdata);
  lhgt=4+txbox[2]-txbox[1];

  sprintf(txt,"order=%d",ptr->fit_order);
  PlotText(plot,NULL,fontname,fontsize,xoff,yoff,
            strlen(txt),txt,color,mask,1);
  sprintf(txt,"lat. bnd.=%g",ptr->latmin);
  PlotText(plot,NULL,fontname,fontsize,xoff,yoff+lhgt,
            strlen(txt),txt,color,mask,1);

  if (ptr->error_wt !=0) strcpy(txt,"err wt/");
  else strcpy(txt,"");
  if (ptr->model_wt !=0) strcat(txt,"norm mod wt");
  else strcat(txt,"fix mod wt");
  PlotText(plot,NULL,fontname,fontsize,xoff,yoff+2*lhgt,
            strlen(txt),txt,color,mask,1);
  sprintf(txt,"%s %d.%.2d",ptr->source,ptr->major_rev,ptr->minor_rev);
  PlotText(plot,NULL,fontname,fontsize,xoff,yoff+3*lhgt,
            strlen(txt),txt,color,mask,1);



  
}
Beispiel #11
0
void plot_chi(struct Plot *plot,
                float xoff,float yoff,
                struct CnvMapData *ptr,
	        int degfree,int degfree_dat,
                unsigned int color,unsigned char mask,
                char *txtfontname,char *symfontname,float fontsize,
                void *txtdata) {

  char txt[256];
  float txbox[3];
  float lhgt;

  sprintf(txt,"Xy");
  txtbox(txtfontname,fontsize,strlen(txt),txt,txbox,txtdata);
  lhgt=4+txbox[2]-txbox[1];

  txtbox(symfontname,fontsize,strlen("c"),"c",txbox,txtdata);
 

  PlotText(plot,NULL,symfontname,fontsize,xoff,yoff,
            strlen("c"),"c",color,mask,1);
  PlotText(plot,NULL,txtfontname,fontsize*0.8,xoff+txbox[0],yoff-lhgt*0.2,
            strlen("2"),"2",color,mask,1);
  sprintf(txt,"/%d=%.1g",degfree,ptr->chi_sqr/degfree);
  PlotText(plot,NULL,txtfontname,fontsize,xoff+txbox[0]*2,yoff,
            strlen(txt),txt,color,mask,1);


  PlotText(plot,NULL,symfontname,fontsize,xoff,yoff+lhgt,
            strlen("c"),"c",color,mask,1);
  PlotText(plot,NULL,txtfontname,fontsize*0.8,xoff+txbox[0],yoff+lhgt*0.8,
            strlen("2"),"2",color,mask,1);
  sprintf(txt,"/%d=%.1g",degfree_dat,ptr->chi_sqr/degfree_dat);
  PlotText(plot,NULL,txtfontname,fontsize,xoff+txbox[0]*2,yoff+lhgt,
            strlen(txt),txt,color,mask,1);
}
Beispiel #12
0
bool Sample()
{
	HRESULT hr = S_OK;

	hr = ::DebugPlotInit();
	if (FAILED(hr))
		return false;

	const int COMPLEX_16M_BYTES = 16*1024*1024/sizeof(COMPLEX16);
	COMPLEX16 * dataToProcess = new COMPLEX16[COMPLEX_16M_BYTES];

	PrepareData(dataToProcess, COMPLEX_16M_BYTES, 4*1024);		// generate a sine wave data and write to a 4k buffer

	// add a special *interesting data* at index 256k
	int interestDataIdx = 32*1024;
	dataToProcess[interestDataIdx].re = 30000;
	dataToProcess[interestDataIdx].im = 30000;

	__int64 counter = 0;
	DWORD timer = 0;
	DWORD lastTimer = 0;

	do
	{
		while(1)	// Periodically write data in 4k buffer to source trace buffer util the buffer is full (16M bytes)
		{
			int numWritten;
			hr = ::TracebufferWriteData(dataToProcess, COMPLEX_16M_BYTES, &numWritten);
			if (hr == E_END_OF_BUF)
			{
				assert(numWritten <= COMPLEX_16M_BYTES);
				break;
			}
		}

		bool endOfSourceBuf = false;
		while(!endOfSourceBuf)
		{
			int numRead;

			// syncronize with viewer, if the plotter plot too much data, wait for viewer will block until viewer read the data
			//::WaitForViewer(INFINITE);

			// process PROCESS_SIZE COMPLEX16 every time
			hr = ::TracebufferReadData(readBuf, PROCESS_SIZE, &numRead);
			if (hr == E_END_OF_BUF)	// source trace buffer is empty
			{
				endOfSourceBuf = true;
				assert(numRead <= PROCESS_SIZE);
			}

			if (numRead == 0)
				continue;

			// process each COMPLEX
			double avgEnergy = 0.0;
			for (int i = 0; i < numRead; i++)
			{
				int re = readBuf[i].re;
				int im = readBuf[i].im;

				if (re > 20000)	// find our interesting data!!!
				{
					//PauseViewer();
					//::OutputDebugString(L"Pause viewer");
				}

				// calculate energy
				double energyF = log(double(re*re + im*im)) - 10;
				energyF = max(energyF, 0.0);
				avgEnergy += energyF;
				energyBuf[i] = (int)energyF;

				// set re & im value
				reBuf[i] = re;
				imBuf[i] = im;
			}
			avgEnergy /= numRead;

			// generate a fake spectrum using rand()
			GenSpectrum();
			
			// plot
			PlotLine("re part", reBuf, numRead);
			PlotLine("im part", imBuf, numRead);
			PlotLine("energy", energyBuf, numRead);
			PlotDots("dots", readBuf, numRead);
			PlotText("text", "%f\n", avgEnergy);
			Log("log", "%I64d\n", counter++);

			if (1)
			{
				static int lowFrequencyData = 0;
				//::PlotLine("low frequency", &lowFrequencyData, 1);
				lowFrequencyData = (lowFrequencyData+1)%100;
				lastTimer = timer;
				::PlotSpectrum("spectrum 63", spectrumBuf, SPECTRUM_SIZE);
				::PlotSpectrum("spectrum 32", spectrumBuf, 32);
			}
			::Sleep(15);

		}

		::TracebufferClear();
	} while(1);

	delete [] dataToProcess;

	DebugPlotDeinit();

	return true;
}
Beispiel #13
0
bool ProcessDot11Frame(UCHAR *frameBuf, ULONG frameBufSize )
{
    
    PDOT11RFC1042ENCAP pWlanHeader = (PDOT11RFC1042ENCAP)frameBuf;
        
    if (pWlanHeader->MacHeader.FrameControl.Type    == FRAME_DATA && 
        pWlanHeader->MacHeader.FrameControl.Subtype == SUBT_DATA ) 
    {

        static USHORT CurRecvSeqNo = 0xffff;

        int fTargetFrame = 0;
        
        // Try to send some ACK
        if ( (memcmp( MACAddress.Address, 
                     pWlanHeader->MacHeader.Address1.Address, 
                     MAC_ADDRESS_LENGTH) == 0) )
        {
            DataFrameAck11(pWlanHeader, frameBufSize);
            UpdateLastRate();
            PlotText ( "mac event", "receive a packet - seq (%d) size (%d) rate (%u).................................",
                pWlanHeader->MacHeader.SequenceControl.SequenceNumber,
                frameBufSize,
                lastRate
            );

            fTargetFrame = 1;
        }
        
        if ( fTargetFrame ||
             ETH_IS_BROADCAST (pWlanHeader->MacHeader.Address1.Address) )
        {
            UpdateLastRate();
            nDataPacketRcvCnt ++;
            
            if (CurRecvSeqNo  != pWlanHeader->MacHeader.SequenceControl.SequenceNumber 
                && pWlanHeader->MacHeader.SequenceControl.FragmentNumber == 0 ) {			
                if ( frameBufSize < sizeof(DOT11RFC1042ENCAP)) {
                    return S_OK;
                }
                
                CurRecvSeqNo   = pWlanHeader->MacHeader.SequenceControl.SequenceNumber;
                MAC_ADDRESS			destAddr;
                MAC_ADDRESS			srcAddr;
                UINT16				Type;
                ULONG				Offset;
                PETHERNET_HEADER	pEthernetHeader;

                /* ad hoc mode
                destAddr = pWlanHeader->MacHeader.Address1;
                srcAddr  = pWlanHeader->MacHeader.Address2;


                lastMACDst   = pWlanHeader->MacHeader.Address1;
                lastMACSrc   = pWlanHeader->MacHeader.Address2;
                lastMACBssid = pWlanHeader->MacHeader.Address3;
                */

                /* AP mode */
                if ( OpMode == CLIENT_MODE ) {
                    destAddr = pWlanHeader->MacHeader.Address1;
                    srcAddr  = pWlanHeader->MacHeader.Address3;
                    Type     = pWlanHeader->Type;

                    lastMACDst   = pWlanHeader->MacHeader.Address1;
                    lastMACSrc   = pWlanHeader->MacHeader.Address3;
                    lastMACBssid = pWlanHeader->MacHeader.Address2;
                } else {
                    destAddr = pWlanHeader->MacHeader.Address1;
                    srcAddr  = pWlanHeader->MacHeader.Address2;
                    Type     = pWlanHeader->Type;					
                    
                    lastMACDst	 = pWlanHeader->MacHeader.Address1;
                    lastMACSrc	 = pWlanHeader->MacHeader.Address2;
                    lastMACBssid = pWlanHeader->MacHeader.Address3;
                }

                Offset   = sizeof(DOT11RFC1042ENCAP) - sizeof(ETHERNET_HEADER);
                pEthernetHeader = (PETHERNET_HEADER)(frameBuf + Offset);
                pEthernetHeader->destAddr = destAddr;
                pEthernetHeader->srcAddr = srcAddr;
                pEthernetHeader->Type = Type;

                PlotText ( "mac event", "Indicate packet seq (%d)", 
                    CurRecvSeqNo );

                HRESULT hr;
                hr = SoraUIndicateRxPacket(frameBuf + Offset, frameBufSize - Offset - 4 ); // remove FCS

                UpdateEnergy ();
                return SUCCEEDED(hr);
            }
        }
        else {
            nInterferenceCnt ++;
        }
    }
    else
    if (pWlanHeader->MacHeader.FrameControl.Type == FRAME_CTRL &&
        pWlanHeader->MacHeader.FrameControl.Subtype == SUBT_ACK) {
        
        if (LastPACKETxID) {
            if (memcmp(MACAddress.Address, 
                pWlanHeader->MacHeader.Address1.Address,
                MAC_ADDRESS_LENGTH))
                return true;

            struct PACKETxID* ptid;
            ptid = LastPACKETxID;
            LastPACKETxID = NULL;

            nAckRcvCnt ++;
            
            if ( ptid->m_packet ) {
                SoraUCompleteTxPacket(ptid->m_packet, 
                    STATUS_SUCCESS);
            }
            
            debug_printf("Complete Send Packet: [%08x], TxID: [%d], TX succeed\n", 
                ptid->m_packet, 
                ptid->m_tid.m_txid[0]);
            
            switch(ptid->m_status) {
            case PACKET_CAN_TX:
                FreeTxResource(&ptid->m_tid);
                break;
            default:
                break;
            }
            free(ptid);
        }
    }
    else
    if (pWlanHeader->MacHeader.FrameControl.Type    == FRAME_MAN &&
        pWlanHeader->MacHeader.FrameControl.Subtype == SUBT_BEACON)
    {
        ProcessBeacon ((PDOT11_MAC_BEACON)pWlanHeader);
    }
    else 
    if (pWlanHeader->MacHeader.FrameControl.Type    == FRAME_MAN )
    {
        if ( memcmp( MACAddress.Address, pWlanHeader->MacHeader.Address1.Address, MAC_ADDRESS_LENGTH) == 0 )
        {
            if ( pWlanHeader->MacHeader.FrameControl.Subtype == SUBT_AUTH ) // auth
            {
                DataFrameAck11 ( pWlanHeader, frameBufSize );

                if ( assoState == ASSO_NONE ) {
                    assoState = ASSO_AUTH;
                }
            } else if ( pWlanHeader->MacHeader.FrameControl.Subtype == SUBT_ASSO ) // asso
            {
                DataFrameAck11 ( pWlanHeader, frameBufSize );

                if ( assoState == ASSO_AUTH || 
                     assoState == ASSO_NONE 
                ) {
                    assoState = ASSO_DONE;
                }
            } else if ( pWlanHeader->MacHeader.FrameControl.Subtype == SUBT_DEASSO || // deassociate
                        pWlanHeader->MacHeader.FrameControl.Subtype == SUBT_DEAUTH )  // deauth
            {
                assoState = ASSO_NONE;  
            }
        }	
    }

    return true;
}
Beispiel #14
0
BOOLEAN MAC11n_Receive (void*) {
    // Alias to context variable
    static SoraPerformanceCounter& decoding_data_stopwatch = BB11nDemodCtx.CF_TimeStamps::decoding_data_stopwatch();
    static ushort& total_symbols = BB11nDemodCtx.CF_11aRxVector::total_symbols();
    static ushort& frame_length = BB11nDemodCtx.CF_11aRxVector::frame_length();

    uint nWaitCounter = 0;
    if ( current_state == MAC_STATE_RX) {
        nWaitCounter = nDIFS + nBackoffCounter;
    } else { 
        // we are waiting for an ACK
        nWaitCounter = nACKTimeout_11n;
    }

    while (1) {
        pBB11nRxSource->Process ();
        ulong err = BB11nDemodCtx.CF_Error::error_code();
    
        if ( err == E_ERROR_SUCCESS ) {
            nIdleCnt ++;
            continue;
        }

        // Any event happened
        if ( err == E_ERROR_FRAME_OK ) {
            // One frame is received
            decoding_data_stopwatch.Stop();
            //TraceOutput ( "mac event: receive a packet - symbol (%hu) rate (%u) samplerate (%u) expect (%u ns) decoding (%llu ns)\n",
            //    total_symbols,
            //    BB11nDemodCtx.GetDataRate(),
            //    gSampleRate,
            //    4 * 1000 * (total_symbols + 4), // total_symbols includes 1 for HT_SIG, 1 for HT_STF, 2 for HT_LTF
            //                                    // decoding_data_stopwatch start from L_LTF, the diff is 4 symbols
            //    decoding_data_stopwatch.GetElapsedNanoseconds()
            //);
            ProcessDot11Frame(FrameBuffer, frame_length);
        } else if ( err == E_ERROR_CRC32_FAIL) {
            err_stat[2] ++;
        } else if ( err == E_ERROR_PLCP_HEADER_FAIL) {
            err_stat[1] ++;
        } else if ( err == BK_ERROR_TIMESTAMP_DROPS) {
            err_stat[3] ++;
            pBB11nRxSource->Seek(ISource::END_POS);
        } else if ( err == E_ERROR_CS_TIMEOUT ) {
            // Channel clean
            BB11nDemodCtx.ResetCarrierSense();
            pBB11nCarrierSense->Reset ();

            if ( nWaitCounter > 0) {
                nWaitCounter --; // just backoff
                continue;
            } else {
                if ( current_state == MAC_STATE_WAITACK ) {
                    nBackoffCounter = 2 * rand () % nBackoffWnd;

                    current_state = MAC_STATE_RX;
                } else {
                    // Ready to tx
                    current_state = MAC_STATE_TX;
                }
                
                break;
            }

        }

        // Flush the brick graph, make related brick threads safe to reset
        pBB11nRxSource->Flush();
        
        //
        // Reset context
        BB11nDemodCtx.Reset();
        pBB11nRxSource->Reset();

        if (   err == E_ERROR_FRAME_OK
            || err == E_ERROR_CRC32_FAIL
            || err == E_ERROR_PLCP_HEADER_FAIL)
        {
            // seek to the rx stream end
            int nMove = pBB11nRxSource->Seek(ISource::END_POS);
            if (BB11nDemodCtx.CF_Error::error_code() == BK_ERROR_HARDWARE_FAILED)
            {
                TraceOutput("[ERROR] Failed to seek, hardware not in good condition!\n");
                BB11nDemodCtx.Reset();
                return TRUE;
            }

            // to do - if HEADER fails, we need to advance an entire frame.
            //
            // We have received anything
            // 
            if ( current_state == MAC_STATE_WAITACK ) {
                current_state = MAC_STATE_RX;

                nBackoffCounter = nBackoffCounter << 1; // a simple way for BEB

                break;
            } else {
                // we have paused during backoff, continue
                    
                if ( nWaitCounter < (uint) nBackoffCounter ) 
                    nBackoffCounter = nWaitCounter;

                nWaitCounter = nDIFS + nBackoffCounter;

                continue;
            }
        } else {
            PlotText ( "mac event", "error not fail %X", err );
        }
    }

    return TRUE;
}
Beispiel #15
0
void NCursesFrontend::PrintKeyInputBar()
{
	int queueSize = CalcQueueSize();
	int inputBarRow = m_screenHeight - 1;

	if (!m_hint.Empty())
	{
		time_t time = Util::CurrentTime();
		if (time - m_startHint < 5)
		{
			PlotLine(m_hint, inputBarRow, 0, NCURSES_COLORPAIR_HINT);
			return;
		}
		else
		{
			SetHint(nullptr);
		}
	}

	switch (m_inputMode)
	{
	case normal:
		if (m_groupFiles)
		{
			PlotLine("(Q)uit | (E)dit | (P)ause | (R)ate | (W)indow | (G)roup | (T)ime", inputBarRow, 0, NCURSES_COLORPAIR_KEYBAR);
		}
		else
		{
			PlotLine("(Q)uit | (E)dit | (P)ause | (R)ate | (W)indow | (G)roup | (T)ime | n(Z)b", inputBarRow, 0, NCURSES_COLORPAIR_KEYBAR);
		}
		break;
	case editQueue:
	{
		const char* status = nullptr;
		if (m_selectedQueueEntry > 0 && queueSize > 1 && m_selectedQueueEntry == queueSize - 1)
		{
			status = "(Q)uit | (E)xit | (P)ause | (D)elete | (U)p/(T)op";
		}
		else if (queueSize > 1 && m_selectedQueueEntry == 0)
		{
			status = "(Q)uit | (E)xit | (P)ause | (D)elete | dow(N)/(B)ottom";
		}
		else if (queueSize > 1)
		{
			status = "(Q)uit | (E)xit | (P)ause | (D)elete | (U)p/dow(N)/(T)op/(B)ottom";
		}
		else
		{
			status = "(Q)uit | (E)xit | (P)ause | (D)elete";
		}

		PlotLine(status, inputBarRow, 0, NCURSES_COLORPAIR_KEYBAR);
		break;
	}
	case downloadRate:
		BString<100> hint("Download rate: %i", m_inputValue);
		PlotLine(hint, inputBarRow, 0, NCURSES_COLORPAIR_KEYBAR);
		// Print the cursor
		PlotText(" ", inputBarRow, 15 + m_inputNumberIndex, NCURSES_COLORPAIR_CURSOR, true);
		break;
	}
}
Beispiel #16
0
BOOLEAN MAC11b_Receive (void*) {

    uint nWaitCounter;
    if ( current_state == MAC_STATE_RX) {
        nWaitCounter = nDIFS + nBackoffCounter;
    } else { 
        // we are waiting for an ACK
        nWaitCounter = nACKTimeout;
    }
    
    while (1) {
        pBB11bRxSource->Process ();
        ulong err = BB11bDemodCtx.CF_Error::error_code();

        if ( err != E_ERROR_SUCCESS ) {
            // Any event happened
            if (  err == E_ERROR_FRAME_OK ) {
                // One frame is received
                ProcessDot11Frame(FrameBuffer, BB11bDemodCtx.CF_11bRxVector::frame_length());
            } else if ( err == E_ERROR_CS_TIMEOUT || err == E_ERROR_SYNC_TIMEOUT ) {
                // Channel clean
                BB11bDemodCtx.reset ();
                pBB11bRxSource->Reset ();

                if ( nWaitCounter > 0) {
                    nWaitCounter --; // just backoff
                    continue;
                } else {
                    if ( current_state == MAC_STATE_WAITACK ) {
                        nBackoffCounter = 2 * rand () % nBackoffWnd;

                        current_state = MAC_STATE_RX;
                    } else {
                        // Ready to tx
                        current_state = MAC_STATE_TX;
                    }
                
                    break;
                }
            }

            //
            // Reset context
            BB11bDemodCtx.reset ();
            pBB11bRxSource->Reset ();

            if (   err == E_ERROR_FRAME_OK
                || err == E_ERROR_CRC32_FAIL
                || err == E_ERROR_PLCP_HEADER_FAIL)
            {
                // seek to the rx stream end
                int nMove = pBB11bRxSource->Seek(ISource::END_POS);

                // to do - if HEADER fails, we need to advance an entire frame.
                //
                // We have received anything
                // 
                if ( current_state == MAC_STATE_WAITACK ) {
                    current_state = MAC_STATE_RX;

                    nBackoffCounter = nBackoffCounter << 1; // a simple way for BEB

                    break;
                } else {
                    // we have paused during backoff, continue
                    
                    if ( nWaitCounter < (uint) nBackoffCounter ) 
                        nBackoffCounter = nWaitCounter;

                    nWaitCounter = nDIFS + nBackoffCounter;

                    continue;
                }
            } else {
                PlotText ( "mac event", "error not fail %X", err );
            }
        } else {
            nIdleCnt ++;
        }
    }	
    return TRUE;
}
Beispiel #17
0
void plot_pos(struct Grplot *grplot,int p,
              struct posdata *pos,double stime,double etime,int mode,
              unsigned int color,float width,char *fontname,
              float fontsize) {
 float *P;
 int i;
 int flg;
 float ylim=0;  
 double ymajor=100;
 double yminor=100/5;
 double y;   
 int km=0;
 float mult=1;
 float ox=0,oy=0,px=0,py=0;
 float tx,ty;
 unsigned int gry;
 unsigned int red;
 unsigned int blue;

 struct PlotDash *dashA;
 struct PlotDash *dashB;

 dashA=PlotMakeDashString("4 4");
 dashB=PlotMakeDashString("4 2 1 2");

 gry=PlotColor(128,128,128,255);
 red=PlotColor(255,0,0,255);
 blue=PlotColor(0,0,255,255);

 GrplotYzero(grplot,p,-1,1,gry,0x0f,width,NULL); 
 
 for (i=0;i<pos->cnt;i++) {
     if (mode==0) P=&pos->PGSM[3*i]; 
     else P=&pos->PGSE[3*i]; 
  
     if (fabs(P[0])>500) continue;
     if (fabs(P[1])>500) continue;
     if (fabs(P[2])>500) continue;

     if (fabs(P[0])>ylim) ylim=fabs(P[0]);
     if (fabs(P[1])>ylim) ylim=fabs(P[1]);
     if (fabs(P[2])>ylim) ylim=fabs(P[2]);
   }
   if (ylim<2) { /* plot in km */
     km=1;
     mult=6370.0;
     ylim=ylim*6370;
     y=0;
     while (y<ylim) y+=1000;
     ylim=y;
     ymajor=1000;
     yminor=1000/5;
     
   } else if (ylim<60) {
     y=0;
     while (y<ylim) y=y+20;
     ylim=y;
     ymajor=20;
     yminor=20/4;
   } else {
     y=0;
     while (y<ylim) y=y+50;
     ylim=y;
     ymajor=100;
     yminor=100/5;
   }

   GrplotYaxis(grplot,p,-ylim,ylim,ymajor,yminor,0x03,color,0x0f,width);
   if (km==0) {
      GrplotYaxisLabel(grplot,p,-ylim,ylim,ymajor,0x03,label_val,NULL,fontname,
                     fontsize,color,0x0f);
      GrplotYaxisTitle(grplot,p,0x03,strlen("Pos (RE)"),"Pos (RE)",
                     fontname,fontsize,color,0x0f);
   } else {
      GrplotYaxisLabel(grplot,p,-ylim,ylim,ymajor,0x03,label_km,NULL,fontname,
                     fontsize,color,0x0f);
      GrplotYaxisTitle(grplot,p,0x03,strlen("Pos (km)"),"Pos (km)",
                     fontname,fontsize,color,0x0f);
   }
   GrplotGetPoint(grplot,p,0,1,0,1,0,1,&tx,&ty);
   PlotLine(grplot->plot,tx+5,ty+5,tx+20,ty+5,color,0x0f,width,NULL);
   PlotLine(grplot->plot,tx+35,ty+5,tx+50,ty+5,red,0x0f,width,dashA);
   PlotLine(grplot->plot,tx+65,ty+5,tx+80,ty+5,blue,0x0f,width,dashB);

   PlotText(grplot->plot,NULL,fontname,fontsize,
             tx+22,ty+10,strlen("X"),"X",blue,0x0f,1);
   PlotText(grplot->plot,NULL,fontname,fontsize,
             tx+52,ty+10,strlen("Y"),"Y",blue,0x0f,1);
   PlotText(grplot->plot,NULL,fontname,fontsize,
             tx+82,ty+10,strlen("Z"),"Z",blue,0x0f,1);


  flg=0;
  for (i=0;i<pos->cnt;i++) { 
    if (mode==0) P=&pos->PGSM[3*i]; 
    else P=&pos->PGSE[3*i];  
    if (fabs(P[0])<500) {
      px=pos->time[i]-stime;
      py=P[0]*mult;
      if (flg==1) GrplotLine(grplot,p,ox,oy,px,py,
                           0,etime-stime,-ylim,ylim,
                           color,0x0f,width,NULL);
      ox=px;
      oy=py;
      flg=1;
    } else flg=0;
  }

  flg=0;
  for (i=0;i<pos->cnt;i++) { 
    if (mode==0) P=&pos->PGSM[3*i]; 
    else P=&pos->PGSE[3*i];  
    if (fabs(P[1])<500) {
      px=pos->time[i]-stime;
      py=P[1]*mult;
      if (flg==1) GrplotLine(grplot,p,ox,oy,px,py,
                           0,etime-stime,-ylim,ylim,
                           red,0x0f,width,dashA);
      ox=px;
      oy=py;
      flg=1;
    } else flg=0;
  }

  flg=0;
  for (i=0;i<pos->cnt;i++) { 
    if (mode==0) P=&pos->PGSM[3*i]; 
    else P=&pos->PGSE[3*i];  
    if (fabs(P[2])<500) {
      px=pos->time[i]-stime;
      py=P[2]*mult;
      if (flg==1) GrplotLine(grplot,p,ox,oy,px,py,
                           0,etime-stime,-ylim,ylim,
                           blue,0x0f,width,dashB);
      ox=px;
      oy=py;
      flg=1;
    } else flg=0;
  }
  PlotFreeDash(dashA);
  PlotFreeDash(dashB);

}