Ejemplo n.º 1
0
void RadioStart(BlinkParams *params) {
	// Initialize Sora user mode extension
    BOOLEAN succ = SoraUInitUserExtension("\\\\.\\HWTest");
    if (!succ) 
    {
        printf("Error: fail to find a Sora UMX capable device!\n");
        exit(1);
    }

	// always start radio first, it will reset radio to the default setting
    SoraURadioStart(params->radioParams.radioId);

    SoraURadioSetRxPA(params->radioParams.radioId, params->radioParams.RXpa);
    SoraURadioSetRxGain(params->radioParams.radioId, params->radioParams.RXgain);
    SoraURadioSetTxGain(params->radioParams.radioId, params->radioParams.TXgain);
    SoraURadioSetCentralFreq(params->radioParams.radioId, params->radioParams.CentralFrequency);
	SoraURadioSetFreqOffset(params->radioParams.radioId, params->radioParams.FreqencyOffset);					
    SoraURadioSetSampleRate(params->radioParams.radioId, params->radioParams.SampleRate);
	params->TXBuffer = NULL;
	params->pRxBuf = NULL;

	// DEBUG
	printf("RadioID: %ld, RX_PA: %ld, RX_Gain: %ld, TX_Gain: %ld, Central Freq: %ld, Freq Offset: %ld, Sample Rate: %ld\n", 
		params->radioParams.radioId, params->radioParams.RXpa, params->radioParams.RXgain,
		params->radioParams.TXgain, params->radioParams.CentralFrequency, params->radioParams.FreqencyOffset,
		params->radioParams.SampleRate);
}
Ejemplo n.º 2
0
int __cdecl main(int argc, const char *argv[])
{
	if ( ParseCmdLine (argc, argv) == false )
	{
		usage();
		return 0;
	}

	if ( CheckParameters () == false ) {
		return 0;
	}

	// init DebugPlot library
	DebugPlotInit();

	InitializeTimestampInfo ( &tsinfo, true );
	
	// begin receive or transmit packets
	if (!SoraUInitUserExtension("\\\\.\\HWTest")) {
		printf ( "Error: fail to find the hwtest driver!\n" );
		getchar();
		return -1;
	}

	if ( bWarning ) {
		printf ( "Warnings - press enter to continue...\n" );
		getchar();
	}	
	
	// clear screen	
	system( "cls" );	
	
	// Start the main procedure
	Dot11_main ();

	// clear screen
	// system( "cls" );	
	
	SoraUCleanUserExtension();
	DebugPlotDeinit();

    return 0;
}
Ejemplo n.º 3
0
int __cdecl main(int argc, const char *argv[])
{
    HRESULT hr;

	if ( ParseCmdLine (argc, argv) == false )
	{
		usage();
		return 0;
	}

	// init DebugPlot library
	DebugPlotInit();

    // init sora timestamp library
	InitializeTimestampInfo ( &tsinfo, false );

    do {
    	// begin receive or transmit packets
    	if (!SoraUInitUserExtension("\\\\.\\HWTest")) {
    		printf ( "Error: fail to find the hwtest driver!\n" );
    		break;
    	}

        // start UMX
        // Map Rx Sample Buffer
        hr = SoraURadioMapRxSampleBuf(TARGET_RADIO, &RxBuffer, &RxBufferSize);
        if (FAILED(hr)) {
            printf ( "Fail to map rx buffer!\n" );
       		break;
        }   
    
        // Alloc Tx Sample Buffer
        SampleBuffer = SoraUAllocBuffer(SampleSize);
        if (!SampleBuffer) {
            printf ( "Fail to allocate Tx buffer!\n" );
            break;
        }   
    
        hr = SoraURadioAllocRxStream(&RxStream, TARGET_RADIO, (PUCHAR)RxBuffer, RxBufferSize);
        if (FAILED(hr)) {
            printf ( "Fail to allocate a RX stream!\n" );
            break;
        }

        printf ( "Configure radio...\n" );
        
        // configure radio parameters properly
        ConfigureRadio ();

		if ( sine.Create ( SampleBuffer, SampleSize ) ) {
			printf ("Sine source starts...\n" );
			sine.Start ();
		}
      
        // enter the message loop
        process_kb (); 
        
    }    while (false);

    
    sine.Stop ();
        
    SoraURadioReleaseRxStream(&RxStream, TARGET_RADIO);
    
    if (SampleBuffer) {
        SoraUReleaseBuffer(SampleBuffer);
        SampleBuffer = NULL;
    }
    
    if (RxBuffer) {
        hr = SoraURadioUnmapRxSampleBuf(TARGET_RADIO, RxBuffer);
    }
    
	SoraUCleanUserExtension();
	DebugPlotDeinit();

    return 0;
}
Ejemplo n.º 4
0
Archivo: dut.c Proyecto: PaulJing/Sora
void DoDump(HANDLE hDevice, ULONG* RadioNo, ULONG Count, char UseTimeStamp, PCSTR szDumpFileName) {

	ULONG mask = 0;
	ULONG i;
	HRESULT err = S_OK;
	PVOID buf[MAX_RADIO_NUMBER] = { 0 };
	ULONG len[MAX_RADIO_NUMBER] = { 0 };
	SORA_RADIO_RX_STREAM RxStream[MAX_RADIO_NUMBER] = { 0 };
	do {
		if (!SoraUInitUserExtension("\\\\.\\HWTest")) {
			err = E_FAIL;
			break;
		}
		for(i=0; i < Count; i++) {
			if (mask & RadioNo[i]) {
				err = E_FAIL;
				break;
			}
			if (SoraURadioMapRxSampleBuf(RadioNo[i], &buf[i], &len[i]) != S_OK) {
				err = E_FAIL;
				break;
			}
			if (SoraURadioAllocRxStream(&RxStream[i], RadioNo[i], buf[i], len[i]) != S_OK) {
				err = E_FAIL;
				break;
			}
		}
		if (err == S_OK) {
			// raise to realtime to dump
			char** dump_buf = __MALLOC(sizeof(char*) * Count);
			memset(dump_buf, 0, sizeof(char*) * Count);
			for(i=0; i < Count; i++) {
				dump_buf[i] = __MALLOC(DUMP_BUFFER_SIZE);
				if (!dump_buf[i]) {
					err = E_FAIL;
					break;
				}
			}
			SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
			SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
			
			if (err == S_OK) {
				ULONG max_timestamp;
				ULONG last_timestamp = 0;
				ULONG clear_count = 0;				
#if 1
				if (UseTimeStamp) {
					for(clear_count=0; clear_count < 2; clear_count++) {
						for(i=0; i < Count; i++) {
							last_timestamp = ClearRxBuf(&RxStream[i]);
							printf("radio: %d, last_timestamp: 0x%08x\n", RadioNo[i], last_timestamp);
							if (i) {
								if (last_timestamp > max_timestamp) {
									if (last_timestamp - max_timestamp > 0x7fffffff) { 
										// timestamp overflow !!! max_timestamp is still the max, do nothing
									}
									else 
										max_timestamp = last_timestamp;
								}
								else
								if (max_timestamp > last_timestamp) {
									if (max_timestamp - last_timestamp > 0x7fffffff) { 
										// timestamp overflow !!! 
										max_timestamp = last_timestamp;
									}
								}
							}
							else
								max_timestamp = last_timestamp;
						}
					}
					printf("max_timestamp: 0x%08x\n", max_timestamp);

					DumpFromTimeStamp(RadioNo, RxStream, dump_buf, Count, max_timestamp + DUMP_BUFFER_DELAY_TIMESTAMP, UseTimeStamp, szDumpFileName);
				}
				else {
					last_timestamp = ClearRxBuf(&RxStream[0]);

					DumpFromTimeStamp(RadioNo, RxStream, dump_buf, Count, 0, UseTimeStamp, szDumpFileName);
				}
			}

#endif

#if 0
timestamp_for_dump:
				for(i=0; i < Count; i++) {					
					last_timestamp = ClearRxBuf(&RxStream[i]);
					printf("last_timestamp: 0x%08x\n", last_timestamp);
					if (i) {
						if (last_timestamp > max_timestamp) {
							if (last_timestamp - max_timestamp > 0x7fffffff) { // timestamp overflow !!!
								printf("timestamp overflow, retry...\n");
								goto timestamp_for_dump;
							}
							max_timestamp = last_timestamp;
						}
						else
						if (max_timestamp > last_timestamp) {
							if (max_timestamp - last_timestamp > 0x7fffffff) { // timestamp overflow !!! 
								printf("timestamp overflow, retry...\n");
								goto timestamp_for_dump;
							}
						}
						else
						if (last_timestamp < min_timestamp)
							min_timestamp = last_timestamp;
					}
					else {
						min_timestamp = last_timestamp;
						max_timestamp = last_timestamp;
					}					
				}
				printf("max_timestamp: 0x%08x, min_timestamp: 0x%08x\n", max_timestamp, min_timestamp);
				if ((max_timestamp - min_timestamp) > (DUMP_BUFFER_SIZE/sizeof(RX_BLOCK))/2) {
					printf("prevent out of sync, retry...\n");
					goto timestamp_for_dump;
				}					
				DumpFromTimeStamp(RadioNo, RxStream, dump_buf, Count, max_timestamp + DUMP_BUFFER_DELAY_TIMESTAMP);
			}
#endif			
			SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
			SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
			
			for(i=0; i < Count; i++)
				if (!dump_buf[i])
					__FREE(dump_buf[i]);				
			__FREE(dump_buf);
		}
	} while(0);
	for(i=0; i < Count; i++) {
		if (RxStream[i].__VStreamMask)
			SoraURadioReleaseRxStream(&RxStream[i], RadioNo[i]);
		if (buf[i])
			SoraURadioUnmapRxSampleBuf(RadioNo[i],	buf[i]);
	}
	SoraUCleanUserExtension();
}
Ejemplo n.º 5
0
void init_sora_hw()
{
	// Start Sora HW

	// Initialize Sora user mode extension
	BOOLEAN succ = SoraUInitUserExtension("\\\\.\\HWTest");
	if (!succ)
	{
		printf("Error: fail to find a Sora UMX capable device!\n");
		exit(1);
	}

	// Override radio ids (as they are hardcoded in firmware)
	params_tx->radioParams.radioId = TARGET_RADIO_TX;
	params_rx->radioParams.radioId = TARGET_RADIO_RX;

	// IMPORTANT!!!!
	// NOTE: Make sure you start TX before RX
	// Otherwise, the current firmware will cause BSOD!
	// (this is a known bug that should be fixed one day...)
	if (params_tx->outType == TY_SDR)
	{
		RadioStart(params_tx);
		InitSoraTx(params_tx);
	}

	if (params_rx->inType == TY_SDR)
	{
		RadioStart(params_rx);
		InitSoraRx(params_rx);
	}

	// Firmware is one for all radios
	RadioSetFirmwareParameters();

	// Start NDIS if not in testIP mode
	if (params_tx->inType == TY_IP && !test_IP)
	{
		HRESULT hResult = SoraUEnableGetTxPacket();
		if (hResult != S_OK)
		{
			printf("*** NDIS binding failed!\n");
		}

		// TODO: Hardcoded Sora MAC address - load from OS/command line
		memset(ethFrame, 0, 14 * sizeof(char));
		ethFrame[0] = 0x02;
		ethFrame[1] = 0x50;
		ethFrame[2] = 0xF2;
		ethFrame[3] = 0x78;
		ethFrame[4] = 0xFD;
		ethFrame[5] = 0x6C;

		ethFrame[12] = 0x08;

		//assert(hResult == S_OK);
		//Ndis_init(NULL);
	}

	/* No init to be done here, just use SoraUIndicateRxPacket
	if (params_rx->outType == TY_IP)
	{
	// To be implemented
	HRESULT hResult = SoraUEnableGetRxPacket();
	assert(hResult == S_OK);
	}
	*/


	// Init radio context blocks
	readSoraCtx *rctx = (readSoraCtx *)params_rx->TXBuffer;
	writeSoraCtx *ctx = (writeSoraCtx *)params_tx->TXBuffer;


	// Start Sora TX worker that is doing PCI transfer to Sora and the actual TX
	initTXCtx(ctx, rctx);

	// Start RX thread
	initRXCtx(rctx, ctx->TXBufferSize);

}