CC3000 Transmitter Testing Using RAW Socket

From Texas Instruments Wiki
Jump to: navigation, search



Following is an example of how to transmit packets in connection less mode using a raw socket. The generated packets in this example are of type: “802.11 Null Data” frame.

The example is based on the "Basic WiFi Application" code for MSP430FR5739 platform, which can be obtained from the CC3000 downloads page

main(void)
{
	int tx_bytes = 0;
	long ulSocket; unsigned char TxPattern[] = {0x01,0x20,0x71,0x48,0x00,0x00,0x00,0x00,0x11,0x22,0x33,0x44,0x55,0x00,0x12,0x55,0x55,0x55,0x55,0x00,0x11,0x22,0x33,0x44,0x55,0x00,0x00,0x12,0x34,0x56,0x78,0x9A,0xBC};
	
	WDTCTL = WDTPW + WDTHOLD;
	
	// Board Initialization start
	initDriver();
	
	// Initialize the UART RX Buffer 
	memset(g_ucUARTBuffer, 0xFF, UART_IF_BUFFER);
	uart_have_cmd =0; 

        // Open a raw socket
        ulSocket = socket(AF_INET, SOCK_RAW, 150);     
	
	// Loop forever transmitting null data packets, and waiting for commands from PC...
	while (1)
	{
		__bis_SR_register(LPM2_bits + GIE); 
		__no_operation();
		
		// Handle any unsolicited event if required - the function shall be
		// triggered few times in a second
		hci_unsolicited_event_handler();
		
		if (uart_have_cmd)
		{
			unsolicicted_events_timer_disable();
			
			// Process the command in RX buffer
			DemoHandleUartCommand(g_ucUARTBuffer);
			uart_have_cmd = 0;
			
			unsolicicted_events_timer_init();
		}
		
		tx_bytes = send(ulSocket, TxPattern, 33, 0);
	}  
}


The 33 bytes pattern has of the following format:

  • 01 (channel 1 - Range is from 1 to 14)
  • 20 (11b, 1Mbps - Bits 5-6: 1 for 11b, 2 for 11g; Bits 0-4: 1, 2, 5.5, 11 for 11b rates; 6, 9, .. 54 for 11g rates)
  • 71 (power level 7 (Bits 4-7: max power - can not be changed), short preamble (Bits 0-3) - 0 for long, 1 for short)
  • 48 (null data frame - according to 802.11 spec - Bits 4-7: Subtype; Bits 2-3: Type; Bits 0-1: Version)
  • 00 (Frame Control Flags - 1 byte)
  • 0000 (Duration - Auto Generated - can not be changed)
  • 001122334455 (Addr 1 = BSSID - can be any value, as working in connection less mode)
  • 001255555555 (Addr 2 = Source - can be any value)
  • 001122334455 (Addr 3 = Destination - can be any value)
  • 0000 (seq control - Auto Generated - can not be changed)
  • 123456789ABC (IE ⇒ random data - can be any value with up to any length according to 802.11)